svg-path-simplify 0.4.4 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1657,7 +1657,7 @@ function roundPathData(pathData, decimalsGlobal = -1) {
1657
1657
 
1658
1658
  let len = pathData.length;
1659
1659
  let decimals = decimalsGlobal;
1660
- let decimalsArc = decimals < 3 ? decimals+2 : decimals;
1660
+ let decimalsArc = decimals < 3 ? decimals + 2 : decimals;
1661
1661
 
1662
1662
  for (let c = 0; c < len; c++) {
1663
1663
  let com = pathData[c];
@@ -1689,23 +1689,47 @@ function detectAccuracy(pathData) {
1689
1689
 
1690
1690
  dimA = dimA ? dimA : getDistManhattan(p0, p);
1691
1691
 
1692
- if (dimA) dims.push(dimA);
1692
+ if (dimA) dims.push(+dimA.toFixed(8));
1693
1693
 
1694
1694
  }
1695
1695
 
1696
1696
  }
1697
1697
 
1698
- let dim_min = dims.sort();
1698
+ dims = dims.sort();
1699
+ let len = dims.length;
1700
+ let dim_mid = dims[Math.floor(len*0.5)];
1699
1701
 
1700
- let sliceIdx = Math.ceil(dim_min.length / 6);
1702
+ // smallest 25% of values
1703
+ let idx_q = Math.ceil(len*0.25);
1704
+ let dims_min = dims.slice(0, idx_q);
1705
+
1706
+ // average smallest values with mid value
1707
+ let dim_min = ((dims_min.reduce((a, b) => a + b, 0) / idx_q) + dim_mid) * 0.5;
1708
+
1709
+ let threshold = 75;
1710
+ let decimalsAuto = dim_min > threshold * 1.5 ? 0 : Math.floor(threshold / dim_min).toString().length;
1711
+
1712
+ // clamp
1713
+ return Math.min(Math.max(0, decimalsAuto), 8)
1714
+
1715
+ /*
1716
+ let dim_min = dims.sort()
1717
+
1718
+ let dim_mid = dim_min[Math.floor(dim_min.length*0.5)]
1719
+
1720
+ let sliceIdx = Math.ceil(dim_min.length / 4);
1701
1721
  dim_min = dim_min.slice(0, sliceIdx);
1702
1722
  let minVal = dim_min.reduce((a, b) => a + b, 0) / sliceIdx;
1703
1723
 
1704
- let threshold = 75;
1705
- let decimalsAuto = minVal > threshold * 1.5 ? 0 : Math.floor(threshold / minVal).toString().length;
1724
+ // average with mid value
1725
+ minVal = (minVal+dim_mid)*0.5
1726
+
1727
+ let threshold = 75
1728
+ let decimalsAuto = minVal > threshold * 1.5 ? 0 : Math.floor(threshold / minVal).toString().length
1706
1729
 
1707
1730
  // clamp
1708
1731
  return Math.min(Math.max(0, decimalsAuto), 8)
1732
+ */
1709
1733
 
1710
1734
  }
1711
1735
 
@@ -2462,7 +2486,7 @@ function simplifyPathDataCubic(pathData, {
2462
2486
  error += com.error;
2463
2487
 
2464
2488
  // find next candidates
2465
- for (let n = i + 1; error < tolerance && n < l; n++) {
2489
+ for (let n = i + offset; error < tolerance && n < l; n++) {
2466
2490
  let comN = pathData[n];
2467
2491
 
2468
2492
  if (comN.type !== 'C' ||
@@ -2472,6 +2496,7 @@ function simplifyPathDataCubic(pathData, {
2472
2496
  (keepExtremes && com.extreme)
2473
2497
  )
2474
2498
  ) {
2499
+
2475
2500
  break
2476
2501
  }
2477
2502
 
@@ -2479,6 +2504,7 @@ function simplifyPathDataCubic(pathData, {
2479
2504
 
2480
2505
  // failure - could not be combined - exit loop
2481
2506
  if (combined.length > 1) {
2507
+
2482
2508
  break
2483
2509
  }
2484
2510
 
@@ -2492,6 +2518,7 @@ function simplifyPathDataCubic(pathData, {
2492
2518
 
2493
2519
  // return combined
2494
2520
  com = combined[0];
2521
+
2495
2522
  }
2496
2523
 
2497
2524
  pathDataN.push(com);
@@ -2605,11 +2632,19 @@ function combineCubicPairs(com1, com2, {
2605
2632
 
2606
2633
  comS.dimA = getDistManhattan(comS.p0, comS.p);
2607
2634
  comS.type = 'C';
2635
+
2608
2636
  comS.extreme = com2.extreme;
2609
2637
  comS.directionChange = com2.directionChange;
2610
-
2611
2638
  comS.corner = com2.corner;
2612
2639
 
2640
+ if (comS.extreme || comS.corner) ;
2641
+
2642
+ /*
2643
+ comS.extreme = com1.extreme;
2644
+ comS.directionChange = com1.directionChange;
2645
+ comS.corner = com1.corner;
2646
+ */
2647
+
2613
2648
  comS.values = [comS.cp1.x, comS.cp1.y, comS.cp2.x, comS.cp2.y, comS.p.x, comS.p.y];
2614
2649
 
2615
2650
  // relative error
@@ -4519,7 +4554,8 @@ function pathDataToTopLeft(pathData) {
4519
4554
  let { type, values } = com;
4520
4555
  let valsLen = values.length;
4521
4556
  if (valsLen) {
4522
- let p = { type: type, x: values[valsLen - 2], y: values[valsLen - 1], index: 0 };
4557
+ // we need rounding otherwise sorting may crash due to e notation
4558
+ let p = { type: type, x: +values[valsLen - 2].toFixed(8), y: +values[valsLen - 1].toFixed(8), index: 0 };
4523
4559
  p.index = i;
4524
4560
  indices.push(p);
4525
4561
  }
@@ -4527,7 +4563,7 @@ function pathDataToTopLeft(pathData) {
4527
4563
 
4528
4564
  // reorder to top left most
4529
4565
 
4530
- indices = indices.sort((a, b) => +a.y.toFixed(8) - +b.y.toFixed(8) || a.x - b.x);
4566
+ indices = indices.sort((a, b) => a.y - b.y || a.x - b.x);
4531
4567
  newIndex = indices[0].index;
4532
4568
 
4533
4569
  return newIndex ? shiftSvgStartingPoint(pathData, newIndex) : pathData;
@@ -1,3 +1,3 @@
1
- const e=180/Math.PI,t=Math.PI/180;function l(e,t={}){let l=function(e,t={}){let l,a;e=e.trim();let n=+(e.length/1024).toFixed(3),s={totalEls:1,hasEls:!0,hasDefs:!1,geometryEls:[],useEls:0,useElsNested:0,nonsensePaths:0,isSuspicious:!1,isBillionLaugh:!1,hasScripts:!1,hasPrologue:!1,hasEntity:!1,isPathData:!1,fileSizeKB:n,hasXmlns:e.includes("http://www.w3.org/2000/svg"),isSymbolSprite:!1,isSvgFont:e.includes("<glyph>")},r=t.useElsNested?t.useElsNested:2e3;const p=(e,t=2e3)=>{let l=0;for(let n=0;n<e.length&&l<t;n++){let s=e[n],r=s.getAttribute("xlink:href")?s.getAttribute("xlink:href"):s.getAttribute("href");r=r?r.replace("#",""):"",s.setAttribute("href","#"+r);let p=a.getElementById(r).querySelectorAll("use");l+=p.length;for(let e=0;e<p.length&&l<t;e++){let t=p[e].getAttribute("href").replace("#","");l+=a.getElementById(t).querySelectorAll("use").length}}return s.useElsNested=l,l};let i=/\<\!ENTITY/gi.test(e),u=!!/\<script/gi.test(e),h=!!/\<use/gi.test(e),y=/[\<path|\<polygon|\<polyline|\<rect|\<circle|\<ellipse|\<line|\<text|\<foreignObject]/gi.test(e),o=/[\<filter|\<linearGradient|\<radialGradient|\<pattern|\<animate|\<animateMotion|\<animateTransform|\<clipPath|\<mask|\<symbol|\<marker]/gi.test(e),c=(e.startsWith("M")||e.startsWith("m"))&&!/[\<svg|\<\/svg]/gi.test(e);if(s.isPathData=c,!i&&!h&&!u&&(y||o)&&n<t.fileSizeKB)return s.hasEls=y,s.hasDefs=o,s;!1===t.hasEntity&&i&&(s.hasEntity=!0);e=e.replace(/\<\?xml.+\?\>|\<\!DOCTYPE.+]\>/g,"").replace(/(<!--.*?-->)|(<!--[\S\s]+?-->)|(<!--[\S\s]*?$)/g,"");try{l=(new DOMParser).parseFromString(e,"text/html"),a=l.querySelector("svg");let t=a.querySelectorAll('path[d="M0,0"], path[d="M0 0"]').length,n=a.querySelectorAll("use").length;if(s.totalEls=a.querySelectorAll("*").length,s.geometryEls=a.querySelectorAll("path, rect, circle, ellipse, polygon, polyline, line").length,s.hasScripts=u,s.useEls=n,s.nonsensePaths=t,s.isSuspicious=!1,s.isBillionLaugh=!1,s.hasXmlns=!!a.getAttribute("xmlns")&&"http://www.w3.org/2000/svg"===a.getAttribute("xmlns"),s.isSymbolSprite=!(!a.querySelectorAll("symbol").length||0!==a.querySelectorAll("use").length),s.isSvgFont=!!a.querySelectorAll("glyph").length,100/s.totalEls*s.useEls>75){s.isSuspicious=!0,p(a.querySelectorAll("use"),r)>=r&&(s.isBillionLaugh=!0)}return s}catch{return console.warn("svg could not be parsed"),!1}}(e,t={useElsNested:5e3,hasScripts:!1,hasEntity:!1,fileSizeKB:1e4,isSymbolSprite:!1,isSvgFont:!1,...t}),a=!0,n=[];if(l.hasEls||(n.push("no elements"),a=!1),Object.keys(l).length){!0===l.isBillionLaugh&&(n.push("suspicious: might contain billion laugh attack"),a=!1);for(let e in t){let s=t[e],r=l[e];"number"==typeof s&&r>s&&(n.push(`allowed "${e}" exceeded: ${r} / ${s} `),a=!1),!0===r&&!1===s&&(n.push(`not allowed: "${e}" `),a=!1)}}else a=!1;return{isValid:a,log:n,fileReport:l}}function a(e,t,l="red",a="1%",n="1",s="",r=!0,p="",i=""){Array.isArray(t)&&(t={x:t[0],y:t[1]});let u=`<circle class="${i}" opacity="${n}" id="${p}" cx="${t.x}" cy="${t.y}" r="${a}" fill="${l}">\n <title>${s}</title></circle>`;if(!r)return u;e.insertAdjacentHTML("beforeend",u)}const{abs:n,acos:s,asin:r,atan:p,atan2:i,ceil:u,cos:h,exp:y,floor:o,log:c,max:x,min:f,pow:g,random:d,round:m,sin:v,sqrt:M,tan:b,PI:A}=Math;function C(e,t,l=!1){let a=i(t.y-e.y,t.x-e.x);return l&&a<0&&(a+=2*Math.PI),a}function S(e,t,l,a=!1){let n=Math.atan2(t.y-e.y,t.x-e.x),s=Math.atan2(l.y-e.y,l.x-e.x),r=s-n;r=(e=>{let t=e%(2*Math.PI);return t>Math.PI?t-=2*Math.PI:t<=-Math.PI&&(t+=2*Math.PI),t})(r),a&&(r=2*Math.PI-Math.abs(r));let p=180/Math.PI;return{startAngle:n,endAngle:s,deltaAngle:r,startAngleDeg:n*p,endAngleDeg:s*p,deltaAngleDeg:r*p}}function w(e=null,t=null,l=null,a=null,n=!0,s=!1,r=!1){let p,i,u,h,y,o={};if(!(e&&t&&l&&a))return r&&console.warn("points missing"),!1;if(e.x===t.x&&e.y===t.y||l.x===a.x&&l.y===a.y)return!1;try{if(p=(a.y-l.y)*(t.x-e.x)-(a.x-l.x)*(t.y-e.y),0===p)return!1}catch{return r&&console.warn("!catch",e,t,"p3:",l,"p4:",a),!1}i=e.y-l.y,u=e.x-l.x,h=(a.x-l.x)*i-(a.y-l.y)*u,y=(t.x-e.x)*i-(t.y-e.y)*u,i=h/p,u=y/p,o={x:e.x+i*(t.x-e.x),y:e.y+i*(t.y-e.y)};let c=!1;return i>0&&i<1&&u>0&&u<1&&(c=!0),!n&&s&&(i>0&&u<0||i<0&&u>0)?(c=!1,!1):!(n&&!c)&&o}function E(e,t,l,a=!1){let n={x:(t.x-e.x)*l+e.x,y:(t.y-e.y)*l+e.y};return a&&(n.angle=C(e,t),n.angle<0&&(n.angle+=2*A)),n}function L(e,t=.5,l=!1,a=!1,n=!1){let s;return Array.isArray(e[0])&&(e=e.map(e=>({x:e[0],y:e[1]})),n=!0),s=e.length>2?((e,t,l=!1)=>{let n=4===e.length,s=e[0],r=e[1],p=n?e[2]:e[1],i=e[e.length-1],u={x:0,y:0};if(l||a){let e,l,h,y,o,c=s.x===r.x&&s.y===r.y,x=i.x===p.x&&i.y===p.y;0!==t||c?1!==t||x?(c&&(t+=1e-7),x&&(t-=1e-7),e=E(s,r,t),n?(l=E(r,p,t),h=E(p,i,t),y=E(e,l,t),o=E(l,h,t),u=E(y,o,t),u.angle=C(y,o),a&&(u.cpts=[l,h,y,o])):(l=E(s,r,t),h=E(r,i,t),u=E(l,h,t),u.angle=C(l,h),a&&(u.cpts=[l,h]))):(u.x=i.x,u.y=i.y,u.angle=C(p,i)):(u.x=s.x,u.y=s.y,u.angle=C(s,r))}else{let e=1-t;u=n?{x:e*e*e*s.x+3*e*e*t*r.x+3*e*t*t*p.x+t*t*t*i.x,y:e*e*e*s.y+3*e*e*t*r.y+3*e*t*t*p.y+t*t*t*i.y}:{x:e*e*s.x+2*e*t*r.x+t*t*i.x,y:e*e*s.y+2*e*t*r.y+t*t*i.y}}return u})(e,t,l):E(e[0],e[1],t,l),l&&s.angle<0&&(s.angle+=2*A),n?[s.x,s.y]:s}function P(l,a,n,s,r,p,i,u,h,y=!0){const o=(e,t,l,a,n=!0)=>{let s=Math.atan2(a-t,l-e);return n&&s<0&&(s+=2*Math.PI),s};let c={cx:0,cy:0,rx:n=Math.abs(n),ry:s=Math.abs(s),startAngle:0,endAngle:0,deltaAngle:0,clockwise:i,xAxisRotation:r=n===s?0:r<0&&y?r+360:r,largeArc:p,sweep:i};if(0==n||0==s)throw Error("rx and ry can not be 0");let x,f,g=n===s?0:r*t,d=g?Math.sin(g):0,m=g?Math.cos(g):1,v=(l-u)/2,M=(a-h)/2,b=(l+u)/2,A=(a+h)/2,C=g?m*v+d*M:v,S=g?m*M-d*v:M,w=C*C/(n*n)+S*S/(s*s);if(w>1){let e=Math.sqrt(w);n*=e,s*=e,c.rx=n,c.ry=s}let E=n*s,L=n*S,P=s*C,T=L**2+P**2;if(!T)throw Error("start point can not be same as end point");let I=Math.sqrt(Math.abs((E*E-T)/T));p===i&&(I=-I);let D=I*L/s,k=-I*P/n;x=g?m*D-d*k+b:b+D,f=g?d*D+m*k+A:A+k,c.cy=f,c.cx=x;let q=o(x,f,l,a,y),Q=o(x,f,u,h,y);i?Q<q&&(Q+=2*Math.PI):Q>q&&(Q-=2*Math.PI);let z=Q-q;return c.startAngle=q,c.startAngle_deg=q*e,c.endAngle=Q,c.endAngle_deg=Q*e,c.deltaAngle=z,c.deltaAngle_deg=z*e,c}function T(e,t,l,a=0,n=!1){return a?(a=n?a/180*Math.PI:a,{x:t+(e.x-t)*Math.cos(a)-(e.y-l)*Math.sin(a),y:l+(e.x-t)*Math.sin(a)+(e.y-l)*Math.cos(a)}):e}function I(e,t,l,a,n,s=0,r=!0,i=!1){if(n=i?n*A/180:n,s=i?s*A/180:s,s=l!==a&&s!==2*A?s:0,r&&l!==a){let e=p(b(n=s?n-s:n)*(l/a));n=h(n)<0?e+A:e}let u=e+l*h(n),y=t+a*v(n),o={x:u,y:y};return s&&(o.x=e+(u-e)*h(s)-(y-t)*v(s),o.y=t+(u-e)*v(s)+(y-t)*h(s)),o}function D(e,t,l){if(t===l||e%A*.5==0)return e;let a=p(b(e)*(t/l));return a=h(e)<0?a+A:a,a}function k(e=null,t=[]){e||(e=t[0],t=t.slice(1,t.length));let l=t.length,a=t[l-1],n=t[0],s=3===l?t[1]:n,r=Math.min(e.y,a.y),p=Math.min(e.x,a.x),i=Math.max(e.x,a.x),u=Math.max(e.y,a.y);return!(n.y>=r&&n.y<=u&&s.y>=r&&s.y<=u&&n.x>=p&&n.x<=i&&s.x>=p&&s.x<=i)}function q(e,{addExtremes:t=!0,addSemiExtremes:l=!1}={}){let a=4===e.length?function(e,t,l,a,{addExtremes:n=!0,addSemiExtremes:s=!1}={}){const r=e=>{const t=Math.PI/4,l=Math.cos(t),a=Math.sin(t);return{x:e.x*l-e.y*a,y:e.x*a+e.y*l}};s&&(e=r(e),t=r(t),l=r(l),a=r(a));let[p,i,u,h,y,o,c,x]=[e.x,e.y,t.x,t.y,l.x,l.y,a.x,a.y],f=Math.min(e.y,a.y),g=Math.min(e.x,a.x),d=Math.max(e.x,a.x),m=Math.max(e.y,a.y);if(t.y>=f&&t.y<=m&&l.y>=f&&l.y<=m&&t.x>=g&&t.x<=d&&l.x>=g&&l.x<=d)return[];let v,M,b,A,C,S,w,E,L=[];for(let e=0;e<2;++e)if(0==e?(M=6*p-12*u+6*y,v=-3*p+9*u-9*y+3*c,b=3*u-3*p):(M=6*i-12*h+6*o,v=-3*i+9*h-9*o+3*x,b=3*h-3*i),Math.abs(v)<1e-8){if(Math.abs(M)<1e-8)continue;A=-b/M,0<A&&A<1&&L.push(A)}else w=M*M-4*b*v,w<0?Math.abs(w)<1e-8&&(A=-M/(2*v),0<A&&A<1&&L.push(A)):(E=Math.sqrt(w),C=(-M+E)/(2*v),0<C&&C<1&&L.push(C),S=(-M-E)/(2*v),0<S&&S<1&&L.push(S));let P=L.length;for(;P--;)A=L[P];return L}(e[0],e[1],e[2],e[3],{addExtremes:t,addSemiExtremes:l}):function(e,t,l,{addExtremes:a=!0,addSemiExtremes:n=!1}={}){const s=e=>{const t=-Math.PI/4,l=Math.cos(t),a=Math.sin(t);return{x:e.x*l-e.y*a,y:e.x*a+e.y*l}};n&&(e=s(e),t=s(t),l=s(l));let r,p,i,u=Math.min(e.y,l.y),h=Math.min(e.x,l.x),y=Math.max(e.x,l.x),o=Math.max(e.y,l.y);if(t.y>=u&&t.y<=o&&t.x>=h&&t.x<=y)return[];let[c,x,f,g,d,m]=[e.x,e.y,t.x,t.y,l.x,l.y],v=[];for(let e=0;e<2;++e)r=0==e?c-2*f+d:x-2*g+m,p=0==e?-2*c+2*f:-2*x+2*g,Math.abs(r)>1e-12&&(i=-p/(2*r),i>0&&i<1&&v.push(i));return v}(e[0],e[1],e[2],{addExtremes:t,addSemiExtremes:l});return a}function Q(e,t){const l=(e,t,l,a,n,s)=>{var r=Math.cos(s),p=Math.sin(s),i=a*Math.cos(e),u=n*Math.sin(e);return{x:t+r*i-p*u,y:l+p*i+r*u}};let a,n,s,r,p,i=P(e.x,e.y,t[0],t[1],t[2],t[3],t[4],t[5],t[6]),{rx:u,ry:h,cx:y,cy:o,endAngle:c,deltaAngle:x}=i,f=t[2],g={x:t[5],y:t[6]},d=[g],m=f*Math.PI/180,v=Math.tan(m);p=Math.atan2(-h*v,u);let M=p,b=p+Math.PI,A=Math.atan2(h,u*v),C=A+Math.PI,S=[e.x,g.x],w=[e.y,g.y],E=Math.min(...S),L=Math.max(...S),T=Math.min(...w),I=Math.max(...w),D=l(c-.001*x,y,o,u,h,m),k=l(c-.999*x,y,o,u,h,m);return(D.x>L||k.x>L)&&(a=l(M,y,o,u,h,m),d.push(a)),(D.x<E||k.x<E)&&(n=l(b,y,o,u,h,m),d.push(n)),(D.y<T||k.y<T)&&(r=l(C,y,o,u,h,m),d.push(r)),(D.y>I||k.y>I)&&(s=l(A,y,o,u,h,m),d.push(s)),d}function z(e=[],t=[]){let l=e.length,a=4===l;t.length||(t=[0]);let n=t.length,s=[];for(let r=0;r<n;r++){let n=t[r],p=n?[]:e.slice(0);if(n)for(let t=0;t<l;t++){let l=e[t];p.push(T(l,0,0,n))}let i=a?$(...p):F(...p);s.push(...i)}return s=[...new Set(s)].sort(),s}function $(e,t,l,a){if(!k(e,[t,l,a]))return[];let n,s,r,p,i,u,h,y,[o,c,x,f,g,d,m,v]=[e.x,e.y,t.x,t.y,l.x,l.y,a.x,a.y],M=[],b=1e-8;for(let e=0;e<2;++e)if(0==e?(s=6*o-12*x+6*g,n=-3*o+9*x-9*g+3*m,r=3*x-3*o):(s=6*c-12*f+6*d,n=-3*c+9*f-9*d+3*v,r=3*f-3*c),Math.abs(n)<b){if(Math.abs(s)<b)continue;p=-r/s,p>0&&p<1&&M.push(p)}else h=s*s-4*r*n,h<0?Math.abs(h)<b&&(p=-s/(2*n),p>0&&p<1&&M.push(p)):(y=Math.sqrt(h),i=(-s+y)/(2*n),i>0&&i<1&&M.push(i),u=(-s-y)/(2*n),u>0&&u<1&&M.push(u));let A=M.length;for(;A--;)p=M[A];return[...new Set(M)].sort()}function F(e,t,l){if(!k(e,[t,l]))return[];let a,n,s,[r,p,i,u,h,y]=[e.x,e.y,t.x,t.y,l.x,l.y],o=[];for(let e=0;e<2;++e)a=0==e?r-2*i+h:p-2*u+y,n=0==e?-2*r+2*i:-2*p+2*u,Math.abs(a)>1e-12&&(s=-n/(2*a),s>0&&s<1&&o.push(s));return[...new Set(o)].sort()}function j(e,t=.001){let l=Math.PI/2,a=l/2;return!(Math.abs(e/l-Math.round(e/l))<t)&&Math.abs(e/a-Math.round(e/a))<t}function B(e,t,l=!1){let a=l?t[0]-e[0]:t.x-e.x,n=l?t[1]-e[1]:t.y-e.y;return Math.sqrt(a*a+n*n)}function R(e,t){let l=t.x-e.x,a=t.y-e.y;return l*l+a*a}function O(e,t){return Math.abs(t.x-e.x)+Math.abs(t.y-e.y)}function N(e,t){return.5*(Math.abs(t.x-e.x)+Math.abs(t.y-e.y))}function Z(e){let t=[],l=[e[0]],a=e.length;for(let n=1;n<a;n++){let a=e[n];"M"!==a.type&&"m"!==a.type||(t.push(l),l=[]),l.push(a)}return l.length&&t.push(l),t}function W(e,t){let l,a,n,s,r,p,i=[],u=[],h=e[0],y=e[1],o=e[e.length-2],c=e[e.length-1];return 4===e.length?(l=L([h,y],t),a=L([y,o],t),n=L([o,c],t),s=L([l,a],t),r=L([a,n],t),p=L([s,r],t),i.push({x:h.x,y:h.y},{x:l.x,y:l.y},{x:s.x,y:s.y},{x:p.x,y:p.y}),u.push({x:p.x,y:p.y},{x:r.x,y:r.y},{x:n.x,y:n.y},{x:c.x,y:c.y})):3===e.length?(a=L([h,y],t),n=L([y,c],t),p=L([a,n],t),i.push({x:h.x,y:h.y},{x:a.x,y:a.y},{x:p.x,y:p.y}),u.push({x:p.x,y:p.y},{x:n.x,y:n.y},{x:c.x,y:c.y})):2===e.length&&(a=L([h,c],t),i.push({x:h.x,y:h.y},{x:a.x,y:a.y}),u.push({x:a.x,y:a.y},{x:c.x,y:c.y})),[i,u]}function J(e,t,{tMin:l=0,tMax:a=1,addExtremes:n=!0,addSemiExtremes:s=!1}={}){let r=[],p=6===t.length?"C":"Q",i={x:t[0],y:t[1]},u="C"===p?{x:t[2],y:t[3]}:i,h={x:t[4],y:t[5]},y=0;let o="C"===p?[e,i,u,h]:[e,i,h],c=n?q(o,{addExtremes:n,addSemiExtremes:!1}):[],x=s?q(o,{addExtremes:n,addSemiExtremes:s}):[],f=Array.from(new Set([...c,...x])).sort();if(f=f.filter(e=>e>0&&e<1),f.length){let l=function(e,t,l,a=!0){let n=[];if(!l.length)return!1;let s,r,p,i=t.length,u={x:t[i-2],y:t[i-1]};2===t.length?p=[e,u]:4===t.length?(s={x:t[0],y:t[1]},p=[e,s,u]):6===t.length&&(s={x:t[0],y:t[1]},r={x:t[2],y:t[3]},p=[e,s,r,u]);if(l.length)if(1===l.length){let e=W(p,l[0]),t=e[0],a=e[1];n.push(t,a)}else{let e=l[0],t=W(p,e),a=t[0];n.push(a),p=t[1];for(let t=1;t<l.length;t++){e=l[t-1];let a=W(p,(l[t]-e)/(1-e));n.push(a[0]),t===l.length-1&&n.push(a[a.length-1]),p=a[1]}}if(a){let e,t,l=[];return n.forEach(a=>{e={type:"",values:[]},a.shift(),t=a.map(e=>Object.values(e)).flat(),e.values=t,3===a.length?e.type="C":2===a.length?e.type="Q":1===a.length&&(e.type="L"),l.push(e)}),l}return n}(e,t,f);r.push(...l),y+=l.length}else r.push({type:p,values:t});return{pathData:r,count:y}}function V(e,{tMin:t=0,tMax:l=1,addExtremes:a=!0,addSemiExtremes:n=!1}={}){let s=[e[0]],r={x:e[0].values[0],y:e[0].values[1]},p={x:e[0].values[0],y:e[0].values[1]},i=e.length;for(let u=1;i&&u<i;u++){let i=e[u],{type:h,values:y}=i,o=y.slice(-2);if(o[0],o[1],"C"!==h&&"Q"!==h)s.push(i);else if((a||n)&&("C"===h||"Q"===h)){let e=J(r,y,{tMin:t,tMax:l,addExtremes:a,addSemiExtremes:n}).pathData;s.push(...e)}r={x:o[0],y:o[1]},"z"===h.toLowerCase()?r=p:"M"===h&&(p={x:o[0],y:o[1]})}return s}function H(e,t=-1){if(t<0)return e;let l=e.length,a=t,n=a<3?a+2:a;for(let t=0;t<l;t++){let l=e[t],{type:s,values:r}=l,p=r.length;if(!p)continue;let i="a"===s.toLowerCase();for(let l=0;l<p;l++)e[t].values[l]=K(r[l],i&&l<2?n:a)}return e}function K(e=0,t=3){if(t<0)return e;if(!t)return Math.round(e);let l=Math.floor(t);if(l!==t){let a=+(t-l).toFixed(2);a=a>.5?.5*Math.floor(a/.5):a;let n=10**-l*a;return+(Math.round(e/n)*n).toFixed(8)}let a=10**t;return Math.round(e*a)/a}function _(e,t=-1){let l=e.map(e=>e.x),a=e.map(e=>e.y),n=Math.min(...l),s=Math.max(...l),r=Math.min(...a),p=Math.max(...a),i={x:n,left:n,right:s,y:r,top:r,bottom:p,width:s-n,height:p-r};if(t>-1)for(let e in i)i[e]=+i[e].toFixed(t);return i}function G(e){let t=[];return e.forEach(e=>{let l=function(e){let t=function(e){let t=[];for(let l=0;l<e.length;l++){let a=e[l],n=l>0?e[l-1]:e[l],{type:s,values:r}=a,p={x:n.values[n.values.length-2],y:n.values[n.values.length-1]},i=r.length?{x:r[r.length-2],y:r[r.length-1]}:"",u=r.length?{x:r[0],y:r[1]}:"";switch(s){case"A":if("function"!=typeof arcToBezier){let e=B(p,i)/2,l=E(p,i,.5),a=I(l.x,l.y,e,e,0),n=I(l.x,l.y,e,e,Math.PI);t.push(a,n,i);break}arcToBezier(p,r).forEach(e=>{let l=e.values,a={x:l[0],y:l[1]},n={x:l[2],y:l[3]},s={x:l[4],y:l[5]};t.push(a,n,s)});break;case"C":let e={x:r[2],y:r[3]};t.push(u,e);break;case"Q":t.push(u)}"z"!==s.toLowerCase()&&t.push(i)}return t}(e),l=_(t);return l}(e);t.push(l)}),t}function U(e,t){let[l,a,n,s,r,p]=[e.x,e.y,e.width,e.height,e.x+e.width,e.y+e.height],[i,u,h,y,o,c]=[t.x,t.y,t.width,t.height,t.x+t.width,t.y+t.height],x=!1;return n*s!=h*y&&n*s>h*y&&l<i&&r>o&&a<u&&p>c&&(x=!0),x}function X(e,t=9){let l=0,a=[],n=Z(e),s=n.length>1,r=[];if(s){let e=G(n);e.forEach(function(t,l){for(let l=0;l<e.length;l++){let a=e[l];if(t!=a){U(t,a)&&r.push(l)}}})}return n.forEach((e,t)=>{a=[];let n=0,s=0,p=1,i=[];e.forEach(function(t,l){let[s,r]=[t.type,t.values],p=r.length;if(r.length){let u=(l>0?e[l-1]:e[0]).values,h=u.length,y={x:u[h-2],y:u[h-1]},o={x:r[p-2],y:r[p-1]};if("C"===s||"Q"===s){let e={x:r[0],y:r[1]};i="C"===s?[y,e,{x:r[2],y:r[3]},o]:[y,e,o];let t=Math.abs(function(e,t=!1){let l,[a,n,s,r]=[e[0],e[1],e[2],e[e.length-1]];if(e.length<3)return 0;3===e.length&&(n={x:1*e[0].x/3+2*e[1].x/3,y:1*e[0].y/3+2*e[1].y/3},s={x:1*e[2].x/3+2*e[1].x/3,y:1*e[2].y/3+2*e[1].y/3});return l=3*(a.x*(-2*n.y-s.y+3*r.y)+n.x*(2*a.y-s.y-r.y)+s.x*(a.y+n.y-2*r.y)+r.x*(-3*a.y+n.y+2*s.y))/20,t?Math.abs(l):l}(i));n+=t,a.push(y,o)}else if("A"===s){let e=P(y.x,y.y,t.values[0],t.values[1],t.values[2],t.values[3],t.values[4],o.x,o.y),{cx:l,cy:s,rx:r,ry:p,startAngle:i,endAngle:u,deltaAngle:h}=e,c=Math.abs(function(e,t,l,a){const n=Math.PI*e*t;let s=(a-l+2*Math.PI)%(2*Math.PI);if(e===t)return n*(s/(2*Math.PI));const r=l=>Math.atan2(e*Math.sin(l),t*Math.cos(l));return l=r(l),a=r(a),s=(a-l+2*Math.PI)%(2*Math.PI),n*(s/(2*Math.PI))}(r,p,i,u));c-=Math.abs(Y([y,{x:l,y:s},o])),a.push(y,o),n+=c}else a.push(y,o)}});let u=Y(a);-1!==r.indexOf(t)&&(p=-1),s=u<0&&n<0?(Math.abs(n)-Math.abs(u))*p:(Math.abs(n)+Math.abs(u))*p,l+=s}),l}function Y(e,t=!1){let l=0,a=e.length;for(let t=0;a&&t<a;t++){l+=e[t].x*e[t===e.length-1?0:t+1].y*.5-e[t===e.length-1?0:t+1].x*e[t].y*.5}return t&&(l=Math.abs(l)),l}function ee(e,t=0){t=parseFloat(t);let l=e.length,a=e[0].values.join(" "),n=t>1?"\n":t<1?"":" ",s=t>.5?" ":"",r=`${e[0].type}${s}${a}${n}`;for(let p=1;p<l;p++){let i=e[p-1],u=e[p],{type:h,values:y}=u;if(a="",t||"A"!==h&&"a"!==h||(y=[y[0],y[1],y[2],`${y[3]}${y[4]}${y[5]}`,y[6]]),h=t<1&&i.type===u.type&&"m"!==u.type.toLowerCase()||t<1&&"M"===i.type&&"L"===u.type?" ":u.type,t)a=y.join(" ");else{let e=!1;for(let t=0,l=y.length;t<l;t++){let l=y[t],n=l.toString(),s=n.includes(".")&&Math.abs(l)<1;s&&e&&(n=n.replace(/^0\./,".")),!(t>0)||e&&s||(a+=" "),a+=n,e=s}}p===l-1&&(n=""),r+=`${h}${s}${a}${n}`}return t<1&&(r=r.replace(/[A-Za-z]0(?=\.)/g,e=>e[0]).replace(/ 0\./g," .").replace(/ -/g,"-").replace(/-0\./g,"-.").replace(/Z/g,"z")),r}function te(e,t,l=0,a=1,n=!1){const s=(e,t,l,a,n)=>{let s=1-n;return{x:3*s*s*(t.x-e.x)+6*s*n*(l.x-t.x)+3*n*n*(a.x-l.x),y:3*s*s*(t.y-e.y)+6*s*n*(l.y-t.y)+3*n*n*(a.y-l.y)}};let r=[e,t],p=N(e.p0,e.p)>N(t.p0,t.p),i=JSON.parse(JSON.stringify(e)),u=JSON.parse(JSON.stringify(t)),h=w(i.p0,i.cp1,u.p,u.cp2,!1);if(!h)return r;if(p){let l={p0:{x:e.p.x,y:e.p.y},cp1:{x:e.cp2.x,y:e.cp2.y},cp2:{x:e.cp1.x,y:e.cp1.y},p:{x:e.p0.x,y:e.p0.y}};e={p0:{x:t.p.x,y:t.p.y},cp1:{x:t.cp2.x,y:t.cp2.y},cp2:{x:t.cp1.x,y:t.cp1.y},p:{x:t.p0.x,y:t.p0.y}},t=l}let y=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),o=(e,t)=>({x:e.x*t,y:e.y*t}),c=(e,t)=>e.x*t.x+e.y*t.y,x=t.p0,f=s(t.p0,t.cp1,t.cp2,t.p,0),g=c(y(e.p0,x),f)/c(f,f),d=L([t.p0,t.cp1,t.cp2,t.p],g),m=s(t.p0,t.cp1,t.cp2,t.p,g);g-=c(y(d,e.p0),m)/c(m,m);let v=L([t.p0,t.cp1,t.cp2,t.p],g),M=t.p,b=s(t.p0,t.cp1,t.cp2,t.p,g),A=s(t.p0,t.cp1,t.cp2,t.p,1),C=1-g,S=(P=v,T=o(b,C/3),{x:P.x+T.x,y:P.y+T.y});var P,T;let I=y(M,o(A,C/3)),D={p0:v,cp1:S,cp2:I,p:M,t0:g};p&&(D={p0:M,cp1:I,cp2:S,p:v,t0:g});let k=.5*(1-g),q=L([D.p0,D.cp1,D.cp2,D.p],k,!1,!0),Q=q.cpts[2],z=w(q,Q,D.p0,h,!1),$=w(q,Q,D.p,h,!1),F=E(D.p0,z,1.333),j=E(D.p,$,1.333);if(w(i.p0,F,u.p,j,!0))return r;D.cp1=F,D.cp2=j;let B=N(i.p0,D.p0)+N(u.p,D.p);if(D.p0=i.p0,D.p=u.p,D.extreme=u.extreme,D.corner=u.corner,D.dimA=u.dimA,D.directionChange=u.directionChange,D.type="C",D.values=[D.cp1.x,D.cp1.y,D.cp2.x,D.cp2.y,D.p.x,D.p.y],B<l){let t=p?1+g:Math.abs(g),s=1+Math.abs(g);if(t=p?1+g:Math.abs(g)/s,N(L([D.p0,D.cp1,D.cp2,D.p],t),e.p)>l*a)return r;let h=X([{type:"M",values:[i.p0.x,i.p0.y]},{type:"C",values:[i.cp1.x,i.cp1.y,i.cp2.x,i.cp2.y,i.p.x,i.p.y]},{type:"C",values:[u.cp1.x,u.cp1.y,u.cp2.x,u.cp2.y,u.p.x,u.p.y]}]),y=[{type:"M",values:[D.p0.x,D.p0.y]},{type:"C",values:[D.cp1.x,D.cp1.y,D.cp2.x,D.cp2.y,D.p.x,D.p.y]}],o=X(y),c=Math.abs(o/h-1);D.error=5*c*a,n&&ee(y),c<.05*a&&(r=[D])}return r}function le(e,{keepExtremes:t=!0,keepInflections:l=!0,keepCorners:a=!0,extrapolateDominant:n=!0,tolerance:s=1}={}){let r=[e[0]],p=e.length;for(let n=2;p&&n<=p;n++){let i=e[n-1],u=n<p?e[n]:null,h=u?.type||null,{type:y,values:o,p0:c,p:x,cp1:f=null,cp2:g=null,extreme:d=!1,directionChange:m=!1,corner:v=!1,dimA:M=0}=i;if("C"===y&&"C"===h)if(a&&v||t&&d)r.push(i);else{let h=ae(i,u,{tolerance:s}),y=0;if(1===h.length){i=h[0];let u=1;y+=i.error;for(let r=n+1;y<s&&r<p;r++){let n=e[r];if("C"!==n.type||l&&i.directionChange||a&&i.corner||t&&i.extreme)break;let p=ae(i,n,{tolerance:s});if(p.length>1)break;y+=.5*p[0].error,u++,i=p[0]}r.push(i),n<p&&(n+=u)}else r.push(i)}else r.push(i)}return r}function ae(e,t,{tolerance:l=1}={}){let a=[e,t],n=function(e,t){let l=O(e.cp2,e.p);if(0===l)return 0;let a=O(e.p,t.cp1);if(0===a)return 0;let n=O(e.cp2,t.cp1);return l/n}(e,t);if(!n)return a;let s=O(e.p0,e.p),r=O(t.p0,t.p),p=.08*Math.max(0,Math.min(s,r))*l,i=function(e,t,l=0){let{p0:a,cp1:n}=e,{p:s,cp2:r}=t;return n={x:(n.x-(1-l)*a.x)/l,y:(n.y-(1-l)*a.y)/l},r={x:(r.x-l*s.x)/(1-l),y:(r.y-l*s.y)/(1-l)},{p0:a,cp1:n,cp2:r,p:s}}(e,t,n),u=L([i.p0,i.cp1,i.cp2,i.p],n),h=O(e.p,u),y=0,o=0,c=!1,x=h;if(h<p){let l=.5*n;if(y=O(L([e.p0,e.cp1,e.cp2,e.p],.5),L([i.p0,i.cp1,i.cp2,i.p],l)),x+=y,y<p){let e=.5*(1+n);o=O(L([t.p0,t.cp1,t.cp2,t.p],.5),L([i.p0,i.cp1,i.cp2,i.p],e)),x+=o,x<p&&(c=!0)}}return c&&(i.p0=e.p0,i.p=t.p,i.dimA=O(i.p0,i.p),i.type="C",i.extreme=t.extreme,i.directionChange=t.directionChange,i.corner=t.corner,i.values=[i.cp1.x,i.cp1.y,i.cp2.x,i.cp2.y,i.p.x,i.p.y],i.error=x/p,a=[i]),a}function ne(e,{tolerance:t=1,debug:l=!1}={}){let a=!1,n={flat:!0,steepness:0},s=e[0],r=e[e.length-1],p=new Set([...e.map(e=>+e.x.toFixed(8))]),i=new Set([...e.map(e=>+e.y.toFixed(8))]);if(1===p.size||1===i.size)return!l||n;let u=R(s,r),h=u/1e3*t,y=Y(e,!0);return y<h&&(a=!0),l&&(n.flat=a,n.steepness=y/u*10),l?n:a}function se(e=[],{detectExtremes:t=!0,detectCorners:l=!0,detectDirection:n=!0,detectSemiExtremes:s=!1,debug:r=!1,addSquareLength:p=!0,addArea:i=!0}={}){e=function(e,{addSquareLength:t=!0,addArea:l=!1,addArcParams:a=!1,addAverageDim:n=!0}={}){let s=e[0],r={x:s.values[0],y:s.values[1]},p=r,i=r;s.p0=p,s.p=i,s.idx=0,s.dimA=0;let u=e.length,h=[s];for(let n=1;n<u;n++){let s,u,y=e[n],{type:o,values:c}=y,x=c.length;if(i=x?{x:c[x-2],y:c[x-1]}:r,y.p0=p,y.p=i,y.dimA=O(p,i),"M"===o&&(r=i),"Q"===o||"C"===o)s={x:c[0],y:c[1]},u="C"===o?{x:c[2],y:c[3]}:null,y.cp1=s,u&&(y.cp2=u);else if("A"===o&&a){let{rx:e,ry:t,cx:l,cy:a,startAngle:n,endAngle:s,deltaAngle:r}=P(p.x,p.y,...c);y.cx=l,y.cy=a,y.rx=e,y.ry=t,y.xAxisRotation=c[2]/180*Math.PI,y.largeArc=c[3],y.sweep=c[4],y.startAngle=n,y.endAngle=s,y.deltaAngle=r}if("Z"===o&&r.x!==i.x&&r.y!==i.y&&(y.closePath=!0),t&&(y.squareDist=R(p,i)),l){let e=0;"C"===o&&(e=Y([p,s,u,i],!1)),"Q"===o&&(e=Y([p,s,i],!1)),y.cptArea=e}y.idx=n,p=i,h.push(y)}return h}(e,{addSquareLength:p,addArea:i});let u=[],h=function(e=[],t=!1,l=-1){let a=[];return e.forEach(e=>{let{type:n,values:s}=e;if(s.length)if(l>-1&&(s=s.map(e=>+e.toFixed(l))),t)for(let e=1;e<s.length;e+=2)a.push({x:s[e-1],y:s[e]});else a.push({x:s[s.length-2],y:s[s.length-1]})}),a}(e),y=_(h),{left:o,right:c,top:x,bottom:f,width:g,height:d}=y;e[0].corner=!1,e[0].extreme=!1,e[0].semiExtreme=!1,e[0].directionChange=!1,e[0].closePath=!1;let m=[e[0]],v=e.length;for(let t=2;v&&t<=v;t++){let l=e[t-1],{type:a,values:n,p0:r,p:p,cp1:i=null,cp2:u=null,squareDist:h=0,cptArea:y=0,dimA:g=0}=l,d=e[t-2],v=e[t]||null;l.corner=!1,l.extreme=!1,l.semiExtreme=!1,l.directionChange=!1,l.closePath=!1;let M="C"===a||"Q"===a?"C"===a?[r,i,u,p]:[r,i,p]:[r,p],b=.1*g,A=.01*b,S="Q"===a||"C"===a,w="A"===a,E=v&&("Q"===v.type||"C"===v.type),L=!1;
1
+ const e=180/Math.PI,t=Math.PI/180;function l(e,t={}){let l=function(e,t={}){let l,a;e=e.trim();let n=+(e.length/1024).toFixed(3),s={totalEls:1,hasEls:!0,hasDefs:!1,geometryEls:[],useEls:0,useElsNested:0,nonsensePaths:0,isSuspicious:!1,isBillionLaugh:!1,hasScripts:!1,hasPrologue:!1,hasEntity:!1,isPathData:!1,fileSizeKB:n,hasXmlns:e.includes("http://www.w3.org/2000/svg"),isSymbolSprite:!1,isSvgFont:e.includes("<glyph>")},r=t.useElsNested?t.useElsNested:2e3;const p=(e,t=2e3)=>{let l=0;for(let n=0;n<e.length&&l<t;n++){let s=e[n],r=s.getAttribute("xlink:href")?s.getAttribute("xlink:href"):s.getAttribute("href");r=r?r.replace("#",""):"",s.setAttribute("href","#"+r);let p=a.getElementById(r).querySelectorAll("use");l+=p.length;for(let e=0;e<p.length&&l<t;e++){let t=p[e].getAttribute("href").replace("#","");l+=a.getElementById(t).querySelectorAll("use").length}}return s.useElsNested=l,l};let i=/\<\!ENTITY/gi.test(e),u=!!/\<script/gi.test(e),h=!!/\<use/gi.test(e),y=/[\<path|\<polygon|\<polyline|\<rect|\<circle|\<ellipse|\<line|\<text|\<foreignObject]/gi.test(e),o=/[\<filter|\<linearGradient|\<radialGradient|\<pattern|\<animate|\<animateMotion|\<animateTransform|\<clipPath|\<mask|\<symbol|\<marker]/gi.test(e),c=(e.startsWith("M")||e.startsWith("m"))&&!/[\<svg|\<\/svg]/gi.test(e);if(s.isPathData=c,!i&&!h&&!u&&(y||o)&&n<t.fileSizeKB)return s.hasEls=y,s.hasDefs=o,s;!1===t.hasEntity&&i&&(s.hasEntity=!0);e=e.replace(/\<\?xml.+\?\>|\<\!DOCTYPE.+]\>/g,"").replace(/(<!--.*?-->)|(<!--[\S\s]+?-->)|(<!--[\S\s]*?$)/g,"");try{l=(new DOMParser).parseFromString(e,"text/html"),a=l.querySelector("svg");let t=a.querySelectorAll('path[d="M0,0"], path[d="M0 0"]').length,n=a.querySelectorAll("use").length;if(s.totalEls=a.querySelectorAll("*").length,s.geometryEls=a.querySelectorAll("path, rect, circle, ellipse, polygon, polyline, line").length,s.hasScripts=u,s.useEls=n,s.nonsensePaths=t,s.isSuspicious=!1,s.isBillionLaugh=!1,s.hasXmlns=!!a.getAttribute("xmlns")&&"http://www.w3.org/2000/svg"===a.getAttribute("xmlns"),s.isSymbolSprite=!(!a.querySelectorAll("symbol").length||0!==a.querySelectorAll("use").length),s.isSvgFont=!!a.querySelectorAll("glyph").length,100/s.totalEls*s.useEls>75){s.isSuspicious=!0,p(a.querySelectorAll("use"),r)>=r&&(s.isBillionLaugh=!0)}return s}catch{return console.warn("svg could not be parsed"),!1}}(e,t={useElsNested:5e3,hasScripts:!1,hasEntity:!1,fileSizeKB:1e4,isSymbolSprite:!1,isSvgFont:!1,...t}),a=!0,n=[];if(l.hasEls||(n.push("no elements"),a=!1),Object.keys(l).length){!0===l.isBillionLaugh&&(n.push("suspicious: might contain billion laugh attack"),a=!1);for(let e in t){let s=t[e],r=l[e];"number"==typeof s&&r>s&&(n.push(`allowed "${e}" exceeded: ${r} / ${s} `),a=!1),!0===r&&!1===s&&(n.push(`not allowed: "${e}" `),a=!1)}}else a=!1;return{isValid:a,log:n,fileReport:l}}function a(e,t,l="red",a="1%",n="1",s="",r=!0,p="",i=""){Array.isArray(t)&&(t={x:t[0],y:t[1]});let u=`<circle class="${i}" opacity="${n}" id="${p}" cx="${t.x}" cy="${t.y}" r="${a}" fill="${l}">\n <title>${s}</title></circle>`;if(!r)return u;e.insertAdjacentHTML("beforeend",u)}const{abs:n,acos:s,asin:r,atan:p,atan2:i,ceil:u,cos:h,exp:y,floor:o,log:c,max:x,min:f,pow:g,random:d,round:m,sin:v,sqrt:M,tan:b,PI:A}=Math;function C(e,t,l=!1){let a=i(t.y-e.y,t.x-e.x);return l&&a<0&&(a+=2*Math.PI),a}function S(e,t,l,a=!1){let n=Math.atan2(t.y-e.y,t.x-e.x),s=Math.atan2(l.y-e.y,l.x-e.x),r=s-n;r=(e=>{let t=e%(2*Math.PI);return t>Math.PI?t-=2*Math.PI:t<=-Math.PI&&(t+=2*Math.PI),t})(r),a&&(r=2*Math.PI-Math.abs(r));let p=180/Math.PI;return{startAngle:n,endAngle:s,deltaAngle:r,startAngleDeg:n*p,endAngleDeg:s*p,deltaAngleDeg:r*p}}function w(e=null,t=null,l=null,a=null,n=!0,s=!1,r=!1){let p,i,u,h,y,o={};if(!(e&&t&&l&&a))return r&&console.warn("points missing"),!1;if(e.x===t.x&&e.y===t.y||l.x===a.x&&l.y===a.y)return!1;try{if(p=(a.y-l.y)*(t.x-e.x)-(a.x-l.x)*(t.y-e.y),0===p)return!1}catch{return r&&console.warn("!catch",e,t,"p3:",l,"p4:",a),!1}i=e.y-l.y,u=e.x-l.x,h=(a.x-l.x)*i-(a.y-l.y)*u,y=(t.x-e.x)*i-(t.y-e.y)*u,i=h/p,u=y/p,o={x:e.x+i*(t.x-e.x),y:e.y+i*(t.y-e.y)};let c=!1;return i>0&&i<1&&u>0&&u<1&&(c=!0),!n&&s&&(i>0&&u<0||i<0&&u>0)?(c=!1,!1):!(n&&!c)&&o}function E(e,t,l,a=!1){let n={x:(t.x-e.x)*l+e.x,y:(t.y-e.y)*l+e.y};return a&&(n.angle=C(e,t),n.angle<0&&(n.angle+=2*A)),n}function L(e,t=.5,l=!1,a=!1,n=!1){let s;return Array.isArray(e[0])&&(e=e.map(e=>({x:e[0],y:e[1]})),n=!0),s=e.length>2?((e,t,l=!1)=>{let n=4===e.length,s=e[0],r=e[1],p=n?e[2]:e[1],i=e[e.length-1],u={x:0,y:0};if(l||a){let e,l,h,y,o,c=s.x===r.x&&s.y===r.y,x=i.x===p.x&&i.y===p.y;0!==t||c?1!==t||x?(c&&(t+=1e-7),x&&(t-=1e-7),e=E(s,r,t),n?(l=E(r,p,t),h=E(p,i,t),y=E(e,l,t),o=E(l,h,t),u=E(y,o,t),u.angle=C(y,o),a&&(u.cpts=[l,h,y,o])):(l=E(s,r,t),h=E(r,i,t),u=E(l,h,t),u.angle=C(l,h),a&&(u.cpts=[l,h]))):(u.x=i.x,u.y=i.y,u.angle=C(p,i)):(u.x=s.x,u.y=s.y,u.angle=C(s,r))}else{let e=1-t;u=n?{x:e*e*e*s.x+3*e*e*t*r.x+3*e*t*t*p.x+t*t*t*i.x,y:e*e*e*s.y+3*e*e*t*r.y+3*e*t*t*p.y+t*t*t*i.y}:{x:e*e*s.x+2*e*t*r.x+t*t*i.x,y:e*e*s.y+2*e*t*r.y+t*t*i.y}}return u})(e,t,l):E(e[0],e[1],t,l),l&&s.angle<0&&(s.angle+=2*A),n?[s.x,s.y]:s}function P(l,a,n,s,r,p,i,u,h,y=!0){const o=(e,t,l,a,n=!0)=>{let s=Math.atan2(a-t,l-e);return n&&s<0&&(s+=2*Math.PI),s};let c={cx:0,cy:0,rx:n=Math.abs(n),ry:s=Math.abs(s),startAngle:0,endAngle:0,deltaAngle:0,clockwise:i,xAxisRotation:r=n===s?0:r<0&&y?r+360:r,largeArc:p,sweep:i};if(0==n||0==s)throw Error("rx and ry can not be 0");let x,f,g=n===s?0:r*t,d=g?Math.sin(g):0,m=g?Math.cos(g):1,v=(l-u)/2,M=(a-h)/2,b=(l+u)/2,A=(a+h)/2,C=g?m*v+d*M:v,S=g?m*M-d*v:M,w=C*C/(n*n)+S*S/(s*s);if(w>1){let e=Math.sqrt(w);n*=e,s*=e,c.rx=n,c.ry=s}let E=n*s,L=n*S,P=s*C,T=L**2+P**2;if(!T)throw Error("start point can not be same as end point");let I=Math.sqrt(Math.abs((E*E-T)/T));p===i&&(I=-I);let D=I*L/s,k=-I*P/n;x=g?m*D-d*k+b:b+D,f=g?d*D+m*k+A:A+k,c.cy=f,c.cx=x;let q=o(x,f,l,a,y),Q=o(x,f,u,h,y);i?Q<q&&(Q+=2*Math.PI):Q>q&&(Q-=2*Math.PI);let z=Q-q;return c.startAngle=q,c.startAngle_deg=q*e,c.endAngle=Q,c.endAngle_deg=Q*e,c.deltaAngle=z,c.deltaAngle_deg=z*e,c}function T(e,t,l,a=0,n=!1){return a?(a=n?a/180*Math.PI:a,{x:t+(e.x-t)*Math.cos(a)-(e.y-l)*Math.sin(a),y:l+(e.x-t)*Math.sin(a)+(e.y-l)*Math.cos(a)}):e}function I(e,t,l,a,n,s=0,r=!0,i=!1){if(n=i?n*A/180:n,s=i?s*A/180:s,s=l!==a&&s!==2*A?s:0,r&&l!==a){let e=p(b(n=s?n-s:n)*(l/a));n=h(n)<0?e+A:e}let u=e+l*h(n),y=t+a*v(n),o={x:u,y:y};return s&&(o.x=e+(u-e)*h(s)-(y-t)*v(s),o.y=t+(u-e)*v(s)+(y-t)*h(s)),o}function D(e,t,l){if(t===l||e%A*.5==0)return e;let a=p(b(e)*(t/l));return a=h(e)<0?a+A:a,a}function k(e=null,t=[]){e||(e=t[0],t=t.slice(1,t.length));let l=t.length,a=t[l-1],n=t[0],s=3===l?t[1]:n,r=Math.min(e.y,a.y),p=Math.min(e.x,a.x),i=Math.max(e.x,a.x),u=Math.max(e.y,a.y);return!(n.y>=r&&n.y<=u&&s.y>=r&&s.y<=u&&n.x>=p&&n.x<=i&&s.x>=p&&s.x<=i)}function q(e,{addExtremes:t=!0,addSemiExtremes:l=!1}={}){let a=4===e.length?function(e,t,l,a,{addExtremes:n=!0,addSemiExtremes:s=!1}={}){const r=e=>{const t=Math.PI/4,l=Math.cos(t),a=Math.sin(t);return{x:e.x*l-e.y*a,y:e.x*a+e.y*l}};s&&(e=r(e),t=r(t),l=r(l),a=r(a));let[p,i,u,h,y,o,c,x]=[e.x,e.y,t.x,t.y,l.x,l.y,a.x,a.y],f=Math.min(e.y,a.y),g=Math.min(e.x,a.x),d=Math.max(e.x,a.x),m=Math.max(e.y,a.y);if(t.y>=f&&t.y<=m&&l.y>=f&&l.y<=m&&t.x>=g&&t.x<=d&&l.x>=g&&l.x<=d)return[];let v,M,b,A,C,S,w,E,L=[];for(let e=0;e<2;++e)if(0==e?(M=6*p-12*u+6*y,v=-3*p+9*u-9*y+3*c,b=3*u-3*p):(M=6*i-12*h+6*o,v=-3*i+9*h-9*o+3*x,b=3*h-3*i),Math.abs(v)<1e-8){if(Math.abs(M)<1e-8)continue;A=-b/M,0<A&&A<1&&L.push(A)}else w=M*M-4*b*v,w<0?Math.abs(w)<1e-8&&(A=-M/(2*v),0<A&&A<1&&L.push(A)):(E=Math.sqrt(w),C=(-M+E)/(2*v),0<C&&C<1&&L.push(C),S=(-M-E)/(2*v),0<S&&S<1&&L.push(S));let P=L.length;for(;P--;)A=L[P];return L}(e[0],e[1],e[2],e[3],{addExtremes:t,addSemiExtremes:l}):function(e,t,l,{addExtremes:a=!0,addSemiExtremes:n=!1}={}){const s=e=>{const t=-Math.PI/4,l=Math.cos(t),a=Math.sin(t);return{x:e.x*l-e.y*a,y:e.x*a+e.y*l}};n&&(e=s(e),t=s(t),l=s(l));let r,p,i,u=Math.min(e.y,l.y),h=Math.min(e.x,l.x),y=Math.max(e.x,l.x),o=Math.max(e.y,l.y);if(t.y>=u&&t.y<=o&&t.x>=h&&t.x<=y)return[];let[c,x,f,g,d,m]=[e.x,e.y,t.x,t.y,l.x,l.y],v=[];for(let e=0;e<2;++e)r=0==e?c-2*f+d:x-2*g+m,p=0==e?-2*c+2*f:-2*x+2*g,Math.abs(r)>1e-12&&(i=-p/(2*r),i>0&&i<1&&v.push(i));return v}(e[0],e[1],e[2],{addExtremes:t,addSemiExtremes:l});return a}function Q(e,t){const l=(e,t,l,a,n,s)=>{var r=Math.cos(s),p=Math.sin(s),i=a*Math.cos(e),u=n*Math.sin(e);return{x:t+r*i-p*u,y:l+p*i+r*u}};let a,n,s,r,p,i=P(e.x,e.y,t[0],t[1],t[2],t[3],t[4],t[5],t[6]),{rx:u,ry:h,cx:y,cy:o,endAngle:c,deltaAngle:x}=i,f=t[2],g={x:t[5],y:t[6]},d=[g],m=f*Math.PI/180,v=Math.tan(m);p=Math.atan2(-h*v,u);let M=p,b=p+Math.PI,A=Math.atan2(h,u*v),C=A+Math.PI,S=[e.x,g.x],w=[e.y,g.y],E=Math.min(...S),L=Math.max(...S),T=Math.min(...w),I=Math.max(...w),D=l(c-.001*x,y,o,u,h,m),k=l(c-.999*x,y,o,u,h,m);return(D.x>L||k.x>L)&&(a=l(M,y,o,u,h,m),d.push(a)),(D.x<E||k.x<E)&&(n=l(b,y,o,u,h,m),d.push(n)),(D.y<T||k.y<T)&&(r=l(C,y,o,u,h,m),d.push(r)),(D.y>I||k.y>I)&&(s=l(A,y,o,u,h,m),d.push(s)),d}function z(e=[],t=[]){let l=e.length,a=4===l;t.length||(t=[0]);let n=t.length,s=[];for(let r=0;r<n;r++){let n=t[r],p=n?[]:e.slice(0);if(n)for(let t=0;t<l;t++){let l=e[t];p.push(T(l,0,0,n))}let i=a?$(...p):F(...p);s.push(...i)}return s=[...new Set(s)].sort(),s}function $(e,t,l,a){if(!k(e,[t,l,a]))return[];let n,s,r,p,i,u,h,y,[o,c,x,f,g,d,m,v]=[e.x,e.y,t.x,t.y,l.x,l.y,a.x,a.y],M=[],b=1e-8;for(let e=0;e<2;++e)if(0==e?(s=6*o-12*x+6*g,n=-3*o+9*x-9*g+3*m,r=3*x-3*o):(s=6*c-12*f+6*d,n=-3*c+9*f-9*d+3*v,r=3*f-3*c),Math.abs(n)<b){if(Math.abs(s)<b)continue;p=-r/s,p>0&&p<1&&M.push(p)}else h=s*s-4*r*n,h<0?Math.abs(h)<b&&(p=-s/(2*n),p>0&&p<1&&M.push(p)):(y=Math.sqrt(h),i=(-s+y)/(2*n),i>0&&i<1&&M.push(i),u=(-s-y)/(2*n),u>0&&u<1&&M.push(u));let A=M.length;for(;A--;)p=M[A];return[...new Set(M)].sort()}function F(e,t,l){if(!k(e,[t,l]))return[];let a,n,s,[r,p,i,u,h,y]=[e.x,e.y,t.x,t.y,l.x,l.y],o=[];for(let e=0;e<2;++e)a=0==e?r-2*i+h:p-2*u+y,n=0==e?-2*r+2*i:-2*p+2*u,Math.abs(a)>1e-12&&(s=-n/(2*a),s>0&&s<1&&o.push(s));return[...new Set(o)].sort()}function j(e,t=.001){let l=Math.PI/2,a=l/2;return!(Math.abs(e/l-Math.round(e/l))<t)&&Math.abs(e/a-Math.round(e/a))<t}function B(e,t,l=!1){let a=l?t[0]-e[0]:t.x-e.x,n=l?t[1]-e[1]:t.y-e.y;return Math.sqrt(a*a+n*n)}function R(e,t){let l=t.x-e.x,a=t.y-e.y;return l*l+a*a}function O(e,t){return Math.abs(t.x-e.x)+Math.abs(t.y-e.y)}function N(e,t){return.5*(Math.abs(t.x-e.x)+Math.abs(t.y-e.y))}function Z(e){let t=[],l=[e[0]],a=e.length;for(let n=1;n<a;n++){let a=e[n];"M"!==a.type&&"m"!==a.type||(t.push(l),l=[]),l.push(a)}return l.length&&t.push(l),t}function W(e,t){let l,a,n,s,r,p,i=[],u=[],h=e[0],y=e[1],o=e[e.length-2],c=e[e.length-1];return 4===e.length?(l=L([h,y],t),a=L([y,o],t),n=L([o,c],t),s=L([l,a],t),r=L([a,n],t),p=L([s,r],t),i.push({x:h.x,y:h.y},{x:l.x,y:l.y},{x:s.x,y:s.y},{x:p.x,y:p.y}),u.push({x:p.x,y:p.y},{x:r.x,y:r.y},{x:n.x,y:n.y},{x:c.x,y:c.y})):3===e.length?(a=L([h,y],t),n=L([y,c],t),p=L([a,n],t),i.push({x:h.x,y:h.y},{x:a.x,y:a.y},{x:p.x,y:p.y}),u.push({x:p.x,y:p.y},{x:n.x,y:n.y},{x:c.x,y:c.y})):2===e.length&&(a=L([h,c],t),i.push({x:h.x,y:h.y},{x:a.x,y:a.y}),u.push({x:a.x,y:a.y},{x:c.x,y:c.y})),[i,u]}function J(e,t,{tMin:l=0,tMax:a=1,addExtremes:n=!0,addSemiExtremes:s=!1}={}){let r=[],p=6===t.length?"C":"Q",i={x:t[0],y:t[1]},u="C"===p?{x:t[2],y:t[3]}:i,h={x:t[4],y:t[5]},y=0;let o="C"===p?[e,i,u,h]:[e,i,h],c=n?q(o,{addExtremes:n,addSemiExtremes:!1}):[],x=s?q(o,{addExtremes:n,addSemiExtremes:s}):[],f=Array.from(new Set([...c,...x])).sort();if(f=f.filter(e=>e>0&&e<1),f.length){let l=function(e,t,l,a=!0){let n=[];if(!l.length)return!1;let s,r,p,i=t.length,u={x:t[i-2],y:t[i-1]};2===t.length?p=[e,u]:4===t.length?(s={x:t[0],y:t[1]},p=[e,s,u]):6===t.length&&(s={x:t[0],y:t[1]},r={x:t[2],y:t[3]},p=[e,s,r,u]);if(l.length)if(1===l.length){let e=W(p,l[0]),t=e[0],a=e[1];n.push(t,a)}else{let e=l[0],t=W(p,e),a=t[0];n.push(a),p=t[1];for(let t=1;t<l.length;t++){e=l[t-1];let a=W(p,(l[t]-e)/(1-e));n.push(a[0]),t===l.length-1&&n.push(a[a.length-1]),p=a[1]}}if(a){let e,t,l=[];return n.forEach(a=>{e={type:"",values:[]},a.shift(),t=a.map(e=>Object.values(e)).flat(),e.values=t,3===a.length?e.type="C":2===a.length?e.type="Q":1===a.length&&(e.type="L"),l.push(e)}),l}return n}(e,t,f);r.push(...l),y+=l.length}else r.push({type:p,values:t});return{pathData:r,count:y}}function V(e,{tMin:t=0,tMax:l=1,addExtremes:a=!0,addSemiExtremes:n=!1}={}){let s=[e[0]],r={x:e[0].values[0],y:e[0].values[1]},p={x:e[0].values[0],y:e[0].values[1]},i=e.length;for(let u=1;i&&u<i;u++){let i=e[u],{type:h,values:y}=i,o=y.slice(-2);if(o[0],o[1],"C"!==h&&"Q"!==h)s.push(i);else if((a||n)&&("C"===h||"Q"===h)){let e=J(r,y,{tMin:t,tMax:l,addExtremes:a,addSemiExtremes:n}).pathData;s.push(...e)}r={x:o[0],y:o[1]},"z"===h.toLowerCase()?r=p:"M"===h&&(p={x:o[0],y:o[1]})}return s}function H(e,t=-1){if(t<0)return e;let l=e.length,a=t,n=a<3?a+2:a;for(let t=0;t<l;t++){let l=e[t],{type:s,values:r}=l,p=r.length;if(!p)continue;let i="a"===s.toLowerCase();for(let l=0;l<p;l++)e[t].values[l]=K(r[l],i&&l<2?n:a)}return e}function K(e=0,t=3){if(t<0)return e;if(!t)return Math.round(e);let l=Math.floor(t);if(l!==t){let a=+(t-l).toFixed(2);a=a>.5?.5*Math.floor(a/.5):a;let n=10**-l*a;return+(Math.round(e/n)*n).toFixed(8)}let a=10**t;return Math.round(e*a)/a}function _(e,t=-1){let l=e.map(e=>e.x),a=e.map(e=>e.y),n=Math.min(...l),s=Math.max(...l),r=Math.min(...a),p=Math.max(...a),i={x:n,left:n,right:s,y:r,top:r,bottom:p,width:s-n,height:p-r};if(t>-1)for(let e in i)i[e]=+i[e].toFixed(t);return i}function G(e){let t=[];return e.forEach(e=>{let l=function(e){let t=function(e){let t=[];for(let l=0;l<e.length;l++){let a=e[l],n=l>0?e[l-1]:e[l],{type:s,values:r}=a,p={x:n.values[n.values.length-2],y:n.values[n.values.length-1]},i=r.length?{x:r[r.length-2],y:r[r.length-1]}:"",u=r.length?{x:r[0],y:r[1]}:"";switch(s){case"A":if("function"!=typeof arcToBezier){let e=B(p,i)/2,l=E(p,i,.5),a=I(l.x,l.y,e,e,0),n=I(l.x,l.y,e,e,Math.PI);t.push(a,n,i);break}arcToBezier(p,r).forEach(e=>{let l=e.values,a={x:l[0],y:l[1]},n={x:l[2],y:l[3]},s={x:l[4],y:l[5]};t.push(a,n,s)});break;case"C":let e={x:r[2],y:r[3]};t.push(u,e);break;case"Q":t.push(u)}"z"!==s.toLowerCase()&&t.push(i)}return t}(e),l=_(t);return l}(e);t.push(l)}),t}function U(e,t){let[l,a,n,s,r,p]=[e.x,e.y,e.width,e.height,e.x+e.width,e.y+e.height],[i,u,h,y,o,c]=[t.x,t.y,t.width,t.height,t.x+t.width,t.y+t.height],x=!1;return n*s!=h*y&&n*s>h*y&&l<i&&r>o&&a<u&&p>c&&(x=!0),x}function X(e,t=9){let l=0,a=[],n=Z(e),s=n.length>1,r=[];if(s){let e=G(n);e.forEach(function(t,l){for(let l=0;l<e.length;l++){let a=e[l];if(t!=a){U(t,a)&&r.push(l)}}})}return n.forEach((e,t)=>{a=[];let n=0,s=0,p=1,i=[];e.forEach(function(t,l){let[s,r]=[t.type,t.values],p=r.length;if(r.length){let u=(l>0?e[l-1]:e[0]).values,h=u.length,y={x:u[h-2],y:u[h-1]},o={x:r[p-2],y:r[p-1]};if("C"===s||"Q"===s){let e={x:r[0],y:r[1]};i="C"===s?[y,e,{x:r[2],y:r[3]},o]:[y,e,o];let t=Math.abs(function(e,t=!1){let l,[a,n,s,r]=[e[0],e[1],e[2],e[e.length-1]];if(e.length<3)return 0;3===e.length&&(n={x:1*e[0].x/3+2*e[1].x/3,y:1*e[0].y/3+2*e[1].y/3},s={x:1*e[2].x/3+2*e[1].x/3,y:1*e[2].y/3+2*e[1].y/3});return l=3*(a.x*(-2*n.y-s.y+3*r.y)+n.x*(2*a.y-s.y-r.y)+s.x*(a.y+n.y-2*r.y)+r.x*(-3*a.y+n.y+2*s.y))/20,t?Math.abs(l):l}(i));n+=t,a.push(y,o)}else if("A"===s){let e=P(y.x,y.y,t.values[0],t.values[1],t.values[2],t.values[3],t.values[4],o.x,o.y),{cx:l,cy:s,rx:r,ry:p,startAngle:i,endAngle:u,deltaAngle:h}=e,c=Math.abs(function(e,t,l,a){const n=Math.PI*e*t;let s=(a-l+2*Math.PI)%(2*Math.PI);if(e===t)return n*(s/(2*Math.PI));const r=l=>Math.atan2(e*Math.sin(l),t*Math.cos(l));return l=r(l),a=r(a),s=(a-l+2*Math.PI)%(2*Math.PI),n*(s/(2*Math.PI))}(r,p,i,u));c-=Math.abs(Y([y,{x:l,y:s},o])),a.push(y,o),n+=c}else a.push(y,o)}});let u=Y(a);-1!==r.indexOf(t)&&(p=-1),s=u<0&&n<0?(Math.abs(n)-Math.abs(u))*p:(Math.abs(n)+Math.abs(u))*p,l+=s}),l}function Y(e,t=!1){let l=0,a=e.length;for(let t=0;a&&t<a;t++){l+=e[t].x*e[t===e.length-1?0:t+1].y*.5-e[t===e.length-1?0:t+1].x*e[t].y*.5}return t&&(l=Math.abs(l)),l}function ee(e,t=0){t=parseFloat(t);let l=e.length,a=e[0].values.join(" "),n=t>1?"\n":t<1?"":" ",s=t>.5?" ":"",r=`${e[0].type}${s}${a}${n}`;for(let p=1;p<l;p++){let i=e[p-1],u=e[p],{type:h,values:y}=u;if(a="",t||"A"!==h&&"a"!==h||(y=[y[0],y[1],y[2],`${y[3]}${y[4]}${y[5]}`,y[6]]),h=t<1&&i.type===u.type&&"m"!==u.type.toLowerCase()||t<1&&"M"===i.type&&"L"===u.type?" ":u.type,t)a=y.join(" ");else{let e=!1;for(let t=0,l=y.length;t<l;t++){let l=y[t],n=l.toString(),s=n.includes(".")&&Math.abs(l)<1;s&&e&&(n=n.replace(/^0\./,".")),!(t>0)||e&&s||(a+=" "),a+=n,e=s}}p===l-1&&(n=""),r+=`${h}${s}${a}${n}`}return t<1&&(r=r.replace(/[A-Za-z]0(?=\.)/g,e=>e[0]).replace(/ 0\./g," .").replace(/ -/g,"-").replace(/-0\./g,"-.").replace(/Z/g,"z")),r}function te(e,t,l=0,a=1,n=!1){const s=(e,t,l,a,n)=>{let s=1-n;return{x:3*s*s*(t.x-e.x)+6*s*n*(l.x-t.x)+3*n*n*(a.x-l.x),y:3*s*s*(t.y-e.y)+6*s*n*(l.y-t.y)+3*n*n*(a.y-l.y)}};let r=[e,t],p=N(e.p0,e.p)>N(t.p0,t.p),i=JSON.parse(JSON.stringify(e)),u=JSON.parse(JSON.stringify(t)),h=w(i.p0,i.cp1,u.p,u.cp2,!1);if(!h)return r;if(p){let l={p0:{x:e.p.x,y:e.p.y},cp1:{x:e.cp2.x,y:e.cp2.y},cp2:{x:e.cp1.x,y:e.cp1.y},p:{x:e.p0.x,y:e.p0.y}};e={p0:{x:t.p.x,y:t.p.y},cp1:{x:t.cp2.x,y:t.cp2.y},cp2:{x:t.cp1.x,y:t.cp1.y},p:{x:t.p0.x,y:t.p0.y}},t=l}let y=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),o=(e,t)=>({x:e.x*t,y:e.y*t}),c=(e,t)=>e.x*t.x+e.y*t.y,x=t.p0,f=s(t.p0,t.cp1,t.cp2,t.p,0),g=c(y(e.p0,x),f)/c(f,f),d=L([t.p0,t.cp1,t.cp2,t.p],g),m=s(t.p0,t.cp1,t.cp2,t.p,g);g-=c(y(d,e.p0),m)/c(m,m);let v=L([t.p0,t.cp1,t.cp2,t.p],g),M=t.p,b=s(t.p0,t.cp1,t.cp2,t.p,g),A=s(t.p0,t.cp1,t.cp2,t.p,1),C=1-g,S=(P=v,T=o(b,C/3),{x:P.x+T.x,y:P.y+T.y});var P,T;let I=y(M,o(A,C/3)),D={p0:v,cp1:S,cp2:I,p:M,t0:g};p&&(D={p0:M,cp1:I,cp2:S,p:v,t0:g});let k=.5*(1-g),q=L([D.p0,D.cp1,D.cp2,D.p],k,!1,!0),Q=q.cpts[2],z=w(q,Q,D.p0,h,!1),$=w(q,Q,D.p,h,!1),F=E(D.p0,z,1.333),j=E(D.p,$,1.333);if(w(i.p0,F,u.p,j,!0))return r;D.cp1=F,D.cp2=j;let B=N(i.p0,D.p0)+N(u.p,D.p);if(D.p0=i.p0,D.p=u.p,D.extreme=u.extreme,D.corner=u.corner,D.dimA=u.dimA,D.directionChange=u.directionChange,D.type="C",D.values=[D.cp1.x,D.cp1.y,D.cp2.x,D.cp2.y,D.p.x,D.p.y],B<l){let t=p?1+g:Math.abs(g),s=1+Math.abs(g);if(t=p?1+g:Math.abs(g)/s,N(L([D.p0,D.cp1,D.cp2,D.p],t),e.p)>l*a)return r;let h=X([{type:"M",values:[i.p0.x,i.p0.y]},{type:"C",values:[i.cp1.x,i.cp1.y,i.cp2.x,i.cp2.y,i.p.x,i.p.y]},{type:"C",values:[u.cp1.x,u.cp1.y,u.cp2.x,u.cp2.y,u.p.x,u.p.y]}]),y=[{type:"M",values:[D.p0.x,D.p0.y]},{type:"C",values:[D.cp1.x,D.cp1.y,D.cp2.x,D.cp2.y,D.p.x,D.p.y]}],o=X(y),c=Math.abs(o/h-1);D.error=5*c*a,n&&ee(y),c<.05*a&&(r=[D])}return r}function le(e,{keepExtremes:t=!0,keepInflections:l=!0,keepCorners:a=!0,extrapolateDominant:n=!0,tolerance:s=1}={}){let r=[e[0]],p=e.length;for(let n=2;p&&n<=p;n++){let i=e[n-1],u=n<p?e[n]:null,h=u?.type||null,{type:y,values:o,p0:c,p:x,cp1:f=null,cp2:g=null,extreme:d=!1,directionChange:m=!1,corner:v=!1,dimA:M=0}=i;if("C"===y&&"C"===h)if(a&&v||t&&d)r.push(i);else{let h=ae(i,u,{tolerance:s}),y=0;if(1===h.length){i=h[0];let u=1;y+=i.error;for(let r=n+u;y<s&&r<p;r++){let n=e[r];if("C"!==n.type||l&&i.directionChange||a&&i.corner||t&&i.extreme)break;let p=ae(i,n,{tolerance:s});if(p.length>1)break;y+=.5*p[0].error,u++,i=p[0]}r.push(i),n<p&&(n+=u)}else r.push(i)}else r.push(i)}return r}function ae(e,t,{tolerance:l=1}={}){let a=[e,t],n=function(e,t){let l=O(e.cp2,e.p);if(0===l)return 0;let a=O(e.p,t.cp1);if(0===a)return 0;let n=O(e.cp2,t.cp1);return l/n}(e,t);if(!n)return a;let s=O(e.p0,e.p),r=O(t.p0,t.p),p=.08*Math.max(0,Math.min(s,r))*l,i=function(e,t,l=0){let{p0:a,cp1:n}=e,{p:s,cp2:r}=t;return n={x:(n.x-(1-l)*a.x)/l,y:(n.y-(1-l)*a.y)/l},r={x:(r.x-l*s.x)/(1-l),y:(r.y-l*s.y)/(1-l)},{p0:a,cp1:n,cp2:r,p:s}}(e,t,n),u=L([i.p0,i.cp1,i.cp2,i.p],n),h=O(e.p,u),y=0,o=0,c=!1,x=h;if(h<p){let l=.5*n;if(y=O(L([e.p0,e.cp1,e.cp2,e.p],.5),L([i.p0,i.cp1,i.cp2,i.p],l)),x+=y,y<p){let e=.5*(1+n);o=O(L([t.p0,t.cp1,t.cp2,t.p],.5),L([i.p0,i.cp1,i.cp2,i.p],e)),x+=o,x<p&&(c=!0)}}return c&&(i.p0=e.p0,i.p=t.p,i.dimA=O(i.p0,i.p),i.type="C",i.extreme=t.extreme,i.directionChange=t.directionChange,i.corner=t.corner,i.extreme||i.corner,i.values=[i.cp1.x,i.cp1.y,i.cp2.x,i.cp2.y,i.p.x,i.p.y],i.error=x/p,a=[i]),a}function ne(e,{tolerance:t=1,debug:l=!1}={}){let a=!1,n={flat:!0,steepness:0},s=e[0],r=e[e.length-1],p=new Set([...e.map(e=>+e.x.toFixed(8))]),i=new Set([...e.map(e=>+e.y.toFixed(8))]);if(1===p.size||1===i.size)return!l||n;let u=R(s,r),h=u/1e3*t,y=Y(e,!0);return y<h&&(a=!0),l&&(n.flat=a,n.steepness=y/u*10),l?n:a}function se(e=[],{detectExtremes:t=!0,detectCorners:l=!0,detectDirection:n=!0,detectSemiExtremes:s=!1,debug:r=!1,addSquareLength:p=!0,addArea:i=!0}={}){e=function(e,{addSquareLength:t=!0,addArea:l=!1,addArcParams:a=!1,addAverageDim:n=!0}={}){let s=e[0],r={x:s.values[0],y:s.values[1]},p=r,i=r;s.p0=p,s.p=i,s.idx=0,s.dimA=0;let u=e.length,h=[s];for(let n=1;n<u;n++){let s,u,y=e[n],{type:o,values:c}=y,x=c.length;if(i=x?{x:c[x-2],y:c[x-1]}:r,y.p0=p,y.p=i,y.dimA=O(p,i),"M"===o&&(r=i),"Q"===o||"C"===o)s={x:c[0],y:c[1]},u="C"===o?{x:c[2],y:c[3]}:null,y.cp1=s,u&&(y.cp2=u);else if("A"===o&&a){let{rx:e,ry:t,cx:l,cy:a,startAngle:n,endAngle:s,deltaAngle:r}=P(p.x,p.y,...c);y.cx=l,y.cy=a,y.rx=e,y.ry=t,y.xAxisRotation=c[2]/180*Math.PI,y.largeArc=c[3],y.sweep=c[4],y.startAngle=n,y.endAngle=s,y.deltaAngle=r}if("Z"===o&&r.x!==i.x&&r.y!==i.y&&(y.closePath=!0),t&&(y.squareDist=R(p,i)),l){let e=0;"C"===o&&(e=Y([p,s,u,i],!1)),"Q"===o&&(e=Y([p,s,i],!1)),y.cptArea=e}y.idx=n,p=i,h.push(y)}return h}(e,{addSquareLength:p,addArea:i});let u=[],h=function(e=[],t=!1,l=-1){let a=[];return e.forEach(e=>{let{type:n,values:s}=e;if(s.length)if(l>-1&&(s=s.map(e=>+e.toFixed(l))),t)for(let e=1;e<s.length;e+=2)a.push({x:s[e-1],y:s[e]});else a.push({x:s[s.length-2],y:s[s.length-1]})}),a}(e),y=_(h),{left:o,right:c,top:x,bottom:f,width:g,height:d}=y;e[0].corner=!1,e[0].extreme=!1,e[0].semiExtreme=!1,e[0].directionChange=!1,e[0].closePath=!1;let m=[e[0]],v=e.length;for(let t=2;v&&t<=v;t++){let l=e[t-1],{type:a,values:n,p0:r,p:p,cp1:i=null,cp2:u=null,squareDist:h=0,cptArea:y=0,dimA:g=0}=l,d=e[t-2],v=e[t]||null;l.corner=!1,l.extreme=!1,l.semiExtreme=!1,l.directionChange=!1,l.closePath=!1;let M="C"===a||"Q"===a?"C"===a?[r,i,u,p]:[r,i,p]:[r,p],b=.1*g,A=.01*b,S="Q"===a||"C"===a,w="A"===a,E=v&&("Q"===v.type||"C"===v.type),L=!1;
2
2
  //!isFlat &&
3
- if(S){let e="C"===a?Math.abs(l.cp2.x-l.p.x):Math.abs(l.cp1.x-l.p.x),t="C"===a?Math.abs(l.cp2.y-l.p.y):Math.abs(l.cp1.y-l.p.y);if(((0===t||t<=A)&&e>0||(0===e||e<=A)&&t>0)&&(L=!0),(i.x===r.x&&i.y!==r.y||i.y===r.y&&i.x!==r.x)&&(m[m.length-1].extreme=!0),p.x!==o&&p.y!==x&&p.x!==c&&p.y!==f||(L=!0),!L){if(k(null,M)){let e=z(M);e.length&&e[0]>.2&&(L=!0)}}}else if(w&&v&&("C"===d.type||"Q"===d.type||"C"===v.type||"Q"===v.type)){let e=v?v.dimA:0,t=l.dimA<.1*(d.dimA+e),a=l.values[0]===l.values[1]&&l.values[0]<1;if(t&&a){let e=_([d.p0,v.p]);(p.x>e.right||p.x<e.x||p.y<e.y||p.y>e.bottom)&&(L=!0)}}if(L&&(l.extreme=!0),S&&E){if(s&&!l.extreme){let e=Math.abs(p.x-u.x),t=Math.abs(p.y-u.y),a=!1;if(e&&t&&e>b||t>b){let e=C(u,p),t=C(p,v.cp1);a=j(Math.abs(e+t)/2)}a&&(l.semiExtreme=!0)}if((l.cptArea<0&&v.cptArea>0||l.cptArea>0&&v.cptArea<0)&&(l.directionChange=!0),!l.extreme){let e=u||i,t=v.cp1,a=Y([e,p,t],!1),n=.01*R(e,t),s=Math.abs(a)<n,r=a<0&&l.cptArea>0||a>0&&l.cptArea<0;!s&&r&&(l.corner=!0)}}m.push(l)}return r&&m.forEach(e=>{e.directionChange&&a(markers,e.p,"orange","1.5%","0.5"),e.corner&&a(markers,e.p,"magenta","1.5%","0.5"),e.extreme&&a(markers,e.p,"cyan","1%","0.5")}),u={pathData:m,bb:y,dimA:(g+d)/2},u}const re=new Set([77,109,65,97,67,99,76,108,81,113,83,115,84,116,72,104,86,118,90,122]),pe=new Uint8Array(128);pe[77]=2,pe[109]=2,pe[65]=7,pe[97]=7,pe[67]=6,pe[99]=6,pe[76]=2,pe[108]=2,pe[81]=4,pe[113]=4,pe[83]=4,pe[115]=4,pe[84]=2,pe[116]=2,pe[72]=1,pe[104]=1,pe[86]=1,pe[118]=1,pe[90]=0,pe[122]=0;const ie=new Set([5760,6158,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288,65279]),ue=e=>32===e||44===e||10===e||13===e||8232===e||8233===e||9===e||11===e||12===e||160===e||e>=5760&&ie.has(e);function he(e,{toShorthands:t=!0,toLonghands:l=!1,toRelative:a=!0,toMixed:n=!1,toAbsolute:s=!1,decimals:r=3,arcToCubic:p=!1,quadraticToCubic:i=!1,hasRelatives:u=!0,hasShorthands:h=!0,hasQuadratics:y=!0,hasArcs:o=!0,isPoly:c=!1,optimizeArcs:x=!0,testTypes:f=!1}={}){let g=[];if(f){let t=Array.from(new Set(e.map(e=>e.type))).join("");/[lcqamts]/gi.test(t),y=/[qt]/gi.test(t),o=/[a]/gi.test(t),h=/[vhst]/gi.test(t),/[mlz]/gi.test(t)}if(a=!s&&a,t=!l&&t,s&&(e=fe(e)),h&&l&&(e=function(e,t=-1,l=!0){let a=!1;if(l){let t=e.map(e=>e.type).join(""),l=/[hstv]/gi.test(t);if(a=/[astvqmhlc]/g.test(t),!l)return e}e=l&&a?fe(e,t):e;let n=[],s={type:"M",values:e[0].values};n.push(s);for(let l=1,a=e.length;l<a;l++){let a,r,p,i,u,h,y,o,c=e[l],{type:x,values:f}=c,g=f.length,d=s.values,m=d.length,[v,M]=[f[g-2],f[g-1]],[b,A]=[d[m-2],d[m-1]];switch(x){case"H":s={type:"L",values:[f[0],A]};break;case"V":s={type:"L",values:[b,f[0]]};break;case"T":[a,r]=[d[0],d[1]],[b,A]=[d[m-2],d[m-1]],p=b+(b-a),i=A+(A-r),s={type:"Q",values:[p,i,v,M]};break;case"S":[a,r]=[d[0],d[1]],[b,A]=[d[m-2],d[m-1]],[y,o]=m>2&&"A"!==s.type?[d[2],d[3]]:[b,A],p=2*b-y,i=2*A-o,u=f[0],h=f[1],s={type:"C",values:[p,i,u,h,v,M]};break;default:s={type:x,values:f}}t>-1&&(s.values=s.values.map(e=>+e.toFixed(t))),n.push(s)}return n}(e)),x&&(e=function(e=[]){let t=e.length,l=[];for(let a=0;a<t;a++){let t=e[a],{type:n,values:s}=t;if("A"!==n){l.push(t);continue}let[r,p,i,u,h]=[s[0],s[1],s[3],s[5],s[6]],y=e[a-1],[o,c]=[y.values[y.values.length-2],y.values[y.values.length-1]],x={x:o,y:c},f={x:u,y:h};0!==r&&0!==p||(e[a]=null);let g=r/p,d=r!==p?Math.abs(1-g):0;if(d>.01){l.push(t);continue}t.values[2]=0;let m=.001*O(x,f),v=Math.abs(u-o),M=Math.abs(h-c),b=M<m;if(b||v<m){(b?1.9*r>v:1.9*p>M)||(r=r>=1?1:r>.5?.5:r),t.values[0]=r,t.values[1]=r,l.push(t);continue}let A=.5*B(x,f);d=r/A,d<.5&&(r=A>=1?1:A>.5?.5:A),t.values[0]=r,t.values[1]=r,l.push(t)}return l}(e)),t&&(e=function(e,t=-1,l=!1){let a;if(l){let t=e.map(e=>e.type).join("");a=/[astvqmhlc]/g.test(t)}e=l&&a?xe(e):e;let n=e.length,s=new Array(n),r=e[0];s[0]=r;let p={x:e[0].values[0],y:e[0].values[1]},i=p;for(let t=1;t<n;t++){let l=e[t];r=l;let{type:a,values:n}=l,u=n.length,h=[n[u-2],n[u-1]],y=e[t-1];i={x:h[0],y:h[1]};let o=Math.abs(i.x-p.x),c=Math.abs(i.y-p.y),x=.01*O(p,i),f=!1,g=!1,d=!1;if("C"===a&&"C"===y.type||"Q"===a&&"Q"===y.type){let e="C"===y.type?{x:y.values[2],y:y.values[3]}:{x:y.values[0],y:y.values[1]},t={x:n[0],y:n[1]},l=p.x-e.x,a=p.y-e.y;x=.01*O(e,t),f=O({x:e.x+2*l,y:e.y+2*a},t)<x}else"L"===a&&(g=0===c||c<x,d=0===o||o<x,f=d||g);switch(a){case"L":g&&(r={type:"H",values:[n[0]]}),d&&(r={type:"V",values:[n[1]]});break;case"Q":f&&(r={type:"T",values:[i.x,i.y]});break;case"C":f&&(r={type:"S",values:[n[2],n[3],i.x,i.y]});break;default:r={type:a,values:n}}p=i,s[t]=r}return s}(e)),o&&p&&(e=function(e,{arcAccuracy:t=1}={}){let l=[e[0]];for(let a=1,n=e.length;a<n;a++){let n=e[a],s=e[a-1].values,r=s.length,p={x:s[r-2],y:s[r-1]};if("A"===n.type){de(p,n.values,t).forEach(e=>{l.push(e)})}else l.push(n)}return l}(e)),y&&i&&(e=function(e){let t=[e[0]];for(let l=1,a=e.length;l<a;l++){let a=e[l],n=e[l-1].values,s=n.length,r={x:n[s-2],y:n[s-1]};"Q"===a.type?t.push(ce(r,a.values)):t.push(a)}return t}(e)),n&&(a=!0),r>-1&&a&&(e=H(e,r)),n&&(g=JSON.parse(JSON.stringify(e))),a&&(e=function(e,t=-1){return xe(e,!0,t)}(e)),r>-1&&(e=H(e,r)),n)for(let t=0;t<e.length;t++){let l=e[t],a=g[t],n=[l.type,l.values.join(" ")].join("").replaceAll(" -","-").replaceAll(" 0."," ."),s=[a.type,a.values.join(" ")].join("").replaceAll(" -","-").replaceAll(" 0."," ."),r=n.length;s.length<r&&(e[t]=g[t])}return e}function ye(e,{toAbsolute:t=!0,toLonghands:l=!0,quadraticToCubic:a=!1,arcToCubic:n=!1,arcAccuracy:s=4}={}){let r=Array.isArray(e),p=r&&"object"==typeof e[0]&&"function"==typeof e[0].constructor,i=r?e:function(e,t=!0,l=0){if(!e)return[];e=e.trim(),l&&console.log("!!!limit",l);let a={pathData:[],hasRelatives:!1,hasShorthands:!1,hasArcs:!1,hasQuadratics:!1,isPolygon:!1,log:[]};if(""===e)return a;let n,s=0,r=e.length,p="",i=-1,u="",h=!1,y=0,o=0,c=0,x=!1,f=new Set([]);const g=()=>{x&&("M"===p?p="L":"m"===p&&(p="l"),a.pathData.push({type:p,values:[]}),i++,o=0,x=!1)},d=(e=!1)=>{(e?y>0:""!==u)&&(t&&-1===i&&(n="Pathdata must start with M command",a.log.push(n),p="M",a.pathData.push({type:p,values:[]}),c=2,o=0,i++),"A"===p||"a"===p?(({val:u,valueIndex:o}=((e="",t=0)=>{let l=e.length;return 3===t&&2===l?(e=[+e[0],+e[1]],t++):4===t&&l>1?(e=[+e[0],+e.substring(1)],t++):3===t&&l>=3?(e=[+e[0],+e[1],+e.substring(2)],t+=2):e=[+e],{val:e,valueIndex:t}})(u,o)),a.pathData[i].values.push(...u)):(t&&u[1]&&"."!==u[1]&&"0"===u[0]&&(n=`${i}. command: Leading zeros not valid: ${u}`,a.log.push(n)),a.pathData[i].values.push(+u)),o++,u="",y=0,x=o>=c)},m=()=>{if(i>0){let e=a.pathData[i].values.length;(e&&e<c||e&&e>c||("z"===p||"Z"===p)&&e>0)&&(n=`${i}. command of type "${p}": ${c-e} values too few - ${c} expected`,a.log[a.log.length-1]!==n&&a.log.push(n))}};let v=!1,M=!1,b=!1,A="";for(;s<r;){A=e.charCodeAt(s);let l=A>47&&A<58;if(l||(v=101===A||69===A,M=45===A||43===A,b=46===A),l||M||b||v){if(h||45!==A&&46!==A)g();else{let e=46===A;d(e),g(),e&&y++}u+=e[s],h=v,s++}else if((A<48||A>5759)&&ue(A))d(),s++;else{if(A>64){if(!re.has(A)){n=`${i}. command "${e[s]}" is not a valid type`,a.log.push(n),s++;continue}""!==u&&(a.pathData[i].values.push(+u),o++,u=""),t&&m(),p=e[s],c=pe[A];let l="M"===p||"m"===p,r=i>0&&("z"===a.pathData[i].type||"Z"===a.pathData[i].type);f.add(p),r&&!l&&(a.pathData.push({type:"m",values:[0,0]}),i++),a.pathData.push({type:p,values:[]}),i++,y=0,o=0,x=!1,s++;continue}l||(n=`${i}. ${e[s]} is not a valid separarator or token`,a.log.push(n),u=""),s++}}d(),t&&m(),t&&a.log.length&&(n="Invalid path data:\n"+a.log.join("\n"),"log"===t||console.warn(n)),a.pathData[0].type="M";let C=Array.from(f).join("");return a.hasRelatives=/[lcqamtsvh]/g.test(C),a.hasShorthands=/[vhst]/gi.test(C),a.hasArcs=/[a]/gi.test(C),a.hasQuadratics=/[qt]/gi.test(C),a.isPolygon=!/[cqats]/gi.test(C),a}(e),{hasRelatives:u=!0,hasShorthands:h=!0,hasQuadratics:y=!0,hasArcs:o=!0}=i,c=p?i:i.pathData;return c=function(e=[],{toAbsolute:t=!0,toLonghands:l=!0,quadraticToCubic:a=!1,arcToCubic:n=!1,arcAccuracy:s=2,hasRelatives:r=!0,hasShorthands:p=!0,hasQuadratics:i=!0,hasArcs:u=!0,testTypes:h=!1}={}){return he(e,{toAbsolute:t,toLonghands:l,quadraticToCubic:a,arcToCubic:n,arcAccuracy:s,hasRelatives:r,hasShorthands:p,hasQuadratics:i,hasArcs:u,testTypes:h,decimals:-1})}(c,{toAbsolute:t,toLonghands:l,quadraticToCubic:a,arcToCubic:n,arcAccuracy:s,hasRelatives:u,hasShorthands:h,hasQuadratics:y,hasArcs:o}),c}function oe(e={},t={},l={},a={},n=1){let s=E(e,t,1.5),r=E(a,l,1.5),p=.01*O(e,a)*n,i=O(s,r),u=null,h={type:"C",values:[t.x,t.y,l.x,l.y,a.x,a.y]};return i<p&&(u=w(e,t,a,l,!1,!0),u&&(h.type="Q",h.values=[u.x,u.y,a.x,a.y],h.p0=e,h.cp1=u,h.cp2=null,h.p=a)),h}function ce(e,t){Array.isArray(e)&&(e={x:e[0],y:e[1]});let l={x:e.x+2/3*(t[0]-e.x),y:e.y+2/3*(t[1]-e.y)},a={x:t[2]+2/3*(t[0]-t[2]),y:t[3]+2/3*(t[1]-t[3])};return{type:"C",values:[l.x,l.y,a.x,a.y,t[2],t[3]]}}function xe(e,t=!1,l=-1){l>=0&&(e[0].values=e[0].values.map(e=>+e.toFixed(l)));let a=e.length,n=e[0].values,s=n[0],r=n[1],p=s,i=r;for(let n=1;n<a;n++){let a=e[n],{type:u,values:h}=a,y=h.length,o=u.toLowerCase(),c=u.toUpperCase(),x=t?o:c;if(u!==x)switch(a.type=x,o){case"a":h[5]=t?h[5]-s:h[5]+s,h[6]=t?h[6]-r:h[6]+r;break;case"v":h[0]=t?h[0]-r:h[0]+r;break;case"h":h[0]=t?h[0]-s:h[0]+s;break;case"m":t?(h[0]-=s,h[1]-=r):(h[0]+=s,h[1]+=r),p=t?h[0]+s:h[0],i=t?h[1]+r:h[1];break;default:if(h.length)for(let e=0;e<h.length;e++)h[e]=t?h[e]-(e%2?r:s):h[e]+(e%2?r:s)}switch(o){case"z":s=p,r=i;break;case"h":s=t?s+h[0]:h[0];break;case"v":r=t?r+h[0]:h[0];break;case"m":p=h[y-2]+(t?s:0),i=h[y-1]+(t?r:0);default:s=h[y-2]+(t?s:0),r=h[y-1]+(t?r:0)}l>=0&&(a.values=a.values.map(e=>+e.toFixed(l)))}return e}function fe(e,t=-1){return xe(e,!1,t)}function ge({p0:e={x:0,y:0},p:t={x:0,y:0},centroid:l={x:0,y:0},rx:a=0,ry:n=0,xAxisRotation:s=0,radToDegree:r=!1,startAngle:p=null,endAngle:i=null,deltaAngle:u=null}={}){if(!a||!n)return[];let h=[];const y=1.5707963267948966;let o=r?s:s*Math.PI/180,c=Math.cos(o),x=Math.sin(o);null!==p&&null!==i&&null!==u||({startAngle:p,endAngle:i,deltaAngle:u}=S(l,e,t));let f=a!==n?D(p,a,n):p,g=a!==n?D(u,a,n):u,d=Math.max(1,Math.ceil(Math.abs(g)/y)),m=g/d;for(let e=0;e<d;e++){const e=Math.abs(m)===y?.551785*Math.sign(m):4/3*Math.tan(m/4);let t=Math.cos(f),s=Math.sin(f),r=Math.cos(f+m),p=Math.sin(f+m),i=[];[{x:t-s*e,y:s+t*e},{x:r+p*e,y:p-r*e},{x:r,y:p}].forEach(e=>{let t=e.x*a,s=e.y*n;i.push(c*t-x*s+l.x,x*t+c*s+l.y)}),h.push({type:"C",values:i,cp1:{x:i[0],y:i[1]},cp2:{x:i[2],y:i[3]},p:{x:i[4],y:i[5]}}),f+=m}return h}function de(e,t,l=1){const a=2*Math.PI;let[n,s,r,p,i,u,h]=t;if(0===n||0===s)return[];let y=r?r*a/360:0,o=y?Math.sin(y):0,c=y?Math.cos(y):1,x=c*(e.x-u)/2+o*(e.y-h)/2,f=-o*(e.x-u)/2+c*(e.y-h)/2;if(0===x&&0===f)return[];n=Math.abs(n),s=Math.abs(s);let g=x*x/(n*n)+f*f/(s*s);if(g>1){let e=Math.sqrt(g);n*=e,s*=e}let d=n*n,m=n===s?d:s*s,v=x*x,M=f*f,b=d*m-d*M-m*v;b<=0?b=0:(b/=d*M+m*v,b=Math.sqrt(b)*(p===i?-1:1));let A=b?b*n/s*f:0,C=b?b*-s/n*x:0,S=c*A-o*C+(e.x+u)/2,w=o*A+c*C+(e.y+h)/2,E=(x-A)/n,L=(f-C)/s,P=(-x-A)/n,T=(-f-C)/s;const I=(e,t,l,a)=>{let n=+(e*l+t*a).toFixed(9);return 1===n||-1===n?1===n?0:Math.PI:(n=n>1?1:n<-1?-1:n,(e*a-t*l<0?-1:1)*Math.acos(n))};let D=I(1,0,E,L),k=I(E,L,P,T);0===i&&k>0?k-=2*Math.PI:1===i&&k<0&&(k+=2*Math.PI);let q=(+(Math.abs(k)/(a/4)).toFixed(0)||1)*l;k/=q;let Q=[];const z=1.5707963267948966,$=.551785;let F=k===z?$:k===-z?-$:4/3*Math.tan(k/4),j=k?Math.cos(k):1,B=k?Math.sin(k):0;const R=(e,t,l,a,n)=>{let s=e!=t?Math.cos(e):a,r=e!=t?Math.sin(e):n,p=Math.cos(e+t),i=Math.sin(e+t);return[{x:s-r*l,y:r+s*l},{x:p+i*l,y:i-p*l},{x:p,y:i}]};for(let e=0;e<q;e++){let e={type:"C",values:[]};R(D,k,F,j,B).forEach(t=>{let l=t.x*n,a=t.y*s;e.values.push(c*l-o*a+S,o*l+c*a+w)}),Q.push(e),D+=k}return Q}function me(e,{tolerance:t=1,flatBezierToLinetos:l=!0}={}){let a=[e[0]],n={x:e[0].values[0],y:e[0].values[1]},s=n,r=n;e[e.length-1].type.toLowerCase();for(let p=1,i=e.length;p<i;p++){let u=e[p],h=e[p+1]||e[i-1],y="z"===h.type.toLowerCase()?n:{x:h.values[h.values.length-2],y:h.values[h.values.length-1]},{type:o,values:c}=u,x=c.slice(-2);r="Z"!==o?{x:x[0],y:x[1]}:n;let f=y?Y([s,r,y],!0):1/0,g=R(s,y),d=f<(g?g/333*t:0),m=!1;if(l||"C"!==o||(d=!1),l&&("C"===o||"Q"===o)){m=ne([s,..."C"===o?[{x:c[0],y:c[1]},{x:c[2],y:c[3]}]:"Q"===o?[{x:c[0],y:c[1]}]:[],r],{tolerance:t}),m&&p<i-1&&(o="L",u.type="L",u.values=x)}d&&p<i-1&&"A"!==h.type&&("L"===o||l&&m)||(s=r,"M"===o&&(n=r),a.push(u))}return a}function ve(e){let t={x:e[0].values[0],y:e[0].values[1]},l=t,a=[e[0]];for(let n=1,s=e.length;n<s;n++){let s=e[n],r=e[n-1],p=e[n+1]||null,{type:i,values:u}=s,h="m"===r.type.toLowerCase()&&!p,y=u.length;if(l={x:u[y-2],y:u[y-1]},h||"L"!==i||l.x!==t.x||l.y!==t.y){if(!h&&("l"===i||"v"===i||"h"===i)){if("l"===i?"00"===u.join(""):0===u[0])continue}a.push(s),t=l}}return a}function Me(e){let t=e.length;if(!("z"===e[t-1].type.toLowerCase()))return e;let l=0,a=[];for(let l=0;l<t;l++){let t=e[l],{type:n,values:s}=t,r=s.length;if(r){let e={type:n,x:s[r-2],y:s[r-1],index:0};e.index=l,a.push(e)}}return a=a.sort((e,t)=>+e.y.toFixed(8)-+t.y.toFixed(8)||e.x-t.x),l=a[0].index,l?Ae(e,l):e}function be(e,{removeFinalLineto:t=!0,autoClose:l=!0}={}){let a=e,n=e.length,s={x:+e[0].values[0].toFixed(8),y:+e[0].values[1].toFixed(8)},r="z"===e[n-1].type.toLowerCase(),p=!1,i=r?n-2:n-1,u=e[i],h=u.type,y=u.values.slice(-2).map(e=>+e.toFixed(8)),o=y[0]===s.x&&y[1]===s.y,c="L"===h,x=[];for(let t=0;t<n;t++){let l=e[t],{type:a,values:n,p0:s,p:r}=l;if("L"===a&&(p=!0),n.length){n.slice(-2);let l={type:a,x:Math.min(s.x,r.x),y:Math.min(s.y,r.y),index:0,prevType:(e[t-1]?e[t-1]:e[i]).type};l.index=t,x.push(l)}}let f=1/0,g=1/0,d=null,m=x.length;for(let e=0;e<m;e++){let t=x[e],{type:l,index:a,x:n,y:s,prevType:r}=t;p&&"L"===r&&(n<f&&s<g&&(d=a-1),s<g&&(g=s),n<f&&(f=n))}return d&&(a=Ae(a,d),n=a.length,s={x:+a[0].values[0].toFixed(8),y:+a[0].values[1].toFixed(8)},i=r?n-2:n-1,u=a[i],h=u.type,y=u.values.slice(-2).map(e=>+e.toFixed(8)),c="L"===h,o=y[0]===s.x&&y[1]===s.y),t&&o&&c&&a.splice(n-2,1),l&&!r&&o&&a.push({type:"Z",values:[]}),a}function Ae(e,t){let l=0,a="z"===e[e.length-1].type.toLowerCase();if(!a||t<1||e.length<3)return e;let n=a?1:0;!function(e){let t=e.length,l="z"===e[t-1].type.toLowerCase(),a=e[0],[n,s]=[a.values[0],a.values[1]].map(e=>+e.toFixed(8)),r=l?e[t-2]:e[t-1],p=r.values.length,[i,u]=[r.values[p-2],r.values[p-1]].map(e=>+e.toFixed(8));!l||n==i&&s==u||(e.pop(),e.push({type:"L",values:[n,s]},{type:"Z",values:[]}))}(e),l=t+1<e.length-1?t+1:e.length-1-n;let s,r,p=e.slice(l),i=e.slice(0,l);return i.shift(),s=i[i.length-1].values||[],r=[s[s.length-2],s[s.length-1]],n&&(p.pop(),i.push({type:"Z",values:[]})),e=[{type:"M",values:r},...p,...i]}function Ce(e,{threshold:t=null,tolerance:l=1}={}){if(!t){let l=function(e){let t=1/0,l=-1/0,a=1/0,n=-1/0;const s=e=>{e.x<t&&(t=e.x),e.x>l&&(l=e.x),e.y<a&&(a=e.y),e.y>n&&(n=e.y)};for(let t=0;t<e.length;t++){let l=e[t],{type:a,values:n}=l,r=n.length,p=(e[t-1]?e[t-1]:e[t]).values,i=p.length;if(r){let e={x:p[i-2],y:p[i-1]},t={x:n[r-2],y:n[r-1]};if(s(t),"C"===a||"Q"===a){let l={x:n[0],y:n[1]},r="C"===a?{x:n[2],y:n[3]}:l,p="C"===a?[e,l,r,t]:[e,l,t];q(p).forEach(e=>{let t=L(p,e);s(t)})}else"A"===a&&Q(e,n).forEach(e=>{s(e)})}}return{x:t,y:a,width:l-t,height:n-a}}(e);t=.05*(l.width+l.height)}let a=e.length;for(let n=0;n<a;n++){let a=e[n],{type:s,values:r,extreme:p,corner:i=!1,dimA:u,p0:h,p:y}=a,o=e[n+1]?e[n+1]:null,c=e[n+2]?e[n+2]:null,x=(o?O(y,o.p):1/0)<t,f=(c?O(c.p,o.p):1/0)<1*t;if(o&&c&&"C"===s&&"C"===o.type&&p&&c.extreme&&(f||x)){let a=te(o,c,t,l,!1);if(1===a.length){a=a[0],e[n+1]=null,e[n+2].values=[a.cp1.x,a.cp1.y,a.cp2.x,a.cp2.y,a.p.x,a.p.y],e[n+2].cp1=a.cp1,e[n+2].cp2=a.cp2,e[n+2].p0=a.p0,e[n+2].p=a.p,e[n+2].extreme=a.extreme,n++;continue}}if(o&&"C"===s&&"C"===o.type&&p&&x){let e=Y([a.p0,a.p,o.p]),t=Y([a.p0,a.cp1,a.cp2,a.p]);if(e<0&&t>0||e>0&&t<0)continue}}a=(e=e.filter(Boolean)).length;let n="z"===e[a-1].type.toLowerCase()?a-2:a-1,s=e[n],r=e[n-1]||null,p={x:e[0].values[0],y:e[0].values[1]},i=s.values.slice(-2),u=+i[0].toFixed(8)===+p.x.toFixed(8)&&+i[1].toFixed(8)===+p.y.toFixed(8),h="C"===e[1].type&&e[1].extreme?e[1]:null,y=O(s.p0,s.p)<t;if(r&&"C"===r.type&&y&&u&&h){let a=te(r,s,t,l,!1);1===a.length&&(e[n-1]=a[0],e[n]=null,e=e.filter(Boolean))}return e}function Se(e,t=!1){if(e.length<3)return!1;let l=e.length,a=Math.floor(.333*l),n=Math.floor(.666*l),s=Math.floor(.5*l),r=e[0],p=e[s],i=e[l-1],u=we([r,p,i]),h=0,y=0,o=0,c=0,x={};if(t){if(l>3){let t=we([r,e[a],i]),l=we([r,e[n],i]);if(!t||!l)return!1;let s=O(u,p);if(O(u,t)+O(u,l)>.05*s)return!1}let t=R(u,p);for(let a=0;a<l;a++){let l=R(u,e[a]);if(Math.abs(t-l)/t>.0025)return!1}h=Math.sqrt(t),x=S(u,r,i),({deltaAngle:y,startAngle:o,endAngle:c}=x)}else h=B(u,r),x=S(u,r,i),({deltaAngle:y,startAngle:o,endAngle:c}=x);return{centroid:u,r:h,startAngle:o,endAngle:c,deltaAngle:y}}function we(e=[]){if((e=e.filter(e=>void 0!==e)).length<3)return!1;let t=e[0],l=e[Math.floor(e.length/2)],a=e[e.length-1],n=t.x,s=t.y,r=l.x,p=l.y,i=a.x,u=a.y,h=n-r,y=s-p,o=n-i,c=s-u,x=(n*n-r*r+(s*s-p*p))/2,f=(n*n-i*i+(s*s-u*u))/2,g=h*c-y*o;return!(Math.abs(g)<1e-10)&&{x:(c*x-y*f)/g,y:(-o*x+h*f)/g}}function Ee(e,{threshold:t=0,simplifyQuadraticCorners:l=!1,tolerance:a=1}={}){let n=e.length,s=[e[0]],r="z"===e[n-1].type.toLowerCase(),p=!!r&&(e[n-1].p.x===e[0].p0.x&&e[n-1].p.y===e[0].p0.y),i=r?2:1,u=e[n-i],h="L"===u.type,y="C"===u.type,o="L"===e[1].type,c="C"===e[1].type,x=null,f=r&&c&&(h||p);f&&(e[n-1].values=e[0].values,e[n-1].type="L",h=!0);for(let t=1;t<n;t++){let p=e[t],{type:u}=p,g=e[t+1]?e[t+1]:null;if("L"===u&&g&&"C"===g.type||"C"===u&&g&&"L"===g.type){let f="L"===u?p:null,d=null,m=[],v=0;if(1===t&&c&&h&&(m=[e[1]],f=e[n-1],d=g),!f){s.push(p);continue}r&&y&&o&&t===n-i-1&&(d=e[1],m=[e[n-i]]);for(let l=t+1;l<n;l++){let t=e[l]?e[l]:null,a=e[l-1];if("C"===a.type&&l>2&&m.push(a),"L"===t.type&&"C"===a.type){d=t;break}v++}if(d){let e=O(f.p0,f.p),r=O(d.p0,d.p),u=O(f.p,d.p0),h=Y([f.p0,f.p,d.p0,d.p],!1),y=Y([m[0].p0,m[0].cp1,m[0].cp2,m[0].p],!1),o=h<0&&y>0||h>0&&y<0,c=.5*u*a,g=c<e&&c<r;if(m.length&&!o&&g){let e=!1;if(1===m.length){let t=Math.abs(m[0].p.x-m[0].p0.x),l=t-Math.abs(m[0].p.y-m[0].p0.y);e=Math.abs(l/t)<.01}let a=!0;if(a=!1,a&&e){let e=L([m[0].p0,m[0].cp1,m[0].cp2,m[0].p],.5),l=Se([m[0].p0,e,m[0].p]),{r:a,centroid:n,deltaAngle:r}=l,p={type:"A",values:[a,a,0,0,r>0?1:0,m[0].p.x,m[0].p.y]};s.push(f,p),t+=v;continue}let r=.005*R(m[0].p0,m[0].p),h=Math.abs(y)<r,o=Math.abs(y)<10*r,g=h?null:w(f.p0,f.p,d.p,d.p0,!1,!0);if(!g||o&&1===m.length){s.push(p);continue}if(g){let e=Y([f.p0,f.p,d.p0,d.p],!1),t=Math.abs(e),l=Y([f.p0,f.p,g,d.p0,d.p],!1),a=Math.abs(l),n=Math.abs(t-a)/t;if(!g||(e<0&&l>0||e>0&&l<0)||n>.5){s.push(p);continue}}let M=.75*O(L([f.p,g,d.p0],.5),1===m.length?L([m[0].p0,m[0].cp1,m[0].cp2,m[0].p],.5):m[0].p);if(c&&M>c&&M>.3*u){s.push(p);continue}let b=d.p0;if(!l){let l=.1666,a=E(g,f.p,1+l);b=E(g,d.p0,1+l);let s=g.y===f.p.y,r=g.x===f.p.x,u=g.y===d.p0.y,h=g.x===d.p0.x;if(e&&p.dimA>3){let e=.5;s&&(a.x=K(a.x,e)),r&&(a.y=K(a.y,e)),u&&(b.x=K(b.x,e)),h&&(b.y=K(b.y,e))}t===n-i-1&&(x=b),f.values=[a.x,a.y],f.p=a}let A={type:"Q",values:[g.x,g.y,b.x,b.y]};A.cp1=g,A.p0=f.p,A.p=b,s.push(f,A),t+=v;continue}}}f&&t===n-1&&"L"===u||s.push(p)}return x&&(s[0].values=[x.x,x.y],s[0].p0=x),(f||r&&"Z"!==s[s.length-1].type)&&s.push({type:"Z",values:[]}),s}function Le(e=[],{threshold:t=0}={}){let l=e.length,a="z"===e[l-1].type.toLowerCase(),n=a?l-2:l-1,s=e[n],r=s.values.slice(-2),p={x:e[0].values[0],y:e[0].values[1]},i=N(p,{x:r[0],y:r[1]});if(i&&i<t){let l=e[n].values.length;e[n].values[l-2]=p.x,e[n].values[l-1]=p.y;let a=e[1];if("C"===a.type&&"C"===s.type){let l=Math.abs(a.values[0]-s.values[2]),r=Math.abs(a.values[1]-s.values[3]),i=Math.abs(e[1].values[0]-a.values[0]),u=Math.abs(e[1].values[1]-a.values[1]),h=Math.abs(e[1].values[0]-s.values[2]),y=Math.abs(e[1].values[1]-s.values[3]),o=u<t&&y<t&&l;l&&l<t&&(i<t&&h<t&&r)&&(e[1].values[0]=p.x,e[n].values[2]=p.x),r&&r<t&&o&&(e[1].values[1]=p.y,e[n].values[3]=p.y)}}return e}function Pe(e,t=1){for(let l=1,a=e.length;l<a;l++){let a=e[l],{type:n,values:s,p0:r,cp1:p=null,cp2:i=null,p:u=null}=a;if("C"===n){let n=oe(r,p,i,u,t);"Q"===n.type&&(n.extreme=a.extreme,n.corner=a.corner,n.dimA=a.dimA,n.squareDist=a.squareDist,e[l]=n)}}return e}function Te(e){for(let t=1,l=e.length;t<l;t++){let l=e[t],{type:a,values:n,p0:s,cp1:r=null,cp2:p=null,p:i=null}=l;if("L"===a){let l=E(s,i,.333),a=E(i,s,.333);e[t].type="C",e[t].values=[l.x,l.y,a.x,a.y,i.x,i.y],e[t].cp1=l,e[t].cp2=a}}return e}function Ie(e,{threshold:t=0,tolerance:l=1,toCubic:a=!1,debug:n=!1}={}){let s=e.length,r=[e[0]];for(let t=1;t<s;t++){let l=e[t],{type:n}=l,s=e[t-1],p=e[t+1]?e[t+1]:null,i=e[t+2]?e[t+2]:null,u=e[t+3]?e[t+3]:null,h=null;"C"===l.type||"Q"===l.type?h=l:!p||"C"!==p.type&&"Q"!==p.type||(h=p);let y,o,c,x,f,g=h?"C"===h.type?[h.p0,h.cp1,h.cp2,h.p]:[h.p0,h.cp1,h.p]:[],d=0,m=0,v=!1,M=!1,b=[];if(i&&u&&"L"===s.type&&"L"===n&&h&&"L"===i.type&&("L"===u.type||"Z"===u.type)?(y=[l.p0,l.p],o=[i.p0,i.p],c=l.p0,x=i.p,d=Y(g,!1),m=Y([...y,...o],!1),v=d<0&&m>0||d>0&&m<0,v||(f=L(g,.5),b=[c,f,x],M=!0)):!p||"C"!==n&&"Q"!==n||"L"!==s.type||!i||"L"!==i.type||"C"!==p.type&&"Q"!==p.type||(M=!0,y=[s.p0,s.p],o=[i.p0,i.p],c=s.p,x=i.p0,f=h.p,b=[c,h.p,x]),M){let e=Se(b);if(e){let n,{centroid:s,r:p,deltaAngle:i,startAngle:u,endAngle:h}=e,y=0,o=i>0?1:0,g=Math.abs(i)>Math.PI?1:0;if(N(T(c,s.x,s.y,.5*i),f)<.05*N(c,x)){if(n=ge({p0:c,p:x,centroid:s,rx:p,ry:p,xAxisRotation:y,sweep:o,largeArc:g,deltaAngle:i,startAngle:u,endAngle:h}),1===n.length){let e=oe(c,n[0].cp1,n[0].cp2,x);"Q"===e.type?a=!0:e=n[0],l=e}n.length>1&&(a=!1),a||(l.type="A",l.values=[p,p,y,g,o,x.x,x.y]),l.p0=c,l.p=x,l.extreme=!1,l.corner=!1,r.push(l),t++;continue}}}r.push(l)}return r}function De(e="",{toAbsolute:t=!0,toRelative:a=!0,toShorthands:n=!0,quadraticToCubic:s=!0,arcToCubic:r=!1,cubicToArc:p=!1,simplifyBezier:i=!0,optimizeOrder:u=!0,autoClose:h=!0,removeZeroLength:y=!0,refineClosing:o=!0,removeColinear:c=!0,flatBezierToLinetos:x=!0,revertToQuadratics:f=!0,refineExtremes:g=!0,simplifyCorners:d=!1,fixDirections:m=!1,keepExtremes:v=!0,keepCorners:M=!0,keepInflections:b=!1,addExtremes:A=!1,addSemiExtremes:C=!1,harmonizeCpts:S=!1,toPolygon:w=!1,removeOrphanSubpaths:E=!1,simplifyRound:L=!1,decimals:P=3,autoAccuracy:T=!0,minifyD:I=0,tolerance:D=1,lineToCubic:k=!1,getObject:q=!1}={}){D=Math.max(.1,D);let Q="",z={x:0,y:0,width:0,height:0},$=[],F=[],j=function(e){let t="",a=!0,n={inputType:"",isValid:!0,fileReport:{}};if(Array.isArray(e))return n.inputType="array",Array.isArray(e[0])?2===e[0].length?n.inputType="polyArray":Array.isArray(e[0][0])&&2===e[0][0].length?n.inputType="polyComplexArray":void 0!==e[0][0].x&&void 0!==e[0][0].y&&(n.inputType="polyComplexObjectArray"):void 0!==e[0].x&&void 0!==e[0].y?n.inputType="polyObjectArray":e[0]?.type&&e[0]?.values&&(n.inputType="pathData"),n;if("string"==typeof e){let s=(e=e.trim()).includes("<svg")&&e.includes("</svg"),r=e.startsWith("<symbol")&&e.includes("</symbol"),p=e.startsWith("M")||e.startsWith("m"),i=!isNaN(e.substring(0,1))&&!isNaN(e.substring(e.length-1,e.length)),u=function(e){e=e.trim();let t=/\d/.test(e),l=/[abcdfghijklmnopqrstuvwz]/gi.test(e);return!(!t||l)&&(e.startsWith("[")&&e.endsWith("]"))}(e);if(s){let s=l(e);({isValid:a,log:t}=s),a?n.inputType="svgMarkup":(n.inputType="invalid",n.isValid=!1,n.log=t),n.fileReport=s.fileReport}else if(u)n.inputType="json";else if(r)n.inputType="symbol";else if(p)n.inputType="pathDataString";else if(i)n.inputType="polyString";else{let t=/^(file:|https?:\/\/|\/|\.\/|\.\.\/)/.test(e),l=e.startsWith("data:image");n.inputType=t||l?"url":"string"}return n}return n.inputType=(e.constructor.name||typeof e).toLowerCase(),n}(e),{inputType:B,log:R}=j;if("pathDataString"===B)Q=e;else if("polyString"===B)Q="M"+e;else{if("pathData"!==B)return!1;Q=e}let N={toRelative:a,toShorthands:n,decimals:P},W=ye(Q,{quadraticToCubic:s,toAbsolute:t,arcToCubic:r});W.length,E&&(W=function(e){let t=[];for(let l=0,a=e.length;l<a;l++){let a=e[l];if(!a)continue;let{type:n=null,values:s=[]}=a,r=e[l+1]?e[l+1]:null;"M"!==n&&"m"!==n||r&&(!r||"Z"!==r.type&&"z"!==r.type)?t.push(a):r&&l++}return t}(W));let J=Z(W),H=J.length,K=[];for(let e=0;e<H;e++){let t=J[e];(c||y)&&(t=ve(t)),u&&(t=Me(t)),c&&(t=me(t,{tolerance:D,flatBezierToLinetos:!1})),(A||C)&&(t=V(t,{tMin:tMin,tMax:tMax,addExtremes:A,addSemiExtremes:C,angles:[30]}));let l=se(t,{detectSemiExtremes:C}),{pathData:a,bb:n,dimA:s}=l;if($.push(n.x,n.x+n.width),F.push(n.y,n.y+n.height),o&&(a=Le(a,{threshold:.001*s})),a=i?le(a,{simplifyBezier:i,keepInflections:b,keepExtremes:v,keepCorners:M,revertToQuadratics:f,tolerance:D}):a,g){a=Ce(a,{threshold:.05*(n.width+n.height),tolerance:D})}if(c&&x&&(a=me(a,{tolerance:D,flatBezierToLinetos:x})),d){a=Ee(a,{threshold:.1*(n.width+n.height),tolerance:D})}L&&(a=Ie(a)),f&&(a=Pe(a,D)),k&&(a=Te(a)),u&&(a=be(a,{autoClose:h})),K.push({pathData:a,bb:n})}let _=Math.min(...$),G=Math.min(...F);z={x:_,y:G,width:Math.max(...$)-_,height:Math.max(...F)-G},u&&(K=z.height>z.width?K.sort((e,t)=>e.bb.y-t.bb.y||e.bb.x-t.bb.x):K.sort((e,t)=>e.bb.x-t.bb.x||e.bb.y-t.bb.y)),W=[],K.forEach(e=>{W.push(...e.pathData)}),T&&(P=function(e){let t=[];for(let l=1,a=e.length;l<a;l++){let a=e[l],{type:n,values:s,p0:r=null,p:p=null,dimA:i=0}=a;s.length&&p&&r&&(i=i||O(r,p),i&&t.push(i))}let l=t.sort(),a=Math.ceil(l.length/6);l=l.slice(0,a);let n=l.reduce((e,t)=>e+t,0)/a,s=n>112.5?0:Math.floor(75/n).toString().length;return Math.min(Math.max(0,s),8)}(W),N.decimals=P),W=he(W,N),W=ve(W);let U=ee(W,I);return q&&(W=W.map(e=>({type:e.type,values:e.values}))),q?W:U}"undefined"!=typeof window&&(window.simplifyPathData=De);export{De as simplifyPathData};
3
+ if(S){let e="C"===a?Math.abs(l.cp2.x-l.p.x):Math.abs(l.cp1.x-l.p.x),t="C"===a?Math.abs(l.cp2.y-l.p.y):Math.abs(l.cp1.y-l.p.y);if(((0===t||t<=A)&&e>0||(0===e||e<=A)&&t>0)&&(L=!0),(i.x===r.x&&i.y!==r.y||i.y===r.y&&i.x!==r.x)&&(m[m.length-1].extreme=!0),p.x!==o&&p.y!==x&&p.x!==c&&p.y!==f||(L=!0),!L){if(k(null,M)){let e=z(M);e.length&&e[0]>.2&&(L=!0)}}}else if(w&&v&&("C"===d.type||"Q"===d.type||"C"===v.type||"Q"===v.type)){let e=v?v.dimA:0,t=l.dimA<.1*(d.dimA+e),a=l.values[0]===l.values[1]&&l.values[0]<1;if(t&&a){let e=_([d.p0,v.p]);(p.x>e.right||p.x<e.x||p.y<e.y||p.y>e.bottom)&&(L=!0)}}if(L&&(l.extreme=!0),S&&E){if(s&&!l.extreme){let e=Math.abs(p.x-u.x),t=Math.abs(p.y-u.y),a=!1;if(e&&t&&e>b||t>b){let e=C(u,p),t=C(p,v.cp1);a=j(Math.abs(e+t)/2)}a&&(l.semiExtreme=!0)}if((l.cptArea<0&&v.cptArea>0||l.cptArea>0&&v.cptArea<0)&&(l.directionChange=!0),!l.extreme){let e=u||i,t=v.cp1,a=Y([e,p,t],!1),n=.01*R(e,t),s=Math.abs(a)<n,r=a<0&&l.cptArea>0||a>0&&l.cptArea<0;!s&&r&&(l.corner=!0)}}m.push(l)}return r&&m.forEach(e=>{e.directionChange&&a(markers,e.p,"orange","1.5%","0.5"),e.corner&&a(markers,e.p,"magenta","1.5%","0.5"),e.extreme&&a(markers,e.p,"cyan","1%","0.5")}),u={pathData:m,bb:y,dimA:(g+d)/2},u}const re=new Set([77,109,65,97,67,99,76,108,81,113,83,115,84,116,72,104,86,118,90,122]),pe=new Uint8Array(128);pe[77]=2,pe[109]=2,pe[65]=7,pe[97]=7,pe[67]=6,pe[99]=6,pe[76]=2,pe[108]=2,pe[81]=4,pe[113]=4,pe[83]=4,pe[115]=4,pe[84]=2,pe[116]=2,pe[72]=1,pe[104]=1,pe[86]=1,pe[118]=1,pe[90]=0,pe[122]=0;const ie=new Set([5760,6158,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288,65279]),ue=e=>32===e||44===e||10===e||13===e||8232===e||8233===e||9===e||11===e||12===e||160===e||e>=5760&&ie.has(e);function he(e,{toShorthands:t=!0,toLonghands:l=!1,toRelative:a=!0,toMixed:n=!1,toAbsolute:s=!1,decimals:r=3,arcToCubic:p=!1,quadraticToCubic:i=!1,hasRelatives:u=!0,hasShorthands:h=!0,hasQuadratics:y=!0,hasArcs:o=!0,isPoly:c=!1,optimizeArcs:x=!0,testTypes:f=!1}={}){let g=[];if(f){let t=Array.from(new Set(e.map(e=>e.type))).join("");/[lcqamts]/gi.test(t),y=/[qt]/gi.test(t),o=/[a]/gi.test(t),h=/[vhst]/gi.test(t),/[mlz]/gi.test(t)}if(a=!s&&a,t=!l&&t,s&&(e=fe(e)),h&&l&&(e=function(e,t=-1,l=!0){let a=!1;if(l){let t=e.map(e=>e.type).join(""),l=/[hstv]/gi.test(t);if(a=/[astvqmhlc]/g.test(t),!l)return e}e=l&&a?fe(e,t):e;let n=[],s={type:"M",values:e[0].values};n.push(s);for(let l=1,a=e.length;l<a;l++){let a,r,p,i,u,h,y,o,c=e[l],{type:x,values:f}=c,g=f.length,d=s.values,m=d.length,[v,M]=[f[g-2],f[g-1]],[b,A]=[d[m-2],d[m-1]];switch(x){case"H":s={type:"L",values:[f[0],A]};break;case"V":s={type:"L",values:[b,f[0]]};break;case"T":[a,r]=[d[0],d[1]],[b,A]=[d[m-2],d[m-1]],p=b+(b-a),i=A+(A-r),s={type:"Q",values:[p,i,v,M]};break;case"S":[a,r]=[d[0],d[1]],[b,A]=[d[m-2],d[m-1]],[y,o]=m>2&&"A"!==s.type?[d[2],d[3]]:[b,A],p=2*b-y,i=2*A-o,u=f[0],h=f[1],s={type:"C",values:[p,i,u,h,v,M]};break;default:s={type:x,values:f}}t>-1&&(s.values=s.values.map(e=>+e.toFixed(t))),n.push(s)}return n}(e)),x&&(e=function(e=[]){let t=e.length,l=[];for(let a=0;a<t;a++){let t=e[a],{type:n,values:s}=t;if("A"!==n){l.push(t);continue}let[r,p,i,u,h]=[s[0],s[1],s[3],s[5],s[6]],y=e[a-1],[o,c]=[y.values[y.values.length-2],y.values[y.values.length-1]],x={x:o,y:c},f={x:u,y:h};0!==r&&0!==p||(e[a]=null);let g=r/p,d=r!==p?Math.abs(1-g):0;if(d>.01){l.push(t);continue}t.values[2]=0;let m=.001*O(x,f),v=Math.abs(u-o),M=Math.abs(h-c),b=M<m;if(b||v<m){(b?1.9*r>v:1.9*p>M)||(r=r>=1?1:r>.5?.5:r),t.values[0]=r,t.values[1]=r,l.push(t);continue}let A=.5*B(x,f);d=r/A,d<.5&&(r=A>=1?1:A>.5?.5:A),t.values[0]=r,t.values[1]=r,l.push(t)}return l}(e)),t&&(e=function(e,t=-1,l=!1){let a;if(l){let t=e.map(e=>e.type).join("");a=/[astvqmhlc]/g.test(t)}e=l&&a?xe(e):e;let n=e.length,s=new Array(n),r=e[0];s[0]=r;let p={x:e[0].values[0],y:e[0].values[1]},i=p;for(let t=1;t<n;t++){let l=e[t];r=l;let{type:a,values:n}=l,u=n.length,h=[n[u-2],n[u-1]],y=e[t-1];i={x:h[0],y:h[1]};let o=Math.abs(i.x-p.x),c=Math.abs(i.y-p.y),x=.01*O(p,i),f=!1,g=!1,d=!1;if("C"===a&&"C"===y.type||"Q"===a&&"Q"===y.type){let e="C"===y.type?{x:y.values[2],y:y.values[3]}:{x:y.values[0],y:y.values[1]},t={x:n[0],y:n[1]},l=p.x-e.x,a=p.y-e.y;x=.01*O(e,t),f=O({x:e.x+2*l,y:e.y+2*a},t)<x}else"L"===a&&(g=0===c||c<x,d=0===o||o<x,f=d||g);switch(a){case"L":g&&(r={type:"H",values:[n[0]]}),d&&(r={type:"V",values:[n[1]]});break;case"Q":f&&(r={type:"T",values:[i.x,i.y]});break;case"C":f&&(r={type:"S",values:[n[2],n[3],i.x,i.y]});break;default:r={type:a,values:n}}p=i,s[t]=r}return s}(e)),o&&p&&(e=function(e,{arcAccuracy:t=1}={}){let l=[e[0]];for(let a=1,n=e.length;a<n;a++){let n=e[a],s=e[a-1].values,r=s.length,p={x:s[r-2],y:s[r-1]};if("A"===n.type){de(p,n.values,t).forEach(e=>{l.push(e)})}else l.push(n)}return l}(e)),y&&i&&(e=function(e){let t=[e[0]];for(let l=1,a=e.length;l<a;l++){let a=e[l],n=e[l-1].values,s=n.length,r={x:n[s-2],y:n[s-1]};"Q"===a.type?t.push(ce(r,a.values)):t.push(a)}return t}(e)),n&&(a=!0),r>-1&&a&&(e=H(e,r)),n&&(g=JSON.parse(JSON.stringify(e))),a&&(e=function(e,t=-1){return xe(e,!0,t)}(e)),r>-1&&(e=H(e,r)),n)for(let t=0;t<e.length;t++){let l=e[t],a=g[t],n=[l.type,l.values.join(" ")].join("").replaceAll(" -","-").replaceAll(" 0."," ."),s=[a.type,a.values.join(" ")].join("").replaceAll(" -","-").replaceAll(" 0."," ."),r=n.length;s.length<r&&(e[t]=g[t])}return e}function ye(e,{toAbsolute:t=!0,toLonghands:l=!0,quadraticToCubic:a=!1,arcToCubic:n=!1,arcAccuracy:s=4}={}){let r=Array.isArray(e),p=r&&"object"==typeof e[0]&&"function"==typeof e[0].constructor,i=r?e:function(e,t=!0,l=0){if(!e)return[];e=e.trim(),l&&console.log("!!!limit",l);let a={pathData:[],hasRelatives:!1,hasShorthands:!1,hasArcs:!1,hasQuadratics:!1,isPolygon:!1,log:[]};if(""===e)return a;let n,s=0,r=e.length,p="",i=-1,u="",h=!1,y=0,o=0,c=0,x=!1,f=new Set([]);const g=()=>{x&&("M"===p?p="L":"m"===p&&(p="l"),a.pathData.push({type:p,values:[]}),i++,o=0,x=!1)},d=(e=!1)=>{(e?y>0:""!==u)&&(t&&-1===i&&(n="Pathdata must start with M command",a.log.push(n),p="M",a.pathData.push({type:p,values:[]}),c=2,o=0,i++),"A"===p||"a"===p?(({val:u,valueIndex:o}=((e="",t=0)=>{let l=e.length;return 3===t&&2===l?(e=[+e[0],+e[1]],t++):4===t&&l>1?(e=[+e[0],+e.substring(1)],t++):3===t&&l>=3?(e=[+e[0],+e[1],+e.substring(2)],t+=2):e=[+e],{val:e,valueIndex:t}})(u,o)),a.pathData[i].values.push(...u)):(t&&u[1]&&"."!==u[1]&&"0"===u[0]&&(n=`${i}. command: Leading zeros not valid: ${u}`,a.log.push(n)),a.pathData[i].values.push(+u)),o++,u="",y=0,x=o>=c)},m=()=>{if(i>0){let e=a.pathData[i].values.length;(e&&e<c||e&&e>c||("z"===p||"Z"===p)&&e>0)&&(n=`${i}. command of type "${p}": ${c-e} values too few - ${c} expected`,a.log[a.log.length-1]!==n&&a.log.push(n))}};let v=!1,M=!1,b=!1,A="";for(;s<r;){A=e.charCodeAt(s);let l=A>47&&A<58;if(l||(v=101===A||69===A,M=45===A||43===A,b=46===A),l||M||b||v){if(h||45!==A&&46!==A)g();else{let e=46===A;d(e),g(),e&&y++}u+=e[s],h=v,s++}else if((A<48||A>5759)&&ue(A))d(),s++;else{if(A>64){if(!re.has(A)){n=`${i}. command "${e[s]}" is not a valid type`,a.log.push(n),s++;continue}""!==u&&(a.pathData[i].values.push(+u),o++,u=""),t&&m(),p=e[s],c=pe[A];let l="M"===p||"m"===p,r=i>0&&("z"===a.pathData[i].type||"Z"===a.pathData[i].type);f.add(p),r&&!l&&(a.pathData.push({type:"m",values:[0,0]}),i++),a.pathData.push({type:p,values:[]}),i++,y=0,o=0,x=!1,s++;continue}l||(n=`${i}. ${e[s]} is not a valid separarator or token`,a.log.push(n),u=""),s++}}d(),t&&m(),t&&a.log.length&&(n="Invalid path data:\n"+a.log.join("\n"),"log"===t||console.warn(n)),a.pathData[0].type="M";let C=Array.from(f).join("");return a.hasRelatives=/[lcqamtsvh]/g.test(C),a.hasShorthands=/[vhst]/gi.test(C),a.hasArcs=/[a]/gi.test(C),a.hasQuadratics=/[qt]/gi.test(C),a.isPolygon=!/[cqats]/gi.test(C),a}(e),{hasRelatives:u=!0,hasShorthands:h=!0,hasQuadratics:y=!0,hasArcs:o=!0}=i,c=p?i:i.pathData;return c=function(e=[],{toAbsolute:t=!0,toLonghands:l=!0,quadraticToCubic:a=!1,arcToCubic:n=!1,arcAccuracy:s=2,hasRelatives:r=!0,hasShorthands:p=!0,hasQuadratics:i=!0,hasArcs:u=!0,testTypes:h=!1}={}){return he(e,{toAbsolute:t,toLonghands:l,quadraticToCubic:a,arcToCubic:n,arcAccuracy:s,hasRelatives:r,hasShorthands:p,hasQuadratics:i,hasArcs:u,testTypes:h,decimals:-1})}(c,{toAbsolute:t,toLonghands:l,quadraticToCubic:a,arcToCubic:n,arcAccuracy:s,hasRelatives:u,hasShorthands:h,hasQuadratics:y,hasArcs:o}),c}function oe(e={},t={},l={},a={},n=1){let s=E(e,t,1.5),r=E(a,l,1.5),p=.01*O(e,a)*n,i=O(s,r),u=null,h={type:"C",values:[t.x,t.y,l.x,l.y,a.x,a.y]};return i<p&&(u=w(e,t,a,l,!1,!0),u&&(h.type="Q",h.values=[u.x,u.y,a.x,a.y],h.p0=e,h.cp1=u,h.cp2=null,h.p=a)),h}function ce(e,t){Array.isArray(e)&&(e={x:e[0],y:e[1]});let l={x:e.x+2/3*(t[0]-e.x),y:e.y+2/3*(t[1]-e.y)},a={x:t[2]+2/3*(t[0]-t[2]),y:t[3]+2/3*(t[1]-t[3])};return{type:"C",values:[l.x,l.y,a.x,a.y,t[2],t[3]]}}function xe(e,t=!1,l=-1){l>=0&&(e[0].values=e[0].values.map(e=>+e.toFixed(l)));let a=e.length,n=e[0].values,s=n[0],r=n[1],p=s,i=r;for(let n=1;n<a;n++){let a=e[n],{type:u,values:h}=a,y=h.length,o=u.toLowerCase(),c=u.toUpperCase(),x=t?o:c;if(u!==x)switch(a.type=x,o){case"a":h[5]=t?h[5]-s:h[5]+s,h[6]=t?h[6]-r:h[6]+r;break;case"v":h[0]=t?h[0]-r:h[0]+r;break;case"h":h[0]=t?h[0]-s:h[0]+s;break;case"m":t?(h[0]-=s,h[1]-=r):(h[0]+=s,h[1]+=r),p=t?h[0]+s:h[0],i=t?h[1]+r:h[1];break;default:if(h.length)for(let e=0;e<h.length;e++)h[e]=t?h[e]-(e%2?r:s):h[e]+(e%2?r:s)}switch(o){case"z":s=p,r=i;break;case"h":s=t?s+h[0]:h[0];break;case"v":r=t?r+h[0]:h[0];break;case"m":p=h[y-2]+(t?s:0),i=h[y-1]+(t?r:0);default:s=h[y-2]+(t?s:0),r=h[y-1]+(t?r:0)}l>=0&&(a.values=a.values.map(e=>+e.toFixed(l)))}return e}function fe(e,t=-1){return xe(e,!1,t)}function ge({p0:e={x:0,y:0},p:t={x:0,y:0},centroid:l={x:0,y:0},rx:a=0,ry:n=0,xAxisRotation:s=0,radToDegree:r=!1,startAngle:p=null,endAngle:i=null,deltaAngle:u=null}={}){if(!a||!n)return[];let h=[];const y=1.5707963267948966;let o=r?s:s*Math.PI/180,c=Math.cos(o),x=Math.sin(o);null!==p&&null!==i&&null!==u||({startAngle:p,endAngle:i,deltaAngle:u}=S(l,e,t));let f=a!==n?D(p,a,n):p,g=a!==n?D(u,a,n):u,d=Math.max(1,Math.ceil(Math.abs(g)/y)),m=g/d;for(let e=0;e<d;e++){const e=Math.abs(m)===y?.551785*Math.sign(m):4/3*Math.tan(m/4);let t=Math.cos(f),s=Math.sin(f),r=Math.cos(f+m),p=Math.sin(f+m),i=[];[{x:t-s*e,y:s+t*e},{x:r+p*e,y:p-r*e},{x:r,y:p}].forEach(e=>{let t=e.x*a,s=e.y*n;i.push(c*t-x*s+l.x,x*t+c*s+l.y)}),h.push({type:"C",values:i,cp1:{x:i[0],y:i[1]},cp2:{x:i[2],y:i[3]},p:{x:i[4],y:i[5]}}),f+=m}return h}function de(e,t,l=1){const a=2*Math.PI;let[n,s,r,p,i,u,h]=t;if(0===n||0===s)return[];let y=r?r*a/360:0,o=y?Math.sin(y):0,c=y?Math.cos(y):1,x=c*(e.x-u)/2+o*(e.y-h)/2,f=-o*(e.x-u)/2+c*(e.y-h)/2;if(0===x&&0===f)return[];n=Math.abs(n),s=Math.abs(s);let g=x*x/(n*n)+f*f/(s*s);if(g>1){let e=Math.sqrt(g);n*=e,s*=e}let d=n*n,m=n===s?d:s*s,v=x*x,M=f*f,b=d*m-d*M-m*v;b<=0?b=0:(b/=d*M+m*v,b=Math.sqrt(b)*(p===i?-1:1));let A=b?b*n/s*f:0,C=b?b*-s/n*x:0,S=c*A-o*C+(e.x+u)/2,w=o*A+c*C+(e.y+h)/2,E=(x-A)/n,L=(f-C)/s,P=(-x-A)/n,T=(-f-C)/s;const I=(e,t,l,a)=>{let n=+(e*l+t*a).toFixed(9);return 1===n||-1===n?1===n?0:Math.PI:(n=n>1?1:n<-1?-1:n,(e*a-t*l<0?-1:1)*Math.acos(n))};let D=I(1,0,E,L),k=I(E,L,P,T);0===i&&k>0?k-=2*Math.PI:1===i&&k<0&&(k+=2*Math.PI);let q=(+(Math.abs(k)/(a/4)).toFixed(0)||1)*l;k/=q;let Q=[];const z=1.5707963267948966,$=.551785;let F=k===z?$:k===-z?-$:4/3*Math.tan(k/4),j=k?Math.cos(k):1,B=k?Math.sin(k):0;const R=(e,t,l,a,n)=>{let s=e!=t?Math.cos(e):a,r=e!=t?Math.sin(e):n,p=Math.cos(e+t),i=Math.sin(e+t);return[{x:s-r*l,y:r+s*l},{x:p+i*l,y:i-p*l},{x:p,y:i}]};for(let e=0;e<q;e++){let e={type:"C",values:[]};R(D,k,F,j,B).forEach(t=>{let l=t.x*n,a=t.y*s;e.values.push(c*l-o*a+S,o*l+c*a+w)}),Q.push(e),D+=k}return Q}function me(e,{tolerance:t=1,flatBezierToLinetos:l=!0}={}){let a=[e[0]],n={x:e[0].values[0],y:e[0].values[1]},s=n,r=n;e[e.length-1].type.toLowerCase();for(let p=1,i=e.length;p<i;p++){let u=e[p],h=e[p+1]||e[i-1],y="z"===h.type.toLowerCase()?n:{x:h.values[h.values.length-2],y:h.values[h.values.length-1]},{type:o,values:c}=u,x=c.slice(-2);r="Z"!==o?{x:x[0],y:x[1]}:n;let f=y?Y([s,r,y],!0):1/0,g=R(s,y),d=f<(g?g/333*t:0),m=!1;if(l||"C"!==o||(d=!1),l&&("C"===o||"Q"===o)){m=ne([s,..."C"===o?[{x:c[0],y:c[1]},{x:c[2],y:c[3]}]:"Q"===o?[{x:c[0],y:c[1]}]:[],r],{tolerance:t}),m&&p<i-1&&(o="L",u.type="L",u.values=x)}d&&p<i-1&&"A"!==h.type&&("L"===o||l&&m)||(s=r,"M"===o&&(n=r),a.push(u))}return a}function ve(e){let t={x:e[0].values[0],y:e[0].values[1]},l=t,a=[e[0]];for(let n=1,s=e.length;n<s;n++){let s=e[n],r=e[n-1],p=e[n+1]||null,{type:i,values:u}=s,h="m"===r.type.toLowerCase()&&!p,y=u.length;if(l={x:u[y-2],y:u[y-1]},h||"L"!==i||l.x!==t.x||l.y!==t.y){if(!h&&("l"===i||"v"===i||"h"===i)){if("l"===i?"00"===u.join(""):0===u[0])continue}a.push(s),t=l}}return a}function Me(e){let t=e.length;if(!("z"===e[t-1].type.toLowerCase()))return e;let l=0,a=[];for(let l=0;l<t;l++){let t=e[l],{type:n,values:s}=t,r=s.length;if(r){let e={type:n,x:+s[r-2].toFixed(8),y:+s[r-1].toFixed(8),index:0};e.index=l,a.push(e)}}return a=a.sort((e,t)=>e.y-t.y||e.x-t.x),l=a[0].index,l?Ae(e,l):e}function be(e,{removeFinalLineto:t=!0,autoClose:l=!0}={}){let a=e,n=e.length,s={x:+e[0].values[0].toFixed(8),y:+e[0].values[1].toFixed(8)},r="z"===e[n-1].type.toLowerCase(),p=!1,i=r?n-2:n-1,u=e[i],h=u.type,y=u.values.slice(-2).map(e=>+e.toFixed(8)),o=y[0]===s.x&&y[1]===s.y,c="L"===h,x=[];for(let t=0;t<n;t++){let l=e[t],{type:a,values:n,p0:s,p:r}=l;if("L"===a&&(p=!0),n.length){n.slice(-2);let l={type:a,x:Math.min(s.x,r.x),y:Math.min(s.y,r.y),index:0,prevType:(e[t-1]?e[t-1]:e[i]).type};l.index=t,x.push(l)}}let f=1/0,g=1/0,d=null,m=x.length;for(let e=0;e<m;e++){let t=x[e],{type:l,index:a,x:n,y:s,prevType:r}=t;p&&"L"===r&&(n<f&&s<g&&(d=a-1),s<g&&(g=s),n<f&&(f=n))}return d&&(a=Ae(a,d),n=a.length,s={x:+a[0].values[0].toFixed(8),y:+a[0].values[1].toFixed(8)},i=r?n-2:n-1,u=a[i],h=u.type,y=u.values.slice(-2).map(e=>+e.toFixed(8)),c="L"===h,o=y[0]===s.x&&y[1]===s.y),t&&o&&c&&a.splice(n-2,1),l&&!r&&o&&a.push({type:"Z",values:[]}),a}function Ae(e,t){let l=0,a="z"===e[e.length-1].type.toLowerCase();if(!a||t<1||e.length<3)return e;let n=a?1:0;!function(e){let t=e.length,l="z"===e[t-1].type.toLowerCase(),a=e[0],[n,s]=[a.values[0],a.values[1]].map(e=>+e.toFixed(8)),r=l?e[t-2]:e[t-1],p=r.values.length,[i,u]=[r.values[p-2],r.values[p-1]].map(e=>+e.toFixed(8));!l||n==i&&s==u||(e.pop(),e.push({type:"L",values:[n,s]},{type:"Z",values:[]}))}(e),l=t+1<e.length-1?t+1:e.length-1-n;let s,r,p=e.slice(l),i=e.slice(0,l);return i.shift(),s=i[i.length-1].values||[],r=[s[s.length-2],s[s.length-1]],n&&(p.pop(),i.push({type:"Z",values:[]})),e=[{type:"M",values:r},...p,...i]}function Ce(e,{threshold:t=null,tolerance:l=1}={}){if(!t){let l=function(e){let t=1/0,l=-1/0,a=1/0,n=-1/0;const s=e=>{e.x<t&&(t=e.x),e.x>l&&(l=e.x),e.y<a&&(a=e.y),e.y>n&&(n=e.y)};for(let t=0;t<e.length;t++){let l=e[t],{type:a,values:n}=l,r=n.length,p=(e[t-1]?e[t-1]:e[t]).values,i=p.length;if(r){let e={x:p[i-2],y:p[i-1]},t={x:n[r-2],y:n[r-1]};if(s(t),"C"===a||"Q"===a){let l={x:n[0],y:n[1]},r="C"===a?{x:n[2],y:n[3]}:l,p="C"===a?[e,l,r,t]:[e,l,t];q(p).forEach(e=>{let t=L(p,e);s(t)})}else"A"===a&&Q(e,n).forEach(e=>{s(e)})}}return{x:t,y:a,width:l-t,height:n-a}}(e);t=.05*(l.width+l.height)}let a=e.length;for(let n=0;n<a;n++){let a=e[n],{type:s,values:r,extreme:p,corner:i=!1,dimA:u,p0:h,p:y}=a,o=e[n+1]?e[n+1]:null,c=e[n+2]?e[n+2]:null,x=(o?O(y,o.p):1/0)<t,f=(c?O(c.p,o.p):1/0)<1*t;if(o&&c&&"C"===s&&"C"===o.type&&p&&c.extreme&&(f||x)){let a=te(o,c,t,l,!1);if(1===a.length){a=a[0],e[n+1]=null,e[n+2].values=[a.cp1.x,a.cp1.y,a.cp2.x,a.cp2.y,a.p.x,a.p.y],e[n+2].cp1=a.cp1,e[n+2].cp2=a.cp2,e[n+2].p0=a.p0,e[n+2].p=a.p,e[n+2].extreme=a.extreme,n++;continue}}if(o&&"C"===s&&"C"===o.type&&p&&x){let e=Y([a.p0,a.p,o.p]),t=Y([a.p0,a.cp1,a.cp2,a.p]);if(e<0&&t>0||e>0&&t<0)continue}}a=(e=e.filter(Boolean)).length;let n="z"===e[a-1].type.toLowerCase()?a-2:a-1,s=e[n],r=e[n-1]||null,p={x:e[0].values[0],y:e[0].values[1]},i=s.values.slice(-2),u=+i[0].toFixed(8)===+p.x.toFixed(8)&&+i[1].toFixed(8)===+p.y.toFixed(8),h="C"===e[1].type&&e[1].extreme?e[1]:null,y=O(s.p0,s.p)<t;if(r&&"C"===r.type&&y&&u&&h){let a=te(r,s,t,l,!1);1===a.length&&(e[n-1]=a[0],e[n]=null,e=e.filter(Boolean))}return e}function Se(e,t=!1){if(e.length<3)return!1;let l=e.length,a=Math.floor(.333*l),n=Math.floor(.666*l),s=Math.floor(.5*l),r=e[0],p=e[s],i=e[l-1],u=we([r,p,i]),h=0,y=0,o=0,c=0,x={};if(t){if(l>3){let t=we([r,e[a],i]),l=we([r,e[n],i]);if(!t||!l)return!1;let s=O(u,p);if(O(u,t)+O(u,l)>.05*s)return!1}let t=R(u,p);for(let a=0;a<l;a++){let l=R(u,e[a]);if(Math.abs(t-l)/t>.0025)return!1}h=Math.sqrt(t),x=S(u,r,i),({deltaAngle:y,startAngle:o,endAngle:c}=x)}else h=B(u,r),x=S(u,r,i),({deltaAngle:y,startAngle:o,endAngle:c}=x);return{centroid:u,r:h,startAngle:o,endAngle:c,deltaAngle:y}}function we(e=[]){if((e=e.filter(e=>void 0!==e)).length<3)return!1;let t=e[0],l=e[Math.floor(e.length/2)],a=e[e.length-1],n=t.x,s=t.y,r=l.x,p=l.y,i=a.x,u=a.y,h=n-r,y=s-p,o=n-i,c=s-u,x=(n*n-r*r+(s*s-p*p))/2,f=(n*n-i*i+(s*s-u*u))/2,g=h*c-y*o;return!(Math.abs(g)<1e-10)&&{x:(c*x-y*f)/g,y:(-o*x+h*f)/g}}function Ee(e,{threshold:t=0,simplifyQuadraticCorners:l=!1,tolerance:a=1}={}){let n=e.length,s=[e[0]],r="z"===e[n-1].type.toLowerCase(),p=!!r&&(e[n-1].p.x===e[0].p0.x&&e[n-1].p.y===e[0].p0.y),i=r?2:1,u=e[n-i],h="L"===u.type,y="C"===u.type,o="L"===e[1].type,c="C"===e[1].type,x=null,f=r&&c&&(h||p);f&&(e[n-1].values=e[0].values,e[n-1].type="L",h=!0);for(let t=1;t<n;t++){let p=e[t],{type:u}=p,g=e[t+1]?e[t+1]:null;if("L"===u&&g&&"C"===g.type||"C"===u&&g&&"L"===g.type){let f="L"===u?p:null,d=null,m=[],v=0;if(1===t&&c&&h&&(m=[e[1]],f=e[n-1],d=g),!f){s.push(p);continue}r&&y&&o&&t===n-i-1&&(d=e[1],m=[e[n-i]]);for(let l=t+1;l<n;l++){let t=e[l]?e[l]:null,a=e[l-1];if("C"===a.type&&l>2&&m.push(a),"L"===t.type&&"C"===a.type){d=t;break}v++}if(d){let e=O(f.p0,f.p),r=O(d.p0,d.p),u=O(f.p,d.p0),h=Y([f.p0,f.p,d.p0,d.p],!1),y=Y([m[0].p0,m[0].cp1,m[0].cp2,m[0].p],!1),o=h<0&&y>0||h>0&&y<0,c=.5*u*a,g=c<e&&c<r;if(m.length&&!o&&g){let e=!1;if(1===m.length){let t=Math.abs(m[0].p.x-m[0].p0.x),l=t-Math.abs(m[0].p.y-m[0].p0.y);e=Math.abs(l/t)<.01}let a=!0;if(a=!1,a&&e){let e=L([m[0].p0,m[0].cp1,m[0].cp2,m[0].p],.5),l=Se([m[0].p0,e,m[0].p]),{r:a,centroid:n,deltaAngle:r}=l,p={type:"A",values:[a,a,0,0,r>0?1:0,m[0].p.x,m[0].p.y]};s.push(f,p),t+=v;continue}let r=.005*R(m[0].p0,m[0].p),h=Math.abs(y)<r,o=Math.abs(y)<10*r,g=h?null:w(f.p0,f.p,d.p,d.p0,!1,!0);if(!g||o&&1===m.length){s.push(p);continue}if(g){let e=Y([f.p0,f.p,d.p0,d.p],!1),t=Math.abs(e),l=Y([f.p0,f.p,g,d.p0,d.p],!1),a=Math.abs(l),n=Math.abs(t-a)/t;if(!g||(e<0&&l>0||e>0&&l<0)||n>.5){s.push(p);continue}}let M=.75*O(L([f.p,g,d.p0],.5),1===m.length?L([m[0].p0,m[0].cp1,m[0].cp2,m[0].p],.5):m[0].p);if(c&&M>c&&M>.3*u){s.push(p);continue}let b=d.p0;if(!l){let l=.1666,a=E(g,f.p,1+l);b=E(g,d.p0,1+l);let s=g.y===f.p.y,r=g.x===f.p.x,u=g.y===d.p0.y,h=g.x===d.p0.x;if(e&&p.dimA>3){let e=.5;s&&(a.x=K(a.x,e)),r&&(a.y=K(a.y,e)),u&&(b.x=K(b.x,e)),h&&(b.y=K(b.y,e))}t===n-i-1&&(x=b),f.values=[a.x,a.y],f.p=a}let A={type:"Q",values:[g.x,g.y,b.x,b.y]};A.cp1=g,A.p0=f.p,A.p=b,s.push(f,A),t+=v;continue}}}f&&t===n-1&&"L"===u||s.push(p)}return x&&(s[0].values=[x.x,x.y],s[0].p0=x),(f||r&&"Z"!==s[s.length-1].type)&&s.push({type:"Z",values:[]}),s}function Le(e=[],{threshold:t=0}={}){let l=e.length,a="z"===e[l-1].type.toLowerCase(),n=a?l-2:l-1,s=e[n],r=s.values.slice(-2),p={x:e[0].values[0],y:e[0].values[1]},i=N(p,{x:r[0],y:r[1]});if(i&&i<t){let l=e[n].values.length;e[n].values[l-2]=p.x,e[n].values[l-1]=p.y;let a=e[1];if("C"===a.type&&"C"===s.type){let l=Math.abs(a.values[0]-s.values[2]),r=Math.abs(a.values[1]-s.values[3]),i=Math.abs(e[1].values[0]-a.values[0]),u=Math.abs(e[1].values[1]-a.values[1]),h=Math.abs(e[1].values[0]-s.values[2]),y=Math.abs(e[1].values[1]-s.values[3]),o=u<t&&y<t&&l;l&&l<t&&(i<t&&h<t&&r)&&(e[1].values[0]=p.x,e[n].values[2]=p.x),r&&r<t&&o&&(e[1].values[1]=p.y,e[n].values[3]=p.y)}}return e}function Pe(e,t=1){for(let l=1,a=e.length;l<a;l++){let a=e[l],{type:n,values:s,p0:r,cp1:p=null,cp2:i=null,p:u=null}=a;if("C"===n){let n=oe(r,p,i,u,t);"Q"===n.type&&(n.extreme=a.extreme,n.corner=a.corner,n.dimA=a.dimA,n.squareDist=a.squareDist,e[l]=n)}}return e}function Te(e){for(let t=1,l=e.length;t<l;t++){let l=e[t],{type:a,values:n,p0:s,cp1:r=null,cp2:p=null,p:i=null}=l;if("L"===a){let l=E(s,i,.333),a=E(i,s,.333);e[t].type="C",e[t].values=[l.x,l.y,a.x,a.y,i.x,i.y],e[t].cp1=l,e[t].cp2=a}}return e}function Ie(e,{threshold:t=0,tolerance:l=1,toCubic:a=!1,debug:n=!1}={}){let s=e.length,r=[e[0]];for(let t=1;t<s;t++){let l=e[t],{type:n}=l,s=e[t-1],p=e[t+1]?e[t+1]:null,i=e[t+2]?e[t+2]:null,u=e[t+3]?e[t+3]:null,h=null;"C"===l.type||"Q"===l.type?h=l:!p||"C"!==p.type&&"Q"!==p.type||(h=p);let y,o,c,x,f,g=h?"C"===h.type?[h.p0,h.cp1,h.cp2,h.p]:[h.p0,h.cp1,h.p]:[],d=0,m=0,v=!1,M=!1,b=[];if(i&&u&&"L"===s.type&&"L"===n&&h&&"L"===i.type&&("L"===u.type||"Z"===u.type)?(y=[l.p0,l.p],o=[i.p0,i.p],c=l.p0,x=i.p,d=Y(g,!1),m=Y([...y,...o],!1),v=d<0&&m>0||d>0&&m<0,v||(f=L(g,.5),b=[c,f,x],M=!0)):!p||"C"!==n&&"Q"!==n||"L"!==s.type||!i||"L"!==i.type||"C"!==p.type&&"Q"!==p.type||(M=!0,y=[s.p0,s.p],o=[i.p0,i.p],c=s.p,x=i.p0,f=h.p,b=[c,h.p,x]),M){let e=Se(b);if(e){let n,{centroid:s,r:p,deltaAngle:i,startAngle:u,endAngle:h}=e,y=0,o=i>0?1:0,g=Math.abs(i)>Math.PI?1:0;if(N(T(c,s.x,s.y,.5*i),f)<.05*N(c,x)){if(n=ge({p0:c,p:x,centroid:s,rx:p,ry:p,xAxisRotation:y,sweep:o,largeArc:g,deltaAngle:i,startAngle:u,endAngle:h}),1===n.length){let e=oe(c,n[0].cp1,n[0].cp2,x);"Q"===e.type?a=!0:e=n[0],l=e}n.length>1&&(a=!1),a||(l.type="A",l.values=[p,p,y,g,o,x.x,x.y]),l.p0=c,l.p=x,l.extreme=!1,l.corner=!1,r.push(l),t++;continue}}}r.push(l)}return r}function De(e="",{toAbsolute:t=!0,toRelative:a=!0,toShorthands:n=!0,quadraticToCubic:s=!0,arcToCubic:r=!1,cubicToArc:p=!1,simplifyBezier:i=!0,optimizeOrder:u=!0,autoClose:h=!0,removeZeroLength:y=!0,refineClosing:o=!0,removeColinear:c=!0,flatBezierToLinetos:x=!0,revertToQuadratics:f=!0,refineExtremes:g=!0,simplifyCorners:d=!1,fixDirections:m=!1,keepExtremes:v=!0,keepCorners:M=!0,keepInflections:b=!1,addExtremes:A=!1,addSemiExtremes:C=!1,harmonizeCpts:S=!1,toPolygon:w=!1,removeOrphanSubpaths:E=!1,simplifyRound:L=!1,decimals:P=3,autoAccuracy:T=!0,minifyD:I=0,tolerance:D=1,lineToCubic:k=!1,getObject:q=!1}={}){D=Math.max(.1,D);let Q="",z={x:0,y:0,width:0,height:0},$=[],F=[],j=function(e){let t="",a=!0,n={inputType:"",isValid:!0,fileReport:{}};if(Array.isArray(e))return n.inputType="array",Array.isArray(e[0])?2===e[0].length?n.inputType="polyArray":Array.isArray(e[0][0])&&2===e[0][0].length?n.inputType="polyComplexArray":void 0!==e[0][0].x&&void 0!==e[0][0].y&&(n.inputType="polyComplexObjectArray"):void 0!==e[0].x&&void 0!==e[0].y?n.inputType="polyObjectArray":e[0]?.type&&e[0]?.values&&(n.inputType="pathData"),n;if("string"==typeof e){let s=(e=e.trim()).includes("<svg")&&e.includes("</svg"),r=e.startsWith("<symbol")&&e.includes("</symbol"),p=e.startsWith("M")||e.startsWith("m"),i=!isNaN(e.substring(0,1))&&!isNaN(e.substring(e.length-1,e.length)),u=function(e){e=e.trim();let t=/\d/.test(e),l=/[abcdfghijklmnopqrstuvwz]/gi.test(e);return!(!t||l)&&(e.startsWith("[")&&e.endsWith("]"))}(e);if(s){let s=l(e);({isValid:a,log:t}=s),a?n.inputType="svgMarkup":(n.inputType="invalid",n.isValid=!1,n.log=t),n.fileReport=s.fileReport}else if(u)n.inputType="json";else if(r)n.inputType="symbol";else if(p)n.inputType="pathDataString";else if(i)n.inputType="polyString";else{let t=/^(file:|https?:\/\/|\/|\.\/|\.\.\/)/.test(e),l=e.startsWith("data:image");n.inputType=t||l?"url":"string"}return n}return n.inputType=(e.constructor.name||typeof e).toLowerCase(),n}(e),{inputType:B,log:R}=j;if("pathDataString"===B)Q=e;else if("polyString"===B)Q="M"+e;else{if("pathData"!==B)return!1;Q=e}let N={toRelative:a,toShorthands:n,decimals:P},W=ye(Q,{quadraticToCubic:s,toAbsolute:t,arcToCubic:r});W.length,E&&(W=function(e){let t=[];for(let l=0,a=e.length;l<a;l++){let a=e[l];if(!a)continue;let{type:n=null,values:s=[]}=a,r=e[l+1]?e[l+1]:null;"M"!==n&&"m"!==n||r&&(!r||"Z"!==r.type&&"z"!==r.type)?t.push(a):r&&l++}return t}(W));let J=Z(W),H=J.length,K=[];for(let e=0;e<H;e++){let t=J[e];(c||y)&&(t=ve(t)),u&&(t=Me(t)),c&&(t=me(t,{tolerance:D,flatBezierToLinetos:!1})),(A||C)&&(t=V(t,{tMin:tMin,tMax:tMax,addExtremes:A,addSemiExtremes:C,angles:[30]}));let l=se(t,{detectSemiExtremes:C}),{pathData:a,bb:n,dimA:s}=l;if($.push(n.x,n.x+n.width),F.push(n.y,n.y+n.height),o&&(a=Le(a,{threshold:.001*s})),a=i?le(a,{simplifyBezier:i,keepInflections:b,keepExtremes:v,keepCorners:M,revertToQuadratics:f,tolerance:D}):a,g){a=Ce(a,{threshold:.05*(n.width+n.height),tolerance:D})}if(c&&x&&(a=me(a,{tolerance:D,flatBezierToLinetos:x})),d){a=Ee(a,{threshold:.1*(n.width+n.height),tolerance:D})}L&&(a=Ie(a)),f&&(a=Pe(a,D)),k&&(a=Te(a)),u&&(a=be(a,{autoClose:h})),K.push({pathData:a,bb:n})}let _=Math.min(...$),G=Math.min(...F);z={x:_,y:G,width:Math.max(...$)-_,height:Math.max(...F)-G},u&&(K=z.height>z.width?K.sort((e,t)=>e.bb.y-t.bb.y||e.bb.x-t.bb.x):K.sort((e,t)=>e.bb.x-t.bb.x||e.bb.y-t.bb.y)),W=[],K.forEach(e=>{W.push(...e.pathData)}),T&&(P=function(e){let t=[];for(let l=1,a=e.length;l<a;l++){let a=e[l],{type:n,values:s,p0:r=null,p:p=null,dimA:i=0}=a;s.length&&p&&r&&(i=i||O(r,p),i&&t.push(+i.toFixed(8)))}t=t.sort();let l=t.length,a=t[Math.floor(.5*l)],n=Math.ceil(.25*l),s=.5*(t.slice(0,n).reduce((e,t)=>e+t,0)/n+a),r=s>112.5?0:Math.floor(75/s).toString().length;return Math.min(Math.max(0,r),8)}(W),N.decimals=P),W=he(W,N),W=ve(W);let U=ee(W,I);return q&&(W=W.map(e=>({type:e.type,values:e.values}))),q?W:U}"undefined"!=typeof window&&(window.simplifyPathData=De);export{De as simplifyPathData};
package/index.html CHANGED
@@ -156,7 +156,7 @@
156
156
 
157
157
 
158
158
  <label>Input SVG
159
- <textarea class="inputSvg code" name="dInput" id="inputSvg" data-tools="size upload copy">m71.72 20.83 0 0c-1.76 .59-3.69 .97-5.79 1.15s-4.68 .26-7.73 .26c5.45 2.46 8.16 6.35 8.16 11.67 0 4.62-1.58 8.39-4.73 11.32s-7.46 4.39-12.9 4.39c-2.11 0-4.07-.3-5.88-.88-.71 .47-1.26 1.1-1.67 1.89s-.61 1.59-.61 2.41c0 2.52 2.02 3.77 6.05 3.77h7.37c3.1 0 5.85 .56 8.25 1.67s4.26 2.64 5.57 4.56 1.98 4.13 1.98 6.59c0 4.5-1.84 7.97-5.53 10.39s-9.07 3.65-16.14 3.65c-4.98 0-8.91-.52-11.81-1.54s-4.95-2.56-6.18-4.61-1.85-4.68-1.85-7.89h5.54 1.75c0 1.87 .35 3.34 1.05 4.43 .7 1.08 1.96 1.9 3.77 2.46s4.39 .83 7.73 .83c4.85 0 8.32-.6 10.39-1.8s3.12-3 3.12-5.4c0-2.16-.82-3.8-2.46-4.91s-3.92-1.67-6.85-1.67h-7.28c-3.92 0-6.89-.83-8.91-2.5s-3.02-3.76-3.02-6.27c0-1.53 .44-2.99 1.31-4.39s2.14-2.66 3.78-3.77c-2.69-1.41-4.67-3.15-5.92-5.23s-1.89-4.6-1.89-7.58c0-3.11 .77-5.89 2.32-8.34s3.69-4.38 6.41-5.75 5.75-2.06 9.08-2.06c3.63 .06 6.67-.08 9.13-.4s4.48-.76 6.1-1.31 3.58-1.36 5.92-2.42l0.88 2.71 .88 2.7 .61 1.87zm-30.58 5.49c-1.67 1.9-2.51 4.4-2.51 7.5 0 3.16 .85 5.69 2.55 7.59s4.1 2.85 7.2 2.85 5.57-.92 7.24-2.76 2.5-4.43 2.5-7.76c0-6.85-3.31-10.27-9.92-10.27-3.04 0-5.4 .95-7.06 2.85z
159
+ <textarea class="inputSvg code" name="dInput" id="inputSvg" data-tools="size upload copy">M13 7 13 9 13 11C13 11.57 12.79 12.07 12.43 12.43 12.07 12.79 11.57 13 11 13L10 13 9.72 13C9.55 12.7 9.3 12.45 9 12.28L9 11 9 9.72C9.6 9.38 10 8.74 10 8 10 6.9 9.1 6 8 6 7.26 6 6.62 6.41 6.28 7L5.5 7 4 7C3.43 7 2.93 6.79 2.57 6.43 2.21 6.07 2 5.57 2 5 2 4.43 2.22 3.93 2.57 3.57 2.93 3.21 3.43 3 4 3L5.5 3 6.28 3C6.62 3.6 7.26 4 8 4 9.1 4 10 3.1 10 2 10 .9 9.1 0 8 0 7.26 0 6.62 .41 6.28 1L5.5 1 4 1C2.88 1 1.88 1.44 1.16 2.16 .44 2.88 0 3.88 0 5 0 6.12 .44 7.12 1.16 7.84 1.88 8.56 2.88 9 4 9L5.5 9 6.28 9C6.45 9.3 6.7 9.55 7 9.72L7 11 7 12.28C6.7 12.45 6.45 12.7 6.28 13L5 13 3.72 13C3.38 12.4 2.74 12 2 12 .9 12 0 12.9 0 14 0 15.1 .9 16 2 16 2.74 16 3.38 15.6 3.72 15L5 15 6.28 15C6.62 15.6 7.26 16 8 16 8.74 16 9.38 15.6 9.72 15L10 15 11 15C12.12 15 13.12 14.56 13.84 13.84 14.56 13.12 15 12.12 15 11L15 9 15 7 14 7 13 7zM8 1C8.55 1 9 1.45 9 2 9 2.55 8.55 3 8 3 7.45 3 7 2.55 7 2 7 1.45 7.45 1 8 1zM2 15C1.45 15 1 14.55 1 14 1 13.45 1.45 13 2 13 2.55 13 3 13.45 3 14 3 14.55 2.55 15 2 15zM8 7C8.55 7 9 7.45 9 8 9 8.55 8.55 9 8 9 7.45 9 7 8.55 7 8 7 7.45 7.45 7 8 7zM8 15C7.45 15 7 14.55 7 14 7 13.45 7.45 13 8 13 8.55 13 9 13.45 9 14 9 14.55 8.55 15 8 15zM14 0C12.9 0 12 .9 12 2 12 3.1 12.9 4 14 4 15.1 4 16 3.1 16 2 16 .9 15.1 0 14 0zM14 3C13.45 3 13 2.55 13 2 13 1.45 13.45 1 14 1 14.55 1 15 1.45 15 2 15 2.55 14.55 3 14 3z
160
160
  </textarea>
161
161
  </label>
162
162
 
@@ -840,8 +840,7 @@
840
840
 
841
841
  <svg id="svg" class="svgO" viewBox="0 0 100 100">
842
842
 
843
- <path id="path1" class="path pathO" d="M54,40.938C68.946,36.071,72.99,30.492,72.992,27
844
- c0.004-5.928-11.632-5.845-1.367,13.938" />
843
+ <path id="path1" class="path pathO" d="M13 7 13 9 13 11C13 11.57 12.79 12.07 12.43 12.43 12.07 12.79 11.57 13 11 13L10 13 9.72 13C9.55 12.7 9.3 12.45 9 12.28L9 11 9 9.72C9.6 9.38 10 8.74 10 8 10 6.9 9.1 6 8 6 7.26 6 6.62 6.41 6.28 7L5.5 7 4 7C3.43 7 2.93 6.79 2.57 6.43 2.21 6.07 2 5.57 2 5 2 4.43 2.22 3.93 2.57 3.57 2.93 3.21 3.43 3 4 3L5.5 3 6.28 3C6.62 3.6 7.26 4 8 4 9.1 4 10 3.1 10 2 10 .9 9.1 0 8 0 7.26 0 6.62 .41 6.28 1L5.5 1 4 1C2.88 1 1.88 1.44 1.16 2.16 .44 2.88 0 3.88 0 5 0 6.12 .44 7.12 1.16 7.84 1.88 8.56 2.88 9 4 9L5.5 9 6.28 9C6.45 9.3 6.7 9.55 7 9.72L7 11 7 12.28C6.7 12.45 6.45 12.7 6.28 13L5 13 3.72 13C3.38 12.4 2.74 12 2 12 .9 12 0 12.9 0 14 0 15.1 .9 16 2 16 2.74 16 3.38 15.6 3.72 15L5 15 6.28 15C6.62 15.6 7.26 16 8 16 8.74 16 9.38 15.6 9.72 15L10 15 11 15C12.12 15 13.12 14.56 13.84 13.84 14.56 13.12 15 12.12 15 11L15 9 15 7 14 7 13 7zM8 1C8.55 1 9 1.45 9 2 9 2.55 8.55 3 8 3 7.45 3 7 2.55 7 2 7 1.45 7.45 1 8 1zM2 15C1.45 15 1 14.55 1 14 1 13.45 1.45 13 2 13 2.55 13 3 13.45 3 14 3 14.55 2.55 15 2 15zM8 7C8.55 7 9 7.45 9 8 9 8.55 8.55 9 8 9 7.45 9 7 8.55 7 8 7 7.45 7.45 7 8 7zM8 15C7.45 15 7 14.55 7 14 7 13.45 7.45 13 8 13 8.55 13 9 13.45 9 14 9 14.55 8.55 15 8 15zM14 0C12.9 0 12 .9 12 2 12 3.1 12.9 4 14 4 15.1 4 16 3.1 16 2 16 .9 15.1 0 14 0zM14 3C13.45 3 13 2.55 13 2 13 1.45 13.45 1 14 1 14.55 1 15 1.45 15 2 15 2.55 14.55 3 14 3z" />
845
844
  <path id="pathS" class="path pathS" d="" />
846
845
 
847
846
  <g id="markers"></g>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svg-path-simplify",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
 
5
5
  "type": "module",
6
6
 
@@ -56,7 +56,7 @@ export function simplifyPathDataCubic(pathData, {
56
56
  error += com.error;
57
57
 
58
58
  // find next candidates
59
- for (let n = i + 1; error < tolerance && n < l; n++) {
59
+ for (let n = i + offset; error < tolerance && n < l; n++) {
60
60
  let comN = pathData[n]
61
61
 
62
62
  if (comN.type !== 'C' ||
@@ -66,6 +66,7 @@ export function simplifyPathDataCubic(pathData, {
66
66
  (keepExtremes && com.extreme)
67
67
  )
68
68
  ) {
69
+
69
70
  break
70
71
  }
71
72
 
@@ -73,6 +74,7 @@ export function simplifyPathDataCubic(pathData, {
73
74
 
74
75
  // failure - could not be combined - exit loop
75
76
  if (combined.length > 1) {
77
+ //renderPoint(markers, com.p, 'orange', '1%', '0.5')
76
78
  break
77
79
  }
78
80
 
@@ -86,6 +88,7 @@ export function simplifyPathDataCubic(pathData, {
86
88
 
87
89
  // return combined
88
90
  com = combined[0]
91
+
89
92
  }
90
93
 
91
94
  //console.log('tests', log, offset);
@@ -213,11 +216,26 @@ export function combineCubicPairs(com1, com2, {
213
216
 
214
217
  comS.dimA = getDistManhattan(comS.p0, comS.p);
215
218
  comS.type = 'C';
219
+
216
220
  comS.extreme = com2.extreme;
217
221
  comS.directionChange = com2.directionChange;
218
- //comS.directionChange = com1.directionChange ? true : (com2.directionChange);
219
222
  comS.corner = com2.corner;
220
223
 
224
+
225
+ if (comS.extreme || comS.corner) {
226
+ //renderPoint(markers, comS.p)
227
+ }
228
+
229
+ /*
230
+ comS.extreme = com1.extreme;
231
+ comS.directionChange = com1.directionChange;
232
+ comS.corner = com1.corner;
233
+ */
234
+
235
+
236
+
237
+ //comS.directionChange = com1.directionChange ? true : (com2.directionChange);
238
+
221
239
  comS.values = [comS.cp1.x, comS.cp1.y, comS.cp2.x, comS.cp2.y, comS.p.x, comS.p.y]
222
240
 
223
241
  // relative error
@@ -91,11 +91,11 @@ export function svgPathSimplify(input = '', settings = {}) {
91
91
  original: 0,
92
92
  new: 0,
93
93
  saved: 0,
94
- svgSize:0,
95
- svgSizeOpt:0,
96
- compression:0,
97
- decimals:0,
98
- invalid:true
94
+ svgSize: 0,
95
+ svgSizeOpt: 0,
96
+ compression: 0,
97
+ decimals: 0,
98
+ invalid: true
99
99
  }
100
100
 
101
101
  return { svg: dummySVG, d: '', polys: [], report, pathDataPlusArr: [], pathDataPlusArr_global: [], inputType: 'invalid', dOriginal: '' };
@@ -297,6 +297,12 @@ export function svgPathSimplify(input = '', settings = {}) {
297
297
  let dN = ''
298
298
  let isPoly = false;
299
299
 
300
+ // disable reordering for elements with stroke dash-array
301
+ if (el && (el.hasAttribute('stroke-dasharray') || el.hasAttribute('stroke-dashoffset'))) {
302
+ optimizeOrder = false;
303
+ //optimizeClosePath=false;
304
+ }
305
+
300
306
  // if polygon we already heave absolute coordinates
301
307
  //let isPolyPath = !mode && isPoly && Array.isArray(d)
302
308
  //let pathData = !isPolyPath ? parsePathDataNormalized(d, { quadraticToCubic, arcToCubic }) : d;
@@ -245,7 +245,6 @@ export const presetSettings = {
245
245
  addViewBox: true,
246
246
  removeDimensions: true,
247
247
  removeOffCanvas: true,
248
-
249
248
  /*
250
249
  */
251
250
  }
@@ -8,7 +8,7 @@ export function getElementAtts(el, {x=0, y=0, width=0, height=0}={}){
8
8
  attributes.forEach(att=>{
9
9
  //let value = normalizeUnits(att.nodeValue, {x, y, width, height});
10
10
  let value = normalizeUnits(el.getAttribute(att), {x, y, width, height});
11
- atts[att.name] = value
11
+ atts[att] = value
12
12
  })
13
13
 
14
14
  return atts
@@ -111,7 +111,7 @@ export function getLength(pts, {
111
111
 
112
112
  // LG weight/abscissae generator
113
113
  export function getLegendreGaussValues(n, x1 = -1, x2 = 1) {
114
- console.log('add new LG', n);
114
+ //console.log('add new LG', n);
115
115
 
116
116
  let waArr = []
117
117
  let z1, z, xm, xl, pp, p3, p2, p1;
@@ -29,7 +29,8 @@ export function pathDataToTopLeft(pathData) {
29
29
  let { type, values } = com;
30
30
  let valsLen = values.length
31
31
  if (valsLen) {
32
- let p = { type: type, x: values[valsLen - 2], y: values[valsLen - 1], index: 0 }
32
+ // we need rounding otherwise sorting may crash due to e notation
33
+ let p = { type: type, x: +values[valsLen - 2].toFixed(8), y: +values[valsLen - 1].toFixed(8), index: 0 }
33
34
  p.index = i
34
35
  indices.push(p)
35
36
  }
@@ -37,7 +38,7 @@ export function pathDataToTopLeft(pathData) {
37
38
 
38
39
  // reorder to top left most
39
40
  //|| a.x - b.x
40
- indices = indices.sort((a, b) => +a.y.toFixed(8) - +b.y.toFixed(8) || a.x - b.x);
41
+ indices = indices.sort((a, b) => a.y - b.y || a.x - b.x);
41
42
  newIndex = indices[0].index
42
43
 
43
44
  return newIndex ? shiftSvgStartingPoint(pathData, newIndex) : pathData;