svg-path-commander 0.1.21 → 0.1.22
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/README.md +72 -12
- package/dist/svg-path-commander.esm.js +647 -190
- package/dist/svg-path-commander.esm.min.js +2 -2
- package/dist/svg-path-commander.js +670 -189
- package/dist/svg-path-commander.min.js +2 -2
- package/package.json +1 -1
- package/src/convert/pathToAbsolute.js +3 -2
- package/src/convert/pathToCurve.js +2 -1
- package/src/convert/pathToRelative.js +2 -1
- package/src/parser/paramsCount.js +1 -0
- package/src/parser/parsePathString.js +4 -3
- package/src/parser/pathParser.js +2 -1
- package/src/parser/scanSegment.js +0 -1
- package/src/process/fixPath.js +1 -1
- package/src/process/lineToCubic.js +4 -5
- package/src/process/normalizePath.js +4 -2
- package/src/util/getClosestPoint.js +12 -0
- package/src/util/getCubicSize.js +41 -39
- package/src/util/getPathArea.js +19 -19
- package/src/util/getPathBBox.js +0 -11
- package/src/util/getPathLength.js +9 -9
- package/src/util/getPointAtLength.js +6 -29
- package/src/util/getPointAtPathLength.js +44 -0
- package/src/util/getPropertiesAtLength.js +62 -0
- package/src/util/getPropertiesAtPoint.js +77 -0
- package/src/util/getSegmentAtLength.js +13 -0
- package/src/util/getSegmentOfPoint.js +14 -0
- package/src/util/getTotalLength.js +15 -0
- package/src/util/isAbsoluteArray.js +2 -1
- package/src/util/isCurveArray.js +2 -1
- package/src/util/isNormalizedArray.js +2 -1
- package/src/util/isPointInStroke.js +13 -0
- package/src/util/isRelativeArray.js +2 -1
- package/src/util/pathLengthFactory.js +99 -0
- package/src/util/segmentArcFactory.js +42 -0
- package/src/util/segmentCubicFactory.js +73 -0
- package/src/util/segmentLineFactory.js +30 -0
- package/src/util/segmentQuadFactory.js +70 -0
- package/src/util/util.js +19 -1
- package/types/index.d.ts +14 -5
- package/types/more/modules.ts +17 -5
- package/types/more/svg.d.ts +21 -0
- package/types/svg-path-commander.d.ts +242 -122
- package/src/util/getPointAtSegLength.js +0 -28
- package/src/util/getSegArcLength.js +0 -27
- package/src/util/getSegCubicLength.js +0 -52
- package/src/util/getSegLineLength.js +0 -14
- package/src/util/getSegQuadLength.js +0 -31
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// SVGPathCommander v0.1.
|
|
2
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SVGPathCommander=e()}(this,(function(){"use strict";var t={origin:[0,0,0],round:4},e={a:7,c:6,h:1,l:2,m:2,r:4,q:4,s:4,t:2,v:1,z:0};function r(t){var r=t.pathValue[t.segmentStart],n=r.toLowerCase(),a=t.data;for("m"===n&&a.length>2&&(t.segments.push([r,a[0],a[1]]),a=a.slice(2),n="l",r="m"===r?"l":"L");a.length>=e[n]&&(t.segments.push([r].concat(a.splice(0,e[n]))),e[n]););}function n(t){var e=t.index,r=t.pathValue.charCodeAt(e);return 48===r?(t.param=0,void(t.index+=1)):49===r?(t.param=1,void(t.index+=1)):void(t.err='Invalid path value: invalid Arc flag "'+r+'", expecting 0 or 1 at index '+e)}function a(t){return t>=48&&t<=57}function i(t){var e,r=t.max,n=t.pathValue,i=t.index,s=i,o=!1,c=!1,u=!1,m=!1;if(s>=r)t.err="Invalid path value at "+s+": missing param "+n[s];else if(43!==(e=n.charCodeAt(s))&&45!==e||(e=(s+=1)<r?n.charCodeAt(s):0),a(e)||46===e){if(46!==e){if(o=48===e,e=(s+=1)<r?n.charCodeAt(s):0,o&&s<r&&e&&a(e))return void(t.err="Invalid path value at index "+i+": "+n[i]+" illegal number");for(;s<r&&a(n.charCodeAt(s));)s+=1,c=!0;e=s<r?n.charCodeAt(s):0}if(46===e){for(m=!0,s+=1;a(n.charCodeAt(s));)s+=1,u=!0;e=s<r?n.charCodeAt(s):0}if(101===e||69===e){if(m&&!c&&!u)return void(t.err="Invalid path value at index "+s+": "+n[s]+" invalid float exponent");if(43!==(e=(s+=1)<r?n.charCodeAt(s):0)&&45!==e||(s+=1),!(s<r&&a(n.charCodeAt(s))))return void(t.err="Invalid path value at index "+s+": "+n[s]+" invalid float exponent");for(;s<r&&a(n.charCodeAt(s));)s+=1}t.index=s,t.param=+t.pathValue.slice(i,s)}else t.err="Invalid path value at index "+s+": "+n[s]+" is not a number"}function s(t){for(var e,r=t.pathValue,n=t.max;t.index<n&&(10===(e=r.charCodeAt(t.index))||13===e||8232===e||8233===e||32===e||9===e||11===e||12===e||160===e||e>=5760&&[5760,6158,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288,65279].indexOf(e)>=0);)t.index+=1}function o(t){return t>=48&&t<=57||43===t||45===t||46===t}function c(t){var a=t.max,c=t.pathValue,u=t.index,m=c.charCodeAt(u),h=e[c[u].toLowerCase()];if(t.segmentStart=u,function(t){switch(32|t){case 109:case 122:case 108:case 104:case 118:case 99:case 115:case 113:case 116:case 97:return!0;default:return!1}}(m))if(t.index+=1,s(t),t.data=[],h){for(;;){for(var l=h;l>0;l-=1){if(97!=(32|m)||3!==l&&4!==l?i(t):n(t),t.err.length)return;t.data.push(t.param),s(t),t.index<a&&44===c.charCodeAt(t.index)&&(t.index+=1,s(t))}if(t.index>=t.max)break;if(!o(c.charCodeAt(t.index)))break}r(t)}else r(t);else t.err="Invalid path value: "+c[u]+" not a path command"}function u(t){return t.map((function(t){return Array.isArray(t)?[].concat(t):t}))}function m(t){this.segments=[],this.pathValue=t,this.max=t.length,this.index=0,this.param=0,this.segmentStart=0,this.data=[],this.err=""}function h(t){return Array.isArray(t)&&t.every((function(t){var r=t[0].toLowerCase();return e[r]===t.length-1&&"achlmqstvz".includes(r)}))}function l(t){if(Array.isArray(t)&&h(t))return u(t);var e=new m(t);for(s(e);e.index<e.max&&!e.err.length;)c(e);return e.err.length?e.segments=[]:e.segments.length&&("mM".includes(e.segments[0][0])?e.segments[0][0]="M":(e.err="Invalid path value: missing M/m",e.segments=[])),e.segments}function f(t){return h(t)&&t.every((function(t){return t[0]===t[0].toUpperCase()}))}function p(t){if(Array.isArray(t)&&f(t))return u(t);var e=l(t),r=0,n=0,a=0,i=0;return e.map((function(t){var e,s=t.slice(1).map(Number),o=t[0],c=o.toUpperCase();if("M"===o)return r=(e=s)[0],n=e[1],a=r,i=n,["M",r,n];var u=[];if(o!==c)switch(c){case"A":u=[c,s[0],s[1],s[2],s[3],s[4],s[5]+r,s[6]+n];break;case"V":u=[c,s[0]+n];break;case"H":u=[c,s[0]+r];break;default:var m=s.map((function(t,e){return t+(e%2?n:r)}));u=[c].concat(m)}else u=[c].concat(s);var h=u.length;switch(c){case"Z":r=a,n=i;break;case"H":r=u[1];break;case"V":n=u[1];break;default:r=u[h-2],n=u[h-1],"M"===c&&(a=r,i=n)}return u}))}function y(t){return h(t)&&t.slice(1).every((function(t){return t[0]===t[0].toLowerCase()}))}function v(t){if(y(t))return u(t);var e=l(t),r=0,n=0,a=0,i=0;return e.map((function(t){var e,s,o=t.slice(1).map(Number),c=t[0],u=c.toLowerCase();if("M"===c)return r=(e=o)[0],n=e[1],a=r,i=n,["M",r,n];var m=[];if(c!==u)switch(u){case"a":m=[u,o[0],o[1],o[2],o[3],o[4],o[5]-r,o[6]-n];break;case"v":m=[u,o[0]-n];break;case"h":m=[u,o[0]-r];break;default:var h=o.map((function(t,e){return t-(e%2?n:r)}));m=[u].concat(h),"m"===u&&(r=(s=o)[0],n=s[1],a=r,i=n)}else"m"===c&&(a=o[0]+r,i=o[1]+n),m=[u].concat(o);var l=m.length;switch(u){case"z":r=a,n=i;break;case"h":r+=m[1];break;case"v":n+=m[1];break;default:r+=m[l-2],n+=m[l-1]}return m}))}function d(t,e,r){if(t[r].length>7){t[r].shift();for(var n=t[r],a=r;n.length;)e[r]="A",t.splice(a+=1,0,["C"].concat(n.splice(0,6)));t.splice(r,1)}}function x(t,e,r){var n=t[0],a=e.x1,i=e.y1,s=e.x2,o=e.y2,c=t.slice(1).map(Number),u=t;if("TQ".includes(n)||(e.qx=null,e.qy=null),"H"===n)u=["L",t[1],i];else if("V"===n)u=["L",a,t[1]];else if("S"===n){var m=function(t,e,r,n,a){return"CS".includes(a)?{x1:2*t-r,y1:2*e-n}:{x1:t,y1:e}}(a,i,s,o,r),h=m.x1,l=m.y1;e.x1=h,e.y1=l,u=["C",h,l].concat(c)}else if("T"===n){var f=function(t,e,r,n,a){return"QT".includes(a)?{qx:2*t-r,qy:2*e-n}:{qx:t,qy:e}}(a,i,e.qx,e.qy,r),p=f.qx,y=f.qy;e.qx=p,e.qy=y,u=["Q",p,y].concat(c)}else if("Q"===n){var v=c[0],d=c[1];e.qx=v,e.qy=d}return u}function g(t){return f(t)&&t.every((function(t){return"ACLMQZ".includes(t[0])}))}var M={x1:0,y1:0,x2:0,y2:0,x:0,y:0,qx:null,qy:null};function b(t){if(g(t))return u(t);for(var e=p(t),r=Object.assign({},M),n=[],a=e.length,i="",s="",o=0;o<a;o+=1){i=e[o][0],n[o]=i,o&&(s=n[o-1]),e[o]=x(e[o],r,s);var c=e[o],m=c.length;r.x1=+c[m-2],r.y1=+c[m-1],r.x2=+c[m-4]||r.x1,r.y2=+c[m-3]||r.y1}return e}function w(t){var e=l(t),r=b(e),n=e.length,a="Z"===r.slice(-1)[0][0],i=a?n-2:n-1,s=r[0].slice(1),o=s[0],c=s[1],u=r[i].slice(-2),m=u[0],h=u[1];return a&&o===m&&c===h?e.slice(0,-1):e}function N(t){return h(t)&&t.every((function(t){return"MC".includes(t[0])}))}function A(t,e,r){return{x:t*Math.cos(r)-e*Math.sin(r),y:t*Math.sin(r)+e*Math.cos(r)}}function C(t,e,r,n,a,i,s,o,c,u){var m,h,l,f,p,y,v=t,d=e,x=r,g=n,M=o,b=c,w=120*Math.PI/180,N=Math.PI/180*(+a||0),k=[];if(u)l=(m=u)[0],f=m[1],p=m[2],y=m[3];else{v=(h=A(v,d,-N)).x,d=h.y;var S=(v-(M=(h=A(M,b,-N)).x))/2,q=(d-(b=h.y))/2,P=S*S/(x*x)+q*q/(g*g);P>1&&(x*=P=Math.sqrt(P),g*=P);var I=x*x,T=g*g,j=(i===s?-1:1)*Math.sqrt(Math.abs((I*T-I*q*q-T*S*S)/(I*q*q+T*S*S)));p=j*x*q/g+(v+M)/2,y=j*-g*S/x+(d+b)/2,l=(Math.asin((d-y)/g)*Math.pow(10,9)>>0)/Math.pow(10,9),f=(Math.asin((b-y)/g)*Math.pow(10,9)>>0)/Math.pow(10,9),l=v<p?Math.PI-l:l,f=M<p?Math.PI-f:f,l<0&&(l=2*Math.PI+l),f<0&&(f=2*Math.PI+f),s&&l>f&&(l-=2*Math.PI),!s&&f>l&&(f-=2*Math.PI)}var V=f-l;if(Math.abs(V)>w){var z=f,O=M,E=b;f=l+w*(s&&f>l?1:-1),k=C(M=p+x*Math.cos(f),b=y+g*Math.sin(f),x,g,a,0,s,O,E,[f,z,p,y])}V=f-l;var L=Math.cos(l),Q=Math.sin(l),Z=Math.cos(f),D=Math.sin(f),X=Math.tan(V/4),H=4/3*x*X,Y=4/3*g*X,R=[v,d],F=[v+H*Q,d-Y*L],B=[M+H*D,b-Y*Z],G=[M,b];if(F[0]=2*R[0]-F[0],F[1]=2*R[1]-F[1],u)return F.concat(B,G,k);for(var J=[],U=0,$=(k=F.concat(B,G,k)).length;U<$;U+=1)J[U]=U%2?A(k[U-1],k[U],N).y:A(k[U],k[U+1],N).x;return J}function k(t,e,r,n,a,i){return[1/3*t+2/3*r,1/3*e+2/3*n,1/3*a+2/3*r,1/3*i+2/3*n,a,i]}function S(t,e,r,n,a,i,s,o,c){var u=1-c;return{x:Math.pow(u,3)*t+u*u*3*c*r+3*u*c*c*a+Math.pow(c,3)*s,y:Math.pow(u,3)*e+u*u*3*c*n+3*u*c*c*i+Math.pow(c,3)*o}}function q(t,e,r){var n=t[0],a=t[1];return[n+(e[0]-n)*r,a+(e[1]-a)*r]}function P(t,e,r,n){var a=.5,i=[t,e],s=[r,n],o=q(i,s,a),c=q(s,o,a),u=q(o,c,a),m=q(c,u,a),h=q(u,m,a),l=i.concat(o,u,h,[a]),f=S.apply(void 0,l),p=h.concat(m,c,s,[0]),y=S.apply(void 0,p);return[f.x,f.y,y.x,y.y,r,n]}function I(t,e){var r,n=t[0],a=t.slice(1).map((function(t){return+t})),i=a[0],s=a[1],o=e.x1,c=e.y1,u=e.x,m=e.y;switch("TQ".includes(n)||(e.qx=null,e.qy=null),n){case"M":return e.x=i,e.y=s,t;case"A":return r=[o,c].concat(a),["C"].concat(C.apply(void 0,r));case"Q":return e.qx=i,e.qy=s,r=[o,c].concat(a),["C"].concat(k.apply(void 0,r));case"L":return["C"].concat(P(o,c,i,s));case"Z":return["C"].concat(P(o,c,u,m))}return t}function T(t){if(N(t))return u(t);for(var e=w(b(t)),r=Object.assign({},M),n=[],a="",i=e.length,s=0;s<i;s+=1){a=e[s][0],n[s]=a,e[s]=I(e[s],r),d(e,n,s),i=e.length;var o=e[s],c=o.length;r.x1=+o[c-2],r.y1=+o[c-1],r.x2=+o[c-4]||r.x1,r.y2=+o[c-3]||r.y1}return e}function j(e,r){var n=t.round;if(!1===r||!1===n)return u(e);var a=(n=r>=1?r:n)>=1?Math.pow(10,n):1;return e.map((function(t){var e=t.slice(1).map(Number).map((function(t){return t%1==0?t:Math.round(t*a)/a}));return[t[0]].concat(e)}))}function V(t,e){return j(t,e).map((function(t){return t[0]+t.slice(1).join(" ")})).join("")}function z(t){var e=p(t),r="Z"===e.slice(-1)[0][0],n=b(e).map((function(t,r){var n=t.slice(-2).map(Number),a=n[0],i=n[1];return{seg:e[r],n:t,c:e[r][0],x:a,y:i}})).map((function(t,e,n){var a=t.seg,i=t.n,s=e&&n[e-1],o=n[e+1]&&n[e+1],c=t.c,u=n.length,m=e?n[e-1].x:n[u-1].x,h=e?n[e-1].y:n[u-1].y,l=[];switch(c){case"M":l=r?["Z"]:[c,m,h];break;case"A":l=[c].concat(a.slice(1,-3),[1===a[5]?0:1],[m],[h]);break;case"C":l=o&&"S"===o.c?["S",a[1],a[2],m,h]:[c,a[3],a[4],a[1],a[2],m,h];break;case"S":l=s&&"CS".includes(s.c)&&(!o||o&&"S"!==o.c)?["C",i[3],i[4],i[1],i[2],m,h]:[c,i[1],i[2],m,h];break;case"Q":l=o&&"T"===o.c?["T",m,h]:[c].concat(a.slice(1,-2),[m],[h]);break;case"T":l=s&&"QT".includes(s.c)&&(!o||o&&"T"!==o.c)?["Q",i[1],i[2],m,h]:[c,m,h];break;case"Z":l=["M",m,h];break;case"H":l=[c,m];break;case"V":l=[c,h];break;default:l=[c].concat(a.slice(1,-2),[m],[h])}return l}));return r?n.reverse():[n[0]].concat(n.slice(1).reverse())}function O(t){return V(p(t),0).replace(/(m|M)/g,"|$1").split("|").map((function(t){return t.trim()})).filter((function(t){return t}))}function E(t,e,r,n){var a=t[0],i=function(t){return Math.round(t*Math.pow(10,4))/Math.pow(10,4)},s=t.slice(1).map((function(t){return+t})),o=e.slice(1).map((function(t){return+t})),c=r.x1,u=r.y1,m=r.x2,h=r.y2,l=r.x,f=r.y,p=t,y=o.slice(-2),v=y[0],d=y[1];if("TQ".includes(a)||(r.qx=null,r.qy=null),["V","H","S","T","Z"].includes(a))p=[a].concat(s);else if("L"===a)i(l)===i(v)?p=["V",d]:i(f)===i(d)&&(p=["H",v]);else if("C"===a){var x=o[0],g=o[1];"CS".includes(n)&&i(x)===i(2*c-m)&&i(g)===i(2*u-h)&&(p=["S"].concat(o.slice(-4))),r.x1=x,r.y1=g}else if("Q"===a){var M=o[0],b=o[1];r.qx=M,r.qy=b,"QT".includes(n)&&i(M)===i(2*c-m)&&i(b)===i(2*u-h)&&(p=["T"].concat(o.slice(-2)))}return p}function L(t,e){for(var r,n=p(t),a=b(n),i=Object.assign({},M),s=[],o=n.length,c="",u="",m=0,h=0,l=0,f=0,y=0;y<o;y+=1){c=n[y][0],s[y]=c,y&&(u=s[y-1]),n[y]=E(n[y],a[y],i,u);var d=n[y],x=d.length;switch(i.x1=+d[x-2],i.y1=+d[x-1],i.x2=+d[x-4]||i.x1,i.y2=+d[x-3]||i.y1,c){case"Z":m=l,h=f;break;case"H":m=d[1];break;case"V":h=d[1];break;default:m=(r=d.slice(-2).map(Number))[0],h=r[1],"M"===c&&(l=m,f=h)}i.x=m,i.y=h}var g=j(n,e),w=j(v(n),e);return g.map((function(t,e){return e?t.join("").length<w[e].join("").length?t:w[e]:t}))}function Q(t){var e=new J,r=Array.from(t);if(!r.every((function(t){return!Number.isNaN(t)})))throw TypeError('CSSMatrix: "'+t+'" must only have numbers.');if(16===r.length){var n=r[0],a=r[1],i=r[2],s=r[3],o=r[4],c=r[5],u=r[6],m=r[7],h=r[8],l=r[9],f=r[10],p=r[11],y=r[12],v=r[13],d=r[14],x=r[15];e.m11=n,e.a=n,e.m21=o,e.c=o,e.m31=h,e.m41=y,e.e=y,e.m12=a,e.b=a,e.m22=c,e.d=c,e.m32=l,e.m42=v,e.f=v,e.m13=i,e.m23=u,e.m33=f,e.m43=d,e.m14=s,e.m24=m,e.m34=p,e.m44=x}else{if(6!==r.length)throw new TypeError("CSSMatrix: expecting an Array of 6/16 values.");var g=r[0],M=r[1],b=r[2],w=r[3],N=r[4],A=r[5];e.m11=g,e.a=g,e.m12=M,e.b=M,e.m21=b,e.c=b,e.m22=w,e.d=w,e.m41=N,e.e=N,e.m42=A,e.f=A}return e}function Z(t){var e=Object.keys(new J);if("object"==typeof t&&e.every((function(e){return e in t})))return Q([t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.m41,t.m42,t.m43,t.m44]);throw TypeError('CSSMatrix: "'+t+'" is not a DOMMatrix / CSSMatrix / JSON compatible object.')}function D(t){if("string"!=typeof t)throw TypeError('CSSMatrix: "'+t+'" is not a string.');var e=String(t).replace(/\s/g,""),r=new J,n='CSSMatrix: invalid transform string "'+t+'"';return e.split(")").filter((function(t){return t})).forEach((function(t){var e=t.split("("),a=e[0],i=e[1];if(!i)throw TypeError(n);var s=i.split(",").map((function(t){return t.includes("rad")?parseFloat(t)*(180/Math.PI):parseFloat(t)})),o=s[0],c=s[1],u=s[2],m=s[3],h=[o,c,u],l=[o,c,u,m];if("perspective"===a&&o&&[c,u].every((function(t){return void 0===t})))r.m34=-1/o;else if(a.includes("matrix")&&[6,16].includes(s.length)&&s.every((function(t){return!Number.isNaN(+t)}))){var f=s.map((function(t){return Math.abs(t)<1e-6?0:t}));r=r.multiply(Q(f))}else if("translate3d"===a&&h.every((function(t){return!Number.isNaN(+t)})))r=r.translate(o,c,u);else if("translate"===a&&o&&void 0===u)r=r.translate(o,c||0,0);else if("rotate3d"===a&&l.every((function(t){return!Number.isNaN(+t)}))&&m)r=r.rotateAxisAngle(o,c,u,m);else if("rotate"===a&&o&&[c,u].every((function(t){return void 0===t})))r=r.rotate(0,0,o);else if("scale3d"===a&&h.every((function(t){return!Number.isNaN(+t)}))&&h.some((function(t){return 1!==t})))r=r.scale(o,c,u);else if("scale"!==a||Number.isNaN(o)||1===o||void 0!==u)if("skew"===a&&o&&void 0===u)r=r.skewX(o),r=c?r.skewY(c):r;else{if(!(/[XYZ]/.test(a)&&o&&[c,u].every((function(t){return void 0===t}))&&["translate","rotate","scale","skew"].some((function(t){return a.includes(t)}))))throw TypeError(n);if(["skewX","skewY"].includes(a))r=r[a](o);else{var p=a.replace(/[XYZ]/,""),y=a.replace(p,""),v=["X","Y","Z"].indexOf(y),d=[0===v?o:0,1===v?o:0,2===v?o:0];r=r[p].apply(r,d)}}else{var x=Number.isNaN(+c)?o:c;r=r.scale(o,x,1)}})),r}function X(t,e,r){var n=new J;return n.m41=t,n.e=t,n.m42=e,n.f=e,n.m43=r,n}function H(t,e,r){var n=new J,a=Math.PI/180,i=t*a,s=e*a,o=r*a,c=Math.cos(i),u=-Math.sin(i),m=Math.cos(s),h=-Math.sin(s),l=Math.cos(o),f=-Math.sin(o),p=m*l,y=-m*f;n.m11=p,n.a=p,n.m12=y,n.b=y,n.m13=h;var v=u*h*l+c*f;n.m21=v,n.c=v;var d=c*l-u*h*f;return n.m22=d,n.d=d,n.m23=-u*m,n.m31=u*f-c*h*l,n.m32=u*l+c*h*f,n.m33=c*m,n}function Y(t,e,r,n){var a=new J,i=n*(Math.PI/360),s=Math.sin(i),o=Math.cos(i),c=s*s,u=Math.sqrt(t*t+e*e+r*r),m=t,h=e,l=r;0===u?(m=0,h=0,l=1):(m/=u,h/=u,l/=u);var f=m*m,p=h*h,y=l*l,v=1-2*(p+y)*c;a.m11=v,a.a=v;var d=2*(m*h*c+l*s*o);a.m12=d,a.b=d,a.m13=2*(m*l*c-h*s*o);var x=2*(h*m*c-l*s*o);a.m21=x,a.c=x;var g=1-2*(y+f)*c;return a.m22=g,a.d=g,a.m23=2*(h*l*c+m*s*o),a.m31=2*(l*m*c+h*s*o),a.m32=2*(l*h*c-m*s*o),a.m33=1-2*(f+p)*c,a}function R(t,e,r){var n=new J;return n.m11=t,n.a=t,n.m22=e,n.d=e,n.m33=r,n}function F(t){var e=new J,r=t*Math.PI/180,n=Math.tan(r);return e.m21=n,e.c=n,e}function B(t){var e=new J,r=t*Math.PI/180,n=Math.tan(r);return e.m12=n,e.b=n,e}function G(t,e){return Q([e.m11*t.m11+e.m12*t.m21+e.m13*t.m31+e.m14*t.m41,e.m11*t.m12+e.m12*t.m22+e.m13*t.m32+e.m14*t.m42,e.m11*t.m13+e.m12*t.m23+e.m13*t.m33+e.m14*t.m43,e.m11*t.m14+e.m12*t.m24+e.m13*t.m34+e.m14*t.m44,e.m21*t.m11+e.m22*t.m21+e.m23*t.m31+e.m24*t.m41,e.m21*t.m12+e.m22*t.m22+e.m23*t.m32+e.m24*t.m42,e.m21*t.m13+e.m22*t.m23+e.m23*t.m33+e.m24*t.m43,e.m21*t.m14+e.m22*t.m24+e.m23*t.m34+e.m24*t.m44,e.m31*t.m11+e.m32*t.m21+e.m33*t.m31+e.m34*t.m41,e.m31*t.m12+e.m32*t.m22+e.m33*t.m32+e.m34*t.m42,e.m31*t.m13+e.m32*t.m23+e.m33*t.m33+e.m34*t.m43,e.m31*t.m14+e.m32*t.m24+e.m33*t.m34+e.m34*t.m44,e.m41*t.m11+e.m42*t.m21+e.m43*t.m31+e.m44*t.m41,e.m41*t.m12+e.m42*t.m22+e.m43*t.m32+e.m44*t.m42,e.m41*t.m13+e.m42*t.m23+e.m43*t.m33+e.m44*t.m43,e.m41*t.m14+e.m42*t.m24+e.m43*t.m34+e.m44*t.m44])}var J=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];var r=this;if(r.a=1,r.b=0,r.c=0,r.d=1,r.e=0,r.f=0,r.m11=1,r.m12=0,r.m13=0,r.m14=0,r.m21=0,r.m22=1,r.m23=0,r.m24=0,r.m31=0,r.m32=0,r.m33=1,r.m34=0,r.m41=0,r.m42=0,r.m43=0,r.m44=1,t&&t.length){var n=[16,6].some((function(e){return e===t.length}))?t:t[0];return r.setMatrixValue(n)}return r},U={isIdentity:{configurable:!0},is2D:{configurable:!0}};U.isIdentity.set=function(t){this.isIdentity=t},U.isIdentity.get=function(){var t=this;return 1===t.m11&&0===t.m12&&0===t.m13&&0===t.m14&&0===t.m21&&1===t.m22&&0===t.m23&&0===t.m24&&0===t.m31&&0===t.m32&&1===t.m33&&0===t.m34&&0===t.m41&&0===t.m42&&0===t.m43&&1===t.m44},U.is2D.get=function(){var t=this;return 0===t.m31&&0===t.m32&&1===t.m33&&0===t.m34&&0===t.m43&&1===t.m44},U.is2D.set=function(t){this.is2D=t},J.prototype.setMatrixValue=function(t){return[Array,Float64Array,Float32Array].some((function(e){return t instanceof e}))?Q(t):"string"==typeof t&&t.length&&"none"!==t?D(t):"object"==typeof t?Z(t):this},J.prototype.toArray=function(){var t=this,e=Math.pow(10,6);return(t.is2D?[t.a,t.b,t.c,t.d,t.e,t.f]:[t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.m41,t.m42,t.m43,t.m44]).map((function(t){return Math.abs(t)<1e-6?0:(t*e>>0)/e}))},J.prototype.toString=function(){var t=this.toArray();return(this.is2D?"matrix":"matrix3d")+"("+t+")"},J.prototype.toJSON=function(){var t=this,e=t.is2D,r=t.isIdentity;return Object.assign({},t,{is2D:e,isIdentity:r})},J.prototype.multiply=function(t){return G(this,t)},J.prototype.translate=function(t,e,r){var n=e,a=r;return void 0===a&&(a=0),void 0===n&&(n=0),G(this,X(t,n,a))},J.prototype.scale=function(t,e,r){var n=e,a=r;return void 0===n&&(n=t),void 0===a&&(a=1),G(this,R(t,n,a))},J.prototype.rotate=function(t,e,r){var n=t,a=e,i=r;return void 0===a&&(a=0),void 0===i&&(i=n,n=0),G(this,H(n,a,i))},J.prototype.rotateAxisAngle=function(t,e,r,n){if([t,e,r,n].some((function(t){return Number.isNaN(t)})))throw new TypeError("CSSMatrix: expecting 4 values");return G(this,Y(t,e,r,n))},J.prototype.skewX=function(t){return G(this,F(t))},J.prototype.skewY=function(t){return G(this,B(t))},J.prototype.transformPoint=function(t){var e=X(t.x,t.y,t.z);return e.m44=t.w||1,{x:(e=this.multiply(e)).m41,y:e.m42,z:e.m43,w:e.m44}},J.prototype.transform=function(t){var e=this,r=e.m11*t.x+e.m12*t.y+e.m13*t.z+e.m14*t.w,n=e.m21*t.x+e.m22*t.y+e.m23*t.z+e.m24*t.w,a=e.m31*t.x+e.m32*t.y+e.m33*t.z+e.m34*t.w,i=e.m41*t.x+e.m42*t.y+e.m43*t.z+e.m44*t.w;return{x:r/i,y:n/i,z:a/i,w:i}},Object.defineProperties(J.prototype,U),Object.assign(J,{Translate:X,Rotate:H,RotateAxisAngle:Y,Scale:R,SkewX:F,SkewY:B,Multiply:G,fromArray:Q,fromMatrix:Z,fromString:D});function $(t,e,r){var n=e[0],a=e[1],i=r[0],s=r[1],o=r[2],c=t.transformPoint({x:n,y:a,z:0,w:1}),u=c.x-i,m=c.y-s,h=c.z-o;return[u*(Math.abs(o)/Math.abs(h))+i,m*(Math.abs(o)/Math.abs(h))+s]}function K(t,e){var r,n,a,i,s,o,c,m=0,h=0,l=p(t),f=b(l),y=function(t){var e=new J,r=t.origin,n=r[0],a=r[1],i=t.translate,s=t.rotate,o=t.skew,c=t.scale;return Array.isArray(i)&&i.every((function(t){return!Number.isNaN(+t)}))&&i.some((function(t){return 0!==t}))?e=e.translate(i[0]||0,i[1]||0,i[2]||0):"number"!=typeof i||Number.isNaN(+i)||(e=e.translate(i||0,0,0)),(s||o||c)&&(e=e.translate(n,a),Array.isArray(s)&&s.every((function(t){return!Number.isNaN(+t)}))&&s.some((function(t){return 0!==t}))?e=e.rotate(s[0],s[1],s[2]):"number"!=typeof s||Number.isNaN(+s)||(e=e.rotate(0,0,s)),Array.isArray(o)&&o.every((function(t){return!Number.isNaN(+t)}))&&o.some((function(t){return 0!==t}))?(e=o[0]?e.skewX(o[0]):e,e=o[1]?e.skewY(o[1]):e):"number"!=typeof o||Number.isNaN(+o)||(e=e.skewX(o||0)),Array.isArray(c)&&c.every((function(t){return!Number.isNaN(+t)}))&&c.some((function(t){return 1!==t}))?e=e.scale(c[0],c[1],c[2]):"number"!=typeof c||Number.isNaN(+c)||(e=e.scale(c||1,c||1,c||1)),e=e.translate(-n,-a)),e}(e),v=Object.keys(e),x=e.origin,g=[y.a,y.b,y.c,y.d,y.e,y.f],w=Object.assign({},M),N=[],A=0,C="",k=[],S=[];if(!y.isIdentity){for(r=0,a=l.length;r<a;r+=1){N=l[r],l[r]&&(C=N[0]),S[r]=C,"A"!==C||y.is2D&&["skewX","skewY"].find((function(t){return v.includes(t)}))||(N=I(f[r],w),l[r]=I(f[r],w),d(l,S,r),f[r]=I(f[r],w),d(f,S,r),a=Math.max(l.length,f.length)),A=(N=f[r]).length,w.x1=+N[A-2],w.y1=+N[A-1],w.x2=+N[A-4]||w.x1,w.y2=+N[A-3]||w.y1;var q={s:l[r],c:l[r][0],x:w.x1,y:w.y1};k=k.concat([q])}return k.map((function(t){var e,r,a;switch(C=t.c,N=t.s,C){case"A":return c=function(t,e,r,n){var a=Math.cos(n*Math.PI/180),i=Math.sin(n*Math.PI/180),s=[e*(t[0]*a+t[2]*i),e*(t[1]*a+t[3]*i),r*(-t[0]*i+t[2]*a),r*(-t[1]*i+t[3]*a)],o=s[0]*s[0]+s[2]*s[2],c=s[1]*s[1]+s[3]*s[3],u=((s[0]-s[3])*(s[0]-s[3])+(s[2]+s[1])*(s[2]+s[1]))*((s[0]+s[3])*(s[0]+s[3])+(s[2]-s[1])*(s[2]-s[1])),m=(o+c)/2;if(u<1e-9*m){var h=Math.sqrt(m);return{rx:h,ry:h,ax:0}}var l,f,p=s[0]*s[1]+s[2]*s[3],y=m+(u=Math.sqrt(u))/2,v=m-u/2,d=Math.abs(p)<1e-9&&Math.abs(y-c)<1e-9?90:Math.atan(Math.abs(p)>Math.abs(y-c)?(y-o)/p:p/(y-c)*180)/Math.PI;return d>=0?(l=Math.sqrt(y),f=Math.sqrt(v)):(d+=90,l=Math.sqrt(v),f=Math.sqrt(y)),{rx:l,ry:f,ax:d}}(g,N[1],N[2],N[3]),g[0]*g[3]-g[1]*g[2]<0&&(N[5]=N[5]?0:1),e=$(y,[+N[6],+N[7]],x),s=e[0],o=e[1],N=m===s&&h===o||c.rx<1e-9*c.ry||c.ry<1e-9*c.rx?["L",s,o]:[C,c.rx,c.ry,c.ax,N[4],N[5],s,o],m=s,h=o,N;case"L":case"H":case"V":return r=$(y,[t.x,t.y],x),s=r[0],o=r[1],m!==s&&h!==o?N=["L",s,o]:h===o?N=["H",s]:m===s&&(N=["V",o]),m=s,h=o,N;default:for(n=1,i=N.length;n<i;n+=2)a=$(y,[+N[n],+N[n+1]],x),m=a[0],h=a[1],N[n]=m,N[n+1]=h;return N}}))}return u(l)}function W(t,e,r,n,a,i,s,o){var c,u=a-2*r+t-(s-2*a+r),m=2*(r-t)-2*(a-r),h=t-r,l=(-m+Math.sqrt(m*m-4*u*h))/2/u,f=(-m-Math.sqrt(m*m-4*u*h))/2/u,p=[e,o],y=[t,s];return Math.abs(l)>"1e12"&&(l=.5),Math.abs(f)>"1e12"&&(f=.5),l>0&&l<1&&(c=S(t,e,r,n,a,i,s,o,l),y.push(c.x),p.push(c.y)),f>0&&f<1&&(c=S(t,e,r,n,a,i,s,o,f),y.push(c.x),p.push(c.y)),u=i-2*n+e-(o-2*i+n),h=e-n,l=(-(m=2*(n-e)-2*(i-n))+Math.sqrt(m*m-4*u*h))/2/u,f=(-m-Math.sqrt(m*m-4*u*h))/2/u,Math.abs(l)>"1e12"&&(l=.5),Math.abs(f)>"1e12"&&(f=.5),l>0&&l<1&&(c=S(t,e,r,n,a,i,s,o,l),y.push(c.x),p.push(c.y)),f>0&&f<1&&(c=S(t,e,r,n,a,i,s,o,f),y.push(c.x),p.push(c.y)),{min:{x:Math.min.apply(0,y),y:Math.min.apply(0,p)},max:{x:Math.max.apply(0,y),y:Math.max.apply(0,p)}}}function _(t){if(!t)return{x:0,y:0,width:0,height:0,x2:0,y2:0,cx:0,cy:0,cz:0};var e=T(t),r=0,n=0,a=[],i=[];e.forEach((function(t){var e=t.slice(-2).map(Number),s=e[0],o=e[1];if("M"===t[0])r=s,n=o,a.push(s),i.push(o);else{var c=[r,n].concat(t.slice(1)),u=W.apply(void 0,c);a=a.concat([u.min.x],[u.max.x]),i=i.concat([u.min.y],[u.max.y]),r=s,n=o}}));var s=Math.min.apply(Math,a),o=Math.min.apply(Math,i),c=Math.max.apply(Math,a),u=Math.max.apply(Math,i),m=c-s,h=u-o;return{width:m,height:h,x:s,y:o,x2:c,y2:u,cx:s+m/2,cy:o+h/2,cz:Math.max(m,h)+Math.min(m,h)/2}}Object.assign(J,{Version:"0.0.24"});var tt=function(e,r){var n=r||{};this.segments=l(e);var a=_(this.segments),i=a.width,s=a.height,o=a.cx,c=a.cy,u=a.cz,m=t.round,h=t.origin,f=n.round,p=n.origin;if("auto"===f){var y=(""+Math.floor(Math.max(i,s))).length;m=y>=4?0:4-y}else(Number.isInteger(f)&&f>=1||!1===f)&&(m=f);if(Array.isArray(p)&&p.length>=2){var v=p.map(Number),d=v[0],x=v[1],g=v[2];h=[Number.isNaN(d)?o:d,Number.isNaN(x)?c:x,g||u]}else h=[o,c,u];return this.round=m,this.origin=h,this};function et(t,e,r,n,a,i,s,o){return 3*((o-e)*(r+a)-(s-t)*(n+i)+n*(t-a)-r*(e-i)+o*(a+t/3)-s*(i+e/3))/20}function rt(t){var e=0,r=0,n=0;return T(t).map((function(t){var a,i;switch(t[0]){case"M":return e=(a=t)[1],r=a[2],0;default:return n=et.apply(void 0,[e,r].concat(t.slice(1))),i=t.slice(-2).map(Number),e=i[0],r=i[1],n}})).reduce((function(t,e){return t+e}),0)}function nt(t,e,r,n,a){return a*(a*(-3*t+9*e-9*r+3*n)+6*t-12*e+6*r)-3*t+3*e}function at(t,e,r,n,a,i,s,o,c){var u=c;(null===c||Number.isNaN(+c))&&(u=1),u>1&&(u=1),u<0&&(u=0);var m=u/2,h=0,l=0,f=0,p=0,y=[.2491,.2491,.2335,.2335,.2032,.2032,.1601,.1601,.1069,.1069,.0472,.0472];return[-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816].forEach((function(c,u){l=nt(t,r,a,s,h=m*c+m),f=nt(e,n,i,o,h),p+=y[u]*Math.sqrt(l*l+f*f)})),m*p}tt.prototype.toAbsolute=function(){var t=this.segments;return this.segments=p(t),this},tt.prototype.toRelative=function(){var t=this.segments;return this.segments=v(t),this},tt.prototype.toCurve=function(){var t=this.segments;return this.segments=T(t),this},tt.prototype.reverse=function(t){this.toAbsolute();var e=this.segments,r=O(this.toString()),n=r.length>1?r:0,a=n&&u(n).map((function(e,r){return t?r?z(e):l(e):z(e)})),i=[];return i=n?a.flat(1):t?e:z(e),this.segments=u(i),this},tt.prototype.normalize=function(){var t=this.segments;return this.segments=b(t),this},tt.prototype.optimize=function(){var t=this.segments;return this.segments=L(t,this.round),this},tt.prototype.transform=function(t){if(!t||"object"!=typeof t||"object"==typeof t&&!["translate","rotate","skew","scale"].some((function(e){return e in t})))return this;var e={};Object.keys(t).forEach((function(r){e[r]=Array.isArray(t[r])?[].concat(t[r]):Number(t[r])}));var r=this.segments,n=e.origin;if(n&&n.length>=2){var a=n.map(Number),i=a[0],s=a[1],o=a[2],c=this.origin,u=c[0],m=c[1],h=c[2];e.origin=[Number.isNaN(i)?u:i,Number.isNaN(s)?m:s,o||h]}else e.origin=Object.assign({},this.origin);return this.segments=K(r,e),this},tt.prototype.flipX=function(){return this.transform({rotate:[180,0,0]}),this},tt.prototype.flipY=function(){return this.transform({rotate:[0,180,0]}),this},tt.prototype.toString=function(){return V(this.segments,this.round)};var it={circle:["cx","cy","r"],ellipse:["cx","cy","rx","ry"],rect:["width","height","x","y","rx","ry"],polygon:["points"],polyline:["points"],glyph:[]};var st={CSSMatrix:J,parsePathString:l,isPathArray:h,isCurveArray:N,isAbsoluteArray:f,isRelativeArray:y,isNormalizedArray:g,isValidPath:function(t){if("string"!=typeof t)return!1;var e=new m(t);for(s(e);e.index<e.max&&!e.err.length;)c(e);return!e.err.length&&"mM".includes(e.segments[0][0])},pathToAbsolute:p,pathToRelative:v,pathToCurve:T,pathToString:V,getDrawDirection:function(t){return rt(T(t))>=0},getPathArea:rt,getPathBBox:_,getPathLength:function(t){var e=0;return T(t).forEach((function(t,r,n){var a="M"!==t[0]?n[r-1].slice(-2).concat(t.slice(1)):[];e+="M"===t[0]?0:at.apply(void 0,a)})),e},getPointAtLength:function(t,e){var r,n,a,i=0;return T(t).map((function(t,s,o){if(n=s?o[s-1].slice(-2).concat(t.slice(1)):t.slice(1),r=s?at.apply(void 0,n):0,i+=r,0===s)a={x:n[0],y:n[1]};else if(i>e&&e>i-r){var c=n.concat([1-(i-e)/r]);a=S.apply(void 0,c)}else a=null;return a})).filter((function(t){return t})).slice(-1)[0]},clonePath:u,splitPath:O,fixPath:w,roundPath:j,optimizePath:L,reverseCurve:function(t){var e=t.slice(1).map((function(e,r,n){return r?n[r-1].slice(-2).concat(e.slice(1)):t[0].slice(1).concat(e.slice(1))})).map((function(t){return t.map((function(e,r){return t[t.length-r-2*(1-r%2)]}))})).reverse();return[["M"].concat(e[0].slice(0,2))].concat(e.map((function(t){return["C"].concat(t.slice(2))})))},reversePath:z,normalizePath:b,transformPath:K,shapeToPath:function(e,r){var n=Object.keys(it),a=e instanceof Element;if(a&&!n.some((function(t){return e.tagName===t})))throw TypeError('shapeToPath: "'+e+'" is not SVGElement');var i,s=document.createElementNS("http://www.w3.org/2000/svg","path"),o=a?e.tagName:e.type,c={};if(c.type=o,a){var u=it[o];u.forEach((function(t){c[t]=e.getAttribute(t)})),Object.values(e.attributes).forEach((function(t){var e=t.name,r=t.value;u.includes(e)||s.setAttribute(e,r)}))}else Object.assign(c,e);var m,h,l,f,p=t.round;return"circle"===o?i=V((h=(m=c).cx,l=m.cy,f=m.r,[["M",h-f,l],["a",f,f,0,1,0,2*f,0],["a",f,f,0,1,0,-2*f,0]]),p):"ellipse"===o?i=V(function(t){var e=t.cx,r=t.cy,n=t.rx,a=t.ry;return[["M",e-n,r],["a",n,a,0,1,0,2*n,0],["a",n,a,0,1,0,-2*n,0]]}(c),p):["polyline","polygon"].includes(o)?i=V(function(t){for(var e=[],r=t.points.split(/[\s|,]/).map(Number),n=0;n<r.length;)e.push([n?"L":"M",r[n],r[n+1]]),n+=2;return"polygon"===t.type?e.concat([["z"]]):e}(c),p):"rect"===o?i=V(function(t){var e=+t.x||0,r=+t.y||0,n=+t.width,a=+t.height,i=+t.rx,s=+t.ry;return i||s?(i=i||s,s=s||i,2*i>n&&(i-=(2*i-n)/2),2*s>a&&(s-=(2*s-a)/2),[["M",e+i,r],["h",n-2*i],["s",i,0,i,s],["v",a-2*s],["s",0,s,-i,s],["h",2*i-n],["s",-i,0,-i,-s],["v",2*s-a],["s",0,-s,i,-s]]):[["M",e,r],["h",n],["v",a],["H",e],["Z"]]}(c),p):"line"===o?i=V(function(t){return[["M",t.x1,t.y1],["L",t.x2,t.y2]]}(c),p):"glyph"===o&&(i=a?e.getAttribute("d"):e.type),!!i&&(s.setAttribute("d",i),r&&a&&(e.before(s,e),e.remove()),s)},options:t};return Object.assign(tt,st,{Version:"0.1.21"}),tt}));
|
|
1
|
+
// SVGPathCommander v0.1.22 | thednp © 2021 | MIT-License
|
|
2
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SVGPathCommander=e()}(this,(function(){"use strict";var t={origin:[0,0,0],round:4},e={a:7,c:6,h:1,l:2,m:2,r:4,q:4,s:4,t:2,v:1,z:0};function r(t){var r=t.pathValue[t.segmentStart],n=r.toLowerCase(),a=t.data;for("m"===n&&a.length>2&&(t.segments.push([r,a[0],a[1]]),a=a.slice(2),n="l",r="m"===r?"l":"L");a.length>=e[n]&&(t.segments.push([r].concat(a.splice(0,e[n]))),e[n]););}function n(t){var e=t.index,r=t.pathValue.charCodeAt(e);return 48===r?(t.param=0,void(t.index+=1)):49===r?(t.param=1,void(t.index+=1)):void(t.err='Invalid path value: invalid Arc flag "'+r+'", expecting 0 or 1 at index '+e)}function a(t){return t>=48&&t<=57}function i(t){var e,r=t.max,n=t.pathValue,i=t.index,o=i,s=!1,u=!1,c=!1,m=!1;if(o>=r)t.err="Invalid path value at "+o+": missing param "+n[o];else if(43!==(e=n.charCodeAt(o))&&45!==e||(e=(o+=1)<r?n.charCodeAt(o):0),a(e)||46===e){if(46!==e){if(s=48===e,e=(o+=1)<r?n.charCodeAt(o):0,s&&o<r&&e&&a(e))return void(t.err="Invalid path value at index "+i+": "+n[i]+" illegal number");for(;o<r&&a(n.charCodeAt(o));)o+=1,u=!0;e=o<r?n.charCodeAt(o):0}if(46===e){for(m=!0,o+=1;a(n.charCodeAt(o));)o+=1,c=!0;e=o<r?n.charCodeAt(o):0}if(101===e||69===e){if(m&&!u&&!c)return void(t.err="Invalid path value at index "+o+": "+n[o]+" invalid float exponent");if(43!==(e=(o+=1)<r?n.charCodeAt(o):0)&&45!==e||(o+=1),!(o<r&&a(n.charCodeAt(o))))return void(t.err="Invalid path value at index "+o+": "+n[o]+" invalid float exponent");for(;o<r&&a(n.charCodeAt(o));)o+=1}t.index=o,t.param=+t.pathValue.slice(i,o)}else t.err="Invalid path value at index "+o+": "+n[o]+" is not a number"}function o(t){for(var e,r=t.pathValue,n=t.max;t.index<n&&(10===(e=r.charCodeAt(t.index))||13===e||8232===e||8233===e||32===e||9===e||11===e||12===e||160===e||e>=5760&&[5760,6158,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288,65279].indexOf(e)>=0);)t.index+=1}function s(t){return t>=48&&t<=57||43===t||45===t||46===t}function u(t){var a=t.max,u=t.pathValue,c=t.index,m=u.charCodeAt(c),f=e[u[c].toLowerCase()];if(t.segmentStart=c,function(t){switch(32|t){case 109:case 122:case 108:case 104:case 118:case 99:case 115:case 113:case 116:case 97:return!0;default:return!1}}(m))if(t.index+=1,o(t),t.data=[],f){for(;;){for(var l=f;l>0;l-=1){if(97!=(32|m)||3!==l&&4!==l?i(t):n(t),t.err.length)return;t.data.push(t.param),o(t),t.index<a&&44===u.charCodeAt(t.index)&&(t.index+=1,o(t))}if(t.index>=t.max)break;if(!s(u.charCodeAt(t.index)))break}r(t)}else r(t);else t.err="Invalid path value: "+u[c]+" not a path command"}function c(t){return t.map((function(t){return Array.isArray(t)?[].concat(t):t}))}function m(t){this.segments=[],this.pathValue=t,this.max=t.length,this.index=0,this.param=0,this.segmentStart=0,this.data=[],this.err=""}function f(t){return Array.isArray(t)&&t.every((function(t){var r=t[0].toLowerCase();return e[r]===t.length-1&&"achlmqstvz".includes(r)}))}function l(t){if(f(t))return c(t);var e=new m(t);for(o(e);e.index<e.max&&!e.err.length;)u(e);return e.err.length?e.segments=[]:e.segments.length&&("mM".includes(e.segments[0][0])?e.segments[0][0]="M":(e.err="Invalid path value: missing M/m",e.segments=[])),e.segments}function h(t){return f(t)&&t.every((function(t){return t[0]===t[0].toUpperCase()}))}function p(t){if(h(t))return c(t);var e=l(t),r=0,n=0,a=0,i=0;return e.map((function(t){var e,o=t.slice(1).map(Number),s=t[0],u=s.toUpperCase();if("M"===s)return r=(e=o)[0],n=e[1],a=r,i=n,["M",r,n];var c=[];if(s!==u)switch(u){case"A":c=[u,o[0],o[1],o[2],o[3],o[4],o[5]+r,o[6]+n];break;case"V":c=[u,o[0]+n];break;case"H":c=[u,o[0]+r];break;default:var m=o.map((function(t,e){return t+(e%2?n:r)}));c=[u].concat(m)}else c=[u].concat(o);var f=c.length;switch(u){case"Z":r=a,n=i;break;case"H":r=c[1];break;case"V":n=c[1];break;default:r=c[f-2],n=c[f-1],"M"===u&&(a=r,i=n)}return c}))}function y(t){return f(t)&&t.slice(1).every((function(t){return t[0]===t[0].toLowerCase()}))}function v(t){if(y(t))return c(t);var e=l(t),r=0,n=0,a=0,i=0;return e.map((function(t){var e,o,s=t.slice(1).map(Number),u=t[0],c=u.toLowerCase();if("M"===u)return r=(e=s)[0],n=e[1],a=r,i=n,["M",r,n];var m=[];if(u!==c)switch(c){case"a":m=[c,s[0],s[1],s[2],s[3],s[4],s[5]-r,s[6]-n];break;case"v":m=[c,s[0]-n];break;case"h":m=[c,s[0]-r];break;default:var f=s.map((function(t,e){return t-(e%2?n:r)}));m=[c].concat(f),"m"===c&&(r=(o=s)[0],n=o[1],a=r,i=n)}else"m"===u&&(a=s[0]+r,i=s[1]+n),m=[c].concat(s);var l=m.length;switch(c){case"z":r=a,n=i;break;case"h":r+=m[1];break;case"v":n+=m[1];break;default:r+=m[l-2],n+=m[l-1]}return m}))}function d(t,e,r){if(t[r].length>7){t[r].shift();for(var n=t[r],a=r;n.length;)e[r]="A",t.splice(a+=1,0,["C"].concat(n.splice(0,6)));t.splice(r,1)}}function g(t,e,r){var n=t[0],a=e.x1,i=e.y1,o=e.x2,s=e.y2,u=t.slice(1).map(Number),c=t;if("TQ".includes(n)||(e.qx=null,e.qy=null),"H"===n)c=["L",t[1],i];else if("V"===n)c=["L",a,t[1]];else if("S"===n){var m=function(t,e,r,n,a){return"CS".includes(a)?{x1:2*t-r,y1:2*e-n}:{x1:t,y1:e}}(a,i,o,s,r),f=m.x1,l=m.y1;e.x1=f,e.y1=l,c=["C",f,l].concat(u)}else if("T"===n){var h=function(t,e,r,n,a){return"QT".includes(a)?{qx:2*t-r,qy:2*e-n}:{qx:t,qy:e}}(a,i,e.qx,e.qy,r),p=h.qx,y=h.qy;e.qx=p,e.qy=y,c=["Q",p,y].concat(u)}else if("Q"===n){var v=u[0],d=u[1];e.qx=v,e.qy=d}return c}function x(t){return h(t)&&t.every((function(t){return"ACLMQZ".includes(t[0])}))}var M={x1:0,y1:0,x2:0,y2:0,x:0,y:0,qx:null,qy:null};function b(t){if(x(t))return c(t);for(var e=p(t),r=Object.assign({},M),n=[],a=e.length,i="",o="",s=0;s<a;s+=1){i=e[s][0],n[s]=i,s&&(o=n[s-1]),e[s]=g(e[s],r,o);var u=e[s],m=u.length;r.x1=+u[m-2],r.y1=+u[m-1],r.x2=+u[m-4]||r.x1,r.y2=+u[m-3]||r.y1}return e}function w(t){var e=l(t),r=b(e),n=e.length,a="Z"===r.slice(-1)[0][0],i=a?n-2:n-1,o=r[0].slice(1),s=o[0],u=o[1],c=r[i].slice(-2),m=c[0],f=c[1];return a&&s===m&&u===f?e.slice(0,-1):e}function N(t){return f(t)&&t.every((function(t){return"MC".includes(t[0])}))}function A(t,e,r){return{x:t*Math.cos(r)-e*Math.sin(r),y:t*Math.sin(r)+e*Math.cos(r)}}function C(t,e,r,n,a,i,o,s,u,c){var m,f,l,h,p,y,v=t,d=e,g=r,x=n,M=s,b=u,w=120*Math.PI/180,N=Math.PI/180*(+a||0),S=[];if(c)l=(m=c)[0],h=m[1],p=m[2],y=m[3];else{v=(f=A(v,d,-N)).x,d=f.y;var k=(v-(M=(f=A(M,b,-N)).x))/2,P=(d-(b=f.y))/2,q=k*k/(g*g)+P*P/(x*x);q>1&&(g*=q=Math.sqrt(q),x*=q);var I=g*g,T=x*x,j=(i===o?-1:1)*Math.sqrt(Math.abs((I*T-I*P*P-T*k*k)/(I*P*P+T*k*k)));p=j*g*P/x+(v+M)/2,y=j*-x*k/g+(d+b)/2,l=(Math.asin((d-y)/x)*Math.pow(10,9)>>0)/Math.pow(10,9),h=(Math.asin((b-y)/x)*Math.pow(10,9)>>0)/Math.pow(10,9),l=v<p?Math.PI-l:l,h=M<p?Math.PI-h:h,l<0&&(l=2*Math.PI+l),h<0&&(h=2*Math.PI+h),o&&l>h&&(l-=2*Math.PI),!o&&h>l&&(h-=2*Math.PI)}var L=h-l;if(Math.abs(L)>w){var V=h,O=M,z=b;h=l+w*(o&&h>l?1:-1),S=C(M=p+g*Math.cos(h),b=y+x*Math.sin(h),g,x,a,0,o,O,z,[h,V,p,y])}L=h-l;var E=Math.cos(l),Z=Math.sin(l),Q=Math.cos(h),D=Math.sin(h),X=Math.tan(L/4),H=4/3*g*X,Y=4/3*x*X,F=[v,d],R=[v+H*Z,d-Y*E],B=[M+H*D,b-Y*Q],G=[M,b];if(R[0]=2*F[0]-R[0],R[1]=2*F[1]-R[1],c)return R.concat(B,G,S);for(var J=[],U=0,$=(S=R.concat(B,G,S)).length;U<$;U+=1)J[U]=U%2?A(S[U-1],S[U],N).y:A(S[U],S[U+1],N).x;return J}function S(t,e,r,n,a,i){return[1/3*t+2/3*r,1/3*e+2/3*n,1/3*a+2/3*r,1/3*i+2/3*n,a,i]}function k(t,e,r){var n=t[0],a=t[1];return[n+(e[0]-n)*r,a+(e[1]-a)*r]}function P(t,e){return Math.sqrt((t[0]-e[0])*(t[0]-e[0])+(t[1]-e[1])*(t[1]-e[1]))}function q(t,e,r,n,a){var i=P([t,e],[r,n]);if("number"==typeof a){if(a<.001)return{x:t,y:e};if(a>i+.001)return{x:r,y:n};var o=k([t,e],[r,n],a/i);return{x:o[0],y:o[1]}}return i}function I(t,e,r,n){var a=.5,i=[t,e],o=[r,n],s=k(i,o,a),u=k(o,s,a),c=k(s,u,a),m=k(u,c,a),f=k(c,m,a),l=i.concat(s,c,f,[a]),h=q.apply(void 0,l),p=f.concat(m,u,o,[0]),y=q.apply(void 0,p);return[h.x,h.y,y.x,y.y,r,n]}function T(t,e){var r,n=t[0],a=t.slice(1).map((function(t){return+t})),i=a[0],o=a[1],s=e.x1,u=e.y1,c=e.x,m=e.y;switch("TQ".includes(n)||(e.qx=null,e.qy=null),n){case"M":return e.x=i,e.y=o,t;case"A":return r=[s,u].concat(a),["C"].concat(C.apply(void 0,r));case"Q":return e.qx=i,e.qy=o,r=[s,u].concat(a),["C"].concat(S.apply(void 0,r));case"L":return["C"].concat(I(s,u,i,o));case"Z":return["C"].concat(I(s,u,c,m))}return t}function j(t){if(N(t))return c(t);for(var e=w(b(t)),r=Object.assign({},M),n=[],a="",i=e.length,o=0;o<i;o+=1){a=e[o][0],n[o]=a,e[o]=T(e[o],r),d(e,n,o),i=e.length;var s=e[o],u=s.length;r.x1=+s[u-2],r.y1=+s[u-1],r.x2=+s[u-4]||r.x1,r.y2=+s[u-3]||r.y1}return e}function L(e,r){var n=t.round;if(!1===r||!1===n)return c(e);var a=(n=r>=1?r:n)>=1?Math.pow(10,n):1;return e.map((function(t){var e=t.slice(1).map(Number).map((function(t){return t%1==0?t:Math.round(t*a)/a}));return[t[0]].concat(e)}))}function V(t,e){return L(t,e).map((function(t){return t[0]+t.slice(1).join(" ")})).join("")}function O(t){var e=p(t),r="Z"===e.slice(-1)[0][0],n=b(e).map((function(t,r){var n=t.slice(-2).map(Number),a=n[0],i=n[1];return{seg:e[r],n:t,c:e[r][0],x:a,y:i}})).map((function(t,e,n){var a=t.seg,i=t.n,o=e&&n[e-1],s=n[e+1]&&n[e+1],u=t.c,c=n.length,m=e?n[e-1].x:n[c-1].x,f=e?n[e-1].y:n[c-1].y,l=[];switch(u){case"M":l=r?["Z"]:[u,m,f];break;case"A":l=[u].concat(a.slice(1,-3),[1===a[5]?0:1],[m],[f]);break;case"C":l=s&&"S"===s.c?["S",a[1],a[2],m,f]:[u,a[3],a[4],a[1],a[2],m,f];break;case"S":l=o&&"CS".includes(o.c)&&(!s||s&&"S"!==s.c)?["C",i[3],i[4],i[1],i[2],m,f]:[u,i[1],i[2],m,f];break;case"Q":l=s&&"T"===s.c?["T",m,f]:[u].concat(a.slice(1,-2),[m],[f]);break;case"T":l=o&&"QT".includes(o.c)&&(!s||s&&"T"!==s.c)?["Q",i[1],i[2],m,f]:[u,m,f];break;case"Z":l=["M",m,f];break;case"H":l=[u,m];break;case"V":l=[u,f];break;default:l=[u].concat(a.slice(1,-2),[m],[f])}return l}));return r?n.reverse():[n[0]].concat(n.slice(1).reverse())}function z(t){return V(p(t),0).replace(/(m|M)/g,"|$1").split("|").map((function(t){return t.trim()})).filter((function(t){return t}))}function E(t,e,r,n){var a=t[0],i=function(t){return Math.round(t*Math.pow(10,4))/Math.pow(10,4)},o=t.slice(1).map((function(t){return+t})),s=e.slice(1).map((function(t){return+t})),u=r.x1,c=r.y1,m=r.x2,f=r.y2,l=r.x,h=r.y,p=t,y=s.slice(-2),v=y[0],d=y[1];if("TQ".includes(a)||(r.qx=null,r.qy=null),["V","H","S","T","Z"].includes(a))p=[a].concat(o);else if("L"===a)i(l)===i(v)?p=["V",d]:i(h)===i(d)&&(p=["H",v]);else if("C"===a){var g=s[0],x=s[1];"CS".includes(n)&&i(g)===i(2*u-m)&&i(x)===i(2*c-f)&&(p=["S"].concat(s.slice(-4))),r.x1=g,r.y1=x}else if("Q"===a){var M=s[0],b=s[1];r.qx=M,r.qy=b,"QT".includes(n)&&i(M)===i(2*u-m)&&i(b)===i(2*c-f)&&(p=["T"].concat(s.slice(-2)))}return p}function Z(t,e){for(var r,n=p(t),a=b(n),i=Object.assign({},M),o=[],s=n.length,u="",c="",m=0,f=0,l=0,h=0,y=0;y<s;y+=1){u=n[y][0],o[y]=u,y&&(c=o[y-1]),n[y]=E(n[y],a[y],i,c);var d=n[y],g=d.length;switch(i.x1=+d[g-2],i.y1=+d[g-1],i.x2=+d[g-4]||i.x1,i.y2=+d[g-3]||i.y1,u){case"Z":m=l,f=h;break;case"H":m=d[1];break;case"V":f=d[1];break;default:m=(r=d.slice(-2).map(Number))[0],f=r[1],"M"===u&&(l=m,h=f)}i.x=m,i.y=f}var x=L(n,e),w=L(v(n),e);return x.map((function(t,e){return e?t.join("").length<w[e].join("").length?t:w[e]:t}))}function Q(t){var e=new U,r=Array.from(t);if(!r.every((function(t){return!Number.isNaN(t)})))throw TypeError('CSSMatrix: "'+t+'" must only have numbers.');if(16===r.length){var n=r[0],a=r[1],i=r[2],o=r[3],s=r[4],u=r[5],c=r[6],m=r[7],f=r[8],l=r[9],h=r[10],p=r[11],y=r[12],v=r[13],d=r[14],g=r[15];e.m11=n,e.a=n,e.m21=s,e.c=s,e.m31=f,e.m41=y,e.e=y,e.m12=a,e.b=a,e.m22=u,e.d=u,e.m32=l,e.m42=v,e.f=v,e.m13=i,e.m23=c,e.m33=h,e.m43=d,e.m14=o,e.m24=m,e.m34=p,e.m44=g}else{if(6!==r.length)throw new TypeError("CSSMatrix: expecting an Array of 6/16 values.");var x=r[0],M=r[1],b=r[2],w=r[3],N=r[4],A=r[5];e.m11=x,e.a=x,e.m12=M,e.b=M,e.m21=b,e.c=b,e.m22=w,e.d=w,e.m41=N,e.e=N,e.m42=A,e.f=A}return e}function D(t){var e=Object.keys(new U);if("object"==typeof t&&e.every((function(e){return e in t})))return Q([t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.m41,t.m42,t.m43,t.m44]);throw TypeError('CSSMatrix: "'+t+'" is not a DOMMatrix / CSSMatrix / JSON compatible object.')}function X(t){if("string"!=typeof t)throw TypeError('CSSMatrix: "'+t+'" is not a string.');var e=String(t).replace(/\s/g,""),r=new U,n='CSSMatrix: invalid transform string "'+t+'"';return e.split(")").filter((function(t){return t})).forEach((function(t){var e=t.split("("),a=e[0],i=e[1];if(!i)throw TypeError(n);var o=i.split(",").map((function(t){return t.includes("rad")?parseFloat(t)*(180/Math.PI):parseFloat(t)})),s=o[0],u=o[1],c=o[2],m=o[3],f=[s,u,c],l=[s,u,c,m];if("perspective"===a&&s&&[u,c].every((function(t){return void 0===t})))r.m34=-1/s;else if(a.includes("matrix")&&[6,16].includes(o.length)&&o.every((function(t){return!Number.isNaN(+t)}))){var h=o.map((function(t){return Math.abs(t)<1e-6?0:t}));r=r.multiply(Q(h))}else if("translate3d"===a&&f.every((function(t){return!Number.isNaN(+t)})))r=r.translate(s,u,c);else if("translate"===a&&s&&void 0===c)r=r.translate(s,u||0,0);else if("rotate3d"===a&&l.every((function(t){return!Number.isNaN(+t)}))&&m)r=r.rotateAxisAngle(s,u,c,m);else if("rotate"===a&&s&&[u,c].every((function(t){return void 0===t})))r=r.rotate(0,0,s);else if("scale3d"===a&&f.every((function(t){return!Number.isNaN(+t)}))&&f.some((function(t){return 1!==t})))r=r.scale(s,u,c);else if("scale"!==a||Number.isNaN(s)||1===s||void 0!==c)if("skew"===a&&s&&void 0===c)r=r.skewX(s),r=u?r.skewY(u):r;else{if(!(/[XYZ]/.test(a)&&s&&[u,c].every((function(t){return void 0===t}))&&["translate","rotate","scale","skew"].some((function(t){return a.includes(t)}))))throw TypeError(n);if(["skewX","skewY"].includes(a))r=r[a](s);else{var p=a.replace(/[XYZ]/,""),y=a.replace(p,""),v=["X","Y","Z"].indexOf(y),d=[0===v?s:0,1===v?s:0,2===v?s:0];r=r[p].apply(r,d)}}else{var g=Number.isNaN(+u)?s:u;r=r.scale(s,g,1)}})),r}function H(t,e,r){var n=new U;return n.m41=t,n.e=t,n.m42=e,n.f=e,n.m43=r,n}function Y(t,e,r){var n=new U,a=Math.PI/180,i=t*a,o=e*a,s=r*a,u=Math.cos(i),c=-Math.sin(i),m=Math.cos(o),f=-Math.sin(o),l=Math.cos(s),h=-Math.sin(s),p=m*l,y=-m*h;n.m11=p,n.a=p,n.m12=y,n.b=y,n.m13=f;var v=c*f*l+u*h;n.m21=v,n.c=v;var d=u*l-c*f*h;return n.m22=d,n.d=d,n.m23=-c*m,n.m31=c*h-u*f*l,n.m32=c*l+u*f*h,n.m33=u*m,n}function F(t,e,r,n){var a=new U,i=n*(Math.PI/360),o=Math.sin(i),s=Math.cos(i),u=o*o,c=Math.sqrt(t*t+e*e+r*r),m=t,f=e,l=r;0===c?(m=0,f=0,l=1):(m/=c,f/=c,l/=c);var h=m*m,p=f*f,y=l*l,v=1-2*(p+y)*u;a.m11=v,a.a=v;var d=2*(m*f*u+l*o*s);a.m12=d,a.b=d,a.m13=2*(m*l*u-f*o*s);var g=2*(f*m*u-l*o*s);a.m21=g,a.c=g;var x=1-2*(y+h)*u;return a.m22=x,a.d=x,a.m23=2*(f*l*u+m*o*s),a.m31=2*(l*m*u+f*o*s),a.m32=2*(l*f*u-m*o*s),a.m33=1-2*(h+p)*u,a}function R(t,e,r){var n=new U;return n.m11=t,n.a=t,n.m22=e,n.d=e,n.m33=r,n}function B(t){var e=new U,r=t*Math.PI/180,n=Math.tan(r);return e.m21=n,e.c=n,e}function G(t){var e=new U,r=t*Math.PI/180,n=Math.tan(r);return e.m12=n,e.b=n,e}function J(t,e){return Q([e.m11*t.m11+e.m12*t.m21+e.m13*t.m31+e.m14*t.m41,e.m11*t.m12+e.m12*t.m22+e.m13*t.m32+e.m14*t.m42,e.m11*t.m13+e.m12*t.m23+e.m13*t.m33+e.m14*t.m43,e.m11*t.m14+e.m12*t.m24+e.m13*t.m34+e.m14*t.m44,e.m21*t.m11+e.m22*t.m21+e.m23*t.m31+e.m24*t.m41,e.m21*t.m12+e.m22*t.m22+e.m23*t.m32+e.m24*t.m42,e.m21*t.m13+e.m22*t.m23+e.m23*t.m33+e.m24*t.m43,e.m21*t.m14+e.m22*t.m24+e.m23*t.m34+e.m24*t.m44,e.m31*t.m11+e.m32*t.m21+e.m33*t.m31+e.m34*t.m41,e.m31*t.m12+e.m32*t.m22+e.m33*t.m32+e.m34*t.m42,e.m31*t.m13+e.m32*t.m23+e.m33*t.m33+e.m34*t.m43,e.m31*t.m14+e.m32*t.m24+e.m33*t.m34+e.m34*t.m44,e.m41*t.m11+e.m42*t.m21+e.m43*t.m31+e.m44*t.m41,e.m41*t.m12+e.m42*t.m22+e.m43*t.m32+e.m44*t.m42,e.m41*t.m13+e.m42*t.m23+e.m43*t.m33+e.m44*t.m43,e.m41*t.m14+e.m42*t.m24+e.m43*t.m34+e.m44*t.m44])}var U=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];var r=this;if(r.a=1,r.b=0,r.c=0,r.d=1,r.e=0,r.f=0,r.m11=1,r.m12=0,r.m13=0,r.m14=0,r.m21=0,r.m22=1,r.m23=0,r.m24=0,r.m31=0,r.m32=0,r.m33=1,r.m34=0,r.m41=0,r.m42=0,r.m43=0,r.m44=1,t&&t.length){var n=[16,6].some((function(e){return e===t.length}))?t:t[0];return r.setMatrixValue(n)}return r},$={isIdentity:{configurable:!0},is2D:{configurable:!0}};$.isIdentity.set=function(t){this.isIdentity=t},$.isIdentity.get=function(){var t=this;return 1===t.m11&&0===t.m12&&0===t.m13&&0===t.m14&&0===t.m21&&1===t.m22&&0===t.m23&&0===t.m24&&0===t.m31&&0===t.m32&&1===t.m33&&0===t.m34&&0===t.m41&&0===t.m42&&0===t.m43&&1===t.m44},$.is2D.get=function(){var t=this;return 0===t.m31&&0===t.m32&&1===t.m33&&0===t.m34&&0===t.m43&&1===t.m44},$.is2D.set=function(t){this.is2D=t},U.prototype.setMatrixValue=function(t){return[Array,Float64Array,Float32Array].some((function(e){return t instanceof e}))?Q(t):"string"==typeof t&&t.length&&"none"!==t?X(t):"object"==typeof t?D(t):this},U.prototype.toArray=function(){var t=this,e=Math.pow(10,6);return(t.is2D?[t.a,t.b,t.c,t.d,t.e,t.f]:[t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.m41,t.m42,t.m43,t.m44]).map((function(t){return Math.abs(t)<1e-6?0:(t*e>>0)/e}))},U.prototype.toString=function(){var t=this.toArray();return(this.is2D?"matrix":"matrix3d")+"("+t+")"},U.prototype.toJSON=function(){var t=this,e=t.is2D,r=t.isIdentity;return Object.assign({},t,{is2D:e,isIdentity:r})},U.prototype.multiply=function(t){return J(this,t)},U.prototype.translate=function(t,e,r){var n=e,a=r;return void 0===a&&(a=0),void 0===n&&(n=0),J(this,H(t,n,a))},U.prototype.scale=function(t,e,r){var n=e,a=r;return void 0===n&&(n=t),void 0===a&&(a=1),J(this,R(t,n,a))},U.prototype.rotate=function(t,e,r){var n=t,a=e,i=r;return void 0===a&&(a=0),void 0===i&&(i=n,n=0),J(this,Y(n,a,i))},U.prototype.rotateAxisAngle=function(t,e,r,n){if([t,e,r,n].some((function(t){return Number.isNaN(t)})))throw new TypeError("CSSMatrix: expecting 4 values");return J(this,F(t,e,r,n))},U.prototype.skewX=function(t){return J(this,B(t))},U.prototype.skewY=function(t){return J(this,G(t))},U.prototype.transformPoint=function(t){var e=H(t.x,t.y,t.z);return e.m44=t.w||1,{x:(e=this.multiply(e)).m41,y:e.m42,z:e.m43,w:e.m44}},U.prototype.transform=function(t){var e=this,r=e.m11*t.x+e.m12*t.y+e.m13*t.z+e.m14*t.w,n=e.m21*t.x+e.m22*t.y+e.m23*t.z+e.m24*t.w,a=e.m31*t.x+e.m32*t.y+e.m33*t.z+e.m34*t.w,i=e.m41*t.x+e.m42*t.y+e.m43*t.z+e.m44*t.w;return{x:r/i,y:n/i,z:a/i,w:i}},Object.defineProperties(U.prototype,$),Object.assign(U,{Translate:H,Rotate:Y,RotateAxisAngle:F,Scale:R,SkewX:B,SkewY:G,Multiply:J,fromArray:Q,fromMatrix:D,fromString:X});function K(t,e,r){var n=e[0],a=e[1],i=r[0],o=r[1],s=r[2],u=t.transformPoint({x:n,y:a,z:0,w:1}),c=u.x-i,m=u.y-o,f=u.z-s;return[c*(Math.abs(s)/Math.abs(f))+i,m*(Math.abs(s)/Math.abs(f))+o]}function W(t,e){var r,n,a,i,o,s,u,m=0,f=0,l=p(t),h=b(l),y=function(t){var e=new U,r=t.origin,n=r[0],a=r[1],i=t.translate,o=t.rotate,s=t.skew,u=t.scale;return Array.isArray(i)&&i.every((function(t){return!Number.isNaN(+t)}))&&i.some((function(t){return 0!==t}))?e=e.translate(i[0]||0,i[1]||0,i[2]||0):"number"!=typeof i||Number.isNaN(+i)||(e=e.translate(i||0,0,0)),(o||s||u)&&(e=e.translate(n,a),Array.isArray(o)&&o.every((function(t){return!Number.isNaN(+t)}))&&o.some((function(t){return 0!==t}))?e=e.rotate(o[0],o[1],o[2]):"number"!=typeof o||Number.isNaN(+o)||(e=e.rotate(0,0,o)),Array.isArray(s)&&s.every((function(t){return!Number.isNaN(+t)}))&&s.some((function(t){return 0!==t}))?(e=s[0]?e.skewX(s[0]):e,e=s[1]?e.skewY(s[1]):e):"number"!=typeof s||Number.isNaN(+s)||(e=e.skewX(s||0)),Array.isArray(u)&&u.every((function(t){return!Number.isNaN(+t)}))&&u.some((function(t){return 1!==t}))?e=e.scale(u[0],u[1],u[2]):"number"!=typeof u||Number.isNaN(+u)||(e=e.scale(u||1,u||1,u||1)),e=e.translate(-n,-a)),e}(e),v=Object.keys(e),g=e.origin,x=[y.a,y.b,y.c,y.d,y.e,y.f],w=Object.assign({},M),N=[],A=0,C="",S=[],k=[];if(!y.isIdentity){for(r=0,a=l.length;r<a;r+=1){N=l[r],l[r]&&(C=N[0]),k[r]=C,"A"!==C||y.is2D&&["skewX","skewY"].find((function(t){return v.includes(t)}))||(N=T(h[r],w),l[r]=T(h[r],w),d(l,k,r),h[r]=T(h[r],w),d(h,k,r),a=Math.max(l.length,h.length)),A=(N=h[r]).length,w.x1=+N[A-2],w.y1=+N[A-1],w.x2=+N[A-4]||w.x1,w.y2=+N[A-3]||w.y1;var P={s:l[r],c:l[r][0],x:w.x1,y:w.y1};S=S.concat([P])}return S.map((function(t){var e,r,a;switch(C=t.c,N=t.s,C){case"A":return u=function(t,e,r,n){var a=Math.cos(n*Math.PI/180),i=Math.sin(n*Math.PI/180),o=[e*(t[0]*a+t[2]*i),e*(t[1]*a+t[3]*i),r*(-t[0]*i+t[2]*a),r*(-t[1]*i+t[3]*a)],s=o[0]*o[0]+o[2]*o[2],u=o[1]*o[1]+o[3]*o[3],c=((o[0]-o[3])*(o[0]-o[3])+(o[2]+o[1])*(o[2]+o[1]))*((o[0]+o[3])*(o[0]+o[3])+(o[2]-o[1])*(o[2]-o[1])),m=(s+u)/2;if(c<1e-9*m){var f=Math.sqrt(m);return{rx:f,ry:f,ax:0}}var l,h,p=o[0]*o[1]+o[2]*o[3],y=m+(c=Math.sqrt(c))/2,v=m-c/2,d=Math.abs(p)<1e-9&&Math.abs(y-u)<1e-9?90:Math.atan(Math.abs(p)>Math.abs(y-u)?(y-s)/p:p/(y-u)*180)/Math.PI;return d>=0?(l=Math.sqrt(y),h=Math.sqrt(v)):(d+=90,l=Math.sqrt(v),h=Math.sqrt(y)),{rx:l,ry:h,ax:d}}(x,N[1],N[2],N[3]),x[0]*x[3]-x[1]*x[2]<0&&(N[5]=N[5]?0:1),e=K(y,[+N[6],+N[7]],g),o=e[0],s=e[1],N=m===o&&f===s||u.rx<1e-9*u.ry||u.ry<1e-9*u.rx?["L",o,s]:[C,u.rx,u.ry,u.ax,N[4],N[5],o,s],m=o,f=s,N;case"L":case"H":case"V":return r=K(y,[t.x,t.y],g),o=r[0],s=r[1],m!==o&&f!==s?N=["L",o,s]:f===s?N=["H",o]:m===o&&(N=["V",s]),m=o,f=s,N;default:for(n=1,i=N.length;n<i;n+=2)a=K(y,[+N[n],+N[n+1]],g),m=a[0],f=a[1],N[n]=m,N[n+1]=f;return N}}))}return c(l)}function _(t,e,r,n,a,i,o,s,u){var c=1-u;return{x:Math.pow(c,3)*t+3*Math.pow(c,2)*u*r+3*c*Math.pow(u,2)*a+Math.pow(u,3)*o,y:Math.pow(c,3)*e+3*Math.pow(c,2)*u*n+3*c*Math.pow(u,2)*i+Math.pow(u,3)*s}}function tt(t,e,r,n,a,i,o,s,u){for(var c,m=t,f=e,l=0,h=[t,e,l],p=[t,e],y=0;y<=101;y+=1){if(l+=P(p,[m=(c=_(t,e,r,n,a,i,o,s,y/101)).x,f=c.y]),p=[m,f],"number"==typeof u&&l>=u){var v=(l-u)/(l-h[2]);return{x:p[0]*(1-v)+h[0]*v,y:p[1]*(1-v)+h[1]*v}}h=[m,f,l]}return l}function et(t,e,r,n,a,i,o,s){var u,c,m,f,l=a-2*r+t-(o-2*a+r),h=2*(r-t)-2*(a-r),p=t-r,y=(-h+Math.sqrt(h*h-4*l*p))/2/l,v=(-h-Math.sqrt(h*h-4*l*p))/2/l,d=[t,o],g=[e,s],x=0,M=0;return Math.abs(y)>1e12&&(y=.5),Math.abs(v)>1e12&&(v=.5),y>0&&y<1&&(x=(u=tt(t,e,r,n,a,i,o,s,y)).x,M=u.y,d.push(x),g.push(M)),v>0&&v<1&&(x=(c=tt(t,e,r,n,a,i,o,s,v)).x,M=c.y,d.push(x),g.push(M)),l=i-2*n+e-(s-2*i+n),p=e-n,y=(-(h=2*(n-e)-2*(i-n))+Math.sqrt(h*h-4*l*p))/2/l,v=(-h-Math.sqrt(h*h-4*l*p))/2/l,Math.abs(y)>1e12&&(y=.5),Math.abs(v)>1e12&&(v=.5),y>0&&y<1&&(x=(m=tt(t,e,r,n,a,i,o,s,y)).x,M=m.y,d.push(x),g.push(M)),v>0&&v<1&&(x=(f=tt(t,e,r,n,a,i,o,s,v)).x,M=f.y,d.push(x),g.push(M)),{min:{x:Math.min.apply(Math,d),y:Math.min.apply(Math,g)},max:{x:Math.max.apply(Math,d),y:Math.max.apply(Math,g)}}}function rt(t){if(!t)return{x:0,y:0,width:0,height:0,x2:0,y2:0,cx:0,cy:0,cz:0};var e=j(t),r=0,n=0,a=[],i=[];e.forEach((function(t){var e=t.slice(-2).map(Number),o=e[0],s=e[1];if("M"===t[0])r=o,n=s,a.push(o),i.push(s);else{var u=[r,n].concat(t.slice(1)),c=et.apply(void 0,u);a=a.concat([c.min.x],[c.max.x]),i=i.concat([c.min.y],[c.max.y]),r=o,n=s}}));var o=Math.min.apply(Math,a),s=Math.min.apply(Math,i),u=Math.max.apply(Math,a),c=Math.max.apply(Math,i),m=u-o,f=c-s;return{width:m,height:f,x:o,y:s,x2:u,y2:c,cx:o+m/2,cy:s+f/2,cz:Math.max(m,f)+Math.min(m,f)/2}}Object.assign(U,{Version:"0.0.24"});var nt=function(e,r){var n=r||{};this.segments=l(e);var a=rt(this.segments),i=a.width,o=a.height,s=a.cx,u=a.cy,c=a.cz,m=t.round,f=t.origin,h=n.round,p=n.origin;if("auto"===h){var y=(""+Math.floor(Math.max(i,o))).length;m=y>=4?0:4-y}else(Number.isInteger(h)&&h>=1||!1===h)&&(m=h);if(Array.isArray(p)&&p.length>=2){var v=p.map(Number),d=v[0],g=v[1],x=v[2];f=[Number.isNaN(d)?s:d,Number.isNaN(g)?u:g,x||c]}else f=[s,u,c];return this.round=m,this.origin=f,this};function at(t,e,r,n,a,i,o,s){return 3*((s-e)*(r+a)-(o-t)*(n+i)+n*(t-a)-r*(e-i)+s*(a+t/3)-o*(i+e/3))/20}function it(t){var e=0,r=0,n=0;return j(t).map((function(t){var a,i;switch(t[0]){case"M":return e=(a=t)[1],r=a[2],0;default:return n=at.apply(void 0,[e,r].concat(t.slice(1))),i=t.slice(-2),e=i[0],r=i[1],n}})).reduce((function(t,e){return t+e}),0)}function ot(t,e,r,n,a,i,o,s,u,c){for(var m,f=[t,e],l=f[0],h=f[1],p=C(t,e,r,n,a,i,o,s,u),y=0,v=[],d=[],g=0,x=0,M=p.length;x<M;x+=6){if(v=p.slice(x,x+6),d=[l,h].concat(v),g=tt.apply(void 0,d),"number"==typeof c&&y+g>=c)return tt.apply(void 0,d.concat([c-y]));y+=g,l=(m=v.slice(-2))[0],h=m[1]}return y}function st(t,e,r,n,a,i,o){var s=1-o;return{x:Math.pow(s,2)*t+2*s*o*r+Math.pow(o,2)*a,y:Math.pow(s,2)*e+2*s*o*n+Math.pow(o,2)*i}}function ut(t,e,r,n,a,i,o){for(var s,u=t,c=e,m=0,f=[t,e,m],l=[t,e],h=0;h<=101;h+=1){if(m+=P(l,[u=(s=st(t,e,r,n,a,i,h/101)).x,c=s.y]),l=[u,c],"number"==typeof o&&m>=o){var p=(m-o)/(m-f[2]);return{x:l[0]*(1-p)+f[0]*p,y:l[1]*(1-p)+f[1]*p}}f=[u,c,m]}return m}function ct(t,e){for(var r,n,a,i=0,o=!0,s=[],u="M",c=0,m=0,f=0,l=0,h=0,p=w(b(t)),y=0,v=p.length;y<v;y+=1){if(s=(o="M"===(u=(a=p[y])[0]))?s:[m,f].concat(a.slice(1)),o){if(l=(r=a)[1],h=r[2],"number"==typeof e&&e<.001)return{x:l,y:h}}else if("L"===u){if(c=q.apply(void 0,s),e&&i+c>=e)return q.apply(void 0,s.concat([e-i]));i+=c}else if("A"===u){if(c=ot.apply(void 0,s),e&&i+c>=e)return ot.apply(void 0,s.concat([e-i]));i+=c}else if("C"===u){if(c=tt.apply(void 0,s),e&&i+c>=e)return tt.apply(void 0,s.concat([e-i]));i+=c}else if("Q"===u){if(c=ut.apply(void 0,s),e&&i+c>=e)return ut.apply(void 0,s.concat([e-i]));i+=c}else if("Z"===u){if(s=[m,f,l,h],c=q.apply(void 0,s),e&&i+c>=e)return q.apply(void 0,s.concat([e-i]));i+=c}m=(n="Z"!==u?a.slice(-2):[l,h])[0],f=n[1]}return e&&e>=i?{x:m,y:f}:i}function mt(t){return ct(t)}function ft(t,e){return ct(t,e)}function lt(t,e){var r=l(t),n=[],a=[].concat(r),i=mt(a),o=a.length-1,s=0,u=0,c=r[0],m=c.slice(-2),f={x:m[0],y:m[1]};if(o<=0||!e||!Number.isFinite(e))return{segment:c,index:0,length:u,point:f,lengthAtSegment:s};if(e>=i)return u=i-(s=mt(a=r.slice(0,-1))),{segment:r[o],index:o,length:u,lengthAtSegment:s};for(;o>0;)c=a[o],u=i-(s=mt(a=a.slice(0,-1))),i=s,n.push({segment:c,index:o,length:u,lengthAtSegment:s}),o-=1;return n.find((function(t){return t.lengthAtSegment<=e}))}function ht(t,e){for(var r=w(l(t)),n=b(r),a=mt(r),i=function(t){var r=t.x-e.x,n=t.y-e.y;return r*r+n*n},o=8,s={x:0,y:0},u=0,c=s,m=0,f=1/0,h=0;h<=a;h+=o)(u=i(s=ft(n,h)))<f&&(c=s,m=h,f=u);o/=2;for(var p={x:0,y:0},y=p,v=0,d=0,g=0,x=0;o>.5;)g=i(p=ft(n,v=m-o)),x=i(y=ft(n,d=m+o)),v>=0&&g<f?(c=p,m=v,f=g):d<=a&&x<f?(c=y,m=d,f=x):o/=2;var M=lt(r,f);return{closest:c,distance:Math.sqrt(f),segment:M}}nt.prototype.toAbsolute=function(){var t=this.segments;return this.segments=p(t),this},nt.prototype.toRelative=function(){var t=this.segments;return this.segments=v(t),this},nt.prototype.toCurve=function(){var t=this.segments;return this.segments=j(t),this},nt.prototype.reverse=function(t){this.toAbsolute();var e=this.segments,r=z(this.toString()),n=r.length>1?r:0,a=n&&c(n).map((function(e,r){return t?r?O(e):l(e):O(e)})),i=[];return i=n?a.flat(1):t?e:O(e),this.segments=c(i),this},nt.prototype.normalize=function(){var t=this.segments;return this.segments=b(t),this},nt.prototype.optimize=function(){var t=this.segments;return this.segments=Z(t,this.round),this},nt.prototype.transform=function(t){if(!t||"object"!=typeof t||"object"==typeof t&&!["translate","rotate","skew","scale"].some((function(e){return e in t})))return this;var e={};Object.keys(t).forEach((function(r){e[r]=Array.isArray(t[r])?[].concat(t[r]):Number(t[r])}));var r=this.segments,n=e.origin;if(n&&n.length>=2){var a=n.map(Number),i=a[0],o=a[1],s=a[2],u=this.origin,c=u[0],m=u[1],f=u[2];e.origin=[Number.isNaN(i)?c:i,Number.isNaN(o)?m:o,s||f]}else e.origin=Object.assign({},this.origin);return this.segments=W(r,e),this},nt.prototype.flipX=function(){return this.transform({rotate:[180,0,0]}),this},nt.prototype.flipY=function(){return this.transform({rotate:[0,180,0]}),this},nt.prototype.toString=function(){return V(this.segments,this.round)};var pt={circle:["cx","cy","r"],ellipse:["cx","cy","rx","ry"],rect:["width","height","x","y","rx","ry"],polygon:["points"],polyline:["points"],glyph:[]};var yt={CSSMatrix:U,parsePathString:l,isPathArray:f,isCurveArray:N,isAbsoluteArray:h,isRelativeArray:y,isNormalizedArray:x,isValidPath:function(t){if("string"!=typeof t)return!1;var e=new m(t);for(o(e);e.index<e.max&&!e.err.length;)u(e);return!e.err.length&&"mM".includes(e.segments[0][0])},pathToAbsolute:p,pathToRelative:v,pathToCurve:j,pathToString:V,getDrawDirection:function(t){return it(j(t))>=0},getPathArea:it,getPathBBox:rt,getTotalLength:mt,getPathLength:function(t){var e=0;return j(t).forEach((function(t,r,n){var a="M"!==t[0]?n[r-1].slice(-2).concat(t.slice(1)):[];e+="M"===t[0]?0:tt.apply(void 0,a)})),e},getPointAtLength:ft,getPointAtPathLength:function(t,e){for(var r,n,a,i,o=0,s=!0,u=0,c={x:0,y:0},m=0,f=0,l=j(t),h=0,p=l.length;h<p;h+=1){if(a=(s="M"===(i=l[h])[0])?i.slice(1):[m,f].concat(i.slice(1)),u=s?0:tt.apply(void 0,a),s)m=(r=i)[1],f=r[2];else if(o+u>e){var y=a.concat([e-o]);c=tt.apply(void 0,y);break}o+=u,m=(n=i.slice(-2))[0],f=n[1]}return c},getClosestPoint:function(t,e){return ht(t,e).closest},getSegmentOfPoint:function(t,e){var r=ht(t,e).segment;return void 0!==r?r.segment:null},getPropertiesAtPoint:ht,getPropertiesAtLength:lt,getSegmentAtLength:function(t,e){var r=lt(t,e);return(void 0!==r?r:{segment:null}).segment},isPointInStroke:function(t,e){var r=ht(t,e).distance;return Math.abs(r)<.01},clonePath:c,splitPath:z,fixPath:w,roundPath:L,optimizePath:Z,reverseCurve:function(t){var e=t.slice(1).map((function(e,r,n){return r?n[r-1].slice(-2).concat(e.slice(1)):t[0].slice(1).concat(e.slice(1))})).map((function(t){return t.map((function(e,r){return t[t.length-r-2*(1-r%2)]}))})).reverse();return[["M"].concat(e[0].slice(0,2))].concat(e.map((function(t){return["C"].concat(t.slice(2))})))},reversePath:O,normalizePath:b,transformPath:W,shapeToPath:function(e,r){var n=Object.keys(pt),a=e instanceof Element;if(a&&!n.some((function(t){return e.tagName===t})))throw TypeError('shapeToPath: "'+e+'" is not SVGElement');var i,o=document.createElementNS("http://www.w3.org/2000/svg","path"),s=a?e.tagName:e.type,u={};if(u.type=s,a){var c=pt[s];c.forEach((function(t){u[t]=e.getAttribute(t)})),Object.values(e.attributes).forEach((function(t){var e=t.name,r=t.value;c.includes(e)||o.setAttribute(e,r)}))}else Object.assign(u,e);var m,f,l,h,p=t.round;return"circle"===s?i=V((f=(m=u).cx,l=m.cy,h=m.r,[["M",f-h,l],["a",h,h,0,1,0,2*h,0],["a",h,h,0,1,0,-2*h,0]]),p):"ellipse"===s?i=V(function(t){var e=t.cx,r=t.cy,n=t.rx,a=t.ry;return[["M",e-n,r],["a",n,a,0,1,0,2*n,0],["a",n,a,0,1,0,-2*n,0]]}(u),p):["polyline","polygon"].includes(s)?i=V(function(t){for(var e=[],r=t.points.split(/[\s|,]/).map(Number),n=0;n<r.length;)e.push([n?"L":"M",r[n],r[n+1]]),n+=2;return"polygon"===t.type?e.concat([["z"]]):e}(u),p):"rect"===s?i=V(function(t){var e=+t.x||0,r=+t.y||0,n=+t.width,a=+t.height,i=+t.rx,o=+t.ry;return i||o?(i=i||o,o=o||i,2*i>n&&(i-=(2*i-n)/2),2*o>a&&(o-=(2*o-a)/2),[["M",e+i,r],["h",n-2*i],["s",i,0,i,o],["v",a-2*o],["s",0,o,-i,o],["h",2*i-n],["s",-i,0,-i,-o],["v",2*o-a],["s",0,-o,i,-o]]):[["M",e,r],["h",n],["v",a],["H",e],["Z"]]}(u),p):"line"===s?i=V(function(t){return[["M",t.x1,t.y1],["L",t.x2,t.y2]]}(u),p):"glyph"===s&&(i=a?e.getAttribute("d"):e.type),!!i&&(o.setAttribute("d",i),r&&a&&(e.before(o,e),e.remove()),o)},options:t};return Object.assign(nt,yt,{Version:"0.1.22"}),nt}));
|
package/package.json
CHANGED
|
@@ -5,11 +5,12 @@ import isAbsoluteArray from '../util/isAbsoluteArray';
|
|
|
5
5
|
* Parses a path string value or object and returns an array
|
|
6
6
|
* of segments, all converted to absolute values.
|
|
7
7
|
*
|
|
8
|
-
* @param {SVGPathCommander.pathArray
|
|
8
|
+
* @param {string | SVGPathCommander.pathArray} pathInput the path string | object
|
|
9
9
|
* @returns {SVGPathCommander.absoluteArray} the resulted `pathArray` with absolute values
|
|
10
10
|
*/
|
|
11
11
|
export default function pathToAbsolute(pathInput) {
|
|
12
|
-
if (
|
|
12
|
+
if (isAbsoluteArray(pathInput)) {
|
|
13
|
+
// @ts-ignore -- `isAbsoluteArray` checks if it's `pathArray`
|
|
13
14
|
return clonePath(pathInput);
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -13,11 +13,12 @@ import paramsParser from '../parser/paramsParser';
|
|
|
13
13
|
* In addition, un-necessary `Z` segment is removed if previous segment
|
|
14
14
|
* extends to the `M` segment.
|
|
15
15
|
*
|
|
16
|
-
* @param {SVGPathCommander.pathArray} pathInput the string to be parsed or 'pathArray'
|
|
16
|
+
* @param {string | SVGPathCommander.pathArray} pathInput the string to be parsed or 'pathArray'
|
|
17
17
|
* @returns {SVGPathCommander.curveArray} the resulted `pathArray` converted to cubic-bezier
|
|
18
18
|
*/
|
|
19
19
|
export default function pathToCurve(pathInput) {
|
|
20
20
|
if (isCurveArray(pathInput)) {
|
|
21
|
+
// @ts-ignore -- `isCurveArray` checks if it's `pathArray`
|
|
21
22
|
return clonePath(pathInput);
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -6,11 +6,12 @@ import isRelativeArray from '../util/isRelativeArray';
|
|
|
6
6
|
* Parses a path string value or object and returns an array
|
|
7
7
|
* of segments, all converted to relative values.
|
|
8
8
|
*
|
|
9
|
-
* @param {SVGPathCommander.pathArray} pathInput the path string | object
|
|
9
|
+
* @param {string | SVGPathCommander.pathArray} pathInput the path string | object
|
|
10
10
|
* @returns {SVGPathCommander.relativeArray} the resulted `pathArray` with relative values
|
|
11
11
|
*/
|
|
12
12
|
export default function pathToRelative(pathInput) {
|
|
13
13
|
if (isRelativeArray(pathInput)) {
|
|
14
|
+
// @ts-ignore -- `isRelativeArray` checks if it's `pathArray`
|
|
14
15
|
return clonePath(pathInput);
|
|
15
16
|
}
|
|
16
17
|
|
|
@@ -13,12 +13,13 @@ import isPathArray from '../util/isPathArray';
|
|
|
13
13
|
* @returns {SVGPathCommander.pathArray} the resulted `pathArray`
|
|
14
14
|
*/
|
|
15
15
|
export default function parsePathString(pathInput) {
|
|
16
|
-
if (
|
|
16
|
+
if (isPathArray(pathInput)) {
|
|
17
|
+
// @ts-ignore -- isPathArray also checks if it's an `Array`
|
|
17
18
|
return clonePath(pathInput);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
const path = new PathParser(pathInput);
|
|
21
|
+
// @ts-ignore -- pathInput is now string
|
|
22
|
+
const path = new PathParser(pathInput);
|
|
22
23
|
|
|
23
24
|
skipSpaces(path);
|
|
24
25
|
|
package/src/parser/pathParser.js
CHANGED
|
@@ -17,7 +17,6 @@ import invalidPathValue from './invalidPathValue';
|
|
|
17
17
|
export default function scanSegment(path) {
|
|
18
18
|
const { max, pathValue, index } = path;
|
|
19
19
|
const cmdCode = pathValue.charCodeAt(index);
|
|
20
|
-
// @ts-ignore
|
|
21
20
|
const reqParams = paramCounts[pathValue[index].toLowerCase()];
|
|
22
21
|
|
|
23
22
|
path.segmentStart = index;
|
package/src/process/fixPath.js
CHANGED
|
@@ -24,7 +24,7 @@ export default function fixPath(pathInput) {
|
|
|
24
24
|
const [x, y] = normalArray[segBeforeZ].slice(-2);
|
|
25
25
|
|
|
26
26
|
if (isClosed && mx === x && my === y) {
|
|
27
|
-
// @ts-ignore -- `pathSegment[]` is a `pathArray`
|
|
27
|
+
// @ts-ignore -- `pathSegment[]` is quite a `pathArray`
|
|
28
28
|
return pathArray.slice(0, -1);
|
|
29
29
|
}
|
|
30
30
|
return pathArray;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import segmentLineFactory from '../util/segmentLineFactory';
|
|
2
2
|
import midPoint from '../math/midPoint';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -21,14 +21,13 @@ export default function lineToCubic(x1, y1, x2, y2) {
|
|
|
21
21
|
const p4 = midPoint(p2, p3, t);
|
|
22
22
|
const p5 = midPoint(p3, p4, t);
|
|
23
23
|
const p6 = midPoint(p4, p5, t);
|
|
24
|
-
// const cp1 = getPointAtSegLength.apply(0, p0.concat(p2, p4, p6, t));
|
|
25
24
|
const seg1 = [...p0, ...p2, ...p4, ...p6, t];
|
|
26
25
|
// @ts-ignore
|
|
27
|
-
const cp1 =
|
|
28
|
-
// const cp2 = getPointAtSegLength.apply(0, p6.concat(p5, p3, p1, 0));
|
|
26
|
+
const cp1 = segmentLineFactory(...seg1);
|
|
29
27
|
const seg2 = [...p6, ...p5, ...p3, ...p1, 0];
|
|
30
28
|
// @ts-ignore
|
|
31
|
-
const cp2 =
|
|
29
|
+
const cp2 = segmentLineFactory(...seg2);
|
|
32
30
|
|
|
31
|
+
// @ts-ignore
|
|
33
32
|
return [cp1.x, cp1.y, cp2.x, cp2.y, x2, y2];
|
|
34
33
|
}
|
|
@@ -9,14 +9,17 @@ import paramsParser from '../parser/paramsParser';
|
|
|
9
9
|
* * convert segments to absolute values
|
|
10
10
|
* * convert shorthand path commands to their non-shorthand notation
|
|
11
11
|
*
|
|
12
|
-
* @param {SVGPathCommander.pathArray} pathInput the string to be parsed or 'pathArray'
|
|
12
|
+
* @param {string | SVGPathCommander.pathArray} pathInput the string to be parsed or 'pathArray'
|
|
13
13
|
* @returns {SVGPathCommander.normalArray} the normalized `pathArray`
|
|
14
14
|
*/
|
|
15
15
|
export default function normalizePath(pathInput) {
|
|
16
16
|
if (isNormalizedArray(pathInput)) {
|
|
17
|
+
// @ts-ignore -- `isNormalizedArray` checks if it's `pathArray`
|
|
17
18
|
return clonePath(pathInput);
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
/** @type {SVGPathCommander.normalArray} */
|
|
22
|
+
// @ts-ignore -- `absoluteArray` will become a `normalArray`
|
|
20
23
|
const path = pathToAbsolute(pathInput);
|
|
21
24
|
const params = { ...paramsParser };
|
|
22
25
|
const allPathCommands = [];
|
|
@@ -44,6 +47,5 @@ export default function normalizePath(pathInput) {
|
|
|
44
47
|
params.y2 = +(segment[seglen - 3]) || params.y1;
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
// @ts-ignore -- a `normalArray` is absolutely an `absoluteArray`
|
|
48
50
|
return path;
|
|
49
51
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import getPropertiesAtPoint from './getPropertiesAtPoint';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the point in path closest to a given point.
|
|
5
|
+
*
|
|
6
|
+
* @param {string | SVGPathCommander.pathArray} pathInput target `pathArray`
|
|
7
|
+
* @param {{x: number, y: number}} point the given point
|
|
8
|
+
* @returns {{x: number, y: number}} the best match
|
|
9
|
+
*/
|
|
10
|
+
export default function getClosestPoint(pathInput, point) {
|
|
11
|
+
return getPropertiesAtPoint(pathInput, point).closest;
|
|
12
|
+
}
|
package/src/util/getCubicSize.js
CHANGED
|
@@ -1,64 +1,66 @@
|
|
|
1
|
-
import
|
|
1
|
+
import segmentCubicFactory from './segmentCubicFactory';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Returns the cubic-bezier segment
|
|
4
|
+
* Returns the cubic-bezier segment bounding box.
|
|
5
5
|
*
|
|
6
|
-
* @param {number}
|
|
7
|
-
* @param {number}
|
|
6
|
+
* @param {number} x1 the starting point X
|
|
7
|
+
* @param {number} y1 the starting point Y
|
|
8
8
|
* @param {number} c1x the first control point X
|
|
9
9
|
* @param {number} c1y the first control point Y
|
|
10
10
|
* @param {number} c2x the second control point X
|
|
11
11
|
* @param {number} c2y the second control point Y
|
|
12
|
-
* @param {number}
|
|
13
|
-
* @param {number}
|
|
14
|
-
* @returns {SVGPathCommander.segmentLimits} the
|
|
12
|
+
* @param {number} x2 the ending point X
|
|
13
|
+
* @param {number} y2 the ending point Y
|
|
14
|
+
* @returns {SVGPathCommander.segmentLimits} the bounding box of the cubic-bezier segment
|
|
15
15
|
*/
|
|
16
|
-
export default function getCubicSize(
|
|
17
|
-
let a = (c2x - 2 * c1x +
|
|
18
|
-
let b = 2 * (c1x -
|
|
19
|
-
let c =
|
|
16
|
+
export default function getCubicSize(x1, y1, c1x, c1y, c2x, c2y, x2, y2) {
|
|
17
|
+
let a = (c2x - 2 * c1x + x1) - (x2 - 2 * c2x + c1x);
|
|
18
|
+
let b = 2 * (c1x - x1) - 2 * (c2x - c1x);
|
|
19
|
+
let c = x1 - c1x;
|
|
20
20
|
let t1 = (-b + Math.sqrt(b * b - 4 * a * c)) / 2 / a;
|
|
21
21
|
let t2 = (-b - Math.sqrt(b * b - 4 * a * c)) / 2 / a;
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (Math.abs(t2) >
|
|
22
|
+
const X = [x1, x2];
|
|
23
|
+
const Y = [y1, y2];
|
|
24
|
+
let x = 0;
|
|
25
|
+
let y = 0;
|
|
26
|
+
|
|
27
|
+
if (Math.abs(t1) > 1e12) t1 = 0.5;
|
|
28
|
+
if (Math.abs(t2) > 1e12) t2 = 0.5;
|
|
29
29
|
|
|
30
30
|
if (t1 > 0 && t1 < 1) {
|
|
31
|
-
|
|
32
|
-
x
|
|
33
|
-
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
({ x, y } = segmentCubicFactory(x1, y1, c1x, c1y, c2x, c2y, x2, y2, t1));
|
|
33
|
+
X.push(x);
|
|
34
|
+
Y.push(y);
|
|
34
35
|
}
|
|
35
36
|
if (t2 > 0 && t2 < 1) {
|
|
36
|
-
|
|
37
|
-
x
|
|
38
|
-
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
({ x, y } = segmentCubicFactory(x1, y1, c1x, c1y, c2x, c2y, x2, y2, t2));
|
|
39
|
+
X.push(x);
|
|
40
|
+
Y.push(y);
|
|
39
41
|
}
|
|
40
|
-
a = (c2y - 2 * c1y +
|
|
41
|
-
b = 2 * (c1y -
|
|
42
|
-
c =
|
|
42
|
+
a = (c2y - 2 * c1y + y1) - (y2 - 2 * c2y + c1y);
|
|
43
|
+
b = 2 * (c1y - y1) - 2 * (c2y - c1y);
|
|
44
|
+
c = y1 - c1y;
|
|
43
45
|
t1 = (-b + Math.sqrt(b * b - 4 * a * c)) / 2 / a;
|
|
44
46
|
t2 = (-b - Math.sqrt(b * b - 4 * a * c)) / 2 / a;
|
|
45
|
-
|
|
46
|
-
if (Math.abs(
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
if (Math.abs(t2) > '1e12') t2 = 0.5;
|
|
47
|
+
if (Math.abs(t1) > 1e12) t1 = 0.5;
|
|
48
|
+
if (Math.abs(t2) > 1e12) t2 = 0.5;
|
|
49
49
|
|
|
50
50
|
if (t1 > 0 && t1 < 1) {
|
|
51
|
-
|
|
52
|
-
x
|
|
53
|
-
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
({ x, y } = segmentCubicFactory(x1, y1, c1x, c1y, c2x, c2y, x2, y2, t1));
|
|
53
|
+
X.push(x);
|
|
54
|
+
Y.push(y);
|
|
54
55
|
}
|
|
55
56
|
if (t2 > 0 && t2 < 1) {
|
|
56
|
-
|
|
57
|
-
x
|
|
58
|
-
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
({ x, y } = segmentCubicFactory(x1, y1, c1x, c1y, c2x, c2y, x2, y2, t2));
|
|
59
|
+
X.push(x);
|
|
60
|
+
Y.push(y);
|
|
59
61
|
}
|
|
60
62
|
return {
|
|
61
|
-
min: { x: Math.min
|
|
62
|
-
max: { x: Math.max
|
|
63
|
+
min: { x: Math.min(...X), y: Math.min(...Y) },
|
|
64
|
+
max: { x: Math.max(...X), y: Math.max(...Y) },
|
|
63
65
|
};
|
|
64
66
|
}
|
package/src/util/getPathArea.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
import pathToCurve from '../convert/pathToCurve';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Returns the area of a single segment
|
|
4
|
+
* Returns the area of a single cubic-bezier segment.
|
|
5
5
|
*
|
|
6
6
|
* http://objectmix.com/graphics/133553-area-closed-bezier-curve.html
|
|
7
7
|
*
|
|
8
|
-
* @param {number}
|
|
9
|
-
* @param {number}
|
|
10
|
-
* @param {number}
|
|
11
|
-
* @param {number}
|
|
12
|
-
* @param {number}
|
|
13
|
-
* @param {number}
|
|
14
|
-
* @param {number}
|
|
15
|
-
* @param {number}
|
|
8
|
+
* @param {number} x1 the starting point X
|
|
9
|
+
* @param {number} y1 the starting point Y
|
|
10
|
+
* @param {number} c1x the first control point X
|
|
11
|
+
* @param {number} c1y the first control point Y
|
|
12
|
+
* @param {number} c2x the second control point X
|
|
13
|
+
* @param {number} c2y the second control point Y
|
|
14
|
+
* @param {number} x2 the ending point X
|
|
15
|
+
* @param {number} y2 the ending point Y
|
|
16
16
|
* @returns {number} the area of the cubic-bezier segment
|
|
17
17
|
*/
|
|
18
|
-
function getCubicSegArea(
|
|
19
|
-
return (3 * ((
|
|
20
|
-
+ (
|
|
21
|
-
+ (
|
|
18
|
+
function getCubicSegArea(x1, y1, c1x, c1y, c2x, c2y, x2, y2) {
|
|
19
|
+
return (3 * ((y2 - y1) * (c1x + c2x) - (x2 - x1) * (c1y + c2y)
|
|
20
|
+
+ (c1y * (x1 - c2x)) - (c1x * (y1 - c2y))
|
|
21
|
+
+ (y2 * (c2x + x1 / 3)) - (x2 * (c2y + y1 / 3)))) / 20;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Returns the area of a shape.
|
|
26
26
|
* @author Jürg Lehni & Jonathan Puckey
|
|
27
27
|
*
|
|
28
|
-
*
|
|
28
|
+
* @see https://github.com/paperjs/paper.js/blob/develop/src/path/Path.js
|
|
29
29
|
*
|
|
30
30
|
* @param {SVGPathCommander.pathArray} path the shape `pathArray`
|
|
31
31
|
* @returns {number} the length of the cubic-bezier segment
|
|
32
32
|
*/
|
|
33
33
|
export default function getPathArea(path) {
|
|
34
|
-
let x = 0; let y = 0;
|
|
35
|
-
|
|
34
|
+
let x = 0; let y = 0; let len = 0;
|
|
35
|
+
|
|
36
36
|
return pathToCurve(path).map((seg) => {
|
|
37
37
|
switch (seg[0]) {
|
|
38
38
|
case 'M':
|
|
@@ -40,9 +40,9 @@ export default function getPathArea(path) {
|
|
|
40
40
|
return 0;
|
|
41
41
|
default:
|
|
42
42
|
// @ts-ignore -- the utility will have proper amount of params
|
|
43
|
-
len = getCubicSegArea(
|
|
44
|
-
|
|
45
|
-
[x, y] = seg.slice(-2)
|
|
43
|
+
len = getCubicSegArea(x, y, ...seg.slice(1));
|
|
44
|
+
// @ts-ignore -- the segment always has numbers
|
|
45
|
+
[x, y] = seg.slice(-2);
|
|
46
46
|
return len;
|
|
47
47
|
}
|
|
48
48
|
}).reduce((a, b) => a + b, 0);
|
package/src/util/getPathBBox.js
CHANGED
|
@@ -33,27 +33,16 @@ export default function getPathBBox(path) {
|
|
|
33
33
|
// @ts-ignore -- this should be fine
|
|
34
34
|
const dim = getCubicSize(...sizeArgs);
|
|
35
35
|
|
|
36
|
-
// X = X.concat(dim.min.x, dim.max.x);
|
|
37
36
|
X = [...X, ...[dim.min.x, dim.max.x]];
|
|
38
|
-
|
|
39
|
-
// Y = Y.concat(dim.min.y, dim.max.y);
|
|
40
37
|
Y = [...Y, ...[dim.min.y, dim.max.y]];
|
|
41
38
|
x = s1;
|
|
42
39
|
y = s2;
|
|
43
40
|
}
|
|
44
41
|
});
|
|
45
42
|
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
// const xTop = Math.min.apply(0, X);
|
|
48
43
|
const xTop = Math.min(...X);
|
|
49
|
-
// @ts-ignore
|
|
50
|
-
// const yTop = Math.min.apply(0, Y);
|
|
51
44
|
const yTop = Math.min(...Y);
|
|
52
|
-
// @ts-ignore
|
|
53
|
-
// const xBot = Math.max.apply(0, X);
|
|
54
45
|
const xBot = Math.max(...X);
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
// const yBot = Math.max.apply(0, Y);
|
|
57
46
|
const yBot = Math.max(...Y);
|
|
58
47
|
const width = xBot - xTop;
|
|
59
48
|
const height = yBot - yTop;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import segmentCubicFactory from './segmentCubicFactory';
|
|
2
2
|
import pathToCurve from '../convert/pathToCurve';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Returns the shape total length,
|
|
6
|
-
* or the equivalent to `shape.getTotalLength()`
|
|
7
|
-
* pathToCurve version
|
|
5
|
+
* Returns the shape total length, or the equivalent to `shape.getTotalLength()`.
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* This is the `pathToCurve` version which is faster and more efficient for
|
|
8
|
+
* paths that are `curveArray`.
|
|
9
|
+
*
|
|
10
|
+
* @param {string | SVGPathCommander.curveArray} path the target `pathArray`
|
|
11
|
+
* @returns {number} the `curveArray` total length
|
|
11
12
|
*/
|
|
12
13
|
export default function getPathLength(path) {
|
|
13
14
|
let totalLength = 0;
|
|
14
15
|
pathToCurve(path).forEach((s, i, curveArray) => {
|
|
15
16
|
const args = s[0] !== 'M' ? [...curveArray[i - 1].slice(-2), ...s.slice(1)] : [];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
: getSegCubicLength(...args);
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
totalLength += s[0] === 'M' ? 0 : segmentCubicFactory(...args);
|
|
19
19
|
});
|
|
20
20
|
return totalLength;
|
|
21
21
|
}
|
|
@@ -1,36 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import getPointAtSegLength from './getPointAtSegLength';
|
|
3
|
-
import pathToCurve from '../convert/pathToCurve';
|
|
1
|
+
import pathLengthFactory from './pathLengthFactory';
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Returns [x,y] coordinates of a point at a given length of a shape.
|
|
7
5
|
*
|
|
8
|
-
* @param {string | SVGPathCommander.pathArray}
|
|
9
|
-
* @param {number}
|
|
10
|
-
* @returns {number
|
|
6
|
+
* @param {string | SVGPathCommander.pathArray} pathInput the `pathArray` to look into
|
|
7
|
+
* @param {number} distance the length of the shape to look at
|
|
8
|
+
* @returns {{x: number, y: number}} the requested {x, y} point coordinates
|
|
11
9
|
*/
|
|
12
|
-
export default function getPointAtLength(
|
|
13
|
-
let totalLength = 0;
|
|
14
|
-
let segLen;
|
|
15
|
-
let data;
|
|
16
|
-
let result;
|
|
10
|
+
export default function getPointAtLength(pathInput, distance) {
|
|
17
11
|
// @ts-ignore
|
|
18
|
-
return
|
|
19
|
-
data = i ? [...curveArray[i - 1].slice(-2), ...seg.slice(1)] : seg.slice(1);
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
segLen = i ? getSegCubicLength(...data) : 0;
|
|
22
|
-
totalLength += segLen;
|
|
23
|
-
|
|
24
|
-
if (i === 0) {
|
|
25
|
-
result = { x: data[0], y: data[1] };
|
|
26
|
-
} else if (totalLength > length && length > totalLength - segLen) {
|
|
27
|
-
const args = [...data, 1 - ((totalLength - length) / segLen)];
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
result = getPointAtSegLength(...args);
|
|
30
|
-
} else {
|
|
31
|
-
result = null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return result;
|
|
35
|
-
}).filter((x) => x).slice(-1)[0]; // isolate last segment
|
|
12
|
+
return pathLengthFactory(pathInput, distance);
|
|
36
13
|
}
|