svg-path-simplify 0.3.5 → 0.4.0
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.
- package/CHANGELOG.md +19 -0
- package/README.md +3 -76
- package/dist/svg-path-simplify.esm.js +5505 -4030
- package/dist/svg-path-simplify.esm.min.js +2 -8
- package/dist/svg-path-simplify.js +5506 -4029
- package/dist/svg-path-simplify.min.js +2 -8
- package/dist/svg-path-simplify.pathdata.esm.js +1154 -1042
- package/dist/svg-path-simplify.pathdata.esm.min.js +2 -8
- package/docs/api.md +127 -0
- package/index.html +279 -257
- package/package.json +1 -1
- package/src/constants.js +10 -1
- package/src/index.js +7 -1
- package/src/pathData_simplify_cubic.js +1 -18
- package/src/pathSimplify-main.js +87 -30
- package/src/pathSimplify-only-pathdata.js +2 -2
- package/src/svg-getAttributes.js +13 -0
- package/src/svg_flatten_transforms.js +1 -1
- package/src/svg_getViewbox.js +23 -11
- package/src/svg_rootSVG.js +9 -0
- package/src/svgii/convert_colors.js +145 -0
- package/src/svgii/convert_units.js +159 -0
- package/src/svgii/geometry.js +24 -4
- package/src/svgii/geometry_bbox.js +2 -1
- package/src/svgii/geometry_bbox_element.js +46 -0
- package/src/svgii/pathData_analyze.js +34 -14
- package/src/svgii/pathData_convert.js +204 -34
- package/src/svgii/pathData_parse.js +2 -99
- package/src/svgii/pathData_parse_els.js +217 -128
- package/src/svgii/pathData_simplify_refineCorners.js +72 -43
- package/src/svgii/pathData_stringify.js +6 -5
- package/src/svgii/pathData_toPolygon.js +3 -1
- package/src/svgii/pathData_transform.js +307 -0
- package/src/svgii/poly_normalize.js +21 -1
- package/src/svgii/rounding.js +36 -5
- package/src/svgii/svg-styles-getTransforms.js +119 -8
- package/src/svgii/svg-styles-to-attributes-const.js +26 -6
- package/src/svgii/svg_cleanup.js +540 -74
- package/src/svgii/svg_el_parse_style_props.js +561 -0
- package/src/svgii/transform_qr_decompose.js +74 -0
- package/src/svgii/pathData_scale.js +0 -42
- package/src/svgii/stringify.js +0 -103
- package/src/svgii/svg-styles-to-attributes.js +0 -217
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
function e(e,t,l="red",a="1%",n="1",r="",s=!0,p="",i=""){Array.isArray(t)&&(t={x:t[0],y:t[1]});let y=`<circle class="${i}" opacity="${n}" id="${p}" cx="${t.x}" cy="${t.y}" r="${a}" fill="${l}">\n <title>${r}</title></circle>`;if(!s)return y;e.insertAdjacentHTML("beforeend",y)}function t(e,t="",l="green",a="1%",n="1",r=!0){let s=`<path d="${t}" fill="none" stroke="${l}" stroke-width="${a}" stroke-opacity="${n}" /> `;if(!r)return s;e.insertAdjacentHTML("beforeend",s)}const{abs:l,acos:a,asin:n,atan:r,atan2:s,ceil:p,cos:i,exp:y,floor:u,log:h,max:o,min:x,pow:c,random:f,round:g,sin:d,sqrt:M,tan:v,PI:m}=Math;function b(e,t,l=!1){let a=s(t.y-e.y,t.x-e.x);return l&&a<0&&(a+=2*Math.PI),a}function A(e,t,l,a=!1){let n=Math.atan2(t.y-e.y,t.x-e.x),r=Math.atan2(l.y-e.y,l.x-e.x),s=r-n;s=(e=>{let t=e%(2*Math.PI);return t>Math.PI?t-=2*Math.PI:t<=-Math.PI&&(t+=2*Math.PI),t})(s),a&&(s=2*Math.PI-Math.abs(s));let p=180/Math.PI;return{startAngle:n,endAngle:r,deltaAngle:s,startAngleDeg:n*p,endAngleDeg:r*p,deltaAngleDeg:s*p}}function C(e=null,t=null,l=null,a=null,n=!0,r=!1,s=!1){let p,i,y,u,h,o={};if(!(e&&t&&l&&a))return s&&console.warn("points missing"),!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 s&&console.warn("!catch",e,t,"p3:",l,"p4:",a),!1}i=e.y-l.y,y=e.x-l.x,u=(a.x-l.x)*i-(a.y-l.y)*y,h=(t.x-e.x)*i-(t.y-e.y)*y,i=u/p,y=h/p,o={x:e.x+i*(t.x-e.x),y:e.y+i*(t.y-e.y)};let x=!1;return i>0&&i<1&&y>0&&y<1&&(x=!0),!n&&r&&(i>0&&y<0||i<0&&y>0)?(x=!1,!1):!(n&&!x)&&o}function L(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=b(e,t),n.angle<0&&(n.angle+=2*m)),n}function w(e,t=.5,l=!1,a=!1,n=!1){let r;return Array.isArray(e[0])&&(e=e.map(e=>({x:e[0],y:e[1]})),n=!0),r=e.length>2?((e,t,l=!1)=>{let n=4===e.length,r=e[0],s=e[1],p=n?e[2]:e[1],i=e[e.length-1],y={x:0,y:0};if(l||a){let e,l,u,h,o,x=r.x===s.x&&r.y===s.y,c=i.x===p.x&&i.y===p.y;0!==t||x?1!==t||c?(x&&(t+=1e-7),c&&(t-=1e-7),e=L(r,s,t),n?(l=L(s,p,t),u=L(p,i,t),h=L(e,l,t),o=L(l,u,t),y=L(h,o,t),y.angle=b(h,o),a&&(y.cpts=[l,u,h,o])):(l=L(r,s,t),u=L(s,i,t),y=L(l,u,t),y.angle=b(l,u),a&&(y.cpts=[l,u]))):(y.x=i.x,y.y=i.y,y.angle=b(p,i)):(y.x=r.x,y.y=r.y,y.angle=b(r,s))}else{let e=1-t;y=n?{x:e**3*r.x+3*e**2*t*s.x+3*e*t**2*p.x+t**3*i.x,y:e**3*r.y+3*e**2*t*s.y+3*e*t**2*p.y+t**3*i.y}:{x:e*e*r.x+2*e*t*s.x+t**2*i.x,y:e*e*r.y+2*e*t*s.y+t**2*i.y}}return y})(e,t,l):L(e[0],e[1],t,l),l&&r.angle<0&&(r.angle+=2*m),n?[r.x,r.y]:r}function P(e,t,a,n,r,p,i,y,u){const h=(e,t,l,a)=>s(a-t,l-e);let o={cx:0,cy:0,rx:a=l(a),ry:n=l(n),startAngle:0,endAngle:0,deltaAngle:0,clockwise:i,xAxisRotation:r,largeArc:p,sweep:i};if(0==a||0==n)throw Error("rx and ry can not be 0");if(a===n){let l=Math.abs(y-e),a=Math.abs(u-t),n=l,r=Math.min(e,y),s=Math.min(t,u),p=.5*Math.PI;if(0===l&&a||0===a&&l)return n=0===l&&a?a/2:l/2,o.rx=n,o.ry=n,0===l&&a?(o.cx=e,o.cy=s+a/2,o.startAngle=t>u?p:-p,o.endAngle=t>u?-p:p,o.deltaAngle=i?Math.PI:-Math.PI):0===a&&l&&(o.cx=r+l/2,o.cy=t,o.startAngle=e>y?Math.PI:0,o.endAngle=e>y?-Math.PI:Math.PI,o.deltaAngle=i?Math.PI:-Math.PI),o}let x,c,f=a===n?0:r*m/180,g=f?Math.sin(f):0,d=f?Math.cos(f):1,M=(e-y)/2,v=(t-u)/2,b=(e+y)/2,A=(t+u)/2,C=f?d*M+g*v:M,L=f?d*v-g*M:v,w=C*C/(a*a)+L*L/(n*n);w>1&&(a*=Math.sqrt(w),n*=Math.sqrt(w),o.rx=a,o.ry=n);let P=a*n,S=a*L,E=n*C,I=S**2+E**2;if(!I)throw Error("start point can not be same as end point");let k=Math.sqrt(Math.abs((P*P-I)/I));p==i&&(k=-k);let D=k*S/n,$=-k*E/a;x=f?d*D-g*$+b:b+D,c=f?g*D+d*$+A:A+$,o.cy=c,o.cx=x;let Q=h(x,c,e,t),q=h(x,c,y,u);!i&&q>Q&&(q-=2*Math.PI),i&&Q>q&&(q=q<=0?q+2*Math.PI:q);let z=q-Q;return o.startAngle=Q,o.endAngle=q,o.deltaAngle=z,o}function S(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 E(e,t,l,a,n,s=0,p=!0,y=!1){if(n=y?n*m/180:n,s=y?s*m/180:s,s=l!==a&&s!==2*m?s:0,p&&l!==a){let e=r(v(n=s?n-s:n)*(l/a));n=i(n)<0?e+m:e}let u=e+l*i(n),h=t+a*d(n),o={x:u,y:h};return s&&(o.x=e+(u-e)*i(s)-(h-t)*d(s),o.y=t+(u-e)*d(s)+(h-t)*i(s)),o}function I(e,t,l){if(t===l||e%m*.5==0)return e;let a=r(v(e)*(t/l));return a=i(e)<0?a+m: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],r=3===l?t[1]:n,s=Math.min(e.y,a.y),p=Math.min(e.x,a.x),i=Math.max(e.x,a.x),y=Math.max(e.y,a.y);return!(n.y>=s&&n.y<=y&&r.y>=s&&r.y<=y&&n.x>=p&&n.x<=i&&r.x>=p&&r.x<=i)}function D(e,{addExtremes:t=!0,addSemiExtremes:l=!1}={}){let a=4===e.length?function(e,t,l,a,{addExtremes:n=!0,addSemiExtremes:r=!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}};r&&(e=s(e),t=s(t),l=s(l),a=s(a));let[p,i,y,u,h,o,x,c]=[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,L,w,P,S=[];for(let e=0;e<2;++e)if(0==e?(m=6*p-12*y+6*h,v=-3*p+9*y-9*h+3*x,b=3*y-3*p):(m=6*i-12*u+6*o,v=-3*i+9*u-9*o+3*c,b=3*u-3*i),Math.abs(v)<1e-8){if(Math.abs(m)<1e-8)continue;A=-b/m,0<A&&A<1&&S.push(A)}else w=m*m-4*b*v,w<0?Math.abs(w)<1e-8&&(A=-m/(2*v),0<A&&A<1&&S.push(A)):(P=Math.sqrt(w),C=(-m+P)/(2*v),0<C&&C<1&&S.push(C),L=(-m-P)/(2*v),0<L&&L<1&&S.push(L));let E=S.length;for(;E--;)A=S[E];return S}(e[0],e[1],e[2],e[3],{addExtremes:t,addSemiExtremes:l}):function(e,t,l,{addExtremes:a=!0,addSemiExtremes:n=!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}};n&&(e=r(e),t=r(t),l=r(l));let s,p,i,y=Math.min(e.y,l.y),u=Math.min(e.x,l.x),h=Math.max(e.x,l.x),o=Math.max(e.y,l.y);if(t.y>=y&&t.y<=o&&t.x>=u&&t.x<=h)return[];let[x,c,f,g,d,M]=[e.x,e.y,t.x,t.y,l.x,l.y],v=[];for(let e=0;e<2;++e)s=0==e?x-2*f+d:c-2*g+M,p=0==e?-2*x+2*f:-2*c+2*g,Math.abs(s)>1e-12&&(i=-p/(2*s),i>0&&i<1&&v.push(i));return v}(e[0],e[1],e[2],{addExtremes:t,addSemiExtremes:l});return a}function $(e,t){const l=(e,t,l,a,n,r)=>{var s=Math.cos(r),p=Math.sin(r),i=a*Math.cos(e),y=n*Math.sin(e);return{x:t+s*i-p*y,y:l+p*i+s*y}};let a,n,r,s,p,i=P(e.x,e.y,t[0],t[1],t[2],t[3],t[4],t[5],t[6]),{rx:y,ry:u,cx:h,cy:o,endAngle:x,deltaAngle:c}=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(-u*v,y);let m=p,b=p+Math.PI,A=Math.atan2(u,y*v),C=A+Math.PI,L=[e.x,g.x],w=[e.y,g.y],S=Math.min(...L),E=Math.max(...L),I=Math.min(...w),k=Math.max(...w),D=l(x-.001*c,h,o,y,u,M),$=l(x-.999*c,h,o,y,u,M);return(D.x>E||$.x>E)&&(a=l(m,h,o,y,u,M),d.push(a)),(D.x<S||$.x<S)&&(n=l(b,h,o,y,u,M),d.push(n)),(D.y<I||$.y<I)&&(s=l(C,h,o,y,u,M),d.push(s)),(D.y>k||$.y>k)&&(r=l(A,h,o,y,u,M),d.push(r)),d}function Q(e=[],t=[]){let l=e.length,a=4===l;t.length||(t=[0]);let n=t.length,r=[];for(let s=0;s<n;s++){let n=t[s],p=n?[]:e.slice(0);if(n)for(let t=0;t<l;t++){let l=e[t];p.push(S(l,0,0,n))}let i=a?q(...p):z(...p);r.push(...i)}return r=[...new Set(r)].sort(),r}function q(e,t,l,a){if(!k(e,[t,l,a]))return[];let n,r,s,p,i,y,u,h,[o,x,c,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?(r=6*o-12*c+6*g,n=-3*o+9*c-9*g+3*M,s=3*c-3*o):(r=6*x-12*f+6*d,n=-3*x+9*f-9*d+3*v,s=3*f-3*x),Math.abs(n)<b){if(Math.abs(r)<b)continue;p=-s/r,p>0&&p<1&&m.push(p)}else u=r*r-4*s*n,u<0?Math.abs(u)<b&&(p=-r/(2*n),p>0&&p<1&&m.push(p)):(h=Math.sqrt(u),i=(-r+h)/(2*n),i>0&&i<1&&m.push(i),y=(-r-h)/(2*n),y>0&&y<1&&m.push(y));let A=m.length;for(;A--;)p=m[A];return[...new Set(m)].sort()}function z(e,t,l){if(!k(e,[t,l]))return[];let a,n,r,[s,p,i,y,u,h]=[e.x,e.y,t.x,t.y,l.x,l.y],o=[];for(let e=0;e<2;++e)a=0==e?s-2*i+u:p-2*y+h,n=0==e?-2*s+2*i:-2*p+2*y,Math.abs(a)>1e-12&&(r=-n/(2*a),r>0&&r<1&&o.push(r));return[...new Set(o)].sort()}function T(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 F(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 M(a*a+n*n)}function j(e,t){let l=t.x-e.x,a=t.y-e.y;return l*l+a*a}function R(e,t){return Math.abs(t.x-e.x)+Math.abs(t.y-e.y)}function Z(e,t){return.5*(Math.abs(t.x-e.x)+Math.abs(t.y-e.y))}function O(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 B(e,t){let l,a,n,r,s,p,i=[],y=[],u=e[0],h=e[1],o=e[e.length-2],x=e[e.length-1];return 4===e.length?(l=w([u,h],t),a=w([h,o],t),n=w([o,x],t),r=w([l,a],t),s=w([a,n],t),p=w([r,s],t),i.push({x:u.x,y:u.y},{x:l.x,y:l.y},{x:r.x,y:r.y},{x:p.x,y:p.y}),y.push({x:p.x,y:p.y},{x:s.x,y:s.y},{x:n.x,y:n.y},{x:x.x,y:x.y})):3===e.length?(a=w([u,h],t),n=w([h,x],t),p=w([a,n],t),i.push({x:u.x,y:u.y},{x:a.x,y:a.y},{x:p.x,y:p.y}),y.push({x:p.x,y:p.y},{x:n.x,y:n.y},{x:x.x,y:x.y})):2===e.length&&(a=w([u,x],t),i.push({x:u.x,y:u.y},{x:a.x,y:a.y}),y.push({x:a.x,y:a.y},{x:x.x,y:x.y})),[i,y]}function N(e,t,{tMin:l=0,tMax:a=1,addExtremes:n=!0,addSemiExtremes:r=!1}={}){let s=[],p=6===t.length?"C":"Q",i={x:t[0],y:t[1]},y="C"===p?{x:t[2],y:t[3]}:i,u={x:t[4],y:t[5]},h=0;let o="C"===p?[e,i,y,u]:[e,i,u],x=n?D(o,{addExtremes:n,addSemiExtremes:!1}):[],c=r?D(o,{addExtremes:n,addSemiExtremes:r}):[],f=Array.from(new Set([...x,...c])).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 r,s,p,i=t.length,y={x:t[i-2],y:t[i-1]};2===t.length?p=[e,y]:4===t.length?(r={x:t[0],y:t[1]},p=[e,r,y]):6===t.length&&(r={x:t[0],y:t[1]},s={x:t[2],y:t[3]},p=[e,r,s,y]);if(l.length)if(1===l.length){let e=B(p,l[0]),t=e[0],a=e[1];n.push(t,a)}else{let e=l[0],t=B(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=B(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);s.push(...l),h+=l.length}else s.push({type:p,values:t});return{pathData:s,count:h}}function H(e,{tMin:t=0,tMax:l=1,addExtremes:a=!0,addSemiExtremes:n=!1}={}){let r=[e[0]],s={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 y=1;i&&y<i;y++){let i=e[y],{type:u,values:h}=i,o=h.slice(-2);if(o[0],o[1],"C"!==u&&"Q"!==u)r.push(i);else if((a||n)&&("C"===u||"Q"===u)){let e=N(s,h,{tMin:t,tMax:l,addExtremes:a,addSemiExtremes:n}).pathData;r.push(...e)}s={x:o[0],y:o[1]},"z"===u.toLowerCase()?s=p:"M"===u&&(p={x:o[0],y:o[1]})}return r}function J(e,t=-1){let l=e.map(e=>e.x),a=e.map(e=>e.y),n=Math.min(...l),r=Math.max(...l),s=Math.min(...a),p=Math.max(...a),i={x:n,left:n,right:r,y:s,top:s,bottom:p,width:r-n,height:p-s};if(t>-1)for(let e in i)i[e]=+i[e].toFixed(t);return i}function U(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:r,values:s}=a,p={x:n.values[n.values.length-2],y:n.values[n.values.length-1]},i=s.length?{x:s[s.length-2],y:s[s.length-1]}:"",y=s.length?{x:s[0],y:s[1]}:"";switch(r){case"A":if("function"!=typeof arcToBezier){let e=F(p,i)/2,l=L(p,i,.5),a=E(l.x,l.y,e,e,0),n=E(l.x,l.y,e,e,Math.PI);t.push(a,n,i);break}arcToBezier(p,s).forEach(e=>{let l=e.values,a={x:l[0],y:l[1]},n={x:l[2],y:l[3]},r={x:l[4],y:l[5]};t.push(a,n,r)});break;case"C":let e={x:s[2],y:s[3]};t.push(y,e);break;case"Q":t.push(y)}"z"!==r.toLowerCase()&&t.push(i)}return t}(e),l=J(t);return l}(e);t.push(l)}),t}function V(e,t){let[l,a,n,r,s,p]=[e.x,e.y,e.width,e.height,e.x+e.width,e.y+e.height],[i,y,u,h,o,x]=[t.x,t.y,t.width,t.height,t.x+t.width,t.y+t.height],c=!1;return n*r!=u*h&&n*r>u*h&&l<i&&s>o&&a<y&&p>x&&(c=!0),c}function W(e,t=9){let l=0,a=[],n=O(e),r=n.length>1,s=[];if(r){let e=U(n);e.forEach(function(t,l){for(let l=0;l<e.length;l++){let a=e[l];if(t!=a){V(t,a)&&s.push(l)}}})}return n.forEach((e,t)=>{a=[];let n=0,r=0,p=1,i=[];e.forEach(function(t,l){let[r,s]=[t.type,t.values],p=s.length;if(s.length){let y=(l>0?e[l-1]:e[0]).values,u=y.length,h={x:y[u-2],y:y[u-1]},o={x:s[p-2],y:s[p-1]};if("C"===r||"Q"===r){let e={x:s[0],y:s[1]};i="C"===r?[h,e,{x:s[2],y:s[3]},o]:[h,e,o];let t=Math.abs(function(e,t=!1){let l,[a,n,r,s]=[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},r={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-r.y+3*s.y)+n.x*(2*a.y-r.y-s.y)+r.x*(a.y+n.y-2*s.y)+s.x*(-3*a.y+n.y+2*r.y))/20,t?Math.abs(l):l}(i));n+=t,a.push(h,o)}else if("A"===r){let e=P(h.x,h.y,t.values[0],t.values[1],t.values[2],t.values[3],t.values[4],o.x,o.y),{cx:l,cy:r,rx:s,ry:p,startAngle:i,endAngle:y,deltaAngle:u}=e,x=Math.abs(function(e,t,l,a){const n=Math.PI*e*t;let r=(a-l+2*Math.PI)%(2*Math.PI);if(e===t)return n*(r/(2*Math.PI));const s=l=>Math.atan2(e*Math.sin(l),t*Math.cos(l));return l=s(l),a=s(a),r=(a-l+2*Math.PI)%(2*Math.PI),n*(r/(2*Math.PI))}(s,p,i,y));x-=Math.abs(G([h,{x:l,y:r},o])),a.push(h,o),n+=x}else a.push(h,o)}});let y=G(a);-1!==s.indexOf(t)&&(p=-1),r=y<0&&n<0?(Math.abs(n)-Math.abs(y))*p:(Math.abs(n)+Math.abs(y))*p,l+=r}),l}function G(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 K(e,t=0){t=parseFloat(t);let l=e.length,a=t>1,n=!a&&!t,r="",s=a?"\n":n?"":" ",p=n?"":" ";r=`${e[0].type}${p}${e[0].values.join(" ")}${s}`;for(let t=1;t<l;t++){let l=e[t-1],a=e[t],{type:i,values:y}=a;if(!n||"A"!==i&&"a"!==i||(y=[y[0],y[1],y[2],`${y[3]}${y[4]}${y[5]}`,y[6]]),i=n&&l.type===a.type&&"m"!==a.type.toLowerCase()||n&&"M"===l.type&&"L"===a.type?" ":a.type,n){let e="",t=!1;for(let l=0,a=y.length;l<a;l++){let a=y[l],n=a.toString(),r=n.includes(".")&&Math.abs(a)<1;r&&t&&(n=n.replace(/^0\./,".")),!(l>0)||t&&r||(e+=" "),e+=n,t=r}r+=`${i}${p}${e}${s}`}else r+=`${i}${p}${y.join(" ")}${s}`}return n&&(r=r.replace(/ 0\./g," .").replace(/ -/g,"-").replace(/-0\./g,"-.").replace(/Z/g,"z")),r}function X(e,t,l=0,a=1,n=!1){const r=(e,t,l,a,n)=>{let r=1-n;return{x:3*r*r*(t.x-e.x)+6*r*n*(l.x-t.x)+3*n*n*(a.x-l.x),y:3*r*r*(t.y-e.y)+6*r*n*(l.y-t.y)+3*n*n*(a.y-l.y)}};let s=[e,t],p=Z(e.p0,e.p)>Z(t.p0,t.p),i=JSON.parse(JSON.stringify(e)),y=JSON.parse(JSON.stringify(t)),u=C(i.p0,i.cp1,y.p,y.cp2,!1);if(!u)return s;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 h=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),o=(e,t)=>({x:e.x*t,y:e.y*t}),x=(e,t)=>e.x*t.x+e.y*t.y,c=t.p0,f=r(t.p0,t.cp1,t.cp2,t.p,0),g=x(h(e.p0,c),f)/x(f,f),d=w([t.p0,t.cp1,t.cp2,t.p],g),M=r(t.p0,t.cp1,t.cp2,t.p,g);g-=x(h(d,e.p0),M)/x(M,M);let v=w([t.p0,t.cp1,t.cp2,t.p],g),m=t.p,b=r(t.p0,t.cp1,t.cp2,t.p,g),A=r(t.p0,t.cp1,t.cp2,t.p,1),P=1-g,S=(E=v,I=o(b,P/3),{x:E.x+I.x,y:E.y+I.y});var E,I;let k=h(m,o(A,P/3)),D={p0:v,cp1:S,cp2:k,p:m,t0:g};p&&(D={p0:m,cp1:k,cp2:S,p:v,t0:g});let $=.5*(1-g),Q=w([D.p0,D.cp1,D.cp2,D.p],$,!1,!0),q=Q.cpts[2],z=C(Q,q,D.p0,u,!1),T=C(Q,q,D.p,u,!1),F=L(D.p0,z,1.333),j=L(D.p,T,1.333);if(C(i.p0,F,y.p,j,!0))return s;D.cp1=F,D.cp2=j;let R=Z(i.p0,D.p0)+Z(y.p,D.p);if(D.p0=i.p0,D.p=y.p,D.extreme=y.extreme,D.corner=y.corner,D.dimA=y.dimA,D.directionChange=y.directionChange,D.type="C",D.values=[D.cp1.x,D.cp1.y,D.cp2.x,D.cp2.y,D.p.x,D.p.y],R<l){let t=p?1+g:Math.abs(g),r=1+Math.abs(g);if(t=p?1+g:Math.abs(g)/r,Z(w([D.p0,D.cp1,D.cp2,D.p],t),e.p)>l*a)return s;let u=W([{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:[y.cp1.x,y.cp1.y,y.cp2.x,y.cp2.y,y.p.x,y.p.y]}]),h=[{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=W(h),x=Math.abs(o/u-1);D.error=5*x*a,n&&K(h),x<.05*a&&(s=[D])}return s}function Y(e,{keepExtremes:t=!0,keepInflections:l=!0,keepCorners:a=!0,extrapolateDominant:n=!0,tolerance:r=1}={}){let s=[e[0]],p=e.length;for(let n=2;p&&n<=p;n++){let i=e[n-1],y=n<p?e[n]:null,u=y?.type||null,{type:h,values:o,p0:x,p:c,cp1:f=null,cp2:g=null,extreme:d=!1,directionChange:M=!1,corner:v=!1,dimA:m=0}=i;if("C"===h&&"C"===u)if(a&&v||t&&d)s.push(i);else{let u=_(i,y,{tolerance:r}),h=0;
|
|
2
|
-
//!count simplification success or failure - just for debugging
|
|
3
|
-
if(1===u.length){i=u[0];let y=1;h+=i.error;
|
|
4
|
-
//!log.push(`success1: ${i} and ${i + 1}`)
|
|
5
|
-
for(let s=n+1;h<r&&s<p;s++){let n=e[s];if("C"!==n.type||l&&i.directionChange||a&&i.corner||t&&i.extreme)break;let p=_(i,n,{tolerance:r});if(p.length>1)break;h+=.5*p[0].error,y++,
|
|
6
|
-
//!log.push(`success2: ${i} and ${n}`)
|
|
7
|
-
i=p[0]}s.push(i),n<p&&(n+=y)}else s.push(i)}else s.push(i)}return s}function _(e,t,{tolerance:l=1}={}){let a=[e,t],n=function(e,t){let l=R(e.cp2,e.p);if(0===l)return 0;let a=R(e.p,t.cp1);if(0===a)return 0;let n=R(e.cp2,t.cp1);return l/n}(e,t);if(!n)return a;let r=R(e.p0,e.p),s=R(t.p0,t.p),p=.08*Math.max(0,Math.min(r,s))*l,i=function(e,t,l=0){let{p0:a,cp1:n}=e,{p:r,cp2:s}=t;return n={x:(n.x-(1-l)*a.x)/l,y:(n.y-(1-l)*a.y)/l},s={x:(s.x-l*r.x)/(1-l),y:(s.y-l*r.y)/(1-l)},{p0:a,cp1:n,cp2:s,p:r}}(e,t,n),y=w([i.p0,i.cp1,i.cp2,i.p],n),u=R(e.p,y),h=0,o=0,x=!1,c=u;if(u<p){let l=.5*(1+n);if(h=R(w([t.p0,t.cp1,t.cp2,t.p],.5),w([i.p0,i.cp1,i.cp2,i.p],l)),c+=h,h<p){let t=.5*n;o=R(w([e.p0,e.cp1,e.cp2,e.p],.5),w([i.p0,i.cp1,i.cp2,i.p],t)),c+=o,c<p&&(x=!0)}}return x&&(i.p0=e.p0,i.p=t.p,i.dimA=R(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=c/p,a=[i]),a}function ee(e,{tolerance:t=1,debug:l=!1}={}){let a=!1,n={flat:!0,steepness:0},r=e[0],s=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 y=j(r,s),u=y/1e3*t,h=G(e,!0);return h<u&&(a=!0),l&&(n.flat=a,n.steepness=h/y*10),l?n:a}function te(e=0,t=3){if(!t)return Math.round(e);let l=10**t;return Math.round(e*l)/l}function le(e,t=-1){if(t<0)return e;let l=e.length;for(let a=0;a<l;a++){let l=e[a].values,n=l.length;if(n)for(let r=0;r<n;r++)e[a].values[r]=te(l[r],t)}return e}function ae(t=[],{detectExtremes:l=!0,detectCorners:a=!0,detectDirection:n=!0,detectSemiExtremes:r=!1,debug:s=!1,addSquareLength:p=!0,addArea:i=!0}={}){t=function(e,{addSquareLength:t=!0,addArea:l=!1,addArcParams:a=!1,addAverageDim:n=!0}={}){let r=e[0],s={x:r.values[0],y:r.values[1]},p=s,i=s;r.p0=p,r.p=i,r.idx=0,r.dimA=0;let y=e.length,u=[r];for(let a=1;a<y;a++){let n,r,y=e[a],{type:h,values:o}=y,x=o.length;if(i=x?{x:o[x-2],y:o[x-1]}:s,y.p0=p,y.p=i,y.dimA=R(p,i),"M"===h&&(s=i),"Q"===h||"C"===h)n={x:o[0],y:o[1]},r="C"===h?{x:o[2],y:o[3]}:null,y.cp1=n,r&&(y.cp2=r);else if("A"===h){let{rx:e,ry:t,cx:l,cy:a,startAngle:n,endAngle:r,deltaAngle:s}=P(p.x,p.y,...o);y.cx=l,y.cy=a,y.rx=e,y.ry=t,y.xAxisRotation=o[2]/180*Math.PI,y.largeArc=o[3],y.sweep=o[4],y.startAngle=n,y.endAngle=r,y.deltaAngle=s}if("Z"===h&&s.x!==i.x&&s.y!==i.y&&(y.closePath=!0),t&&(y.squareDist=j(p,i)),l){let e=0;"C"===h&&(e=G([p,n,r,i],!1)),"Q"===h&&(e=G([p,n,i],!1)),y.cptArea=e}y.idx=a,p=i,u.push(y)}return u}(t,{addSquareLength:p,addArea:i});let y=[],u=function(e){let t=[],l={x:e[0].values[0],y:e[0].values[1]};return e.forEach(e=>{let{type:a,values:n}=e;if(n.length){let e=n.length>1?{x:n[n.length-2],y:n[n.length-1]}:"V"===a?{x:l.x,y:n[0]}:{x:n[0],y:l.y};t.push(e),l=e}}),t}(t),h=J(u),{left:o,right:x,top:c,bottom:f,width:g,height:d}=h;t[0].corner=!1,t[0].extreme=!1,t[0].semiExtreme=!1,t[0].directionChange=!1,t[0].closePath=!1;let M=[t[0]],v=t.length;for(let l=2;v&&l<=v;l++){let a=t[l-1],{type:n,values:p,p0:i,p:y,cp1:u=null,cp2:h=null,squareDist:g=0,cptArea:d=0,dimA:v=0}=a,m=t[l]||null;a.corner=!1,a.extreme=!1,a.semiExtreme=!1,a.directionChange=!1,a.closePath=!1;let A="C"===n||"Q"===n?"C"===n?[i,u,h,y]:[i,u,y]:[i,y],C=.1*v,L=.01*C,w="Q"===n||"C"===n,P=m&&("Q"===m.type||"C"===m.type),S=!1;
|
|
1
|
+
function e(e,t,a="red",l="1%",n="1",r="",s=!0,p="",u=""){Array.isArray(t)&&(t={x:t[0],y:t[1]});let i=`<circle class="${u}" opacity="${n}" id="${p}" cx="${t.x}" cy="${t.y}" r="${l}" fill="${a}">\n <title>${r}</title></circle>`;if(!s)return i;e.insertAdjacentHTML("beforeend",i)}function t(e,t="",a="green",l="1%",n="1",r=!0){let s=`<path d="${t}" fill="none" stroke="${a}" stroke-width="${l}" stroke-opacity="${n}" /> `;if(!r)return s;e.insertAdjacentHTML("beforeend",s)}const{abs:a,acos:l,asin:n,atan:r,atan2:s,ceil:p,cos:u,exp:i,floor:y,log:h,max:o,min:x,pow:c,random:f,round:g,sin:d,sqrt:M,tan:v,PI:m}=Math;function b(e,t,a=!1){let l=s(t.y-e.y,t.x-e.x);return a&&l<0&&(l+=2*Math.PI),l}function A(e,t,a,l=!1){let n=Math.atan2(t.y-e.y,t.x-e.x),r=Math.atan2(a.y-e.y,a.x-e.x),s=r-n;s=(e=>{let t=e%(2*Math.PI);return t>Math.PI?t-=2*Math.PI:t<=-Math.PI&&(t+=2*Math.PI),t})(s),l&&(s=2*Math.PI-Math.abs(s));let p=180/Math.PI;return{startAngle:n,endAngle:r,deltaAngle:s,startAngleDeg:n*p,endAngleDeg:r*p,deltaAngleDeg:s*p}}function C(e=null,t=null,a=null,l=null,n=!0,r=!1,s=!1){let p,u,i,y,h,o={};if(!(e&&t&&a&&l))return s&&console.warn("points missing"),!1;if(e.x===t.x&&e.y===t.y||a.x===l.x&&a.y===l.y)return!1;try{if(p=(l.y-a.y)*(t.x-e.x)-(l.x-a.x)*(t.y-e.y),0===p)return!1}catch{return s&&console.warn("!catch",e,t,"p3:",a,"p4:",l),!1}u=e.y-a.y,i=e.x-a.x,y=(l.x-a.x)*u-(l.y-a.y)*i,h=(t.x-e.x)*u-(t.y-e.y)*i,u=y/p,i=h/p,o={x:e.x+u*(t.x-e.x),y:e.y+u*(t.y-e.y)};let x=!1;return u>0&&u<1&&i>0&&i<1&&(x=!0),!n&&r&&(u>0&&i<0||u<0&&i>0)?(x=!1,!1):!(n&&!x)&&o}function L(e,t,a,l=!1){let n={x:(t.x-e.x)*a+e.x,y:(t.y-e.y)*a+e.y};return l&&(n.angle=b(e,t),n.angle<0&&(n.angle+=2*m)),n}function w(e,t=.5,a=!1,l=!1,n=!1){let r;return Array.isArray(e[0])&&(e=e.map(e=>({x:e[0],y:e[1]})),n=!0),r=e.length>2?((e,t,a=!1)=>{let n=4===e.length,r=e[0],s=e[1],p=n?e[2]:e[1],u=e[e.length-1],i={x:0,y:0};if(a||l){let e,a,y,h,o,x=r.x===s.x&&r.y===s.y,c=u.x===p.x&&u.y===p.y;0!==t||x?1!==t||c?(x&&(t+=1e-7),c&&(t-=1e-7),e=L(r,s,t),n?(a=L(s,p,t),y=L(p,u,t),h=L(e,a,t),o=L(a,y,t),i=L(h,o,t),i.angle=b(h,o),l&&(i.cpts=[a,y,h,o])):(a=L(r,s,t),y=L(s,u,t),i=L(a,y,t),i.angle=b(a,y),l&&(i.cpts=[a,y]))):(i.x=u.x,i.y=u.y,i.angle=b(p,u)):(i.x=r.x,i.y=r.y,i.angle=b(r,s))}else{let e=1-t;i=n?{x:e**3*r.x+3*e**2*t*s.x+3*e*t**2*p.x+t**3*u.x,y:e**3*r.y+3*e**2*t*s.y+3*e*t**2*p.y+t**3*u.y}:{x:e*e*r.x+2*e*t*s.x+t**2*u.x,y:e*e*r.y+2*e*t*s.y+t**2*u.y}}return i})(e,t,a):L(e[0],e[1],t,a),a&&r.angle<0&&(r.angle+=2*m),n?[r.x,r.y]:r}function P(e,t,l,n,r,p,u,i,y){const h=(e,t,a,l)=>s(l-t,a-e);let o={cx:0,cy:0,rx:l=a(l),ry:n=a(n),startAngle:0,endAngle:0,deltaAngle:0,clockwise:u,xAxisRotation:r,largeArc:p,sweep:u};if(0==l||0==n)throw Error("rx and ry can not be 0");if(l===n){let a=Math.abs(i-e),l=Math.abs(y-t),n=a,r=Math.min(e,i),s=Math.min(t,y),p=.5*Math.PI;if(0===a&&l||0===l&&a)return n=0===a&&l?l/2:a/2,o.rx=n,o.ry=n,0===a&&l?(o.cx=e,o.cy=s+l/2,o.startAngle=t>y?p:-p,o.endAngle=t>y?-p:p,o.deltaAngle=u?Math.PI:-Math.PI):0===l&&a&&(o.cx=r+a/2,o.cy=t,o.startAngle=e>i?Math.PI:0,o.endAngle=e>i?-Math.PI:Math.PI,o.deltaAngle=u?Math.PI:-Math.PI),o}let x,c,f=l===n?0:r*m/180,g=f?Math.sin(f):0,d=f?Math.cos(f):1,M=(e-i)/2,v=(t-y)/2,b=(e+i)/2,A=(t+y)/2,C=f?d*M+g*v:M,L=f?d*v-g*M:v,w=C*C/(l*l)+L*L/(n*n);w>1&&(l*=Math.sqrt(w),n*=Math.sqrt(w),o.rx=l,o.ry=n);let P=l*n,E=l*L,S=n*C,I=E**2+S**2;if(!I)throw Error("start point can not be same as end point");let k=Math.sqrt(Math.abs((P*P-I)/I));p==u&&(k=-k);let D=k*E/n,$=-k*S/l;x=f?d*D-g*$+b:b+D,c=f?g*D+d*$+A:A+$,o.cy=c,o.cx=x;let Q=h(x,c,e,t),T=h(x,c,i,y);!u&&T>Q&&(T-=2*Math.PI),u&&Q>T&&(T=T<=0?T+2*Math.PI:T);let z=T-Q;return o.startAngle=Q,o.endAngle=T,o.deltaAngle=z,o}function E(e,t,a,l=0,n=!1){return l?(l=n?l/180*Math.PI:l,{x:t+(e.x-t)*Math.cos(l)-(e.y-a)*Math.sin(l),y:a+(e.x-t)*Math.sin(l)+(e.y-a)*Math.cos(l)}):e}function S(e,t,a,l,n,s=0,p=!0,i=!1){if(n=i?n*m/180:n,s=i?s*m/180:s,s=a!==l&&s!==2*m?s:0,p&&a!==l){let e=r(v(n=s?n-s:n)*(a/l));n=u(n)<0?e+m:e}let y=e+a*u(n),h=t+l*d(n),o={x:y,y:h};return s&&(o.x=e+(y-e)*u(s)-(h-t)*d(s),o.y=t+(y-e)*d(s)+(h-t)*u(s)),o}function I(e,t,a){if(t===a||e%m*.5==0)return e;let l=r(v(e)*(t/a));return l=u(e)<0?l+m:l,l}function k(e=null,t=[]){e||(e=t[0],t=t.slice(1,t.length));let a=t.length,l=t[a-1],n=t[0],r=3===a?t[1]:n,s=Math.min(e.y,l.y),p=Math.min(e.x,l.x),u=Math.max(e.x,l.x),i=Math.max(e.y,l.y);return!(n.y>=s&&n.y<=i&&r.y>=s&&r.y<=i&&n.x>=p&&n.x<=u&&r.x>=p&&r.x<=u)}function D(e,{addExtremes:t=!0,addSemiExtremes:a=!1}={}){let l=4===e.length?function(e,t,a,l,{addExtremes:n=!0,addSemiExtremes:r=!1}={}){const s=e=>{const t=Math.PI/4,a=Math.cos(t),l=Math.sin(t);return{x:e.x*a-e.y*l,y:e.x*l+e.y*a}};r&&(e=s(e),t=s(t),a=s(a),l=s(l));let[p,u,i,y,h,o,x,c]=[e.x,e.y,t.x,t.y,a.x,a.y,l.x,l.y],f=Math.min(e.y,l.y),g=Math.min(e.x,l.x),d=Math.max(e.x,l.x),M=Math.max(e.y,l.y);if(t.y>=f&&t.y<=M&&a.y>=f&&a.y<=M&&t.x>=g&&t.x<=d&&a.x>=g&&a.x<=d)return[];let v,m,b,A,C,L,w,P,E=[];for(let e=0;e<2;++e)if(0==e?(m=6*p-12*i+6*h,v=-3*p+9*i-9*h+3*x,b=3*i-3*p):(m=6*u-12*y+6*o,v=-3*u+9*y-9*o+3*c,b=3*y-3*u),Math.abs(v)<1e-8){if(Math.abs(m)<1e-8)continue;A=-b/m,0<A&&A<1&&E.push(A)}else w=m*m-4*b*v,w<0?Math.abs(w)<1e-8&&(A=-m/(2*v),0<A&&A<1&&E.push(A)):(P=Math.sqrt(w),C=(-m+P)/(2*v),0<C&&C<1&&E.push(C),L=(-m-P)/(2*v),0<L&&L<1&&E.push(L));let S=E.length;for(;S--;)A=E[S];return E}(e[0],e[1],e[2],e[3],{addExtremes:t,addSemiExtremes:a}):function(e,t,a,{addExtremes:l=!0,addSemiExtremes:n=!1}={}){const r=e=>{const t=-Math.PI/4,a=Math.cos(t),l=Math.sin(t);return{x:e.x*a-e.y*l,y:e.x*l+e.y*a}};n&&(e=r(e),t=r(t),a=r(a));let s,p,u,i=Math.min(e.y,a.y),y=Math.min(e.x,a.x),h=Math.max(e.x,a.x),o=Math.max(e.y,a.y);if(t.y>=i&&t.y<=o&&t.x>=y&&t.x<=h)return[];let[x,c,f,g,d,M]=[e.x,e.y,t.x,t.y,a.x,a.y],v=[];for(let e=0;e<2;++e)s=0==e?x-2*f+d:c-2*g+M,p=0==e?-2*x+2*f:-2*c+2*g,Math.abs(s)>1e-12&&(u=-p/(2*s),u>0&&u<1&&v.push(u));return v}(e[0],e[1],e[2],{addExtremes:t,addSemiExtremes:a});return l}function $(e,t){const a=(e,t,a,l,n,r)=>{var s=Math.cos(r),p=Math.sin(r),u=l*Math.cos(e),i=n*Math.sin(e);return{x:t+s*u-p*i,y:a+p*u+s*i}};let l,n,r,s,p,u=P(e.x,e.y,t[0],t[1],t[2],t[3],t[4],t[5],t[6]),{rx:i,ry:y,cx:h,cy:o,endAngle:x,deltaAngle:c}=u,f=t[2],g={x:t[5],y:t[6]},d=[g],M=f*Math.PI/180,v=Math.tan(M);p=Math.atan2(-y*v,i);let m=p,b=p+Math.PI,A=Math.atan2(y,i*v),C=A+Math.PI,L=[e.x,g.x],w=[e.y,g.y],E=Math.min(...L),S=Math.max(...L),I=Math.min(...w),k=Math.max(...w),D=a(x-.001*c,h,o,i,y,M),$=a(x-.999*c,h,o,i,y,M);return(D.x>S||$.x>S)&&(l=a(m,h,o,i,y,M),d.push(l)),(D.x<E||$.x<E)&&(n=a(b,h,o,i,y,M),d.push(n)),(D.y<I||$.y<I)&&(s=a(C,h,o,i,y,M),d.push(s)),(D.y>k||$.y>k)&&(r=a(A,h,o,i,y,M),d.push(r)),d}function Q(e=[],t=[]){let a=e.length,l=4===a;t.length||(t=[0]);let n=t.length,r=[];for(let s=0;s<n;s++){let n=t[s],p=n?[]:e.slice(0);if(n)for(let t=0;t<a;t++){let a=e[t];p.push(E(a,0,0,n))}let u=l?T(...p):z(...p);r.push(...u)}return r=[...new Set(r)].sort(),r}function T(e,t,a,l){if(!k(e,[t,a,l]))return[];let n,r,s,p,u,i,y,h,[o,x,c,f,g,d,M,v]=[e.x,e.y,t.x,t.y,a.x,a.y,l.x,l.y],m=[],b=1e-8;for(let e=0;e<2;++e)if(0==e?(r=6*o-12*c+6*g,n=-3*o+9*c-9*g+3*M,s=3*c-3*o):(r=6*x-12*f+6*d,n=-3*x+9*f-9*d+3*v,s=3*f-3*x),Math.abs(n)<b){if(Math.abs(r)<b)continue;p=-s/r,p>0&&p<1&&m.push(p)}else y=r*r-4*s*n,y<0?Math.abs(y)<b&&(p=-r/(2*n),p>0&&p<1&&m.push(p)):(h=Math.sqrt(y),u=(-r+h)/(2*n),u>0&&u<1&&m.push(u),i=(-r-h)/(2*n),i>0&&i<1&&m.push(i));let A=m.length;for(;A--;)p=m[A];return[...new Set(m)].sort()}function z(e,t,a){if(!k(e,[t,a]))return[];let l,n,r,[s,p,u,i,y,h]=[e.x,e.y,t.x,t.y,a.x,a.y],o=[];for(let e=0;e<2;++e)l=0==e?s-2*u+y:p-2*i+h,n=0==e?-2*s+2*u:-2*p+2*i,Math.abs(l)>1e-12&&(r=-n/(2*l),r>0&&r<1&&o.push(r));return[...new Set(o)].sort()}function q(e,t=.001){let a=Math.PI/2,l=a/2;return!(Math.abs(e/a-Math.round(e/a))<t)&&Math.abs(e/l-Math.round(e/l))<t}function F(e,t,a=!1){let l=a?t[0]-e[0]:t.x-e.x,n=a?t[1]-e[1]:t.y-e.y;return M(l*l+n*n)}function j(e,t){let a=t.x-e.x,l=t.y-e.y;return a*a+l*l}function R(e,t){return Math.abs(t.x-e.x)+Math.abs(t.y-e.y)}function Z(e,t){return.5*(Math.abs(t.x-e.x)+Math.abs(t.y-e.y))}function O(e){let t=[],a=[e[0]],l=e.length;for(let n=1;n<l;n++){let l=e[n];"M"!==l.type&&"m"!==l.type||(t.push(a),a=[]),a.push(l)}return a.length&&t.push(a),t}function B(e,t){let a,l,n,r,s,p,u=[],i=[],y=e[0],h=e[1],o=e[e.length-2],x=e[e.length-1];return 4===e.length?(a=w([y,h],t),l=w([h,o],t),n=w([o,x],t),r=w([a,l],t),s=w([l,n],t),p=w([r,s],t),u.push({x:y.x,y:y.y},{x:a.x,y:a.y},{x:r.x,y:r.y},{x:p.x,y:p.y}),i.push({x:p.x,y:p.y},{x:s.x,y:s.y},{x:n.x,y:n.y},{x:x.x,y:x.y})):3===e.length?(l=w([y,h],t),n=w([h,x],t),p=w([l,n],t),u.push({x:y.x,y:y.y},{x:l.x,y:l.y},{x:p.x,y:p.y}),i.push({x:p.x,y:p.y},{x:n.x,y:n.y},{x:x.x,y:x.y})):2===e.length&&(l=w([y,x],t),u.push({x:y.x,y:y.y},{x:l.x,y:l.y}),i.push({x:l.x,y:l.y},{x:x.x,y:x.y})),[u,i]}function N(e,t,{tMin:a=0,tMax:l=1,addExtremes:n=!0,addSemiExtremes:r=!1}={}){let s=[],p=6===t.length?"C":"Q",u={x:t[0],y:t[1]},i="C"===p?{x:t[2],y:t[3]}:u,y={x:t[4],y:t[5]},h=0;let o="C"===p?[e,u,i,y]:[e,u,y],x=n?D(o,{addExtremes:n,addSemiExtremes:!1}):[],c=r?D(o,{addExtremes:n,addSemiExtremes:r}):[],f=Array.from(new Set([...x,...c])).sort();if(f=f.filter(e=>e>0&&e<1),f.length){let a=function(e,t,a,l=!0){let n=[];if(!a.length)return!1;let r,s,p,u=t.length,i={x:t[u-2],y:t[u-1]};2===t.length?p=[e,i]:4===t.length?(r={x:t[0],y:t[1]},p=[e,r,i]):6===t.length&&(r={x:t[0],y:t[1]},s={x:t[2],y:t[3]},p=[e,r,s,i]);if(a.length)if(1===a.length){let e=B(p,a[0]),t=e[0],l=e[1];n.push(t,l)}else{let e=a[0],t=B(p,e),l=t[0];n.push(l),p=t[1];for(let t=1;t<a.length;t++){e=a[t-1];let l=B(p,(a[t]-e)/(1-e));n.push(l[0]),t===a.length-1&&n.push(l[l.length-1]),p=l[1]}}if(l){let e,t,a=[];return n.forEach(l=>{e={type:"",values:[]},l.shift(),t=l.map(e=>Object.values(e)).flat(),e.values=t,3===l.length?e.type="C":2===l.length?e.type="Q":1===l.length&&(e.type="L"),a.push(e)}),a}return n}(e,t,f);s.push(...a),h+=a.length}else s.push({type:p,values:t});return{pathData:s,count:h}}function H(e,{tMin:t=0,tMax:a=1,addExtremes:l=!0,addSemiExtremes:n=!1}={}){let r=[e[0]],s={x:e[0].values[0],y:e[0].values[1]},p={x:e[0].values[0],y:e[0].values[1]},u=e.length;for(let i=1;u&&i<u;i++){let u=e[i],{type:y,values:h}=u,o=h.slice(-2);if(o[0],o[1],"C"!==y&&"Q"!==y)r.push(u);else if((l||n)&&("C"===y||"Q"===y)){let e=N(s,h,{tMin:t,tMax:a,addExtremes:l,addSemiExtremes:n}).pathData;r.push(...e)}s={x:o[0],y:o[1]},"z"===y.toLowerCase()?s=p:"M"===y&&(p={x:o[0],y:o[1]})}return r}function J(e=0,t=3){if(!t)return Math.round(e);let a=10**t;return Math.round(e*a)/a}function U(e,t=-1){if(t<0)return e;let a=e.length,l=t;for(let t=0;t<a;t++){let a=e[t],{values:n}=a,r=n.length;if(r)for(let a=0;a<r;a++)e[t].values[a]=J(n[a],l)}return e}function V(e,t=-1){let a=e.map(e=>e.x),l=e.map(e=>e.y),n=Math.min(...a),r=Math.max(...a),s=Math.min(...l),p=Math.max(...l),u={x:n,left:n,right:r,y:s,top:s,bottom:p,width:r-n,height:p-s};if(t>-1)for(let e in u)u[e]=+u[e].toFixed(t);return u}function W(e){let t=[];return e.forEach(e=>{let a=function(e){let t=function(e){let t=[];for(let a=0;a<e.length;a++){let l=e[a],n=a>0?e[a-1]:e[a],{type:r,values:s}=l,p={x:n.values[n.values.length-2],y:n.values[n.values.length-1]},u=s.length?{x:s[s.length-2],y:s[s.length-1]}:"",i=s.length?{x:s[0],y:s[1]}:"";switch(r){case"A":if("function"!=typeof arcToBezier){let e=F(p,u)/2,a=L(p,u,.5),l=S(a.x,a.y,e,e,0),n=S(a.x,a.y,e,e,Math.PI);t.push(l,n,u);break}arcToBezier(p,s).forEach(e=>{let a=e.values,l={x:a[0],y:a[1]},n={x:a[2],y:a[3]},r={x:a[4],y:a[5]};t.push(l,n,r)});break;case"C":let e={x:s[2],y:s[3]};t.push(i,e);break;case"Q":t.push(i)}"z"!==r.toLowerCase()&&t.push(u)}return t}(e),a=V(t);return a}(e);t.push(a)}),t}function G(e,t){let[a,l,n,r,s,p]=[e.x,e.y,e.width,e.height,e.x+e.width,e.y+e.height],[u,i,y,h,o,x]=[t.x,t.y,t.width,t.height,t.x+t.width,t.y+t.height],c=!1;return n*r!=y*h&&n*r>y*h&&a<u&&s>o&&l<i&&p>x&&(c=!0),c}function K(e,t=9){let a=0,l=[],n=O(e),r=n.length>1,s=[];if(r){let e=W(n);e.forEach(function(t,a){for(let a=0;a<e.length;a++){let l=e[a];if(t!=l){G(t,l)&&s.push(a)}}})}return n.forEach((e,t)=>{l=[];let n=0,r=0,p=1,u=[];e.forEach(function(t,a){let[r,s]=[t.type,t.values],p=s.length;if(s.length){let i=(a>0?e[a-1]:e[0]).values,y=i.length,h={x:i[y-2],y:i[y-1]},o={x:s[p-2],y:s[p-1]};if("C"===r||"Q"===r){let e={x:s[0],y:s[1]};u="C"===r?[h,e,{x:s[2],y:s[3]},o]:[h,e,o];let t=Math.abs(function(e,t=!1){let a,[l,n,r,s]=[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},r={x:1*e[2].x/3+2*e[1].x/3,y:1*e[2].y/3+2*e[1].y/3});return a=3*(l.x*(-2*n.y-r.y+3*s.y)+n.x*(2*l.y-r.y-s.y)+r.x*(l.y+n.y-2*s.y)+s.x*(-3*l.y+n.y+2*r.y))/20,t?Math.abs(a):a}(u));n+=t,l.push(h,o)}else if("A"===r){let e=P(h.x,h.y,t.values[0],t.values[1],t.values[2],t.values[3],t.values[4],o.x,o.y),{cx:a,cy:r,rx:s,ry:p,startAngle:u,endAngle:i,deltaAngle:y}=e,x=Math.abs(function(e,t,a,l){const n=Math.PI*e*t;let r=(l-a+2*Math.PI)%(2*Math.PI);if(e===t)return n*(r/(2*Math.PI));const s=a=>Math.atan2(e*Math.sin(a),t*Math.cos(a));return a=s(a),l=s(l),r=(l-a+2*Math.PI)%(2*Math.PI),n*(r/(2*Math.PI))}(s,p,u,i));x-=Math.abs(X([h,{x:a,y:r},o])),l.push(h,o),n+=x}else l.push(h,o)}});let i=X(l);-1!==s.indexOf(t)&&(p=-1),r=i<0&&n<0?(Math.abs(n)-Math.abs(i))*p:(Math.abs(n)+Math.abs(i))*p,a+=r}),a}function X(e,t=!1){let a=0,l=e.length;for(let t=0;l&&t<l;t++){a+=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&&(a=Math.abs(a)),a}function Y(e,t=0){t=parseFloat(t);let a=e.length,l=t>1,n=!l&&!t,r="",s=e[0].values.join(" "),p=l?"\n":n?"":" ",u=n?"":" ";r=`${e[0].type}${u}${s}${p}`;for(let t=1;t<a;t++){let a=e[t-1],l=e[t],{type:i,values:y}=l;if(s="",!n||"A"!==i&&"a"!==i||(y=[y[0],y[1],y[2],`${y[3]}${y[4]}${y[5]}`,y[6]]),i=n&&a.type===l.type&&"m"!==l.type.toLowerCase()||n&&"M"===a.type&&"L"===l.type?" ":l.type,n){let e=!1;for(let t=0,a=y.length;t<a;t++){let a=y[t],l=a.toString(),n=l.includes(".")&&Math.abs(a)<1;n&&e&&(l=l.replace(/^0\./,".")),!(t>0)||e&&n||(s+=" "),s+=l,e=n}r+=`${i}${u}${s}${p}`}else r+=`${i}${u}${y.join(" ")}${p}`}return n&&(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 _(e,t,a=0,l=1,n=!1){const r=(e,t,a,l,n)=>{let r=1-n;return{x:3*r*r*(t.x-e.x)+6*r*n*(a.x-t.x)+3*n*n*(l.x-a.x),y:3*r*r*(t.y-e.y)+6*r*n*(a.y-t.y)+3*n*n*(l.y-a.y)}};let s=[e,t],p=Z(e.p0,e.p)>Z(t.p0,t.p),u=JSON.parse(JSON.stringify(e)),i=JSON.parse(JSON.stringify(t)),y=C(u.p0,u.cp1,i.p,i.cp2,!1);if(!y)return s;if(p){let a={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=a}let h=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),o=(e,t)=>({x:e.x*t,y:e.y*t}),x=(e,t)=>e.x*t.x+e.y*t.y,c=t.p0,f=r(t.p0,t.cp1,t.cp2,t.p,0),g=x(h(e.p0,c),f)/x(f,f),d=w([t.p0,t.cp1,t.cp2,t.p],g),M=r(t.p0,t.cp1,t.cp2,t.p,g);g-=x(h(d,e.p0),M)/x(M,M);let v=w([t.p0,t.cp1,t.cp2,t.p],g),m=t.p,b=r(t.p0,t.cp1,t.cp2,t.p,g),A=r(t.p0,t.cp1,t.cp2,t.p,1),P=1-g,E=(S=v,I=o(b,P/3),{x:S.x+I.x,y:S.y+I.y});var S,I;let k=h(m,o(A,P/3)),D={p0:v,cp1:E,cp2:k,p:m,t0:g};p&&(D={p0:m,cp1:k,cp2:E,p:v,t0:g});let $=.5*(1-g),Q=w([D.p0,D.cp1,D.cp2,D.p],$,!1,!0),T=Q.cpts[2],z=C(Q,T,D.p0,y,!1),q=C(Q,T,D.p,y,!1),F=L(D.p0,z,1.333),j=L(D.p,q,1.333);if(C(u.p0,F,i.p,j,!0))return s;D.cp1=F,D.cp2=j;let R=Z(u.p0,D.p0)+Z(i.p,D.p);if(D.p0=u.p0,D.p=i.p,D.extreme=i.extreme,D.corner=i.corner,D.dimA=i.dimA,D.directionChange=i.directionChange,D.type="C",D.values=[D.cp1.x,D.cp1.y,D.cp2.x,D.cp2.y,D.p.x,D.p.y],R<a){let t=p?1+g:Math.abs(g),r=1+Math.abs(g);if(t=p?1+g:Math.abs(g)/r,Z(w([D.p0,D.cp1,D.cp2,D.p],t),e.p)>a*l)return s;let y=K([{type:"M",values:[u.p0.x,u.p0.y]},{type:"C",values:[u.cp1.x,u.cp1.y,u.cp2.x,u.cp2.y,u.p.x,u.p.y]},{type:"C",values:[i.cp1.x,i.cp1.y,i.cp2.x,i.cp2.y,i.p.x,i.p.y]}]),h=[{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=K(h),x=Math.abs(o/y-1);D.error=5*x*l,n&&Y(h),x<.05*l&&(s=[D])}return s}function ee(e,{keepExtremes:t=!0,keepInflections:a=!0,keepCorners:l=!0,extrapolateDominant:n=!0,tolerance:r=1}={}){let s=[e[0]],p=e.length;for(let n=2;p&&n<=p;n++){let u=e[n-1],i=n<p?e[n]:null,y=i?.type||null,{type:h,values:o,p0:x,p:c,cp1:f=null,cp2:g=null,extreme:d=!1,directionChange:M=!1,corner:v=!1,dimA:m=0}=u;if("C"===h&&"C"===y)if(l&&v||t&&d)s.push(u);else{let y=te(u,i,{tolerance:r}),h=0;if(1===y.length){u=y[0];let i=1;h+=u.error;for(let s=n+1;h<r&&s<p;s++){let n=e[s];if("C"!==n.type||a&&u.directionChange||l&&u.corner||t&&u.extreme)break;let p=te(u,n,{tolerance:r});if(p.length>1)break;h+=.5*p[0].error,i++,u=p[0]}s.push(u),n<p&&(n+=i)}else s.push(u)}else s.push(u)}return s}function te(e,t,{tolerance:a=1}={}){let l=[e,t],n=function(e,t){let a=R(e.cp2,e.p);if(0===a)return 0;let l=R(e.p,t.cp1);if(0===l)return 0;let n=R(e.cp2,t.cp1);return a/n}(e,t);if(!n)return l;let r=R(e.p0,e.p),s=R(t.p0,t.p),p=.08*Math.max(0,Math.min(r,s))*a,u=function(e,t,a=0){let{p0:l,cp1:n}=e,{p:r,cp2:s}=t;return n={x:(n.x-(1-a)*l.x)/a,y:(n.y-(1-a)*l.y)/a},s={x:(s.x-a*r.x)/(1-a),y:(s.y-a*r.y)/(1-a)},{p0:l,cp1:n,cp2:s,p:r}}(e,t,n),i=w([u.p0,u.cp1,u.cp2,u.p],n),y=R(e.p,i),h=0,o=0,x=!1,c=y;if(y<p){let a=.5*(1+n);if(h=R(w([t.p0,t.cp1,t.cp2,t.p],.5),w([u.p0,u.cp1,u.cp2,u.p],a)),c+=h,h<p){let t=.5*n;o=R(w([e.p0,e.cp1,e.cp2,e.p],.5),w([u.p0,u.cp1,u.cp2,u.p],t)),c+=o,c<p&&(x=!0)}}return x&&(u.p0=e.p0,u.p=t.p,u.dimA=R(u.p0,u.p),u.type="C",u.extreme=t.extreme,u.directionChange=t.directionChange,u.corner=t.corner,u.values=[u.cp1.x,u.cp1.y,u.cp2.x,u.cp2.y,u.p.x,u.p.y],u.error=c/p,l=[u]),l}function ae(e,{tolerance:t=1,debug:a=!1}={}){let l=!1,n={flat:!0,steepness:0},r=e[0],s=e[e.length-1],p=new Set([...e.map(e=>+e.x.toFixed(8))]),u=new Set([...e.map(e=>+e.y.toFixed(8))]);if(1===p.size||1===u.size)return!a||n;let i=j(r,s),y=i/1e3*t,h=X(e,!0);return h<y&&(l=!0),a&&(n.flat=l,n.steepness=h/i*10),a?n:l}function le(t=[],{detectExtremes:a=!0,detectCorners:l=!0,detectDirection:n=!0,detectSemiExtremes:r=!1,debug:s=!1,addSquareLength:p=!0,addArea:u=!0}={}){t=function(e,{addSquareLength:t=!0,addArea:a=!1,addArcParams:l=!1,addAverageDim:n=!0}={}){let r=e[0],s={x:r.values[0],y:r.values[1]},p=s,u=s;r.p0=p,r.p=u,r.idx=0,r.dimA=0;let i=e.length,y=[r];for(let n=1;n<i;n++){let r,i,h=e[n],{type:o,values:x}=h,c=x.length;if(u=c?{x:x[c-2],y:x[c-1]}:s,h.p0=p,h.p=u,h.dimA=R(p,u),"M"===o&&(s=u),"Q"===o||"C"===o)r={x:x[0],y:x[1]},i="C"===o?{x:x[2],y:x[3]}:null,h.cp1=r,i&&(h.cp2=i);else if("A"===o&&l){let{rx:e,ry:t,cx:a,cy:l,startAngle:n,endAngle:r,deltaAngle:s}=P(p.x,p.y,...x);h.cx=a,h.cy=l,h.rx=e,h.ry=t,h.xAxisRotation=x[2]/180*Math.PI,h.largeArc=x[3],h.sweep=x[4],h.startAngle=n,h.endAngle=r,h.deltaAngle=s}if("Z"===o&&s.x!==u.x&&s.y!==u.y&&(h.closePath=!0),t&&(h.squareDist=j(p,u)),a){let e=0;"C"===o&&(e=X([p,r,i,u],!1)),"Q"===o&&(e=X([p,r,u],!1)),h.cptArea=e}h.idx=n,p=u,y.push(h)}return y}(t,{addSquareLength:p,addArea:u});let i=[],y=function(e){let t=[],a={x:e[0].values[0],y:e[0].values[1]};return e.forEach(e=>{let{type:l,values:n}=e;if(n.length){let e=n.length>1?{x:n[n.length-2],y:n[n.length-1]}:"V"===l?{x:a.x,y:n[0]}:{x:n[0],y:a.y};t.push(e),a=e}}),t}(t),h=V(y),{left:o,right:x,top:c,bottom:f,width:g,height:d}=h;t[0].corner=!1,t[0].extreme=!1,t[0].semiExtreme=!1,t[0].directionChange=!1,t[0].closePath=!1;let M=[t[0]],v=t.length;for(let e=2;v&&e<=v;e++){let a=t[e-1],{type:l,values:n,p0:s,p:p,cp1:u=null,cp2:i=null,squareDist:y=0,cptArea:h=0,dimA:g=0}=a,d=t[e]||null;a.corner=!1,a.extreme=!1,a.semiExtreme=!1,a.directionChange=!1,a.closePath=!1;let v="C"===l||"Q"===l?"C"===l?[s,u,i,p]:[s,u,p]:[s,p],m=.1*g,A=.01*m,C="Q"===l||"C"===l,L=d&&("Q"===d.type||"C"===d.type),w=!1;
|
|
8
2
|
//!isFlat &&
|
|
9
|
-
if(w){let e="C"===n?Math.abs(a.cp2.x-a.p.x):Math.abs(a.cp1.x-a.p.x),t="C"===n?Math.abs(a.cp2.y-a.p.y):Math.abs(a.cp1.y-a.p.y);if(((0===t||t<L)&&e>0||(0===e||e<L)&&t>0)&&(S=!0),y.x!==o&&y.y!==c&&y.x!==x&&y.y!==f||(S=!0),!S){if(k(null,A)){let e=Q(A);e.length&&e[0]>.2&&(S=!0)}}}if(S&&(a.extreme=!0),w&&P){if(r&&!a.extreme){let e=Math.abs(y.x-h.x),t=Math.abs(y.y-h.y),l=!1;if(e&&t&&e>C||t>C){let e=b(h,y),t=b(y,m.cp1);l=T(Math.abs(e+t)/2)}l&&(a.semiExtreme=!0)}if((a.cptArea<0&&m.cptArea>0||a.cptArea>0&&m.cptArea<0)&&(a.directionChange=!0),!a.extreme){let e=h||u,t=m.cp1,l=G([e,y,t],!1),n=.01*j(e,t),r=Math.abs(l)<n,s=l<0&&a.cptArea>0||l>0&&a.cptArea<0;!r&&s&&(a.corner=!0)}}s&&(a.directionChange&&e(markers,a.p,"orange","1.5%","0.5"),a.corner&&e(markers,a.p,"magenta","1.5%","0.5"),a.extreme&&e(markers,a.p,"cyan","1%","0.5")),M.push(a)}return y={pathData:M,bb:h,dimA:(g+d)/2},y}function ne(e={},t={},l={},a={},n=1){let r=L(e,t,1.5),s=L(a,l,1.5),p=.01*R(e,a)*n,i=R(r,s),y=null,u={type:"C",values:[t.x,t.y,l.x,l.y,a.x,a.y]};return i<p&&(y=C(e,t,a,l,!1),y&&(u.type="Q",u.values=[y.x,y.y,a.x,a.y],u.p0=e,u.cp1=y,u.cp2=null,u.p=a)),u}function re(e,{toShorthands:t=!0,toLonghands:l=!1,toRelative:a=!0,toAbsolute:n=!1,decimals:r=3,arcToCubic:s=!1,quadraticToCubic:p=!1,hasRelatives:i=!0,hasShorthands:y=!0,hasQuadratics:u=!0,hasArcs:h=!0,testTypes:o=!1}={}){if(o){let t=Array.from(new Set(e.map(e=>e.type))).join("");/[lcqamts]/gi.test(t),u=/[qt]/gi.test(t),h=/[a]/gi.test(t),y=/[vhst]/gi.test(t),isPoly=/[mlz]/gi.test(t)}return a=!n&&a,t=!l&&t,u&&p&&(e=pe(e)),h&&s&&(e=se(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?ye(e):e;let n=e.length,r=new Array(n),s=e[0];r[0]=s;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];s=l;let{type:a,values:n}=l,y=n.length,u=[n[y-2],n[y-1]],h=e[t-1];i={x:u[0],y:u[1]};let o=Math.abs(i.x-p.x),x=Math.abs(i.y-p.y),c=.01*R(p,i),f=!1,g=!1,d=!1;if("C"===a&&"C"===h.type||"Q"===a&&"Q"===h.type){let e="C"===h.type?{x:h.values[2],y:h.values[3]}:{x:h.values[0],y:h.values[1]},t={x:n[0],y:n[1]},l=p.x-e.x,a=p.y-e.y;c=.025*R(e,t),f=R({x:e.x+2*l,y:e.y+2*a},t)<c}else"L"===a&&(g=0===x||x<c,d=0===o||o<c,f=d||g);switch(a){case"L":g&&(s={type:"H",values:[n[0]]}),d&&(s={type:"V",values:[n[1]]});break;case"Q":f&&(s={type:"T",values:[i.x,i.y]});break;case"C":f&&(s={type:"S",values:[n[2],n[3],i.x,i.y]});break;default:s={type:a,values:n}}p=i,r[t]=s}return r}(e)),y&&l&&(e=he(e)),n&&(e=ue(e)),r>-1&&a&&(e=le(e,r)),a&&(e=function(e,t=-1){return ye(e,!0,t)}(e)),r>-1&&(e=le(e,r)),e}function se(e,{arcAccuracy:t=1}={}){let l=[e[0]];for(let a=1,n=e.length;a<n;a++){let n=e[a],r=e[a-1].values,s=r.length,p={x:r[s-2],y:r[s-1]};if("A"===n.type){xe(p,n.values,t).forEach(e=>{l.push(e)})}else l.push(n)}return l}function pe(e){let t=[e[0]];for(let l=1,a=e.length;l<a;l++){let a=e[l],n=e[l-1].values,r=n.length,s={x:n[r-2],y:n[r-1]};"Q"===a.type?t.push(ie(s,a.values)):t.push(a)}return t}function ie(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 ye(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,r=n[0],s=n[1],p=r,i=s;for(let n=1;n<a;n++){let a=e[n],{type:y,values:u}=a,h=u.length,o=y.toLowerCase(),x=y.toUpperCase(),c=t?o:x;if(y!==c)switch(a.type=c,o){case"a":u[5]=t?u[5]-r:u[5]+r,u[6]=t?u[6]-s:u[6]+s;break;case"v":u[0]=t?u[0]-s:u[0]+s;break;case"h":u[0]=t?u[0]-r:u[0]+r;break;case"m":t?(u[0]-=r,u[1]-=s):(u[0]+=r,u[1]+=s),p=t?u[0]+r:u[0],i=t?u[1]+s:u[1];break;default:if(u.length)for(let e=0;e<u.length;e++)u[e]=t?u[e]-(e%2?s:r):u[e]+(e%2?s:r)}switch(o){case"z":r=p,s=i;break;case"h":r=t?r+u[0]:u[0];break;case"v":s=t?s+u[0]:u[0];break;case"m":p=u[h-2]+(t?r:0),i=u[h-1]+(t?s:0);default:r=u[h-2]+(t?r:0),s=u[h-1]+(t?s:0)}l>=0&&(a.values=a.values.map(e=>+e.toFixed(l)))}return e}function ue(e,t=-1){return ye(e,!1,t)}function he(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}let n=[],r={type:"M",values:(e=l&&a?ue(e,t):e)[0].values};n.push(r);for(let l=1,a=e.length;l<a;l++){let a,s,p,i,y,u,h,o,x=e[l],{type:c,values:f}=x,g=f.length,d=r.values,M=d.length,[v,m]=[f[g-2],f[g-1]],[b,A]=[d[M-2],d[M-1]];switch(c){case"H":r={type:"L",values:[f[0],A]};break;case"V":r={type:"L",values:[b,f[0]]};break;case"T":[a,s]=[d[0],d[1]],[b,A]=[d[M-2],d[M-1]],p=b+(b-a),i=A+(A-s),r={type:"Q",values:[p,i,v,m]};break;case"S":[a,s]=[d[0],d[1]],[b,A]=[d[M-2],d[M-1]],[h,o]=M>2&&"A"!==r.type?[d[2],d[3]]:[b,A],p=2*b-h,i=2*A-o,y=f[0],u=f[1],r={type:"C",values:[p,i,y,u,v,m]};break;default:r={type:c,values:f}}t>-1&&(r.values=r.values.map(e=>+e.toFixed(t))),n.push(r)}return n}function oe({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:r=0,radToDegree:s=!1,startAngle:p=null,endAngle:i=null,deltaAngle:y=null}={}){if(!a||!n)return[];let u=[];const h=1.5707963267948966;let o=s?r:r*Math.PI/180,x=Math.cos(o),c=Math.sin(o);null!==p&&null!==i&&null!==y||({startAngle:p,endAngle:i,deltaAngle:y}=A(l,e,t));let f=a!==n?I(p,a,n):p,g=a!==n?I(y,a,n):y,d=Math.max(1,Math.ceil(Math.abs(g)/h)),M=g/d;for(let e=0;e<d;e++){const e=Math.abs(M)===h?.551785*Math.sign(M):4/3*Math.tan(M/4);let t=Math.cos(f),r=Math.sin(f),s=Math.cos(f+M),p=Math.sin(f+M),i=[];[{x:t-r*e,y:r+t*e},{x:s+p*e,y:p-s*e},{x:s,y:p}].forEach(e=>{let t=e.x*a,r=e.y*n;i.push(x*t-c*r+l.x,c*t+x*r+l.y)}),u.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 u}function xe(e,t,l=1){const a=2*Math.PI;let[n,r,s,p,i,y,u]=t;if(0===n||0===r)return[];let h=s?s*a/360:0,o=h?Math.sin(h):0,x=h?Math.cos(h):1,c=x*(e.x-y)/2+o*(e.y-u)/2,f=-o*(e.x-y)/2+x*(e.y-u)/2;if(0===c&&0===f)return[];n=Math.abs(n),r=Math.abs(r);let g=c*c/(n*n)+f*f/(r*r);if(g>1){let e=Math.sqrt(g);n*=e,r*=e}let d=n*n,M=n===r?d:r*r,v=c*c,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/r*f:0,C=b?b*-r/n*c:0,L=x*A-o*C+(e.x+y)/2,w=o*A+x*C+(e.y+u)/2,P=(c-A)/n,S=(f-C)/r,E=(-c-A)/n,I=(-f-C)/r;const k=(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=k(1,0,P,S),$=k(P,S,E,I);0===i&&$>0?$-=2*Math.PI:1===i&&$<0&&($+=2*Math.PI);let Q=(+(Math.abs($)/(a/4)).toFixed(0)||1)*l;$/=Q;let q=[];const z=1.5707963267948966,T=.551785;let F=$===z?T:$===-z?-T:4/3*Math.tan($/4),j=$?Math.cos($):1,R=$?Math.sin($):0;const Z=(e,t,l,a,n)=>{let r=e!=t?Math.cos(e):a,s=e!=t?Math.sin(e):n,p=Math.cos(e+t),i=Math.sin(e+t);return[{x:r-s*l,y:s+r*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:[]};Z(D,$,F,j,R).forEach(t=>{let l=t.x*n,a=t.y*r;e.values.push(x*l-o*a+L,o*l+x*a+w)}),q.push(e),D+=$}return q}function ce(e,{toAbsolute:t=!0,toLonghands:l=!0,quadraticToCubic:a=!1,arcToCubic:n=!1,arcAccuracy:r=4}={}){let s=Array.isArray(e),p=s&&"object"==typeof e[0]&&"function"==typeof e[0].constructor,i=s?e:function(e,t=!0,l=0){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,r=0,s=e.length,p="",i=-1,y="",u=!1,h=0,o=0,x=0,c=!1,f=new Set([]);const g=()=>{c&&("M"===p?p="L":"m"===p&&(p="l"),a.pathData.push({type:p,values:[]}),i++,o=0,c=!1)},d=(e=!1)=>{(e?h>0:""!==y)&&(t&&-1===i&&(n="Pathdata must start with M command",a.log.push(n),p="M",a.pathData.push({type:p,values:[]}),x=2,o=0,i++),"A"===p||"a"===p?(({val:y,valueIndex:o}=ve(y,o)),a.pathData[i].values.push(...y)):(t&&y[1]&&"."!==y[1]&&"0"===y[0]&&(n=`${i}. command: Leading zeros not valid: ${y}`,a.log.push(n)),a.pathData[i].values.push(+y)),o++,y="",h=0,c=o>=x)},M=()=>{if(i>0){let e=a.pathData[i].values.length;if(e&&e<x||e&&e>x||("z"===p||"Z"===p)&&e>0){n=`${i}. command of type "${p}": ${x-e} values too few - ${x} expected`,a.log[a.log.length-1]!==n&&a.log.push(n)}}};let v=!1,m=!1,b=!1,A="";for(;r<s;){A=e.charCodeAt(r);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(u||45!==A&&46!==A)g();else{let e=46===A;d(e),g(),e&&h++}y+=e[r],u=v,r++}else if((A<48||A>5759)&&Me(A))d(),r++;else{if(A>64){if(!fe.has(A)){n=`${i}. command "${e[r]}" is not a valid type`,a.log.push(n),r++;continue}""!==y&&(a.pathData[i].values.push(+y),o++,y=""),t&&M(),p=e[r],x=ge[A];let l="M"===p||"m"===p,s=i>0&&("z"===a.pathData[i].type||"Z"===a.pathData[i].type);f.add(p),s&&!l&&(a.pathData.push({type:"m",values:[0,0]}),i++),a.pathData.push({type:p,values:[]}),i++,h=0,o=0,c=!1,r++;continue}l||(n=`${i}. ${e[r]} is not a valid separarator or token`,a.log.push(n),y=""),r++}}d(),t&&M();t&&a.log.length&&(n="Invalid path data:\n"+a.log.join("\n"),"log"===t?console.log(n):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:y=!0,hasShorthands:u=!0,hasQuadratics:h=!0,hasArcs:o=!0}=i,x=p?i:i.pathData;return x=function(e=[],{toAbsolute:t=!0,toLonghands:l=!0,quadraticToCubic:a=!1,arcToCubic:n=!1,arcAccuracy:r=2,hasRelatives:s=!0,hasShorthands:p=!0,hasQuadratics:i=!0,hasArcs:y=!0,testTypes:u=!1}={}){if(u){let t=Array.from(new Set(e.map(e=>e.type))).join("");s=/[lcqamts]/gi.test(t),i=/[qt]/gi.test(t),y=/[a]/gi.test(t),p=/[vhst]/gi.test(t),isPoly=/[mlz]/gi.test(t)}return(i&&a||y&&n)&&(l=!0,t=!0),s&&t&&(e=ye(e,!1)),p&&l&&(e=he(e,-1,!1)),y&&n&&(e=se(e,r)),i&&a&&(e=pe(e)),e}(x,{toAbsolute:t,toLonghands:l,quadraticToCubic:a,arcToCubic:n,arcAccuracy:r,hasRelatives:y,hasShorthands:u,hasQuadratics:h,hasArcs:o}),x}const fe=new Set([77,109,65,97,67,99,76,108,81,113,83,115,84,116,72,104,86,118,90,122]),ge=new Uint8Array(128);ge[77]=2,ge[109]=2,ge[65]=7,ge[97]=7,ge[67]=6,ge[99]=6,ge[76]=2,ge[108]=2,ge[81]=4,ge[113]=4,ge[83]=4,ge[115]=4,ge[84]=2,ge[116]=2,ge[72]=1,ge[104]=1,ge[86]=1,ge[118]=1,ge[90]=0,ge[122]=0;const de=new Set([5760,6158,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288,65279]),Me=e=>32===e||44===e||10===e||13===e||8232===e||8233===e||9===e||11===e||12===e||160===e||e>=5760&&de.has(e),ve=(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}};function me(e,{tolerance:t=1,flatBezierToLinetos:l=!0}={}){let a=[e[0]],n={x:e[0].values[0],y:e[0].values[1]},r=n,s=n;e[e.length-1].type.toLowerCase();for(let p=1,i=e.length;p<i;p++){let y=e[p],u=e[p+1]||e[i-1],h="z"===u.type.toLowerCase()?n:{x:u.values[u.values.length-2],y:u.values[u.values.length-1]},{type:o,values:x}=y,c=x.slice(-2);s="Z"!==o?{x:c[0],y:c[1]}:n;let f=h?G([r,s,h],!0):1/0,g=j(r,h),d=f<(g?g/333*t:0),M=!1;if(l||"C"!==o||(d=!1),l&&("C"===o||"Q"===o)){M=ee([r,..."C"===o?[{x:x[0],y:x[1]},{x:x[2],y:x[3]}]:"Q"===o?[{x:x[0],y:x[1]}]:[],s],{tolerance:t}),M&&p<i-1&&(o="L",y.type="L",y.values=c)}d&&p<i-1&&"A"!==u.type&&("L"===o||l&&M)||(r=s,"M"===o&&(n=s),a.push(y))}return a}function be(e){let t={x:e[0].values[0],y:e[0].values[1]},l=t,a=[e[0]];for(let n=1,r=e.length;n<r;n++){let r=e[n],s=e[n-1],p=e[n+1]||null,{type:i,values:y}=r,u="m"===s.type.toLowerCase()&&!p,h=y.length;if(l={x:y[h-2],y:y[h-1]},u||"L"!==i||l.x!==t.x||l.y!==t.y){if(!u&&("l"===i||"v"===i||"h"===i)){if("l"===i?"00"===y.join(""):0===y[0])continue}a.push(r),t=l}}return a}function Ae(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:r}=t,s=r.length;if(s){let e={type:n,x:r[s-2],y:r[s-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?Le(e,l):e}function Ce(e,{removeFinalLineto:t=!0,autoClose:l=!0}={}){let a=[],n=e.length,r={x:+e[0].values[0].toFixed(8),y:+e[0].values[1].toFixed(8)},s="z"===e[n-1].type.toLowerCase(),p=e.filter(e=>"L"===e.type),i=e[s?n-2:n-1],y=i.type,u=i.values.slice(-2).map(e=>+e.toFixed(8)),h=u[0]===r.x&&u[1]===r.y;!s&&l&&h&&(e.push({type:"Z",values:[]}),s=!0,n++);let o="L"!==e[1].type&&(!h||"L"===i.type);if(o=!1,!s)return e;let x=0;{let t=[];for(let l=0;l<n;l++){let a=e[l],{type:n,values:r}=a;if(r.length){let a=r.slice(-2),s=e[l-1]&&"L"===e[l-1].type,p=e[l+1]&&"L"===e[l+1].type,i=e[l-1]?e[l-1].type.toUpperCase():null,y=e[l+1]?e[l+1].type.toUpperCase():null,u={type:n,x:a[0],y:a[1],dist:0,index:0,prevL:s,nextL:p,prevCom:i,nextCom:y};u.index=l,t.push(u)}}if(p.length){let e=t.filter(e=>"L"!==e.type&&"M"!==e.type&&e.prevCom&&"L"===e.prevCom||"M"===e.prevCom&&"L"===y).sort((e,t)=>e.y-t.y||e.x-t.x)[0];x=e?e.index-1:0}else t=t.sort((e,t)=>+e.y.toFixed(8)-+t.y.toFixed(8)||e.x-t.x),x=t[0].index;e=x?Le(e,x):e}return r={x:+e[0].values[0].toFixed(8),y:+e[0].values[1].toFixed(8)},n=e.length,i=e[n-2],y=i.type,u=i.values.slice(-2).map(e=>+e.toFixed(8)),h="L"===y&&u[0]===r.x&&u[1]===r.y,t&&h&&e.splice(n-2,1),a.push(...e),a}function Le(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,r]=[a.values[0],a.values[1]].map(e=>+e.toFixed(8)),s=l?e[t-2]:e[t-1],p=s.values.length,[i,y]=[s.values[p-2],s.values[p-1]].map(e=>+e.toFixed(8));!l||n==i&&r==y||(e.pop(),e.push({type:"L",values:[n,r]},{type:"Z",values:[]}))}(e),l=t+1<e.length-1?t+1:e.length-1-n;let r,s,p=e.slice(l),i=e.slice(0,l);return i.shift(),r=i[i.length-1].values||[],s=[r[r.length-2],r[r.length-1]],n&&(p.pop(),i.push({type:"Z",values:[]})),e=[{type:"M",values:s},...p,...i]}function we(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 r=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,s=n.length,p=(e[t-1]?e[t-1]:e[t]).values,i=p.length;if(s){let e={x:p[i-2],y:p[i-1]},t={x:n[s-2],y:n[s-1]};if(r(t),"C"===a||"Q"===a){let l={x:n[0],y:n[1]},s="C"===a?{x:n[2],y:n[3]}:l,p="C"===a?[e,l,s,t]:[e,l,t];D(p).forEach(e=>{let t=w(p,e);r(t)})}else"A"===a&&$(e,n).forEach(e=>{r(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:r,values:s,extreme:p,corner:i=!1,dimA:y,p0:u,p:h}=a,o=e[n+1]?e[n+1]:null,x=e[n+2]?e[n+2]:null,c=(o?R(h,o.p):1/0)<t,f=(x?R(x.p,o.p):1/0)<1*t;if(o&&x&&"C"===r&&"C"===o.type&&p&&x.extreme&&(f||c)){let a=X(o,x,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"===r&&"C"===o.type&&p&&c){let e=G([a.p0,a.p,o.p]),t=G([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,r=e[n],s=e[n-1]||null,p={x:e[0].values[0],y:e[0].values[1]},i=r.values.slice(-2),y=+i[0].toFixed(8)===+p.x.toFixed(8)&&+i[1].toFixed(8)===+p.y.toFixed(8),u="C"===e[1].type&&e[1].extreme?e[1]:null,h=R(r.p0,r.p)<t;if(s&&"C"===s.type&&h&&y&&u){let a=X(s,r,t,l,!1);1===a.length&&(e[n-1]=a[0],e[n]=null,e=e.filter(Boolean))}return e}function Pe(e,{threshold:t=0,tolerance:l=1}={}){let a=e.length,n=[e[0]],r="z"===e[a-1].type.toLowerCase(),s=!!r&&(e[a-1].p.x===e[0].p0.x&&e[a-1].p.y===e[0].p0.y),p=r?2:1,i=e[a-p],y="L"===i.type,u="C"===i.type,h="L"===e[1].type,o="C"===e[1].type,x=r&&o&&(y||s);x&&(e[a-1].values=e[0].values,e[a-1].type="L",y=!0);for(let t=1;t<a;t++){let s=e[t],{type:i}=s,c=e[t+1]?e[t+1]:null;if("L"===i&&c&&"C"===c.type||"C"===i&&c&&"L"===c.type){let x="L"===i?s:null,f=null,g=[],d=0;if(1===t&&o&&y&&(g=[e[1]],x=e[a-1],f=c),!x){n.push(s);continue}r&&u&&h&&t===a-p-1&&(f=e[1],g=[e[a-p]]);for(let l=t+1;l<a;l++){let t=e[l]?e[l]:null,a=e[l-1];if("C"===a.type&&g.push(a),"L"===t.type&&"C"===a.type){f=t;break}d++}if(f){let e=R(x.p0,x.p),a=R(f.p0,f.p);g.length;let r=R(x.p,f.p0),p=G([x.p0,x.p,f.p0,f.p],!1),i=G([g[0].p0,g[0].cp1,g[0].cp2,g[0].p],!1),y=p<0&&i>0||p>0&&i<0,u=.5*r*l,h=u<e&&u<a;if(g.length&&!y&&h){let e=Math.abs(i)<=.005*j(g[0].p0,g[0].p),l=e?null:C(x.p0,x.p,f.p0,f.p,!1);if(!e&&l){let e=.75*R(w([x.p,l,f.p0],.5),1===g.length?w([g[0].p0,g[0].cp1,g[0].cp2,g[0].p],.5):g[0].p);if(u&&e>u&&e>.3*r){n.push(s);continue}{let e={type:"Q",values:[l.x,l.y,f.p0.x,f.p0.y]};e.p0=x.p,e.cp1=l,e.p=f.p0,n.push(x,e),t+=d;continue}}}}}x&&t===a-1&&"L"===i||n.push(s)}return(x||r&&"Z"!==n[n.length-1].type)&&n.push({type:"Z",values:[]}),n}function Se(e){if(e.length<3)return!1;let t=e[0],l=e[Math.floor(e.length/2)],a=e[e.length-1],n=t.x,r=t.y,s=l.x,p=l.y,i=a.x,y=a.y,u=n-s,h=r-p,o=n-i,x=r-y,c=(n*n-s*s+(r*r-p*p))/2,f=(n*n-i*i+(r*r-y*y))/2,g=u*x-h*o;if(Math.abs(g)<1e-10)return console.warn("Points are collinear or numerically unstable"),!1;let d={x:(x*c-h*f)/g,y:(-o*c+u*f)/g},M=F(d,t),v=A(d,t,a),{deltaAngle:m,startAngle:b,endAngle:C}=v;return{centroid:d,r:M,startAngle:b,endAngle:C,deltaAngle:m}}function Ee(e,{threshold:l=0,tolerance:a=1,toCubic:n=!1,debug:r=!1}={}){let s=e.length,p=[e[0]],i=[];for(let l=1;l<s;l++){let a=e[l],{type:s}=a,y=e[l-1],u=e[l+1]?e[l+1]:null,h=e[l+2]?e[l+2]:null,o=e[l+3]?e[l+3]:null,x=null;"C"===a.type||"Q"===a.type?x=a:!u||"C"!==u.type&&"Q"!==u.type||(x=u);let c,f,g,d,M,v=x?"C"===x.type?[x.p0,x.cp1,x.cp2,x.p]:[x.p0,x.cp1,x.p]:[],m=0,b=0,A=!1,C=!1,L=[];if("L"===y.type&&"L"===s&&x&&"L"===h.type&&o&&("L"===o.type||"Z"===o.type)?(c=[a.p0,a.p],f=[h.p0,h.p],g=a.p0,d=h.p,m=G(v,!1),b=G([...c,...f],!1),A=m<0&&b>0||m>0&&b<0,A||(M=w(v,.5),L=[g,M,d],C=!0)):"C"!==s&&"Q"!==s||"L"!==y.type||"C"!==u.type&&"Q"!==u.type||"L"!==h.type||(C=!0,c=[y.p0,y.p],f=[h.p0,h.p],g=y.p,d=h.p0,M=x.p,L=[g,x.p,d]),C){let e=Se(L);if(e){let s,{centroid:y,r:u,deltaAngle:h,startAngle:o,endAngle:x}=e,c=0,f=h>0?1:0,v=Math.abs(h)>Math.PI?1:0;if(Z(S(g,y.x,y.y,.5*h),M)<.05*Z(g,d)){if(s=oe({p0:g,p:d,centroid:y,rx:u,ry:u,xAxisRotation:c,sweep:f,largeArc:v,deltaAngle:h,startAngle:o,endAngle:x}),1===s.length){let e=ne(g,s[0].cp1,s[0].cp2,d);"Q"===e.type&&(n=!0),a=e}if(s.length>1&&(n=!1),n||(a.type="A",a.values=[u,u,c,v,f,d.x,d.y]),a.p0=g,a.p=d,a.extreme=!1,a.corner=!1,r){i=n?[{type:"M",values:[g.x,g.y]},...s]:[{type:"M",values:[g.x,g.y]},{type:"A",values:[u,u,c,v,f,d.x,d.y]}];let e=K(i);t(markers,e,"orange","0.5%","0.5")}p.push(a),l++;continue}}}p.push(a)}return p}function Ie(e=[],{threshold:t=0}={}){let l=e.length,a="z"===e[l-1].type.toLowerCase(),n=a?l-2:l-1,r=e[n],s=r.values.slice(-2),p={x:e[0].values[0],y:e[0].values[1]},i=Z(p,{x:s[0],y:s[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"===r.type){let l=Math.abs(a.values[0]-r.values[2]),s=Math.abs(a.values[1]-r.values[3]),i=Math.abs(e[1].values[0]-a.values[0]),y=Math.abs(e[1].values[1]-a.values[1]),u=Math.abs(e[1].values[0]-r.values[2]),h=Math.abs(e[1].values[1]-r.values[3]),o=y<t&&h<t&&l;l&&l<t&&(i<t&&u<t&&s)&&(e[1].values[0]=p.x,e[n].values[2]=p.x),s&&s<t&&o&&(e[1].values[1]=p.y,e[n].values[3]=p.y)}}return e}function ke(e,t=1){for(let l=1,a=e.length;l<a;l++){let a=e[l],{type:n,values:r,p0:s,cp1:p=null,cp2:i=null,p:y=null}=a;if("C"===n){let n=ne(s,p,i,y,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 De(e){for(let t=1,l=e.length;t<l;t++){let l=e[t],{type:a,values:n,p0:r,cp1:s=null,cp2:p=null,p:i=null}=l;if("L"===a){let l=L(r,i,.333),a=L(i,r,.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 $e(e="",{toAbsolute:t=!0,toRelative:l=!0,toShorthands:a=!0,quadraticToCubic:n=!0,arcToCubic:r=!1,cubicToArc:s=!1,simplifyBezier:p=!0,optimizeOrder:i=!0,autoClose:y=!0,removeZeroLength:u=!0,refineClosing:h=!0,removeColinear:o=!0,flatBezierToLinetos:x=!0,revertToQuadratics:c=!0,refineExtremes:f=!0,simplifyCorners:g=!1,fixDirections:d=!1,keepExtremes:M=!0,keepCorners:v=!0,keepInflections:m=!1,addExtremes:b=!1,addSemiExtremes:A=!1,harmonizeCpts:C=!1,toPolygon:L=!1,removeOrphanSubpaths:w=!1,simplifyRound:P=!1,decimals:S=3,autoAccuracy:E=!0,minifyD:I=0,tolerance:k=1,lineToCubic:D=!1,getObject:$=!1}={}){k=Math.max(.1,k);let Q="",q={x:0,y:0,width:0,height:0},z=[],T=[],F=function(e){let t="string";if(Array.isArray(e)){if(Array.isArray(e[0])){if(2===e[0].length)return"polyArray";if(Array.isArray(e[0][0])&&2===e[0][0].length)return"polyComplexArray";if(void 0!==e[0][0].x&&void 0!==e[0][0].y)return"polyComplexObjectArray"}else{if(void 0!==e[0].x&&void 0!==e[0].y)return"polyObjectArray";if(e[0]?.type&&e[0]?.values)return"pathData"}return"array"}if("string"==typeof e){let l=(e=e.trim()).includes("<svg")&&e.includes("</svg"),a=e.startsWith("M")||e.startsWith("m"),n=!isNaN(e.substring(0,1))&&!isNaN(e.substring(e.length-1,e.length));if(l)t="svgMarkup";else if(a)t="pathDataString";else if(n)t="polyString";else{let l=/^(file:|https?:\/\/|\/|\.\/|\.\.\/)/.test(e),a=e.startsWith("data:image");t=l||a?"url":"string"}return t}return t=typeof e,(e.constructor.name||t).toLowerCase()}(e);if("pathDataString"===F)Q=e;else if("polyString"===F)Q="M"+e;else{if("pathData"!==F)return!1;Q=e}let j={toRelative:l,toShorthands:a,decimals:S},Z=ce(Q,{quadraticToCubic:n,toAbsolute:t,arcToCubic:r});Z.length,w&&(Z=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:r=[]}=a,s=e[l+1]?e[l+1]:null;"M"!==n&&"m"!==n||s&&(!s||"Z"!==s.type&&"z"!==s.type)?t.push(a):s&&l++}return t}(Z));let B=O(Z),N=B.length,J=[];for(let e=0;e<N;e++){let t=B[e];(o||u)&&(t=be(t)),i&&(t=Ae(t)),o&&(t=me(t,{tolerance:k,flatBezierToLinetos:!1})),(b||A)&&(t=H(t,{tMin:tMin,tMax:tMax,addExtremes:b,addSemiExtremes:A,angles:[30]}));let l=ae(t,{detectSemiExtremes:A}),{pathData:a,bb:n,dimA:r}=l;if(z.push(n.x,n.x+n.width),T.push(n.y,n.y+n.height),h&&(a=Ie(a,{threshold:.001*r})),a=p?Y(a,{simplifyBezier:p,keepInflections:m,keepExtremes:M,keepCorners:v,revertToQuadratics:c,tolerance:k}):a,f){a=we(a,{threshold:.05*(n.width+n.height),tolerance:k})}if(o&&x&&(a=me(a,{tolerance:k,flatBezierToLinetos:x})),g){a=Pe(a,{threshold:.1*(n.width+n.height),tolerance:k})}P&&(a=Ee(a)),c&&(a=ke(a,k)),D&&(a=De(a)),i&&(a=Ce(a,{autoClose:y})),J.push({pathData:a,bb:n})}let U=Math.min(...z),V=Math.min(...T);q={x:U,y:V,width:Math.max(...z)-U,height:Math.max(...T)-V},i&&(J=q.height>q.width?J.sort((e,t)=>e.bb.y-t.bb.y||e.bb.x-t.bb.x):J.sort((e,t)=>e.bb.x-t.bb.x||e.bb.y-t.bb.y)),Z=[],J.forEach(e=>{Z.push(...e.pathData)}),E&&(S=function(e){let t=[];for(let l=1,a=e.length;l<a;l++){let a=e[l],{type:n,values:r,p0:s=null,p:p=null,dimA:i=0}=a;r.length&&p&&s&&(i=i||R(s,p),i&&t.push(i))}let l=t.sort(),a=Math.ceil(l.length/8);l=l.slice(0,a);let n=l.reduce((e,t)=>e+t,0)/a,r=n>112.5?0:Math.floor(75/n).toString().length;return Math.min(Math.max(0,r),8)}(Z),j.decimals=S),Z=re(Z,j),Z=be(Z);let W=K(Z,I);return $&&(Z=Z.map(e=>({type:e.type,values:e.values}))),$?Z:W}"undefined"!=typeof window&&(window.simplifyPathData=$e);export{$e as simplifyPathData};
|
|
3
|
+
if(C){let e="C"===l?Math.abs(a.cp2.x-a.p.x):Math.abs(a.cp1.x-a.p.x),t="C"===l?Math.abs(a.cp2.y-a.p.y):Math.abs(a.cp1.y-a.p.y);if(((0===t||t<=A)&&e>0||(0===e||e<=A)&&t>0)&&(w=!0),(u.x===s.x&&u.y!==s.y||u.y===s.y&&u.x!==s.x)&&(M[M.length-1].extreme=!0),p.x!==o&&p.y!==c&&p.x!==x&&p.y!==f||(w=!0),!w){if(k(null,v)){let e=Q(v);e.length&&e[0]>.2&&(w=!0)}}}if(w&&(a.extreme=!0),C&&L){if(r&&!a.extreme){let e=Math.abs(p.x-i.x),t=Math.abs(p.y-i.y),l=!1;if(e&&t&&e>m||t>m){let e=b(i,p),t=b(p,d.cp1);l=q(Math.abs(e+t)/2)}l&&(a.semiExtreme=!0)}if((a.cptArea<0&&d.cptArea>0||a.cptArea>0&&d.cptArea<0)&&(a.directionChange=!0),!a.extreme){let e=i||u,t=d.cp1,l=X([e,p,t],!1),n=.01*j(e,t),r=Math.abs(l)<n,s=l<0&&a.cptArea>0||l>0&&a.cptArea<0;!r&&s&&(a.corner=!0)}}M.push(a)}return s&&M.forEach(t=>{t.directionChange&&e(markers,t.p,"orange","1.5%","0.5"),t.corner&&e(markers,t.p,"magenta","1.5%","0.5"),t.extreme&&e(markers,t.p,"cyan","1%","0.5")}),i={pathData:M,bb:h,dimA:(g+d)/2},i}const ne=new Set([77,109,65,97,67,99,76,108,81,113,83,115,84,116,72,104,86,118,90,122]),re=new Uint8Array(128);re[77]=2,re[109]=2,re[65]=7,re[97]=7,re[67]=6,re[99]=6,re[76]=2,re[108]=2,re[81]=4,re[113]=4,re[83]=4,re[115]=4,re[84]=2,re[116]=2,re[72]=1,re[104]=1,re[86]=1,re[118]=1,re[90]=0,re[122]=0;const se=new Set([5760,6158,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288,65279]),pe=e=>32===e||44===e||10===e||13===e||8232===e||8233===e||9===e||11===e||12===e||160===e||e>=5760&&se.has(e);function ue(e,{toAbsolute:t=!0,toLonghands:a=!0,quadraticToCubic:l=!1,arcToCubic:n=!1,arcAccuracy:r=4}={}){let s=Array.isArray(e),p=s&&"object"==typeof e[0]&&"function"==typeof e[0].constructor,u=s?e:function(e,t=!0,a=0){e=e.trim(),a&&console.log("!!!limit",a);let l={pathData:[],hasRelatives:!1,hasShorthands:!1,hasArcs:!1,hasQuadratics:!1,isPolygon:!1,log:[]};if(""===e)return l;let n,r=0,s=e.length,p="",u=-1,i="",y=!1,h=0,o=0,x=0,c=!1,f=new Set([]);const g=()=>{c&&("M"===p?p="L":"m"===p&&(p="l"),l.pathData.push({type:p,values:[]}),u++,o=0,c=!1)},d=(e=!1)=>{(e?h>0:""!==i)&&(t&&-1===u&&(n="Pathdata must start with M command",l.log.push(n),p="M",l.pathData.push({type:p,values:[]}),x=2,o=0,u++),"A"===p||"a"===p?(({val:i,valueIndex:o}=((e="",t=0)=>{let a=e.length;return 3===t&&2===a?(e=[+e[0],+e[1]],t++):4===t&&a>1?(e=[+e[0],+e.substring(1)],t++):3===t&&a>=3?(e=[+e[0],+e[1],+e.substring(2)],t+=2):e=[+e],{val:e,valueIndex:t}})(i,o)),l.pathData[u].values.push(...i)):(t&&i[1]&&"."!==i[1]&&"0"===i[0]&&(n=`${u}. command: Leading zeros not valid: ${i}`,l.log.push(n)),l.pathData[u].values.push(+i)),o++,i="",h=0,c=o>=x)},M=()=>{if(u>0){let e=l.pathData[u].values.length;(e&&e<x||e&&e>x||("z"===p||"Z"===p)&&e>0)&&(n=`${u}. command of type "${p}": ${x-e} values too few - ${x} expected`,l.log[l.log.length-1]!==n&&l.log.push(n))}};let v=!1,m=!1,b=!1,A="";for(;r<s;){A=e.charCodeAt(r);let a=A>47&&A<58;if(a||(v=101===A||69===A,m=45===A||43===A,b=46===A),a||m||b||v){if(y||45!==A&&46!==A)g();else{let e=46===A;d(e),g(),e&&h++}i+=e[r],y=v,r++}else if((A<48||A>5759)&&pe(A))d(),r++;else{if(A>64){if(!ne.has(A)){n=`${u}. command "${e[r]}" is not a valid type`,l.log.push(n),r++;continue}""!==i&&(l.pathData[u].values.push(+i),o++,i=""),t&&M(),p=e[r],x=re[A];let a="M"===p||"m"===p,s=u>0&&("z"===l.pathData[u].type||"Z"===l.pathData[u].type);f.add(p),s&&!a&&(l.pathData.push({type:"m",values:[0,0]}),u++),l.pathData.push({type:p,values:[]}),u++,h=0,o=0,c=!1,r++;continue}a||(n=`${u}. ${e[r]} is not a valid separarator or token`,l.log.push(n),i=""),r++}}d(),t&&M(),t&&l.log.length&&(n="Invalid path data:\n"+l.log.join("\n"),"log"===t?console.log(n):console.warn(n)),l.pathData[0].type="M";let C=Array.from(f).join("");return l.hasRelatives=/[lcqamtsvh]/g.test(C),l.hasShorthands=/[vhst]/gi.test(C),l.hasArcs=/[a]/gi.test(C),l.hasQuadratics=/[qt]/gi.test(C),l.isPolygon=!/[cqats]/gi.test(C),l}(e),{hasRelatives:i=!0,hasShorthands:y=!0,hasQuadratics:h=!0,hasArcs:o=!0}=u,x=p?u:u.pathData;return x=function(e=[],{toAbsolute:t=!0,toLonghands:a=!0,quadraticToCubic:l=!1,arcToCubic:n=!1,arcAccuracy:r=2,hasRelatives:s=!0,hasShorthands:p=!0,hasQuadratics:u=!0,hasArcs:i=!0,testTypes:y=!1}={}){return ie(e,{toAbsolute:t,toLonghands:a,quadraticToCubic:l,arcToCubic:n,arcAccuracy:r,hasRelatives:s,hasShorthands:p,hasQuadratics:u,hasArcs:i,testTypes:y,decimals:-1})}(x,{toAbsolute:t,toLonghands:a,quadraticToCubic:l,arcToCubic:n,arcAccuracy:r,hasRelatives:i,hasShorthands:y,hasQuadratics:h,hasArcs:o}),x}function ie(e,{toShorthands:t=!0,toLonghands:a=!1,toRelative:l=!0,toAbsolute:n=!1,decimals:r=3,arcToCubic:s=!1,quadraticToCubic:p=!1,hasRelatives:u=!0,hasShorthands:i=!0,hasQuadratics:y=!0,hasArcs:h=!0,optimizeArcs:o=!0,testTypes:x=!1}={}){if(x){let t=Array.from(new Set(e.map(e=>e.type))).join("");/[lcqamts]/gi.test(t),y=/[qt]/gi.test(t),h=/[a]/gi.test(t),i=/[vhst]/gi.test(t),isPoly=/[mlz]/gi.test(t)}return l=!n&&l,t=!a&&t,n&&(e=xe(e)),i&&a&&(e=function(e,t=-1,a=!0){let l=!1;if(a){let t=e.map(e=>e.type).join(""),a=/[hstv]/gi.test(t);if(l=/[astvqmhlc]/g.test(t),!a)return e}e=a&&l?xe(e,t):e;let n=[],r={type:"M",values:e[0].values};n.push(r);for(let a=1,l=e.length;a<l;a++){let l,s,p,u,i,y,h,o,x=e[a],{type:c,values:f}=x,g=f.length,d=r.values,M=d.length,[v,m]=[f[g-2],f[g-1]],[b,A]=[d[M-2],d[M-1]];switch(c){case"H":r={type:"L",values:[f[0],A]};break;case"V":r={type:"L",values:[b,f[0]]};break;case"T":[l,s]=[d[0],d[1]],[b,A]=[d[M-2],d[M-1]],p=b+(b-l),u=A+(A-s),r={type:"Q",values:[p,u,v,m]};break;case"S":[l,s]=[d[0],d[1]],[b,A]=[d[M-2],d[M-1]],[h,o]=M>2&&"A"!==r.type?[d[2],d[3]]:[b,A],p=2*b-h,u=2*A-o,i=f[0],y=f[1],r={type:"C",values:[p,u,i,y,v,m]};break;default:r={type:c,values:f}}t>-1&&(r.values=r.values.map(e=>+e.toFixed(t))),n.push(r)}return n}(e)),o&&(e=function(e=[]){return e.forEach((t,a)=>{let{type:l,values:n}=t;if("A"===l){let[t,l,r,s,p]=[n[0],n[1],n[3],n[5],n[6]],u=e[a-1],[i,y]=[u.values[u.values.length-2],u.values[u.values.length-1]],h={x:i,y:y},o={x:s,y:p};if(t>=1&&(s===i||p===y)){if(Math.abs(t-l)/t<.01){let l=F(L(h,o,.5),h);Math.abs(l-t)/t<.01&&(e[a].values[0]=1,e[a].values[1]=1,e[a].values[2]=0)}}}}),e}(e)),t&&(e=function(e,t=-1,a=!1){let l;if(a){let t=e.map(e=>e.type).join("");l=/[astvqmhlc]/g.test(t)}e=a&&l?oe(e):e;let n=e.length,r=new Array(n),s=e[0];r[0]=s;let p={x:e[0].values[0],y:e[0].values[1]},u=p;for(let t=1;t<n;t++){let a=e[t];s=a;let{type:l,values:n}=a,i=n.length,y=[n[i-2],n[i-1]],h=e[t-1];u={x:y[0],y:y[1]};let o=Math.abs(u.x-p.x),x=Math.abs(u.y-p.y),c=.01*R(p,u),f=!1,g=!1,d=!1;if("C"===l&&"C"===h.type||"Q"===l&&"Q"===h.type){let e="C"===h.type?{x:h.values[2],y:h.values[3]}:{x:h.values[0],y:h.values[1]},t={x:n[0],y:n[1]},a=p.x-e.x,l=p.y-e.y;c=.01*R(e,t),f=R({x:e.x+2*a,y:e.y+2*l},t)<c}else"L"===l&&(g=0===x||x<c,d=0===o||o<c,f=d||g);switch(l){case"L":g&&(s={type:"H",values:[n[0]]}),d&&(s={type:"V",values:[n[1]]});break;case"Q":f&&(s={type:"T",values:[u.x,u.y]});break;case"C":f&&(s={type:"S",values:[n[2],n[3],u.x,u.y]});break;default:s={type:l,values:n}}p=u,r[t]=s}return r}(e)),h&&s&&(e=function(e,{arcAccuracy:t=1}={}){let a=[e[0]];for(let l=1,n=e.length;l<n;l++){let n=e[l],r=e[l-1].values,s=r.length,p={x:r[s-2],y:r[s-1]};if("A"===n.type){fe(p,n.values,t).forEach(e=>{a.push(e)})}else a.push(n)}return a}(e)),y&&p&&(e=function(e){let t=[e[0]];for(let a=1,l=e.length;a<l;a++){let l=e[a],n=e[a-1].values,r=n.length,s={x:n[r-2],y:n[r-1]};"Q"===l.type?t.push(he(s,l.values)):t.push(l)}return t}(e)),r>-1&&l&&(e=U(e,r)),l&&(e=function(e,t=-1){return oe(e,!0,t)}(e)),r>-1&&(e=U(e,r)),e}function ye(e={},t={},a={},l={},n=1){let r=L(e,t,1.5),s=L(l,a,1.5),p=.01*R(e,l)*n,u=R(r,s),i=null,y={type:"C",values:[t.x,t.y,a.x,a.y,l.x,l.y]};return u<p&&(i=C(e,t,l,a,!1,!0),i&&(y.type="Q",y.values=[i.x,i.y,l.x,l.y],y.p0=e,y.cp1=i,y.cp2=null,y.p=l)),y}function he(e,t){Array.isArray(e)&&(e={x:e[0],y:e[1]});let a={x:e.x+2/3*(t[0]-e.x),y:e.y+2/3*(t[1]-e.y)},l={x:t[2]+2/3*(t[0]-t[2]),y:t[3]+2/3*(t[1]-t[3])};return{type:"C",values:[a.x,a.y,l.x,l.y,t[2],t[3]]}}function oe(e,t=!1,a=-1){a>=0&&(e[0].values=e[0].values.map(e=>+e.toFixed(a)));let l=e.length,n=e[0].values,r=n[0],s=n[1],p=r,u=s;for(let n=1;n<l;n++){let l=e[n],{type:i,values:y}=l,h=y.length,o=i.toLowerCase(),x=i.toUpperCase(),c=t?o:x;if(i!==c)switch(l.type=c,o){case"a":y[5]=t?y[5]-r:y[5]+r,y[6]=t?y[6]-s:y[6]+s;break;case"v":y[0]=t?y[0]-s:y[0]+s;break;case"h":y[0]=t?y[0]-r:y[0]+r;break;case"m":t?(y[0]-=r,y[1]-=s):(y[0]+=r,y[1]+=s),p=t?y[0]+r:y[0],u=t?y[1]+s:y[1];break;default:if(y.length)for(let e=0;e<y.length;e++)y[e]=t?y[e]-(e%2?s:r):y[e]+(e%2?s:r)}switch(o){case"z":r=p,s=u;break;case"h":r=t?r+y[0]:y[0];break;case"v":s=t?s+y[0]:y[0];break;case"m":p=y[h-2]+(t?r:0),u=y[h-1]+(t?s:0);default:r=y[h-2]+(t?r:0),s=y[h-1]+(t?s:0)}a>=0&&(l.values=l.values.map(e=>+e.toFixed(a)))}return e}function xe(e,t=-1){return oe(e,!1,t)}function ce({p0:e={x:0,y:0},p:t={x:0,y:0},centroid:a={x:0,y:0},rx:l=0,ry:n=0,xAxisRotation:r=0,radToDegree:s=!1,startAngle:p=null,endAngle:u=null,deltaAngle:i=null}={}){if(!l||!n)return[];let y=[];const h=1.5707963267948966;let o=s?r:r*Math.PI/180,x=Math.cos(o),c=Math.sin(o);null!==p&&null!==u&&null!==i||({startAngle:p,endAngle:u,deltaAngle:i}=A(a,e,t));let f=l!==n?I(p,l,n):p,g=l!==n?I(i,l,n):i,d=Math.max(1,Math.ceil(Math.abs(g)/h)),M=g/d;for(let e=0;e<d;e++){const e=Math.abs(M)===h?.551785*Math.sign(M):4/3*Math.tan(M/4);let t=Math.cos(f),r=Math.sin(f),s=Math.cos(f+M),p=Math.sin(f+M),u=[];[{x:t-r*e,y:r+t*e},{x:s+p*e,y:p-s*e},{x:s,y:p}].forEach(e=>{let t=e.x*l,r=e.y*n;u.push(x*t-c*r+a.x,c*t+x*r+a.y)}),y.push({type:"C",values:u,cp1:{x:u[0],y:u[1]},cp2:{x:u[2],y:u[3]},p:{x:u[4],y:u[5]}}),f+=M}return y}function fe(e,t,a=1){const l=2*Math.PI;let[n,r,s,p,u,i,y]=t;if(0===n||0===r)return[];let h=s?s*l/360:0,o=h?Math.sin(h):0,x=h?Math.cos(h):1,c=x*(e.x-i)/2+o*(e.y-y)/2,f=-o*(e.x-i)/2+x*(e.y-y)/2;if(0===c&&0===f)return[];n=Math.abs(n),r=Math.abs(r);let g=c*c/(n*n)+f*f/(r*r);if(g>1){let e=Math.sqrt(g);n*=e,r*=e}let d=n*n,M=n===r?d:r*r,v=c*c,m=f*f,b=d*M-d*m-M*v;b<=0?b=0:(b/=d*m+M*v,b=Math.sqrt(b)*(p===u?-1:1));let A=b?b*n/r*f:0,C=b?b*-r/n*c:0,L=x*A-o*C+(e.x+i)/2,w=o*A+x*C+(e.y+y)/2,P=(c-A)/n,E=(f-C)/r,S=(-c-A)/n,I=(-f-C)/r;const k=(e,t,a,l)=>{let n=+(e*a+t*l).toFixed(9);return 1===n||-1===n?1===n?0:Math.PI:(n=n>1?1:n<-1?-1:n,(e*l-t*a<0?-1:1)*Math.acos(n))};let D=k(1,0,P,E),$=k(P,E,S,I);0===u&&$>0?$-=2*Math.PI:1===u&&$<0&&($+=2*Math.PI);let Q=(+(Math.abs($)/(l/4)).toFixed(0)||1)*a;$/=Q;let T=[];const z=1.5707963267948966,q=.551785;let F=$===z?q:$===-z?-q:4/3*Math.tan($/4),j=$?Math.cos($):1,R=$?Math.sin($):0;const Z=(e,t,a,l,n)=>{let r=e!=t?Math.cos(e):l,s=e!=t?Math.sin(e):n,p=Math.cos(e+t),u=Math.sin(e+t);return[{x:r-s*a,y:s+r*a},{x:p+u*a,y:u-p*a},{x:p,y:u}]};for(let e=0;e<Q;e++){let e={type:"C",values:[]};Z(D,$,F,j,R).forEach(t=>{let a=t.x*n,l=t.y*r;e.values.push(x*a-o*l+L,o*a+x*l+w)}),T.push(e),D+=$}return T}function ge(e,{tolerance:t=1,flatBezierToLinetos:a=!0}={}){let l=[e[0]],n={x:e[0].values[0],y:e[0].values[1]},r=n,s=n;e[e.length-1].type.toLowerCase();for(let p=1,u=e.length;p<u;p++){let i=e[p],y=e[p+1]||e[u-1],h="z"===y.type.toLowerCase()?n:{x:y.values[y.values.length-2],y:y.values[y.values.length-1]},{type:o,values:x}=i,c=x.slice(-2);s="Z"!==o?{x:c[0],y:c[1]}:n;let f=h?X([r,s,h],!0):1/0,g=j(r,h),d=f<(g?g/333*t:0),M=!1;if(a||"C"!==o||(d=!1),a&&("C"===o||"Q"===o)){M=ae([r,..."C"===o?[{x:x[0],y:x[1]},{x:x[2],y:x[3]}]:"Q"===o?[{x:x[0],y:x[1]}]:[],s],{tolerance:t}),M&&p<u-1&&(o="L",i.type="L",i.values=c)}d&&p<u-1&&"A"!==y.type&&("L"===o||a&&M)||(r=s,"M"===o&&(n=s),l.push(i))}return l}function de(e){let t={x:e[0].values[0],y:e[0].values[1]},a=t,l=[e[0]];for(let n=1,r=e.length;n<r;n++){let r=e[n],s=e[n-1],p=e[n+1]||null,{type:u,values:i}=r,y="m"===s.type.toLowerCase()&&!p,h=i.length;if(a={x:i[h-2],y:i[h-1]},y||"L"!==u||a.x!==t.x||a.y!==t.y){if(!y&&("l"===u||"v"===u||"h"===u)){if("l"===u?"00"===i.join(""):0===i[0])continue}l.push(r),t=a}}return l}function Me(e){let t=e.length;if(!("z"===e[t-1].type.toLowerCase()))return e;let a=0,l=[];for(let a=0;a<t;a++){let t=e[a],{type:n,values:r}=t,s=r.length;if(s){let e={type:n,x:r[s-2],y:r[s-1],index:0};e.index=a,l.push(e)}}return l=l.sort((e,t)=>+e.y.toFixed(8)-+t.y.toFixed(8)||e.x-t.x),a=l[0].index,a?me(e,a):e}function ve(e,{removeFinalLineto:t=!0,autoClose:a=!0}={}){let l=[],n=e.length,r={x:+e[0].values[0].toFixed(8),y:+e[0].values[1].toFixed(8)},s="z"===e[n-1].type.toLowerCase(),p=e.filter(e=>"L"===e.type),u=e[s?n-2:n-1],i=u.type,y=u.values.slice(-2).map(e=>+e.toFixed(8)),h=y[0]===r.x&&y[1]===r.y;!s&&a&&h&&(e.push({type:"Z",values:[]}),s=!0,n++);let o="L"!==e[1].type&&(!h||"L"===u.type);if(o=!1,!s)return e;let x=0;{let t=[];for(let a=0;a<n;a++){let l=e[a],{type:n,values:r}=l;if(r.length){let l=r.slice(-2),s=e[a-1]&&"L"===e[a-1].type,p=e[a+1]&&"L"===e[a+1].type,u=e[a-1]?e[a-1].type.toUpperCase():null,i=e[a+1]?e[a+1].type.toUpperCase():null,y={type:n,x:l[0],y:l[1],dist:0,index:0,prevL:s,nextL:p,prevCom:u,nextCom:i};y.index=a,t.push(y)}}if(p.length){let e=t.filter(e=>"L"!==e.type&&"M"!==e.type&&e.prevCom&&"L"===e.prevCom||"M"===e.prevCom&&"L"===i).sort((e,t)=>e.y-t.y||e.x-t.x)[0];x=e?e.index-1:0}else t=t.sort((e,t)=>+e.y.toFixed(8)-+t.y.toFixed(8)||e.x-t.x),x=t[0].index;e=x?me(e,x):e}return r={x:+e[0].values[0].toFixed(8),y:+e[0].values[1].toFixed(8)},n=e.length,u=e[n-2],i=u.type,y=u.values.slice(-2).map(e=>+e.toFixed(8)),h="L"===i&&y[0]===r.x&&y[1]===r.y,t&&h&&e.splice(n-2,1),l.push(...e),l}function me(e,t){let a=0,l="z"===e[e.length-1].type.toLowerCase();if(!l||t<1||e.length<3)return e;let n=l?1:0;!function(e){let t=e.length,a="z"===e[t-1].type.toLowerCase(),l=e[0],[n,r]=[l.values[0],l.values[1]].map(e=>+e.toFixed(8)),s=a?e[t-2]:e[t-1],p=s.values.length,[u,i]=[s.values[p-2],s.values[p-1]].map(e=>+e.toFixed(8));!a||n==u&&r==i||(e.pop(),e.push({type:"L",values:[n,r]},{type:"Z",values:[]}))}(e),a=t+1<e.length-1?t+1:e.length-1-n;let r,s,p=e.slice(a),u=e.slice(0,a);return u.shift(),r=u[u.length-1].values||[],s=[r[r.length-2],r[r.length-1]],n&&(p.pop(),u.push({type:"Z",values:[]})),e=[{type:"M",values:s},...p,...u]}function be(e,{threshold:t=null,tolerance:a=1}={}){if(!t){let a=function(e){let t=1/0,a=-1/0,l=1/0,n=-1/0;const r=e=>{e.x<t&&(t=e.x),e.x>a&&(a=e.x),e.y<l&&(l=e.y),e.y>n&&(n=e.y)};for(let t=0;t<e.length;t++){let a=e[t],{type:l,values:n}=a,s=n.length,p=(e[t-1]?e[t-1]:e[t]).values,u=p.length;if(s){let e={x:p[u-2],y:p[u-1]},t={x:n[s-2],y:n[s-1]};if(r(t),"C"===l||"Q"===l){let a={x:n[0],y:n[1]},s="C"===l?{x:n[2],y:n[3]}:a,p="C"===l?[e,a,s,t]:[e,a,t];D(p).forEach(e=>{let t=w(p,e);r(t)})}else"A"===l&&$(e,n).forEach(e=>{r(e)})}}return{x:t,y:l,width:a-t,height:n-l}}(e);t=.05*(a.width+a.height)}let l=e.length;for(let n=0;n<l;n++){let l=e[n],{type:r,values:s,extreme:p,corner:u=!1,dimA:i,p0:y,p:h}=l,o=e[n+1]?e[n+1]:null,x=e[n+2]?e[n+2]:null,c=(o?R(h,o.p):1/0)<t,f=(x?R(x.p,o.p):1/0)<1*t;if(o&&x&&"C"===r&&"C"===o.type&&p&&x.extreme&&(f||c)){let l=_(o,x,t,a,!1);if(1===l.length){l=l[0],e[n+1]=null,e[n+2].values=[l.cp1.x,l.cp1.y,l.cp2.x,l.cp2.y,l.p.x,l.p.y],e[n+2].cp1=l.cp1,e[n+2].cp2=l.cp2,e[n+2].p0=l.p0,e[n+2].p=l.p,e[n+2].extreme=l.extreme,n++;continue}}if(o&&"C"===r&&"C"===o.type&&p&&c){let e=X([l.p0,l.p,o.p]),t=X([l.p0,l.cp1,l.cp2,l.p]);if(e<0&&t>0||e>0&&t<0)continue}}l=(e=e.filter(Boolean)).length;let n="z"===e[l-1].type.toLowerCase()?l-2:l-1,r=e[n],s=e[n-1]||null,p={x:e[0].values[0],y:e[0].values[1]},u=r.values.slice(-2),i=+u[0].toFixed(8)===+p.x.toFixed(8)&&+u[1].toFixed(8)===+p.y.toFixed(8),y="C"===e[1].type&&e[1].extreme?e[1]:null,h=R(r.p0,r.p)<t;if(s&&"C"===s.type&&h&&i&&y){let l=_(s,r,t,a,!1);1===l.length&&(e[n-1]=l[0],e[n]=null,e=e.filter(Boolean))}return e}function Ae(e,{threshold:t=0,tolerance:a=1}={}){let l=e.length,n=[e[0]],r="z"===e[l-1].type.toLowerCase(),s=!!r&&(e[l-1].p.x===e[0].p0.x&&e[l-1].p.y===e[0].p0.y),p=r?2:1,u=e[l-p],i="L"===u.type,y="C"===u.type,h="L"===e[1].type,o="C"===e[1].type,x=r&&o&&(i||s);x&&(e[l-1].values=e[0].values,e[l-1].type="L",i=!0);for(let t=1;t<l;t++){let s=e[t],{type:u}=s,c=e[t+1]?e[t+1]:null;if("L"===u&&c&&"C"===c.type||"C"===u&&c&&"L"===c.type){let x="L"===u?s:null,f=null,g=[],d=0;if(1===t&&o&&i&&(g=[e[1]],x=e[l-1],f=c),!x){n.push(s);continue}r&&y&&h&&t===l-p-1&&(f=e[1],g=[e[l-p]]);for(let a=t+1;a<l;a++){let t=e[a]?e[a]:null,l=e[a-1];if("C"===l.type&&g.push(l),"L"===t.type&&"C"===l.type){f=t;break}d++}if(f){let e=R(x.p0,x.p),l=R(f.p0,f.p),r=R(x.p,f.p0),p=X([x.p0,x.p,f.p0,f.p],!1),u=X([g[0].p0,g[0].cp1,g[0].cp2,g[0].p],!1),i=p<0&&u>0||p>0&&u<0,y=.5*r*a,h=y<e&&y<l;if(g.length&&!i&&h){let e=Math.abs(u)<.005*j(g[0].p0,g[0].p)?null:C(x.p0,x.p,f.p,f.p0,!1,!0);if(!e){n.push(s);continue}if(e){let t=X([x.p0,x.p,f.p0,f.p],!1),a=Math.abs(t),l=X([x.p0,x.p,e,f.p0,f.p],!1),r=Math.abs(l),p=Math.abs(a-r)/a;if(!e||(t<0&&l>0||t>0&&l<0)||p>.5){n.push(s);continue}}let a=.75*R(w([x.p,e,f.p0],.5),1===g.length?w([g[0].p0,g[0].cp1,g[0].cp2,g[0].p],.5):g[0].p);if(y&&a>y&&a>.3*r){n.push(s);continue}{let a={type:"Q",values:[e.x,e.y,f.p0.x,f.p0.y]};a.p0=x.p,a.cp1=e,a.p=f.p0,n.push(x,a),t+=d;continue}}}}x&&t===l-1&&"L"===u||n.push(s)}return(x||r&&"Z"!==n[n.length-1].type)&&n.push({type:"Z",values:[]}),n}function Ce(e){if(e.length<3)return!1;let t=e[0],a=e[Math.floor(e.length/2)],l=e[e.length-1],n=t.x,r=t.y,s=a.x,p=a.y,u=l.x,i=l.y,y=n-s,h=r-p,o=n-u,x=r-i,c=(n*n-s*s+(r*r-p*p))/2,f=(n*n-u*u+(r*r-i*i))/2,g=y*x-h*o;if(Math.abs(g)<1e-10)return console.warn("Points are collinear or numerically unstable"),!1;let d={x:(x*c-h*f)/g,y:(-o*c+y*f)/g},M=F(d,t),v=A(d,t,l),{deltaAngle:m,startAngle:b,endAngle:C}=v;return{centroid:d,r:M,startAngle:b,endAngle:C,deltaAngle:m}}function Le(e,{threshold:a=0,tolerance:l=1,toCubic:n=!1,debug:r=!1}={}){let s=e.length,p=[e[0]],u=[];for(let a=1;a<s;a++){let l=e[a],{type:s}=l,i=e[a-1],y=e[a+1]?e[a+1]:null,h=e[a+2]?e[a+2]:null,o=e[a+3]?e[a+3]:null,x=null;"C"===l.type||"Q"===l.type?x=l:!y||"C"!==y.type&&"Q"!==y.type||(x=y);let c,f,g,d,M,v=x?"C"===x.type?[x.p0,x.cp1,x.cp2,x.p]:[x.p0,x.cp1,x.p]:[],m=0,b=0,A=!1,C=!1,L=[];if("L"===i.type&&"L"===s&&x&&"L"===h.type&&o&&("L"===o.type||"Z"===o.type)?(c=[l.p0,l.p],f=[h.p0,h.p],g=l.p0,d=h.p,m=X(v,!1),b=X([...c,...f],!1),A=m<0&&b>0||m>0&&b<0,A||(M=w(v,.5),L=[g,M,d],C=!0)):"C"!==s&&"Q"!==s||"L"!==i.type||"C"!==y.type&&"Q"!==y.type||"L"!==h.type||(C=!0,c=[i.p0,i.p],f=[h.p0,h.p],g=i.p,d=h.p0,M=x.p,L=[g,x.p,d]),C){let e=Ce(L);if(e){let s,{centroid:i,r:y,deltaAngle:h,startAngle:o,endAngle:x}=e,c=0,f=h>0?1:0,v=Math.abs(h)>Math.PI?1:0;if(Z(E(g,i.x,i.y,.5*h),M)<.05*Z(g,d)){if(s=ce({p0:g,p:d,centroid:i,rx:y,ry:y,xAxisRotation:c,sweep:f,largeArc:v,deltaAngle:h,startAngle:o,endAngle:x}),1===s.length){let e=ye(g,s[0].cp1,s[0].cp2,d);"Q"===e.type&&(n=!0),l=e}if(s.length>1&&(n=!1),n||(l.type="A",l.values=[y,y,c,v,f,d.x,d.y]),l.p0=g,l.p=d,l.extreme=!1,l.corner=!1,r){u=n?[{type:"M",values:[g.x,g.y]},...s]:[{type:"M",values:[g.x,g.y]},{type:"A",values:[y,y,c,v,f,d.x,d.y]}];let e=Y(u);t(markers,e,"orange","0.5%","0.5")}p.push(l),a++;continue}}}p.push(l)}return p}function we(e=[],{threshold:t=0}={}){let a=e.length,l="z"===e[a-1].type.toLowerCase(),n=l?a-2:a-1,r=e[n],s=r.values.slice(-2),p={x:e[0].values[0],y:e[0].values[1]},u=Z(p,{x:s[0],y:s[1]});if(u&&u<t){let a=e[n].values.length;e[n].values[a-2]=p.x,e[n].values[a-1]=p.y;let l=e[1];if("C"===l.type&&"C"===r.type){let a=Math.abs(l.values[0]-r.values[2]),s=Math.abs(l.values[1]-r.values[3]),u=Math.abs(e[1].values[0]-l.values[0]),i=Math.abs(e[1].values[1]-l.values[1]),y=Math.abs(e[1].values[0]-r.values[2]),h=Math.abs(e[1].values[1]-r.values[3]),o=i<t&&h<t&&a;a&&a<t&&(u<t&&y<t&&s)&&(e[1].values[0]=p.x,e[n].values[2]=p.x),s&&s<t&&o&&(e[1].values[1]=p.y,e[n].values[3]=p.y)}}return e}function Pe(e,t=1){for(let a=1,l=e.length;a<l;a++){let l=e[a],{type:n,values:r,p0:s,cp1:p=null,cp2:u=null,p:i=null}=l;if("C"===n){let n=ye(s,p,u,i,t);"Q"===n.type&&(n.extreme=l.extreme,n.corner=l.corner,n.dimA=l.dimA,n.squareDist=l.squareDist,e[a]=n)}}return e}function Ee(e){for(let t=1,a=e.length;t<a;t++){let a=e[t],{type:l,values:n,p0:r,cp1:s=null,cp2:p=null,p:u=null}=a;if("L"===l){let a=L(r,u,.333),l=L(u,r,.333);e[t].type="C",e[t].values=[a.x,a.y,l.x,l.y,u.x,u.y],e[t].cp1=a,e[t].cp2=l}}return e}function Se(e="",{toAbsolute:t=!0,toRelative:a=!0,toShorthands:l=!0,quadraticToCubic:n=!0,arcToCubic:r=!1,cubicToArc:s=!1,simplifyBezier:p=!0,optimizeOrder:u=!0,autoClose:i=!0,removeZeroLength:y=!0,refineClosing:h=!0,removeColinear:o=!0,flatBezierToLinetos:x=!0,revertToQuadratics:c=!0,refineExtremes:f=!0,simplifyCorners:g=!1,fixDirections:d=!1,keepExtremes:M=!0,keepCorners:v=!0,keepInflections:m=!1,addExtremes:b=!1,addSemiExtremes:A=!1,harmonizeCpts:C=!1,toPolygon:L=!1,removeOrphanSubpaths:w=!1,simplifyRound:P=!1,decimals:E=3,autoAccuracy:S=!0,minifyD:I=0,tolerance:k=1,lineToCubic:D=!1,getObject:$=!1}={}){k=Math.max(.1,k);let Q="",T={x:0,y:0,width:0,height:0},z=[],q=[],F=function(e){let t="string";if(Array.isArray(e)){if(Array.isArray(e[0])){if(2===e[0].length)return"polyArray";if(Array.isArray(e[0][0])&&2===e[0][0].length)return"polyComplexArray";if(void 0!==e[0][0].x&&void 0!==e[0][0].y)return"polyComplexObjectArray"}else{if(void 0!==e[0].x&&void 0!==e[0].y)return"polyObjectArray";if(e[0]?.type&&e[0]?.values)return"pathData"}return"array"}if("string"==typeof e){let a=(e=e.trim()).includes("<svg")&&e.includes("</svg"),l=e.startsWith("M")||e.startsWith("m"),n=!isNaN(e.substring(0,1))&&!isNaN(e.substring(e.length-1,e.length));if(a)t="svgMarkup";else if(l)t="pathDataString";else if(n)t="polyString";else{let a=/^(file:|https?:\/\/|\/|\.\/|\.\.\/)/.test(e),l=e.startsWith("data:image");t=a||l?"url":"string"}return t}return t=typeof e,(e.constructor.name||t).toLowerCase()}(e);if("pathDataString"===F)Q=e;else if("polyString"===F)Q="M"+e;else{if("pathData"!==F)return!1;Q=e}let j={toRelative:a,toShorthands:l,decimals:E},Z=ue(Q,{quadraticToCubic:n,toAbsolute:t,arcToCubic:r});Z.length,w&&(Z=function(e){let t=[];for(let a=0,l=e.length;a<l;a++){let l=e[a];if(!l)continue;let{type:n=null,values:r=[]}=l,s=e[a+1]?e[a+1]:null;"M"!==n&&"m"!==n||s&&(!s||"Z"!==s.type&&"z"!==s.type)?t.push(l):s&&a++}return t}(Z));let B=O(Z),N=B.length,J=[];for(let e=0;e<N;e++){let t=B[e];(o||y)&&(t=de(t)),u&&(t=Me(t)),o&&(t=ge(t,{tolerance:k,flatBezierToLinetos:!1})),(b||A)&&(t=H(t,{tMin:tMin,tMax:tMax,addExtremes:b,addSemiExtremes:A,angles:[30]}));let a=le(t,{detectSemiExtremes:A}),{pathData:l,bb:n,dimA:r}=a;if(z.push(n.x,n.x+n.width),q.push(n.y,n.y+n.height),h&&(l=we(l,{threshold:.001*r})),l=p?ee(l,{simplifyBezier:p,keepInflections:m,keepExtremes:M,keepCorners:v,revertToQuadratics:c,tolerance:k}):l,f){l=be(l,{threshold:.05*(n.width+n.height),tolerance:k})}if(o&&x&&(l=ge(l,{tolerance:k,flatBezierToLinetos:x})),g){l=Ae(l,{threshold:.1*(n.width+n.height),tolerance:k})}P&&(l=Le(l)),c&&(l=Pe(l,k)),D&&(l=Ee(l)),u&&(l=ve(l,{autoClose:i})),J.push({pathData:l,bb:n})}let U=Math.min(...z),V=Math.min(...q);T={x:U,y:V,width:Math.max(...z)-U,height:Math.max(...q)-V},u&&(J=T.height>T.width?J.sort((e,t)=>e.bb.y-t.bb.y||e.bb.x-t.bb.x):J.sort((e,t)=>e.bb.x-t.bb.x||e.bb.y-t.bb.y)),Z=[],J.forEach(e=>{Z.push(...e.pathData)}),S&&(E=function(e){let t=[];for(let a=1,l=e.length;a<l;a++){let l=e[a],{type:n,values:r,p0:s=null,p:p=null,dimA:u=0}=l;r.length&&p&&s&&(u=u||R(s,p),u&&t.push(u))}let a=t.sort(),l=Math.ceil(a.length/8);a=a.slice(0,l);let n=a.reduce((e,t)=>e+t,0)/l,r=n>112.5?0:Math.floor(75/n).toString().length;return Math.min(Math.max(0,r),8)}(Z),j.decimals=E),Z=ie(Z,j),Z=de(Z);let W=Y(Z,I);return $&&(Z=Z.map(e=>({type:e.type,values:e.values}))),$?Z:W}"undefined"!=typeof window&&(window.simplifyPathData=Se);export{Se as simplifyPathData};
|
package/docs/api.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# API
|
|
2
|
+
**svg-path-simplify** aims at a convenient usage concept applying as much reasonable
|
|
3
|
+
default parameters as possible to get a good optimization – without screwing up your SVG.
|
|
4
|
+
It expects at least one input parameter which is the actual SVG data:
|
|
5
|
+
|
|
6
|
+
```js
|
|
7
|
+
let output = svgPathSimplify(input);
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Allowed inputs
|
|
11
|
+
`input` could be:
|
|
12
|
+
* a path data string – as used in SVG `<path>` element's `d` attribute
|
|
13
|
+
* a pathData object array – retrieved via SVG2 `getPathData()` (natively supported by Firefox)
|
|
14
|
+
* a polygon string – as used in SVG `<polygon>` element's `points` attribute
|
|
15
|
+
* a polygon:
|
|
16
|
+
- polygon point object array `[{x:0, y:0}]`
|
|
17
|
+
- polygon point value array `[{0, 0]`
|
|
18
|
+
* an entire `<svg>` markup string `<svg></svg>`
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Options
|
|
22
|
+
For more fine grained controls you can add options to the 2nd parameter.
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
let options = {}
|
|
26
|
+
let output = svgPathSimplify(input, options);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The options divide into these categories:
|
|
30
|
+
|
|
31
|
+
* path simplification – also applied when processing entire SVGs
|
|
32
|
+
* SVG document cleanup
|
|
33
|
+
* polygon conversions
|
|
34
|
+
|
|
35
|
+
All of these main categories are split into **»default«** and **»advanced«** settings.
|
|
36
|
+
The advanced options should ideally only applied after testing in the [webapp](https://herrstrietzel.github.io/svg-path-simplify). These will often increase processing time significantly but may help to get a more compact output.
|
|
37
|
+
|
|
38
|
+

|
|
39
|
+
|
|
40
|
+
The webapp also provides a object output you can copy for customized JS usage! You can find it in the 2nd column right at the bottom (collapsed by default)
|
|
41
|
+
|
|
42
|
+
Also, these options are disabled by default to mitigate problems in batch processing.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## Path simplifications/optimizations
|
|
46
|
+
|
|
47
|
+
These params control which simplifications are applied. The default settings aim at a safe or balanced performance-to-minification ratio. However if your main goal is to get the most compact result you can enable additional options which also require more processing time.
|
|
48
|
+
|
|
49
|
+
| parameter | effect | type | default |
|
|
50
|
+
| -- | -- | -- | -- |
|
|
51
|
+
| simplifyBezier | main Bézier simplification. When disabled you get the common optimization similar to SVGO (rounding, to all relative and shorthand conversions) | Boolean | true |
|
|
52
|
+
| tolerance | increase or decrease tolerance: higher values allow more distortions, lower ones more shape fidelity | Number | 1 |
|
|
53
|
+
| optimizeOrder | reorders commands to get more adjacent simplification candidates. Improves optimization efficiency | Boolean | true |
|
|
54
|
+
| removeColinear | removes unnecessary zero-length or colinear lineto commands | Boolean | true |
|
|
55
|
+
| flatBezierToLinetos | replaces flat Béziers with linetos which also can be stripped via previous colinear removal | Boolean | true |
|
|
56
|
+
| revertToQuadratics | replaces cubic Béziers with quadratic (more compact) ones when applicable | Boolean | true |
|
|
57
|
+
|
|
58
|
+
### Limit simplification
|
|
59
|
+
|
|
60
|
+
These params specify which geometry features should be retained – prevents undesired distortions.
|
|
61
|
+
|
|
62
|
+
| parameter | effect | type | default |
|
|
63
|
+
| -- | -- | -- | -- |
|
|
64
|
+
| keepExtremes | skips simplification across x/y extrema – improves shape fidelity | Boolean | true |
|
|
65
|
+
| keepCorners | skips simplification corners – improves shape fidelity | Boolean | true |
|
|
66
|
+
| keepInflections | retains commands introducing direction changes – adds complexity but may help for editing in a graphic application | Boolean | false |
|
|
67
|
+
|
|
68
|
+
### Advanced path simplifications
|
|
69
|
+
| parameter | effect | type | default |
|
|
70
|
+
| -- | -- | -- | -- |
|
|
71
|
+
| refineExtremes | tries to combine commands close to an adjacent x/y extreme segment | Boolean | false |
|
|
72
|
+
| addExtremes | adds commands at x/y extrema – adds complexity but may help for editing in a graphic application – when using this option enable `refineExtremes` as well to avoid tiny adjacent segments | Boolean | false |
|
|
73
|
+
| simplifyCorners | replaces Bézier segments enclosed by linetos with single quadratic commands – handy to reduce overly complex tiny corner roundings. See example in [webapp](https://herrstrietzel.github.io/svg-path-simplify?samples=fontawesome_gears&refineExtremes=true&simplifyCorners=true) | Boolean | false |
|
|
74
|
+
| cubicToArc | replaces Bézier segments by elliptic arc `A` commands where applicable – can reduce complexity for semi- or full circles | Boolean | false |
|
|
75
|
+
| simplifyRound | replaces small round segments encloses by linetos – helps to simplify shapes like gears/cogs | Boolean | false |
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
### Path direction
|
|
79
|
+
| parameter | effect | type | default |
|
|
80
|
+
| -- | -- | -- | -- |
|
|
81
|
+
| fixDirections | alternates sub path directions to fulfill non-zero. Makes fill-rule attribute obsolete and render correct in other environments e.g when converting to fonts | Boolean | false |
|
|
82
|
+
| reversePath | simply reverses drawing direction - sometimes needed for line animations | Boolean | false |
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
### Polygon options
|
|
87
|
+
| parameter | effect | type | default |
|
|
88
|
+
| -- | -- | -- | -- |
|
|
89
|
+
| smoothPoly | Curve-fitting: Converts polylines to cubic beziers | Boolean | false |
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### Output options
|
|
94
|
+
|
|
95
|
+
| parameter | effect | type | default |
|
|
96
|
+
| -- | -- | -- | -- |
|
|
97
|
+
| getObject | whether to return the SVG/pathdata markup directly or a detailed object (containing more info) | Boolean | true |
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
### SVG output optimizations
|
|
101
|
+
| parameter | effect | type | default |
|
|
102
|
+
| -- | -- | -- | -- |
|
|
103
|
+
| autoAccuracy | calculates a suitable floating point precision for coordinate rounding. Usually rather conservative – decreasing by one decimal should work without significant distortions | Boolean | true |
|
|
104
|
+
| decimals | manual floating point rounding precision – overriden when `autoAccuracy` is enabled | Number | 3 |
|
|
105
|
+
| minifyD | path data microoptimization: removes recurring command type tokens, whitespace and leading zeroes: 0: maximum optimization; 1: "verbose" dont't omit command type tokes; 2: "beautify" separate each command with new lines (e.g for educational purposes) | Number | 0 |
|
|
106
|
+
| toRelative | converts all commands to relative – reduces file size | Boolean | true |
|
|
107
|
+
| toShorthands | converts all commands to shorthand when applicable – reduces file size | Boolean | true |
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
### SVG scaling
|
|
111
|
+
Scaling only indirectly affects file size analogous to rounding. Use it only for very large or small SVGs. Finding the »sweet spot« where all coordinates can be expressed in integers can reduce file size as no decimal separators are required.
|
|
112
|
+
|
|
113
|
+
| parameter | effect | type | default |
|
|
114
|
+
| -- | -- | -- | -- |
|
|
115
|
+
| scale | scales all pathdata, `viewBox`, `width` and `height` attributes | Boolean | true |
|
|
116
|
+
| scaleTo | scales to a specified max width | Boolean | false |
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
### SVG input normalization
|
|
120
|
+
| parameter | effect | type | default |
|
|
121
|
+
| -- | -- | -- | -- |
|
|
122
|
+
| quadraticToCubic | converts all quadratic Béziers to cubics – recommended for efficiency | Boolean | true |
|
|
123
|
+
| arcToCubic | converts elliptic arc `A` commands to cubic approximations – not recommended | Boolean | false |
|
|
124
|
+
| removeHidden | removes hidden elements for SVG inputs | Boolean | true |
|
|
125
|
+
| mergePaths | concatenates paths into single one – does not respect individual styles! | Boolean | false |
|
|
126
|
+
| shapesToPaths | converts shapes to paths - usually not recommended as shapes are most often more compact. But useful for path concatenation | Boolean | false |
|
|
127
|
+
| stylesToAttributes | consolidates styles and set them to attributes. Also removes invalid attributes (e.g `font-family` for paths) | Boolean | false |
|