var t={};function n(t=[],n){const r=[],o={beziers:t,curves:r,idx:n};if(0===t.length)return o;let i,c=0;for(let n=0;n{for(var r in e)t.o(e,r)&&!t.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:e[r]})},t.o=(t,n)=>Object.prototype.hasOwnProperty.call(t,n);class o{initialPoint=void 0;p;vals=void 0;prev2ndCubicControlPoint=void 0;prev2ndQuadraticControlPoint=void 0;constructor(){this.p=[0,0]}}function i(t){const n=[t.p,t.initialPoint];return t.prev2ndCubicControlPoint=void 0,t.prev2ndQuadraticControlPoint=void 0,n}function c(t){t.prev2ndCubicControlPoint=void 0,t.prev2ndQuadraticControlPoint=void 0;const n=(e=t.p,t.vals[0],t.vals[1],t.vals[2],t.vals[3],t.vals[4],[[e,[t.vals[5],t.vals[6]]]]);var e;const r=n[n.length-1];return t.p=r[r.length-1],n}const s={c:function(t){const n=[t.p,[t.vals[0],t.vals[1]],[t.vals[2],t.vals[3]],[t.vals[4],t.vals[5]]];return t.prev2ndCubicControlPoint=n[2],t.prev2ndQuadraticControlPoint=void 0,n},h:function(t){const n=[t.p,[t.vals[0],t.p[1]]];return t.prev2ndCubicControlPoint=void 0,t.prev2ndQuadraticControlPoint=void 0,n},l:function(t){const n=[t.p,t.vals];return t.prev2ndCubicControlPoint=void 0,t.prev2ndQuadraticControlPoint=void 0,n},q:function(t){const n=[t.vals[0],t.vals[1]],e=[t.vals[2],t.vals[3]];return t.prev2ndCubicControlPoint=void 0,t.prev2ndQuadraticControlPoint=n,[t.p,n,e]},s:function(t){const n=t.prev2ndCubicControlPoint?[t.p[0]-t.prev2ndCubicControlPoint[0]+t.p[0],t.p[1]-t.prev2ndCubicControlPoint[1]+t.p[1]]:t.p,e=[t.p,n,[t.vals[0],t.vals[1]],[t.vals[2],t.vals[3]]];return t.prev2ndCubicControlPoint=e[2],t.prev2ndQuadraticControlPoint=void 0,e},t:function(t){const n=t.prev2ndQuadraticControlPoint?[t.p[0]-t.prev2ndQuadraticControlPoint[0]+t.p[0],t.p[1]-t.prev2ndQuadraticControlPoint[1]+t.p[1]]:t.p,e=[t.vals[0],t.vals[1]];return t.prev2ndCubicControlPoint=void 0,t.prev2ndQuadraticControlPoint=n,[t.p,n,e]},v:function(t){const n=[t.p,[t.p[0],t.vals[0]]];return t.prev2ndCubicControlPoint=void 0,t.prev2ndQuadraticControlPoint=void 0,n},z:i};function u(t){let n=0,e=0,r=1,o=0,i=1,c=1;const s=t._currentIndex;if(t._skipOptionalSpaces(),t._currentIndex"9")&&"."!==t._string[t._currentIndex])throw new Error("The first character of a number must be one of [0-9+-.].");const u=t._currentIndex;for(;t._currentIndex="0"&&t._string[t._currentIndex]<="9";)t._currentIndex+=1;if(t._currentIndex!==u){let n=t._currentIndex-1,r=1;for(;n>=u;)e+=r*(Number(t._string[n])-0),n-=1,r*=10}if(t._currentIndex=t._endIndex||t._string[t._currentIndex]<"0"||t._string[t._currentIndex]>"9")throw new Error("There must be a least one digit following the .");for(;t._currentIndex="0"&&t._string[t._currentIndex]<="9";)r*=10,o+=Number(t._string.charAt(t._currentIndex))/r,t._currentIndex+=1}if(t._currentIndex!==s&&t._currentIndex+1=t._endIndex||t._string[t._currentIndex]<"0"||t._string[t._currentIndex]>"9")throw new Error("There must be an exponent.");for(;t._currentIndex="0"&&t._string[t._currentIndex]<="9";)n*=10,n+=Number(t._string[t._currentIndex]),t._currentIndex+=1}let f=e+o;if(f*=i,n&&(f*=Math.pow(10,c*n)),s===t._currentIndex)throw new Error("Internal error: startIndex === source._currentIndex");return t._skipOptionalSpacesOrDelimiter(),f}const f={Z:"Z",M:"M",L:"L",C:"C",Q:"Q",A:"A",H:"H",V:"V",S:"S",T:"T",z:"Z",m:"m",l:"l",c:"c",q:"q",a:"a",h:"h",v:"v",s:"s",t:"t"};class l{_string;_currentIndex;_endIndex;_prevCommand;constructor(t){this._string=t,this._currentIndex=0,this._endIndex=this._string.length,this._prevCommand=void 0,this._skipOptionalSpaces()}parseSegment(){const t=this._string[this._currentIndex];let n,e=f[t];if(void 0===e){if(void 0===this._prevCommand)throw new Error("Implicit command not allowed for first commands.");if(!("+"===t||"-"===t||"."===t||t>="0"&&t<="9")||"Z"===this._prevCommand)throw new Error("Remaining coordinates not found for implicit command");e="M"===this._prevCommand?"L":"m"===this._prevCommand?"l":this._prevCommand}else this._currentIndex+=1;this._prevCommand=e;const r=e.toUpperCase();if("H"===r||"V"===r?n=[u(this)]:"M"===r||"L"===r||"T"===r?n=[u(this),u(this)]:"S"===r||"Q"===r?n=[u(this),u(this),u(this),u(this)]:"C"===r?n=[u(this),u(this),u(this),u(this),u(this),u(this)]:"A"===r?n=[u(this),u(this),u(this),this._parseArcFlag(),this._parseArcFlag(),u(this),u(this)]:"Z"===r&&(this._skipOptionalSpaces(),n=[]),void 0===n)throw new Error("Unknown command");return{type:e,values:n}}hasMoreData(){return this._currentIndex=this._endIndex)throw new Error("Unable to parse arc flag");let t;const n=this._string[this._currentIndex];if(this._currentIndex+=1,"0"===n)t=0;else{if("1"!==n)throw new Error("Unable to parse arc flag - arc flag must be 0 or 1");t=1}return this._skipOptionalSpacesOrDelimiter(),t}}function a(t){return function(t){if(0===t.length)return[];if("m"!==t[0].type.toLowerCase())throw new Error("Invalid SVG - every new path must start with an M or m.");const n=new o,e=[];let r,u=[];for(let o=0;o0&&("z"!==r&&u.push(i(n)),e.push(u)),e}(function(t){if(!t.length)return[];const n=new l(t),e=[];if(!n.initialCommandIsMoveTo())throw new Error("Path must start with m or M");for(;n.hasMoreData();)e.push(n.parseSegment());return e}(t))}function p(t,n,e="thin10 red nofill",r=0){if(0===n.length)return[];let o=`M${n[0][0][0]} ${n[0][0][1]} `;for(let t=0;tnew Array(n).fill(0));for(let r=0;r0)return!1;const l=e+c,a=l-2*o,p=et(l)+et(a);return!(et(a)-p>0)&&0===tt(K(nt(n,i),[2*r]))&&0===tt(K(nt(e,c),[2*o]))}const ot=134217729;function it(t,n){const e=t*n,r=ot*t,o=r-(r-t),i=t-o,c=ot*n,s=c-(c-n),u=n-s;return[i*u-(e-o*s-i*s-o*u),e]}const ct=it,st=B,ut=Q,ft=V,lt=Number.EPSILON/2,at=Math.abs;function pt(t){const[[n,e],[r,o],[i,c],[s,u]]=t,f=s+3*r,l=n+3*i,a=f-l,p=at(3*r)+at(f)+(at(3*i)+at(l))+at(a);if(at(a)-lt*p>0)return!1;const h=u+3*o,d=e+3*c,v=h-d,g=at(3*o)+at(h)+(at(3*c)+at(d))+at(v);return!(at(v)-lt*g>0)&&0===ut(ft(st([s],ct(3,r)),st([n],ct(3,i))))&&0===ut(ft(st([u],ct(3,o)),st([e],ct(3,c))))}function ht(t){let n=t[0];for(let e=1;e=0;--t){const e=r,i=n[t];r=e+i;const c=i-(r-e);c&&(n[--o]=r,r=c)}let i=0;for(let t=o;t0){if(o<=0)return i;c=r+o}else{if(!(r<0))return i;if(o>=0)return i;c=-r-o}return Math.abs(i)>=3330669073875472e-31*c?i:function(t,n,e,r){const o=t[0]-e[0],i=n[0]-e[0],c=t[1]-e[1],s=n[1]-e[1],u=V(it(o,s),it(c,i));let f=ht(u);if(Math.abs(f)>=2220446049250315e-31*r)return f;const l=dt(t[0],e[0])[0],a=dt(n[0],e[0])[0],p=dt(t[1],e[1])[0],h=dt(n[1],e[1])[0];if(0===l&&0===p&&0===a&&0===h)return f;const d=1109335647967049e-46*r+3330669073875471e-31*Math.abs(f);if(f+=o*h+s*l-(c*a+i*p),Math.abs(f)>=d)return f;const v=B(u,V(it(l,s),it(p,i))),g=B(v,V(it(o,h),it(c,a)));let m=B(g,V(it(l,h),it(p,a)));return m=vt(m),m[m.length-1]}(t,n,e,c)}const mt=gt;function xt(t){if(4===t.length)return 0===mt(t[0],t[1],t[2])&&0===mt(t[1],t[2],t[3])&&0===mt(t[0],t[2],t[3]);if(3===t.length)return 0===mt(t[0],t[1],t[2]);if(t.length<=2)return!0;throw new Error("The given bezier curve must be of order <= 3.")}const bt=k,It=V,_t=J,Nt=Q,St=Math.abs;const Et=Math.abs,wt=j(1);function Mt(t){const{coeffs:[[n,e,r],[o,i,c]],errorBound:[[s,u],[f,l]]}=function(t){const[[n,e],[r,o],[i,c],[s,u]]=t,f=s-n,l=r-i,a=f+3*l,p=i+n,h=p-2*r,d=r-n,v=u-e,g=o-c,m=v+3*g,x=c+e,b=x-2*o,I=o-e;return{coeffs:[[a,3*h,3*d,n],[m,3*b,3*I,e]],errorBound:[[St(f)+6*St(l)+St(a),6*(St(p)+St(h)),6*St(d),0],[St(v)+6*St(g)+St(m),6*(St(x)+St(b)),6*St(I),0]]}}(t),a=Et(n),p=Et(e),h=Et(r),d=Et(o),v=Et(i),g=Et(c),m=e*o,x=n*i,b=n*c,I=r*o,_=e*c,N=r*i,S=u*d+p*f+Et(m),E=s*v+a*l+Et(x),w=s*g+Et(b),M=h*f+Et(I),O=u*g+Et(_),T=h*l+Et(N),C=m-x,y=Et(C),P=S+E+y,A=I-b,B=Et(A),z=M+w+B,F=_-N,Y=Et(F),V=O+T+Y,L=C*C,k=C*A,$=F*C,X=A*A,q=$+X;return{coeffs:[L,k,q],errBound:[2*P*y+Et(L),P*B+y*z+Et(k),V*y+Y*P+Et($)+(2*B*z+Et(X))+Et(q)].map(t=>wt*t)}}const Ot=dt,Tt=J,Ct=$,yt=D,Pt=B;function At(t){if(4===t.length)return Bt(t);if(3===t.length)return zt(t);if(2===t.length)return Ft(t);if(1===t.length)return function(t){const[[n,e]]=t;return[[[n]],[[e]]]}(t);throw new Error("The given bezier curve must be of order <= cubic.")}function Bt(t){const[[n,e],[r,o],[i,c],[s,u]]=t;return[[Pt(Ot(s,n),Ct(3,Ot(r,i))),Ct(3,yt(Tt(i,n),-2*r)),Ct(3,Ot(r,n)),[n]],[Pt(Ot(u,e),Ct(3,Ot(o,c))),Ct(3,yt(Tt(c,e),-2*o)),Ct(3,Ot(o,e)),[e]]]}function zt(t){const[[n,e],[r,o],[i,c]]=t;return[[yt(Tt(i,n),-2*r),Ot(2*r,2*n),[n]],[yt(Tt(c,e),-2*o),Ot(2*o,2*e),[e]]]}function Ft(t){const[[n,e],[r,o]]=t;return[[Ot(r,n),[n]],[Ot(o,e),[e]]]}const Yt=H,Vt=B,Lt=V;function kt(t){const[[n,e,r],[o,i,c]]=Bt(t),s=Yt(e,o),u=Yt(n,i),f=Yt(n,c),l=Yt(r,o),a=Yt(e,c),p=Yt(r,i),h=Lt(s,u),d=Lt(l,f),v=Lt(a,p),g=Yt(h,h),m=Yt(h,d),x=Yt(h,v),b=Yt(d,d);return[g,m,Vt(x,b)]}const $t=Q,Xt=G,qt=V,Ht=H,Dt=$,Qt=P,Gt=A,Rt=B,Ut=D,jt=Math.abs,Zt=j(1),Wt={order:0,realOrder:0,collinear:!0,nodeType:"n/a"},Jt={order:1,realOrder:1,collinear:!0,nodeType:"n/a"},Kt={order:1,realOrder:0,collinear:!0,nodeType:"n/a"},tn={order:2,realOrder:2,collinear:!1,nodeType:"n/a"},nn={order:2,realOrder:2,collinear:!0,nodeType:"n/a"},en={order:2,realOrder:1,collinear:!0,nodeType:"n/a"},rn={order:2,realOrder:0,collinear:!0,nodeType:"n/a"},on={order:3,realOrder:3,collinear:!1,nodeType:"crunode"},cn={order:3,realOrder:3,collinear:!1,nodeType:"acnode"},sn={order:3,realOrder:3,collinear:!1,nodeType:"cusp"},un={order:3,realOrder:3,collinear:!1,nodeType:"explicit"},fn={order:3,realOrder:3,collinear:!0,nodeType:"n/a"},ln={order:3,realOrder:2,collinear:!1,nodeType:"n/a"},an={order:3,realOrder:2,collinear:!0,nodeType:"n/a"},pn={order:3,realOrder:1,collinear:!0,nodeType:"n/a"},hn={order:3,realOrder:0,collinear:!0,nodeType:"n/a"};function dn(t){const n=[],e=t.length-1;for(let r=0;r1/t(function(t){return t.slice().reverse()}(n))};function Sn(t){const n=t.length-1;if(n<1)return 0;t[0]<0&&(t=_n(t));const e=[];for(let t=0;t=0)continue;let n=Number.POSITIVE_INFINITY,i=!1;for(let r=0;rc&&(n=c),i=!0}i&&r-wn(function(t){const n=t.length-1;if(n<0)return[];const e=t.slice();for(let t=0;t0&&(s=i,u=r,f=c-i,l=f)}},yn=En,Pn=Sn,An=Mn;function Bn(t,n=Number.NEGATIVE_INFINITY,e=Number.POSITIVE_INFINITY){t=An(t);let r=0;for(;0===t[t.length-1];)t=t.slice(0,-1),r++;if(t.length<=1){const t=[];for(let n=0;n=0;r--){const t=o[r],c=[];let s=n,u=Tn(t,s);0===u&&0===r&&c.push(n);for(let n=0;n0&&n<=0&&e>=0){const t=[];let n=!1;for(let e=0;e=0){for(let n=0;nl)return on;const[a,p,h]=kt(t),d=qt(Ht(p,p),Dt(4,Ht(a,h))),v=$t(d);return v<0?cn:v>0?on:sn}(t);if(3===t.length)return xt(t)?rt(t)?W(t)?rn:en:nn:tn;if(2===t.length)return W(t)?Kt:Jt;if(1===t.length)return Wt;throw new Error("The given bezier curve must be of order <= 3")}(n),[[i,c],[s,u],[f,l],[a,p]]=n,h=[s-i,u-c],d=[f-s,l-u],v=[a-f,p-l];if(0===d[0]&&0===d[1]||o.realOrder<=2)return E(h,v);const g=E(h,d)+E(d,v);return"acnode"===o.nodeType||"cusp"===o.nodeType?g<=-Yn?g+2*Yn:g>=+Yn?g-2*Yn:g:g}throw new Error("The given bezier curve must be of order <= 3.")}function Ln(t,n){const e=n[0]-t[0],r=n[1]-t[1];return Math.sqrt(e*e+r*r)}function kn(t,n){const[e,r]=t,[[o,i],[c,s]]=n;return Ln([o+e*(c-o),i+e*(s-i)],[o+r*(c-o),i+r*(s-i)])}function $n(t,n,e=16){if(n[0]===n[1])return 0;const{weights:r,abscissas:o}=Xn[e],[i,c]=n;let s=0;const u=(c-i)/2,f=(c+i)/2;for(let n=0;n<=e-1;n++)s+=r[n]*t(u*o[n]+f);return u*s}const Xn={2:{weights:[1,1],abscissas:[-.5773502691896257,.5773502691896257]},4:{weights:[.6521451548625461,.6521451548625461,.3478548451374538,.3478548451374538],abscissas:[-.3399810435848563,.3399810435848563,-.8611363115940526,.8611363115940526]},8:{weights:[.362683783378362,.362683783378362,.3137066458778873,.3137066458778873,.2223810344533745,.2223810344533745,.1012285362903763,.1012285362903763],abscissas:[-.1834346424956498,.1834346424956498,-.525532409916329,.525532409916329,-.7966664774136267,.7966664774136267,-.9602898564975363,.9602898564975363]},16:{weights:[.027152459411754096,.062253523938647894,.09515851168249279,.12462897125553388,.14959598881657674,.16915651939500254,.18260341504492358,.1894506104550685,.1894506104550685,.18260341504492358,.16915651939500254,.14959598881657674,.12462897125553388,.09515851168249279,.062253523938647894,.027152459411754096],abscissas:[-.9894009349916499,-.9445750230732326,-.8656312023878318,-.755404408355003,-.6178762444026438,-.45801677765722737,-.2816035507792589,-.09501250983763744,.09501250983763744,.2816035507792589,.45801677765722737,.6178762444026438,.755404408355003,.8656312023878318,.9445750230732326,.9894009349916499]},64:{weights:[.048690957009139724,.048690957009139724,.04857546744150343,.04857546744150343,.048344762234802954,.048344762234802954,.04799938859645831,.04799938859645831,.04754016571483031,.04754016571483031,.04696818281621002,.04696818281621002,.046284796581314416,.046284796581314416,.04549162792741814,.04549162792741814,.044590558163756566,.044590558163756566,.04358372452932345,.04358372452932345,.04247351512365359,.04247351512365359,.04126256324262353,.04126256324262353,.03995374113272034,.03995374113272034,.038550153178615626,.038550153178615626,.03705512854024005,.03705512854024005,.035472213256882386,.035472213256882386,.033805161837141606,.033805161837141606,.03205792835485155,.03205792835485155,.030234657072402478,.030234657072402478,.028339672614259483,.028339672614259483,.02637746971505466,.02637746971505466,.024352702568710874,.024352702568710874,.022270173808383253,.022270173808383253,.02013482315353021,.02013482315353021,.017951715775697343,.017951715775697343,.015726030476024718,.015726030476024718,.013463047896718643,.013463047896718643,.011168139460131128,.011168139460131128,.008846759826363947,.008846759826363947,.006504457968978363,.006504457968978363,.004147033260562468,.004147033260562468,.001783280721696433,.001783280721696433],abscissas:[-.024350292663424433,.024350292663424433,-.07299312178779904,.07299312178779904,-.12146281929612056,.12146281929612056,-.16964442042399283,.16964442042399283,-.21742364374000708,.21742364374000708,-.2646871622087674,.2646871622087674,-.31132287199021097,.31132287199021097,-.3572201583376681,.3572201583376681,-.4022701579639916,.4022701579639916,-.4463660172534641,.4463660172534641,-.48940314570705296,.48940314570705296,-.5312794640198946,.5312794640198946,-.571895646202634,.571895646202634,-.6111553551723933,.6111553551723933,-.6489654712546573,.6489654712546573,-.6852363130542333,.6852363130542333,-.7198818501716109,.7198818501716109,-.7528199072605319,.7528199072605319,-.7839723589433414,.7839723589433414,-.8132653151227975,.8132653151227975,-.8406292962525803,.8406292962525803,-.8659993981540928,.8659993981540928,-.8893154459951141,.8893154459951141,-.9105221370785028,.9105221370785028,-.9295691721319396,.9295691721319396,-.9464113748584028,.9464113748584028,-.9610087996520538,.9610087996520538,-.973326827789911,.973326827789911,-.983336253884626,.983336253884626,-.9910133714767443,.9910133714767443,-.9963401167719553,.9963401167719553,-.9993050417357722,.9993050417357722]}};function qn(t){if(4===t.length)return function(t){const[[n,e],[r,o],[i,c],[s,u]]=t;return[[3*(s-n+3*(r-i)),6*(i+n-2*r),3*(r-n)],[3*(u-e+3*(o-c)),6*(c+e-2*o),3*(o-e)]]}(t);if(3===t.length)return function(t){const[[n,e],[r,o],[i,c]]=t;return[[2*(i+n-2*r),2*(r-n)],[2*(c+e-2*o),2*(o-e)]]}(t);if(2===t.length)return function(t){const[[n,e],[r,o]]=t;return[[r-n],[o-e]]}(t);if(1===t.length)return[[0],[0]];throw new Error("The bezier curve must be of order <= 3.")}function Hn(t){const[n,e]=qn(t);return function(t){const r=vn(n,t),o=vn(e,t);return Math.sqrt(r*r+o*o)}}const{abs:Dn}=Math;function Qn(t){const n=[];for(let e=0;e0?e:-e}const[[I],[_]]=xe(t),[[N],[S]]=xe(n),E=V(H(e,_),H(r,I)),w=B(H(e,o),H(r,i)),M=V(H(c,S),H(s,N)),O=B(H(c,u),H(s,f)),T=V(H(v,E),k(H(l,w),3)),C=V(H(d,M),k(H(a,O),3)),y=Q(T),P=Q(C);if(y!==P)return y-P;if(0===y&&0===P)return 0;const A=H(T,T),z=H(g,m),F=H(C,C),Y=H(x,b),L=Q(V(H(A,z),H(F,Y)));return y>0?L:-L}function _e(t,n){return t[0]===n[0]&&t[1]===n[1]}function Ne(t,n){const{ccw:e,tangentI:r,tangentO:o,dotTangents:i}=function(t,n){const e=t.length;let r=t[e-2],o=n[0],i=n[1];_e(r,o)&&(r=t[e-3]),_e(o,i)&&(i=n[2]);const c=function(t,n,e){const r=dt(t[0],e[0]),o=dt(n[1],e[1]),i=dt(t[1],e[1]),c=dt(n[0],e[0]);return ht(B(H(r,o),z(H(i,c))))}(r,o,i),s=[dt(o[0],r[0]),dt(o[1],r[1])],u=[dt(i[0],o[0]),dt(i[1],o[1])],f=function(t,n){return ht(B(H(t[0],n[0]),H(t[1],n[1])))}(s,u);return 0!==c||f>0?{ccw:c,tangentI:s,tangentO:u,dotTangents:f}:{ccw:Ie(t.slice().reverse(),n),tangentI:s,tangentO:u,dotTangents:f}}(t,n),c=e<0,s=e>0,u=[ie(r.map(t=>t[1])),ie(o.map(t=>t[1]))],f=ee(u[0],u[1]);let l,a;return i>0?(l=f<-.0698,a=f>.0698):(l=c,a=s),{tangents:u,isSharp:c,isDull:s,isQuiteSharp:l,isQuiteDull:a}}function Se(t){return Ne(1===t.t?t.curve.ps:t.curve.prev.ps,1===t.t?t.curve.next.ps:t.curve.ps)}function Ee(t){return 0===t.t||1===t.t}const we=Wn(t=>!!Ee(t)&&Se(t).isSharp);function Me(t){const n=t.cp.circle.center,e=t,r=t.nextOnCircle,o=e.cp.pointOnShape,i=r.cp.pointOnShape,c=o.p,s=i.p;let u;if(we(o)){let t,n;0===o.t?(t=o.curve,n=o.curve.prev):1===o.t&&(t=o.curve.next,n=o.curve);const e=ie(se(t.ps,0)),r=[-(f=ie(se(n.ps,1)))[0],-f[1]],i=te(e,r),c=Math.sqrt((1+i)/2);u=ce(Math.sqrt((1-i)/2),c,r)}else u=c[0]===s[0]&&c[1]===s[1]?Kn(c,n):ne(Kn(c,s));var f;return[n,oe(ie(u),n)]}const Oe=1e-4;function Te(t,n){const e=t.cp.circle.center,r=Me(t),o=n.cp.circle.center,i=Me(n.prevOnCircle),c=Jn(r,i),s=Kn(e,o);let u;if(c){const t=Kn(e,c),n=Kn(o,c);u=te(t,s)<0||te(n,s)>0}else u=!0;if(!u)return[e,c,o];const f=ne(s),l=Kn(r[0],r[1]),a=Kn(i[0],i[1]),p=Math.abs(ee(s,l))/9,h=Math.abs(ee(s,a))/9;if(p>.01||h>.01)return[e,o];if(p>Oe||h>Oe){const t=re(e,o,1/3),n=re(e,o,2/3),c=oe(f,t),s=[n,oe(f,n)];return[e,Jn(r,[t,c]),Jn(i,s),o]}return[e,o]}function Ce(t){return Te(t,t.next)}const ye=Wn(Ce);function Pe(t,n=!1){const e=t;let r=e;const o=[];do{n&&r===e||o.push(r),r=r.nextOnCircle}while(r!==e);return o}function Ae(t){return t===t.next.prevOnCircle}function Be(t){return Pe(t).filter(t=>!Ae(t)).length}const{min:ze,abs:Fe}=Math;function Ye(t){if(2!==Be(t))return 0;const{radius:n}=t.cp.circle,e=Ce(t),r=function(t,n=[0,1]){if(t.length<=3)return Fn(Vn(t,n));if(4===t.length){const[e,r]=n;if(e===r)return 0;const o=y(t,e,r).ps,i=[0,...zn(o),1];let c=0;for(let t=0;t!Ae(t)).map(t=>t.next);for(const t of e){const e=[t];for(;e.length;){const t=e.pop();n(t),e.push(...Ge(t))}}}const Ue=["prev","next","prevOnCircle","nextOnCircle"];function je(t){const n=new Map,e=Ze(t);n.set(t,e);const r=[{cpNode:t,newCpNode:e}];for(;r.length;){const{cpNode:t,newCpNode:e}=r.pop();for(const o of Ue){const i=t[o];let c=n.get(i);c||(c=Ze(i),n.set(i,c),r.push({cpNode:i,newCpNode:c})),e[o]=c}}return e}function Ze(t){return{...t,prev:void 0,next:void 0,prevOnCircle:void 0,nextOnCircle:void 0}}function We(t){const n=t,e=t.next,r=n.cp.pointOnShape,o=e.cp.pointOnShape,i=r.curve,c=o.curve;if(i.loop!==c.loop)return[];const s=[];return c===i?s.push(Gn(r.curve.ps,r.t,o.t)):(s.push(Gn(r.curve.ps,r.t,1)),function(t,n,e,r){let o=n;do{o=o.next;const n=o===e?r:1;t.push(Gn(o.ps,0,n))}while(o!==e)}(s,r.curve,o.curve,o.t)),s}function Je(t,n){const e=t.prev,r=t.next;e.next=r,r.prev=e,n.get(t.cp.pointOnShape.curve.loop).remove(t,!1)}function Ke(t,n){const e=qe(t);if(2!==e)throw new Error(`Cannot delete \`CpNode\` on ${e}-prong`);Pe(t).forEach(t=>Je(t,n))}function tr(t,n){return Pe(t).indexOf(n)>=0}function nr(t){if(function(t){return Pe(t).every(Ae)}(t))return[];for(;Ae(t);)t=t.nextOnCircle;for(t=t.next;2===Be(t);)t=t.next;t=t.prevOnCircle;const n=[];do{n.push(t),t=t.next}while(!ke(t)&&2===Be(t));return n}function er(t,n,e=!0){const r=function(t,n,e=!0){if(!e&&t===n)return{cpNodes:[],hasHoleCloser:!1};const r=t,o=[r];let i=t.next,c=r.isHoleClosing;for(;i!==n&&i!==r;)i.isHoleClosing&&(c=!0),o.push(i),i=i.next;return{cpNodes:o,hasHoleCloser:c}}(t,n,e);return{pss:(o=r.cpNodes,o.flatMap(We)),hasHoleCloser:r.hasHoleCloser};var o}const rr={getChildren:function(t){const n=[],e=t.next;let r=e;do{n.push(r),r=r.nextOnCircle}while(r.nextOnCircle!==e);return n},getVertexForwardChildren:Ge,getAllOnLoop:v,getAllOnCircle:Pe,isOnSameCircle:tr,isTerminating:Ae,isFullyTerminating:ke,getFirstExit:function(t){const n=t;let e=n;for(;e.next===e.prevOnCircle;)if(e=e.next,e===n)return;return e},isSharp:He,isOneProng:function(t){const n=t;if(0===n.cp.circle.radius)return!0;const e=n.nextOnCircle,r=n.cp.pointOnShape.p,o=e.cp.pointOnShape.p;return r[0]===o[0]&&r[1]===o[1]},getProngCount:qe,getRealProngCount:Be,cpNodeComparator:(t,n)=>d(t.cp,n.cp),enhanceCpNode:function(t){const n=t.cp.pointOnShape.curve;return{...t,pos:t.cp.pointOnShape,p:t.cp.pointOnShape.p,t:t.cp.pointOnShape.t,isTerminating:Ae(t),isFullyTerminating:ke(t),isSharp:He(t),prongCount:qe(t),getRealProngCount:Be(t),ordering:Xe(t),curve:n,loop:n.loop}},traverseCp:De,traverseEdges:Qe,traverseVertices:Re,clone:je,getBoundaryBezierPartsToNext:function(t){const n=t,e=t.next,r=n.cp.pointOnShape,o=e.cp.pointOnShape,i=r.curve,c=o.curve;if(i.loop!==c.loop)return;const s=[];return c===i?s.push({ps:r.curve.ps,ts:[r.t,o.t]}):(s.push({ps:r.curve.ps,ts:[r.t,1]}),function(t,n,e,r){let o=n;do{o=o.next;const n=o===e?{ps:o.ps,ts:[0,r]}:{ps:o.ps,ts:[0,1]};t.push(n)}while(o!==e)}(s,r.curve,o.curve,o.t)),s},getBoundaryBeziersToNext:We,removeVertex:Ke,getMatCurveToNext:Ce,isTwoProng:function(t){return 2===Be(t)},getBranch:nr,getBranchBeziers:function(t){return nr(t).map(t=>Ce(t))},getSalience:function(t){const n=t,e=t.nextOnCircle,r=Ln(n.cp.pointOnShape.p,e.cp.pointOnShape.p),{pss:o,hasHoleCloser:i}=er(n,e),c=function(t){let n=0;for(let e of t)n+=e;return n}(o.map(t=>Zn(t)));return i?Number.POSITIVE_INFINITY:c/r},getMatCurveBetween:Te,getEdgeDirection:Me,getBoundaryBeziersBetween:er,getMatCurvesBetween:function(t,n){let e=t;const r=[];for(;e!==n;){const t=Te(e,e.next);r.push(t),e=e.next}return r},getHoleClosers:function(t){return v(t).filter(t=>t.isHoleClosing)},getSpeed:Ye,getSmoothedSpeed$:$e,getInitialDegAngleBetweenMatCurves:function(t,n){const e=ee(ie(se(Ce(t),0)),ie(se(Ce(n),0)));return Math.abs(Math.asin(e)*(180/Math.PI))},getAllVertices:function(t){const n=[];return Re(t,t=>{n.push(t)}),n}};function or(t){return n=>Pe(n).some(t)}const ir=or(function(t){return 2!==Be(t)&&!t.isHoleClosing}),cr=2**27+1;function sr(t,n){const e=t[1],r=n[1],o=e*r,i=cr*e,c=i-(i-e),s=e-c,u=cr*r,f=u-(u-r),l=r-f,a=s*l-(o-c*f-s*f-c*l)+(e*n[0]+t[0]*r),p=o+a;return[a-(p-o),p]}function ur(t,n){const e=t[0],r=t[1],o=r+n,i=o-r,c=e+(r-(o-i)+(n-i)),s=o+c;return[c-(s-o),s]}const fr=sr,lr=x,ar=b,pr=P,hr=ur;function dr(t,n){if(0===n[0]&&0===n[1])return t[0].map(t=>[0,t]);if(0===n[0]&&1===n[1])return t[t.length-1].map(t=>[0,t]);if(4===t.length){const[[e,r],[o,i],[c,s],[u,f]]=t,l=hr(fr(pr(o,e),n),e),a=hr(fr(pr(c,o),n),o),p=hr(fr(pr(u,c),n),c),h=lr(l,fr(ar(a,l),n)),d=lr(a,fr(ar(p,a),n)),v=lr(h,fr(ar(d,h),n)),g=hr(fr(pr(i,r),n),r),m=hr(fr(pr(s,i),n),i),x=hr(fr(pr(f,s),n),s),b=lr(g,fr(ar(m,g),n)),I=lr(m,fr(ar(x,m),n));return[v,lr(b,fr(ar(I,b),n))]}if(3===t.length){const[[e,r],[o,i],[c,s]]=t,u=lr([0,e],fr(pr(o,e),n)),f=lr([0,o],fr(pr(c,o),n)),l=lr(u,fr(ar(f,u),n)),a=lr([0,r],fr(pr(i,r),n)),p=lr([0,i],fr(pr(s,i),n));return[l,lr(a,fr(ar(p,a),n))]}if(2===t.length){const[[e,r],[o,i]]=t;return[hr(fr(pr(o,e),n),e),hr(fr(pr(i,r),n),r)]}if(1===t.length){const[n,e]=t[0];return[[0,n],[0,e]]}throw new Error("The given bezier curve must be of order <= 3.")}function vr(t,n,e){return{curve:t,t:n,p:dr(t.ps,[0,n]).map(t=>t[1]),isSource:void 0!==e&&e}}const gr=Number.EPSILON/2,mr=gr*gr,xr=134217729;function br(t,n){const e=n[0],r=n[1],o=r*t,i=xr*r,c=i-(i-r),s=r-c,u=xr*t,f=u-(u-t),l=t-f,a=e*t,p=o+a,h=a-(p-o)+(s*l-(o-c*f-s*f-c*l)),d=p+h;return[h-(d-p),d]}function Ir(t,n){const e=n[0],r=n[1],o=r*t,i=xr*r,c=i-(i-r),s=r-c,u=xr*t,f=u-(u-t),l=t-f,a=s*l-(o-c*f-s*f-c*l)+e*t,p=o+a;return[a-(p-o),p]}const _r=Ir,Nr=ht,Sr=function(){const t=3*mr;return t/(1-t)}(),Er=k,wr=J,Mr=it,Or=Math.abs,Tr=Number.EPSILON/2;function Cr(t,n){let e=t[0],r=.5*Or(e);for(let o=1;ot),r=r||new Array(t.length).fill(0);let c,s,u=0;for(;t.length>0&&fo(t[0][1])<=r[0]&&(s=s||o(),0===co(s[0]));)(t=t.slice()).shift(),(r=r.slice()).shift(),s.shift();if(0===t.length)return i?void 0:[];if(1===t.length)return[];if(n===Number.NEGATIVE_INFINITY||e===Number.POSITIVE_INFINITY){const r=t.map(t=>t[1]);n===Number.NEGATIVE_INFINITY&&(n=no(r)),e===Number.POSITIVE_INFINITY&&(e=eo(r))}const f=Jr(t);let l,a;const p=t.length-1;let h,d;l=0,a=!1;do{if(h=a?oo(Wr(I(),n)):Zr(f,n,r),0===h){if(l++,l>=3&&!a){a=!0;continue}n-=2*Number.EPSILON*so(1,fo(n))}}while(0===h);l=0,a=!1;do{if(d=a?oo(Wr(I(),e)):Zr(f,e,r),0===d){if(l++,l>=3&&!a){a=!0;continue}e+=2*Number.EPSILON*so(1,fo(e))}}while(0===d);const v=[{p:t,pE:r}],g=[Jr(t)];for(let t=1;t<=p;t++){const n=jr(v[t-1]);v.push(n),g.push(Jr(n.p))}let m,x,b=[];for(u=p-1;u>=0;u--)m=v[u].pE,x=g[u],b=_();function I(){if(void 0!==c)return c[u];let t=s||o();for(c=[t];t.length>1;)t=ro(t),c.push(t);return c[u]}return b;function _(){const t=[],r=Kr(x,m,n,I);if(!b.length){const t=Kr(x,m,e,I);if(r*t>=0)return[];const[o,i]=to(x,m,n,e,r,t,I);return[{tS:o,tE:i,multiplicity:1}]}let o=b[0].tS,i=Kr(x,m,o,I);if(r*i>0);else if(r*i<0){const[e,c]=to(x,m,n,o,r,i,I);t.push({tS:e,tE:c,multiplicity:1})}let c,s=n,f=r,l=o,a=i;for(let n=0;n0)if(f*a>0)s!==o&&c.multiplicity%2==1&&h();else if(f*a<0){s!==o&&c.multiplicity%2==1&&h();const[n,e]=to(x,m,s,l,f,a,I);t.push({tS:n,tE:e,multiplicity:1})}else s!==o&&c.multiplicity%2==1&&h();else if(i*f<0){if(t.push({tS:c.tS,tE:c.tE,multiplicity:3}),f*a<0){const[n,e]=to(x,m,s,l,f,a,I);t.push({tS:n,tE:e,multiplicity:1})}}else if(0===f)0===i?t.push({tS:c.tS,tE:c.tE,multiplicity:c.multiplicity+1}):i*a>0?t.push({tS:c.tS,tE:c.tE,multiplicity:2}):t.push({tS:c.tS,tE:c.tE,multiplicity:3});else{if(f*a<0){const[n,e]=to(x,m,s,l,f,a,I);t.push({tS:n,tE:e,multiplicity:1})}u*f>0?t.push({tS:c.tS,tE:c.tE,multiplicity:2}):t.push({tS:c.tS,tE:c.tE,multiplicity:3})}}for(let n=0;n=r.tS)return po(t)}return t;function h(){const n=(s-o)*lo;let e=1,r=0;for(let t=u+2;t<=p;t++){const i=g[t][0],c=io(i,o);r+=(fo(c[0])+c[1])*e,e*=n*lo}const l=f>0?uo(i,f):so(i,f),a=2*Number.EPSILON*so(1,fo(s)),h=r*(2*a);(l+(f>0?2*-h*a:2*h*a))*f<0&&t.push({tS:c.tS,tE:c.tE,multiplicity:2})}}}function po(t){const n=[],e=t[0];let r={tS:e.tS,tE:e.tE,multiplicity:e.multiplicity};for(let e=0;e8*_o*t);else if(3===t.length)i=mo(t,[0,n]).map(t=>5*_o*t);else if(2===t.length)i=mo(t,[0,n]).map(t=>2*_o*t);else if(1===t.length)return[o,o];return[[o[0]-i[0],o[1]-i[1]],[o[0]+i[0],o[1]+i[1]]]}(t,n[0])}function So(t){const n=t[0],e=t[1];return[(n[0]+e[0])/2,(n[1]+e[1])/2]}const E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(5,Vo(w,Fo(E)))))),Vo(U,Fo(Vo(Fo(j),Bo(5,Vo(F,Fo(z)))))))),Fo(Ao(Vo(G,Bo(5,Vo(w,Bo(3,E)))),Vo(j,Bo(5,Vo(F,Bo(3,z)))))),Ao(Vo(w,Bo(6,E)),Vo(F,Bo(6,z)))]}const ko=P,$o=x,Xo=Ir,qo=sr,Ho=Co,Do=b,Qo=yo;function Go(t,n){const[[e,r],[o,i],[c,s]]=t,[u,f]=n,l=ko(e,u),a=ko(o,u),p=ko(c,u),h=ko(r,f),d=ko(i,f),v=ko(s,f),g=qo(l,l),m=qo(l,a),x=qo(l,p),b=qo(a,a),I=qo(a,p),_=qo(p,p),N=qo(h,h),S=qo(h,d),E=qo(h,v),w=qo(d,d),M=qo(d,v),O=qo(v,v),T=$o(E,Ho(w)),C=$o(x,Ho(b));return[$o(Do($o($o(O,N),Ho(T)),Qo($o(M,S))),Do($o($o(_,g),Ho(C)),Qo($o(I,m)))),Xo(3,$o($o(Do(M,T),Do(Xo(3,S),N)),$o(Do(I,C),Do(Xo(3,m),g)))),$o(Do(T,Xo(3,Do(Ho(S),N))),Do(C,Xo(3,Do(Ho(m),g)))),$o(Do(S,N),Do(m,g))]}const Ro=m,Uo=x,jo=function(t){return[-2*t[0],-2*t[1]]},Zo=b;function Wo(t,n){const[[e,r],[o,i]]=t,[c,s]=n,u=e-c,f=o-c,l=r-s,a=i-s,p=Ro(u,u),h=Ro(u,f),d=Ro(f,f),v=Ro(l,l),g=Ro(l,a),m=Ro(a,a),x=Uo(h,g),b=Uo(v,p);return[Uo(Uo(d,m),Uo(b,jo(x))),Zo(x,b)]}function Jo(t){const n=[];for(let e=0;e10*Si*t),getPolyExact:()=>function(t,n){const e=t[0],r=t[1],o=t[2],i=t[3],c=e[0],s=e[1],u=r[0],f=r[1],l=o[0],a=o[1],p=i[0],h=i[1],[d,v]=n,g=ti(c,d),m=ti(u,d),x=ti(l,d),b=ti(p,d),I=ti(s,v),_=ti(f,v),N=ti(a,v),S=ti(h,v),E=ni(g,g),w=ei(6,ni(g,m)),M=ei(6,ni(g,x)),O=ri(ni(g,b)),T=ei(9,ni(m,m)),C=ei(18,ni(m,x)),y=ei(6,ni(m,b)),P=ei(9,ni(x,x)),A=ei(6,ni(x,b)),B=ni(b,b),z=ni(I,I),F=ei(6,ni(I,_)),Y=ei(6,ni(I,N)),V=ri(ni(I,S)),L=ei(9,ni(_,_)),k=ei(18,ni(_,N)),$=ei(6,ni(_,S)),X=ei(9,ni(N,N)),q=ei(6,ni(N,S)),H=ni(S,S),D=ii(y,P),Q=ii(O,C),G=ii(M,T),R=ii($,X),U=ii(V,k),j=ii(Y,L),Z=ci(ii(ii(B,E),ii(D,G)),ii(ii(Q,A),w)),W=ci(ii(ii(H,z),ii(R,j)),ii(ii(U,q),F)),J=ei(6,ii(Z,W)),K=ii(oi(ii(ii(D,ri(G)),ei(3,E))),ii(ii(A,ei(3,Q)),ei(5,w))),tt=ii(oi(ii(ii(R,ri(j)),ei(3,z))),ii(ii(q,ei(3,U)),ei(5,F))),nt=ei(5,ii(K,tt)),et=ii(ii(D,ei(3,ci(ri(G),Q))),ei(5,ci(ei(3,E),ri(w)))),rt=ii(ii(R,ei(3,ci(ri(j),U))),ei(5,ci(ei(3,z),ri(F)))),ot=ei(4,ii(et,rt)),it=ci(Q,ri(ci(ri(G),ei(5,ci(w,ri(E)))))),ct=ci(U,ri(ci(ri(j),ei(5,ci(F,ri(z)))))),st=ei(3,ii(it,ct)),ut=ci(G,ei(5,ci(w,ei(3,E)))),ft=ci(j,ei(5,ci(F,ei(3,z)))),lt=ri(ii(ut,ft)),at=ci(w,ei(6,E)),pt=ci(F,ei(6,z));return[J,nt,ot,st,lt,ii(at,pt)]}(t,n)};if(2===e)return{polyDd:Go(t,n),polyE:_i(t,n).map(t=>8*Si*t),getPolyExact:()=>function(t,n){const[[e,r],[o,i],[c,s]]=t,[u,f]=n,l=si(e,u),a=si(o,u),p=si(c,u),h=si(r,f),d=si(i,f),v=si(s,f),g=ui(l,l),m=ui(l,a),x=ui(l,p),b=ui(a,a),I=ui(a,p),_=ui(p,p),N=ui(h,h),S=ui(h,d),E=ui(h,v),w=ui(d,d),M=ui(d,v),O=ui(v,v),T=ai(E,li(w)),C=ai(x,li(b)),y=ai(pi(ai(_,li(C)),hi(ai(I,m))),g),P=ai(pi(ai(O,li(T)),hi(ai(M,S))),N),A=ai(y,P),B=ai(pi(I,C),pi(fi(3,m),g)),z=ai(pi(M,T),pi(fi(3,S),N)),F=fi(3,ai(B,z)),Y=pi(T,fi(3,pi(li(S),N))),V=pi(C,fi(3,pi(li(m),g))),L=ai(Y,V),k=pi(S,N),$=pi(m,g);return[A,F,L,ai(k,$)]}(t,n)};if(1===e)return{polyDd:Wo(t,n),polyE:Ni(t,n).map(t=>6*Si*t),getPolyExact:()=>function(t,n){const[[e,r],[o,i]]=t,[c,s]=n,u=di(e,c),f=di(o,c),l=di(r,s),a=di(i,s),p=vi(u,u),h=vi(u,f),d=vi(f,f),v=vi(l,l),g=vi(l,a),m=vi(a,a),x=mi(h,g),b=mi(v,p);return[mi(mi(d,m),mi(gi(x),b)),xi(x,b)]}(t,n)};if(0===e)return{polyDd:[[0,1]],polyE:[0],getPolyExact:()=>[[1]]};throw new Error("The given bezier curve must be of order <= 3")}const{sqrt:wi}=Math;function Mi(t,n,e=0,r=1){const{polyDd:o,polyE:i,getPolyExact:c}=Ei(t,n),s=ao(o,e,r,i,c);s.push({tS:e,tE:e,multiplicity:1}),s.push({tS:r,tE:r,multiplicity:1});const u=s.map(e=>{const r=No(t,[e.tS,e.tE]),o=function(t,n){const e=t[0],r=t[1],o=e[0],i=e[1],c=r[0],s=r[1],u=n[0],f=n[1];let l=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(const[t,n]of[[o,i],[o,s],[c,i],[c,s]]){const e=wo(t,u),r=wo(n,f),o=Oo(Mo(e,e),Mo(r,r)),i=Eo(o),c=i*(1-To),s=i*(1+To);c<=l&&(l=c),s>=a&&(a=s)}return[l,a]}(r,n);return{p:So(r),t:ho(e),d:(wi(o[0])+wi(o[1]))/2,dSquaredI:o,box:r,ri:e}});let f=Number.POSITIVE_INFINITY;for(let t=0;tYi*Yi*t[1]),s=Bi(i,0,1,c,()=>o),u=[];for(const t of s)u.push({tS:Fi(e,t.tS*r),tE:Fi(e,t.tE*r),multiplicity:t.multiplicity});return u}const{abs:Li}=Math;function ki(t,n){const e=t.inOuts;e.sort(function(t){return(n,e)=>{let r=n.side-e.side;if(0!==r)return r;const o=n.sideX,i=e.sideX;r=o.ri.tS-i.ri.tS;const c=8*Number.EPSILON;return Li(r)>=c?r:(o.compensated||(o.compensated=1,o.riExp=Vi(o.ri,o.getPExact())[0]),i.compensated||(i.compensated=1,i.riExp=Vi(i.ri,i.getPExact())[0]),r=G(o.riExp.tS,i.riExp.tS),0!==r?r:(r=n.dir-e.dir,0!==r?t*r:1===n.dir?n.idx-e.idx:e.idx-n.idx))}}(n));let r=e[e.length-1];for(let t=0;t{t.has(e)||(e.orientation=r,e.parent=o,e.windingNum=o.windingNum+e.orientation,n.push(e))}}(r,e);ki(t.container,n.orientation);let i,c,s=1,u=t,f=n.orientation;for(;u=1===n.orientation?u.nextAround:u.prevAround,u!==t;){const t=s;s-=u.dir,1===s&&(f*=-1),-1!==u.dir&&(i?1===t&&0===s?o(u,n.orientation,n.parent):0===t&&-1===s&&o(u,-n.orientation,n.parent):0===s?i=u:1===s&&o(u,n.orientation,n))}return Oi(t.container)||(c=[t.p,i.p]),{inOutToUse:i,additionalBezier:c}}function Xi(t,n){const e=t.nextOrPrev;n.add(e);const r=t._x_,o=e._x_,i=r.curve,c=r.x.ri.tS,s=o.curve,u=o.x.ri.tS;let f=i,l=c;Oi(t.container)||(l=ho(Mi(i.ps,t.p)[0].ri));const a=[];for(;;){if(f===s&&(lu||l===u&&0!==a.length)){const n=[l,u];return a.push({ps:t,ts:n}),{bezierPieces:a,inOut:e}}{const n=[l,0];a.push({ps:t,ts:n})}l=1,f=f.prev}}function Hi(t,n,e,r){const o=function(t,n,e){return(r,o,i,c)=>{n.has(r)||1!==r.dir||(r.loopsIdxs=new Set(c),r.orientation=o*t.orientation,r.parent=i.parent,r.windingNum=i.windingNum+r.orientation,e.unshift(r))}}(n,r,e);ki(t.container,1);let i=t.nextAround,c=t;const s=new Set(n.loopsIdxs);for(;c=c.nextAround,c!==t;)o(c,n.dir,n,s),-1===c.dir?s?.add(c._x_?.curve.loop.idx):s.delete(c._x_?.curve.loop.idx);let u;return Oi(t.container)||(u=[t.p,i.p]),{inOutToUse:i,additionalBezier:u}}function Di(t){const{ps:n,ts:e}=t;return Gn(n,e[0],e[1])}function Qi(t,n,e){const r=[],o=[];let i,c=n;do{t.add(c);const s=1===c.dir?Xi(c,t):qi(c,t),{bezierPieces:u,inOut:f}=s;o.push(...u);const l=(e?Hi:$i)(f,n,r,t);if(({inOutToUse:c,additionalBezier:i}=l),void 0!==i){const t=Di(o[o.length-1]),n={ps:t,ts:[0,ho(Mi(t,i[0])[0].ri)]};o.pop(),o.push(n),o.push({ps:i,ts:[0,1]})}}while(c!==n);return{bezierPieces:o,additionalOutsToCheck:r}}function Gi(t,n,e,r){const o=[t];for(;o.length;){const t=o.pop();if(n.add(t._x_.curve.loop),e.has(t))continue;t.children=new Set;const{bezierPieces:i,additionalOutsToCheck:c}=Qi(e,t,r);t.bezierPieces=i,t.parent.children=t.parent.children||new Set,t.parent.children.add(t),o.push(...c)}}function Ri(t){if(4===t.length)return Ui(t);if(3===t.length)return ji(t);if(2===t.length)return function(t){const[[n,e],[r,o]]=t;return[[r-n,n],[o-e,e]]}(t);if(1===t.length)return function(t){const[[n,e]]=t;return[[n],[e]]}(t);throw new Error("The given bezier curve must be of order <= 3.")}function Ui(t){const[[n,e],[r,o],[i,c],[s,u]]=t;return[[s-n+3*(r-i),3*(i+n-2*r),3*(r-n),n],[u-e+3*(o-c),3*(c+e-2*o),3*(o-e),e]]}function ji(t){const[[n,e],[r,o],[i,c]]=t;return[[i+n-2*r,2*(r-n),n],[c+e-2*o,2*(o-e),e]]}function Zi(t,n=Number.NEGATIVE_INFINITY,e=Number.POSITIVE_INFINITY,r){return ao(t.map(t=>[0,t]),n,e,void 0,void 0,r)}function Wi(t){const n=t[0],e=t[t.length-1];let r,o;if(n[1]o.box[0][1]&&(o={ts:i,box:s})}return{minY:r,maxY:o}}function Ji(t){const n=function(t){const n=t[0],e=t[t.length-1];let r,o;if(n[0]o.box[0][0]&&(o={ts:i,box:s})}return{minX:r,maxX:o}}(t),e=Wi(t);return[[n.minX.box[0][0],e.minY.box[0][1]],[n.maxX.box[1][0],e.maxY.box[1][1]]]}const Ki=Wn(Ji);function tc(t){const n=qn(t),e=Bn(n[0],0,1),r=Bn(n[1],0,1);e.push(0,1),r.push(0,1);let o,i,c,s,u=Number.POSITIVE_INFINITY,f=Number.NEGATIVE_INFINITY,l=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(let n=0;nf&&(f=c,i=r)}for(let n=0;na&&(a=o,s=e)}return{ts:[[o,c],[i,s]],box:[[u,l],[f,a]]}}const nc=Wn(tc),{min:ec,max:rc}=Math;function oc(t){const n=t.map(nc);return{minX:ec(...n.map(t=>t.box[0][0])),maxX:rc(...n.map(t=>t.box[1][0])),minY:ec(...n.map(t=>t.box[0][1])),maxY:rc(...n.map(t=>t.box[1][1]))}}const ic=new Function("try {return this===window;}catch(e){ return false;}")()?function(t){const n=window.atob(t),e=n.length,r=new Uint8Array(e);for(let t=0;tr.maxX||e.minYr.maxY}(t,n))return!1;const r=function(t,n){const[e,r]=n;let o=0;for(let i=0;ir||le||!1,a)continue;const p=[];let h,d,v;const g=!0;h=t=>Ri(t)[1],d=[0,-r],v=0;const m=c.map(oe(d)),x=Bn(h(m),0-lc,1+lc);for(let t=0;t=r[v]||!g&&n[v]<=r[v])&&p.push(e)}if(1===p.length||3===p.length)for(const t of p){const n=ie(se(c,t));if(Math.abs(n[1])c&&([o,c]=[c,o]),u>l&&([u,l]=[l,u]),r>i&&([r,i]=[i,r]),s>f&&([s,f]=[f,s]);const a=t||r===i&&s===f,p=t||o===c&&u===l;return(a?r<=f:r=s:i>s)&&(p?u<=c:u=o:l>o)}function gc(t,n){return vc(!0,t.box,n.box)}function mc(t,n){for(let e=0;eo&&(o=u),f>i&&(i=f),c.push(...n.xs)}const s={box:[[t,r],[o,i]],xs:c,inOuts:void 0};n.push(s)}return n}function Sc(t){return{tS:[0,t.tS],tE:[0,t.tE],multiplicity:t.multiplicity}}const Ec=P,wc=Ir,Mc=x,Oc=ur,Tc=Math.abs;function Cc(t){const[[n,e],[r,o],[i,c],[s,u]]=t,f=Ec(s,n),l=Ec(r,i),a=3*(r-i),p=wc(3,l),h=Tc(a),d=Mc(f,p),v=h+Tc(s-n+a),g=Ec(i,2*r),m=Oc(g,n),x=Tc(i-2*r+n),b=wc(3,m),I=6*x,_=Ec(r,n),N=wc(3,_),S=Tc(3*(r-n)),E=Ec(u,e),w=Ec(o,c),M=3*(o-c),O=wc(3,w),T=Tc(M),C=Mc(E,O),y=T+Tc(u-e+M),P=Ec(c,2*o),A=Oc(P,e),B=Tc(c-2*o+e),z=wc(3,A),F=6*B,Y=Ec(o,e);return{coeffs:[[d,b,N,[0,n]],[C,z,wc(3,Y),[0,e]]],errorBound:[[v,I,S,0],[y,F,Tc(3*(o-e)),0]]}}function yc(t){const[[n,e],[r,o],[i,c]]=t,s=i-2*r,u=Ec(i,2*r),f=Oc(u,n),l=Tc(s+n),a=Ec(2*r,2*n),p=c-2*o,h=Ec(c,2*o),d=Oc(h,e),v=Tc(p+e);return{coeffs:[[f,a,[0,n]],[d,Ec(2*o,2*e),[0,e]]],errorBound:[[l,0,0],[v,0,0]]}}function Pc(t){const[[n,e],[r,o]]=t;return[[Ec(r,n),[0,n]],[Ec(o,e),[0,e]]]}const Ac=b,Bc=Ir,zc=z,Fc=Math.abs;function Yc(t){const[[n,[,e]],[r,[,o]]]=Pc(t),i=zc(r),c=n,s=Bc(o,n),u=Fc(s[1]),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,Ys=Z(3),Vs=x,Ls=Ir,ks=sr,$s=Math.abs,Xs=Z(3),qs=m,Hs=Co,Ds=Ir,Qs=sr,Gs=x,Rs=Math.abs,Us=Z(3),js=m,Zs=Co,Ws=Ir,Js=sr,Ks=x,tu=Math.abs,nu=Z(3),eu=$,ru=V,ou=z,iu=Q;function cu(t){const[[n,[e]],[r,[o]]]=t;if(0!==iu(n)||0!==iu(r))return{vₓ:ou(r),vᵧ:n,v:ru(eu(e,r),eu(o,n))}}const su=$,uu=H,fu=B;function lu(t,n){const e=Ft(t),[[r,[o]],[i,[c]]]=Ft(n),{vₓ:s,vᵧ:u,v:f}=cu(e),l=uu(r,s),a=uu(i,u),p=fu(l,a),h=su(o,s),d=su(c,u),v=fu(h,d);return[p,fu(v,f)]}const au=$,pu=Jo,hu=V,du=H,vu=z;function gu(t){const[[n,e,[r]],[o,i,[c]]]=t;if(0===Q(n)&&0===Q(o))return cu([[e,[r]],[i,[c]]]);const s=du(n,i),u=du(e,o),f=au(c,n),l=au(r,o),a=au(c,e),p=au(r,i),h=du(n,n),d=du(n,o),v=du(o,o),g=hu(s,u),m=hu(f,l),x=hu(a,p),b=vu(v),I=pu(d),_=vu(h),N=du(i,g),S=pu(du(o,m)),E=hu(N,S),w=pu(du(n,m)),M=du(e,g),O=hu(w,M),T=du(g,x),C=du(m,m);return{vₓₓ:b,vₓᵧ:I,vᵧᵧ:_,vₓ:E,vᵧ:O,v:hu(T,C)}}const mu=it,xu=$,bu=H,Iu=B,_u=Jo,Nu=Q;function Su(t,n){const e=zt(t);if(0===Nu(e[0][0])&&0===Nu(e[1][0]))return lu([t[0],t[2]],n);const[[r,[o]],[i,[c]]]=Ft(n),{vₓₓ:s,vₓᵧ:u,vᵧᵧ:f,vₓ:l,vᵧ:a,v:p}=gu(e),h=mu(o,o),d=xu(o,r),v=mu(o,c),g=xu(o,i),m=bu(r,r),x=xu(c,r),b=bu(r,i),I=mu(c,c),_=xu(c,i),N=bu(i,i),S=bu(m,s),E=bu(N,f),w=bu(b,u),M=Iu(S,E),O=Iu(M,w),T=bu(d,s),C=bu(_,f),y=Iu(g,x),P=bu(y,u),A=_u(Iu(T,C)),B=Iu(A,P),z=bu(r,l),F=bu(i,a),Y=Iu(z,F),V=Iu(B,Y),L=bu(h,s),k=bu(v,u),$=bu(I,f),X=Iu(L,k),q=Iu(X,$),H=xu(o,l),D=xu(c,a),Q=Iu(H,D),G=Iu(q,Q);return[O,V,Iu(G,p)]}const Eu=H,wu=dt,Mu=V,Ou=Q,Tu=ht,Cu=k,yu=J;function Pu(t,n=!1){const[e,r,o,i]=t;if(!n){const[t,n]=e,[c,s]=r,[u,f]=o,[l,a]=i;return[e,[Tu(Mu(Cu(yu(c/4,u/4),3),yu(t/4,l/4))),Tu(Mu(Cu(yu(s/4,f/4),3),yu(n/4,a/4)))],i]}const c=function(t,n){const[[e,r],[o,i]]=t,[[c,s],[u,f]]=n,l=wu(o,e),a=wu(i,r),p=wu(u,c),h=wu(f,s),d=Mu(Eu(p,a),Eu(h,l));if(0===Ou(d))return;const v=wu(c,e),g=wu(s,r),m=Mu(Eu(g,l),Eu(v,a)),x=Tu(m)/Tu(d);return[c+x*Tu(p),s+x*Tu(h)]}([e,r],[i,o]);if(void 0!==c)return[e,c,i]}const Au=$,Bu=H,zu=B,Fu=V,Yu=z,Vu=Jo,Lu=Q;function ku(t){const[[n,e,r,[o]],[i,c,s,[u]]]=t;if(0===Lu(n)&&0===Lu(i))return gu([[e,r,[o]],[c,s,[u]]]);const f=Bu(n,s),l=Bu(r,i),a=Bu(n,c),p=Bu(e,c),h=Bu(e,i),d=Bu(n,n),v=Bu(c,c),g=Bu(i,i),m=Bu(r,n),x=Bu(e,e),b=Bu(s,i),I=Bu(c,i),_=Bu(e,n),N=Bu(n,i),S=Au(u,n),E=Au(o,i),w=Au(u,e),M=Au(o,c),O=Bu(e,s),T=Bu(r,c),C=Au(u,r),y=Au(o,s),P=Fu(S,E),A=Fu(f,l),B=Fu(a,h),z=Fu(w,M),F=Fu(O,T),Y=Fu(C,y),V=Fu(b,v),L=Fu(m,x),k=zu(h,a),$=zu(l,f),X=Vu(A),q=Bu(P,P),H=Bu(P,A),D=Bu(P,B),Q=Bu(P,F),G=Bu(A,A),R=Bu(X,z),U=Bu(B,z),j=Bu(B,F),Z=Bu(B,Y),W=Bu(Yu(i),g),J=Bu(Au(3,n),g),K=Bu(Au(-3,i),d),tt=Bu(n,d),nt=Fu(Au(-3,P),F),et=Bu(nt,g),rt=Bu(B,V),ot=zu(et,rt),it=Bu(X,I),ct=zu(ot,it),st=Bu(nt,d),ut=Bu(B,L),ft=zu(st,ut),lt=Bu(X,_),at=zu(ft,lt),pt=Fu(p,function(t){const n=[];for(let e=0;eAf[t.length-2][n.length-2](t,n)}}const zf=134217729;function Ff(t,n){const e=t[0],r=t[1],o=n[0],i=n[1],c=r/i,s=i*c,u=zf*i,f=u-(u-i),l=i-f,a=zf*c,p=a-(a-c),h=c-p,d=o*c,v=s+d,g=d-(v-s)+(l*h-(s-f*p-l*p-f*h)),m=v+g,x=(r-m+(e-(g-(m-v))))/i,b=c+x;return[x-(b-c),b]}const Yf=Ff,Vf=Number.EPSILON/2,Lf=Vf*Vf,kf=b,$f=b,Xf=b,qf=ur,Hf=sr,Df=Ir,Qf=x,Gf=Co,Rf=Number.EPSILON/2,Uf=Rf*Rf,jf=Math.abs,Zf=Xf,Wf=[0,1],Jf=qf,Kf=Qf,tl=Hf,nl=Df,el=Gf,rl=function(t,n,e,r){const o=t[0],i=t[1],c=n[0],s=n[1],u=Yf(t,n),f=Math.abs(o+i),l=Math.abs(c+s),a=l-Vf*l-r;return a<=0?{est:u,err:Number.POSITIVE_INFINITY}:{est:u,err:(l*e+f*r)/a**2+9*Lf*Math.abs(f/l)}},ol=function(t,n){return kf(t,n)[1]>0?n:t},il=function(t,n){return $f(t,n)[1]>0?t:n},cl=Z(3);function sl(t,n){return n[0][0]!==n[1][0]||n[0][1]!==n[1][1]?4===t.length?function([[t,n],[e,r],[o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t,M)),tl(el(ht),w)),mt=Kf(Kf(nl(s,O),tl(dt,y)),nl(3,Kf(tl(pt,T),tl(ht,C)))),xt=jf(dt[1]),bt=et*P+tt*A,It=et*B+2*tt*z+J*F;Z=et*Y+Z*k+3*(tt*V+J*L),J=It*$+xt*X,tt=bt*q+xt*D+2*It*H,et=et*Q+xt*U+3*(bt*G+It*R),Z*=11*Uf,J*=15*Uf,tt*=20*Uf,et*=22*Uf;const _t=ol(ol(Jf(it,-j),Jf(ct,-W)),ol(Jf(st,-K),Jf(ut,-nt))),Nt=il(il(Jf(it,+j),Jf(ct,+W)),il(Jf(st,+K),Jf(ut,+nt)));return[[_t,ol(ol(Jf(dt,-Z),Jf(vt,-J)),ol(Jf(gt,-tt),Jf(mt,-et)))],[Nt,il(il(Jf(dt,+Z),Jf(vt,+J)),il(Jf(gt,+tt),Jf(mt,+et)))]]}(t,n):3===t.length?function([[t,n],[e,r],[o,i]],[c,s]){const u=Zf(s,c),f=3*Uf*jf(u[1]),l=Zf(Wf,c),a=3*Uf*jf(l[1]),p=rl(u,l,f,a);s=Jf(p.est,p.err);const h=Zf(Wf,c),d=tl(c,c),v=tl(c,h),g=tl(h,h),m=Zf(Wf,s),x=tl(s,s),b=tl(s,m),I=tl(m,m),_=jf(c[1]),N=jf(h[1]),S=jf(d[1]),E=jf(v[1]),w=jf(g[1]),M=jf(s[1]),O=jf(m[1]),T=jf(x[1]),C=jf(b[1]),y=jf(I[1]);let P=jf(t),A=jf(n),B=jf(e),z=jf(r),F=jf(o),Y=jf(i);const V=Kf(Kf(nl(o,d),nl(2*e,v)),nl(t,g)),L=Kf(nl(o,c),nl(e,h)),k=V,$=Kf(tl(s,L),tl(m,V)),X=Kf(Kf(nl(o,x),tl(el(b),L)),tl(I,V)),q=F*S+2*B*E+P*w,H=F*_+B*N;P=q,B=M*H+O*q,F=T*o+2*C*H+y*q,P*=7*Uf,B*=11*Uf,F*=14*Uf;const D=Kf(Kf(nl(i,d),nl(2*r,v)),nl(n,g)),Q=Kf(nl(i,c),nl(r,h)),G=D,R=Kf(tl(s,Q),tl(m,D)),U=Kf(Kf(nl(i,x),tl(el(b),Q)),tl(I,D)),j=Y*S+2*z*E+A*w,Z=Y*_+z*N;A=j,z=M*Z+O*j,Y=T*i+2*C*Z+y*j,A*=7*Uf,z*=11*Uf,Y*=14*Uf;const W=ol(ol(Jf(k,-P),Jf($,-B)),Jf(X,-F)),J=il(il(Jf(k,+P),Jf($,+B)),Jf(X,+F));return[[W,ol(ol(Jf(G,-A),Jf(R,-z)),Jf(U,-Y))],[J,il(il(Jf(G,+A),Jf(R,+z)),Jf(U,+Y))]]}(t,n):function([[t,n],[e,r]],[o,i]){const c=Zf(i,o),s=3*Uf*jf(c[1]),u=Zf(Wf,o),f=3*Uf*jf(u[1]),l=rl(c,u,s,f);i=Jf(l.est,l.err);const a=Zf(Wf,o),p=Zf(Wf,i),h=jf(o[1]),d=jf(a[1]),v=jf(i[1]),g=jf(p[1]);let m=jf(t),x=jf(n),b=jf(e),I=jf(r);const _=Kf(nl(e,o),nl(t,a)),N=Kf(nl(e,i),tl(_,p));m=b*h+m*d,b=b*v+m*g,m*=3*Rf,b*=7*Rf;const S=Kf(nl(r,o),nl(n,a)),E=Kf(nl(r,i),tl(S,p));x=I*h+x*d,I=I*v+x*g,x*=3*Rf,I*=7*Rf;const w=ol(Jf(_,-m),Jf(N,-b)),M=il(Jf(_,+m),Jf(N,+b));return[[w,ol(Jf(S,-x),Jf(E,-I))],[M,il(Jf(S,+x),Jf(E,+I))]]}(t,n):function(t,n){const e=t[0],r=t[t.length-1];if(0===n[0]&&0===n[1]){const t=[0,e[0]],n=[0,e[1]];return[[t,n],[t,n]]}if(0===n[0]&&1===n[1]){const t=[0,r[0]],n=[0,r[1]];return[[t,n],[t,n]]}const o=dr(t,n);let i;if(4===t.length)i=mo(t,n).map(t=>16*cl*t);else if(3===t.length)i=mo(t,n).map(t=>10*cl*t);else if(2===t.length)i=mo(t,n).map(t=>4*cl*t);else if(1===t.length)return[o,o];return[[Jf(o[0],-i[0]),Jf(o[1],-i[1])],[Jf(o[0],+i[0]),Jf(o[1],+i[1])]]}(t,n[0])}function ul(t){return(n,e)=>{let[[r,o],[i,c]]=n,[[s,u],[f,l]]=e;return(o[1]>c[1]||o[1]===c[1]&&o[0]>c[0])&&([o,c]=[c,o]),(u[1]>l[1]||u[1]===l[1]&&u[0]>l[0])&&([u,l]=[l,u]),(r[1]>i[1]||r[1]===i[1]&&r[0]>i[0])&&([r,i]=[i,r]),(s[1]>f[1]||s[1]===f[1]&&s[0]>f[0])&&([s,f]=[f,s]),t?(r[1]s[1]||i[1]===s[1]&&i[0]>=s[0])&&(u[1]o[1]||l[1]===o[1]&&l[0]>=o[0]):(r[1]s[1]||i[1]===s[1]&&i[0]>s[0])&&(u[1]o[1]||l[1]===o[1]&&l[0]>o[0])}}function fl(t){return[((n=t.x.box)[0][0]+n[1][0])/2,(n[0][1]+n[1][1])/2];var n}function ll(t,n){const e=Bf(t,n);if(void 0===e)return;const{coeffs:r,errBound:o,getPExact:i}=e,c=ao(r,0,1,o,i);return 0!==c.length?{ris:c.map(Sc),getPExact:i}:void 0}function al(t){return{tS:ht(t.tS),tE:ht(t.tE),multiplicity:t.multiplicity}}function pl(t,n){const e=ll(t,n);if(void 0===e)return[];const{getPExact:r}=e;let o,{ris:i}=e;const c=()=>(o=o||r(),o),s=ll(n,t);if(void 0===s)return[];let{ris:u}=s;const{getPExact:f}=s;let l;const a=()=>(l=l||f(),l);let p;p=1;let h,d=0;t:for(;dsl(t,[n.tS,n.tE]));for(let t=0;tsl(n,[t.tS,t.tE]));for(let t=0;tt.map(ht))}function dl(t,n){return function(t,n){const e=t.xs,r=[],o=new Map;for(const t of e){const n=t.curve,e=o.get(n);e?e.push(t):o.set(n,[t])}const i=function(t){const[[n,e],[r,o]]=t.box,i=[[[r,e],[n,e]],[[n,e],[n,o]],[[n,o],[r,o]],[[r,o],[r,e]]];return(n,e,r)=>{const o=n.ps,c=e.slice();for(let t=0;tt.x.ri.tS-n.x.ri.tS);const s=[],u=[];let f,l;for(const n of c)void 0!==n.side?(!0===l&&(u.push({idx:++r,dir:1,p:fl(n),_x_:f,container:t,side:n.side,sideX:n.sideX,loopsIdxs:new Set}),f.out=u[u.length-1]),l=!1):(!1===l&&(s.push({idx:++r,dir:-1,p:fl(f),_x_:n,container:t,side:f.side,sideX:f.sideX,loopsIdxs:new Set}),n.in_=s[s.length-1]),l=!0),f=n;return{ins:s,outs:u,ioIdx:r}}}(t);for(const t of o){const[e,o]=t;let c,s;({ins:c,outs:s,ioIdx:n}=i(e,o,n)),r.push(...c),r.push(...s)}return{inOuts:r,ioIdx:n}}(t,n)}function vl(t,n,e,r){const o=[];for(const r of t)o.push({type:-1,item:r,x:n(r)}),o.push({type:1,item:r,x:e(r)});o.sort(gl);const i=new Set,c=[];for(const t of o){const n=t.item;if(-1===t.type){for(const t of i.values()){const e=r(n,t);e&&c.push({a:n,b:t,u:e})}i.add(n)}else 1===t.type&&i.delete(t.item)}return c}function gl(t,n){const e=t.x-n.x;return 0!==e?e:t.type}function ml(t,n){const e=n[0]-t[0],r=n[1]-t[1];return e*e+r*r}function xl(t,n,e){const r=n[0]-t[0],o=n[1]-t[1];return r*(e[0]-n[0])+o*(e[1]-n[1])}const bl=function(t,n){if(0===t.length)return;const e=t.slice(),r=function(t){let n,e=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY];for(let r=0;r{let e=-gt(o,t,n);return 0!==e?e:(e=t[1]-n[1],0!==e?e:t[0]-n[0])}),e.unshift(o);const i=function(t){const n=[t[0]],e=t.length;for(let r=1;r=2&>(c[c.length-2],c[c.length-1],t)<0;)c.pop();c.push(t)}if(n||c.length<3)return c;const s=[];{const t=c.length;for(let n=0;no&&([e,o]=[o,e]),c>u&&([c,u]=[u,c]),r>i&&([r,i]=[i,r]),s>f&&([s,f]=[f,s]),e<=u&&o>=c&&s<=i&&f>=r)return[[ea(e,c),ea(r,s)],[na(o,u),na(i,f)]]}function oa(t,n,e){if(void 0===e)return;if(0===e.length)return[];const r=ta(n,t);if(void 0===r)return;if(0===r.length)return[];const o=r.map(n=>No(t,[n.tS,n.tE])),i=e.map(t=>No(n,[t.tS,t.tE])),c=[];for(let t=0;tl&&(l=e)}let a=Number.POSITIVE_INFINITY,p=Number.NEGATIVE_INFINITY;for(let t=0;tp&&(p=e)}if(e&&(l1?t:1+sa}function la(t){const n=function(t){const n=new ArrayBuffer(8);return new DataView(n).setFloat64(0,t,!1),Array.from(new Uint8Array(n))}(t),e=n[0],r=n[1],o=e>>7,i=((127&e)<<4)+((240&r)>>4),c=0===i?0:16,s=0===i?i-1022:i-1023,u=n.slice(1);return u[0]=(15&r)+c,{sign:o,exponent:s,significand:u}}function aa(t){return la(t).significand}function pa(t){return Math.log2(t&-t)}function ha(t){if(0===t||!Number.isFinite(t))return NaN;const n=aa(t),e=n.length;for(let t=e-1;t>=0;t--){if(0===n[t])continue;const r=pa(n[t]);if(Number.isFinite(r))return 8*(e-t-1)+r}return NaN}function da(t){return t>=128?7:t>=64?6:t>=32?5:t>=16?4:t>=8?3:t>=4?2:t>=2?1:t>=1?0:NaN}function va(t){if(0===t||!Number.isFinite(t))return NaN;const n=aa(t),e=n.length;for(let t=0;t0;){const i=ma(t[o-1]);if(e-i>n)break;r=i,o--}const i=Math.min(n-(e-r),53);let c=t[o];c=xa(c,i);const s=t.slice(o);return s[0]=c,s},Ea=function(t){const n=vt(t);if(0===Q(n))return 0;const e=n[n.length-1],r=n[0];return ga(e)-ga(r)+(53-ha(r))},wa=V,Ma=ht;function Oa(t){return ht(function(t,n,e){let r=n,o=t,i=!1,c=0;e||(c=Ea(o)-Ea(r)+1,e=c/53+1,i=!0);let s=[1/Ma(r)],u=1;for(;;){if(o=Na(o,s),u>e)return i?(o=Sa(o,c),o):o.slice(o.length-e,o.length);r=Na(r,s),s=wa([2],r),u*=2}}(t[0],t[1],2))}function Ta(t){return Q(t[0])*Q(t[1])}function Ca(t){return(n,e)=>{const r=At(n),o=At(e),i=At(n.slice().reverse()),c=At(e.slice().reverse()),s=t(r,o),u=t(i,o),f=t(r,c),l=t(i,c),a=-Ta(u),p=-Ta(l),h=Oa(s),d=Oa(f);return[fa(h,a),fa(d,p)]}}const ya=Ca(function(t,n){const e=0===Q(t[0][0])?1:0;return function(t,n){const[e,r]=t,[,o]=n;return[V(o,r),e]}(t[e],n[e])});function Pa(t,n){return G(H(t[0],n[1]),H(t[1],n[0]))*Q(t[1])*Q(n[1])}const Aa=ga,Ba=_a;function za(t){let n=-1024;for(let e=0;en&&(n=o)}}return 0===n?t.map(t=>t.map(t=>BigInt(t))):n>0?t.map(t=>t.map(t=>{if(0===t)return 0n;const e=-Aa(t)+Ba(t)-1;return BigInt(t*2**e)*2n**BigInt(n-e)})):t.map(t=>t.map(t=>BigInt(t*2**n)))}function Fa(t,n){if(n=n<0n?-n:n,0n===(t=t<0n?-t:t))return n;if(0n===n)return t;for(;0n!==n;){const e=n;n=t%n,t=e}return t}const Ya=BigInt(2**53);function Va(t){if(0n===t)return[0];const n=[];let e=0,r=t;for(;0n!==r;){r=t/Ya;const o=t%Ya;n.push(Number(o)*2**(53*e)),t=r,e++}return vt(n)}const{round:La,sqrt:ka}=Math;function $a(t){if(t<=1n){if(t<0n)throw new Error("square root of negative numbers are not allowed");return t}let n=BigInt(La(ka(Number(t))));for(;;){const e=n+t/n>>1n;if(e===n)return n;n=e}}function Xa(t){return t<0n?-t:t}function qa(t){let n=0n;for(let e=0;e0n?1n:e<0n?-1n:0n;var e;if((t=Xa(t))<=1n)return n*t;let r=BigInt(Ga(Ra(Number(t))));for(;;){const e=(2n*r+t/(r*r))/3n;if(e===r)return n*r;r=e}}function ja(t){return H(t,t)}const Za=Ca(function(t,n){const e=0===Q(t[0][0])?1:0;return function(t,n){const[e,r]=t,[o,i]=n,c=function(t){const[n,e]=za(t).map(qa),r=Fa(n,e);return[Va(Ua(n/r)),Va(Ua(e/r))]}([o,e]),s=ja(c[0]);return[V(H(i,ja(c[1])),H(r,s)),H($(3,e),s)]}(t[e],n[e])}),{EPSILON:Wa}=Number,Ja=Wa/2+Wa**2/2;function Ka(t){return t>0?t-t*Ja:t+t*Ja}const{EPSILON:tp}=Number,np=tp/2+tp**2/2;function ep(t){return t>0?t+t*np:t-t*np}function rp(t){if(0===t||1===t)return[t,t];const n=Ka(Ka(t)),e=function(t){return ep(ep(t))}(t);return[n,e]}function op(t,n,e,r){const o=t.ps,i=n.ps,c=[];let s=ta(o,i);if(void 0===s){const r=2**(e-47),s=function(t,n,e=!1){e||(t=ca(t),n=ca(n));const r=[,,ya,Qa,Za],[o,i]=r[t.length](t,n),[c,s]=r[t.length](n,t),u=[{tA:o,tB:0,bez:"B",start:!0},{tA:i,tB:1,bez:"B",start:!1},{tA:0,tB:c,bez:"A",start:!0},{tA:1,tB:s,bez:"A",start:!1}].sort((t,n)=>t.tA-n.tA);if(u[1].tA===u[2].tA){const n=u[1],e=n.tA,r=n.tB,o=No(t,[e,e]);return[{p:o[0],kind:4,box:o,t1:e,ri1:{tS:e,tE:e,multiplicity:1},t2:r,ri2:{tS:r,tE:r,multiplicity:1}}]}if(u[0].bez===u[1].bez)return[];const f=u[1],l=u[2],[a,p]=rp(f.tA),[h,d]=rp(f.tB),[v,g]=rp(l.tA),[m,x]=rp(l.tB),b=No(t,[a,p]),I=No(n,[h,d]),_=No(t,[v,g]),N=No(n,[m,x]),S=ra(b,I),E=ra(_,N),w={tS:a,tE:p,multiplicity:1},M={tS:h,tE:d,multiplicity:1},O={tS:v,tE:g,multiplicity:1},T={tS:m,tE:x,multiplicity:1};return[{p:So(S),kind:5,box:S,t1:ho(w),ri1:w,t2:ho(M),ri2:M},{p:So(E),kind:5,box:E,t1:ho(O),ri1:O,t2:ho(T),ri2:T}]}(o,i);for(const e of s){const i=vo(o,e.ri1.tS),s=[[i[0]-r,i[1]-r],[i[0]+r,i[1]+r]],u={x:{ri:e.ri1,kind:5,box:s},curve:t},f={x:{ri:e.ri2,kind:5,box:s},curve:n};c.push([u,f])}return c}if(r&&(s=s.filter(t=>t.tS>0)),0===s.length)return[];const u=oa(o,i,s);if(void 0===u||0===u.length)return[];for(const e of u){const r={x:e[0],curve:t},o={x:e[1],curve:n};c.push([r,o])}return c}const ip=vo,cp=mo,sp=j(1);function up(t,n,e){const r=n.ps;if(0===t)return r[0],{x:{ri:{tS:t,tE:t,multiplicity:1},box:[r[0],r[0]],kind:e},curve:n};if(1===t){const o=r[r.length-1];return{x:{ri:{tS:t,tE:t,multiplicity:1},box:[o,o],kind:e},curve:n}}const{p:o,pE:i}=function(t,n){const e=ip(t,n),r=cp(t,[0,n]);if(4===t.length)return{p:e,pE:r.map(t=>9*sp*t)};if(3===t.length)return{p:e,pE:r.map(t=>6*sp*t)};if(2===t.length)return{p:e,pE:r.map(t=>3*sp*t)};if(1===t.length)return{p:t[0],pE:[0,0]};throw new Error("The given bezier curve must be of order <= 3.")}(r,t);return{x:{ri:{tS:t,tE:t,multiplicity:1},box:[[o[0]-i[0],o[1]-i[1]],[o[0]+i[0],o[1]+i[1]]],kind:e},curve:n}}function fp(t,n){if(n.next===t){if(t.next===n)return;[t,n]=[n,t]}const e=t.ps,r=n.ps;if(function(t,n){if(4===t.length)return Kl(t,n);if(3===t.length)return Xl(t,n);if(2===t.length)return function(t,n){const[e,r]=n,o=e.length,i=r.length,c=e[o-1],s=r[i-1],u=1===o&&1===i;{const{coeffs:{vₓ:n,vᵧ:o,v:i},errorBound:{v_:u}}=Yc(t),f=Ml(e),l=Ml(r),a=Ol(c),p=Ol(s),h=Ol(n[1]),d=Ol(o[1]),v=a/3,g=p/3,m=n[1]*c,x=wl(f,n),b=h*v+2*Ol(m),I=o[1]*s,_=wl(l,o),N=d*g+2*Ol(I),S=Il(x,_),E=b+N+Ol(S[1]),w=Il(S,i),M=E+u+Ol(w[1]);if(Tl*M[t]))){const i=oa(e,r,[(o=1,{tS:o,tE:o,multiplicity:1})]);if(void 0===i||0===i.length)return;return[[{x:i[0][0],curve:t},up(1,n,1)]]}var o}const lp=z;function ap(t){return t[t.length-1]<0?lp(t):t}Number.EPSILON;const pp=Number.EPSILON/2;function hp(t,n,e,r){const o=t/n,i=Math.abs(t),c=Math.abs(n),s=c-r;return s<=0?{est:o,err:Number.POSITIVE_INFINITY}:{est:o,err:(c*e+i*r)/s**2+pp*Math.abs(i/c)}}const dp=V,vp=H,gp=$,mp=P,xp=A,bp=qc,Ip=x,_p=Co,Np=Ff,Sp=B,Ep=D,wp=2*Number.EPSILON,Mp=Math.abs,Op=j(1);function Tp(t,n=!0){if(t.length<4)return[];const{coeffs:[e,r,o],errBound:[i,c,s]}=Mt(t);if(Mp(e)<=i){const[[n,e],[r,o],[i,c],[s,u]]=t,f=Sp(mp(s,n),gp(3,mp(r,i))),l=Ep(xp(i,n),-2*r),a=Sp(mp(u,e),gp(3,mp(o,c))),p=Ep(xp(c,e),-2*o);if(0===G(vp(l,a),vp(f,p)))return[]}const u=r*r,f=4*e*o,l=u-f,a=2*c*Mp(r)+Op*u+(4*(i*Mp(o)+Mp(e)*s)+Op*Mp(f))+Op*Mp(l);if(l<-a)return[];if(l>a){const{est:t,err:u}=function(t,n){if(t-n<=0){const e=t>0?Math.sqrt(t):0;return{est:e,err:Math.max(Math.sqrt(t+n)-e,e)}}const e=Math.sqrt(t),r=Math.sqrt(t-n),o=Math.sqrt(t+n);return{est:e,err:Math.max(Math.abs(r-e),Math.abs(o-e))}}(l,a);let f;f=r>=0?-r-t:-r+t;const p=c+u+Op*Mp(f),{est:h,err:d}=hp(f,2*e,p,2*i),{est:v,err:g}=hp(2*o,f,2*s,p);if(n){if(h+d<0||h-d>1||v+g<0||v-g>1)return[]}else if((h+d<0||h-d>1)&&(v+g<0||v-g>1))return[]}let[p,h,d]=kt(t);const v=dp(vp(h,h),gp(4,vp(p,d))),g=Q(v);if(g<0)return[];if(g>0){const t=function(t){const n=t[0],e=t[1];if(0===e)return[0,0];const r=Math.sqrt(e),o=r*r,i=134217729*r,c=i-(i-r),s=r-c,u=.5*(e-o-(s*s-(o-c*c-c*s*2))+n)/r;return[u-(r+u-r),r+u]}(Ci(v));let e;p=Ci(p),h=Ci(h),d=Ci(d),e=Q(h)>=0?bp(Ip(h,t)):Ip(bp(h),t);let r=ht(Np(e,_p(p))),o=ht(Np(_p(d),e));if(n){if(r<-wp||r>1+wp||o<-wp||o>1+wp)return[]}else if((r<-wp||r>1+wp)&&(o<-wp||o>1+wp))return[];return[r,o]=r=0-wp&&r<=1+wp?o>=0-wp&&o<=1+wp?[r,o]:[r]:o>=0-wp&&o<=1+wp?[o]:[]}const m=Ko(p);if(Q(h)*Q(m)<0)return[];if(G(ap(h),ap(m))>0)return[];const x=Ci(h),b=Ci(m),I=Np(x,b),_=I[1]+I[0];return[_,_]}const Cp=Number.EPSILON;function yp(t){if(4===t.length){const[[n,e],[r,o],[i,c],[s,u]]=t;return[[6*(s-n+3*(r-i)),6*(i+n-2*r)],[6*(u-e+3*(o-c)),6*(c+e-2*o)]]}if(3===t.length){const[[n,e],[r,o],[i,c]]=t;return[[2*(i-2*r+n)],[2*(c-2*o+e)]]}if(t.length<=2)return[[0],[0]];throw new Error("The given bezier curve must be of order <= 3.")}function Pp(t){if(xt(t))return{minima:[],maxima:[],inflections:[]};if(4===t.length&&pt(t)&&(t=Pu(t)),3===t.length){const n=function(t){const[[n,e],[r,o],[i,c]]=t,s=i-r,u=s-(r-n),f=c-o,l=f-(o-e);return[u*u+l*l,-(n*(u-r)-r*(s-r)+e*(l-o)-o*(f-o))]}(t);return{minima:[],maxima:Bn(n,0,1),inflections:[]}}const n=function(t){const[[n,e,r],[o,i,c]]=qn(t),[[s,u],[f,l]]=yp(t),[[a],[p]]=function(t){if(4===t.length){const[[n,e],[r,o],[i,c],[s,u]]=t;return[[6*(s-n+3*(r-i))],[6*(u-e+3*(o-c))]]}if(t.length<=3)return[[0],[0]];throw new Error("The given bezier curve must be of order <= 3.")}(t),h=a*i,d=p*e,v=u*c,g=u*i,m=f*f,x=s*c,b=l*r,I=l*e,_=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bp}=Math,zp=Wn(function(t){const{curves:n}=t;let e=Wi(n[0].ps).minY,r=n[0];for(let t=1;te.ts[0])&&(e=o,r=n[t])}return{curve:r,y:e}});function Fp(t){const{curve:n,y:e}=zp(t),r=e.ts;return r[0]<=0?[up(0,n,0),up(1,n.prev,0)]:r[1]>=1?[up(1,n,0),up(0,n.next,0)]:[{x:{ri:{tS:r[0],tE:r[1],multiplicity:1},kind:0,box:e.box},curve:n},{x:{ri:{tS:r[0],tE:r[1],multiplicity:1},kind:0,box:e.box},curve:n}]}function Yp(t,n,e){const r=e-(n-Math.floor(Math.log2(Math.abs(t))))+1;return r<=0?0:e>=53?t:xa(t,r)}function Vp(t,n,e){const r=function(t,n){const e=[];for(const n of t)for(const t of n.curves)e.push(t);const r=vl(e,t=>Ki(t.ps)[0][0],t=>Ki(t.ps)[1][0],function(t){return(n,e)=>{const r=n.ps,o=e.ps;if(2===r.length&&2===o.length)return function(t,n,e){let r=t.ps,o=n.ps;const i=Ki(r),c=Ki(o);if(t.next!==n&&n.next!==t){if(vc(!0,i,c)){const r=op(t,n,e,!1);return r.length?r:void 0}return}if(n.next===t&&([t,n]=[n,t],[r,o]=[o,r]),0!==gt(r[0],r[1],o[1]))return;if(!vc(!1,i,c))return;let s;return s=ml(r[0],r[1])>ml(o[0],o[1])?[ho(Mi(r,o[1])[0].ri),1]:[0,ho(Mi(o,r[0])[0].ri)],[[up(1,t,5),up(0,n,5)],[up(s[0],t,5),up(s[1],n,5)]]}(n,e,t);if(n.next===e||e.next===n)return vc(!1,Ki(r),Ki(o))&&ia(bl(r,!1),bl(o,!1),!1)?e.next===n?op(e,n,t,!0):op(n,e,t,!0):fp(n,e);let i=vc(!0,Ki(r),Ki(o));return i?(i=ia(bl(r,!1),bl(o,!1),!0),i?op(n,e,t,!1):void 0):void 0}}(n)),o=[];for(const t of r)for(const n of t.u)o.push(n);return o}(t,e),o=function(t){const n=[];for(const e of t)for(const t of e.curves){const e=t.ps,r=Tp(e);if(0===r.length)continue;const o=r[0]===r[1]?3:2,i=r[0]-Cp,c=r[0]+Cp,s=r[1]-Cp,u=r[1]+Cp,f=No(e,[i,c]),l=No(e,[s,u]);n.push([{x:{ri:{tS:i,tE:c,multiplicity:1},box:f,kind:o},curve:t},{x:{ri:{tS:s,tE:u,multiplicity:1},box:l,kind:o},curve:t}])}return n}(t),i=function(t){const n=[];for(const e of t)for(const t of e.curves)n.push([up(1,t,4),up(0,t.next,4)]);return n}(t),{extremes:c,xs:s}=function(t){const n=new Map,e=[];for(const r of t){const t=Fp(r);e.push(t),n.set(r,t)}return{extremes:n,xs:e}}(t),u=function(t,n){const e=[];for(const r of n)for(const n of r.curves){const r=n.ps,o=Pp(r),{minima:i,maxima:c}=o,s=[0,1,...i,...c];for(let o of s)Bp(Ap(r,o))>1e7*2**-t&&e.push([up(o,n,7),up(o,n,7)])}return e}(e,t);let f=[...r,...o,...i,...s,...u];if("undefined"!=typeof _debug_){for(const t of r)_debug_.generated.elems.intersection.push(...t);for(const t of o)_debug_.generated.elems.intersection.push(...t);for(const t of i)_debug_.generated.elems.intersection.push(...t);for(const t of s)_debug_.generated.elems.intersection.push(...t);for(const t of u)_debug_.generated.elems.intersection.push(...t)}let l=f.map(t=>({xs:t,box:[[t[0].x.box[0][0]-n,t[0].x.box[0][1]-n],[t[0].x.box[1][0]+n,t[0].x.box[1][1]+n]],inOuts:void 0}));for(;;){const t=vl(l,Lp,kp,gc);if(!t.length)break;const n=new Map;mc(n,t);const e=Ic(n),r=_c(l,e);l=[...Nc(e),...r]}l=function(t){return t.filter(t=>{const n=t.xs;if(2===t.xs.length){const t=n[0];if(1===t.x.kind&&t.x.ri.multiplicity%2==0)return!1}for(const n of t.xs)if(4!==n.x.kind)return!0;return!1})}(l),l=function(t,n,e){const r=Math.log2(e)-3;return t.map(t=>{const e=t.box.map(t=>t.map(t=>Yp(t,n,n-r)));return{...t,box:e}})}(l,e,n),"undefined"!=typeof _debug_&&(_debug_.generated.elems.container=l);let a=0;for(const t of l){for(const n of t.xs)n.container=t;let n;({inOuts:n,ioIdx:a}=dl(t,a)),t.inOuts=n}f=f.filter(t=>void 0!==t[0].container),function(t){const n=new Map;for(const e of t)for(const t of e){const e=t.curve.loop,r=n.get(e)||[];r.length||n.set(e,r),r.push(t)}for(const t of n){const n=t[1];if(!n||!n.length)continue;n.sort((t,n)=>{let e=t.curve.idx-n.curve.idx;return 0!==e?e:(e=t.x.ri.tS-n.x.ri.tS,0!==e?e:void 0!==t.in_?-1:1)});const e=n.length;for(let t=0;tt[0]),e=t.map(t=>t[1]);return!(qp(n)&&qp(e))}function qp(t){return function(t){for(let n=1;nt[n])return!1;return!0}(t)||function(t){for(let n=1;n{const r=Yp(e[0],t,n),o=Yp(e[1],t,n);return r===e[0]&&o===e[1]?e:[r,o]}}(t,n):jp;return t=>{const n=[];for(let e=0;eo(t)),Xp(i)&&(i=[i[0],i[i.length-1]]),i=Gp(i,r,o),void 0!==i&&n.push(i)}const e=n.length;if(!e)return[];const i=n[e-1];return i[i.length-1]=n[0][0],n}}(e,n,o);let c=t.slice();return c=r?function(t,n,e,r=.02){const o=[];for(const i of t){const t=[];for(const o of i){const i=o.map(t=>t.map(t=>{let o,i=0,c=0,s=0;for(;!(++c>10);){i=(t+Math.random())*(1+(Math.random()-.7)*r),i=Yp(i,e,n);const c=_a(i);c>s&&(s=c,o=i)}return o}));t.push(i)}o.push(t)}return o}(c,n,e,1):c,c=c.map(i),c=c.filter(t=>t.length>0),c}const Wp=Wn(t=>{let n=0;for(const e of t)for(const t of e)for(const e of t)for(const t of e){const e=Math.abs(t);e>n&&(n=e)}return n}),Jp=Mn;function Kp(t,n){const e=t.length-1,r=n.length-1;if(e<0||r<0)return[];const o=e+r,i=new Array(o+1).fill(0);for(let c=0;c0?-o:0,s=Math.max(e,r),u=[];for(let e=0;e-t));return Ji(t.map(t=>ce(-n,e,r(t))))}(t,i,c),[[f,l],[a,p]]=u,h=[u[0],[a,l],u[1],[f,p]],d=ce(i,c);return h.map(n=>oe(t[0],d(n)))}function ch(t){return{ps:t,ts:[0,1]}}const{round:sh,PI:uh}=Math;const{abs:fh,max:lh}=Math;function ah(t,e,r={}){let o;"undefined"!=typeof _debug_&&(o=performance.now()),e=e||Wp(t);const i=Math.ceil(Math.log2(e)),{maxBitLength:c=46,inclMicroCorners:s=!0,minLoopArea:u=(2**i*2**-12)**2,orientationPositive:f=!1}=r,l=2**i*2**-c*16;(function(t){if("undefined"!=typeof _debug_)for(const n of t){_debug_.generated.elems.loopPre.push(...t),_debug_.generated.elems.loopsPre.push(t);for(const t of n){const n=Ki(t),e=ih(t),r=bl(t,!1);_debug_.generated.elems.bezier_.push(t),_debug_.generated.elems.looseBoundingBox_.push(n),_debug_.generated.elems.tightBoundingBox_.push(e),_debug_.generated.elems.boundingHull_.push(r)}}})(t=Zp(t,c,i,!1,!0)),t.sort(pc);const a=t.map((t,e)=>n(t,e)),{extremes:p,containers:h}=Vp(a,l,i),d={dir:void 0,idx:0,parent:void 0,children:new Set,windingNum:0,p:void 0,_x_:void 0,container:void 0,loopsIdxs:new Set,orientation:-1},v=new Set,g=new Set;for(const t of a){if(v.has(t))continue;v.add(t);const n=ac(d,t),e=p.get(t)[0].container;if(0===e.inOuts.length)continue;const r=$p(e,n,t),o=2===e.inOuts.length&&2===e.xs.length;if(o&&e.inOuts[0].nextOrPrev===e.inOuts[1])r.bezierPieces=t.beziers.map(ch),r.parent.children=r.parent.children||new Set,r.parent.children.add(r);else if(Gi(r,v,g,!1),o&&void 0!==r.bezierPieces){const{bezierPieces:t}=r,n=t[t.length-1],e=t[0];if(n.ps===e.ps){const r={ps:n.ps,ts:[n.ts[0],e.ts[1]]};t.shift(),t.pop(),t.unshift(r)}}}const m=function(t){const n=[],e=[t];for(;e.length;){const t=e.pop();t.children=t.children||new Set;for(const r of t.children)0===t.windingNum&&n.push(r),e.push(r);0===t.windingNum&&(t.children=new Set)}return n}(d),x=m.map(dc).map(t=>{const e=(f?1:-1)*t[0].orientation;return t.map((t,r)=>function(t,e,r){const o=t.bezierPieces?.map(Di);return n(void 0===o?[]:e<0?o.map(t=>t.toReversed()).toReversed():o,r)}(t,e,r))}),b=[];for(let t=0;tMath.abs(rh(t.beziers))>u);n.length&&(n.sort((t,n)=>pc(t.beziers,n.beziers)),b.push(n))}"undefined"!=typeof _debug_&&(_debug_.generated.timing.simplifyPaths=performance.now()-o);const I=s?b:b.map(t=>t.map(t=>{const{beziers:e}=t,r=function(t,n){!function(t){sh(function(t){const n=t.length;let e=0;for(let r=0;rt.map(t=>[t[0],t[1]])).filter(t=>oh(t)>n),r=e.length;for(let t=0;tfh(t.box[0][0]-t.box[1][0])),...h.map(t=>fh(t.box[0][1]-t.box[1][1]))));return n(r,t.idx)}));return function(t){if("undefined"!=typeof _debug_)for(const n of t)_debug_.generated.elems.loop.push(...n),_debug_.generated.elems.loops.push(n)}(I),I}const ph=Math.max,hh=Math.abs;function dh(t,n){const e=t[0],r=t[1],o=t[2],i=t[3],c=e[0],s=e[1],u=r[0],f=r[1],l=o[0],a=o[1],p=i[0],h=i[1],d=n[0],v=n[1],g=c-d,m=u-d,x=l-d,b=p-d,I=s-v,_=f-v,N=a-v,S=h-v,E=g*g,w=6*g*m,M=6*x*b,O=I*I,T=6*I*_,C=6*N*S,y=6*m*b+9*x*x,P=2*g*b+18*m*x,A=6*g*x+9*m*m,B=6*_*S+9*N*N,z=2*I*S+18*_*N,F=6*I*N+9*_*_;return[6*(b*b-M+(E-w)+y+(A-P)+(S*S-C+(O-T)+B+(F-z))),5*(M+5*w+3*P-2*(y+2*A+3*E)+(C+5*T+3*z-2*(B+2*F+3*O))),4*(y-3*(P-2*A)-5*(2*w-3*E)+(B-3*(z-2*F)-5*(2*T-3*O))),3*(P-2*(2*A-5*(w-2*E))+(z-2*(2*F-5*(T-2*O)))),2*(A-5*(w-3*E)+(F-5*(T-3*O))),w-6*E+(T-6*O)]}function vh(t,n){const e=t[0],r=t[1],o=t[2],i=e[0],c=e[1],s=r[0],u=r[1],f=o[0],l=o[1],a=n[0],p=n[1],h=i-a,d=s-a,v=f-a,g=c-p,m=u-p,x=l-p,b=h*h,I=h*d,_=d*v,N=g*g,S=g*m,E=m*x,w=g*x+m*m*2,M=h*v+d*d*2;return[x*x+N+2*w-4*(E+S)+(v*v+b+2*M-4*(_+I)),3*(E-w+(3*S-N)+(_-M+(3*I-b))),w-3*(2*S-N)+(M-3*(2*I-b)),S-N+(I-b)]}function gh(t,n){const[[e,r],[o,i]]=t,[c,s]=n,u=e-c,f=o-c,l=r-s,a=i-s,p=u*f+l*a,h=l*l+u*u;return[f*f+a*a+(h-2*p),p-h]}const mh=Math.sqrt;function xh(t,n){let e;if(4===t.length)e=dh(t,n);else if(3===t.length)e=vh(t,n);else{if(2!==t.length){if(1===t.length)return{p:t[0],t:0,d:Ln(t[0],n)};throw new Error("The given bezier curve must be of order <= 3.")}e=gh(t,n)}const r=Bn(e,0,1);r.push(0),r.push(1);let o,i=Number.POSITIVE_INFINITY;for(const e of r){const r=vo(t,e),c=ml(r,n);cn&&(n=o),i>n&&(n=i)}return n}function _h(t){return Math.max(t.hL+t.hEL,t.hR+t.hER)}function Nh(t,n){const e=_h(t)-_h(n);return 0!==e?e:t.tS-n.tS}class Sh{compare;heap=[];constructor(t){this.compare=t}insert(t){const n=this.heap;n.push(t);let e=n.length-1;for(;;){const r=(e-1-(e+1)%2)/2;if(-1===r)return;const o=n[r];if(this.compare(t,o)<0)break;n[r]=t,n[e]=o,e=r}}popMax(){const t=this.heap,n=t[0];return t[0]=t[t.length-1],t.length--,this.swimDown(),n}swimDown(){const t=this.heap,n=t.length;let e=0;for(;;){const r=2*e+1;if(r>=n)break;const o=2*e+2,i=o>=n||this.compare(t[r],t[o])>0?r:o,c=t[i],s=t[e];if(this.compare(s,c)>0)break;t[i]=s,t[e]=c,e=i}}swapMinOrMax(t){this.heap[0]=t,this.swimDown()}static getParentIdx(t){return(t-1-(t+1)%2)/2}static getLeftChild(t){return 2*t+1}static getRightChild(t){return 2*t+2}}const Eh=Math.max;function wh(t,n,e,r=50){if(1===t.length)return xh(n,t[0]).d;if(1===n.length)return function(t,n){let e;if(4===t.length)e=dh(t,n);else if(3===t.length)e=vh(t,n);else{if(2!==t.length){if(1===t.length)return{p:t[0],t:0,d:Ln(t[0],n)};throw new Error("The given bezier curve must be of order <= 3.")}e=gh(t,n)}const r=Bn(e,0,1);r.push(0),r.push(1);let o,i=Number.NEGATIVE_INFINITY;for(const e of r){const r=vo(t,e),c=ml(r,n);c>i&&(i=c,o={p:r,t:e,d:bh(c)})}return o}(t,n[0]).d;if(2===t.length&&2===n.length){const e=xh(n,t[0]).d,r=xh(n,t[t.length-1]).d;return e>r?e:r}const o=Eh(Ih(t),Ih(n));e=e||o/1e6;const[i,c]=Mh(t,0,1),s={tS:0,tE:1,hL:xh(n,t[0]).d,hR:xh(n,t[t.length-1]).d,hEL:i,hER:c},u=new Sh(Nh);u.insert(s);let f=0,l=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(;;){const o=u.heap[0],{tS:i,tE:c,hL:s,hR:p}=o,h=(i+c)/2,[d,v]=Mh(t,i,h),[g,m]=Mh(t,h,c),x=vo(t,h),b=Ln(x,xh(n,x).p),I=Eh(s,b,p);if(I>a&&(a=I),l=_h(o),l-ar)return a;const _={tS:i,tE:h,hL:s,hR:b,hEL:d,hER:v},N={tS:h,tE:c,hL:b,hR:p,hEL:g,hER:m};u.swapMinOrMax(_),u.insert(N)}}function Mh(t,n,e){const r=(e+n)/2,o=Gn(t,n,r),i=Gn(t,r,e);return[oh(o),oh(i)]}function Oh(t,n=!1){const e=t;let r=e;const o=[];do{n&&r===e||Ae(r)||o.push(r),r=r.nextOnCircle}while(r!==e);return o}function Th(t){const n=[],e=[t],r=new Set;for(;e.length>0;){const t=nr(e.pop());if(0===t.length)continue;n.push(t);const o=t[0],i=t[t.length-1].next.prevOnCircle;r.add(o),r.add(i);const c=Oh(o,!0),s=Oh(i,!0),u=c.filter(t=>!r.has(t)),f=s.filter(t=>!r.has(t));for(const t of u)r.add(t);for(const t of f)r.add(t);e.push(...u,...f)}return n}const Ch=-1;class yh{constructor(t){this.datum=t,this.color=0}}function Ph(t){return!!t&&0===t.color}class Ah{constructor(t,n=!0,e){if(this.compare=t,this.duplicatesAllowed=n,this.getMinNode=this.getMinOrMaxNode(Ch),this.getMaxNode=this.getMinOrMaxNode(1),this.root=void 0,this.nodeCount=0,this.valueCount=0,e)for(const t of e)this.insert(t)}isEmpty(){return!this.root}find(t){const n=this;let e=this.root;for(;e;){const r=n.compare(t,e.datum);if(0===r)return e;e=e[r>0?1:Ch]}}toArrayInOrder(){const t=[];return function n(e){e&&(n(e[-1]),t.push(e.datum),void 0!==e.extras&&t.push(...e.extras),n(e[1]))}(this.root),t}insertMulti(t){const n=this;for(const e of t)n.insert(e)}insert(t){const n=this;n.root=function t(e,r){if(void 0===e)return n.valueCount++,n.nodeCount++,new yh(r);const o=n.compare(r,e.datum);if(0===o&&(n.duplicatesAllowed?(n.valueCount++,void 0===e.extras?e.extras=[r]:e.extras.push(r)):e.datum=r),0!==o){const n=o>0?1:Ch;e[n]=t(e[n],r),e[n].parent=e}return Ph(e[1])&&!Ph(e[-1])&&(e=Bh(Ch,e)),Ph(e[-1])&&Ph(e[-1][-1])&&(e=Bh(1,e)),Ph(e[-1])&&Ph(e[1])&&Fh(e),e}(n.root,t),n.root.color=1,n.root.parent=void 0}remove(t,n=!1,e){const r=this;if(void 0===r.root)return;let o;const i=function t(i,c){const s=r.duplicatesAllowed&&void 0!==i.extras;let u=r.compare(c,i.datum);if(u<0&&!i[-1]||u>0&&!i[1])return i;if(u<0){Ph(i[-1])||Ph(i[-1][-1])||(i=Yh(i));const n=t(i[-1],c);return null===n?null:(i[-1]=n,i[-1]&&(i[-1].parent=i),Vh(i))}if(Ph(i[-1])&&(i=Bh(1,i),u=r.compare(c,i.datum)),0===u&&!i[1]){if(s&&!n){if(void 0===e||!0===e(c,i.datum))return o=i.datum,i.datum=i.extras.pop(),r.valueCount--,0===i.extras.length&&(i.extras=void 0),i;{const t=i.extras;for(let n=0;n=0?r[0]=e:r[1]=e,e=e[o>=0?1:Ch]}return r}findBoundsExcl(t){const n=this,e=n.root,r=[void 0,void 0];return void 0===e||function e(o){for(;o;){const i=n.compare(t,o.datum);if(0===i)return e(o[-1]),void e(o[1]);i>0?r[0]=o:i<0&&(r[1]=o),o=o[i>0?1:Ch]}}(e),r}findAll(t){const n=this;let e=this.root;for(;e;){const r=n.compare(t,e.datum);if(0===r)return[e.datum,...e.extras?e.extras:[]];e=e[r>0?1:Ch]}return[]}getMinOrMaxNode(t){return n=>{if(void 0===n&&(n=this.root),n){for(;n[t];)n=n[t];return n}}}min(t){void 0===t&&(t=this.root);const n=this.getMinNode(t);if(void 0!==n)return n.datum}max(t){void 0===t&&(t=this.root);const n=this.getMaxNode(t);if(void 0!==n)return n.datum}}function Bh(t,n){const e=n[-t];return n[-t]=e[t],e[t]&&(e[t].parent=n),e[t]=n,n.parent=e,e.color=n.color,n.color=0,e}function zh(t){if(t[-1])return Ph(t[-1])||Ph(t[-1][-1])||(t=Yh(t)),t[-1]=zh(t[-1]),t[-1]&&(t[-1].parent=t),Vh(t)}function Fh(t){t.color=(t.color+1)%2,t[-1].color=(t[-1].color+1)%2,t[1].color=(t[1].color+1)%2}function Yh(t){if(Fh(t),Ph(t[1][-1])){const n=Bh(1,t[1]);t[1]=n,n.parent=t,Fh(t=Bh(Ch,t))}return t}function Vh(t){return Ph(t[1])&&(t=Bh(Ch,t)),Ph(t[-1])&&Ph(t[-1][-1])&&(t=Bh(1,t)),Ph(t[-1])&&Ph(t[1])&&Fh(t),t}const{cpNodeComparator:Lh,getAllOnLoop:kh}=rr;function $h(t){const n=new Map;return kh(t).forEach(function(t){const e=t.cp.pointOnShape.curve.loop;let r=n.get(e);r||(r=new Ah(Lh,!1),n.set(e,r)),r.insert(t)}),n}function Xh(t,n=.125,e=50){let r=je(t.cpNode);for(;!Ae(r);)r=r.next;const o=Th(r),i=new Set;for(let t=0;tn);)i.add(r[c])}}r=function(t,n){const e=n;if(t(e))return e;let r=n.next;for(;r!==e;){if(t(r))return r;r=r.next}}(t=>Ae(t)?t:void 0,r);for(const n of i)or(t=>2!==qe(t)&&!t.isHoleClosing)(n)||Ke(n,t.meta.cpTrees);return{cpNode:r,meta:{...t.meta,cpTrees:$h(r)}}}function qh(t,n,e,r){const o=[],i=Te(e[t],e[n].next);for(;tn*s)for(const t of Pe(i))if(r.set(t,o-c),!i.isHoleClosing){const{center:t}=i.cp.circle;Gh(e,t[0],t[1])}}),e}function Zh(t,n){let e=0;"undefined"!=typeof _debug_&&(e=performance.now());const r=function(t){const n=v(t);return n.reduce(function(t,n){return t.cp.circle.radius>=n.cp.circle.radius?t:n},n[0])}(je(t.cpNode));!function(t,n){const e=Dh(n);for(;e.length;){const r=e.pop(),{center:o}=r.cp.circle;if(!Qh(t,o[0],o[1])||r.isIntersection)continue;let i=r.prevOnCircle,c=!1;for(;!c;){i=i.next;const{center:e}=i.cp.circle;if(Qh(t,e[0],e[1]))if(Rh(i,n))c=!0;else{if(1===Uh(i).length)continue;c=!0}else{for(;Ae(i.prevOnCircle);)i=i.prevOnCircle;c=!0}}if(c){const t=i.prevOnCircle;t.next=i,i.prev=t,t.nextOnCircle=i,i.prevOnCircle=t}}}(jh(r,n),r);const o={cpNode:r,meta:{...t.meta,cpTrees:$h(r)}};return function(t){"undefined"!=typeof _debug_&&(_debug_.generated.timing.sats=performance.now()-t)}(e),o}const Wh={maxCurviness:.05,maxLength:40,applySat:!0,satScale:2,simplify:!0,simplifyTolerance:2**-4,minBezLength:2**-6,angleIncrement:15},Jh={maxCurviness:{range:[.01,3]},maxLength:{range:[1,1024],scaleByMaxRadius:!0},angleIncrement:{range:[.1,360]},satScale:{range:[1,Number.POSITIVE_INFINITY]},simplifyTolerance:{range:[2**-10,1024],scaleByMaxCoordinate:!0},minBezLength:{range:[2**-20,2],scaleByMaxCoordinate:!0}};function Kh(t){return[t[1],-t[0]]}function td(t,n){return Ee(n)&&Se(n).isDull?-te(Kh(Se(n).tangents[0]),ie(Kn(n.p,t.center))):0}function nd(t){return t[0]*t[0]+t[1]*t[1]}function ed(t,n,e){return t[0]*(n[1]*e[2]-n[2]*e[1])-t[1]*(n[0]*e[2]-n[2]*e[0])+t[2]*(n[0]*e[1]-n[1]*e[0])}function rd(t){const n=t[0],e=t[1],r=t[2],o=nd,i=.5*ed([o(n),n[1],1],[o(e),e[1],1],[o(r),r[1],1]),c=.5*ed([n[0],o(n),1],[e[0],o(e),1],[r[0],o(r),1]),s=ed([n[0],n[1],1],[e[0],e[1],1],[r[0],r[1],1]);return[i/s,c/s]}function od(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])}const id=Number.EPSILON/2,cd=id*id;function sd(t){const n=t*cd;return n/(1-n)}const ud=Ir,fd=x,{abs:ld}=Math,ad=sd(3);function pd(t,n,e){const r=t.length-1,o=[t[0]];let i=n[0];const c=[i];for(let s=1;sad*t)}}const hd=$,dd=B;function vd(t,n){const e=t.length-1,r=[t[0]];for(let o=1;ot/Id),i):void 0,g=c&&a?pd(v.coeffs,v.errBound.map(t=>t/Id),i):void 0,m=c&&a?pd(g.coeffs,g.errBound.map(t=>t/Id),i):void 0,{polyDd:x,polyE:b,getPolyExact:I}=void 0!==m?{polyDd:m.coeffs,polyE:m.errBound,getPolyExact:()=>vd(vd(vd(d(),i),i),i)}:void 0!==v?{polyDd:v.coeffs,polyE:v.errBound,getPolyExact:()=>vd(d(),i)}:{polyDd:p,polyE:h,getPolyExact:d},_=ao(x,u,f,b,I),N=1===i&&n===o.next||0===i&&n===o,S=0===i&&n===o.prev||1===i&&n===o;0===u?N||_.push({tS:0,tE:0,multiplicity:1}):1===u?S||_.push({tS:1,tE:1,multiplicity:1}):_.push({tS:u,tE:u,multiplicity:1}),0===f?N||_.push({tS:0,tE:0,multiplicity:1}):1===f?S||_.push({tS:1,tE:1,multiplicity:1}):_.push({tS:f,tE:f,multiplicity:1});const E=_.map(r=>{const{tS:o,tE:i}=r;if(if)return;const c=(o+i)/2,s=c<0?0:c>1?1:c,a=No(l,[o,i]),p=function(t){const n=t[0],e=t[1];return[(n[0]+e[0])/2,(n[1]+e[1])/2]}(a),h=function(t,n,e){const r=n[0],o=n[1],i=r[0],c=r[1],s=o[0],u=o[1],f=e[0],l=e[1];let a=Number.POSITIVE_INFINITY,p=Number.NEGATIVE_INFINITY;for(const[n,e]of[[i,c],[i,u],[s,c],[s,u]]){const r=gd(n,f),o=gd(e,l),i=xd(md(r,r),md(o,o))[1],c=i*(1-2**t*bd),s=i*(1+2**t*bd);c<=a&&(a=c),s>=p&&(p=s)}return[a,p]}(t,a,e),d=0===s?1:s;return{curve:0===s?n.prev:n,p,t:d,d:(_d(h[0])+_d(h[1]))/2,dSquaredI:h,box:a}});return E.filter(t=>void 0!==t)}const Sd=ml;function Ed(t,n){const e=t[0],r=t[1],o=e[0],i=e[1],c=r[0],s=r[1],u=n[0],f=n[1];return us?Sd([o,s],n):(o-u)**2:u>c?fs?Sd(t[1],n):(u-c)**2:fs?(f-s)**2:0}const wd=Wn(Ji);function Md(t,n){const e=[0,1,2,3].map(e=>function(t,n){const e=ml,r=n[0],o=n[1],i=e(r,o);if(0==i)return e(t,r);let c=((t[0]-r[0])*(o[0]-r[0])+(t[1]-r[1])*(o[1]-r[1]))/i;return c=Math.max(0,Math.min(1,c)),e(t,[r[0]+c*(o[0]-r[0]),r[1]+c*(o[1]-r[1])])}(n,[t[e],t[(e+1)%4]])),r=ml(t[0],t[1]),o=ml(t[0],t[3]);return e[0]<=o&&e[2]<=o&&e[1]<=r&&e[3]<=r?0:Math.min(...e)}const Od=Wn(ih);function Td(t,n,e,r=void 0,o=void 0,i=!1,c=0){n=function(t,n){const e=function(t,n){let e=Number.POSITIVE_INFINITY;for(let r=0;rvr(t.curve,t.t,!1))}const{max:Cd,ceil:yd,log2:Pd}=Math;function Ad(t,n){return n.map(n=>Td(5,n,t)[0])}function Bd(t,n){return[n*t[0],n*t[1]]}function zd(t,n,e){const r=od(e);let o,i,c,s,u=1,f=0;do{i=oe(Bd(e,u),n),c=Ad(i,t),s=od(Kn(i,rd(c.map(t=>t.p)))),o=si&&p<10;){if(p++,l=Ad(h,f),!Number.isFinite(h[0])||!Number.isFinite(h[1]))return;a=rd(l.map(t=>t.p));const t=Yd(h,a);if(!Number.isFinite(t[0])||!Number.isFinite(t[1]))return;const n=zd(f,h,t);h=n.newX,l=n.newPoss;const e=od(t);d=Math.abs(e-n.newV)}const v=(Ln(h,l[0].p)+Ln(h,l[1].p)+Ln(h,l[2].p))/3,g={center:h,radius:v};let m=0;for(let t=0;t<3;t++){const n=l[t],e=ie(Kn(n.p,h)),r=ne(e);if(Ee(n)&&Se(n).isDull){const t=Ne(n.curve.ps,n.curve.next.ps).tangents.map(ne),r=Math.asin(ee(t[0],e)),o=Math.asin(ee(e,t[1]));let i=0;r>0&&(i+=r),o>0&&(i+=o),m+=i}else{const t=ie(se(n.curve.ps,n.t));m+=Math.abs(Math.asin(ee(r,t)))}}const x=[];for(let t=0;t!!Ee(t)&&Se(t).isQuiteSharp);function kd(t){let n=t[0];const e=t[1],r=[];let o=!0;do{if(!o){o=!0,n=n.prevOnCircle;continue}o=!1;const t=n.cp.pointOnShape,e=n.next.cp.pointOnShape;e.curve===t.curve&&Ld(t)&&Ld(e)||(e.curve===t.curve&&d(n.next.cp,n.cp)>0?r.push({curve:t.curve,ts:[t.t,e.t]}):(r.push({curve:t.curve,ts:[t.t,1]}),t.curve.loop===e.curve.loop&&$d(r,t.curve,e.curve,e.t))),n=n.next}while(n!==e);return r}function $d(t,n,e,r){let o=n;do{o=o.next;const n=o===e?r:1;t.push({curve:o,ts:[0,n]})}while(o!==e)}function Xd(t,n,e,r){const o={pointOnShape:n,order:e,order2:r},i=t.findBounds({cp:o});if(void 0!==i[0]||void 0!==i[1])return void 0===i[0]||void 0===i[1]?t.max(t.root):i[0].datum}function qd(t,n,e,r,o,i){if(void 0!==i&&!function(t,n,e){const r=d(n,e.cp);if(r<0)return!0;if(0===r)return!0;const o=t.getMinNode();if(void 0===o)return!0;const i=o.datum;return d(t.getMaxNode().datum.cp,n)<0&&i===e}(r,o,i.next)&&!t)return;const c={cp:o,isHoleClosing:n,isIntersection:e},s=void 0===i?c:i,u=void 0===i?c:s.next;return u.prev=c,s.next=c,c.prev=s,c.next=u,r.insert(c),c}function Hd(t,n,e,r,o,i,c){let s=!1;const u=i.map((i,u)=>{const f=r[u],l=o.get(i.curve.loop),a={pointOnShape:i,circle:e,order:f,order2:0},p=void 0===c?Xd(l,i,f,0):c[u],h=qd(t,n,!1,l,a,p);return void 0===h&&(s=!0),h});return s||function(t,n){n=n.slice().sort(function(t){const n=t.center;return function(t,e){let r=t.cp.pointOnShape.p,o=e.cp.pointOnShape.p;r=[r[0]-n[0],r[1]-n[1]],o=[o[0]-n[0],o[1]-n[1]];const i=Math.atan2(r[1],r[0]);return Math.atan2(o[1],o[0])-i}}(t));const e=n.length;for(let t=0;tu)&&(te(ie(Kn(n,t.cp.circle.center)),ie(Kn(p,e.center)))>Dd||rt[0])).cpNodes:[]}}let Rd=0;function Ud(t,n){if(we(n.cp.pointOnShape))return{closeBysFor3Prong:void 0,addedCpNodes:[]};const e=[];for(;;){if(void 0===n)continue;const r=De(n);if(r.length<=2)break;const{closeBysFor3Prong:o,cpNodes:i}=Gd(t,r);if(e.push(i),o.length>0)return{closeBysFor3Prong:o,addedCpNodes:e};if("undefined"!=typeof _debug_&&++Rd===_debug_.directives.stopAfterThreeProngsNum)return}return{closeBysFor3Prong:undefined,addedCpNodes:e}}function jd(t){for(const n of t)return n}function Zd(t,n,e,r){for(const o of[n[0]])Pe(o).forEach(t=>{e.delete(t),r.delete(t)}),Ke(o,t)}const{cpNodeComparator:Wd}=rr;function Jd(t,n,e){let r;for(let o=0;o{const e=[];for(let r=0;rt[t.length-1]),u=[-s[1],s[0]],f=Math.sqrt(u[0]**2+u[1]**2);return{center:[o[0]-u[0]/(c*f),o[1]-u[1]/(c*f)],radius:1/c}}const{abs:Mv}=Math,Ov=P,Tv=m;function Cv(t,n,e){const r=Mv(t[1]-n[1])>Mv(t[0]-n[0]);let o,i,c,s,u,f;r?(o=t[1],i=t[0],c=n[1],s=n[0],u=e[1],f=e[0]):(o=t[0],i=t[1],c=n[0],s=n[1],u=e[0],f=e[1]);const l=Ff(Ov(i,s),Ov(o,c)),a=b([0,s],br(c,l)),p=Ff(x(b(x(Tv(c,c),Tv(s,s)),x(Tv(u,u),Tv(f,f))),Co(sr(a,Ov(f,s)))),Co(x(Ov(c,u),sr(l,Ov(s,f))))),h=x(sr(l,p),a);return r?[h[1],p[1]]:[p[1],h[1]]}function yv(t,n,e,r){const o=(2**-14*t)**2;if(ml(n,r)=t)return Number.POSITIVE_INFINITY;const r=P(t,n),o=Vv(n,r),i=t-n,c=n*i,s=(c-n*e-e*e/2)/(c+i*e),u=Ff(Yv(Yv(o,zv(n,e)),zv(e,e/2)),Fv(o,Vv(e,r)))[1];return kv(s),n*kv(u)}Dv(699,698,Hv),function(t,n,e){const r=698+e;const o=t*t-r*r-1,i=2*r*1,c=Ff(Yv(Yv(zv(t,t),zv(r,r)),zv(1,1)),zv(-2*r,1))[1];kv(-o/i),kv(c)}(699,0,Hv),function(t,n,e){const r=698+e,o=699,i=Xv((1-(r*r+o*o-2*r*o))/(4*r*o));Lv(i)}(0,0,Hv);const{ceil:Qv,log2:Gv,max:Rv,sqrt:Uv,abs:jv,sin:Zv,cos:Wv}=Math;function Jv(t,n,e,r,o){const{loops:i,maxCoordinate:c,squaredDiagonalLength:s,cpTrees:u}=t,f=o.curve.loop,l=(2**-21*c)**2,a=2**-46*c,p=Uv(s),h=1/p,d=2**-16*c,[v,g]=function(t,n,e,r,o){let i;const c=o.p;let s;if(n)i=[c[0],c[1]-e],s=e;else if(0===t)({center:i,radius:s}=wv(r,o));else{({center:i,radius:s}=wv(r,o,!0));const n=Kn(o.p,i),e=ce(Zv(t),Wv(t))(n);i=oe(o.p)(e)}return[i,s]}(r,n,p,h,o),m=o.p;let x=function(t,n,e,r,o,i,c){if(n)return r.filter(t=>t!==e).flatMap(t=>t.curves.map(t=>({curve:t,ts:[0,1]})));const s=Ee(i)&&Se(i).isDull?1===i.t&&0===t?-1:0===i.t?1:td(c,i):0,u=Xd(o.get(e),i,s,0);return u&&u!==u.next.next?kd([u,u]):e.curves.map(t=>({curve:t,ts:[0,1]}))}(r,n,f,i,u,o,{center:v,radius:g}),b=v;const I=Uv(function(t,n,e,r){let o=Number.POSITIVE_INFINITY;for(let i=0;iI&&(b=re(m,v,I/g));let S=0;for(;S<25;){const i=Pv(b,o.p);S<2&&(x=Av(x,b,i));const s=Td(Rv(0,Qv(Gv(c/i)))+1,x,b,o.curve,o.t,e&&0==S&&g!==1/h,r).map(t=>vr(t.curve,t.t,!1));let u,f=Number.NEGATIVE_INFINITY;_=[];for(const t of s){if(void 0===t)continue;const n=Pv(o.p,t.p);n>f&&(f=n,u=t),0!==n&&_.push(t)}const p=f;if(N=u,void 0===N||0===p)return;const m=Pv(b,N.p);if(0===S&&g<(1-d)*Uv(m))return void Bv(t,g,v,o);if(!n&&p<=Rv(Dv(g,Uv(m),4*a),l))return;if(b=Cv(b,o.p,N.p),jv(Uv(i)-Uv(m))td(n,t));for(let r=0;r{void 0!==t&&Je(t,o)})}const{PI:tg,atan2:ng}=Math;function eg(t,n,e,r){let o;const i=n*tg/180;for(let n=0;n0!==t&&1!==t);const f=u.map(t=>vr(c,t,!0));o.push(...f)}return o}}const cg=Ir,sg=P,ug=x,fg=Ir,lg=Co,ag=yo,pg=Ir,hg=sr,dg=x,vg=b;const gg=P,mg=Ir,xg=sr,bg=x,Ig=b;function _g(t){if(xt(t))return{minima:[],maxima:[],inflections:[]};if(4===t.length&&pt(t)&&(t=Pu(t)),3===t.length){const n=function(t){const[[n,e],[r,o],[i,c]]=t,s=gg(r,n),u=gg(i,r),f=Ig(u,s),l=gg(o,e),a=gg(c,o),p=Ig(a,l),h=bg(Ig(mg(n,Ig(f,[0,r])),mg(r,Ig(u,[0,r]))),Ig(mg(e,Ig(p,[0,o])),mg(o,Ig(a,[0,o]))));return[bg(xg(f,f),xg(p,p)),qc(h)]}(t);return{minima:[],maxima:ao(n,0,1).map(t=>(t.tS+t.tE)/2),inflections:[]}}const n=function(t){const[[n,e,r],[o,i,c]]=av(t),[[s,u],[f,l]]=gv(t),[[a],[p]]=function(t){if(4===t.length){const[[n,e],[r,o],[i,c],[s,u]]=t;return[[fg(6,ug(sg(s,n),fg(3,sg(r,i))))],[fg(6,ug(sg(u,e),fg(3,sg(o,c))))]]}if(t.length<=3)return[[[0,0]],[[0,0]]];throw new Error("The given bezier curve must be of order <= 3.")}(t),h=hg(a,i),d=hg(p,e),v=hg(u,c),g=hg(u,i),m=hg(f,f),x=hg(s,c),b=hg(l,r),I=hg(l,e),_=hg(f,r),N=hg(r,e),S=hg(r,n),E=hg(r,o),w=hg(e,e),M=hg(e,n),O=hg(e,i),T=hg(n,c),C=hg(n,o),y=hg(n,n),P=hg(c,i),A=hg(c,o),B=hg(i,i),z=hg(i,o),F=hg(o,o),Y=vg(hg(a,c),hg(p,r)),V=vg(h,d),L=dg(hg(u,r),hg(l,c)),k=dg(dg(hg(u,e),hg(s,r)),dg(hg(l,i),hg(f,c))),$=vg(v,b),X=vg(dg(g,x),dg(I,_)),q=dg(hg(r,r),hg(c,c)),H=dg(N,P),D=dg(O,T),Q=dg(A,B),G=dg(S,w),R=dg(hg(e,o),hg(n,i)),U=vg(y,F),j=vg(M,z),Z=dg(E,O),W=vg(N,P),J=dg(hg(r,i),hg(e,c)),K=dg(A,Q),tt=dg(S,G),nt=dg(E,D),et=dg(O,D),rt=vg(tt,K),ot=dg(D,T),it=dg(Z,T),ct=dg(Co(I),_),st=hg(y,vg(h,pg(3,d))),ut=hg(F,vg(pg(3,h),d)),ft=Co(dg(hg(C,dg(vg(hg(a,e),hg(p,i)),pg(3,vg(hg(l,f),hg(u,s))))),pg(3,hg(hg(s,f),j)))),lt=pg(3,dg(hg(R,vg(m,hg(s,s))),hg(U,dg(hg(u,f),hg(l,s))))),at=dg(dg(st,ut),dg(ft,lt)),pt=hg(a,dg(hg(o,dg(tt,pg(3,Q))),hg(n,et))),ht=hg(p,dg(dg(hg(r,dg(pg(3,y),F)),hg(e,dg(pg(3,M),lg(z)))),hg(n,K))),dt=pg(3,dg(dg(hg(u,dg(vg(hg(l,U),hg(u,C)),lg(vg(hg(f,j),hg(s,R))))),hg(s,vg(dg(lg(hg(l,j)),hg(f,dg(lg(vg(S,A)),vg(w,B)))),hg(s,it)))),dg(hg(l,dg(hg(l,C),lg(hg(f,R)))),hg(m,nt)))),vt=dg(vg(pt,ht),dt),gt=hg(a,dg(dg(lg(hg(r,R)),hg(e,ot)),hg(i,dg(ag(A),K)))),mt=hg(p,dg(dg(lg(hg(r,dg(pg(3,M),z))),hg(e,dg(w,lg(A)))),hg(i,ot))),xt=pg(3,dg(dg(hg(u,vg(dg(lg(vg(hg(l,j),hg(s,it))),hg(f,rt)),hg(u,R))),hg(s,vg(lg(hg(f,W)),hg(s,J)))),dg(hg(l,dg(dg(hg(l,R),lg(hg(f,nt))),hg(s,rt))),hg(m,J)))),bt=dg(vg(gt,mt),xt),It=hg(a,dg(hg(r,dg(E,lg(D))),hg(c,dg(w,pg(3,Q))))),_t=hg(p,dg(hg(r,dg(pg(3,G),K)),hg(c,et))),Nt=pg(3,dg(dg(hg(u,dg(vg(hg(l,rt),hg(u,nt)),lg(vg(hg(f,W),hg(s,J))))),hg(s,vg(hg(r,vg(ct,hg(s,c))),hg(c,dg(lg(hg(l,i)),hg(f,c)))))),dg(hg(l,dg(hg(l,D),hg(r,dg(lg(hg(f,i)),hg(l,o))))),hg(f,hg(c,ct))))),St=dg(vg(It,_t),Nt),Et=vg(dg(hg(q,V),lg(hg(H,Y))),pg(3,dg(hg(L,X),hg(k,$)))),wt=vg(hg(Y,q),pg(3,hg(L,$)));return{inflectionPoly:[vg(hg(s,o),hg(f,n)),vg(dg(hg(u,o),hg(s,i)),dg(hg(l,n),hg(f,e))),vg(dg(g,x),dg(I,_)),vg(v,b)],otherExtremaPoly:[at,vt,bt,St,Et,wt]}}(t),e=n.inflectionPoly,r=n.otherExtremaPoly,o=ao(r,0,1),i=function(t){const n=[],e=t.length-1;for(let r=0;r=0?c.push(n):s.push(n)}return{minima:c,maxima:s,inflections:ao(e,0,1).map(t=>(t.tS+t.tE)/2)}}const Ng=Number.POSITIVE_INFINITY,Sg=Wn(function(t){const n=[[{bezier:void 0,t:void 0,val:Ng},{bezier:void 0,t:void 0,val:Ng}],[{bezier:void 0,t:void 0,val:-Ng},{bezier:void 0,t:void 0,val:-Ng}]];return t.curves.forEach(function(t){const e=tc(t.ps);{const r=e.box[0][0],o=n[0][0].val;(rn[0][0].t)&&(n[0][0]={bezier:t,t:e.ts[0][0],val:r})}{const r=e.box[0][1],o=n[0][1].val;(rn[0][1].t)&&(n[0][1]={bezier:t,t:e.ts[0][1],val:r})}{const r=e.box[1][0],o=n[1][0].val;(r>o||r===o&&e.ts[1][0]>n[1][0].t)&&(n[1][0]={bezier:t,t:e.ts[1][0],val:r})}{const r=e.box[1][1],o=n[1][1].val;(r>o||r===o&&e.ts[1][1]>n[1][1].t)&&(n[1][1]={bezier:t,t:e.ts[1][1],val:r})}}),{minY:vr(n[0][1].bezier,n[0][1].t,!0),minX:vr(n[0][0].bezier,n[0][0].t,!0),maxX:vr(n[1][0].bezier,n[1][0].t,!0),maxY:vr(n[1][1].bezier,n[1][1].t,!0)}});function Eg(t){return Sg(t).minY}function wg(t){const{loops:n}=t,e=n.map(Eg);let r;for(let n=1;nc&&(e=t.maxX,c=t.maxX.p[0]),t.minY.p[1]u&&(o=t.maxY,u=t.maxY.p[1])}return{minX:n,minY:r,maxX:e,maxY:o}});function Og(t,n,e){const{minBezLength:r,maxCurviness:o,maxLength:i,angleIncrement:c}=e,s=ev(r),u=function(t){return n=>{const e=[];for(let r=0;rvr(o,t,!0))),e.maxima.push(...c.map(t=>vr(o,t,!0)))}return e}}(t)(n);return e.push(...r.minima,...r.maxima),e}}(r),a=t.map(s),p=new Map;Jd(t,p,a);const h=Mg(t),d=nv(n,(h.maxX.p[0]-h.minX.p[0])**2+(h.maxY.p[1]-h.minY.p[1])**2,t,p);let g;if(g=wg(d),"undefined"!=typeof _debug_&&_debug_.directives.stopAfterHoleClosers)return{cpNode:g,meta:d};if(function(){if("undefined"==typeof _debug_)return;const t=_debug_.generated.timing,n=performance.now();t.holeClosers+=n-tv,tv=n}(),g=rg(d,c,t.map(u),!1)||g,g=rg(d,c,t.map(l),!0)||g,g=rg(d,c,t.map(f),!1)||g,function(){if("undefined"==typeof _debug_)return;const t=_debug_.generated.timing,n=performance.now();t.oneAnd2Prongs+=n-tv,tv=n}(),"undefined"!=typeof _debug_&&_debug_.directives.stopAfterTwoProngs)return{cpNode:g,meta:d};if(g=function(t,n){if(void 0===n)return;const e=new Set;let r=!0;for(;r;){r=!1;const o=new Set(v(n));for(const n of o){const{closeBysFor3Prong:i,addedCpNodes:c}=Ud(t,n);c.length>0&&(r=!0),void 0===i?e.add(n):(r=!0,Zd(t.cpTrees,i,o,e)),c.forEach(t=>t.forEach(t=>e.add(t)))}n=jd(e)}return jd(e)}(d,g),void 0===g)return;if("undefined"!=typeof _debug_&&_debug_.directives.stopAfterThreeProngs)return{cpNode:g,meta:d};const m={cpNode:g,meta:d};return"undefined"!=typeof _debug_&&(_debug_.generated.timing.threeProngs+=performance.now()-tv),m}function Tg(t,n){const{maxCoordinate:e,maxRadius:r}=function(t){let n=0,e=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(const c of t)for(const t of c)for(const c of t){const t=c[0],s=c[1],u=ph(hh(t),hh(s));u>n&&(n=u),tr&&(r=t),si&&(i=s)}return{maxCoordinate:n,maxRadius:ph(r-e,i-o)}}(t),o=function(t,n,e){const r=Math.ceil(Math.log2(t)),o=Math.ceil(Math.log2(n)),i={...e};for(const t in Jh){let n=i[t];const e=Jh[t],{range:c,scaleByMaxCoordinate:s,scaleByMaxRadius:u}=e;nc[1]&&(n=c[1]),s?n*=2**r*2**-10:u&&(n*=2**o*2**-10),i[t]=n}return i}(e,r,{...Wh,...n||{}}),{applySat:i,simplify:c,satScale:s,simplifyTolerance:u}=o,f=ah(t),l=[];for(const t of f){let n=Og(t,e,o);void 0!==n&&(i&&(n=Zh(n,s)),c&&(n=Xh(n,u,50)),l.push(n))}return l}const{getProngCount:Cg,isOnSameCircle:yg,isTerminating:Pg}=rr;function Ag(t){const n=function(t){let n=t;const e=Dh(t);for(;e.length;){const r=e.pop();if(r.isHoleClosing||r.isIntersection)continue;let o=r.next;for(;;){o=o.next;let e=!1;const r=o.prevOnCircle;if(Cg(o)>2){const n=o.nextOnCircle;yg(o,t)?e=!0:o.next===n?o=n:n.next!==r&&(e=!0)}else if(Pg(o)&&!o.isIntersection)return void(n=o);if(e){r.next=o,o.prev=r,n=o;break}}}return n}(je(t.cpNode));if(n)return{cpNode:n,meta:{...t.meta,cpTrees:$h(n)}}}let Bg=0;function zg(t){return t.map(t=>{return(n=t.cp.pointOnShape).p[0]+", "+n.p[1]+" | bz: "+n.curve.idx+" | t: "+n.t;var n})}function Fg(t,n=3){return t[0].toFixed(n)+", "+t[1].toFixed(n)}const Yg={δToString:zg,δsToString:function(t){return t.map(zg)},pointToStr:Fg,pointsToStr:function(t,n=3){return t.map(t=>Fg(t,n))},nameObj:function(t,n=""){t.name=""+n+Bg++}},Vg="red thin10 nofill ",Lg="http://www.w3.org/2000/svg";function kg(t,n,e=Vg,r){const o=n.center,i=n.radius,c=document.createElementNS(Lg,"circle");return c.setAttributeNS(null,"cx",o[0].toString()),c.setAttributeNS(null,"cy",o[1].toString()),c.setAttributeNS(null,"r",i.toString()),c.setAttributeNS(null,"class",e),t.appendChild(c),r&&setTimeout(()=>c.remove(),r),[c]}function $g(t,n,e=3,r="red",o){const[i]=kg(t,{center:n,radius:e},"dot "+r,o);return o&&setTimeout(()=>i.remove(),o),[i]}function Xg(t,n,e=Vg,r=0,o=void 0,i=0){const c=document.createElementNS(Lg,"line");c.setAttributeNS(null,"x1",n[0][0].toString()),c.setAttributeNS(null,"y1",n[0][1].toString()),c.setAttributeNS(null,"x2",n[1][0].toString()),c.setAttributeNS(null,"y2",n[1][1].toString()),c.setAttributeNS(null,"class",e),t.appendChild(c);let s=[];if(void 0!==o)for(const e of n)s.push(...$g(t,e,i,o,r));for(const n of s)t.appendChild(n);const u=[c,...s];return r&&setTimeout(()=>{for(const t of u)t.remove()},r),u}function qg(t,n,e=Vg,r=3,o){const i=kg(t,{center:n,radius:r},e),c=[[n[0]-r,n[1]],[n[0]+r,n[1]]],s=[[n[0],n[1]-r],[n[0],n[1]+r]],u=Xg(t,c,e),f=Xg(t,s,e);return o&&setTimeout(()=>{i.forEach(t=>t.remove()),u.forEach(t=>t.remove()),f.forEach(t=>t.remove())},o),[...i,...u,...f]}function Hg(t){return 2===t?"L":3===t?"Q":4===t?"C":void 0}function Dg(t,n,e=Vg,r=0,o=void 0,i=0,c=void 0){const[[s,u],[f,l],[a,p]]=n,h=document.createElementNS(Lg,"path");h.setAttributeNS(null,"d",`M${s} ${u} Q${f} ${l} ${a} ${p}`),e&&h.setAttributeNS(null,"class",e);let d=[];if(void 0!==o)for(const e of n)d.push(...$g(t,e,i,o,r));let v=[];if(void 0!==c)for(let e=0;e{for(const t of g)t.remove()},r),g}function Qg(t,n,e=Vg,r=0,o=void 0,i=0,c=void 0){const[[s,u],[f,l],[a,p],[h,d]]=n;if(s===h&&f===h&&a===h&&u===d&&l===d&&p===d)return qg(t,[s,u],e,.2,r);const v=document.createElementNS(Lg,"path");v.setAttributeNS(null,"d",`M${s} ${u} C${f} ${l} ${a} ${p} ${h} ${d}`),v.setAttributeNS(null,"class",e);let g=[];if(void 0!==o)for(const e of n)g.push(...$g(t,e,i,o,r));let m=[];if(void 0!==c)for(let e=0;e{for(const t of x)t.remove()},r),x}function Gg(t,n,e=Vg,r=0,o=void 0,i=0,c=void 0){return 2===n.length?Xg(t,n,e,r,o,i):3===n.length?Dg(t,n,e,r,o,i,c):4===n.length?Qg(t,n,e,r,o,i,c):[]}const Rg=["red","green","cyan","blue"];function Ug(t,n){const e=1-n;if(4===t.length){const[[r,o],[i,c],[s,u],[f,l]]=t;return[r*e**3+3*i*e**2*n+3*s*e*n**2+f*n**3,o*e**3+3*c*e**2*n+3*u*e*n**2+l*n**3]}if(3===t.length){const[[r,o],[i,c],[s,u]]=t;return[r*e**2+2*i*e*n+s*n**2,o*e**2+2*c*e*n+u*n**2]}if(2===t.length){const[[r,o],[i,c]]=t;return[r*e+i*n,o*e+c*n]}return[NaN,NaN]}function jg(t,n){return 2===t.length?function(t,n){const[[e,r],[o,i]]=t,c=1-n,s=[c*e+n*o,c*r+n*i];return[[[e,r],s],[s,[o,i]]]}(t,n):3===t.length?function(t,n){const[[e,r],[o,i],[c,s]]=t,u=1-n,f=[u*u*e+2*u*n*o+n*n*c,u*u*r+2*u*n*i+n*n*s];return[[[e,r],[u*e+n*o,u*r+n*i],f],[f,[u*o+n*c,u*i+n*s],[c,s]]]}(t,n):4===t.length?function(t,n){const[[e,r],[o,i],[c,s],[u,f]]=t,l=1-n,a=n*n,p=a*n,h=l*l,d=h*l,v=[p*u+3*l*a*c+3*h*n*o+d*e,p*f+3*l*a*s+3*h*n*i+d*r];return[[[e,r],[n*o+l*e,n*i+l*r],[a*c+2*l*n*o+h*e,a*s+2*l*n*i+h*r],v],[v,[a*u+2*n*l*c+h*o,a*f+2*n*l*s+h*i],[n*u+l*c,n*f+l*s],[u,f]]]}(t,n):[]}const Zg={circle:kg,crossHair:qg,dot:$g,line:Xg,rect:function(t,n,e=Vg,r){const[[o,i],[c,s]]=n,u=op.remove(),r),[p]},beziers:function(t,n,e,r){const o=void 0===e,i=[];for(let r=0;ri.forEach(t=>t.remove()),r),i},bezier:Gg,bezierPiece:function(t,n,e,r=Vg,o){const i=e[0]===e[1]?qg(t,Ug(n,e[0]),r,1.5):Gg(t,function(t,n){if(0===n[0]&&1===n[1])return t;if(n[0]===n[1]){const e=Ug(t,n[0]);return[e,e,e,e]}return 0===n[0]?jg(t,n[1])[0]:1===n[1]?jg(t,n[0])[1]:jg(jg(t,n[0])[1],(n[1]-n[0])/(1-n[0]))[0]}(n,e),r);return o&&setTimeout(()=>i.forEach(t=>t.remove()),o),i},quadBezier:Dg,cubicBezier:Qg,polygon:function(t,n,e=Vg,r){const o=document.createElementNS(Lg,"path");let i=`M${n[0][0]} ${n[0][1]} L`;for(let t=0;to.remove(),r),[o]},loop:function(t,n,e=Vg,r){if(!n.length)return[];const o=document.createElementNS(Lg,"path");let i=`M${n[0][0][0]} ${n[0][0][1]} `;for(let t=0;to.remove(),r),[o]},polyline:function(t,n,e=Vg,r){if(n.length<2)return[];const o=document.createElementNS(Lg,"path");let i=`M${n[0][0]} ${n[0][1]} L`;for(let t=0;to.remove(),r),[o]},text:function(t,n,e,r,o=Vg,i){const c=document.createElementNS(Lg,"text");return c.setAttributeNS(null,"x",n[0].toString()),c.setAttributeNS(null,"y",n[1].toString()),c.setAttributeNS(null,"font-size",r.toString()),c.setAttributeNS(null,"class",o),c.textContent=e,t.appendChild(c),i&&setTimeout(()=>c.remove(),i),[c]}};function Wg(t,n){return(n,e,r,o=0,i=1)=>{let c,s;switch(e.isHoleClosing){case!1:c="red ",s="2";break;case!0:c="cyan ",s="10"}const u=e.cp,{circle:f,pointOnShape:l}=u,{center:a,radius:p}=f,{isSource:h,p:d}=l,v=e.nextOnCircle.cp.pointOnShape.p,g=h?d:v,m=h?v:d,{line:x,dot:b,circle:I,crossHair:_}=Zg,N=b(n,f.center,.02*i,"yellow",o);return[...I(n,f,c+"thin"+s+" nofill",o),...b(n,g,.005*i,c,o),...b(n,m,.01*i,c,o),...t?_(n,f.center,"red thin2 nofill",.002*i,o):[],...N]}}function Jg(t,n){return{center:t.center,radius:n*t.radius}}const{getAllOnCircle:Kg}=rr,{isTerminating:tm}=rr,nm=["thin10 blue nofill","thin10 red nofill"];function em(t,n,e,r=0,o=1){let i=n.cpNode;if(!i)return[];for(;!tm(i);)i=i.next;const c=[];let s=0;return Qe(i,async n=>{if(tm(n))return;const e=Ce(n);e&&(c.push(...Zg.bezier(t,e,nm[s%2],r)),s++)}),c}function rm(t,n,e,r){const o=document.createElementNS("http://www.w3.org/2000/svg","circle");return o.setAttributeNS(null,"cx",n[0].toString()),o.setAttributeNS(null,"cy",n[1].toString()),o.setAttributeNS(null,"r",e.toString()+"%"),o.setAttributeNS(null,"class",r),t.appendChild(o),o}function om(t,n,e="thin5 purple nofill",r=0,o=1){const i=[],c=[];for(const t of n){if(Ae(t))continue;const n=Ce(t);n&&c.push(n)}return i.push(...p(t,c,e,r)),i}const im={oneProng:function(t,n,e,r=0,o=1){const i=n[0].cp,{circle:c,pointOnShape:s}=i;return[...Zg.dot(t,s.p,.02*o,"deeppink",r),...Zg.dot(t,c.center,.05*o,"deeppink",r),...Zg.circle(t,c,"deeppink thin5 nofill",r)]},twoProng:Wg(!1),threeProng:function(t,n,e,r=0,o=1){const i=Jg(n.cp.circle,1),{center:c,radius:s}=i,u=rr.getAllOnCircle(n).map(t=>t.cp.pointOnShape),{dot:f,circle:l,crossHair:a}=Zg,p=l(t,i,"blue thin2 nofill",r),h=[],d=[];for(let n=0;nt.cp.pointOnShape),v=[],g=[];for(let n=0;nt.cp.pointOnShape),{dot:f,circle:l,crossHair:a}=Zg,p=l(t,i,e,r),h=[],d=[];for(let n=0;n0}else g=!0;if(!g)return[i,d,u];const m=Kn(p[0],p[1]),x=Kn(h[0],h[1]),b=Math.abs(ee(v,m))/9,I=Math.abs(ee(v,x))/9;return b>.01||I>.01||b>dm||I>dm?void 0:[i,u]}const gm=Wn(function(t){return Zn(Ce(t))});function mm(t,n){const e=function(t){const n=new Map;for(let e of t)for(let r of t){const t=e.cp.circle.center,o=r.cp.circle.center,i=e.cp.pointOnShape.p,c=r.cp.pointOnShape.p;r!==e&&t[0]===o[0]&&t[1]===o[1]&&i[0]===c[0]&&i[1]===c[1]&&n.set(e,r)}return n}(n),r=t.length,o=[];for(let n=0;n