@nitrohe/webtopo-sdk 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitrohe/webtopo-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "topo",
5
5
  "keywords": [
6
6
  "konva",
@@ -14,7 +14,7 @@
14
14
  "main": "./webtopo.umd.js",
15
15
  "module": "./webtopo.es.js",
16
16
  "sideEffects": false,
17
- "author": "nitrohe",
17
+ "author": "nitrohe@163.com",
18
18
  "contributors": [],
19
19
  "scripts": {},
20
20
  "peerDependencies": {
package/webtopo.es.js CHANGED
@@ -16258,16 +16258,7 @@ const sdk = {
16258
16258
  Render
16259
16259
  };
16260
16260
  export {
16261
- AlignType,
16262
- AssetType,
16263
- BaseDraw,
16264
- GraphType,
16265
- ImageType,
16266
- LinkType,
16267
- MouseButton,
16268
- MoveKey,
16269
16261
  Render,
16270
- ShutcutKey,
16271
16262
  sdk as default
16272
16263
  };
16273
16264
  //# sourceMappingURL=webtopo.es.js.map
package/webtopo.iife.js CHANGED
@@ -20,5 +20,5 @@ var vl,xl=4294967295,wl=Array.prototype,bl=Object.prototype.hasOwnProperty,Sl=a?
20
20
  * Kerry Liu
21
21
  *
22
22
  * Copyright (c) 2014 Gliffy Inc.
23
- */wc=bc,function(){var t,e,n,r,i;function o(t,e){var n,r=Object.keys(e);for(n=0;n<r.length;n++)t=t.replace(new RegExp("\\{"+r[n]+"\\}","gi"),e[r[n]]);return t}function s(t){var e,n,r;if(!t)throw new Error("cannot create a random attribute name for an undefined object");e="ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",n="";do{for(n="",r=0;r<12;r++)n+=e[Math.floor(51*Math.random())]}while(t[n]);return n}function a(t){var e={alphabetic:"alphabetic",hanging:"hanging",top:"text-before-edge",bottom:"text-after-edge",middle:"central"};return e[t]||e.alphabetic}i=function(t,e){var n,r,i,o={};for(t=t.split(","),e=e||10,n=0;n<t.length;n+=2)r="&"+t[n+1]+";",i=parseInt(t[n],e),o[r]="&#"+i+";";return o["\\xa0"]="&#160;",o}("50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,t9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro",32),t={strokeStyle:{svgAttr:"stroke",canvas:"#000000",svg:"none",apply:"stroke"},fillStyle:{svgAttr:"fill",canvas:"#000000",svg:null,apply:"fill"},lineCap:{svgAttr:"stroke-linecap",canvas:"butt",svg:"butt",apply:"stroke"},lineJoin:{svgAttr:"stroke-linejoin",canvas:"miter",svg:"miter",apply:"stroke"},miterLimit:{svgAttr:"stroke-miterlimit",canvas:10,svg:4,apply:"stroke"},lineWidth:{svgAttr:"stroke-width",canvas:1,svg:1,apply:"stroke"},globalAlpha:{svgAttr:"opacity",canvas:1,svg:1,apply:"fill stroke"},font:{canvas:"10px sans-serif"},shadowColor:{canvas:"#000000"},shadowOffsetX:{canvas:0},shadowOffsetY:{canvas:0},shadowBlur:{canvas:0},textAlign:{canvas:"start"},textBaseline:{canvas:"alphabetic"}},(n=function(t,e){this.__root=t,this.__ctx=e}).prototype.addColorStop=function(t,e){var n,r=this.__ctx.__createElement("stop");r.setAttribute("offset",t),-1!==e.indexOf("rgba")?(n=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi.exec(e),r.setAttribute("stop-color",o("rgb({r},{g},{b})",{r:n[1],g:n[2],b:n[3]})),r.setAttribute("stop-opacity",n[4])):r.setAttribute("stop-color",e),this.__root.appendChild(r)},r=function(t,e){this.__root=t,this.__ctx=e},e=function(t){var n,r={width:500,height:500,enableMirroring:!1};if(arguments.length>1?((n=r).width=arguments[0],n.height=arguments[1]):n=t||r,!(this instanceof e))return new e(n);this.width=n.width||r.width,this.height=n.height||r.height,this.enableMirroring=void 0!==n.enableMirroring?n.enableMirroring:r.enableMirroring,this.canvas=this,this.__document=n.document||document,this.__canvas=this.__document.createElement("canvas"),this.__ctx=this.__canvas.getContext("2d"),this.__setDefaultStyles(),this.__stack=[this.__getStyleState()],this.__groupStack=[],this.__root=this.__document.createElementNS("http://www.w3.org/2000/svg","svg"),this.__root.setAttribute("version",1.1),this.__root.setAttribute("xmlns","http://www.w3.org/2000/svg"),this.__root.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink"),this.__root.setAttribute("width",this.width),this.__root.setAttribute("height",this.height),this.__ids={},this.__defs=this.__document.createElementNS("http://www.w3.org/2000/svg","defs"),this.__root.appendChild(this.__defs),this.__currentElement=this.__document.createElementNS("http://www.w3.org/2000/svg","g"),this.__root.appendChild(this.__currentElement)},e.prototype.__createElement=function(t,e,n){void 0===e&&(e={});var r,i,o=this.__document.createElementNS("http://www.w3.org/2000/svg",t),s=Object.keys(e);for(n&&(o.setAttribute("fill","none"),o.setAttribute("stroke","none")),r=0;r<s.length;r++)i=s[r],o.setAttribute(i,e[i]);return o},e.prototype.__setDefaultStyles=function(){var e,n,r=Object.keys(t);for(e=0;e<r.length;e++)this[n=r[e]]=t[n].canvas},e.prototype.__applyStyleState=function(t){var e,n,r=Object.keys(t);for(e=0;e<r.length;e++)this[n=r[e]]=t[n]},e.prototype.__getStyleState=function(){var e,n,r={},i=Object.keys(t);for(e=0;e<i.length;e++)r[n=i[e]]=this[n];return r},e.prototype.__applyStyleToCurrentElement=function(e){var i,s,a,h,d,u=Object.keys(t);for(i=0;i<u.length;i++)if(s=t[u[i]],a=this[u[i]],s.apply)if(-1!==s.apply.indexOf("fill")&&a instanceof r){if(a.__ctx)for(;a.__ctx.__defs.childNodes.length;)h=a.__ctx.__defs.childNodes[0].getAttribute("id"),this.__ids[h]=h,this.__defs.appendChild(a.__ctx.__defs.childNodes[0]);this.__currentElement.setAttribute("fill",o("url(#{id})",{id:a.__root.getAttribute("id")}))}else-1!==s.apply.indexOf("fill")&&a instanceof n?this.__currentElement.setAttribute("fill",o("url(#{id})",{id:a.__root.getAttribute("id")})):-1!==s.apply.indexOf(e)&&s.svg!==a&&("stroke"!==s.svgAttr&&"fill"!==s.svgAttr||-1===a.indexOf("rgba")?this.__currentElement.setAttribute(s.svgAttr,a):(d=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi.exec(a),this.__currentElement.setAttribute(s.svgAttr,o("rgb({r},{g},{b})",{r:d[1],g:d[2],b:d[3]})),this.__currentElement.setAttribute(s.svgAttr+"-opacity",d[4])))},e.prototype.__closestGroupOrSvg=function(t){return"g"===(t=t||this.__currentElement).nodeName||"svg"===t.nodeName?t:this.__closestGroupOrSvg(t.parentNode)},e.prototype.getSerializedSvg=function(t){var e,n,r,o,s,a=(new XMLSerializer).serializeToString(this.__root);if(/xmlns="http:\/\/www\.w3\.org\/2000\/svg".+xmlns="http:\/\/www\.w3\.org\/2000\/svg/gi.test(a)&&(a=a.replace('xmlns="http://www.w3.org/2000/svg','xmlns:xlink="http://www.w3.org/1999/xlink')),t)for(e=Object.keys(i),n=0;n<e.length;n++)r=e[n],o=i[r],(s=new RegExp(r,"gi")).test(a)&&(a=a.replace(s,o));return a},e.prototype.getSvg=function(){return this.__root},e.prototype.save=function(){var t=this.__createElement("g"),e=this.__closestGroupOrSvg();this.__groupStack.push(e),e.appendChild(t),this.__currentElement=t,this.__stack.push(this.__getStyleState())},e.prototype.restore=function(){this.__currentElement=this.__groupStack.pop();var t=this.__stack.pop();this.__applyStyleState(t)},e.prototype.__addTransform=function(t){var e=this.__closestGroupOrSvg();if(e.childNodes.length>0){var n=this.__createElement("g");e.appendChild(n),this.__currentElement=n}var r=this.__currentElement.getAttribute("transform");r?r+=" ":r="",r+=t,this.__currentElement.setAttribute("transform",r)},e.prototype.scale=function(t,e){void 0===e&&(e=t),this.__addTransform(o("scale({x},{y})",{x:t,y:e}))},e.prototype.rotate=function(t){var e=180*t/Math.PI;this.__addTransform(o("rotate({angle},{cx},{cy})",{angle:e,cx:0,cy:0}))},e.prototype.translate=function(t,e){this.__addTransform(o("translate({x},{y})",{x:t,y:e}))},e.prototype.transform=function(t,e,n,r,i,s){this.__addTransform(o("matrix({a},{b},{c},{d},{e},{f})",{a:t,b:e,c:n,d:r,e:i,f:s}))},e.prototype.beginPath=function(){var t;this.__currentDefaultPath="",this.__currentPosition={},t=this.__createElement("path",{},!0),this.__closestGroupOrSvg().appendChild(t),this.__currentElement=t},e.prototype.__applyCurrentDefaultPath=function(){if("path"!==this.__currentElement.nodeName)throw new Error("Attempted to apply path command to node "+this.__currentElement.nodeName);var t=this.__currentDefaultPath;this.__currentElement.setAttribute("d",t)},e.prototype.__addPathCommand=function(t){this.__currentDefaultPath+=" ",this.__currentDefaultPath+=t},e.prototype.moveTo=function(t,e){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.__currentPosition={x:t,y:e},this.__addPathCommand(o("M {x} {y}",{x:t,y:e}))},e.prototype.closePath=function(){this.__addPathCommand("Z")},e.prototype.lineTo=function(t,e){this.__currentPosition={x:t,y:e},this.__currentDefaultPath.indexOf("M")>-1?this.__addPathCommand(o("L {x} {y}",{x:t,y:e})):this.__addPathCommand(o("M {x} {y}",{x:t,y:e}))},e.prototype.bezierCurveTo=function(t,e,n,r,i,s){this.__currentPosition={x:i,y:s},this.__addPathCommand(o("C {cp1x} {cp1y} {cp2x} {cp2y} {x} {y}",{cp1x:t,cp1y:e,cp2x:n,cp2y:r,x:i,y:s}))},e.prototype.quadraticCurveTo=function(t,e,n,r){this.__currentPosition={x:n,y:r},this.__addPathCommand(o("Q {cpx} {cpy} {x} {y}",{cpx:t,cpy:e,x:n,y:r}))};var h=function(t){var e=Math.sqrt(t[0]*t[0]+t[1]*t[1]);return[t[0]/e,t[1]/e]};e.prototype.arcTo=function(t,e,n,r,i){var o=this.__currentPosition&&this.__currentPosition.x,s=this.__currentPosition&&this.__currentPosition.y;if(void 0!==o&&void 0!==s){if(i<0)throw new Error("IndexSizeError: The radius provided ("+i+") is negative.");if(o===t&&s===e||t===n&&e===r||0===i)this.lineTo(t,e);else{var a=h([o-t,s-e]),d=h([n-t,r-e]);if(a[0]*d[1]!==a[1]*d[0]){var u=a[0]*d[0]+a[1]*d[1],l=Math.acos(Math.abs(u)),c=h([a[0]+d[0],a[1]+d[1]]),f=i/Math.sin(l/2),g=t+f*c[0],p=e+f*c[1],y=[-a[1],a[0]],m=[d[1],-d[0]],v=function(t){var e=t[0];return t[1]>=0?Math.acos(e):-Math.acos(e)},x=v(y),w=v(m);this.lineTo(g+y[0]*i,p+y[1]*i),this.arc(g,p,i,x,w)}else this.lineTo(t,e)}}},e.prototype.stroke=function(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","fill stroke markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("stroke")},e.prototype.fill=function(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","stroke fill markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("fill")},e.prototype.rect=function(t,e,n,r){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.moveTo(t,e),this.lineTo(t+n,e),this.lineTo(t+n,e+r),this.lineTo(t,e+r),this.lineTo(t,e),this.closePath()},e.prototype.fillRect=function(t,e,n,r){var i;i=this.__createElement("rect",{x:t,y:e,width:n,height:r},!0),this.__closestGroupOrSvg().appendChild(i),this.__currentElement=i,this.__applyStyleToCurrentElement("fill")},e.prototype.strokeRect=function(t,e,n,r){var i;i=this.__createElement("rect",{x:t,y:e,width:n,height:r},!0),this.__closestGroupOrSvg().appendChild(i),this.__currentElement=i,this.__applyStyleToCurrentElement("stroke")},e.prototype.clearRect=function(t,e,n,r){var i,o=this.__closestGroupOrSvg();i=this.__createElement("rect",{x:t,y:e,width:n,height:r,fill:"#FFFFFF"},!0),o.appendChild(i)},e.prototype.createLinearGradient=function(t,e,r,i){var o=this.__createElement("linearGradient",{id:s(this.__ids),x1:t+"px",x2:r+"px",y1:e+"px",y2:i+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(o),new n(o,this)},e.prototype.createRadialGradient=function(t,e,r,i,o,a){var h=this.__createElement("radialGradient",{id:s(this.__ids),cx:i+"px",cy:o+"px",r:a+"px",fx:t+"px",fy:e+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(h),new n(h,this)},e.prototype.__parseFont=function(){var t=/^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-,\"\sa-z]+?)\s*$/i.exec(this.font),e={style:t[1]||"normal",size:t[4]||"10px",family:t[6]||"sans-serif",weight:t[3]||"normal",decoration:t[2]||"normal",href:null};return"underline"===this.__fontUnderline&&(e.decoration="underline"),this.__fontHref&&(e.href=this.__fontHref),e},e.prototype.__wrapTextLink=function(t,e){if(t.href){var n=this.__createElement("a");return n.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t.href),n.appendChild(e),n}return e},e.prototype.__applyText=function(t,e,n,r){var i,o,s=this.__parseFont(),h=this.__closestGroupOrSvg(),d=this.__createElement("text",{"font-family":s.family,"font-size":s.size,"font-style":s.style,"font-weight":s.weight,"text-decoration":s.decoration,x:e,y:n,"text-anchor":(i=this.textAlign,o={left:"start",right:"end",center:"middle",start:"start",end:"end"},o[i]||o.start),"dominant-baseline":a(this.textBaseline)},!0);d.appendChild(this.__document.createTextNode(t)),this.__currentElement=d,this.__applyStyleToCurrentElement(r),h.appendChild(this.__wrapTextLink(s,d))},e.prototype.fillText=function(t,e,n){this.__applyText(t,e,n,"fill")},e.prototype.strokeText=function(t,e,n){this.__applyText(t,e,n,"stroke")},e.prototype.measureText=function(t){return this.__ctx.font=this.font,this.__ctx.measureText(t)},e.prototype.arc=function(t,e,n,r,i,s){if(r!==i){(r%=2*Math.PI)==(i%=2*Math.PI)&&(i=(i+2*Math.PI-.001*(s?-1:1))%(2*Math.PI));var a=t+n*Math.cos(i),h=e+n*Math.sin(i),d=t+n*Math.cos(r),u=e+n*Math.sin(r),l=s?0:1,c=0,f=i-r;f<0&&(f+=2*Math.PI),c=s?f>Math.PI?0:1:f>Math.PI?1:0,this.lineTo(d,u),this.__addPathCommand(o("A {rx} {ry} {xAxisRotation} {largeArcFlag} {sweepFlag} {endX} {endY}",{rx:n,ry:n,xAxisRotation:0,largeArcFlag:c,sweepFlag:l,endX:a,endY:h})),this.__currentPosition={x:a,y:h}}},e.prototype.clip=function(){var t=this.__closestGroupOrSvg(),e=this.__createElement("clipPath"),n=s(this.__ids),r=this.__createElement("g");t.removeChild(this.__currentElement),e.setAttribute("id",n),e.appendChild(this.__currentElement),this.__defs.appendChild(e),t.setAttribute("clip-path",o("url(#{id})",{id:n})),t.appendChild(r),this.__currentElement=r},e.prototype.drawImage=function(){var t,n,r,i,o,s,a,h,d,u,l,c,f,g,p=Array.prototype.slice.call(arguments),y=p[0],m=0,v=0;if(3===p.length)t=p[1],n=p[2],r=o=y.width,i=s=y.height;else if(5===p.length)t=p[1],n=p[2],r=p[3],i=p[4],o=y.width,s=y.height;else{if(9!==p.length)throw new Error("Inavlid number of arguments passed to drawImage: "+arguments.length);m=p[1],v=p[2],o=p[3],s=p[4],t=p[5],n=p[6],r=p[7],i=p[8]}if(a=this.__closestGroupOrSvg(),l=this.__currentElement,y instanceof e){for(d=(h=y.getSvg()).childNodes[0];d.childNodes.length;)g=d.childNodes[0].getAttribute("id"),this.__ids[g]=g,this.__defs.appendChild(d.childNodes[0]);u=h.childNodes[1],a.appendChild(u),this.__currentElement=u,this.translate(t,n),this.__currentElement=l}else"CANVAS"!==y.nodeName&&"IMG"!==y.nodeName||((c=this.__createElement("image")).setAttribute("width",r),c.setAttribute("height",i),c.setAttribute("preserveAspectRatio","none"),(m||v||o!==y.width||s!==y.height)&&((f=this.__document.createElement("canvas")).width=r,f.height=i,f.getContext("2d").drawImage(y,m,v,o,s,0,0,r,i),y=f),c.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===y.nodeName?y.toDataURL():y.getAttribute("src")),a.appendChild(c),this.__currentElement=c,this.translate(t,n),this.__currentElement=l)},e.prototype.createPattern=function(t,n){var i,o=this.__document.createElementNS("http://www.w3.org/2000/svg","pattern"),a=s(this.__ids);return o.setAttribute("id",a),o.setAttribute("width",t.width),o.setAttribute("height",t.height),"CANVAS"===t.nodeName||"IMG"===t.nodeName?((i=this.__document.createElementNS("http://www.w3.org/2000/svg","image")).setAttribute("width",t.width),i.setAttribute("height",t.height),i.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===t.nodeName?t.toDataURL():t.getAttribute("src")),o.appendChild(i),this.__defs.appendChild(o)):t instanceof e&&(o.appendChild(t.__root.childNodes[1]),this.__defs.appendChild(o)),new r(o,this)},e.prototype.drawFocusRing=function(){},e.prototype.createImageData=function(){},e.prototype.getImageData=function(){},e.prototype.putImageData=function(){},e.prototype.globalCompositeOperation=function(){},e.prototype.setTransform=function(){},"object"==typeof window&&(window.C2S=e),wc.exports=e}();const Sc=xc(bc.exports);Sc.prototype.__applyCurrentDefaultPath=function(){if("g"===this.__currentElement.nodeName){const t=this.__currentElement.querySelector("g");if(t){const e=t.getAttribute("transform");if(e){const t=e.match(/scale\(([^),]+),([^)]+)\)/);if(t){const[e,n]=[parseFloat(t[1]),parseFloat(t[2])];let r=this.__currentDefaultPath;const i=/A ([^ ]+) ([^ ]+) /,o=r.match(i);if(o){const[t,s]=[parseFloat(o[1]),parseFloat(o[2])];r=r.replace(i,`A ${t*e} ${s*n} `);const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("d",r),a.setAttribute("fill","none"),this.__currentElement.append(a)}}}else{const t=this.__currentDefaultPath,e=document.createElementNS("http://www.w3.org/2000/svg","path");e.setAttribute("d",t),e.setAttribute("fill","none"),this.__currentElement.append(e)}}return}if("path"!==this.__currentElement.nodeName)throw new Error("Attempted to apply path command to node "+this.__currentElement.nodeName);{const t=this.__currentDefaultPath;this.__currentElement.setAttribute("d",t)}};class _c{constructor(t){r(this,"render"),this.render=t}getView(t=!1){const n=this.render.stage.clone(),r=n.find("#main")[0],i=n.find("#cover")[0],o=n.getChildren();if(n.removeChildren(),r&&i){let o=r.getChildren(t=>!this.render.ignore(t));for(const t of o){t.listening(!0),t.draggable(!this.render.config.readonly);for(const e of t.children)this.render.ignoreSelect(e)&&e.remove()}if(t){const t=i.children.find(t=>t.attrs.name===Fl.name);t&&(o=o.concat(t.children.filter(t=>"link-line"===t.attrs.name)))}const s=new e.Layer;s.add(...o),o=s.getChildren();for(const t of o)t.attrs.nodeMousedownPos&&t.setAttrs({opacity:n.attrs.lastOpacity??1});n.add(s),r.removeChildren(),i.removeChildren()}return o.forEach(t=>t.destroy()),n}save(){const t=this.getView(),e=t.toJSON();return t.destroy(),e}loadImage(t){return new Promise(e=>{const n=new Image;n.onload=()=>{e(n)},n.onerror=()=>{e(null)},n.src=t})}async restoreImage(t=[]){for(const n of t)if(n instanceof e.Group)await this.restoreImage(n.getChildren());else if(n instanceof e.Image)if(n.attrs.svgXML){const t=new Blob([n.attrs.svgXML],{type:"image/svg+xml"}),e=URL.createObjectURL(t),r=await this.loadImage(e);r&&n.image(r)}else if(n.attrs.gif){const t=await this.render.assetTool.loadGif(n.attrs.gif);t&&n.image(t.image())}else if(n.attrs.src){const t=await this.loadImage(n.attrs.src);t&&n.image(t)}}async restore(t,n=!1){try{this.render.emit("loading",!0),this.render.selectionTool.selectingClear(),this.render.linkTool.selectingClear(),this.render.layer.getChildren().forEach(t=>{t.destroy()}),this.render.layer.removeChildren();const r=document.createElement("div"),i=e.Node.create(t,r),o=i.getChildren()[0].getChildren();await this.restoreImage(o);for(const t of o)t.draggable(!this.render.config.readonly),t.off("mouseenter"),t.on("mouseenter",()=>{this.render.linkTool.pointsVisible(!0,t)}),t.add(new e.Rect({id:"hoverRect",width:t.width(),height:t.height(),fill:"rgba(0,255,0,0.3)",visible:!1})),t.off("mouseleave"),t.on("mouseleave",()=>{var e;this.render.linkTool.pointsVisible(!1,t),null==(e=t.findOne("#hoverRect"))||e.visible(!1)});this.render.layer.add(...o),this.render.stage.setAttr("pageSettings",i.attrs.pageSettings),this.render.emit("page-settings-change",this.render.getPageSettings()),this.render.updateBackground(),n||this.render.updateHistory(),this.render.linkTool.pointsVisible(!1),this.render.redraw([rc.name,Fl.name,Rl.name,Bl.name]),i.destroy()}catch(r){}finally{this.render.emit("loading",!1)}}getImage(t=1,n){const r=this.getAssetView(),i=new e.Layer,o=new e.Rect({listening:!1});o.setAttrs({x:0,y:0,width:r.width(),height:r.height(),fill:n??this.render.getPageSettings().background}),i.add(o);const s=r.getChildren();r.removeChildren(),r.add(i),r.add(s[0],...s.slice(1));const a=r.toDataURL({pixelRatio:t});return r.destroy(),a}getAssetImage(t=1,n){const r=this.getAssetView(),i=new e.Layer,o=new e.Rect({listening:!1});o.setAttrs({x:-r.x(),y:-r.y(),width:r.width(),height:r.height(),fill:n??this.render.getPageSettings().background}),i.add(o);const s=r.getChildren();r.removeChildren(),r.add(i),r.add(s[0],...s.slice(1));const a=r.toDataURL({pixelRatio:t});return r.destroy(),a}blobToBase64(t,e){return new Promise(n=>{const r=new File([t],"image",{type:e}),i=new FileReader;i.readAsDataURL(r),i.onload=function(){n(this.result??"")}})}parseSvgImage(t){return new Promise(e=>{t.length>0?Promise.all(t.map(t=>fetch(t))).then(t=>{Promise.all(t.map(t=>t.text())).then(t=>{e(t)})}):e([])})}parseOtherImage(t){return new Promise(e=>{t.length>0?Promise.all(t.map(t=>fetch(t))).then(t=>{Promise.all(t.map(t=>t.blob())).then(t=>{Promise.all(t.map(t=>this.blobToBase64(t,"image/*"))).then(t=>{e(t)})})}):e([])})}parseImage(t){return new Promise(e=>{const n=t.match(new RegExp('(?<=xlink:href=")blob:https?:\\/\\/[^"]+(?=")',"g"))??[],r=t.match(new RegExp('(?<=xlink:href=")(?<!blob:)[^"]+(?=")',"g"))??[];Promise.all([this.parseSvgImage(n),this.parseOtherImage(r)]).then(([i,o])=>{n.forEach((e,n)=>{var r;t=t.replace(new RegExp(`<image[^><]* xlink:href="${e}"[^><]*/>`),(null==(r=i[n].match(/<svg[^><]*>.*<\/svg>/))?void 0:r[0])??"")}),r.forEach((e,n)=>{t=t.replace(`"${e}"`,`"${o[n]}"`)}),e(t)})})}async getSvg(){const t=this.getAssetView(),e=t.children[0],n=e.canvas.context._context;if(n){const r=new Sc({ctx:n,...e.size()});e.canvas.context._context=r,e.draw();let i=r.getSerializedSvg();i=i.replace(/(<defs\/><g><rect fill=")([^"]+)(")/,`$1${this.render.getPageSettings().background}$3`);const o=await this.parseImage(i);return t.destroy(),o}return Promise.resolve('<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0"></svg>')}getAssetView(){const t=this.getView(!0),n=[...t.getChildren()[0].getChildren()];let r=1/0,i=-1/0,o=1/0,s=-1/0,a=1/0,h=1/0;const d=this.render.getStageState();for(const u of n)if(u instanceof e.Group){const{x:t,y:n,width:l,height:c}=(t=>({x:this.render.toStageValue(t.x-d.x),y:this.render.toStageValue(t.y-d.y),width:this.render.toStageValue(t.width),height:this.render.toStageValue(t.height)}))(u.getClientRect());if(t<r&&(r=t),t+l>i&&(i=t+l),n<o&&(o=n),n+c>s&&(s=n+c),t<a&&(a=t),n<h&&(h=n),u instanceof e.Group){const t=u.findOne("#click-mask");t&&t.destroy()}}else if(u instanceof e.Line&&"link-line"===u.name()){const t=u.points();for(let e=0;e<t.length;e+=2){const[n,d]=[t[e],t[e+1]];n<r&&(r=n-1),n>i&&(i=n+1),d<o&&(o=d-1),d>s&&(s=d+1),n<a&&(a=n-1),d<h&&(h=d-1)}}for(const u of n)if(u instanceof e.Group)u.x(u.x()-a),u.y(u.y()-h);else if(u instanceof e.Line&&"link-line"===u.name()){const t=u.points();for(let e=0;e<t.length;e+=2)t[e]=t[e]-a,t[e+1]=t[e+1]-h;u.points(t)}return t.x(0),t.y(0),t.width(i-r),t.height(s-o),t.scale({x:1,y:1}),t}getAsset(){const t=this.getAssetView(),e=this.render.getBackground();e.width(t.width()),e.height(t.height()),t.children[0].add(e),e.moveToBottom();const n=t.toJSON(),r=JSON.parse(n),i=r.children[0].children;for(const s of i)"asset"===s.attrs.name&&(s.attrs.name="sub-asset"),s.attrs.selected&&(s.attrs.selected=!1);this.render.linkTool.jsonIdCover(i);const o=JSON.stringify({...r.children[0],className:"Group",attrs:{width:t.width(),height:t.height(),x:0,y:0}});return t.destroy(),o}}r(_c,"name","ImportExportTool");class Ac{constructor(t){r(this,"render"),this.render=t}getAlignRect(t){const e=this.render.getStageState();let n=0,r=0,i=0,o=0;const s=t.getClientRect();return[n,r,i,o]=[this.render.toStageValue(s.width),this.render.toStageValue(s.height),this.render.toStageValue(s.x-e.x),this.render.toStageValue(s.y-e.y)],{width:n,height:r,x:i,y:o}}getAlignPoints(t){let e=0,n=0,r=0,i=0;if(void 0===t)return this.getAlignPoints(this.render.transformer);{const o=this.getAlignRect(t);[e,n,r,i]=[o.width,o.height,o.x,o.y]}return{[Ml.垂直居中]:r+e/2,[Ml.左对齐]:r,[Ml.右对齐]:r+e,[Ml.水平居中]:i+n/2,[Ml.上对齐]:i,[Ml.下对齐]:i+n}}align(t,e){const n=this.getAlignPoints(e)[t],r=this.render.transformer.nodes().filter(t=>t!==e);for(const i of r){const e=this.getAlignRect(i),[r,o,s,a]=[e.width,e.height,e.x,e.y];switch(t){case Ml.垂直居中:{const t=s+r/2;i.x(i.x()+(n-t))}break;case Ml.水平居中:{const t=a+o/2;i.y(i.y()+(n-t))}break;case Ml.左对齐:{const t=s;i.x(i.x()+(n-t))}break;case Ml.右对齐:{const t=s+r;i.x(i.x()+(n-t))}break;case Ml.上对齐:{const t=a;i.y(i.y()+(n-t))}break;case Ml.下对齐:{const t=a+o;i.y(i.y()+(n-t))}}}this.render.updateHistory(),this.render.redraw([rc.name,Fl.name,Rl.name,Bl.name])}}r(Ac,"name","AlignTool");class kc{constructor(t){r(this,"render"),r(this,"linkCurrent"),this.render=t}pointsVisible(t,e){var n;if(!this.render.config.readonly){const r=e??this.render.layer;for(const e of[...["asset","sub-asset"].includes(r.name())?[r]:[],...r.find(".asset"),...r.find(".sub-asset")]){const n=e.getAttr("points")??[];e.setAttrs({points:n.map(e=>({...e,visible:t}))})}(null==(n=this.render.draws[Fl.name])?void 0:n.state.linkManualing)||this.render.redraw([Fl.name,Rl.name,Bl.name])}}remove(t){const e=t??this.linkCurrent;if(e){const{groupId:t,pointId:n,pairId:r}=e.getAttrs();if(t&&n&&r){const e=this.render.layer.findOne(`#${t}`);if(e){const t=(e.getAttr("points")??[]).find(t=>t.id===n);if(t){const n=(t.pairs??[]).findIndex(t=>t.id===r);if(n>-1){const r=t.pairs.splice(n,1)[0];e.attrs.manualPointsMap&&e.attrs.manualPointsMap[r.id]&&e.setAttr("manualPointsMap",{...e.attrs.manualPointsMap,[r.id]:void 0}),this.render.redraw([Fl.name,Rl.name,Bl.name])}}}}}}jsonIdCover(t){let e=[...t];const n=new Map;for(;e.length>0;){const t=e.shift();if(t){if(Array.isArray(t.attrs.points))for(const e of t.attrs.points){if(Array.isArray(e.pairs))for(const t of e.pairs)t.from.groupId&&!n.has(t.from.groupId)&&n.set(t.from.groupId,"g:"+Nl()),t.to.groupId&&!n.has(t.to.groupId)&&n.set(t.to.groupId,"g:"+Nl()),t.from.pointId&&!n.has(t.from.pointId)&&n.set(t.from.pointId,"p:"+Nl()),t.to.pointId&&!n.has(t.to.pointId)&&n.set(t.to.pointId,"p:"+Nl());e.id&&(n.has(e.id)||n.set(e.id,"p:"+Nl())),e.groupId&&(n.has(e.groupId)||n.set(e.groupId,"g:"+Nl()))}t.attrs.id&&(n.has(t.attrs.id)||n.set(t.attrs.id,"n:"+Nl())),Array.isArray(t.children)&&e.push(...t.children)}}for(e=[...t];e.length>0;){const t=e.shift();if(t){if(n.has(t.attrs.id)&&(t.attrs.id=n.get(t.attrs.id)),Array.isArray(t.attrs.points))for(const e of t.attrs.points){if(Array.isArray(e.pairs))for(const t of e.pairs)t.disabled=!0,t.id&&(t.id="pr:"+Nl()),n.has(t.from.groupId)&&(t.from.groupId=n.get(t.from.groupId)),n.has(t.to.groupId)&&(t.to.groupId=n.get(t.to.groupId)),n.has(t.from.pointId)&&(t.from.pointId=n.get(t.from.pointId)),n.has(t.to.pointId)&&(t.to.pointId=n.get(t.to.pointId));if(n.has(e.id)){const r=t.children.find(t=>t.attrs.id===e.id);e.id=n.get(e.id),r&&(r.attrs.id=e.id)}n.has(e.groupId)&&(e.groupId=n.get(e.groupId))}Array.isArray(t.children)&&e.push(...t.children)}}}groupIdCover(t){const e=t.id(),n=t.find(".sub-asset");for(;n.length>0;){const t=n.shift();if(t){const r=t.attrs.points;if(Array.isArray(r))for(const t of r){t.rawGroupId=t.groupId,t.groupId=e;for(const n of t.pairs)n.from.rawGroupId=n.from.groupId,n.from.groupId=e,n.to.rawGroupId=n.to.groupId,n.to.groupId=e}n.push(...t.find(".sub-asset"))}}}select(t){this.render.selectionTool.selectingClear(),this.linkCurrent=t,this.render.emit("link-selection-change",this.linkCurrent),this.render.redraw([Fl.name,Rl.name])}selectingClear(){this.linkCurrent=void 0,this.render.emit("link-selection-change",void 0),this.render.redraw([Fl.name,Rl.name])}}r(kc,"name","LinkTool");class jc{constructor(t){r(this,"render"),r(this,"alignLines",[]),r(this,"attractPoint",t=>{this.alignLinesClear();const n=this.render.getStageState();let r=t.x,i=t.y,o=!1,s=null,a=null;if(!this.render.config.readonly&&this.render.config.attractNode){const t=[{value:this.render.toStageValue(r-n.x)}],h=[{value:this.render.toStageValue(i-n.y)}];let d=1/0,u=[],l=1/0,c=[];for(let e=0;e<t.length-1;e++)if(void 0===t[e].id&&void 0!==t[e+1].id||void 0!==t[e].id&&void 0===t[e+1].id){const n=Math.abs(t[e].value-t[e+1].value);n<d?(d=n,u=[[t[e],t[e+1]]]):n===d&&u.push([t[e],t[e+1]])}for(let e=0;e<h.length-1;e++)if(void 0===h[e].id&&void 0!==h[e+1].id||void 0!==h[e].id&&void 0===h[e+1].id){const t=Math.abs(h[e].value-h[e+1].value);t<l?(l=t,c=[[h[e],h[e+1]]]):t===l&&c.push([h[e],h[e+1]])}if(u[0]&&Math.abs(u[0][0].value-u[0][1].value)<this.render.bgSize/2&&(s=u[0]),c[0]&&Math.abs(c[0][0].value-c[0][1].value)<this.render.bgSize/2&&(a=c[0]),2===(null==s?void 0:s.length)){for(const r of u){const t=r.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[t.value,this.render.toStageValue(-n.y)],[t.value,this.render.toStageValue(this.render.stage.height()-n.y)]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=s.find(t=>void 0===t.id),i=s.find(t=>void 0!==t.id);t&&i&&(r-=this.render.toBoardValue(t.value-i.value),o=!0)}if(2===(null==a?void 0:a.length)){for(const i of c){const t=i.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[this.render.toStageValue(-n.x),t.value],[this.render.toStageValue(this.render.stage.width()-n.x),t.value]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=a.find(t=>void 0===t.id),r=a.find(t=>void 0!==t.id);t&&r&&(i-=this.render.toBoardValue(t.value-r.value),o=!0)}}if(!this.render.config.readonly&&this.render.config.attractBg){if(null===s){const t=this.render.toStageValue(r-n.x),e=Math.round(t/this.render.bgSize)*this.render.bgSize,i=Math.abs(t-e),s=this.render.toStageValue(r-n.x),a=Math.round(s/this.render.bgSize)*this.render.bgSize,h=Math.abs(s-a),d=n.width,u=Math.abs(s-d);for(const l of[{type:"leftX",value:i},{type:"rightX",value:h},{type:"stageRightX",value:u}].sort((t,e)=>t.value-e.value))if(l.value<5){"stageRightX"===l.type?r=this.render.toBoardValue(d)+n.x:"leftX"===l.type?r=this.render.toBoardValue(e)+n.x:"rightX"===l.type&&(r=this.render.toBoardValue(a)+n.x),o=!0;break}}if(null===a){const t=this.render.toStageValue(i-n.y),e=Math.round(t/this.render.bgSize)*this.render.bgSize,r=Math.abs(t-e),s=this.render.toStageValue(i-n.y),a=Math.round(s/this.render.bgSize)*this.render.bgSize,h=Math.abs(s-a),d=n.height,u=Math.abs(s-d);for(const l of[{type:"topY",value:r},{type:"bottomY",value:h},{type:"stageBottomY",value:u}].sort((t,e)=>t.value-e.value))if(l.value<5){"stageBottomY"===l.type?i=this.render.toBoardValue(d)+n.y:"topY"===l.type?i=this.render.toBoardValue(e)+n.y:"bottomY"===l.type&&(i=this.render.toBoardValue(a)+n.y),o=!0;break}}}return{pos:{x:r,y:i},isAttract:o}}),r(this,"attractTransformer",t=>{this.alignLinesClear();const n=this.render.getStageState(),r=this.render.transformer.width(),i=this.render.transformer.height();let o=t.x,s=t.y,a=!1,h=null,d=null;if(!this.render.config.readonly&&this.render.config.attractNode){const{sortX:r,sortY:i}=this.getSortItems(t);let u=1/0,l=[],c=1/0,f=[];for(let t=0;t<r.length-1;t++)if(void 0===r[t].id&&void 0!==r[t+1].id||void 0!==r[t].id&&void 0===r[t+1].id){const e=Math.abs(r[t].value-r[t+1].value);e<u?(u=e,l=[[r[t],r[t+1]]]):e===u&&l.push([r[t],r[t+1]])}for(let t=0;t<i.length-1;t++)if(void 0===i[t].id&&void 0!==i[t+1].id||void 0!==i[t].id&&void 0===i[t+1].id){const e=Math.abs(i[t].value-i[t+1].value);e<c?(c=e,f=[[i[t],i[t+1]]]):e===c&&f.push([i[t],i[t+1]])}if(l[0]&&Math.abs(l[0][0].value-l[0][1].value)<this.render.bgSize/2&&(h=l[0]),f[0]&&Math.abs(f[0][0].value-f[0][1].value)<this.render.bgSize/2&&(d=f[0]),2===(null==h?void 0:h.length)){for(const i of l){const t=i.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[t.value,this.render.toStageValue(-n.y)],[t.value,this.render.toStageValue(this.render.stage.height()-n.y)]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=h.find(t=>void 0===t.id),r=h.find(t=>void 0!==t.id);t&&r&&(o-=this.render.toBoardValue(t.value-r.value),a=!0)}if(2===(null==d?void 0:d.length)){for(const i of f){const t=i.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[this.render.toStageValue(-n.x),t.value],[this.render.toStageValue(this.render.stage.width()-n.x),t.value]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=d.find(t=>void 0===t.id),r=d.find(t=>void 0!==t.id);t&&r&&(s-=this.render.toBoardValue(t.value-r.value),a=!0)}}if(!this.render.config.readonly&&this.render.config.attractBg){if(null===h){const t=this.render.toStageValue(o-n.x),e=Math.round(t/this.render.bgSize)*this.render.bgSize,i=Math.abs(t-e),s=this.render.toStageValue(o+r-n.x),h=Math.round(s/this.render.bgSize)*this.render.bgSize,d=Math.abs(s-h),u=n.width,l=Math.abs(s-u);for(const c of[{type:"leftX",value:i},{type:"rightX",value:d},{type:"stageRightX",value:l}].sort((t,e)=>t.value-e.value))if(c.value<5){"stageRightX"===c.type?o=this.render.toBoardValue(u)+n.x-r:"leftX"===c.type?o=this.render.toBoardValue(e)+n.x:"rightX"===c.type&&(o=this.render.toBoardValue(h)+n.x-r),a=!0;break}}if(null===d){const t=this.render.toStageValue(s-n.y),e=Math.round(t/this.render.bgSize)*this.render.bgSize,r=Math.abs(t-e),o=this.render.toStageValue(s+i-n.y),h=Math.round(o/this.render.bgSize)*this.render.bgSize,d=Math.abs(o-h),u=n.height,l=Math.abs(o-u);for(const c of[{type:"topY",value:r},{type:"bottomY",value:d},{type:"stageBottomY",value:l}].sort((t,e)=>t.value-e.value))if(c.value<5){"stageBottomY"===c.type?s=this.render.toBoardValue(u)+n.y-i:"topY"===c.type?s=this.render.toBoardValue(e)+n.y:"bottomY"===c.type&&(s=this.render.toBoardValue(h)+n.y-i),a=!0;break}}}return{pos:{x:o,y:s},isAttract:a}}),this.render=t}alignLinesClear(){for(const t of this.alignLines)t.destroy();this.alignLines=[]}getSortItems(t){const e=this.render.getStageState(),n=[],r=[];n.push({value:this.render.toStageValue(t.x-e.x)},{value:this.render.toStageValue(t.x-e.x+t.width/2)},{value:this.render.toStageValue(t.x-e.x+t.width)}),r.push({value:this.render.toStageValue(t.y-e.y)},{value:this.render.toStageValue(t.y-e.y+t.height/2)},{value:this.render.toStageValue(t.y-e.y+t.height)});const i=this.render.selectionTool.selectingNodes.map(t=>t._id),o=this.render.layer.find(".asset").filter(t=>!i.includes(t._id));for(const s of o){const t=s.getClientRect();n.push({id:s._id,value:this.render.toStageValue(t.x-e.x)},{id:s._id,value:this.render.toStageValue(t.x-e.x+t.width/2)},{id:s._id,value:this.render.toStageValue(t.x-e.x+t.width)}),r.push({id:s._id,value:this.render.toStageValue(t.y-e.y)},{id:s._id,value:this.render.toStageValue(t.y-e.y+t.height/2)},{id:s._id,value:this.render.toStageValue(t.y-e.y+t.height)})}return n.sort((t,e)=>t.value-e.value),r.sort((t,e)=>t.value-e.value),{sortX:n,sortY:r}}}r(jc,"name","AttractTool");const Ic=class t{constructor(t,n){var i;r(this,"stage"),r(this,"layer",new e.Layer({id:"main"})),r(this,"layerFloor",new e.Layer),r(this,"layerCover",new e.Layer({id:"cover"})),r(this,"config"),r(this,"draws",{}),r(this,"assetTool"),r(this,"selectionTool"),r(this,"copyTool"),r(this,"positionTool"),r(this,"zIndexTool"),r(this,"importExportTool"),r(this,"alignTool"),r(this,"linkTool"),r(this,"attractTool"),r(this,"groupTransformer",new e.Group),r(this,"transformer",new e.Transformer({shouldOverdrawWholeArea:!0,borderDash:[4,4],padding:1,rotationSnaps:[0,45,90,135,180,225,270,315,360],flipEnabled:!1})),r(this,"selectRect",new e.Rect({id:"selectRect",fill:"rgba(0,0,255,0.1)",visible:!1})),r(this,"handlers",{}),r(this,"bgSize",20),r(this,"rulerSize",0),r(this,"previewSize",.2),r(this,"pointSize",6),r(this,"history",[]),r(this,"historyIndex",-1),r(this,"debug",!1),r(this,"graphType"),r(this,"texting",!1),r(this,"emitter",{all:i=i||new Map,on:function(t,e){var n=i.get(t);n?n.push(e):i.set(t,[e])},off:function(t,e){var n=i.get(t);n&&(e?n.splice(n.indexOf(e)>>>0,1):i.set(t,[]))},emit:function(t,e){var n=i.get(t);n&&n.slice().map(function(t){t(e)}),(n=i.get("*"))&&n.slice().map(function(n){n(t,e)})}}),r(this,"on"),r(this,"off"),r(this,"emit"),this.config=n,this.on=this.emitter.on.bind(this.emitter),this.off=this.emitter.off.bind(this.emitter),this.emit=this.emitter.emit.bind(this.emitter),this.config.showRuler&&(this.rulerSize=40),this.stage=new e.Stage({container:t,x:this.rulerSize,y:this.rulerSize,width:n.width,height:n.height}),this.groupTransformer.add(this.transformer),this.groupTransformer.add(this.selectRect),this.layerCover.add(this.groupTransformer),this.config.showBg&&(this.draws[El.name]=new El(this,this.layerFloor,{size:this.bgSize,readonly:this.config.readonly??!1})),this.draws[Fl.name]=new Fl(this,this.layerCover,{size:this.pointSize}),this.draws[Xl.name]=new Xl(this,this.layerCover,{size:this.pointSize}),!this.config.readonly&&this.config.showRuler&&(this.draws[Rl.name]=new Rl(this,this.layerCover,{size:this.rulerSize})),!this.config.readonly&&this.config.showRefLine&&(this.draws[Ll.name]=new Ll(this,this.layerCover,{padding:this.rulerSize})),this.config.showContextmenu&&(this.draws[Wl.name]=new Wl(this,this.layerCover,{})),!this.config.readonly&&this.config.showPreview&&(this.draws[Bl.name]=new Bl(this,this.layerCover,{size:this.previewSize})),this.draws[rc.name]=new rc(this,this.layerCover,{}),this.assetTool=new gc(this),this.selectionTool=new pc(this),this.copyTool=new yc(this),this.positionTool=new mc(this),this.zIndexTool=new vc(this),this.importExportTool=new _c(this),this.alignTool=new Ac(this),this.linkTool=new kc(this),this.attractTool=new jc(this),this.handlers[ic.name]=new ic(this),this.handlers[oc.name]=new oc(this),this.config.readonly||(this.handlers[sc.name]=new sc(this),this.handlers[ac.name]=new ac(this),this.handlers[hc.name]=new hc(this),this.handlers[uc.name]=new uc(this),this.handlers[lc.name]=new lc(this),this.handlers[cc.name]=new cc(this)),!this.config.readonly&&this.config.showRefLine&&void 0!==this.draws[Ll.name]&&(this.handlers[Ll.name]=this.draws[Ll.name]),this.handlers[dc.name]=new dc(this),this.init(),this.config.configJson&&this.importExportTool.restore(this.config.configJson)}changeDebug(t){var e,n,r,i,o,s;return this.debug=t,this.emit("debug-change",this.debug),null==(e=this.draws[Fl.name])||e.init(),null==(n=this.draws[Xl.name])||n.init(),null==(r=this.draws[Rl.name])||r.init(),null==(i=this.draws[Ll.name])||i.init(),null==(o=this.draws[Wl.name])||o.init(),null==(s=this.draws[Bl.name])||s.init(),this.debug}init(){var t,e,n,r,i,o,s;this.stage.add(this.layerFloor),null==(t=this.draws[El.name])||t.init(),this.stage.add(this.layer),this.stage.add(this.layerCover),null==(e=this.draws[Fl.name])||e.init(),null==(n=this.draws[Xl.name])||n.init(),null==(r=this.draws[Rl.name])||r.init(),null==(i=this.draws[Ll.name])||i.init(),null==(o=this.draws[Wl.name])||o.init(),null==(s=this.draws[Bl.name])||s.init(),this.eventBind(),this.updateHistory()}resize(t,e){this.stage.setAttrs({width:t,height:e}),this.redraw()}remove(t){for(const n of t)if(n instanceof e.Transformer)this.remove(this.selectionTool.selectingNodes);else{const t=n.id();for(const e of this.layer.getChildren())if(e.id()!==t&&Array.isArray(e.attrs.points)){for(const n of e.attrs.points)Array.isArray(n.pairs)&&(e.attrs.manualPointsMap&&n.pairs.filter(e=>e.from.groupId===t||e.to.groupId===t).forEach(t=>{e.attrs.manualPointsMap[t.id]=void 0}),n.pairs=n.pairs.filter(e=>e.from.groupId!==t&&e.to.groupId!==t));e.setAttr("points",e.attrs.points)}n.destroy()}t.length>0&&(this.selectionTool.selectingClear(),this.linkTool.selectingClear(),this.updateHistory(),this.redraw())}prevHistory(){const t=this.history[this.historyIndex-1];t&&(this.importExportTool.restore(t,!0),this.historyIndex--,this.emit("history-change",{records:bt.clone(this.history),index:this.historyIndex}))}nextHistory(){const t=this.history[this.historyIndex+1];t&&(this.importExportTool.restore(t,!0),this.historyIndex++,this.emit("history-change",{records:bt.clone(this.history),index:this.historyIndex}))}updateHistory(){this.history.splice(this.historyIndex+1),this.history.push(this.importExportTool.save()),this.historyIndex=this.history.length-1,this.emit("history-change",{records:bt.clone(this.history),index:this.historyIndex})}eventBind(){var t,e;for(const r of["mousedown","mouseup","mousemove","wheel","contextmenu","pointerclick"])this.stage.on(r,t=>{var e,n,i,o,s,a,h,d,u;null==(e=null==t?void 0:t.evt)||e.preventDefault();for(const l in this.draws)null==(s=null==(o=null==(i=null==(n=this.draws[l])?void 0:n.handlers)?void 0:i.stage)?void 0:o[r])||s.call(o,t);for(const l in this.handlers)null==(u=null==(d=null==(h=null==(a=this.handlers[l])?void 0:a.handlers)?void 0:h.stage)?void 0:d[r])||u.call(d,t)});const n=this.stage.container();n.tabIndex=1,n.focus();for(const r of["mouseenter","dragenter","mousemove","mouseout","dragenter","dragover","drop","keydown","keyup"])n.addEventListener(r,t=>{var e,n,i,o,s,a,h,d;null==t||t.preventDefault(),["mouseenter","dragenter"].includes(r)&&this.stage.container().focus();for(const u in this.draws)null==(o=null==(i=null==(n=null==(e=this.draws[u])?void 0:e.handlers)?void 0:n.dom)?void 0:i[r])||o.call(i,t);for(const u in this.handlers)null==(d=null==(h=null==(a=null==(s=this.handlers[u])?void 0:s.handlers)?void 0:a.dom)?void 0:h[r])||d.call(h,t)});for(const r of["mousedown","transformstart","transform","transformend","dragstart","dragmove","dragend","mousemove","mouseleave","dblclick"])this.transformer.on(r,t=>{var e,n,i,o,s,a,h,d,u;null==(e=null==t?void 0:t.evt)||e.preventDefault();for(const l in this.draws)null==(s=null==(o=null==(i=null==(n=this.draws[l])?void 0:n.handlers)?void 0:i.transformer)?void 0:o[r])||s.call(o,t);for(const l in this.handlers)null==(u=null==(d=null==(h=null==(a=this.handlers[l])?void 0:a.handlers)?void 0:h.transformer)?void 0:d[r])||u.call(d,t)});(null==(e=null==(t=this.handlers[ac.name])?void 0:t.transformerConfig)?void 0:e.anchorDragBoundFunc)&&this.transformer.anchorDragBoundFunc(this.handlers[ac.name].transformerConfig.anchorDragBoundFunc)}getStageState(){return{width:this.stage.width()-this.rulerSize,height:this.stage.height()-this.rulerSize,scale:this.stage.scaleX(),x:this.stage.x(),y:this.stage.y()}}toStageValue(t){return t/this.stage.scaleX()}toBoardValue(t){return t*this.stage.scaleX()}ignore(t){return!(t instanceof e.Group)||this.ignoreSelect(t)||this.ignoreDraw(t)||this.ignoreLink(t)}ignoreSelect(t){return"selectRect"===t.id()||"hoverRect"===t.id()}ignoreDraw(t){return t.name()===El.name||t.name()===Rl.name||t.name()===Ll.name||t.name()===Wl.name||t.name()===Bl.name||t.name()===Fl.name||t.name()===Xl.name||t.name()===rc.name}ignoreLink(t){return"link-anchor"===t.name()||"linking-line"===t.name()||"link-point"===t.name()||"link-line"===t.name()||"link-manual-point"===t.name()}redraw(t){var e,n;const r=[El.name,rc.name,Fl.name,Xl.name,Rl.name,Ll.name,Bl.name,Wl.name];if(Array.isArray(t)&&!this.debug)for(const i of r)t.includes(i)&&(null==(e=this.draws[i])||e.draw());else for(const i of r)null==(n=this.draws[i])||n.draw()}changeDraggable(t){this.layer.children.forEach(e=>{e.draggable(t)})}changeGraphType(t){t&&(this.texting=!1,this.emit("texting-change",this.texting)),this.graphType=t,this.emit("graph-type-change",this.graphType),this.changeDraggable(!this.config.readonly&&void 0===this.graphType)}changeTexting(t){t&&(this.graphType=void 0,this.emit("graph-type-change",this.graphType)),this.texting=t,this.emit("texting-change",this.texting),document.body.style.cursor=this.texting?"text":"default"}getPageSettings(){return this.stage.attrs.pageSettings??{...t.PageSettingsDefault}}setPageSettings(t,e=!1){this.stage.setAttr("pageSettings",t),this.updateBackground(),e&&this.updateHistory()}getBackground(){var t;return null==(t=this.draws[El.name])?void 0:t.layer.findOne(`.${El.name}__background`)}updateBackground(){var t,e,n,r;const i=this.getBackground();i&&i.fill(this.getPageSettings().background??"transparent"),null==(t=this.draws[El.name])||t.draw(),null==(e=this.draws[rc.name])||e.draw(),null==(n=this.draws[Fl.name])||n.draw(),null==(r=this.draws[Bl.name])||r.draw()}getAssetSettings(e){const n=(null==e?void 0:e.attrs.assetSettings)??{...t.AssetSettingsDefault};return{...n,stroke:n.stroke||this.getPageSettings().stroke,strokeWidth:n.strokeWidth||this.getPageSettings().strokeWidth,fontSize:n.fontSize||this.getPageSettings().fontSize,textFill:n.textFill||this.getPageSettings().textFill,fill:n.fill||((null==e?void 0:e.attrs.assetType)===Cl.Graph?"transparent":this.getPageSettings().fill),x:parseFloat(((null==e?void 0:e.position().x)??0).toFixed(1)),y:parseFloat(((null==e?void 0:e.position().y)??0).toFixed(1)),rotation:parseFloat(((null==e?void 0:e.rotation())??0).toFixed(1)),tension:(null==e?void 0:e.attrs.assetType)===Cl.Graph&&(null==e?void 0:e.attrs.graphType)===Vl.Curve?n.tension:void 0}}setSvgXMLSettings(t,e){const n=t.match(/<(circle|ellipse|line|path|polygon|rect|text|textPath|tref|tspan)[^>/]*\/?>/g),r=/ stroke="([^"]*)"/,i=/ fill="([^"]*)"/;for(const o of n??[]){let n=o;e.stroke&&(n=r.test(o)?n.replace(r,` stroke="${e.stroke}"`):n.replace(/(<[^>/]*)(\/?>)/,`$1 stroke="${e.stroke}" $2`)),e.fill&&(n=i.test(o)?n.replace(i,` fill="${e.fill}"`):n.replace(/(<[^>/]*)(\/?>)/,`$1 fill="${e.fill}" $2`)),t=t.replace(o,n)}return t}rotatePoint({x:t,y:e},n){const r=Math.cos(n),i=Math.sin(n);return{x:t*r-e*i,y:e*r+t*i}}rotateAroundCenter(t,n){const r={x:-t.width()/2,y:-t.height()/2},i=this.rotatePoint(r,e.getAngle(t.rotation())),o=this.rotatePoint(r,e.getAngle(n)),s=o.x-i.x,a=o.y-i.y;t.rotation(n),t.x(t.x()+s),t.y(t.y()+a)}async setAssetSettings(t,n,r=!1){var i,o,s,a,h;if(t.setAttr("assetSettings",n),t instanceof e.Group){if(t.attrs.imageType===Ol.svg){const r=t.children[0];if(r instanceof e.Image&&r.attrs.svgXML){const t=await this.assetTool.loadSvgXML(this.setSvgXMLSettings(r.attrs.svgXML,n));null==(i=r.parent)||i.add(t),r.remove(),r.destroy(),t.zIndex(0)}}else if(t.attrs.assetType===Cl.Graph){const r=t.findOne(".graph");r instanceof e.Shape&&(r.strokeWidth(n.strokeWidth),r.stroke(n.stroke),r instanceof e.Arrow?r.fill(n.stroke):r.fill(n.fill),r instanceof e.Arrow&&(r.pointerAtBeginning(n.arrowStart),r.pointerAtEnding(n.arrowEnd)),r instanceof e.Arrow&&t.attrs.graphType===Vl.Curve&&r.tension(n.tension))}else if(t.attrs.assetType===Cl.Text){const r=t.findOne("Text"),i=t.findOne("Rect");if(r instanceof e.Text&&i instanceof e.Rect){let e=!1;r.fontSize()===n.fontSize&&r.text()===n.text||(e=!0),r.fill(n.textFill),r.fontSize(n.fontSize),r.text(n.text),i.fill(r.text().trim()?"":"rgba(0,0,0,0.1)"),i.width(Math.max(r.width(),n.fontSize)),i.height(Math.max(r.height(),n.fontSize)),e&&this.selectionTool.select([t])}}if(Math.abs(n.rotation-t.rotation())>=.1)this.rotateAroundCenter(t,n.rotation),this.emit("asset-position-change",[t]);else{const e=this.getAssetSettings(t);t.position({x:parseFloat(n.x.toFixed(1)),y:parseFloat(n.y.toFixed(1))}),n.x===e.x&&n.y===e.y||this.emit("asset-position-change",[t])}}r&&this.updateHistory(),null==(o=this.draws[El.name])||o.draw(),null==(s=this.draws[rc.name])||s.draw(),null==(a=this.draws[Fl.name])||a.draw(),null==(h=this.draws[Bl.name])||h.draw()}async setLinkSettings(t,e,n=!1){var r,i,o,s;const a=this.layer.findOne(`#${t.attrs.groupId}`);if(Array.isArray(null==a?void 0:a.attrs.points)){const n=(null==a?void 0:a.attrs.points).find(e=>e.id===t.attrs.pointId);if(n){const r=n.pairs.find(e=>e.id===t.attrs.pairId);r&&(r.style={...r.style,...e},a.setAttr("points",null==a?void 0:a.attrs.points))}}n&&this.updateHistory(),null==(r=this.draws[El.name])||r.draw(),null==(i=this.draws[rc.name])||i.draw(),null==(o=this.draws[Fl.name])||o.draw(),null==(s=this.draws[Bl.name])||s.draw()}getLinkSettings(e){let n;if(e){const t=this.layer.findOne(`#${e.attrs.groupId}`);if(Array.isArray(null==t?void 0:t.attrs.points)){const r=(null==t?void 0:t.attrs.points).find(t=>t.id===e.attrs.pointId);if(r){const t=r.pairs.find(t=>t.id===e.attrs.pairId);t&&(n=t.style)}}}const r=n??{...t.LinkSettingsDefault};return{...r,stroke:r.stroke||this.getPageSettings().linkStroke,strokeWidth:r.strokeWidth||this.getPageSettings().linkStrokeWidth}}};r(Ic,"PageSettingsDefault",{background:"transparent",stroke:"rgb(0,0,0)",strokeWidth:1,fill:"rgb(0,0,0)",linkStroke:"rgb(0,0,0)",linkStrokeWidth:1,fontSize:24,textFill:"rgb(0,0,0)"}),r(Ic,"AssetSettingsDefault",{stroke:"",strokeWidth:0,fill:"",arrowStart:!1,arrowEnd:!1,fontSize:0,textFill:"",text:"Text",x:0,y:0,rotation:0,tension:0}),r(Ic,"LinkSettingsDefault",{stroke:"",strokeWidth:0,arrowStart:!1,arrowEnd:!1,tension:0});let Tc=Ic;const Pc={Render:Tc};return t.AlignType=Ml,t.AssetType=Cl,t.BaseDraw=Il,t.GraphType=Vl,t.ImageType=Ol,t.LinkType=zl,t.MouseButton=jl,t.MoveKey=Tl,t.Render=Tc,t.ShutcutKey=Pl,t.default=Pc,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),t}({},Konva);
23
+ */wc=bc,function(){var t,e,n,r,i;function o(t,e){var n,r=Object.keys(e);for(n=0;n<r.length;n++)t=t.replace(new RegExp("\\{"+r[n]+"\\}","gi"),e[r[n]]);return t}function s(t){var e,n,r;if(!t)throw new Error("cannot create a random attribute name for an undefined object");e="ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",n="";do{for(n="",r=0;r<12;r++)n+=e[Math.floor(51*Math.random())]}while(t[n]);return n}function a(t){var e={alphabetic:"alphabetic",hanging:"hanging",top:"text-before-edge",bottom:"text-after-edge",middle:"central"};return e[t]||e.alphabetic}i=function(t,e){var n,r,i,o={};for(t=t.split(","),e=e||10,n=0;n<t.length;n+=2)r="&"+t[n+1]+";",i=parseInt(t[n],e),o[r]="&#"+i+";";return o["\\xa0"]="&#160;",o}("50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,t9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro",32),t={strokeStyle:{svgAttr:"stroke",canvas:"#000000",svg:"none",apply:"stroke"},fillStyle:{svgAttr:"fill",canvas:"#000000",svg:null,apply:"fill"},lineCap:{svgAttr:"stroke-linecap",canvas:"butt",svg:"butt",apply:"stroke"},lineJoin:{svgAttr:"stroke-linejoin",canvas:"miter",svg:"miter",apply:"stroke"},miterLimit:{svgAttr:"stroke-miterlimit",canvas:10,svg:4,apply:"stroke"},lineWidth:{svgAttr:"stroke-width",canvas:1,svg:1,apply:"stroke"},globalAlpha:{svgAttr:"opacity",canvas:1,svg:1,apply:"fill stroke"},font:{canvas:"10px sans-serif"},shadowColor:{canvas:"#000000"},shadowOffsetX:{canvas:0},shadowOffsetY:{canvas:0},shadowBlur:{canvas:0},textAlign:{canvas:"start"},textBaseline:{canvas:"alphabetic"}},(n=function(t,e){this.__root=t,this.__ctx=e}).prototype.addColorStop=function(t,e){var n,r=this.__ctx.__createElement("stop");r.setAttribute("offset",t),-1!==e.indexOf("rgba")?(n=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi.exec(e),r.setAttribute("stop-color",o("rgb({r},{g},{b})",{r:n[1],g:n[2],b:n[3]})),r.setAttribute("stop-opacity",n[4])):r.setAttribute("stop-color",e),this.__root.appendChild(r)},r=function(t,e){this.__root=t,this.__ctx=e},e=function(t){var n,r={width:500,height:500,enableMirroring:!1};if(arguments.length>1?((n=r).width=arguments[0],n.height=arguments[1]):n=t||r,!(this instanceof e))return new e(n);this.width=n.width||r.width,this.height=n.height||r.height,this.enableMirroring=void 0!==n.enableMirroring?n.enableMirroring:r.enableMirroring,this.canvas=this,this.__document=n.document||document,this.__canvas=this.__document.createElement("canvas"),this.__ctx=this.__canvas.getContext("2d"),this.__setDefaultStyles(),this.__stack=[this.__getStyleState()],this.__groupStack=[],this.__root=this.__document.createElementNS("http://www.w3.org/2000/svg","svg"),this.__root.setAttribute("version",1.1),this.__root.setAttribute("xmlns","http://www.w3.org/2000/svg"),this.__root.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink"),this.__root.setAttribute("width",this.width),this.__root.setAttribute("height",this.height),this.__ids={},this.__defs=this.__document.createElementNS("http://www.w3.org/2000/svg","defs"),this.__root.appendChild(this.__defs),this.__currentElement=this.__document.createElementNS("http://www.w3.org/2000/svg","g"),this.__root.appendChild(this.__currentElement)},e.prototype.__createElement=function(t,e,n){void 0===e&&(e={});var r,i,o=this.__document.createElementNS("http://www.w3.org/2000/svg",t),s=Object.keys(e);for(n&&(o.setAttribute("fill","none"),o.setAttribute("stroke","none")),r=0;r<s.length;r++)i=s[r],o.setAttribute(i,e[i]);return o},e.prototype.__setDefaultStyles=function(){var e,n,r=Object.keys(t);for(e=0;e<r.length;e++)this[n=r[e]]=t[n].canvas},e.prototype.__applyStyleState=function(t){var e,n,r=Object.keys(t);for(e=0;e<r.length;e++)this[n=r[e]]=t[n]},e.prototype.__getStyleState=function(){var e,n,r={},i=Object.keys(t);for(e=0;e<i.length;e++)r[n=i[e]]=this[n];return r},e.prototype.__applyStyleToCurrentElement=function(e){var i,s,a,h,d,u=Object.keys(t);for(i=0;i<u.length;i++)if(s=t[u[i]],a=this[u[i]],s.apply)if(-1!==s.apply.indexOf("fill")&&a instanceof r){if(a.__ctx)for(;a.__ctx.__defs.childNodes.length;)h=a.__ctx.__defs.childNodes[0].getAttribute("id"),this.__ids[h]=h,this.__defs.appendChild(a.__ctx.__defs.childNodes[0]);this.__currentElement.setAttribute("fill",o("url(#{id})",{id:a.__root.getAttribute("id")}))}else-1!==s.apply.indexOf("fill")&&a instanceof n?this.__currentElement.setAttribute("fill",o("url(#{id})",{id:a.__root.getAttribute("id")})):-1!==s.apply.indexOf(e)&&s.svg!==a&&("stroke"!==s.svgAttr&&"fill"!==s.svgAttr||-1===a.indexOf("rgba")?this.__currentElement.setAttribute(s.svgAttr,a):(d=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi.exec(a),this.__currentElement.setAttribute(s.svgAttr,o("rgb({r},{g},{b})",{r:d[1],g:d[2],b:d[3]})),this.__currentElement.setAttribute(s.svgAttr+"-opacity",d[4])))},e.prototype.__closestGroupOrSvg=function(t){return"g"===(t=t||this.__currentElement).nodeName||"svg"===t.nodeName?t:this.__closestGroupOrSvg(t.parentNode)},e.prototype.getSerializedSvg=function(t){var e,n,r,o,s,a=(new XMLSerializer).serializeToString(this.__root);if(/xmlns="http:\/\/www\.w3\.org\/2000\/svg".+xmlns="http:\/\/www\.w3\.org\/2000\/svg/gi.test(a)&&(a=a.replace('xmlns="http://www.w3.org/2000/svg','xmlns:xlink="http://www.w3.org/1999/xlink')),t)for(e=Object.keys(i),n=0;n<e.length;n++)r=e[n],o=i[r],(s=new RegExp(r,"gi")).test(a)&&(a=a.replace(s,o));return a},e.prototype.getSvg=function(){return this.__root},e.prototype.save=function(){var t=this.__createElement("g"),e=this.__closestGroupOrSvg();this.__groupStack.push(e),e.appendChild(t),this.__currentElement=t,this.__stack.push(this.__getStyleState())},e.prototype.restore=function(){this.__currentElement=this.__groupStack.pop();var t=this.__stack.pop();this.__applyStyleState(t)},e.prototype.__addTransform=function(t){var e=this.__closestGroupOrSvg();if(e.childNodes.length>0){var n=this.__createElement("g");e.appendChild(n),this.__currentElement=n}var r=this.__currentElement.getAttribute("transform");r?r+=" ":r="",r+=t,this.__currentElement.setAttribute("transform",r)},e.prototype.scale=function(t,e){void 0===e&&(e=t),this.__addTransform(o("scale({x},{y})",{x:t,y:e}))},e.prototype.rotate=function(t){var e=180*t/Math.PI;this.__addTransform(o("rotate({angle},{cx},{cy})",{angle:e,cx:0,cy:0}))},e.prototype.translate=function(t,e){this.__addTransform(o("translate({x},{y})",{x:t,y:e}))},e.prototype.transform=function(t,e,n,r,i,s){this.__addTransform(o("matrix({a},{b},{c},{d},{e},{f})",{a:t,b:e,c:n,d:r,e:i,f:s}))},e.prototype.beginPath=function(){var t;this.__currentDefaultPath="",this.__currentPosition={},t=this.__createElement("path",{},!0),this.__closestGroupOrSvg().appendChild(t),this.__currentElement=t},e.prototype.__applyCurrentDefaultPath=function(){if("path"!==this.__currentElement.nodeName)throw new Error("Attempted to apply path command to node "+this.__currentElement.nodeName);var t=this.__currentDefaultPath;this.__currentElement.setAttribute("d",t)},e.prototype.__addPathCommand=function(t){this.__currentDefaultPath+=" ",this.__currentDefaultPath+=t},e.prototype.moveTo=function(t,e){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.__currentPosition={x:t,y:e},this.__addPathCommand(o("M {x} {y}",{x:t,y:e}))},e.prototype.closePath=function(){this.__addPathCommand("Z")},e.prototype.lineTo=function(t,e){this.__currentPosition={x:t,y:e},this.__currentDefaultPath.indexOf("M")>-1?this.__addPathCommand(o("L {x} {y}",{x:t,y:e})):this.__addPathCommand(o("M {x} {y}",{x:t,y:e}))},e.prototype.bezierCurveTo=function(t,e,n,r,i,s){this.__currentPosition={x:i,y:s},this.__addPathCommand(o("C {cp1x} {cp1y} {cp2x} {cp2y} {x} {y}",{cp1x:t,cp1y:e,cp2x:n,cp2y:r,x:i,y:s}))},e.prototype.quadraticCurveTo=function(t,e,n,r){this.__currentPosition={x:n,y:r},this.__addPathCommand(o("Q {cpx} {cpy} {x} {y}",{cpx:t,cpy:e,x:n,y:r}))};var h=function(t){var e=Math.sqrt(t[0]*t[0]+t[1]*t[1]);return[t[0]/e,t[1]/e]};e.prototype.arcTo=function(t,e,n,r,i){var o=this.__currentPosition&&this.__currentPosition.x,s=this.__currentPosition&&this.__currentPosition.y;if(void 0!==o&&void 0!==s){if(i<0)throw new Error("IndexSizeError: The radius provided ("+i+") is negative.");if(o===t&&s===e||t===n&&e===r||0===i)this.lineTo(t,e);else{var a=h([o-t,s-e]),d=h([n-t,r-e]);if(a[0]*d[1]!==a[1]*d[0]){var u=a[0]*d[0]+a[1]*d[1],l=Math.acos(Math.abs(u)),c=h([a[0]+d[0],a[1]+d[1]]),f=i/Math.sin(l/2),g=t+f*c[0],p=e+f*c[1],y=[-a[1],a[0]],m=[d[1],-d[0]],v=function(t){var e=t[0];return t[1]>=0?Math.acos(e):-Math.acos(e)},x=v(y),w=v(m);this.lineTo(g+y[0]*i,p+y[1]*i),this.arc(g,p,i,x,w)}else this.lineTo(t,e)}}},e.prototype.stroke=function(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","fill stroke markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("stroke")},e.prototype.fill=function(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","stroke fill markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("fill")},e.prototype.rect=function(t,e,n,r){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.moveTo(t,e),this.lineTo(t+n,e),this.lineTo(t+n,e+r),this.lineTo(t,e+r),this.lineTo(t,e),this.closePath()},e.prototype.fillRect=function(t,e,n,r){var i;i=this.__createElement("rect",{x:t,y:e,width:n,height:r},!0),this.__closestGroupOrSvg().appendChild(i),this.__currentElement=i,this.__applyStyleToCurrentElement("fill")},e.prototype.strokeRect=function(t,e,n,r){var i;i=this.__createElement("rect",{x:t,y:e,width:n,height:r},!0),this.__closestGroupOrSvg().appendChild(i),this.__currentElement=i,this.__applyStyleToCurrentElement("stroke")},e.prototype.clearRect=function(t,e,n,r){var i,o=this.__closestGroupOrSvg();i=this.__createElement("rect",{x:t,y:e,width:n,height:r,fill:"#FFFFFF"},!0),o.appendChild(i)},e.prototype.createLinearGradient=function(t,e,r,i){var o=this.__createElement("linearGradient",{id:s(this.__ids),x1:t+"px",x2:r+"px",y1:e+"px",y2:i+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(o),new n(o,this)},e.prototype.createRadialGradient=function(t,e,r,i,o,a){var h=this.__createElement("radialGradient",{id:s(this.__ids),cx:i+"px",cy:o+"px",r:a+"px",fx:t+"px",fy:e+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(h),new n(h,this)},e.prototype.__parseFont=function(){var t=/^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-,\"\sa-z]+?)\s*$/i.exec(this.font),e={style:t[1]||"normal",size:t[4]||"10px",family:t[6]||"sans-serif",weight:t[3]||"normal",decoration:t[2]||"normal",href:null};return"underline"===this.__fontUnderline&&(e.decoration="underline"),this.__fontHref&&(e.href=this.__fontHref),e},e.prototype.__wrapTextLink=function(t,e){if(t.href){var n=this.__createElement("a");return n.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t.href),n.appendChild(e),n}return e},e.prototype.__applyText=function(t,e,n,r){var i,o,s=this.__parseFont(),h=this.__closestGroupOrSvg(),d=this.__createElement("text",{"font-family":s.family,"font-size":s.size,"font-style":s.style,"font-weight":s.weight,"text-decoration":s.decoration,x:e,y:n,"text-anchor":(i=this.textAlign,o={left:"start",right:"end",center:"middle",start:"start",end:"end"},o[i]||o.start),"dominant-baseline":a(this.textBaseline)},!0);d.appendChild(this.__document.createTextNode(t)),this.__currentElement=d,this.__applyStyleToCurrentElement(r),h.appendChild(this.__wrapTextLink(s,d))},e.prototype.fillText=function(t,e,n){this.__applyText(t,e,n,"fill")},e.prototype.strokeText=function(t,e,n){this.__applyText(t,e,n,"stroke")},e.prototype.measureText=function(t){return this.__ctx.font=this.font,this.__ctx.measureText(t)},e.prototype.arc=function(t,e,n,r,i,s){if(r!==i){(r%=2*Math.PI)==(i%=2*Math.PI)&&(i=(i+2*Math.PI-.001*(s?-1:1))%(2*Math.PI));var a=t+n*Math.cos(i),h=e+n*Math.sin(i),d=t+n*Math.cos(r),u=e+n*Math.sin(r),l=s?0:1,c=0,f=i-r;f<0&&(f+=2*Math.PI),c=s?f>Math.PI?0:1:f>Math.PI?1:0,this.lineTo(d,u),this.__addPathCommand(o("A {rx} {ry} {xAxisRotation} {largeArcFlag} {sweepFlag} {endX} {endY}",{rx:n,ry:n,xAxisRotation:0,largeArcFlag:c,sweepFlag:l,endX:a,endY:h})),this.__currentPosition={x:a,y:h}}},e.prototype.clip=function(){var t=this.__closestGroupOrSvg(),e=this.__createElement("clipPath"),n=s(this.__ids),r=this.__createElement("g");t.removeChild(this.__currentElement),e.setAttribute("id",n),e.appendChild(this.__currentElement),this.__defs.appendChild(e),t.setAttribute("clip-path",o("url(#{id})",{id:n})),t.appendChild(r),this.__currentElement=r},e.prototype.drawImage=function(){var t,n,r,i,o,s,a,h,d,u,l,c,f,g,p=Array.prototype.slice.call(arguments),y=p[0],m=0,v=0;if(3===p.length)t=p[1],n=p[2],r=o=y.width,i=s=y.height;else if(5===p.length)t=p[1],n=p[2],r=p[3],i=p[4],o=y.width,s=y.height;else{if(9!==p.length)throw new Error("Inavlid number of arguments passed to drawImage: "+arguments.length);m=p[1],v=p[2],o=p[3],s=p[4],t=p[5],n=p[6],r=p[7],i=p[8]}if(a=this.__closestGroupOrSvg(),l=this.__currentElement,y instanceof e){for(d=(h=y.getSvg()).childNodes[0];d.childNodes.length;)g=d.childNodes[0].getAttribute("id"),this.__ids[g]=g,this.__defs.appendChild(d.childNodes[0]);u=h.childNodes[1],a.appendChild(u),this.__currentElement=u,this.translate(t,n),this.__currentElement=l}else"CANVAS"!==y.nodeName&&"IMG"!==y.nodeName||((c=this.__createElement("image")).setAttribute("width",r),c.setAttribute("height",i),c.setAttribute("preserveAspectRatio","none"),(m||v||o!==y.width||s!==y.height)&&((f=this.__document.createElement("canvas")).width=r,f.height=i,f.getContext("2d").drawImage(y,m,v,o,s,0,0,r,i),y=f),c.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===y.nodeName?y.toDataURL():y.getAttribute("src")),a.appendChild(c),this.__currentElement=c,this.translate(t,n),this.__currentElement=l)},e.prototype.createPattern=function(t,n){var i,o=this.__document.createElementNS("http://www.w3.org/2000/svg","pattern"),a=s(this.__ids);return o.setAttribute("id",a),o.setAttribute("width",t.width),o.setAttribute("height",t.height),"CANVAS"===t.nodeName||"IMG"===t.nodeName?((i=this.__document.createElementNS("http://www.w3.org/2000/svg","image")).setAttribute("width",t.width),i.setAttribute("height",t.height),i.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===t.nodeName?t.toDataURL():t.getAttribute("src")),o.appendChild(i),this.__defs.appendChild(o)):t instanceof e&&(o.appendChild(t.__root.childNodes[1]),this.__defs.appendChild(o)),new r(o,this)},e.prototype.drawFocusRing=function(){},e.prototype.createImageData=function(){},e.prototype.getImageData=function(){},e.prototype.putImageData=function(){},e.prototype.globalCompositeOperation=function(){},e.prototype.setTransform=function(){},"object"==typeof window&&(window.C2S=e),wc.exports=e}();const Sc=xc(bc.exports);Sc.prototype.__applyCurrentDefaultPath=function(){if("g"===this.__currentElement.nodeName){const t=this.__currentElement.querySelector("g");if(t){const e=t.getAttribute("transform");if(e){const t=e.match(/scale\(([^),]+),([^)]+)\)/);if(t){const[e,n]=[parseFloat(t[1]),parseFloat(t[2])];let r=this.__currentDefaultPath;const i=/A ([^ ]+) ([^ ]+) /,o=r.match(i);if(o){const[t,s]=[parseFloat(o[1]),parseFloat(o[2])];r=r.replace(i,`A ${t*e} ${s*n} `);const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("d",r),a.setAttribute("fill","none"),this.__currentElement.append(a)}}}else{const t=this.__currentDefaultPath,e=document.createElementNS("http://www.w3.org/2000/svg","path");e.setAttribute("d",t),e.setAttribute("fill","none"),this.__currentElement.append(e)}}return}if("path"!==this.__currentElement.nodeName)throw new Error("Attempted to apply path command to node "+this.__currentElement.nodeName);{const t=this.__currentDefaultPath;this.__currentElement.setAttribute("d",t)}};class _c{constructor(t){r(this,"render"),this.render=t}getView(t=!1){const n=this.render.stage.clone(),r=n.find("#main")[0],i=n.find("#cover")[0],o=n.getChildren();if(n.removeChildren(),r&&i){let o=r.getChildren(t=>!this.render.ignore(t));for(const t of o){t.listening(!0),t.draggable(!this.render.config.readonly);for(const e of t.children)this.render.ignoreSelect(e)&&e.remove()}if(t){const t=i.children.find(t=>t.attrs.name===Fl.name);t&&(o=o.concat(t.children.filter(t=>"link-line"===t.attrs.name)))}const s=new e.Layer;s.add(...o),o=s.getChildren();for(const t of o)t.attrs.nodeMousedownPos&&t.setAttrs({opacity:n.attrs.lastOpacity??1});n.add(s),r.removeChildren(),i.removeChildren()}return o.forEach(t=>t.destroy()),n}save(){const t=this.getView(),e=t.toJSON();return t.destroy(),e}loadImage(t){return new Promise(e=>{const n=new Image;n.onload=()=>{e(n)},n.onerror=()=>{e(null)},n.src=t})}async restoreImage(t=[]){for(const n of t)if(n instanceof e.Group)await this.restoreImage(n.getChildren());else if(n instanceof e.Image)if(n.attrs.svgXML){const t=new Blob([n.attrs.svgXML],{type:"image/svg+xml"}),e=URL.createObjectURL(t),r=await this.loadImage(e);r&&n.image(r)}else if(n.attrs.gif){const t=await this.render.assetTool.loadGif(n.attrs.gif);t&&n.image(t.image())}else if(n.attrs.src){const t=await this.loadImage(n.attrs.src);t&&n.image(t)}}async restore(t,n=!1){try{this.render.emit("loading",!0),this.render.selectionTool.selectingClear(),this.render.linkTool.selectingClear(),this.render.layer.getChildren().forEach(t=>{t.destroy()}),this.render.layer.removeChildren();const r=document.createElement("div"),i=e.Node.create(t,r),o=i.getChildren()[0].getChildren();await this.restoreImage(o);for(const t of o)t.draggable(!this.render.config.readonly),t.off("mouseenter"),t.on("mouseenter",()=>{this.render.linkTool.pointsVisible(!0,t)}),t.add(new e.Rect({id:"hoverRect",width:t.width(),height:t.height(),fill:"rgba(0,255,0,0.3)",visible:!1})),t.off("mouseleave"),t.on("mouseleave",()=>{var e;this.render.linkTool.pointsVisible(!1,t),null==(e=t.findOne("#hoverRect"))||e.visible(!1)});this.render.layer.add(...o),this.render.stage.setAttr("pageSettings",i.attrs.pageSettings),this.render.emit("page-settings-change",this.render.getPageSettings()),this.render.updateBackground(),n||this.render.updateHistory(),this.render.linkTool.pointsVisible(!1),this.render.redraw([rc.name,Fl.name,Rl.name,Bl.name]),i.destroy()}catch(r){}finally{this.render.emit("loading",!1)}}getImage(t=1,n){const r=this.getAssetView(),i=new e.Layer,o=new e.Rect({listening:!1});o.setAttrs({x:0,y:0,width:r.width(),height:r.height(),fill:n??this.render.getPageSettings().background}),i.add(o);const s=r.getChildren();r.removeChildren(),r.add(i),r.add(s[0],...s.slice(1));const a=r.toDataURL({pixelRatio:t});return r.destroy(),a}getAssetImage(t=1,n){const r=this.getAssetView(),i=new e.Layer,o=new e.Rect({listening:!1});o.setAttrs({x:-r.x(),y:-r.y(),width:r.width(),height:r.height(),fill:n??this.render.getPageSettings().background}),i.add(o);const s=r.getChildren();r.removeChildren(),r.add(i),r.add(s[0],...s.slice(1));const a=r.toDataURL({pixelRatio:t});return r.destroy(),a}blobToBase64(t,e){return new Promise(n=>{const r=new File([t],"image",{type:e}),i=new FileReader;i.readAsDataURL(r),i.onload=function(){n(this.result??"")}})}parseSvgImage(t){return new Promise(e=>{t.length>0?Promise.all(t.map(t=>fetch(t))).then(t=>{Promise.all(t.map(t=>t.text())).then(t=>{e(t)})}):e([])})}parseOtherImage(t){return new Promise(e=>{t.length>0?Promise.all(t.map(t=>fetch(t))).then(t=>{Promise.all(t.map(t=>t.blob())).then(t=>{Promise.all(t.map(t=>this.blobToBase64(t,"image/*"))).then(t=>{e(t)})})}):e([])})}parseImage(t){return new Promise(e=>{const n=t.match(new RegExp('(?<=xlink:href=")blob:https?:\\/\\/[^"]+(?=")',"g"))??[],r=t.match(new RegExp('(?<=xlink:href=")(?<!blob:)[^"]+(?=")',"g"))??[];Promise.all([this.parseSvgImage(n),this.parseOtherImage(r)]).then(([i,o])=>{n.forEach((e,n)=>{var r;t=t.replace(new RegExp(`<image[^><]* xlink:href="${e}"[^><]*/>`),(null==(r=i[n].match(/<svg[^><]*>.*<\/svg>/))?void 0:r[0])??"")}),r.forEach((e,n)=>{t=t.replace(`"${e}"`,`"${o[n]}"`)}),e(t)})})}async getSvg(){const t=this.getAssetView(),e=t.children[0],n=e.canvas.context._context;if(n){const r=new Sc({ctx:n,...e.size()});e.canvas.context._context=r,e.draw();let i=r.getSerializedSvg();i=i.replace(/(<defs\/><g><rect fill=")([^"]+)(")/,`$1${this.render.getPageSettings().background}$3`);const o=await this.parseImage(i);return t.destroy(),o}return Promise.resolve('<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0"></svg>')}getAssetView(){const t=this.getView(!0),n=[...t.getChildren()[0].getChildren()];let r=1/0,i=-1/0,o=1/0,s=-1/0,a=1/0,h=1/0;const d=this.render.getStageState();for(const u of n)if(u instanceof e.Group){const{x:t,y:n,width:l,height:c}=(t=>({x:this.render.toStageValue(t.x-d.x),y:this.render.toStageValue(t.y-d.y),width:this.render.toStageValue(t.width),height:this.render.toStageValue(t.height)}))(u.getClientRect());if(t<r&&(r=t),t+l>i&&(i=t+l),n<o&&(o=n),n+c>s&&(s=n+c),t<a&&(a=t),n<h&&(h=n),u instanceof e.Group){const t=u.findOne("#click-mask");t&&t.destroy()}}else if(u instanceof e.Line&&"link-line"===u.name()){const t=u.points();for(let e=0;e<t.length;e+=2){const[n,d]=[t[e],t[e+1]];n<r&&(r=n-1),n>i&&(i=n+1),d<o&&(o=d-1),d>s&&(s=d+1),n<a&&(a=n-1),d<h&&(h=d-1)}}for(const u of n)if(u instanceof e.Group)u.x(u.x()-a),u.y(u.y()-h);else if(u instanceof e.Line&&"link-line"===u.name()){const t=u.points();for(let e=0;e<t.length;e+=2)t[e]=t[e]-a,t[e+1]=t[e+1]-h;u.points(t)}return t.x(0),t.y(0),t.width(i-r),t.height(s-o),t.scale({x:1,y:1}),t}getAsset(){const t=this.getAssetView(),e=this.render.getBackground();e.width(t.width()),e.height(t.height()),t.children[0].add(e),e.moveToBottom();const n=t.toJSON(),r=JSON.parse(n),i=r.children[0].children;for(const s of i)"asset"===s.attrs.name&&(s.attrs.name="sub-asset"),s.attrs.selected&&(s.attrs.selected=!1);this.render.linkTool.jsonIdCover(i);const o=JSON.stringify({...r.children[0],className:"Group",attrs:{width:t.width(),height:t.height(),x:0,y:0}});return t.destroy(),o}}r(_c,"name","ImportExportTool");class Ac{constructor(t){r(this,"render"),this.render=t}getAlignRect(t){const e=this.render.getStageState();let n=0,r=0,i=0,o=0;const s=t.getClientRect();return[n,r,i,o]=[this.render.toStageValue(s.width),this.render.toStageValue(s.height),this.render.toStageValue(s.x-e.x),this.render.toStageValue(s.y-e.y)],{width:n,height:r,x:i,y:o}}getAlignPoints(t){let e=0,n=0,r=0,i=0;if(void 0===t)return this.getAlignPoints(this.render.transformer);{const o=this.getAlignRect(t);[e,n,r,i]=[o.width,o.height,o.x,o.y]}return{[Ml.垂直居中]:r+e/2,[Ml.左对齐]:r,[Ml.右对齐]:r+e,[Ml.水平居中]:i+n/2,[Ml.上对齐]:i,[Ml.下对齐]:i+n}}align(t,e){const n=this.getAlignPoints(e)[t],r=this.render.transformer.nodes().filter(t=>t!==e);for(const i of r){const e=this.getAlignRect(i),[r,o,s,a]=[e.width,e.height,e.x,e.y];switch(t){case Ml.垂直居中:{const t=s+r/2;i.x(i.x()+(n-t))}break;case Ml.水平居中:{const t=a+o/2;i.y(i.y()+(n-t))}break;case Ml.左对齐:{const t=s;i.x(i.x()+(n-t))}break;case Ml.右对齐:{const t=s+r;i.x(i.x()+(n-t))}break;case Ml.上对齐:{const t=a;i.y(i.y()+(n-t))}break;case Ml.下对齐:{const t=a+o;i.y(i.y()+(n-t))}}}this.render.updateHistory(),this.render.redraw([rc.name,Fl.name,Rl.name,Bl.name])}}r(Ac,"name","AlignTool");class kc{constructor(t){r(this,"render"),r(this,"linkCurrent"),this.render=t}pointsVisible(t,e){var n;if(!this.render.config.readonly){const r=e??this.render.layer;for(const e of[...["asset","sub-asset"].includes(r.name())?[r]:[],...r.find(".asset"),...r.find(".sub-asset")]){const n=e.getAttr("points")??[];e.setAttrs({points:n.map(e=>({...e,visible:t}))})}(null==(n=this.render.draws[Fl.name])?void 0:n.state.linkManualing)||this.render.redraw([Fl.name,Rl.name,Bl.name])}}remove(t){const e=t??this.linkCurrent;if(e){const{groupId:t,pointId:n,pairId:r}=e.getAttrs();if(t&&n&&r){const e=this.render.layer.findOne(`#${t}`);if(e){const t=(e.getAttr("points")??[]).find(t=>t.id===n);if(t){const n=(t.pairs??[]).findIndex(t=>t.id===r);if(n>-1){const r=t.pairs.splice(n,1)[0];e.attrs.manualPointsMap&&e.attrs.manualPointsMap[r.id]&&e.setAttr("manualPointsMap",{...e.attrs.manualPointsMap,[r.id]:void 0}),this.render.redraw([Fl.name,Rl.name,Bl.name])}}}}}}jsonIdCover(t){let e=[...t];const n=new Map;for(;e.length>0;){const t=e.shift();if(t){if(Array.isArray(t.attrs.points))for(const e of t.attrs.points){if(Array.isArray(e.pairs))for(const t of e.pairs)t.from.groupId&&!n.has(t.from.groupId)&&n.set(t.from.groupId,"g:"+Nl()),t.to.groupId&&!n.has(t.to.groupId)&&n.set(t.to.groupId,"g:"+Nl()),t.from.pointId&&!n.has(t.from.pointId)&&n.set(t.from.pointId,"p:"+Nl()),t.to.pointId&&!n.has(t.to.pointId)&&n.set(t.to.pointId,"p:"+Nl());e.id&&(n.has(e.id)||n.set(e.id,"p:"+Nl())),e.groupId&&(n.has(e.groupId)||n.set(e.groupId,"g:"+Nl()))}t.attrs.id&&(n.has(t.attrs.id)||n.set(t.attrs.id,"n:"+Nl())),Array.isArray(t.children)&&e.push(...t.children)}}for(e=[...t];e.length>0;){const t=e.shift();if(t){if(n.has(t.attrs.id)&&(t.attrs.id=n.get(t.attrs.id)),Array.isArray(t.attrs.points))for(const e of t.attrs.points){if(Array.isArray(e.pairs))for(const t of e.pairs)t.disabled=!0,t.id&&(t.id="pr:"+Nl()),n.has(t.from.groupId)&&(t.from.groupId=n.get(t.from.groupId)),n.has(t.to.groupId)&&(t.to.groupId=n.get(t.to.groupId)),n.has(t.from.pointId)&&(t.from.pointId=n.get(t.from.pointId)),n.has(t.to.pointId)&&(t.to.pointId=n.get(t.to.pointId));if(n.has(e.id)){const r=t.children.find(t=>t.attrs.id===e.id);e.id=n.get(e.id),r&&(r.attrs.id=e.id)}n.has(e.groupId)&&(e.groupId=n.get(e.groupId))}Array.isArray(t.children)&&e.push(...t.children)}}}groupIdCover(t){const e=t.id(),n=t.find(".sub-asset");for(;n.length>0;){const t=n.shift();if(t){const r=t.attrs.points;if(Array.isArray(r))for(const t of r){t.rawGroupId=t.groupId,t.groupId=e;for(const n of t.pairs)n.from.rawGroupId=n.from.groupId,n.from.groupId=e,n.to.rawGroupId=n.to.groupId,n.to.groupId=e}n.push(...t.find(".sub-asset"))}}}select(t){this.render.selectionTool.selectingClear(),this.linkCurrent=t,this.render.emit("link-selection-change",this.linkCurrent),this.render.redraw([Fl.name,Rl.name])}selectingClear(){this.linkCurrent=void 0,this.render.emit("link-selection-change",void 0),this.render.redraw([Fl.name,Rl.name])}}r(kc,"name","LinkTool");class jc{constructor(t){r(this,"render"),r(this,"alignLines",[]),r(this,"attractPoint",t=>{this.alignLinesClear();const n=this.render.getStageState();let r=t.x,i=t.y,o=!1,s=null,a=null;if(!this.render.config.readonly&&this.render.config.attractNode){const t=[{value:this.render.toStageValue(r-n.x)}],h=[{value:this.render.toStageValue(i-n.y)}];let d=1/0,u=[],l=1/0,c=[];for(let e=0;e<t.length-1;e++)if(void 0===t[e].id&&void 0!==t[e+1].id||void 0!==t[e].id&&void 0===t[e+1].id){const n=Math.abs(t[e].value-t[e+1].value);n<d?(d=n,u=[[t[e],t[e+1]]]):n===d&&u.push([t[e],t[e+1]])}for(let e=0;e<h.length-1;e++)if(void 0===h[e].id&&void 0!==h[e+1].id||void 0!==h[e].id&&void 0===h[e+1].id){const t=Math.abs(h[e].value-h[e+1].value);t<l?(l=t,c=[[h[e],h[e+1]]]):t===l&&c.push([h[e],h[e+1]])}if(u[0]&&Math.abs(u[0][0].value-u[0][1].value)<this.render.bgSize/2&&(s=u[0]),c[0]&&Math.abs(c[0][0].value-c[0][1].value)<this.render.bgSize/2&&(a=c[0]),2===(null==s?void 0:s.length)){for(const r of u){const t=r.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[t.value,this.render.toStageValue(-n.y)],[t.value,this.render.toStageValue(this.render.stage.height()-n.y)]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=s.find(t=>void 0===t.id),i=s.find(t=>void 0!==t.id);t&&i&&(r-=this.render.toBoardValue(t.value-i.value),o=!0)}if(2===(null==a?void 0:a.length)){for(const i of c){const t=i.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[this.render.toStageValue(-n.x),t.value],[this.render.toStageValue(this.render.stage.width()-n.x),t.value]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=a.find(t=>void 0===t.id),r=a.find(t=>void 0!==t.id);t&&r&&(i-=this.render.toBoardValue(t.value-r.value),o=!0)}}if(!this.render.config.readonly&&this.render.config.attractBg){if(null===s){const t=this.render.toStageValue(r-n.x),e=Math.round(t/this.render.bgSize)*this.render.bgSize,i=Math.abs(t-e),s=this.render.toStageValue(r-n.x),a=Math.round(s/this.render.bgSize)*this.render.bgSize,h=Math.abs(s-a),d=n.width,u=Math.abs(s-d);for(const l of[{type:"leftX",value:i},{type:"rightX",value:h},{type:"stageRightX",value:u}].sort((t,e)=>t.value-e.value))if(l.value<5){"stageRightX"===l.type?r=this.render.toBoardValue(d)+n.x:"leftX"===l.type?r=this.render.toBoardValue(e)+n.x:"rightX"===l.type&&(r=this.render.toBoardValue(a)+n.x),o=!0;break}}if(null===a){const t=this.render.toStageValue(i-n.y),e=Math.round(t/this.render.bgSize)*this.render.bgSize,r=Math.abs(t-e),s=this.render.toStageValue(i-n.y),a=Math.round(s/this.render.bgSize)*this.render.bgSize,h=Math.abs(s-a),d=n.height,u=Math.abs(s-d);for(const l of[{type:"topY",value:r},{type:"bottomY",value:h},{type:"stageBottomY",value:u}].sort((t,e)=>t.value-e.value))if(l.value<5){"stageBottomY"===l.type?i=this.render.toBoardValue(d)+n.y:"topY"===l.type?i=this.render.toBoardValue(e)+n.y:"bottomY"===l.type&&(i=this.render.toBoardValue(a)+n.y),o=!0;break}}}return{pos:{x:r,y:i},isAttract:o}}),r(this,"attractTransformer",t=>{this.alignLinesClear();const n=this.render.getStageState(),r=this.render.transformer.width(),i=this.render.transformer.height();let o=t.x,s=t.y,a=!1,h=null,d=null;if(!this.render.config.readonly&&this.render.config.attractNode){const{sortX:r,sortY:i}=this.getSortItems(t);let u=1/0,l=[],c=1/0,f=[];for(let t=0;t<r.length-1;t++)if(void 0===r[t].id&&void 0!==r[t+1].id||void 0!==r[t].id&&void 0===r[t+1].id){const e=Math.abs(r[t].value-r[t+1].value);e<u?(u=e,l=[[r[t],r[t+1]]]):e===u&&l.push([r[t],r[t+1]])}for(let t=0;t<i.length-1;t++)if(void 0===i[t].id&&void 0!==i[t+1].id||void 0!==i[t].id&&void 0===i[t+1].id){const e=Math.abs(i[t].value-i[t+1].value);e<c?(c=e,f=[[i[t],i[t+1]]]):e===c&&f.push([i[t],i[t+1]])}if(l[0]&&Math.abs(l[0][0].value-l[0][1].value)<this.render.bgSize/2&&(h=l[0]),f[0]&&Math.abs(f[0][0].value-f[0][1].value)<this.render.bgSize/2&&(d=f[0]),2===(null==h?void 0:h.length)){for(const i of l){const t=i.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[t.value,this.render.toStageValue(-n.y)],[t.value,this.render.toStageValue(this.render.stage.height()-n.y)]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=h.find(t=>void 0===t.id),r=h.find(t=>void 0!==t.id);t&&r&&(o-=this.render.toBoardValue(t.value-r.value),a=!0)}if(2===(null==d?void 0:d.length)){for(const i of f){const t=i.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[this.render.toStageValue(-n.x),t.value],[this.render.toStageValue(this.render.stage.width()-n.x),t.value]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=d.find(t=>void 0===t.id),r=d.find(t=>void 0!==t.id);t&&r&&(s-=this.render.toBoardValue(t.value-r.value),a=!0)}}if(!this.render.config.readonly&&this.render.config.attractBg){if(null===h){const t=this.render.toStageValue(o-n.x),e=Math.round(t/this.render.bgSize)*this.render.bgSize,i=Math.abs(t-e),s=this.render.toStageValue(o+r-n.x),h=Math.round(s/this.render.bgSize)*this.render.bgSize,d=Math.abs(s-h),u=n.width,l=Math.abs(s-u);for(const c of[{type:"leftX",value:i},{type:"rightX",value:d},{type:"stageRightX",value:l}].sort((t,e)=>t.value-e.value))if(c.value<5){"stageRightX"===c.type?o=this.render.toBoardValue(u)+n.x-r:"leftX"===c.type?o=this.render.toBoardValue(e)+n.x:"rightX"===c.type&&(o=this.render.toBoardValue(h)+n.x-r),a=!0;break}}if(null===d){const t=this.render.toStageValue(s-n.y),e=Math.round(t/this.render.bgSize)*this.render.bgSize,r=Math.abs(t-e),o=this.render.toStageValue(s+i-n.y),h=Math.round(o/this.render.bgSize)*this.render.bgSize,d=Math.abs(o-h),u=n.height,l=Math.abs(o-u);for(const c of[{type:"topY",value:r},{type:"bottomY",value:d},{type:"stageBottomY",value:l}].sort((t,e)=>t.value-e.value))if(c.value<5){"stageBottomY"===c.type?s=this.render.toBoardValue(u)+n.y-i:"topY"===c.type?s=this.render.toBoardValue(e)+n.y:"bottomY"===c.type&&(s=this.render.toBoardValue(h)+n.y-i),a=!0;break}}}return{pos:{x:o,y:s},isAttract:a}}),this.render=t}alignLinesClear(){for(const t of this.alignLines)t.destroy();this.alignLines=[]}getSortItems(t){const e=this.render.getStageState(),n=[],r=[];n.push({value:this.render.toStageValue(t.x-e.x)},{value:this.render.toStageValue(t.x-e.x+t.width/2)},{value:this.render.toStageValue(t.x-e.x+t.width)}),r.push({value:this.render.toStageValue(t.y-e.y)},{value:this.render.toStageValue(t.y-e.y+t.height/2)},{value:this.render.toStageValue(t.y-e.y+t.height)});const i=this.render.selectionTool.selectingNodes.map(t=>t._id),o=this.render.layer.find(".asset").filter(t=>!i.includes(t._id));for(const s of o){const t=s.getClientRect();n.push({id:s._id,value:this.render.toStageValue(t.x-e.x)},{id:s._id,value:this.render.toStageValue(t.x-e.x+t.width/2)},{id:s._id,value:this.render.toStageValue(t.x-e.x+t.width)}),r.push({id:s._id,value:this.render.toStageValue(t.y-e.y)},{id:s._id,value:this.render.toStageValue(t.y-e.y+t.height/2)},{id:s._id,value:this.render.toStageValue(t.y-e.y+t.height)})}return n.sort((t,e)=>t.value-e.value),r.sort((t,e)=>t.value-e.value),{sortX:n,sortY:r}}}r(jc,"name","AttractTool");const Ic=class t{constructor(t,n){var i;r(this,"stage"),r(this,"layer",new e.Layer({id:"main"})),r(this,"layerFloor",new e.Layer),r(this,"layerCover",new e.Layer({id:"cover"})),r(this,"config"),r(this,"draws",{}),r(this,"assetTool"),r(this,"selectionTool"),r(this,"copyTool"),r(this,"positionTool"),r(this,"zIndexTool"),r(this,"importExportTool"),r(this,"alignTool"),r(this,"linkTool"),r(this,"attractTool"),r(this,"groupTransformer",new e.Group),r(this,"transformer",new e.Transformer({shouldOverdrawWholeArea:!0,borderDash:[4,4],padding:1,rotationSnaps:[0,45,90,135,180,225,270,315,360],flipEnabled:!1})),r(this,"selectRect",new e.Rect({id:"selectRect",fill:"rgba(0,0,255,0.1)",visible:!1})),r(this,"handlers",{}),r(this,"bgSize",20),r(this,"rulerSize",0),r(this,"previewSize",.2),r(this,"pointSize",6),r(this,"history",[]),r(this,"historyIndex",-1),r(this,"debug",!1),r(this,"graphType"),r(this,"texting",!1),r(this,"emitter",{all:i=i||new Map,on:function(t,e){var n=i.get(t);n?n.push(e):i.set(t,[e])},off:function(t,e){var n=i.get(t);n&&(e?n.splice(n.indexOf(e)>>>0,1):i.set(t,[]))},emit:function(t,e){var n=i.get(t);n&&n.slice().map(function(t){t(e)}),(n=i.get("*"))&&n.slice().map(function(n){n(t,e)})}}),r(this,"on"),r(this,"off"),r(this,"emit"),this.config=n,this.on=this.emitter.on.bind(this.emitter),this.off=this.emitter.off.bind(this.emitter),this.emit=this.emitter.emit.bind(this.emitter),this.config.showRuler&&(this.rulerSize=40),this.stage=new e.Stage({container:t,x:this.rulerSize,y:this.rulerSize,width:n.width,height:n.height}),this.groupTransformer.add(this.transformer),this.groupTransformer.add(this.selectRect),this.layerCover.add(this.groupTransformer),this.config.showBg&&(this.draws[El.name]=new El(this,this.layerFloor,{size:this.bgSize,readonly:this.config.readonly??!1})),this.draws[Fl.name]=new Fl(this,this.layerCover,{size:this.pointSize}),this.draws[Xl.name]=new Xl(this,this.layerCover,{size:this.pointSize}),!this.config.readonly&&this.config.showRuler&&(this.draws[Rl.name]=new Rl(this,this.layerCover,{size:this.rulerSize})),!this.config.readonly&&this.config.showRefLine&&(this.draws[Ll.name]=new Ll(this,this.layerCover,{padding:this.rulerSize})),this.config.showContextmenu&&(this.draws[Wl.name]=new Wl(this,this.layerCover,{})),!this.config.readonly&&this.config.showPreview&&(this.draws[Bl.name]=new Bl(this,this.layerCover,{size:this.previewSize})),this.draws[rc.name]=new rc(this,this.layerCover,{}),this.assetTool=new gc(this),this.selectionTool=new pc(this),this.copyTool=new yc(this),this.positionTool=new mc(this),this.zIndexTool=new vc(this),this.importExportTool=new _c(this),this.alignTool=new Ac(this),this.linkTool=new kc(this),this.attractTool=new jc(this),this.handlers[ic.name]=new ic(this),this.handlers[oc.name]=new oc(this),this.config.readonly||(this.handlers[sc.name]=new sc(this),this.handlers[ac.name]=new ac(this),this.handlers[hc.name]=new hc(this),this.handlers[uc.name]=new uc(this),this.handlers[lc.name]=new lc(this),this.handlers[cc.name]=new cc(this)),!this.config.readonly&&this.config.showRefLine&&void 0!==this.draws[Ll.name]&&(this.handlers[Ll.name]=this.draws[Ll.name]),this.handlers[dc.name]=new dc(this),this.init(),this.config.configJson&&this.importExportTool.restore(this.config.configJson)}changeDebug(t){var e,n,r,i,o,s;return this.debug=t,this.emit("debug-change",this.debug),null==(e=this.draws[Fl.name])||e.init(),null==(n=this.draws[Xl.name])||n.init(),null==(r=this.draws[Rl.name])||r.init(),null==(i=this.draws[Ll.name])||i.init(),null==(o=this.draws[Wl.name])||o.init(),null==(s=this.draws[Bl.name])||s.init(),this.debug}init(){var t,e,n,r,i,o,s;this.stage.add(this.layerFloor),null==(t=this.draws[El.name])||t.init(),this.stage.add(this.layer),this.stage.add(this.layerCover),null==(e=this.draws[Fl.name])||e.init(),null==(n=this.draws[Xl.name])||n.init(),null==(r=this.draws[Rl.name])||r.init(),null==(i=this.draws[Ll.name])||i.init(),null==(o=this.draws[Wl.name])||o.init(),null==(s=this.draws[Bl.name])||s.init(),this.eventBind(),this.updateHistory()}resize(t,e){this.stage.setAttrs({width:t,height:e}),this.redraw()}remove(t){for(const n of t)if(n instanceof e.Transformer)this.remove(this.selectionTool.selectingNodes);else{const t=n.id();for(const e of this.layer.getChildren())if(e.id()!==t&&Array.isArray(e.attrs.points)){for(const n of e.attrs.points)Array.isArray(n.pairs)&&(e.attrs.manualPointsMap&&n.pairs.filter(e=>e.from.groupId===t||e.to.groupId===t).forEach(t=>{e.attrs.manualPointsMap[t.id]=void 0}),n.pairs=n.pairs.filter(e=>e.from.groupId!==t&&e.to.groupId!==t));e.setAttr("points",e.attrs.points)}n.destroy()}t.length>0&&(this.selectionTool.selectingClear(),this.linkTool.selectingClear(),this.updateHistory(),this.redraw())}prevHistory(){const t=this.history[this.historyIndex-1];t&&(this.importExportTool.restore(t,!0),this.historyIndex--,this.emit("history-change",{records:bt.clone(this.history),index:this.historyIndex}))}nextHistory(){const t=this.history[this.historyIndex+1];t&&(this.importExportTool.restore(t,!0),this.historyIndex++,this.emit("history-change",{records:bt.clone(this.history),index:this.historyIndex}))}updateHistory(){this.history.splice(this.historyIndex+1),this.history.push(this.importExportTool.save()),this.historyIndex=this.history.length-1,this.emit("history-change",{records:bt.clone(this.history),index:this.historyIndex})}eventBind(){var t,e;for(const r of["mousedown","mouseup","mousemove","wheel","contextmenu","pointerclick"])this.stage.on(r,t=>{var e,n,i,o,s,a,h,d,u;null==(e=null==t?void 0:t.evt)||e.preventDefault();for(const l in this.draws)null==(s=null==(o=null==(i=null==(n=this.draws[l])?void 0:n.handlers)?void 0:i.stage)?void 0:o[r])||s.call(o,t);for(const l in this.handlers)null==(u=null==(d=null==(h=null==(a=this.handlers[l])?void 0:a.handlers)?void 0:h.stage)?void 0:d[r])||u.call(d,t)});const n=this.stage.container();n.tabIndex=1,n.focus();for(const r of["mouseenter","dragenter","mousemove","mouseout","dragenter","dragover","drop","keydown","keyup"])n.addEventListener(r,t=>{var e,n,i,o,s,a,h,d;null==t||t.preventDefault(),["mouseenter","dragenter"].includes(r)&&this.stage.container().focus();for(const u in this.draws)null==(o=null==(i=null==(n=null==(e=this.draws[u])?void 0:e.handlers)?void 0:n.dom)?void 0:i[r])||o.call(i,t);for(const u in this.handlers)null==(d=null==(h=null==(a=null==(s=this.handlers[u])?void 0:s.handlers)?void 0:a.dom)?void 0:h[r])||d.call(h,t)});for(const r of["mousedown","transformstart","transform","transformend","dragstart","dragmove","dragend","mousemove","mouseleave","dblclick"])this.transformer.on(r,t=>{var e,n,i,o,s,a,h,d,u;null==(e=null==t?void 0:t.evt)||e.preventDefault();for(const l in this.draws)null==(s=null==(o=null==(i=null==(n=this.draws[l])?void 0:n.handlers)?void 0:i.transformer)?void 0:o[r])||s.call(o,t);for(const l in this.handlers)null==(u=null==(d=null==(h=null==(a=this.handlers[l])?void 0:a.handlers)?void 0:h.transformer)?void 0:d[r])||u.call(d,t)});(null==(e=null==(t=this.handlers[ac.name])?void 0:t.transformerConfig)?void 0:e.anchorDragBoundFunc)&&this.transformer.anchorDragBoundFunc(this.handlers[ac.name].transformerConfig.anchorDragBoundFunc)}getStageState(){return{width:this.stage.width()-this.rulerSize,height:this.stage.height()-this.rulerSize,scale:this.stage.scaleX(),x:this.stage.x(),y:this.stage.y()}}toStageValue(t){return t/this.stage.scaleX()}toBoardValue(t){return t*this.stage.scaleX()}ignore(t){return!(t instanceof e.Group)||this.ignoreSelect(t)||this.ignoreDraw(t)||this.ignoreLink(t)}ignoreSelect(t){return"selectRect"===t.id()||"hoverRect"===t.id()}ignoreDraw(t){return t.name()===El.name||t.name()===Rl.name||t.name()===Ll.name||t.name()===Wl.name||t.name()===Bl.name||t.name()===Fl.name||t.name()===Xl.name||t.name()===rc.name}ignoreLink(t){return"link-anchor"===t.name()||"linking-line"===t.name()||"link-point"===t.name()||"link-line"===t.name()||"link-manual-point"===t.name()}redraw(t){var e,n;const r=[El.name,rc.name,Fl.name,Xl.name,Rl.name,Ll.name,Bl.name,Wl.name];if(Array.isArray(t)&&!this.debug)for(const i of r)t.includes(i)&&(null==(e=this.draws[i])||e.draw());else for(const i of r)null==(n=this.draws[i])||n.draw()}changeDraggable(t){this.layer.children.forEach(e=>{e.draggable(t)})}changeGraphType(t){t&&(this.texting=!1,this.emit("texting-change",this.texting)),this.graphType=t,this.emit("graph-type-change",this.graphType),this.changeDraggable(!this.config.readonly&&void 0===this.graphType)}changeTexting(t){t&&(this.graphType=void 0,this.emit("graph-type-change",this.graphType)),this.texting=t,this.emit("texting-change",this.texting),document.body.style.cursor=this.texting?"text":"default"}getPageSettings(){return this.stage.attrs.pageSettings??{...t.PageSettingsDefault}}setPageSettings(t,e=!1){this.stage.setAttr("pageSettings",t),this.updateBackground(),e&&this.updateHistory()}getBackground(){var t;return null==(t=this.draws[El.name])?void 0:t.layer.findOne(`.${El.name}__background`)}updateBackground(){var t,e,n,r;const i=this.getBackground();i&&i.fill(this.getPageSettings().background??"transparent"),null==(t=this.draws[El.name])||t.draw(),null==(e=this.draws[rc.name])||e.draw(),null==(n=this.draws[Fl.name])||n.draw(),null==(r=this.draws[Bl.name])||r.draw()}getAssetSettings(e){const n=(null==e?void 0:e.attrs.assetSettings)??{...t.AssetSettingsDefault};return{...n,stroke:n.stroke||this.getPageSettings().stroke,strokeWidth:n.strokeWidth||this.getPageSettings().strokeWidth,fontSize:n.fontSize||this.getPageSettings().fontSize,textFill:n.textFill||this.getPageSettings().textFill,fill:n.fill||((null==e?void 0:e.attrs.assetType)===Cl.Graph?"transparent":this.getPageSettings().fill),x:parseFloat(((null==e?void 0:e.position().x)??0).toFixed(1)),y:parseFloat(((null==e?void 0:e.position().y)??0).toFixed(1)),rotation:parseFloat(((null==e?void 0:e.rotation())??0).toFixed(1)),tension:(null==e?void 0:e.attrs.assetType)===Cl.Graph&&(null==e?void 0:e.attrs.graphType)===Vl.Curve?n.tension:void 0}}setSvgXMLSettings(t,e){const n=t.match(/<(circle|ellipse|line|path|polygon|rect|text|textPath|tref|tspan)[^>/]*\/?>/g),r=/ stroke="([^"]*)"/,i=/ fill="([^"]*)"/;for(const o of n??[]){let n=o;e.stroke&&(n=r.test(o)?n.replace(r,` stroke="${e.stroke}"`):n.replace(/(<[^>/]*)(\/?>)/,`$1 stroke="${e.stroke}" $2`)),e.fill&&(n=i.test(o)?n.replace(i,` fill="${e.fill}"`):n.replace(/(<[^>/]*)(\/?>)/,`$1 fill="${e.fill}" $2`)),t=t.replace(o,n)}return t}rotatePoint({x:t,y:e},n){const r=Math.cos(n),i=Math.sin(n);return{x:t*r-e*i,y:e*r+t*i}}rotateAroundCenter(t,n){const r={x:-t.width()/2,y:-t.height()/2},i=this.rotatePoint(r,e.getAngle(t.rotation())),o=this.rotatePoint(r,e.getAngle(n)),s=o.x-i.x,a=o.y-i.y;t.rotation(n),t.x(t.x()+s),t.y(t.y()+a)}async setAssetSettings(t,n,r=!1){var i,o,s,a,h;if(t.setAttr("assetSettings",n),t instanceof e.Group){if(t.attrs.imageType===Ol.svg){const r=t.children[0];if(r instanceof e.Image&&r.attrs.svgXML){const t=await this.assetTool.loadSvgXML(this.setSvgXMLSettings(r.attrs.svgXML,n));null==(i=r.parent)||i.add(t),r.remove(),r.destroy(),t.zIndex(0)}}else if(t.attrs.assetType===Cl.Graph){const r=t.findOne(".graph");r instanceof e.Shape&&(r.strokeWidth(n.strokeWidth),r.stroke(n.stroke),r instanceof e.Arrow?r.fill(n.stroke):r.fill(n.fill),r instanceof e.Arrow&&(r.pointerAtBeginning(n.arrowStart),r.pointerAtEnding(n.arrowEnd)),r instanceof e.Arrow&&t.attrs.graphType===Vl.Curve&&r.tension(n.tension))}else if(t.attrs.assetType===Cl.Text){const r=t.findOne("Text"),i=t.findOne("Rect");if(r instanceof e.Text&&i instanceof e.Rect){let e=!1;r.fontSize()===n.fontSize&&r.text()===n.text||(e=!0),r.fill(n.textFill),r.fontSize(n.fontSize),r.text(n.text),i.fill(r.text().trim()?"":"rgba(0,0,0,0.1)"),i.width(Math.max(r.width(),n.fontSize)),i.height(Math.max(r.height(),n.fontSize)),e&&this.selectionTool.select([t])}}if(Math.abs(n.rotation-t.rotation())>=.1)this.rotateAroundCenter(t,n.rotation),this.emit("asset-position-change",[t]);else{const e=this.getAssetSettings(t);t.position({x:parseFloat(n.x.toFixed(1)),y:parseFloat(n.y.toFixed(1))}),n.x===e.x&&n.y===e.y||this.emit("asset-position-change",[t])}}r&&this.updateHistory(),null==(o=this.draws[El.name])||o.draw(),null==(s=this.draws[rc.name])||s.draw(),null==(a=this.draws[Fl.name])||a.draw(),null==(h=this.draws[Bl.name])||h.draw()}async setLinkSettings(t,e,n=!1){var r,i,o,s;const a=this.layer.findOne(`#${t.attrs.groupId}`);if(Array.isArray(null==a?void 0:a.attrs.points)){const n=(null==a?void 0:a.attrs.points).find(e=>e.id===t.attrs.pointId);if(n){const r=n.pairs.find(e=>e.id===t.attrs.pairId);r&&(r.style={...r.style,...e},a.setAttr("points",null==a?void 0:a.attrs.points))}}n&&this.updateHistory(),null==(r=this.draws[El.name])||r.draw(),null==(i=this.draws[rc.name])||i.draw(),null==(o=this.draws[Fl.name])||o.draw(),null==(s=this.draws[Bl.name])||s.draw()}getLinkSettings(e){let n;if(e){const t=this.layer.findOne(`#${e.attrs.groupId}`);if(Array.isArray(null==t?void 0:t.attrs.points)){const r=(null==t?void 0:t.attrs.points).find(t=>t.id===e.attrs.pointId);if(r){const t=r.pairs.find(t=>t.id===e.attrs.pairId);t&&(n=t.style)}}}const r=n??{...t.LinkSettingsDefault};return{...r,stroke:r.stroke||this.getPageSettings().linkStroke,strokeWidth:r.strokeWidth||this.getPageSettings().linkStrokeWidth}}};r(Ic,"PageSettingsDefault",{background:"transparent",stroke:"rgb(0,0,0)",strokeWidth:1,fill:"rgb(0,0,0)",linkStroke:"rgb(0,0,0)",linkStrokeWidth:1,fontSize:24,textFill:"rgb(0,0,0)"}),r(Ic,"AssetSettingsDefault",{stroke:"",strokeWidth:0,fill:"",arrowStart:!1,arrowEnd:!1,fontSize:0,textFill:"",text:"Text",x:0,y:0,rotation:0,tension:0}),r(Ic,"LinkSettingsDefault",{stroke:"",strokeWidth:0,arrowStart:!1,arrowEnd:!1,tension:0});let Tc=Ic;const Pc={Render:Tc};return t.Render=Tc,t.default=Pc,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),t}({},Konva);
24
24
  //# sourceMappingURL=webtopo.iife.js.map
package/webtopo.umd.js CHANGED
@@ -20,5 +20,5 @@ var vl,xl=4294967295,wl=Array.prototype,bl=Object.prototype.hasOwnProperty,Sl=a?
20
20
  * Kerry Liu
21
21
  *
22
22
  * Copyright (c) 2014 Gliffy Inc.
23
- */wc=bc,function(){var t,e,n,r,i;function o(t,e){var n,r=Object.keys(e);for(n=0;n<r.length;n++)t=t.replace(new RegExp("\\{"+r[n]+"\\}","gi"),e[r[n]]);return t}function s(t){var e,n,r;if(!t)throw new Error("cannot create a random attribute name for an undefined object");e="ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",n="";do{for(n="",r=0;r<12;r++)n+=e[Math.floor(51*Math.random())]}while(t[n]);return n}function a(t){var e={alphabetic:"alphabetic",hanging:"hanging",top:"text-before-edge",bottom:"text-after-edge",middle:"central"};return e[t]||e.alphabetic}i=function(t,e){var n,r,i,o={};for(t=t.split(","),e=e||10,n=0;n<t.length;n+=2)r="&"+t[n+1]+";",i=parseInt(t[n],e),o[r]="&#"+i+";";return o["\\xa0"]="&#160;",o}("50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,t9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro",32),t={strokeStyle:{svgAttr:"stroke",canvas:"#000000",svg:"none",apply:"stroke"},fillStyle:{svgAttr:"fill",canvas:"#000000",svg:null,apply:"fill"},lineCap:{svgAttr:"stroke-linecap",canvas:"butt",svg:"butt",apply:"stroke"},lineJoin:{svgAttr:"stroke-linejoin",canvas:"miter",svg:"miter",apply:"stroke"},miterLimit:{svgAttr:"stroke-miterlimit",canvas:10,svg:4,apply:"stroke"},lineWidth:{svgAttr:"stroke-width",canvas:1,svg:1,apply:"stroke"},globalAlpha:{svgAttr:"opacity",canvas:1,svg:1,apply:"fill stroke"},font:{canvas:"10px sans-serif"},shadowColor:{canvas:"#000000"},shadowOffsetX:{canvas:0},shadowOffsetY:{canvas:0},shadowBlur:{canvas:0},textAlign:{canvas:"start"},textBaseline:{canvas:"alphabetic"}},(n=function(t,e){this.__root=t,this.__ctx=e}).prototype.addColorStop=function(t,e){var n,r=this.__ctx.__createElement("stop");r.setAttribute("offset",t),-1!==e.indexOf("rgba")?(n=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi.exec(e),r.setAttribute("stop-color",o("rgb({r},{g},{b})",{r:n[1],g:n[2],b:n[3]})),r.setAttribute("stop-opacity",n[4])):r.setAttribute("stop-color",e),this.__root.appendChild(r)},r=function(t,e){this.__root=t,this.__ctx=e},e=function(t){var n,r={width:500,height:500,enableMirroring:!1};if(arguments.length>1?((n=r).width=arguments[0],n.height=arguments[1]):n=t||r,!(this instanceof e))return new e(n);this.width=n.width||r.width,this.height=n.height||r.height,this.enableMirroring=void 0!==n.enableMirroring?n.enableMirroring:r.enableMirroring,this.canvas=this,this.__document=n.document||document,this.__canvas=this.__document.createElement("canvas"),this.__ctx=this.__canvas.getContext("2d"),this.__setDefaultStyles(),this.__stack=[this.__getStyleState()],this.__groupStack=[],this.__root=this.__document.createElementNS("http://www.w3.org/2000/svg","svg"),this.__root.setAttribute("version",1.1),this.__root.setAttribute("xmlns","http://www.w3.org/2000/svg"),this.__root.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink"),this.__root.setAttribute("width",this.width),this.__root.setAttribute("height",this.height),this.__ids={},this.__defs=this.__document.createElementNS("http://www.w3.org/2000/svg","defs"),this.__root.appendChild(this.__defs),this.__currentElement=this.__document.createElementNS("http://www.w3.org/2000/svg","g"),this.__root.appendChild(this.__currentElement)},e.prototype.__createElement=function(t,e,n){void 0===e&&(e={});var r,i,o=this.__document.createElementNS("http://www.w3.org/2000/svg",t),s=Object.keys(e);for(n&&(o.setAttribute("fill","none"),o.setAttribute("stroke","none")),r=0;r<s.length;r++)i=s[r],o.setAttribute(i,e[i]);return o},e.prototype.__setDefaultStyles=function(){var e,n,r=Object.keys(t);for(e=0;e<r.length;e++)this[n=r[e]]=t[n].canvas},e.prototype.__applyStyleState=function(t){var e,n,r=Object.keys(t);for(e=0;e<r.length;e++)this[n=r[e]]=t[n]},e.prototype.__getStyleState=function(){var e,n,r={},i=Object.keys(t);for(e=0;e<i.length;e++)r[n=i[e]]=this[n];return r},e.prototype.__applyStyleToCurrentElement=function(e){var i,s,a,h,d,u=Object.keys(t);for(i=0;i<u.length;i++)if(s=t[u[i]],a=this[u[i]],s.apply)if(-1!==s.apply.indexOf("fill")&&a instanceof r){if(a.__ctx)for(;a.__ctx.__defs.childNodes.length;)h=a.__ctx.__defs.childNodes[0].getAttribute("id"),this.__ids[h]=h,this.__defs.appendChild(a.__ctx.__defs.childNodes[0]);this.__currentElement.setAttribute("fill",o("url(#{id})",{id:a.__root.getAttribute("id")}))}else-1!==s.apply.indexOf("fill")&&a instanceof n?this.__currentElement.setAttribute("fill",o("url(#{id})",{id:a.__root.getAttribute("id")})):-1!==s.apply.indexOf(e)&&s.svg!==a&&("stroke"!==s.svgAttr&&"fill"!==s.svgAttr||-1===a.indexOf("rgba")?this.__currentElement.setAttribute(s.svgAttr,a):(d=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi.exec(a),this.__currentElement.setAttribute(s.svgAttr,o("rgb({r},{g},{b})",{r:d[1],g:d[2],b:d[3]})),this.__currentElement.setAttribute(s.svgAttr+"-opacity",d[4])))},e.prototype.__closestGroupOrSvg=function(t){return"g"===(t=t||this.__currentElement).nodeName||"svg"===t.nodeName?t:this.__closestGroupOrSvg(t.parentNode)},e.prototype.getSerializedSvg=function(t){var e,n,r,o,s,a=(new XMLSerializer).serializeToString(this.__root);if(/xmlns="http:\/\/www\.w3\.org\/2000\/svg".+xmlns="http:\/\/www\.w3\.org\/2000\/svg/gi.test(a)&&(a=a.replace('xmlns="http://www.w3.org/2000/svg','xmlns:xlink="http://www.w3.org/1999/xlink')),t)for(e=Object.keys(i),n=0;n<e.length;n++)r=e[n],o=i[r],(s=new RegExp(r,"gi")).test(a)&&(a=a.replace(s,o));return a},e.prototype.getSvg=function(){return this.__root},e.prototype.save=function(){var t=this.__createElement("g"),e=this.__closestGroupOrSvg();this.__groupStack.push(e),e.appendChild(t),this.__currentElement=t,this.__stack.push(this.__getStyleState())},e.prototype.restore=function(){this.__currentElement=this.__groupStack.pop();var t=this.__stack.pop();this.__applyStyleState(t)},e.prototype.__addTransform=function(t){var e=this.__closestGroupOrSvg();if(e.childNodes.length>0){var n=this.__createElement("g");e.appendChild(n),this.__currentElement=n}var r=this.__currentElement.getAttribute("transform");r?r+=" ":r="",r+=t,this.__currentElement.setAttribute("transform",r)},e.prototype.scale=function(t,e){void 0===e&&(e=t),this.__addTransform(o("scale({x},{y})",{x:t,y:e}))},e.prototype.rotate=function(t){var e=180*t/Math.PI;this.__addTransform(o("rotate({angle},{cx},{cy})",{angle:e,cx:0,cy:0}))},e.prototype.translate=function(t,e){this.__addTransform(o("translate({x},{y})",{x:t,y:e}))},e.prototype.transform=function(t,e,n,r,i,s){this.__addTransform(o("matrix({a},{b},{c},{d},{e},{f})",{a:t,b:e,c:n,d:r,e:i,f:s}))},e.prototype.beginPath=function(){var t;this.__currentDefaultPath="",this.__currentPosition={},t=this.__createElement("path",{},!0),this.__closestGroupOrSvg().appendChild(t),this.__currentElement=t},e.prototype.__applyCurrentDefaultPath=function(){if("path"!==this.__currentElement.nodeName)throw new Error("Attempted to apply path command to node "+this.__currentElement.nodeName);var t=this.__currentDefaultPath;this.__currentElement.setAttribute("d",t)},e.prototype.__addPathCommand=function(t){this.__currentDefaultPath+=" ",this.__currentDefaultPath+=t},e.prototype.moveTo=function(t,e){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.__currentPosition={x:t,y:e},this.__addPathCommand(o("M {x} {y}",{x:t,y:e}))},e.prototype.closePath=function(){this.__addPathCommand("Z")},e.prototype.lineTo=function(t,e){this.__currentPosition={x:t,y:e},this.__currentDefaultPath.indexOf("M")>-1?this.__addPathCommand(o("L {x} {y}",{x:t,y:e})):this.__addPathCommand(o("M {x} {y}",{x:t,y:e}))},e.prototype.bezierCurveTo=function(t,e,n,r,i,s){this.__currentPosition={x:i,y:s},this.__addPathCommand(o("C {cp1x} {cp1y} {cp2x} {cp2y} {x} {y}",{cp1x:t,cp1y:e,cp2x:n,cp2y:r,x:i,y:s}))},e.prototype.quadraticCurveTo=function(t,e,n,r){this.__currentPosition={x:n,y:r},this.__addPathCommand(o("Q {cpx} {cpy} {x} {y}",{cpx:t,cpy:e,x:n,y:r}))};var h=function(t){var e=Math.sqrt(t[0]*t[0]+t[1]*t[1]);return[t[0]/e,t[1]/e]};e.prototype.arcTo=function(t,e,n,r,i){var o=this.__currentPosition&&this.__currentPosition.x,s=this.__currentPosition&&this.__currentPosition.y;if(void 0!==o&&void 0!==s){if(i<0)throw new Error("IndexSizeError: The radius provided ("+i+") is negative.");if(o===t&&s===e||t===n&&e===r||0===i)this.lineTo(t,e);else{var a=h([o-t,s-e]),d=h([n-t,r-e]);if(a[0]*d[1]!==a[1]*d[0]){var u=a[0]*d[0]+a[1]*d[1],l=Math.acos(Math.abs(u)),c=h([a[0]+d[0],a[1]+d[1]]),f=i/Math.sin(l/2),g=t+f*c[0],p=e+f*c[1],y=[-a[1],a[0]],m=[d[1],-d[0]],v=function(t){var e=t[0];return t[1]>=0?Math.acos(e):-Math.acos(e)},x=v(y),w=v(m);this.lineTo(g+y[0]*i,p+y[1]*i),this.arc(g,p,i,x,w)}else this.lineTo(t,e)}}},e.prototype.stroke=function(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","fill stroke markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("stroke")},e.prototype.fill=function(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","stroke fill markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("fill")},e.prototype.rect=function(t,e,n,r){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.moveTo(t,e),this.lineTo(t+n,e),this.lineTo(t+n,e+r),this.lineTo(t,e+r),this.lineTo(t,e),this.closePath()},e.prototype.fillRect=function(t,e,n,r){var i;i=this.__createElement("rect",{x:t,y:e,width:n,height:r},!0),this.__closestGroupOrSvg().appendChild(i),this.__currentElement=i,this.__applyStyleToCurrentElement("fill")},e.prototype.strokeRect=function(t,e,n,r){var i;i=this.__createElement("rect",{x:t,y:e,width:n,height:r},!0),this.__closestGroupOrSvg().appendChild(i),this.__currentElement=i,this.__applyStyleToCurrentElement("stroke")},e.prototype.clearRect=function(t,e,n,r){var i,o=this.__closestGroupOrSvg();i=this.__createElement("rect",{x:t,y:e,width:n,height:r,fill:"#FFFFFF"},!0),o.appendChild(i)},e.prototype.createLinearGradient=function(t,e,r,i){var o=this.__createElement("linearGradient",{id:s(this.__ids),x1:t+"px",x2:r+"px",y1:e+"px",y2:i+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(o),new n(o,this)},e.prototype.createRadialGradient=function(t,e,r,i,o,a){var h=this.__createElement("radialGradient",{id:s(this.__ids),cx:i+"px",cy:o+"px",r:a+"px",fx:t+"px",fy:e+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(h),new n(h,this)},e.prototype.__parseFont=function(){var t=/^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-,\"\sa-z]+?)\s*$/i.exec(this.font),e={style:t[1]||"normal",size:t[4]||"10px",family:t[6]||"sans-serif",weight:t[3]||"normal",decoration:t[2]||"normal",href:null};return"underline"===this.__fontUnderline&&(e.decoration="underline"),this.__fontHref&&(e.href=this.__fontHref),e},e.prototype.__wrapTextLink=function(t,e){if(t.href){var n=this.__createElement("a");return n.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t.href),n.appendChild(e),n}return e},e.prototype.__applyText=function(t,e,n,r){var i,o,s=this.__parseFont(),h=this.__closestGroupOrSvg(),d=this.__createElement("text",{"font-family":s.family,"font-size":s.size,"font-style":s.style,"font-weight":s.weight,"text-decoration":s.decoration,x:e,y:n,"text-anchor":(i=this.textAlign,o={left:"start",right:"end",center:"middle",start:"start",end:"end"},o[i]||o.start),"dominant-baseline":a(this.textBaseline)},!0);d.appendChild(this.__document.createTextNode(t)),this.__currentElement=d,this.__applyStyleToCurrentElement(r),h.appendChild(this.__wrapTextLink(s,d))},e.prototype.fillText=function(t,e,n){this.__applyText(t,e,n,"fill")},e.prototype.strokeText=function(t,e,n){this.__applyText(t,e,n,"stroke")},e.prototype.measureText=function(t){return this.__ctx.font=this.font,this.__ctx.measureText(t)},e.prototype.arc=function(t,e,n,r,i,s){if(r!==i){(r%=2*Math.PI)==(i%=2*Math.PI)&&(i=(i+2*Math.PI-.001*(s?-1:1))%(2*Math.PI));var a=t+n*Math.cos(i),h=e+n*Math.sin(i),d=t+n*Math.cos(r),u=e+n*Math.sin(r),l=s?0:1,c=0,f=i-r;f<0&&(f+=2*Math.PI),c=s?f>Math.PI?0:1:f>Math.PI?1:0,this.lineTo(d,u),this.__addPathCommand(o("A {rx} {ry} {xAxisRotation} {largeArcFlag} {sweepFlag} {endX} {endY}",{rx:n,ry:n,xAxisRotation:0,largeArcFlag:c,sweepFlag:l,endX:a,endY:h})),this.__currentPosition={x:a,y:h}}},e.prototype.clip=function(){var t=this.__closestGroupOrSvg(),e=this.__createElement("clipPath"),n=s(this.__ids),r=this.__createElement("g");t.removeChild(this.__currentElement),e.setAttribute("id",n),e.appendChild(this.__currentElement),this.__defs.appendChild(e),t.setAttribute("clip-path",o("url(#{id})",{id:n})),t.appendChild(r),this.__currentElement=r},e.prototype.drawImage=function(){var t,n,r,i,o,s,a,h,d,u,l,c,f,g,p=Array.prototype.slice.call(arguments),y=p[0],m=0,v=0;if(3===p.length)t=p[1],n=p[2],r=o=y.width,i=s=y.height;else if(5===p.length)t=p[1],n=p[2],r=p[3],i=p[4],o=y.width,s=y.height;else{if(9!==p.length)throw new Error("Inavlid number of arguments passed to drawImage: "+arguments.length);m=p[1],v=p[2],o=p[3],s=p[4],t=p[5],n=p[6],r=p[7],i=p[8]}if(a=this.__closestGroupOrSvg(),l=this.__currentElement,y instanceof e){for(d=(h=y.getSvg()).childNodes[0];d.childNodes.length;)g=d.childNodes[0].getAttribute("id"),this.__ids[g]=g,this.__defs.appendChild(d.childNodes[0]);u=h.childNodes[1],a.appendChild(u),this.__currentElement=u,this.translate(t,n),this.__currentElement=l}else"CANVAS"!==y.nodeName&&"IMG"!==y.nodeName||((c=this.__createElement("image")).setAttribute("width",r),c.setAttribute("height",i),c.setAttribute("preserveAspectRatio","none"),(m||v||o!==y.width||s!==y.height)&&((f=this.__document.createElement("canvas")).width=r,f.height=i,f.getContext("2d").drawImage(y,m,v,o,s,0,0,r,i),y=f),c.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===y.nodeName?y.toDataURL():y.getAttribute("src")),a.appendChild(c),this.__currentElement=c,this.translate(t,n),this.__currentElement=l)},e.prototype.createPattern=function(t,n){var i,o=this.__document.createElementNS("http://www.w3.org/2000/svg","pattern"),a=s(this.__ids);return o.setAttribute("id",a),o.setAttribute("width",t.width),o.setAttribute("height",t.height),"CANVAS"===t.nodeName||"IMG"===t.nodeName?((i=this.__document.createElementNS("http://www.w3.org/2000/svg","image")).setAttribute("width",t.width),i.setAttribute("height",t.height),i.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===t.nodeName?t.toDataURL():t.getAttribute("src")),o.appendChild(i),this.__defs.appendChild(o)):t instanceof e&&(o.appendChild(t.__root.childNodes[1]),this.__defs.appendChild(o)),new r(o,this)},e.prototype.drawFocusRing=function(){},e.prototype.createImageData=function(){},e.prototype.getImageData=function(){},e.prototype.putImageData=function(){},e.prototype.globalCompositeOperation=function(){},e.prototype.setTransform=function(){},"object"==typeof window&&(window.C2S=e),wc.exports=e}();const Sc=xc(bc.exports);Sc.prototype.__applyCurrentDefaultPath=function(){if("g"===this.__currentElement.nodeName){const t=this.__currentElement.querySelector("g");if(t){const e=t.getAttribute("transform");if(e){const t=e.match(/scale\(([^),]+),([^)]+)\)/);if(t){const[e,n]=[parseFloat(t[1]),parseFloat(t[2])];let r=this.__currentDefaultPath;const i=/A ([^ ]+) ([^ ]+) /,o=r.match(i);if(o){const[t,s]=[parseFloat(o[1]),parseFloat(o[2])];r=r.replace(i,`A ${t*e} ${s*n} `);const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("d",r),a.setAttribute("fill","none"),this.__currentElement.append(a)}}}else{const t=this.__currentDefaultPath,e=document.createElementNS("http://www.w3.org/2000/svg","path");e.setAttribute("d",t),e.setAttribute("fill","none"),this.__currentElement.append(e)}}return}if("path"!==this.__currentElement.nodeName)throw new Error("Attempted to apply path command to node "+this.__currentElement.nodeName);{const t=this.__currentDefaultPath;this.__currentElement.setAttribute("d",t)}};class _c{constructor(t){r(this,"render"),this.render=t}getView(t=!1){const n=this.render.stage.clone(),r=n.find("#main")[0],i=n.find("#cover")[0],o=n.getChildren();if(n.removeChildren(),r&&i){let o=r.getChildren(t=>!this.render.ignore(t));for(const t of o){t.listening(!0),t.draggable(!this.render.config.readonly);for(const e of t.children)this.render.ignoreSelect(e)&&e.remove()}if(t){const t=i.children.find(t=>t.attrs.name===Fl.name);t&&(o=o.concat(t.children.filter(t=>"link-line"===t.attrs.name)))}const s=new e.Layer;s.add(...o),o=s.getChildren();for(const t of o)t.attrs.nodeMousedownPos&&t.setAttrs({opacity:n.attrs.lastOpacity??1});n.add(s),r.removeChildren(),i.removeChildren()}return o.forEach(t=>t.destroy()),n}save(){const t=this.getView(),e=t.toJSON();return t.destroy(),e}loadImage(t){return new Promise(e=>{const n=new Image;n.onload=()=>{e(n)},n.onerror=()=>{e(null)},n.src=t})}async restoreImage(t=[]){for(const n of t)if(n instanceof e.Group)await this.restoreImage(n.getChildren());else if(n instanceof e.Image)if(n.attrs.svgXML){const t=new Blob([n.attrs.svgXML],{type:"image/svg+xml"}),e=URL.createObjectURL(t),r=await this.loadImage(e);r&&n.image(r)}else if(n.attrs.gif){const t=await this.render.assetTool.loadGif(n.attrs.gif);t&&n.image(t.image())}else if(n.attrs.src){const t=await this.loadImage(n.attrs.src);t&&n.image(t)}}async restore(t,n=!1){try{this.render.emit("loading",!0),this.render.selectionTool.selectingClear(),this.render.linkTool.selectingClear(),this.render.layer.getChildren().forEach(t=>{t.destroy()}),this.render.layer.removeChildren();const r=document.createElement("div"),i=e.Node.create(t,r),o=i.getChildren()[0].getChildren();await this.restoreImage(o);for(const t of o)t.draggable(!this.render.config.readonly),t.off("mouseenter"),t.on("mouseenter",()=>{this.render.linkTool.pointsVisible(!0,t)}),t.add(new e.Rect({id:"hoverRect",width:t.width(),height:t.height(),fill:"rgba(0,255,0,0.3)",visible:!1})),t.off("mouseleave"),t.on("mouseleave",()=>{var e;this.render.linkTool.pointsVisible(!1,t),null==(e=t.findOne("#hoverRect"))||e.visible(!1)});this.render.layer.add(...o),this.render.stage.setAttr("pageSettings",i.attrs.pageSettings),this.render.emit("page-settings-change",this.render.getPageSettings()),this.render.updateBackground(),n||this.render.updateHistory(),this.render.linkTool.pointsVisible(!1),this.render.redraw([rc.name,Fl.name,Rl.name,Bl.name]),i.destroy()}catch(r){}finally{this.render.emit("loading",!1)}}getImage(t=1,n){const r=this.getAssetView(),i=new e.Layer,o=new e.Rect({listening:!1});o.setAttrs({x:0,y:0,width:r.width(),height:r.height(),fill:n??this.render.getPageSettings().background}),i.add(o);const s=r.getChildren();r.removeChildren(),r.add(i),r.add(s[0],...s.slice(1));const a=r.toDataURL({pixelRatio:t});return r.destroy(),a}getAssetImage(t=1,n){const r=this.getAssetView(),i=new e.Layer,o=new e.Rect({listening:!1});o.setAttrs({x:-r.x(),y:-r.y(),width:r.width(),height:r.height(),fill:n??this.render.getPageSettings().background}),i.add(o);const s=r.getChildren();r.removeChildren(),r.add(i),r.add(s[0],...s.slice(1));const a=r.toDataURL({pixelRatio:t});return r.destroy(),a}blobToBase64(t,e){return new Promise(n=>{const r=new File([t],"image",{type:e}),i=new FileReader;i.readAsDataURL(r),i.onload=function(){n(this.result??"")}})}parseSvgImage(t){return new Promise(e=>{t.length>0?Promise.all(t.map(t=>fetch(t))).then(t=>{Promise.all(t.map(t=>t.text())).then(t=>{e(t)})}):e([])})}parseOtherImage(t){return new Promise(e=>{t.length>0?Promise.all(t.map(t=>fetch(t))).then(t=>{Promise.all(t.map(t=>t.blob())).then(t=>{Promise.all(t.map(t=>this.blobToBase64(t,"image/*"))).then(t=>{e(t)})})}):e([])})}parseImage(t){return new Promise(e=>{const n=t.match(new RegExp('(?<=xlink:href=")blob:https?:\\/\\/[^"]+(?=")',"g"))??[],r=t.match(new RegExp('(?<=xlink:href=")(?<!blob:)[^"]+(?=")',"g"))??[];Promise.all([this.parseSvgImage(n),this.parseOtherImage(r)]).then(([i,o])=>{n.forEach((e,n)=>{var r;t=t.replace(new RegExp(`<image[^><]* xlink:href="${e}"[^><]*/>`),(null==(r=i[n].match(/<svg[^><]*>.*<\/svg>/))?void 0:r[0])??"")}),r.forEach((e,n)=>{t=t.replace(`"${e}"`,`"${o[n]}"`)}),e(t)})})}async getSvg(){const t=this.getAssetView(),e=t.children[0],n=e.canvas.context._context;if(n){const r=new Sc({ctx:n,...e.size()});e.canvas.context._context=r,e.draw();let i=r.getSerializedSvg();i=i.replace(/(<defs\/><g><rect fill=")([^"]+)(")/,`$1${this.render.getPageSettings().background}$3`);const o=await this.parseImage(i);return t.destroy(),o}return Promise.resolve('<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0"></svg>')}getAssetView(){const t=this.getView(!0),n=[...t.getChildren()[0].getChildren()];let r=1/0,i=-1/0,o=1/0,s=-1/0,a=1/0,h=1/0;const d=this.render.getStageState();for(const u of n)if(u instanceof e.Group){const{x:t,y:n,width:l,height:c}=(t=>({x:this.render.toStageValue(t.x-d.x),y:this.render.toStageValue(t.y-d.y),width:this.render.toStageValue(t.width),height:this.render.toStageValue(t.height)}))(u.getClientRect());if(t<r&&(r=t),t+l>i&&(i=t+l),n<o&&(o=n),n+c>s&&(s=n+c),t<a&&(a=t),n<h&&(h=n),u instanceof e.Group){const t=u.findOne("#click-mask");t&&t.destroy()}}else if(u instanceof e.Line&&"link-line"===u.name()){const t=u.points();for(let e=0;e<t.length;e+=2){const[n,d]=[t[e],t[e+1]];n<r&&(r=n-1),n>i&&(i=n+1),d<o&&(o=d-1),d>s&&(s=d+1),n<a&&(a=n-1),d<h&&(h=d-1)}}for(const u of n)if(u instanceof e.Group)u.x(u.x()-a),u.y(u.y()-h);else if(u instanceof e.Line&&"link-line"===u.name()){const t=u.points();for(let e=0;e<t.length;e+=2)t[e]=t[e]-a,t[e+1]=t[e+1]-h;u.points(t)}return t.x(0),t.y(0),t.width(i-r),t.height(s-o),t.scale({x:1,y:1}),t}getAsset(){const t=this.getAssetView(),e=this.render.getBackground();e.width(t.width()),e.height(t.height()),t.children[0].add(e),e.moveToBottom();const n=t.toJSON(),r=JSON.parse(n),i=r.children[0].children;for(const s of i)"asset"===s.attrs.name&&(s.attrs.name="sub-asset"),s.attrs.selected&&(s.attrs.selected=!1);this.render.linkTool.jsonIdCover(i);const o=JSON.stringify({...r.children[0],className:"Group",attrs:{width:t.width(),height:t.height(),x:0,y:0}});return t.destroy(),o}}r(_c,"name","ImportExportTool");class Ac{constructor(t){r(this,"render"),this.render=t}getAlignRect(t){const e=this.render.getStageState();let n=0,r=0,i=0,o=0;const s=t.getClientRect();return[n,r,i,o]=[this.render.toStageValue(s.width),this.render.toStageValue(s.height),this.render.toStageValue(s.x-e.x),this.render.toStageValue(s.y-e.y)],{width:n,height:r,x:i,y:o}}getAlignPoints(t){let e=0,n=0,r=0,i=0;if(void 0===t)return this.getAlignPoints(this.render.transformer);{const o=this.getAlignRect(t);[e,n,r,i]=[o.width,o.height,o.x,o.y]}return{[Ml.垂直居中]:r+e/2,[Ml.左对齐]:r,[Ml.右对齐]:r+e,[Ml.水平居中]:i+n/2,[Ml.上对齐]:i,[Ml.下对齐]:i+n}}align(t,e){const n=this.getAlignPoints(e)[t],r=this.render.transformer.nodes().filter(t=>t!==e);for(const i of r){const e=this.getAlignRect(i),[r,o,s,a]=[e.width,e.height,e.x,e.y];switch(t){case Ml.垂直居中:{const t=s+r/2;i.x(i.x()+(n-t))}break;case Ml.水平居中:{const t=a+o/2;i.y(i.y()+(n-t))}break;case Ml.左对齐:{const t=s;i.x(i.x()+(n-t))}break;case Ml.右对齐:{const t=s+r;i.x(i.x()+(n-t))}break;case Ml.上对齐:{const t=a;i.y(i.y()+(n-t))}break;case Ml.下对齐:{const t=a+o;i.y(i.y()+(n-t))}}}this.render.updateHistory(),this.render.redraw([rc.name,Fl.name,Rl.name,Bl.name])}}r(Ac,"name","AlignTool");class kc{constructor(t){r(this,"render"),r(this,"linkCurrent"),this.render=t}pointsVisible(t,e){var n;if(!this.render.config.readonly){const r=e??this.render.layer;for(const e of[...["asset","sub-asset"].includes(r.name())?[r]:[],...r.find(".asset"),...r.find(".sub-asset")]){const n=e.getAttr("points")??[];e.setAttrs({points:n.map(e=>({...e,visible:t}))})}(null==(n=this.render.draws[Fl.name])?void 0:n.state.linkManualing)||this.render.redraw([Fl.name,Rl.name,Bl.name])}}remove(t){const e=t??this.linkCurrent;if(e){const{groupId:t,pointId:n,pairId:r}=e.getAttrs();if(t&&n&&r){const e=this.render.layer.findOne(`#${t}`);if(e){const t=(e.getAttr("points")??[]).find(t=>t.id===n);if(t){const n=(t.pairs??[]).findIndex(t=>t.id===r);if(n>-1){const r=t.pairs.splice(n,1)[0];e.attrs.manualPointsMap&&e.attrs.manualPointsMap[r.id]&&e.setAttr("manualPointsMap",{...e.attrs.manualPointsMap,[r.id]:void 0}),this.render.redraw([Fl.name,Rl.name,Bl.name])}}}}}}jsonIdCover(t){let e=[...t];const n=new Map;for(;e.length>0;){const t=e.shift();if(t){if(Array.isArray(t.attrs.points))for(const e of t.attrs.points){if(Array.isArray(e.pairs))for(const t of e.pairs)t.from.groupId&&!n.has(t.from.groupId)&&n.set(t.from.groupId,"g:"+Nl()),t.to.groupId&&!n.has(t.to.groupId)&&n.set(t.to.groupId,"g:"+Nl()),t.from.pointId&&!n.has(t.from.pointId)&&n.set(t.from.pointId,"p:"+Nl()),t.to.pointId&&!n.has(t.to.pointId)&&n.set(t.to.pointId,"p:"+Nl());e.id&&(n.has(e.id)||n.set(e.id,"p:"+Nl())),e.groupId&&(n.has(e.groupId)||n.set(e.groupId,"g:"+Nl()))}t.attrs.id&&(n.has(t.attrs.id)||n.set(t.attrs.id,"n:"+Nl())),Array.isArray(t.children)&&e.push(...t.children)}}for(e=[...t];e.length>0;){const t=e.shift();if(t){if(n.has(t.attrs.id)&&(t.attrs.id=n.get(t.attrs.id)),Array.isArray(t.attrs.points))for(const e of t.attrs.points){if(Array.isArray(e.pairs))for(const t of e.pairs)t.disabled=!0,t.id&&(t.id="pr:"+Nl()),n.has(t.from.groupId)&&(t.from.groupId=n.get(t.from.groupId)),n.has(t.to.groupId)&&(t.to.groupId=n.get(t.to.groupId)),n.has(t.from.pointId)&&(t.from.pointId=n.get(t.from.pointId)),n.has(t.to.pointId)&&(t.to.pointId=n.get(t.to.pointId));if(n.has(e.id)){const r=t.children.find(t=>t.attrs.id===e.id);e.id=n.get(e.id),r&&(r.attrs.id=e.id)}n.has(e.groupId)&&(e.groupId=n.get(e.groupId))}Array.isArray(t.children)&&e.push(...t.children)}}}groupIdCover(t){const e=t.id(),n=t.find(".sub-asset");for(;n.length>0;){const t=n.shift();if(t){const r=t.attrs.points;if(Array.isArray(r))for(const t of r){t.rawGroupId=t.groupId,t.groupId=e;for(const n of t.pairs)n.from.rawGroupId=n.from.groupId,n.from.groupId=e,n.to.rawGroupId=n.to.groupId,n.to.groupId=e}n.push(...t.find(".sub-asset"))}}}select(t){this.render.selectionTool.selectingClear(),this.linkCurrent=t,this.render.emit("link-selection-change",this.linkCurrent),this.render.redraw([Fl.name,Rl.name])}selectingClear(){this.linkCurrent=void 0,this.render.emit("link-selection-change",void 0),this.render.redraw([Fl.name,Rl.name])}}r(kc,"name","LinkTool");class jc{constructor(t){r(this,"render"),r(this,"alignLines",[]),r(this,"attractPoint",t=>{this.alignLinesClear();const n=this.render.getStageState();let r=t.x,i=t.y,o=!1,s=null,a=null;if(!this.render.config.readonly&&this.render.config.attractNode){const t=[{value:this.render.toStageValue(r-n.x)}],h=[{value:this.render.toStageValue(i-n.y)}];let d=1/0,u=[],l=1/0,c=[];for(let e=0;e<t.length-1;e++)if(void 0===t[e].id&&void 0!==t[e+1].id||void 0!==t[e].id&&void 0===t[e+1].id){const n=Math.abs(t[e].value-t[e+1].value);n<d?(d=n,u=[[t[e],t[e+1]]]):n===d&&u.push([t[e],t[e+1]])}for(let e=0;e<h.length-1;e++)if(void 0===h[e].id&&void 0!==h[e+1].id||void 0!==h[e].id&&void 0===h[e+1].id){const t=Math.abs(h[e].value-h[e+1].value);t<l?(l=t,c=[[h[e],h[e+1]]]):t===l&&c.push([h[e],h[e+1]])}if(u[0]&&Math.abs(u[0][0].value-u[0][1].value)<this.render.bgSize/2&&(s=u[0]),c[0]&&Math.abs(c[0][0].value-c[0][1].value)<this.render.bgSize/2&&(a=c[0]),2===(null==s?void 0:s.length)){for(const r of u){const t=r.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[t.value,this.render.toStageValue(-n.y)],[t.value,this.render.toStageValue(this.render.stage.height()-n.y)]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=s.find(t=>void 0===t.id),i=s.find(t=>void 0!==t.id);t&&i&&(r-=this.render.toBoardValue(t.value-i.value),o=!0)}if(2===(null==a?void 0:a.length)){for(const i of c){const t=i.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[this.render.toStageValue(-n.x),t.value],[this.render.toStageValue(this.render.stage.width()-n.x),t.value]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=a.find(t=>void 0===t.id),r=a.find(t=>void 0!==t.id);t&&r&&(i-=this.render.toBoardValue(t.value-r.value),o=!0)}}if(!this.render.config.readonly&&this.render.config.attractBg){if(null===s){const t=this.render.toStageValue(r-n.x),e=Math.round(t/this.render.bgSize)*this.render.bgSize,i=Math.abs(t-e),s=this.render.toStageValue(r-n.x),a=Math.round(s/this.render.bgSize)*this.render.bgSize,h=Math.abs(s-a),d=n.width,u=Math.abs(s-d);for(const l of[{type:"leftX",value:i},{type:"rightX",value:h},{type:"stageRightX",value:u}].sort((t,e)=>t.value-e.value))if(l.value<5){"stageRightX"===l.type?r=this.render.toBoardValue(d)+n.x:"leftX"===l.type?r=this.render.toBoardValue(e)+n.x:"rightX"===l.type&&(r=this.render.toBoardValue(a)+n.x),o=!0;break}}if(null===a){const t=this.render.toStageValue(i-n.y),e=Math.round(t/this.render.bgSize)*this.render.bgSize,r=Math.abs(t-e),s=this.render.toStageValue(i-n.y),a=Math.round(s/this.render.bgSize)*this.render.bgSize,h=Math.abs(s-a),d=n.height,u=Math.abs(s-d);for(const l of[{type:"topY",value:r},{type:"bottomY",value:h},{type:"stageBottomY",value:u}].sort((t,e)=>t.value-e.value))if(l.value<5){"stageBottomY"===l.type?i=this.render.toBoardValue(d)+n.y:"topY"===l.type?i=this.render.toBoardValue(e)+n.y:"bottomY"===l.type&&(i=this.render.toBoardValue(a)+n.y),o=!0;break}}}return{pos:{x:r,y:i},isAttract:o}}),r(this,"attractTransformer",t=>{this.alignLinesClear();const n=this.render.getStageState(),r=this.render.transformer.width(),i=this.render.transformer.height();let o=t.x,s=t.y,a=!1,h=null,d=null;if(!this.render.config.readonly&&this.render.config.attractNode){const{sortX:r,sortY:i}=this.getSortItems(t);let u=1/0,l=[],c=1/0,f=[];for(let t=0;t<r.length-1;t++)if(void 0===r[t].id&&void 0!==r[t+1].id||void 0!==r[t].id&&void 0===r[t+1].id){const e=Math.abs(r[t].value-r[t+1].value);e<u?(u=e,l=[[r[t],r[t+1]]]):e===u&&l.push([r[t],r[t+1]])}for(let t=0;t<i.length-1;t++)if(void 0===i[t].id&&void 0!==i[t+1].id||void 0!==i[t].id&&void 0===i[t+1].id){const e=Math.abs(i[t].value-i[t+1].value);e<c?(c=e,f=[[i[t],i[t+1]]]):e===c&&f.push([i[t],i[t+1]])}if(l[0]&&Math.abs(l[0][0].value-l[0][1].value)<this.render.bgSize/2&&(h=l[0]),f[0]&&Math.abs(f[0][0].value-f[0][1].value)<this.render.bgSize/2&&(d=f[0]),2===(null==h?void 0:h.length)){for(const i of l){const t=i.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[t.value,this.render.toStageValue(-n.y)],[t.value,this.render.toStageValue(this.render.stage.height()-n.y)]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=h.find(t=>void 0===t.id),r=h.find(t=>void 0!==t.id);t&&r&&(o-=this.render.toBoardValue(t.value-r.value),a=!0)}if(2===(null==d?void 0:d.length)){for(const i of f){const t=i.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[this.render.toStageValue(-n.x),t.value],[this.render.toStageValue(this.render.stage.width()-n.x),t.value]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=d.find(t=>void 0===t.id),r=d.find(t=>void 0!==t.id);t&&r&&(s-=this.render.toBoardValue(t.value-r.value),a=!0)}}if(!this.render.config.readonly&&this.render.config.attractBg){if(null===h){const t=this.render.toStageValue(o-n.x),e=Math.round(t/this.render.bgSize)*this.render.bgSize,i=Math.abs(t-e),s=this.render.toStageValue(o+r-n.x),h=Math.round(s/this.render.bgSize)*this.render.bgSize,d=Math.abs(s-h),u=n.width,l=Math.abs(s-u);for(const c of[{type:"leftX",value:i},{type:"rightX",value:d},{type:"stageRightX",value:l}].sort((t,e)=>t.value-e.value))if(c.value<5){"stageRightX"===c.type?o=this.render.toBoardValue(u)+n.x-r:"leftX"===c.type?o=this.render.toBoardValue(e)+n.x:"rightX"===c.type&&(o=this.render.toBoardValue(h)+n.x-r),a=!0;break}}if(null===d){const t=this.render.toStageValue(s-n.y),e=Math.round(t/this.render.bgSize)*this.render.bgSize,r=Math.abs(t-e),o=this.render.toStageValue(s+i-n.y),h=Math.round(o/this.render.bgSize)*this.render.bgSize,d=Math.abs(o-h),u=n.height,l=Math.abs(o-u);for(const c of[{type:"topY",value:r},{type:"bottomY",value:d},{type:"stageBottomY",value:l}].sort((t,e)=>t.value-e.value))if(c.value<5){"stageBottomY"===c.type?s=this.render.toBoardValue(u)+n.y-i:"topY"===c.type?s=this.render.toBoardValue(e)+n.y:"bottomY"===c.type&&(s=this.render.toBoardValue(h)+n.y-i),a=!0;break}}}return{pos:{x:o,y:s},isAttract:a}}),this.render=t}alignLinesClear(){for(const t of this.alignLines)t.destroy();this.alignLines=[]}getSortItems(t){const e=this.render.getStageState(),n=[],r=[];n.push({value:this.render.toStageValue(t.x-e.x)},{value:this.render.toStageValue(t.x-e.x+t.width/2)},{value:this.render.toStageValue(t.x-e.x+t.width)}),r.push({value:this.render.toStageValue(t.y-e.y)},{value:this.render.toStageValue(t.y-e.y+t.height/2)},{value:this.render.toStageValue(t.y-e.y+t.height)});const i=this.render.selectionTool.selectingNodes.map(t=>t._id),o=this.render.layer.find(".asset").filter(t=>!i.includes(t._id));for(const s of o){const t=s.getClientRect();n.push({id:s._id,value:this.render.toStageValue(t.x-e.x)},{id:s._id,value:this.render.toStageValue(t.x-e.x+t.width/2)},{id:s._id,value:this.render.toStageValue(t.x-e.x+t.width)}),r.push({id:s._id,value:this.render.toStageValue(t.y-e.y)},{id:s._id,value:this.render.toStageValue(t.y-e.y+t.height/2)},{id:s._id,value:this.render.toStageValue(t.y-e.y+t.height)})}return n.sort((t,e)=>t.value-e.value),r.sort((t,e)=>t.value-e.value),{sortX:n,sortY:r}}}r(jc,"name","AttractTool");const Ic=class t{constructor(t,n){var i;r(this,"stage"),r(this,"layer",new e.Layer({id:"main"})),r(this,"layerFloor",new e.Layer),r(this,"layerCover",new e.Layer({id:"cover"})),r(this,"config"),r(this,"draws",{}),r(this,"assetTool"),r(this,"selectionTool"),r(this,"copyTool"),r(this,"positionTool"),r(this,"zIndexTool"),r(this,"importExportTool"),r(this,"alignTool"),r(this,"linkTool"),r(this,"attractTool"),r(this,"groupTransformer",new e.Group),r(this,"transformer",new e.Transformer({shouldOverdrawWholeArea:!0,borderDash:[4,4],padding:1,rotationSnaps:[0,45,90,135,180,225,270,315,360],flipEnabled:!1})),r(this,"selectRect",new e.Rect({id:"selectRect",fill:"rgba(0,0,255,0.1)",visible:!1})),r(this,"handlers",{}),r(this,"bgSize",20),r(this,"rulerSize",0),r(this,"previewSize",.2),r(this,"pointSize",6),r(this,"history",[]),r(this,"historyIndex",-1),r(this,"debug",!1),r(this,"graphType"),r(this,"texting",!1),r(this,"emitter",{all:i=i||new Map,on:function(t,e){var n=i.get(t);n?n.push(e):i.set(t,[e])},off:function(t,e){var n=i.get(t);n&&(e?n.splice(n.indexOf(e)>>>0,1):i.set(t,[]))},emit:function(t,e){var n=i.get(t);n&&n.slice().map(function(t){t(e)}),(n=i.get("*"))&&n.slice().map(function(n){n(t,e)})}}),r(this,"on"),r(this,"off"),r(this,"emit"),this.config=n,this.on=this.emitter.on.bind(this.emitter),this.off=this.emitter.off.bind(this.emitter),this.emit=this.emitter.emit.bind(this.emitter),this.config.showRuler&&(this.rulerSize=40),this.stage=new e.Stage({container:t,x:this.rulerSize,y:this.rulerSize,width:n.width,height:n.height}),this.groupTransformer.add(this.transformer),this.groupTransformer.add(this.selectRect),this.layerCover.add(this.groupTransformer),this.config.showBg&&(this.draws[El.name]=new El(this,this.layerFloor,{size:this.bgSize,readonly:this.config.readonly??!1})),this.draws[Fl.name]=new Fl(this,this.layerCover,{size:this.pointSize}),this.draws[Xl.name]=new Xl(this,this.layerCover,{size:this.pointSize}),!this.config.readonly&&this.config.showRuler&&(this.draws[Rl.name]=new Rl(this,this.layerCover,{size:this.rulerSize})),!this.config.readonly&&this.config.showRefLine&&(this.draws[Ll.name]=new Ll(this,this.layerCover,{padding:this.rulerSize})),this.config.showContextmenu&&(this.draws[Wl.name]=new Wl(this,this.layerCover,{})),!this.config.readonly&&this.config.showPreview&&(this.draws[Bl.name]=new Bl(this,this.layerCover,{size:this.previewSize})),this.draws[rc.name]=new rc(this,this.layerCover,{}),this.assetTool=new gc(this),this.selectionTool=new pc(this),this.copyTool=new yc(this),this.positionTool=new mc(this),this.zIndexTool=new vc(this),this.importExportTool=new _c(this),this.alignTool=new Ac(this),this.linkTool=new kc(this),this.attractTool=new jc(this),this.handlers[ic.name]=new ic(this),this.handlers[oc.name]=new oc(this),this.config.readonly||(this.handlers[sc.name]=new sc(this),this.handlers[ac.name]=new ac(this),this.handlers[hc.name]=new hc(this),this.handlers[uc.name]=new uc(this),this.handlers[lc.name]=new lc(this),this.handlers[cc.name]=new cc(this)),!this.config.readonly&&this.config.showRefLine&&void 0!==this.draws[Ll.name]&&(this.handlers[Ll.name]=this.draws[Ll.name]),this.handlers[dc.name]=new dc(this),this.init(),this.config.configJson&&this.importExportTool.restore(this.config.configJson)}changeDebug(t){var e,n,r,i,o,s;return this.debug=t,this.emit("debug-change",this.debug),null==(e=this.draws[Fl.name])||e.init(),null==(n=this.draws[Xl.name])||n.init(),null==(r=this.draws[Rl.name])||r.init(),null==(i=this.draws[Ll.name])||i.init(),null==(o=this.draws[Wl.name])||o.init(),null==(s=this.draws[Bl.name])||s.init(),this.debug}init(){var t,e,n,r,i,o,s;this.stage.add(this.layerFloor),null==(t=this.draws[El.name])||t.init(),this.stage.add(this.layer),this.stage.add(this.layerCover),null==(e=this.draws[Fl.name])||e.init(),null==(n=this.draws[Xl.name])||n.init(),null==(r=this.draws[Rl.name])||r.init(),null==(i=this.draws[Ll.name])||i.init(),null==(o=this.draws[Wl.name])||o.init(),null==(s=this.draws[Bl.name])||s.init(),this.eventBind(),this.updateHistory()}resize(t,e){this.stage.setAttrs({width:t,height:e}),this.redraw()}remove(t){for(const n of t)if(n instanceof e.Transformer)this.remove(this.selectionTool.selectingNodes);else{const t=n.id();for(const e of this.layer.getChildren())if(e.id()!==t&&Array.isArray(e.attrs.points)){for(const n of e.attrs.points)Array.isArray(n.pairs)&&(e.attrs.manualPointsMap&&n.pairs.filter(e=>e.from.groupId===t||e.to.groupId===t).forEach(t=>{e.attrs.manualPointsMap[t.id]=void 0}),n.pairs=n.pairs.filter(e=>e.from.groupId!==t&&e.to.groupId!==t));e.setAttr("points",e.attrs.points)}n.destroy()}t.length>0&&(this.selectionTool.selectingClear(),this.linkTool.selectingClear(),this.updateHistory(),this.redraw())}prevHistory(){const t=this.history[this.historyIndex-1];t&&(this.importExportTool.restore(t,!0),this.historyIndex--,this.emit("history-change",{records:bt.clone(this.history),index:this.historyIndex}))}nextHistory(){const t=this.history[this.historyIndex+1];t&&(this.importExportTool.restore(t,!0),this.historyIndex++,this.emit("history-change",{records:bt.clone(this.history),index:this.historyIndex}))}updateHistory(){this.history.splice(this.historyIndex+1),this.history.push(this.importExportTool.save()),this.historyIndex=this.history.length-1,this.emit("history-change",{records:bt.clone(this.history),index:this.historyIndex})}eventBind(){var t,e;for(const r of["mousedown","mouseup","mousemove","wheel","contextmenu","pointerclick"])this.stage.on(r,t=>{var e,n,i,o,s,a,h,d,u;null==(e=null==t?void 0:t.evt)||e.preventDefault();for(const l in this.draws)null==(s=null==(o=null==(i=null==(n=this.draws[l])?void 0:n.handlers)?void 0:i.stage)?void 0:o[r])||s.call(o,t);for(const l in this.handlers)null==(u=null==(d=null==(h=null==(a=this.handlers[l])?void 0:a.handlers)?void 0:h.stage)?void 0:d[r])||u.call(d,t)});const n=this.stage.container();n.tabIndex=1,n.focus();for(const r of["mouseenter","dragenter","mousemove","mouseout","dragenter","dragover","drop","keydown","keyup"])n.addEventListener(r,t=>{var e,n,i,o,s,a,h,d;null==t||t.preventDefault(),["mouseenter","dragenter"].includes(r)&&this.stage.container().focus();for(const u in this.draws)null==(o=null==(i=null==(n=null==(e=this.draws[u])?void 0:e.handlers)?void 0:n.dom)?void 0:i[r])||o.call(i,t);for(const u in this.handlers)null==(d=null==(h=null==(a=null==(s=this.handlers[u])?void 0:s.handlers)?void 0:a.dom)?void 0:h[r])||d.call(h,t)});for(const r of["mousedown","transformstart","transform","transformend","dragstart","dragmove","dragend","mousemove","mouseleave","dblclick"])this.transformer.on(r,t=>{var e,n,i,o,s,a,h,d,u;null==(e=null==t?void 0:t.evt)||e.preventDefault();for(const l in this.draws)null==(s=null==(o=null==(i=null==(n=this.draws[l])?void 0:n.handlers)?void 0:i.transformer)?void 0:o[r])||s.call(o,t);for(const l in this.handlers)null==(u=null==(d=null==(h=null==(a=this.handlers[l])?void 0:a.handlers)?void 0:h.transformer)?void 0:d[r])||u.call(d,t)});(null==(e=null==(t=this.handlers[ac.name])?void 0:t.transformerConfig)?void 0:e.anchorDragBoundFunc)&&this.transformer.anchorDragBoundFunc(this.handlers[ac.name].transformerConfig.anchorDragBoundFunc)}getStageState(){return{width:this.stage.width()-this.rulerSize,height:this.stage.height()-this.rulerSize,scale:this.stage.scaleX(),x:this.stage.x(),y:this.stage.y()}}toStageValue(t){return t/this.stage.scaleX()}toBoardValue(t){return t*this.stage.scaleX()}ignore(t){return!(t instanceof e.Group)||this.ignoreSelect(t)||this.ignoreDraw(t)||this.ignoreLink(t)}ignoreSelect(t){return"selectRect"===t.id()||"hoverRect"===t.id()}ignoreDraw(t){return t.name()===El.name||t.name()===Rl.name||t.name()===Ll.name||t.name()===Wl.name||t.name()===Bl.name||t.name()===Fl.name||t.name()===Xl.name||t.name()===rc.name}ignoreLink(t){return"link-anchor"===t.name()||"linking-line"===t.name()||"link-point"===t.name()||"link-line"===t.name()||"link-manual-point"===t.name()}redraw(t){var e,n;const r=[El.name,rc.name,Fl.name,Xl.name,Rl.name,Ll.name,Bl.name,Wl.name];if(Array.isArray(t)&&!this.debug)for(const i of r)t.includes(i)&&(null==(e=this.draws[i])||e.draw());else for(const i of r)null==(n=this.draws[i])||n.draw()}changeDraggable(t){this.layer.children.forEach(e=>{e.draggable(t)})}changeGraphType(t){t&&(this.texting=!1,this.emit("texting-change",this.texting)),this.graphType=t,this.emit("graph-type-change",this.graphType),this.changeDraggable(!this.config.readonly&&void 0===this.graphType)}changeTexting(t){t&&(this.graphType=void 0,this.emit("graph-type-change",this.graphType)),this.texting=t,this.emit("texting-change",this.texting),document.body.style.cursor=this.texting?"text":"default"}getPageSettings(){return this.stage.attrs.pageSettings??{...t.PageSettingsDefault}}setPageSettings(t,e=!1){this.stage.setAttr("pageSettings",t),this.updateBackground(),e&&this.updateHistory()}getBackground(){var t;return null==(t=this.draws[El.name])?void 0:t.layer.findOne(`.${El.name}__background`)}updateBackground(){var t,e,n,r;const i=this.getBackground();i&&i.fill(this.getPageSettings().background??"transparent"),null==(t=this.draws[El.name])||t.draw(),null==(e=this.draws[rc.name])||e.draw(),null==(n=this.draws[Fl.name])||n.draw(),null==(r=this.draws[Bl.name])||r.draw()}getAssetSettings(e){const n=(null==e?void 0:e.attrs.assetSettings)??{...t.AssetSettingsDefault};return{...n,stroke:n.stroke||this.getPageSettings().stroke,strokeWidth:n.strokeWidth||this.getPageSettings().strokeWidth,fontSize:n.fontSize||this.getPageSettings().fontSize,textFill:n.textFill||this.getPageSettings().textFill,fill:n.fill||((null==e?void 0:e.attrs.assetType)===Cl.Graph?"transparent":this.getPageSettings().fill),x:parseFloat(((null==e?void 0:e.position().x)??0).toFixed(1)),y:parseFloat(((null==e?void 0:e.position().y)??0).toFixed(1)),rotation:parseFloat(((null==e?void 0:e.rotation())??0).toFixed(1)),tension:(null==e?void 0:e.attrs.assetType)===Cl.Graph&&(null==e?void 0:e.attrs.graphType)===Vl.Curve?n.tension:void 0}}setSvgXMLSettings(t,e){const n=t.match(/<(circle|ellipse|line|path|polygon|rect|text|textPath|tref|tspan)[^>/]*\/?>/g),r=/ stroke="([^"]*)"/,i=/ fill="([^"]*)"/;for(const o of n??[]){let n=o;e.stroke&&(n=r.test(o)?n.replace(r,` stroke="${e.stroke}"`):n.replace(/(<[^>/]*)(\/?>)/,`$1 stroke="${e.stroke}" $2`)),e.fill&&(n=i.test(o)?n.replace(i,` fill="${e.fill}"`):n.replace(/(<[^>/]*)(\/?>)/,`$1 fill="${e.fill}" $2`)),t=t.replace(o,n)}return t}rotatePoint({x:t,y:e},n){const r=Math.cos(n),i=Math.sin(n);return{x:t*r-e*i,y:e*r+t*i}}rotateAroundCenter(t,n){const r={x:-t.width()/2,y:-t.height()/2},i=this.rotatePoint(r,e.getAngle(t.rotation())),o=this.rotatePoint(r,e.getAngle(n)),s=o.x-i.x,a=o.y-i.y;t.rotation(n),t.x(t.x()+s),t.y(t.y()+a)}async setAssetSettings(t,n,r=!1){var i,o,s,a,h;if(t.setAttr("assetSettings",n),t instanceof e.Group){if(t.attrs.imageType===Ol.svg){const r=t.children[0];if(r instanceof e.Image&&r.attrs.svgXML){const t=await this.assetTool.loadSvgXML(this.setSvgXMLSettings(r.attrs.svgXML,n));null==(i=r.parent)||i.add(t),r.remove(),r.destroy(),t.zIndex(0)}}else if(t.attrs.assetType===Cl.Graph){const r=t.findOne(".graph");r instanceof e.Shape&&(r.strokeWidth(n.strokeWidth),r.stroke(n.stroke),r instanceof e.Arrow?r.fill(n.stroke):r.fill(n.fill),r instanceof e.Arrow&&(r.pointerAtBeginning(n.arrowStart),r.pointerAtEnding(n.arrowEnd)),r instanceof e.Arrow&&t.attrs.graphType===Vl.Curve&&r.tension(n.tension))}else if(t.attrs.assetType===Cl.Text){const r=t.findOne("Text"),i=t.findOne("Rect");if(r instanceof e.Text&&i instanceof e.Rect){let e=!1;r.fontSize()===n.fontSize&&r.text()===n.text||(e=!0),r.fill(n.textFill),r.fontSize(n.fontSize),r.text(n.text),i.fill(r.text().trim()?"":"rgba(0,0,0,0.1)"),i.width(Math.max(r.width(),n.fontSize)),i.height(Math.max(r.height(),n.fontSize)),e&&this.selectionTool.select([t])}}if(Math.abs(n.rotation-t.rotation())>=.1)this.rotateAroundCenter(t,n.rotation),this.emit("asset-position-change",[t]);else{const e=this.getAssetSettings(t);t.position({x:parseFloat(n.x.toFixed(1)),y:parseFloat(n.y.toFixed(1))}),n.x===e.x&&n.y===e.y||this.emit("asset-position-change",[t])}}r&&this.updateHistory(),null==(o=this.draws[El.name])||o.draw(),null==(s=this.draws[rc.name])||s.draw(),null==(a=this.draws[Fl.name])||a.draw(),null==(h=this.draws[Bl.name])||h.draw()}async setLinkSettings(t,e,n=!1){var r,i,o,s;const a=this.layer.findOne(`#${t.attrs.groupId}`);if(Array.isArray(null==a?void 0:a.attrs.points)){const n=(null==a?void 0:a.attrs.points).find(e=>e.id===t.attrs.pointId);if(n){const r=n.pairs.find(e=>e.id===t.attrs.pairId);r&&(r.style={...r.style,...e},a.setAttr("points",null==a?void 0:a.attrs.points))}}n&&this.updateHistory(),null==(r=this.draws[El.name])||r.draw(),null==(i=this.draws[rc.name])||i.draw(),null==(o=this.draws[Fl.name])||o.draw(),null==(s=this.draws[Bl.name])||s.draw()}getLinkSettings(e){let n;if(e){const t=this.layer.findOne(`#${e.attrs.groupId}`);if(Array.isArray(null==t?void 0:t.attrs.points)){const r=(null==t?void 0:t.attrs.points).find(t=>t.id===e.attrs.pointId);if(r){const t=r.pairs.find(t=>t.id===e.attrs.pairId);t&&(n=t.style)}}}const r=n??{...t.LinkSettingsDefault};return{...r,stroke:r.stroke||this.getPageSettings().linkStroke,strokeWidth:r.strokeWidth||this.getPageSettings().linkStrokeWidth}}};r(Ic,"PageSettingsDefault",{background:"transparent",stroke:"rgb(0,0,0)",strokeWidth:1,fill:"rgb(0,0,0)",linkStroke:"rgb(0,0,0)",linkStrokeWidth:1,fontSize:24,textFill:"rgb(0,0,0)"}),r(Ic,"AssetSettingsDefault",{stroke:"",strokeWidth:0,fill:"",arrowStart:!1,arrowEnd:!1,fontSize:0,textFill:"",text:"Text",x:0,y:0,rotation:0,tension:0}),r(Ic,"LinkSettingsDefault",{stroke:"",strokeWidth:0,arrowStart:!1,arrowEnd:!1,tension:0});let Tc=Ic;const Pc={Render:Tc};t.AlignType=Ml,t.AssetType=Cl,t.BaseDraw=Il,t.GraphType=Vl,t.ImageType=Ol,t.LinkType=zl,t.MouseButton=jl,t.MoveKey=Tl,t.Render=Tc,t.ShutcutKey=Pl,t.default=Pc,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
23
+ */wc=bc,function(){var t,e,n,r,i;function o(t,e){var n,r=Object.keys(e);for(n=0;n<r.length;n++)t=t.replace(new RegExp("\\{"+r[n]+"\\}","gi"),e[r[n]]);return t}function s(t){var e,n,r;if(!t)throw new Error("cannot create a random attribute name for an undefined object");e="ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",n="";do{for(n="",r=0;r<12;r++)n+=e[Math.floor(51*Math.random())]}while(t[n]);return n}function a(t){var e={alphabetic:"alphabetic",hanging:"hanging",top:"text-before-edge",bottom:"text-after-edge",middle:"central"};return e[t]||e.alphabetic}i=function(t,e){var n,r,i,o={};for(t=t.split(","),e=e||10,n=0;n<t.length;n+=2)r="&"+t[n+1]+";",i=parseInt(t[n],e),o[r]="&#"+i+";";return o["\\xa0"]="&#160;",o}("50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,t9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro",32),t={strokeStyle:{svgAttr:"stroke",canvas:"#000000",svg:"none",apply:"stroke"},fillStyle:{svgAttr:"fill",canvas:"#000000",svg:null,apply:"fill"},lineCap:{svgAttr:"stroke-linecap",canvas:"butt",svg:"butt",apply:"stroke"},lineJoin:{svgAttr:"stroke-linejoin",canvas:"miter",svg:"miter",apply:"stroke"},miterLimit:{svgAttr:"stroke-miterlimit",canvas:10,svg:4,apply:"stroke"},lineWidth:{svgAttr:"stroke-width",canvas:1,svg:1,apply:"stroke"},globalAlpha:{svgAttr:"opacity",canvas:1,svg:1,apply:"fill stroke"},font:{canvas:"10px sans-serif"},shadowColor:{canvas:"#000000"},shadowOffsetX:{canvas:0},shadowOffsetY:{canvas:0},shadowBlur:{canvas:0},textAlign:{canvas:"start"},textBaseline:{canvas:"alphabetic"}},(n=function(t,e){this.__root=t,this.__ctx=e}).prototype.addColorStop=function(t,e){var n,r=this.__ctx.__createElement("stop");r.setAttribute("offset",t),-1!==e.indexOf("rgba")?(n=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi.exec(e),r.setAttribute("stop-color",o("rgb({r},{g},{b})",{r:n[1],g:n[2],b:n[3]})),r.setAttribute("stop-opacity",n[4])):r.setAttribute("stop-color",e),this.__root.appendChild(r)},r=function(t,e){this.__root=t,this.__ctx=e},e=function(t){var n,r={width:500,height:500,enableMirroring:!1};if(arguments.length>1?((n=r).width=arguments[0],n.height=arguments[1]):n=t||r,!(this instanceof e))return new e(n);this.width=n.width||r.width,this.height=n.height||r.height,this.enableMirroring=void 0!==n.enableMirroring?n.enableMirroring:r.enableMirroring,this.canvas=this,this.__document=n.document||document,this.__canvas=this.__document.createElement("canvas"),this.__ctx=this.__canvas.getContext("2d"),this.__setDefaultStyles(),this.__stack=[this.__getStyleState()],this.__groupStack=[],this.__root=this.__document.createElementNS("http://www.w3.org/2000/svg","svg"),this.__root.setAttribute("version",1.1),this.__root.setAttribute("xmlns","http://www.w3.org/2000/svg"),this.__root.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink"),this.__root.setAttribute("width",this.width),this.__root.setAttribute("height",this.height),this.__ids={},this.__defs=this.__document.createElementNS("http://www.w3.org/2000/svg","defs"),this.__root.appendChild(this.__defs),this.__currentElement=this.__document.createElementNS("http://www.w3.org/2000/svg","g"),this.__root.appendChild(this.__currentElement)},e.prototype.__createElement=function(t,e,n){void 0===e&&(e={});var r,i,o=this.__document.createElementNS("http://www.w3.org/2000/svg",t),s=Object.keys(e);for(n&&(o.setAttribute("fill","none"),o.setAttribute("stroke","none")),r=0;r<s.length;r++)i=s[r],o.setAttribute(i,e[i]);return o},e.prototype.__setDefaultStyles=function(){var e,n,r=Object.keys(t);for(e=0;e<r.length;e++)this[n=r[e]]=t[n].canvas},e.prototype.__applyStyleState=function(t){var e,n,r=Object.keys(t);for(e=0;e<r.length;e++)this[n=r[e]]=t[n]},e.prototype.__getStyleState=function(){var e,n,r={},i=Object.keys(t);for(e=0;e<i.length;e++)r[n=i[e]]=this[n];return r},e.prototype.__applyStyleToCurrentElement=function(e){var i,s,a,h,d,u=Object.keys(t);for(i=0;i<u.length;i++)if(s=t[u[i]],a=this[u[i]],s.apply)if(-1!==s.apply.indexOf("fill")&&a instanceof r){if(a.__ctx)for(;a.__ctx.__defs.childNodes.length;)h=a.__ctx.__defs.childNodes[0].getAttribute("id"),this.__ids[h]=h,this.__defs.appendChild(a.__ctx.__defs.childNodes[0]);this.__currentElement.setAttribute("fill",o("url(#{id})",{id:a.__root.getAttribute("id")}))}else-1!==s.apply.indexOf("fill")&&a instanceof n?this.__currentElement.setAttribute("fill",o("url(#{id})",{id:a.__root.getAttribute("id")})):-1!==s.apply.indexOf(e)&&s.svg!==a&&("stroke"!==s.svgAttr&&"fill"!==s.svgAttr||-1===a.indexOf("rgba")?this.__currentElement.setAttribute(s.svgAttr,a):(d=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi.exec(a),this.__currentElement.setAttribute(s.svgAttr,o("rgb({r},{g},{b})",{r:d[1],g:d[2],b:d[3]})),this.__currentElement.setAttribute(s.svgAttr+"-opacity",d[4])))},e.prototype.__closestGroupOrSvg=function(t){return"g"===(t=t||this.__currentElement).nodeName||"svg"===t.nodeName?t:this.__closestGroupOrSvg(t.parentNode)},e.prototype.getSerializedSvg=function(t){var e,n,r,o,s,a=(new XMLSerializer).serializeToString(this.__root);if(/xmlns="http:\/\/www\.w3\.org\/2000\/svg".+xmlns="http:\/\/www\.w3\.org\/2000\/svg/gi.test(a)&&(a=a.replace('xmlns="http://www.w3.org/2000/svg','xmlns:xlink="http://www.w3.org/1999/xlink')),t)for(e=Object.keys(i),n=0;n<e.length;n++)r=e[n],o=i[r],(s=new RegExp(r,"gi")).test(a)&&(a=a.replace(s,o));return a},e.prototype.getSvg=function(){return this.__root},e.prototype.save=function(){var t=this.__createElement("g"),e=this.__closestGroupOrSvg();this.__groupStack.push(e),e.appendChild(t),this.__currentElement=t,this.__stack.push(this.__getStyleState())},e.prototype.restore=function(){this.__currentElement=this.__groupStack.pop();var t=this.__stack.pop();this.__applyStyleState(t)},e.prototype.__addTransform=function(t){var e=this.__closestGroupOrSvg();if(e.childNodes.length>0){var n=this.__createElement("g");e.appendChild(n),this.__currentElement=n}var r=this.__currentElement.getAttribute("transform");r?r+=" ":r="",r+=t,this.__currentElement.setAttribute("transform",r)},e.prototype.scale=function(t,e){void 0===e&&(e=t),this.__addTransform(o("scale({x},{y})",{x:t,y:e}))},e.prototype.rotate=function(t){var e=180*t/Math.PI;this.__addTransform(o("rotate({angle},{cx},{cy})",{angle:e,cx:0,cy:0}))},e.prototype.translate=function(t,e){this.__addTransform(o("translate({x},{y})",{x:t,y:e}))},e.prototype.transform=function(t,e,n,r,i,s){this.__addTransform(o("matrix({a},{b},{c},{d},{e},{f})",{a:t,b:e,c:n,d:r,e:i,f:s}))},e.prototype.beginPath=function(){var t;this.__currentDefaultPath="",this.__currentPosition={},t=this.__createElement("path",{},!0),this.__closestGroupOrSvg().appendChild(t),this.__currentElement=t},e.prototype.__applyCurrentDefaultPath=function(){if("path"!==this.__currentElement.nodeName)throw new Error("Attempted to apply path command to node "+this.__currentElement.nodeName);var t=this.__currentDefaultPath;this.__currentElement.setAttribute("d",t)},e.prototype.__addPathCommand=function(t){this.__currentDefaultPath+=" ",this.__currentDefaultPath+=t},e.prototype.moveTo=function(t,e){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.__currentPosition={x:t,y:e},this.__addPathCommand(o("M {x} {y}",{x:t,y:e}))},e.prototype.closePath=function(){this.__addPathCommand("Z")},e.prototype.lineTo=function(t,e){this.__currentPosition={x:t,y:e},this.__currentDefaultPath.indexOf("M")>-1?this.__addPathCommand(o("L {x} {y}",{x:t,y:e})):this.__addPathCommand(o("M {x} {y}",{x:t,y:e}))},e.prototype.bezierCurveTo=function(t,e,n,r,i,s){this.__currentPosition={x:i,y:s},this.__addPathCommand(o("C {cp1x} {cp1y} {cp2x} {cp2y} {x} {y}",{cp1x:t,cp1y:e,cp2x:n,cp2y:r,x:i,y:s}))},e.prototype.quadraticCurveTo=function(t,e,n,r){this.__currentPosition={x:n,y:r},this.__addPathCommand(o("Q {cpx} {cpy} {x} {y}",{cpx:t,cpy:e,x:n,y:r}))};var h=function(t){var e=Math.sqrt(t[0]*t[0]+t[1]*t[1]);return[t[0]/e,t[1]/e]};e.prototype.arcTo=function(t,e,n,r,i){var o=this.__currentPosition&&this.__currentPosition.x,s=this.__currentPosition&&this.__currentPosition.y;if(void 0!==o&&void 0!==s){if(i<0)throw new Error("IndexSizeError: The radius provided ("+i+") is negative.");if(o===t&&s===e||t===n&&e===r||0===i)this.lineTo(t,e);else{var a=h([o-t,s-e]),d=h([n-t,r-e]);if(a[0]*d[1]!==a[1]*d[0]){var u=a[0]*d[0]+a[1]*d[1],l=Math.acos(Math.abs(u)),c=h([a[0]+d[0],a[1]+d[1]]),f=i/Math.sin(l/2),g=t+f*c[0],p=e+f*c[1],y=[-a[1],a[0]],m=[d[1],-d[0]],v=function(t){var e=t[0];return t[1]>=0?Math.acos(e):-Math.acos(e)},x=v(y),w=v(m);this.lineTo(g+y[0]*i,p+y[1]*i),this.arc(g,p,i,x,w)}else this.lineTo(t,e)}}},e.prototype.stroke=function(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","fill stroke markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("stroke")},e.prototype.fill=function(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","stroke fill markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("fill")},e.prototype.rect=function(t,e,n,r){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.moveTo(t,e),this.lineTo(t+n,e),this.lineTo(t+n,e+r),this.lineTo(t,e+r),this.lineTo(t,e),this.closePath()},e.prototype.fillRect=function(t,e,n,r){var i;i=this.__createElement("rect",{x:t,y:e,width:n,height:r},!0),this.__closestGroupOrSvg().appendChild(i),this.__currentElement=i,this.__applyStyleToCurrentElement("fill")},e.prototype.strokeRect=function(t,e,n,r){var i;i=this.__createElement("rect",{x:t,y:e,width:n,height:r},!0),this.__closestGroupOrSvg().appendChild(i),this.__currentElement=i,this.__applyStyleToCurrentElement("stroke")},e.prototype.clearRect=function(t,e,n,r){var i,o=this.__closestGroupOrSvg();i=this.__createElement("rect",{x:t,y:e,width:n,height:r,fill:"#FFFFFF"},!0),o.appendChild(i)},e.prototype.createLinearGradient=function(t,e,r,i){var o=this.__createElement("linearGradient",{id:s(this.__ids),x1:t+"px",x2:r+"px",y1:e+"px",y2:i+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(o),new n(o,this)},e.prototype.createRadialGradient=function(t,e,r,i,o,a){var h=this.__createElement("radialGradient",{id:s(this.__ids),cx:i+"px",cy:o+"px",r:a+"px",fx:t+"px",fy:e+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(h),new n(h,this)},e.prototype.__parseFont=function(){var t=/^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-,\"\sa-z]+?)\s*$/i.exec(this.font),e={style:t[1]||"normal",size:t[4]||"10px",family:t[6]||"sans-serif",weight:t[3]||"normal",decoration:t[2]||"normal",href:null};return"underline"===this.__fontUnderline&&(e.decoration="underline"),this.__fontHref&&(e.href=this.__fontHref),e},e.prototype.__wrapTextLink=function(t,e){if(t.href){var n=this.__createElement("a");return n.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t.href),n.appendChild(e),n}return e},e.prototype.__applyText=function(t,e,n,r){var i,o,s=this.__parseFont(),h=this.__closestGroupOrSvg(),d=this.__createElement("text",{"font-family":s.family,"font-size":s.size,"font-style":s.style,"font-weight":s.weight,"text-decoration":s.decoration,x:e,y:n,"text-anchor":(i=this.textAlign,o={left:"start",right:"end",center:"middle",start:"start",end:"end"},o[i]||o.start),"dominant-baseline":a(this.textBaseline)},!0);d.appendChild(this.__document.createTextNode(t)),this.__currentElement=d,this.__applyStyleToCurrentElement(r),h.appendChild(this.__wrapTextLink(s,d))},e.prototype.fillText=function(t,e,n){this.__applyText(t,e,n,"fill")},e.prototype.strokeText=function(t,e,n){this.__applyText(t,e,n,"stroke")},e.prototype.measureText=function(t){return this.__ctx.font=this.font,this.__ctx.measureText(t)},e.prototype.arc=function(t,e,n,r,i,s){if(r!==i){(r%=2*Math.PI)==(i%=2*Math.PI)&&(i=(i+2*Math.PI-.001*(s?-1:1))%(2*Math.PI));var a=t+n*Math.cos(i),h=e+n*Math.sin(i),d=t+n*Math.cos(r),u=e+n*Math.sin(r),l=s?0:1,c=0,f=i-r;f<0&&(f+=2*Math.PI),c=s?f>Math.PI?0:1:f>Math.PI?1:0,this.lineTo(d,u),this.__addPathCommand(o("A {rx} {ry} {xAxisRotation} {largeArcFlag} {sweepFlag} {endX} {endY}",{rx:n,ry:n,xAxisRotation:0,largeArcFlag:c,sweepFlag:l,endX:a,endY:h})),this.__currentPosition={x:a,y:h}}},e.prototype.clip=function(){var t=this.__closestGroupOrSvg(),e=this.__createElement("clipPath"),n=s(this.__ids),r=this.__createElement("g");t.removeChild(this.__currentElement),e.setAttribute("id",n),e.appendChild(this.__currentElement),this.__defs.appendChild(e),t.setAttribute("clip-path",o("url(#{id})",{id:n})),t.appendChild(r),this.__currentElement=r},e.prototype.drawImage=function(){var t,n,r,i,o,s,a,h,d,u,l,c,f,g,p=Array.prototype.slice.call(arguments),y=p[0],m=0,v=0;if(3===p.length)t=p[1],n=p[2],r=o=y.width,i=s=y.height;else if(5===p.length)t=p[1],n=p[2],r=p[3],i=p[4],o=y.width,s=y.height;else{if(9!==p.length)throw new Error("Inavlid number of arguments passed to drawImage: "+arguments.length);m=p[1],v=p[2],o=p[3],s=p[4],t=p[5],n=p[6],r=p[7],i=p[8]}if(a=this.__closestGroupOrSvg(),l=this.__currentElement,y instanceof e){for(d=(h=y.getSvg()).childNodes[0];d.childNodes.length;)g=d.childNodes[0].getAttribute("id"),this.__ids[g]=g,this.__defs.appendChild(d.childNodes[0]);u=h.childNodes[1],a.appendChild(u),this.__currentElement=u,this.translate(t,n),this.__currentElement=l}else"CANVAS"!==y.nodeName&&"IMG"!==y.nodeName||((c=this.__createElement("image")).setAttribute("width",r),c.setAttribute("height",i),c.setAttribute("preserveAspectRatio","none"),(m||v||o!==y.width||s!==y.height)&&((f=this.__document.createElement("canvas")).width=r,f.height=i,f.getContext("2d").drawImage(y,m,v,o,s,0,0,r,i),y=f),c.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===y.nodeName?y.toDataURL():y.getAttribute("src")),a.appendChild(c),this.__currentElement=c,this.translate(t,n),this.__currentElement=l)},e.prototype.createPattern=function(t,n){var i,o=this.__document.createElementNS("http://www.w3.org/2000/svg","pattern"),a=s(this.__ids);return o.setAttribute("id",a),o.setAttribute("width",t.width),o.setAttribute("height",t.height),"CANVAS"===t.nodeName||"IMG"===t.nodeName?((i=this.__document.createElementNS("http://www.w3.org/2000/svg","image")).setAttribute("width",t.width),i.setAttribute("height",t.height),i.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===t.nodeName?t.toDataURL():t.getAttribute("src")),o.appendChild(i),this.__defs.appendChild(o)):t instanceof e&&(o.appendChild(t.__root.childNodes[1]),this.__defs.appendChild(o)),new r(o,this)},e.prototype.drawFocusRing=function(){},e.prototype.createImageData=function(){},e.prototype.getImageData=function(){},e.prototype.putImageData=function(){},e.prototype.globalCompositeOperation=function(){},e.prototype.setTransform=function(){},"object"==typeof window&&(window.C2S=e),wc.exports=e}();const Sc=xc(bc.exports);Sc.prototype.__applyCurrentDefaultPath=function(){if("g"===this.__currentElement.nodeName){const t=this.__currentElement.querySelector("g");if(t){const e=t.getAttribute("transform");if(e){const t=e.match(/scale\(([^),]+),([^)]+)\)/);if(t){const[e,n]=[parseFloat(t[1]),parseFloat(t[2])];let r=this.__currentDefaultPath;const i=/A ([^ ]+) ([^ ]+) /,o=r.match(i);if(o){const[t,s]=[parseFloat(o[1]),parseFloat(o[2])];r=r.replace(i,`A ${t*e} ${s*n} `);const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("d",r),a.setAttribute("fill","none"),this.__currentElement.append(a)}}}else{const t=this.__currentDefaultPath,e=document.createElementNS("http://www.w3.org/2000/svg","path");e.setAttribute("d",t),e.setAttribute("fill","none"),this.__currentElement.append(e)}}return}if("path"!==this.__currentElement.nodeName)throw new Error("Attempted to apply path command to node "+this.__currentElement.nodeName);{const t=this.__currentDefaultPath;this.__currentElement.setAttribute("d",t)}};class _c{constructor(t){r(this,"render"),this.render=t}getView(t=!1){const n=this.render.stage.clone(),r=n.find("#main")[0],i=n.find("#cover")[0],o=n.getChildren();if(n.removeChildren(),r&&i){let o=r.getChildren(t=>!this.render.ignore(t));for(const t of o){t.listening(!0),t.draggable(!this.render.config.readonly);for(const e of t.children)this.render.ignoreSelect(e)&&e.remove()}if(t){const t=i.children.find(t=>t.attrs.name===Fl.name);t&&(o=o.concat(t.children.filter(t=>"link-line"===t.attrs.name)))}const s=new e.Layer;s.add(...o),o=s.getChildren();for(const t of o)t.attrs.nodeMousedownPos&&t.setAttrs({opacity:n.attrs.lastOpacity??1});n.add(s),r.removeChildren(),i.removeChildren()}return o.forEach(t=>t.destroy()),n}save(){const t=this.getView(),e=t.toJSON();return t.destroy(),e}loadImage(t){return new Promise(e=>{const n=new Image;n.onload=()=>{e(n)},n.onerror=()=>{e(null)},n.src=t})}async restoreImage(t=[]){for(const n of t)if(n instanceof e.Group)await this.restoreImage(n.getChildren());else if(n instanceof e.Image)if(n.attrs.svgXML){const t=new Blob([n.attrs.svgXML],{type:"image/svg+xml"}),e=URL.createObjectURL(t),r=await this.loadImage(e);r&&n.image(r)}else if(n.attrs.gif){const t=await this.render.assetTool.loadGif(n.attrs.gif);t&&n.image(t.image())}else if(n.attrs.src){const t=await this.loadImage(n.attrs.src);t&&n.image(t)}}async restore(t,n=!1){try{this.render.emit("loading",!0),this.render.selectionTool.selectingClear(),this.render.linkTool.selectingClear(),this.render.layer.getChildren().forEach(t=>{t.destroy()}),this.render.layer.removeChildren();const r=document.createElement("div"),i=e.Node.create(t,r),o=i.getChildren()[0].getChildren();await this.restoreImage(o);for(const t of o)t.draggable(!this.render.config.readonly),t.off("mouseenter"),t.on("mouseenter",()=>{this.render.linkTool.pointsVisible(!0,t)}),t.add(new e.Rect({id:"hoverRect",width:t.width(),height:t.height(),fill:"rgba(0,255,0,0.3)",visible:!1})),t.off("mouseleave"),t.on("mouseleave",()=>{var e;this.render.linkTool.pointsVisible(!1,t),null==(e=t.findOne("#hoverRect"))||e.visible(!1)});this.render.layer.add(...o),this.render.stage.setAttr("pageSettings",i.attrs.pageSettings),this.render.emit("page-settings-change",this.render.getPageSettings()),this.render.updateBackground(),n||this.render.updateHistory(),this.render.linkTool.pointsVisible(!1),this.render.redraw([rc.name,Fl.name,Rl.name,Bl.name]),i.destroy()}catch(r){}finally{this.render.emit("loading",!1)}}getImage(t=1,n){const r=this.getAssetView(),i=new e.Layer,o=new e.Rect({listening:!1});o.setAttrs({x:0,y:0,width:r.width(),height:r.height(),fill:n??this.render.getPageSettings().background}),i.add(o);const s=r.getChildren();r.removeChildren(),r.add(i),r.add(s[0],...s.slice(1));const a=r.toDataURL({pixelRatio:t});return r.destroy(),a}getAssetImage(t=1,n){const r=this.getAssetView(),i=new e.Layer,o=new e.Rect({listening:!1});o.setAttrs({x:-r.x(),y:-r.y(),width:r.width(),height:r.height(),fill:n??this.render.getPageSettings().background}),i.add(o);const s=r.getChildren();r.removeChildren(),r.add(i),r.add(s[0],...s.slice(1));const a=r.toDataURL({pixelRatio:t});return r.destroy(),a}blobToBase64(t,e){return new Promise(n=>{const r=new File([t],"image",{type:e}),i=new FileReader;i.readAsDataURL(r),i.onload=function(){n(this.result??"")}})}parseSvgImage(t){return new Promise(e=>{t.length>0?Promise.all(t.map(t=>fetch(t))).then(t=>{Promise.all(t.map(t=>t.text())).then(t=>{e(t)})}):e([])})}parseOtherImage(t){return new Promise(e=>{t.length>0?Promise.all(t.map(t=>fetch(t))).then(t=>{Promise.all(t.map(t=>t.blob())).then(t=>{Promise.all(t.map(t=>this.blobToBase64(t,"image/*"))).then(t=>{e(t)})})}):e([])})}parseImage(t){return new Promise(e=>{const n=t.match(new RegExp('(?<=xlink:href=")blob:https?:\\/\\/[^"]+(?=")',"g"))??[],r=t.match(new RegExp('(?<=xlink:href=")(?<!blob:)[^"]+(?=")',"g"))??[];Promise.all([this.parseSvgImage(n),this.parseOtherImage(r)]).then(([i,o])=>{n.forEach((e,n)=>{var r;t=t.replace(new RegExp(`<image[^><]* xlink:href="${e}"[^><]*/>`),(null==(r=i[n].match(/<svg[^><]*>.*<\/svg>/))?void 0:r[0])??"")}),r.forEach((e,n)=>{t=t.replace(`"${e}"`,`"${o[n]}"`)}),e(t)})})}async getSvg(){const t=this.getAssetView(),e=t.children[0],n=e.canvas.context._context;if(n){const r=new Sc({ctx:n,...e.size()});e.canvas.context._context=r,e.draw();let i=r.getSerializedSvg();i=i.replace(/(<defs\/><g><rect fill=")([^"]+)(")/,`$1${this.render.getPageSettings().background}$3`);const o=await this.parseImage(i);return t.destroy(),o}return Promise.resolve('<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0"></svg>')}getAssetView(){const t=this.getView(!0),n=[...t.getChildren()[0].getChildren()];let r=1/0,i=-1/0,o=1/0,s=-1/0,a=1/0,h=1/0;const d=this.render.getStageState();for(const u of n)if(u instanceof e.Group){const{x:t,y:n,width:l,height:c}=(t=>({x:this.render.toStageValue(t.x-d.x),y:this.render.toStageValue(t.y-d.y),width:this.render.toStageValue(t.width),height:this.render.toStageValue(t.height)}))(u.getClientRect());if(t<r&&(r=t),t+l>i&&(i=t+l),n<o&&(o=n),n+c>s&&(s=n+c),t<a&&(a=t),n<h&&(h=n),u instanceof e.Group){const t=u.findOne("#click-mask");t&&t.destroy()}}else if(u instanceof e.Line&&"link-line"===u.name()){const t=u.points();for(let e=0;e<t.length;e+=2){const[n,d]=[t[e],t[e+1]];n<r&&(r=n-1),n>i&&(i=n+1),d<o&&(o=d-1),d>s&&(s=d+1),n<a&&(a=n-1),d<h&&(h=d-1)}}for(const u of n)if(u instanceof e.Group)u.x(u.x()-a),u.y(u.y()-h);else if(u instanceof e.Line&&"link-line"===u.name()){const t=u.points();for(let e=0;e<t.length;e+=2)t[e]=t[e]-a,t[e+1]=t[e+1]-h;u.points(t)}return t.x(0),t.y(0),t.width(i-r),t.height(s-o),t.scale({x:1,y:1}),t}getAsset(){const t=this.getAssetView(),e=this.render.getBackground();e.width(t.width()),e.height(t.height()),t.children[0].add(e),e.moveToBottom();const n=t.toJSON(),r=JSON.parse(n),i=r.children[0].children;for(const s of i)"asset"===s.attrs.name&&(s.attrs.name="sub-asset"),s.attrs.selected&&(s.attrs.selected=!1);this.render.linkTool.jsonIdCover(i);const o=JSON.stringify({...r.children[0],className:"Group",attrs:{width:t.width(),height:t.height(),x:0,y:0}});return t.destroy(),o}}r(_c,"name","ImportExportTool");class Ac{constructor(t){r(this,"render"),this.render=t}getAlignRect(t){const e=this.render.getStageState();let n=0,r=0,i=0,o=0;const s=t.getClientRect();return[n,r,i,o]=[this.render.toStageValue(s.width),this.render.toStageValue(s.height),this.render.toStageValue(s.x-e.x),this.render.toStageValue(s.y-e.y)],{width:n,height:r,x:i,y:o}}getAlignPoints(t){let e=0,n=0,r=0,i=0;if(void 0===t)return this.getAlignPoints(this.render.transformer);{const o=this.getAlignRect(t);[e,n,r,i]=[o.width,o.height,o.x,o.y]}return{[Ml.垂直居中]:r+e/2,[Ml.左对齐]:r,[Ml.右对齐]:r+e,[Ml.水平居中]:i+n/2,[Ml.上对齐]:i,[Ml.下对齐]:i+n}}align(t,e){const n=this.getAlignPoints(e)[t],r=this.render.transformer.nodes().filter(t=>t!==e);for(const i of r){const e=this.getAlignRect(i),[r,o,s,a]=[e.width,e.height,e.x,e.y];switch(t){case Ml.垂直居中:{const t=s+r/2;i.x(i.x()+(n-t))}break;case Ml.水平居中:{const t=a+o/2;i.y(i.y()+(n-t))}break;case Ml.左对齐:{const t=s;i.x(i.x()+(n-t))}break;case Ml.右对齐:{const t=s+r;i.x(i.x()+(n-t))}break;case Ml.上对齐:{const t=a;i.y(i.y()+(n-t))}break;case Ml.下对齐:{const t=a+o;i.y(i.y()+(n-t))}}}this.render.updateHistory(),this.render.redraw([rc.name,Fl.name,Rl.name,Bl.name])}}r(Ac,"name","AlignTool");class kc{constructor(t){r(this,"render"),r(this,"linkCurrent"),this.render=t}pointsVisible(t,e){var n;if(!this.render.config.readonly){const r=e??this.render.layer;for(const e of[...["asset","sub-asset"].includes(r.name())?[r]:[],...r.find(".asset"),...r.find(".sub-asset")]){const n=e.getAttr("points")??[];e.setAttrs({points:n.map(e=>({...e,visible:t}))})}(null==(n=this.render.draws[Fl.name])?void 0:n.state.linkManualing)||this.render.redraw([Fl.name,Rl.name,Bl.name])}}remove(t){const e=t??this.linkCurrent;if(e){const{groupId:t,pointId:n,pairId:r}=e.getAttrs();if(t&&n&&r){const e=this.render.layer.findOne(`#${t}`);if(e){const t=(e.getAttr("points")??[]).find(t=>t.id===n);if(t){const n=(t.pairs??[]).findIndex(t=>t.id===r);if(n>-1){const r=t.pairs.splice(n,1)[0];e.attrs.manualPointsMap&&e.attrs.manualPointsMap[r.id]&&e.setAttr("manualPointsMap",{...e.attrs.manualPointsMap,[r.id]:void 0}),this.render.redraw([Fl.name,Rl.name,Bl.name])}}}}}}jsonIdCover(t){let e=[...t];const n=new Map;for(;e.length>0;){const t=e.shift();if(t){if(Array.isArray(t.attrs.points))for(const e of t.attrs.points){if(Array.isArray(e.pairs))for(const t of e.pairs)t.from.groupId&&!n.has(t.from.groupId)&&n.set(t.from.groupId,"g:"+Nl()),t.to.groupId&&!n.has(t.to.groupId)&&n.set(t.to.groupId,"g:"+Nl()),t.from.pointId&&!n.has(t.from.pointId)&&n.set(t.from.pointId,"p:"+Nl()),t.to.pointId&&!n.has(t.to.pointId)&&n.set(t.to.pointId,"p:"+Nl());e.id&&(n.has(e.id)||n.set(e.id,"p:"+Nl())),e.groupId&&(n.has(e.groupId)||n.set(e.groupId,"g:"+Nl()))}t.attrs.id&&(n.has(t.attrs.id)||n.set(t.attrs.id,"n:"+Nl())),Array.isArray(t.children)&&e.push(...t.children)}}for(e=[...t];e.length>0;){const t=e.shift();if(t){if(n.has(t.attrs.id)&&(t.attrs.id=n.get(t.attrs.id)),Array.isArray(t.attrs.points))for(const e of t.attrs.points){if(Array.isArray(e.pairs))for(const t of e.pairs)t.disabled=!0,t.id&&(t.id="pr:"+Nl()),n.has(t.from.groupId)&&(t.from.groupId=n.get(t.from.groupId)),n.has(t.to.groupId)&&(t.to.groupId=n.get(t.to.groupId)),n.has(t.from.pointId)&&(t.from.pointId=n.get(t.from.pointId)),n.has(t.to.pointId)&&(t.to.pointId=n.get(t.to.pointId));if(n.has(e.id)){const r=t.children.find(t=>t.attrs.id===e.id);e.id=n.get(e.id),r&&(r.attrs.id=e.id)}n.has(e.groupId)&&(e.groupId=n.get(e.groupId))}Array.isArray(t.children)&&e.push(...t.children)}}}groupIdCover(t){const e=t.id(),n=t.find(".sub-asset");for(;n.length>0;){const t=n.shift();if(t){const r=t.attrs.points;if(Array.isArray(r))for(const t of r){t.rawGroupId=t.groupId,t.groupId=e;for(const n of t.pairs)n.from.rawGroupId=n.from.groupId,n.from.groupId=e,n.to.rawGroupId=n.to.groupId,n.to.groupId=e}n.push(...t.find(".sub-asset"))}}}select(t){this.render.selectionTool.selectingClear(),this.linkCurrent=t,this.render.emit("link-selection-change",this.linkCurrent),this.render.redraw([Fl.name,Rl.name])}selectingClear(){this.linkCurrent=void 0,this.render.emit("link-selection-change",void 0),this.render.redraw([Fl.name,Rl.name])}}r(kc,"name","LinkTool");class jc{constructor(t){r(this,"render"),r(this,"alignLines",[]),r(this,"attractPoint",t=>{this.alignLinesClear();const n=this.render.getStageState();let r=t.x,i=t.y,o=!1,s=null,a=null;if(!this.render.config.readonly&&this.render.config.attractNode){const t=[{value:this.render.toStageValue(r-n.x)}],h=[{value:this.render.toStageValue(i-n.y)}];let d=1/0,u=[],l=1/0,c=[];for(let e=0;e<t.length-1;e++)if(void 0===t[e].id&&void 0!==t[e+1].id||void 0!==t[e].id&&void 0===t[e+1].id){const n=Math.abs(t[e].value-t[e+1].value);n<d?(d=n,u=[[t[e],t[e+1]]]):n===d&&u.push([t[e],t[e+1]])}for(let e=0;e<h.length-1;e++)if(void 0===h[e].id&&void 0!==h[e+1].id||void 0!==h[e].id&&void 0===h[e+1].id){const t=Math.abs(h[e].value-h[e+1].value);t<l?(l=t,c=[[h[e],h[e+1]]]):t===l&&c.push([h[e],h[e+1]])}if(u[0]&&Math.abs(u[0][0].value-u[0][1].value)<this.render.bgSize/2&&(s=u[0]),c[0]&&Math.abs(c[0][0].value-c[0][1].value)<this.render.bgSize/2&&(a=c[0]),2===(null==s?void 0:s.length)){for(const r of u){const t=r.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[t.value,this.render.toStageValue(-n.y)],[t.value,this.render.toStageValue(this.render.stage.height()-n.y)]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=s.find(t=>void 0===t.id),i=s.find(t=>void 0!==t.id);t&&i&&(r-=this.render.toBoardValue(t.value-i.value),o=!0)}if(2===(null==a?void 0:a.length)){for(const i of c){const t=i.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[this.render.toStageValue(-n.x),t.value],[this.render.toStageValue(this.render.stage.width()-n.x),t.value]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=a.find(t=>void 0===t.id),r=a.find(t=>void 0!==t.id);t&&r&&(i-=this.render.toBoardValue(t.value-r.value),o=!0)}}if(!this.render.config.readonly&&this.render.config.attractBg){if(null===s){const t=this.render.toStageValue(r-n.x),e=Math.round(t/this.render.bgSize)*this.render.bgSize,i=Math.abs(t-e),s=this.render.toStageValue(r-n.x),a=Math.round(s/this.render.bgSize)*this.render.bgSize,h=Math.abs(s-a),d=n.width,u=Math.abs(s-d);for(const l of[{type:"leftX",value:i},{type:"rightX",value:h},{type:"stageRightX",value:u}].sort((t,e)=>t.value-e.value))if(l.value<5){"stageRightX"===l.type?r=this.render.toBoardValue(d)+n.x:"leftX"===l.type?r=this.render.toBoardValue(e)+n.x:"rightX"===l.type&&(r=this.render.toBoardValue(a)+n.x),o=!0;break}}if(null===a){const t=this.render.toStageValue(i-n.y),e=Math.round(t/this.render.bgSize)*this.render.bgSize,r=Math.abs(t-e),s=this.render.toStageValue(i-n.y),a=Math.round(s/this.render.bgSize)*this.render.bgSize,h=Math.abs(s-a),d=n.height,u=Math.abs(s-d);for(const l of[{type:"topY",value:r},{type:"bottomY",value:h},{type:"stageBottomY",value:u}].sort((t,e)=>t.value-e.value))if(l.value<5){"stageBottomY"===l.type?i=this.render.toBoardValue(d)+n.y:"topY"===l.type?i=this.render.toBoardValue(e)+n.y:"bottomY"===l.type&&(i=this.render.toBoardValue(a)+n.y),o=!0;break}}}return{pos:{x:r,y:i},isAttract:o}}),r(this,"attractTransformer",t=>{this.alignLinesClear();const n=this.render.getStageState(),r=this.render.transformer.width(),i=this.render.transformer.height();let o=t.x,s=t.y,a=!1,h=null,d=null;if(!this.render.config.readonly&&this.render.config.attractNode){const{sortX:r,sortY:i}=this.getSortItems(t);let u=1/0,l=[],c=1/0,f=[];for(let t=0;t<r.length-1;t++)if(void 0===r[t].id&&void 0!==r[t+1].id||void 0!==r[t].id&&void 0===r[t+1].id){const e=Math.abs(r[t].value-r[t+1].value);e<u?(u=e,l=[[r[t],r[t+1]]]):e===u&&l.push([r[t],r[t+1]])}for(let t=0;t<i.length-1;t++)if(void 0===i[t].id&&void 0!==i[t+1].id||void 0!==i[t].id&&void 0===i[t+1].id){const e=Math.abs(i[t].value-i[t+1].value);e<c?(c=e,f=[[i[t],i[t+1]]]):e===c&&f.push([i[t],i[t+1]])}if(l[0]&&Math.abs(l[0][0].value-l[0][1].value)<this.render.bgSize/2&&(h=l[0]),f[0]&&Math.abs(f[0][0].value-f[0][1].value)<this.render.bgSize/2&&(d=f[0]),2===(null==h?void 0:h.length)){for(const i of l){const t=i.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[t.value,this.render.toStageValue(-n.y)],[t.value,this.render.toStageValue(this.render.stage.height()-n.y)]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=h.find(t=>void 0===t.id),r=h.find(t=>void 0!==t.id);t&&r&&(o-=this.render.toBoardValue(t.value-r.value),a=!0)}if(2===(null==d?void 0:d.length)){for(const i of f){const t=i.find(t=>void 0!==t.id);if(t){const r=new e.Line({points:bt.flatten([[this.render.toStageValue(-n.x),t.value],[this.render.toStageValue(this.render.stage.width()-n.x),t.value]]),stroke:"blue",strokeWidth:this.render.toStageValue(1),dash:[4,4],listening:!1});this.alignLines.push(r),this.render.layerCover.add(r)}}const t=d.find(t=>void 0===t.id),r=d.find(t=>void 0!==t.id);t&&r&&(s-=this.render.toBoardValue(t.value-r.value),a=!0)}}if(!this.render.config.readonly&&this.render.config.attractBg){if(null===h){const t=this.render.toStageValue(o-n.x),e=Math.round(t/this.render.bgSize)*this.render.bgSize,i=Math.abs(t-e),s=this.render.toStageValue(o+r-n.x),h=Math.round(s/this.render.bgSize)*this.render.bgSize,d=Math.abs(s-h),u=n.width,l=Math.abs(s-u);for(const c of[{type:"leftX",value:i},{type:"rightX",value:d},{type:"stageRightX",value:l}].sort((t,e)=>t.value-e.value))if(c.value<5){"stageRightX"===c.type?o=this.render.toBoardValue(u)+n.x-r:"leftX"===c.type?o=this.render.toBoardValue(e)+n.x:"rightX"===c.type&&(o=this.render.toBoardValue(h)+n.x-r),a=!0;break}}if(null===d){const t=this.render.toStageValue(s-n.y),e=Math.round(t/this.render.bgSize)*this.render.bgSize,r=Math.abs(t-e),o=this.render.toStageValue(s+i-n.y),h=Math.round(o/this.render.bgSize)*this.render.bgSize,d=Math.abs(o-h),u=n.height,l=Math.abs(o-u);for(const c of[{type:"topY",value:r},{type:"bottomY",value:d},{type:"stageBottomY",value:l}].sort((t,e)=>t.value-e.value))if(c.value<5){"stageBottomY"===c.type?s=this.render.toBoardValue(u)+n.y-i:"topY"===c.type?s=this.render.toBoardValue(e)+n.y:"bottomY"===c.type&&(s=this.render.toBoardValue(h)+n.y-i),a=!0;break}}}return{pos:{x:o,y:s},isAttract:a}}),this.render=t}alignLinesClear(){for(const t of this.alignLines)t.destroy();this.alignLines=[]}getSortItems(t){const e=this.render.getStageState(),n=[],r=[];n.push({value:this.render.toStageValue(t.x-e.x)},{value:this.render.toStageValue(t.x-e.x+t.width/2)},{value:this.render.toStageValue(t.x-e.x+t.width)}),r.push({value:this.render.toStageValue(t.y-e.y)},{value:this.render.toStageValue(t.y-e.y+t.height/2)},{value:this.render.toStageValue(t.y-e.y+t.height)});const i=this.render.selectionTool.selectingNodes.map(t=>t._id),o=this.render.layer.find(".asset").filter(t=>!i.includes(t._id));for(const s of o){const t=s.getClientRect();n.push({id:s._id,value:this.render.toStageValue(t.x-e.x)},{id:s._id,value:this.render.toStageValue(t.x-e.x+t.width/2)},{id:s._id,value:this.render.toStageValue(t.x-e.x+t.width)}),r.push({id:s._id,value:this.render.toStageValue(t.y-e.y)},{id:s._id,value:this.render.toStageValue(t.y-e.y+t.height/2)},{id:s._id,value:this.render.toStageValue(t.y-e.y+t.height)})}return n.sort((t,e)=>t.value-e.value),r.sort((t,e)=>t.value-e.value),{sortX:n,sortY:r}}}r(jc,"name","AttractTool");const Ic=class t{constructor(t,n){var i;r(this,"stage"),r(this,"layer",new e.Layer({id:"main"})),r(this,"layerFloor",new e.Layer),r(this,"layerCover",new e.Layer({id:"cover"})),r(this,"config"),r(this,"draws",{}),r(this,"assetTool"),r(this,"selectionTool"),r(this,"copyTool"),r(this,"positionTool"),r(this,"zIndexTool"),r(this,"importExportTool"),r(this,"alignTool"),r(this,"linkTool"),r(this,"attractTool"),r(this,"groupTransformer",new e.Group),r(this,"transformer",new e.Transformer({shouldOverdrawWholeArea:!0,borderDash:[4,4],padding:1,rotationSnaps:[0,45,90,135,180,225,270,315,360],flipEnabled:!1})),r(this,"selectRect",new e.Rect({id:"selectRect",fill:"rgba(0,0,255,0.1)",visible:!1})),r(this,"handlers",{}),r(this,"bgSize",20),r(this,"rulerSize",0),r(this,"previewSize",.2),r(this,"pointSize",6),r(this,"history",[]),r(this,"historyIndex",-1),r(this,"debug",!1),r(this,"graphType"),r(this,"texting",!1),r(this,"emitter",{all:i=i||new Map,on:function(t,e){var n=i.get(t);n?n.push(e):i.set(t,[e])},off:function(t,e){var n=i.get(t);n&&(e?n.splice(n.indexOf(e)>>>0,1):i.set(t,[]))},emit:function(t,e){var n=i.get(t);n&&n.slice().map(function(t){t(e)}),(n=i.get("*"))&&n.slice().map(function(n){n(t,e)})}}),r(this,"on"),r(this,"off"),r(this,"emit"),this.config=n,this.on=this.emitter.on.bind(this.emitter),this.off=this.emitter.off.bind(this.emitter),this.emit=this.emitter.emit.bind(this.emitter),this.config.showRuler&&(this.rulerSize=40),this.stage=new e.Stage({container:t,x:this.rulerSize,y:this.rulerSize,width:n.width,height:n.height}),this.groupTransformer.add(this.transformer),this.groupTransformer.add(this.selectRect),this.layerCover.add(this.groupTransformer),this.config.showBg&&(this.draws[El.name]=new El(this,this.layerFloor,{size:this.bgSize,readonly:this.config.readonly??!1})),this.draws[Fl.name]=new Fl(this,this.layerCover,{size:this.pointSize}),this.draws[Xl.name]=new Xl(this,this.layerCover,{size:this.pointSize}),!this.config.readonly&&this.config.showRuler&&(this.draws[Rl.name]=new Rl(this,this.layerCover,{size:this.rulerSize})),!this.config.readonly&&this.config.showRefLine&&(this.draws[Ll.name]=new Ll(this,this.layerCover,{padding:this.rulerSize})),this.config.showContextmenu&&(this.draws[Wl.name]=new Wl(this,this.layerCover,{})),!this.config.readonly&&this.config.showPreview&&(this.draws[Bl.name]=new Bl(this,this.layerCover,{size:this.previewSize})),this.draws[rc.name]=new rc(this,this.layerCover,{}),this.assetTool=new gc(this),this.selectionTool=new pc(this),this.copyTool=new yc(this),this.positionTool=new mc(this),this.zIndexTool=new vc(this),this.importExportTool=new _c(this),this.alignTool=new Ac(this),this.linkTool=new kc(this),this.attractTool=new jc(this),this.handlers[ic.name]=new ic(this),this.handlers[oc.name]=new oc(this),this.config.readonly||(this.handlers[sc.name]=new sc(this),this.handlers[ac.name]=new ac(this),this.handlers[hc.name]=new hc(this),this.handlers[uc.name]=new uc(this),this.handlers[lc.name]=new lc(this),this.handlers[cc.name]=new cc(this)),!this.config.readonly&&this.config.showRefLine&&void 0!==this.draws[Ll.name]&&(this.handlers[Ll.name]=this.draws[Ll.name]),this.handlers[dc.name]=new dc(this),this.init(),this.config.configJson&&this.importExportTool.restore(this.config.configJson)}changeDebug(t){var e,n,r,i,o,s;return this.debug=t,this.emit("debug-change",this.debug),null==(e=this.draws[Fl.name])||e.init(),null==(n=this.draws[Xl.name])||n.init(),null==(r=this.draws[Rl.name])||r.init(),null==(i=this.draws[Ll.name])||i.init(),null==(o=this.draws[Wl.name])||o.init(),null==(s=this.draws[Bl.name])||s.init(),this.debug}init(){var t,e,n,r,i,o,s;this.stage.add(this.layerFloor),null==(t=this.draws[El.name])||t.init(),this.stage.add(this.layer),this.stage.add(this.layerCover),null==(e=this.draws[Fl.name])||e.init(),null==(n=this.draws[Xl.name])||n.init(),null==(r=this.draws[Rl.name])||r.init(),null==(i=this.draws[Ll.name])||i.init(),null==(o=this.draws[Wl.name])||o.init(),null==(s=this.draws[Bl.name])||s.init(),this.eventBind(),this.updateHistory()}resize(t,e){this.stage.setAttrs({width:t,height:e}),this.redraw()}remove(t){for(const n of t)if(n instanceof e.Transformer)this.remove(this.selectionTool.selectingNodes);else{const t=n.id();for(const e of this.layer.getChildren())if(e.id()!==t&&Array.isArray(e.attrs.points)){for(const n of e.attrs.points)Array.isArray(n.pairs)&&(e.attrs.manualPointsMap&&n.pairs.filter(e=>e.from.groupId===t||e.to.groupId===t).forEach(t=>{e.attrs.manualPointsMap[t.id]=void 0}),n.pairs=n.pairs.filter(e=>e.from.groupId!==t&&e.to.groupId!==t));e.setAttr("points",e.attrs.points)}n.destroy()}t.length>0&&(this.selectionTool.selectingClear(),this.linkTool.selectingClear(),this.updateHistory(),this.redraw())}prevHistory(){const t=this.history[this.historyIndex-1];t&&(this.importExportTool.restore(t,!0),this.historyIndex--,this.emit("history-change",{records:bt.clone(this.history),index:this.historyIndex}))}nextHistory(){const t=this.history[this.historyIndex+1];t&&(this.importExportTool.restore(t,!0),this.historyIndex++,this.emit("history-change",{records:bt.clone(this.history),index:this.historyIndex}))}updateHistory(){this.history.splice(this.historyIndex+1),this.history.push(this.importExportTool.save()),this.historyIndex=this.history.length-1,this.emit("history-change",{records:bt.clone(this.history),index:this.historyIndex})}eventBind(){var t,e;for(const r of["mousedown","mouseup","mousemove","wheel","contextmenu","pointerclick"])this.stage.on(r,t=>{var e,n,i,o,s,a,h,d,u;null==(e=null==t?void 0:t.evt)||e.preventDefault();for(const l in this.draws)null==(s=null==(o=null==(i=null==(n=this.draws[l])?void 0:n.handlers)?void 0:i.stage)?void 0:o[r])||s.call(o,t);for(const l in this.handlers)null==(u=null==(d=null==(h=null==(a=this.handlers[l])?void 0:a.handlers)?void 0:h.stage)?void 0:d[r])||u.call(d,t)});const n=this.stage.container();n.tabIndex=1,n.focus();for(const r of["mouseenter","dragenter","mousemove","mouseout","dragenter","dragover","drop","keydown","keyup"])n.addEventListener(r,t=>{var e,n,i,o,s,a,h,d;null==t||t.preventDefault(),["mouseenter","dragenter"].includes(r)&&this.stage.container().focus();for(const u in this.draws)null==(o=null==(i=null==(n=null==(e=this.draws[u])?void 0:e.handlers)?void 0:n.dom)?void 0:i[r])||o.call(i,t);for(const u in this.handlers)null==(d=null==(h=null==(a=null==(s=this.handlers[u])?void 0:s.handlers)?void 0:a.dom)?void 0:h[r])||d.call(h,t)});for(const r of["mousedown","transformstart","transform","transformend","dragstart","dragmove","dragend","mousemove","mouseleave","dblclick"])this.transformer.on(r,t=>{var e,n,i,o,s,a,h,d,u;null==(e=null==t?void 0:t.evt)||e.preventDefault();for(const l in this.draws)null==(s=null==(o=null==(i=null==(n=this.draws[l])?void 0:n.handlers)?void 0:i.transformer)?void 0:o[r])||s.call(o,t);for(const l in this.handlers)null==(u=null==(d=null==(h=null==(a=this.handlers[l])?void 0:a.handlers)?void 0:h.transformer)?void 0:d[r])||u.call(d,t)});(null==(e=null==(t=this.handlers[ac.name])?void 0:t.transformerConfig)?void 0:e.anchorDragBoundFunc)&&this.transformer.anchorDragBoundFunc(this.handlers[ac.name].transformerConfig.anchorDragBoundFunc)}getStageState(){return{width:this.stage.width()-this.rulerSize,height:this.stage.height()-this.rulerSize,scale:this.stage.scaleX(),x:this.stage.x(),y:this.stage.y()}}toStageValue(t){return t/this.stage.scaleX()}toBoardValue(t){return t*this.stage.scaleX()}ignore(t){return!(t instanceof e.Group)||this.ignoreSelect(t)||this.ignoreDraw(t)||this.ignoreLink(t)}ignoreSelect(t){return"selectRect"===t.id()||"hoverRect"===t.id()}ignoreDraw(t){return t.name()===El.name||t.name()===Rl.name||t.name()===Ll.name||t.name()===Wl.name||t.name()===Bl.name||t.name()===Fl.name||t.name()===Xl.name||t.name()===rc.name}ignoreLink(t){return"link-anchor"===t.name()||"linking-line"===t.name()||"link-point"===t.name()||"link-line"===t.name()||"link-manual-point"===t.name()}redraw(t){var e,n;const r=[El.name,rc.name,Fl.name,Xl.name,Rl.name,Ll.name,Bl.name,Wl.name];if(Array.isArray(t)&&!this.debug)for(const i of r)t.includes(i)&&(null==(e=this.draws[i])||e.draw());else for(const i of r)null==(n=this.draws[i])||n.draw()}changeDraggable(t){this.layer.children.forEach(e=>{e.draggable(t)})}changeGraphType(t){t&&(this.texting=!1,this.emit("texting-change",this.texting)),this.graphType=t,this.emit("graph-type-change",this.graphType),this.changeDraggable(!this.config.readonly&&void 0===this.graphType)}changeTexting(t){t&&(this.graphType=void 0,this.emit("graph-type-change",this.graphType)),this.texting=t,this.emit("texting-change",this.texting),document.body.style.cursor=this.texting?"text":"default"}getPageSettings(){return this.stage.attrs.pageSettings??{...t.PageSettingsDefault}}setPageSettings(t,e=!1){this.stage.setAttr("pageSettings",t),this.updateBackground(),e&&this.updateHistory()}getBackground(){var t;return null==(t=this.draws[El.name])?void 0:t.layer.findOne(`.${El.name}__background`)}updateBackground(){var t,e,n,r;const i=this.getBackground();i&&i.fill(this.getPageSettings().background??"transparent"),null==(t=this.draws[El.name])||t.draw(),null==(e=this.draws[rc.name])||e.draw(),null==(n=this.draws[Fl.name])||n.draw(),null==(r=this.draws[Bl.name])||r.draw()}getAssetSettings(e){const n=(null==e?void 0:e.attrs.assetSettings)??{...t.AssetSettingsDefault};return{...n,stroke:n.stroke||this.getPageSettings().stroke,strokeWidth:n.strokeWidth||this.getPageSettings().strokeWidth,fontSize:n.fontSize||this.getPageSettings().fontSize,textFill:n.textFill||this.getPageSettings().textFill,fill:n.fill||((null==e?void 0:e.attrs.assetType)===Cl.Graph?"transparent":this.getPageSettings().fill),x:parseFloat(((null==e?void 0:e.position().x)??0).toFixed(1)),y:parseFloat(((null==e?void 0:e.position().y)??0).toFixed(1)),rotation:parseFloat(((null==e?void 0:e.rotation())??0).toFixed(1)),tension:(null==e?void 0:e.attrs.assetType)===Cl.Graph&&(null==e?void 0:e.attrs.graphType)===Vl.Curve?n.tension:void 0}}setSvgXMLSettings(t,e){const n=t.match(/<(circle|ellipse|line|path|polygon|rect|text|textPath|tref|tspan)[^>/]*\/?>/g),r=/ stroke="([^"]*)"/,i=/ fill="([^"]*)"/;for(const o of n??[]){let n=o;e.stroke&&(n=r.test(o)?n.replace(r,` stroke="${e.stroke}"`):n.replace(/(<[^>/]*)(\/?>)/,`$1 stroke="${e.stroke}" $2`)),e.fill&&(n=i.test(o)?n.replace(i,` fill="${e.fill}"`):n.replace(/(<[^>/]*)(\/?>)/,`$1 fill="${e.fill}" $2`)),t=t.replace(o,n)}return t}rotatePoint({x:t,y:e},n){const r=Math.cos(n),i=Math.sin(n);return{x:t*r-e*i,y:e*r+t*i}}rotateAroundCenter(t,n){const r={x:-t.width()/2,y:-t.height()/2},i=this.rotatePoint(r,e.getAngle(t.rotation())),o=this.rotatePoint(r,e.getAngle(n)),s=o.x-i.x,a=o.y-i.y;t.rotation(n),t.x(t.x()+s),t.y(t.y()+a)}async setAssetSettings(t,n,r=!1){var i,o,s,a,h;if(t.setAttr("assetSettings",n),t instanceof e.Group){if(t.attrs.imageType===Ol.svg){const r=t.children[0];if(r instanceof e.Image&&r.attrs.svgXML){const t=await this.assetTool.loadSvgXML(this.setSvgXMLSettings(r.attrs.svgXML,n));null==(i=r.parent)||i.add(t),r.remove(),r.destroy(),t.zIndex(0)}}else if(t.attrs.assetType===Cl.Graph){const r=t.findOne(".graph");r instanceof e.Shape&&(r.strokeWidth(n.strokeWidth),r.stroke(n.stroke),r instanceof e.Arrow?r.fill(n.stroke):r.fill(n.fill),r instanceof e.Arrow&&(r.pointerAtBeginning(n.arrowStart),r.pointerAtEnding(n.arrowEnd)),r instanceof e.Arrow&&t.attrs.graphType===Vl.Curve&&r.tension(n.tension))}else if(t.attrs.assetType===Cl.Text){const r=t.findOne("Text"),i=t.findOne("Rect");if(r instanceof e.Text&&i instanceof e.Rect){let e=!1;r.fontSize()===n.fontSize&&r.text()===n.text||(e=!0),r.fill(n.textFill),r.fontSize(n.fontSize),r.text(n.text),i.fill(r.text().trim()?"":"rgba(0,0,0,0.1)"),i.width(Math.max(r.width(),n.fontSize)),i.height(Math.max(r.height(),n.fontSize)),e&&this.selectionTool.select([t])}}if(Math.abs(n.rotation-t.rotation())>=.1)this.rotateAroundCenter(t,n.rotation),this.emit("asset-position-change",[t]);else{const e=this.getAssetSettings(t);t.position({x:parseFloat(n.x.toFixed(1)),y:parseFloat(n.y.toFixed(1))}),n.x===e.x&&n.y===e.y||this.emit("asset-position-change",[t])}}r&&this.updateHistory(),null==(o=this.draws[El.name])||o.draw(),null==(s=this.draws[rc.name])||s.draw(),null==(a=this.draws[Fl.name])||a.draw(),null==(h=this.draws[Bl.name])||h.draw()}async setLinkSettings(t,e,n=!1){var r,i,o,s;const a=this.layer.findOne(`#${t.attrs.groupId}`);if(Array.isArray(null==a?void 0:a.attrs.points)){const n=(null==a?void 0:a.attrs.points).find(e=>e.id===t.attrs.pointId);if(n){const r=n.pairs.find(e=>e.id===t.attrs.pairId);r&&(r.style={...r.style,...e},a.setAttr("points",null==a?void 0:a.attrs.points))}}n&&this.updateHistory(),null==(r=this.draws[El.name])||r.draw(),null==(i=this.draws[rc.name])||i.draw(),null==(o=this.draws[Fl.name])||o.draw(),null==(s=this.draws[Bl.name])||s.draw()}getLinkSettings(e){let n;if(e){const t=this.layer.findOne(`#${e.attrs.groupId}`);if(Array.isArray(null==t?void 0:t.attrs.points)){const r=(null==t?void 0:t.attrs.points).find(t=>t.id===e.attrs.pointId);if(r){const t=r.pairs.find(t=>t.id===e.attrs.pairId);t&&(n=t.style)}}}const r=n??{...t.LinkSettingsDefault};return{...r,stroke:r.stroke||this.getPageSettings().linkStroke,strokeWidth:r.strokeWidth||this.getPageSettings().linkStrokeWidth}}};r(Ic,"PageSettingsDefault",{background:"transparent",stroke:"rgb(0,0,0)",strokeWidth:1,fill:"rgb(0,0,0)",linkStroke:"rgb(0,0,0)",linkStrokeWidth:1,fontSize:24,textFill:"rgb(0,0,0)"}),r(Ic,"AssetSettingsDefault",{stroke:"",strokeWidth:0,fill:"",arrowStart:!1,arrowEnd:!1,fontSize:0,textFill:"",text:"Text",x:0,y:0,rotation:0,tension:0}),r(Ic,"LinkSettingsDefault",{stroke:"",strokeWidth:0,arrowStart:!1,arrowEnd:!1,tension:0});let Tc=Ic;const Pc={Render:Tc};t.Render=Tc,t.default=Pc,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
24
24
  //# sourceMappingURL=webtopo.umd.js.map