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;re.length)&&(t=e.length);for(var r=0,n=new Array(t);r=e.length?{done:!0}:{done:!1,value:e[t++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var n,i,a=!0,s=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}} /** * A jQuery module to work with SVG attributes. * @module jQueryAttr * @license MIT */ function p(t){var r=t.fn.attr;return t.fn.attr=function(t,n){var i=this.length;if(!i)return r.call(this,t,n);for(var a=0;at.getTotalLength())break;r--}while(r>0);return r}),window.SVGPathSeg=e,window.SVGPathSegClosePath=t,window.SVGPathSegMovetoAbs=r,window.SVGPathSegMovetoRel=i,window.SVGPathSegLinetoAbs=o,window.SVGPathSegLinetoRel=u,window.SVGPathSegCurvetoCubicAbs=l,window.SVGPathSegCurvetoCubicRel=c,window.SVGPathSegCurvetoQuadraticAbs=d,window.SVGPathSegCurvetoQuadraticRel=m,window.SVGPathSegArcAbs=f,window.SVGPathSegArcRel=g,window.SVGPathSegLinetoHorizontalAbs=p,window.SVGPathSegLinetoHorizontalRel=y,window.SVGPathSegLinetoVerticalAbs=v,window.SVGPathSegLinetoVerticalRel=x,window.SVGPathSegCurvetoCubicSmoothAbs=S,window.SVGPathSegCurvetoCubicSmoothRel=_,window.SVGPathSegCurvetoQuadraticSmoothAbs=b,window.SVGPathSegCurvetoQuadraticSmoothRel=w}if(!("SVGPathSegList"in window)||!("appendItem"in window.SVGPathSegList.prototype)){var A=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}}],[{key:"_pathSegArrayAsString",value:function(e){var t="",r=!0;return e.forEach((function(e){r?(r=!1,t+=e._asPathString()):t+=" "+e._asPathString()})),t}}]),e}();A.prototype.classname="SVGPathSegList",Object.defineProperty(A.prototype,"numberOfItems",{get:function(){return this._checkPathSynchronizedToList(),this._list.length},enumerable:!0}),Object.defineProperties(SVGPathElement.prototype,{pathSegList:{get:function(){return this._pathSegList||(this._pathSegList=new A(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=A}}(); /** * Namespaces or tools therefor. * @module namespaces * @license MIT */ var y,v={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/"},x=function(){var e={};return Object.entries(v).forEach((function(t){var r=c(t,2),n=r[0],i=r[1];e[i]=n.toLowerCase()})),e},S=jQuery,_=(Boolean(document.createElementNS&&document.createElementNS(v.SVG,"svg").createSVGRect),navigator.userAgent),b=document.createElementNS(v.SVG,"svg"),w=Boolean(window.opera),A=_.includes("AppleWebKit"),k=_.includes("Gecko/"),C=_.includes("MSIE"),E=_.includes("Chrome/"),P=(_.includes("Windows"),_.includes("Macintosh"),"ontouchstart"in window),N=Boolean(b.querySelector),G=Boolean(document.evaluate),I=function(){var e=document.createElementNS(v.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}(),T=function(){var e=document.createElementNS(v.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}(),L=function(){var e=document.createElementNS(v.SVG,"svg"),t=document.createElementNS(v.SVG,"svg");document.documentElement.append(e),t.setAttribute("x",5),e.append(t);var r=document.createElementNS(v.SVG,"text");r.textContent="a",t.append(r);try{return 0===r.getStartPositionOfChar(0).x}catch(e){return!1}finally{e.remove()}}(),V=function(){var e=document.createElementNS(v.SVG,"svg");document.documentElement.append(e);var t=document.createElementNS(v.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}(),O=function(){var e=document.createElementNS(v.SVG,"svg");document.documentElement.append(e);var t=document.createElementNS(v.SVG,"path");t.setAttribute("d","M0,0 10,0");var r=document.createElementNS(v.SVG,"path");r.setAttribute("d","M5,0 15,0");var n=document.createElementNS(v.SVG,"g");n.append(t,r),e.append(n);var i=n.getBBox();return e.remove(),15===i.width}(),M=(function(){var e=document.createElementNS(v.SVG,"rect");e.setAttribute("x",.1);var t=!e.cloneNode(!1).getAttribute("x").includes(",");t||S.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.')}(),(y=document.createElementNS(v.SVG,"rect")).setAttribute("style","vector-effect:non-scaling-stroke"),"non-scaling-stroke"===y.style.vectorEffect),R=function(){var t=document.createElementNS(v.SVG,"rect").transform.baseVal,r=b.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}(),B=function(){return A},U=function(){return k},H=function(){return C},j=function(){return E},F=function(){return M},D=document.createElementNS(v.SVG,"svg");function z(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 q,Q={},W=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(ie.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}}]),r}(ae);he.type=he.prototype.type;var ce,de,me,fe,ge,pe=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];$t(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 he("Change "+r),i=t.elements.length;i--;){var a=t.elements[i];if(!$t(a)){var s={};s[r]=t.oldValues[i],s[r]!==a.getAttribute(r)&&n.addSubCommand(new le(a,s,r))}}return this.undoableChangeStack[e]=null,n}}]),e}(),ye=Object.freeze({__proto__:null,HistoryEventTypes:ie,MoveElementCommand:se,InsertElementCommand:oe,RemoveElementCommand:ue,ChangeElementCommand:le,BatchCommand:he,UndoManager:pe}),ve=document.createElementNS(v.SVG,"svg"),xe=function(e,t,r){return{x:r.a*e+r.c*t+r.e,y:r.b*e+r.d*t+r.f}},Se=function(e){return 1===e.a&&0===e.b&&0===e.c&&1===e.d&&0===e.e&&0===e.f},_e=function(){for(var e=arguments.length,t=new Array(e),r=0;r(r=Number.parseInt(r))){var n=r;r=t,t=n}for(var i=ve.createSVGMatrix(),a=t;a<=r;++a){var s=a>=0&&ae.x&&t.ye.y},Pe=jQuery,Ne={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"]},Ge={},Ie=function(e){Object.assign(Ge,e.ui)},Te=[],Le=!0,Ve={},Oe=null,Me=null,Re=function(e){Me=e,Te=[0,"ClosePath"];Pe.each(["Moveto","Lineto","CurvetoCubic","CurvetoQuadratic","Arc","LinetoHorizontal","LinetoVertical","CurvetoCubicSmooth","CurvetoQuadraticSmooth"],(function(e,t){Te.push(t+"Abs"),Te.push(t+"Rel")}))},Be=function(e,t,r){var n=e.pathSegList;if(T)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=[],Oe=this,this.init()}return a(e,[{key:"init",value:function(){Pe(De()).find("*").each((function(){Pe(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(),$t(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]);Me.addPtsToSelection({grips:i,closedSubpath:o})}}],[{key:"subpathIsClosed",value:function(e){var t=!1;return Oe.eachSeg((function(r){return r<=e||2!==this.type&&(1!==this.type||(t=!0,!1))})),t}}]),e}(),$e=function(e){var t=Ve[e.id];return t||(t=Ve[e.id]=new Ze(e)),t},Je=function(e){e in Ve&&delete Ve[e]},et=function(e,t){var r=e-me,n=t-fe,i=Math.sqrt(r*r+n*n),a=Math.atan2(n,r)+ge;return r=i*Math.cos(a)+me,n=i*Math.sin(a)+fe,r-=ce,n-=de,i=Math.sqrt(r*r+n*n),a=Math.atan2(n,r)-ge,{x:i*Math.cos(a)+ce,y:i*Math.sin(a)+de}},tt=function(){var e=Oe.elem;if(ge=qt(e,!0)){var t=Oe.oldbbox;me=t.x+t.width/2,fe=t.y+t.height/2;var r=Vt(e);ce=r.x+r.width/2,de=r.y+r.height/2;var n=ce-me,i=de-fe,a=Math.sqrt(n*n+i*i),s=Math.atan2(i,n)+ge;ce=a*Math.cos(s)+me,de=a*Math.sin(s)+fe;for(var o=e.pathSegList,u=o.numberOfItems;u;){u-=1;var l=o.getItem(u),h=l.pathSegType;if(1!==h){var c=et(l.x,l.y),d=[c.x,c.y];if(!$t(l.x1)&&!$t(l.x2)){var m=et(l.x1,l.y1),f=et(l.x2,l.y2);d.splice(d.length,0,m.x,m.y,f.x,f.y)}We(h,u,d)}}Vt(e);var g=Me.getSVGRoot().createSVGTransform(),p=X(e);g.setRotate(180*ge/Math.PI,ce,de),p.replaceItem(g,0)}},rt=[0,"z","M","m","L","l","C","c","Q","q","A","a","H","h","V","v","S","s","T","t"],nt=function(e,t){for(var r=e.pathSegList,n=r.numberOfItems,i=0,a=0,s="",o=null,u=0;u=A-_&&m<=A+_&&f>=k-_&&f<=k+_){b=!0;break}}i=Me.getId(),Je(i);var C,E,P=Wt(i),N=x.numberOfItems;if(b){if(S<=1&&N>=2){var G=x.getItem(0).x,I=x.getItem(0).y;C=4===(E=g.pathSegList.getItem(1)).pathSegType?y.createSVGPathSegLinetoAbs(G,I):y.createSVGPathSegCurvetoCubicAbs(G,I,E.x1/h,E.y1/h,G,I);var T=y.createSVGPathSegClosePath();x.appendItem(C),x.appendItem(T)}else if(N<3)return!1;if(Pe(g).remove(),Me.setDrawnPath(null),Me.setStarted(!1),ot){Oe.matrix&&Me.remapElement(P,{},Oe.matrix.inverse());var L=P.getAttribute("d"),V=Pe(Oe.elem).attr("d");return Pe(Oe.elem).attr("d",V+L),Pe(P).remove(),Oe.matrix&&tt(),Re(),ht.toEditMode(Oe.elem),Oe.selectPt(),!1}}else{if(!Pe.contains(Me.getContainer(),Me.getMouseTarget(e)))return!1;var O=y.pathSegList.numberOfItems,M=y.pathSegList.getItem(O-1),R=M.x,B=M.y;if(e.shiftKey){var U=Ce(R,B,m,f);m=U.x,f=U.y}C=4===(E=g.pathSegList.getItem(1)).pathSegType?y.createSVGPathSegLinetoAbs(Me.round(m),Me.round(f)):y.createSVGPathSegCurvetoCubicAbs(Me.round(m),Me.round(f),E.x1/h,E.y1/h,E.x2/h,E.y2/h),y.pathSegList.appendItem(C),m*=h,f*=h,g.setAttribute("d",["M",m,f,m,f].join(" ")),p=O,ot&&(p+=Oe.segs.length),Fe(p,m,f)}}else{var H="M"+m+","+f+" ";Me.setDrawnPath(Me.addSVGElementFromJson({element:"path",curStyles:!0,attr:{d:H,id:Me.getNextId(),opacity:Me.getOpacity()/2}})),g.setAttribute("d",["M",c,d,c,d].join(" ")),p=ot?Oe.segs.length:0,Fe(p,c,d)}}},mouseMove:function(e,t){var r=Me.getCurrentZoom();lt=!0;var n=Me.getDrawnPath();if("path"!==Me.getCurrentMode())if(Oe.dragging){var i=je({x:Oe.dragging[0],y:Oe.dragging[1]},Oe),a=je({x:e,y:t},Oe),s=a.x-i.x,o=a.y-i.y;Oe.dragging=[e,t],Oe.dragctrl?Oe.moveCtrl(s,o):Oe.movePts(s,o)}else Oe.selected_pts=[],Oe.eachSeg((function(e){if(this.next||this.prev){var t=Me.getRubberBox().getBBox(),r=He(this),n={x:r.x,y:r.y,width:0,height:0},i=Ee(t,n);this.select(i),i&&Oe.selected_pts.push(this.index)}}));else{if(!n)return;var u=n.pathSegList,l=u.numberOfItems-1;if(at){var h=ze("1c1"),c=ze("0c2");h.setAttribute("cx",e),h.setAttribute("cy",t),h.setAttribute("display","inline");var d=at[0],m=at[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=qe(1);if(Yt(p,{x1:e,y1:t,x2:f*r,y2:g*r,display:"inline"}),0===l)st=[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):st&&(v=st[0]/r,x=st[1]/r),We(6,l,[d,m,v,x,f,g],n)}}else{var S=Wt("path_stretch_line");if(S){var _=u.getItem(l);if(6===_.pathSegType){var b=_.x+(_.x-_.x2),w=_.y+(_.y-_.y2);We(6,1,[e,t,b*r,w*r,e,t],S)}else st?We(6,1,[e,t,st[0],st[1],e,t],S):We(4,1,[e,t],S)}}}},mouseUp:function(e,t,r,n){var i=Me.getDrawnPath();if("path"===Me.getCurrentMode())return at=null,i||(t=Wt(Me.getId()),Me.setStarted(!1),st=null),{keep:!0,element:t};var a=Me.getRubberBox();if(Oe.dragging){var s=Oe.cur_pt;Oe.dragging=!1,Oe.dragctrl=!1,Oe.update(),lt&&Oe.endChanges("Move path point(s)"),e.shiftKey||lt||Oe.selectPt(s)}else a&&"none"!==a.getAttribute("display")?(a.setAttribute("display","none"),a.getAttribute("width")<=2&&a.getAttribute("height")<=2&&ht.toSelectMode(e.target)):ht.toSelectMode(e.target);lt=!1},toEditMode:function(e){Oe=$e(e),Me.setCurrentMode("pathedit"),Me.clearSelection(),Oe.show(!0).update(),Oe.oldbbox=Vt(Oe.elem),ot=!1},toSelectMode:function(e){var t=e===Oe.elem;Me.setCurrentMode("select"),Oe.show(!1),ut=!1,Me.clearSelection(),Oe.matrix&&tt(),t&&(Me.call("selected",[e]),Me.addToSelection([e],!0))},addSubPath:function(e){e?(Me.setCurrentMode("path"),ot=!0):(ht.clear(!0),ht.toEditMode(Oe.elem))},select:function(e){ut===e?(ht.toEditMode(e),Me.setCurrentMode("pathedit")):ut=e},reorient:function(){var e=Me.getSelectedElements()[0];if(e&&0!==qt(e)){var t=new he("Reorient path"),r={d:e.getAttribute("d"),transform:e.getAttribute("transform")};t.addSubCommand(new le(e,r)),Me.clearSelection(),this.resetOrientation(e),Me.addCommandToHistory(t),$e(e).show(!1).matrix=null,this.clear(),Me.addToSelection([e],!0),Me.call("changed",Me.getSelectedElements())}},clear:function(e){var t=Me.getDrawnPath();if(ut=null,t){var r=Wt(Me.getId());Pe(Wt("path_stretch_line")).remove(),Pe(r).remove(),Pe(Wt("pathpointgrip_container")).find("*").attr("display","none"),st=null,Me.setDrawnPath(null),Me.setStarted(!1)}else"pathedit"===Me.getCurrentMode()&&this.toSelectMode();Oe&&Oe.init().show(!1)},resetOrientation:function(e){if($t(e)||"path"!==e.nodeName)return!1;var t=X(e),r=Ae(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=[];Pe.each(["",1,2],(function(e,t){var n=i["x"+t],a=i["y"+t];if(void 0!==n&&void 0!==a){var o=xe(n,a,r);s.splice(s.length,0,o.x,o.y)}})),We(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}(),Oe.elem.pathSegList.numberOfItems<=1)return ht.toSelectMode(Oe.elem),void Me.canvas.deleteSelectedElements();if(Oe.init(),Oe.clearSelection(),window.opera){var n=Pe(Oe.elem);n.attr("d",n.attr("d"))}Oe.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=Xe(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")},xt=function(e){return e.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")};function St(e){if(e=wt(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;Number.isNaN(a)?(l=64,h=64):Number.isNaN(s)&&(h=64),t[n++]=dt.charAt(o),t[n++]=dt.charAt(u),t[n++]=dt.charAt(l),t[n++]=dt.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"});kt(e)}(),function(e){var t,r;e.includes("0?t=t[0]:(t=e.ownerDocument.createElementNS(v.SVG,"defs"),e.firstChild?e.insertBefore(t,e.firstChild.nextSibling):e.append(t)),t},Tt=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 S=-p/f;S>0&&S<1&&n[d].push(m(S))}}a=c}else n[0].push(u.x),n[1].push(u.y)}var _=Math.min.apply(null,n[0]),b=Math.max.apply(null,n[0])-_,w=Math.min.apply(null,n[1]);return{x:_,y:w,width:b,height:Math.max.apply(null,n[1])-w}};function Lt(e){if(O)try{return e.getBBox()}catch(e){}var t,r,n=ct.data(e,"ref"),i=null;n?(r=ct(n).children().clone().attr("visibility","hidden"),ct(yt).append(r),i=r.filter("line, path")):i=ct(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:ct(e).children();t=jt(s)}else t=e.getBBox();else t=e.getBBox();return n&&r.remove(),t}var Vt=function(e){var t=e||ft.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":V?t.getBBox&&(i=t.getBBox()):i=Tt(t);break;case"g":case"a":i=Lt(t);break;default:if("use"===n&&(i=Lt(t)),"use"===n||"foreignObject"===n&&B()){if(i||(i=t.getBBox()),!B()){var a=i,s=a.x,o=a.y;i={width:a.width,height:a.height,x:s+Number.parseFloat(t.getAttribute("x")||0),y:o+Number.parseFloat(t.getAttribute("y")||0)}}}else if(mt.includes(n))if(t)try{i=t.getBBox()}catch(e){var u=t.getExtentOfChar(0),l=t.getComputedTextLength();i={x:u.x,y:u.y,width:l,height:u.height}}else{var h=ct(t).closest("foreignObject");h.length&&h[0].getBBox&&(i=h[0].getBBox())}}return i&&(i={x:(r=i).x,y:r.y,width:r.width,height:r.height}),i},Ot=function(e){var t="";return ct.each(e,(function(e,r){var n=c(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=Bt(e,t,r);else if("rect"===e.tagName){var u=e.getAttribute("rx"),l=e.getAttribute("ry");(u||l)&&(n=o=Bt(e,t,r))}}if(!o){var h=Ae(i).matrix;n=we(n.x,n.y,n.width,n.height,h).aabox}}return n};function Ht(e){var t=e.getAttribute("stroke-width");return isNaN(t)||"none"===e.getAttribute("stroke")?0:t/2}var jt=function(e,t,r){if(!e||!e.length)return!1;var n;if(ct.each(e,(function(){n||this.parentNode&&(n=Ut(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=Ht(e[0]);s-=u,o-=u,i+=u,a+=u}else ct.each(e,(function(e,n){var u=Ut(n,t,r);if(u){var l=Ht(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},Ft=function(e){e||(e=ct(ft.getSVGContent()).children());var t=[];return ct(e).children().each((function(e,r){r.getBBox&&t.push(r)})),t.reverse()},Dt=function(e){return e||(e=Ft()),jt(e,ft.addSVGElementFromJson,ft.pathActions)},zt=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){var t,r=g(e);try{for(r.s();!(t=r.n()).done;){var n=t.value;this.group_.append(n)}}catch(e){r.e(e)}finally{r.f()}}},{key:"getTitleElement",value:function(){for(var e=this.group_.childNodes.length,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(v.SE,"nonce");i&&or!==sr?this.nonce_=i:or===ar&&this.setNonce(Math.floor(100001*Math.random()))}return a(e,[{key:"getElem_",value:function(e){return this.svgElem_.querySelector?this.svgElem_.querySelector("#"+e):nr(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(v.XMLNS,"xmlns:se",v.SE),this.svgElem_.setAttributeNS(v.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=Number.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=this.svgElem_.childNodes.length,t=[],r=[],n=null,i=!1,a=0;a0||!i?((n=new er(cr(r),null,this.svgElem_)).appendChildren(t),this.all_layers.push(n),this.layer_map[name]=n):n.activate(),this.current_layer=n}},{key:"createLayer",value:function(e,t){this.current_layer&&this.current_layer.deactivate(),(null==e||""===e||this.layer_map[e])&&(e=cr(Object.keys(this.layer_map)));var r=new er(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=cr(Object.keys(this.layer_map)));var n=this.current_layer.getGroup(),i=new er(e,n,this.svgElem_),a=i.getGroup();d(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(ct.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(),B()&&"path"===t.nodeName){var i=nt(t);n.setAttribute("d",i)}if(ct.each(t.childNodes,(function(t,i){switch(i.nodeType){case 1:n.append(e(i,r));break;case 3:n.textContent=i.nodeValue}})),ct(t).data("gsvg"))ct(n).data("gsvg",n.firstChild);else if(ct(t).data("symbol")){var a=ct(t).data("symbol");ct(n).data("ref",a).data("symbol",a)}else"image"===n.tagName&&Zt(n);return n}(e,(function(){return t.getNextId()}))}}]),e}(),fr=function(e,t){(or=!1===e?sr:ar)!==ar||t.getNonce()?or===sr&&t.getNonce()&&t.clearNonce():t.setNonce(Math.floor(100001*Math.random()))},gr=function(){Cr(),dr.getCurrentDrawing().identifyLayers()},pr=function(e,t){var r=dr.getCurrentDrawing().createLayer(e,lr(t));dr.clearSelection(),dr.call("changed",[r])},yr=function(e,t){var r=dr.getCurrentDrawing().cloneLayer(e,lr(t));dr.clearSelection(),Cr(),dr.call("changed",[r])},vr=function(){var e=dr.getCurrentDrawing().getCurrentLayer(),t=e.nextSibling,r=e.parentNode;if(e=dr.getCurrentDrawing().deleteCurrentLayer()){var n=new he("Delete Layer");return n.addSubCommand(new ue(e,t,r)),dr.addCommandToHistory(n),dr.clearSelection(),dr.call("changed",[r]),!0}return!1},xr=function(e){var t=dr.getCurrentDrawing().setCurrentLayer(xt(e));return t&&dr.clearSelection(),t},Sr=function(e){var t=dr.getCurrentDrawing(),r=t.getCurrentLayer();if(r&&t.setCurrentLayerName(e,lr()))return dr.call("changed",[r]),!0;return!1},_r=function(e){var t=dr.getCurrentDrawing().setCurrentLayerPosition(e);return!!t&&(dr.addCommandToHistory(new se(t.currentGroup,t.oldNextSibling,dr.getSVGContent())),!0)},br=function(e,t){var r=dr.getCurrentDrawing(),n=r.getLayerVisibility(e),i=r.setLayerVisibility(e,t);if(!i)return!1;var a=n?"inline":"none";return dr.addCommandToHistory(new le(i,{display:a},"Layer Visibility")),i===r.getCurrentLayer()&&(dr.clearSelection(),dr.pathActions.clear()),!0},wr=function(e){var t=dr.getCurrentDrawing().getLayerByName(e);if(!t)return!1;for(var r=new he("Move Elements to Layer"),n=dr.getSelectedElements(),i=n.length;i--;){var a=n[i];if(a){var s=a.nextSibling,o=a.parentNode;t.append(a),r.addSubCommand(new se(a,s,o))}}return dr.addCommandToHistory(r),!0},Ar=function(e){dr.getCurrentDrawing().mergeLayer(lr(e)),dr.clearSelection(),Cr(),dr.changeSVGContent()},kr=function(e){dr.getCurrentDrawing().mergeAllLayers(lr(e)),dr.clearSelection(),Cr(),dr.changeSVGContent()},Cr=function(){var e=ur.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 Mr(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",Lr(i,t),i.addEventListener("error",a),i.addEventListener("load",s),i.src=e,document.head.append(i)}))}function Rr(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.returnDefault,i=void 0!==n&&n;return Array.isArray(e)?Promise.all(e.map((function(e){return Rr(e,t)}))):new Promise((function(r,n){var a="$importModule$"+Math.random().toString(32).slice(2),s=document.createElement("script");function o(){n(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=""};Lr(s,t),s.defer="defer",s.type="module",s.addEventListener("error",o),s.addEventListener("load",u);var h=Tr(e),c="import * as m from '".concat(h.replace(/'/g,"\\'"),"'; window.").concat(a," = ").concat(i?"m.default || ":"","m;"),d=new Blob([c],{type:"text/javascript"});s.src=URL.createObjectURL(d),document.head.append(s)}))}var Br,Ur,Hr,jr,Fr=jQuery,Dr=[0,"z","M","m","L","l","C","c","Q","q","A","a","H","h","V","v","S","s","T","t"],zr=null,qr=function(e,t,r){for(var n=function(e,t){return xe(e,t,r)},i=function(e){return r.a*e},a=function(e){return r.d*e},s=zr.getGridSnapping()&&"svg"===e.parentNode.parentNode.localName,o=function(){s&&Object.entries(t).forEach((function(e){var r=c(e,2),n=r[0],i=r[1];t[n]=Kt(i)})),Yt(e,t,1e3,!0)},u=Vt(e),l=0;l<2;l++){var h=0===l?"fill":"stroke",d=e.getAttribute(h);if(d&&d.startsWith("url(")&&(r.a<0||r.d<0)){var m=Qt(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=zr.getDrawing().getNextId(),It().append(m),e.setAttribute(h,"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=X(e),S=zr.getSVGRoot().createSVGTransform();S.setMatrix(_e(Ae(x).matrix,r)),x.clear(),x.appendItem(S)}else{var _=Ae(e).matrix,b=_e(_.inverse(),r,_);t.x=Number.parseFloat(t.x)+b.e,t.y=Number.parseFloat(t.y)+b.f}switch(v){case"foreignObject":case"rect":case"image":if("image"===v&&(r.a<0||r.d<0)){var w=X(e),A=zr.getSVGRoot().createSVGTransform();A.setMatrix(_e(Ae(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=we(u.x,u.y,u.width,u.height,r),N=P.tr.x-P.tl.x,G=P.bl.y-P.tl.y;t.r=Math.min(N/2,G/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=Fr(e).data("gsvg");L&&Yt(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(Se(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&&qt(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(_e(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=_e(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,f,g=Qr(t).data("gsvg"),p=new he("Transform"),y={},x=null,S=[];switch(t.tagName){case"line":S=["x1","y1","x2","y2"];break;case"circle":S=["cx","cy","r"];break;case"ellipse":S=["cx","cy","rx","ry"];break;case"foreignObject":case"rect":case"image":S=["width","height","x","y"];break;case"use":case"text":case"tspan":S=["x","y"];break;case"polygon":case"polyline":(x={}).points=t.getAttribute("points");var _=t.points,b=_.numberOfItems;y.points=new Array(b);for(var w=0;w1e-10?Math.sin(P)/(1-Math.cos(P)):2/P;for(var N=0;N=3&&3===n.getItem(V-2).type&&2===n.getItem(V-3).type&&2===n.getItem(V-1).type){R=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(O=0,M=0,1===z.nodeType){var q=X(z);if(!q)continue;var Q=Ae(q).matrix,W=qt(z);if(L=Br.getStartTransform(),Br.setStartTransform(z.getAttribute("transform")),W||be(q)){var Y=r.createSVGTransform();Y.setMatrix(_e(U,H,j,Q)),q.clear(),q.appendItem(Y)}else{var K=_e(Q.inverse(),j,Q),Z=r.createSVGMatrix();Z.e=-K.e,Z.f=-K.f;var $=_e(Z.inverse(),Q.inverse(),U,H,j,Q,K.inverse()),J=r.createSVGTransform(),ee=r.createSVGTransform(),te=r.createSVGTransform();J.setTranslate(K.e,K.f),ee.setScale($.a,$.d),te.setTranslate(Z.e,Z.f),q.appendItem(te),q.appendItem(ee),q.appendItem(J)}p.addSubCommand(e(z)),Br.setStartTransform(L)}}n.removeItem(V-1),n.removeItem(V-2),n.removeItem(V-3)}else if(V>=3&&1===n.getItem(V-1).type){R=3;var re=Ae(n).matrix,ie=r.createSVGTransform();ie.setMatrix(re),n.clear(),n.appendItem(ie)}else if((1===V||V>1&&3!==n.getItem(1).type)&&2===n.getItem(0).type){R=2;var ae=Ae(n).matrix;n.removeItem(0);var se=Ae(n).matrix.inverse(),oe=_e(se,ae);if(O=oe.e,M=oe.f,0!==O||0!==M){for(var ue=t.childNodes,ce=ue.length,de=[];ce--;){var me=ue.item(ce);if(1===me.nodeType){if(me.getAttribute("clip-path")){var fe=me.getAttribute("clip-path");de.includes(fe)||(Wr(fe,O,M),de.push(fe))}L=Br.getStartTransform(),Br.setStartTransform(me.getAttribute("transform"));var ge=X(me);if(ge){var pe=r.createSVGTransform();pe.setTranslate(O,M),ge.numberOfItems?ge.insertItemBefore(pe,0):ge.appendItem(pe),p.addSubCommand(e(me));for(var ye=t.getElementsByTagNameNS(v.SVG,"use"),ve="#"+me.id,we=ye.length;we--;){var ke=ye.item(we);if(ve===Nt(ke)){var Ce=r.createSVGTransform();Ce.setTranslate(-O,-M),X(ke).insertItemBefore(Ce,0),p.addSubCommand(e(ke))}}Br.setStartTransform(L)}}}Br.setStartTransform(L)}}else{if(1!==V||1!==n.getItem(0).type||C){if(C){var Ee=r.createSVGTransform();Ee.setRotate(C,f.x,f.y),n.numberOfItems?n.insertItemBefore(Ee,0):n.appendItem(Ee)}return 0===n.numberOfItems&&t.removeAttribute("transform"),null}R=1;for(var Pe=n.getItem(0).matrix,Ne=t.childNodes,Ge=Ne.length;Ge--;){var Ie=Ne.item(Ge);if(1===Ie.nodeType){L=Br.getStartTransform(),Br.setStartTransform(Ie.getAttribute("transform"));var Te=X(Ie);if(!Te)continue;var Le=_e(Pe,Ae(Te).matrix),Ve=r.createSVGTransform();Ve.setMatrix(Le),Te.clear(),Te.appendItem(Ve,0),p.addSubCommand(e(Ie)),Br.setStartTransform(L);var Oe=Ie.getAttribute("stroke-width");if("none"!==Ie.getAttribute("stroke")&&!isNaN(Oe)){var Me=(Math.abs(Le.a)+Math.abs(Le.d))/2;Ie.setAttribute("stroke-width",Oe*Me)}}}n.clear()}if(2===R){if(C){f={x:m.x+T.e,y:m.y+T.f};var Re=r.createSVGTransform();Re.setRotate(C,f.x,f.y),n.numberOfItems?n.insertItemBefore(Re,0):n.appendItem(Re)}}else if(3===R){var Be=Ae(n).matrix,Ue=r.createSVGTransform();Ue.setRotate(C,m.x,m.y);var He=Ue.matrix,je=r.createSVGTransform();je.setRotate(C,f.x,f.y);var Fe=je.matrix.inverse(),De=Be.inverse(),ze=_e(De,Fe,He,Be);if(O=ze.e,M=ze.f,0!==O||0!==M)for(var qe=t.childNodes,Qe=qe.length;Qe--;){var We=qe.item(Qe);if(1===We.nodeType){L=Br.getStartTransform(),Br.setStartTransform(We.getAttribute("transform"));var Ye=X(We),Xe=r.createSVGTransform();Xe.setTranslate(O,M),Ye.numberOfItems?Ye.insertItemBefore(Xe,0):Ye.appendItem(Xe),p.addSubCommand(e(We)),Br.setStartTransform(L)}}C&&(n.numberOfItems?n.insertItemBefore(je,0):n.appendItem(je))}}else{var Ke,Ze=Vt(t);if(!Ze&&"path"!==t.tagName)return null;var $e=qt(t);if($e){m={x:Ze.x+Ze.width/2,y:Ze.y+Ze.height/2},f=xe(Ze.x+Ze.width/2,Ze.y+Ze.height/2,Ae(n).matrix);for(var Je=$e*Math.PI/180,et=Math.abs(Je)>1e-10?Math.sin(Je)/(1-Math.cos(Je)):2/Je,tt=0;tt=3&&3===n.getItem(at-2).type&&2===n.getItem(at-3).type&&2===n.getItem(at-1).type)it=3,Ke=Ae(n,at-3,at-1).matrix,n.removeItem(at-1),n.removeItem(at-2),n.removeItem(at-3);else if(4===at&&1===n.getItem(at-1).type){it=3,Ke=Ae(n).matrix;var dt=r.createSVGTransform();dt.setMatrix(Ke),n.clear(),n.appendItem(dt),Ke=r.createSVGMatrix()}else if((1===at||at>1&&3!==n.getItem(1).type)&&2===n.getItem(0).type){it=2;var mt=n.getItem(0).matrix,ft=Ae(n,1).matrix,gt=ft.inverse();Ke=_e(gt,mt,ft),n.removeItem(0)}else{if(1!==at||1!==n.getItem(0).type||$e){if($e){var pt=r.createSVGTransform();pt.setRotate($e,f.x,f.y),n.numberOfItems?n.insertItemBefore(pt,0):n.appendItem(pt)}return 0===n.numberOfItems&&t.removeAttribute("transform"),null}switch(Ke=Ae(n).matrix,t.tagName){case"line":y=Qr(t).attr(["x1","y1","x2","y2"]);case"polyline":case"polygon":if(y.points=t.getAttribute("points"),y.points){var yt=t.points,vt=yt.numberOfItems;y.points=new Array(vt);for(var xt=0;xt0;)t.push(t.shift()),r--;Object.values(jr.selectorGrips).forEach((function(e,r){e.setAttribute("style","cursor:"+t[r]+"-resize")}))}}]),e}(),$r=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=Ur.createSVGElement({element:"g",attr:{id:"selectorParentGroup"}}),this.selectorGripsGroup=Ur.createSVGElement({element:"g",attr:{display:"none"}}),this.selectorParentGroup.append(this.selectorGripsGroup),Ur.svgRoot().append(this.selectorParentGroup),this.selectorMap={},this.selectors=[],this.rubberBandBox=null,Object.keys(this.selectorGrips).forEach((function(t){var r=Ur.createSVGElement({element:"circle",attr:{id:"selectorGrip_resize_"+t,fill:"#22C",r:Kr,style:"cursor:"+t+"-resize","stroke-width":2,"pointer-events":"all"}});Xr.data(r,"dir",t),Xr.data(r,"type","resize"),e.selectorGrips[t]=e.selectorGripsGroup.appendChild(r)})),this.rotateGripConnector=this.selectorGripsGroup.appendChild(Ur.createSVGElement({element:"line",attr:{id:"selectorGrip_rotateconnector",stroke:"#22C","stroke-width":"1"}})),this.rotateGrip=this.selectorGripsGroup.appendChild(Ur.createSVGElement({element:"circle",attr:{id:"selectorGrip_rotate",fill:"lime",r:Kr,stroke:"#22C","stroke-width":2,style:"cursor:url("+Hr.imgPath+"rotate.png) 12 12, auto;"}})),Xr.data(this.rotateGrip,"type","rotate"),!Xr("#canvasBackground").length){var t=c(Hr.dimensions,2),r=t[0],n=t[1],i=Ur.createSVGElement({element:"svg",attr:{id:"canvasBackground",width:r,height:n,x:0,y:0,overflow:B()?"none":"visible",style:"pointer-events:none"}}),a=Ur.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),Ur.svgRoot().insertBefore(i,Ur.svgContent())}}},{key:"requestSelector",value:function(t,r){if($t(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(h);var m=l.createElementNS(v.SVG,"svg");(u.clearSvgContentElement=function(){Jr(m).empty(),Jr(m).attr({id:"svgcontent",width:o[0],height:o[1],x:o[0],y:o[1],overflow:s.show_outside_canvas?"visible":"hidden",xmlns:v.SVG,"xmlns:se":v.SE,"xmlns:xlink":v.XLINK}).appendTo(h);var e=l.createComment(" Created with SVG-edit - https://github.com/SVG-Edit/svgedit");m.append(e)})();var f="svg_";u.setIdPrefix=function(e){f=e},u.current_drawing_=new mr(m,f);var p=u.getCurrentDrawing=function(){return u.current_drawing_},y=1,S=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=Jr.extend(!0,{},_.shape),Jr.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 b=_.shape,w=[],A=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]=A(i);return r},k=this.addSVGElementFromJson=function(e){if("string"==typeof e)return l.createTextNode(e);var t=Wt(e.attr.id),r=p().getCurrentLayer();if(t&&e.element!==t.tagName&&(t.remove(),t=null),!t){var n=e.namespace||v.SVG;t=l.createElementNS(n,e.element),r&&(S||r).append(t)}return e.curStyles&&Yt(t,{fill:b.fill,stroke:b.stroke,"stroke-width":b.stroke_width,"stroke-dasharray":b.stroke_dasharray,"stroke-linejoin":b.stroke_linejoin,"stroke-linecap":b.stroke_linecap,"stroke-opacity":b.stroke_opacity,"fill-opacity":b.fill_opacity,opacity:b.opacity/2,style:"pointer-events:inherit"}),Yt(t,e.attr),Xt(t),e.children&&e.children.forEach((function(e){t.append(k(e))})),t};u.getTransformList=X,u.matrixMultiply=_e,u.hasMatrixTransform=be,u.transformListToTransform=Ae;var C=function(){return s.baseUnit};!function(e){q=e;var t=document.createElementNS(v.SVG,"svg");document.body.append(t);var r=document.createElementNS(v.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;$={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:C,getElement:Wt,getHeight:function(){return m.getAttribute("height")/y},getWidth:function(){return m.getAttribute("width")/y},getRoundDigits:function(){return fe.round_digits}}),u.convertToNum=ne;var E,P=function(){return m},N=this.getSelectedElems=function(){return w},G=ht,I=function(){return h};ft=E={pathActions:G,getSVGContent:P,addSVGElementFromJson:k,getSelectedElements:N,getDOMDocument:function(){return l},getDOMContainer:function(){return i},getSVGRoot:I,getBaseUnit:C,getSnappingStep:function(){return s.snappingStep}},gt=E.getDOMDocument(),pt=E.getDOMContainer(),yt=E.getSVGRoot(),u.findDefs=It,u.getUrlFromAttr=Pt,u.getHref=Nt,u.setHref=Gt,u.getBBox=Vt,u.getRotationAngle=qt,u.getElem=Wt,u.getRefElem=Qt,u.assignAttributes=Yt,this.cleanupElement=Xt;var T=function(){return s.gridSnapping};!function(e){zr=e}({getDrawing:function(){return p()},getSVGRoot:I,getGridSnapping:T}),this.remapElement=qr,function(e){Br=e}({getSVGRoot:I,getStartTransform:function(){return Te},setStartTransform:function(e){Te=e}}),this.recalculateDimensions=Yr;var V=x();u.sanitizeSvg=Ir;var O=u.undoMgr=new sn({handleHistoryEvent:function(e,t){var r=on;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(),Z("changed",n);var i=t.type(),a=e===r.AFTER_APPLY;if(i===en.type())(a?t.newParent:t.oldParent)===m&&gr();else if(i===tn.type()||i===rn.type())t.parent===m&&gr(),i===tn.type()?a&&de(t.elem):a||de(t.elem),"use"===t.elem.tagName&&er(t.elem);else if(i===nn.type()){"title"===t.elem.tagName&&t.elem.parentNode.parentNode===m&&gr();var s=a?t.newValues:t.oldValues;s.stdDeviation&&u.setBlurOffsets(t.elem.parentNode,s.stdDeviation)}}}}),M=function(e){u.undoMgr.addCommandToHistory(e)},R=this.getZoom=function(){return y},D=this.round=function(e){return Number.parseInt(e*y)/y};!function(e,t){Hr=e,Ur=t,jr=new $r}(s,{createSVGElement:function(e){return u.addSVGElementFromJson(e)},svgRoot:function(){return h},svgContent:function(){return m},getCurrentZoom:R});var z=this.selectorManager=jr,Y=u.getNextId=function(){return p().getNextId()},K=u.getId=function(){return p().getId()},Z=function(e,t){if(We[e])return We[e](window,t)},re=this.clearSelection=function(e){w.forEach((function(e){$t(e)||z.releaseSelector(e)})),w=[],e||Z("selected",w)},ie=this.addToSelection=function(e,t){if(e.length){for(var r=0;r1&&s.showGrips(!1)}}}if(w.length)for(Z("selected",w),t||1===w.length?z.requestSelector(w[0]).showGrips(!0):z.requestSelector(w[0]).showGrips(!1),w.sort((function(e,t){return e&&t&&e.compareDocumentPosition?3-(6&t.compareDocumentPosition(e)):$t(e)?1:0}));$t(w[0]);)w.shift(0)}},ae=function(){return b.opacity},se=this.getMouseTarget=function(e){if($t(e))return null;var t=e.target;if(t.correspondingUseElement&&(t=t.correspondingUseElement),[v.MATH,v.HTML].includes(t.namespaceURI)&&"svgcanvas"!==t.id)for(;"foreignObject"!==t.nodeName;)if(!(t=t.parentNode))return h;var r=p().getCurrentLayer();if([h,i,m,r].includes(t))return h;if(Jr(t).closest("#selectorParentGroup").length)return z.selectorParentGroup;for(;t.parentNode!==(S||r);)t=t.parentNode;return t};u.pathActions=G,Re({selectorManager:z,canvas:u,call:Z,resetD:function(e){e.setAttribute("d",G.convertPath(e))},round:D,clearSelection:re,addToSelection:ie,addCommandToHistory:M,remapElement:qr,addSVGElementFromJson:k,getGridSnapping:T,getOpacity:ae,getSelectedElements:N,getContainer:function(){return i},setStarted:function(e){Ge=e},getRubberBox:function(){return He},setRubberBox:function(e){return He=e},addPtsToSelection:function(e){var t=e.closedSubpath,r=e.grips;G.canDeleteNodes=!0,G.closed_subpath=t,Z("pointsAdded",{closedSubpath:t,grips:r}),Z("selected",r)},endChanges:function(e){var t=e.cmd,r=e.elem;M(t),Z("changed",[r])},getCurrentZoom:R,getId:K,getNextId:Y,getMouseTarget:se,getCurrentMode:function(){return Le},setCurrentMode:function(e){return Le=e},getDrawnPath:function(){return Ot},setDrawnPath:function(e){return Ot=e},getSVGRoot:I});var oe={},ue="a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use",le=["clip-path","fill","filter","marker-end","marker-mid","marker-start","mask","stroke"],he=Jr.data,ce=document.createElementNS(v.SVG,"animate");Jr(ce).attr({attributeName:"opacity",begin:"indefinite",dur:1,fill:"freeze"}).appendTo(h);var de=function e(t){var r=Jr(t).attr(le);Object.values(r).forEach((function(e){if(e&&e.startsWith("url(")){var t=Pt(e).substr(1);Wt(t)||(It().append(Pe[t]),delete Pe[t])}}));var n=t.getElementsByTagName("*");if(n.length)for(var i=0,a=n.length;i0&&(4===o.getItem(0).type&&o.removeItem(0));if(0!==e){var u=xe(a,s,Ae(o).matrix),l=h.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 c=r.getAttribute("transform");r.setAttribute("transform",n),lr("transform",c,w),Z("changed",w)}z.requestSelector(w[0]).resize(),Zr.updateGripCursors(e)};var Xe=this.recalculateAllSelectedDimensions=function(){for(var e=new an("none"===Me?"position":"size"),t=w.length;t--;){var r=w[t],n=Yr(r);n&&e.addSubCommand(n)}e.isEmpty()||(M(e),Z("changed",w))},Ke=function(e){console.log([e.a,e.b,e.c,e.d,e.e,e.f])},Ze=null,$e=this.selectOnly=function(e,t){re(!0),ie(e,t)};this.removeFromSelection=function(e){if(!$t(w[0])&&e.length){for(var t=[],r=w.length,n=0;n0&&u.removeFromSelection(E),P.length>0&&u.addToSelection(P);break;case"resize":f=X(g);var L=be(f),V=(d=L?st:Vt(g)).x,O=d.y,M=d,R=M.width,B=M.height;if(a=b-rt,o=k-nt,s.gridSnapping&&(a=Kt(a),o=Kt(o),B=Kt(B),R=Kt(R)),c=qt(g)){var U=Math.sqrt(a*a+o*o),H=Math.atan2(o,a)-c*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,q=R?(R+a)/R:1;Me.includes("n")&&(D=B?(B-o)/B:1,F=B),Me.includes("w")&&(q=R?(R-a)/R:1,j=R);var Q=h.createSVGTransform(),W=h.createSVGTransform(),Y=h.createSVGTransform();if(s.gridSnapping&&(V=Kt(V),j=Kt(j),O=Kt(O),F=Kt(F)),Q.setTranslate(-(V+j),-(O+F)),e.shiftKey&&(1===q?q=D:D=q),W.setScale(q,D),Y.setTranslate(V+j,O+F),L){var $=c?1:0;f.replaceItem(Q,2+$),f.replaceItem(W,1+$),f.replaceItem(Y,Number($))}else{var J=f.numberOfItems;f.replaceItem(Y,J-3),f.replaceItem(W,J-2),f.replaceItem(Q,J-1)}z.requestSelector(g).resize(),Z("transition",w);break;case"zoom":_*=y,A*=y,Yt(He,{x:Math.min(it*y,_),y:Math.min(at*y,A),width:Math.abs(_-it*y),height:Math.abs(A-at*y)});break;case"text":Yt(S,{x:b,y:k});break;case"line":s.gridSnapping&&(b=Kt(b),k=Kt(k));var ee=b,te=k;e.shiftKey&&(ee=(r=Ce(rt,nt,ee,te)).x,te=r.y),S.setAttribute("x2",ee),S.setAttribute("y2",te);break;case"foreignObject":case"square":case"rect":case"image":var re,ne,ie="square"===Le||e.shiftKey,ae=Math.abs(b-rt),se=Math.abs(k-nt);ie?(ae=se=Math.max(ae,se),re=rt.8){ot-=.8;var ce=m.createSVGPoint();ce.x=bt.x,ce.y=bt.y,S.points.appendItem(ce)}ut={x:lt.x,y:lt.y},lt={x:dt.x,y:dt.y},dt={x:mt.x,y:mt.y};break;case"path":case"pathedit":if(b*=y,k*=y,s.gridSnapping&&(b=Kt(b),k=Kt(k),rt=Kt(rt),nt=Kt(nt)),e.shiftKey){var de,me,fe=Oe;fe?(de=fe.dragging?fe.dragging[0]:rt,me=fe.dragging?fe.dragging[1]:nt):(de=rt,me=nt);var ge=r=Ce(de,me,b,k);b=ge.x,k=ge.y}He&&"none"!==He.getAttribute("display")&&(_*=y,A*=y,Yt(He,{x:Math.min(it*y,_),y:Math.min(at*y,A),width:Math.abs(_-it*y),height:Math.abs(A-at*y)})),G.mouseMove(b,k);break;case"textedit":b*=y,k*=y,Ht.mouseMove(v,x);break;case"rotate":n=(d=Vt(g)).x+d.width/2,i=d.y+d.height/2;var pe=ke(g),ye=xe(n,i,pe);n=ye.x,i=ye.y,c=(Math.atan2(i-k,n-b)*(180/Math.PI)-90)%360,s.gridSnapping&&(c=Kt(c)),e.shiftKey&&(c=45*Math.round(c/45)),u.setRotationAngle(c<-180?360+c:c,!0),Z("transition",w)}De("mouseMove",{event:e,mouse_x:v,mouse_y:x,selected:g})}})).click((function(e){return e.preventDefault(),!1})).dblclick((function(e){var t=e.target.parentNode;if(t!==S){var r=se(e),n=r.tagName;if("text"===n&&"textedit"!==Le){var i=xe(e.pageX,e.pageY,Ze);Ht.select(r,i.x,i.y)}"g"!==n&&"a"!==n||!qt(r)||(Pr(r),r=w[0],re(!0)),S&&Cr(),"g"!==t.tagName&&"a"!==t.tagName||t===p().getCurrentLayer()||r===z.selectorParentGroup||Er(r)}})).mouseup((function(e){if(2!==e.button){var t=Ue;if(Ue=null,Ge){var r,n,i=xe(e.pageX,e.pageY,Ze),a=i.x*y,o=i.y*y,l=a/y,h=o/y,c=Wt(K()),d=!1,m=l,f=h;switch(Ge=!1,Le){case"resize":case"multiselect":$t(He)||(He.setAttribute("display","none"),je=[]),Le="select";case"select":if(!$t(w[0])){if($t(w[1])){var g=w[0];switch(g.tagName){case"g":case"use":case"image":case"foreignObject":break;default:Be.fill=g.getAttribute("fill"),Be.fill_opacity=g.getAttribute("fill-opacity"),Be.stroke=g.getAttribute("stroke"),Be.stroke_opacity=g.getAttribute("stroke-opacity"),Be.stroke_width=g.getAttribute("stroke-width"),Be.stroke_dasharray=g.getAttribute("stroke-dasharray"),Be.stroke_linejoin=g.getAttribute("stroke-linejoin"),Be.stroke_linecap=g.getAttribute("stroke-linecap")}"text"===g.tagName&&(pe.font_size=g.getAttribute("font-size"),pe.font_family=g.getAttribute("font-family")),z.requestSelector(g).showGrips(!0)}if(Xe(),m!==it||f!==at)for(var v=w.length,x=0;x=0?A.includes(",",C+1):A.includes(" ",A.indexOf(" ")+1))&&(c=G.smoothPolylineIntoPath(c));break;case"line":r=Jr(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=Jr(c).attr(["width","height"]),d=r.width||r.height||"image"===Le;break;case"circle":d="0"!==c.getAttribute("r");break;case"ellipse":r=Jr(c).attr(["rx","ry"]),d=r.rx||r.ry;break;case"fhellipse":tt.maxx-tt.minx>0&&tt.maxy-tt.miny>0&&(c=k({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:K()}}),Z("changed",[c]),d=!0);break;case"fhrect":tt.maxx-tt.minx>0&&tt.maxy-tt.miny>0&&(c=k({element:"rect",curStyles:!0,attr:{x:tt.minx,y:tt.miny,width:tt.maxx-tt.minx,height:tt.maxy-tt.miny,id:K()}}),Z("changed",[c]),d=!0);break;case"text":d=!0,$e([c]),Ht.start(c);break;case"path":c=null,Ge=!0;var E=G.mouseUp(e,c,a,o);c=E.element,d=E.keep;break;case"pathedit":d=!0,c=null,G.mouseUp(e);break;case"textedit":d=!1,c=null,Ht.mouseUp(e,a,o);break;case"rotate":d=!0,c=null,Le="select";var P=u.undoMgr.finishUndoableChange();P.isEmpty()||M(P),Xe(),Z("changed",w)}var N=De("mouseUp",{event:e,mouse_x:a,mouse_y:o},!0);if(Jr.each(N,(function(e,t){t&&(d=t.keep||d,c=t.element,Ge=t.started||Ge)})),d||$t(c)){if(!$t(c)){u.addedNew=!0;var I,T=.2;if(ce.beginElement&&Number.parseFloat(c.getAttribute("opacity"))!==b.opacity){I=Jr(ce).clone().attr({to:b.opacity,dur:T}).appendTo(c);try{I[0].beginElement()}catch(e){}}else T=0;setTimeout((function(){I&&I.remove(),c.setAttribute("opacity",b.opacity),c.setAttribute("style","pointer-events:inherit"),Xt(c),"path"===Le?G.toEditMode(c):s.selectNew&&$e([c],!0),M(new tn(c)),Z("changed",[c])}),1e3*T)}}else{for(p().releaseId(K()),c.remove(),c=null,n=e.target;n&&n.parentNode&&n.parentNode.parentNode&&"g"===n.parentNode.parentNode.tagName;)n=n.parentNode;"path"===Le&&Ot||!n||!n.parentNode||"selectorParentGroup"===n.parentNode.id||"svgcanvas"===n.id||"svgroot"===n.id||(u.setMode("select"),$e([n],!0))}Te=null}}})),Jr(i).bind("mousewheel DOMMouseScroll",(function(e){if(e.shiftKey){e.preventDefault();var t=e.originalEvent;Ze=Jr("#svgcontent g")[0].getScreenCTM().inverse();var r=Jr("#workarea"),n=s.showRulers?16:0,i=xe(t.pageX,t.pageY,Ze),a=r.width(),o=r.height(),l=a-15-n,h=o-15-n,c=l*Ze.a,d=h*Ze.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 v,x,S=Math.max(3/4,Math.min(4/3,p));S>1?(v=Math.ceil(l/c*S*100)/100,x=Math.ceil(h/d*S*100)/100):(v=Math.floor(l/c*S*100)/100,x=Math.floor(h/d*S*100)/100);var _=Math.min(v,x);if((_=Math.min(10,Math.max(.01,_)))!==y){S=_/y;var b=xe(f,g,Ze),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(_),Jr("#zoom").val((100*_).toFixed(1)),Z("updateCanvas",{center:!1,newCtr:w}),Z("zoomDone")}}}}));var Ut,Ht=u.textActions=function(){var e,t,r,n,i,a,s,o,l,c,d=[];function m(e){var s=""===t.value;if(Jr(t).focus(),!arguments.length)if(s)e=0;else{if(t.selectionEnd!==t.selectionStart)return;e=t.selectionEnd}var o=d[e];s||t.setSelectionRange(e,e),(r=Wt("text_cursor"))||(r=document.createElementNS(v.SVG,"line"),Yt(r,{id:"text_cursor",stroke:"#333","stroke-width":1}),r=Wt("selectorParentGroup").appendChild(r)),i||(i=setInterval((function(){var e="none"===r.getAttribute("display");r.setAttribute("display",e?"inline":"none")}),600));var u=_(o.x,a.y),l=_(o.x,a.y+a.height);Yt(r,{x1:u.x,y1:u.y,x2:l.x,y2:l.y,visibility:"visible",display:"inline"}),n&&n.setAttribute("d","")}function f(e,i,s){if(e!==i){s||t.setSelectionRange(e,i),(n=Wt("text_selectblock"))||(n=document.createElementNS(v.SVG,"path"),Yt(n,{id:"text_selectblock",fill:"green",opacity:.5,style:"pointer-events:none"}),Wt("selectorParentGroup").append(n));var o=d[e],u=d[i];r.setAttribute("visibility","hidden");var l=_(o.x,a.y),h=_(o.x+(u.x-o.x),a.y),c=_(o.x,a.y+a.height),f=_(o.x+(u.x-o.x),a.y+a.height),g="M"+l.x+","+l.y+" L"+h.x+","+h.y+" "+f.x+","+f.y+" "+c.x+","+c.y+"z";Yt(n,{d:g,display:"inline"})}else m(i)}function g(t,r){var n=h.createSVGPoint();if(n.x=t,n.y=r,1===d.length)return 0;var i=e.getCharNumAtPosition(n);i<0?(i=d.length-2,t<=d[0].x&&(i=0)):i>=d.length-2&&(i=d.length-2);var a=d[i];return t>a.x+a.width/2&&i++,i}function p(e,t){m(g(e,t))}function x(e,r,n){var i=t.selectionStart,a=g(e,r);f(Math.min(i,a),Math.max(i,a),!n)}function S(e,t){var r={x:e,y:t};if(r.x/=y,r.y/=y,s){var n=xe(r.x,r.y,s.inverse());r.x=n.x,r.y=n.y}return r}function _(e,t){var r={x:e,y:t};if(s){var n=xe(r.x,r.y,s);r.x=n.x,r.y=n.y}return r.x*=y,r.y*=y,r}function b(t){f(0,e.textContent.length),Jr(this).unbind(t)}function A(t){if(c&&e){var r=xe(t.pageX,t.pageY,Ze),n=S(r.x*y,r.y*y),i=g(n.x,n.y),a=e.textContent,s=a.substr(0,i).replace(/[a-z\d]+$/i,"").length,o=a.substr(i).match(/^[a-z\d]+/i);f(s,(o?o[0].length:0)+i),Jr(t.target).click(b),setTimeout((function(){Jr(t.target).unbind("click",b)}),300)}}return{select:function(t,r,n){e=t,Ht.toEditMode(r,n)},start:function(t){e=t,Ht.toEditMode()},mouseDown:function(e,r,n,i){var a=S(n,i);t.focus(),p(a.x,a.y),o=n,l=i},mouseMove:function(e,t){var r=S(e,t);x(r.x,r.y)},mouseUp:function(t,r,n){var i=S(r,n);x(i.x,i.y,!0),t.target!==e&&ro-2&&nl-2&&Ht.toSelectMode(!0)},setCursor:m,toEditMode:function(t,r){if(c=!1,Le="textedit",z.requestSelector(e).showGrips(!1),z.requestSelector(e),Ht.init(),Jr(e).css("cursor","text"),arguments.length){var n=S(t,r);p(n.x,n.y)}else m();setTimeout((function(){c=!0}),300)},toSelectMode:function(a){Le="select",clearInterval(i),i=null,n&&Jr(n).attr("display","none"),r&&Jr(r).attr("visibility","hidden"),Jr(e).css("cursor","move"),a&&(re(),Jr(e).css("cursor","move"),Z("selected",[e]),ie([e],!0)),e&&!e.textContent.length&&u.deleteSelectedElements(),Jr(t).blur(),e=!1},setInputElem:function(e){t=e},clear:function(){"textedit"===Le&&Ht.toSelectMode()},init:function(r){if(e){var n,i;e.parentNode||(e=w[0],z.requestSelector(e).showGrips(!1));var o=e.textContent.length,l=e.getAttribute("transform");for(a=Vt(e),s=l?ke(e):null,(d=[]).length=o,t.focus(),Jr(e).unbind("dblclick",A).dblclick(A),o||(i={x:a.x+a.width/2,width:0}),n=0;n")[0].getContext("2d")||(r.text=oe.exportNoText),Jr.each(r,(function(r,i){n.find(r).length&&(t.push(r),e.push(i))})),{issues:e,issueCodes:t}}this.svgCanvasToString=function(){for(;jt()>0;);G.clear(!0),Jr.each(m.childNodes,(function(e,t){e&&8===t.nodeType&&t.data.includes("Created with")&&m.firstChild.before(t)})),S&&(Cr(),$e([S]));var e=[];Jr(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;y--){var x=a[y],S=xt(x.value);if(!p.includes(x.localName)){if("null"===S){var _=x.localName.replace(/-[a-z]/g,(function(e){return e[1].toUpperCase()}));if(Object.prototype.hasOwnProperty.call(e.style,_))continue}if(""!==S){if(S.startsWith("pointer-events"))continue;if("class"===x.localName&&S.startsWith("se_"))continue;if(r.push(" "),"d"===x.localName&&(S=G.convertPath(e,!0)),isNaN(S)?i.test(S)&&(S=ee(S)+n):S=ee(S),fe.apply&&"image"===e.nodeName&&"href"===x.localName&&fe.images&&"embed"===fe.images){var b=me[S];b&&(S=b)}x.namespaceURI&&x.namespaceURI!==v.SVG&&!V[x.namespaceURI]||(r.push(x.nodeName),r.push('="'),r.push(S),r.push('"'))}}}}if(e.hasChildNodes()){r.push(">"),t++;for(var w=!1,A=0;A");break;case 8:r.push("\n"),r.push(new Array(t+1).join(" ")),r.push("\x3c!--"),r.push(k.data),r.push("--\x3e")}}if(t--,!w){r.push("\n");for(var E=0;E")}else r.push("/>")}return r.join("")},this.embedImage=function(e){return new Promise((function(t,r){Jr(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"),me[e]=o}catch(t){me[e]=!1}Ne=e,t(me[e])}else r(new Error("Error loading image: "+a.status+" "+a.statusText))})).attr("src",e)}))},this.setGoodImage=function(e){Ne=e},this.open=function(){},this.save=function(e){re(),e&&Jr.extend(fe,e),fe.apply=!0;var t=this.svgCanvasToString();Z("saved",t)},this.rasterExport=function(){var e=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=zt(),h=l.issues,c=l.issueCodes,d=this.svgCanvasToString(),Ut){e.next=10;break}return e.next=8,Vr(s.canvgPath+"canvg.js",{global:"canvg"});case 8:m=e.sent,Ut=m.canvg;case 10:return Jr("#export_canvas").length||Jr("",{id:"export_canvas"}).hide().appendTo("body"),(f=Jr("#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||Z("exported",a),e(a)}f.toBlob?f.toBlob((function(e){u=kt(e),g()}),o,r):(u=At(m),g())})));case 17:case"end":return e.stop()}}),e,this)})));return function(t,r,n){return e.apply(this,arguments)}}(),this.exportPDF=function(){var e=r(regeneratorRuntime.mark((function e(t){var r,n,i,a,o,u,l,h,c,d,m,f,g=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=g.length>1&&void 0!==g[1]?g[1]:j()?"save":void 0,window.jsPDF){e.next=7;break}return e.next=4,Mr(["jspdf/underscore-min.js","../../svgedit-myfix/editor/jspdf/jspdf-1.0.150.debug.js"]);case 4:return n=!("svgEditor"in window)||!window.svgEditor||!1!==window.svgEditor.modules,e.next=7,Mr(s.jspdfPath+"jspdf.plugin.svgToPdf.js",{type:n?"module":"text/javascript"});case 7:return i=ir(),a=i.w>i.h?"landscape":"portrait",o="pt",u=jsPDF({orientation:a,unit:o,format:[i.w,i.h]}),l=ar(),u.setProperties({title:l}),h=zt(),c=h.issues,d=h.issueCodes,m=this.svgCanvasToString(),u.addSVG(m,0,0),(f={svg:m,issues:c,issueCodes:d,exportWindowName:t,outputType:r=r||"dataurlstring"}).output=u.output(r,"save"===r?t||"svg.pdf":void 0),Z("exportedPDF",f),e.abrupt("return",f);case 21:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),this.getSvgString=function(){return fe.apply=!1,this.svgCanvasToString()},this.randomizeIds=function(e){arguments.length>0&&!1===e?fr(!1,p()):fr(!0,p())};var Jt=this.uniquifyElems=function(e){var t={},r=["filter","linearGradient","pattern","radialGradient","symbol","textPath","use"];for(var n in Et(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),Jr.each(le,(function(r,n){var i=e.getAttributeNode(n);if(i){var a=Pt(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=Nt(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];Gt(c,"#"+a)}}}},er=this.setUseData=function(e){var t=Jr(e);"use"!==e.tagName&&(t=t.find("use")),t.each((function(){var e=Nt(this).substr(1),t=Wt(e);t&&(Jr(this).data("ref",t),"symbol"!==t.tagName&&"svg"!==t.tagName||Jr(this).data("symbol",t).data("ref",t))}))},tr=this.convertGradients=function(e){var t=Jr(e).find("linearGradient, radialGradient");!t.length&&B()&&(t=Jr(e).find("*").filter((function(){return this.tagName.includes("Gradient")}))),t.each((function(){if("userSpaceOnUse"===Jr(this).attr("gradientUnits")){var e=Jr(m).find('[fill="url(#'+this.id+')"],[stroke="url(#'+this.id+')"]');if(!e.length)return;var t=Vt(e[0]);if(!t)return;if("linearGradient"===this.tagName){var r=Jr(this).attr(["x1","y1","x2","y2"]),n=this.gradientTransform.baseVal;if(n&&n.numberOfItems>0){var i=Ae(n).matrix,a=xe(r.x1,r.y1,i),s=xe(r.x2,r.y2,i);r.x1=a.x,r.y1=a.y,r.x2=s.x,r.y2=s.y,this.removeAttribute("gradientTransform")}Jr(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")}}}))},rr=this.convertToGroup=function(e){e||(e=w[0]);var t,r=Jr(e),n=new an;if(r.data("gsvg")){var i=e.firstChild,a=Jr(i).attr(["x","y"]);Jr(e.firstChild.firstChild).unwrap(),Jr(e).removeData("gsvg");var s=X(e),o=h.createSVGTransform();o.setTranslate(a.x,a.y),s.appendItem(o),Yr(e),Z("selected",[e])}else if(r.data("symbol")){e=r.data("symbol"),t=r.attr("transform");var u=r.attr(["x","y"]),c=e.getAttribute("viewBox");if(c){var d=c.split(" ");u.x-=Number(d[0]),u.y-=Number(d[1])}t+=" translate("+(u.x||0)+","+(u.y||0)+")";var f=r.prev();n.addSubCommand(new rn(r[0],r[0].nextSibling,r[0].parentNode)),r.remove();var g,p=Jr(m).find("use:data(symbol)").length,y=l.createElementNS(v.SVG,"g"),x=e.childNodes;for(g=0;gc?"scale("+x/3/y[3]+")":"scale("+x/3/y[2]+")")+" translate(0)",s=l.createElementNS(v.SVG,"symbol");var _=It();for(U()&&Jr(u).find("linearGradient, radialGradient, pattern").appendTo(_);u.firstChild;){var b=u.firstChild;s.append(b)}var w,A=g(u.attributes);try{for(A.s();!(w=A.n()).done;){var k=w.value;s.setAttribute(k.nodeName,k.value)}}catch(e){A.e(e)}finally{A.f()}s.id=Y(),ge[i]={symbol:s,xform:r},It().append(s),o.addSubCommand(new tn(s))}(n=l.createElementNS(v.SVG,"use")).id=Y(),Gt(n,"#"+s.id),(S||p().getCurrentLayer()).append(n),o.addSubCommand(new tn(n)),re(),n.setAttribute("transform",r),Yr(n),Jr(n).data("symbol",s).data("ref",s),ie([n]),M(o),Z("changed",[m])}catch(e){return console.log(e),null}return n};var nr={identifyLayers:gr,createLayer:pr,cloneLayer:yr,deleteCurrentLayer:vr,setCurrentLayer:xr,renameCurrentLayer:Sr,setCurrentLayerPosition:_r,setLayerVisibility:br,moveSelectedToLayer:wr,mergeLayer:Ar,mergeAllLayers:kr,leaveContext:Cr,setContext:Er};Object.entries(nr).forEach((function(e){var t=c(e,2),r=t[0],n=t[1];u[r]=n})),function(e){dr=e}({pathActions:G,getCurrentGroup:function(){return S},setCurrentGroup:function(e){S=e},getSelectedElements:N,getSVGContent:P,undoMgr:O,elData:he,getCurrentDrawing:p,clearSelection:re,call:Z,addCommandToHistory:M,changeSVGContent:function(){Z("changed",[m])}}),this.clear=function(){G.clear(),re(),u.clearSvgContentElement(),u.current_drawing_=new mr(m),u.createLayer("Layer 1"),u.undoMgr.resetUndoStack(),z.initGroup(),He=z.getRubberBandBox(),Z("cleared")},this.linkControlPoints=G.linkControlPoints,this.getContentElem=function(){return m},this.getRootElem=function(){return h};var ir=this.getResolution=function(){return{w:m.getAttribute("width")/y,h:m.getAttribute("height")/y,zoom:y}};this.getSnapToGrid=function(){return s.gridSnapping},this.getVersion=function(){return"svgcanvas.js ($Rev$)"},this.setUiStrings=function(t){Object.assign(oe,t.notification),Jr=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("