Commit ee1c7387 by liuyong

修改三个架构资产

1 parent 0a8dd46d
...@@ -6,7 +6,11 @@ ...@@ -6,7 +6,11 @@
<meta name="viewport" content="width=device-width,initial-scale=1.0"> <meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico"> <link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title> <title><%= htmlWebpackPlugin.options.title %></title>
<script src="./sm4.js"></script> <link type="text/css" rel="stylesheet" href="./jsmind/jsmind.css" />
<script type="text/javascript" src="./jsmind/jsmind.js"></script>
<script type="text/javascript" src="./jsmind/jsmind.draggable-node.js"></script>
<script type="text/javascript" src="./jsmind/dom-to-image.js"></script>
<script type="text/javascript" src="./jsmind/jsmind.screenshot.js"></script>
</head> </head>
<body> <body>
<noscript> <noscript>
......
/*! dom-to-image 10-06-2017 */
!function(a){"use strict";function b(a,b){function c(a){return b.bgcolor&&(a.style.backgroundColor=b.bgcolor),b.width&&(a.style.width=b.width+"px"),b.height&&(a.style.height=b.height+"px"),b.style&&Object.keys(b.style).forEach(function(c){a.style[c]=b.style[c]}),a}return b=b||{},g(b),Promise.resolve(a).then(function(a){return i(a,b.filter,!0)}).then(j).then(k).then(c).then(function(c){return l(c,b.width||q.width(a),b.height||q.height(a))})}function c(a,b){return h(a,b||{}).then(function(b){return b.getContext("2d").getImageData(0,0,q.width(a),q.height(a)).data})}function d(a,b){return h(a,b||{}).then(function(a){return a.toDataURL()})}function e(a,b){return b=b||{},h(a,b).then(function(a){return a.toDataURL("image/jpeg",b.quality||1)})}function f(a,b){return h(a,b||{}).then(q.canvasToBlob)}function g(a){"undefined"==typeof a.imagePlaceholder?v.impl.options.imagePlaceholder=u.imagePlaceholder:v.impl.options.imagePlaceholder=a.imagePlaceholder,"undefined"==typeof a.cacheBust?v.impl.options.cacheBust=u.cacheBust:v.impl.options.cacheBust=a.cacheBust}function h(a,c){function d(a){var b=document.createElement("canvas");if(b.width=c.width||q.width(a),b.height=c.height||q.height(a),c.bgcolor){var d=b.getContext("2d");d.fillStyle=c.bgcolor,d.fillRect(0,0,b.width,b.height)}return b}return b(a,c).then(q.makeImage).then(q.delay(100)).then(function(b){var c=d(a);return c.getContext("2d").drawImage(b,0,0),c})}function i(a,b,c){function d(a){return a instanceof HTMLCanvasElement?q.makeImage(a.toDataURL()):a.cloneNode(!1)}function e(a,b,c){function d(a,b,c){var d=Promise.resolve();return b.forEach(function(b){d=d.then(function(){return i(b,c)}).then(function(b){b&&a.appendChild(b)})}),d}var e=a.childNodes;return 0===e.length?Promise.resolve(b):d(b,q.asArray(e),c).then(function(){return b})}function f(a,b){function c(){function c(a,b){function c(a,b){q.asArray(a).forEach(function(c){b.setProperty(c,a.getPropertyValue(c),a.getPropertyPriority(c))})}a.cssText?b.cssText=a.cssText:c(a,b)}c(window.getComputedStyle(a),b.style)}function d(){function c(c){function d(a,b,c){function d(a){var b=a.getPropertyValue("content");return a.cssText+" content: "+b+";"}function e(a){function b(b){return b+": "+a.getPropertyValue(b)+(a.getPropertyPriority(b)?" !important":"")}return q.asArray(a).map(b).join("; ")+";"}var f="."+a+":"+b,g=c.cssText?d(c):e(c);return document.createTextNode(f+"{"+g+"}")}var e=window.getComputedStyle(a,c),f=e.getPropertyValue("content");if(""!==f&&"none"!==f){var g=q.uid();b.className=b.className+" "+g;var h=document.createElement("style");h.appendChild(d(g,c,e)),b.appendChild(h)}}[":before",":after"].forEach(function(a){c(a)})}function e(){a instanceof HTMLTextAreaElement&&(b.innerHTML=a.value),a instanceof HTMLInputElement&&b.setAttribute("value",a.value)}function f(){b instanceof SVGElement&&(b.setAttribute("xmlns","http://www.w3.org/2000/svg"),b instanceof SVGRectElement&&["width","height"].forEach(function(a){var c=b.getAttribute(a);c&&b.style.setProperty(a,c)}))}return b instanceof Element?Promise.resolve().then(c).then(d).then(e).then(f).then(function(){return b}):b}return c||!b||b(a)?Promise.resolve(a).then(d).then(function(c){return e(a,c,b)}).then(function(b){return f(a,b)}):Promise.resolve()}function j(a){return s.resolveAll().then(function(b){var c=document.createElement("style");return a.appendChild(c),c.appendChild(document.createTextNode(b)),a})}function k(a){return t.inlineAll(a).then(function(){return a})}function l(a,b,c){return Promise.resolve(a).then(function(a){return a.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),(new XMLSerializer).serializeToString(a)}).then(q.escapeXhtml).then(function(a){return'<foreignObject x="0" y="0" width="100%" height="100%">'+a+"</foreignObject>"}).then(function(a){return'<svg xmlns="http://www.w3.org/2000/svg" width="'+b+'" height="'+c+'">'+a+"</svg>"}).then(function(a){return"data:image/svg+xml;charset=utf-8,"+a})}function m(){function a(){var a="application/font-woff",b="image/jpeg";return{woff:a,woff2:a,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:b,jpeg:b,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml"}}function b(a){var b=/\.([^\.\/]*?)$/g.exec(a);return b?b[1]:""}function c(c){var d=b(c).toLowerCase();return a()[d]||""}function d(a){return a.search(/^(data:)/)!==-1}function e(a){return new Promise(function(b){for(var c=window.atob(a.toDataURL().split(",")[1]),d=c.length,e=new Uint8Array(d),f=0;f<d;f++)e[f]=c.charCodeAt(f);b(new Blob([e],{type:"image/png"}))})}function f(a){return a.toBlob?new Promise(function(b){a.toBlob(b)}):e(a)}function g(a,b){var c=document.implementation.createHTMLDocument(),d=c.createElement("base");c.head.appendChild(d);var e=c.createElement("a");return c.body.appendChild(e),d.href=b,e.href=a,e.href}function h(){var a=0;return function(){function b(){return("0000"+(Math.random()*Math.pow(36,4)<<0).toString(36)).slice(-4)}return"u"+b()+a++}}function i(a){return new Promise(function(b,c){var d=new Image;d.onload=function(){b(d)},d.onerror=c,d.src=a})}function j(a){var b=3e4;return v.impl.options.cacheBust&&(a+=(/\?/.test(a)?"&":"?")+(new Date).getTime()),new Promise(function(c){function d(){if(4===g.readyState){if(200!==g.status)return void(h?c(h):f("cannot fetch resource: "+a+", status: "+g.status));var b=new FileReader;b.onloadend=function(){var a=b.result.split(/,/)[1];c(a)},b.readAsDataURL(g.response)}}function e(){h?c(h):f("timeout of "+b+"ms occured while fetching resource: "+a)}function f(a){console.error(a),c("")}var g=new XMLHttpRequest;g.onreadystatechange=d,g.ontimeout=e,g.responseType="blob",g.timeout=b,g.open("GET",a,!0),g.send();var h;if(v.impl.options.imagePlaceholder){var i=v.impl.options.imagePlaceholder.split(/,/);i&&i[1]&&(h=i[1])}})}function k(a,b){return"data:"+b+";base64,"+a}function l(a){return a.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1")}function m(a){return function(b){return new Promise(function(c){setTimeout(function(){c(b)},a)})}}function n(a){for(var b=[],c=a.length,d=0;d<c;d++)b.push(a[d]);return b}function o(a){return a.replace(/#/g,"%23").replace(/\n/g,"%0A")}function p(a){var b=r(a,"border-left-width"),c=r(a,"border-right-width");return a.scrollWidth+b+c}function q(a){var b=r(a,"border-top-width"),c=r(a,"border-bottom-width");return a.scrollHeight+b+c}function r(a,b){var c=window.getComputedStyle(a).getPropertyValue(b);return parseFloat(c.replace("px",""))}return{escape:l,parseExtension:b,mimeType:c,dataAsUrl:k,isDataUrl:d,canvasToBlob:f,resolveUrl:g,getAndEncode:j,uid:h(),delay:m,asArray:n,escapeXhtml:o,makeImage:i,width:p,height:q}}function n(){function a(a){return a.search(e)!==-1}function b(a){for(var b,c=[];null!==(b=e.exec(a));)c.push(b[1]);return c.filter(function(a){return!q.isDataUrl(a)})}function c(a,b,c,d){function e(a){return new RegExp("(url\\(['\"]?)("+q.escape(a)+")(['\"]?\\))","g")}return Promise.resolve(b).then(function(a){return c?q.resolveUrl(a,c):a}).then(d||q.getAndEncode).then(function(a){return q.dataAsUrl(a,q.mimeType(b))}).then(function(c){return a.replace(e(b),"$1"+c+"$3")})}function d(d,e,f){function g(){return!a(d)}return g()?Promise.resolve(d):Promise.resolve(d).then(b).then(function(a){var b=Promise.resolve(d);return a.forEach(function(a){b=b.then(function(b){return c(b,a,e,f)})}),b})}var e=/url\(['"]?([^'"]+?)['"]?\)/g;return{inlineAll:d,shouldProcess:a,impl:{readUrls:b,inline:c}}}function o(){function a(){return b(document).then(function(a){return Promise.all(a.map(function(a){return a.resolve()}))}).then(function(a){return a.join("\n")})}function b(){function a(a){return a.filter(function(a){return a.type===CSSRule.FONT_FACE_RULE}).filter(function(a){return r.shouldProcess(a.style.getPropertyValue("src"))})}function b(a){var b=[];return a.forEach(function(a){try{q.asArray(a.cssRules||[]).forEach(b.push.bind(b))}catch(c){console.log("Error while reading CSS rules from "+a.href,c.toString())}}),b}function c(a){return{resolve:function(){var b=(a.parentStyleSheet||{}).href;return r.inlineAll(a.cssText,b)},src:function(){return a.style.getPropertyValue("src")}}}return Promise.resolve(q.asArray(document.styleSheets)).then(b).then(a).then(function(a){return a.map(c)})}return{resolveAll:a,impl:{readAll:b}}}function p(){function a(a){function b(b){return q.isDataUrl(a.src)?Promise.resolve():Promise.resolve(a.src).then(b||q.getAndEncode).then(function(b){return q.dataAsUrl(b,q.mimeType(a.src))}).then(function(b){return new Promise(function(c,d){a.onload=c,a.onerror=d,a.src=b})})}return{inline:b}}function b(c){function d(a){var b=a.style.getPropertyValue("background");return b?r.inlineAll(b).then(function(b){a.style.setProperty("background",b,a.style.getPropertyPriority("background"))}).then(function(){return a}):Promise.resolve(a)}return c instanceof Element?d(c).then(function(){return c instanceof HTMLImageElement?a(c).inline():Promise.all(q.asArray(c.childNodes).map(function(a){return b(a)}))}):Promise.resolve(c)}return{inlineAll:b,impl:{newImage:a}}}var q=m(),r=n(),s=o(),t=p(),u={imagePlaceholder:void 0,cacheBust:!1},v={toSvg:b,toPng:d,toJpeg:e,toBlob:f,toPixelData:c,impl:{fontFaces:s,images:t,util:q,inliner:r,options:{}}};"undefined"!=typeof module?module.exports=v:a.domtoimage=v}(this);
\ No newline at end of file
/**
* @license BSD
* @copyright 2014-2023 hizzgdev@163.com
*
* Project Home:
* https://github.com/hizzgdev/jsmind/
*/
/* important section */
.jsmind-inner {
position: relative;
overflow: auto;
width: 100%;
height: 100%;
outline: none;
} /*box-shadow:0 0 2px #000;*/
.jsmind-inner {
moz-user-select: -moz-none;
-moz-user-select: none;
-o-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
.jsmind-inner canvas {
position: absolute;
}
/* z-index:1 */
svg.jsmind {
position: absolute;
z-index: 1;
}
canvas.jsmind {
position: absolute;
z-index: 1;
}
/* z-index:2 */
jmnodes {
position: absolute;
z-index: 2;
background-color: rgba(0, 0, 0, 0);
} /*background color is necessary*/
jmnode {
position: absolute;
cursor: default;
max-width: 400px;
}
jmexpander {
position: absolute;
width: 11px;
height: 11px;
display: block;
overflow: hidden;
line-height: 12px;
font-size: 10px;
text-align: center;
border-radius: 6px;
border-width: 1px;
border-style: solid;
cursor: pointer;
}
.jmnode-overflow-wrap jmnodes {
min-width: 420px;
}
.jmnode-overflow-hidden jmnode {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* default theme */
jmnode {
padding: 10px;
background-color: #fff;
color: #333;
border-radius: 5px;
box-shadow: 1px 1px 1px #666;
font: 16px/1.125 Verdana, Arial, Helvetica, sans-serif;
}
jmnode:hover {
box-shadow: 2px 2px 8px #000;
background-color: #ebebeb;
color: #333;
}
jmnode.selected {
background-color: #11f;
color: #fff;
box-shadow: 2px 2px 8px #000;
}
jmnode.root {
font-size: 24px;
}
jmexpander {
border-color: gray;
}
jmexpander:hover {
border-color: #000;
}
@media screen and (max-device-width: 1024px) {
jmnode {
padding: 5px;
border-radius: 3px;
font-size: 14px;
}
jmnode.root {
font-size: 21px;
}
}
/* primary theme */
jmnodes.theme-primary jmnode {
background-color: #428bca;
color: #fff;
border-color: #357ebd;
}
jmnodes.theme-primary jmnode:hover {
background-color: #3276b1;
border-color: #285e8e;
}
jmnodes.theme-primary jmnode.selected {
background-color: #f1c40f;
color: #fff;
}
jmnodes.theme-primary jmnode.root {
}
jmnodes.theme-primary jmexpander {
}
jmnodes.theme-primary jmexpander:hover {
}
/* warning theme */
jmnodes.theme-warning jmnode {
background-color: #f0ad4e;
border-color: #eea236;
color: #fff;
}
jmnodes.theme-warning jmnode:hover {
background-color: #ed9c28;
border-color: #d58512;
}
jmnodes.theme-warning jmnode.selected {
background-color: #11f;
color: #fff;
}
jmnodes.theme-warning jmnode.root {
}
jmnodes.theme-warning jmexpander {
}
jmnodes.theme-warning jmexpander:hover {
}
/* danger theme */
jmnodes.theme-danger jmnode {
background-color: #d9534f;
border-color: #d43f3a;
color: #fff;
}
jmnodes.theme-danger jmnode:hover {
background-color: #d2322d;
border-color: #ac2925;
}
jmnodes.theme-danger jmnode.selected {
background-color: #11f;
color: #fff;
}
jmnodes.theme-danger jmnode.root {
}
jmnodes.theme-danger jmexpander {
}
jmnodes.theme-danger jmexpander:hover {
}
/* success theme */
jmnodes.theme-success jmnode {
background-color: #5cb85c;
border-color: #4cae4c;
color: #fff;
}
jmnodes.theme-success jmnode:hover {
background-color: #47a447;
border-color: #398439;
}
jmnodes.theme-success jmnode.selected {
background-color: #11f;
color: #fff;
}
jmnodes.theme-success jmnode.root {
}
jmnodes.theme-success jmexpander {
}
jmnodes.theme-success jmexpander:hover {
}
/* info theme */
jmnodes.theme-info jmnode {
background-color: #5dc0de;
border-color: #46b8da;
color: #fff;
}
jmnodes.theme-info jmnode:hover {
background-color: #39b3d7;
border-color: #269abc;
}
jmnodes.theme-info jmnode.selected {
background-color: #11f;
color: #fff;
}
jmnodes.theme-info jmnode.root {
}
jmnodes.theme-info jmexpander {
}
jmnodes.theme-info jmexpander:hover {
}
/* greensea theme */
jmnodes.theme-greensea jmnode {
background-color: #1abc9c;
color: #fff;
}
jmnodes.theme-greensea jmnode:hover {
background-color: #16a085;
}
jmnodes.theme-greensea jmnode.selected {
background-color: #11f;
color: #fff;
}
jmnodes.theme-greensea jmnode.root {
}
jmnodes.theme-greensea jmexpander {
}
jmnodes.theme-greensea jmexpander:hover {
}
/* nephrite theme */
jmnodes.theme-nephrite jmnode {
background-color: #2ecc71;
color: #fff;
}
jmnodes.theme-nephrite jmnode:hover {
background-color: #27ae60;
}
jmnodes.theme-nephrite jmnode.selected {
background-color: #11f;
color: #fff;
}
jmnodes.theme-nephrite jmnode.root {
}
jmnodes.theme-nephrite jmexpander {
}
jmnodes.theme-nephrite jmexpander:hover {
}
/* belizehole theme */
jmnodes.theme-belizehole jmnode {
background-color: #3498db;
color: #fff;
}
jmnodes.theme-belizehole jmnode:hover {
background-color: #2980b9;
}
jmnodes.theme-belizehole jmnode.selected {
background-color: #11f;
color: #fff;
}
jmnodes.theme-belizehole jmnode.root {
}
jmnodes.theme-belizehole jmexpander {
}
jmnodes.theme-belizehole jmexpander:hover {
}
/* wisteria theme */
jmnodes.theme-wisteria jmnode {
background-color: #9b59b6;
color: #fff;
}
jmnodes.theme-wisteria jmnode:hover {
background-color: #8e44ad;
}
jmnodes.theme-wisteria jmnode.selected {
background-color: #11f;
color: #fff;
}
jmnodes.theme-wisteria jmnode.root {
}
jmnodes.theme-wisteria jmexpander {
}
jmnodes.theme-wisteria jmexpander:hover {
}
/* asphalt theme */
jmnodes.theme-asphalt jmnode {
background-color: #34495e;
color: #fff;
}
jmnodes.theme-asphalt jmnode:hover {
background-color: #2c3e50;
}
jmnodes.theme-asphalt jmnode.selected {
background-color: #11f;
color: #fff;
}
jmnodes.theme-asphalt jmnode.root {
}
jmnodes.theme-asphalt jmexpander {
}
jmnodes.theme-asphalt jmexpander:hover {
}
/* orange theme */
jmnodes.theme-orange jmnode {
background-color: #f1c40f;
color: #fff;
}
jmnodes.theme-orange jmnode:hover {
background-color: #f39c12;
}
jmnodes.theme-orange jmnode.selected {
background-color: #11f;
color: #fff;
}
jmnodes.theme-orange jmnode.root {
}
jmnodes.theme-orange jmexpander {
}
jmnodes.theme-orange jmexpander:hover {
}
/* pumpkin theme */
jmnodes.theme-pumpkin jmnode {
background-color: #e67e22;
color: #fff;
}
jmnodes.theme-pumpkin jmnode:hover {
background-color: #d35400;
}
jmnodes.theme-pumpkin jmnode.selected {
background-color: #11f;
color: #fff;
}
jmnodes.theme-pumpkin jmnode.root {
}
jmnodes.theme-pumpkin jmexpander {
}
jmnodes.theme-pumpkin jmexpander:hover {
}
/* pomegranate theme */
jmnodes.theme-pomegranate jmnode {
background-color: #e74c3c;
color: #fff;
}
jmnodes.theme-pomegranate jmnode:hover {
background-color: #c0392b;
}
jmnodes.theme-pomegranate jmnode.selected {
background-color: #11f;
color: #fff;
}
jmnodes.theme-pomegranate jmnode.root {
}
jmnodes.theme-pomegranate jmexpander {
}
jmnodes.theme-pomegranate jmexpander:hover {
}
/* clouds theme */
jmnodes.theme-clouds jmnode {
background-color: #ecf0f1;
color: #333;
}
jmnodes.theme-clouds jmnode:hover {
background-color: #bdc3c7;
}
jmnodes.theme-clouds jmnode.selected {
background-color: #11f;
color: #fff;
}
jmnodes.theme-clouds jmnode.root {
}
jmnodes.theme-clouds jmexpander {
}
jmnodes.theme-clouds jmexpander:hover {
}
/* asbestos theme */
jmnodes.theme-asbestos jmnode {
background-color: #95a5a6;
color: #fff;
}
jmnodes.theme-asbestos jmnode:hover {
background-color: #7f8c8d;
}
jmnodes.theme-asbestos jmnode.selected {
background-color: #11f;
color: #fff;
}
jmnodes.theme-asbestos jmnode.root {
}
jmnodes.theme-asbestos jmexpander {
}
jmnodes.theme-asbestos jmexpander:hover {
}
\ No newline at end of file
/**
* @license BSD-3-Clause
* @copyright 2014-2023 hizzgdev@163.com
*
* Project Home:
* https://github.com/hizzgdev/jsmind/
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("jsmind")):"function"==typeof define&&define.amd?define(["jsmind"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).jsMind)}(this,(function(t){"use strict";function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=e(t);if(!i.default)throw new Error("jsMind is not defined");const s=i.default.$,o="getSelection"in s.w?function(){s.w.getSelection().removeAllRanges()}:function(){s.d.selection.empty()},n={line_width:5,line_color:"rgba(0,0,0,0.3)",line_color_invalid:"rgba(255,51,51,0.6)",lookup_delay:200,lookup_interval:100,scrolling_trigger_width:20,scrolling_step_length:10,shadow_node_class_name:"jsmind-draggable-shadow-node"};class h{constructor(t,e){var s={};i.default.util.json.merge(s,n),i.default.util.json.merge(s,e),this.version="0.4.0",this.jm=t,this.options=s,this.e_canvas=null,this.canvas_ctx=null,this.shadow=null,this.shadow_p_x=0,this.shadow_p_y=0,this.shadow_w=0,this.shadow_h=0,this.active_node=null,this.target_node=null,this.target_direct=null,this.client_w=0,this.client_h=0,this.offset_x=0,this.offset_y=0,this.hlookup_delay=0,this.hlookup_timer=0,this.capture=!1,this.moved=!1,this.canvas_draggable=t.get_view_draggable(),this.view_panel=t.view.e_panel,this.view_panel_rect=null}init(){this.create_canvas(),this.create_shadow(),this.event_bind()}resize(){this.jm.view.e_nodes.appendChild(this.shadow),this.e_canvas.width=this.jm.view.size.w,this.e_canvas.height=this.jm.view.size.h}create_canvas(){var t=s.c("canvas");this.jm.view.e_panel.appendChild(t);var e=t.getContext("2d");this.e_canvas=t,this.canvas_ctx=e}create_shadow(){var t=s.c("jmnode");t.style.visibility="hidden",t.style.zIndex="3",t.style.cursor="move",t.style.opacity="0.7",t.className=this.options.shadow_node_class_name,this.shadow=t}reset_shadow(t){var e=this.shadow.style;this.shadow.innerHTML=t.innerHTML,e.left=t.style.left,e.top=t.style.top,e.width=t.style.width,e.height=t.style.height,e.backgroundImage=t.style.backgroundImage,e.backgroundSize=t.style.backgroundSize,e.transform=t.style.transform,this.shadow_w=this.shadow.clientWidth,this.shadow_h=this.shadow.clientHeight}show_shadow(){this.moved||(this.shadow.style.visibility="visible")}hide_shadow(){this.shadow.style.visibility="hidden"}magnet_shadow(t,e,i){this.canvas_ctx.lineWidth=this.options.line_width,this.canvas_ctx.strokeStyle=i?this.options.line_color_invalid:this.options.line_color,this.canvas_ctx.lineCap="round",this.clear_lines(),this.canvas_lineto(t.x,t.y,e.x,e.y)}clear_lines(){this.canvas_ctx.clearRect(0,0,this.jm.view.size.w,this.jm.view.size.h)}canvas_lineto(t,e,i,s){this.canvas_ctx.beginPath(),this.canvas_ctx.moveTo(t,e),this.canvas_ctx.lineTo(i,s),this.canvas_ctx.stroke()}event_bind(){var t=this,e=this.jm.view.container;s.on(e,"mousedown",(function(e){0===e.button&&t.dragstart.call(t,e)})),s.on(e,"mousemove",(function(e){0===e.movementX&&0===e.movementY||t.drag.call(t,e)})),s.on(e,"mouseup",(function(e){t.dragend.call(t,e)})),s.on(e,"touchstart",(function(e){t.dragstart.call(t,e)})),s.on(e,"touchmove",(function(e){t.drag.call(t,e)})),s.on(e,"touchend",(function(e){t.dragend.call(t,e)}))}dragstart(t){if(this.jm.get_editable()&&!this.capture){this.active_node=null,this.view_draggable=this.jm.get_view_draggable();var e=this.jm.view,i=this.find_node_element(t.target);if(i){this.view_draggable&&this.jm.disable_view_draggable();var o=e.get_binded_nodeid(i);if(o){var n=this.jm.get_node(o);if(!n.isroot){this.reset_shadow(i),this.view_panel_rect=this.view_panel.getBoundingClientRect(),this.active_node=n,this.offset_x=(t.clientX||t.touches[0].clientX)/e.zoom_current-i.offsetLeft,this.offset_y=(t.clientY||t.touches[0].clientY)/e.zoom_current-i.offsetTop,this.client_hw=Math.floor(i.clientWidth/2),this.client_hh=Math.floor(i.clientHeight/2),0!=this.hlookup_delay&&s.w.clearTimeout(this.hlookup_delay),0!=this.hlookup_timer&&s.w.clearInterval(this.hlookup_timer);var h=this;this.hlookup_delay=s.w.setTimeout((function(){h.hlookup_delay=0,h.hlookup_timer=s.w.setInterval((function(){h.lookup_target_node.call(h)}),h.options.lookup_interval)}),this.options.lookup_delay),h.capture=!0}}}else console.log("throw away")}}drag(t){if(this.jm.get_editable()&&this.capture){t.preventDefault(),this.show_shadow(),this.moved=!0,o();var e=this.jm.view,i=(t.clientX||t.touches[0].clientX)/e.zoom_current-this.offset_x,s=(t.clientY||t.touches[0].clientY)/e.zoom_current-this.offset_y;t.clientY-this.view_panel_rect.top<this.options.scrolling_trigger_width&&this.view_panel.scrollTop>this.options.scrolling_step_length?(this.view_panel.scrollBy(0,-this.options.scrolling_step_length),this.offset_y+=this.options.scrolling_step_length/e.zoom_current):this.view_panel_rect.bottom-t.clientY<this.options.scrolling_trigger_width&&this.view_panel.scrollTop<this.view_panel.scrollHeight-this.view_panel_rect.height-this.options.scrolling_step_length&&(this.view_panel.scrollBy(0,this.options.scrolling_step_length),this.offset_y-=this.options.scrolling_step_length/e.zoom_current),t.clientX-this.view_panel_rect.left<this.options.scrolling_trigger_width&&this.view_panel.scrollLeft>this.options.scrolling_step_length?(this.view_panel.scrollBy(-this.options.scrolling_step_length,0),this.offset_x+=this.options.scrolling_step_length/e.zoom_current):this.view_panel_rect.right-t.clientX<this.options.scrolling_trigger_width&&this.view_panel.scrollLeft<this.view_panel.scrollWidth-this.view_panel_rect.width-this.options.scrolling_step_length&&(this.view_panel.scrollBy(this.options.scrolling_step_length,0),this.offset_x-=this.options.scrolling_step_length/e.zoom_current),this.shadow.style.left=i+"px",this.shadow.style.top=s+"px",o()}}dragend(t){if(this.jm.get_editable()){if(this.view_draggable&&this.jm.enable_view_draggable(),this.capture){if(0!=this.hlookup_delay&&(s.w.clearTimeout(this.hlookup_delay),this.hlookup_delay=0,this.clear_lines()),0!=this.hlookup_timer&&(s.w.clearInterval(this.hlookup_timer),this.hlookup_timer=0,this.clear_lines()),this.moved){var e=this.active_node,i=this.target_node,o=this.target_direct;this.move_node(e,i,o)}this.hide_shadow()}this.view_panel_rect=null,this.moved=!1,this.capture=!1}}find_node_element(t){return t===this.jm.view.e_nodes||t===this.jm.view.e_panel||t===this.jm.view.container?null:"jmnode"===t.tagName.toLowerCase()?t:this.find_node_element(t.parentNode)}lookup_target_node(){let t=this.shadow.offsetLeft,e=this.shadow.offsetTop;if(t===this.shadow_p_x&&e===this.shadow_p_y)return;this.shadow_p_x=t,this.shadow_p_y=e;let s=this.shadow_p_x+this.shadow_w/2>=this.get_root_x()?i.default.direction.right:i.default.direction.left,o=this.lookup_overlapping_node_parent(s)||this.lookup_close_node(s);if(o){let t=this.calc_point_of_node(o,s),e=i.default.node.inherited(this.active_node,o);this.magnet_shadow(t.sp,t.np,e),this.target_node=o,this.target_direct=s}}get_root_x(){let t=this.jm.get_root(),e=t.get_location(),i=t.get_size();return e.x+i.w/2}lookup_overlapping_node_parent(t){let e=this.shadow.getBoundingClientRect(),i=e.x+e.width*(1-t)/2,s=(this.jm.options.layout.hspace+this.jm.options.layout.pspace)*t,o=e.height,n=[[i,e.y],[i,e.y+o/2],[i,e.y+o],[i+s/2,e.y],[i+s/2,e.y+o/2],[i+s/2,e.y+o],[i+s,e.y],[i+s,e.y+o/2],[i+s,e.y+o]];for(const t of n){let e=this.lookup_node_parent_by_location(t[0],t[1]);if(e)return e}}lookup_node_parent_by_location(t,e){return s.d.elementsFromPoint(t,e).filter((t=>"JMNODE"===t.tagName&&t.className!==this.options.shadow_node_class_name)).map((t=>this.jm.view.get_binded_nodeid(t))).map((t=>t&&this.jm.mind.nodes[t])).map((t=>t&&t.parent)).find((t=>t))}lookup_close_node(t){return Object.values(this.jm.mind.nodes).filter((e=>e.direction==t||e.isroot)).filter((t=>this.jm.layout.is_visible(t))).filter((e=>this.shadow_on_target_side(e,t))).map((e=>({node:e,distance:this.shadow_to_node(e,t)}))).reduce(((t,e)=>t.distance<e.distance?t:e),{node:this.jm.get_root(),distance:Number.MAX_VALUE}).node}shadow_on_target_side(t,e){return e==i.default.direction.right&&this.shadow_to_right_of_node(t)>0||e==i.default.direction.left&&this.shadow_to_left_of_node(t)>0}shadow_to_right_of_node(t){return this.shadow_p_x-t.get_location().x-t.get_size().w}shadow_to_left_of_node(t){return t.get_location().x-this.shadow_p_x-this.shadow_w}shadow_to_base_line_of_node(t){return this.shadow_p_y+this.shadow_h/2-t.get_location().y-t.get_size().h/2}shadow_to_node(t,e){return(e===i.default.direction.right?Math.abs(this.shadow_to_right_of_node(t)):Math.abs(this.shadow_to_left_of_node(t)))+Math.abs(this.shadow_to_base_line_of_node(t))}calc_point_of_node(t,e){let i=t.get_size(),s=t.get_location(),o=t.isroot?s.x+i.w/2:s.x+i.w*(1+e)/2+this.options.line_width*e,n=s.y+i.h/2;return{sp:{x:this.shadow_p_x+this.shadow_w*(1-e)/2-this.options.line_width*e,y:this.shadow_p_y+this.shadow_h/2},np:{x:o,y:n}}}move_node(t,e,s){var o=this.shadow.offsetTop;if(e&&t&&!i.default.node.inherited(t,e)){for(var n=e.children,h=n.length,l=null,a=Number.MAX_VALUE,_=null,d="_last_";h--;)if((l=n[h]).direction==s&&l.id!=t.id){var r=l.get_location().y-o;r>0&&r<a&&(a=r,_=l,d="_first_")}_&&(d=_.id),this.jm.move_node(t.id,d,e.id,s)}this.active_node=null,this.target_node=null,this.target_direct=null}jm_event_handle(t,e){t===i.default.event_type.resize&&this.resize()}}var l=new i.default.plugin("draggable_node",(function(t,e){var i=new h(t,e);i.init(),t.add_event_listener((function(t,e){i.jm_event_handle.call(i,t,e)}))}));i.default.register_plugin(l)}));
//# sourceMappingURL=jsmind.draggable-node.js.map
\ No newline at end of file
/**
* @license BSD-3-Clause
* @copyright 2014-2023 hizzgdev@163.com
*
* Project Home:
* https://github.com/hizzgdev/jsmind/
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).jsMind=t()}(this,(function(){"use strict";const e="0.8.1";"function"!=typeof String.prototype.startsWith&&(String.prototype.startsWith=function(e){return this.slice(0,e.length)===e});const t={left:-1,center:0,right:1,of:function(e){return e&&-1!==e&&0!==e&&1!==e?"-1"===e||"0"===e||"1"===e?parseInt(e):"left"===e.toLowerCase()?this.left:"right"===e.toLowerCase()?this.right:"center"===e.toLowerCase()?this.center:void 0:e}},i={show:1,resize:2,edit:3,select:4},n={debug:1,info:2,warn:3,error:4,disable:9};var o=function(){};let s="undefined"==typeof console?{level:o,log:o,debug:o,info:o,warn:o,error:o}:{level:function(e){s.debug=e>n.debug?o:console.debug;s.info=e>n.info?o:console.info;s.warn=e>n.warn?o:console.warn;s.error=e>n.error?o:console.error},log:console.log,debug:console.debug,info:console.info,warn:console.warn,error:console.error};const r=new class{constructor(e){this.w=e,this.d=e.document,this.g=function(e){return this.d.getElementById(e)},this.c=function(e){return this.d.createElement(e)},this.t=function(e,t){e.hasChildNodes()?e.firstChild.nodeValue=t:e.appendChild(this.d.createTextNode(t))},this.h=function(e,t){t instanceof HTMLElement?(e.innerHTML="",e.appendChild(t)):e.innerHTML=t},this.i=function(e){return!!e&&"object"==typeof e&&1===e.nodeType&&"object"==typeof e.style&&"object"==typeof e.ownerDocument},this.on=function(e,t,i){e.addEventListener?e.addEventListener(t,i,!1):e.attachEvent("on"+t,i)}}}(window),a={file:{read:function(e,t){var i=new FileReader;i.onload=function(){"function"==typeof t&&t(this.result,e.name)},i.readAsText(e)},save:function(e,t,i){var n;if("function"==typeof r.w.Blob)n=new Blob([e],{type:t});else{var o=new(r.w.BlobBuilder||r.w.MozBlobBuilder||r.w.WebKitBlobBuilder||r.w.MSBlobBuilder);o.append(e),n=o.getBlob(t)}if(navigator.msSaveBlob)navigator.msSaveBlob(n,i);else{var s=(r.w.URL||r.w.webkitURL).createObjectURL(n),a=r.c("a");if("download"in a){a.style.visibility="hidden",a.href=s,a.download=i,r.d.body.appendChild(a);var d=r.d.createEvent("MouseEvents");d.initEvent("click",!0,!0),a.dispatchEvent(d),r.d.body.removeChild(a)}else location.href=s}}},json:{json2string:function(e){return JSON.stringify(e)},string2json:function(e){return JSON.parse(e)},merge:function(e,t){for(var i in t)i in e?"object"!=typeof e[i]||"[object object]"!=Object.prototype.toString.call(e[i]).toLowerCase()||e[i].length?e[i]=t[i]:a.json.merge(e[i],t[i]):e[i]=t[i];return e}},uuid:{newid:function(){return((new Date).getTime().toString(16)+Math.random().toString(16).substring(2)).substring(2,18)}},text:{is_empty:function(e){return!e||0==e.replace(/\s*/,"").length}}},d={container:"",editable:!1,theme:null,mode:"full",support_html:!0,log_level:"info",view:{engine:"canvas",hmargin:100,vmargin:50,line_width:2,line_color:"#555",line_style:"curved",draggable:!1,hide_scrollbars_when_draggable:!1,node_overflow:"hidden",zoom:{min:.5,max:2.1,step:.1},custom_node_render:null,expander_style:"char"},layout:{hspace:30,vspace:20,pspace:13,cousin_space:0},default_event_handle:{enable_mousedown_handle:!0,enable_click_handle:!0,enable_dblclick_handle:!0,enable_mousewheel_handle:!0},shortcut:{enable:!0,handles:{},mapping:{addchild:[45,4109],addbrother:13,editnode:113,delnode:46,toggle:32,left:37,up:38,right:39,down:40}},plugin:{}};class l{constructor(e,t,i,n,o,r,a,d){e?"number"==typeof t?(void 0===d&&(d=!0),this.id=e,this.index=t,this.topic=i,this.data=n||{},this.isroot=o,this.parent=r,this.direction=a,this.expanded=!!d,this.children=[],this._data={}):s.error("invalid node index"):s.error("invalid node id")}get_location(){var e=this._data.view;return{x:e.abs_x,y:e.abs_y}}get_size(){var e=this._data.view;return{w:e.width,h:e.height}}static compare(e,t){var i=e.index,n=t.index;return i>=0&&n>=0?i-n:-1==i&&-1==n?0:-1==i?1:-1==n?-1:0}static inherited(e,t){if(e&&t){if(e.id===t.id)return!0;if(e.isroot)return!0;for(var i=e.id,n=t;!n.isroot;)if((n=n.parent).id===i)return!0}return!1}static is_node(e){return!!e&&e instanceof l}}class h{constructor(){this.name=null,this.author=null,this.version=null,this.root=null,this.selected=null,this.nodes={}}get_node(e){return e in this.nodes?this.nodes[e]:(s.warn("the node[id="+e+"] can not be found"),null)}set_root(e,t,i){return null==this.root?(this.root=new l(e,0,t,i,!0),this._put_node(this.root),this.root):(s.error("root node is already exist"),null)}add_node(e,i,n,o,r,a,d){if(!l.is_node(e))return s.error("the parent_node "+e+" is not a node."),null;var h=new l(i,d||-1,n,o,!1,e,e.direction,a);return e.isroot&&(h.direction=r||t.right),this._put_node(h)?(e.children.push(h),this._update_index(e)):(s.error("fail, the node id '"+h.id+"' has been already exist."),h=null),h}insert_node_before(e,t,i,n,o){if(!l.is_node(e))return s.error("the node_before "+e+" is not a node."),null;var r=e.index-.5;return this.add_node(e.parent,t,i,n,o,!0,r)}get_node_before(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.get_node_before(t):(s.error("the node[id="+e+"] can not be found."),null)}if(e.isroot)return null;var i=e.index-2;return i>=0?e.parent.children[i]:null}insert_node_after(e,t,i,n,o){if(!l.is_node(e))return s.error("the node_after "+e+" is not a node."),null;var r=e.index+.5;return this.add_node(e.parent,t,i,n,o,!0,r)}get_node_after(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.get_node_after(t):(s.error("the node[id="+e+"] can not be found."),null)}if(e.isroot)return null;var i=e.index;return e.parent.children.length>i?e.parent.children[i]:null}move_node(e,t,i,n){return l.is_node(e)?(i||(i=e.parent.id),this._move_node(e,t,i,n)):(s.error("the parameter node "+e+" is not a node."),null)}_flow_node_direction(e,t){void 0===t?t=e.direction:e.direction=t;for(var i=e.children.length;i--;)this._flow_node_direction(e.children[i],t)}_move_node_internal(e,t){if(e&&t)if("_last_"==t)e.index=-1,this._update_index(e.parent);else if("_first_"==t)e.index=0,this._update_index(e.parent);else{var i=t?this.get_node(t):null;null!=i&&null!=i.parent&&i.parent.id==e.parent.id&&(e.index=i.index-.5,this._update_index(e.parent))}return e}_move_node(e,i,n,o){if(e&&n){var r=this.get_node(n);if(l.inherited(e,r))return s.error("can not move a node to its children"),null;if(e.parent.id!=n){for(var a=e.parent.children,d=a.length;d--;)if(a[d].id==e.id){a.splice(d,1);break}e.parent=r,r.children.push(e)}e.parent.isroot?o==t.left?e.direction=o:e.direction=t.right:e.direction=e.parent.direction,this._move_node_internal(e,i),this._flow_node_direction(e)}return e}remove_node(e){if(!l.is_node(e))return s.error("the parameter node "+e+" is not a node."),!1;if(e.isroot)return s.error("fail, can not remove root node"),!1;null!=this.selected&&this.selected.id==e.id&&(this.selected=null);for(var t=e.children,i=t.length;i--;)this.remove_node(t[i]);t.length=0;for(var n=e.parent,o=n.children,r=o.length;r--;)if(o[r].id==e.id){o.splice(r,1);break}for(var a in delete this.nodes[e.id],e)delete e[a];return e=null,this._update_index(n),!0}_put_node(e){return e.id in this.nodes?(s.warn("the node_id '"+e.id+"' has been already exist."),!1):(this.nodes[e.id]=e,!0)}_update_index(e){if(e instanceof l){e.children.sort(l.compare);for(var t=0;t<e.children.length;t++)e.children[t].index=t+1}}}const _={name:"jsMind",author:"hizzgdev@163.com",version:e},u={node_tree:{example:{meta:_,format:"node_tree",data:{id:"root",topic:"jsMind node_tree example"}},get_mind:function(e){var t=u.node_tree,i=new h;return i.name=e.meta.name,i.author=e.meta.author,i.version=e.meta.version,t._parse(i,e.data),i},get_data:function(e){var t=u.node_tree,i={};return i.meta={name:e.name,author:e.author,version:e.version},i.format="node_tree",i.data=t._build_node(e.root),i},_parse:function(e,t){var i=u.node_tree,n=i._extract_data(t);if(e.set_root(t.id,t.topic,n),"children"in t)for(var o=t.children,s=0;s<o.length;s++)i._extract_subnode(e,e.root,o[s])},_extract_data:function(e){var t={};for(var i in e)"id"!=i&&"topic"!=i&&"children"!=i&&"direction"!=i&&"expanded"!=i&&(t[i]=e[i]);return t},_extract_subnode:function(e,i,n){var o=u.node_tree,s=o._extract_data(n),r=null;i.isroot&&(r="left"==n.direction?t.left:t.right);var a=e.add_node(i,n.id,n.topic,s,r,n.expanded);if(n.children)for(var d=n.children,l=0;l<d.length;l++)o._extract_subnode(e,a,d[l])},_build_node:function(e){var i=u.node_tree;if(e instanceof l){var n={id:e.id,topic:e.topic,expanded:e.expanded};if(e.parent&&e.parent.isroot&&(n.direction=e.direction==t.left?"left":"right"),null!=e.data){var o=e.data;for(var s in o)n[s]=o[s]}var r=e.children;if(r.length>0){n.children=[];for(var a=0;a<r.length;a++)n.children.push(i._build_node(r[a]))}return n}}},node_array:{example:{meta:_,format:"node_array",data:[{id:"root",topic:"jsMind node_array example",isroot:!0}]},get_mind:function(e){var t=u.node_array,i=new h;return i.name=e.meta.name,i.author=e.meta.author,i.version=e.meta.version,t._parse(i,e.data),i},get_data:function(e){var t=u.node_array,i={};return i.meta={name:e.name,author:e.author,version:e.version},i.format="node_array",i.data=[],t._array(e,i.data),i},_parse:function(e,t){var i=u.node_array,n=t.slice(0);n.reverse();var o=i._extract_root(e,n);o?i._extract_subnode(e,o,n):s.error("root node can not be found")},_extract_root:function(e,t){for(var i=u.node_array,n=t.length;n--;)if("isroot"in t[n]&&t[n].isroot){var o=t[n],s=i._extract_data(o),r=e.set_root(o.id,o.topic,s);return t.splice(n,1),r}return null},_extract_subnode:function(e,i,n){for(var o=u.node_array,s=n.length,r=null,a=null,d=0;s--;)if((r=n[s]).parentid==i.id){a=o._extract_data(r);var l=null,h=r.direction;h&&(l="left"==h?t.left:t.right);var _=e.add_node(i,r.id,r.topic,a,l,r.expanded);n.splice(s,1),d++;var c=o._extract_subnode(e,_,n);c>0&&(s=n.length,d+=c)}return d},_extract_data:function(e){var t={};for(var i in e)"id"!=i&&"topic"!=i&&"parentid"!=i&&"isroot"!=i&&"direction"!=i&&"expanded"!=i&&(t[i]=e[i]);return t},_array:function(e,t){u.node_array._array_node(e.root,t)},_array_node:function(e,i){var n=u.node_array;if(e instanceof l){var o={id:e.id,topic:e.topic,expanded:e.expanded};if(e.parent&&(o.parentid=e.parent.id),e.isroot&&(o.isroot=!0),e.parent&&e.parent.isroot&&(o.direction=e.direction==t.left?"left":"right"),null!=e.data){var s=e.data;for(var r in s)o[r]=s[r]}i.push(o);for(var a=e.children.length,d=0;d<a;d++)n._array_node(e.children[d],i)}}},freemind:{example:{meta:_,format:"freemind",data:'<map version="1.0.1"><node ID="root" TEXT="jsMind freemind example"/></map>'},get_mind:function(e){var t=u.freemind,i=new h;i.name=e.meta.name,i.author=e.meta.author,i.version=e.meta.version;var n=e.data,o=t._parse_xml(n),s=t._find_root(o);return t._load_node(i,null,s),i},get_data:function(e){var t=u.freemind,i={};i.meta={name:e.name,author:e.author,version:e.version},i.format="freemind";var n=[];return n.push('<map version="1.0.1">'),t._build_map(e.root,n),n.push("</map>"),i.data=n.join(" "),i},_parse_xml:function(e){var t=null;window.DOMParser?t=(new DOMParser).parseFromString(e,"text/xml"):((t=new ActiveXObject("Microsoft.XMLDOM")).async=!1,t.loadXML(e));return t},_find_root:function(e){for(var t=e.childNodes,i=null,n=null,o=0;o<t.length;o++)if(1==(n=t[o]).nodeType&&"map"==n.tagName){i=n;break}if(i){var s=i.childNodes;i=null;for(o=0;o<s.length;o++)if(1==(n=s[o]).nodeType&&"node"==n.tagName){i=n;break}}return i},_load_node:function(e,i,n){var o=u.freemind,s=n.getAttribute("ID"),r=n.getAttribute("TEXT");if(null==r)for(var a=n.childNodes,d=null,l=0;l<a.length;l++)if(1==(d=a[l]).nodeType&&"richcontent"===d.tagName){r=d.textContent;break}var h=o._load_attributes(n),_=!("expanded"in h)||"true"==h.expanded;delete h.expanded;var c=n.getAttribute("POSITION"),p=null;c&&(p="left"==c?t.left:t.right);var v=null;v=i?e.add_node(i,s,r,h,p,_):e.set_root(s,r,h);var f=n.childNodes,g=null;for(l=0;l<f.length;l++)1==(g=f[l]).nodeType&&"node"==g.tagName&&o._load_node(e,v,g)},_load_attributes:function(e){for(var t=e.childNodes,i=null,n={},o=0;o<t.length;o++)1==(i=t[o]).nodeType&&"attribute"===i.tagName&&(n[i.getAttribute("NAME")]=i.getAttribute("VALUE"));return n},_build_map:function(e,i){var n=u.freemind,o=null;e.parent&&e.parent.isroot&&(o=e.direction===t.left?"left":"right"),i.push("<node"),i.push('ID="'+e.id+'"'),o&&i.push('POSITION="'+o+'"'),i.push('TEXT="'+e.topic+'">'),i.push('<attribute NAME="expanded" VALUE="'+e.expanded+'"/>');var s=e.data;if(null!=s)for(var r in s)i.push('<attribute NAME="'+r+'" VALUE="'+s[r]+'"/>');for(var a=e.children,d=0;d<a.length;d++)n._build_map(a[d],i);i.push("</node>")}},text:{example:{meta:_,format:"text",data:"jsMind text example\n node1\n node1-sub\n node1-sub\n node2"},_line_regex:/\s*/,get_mind:function(e){var t=u.text,i=new h;i.name=e.meta.name,i.author=e.meta.author,i.version=e.meta.version;var n=e.data.split(/\n|\r/);return t._fill_nodes(i,n,0,0),i},_fill_nodes:function(e,t){let i=[],n=0;for(;n<t.length;){let o=t[n],s=o.match(/\s*/)[0].length,r=o.substr(s);if(0==s&&i.length>0)return void log.error("more than 1 root node was found: "+r);if(s>i.length)return void log.error("a suspended node was found: "+r);let d=i.length-s;for(;d--;)i.pop();if(0==s&&0==i.length){let t=e.set_root(a.uuid.newid(),r);i.push(t)}else{let t=e.add_node(i[s-1],a.uuid.newid(),r,{},null);i.push(t)}n++}i.length=0},get_data:function(e){var t=u.text,i={};i.meta={name:e.name,author:e.author,version:e.version},i.format="text";let n=[];return t._build_lines(n,[e.root],0),i.data=n.join("\n"),i},_build_lines:function(e,t,i){let n=new Array(i+1).join(" ");for(let o of t)e.push(n+o.topic),o.children&&u.text._build_lines(e,o.children,i+1)}}};class c{constructor(e){this.jm=e}init(){s.debug("data.init")}reset(){s.debug("data.reset")}load(e){var t=null,i=null;return"node_array"==(t="object"==typeof e?e.format?e.format:"node_tree":"freemind")?i=u.node_array.get_mind(e):"node_tree"==t?i=u.node_tree.get_mind(e):"freemind"==t?i=u.freemind.get_mind(e):"text"==t?i=u.text.get_mind(e):s.warn("unsupported format"),i}get_data(e){var t=null;return"node_array"==e?t=u.node_array.get_data(this.jm.mind):"node_tree"==e?t=u.node_tree.get_data(this.jm.mind):"freemind"==e?t=u.freemind.get_data(this.jm.mind):"text"==e?t=u.text.get_data(this.jm.mind):s.error("unsupported "+e+" format"),t}}class p{constructor(e,t){this.opts=t,this.jm=e,this.isside="side"==this.opts.mode,this.bounds=null,this.cache_valid=!1}init(){s.debug("layout.init")}reset(){s.debug("layout.reset"),this.bounds={n:0,s:0,w:0,e:0}}calculate_next_child_direction(e){if(this.isside)return t.right;for(var i=e.children||[],n=i.length,o=0,s=0;s<n;s++)i[s].direction===t.left?o--:o++;return n>1&&o>0?t.left:t.right}layout(){s.debug("layout.layout"),this.layout_direction(),this.layout_offset()}layout_direction(){this._layout_direction_root()}_layout_direction_root(){var e=this.jm.mind.root,i=null;"layout"in e._data?i=e._data.layout:(i={},e._data.layout=i);var n=e.children,o=n.length;if(i.direction=t.center,i.side_index=0,this.isside)for(var s=o;s--;)this._layout_direction_side(n[s],t.right,s);else{s=o;for(var r=null;s--;)(r=n[s]).direction==t.left?this._layout_direction_side(r,t.left,s):this._layout_direction_side(r,t.right,s)}}_layout_direction_side(e,t,i){var n=null;"layout"in e._data?n=e._data.layout:(n={},e._data.layout=n);var o=e.children,s=o.length;n.direction=t,n.side_index=i;for(var r=s;r--;)this._layout_direction_side(o[r],t,r)}layout_offset(){var e=this.jm.mind.root,i=e._data.layout;i.offset_x=0,i.offset_y=0,i.outer_height=0;for(var n=e.children,o=n.length,s=[],r=[],a=null;o--;)(a=n[o])._data.layout.direction==t.right?r.unshift(a):s.unshift(a);i.left_nodes=s,i.right_nodes=r,i.outer_height_left=this._layout_offset_subnodes(s),i.outer_height_right=this._layout_offset_subnodes(r),this.bounds.e=e._data.view.width/2,this.bounds.w=0-this.bounds.e,this.bounds.n=0,this.bounds.s=Math.max(i.outer_height_left,i.outer_height_right)}_layout_offset_subnodes(e){for(var t=0,i=e.length,n=i,o=null,s=0,r=null,a=0,d=null;n--;)r=(o=e[n])._data.layout,null==d&&(d=o.parent._data),s=this._layout_offset_subnodes(o.children),o.expanded||(s=0,this.set_visible(o.children,!1)),s=Math.max(o._data.view.height,s),o.children.length>1&&(s+=this.opts.cousin_space),r.outer_height=s,r.offset_y=a-s/2,r.offset_x=this.opts.hspace*r.direction+d.view.width*(d.layout.direction+r.direction)/2,o.parent.isroot||(r.offset_x+=this.opts.pspace*r.direction),a=a-s-this.opts.vspace,t+=s;i>1&&(t+=this.opts.vspace*(i-1)),n=i;for(var l=t/2;n--;)(o=e[n])._data.layout.offset_y+=l;return t}_layout_offset_subnodes_height(e){for(var t=0,i=e.length,n=i,o=null,s=0,r=null,a=0,d=null;n--;)r=(o=e[n])._data.layout,null==d&&(d=o.parent._data),s=this._layout_offset_subnodes_height(o.children),o.expanded||(s=0),s=Math.max(o._data.view.height,s),o.children.length>1&&(s+=this.opts.cousin_space),r.outer_height=s,r.offset_y=a-s/2,a=a-s-this.opts.vspace,t+=s;i>1&&(t+=this.opts.vspace*(i-1)),n=i;for(var l=t/2;n--;)(o=e[n])._data.layout.offset_y+=l;return t}get_node_offset(e){var t=e._data.layout,i=null;if("_offset_"in t&&this.cache_valid?i=t._offset_:(i={x:-1,y:-1},t._offset_=i),-1==i.x||-1==i.y){var n=t.offset_x,o=t.offset_y;if(!e.isroot){var s=this.get_node_offset(e.parent);n+=s.x,o+=s.y}i.x=n,i.y=o}return i}get_node_point(e){var t=e._data.view,i=this.get_node_offset(e),n={};return n.x=i.x+t.width*(e._data.layout.direction-1)/2,n.y=i.y-t.height/2,n}get_node_point_in(e){return this.get_node_offset(e)}get_node_point_out(e){var t=e._data.layout,i=null;if("_pout_"in t&&this.cache_valid?i=t._pout_:(i={x:-1,y:-1},t._pout_=i),-1==i.x||-1==i.y)if(e.isroot)i.x=0,i.y=0;else{var n=e._data.view,o=this.get_node_offset(e);i.x=o.x+(n.width+this.opts.pspace)*e._data.layout.direction,i.y=o.y}return i}get_expander_point(e){var i=this.get_node_point_out(e),n={};return e._data.layout.direction==t.right?n.x=i.x-this.opts.pspace:n.x=i.x,n.y=i.y-Math.ceil(this.opts.pspace/2),n}get_min_size(){var e=this.jm.mind.nodes,t=null,i=null;for(var n in e)t=e[n],(i=this.get_node_point_out(t)).x>this.bounds.e&&(this.bounds.e=i.x),i.x<this.bounds.w&&(this.bounds.w=i.x);return{w:this.bounds.e-this.bounds.w,h:this.bounds.s-this.bounds.n}}toggle_node(e){e.isroot||(e.expanded?this.collapse_node(e):this.expand_node(e))}expand_node(e){e.expanded=!0,this.part_layout(e),this.set_visible(e.children,!0),this.jm.invoke_event_handle(i.show,{evt:"expand_node",data:[],node:e.id})}collapse_node(e){e.expanded=!1,this.part_layout(e),this.set_visible(e.children,!1),this.jm.invoke_event_handle(i.show,{evt:"collapse_node",data:[],node:e.id})}expand_all(){var e,t=this.jm.mind.nodes,i=0;for(var n in t)(e=t[n]).expanded||(e.expanded=!0,i++);if(i>0){var o=this.jm.mind.root;this.part_layout(o),this.set_visible(o.children,!0)}}collapse_all(){var e,t=this.jm.mind.nodes,i=0;for(var n in t)(e=t[n]).expanded&&!e.isroot&&(e.expanded=!1,i++);if(i>0){var o=this.jm.mind.root;this.part_layout(o),this.set_visible(o.children,!0)}}expand_to_depth(e,t,i){if(!(e<1))for(var n=t||this.jm.mind.root.children,o=i||1,s=n.length,r=null;s--;)r=n[s],o<e&&(r.expanded||this.expand_node(r),this.expand_to_depth(e,r.children,o+1)),o==e&&r.expanded&&this.collapse_node(r)}part_layout(e){var i=this.jm.mind.root;if(i){var n=i._data.layout;e.isroot?(n.outer_height_right=this._layout_offset_subnodes_height(n.right_nodes),n.outer_height_left=this._layout_offset_subnodes_height(n.left_nodes)):e._data.layout.direction==t.right?n.outer_height_right=this._layout_offset_subnodes_height(n.right_nodes):n.outer_height_left=this._layout_offset_subnodes_height(n.left_nodes),this.bounds.s=Math.max(n.outer_height_left,n.outer_height_right),this.cache_valid=!1}else s.warn("can not found root node")}set_visible(e,t){for(var i=e.length,n=null;i--;)(n=e[i])._data.layout,n.expanded?this.set_visible(n.children,t):this.set_visible(n.children,!1),n.isroot||(n._data.layout.visible=t)}is_expand(e){return e.expanded}is_visible(e){var t=e._data.layout;return!("visible"in t&&!t.visible)}}class v{constructor(e){this.view=e,this.opts=e.opts,this.e_svg=v.c("svg"),this.e_svg.setAttribute("class","jsmind"),this.size={w:0,h:0},this.lines=[],this.line_drawing={straight:this._line_to,curved:this._bezier_to},this.drawing=this.line_drawing[this.opts.line_style]||this.line_drawing.curved}static c(e){return r.d.createElementNS("http://www.w3.org/2000/svg",e)}element(){return this.e_svg}set_size(e,t){this.size.w=e,this.size.h=t,this.e_svg.setAttribute("width",e),this.e_svg.setAttribute("height",t)}clear(){for(var e=this.lines.length;e--;)this.e_svg.removeChild(this.lines[e]);this.lines.length=0}draw_line(e,t,i,n){var o=v.c("path");o.setAttribute("stroke",n||this.opts.line_color),o.setAttribute("stroke-width",this.opts.line_width),o.setAttribute("fill","transparent"),this.lines.push(o),this.e_svg.appendChild(o),this.drawing(o,t.x+i.x,t.y+i.y,e.x+i.x,e.y+i.y)}copy_to(e,t){var i=new Image;i.onload=function(){e.drawImage(i,0,0),t&&t()},i.src="data:image/svg+xml;base64,"+btoa((new XMLSerializer).serializeToString(this.e_svg))}_bezier_to(e,t,i,n,o){e.setAttribute("d","M "+t+" "+i+" C "+(t+2*(n-t)/3)+" "+i+", "+t+" "+o+", "+n+" "+o)}_line_to(e,t,i,n,o){e.setAttribute("d","M "+t+" "+i+" L "+n+" "+o)}}class f{constructor(e){this.opts=e.opts,this.e_canvas=r.c("canvas"),this.e_canvas.className="jsmind",this.canvas_ctx=this.e_canvas.getContext("2d"),this.size={w:0,h:0},this.line_drawing={straight:this._line_to,curved:this._bezier_to},this.drawing=this.line_drawing[this.opts.line_style]||this.line_drawing.curved}element(){return this.e_canvas}set_size(e,t){this.size.w=e,this.size.h=t,this.e_canvas.width=e,this.e_canvas.height=t}clear(){this.canvas_ctx.clearRect(0,0,this.size.w,this.size.h)}draw_line(e,t,i,n){var o=this.canvas_ctx;o.strokeStyle=n||this.opts.line_color,o.lineWidth=this.opts.line_width,o.lineCap="round",this.drawing(o,t.x+i.x,t.y+i.y,e.x+i.x,e.y+i.y)}copy_to(e,t){e.drawImage(this.e_canvas,0,0),t&&t()}_bezier_to(e,t,i,n,o){e.beginPath(),e.moveTo(t,i),e.bezierCurveTo(t+2*(n-t)/3,i,t,o,n,o),e.stroke()}_line_to(e,t,i,n,o){e.beginPath(),e.moveTo(t,i),e.lineTo(n,o),e.stroke()}}class g{constructor(e,t){this.opts=t,this.jm=e,this.layout=e.layout,this.container=null,this.e_panel=null,this.e_nodes=null,this.size={w:0,h:0},this.selected_node=null,this.editing_node=null,this.graph=null,this.render_node=t.custom_node_render?this._custom_node_render:this._default_node_render,this._initialized=!1}init(){if(s.debug(this.opts),s.debug("view.init"),this.container=r.i(this.opts.container)?this.opts.container:r.g(this.opts.container),this.container){var e;this.graph=(e=this,"svg"===this.opts.engine.toLowerCase()?new v(e):new f(e)),this.e_panel=r.c("div"),this.e_nodes=r.c("jmnodes"),this.e_editor=r.c("input"),this.e_panel.className="jsmind-inner jmnode-overflow-"+this.opts.node_overflow,this.e_panel.tabIndex=1,this.e_panel.appendChild(this.graph.element()),this.e_panel.appendChild(this.e_nodes),this.e_editor.className="jsmind-editor",this.e_editor.type="text",this.zoom_current=1;var t=this;r.on(this.e_editor,"keydown",(function(e){var i=e||event;13==i.keyCode&&(t.edit_node_end(),i.stopPropagation())})),r.on(this.e_editor,"blur",(function(e){t.edit_node_end()})),this.container.appendChild(this.e_panel),this.container.offsetParent||new IntersectionObserver(((e,t)=>{e[0].isIntersecting&&(t.unobserve(this.e_panel),this.resize())})).observe(this.e_panel)}else s.error("the options.view.container was not be found in dom")}add_event(e,t,i,n){let o=n?this.e_panel:this.e_nodes;r.on(o,t,(function(t){var n=t||event;i.call(e,n)}))}get_binded_nodeid(e){if(null==e)return null;var t=e.tagName.toLowerCase();return"jmnode"==t||"jmexpander"==t?e.getAttribute("nodeid"):"jmnodes"==t||"body"==t||"html"==t?null:this.get_binded_nodeid(e.parentElement)}is_node(e){if(null==e)return!1;var t=e.tagName.toLowerCase();return"jmnode"==t||"jmnodes"!=t&&"body"!=t&&"html"!=t&&this.is_node(e.parentElement)}is_expander(e){return"jmexpander"==e.tagName.toLowerCase()}reset(){s.debug("view.reset"),this.selected_node=null,this.clear_lines(),this.clear_nodes(),this.reset_theme()}reset_theme(){var e=this.jm.options.theme;this.e_nodes.className=e?"theme-"+e:""}reset_custom_style(){var e=this.jm.mind.nodes;for(var t in e)this.reset_node_custom_style(e[t])}load(){s.debug("view.load"),this.setup_canvas_draggable(this.opts.draggable),this.init_nodes(),this._initialized=!0}expand_size(){var e=this.layout.get_min_size(),t=e.w+2*this.opts.hmargin,i=e.h+2*this.opts.vmargin,n=this.e_panel.clientWidth,o=this.e_panel.clientHeight;n<t&&(n=t),o<i&&(o=i),this.size.w=n,this.size.h=o}init_nodes_size(e){var t=e._data.view;t.width=t.element.clientWidth,t.height=t.element.clientHeight}init_nodes(){var e=this.jm.mind.nodes,t=r.d.createDocumentFragment();for(var i in e)this.create_node_element(e[i],t);this.e_nodes.appendChild(t),this.run_in_c11y_mode_if_needed((()=>{for(var t in e)this.init_nodes_size(e[t])}))}add_node(e){this.create_node_element(e,this.e_nodes),this.run_in_c11y_mode_if_needed((()=>{this.init_nodes_size(e)}))}run_in_c11y_mode_if_needed(e){this.container.offsetParent?e():(s.warn("init nodes in compatibility mode. because the container or its parent has style {display:none}. "),this.e_panel.style.position="absolute",this.e_panel.style.top="-100000",r.d.body.appendChild(this.e_panel),e(),this.container.appendChild(this.e_panel),this.e_panel.style.position=null,this.e_panel.style.top=null)}create_node_element(e,t){var i=null;"view"in e._data?i=e._data.view:(i={},e._data.view=i);var n=r.c("jmnode");if(e.isroot)n.className="root";else{var o=r.c("jmexpander");r.t(o,"-"),o.setAttribute("nodeid",e.id),o.style.visibility="hidden",t.appendChild(o),i.expander=o}e.topic&&this.render_node(n,e),n.setAttribute("nodeid",e.id),n.style.visibility="hidden",this._reset_node_custom_style(n,e.data),t.appendChild(n),i.element=n}remove_node(e){null!=this.selected_node&&this.selected_node.id==e.id&&(this.selected_node=null),null!=this.editing_node&&this.editing_node.id==e.id&&(e._data.view.element.removeChild(this.e_editor),this.editing_node=null);for(var t=e.children,i=t.length;i--;)this.remove_node(t[i]);if(e._data.view){var n=e._data.view.element,o=e._data.view.expander;this.e_nodes.removeChild(n),this.e_nodes.removeChild(o),e._data.view.element=null,e._data.view.expander=null}}update_node(e){var t=e._data.view,i=t.element;if(e.topic&&this.render_node(i,e),this.layout.is_visible(e))t.width=i.clientWidth,t.height=i.clientHeight;else{let e=i.getAttribute("style");i.style="visibility: visible; left:0; top:0;",t.width=i.clientWidth,t.height=i.clientHeight,i.style=e}}select_node(e){if(this.selected_node){var t=this.selected_node._data.view.element;t.className=t.className.replace(/\s*selected\b/i,""),this.restore_selected_node_custom_style(this.selected_node)}e&&(this.selected_node=e,e._data.view.element.className+=" selected",this.clear_selected_node_custom_style(e))}select_clear(){this.select_node(null)}get_editing_node(){return this.editing_node}is_editing(){return!!this.editing_node}edit_node_begin(e){if(e.topic){null!=this.editing_node&&this.edit_node_end(),this.editing_node=e;var t=e._data.view.element,i=e.topic,n=getComputedStyle(t);this.e_editor.value=i,this.e_editor.style.width=t.clientWidth-parseInt(n.getPropertyValue("padding-left"))-parseInt(n.getPropertyValue("padding-right"))+"px",t.innerHTML="",t.appendChild(this.e_editor),t.style.zIndex=5,this.e_editor.focus(),this.e_editor.select()}else s.warn("don't edit image nodes")}edit_node_end(){if(null!=this.editing_node){var e=this.editing_node;this.editing_node=null;var t=e._data.view.element,i=this.e_editor.value;t.style.zIndex="auto",t.removeChild(this.e_editor),a.text.is_empty(i)||e.topic===i?this.render_node(t,e):this.jm.update_node(e.id,i)}this.e_panel.focus()}get_view_offset(){var e=this.layout.bounds;return{x:(this.size.w-e.e-e.w)/2,y:this.size.h/2}}resize(){this.graph.set_size(1,1),this.e_nodes.style.width="1px",this.e_nodes.style.height="1px",this.expand_size(),this._show()}_show(){this.graph.set_size(this.size.w,this.size.h),this.e_nodes.style.width=this.size.w+"px",this.e_nodes.style.height=this.size.h+"px",this.show_nodes(),this.show_lines(),this.jm.invoke_event_handle(i.resize,{data:[]})}zoom_in(e){return this.set_zoom(this.zoom_current+this.opts.zoom.step,e)}zoom_out(e){return this.set_zoom(this.zoom_current-this.opts.zoom.step,e)}set_zoom(e,t){if(e<this.opts.zoom.min||e>this.opts.zoom.max)return!1;let i=this.e_panel.getBoundingClientRect();if(e<1&&e<this.zoom_current&&this.size.w*e<i.width&&this.size.h*e<i.height)return!1;let n=t?{x:t.x-i.x,y:t.y-i.y}:{x:i.width/2,y:i.height/2},o=(this.e_panel.scrollLeft+n.x)*e/this.zoom_current-n.x,s=(this.e_panel.scrollTop+n.y)*e/this.zoom_current-n.y;this.zoom_current=e;for(var r=0;r<this.e_panel.children.length;r++)this.e_panel.children[r].style.zoom=e;return this._show(),this.e_panel.scrollLeft=o,this.e_panel.scrollTop=s,!0}show(e){s.debug("view.show"),this.expand_size(),this._show(),e&&this.center_node(this.jm.mind.root)}relayout(){this.expand_size(),this._show()}save_location(e){var t=e._data.view;t._saved_location={x:parseInt(t.element.style.left)-this.e_panel.scrollLeft,y:parseInt(t.element.style.top)-this.e_panel.scrollTop}}restore_location(e){var t=e._data.view;this.e_panel.scrollLeft=parseInt(t.element.style.left)-t._saved_location.x,this.e_panel.scrollTop=parseInt(t.element.style.top)-t._saved_location.y}clear_nodes(){var e=this.jm.mind;if(null!=e){var t=e.nodes,i=null;for(var n in t)(i=t[n])._data.view.element=null,i._data.view.expander=null;this.e_nodes.innerHTML=""}}show_nodes(){var e=this.jm.mind.nodes,t=null,i=null,n=null,o=null,s=this.get_view_offset();for(var r in e)i=(o=(t=e[r])._data.view).element,this.layout.is_visible(t)?(this.reset_node_custom_style(t),n=this.layout.get_node_point(t),o.abs_x=s.x+n.x,o.abs_y=s.y+n.y,i.style.left=s.x+n.x+"px",i.style.top=s.y+n.y+"px",i.style.display="",i.style.visibility="visible",this._show_expander(t,s)):(i.style.display="none",o.expander.style.display="none")}_show_expander(e,t){if(e.isroot)return;var i=e._data.view.expander;if(0==e.children.length)return i.style.display="none",void(i.style.visibility="hidden");let n=this._get_expander_text(e);r.t(i,n);let o=this.layout.get_expander_point(e);i.style.left=t.x+o.x+"px",i.style.top=t.y+o.y+"px",i.style.display="",i.style.visibility="visible"}_get_expander_text(e){let t=this.opts.expander_style?this.opts.expander_style.toLowerCase():"char";return"number"===t?e.children.length>99?"...":e.children.length:"char"===t?e.expanded?"-":"+":void 0}_default_node_render(e,t){this.opts.support_html?r.h(e,t.topic):r.t(e,t.topic)}_custom_node_render(e,t){this.opts.custom_node_render(this.jm,e,t)||this._default_node_render(e,t)}reset_node_custom_style(e){this._reset_node_custom_style(e._data.view.element,e.data)}_reset_node_custom_style(e,t){if("background-color"in t&&(e.style.backgroundColor=t["background-color"]),"foreground-color"in t&&(e.style.color=t["foreground-color"]),"width"in t&&(e.style.width=t.width+"px"),"height"in t&&(e.style.height=t.height+"px"),"font-size"in t&&(e.style.fontSize=t["font-size"]+"px"),"font-weight"in t&&(e.style.fontWeight=t["font-weight"]),"font-style"in t&&(e.style.fontStyle=t["font-style"]),"background-image"in t){var i=t["background-image"];if(i.startsWith("data")&&t.width&&t.height){var n=new Image;n.onload=function(){var t=r.c("canvas");t.width=e.clientWidth,t.height=e.clientHeight;if(t.getContext){t.getContext("2d").drawImage(this,2,2,e.clientWidth,e.clientHeight);var i=t.toDataURL();e.style.backgroundImage="url("+i+")"}},n.src=i}else e.style.backgroundImage="url("+i+")";e.style.backgroundSize="99%","background-rotation"in t&&(e.style.transform="rotate("+t["background-rotation"]+"deg)")}}restore_selected_node_custom_style(e){var t=e._data.view.element,i=e.data;"background-color"in i&&(t.style.backgroundColor=i["background-color"]),"foreground-color"in i&&(t.style.color=i["foreground-color"])}clear_selected_node_custom_style(e){var t=e._data.view.element;t.style.backgroundColor="",t.style.color=""}clear_lines(){this.graph.clear()}show_lines(){this.clear_lines();var e=this.jm.mind.nodes,t=null,i=null,n=null,o=null,s=this.get_view_offset();for(var r in e)(t=e[r]).isroot||this.layout.is_visible(t)&&(i=this.layout.get_node_point_in(t),n=this.layout.get_node_point_out(t.parent),o=t.data["leading-line-color"],this.graph.draw_line(n,i,s,o))}setup_canvas_draggable(e){if(this.opts.draggable=e,!this._initialized){let e,t,i=!1;this.opts.hide_scrollbars_when_draggable&&(this.e_panel.style="overflow: hidden"),r.on(this.container,"mousedown",(n=>{this.opts.draggable&&(i=!0,e=n.clientX,t=n.clientY)})),r.on(this.container,"mouseup",(()=>{i=!1})),r.on(this.container,"mousemove",(n=>{this.opts.draggable&&i&&(this.e_panel.scrollBy(e-n.clientX,t-n.clientY),e=n.clientX,t=n.clientY)}))}}center_node(e){if(!this.layout.is_visible(e))return s.warn("can not scroll to the node, because it is invisible"),!1;let t=e._data.view,i=this.e_panel.getBoundingClientRect(),n=t.abs_x+t.width/2,o=t.abs_y+t.height/2;return this.e_panel.scrollTo(n*this.zoom_current-i.width/2,o*this.zoom_current-i.height/2),!0}zoomIn(e){return s.warn("please use zoom_in instead"),this.zoom_in(e)}zoomOut(e){return s.warn("please use zoom_out instead"),this.zoom_out(e)}setZoom(e,t){return s.warn("please use set_zoom instead"),this.set_zoom(e,t)}}class m{constructor(e,t){this.jm=e,this.opts=t,this.mapping=t.mapping,this.handles=t.handles,this._newid=null,this._mapping={}}init(){for(var e in r.on(this.jm.view.e_panel,"keydown",this.handler.bind(this)),this.handles.addchild=this.handle_addchild,this.handles.addbrother=this.handle_addbrother,this.handles.editnode=this.handle_editnode,this.handles.delnode=this.handle_delnode,this.handles.toggle=this.handle_toggle,this.handles.up=this.handle_up,this.handles.down=this.handle_down,this.handles.left=this.handle_left,this.handles.right=this.handle_right,this.mapping)if(this.mapping[e]&&e in this.handles){let t=this.mapping[e];Array.isArray(t)||(t=[t]);for(let i of t)this._mapping[i]=this.handles[e]}"function"==typeof this.opts.id_generator?this._newid=this.opts.id_generator:this._newid=a.uuid.newid}enable_shortcut(){this.opts.enable=!0}disable_shortcut(){this.opts.enable=!1}handler(e){if(9==e.which&&e.preventDefault(),!this.jm.view.is_editing()){var t=e||event;if(!this.opts.enable)return!0;var i=t.keyCode+(t.metaKey<<13)+(t.ctrlKey<<12)+(t.altKey<<11)+(t.shiftKey<<10);i in this._mapping&&this._mapping[i].call(this,this.jm,e)}}handle_addchild(e,t){var i=e.get_selected_node();if(i){var n=this._newid();e.add_node(i,n,"New Node")&&(e.select_node(n),e.begin_edit(n))}}handle_addbrother(e,t){var i=e.get_selected_node();if(i&&!i.isroot){var n=this._newid();e.insert_node_after(i,n,"New Node")&&(e.select_node(n),e.begin_edit(n))}}handle_editnode(e,t){var i=e.get_selected_node();i&&e.begin_edit(i)}handle_delnode(e,t){var i=e.get_selected_node();i&&!i.isroot&&(e.select_node(i.parent),e.remove_node(i))}handle_toggle(e,t){var i=t||event,n=e.get_selected_node();n&&(e.toggle_node(n.id),i.stopPropagation(),i.preventDefault())}handle_up(e,t){var i=t||event,n=e.get_selected_node();if(n){var o=e.find_node_before(n);if(!o){var s=e.find_node_before(n.parent);s&&s.children.length>0&&(o=s.children[s.children.length-1])}o&&e.select_node(o),i.stopPropagation(),i.preventDefault()}}handle_down(e,t){var i=t||event,n=e.get_selected_node();if(n){var o=e.find_node_after(n);if(!o){var s=e.find_node_after(n.parent);s&&s.children.length>0&&(o=s.children[0])}o&&e.select_node(o),i.stopPropagation(),i.preventDefault()}}handle_left(e,i){this._handle_direction(e,i,t.left)}handle_right(e,i){this._handle_direction(e,i,t.right)}_handle_direction(e,t,i){var n=t||event,o=e.get_selected_node(),s=null;if(o){if(o.isroot){for(var r=o.children,a=[],d=0;d<r.length;d++)r[d].direction===i&&a.push(d);s=r[a[Math.floor((a.length-1)/2)]]}else if(o.direction===i){var l=(a=o.children).length;l>0&&(s=a[Math.floor((l-1)/2)])}else s=o.parent;s&&e.select_node(s),n.stopPropagation(),n.preventDefault()}}}const w={plugins:[]};function y(e){if(!(e instanceof x))throw new Error("can not register plugin, it is not an instance of Plugin");if(w.plugins.map((e=>e.name)).includes(e.name))throw new Error("can not register plugin "+e.name+": plugin name already exist");w.plugins.push(e)}function b(e,t){r.w.setTimeout((function(){!function(e,t){w.plugins.forEach((i=>i.fn_init(e,t[i.name])))}(e,t)}),0)}class x{constructor(e,t){if(!e)throw new Error("plugin must has a name");if(!t||"function"!=typeof t)throw new Error("plugin must has an init function");this.name=e,this.fn_init=t}}class z{static mind=h;static node=l;static direction=t;static event_type=i;static $=r;static plugin=x;static register_plugin=y;static util=a;constructor(t){z.current=this,this.options=function(e){var t={};if(a.json.merge(t,d),a.json.merge(t,e),!t.container)throw new Error("the options.container should not be null or empty.");return t}(t),s.level(n[this.options.log_level]),this.version=e,this.initialized=!1,this.mind=null,this.event_handles=[],this.init()}init(){if(!this.initialized){this.initialized=!0;var e={mode:this.options.mode,hspace:this.options.layout.hspace,vspace:this.options.layout.vspace,pspace:this.options.layout.pspace,cousin_space:this.options.layout.cousin_space},t={container:this.options.container,support_html:this.options.support_html,engine:this.options.view.engine,hmargin:this.options.view.hmargin,vmargin:this.options.view.vmargin,line_width:this.options.view.line_width,line_color:this.options.view.line_color,line_style:this.options.view.line_style,draggable:this.options.view.draggable,hide_scrollbars_when_draggable:this.options.view.hide_scrollbars_when_draggable,node_overflow:this.options.view.node_overflow,zoom:this.options.view.zoom,custom_node_render:this.options.view.custom_node_render,expander_style:this.options.view.expander_style};this.data=new c(this),this.layout=new p(this,e),this.view=new g(this,t),this.shortcut=new m(this,this.options.shortcut),this.data.init(),this.layout.init(),this.view.init(),this.shortcut.init(),this._event_bind(),b(this,this.options.plugin)}}get_editable(){return this.options.editable}enable_edit(){this.options.editable=!0}disable_edit(){this.options.editable=!1}get_view_draggable(){return this.options.view.draggable}enable_view_draggable(){this.options.view.draggable=!0,this.view.setup_canvas_draggable(!0)}disable_view_draggable(){this.options.view.draggable=!1,this.view.setup_canvas_draggable(!1)}enable_event_handle(e){this.options.default_event_handle["enable_"+e+"_handle"]=!0}disable_event_handle(e){this.options.default_event_handle["enable_"+e+"_handle"]=!1}set_theme(e){var t=this.options.theme;this.options.theme=e||null,t!=this.options.theme&&(this.view.reset_theme(),this.view.reset_custom_style())}_event_bind(){this.view.add_event(this,"mousedown",this.mousedown_handle),this.view.add_event(this,"click",this.click_handle),this.view.add_event(this,"dblclick",this.dblclick_handle),this.view.add_event(this,"mousewheel",this.mousewheel_handle,!0)}mousedown_handle(e){if(this.options.default_event_handle.enable_mousedown_handle){var t=e.target||event.srcElement,i=this.view.get_binded_nodeid(t);i?this.view.is_node(t)&&this.select_node(i):this.select_clear()}}click_handle(e){if(this.options.default_event_handle.enable_click_handle){var t=e.target||event.srcElement;if(this.view.is_expander(t)){var i=this.view.get_binded_nodeid(t);i&&this.toggle_node(i)}}}dblclick_handle(e){if(this.options.default_event_handle.enable_dblclick_handle&&this.get_editable()){var t=e.target||event.srcElement;if(this.view.is_node(t)){var i=this.view.get_binded_nodeid(t);i&&this.begin_edit(i)}}}mousewheel_handle(e){if(this.options.default_event_handle.enable_mousewheel_handle&&e.ctrlKey){var t=e||event;t.preventDefault(),t.deltaY<0?this.view.zoom_in(t):this.view.zoom_out(t)}}begin_edit(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.begin_edit(t):(s.error("the node[id="+e+"] can not be found."),!1)}this.get_editable()?this.view.edit_node_begin(e):s.error("fail, this mind map is not editable.")}end_edit(){this.view.edit_node_end()}toggle_node(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.toggle_node(t):void s.error("the node[id="+e+"] can not be found.")}e.isroot||(this.view.save_location(e),this.layout.toggle_node(e),this.view.relayout(),this.view.restore_location(e))}expand_node(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.expand_node(t):void s.error("the node[id="+e+"] can not be found.")}e.isroot||(this.view.save_location(e),this.layout.expand_node(e),this.view.relayout(),this.view.restore_location(e))}collapse_node(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.collapse_node(t):void s.error("the node[id="+e+"] can not be found.")}e.isroot||(this.view.save_location(e),this.layout.collapse_node(e),this.view.relayout(),this.view.restore_location(e))}expand_all(){this.layout.expand_all(),this.view.relayout()}collapse_all(){this.layout.collapse_all(),this.view.relayout()}expand_to_depth(e){this.layout.expand_to_depth(e),this.view.relayout()}_reset(){this.view.reset(),this.layout.reset(),this.data.reset()}_show(e){var t=e||u.node_array.example;this.mind=this.data.load(t),this.mind?(s.debug("data.load ok"),this.view.load(),s.debug("view.load ok"),this.layout.layout(),s.debug("layout.layout ok"),this.view.show(!0),s.debug("view.show ok"),this.invoke_event_handle(i.show,{data:[e]})):s.error("data.load error")}show(e){this._reset(),this._show(e)}get_meta(){return{name:this.mind.name,author:this.mind.author,version:this.mind.version}}get_data(e){var t=e||"node_tree";return this.data.get_data(t)}get_root(){return this.mind.root}get_node(e){return l.is_node(e)?e:this.mind.get_node(e)}add_node(e,n,o,r,a){if(this.get_editable()){var d=this.get_node(e),l=t.of(a);void 0===l&&(l=this.layout.calculate_next_child_direction(d));var h=this.mind.add_node(d,n,o,r,l);return h&&(this.view.add_node(h),this.layout.layout(),this.view.show(!1),this.view.reset_node_custom_style(h),this.expand_node(d),this.invoke_event_handle(i.edit,{evt:"add_node",data:[d.id,n,o,r,l],node:n})),h}return s.error("fail, this mind map is not editable"),null}insert_node_before(e,n,o,r,a){if(this.get_editable()){var d=this.get_node(e),l=t.of(a);void 0===l&&(l=this.layout.calculate_next_child_direction(d.parent));var h=this.mind.insert_node_before(d,n,o,r,l);return h&&(this.view.add_node(h),this.layout.layout(),this.view.show(!1),this.invoke_event_handle(i.edit,{evt:"insert_node_before",data:[d.id,n,o,r,l],node:n})),h}return s.error("fail, this mind map is not editable"),null}insert_node_after(e,n,o,r,a){if(this.get_editable()){var d=this.get_node(e),l=t.of(a);void 0===l&&(l=this.layout.calculate_next_child_direction(d.parent));var h=this.mind.insert_node_after(d,n,o,r,l);return h&&(this.view.add_node(h),this.layout.layout(),this.view.show(!1),this.invoke_event_handle(i.edit,{evt:"insert_node_after",data:[d.id,n,o,r,l],node:n})),h}return s.error("fail, this mind map is not editable"),null}remove_node(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.remove_node(t):(s.error("the node[id="+e+"] can not be found."),!1)}if(this.get_editable()){if(e.isroot)return s.error("fail, can not remove root node"),!1;var n=e.id,o=e.parent.id,r=this.get_node(o);return this.view.save_location(r),this.view.remove_node(e),this.mind.remove_node(e),this.layout.layout(),this.view.show(!1),this.view.restore_location(r),this.invoke_event_handle(i.edit,{evt:"remove_node",data:[n],node:o}),!0}return s.error("fail, this mind map is not editable"),!1}update_node(e,t){if(this.get_editable())if(a.text.is_empty(t))s.warn("fail, topic can not be empty");else{var n=this.get_node(e);if(n){if(n.topic===t)return s.info("nothing changed"),void this.view.update_node(n);n.topic=t,this.view.update_node(n),this.layout.layout(),this.view.show(!1),this.invoke_event_handle(i.edit,{evt:"update_node",data:[e,t],node:e})}}else s.error("fail, this mind map is not editable")}move_node(e,t,n,o){if(this.get_editable()){var r=this.get_node(e),a=this.mind.move_node(r,t,n,o);a&&(this.view.update_node(a),this.layout.layout(),this.view.show(!1),this.invoke_event_handle(i.edit,{evt:"move_node",data:[e,t,n,o],node:e}))}else s.error("fail, this mind map is not editable")}select_node(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.select_node(t):void s.error("the node[id="+e+"] can not be found.")}this.layout.is_visible(e)&&(this.mind.selected=e,this.view.select_node(e),this.invoke_event_handle(i.select,{evt:"select_node",data:[],node:e.id}))}get_selected_node(){return this.mind?this.mind.selected:null}select_clear(){this.mind&&(this.mind.selected=null,this.view.select_clear())}is_node_visible(e){return this.layout.is_visible(e)}scroll_node_to_center(e){if(l.is_node(e))this.view.center_node(e);else{var t=this.get_node(e);t?this.scroll_node_to_center(t):s.error("the node[id="+e+"] can not be found.")}}find_node_before(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.find_node_before(t):void s.error("the node[id="+e+"] can not be found.")}if(e.isroot)return null;var i=null;if(e.parent.isroot)for(var n=e.parent.children,o=null,r=null,a=0;a<n.length;a++)r=n[a],e.direction===r.direction&&(e.id===r.id&&(i=o),o=r);else i=this.mind.get_node_before(e);return i}find_node_after(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.find_node_after(t):void s.error("the node[id="+e+"] can not be found.")}if(e.isroot)return null;var i=null;if(e.parent.isroot){for(var n=e.parent.children,o=!1,r=null,a=0;a<n.length;a++)if(r=n[a],e.direction===r.direction){if(o){i=r;break}e.id===r.id&&(o=!0)}}else i=this.mind.get_node_after(e);return i}set_node_color(e,t,i){if(!this.get_editable())return s.error("fail, this mind map is not editable"),null;var n=this.mind.get_node(e);n&&(t&&(n.data["background-color"]=t),i&&(n.data["foreground-color"]=i),this.view.reset_node_custom_style(n))}set_node_font_style(e,t,i,n){if(!this.get_editable())return s.error("fail, this mind map is not editable"),null;var o=this.mind.get_node(e);o&&(t&&(o.data["font-size"]=t),i&&(o.data["font-weight"]=i),n&&(o.data["font-style"]=n),this.view.reset_node_custom_style(o),this.view.update_node(o),this.layout.layout(),this.view.show(!1))}set_node_background_image(e,t,i,n,o){if(!this.get_editable())return s.error("fail, this mind map is not editable"),null;var r=this.mind.get_node(e);r&&(t&&(r.data["background-image"]=t),i&&(r.data.width=i),n&&(r.data.height=n),o&&(r.data["background-rotation"]=o),this.view.reset_node_custom_style(r),this.view.update_node(r),this.layout.layout(),this.view.show(!1))}set_node_background_rotation(e,t){if(!this.get_editable())return s.error("fail, this mind map is not editable"),null;var i=this.mind.get_node(e);if(i){if(!i.data["background-image"])return s.error("fail, only can change rotation angle of node with background image"),null;i.data["background-rotation"]=t,this.view.reset_node_custom_style(i),this.view.update_node(i),this.layout.layout(),this.view.show(!1)}}resize(){this.view.resize()}add_event_listener(e){"function"==typeof e&&this.event_handles.push(e)}clear_event_listener(){this.event_handles=[]}invoke_event_handle(e,t){var i=this;r.w.setTimeout((function(){i._invoke_event_handle(e,t)}),0)}_invoke_event_handle(e,t){for(var i=this.event_handles.length,n=0;n<i;n++)this.event_handles[n](e,t)}static show(e,t){s.warn("`jsMind.show(options, mind)` is deprecated, please use `jm = new jsMind(options); jm.show(mind);` instead");var i=new z(e);return i.show(t),i}}return z}));
//# sourceMappingURL=jsmind.js.map
\ No newline at end of file
/**
* @license BSD-3-Clause
* @copyright 2014-2023 hizzgdev@163.com
*
* Project Home:
* https://github.com/hizzgdev/jsmind/
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("jsmind"),require("dom-to-image")):"function"==typeof define&&define.amd?define(["jsmind","dom-to-image"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jsMind,e.domtoimage)}(this,(function(e,t){"use strict";function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=i(e),o=i(t);if(!n.default)throw new Error("jsMind is not defined");if(!o.default)throw new Error("dom-to-image is required");const r=n.default.$,a={filename:null,watermark:{left:r.w.location,right:"https://github.com/hizzgdev/jsmind"}};class s{constructor(e,t){var i={};n.default.util.json.merge(i,a),n.default.util.json.merge(i,t),this.version="0.2.0",this.jm=e,this.options=i}shoot(){let e=this.create_canvas(),t=e.getContext("2d");Promise.resolve(t).then((()=>this.draw_lines(t))).then((()=>this.draw_nodes(t))).then((()=>this.draw_watermark(e,t))).then((()=>this.download(e))).then((()=>this.clear(e)))}create_canvas(){let e=r.c("canvas");return e.width=this.jm.view.size.w,e.height=this.jm.view.size.h,e.style.visibility="hidden",this.jm.view.e_panel.appendChild(e),e}clear(e){e.parentNode.removeChild(e)}draw_lines(e){return new Promise(function(t,i){this.jm.view.graph.copy_to(e,(function(){t(e)}))}.bind(this))}draw_nodes(e){return o.default.toSvg(this.jm.view.e_nodes,{style:{zoom:1}}).then(this.load_image).then((function(t){return e.drawImage(t,0,0),e}))}draw_watermark(e,t){return t.textBaseline="bottom",t.fillStyle="#000",t.font="11px Verdana,Arial,Helvetica,sans-serif",this.options.watermark.left&&(t.textAlign="left",t.fillText(this.options.watermark.left,5.5,e.height-2.5)),this.options.watermark.right&&(t.textAlign="right",t.fillText(this.options.watermark.right,e.width-5.5,e.height-2.5)),t}load_image(e){return new Promise((function(t,i){let n=new Image;n.onload=function(){t(n)},n.onerror=i,n.src=e}))}download(e){var t=(this.options.filename||this.jm.mind.name)+".png";if(navigator.msSaveBlob&&e.msToBlob){var i=e.msToBlob();navigator.msSaveBlob(i,t)}else{var n=e.toDataURL(),o=r.c("a");if("download"in o){o.style.visibility="hidden",o.href=n,o.download=t,r.d.body.appendChild(o);var a=r.d.createEvent("MouseEvents");a.initEvent("click",!0,!0),o.dispatchEvent(a),r.d.body.removeChild(o)}else location.href=n}}}let d=new n.default.plugin("screenshot",(function(e,t){var i=new s(e,t);e.screenshot=i,e.shoot=function(){i.shoot()}}));n.default.register_plugin(d)}));
//# sourceMappingURL=jsmind.screenshot.js.map
\ No newline at end of file
/**
* @title: 国密sm4
* @description: 工具类-基于gm-crypt改造为适合无脚手架的js项目
* @author: 杨朋朋
* @date: 2023/04/10 下午8:23
* @version: V1.0
*/
/*使用
*引入<script src="./sm4.js"></script>
* key:加解密秘钥(前后台对应)
* iv:cbc模式下需配置iv参数(iv:偏移量)
* cbc加密 encrypt_cbc('加密内容', key, iv)
* cbc解密 decrypt_cbc('解密内容', key, iv)
* ecb加密 encrypt_ecb('加密内容', key)
* ecb解密 decrypt_ecb('解密内容', key)
*/
(function(r) {
if (typeof exports === "object" && typeof module !== "undefined") {
module.exports = r()
} else if (typeof define === "function" && define.amd) {
define([], r)
} else {
var e;
if (typeof window !== "undefined") {
e = window
} else if (typeof global !== "undefined") {
e = global
} else if (typeof self !== "undefined") {
e = self
} else {
e = this
}
e.base64js = r()
}
})(function() {
var r, e, t;
return function r(e, t, n) {
function o(i, a) {
if (!t[i]) {
if (!e[i]) {
var u = typeof require == "function" && require;
if (!a && u) return u(i, !0);
if (f) return f(i, !0);
var d = new Error("Cannot find module '" + i + "'");
throw d.code = "MODULE_NOT_FOUND", d
}
var c = t[i] = {
exports: {}
};
e[i][0].call(c.exports, function(r) {
var t = e[i][1][r];
return o(t ? t : r)
}, c, c.exports, r, e, t, n)
}
return t[i].exports
}
var f = typeof require == "function" && require;
for (var i = 0; i < n.length; i++) o(n[i]);
return o
}({
"/": [function(r, e, t) {
"use strict";
t.byteLength = c;
t.toByteArray = v;
t.fromByteArray = s;
var n = [];
var o = [];
var f = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
var i = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
for (var a = 0, u = i.length; a < u; ++a) {
n[a] = i[a];
o[i.charCodeAt(a)] = a
}
o["-".charCodeAt(0)] = 62;
o["_".charCodeAt(0)] = 63;
function d(r) {
var e = r.length;
if (e % 4 > 0) {
throw new Error("Invalid string. Length must be a multiple of 4")
}
return r[e - 2] === "=" ? 2 : r[e - 1] === "=" ? 1 : 0
}
function c(r) {
return r.length * 3 / 4 - d(r)
}
function v(r) {
var e, t, n, i, a;
var u = r.length;
i = d(r);
a = new f(u * 3 / 4 - i);
t = i > 0 ? u - 4 : u;
var c = 0;
for (e = 0; e < t; e += 4) {
n = o[r.charCodeAt(e)] << 18 | o[r.charCodeAt(e + 1)] << 12 | o[r.charCodeAt(
e + 2)] << 6 | o[r.charCodeAt(e + 3)];
a[c++] = n >> 16 & 255;
a[c++] = n >> 8 & 255;
a[c++] = n & 255
}
if (i === 2) {
n = o[r.charCodeAt(e)] << 2 | o[r.charCodeAt(e + 1)] >> 4;
a[c++] = n & 255
} else if (i === 1) {
n = o[r.charCodeAt(e)] << 10 | o[r.charCodeAt(e + 1)] << 4 | o[r.charCodeAt(e +
2)] >> 2;
a[c++] = n >> 8 & 255;
a[c++] = n & 255
}
return a
}
function l(r) {
return n[r >> 18 & 63] + n[r >> 12 & 63] + n[r >> 6 & 63] + n[r & 63]
}
function h(r, e, t) {
var n;
var o = [];
for (var f = e; f < t; f += 3) {
n = (r[f] << 16) + (r[f + 1] << 8) + r[f + 2];
o.push(l(n))
}
return o.join("")
}
function s(r) {
var e;
var t = r.length;
var o = t % 3;
var f = "";
var i = [];
var a = 16383;
for (var u = 0, d = t - o; u < d; u += a) {
i.push(h(r, u, u + a > d ? d : u + a))
}
if (o === 1) {
e = r[t - 1];
f += n[e >> 2];
f += n[e << 4 & 63];
f += "=="
} else if (o === 2) {
e = (r[t - 2] << 8) + r[t - 1];
f += n[e >> 10];
f += n[e >> 4 & 63];
f += n[e << 2 & 63];
f += "="
}
i.push(f);
return i.join("")
}
}, {}]
}, {}, [])("/")
});
const Sbox = [
0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7, 0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05,
0x2b, 0x67, 0x9a, 0x76, 0x2a, 0xbe, 0x04, 0xc3, 0xaa, 0x44, 0x13, 0x26, 0x49, 0x86, 0x06, 0x99,
0x9c, 0x42, 0x50, 0xf4, 0x91, 0xef, 0x98, 0x7a, 0x33, 0x54, 0x0b, 0x43, 0xed, 0xcf, 0xac, 0x62,
0xe4, 0xb3, 0x1c, 0xa9, 0xc9, 0x08, 0xe8, 0x95, 0x80, 0xdf, 0x94, 0xfa, 0x75, 0x8f, 0x3f, 0xa6,
0x47, 0x07, 0xa7, 0xfc, 0xf3, 0x73, 0x17, 0xba, 0x83, 0x59, 0x3c, 0x19, 0xe6, 0x85, 0x4f, 0xa8,
0x68, 0x6b, 0x81, 0xb2, 0x71, 0x64, 0xda, 0x8b, 0xf8, 0xeb, 0x0f, 0x4b, 0x70, 0x56, 0x9d, 0x35,
0x1e, 0x24, 0x0e, 0x5e, 0x63, 0x58, 0xd1, 0xa2, 0x25, 0x22, 0x7c, 0x3b, 0x01, 0x21, 0x78, 0x87,
0xd4, 0x00, 0x46, 0x57, 0x9f, 0xd3, 0x27, 0x52, 0x4c, 0x36, 0x02, 0xe7, 0xa0, 0xc4, 0xc8, 0x9e,
0xea, 0xbf, 0x8a, 0xd2, 0x40, 0xc7, 0x38, 0xb5, 0xa3, 0xf7, 0xf2, 0xce, 0xf9, 0x61, 0x15, 0xa1,
0xe0, 0xae, 0x5d, 0xa4, 0x9b, 0x34, 0x1a, 0x55, 0xad, 0x93, 0x32, 0x30, 0xf5, 0x8c, 0xb1, 0xe3,
0x1d, 0xf6, 0xe2, 0x2e, 0x82, 0x66, 0xca, 0x60, 0xc0, 0x29, 0x23, 0xab, 0x0d, 0x53, 0x4e, 0x6f,
0xd5, 0xdb, 0x37, 0x45, 0xde, 0xfd, 0x8e, 0x2f, 0x03, 0xff, 0x6a, 0x72, 0x6d, 0x6c, 0x5b, 0x51,
0x8d, 0x1b, 0xaf, 0x92, 0xbb, 0xdd, 0xbc, 0x7f, 0x11, 0xd9, 0x5c, 0x41, 0x1f, 0x10, 0x5a, 0xd8,
0x0a, 0xc1, 0x31, 0x88, 0xa5, 0xcd, 0x7b, 0xbd, 0x2d, 0x74, 0xd0, 0x12, 0xb8, 0xe5, 0xb4, 0xb0,
0x89, 0x69, 0x97, 0x4a, 0x0c, 0x96, 0x77, 0x7e, 0x65, 0xb9, 0xf1, 0x09, 0xc5, 0x6e, 0xc6, 0x84,
0x18, 0xf0, 0x7d, 0xec, 0x3a, 0xdc, 0x4d, 0x20, 0x79, 0xee, 0x5f, 0x3e, 0xd7, 0xcb, 0x39, 0x48
];
const CK = [
0x00070e15, 0x1c232a31, 0x383f464d, 0x545b6269,
0x70777e85, 0x8c939aa1, 0xa8afb6bd, 0xc4cbd2d9,
0xe0e7eef5, 0xfc030a11, 0x181f262d, 0x343b4249,
0x50575e65, 0x6c737a81, 0x888f969d, 0xa4abb2b9,
0xc0c7ced5, 0xdce3eaf1, 0xf8ff060d, 0x141b2229,
0x30373e45, 0x4c535a61, 0x686f767d, 0x848b9299,
0xa0a7aeb5, 0xbcc3cad1, 0xd8dfe6ed, 0xf4fb0209,
0x10171e25, 0x2c333a41, 0x484f565d, 0x646b7279
];
const FK = [
0xa3b1bac6, 0x56aa3350, 0x677d9197, 0xb27022dc
];
/**
* 将字符串转为Unicode数组
* @example "1234" => [49, 50, 51, 52];
* @param {String} str 要转换的字符串
* @returns {Number[]} 转换后的数组
*/
const stringToArray = (str) => {
if (!/string/gi.test(Object.prototype.toString.call(str))) {
str = JSON.stringify(str);
}
return unescape(encodeURIComponent(str)).split("").map(val => val.charCodeAt());
}
const rotateLeft = (x, y) => {
return x << y | x >>> (32 - y);
}
const tauTransform = (a) => {
return Sbox[a >>> 24 & 0xff] << 24 | Sbox[a >>> 16 & 0xff] << 16 | Sbox[a >>> 8 & 0xff] << 8 | Sbox[a & 0xff];
}
const tTransform1 = (z) => {
let b = tauTransform(z);
let c = b ^ rotateLeft(b, 2) ^ rotateLeft(b, 10) ^ rotateLeft(b, 18) ^ rotateLeft(b, 24);
return c
}
const tTransform2 = (z) => {
let b = tauTransform(z);
let c = b ^ rotateLeft(b, 13) ^ rotateLeft(b, 23);
return c
}
const EncryptRoundKeys = (key) => {
const keys = [];
const mk = [
key[0] << 24 | key[1] << 16 | key[2] << 8 | key[3],
key[4] << 24 | key[5] << 16 | key[6] << 8 | key[7],
key[8] << 24 | key[9] << 16 | key[10] << 8 | key[11],
key[12] << 24 | key[13] << 16 | key[14] << 8 | key[15]
];
let k = new Array(36);
k[0] = mk[0] ^ FK[0];
k[1] = mk[1] ^ FK[1];
k[2] = mk[2] ^ FK[2];
k[3] = mk[3] ^ FK[3];
for (let i = 0; i < 32; i++) {
k[i + 4] = k[i] ^ tTransform2(k[i + 1] ^ k[i + 2] ^ k[i + 3] ^ CK[i]);
keys[i] = k[i + 4];
}
return keys;
}
const UINT8_BLOCK = 16;
const getChainBlock = (arr, baseIndex = 0) => {
let block = [
arr[baseIndex] << 24 | arr[baseIndex + 1] << 16 | arr[baseIndex + 2] << 8 | arr[baseIndex + 3],
arr[baseIndex + 4] << 24 | arr[baseIndex + 5] << 16 | arr[baseIndex + 6] << 8 | arr[baseIndex + 7],
arr[baseIndex + 8] << 24 | arr[baseIndex + 9] << 16 | arr[baseIndex + 10] << 8 | arr[baseIndex + 11],
arr[baseIndex + 12] << 24 | arr[baseIndex + 13] << 16 | arr[baseIndex + 14] << 8 | arr[baseIndex + 15]
];
return block;
}
const doBlockCrypt = (blockData, roundKeys) => {
let xBlock = new Array(36);
blockData.forEach((val, index) => xBlock[index] = val);
// loop to process 32 rounds crypt
for (let i = 0; i < 32; i++) {
xBlock[i + 4] = xBlock[i] ^ tTransform1(xBlock[i + 1] ^ xBlock[i + 2] ^ xBlock[i + 3] ^ roundKeys[i]);
}
let yBlock = [xBlock[35], xBlock[34], xBlock[33], xBlock[32]];
return yBlock;
}
const padding = (originalBuffer) => {
if (originalBuffer === null) {
return null;
}
let paddingLength = UINT8_BLOCK - originalBuffer.length % UINT8_BLOCK;
let paddedBuffer = new Array(originalBuffer.length + paddingLength);
originalBuffer.forEach((val, index) => paddedBuffer[index] = val);
paddedBuffer.fill(paddingLength, originalBuffer.length);
return paddedBuffer;
}
const dePadding = (paddedBuffer) => {
if (paddedBuffer === null) {
return null;
}
let paddingLength = paddedBuffer[paddedBuffer.length - 1];
let originalBuffer = paddedBuffer.slice(0, paddedBuffer.length - paddingLength);
return originalBuffer;
}
const check = (name, str) => {
if (!str || str.length != 16) {
console.error(`${name} should be a 16 bytes string.`);
return false;
}
return true;
}
/**
* CBC加密模式
* @example encrypt_cbc("1234", "1234567890123456", "1234567890123456") => "K++iI4IhSGMnEJZT/jv1ow=="
* @param {any} plaintext 要加密的数据
* @param {String} key
* @param {String} iv
* @param {String} mode base64 | "text"
* @returns {String} 加密后的字符串
*/
const encrypt_cbc = (plaintext, key, iv, mode = "base64") => {
if (!check("iv", iv) && !check("key", key)) {
return;
}
let encryptRoundKeys = EncryptRoundKeys(stringToArray(key));
let plainByteArray = stringToArray(JSON.stringify(plaintext));
let padded = padding(plainByteArray);
let blockTimes = padded.length / UINT8_BLOCK;
let outArray = [];
// init chain with iv (transform to uint32 block)
let chainBlock = getChainBlock(stringToArray(iv));
// console.log(padded, blockTimes, encryptRoundKeys, chainBlock);
for (let i = 0; i < blockTimes; i++) {
// extract the 16 bytes block data for this round to encrypt
let roundIndex = i * UINT8_BLOCK;
let block = getChainBlock(padded, roundIndex);
// xor the chain block
chainBlock[0] = chainBlock[0] ^ block[0];
chainBlock[1] = chainBlock[1] ^ block[1];
chainBlock[2] = chainBlock[2] ^ block[2];
chainBlock[3] = chainBlock[3] ^ block[3];
// use chain block to crypt
let cipherBlock = doBlockCrypt(chainBlock, encryptRoundKeys);
// make the cipher block be part of next chain block
chainBlock = cipherBlock;
for (let l = 0; l < UINT8_BLOCK; l++) {
outArray[roundIndex + l] = cipherBlock[parseInt(l / 4)] >> ((3 - l) % 4 * 8) & 0xff;
}
}
// cipher array to string
if (mode === 'base64') {
return base64js.fromByteArray(outArray);
} else {
// text
return decodeURIComponent(escape(String.fromCharCode(...outArray)));
}
}
/**
* ECB加密模式
* @example encrypt_cbc("1234", "1234567890123456") => "woPrxebr8Xvyo1qG8QxAUA=="
* @param {any} plaintext 要加密的数据
* @param {String} key
* @param {String} mode base64 | "text"
* @returns {String} 加密后的字符串
*/
const encrypt_ecb = (plaintext, key, mode = "base64") => {
//console.log(plaintext, key)
if (!check("key", key)) {
return;
}
let encryptRoundKeys = EncryptRoundKeys(stringToArray(key));
let plainByteArray = stringToArray(JSON.stringify(plaintext));
let padded = padding(plainByteArray);
let blockTimes = padded.length / UINT8_BLOCK;
let outArray = [];
// CBC mode
// init chain with iv (transform to uint32 block)
for (let i = 0; i < blockTimes; i++) {
// extract the 16 bytes block data for this round to encrypt
let roundIndex = i * UINT8_BLOCK;
let block = getChainBlock(padded, roundIndex);
let cipherBlock = doBlockCrypt(block, encryptRoundKeys);
for (let l = 0; l < UINT8_BLOCK; l++) {
outArray[roundIndex + l] = cipherBlock[parseInt(l / 4)] >> ((3 - l) % 4 * 8) & 0xff;
}
}
// cipher array to string
if (mode === 'base64') {
return base64js.fromByteArray(outArray);
} else {
// text
return decodeURIComponent(escape(String.fromCharCode(...outArray)));
}
}
/**
* CBC解密模式
* @example decrypt_cbc("K++iI4IhSGMnEJZT/jv1ow==", "1234567890123456", "1234567890123456") => "1234"
* @param {any} plaintext 要解密的数据
* @param {String} key
* @param {String} iv
* @param {String} mode base64 | "text"
* @returns {String} 解密后的字符串
*/
const decrypt_cbc = (ciphertext, key, iv, mode = "base64") => {
if (!check("iv", iv) && !check("key", key)) {
return;
}
// get cipher byte array
let cipherByteArray = null;
let decryptRoundKeys = EncryptRoundKeys(stringToArray(key)).reverse();
if (mode === 'base64') {
// cipher is base64 string
cipherByteArray = base64js.toByteArray(ciphertext);
} else {
// cipher is text
cipherByteArray = stringToArray(ciphertext);
}
let blockTimes = cipherByteArray.length / UINT8_BLOCK;
let outArray = [];
// init chain with iv (transform to uint32 block)
let chainBlock = getChainBlock(stringToArray(iv));
//console.log(cipherByteArray, decryptRoundKeys, chainBlock)
for (let i = 0; i < blockTimes; i++) {
// extract the 16 bytes block data for this round to encrypt
let roundIndex = i * UINT8_BLOCK;
// make Uint8Array to Uint32Array block
let block = getChainBlock(cipherByteArray, roundIndex);
// reverse the round keys to decrypt
let plainBlockBeforeXor = doBlockCrypt(block, decryptRoundKeys);
// xor the chain block
let plainBlock = [
chainBlock[0] ^ plainBlockBeforeXor[0],
chainBlock[1] ^ plainBlockBeforeXor[1],
chainBlock[2] ^ plainBlockBeforeXor[2],
chainBlock[3] ^ plainBlockBeforeXor[3]
];
// make the cipher block be part of next chain block
chainBlock = block;
for (let l = 0; l < UINT8_BLOCK; l++) {
outArray[roundIndex + l] = plainBlock[parseInt(l / 4)] >> ((3 - l) % 4 * 8) & 0xff;
}
}
// depadding the decrypted data
let depaddedPlaintext = dePadding(outArray);
// transform data to utf8 string
return JSON.parse(decodeURIComponent(escape(String.fromCharCode(...depaddedPlaintext))));
}
/**
* ECB解密模式
* @example decrypt_ecb("woPrxebr8Xvyo1qG8QxAUA==", "1234567890123456") => "1234"
* @param {any} plaintext 要解密的数据
* @param {String} key
* @param {String} mode base64 | "text"
* @returns {String} 解密后的字符串
*/
const decrypt_ecb = (ciphertext, key, mode = "base64") => {
if (!check("key", key)) {
return;
}
// get cipher byte array
let decryptRoundKeys = EncryptRoundKeys(stringToArray(key)).reverse();
let cipherByteArray = null;
if (mode === 'base64') {
// cipher is base64 string
cipherByteArray = base64js.toByteArray(ciphertext);
} else {
// cipher is text
cipherByteArray = stringToArray(ciphertext);
}
let blockTimes = cipherByteArray.length / UINT8_BLOCK;
let outArray = [];
for (let i = 0; i < blockTimes; i++) {
// extract the 16 bytes block data for this round to encrypt
let roundIndex = i * UINT8_BLOCK;
// make Uint8Array to Uint32Array block
let block = getChainBlock(cipherByteArray, roundIndex);
// reverse the round keys to decrypt
let plainBlock = doBlockCrypt(block, decryptRoundKeys);
for (let l = 0; l < UINT8_BLOCK; l++) {
outArray[roundIndex + l] = plainBlock[parseInt(l / 4)] >> ((3 - l) % 4 * 8) & 0xff;
}
}
// depadding the decrypted data
let depaddedPlaintext = dePadding(outArray);
// transform data to utf8 string
return JSON.parse(decodeURIComponent(escape(String.fromCharCode(...depaddedPlaintext))));
}
...@@ -18,6 +18,11 @@ const routes = [ ...@@ -18,6 +18,11 @@ const routes = [
// component: Home // component: Home
}, },
{ {
path: '/jsmindDemo',
name: 'jsmindDemo',
component: () => import('@/views/jsmindDemo/index.vue'),
},
{
path: '/main', path: '/main',
name: 'main', name: 'main',
// route level code-splitting // route level code-splitting
......
...@@ -3,20 +3,23 @@ import axios from 'axios'; ...@@ -3,20 +3,23 @@ import axios from 'axios';
import router from '../router/index.js'; import router from '../router/index.js';
import { Message, MessageBox, Loading } from 'element-ui'; import { Message, MessageBox, Loading } from 'element-ui';
import { SM4Util } from "./sm4";
axios.defaults.timeout = 300000; axios.defaults.timeout = 300000;
axios.defaults.baseURL = process.env.VUE_APP_BASE_URL; axios.defaults.baseURL = process.env.VUE_APP_BASE_URL;
function encryptStringBySM4_CBC(str) {//使用sm4-cbc算法给字符串加密
const sm4 = new SM4Util();
const encryptString = sm4.encryptCustom_CBC(str, 'ZkR_SiNoSOFT=568', 'GJwsXX_BzW=gJWJW');
return encryptString;
}
const result = encrypt_ecb('{"id": "1", name: "2"}', 'TAxH5p1vs3ePYABC'); function decryptStringBySM4_CBC(str) {//使用sm4-cbc算法给字符串解密
const sm4 = new SM4Util();
// const result2 = decrypt_cbc('j7STqWGQdaRM+slFbSvd6MeoCuWnWdRZNvPWDPpbzpQ=', 'E99567ACC5364D69BA0B0BC83066955F', '1234567890123456'); const decryptString = sm4.decryptCustom_CBC(str, 'ZkR_SiNoSOFT=568', 'GJwsXX_BzW=gJWJW');
return decryptString;
console.log(result); }
// console.log(result2);
//http 请求拦截器 //http 请求拦截器
......
/**
* 国密SM4加密算法
* 徐一杰
* 2022/10/18
*
* 调用方法:
* import {SM4Util} from '@/utils/sm4';
* var sm4 = new SM4Util();
* 不使用自定义 secretKey,一般用于前端自行加解密,如果是前端加密后端解密,则需要自定义secretKey,前后端一致才能正确解密
* sm4.encryptDefault_ECB('123456');
* sm4.decryptDefault_ECB('123456');
* sm4.encryptCustom_ECB('123456', 'asdfghjklmnbvcx,');
* sm4.decryptCustom_ECB('123456', 'asdfghjklmnbvcx,');
*
* CBC 加密模式(更加安全),需要两个密钥
* sm4.encryptDefault_CBC('123456');
* sm4.decryptDefault_CBC('123456');
* 同样可以自定义 secretKey 和 iv,需要两个密钥前后端都一致
* sm4.encryptCustom_CBC('123456', 'asdfghjklmnbvcx,', 'mnbvcxzpoiuytre1');
* sm4.decryptCustom_CBC('123456', 'asdfghjklmnbvcx,', 'mnbvcxzpoiuytre1');
*/
(function (r) {
if (typeof exports === "object" && typeof module !== "undefined") {
module.exports = r()
} else {
let define;
if (typeof define ===
"function" && define.amd) {
define([], r)
} else {
let e;
if (typeof window !== "undefined") {
e = window
} else {
if (typeof global
!== "undefined") {
e = global
} else {
if (typeof self !== "undefined") {
e = self
} else {
e = this
}
}
}
e.base64js = r()
}
}
})(function () {
return function r(e, t, n) {
const f = typeof require == "function" && require;
function o(i, a) {
if (!t[i]) {
if (!e[i]) {
const u = typeof require == "function" && require;
if (!a && u) {
return u(i, !0)
}
if (f) {
return f(i, !0)
}
const d = new Error("Cannot find module '" + i + "'");
throw d.code = "MODULE_NOT_FOUND", d
}
const c = t[i] = {exports: {}};
e[i][0].call(c.exports, function (r) {
const t = e[i][1][r];
return o(t ? t : r)
}, c, c.exports, r, e, t, n)
}
return t[i].exports
}
for (let i = 0; i < n.length; i++) {
o(n[i])
}
return o
}({
"/": [function (r, e, t) {
t.byteLength = c;
t.toByteArray = v;
t.fromByteArray = s;
const n = [];
const o = [];
const f = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
const i = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
let a = 0, u = i.length;
for (; a < u; ++a) {
n[a] = i[a];
o[i.charCodeAt(a)] = a
}
o["-".charCodeAt(0)] = 62;
o["_".charCodeAt(0)] = 63;
function d(r) {
const e = r.length;
if (e % 4 > 0) {
throw new Error("Invalid string. Length must be a multiple of 4")
}
return r[e - 2] === "=" ? 2 : r[e - 1] === "=" ? 1 : 0
}
function c(r) {
return r.length * 3 / 4 - d(r)
}
function v(r) {
let e, t, n, i, a;
const u = r.length;
i = d(r);
a = new f(u * 3 / 4 - i);
t = i > 0 ? u - 4 : u;
let c = 0;
for (e = 0; e < t; e += 4) {
n = o[r.charCodeAt(e)] << 18 | o[r.charCodeAt(e + 1)] << 12 | o[r.charCodeAt(e + 2)] << 6 | o[r.charCodeAt(e + 3)];
a[c++] = n >> 16 & 255;
a[c++] = n >> 8 & 255;
a[c++] = n & 255
}
if (i === 2) {
n = o[r.charCodeAt(e)] << 2 | o[r.charCodeAt(e + 1)] >> 4;
a[c++] = n & 255
} else {
if (i === 1) {
n = o[r.charCodeAt(e)] << 10 | o[r.charCodeAt(e + 1)] << 4 | o[r.charCodeAt(e + 2)] >> 2;
a[c++] = n >> 8 & 255;
a[c++] = n & 255
}
}
return a
}
function l(r) {
return n[r >> 18 & 63] + n[r >> 12 & 63] + n[r >> 6 & 63] + n[r & 63]
}
function h(r, e, t) {
let n;
const o = [];
for (let f = e; f < t; f += 3) {
n = (r[f] << 16) + (r[f + 1] << 8) + r[f + 2];
o.push(l(n))
}
return o.join("")
}
function s(r) {
let e;
const t = r.length;
const o = t % 3;
let f = "";
const i = [];
const a = 16383;
let u = 0, d = t - o;
for (; u < d; u += a) {
i.push(h(r, u, u + a > d ? d : u + a))
}
if (o === 1) {
e = r[t - 1];
f += n[e >> 2];
f += n[e << 4 & 63];
f += "=="
} else {
if (o === 2) {
e = (r[t - 2] << 8) + r[t - 1];
f += n[e >> 10];
f += n[e >> 4 & 63];
f += n[e << 2 & 63];
f += "="
}
}
i.push(f);
return i.join("")
}
}, {}]
}, {}, [])("/")
});
function SM4_Context() {
this.mode = 1;
this.isPadding = true;
this.sk = new Array(32);
}
function SM4() {
this.SM4_ENCRYPT = 1;
this.SM4_DECRYPT = 0;
const SboxTable = [0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7, 0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05,
0x2b, 0x67, 0x9a, 0x76, 0x2a, 0xbe, 0x04, 0xc3, 0xaa, 0x44, 0x13, 0x26, 0x49, 0x86, 0x06, 0x99,
0x9c, 0x42, 0x50, 0xf4, 0x91, 0xef, 0x98, 0x7a, 0x33, 0x54, 0x0b, 0x43, 0xed, 0xcf, 0xac, 0x62,
0xe4, 0xb3, 0x1c, 0xa9, 0xc9, 0x08, 0xe8, 0x95, 0x80, 0xdf, 0x94, 0xfa, 0x75, 0x8f, 0x3f, 0xa6,
0x47, 0x07, 0xa7, 0xfc, 0xf3, 0x73, 0x17, 0xba, 0x83, 0x59, 0x3c, 0x19, 0xe6, 0x85, 0x4f, 0xa8,
0x68, 0x6b, 0x81, 0xb2, 0x71, 0x64, 0xda, 0x8b, 0xf8, 0xeb, 0x0f, 0x4b, 0x70, 0x56, 0x9d, 0x35,
0x1e, 0x24, 0x0e, 0x5e, 0x63, 0x58, 0xd1, 0xa2, 0x25, 0x22, 0x7c, 0x3b, 0x01, 0x21, 0x78, 0x87,
0xd4, 0x00, 0x46, 0x57, 0x9f, 0xd3, 0x27, 0x52, 0x4c, 0x36, 0x02, 0xe7, 0xa0, 0xc4, 0xc8, 0x9e,
0xea, 0xbf, 0x8a, 0xd2, 0x40, 0xc7, 0x38, 0xb5, 0xa3, 0xf7, 0xf2, 0xce, 0xf9, 0x61, 0x15, 0xa1,
0xe0, 0xae, 0x5d, 0xa4, 0x9b, 0x34, 0x1a, 0x55, 0xad, 0x93, 0x32, 0x30, 0xf5, 0x8c, 0xb1, 0xe3,
0x1d, 0xf6, 0xe2, 0x2e, 0x82, 0x66, 0xca, 0x60, 0xc0, 0x29, 0x23, 0xab, 0x0d, 0x53, 0x4e, 0x6f,
0xd5, 0xdb, 0x37, 0x45, 0xde, 0xfd, 0x8e, 0x2f, 0x03, 0xff, 0x6a, 0x72, 0x6d, 0x6c, 0x5b, 0x51,
0x8d, 0x1b, 0xaf, 0x92, 0xbb, 0xdd, 0xbc, 0x7f, 0x11, 0xd9, 0x5c, 0x41, 0x1f, 0x10, 0x5a, 0xd8,
0x0a, 0xc1, 0x31, 0x88, 0xa5, 0xcd, 0x7b, 0xbd, 0x2d, 0x74, 0xd0, 0x12, 0xb8, 0xe5, 0xb4, 0xb0,
0x89, 0x69, 0x97, 0x4a, 0x0c, 0x96, 0x77, 0x7e, 0x65, 0xb9, 0xf1, 0x09, 0xc5, 0x6e, 0xc6, 0x84,
0x18, 0xf0, 0x7d, 0xec, 0x3a, 0xdc, 0x4d, 0x20, 0x79, 0xee, 0x5f, 0x3e, 0xd7, 0xcb, 0x39, 0x48];
const FK = [0xa3b1bac6, 0x56aa3350, 0x677d9197, 0xb27022dc];
const CK = [0x00070e15, 0x1c232a31, 0x383f464d, 0x545b6269,
0x70777e85, 0x8c939aa1, 0xa8afb6bd, 0xc4cbd2d9,
0xe0e7eef5, 0xfc030a11, 0x181f262d, 0x343b4249,
0x50575e65, 0x6c737a81, 0x888f969d, 0xa4abb2b9,
0xc0c7ced5, 0xdce3eaf1, 0xf8ff060d, 0x141b2229,
0x30373e45, 0x4c535a61, 0x686f767d, 0x848b9299,
0xa0a7aeb5, 0xbcc3cad1, 0xd8dfe6ed, 0xf4fb0209,
0x10171e25, 0x2c333a41, 0x484f565d, 0x646b7279];
this.GET_ULONG_BE = function (b, i) {
return (b[i] & 0xff) << 24 | ((b[i + 1] & 0xff) << 16) | ((b[i + 2] & 0xff) << 8) | (b[i + 3] & 0xff) & 0xffffffff;
}
this.PUT_ULONG_BE = function (n, b, i) {
var t1 = (0xFF & (n >> 24));
var t2 = (0xFF & (n >> 16));
var t3 = (0xFF & (n >> 8));
var t4 = (0xFF & (n));
b[i] = t1 > 128 ? t1 - 256 : t1;
b[i + 1] = t2 > 128 ? t2 - 256 : t2;
b[i + 2] = t3 > 128 ? t3 - 256 : t3;
b[i + 3] = t4 > 128 ? t4 - 256 : t4;
}
this.SHL = function (x, n) {
return (x & 0xFFFFFFFF) << n;
}
this.ROTL = function (x, n) {
// const s = this.SHL(x, n);
// const ss = x >> (32 - n);
return this.SHL(x, n) | x >> (32 - n);
}
this.sm4Lt = function (ka) {
let bb;
let c;
const a = new Array(4);
const b = new Array(4);
this.PUT_ULONG_BE(ka, a, 0);
b[0] = this.sm4Sbox(a[0]);
b[1] = this.sm4Sbox(a[1]);
b[2] = this.sm4Sbox(a[2]);
b[3] = this.sm4Sbox(a[3]);
bb = this.GET_ULONG_BE(b, 0);
c = bb ^ this.ROTL(bb, 2) ^ this.ROTL(bb, 10) ^ this.ROTL(bb, 18) ^ this.ROTL(bb, 24);
return c;
}
this.sm4F = function (x0, x1, x2, x3, rk) {
return x0 ^ this.sm4Lt(x1 ^ x2 ^ x3 ^ rk);
}
this.sm4CalciRK = function (ka) {
let bb;
let rk;
const a = new Array(4);
const b = new Array(4);
this.PUT_ULONG_BE(ka, a, 0);
b[0] = this.sm4Sbox(a[0]);
b[1] = this.sm4Sbox(a[1]);
b[2] = this.sm4Sbox(a[2]);
b[3] = this.sm4Sbox(a[3]);
bb = this.GET_ULONG_BE(b, 0);
rk = bb ^ this.ROTL(bb, 13) ^ this.ROTL(bb, 23);
return rk;
}
this.sm4Sbox = function (inch) {
const i = inch & 0xFF;
const retVal = SboxTable[i];
return retVal > 128 ? retVal - 256 : retVal;
}
this.sm4_setkey_enc = function (ctx, key) {
if (ctx == null) {
alert("ctx is null!");
return false;
}
if (key == null || key.length !== 16) {
alert("key error!");
return false;
}
ctx.mode = this.SM4_ENCRYPT;
this.sm4_setkey(ctx.sk, key);
};
//生成解密密钥
this.sm4_setkey_dec = function (ctx, key) {
if (ctx == null) {
Error("ctx is null!");
}
if (key == null || key.length !== 16) {
Error("2key error!");
}
// var i = 0;
ctx.mode = 0;
this.sm4_setkey(ctx.sk, key);
ctx.sk = ctx.sk.reverse();
}
this.sm4_setkey = function (SK, key) {
const MK = new Array(4);
const k = new Array(36);
// var i = 0;
MK[0] = this.GET_ULONG_BE(key, 0);
MK[1] = this.GET_ULONG_BE(key, 4);
MK[2] = this.GET_ULONG_BE(key, 8);
MK[3] = this.GET_ULONG_BE(key, 12);
k[0] = MK[0] ^ FK[0];
k[1] = MK[1] ^ FK[1];
k[2] = MK[2] ^ FK[2];
k[3] = MK[3] ^ FK[3];
for (let i = 0; i < 32; i++) {
k[(i + 4)] = (k[i] ^ this.sm4CalciRK(k[(i + 1)] ^ k[(i + 2)] ^ k[(i + 3)] ^ CK[i]));
SK[i] = k[(i + 4)];
}
}
this.padding = function (input, mode) {
let p;
if (input == null) {
return null;
}
let ret = null;
if (mode === this.SM4_ENCRYPT) {
p = parseInt(16 - input.length % 16);
ret = input.slice(0);
for (let i = 0; i < p; i++) {
ret[input.length + i] = p;
}
} else {
p = input[input.length - 1];
ret = input.slice(0, input.length - p);
}
return ret;
}
this.sm4_one_round = function (sk, input, output) {
let i = 0;
const ulbuf = new Array(36);
ulbuf[0] = this.GET_ULONG_BE(input, 0);
ulbuf[1] = this.GET_ULONG_BE(input, 4);
ulbuf[2] = this.GET_ULONG_BE(input, 8);
ulbuf[3] = this.GET_ULONG_BE(input, 12);
while (i < 32) {
ulbuf[(i + 4)] = this.sm4F(ulbuf[i], ulbuf[(i + 1)], ulbuf[(i + 2)], ulbuf[(i + 3)], sk[i]);
i++;
}
this.PUT_ULONG_BE(ulbuf[35], output, 0);
this.PUT_ULONG_BE(ulbuf[34], output, 4);
this.PUT_ULONG_BE(ulbuf[33], output, 8);
this.PUT_ULONG_BE(ulbuf[32], output, 12);
}
this.sm4_crypt_ecb = function (ctx, input) {
if (input == null) {
alert("input is null!");
}
if ((ctx.isPadding) && (ctx.mode === this.SM4_ENCRYPT)) {
input = this.padding(input, this.SM4_ENCRYPT);
}
let i = 0;
let length = input.length;
let bous = [];
for (; length > 0; length -= 16) {
var out = new Array(16);
var ins = input.slice(i * 16, (16 * (i + 1)));
this.sm4_one_round(ctx.sk, ins, out)
bous = bous.concat(out);
i++;
}
let output = bous;
if (ctx.isPadding && ctx.mode === this.SM4_DECRYPT) {
output = this.padding(output, this.SM4_DECRYPT);
}
for (i = 0; i < output.length; i++) {
if (output[i] < 0) {
output[i] = output[i] + 256;
}
}
return output;
}
this.sm4_crypt_cbc = function (ctx, iv, input) {
let out;
let ins;
let out1;
let k;
if (iv == null || iv.length !== 16) {
alert("iv error!");
}
if (input == null) {
alert("input is null!");
}
if (ctx.isPadding && ctx.mode === this.SM4_ENCRYPT) {
input = this.padding(input, this.SM4_ENCRYPT);
}
let i = 0;
let length = input.length;
let bous = [];
if (ctx.mode === this.SM4_ENCRYPT) {
k = 0;
for (; length > 0; length -= 16) {
out = new Array(16);
out1 = new Array(16);
ins = input.slice(k * 16, (16 * (k + 1)));
for (i = 0; i < 16; i++) {
out[i] = (ins[i] ^ iv[i]);
}
this.sm4_one_round(ctx.sk, out, out1);
iv = out1.slice(0, 16);
bous = bous.concat(out1);
k++;
}
} else {
let temp = [];
k = 0;
for (; length > 0; length -= 16) {
out = new Array(16);
out1 = new Array(16);
ins = input.slice(k * 16, (16 * (k + 1)));
temp = ins.slice(0, 16);
this.sm4_one_round(ctx.sk, ins, out);
for (i = 0; i < 16; i++) {
out1[i] = (out[i] ^ iv[i]);
}
iv = temp.slice(0, 16);
bous = bous.concat(out1);
k++;
}
}
let output = bous;
if (ctx.isPadding && ctx.mode === this.SM4_DECRYPT) {
output = this.padding(output, this.SM4_DECRYPT);
}
for (i = 0; i < output.length; i++) {
if (output[i] < 0) {
output[i] = output[i] + 256;
}
}
return output;
}
}
const SM4Util = function () {
// 和后端secretKey一致才能正确解密,可自定义传入,如果不传,则使用下面的默认secretKey
this.secretKey = "GJwsXX_BzW=gJWJW";
// 当时用CBC模式的时候,除了secretKey,还需要 iv,可自定义传入,如果不传,则使用下面的默认iv
this.iv = "ZkR_SiNoSOFT=568";
this.hexString = false;
// ECB模式加密,默认secretKey
this.encryptDefault_ECB = function (plainText) {
try {
const sm4 = new SM4();
const ctx = new SM4_Context();
ctx.isPadding = true;
ctx.mode = sm4.SM4_ENCRYPT;
const keyBytes = this.stringToByte(this.secretKey);
sm4.sm4_setkey_enc(ctx, keyBytes);
const encrypted = sm4.sm4_crypt_ecb(ctx, this.stringToByte(plainText));
const cipherText = base64js.fromByteArray(encrypted);
if (cipherText != null && cipherText.trim().length > 0) {
cipherText.replace(/(\s*|\t|\r|\n)/g, "");
}
return cipherText;
} catch (e) {
console.error(e);
return null;
}
}
// ECB模式加密,自定义secretKey
this.encryptCustom_ECB = function (plainText, secretKey) {
try {
const sm4 = new SM4();
const ctx = new SM4_Context();
ctx.isPadding = true;
ctx.mode = sm4.SM4_ENCRYPT;
const keyBytes = this.stringToByte(secretKey);
sm4.sm4_setkey_enc(ctx, keyBytes);
const encrypted = sm4.sm4_crypt_ecb(ctx, this.stringToByte(plainText));
const cipherText = base64js.fromByteArray(encrypted);
if (cipherText != null && cipherText.trim().length > 0) {
cipherText.replace(/(\s*|\t|\r|\n)/g, "");
}
return cipherText;
} catch (e) {
console.error(e);
return null;
}
}
//解密_ECB,默认secretKey
this.decryptDefault_ECB = function (cipherText) {
try {
let sm4 = new SM4();
let ctx = new SM4_Context();
ctx.isPadding = true;
ctx.mode = sm4.SM4_ENCRYPT;
let keyBytes = this.stringToByte(this.secretKey);
sm4.sm4_setkey_dec(ctx, keyBytes);
let decrypted = sm4.sm4_crypt_ecb(ctx, base64js.toByteArray(cipherText));
return this.byteToString(decrypted);
} catch (e) {
console.error(e);
return null;
}
}
//解密_ECB,自定义secretKey
this.decryptCustom_ECB = function (cipherText, secretKey) {
try {
let sm4 = new SM4();
let ctx = new SM4_Context();
ctx.isPadding = true;
ctx.mode = sm4.SM4_ENCRYPT;
let keyBytes = this.stringToByte(secretKey);
sm4.sm4_setkey_dec(ctx, keyBytes);
let decrypted = sm4.sm4_crypt_ecb(ctx, base64js.toByteArray(cipherText));
return this.byteToString(decrypted);
} catch (e) {
console.error(e);
return null;
}
}
// CBC模式加密,默认 iv 和 secretKey
this.encryptDefault_CBC = function (plainText) {
try {
const sm4 = new SM4();
const ctx = new SM4_Context();
ctx.isPadding = true;
ctx.mode = sm4.SM4_ENCRYPT;
const keyBytes = this.stringToByte(this.secretKey);
const ivBytes = this.stringToByte(this.iv);
sm4.sm4_setkey_enc(ctx, keyBytes);
const encrypted = sm4.sm4_crypt_cbc(ctx, ivBytes, this.stringToByte(plainText));
const cipherText = base64js.fromByteArray(encrypted);
if (cipherText != null && cipherText.trim().length > 0) {
cipherText.replace(/(\s*|\t|\r|\n)/g, "");
}
return cipherText;
} catch (e) {
console.error(e);
return null;
}
}
// CBC模式加密,自定义 iv 和 secretKey
this.encryptCustom_CBC = function (plainText, iv, secretKey) {
try {
const sm4 = new SM4();
const ctx = new SM4_Context();
ctx.isPadding = true;
ctx.mode = sm4.SM4_ENCRYPT;
const keyBytes = this.stringToByte(secretKey);
const ivBytes = this.stringToByte(iv);
sm4.sm4_setkey_enc(ctx, keyBytes);
const encrypted = sm4.sm4_crypt_cbc(ctx, ivBytes, this.stringToByte(plainText));
const cipherText = base64js.fromByteArray(encrypted);
if (cipherText != null && cipherText.trim().length > 0) {
cipherText.replace(/(\s*|\t|\r|\n)/g, "");
}
return cipherText;
} catch (e) {
console.error(e);
return null;
}
}
//解密_CBC,默认 iv 和 secretKey
this.decryptDefault_CBC = function (cipherText) {
try {
let sm4 = new SM4();
let ctx = new SM4_Context();
ctx.isPadding = true;
ctx.mode = sm4.SM4_ENCRYPT;
let keyBytes = this.stringToByte(this.secretKey);
let ivBytes = this.stringToByte(this.iv);
sm4.sm4_setkey_dec(ctx, keyBytes);
let decrypted = sm4.sm4_crypt_cbc(ctx, ivBytes, base64js.toByteArray(cipherText));
return this.byteToString(decrypted);
} catch (e) {
console.error(e);
return null;
}
}
//解密_CBC,自定义 iv 和 secretKey
this.decryptCustom_CBC = function (cipherText, iv, secretKey) {
try {
let sm4 = new SM4();
let ctx = new SM4_Context();
ctx.isPadding = true;
ctx.mode = sm4.SM4_ENCRYPT;
let keyBytes = this.stringToByte(secretKey);
let ivBytes = this.stringToByte(iv);
sm4.sm4_setkey_dec(ctx, keyBytes);
let decrypted = sm4.sm4_crypt_cbc(ctx, ivBytes, base64js.toByteArray(cipherText));
return this.byteToString(decrypted);
} catch (e) {
console.error(e);
return null;
}
}
this.stringToByte = function (str) {
const bytes = [];
let len, c;
len = str.length;
for (let i = 0; i < len; i++) {
c = str.charCodeAt(i);
if (c >= 0x010000 && c <= 0x10FFFF) {
bytes.push(((c >> 18) & 0x07) | 0xF0);
bytes.push(((c >> 12) & 0x3F) | 0x80);
bytes.push(((c >> 6) & 0x3F) | 0x80);
bytes.push((c & 0x3F) | 0x80);
} else if (c >= 0x000800 && c <= 0x00FFFF) {
bytes.push(((c >> 12) & 0x0F) | 0xE0);
bytes.push(((c >> 6) & 0x3F) | 0x80);
bytes.push((c & 0x3F) | 0x80);
} else if (c >= 0x000080 && c <= 0x0007FF) {
bytes.push(((c >> 6) & 0x1F) | 0xC0);
bytes.push((c & 0x3F) | 0x80);
} else {
bytes.push(c & 0xFF);
}
}
return bytes;
}
this.byteToString = function (arr) {
if (typeof arr === 'string') {
return arr;
}
let str = '',
_arr = arr;
for (let i = 0; i < _arr.length; i++) {
const one = _arr[i].toString(2),
v = one.match(/^1+?(?=0)/);
if (v && one.length === 8) {
const bytesLength = v[0].length;
let store = _arr[i].toString(2).slice(7 - bytesLength);
for (let st = 1; st < bytesLength; st++) {
store += _arr[st + i].toString(2).slice(2);
}
str += String.fromCharCode(parseInt(store, 2));
i += bytesLength - 1;
} else {
str += String.fromCharCode(_arr[i]);
}
}
return str;
}
};
export {SM4Util};
...@@ -24,3 +24,10 @@ export default { ...@@ -24,3 +24,10 @@ export default {
} }
} }
</script> </script>
<style scoped>
.home{
width: 100%;
height: 100%;
text-align: left;
}
</style>
\ No newline at end of file
<template>
<div class="jsmindDemo">
<div id="jsmind_container"></div>
</div>
</template>
<script>
export default {
name: 'JsmindDemo',
data() {
return {
}
},
mounted(){
var mind = {
/* 元数据,定义思维导图的名称、作者、版本等信息 */
"meta":{
"name":"jsMind-demo-tree",
"author":"hizzgdev@163.com",
"version":"0.2"
},
/* 数据格式声明 */
"format":"node_tree",
/* 数据内容 */
"data":{"id":"root","topic":"jsMind","children":[
{"id":"easy","topic":"Easy","direction":"left","expanded":false,"children":[
{"id":"easy1","topic":"Easy to show"},
{"id":"easy2","topic":"Easy to edit"},
{"id":"easy3","topic":"Easy to store"},
{"id":"easy4","topic":"Easy to embed"}
]},
{"id":"open","topic":"Open Source","direction":"right","expanded":true,"children":[
{"id":"open1","topic":"on GitHub"},
{"id":"open2","topic":"BSD License"}
]},
{"id":"powerful","topic":"Powerful","direction":"right","children":[
{"id":"powerful1","topic":"Base on Javascript"},
{"id":"powerful2","topic":"Base on HTML5"},
{"id":"powerful3","topic":"Depends on you"}
]},
{"id":"other","topic":"test node","direction":"left","children":[
{"id":"other1","topic":"I'm from local variable"},
{"id":"other2","topic":"I can do everything"}
]}
]}
};
var options = {
container:'jsmind_container',
editable:true,
theme:'greensea'
};
var jm = new jsMind(options);
jm.show(mind);
console.log(jm.get_data())
},
methods: {
}
}
</script>
<style scoped>
.jsmindDemo{
width: 100%;
height: 100%;
text-align: left;
}
#jsmind_container{
width: 100%;
height: 100%;
}
</style>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!