33 lines
176 KiB
JavaScript
33 lines
176 KiB
JavaScript
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<r;++s){const r=this[s];if("http://www.w3.org/2000/svg"!==r.namespaceURI)return e.call(this,t,n);if(void 0!==n)r.setAttribute(t,n);else if(Array.isArray(t)){const e={};let n=t.length;for(;n--;){const s=t[n];let i=r.getAttribute(s);(i||"0"===i)&&(i=isNaN(i)?i:i-0),e[s]=i}return e}if("object"!=typeof t){let e=r.getAttribute(t);return(e||"0"===e)&&(e=isNaN(e)?e:e-0),e}for(const[e,n]of Object.entries(t))r.setAttribute(e,n)}return this},t}(()=>{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<this._endIndex&&this._isCurrentSpace();)this._currentIndex++;return this._currentIndex<this._endIndex}_skipOptionalSpacesOrDelimiter(){return!(this._currentIndex<this._endIndex&&!this._isCurrentSpace()&&","!==this._string.charAt(this._currentIndex))&&(this._skipOptionalSpaces()&&this._currentIndex<this._endIndex&&","===this._string.charAt(this._currentIndex)&&(this._currentIndex++,this._skipOptionalSpaces()),this._currentIndex<this._endIndex)}hasMoreData(){return this._currentIndex<this._endIndex}peekSegmentType(){const t=this._string[this._currentIndex];return this._pathSegTypeFromChar(t)}_pathSegTypeFromChar(t){switch(t){case"Z":case"z":return SVGPathSeg.PATHSEG_CLOSEPATH;case"M":return SVGPathSeg.PATHSEG_MOVETO_ABS;case"m":return SVGPathSeg.PATHSEG_MOVETO_REL;case"L":return SVGPathSeg.PATHSEG_LINETO_ABS;case"l":return SVGPathSeg.PATHSEG_LINETO_REL;case"C":return SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS;case"c":return SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL;case"Q":return SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS;case"q":return SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL;case"A":return SVGPathSeg.PATHSEG_ARC_ABS;case"a":return SVGPathSeg.PATHSEG_ARC_REL;case"H":return SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS;case"h":return SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL;case"V":return SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS;case"v":return SVGPathSeg.PATHSEG_LINETO_VERTICAL_REL;case"S":return SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS;case"s":return SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL;case"T":return SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS;case"t":return SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL;default:return SVGPathSeg.PATHSEG_UNKNOWN}}_nextCommandHelper(t,e){return("+"===t||"-"===t||"."===t||t>="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<this._endIndex&&"+"===this._string.charAt(this._currentIndex)?this._currentIndex++:this._currentIndex<this._endIndex&&"-"===this._string.charAt(this._currentIndex)&&(this._currentIndex++,s=-1),this._currentIndex===this._endIndex||(this._string.charAt(this._currentIndex)<"0"||this._string.charAt(this._currentIndex)>"9")&&"."!==this._string.charAt(this._currentIndex))return;const a=this._currentIndex;for(;this._currentIndex<this._endIndex&&this._string.charAt(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)){if(this._currentIndex++,this._currentIndex>=this._endIndex||this._string.charAt(this._currentIndex)<"0"||this._string.charAt(this._currentIndex)>"9")return;for(;this._currentIndex<this._endIndex&&this._string.charAt(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&&("e"===this._string.charAt(this._currentIndex)||"E"===this._string.charAt(this._currentIndex))&&"x"!==this._string.charAt(this._currentIndex+1)&&"m"!==this._string.charAt(this._currentIndex+1)){if(this._currentIndex++,"+"===this._string.charAt(this._currentIndex)?this._currentIndex++:"-"===this._string.charAt(this._currentIndex)&&(this._currentIndex++,i=-1),this._currentIndex>=this._endIndex||this._string.charAt(this._currentIndex)<"0"||this._string.charAt(this._currentIndex)>"9")return;for(;this._currentIndex<this._endIndex&&this._string.charAt(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 <a href="http://opera.com">latest version</a> 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<this.numberOfItems;++e){t+=G(this._list.getItem(e))+" "}this._elem.setAttribute("transform",t)},this._list=this,this._init=function(){let t=this._elem.getAttribute("transform");if(!t)return;const e=/\s*((scale|matrix|rotate|translate)\s*\(.*?\))\s*,?\s*/;let n=!0;for(;n;)if(n=t.match(e),t=t.replace(e,""),n&&n[1]){const t=n[1].split(/\s*\(/),e=t[0],r=t[1].match(/\s*(.*?)\s*\)/);r[1]=r[1].replace(/(\d)-/g,"$1 -");const s=r[1].split(/[, ]+/),i="abcdef".split(""),o=E.createSVGMatrix();Object.values(s).forEach((function(t,n){s[n]=Number.parseFloat(t),"matrix"===e&&(o[i[n]]=s[n])}));const a=E.createSVGTransform(),c="set"+e.charAt(0).toUpperCase()+e.slice(1),l="matrix"===e?[o]:s;"scale"===e&&1===l.length?l.push(l[0]):"translate"===e&&1===l.length?l.push(0):"rotate"===e&&1===l.length&&l.push(0,0),a[c](...l),this._list.appendItem(a)}},this._removeFromOtherLists=function(t){t&&Object.values(N).some(e=>{for(let n=0,r=e._xforms.length;n<r;++n)if(e._xforms[n]===t)return e.removeItem(n),!0;return!1})},this.numberOfItems=0}clear(){this.numberOfItems=0,this._xforms=[]}initialize(t){this.numberOfItems=1,this._removeFromOtherLists(t),this._xforms=[t]}getItem(t){if(t<this.numberOfItems&&t>=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<this.numberOfItems){this._removeFromOtherLists(t);const r=new Array(this.numberOfItems+1);let s;for(s=0;s<e;++s)r[s]=this._xforms[s];r[s]=t;for(let t=s+1;s<this.numberOfItems;++t,++s)r[t]=this._xforms[s];this.numberOfItems++,this._xforms=r,n=t,this._list._update()}else n=this._list.appendItem(t);return n}replaceItem(t,e){let n=null;return e<this.numberOfItems&&e>=0&&(this._removeFromOtherLists(t),this._xforms[e]=t,n=t,this._list._update()),n}removeItem(t){if(t<this.numberOfItems&&t>=0){const e=this._xforms[t],n=new Array(this.numberOfItems-1);let r;for(r=0;r<t;++r)n[r]=this._xforms[r];for(let t=r;t<this.numberOfItems-1;++t,++r)n[t]=this._xforms[r+1];return this.numberOfItems--,this._xforms=n,this._list._update(),e}const e=new Error("DOMException with code=INDEX_SIZE_ERR");throw e.code=1,e}appendItem(t){return this._removeFromOtherLists(t),this._xforms.push(t),this.numberOfItems++,this._list._update(),t}}let I=function(t){t.id&&N[t.id]&&delete N[t.id]};const P=function(t){if(!_){const e=t.id||"temp";let n=N[e];return n&&"temp"!==e||(N[e]=new k(t),N[e]._init(),n=N[e]),n}return t.transform?t.transform.baseVal:t.gradientTransform?t.gradientTransform.baseVal:t.patternTransform?t.patternTransform.baseVal:null},T=document.createElementNS(e.SVG,"svg"),L=function(t,e,n){return{x:n.a*t+n.c*e+n.e,y:n.b*t+n.d*e+n.f}},V=function(t){return 1===t.a&&0===t.b&&0===t.c&&1===t.d&&0===t.e&&0===t.f},O=function(...t){const e=t.reduceRight((t,e)=>e.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&&s<t.numberOfItems?t.getItem(s).matrix:T.createSVGMatrix();r=O(r,e)}return T.createSVGTransformFromMatrix(r)},U=function(t){const e=P(t);return B(e).matrix},j=function(t,e,n,r){const s=Math.PI/4,i=n-t,o=r-e,a=Math.atan2(o,i),c=Math.sqrt(i*i+o*o),l=Math.round(a/s)*s;return{x:t+c*Math.cos(l),y:e+c*Math.sin(l),a:l}},H=function(t,e){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.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(/(<!DOCTYPE\s+\w*\s*\[).*(\?]>)/,"$1$2"),Z=function(t){return t.replace(/&/g,"&").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<t.length);return e.join("")}function $(t){if(window.atob)return J(window.atob(t));t=t.replace(/[^A-Za-z\d+/=]/g,"");let e="",n=0;do{const r=D.indexOf(t.charAt(n++)),s=D.indexOf(t.charAt(n++)),i=D.indexOf(t.charAt(n++)),o=D.indexOf(t.charAt(n++)),a=r<<2|s>>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(n<t.length);return J(e)}function J(t){return decodeURIComponent(escape(t))}const tt=function(t){return unescape(encodeURIComponent(t))},et=function(t){return t&&"undefined"!=typeof URL&&URL.createObjectURL?URL.createObjectURL(t):""},nt=(function(){if("undefined"==typeof Blob)return"";const t=new Blob(["<html><head><title>SVG-edit</title></head><body> </body></html>"],{type:"text/html"});et(t)}(),function(t){let e,n;t.includes("<svg:svg")&&(t=t.replace(/<(\/?)svg:/g,"<$1").replace("xmlns:svg","xmlns"));try{n=window.DOMParser?new DOMParser:new window.ActiveXObject("Microsoft.XMLDOM"),n.async=!1}catch(t){throw new Error("XML Parser could not be instantiated")}try{e=n.loadXML?!!n.loadXML(t)&&n:n.parseFromString(t,"text/xml")}catch(t){throw new Error("Error parsing XML string")}return e}),rt=function(t,e){if(t&&1===t.nodeType){e(t);let n=t.childNodes.length;for(;n--;)rt(t.childNodes.item(n),e)}},st=function(t){if(t){if(t.startsWith('url("'))return t.substring(5,t.indexOf('"',6));if(t.startsWith("url('"))return t.substring(5,t.indexOf("'",6));if(t.startsWith("url("))return t.substring(4,t.indexOf(")"))}return null};let it=function(t){return t.getAttributeNS(e.XLINK,"href")},ot=function(t,n){t.setAttributeNS(e.XLINK,"xlink:href",n)};const at=function(){const t=q.getSVGContent();let n=t.getElementsByTagNameNS(e.SVG,"defs");return n.length>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;t<n;t++){const n=e.getItem(t);if(void 0!==n.x)if(r[0].push(i[0]),r[1].push(i[1]),n.x1){const t=[n.x1,n.y1],e=[n.x2,n.y2],s=[n.x,n.y];for(let n=0;n<2;n++){const a=o(n,t,e,s),c=6*i[n]-12*t[n]+6*e[n],l=-3*i[n]+9*t[n]-9*e[n]+3*s[n],h=3*t[n]-3*i[n];if(0===l){if(0===c)continue;const t=-h/c;t>0&&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<r.length;t+=2)e+=r[t]+","+r[t+1]+" "})),e},dt=function(t){let e,n,r,s,i=1.81;switch(t.tagName){case"ellipse":case"circle":{n=F(t).attr(["rx","ry","cx","cy"]);const{cx:o,cy:a}=n;({rx:r,ry:s}=n),"circle"===t.tagName&&(s=F(t).attr("r"),r=s),e=ut([["M",[o-r,a]],["C",[o-r,a-s/i,o-r/i,a-s,o,a-s]],["C",[o+r/i,a-s,o+r,a-s/i,o+r,a]],["C",[o+r,a+s/i,o+r/i,a+s,o,a+s]],["C",[o-r/i,a+s,o-r,a+s/i,o-r,a]],["Z",[]]]);break}case"path":e=t.getAttribute("d");break;case"line":n=F(t).attr(["x1","y1","x2","y2"]),e="M"+n.x1+","+n.y1+"L"+n.x2+","+n.y2;break;case"polyline":e="M"+t.getAttribute("points");break;case"polygon":e="M"+t.getAttribute("points")+" Z";break;case"rect":{const n=F(t).attr(["rx","ry"]);({rx:r,ry:s}=n);const o=t.getBBox(),{x:a,y:c}=o,l=o.width,h=o.height;i=4-i,e=ut(r||s?[["M",[a,c+s]],["C",[a,c+s/i,a+r/i,c,a+r,c]],["L",[a+l-r,c]],["C",[a+l-r/i,c,a+l,c+s/i,a+l,c+s]],["L",[a+l,c+h-s]],["C",[a+l,c+h-s/i,a+l-r/i,c+h,a+l-r,c+h]],["L",[a+r,c+h]],["C",[a+r/i,c+h,a,c+h-s/i,a,c+h-s]],["L",[a,c+s]],["Z",[]]]:[["M",[a,c]],["L",[a+l,c]],["L",[a+l,c+h]],["L",[a,c+h]],["L",[a,c]],["Z",[]]]);break}}return e},mt=function(t){const e={};return F.each(["marker-start","marker-end","marker-mid","filter","clip-path"],(function(){const n=t.getAttribute(this);n&&(e[this]=n)})),e},gt=function(t,e,n){const r=e({element:"path",attr:mt(t)}),s=t.getAttribute("transform");s&&r.setAttribute("transform",s);const{parentNode:i}=t;t.nextSibling?t.before(r):i.append(r);const o=dt(t);o?r.setAttribute("d",o):r.remove(),n.resetOrientation(r);let a=!1;try{a=r.getBBox()}catch(t){}return r.remove(),a};const pt=function(t,e,n){let r=ht(t);if(!r)return null;const s=P(t),i=_t(s),o=M(s);if(i||o){let a=!1;if(function(t,e){const n=t%90;return e||!(n>-.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<n;++r){const n=t.getItem(r);if(4===n.type)return e?n.angle*Math.PI/180:n.angle}return 0};let bt=function(t,e){const n=t||q.getSelectedElements()[0],r=P(n);return _t(r,e)};const wt=function(t){return At(st(t).substr(1))},At=d?function(t){return X.querySelector("#"+t)}:m?function(t){return Q.evaluate('svg:svg[@id="svgroot"]//svg:*[@id="'+t+'"]',W,(function(){return e.SVG}),9,null).singleNodeValue}:function(t){return F(X).find("[id="+t+"]")[0]},Ct=function(t,n,r,s){for(const[r,i]of Object.entries(n)){const n="xml:"===r.substr(0,4)?e.XML:"xlink:"===r.substr(0,6)?e.XLINK:null;Nt(i)?n?t.removeAttributeNS(n,r):t.removeAttribute(r):n?t.setAttributeNS(n,r,i):s?Mt(t,r,i):t.setAttribute(r,i)}},vt=function(t){const e={"fill-opacity":1,"stop-opacity":1,opacity:1,stroke:"none","stroke-dasharray":"none","stroke-linejoin":"miter","stroke-linecap":"butt","stroke-opacity":1,"stroke-width":1,rx:0,ry:0};"ellipse"===t.nodeName&&(delete e.rx,delete e.ry),Object.entries(e).forEach(([e,n])=>{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.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,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.undoStackPointer<this.undoStack.length?this.undoStack[this.undoStackPointer].getText():""}undo(){if(this.undoStackPointer>0){this.undoStack[--this.undoStackPointer].unapply(this.handler_)}}redo(){if(this.undoStackPointer<this.undoStack.length&&this.undoStack.length>0){this.undoStack[this.undoStackPointer++].apply(this.handler_)}}addCommandToHistory(t){this.undoStackPointer<this.undoStack.length&&this.undoStack.length>0&&(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;t<s;t++){const e=r.getItem(t);i.push(e)}r.clear();for(let t=0;t<s;t++)t===n&&r.appendItem(e),r.appendItem(i[t])},se=function(t,e){return Wt[t].map(t=>e[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;e<n;e++){const n=t.getItem(e);r.push(n)}t.clear();for(let s=0;s<n;s++)s===e?t.appendItem(i):t.appendItem(r[s])}},ge=function(t,n){const{index:r}=t;let s=At("segline_"+r);if(!s){const t=ce();s=document.createElementNS(e.SVG,"path"),Ct(s,{id:"segline_"+r,display:"none",fill:"none",stroke:"#0FF","stroke-width":2,style:"pointer-events:none",d:"M0,0 0,0"}),t.append(s)}if(n){const{prev:e}=t;if(!e)return s.setAttribute("display","none"),s;const n=ie(e);me(2,0,[n.x,n.y],s);const r=se(t.type,t.item);for(let e=0;e<r.length;e+=2){const n=ie(t,{x:r[e],y:r[e+1]});r[e]=n.x,r[e+1]=n.y}me(t.type,1,r,s)}return s},pe=function(t,e,n){const r=t.x-n.x,s=t.y-n.y,i=e.x-n.x,o=e.y-n.y;if(!(0===r&&0===s||0===i&&0===o)){const t=Math.sqrt(r*r+s*s),e=Math.sqrt(i*i+o*o),a=ee.getSVGRoot().createSVGPoint(),c=ee.getSVGRoot().createSVGPoint();let l=Math.atan2(s,r),h=Math.atan2(o,i);l<0&&(l+=2*Math.PI),h<0&&(h+=2*Math.PI);const u=Math.abs(l-h),d=Math.abs(Math.PI-u)/2;let m,g;return l-h>0?(m=u<Math.PI?l+d:l-d,g=u<Math.PI?h-d:h+d):(m=u<Math.PI?l-d:l+d,g=u<Math.PI?h+d:h-d),a.x=t*Math.cos(m)+n.x,a.y=t*Math.sin(m)+n.y,c.x=e*Math.cos(g)+n.x,c.y=e*Math.sin(g)+n.y,[a,c]}};class fe{constructor(t,e){this.selected=!1,this.index=t,this.item=e,this.type=e.pathSegType,this.ctrlpts=[],this.ptgrip=null,this.segsel=null}showCtrlPts(t){for(const e in this.ctrlpts)({}).hasOwnProperty.call(this.ctrlpts,e)&&this.ctrlpts[e].setAttribute("display",t?"inline":"none")}selectCtrls(t){Qt("#ctrlpointgrip_"+this.index+"c1, #ctrlpointgrip_"+this.index+"c2").attr("fill",t?"#0FF":"#EEE")}show(t){this.ptgrip&&(this.ptgrip.setAttribute("display",t?"inline":"none"),this.segsel.setAttribute("display",t?"inline":"none"),this.showCtrlPts(t))}select(t){this.ptgrip&&(this.ptgrip.setAttribute("stroke",t?"#0FF":"#00F"),this.segsel.setAttribute("display",t?"inline":"none"),this.ctrlpts&&this.selectCtrls(t),this.selected=t)}addGrip(){this.ptgrip=ue(this,!0),this.ctrlpts=de(this),this.segsel=ge(this,!0)}update(t){if(this.ptgrip){const e=ie(this);Ct(this.ptgrip,{cx:e.x,cy:e.y}),ge(this,!0),this.ctrlpts&&(t&&(this.item=te.elem.pathSegList.getItem(this.index),this.type=this.item.pathSegType),de(this))}}move(t,e){const{item:n}=this,r=this.ctrlpts?[n.x+=t,n.y+=e,n.x1,n.y1,n.x2+=t,n.y2+=e]:[n.x+=t,n.y+=e];if(me(this.type,this.index,10===this.type?se(this.type,n):r),this.next&&this.next.ctrlpts){const n=this.next.item,r=[n.x,n.y,n.x1+=t,n.y1+=e,n.x2,n.y2];me(this.next.type,this.next.index,r)}if(this.mate){const{item:n}=this.mate,r=[n.x+=t,n.y+=e];me(this.mate.type,this.mate.index,r)}this.update(!0),this.next&&this.next.update(!0)}setLinked(t){let e,n,r;if(2===t){if(n=1,e=this.next,!e)return;r=this.item}else{if(n=2,e=this.prev,!e)return;r=e.item}const{item:s}=e;s["x"+n]=r.x+(r.x-this.item["x"+t]),s["y"+n]=r.y+(r.y-this.item["y"+t]);const i=[s.x,s.y,s.x1,s.y1,s.x2,s.y2];me(e.type,e.index,i),e.update(!0)}moveCtrl(t,e,n){const{item:r}=this;r["x"+t]+=e,r["y"+t]+=n;const s=[r.x,r.y,r.x1,r.y1,r.x2,r.y2];me(this.type,this.index,s),this.update(!0)}setType(t,e){me(t,this.index,e),this.type=t,this.item=te.elem.pathSegList.getItem(this.index),this.showCtrlPts(6===t),this.ctrlpts=de(this),this.update(!0)}}class ye{constructor(t){if(!t||"path"!==t.tagName)throw new Error("svgedit.path.Path constructed without a <path> 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;n++){const e=t.getItem(n),r=new fe(n,e);r.path=this,this.segs.push(r)}const{segs:n}=this;let r=null;for(let t=0;t<e;t++){const s=n[t],i=t+1>=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<e;n++){if(!1===t.call(this.segs[n],n))break}}addSeg(t){const e=this.segs[t];if(!e.prev)return;const{prev:n}=e;let r,s,i;switch(e.item.pathSegType){case 4:s=(e.item.x+n.item.x)/2,i=(e.item.y+n.item.y)/2,r=this.elem.createSVGPathSegLinetoAbs(s,i);break;case 6:{const o=(n.item.x+e.item.x1)/2,a=(e.item.x1+e.item.x2)/2,c=(e.item.x2+e.item.x)/2,l=(o+a)/2,h=(a+c)/2;s=(l+h)/2;const u=(n.item.y+e.item.y1)/2,d=(e.item.y1+e.item.y2)/2,m=(e.item.y2+e.item.y)/2,g=(u+d)/2,p=(d+m)/2;i=(g+p)/2,r=this.elem.createSVGPathSegCurvetoCubicAbs(s,i,o,u,l,g);const f=[e.item.x,e.item.y,h,p,c,m];me(e.type,t,f);break}}re(this.elem,r,t)}deleteSeg(t){const e=this.segs[t],n=this.elem.pathSegList;e.show(!1);const{next:r}=e;if(e.mate){const t=[r.item.x,r.item.y];me(2,r.index,t),me(4,e.index,t),n.removeItem(e.mate.index)}else if(e.prev)n.removeItem(t);else{const s=[r.item.x,r.item.y];me(2,e.next.index,s),n.removeItem(t)}}removePtFromSelection(t){const e=this.selected_pts.indexOf(t);-1!==e&&(this.segs[t].select(!1),this.selected_pts.splice(e,1))}clearSelection(){this.eachSeg((function(){this.select(!1)})),this.selected_pts=[]}storeD(){this.last_d=this.elem.getAttribute("d")}show(t){return this.eachSeg((function(){this.show(t)})),t&&this.selectPt(this.first_seg.index),this}movePts(t,e){let n=this.selected_pts.length;for(;n--;){this.segs[this.selected_pts[n]].move(t,e)}}moveCtrl(t,e){const n=this.segs[this.selected_pts[0]];n.moveCtrl(this.dragctrl,t,e),Yt&&n.setLinked(this.dragctrl)}setSegType(t){this.storeD();let e,n=this.selected_pts.length;for(;n--;){const r=this.selected_pts[n],s=this.segs[r],{prev:i}=s;if(!i)continue;if(!t){e="Toggle Path Segment Type";t=6===s.type?4:6}t=Number(t);const o=s.item.x,a=s.item.y,c=i.item.x,l=i.item.y;let h;switch(t){case 6:if(s.olditem){const t=s.olditem;h=[o,a,t.x1,t.y1,t.x2,t.y2]}else{const t=o-c,e=a-l;h=[o,a,c+t/3,l+e/3,o-t/3,a-e/3]}break;case 4:h=[o,a],s.olditem=s.item}s.setType(t,h)}te.endChanges(e)}selectPt(t,e){this.clearSelection(),Nt(t)&&this.eachSeg((function(e){this.prev&&(t=e)})),this.addPtsToSelection(t),e&&(this.dragctrl=e,Yt&&this.segs[t].setLinked(e))}update(){const{elem:t}=this;return bt(t)?(this.matrix=U(t),this.imatrix=this.matrix.inverse()):(this.matrix=null,this.imatrix=null),this.eachSeg((function(e){this.item=t.pathSegList.getItem(e),this.update()})),this}endChanges(t){b()&&ee.resetD(this.elem);const e=new Dt(this.elem,{d:this.last_d},t);ee.endChanges({cmd:e,elem:this.elem})}addPtsToSelection(t){Array.isArray(t)||(t=[t]),t.forEach(t=>{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;++t){const r=n.getItem(t);let c=r.x||0,l=r.y||0,h=r.x1||0,u=r.y1||0,d=r.x2||0,m=r.y2||0;const g=r.pathSegType;let p=ke[g][e?"toLowerCase":"toUpperCase"]();switch(g){case 1:o+="z",a&&!e&&(s=a[0],i=a[1]);break;case 12:c-=s;case 13:e?(l=0,s+=c,p="l"):(l=i,c+=s,s=c,p="L"),o+=Pe(p,[[c,l]]);break;case 14:l-=i;case 15:e?(c=0,i+=l,p="l"):(c=s,l+=i,i=l,p="L"),o+=Pe(p,[[c,l]]);break;case 2:case 4:case 18:c-=s,l-=i;case 5:case 3:case 19:e?(s+=c,i+=l):(c+=s,l+=i,s=c,i=l),2!==g&&3!==g||(a=[s,i]),o+=Pe(p,[[c,l]]);break;case 6:c-=s,h-=s,d-=s,l-=i,u-=i,m-=i;case 7:e?(s+=c,i+=l):(c+=s,h+=s,d+=s,l+=i,u+=i,m+=i,s=c,i=l),o+=Pe(p,[[h,u],[d,m],[c,l]]);break;case 8:c-=s,h-=s,l-=i,u-=i;case 9:e?(s+=c,i+=l):(c+=s,h+=s,l+=i,u+=i,s=c,i=l),o+=Pe(p,[[h,u],[c,l]]);break;case 10:c-=s,l-=i;case 11:e?(s+=c,i+=l):(c+=s,l+=i,s=c,i=l),o+=Pe(p,[[r.r1,r.r2]],[r.angle,r.largeArcFlag?1:0,r.sweepFlag?1:0],[c,l]);break;case 16:c-=s,d-=s,l-=i,m-=i;case 17:e?(s+=c,i+=l):(c+=s,d+=s,l+=i,m+=i,s=c,i=l),o+=Pe(p,[[d,m],[c,l]])}}return o};function Pe(t,e,n,r){Qt.each(e,(function(t,n){e[t]=Vt(n)}));let s=t+e.join(" ");return n&&(s+=" "+n.join(" ")),r&&(s+=" "+Vt(r)),s}const Te=function(){let t,n,r=!1,s=null,i=!1;return{mouseDown(n,s,i,o){let a,c;if("path"!==ee.getCurrentMode()){if(te){if(te.storeD(),({id:a}=n.target),"pathpointgrip_"===a.substr(0,14)){c=te.cur_pt=Number.parseInt(a.substr(14)),te.dragging=[i,o];const t=te.segs[c];n.shiftKey?t.selected?te.removePtFromSelection(c):te.addPtsToSelection(c):((te.selected_pts.length<=1||!t.selected)&&te.clearSelection(),te.addPtsToSelection(c))}else if(a.startsWith("ctrlpointgrip_")){te.dragging=[i,o];const t=a.split("_")[1].split("c");c=Number(t[0]);const e=Number(t[1]);te.selectPt(c,e)}if(!te.dragging){let t=ee.getRubberBox();Nt(t)&&(t=ee.setRubberBox(ee.selectorManager.getRubberBandBox()));const e=ee.getCurrentZoom();Ct(t,{x:i*e,y:o*e,width:0,height:0,display:"inline"})}}}else{let s=i,c=o;const l=ee.getCurrentZoom();let h=s/l,u=c/l,d=At("path_stretch_line");t=[h,u],ee.getGridSnapping()&&(h=Et(h),u=Et(u),s=Et(s),c=Et(c)),d||(d=document.createElementNS(e.SVG,"path"),Ct(d,{id:"path_stretch_line",stroke:"#22C","stroke-width":"0.5",fill:"none"}),d=At("selectorParentGroup").appendChild(d)),d.setAttribute("display","inline");let m,g=null;const p=ee.getDrawnPath();if(p){const t=p.pathSegList;let e=t.numberOfItems;const s=6/l;let i=!1;for(;e;){e--;const n=t.getItem(e),r=n.x,o=n.y;if(h>=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;e<s;++e){const s=r.getItem(e),i=s.pathSegType;if(1===i)continue;const o=[];Qt.each(["",1,2],(function(t,e){const r=s["x"+e],i=s["y"+e];if(void 0!==r&&void 0!==i){const t=L(r,i,n);o.splice(o.length,0,t.x,t.y)}})),me(i,e,o,t)}Ne(t,n)},zoomChange(){"pathedit"===ee.getCurrentMode()&&te.update()},getNodePoint(){const t=te.selected_pts.length?te.selected_pts[0]:1,e=te.segs[t];return{x:e.item.x,y:e.item.y,type:e.type}},linkControlPoints(t){Jt(t)},clonePathNode(){te.storeD();const t=te.selected_pts;let e=t.length;const n=[];for(;e--;){const r=t[e];te.addSeg(r),n.push(r+e),n.push(r+e+1)}te.init().addPtsToSelection(n),te.endChanges("Clone path node(s)")},opencloseSubPath(){const t=te.selected_pts;if(1!==t.length)return;const{elem:e}=te,n=e.pathSegList,r=t[0];let s=null,i=null;if(te.eachSeg((function(t){return 2===this.type&&t<=r&&(i=this.item),t<=r||(2===this.type?(s=t,!1):1!==this.type||(s=!1,!1))})),Nt(s)&&(s=te.segs.length-1),!1!==s){const t=e.createSVGPathSegLinetoAbs(i.x,i.y),r=e.createSVGPathSegClosePath();return s===te.segs.length-1?(n.appendItem(t),n.appendItem(r)):(re(e,r,s),re(e,t,s)),void te.init().selectPt(s+1)}if(te.segs[r].mate)return n.removeItem(r),n.removeItem(r),void te.init().selectPt(r-1);let o,a;for(let t=0;t<n.numberOfItems;t++){const e=n.getItem(t);if(2===e.pathSegType)o=t;else if(t===r)n.removeItem(o);else if(1===e.pathSegType&&r<t){a=t-1,n.removeItem(t);break}}let c=r-o-1;for(;c--;)re(e,n.getItem(o),a);const l=n.getItem(o);me(2,o,[l.x,l.y]),te.init().selectPt(0)},deletePathNode(){if(!Te.canDeleteNodes)return;te.storeD();const t=te.selected_pts;let e=t.length;for(;e--;){const n=t[e];te.deleteSeg(n)}const n=function(){const t=te.elem.pathSegList;let e=t.numberOfItems;const r=function(e,n){for(;n--;)t.removeItem(e)};if(e<=1)return!0;for(;e--;){const s=t.getItem(e);if(1===s.pathSegType){const s=t.getItem(e-1),i=t.getItem(e-2);if(2===s.pathSegType){r(e-1,2),n();break}if(2===i.pathSegType){r(e-2,3),n();break}}else if(2===s.pathSegType&&e>0){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<r;){const t=n.getItem(e);o.push([t.x,t.y].join(",")),e++}o=o.join(" "),t=ee.addSVGElementFromJson({element:"path",curStyles:!0,attr:{id:ee.getId(),d:o,fill:"none"}})}return t},setSegType(t){te.setSegType(t)},moveNode(t,e){const n=te.selected_pts;if(!n.length)return;te.storeD();const r=te.segs[n[0]],s={x:0,y:0};s[t]=e-r.item[t],r.move(s.x,s.y),te.endChanges("Move path point")},fixEnd(t){const e=t.pathSegList,n=e.numberOfItems;let r;for(let s=0;s<n;++s){const n=e.getItem(s);if(2===n.pathSegType&&(r=n),1===n.pathSegType){const n=e.getItem(s-1);if(n.x!==r.x||n.y!==r.y){const e=t.createSVGPathSegLinetoAbs(r.x,r.y);re(t,e,s),Te.fixEnd(t);break}}}b()&&ee.resetD(t)},convertPath:Ie}}();var Le=Object.freeze({__proto__:null,setUiStrings:Kt,setLinkControlPoints:Jt,get path(){return te},init:ne,insertItemBefore:re,ptObjToArr:se,getGripPt:ie,getPointFromGrip:oe,addPointGrip:ae,getGripContainer:ce,addCtrlGrip:le,getCtrlLine:he,getPointGrip:ue,getControlPoints:de,replacePathSeg:me,getSegSelector:ge,smoothControlPoints:pe,Segment:fe,Path:ye,getPath_:xe,removePath_:Se,recalcRotatedPath:Ee,clearData:Ge,reorientGrads:Ne,convertPath:Ie,pathActions:Te});const Ve=jQuery;class Oe{constructor(t,n,r){if(this.name_=t,this.group_=r?null:n,r){const s=r.ownerDocument;this.group_=s.createElementNS(e.SVG,"g");const i=s.createElementNS(e.SVG,"title");i.textContent=t,this.group_.append(i),n?Ve(n).after(this.group_):r.append(this.group_)}!function(t){const e=t.getAttribute("class");Nt(e)||!e.length?t.setAttribute("class",Oe.CLASS_NAME):Oe.CLASS_REGEX.test(e)||t.setAttribute("class",e+" "+Oe.CLASS_NAME)}
|
|
/**
|
|
* HistoryRecordingService component of history.
|
|
* @module history
|
|
* @license MIT
|
|
* @copyright 2016 Flint O'Brien
|
|
*/(this.group_),rt(this.group_,(function(t){t.setAttribute("style","pointer-events:inherit")})),this.group_.setAttribute("style",r?"pointer-events:all":"pointer-events:none")}getName(){return this.name_}getGroup(){return this.group_}activate(){this.group_.setAttribute("style","pointer-events:all")}deactivate(){this.group_.setAttribute("style","pointer-events:none")}setVisible(t){const e=void 0===t||t?"inline":"none";this.group_.getAttribute("display")!==e&&this.group_.setAttribute("display",e)}isVisible(){return"none"!==this.group_.getAttribute("display")}getOpacity(){const t=this.group_.getAttribute("opacity");return Nt(t)?1:Number.parseFloat(t)}setOpacity(t){"number"==typeof t&&t>=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<t;++e){const t=this.group_.childNodes.item(e);if(t&&"title"===t.tagName)return t}return null}setName(t,e){const n=this.name_;t=Z(t);const r=this.getTitleElement();return r?(Ve(r).empty(),r.textContent=t,this.name_=t,e&&e.changeElement(r,{"#text":n}),this.name_):null}removeGroup(){const t=this.group_;return this.group_.remove(),this.group_=void 0,t}}Oe.CLASS_NAME="layer",Oe.CLASS_REGEX=new RegExp("(\\s|^)"+Oe.CLASS_NAME+"(\\s|$)");class Me{constructor(t){this.undoManager_=t,this.currentBatchCommand_=null,this.batchCommandStack_=[]}startBatchCommand(t){return this.undoManager_?(this.currentBatchCommand_=new zt(t),this.batchCommandStack_.push(this.currentBatchCommand_),this):this}endBatchCommand(){if(!this.undoManager_)return this;if(this.currentBatchCommand_){const t=this.currentBatchCommand_;this.batchCommandStack_.pop();const{length:e}=this.batchCommandStack_;this.currentBatchCommand_=e?this.batchCommandStack_[e-1]:null,this.addCommand_(t)}return this}moveElement(t,e,n,r){return this.undoManager_?(this.addCommand_(new jt(t,e,n,r)),this):this}insertElement(t,e){return this.undoManager_?(this.addCommand_(new Ht(t,e)),this):this}removeElement(t,e,n,r){return this.undoManager_?(this.addCommand_(new Ft(t,e,n,r)),this):this}changeElement(t,e,n){return this.undoManager_?(this.addCommand_(new Dt(t,e,n)),this):this}addCommand_(t){if(!this.undoManager_)return this;this.currentBatchCommand_?this.currentBatchCommand_.addSubCommand(t):this.undoManager_.addCommandToHistory(t)}}Me.NO_HISTORY=new Me;const Re=t(jQuery),Be=function(t,e){const n=document.createElementNS(t.namespaceURI,t.nodeName);if(Re.each(t.attributes,(function(t,e){"-moz-math-font-style"!==e.localName&&n.setAttributeNS(e.namespaceURI,e.nodeName,e.value)})),n.removeAttribute("id"),n.id=e(),b()&&"path"===t.nodeName){const e=Ie(t);n.setAttribute("d",e)}if(Re.each(t.childNodes,(function(t,r){switch(r.nodeType){case 1:n.append(Be(r,e));break;case 3:n.textContent=r.nodeValue}})),Re(t).data("gsvg"))Re(n).data("gsvg",n.firstChild);else if(Re(t).data("symbol")){const e=Re(t).data("symbol");Re(n).data("ref",e).data("symbol",e)}else"image"===n.tagName&&Gt(n);return n},Ue=jQuery,je="a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use".split(","),He=1,Fe=2;let De=0,ze=[];function qe(t){return t||new Me(Ze.undoMgr)}function Qe(t){return Ue("title",t).text()||(o&&t.querySelectorAll?Ue(t.querySelectorAll("title")).text():"")}function We(t){let e=1;for(;t.includes("Layer "+e);)e++;return"Layer "+e}class Xe{constructor(t,n){if(!t||!t.tagName||!t.namespaceURI||"svg"!==t.tagName||t.namespaceURI!==e.SVG)throw new Error("Error: svgedit.draw.Drawing instance initialized without a <svg> 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<this.getNumLayers()?this.all_layers[t].getName():""}getCurrentLayer(){return this.current_layer?this.current_layer.getGroup():null}getLayerByName(t){const e=this.layer_map[t];return e?e.getGroup():null}getCurrentLayerName(){return this.current_layer?this.current_layer.getName():""}setCurrentLayerName(t,e){let n=null;if(this.current_layer){const r=this.current_layer.getName();n=this.current_layer.setName(t,e),n&&(delete this.layer_map[r],this.layer_map[n]=this.current_layer)}return n}setCurrentLayerPosition(t){const e=this.getNumLayers();if(!this.current_layer||t<0||t>=e)return null;let n;for(n=0;n<e&&this.all_layers[n]!==this.current_layer;++n);if(n===e)return null;if(n!==t){const r=this.current_layer.getGroup(),s=r.nextSibling;let i=null;return t>n?t<e-1&&(i=this.all_layers[t+1].getGroup()):i=this.all_layers[t].getGroup(),this.svgElem_.insertBefore(r,i),this.identifyLayers(),this.setCurrentLayer(this.getLayerName(t)),{currentGroup:r,oldNextSibling:s}}return null}mergeLayer(t){const e=this.current_layer.getGroup(),n=Ue(e).prev()[0];if(!n)return;t.startBatchCommand("Merge Layer");const r=e.nextSibling;for(t.removeElement(e,r,this.svgElem_);e.firstChild;){const r=e.firstChild;if("title"===r.localName){t.removeElement(r,r.nextSibling,e),r.remove();continue}const s=r.nextSibling;n.append(r),t.moveElement(r,s,e)}this.current_layer.removeGroup();const s=this.all_layers.indexOf(this.current_layer);if(s>0){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;i<t;++i){const t=this.svgElem_.childNodes.item(i);if(t&&1===t.nodeType)if("g"===t.tagName){s=!0;const i=Qe(t);i?(n.push(i),r=new Oe(i,t),this.all_layers.push(r),this.layer_map[i]=r):e.push(t)}else je.includes(t.nodeName)&&e.push(t)}e.length>0||!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;e++){const t=ze[e],n=Ze.elData(t,"orig_opac");1!==n?t.setAttribute("opacity",n):t.removeAttribute("opacity"),t.setAttribute("style","pointer-events: inherit")}ze=[],Ze.clearSelection(!0),Ze.call("contextset",null)}Ze.setCurrentGroup(null)},hn=function(t){ln(),"string"==typeof t&&(t=At(t)),Ze.setCurrentGroup(t),Ue(t).parentsUntil("#svgcontent").andSelf().siblings().each((function(){const t=this.getAttribute("opacity")||1;Ze.elData(this,"orig_opac",t),this.setAttribute("opacity",.33*t),this.setAttribute("style","pointer-events: none"),ze.push(this)})),Ze.clearSelection(),Ze.call("contextset",Ze.getCurrentGroup())},un=n(),dn={a:["class","clip-path","clip-rule","fill","fill-opacity","fill-rule","filter","id","mask","opacity","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","systemLanguage","transform","xlink:href","xlink:title"],circle:["class","clip-path","clip-rule","cx","cy","fill","fill-opacity","fill-rule","filter","id","mask","opacity","r","requiredFeatures","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","systemLanguage","transform"],clipPath:["class","clipPathUnits","id"],defs:[],style:["type"],desc:[],ellipse:["class","clip-path","clip-rule","cx","cy","fill","fill-opacity","fill-rule","filter","id","mask","opacity","requiredFeatures","rx","ry","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","systemLanguage","transform"],feGaussianBlur:["class","color-interpolation-filters","id","requiredFeatures","stdDeviation"],feMorphology:["class","in","operator","radius"],filter:["class","color-interpolation-filters","filterRes","filterUnits","height","id","primitiveUnits","requiredFeatures","width","x","xlink:href","y"],foreignObject:["class","font-size","height","id","opacity","requiredFeatures","style","transform","width","x","y"],g:["class","clip-path","clip-rule","id","display","fill","fill-opacity","fill-rule","filter","mask","opacity","requiredFeatures","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","systemLanguage","transform","font-family","font-size","font-style","font-weight","text-anchor"],image:["class","clip-path","clip-rule","filter","height","id","mask","opacity","requiredFeatures","style","systemLanguage","transform","width","x","xlink:href","xlink:title","y"],line:["class","clip-path","clip-rule","fill","fill-opacity","fill-rule","filter","id","marker-end","marker-mid","marker-start","mask","opacity","requiredFeatures","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","systemLanguage","transform","x1","x2","y1","y2"],linearGradient:["class","id","gradientTransform","gradientUnits","requiredFeatures","spreadMethod","systemLanguage","x1","x2","xlink:href","y1","y2"],marker:["id","class","markerHeight","markerUnits","markerWidth","orient","preserveAspectRatio","refX","refY","systemLanguage","viewBox"],mask:["class","height","id","maskContentUnits","maskUnits","width","x","y"],metadata:["class","id"],path:["class","clip-path","clip-rule","d","fill","fill-opacity","fill-rule","filter","id","marker-end","marker-mid","marker-start","mask","opacity","requiredFeatures","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","systemLanguage","transform"],pattern:["class","height","id","patternContentUnits","patternTransform","patternUnits","requiredFeatures","style","systemLanguage","viewBox","width","x","xlink:href","y"],polygon:["class","clip-path","clip-rule","id","fill","fill-opacity","fill-rule","filter","id","class","marker-end","marker-mid","marker-start","mask","opacity","points","requiredFeatures","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","systemLanguage","transform"],polyline:["class","clip-path","clip-rule","id","fill","fill-opacity","fill-rule","filter","marker-end","marker-mid","marker-start","mask","opacity","points","requiredFeatures","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","systemLanguage","transform"],radialGradient:["class","cx","cy","fx","fy","gradientTransform","gradientUnits","id","r","requiredFeatures","spreadMethod","systemLanguage","xlink:href"],rect:["class","clip-path","clip-rule","fill","fill-opacity","fill-rule","filter","height","id","mask","opacity","requiredFeatures","rx","ry","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","systemLanguage","transform","width","x","y"],stop:["class","id","offset","requiredFeatures","stop-color","stop-opacity","style","systemLanguage"],svg:["class","clip-path","clip-rule","filter","id","height","mask","preserveAspectRatio","requiredFeatures","style","systemLanguage","viewBox","width","x","xmlns","xmlns:se","xmlns:xlink","y"],switch:["class","id","requiredFeatures","systemLanguage"],symbol:["class","fill","fill-opacity","fill-rule","filter","font-family","font-size","font-style","font-weight","id","opacity","preserveAspectRatio","requiredFeatures","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","systemLanguage","transform","viewBox"],text:["class","clip-path","clip-rule","fill","fill-opacity","fill-rule","filter","font-family","font-size","font-style","font-weight","id","mask","opacity","requiredFeatures","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","systemLanguage","text-anchor","transform","x","xml:space","y"],textPath:["class","id","method","requiredFeatures","spacing","startOffset","style","systemLanguage","transform","xlink:href"],title:[],tspan:["class","clip-path","clip-rule","dx","dy","fill","fill-opacity","fill-rule","filter","font-family","font-size","font-style","font-weight","id","mask","opacity","requiredFeatures","rotate","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","systemLanguage","text-anchor","textLength","transform","x","xml:space","y"],use:["class","clip-path","clip-rule","fill","fill-opacity","fill-rule","filter","height","id","mask","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","transform","width","x","xlink:href","y"],annotation:["encoding"],"annotation-xml":["encoding"],maction:["actiontype","other","selection"],math:["class","id","display","xmlns"],menclose:["notation"],merror:[],mfrac:["linethickness"],mi:["mathvariant"],mmultiscripts:[],mn:[],mo:["fence","lspace","maxsize","minsize","rspace","stretchy"],mover:[],mpadded:["lspace","width","height","depth","voffset"],mphantom:[],mprescripts:[],mroot:[],mrow:["xlink:href","xlink:type","xmlns:xlink"],mspace:["depth","height","width"],msqrt:[],mstyle:["displaystyle","mathbackground","mathcolor","mathvariant","scriptlevel"],msub:[],msubsup:[],msup:[],mtable:["align","columnalign","columnlines","columnspacing","displaystyle","equalcolumns","equalrows","frame","rowalign","rowlines","rowspacing","width"],mtd:["columnalign","columnspan","rowalign","rowspan"],mtext:[],mtr:["columnalign","rowalign"],munder:[],munderover:[],none:[],semantics:[]},mn={};Object.entries(dn).forEach((function([t,n]){const r={};Object.entries(n).forEach((function([t,n]){if(n.includes(":")){const t=n.split(":");r[t[1]]=e[t[0].toUpperCase()]}else r[n]="xmlns"===n?e.XMLNS:null})),mn[t]=r}));const gn=function(t){if(3===t.nodeType&&(t.nodeValue=t.nodeValue.replace(/^\s+|\s+$/g,""),t.nodeValue.length||t.remove()),1!==t.nodeType)return;const n=t.ownerDocument,r=t.parentNode;if(!n||!r)return;const s=dn[t.nodeName],i=mn[t.nodeName];if(void 0!==s){const n=[];let r=t.attributes.length;for(;r--;){const o=t.attributes.item(r),a=o.nodeName,c=o.localName,l=o.namespaceURI;if({}.hasOwnProperty.call(i,c)&&l===i[c]&&l!==e.XMLNS||l===e.XMLNS&&un[o.value]||((a.startsWith("se:")||a.startsWith("data-"))&&n.push([a,o.value]),t.removeAttributeNS(l,c)),w())switch(a){case"transform":case"gradientTransform":case"patternTransform":{const e=o.value.replace(/(\d)-/g,"$1 -");t.setAttribute(a,e);break}}if("style"===a){const e=o.value.split(";");let n=e.length;for(;n--;){const[r,i]=e[n].split(":"),o=(r||"").trim(),a=(i||"").trim();s.includes(o)&&t.setAttribute(o,a)}t.removeAttribute("style")}}Object.values(n).forEach(([n,r])=>{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;t<n;++t){const n=e.points[t],{x:s,y:i}=r(n.x,n.y);e.points[t].x=s,e.points[t].y=i}let s="";for(let t=0;t<n;++t){const n=e.points[t];s+=n.x+","+n.y+" "}t.setAttribute("points",s);break}case"path":{const n=t.pathSegList;let o=n.numberOfItems;e.d=[];for(let t=0;t<o;++t){const r=n.getItem(t);e.d[t]={type:r.pathSegType,x:r.x,y:r.y,x1:r.x1,y1:r.y1,x2:r.x2,y2:r.y2,r1:r.r1,r2:r.r2,angle:r.angle,largeArcFlag:r.largeArcFlag,sweepFlag:r.sweepFlag}}o=e.d.length;const a=e.d[0],c=r(a.x,a.y);e.d[0].x=c.x,e.d[0].y=c.y;for(let t=1;t<o;++t){const n=e.d[t],{type:o}=n;if(o%2==0){const t=r(void 0!==n.x?n.x:c.x,void 0!==n.y?n.y:c.y),e=r(n.x1,n.y1),o=r(n.x2,n.y2);n.x=t.x,n.y=t.y,n.x1=e.x,n.y1=e.y,n.x2=o.x,n.y2=o.y,n.r1=s(n.r1),n.r2=i(n.r2)}else n.x=s(n.x),n.y=i(n.y),n.x1=s(n.x1),n.y1=i(n.y1),n.x2=s(n.x2),n.y2=i(n.y2),n.r1=s(n.r1),n.r2=i(n.r2)}let l="";o=e.d.length;for(let t=0;t<o;++t){const n=e.d[t],{type:r}=n;switch(l+=Sn[r],r){case 13:case 12:l+=n.x+" ";break;case 15:case 14:l+=n.y+" ";break;case 3:case 5:case 19:case 2:case 4:case 18:l+=n.x+","+n.y+" ";break;case 7:case 6:l+=n.x1+","+n.y1+" "+n.x2+","+n.y2+" "+n.x+","+n.y+" ";break;case 9:case 8:l+=n.x1+","+n.y1+" "+n.x+","+n.y+" ";break;case 11:case 10:l+=n.r1+","+n.r2+" "+n.angle+" "+Number(n.largeArcFlag)+" "+Number(n.sweepFlag)+" "+n.x+","+n.y+" ";break;case 17:case 16:l+=n.x2+","+n.y2+" "+n.x+","+n.y+" "}}t.setAttribute("d",l);break}}},wn=t(jQuery);let An;const Cn=function(t,e,n){const r=wt(t).firstChild,s=P(r),i=An.getSVGRoot().createSVGTransform();i.setTranslate(e,n),s.appendItem(i),vn(r)},vn=function(t){if(Nt(t))return null;if("svg"===t.nodeName&&navigator.userAgent.includes("Firefox/20"))return null;const n=An.getSVGRoot(),r=P(t);if(r&&r.numberOfItems>0){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;t<n;++t){const n=e.getItem(t);c.points[t]={x:n.x,y:n.y}}break}case"path":l={},l.d=t.getAttribute("d"),c.d=t.getAttribute("d")}if(h.length?(c=wn(t).attr(h),wn.each(c,(function(t,e){c[t]=Rt(t,e)}))):s&&(c={x:wn(s).attr("x")||0,y:wn(s).attr("y")||0}),Nt(l)&&(l=wn.extend(!0,{},c),wn.each(l,(function(t,e){l[t]=Rt(t,e)}))),l.transform=An.getStartTransform()||"","g"===t.tagName&&!s||"a"===t.tagName){const s=ht(t);o={x:s.x+s.width/2,y:s.y+s.height/2},a=L(s.x+s.width/2,s.y+s.height/2,B(r).matrix);const c=bt(t);if(c){const t=c*Math.PI/180;let e;e=Math.abs(t)>1e-10?Math.sin(t)/(1-Math.cos(t)):2/t;for(let t=0;t<r.numberOfItems;++t){const n=r.getItem(t);if(4===n.type){const s=n.matrix;o.y=(e*s.e+s.f)/2,o.x=(s.e-e*s.f)/2,r.removeItem(t);break}}}const l=r.numberOfItems;let h,u,d=0,m=0,g=0;if(l&&(h=r.getItem(0).matrix),l>=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<r.numberOfItems;++t){const e=r.getItem(t);if(4===e.type){const s=e.matrix;o.y=(n*s.e+s.f)/2,o.x=(s.e-n*s.f)/2,r.removeItem(t);break}}}let l=0;const h=r.numberOfItems;if(!b()){const e=t.getAttribute("fill");if(e&&e.startsWith("url(")){const t=wt(e);let n="pattern";t.tagName!==n&&(n="gradient");if("userSpaceOnUse"===t.getAttribute(n+"Units")){s=B(r).matrix;const e=P(t),i=B(e).matrix;s=O(s,i);const o="matrix("+[s.a,s.b,s.c,s.d,s.e,s.f].join(",")+")";t.setAttribute(n+"Transform",o)}}}if(h>=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<n;++t){const n=e.getItem(t);c.points[t]={x:n.x,y:n.y}}}case"path":c.d=t.getAttribute("d"),l=1,r.clear()}}if(1!==l&&2!==l&&3!==l||bn(t,c,s),2===l){if(i){M(r)||(a={x:o.x+s.e,y:o.y+s.f});const t=n.createSVGTransform();t.setRotate(i,a.x,a.y),r.numberOfItems?r.insertItemBefore(t,0):r.appendItem(t)}if("text"===t.tagName){const e=t.childNodes;let n=e.length;for(;n--;){const t=e.item(n);if("tspan"===t.tagName){const e={x:wn(t).attr("x")||0,y:wn(t).attr("y")||0};bn(t,e,s)}}}}else if(3===l&&i){const{matrix:e}=B(r),s=n.createSVGTransform();s.setRotate(i,o.x,o.y);const l=s.matrix,h=n.createSVGTransform();h.setRotate(i,a.x,a.y);const u=h.matrix.inverse(),d=e.inverse(),m=O(d,u,l,e);bn(t,c,m),i&&(r.numberOfItems?r.insertItemBefore(h,0):r.appendItem(h))}}return 0===r.numberOfItems&&t.removeAttribute("transform"),i.addSubCommand(new Dt(t,l)),i},En=jQuery;let Gn,Nn,kn;const In=u?10:4;class Pn{constructor(t,e,n){this.id=t,this.selectedElement=e,this.locked=!0,this.selectorGroup=Gn.createSVGElement({element:"g",attr:{id:"selectorGroup"+this.id}}),this.selectorRect=this.selectorGroup.appendChild(Gn.createSVGElement({element:"path",attr:{id:"selectedBox"+this.id,fill:"none",stroke:"#22C","stroke-width":"1","stroke-dasharray":"5,5",style:"pointer-events:none"}})),this.gripCoords={nw:null,n:null,ne:null,e:null,se:null,s:null,sw:null,w:null},this.reset(this.selectedElement,n)}reset(t,e){this.locked=!0,this.selectedElement=t,this.resize(e),this.selectorGroup.setAttribute("display","inline")}showGrips(t){const e=t?"inline":"none";kn.selectorGripsGroup.setAttribute("display",e);const n=this.selectedElement;this.hasGrips=t,n&&t&&(this.selectorGroup.append(kn.selectorGripsGroup),Pn.updateGripCursors(bt(n)))}resize(t){const e=this.selectorRect,n=kn,r=n.selectorGrips,s=this.selectedElement,i=s.getAttribute("stroke-width"),o=Gn.getCurrentZoom();let a=1/o;"none"===s.getAttribute("stroke")||isNaN(i)||(a+=i/2);const{tagName:c}=s;"text"===c&&(a+=2/o);const l=P(s),h=B(l).matrix;if(h.e*=o,h.f*=o,t||(t=ht(s)),"g"===c&&!En.data(s,"gsvg")){const e=yt([s.childNodes]);e&&(t=e)}const u=t.x,d=t.y,m=t.width,g=t.height;a*=o;const p=R(u*o,d*o,m*o,g*o,h),{aabox:f}=p;let y=f.x-a,x=f.y-a,S=f.width+2*a,_=f.height+2*a;const b=y+S/2,w=x+_/2,A=bt(s);if(A){const t=Gn.svgRoot().createSVGTransform();t.setRotate(-A,b,w);const e=t.matrix;p.tl=L(p.tl.x,p.tl.y,e),p.tr=L(p.tr.x,p.tr.y,e),p.bl=L(p.bl.x,p.bl.y,e),p.br=L(p.br.x,p.br.y,e);const{tl:n}=p;let r=n.x,s=n.y,i=n.x,o=n.y;const{min:c,max:l}=Math;r=c(r,c(p.tr.x,c(p.bl.x,p.br.x)))-a,s=c(s,c(p.tr.y,c(p.bl.y,p.br.y)))-a,i=l(i,l(p.tr.x,l(p.bl.x,p.br.x)))+a,o=l(o,l(p.tr.y,l(p.bl.y,p.br.y)))+a,y=r,x=s,S=i-r,_=o-s}const C="M"+y+","+x+" L"+(y+S)+","+x+" "+(y+S)+","+(x+_)+" "+y+","+(x+_)+"z";e.setAttribute("d",C);const v=A?"rotate("+[A,b,w].join(",")+")":"";this.selectorGroup.setAttribute("transform",v),this.gripCoords={nw:[y,x],ne:[y+S,x],sw:[y,x+_],se:[y+S,x+_],n:[y+S/2,x],w:[y,x+_/2],e:[y+S,x+_/2],s:[y+S/2,x+_]},Object.entries(this.gripCoords).forEach(([t,e])=>{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<n;++r)if(this.selectors[r]&&!this.selectors[r].locked)return this.selectors[r].locked=!0,this.selectors[r].reset(t,e),this.selectorMap[t.id]=this.selectors[r],this.selectors[r];return this.selectors[n]=new Pn(n,t,e),this.selectorParentGroup.append(this.selectors[n].selectorGroup),this.selectorMap[t.id]=this.selectors[n],this.selectors[n]}releaseSelector(t){if(Nt(t))return;const e=this.selectors.length,n=this.selectorMap[t.id];n.locked||console.log("WARNING! selector was released but was already unlocked");for(let r=0;r<e;++r)if(this.selectors[r]&&this.selectors[r]===n){delete this.selectorMap[t.id],n.locked=!1,n.selectedElement=null,n.showGrips(!1);try{n.selectorGroup.setAttribute("display","none")}catch(t){}break}}getRubberBandBox(){return this.rubberBandBox||(this.rubberBandBox=this.selectorParentGroup.appendChild(Gn.createSVGElement({element:"rect",attr:{id:"selectorRubberBand",fill:"#22C","fill-opacity":.15,stroke:"#22C","stroke-width":.5,display:"none",style:"pointer-events:none"}}))),this.rubberBandBox}}let Ln=t(jQuery);const{MoveElementCommand:Vn,InsertElementCommand:On,RemoveElementCommand:Mn,ChangeElementCommand:Rn,BatchCommand:Bn,UndoManager:Un,HistoryEventTypes:jn}=qt;window.console||(window.console={},window.console.log=function(t){},window.console.dir=function(t){}),window.opera&&(window.console.log=function(t){window.opera.postError(t)},window.console.dir=function(t){});return class{constructor(t,r){const s={show_outside_canvas:!0,selectNew:!0,dimensions:[640,480]};r&&Ln.extend(s,r);const{dimensions:i}=s,o=this,a=t.ownerDocument,c=a.importNode(nt('<svg id="svgroot" xmlns="'+e.SVG+'" xlinkns="'+e.XLINK+'" width="'+i[0]+'" height="'+i[1]+'" x="'+i[0]+'" y="'+i[1]+'" overflow="visible"><defs><filter id="canvashadow" filterUnits="objectBoundingBox"><feGaussianBlur in="SourceAlpha" stdDeviation="4" result="blur"/><feOffset in="blur" dx="5" dy="5" result="offsetBlur"/><feMerge><feMergeNode in="offsetBlur"/><feMergeNode in="SourceGraphic"/></feMerge></filter></defs></svg>').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(;n<y.length&&!Nt(y[n]);)++n;let r=t.length;for(;r--;){let e=t[r];if(!e)continue;const s=ht(e);if(s&&("a"===e.tagName&&1===e.childNodes.length&&(e=e.firstChild),!y.includes(e))){y[n]=e,n++;const t=ft.requestSelector(e,s);y.length>1&&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;t<e;t++)Qt(n[t])},Wt={},Xt={round_digits:5},Zt={},Yt=g.text,$t={},Jt={};let te=s.imgPath+"logo.png",ee=!1,re=null,se="select",ie="none",oe=p,ae=null,ce=null,le=[],he=null;this.runExtension=function(t,e,n){return this.runExtensions(e,n,!1,e=>e===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;r<n;++r){const n=y[r];n&&(t.includes(n)?ft.releaseSelector(n):e.push(n))}y=e},this.selectAllInCurrentLayer=function(){const t=u().getCurrentLayer();t&&(se="select",be(Ln(m||t).children()))};let we=null;!function(){const e={minx:null,miny:null,maxx:null,maxy:null};let n,r,i=null,a=null,h=null,g=null,f=null,x={},_=0,w={x:0,y:0},A={x:0,y:0},C={x:0,y:0},E={x:0,y:0},G={x:0,y:0},N={x:0,y:0};const k=function(t){const e={x:0,y:0},n=w,r=A,s=C,i=E,o=t*t,a=o*t,c=[[-1,3,-3,1],[3,-6,3,0],[-3,0,3,0],[1,4,1,0]];return e.x=1/6*((n.x*c[0][0]+r.x*c[0][1]+s.x*c[0][2]+i.x*c[0][3])*a+(n.x*c[1][0]+r.x*c[1][1]+s.x*c[1][2]+i.x*c[1][3])*o+(n.x*c[2][0]+r.x*c[2][1]+s.x*c[2][2]+i.x*c[2][3])*t+(n.x*c[3][0]+r.x*c[3][1]+s.x*c[3][2]+i.x*c[3][3])),e.y=1/6*((n.y*c[0][0]+r.y*c[0][1]+s.y*c[0][2]+i.y*c[0][3])*a+(n.y*c[1][0]+r.y*c[1][1]+s.y*c[1][2]+i.y*c[1][3])*o+(n.y*c[2][0]+r.y*c[2][1]+s.y*c[2][2]+i.y*c[2][3])*t+(n.y*c[3][0]+r.y*c[3][1]+s.y*c[3][2]+i.y*c[3][3])),{x:e.x,y:e.y}};Ln(t).mousedown((function(t){if(o.spaceKey||1===t.button)return;const n=2===t.button;t.altKey&&o.cloneSelectedElements(0,0),_e=Ln("#svgcontent g")[0].getScreenCTM().inverse();const r=L(t.pageX,t.pageY,_e),l=r.x*d,u=r.y*d;t.preventDefault(),n&&(se="select",he=r);let m=l/d,_=u/d,E=Ut(t);"a"===E.tagName&&1===E.childNodes.length&&(E=E.firstChild);const G=m;g=a=m;const N=_;if(f=h=_,s.gridSnapping&&(m=Et(m),_=Et(_),a=Et(a),h=Et(h)),E===ft.selectorParentGroup&&!Nt(y[0])){const e=t.target,n=Dt(e,"type");"rotate"===n?se="rotate":"resize"===n&&(se="resize",ie=Dt(e,"dir")),E=y[0]}re=E.getAttribute("transform");const k=P(E);switch(se){case"select":if(ee=!0,ie="none",n&&(ee=!1),E!==c){if(y.includes(E)||(t.shiftKey||It(!0),Mt([E]),ae=E,I.clear()),!n)for(const t of y){if(Nt(t))continue;const e=P(t);e.numberOfItems?e.insertItemBefore(c.createSVGTransform(),0):e.appendItem(c.createSVGTransform())}}else n||(It(),se="multiselect",Nt(ce)&&(ce=ft.getRubberBandBox()),g*=d,f*=d,Ct(ce,{x:g,y:f,width:0,height:0,display:"inline"}));break;case"zoom":ee=!0,Nt(ce)&&(ce=ft.getRubberBandBox()),Ct(ce,{x:G*d,y:G*d,width:0,height:0,display:"inline"});break;case"resize":{ee=!0,a=m,h=_,x=ht(Ln("#selectedBox0")[0]);const t={};Ln.each(x,(function(e,n){t[e]=n/d})),x=t;const e=bt(E)?1:0;if(M(k))k.insertItemBefore(c.createSVGTransform(),e),k.insertItemBefore(c.createSVGTransform(),e),k.insertItemBefore(c.createSVGTransform(),e);else if(k.appendItem(c.createSVGTransform()),k.appendItem(c.createSVGTransform()),k.appendItem(c.createSVGTransform()),v()){const t=b();let e;t&&(e=function(t){const e=t.getAttribute("stroke");t.removeAttribute("stroke"),null!==e&&setTimeout((function(){t.setAttribute("stroke",e)}),0)}),E.style.vectorEffect="non-scaling-stroke",t&&e(E);const n=E.getElementsByTagName("*"),r=n.length;for(let s=0;s<r;s++)n[s].style&&(n[s].style.vectorEffect="non-scaling-stroke",t&&e(n[s]))}break}case"fhellipse":case"fhrect":case"fhpath":C.x=G,C.y=N,A={x:0,y:0},w={x:0,y:0},ee=!0,i=G+","+N+" ",S({element:"polyline",curStyles:!0,attr:{points:i,id:yt(),fill:"none",opacity:p.opacity/2,"stroke-linecap":"round",style:"pointer-events:none"}}),e.minx=G,e.maxx=G,e.miny=N,e.maxy=N;break;case"image":{ee=!0;const t=S({element:"image",attr:{x:m,y:_,width:0,height:0,id:yt(),opacity:p.opacity/2,style:"pointer-events:inherit"}});ot(t,te),Gt(t);break}case"square":case"rect":ee=!0,a=m,h=_,S({element:"rect",curStyles:!0,attr:{x:m,y:_,width:0,height:0,id:yt(),opacity:p.opacity/2}});break;case"line":{ee=!0;const t=0===Number(p.stroke_width)?1:p.stroke_width;S({element:"line",curStyles:!0,attr:{x1:m,y1:_,x2:m,y2:_,id:yt(),stroke:p.stroke,"stroke-width":t,"stroke-dasharray":p.stroke_dasharray,"stroke-linejoin":p.stroke_linejoin,"stroke-linecap":p.stroke_linecap,"stroke-opacity":p.stroke_opacity,fill:"none",opacity:p.opacity/2,style:"pointer-events:none"}});break}case"circle":ee=!0,S({element:"circle",curStyles:!0,attr:{cx:m,cy:_,r:0,id:yt(),opacity:p.opacity/2}});break;case"ellipse":ee=!0,S({element:"ellipse",curStyles:!0,attr:{cx:m,cy:_,rx:0,ry:0,id:yt(),opacity:p.opacity/2}});break;case"text":ee=!0,S({element:"text",curStyles:!0,attr:{x:m,y:_,id:yt(),fill:Yt.fill,"stroke-width":Yt.stroke_width,"font-size":Yt.font_size,"font-family":Yt.font_family,"text-anchor":"middle","xml:space":"preserve",opacity:p.opacity}});break;case"path":case"pathedit":a*=d,h*=d,I.mouseDown(t,E,a,h),ee=!0;break;case"textedit":a*=d,h*=d,Ae.mouseDown(t,E,a,h),ee=!0;break;case"rotate":ee=!0,o.undoMgr.beginUndoableChange("transform",y)}const T=ue("mouseDown",{event:t,start_x:a,start_y:h,selectedElements:y},!0);Ln.each(T,(function(t,e){e&&e.started&&(ee=!0)}))})).mousemove((function(t){if(!ee)return;if(1===t.button||o.spaceKey)return;let i,u,m,p,S,b,v,T,V,O,R=y[0];const B=L(t.pageX,t.pageY,_e),H=B.x*d,F=B.y*d,D=At(_t());let z,q=H/d,Q=q,W=F/d,X=W;switch(s.gridSnapping&&(Q=Et(Q),X=Et(X)),t.preventDefault(),se){case"select":if(null!==y[0]&&(b=Q-a,v=X-h,s.gridSnapping&&(b=Et(b),v=Et(v)),0!==b||0!==v)){for(T=y.length,i=0;i<T&&(R=y[i],!Nt(R));++i){const t=c.createSVGTransform();z=P(R),t.setTranslate(b,v),z.numberOfItems?z.replaceItem(t,0):z.appendItem(t),ft.requestSelector(R).resize()}kt("transition",y)}break;case"multiselect":{q*=d,W*=d,Ct(ce,{x:Math.min(g,q),y:Math.min(f,W),width:Math.abs(q-g),height:Math.abs(W-f)});const t=y.slice(),e=[],n=de();for(T=n.length,i=0;i<T;++i){const r=n[i];y.includes(r)||e.push(r);const s=t.indexOf(r);-1!==s&&t.splice(s,1)}t.length>0&&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<Q?a:a-i,r=h<X?h:h-o):(n=Math.min(a,Q),r=Math.min(h,X)),s.gridSnapping&&(i=Et(i),o=Et(o),n=Et(n),r=Et(r)),Ct(D,{width:i,height:o,x:n,y:r});break}case"circle":{m=Ln(D).attr(["cx","cy"]),({cx:p,cy:S}=m);let t=Math.sqrt((Q-p)*(Q-p)+(X-S)*(X-S));s.gridSnapping&&(t=Et(t)),D.setAttribute("r",t);break}case"ellipse":{m=Ln(D).attr(["cx","cy"]),({cx:p,cy:S}=m),s.gridSnapping&&(Q=Et(Q),p=Et(p),X=Et(X),S=Et(S)),D.setAttribute("rx",Math.abs(Q-p));const e=Math.abs(t.shiftKey?Q-p:X-S);D.setAttribute("ry",e);break}case"fhellipse":case"fhrect":e.minx=Math.min(q,e.minx),e.maxx=Math.max(q,e.maxx),e.miny=Math.min(W,e.miny),e.maxy=Math.max(W,e.maxy);case"fhpath":if(E.x=q,E.y=W,w.x&&w.y)for(i=0;i<9;i++)if(n=i/10,r=(i+1)/10,G=k(r),N=G,G=k(n),_+=Math.sqrt((N.x-G.x)*(N.x-G.x)+(N.y-G.y)*(N.y-G.y)),_>.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<t&&!Nt(y[e]);++e)y[e].firstChild||ft.requestSelector(y[e]).resize()}else N=t.target,"path"===y[0].nodeName&&Nt(y[1])?I.select(y[0]):t.shiftKey&&n!==N&&o.removeFromSelection([N]);if(v()){const t=y[0];t&&(t.removeAttribute("style"),rt(t,(function(t){t.removeAttribute("style")})))}}return;case"zoom":{Nt(ce)||ce.setAttribute("display","none");const e=t.shiftKey?.5:2;return void kt("zoomed",{x:Math.min(g,x),y:Math.min(f,b),width:Math.abs(x-g),height:Math.abs(b-f),factor:e})}case"fhpath":{_=0,w={x:0,y:0},A={x:0,y:0},C={x:0,y:0},E={x:0,y:0};const t=h.getAttribute("points"),e=t.indexOf(",");m=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&&n<h+2&&n>h-2&&r<u+2&&r>u-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<i;r++){const e=t.getStartPositionOfChar(r);if(s=t.getEndPositionOfChar(r),!f){const t=o.contentW*d;e.x-=t,s.x-=t,e.x/=d,s.x/=d}g[r]={x:e.x,y:a.y,width:s.x-e.x,height:a.height}}g.push({x:s.x,width:0}),x(n.selectionStart,n.selectionEnd,!0)}}}(),Ce=this.removeUnusedDefElems=function(){const t=l.getElementsByTagNameNS(e.SVG,"defs");if(!t||!t.length)return 0;const n=[];let r=0;const s=["fill","stroke","filter","marker-start","marker-mid","marker-end"],i=s.length,o=l.getElementsByTagNameNS(e.SVG,"*"),a=o.length;let c,h;for(c=0;c<a;c++){const t=o[c];for(h=0;h<i;h++){const e=st(t.getAttribute(s[h]));e&&n.push(e.substr(1))}const e=it(t);e&&e.startsWith("#")&&n.push(e.substr(1))}const u=Ln(t).find("linearGradient, radialGradient, filter, marker, svg, symbol");for(c=u.length;c--;){const t=u[c],{id:e}=t;n.includes(e)||(Jt[e]=t,t.remove(),r++)}return r};function ve(){It();const t=[],e=[],n={feGaussianBlur:jt.exportNoBlur,foreignObject:jt.exportNoforeignObject,"[stroke-dasharray]":jt.exportNoDashArray},r=Ln(l);return"font"in Ln("<canvas>")[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;t<n;t++)"id"!==e[t].nodeName&&"style"!==e[t].nodeName||n--;if(n<=0){const e=this.firstChild;t.push(e),Ln(this).replaceWith(e)}}));const e=this.svgToString(l,0);return t.length&&Ln(t).each((function(){ge(this)})),e},this.svgToString=function(t,n){const r=[],i=s.baseUnit,o=new RegExp("^-?[\\d\\.]+"+i+"$");if(t){vt(t);const s=[...t.attributes],a=t.childNodes;s.sort((t,e)=>t.name>e.name?-1:1);for(let t=0;t<n;t++)r.push(" ");if(r.push("<"),r.push(t.nodeName),"svgcontent"===t.id){const n=Ve(),o="";"px"!==i&&(n.w=Ot(n.w,i)+i,n.h=Ot(n.h,i)+i),r.push(' width="'+n.w+'" height="'+n.h+'"'+o+' xmlns="'+e.SVG+'"');const a={};Ln(t).find("*").andSelf().each((function(){const t=this.namespaceURI;t&&!a[t]&&J[t]&&"xmlns"!==J[t]&&"xml"!==J[t]&&(a[t]=!0,r.push(" xmlns:"+J[t]+'="'+t+'"')),Ln.each(this.attributes,(function(t,e){const n=e.namespaceURI;n&&!a[n]&&"xmlns"!==J[n]&&"xml"!==J[n]&&(a[n]=!0,r.push(" xmlns:"+J[n]+'="'+n+'"'))}))}));let c=s.length;const l=["width","height","xmlns","x","y","viewBox","id","overflow"];for(;c--;){const t=s[c],e=Z(t.value);t.nodeName.startsWith("xmlns:")||(""===e||l.includes(t.localName)||t.namespaceURI&&!J[t.namespaceURI]||(r.push(" "),r.push(t.nodeName),r.push('="'),r.push(e),r.push('"')))}}else{if("defs"===t.nodeName&&!t.firstChild)return"";const n=["-moz-math-font-style","_moz-math-font-style"];for(let a=s.length-1;a>=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<a.length;t++){const s=a.item(t);switch(s.nodeType){case 1:r.push("\n"),r.push(this.svgToString(s,n));break;case 3:{const t=s.nodeValue.replace(/^\s+|\s+$/g,"");""!==t&&(e=!0,r.push(String(Z(t))));break}case 4:r.push("\n"),r.push(new Array(n+1).join(" ")),r.push("<![CDATA["),r.push(s.nodeValue),r.push("]]>");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<n;t++)r.push(" ")}r.push("</"),r.push(t.nodeName),r.push(">")}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("<canvas>",{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;m<d.length;m++)u.append(d[m].cloneNode(!0));if(w()){const t=Ln(at()).children("linearGradient,radialGradient,pattern").clone();Ln(u).append(t)}s&&u.setAttribute("transform",s);const g=t.parentNode;if(Ne(u),w()&&Ln(at()).append(Ln(u).find("linearGradient,radialGradient,pattern")),u.id=yt(),c.after(u),g){if(!h){const{nextSibling:e}=t;t.remove(),r.addSubCommand(new Mn(t,e,g))}r.addSubCommand(new On(u))}ke(u),w()?Ie(at()):Ie(u),function(t,e){if(t&&1===t.nodeType){let n=t.childNodes.length;for(;n--;)rt(t.childNodes.item(n),e);e(t)}}(u,(function(t){try{vn(t)}catch(t){console.log(t)}})),Ln(u).find(Ht).each((function(){this.id||(this.id=yt())})),be([u]);const p=Fe(u,!0);p&&r.addSubCommand(p),lt(r)}else console.log("Unexpected element to ungroup:",t)};this.setSvgString=function(t,n){try{const r=nt(t);if(r.firstElementChild&&r.firstElementChild.namespaceURI!==e.SVG)return!1;this.prepareSvg(r);const i=new Bn("Change Source"),{nextSibling:m}=l;l.remove();const g=l;i.addSubCommand(new Mn(g,m,c)),l=a.adoptNode?a.adoptNode(r.documentElement):a.importNode(r.documentElement,!0),c.append(l);const p=Ln(l);o.current_drawing_=new Xe(l,h);const f=u().getNonce();f?kt("setnonce",f):kt("unsetnonce"),p.find("image").each((function(){const t=this;Gt(t);const n=it(this);if(n){if(n.startsWith("data:")){const r=n.match(/svgedit_url=(.*?);/);if(r){const n=decodeURIComponent(r[1]);Ln(new Image).load((function(){t.setAttributeNS(e.XLINK,"xlink:href",n)})).attr("src",n)}}o.embedImage(n)}})),p.find("svg").each((function(){if(Ln(this).closest("defs").length)return;Ne(this);const t=this.parentNode;1===t.childNodes.length&&"g"===t.nodeName?(Ln(t).data("gsvg",this),t.id=t.id||yt()):ge(this)})),w()&&p.find("linearGradient, radialGradient, pattern").appendTo(at()),ke(p),Ie(p[0]);const y={id:"svgcontent",overflow:s.show_outside_canvas?"visible":"hidden"};let x=!1;if(p.attr("viewBox")){const t=p.attr("viewBox").split(" ");y.width=t[2],y.height=t[3]}else Ln.each(["width","height"],(function(t,e){const n=p.attr(e)||"100%";"%"===String(n).substr(-1)?x=!0:y[e]=Rt(e,n)}));if(Ye(),p.children().find(Ht).each((function(){this.id||(this.id=yt())})),x){const t=St();y.width=t.width+t.x,y.height=t.height+t.y}y.width<=0&&(y.width=100),y.height<=0&&(y.height=100),p.attr(y),this.contentW=y.width,this.contentH=y.height,i.addSubCommand(new On(l));const S=p.attr(["width","height"]);i.addSubCommand(new Rn(c,S)),d=1,N={},It(),Ge(),c.append(ft.selectorParentGroup),n||lt(i),kt("changed",[l])}catch(t){return console.log(t),!1}return!0},this.importSvgString=function(t){let n,r,s;try{const i=Y(t.length+t).substr(0,32);let o=!1;Zt[i]&&Ln(Zt[i].symbol).parents("#svgroot").length&&(o=!0);const c=new Bn("Import Image");let h;if(o)({symbol:h}=Zt[i]),r=Zt[i].xform;else{const s=nt(t);let o;this.prepareSvg(s),o=a.adoptNode?a.adoptNode(s.documentElement):a.importNode(s.documentElement,!0),Ne(o);const u=Rt("width",o.getAttribute("width")),d=Rt("height",o.getAttribute("height")),m=o.getAttribute("viewBox"),g=m?m.split(" "):[0,0,u,d];for(n=0;n<4;++n)g[n]=Number(g[n]);const p=Number(l.getAttribute("height"));r=d>u?"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("<p>"+a.replace(/\n/g,"</p><p>")+"</p>").toggleClass("prompt","prompt"===o),s.empty();const d=t('<input type="button" data-ok="" value="'+e+'">').appendTo(s);return new Promise((e,m)=>{let g,p;if("alert"!==o&&t('<input type="button" value="'+n+'">').appendTo(s).click((function(){r.hide(),e(!1)})),"prompt"===o)g=t('<input type="text">').prependTo(s),g.val(c||""),g.bind("keydown","return",(function(){d.click()}));else if("select"===o){const e=t('<div style="text-align:center;">');if(g=t(`<select aria-label="${a}">`).appendTo(e),u){const n=t("<label>").text(u.label);p=t('<input type="checkbox">').appendTo(n),p.val(u.value),u.tooltip&&n.attr("title",u.tooltip),p.prop("checked",Boolean(u.checked)),e.append(t("<div>").append(n))}t.each(l||[],(function(e,n){"object"==typeof n?g.append(t("<option>").val(n.value).html(n.text)):g.append(t("<option>").html(n))})),i.append(e),c&&g.val(c),h&&g.bind("change","return",h),g.bind("keydown","return",(function(){d.click()}))}else"process"===o&&d.hide();r.show(),d.click((function(){r.hide();const t="prompt"!==o&&"select"!==o||g.val();e(p?{response:t,checked:p.prop("checked")}:t)})).focus(),"prompt"!==o&&"select"!==o||g.focus()})}return t.alert=function(t){return o("alert",t)},t.confirm=function(t){return o("confirm",t)},t.process_cancel=function(t){return o("process",t)},t.prompt=function(t,e=""){return o("prompt",t,e)},t.select=function(t,e,n,r,s){return o("select",t,r,e,n,s)},t}(Ln,t.common),Kt(t)},this.setConfig=function(t){Object.assign(s,t)},this.getTitle=function(t){if(!(t=t||y[0]))return;const e=(t=Ln(t).data("gsvg")||Ln(t).data("symbol")||t).childNodes;for(const t of e)if("title"===t.nodeName)return t.textContent;return""},this.setGroupTitle=function(t){let n=y[0];n=Ln(n).data("gsvg")||n;const r=Ln(n).children("title"),s=new Bn("Set Label");let i;if(t.length)r.length?(i=r[0],s.addSubCommand(new Rn(i,{"#text":i.textContent})),i.textContent=t):(i=a.createElementNS(e.SVG,"title"),i.textContent=t,Ln(n).prepend(i),s.addSubCommand(new On(i)));else{const t=r.nextSibling;s.addSubCommand(new Mn(r[0],t,n)),r.remove()}lt(s)};const Oe=this.getDocumentTitle=function(){return o.getTitle(l)};this.setDocumentTitle=function(t){const n=l.childNodes;let r=!1,s="";const i=new Bn("Change Image Title");for(const t of n)if("title"===t.nodeName){r=t,s=r.textContent;break}r||(r=a.createElementNS(e.SVG,"title"),l.insertBefore(r,l.firstChild)),t.length?r.textContent=t:r.remove(),i.addSubCommand(new Rn(r,{"#text":s})),lt(i)},this.getEditorNS=function(t){return t&&l.setAttribute("xmlns:se",e.SE),e.SE},this.setResolution=function(t,e){const n=Ve(),{w:r,h:s}=n;let i;if("fit"===t){const n=St();if(!n)return!1;{i=new Bn("Fit Canvas to Content");const r=xt();Mt(r);const s=[],a=[];Ln.each(r,(function(t,e){s.push(-1*n.x),a.push(-1*n.y)}));const c=o.moveSelectedElements(s,a,!0);i.addSubCommand(c),It(),t=Math.round(n.width),e=Math.round(n.height)}}return t===r&&e===s||(i||(i=new Bn("Change Image Dimensions")),t=Rt("width",t),e=Rt("height",e),l.setAttribute("width",t),l.setAttribute("height",e),this.contentW=t,this.contentH=e,i.addSubCommand(new Rn(l,{width:r,height:s})),l.setAttribute("viewBox",[0,0,t/d,e/d].join(" ")),i.addSubCommand(new Rn(l,{viewBox:["0 0",r,s].join(" ")})),lt(i),kt("changed",[l])),!0},this.getOffset=function(){return Ln(l).attr(["x","y"])},this.setBBoxZoom=function(t,e,n){let r,s=.85;const i=function(t){if(!t)return!1;const r=Math.round(e/t.width*100*s)/100,i=Math.round(n/t.height*100*s)/100,a=Math.min(r,i);return o.setZoom(a),{zoom:a,bbox:t}};if("object"==typeof t){if(r=t,0===r.width||0===r.height){const t=r.zoom?r.zoom:d*r.factor;return o.setZoom(t),{zoom:d,bbox:r}}return i(r)}switch(t){case"selection":{if(!y[0])return;const t=Ln.map(y,(function(t){if(t)return t}));r=St(t);break}case"canvas":{const t=Ve();s=.95,r={width:t.w,height:t.h,x:0,y:0};break}case"content":r=St();break;case"layer":r=St(xt(u().getCurrentLayer()));break;default:return}return i(r)},this.setZoom=function(t){const e=Ve();l.setAttribute("viewBox","0 0 "+e.w/t+" "+e.h/t),d=t,Ln.each(y,(function(t,e){e&&ft.requestSelector(e).resize()})),I.zoomChange(),ue("zoomChanged",t)},this.getMode=function(){return se},this.setMode=function(t){I.clear(!0),Ae.clear(),oe=y[0]&&"text"===y[0].nodeName?Yt:p,se=t},this.getColor=function(t){return oe[t]},this.setColor=function(t,e,n){p[t]=e,oe[t+"_paint"]={type:"solidColor"};const r=[];function s(t){"g"!==t.nodeName&&r.push(t)}let i=y.length;for(;i--;){const e=y[i];e&&("g"===e.tagName?rt(e,s):"fill"===t?"polyline"!==e.tagName&&"line"!==e.tagName&&r.push(e):r.push(e))}r.length>0&&(n?Be(t,e,r):(Ue(t,e,r),kt("changed",r)))};const Me=this.setGradient=function(t){if(!oe[t+"_paint"]||"solidColor"===oe[t+"_paint"].type)return;let e=o[t+"Grad"];const n=Re(e),r=at();n?e=n:(e=r.appendChild(a.importNode(e,!0)),e.id=yt()),o.setColor(t,"url(#"+e.id+")")},Re=function(t){const n=at(),r=Ln(n).find("linearGradient, radialGradient");let s=r.length;const i=["r","cx","cy","fx","fy"];for(;s--;){const n=r[s];if("linearGradient"===t.tagName){if(t.getAttribute("x1")!==n.getAttribute("x1")||t.getAttribute("y1")!==n.getAttribute("y1")||t.getAttribute("x2")!==n.getAttribute("x2")||t.getAttribute("y2")!==n.getAttribute("y2"))continue}else{const e=Ln(t).attr(i),r=Ln(n).attr(i);let s=!1;if(Ln.each(i,(function(t,n){e[n]!==r[n]&&(s=!0)})),s)continue}const o=t.getElementsByTagNameNS(e.SVG,"stop"),a=n.getElementsByTagNameNS(e.SVG,"stop");if(o.length!==a.length)continue;let c=o.length;for(;c--;){const t=o[c],e=a[c];if(t.getAttribute("offset")!==e.getAttribute("offset")||t.getAttribute("stop-opacity")!==e.getAttribute("stop-opacity")||t.getAttribute("stop-color")!==e.getAttribute("stop-color"))break}if(-1===c)return n}return null};this.setPaint=function(t,e){const n=new Ln.jGraduate.Paint(e);switch(this.setPaintOpacity(t,n.alpha/100,!0),oe[t+"_paint"]=n,n.type){case"solidColor":this.setColor(t,"none"!==n.solidColor?"#"+n.solidColor:"none");break;case"linearGradient":case"radialGradient":o[t+"Grad"]=n[n.type],Me(t)}},this.setStrokePaint=function(t){this.setPaint("stroke",t)},this.setFillPaint=function(t){this.setPaint("fill",t)},this.getStrokeWidth=function(){return oe.stroke_width},this.setStrokeWidth=function(t){if(0===t&&["line","path"].includes(se))return void o.setStrokeWidth(1);oe.stroke_width=t;const e=[];function n(t){"g"!==t.nodeName&&e.push(t)}let r=y.length;for(;r--;){const t=y[r];t&&("g"===t.tagName?rt(t,n):e.push(t))}e.length>0&&(Ue("stroke-width",t,e),kt("changed",y))},this.setStrokeAttr=function(t,e){p[t.replace("-","_")]=e;const n=[];let r=y.length;for(;r--;){const t=y[r];t&&("g"===t.tagName?rt(t,(function(t){"g"!==t.nodeName&&n.push(t)})):n.push(t))}n.length>0&&(Ue(t,e,n),kt("changed",y))},this.getStyle=function(){return p},this.getOpacity=Bt,this.setOpacity=function(t){p.opacity=t,Ue("opacity",t)},this.getFillOpacity=function(){return p.fill_opacity},this.getStrokeOpacity=function(){return p.stroke_opacity},this.setPaintOpacity=function(t,e,n){p[t+"_opacity"]=e,n?Be(t+"-opacity",e):Ue(t+"-opacity",e)},this.getPaintOpacity=function(t){return"fill"===t?this.getFillOpacity():this.getStrokeOpacity()},this.getBlur=function(t){let e=0;if(t){if(t.getAttribute("filter")){const n=At(t.id+"_blur");n&&(e=n.firstChild.getAttribute("stdDeviation"))}}return e},function(){let t=null,e=null,n=!1;function r(){const n=o.undoMgr.finishUndoableChange();t.addSubCommand(n),lt(t),t=null,e=null}o.setBlurNoUndo=function(t){if(e)if(0===t)Be("filter",""),n=!0;else{const r=y[0];n&&Be("filter","url(#"+r.id+"_blur)"),b()&&(r.removeAttribute("filter"),r.setAttribute("filter","url(#"+r.id+"_blur)")),Be("stdDeviation",t,[e.firstChild]),o.setBlurOffsets(e,t)}else o.setBlur(t)},o.setBlurOffsets=function(t,e){e>3?Ct(t,{x:"-50%",y:"-50%",width:"200%",height:"200%"}):b()||(t.removeAttribute("x"),t.removeAttribute("y"),t.removeAttribute("width"),t.removeAttribute("height"))},o.setBlur=function(n,s){if(t)return void r();const i=y[0],a=i.id;e=At(a+"_blur"),n-=0;const c=new Bn;if(e)0===n&&(e=null);else{const t=S({element:"feGaussianBlur",attr:{in:"SourceGraphic",stdDeviation:n}});e=S({element:"filter",attr:{id:a+"_blur"}}),e.append(t),at().append(e),c.addSubCommand(new On(e))}const l={filter:i.getAttribute("filter")};if(0===n)return i.removeAttribute("filter"),void c.addSubCommand(new Rn(i,l));Ue("filter","url(#"+a+"_blur)"),c.addSubCommand(new Rn(i,l)),o.setBlurOffsets(e,n),t=c,o.undoMgr.beginUndoableChange("stdDeviation",[e?e.firstChild:null]),s&&(o.setBlurNoUndo(n),r())}}(),this.getBold=function(){const t=y[0];return!(Nt(t)||"text"!==t.tagName||!Nt(y[1]))&&"bold"===t.getAttribute("font-weight")},this.setBold=function(t){const e=y[0];!Nt(e)&&"text"===e.tagName&&Nt(y[1])&&Ue("font-weight",t?"bold":"normal"),y[0].textContent||Ae.setCursor()},this.getItalic=function(){const t=y[0];return!(Nt(t)||"text"!==t.tagName||!Nt(y[1]))&&"italic"===t.getAttribute("font-style")},this.setItalic=function(t){const e=y[0];!Nt(e)&&"text"===e.tagName&&Nt(y[1])&&Ue("font-style",t?"italic":"normal"),y[0].textContent||Ae.setCursor()},this.getFontFamily=function(){return Yt.font_family},this.setFontFamily=function(t){Yt.font_family=t,Ue("font-family",t),y[0]&&!y[0].textContent&&Ae.setCursor()},this.setFontColor=function(t){Yt.fill=t,Ue("fill",t)},this.getFontColor=function(){return Yt.fill},this.getFontSize=function(){return Yt.font_size},this.setFontSize=function(t){Yt.font_size=t,Ue("font-size",t),y[0].textContent||Ae.setCursor()},this.getText=function(){const t=y[0];return Nt(t)?"":t.textContent},this.setTextContent=function(t){Ue("#text",t),Ae.init(t),Ae.setCursor()},this.setImageURL=function(t){const e=y[0];if(!e)return;const n=Ln(e).attr(["width","height"]),r=!n.width||!n.height,s=it(e);if(s===t&&!r)return;const i=new Bn("Change Image URL");ot(e,t),i.addSubCommand(new Rn(e,{"#href":s})),Ln(new Image).load((function(){const t=Ln(e).attr(["width","height"]);Ln(e).attr({width:this.width,height:this.height}),ft.requestSelector(e).resize(),i.addSubCommand(new Rn(e,t)),lt(i),kt("changed",[e])})).attr("src",t)},this.setLinkURL=function(t){let e=y[0];if(!e)return;if("a"!==e.tagName){const t=Ln(e).parents("a");if(!t.length)return;e=t[0]}const n=it(e);if(n===t)return;const r=new Bn("Change Link URL");ot(e,t),r.addSubCommand(new Rn(e,{"#href":n})),lt(r)},this.setRectRadius=function(t){const e=y[0];if(!Nt(e)&&"rect"===e.tagName){const n=e.getAttribute("rx");n!==String(t)&&(e.setAttribute("rx",t),e.setAttribute("ry",t),lt(new Rn(e,{rx:n,ry:n},"Radius")),kt("changed",[e]))}},this.makeHyperlink=function(t){o.groupSelectedElements("a",t)},this.removeHyperlink=function(){o.ungroupSelectedElement()},this.setSegType=function(t){I.setSegType(t)},this.convertToPath=function(t,e){if(Nt(t)){const t=y;return void Ln.each(t,(function(t,e){e&&o.convertToPath(e)}))}if(e)return gt(t,S,I);return function(t,e,n,r,s,i,o,a){const c=new o.BatchCommand("Convert element to Path"),l=n({element:"path",attr:e=F.extend({},e,mt(t))}),h=t.getAttribute("transform");h&&l.setAttribute("transform",h);const{id:u}=t,{parentNode:d}=t;t.nextSibling?t.before(l):d.append(l);const m=dt(t);if(m){if(l.setAttribute("d",m),h){const t=P(l);M(t)&&r.resetOrientation(l)}const{nextSibling:e}=t;return c.addSubCommand(new o.RemoveElementCommand(t,e,parent)),c.addSubCommand(new o.InsertElementCommand(l)),s(),t.remove(),l.setAttribute("id",u),l.removeAttribute("visibility"),i([l],!0),a(c),l}return l.remove(),null}(t,{fill:p.fill,"fill-opacity":p.fill_opacity,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,opacity:p.opacity,visibility:"hidden"},S,I,It,Mt,qt,lt)};const Be=function(t,e,n){"pathedit"===se&&I.moveNode(t,e);let r=(n=n||y).length;const s=["g","polyline","path"];for(;r--;){let i=n[r];if(Nt(i))continue;if(("x"===t||"y"===t)&&s.includes(i.tagName)){const n=St([i]),r="x"===t?e-n.x:0,s="y"===t?e-n.y:0;o.moveSelectedElements(r*d,s*d,!0);continue}let a="#text"===t?i.textContent:i.getAttribute(t);if(Nt(a)&&(a=""),a!==String(e)){"#text"===t?(i.textContent=e,/rotate/.test(i.getAttribute("transform"))&&(i=fe(i))):"#href"===t?ot(i,e):i.setAttribute(t,e),"textedit"===se&&"#text"!==t&&i.textContent.length&&Ae.toSelectMode(i),w()&&"text"===i.nodeName&&/rotate/.test(i.getAttribute("transform"))&&(String(e).startsWith("url")||["font-size","font-family","x","y"].includes(t)&&i.textContent)&&(i=fe(i)),y.includes(i)&&setTimeout((function(){i.parentNode&&ft.requestSelector(i).resize()}),0);const n=bt(i);if(0!==n&&"transform"!==t){const t=P(i);let e=t.numberOfItems;for(;e--;){if(4===t.getItem(e).type){t.removeItem(e);const r=ht(i),s=L(r.x+r.width/2,r.y+r.height/2,B(t).matrix),o=s.x,a=s.y,l=c.createSVGTransform();l.setRotate(n,o,a),t.insertItemBefore(l,e);break}}}}}},Ue=this.changeSelectedAttribute=function(t,e,n){n=n||y,o.undoMgr.beginUndoableChange(t,n),Be(t,e,n);const r=o.undoMgr.finishUndoableChange();r.isEmpty()||lt(r)};this.deleteSelectedElements=function(){const t=new Bn("Delete Elements"),e=y.length,n=[];for(let r=0;r<e;++r){const e=y[r];if(Nt(e))break;let s=e.parentNode,i=e;ft.releaseSelector(i),Se(i.id),"a"===s.tagName&&1===s.childNodes.length&&(i=s,s=s.parentNode);const{nextSibling:o}=i;i.remove();const a=i;n.push(e),t.addSubCommand(new Mn(a,o,s))}y=[],t.isEmpty()||lt(t),kt("changed",n),It()},this.cutSelectedElements=function(){o.copySelectedElements(),o.deleteSelectedElements()};const je="svgedit_clipboard";function He(){const t=sessionStorage.getItem(je);localStorage.setItem(je,t),setTimeout((function(){localStorage.removeItem(je)}),1)}window.addEventListener("storage",(function(t){t.newValue&&(t.key===je+"_startup"?(localStorage.removeItem(je+"_startup"),He()):t.key===je&&sessionStorage.setItem(je,t.newValue))}),!1),localStorage.setItem(je+"_startup",Math.random()),this.copySelectedElements=function(){const t=JSON.stringify(y.map(t=>x(t)));sessionStorage.setItem(je,t),He();const e=Ln("#cmenu_canvas");e.enableContextMenuItems&&e.enableContextMenuItems("#paste,#paste_in_place")},this.pasteElements=function(t,e,n){let r=JSON.parse(sessionStorage.getItem(je));if(!r)return;let s=r.length;if(!s)return;const i=[],a=new Bn("Paste elements"),c={};for(r.forEach((function t(e){e.attr&&e.attr.id&&(c[e.attr.id]=yt(),e.attr.id=c[e.attr.id]),e.children&&e.children.forEach(t)})),ue("IDsUpdated",{elems:r,changes:c},!0).forEach((function(t){t&&"remove"in t&&t.remove.forEach((function(t){r=r.filter((function(e){return e.attr.id!==t}))}))}));s--;){const t=r[s];if(!t)continue;const e=S(t);i.push(e),a.addSubCommand(new On(e)),Qt(e)}if(be(i),"in_place"!==t){let r,s;t?"point"===t&&(r=e,s=n):(r=he.x,s=he.y);const c=St(i),l=r-(c.x+c.width/2),h=s-(c.y+c.height/2),u=[],d=[];Ln.each(i,(function(t,e){u.push(l),d.push(h)}));const m=o.moveSelectedElements(u,d,!1);m&&a.addSubCommand(m)}lt(a),kt("changed",i)},this.groupSelectedElements=function(t,e){t||(t="g");let n,r="";switch(t){case"a":r="Make hyperlink",n=e||"";break;default:t="g",r="Group Elements"}const s=new Bn(r),i=S({element:t,attr:{id:yt()}});"a"===t&&ot(i,n),s.addSubCommand(new On(i));let o=y.length;for(;o--;){let t=y[o];if(Nt(t))continue;"a"===t.parentNode.tagName&&1===t.parentNode.childNodes.length&&(t=t.parentNode);const e=t.nextSibling,n=t.parentNode;i.append(t),s.addSubCommand(new Vn(t,e,n))}s.isEmpty()||lt(s),be([i],!0)};const Fe=this.pushGroupProperties=function(t,e){const n=t.childNodes,r=n.length,s=t.getAttribute("transform"),i=P(t),a=B(i).matrix,l=new Bn("Push group properties"),h=bt(t),d=Ln(t).attr(["filter","opacity"]);let m,g,p;const f=u();for(let e=0;e<r;e++){const r=n[e];if(1!==r.nodeType)continue;if(null!==d.opacity&&1!==d.opacity){const t=Math.round((r.getAttribute("opacity")||1)*d.opacity*100)/100;Ue("opacity",t,[r])}if(d.filter){let e=this.getBlur(r);const n=e;g||(g=this.getBlur(t)),e?e=Number(g)+Number(e):0===e&&(e=g),n?m=wt(r.getAttribute("filter")):m?(m=f.copyElem(m),at().append(m)):m=wt(d.filter);const s="feGaussianBlur"===m.firstChild.tagName?"blur":"filter";m.id=r.id+"_"+s,Ue("filter","url(#"+m.id+")",[r]),e&&(Ue("stdDeviation",e,[m.firstChild]),o.setBlurOffsets(m,e))}let s=P(r);if(r.tagName.includes("Gradient")&&(s=null),s&&"defs"!==r.tagName&&i.numberOfItems){if(h&&1===i.numberOfItems){const t=i.getItem(0).matrix;let e=c.createSVGMatrix();const n=bt(r);n&&(e=s.getItem(0).matrix);const o=ht(r),a=B(s).matrix,l=L(o.x+o.width/2,o.y+o.height/2,a),u=h+n,d=c.createSVGTransform();d.setRotate(u,l.x,l.y);const m=O(t,e,d.matrix.inverse());if(n&&s.removeItem(0),u&&(s.numberOfItems?s.insertItemBefore(d,0):s.appendItem(d)),m.e||m.f){const t=c.createSVGTransform();t.setTranslate(m.e,m.f),s.numberOfItems?s.insertItemBefore(t,0):s.appendItem(t)}}else{const t=r.getAttribute("transform");p={},p.transform=t||"";const e=c.createSVGTransform(),n=B(s).matrix,i=n.inverse(),o=O(i,a,n);e.setMatrix(o),s.appendItem(e)}const t=vn(r);t&&l.addSubCommand(t)}}if(s&&(p={},p.transform=s,t.setAttribute("transform",""),t.removeAttribute("transform"),l.addSubCommand(new Rn(t,p))),e&&!l.isEmpty())return l};this.ungroupSelectedElement=function(){let t=y[0];if(!t)return;if(Ln(t).data("gsvg")||Ln(t).data("symbol"))return void Pe(t);if("use"===t.tagName){const e=At(it(t).substr(1));return Ln(t).data("symbol",e).data("ref",e),void Pe(t)}const e=Ln(t).parents("a");if(e.length&&(t=e[0]),"g"===t.tagName||"a"===t.tagName){const e=new Bn("Ungroup Elements"),n=Fe(t,!0);n&&e.addSubCommand(n);const r=t.parentNode,s=t.nextSibling,i=new Array(t.childNodes.length);let o=0;for(;t.firstChild;){const n=t.firstChild,r=n.nextSibling,a=n.parentNode;if("title"!==n.tagName)s?s.before(n):t.after(n),i[o++]=n,e.addSubCommand(new Vn(n,r,a));else{const{nextSibling:t}=n;e.addSubCommand(new Mn(n,t,a)),n.remove()}}It();const a=t.nextSibling;t.remove(),e.addSubCommand(new Mn(t,a,r)),e.isEmpty()||lt(e),Mt(i)}},this.moveToTopSelectedElement=function(){const[t]=y;if(!Nt(t)){let e=t;const n=e.parentNode,r=e.nextSibling;e=e.parentNode.appendChild(e),r!==e.nextSibling&&(lt(new Vn(e,r,n,"top")),kt("changed",[e]))}},this.moveToBottomSelectedElement=function(){const[t]=y;if(!Nt(t)){let e=t;const n=e.parentNode,r=e.nextSibling;let{firstChild:s}=e.parentNode;"title"===s.tagName&&(s=s.nextSibling),"defs"===s.tagName&&(s=s.nextSibling),e=e.parentNode.insertBefore(e,s),r!==e.nextSibling&&(lt(new Vn(e,r,n,"bottom")),kt("changed",[e]))}},this.moveUpDownSelected=function(t){const e=y[0];if(!e)return;let n,r;le=[];const s=Ln(de(St([e]))).toArray();if("Down"===t&&s.reverse(),Ln.each(s,(function(){return r?(n=this,!1):(this===e&&(r=!0),!0)})),!n)return;const i=e,o=i.parentNode,a=i.nextSibling;Ln(n)["Down"===t?"before":"after"](i),a!==i.nextSibling&&(lt(new Vn(i,a,o,"Move "+t)),kt("changed",[i]))},this.moveSelectedElements=function(t,e,n){t.constructor!==Array&&(t/=d,e/=d),n=n||!0;const r=new Bn("position");let s=y.length;for(;s--;){const n=y[s];if(!Nt(n)){const i=c.createSVGTransform(),o=P(n);t.constructor===Array?i.setTranslate(t[s],e[s]):i.setTranslate(t,e),o.numberOfItems?o.insertItemBefore(i,0):o.appendItem(i);const a=vn(n);a&&r.addSubCommand(a),ft.requestSelector(n).resize()}}if(!r.isEmpty())return n&<(r),kt("changed",y),r},this.cloneSelectedElements=function(t,e){let n,r;const s=new Bn("Clone Elements"),i=y.length;for(y.sort((function(t,e){return Ln(e).index()-Ln(t).index()})),n=0;n<i&&(r=y[n],!Nt(r));++n);const o=y.slice(0,n);this.clearSelection(!0);const a=u();for(n=o.length;n--;)r=o[n]=a.copyElem(o[n]),(m||a.getCurrentLayer()).append(r),s.addSubCommand(new On(r));s.isEmpty()||(Mt(o.reverse()),this.moveSelectedElements(t,e,!1),lt(s))},this.alignSelectedElements=function(t,e){const n=[],r=y.length;if(!r)return;let s=Number.MAX_VALUE,i=Number.MIN_VALUE,a=Number.MAX_VALUE,c=Number.MIN_VALUE,l=Number.MIN_VALUE,h=Number.MIN_VALUE;for(let o=0;o<r&&!Nt(y[o]);++o){const r=y[o];switch(n[o]=St([r]),e){case"smallest":(("l"===t||"c"===t||"r"===t)&&(l===Number.MIN_VALUE||l>n[o].width)||("t"===t||"m"===t||"b"===t)&&(h===Number.MIN_VALUE||h>n[o].height))&&(s=n[o].x,a=n[o].y,i=n[o].x+n[o].width,c=n[o].y+n[o].height,l=n[o].width,h=n[o].height);break;case"largest":(("l"===t||"c"===t||"r"===t)&&(l===Number.MIN_VALUE||l<n[o].width)||("t"===t||"m"===t||"b"===t)&&(h===Number.MIN_VALUE||h<n[o].height))&&(s=n[o].x,a=n[o].y,i=n[o].x+n[o].width,c=n[o].y+n[o].height,l=n[o].width,h=n[o].height);break;default:n[o].x<s&&(s=n[o].x),n[o].y<a&&(a=n[o].y),n[o].x+n[o].width>i&&(i=n[o].x+n[o].width),n[o].y+n[o].height>c&&(c=n[o].y+n[o].height)}}"page"===e&&(s=0,a=0,i=o.contentW,c=o.contentH);const u=new Array(r),d=new Array(r);for(let e=0;e<r&&!Nt(y[e]);++e){const r=n[e];switch(u[e]=0,d[e]=0,t){case"l":u[e]=s-r.x;break;case"c":u[e]=(s+i)/2-(r.x+r.width/2);break;case"r":u[e]=i-(r.x+r.width);break;case"t":d[e]=a-r.y;break;case"m":d[e]=(a+c)/2-(r.y+r.height/2);break;case"b":d[e]=c-(r.y+r.height)}}this.moveSelectedElements(u,d)},this.contentW=Ve().w,this.contentH=Ve().h,this.updateCanvas=function(t,e){c.setAttribute("width",t),c.setAttribute("height",e);const n=Ln("#canvasBackground")[0],r=l.getAttribute("x"),s=l.getAttribute("y"),i=(t-this.contentW*d)/2,o=(e-this.contentH*d)/2;Ct(l,{width:this.contentW*d,height:this.contentH*d,x:i,y:o,viewBox:"0 0 "+this.contentW+" "+this.contentH}),Ct(n,{width:l.getAttribute("width"),height:l.getAttribute("height"),x:i,y:o});const a=At("background_image");return a&&Ct(a,{width:"100%",height:"100%"}),ft.selectorParentGroup.setAttribute("transform","translate("+i+","+o+")"),ue("canvasUpdated",{new_x:i,new_y:o,old_x:r,old_y:s,d_x:i-r,d_y:o-s}),{x:i,y:o,old_x:r,old_y:s,d_x:i-r,d_y:o-s}},this.setBackground=function(t,n){const r=At("canvasBackground"),s=Ln(r).find("rect")[0];let i=At("background_image"),o=At("background_pattern");if(s.setAttribute("fill","chessboard"===t?"#fff":t),"chessboard"===t){if(!o){o=a.createElementNS(e.SVG,"foreignObject"),Ct(o,{id:"background_pattern",width:"100%",height:"100%",preserveAspectRatio:"xMinYMin",style:"pointer-events:none"});const t=document.createElement("div");Ct(t,{style:"pointer-events:none;width:100%;height:100%;background-image:url(data:image/gif;base64,R0lGODlhEAAQAIAAAP///9bW1iH5BAAAAAAALAAAAAAQABAAAAIfjG+gq4jM3IFLJgpswNly/XkcBpIiVaInlLJr9FZWAQA7);"}),o.appendChild(t),r.append(o)}}else o&&o.remove();n?(i||(i=a.createElementNS(e.SVG,"image"),Ct(i,{id:"background_image",width:"100%",height:"100%",preserveAspectRatio:"xMinYMin",style:"pointer-events:none"})),ot(i,n),r.append(i)):i&&i.remove()},this.cycleElement=function(t){let e;const n=y[0];let r=!1;const s=xt(m||u().getCurrentLayer());if(s.length){if(Nt(n))e=t?s.length-1:0,r=s[e];else{let i=s.length;for(;i--;)if(s[i]===n){e=t?i-1:i+1,e>=s.length?e=0:e<0&&(e=s.length-1),r=s[e];break}}be([r],!0),kt("selected",y)}},this.clear(),this.getPrivateMethods=function(){return{addCommandToHistory:lt,BatchCommand:Bn,ChangeElementCommand:Rn,decode64:$,dropXMLInternalSubset:K,encode64:Y,ffClone:fe,findDefs:at,findDuplicateGradient:Re,getElem:At,getPathBBox:ct,getTypeMap:Lt,getUrlFromAttr:st,identifyLayers:Ye,InsertElementCommand:On,isChrome:C,isIdentity:V,isIE:A,logMatrix:xe,MoveElementCommand:Vn,NS:e,preventClickDefault:Gt,RemoveElementCommand:Mn,SVGEditTransformList:k,text2xml:nt,transformBox:R,transformPoint:L,walkTree:rt}}}}}();
|
|
//# sourceMappingURL=svgcanvas-iife.min.js.map
|