var SvgCanvas=function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t,r,n,i,a,s){try{var o=e[a](s),u=o.value}catch(e){return void r(e)}o.done?t(u):Promise.resolve(u).then(n,i)}function r(e){return function(){var r=this,n=arguments;return new Promise(function(i,a){var s=e.apply(r,n);function o(e){t(s,i,a,o,u,"next",e)}function u(e){t(s,i,a,o,u,"throw",e)}o(void 0)})}}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var r=0;rt.getTotalLength())break;r--}while(r>0);return r}),window.SVGPathSeg=e,window.SVGPathSegClosePath=t,window.SVGPathSegMovetoAbs=r,window.SVGPathSegMovetoRel=i,window.SVGPathSegLinetoAbs=u,window.SVGPathSegLinetoRel=h,window.SVGPathSegCurvetoCubicAbs=c,window.SVGPathSegCurvetoCubicRel=d,window.SVGPathSegCurvetoQuadraticAbs=m,window.SVGPathSegCurvetoQuadraticRel=f,window.SVGPathSegArcAbs=g,window.SVGPathSegArcRel=p,window.SVGPathSegLinetoHorizontalAbs=y,window.SVGPathSegLinetoHorizontalRel=v,window.SVGPathSegLinetoVerticalAbs=x,window.SVGPathSegLinetoVerticalRel=_,window.SVGPathSegCurvetoCubicSmoothAbs=S,window.SVGPathSegCurvetoCubicSmoothRel=b,window.SVGPathSegCurvetoQuadraticSmoothAbs=w,window.SVGPathSegCurvetoQuadraticSmoothRel=A}if(!("SVGPathSegList"in window&&"appendItem"in window.SVGPathSegList.prototype)){var k=function(){function e(t){n(this,e),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)}return a(e,[{key:"_checkPathSynchronizedToList",value:function(){this._updateListFromPathMutations(this._pathElementMutationObserver.takeRecords())}},{key:"_updateListFromPathMutations",value:function(e){if(this._pathElement){var t=!1;e.forEach(function(e){"d"===e.attributeName&&(t=!0)}),t&&(this._list=this._parsePath(this._pathElement.getAttribute("d")))}}},{key:"_writeListToPath",value:function(){this._pathElementMutationObserver.disconnect(),this._pathElement.setAttribute("d",e._pathSegArrayAsString(this._list)),this._pathElementMutationObserver.observe(this._pathElement,this._mutationObserverConfig)}},{key:"segmentChanged",value:function(e){this._writeListToPath()}},{key:"clear",value:function(){this._checkPathSynchronizedToList(),this._list.forEach(function(e){e._owningPathSegList=null}),this._list=[],this._writeListToPath()}},{key:"initialize",value:function(e){return this._checkPathSynchronizedToList(),this._list=[e],e._owningPathSegList=this,this._writeListToPath(),e}},{key:"_checkValidIndex",value:function(e){if(isNaN(e)||e<0||e>=this.numberOfItems)throw new Error("INDEX_SIZE_ERR")}},{key:"getItem",value:function(e){return this._checkPathSynchronizedToList(),this._checkValidIndex(e),this._list[e]}},{key:"insertItemBefore",value:function(e,t){return this._checkPathSynchronizedToList(),t>this.numberOfItems&&(t=this.numberOfItems),e._owningPathSegList&&(e=e.clone()),this._list.splice(t,0,e),e._owningPathSegList=this,this._writeListToPath(),e}},{key:"replaceItem",value:function(e,t){return this._checkPathSynchronizedToList(),e._owningPathSegList&&(e=e.clone()),this._checkValidIndex(t),this._list[t]=e,e._owningPathSegList=this,this._writeListToPath(),e}},{key:"removeItem",value:function(e){this._checkPathSynchronizedToList(),this._checkValidIndex(e);var t=this._list[e];return this._list.splice(e,1),this._writeListToPath(),t}},{key:"appendItem",value:function(e){return this._checkPathSynchronizedToList(),e._owningPathSegList&&(e=e.clone()),this._list.push(e),e._owningPathSegList=this,this._writeListToPath(),e}},{key:"_parsePath",value:function(e){if(!e||!e.length)return[];var t=this,r=function(){function e(){n(this,e),this.pathSegList=[]}return a(e,[{key:"appendSegment",value:function(e){this.pathSegList.push(e)}}]),e}(),i=function(){function e(t){n(this,e),this._string=t,this._currentIndex=0,this._endIndex=this._string.length,this._previousCommand=SVGPathSeg.PATHSEG_UNKNOWN,this._skipOptionalSpaces()}return a(e,[{key:"_isCurrentSpace",value:function(){var e=this._string[this._currentIndex];return e<=" "&&(" "===e||"\n"===e||"\t"===e||"\r"===e||"\f"===e)}},{key:"_skipOptionalSpaces",value:function(){for(;this._currentIndex="0"&&e<="9")&&t!==SVGPathSeg.PATHSEG_CLOSEPATH?t===SVGPathSeg.PATHSEG_MOVETO_ABS?SVGPathSeg.PATHSEG_LINETO_ABS:t===SVGPathSeg.PATHSEG_MOVETO_REL?SVGPathSeg.PATHSEG_LINETO_REL:t:SVGPathSeg.PATHSEG_UNKNOWN}},{key:"initialCommandIsMoveTo",value:function(){if(!this.hasMoreData())return!0;var e=this.peekSegmentType();return e===SVGPathSeg.PATHSEG_MOVETO_ABS||e===SVGPathSeg.PATHSEG_MOVETO_REL}},{key:"_parseNumber",value:function(){var e=0,t=0,r=1,n=0,i=1,a=1,s=this._currentIndex;if(this._skipOptionalSpaces(),this._currentIndex"9")&&"."!==this._string.charAt(this._currentIndex))){for(var o=this._currentIndex;this._currentIndex="0"&&this._string.charAt(this._currentIndex)<="9";)this._currentIndex++;if(this._currentIndex!==o)for(var u=this._currentIndex-1,l=1;u>=o;)t+=l*(this._string.charAt(u--)-"0"),l*=10;if(this._currentIndex=this._endIndex||this._string.charAt(this._currentIndex)<"0"||this._string.charAt(this._currentIndex)>"9")return;for(;this._currentIndex="0"&&this._string.charAt(this._currentIndex)<="9";)r*=10,n+=(this._string.charAt(this._currentIndex)-"0")/r,this._currentIndex+=1}if(this._currentIndex!==s&&this._currentIndex+1=this._endIndex||this._string.charAt(this._currentIndex)<"0"||this._string.charAt(this._currentIndex)>"9")return;for(;this._currentIndex="0"&&this._string.charAt(this._currentIndex)<="9";)e*=10,e+=this._string.charAt(this._currentIndex)-"0",this._currentIndex++}var h=t+n;if(h*=i,e&&(h*=Math.pow(10,a*e)),s!==this._currentIndex)return this._skipOptionalSpacesOrDelimiter(),h}}},{key:"_parseArcFlag",value:function(){if(!(this._currentIndex>=this._endIndex)){var e=!1,t=this._string.charAt(this._currentIndex++);if("0"===t)e=!1;else{if("1"!==t)return;e=!0}return this._skipOptionalSpacesOrDelimiter(),e}}},{key:"parseSegment",value:function(){var e=this._string[this._currentIndex],r=this._pathSegTypeFromChar(e);if(r===SVGPathSeg.PATHSEG_UNKNOWN){if(this._previousCommand===SVGPathSeg.PATHSEG_UNKNOWN)return null;if((r=this._nextCommandHelper(e,this._previousCommand))===SVGPathSeg.PATHSEG_UNKNOWN)return null}else this._currentIndex++;switch(this._previousCommand=r,r){case SVGPathSeg.PATHSEG_MOVETO_REL:return new SVGPathSegMovetoRel(t,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_MOVETO_ABS:return new SVGPathSegMovetoAbs(t,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_REL:return new SVGPathSegLinetoRel(t,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_ABS:return new SVGPathSegLinetoAbs(t,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL:return new SVGPathSegLinetoHorizontalRel(t,this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS:return new SVGPathSegLinetoHorizontalAbs(t,this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_VERTICAL_REL:return new SVGPathSegLinetoVerticalRel(t,this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS:return new SVGPathSegLinetoVerticalAbs(t,this._parseNumber());case SVGPathSeg.PATHSEG_CLOSEPATH:return this._skipOptionalSpaces(),new SVGPathSegClosePath(t);case SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL:var n={x1:this._parseNumber(),y1:this._parseNumber(),x2:this._parseNumber(),y2:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoCubicRel(t,n.x,n.y,n.x1,n.y1,n.x2,n.y2);case SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS:var i={x1:this._parseNumber(),y1:this._parseNumber(),x2:this._parseNumber(),y2:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoCubicAbs(t,i.x,i.y,i.x1,i.y1,i.x2,i.y2);case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL:var a={x2:this._parseNumber(),y2:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoCubicSmoothRel(t,a.x,a.y,a.x2,a.y2);case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:var s={x2:this._parseNumber(),y2:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoCubicSmoothAbs(t,s.x,s.y,s.x2,s.y2);case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL:var o={x1:this._parseNumber(),y1:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoQuadraticRel(t,o.x,o.y,o.x1,o.y1);case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS:var u={x1:this._parseNumber(),y1:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoQuadraticAbs(t,u.x,u.y,u.x1,u.y1);case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL:return new SVGPathSegCurvetoQuadraticSmoothRel(t,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS:return new SVGPathSegCurvetoQuadraticSmoothAbs(t,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_ARC_REL:var l={x1:this._parseNumber(),y1:this._parseNumber(),arcAngle:this._parseNumber(),arcLarge:this._parseArcFlag(),arcSweep:this._parseArcFlag(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegArcRel(t,l.x,l.y,l.x1,l.y1,l.arcAngle,l.arcLarge,l.arcSweep);case SVGPathSeg.PATHSEG_ARC_ABS:var h={x1:this._parseNumber(),y1:this._parseNumber(),arcAngle:this._parseNumber(),arcLarge:this._parseArcFlag(),arcSweep:this._parseArcFlag(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegArcAbs(t,h.x,h.y,h.x1,h.y1,h.arcAngle,h.arcLarge,h.arcSweep);default:throw new Error("Unknown path seg type.")}}}]),e}(),s=new r,o=new i(e);if(!o.initialCommandIsMoveTo())return[];for(;o.hasMoreData();){var u=o.parseSegment();if(!u)return[];s.appendSegment(u)}return s.pathSegList}}]),e}();k.prototype.classname="SVGPathSegList",Object.defineProperty(k.prototype,"numberOfItems",{get:function(){return this._checkPathSynchronizedToList(),this._list.length},enumerable:!0}),k._pathSegArrayAsString=function(e){var t="",r=!0;return e.forEach(function(e){r?(r=!1,t+=e._asPathString()):t+=" "+e._asPathString()}),t},Object.defineProperties(SVGPathElement.prototype,{pathSegList:{get:function(){return this._pathSegList||(this._pathSegList=new k(this)),this._pathSegList},enumerable:!0},normalizedPathSegList:{get:function(){return this.pathSegList},enumerable:!0},animatedPathSegList:{get:function(){return this.pathSegList},enumerable:!0},animatedNormalizedPathSegList:{get:function(){return this.pathSegList},enumerable:!0}}),window.SVGPathSegList=k}}();var m,f={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/"},g=function(){var e={};return Object.entries(f).forEach(function(t){var r=h(t,2),n=r[0],i=r[1];e[i]=n.toLowerCase()}),e},p=jQuery,y=(Boolean(document.createElementNS&&document.createElementNS(f.SVG,"svg").createSVGRect),navigator.userAgent),v=document.createElementNS(f.SVG,"svg"),x=Boolean(window.opera),_=y.includes("AppleWebKit"),S=y.includes("Gecko/"),b=y.includes("MSIE"),w=y.includes("Chrome/"),A=(y.includes("Windows"),y.includes("Macintosh"),"ontouchstart"in window),k=Boolean(v.querySelector),C=Boolean(document.evaluate),E=function(){var e=document.createElementNS(f.SVG,"path");e.setAttribute("d","M0,0 10,10");var t=e.pathSegList,r=e.createSVGPathSegLinetoAbs(5,5);try{return t.replaceItem(r,1),!0}catch(e){}return!1}(),P=function(){var e=document.createElementNS(f.SVG,"path");e.setAttribute("d","M0,0 10,10");var t=e.pathSegList,r=e.createSVGPathSegLinetoAbs(5,5);try{return t.insertItemBefore(r,1),!0}catch(e){}return!1}(),G=function(){var e=document.createElementNS(f.SVG,"svg"),t=document.createElementNS(f.SVG,"svg");document.documentElement.append(e),t.setAttribute("x",5),e.append(t);var r=document.createElementNS(f.SVG,"text");r.textContent="a",t.append(r);try{return 0===r.getStartPositionOfChar(0).x}catch(e){return!1}finally{e.remove()}}(),N=function(){var e=document.createElementNS(f.SVG,"svg");document.documentElement.append(e);var t=document.createElementNS(f.SVG,"path");t.setAttribute("d","M0,0 C0,0 10,10 10,0"),e.append(t);var r=t.getBBox();return e.remove(),r.height>4&&r.height<5}(),I=function(){var e=document.createElementNS(f.SVG,"svg");document.documentElement.append(e);var t=document.createElementNS(f.SVG,"path");t.setAttribute("d","M0,0 10,0");var r=document.createElementNS(f.SVG,"path");r.setAttribute("d","M5,0 15,0");var n=document.createElementNS(f.SVG,"g");n.append(t,r),e.append(n);var i=n.getBBox();return e.remove(),15===i.width}(),T=(function(){var e=document.createElementNS(f.SVG,"rect");e.setAttribute("x",.1);var t=!e.cloneNode(!1).getAttribute("x").includes(",");t||p.alert('NOTE: This version of Opera is known to contain bugs in SVG-edit.\nPlease upgrade to the latest version in which the problems have been fixed.')}(),(m=document.createElementNS(f.SVG,"rect")).setAttribute("style","vector-effect:non-scaling-stroke"),"non-scaling-stroke"===m.style.vectorEffect),L=function(){var t=document.createElementNS(f.SVG,"rect").transform.baseVal,r=v.createSVGTransform();t.appendItem(r);var n=t.getItem(0),i=function(t){return t&&"object"===e(t)&&"function"==typeof t.setMatrix&&"angle"in t};return i(n)&&i(r)&&n.type===r.type&&n.angle===r.angle&&n.matrix.a===r.matrix.a&&n.matrix.b===r.matrix.b&&n.matrix.c===r.matrix.c&&n.matrix.d===r.matrix.d&&n.matrix.e===r.matrix.e&&n.matrix.f===r.matrix.f}(),V=function(){return x},O=function(){return _},M=function(){return S},R=function(){return b},B=function(){return w},U=function(){return I},H=function(){return T},j=document.createElementNS(f.SVG,"svg");function F(e){var t=e.matrix,r="";switch(e.type){case 1:r="matrix("+[t.a,t.b,t.c,t.d,t.e,t.f].join(",")+")";break;case 2:r="translate("+t.e+","+t.f+")";break;case 3:r=t.a===t.d?"scale("+t.a+")":"scale("+t.a+","+t.d+")";break;case 4:var n=0,i=0;if(0!==e.angle){var a=1-t.a;i=(a*t.f+t.b*t.e)/(a*a+t.b*t.b),n=(t.e-t.b*i)/a}r="rotate("+e.angle+" "+n+","+i+")"}return r}var D,z={},q=function(){function e(t){n(this,e),this._elem=t||null,this._xforms=[],this._update=function(){for(var e="",t=0;t=0)return this._xforms[e];var t=new Error("DOMException with code=INDEX_SIZE_ERR");throw t.code=1,t}},{key:"insertItemBefore",value:function(e,t){var r=null;if(t>=0)if(t=0&&(this._removeFromOtherLists(e),this._xforms[t]=e,r=e,this._list._update()),r}},{key:"removeItem",value:function(e){if(e=0){var t,r=this._xforms[e],n=new Array(this.numberOfItems-1);for(t=0;t=0;t--)this.stack[t].unapply(e);e&&e.handleHistoryEvent(re.AFTER_UNAPPLY,this)}},{key:"elements",value:function(){for(var e=[],t=this.stack.length;t--;)for(var r=this.stack[t].elements(),n=r.length;n--;)e.includes(r[n])||e.push(r[n]);return e}},{key:"addSubCommand",value:function(e){this.stack.push(e)}},{key:"isEmpty",value:function(){return!this.stack.length}}]),t}();ue.type=ue.prototype.type;var le=function(){function e(t){n(this,e),this.handler_=t||null,this.undoStackPointer=0,this.undoStack=[],this.undoChangeStackPointer=-1,this.undoableChangeStack=[]}return a(e,[{key:"resetUndoStack",value:function(){this.undoStack=[],this.undoStackPointer=0}},{key:"getUndoStackSize",value:function(){return this.undoStackPointer}},{key:"getRedoStackSize",value:function(){return this.undoStack.length-this.undoStackPointer}},{key:"getNextUndoCommandText",value:function(){return this.undoStackPointer>0?this.undoStack[this.undoStackPointer-1].getText():""}},{key:"getNextRedoCommandText",value:function(){return this.undoStackPointer0&&this.undoStack[--this.undoStackPointer].unapply(this.handler_)}},{key:"redo",value:function(){this.undoStackPointer0&&this.undoStack[this.undoStackPointer++].apply(this.handler_)}},{key:"addCommandToHistory",value:function(e){this.undoStackPointer0&&(this.undoStack=this.undoStack.splice(0,this.undoStackPointer)),this.undoStack.push(e),this.undoStackPointer=this.undoStack.length}},{key:"beginUndoableChange",value:function(e,t){for(var r=++this.undoChangeStackPointer,n=t.length,i=new Array(n),a=new Array(n);n--;){var s=t[n];Xt(s)||(a[n]=s,i[n]=s.getAttribute(e))}this.undoableChangeStack[r]={attrName:e,oldValues:i,elements:a}}},{key:"finishUndoableChange",value:function(){for(var e=this.undoChangeStackPointer--,t=this.undoableChangeStack[e],r=t.attrName,n=new ue("Change "+r),i=t.elements.length;i--;){var a=t.elements[i];if(!Xt(a)){var s={};s[r]=t.oldValues[i],s[r]!==a.getAttribute(r)&&n.addSubCommand(new oe(a,s,r))}}return this.undoableChangeStack[e]=null,n}}]),e}(),he=Object.freeze({HistoryEventTypes:re,MoveElementCommand:ie,InsertElementCommand:ae,RemoveElementCommand:se,ChangeElementCommand:oe,BatchCommand:ue,UndoManager:le}),ce=document.createElementNS(f.SVG,"svg"),de=function(e,t,r){return{x:r.a*e+r.c*t+r.e,y:r.b*e+r.d*t+r.f}},me=function(e){return 1===e.a&&0===e.b&&0===e.c&&1===e.d&&0===e.e&&0===e.f},fe=function(){for(var e=arguments.length,t=new Array(e),r=0;r(r=parseInt(r))){var n=r;r=t,t=n}for(var i=ce.createSVGMatrix(),a=t;a<=r;++a){var s=a>=0&&ae.x&&t.ye.y},Se=jQuery,be={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"]},we={},Ae=function(e){Object.assign(we,e.ui)},ke=[],Ce=!0,Ee={},Pe=null,Ge=null,Ne=function(e){Ge=e,ke=[0,"ClosePath"];Se.each(["Moveto","Lineto","CurvetoCubic","CurvetoQuadratic","Arc","LinetoHorizontal","LinetoVertical","CurvetoCubicSmooth","CurvetoQuadraticSmooth"],function(e,t){ke.push(t+"Abs"),ke.push(t+"Rel")})},Ie=function(e,t,r){var n=e.pathSegList;if(P)n.insertItemBefore(t,r);else{for(var i=n.numberOfItems,a=[],s=0;s0?(m=g element");this.elem=t,this.segs=[],this.selected_pts=[],Pe=this,this.init()}return a(e,[{key:"init",value:function(){Se(Me()).find("*").each(function(){Se(this).attr("display","none")});var e=this.elem.pathSegList,t=e.numberOfItems;this.segs=[],this.selected_pts=[],this.first_seg=null;for(var r=0;r=t?null:a[o+1],h=o-1<0?null:a[o-1];if(2===u.type){if(h&&1!==h.type){var c=a[s];c.next=a[s+1],c.next.prev=c,c.addGrip()}s=o}else if(l&&1===l.type)u.next=a[s+1],u.next.prev=u,u.mate=a[s],u.addGrip(),Xt(this.first_seg)&&(this.first_seg=u);else if(l)1!==u.type&&(u.addGrip(),l&&2!==l.type&&(u.next=l,u.next.prev=u));else if(1!==u.type){var d=a[s];d.next=a[s+1],d.next.prev=d,d.addGrip(),u.addGrip(),this.first_seg||(this.first_seg=a[s])}}return this}},{key:"eachSeg",value:function(e){for(var t=this.segs.length,r=0;r=0&&r.selected_pts.push(e)}),this.selected_pts.sort();var n=this.selected_pts.length,i=[];for(i.length=n;n--;){var a=this.selected_pts[n],s=this.segs[a];s.select(!0),i[n]=s.ptgrip}var o=e.subpathIsClosed(this.selected_pts[0]);Ge.addPtsToSelection({grips:i,closedSubpath:o})}}]),e}();ze.subpathIsClosed=function(e){var t=!1;return Pe.eachSeg(function(r){return r<=e||2!==this.type&&(1!==this.type||(t=!0,!1))}),t};var qe,We,Qe,Ye,Ze,Xe=function(e){var t=Ee[e.id];return t||(t=Ee[e.id]=new ze(e)),t},Ke=function(e){e in Ee&&delete Ee[e]},$e=function(e,t){var r=e-Qe,n=t-Ye,i=Math.sqrt(r*r+n*n),a=Math.atan2(n,r)+Ze;return r=i*Math.cos(a)+Qe,n=i*Math.sin(a)+Ye,r-=qe,n-=We,i=Math.sqrt(r*r+n*n),a=Math.atan2(n,r)-Ze,{x:i*Math.cos(a)+qe,y:i*Math.sin(a)+We}},Je=function(){var e=Pe.elem;if(Ze=Dt(e,!0)){var t=Pe.oldbbox;Qe=t.x+t.width/2,Ye=t.y+t.height/2;var r=Tt(e);qe=r.x+r.width/2,We=r.y+r.height/2;var n=qe-Qe,i=We-Ye,a=Math.sqrt(n*n+i*i),s=Math.atan2(i,n)+Ze;qe=a*Math.cos(s)+Qe,We=a*Math.sin(s)+Ye;for(var o=e.pathSegList,u=o.numberOfItems;u;){u-=1;var l=o.getItem(u),h=l.pathSegType;if(1!==h){var c=$e(l.x,l.y),d=[c.x,c.y];if(!Xt(l.x1)&&!Xt(l.x2)){var m=$e(l.x1,l.y1),f=$e(l.x2,l.y2);d.splice(d.length,0,m.x,m.y,f.x,f.y)}He(h,u,d)}}Tt(e);var g=Ge.getSVGRoot().createSVGTransform(),p=Q(e);g.setRotate(180*Ze/Math.PI,qe,We),p.replaceItem(g,0)}},et=[0,"z","M","m","L","l","C","c","Q","q","A","a","H","h","V","v","S","s","T","t"],tt=function(e,t){for(var r=e.pathSegList,n=r.numberOfItems,i=0,a=0,s="",o=null,u=0;u=k-b&&g<=k+b&&p>=C-b&&p<=C+b){w=!0;break}}i=Ge.getId(),Ke(i);var E,P,G=qt(i),N=_.numberOfItems;if(w){if(S<=1&&N>=2){var I=_.getItem(0).x,T=_.getItem(0).y;E=4===(P=y.pathSegList.getItem(1)).pathSegType?x.createSVGPathSegLinetoAbs(I,T):x.createSVGPathSegCurvetoCubicAbs(I,T,P.x1/m,P.y1/m,I,T);var L=x.createSVGPathSegClosePath();_.appendItem(E),_.appendItem(L)}else if(N<3)return!1;if(Se(y).remove(),Ge.setDrawnPath(null),Ge.setStarted(!1),at){Pe.matrix&&Ge.remapElement(G,{},Pe.matrix.inverse());var V=G.getAttribute("d"),O=Se(Pe.elem).attr("d");return Se(Pe.elem).attr("d",O+V),Se(G).remove(),Pe.matrix&&Je(),Ne(),ut.toEditMode(Pe.elem),Pe.selectPt(),!1}}else{if(!Se.contains(Ge.getContainer(),Ge.getMouseTarget(e)))return!1;var M=x.pathSegList.numberOfItems,R=x.pathSegList.getItem(M-1),B=R.x,U=R.y;if(e.shiftKey){var H=xe(B,U,g,p);g=H.x,p=H.y}E=4===(P=y.pathSegList.getItem(1)).pathSegType?x.createSVGPathSegLinetoAbs(Ge.round(g),Ge.round(p)):x.createSVGPathSegCurvetoCubicAbs(Ge.round(g),Ge.round(p),P.x1/m,P.y1/m,P.x2/m,P.y2/m),x.pathSegList.appendItem(E),g*=m,p*=m,y.setAttribute("d",["M",g,p,g,p].join(" ")),v=M,at&&(v+=Pe.segs.length),Oe(v,g,p)}}else{var j="M"+g+","+p+" ";Ge.setDrawnPath(Ge.addSVGElementFromJson({element:"path",curStyles:!0,attr:{d:j,id:Ge.getNextId(),opacity:Ge.getOpacity()/2}})),y.setAttribute("d",["M",c,d,c,d].join(" ")),v=at?Pe.segs.length:0,Oe(v,c,d)}}},mouseMove:function(e,t){var r=Ge.getCurrentZoom();ot=!0;var n=Ge.getDrawnPath();if("path"!==Ge.getCurrentMode())if(Pe.dragging){var i=Ve({x:Pe.dragging[0],y:Pe.dragging[1]},Pe),a=Ve({x:e,y:t},Pe),s=a.x-i.x,o=a.y-i.y;Pe.dragging=[e,t],Pe.dragctrl?Pe.moveCtrl(s,o):Pe.movePts(s,o)}else Pe.selected_pts=[],Pe.eachSeg(function(e){if(this.next||this.prev){var t=Ge.getRubberBox().getBBox(),r=Le(this),n={x:r.x,y:r.y,width:0,height:0},i=_e(t,n);this.select(i),i&&Pe.selected_pts.push(this.index)}});else{if(!n)return;var u=n.pathSegList,l=u.numberOfItems-1;if(nt){var h=Re("1c1"),c=Re("0c2");h.setAttribute("cx",e),h.setAttribute("cy",t),h.setAttribute("display","inline");var d=nt[0],m=nt[1],f=d+(d-e/r),g=m+(m-t/r);c.setAttribute("cx",f*r),c.setAttribute("cy",g*r),c.setAttribute("display","inline");var p=Be(1);if(Wt(p,{x1:e,y1:t,x2:f*r,y2:g*r,display:"inline"}),0===l)it=[e,t];else{var y=u.getItem(l-1),v=y.x,x=y.y;6===y.pathSegType?(v+=v-y.x2,x+=x-y.y2):it&&(v=it[0]/r,x=it[1]/r),He(6,l,[d,m,v,x,f,g],n)}}else{var _=qt("path_stretch_line");if(_){var S=u.getItem(l);if(6===S.pathSegType){var b=S.x+(S.x-S.x2),w=S.y+(S.y-S.y2);He(6,1,[e,t,b*r,w*r,e,t],_)}else it?He(6,1,[e,t,it[0],it[1],e,t],_):He(4,1,[e,t],_)}}}},mouseUp:function(e,t,r,n){var i=Ge.getDrawnPath();if("path"===Ge.getCurrentMode())return nt=null,i||(t=qt(Ge.getId()),Ge.setStarted(!1),it=null),{keep:!0,element:t};var a=Ge.getRubberBox();if(Pe.dragging){var s=Pe.cur_pt;Pe.dragging=!1,Pe.dragctrl=!1,Pe.update(),ot&&Pe.endChanges("Move path point(s)"),e.shiftKey||ot||Pe.selectPt(s)}else a&&"none"!==a.getAttribute("display")?(a.setAttribute("display","none"),a.getAttribute("width")<=2&&a.getAttribute("height")<=2&&ut.toSelectMode(e.target)):ut.toSelectMode(e.target);ot=!1},toEditMode:function(e){Pe=Xe(e),Ge.setCurrentMode("pathedit"),Ge.clearSelection(),Pe.show(!0).update(),Pe.oldbbox=Tt(Pe.elem),at=!1},toSelectMode:function(e){var t=e===Pe.elem;Ge.setCurrentMode("select"),Pe.show(!1),st=!1,Ge.clearSelection(),Pe.matrix&&Je(),t&&(Ge.call("selected",[e]),Ge.addToSelection([e],!0))},addSubPath:function(e){e?(Ge.setCurrentMode("path"),at=!0):(ut.clear(!0),ut.toEditMode(Pe.elem))},select:function(e){st===e?(ut.toEditMode(e),Ge.setCurrentMode("pathedit")):st=e},reorient:function(){var e=Ge.getSelectedElements()[0];if(e&&0!==Dt(e)){var t=new ue("Reorient path"),r={d:e.getAttribute("d"),transform:e.getAttribute("transform")};t.addSubCommand(new oe(e,r)),Ge.clearSelection(),this.resetOrientation(e),Ge.addCommandToHistory(t),Xe(e).show(!1).matrix=null,this.clear(),Ge.addToSelection([e],!0),Ge.call("changed",Ge.getSelectedElements())}},clear:function(e){var t=Ge.getDrawnPath();if(st=null,t){var r=qt(Ge.getId());Se(qt("path_stretch_line")).remove(),Se(r).remove(),Se(qt("pathpointgrip_container")).find("*").attr("display","none"),it=null,Ge.setDrawnPath(null),Ge.setStarted(!1)}else"pathedit"===Ge.getCurrentMode()&&this.toSelectMode();Pe&&Pe.init().show(!1)},resetOrientation:function(e){if(Xt(e)||"path"!==e.nodeName)return!1;var t=Q(e),r=ye(t).matrix;t.clear(),e.removeAttribute("transform");for(var n=e.pathSegList,i=n.numberOfItems,a=function(t){var i=n.getItem(t),a=i.pathSegType;if(1===a)return"continue";var s=[];Se.each(["",1,2],function(e,t){var n=i["x"+t],a=i["y"+t];if(void 0!==n&&void 0!==a){var o=de(n,a,r);s.splice(s.length,0,o.x,o.y)}}),He(a,t,s,e)},s=0;s0){var o=t.getItem(r-1).pathSegType;if(2===o){n(r-1,1),e();break}if(1===o&&t.numberOfItems-1===r){n(r,1),e();break}}}return!1}(),Pe.elem.pathSegList.numberOfItems<=1)return ut.toSelectMode(Pe.elem),void Ge.canvas.deleteSelectedElements();if(Pe.init(),Pe.clearSelection(),window.opera){var n=Se(Pe.elem);n.attr("d",n.attr("d"))}Pe.endChanges("Delete path node(s)")}},smoothPolylineIntoPath:function(e){var t,r=e.points,n=r.numberOfItems;if(n>=4){var i=r.getItem(0),a=null,s=[];for(s.push(["M",i.x,",",i.y," C"].join("")),t=1;t<=n-4;t+=3){var o=r.getItem(t),u=r.getItem(t+1),l=r.getItem(t+2);if(a){var h=Fe(a,o,i);if(h&&2===h.length){var c=s[s.length-1].split(",");c[2]=h[0].x,c[3]=h[0].y,s[s.length-1]=c.join(","),o=h[1]}}s.push([o.x,o.y,u.x,u.y,l.x,l.y].join(",")),i=l,a=u}for(s.push("L");t)/,"$1$2")},yt=function(e){return e.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")};function vt(e){if(e=St(e),window.btoa)return window.btoa(e);var t=new Array(4*Math.floor((e.length+2)/3)),r=0,n=0;do{var i=e.charCodeAt(r++),a=e.charCodeAt(r++),s=e.charCodeAt(r++),o=i>>2,u=(3&i)<<4|a>>4,l=(15&a)<<2|s>>6,h=63&s;isNaN(a)?(l=64,h=64):isNaN(s)&&(h=64),t[n++]=ht.charAt(o),t[n++]=ht.charAt(u),t[n++]=ht.charAt(l),t[n++]=ht.charAt(h)}while(r>4,u=(15&i)<<4|a>>2,l=(3&a)<<6|s;t+=String.fromCharCode(o),64!==a&&(t+=String.fromCharCode(u)),64!==s&&(t+=String.fromCharCode(l))}while(rSVG-edit "],{type:"text/html"});wt(e)}(),function(e){var t,r;e.includes("0?t=t[0]:(t=e.ownerDocument.createElementNS(f.SVG,"defs"),e.firstChild?e.insertBefore(t,e.firstChild.nextSibling):e.append(t)),t},Nt=function(e){for(var t=e.pathSegList,r=t.numberOfItems,n=[[],[]],i=t.getItem(0),a=[i.x,i.y],s=function(e,t,r,n){return function(i){return 1-Math.pow(i,3)*a[e]+3-Math.pow(i,2)*i*t[e]+3*(1-i)*Math.pow(i,2)*r[e]+Math.pow(i,3)*n[e]}},o=0;o0&&v<1&&n[d].push(m(v));var x=(-f-Math.sqrt(y))/(2*g);x>0&&x<1&&n[d].push(m(x))}}else{if(0===f)continue;var _=-p/f;_>0&&_<1&&n[d].push(m(_))}}a=c}else n[0].push(u.x),n[1].push(u.y)}var S=Math.min.apply(null,n[0]),b=Math.max.apply(null,n[0])-S,w=Math.min.apply(null,n[1]);return{x:S,y:w,width:b,height:Math.max.apply(null,n[1])-w}};function It(e){if(U())try{return e.getBBox()}catch(e){}var t,r,n=lt.data(e,"ref"),i=null;n?(r=lt(n).children().clone().attr("visibility","hidden"),lt(gt).append(r),i=r.filter("line, path")):i=lt(e).find("line, path");var a=!1;if(i.length)if(i.each(function(){var e=this.getBBox();e.width&&e.height||(a=!0)}),a){var s=n?r:lt(e).children();t=Ut(s)}else t=e.getBBox();else t=e.getBBox();return n&&r.remove(),t}var Tt=function(e){var t=e||dt.geSelectedElements()[0];if(1!==e.nodeType)return null;var r,n=t.nodeName,i=null;switch(n){case"text":""===t.textContent?(t.textContent="a",i=t.getBBox(),t.textContent=""):t.getBBox&&(i=t.getBBox());break;case"path":N?t.getBBox&&(i=t.getBBox()):i=Nt(t);break;case"g":case"a":i=It(t);break;default:if("use"===n&&(i=It(t)),"use"===n||"foreignObject"===n&&O()){if(i||(i=t.getBBox()),!O()){var a={};a.width=i.width,a.height=i.height,a.x=i.x+parseFloat(t.getAttribute("x")||0),a.y=i.y+parseFloat(t.getAttribute("y")||0),i=a}}else if(ct.includes(n))if(t)try{i=t.getBBox()}catch(e){var s=t.getExtentOfChar(0),o=t.getComputedTextLength();i={x:s.x,y:s.y,width:o,height:s.height}}else{var u=lt(t).closest("foreignObject");u.length&&u[0].getBBox&&(i=u[0].getBBox())}}return i&&(i={x:(r=i).x,y:r.y,width:r.width,height:r.height}),i},Lt=function(e){var t="";return lt.each(e,function(e,r){var n=h(r,2),i=n[0],a=n[1];t+=i;for(var s=0;s-.001&&r<.001||r<-89.99||r>89.99)}(a,s)){if(["ellipse","path","line","polyline","polygon"].includes(e.tagName))n=o=Mt(e,t,r);else if("rect"===e.tagName){var u=e.getAttribute("rx"),l=e.getAttribute("ry");(u||l)&&(n=o=Mt(e,t,r))}}if(!o){var h=ye(i).matrix;n=pe(n.x,n.y,n.width,n.height,h).aabox}}return n};function Bt(e){var t=e.getAttribute("stroke-width");return isNaN(t)||"none"===e.getAttribute("stroke")?0:t/2}var Ut=function(e,t,r){if(!e||!e.length)return!1;var n;if(lt.each(e,function(){n||this.parentNode&&(n=Rt(this,t,r))}),void 0===n)return null;var i=n.x+n.width,a=n.y+n.height,s=n.x,o=n.y;if(1===e.length){var u=Bt(e[0]);s-=u,o-=u,i+=u,a+=u}else lt.each(e,function(e,n){var u=Rt(n,t,r);if(u){var l=Bt(n);s=Math.min(s,u.x-l),o=Math.min(o,u.y-l),1===n.nodeType&&(i=Math.max(i,u.x+u.width+l),a=Math.max(a,u.y+u.height+l))}});return n.x=s,n.y=o,n.width=i-s,n.height=a-o,n},Ht=function(e){e||(e=lt(dt.getSVGContent()).children());var t=[];return lt(e).children().each(function(e,r){r.getBBox&&t.push(r)}),t.reverse()},jt=function(e){return e||(e=Ht()),Ut(e,dt.addSVGElementFromJson,dt.pathActions)},Ft=function(e,t){if(!e)return 0;for(var r=e.numberOfItems,n=0;n=0&&e<=1&&this.group_.setAttribute("opacity",e)}},{key:"appendChildren",value:function(e){for(var t=0;t element");this.svgElem_=t,this.obj_num=0,this.idPrefix=r||"svg_",this.releasedNums=[],this.all_layers=[],this.layer_map={},this.current_layer=null,this.nonce_="";var i=this.svgElem_.getAttributeNS(f.SE,"nonce");i&&ir!==nr.NEVER_RANDOMIZE?this.nonce_=i:ir===nr.ALWAYS_RANDOMIZE&&this.setNonce(Math.floor(100001*Math.random()))}return a(e,[{key:"getElem_",value:function(e){return this.svgElem_.querySelector?this.svgElem_.querySelector("#"+e):tr(this.svgElem_).find("[id="+e+"]")[0]}},{key:"getSvgElem",value:function(){return this.svgElem_}},{key:"getNonce",value:function(){return this.nonce_}},{key:"setNonce",value:function(e){this.svgElem_.setAttributeNS(f.XMLNS,"xmlns:se",f.SE),this.svgElem_.setAttributeNS(f.SE,"se:nonce",e),this.nonce_=e}},{key:"clearNonce",value:function(){this.nonce_=""}},{key:"getId",value:function(){return this.nonce_?this.idPrefix+this.nonce_+"_"+this.obj_num:this.idPrefix+this.obj_num}},{key:"getNextId",value:function(){var e=this.obj_num,t=!1;this.releasedNums.length>0?(this.obj_num=this.releasedNums.pop(),t=!0):this.obj_num++;for(var r=this.getId();this.getElem_(r);)t&&(this.obj_num=e,t=!1),this.obj_num++,r=this.getId();return t&&(this.obj_num=e),r}},{key:"releaseId",value:function(e){var t=this.idPrefix+(this.nonce_?this.nonce_+"_":"");if("string"!=typeof e||!e.startsWith(t))return!1;var r=parseInt(e.substr(t.length));return!("number"!=typeof r||r<=0||this.releasedNums.includes(r))&&(this.releasedNums.push(r),!0)}},{key:"getNumLayers",value:function(){return this.all_layers.length}},{key:"hasLayer",value:function(e){return void 0!==this.layer_map[e]}},{key:"getLayerName",value:function(e){return e>=0&&e=r)return null;for(t=0;tt?e0){var o=this.current_layer.getName();this.current_layer=this.all_layers[s-1],this.all_layers.splice(s,1),delete this.layer_map[o]}e.endBatchCommand()}}},{key:"mergeAllLayers",value:function(e){for(this.current_layer=this.all_layers[this.all_layers.length-1],e.startBatchCommand("Merge all Layers");this.all_layers.length>1;)this.mergeLayer(e);e.endBatchCommand()}},{key:"setCurrentLayer",value:function(e){var t=this.layer_map[e];return!!t&&(this.current_layer&&this.current_layer.deactivate(),this.current_layer=t,this.current_layer.activate(),!0)}},{key:"deleteCurrentLayer",value:function(){if(this.current_layer&&this.getNumLayers()>1){var e=this.current_layer.removeGroup();return this.identifyLayers(),e}return null}},{key:"identifyLayers",value:function(){this.all_layers=[],this.layer_map={};for(var e,t=this.svgElem_.childNodes.length,r=[],n=[],i=null,a=!1,s=0;s0||!a?((i=new $t(or(n),null,this.svgElem_)).appendChildren(r),this.all_layers.push(i),this.layer_map[name]=i):i.activate(),this.current_layer=i}},{key:"createLayer",value:function(e,t){this.current_layer&&this.current_layer.deactivate(),(null==e||""===e||this.layer_map[e])&&(e=or(Object.keys(this.layer_map)));var r=new $t(e,null,this.svgElem_);return t&&(t.startBatchCommand("Create Layer"),t.insertElement(r.getGroup()),t.endBatchCommand()),this.all_layers.push(r),this.layer_map[e]=r,this.current_layer=r,r.getGroup()}},{key:"cloneLayer",value:function(e,t){var r=this;if(!this.current_layer)return null;this.current_layer.deactivate(),(null==e||""===e||this.layer_map[e])&&(e=or(Object.keys(this.layer_map)));var n=this.current_layer.getGroup(),i=new $t(e,n,this.svgElem_),a=i.getGroup();c(n.childNodes).forEach(function(e){"title"!==e.localName&&a.append(r.copyElem(e))}),t&&(t.startBatchCommand("Duplicate Layer"),t.insertElement(a),t.endBatchCommand());var s=this.all_layers.indexOf(this.current_layer);return s>=0?this.all_layers.splice(s+1,0,i):this.all_layers.push(i),this.layer_map[e]=i,this.current_layer=i,a}},{key:"getLayerVisibility",value:function(e){var t=this.layer_map[e];return!!t&&t.isVisible()}},{key:"setLayerVisibility",value:function(e,t){if("boolean"!=typeof t)return null;var r=this.layer_map[e];return r?(r.setVisible(t),r.getGroup()):null}},{key:"getLayerOpacity",value:function(e){var t=this.layer_map[e];return t?t.getOpacity():null}},{key:"setLayerOpacity",value:function(e,t){if(!("number"!=typeof t||t<0||t>1)){var r=this.layer_map[e];r&&r.setOpacity(t)}}},{key:"copyElem",value:function(e){var t=this;return function e(t,r){var n=document.createElementNS(t.namespaceURI,t.nodeName);if(lt.each(t.attributes,function(e,t){"-moz-math-font-style"!==t.localName&&n.setAttributeNS(t.namespaceURI,t.nodeName,t.value)}),n.removeAttribute("id"),n.id=r(),O()&&"path"===t.nodeName){var i=tt(t);n.setAttribute("d",i)}if(lt.each(t.childNodes,function(t,i){switch(i.nodeType){case 1:n.append(e(i,r));break;case 3:n.textContent=i.nodeValue}}),lt(t).data("gsvg"))lt(n).data("gsvg",n.firstChild);else if(lt(t).data("symbol")){var a=lt(t).data("symbol");lt(n).data("ref",a).data("symbol",a)}else"image"===n.tagName&&Zt(n);return n}(e,function(){return t.getNextId()})}}]),e}(),hr=function(e,t){(ir=!1===e?nr.NEVER_RANDOMIZE:nr.ALWAYS_RANDOMIZE)!==nr.ALWAYS_RANDOMIZE||t.getNonce()?ir===nr.NEVER_RANDOMIZE&&t.getNonce()&&t.clearNonce():t.setNonce(Math.floor(100001*Math.random()))},cr=function(){br(),ur.getCurrentDrawing().identifyLayers()},dr=function(e,t){var r=ur.getCurrentDrawing().createLayer(e,sr(t));ur.clearSelection(),ur.call("changed",[r])},mr=function(e,t){var r=ur.getCurrentDrawing().cloneLayer(e,sr(t));ur.clearSelection(),br(),ur.call("changed",[r])},fr=function(){var e=ur.getCurrentDrawing().getCurrentLayer(),t=e.nextSibling,r=e.parentNode;if(e=ur.getCurrentDrawing().deleteCurrentLayer()){var n=new ue("Delete Layer");return n.addSubCommand(new se(e,t,r)),ur.addCommandToHistory(n),ur.clearSelection(),ur.call("changed",[r]),!0}return!1},gr=function(e){var t=ur.getCurrentDrawing().setCurrentLayer(yt(e));return t&&ur.clearSelection(),t},pr=function(e){var t=ur.getCurrentDrawing(),r=t.getCurrentLayer();if(r&&t.setCurrentLayerName(e,sr()))return ur.call("changed",[r]),!0;return!1},yr=function(e){var t=ur.getCurrentDrawing().setCurrentLayerPosition(e);return!!t&&(ur.addCommandToHistory(new ie(t.currentGroup,t.oldNextSibling,ur.getSVGContent())),!0)},vr=function(e,t){var r=ur.getCurrentDrawing(),n=r.getLayerVisibility(e),i=r.setLayerVisibility(e,t);if(!i)return!1;var a=n?"inline":"none";return ur.addCommandToHistory(new oe(i,{display:a},"Layer Visibility")),i===r.getCurrentLayer()&&(ur.clearSelection(),ur.pathActions.clear()),!0},xr=function(e){var t=ur.getCurrentDrawing().getLayerByName(e);if(!t)return!1;for(var r=new ue("Move Elements to Layer"),n=ur.getSelectedElements(),i=n.length;i--;){var a=n[i];if(a){var s=a.nextSibling,o=a.parentNode;t.append(a),r.addSubCommand(new ie(a,s,o))}}return ur.addCommandToHistory(r),!0},_r=function(e){ur.getCurrentDrawing().mergeLayer(sr(e)),ur.clearSelection(),br(),ur.changeSVGContent()},Sr=function(e){ur.getCurrentDrawing().mergeAllLayers(sr(e)),ur.clearSelection(),br(),ur.changeSVGContent()},br=function(){var e=ar.length;if(e){for(var t=0;t1&&void 0!==arguments[1]?arguments[1]:{};return Array.isArray(e)?Promise.all(e.map(function(e){return Ir(e,t)})):new Promise(function(r,n){var i=document.createElement("script");function a(){n(new Error("Failed to import: ".concat(e))),o()}function s(){r(),o()}var o=function(){i.removeEventListener("error",a),i.removeEventListener("load",s),i.remove(),i.src=""};i.defer="defer",Pr(i,t),i.addEventListener("error",a),i.addEventListener("load",s),i.src=e,document.head.append(i)})}function Tr(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).returnDefault,n=void 0!==r&&r;return Array.isArray(e)?Promise.all(e.map(function(e){return Tr(e,t)})):new Promise(function(r,i){var a="$importModule$"+Math.random().toString(32).slice(2),s=document.createElement("script");function o(){i(new Error("Failed to import: ".concat(e))),l()}function u(){r(window[a]),l()}var l=function(){delete window[a],s.removeEventListener("error",o),s.removeEventListener("load",u),s.remove(),URL.revokeObjectURL(s.src),s.src=""};Pr(s,t),s.defer="defer",s.type="module",s.addEventListener("error",o),s.addEventListener("load",u);var h=function(e){var t=document.createElement("a");return t.setAttribute("href",e),t.cloneNode(!1).href}(e),c="import * as m from '".concat(h.replace(/'/g,"\\'"),"'; window.").concat(a," = ").concat(n?"m.default || ":"","m;"),d=new Blob([c],{type:"text/javascript"});s.src=URL.createObjectURL(d),document.head.append(s)})}var Lr,Vr,Or,Mr,Rr=jQuery,Br=[0,"z","M","m","L","l","C","c","Q","q","A","a","H","h","V","v","S","s","T","t"],Ur=null,Hr=function(e,t,r){for(var n=function(e,t){return de(e,t,r)},i=function(e){return r.a*e},a=function(e){return r.d*e},s=Ur.getGridSnapping()&&"svg"===e.parentNode.parentNode.localName,o=function(){s&&Object.entries(t).forEach(function(e){var r=h(e,2),n=r[0],i=r[1];t[n]=Yt(i)}),Wt(e,t,1e3,!0)},u=Tt(e),l=0;l<2;l++){var c=0===l?"fill":"stroke",d=e.getAttribute(c);if(d&&d.startsWith("url(")&&(r.a<0||r.d<0)){var m=zt(d).cloneNode(!0);if(r.a<0){var f=m.getAttribute("x1"),g=m.getAttribute("x2");m.setAttribute("x1",-(f-1)),m.setAttribute("x2",-(g-1))}if(r.d<0){var p=m.getAttribute("y1"),y=m.getAttribute("y2");m.setAttribute("y1",-(p-1)),m.setAttribute("y2",-(y-1))}m.id=Ur.getDrawing().getNextId(),Gt().append(m),e.setAttribute(c,"url(#"+m.id+")")}}var v=e.tagName;if("g"===v||"text"===v||"tspan"===v||"use"===v)if(1!==r.a||0!==r.b||0!==r.c||1!==r.d||0===r.e&&0===r.f){var x=Q(e),_=Ur.getSVGRoot().createSVGTransform();_.setMatrix(fe(ye(x).matrix,r)),x.clear(),x.appendItem(_)}else{var S=ye(e).matrix,b=fe(S.inverse(),r,S);t.x=parseFloat(t.x)+b.e,t.y=parseFloat(t.y)+b.f}switch(v){case"foreignObject":case"rect":case"image":if("image"===v&&(r.a<0||r.d<0)){var w=Q(e),A=Ur.getSVGRoot().createSVGTransform();A.setMatrix(fe(ye(w).matrix,r)),w.clear(),w.appendItem(A)}else{var k=n(t.x,t.y);t.width=i(t.width),t.height=a(t.height),t.x=k.x+Math.min(0,t.width),t.y=k.y+Math.min(0,t.height),t.width=Math.abs(t.width),t.height=Math.abs(t.height)}o();break;case"ellipse":var C=n(t.cx,t.cy);t.cx=C.x,t.cy=C.y,t.rx=i(t.rx),t.ry=a(t.ry),t.rx=Math.abs(t.rx),t.ry=Math.abs(t.ry),o();break;case"circle":var E=n(t.cx,t.cy);t.cx=E.x,t.cy=E.y;var P=pe(u.x,u.y,u.width,u.height,r),G=P.tr.x-P.tl.x,N=P.bl.y-P.tl.y;t.r=Math.min(G/2,N/2),t.r&&(t.r=Math.abs(t.r)),o();break;case"line":var I=n(t.x1,t.y1),T=n(t.x2,t.y2);t.x1=I.x,t.y1=I.y,t.x2=T.x,t.y2=T.y;case"text":case"tspan":case"use":o();break;case"g":var L=Rr(e).data("gsvg");L&&Wt(L,t,1e3,!0);break;case"polyline":case"polygon":for(var V=t.points.length,O=0;O0){for(var i=n.numberOfItems,a=i;i--;){var s=n.getItem(i);if(0===s.type)n.removeItem(i);else if(1===s.type){if(me(s.matrix)){if(1===a)return t.removeAttribute("transform"),null;n.removeItem(i)}}else 4===s.type&&0===s.angle&&n.removeItem(i)}if(1===n.numberOfItems&&Dt(t))return null}if(!n||0===n.numberOfItems)return t.setAttribute("transform",""),t.removeAttribute("transform"),null;if(n){for(var o=[],u=n.numberOfItems;u--;){var l=n.getItem(u);1===l.type?o.push([l.matrix,u]):o.length&&(o=[])}if(2===o.length){var h=r.createSVGTransformFromMatrix(fe(o[1][0],o[0][0]));n.removeItem(o[0][1]),n.removeItem(o[1][1]),n.insertItemBefore(h,o[1][1])}if((u=n.numberOfItems)>=2&&1===n.getItem(u-2).type&&2===n.getItem(u-1).type){var c=r.createSVGTransform(),d=fe(n.getItem(u-2).matrix,n.getItem(u-1).matrix);c.setMatrix(d),n.removeItem(u-2),n.removeItem(u-2),n.appendItem(c)}}switch(t.tagName){case"line":case"polyline":case"polygon":case"path":break;default:if(1===n.numberOfItems&&1===n.getItem(0).type||2===n.numberOfItems&&1===n.getItem(0).type&&4===n.getItem(0).type)return null}var m,g,p=jr(t).data("gsvg"),y=new ue("Transform"),v={},x=null,_=[];switch(t.tagName){case"line":_=["x1","y1","x2","y2"];break;case"circle":_=["cx","cy","r"];break;case"ellipse":_=["cx","cy","rx","ry"];break;case"foreignObject":case"rect":case"image":_=["width","height","x","y"];break;case"use":case"text":case"tspan":_=["x","y"];break;case"polygon":case"polyline":(x={}).points=t.getAttribute("points");var S=t.points,b=S.numberOfItems;v.points=new Array(b);for(var w=0;w1e-10?Math.sin(P)/(1-Math.cos(P)):2/P;for(var G=0;G=3&&3===n.getItem(V-2).type&&2===n.getItem(V-3).type&&2===n.getItem(V-1).type){B=3;for(var U=n.getItem(V-3).matrix,H=n.getItem(V-2).matrix,j=n.getItem(V-1).matrix,F=t.childNodes,D=F.length;D--;){var z=F.item(D);if(M=0,R=0,1===z.nodeType){var q=Q(z);if(!q)continue;var W=ye(q).matrix,Y=Dt(z);L=Lr.getStartTransform();var Z=[];if(Lr.setStartTransform(z.getAttribute("transform")),Y||ge(q)){var X=r.createSVGTransform();X.setMatrix(fe(U,H,j,W)),q.clear(),q.appendItem(X),Z.push(X)}else{var K=fe(W.inverse(),j,W),$=r.createSVGMatrix();$.e=-K.e,$.f=-K.f;var J=fe($.inverse(),W.inverse(),U,H,j,W,K.inverse()),ee=r.createSVGTransform(),re=r.createSVGTransform(),ne=r.createSVGTransform();ee.setTranslate(K.e,K.f),re.setScale(J.a,J.d),ne.setTranslate($.e,$.f),q.appendItem(ne),q.appendItem(re),q.appendItem(ee),Z.push(ne),Z.push(re),Z.push(ee)}y.addSubCommand(e(z)),Lr.setStartTransform(L)}}n.removeItem(V-1),n.removeItem(V-2),n.removeItem(V-3)}else if(V>=3&&1===n.getItem(V-1).type){B=3;var ie=ye(n).matrix,ae=r.createSVGTransform();ae.setMatrix(ie),n.clear(),n.appendItem(ae)}else if((1===V||V>1&&3!==n.getItem(1).type)&&2===n.getItem(0).type){B=2;var se=ye(n).matrix;n.removeItem(0);var le=ye(n).matrix.inverse(),he=fe(le,se);if(M=he.e,R=he.f,0!==M||0!==R){for(var ce=t.childNodes,pe=ce.length,ve=[];pe--;){var xe=ce.item(pe);if(1===xe.nodeType){if(xe.getAttribute("clip-path")){var _e=xe.getAttribute("clip-path");ve.includes(_e)||(Fr(_e,M,R),ve.push(_e))}L=Lr.getStartTransform(),Lr.setStartTransform(xe.getAttribute("transform"));var Se=Q(xe);if(Se){var be=r.createSVGTransform();be.setTranslate(M,R),Se.numberOfItems?Se.insertItemBefore(be,0):Se.appendItem(be),y.addSubCommand(e(xe));for(var we=t.getElementsByTagNameNS(f.SVG,"use"),Ae="#"+xe.id,ke=we.length;ke--;){var Ce=we.item(ke);if(Ae===Et(Ce)){var Ee=r.createSVGTransform();Ee.setTranslate(-M,-R),Q(Ce).insertItemBefore(Ee,0),y.addSubCommand(e(Ce))}}Lr.setStartTransform(L)}}}Lr.setStartTransform(L)}}else{if(1!==V||1!==n.getItem(0).type||C){if(C){var Pe=r.createSVGTransform();Pe.setRotate(C,g.x,g.y),n.numberOfItems?n.insertItemBefore(Pe,0):n.appendItem(Pe)}return 0===n.numberOfItems&&t.removeAttribute("transform"),null}B=1;for(var Ge=n.getItem(0).matrix,Ne=t.childNodes,Ie=Ne.length;Ie--;){var Te=Ne.item(Ie);if(1===Te.nodeType){L=Lr.getStartTransform(),Lr.setStartTransform(Te.getAttribute("transform"));var Le=Q(Te);if(!Le)continue;var Ve=fe(Ge,ye(Le).matrix),Oe=r.createSVGTransform();Oe.setMatrix(Ve),Le.clear(),Le.appendItem(Oe,0),y.addSubCommand(e(Te)),Lr.setStartTransform(L);var Me=Te.getAttribute("stroke-width");if("none"!==Te.getAttribute("stroke")&&!isNaN(Me)){var Re=(Math.abs(Ve.a)+Math.abs(Ve.d))/2;Te.setAttribute("stroke-width",Me*Re)}}}n.clear()}if(2===B){if(C){g={x:m.x+T.e,y:m.y+T.f};var Be=r.createSVGTransform();Be.setRotate(C,g.x,g.y),n.numberOfItems?n.insertItemBefore(Be,0):n.appendItem(Be)}}else if(3===B){var Ue=ye(n).matrix,He=r.createSVGTransform();He.setRotate(C,m.x,m.y);var je=He.matrix,Fe=r.createSVGTransform();Fe.setRotate(C,g.x,g.y);var De=Fe.matrix.inverse(),ze=Ue.inverse(),qe=fe(ze,De,je,Ue);if(M=qe.e,R=qe.f,0!==M||0!==R)for(var We=t.childNodes,Qe=We.length;Qe--;){var Ye=We.item(Qe);if(1===Ye.nodeType){L=Lr.getStartTransform(),Lr.setStartTransform(Ye.getAttribute("transform"));var Ze=Q(Ye),Xe=r.createSVGTransform();Xe.setTranslate(M,R),Ze.numberOfItems?Ze.insertItemBefore(Xe,0):Ze.appendItem(Xe),y.addSubCommand(e(Ye)),Lr.setStartTransform(L)}}C&&(n.numberOfItems?n.insertItemBefore(Fe,0):n.appendItem(Fe))}}else{var Ke,$e=Tt(t);if(!$e&&"path"!==t.tagName)return null;var Je=Dt(t);if(Je){m={x:$e.x+$e.width/2,y:$e.y+$e.height/2},g=de($e.x+$e.width/2,$e.y+$e.height/2,ye(n).matrix);for(var et=Je*Math.PI/180,tt=Math.abs(et)>1e-10?Math.sin(et)/(1-Math.cos(et)):2/et,rt=0;rt=3&&3===n.getItem(st-2).type&&2===n.getItem(st-3).type&&2===n.getItem(st-1).type)at=3,Ke=ye(n,st-3,st-1).matrix,n.removeItem(st-1),n.removeItem(st-2),n.removeItem(st-3);else if(4===st&&1===n.getItem(st-1).type){at=3,Ke=ye(n).matrix;var mt=r.createSVGTransform();mt.setMatrix(Ke),n.clear(),n.appendItem(mt),Ke=r.createSVGMatrix()}else if((1===st||st>1&&3!==n.getItem(1).type)&&2===n.getItem(0).type){at=2;var ft=n.getItem(0).matrix,gt=ye(n,1).matrix,pt=gt.inverse();Ke=fe(pt,ft,gt),n.removeItem(0)}else{if(1!==st||1!==n.getItem(0).type||Je){if(Je){var yt=r.createSVGTransform();yt.setRotate(Je,g.x,g.y),n.numberOfItems?n.insertItemBefore(yt,0):n.appendItem(yt)}return 0===n.numberOfItems&&t.removeAttribute("transform"),null}switch(Ke=ye(n).matrix,t.tagName){case"line":v=jr(t).attr(["x1","y1","x2","y2"]);case"polyline":case"polygon":if(v.points=t.getAttribute("points"),v.points){var vt=t.points,xt=vt.numberOfItems;v.points=new Array(xt);for(var _t=0;_t0;)t.push(t.shift()),r--;Object.values(Mr.selectorGrips).forEach(function(e,r){e.setAttribute("style","cursor:"+t[r]+"-resize")})};var Qr=function(){function t(){n(this,t),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()}return a(t,[{key:"initGroup",value:function(){var e=this;if(this.selectorParentGroup&&this.selectorParentGroup.parentNode&&this.selectorParentGroup.remove(),this.selectorParentGroup=Vr.createSVGElement({element:"g",attr:{id:"selectorParentGroup"}}),this.selectorGripsGroup=Vr.createSVGElement({element:"g",attr:{display:"none"}}),this.selectorParentGroup.append(this.selectorGripsGroup),Vr.svgRoot().append(this.selectorParentGroup),this.selectorMap={},this.selectors=[],this.rubberBandBox=null,Object.keys(this.selectorGrips).forEach(function(t){var r=Vr.createSVGElement({element:"circle",attr:{id:"selectorGrip_resize_"+t,fill:"#22C",r:qr,style:"cursor:"+t+"-resize","stroke-width":2,"pointer-events":"all"}});zr.data(r,"dir",t),zr.data(r,"type","resize"),e.selectorGrips[t]=e.selectorGripsGroup.appendChild(r)}),this.rotateGripConnector=this.selectorGripsGroup.appendChild(Vr.createSVGElement({element:"line",attr:{id:"selectorGrip_rotateconnector",stroke:"#22C","stroke-width":"1"}})),this.rotateGrip=this.selectorGripsGroup.appendChild(Vr.createSVGElement({element:"circle",attr:{id:"selectorGrip_rotate",fill:"lime",r:qr,stroke:"#22C","stroke-width":2,style:"cursor:url("+Or.imgPath+"rotate.png) 12 12, auto;"}})),zr.data(this.rotateGrip,"type","rotate"),!zr("#canvasBackground").length){var t=h(Or.dimensions,2),r=t[0],n=t[1],i=Vr.createSVGElement({element:"svg",attr:{id:"canvasBackground",width:r,height:n,x:0,y:0,overflow:O()?"none":"visible",style:"pointer-events:none"}}),a=Vr.createSVGElement({element:"rect",attr:{width:"100%",height:"100%",x:0,y:0,"stroke-width":1,stroke:"#000",fill:"#FFF",style:"pointer-events:none"}});i.append(a),Vr.svgRoot().insertBefore(i,Vr.svgContent())}}},{key:"requestSelector",value:function(t,r){if(Xt(t))return null;var n=this.selectors.length;if("object"===e(this.selectorMap[t.id]))return this.selectorMap[t.id].locked=!0,this.selectorMap[t.id];for(var i=0;i').documentElement,!0);i.append(d);var m=l.createElementNS(f.SVG,"svg");(u.clearSvgContentElement=function(){Yr(m).empty(),Yr(m).attr({id:"svgcontent",width:o[0],height:o[1],x:o[0],y:o[1],overflow:s.show_outside_canvas?"visible":"hidden",xmlns:f.SVG,"xmlns:se":f.SE,"xmlns:xlink":f.XLINK}).appendTo(d);var e=l.createComment(" Created with SVG-edit - https://github.com/SVG-Edit/svgedit");m.append(e)})();var p="svg_";u.setIdPrefix=function(e){p=e},u.current_drawing_=new lr(m,p);var y=u.getCurrentDrawing=function(){return u.current_drawing_},v=1,x=null,_={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}};_.text=Yr.extend(!0,{},_.shape),Yr.extend(_.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});var S=_.shape,b=[],w=this.getJsonFromSvgElement=function(e){if(3===e.nodeType)return e.nodeValue;for(var t,r={element:e.tagName,attr:{},children:[]},n=0;t=e.attributes[n];n++)r.attr[t.name]=t.value;for(var i,a=0;i=e.childNodes[a];a++)r.children[a]=w(i);return r},A=this.addSVGElementFromJson=function(e){if("string"==typeof e)return l.createTextNode(e);var t=qt(e.attr.id),r=y().getCurrentLayer();if(t&&e.element!==t.tagName&&(t.remove(),t=null),!t){var n=e.namespace||f.SVG;t=l.createElementNS(n,e.element),r&&(x||r).append(t)}return e.curStyles&&Wt(t,{fill:S.fill,stroke:S.stroke,"stroke-width":S.stroke_width,"stroke-dasharray":S.stroke_dasharray,"stroke-linejoin":S.stroke_linejoin,"stroke-linecap":S.stroke_linecap,"stroke-opacity":S.stroke_opacity,"fill-opacity":S.fill_opacity,opacity:S.opacity/2,style:"pointer-events:inherit"},100),Wt(t,e.attr,100),Qt(t),e.children&&e.children.forEach(function(e){t.append(A(e))}),t};u.getTransformList=Q,u.matrixMultiply=fe,u.hasMatrixTransform=ge,u.transformListToTransform=ye;var k=function(){return s.baseUnit};!function(e){D=e;var t=document.createElementNS(f.SVG,"svg");document.body.append(t);var r=document.createElementNS(f.SVG,"rect");r.setAttribute("width","1em"),r.setAttribute("height","1ex"),r.setAttribute("x","1in"),t.append(r);var n=r.getBBox();t.remove();var i=n.x;X={em:n.width,ex:n.height,in:i,cm:i/2.54,mm:i/25.4,pt:i/72,pc:i/6,px:1,"%":0}}({getBaseUnit:k,getElement:qt,getHeight:function(){return m.getAttribute("height")/v},getWidth:function(){return m.getAttribute("width")/v},getRoundDigits:function(){return we.round_digits}}),u.convertToNum=te;var C,E=function(){return m},P=this.getSelectedElems=function(){return b},N=ut,I=function(){return d};dt=C={pathActions:N,getSVGContent:E,addSVGElementFromJson:A,getSelectedElements:P,getDOMDocument:function(){return l},getDOMContainer:function(){return i},getSVGRoot:I,getBaseUnit:k,getSnappingStep:function(){return s.snappingStep}},mt=C.getDOMDocument(),ft=C.getDOMContainer(),gt=C.getSVGRoot(),u.findDefs=Gt,u.getUrlFromAttr=Ct,u.getHref=Et,u.setHref=Pt,u.getBBox=Tt,u.getRotationAngle=Dt,u.getElem=qt,u.getRefElem=zt,u.assignAttributes=Wt,this.cleanupElement=Qt;var T=function(){return s.gridSnapping};!function(e){Ur=e}({getDrawing:function(){return y()},getSVGRoot:I,getGridSnapping:T}),this.remapElement=Hr,function(e){Lr=e}({getSVGRoot:I,getStartTransform:function(){return Ve},setStartTransform:function(e){Ve=e}}),this.recalculateDimensions=Dr;var L=g();u.sanitizeSvg=Er;var V=u.undoMgr=new en({handleHistoryEvent:function(e,t){var r=tn;if(e===r.BEFORE_UNAPPLY||e===r.BEFORE_APPLY)u.clearSelection();else if(e===r.AFTER_APPLY||e===r.AFTER_UNAPPLY){var n=t.elements();u.pathActions.clear(),ee("changed",n);var i=t.type(),a=e===r.AFTER_APPLY;if(i===Zr.type())(a?t.newParent:t.oldParent)===m&&cr();else if(i===Xr.type()||i===Kr.type())t.parent===m&&cr(),i===Xr.type()?a&&Se(t.elem):a||Se(t.elem),"use"===t.elem.tagName&&rr(t.elem);else if(i===$r.type()){"title"===t.elem.tagName&&t.elem.parentNode.parentNode===m&&cr();var s=a?t.newValues:t.oldValues;s.stdDeviation&&u.setBlurOffsets(t.elem.parentNode,s.stdDeviation)}}}}),U=function(e){u.undoMgr.addCommandToHistory(e)},j=this.getZoom=function(){return v},F=this.round=function(e){return parseInt(e*v)/v};!function(e,t){Or=e,Vr=t,Mr=new Qr}(s,{createSVGElement:function(e){return u.addSVGElementFromJson(e)},svgRoot:function(){return d},svgContent:function(){return m},getCurrentZoom:j});var W=this.selectorManager=Mr,Y=u.getNextId=function(){return y().getNextId()},Z=u.getId=function(){return y().getId()},ee=function(e,t){if(Qe[e])return Qe[e](window,t)},re=this.clearSelection=function(e){b.forEach(function(e){Xt(e)||W.releaseSelector(e)}),b=[],e||ee("selected",b)},ne=this.addToSelection=function(e,t){if(e.length){for(var r=0;r1&&s.showGrips(!1)}}}for(ee("selected",b),t||1===b.length?W.requestSelector(b[0]).showGrips(!0):W.requestSelector(b[0]).showGrips(!1),b.sort(function(e,t){return e&&t&&e.compareDocumentPosition?3-(6&t.compareDocumentPosition(e)):Xt(e)?1:0});Xt(b[0]);)b.shift(0)}},ie=function(){return S.opacity},ae=this.getMouseTarget=function(e){if(Xt(e))return null;var t=e.target;if(t.correspondingUseElement&&(t=t.correspondingUseElement),[f.MATH,f.HTML].includes(t.namespaceURI)&&"svgcanvas"!==t.id)for(;"foreignObject"!==t.nodeName;)if(!(t=t.parentNode))return d;var r=y().getCurrentLayer();if([d,i,m,r].includes(t))return d;if(Yr(t).closest("#selectorParentGroup").length)return W.selectorParentGroup;for(;t.parentNode!==(x||r);)t=t.parentNode;return t};u.pathActions=N,Ne({selectorManager:W,canvas:u,call:ee,resetD:function(e){e.setAttribute("d",N.convertPath(e))},round:F,clearSelection:re,addToSelection:ne,addCommandToHistory:U,remapElement:Hr,addSVGElementFromJson:A,getGridSnapping:T,getOpacity:ie,getSelectedElements:P,getContainer:function(){return i},setStarted:function(e){Le=e},getRubberBox:function(){return Ue},setRubberBox:function(e){return Ue=e},addPtsToSelection:function(e){var t=e.closedSubpath,r=e.grips;N.canDeleteNodes=!0,N.closed_subpath=t,ee("pointsAdded",{closedSubpath:t,grips:r}),ee("selected",r)},endChanges:function(e){var t=e.cmd,r=e.elem;U(t),ee("changed",[r])},getCurrentZoom:j,getId:Z,getNextId:Y,getMouseTarget:ae,getCurrentMode:function(){return Oe},setCurrentMode:function(e){return Oe=e},getDrawnPath:function(){return Bt},setDrawnPath:function(e){return Bt=e},getSVGRoot:I});var se={},oe="a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use",ue=["clip-path","fill","filter","marker-end","marker-mid","marker-start","mask","stroke"],le=Yr.data,ce=document.createElementNS(f.SVG,"animate");Yr(ce).attr({attributeName:"opacity",begin:"indefinite",dur:1,fill:"freeze"}).appendTo(d);var Se=function e(t){var r=Yr(t).attr(ue);Object.values(r).forEach(function(e){if(e&&e.startsWith("url(")){var t=Ct(e).substr(1);qt(t)||(Gt().append(Ie[t]),delete Ie[t])}});var n=t.getElementsByTagName("*");if(n.length)for(var i=0,a=n.length;i0&&4===o.getItem(0).type&&o.removeItem(0),0!==e){var u=de(a,s,ye(o).matrix),l=d.createSVGTransform();l.setRotate(e,u.x,u.y),o.numberOfItems?o.insertItemBefore(l,0):o.appendItem(l)}else 0===o.numberOfItems&&r.removeAttribute("transform");if(!t){var h=r.getAttribute("transform");r.setAttribute("transform",n),Pr("transform",h,b),ee("changed",b)}W.requestSelector(b[0]).resize(),Wr.updateGripCursors(e)};var Ze=this.recalculateAllSelectedDimensions=function(){for(var e=new Jr("none"===Me?"position":"size"),t=b.length;t--;){var r=b[t],n=Dr(r);n&&e.addSubCommand(n)}e.isEmpty()||(U(e),ee("changed",b))},Xe=function(e){console.log([e.a,e.b,e.c,e.d,e.e,e.f])},$e=null,Je=this.selectOnly=function(e,t){re(!0),ne(e,t)};this.removeFromSelection=function(e){if(!Xt(b[0])&&e.length){for(var t=[],r=b.length,n=0;n0&&u.removeFromSelection(E),P.length>0&&u.addToSelection(P);break;case"resize":f=Q(g);var L=ge(f),V=(c=L?st:Tt(g)).x,O=c.y,M=c,R=M.width,B=M.height;if(a=w-rt,o=k-nt,s.gridSnapping&&(a=Yt(a),o=Yt(o),B=Yt(B),R=Yt(R)),h=Dt(g)){var U=Math.sqrt(a*a+o*o),H=Math.atan2(o,a)-h*Math.PI/180;a=U*Math.cos(H),o=U*Math.sin(H)}Me.includes("n")||Me.includes("s")||(o=0),Me.includes("e")||Me.includes("w")||(a=0);var j=0,F=0,D=B?(B+o)/B:1,z=R?(R+a)/R:1;Me.includes("n")&&(D=B?(B-o)/B:1,F=B),Me.includes("w")&&(z=R?(R-a)/R:1,j=R);var q=d.createSVGTransform(),Y=d.createSVGTransform(),X=d.createSVGTransform();if(s.gridSnapping&&(V=Yt(V),j=Yt(j),O=Yt(O),F=Yt(F)),q.setTranslate(-(V+j),-(O+F)),e.shiftKey&&(1===z?z=D:D=z),Y.setScale(z,D),X.setTranslate(V+j,O+F),L){var K=h?1:0;f.replaceItem(q,2+K),f.replaceItem(Y,1+K),f.replaceItem(X,Number(K))}else{var $=f.numberOfItems;f.replaceItem(X,$-3),f.replaceItem(Y,$-2),f.replaceItem(q,$-1)}W.requestSelector(g).resize(),ee("transition",b);break;case"zoom":S*=v,A*=v,Wt(Ue,{x:Math.min(it*v,S),y:Math.min(at*v,A),width:Math.abs(S-it*v),height:Math.abs(A-at*v)},100);break;case"text":Wt(_,{x:w,y:k},1e3);break;case"line":s.gridSnapping&&(w=Yt(w),k=Yt(k));var J=w,te=k;e.shiftKey&&(J=(r=xe(rt,nt,J,te)).x,te=r.y),_.setAttribute("x2",J),_.setAttribute("y2",te);break;case"foreignObject":case"square":case"rect":case"image":var re,ne,ie="square"===Oe||e.shiftKey,ae=Math.abs(w-rt),se=Math.abs(k-nt);ie?(ae=se=Math.max(ae,se),re=rt.8){ot-=.8;var ce=m.createSVGPoint();ce.x=It.x,ce.y=It.y,_.points.appendItem(ce)}ht={x:ct.x,y:ct.y},ct={x:_t.x,y:_t.y},_t={x:St.x,y:St.y};break;case"path":case"pathedit":if(w*=v,k*=v,s.gridSnapping&&(w=Yt(w),k=Yt(k),rt=Yt(rt),nt=Yt(nt)),e.shiftKey){var me,fe,pe=Pe;pe?(me=pe.dragging?pe.dragging[0]:rt,fe=pe.dragging?pe.dragging[1]:nt):(me=rt,fe=nt);var ye=r=xe(me,fe,w,k);w=ye.x,k=ye.y}Ue&&"none"!==Ue.getAttribute("display")&&(S*=v,A*=v,Wt(Ue,{x:Math.min(it*v,S),y:Math.min(at*v,A),width:Math.abs(S-it*v),height:Math.abs(A-at*v)},100)),N.mouseMove(w,k);break;case"textedit":w*=v,k*=v,Ft.mouseMove(y,x);break;case"rotate":n=(c=Tt(g)).x+c.width/2,i=c.y+c.height/2;var _e=ve(g),Se=de(n,i,_e);n=Se.x,i=Se.y,h=(Math.atan2(i-k,n-w)*(180/Math.PI)-90)%360,s.gridSnapping&&(h=Yt(h)),e.shiftKey&&(h=45*Math.round(h/45)),u.setRotationAngle(h<-180?360+h:h,!0),ee("transition",b)}Fe("mouseMove",{event:e,mouse_x:y,mouse_y:x,selected:g})}}).click(function(e){return e.preventDefault(),!1}).dblclick(function(e){var t=e.target.parentNode;if(t!==x){var r=ae(e),n=r.tagName;if("text"===n&&"textedit"!==Oe){var i=de(e.pageX,e.pageY,$e);Ft.select(r,i.x,i.y)}"g"!==n&&"a"!==n||!Dt(r)||(Nr(r),r=b[0],re(!0)),x&&br(),"g"!==t.tagName&&"a"!==t.tagName||t===y().getCurrentLayer()||r===W.selectorParentGroup||wr(r)}}).mouseup(function(e){if(2!==e.button){var t=Be;if(Be=null,Le){var r,n,i=de(e.pageX,e.pageY,$e),a=i.x*v,o=i.y*v,l=a/v,h=o/v,c=qt(Z()),d=!1,m=l,f=h;switch(Le=!1,Oe){case"resize":case"multiselect":Xt(Ue)||(Ue.setAttribute("display","none"),He=[]),Oe="select";case"select":if(!Xt(b[0])){if(Xt(b[1])){var g=b[0];switch(g.tagName){case"g":case"use":case"image":case"foreignObject":break;default:Re.fill=g.getAttribute("fill"),Re.fill_opacity=g.getAttribute("fill-opacity"),Re.stroke=g.getAttribute("stroke"),Re.stroke_opacity=g.getAttribute("stroke-opacity"),Re.stroke_width=g.getAttribute("stroke-width"),Re.stroke_dasharray=g.getAttribute("stroke-dasharray"),Re.stroke_linejoin=g.getAttribute("stroke-linejoin"),Re.stroke_linecap=g.getAttribute("stroke-linecap")}"text"===g.tagName&&(Ce.font_size=g.getAttribute("font-size"),Ce.font_family=g.getAttribute("font-family")),W.requestSelector(g).showGrips(!0)}if(Ze(),m!==it||f!==at)for(var p=b.length,x=0;x=0?k.includes(",",C+1):k.includes(" ",k.indexOf(" ")+1))&&(c=N.smoothPolylineIntoPath(c));break;case"line":r=Yr(c).attr(["x1","x2","y1","y2"]),d=r.x1!==r.x2||r.y1!==r.y2;break;case"foreignObject":case"square":case"rect":case"image":r=Yr(c).attr(["width","height"]),d=r.width||r.height||"image"===Oe;break;case"circle":d="0"!==c.getAttribute("r");break;case"ellipse":r=Yr(c).attr(["rx","ry"]),d=r.rx||r.ry;break;case"fhellipse":tt.maxx-tt.minx>0&&tt.maxy-tt.miny>0&&(c=A({element:"ellipse",curStyles:!0,attr:{cx:(tt.minx+tt.maxx)/2,cy:(tt.miny+tt.maxy)/2,rx:(tt.maxx-tt.minx)/2,ry:(tt.maxy-tt.miny)/2,id:Z()}}),ee("changed",[c]),d=!0);break;case"fhrect":tt.maxx-tt.minx>0&&tt.maxy-tt.miny>0&&(c=A({element:"rect",curStyles:!0,attr:{x:tt.minx,y:tt.miny,width:tt.maxx-tt.minx,height:tt.maxy-tt.miny,id:Z()}}),ee("changed",[c]),d=!0);break;case"text":d=!0,Je([c]),Ft.start(c);break;case"path":c=null,Le=!0;var E=N.mouseUp(e,c,a,o);c=E.element,d=E.keep;break;case"pathedit":d=!0,c=null,N.mouseUp(e);break;case"textedit":d=!1,c=null,Ft.mouseUp(e,a,o);break;case"rotate":d=!0,c=null,Oe="select";var P=u.undoMgr.finishUndoableChange();P.isEmpty()||U(P),Ze(),ee("changed",b)}var G=Fe("mouseUp",{event:e,mouse_x:a,mouse_y:o},!0);if(Yr.each(G,function(e,t){t&&(d=t.keep||d,c=t.element,Le=t.started||Le)}),d||Xt(c)){if(!Xt(c)){u.addedNew=!0;var I,T=.2;if(ce.beginElement&&parseFloat(c.getAttribute("opacity"))!==S.opacity){I=Yr(ce).clone().attr({to:S.opacity,dur:T}).appendTo(c);try{I[0].beginElement()}catch(e){}}else T=0;setTimeout(function(){I&&I.remove(),c.setAttribute("opacity",S.opacity),c.setAttribute("style","pointer-events:inherit"),Qt(c),"path"===Oe?N.toEditMode(c):s.selectNew&&Je([c],!0),U(new Xr(c)),ee("changed",[c])},1e3*T)}}else{for(y().releaseId(Z()),c.remove(),c=null,n=e.target;n&&n.parentNode&&n.parentNode.parentNode&&"g"===n.parentNode.parentNode.tagName;)n=n.parentNode;"path"===Oe&&Bt||!n||!n.parentNode||"selectorParentGroup"===n.parentNode.id||"svgcanvas"===n.id||"svgroot"===n.id||(u.setMode("select"),Je([n],!0))}Ve=null}}}),Yr(i).bind("mousewheel DOMMouseScroll",function(e){if(e.shiftKey){e.preventDefault();var t=e.originalEvent;$e=Yr("#svgcontent g")[0].getScreenCTM().inverse();var r=Yr("#workarea"),n=s.showRulers?16:0,i=de(t.pageX,t.pageY,$e),a=r.width(),o=r.height(),l=a-15-n,h=o-15-n,c=l*$e.a,d=h*$e.d,m=r.offset(),f=m.left+n,g=m.top+n,p=t.wheelDelta?t.wheelDelta:t.detail?-t.detail:0;if(p){var y,x,_=Math.max(.75,Math.min(4/3,p));_>1?(y=Math.ceil(l/c*_*100)/100,x=Math.ceil(h/d*_*100)/100):(y=Math.floor(l/c*_*100)/100,x=Math.floor(h/d*_*100)/100);var S=Math.min(y,x);if((S=Math.min(10,Math.max(.01,S)))!==v){_=S/v;var b=de(f,g,$e),w={x:(i.x-(i.x-b.x)/_)*S-n+a/2,y:(i.y-(i.y-b.y)/_)*S-n+o/2};u.setZoom(S),Yr("#zoom").val((100*S).toFixed(1)),ee("updateCanvas",{center:!1,newCtr:w}),ee("zoomDone")}}}});var Ut,Ft=u.textActions=function(){var e,t,r,n,i,a,s,o,l,h,c=[];function m(e){var s=""===t.value;if(Yr(t).focus(),!arguments.length)if(s)e=0;else{if(t.selectionEnd!==t.selectionStart)return;e=t.selectionEnd}var o=c[e];s||t.setSelectionRange(e,e),(r=qt("text_cursor"))||(r=document.createElementNS(f.SVG,"line"),Wt(r,{id:"text_cursor",stroke:"#333","stroke-width":1}),r=qt("selectorParentGroup").appendChild(r)),i||(i=setInterval(function(){var e="none"===r.getAttribute("display");r.setAttribute("display",e?"inline":"none")},600));var u=S(o.x,a.y),l=S(o.x,a.y+a.height);Wt(r,{x1:u.x,y1:u.y,x2:l.x,y2:l.y,visibility:"visible",display:"inline"}),n&&n.setAttribute("d","")}function g(e,i,s){if(e!==i){s||t.setSelectionRange(e,i),(n=qt("text_selectblock"))||(n=document.createElementNS(f.SVG,"path"),Wt(n,{id:"text_selectblock",fill:"green",opacity:.5,style:"pointer-events:none"}),qt("selectorParentGroup").append(n));var o=c[e],u=c[i];r.setAttribute("visibility","hidden");var l=S(o.x,a.y),h=S(o.x+(u.x-o.x),a.y),d=S(o.x,a.y+a.height),g=S(o.x+(u.x-o.x),a.y+a.height),p="M"+l.x+","+l.y+" L"+h.x+","+h.y+" "+g.x+","+g.y+" "+d.x+","+d.y+"z";Wt(n,{d:p,display:"inline"})}else m(i)}function p(t,r){var n=d.createSVGPoint();if(n.x=t,n.y=r,1===c.length)return 0;var i=e.getCharNumAtPosition(n);i<0?(i=c.length-2,t<=c[0].x&&(i=0)):i>=c.length-2&&(i=c.length-2);var a=c[i];return t>a.x+a.width/2&&i++,i}function y(e,t){m(p(e,t))}function x(e,r,n){var i=t.selectionStart,a=p(e,r);g(Math.min(i,a),Math.max(i,a),!n)}function _(e,t){var r={x:e,y:t};if(r.x/=v,r.y/=v,s){var n=de(r.x,r.y,s.inverse());r.x=n.x,r.y=n.y}return r}function S(e,t){var r={x:e,y:t};if(s){var n=de(r.x,r.y,s);r.x=n.x,r.y=n.y}return r.x*=v,r.y*=v,r}function w(t){g(0,e.textContent.length),Yr(this).unbind(t)}function A(t){if(h&&e){var r=de(t.pageX,t.pageY,$e),n=_(r.x*v,r.y*v),i=p(n.x,n.y),a=e.textContent,s=a.substr(0,i).replace(/[a-z0-9]+$/i,"").length,o=a.substr(i).match(/^[a-z0-9]+/i);g(s,(o?o[0].length:0)+i),Yr(t.target).click(w),setTimeout(function(){Yr(t.target).unbind("click",w)},300)}}return{select:function(t,r,n){e=t,Ft.toEditMode(r,n)},start:function(t){e=t,Ft.toEditMode()},mouseDown:function(e,r,n,i){var a=_(n,i);t.focus(),y(a.x,a.y),o=n,l=i},mouseMove:function(e,t){var r=_(e,t);x(r.x,r.y)},mouseUp:function(t,r,n){var i=_(r,n);x(i.x,i.y,!0),t.target!==e&&ro-2&&nl-2&&Ft.toSelectMode(!0)},setCursor:m,toEditMode:function(t,r){if(h=!1,Oe="textedit",W.requestSelector(e).showGrips(!1),W.requestSelector(e),Ft.init(),Yr(e).css("cursor","text"),arguments.length){var n=_(t,r);y(n.x,n.y)}else m();setTimeout(function(){h=!0},300)},toSelectMode:function(a){Oe="select",clearInterval(i),i=null,n&&Yr(n).attr("display","none"),r&&Yr(r).attr("visibility","hidden"),Yr(e).css("cursor","move"),a&&(re(),Yr(e).css("cursor","move"),ee("selected",[e]),ne([e],!0)),e&&!e.textContent.length&&u.deleteSelectedElements(),Yr(t).blur(),e=!1},setInputElem:function(e){t=e},clear:function(){"textedit"===Oe&&Ft.toSelectMode()},init:function(r){if(e){var n,i;e.parentNode||(e=b[0],W.requestSelector(e).showGrips(!1));var o=e.textContent.length,l=e.getAttribute("transform");for(a=Tt(e),s=l?ve(e):null,(c=[]).length=o,t.focus(),Yr(e).unbind("dblclick",A).dblclick(A),o||(i={x:a.x+a.width/2,width:0}),n=0;n")[0].getContext("2d")||(r.text=se.exportNoText),Yr.each(r,function(r,i){n.find(r).length&&(t.push(r),e.push(i))}),{issues:e,issueCodes:t}}this.svgCanvasToString=function(){for(;Kt()>0;);N.clear(!0),Yr.each(m.childNodes,function(e,t){e&&8===t.nodeType&&t.data.includes("Created with")&&m.firstChild.before(t)}),x&&(br(),Je([x]));var e=[];Yr(m).find("g:data(gsvg)").each(function(){for(var t=this.attributes,r=t.length,n=0;nt.name?-1:1});for(var u=0;u=0;v--){var x=a[v],_=yt(x.value);if(!y.includes(x.localName)&&""!==_){if(_.startsWith("pointer-events"))continue;if("class"===x.localName&&_.startsWith("se_"))continue;if(r.push(" "),"d"===x.localName&&(_=N.convertPath(e,!0)),isNaN(_)?i.test(_)&&(_=$(_)+n):_=$(_),we.apply&&"image"===e.nodeName&&"href"===x.localName&&we.images&&"embed"===we.images){var S=be[_];S&&(_=S)}x.namespaceURI&&x.namespaceURI!==f.SVG&&!L[x.namespaceURI]||(r.push(x.nodeName),r.push('="'),r.push(_),r.push('"'))}}}if(e.hasChildNodes()){r.push(">"),t++;for(var b=!1,w=0;w");break;case 8:r.push("\n"),r.push(new Array(t+1).join(" ")),r.push("\x3c!--"),r.push(A.data),r.push("--\x3e")}}if(t--,!b){r.push("\n");for(var C=0;C")}else r.push("/>")}return r.join("")},this.embedImage=function(e){return new Promise(function(t,r){Yr(new Image).load(function(n,i,a){if("error"!==i){var s=document.createElement("canvas");s.width=this.width,s.height=this.height,s.getContext("2d").drawImage(this,0,0);try{var o=";svgedit_url="+encodeURIComponent(e);o=s.toDataURL().replace(";base64",o+";base64"),be[e]=o}catch(t){be[e]=!1}Te=e,t(be[e])}else r(new Error("Error loading image: "+a.status+" "+a.statusText))}).attr("src",e)})},this.setGoodImage=function(e){Te=e},this.open=function(){},this.save=function(e){re(),e&&Yr.extend(we,e),we.apply=!0;var t=this.svgCanvasToString();ee("saved",t)},this.rasterExport=(er=r(regeneratorRuntime.mark(function e(t,r,n){var i,a,o,l,h,c,d,m,f,g=arguments;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(i=g.length>3&&void 0!==g[3]?g[3]:{},o="image/"+(a="ICO"===t?"BMP":t||"PNG").toLowerCase(),l=$t(),h=l.issues,c=l.issueCodes,d=this.svgCanvasToString(),Ut){e.next=10;break}return e.next=8,Gr(s.canvgPath+"canvg.js",{global:"canvg"});case 8:m=e.sent,Ut=m.canvg;case 10:return Yr("#export_canvas").length||Yr("",{id:"export_canvas"}).hide().appendTo("body"),(f=Yr("#export_canvas")[0]).width=u.contentW,f.height=u.contentH,e.next=16,Ut(f,d);case 16:return e.abrupt("return",new Promise(function(e,s){var u,l=a.toLowerCase(),m=r?f.toDataURL("image/"+l,r):f.toDataURL("image/"+l);function g(){var a={datauri:m,bloburl:u,svg:d,issues:h,issueCodes:c,type:t,mimeType:o,quality:r,exportWindowName:n};i.avoidEvent||ee("exported",a),e(a)}f.toBlob?f.toBlob(function(e){u=wt(e),g()},o,r):(u=bt(m),g())}));case 17:case"end":return e.stop()}},e,this)})),function(e,t,r){return er.apply(this,arguments)}),this.exportPDF=(Jt=r(regeneratorRuntime.mark(function e(t){var r,n,i,a,o,u,l,h,c,d,m,f=arguments;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r=f.length>1&&void 0!==f[1]?f[1]:B()?"save":void 0,window.jsPDF){e.next=7;break}return e.next=4,Ir(["jspdf/underscore-min.js","jspdf/jspdf.min.js"]);case 4:return n=!("svgEditor"in window&&window.svgEditor&&!1===window.svgEditor.modules),e.next=7,Ir(s.jspdfPath+"jspdf.plugin.svgToPdf.js",{type:n?"module":"text/javascript"});case 7:return i=sr(),a=i.w>i.h?"landscape":"portrait",o=jsPDF({orientation:a,unit:"pt",format:[i.w,i.h]}),u=or(),o.setProperties({title:u}),l=$t(),h=l.issues,c=l.issueCodes,d=this.svgCanvasToString(),o.addSVG(d,0,0),(m={svg:d,issues:h,issueCodes:c,exportWindowName:t,outputType:r=r||"dataurlstring"}).output=o.output(r,"save"===r?t||"svg.pdf":void 0),ee("exportedPDF",m),e.abrupt("return",m);case 21:case"end":return e.stop()}},e,this)})),function(e){return Jt.apply(this,arguments)}),this.getSvgString=function(){return we.apply=!1,this.svgCanvasToString()},this.randomizeIds=function(e){arguments.length>0&&!1===e?hr(!1,y()):hr(!0,y())};var Jt;var er;var tr=this.uniquifyElems=function(e){var t={},r=["filter","linearGradient","pattern","radialGradient","symbol","textPath","use"];for(var n in kt(e,function(e){if(1===e.nodeType){e.id&&(e.id in t||(t[e.id]={elem:null,attrs:[],hrefs:[]}),t[e.id].elem=e),Yr.each(ue,function(r,n){var i=e.getAttributeNode(n);if(i){var a=Ct(i.value),s=a?a.substr(1):null;s&&(s in t||(t[s]={elem:null,attrs:[],hrefs:[]}),t[s].attrs.push(i))}});var n=Et(e);if(n&&r.includes(e.nodeName)){var i=n.substr(1);i&&(i in t||(t[i]={elem:null,attrs:[],hrefs:[]}),t[i].hrefs.push(e))}}}),t)if(n){var i=t[n].elem;if(i){var a=Y();i.id=a;for(var s=t[n].attrs,o=s.length;o--;){var u=s[o];u.ownerElement.setAttribute(u.name,"url(#"+a+")")}for(var l=t[n].hrefs,h=l.length;h--;){var c=l[h];Pt(c,"#"+a)}}}},rr=this.setUseData=function(e){var t=Yr(e);"use"!==e.tagName&&(t=t.find("use")),t.each(function(){var e=Et(this).substr(1),t=qt(e);t&&(Yr(this).data("ref",t),"symbol"!==t.tagName&&"svg"!==t.tagName||Yr(this).data("symbol",t).data("ref",t))})},nr=this.convertGradients=function(e){var t=Yr(e).find("linearGradient, radialGradient");!t.length&&O()&&(t=Yr(e).find("*").filter(function(){return this.tagName.includes("Gradient")})),t.each(function(){if("userSpaceOnUse"===Yr(this).attr("gradientUnits")){var e=Yr(m).find('[fill="url(#'+this.id+')"],[stroke="url(#'+this.id+')"]');if(!e.length)return;var t=Tt(e[0]);if(!t)return;if("linearGradient"===this.tagName){var r=Yr(this).attr(["x1","y1","x2","y2"]),n=this.gradientTransform.baseVal;if(n&&n.numberOfItems>0){var i=ye(n).matrix,a=de(r.x1,r.y1,i),s=de(r.x2,r.y2,i);r.x1=a.x,r.y1=a.y,r.x2=s.x,r.y2=s.y,this.removeAttribute("gradientTransform")}Yr(this).attr({x1:(r.x1-t.x)/t.width,y1:(r.y1-t.y)/t.height,x2:(r.x2-t.x)/t.width,y2:(r.y2-t.y)/t.height}),this.removeAttribute("gradientUnits")}}})},ir=this.convertToGroup=function(e){e||(e=b[0]);var t,r=Yr(e),n=new Jr;if(r.data("gsvg")){var i=e.firstChild,a=Yr(i).attr(["x","y"]);Yr(e.firstChild.firstChild).unwrap(),Yr(e).removeData("gsvg");var s=Q(e),o=d.createSVGTransform();o.setTranslate(a.x,a.y),s.appendItem(o),Dr(e),ee("selected",[e])}else if(r.data("symbol")){e=r.data("symbol"),t=r.attr("transform");var u=r.attr(["x","y"]),h=e.getAttribute("viewBox");if(h){var c=h.split(" ");u.x-=Number(c[0]),u.y-=Number(c[1])}t+=" translate("+(u.x||0)+","+(u.y||0)+")";var g=r.prev();n.addSubCommand(new Kr(r[0],r[0].nextSibling,r[0].parentNode)),r.remove();var p,y=Yr(m).find("use:data(symbol)").length,v=l.createElementNS(f.SVG,"g"),x=e.childNodes;for(p=0;pc?"scale("+v/3/p[3]+")":"scale("+v/3/p[2]+")")+" translate(0)",s=l.createElementNS(f.SVG,"symbol");var _=Gt();for(M()&&Yr(u).find("linearGradient, radialGradient, pattern").appendTo(_);u.firstChild;){var S=u.firstChild;s.append(S)}var b=u.attributes,w=!0,A=!1,k=void 0;try{for(var C,E=b[Symbol.iterator]();!(w=(C=E.next()).done);w=!0){var P=C.value;s.setAttribute(P.nodeName,P.value)}}catch(e){A=!0,k=e}finally{try{w||null==E.return||E.return()}finally{if(A)throw k}}s.id=Y(),ke[i]={symbol:s,xform:r},Gt().append(s),o.addSubCommand(new Xr(s))}(n=l.createElementNS(f.SVG,"use")).id=Y(),Pt(n,"#"+s.id),(x||y().getCurrentLayer()).append(n),o.addSubCommand(new Xr(n)),re(),n.setAttribute("transform",r),Dr(n),Yr(n).data("symbol",s).data("ref",s),ne([n]),U(o),ee("changed",[m])}catch(e){return console.log(e),null}return n};var ar={identifyLayers:cr,createLayer:dr,cloneLayer:mr,deleteCurrentLayer:fr,setCurrentLayer:gr,renameCurrentLayer:pr,setCurrentLayerPosition:yr,setLayerVisibility:vr,moveSelectedToLayer:xr,mergeLayer:_r,mergeAllLayers:Sr,leaveContext:br,setContext:wr};Object.entries(ar).forEach(function(e){var t=h(e,2),r=t[0],n=t[1];u[r]=n}),function(e){ur=e}({pathActions:N,getCurrentGroup:function(){return x},setCurrentGroup:function(e){x=e},getSelectedElements:P,getSVGContent:E,undoMgr:V,elData:le,getCurrentDrawing:y,clearSelection:re,call:ee,addCommandToHistory:U,changeSVGContent:function(){ee("changed",[m])}}),this.clear=function(){N.clear(),re(),u.clearSvgContentElement(),u.current_drawing_=new lr(m),u.createLayer("Layer 1"),u.undoMgr.resetUndoStack(),W.initGroup(),Ue=W.getRubberBandBox(),ee("cleared")},this.linkControlPoints=N.linkControlPoints,this.getContentElem=function(){return m},this.getRootElem=function(){return d};var sr=this.getResolution=function(){return{w:m.getAttribute("width")/v,h:m.getAttribute("height")/v,zoom:v}};this.getSnapToGrid=function(){return s.gridSnapping},this.getVersion=function(){return"svgcanvas.js ($Rev$)"},this.setUiStrings=function(t){Object.assign(se,t.notification),Yr=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{ok:"Ok",cancel:"Cancel"};t("#dialog_container").draggable({cancel:"#dialog_content, #dialog_buttons *",containment:"window"}).css("position","absolute");var n=t("#dialog_box"),i=t("#dialog_buttons"),a=t("#dialog_content");function s(s,o,u,l,h,c){a.html("

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

")+"

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