-
Notifications
You must be signed in to change notification settings - Fork 8
/
svg.js
1 lines (1 loc) · 30.1 KB
/
svg.js
1
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).SVG=t()}(this,(function(){"use strict";const e="object"==typeof window&&"object"==typeof window.document;"object"==typeof process&&"object"==typeof process.versions&&(null!=process.versions.node||process.versions.bun);const t="window not set; svg.window = @xmldom/xmldom",r={window:void 0};e&&(r.window=window);const n=()=>{if(void 0===r.window)throw new Error(t);return r.window},o="http://www.w3.org/2000/svg",a={presentation:["color","color-interpolation","cursor","direction","display","fill","fill-opacity","fill-rule","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","image-rendering","letter-spacing","opacity","overflow","paint-order","pointer-events","preserveAspectRatio","shape-rendering","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","tabindex","transform-origin","user-select","vector-effect","visibility"],animation:["accumulate","additive","attributeName","begin","by","calcMode","dur","end","from","keyPoints","keySplines","keyTimes","max","min","repeatCount","repeatDur","restart","to","values"],effects:["azimuth","baseFrequency","bias","color-interpolation-filters","diffuseConstant","divisor","edgeMode","elevation","exponent","filter","filterRes","filterUnits","flood-color","flood-opacity","in","in2","intercept","k1","k2","k3","k4","kernelMatrix","lighting-color","limitingConeAngle","mode","numOctaves","operator","order","pointsAtX","pointsAtY","pointsAtZ","preserveAlpha","primitiveUnits","radius","result","seed","specularConstant","specularExponent","stdDeviation","stitchTiles","surfaceScale","targetX","targetY","type","xChannelSelector","yChannelSelector"],text:["dx","dy","alignment-baseline","baseline-shift","dominant-baseline","lengthAdjust","method","overline-position","overline-thickness","rotate","spacing","startOffset","strikethrough-position","strikethrough-thickness","text-anchor","text-decoration","text-rendering","textLength","underline-position","underline-thickness","word-spacing","writing-mode"],gradient:["gradientTransform","gradientUnits","spreadMethod"]},i={svg:["svg"],defs:["defs"],header:["desc","filter","metadata","style","script","title","view"],cdata:["cdata"],group:["g"],visible:["circle","ellipse","line","path","polygon","polyline","rect","arc","arrow","curve","parabola","roundRect","wedge","origami"],text:["text"],invisible:["marker","symbol","clipPath","mask"],patterns:["linearGradient","radialGradient","pattern"],childrenOfText:["textPath","tspan"],gradients:["stop"],filter:["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]},s="class",l="function",c="number",f="string",d="object",u="svg",p="path",h="id",m="style",g="viewBox",b="transform",y="points",v="stroke",w="none",x="arrow",k="head",A="tail",E={svg:[g],line:["x1","y1","x2","y2"],rect:["x","y","width","height"],circle:["cx","cy","r"],ellipse:["cx","cy","rx","ry"],polygon:[y],polyline:[y],path:["d"],text:["x","y"],mask:[h],symbol:[h],clipPath:[h,"clip-rule"],marker:[h,"markerHeight","markerUnits","markerWidth","orient","refX","refY"],linearGradient:["x1","x2","y1","y2"],radialGradient:["cx","cy","r","fr","fx","fy"],stop:["offset","stop-color","stop-opacity"],pattern:["patternContentUnits","patternTransform","patternUnits"]};[{nodes:[u,"defs","g"].concat(i.visible,i.text),attr:a.presentation},{nodes:["filter"],attr:a.effects},{nodes:i.childrenOfText.concat("text"),attr:a.text},{nodes:i.filter,attr:a.effects},{nodes:i.gradients,attr:a.gradient}].forEach((e=>e.nodes.forEach((t=>{E[t]||(E[t]=[]),E[t].push(...e.attr)}))));const C=[i.header,i.invisible,i.patterns].flat(),j=[i.group,i.visible,i.text].flat(),M={svg:[["svg","defs"],C,j].flat(),defs:C,filter:i.filter,g:j,text:i.childrenOfText,marker:j,symbol:j,clipPath:j,mask:j,linearGradient:i.gradients,radialGradient:i.gradients},O={black:"#000000",silver:"#c0c0c0",gray:"#808080",white:"#ffffff",maroon:"#800000",red:"#ff0000",purple:"#800080",fuchsia:"#ff00ff",green:"#008000",lime:"#00ff00",olive:"#808000",yellow:"#ffff00",navy:"#000080",blue:"#0000ff",teal:"#008080",aqua:"#00ffff",orange:"#ffa500",aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",blanchedalmond:"#ffebcd",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",oldlace:"#fdf5e6",olivedrab:"#6b8e23",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",whitesmoke:"#f5f5f5",yellowgreen:"#9acd32"},_=(e,t,r,n)=>{const o=r/100,a=t=>(t+e/30)%12,i=t/100*Math.min(o,1-o),s=e=>o-i*Math.max(-1,Math.min(a(e)-3,Math.min(9-a(e),1)));return void 0===n?[255*s(0),255*s(8),255*s(4)]:[255*s(0),255*s(8),255*s(4),n]},P=(e,t)=>{const r=Array.from(Array(t.length)).map(((t,r)=>e[r]||"0"));return e.length<=4?t.map((e=>r[e])).join(""):r.join("")},$=e=>{const t=e.replace(/#(?=\S)/g,""),r=4===t.length||8===t.length,n=P(t,r?[0,0,1,1,2,2,3,3]:[0,0,1,1,2,2]),o=parseInt(n,16);return r?[o>>24&255,o>>16&255,o>>8&255,(a=(255&o)/256,Math.round(100*a)/100)]:[o>>16&255,o>>8&255,255&o];var a},N=(e,t,r,n)=>{const o=e=>`00${Math.max(0,Math.min(Math.round(e),255)).toString(16)}`.slice(-2),a=`#${[e,t,r].map(o).join("")}`;return void 0===n?a:`${a}${o(255*n)}`},S=Object.freeze({__proto__:null,hexToRgb:$,hslToRgb:_,rgbToHex:N}),T=e=>{const t=e.match(/\(([^\)]+)\)/g);return null!=t&&t.length?t[0].substring(1,t[0].length-1).split(/[\s,]+/).map(parseFloat):[]},z=Object.freeze({__proto__:null,parseColorToHex:e=>{if(O[e])return O[e].toUpperCase();if("#"===e[0]){const[t,r,n,o]=$(e);return N(t,r,n,o)}if("rgba"===e.substring(0,4)||"rgb"===e.substring(0,3)){const[t,r,n,o]=T(e);return N(t,r,n,o)}if("hsla"===e.substring(0,4)||"hsl"===e.substring(0,3)){const t=T(e);[0,1,2].filter((e=>void 0===t[e])).forEach((e=>{t[e]=0}));const[r,n,o,a]=t,[i,s,l]=_(r,n,o,a);return N(i,s,l,a)}},parseColorToRgb:e=>{if(O[e])return $(O[e]);if("#"===e[0])return $(e);if("rgba"===e.substring(0,4)||"rgb"===e.substring(0,3)){const t=T(e);return[0,1,2].filter((e=>void 0===t[e])).forEach((e=>{t[e]=0})),t}if("hsla"===e.substring(0,4)||"hsl"===e.substring(0,3)){const t=T(e);return[0,1,2].filter((e=>void 0===t[e])).forEach((e=>{t[e]=0})),_(t[0],t[1],t[2],t[3])}}}),q={cssColors:O,...S,...z},B=(e,t)=>[e[0]+t[0],e[1]+t[1]],L=(e,t)=>[e[0]-t[0],e[1]-t[1]],F=(e,t)=>[e[0]*t,e[1]*t],U=e=>e[0]**2+e[1]**2,D=e=>Math.sqrt(U(e)),R=(e,t)=>U(L(e,t)),V=(e,t)=>Math.sqrt(R(e,t)),G=(e,t)=>[Math.cos(e)*t,Math.sin(e)*t],Z=(e,t)=>[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]],H=Object.freeze({__proto__:null,svg_add2:B,svg_distance2:V,svg_distanceSq2:R,svg_magnitude2:D,svg_magnitudeSq2:U,svg_multiplyMatrices2:Z,svg_polar_to_cart:G,svg_scale2:F,svg_sub2:L}),I=e=>{const t=e.match(/(\w+\((\-?\d+\.?\d*e?\-?\d*,?\s*)+\))+/g);if(!t)return[];return t.map((e=>e.match(/[\w\.\-]+/g))).map((e=>({transform:e.shift(),parameters:e.map((e=>parseFloat(e)))})))},Y=function(e,t){switch(e){case"translate":return function(e){switch(e.length){case 1:return[1,0,0,1,e[0],0];case 2:return[1,0,0,1,e[0],e[1]];default:console.warn(`improper translate, ${e}`)}}(t);case"rotate":return function(e){const t=Math.cos(e[0]/(180*Math.PI)),r=Math.sin(e[0]/(180*Math.PI));switch(e.length){case 1:return[t,r,-r,t,0,0];case 3:return[t,r,-r,t,-e[1]*t+e[2]*r+e[1],-e[1]*r-e[2]*t+e[2]];default:console.warn(`improper rotate, ${e}`)}}(t);case"scale":return function(e){switch(e.length){case 1:return[e[0],0,0,e[0],0,0];case 2:return[e[0],0,0,e[1],0,0];default:console.warn(`improper scale, ${e}`)}}(t);case"skewX":return function(e){return[1,0,Math.tan(e[0]/(180*Math.PI)),1,0,0]}(t);case"skewY":return function(e){return[1,Math.tan(e[0]/(180*Math.PI)),0,1,0,0]}(t);case"matrix":return t;default:console.warn(`unknown transform type ${e}`)}},X=function(e){return I(e).map((e=>Y(e.transform,e.parameters))).filter((e=>void 0!==e)).reduce(((e,t)=>Z(e,t)),[1,0,0,1,0,0])},Q=Object.freeze({__proto__:null,parseTransform:I,transformStringToMatrix:X}),W=(e,t)=>{if((e.nodeName||"")===t)return e;const r=e.parentElement;return r?W(r,t):null},J=e=>null!=e.childNodes&&e.childNodes.length?Array.from(e.childNodes).flatMap((e=>J(e))):[e],K={svg:["viewBox","xmlns","version"],line:["x1","y1","x2","y2"],rect:["x","y","width","height"],circle:["cx","cy","r"],ellipse:["cx","cy","rx","ry"],polygon:["points"],polyline:["points"],path:["d"]},ee=(e,t)=>{const r=(e=>{const t={};return e.forEach((e=>{t[e.nodeName]=e.value})),t})((e=>{const t=e.attributes;if(null==t)return[];const r=Array.from(t);return K[e.nodeName]?r.filter((t=>!K[e.nodeName].includes(t.name))):r})(t));if(!r.transform&&!e.transform)return{...e,...r};const n=r.transform||"",o=e.transform||"",a=X(n),i=X(o),s=`matrix(${Z(i,a).join(", ")})`;return{...e,...r,transform:s}},te=(e,t={})=>null!=e.childNodes&&e.childNodes.length?Array.from(e.childNodes).flatMap((e=>te(e,ee(t,e)))):[{element:e,attributes:t}],re=Object.freeze({__proto__:null,addClass:(e,...t)=>{if(e&&t.length)return e.classList?e.classList.add(...t):((e,...t)=>{const r={},n=e.getAttribute("class"),o=n?n.split(" "):[];o.push(...t),o.forEach((e=>{r[e]=!0}));const a=Object.keys(r).join(" ");e.setAttribute("class",a)})(e,...t)},findElementTypeInParents:W,flattenDomTree:J,flattenDomTreeWithStyle:te,getRootParent:e=>{let t=e;for(;t&&null!=t.parentElement;)t=t.parentElement;return t},xmlStringToElement:(e,t="text/xml")=>{const r=(new(n().DOMParser)).parseFromString(e,t);return r?r.documentElement:null}}),ne=e=>(new(n().DOMParser)).parseFromString("<root></root>","text/xml").createCDATASection(e),oe=Object.freeze({__proto__:null,makeCDATASection:ne}),ae=/[MmLlSsQqLlHhVvCcSsQqTtAaZz]/g,ie=/-?[0-9]*\.?\d+/g,se={m:"move",l:"line",v:"vertical",h:"horizontal",a:"ellipse",c:"curve",s:"smoothCurve",q:"quadCurve",t:"smoothQuadCurve",z:"close"};Object.keys(se).forEach((e=>{const t=se[e];se[e.toUpperCase()]=t.charAt(0).toUpperCase()+t.slice(1)}));const le=(e,t)=>[e[0]+(t[0]||0),e[1]+(t[1]||0)],ce=e=>{const t=[];let r=ae.exec(e);for(;null!==r;)t.push(r),r=ae.exec(e);return t.map(((t,r,n)=>({command:t[0],start:t.index,end:r===n.length-1?e.length-1:n[(r+1)%n.length].index-1}))).map((({command:t,start:r,end:n})=>{const o=e.substring(r+1,n+1).match(ie);return{command:t,values:o?o.map(parseFloat):[]}}))},fe=(...e)=>e.filter((e=>typeof e===c)).concat(e.filter((e=>typeof e===d&&null!==e)).map((e=>typeof e.x===c?[e.x,e.y]:typeof e[0]===c?[e[0],e[1]]:void 0)).filter((e=>void 0!==e)).reduce(((e,t)=>e.concat(t)),[])),de=(...e)=>{const t=fe(...e.flat());return 2===t.length&&t.unshift(0,0),4===t.length?function(e,t,r,n,o=0){const a=r/1-r;return[e-a-o,t-a-o,r+2*a+2*o,n+2*a+2*o].join(" ")}(t[0],t[1],t[2],t[3]):void 0},ue=(e,...t)=>{const r=1===t.length&&typeof t[0]===f?t[0]:de(...t);return r&&e.setAttribute(g,r),e},pe=function(e){const t=e.getAttribute(g);return null==t?void 0:t.split(" ").map((e=>parseFloat(e)))},he=function(e,t,r){const n=e.createSVGPoint();n.x=t,n.y=r;const o=n.matrixTransform(e.getScreenCTM().inverse());return[o.x,o.y]},me={...H,...re,...oe,...Object.freeze({__proto__:null,parsePathCommands:ce,parsePathCommandsWithEndpoints:e=>{let t=[0,0];const r=ce(e).map((e=>({...e,end:void 0,start:void 0})));if(!r.length)return r;r.forEach(((e,n)=>{r[n].end=((e,t,r=[0,0])=>{const n=e.toUpperCase();let o=e===n?[0,0]:r;switch("V"===e&&(o=[r[0],0]),"H"===e&&(o=[0,r[1]]),n){case"V":return le(o,[0,t[0]]);case"H":return le(o,[t[0],0]);case"M":case"L":case"T":return le(o,t);case"A":return le(o,[t[5],t[6]]);case"C":return le(o,[t[4],t[5]]);case"S":case"Q":return le(o,[t[2],t[3]]);case"Z":return;default:return o}})(e.command,e.values,t),r[n].start=0===n?t:r[n-1].end,t=r[n].end}));const n=r[r.length-1],o=r.filter((e=>"M"!==e.command.toUpperCase()&&"Z"!==e.command.toUpperCase())).shift();return"Z"===n.command.toUpperCase()&&(n.end=[...o.start]),r},pathCommandNames:se}),...Q,...Object.freeze({__proto__:null,convertToViewBox:he,foldToViewBox:({vertices_coords:e})=>{if(!e)return;const t=[1/0,1/0],r=[-1/0,-1/0];return e.forEach((e=>[0,1].forEach((n=>{t[n]=Math.min(e[n],t[n]),r[n]=Math.max(e[n],r[n])})))),[t[0],t[1],r[0]-t[0],r[1]-t[1]].join(" ")},getViewBox:pe,setViewBox:ue})},ge=function(e){const t=pe(e);if(void 0!==t)return t;if(typeof e.getBoundingClientRect===l){const t=e.getBoundingClientRect();return[t.x,t.y,t.width,t.height]}return[]},be="svg-background-rectangle",ye=e=>{const t=e.getAttribute(b);return null==t||""===t?void 0:t},ve={clearTransform:e=>(e.removeAttribute(b),e)};["translate","rotate","scale","matrix"].forEach((e=>{ve[e]=(t,...r)=>(t.setAttribute(b,[ye(t),`${e}(${r.join(" ")})`].filter((e=>void 0!==e)).join(" ")),t)}));const we=()=>Math.random().toString(36).replace(/[^a-z]+/g,"").concat("aaaaa").substring(0,5),xe=e=>e.replace(/([-_][a-z])/gi,(e=>e.toUpperCase().replace("-","").replace("_",""))),ke=e=>{for(;e.lastChild;)e.removeChild(e.lastChild);return e},Ae=(e,t)=>(t&&t.appendChild&&t.appendChild(e),e),Ee=(e,t)=>(Object.keys(t).forEach((r=>e.setAttribute(r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z])(?=[a-z])/g,"$1-$2").toLowerCase(),t[r]))),e),Ce=Object.freeze({__proto__:null,appendTo:Ae,removeChildren:ke,setAttributes:Ee}),je=function(e,t){let r=function(e,t){const r=e.getElementsByTagName(t);return r.length?r[0]:null}(e,m);return null==r&&(r=n().document.createElementNS(o,m),r.setTextContent=e=>(r.textContent="",r.appendChild(ne(e)),r),e.insertBefore(r,e.firstChild)),r.textContent="",r.appendChild(ne(t)),r},Me={clear:e=>(Array.from(e.attributes).filter((e=>"xmlns"!==e.name&&"version"!==e.name)).forEach((t=>e.removeAttribute(t.name))),ke(e)),size:ue,setViewBox:ue,getViewBox:pe,padding:function(e,t){const r=pe(e);return void 0!==r&&ue(e,...[-t,-t,2*t,2*t].map(((e,t)=>r[t]+e))),e},background:function(e,t){let r=Array.from(e.childNodes).filter((e=>e.getAttribute(s)===be)).shift();return null==r&&(r=n().document.createElementNS(o,"rect"),ge(e).forEach(((e,t)=>r.setAttribute(E.rect[t],e))),r.setAttribute(s,be),r.setAttribute(v,w),e.insertBefore(r,e.firstChild)),r.setAttribute("fill",t),e},getWidth:e=>ge(e)[2],getHeight:e=>ge(e)[3],stylesheet:function(e,t){return je.call(this,e,t)},...ve,...Ce},Oe={move:["mousemove","touchmove"],press:["mousedown","touchstart"],release:["mouseup","touchend"],leave:["mouseleave","touchcancel"]},_e=(e,t,r)=>Object.defineProperty(e,t,{get:()=>r,enumerable:!0,configurable:!0}),Pe=function(e){const t=[];Object.keys(Oe).forEach((e=>{Oe[e].forEach((e=>{t[e]=[]}))}));Object.keys(Oe).forEach((r=>{var n;Object.defineProperty(e,`on${n=r,n.charAt(0).toUpperCase()+n.slice(1)}`,{set:n=>{e.addEventListener&&(null!=n?Oe[r].forEach((r=>{const o=t=>{const r=null!=t.touches?t.touches[0]:t;if(void 0!==r){const{clientX:n,clientY:o}=r,[a,i]=he(e,n,o);_e(t,"x",a),_e(t,"y",i)}n(t)};t[r].push(o),e.addEventListener(r,o)})):(r=>{Oe[r].forEach((r=>t[r].forEach((t=>e.removeEventListener(r,t)))))})(r))},enumerable:!0})})),Object.defineProperty(e,"off",{value:()=>((e,t)=>Object.values(Oe).flat().forEach((r=>{t[r].forEach((t=>e.removeEventListener(r,t))),t[r]=[]})))(e,t)})},$e=[["cx","cy"],["x","y"]],Ne=function(e){const t=[0,0],r={selected:!1,svg:void 0,updatePosition:e=>e},n=()=>{r.svg&&(r.svg.parentNode||e.appendChild(r.svg),$e.filter((e=>null!=r.svg[e[0]])).forEach((e=>e.forEach(((e,n)=>{r.svg.setAttribute(e,t[n])})))))},o=new Proxy(t,{set:(e,t,r)=>(e[t]=r,n(),!0)}),a=function(...e){fe(...e.flat()).forEach(((e,r)=>{t[r]=e})),n(),typeof t.delegate===l&&t.delegate.apply(t.pointsContainer,[o,t.pointsContainer])};return t.delegate=void 0,t.setPosition=a,t.onMouseMove=e=>r.selected?a(r.updatePosition(e)):void 0,t.onMouseUp=()=>{r.selected=!1},t.distance=e=>Math.sqrt(R(e,t)),["x","y"].forEach(((e,r)=>Object.defineProperty(t,e,{get:()=>t[r],set:e=>{t[r]=e}}))),[u,"updatePosition","selected"].forEach((e=>Object.defineProperty(t,e,{get:()=>r[e],set:t=>{r[e]=t}}))),Object.defineProperty(t,"remove",{value:()=>{(e=>{e&&e.parentNode&&e.parentNode.removeChild(e)})(r.svg),t.delegate=void 0}}),o},Se=function(e,t,r){let n,o;const a=Array.from(Array(t)).map((()=>Ne(e))),i=e=>typeof o===l?o.call(a,e,n,a):void 0;a.forEach((e=>{e.delegate=i,e.pointsContainer=a}));e.onPress=function(e){a.length>0&&(n=a.map(((t,r)=>({i:r,d:R(t,[e.x,e.y])}))).sort(((e,t)=>e.d-t.d)).shift().i,a[n].selected=!0)},e.onMove=function(e){a.forEach((t=>t.onMouseMove(e)))},e.onRelease=function(){a.forEach((e=>e.onMouseUp())),n=void 0},Object.defineProperty(a,"selectedIndex",{get:()=>n}),Object.defineProperty(a,"selected",{get:()=>a[n]}),Object.defineProperty(a,"add",{value:t=>{a.push(Ne(e))}}),a.removeAll=()=>{for(;a.length>0;)a.pop().remove()};const s={onChange:(e,t)=>{if(o=e,!0===t){const t=a.length-1;e.call(a,a[t],t,a)}},position:e=>a.forEach(((t,r)=>t.setPosition(e.call(a,t,r,a)))),svg:e=>a.forEach(((t,r)=>{t.svg=e.call(a,t,r,a)}))};return Object.keys(s).forEach((e=>{a[e]=function(){return typeof arguments[0]===l&&s[e](...arguments),a}})),a.parent=function(e){return null!=e&&null!=e.appendChild&&a.forEach((t=>{e.appendChild(t.svg)})),a},a},Te=e=>{e.controls=(...t)=>Se.call(e,e,...t)},ze={svg:{args:(...e)=>[de(fe(...e))].filter((e=>null!=e)),methods:Me,init:(...e)=>{const t=n().document.createElementNS(o,"svg");return t.setAttribute("version","1.1"),t.setAttribute("xmlns",o),e.filter((e=>null!=e)).filter((e=>e.appendChild)).forEach((e=>e.appendChild(t))),Pe(t),function(e){let t,r,o=0;const a={},i=()=>{n().cancelAnimationFrame&&n().cancelAnimationFrame(r),Object.keys(a).forEach((e=>delete a[e]))};Object.defineProperty(e,"play",{set:e=>{if(i(),!e||!n().requestAnimationFrame)return;t=performance.now(),o=0;const s=we();a[s]=i=>{e({time:.001*(i-t),frame:o}),o+=1,a[s]&&(r=n().requestAnimationFrame(a[s]))},r=n().requestAnimationFrame(a[s])},enumerable:!0}),Object.defineProperty(e,"stop",{value:i,enumerable:!0})}(t),Te(t),t}}},qe={};["clip-path","mask","symbol","marker-end","marker-mid","marker-start"].forEach((e=>{qe[xe(e)]=(t,r)=>(t.setAttribute(e,function(e){if(null==e)return"";if(typeof e===f)return"url"===e.slice(0,3)?e:`url(#${e})`;if(null!=e.getAttribute)return`url(#${e.getAttribute(h)})`;return""}(r)),t)}));const Be={g:{methods:{...ve,...qe,...Ce}}},Le=(e,t)=>(e.setAttribute(E.circle[2],t),e),Fe=(e,t,r)=>([...fe(...[t,r].flat()).slice(0,2)].forEach(((t,r)=>e.setAttribute(E.circle[r],t))),e),Ue={circle:{args:(e,t,r,n)=>{const o=fe(...[e,t,r,n].flat());switch(o.length){case 0:case 1:return[,,...o];case 2:case 3:return o;default:return((e,t,r,n)=>[e,t,V([e,t],[r,n])])(...o)}},methods:{radius:Le,setRadius:Le,origin:Fe,setOrigin:Fe,center:Fe,setCenter:Fe,position:Fe,setPosition:Fe,...ve,...qe,...Ce}}},De=(e,t,r)=>([,,t,r].forEach(((t,r)=>e.setAttribute(E.ellipse[r],t))),e),Re=(e,t,r)=>([...fe(...[t,r].flat()).slice(0,2)].forEach(((t,r)=>e.setAttribute(E.ellipse[r],t))),e),Ve={ellipse:{args:(e,t,r,n)=>{const o=fe(...[e,t,r,n].flat()).slice(0,4);switch(o.length){case 0:case 1:case 2:return[,,...o];default:return o}},methods:{radius:De,setRadius:De,origin:Re,setOrigin:Re,center:Re,setCenter:Re,position:Re,setPosition:Re,...ve,...qe,...Ce}}},Ge=e=>null!=e&&typeof e[Symbol.iterator]===l,Ze=function(){switch(arguments.length){case 0:return Array.from(arguments);case 1:return Ge(arguments[0])&&typeof arguments[0]!==f?Ze(...arguments[0]):[arguments[0]];default:return Array.from(arguments).map((e=>Ge(e)?[...Ze(e)]:e))}},He=(...e)=>fe(...Ze(...e)).slice(0,4),Ie={line:{args:He,methods:{setPoints:(e,...t)=>(He(...t).forEach(((t,r)=>e.setAttribute(E.line[r],t))),e),...ve,...qe,...Ce}}},Ye=e=>{const t=e.getAttribute("d");return null==t?"":t},Xe=(e,t,...r)=>(e.setAttribute("d",`${Ye(e)}${t}${r.flat().join(" ")}`),e),Qe=e=>ce(Ye(e)),We={addCommand:Xe,appendCommand:Xe,clear:e=>(e.removeAttribute("d"),e),getCommands:Qe,get:Qe,getD:e=>e.getAttribute("d"),...ve,...qe,...Ce};Object.keys(se).forEach((e=>{We[se[e]]=(t,...r)=>Xe(t,e,...r)}));const Je={path:{methods:We}},Ke=(e,t,r)=>([,,t,r].forEach(((t,r)=>e.setAttribute(E.rect[r],t))),e),et=(e,t,r)=>([...fe(...[t,r].flat()).slice(0,2)].forEach(((t,r)=>e.setAttribute(E.rect[r],t))),e),tt=function(e){return[0,1].forEach((t=>{e[2+t]<0&&(void 0===e[0+t]&&(e[0+t]=0),e[0+t]+=e[2+t],e[2+t]=-e[2+t])})),e},rt={rect:{args:(e,t,r,n)=>{const o=fe(...[e,t,r,n].flat()).slice(0,4);switch(o.length){case 0:case 1:case 2:case 3:return tt([,,...o]);default:return tt(o)}},methods:{origin:et,setOrigin:et,center:et,setCenter:et,size:Ke,setSize:Ke,...ve,...qe,...Ce}}},nt={style:{init:e=>{const t=n().document.createElementNS(o,"style");return t.setAttribute("type","text/css"),t.textContent="",t.appendChild(ne(e)),t},methods:{setTextContent:(e,t)=>(e.textContent="",e.appendChild(ne(t)),e)}}},ot={text:{args:(e,t,r)=>fe(...[e,t,r].flat()).slice(0,2),init:(e,t,r,a)=>{const i=n().document.createElementNS(o,"text"),s=[e,t,r,a].filter((e=>typeof e===f)).shift();return i.appendChild(n().document.createTextNode(s||"")),i},methods:{...ve,...qe,appendTo:Ae,setAttributes:Ee}}},at=function(){return Array.from(arguments).filter((e=>typeof e===f||e instanceof String)).shift()||we()},it=(...e)=>[at(...e)],st={mask:{args:it,methods:{...ve,...qe,...Ce}},clipPath:{args:it,methods:{...ve,...qe,...Ce}},symbol:{args:it,methods:{...ve,...qe,...Ce}},marker:{args:it,methods:{size:ue,setViewBox:ue,...ve,...qe,...Ce}}},lt=e=>{const t=e.getAttribute(y);return null==t?"":t},ct=function(){return Array.from(Array(Math.floor(arguments.length/2))).map(((e,t)=>`${arguments[2*t+0]},${arguments[2*t+1]}`)).join(" ")},ft=(...e)=>[ct(...fe(...Ze(...e)))],dt=(e,...t)=>(e.setAttribute(y,ft(...t)[0]),e),ut=(e,...t)=>(e.setAttribute(y,[lt(e),ft(...t)[0]].filter((e=>""!==e)).join(" ")),e),pt=function(...e){return 1===e.length&&typeof e[0]===f?[e[0]]:ft(...e)},ht={polyline:{args:pt,methods:{setPoints:dt,addPoint:ut,...ve,...qe,...Ce}},polygon:{args:pt,methods:{setPoints:dt,addPoint:ut,...ve,...qe,...Ce}}},mt=(e,t,r,n,o,a=!1)=>{if(null==o)return"";const i=G(n,r),s=G(o,r),l=[s[0]-i[0],s[1]-i[1]],c=i[0]*s[1]-i[1]*s[0],f=i[0]*s[0]+i[1]*s[1],d=Math.atan2(c,f)>0?0:1;let u=a?`M ${e},${t} l ${i[0]},${i[1]} `:`M ${e+i[0]},${t+i[1]} `;return u+=["a ",r,r,0,d,1,l[0],l[1]].join(" "),a&&(u+=" Z"),u},gt=(e,t,r,n,o)=>[mt(e,t,r,n,o,!1)],bt={arc:{nodeName:p,attributes:["d"],args:gt,methods:{setArc:(e,...t)=>e.setAttribute("d",gt(...t)),...ve}}},yt=[A,k],vt=e=>e.join(","),wt=e=>"M"+e.map((e=>e.join(","))).join("L")+"Z",xt=(e,t,r)=>{"boolean"==typeof t?e.options[r].visible=t:typeof t===d?(Object.assign(e.options[r],t),null==t.visible&&(e.options[r].visible=!0)):null==t&&(e.options[r].visible=!0)},kt=(e,t={},r=k)=>{const n=e.getElementsByClassName(`${x}-${r}`)[0];Object.keys(t).map((e=>({key:e,fn:n[xe(e)]}))).filter((e=>typeof e.fn===l&&"class"!==e.key)).forEach((e=>e.fn(t[e.key]))),Object.keys(t).filter((e=>"class"===e)).forEach((e=>n.classList.add(t[e])))},At=e=>{const t=(e=>{let t=[[e.points[0]||0,e.points[1]||0],[e.points[2]||0,e.points[3]||0]],r=L(t[1],t[0]),n=B(t[0],F(r,.5));const o=D(r),a=yt.map((t=>e[t].visible?(1+e[t].padding)*e[t].height*2.5:0)).reduce(((e,t)=>e+t),0);if(o<a){const e=0===o?[a,0]:F(r,a/o);t=[L(n,F(e,.5)),B(n,F(e,.5))],r=L(t[1],t[0])}let i=[r[1],-r[0]],s=B(n,F(i,e.bend));const l=t.map((e=>L(s,e))),c=l.map((e=>D(e))),f=l.map(((e,t)=>0===c[t]?e:F(e,1/c[t]))),d=f.map((e=>F(e,-1))),u=[[d[0][1],-d[0][0]],[d[1][1],-d[1][0]]],p=yt.map(((t,r)=>e[t].padding?e[t].padding:e.padding?e.padding:0)),h=yt.map(((t,r)=>e[t].height*(e[t].visible?1:0))).map(((e,t)=>e+p[t])),m=t.map(((e,t)=>B(e,F(f[t],h[t]))));r=L(m[1],m[0]),i=[r[1],-r[0]],n=B(m[0],F(r,.5)),s=B(n,F(i,e.bend));const g=m.map(((t,r)=>B(t,F(L(s,t),e.pinch)))),b=yt.map(((t,r)=>[B(m[r],F(d[r],e[t].height)),B(m[r],F(u[r],e[t].width/2)),B(m[r],F(u[r],-e[t].width/2))]));return{line:`M${vt(m[0])}C${vt(g[0])},${vt(g[1])},${vt(m[1])}`,tail:wt(b[0]),head:wt(b[1])}})(e.options);return Object.keys(t).map((t=>({path:t,element:e.getElementsByClassName(`${x}-${t}`)[0]}))).filter((e=>e.element)).map((e=>(e.element.setAttribute("d",t[e.path]),e))).filter((t=>e.options[t.path])).forEach((t=>t.element.setAttribute("visibility",e.options[t.path].visible?"visible":"hidden"))),e},Et=(e,...t)=>(e.options.points=fe(...Ze(...t)).slice(0,4),At(e)),Ct={setPoints:Et,points:Et,bend:(e,t)=>(e.options.bend=t,At(e)),pinch:(e,t)=>(e.options.pinch=t,At(e)),padding:(e,t)=>(e.options.padding=t,At(e)),head:(e,t)=>(xt(e,t,k),kt(e,t,k),At(e)),tail:(e,t)=>(xt(e,t,A),kt(e,t,A),At(e)),getLine:e=>e.getElementsByClassName(`${x}-line`)[0],getHead:e=>e.getElementsByClassName(`${x}-${k}`)[0],getTail:e=>e.getElementsByClassName(`${x}-${A}`)[0],...ve},jt=Object.keys({head:{visible:!1,width:8,height:10,padding:0},tail:{visible:!1,width:8,height:10,padding:0},bend:0,padding:0,pinch:.618,points:[]}),Mt={arrow:{nodeName:"g",attributes:[],args:()=>[],methods:Ct,init:function(...e){const t=n().document.createElementNS(o,"g");t.setAttribute(s,x);const r=["line",A,k].map((e=>{const r=n().document.createElementNS(o,p);return r.setAttribute(s,`${x}-${e}`),t.appendChild(r),r}));r[0].setAttribute(m,"fill:none;"),r[1].setAttribute(v,w),r[2].setAttribute(v,w),t.options={head:{visible:!1,width:8,height:10,padding:0},tail:{visible:!1,width:8,height:10,padding:0},bend:0,padding:0,pinch:.618,points:[]},Ct.setPoints(t,...e);const a=((...e)=>{for(let t=0;t<e.length;t+=1){if(typeof e[t]!==d)continue;const r=Object.keys(e[t]);for(let n=0;n<r.length;n+=1)if(jt.includes(r[n]))return e[t]}})(...e);return a&&Object.keys(a).filter((e=>Ct[e])).forEach((e=>Ct[e](t,a[e]))),t}}},Ot=(e=[],t=0,r=.5)=>{const n=[e[0]||0,e[1]||0],o=[e[2]||0,e[3]||0],a=L(o,n),i=B(n,F(a,.5)),s=[a[1],-a[0]],l=B(i,F(s,t)),c=B(n,F(L(l,n),r)),f=B(o,F(L(l,o),r));return`M${n[0]},${n[1]}C${c[0]},${c[1]} ${f[0]},${f[1]} ${o[0]},${o[1]}`},_t=e=>e.slice(1).split(/[, ]+/).map((e=>parseFloat(e))),Pt=e=>{const t=(e=>e.match(/[Mm][(0-9), .-]+/).map((e=>_t(e))))(e).shift(),r=(e=>e.match(/[Cc][(0-9), .-]+/).map((e=>_t(e))))(e).shift();return[...t?[t[t.length-2],t[t.length-1]]:[0,0],...r?[r[r.length-2],r[r.length-1]]:[0,0]]},$t=(e,...t)=>{const r=fe(...t.flat()).slice(0,4);return e.setAttribute("d",Ot(r,e._bend,e._pinch)),e},Nt={setPoints:$t,bend:(e,t)=>(e._bend=t,$t(e,...Pt(e.getAttribute("d")))),pinch:(e,t)=>(e._pinch=t,$t(e,...Pt(e.getAttribute("d")))),...ve},St={curve:{nodeName:p,attributes:["d"],args:(...e)=>[Ot(fe(...e.flat()))],methods:Nt}},Tt=(e,t,r,n,o)=>[mt(e,t,r,n,o,!0)],zt={wedge:{nodeName:p,args:Tt,attributes:["d"],methods:{setArc:(e,...t)=>e.setAttribute("d",Tt(...t)),...ve}}},qt={},Bt={...ze,...Be,...Ue,...Ve,...Ie,...Je,...rt,...nt,...ot,...st,...ht,...bt,...Mt,...St,...zt,...{origami:{nodeName:"g",init:(e,...t)=>{const r=n().document.createElementNS(o,"g");return qt.ear.convert.foldToSvg.render(e,r,...t),r},args:()=>[],methods:{...ve,...qe,...Ce}}}},Lt=Object.values(i).flat(),Ft=(...e)=>e,Ut=(e,t,...r)=>{const a=Bt[e]&&Bt[e].nodeName?Bt[e].nodeName:e,{init:i,args:s,methods:l}=Bt[e]||{},c=E[a]||[],f=M[a]||[],d=i?i(...r):n().document.createElementNS(o,a);t&&t.appendChild(d);return(s||Ft)(...r).forEach(((e,t)=>{d.setAttribute(E[a][t],e)})),l&&Object.keys(l).forEach((e=>Object.defineProperty(d,e,{value:function(){return l[e](d,...arguments)}}))),c.forEach((e=>{const t=xe(e);d[t]||Object.defineProperty(d,t,{value:function(){return d.setAttribute(e,...arguments),d}})})),f.forEach((e=>{if(d[e])return;Object.defineProperty(d,e,{value:function(){return Ut(e,d,...arguments)}})})),d},Dt={};Lt.forEach((e=>{Dt[e]=(...t)=>Ut(e,null,...t)}));const Rt=Object.assign(Dt),Vt={NS:o,nodes_attributes:E,nodes_children:M,extensions:Bt,...q,...me,...Rt},Gt=Object.assign(((...e)=>{const t=Ut(u,null,...e),r=()=>e.filter((e=>"function"==typeof e)).forEach((e=>e.call(t,t)));return"loading"===n().document.readyState?n().document.addEventListener("DOMContentLoaded",r):r(),t}),Vt);return Object.defineProperty(Gt,"window",{enumerable:!1,set:e=>(e.document||(e.document=(e=>(new e.DOMParser).parseFromString("<!DOCTYPE html><title>.</title>","text/html"))(e)),r.window=e,r.window)}),Gt}));