var SvgCanvas=function(){"use strict"; /** * A jQuery module to work with SVG attributes. * @module jQueryAttr * @license MIT */ function t(t){const e=t.fn.attr;return t.fn.attr=function(t,n){const r=this.length;if(!r)return e.call(this,t,n);for(let s=0;s{if(!("SVGPathSeg"in window)){class t{constructor(t,e,n){this.pathSegType=t,this.pathSegTypeAsLetter=e,this._owningPathSegList=n}_segmentChanged(){this._owningPathSegList&&this._owningPathSegList.segmentChanged(this)}}t.prototype.classname="SVGPathSeg",t.PATHSEG_UNKNOWN=0,t.PATHSEG_CLOSEPATH=1,t.PATHSEG_MOVETO_ABS=2,t.PATHSEG_MOVETO_REL=3,t.PATHSEG_LINETO_ABS=4,t.PATHSEG_LINETO_REL=5,t.PATHSEG_CURVETO_CUBIC_ABS=6,t.PATHSEG_CURVETO_CUBIC_REL=7,t.PATHSEG_CURVETO_QUADRATIC_ABS=8,t.PATHSEG_CURVETO_QUADRATIC_REL=9,t.PATHSEG_ARC_ABS=10,t.PATHSEG_ARC_REL=11,t.PATHSEG_LINETO_HORIZONTAL_ABS=12,t.PATHSEG_LINETO_HORIZONTAL_REL=13,t.PATHSEG_LINETO_VERTICAL_ABS=14,t.PATHSEG_LINETO_VERTICAL_REL=15,t.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS=16,t.PATHSEG_CURVETO_CUBIC_SMOOTH_REL=17,t.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS=18,t.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL=19;class e extends t{constructor(e){super(t.PATHSEG_CLOSEPATH,"z",e)}toString(){return"[object SVGPathSegClosePath]"}_asPathString(){return this.pathSegTypeAsLetter}clone(){return new e(void 0)}}class n extends t{constructor(e,n,r){super(t.PATHSEG_MOVETO_ABS,"M",e),this._x=n,this._y=r}toString(){return"[object SVGPathSegMovetoAbs]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}clone(){return new n(void 0,this._x,this._y)}}Object.defineProperties(n.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0}});class r extends t{constructor(e,n,r){super(t.PATHSEG_MOVETO_REL,"m",e),this._x=n,this._y=r}toString(){return"[object SVGPathSegMovetoRel]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}clone(){return new r(void 0,this._x,this._y)}}Object.defineProperties(r.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0}});class s extends t{constructor(e,n,r){super(t.PATHSEG_LINETO_ABS,"L",e),this._x=n,this._y=r}toString(){return"[object SVGPathSegLinetoAbs]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}clone(){return new s(void 0,this._x,this._y)}}Object.defineProperties(s.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0}});class i extends t{constructor(e,n,r){super(t.PATHSEG_LINETO_REL,"l",e),this._x=n,this._y=r}toString(){return"[object SVGPathSegLinetoRel]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}clone(){return new i(void 0,this._x,this._y)}}Object.defineProperties(i.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0}});class o extends t{constructor(e,n,r,s,i,o,a){super(t.PATHSEG_CURVETO_CUBIC_ABS,"C",e),this._x=n,this._y=r,this._x1=s,this._y1=i,this._x2=o,this._y2=a}toString(){return"[object SVGPathSegCurvetoCubicAbs]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x1+" "+this._y1+" "+this._x2+" "+this._y2+" "+this._x+" "+this._y}clone(){return new o(void 0,this._x,this._y,this._x1,this._y1,this._x2,this._y2)}}Object.defineProperties(o.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0},x1:{get(){return this._x1},set(t){this._x1=t,this._segmentChanged()},enumerable:!0},y1:{get(){return this._y1},set(t){this._y1=t,this._segmentChanged()},enumerable:!0},x2:{get(){return this._x2},set(t){this._x2=t,this._segmentChanged()},enumerable:!0},y2:{get(){return this._y2},set(t){this._y2=t,this._segmentChanged()},enumerable:!0}});class a extends t{constructor(e,n,r,s,i,o,a){super(t.PATHSEG_CURVETO_CUBIC_REL,"c",e),this._x=n,this._y=r,this._x1=s,this._y1=i,this._x2=o,this._y2=a}toString(){return"[object SVGPathSegCurvetoCubicRel]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x1+" "+this._y1+" "+this._x2+" "+this._y2+" "+this._x+" "+this._y}clone(){return new a(void 0,this._x,this._y,this._x1,this._y1,this._x2,this._y2)}}Object.defineProperties(a.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0},x1:{get(){return this._x1},set(t){this._x1=t,this._segmentChanged()},enumerable:!0},y1:{get(){return this._y1},set(t){this._y1=t,this._segmentChanged()},enumerable:!0},x2:{get(){return this._x2},set(t){this._x2=t,this._segmentChanged()},enumerable:!0},y2:{get(){return this._y2},set(t){this._y2=t,this._segmentChanged()},enumerable:!0}});class c extends t{constructor(e,n,r,s,i){super(t.PATHSEG_CURVETO_QUADRATIC_ABS,"Q",e),this._x=n,this._y=r,this._x1=s,this._y1=i}toString(){return"[object SVGPathSegCurvetoQuadraticAbs]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x1+" "+this._y1+" "+this._x+" "+this._y}clone(){return new c(void 0,this._x,this._y,this._x1,this._y1)}}Object.defineProperties(c.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0},x1:{get(){return this._x1},set(t){this._x1=t,this._segmentChanged()},enumerable:!0},y1:{get(){return this._y1},set(t){this._y1=t,this._segmentChanged()},enumerable:!0}});class l extends t{constructor(e,n,r,s,i){super(t.PATHSEG_CURVETO_QUADRATIC_REL,"q",e),this._x=n,this._y=r,this._x1=s,this._y1=i}toString(){return"[object SVGPathSegCurvetoQuadraticRel]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x1+" "+this._y1+" "+this._x+" "+this._y}clone(){return new l(void 0,this._x,this._y,this._x1,this._y1)}}Object.defineProperties(l.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0},x1:{get(){return this._x1},set(t){this._x1=t,this._segmentChanged()},enumerable:!0},y1:{get(){return this._y1},set(t){this._y1=t,this._segmentChanged()},enumerable:!0}});class h extends t{constructor(e,n,r,s,i,o,a,c){super(t.PATHSEG_ARC_ABS,"A",e),this._x=n,this._y=r,this._r1=s,this._r2=i,this._angle=o,this._largeArcFlag=a,this._sweepFlag=c}toString(){return"[object SVGPathSegArcAbs]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._r1+" "+this._r2+" "+this._angle+" "+(this._largeArcFlag?"1":"0")+" "+(this._sweepFlag?"1":"0")+" "+this._x+" "+this._y}clone(){return new h(void 0,this._x,this._y,this._r1,this._r2,this._angle,this._largeArcFlag,this._sweepFlag)}}Object.defineProperties(h.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0},r1:{get(){return this._r1},set(t){this._r1=t,this._segmentChanged()},enumerable:!0},r2:{get(){return this._r2},set(t){this._r2=t,this._segmentChanged()},enumerable:!0},angle:{get(){return this._angle},set(t){this._angle=t,this._segmentChanged()},enumerable:!0},largeArcFlag:{get(){return this._largeArcFlag},set(t){this._largeArcFlag=t,this._segmentChanged()},enumerable:!0},sweepFlag:{get(){return this._sweepFlag},set(t){this._sweepFlag=t,this._segmentChanged()},enumerable:!0}});class u extends t{constructor(e,n,r,s,i,o,a,c){super(t.PATHSEG_ARC_REL,"a",e),this._x=n,this._y=r,this._r1=s,this._r2=i,this._angle=o,this._largeArcFlag=a,this._sweepFlag=c}toString(){return"[object SVGPathSegArcRel]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._r1+" "+this._r2+" "+this._angle+" "+(this._largeArcFlag?"1":"0")+" "+(this._sweepFlag?"1":"0")+" "+this._x+" "+this._y}clone(){return new u(void 0,this._x,this._y,this._r1,this._r2,this._angle,this._largeArcFlag,this._sweepFlag)}}Object.defineProperties(u.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0},r1:{get(){return this._r1},set(t){this._r1=t,this._segmentChanged()},enumerable:!0},r2:{get(){return this._r2},set(t){this._r2=t,this._segmentChanged()},enumerable:!0},angle:{get(){return this._angle},set(t){this._angle=t,this._segmentChanged()},enumerable:!0},largeArcFlag:{get(){return this._largeArcFlag},set(t){this._largeArcFlag=t,this._segmentChanged()},enumerable:!0},sweepFlag:{get(){return this._sweepFlag},set(t){this._sweepFlag=t,this._segmentChanged()},enumerable:!0}});class d extends t{constructor(e,n){super(t.PATHSEG_LINETO_HORIZONTAL_ABS,"H",e),this._x=n}toString(){return"[object SVGPathSegLinetoHorizontalAbs]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x}clone(){return new d(void 0,this._x)}}Object.defineProperty(d.prototype,"x",{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0});class m extends t{constructor(e,n){super(t.PATHSEG_LINETO_HORIZONTAL_REL,"h",e),this._x=n}toString(){return"[object SVGPathSegLinetoHorizontalRel]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x}clone(){return new m(void 0,this._x)}}Object.defineProperty(m.prototype,"x",{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0});class g extends t{constructor(e,n){super(t.PATHSEG_LINETO_VERTICAL_ABS,"V",e),this._y=n}toString(){return"[object SVGPathSegLinetoVerticalAbs]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._y}clone(){return new g(void 0,this._y)}}Object.defineProperty(g.prototype,"y",{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0});class p extends t{constructor(e,n){super(t.PATHSEG_LINETO_VERTICAL_REL,"v",e),this._y=n}toString(){return"[object SVGPathSegLinetoVerticalRel]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._y}clone(){return new p(void 0,this._y)}}Object.defineProperty(p.prototype,"y",{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0});class f extends t{constructor(e,n,r,s,i){super(t.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS,"S",e),this._x=n,this._y=r,this._x2=s,this._y2=i}toString(){return"[object SVGPathSegCurvetoCubicSmoothAbs]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x2+" "+this._y2+" "+this._x+" "+this._y}clone(){return new f(void 0,this._x,this._y,this._x2,this._y2)}}Object.defineProperties(f.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0},x2:{get(){return this._x2},set(t){this._x2=t,this._segmentChanged()},enumerable:!0},y2:{get(){return this._y2},set(t){this._y2=t,this._segmentChanged()},enumerable:!0}});class y extends t{constructor(e,n,r,s,i){super(t.PATHSEG_CURVETO_CUBIC_SMOOTH_REL,"s",e),this._x=n,this._y=r,this._x2=s,this._y2=i}toString(){return"[object SVGPathSegCurvetoCubicSmoothRel]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x2+" "+this._y2+" "+this._x+" "+this._y}clone(){return new y(void 0,this._x,this._y,this._x2,this._y2)}}Object.defineProperties(y.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0},x2:{get(){return this._x2},set(t){this._x2=t,this._segmentChanged()},enumerable:!0},y2:{get(){return this._y2},set(t){this._y2=t,this._segmentChanged()},enumerable:!0}});class x extends t{constructor(e,n,r){super(t.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS,"T",e),this._x=n,this._y=r}toString(){return"[object SVGPathSegCurvetoQuadraticSmoothAbs]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}clone(){return new x(void 0,this._x,this._y)}}Object.defineProperties(x.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0}});class S extends t{constructor(e,n,r){super(t.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL,"t",e),this._x=n,this._y=r}toString(){return"[object SVGPathSegCurvetoQuadraticSmoothRel]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}clone(){return new S(void 0,this._x,this._y)}}Object.defineProperties(S.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0}}),SVGPathElement.prototype.createSVGPathSegClosePath=function(){return new e(void 0)},SVGPathElement.prototype.createSVGPathSegMovetoAbs=function(t,e){return new n(void 0,t,e)},SVGPathElement.prototype.createSVGPathSegMovetoRel=function(t,e){return new r(void 0,t,e)},SVGPathElement.prototype.createSVGPathSegLinetoAbs=function(t,e){return new s(void 0,t,e)},SVGPathElement.prototype.createSVGPathSegLinetoRel=function(t,e){return new i(void 0,t,e)},SVGPathElement.prototype.createSVGPathSegCurvetoCubicAbs=function(t,e,n,r,s,i){return new o(void 0,t,e,n,r,s,i)},SVGPathElement.prototype.createSVGPathSegCurvetoCubicRel=function(t,e,n,r,s,i){return new a(void 0,t,e,n,r,s,i)},SVGPathElement.prototype.createSVGPathSegCurvetoQuadraticAbs=function(t,e,n,r){return new c(void 0,t,e,n,r)},SVGPathElement.prototype.createSVGPathSegCurvetoQuadraticRel=function(t,e,n,r){return new l(void 0,t,e,n,r)},SVGPathElement.prototype.createSVGPathSegArcAbs=function(t,e,n,r,s,i,o){return new h(void 0,t,e,n,r,s,i,o)},SVGPathElement.prototype.createSVGPathSegArcRel=function(t,e,n,r,s,i,o){return new u(void 0,t,e,n,r,s,i,o)},SVGPathElement.prototype.createSVGPathSegLinetoHorizontalAbs=function(t){return new d(void 0,t)},SVGPathElement.prototype.createSVGPathSegLinetoHorizontalRel=function(t){return new m(void 0,t)},SVGPathElement.prototype.createSVGPathSegLinetoVerticalAbs=function(t){return new g(void 0,t)},SVGPathElement.prototype.createSVGPathSegLinetoVerticalRel=function(t){return new p(void 0,t)},SVGPathElement.prototype.createSVGPathSegCurvetoCubicSmoothAbs=function(t,e,n,r){return new f(void 0,t,e,n,r)},SVGPathElement.prototype.createSVGPathSegCurvetoCubicSmoothRel=function(t,e,n,r){return new y(void 0,t,e,n,r)},SVGPathElement.prototype.createSVGPathSegCurvetoQuadraticSmoothAbs=function(t,e){return new x(void 0,t,e)},SVGPathElement.prototype.createSVGPathSegCurvetoQuadraticSmoothRel=function(t,e){return new S(void 0,t,e)},"getPathSegAtLength"in SVGPathElement.prototype||(SVGPathElement.prototype.getPathSegAtLength=function(t){if(void 0===t||!isFinite(t))throw new Error("Invalid arguments.");const e=document.createElementNS("http://www.w3.org/2000/svg","path");e.setAttribute("d",this.getAttribute("d"));let n=e.pathSegList.numberOfItems-1;if(n<=0)return 0;do{if(e.pathSegList.removeItem(n),t>e.getTotalLength())break;n--}while(n>0);return n}),window.SVGPathSeg=t,window.SVGPathSegClosePath=e,window.SVGPathSegMovetoAbs=n,window.SVGPathSegMovetoRel=r,window.SVGPathSegLinetoAbs=s,window.SVGPathSegLinetoRel=i,window.SVGPathSegCurvetoCubicAbs=o,window.SVGPathSegCurvetoCubicRel=a,window.SVGPathSegCurvetoQuadraticAbs=c,window.SVGPathSegCurvetoQuadraticRel=l,window.SVGPathSegArcAbs=h,window.SVGPathSegArcRel=u,window.SVGPathSegLinetoHorizontalAbs=d,window.SVGPathSegLinetoHorizontalRel=m,window.SVGPathSegLinetoVerticalAbs=g,window.SVGPathSegLinetoVerticalRel=p,window.SVGPathSegCurvetoCubicSmoothAbs=f,window.SVGPathSegCurvetoCubicSmoothRel=y,window.SVGPathSegCurvetoQuadraticSmoothAbs=x,window.SVGPathSegCurvetoQuadraticSmoothRel=S}if(!("SVGPathSegList"in window)||!("appendItem"in window.SVGPathSegList.prototype)){class t{constructor(t){this._pathElement=t,this._list=this._parsePath(this._pathElement.getAttribute("d")),this._mutationObserverConfig={attributes:!0,attributeFilter:["d"]},this._pathElementMutationObserver=new MutationObserver(this._updateListFromPathMutations.bind(this)),this._pathElementMutationObserver.observe(this._pathElement,this._mutationObserverConfig)}_checkPathSynchronizedToList(){this._updateListFromPathMutations(this._pathElementMutationObserver.takeRecords())}_updateListFromPathMutations(t){if(!this._pathElement)return;let e=!1;t.forEach(t=>{"d"===t.attributeName&&(e=!0)}),e&&(this._list=this._parsePath(this._pathElement.getAttribute("d")))}_writeListToPath(){this._pathElementMutationObserver.disconnect(),this._pathElement.setAttribute("d",t._pathSegArrayAsString(this._list)),this._pathElementMutationObserver.observe(this._pathElement,this._mutationObserverConfig)}segmentChanged(t){this._writeListToPath()}clear(){this._checkPathSynchronizedToList(),this._list.forEach(t=>{t._owningPathSegList=null}),this._list=[],this._writeListToPath()}initialize(t){return this._checkPathSynchronizedToList(),this._list=[t],t._owningPathSegList=this,this._writeListToPath(),t}_checkValidIndex(t){if(isNaN(t)||t<0||t>=this.numberOfItems)throw new Error("INDEX_SIZE_ERR")}getItem(t){return this._checkPathSynchronizedToList(),this._checkValidIndex(t),this._list[t]}insertItemBefore(t,e){return this._checkPathSynchronizedToList(),e>this.numberOfItems&&(e=this.numberOfItems),t._owningPathSegList&&(t=t.clone()),this._list.splice(e,0,t),t._owningPathSegList=this,this._writeListToPath(),t}replaceItem(t,e){return this._checkPathSynchronizedToList(),t._owningPathSegList&&(t=t.clone()),this._checkValidIndex(e),this._list[e]=t,t._owningPathSegList=this,this._writeListToPath(),t}removeItem(t){this._checkPathSynchronizedToList(),this._checkValidIndex(t);const e=this._list[t];return this._list.splice(t,1),this._writeListToPath(),e}appendItem(t){return this._checkPathSynchronizedToList(),t._owningPathSegList&&(t=t.clone()),this._list.push(t),t._owningPathSegList=this,this._writeListToPath(),t}_parsePath(t){if(!t||!t.length)return[];const e=this;const n=new class{constructor(){this.pathSegList=[]}appendSegment(t){this.pathSegList.push(t)}},r=new class{constructor(t){this._string=t,this._currentIndex=0,this._endIndex=this._string.length,this._previousCommand=SVGPathSeg.PATHSEG_UNKNOWN,this._skipOptionalSpaces()}_isCurrentSpace(){const t=this._string[this._currentIndex];return t<=" "&&(" "===t||"\n"===t||"\t"===t||"\r"===t||"\f"===t)}_skipOptionalSpaces(){for(;this._currentIndex="0"&&t<="9")&&e!==SVGPathSeg.PATHSEG_CLOSEPATH?e===SVGPathSeg.PATHSEG_MOVETO_ABS?SVGPathSeg.PATHSEG_LINETO_ABS:e===SVGPathSeg.PATHSEG_MOVETO_REL?SVGPathSeg.PATHSEG_LINETO_REL:e:SVGPathSeg.PATHSEG_UNKNOWN}initialCommandIsMoveTo(){if(!this.hasMoreData())return!0;const t=this.peekSegmentType();return t===SVGPathSeg.PATHSEG_MOVETO_ABS||t===SVGPathSeg.PATHSEG_MOVETO_REL}_parseNumber(){let t=0,e=0,n=1,r=0,s=1,i=1;const o=this._currentIndex;if(this._skipOptionalSpaces(),this._currentIndex"9")&&"."!==this._string.charAt(this._currentIndex))return;const a=this._currentIndex;for(;this._currentIndex="0"&&this._string.charAt(this._currentIndex)<="9";)this._currentIndex++;if(this._currentIndex!==a){let t=this._currentIndex-1,n=1;for(;t>=a;)e+=n*(this._string.charAt(t--)-"0"),n*=10}if(this._currentIndex=this._endIndex||this._string.charAt(this._currentIndex)<"0"||this._string.charAt(this._currentIndex)>"9")return;for(;this._currentIndex="0"&&this._string.charAt(this._currentIndex)<="9";)n*=10,r+=(this._string.charAt(this._currentIndex)-"0")/n,this._currentIndex+=1}if(this._currentIndex!==o&&this._currentIndex+1=this._endIndex||this._string.charAt(this._currentIndex)<"0"||this._string.charAt(this._currentIndex)>"9")return;for(;this._currentIndex="0"&&this._string.charAt(this._currentIndex)<="9";)t*=10,t+=this._string.charAt(this._currentIndex)-"0",this._currentIndex++}let c=e+r;return c*=s,t&&(c*=10**(i*t)),o!==this._currentIndex?(this._skipOptionalSpacesOrDelimiter(),c):void 0}_parseArcFlag(){if(this._currentIndex>=this._endIndex)return;let t=!1;const e=this._string.charAt(this._currentIndex++);if("0"===e)t=!1;else{if("1"!==e)return;t=!0}return this._skipOptionalSpacesOrDelimiter(),t}parseSegment(){const t=this._string[this._currentIndex];let n=this._pathSegTypeFromChar(t);if(n===SVGPathSeg.PATHSEG_UNKNOWN){if(this._previousCommand===SVGPathSeg.PATHSEG_UNKNOWN)return null;if(n=this._nextCommandHelper(t,this._previousCommand),n===SVGPathSeg.PATHSEG_UNKNOWN)return null}else this._currentIndex++;switch(this._previousCommand=n,n){case SVGPathSeg.PATHSEG_MOVETO_REL:return new SVGPathSegMovetoRel(e,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_MOVETO_ABS:return new SVGPathSegMovetoAbs(e,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_REL:return new SVGPathSegLinetoRel(e,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_ABS:return new SVGPathSegLinetoAbs(e,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL:return new SVGPathSegLinetoHorizontalRel(e,this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS:return new SVGPathSegLinetoHorizontalAbs(e,this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_VERTICAL_REL:return new SVGPathSegLinetoVerticalRel(e,this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS:return new SVGPathSegLinetoVerticalAbs(e,this._parseNumber());case SVGPathSeg.PATHSEG_CLOSEPATH:return this._skipOptionalSpaces(),new SVGPathSegClosePath(e);case SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL:{const t={x1:this._parseNumber(),y1:this._parseNumber(),x2:this._parseNumber(),y2:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoCubicRel(e,t.x,t.y,t.x1,t.y1,t.x2,t.y2)}case SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS:{const t={x1:this._parseNumber(),y1:this._parseNumber(),x2:this._parseNumber(),y2:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoCubicAbs(e,t.x,t.y,t.x1,t.y1,t.x2,t.y2)}case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL:{const t={x2:this._parseNumber(),y2:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoCubicSmoothRel(e,t.x,t.y,t.x2,t.y2)}case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:{const t={x2:this._parseNumber(),y2:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoCubicSmoothAbs(e,t.x,t.y,t.x2,t.y2)}case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL:{const t={x1:this._parseNumber(),y1:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoQuadraticRel(e,t.x,t.y,t.x1,t.y1)}case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS:{const t={x1:this._parseNumber(),y1:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoQuadraticAbs(e,t.x,t.y,t.x1,t.y1)}case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL:return new SVGPathSegCurvetoQuadraticSmoothRel(e,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS:return new SVGPathSegCurvetoQuadraticSmoothAbs(e,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_ARC_REL:{const t={x1:this._parseNumber(),y1:this._parseNumber(),arcAngle:this._parseNumber(),arcLarge:this._parseArcFlag(),arcSweep:this._parseArcFlag(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegArcRel(e,t.x,t.y,t.x1,t.y1,t.arcAngle,t.arcLarge,t.arcSweep)}case SVGPathSeg.PATHSEG_ARC_ABS:{const t={x1:this._parseNumber(),y1:this._parseNumber(),arcAngle:this._parseNumber(),arcLarge:this._parseArcFlag(),arcSweep:this._parseArcFlag(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegArcAbs(e,t.x,t.y,t.x1,t.y1,t.arcAngle,t.arcLarge,t.arcSweep)}default:throw new Error("Unknown path seg type.")}}}(t);if(!r.initialCommandIsMoveTo())return[];for(;r.hasMoreData();){const t=r.parseSegment();if(!t)return[];n.appendSegment(t)}return n.pathSegList}static _pathSegArrayAsString(t){let e="",n=!0;return t.forEach(t=>{n?(n=!1,e+=t._asPathString()):e+=" "+t._asPathString()}),e}}t.prototype.classname="SVGPathSegList",Object.defineProperty(t.prototype,"numberOfItems",{get(){return this._checkPathSynchronizedToList(),this._list.length},enumerable:!0}),Object.defineProperties(SVGPathElement.prototype,{pathSegList:{get(){return this._pathSegList||(this._pathSegList=new t(this)),this._pathSegList},enumerable:!0},normalizedPathSegList:{get(){return this.pathSegList},enumerable:!0},animatedPathSegList:{get(){return this.pathSegList},enumerable:!0},animatedNormalizedPathSegList:{get(){return this.pathSegList},enumerable:!0}}),window.SVGPathSegList=t}})(); /** * Namespaces or tools therefor. * @module namespaces * @license MIT */ const e={HTML:"http://www.w3.org/1999/xhtml",MATH:"http://www.w3.org/1998/Math/MathML",SE:"http://svg-edit.googlecode.com",SVG:"http://www.w3.org/2000/svg",XLINK:"http://www.w3.org/1999/xlink",XML:"http://www.w3.org/XML/1998/namespace",XMLNS:"http://www.w3.org/2000/xmlns/"},n=function(){const t={};return Object.entries(e).forEach(([e,n])=>{t[n]=e.toLowerCase()}),t},r=jQuery,{userAgent:s}=(Boolean(document.createElementNS&&document.createElementNS(e.SVG,"svg").createSVGRect),navigator),i=document.createElementNS(e.SVG,"svg"),o=Boolean(window.opera),a=s.includes("AppleWebKit"),c=s.includes("Gecko/"),l=s.includes("MSIE"),h=s.includes("Chrome/"),u=(s.includes("Windows"),s.includes("Macintosh"),"ontouchstart"in window),d=Boolean(i.querySelector),m=Boolean(document.evaluate),g=function(){const t=document.createElementNS(e.SVG,"path");t.setAttribute("d","M0,0 10,10");const n=t.pathSegList,r=t.createSVGPathSegLinetoAbs(5,5);try{return n.replaceItem(r,1),!0}catch(t){}return!1}(),p=function(){const t=document.createElementNS(e.SVG,"path");t.setAttribute("d","M0,0 10,10");const n=t.pathSegList,r=t.createSVGPathSegLinetoAbs(5,5);try{return n.insertItemBefore(r,1),!0}catch(t){}return!1}(),f=function(){const t=document.createElementNS(e.SVG,"svg"),n=document.createElementNS(e.SVG,"svg");document.documentElement.append(t),n.setAttribute("x",5),t.append(n);const r=document.createElementNS(e.SVG,"text");r.textContent="a",n.append(r);try{return 0===r.getStartPositionOfChar(0).x}catch(t){return!1}finally{t.remove()}}(),y=function(){const t=document.createElementNS(e.SVG,"svg");document.documentElement.append(t);const n=document.createElementNS(e.SVG,"path");n.setAttribute("d","M0,0 C0,0 10,10 10,0"),t.append(n);const r=n.getBBox();return t.remove(),r.height>4&&r.height<5}(),x=function(){const t=document.createElementNS(e.SVG,"svg");document.documentElement.append(t);const n=document.createElementNS(e.SVG,"path");n.setAttribute("d","M0,0 10,0");const r=document.createElementNS(e.SVG,"path");r.setAttribute("d","M5,0 15,0");const s=document.createElementNS(e.SVG,"g");s.append(n,r),t.append(s);const i=s.getBBox();return t.remove(),15===i.width}(),S=(function(){const t=document.createElementNS(e.SVG,"rect");t.setAttribute("x",.1);const n=!t.cloneNode(!1).getAttribute("x").includes(",");n||r.alert('NOTE: This version of Opera is known to contain bugs in SVG-edit.\nPlease upgrade to the latest version in which the problems have been fixed.')}(),function(){const t=document.createElementNS(e.SVG,"rect");return t.setAttribute("style","vector-effect:non-scaling-stroke"),"non-scaling-stroke"===t.style.vectorEffect}());let _=function(){const t=document.createElementNS(e.SVG,"rect").transform.baseVal,n=i.createSVGTransform();t.appendItem(n);const r=t.getItem(0),s=t=>t&&"object"==typeof t&&"function"==typeof t.setMatrix&&"angle"in t;return s(r)&&s(n)&&r.type===n.type&&r.angle===n.angle&&r.matrix.a===n.matrix.a&&r.matrix.b===n.matrix.b&&r.matrix.c===n.matrix.c&&r.matrix.d===n.matrix.d&&r.matrix.e===n.matrix.e&&r.matrix.f===n.matrix.f}();const b=()=>a,w=()=>c,A=()=>l,C=()=>h,v=()=>S,E=document.createElementNS(e.SVG,"svg");function G(t){const e=t.matrix;let n="";switch(t.type){case 1:n="matrix("+[e.a,e.b,e.c,e.d,e.e,e.f].join(",")+")";break;case 2:n="translate("+e.e+","+e.f+")";break;case 3:n=e.a===e.d?"scale("+e.a+")":"scale("+e.a+","+e.d+")";break;case 4:{let r=0,s=0;if(0!==t.angle){const t=1-e.a;s=(t*e.f+e.b*e.e)/(t*t+e.b*e.b),r=(e.e-e.b*s)/t}n="rotate("+t.angle+" "+r+","+s+")";break}}return n}let N={};class k{constructor(t){this._elem=t||null,this._xforms=[],this._update=function(){let t="";for(let e=0;e{for(let n=0,r=e._xforms.length;n=0)return this._xforms[t];const e=new Error("DOMException with code=INDEX_SIZE_ERR");throw e.code=1,e}insertItemBefore(t,e){let n=null;if(e>=0)if(e=0&&(this._removeFromOtherLists(t),this._xforms[e]=t,n=t,this._list._update()),n}removeItem(t){if(t=0){const e=this._xforms[t],n=new Array(this.numberOfItems-1);let r;for(r=0;re.multiply(t));return Math.abs(e.a)<1e-14&&(e.a=0),Math.abs(e.b)<1e-14&&(e.b=0),Math.abs(e.c)<1e-14&&(e.c=0),Math.abs(e.d)<1e-14&&(e.d=0),Math.abs(e.e)<1e-14&&(e.e=0),Math.abs(e.f)<1e-14&&(e.f=0),e},M=function(t){if(!t)return!1;let e=t.numberOfItems;for(;e--;){const n=t.getItem(e);if(1===n.type&&!V(n.matrix))return!0}return!1},R=function(t,e,n,r,s){const i=L(t,e,s),o=L(t+n,e,s),a=L(t,e+r,s),c=L(t+n,e+r,s),l=Math.min(i.x,o.x,a.x,c.x),h=Math.max(i.x,o.x,a.x,c.x),u=Math.min(i.y,o.y,a.y,c.y);return{tl:i,tr:o,bl:a,br:c,aabox:{x:l,y:u,width:h-l,height:Math.max(i.y,o.y,a.y,c.y)-u}}},B=function(t,e,n){if(Nt(t))return T.createSVGTransformFromMatrix(T.createSVGMatrix());if(e=e||0,n=n||t.numberOfItems-1,(e=Number.parseInt(e))>(n=Number.parseInt(n))){const t=n;n=e,e=t}let r=T.createSVGMatrix();for(let s=e;s<=n;++s){const e=s>=0&&st.x&&e.yt.y},F=t(jQuery),D="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",z="a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use,clipPath".split(","); /** * Mathematical utilities. * @module math * @license MIT * * @copyright 2010 Alexis Deveria, 2010 Jeff Schiller */let q=null,Q=null,W=null,X=null;const K=t=>t.replace(/()/,"$1$2"),Z=function(t){return t.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")};function Y(t){if(t=tt(t),window.btoa)return window.btoa(t);const e=new Array(4*Math.floor((t.length+2)/3));let n=0,r=0;do{const s=t.charCodeAt(n++),i=t.charCodeAt(n++),o=t.charCodeAt(n++),a=s>>2,c=(3&s)<<4|i>>4;let l=(15&i)<<2|o>>6,h=63&o;Number.isNaN(i)?(l=64,h=64):Number.isNaN(o)&&(h=64),e[r++]=D.charAt(a),e[r++]=D.charAt(c),e[r++]=D.charAt(l),e[r++]=D.charAt(h)}while(n>4,c=(15&s)<<4|i>>2,l=(3&i)<<6|o;e+=String.fromCharCode(a),64!==i&&(e+=String.fromCharCode(c)),64!==o&&(e+=String.fromCharCode(l))}while(nSVG-edit "],{type:"text/html"});et(t)}(),function(t){let e,n;t.includes("0?n=n[0]:(n=t.ownerDocument.createElementNS(e.SVG,"defs"),t.firstChild?t.insertBefore(n,t.firstChild.nextSibling):t.append(n)),n},ct=function(t){const e=t.pathSegList,n=e.numberOfItems,r=[[],[]],s=e.getItem(0);let i=[s.x,s.y];const o=function(t,e,n,r){return function(s){return 1-s**3*i[t]+3-s**2*s*e[t]+3*(1-s)*s**2*n[t]+s**3*r[t]}};for(let t=0;t0&&t<1&&r[n].push(a(t));continue}const u=c**2-4*h*l;if(u<0)continue;const d=(-c+Math.sqrt(u))/(2*l);d>0&&d<1&&r[n].push(a(d));const m=(-c-Math.sqrt(u))/(2*l);m>0&&m<1&&r[n].push(a(m))}i=s}else r[0].push(n.x),r[1].push(n.y)}const a=Math.min.apply(null,r[0]),c=Math.max.apply(null,r[0])-a,l=Math.min.apply(null,r[1]);return{x:a,y:l,width:c,height:Math.max.apply(null,r[1])-l}};function lt(t){if(x)try{return t.getBBox()}catch(t){}const e=F.data(t,"ref");let n,r,s=null;e?(r=F(e).children().clone().attr("visibility","hidden"),F(X).append(r),s=r.filter("line, path")):s=F(t).find("line, path");let i=!1;if(s.length)if(s.each((function(){const t=this.getBBox();t.width&&t.height||(i=!0)})),i){const s=e?r:F(t).children();n=yt(s)}else n=t.getBBox();else n=t.getBBox();return e&&r.remove(),n}const ht=function(t){const e=t||q.geSelectedElements()[0];if(1!==t.nodeType)return null;const n=e.nodeName;let r=null;switch(n){case"text":""===e.textContent?(e.textContent="a",r=e.getBBox(),e.textContent=""):e.getBBox&&(r=e.getBBox());break;case"path":y?e.getBBox&&(r=e.getBBox()):r=ct(e);break;case"g":case"a":r=lt(e);break;default:if("use"===n&&(r=lt(e)),"use"===n||"foreignObject"===n&&b()){if(r||(r=e.getBBox()),!b()){const{x:t,y:n,width:s,height:i}=r;r={width:s,height:i,x:t+Number.parseFloat(e.getAttribute("x")||0),y:n+Number.parseFloat(e.getAttribute("y")||0)}}}else if(z.includes(n))if(e)try{r=e.getBBox()}catch(t){const n=e.getExtentOfChar(0),s=e.getComputedTextLength();r={x:n.x,y:n.y,width:s,height:n.height}}else{const t=F(e).closest("foreignObject");t.length&&t[0].getBBox&&(r=t[0].getBBox())}}return r&&(r=function({x:t,y:e,width:n,height:r}){return{x:t,y:e,width:n,height:r}}(r)),r},ut=function(t){let e="";return F.each(t,(function(t,[n,r]){e+=n;for(let t=0;t-.001&&n<.001||(n<-89.99||n>89.99))}(i,o)){if(["ellipse","path","line","polyline","polygon"].includes(t.tagName))a=gt(t,e,n),r=a;else if("rect"===t.tagName){const s=t.getAttribute("rx"),i=t.getAttribute("ry");(s||i)&&(a=gt(t,e,n),r=a)}}if(!a){const{matrix:t}=B(s);r=R(r.x,r.y,r.width,r.height,t).aabox}}return r};function ft(t){const e=t.getAttribute("stroke-width");return isNaN(e)||"none"===t.getAttribute("stroke")?0:e/2}const yt=function(t,e,n){if(!t||!t.length)return!1;let r;if(F.each(t,(function(){r||this.parentNode&&(r=pt(this,e,n))})),void 0===r)return null;let s=r.x+r.width,i=r.y+r.height,o=r.x,a=r.y;if(1===t.length){const e=ft(t[0]);o-=e,a-=e,s+=e,i+=e}else F.each(t,(function(t,r){const c=pt(r,e,n);if(c){const t=ft(r);o=Math.min(o,c.x-t),a=Math.min(a,c.y-t),1===r.nodeType&&(s=Math.max(s,c.x+c.width+t),i=Math.max(i,c.y+c.height+t))}}));return r.x=o,r.y=a,r.width=s-o,r.height=i-a,r},xt=function(t){t||(t=F(q.getSVGContent()).children());const e=[];return F(t).children().each((function(t,n){n.getBBox&&e.push(n)})),e.reverse()},St=function(t){return t||(t=xt()),yt(t,q.addSVGElementFromJson,q.pathActions)},_t=function(t,e){if(!t)return 0;const n=t.numberOfItems;for(let r=0;r{t.getAttribute(e)===String(n)&&t.removeAttribute(e)})},Et=function(t){const e=q.getBaseUnit();let n=q.getSnappingStep();return"px"!==e&&(n*=Lt()[e]),t=Math.round(t/n)*n},Gt=function(t){F(t).click((function(t){t.preventDefault()}))},Nt=t=>null==t,kt=["x","x1","cx","rx","width"],It=["y","y1","cy","ry","height"];let Pt,Tt={};const Lt=function(){return Tt},Vt=function(t){const e=Pt.getRoundDigits();return isNaN(t)?Array.isArray(t)?Vt(t[0])+","+Vt(t[1]):Number.parseFloat(t).toFixed(e)-0:Number(Number(t).toFixed(e))},Ot=function(t,e){return e=e||Pt.getBaseUnit(),Vt(t/Tt[e])},Mt=function(t,e,n){t.setAttribute(e,n)},Rt=function(t,e){if(!isNaN(e))return e-0;if("%"===e.substr(-1)){const n=e.substr(0,e.length-1)/100,r=Pt.getWidth(),s=Pt.getHeight();return kt.includes(t)?n*r:It.includes(t)?n*s:n*Math.sqrt(r*r+s*s)/Math.sqrt(2)}const n=e.substr(-2);return e.substr(0,e.length-2)*Tt[n]},Bt={BEFORE_APPLY:"before_apply",AFTER_APPLY:"after_apply",BEFORE_UNAPPLY:"before_unapply",AFTER_UNAPPLY:"after_unapply"};class Ut{getText(){return this.text}apply(t,e){t&&t.handleHistoryEvent(Bt.BEFORE_APPLY,this),e(t),t&&t.handleHistoryEvent(Bt.AFTER_APPLY,this)}unapply(t,e){t&&t.handleHistoryEvent(Bt.BEFORE_UNAPPLY,this),e(),t&&t.handleHistoryEvent(Bt.AFTER_UNAPPLY,this)}elements(){return[this.elem]}type(){return this.constructor.name}}class jt extends Ut{constructor(t,e,n,r){super(),this.elem=t,this.text=r?"Move "+t.tagName+" to "+r:"Move "+t.tagName,this.oldNextSibling=e,this.oldParent=n,this.newNextSibling=t.nextSibling,this.newParent=t.parentNode}apply(t){super.apply(t,()=>{this.elem=this.newParent.insertBefore(this.elem,this.newNextSibling)})}unapply(t){super.unapply(t,()=>{this.elem=this.oldParent.insertBefore(this.elem,this.oldNextSibling)})}}class Ht extends Ut{constructor(t,e){super(),this.elem=t,this.text=e||"Create "+t.tagName,this.parent=t.parentNode,this.nextSibling=this.elem.nextSibling}apply(t){super.apply(t,()=>{this.elem=this.parent.insertBefore(this.elem,this.nextSibling)})}unapply(t){super.unapply(t,()=>{this.parent=this.elem.parentNode,this.elem.remove()})}}class Ft extends Ut{constructor(t,e,n,r){super(),this.elem=t,this.text=r||"Delete "+t.tagName,this.nextSibling=e,this.parent=n,I(t)}apply(t){super.apply(t,()=>{I(this.elem),this.parent=this.elem.parentNode,this.elem.remove()})}unapply(t){super.unapply(t,()=>{I(this.elem),Nt(this.nextSibling)&&window.console&&console.error("Reference element was lost"),this.parent.insertBefore(this.elem,this.nextSibling)})}}class Dt extends Ut{constructor(t,e,n){super(),this.elem=t,this.text=n?"Change "+t.tagName+" "+n:"Change "+t.tagName,this.newValues={},this.oldValues=e;for(const n in e)this.newValues[n]="#text"===n?t.textContent:"#href"===n?it(t):t.getAttribute(n)}apply(t){super.apply(t,()=>{let t=!1;if(Object.entries(this.newValues).forEach(([e,n])=>{n?"#text"===e?this.elem.textContent=n:"#href"===e?ot(this.elem,n):this.elem.setAttribute(e,n):"#text"===e?this.elem.textContent="":(this.elem.setAttribute(e,""),this.elem.removeAttribute(e)),"transform"===e&&(t=!0)}),!t){const t=bt(this.elem);if(t){const e=this.elem.getBBox(),n=["rotate(",t," ",e.x+e.width/2,",",e.y+e.height/2,")"].join("");n!==this.elem.getAttribute("transform")&&this.elem.setAttribute("transform",n)}}})}unapply(t){super.unapply(t,()=>{let t=!1;if(Object.entries(this.oldValues).forEach(([e,n])=>{n?"#text"===e?this.elem.textContent=n:"#href"===e?ot(this.elem,n):this.elem.setAttribute(e,n):"#text"===e?this.elem.textContent="":this.elem.removeAttribute(e),"transform"===e&&(t=!0)}),!t){const t=bt(this.elem);if(t){const e=this.elem.getBBox(),n=["rotate(",t," ",e.x+e.width/2,",",e.y+e.height/2,")"].join("");n!==this.elem.getAttribute("transform")&&this.elem.setAttribute("transform",n)}}I(this.elem)})}}class zt extends Ut{constructor(t){super(),this.text=t||"Batch Command",this.stack=[]}apply(t){super.apply(t,()=>{this.stack.forEach(e=>{console.assert(e,"stack item should not be null"),e&&e.apply(t)})})}unapply(t){super.unapply(t,()=>{this.stack.reverse().forEach(e=>{console.assert(e,"stack item should not be null"),e&&e.unapply(t)})})}elements(){const t=[];let e=this.stack.length;for(;e--;){if(!this.stack[e])continue;const n=this.stack[e].elements();let r=n.length;for(;r--;)t.includes(n[r])||t.push(n[r])}return t}addSubCommand(t){console.assert(null!==t,"cmd should not be null"),this.stack.push(t)}isEmpty(){return!this.stack.length}}var qt=Object.freeze({__proto__:null,HistoryEventTypes:Bt,Command:Ut,MoveElementCommand:jt,InsertElementCommand:Ht,RemoveElementCommand:Ft,ChangeElementCommand:Dt,BatchCommand:zt,UndoManager:class{constructor(t){this.handler_=t||null,this.undoStackPointer=0,this.undoStack=[],this.undoChangeStackPointer=-1,this.undoableChangeStack=[]}resetUndoStack(){this.undoStack=[],this.undoStackPointer=0}getUndoStackSize(){return this.undoStackPointer}getRedoStackSize(){return this.undoStack.length-this.undoStackPointer}getNextUndoCommandText(){return this.undoStackPointer>0?this.undoStack[this.undoStackPointer-1].getText():""}getNextRedoCommandText(){return this.undoStackPointer0){this.undoStack[--this.undoStackPointer].unapply(this.handler_)}}redo(){if(this.undoStackPointer0){this.undoStack[this.undoStackPointer++].apply(this.handler_)}}addCommandToHistory(t){this.undoStackPointer0&&(this.undoStack=this.undoStack.splice(0,this.undoStackPointer)),this.undoStack.push(t),this.undoStackPointer=this.undoStack.length}beginUndoableChange(t,e){const n=++this.undoChangeStackPointer;let r=e.length;const s=new Array(r),i=new Array(r);for(;r--;){const n=e[r];Nt(n)||(i[r]=n,s[r]=n.getAttribute(t))}this.undoableChangeStack[n]={attrName:t,oldValues:s,elements:i}}finishUndoableChange(){const t=this.undoChangeStackPointer--,e=this.undoableChangeStack[t],{attrName:n}=e,r=new zt("Change "+n);let s=e.elements.length;for(;s--;){const t=e.elements[s];if(Nt(t))continue;const i={};i[n]=e.oldValues[s],i[n]!==t.getAttribute(n)&&r.addSubCommand(new Dt(t,i,n))}return this.undoableChangeStack[t]=null,r}}});const Qt=jQuery,Wt={2:["x","y"],4:["x","y"],6:["x","y","x1","y1","x2","y2"],8:["x","y","x1","y1"],10:["x","y","r1","r2","angle","largeArcFlag","sweepFlag"],12:["x"],14:["y"],16:["x","y","x2","y2"],18:["x","y"]},Xt={},Kt=function(t){Object.assign(Xt,t.ui)};let Zt=[],Yt=!0,$t={};const Jt=function(t){Yt=t};let te=null,ee=null;const ne=function(t){ee=t,Zt=[0,"ClosePath"];Qt.each(["Moveto","Lineto","CurvetoCubic","CurvetoQuadratic","Arc","LinetoHorizontal","LinetoVertical","CurvetoCubicSmooth","CurvetoQuadraticSmooth"],(function(t,e){Zt.push(e+"Abs"),Zt.push(e+"Rel")}))},re=function(t,e,n){const r=t.pathSegList;if(p)return void r.insertItemBefore(e,n);const s=r.numberOfItems,i=[];for(let t=0;te[t])},ie=function(t,e){const{path:n}=t;let r={x:e?e.x:t.item.x,y:e?e.y:t.item.y};if(n.matrix){r=L(r.x,r.y,n.matrix)}const s=ee.getCurrentZoom();return r.x*=s,r.y*=s,r},oe=function(t,e){const n={x:t.x,y:t.y};e.matrix&&(t=L(n.x,n.y,e.imatrix),n.x=t.x,n.y=t.y);const r=ee.getCurrentZoom();return n.x/=r,n.y/=r,n},ae=function(t,n,r){const s=ce();let i=At("pathpointgrip_"+t);if(!i){i=document.createElementNS(e.SVG,"circle");const n={id:"pathpointgrip_"+t,display:"none",r:4,fill:"#0FF",stroke:"#00F","stroke-width":2,cursor:"move",style:"pointer-events:all"};"pathNodeTooltip"in Xt&&(n["xlink:title"]=Xt.pathNodeTooltip),Ct(i,n),i=s.appendChild(i);Qt("#pathpointgrip_"+t).dblclick((function(){te&&te.setSegType()}))}return n&&r&&Ct(i,{cx:n,cy:r,display:"inline"}),i},ce=function(){let t=At("pathpointgrip_container");if(!t){t=At("selectorParentGroup").appendChild(document.createElementNS(e.SVG,"g")),t.id="pathpointgrip_container"}return t},le=function(t){let n=At("ctrlpointgrip_"+t);if(n)return n;n=document.createElementNS(e.SVG,"circle");const r={id:"ctrlpointgrip_"+t,display:"none",r:4,fill:"#0FF",stroke:"#55F","stroke-width":1,cursor:"move",style:"pointer-events:all"};return"pathCtrlPtTooltip"in Xt&&(r["xlink:title"]=Xt.pathCtrlPtTooltip),Ct(n,r),ce().append(n),n},he=function(t){let n=At("ctrlLine_"+t);return n||(n=document.createElementNS(e.SVG,"line"),Ct(n,{id:"ctrlLine_"+t,stroke:"#555","stroke-width":1,style:"pointer-events:none"}),ce().append(n),n)},ue=function(t,e){const{index:n}=t,r=ae(n);if(e){const e=ie(t);Ct(r,{cx:e.x,cy:e.y,display:"inline"})}return r},de=function(t){const{item:e,index:n}=t;if(!("x1"in e)||!("x2"in e))return null;const r={};ce();const s=[te.segs[n-1].item,e];for(let i=1;i<3;i++){const o=n+"c"+i,a=r["c"+i+"_line"]=he(o),c=ie(t,{x:e["x"+i],y:e["y"+i]}),l=ie(t,{x:s[i-1].x,y:s[i-1].y});Ct(a,{x1:c.x,y1:c.y,x2:l.x,y2:l.y,display:"inline"}),r["c"+i+"_line"]=a;const h=r["c"+i]=le(o);Ct(h,{cx:c.x,cy:c.y,display:"inline"}),r["c"+i]=h}return r},me=function(t,e,n,r){const s=r||te.elem,i=s["createSVGPathSeg"+Zt[t]](...n);if(g)s.pathSegList.replaceItem(i,e);else{const t=s.pathSegList,n=t.numberOfItems,r=[];for(let e=0;e0?(m=u element");this.elem=t,this.segs=[],this.selected_pts=[],te=this,this.init()}init(){Qt(ce()).find("*").each((function(){Qt(this).attr("display","none")}));const t=this.elem.pathSegList,e=t.numberOfItems;this.segs=[],this.selected_pts=[],this.first_seg=null;for(let n=0;n=e?null:n[t+1],o=t-1<0?null:n[t-1];if(2===s.type){if(o&&1!==o.type){const t=n[r];t.next=n[r+1],t.next.prev=t,t.addGrip()}r=t}else if(i&&1===i.type)s.next=n[r+1],s.next.prev=s,s.mate=n[r],s.addGrip(),Nt(this.first_seg)&&(this.first_seg=s);else if(i)1!==s.type&&(s.addGrip(),i&&2!==i.type&&(s.next=i,s.next.prev=s));else if(1!==s.type){const t=n[r];t.next=n[r+1],t.next.prev=t,t.addGrip(),s.addGrip(),this.first_seg||(this.first_seg=n[r])}}return this}eachSeg(t){const e=this.segs.length;for(let n=0;n{this.segs[t].ptgrip&&!this.selected_pts.includes(t)&&t>=0&&this.selected_pts.push(t)}),this.selected_pts.sort();let e=this.selected_pts.length;const n=[];for(n.length=e;e--;){const t=this.selected_pts[e],r=this.segs[t];r.select(!0),n[e]=r.ptgrip}const r=ye.subpathIsClosed(this.selected_pts[0]);ee.addPtsToSelection({grips:n,closedSubpath:r})}static subpathIsClosed(t){let e=!1;return te.eachSeg((function(n){return n<=t||2!==this.type&&(1!==this.type||(e=!0,!1))})),e}}const xe=function(t){let e=$t[t.id];return e||(e=$t[t.id]=new ye(t)),e},Se=function(t){t in $t&&delete $t[t]};let _e,be,we,Ae,Ce;const ve=function(t,e){let n=t-we,r=e-Ae,s=Math.sqrt(n*n+r*r),i=Math.atan2(r,n)+Ce;return n=s*Math.cos(i)+we,r=s*Math.sin(i)+Ae,n-=_e,r-=be,s=Math.sqrt(n*n+r*r),i=Math.atan2(r,n)-Ce,{x:s*Math.cos(i)+_e,y:s*Math.sin(i)+be}},Ee=function(){const t=te.elem;if(Ce=bt(t,!0),!Ce)return;const e=te.oldbbox;we=e.x+e.width/2,Ae=e.y+e.height/2;const n=ht(t);_e=n.x+n.width/2,be=n.y+n.height/2;const r=_e-we,s=be-Ae,i=Math.sqrt(r*r+s*s),o=Math.atan2(s,r)+Ce;_e=i*Math.cos(o)+we,be=i*Math.sin(o)+Ae;const a=t.pathSegList;let c=a.numberOfItems;for(;c;){c-=1;const t=a.getItem(c),e=t.pathSegType;if(1===e)continue;const n=ve(t.x,t.y),r=[n.x,n.y];if(!Nt(t.x1)&&!Nt(t.x2)){const e=ve(t.x1,t.y1),n=ve(t.x2,t.y2);r.splice(r.length,0,e.x,e.y,n.x,n.y)}me(e,c,r)}ht(t);const l=ee.getSVGRoot().createSVGTransform(),h=P(t);l.setRotate(180*Ce/Math.PI,_e,be),h.replaceItem(l,0)},Ge=function(){$t={}},Ne=function(t,e){const n=ht(t);for(let r=0;r<2;r++){const s=0===r?"fill":"stroke",i=t.getAttribute(s);if(i&&i.startsWith("url(")){const r=wt(i);if("linearGradient"===r.tagName){let i=r.getAttribute("x1")||0,o=r.getAttribute("y1")||0,a=r.getAttribute("x2")||1,c=r.getAttribute("y2")||0;i=n.width*i+n.x,o=n.height*o+n.y,a=n.width*a+n.x,c=n.height*c+n.y;const l=L(i,o,e),h=L(a,c,e),u={x1:(l.x-n.x)/n.width,y1:(l.y-n.y)/n.height,x2:(h.x-n.x)/n.width,y2:(h.y-n.y)/n.height},d=r.cloneNode(!0);Qt(d).attr(u),d.id=ee.getNextId(),at().append(d),t.setAttribute(s,"url(#"+d.id+")")}}}},ke=[0,"z","M","m","L","l","C","c","Q","q","A","a","H","h","V","v","S","s","T","t"],Ie=function(t,e){const{pathSegList:n}=t,r=n.numberOfItems;let s=0,i=0,o="",a=null;for(let t=0;t=r-s&&h<=r+s&&u>=o-s&&u<=o+s){i=!0;break}}a=ee.getId(),Se(a);const o=At(a);let c,f;const y=t.numberOfItems;if(i){if(e<=1&&y>=2){const e=t.getItem(0).x,n=t.getItem(0).y;f=d.pathSegList.getItem(1),c=4===f.pathSegType?p.createSVGPathSegLinetoAbs(e,n):p.createSVGPathSegCurvetoCubicAbs(e,n,f.x1/l,f.y1/l,e,n);const r=p.createSVGPathSegClosePath();t.appendItem(c),t.appendItem(r)}else if(y<3)return g=!1,g;if(Qt(d).remove(),ee.setDrawnPath(null),ee.setStarted(!1),r){te.matrix&&ee.remapElement(o,{},te.matrix.inverse());const t=o.getAttribute("d"),e=Qt(te.elem).attr("d");return Qt(te.elem).attr("d",e+t),Qt(o).remove(),te.matrix&&Ee(),ne(),Te.toEditMode(te.elem),te.selectPt(),!1}}else{if(!Qt.contains(ee.getContainer(),ee.getMouseTarget(n)))return!1;const t=p.pathSegList.numberOfItems,e=p.pathSegList.getItem(t-1),s=e.x,i=e.y;if(n.shiftKey){const t=j(s,i,h,u);({x:h,y:u}=t)}f=d.pathSegList.getItem(1),c=4===f.pathSegType?p.createSVGPathSegLinetoAbs(ee.round(h),ee.round(u)):p.createSVGPathSegCurvetoCubicAbs(ee.round(h),ee.round(u),f.x1/l,f.y1/l,f.x2/l,f.y2/l),p.pathSegList.appendItem(c),h*=l,u*=l,d.setAttribute("d",["M",h,u,h,u].join(" ")),m=t,r&&(m+=te.segs.length),ae(m,h,u)}}else{const t="M"+h+","+u+" ";ee.setDrawnPath(ee.addSVGElementFromJson({element:"path",curStyles:!0,attr:{d:t,id:ee.getNextId(),opacity:ee.getOpacity()/2}})),d.setAttribute("d",["M",s,c,s,c].join(" ")),m=r?te.segs.length:0,ae(m,s,c)}}},mouseMove(e,r){const s=ee.getCurrentZoom();i=!0;const o=ee.getDrawnPath();if("path"!==ee.getCurrentMode())if(te.dragging){const t=oe({x:te.dragging[0],y:te.dragging[1]},te),n=oe({x:e,y:r},te),s=n.x-t.x,i=n.y-t.y;te.dragging=[e,r],te.dragctrl?te.moveCtrl(s,i):te.movePts(s,i)}else te.selected_pts=[],te.eachSeg((function(t){const e=this;if(!e.next&&!e.prev)return;const n=ee.getRubberBox().getBBox(),r=ie(e),s={x:r.x,y:r.y,width:0,height:0},i=H(n,s);this.select(i),i&&te.selected_pts.push(e.index)}));else{if(!o)return;const i=o.pathSegList,a=i.numberOfItems-1;if(t){const c=le("1c1"),l=le("0c2");c.setAttribute("cx",e),c.setAttribute("cy",r),c.setAttribute("display","inline");const h=t[0],u=t[1],d=h+(h-e/s),m=u+(u-r/s);l.setAttribute("cx",d*s),l.setAttribute("cy",m*s),l.setAttribute("display","inline");const g=he(1);if(Ct(g,{x1:e,y1:r,x2:d*s,y2:m*s,display:"inline"}),0===a)n=[e,r];else{const t=i.getItem(a-1);let e=t.x,r=t.y;6===t.pathSegType?(e+=e-t.x2,r+=r-t.y2):n&&(e=n[0]/s,r=n[1]/s),me(6,a,[h,u,e,r,d,m],o)}}else{const t=At("path_stretch_line");if(t){const o=i.getItem(a);if(6===o.pathSegType){const n=o.x+(o.x-o.x2),i=o.y+(o.y-o.y2);me(6,1,[e,r,n*s,i*s,e,r],t)}else n?me(6,1,[e,r,n[0],n[1],e,r],t):me(4,1,[e,r],t)}}}},mouseUp(e,r,s,o){const a=ee.getDrawnPath();if("path"===ee.getCurrentMode())return t=null,a||(r=At(ee.getId()),ee.setStarted(!1),n=null),{keep:!0,element:r};const c=ee.getRubberBox();if(te.dragging){const t=te.cur_pt;te.dragging=!1,te.dragctrl=!1,te.update(),i&&te.endChanges("Move path point(s)"),e.shiftKey||i||te.selectPt(t)}else c&&"none"!==c.getAttribute("display")?(c.setAttribute("display","none"),c.getAttribute("width")<=2&&c.getAttribute("height")<=2&&Te.toSelectMode(e.target)):Te.toSelectMode(e.target);i=!1},toEditMode(t){te=xe(t),ee.setCurrentMode("pathedit"),ee.clearSelection(),te.show(!0).update(),te.oldbbox=ht(te.elem),r=!1},toSelectMode(t){const e=t===te.elem;ee.setCurrentMode("select"),te.show(!1),s=!1,ee.clearSelection(),te.matrix&&Ee(),e&&(ee.call("selected",[t]),ee.addToSelection([t],!0))},addSubPath(t){t?(ee.setCurrentMode("path"),r=!0):(Te.clear(!0),Te.toEditMode(te.elem))},select(t){s===t?(Te.toEditMode(t),ee.setCurrentMode("pathedit")):s=t},reorient(){const t=ee.getSelectedElements()[0];if(!t)return;if(0===bt(t))return;const e=new zt("Reorient path"),n={d:t.getAttribute("d"),transform:t.getAttribute("transform")};e.addSubCommand(new Dt(t,n)),ee.clearSelection(),this.resetOrientation(t),ee.addCommandToHistory(e),xe(t).show(!1).matrix=null,this.clear(),ee.addToSelection([t],!0),ee.call("changed",ee.getSelectedElements())},clear(t){const e=ee.getDrawnPath();if(s=null,e){const t=At(ee.getId());Qt(At("path_stretch_line")).remove(),Qt(t).remove(),Qt(At("pathpointgrip_container")).find("*").attr("display","none"),n=null,ee.setDrawnPath(null),ee.setStarted(!1)}else"pathedit"===ee.getCurrentMode()&&this.toSelectMode();te&&te.init().show(!1)},resetOrientation(t){if(Nt(t)||"path"!==t.nodeName)return!1;const e=P(t),n=B(e).matrix;e.clear(),t.removeAttribute("transform");const r=t.pathSegList,s=r.numberOfItems;for(let e=0;e0){const s=t.getItem(e-1).pathSegType;if(2===s){r(e-1,1),n();break}if(1===s&&t.numberOfItems-1===e){r(e,1),n();break}}}return!1};if(n(),te.elem.pathSegList.numberOfItems<=1)return Te.toSelectMode(te.elem),void ee.canvas.deleteSelectedElements();if(te.init(),te.clearSelection(),window.opera){const t=Qt(te.elem);t.attr("d",t.attr("d"))}te.endChanges("Delete path node(s)")},smoothPolylineIntoPath:function(t){let e;const{points:n}=t,r=n.numberOfItems;if(r>=4){let s=n.getItem(0),i=null,o=[];for(o.push(["M",s.x,",",s.y," C"].join("")),e=1;e<=r-4;e+=3){let t=n.getItem(e);const r=n.getItem(e+1),a=n.getItem(e+2);if(i){const e=pe(i,t,s);if(e&&2===e.length){const n=o[o.length-1].split(",");n[2]=e[0].x,n[3]=e[0].y,o[o.length-1]=n.join(","),t=e[1]}}o.push([t.x,t.y,r.x,r.y,a.x,a.y].join(",")),s=a,i=r}for(o.push("L");e=0&&t<=1&&this.group_.setAttribute("opacity",t)}appendChildren(t){for(const e of t)this.group_.append(e)}getTitleElement(){const t=this.group_.childNodes.length;for(let e=0;e element");this.svgElem_=t,this.obj_num=0,this.idPrefix=n||"svg_",this.releasedNums=[],this.all_layers=[],this.layer_map={},this.current_layer=null,this.nonce_="";const r=this.svgElem_.getAttributeNS(e.SE,"nonce");r&&De!==Fe?this.nonce_=r:De===He&&this.setNonce(Math.floor(100001*Math.random()))}getElem_(t){return this.svgElem_.querySelector?this.svgElem_.querySelector("#"+t):Ue(this.svgElem_).find("[id="+t+"]")[0]}getSvgElem(){return this.svgElem_}getNonce(){return this.nonce_}setNonce(t){this.svgElem_.setAttributeNS(e.XMLNS,"xmlns:se",e.SE),this.svgElem_.setAttributeNS(e.SE,"se:nonce",t),this.nonce_=t}clearNonce(){this.nonce_=""}getId(){return this.nonce_?this.idPrefix+this.nonce_+"_"+this.obj_num:this.idPrefix+this.obj_num}getNextId(){const t=this.obj_num;let e=!1;this.releasedNums.length>0?(this.obj_num=this.releasedNums.pop(),e=!0):this.obj_num++;let n=this.getId();for(;this.getElem_(n);)e&&(this.obj_num=t,e=!1),this.obj_num++,n=this.getId();return e&&(this.obj_num=t),n}releaseId(t){const e=this.idPrefix+(this.nonce_?this.nonce_+"_":"");if("string"!=typeof t||!t.startsWith(e))return!1;const n=Number.parseInt(t.substr(e.length));return!("number"!=typeof n||n<=0||this.releasedNums.includes(n))&&(this.releasedNums.push(n),!0)}getNumLayers(){return this.all_layers.length}hasLayer(t){return void 0!==this.layer_map[t]}getLayerName(t){return t>=0&&t=e)return null;let n;for(n=0;nn?t0){const t=this.current_layer.getName();this.current_layer=this.all_layers[s-1],this.all_layers.splice(s,1),delete this.layer_map[t]}t.endBatchCommand()}mergeAllLayers(t){for(this.current_layer=this.all_layers[this.all_layers.length-1],t.startBatchCommand("Merge all Layers");this.all_layers.length>1;)this.mergeLayer(t);t.endBatchCommand()}setCurrentLayer(t){const e=this.layer_map[t];return!!e&&(this.current_layer&&this.current_layer.deactivate(),this.current_layer=e,this.current_layer.activate(),!0)}deleteCurrentLayer(){if(this.current_layer&&this.getNumLayers()>1){const t=this.current_layer.removeGroup();return this.identifyLayers(),t}return null}identifyLayers(){this.all_layers=[],this.layer_map={};const t=this.svgElem_.childNodes.length,e=[],n=[];let r=null,s=!1;for(let i=0;i0||!s?(r=new Oe(We(n),null,this.svgElem_),r.appendChildren(e),this.all_layers.push(r),this.layer_map[name]=r):r.activate(),this.current_layer=r}createLayer(t,e){this.current_layer&&this.current_layer.deactivate(),(null==t||""===t||this.layer_map[t])&&(t=We(Object.keys(this.layer_map)));const n=new Oe(t,null,this.svgElem_);return e&&(e.startBatchCommand("Create Layer"),e.insertElement(n.getGroup()),e.endBatchCommand()),this.all_layers.push(n),this.layer_map[t]=n,this.current_layer=n,n.getGroup()}cloneLayer(t,e){if(!this.current_layer)return null;this.current_layer.deactivate(),(null==t||""===t||this.layer_map[t])&&(t=We(Object.keys(this.layer_map)));const n=this.current_layer.getGroup(),r=new Oe(t,n,this.svgElem_),s=r.getGroup();[...n.childNodes].forEach(t=>{"title"!==t.localName&&s.append(this.copyElem(t))}),e&&(e.startBatchCommand("Duplicate Layer"),e.insertElement(s),e.endBatchCommand());const i=this.all_layers.indexOf(this.current_layer);return i>=0?this.all_layers.splice(i+1,0,r):this.all_layers.push(r),this.layer_map[t]=r,this.current_layer=r,s}getLayerVisibility(t){const e=this.layer_map[t];return!!e&&e.isVisible()}setLayerVisibility(t,e){if("boolean"!=typeof e)return null;const n=this.layer_map[t];return n?(n.setVisible(e),n.getGroup()):null}getLayerOpacity(t){const e=this.layer_map[t];return e?e.getOpacity():null}setLayerOpacity(t,e){if("number"!=typeof e||e<0||e>1)return;const n=this.layer_map[t];n&&n.setOpacity(e)}copyElem(t){const e=this;return Be(t,(function(){return e.getNextId()}))}}const Ke=function(t,e){De=!1===t?Fe:He,De!==He||e.getNonce()?De===Fe&&e.getNonce()&&e.clearNonce():e.setNonce(Math.floor(100001*Math.random()))};let Ze;const Ye=function(){ln(),Ze.getCurrentDrawing().identifyLayers()},$e=function(t,e){const n=Ze.getCurrentDrawing().createLayer(t,qe(e));Ze.clearSelection(),Ze.call("changed",[n])},Je=function(t,e){const n=Ze.getCurrentDrawing().cloneLayer(t,qe(e));Ze.clearSelection(),ln(),Ze.call("changed",[n])},tn=function(){let t=Ze.getCurrentDrawing().getCurrentLayer();const{nextSibling:e}=t,n=t.parentNode;if(t=Ze.getCurrentDrawing().deleteCurrentLayer(),t){const r=new zt("Delete Layer");return r.addSubCommand(new Ft(t,e,n)),Ze.addCommandToHistory(r),Ze.clearSelection(),Ze.call("changed",[n]),!0}return!1},en=function(t){const e=Ze.getCurrentDrawing().setCurrentLayer(Z(t));return e&&Ze.clearSelection(),e},nn=function(t){const e=Ze.getCurrentDrawing(),n=e.getCurrentLayer();if(n){if(e.setCurrentLayerName(t,qe()))return Ze.call("changed",[n]),!0}return!1},rn=function(t){const e=Ze.getCurrentDrawing().setCurrentLayerPosition(t);return!!e&&(Ze.addCommandToHistory(new jt(e.currentGroup,e.oldNextSibling,Ze.getSVGContent())),!0)},sn=function(t,e){const n=Ze.getCurrentDrawing(),r=n.getLayerVisibility(t),s=n.setLayerVisibility(t,e);if(!s)return!1;{const t=r?"inline":"none";Ze.addCommandToHistory(new Dt(s,{display:t},"Layer Visibility"))}return s===n.getCurrentLayer()&&(Ze.clearSelection(),Ze.pathActions.clear()),!0},on=function(t){const e=Ze.getCurrentDrawing().getLayerByName(t);if(!e)return!1;const n=new zt("Move Elements to Layer"),r=Ze.getSelectedElements();let s=r.length;for(;s--;){const t=r[s];if(!t)continue;const i=t.nextSibling,o=t.parentNode;e.append(t),n.addSubCommand(new jt(t,i,o))}return Ze.addCommandToHistory(n),!0},an=function(t){Ze.getCurrentDrawing().mergeLayer(qe(t)),Ze.clearSelection(),ln(),Ze.changeSVGContent()},cn=function(t){Ze.getCurrentDrawing().mergeAllLayers(qe(t)),Ze.clearSelection(),ln(),Ze.changeSVGContent()},ln=function(){const t=ze.length;if(t){for(let e=0;e{t.setAttributeNS(e.SE,n,r)});const o=it(t);if(o&&["filter","linearGradient","pattern","radialGradient","textPath","use"].includes(t.nodeName)&&"#"!==o[0]&&(ot(t,""),t.removeAttributeNS(e.XLINK,"href")),"use"===t.nodeName&&!it(t))return void t.remove();for(Object.values(["clip-path","fill","filter","marker-end","marker-mid","marker-start","mask","stroke"],(function(e){let n=t.getAttribute(e);n&&(n=st(n),n&&"#"!==n[0]&&(t.setAttribute(e,""),t.removeAttribute(e)))})),r=t.childNodes.length;r--;)gn(t.childNodes.item(r))}else{const e=[];for(;t.hasChildNodes();)e.push(r.insertBefore(t.firstChild,t));t.remove();let n=e.length;for(;n--;)gn(e[n])}}; /** * Adapted from {@link https://github.com/uupaa/dynamic-import-polyfill/blob/master/importModule.js}. * @module importModule * @license MIT */function pn(t,e){["id","class","type"].forEach(n=>{n in e&&(t[n]=e[n])})}async function fn(t,{global:e,returnDefault:n}){return"svgEditor"in window&&window.svgEditor&&!1===window.svgEditor.modules?(await yn(t),window[e]):function t(e,n={},{returnDefault:r=!1}={}){if(Array.isArray(e))return Promise.all(e.map(e=>t(e,n)));return new Promise((t,s)=>{const i="$importModule$"+Math.random().toString(32).slice(2),o=document.createElement("script");function a(){s(new Error("Failed to import: "+e)),l()}function c(){t(window[i]),l()}const l=()=>{delete window[i],o.removeEventListener("error",a),o.removeEventListener("load",c),o.remove(),URL.revokeObjectURL(o.src),o.src=""};pn(o,n),o.defer="defer",o.type="module",o.addEventListener("error",a),o.addEventListener("load",c);const h=`import * as m from '${function(t){const e=document.createElement("a");return e.setAttribute("href",t),e.cloneNode(!1).href}(e).replace(/'/g,"\\'")}'; window.${i} = ${r?"m.default || ":""}m;`,u=new Blob([h],{type:"text/javascript"});o.src=URL.createObjectURL(u),document.head.append(o)})}(t,void 0,{returnDefault:n})}function yn(t,e={}){return Array.isArray(t)?Promise.all(t.map(t=>yn(t,e))):new Promise((n,r)=>{const s=document.createElement("script");function i(){r(new Error("Failed to import: "+t)),a()}function o(){n(),a()}const a=()=>{s.removeEventListener("error",i),s.removeEventListener("load",o),s.remove(),s.src=""};s.defer="defer",pn(s,e),s.addEventListener("error",i),s.addEventListener("load",o),s.src=t,document.head.append(s)})}const xn=jQuery,Sn=[0,"z","M","m","L","l","C","c","Q","q","A","a","H","h","V","v","S","s","T","t"];let _n=null;const bn=function(t,e,n){const r=function(t,e){return L(t,e,n)},s=function(t){return n.a*t},i=function(t){return n.d*t},o=_n.getGridSnapping()&&"svg"===t.parentNode.parentNode.localName,a=function(){o&&Object.entries(e).forEach(([t,n])=>{e[t]=Et(n)}),Ct(t,e,0,!0)},c=ht(t);for(let e=0;e<2;e++){const r=0===e?"fill":"stroke",s=t.getAttribute(r);if(s&&s.startsWith("url(")&&(n.a<0||n.d<0)){const e=wt(s).cloneNode(!0);if(n.a<0){const t=e.getAttribute("x1"),n=e.getAttribute("x2");e.setAttribute("x1",-(t-1)),e.setAttribute("x2",-(n-1))}if(n.d<0){const t=e.getAttribute("y1"),n=e.getAttribute("y2");e.setAttribute("y1",-(t-1)),e.setAttribute("y2",-(n-1))}e.id=_n.getDrawing().getNextId(),at().append(e),t.setAttribute(r,"url(#"+e.id+")")}}const l=t.tagName;if("g"===l||"text"===l||"tspan"===l||"use"===l)if(1!==n.a||0!==n.b||0!==n.c||1!==n.d||0===n.e&&0===n.f){const e=P(t),r=_n.getSVGRoot().createSVGTransform();r.setMatrix(O(B(e).matrix,n)),e.clear(),e.appendItem(r)}else{const r=B(t).matrix,s=O(r.inverse(),n,r);e.x=Number.parseFloat(e.x)+s.e,e.y=Number.parseFloat(e.y)+s.f}switch(l){case"foreignObject":case"rect":case"image":if("image"===l&&(n.a<0||n.d<0)){const e=P(t),r=_n.getSVGRoot().createSVGTransform();r.setMatrix(O(B(e).matrix,n)),e.clear(),e.appendItem(r)}else{const t=r(e.x,e.y);e.width=s(e.width),e.height=i(e.height),e.x=t.x+Math.min(0,e.width),e.y=t.y+Math.min(0,e.height),e.width=Math.abs(e.width),e.height=Math.abs(e.height)}a();break;case"ellipse":{const t=r(e.cx,e.cy);e.cx=t.x,e.cy=t.y,e.rx=s(e.rx),e.ry=i(e.ry),e.rx=Math.abs(e.rx),e.ry=Math.abs(e.ry),a();break}case"circle":{const t=r(e.cx,e.cy);e.cx=t.x,e.cy=t.y;const s=R(c.x,c.y,c.width,c.height,n),i=s.tr.x-s.tl.x,o=s.bl.y-s.tl.y;e.r=Math.min(i/2,o/2),e.r&&(e.r=Math.abs(e.r)),a();break}case"line":{const t=r(e.x1,e.y1),n=r(e.x2,e.y2);e.x1=t.x,e.y1=t.y,e.x2=n.x,e.y2=n.y}case"text":case"tspan":case"use":a();break;case"g":{const n=xn(t).data("gsvg");n&&Ct(n,e,0,!0);break}case"polyline":case"polygon":{const n=e.points.length;for(let t=0;t0){let e=r.numberOfItems;const n=e;for(;e--;){const s=r.getItem(e);if(0===s.type)r.removeItem(e);else if(1===s.type){if(V(s.matrix)){if(1===n)return t.removeAttribute("transform"),null;r.removeItem(e)}}else 4===s.type&&0===s.angle&&r.removeItem(e)}if(1===r.numberOfItems&&bt(t))return null}if(!r||0===r.numberOfItems)return t.setAttribute("transform",""),t.removeAttribute("transform"),null;if(r){let t=[],e=r.numberOfItems;for(;e--;){const n=r.getItem(e);1===n.type?t.push([n.matrix,e]):t.length&&(t=[])}if(2===t.length){const e=n.createSVGTransformFromMatrix(O(t[1][0],t[0][0]));r.removeItem(t[0][1]),r.removeItem(t[1][1]),r.insertItemBefore(e,t[1][1])}if(e=r.numberOfItems,e>=2&&1===r.getItem(e-2).type&&2===r.getItem(e-1).type){const t=n.createSVGTransform(),s=O(r.getItem(e-2).matrix,r.getItem(e-1).matrix);t.setMatrix(s),r.removeItem(e-2),r.removeItem(e-2),r.appendItem(t)}}switch(t.tagName){case"line":case"polyline":case"polygon":case"path":break;default:if(1===r.numberOfItems&&1===r.getItem(0).type||2===r.numberOfItems&&1===r.getItem(0).type&&4===r.getItem(0).type)return null}const s=wn(t).data("gsvg"),i=new zt("Transform");let o,a,c={},l=null,h=[];switch(t.tagName){case"line":h=["x1","y1","x2","y2"];break;case"circle":h=["cx","cy","r"];break;case"ellipse":h=["cx","cy","rx","ry"];break;case"foreignObject":case"rect":case"image":h=["width","height","x","y"];break;case"use":case"text":case"tspan":h=["x","y"];break;case"polygon":case"polyline":{l={},l.points=t.getAttribute("points");const e=t.points,n=e.numberOfItems;c.points=new Array(n);for(let t=0;t1e-10?Math.sin(t)/(1-Math.cos(t)):2/t;for(let t=0;t=3&&3===r.getItem(l-2).type&&2===r.getItem(l-3).type&&2===r.getItem(l-1).type){g=3;const e=r.getItem(l-3).matrix,s=r.getItem(l-2).matrix,o=r.getItem(l-1).matrix,a=t.childNodes;let c=a.length;for(;c--;){const t=a.item(c);if(d=0,m=0,1===t.nodeType){const r=P(t);if(!r)continue;const a=B(r).matrix,c=bt(t);if(u=An.getStartTransform(),An.setStartTransform(t.getAttribute("transform")),c||M(r)){const t=n.createSVGTransform();t.setMatrix(O(e,s,o,a)),r.clear(),r.appendItem(t)}else{const t=O(a.inverse(),o,a),i=n.createSVGMatrix();i.e=-t.e,i.f=-t.f;const c=O(i.inverse(),a.inverse(),e,s,o,a,t.inverse()),l=n.createSVGTransform(),h=n.createSVGTransform(),u=n.createSVGTransform();l.setTranslate(t.e,t.f),h.setScale(c.a,c.d),u.setTranslate(i.e,i.f),r.appendItem(u),r.appendItem(h),r.appendItem(l)}i.addSubCommand(vn(t)),An.setStartTransform(u)}}r.removeItem(l-1),r.removeItem(l-2),r.removeItem(l-3)}else if(l>=3&&1===r.getItem(l-1).type){g=3;const t=B(r).matrix,e=n.createSVGTransform();e.setMatrix(t),r.clear(),r.appendItem(e)}else if((1===l||l>1&&3!==r.getItem(1).type)&&2===r.getItem(0).type){g=2;const s=B(r).matrix;r.removeItem(0);const o=B(r).matrix.inverse(),a=O(o,s);if(d=a.e,m=a.f,0!==d||0!==m){const r=t.childNodes;let s=r.length;const o=[];for(;s--;){const a=r.item(s);if(1===a.nodeType){if(a.getAttribute("clip-path")){const t=a.getAttribute("clip-path");o.includes(t)||(Cn(t,d,m),o.push(t))}u=An.getStartTransform(),An.setStartTransform(a.getAttribute("transform"));const r=P(a);if(r){const s=n.createSVGTransform();s.setTranslate(d,m),r.numberOfItems?r.insertItemBefore(s,0):r.appendItem(s),i.addSubCommand(vn(a));const o=t.getElementsByTagNameNS(e.SVG,"use"),c="#"+a.id;let l=o.length;for(;l--;){const t=o.item(l);if(c===it(t)){const e=n.createSVGTransform();e.setTranslate(-d,-m),P(t).insertItemBefore(e,0),i.addSubCommand(vn(t))}}An.setStartTransform(u)}}}An.setStartTransform(u)}}else{if(1!==l||1!==r.getItem(0).type||c){if(c){const t=n.createSVGTransform();t.setRotate(c,a.x,a.y),r.numberOfItems?r.insertItemBefore(t,0):r.appendItem(t)}return 0===r.numberOfItems&&t.removeAttribute("transform"),null}{g=1;const e=r.getItem(0).matrix,s=t.childNodes;let o=s.length;for(;o--;){const t=s.item(o);if(1===t.nodeType){u=An.getStartTransform(),An.setStartTransform(t.getAttribute("transform"));const r=P(t);if(!r)continue;const s=O(e,B(r).matrix),o=n.createSVGTransform();o.setMatrix(s),r.clear(),r.appendItem(o,0),i.addSubCommand(vn(t)),An.setStartTransform(u);const a=t.getAttribute("stroke-width");if("none"!==t.getAttribute("stroke")&&!isNaN(a)){const e=(Math.abs(s.a)+Math.abs(s.d))/2;t.setAttribute("stroke-width",a*e)}}}r.clear()}}if(2===g){if(c){a={x:o.x+h.e,y:o.y+h.f};const t=n.createSVGTransform();t.setRotate(c,a.x,a.y),r.numberOfItems?r.insertItemBefore(t,0):r.appendItem(t)}}else if(3===g){const e=B(r).matrix,s=n.createSVGTransform();s.setRotate(c,o.x,o.y);const l=s.matrix,h=n.createSVGTransform();h.setRotate(c,a.x,a.y);const g=h.matrix.inverse(),p=e.inverse(),f=O(p,g,l,e);if(d=f.e,m=f.f,0!==d||0!==m){const e=t.childNodes;let r=e.length;for(;r--;){const t=e.item(r);if(1===t.nodeType){u=An.getStartTransform(),An.setStartTransform(t.getAttribute("transform"));const e=P(t),r=n.createSVGTransform();r.setTranslate(d,m),e.numberOfItems?e.insertItemBefore(r,0):e.appendItem(r),i.addSubCommand(vn(t)),An.setStartTransform(u)}}}c&&(r.numberOfItems?r.insertItemBefore(h,0):r.appendItem(h))}}else{const e=ht(t);if(!e&&"path"!==t.tagName)return null;let s;const i=bt(t);if(i){o={x:e.x+e.width/2,y:e.y+e.height/2},a=L(e.x+e.width/2,e.y+e.height/2,B(r).matrix);const t=i*Math.PI/180,n=Math.abs(t)>1e-10?Math.sin(t)/(1-Math.cos(t)):2/t;for(let t=0;t=3&&3===r.getItem(h-2).type&&2===r.getItem(h-3).type&&2===r.getItem(h-1).type)l=3,s=B(r,h-3,h-1).matrix,r.removeItem(h-1),r.removeItem(h-2),r.removeItem(h-3);else if(4===h&&1===r.getItem(h-1).type){l=3,s=B(r).matrix;const t=n.createSVGTransform();t.setMatrix(s),r.clear(),r.appendItem(t),s=n.createSVGMatrix()}else if((1===h||h>1&&3!==r.getItem(1).type)&&2===r.getItem(0).type){l=2;const t=r.getItem(0).matrix,e=B(r,1).matrix,n=e.inverse();s=O(n,t,e),r.removeItem(0)}else{if(1!==h||1!==r.getItem(0).type||i){if(i){const t=n.createSVGTransform();t.setRotate(i,a.x,a.y),r.numberOfItems?r.insertItemBefore(t,0):r.appendItem(t)}return 0===r.numberOfItems&&t.removeAttribute("transform"),null}switch(s=B(r).matrix,t.tagName){case"line":c=wn(t).attr(["x1","y1","x2","y2"]);case"polyline":case"polygon":if(c.points=t.getAttribute("points"),c.points){const e=t.points,n=e.numberOfItems;c.points=new Array(n);for(let t=0;t{r[t].setAttribute("cx",e[0]),r[t].setAttribute("cy",e[1])}),n.rotateGripConnector.setAttribute("x1",y+S/2),n.rotateGripConnector.setAttribute("y1",x),n.rotateGripConnector.setAttribute("x2",y+S/2),n.rotateGripConnector.setAttribute("y2",x-5*In),n.rotateGrip.setAttribute("cx",y+S/2),n.rotateGrip.setAttribute("cy",x-5*In)}static updateGripCursors(t){const e=Object.keys(kn.selectorGrips);let n=Math.round(t/45);for(n<0&&(n+=8);n>0;)e.push(e.shift()),n--;Object.values(kn.selectorGrips).forEach((t,n)=>{t.setAttribute("style","cursor:"+e[n]+"-resize")})}}class Tn{constructor(){this.selectorParentGroup=null,this.rubberBandBox=null,this.selectors=[],this.selectorMap={},this.selectorGrips={nw:null,n:null,ne:null,e:null,se:null,s:null,sw:null,w:null},this.selectorGripsGroup=null,this.rotateGripConnector=null,this.rotateGrip=null,this.initGroup()}initGroup(){if(this.selectorParentGroup&&this.selectorParentGroup.parentNode&&this.selectorParentGroup.remove(),this.selectorParentGroup=Gn.createSVGElement({element:"g",attr:{id:"selectorParentGroup"}}),this.selectorGripsGroup=Gn.createSVGElement({element:"g",attr:{display:"none"}}),this.selectorParentGroup.append(this.selectorGripsGroup),Gn.svgRoot().append(this.selectorParentGroup),this.selectorMap={},this.selectors=[],this.rubberBandBox=null,Object.keys(this.selectorGrips).forEach(t=>{const e=Gn.createSVGElement({element:"circle",attr:{id:"selectorGrip_resize_"+t,fill:"#22C",r:In,style:"cursor:"+t+"-resize","stroke-width":2,"pointer-events":"all"}});En.data(e,"dir",t),En.data(e,"type","resize"),this.selectorGrips[t]=this.selectorGripsGroup.appendChild(e)}),this.rotateGripConnector=this.selectorGripsGroup.appendChild(Gn.createSVGElement({element:"line",attr:{id:"selectorGrip_rotateconnector",stroke:"#22C","stroke-width":"1"}})),this.rotateGrip=this.selectorGripsGroup.appendChild(Gn.createSVGElement({element:"circle",attr:{id:"selectorGrip_rotate",fill:"lime",r:In,stroke:"#22C","stroke-width":2,style:"cursor:url("+Nn.imgPath+"rotate.png) 12 12, auto;"}})),En.data(this.rotateGrip,"type","rotate"),En("#canvasBackground").length)return;const[t,e]=Nn.dimensions,n=Gn.createSVGElement({element:"svg",attr:{id:"canvasBackground",width:t,height:e,x:0,y:0,overflow:b()?"none":"visible",style:"pointer-events:none"}}),r=Gn.createSVGElement({element:"rect",attr:{width:"100%",height:"100%",x:0,y:0,"stroke-width":1,stroke:"#000",fill:"#FFF",style:"pointer-events:none"}});n.append(r),Gn.svgRoot().insertBefore(n,Gn.svgContent())}requestSelector(t,e){if(Nt(t))return null;const n=this.selectors.length;if("object"==typeof this.selectorMap[t.id])return this.selectorMap[t.id].locked=!0,this.selectorMap[t.id];for(let r=0;r').documentElement,!0);t.append(c);let l=a.createElementNS(e.SVG,"svg");(o.clearSvgContentElement=function(){Ln(l).empty(),Ln(l).attr({id:"svgcontent",width:i[0],height:i[1],x:i[0],y:i[1],overflow:s.show_outside_canvas?"visible":"hidden",xmlns:e.SVG,"xmlns:se":e.SE,"xmlns:xlink":e.XLINK}).appendTo(c);const t=a.createComment(" Created with SVG-edit - https://github.com/SVG-Edit/svgedit");l.append(t)})();let h="svg_";o.setIdPrefix=function(t){h=t},o.current_drawing_=new Xe(l,h);const u=o.getCurrentDrawing=function(){return o.current_drawing_};let d=1,m=null;const g={shape:{fill:("none"===s.initFill.color?"":"#")+s.initFill.color,fill_paint:null,fill_opacity:s.initFill.opacity,stroke:"#"+s.initStroke.color,stroke_paint:null,stroke_opacity:s.initStroke.opacity,stroke_width:s.initStroke.width,stroke_dasharray:"none",stroke_linejoin:"miter",stroke_linecap:"butt",opacity:s.initOpacity}};g.text=Ln.extend(!0,{},g.shape),Ln.extend(g.text,{fill:"#000000",stroke_width:s.text&&s.text.stroke_width,font_size:s.text&&s.text.font_size,font_family:s.text&&s.text.font_family});const p=g.shape;let y=[];const x=this.getJsonFromSvgElement=function(t){if(3===t.nodeType)return t.nodeValue;const e={element:t.tagName,attr:{},children:[]};for(let n,r=0;n=t.attributes[r];r++)e.attr[n.name]=n.value;for(let n,r=0;n=t.childNodes[r];r++)e.children[r]=x(n);return e},S=this.addSVGElementFromJson=function(t){if("string"==typeof t)return a.createTextNode(t);let n=At(t.attr.id);const r=u().getCurrentLayer();if(n&&t.element!==n.tagName&&(n.remove(),n=null),!n){const s=t.namespace||e.SVG;n=a.createElementNS(s,t.element),r&&(m||r).append(n)}return t.curStyles&&Ct(n,{fill:p.fill,stroke:p.stroke,"stroke-width":p.stroke_width,"stroke-dasharray":p.stroke_dasharray,"stroke-linejoin":p.stroke_linejoin,"stroke-linecap":p.stroke_linecap,"stroke-opacity":p.stroke_opacity,"fill-opacity":p.fill_opacity,opacity:p.opacity/2,style:"pointer-events:inherit"}),Ct(n,t.attr),vt(n),t.children&&t.children.forEach(t=>{n.append(S(t))}),n};o.getTransformList=P,o.matrixMultiply=O,o.hasMatrixTransform=M,o.transformListToTransform=B;const _=()=>s.baseUnit;!function(t){Pt=t;const n=document.createElementNS(e.SVG,"svg");document.body.append(n);const r=document.createElementNS(e.SVG,"rect");r.setAttribute("width","1em"),r.setAttribute("height","1ex"),r.setAttribute("x","1in"),n.append(r);const s=r.getBBox();n.remove();const i=s.x;Tt={em:s.width,ex:s.height,in:i,cm:i/2.54,mm:i/25.4,pt:i/72,pc:i/6,px:1,"%":0}}({getBaseUnit:_,getElement:At,getHeight:()=>l.getAttribute("height")/d,getWidth:()=>l.getAttribute("width")/d,getRoundDigits:()=>Xt.round_digits}),o.convertToNum=Rt;const E=()=>l,G=this.getSelectedElems=function(){return y},{pathActions:I}=Le,T=()=>c;var D;q=D={pathActions:I,getSVGContent:E,addSVGElementFromJson:S,getSelectedElements:G,getDOMDocument:()=>a,getDOMContainer:()=>t,getSVGRoot:T,getBaseUnit:_,getSnappingStep:()=>s.snappingStep},Q=D.getDOMDocument(),W=D.getDOMContainer(),X=D.getSVGRoot(),o.findDefs=at,o.getUrlFromAttr=st,o.getHref=it,o.setHref=ot,o.getBBox=ht,o.getRotationAngle=bt,o.getElem=At,o.getRefElem=wt,o.assignAttributes=Ct,this.cleanupElement=vt;const z=()=>s.gridSnapping;!function(t){_n=t}({getDrawing:()=>u(),getSVGRoot:T,getGridSnapping:z}),this.remapElement=bn,function(t){An=t}({getSVGRoot:T,getStartTransform:()=>re,setStartTransform(t){re=t}}),this.recalculateDimensions=vn;const J=n();o.sanitizeSvg=gn;const tt=o.undoMgr=new Un({handleHistoryEvent(t,e){const n=jn;if(t===n.BEFORE_UNAPPLY||t===n.BEFORE_APPLY)o.clearSelection();else if(t===n.AFTER_APPLY||t===n.AFTER_UNAPPLY){const r=e.elements();o.pathActions.clear(),kt("changed",r);const s=e.type(),i=t===n.AFTER_APPLY;if("MoveElementCommand"===s){(i?e.newParent:e.oldParent)===l&&Ye()}else if("InsertElementCommand"===s||"RemoveElementCommand"===s)e.parent===l&&Ye(),"InsertElementCommand"===s?i&&Qt(e.elem):i||Qt(e.elem),e.elem&&"use"===e.elem.tagName&&ke(e.elem);else if("ChangeElementCommand"===s){"title"===e.elem.tagName&&e.elem.parentNode.parentNode===l&&Ye();const t=i?e.newValues:e.oldValues;t.stdDeviation&&o.setBlurOffsets(e.elem.parentNode,t.stdDeviation)}}}}),lt=function(t){o.undoMgr.addCommandToHistory(t)},ut=this.getZoom=function(){return d},pt=this.round=function(t){return Number.parseInt(t*d)/d};!function(t,e){Nn=t,Gn=e,kn=new Tn}(s,{createSVGElement:t=>o.addSVGElementFromJson(t),svgRoot:()=>c,svgContent:()=>l,getCurrentZoom:ut});const ft=this.selectorManager=kn,yt=o.getNextId=function(){return u().getNextId()},_t=o.getId=function(){return u().getId()},kt=function(t,e){if(pe[t])return pe[t](window,e)},It=this.clearSelection=function(t){y.forEach(t=>{Nt(t)||ft.releaseSelector(t)}),y=[],t||kt("selected",y)},Mt=this.addToSelection=function(t,e){if(!t.length)return;let n=0;for(;n1&&t.showGrips(!1)}}if(y.length)for(kt("selected",y),1===y.length&&ft.requestSelector(y[0]).showGrips(e),y.sort((function(t,e){return t&&e&&t.compareDocumentPosition?3-(6&e.compareDocumentPosition(t)):Nt(t)?1:0}));Nt(y[0]);)y.shift(0)},Bt=function(){return p.opacity},Ut=this.getMouseTarget=function(n){if(Nt(n))return null;let r=n.target;if(r.correspondingUseElement&&(r=r.correspondingUseElement),[e.MATH,e.HTML].includes(r.namespaceURI)&&"svgcanvas"!==r.id)for(;"foreignObject"!==r.nodeName;)if(r=r.parentNode,!r)return c;const s=u().getCurrentLayer();if([c,t,l,s].includes(r))return c;if(Ln(r).closest("#selectorParentGroup").length)return ft.selectorParentGroup;for(;r.parentNode!==(m||s);)r=r.parentNode;return r};o.pathActions=I,ne({selectorManager:ft,canvas:o,call:kt,resetD:function(t){t.setAttribute("d",I.convertPath(t))},round:pt,clearSelection:It,addToSelection:Mt,addCommandToHistory:lt,remapElement:bn,addSVGElementFromJson:S,getGridSnapping:z,getOpacity:Bt,getSelectedElements:G,getContainer:()=>t,setStarted(t){ee=t},getRubberBox:()=>ce,setRubberBox:t=>(ce=t,ce),addPtsToSelection({closedSubpath:t,grips:e}){I.canDeleteNodes=!0,I.closed_subpath=t,kt("pointsAdded",{closedSubpath:t,grips:e}),kt("selected",e)},endChanges({cmd:t,elem:e}){lt(t),kt("changed",[e])},getCurrentZoom:ut,getId:_t,getNextId:yt,getMouseTarget:Ut,getCurrentMode:()=>se,setCurrentMode:t=>(se=t,se),getDrawnPath:()=>we,setDrawnPath:t=>(we=t,we),getSVGRoot:T});const jt={},Ht="a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use",Ft=["clip-path","fill","filter","marker-end","marker-mid","marker-start","mask","stroke"],Dt=Ln.data,zt=document.createElementNS(e.SVG,"animate");Ln(zt).attr({attributeName:"opacity",begin:"indefinite",dur:1,fill:"freeze"}).appendTo(c);const Qt=function(t){const e=Ln(t).attr(Ft);Object.values(e).forEach(t=>{if(t&&t.startsWith("url(")){const e=st(t).substr(1);At(e)||(at().append(Jt[e]),delete Jt[e])}});const n=t.getElementsByTagName("*");if(n.length)for(let t=0,e=n.length;te===t)};const ue=this.runExtensions=function(t,e,n,r){let s=!!n&&[];return Ln.each($t,(function(i,o){r&&!r(i)||o&&t in o&&("function"==typeof e&&(e=e(i)),n?s.push(o[t](e)):s=o[t](e))})),s};this.addExtension=async function(t,e,{$:n,importLocale:r}){if("function"!=typeof e)throw new TypeError("Function argument expected for `svgcanvas.addExtension`");if(t in $t)throw new Error('Cannot add extension "'+t+'", an extension by that name already exists.');const s=Ln.extend(o.getPrivateMethods(),{$:n,importLocale:r,svgroot:c,svgcontent:l,nonce:u().getNonce(),selectorManager:ft}),i=await e(s);return i&&(i.name=t),$t[t]=i,kt("extension_added",i)};const de=this.getIntersectionList=function(t){if(Nt(ce))return null;const e=m||u().getCurrentLayer();let n;if(t)n=l.createSVGRect(),n.x=t.x,n.y=t.y,n.width=t.width,n.height=t.height;else{n=ce.getBBox();const t=l.createSVGRect();["x","y","width","height","top","right","bottom","left"].forEach(e=>{t[e]=n[e]/d}),n=t}let r=null;if(A()||"function"==typeof c.getIntersectionList&&(n.x+=Number.parseInt(l.getAttribute("x")),n.y+=Number.parseInt(l.getAttribute("y")),r=c.getIntersectionList(n,e)),Nt(r)||"function"!=typeof r.item){r=[],le.length||(le=me(e));let t=le.length;for(;t--;)n.width&&H(n,le[t].bbox)&&r.push(le[t].elem)}return r};this.getStrokedBBox=St,this.getVisibleElements=xt;const me=this.getVisibleElementsAndBBoxes=function(t){t||(t=Ln(l).children());const e=[];return Ln(t).children().each((function(t,n){n.getBBox&&e.push({elem:n,bbox:St([n])})})),e.reverse()},ge=this.groupSvgElem=function(t){const n=document.createElementNS(e.SVG,"g");t.replaceWith(n),Ln(n).append(t).data("gsvg",t)[0].id=yt()},pe={};o.call=kt,o.bind=function(t,e){const n=pe[t];return pe[t]=e,n},this.prepareSvg=function(t){this.sanitizeSvg(t.documentElement);[...t.getElementsByTagNameNS(e.SVG,"path")].forEach(t=>{t.setAttribute("d",I.convertPath(t)),I.fixEnd(t)})};const fe=function(t){if(!w())return t;const e=t.cloneNode(!0);return t.before(e),t.remove(),ft.releaseSelector(t),y[0]=e,ft.requestSelector(e).showGrips(!0),e};this.setRotationAngle=function(t,e){t=Number.parseFloat(t);const n=y[0],r=n.getAttribute("transform"),s=ht(n),i=s.x+s.width/2,o=s.y+s.height/2,a=P(n);if(a.numberOfItems>0){4===a.getItem(0).type&&a.removeItem(0)}if(0!==t){const e=L(i,o,B(a).matrix),n=c.createSVGTransform();n.setRotate(t,e.x,e.y),a.numberOfItems?a.insertItemBefore(n,0):a.appendItem(n)}else 0===a.numberOfItems&&n.removeAttribute("transform");if(!e){const t=n.getAttribute("transform");n.setAttribute("transform",r),Ue("transform",t,y),kt("changed",y)}ft.requestSelector(y[0]).resize(),Pn.updateGripCursors(t)};const ye=this.recalculateAllSelectedDimensions=function(){const t=new Bn("none"===ie?"position":"size");let e=y.length;for(;e--;){const n=y[e],r=vn(n);r&&t.addSubCommand(r)}t.isEmpty()||(lt(t),kt("changed",y))},xe=function(t){console.log([t.a,t.b,t.c,t.d,t.e,t.f])};let _e=null;const be=this.selectOnly=function(t,e){It(!0),Mt(t,e)};this.removeFromSelection=function(t){if(Nt(y[0]))return;if(!t.length)return;const e=[],n=y.length;for(let r=0;r0&&o.removeFromSelection(t),e.length>0&&o.addToSelection(e);break}case"resize":{z=P(R);const e=M(z);O=e?x:ht(R);let n=O.x,r=O.y,{width:i,height:o}=O;if(b=Q-a,v=X-h,s.gridSnapping&&(b=Et(b),v=Et(v),o=Et(o),i=Et(i)),V=bt(R),V){const t=Math.sqrt(b*b+v*v),e=Math.atan2(v,b)-V*Math.PI/180;b=t*Math.cos(e),v=t*Math.sin(e)}ie.includes("n")||ie.includes("s")||(v=0),ie.includes("e")||ie.includes("w")||(b=0);let l=0,u=0,d=o?(o+v)/o:1,m=i?(i+b)/i:1;ie.includes("n")&&(d=o?(o-v)/o:1,u=o),ie.includes("w")&&(m=i?(i-b)/i:1,l=i);const g=c.createSVGTransform(),p=c.createSVGTransform(),f=c.createSVGTransform();if(s.gridSnapping&&(n=Et(n),l=Et(l),r=Et(r),u=Et(u)),g.setTranslate(-(n+l),-(r+u)),t.shiftKey&&(1===m?m=d:d=m),p.setScale(m,d),f.setTranslate(n+l,r+u),e){const t=V?1:0;z.replaceItem(g,2+t),z.replaceItem(p,1+t),z.replaceItem(f,Number(t))}else{const t=z.numberOfItems;z.replaceItem(f,t-3),z.replaceItem(p,t-2),z.replaceItem(g,t-1)}ft.requestSelector(R).resize(),kt("transition",y);break}case"zoom":q*=d,W*=d,Ct(ce,{x:Math.min(g*d,q),y:Math.min(f*d,W),width:Math.abs(q-g*d),height:Math.abs(W-f*d)});break;case"text":Ct(D,{x:Q,y:X});break;case"line":{s.gridSnapping&&(Q=Et(Q),X=Et(X));let e=Q,n=X;t.shiftKey&&(u=j(a,h,e,n),e=u.x,n=u.y),D.setAttribute("x2",e),D.setAttribute("y2",n);break}case"foreignObject":case"square":case"rect":case"image":{const e="square"===se||t.shiftKey;let n,r,i=Math.abs(Q-a),o=Math.abs(X-h);e?(i=o=Math.max(i,o),n=a.8){_-=.8;const t=l.createSVGPoint();t.x=G.x,t.y=G.y,D.points.appendItem(t)}w={x:A.x,y:A.y},A={x:C.x,y:C.y},C={x:E.x,y:E.y};break;case"path":case"pathedit":if(Q*=d,X*=d,s.gridSnapping&&(Q=Et(Q),X=Et(X),a=Et(a),h=Et(h)),t.shiftKey){const{path:t}=Le;let e,n;t?(e=t.dragging?t.dragging[0]:a,n=t.dragging?t.dragging[1]:h):(e=a,n=h),u=j(e,n,Q,X),({x:Q,y:X}=u)}ce&&"none"!==ce.getAttribute("display")&&(q*=d,W*=d,Ct(ce,{x:Math.min(g*d,q),y:Math.min(f*d,W),width:Math.abs(q-g*d),height:Math.abs(W-f*d)})),I.mouseMove(Q,X);break;case"textedit":Q*=d,X*=d,Ae.mouseMove(H,F);break;case"rotate":{O=ht(R),p=O.x+O.width/2,S=O.y+O.height/2;const e=U(R),n=L(p,S,e);if(p=n.x,S=n.y,V=(Math.atan2(S-X,p-Q)*(180/Math.PI)-90)%360,s.gridSnapping&&(V=Et(V)),t.shiftKey){const t=45;V=Math.round(V/t)*t}o.setRotationAngle(V<-180?360+V:V,!0),kt("transition",y);break}}ue("mouseMove",{event:t,mouse_x:H,mouse_y:F,selected:R})})).click((function(t){return t.preventDefault(),!1})).dblclick((function(t){const e=t.target.parentNode;let n=Ut(t);const{tagName:r}=n;if("text"===r&&"textedit"!==se){const e=L(t.pageX,t.pageY,_e);Ae.select(n,e.x,e.y)}e!==m&&("g"!==r&&"a"!==r||!bt(n)||(Fe(n),n=y[0],It(!0)),m&&ln(),"g"!==e.tagName&&"a"!==e.tagName||e===u().getCurrentLayer()||n===ft.selectorParentGroup||hn(n))})).mouseup((function(t){if(2===t.button)return;const n=ae;if(ae=null,!ee)return;const r=L(t.pageX,t.pageY,_e),i=r.x*d,a=r.y*d,c=i/d,l=a/d;let h=At(_t()),m=!1;const x=c,b=l;let G,N;switch(ee=!1,se){case"resize":case"multiselect":Nt(ce)||(ce.setAttribute("display","none"),le=[]),se="select";case"select":if(!Nt(y[0])){if(Nt(y[1])){const t=y[0];switch(t.tagName){case"g":case"use":case"image":case"foreignObject":break;default:oe.fill=t.getAttribute("fill"),oe.fill_opacity=t.getAttribute("fill-opacity"),oe.stroke=t.getAttribute("stroke"),oe.stroke_opacity=t.getAttribute("stroke-opacity"),oe.stroke_width=t.getAttribute("stroke-width"),oe.stroke_dasharray=t.getAttribute("stroke-dasharray"),oe.stroke_linejoin=t.getAttribute("stroke-linejoin"),oe.stroke_linecap=t.getAttribute("stroke-linecap")}"text"===t.tagName&&(Yt.font_size=t.getAttribute("font-size"),Yt.font_family=t.getAttribute("font-family")),ft.requestSelector(t).showGrips(!0)}if(ye(),x!==g||b!==f){const t=y.length;for(let e=0;e=0?t.includes(",",e+1):t.includes(" ",t.indexOf(" ")+1),m&&(h=I.smoothPolylineIntoPath(h));break}case"line":G=Ln(h).attr(["x1","x2","y1","y2"]),m=G.x1!==G.x2||G.y1!==G.y2;break;case"foreignObject":case"square":case"rect":case"image":G=Ln(h).attr(["width","height"]),m=G.width||G.height||"image"===se;break;case"circle":m="0"!==h.getAttribute("r");break;case"ellipse":G=Ln(h).attr(["rx","ry"]),m=G.rx||G.ry;break;case"fhellipse":e.maxx-e.minx>0&&e.maxy-e.miny>0&&(h=S({element:"ellipse",curStyles:!0,attr:{cx:(e.minx+e.maxx)/2,cy:(e.miny+e.maxy)/2,rx:(e.maxx-e.minx)/2,ry:(e.maxy-e.miny)/2,id:_t()}}),kt("changed",[h]),m=!0);break;case"fhrect":e.maxx-e.minx>0&&e.maxy-e.miny>0&&(h=S({element:"rect",curStyles:!0,attr:{x:e.minx,y:e.miny,width:e.maxx-e.minx,height:e.maxy-e.miny,id:_t()}}),kt("changed",[h]),m=!0);break;case"text":m=!0,be([h]),Ae.start(h);break;case"path":{h=null,ee=!0;const e=I.mouseUp(t,h,i,a);({element:h}=e),({keep:m}=e);break}case"pathedit":m=!0,h=null,I.mouseUp(t);break;case"textedit":m=!1,h=null,Ae.mouseUp(t,i,a);break;case"rotate":{m=!0,h=null,se="select";const t=o.undoMgr.finishUndoableChange();t.isEmpty()||lt(t),ye(),kt("changed",y);break}}const k=ue("mouseUp",{event:t,mouse_x:i,mouse_y:a},!0);if(Ln.each(k,(function(t,e){e&&(m=e.keep||m,({element:h}=e),ee=e.started||ee)})),m||Nt(h)){if(!Nt(h)){o.addedNew=!0;let t,e=.2;if(zt.beginElement&&Number.parseFloat(h.getAttribute("opacity"))!==p.opacity){t=Ln(zt).clone().attr({to:p.opacity,dur:e}).appendTo(h);try{t[0].beginElement()}catch(t){}}else e=0;setTimeout((function(){t&&t.remove(),h.setAttribute("opacity",p.opacity),h.setAttribute("style","pointer-events:inherit"),vt(h),"path"===se?I.toEditMode(h):s.selectNew&&be([h],!0),lt(new On(h)),kt("changed",[h])}),1e3*e)}}else{for(u().releaseId(_t()),h.remove(),h=null,N=t.target;N&&N.parentNode&&N.parentNode.parentNode&&"g"===N.parentNode.parentNode.tagName;)N=N.parentNode;"path"===se&&we||!N||!N.parentNode||"selectorParentGroup"===N.parentNode.id||"svgcanvas"===N.id||"svgroot"===N.id||(o.setMode("select"),be([N],!0))}re=null})),Ln(t).bind("mousewheel DOMMouseScroll",(function(t){if(!t.shiftKey)return;t.preventDefault();const e=t.originalEvent;_e=Ln("#svgcontent g")[0].getScreenCTM().inverse();const n=Ln("#workarea"),r=s.showRulers?16:0,i=L(e.pageX,e.pageY,_e),a=n.width(),c=n.height(),l=a-15-r,h=c-15-r,u=l*_e.a,m=h*_e.d,g=n.offset(),p=g.left+r,f=g.top+r,y=e.wheelDelta?e.wheelDelta:e.detail?-e.detail:0;if(!y)return;let x,S,_=Math.max(3/4,Math.min(4/3,y));_>1?(x=Math.ceil(l/u*_*100)/100,S=Math.ceil(h/m*_*100)/100):(x=Math.floor(l/u*_*100)/100,S=Math.floor(h/m*_*100)/100);let b=Math.min(x,S);if(b=Math.min(10,Math.max(.01,b)),b===d)return;_=b/d;const w=L(p,f,_e),A={x:(i.x-(i.x-w.x)/_)*b-r+a/2,y:(i.y-(i.y-w.y)/_)*b-r+c/2};o.setZoom(b),Ln("#zoom").val((100*b).toFixed(1)),kt("updateCanvas",{center:!1,newCtr:A}),kt("zoomDone")}))}();const Ae=o.textActions=function(){let t,n,r,s,i,a,l,h,u,m,g=[];function p(t){const o=""===n.value;if(Ln(n).focus(),!arguments.length)if(o)t=0;else{if(n.selectionEnd!==n.selectionStart)return;t=n.selectionEnd}const c=g[t];o||n.setSelectionRange(t,t),r=At("text_cursor"),r||(r=document.createElementNS(e.SVG,"line"),Ct(r,{id:"text_cursor",stroke:"#333","stroke-width":1}),r=At("selectorParentGroup").appendChild(r)),i||(i=setInterval((function(){const t="none"===r.getAttribute("display");r.setAttribute("display",t?"inline":"none")}),600));const l=A(c.x,a.y),h=A(c.x,a.y+a.height);Ct(r,{x1:l.x,y1:l.y,x2:h.x,y2:h.y,visibility:"visible",display:"inline"}),s&&s.setAttribute("d","")}function x(t,i,o){if(t===i)return void p(i);o||n.setSelectionRange(t,i),s=At("text_selectblock"),s||(s=document.createElementNS(e.SVG,"path"),Ct(s,{id:"text_selectblock",fill:"green",opacity:.5,style:"pointer-events:none"}),At("selectorParentGroup").append(s));const c=g[t],l=g[i];r.setAttribute("visibility","hidden");const h=A(c.x,a.y),u=A(c.x+(l.x-c.x),a.y),d=A(c.x,a.y+a.height),m=A(c.x+(l.x-c.x),a.y+a.height),f="M"+h.x+","+h.y+" L"+u.x+","+u.y+" "+m.x+","+m.y+" "+d.x+","+d.y+"z";Ct(s,{d:f,display:"inline"})}function S(e,n){const r=c.createSVGPoint();if(r.x=e,r.y=n,1===g.length)return 0;let s=t.getCharNumAtPosition(r);s<0?(s=g.length-2,e<=g[0].x&&(s=0)):s>=g.length-2&&(s=g.length-2);const i=g[s];return e>i.x+i.width/2&&s++,s}function _(t,e){p(S(t,e))}function b(t,e,r){const s=n.selectionStart,i=S(t,e);x(Math.min(s,i),Math.max(s,i),!r)}function w(t,e){const n={x:t,y:e};if(n.x/=d,n.y/=d,l){const t=L(n.x,n.y,l.inverse());n.x=t.x,n.y=t.y}return n}function A(t,e){const n={x:t,y:e};if(l){const t=L(n.x,n.y,l);n.x=t.x,n.y=t.y}return n.x*=d,n.y*=d,n}function C(e){x(0,t.textContent.length),Ln(this).unbind(e)}function v(e){if(!m||!t)return;const n=L(e.pageX,e.pageY,_e),r=w(n.x*d,n.y*d),s=S(r.x,r.y),i=t.textContent,o=i.substr(0,s).replace(/[a-z\d]+$/i,"").length,a=i.substr(s).match(/^[a-z\d]+/i);x(o,(a?a[0].length:0)+s),Ln(e.target).click(C),setTimeout((function(){Ln(e.target).unbind("click",C)}),300)}return{select(e,n,r){t=e,Ae.toEditMode(n,r)},start(e){t=e,Ae.toEditMode()},mouseDown(t,e,r,s){const i=w(r,s);n.focus(),_(i.x,i.y),h=r,u=s},mouseMove(t,e){const n=w(t,e);b(n.x,n.y)},mouseUp(e,n,r){const s=w(n,r);b(s.x,s.y,!0),e.target!==t&&nh-2&&ru-2&&Ae.toSelectMode(!0)},setCursor:p,toEditMode(e,n){if(m=!1,se="textedit",ft.requestSelector(t).showGrips(!1),ft.requestSelector(t),Ae.init(),Ln(t).css("cursor","text"),arguments.length){const t=w(e,n);_(t.x,t.y)}else p();setTimeout((function(){m=!0}),300)},toSelectMode(e){se="select",clearInterval(i),i=null,s&&Ln(s).attr("display","none"),r&&Ln(r).attr("visibility","hidden"),Ln(t).css("cursor","move"),e&&(It(),Ln(t).css("cursor","move"),kt("selected",[t]),Mt([t],!0)),t&&!t.textContent.length&&o.deleteSelectedElements(),Ln(n).blur(),t=!1},setInputElem(t){n=t},clear(){"textedit"===se&&Ae.toSelectMode()},init(e){if(!t)return;let r,s;t.parentNode||(t=y[0],ft.requestSelector(t).showGrips(!1));const i=t.textContent.length,c=t.getAttribute("transform");for(a=ht(t),l=c?U(t):null,g=[],g.length=i,n.focus(),Ln(t).unbind("dblclick",v).dblclick(v),i||(s={x:a.x+a.width/2,width:0}),r=0;r")[0].getContext("2d")||(n.text=jt.exportNoText),Ln.each(n,(function(n,s){r.find(n).length&&(e.push(n),t.push(s))})),{issues:t,issueCodes:e}}let Ee;this.svgCanvasToString=function(){for(;Ce()>0;);I.clear(!0),Ln.each(l.childNodes,(function(t,e){t&&8===e.nodeType&&e.data.includes("Created with")&&l.firstChild.before(e)})),m&&(ln(),be([m]));const t=[];Ln(l).find("g:data(gsvg)").each((function(){const e=this.attributes;let n=e.length;for(let t=0;tt.name>e.name?-1:1);for(let t=0;t=0;a--){const c=s[a];let l=Z(c.value);if(!n.includes(c.localName)){if("null"===l){const e=c.localName.replace(/-[a-z]/g,t=>t[1].toUpperCase());if(Object.prototype.hasOwnProperty.call(t.style,e))continue}if(""!==l){if(l.startsWith("pointer-events"))continue;if("class"===c.localName&&l.startsWith("se_"))continue;if(r.push(" "),"d"===c.localName&&(l=I.convertPath(t,!0)),isNaN(l)?o.test(l)&&(l=Vt(l)+i):l=Vt(l),Xt.apply&&"image"===t.nodeName&&"href"===c.localName&&Xt.images&&"embed"===Xt.images){const t=Wt[l];t&&(l=t)}c.namespaceURI&&c.namespaceURI!==e.SVG&&!J[c.namespaceURI]||(r.push(c.nodeName),r.push('="'),r.push(l),r.push('"'))}}}}if(t.hasChildNodes()){r.push(">"),n++;let e=!1;for(let t=0;t");break;case 8:r.push("\n"),r.push(new Array(n+1).join(" ")),r.push("\x3c!--"),r.push(s.data),r.push("--\x3e")}}if(n--,!e){r.push("\n");for(let t=0;t")}else r.push("/>")}return r.join("")},this.embedImage=function(t){return new Promise((function(e,n){Ln(new Image).load((function(r,s,i){if("error"===s)return void n(new Error("Error loading image: "+i.status+" "+i.statusText));const o=document.createElement("canvas");o.width=this.width,o.height=this.height,o.getContext("2d").drawImage(this,0,0);try{let e=";svgedit_url="+encodeURIComponent(t);e=o.toDataURL().replace(";base64",e+";base64"),Wt[t]=e}catch(e){Wt[t]=!1}te=t,e(Wt[t])})).attr("src",t)}))},this.setGoodImage=function(t){te=t},this.open=function(){},this.save=function(t){It(),t&&Ln.extend(Xt,t),Xt.apply=!0;const e=this.svgCanvasToString();kt("saved",e)},this.rasterExport=async function(t,e,n,r={}){const i="ICO"===t?"BMP":t||"PNG",a="image/"+i.toLowerCase(),{issues:c,issueCodes:l}=ve(),h=this.svgCanvasToString();Ee||({canvg:Ee}=await fn(s.canvgPath+"canvg.js",{global:"canvg"})),Ln("#export_canvas").length||Ln("",{id:"export_canvas"}).hide().appendTo("body");const u=Ln("#export_canvas")[0];return u.width=o.contentW,u.height=o.contentH,await Ee(u,h),new Promise((s,o)=>{const d=i.toLowerCase(),m=e?u.toDataURL("image/"+d,e):u.toDataURL("image/"+d);let g;function p(){const i={datauri:m,bloburl:g,svg:h,issues:c,issueCodes:l,type:t,mimeType:a,quality:e,exportWindowName:n};r.avoidEvent||kt("exported",i),s(i)}u.toBlob?u.toBlob(t=>{g=et(t),p()},a,e):(g=function(t){if("undefined"==typeof Uint8Array||"undefined"==typeof Blob||"undefined"==typeof URL||!URL.createObjectURL)return"";const e=t.split(","),n=e[0].match(/:(.*?);/)[1],r=atob(e[1]);let s=r.length;const i=new Uint8Array(s);for(;s--;)i[s]=r.charCodeAt(s);const o=new Blob([i],{type:n});return URL.createObjectURL(o)}(m),p())})},this.exportPDF=async function(t,e=(C()?"save":void 0)){if(!window.jsPDF){await yn(["jspdf/underscore-min.js","../../svgedit-myfix/editor/jspdf/jspdf-1.0.150.debug.js"]);const t=!("svgEditor"in window)||!window.svgEditor||!1!==window.svgEditor.modules;await yn(s.jspdfPath+"jspdf.plugin.svgToPdf.js",{type:t?"module":"text/javascript"})}const n=Ve(),r=n.w>n.h?"landscape":"portrait",i=jsPDF({orientation:r,unit:"pt",format:[n.w,n.h]}),o=Oe();i.setProperties({title:o});const{issues:a,issueCodes:c}=ve(),l=this.svgCanvasToString();i.addSVG(l,0,0);const h={svg:l,issues:a,issueCodes:c,exportWindowName:t,outputType:e=e||"dataurlstring"};return h.output=i.output(e,"save"===e?t||"svg.pdf":void 0),kt("exportedPDF",h),h},this.getSvgString=function(){return Xt.apply=!1,this.svgCanvasToString()},this.randomizeIds=function(t){Ke(!(arguments.length>0&&!1===t),u())};const Ne=this.uniquifyElems=function(t){const e={},n=["filter","linearGradient","pattern","radialGradient","symbol","textPath","use"];rt(t,(function(t){if(1===t.nodeType){t.id&&(t.id in e||(e[t.id]={elem:null,attrs:[],hrefs:[]}),e[t.id].elem=t),Ln.each(Ft,(function(n,r){const s=t.getAttributeNode(r);if(s){const t=st(s.value),n=t?t.substr(1):null;n&&(n in e||(e[n]={elem:null,attrs:[],hrefs:[]}),e[n].attrs.push(s))}}));const r=it(t);if(r&&n.includes(t.nodeName)){const n=r.substr(1);n&&(n in e||(e[n]={elem:null,attrs:[],hrefs:[]}),e[n].hrefs.push(t))}}}));for(const t in e){if(!t)continue;const{elem:n}=e[t];if(n){const r=yt();n.id=r;const{attrs:s}=e[t];let i=s.length;for(;i--;){const t=s[i];t.ownerElement.setAttribute(t.name,"url(#"+r+")")}const o=e[t].hrefs;let a=o.length;for(;a--;){const t=o[a];ot(t,"#"+r)}}}},ke=this.setUseData=function(t){let e=Ln(t);"use"!==t.tagName&&(e=e.find("use")),e.each((function(){const t=it(this).substr(1),e=At(t);e&&(Ln(this).data("ref",e),"symbol"!==e.tagName&&"svg"!==e.tagName||Ln(this).data("symbol",e).data("ref",e))}))},Ie=this.convertGradients=function(t){let e=Ln(t).find("linearGradient, radialGradient");!e.length&&b()&&(e=Ln(t).find("*").filter((function(){return this.tagName.includes("Gradient")}))),e.each((function(){const t=this;if("userSpaceOnUse"===Ln(t).attr("gradientUnits")){const e=Ln(l).find('[fill="url(#'+t.id+')"],[stroke="url(#'+t.id+')"]');if(!e.length)return;const n=ht(e[0]);if(!n)return;if("linearGradient"===t.tagName){const e=Ln(t).attr(["x1","y1","x2","y2"]),r=t.gradientTransform.baseVal;if(r&&r.numberOfItems>0){const n=B(r).matrix,s=L(e.x1,e.y1,n),i=L(e.x2,e.y2,n);e.x1=s.x,e.y1=s.y,e.x2=i.x,e.y2=i.y,t.removeAttribute("gradientTransform")}Ln(t).attr({x1:(e.x1-n.x)/n.width,y1:(e.y1-n.y)/n.height,x2:(e.x2-n.x)/n.width,y2:(e.y2-n.y)/n.height}),t.removeAttribute("gradientUnits")}}}))},Pe=this.convertToGroup=function(t){t||(t=y[0]);const n=Ln(t),r=new Bn;let s;if(n.data("gsvg")){const e=t.firstChild,n=Ln(e).attr(["x","y"]);Ln(t.firstChild.firstChild).unwrap(),Ln(t).removeData("gsvg");const r=P(t),s=c.createSVGTransform();s.setTranslate(n.x,n.y),r.appendItem(s),vn(t),kt("selected",[t])}else if(n.data("symbol")){t=n.data("symbol"),s=n.attr("transform");const i=n.attr(["x","y"]),o=t.getAttribute("viewBox");if(o){const t=o.split(" ");i.x-=Number(t[0]),i.y-=Number(t[1])}s+=" translate("+(i.x||0)+","+(i.y||0)+")";const c=n.prev();r.addSubCommand(new Mn(n[0],n[0].nextSibling,n[0].parentNode)),n.remove();const h=Ln(l).find("use:data(symbol)").length,u=a.createElementNS(e.SVG,"g"),d=t.childNodes;let m;for(m=0;mu?"scale("+p/3/g[3]+")":"scale("+p/3/g[2]+")",r="translate(0) "+r+" translate(0)",h=a.createElementNS(e.SVG,"symbol");const f=at();for(w()&&Ln(o).find("linearGradient, radialGradient, pattern").appendTo(f);o.firstChild;){const t=o.firstChild;h.append(t)}const y=o.attributes;for(const t of y)h.setAttribute(t.nodeName,t.value);h.id=yt(),Zt[i]={symbol:h,xform:r},at().append(h),c.addSubCommand(new On(h))}s=a.createElementNS(e.SVG,"use"),s.id=yt(),ot(s,"#"+h.id),(m||u().getCurrentLayer()).append(s),c.addSubCommand(new On(s)),It(),s.setAttribute("transform",r),vn(s),Ln(s).data("symbol",h).data("ref",h),Mt([s]),lt(c),kt("changed",[l])}catch(t){return console.log(t),null}return s};const Te={identifyLayers:Ye,createLayer:$e,cloneLayer:Je,deleteCurrentLayer:tn,setCurrentLayer:en,renameCurrentLayer:nn,setCurrentLayerPosition:rn,setLayerVisibility:sn,moveSelectedToLayer:on,mergeLayer:an,mergeAllLayers:cn,leaveContext:ln,setContext:hn};Object.entries(Te).forEach(([t,e])=>{o[t]=e}),function(t){Ze=t}({pathActions:I,getCurrentGroup:()=>m,setCurrentGroup(t){m=t},getSelectedElements:G,getSVGContent:E,undoMgr:tt,elData:Dt,getCurrentDrawing:u,clearSelection:It,call:kt,addCommandToHistory:lt,changeSVGContent(){kt("changed",[l])}}),this.clear=function(){I.clear(),It(),o.clearSvgContentElement(),o.current_drawing_=new Xe(l),o.createLayer("Layer 1"),o.undoMgr.resetUndoStack(),ft.initGroup(),ce=ft.getRubberBandBox(),kt("cleared")},this.linkControlPoints=I.linkControlPoints,this.getContentElem=function(){return l},this.getRootElem=function(){return c};const Ve=this.getResolution=function(){return{w:l.getAttribute("width")/d,h:l.getAttribute("height")/d,zoom:d}};this.getSnapToGrid=function(){return s.gridSnapping},this.getVersion=function(){return"svgcanvas.js ($Rev$)"},this.setUiStrings=function(t){Object.assign(jt,t.notification),Ln=function(t,{ok:e="Ok",cancel:n="Cancel"}={}){t("#dialog_container").draggable({cancel:"#dialog_content, #dialog_buttons *",containment:"window"}).css("position","absolute");const r=t("#dialog_box"),s=t("#dialog_buttons"),i=t("#dialog_content");function o(o,a,c,l,h,u){i.html("

"+a.replace(/\n/g,"

")+"

").toggleClass("prompt","prompt"===o),s.empty();const d=t('').appendTo(s);return new Promise((e,m)=>{let g,p;if("alert"!==o&&t('').appendTo(s).click((function(){r.hide(),e(!1)})),"prompt"===o)g=t('').prependTo(s),g.val(c||""),g.bind("keydown","return",(function(){d.click()}));else if("select"===o){const e=t('
');if(g=t(`').appendTo(n),p.val(u.value),u.tooltip&&n.attr("title",u.tooltip),p.prop("checked",Boolean(u.checked)),e.append(t("
").append(n))}t.each(l||[],(function(e,n){"object"==typeof n?g.append(t("