svgedit/dist/svgcanvas-iife.min.js

33 lines
176 KiB
JavaScript
Raw Normal View History

var SvgCanvas=function(){"use strict";
/**
* A jQuery module to work with SVG attributes.
* @module jQueryAttr
* @license MIT
*/
function t(t){const e=t.fn.attr;return t.fn.attr=function(t,n){const r=this.length;if(!r)return e.call(this,t,n);for(let s=0;s<r;++s){const r=this[s];if("http://www.w3.org/2000/svg"!==r.namespaceURI)return e.call(this,t,n);if(void 0!==n)r.setAttribute(t,n);else if(Array.isArray(t)){const e={};let n=t.length;for(;n--;){const s=t[n];let i=r.getAttribute(s);(i||"0"===i)&&(i=isNaN(i)?i:i-0),e[s]=i}return e}if("object"!=typeof t){let e=r.getAttribute(t);return(e||"0"===e)&&(e=isNaN(e)?e:e-0),e}for(const[e,n]of Object.entries(t))r.setAttribute(e,n)}return this},t}(()=>{if(!("SVGPathSeg"in window)){class t{constructor(t,e,n){this.pathSegType=t,this.pathSegTypeAsLetter=e,this._owningPathSegList=n}_segmentChanged(){this._owningPathSegList&&this._owningPathSegList.segmentChanged(this)}}t.prototype.classname="SVGPathSeg",t.PATHSEG_UNKNOWN=0,t.PATHSEG_CLOSEPATH=1,t.PATHSEG_MOVETO_ABS=2,t.PATHSEG_MOVETO_REL=3,t.PATHSEG_LINETO_ABS=4,t.PATHSEG_LINETO_REL=5,t.PATHSEG_CURVETO_CUBIC_ABS=6,t.PATHSEG_CURVETO_CUBIC_REL=7,t.PATHSEG_CURVETO_QUADRATIC_ABS=8,t.PATHSEG_CURVETO_QUADRATIC_REL=9,t.PATHSEG_ARC_ABS=10,t.PATHSEG_ARC_REL=11,t.PATHSEG_LINETO_HORIZONTAL_ABS=12,t.PATHSEG_LINETO_HORIZONTAL_REL=13,t.PATHSEG_LINETO_VERTICAL_ABS=14,t.PATHSEG_LINETO_VERTICAL_REL=15,t.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS=16,t.PATHSEG_CURVETO_CUBIC_SMOOTH_REL=17,t.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS=18,t.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL=19;class e extends t{constructor(e){super(t.PATHSEG_CLOSEPATH,"z",e)}toString(){return"[object SVGPathSegClosePath]"}_asPathString(){return this.pathSegTypeAsLetter}clone(){return new e(void 0)}}class n extends t{constructor(e,n,r){super(t.PATHSEG_MOVETO_ABS,"M",e),this._x=n,this._y=r}toString(){return"[object SVGPathSegMovetoAbs]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}clone(){return new n(void 0,this._x,this._y)}}Object.defineProperties(n.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0}});class r extends t{constructor(e,n,r){super(t.PATHSEG_MOVETO_REL,"m",e),this._x=n,this._y=r}toString(){return"[object SVGPathSegMovetoRel]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}clone(){return new r(void 0,this._x,this._y)}}Object.defineProperties(r.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0}});class s extends t{constructor(e,n,r){super(t.PATHSEG_LINETO_ABS,"L",e),this._x=n,this._y=r}toString(){return"[object SVGPathSegLinetoAbs]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}clone(){return new s(void 0,this._x,this._y)}}Object.defineProperties(s.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0}});class i extends t{constructor(e,n,r){super(t.PATHSEG_LINETO_REL,"l",e),this._x=n,this._y=r}toString(){return"[object SVGPathSegLinetoRel]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}clone(){return new i(void 0,this._x,this._y)}}Object.defineProperties(i.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0}});class o extends t{constructor(e,n,r,s,i,o,a){super(t.PATHSEG_CURVETO_CUBIC_ABS,"C",e),this._x=n,this._y=r,this._x1=s,this._y1=i,this._x2=o,this._y2=a}toString(){return"[object SVGPathSegCurvetoCubicAbs]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x1+" "+this._y1+" "+this._x2+" "+this._y2+" "+this._x+" "+this._y}clone(){return new o(void 0,this._x,this._y,this._x1,this._y1,this._x2,this._y2)}}Object.defineProperties(o.prototype,{x:{get(){return this._x},set(t){this._x=t,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(t){this._y=t,this._segmentChanged()},enumerable:!0},x1:{get(){return this._x1},set(t){this._
/**
* Namespaces or tools therefor.
* @module namespaces
* @license MIT
*/
const e={HTML:"http://www.w3.org/1999/xhtml",MATH:"http://www.w3.org/1998/Math/MathML",SE:"http://svg-edit.googlecode.com",SVG:"http://www.w3.org/2000/svg",XLINK:"http://www.w3.org/1999/xlink",XML:"http://www.w3.org/XML/1998/namespace",XMLNS:"http://www.w3.org/2000/xmlns/"},n=function(){const t={};return Object.entries(e).forEach(([e,n])=>{t[n]=e.toLowerCase()}),t},r=jQuery,{userAgent:s}=(Boolean(document.createElementNS&&document.createElementNS(e.SVG,"svg").createSVGRect),navigator),i=document.createElementNS(e.SVG,"svg"),o=Boolean(window.opera),a=s.includes("AppleWebKit"),c=s.includes("Gecko/"),l=s.includes("MSIE"),h=s.includes("Chrome/"),u=(s.includes("Windows"),s.includes("Macintosh"),"ontouchstart"in window),d=Boolean(i.querySelector),m=Boolean(document.evaluate),g=function(){const t=document.createElementNS(e.SVG,"path");t.setAttribute("d","M0,0 10,10");const n=t.pathSegList,r=t.createSVGPathSegLinetoAbs(5,5);try{return n.replaceItem(r,1),!0}catch(t){}return!1}(),p=function(){const t=document.createElementNS(e.SVG,"path");t.setAttribute("d","M0,0 10,10");const n=t.pathSegList,r=t.createSVGPathSegLinetoAbs(5,5);try{return n.insertItemBefore(r,1),!0}catch(t){}return!1}(),f=function(){const t=document.createElementNS(e.SVG,"svg"),n=document.createElementNS(e.SVG,"svg");document.documentElement.append(t),n.setAttribute("x",5),t.append(n);const r=document.createElementNS(e.SVG,"text");r.textContent="a",n.append(r);try{return 0===r.getStartPositionOfChar(0).x}catch(t){return!1}finally{t.remove()}}(),y=function(){const t=document.createElementNS(e.SVG,"svg");document.documentElement.append(t);const n=document.createElementNS(e.SVG,"path");n.setAttribute("d","M0,0 C0,0 10,10 10,0"),t.append(n);const r=n.getBBox();return t.remove(),r.height>4&&r.height<5}(),x=function(){const t=document.createElementNS(e.SVG,"svg");document.documentElement.append(t);const n=document.createElementNS(e.SVG,"path");n.setAttribute("d","M0,0 10,0");const r=document.createElementNS(e.SVG,"path");r.setAttribute("d","M5,0 15,0");const s=document.createElementNS(e.SVG,"g");s.append(n,r),t.append(s);const i=s.getBBox();return t.remove(),15===i.width}(),S=(function(){const t=document.createElementNS(e.SVG,"rect");t.setAttribute("x",.1);const n=!t.cloneNode(!1).getAttribute("x").includes(",");n||r.alert('NOTE: This version of Opera is known to contain bugs in SVG-edit.\nPlease upgrade to the <a href="http://opera.com">latest version</a> in which the problems have been fixed.')}(),function(){const t=document.createElementNS(e.SVG,"rect");return t.setAttribute("style","vector-effect:non-scaling-stroke"),"non-scaling-stroke"===t.style.vectorEffect}());let _=function(){const t=document.createElementNS(e.SVG,"rect").transform.baseVal,n=i.createSVGTransform();t.appendItem(n);const r=t.getItem(0),s=t=>t&&"object"==typeof t&&"function"==typeof t.setMatrix&&"angle"in t;return s(r)&&s(n)&&r.type===n.type&&r.angle===n.angle&&r.matrix.a===n.matrix.a&&r.matrix.b===n.matrix.b&&r.matrix.c===n.matrix.c&&r.matrix.d===n.matrix.d&&r.matrix.e===n.matrix.e&&r.matrix.f===n.matrix.f}();const b=()=>a,w=()=>c,A=()=>l,C=()=>h,v=()=>S,E=document.createElementNS(e.SVG,"svg");function G(t){const e=t.matrix;let n="";switch(t.type){case 1:n="matrix("+[e.a,e.b,e.c,e.d,e.e,e.f].join(",")+")";break;case 2:n="translate("+e.e+","+e.f+")";break;case 3:n=e.a===e.d?"scale("+e.a+")":"scale("+e.a+","+e.d+")";break;case 4:{let r=0,s=0;if(0!==t.angle){const t=1-e.a;s=(t*e.f+e.b*e.e)/(t*t+e.b*e.b),r=(e.e-e.b*s)/t}n="rotate("+t.angle+" "+r+","+s+")";break}}return n}let N={};class k{constructor(t){this._elem=t||null,this._xforms=[],this._update=function(){let t="";for(let e=0;e<this.numberOfItems;++e){t+=G(this._list.getItem(e))+" "}this._elem.setAttribute("transform",t)},this._list=this,this._init=function(){let t=this._elem.getAttribute("transform");if(!t)return;const e=/\s*((scale|matrix|rotate|translate)\s*\(.*?\))\s*,?\s*/;let n=!0;for(;n;)if(n=t.match(e),t=t.replace(e,""),n&&n[1]){const t=n[1].split(/\s*\(/),e=t[0],r=t[1].match(/\s*(.*?)\s*\)/);r[1]=r[1].replace(/(\d)-/g,"$1 -");const s=r[
/**
* Mathematical utilities.
* @module math
* @license MIT
*
* @copyright 2010 Alexis Deveria, 2010 Jeff Schiller
2020-07-25 17:57:19 +00:00
*/let q=null,Q=null,W=null,X=null;const K=t=>t.replace(/(<!DOCTYPE\s+\w*\s*\[).*(\?]>)/,"$1$2"),Z=function(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;")};function Y(t){if(t=tt(t),window.btoa)return window.btoa(t);const e=new Array(4*Math.floor((t.length+2)/3));let n=0,r=0;do{const s=t.charCodeAt(n++),i=t.charCodeAt(n++),o=t.charCodeAt(n++),a=s>>2,c=(3&s)<<4|i>>4;let l=(15&i)<<2|o>>6,h=63&o;Number.isNaN(i)?(l=64,h=64):Number.isNaN(o)&&(h=64),e[r++]=D.charAt(a),e[r++]=D.charAt(c),e[r++]=D.charAt(l),e[r++]=D.charAt(h)}while(n<t.length);return e.join("")}function $(t){if(window.atob)return J(window.atob(t));t=t.replace(/[^A-Za-z\d+/=]/g,"");let e="",n=0;do{const r=D.indexOf(t.charAt(n++)),s=D.indexOf(t.charAt(n++)),i=D.indexOf(t.charAt(n++)),o=D.indexOf(t.charAt(n++)),a=r<<2|s>>4,c=(15&s)<<4|i>>2,l=(3&i)<<6|o;e+=String.fromCharCode(a),64!==i&&(e+=String.fromCharCode(c)),64!==o&&(e+=String.fromCharCode(l))}while(n<t.length);return J(e)}function J(t){return decodeURIComponent(escape(t))}const tt=function(t){return unescape(encodeURIComponent(t))},et=function(t){return t&&"undefined"!=typeof URL&&URL.createObjectURL?URL.createObjectURL(t):""},nt=(function(){if("undefined"==typeof Blob)return"";const t=new Blob(["<html><head><title>SVG-edit</title></head><body>&nbsp;</body></html>"],{type:"text/html"});et(t)}(),function(t){let e,n;t.includes("<svg:svg")&&(t=t.replace(/<(\/?)svg:/g,"<$1").replace("xmlns:svg","xmlns"));try{n=window.DOMParser?new DOMParser:new window.ActiveXObject("Microsoft.XMLDOM"),n.async=!1}catch(t){throw new Error("XML Parser could not be instantiated")}try{e=n.loadXML?!!n.loadXML(t)&&n:n.parseFromString(t,"text/xml")}catch(t){throw new Error("Error parsing XML string")}return e}),rt=function(t,e){if(t&&1===t.nodeType){e(t);let n=t.childNodes.length;for(;n--;)rt(t.childNodes.item(n),e)}},st=function(t){if(t){if(t.startsWith('url("'))return t.substring(5,t.indexOf('"',6));if(t.startsWith("url('"))return t.substring(5,t.indexOf("'",6));if(t.startsWith("url("))return t.substring(4,t.indexOf(")"))}return null};let it=function(t){return t.getAttributeNS(e.XLINK,"href")},ot=function(t,n){t.setAttributeNS(e.XLINK,"xlink:href",n)};const at=function(){const t=q.getSVGContent();let n=t.getElementsByTagNameNS(e.SVG,"defs");return n.length>0?n=n[0]:(n=t.ownerDocument.createElementNS(e.SVG,"defs"),t.firstChild?t.insertBefore(n,t.firstChild.nextSibling):t.append(n)),n},ct=function(t){const e=t.pathSegList,n=e.numberOfItems,r=[[],[]],s=e.getItem(0);let i=[s.x,s.y];const o=function(t,e,n,r){return function(s){return 1-s**3*i[t]+3-s**2*s*e[t]+3*(1-s)*s**2*n[t]+s**3*r[t]}};for(let t=0;t<n;t++){const n=e.getItem(t);if(void 0!==n.x)if(r[0].push(i[0]),r[1].push(i[1]),n.x1){const t=[n.x1,n.y1],e=[n.x2,n.y2],s=[n.x,n.y];for(let n=0;n<2;n++){const a=o(n,t,e,s),c=6*i[n]-12*t[n]+6*e[n],l=-3*i[n]+9*t[n]-9*e[n]+3*s[n],h=3*t[n]-3*i[n];if(0===l){if(0===c)continue;const t=-h/c;t>0&&t<1&&r[n].push(a(t));continue}const u=c**2-4*h*l;if(u<0)continue;const d=(-c+Math.sqrt(u))/(2*l);d>0&&d<1&&r[n].push(a(d));const m=(-c-Math.sqrt(u))/(2*l);m>0&&m<1&&r[n].push(a(m))}i=s}else r[0].push(n.x),r[1].push(n.y)}const a=Math.min.apply(null,r[0]),c=Math.max.apply(null,r[0])-a,l=Math.min.apply(null,r[1]);return{x:a,y:l,width:c,height:Math.max.apply(null,r[1])-l}};function lt(t){if(x)try{return t.getBBox()}catch(t){}const e=F.data(t,"ref");let n,r,s=null;e?(r=F(e).children().clone().attr("visibility","hidden"),F(X).append(r),s=r.filter("line, path")):s=F(t).find("line, path");let i=!1;if(s.length)if(s.each((function(){const t=this.getBBox();t.width&&t.height||(i=!0)})),i){const s=e?r:F(t).children();n=yt(s)}else n=t.getBBox();else n=t.getBBox();return e&&r.remove(),n}const ht=function(t){const e=t||q.geSelectedElements()[0];if(1!==t.nodeType)return null;const n=e.nodeName;let r=null;switch(n){case"text":""===e.textContent?(e.textContent="a",r=e.getBBox(),e.textContent=""):e.getBBox&&(r=e.getBBox());break;case"path":y?e.getBBox&&(r=e.getBBox()):r=ct(e);break;case"g":case"a":r=lt(e
/**
* HistoryRecordingService component of history.
* @module history
* @license MIT
* @copyright 2016 Flint O'Brien
*/(this.group_),rt(this.group_,(function(t){t.setAttribute("style","pointer-events:inherit")})),this.group_.setAttribute("style",r?"pointer-events:all":"pointer-events:none")}getName(){return this.name_}getGroup(){return this.group_}activate(){this.group_.setAttribute("style","pointer-events:all")}deactivate(){this.group_.setAttribute("style","pointer-events:none")}setVisible(t){const e=void 0===t||t?"inline":"none";this.group_.getAttribute("display")!==e&&this.group_.setAttribute("display",e)}isVisible(){return"none"!==this.group_.getAttribute("display")}getOpacity(){const t=this.group_.getAttribute("opacity");return Nt(t)?1:Number.parseFloat(t)}setOpacity(t){"number"==typeof t&&t>=0&&t<=1&&this.group_.setAttribute("opacity",t)}appendChildren(t){for(const e of t)this.group_.append(e)}getTitleElement(){const t=this.group_.childNodes.length;for(let e=0;e<t;++e){const t=this.group_.childNodes.item(e);if(t&&"title"===t.tagName)return t}return null}setName(t,e){const n=this.name_;t=Z(t);const r=this.getTitleElement();return r?(Ve(r).empty(),r.textContent=t,this.name_=t,e&&e.changeElement(r,{"#text":n}),this.name_):null}removeGroup(){const t=this.group_;return this.group_.remove(),this.group_=void 0,t}}Oe.CLASS_NAME="layer",Oe.CLASS_REGEX=new RegExp("(\\s|^)"+Oe.CLASS_NAME+"(\\s|$)");class Me{constructor(t){this.undoManager_=t,this.currentBatchCommand_=null,this.batchCommandStack_=[]}startBatchCommand(t){return this.undoManager_?(this.currentBatchCommand_=new zt(t),this.batchCommandStack_.push(this.currentBatchCommand_),this):this}endBatchCommand(){if(!this.undoManager_)return this;if(this.currentBatchCommand_){const t=this.currentBatchCommand_;this.batchCommandStack_.pop();const{length:e}=this.batchCommandStack_;this.currentBatchCommand_=e?this.batchCommandStack_[e-1]:null,this.addCommand_(t)}return this}moveElement(t,e,n,r){return this.undoManager_?(this.addCommand_(new jt(t,e,n,r)),this):this}insertElement(t,e){return this.undoManager_?(this.addCommand_(new Ht(t,e)),this):this}removeElement(t,e,n,r){return this.undoManager_?(this.addCommand_(new Ft(t,e,n,r)),this):this}changeElement(t,e,n){return this.undoManager_?(this.addCommand_(new Dt(t,e,n)),this):this}addCommand_(t){if(!this.undoManager_)return this;this.currentBatchCommand_?this.currentBatchCommand_.addSubCommand(t):this.undoManager_.addCommandToHistory(t)}}Me.NO_HISTORY=new Me;const Re=t(jQuery),Be=function(t,e){const n=document.createElementNS(t.namespaceURI,t.nodeName);if(Re.each(t.attributes,(function(t,e){"-moz-math-font-style"!==e.localName&&n.setAttributeNS(e.namespaceURI,e.nodeName,e.value)})),n.removeAttribute("id"),n.id=e(),b()&&"path"===t.nodeName){const e=Ie(t);n.setAttribute("d",e)}if(Re.each(t.childNodes,(function(t,r){switch(r.nodeType){case 1:n.append(Be(r,e));break;case 3:n.textContent=r.nodeValue}})),Re(t).data("gsvg"))Re(n).data("gsvg",n.firstChild);else if(Re(t).data("symbol")){const e=Re(t).data("symbol");Re(n).data("ref",e).data("symbol",e)}else"image"===n.tagName&&Gt(n);return n},Ue=jQuery,je="a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use".split(","),He=1,Fe=2;let De=0,ze=[];function qe(t){return t||new Me(Ze.undoMgr)}function Qe(t){return Ue("title",t).text()||(o&&t.querySelectorAll?Ue(t.querySelectorAll("title")).text():"")}function We(t){let e=1;for(;t.includes("Layer "+e);)e++;return"Layer "+e}class Xe{constructor(t,n){if(!t||!t.tagName||!t.namespaceURI||"svg"!==t.tagName||t.namespaceURI!==e.SVG)throw new Error("Error: svgedit.draw.Drawing instance initialized without a <svg> element");this.svgElem_=t,this.obj_num=0,this.idPrefix=n||"svg_",this.releasedNums=[],this.all_layers=[],this.layer_map={},this.current_layer=null,this.nonce_="";const r=this.svgElem_.getAttributeNS(e.SE,"nonce");r&&De!==Fe?this.nonce_=r:De===He&&this.setNonce(Math.floor(100001*Math.random()))}getElem_(t){return this.svgElem_.querySelector?this.svgElem_.querySelector("#"+t):Ue(this.svgElem_).find("[id="+t+"]")[0]}getSvgElem(){return this.svgElem_}getNonce(){return this.nonce_}setNonce(t){this.svgElem_.setAttributeNS(e.XM
/**
* Adapted from {@link https://github.com/uupaa/dynamic-import-polyfill/blob/master/importModule.js}.
* @module importModule
* @license MIT
*/function pn(t,e){["id","class","type"].forEach(n=>{n in e&&(t[n]=e[n])})}async function fn(t,{global:e,returnDefault:n}){return"svgEditor"in window&&window.svgEditor&&!1===window.svgEditor.modules?(await yn(t),window[e]):function t(e,n={},{returnDefault:r=!1}={}){if(Array.isArray(e))return Promise.all(e.map(e=>t(e,n)));return new Promise((t,s)=>{const i="$importModule$"+Math.random().toString(32).slice(2),o=document.createElement("script");function a(){s(new Error("Failed to import: "+e)),l()}function c(){t(window[i]),l()}const l=()=>{delete window[i],o.removeEventListener("error",a),o.removeEventListener("load",c),o.remove(),URL.revokeObjectURL(o.src),o.src=""};pn(o,n),o.defer="defer",o.type="module",o.addEventListener("error",a),o.addEventListener("load",c);const h=`import * as m from '${function(t){const e=document.createElement("a");return e.setAttribute("href",t),e.cloneNode(!1).href}(e).replace(/'/g,"\\'")}'; window.${i} = ${r?"m.default || ":""}m;`,u=new Blob([h],{type:"text/javascript"});o.src=URL.createObjectURL(u),document.head.append(o)})}(t,void 0,{returnDefault:n})}function yn(t,e={}){return Array.isArray(t)?Promise.all(t.map(t=>yn(t,e))):new Promise((n,r)=>{const s=document.createElement("script");function i(){r(new Error("Failed to import: "+t)),a()}function o(){n(),a()}const a=()=>{s.removeEventListener("error",i),s.removeEventListener("load",o),s.remove(),s.src=""};s.defer="defer",pn(s,e),s.addEventListener("error",i),s.addEventListener("load",o),s.src=t,document.head.append(s)})}const xn=jQuery,Sn=[0,"z","M","m","L","l","C","c","Q","q","A","a","H","h","V","v","S","s","T","t"];let _n=null;const bn=function(t,e,n){const r=function(t,e){return L(t,e,n)},s=function(t){return n.a*t},i=function(t){return n.d*t},o=_n.getGridSnapping()&&"svg"===t.parentNode.parentNode.localName,a=function(){o&&Object.entries(e).forEach(([t,n])=>{e[t]=Et(n)}),Ct(t,e,0,!0)},c=ht(t);for(let e=0;e<2;e++){const r=0===e?"fill":"stroke",s=t.getAttribute(r);if(s&&s.startsWith("url(")&&(n.a<0||n.d<0)){const e=wt(s).cloneNode(!0);if(n.a<0){const t=e.getAttribute("x1"),n=e.getAttribute("x2");e.setAttribute("x1",-(t-1)),e.setAttribute("x2",-(n-1))}if(n.d<0){const t=e.getAttribute("y1"),n=e.getAttribute("y2");e.setAttribute("y1",-(t-1)),e.setAttribute("y2",-(n-1))}e.id=_n.getDrawing().getNextId(),at().append(e),t.setAttribute(r,"url(#"+e.id+")")}}const l=t.tagName;if("g"===l||"text"===l||"tspan"===l||"use"===l)if(1!==n.a||0!==n.b||0!==n.c||1!==n.d||0===n.e&&0===n.f){const e=P(t),r=_n.getSVGRoot().createSVGTransform();r.setMatrix(O(B(e).matrix,n)),e.clear(),e.appendItem(r)}else{const r=B(t).matrix,s=O(r.inverse(),n,r);e.x=Number.parseFloat(e.x)+s.e,e.y=Number.parseFloat(e.y)+s.f}switch(l){case"foreignObject":case"rect":case"image":if("image"===l&&(n.a<0||n.d<0)){const e=P(t),r=_n.getSVGRoot().createSVGTransform();r.setMatrix(O(B(e).matrix,n)),e.clear(),e.appendItem(r)}else{const t=r(e.x,e.y);e.width=s(e.width),e.height=i(e.height),e.x=t.x+Math.min(0,e.width),e.y=t.y+Math.min(0,e.height),e.width=Math.abs(e.width),e.height=Math.abs(e.height)}a();break;case"ellipse":{const t=r(e.cx,e.cy);e.cx=t.x,e.cy=t.y,e.rx=s(e.rx),e.ry=i(e.ry),e.rx=Math.abs(e.rx),e.ry=Math.abs(e.ry),a();break}case"circle":{const t=r(e.cx,e.cy);e.cx=t.x,e.cy=t.y;const s=R(c.x,c.y,c.width,c.height,n),i=s.tr.x-s.tl.x,o=s.bl.y-s.tl.y;e.r=Math.min(i/2,o/2),e.r&&(e.r=Math.abs(e.r)),a();break}case"line":{const t=r(e.x1,e.y1),n=r(e.x2,e.y2);e.x1=t.x,e.y1=t.y,e.x2=n.x,e.y2=n.y}case"text":case"tspan":case"use":a();break;case"g":{const n=xn(t).data("gsvg");n&&Ct(n,e,0,!0);break}case"polyline":case"polygon":{const n=e.points.length;for(let t=0;t<n;++t){const n=e.points[t],{x:s,y:i}=r(n.x,n.y);e.points[t].x=s,e.points[t].y=i}let s="";for(let t=0;t<n;++t){const n=e.points[t];s+=n.x+","+n.y+" "}t.setAttribute("points",s);break}case"path":{const n=t.pathSegList;let o=n.numberOfItems;e.d=[];for(let t=0;t<o;++t){const r=n.getItem(t);e.d[t]={type:r.pathSegType,x:r.x,y:r.y,x1:r.x1,y1:r.y1,x2:r.x2,y2:r.y2,r1:r.r1,r2:r.r2,angle:r.angle,largeArcFlag:r.largeArcFlag,sweepFlag:r.sweepFlag}}o=e
//# sourceMappingURL=svgcanvas-iife.min.js.map