diff --git a/libs/le5le-topology/0.0.1/topology.bundle.js b/libs/le5le-topology/0.0.1/topology.bundle.js new file mode 100644 index 000000000..58373ad57 --- /dev/null +++ b/libs/le5le-topology/0.0.1/topology.bundle.js @@ -0,0 +1 @@ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.MA=e():t.MA=e()}(window,(function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=15)}([function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t,e,i,n,r){this.x=t,this.y=e,this.x=this.x<<0,this.y=this.y<<0,this.direction=i,this.anchorIndex=n,this.id=r}return t.prototype.clone=function(){return new t(this.x,this.y,this.direction,this.anchorIndex,this.id)},t.prototype.hit=function(t,e){return void 0===e&&(e=5),t.x>this.x-e&&t.xthis.y-e&&t.ythis.x-e&&t.xthis.y-e&&t.ythis.x&&t.xthis.y&&t.ythis.x&&t.exthis.y&&t.ythis.x&&t.exthis.y&&t.eythis.x&&t.xthis.y&&t.eythis.x-e&&t.xthis.y-e&&t.ythis.x-e&&t.xthis.y-e&&t.ythis.x&&t.xthis.y&&t.ythis.x&&t.exthis.y&&t.ythis.x&&t.exthis.y&&t.eythis.x&&t.xthis.y&&t.eythis.x-e&&t.xthis.y-e&&t.ythis.x-e&&t.xthis.y-e&&t.ythis.x&&t.xthis.y&&t.ythis.x&&t.exthis.y&&t.ythis.x&&t.exthis.y&&t.eythis.x&&t.xthis.y&&t.eythis.x-e&&t.xthis.y-e&&t.ythis.x&&t.xthis.y&&t.ythis.x&&t.exthis.y&&t.ythis.x&&t.exthis.y&&t.eythis.x&&t.xthis.y&&t.eythis.x-e&&t.xthis.y-e&&t.y=t.y||o.y>=t.y&&n.yt.x&&(i=!i),n=o}return i}e.pointInRect=r,e.pointInLine=function(t,e,i){return r(t,[new n.Point(e.x-8,e.y-8),new n.Point(i.x-8,i.y-8),new n.Point(i.x+8,i.y+8),new n.Point(e.x+8,e.y+8)])},e.lineLen=function(t,e){return 0|Math.sqrt(Math.pow(Math.abs(t.x-e.x),2)+Math.pow(Math.abs(t.y-e.y),2))},e.curveLen=function(t,e,i,n){var r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("d","M"+t.x+" "+t.y+" C"+e.x+" "+e.y+" "+i.x+" "+i.y+" "+n.x+" "+n.y),0|r.getTotalLength()},e.pSBC=function(t,e,i,n){var r,h,o,s,c,a,l,y="string"==typeof i,d=parseInt,x=Math.round;if("number"!=typeof t||t<-1||t>1||"string"!=typeof e||"r"!==e[0]&&"#"!==e[0]||i&&!y)return null;var f=function(t){var e,i=t.length,n={};if(i>9){if(e=t=t.split(","),r=e[0],h=e[1],o=e[2],y=e[3],(i=t.length)<3||i>4)return null;n.r=d("a"===r[3]?r.slice(5):r.slice(4)),n.g=d(h),n.b=d(o),n.a=y?parseFloat(y):-1}else{if(8===i||6===i||i<4)return null;i<6&&(t="#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]+(i>4?t[4]+t[4]:"")),t=d(t.slice(1),16),9===i||5===i?(n.r=t>>24&255,n.g=t>>16&255,n.b=t>>8&255,n.a=x((255&t)/.255)/1e3):(n.r=t>>16,n.g=t>>8&255,n.b=255&t,n.a=-1)}return n};return l=e.length>9,l=y?i.length>9||"c"===i&&!l:l,c=f(e),s=t<0,a=i&&"c"!==i?f(i):s?{r:0,g:0,b:0,a:-1}:{r:255,g:255,b:255,a:-1},s=1-(t=s?-1*t:t),c&&a?(n?(r=x(s*c.r+t*a.r),h=x(s*c.g+t*a.g),o=x(s*c.b+t*a.b)):(r=x(Math.pow(s*Math.pow(c.r,2)+t*Math.pow(a.r,2),.5)),h=x(Math.pow(s*Math.pow(c.g,2)+t*Math.pow(a.g,2),.5)),o=x(Math.pow(s*Math.pow(c.b,2)+t*Math.pow(a.b,2),.5))),y=c.a,a=a.a,y=(c=y>=0||a>=0)?y<0?a:a<0?y:y*s+a*t:0,l?"rgb"+(c?"a(":"(")+r+","+h+","+o+(c?","+x(1e3*y)/1e3:"")+")":"#"+(4294967296+16777216*r+65536*h+256*o+(c?x(255*y):0)).toString(16).slice(1,c?void 0:-2)):null}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=i(5);function r(t,e){if(e.length<3)return!1;for(var i=!1,n=e[e.length-1],r=0,h=e;r=t.y||o.y>=t.y&&n.yt.x&&(i=!i),n=o}return i}e.pointInRect=r,e.pointInLine=function(t,e,i){return r(t,[new n.Point(e.x-8,e.y-8),new n.Point(i.x-8,i.y-8),new n.Point(i.x+8,i.y+8),new n.Point(e.x+8,e.y+8)])},e.lineLen=function(t,e){return 0|Math.sqrt(Math.pow(Math.abs(t.x-e.x),2)+Math.pow(Math.abs(t.y-e.y),2))},e.curveLen=function(t,e,i,n){var r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("d","M"+t.x+" "+t.y+" C"+e.x+" "+e.y+" "+i.x+" "+i.y+" "+n.x+" "+n.y),0|r.getTotalLength()},e.pSBC=function(t,e,i,n){var r,h,o,s,c,a,l,y="string"==typeof i,d=parseInt,x=Math.round;if("number"!=typeof t||t<-1||t>1||"string"!=typeof e||"r"!==e[0]&&"#"!==e[0]||i&&!y)return null;var f=function(t){var e,i=t.length,n={};if(i>9){if(e=t=t.split(","),r=e[0],h=e[1],o=e[2],y=e[3],(i=t.length)<3||i>4)return null;n.r=d("a"===r[3]?r.slice(5):r.slice(4)),n.g=d(h),n.b=d(o),n.a=y?parseFloat(y):-1}else{if(8===i||6===i||i<4)return null;i<6&&(t="#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]+(i>4?t[4]+t[4]:"")),t=d(t.slice(1),16),9===i||5===i?(n.r=t>>24&255,n.g=t>>16&255,n.b=t>>8&255,n.a=x((255&t)/.255)/1e3):(n.r=t>>16,n.g=t>>8&255,n.b=255&t,n.a=-1)}return n};return l=e.length>9,l=y?i.length>9||"c"===i&&!l:l,c=f(e),s=t<0,a=i&&"c"!==i?f(i):s?{r:0,g:0,b:0,a:-1}:{r:255,g:255,b:255,a:-1},s=1-(t=s?-1*t:t),c&&a?(n?(r=x(s*c.r+t*a.r),h=x(s*c.g+t*a.g),o=x(s*c.b+t*a.b)):(r=x(Math.pow(s*Math.pow(c.r,2)+t*Math.pow(a.r,2),.5)),h=x(Math.pow(s*Math.pow(c.g,2)+t*Math.pow(a.g,2),.5)),o=x(Math.pow(s*Math.pow(c.b,2)+t*Math.pow(a.b,2),.5))),y=c.a,a=a.a,y=(c=y>=0||a>=0)?y<0?a:a<0?y:y*s+a*t:0,l?"rgb"+(c?"a(":"(")+r+","+h+","+o+(c?","+x(1e3*y)/1e3:"")+")":"#"+(4294967296+16777216*r+65536*h+256*o+(c?x(255*y):0)).toString(16).slice(1,c?void 0:-2)):null}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=i(10);function r(t,e){if(e.length<3)return!1;for(var i=!1,n=e[e.length-1],r=0,h=e;r=t.y||o.y>=t.y&&n.yt.x&&(i=!i),n=o}return i}e.pointInRect=r,e.pointInLine=function(t,e,i){return r(t,[new n.Point(e.x-8,e.y-8),new n.Point(i.x-8,i.y-8),new n.Point(i.x+8,i.y+8),new n.Point(e.x+8,e.y+8)])},e.lineLen=function(t,e){return 0|Math.sqrt(Math.pow(Math.abs(t.x-e.x),2)+Math.pow(Math.abs(t.y-e.y),2))},e.curveLen=function(t,e,i,n){var r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("d","M"+t.x+" "+t.y+" C"+e.x+" "+e.y+" "+i.x+" "+i.y+" "+n.x+" "+n.y),0|r.getTotalLength()},e.pSBC=function(t,e,i,n){var r,h,o,s,c,a,l,y="string"==typeof i,d=parseInt,x=Math.round;if("number"!=typeof t||t<-1||t>1||"string"!=typeof e||"r"!==e[0]&&"#"!==e[0]||i&&!y)return null;var f=function(t){var e,i=t.length,n={};if(i>9){if(e=t=t.split(","),r=e[0],h=e[1],o=e[2],y=e[3],(i=t.length)<3||i>4)return null;n.r=d("a"===r[3]?r.slice(5):r.slice(4)),n.g=d(h),n.b=d(o),n.a=y?parseFloat(y):-1}else{if(8===i||6===i||i<4)return null;i<6&&(t="#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]+(i>4?t[4]+t[4]:"")),t=d(t.slice(1),16),9===i||5===i?(n.r=t>>24&255,n.g=t>>16&255,n.b=t>>8&255,n.a=x((255&t)/.255)/1e3):(n.r=t>>16,n.g=t>>8&255,n.b=255&t,n.a=-1)}return n};return l=e.length>9,l=y?i.length>9||"c"===i&&!l:l,c=f(e),s=t<0,a=i&&"c"!==i?f(i):s?{r:0,g:0,b:0,a:-1}:{r:255,g:255,b:255,a:-1},s=1-(t=s?-1*t:t),c&&a?(n?(r=x(s*c.r+t*a.r),h=x(s*c.g+t*a.g),o=x(s*c.b+t*a.b)):(r=x(Math.pow(s*Math.pow(c.r,2)+t*Math.pow(a.r,2),.5)),h=x(Math.pow(s*Math.pow(c.g,2)+t*Math.pow(a.g,2),.5)),o=x(Math.pow(s*Math.pow(c.b,2)+t*Math.pow(a.b,2),.5))),y=c.a,a=a.a,y=(c=y>=0||a>=0)?y<0?a:a<0?y:y*s+a*t:0,l?"rgb"+(c?"a(":"(")+r+","+h+","+o+(c?","+x(1e3*y)/1e3:"")+")":"#"+(4294967296+16777216*r+65536*h+256*o+(c?x(255*y):0)).toString(16).slice(1,c?void 0:-2)):null}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=i(3);function r(t,e){if(e.length<3)return!1;for(var i=!1,n=e[e.length-1],r=0,h=e;r=t.y||o.y>=t.y&&n.yt.x&&(i=!i),n=o}return i}e.pointInRect=r,e.pointInLine=function(t,e,i){return r(t,[new n.Point(e.x-8,e.y-8),new n.Point(i.x-8,i.y-8),new n.Point(i.x+8,i.y+8),new n.Point(e.x+8,e.y+8)])},e.lineLen=function(t,e){return 0|Math.sqrt(Math.pow(Math.abs(t.x-e.x),2)+Math.pow(Math.abs(t.y-e.y),2))},e.curveLen=function(t,e,i,n){var r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("d","M"+t.x+" "+t.y+" C"+e.x+" "+e.y+" "+i.x+" "+i.y+" "+n.x+" "+n.y),0|r.getTotalLength()},e.pSBC=function(t,e,i,n){var r,h,o,s,c,a,l,y="string"==typeof i,d=parseInt,x=Math.round;if("number"!=typeof t||t<-1||t>1||"string"!=typeof e||"r"!==e[0]&&"#"!==e[0]||i&&!y)return null;var f=function(t){var e,i=t.length,n={};if(i>9){if(e=t=t.split(","),r=e[0],h=e[1],o=e[2],y=e[3],(i=t.length)<3||i>4)return null;n.r=d("a"===r[3]?r.slice(5):r.slice(4)),n.g=d(h),n.b=d(o),n.a=y?parseFloat(y):-1}else{if(8===i||6===i||i<4)return null;i<6&&(t="#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]+(i>4?t[4]+t[4]:"")),t=d(t.slice(1),16),9===i||5===i?(n.r=t>>24&255,n.g=t>>16&255,n.b=t>>8&255,n.a=x((255&t)/.255)/1e3):(n.r=t>>16,n.g=t>>8&255,n.b=255&t,n.a=-1)}return n};return l=e.length>9,l=y?i.length>9||"c"===i&&!l:l,c=f(e),s=t<0,a=i&&"c"!==i?f(i):s?{r:0,g:0,b:0,a:-1}:{r:255,g:255,b:255,a:-1},s=1-(t=s?-1*t:t),c&&a?(n?(r=x(s*c.r+t*a.r),h=x(s*c.g+t*a.g),o=x(s*c.b+t*a.b)):(r=x(Math.pow(s*Math.pow(c.r,2)+t*Math.pow(a.r,2),.5)),h=x(Math.pow(s*Math.pow(c.g,2)+t*Math.pow(a.g,2),.5)),o=x(Math.pow(s*Math.pow(c.b,2)+t*Math.pow(a.b,2),.5))),y=c.a,a=a.a,y=(c=y>=0||a>=0)?y<0?a:a<0?y:y*s+a*t:0,l?"rgb"+(c?"a(":"(")+r+","+h+","+o+(c?","+x(1e3*y)/1e3:"")+")":"#"+(4294967296+16777216*r+65536*h+256*o+(c?x(255*y):0)).toString(16).slice(1,c?void 0:-2)):null}},function(t,e,i){"use strict";function n(){return(65536*(1+Math.random())|0).toString(16).substring(1)}function r(){return n()+n()}i.r(e);class h{constructor(t,e,i,n,r){this.x=t,this.y=e,this.x=this.x,this.y=this.y,this.direction=i,this.anchorIndex=n,this.id=r}clone(){const t=new h(this.x,this.y,this.direction,this.anchorIndex,this.id);return this.data&&(t.data=this.data),t}hit(t,e=5){return t.x>this.x-e&&t.xthis.y-e&&t.y=t.y||r.y>=t.y&&n.yt.x&&(i=!i),n=r;return i}function s(t,e,i){return o(t,[new h(e.x-8,e.y-8),new h(i.x-8,i.y-8),new h(i.x+8,i.y+8),new h(e.x+8,e.y+8)])}function c(t,e){return 0|Math.sqrt(Math.pow(Math.abs(t.x-e.x),2)+Math.pow(Math.abs(t.y-e.y),2))}function a(t,e,i,n){let r,h,o,s,c,a,l,y="string"==typeof i;const d=parseInt,x=Math.round;if("number"!=typeof t||t<-1||t>1||"string"!=typeof e||"r"!==e[0]&&"#"!==e[0]||i&&!y)return null;const f=t=>{let e=t.length;const i={};if(e>9){if([r,h,o,y]=t=t.split(","),(e=t.length)<3||e>4)return null;i.r=d("a"===r[3]?r.slice(5):r.slice(4)),i.g=d(h),i.b=d(o),i.a=y?parseFloat(y):-1}else{if(8===e||6===e||e<4)return null;e<6&&(t="#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]+(e>4?t[4]+t[4]:"")),t=d(t.slice(1),16),9===e||5===e?(i.r=t>>24&255,i.g=t>>16&255,i.b=t>>8&255,i.a=x((255&t)/.255)/1e3):(i.r=t>>16,i.g=t>>8&255,i.b=255&t,i.a=-1)}return i};return l=e.length>9,l=y?i.length>9||"c"===i&&!l:l,c=f(e),s=t<0,a=i&&"c"!==i?f(i):s?{r:0,g:0,b:0,a:-1}:{r:255,g:255,b:255,a:-1},s=1-(t=s?-1*t:t),c&&a?(n?(r=x(s*c.r+t*a.r),h=x(s*c.g+t*a.g),o=x(s*c.b+t*a.b)):(r=x((s*c.r**2+t*a.r**2)**.5),h=x((s*c.g**2+t*a.g**2)**.5),o=x((s*c.b**2+t*a.b**2)**.5)),y=c.a,a=a.a,y=(c=y>=0||a>=0)?y<0?a:a<0?y:y*s+a*t:0,l?"rgb"+(c?"a(":"(")+r+","+h+","+o+(c?","+x(1e3*y)/1e3:"")+")":"#"+(4294967296+16777216*r+65536*h+256*o+(c?x(255*y):0)).toString(16).slice(1,c?void 0:-2)):null}class l{constructor(t,e,i,n){this.x=t,this.y=e,this.width=i,this.height=n,this.center=new h(0,0),this.ex=this.x+this.width,this.ey=this.y+this.height,this.calceCenter()}clone(){return new l(this.x,this.y,this.width,this.height)}hit(t,e=0){return t.x>this.x-e&&t.xthis.y-e&&t.ythis.x&&t.xthis.y&&t.ythis.x&&t.exthis.y&&t.ythis.x&&t.exthis.y&&t.eythis.x&&t.xthis.y&&t.ey1&&(t.lineWidth=this.lineWidth),this.strokeStyle?t.strokeStyle=this.strokeStyle:t.strokeStyle="#333",this.fillStyle?t.fillStyle=this.fillStyle:t.fillStyle="transparent",this.globalAlpha<1&&(t.globalAlpha=this.globalAlpha),this.dash){case 1:t.setLineDash([5,5]);break;case 2:t.setLineDash([10,10]);break;case 3:t.setLineDash([10,10,2,10])}if(this.draw(t),t.restore(),this.children)for(const e of this.children)e.render(t)}hit(t,e=0){if(!this.rotate)return this.rect.hit(t,e);const i=this.rect.toPoints();for(const t of i)t.rotate(this.rotate,this.rect.center);return o(t,i)}}function d(t,e){const i=e.rect.width*e.borderRadius,n=e.rect.height*e.borderRadius;let r=i126?(i&&(e.push(i),i=""),e.push(t[n])):i+=t[n]}return i&&e.push(i),e}function m(t,e,i){const n=[];let r=e[0]||"";for(let h=1;hs?s:n.length);let c=i.x+i.width/2,a=i.y+(i.height-h*o)/2+4*h/7;switch(t.textAlign){case"left":c=i.x;break;case"right":c=i.x+i.width}switch(t.textBaseline){case"top":a=i.y+(h-e.font.fontSize)/2;break;case"bottom":a=i.ey-h*n.length+h}!function(t,e,i,n,r,h,o,s){s=!s||s>e.length?e.length:Math.ceil(s);for(let r=0;rr&&(h=e[s-1].substr(0,e[s-1].length-2)+"..."),t.fillText(h,i,n+(s-1)*o)}else t.fillText(e[s-1],i,n+(s-1)*o)}(t,n,c,a,i.width,i.height,h,o),t.restore()}function L(t,e){t.beginPath();const i=e.rect.y+e.rect.height/2;t.moveTo(e.rect.x,i),t.lineTo(e.rect.x+e.rect.width,i),t.stroke()}var R;function b(t){t.anchors.push(new h(t.rect.x+t.rect.width/2,t.rect.y,R.Up)),t.anchors.push(new h(t.rect.x+3*t.rect.width/4,t.rect.y+t.rect.height/2,R.Right)),t.anchors.push(new h(t.rect.x+t.rect.width/2,t.rect.y+t.rect.height,R.Bottom)),t.anchors.push(new h(t.rect.x+t.rect.width/4,t.rect.y+t.rect.height/2,R.Left))}function T(t){t.anchors.push(new h(t.rect.x,t.rect.y+t.rect.height/2,R.Left)),t.anchors.push(new h(t.rect.x+t.rect.width,t.rect.y+t.rect.height/2,R.Right))}function S(t){t.anchors.push(new h(t.rect.x,t.rect.y+t.rect.height/2,R.Left)),t.anchors.push(new h(t.rect.x+t.rect.width,t.rect.y+t.rect.height/2,R.Right))}function I(t){let e=t.rect.width/2,i=t.rect.height/2;e>i?e=i:i=e;let n=t.rect.height/10;n<10&&(n=10),t.iconRect=new l(t.rect.x+(t.rect.width-e)/2,t.rect.y+n,e,i)}function M(t){let e=t.rect.height/20;e<5&&(e=0),t.textRect=new l(t.rect.x+t.rect.width/4,t.rect.y+2*t.rect.height/3-e,t.rect.width/2,t.rect.height/3-5);const i=5*t.rect.width/7,n=5*t.rect.height/7;t.fullTextRect=new l(t.rect.x+(t.rect.width-i)/2,t.rect.y+(t.rect.height-n)/2,i,n)}function C(t){let e=2*t.rect.width/7,i=2*t.rect.height/7;e>i?e=i:i=e;let n=e;n<10&&(n=10),t.iconRect=new l(t.rect.x+(t.rect.width-e)/2,t.rect.y+n,e,i)}function k(t){t.textRect=new l(t.rect.x+t.rect.width/4,t.rect.y+2*t.rect.height/3,t.rect.width/2,t.rect.height/3-5);const e=t.rect.width/2,i=3*t.rect.height/7;t.fullTextRect=new l(t.rect.x+(t.rect.width-e)/2,t.rect.y+t.rect.height/2-5,e,i)}function A(t){let e=t.rect.width/3,i=t.rect.height/3;e>i?e=i:i=e;let n=t.rect.width/5;n<10&&(n=10),t.iconRect=new l(t.rect.x+(t.rect.width-e)/2,t.rect.y+n,e,i)}function N(t){let e=t.rect.height/10;e<5&&(e=0),t.textRect=new l(t.rect.x+t.rect.width/3,t.rect.y+2*t.rect.height/3-e,t.rect.width/3,t.rect.height/3-5);const i=t.rect.width/2,n=1*t.rect.height/2;t.fullTextRect=new l(t.rect.x+(t.rect.width-i)/2,t.rect.y+t.rect.height/4,i,n)}function z(t){t.iconRect=new l(0,0,0,0)}function D(t){t.textRect=new l(t.rect.x+t.rect.height/2,t.rect.y+t.rect.height/3,t.rect.width-t.rect.height/2,t.rect.height/3),t.fullTextRect=t.textRect}function W(t){t.iconRect=new l(0,0,0,0)}function F(t){t.textRect=new l(t.rect.x,t.rect.y+t.rect.height/3,t.rect.width-t.rect.height/2,t.rect.height/3),t.fullTextRect=t.textRect}function B(t){t.iconRect=new l(0,0,0,0)}function H(t){t.textRect=new l(t.rect.x+t.rect.height/2,t.rect.y+t.rect.height/3,t.rect.width-t.rect.height,t.rect.height/3),t.fullTextRect=t.textRect}function E(t){t.iconRect=new l(0,0,0,0)}function U(t){t.fullTextRect=new l(t.rect.x+10,t.rect.y+t.rect.height/2-20,t.rect.width-20,20),t.textRect=t.fullTextRect}function _(t,e){t.beginPath(),t.moveTo(e.from.x,e.from.y),t.lineTo(e.to.x,e.to.y),t.stroke()}function O(t,e){}function $(t){t.controlPoints=[]}!function(t){t[t.Up=1]="Up",t[t.Right=2]="Right",t[t.Bottom=3]="Bottom",t[t.Left=4]="Left"}(R||(R={}));const j=50;function Y(t,e){t.beginPath(),t.moveTo(e.from.x,e.from.y);for(const i of e.controlPoints)t.lineTo(i.x,i.y);t.lineTo(e.to.x,e.to.y),t.stroke()}function X(t,e){t.fillStyle="#fff",t.lineWidth=2;for(const i of e.controlPoints)t.beginPath(),t.arc(i.x,i.y,4,0,2*Math.PI),t.stroke(),t.fill()}function K(t){t.controlPoints=[];const e=V(t.from,t.to);t.from.direction&&t.controlPoints.push(e);const i=V(t.to,t.from);let n;switch(e.direction){case R.Up:n=function(t,e){if(t.x===e.x||t.y===e.y)return[];if(t.y>e.y)return e.direction===R.Up&&t.y-e.y>3*j?t.xe.x||e.direction===R.Right&&t.x3*j?t.ye.y?[new h(e.x,t.y)]:[new h(t.x,e.y)];if(e.direction===R.Left){if(t.y3*j?t.xe.x||e.direction===R.Right&&t.xe.x)return e.direction===R.Left&&t.x-e.x>3*j?t.ye.y?[new h(e.x,t.y)]:[new h(t.x,e.y)];if(e.direction===R.Left){if(t.yt.x?i.x+=Math.floor((e.x-t.x)/2):i.x+=j;break;case R.Bottom:e.y>t.y?i.y+=Math.floor((e.y-t.y)/2):i.y+=j;break;case R.Left:e.xt.y?(n=Math.floor((e.y-t.y)/3),i.y+=n):(n=Math.floor((t.y-e.y)/3),i.y-=n),i;if((t.direction===R.Left||t.direction===R.Right)&&Math.abs(t.y-e.y)<3)return e.x>t.x?(n=Math.floor((e.x-t.x)/3),i.x+=n):(n=Math.floor((t.x-e.x)/3),i.x-=n),i;switch(t.direction){case R.Up:i.y-=n;break;case R.Right:i.x+=n;break;case R.Bottom:i.y+=n;break;case R.Left:i.x-=n}return i}function lt(t,e,i,n,r){const o=new l(i.x-17,i.y-5,15,10);n&&1!==n&&o.scale(n,new h(o.x+15,o.y+5)),t.translate(i.x,i.y),t.rotate(Math.atan2(i.y-e.y,i.x-e.x)),t.translate(-i.x,-i.y),t.moveTo(o.x,o.y),t.lineTo(o.x+o.width,o.y+o.height/2),t.lineTo(o.x,o.y+o.height),t.closePath(),t.lineWidth=2,t.stroke(),r&&(t.fillStyle=r),t.fill()}function yt(t,e,i,n){lt(t,e,i,n,"#fff")}function dt(t,e,i,n,r){const o=new l(i.x-16,i.y-4,14,8);n&&1!==n&&o.scale(n,new h(o.x+14,o.y+4)),t.translate(i.x,i.y),t.rotate(Math.atan2(i.y-e.y,i.x-e.x)),t.translate(-i.x,-i.y),t.moveTo(o.x+o.width/2,o.y),t.lineTo(o.x+o.width,o.y+o.height/2),t.lineTo(o.x+o.width/2,o.y+o.height),t.lineTo(o.x,o.y+o.height/2),t.closePath(),t.lineWidth=2,t.stroke(),r&&(t.fillStyle=r),t.fill()}function xt(t,e,i,n){dt(t,e,i,n,"#fff")}function ft(t,e,i,n,r){const o=new l(i.x-12,i.y-5,10,10);n&&1!==n&&o.scale(n,new h(o.x+9,o.y+5)),t.translate(i.x,i.y),t.rotate(Math.atan2(i.y-e.y,i.x-e.x)),t.translate(-i.x,-i.y),t.arc(o.center.x,o.center.y,o.width/2,0,2*Math.PI),t.lineWidth=2,t.stroke(),r&&(t.fillStyle=r),t.fill()}function ut(t,e,i,n){ft(t,e,i,n,"#fff")}function gt(t){t.anchors.push(new h(t.rect.x,t.rect.y+t.rect.height/2,R.Left)),t.anchors.push(new h(t.rect.x+t.rect.width/2,t.rect.y,R.Up)),t.anchors.push(new h(t.rect.x+t.rect.width,t.rect.y+t.rect.height/2,R.Right)),t.anchors.push(new h(t.rect.x+t.rect.width/2,t.rect.y+t.rect.height,R.Bottom));for(let e=10;e<360;e+=10){if(e%90==0)continue;const i=Math.floor(e/90),n=new h(t.rect.center.x+Math.sin(e/180*Math.PI)*t.rect.width/2,t.rect.center.y+Math.cos(e/180*Math.PI)*t.rect.height/2,i);n.data="hidden",t.anchors.push(n)}}function wt(t,e,i,n){const r=new l(i.x-12,i.y-6,12,12);n&&1!==n&&r.scale(n,new h(r.x+12,r.y+6)),t.translate(i.x,i.y),t.rotate(Math.atan2(i.y-e.y,i.x-e.x)),t.translate(-i.x,-i.y),t.moveTo(r.x,r.y),t.lineTo(r.x+r.width,r.y+r.height/2),t.lineTo(r.x,r.y+r.height),t.stroke()}function pt(t,e,i,n){const r=new l(i.x-12,i.y-6,12,12);n&&1!==n&&r.scale(n,new h(r.x+12,r.y+6)),t.translate(i.x,i.y),t.rotate(Math.atan2(i.y-e.y,i.x-e.x)),t.translate(-i.x,-i.y),i.x>e.x?(t.moveTo(r.x,r.y),t.lineTo(r.x+r.width,r.y+r.height/2)):(t.moveTo(r.x+r.width,r.y+r.height/2),t.lineTo(r.x,r.y+r.height)),t.stroke()}function vt(t,e,i,n){const r=new l(i.x-12,i.y-6,12,12);n&&1!==n&&r.scale(n,new h(r.x+12,r.y+6)),t.translate(i.x,i.y),t.rotate(Math.atan2(i.y-e.y,i.x-e.x)),t.translate(-i.x,-i.y),i.xi?e=i:i=e;let n=t.rect.height/7;n<10&&(n=10),t.iconRect=new l(t.rect.x+(t.rect.width-e)/2,t.rect.y+n,e,i)}function Lt(t){t.textRect=new l(t.rect.x+t.rect.width/5,t.rect.y+5*t.rect.height/7,3*t.rect.width/5,t.rect.height/4);const e=3*t.rect.width/5,i=3*t.rect.height/5;t.fullTextRect=new l(t.rect.x+(t.rect.width-e)/2,t.rect.y+t.rect.height/4,e,i)}function Rt(t){t.anchors.push(new h(t.rect.x+t.rect.width/2,t.rect.y,R.Up)),t.anchors.push(new h(t.rect.x+t.rect.width,t.rect.y+2*t.rect.height/5,R.Right)),t.anchors.push(new h(t.rect.x+4*t.rect.width/5,t.rect.y+t.rect.height,R.Bottom)),t.anchors.push(new h(t.rect.x+t.rect.width/5,t.rect.y+t.rect.height,R.Bottom)),t.anchors.push(new h(t.rect.x,t.rect.y+2*t.rect.height/5,R.Left))}function bt(t,e){t.beginPath();const i=e.rect.width/5;t.moveTo(e.rect.x+i,e.rect.y),t.lineTo(e.rect.x+e.rect.width-i,e.rect.y),t.lineTo(e.rect.x+e.rect.width,e.rect.y+e.rect.height/2),t.lineTo(e.rect.x+e.rect.width-i,e.rect.y+e.rect.height),t.lineTo(e.rect.x+i,e.rect.y+e.rect.height),t.lineTo(e.rect.x,e.rect.y+e.rect.height/2),t.closePath(),t.fill(),t.stroke()}function Tt(t){t.anchors.push(new h(t.rect.x+t.rect.width/2,t.rect.y,R.Up)),t.anchors.push(new h(t.rect.x+t.rect.width,t.rect.y+t.rect.height/2,R.Right)),t.anchors.push(new h(t.rect.x+t.rect.width/2,t.rect.y+t.rect.height,R.Bottom)),t.anchors.push(new h(t.rect.x,t.rect.y+t.rect.height/2,R.Left)),t.anchors.push(new h(t.rect.x+t.rect.width/10,t.rect.y+t.rect.height/4,R.Left)),t.anchors.push(new h(t.rect.x+t.rect.width/10,t.rect.y+3*t.rect.height/4,R.Left)),t.anchors.push(new h(t.rect.x+9*t.rect.width/10,t.rect.y+t.rect.height/4,R.Right)),t.anchors.push(new h(t.rect.x+9*t.rect.width/10,t.rect.y+3*t.rect.height/4,R.Right))}function St(t){let e=t.rect.width/2,i=2*t.rect.height/3;e>i?e=i:i=e;let n=t.rect.height/10;n<10&&(n=10),t.iconRect=new l(t.rect.x+(t.rect.width-e)/2,t.rect.y+n,e,i)}function It(t){t.textRect=new l(t.rect.x+t.rect.width/5,t.rect.y+5*t.rect.height/7,3*t.rect.width/5,t.rect.height/4);const e=3*t.rect.width/5;t.fullTextRect=new l(t.rect.x+(t.rect.width-e)/2,t.rect.y,e,t.rect.height)}function Mt(t,e){t.beginPath();for(let i=0;i<5;++i)t.lineTo(Math.cos((18+72*i)/180*Math.PI)*e.rect.width/2+e.rect.x+e.rect.width/2,-Math.sin((18+72*i)/180*Math.PI)*e.rect.width/2+e.rect.y+e.rect.height/2),t.lineTo(Math.cos((54+72*i)/180*Math.PI)*e.rect.width/4+e.rect.x+e.rect.width/2,-Math.sin((54+72*i)/180*Math.PI)*e.rect.width/4+e.rect.y+e.rect.height/2);t.closePath(),t.fill(),t.stroke()}function Ct(t){t.anchors.push(new h(Math.cos(.1*Math.PI)*t.rect.width/2+t.rect.x+t.rect.width/2,-Math.sin(.1*Math.PI)*t.rect.width/2+t.rect.y+t.rect.height/2,R.Right)),t.anchors.push(new h(Math.cos(.5*Math.PI)*t.rect.width/2+t.rect.x+t.rect.width/2,-Math.sin(.5*Math.PI)*t.rect.width/2+t.rect.y+t.rect.height/2,R.Up)),t.anchors.push(new h(Math.cos(.9*Math.PI)*t.rect.width/2+t.rect.x+t.rect.width/2,-Math.sin(.9*Math.PI)*t.rect.width/2+t.rect.y+t.rect.height/2,R.Left)),t.anchors.push(new h(Math.cos(1.3*Math.PI)*t.rect.width/2+t.rect.x+t.rect.width/2,-Math.sin(1.3*Math.PI)*t.rect.width/2+t.rect.y+t.rect.height/2,R.Bottom)),t.anchors.push(new h(Math.cos(1.7*Math.PI)*t.rect.width/2+t.rect.x+t.rect.width/2,-Math.sin(1.7*Math.PI)*t.rect.width/2+t.rect.y+t.rect.height/2,R.Bottom))}function kt(t){t.iconRect=new l(0,0,0,0)}function At(t){const e=2*t.rect.width/5,i=2*t.rect.height/5;t.fullTextRect=new l(t.rect.x+(t.rect.width-e)/2,t.rect.y+(t.rect.height-i)/2,e,i),t.textRect=t.fullTextRect}function Nt(t,e){t.beginPath(),t.moveTo(e.rect.x+e.rect.width/5,e.rect.y+13*e.rect.height/16),t.bezierCurveTo(e.rect.x-e.rect.width/15,e.rect.y+13*e.rect.height/16,e.rect.x-e.rect.width/15,e.rect.y+7*e.rect.height/16,e.rect.x+e.rect.width/5,e.rect.y+7*e.rect.height/16),t.bezierCurveTo(e.rect.x+e.rect.width/5,e.rect.y,e.rect.x+4*e.rect.width/5,e.rect.y,e.rect.x+4*e.rect.width/5,e.rect.y+7*e.rect.height/16),t.bezierCurveTo(e.rect.x+16*e.rect.width/15,e.rect.y+7*e.rect.height/16,e.rect.x+16*e.rect.width/15,e.rect.y+13*e.rect.height/16,e.rect.x+4*e.rect.width/5,e.rect.y+13*e.rect.height/16),t.closePath(),t.fill(),t.stroke()}function zt(t){t.anchors.push(new h(t.rect.x,t.rect.y+3*t.rect.height/5,R.Left)),t.anchors.push(new h(t.rect.x+t.rect.width/2,t.rect.y+t.rect.height/9,R.Up)),t.anchors.push(new h(t.rect.x+t.rect.width,t.rect.y+3*t.rect.height/5,R.Right)),t.anchors.push(new h(t.rect.x+t.rect.width/2,t.rect.y+4*t.rect.height/5,R.Bottom))}function Dt(t){t.iconRect=new l(0,0,0,0)}function Wt(t){t.textRect=new l(t.rect.x+t.rect.width/4,t.rect.y+t.rect.height/4,t.rect.width/2,6*t.rect.height/11),t.fullTextRect=t.textRect}function Ft(t,e){t.beginPath(),t.moveTo(e.rect.x,e.rect.y),t.lineTo(e.rect.x+e.rect.width,e.rect.y),t.lineTo(e.rect.x+e.rect.width,e.rect.y+3*e.rect.height/4),t.lineTo(e.rect.x+8*e.rect.width/16,e.rect.y+3*e.rect.height/4),t.lineTo(e.rect.x+e.rect.width/4,e.rect.ey),t.lineTo(e.rect.x+5*e.rect.width/16,e.rect.y+3*e.rect.height/4),t.lineTo(e.rect.x,e.rect.y+3*e.rect.height/4),t.closePath(),t.fill(),t.stroke()}function Bt(t){t.iconRect=new l(0,0,0,0)}function Ht(t){t.textRect=new l(t.rect.x,t.rect.y,t.rect.width,3*t.rect.height/4),t.fullTextRect=t.textRect}function Et(t){t.anchors.push(new h(t.rect.x,t.rect.y+3*t.rect.height/8,R.Left)),t.anchors.push(new h(t.rect.x+t.rect.width/2,t.rect.y,R.Up)),t.anchors.push(new h(t.rect.x+t.rect.width,t.rect.y+3*t.rect.height/8,R.Right)),t.anchors.push(new h(t.rect.x+t.rect.width/4,t.rect.ey,R.Bottom))}function Ut(t,e){t.beginPath();const i=e.rect.width/6;t.moveTo(e.rect.x,e.rect.y),t.lineTo(e.rect.ex-i,e.rect.y),t.lineTo(e.rect.ex,e.rect.y+i),t.lineTo(e.rect.ex,e.rect.ey),t.lineTo(e.rect.x,e.rect.ey),t.closePath(),t.moveTo(e.rect.ex-i,e.rect.y),t.lineTo(e.rect.ex-i,e.rect.y+i),t.lineTo(e.rect.ex,e.rect.y+i),t.fill(),t.stroke()}const _t=5,Ot=30;function $t(t){let e=t.rect.x,i=t.rect.y,n=t.rect.width;t.imageWidth&&(n=t.imageWidth,e+=(t.rect.width-n)/2);let r=t.rect.height-t.textRect.height-_t;r0&&(e=t.imageHeight):t.icon&&t.iconSize>0&&(e=t.iconSize),e}class Xt{constructor(t,e,i,n,r="",h=""){this.points=[],this.fillStyle="",this.strokeStyle="",this.points.push(t),this.points.push(e),this.points.push(i),this.points.push(n),this.fillStyle=r,this.strokeStyle=h||r}render(t){t.save(),t.fillStyle=this.fillStyle,t.strokeStyle=this.strokeStyle,t.beginPath();for(let e=0;e{},ee.line=L,re.line=S,ie.line=E,ne.line=U,ee.image=(t,e)=>{},ie.image=$t,ne.image=jt,ee.cube=qt,re.cube=Gt,ie.cube=Vt,ne.cube=Jt,ee.people=Qt,ie.people=Zt,ne.people=te,he.line={drawFn:_,drawControlPointsFn:O,controlPointsFn:$,pointIn:q},he.polyline={drawFn:Y,drawControlPointsFn:X,controlPointsFn:K,dockControlPointFn:G,pointIn:q},he.curve={drawFn:rt,drawControlPointsFn:ht,controlPointsFn:ot,pointIn:st},oe.triangleSolid=lt,oe.triangle=yt,oe.diamondSolid=dt,oe.diamond=xt,oe.circleSolid=ft,oe.circle=ut,oe.line=wt,oe.lineUp=pt,oe.lineDown=vt;class ce extends y{constructor(t){super(t),this.is3D=!1,this.zRotate=0,this.imageRatio=!0,this.anchors=[],this.rotatedAnchors=[],this.animateType=0,this.animateDuration=0,this.animateFrames=[],this.is3D=t.is3D,this.z=t.z,this.zRotate=t.zRotate||0,this.borderRadius=+t.borderRadius||0,this.borderRadius>1&&(this.borderRadius=1),this.icon=t.icon,this.iconFamily=t.iconFamily,this.iconSize=+t.iconSize,this.iconColor=t.iconColor,this.image=t.image,t.imgNaturalWidth&&(this.imgNaturalWidth=t.imgNaturalWidth),t.imgNaturalHeight&&(this.imgNaturalHeight=t.imgNaturalHeight),t.imageWidth&&(this.imageWidth=t.imageWidth),t.imageHeight&&(this.imageHeight=t.imageHeight),this.imageRatio=t.imageRatio,this.text=t.text,t.textMaxLine&&(this.textMaxLine=+t.textMaxLine||0),t.parentRect&&(this.parentRect=t.parentRect),t.animateFrames&&(this.animateFrames=t.animateFrames),t.animateDuration&&(this.animateDuration=t.animateDuration),this.animateType=t.animateType?t.animateType:t.animateDuration?"8":"",this.init(),this.setChild(t)}static cloneState(t){const e=new ce(t);return delete e.animateFrames,e}init(){var t;ne[this.name]?ne[this.name](this):((t=this).textRect=new l(t.rect.x+10,t.rect.y+2*t.rect.height/3,t.rect.width-20,t.rect.height/3-5),t.fullTextRect=t.rect),ie[this.name]?ie[this.name](this):function(t){t.iconRect=new l(t.rect.x,t.rect.y+10,t.rect.width,2*t.rect.height/3-20),t.fullIconRect=t.rect}(this),this.calcAnchors()}setChild(t){if(t.children){this.children=[];for(let e=0;e{this.imgNaturalWidth=this.img.naturalWidth,this.imgNaturalHeight=this.img.naturalHeight,this.drawImg(t),this.emitRender()}));this.icon&&(t.save(),t.shadowColor="",t.shadowBlur=0,function(t,e){t.save(),t.textAlign="center",t.textBaseline="middle";const i=e.getIconRect();e.iconSize>0?t.font=`${e.iconSize}px ${e.iconFamily}`:i.width>i.height?t.font=`${i.height}px ${e.iconFamily}`:t.font=`${i.width}px ${e.iconFamily}`,e.iconColor||(e.iconColor="#2f54eb"),t.fillStyle=e.iconColor,t.beginPath(),t.fillText(e.icon,i.x+i.width/2,i.y+i.height/2),t.restore()}(t,this),t.restore())}}drawImg(t){t.save(),t.shadowColor="",t.shadowBlur=0;const e=this.getIconRect().clone(),i=e.width,n=e.height;this.imageWidth&&(e.width=this.imageWidth),this.imageHeight&&(e.height=this.imageHeight),this.imageRatio&&(this.imageWidth?e.height=this.imgNaturalHeight/this.imgNaturalWidth*e.width:e.width=this.imgNaturalWidth/this.imgNaturalHeight*e.height),"image"!==this.name&&(e.x+=(i-e.width)/2,e.y+=(n-e.height)/2),t.drawImage(this.img,e.x,e.y,e.width,e.height),t.restore()}emitRender(){it.set("render",1)}calcAnchors(){var t;this.anchors=[],re[this.name]?re[this.name](this):((t=this).anchors.push(new h(t.rect.x,t.rect.y+t.rect.height/2,R.Left)),t.anchors.push(new h(t.rect.x+t.rect.width/2,t.rect.y,R.Up)),t.anchors.push(new h(t.rect.x+t.rect.width,t.rect.y+t.rect.height/2,R.Right)),t.anchors.push(new h(t.rect.x+t.rect.width/2,t.rect.y+t.rect.height,R.Bottom))),this.calcRotateAnchors()}calcRotateAnchors(t){void 0===t&&(t=this.rotate),this.rotatedAnchors=[];for(const e of this.anchors)this.rotatedAnchors.push(e.clone().rotate(t,this.rect.center))}getTextRect(){let t=this.textRect;return this.icon||this.image||(t=this.fullTextRect),t}getIconRect(){let t=this.iconRect;return this.text||(t=this.fullIconRect||this.fullTextRect||this.rect),t}getDockWatchers(){this.dockWatchers=this.rect.toPoints(),this.dockWatchers.unshift(this.rect.center)}clearImg(){this.img=null}animate(t,e){let i=e-this.animateStart;if(i>this.animateDuration){if(++this.animateCycleIndex>=this.animateCycle&&this.animateCycle>0){this.animateStart=0,this.animateCycleIndex=0;const t=this.animateFrames[this.animateFrames.length-1];return this.dash=t.state.dash,this.strokeStyle=t.state.strokeStyle,this.fillStyle=t.state.fillStyle,this.font=t.state.font,this.lineWidth=t.state.lineWidth,this.rotate=t.state.rotate,this.globalAlpha=t.state.globalAlpha,t.state.rect&&t.state.rect.width&&(this.rect=new l(t.state.rect.x,t.state.rect.y,t.state.rect.width,t.state.rect.height),this.init()),void it.set("animateEnd",{type:"node",data:this})}this.animateStart=e,i=0,this.animateFrames[0].initState=ce.cloneState(this)}let n=!1;for(let t=0;t=e.start&&ithis.length+this.animateSpan){if(++this.animateCycleIndex>=this.animateCycle&&this.animateCycle>0)return this.animateStart=0,void it.set("animateEnd",{type:"line",data:this});this.animatePos=this.animateSpan}}}class le{constructor(t={},e=""){this.options=t,this.name="",this.canvas=document.createElement("canvas"),this.nodes=it.get("nodes"),this.lines=it.get("lines"),this.rendering=!1,this.name=e,this.canvas.style.outline="none"}resize(t,e){this.canvas.width=t,this.canvas.height=e}addNode(t){if(!ee[t.name])return!1;let e=!1;for(const i of this.nodes)if(i.id===t.id){e=!0;break}return!e&&(this.nodes.push(t),!0)}render(){if(this.rendering)return;this.rendering=!0,this.canvas.height=this.canvas.height;const t=this.canvas.getContext("2d");t.strokeStyle=this.options.color,t.fillStyle="#fff",this.renderNodes(),this.renderLines(),it.set("render",1),this.rendering=!1}renderNodes(){if(!this.nodes.length)return;const t=this.canvas.getContext("2d");for(const e of this.nodes)e.animateStart&&e.animateDuration||e.render(t)}renderLines(){if(!this.lines.length)return;const t=this.canvas.getContext("2d");let e=0;for(const i of this.lines)i.to?(i.render(t),++e):this.lines.splice(e++,1)}}class ye{constructor(t,e){this.options=e,this.canvas=document.createElement("canvas"),this.anchorRadius=4,this.hoverAnchorIndex=-1,this.dockLineX=0,this.dockLineY=0,this.options.hoverColor||(this.options.hoverColor="#d4380d"),this.options.dragColor||(this.options.dragColor="#d4380d"),this.canvas.style.position="absolute",this.canvas.style.left="0",this.canvas.style.top="0",this.canvas.style.outline="none",t.appendChild(this.canvas)}setLine(t,e="",i="curve"){this.line=new ae,this.line.name=i,this.line.setFrom(t,e),it.get("lines").push(this.line)}lineTo(t,e="triangleSolid"){this.line.setTo(t,e),this.line.calcControlPoints()}lineFrom(t){this.line.setFrom(t,this.line.fromArrow),this.line.calcControlPoints()}lineMove(t,e){const i=t.x-e.x,n=t.y-e.y;this.line.setTo(new h(this.initLine.to.x+i,this.initLine.to.y+n),this.line.toArrow),this.line.setFrom(new h(this.initLine.from.x+i,this.initLine.from.y+n),this.line.fromArrow),this.line.calcControlPoints()}render(){this.canvas.height=this.canvas.height;const t=this.canvas.getContext("2d");if(t.translate(0,0),t.strokeStyle=this.options.hoverColor,t.fillStyle="#fff",this.node)for(let e=0;e0&&(t.beginPath(),t.moveTo(this.dockLineX,0),t.lineTo(this.dockLineX,this.canvas.height),t.stroke()),this.dockLineY>0&&(t.beginPath(),t.moveTo(0,this.dockLineY),t.lineTo(this.canvas.width,this.dockLineY),t.stroke()),this.dragRect&&(t.strokeStyle=this.options.dragColor,t.beginPath(),t.strokeRect(this.dragRect.x,this.dragRect.y,this.dragRect.width,this.dragRect.height),t.fillRect(this.dragRect.x,this.dragRect.y,this.dragRect.width,this.dragRect.height))}resize(t,e){this.canvas.width=t,this.canvas.height=e}getLen(t){const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("d",`M${t.from.x} ${t.from.y} C${t.controlPoints[0].x} ${t.controlPoints[0].y} ${t.controlPoints[1].x} ${t.controlPoints[1].y} ${t.to.x} ${t.to.y}`),e.getTotalLength()}}class de{constructor(t,e){this.options=e,this.canvas=document.createElement("canvas"),this.rotateCPs=[],this.sizeCPs=[],this.nodes=[],this.lines=[],this.rotate=0,this.initialSizeCPs=[],this.nodeRects=[],this.childrenRects={},this.dockWatchers=[],this.rotating=!1,this.options.activeColor||(this.options.activeColor="#d4380d"),this.canvas.style.position="absolute",this.canvas.style.left="0",this.canvas.style.top="0",this.canvas.style.outline="none",t.appendChild(this.canvas)}calcControlPoints(){if(1===this.nodes.length){if(this.rect=this.nodes[0].rect,this.sizeCPs=this.nodes[0].rect.toPoints(),this.rotateCPs=[new h(this.nodes[0].rect.x+this.nodes[0].rect.width/2,this.nodes[0].rect.y-35),new h(this.nodes[0].rect.x+this.nodes[0].rect.width/2,this.nodes[0].rect.y)],this.rotate||this.nodes[0].rotate){for(const t of this.sizeCPs)this.nodes[0].rotate&&t.rotate(this.nodes[0].rotate,this.nodes[0].rect.center),this.rotate&&t.rotate(this.rotate,this.rect.center);for(const t of this.rotateCPs)this.nodes[0].rotate&&t.rotate(this.nodes[0].rotate,this.nodes[0].rect.center),this.rotate&&t.rotate(this.rotate,this.rect.center)}return void(this.options.hideRotateCP&&(this.rotateCPs=[new h(-1e3,-1e3),new h(-1e3,-1e3)]))}let t=99999,e=99999,i=-99999,n=-99999;const r=this.getPoints();for(const h of r)t>h.x&&(t=h.x),e>h.y&&(e=h.y),i1&&(t.translate(this.rect.center.x,this.rect.center.y),t.rotate(this.rotate*Math.PI/180),t.translate(-this.rect.center.x,-this.rect.center.y)),t.save(),t.globalAlpha=.3,t.beginPath(),t.moveTo(this.sizeCPs[0].x-.5,this.sizeCPs[0].y-.5),t.lineTo(this.sizeCPs[1].x+.5,this.sizeCPs[1].y-.5),t.lineTo(this.sizeCPs[2].x+.5,this.sizeCPs[2].y+.5),t.lineTo(this.sizeCPs[3].x-.5,this.sizeCPs[3].y-.5),t.closePath(),t.stroke(),t.restore(),!it.get("locked")){t.beginPath(),t.moveTo(this.rotateCPs[0].x,this.rotateCPs[0].y),t.lineTo(this.rotateCPs[1].x,this.rotateCPs[1].y),t.stroke(),t.beginPath(),t.arc(this.rotateCPs[0].x,this.rotateCPs[0].y,5,0,2*Math.PI),t.fill(),t.stroke(),t.lineWidth=1;for(const e of this.sizeCPs)t.save(),t.beginPath(),1===this.nodes.length&&(this.nodes[0].rotate||this.rotate)&&(t.translate(e.x,e.y),t.rotate((this.nodes[0].rotate+this.rotate)*Math.PI/180),t.translate(-e.x,-e.y)),t.fillRect(e.x-4.5,e.y-4.5,8,8),t.strokeRect(e.x-5.5,e.y-5.5,10,10),t.restore()}}saveNodeRects(){this.nodeRects=[],this.childrenRects={};for(const t of this.nodes)this.nodeRects.push(new l(t.rect.x,t.rect.y,t.rect.width,t.rect.height)),this.saveChildrenRects(t);this.initialSizeCPs=[];for(const t of this.sizeCPs){const e=t.clone();1===this.nodes.length&&this.nodes[0].rotate&&e.rotate(-this.nodes[0].rotate,this.nodes[0].rect.center),this.initialSizeCPs.push(e)}this.getDockWatchers()}saveChildrenRects(t){if(t.children)for(const e of t.children)this.childrenRects[e.id]=new l(e.rect.x,e.rect.y,e.rect.width,e.rect.height),this.saveChildrenRects(e)}resizeNodes(t,e){let i=0;const n=new h(0,0);let r,o,s,c;for(const h of this.nodes){switch(t){case 0:r=e.x,o=e.y,s=this.initialSizeCPs[2].x-e.x,c=this.initialSizeCPs[2].y-e.y,n.x=s>5?r:this.initialSizeCPs[2].x-5,n.y=c>5?o:this.initialSizeCPs[2].y-5;break;case 1:o=e.y,s=e.x-this.initialSizeCPs[0].x,c=this.initialSizeCPs[2].y-e.y,n.x=this.initialSizeCPs[0].x,n.y=c>5?o:this.initialSizeCPs[2].y-5;break;case 2:s=e.x-this.initialSizeCPs[0].x,c=e.y-this.initialSizeCPs[0].y,n.x=this.initialSizeCPs[0].x,n.y=this.initialSizeCPs[0].y;break;case 3:r=e.x,s=this.initialSizeCPs[2].x-e.x,c=e.y-this.initialSizeCPs[0].y,n.x=s>5?r:this.initialSizeCPs[2].x-5,n.y=this.initialSizeCPs[0].y}s=s>5?s:5,c=c>5?c:5,this.calcResizedPos(h.rect,this.nodeRects[i],n,s/(this.initialSizeCPs[2].x-this.initialSizeCPs[0].x),c/(this.initialSizeCPs[2].y-this.initialSizeCPs[0].y)),h.rect.calceCenter(),h.init(),this.updateChildren(h),++i}this.updateLines()}calcResizedPos(t,e,i,n,r){t.x=i.x+(e.x-this.initialSizeCPs[0].x)*n,t.y=i.y+(e.y-this.initialSizeCPs[0].y)*r,t.width=e.width*n,t.height=e.height*r,t.ex=t.x+t.width,t.ey=t.y+t.height}moveNodes(t,e){if(this.nodeRects.length!==this.nodes.length)return;let i=0;for(const n of this.nodes)n.rect.x=this.nodeRects[i].x+t,n.rect.y=this.nodeRects[i].y+e,n.rect.ex=n.rect.x+n.rect.width,n.rect.ey=n.rect.y+n.rect.height,n.rect.calceCenter(),n.init(),this.updateChildren(n),++i;this.updateLines()}updateChildren(t){if(t.children)for(const e of t.children)e.calcChildRect(t),e.init(),this.updateChildren(e)}updateLines(t){t||(t=this.nodes);const e=it.get("lines");for(const i of e){let e=!1;for(const n of t)i.from.id===n.id&&(i.from.x=n.rotatedAnchors[i.from.anchorIndex].x,i.from.y=n.rotatedAnchors[i.from.anchorIndex].y,e=!0),i.to.id===n.id&&(i.to.x=n.rotatedAnchors[i.to.anchorIndex].x,i.to.y=n.rotatedAnchors[i.to.anchorIndex].y,e=!0),n.children&&this.updateLines(n.children);e&&i.calcControlPoints()}}changeLineType(){for(const t of this.lines)t.calcControlPoints()}offsetRotate(t){this.rotating=!0;let e=0;for(const i of this.nodes){const n=this.nodeRects[e].center.clone();this.nodes.length>1&&n.rotate(t,this.rect.center),i.rect.x=n.x-i.rect.width/2,i.rect.y=n.y-i.rect.height/2,i.rect.ex=i.rect.x+i.rect.width,i.rect.ey=i.rect.y+i.rect.height,i.rect.calceCenter(),i.init(),i.offsetRotate=t,i.calcRotateAnchors(i.rotate+i.offsetRotate),this.updateChildren(i),++e}this.rotate=t}updateRotate(){for(const t of this.nodes)t.rotate+=t.offsetRotate,t.offsetRotate=0;this.rotate=0,this.rotating=!1}addNode(t){this.nodes.push(t)}setNodes(t){this.nodes=t,this.lines=[]}hasNode(t){let e=!1;for(const i of this.nodes)if(i.id===t.id){e=!0;break}return e}renderNodesLines(){const t=this.canvas.getContext("2d");t.save();for(const e of this.nodes){const i=new ce(e);i.fillStyle=null,i.icon="",i.image="",i.text="",i.children=null,"transparent"!==i.strokeStyle&&(i.strokeStyle="#ffffff",i.lineWidth+=2,i.render(t),i.strokeStyle="#d4380d",i.lineWidth-=2),i.render(t)}for(const e of this.lines){if(!e.to)continue;const i=new ae(e);i.strokeStyle="#ffffff",i.lineWidth+=2,i.render(t),i.strokeStyle="#d4380d",i.lineWidth-=2,i.render(t)}t.restore()}resize(t,e){this.canvas.width=t,this.canvas.height=e}updateProps(t,e,i){if(t){for(const e of t)e.rect.ex=e.rect.x+e.rect.width,e.rect.ey=e.rect.y+e.rect.height,e.rect.calceCenter(),e.init(),e.dash=i.dash,e.lineWidth=i.lineWidth,e.strokeStyle=i.strokeStyle,e.fillStyle=i.fillStyle,e.globalAlpha=i.globalAlpha;this.updateLines(t)}if(e)for(const t of e)t.dash=i.dash,t.lineWidth=i.lineWidth,t.strokeStyle=i.strokeStyle,t.fillStyle=i.fillStyle,t.globalAlpha=i.globalAlpha;this.calcControlPoints()}getDockWatchers(){if(1===this.nodes.length)return this.dockWatchers=this.nodeRects[0].toPoints(),void this.dockWatchers.unshift(this.nodeRects[0].center);this.dockWatchers=this.rect.toPoints(),this.dockWatchers.unshift(this.rect.center)}}class xe{constructor(t,e){this.options=e,this.canvas=document.createElement("canvas"),this.nodes=[],this.lines=[],this.last=Date.now(),this.options.animateColor||(this.options.animateColor="#ff6600"),this.canvas.style.position="absolute",this.canvas.style.left="0",this.canvas.style.top="0",this.canvas.style.outline="none",t.appendChild(this.canvas)}render(t=!0){this.timer&&cancelAnimationFrame(this.timer),t&&(this.nodes=[],this.lines=[]);const e=it.get("nodes"),i=it.get("lines");for(const t of e){let e=!1;for(let i=0;i{const t=Date.now(),e=t-this.last;if(this.last=t,e>15){this.canvas.height=this.canvas.height;const e=this.canvas.getContext("2d");for(let t=0;t{if(this.scheduledAnimationFrame)return;if(t.altKey&&this.mouseDown)return void this.translate(t.offsetX-this.mouseDown.x,t.offsetY-this.mouseDown.y);if(this.locked<0)return;this.scheduledAnimationFrame=!0;const e=new h(t.offsetX,t.offsetY);requestAnimationFrame(()=>{if(this.scheduledAnimationFrame=!1,!this.mouseDown)return this.getMoveIn(e),this.moveIn.hoverNode?(this.hoverLayer.node=this.moveIn.hoverNode,this.hoverLayer.render(),!this.lastHoverNode&&this.options.on&&this.options.on("moveInNode",this.moveIn.hoverNode)):this.lastHoverNode&&(this.hoverLayer.node=null,this.hoverLayer.canvas.height=this.hoverLayer.canvas.height,this.options.on&&this.options.on("moveOutNode",null)),void(this.moveIn.type===ue.LineControlPoint?(this.hoverLayer.hoverLineCP=this.moveIn.lineControlPoint,this.hoverLayer.render()):this.hoverLayer.hoverLineCP&&(this.hoverLayer.hoverLineCP=null,this.hoverLayer.render()));(e.x+50>this.parentElem.clientWidth+this.parentElem.scrollLeft||e.y+50>this.parentElem.clientHeight+this.parentElem.scrollTop)&&this.options.on&&this.options.on("moveOutParent",e);const t=e.x+50>this.hoverLayer.canvas.width||e.y+50>this.hoverLayer.canvas.height;switch(t&&(e.x+50>this.hoverLayer.canvas.width&&(this.canvas.width+=200),e.y+50>this.hoverLayer.canvas.height&&(this.canvas.height+=200),this.offscreen.canvas.width=this.canvas.width,this.offscreen.canvas.height=this.canvas.height,this.hoverLayer.canvas.width=this.canvas.width,this.hoverLayer.canvas.height=this.canvas.height,this.activeLayer.canvas.width=this.canvas.width,this.activeLayer.canvas.height=this.canvas.height,this.options.on&&this.options.on("resize",{width:this.canvas.width,height:this.canvas.height})),this.moveIn.type){case ue.None:if(this.hoverLayer.dragRect=new l(this.mouseDown.x,this.mouseDown.y,e.x-this.mouseDown.x,e.y-this.mouseDown.y),!t)return void this.hoverLayer.render();break;case ue.Nodes:this.nodesMoved=!0;const i=e.x-this.mouseDown.x,n=e.y-this.mouseDown.y;if(i||n){const t=this.getDockPos(i,n);this.activeLayer.moveNodes(t.x?t.x:i,t.y?t.y:n),this.options.on&&this.options.on("moveNodes",this.activeLayer.nodes)}break;case ue.ResizeCP:this.activeLayer.resizeNodes(this.moveIn.activeAnchorIndex,e),this.options.on&&this.options.on("resizeNodes",this.activeLayer.nodes);break;case ue.LineTo:case ue.HoverAnchors:let r=this.toArrowType;this.moveIn.hoverLine&&(r=this.moveIn.hoverLine.toArrow),this.hoverLayer.lineTo(this.getLineDock(e),r);break;case ue.LineFrom:this.hoverLayer.lineFrom(this.getLineDock(e));break;case ue.LineMove:this.hoverLayer.lineMove(e,this.mouseDown);break;case ue.LineControlPoint:this.moveIn.hoverLine.controlPoints[this.moveIn.lineControlPoint.id].x=e.x,this.moveIn.hoverLine.controlPoints[this.moveIn.lineControlPoint.id].y=e.y,he[this.moveIn.hoverLine.name]&&he[this.moveIn.hoverLine.name].dockControlPointFn&&he[this.moveIn.hoverLine.name].dockControlPointFn(this.moveIn.hoverLine.controlPoints[this.moveIn.lineControlPoint.id],this.moveIn.hoverLine);break;case ue.Rotate:this.activeLayer.nodes.length&&(this.activeLayer.offsetRotate(this.getAngle(e)),this.activeLayer.updateLines()),this.options.on&&this.options.on("rotateNodes",this.activeLayer.nodes)}this.hoverLayer.render(),this.activeLayer.render(),this.animateLayer.render(),this.offscreen.render()})},this.onmousedown=t=>{switch(this.mouseDown={x:t.offsetX,y:t.offsetY},it.set("activeLine",null),t.altKey&&(this.hoverLayer.canvas.style.cursor="move"),this.inputNode&&this.setNodeText(),this.moveIn.type){case ue.None:return this.activeLayer.nodes=[],this.activeLayer.lines=[],this.activeLayer.canvas.height=this.activeLayer.canvas.height,this.hoverLayer.node=null,this.hoverLayer.line=null,this.hoverLayer.canvas.height=this.hoverLayer.canvas.height,void(this.options.on&&this.options.on("space",null));case ue.Line:case ue.LineControlPoint:return t.ctrlKey?(this.activeLayer.lines.push(this.moveIn.hoverLine),this.options.on&&(this.lines.length>1||this.nodes.length?this.options.on("multi",{nodes:this.activeLayer.nodes,lines:this.activeLayer.lines}):this.options.on("line",this.moveIn.hoverLine))):(this.activeLayer.nodes=[],this.activeLayer.lines=[this.moveIn.hoverLine],this.options.on&&this.options.on("line",this.moveIn.hoverLine)),it.set("activeLine",this.moveIn.hoverLine),this.hoverLayer.render(),void this.activeLayer.render();case ue.LineMove:this.hoverLayer.initLine=new ae(this.moveIn.hoverLine);case ue.LineFrom:case ue.LineTo:return this.activeLayer.nodes=[],this.activeLayer.lines=[this.moveIn.hoverLine],this.options.on&&this.options.on("line",this.moveIn.hoverLine),it.set("activeLine",this.moveIn.hoverLine),this.hoverLayer.line=this.moveIn.hoverLine,this.hoverLayer.render(),this.activeLayer.render(),void this.animateLayer.render();case ue.HoverAnchors:this.hoverLayer.setLine(new h(this.moveIn.hoverNode.rotatedAnchors[this.moveIn.hoverAnchorIndex].x,this.moveIn.hoverNode.rotatedAnchors[this.moveIn.hoverAnchorIndex].y,this.moveIn.hoverNode.rotatedAnchors[this.moveIn.hoverAnchorIndex].direction,this.moveIn.hoverAnchorIndex,this.moveIn.hoverNode.id),this.fromArrowType,this.lineName);case ue.Nodes:if(!this.moveIn.hoverNode||this.activeLayer.hasNode(this.moveIn.hoverNode))break;t.ctrlKey?(this.activeLayer.addNode(this.moveIn.hoverNode),this.options.on&&(this.activeLayer.nodes.length>1||this.activeLayer.lines.length?this.options.on("multi",{nodes:this.activeLayer.nodes,lines:this.activeLayer.lines}):this.options.on("node",this.moveIn.hoverNode))):(this.activeLayer.setNodes([this.moveIn.hoverNode]),this.options.on&&this.options.on("node",this.moveIn.hoverNode))}this.activeLayer.saveNodeRects(),this.activeLayer.render(),this.animateLayer.render()},this.onmouseup=t=>{if(this.mouseDown=null,this.lastTranlated.x&&this.cache(),this.lastTranlated.x=0,this.lastTranlated.y=0,this.hoverLayer.dockAnchor=null,this.hoverLayer.dockLineX=0,this.hoverLayer.dockLineY=0,this.hoverLayer.canvas.style.cursor="default",this.hoverLayer.dragRect)this.getRectNodes(this.nodes,this.hoverLayer.dragRect),this.getRectLines(this.lines,this.hoverLayer.dragRect),this.activeLayer.render(),this.options.on&&this.activeLayer.nodes&&this.activeLayer.nodes.length&&this.options.on("multi",{nodes:this.activeLayer.nodes,lines:this.activeLayer.lines});else switch(this.moveIn.type){case ue.HoverAnchors:this.hoverLayer.line&&this.hoverLayer.line.to&&(this.activeLayer.nodes=[],this.hoverLayer.line.to.id||!this.options.disableEmptyLine?(this.activeLayer.lines=[this.hoverLayer.line],it.set("activeLine",this.hoverLayer.line),this.options.on("line",this.hoverLayer.line)):this.lines.pop(),this.activeLayer.render()),this.offscreen.render(),this.hoverLayer.line=null;break;case ue.Rotate:this.activeLayer.updateRotate(),this.activeLayer.render(),this.animateLayer.render();break;case ue.LineControlPoint:it.set("pts-"+this.moveIn.hoverLine.id,null)}this.hoverLayer.dragRect=null,this.hoverLayer.render(),(this.nodesMoved||this.moveIn.type!==ue.None)&&this.cache(),this.nodesMoved=!1},this.ondblclick=t=>{switch(this.moveIn.type){case ue.Nodes:if(this.moveIn.hoverNode){const e=this.clickText(this.moveIn.hoverNode,new h(t.offsetX,t.offsetY));e&&this.showInput(e.node,e.textRect),this.options.on&&this.options.on("dblclick",this.moveIn.hoverNode)}}},this.onkeydown=t=>{let e=!1,i=0,n=0;switch(t.keyCode){case 8:case 46:if(!this.activeLayer.nodes.length&&!this.activeLayer.lines.length)return;let r=0;for(const t of this.activeLayer.lines){r=0;for(const e of this.lines){if(t.id===e.id){this.lines.splice(r,1);break}++r}}for(const t of this.activeLayer.nodes)(r=this.findNode(t))>-1&&this.nodes.splice(r,1);this.activeLayer.nodes=[],this.activeLayer.lines=[],this.hoverLayer.node=null,this.hoverLayer.line=null,it.set("activeLine",null),e=!0;break;case 37:i=-5,t.ctrlKey&&(i=-1),e=!0;break;case 38:n=-5,t.ctrlKey&&(n=-1),e=!0;break;case 39:i=5,t.ctrlKey&&(i=1),e=!0;break;case 40:n=5,t.ctrlKey&&(n=1),e=!0}e&&((i||n)&&(this.activeLayer.saveNodeRects(),this.activeLayer.moveNodes(i,n)),this.activeLayer.render(),this.animateLayer.render(),this.hoverLayer.render(),this.offscreen.render(),this.cache())},this.options=e||{},this.options.font||(this.options.font={color:"#333",fontFamily:'"Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial',fontSize:12,lineHeight:1.5,textAlign:"center",textBaseline:"middle"}),this.options.color||(this.options.color="#000"),this.options.rotateCursor||(this.options.rotateCursor="/assets/img/rotate.cur"),this.options.font.fontFamily||(this.options.font.fontFamily='"Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial'),this.options.font.color||(this.options.font.color="#333"),this.options.font.fontSize||(this.options.font.fontSize=12),this.options.font.lineHeight||(this.options.font.lineHeight=1.5),this.options.font.textAlign||(this.options.font.textAlign="center"),this.options.font.textBaseline||(this.options.font.textBaseline="middle"),it.set("nodes",this.nodes),it.set("lines",this.lines),this.parentElem="string"==typeof t?document.getElementById(t):t,this.offscreen=new le(this.options,"offscreen"),it.set("offscreen",this.offscreen.canvas),this.parentElem.appendChild(this.canvas),this.activeLayer=new de(this.parentElem,this.options),this.animateLayer=new xe(this.parentElem,this.options),this.hoverLayer=new ye(this.parentElem,this.options),this.resize(),this.hoverLayer.canvas.ondragover=t=>t.preventDefault(),this.hoverLayer.canvas.ondrop=t=>{this.ondrop(t)},this.subcribe=it.subcribe("render",()=>{this.renderOffscreen()}),this.subcribeAnimateMoved=it.subcribe("animateMoved",t=>{this.activeLayer.updateLines(this.nodes),this.activeLayer.render(),this.offscreen.render(),this.options.on&&this.options.on("animateMoved",t)}),this.subcribeAnimateEnd=it.subcribe("animateEnd",t=>{if(t){switch(t.type){case"line":for(const e of this.lines)if(e.id===t.data.id){e.animateStart=0;break}break;case"node":this.offscreen.render()}this.options.on&&this.options.on("animateEnd",t)}}),this.hoverLayer.canvas.onmousemove=this.onMouseMove,this.hoverLayer.canvas.onmousedown=this.onmousedown,this.hoverLayer.canvas.onmouseup=this.onmouseup,this.hoverLayer.canvas.ondblclick=this.ondblclick,this.hoverLayer.canvas.tabIndex=0,this.hoverLayer.canvas.onkeydown=this.onkeydown,this.hoverLayer.canvas.onwheel=t=>{t.altKey&&(t.preventDefault(),t.deltaY<0?this.scale(1.1):this.scale(.9),this.hoverLayer.canvas.focus())},this.hoverLayer.canvas.ontouchend=t=>{this.ontouched(t)},this.input.style.position="absolute",this.input.style.zIndex="-1",this.input.style.left="-1000px",this.input.style.width="0",this.input.style.height="0",this.input.style.outline="none",this.input.style.border="1px solid #cdcdcd",this.input.style.resize="none",this.parentElem.appendChild(this.input),this.canvas.style.outline="none",this.cache()}resize(t){t?(this.canvas.width=t.width,this.canvas.height=t.height):(this.options.width&&"auto"!==this.options.width?this.canvas.width=+this.options.width:this.canvas.width=this.parentElem.clientWidth,this.options.height&&"auto"!==this.options.height?this.canvas.height=+this.options.height:this.canvas.height=this.parentElem.clientHeight-8),this.offscreen.resize(this.canvas.width,this.canvas.height),this.hoverLayer.resize(this.canvas.width,this.canvas.height),this.activeLayer.resize(this.canvas.width,this.canvas.height),this.animateLayer.resize(this.canvas.width,this.canvas.height)}ondrop(t){t.preventDefault();const e=JSON.parse(t.dataTransfer.getData("Text"));e.rect.x=t.offsetX-e.rect.width/2<<0,e.rect.y=t.offsetY-e.rect.height/2<<0,this.addNode(new ce(e))}getTouchOffset(t){let e=this.parentElem,i=0,n=0;for(;e;)i+=e.offsetLeft,n+=e.offsetTop,e=e.offsetParent;return{offsetX:t.pageX-i,offsetY:t.pageY-n}}ontouched(t){if(!this.touchedNode)return;const e=this.getTouchOffset(t.changedTouches[0]);this.touchedNode.rect.x=e.offsetX-this.touchedNode.rect.width/2,this.touchedNode.rect.y=e.offsetY-this.touchedNode.rect.height/2,this.addNode(new ce(this.touchedNode)),this.touchedNode=void 0}addNode(t){return!!ee[t.name]&&(1!==this.scaleState&&t.scale(this.scaleState),this.activeLayer.setNodes([t]),this.activeLayer.render(),this.hoverLayer.canvas.focus(),this.nodes.push(t),this.offscreen.render(),this.cache(),this.options.on&&this.options.on("node",t),!0)}render(){this.activeLayer.nodes=[],this.activeLayer.lines=[],this.hoverLayer.node=null,this.hoverLayer.render(),this.activeLayer.render(),this.animateLayer.render(),this.offscreen.render()}open(t){this.animateLayer.nodes=[],this.animateLayer.lines=[],this.locked=0,t.lineName&&(this.lineName=t.lineName),this.scaleState=t.scaleState||1,it.set("scale",this.scaleState),this.options.on&&this.options.on("scale",this.scaleState),this.nodes.splice(0,this.nodes.length),this.lines.splice(0,this.lines.length);for(const e of t.nodes)this.nodes.push(new ce(e));for(const e of t.lines)this.lines.push(new ae(e));this.caches.list=[],this.cache(),this.overflow(),this.render()}overflow(){const t=this.getRect();(t.width>this.canvas.width||t.height>this.canvas.height)&&this.resize({width:t.ex+200,height:t.ey+200})}renderOffscreen(){this.canvas.height=this.canvas.height,this.canvas.getContext("2d").drawImage(this.offscreen.canvas,0,0)}setNodeText(){this.inputNode.text=this.input.value,this.input.style.zIndex="-1",this.input.style.left="-1000px",this.input.style.width="0",this.inputNode=null,this.cache(),this.offscreen.render()}clickText(t,e){const i=t.getTextRect();if(i.hitRotate(e,t.rotate,t.rect.center))return{node:t,textRect:i};if(!t.children)return null;for(const i of t.children){const t=this.clickText(i,e);if(t)return t}return null}getHoverNode(t){for(let e=this.activeLayer.nodes.length-1;e>-1;--e)if(this.activeLayer.nodes[e].hit(t,2))return this.moveIn.hoverNode=this.activeLayer.nodes[e],void(this.moveIn.type=ue.Nodes);for(let e=this.nodes.length-1;e>-1;--e)if(this.nodes[e].hit(t,2)){this.moveIn.hoverNode=this.nodes[e],this.moveIn.type=ue.Nodes;break}}getMoveIn(t){if(this.lastHoverNode=this.moveIn.hoverNode,this.moveIn.type=ue.None,this.moveIn.hoverNode=null,this.moveIn.lineControlPoint=null,this.moveIn.hoverLine=null,this.hoverLayer.hoverAnchorIndex=-1,1!==this.locked)for(const e of this.activeLayer.lines)if(this.isInLine(t,e))return;if(this.getHoverNode(t),this.moveIn.hoverNode?this.hoverLayer.canvas.style.cursor="move":this.hoverLayer.canvas.style.cursor="default",this.activeLayer.nodes.length)if(this.activeLayer.rotateCPs[0].hit(t,15))this.moveIn.type=ue.Rotate,this.hoverLayer.canvas.style.cursor=`url("${this.options.rotateCursor}"), auto`;else if(o(t,this.activeLayer.sizeCPs)&&(this.moveIn.type=ue.Nodes,this.hoverLayer.canvas.style.cursor="move"),!this.locked)for(let e=0;e0&&i>0?n=180-n:e<0&&i>0?n+=180:e<0&&i<0&&(n=360-n),1===this.activeLayer.nodes.length?n-this.activeLayer.nodes[0].rotate:n}showInput(t,e){this.locked||this.options.hideInput||(this.inputNode=t,this.input.value=t.text,this.input.style.left=e.x+"px",this.input.style.top=e.y+"px",this.input.style.width=e.width+"px",this.input.style.height=e.height+"px",this.input.style.zIndex="1000",this.input.focus())}getRect(){let t=99999,e=99999,i=-99999,n=-99999;const r=[];for(const t of this.nodes){const e=t.rect.toPoints();if(t.rotate)for(const i of e)i.rotate(t.rotate,t.rect.center);r.push.apply(r,e)}for(const t of this.lines)if(r.push(t.from),r.push(t.to),"curve"===t.name)for(let e=.01;e<1;e+=.02)r.push(ct(e,t.from,t.controlPoints[0],t.controlPoints[1],t.to));for(const h of r)t>h.x&&(t=h.x),e>h.y&&(e=h.y),it.x&&(e=t.x),i>t.y&&(i=t.y),nthis.caches.list.length-2)return;const t=this.caches.list[++this.caches.index];this.nodes.splice(0,this.nodes.length),this.lines.splice(0,this.lines.length),this.nodes.push.apply(this.nodes,t.nodes),this.lines.push.apply(this.lines,t.lines),this.render()}data(){return{nodes:this.nodes,lines:this.lines,lineName:this.lineName,fromArrowType:this.fromArrowType,toArrowType:this.toArrowType,scaleState:this.scaleState}}toImage(t,e,i){const n=this.getRect(),r=document.createElement("canvas");r.width=n.width+20,r.height=n.height+20;const h=r.getContext("2d");return t&&"image/png"!==t&&(h.fillStyle="white",h.fillRect(0,0,r.width,r.height)),h.drawImage(this.offscreen.canvas,n.x-10,n.y-10,n.width+20,n.height+20,0,0,n.width+20,n.height+20),i?(r.toBlob(i),""):r.toDataURL(t,e)}saveAsImage(t,e,i){const n=document.createElement("a");n.setAttribute("download",t||"le5le.topology.png"),n.setAttribute("href",this.toImage(e,i));const r=document.createEvent("MouseEvents");r.initEvent("click",!0,!0),n.dispatchEvent(r)}cut(){if(!this.locked){this.clipboard={nodes:[],lines:[]};for(const t of this.activeLayer.nodes){this.clipboard.nodes.push(new ce(t));const e=this.findNode(t);e>-1&&this.nodes.splice(e,1)}for(const t of this.activeLayer.lines){this.clipboard.lines.push(new ae(t));let e=0;for(const i of this.lines)t.id===i.id&&this.lines.splice(e,1),++e}this.cache(),this.activeLayer.nodes=[],this.activeLayer.lines=[],this.activeLayer.render(),this.animateLayer.render(),this.hoverLayer.node=null,this.hoverLayer.render(),this.offscreen.render(),this.moveIn.hoverLine=null,this.moveIn.hoverNode=null}}copy(){this.clipboard={nodes:[],lines:[]};for(const t of this.activeLayer.nodes)this.clipboard.nodes.push(new ce(t));for(const t of this.activeLayer.lines)this.clipboard.lines.push(new ae(t))}parse(){if(!this.clipboard||this.locked)return;this.hoverLayer.node=null,this.hoverLayer.line=null,this.hoverLayer.render(),this.activeLayer.nodes=[],this.activeLayer.lines=[];const t={};for(const e of this.clipboard.nodes){const i=e.id;e.id=r(),t[i]=e.id,e.rect.x+=20,e.rect.ex+=20,e.rect.y+=20,e.rect.ey+=20;const n=new ce(e);this.nodes.push(n),this.activeLayer.nodes.push(n)}for(const e of this.clipboard.lines){e.id=r(),e.from=new h(e.from.x+20,e.from.y+20,e.from.direction,e.from.anchorIndex,t[e.from.id]),e.to=new h(e.to.x+20,e.to.y+20,e.to.direction,e.to.anchorIndex,t[e.to.id]);const i=new ae(e);this.lines.push(i),this.activeLayer.lines.push(i),it.set("activeLine",i)}this.offscreen.render(),this.activeLayer.render(),this.animateLayer.render(),this.cache(),this.clipboard.nodes.length>1||this.clipboard.lines.length>1||this.clipboard.nodes.length&&this.clipboard.lines.length?this.options.on("multi",{nodes:this.clipboard.nodes,lines:this.clipboard.lines}):this.clipboard.nodes.length?this.options.on("node",this.activeLayer.nodes[0]):this.clipboard.lines.length&&this.options.on("line",this.activeLayer.lines[0])}animate(){this.offscreen.render(),this.animateLayer.render(!1)}updateProps(t,e,i){this.activeLayer.updateProps(t,e,i),this.activeLayer.saveNodeRects(),this.activeLayer.changeLineType(),this.activeLayer.render(),this.animateLayer.render(),this.hoverLayer.render(),this.offscreen.render(),this.cache()}lock(t){this.locked=t,it.set("locked",t)}top(t){const e=this.findNode(t);e>-1&&(this.nodes.push(this.nodes[e]),this.nodes.splice(e,1))}bottom(t){const e=this.findNode(t);e>-1&&(this.nodes.unshift(this.nodes[e]),this.nodes.splice(e+1,1))}combine(t){const e=this.getNodesRect(t);for(const e of t){const t=this.findNode(e);t>-1&&this.nodes.splice(t,1)}const i=new ce({name:"combine",rect:e,text:"",strokeStyle:"transparent"});i.children=[];for(const e of t)e.parentId=i.id,e.parentRect={offsetX:10,offsetY:10,x:(e.rect.x-i.rect.x-10)/(i.rect.width-10),y:(e.rect.y-i.rect.y-10)/(i.rect.height-10),width:e.rect.width/(i.rect.width-10),height:e.rect.height/(i.rect.height-10),marginX:0,marginY:0,rotate:e.rotate},i.children.push(e);this.nodes.push(i),this.cache()}uncombine(t){if("combine"!==t.name)return;const e=this.findNode(t);e>-1&&this.nodes.splice(e,1);for(const e of t.children)e.parentId=void 0,e.parentRect=void 0,this.nodes.push(e);this.cache()}findNode(t){for(let e=0;e