brepjs-verify 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +26 -0
- package/dist/brepjs-verify.cjs +1 -1
- package/dist/brepjs-verify.js +1 -1
- package/dist/cli/main.cjs +1 -1
- package/dist/cli/main.js +1 -1
- package/dist/{diff-CZ4mLtrf.cjs → diff-BNmCp_8I.cjs} +90 -5
- package/dist/{diff-D7ZBNRJG.js → diff-D5U3Ie2F.js} +90 -5
- package/dist/snapshot/registry.cjs +1 -1
- package/dist/snapshot/registry.js +1 -1
- package/dist/snapshot/static.cjs +1 -1
- package/dist/snapshot/static.d.ts +1 -1
- package/dist/snapshot/static.js +1 -1
- package/dist/verify/brepjsRuntime.d.ts +1 -0
- package/dist/verify/expected.d.ts +15 -0
- package/package.json +8 -3
- package/reference/llms-full.txt +2052 -0
- package/reference/llms.txt +1810 -0
- package/viewer/dist/assets/{brepjs-CDZqKweN.js → brepjs-CI5VXw8W.js} +19 -19
- package/viewer/dist/assets/{index-B8QUQDqM.js → index-CiN0lKoi.js} +1 -1
- package/viewer/dist/assets/{kernelWorker-C6s5i9JH.js → kernelWorker-BtcMpY8t.js} +1 -1
- package/viewer/dist/index.html +1 -1
|
@@ -4,33 +4,33 @@ var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports);function
|
|
|
4
4
|
`)+`
|
|
5
5
|
`).buffer}function $n(e,t){return e.toBREP(E(t))}function er(e,t){return D(e,e.fromBREP(t))}function tr(e,t,n){let r=e.xcafNewDocument();for(let t of n){let n=e.xcafAddShape(r,E(t.shape));if(t.name&&e.xcafSetName(r,n,t.name),t.color){let[i,a,o]=t.color;e.xcafSetColor(r,n,i/255,a/255,o/255)}}return T(`compound`,r)}function nr(e,t,n){let r=E(t),i=e.xcafGetRootLabels(r),a=(()=>{try{return i.size()>0}finally{i.delete()}})();try{return a?e.xcafExportSTEP(r):``}finally{e.xcafClose(r)}}function rr(e,t,n,r){if(n.length===0)return``;let i=tr(e,t,n.map(e=>({shape:e.shape,name:e.name??``,color:e.color})));try{return nr(e,i)}finally{i.delete()}}function ir(e,t,n,r){return T(`vertex`,e.makeVertex(t,n,r))}function ar(e,t){throw ye(t)?Error(`occt-wasm: makeEdge from curve handle is not implemented`):Error(`occt-wasm: makeEdge is not implemented`)}function or(e,t,n){let r=xe(t,n.map(E));try{return T(`wire`,e.makeWire(r))}finally{r.delete()}}function sr(e,t,n){let r=[];for(let t of n){let n=e.getSubShapes(E(t),`edge`);try{let e=n.size();for(let t=0;t<e;t++)r.push(n.get(t))}finally{n.delete()}}let i=xe(t,r);try{return T(`wire`,e.makeWire(i))}finally{i.delete()}}function cr(e,t,n){return T(`face`,e.makeFace(E(t)))}function lr(e,t,n){return T(`edge`,e.makeLineEdge(t[0],t[1],t[2],n[0],n[1],n[2]))}function ur(e,t,n,r){return T(`edge`,e.makeCircleEdge(t[0],t[1],t[2],n[0],n[1],n[2],r))}function dr(e,t,n,r,i,a){return T(`edge`,e.makeCircleArc(t[0],t[1],t[2],n[0],n[1],n[2],r,i,a))}function fr(e,t,n,r){return T(`edge`,e.makeArcEdge(t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]))}function pr(e,t,n,r,i){return T(`edge`,e.makeEllipseEdge(t[0],t[1],t[2],n[0],n[1],n[2],r,i))}function mr(e,t,n,r,i,a,o){return T(`edge`,e.makeEllipseArc(t[0],t[1],t[2],n[0],n[1],n[2],r,i,a,o))}function hr(e,t,n){let r=[];for(let e of n)r.push(e[0],e[1],e[2]);let i=Ce(t,r);try{return T(`edge`,e.makeBezierEdge(i))}finally{i.delete()}}function gr(e,t,n,r){let[i,a,o]=t,[s,c,l]=n,[u,d,f]=r;return T(`edge`,e.makeTangentArc(i,a,o,s,c,l,u,d,f))}function _r(e,t,n,r,i,a){let o=i?i[0]:0,s=i?i[1]:0,c=i?i[2]:0,l=a?a[0]:0,u=a?a[1]:0,d=a?a[2]:1;return T(`wire`,e.makeHelixWire(o,s,c,l,u,d,t,n,r))}function vr(e,t,n){let r=xe(t,n.map(E));try{return T(`compound`,e.makeCompound(r))}finally{r.delete()}}function yr(e,t){return T(`solid`,e.solidFromShell(E(t)))}function br(e,t,n,r,i){let a=[];for(let[t,i,o]of r){let r=n[t],s=n[i],c=n[o];!r||!s||!c||a.push(e.buildTriFace(r.x,r.y,r.z,s.x,s.y,s.z,c.x,c.y,c.z))}let o=xe(t,a);try{let t=e.sewAndSolidify(o,i);return t=e.fixFaceOrientations(t),D(e,t)}finally{o.delete()}}function xr(e,t){return T(`face`,e.makeNonPlanarFace(E(t)))}function Sr(e,t,n,r){let i=xe(t,r.map(E));try{return T(`face`,e.addHolesInFace(E(n),i))}finally{i.delete()}}function Cr(e,t,n){let r=e.getSubShapes(E(n),`wire`),i=(()=>{try{return r.size()-1}finally{r.delete()}})(),a=[];for(let e=0;e<i;e++)a.push(e);let o=Se(t,a);try{return T(`face`,e.removeHolesFromFace(E(n),o))}finally{o.delete()}}function wr(e,t,n){let r=E(t);return T(`face`,e.makeFaceOnSurface(r,E(n)))}function Tr(e,t,n,r,i){let a=new t.VectorDouble;for(let[e,t,r]of n)a.push_back(e),a.push_back(t),a.push_back(r);try{return T(`face`,e.bsplineSurface(a,r,i))}finally{a.delete()}}function Er(e,t,n,r,i){let a=[];for(let t=0;t<r-1;t++)for(let r=0;r<i-1;r++){let o=t*i+r,s=(t+1)*i+r,c=t*i+(r+1),l=(t+1)*i+(r+1),u=n[o],d=n[s],f=n[c],p=n[l];u&&d&&f&&a.push(e.buildTriFace(u[0],u[1],u[2],d[0],d[1],d[2],f[0],f[1],f[2])),d&&p&&f&&a.push(e.buildTriFace(d[0],d[1],d[2],p[0],p[1],p[2],f[0],f[1],f[2]))}let o=xe(t,a);try{return D(e,e.sewAndSolidify(o,.001))}finally{o.delete()}}function Dr(e,t,n,r){let i=e.buildTriFace(t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]);return i===0?null:T(`face`,i)}function Or(e,t,n,r){let i=xe(t,n.map(E));try{let t=e.sewAndSolidify(i,r);return t=e.fixFaceOrientations(t),T(`solid`,t)}finally{i.delete()}}function kr(e,t,n){return{x:e,y:t,z:n,__type:`point3d`,delete:ve}}function Ar(e,t,n){return{x:e,y:t,z:n,__type:`direction3d`,delete:ve}}function jr(e,t,n){return{x:e,y:t,z:n,__type:`vector3d`,delete:ve}}function Mr(e,t,n,r,i,a){return{origin:{x:e,y:t,z:n},direction:{x:r,y:i,z:a},__type:`axis1`,delete:ve}}function Nr(e,t,n,r,i,a,o,s,c){return{origin:{x:e,y:t,z:n},zDir:{x:r,y:i,z:a},xDir:o===void 0?void 0:{x:o,y:s,z:c},__type:`axis2`,delete:ve}}function Pr(e,t,n,r,i,a,o,s,c){return{origin:{x:e,y:t,z:n},zDir:{x:r,y:i,z:a},xDir:o===void 0?void 0:{x:o,y:s,z:c},__type:`axis3`,delete:ve}}function Fr(e){return e}function Ir(e){return e}function Lr(e,t){return{x:e,y:t}}function Rr(e,t){let n=Math.sqrt(e*e+t*t);if(n<1e-15)throw Error(`occt-wasm: createDirection2d called with zero-length vector`);return{x:e/n,y:t/n}}function zr(e,t){return{x:e,y:t}}function Br(e,t,n,r){return{px:e,py:t,dx:n,dy:r,delete(){}}}function Vr(e){return e}function Hr(e,t,n,r){return Ir(y(e,t,n,r))}function Ur(e,t,n,r){return Ir(b(e,t,n,r))}function Wr(e,t,n,r,i,a){let o=2*(e*(r-a)+n*(a-t)+i*(t-r));if(Math.abs(o)<1e-12)return Ir(y(e,t,i,a));let s=((e*e+t*t)*(r-a)+(n*n+r*r)*(a-t)+(i*i+a*a)*(t-r))/o,c=((e*e+t*t)*(i-n)+(n*n+r*r)*(e-i)+(i*i+a*a)*(n-e))/o,l=Math.sqrt((e-s)**2+(t-c)**2),u=Math.atan2(t-c,e-s),d=Math.atan2(r-c,n-s),f=Math.atan2(a-c,i-s),p=d-u;p<0&&(p+=2*Math.PI);let m=f-u;m<0&&(m+=2*Math.PI);let h=p<m,g=b(s,c,l,h);if(!h){let e=-u,t=-f;return t<e-1e-9&&(t+=2*Math.PI),Ir({__bk2d:`trimmed`,basis:g,tStart:e,tEnd:t})}let _=f;return _<u-1e-9&&(_+=2*Math.PI),Ir({__bk2d:`trimmed`,basis:g,tStart:u,tEnd:_})}function Gr(e,t,n,r,i,a){let o=Math.sqrt(n*n+r*r),s=o>0?n/o:0,c=o>0?r/o:0,l=e-i,u=t-a,d=2*(u*s-l*c);if(Math.abs(d)<1e-12)return Ir(y(e,t,i,a));let f=-(l*l+u*u)/d,p=e-f*c,m=t+f*s,h=Math.abs(f),g=Math.atan2(t-m,e-p),_=Math.atan2(a-m,i-p),v=-(t-m)/h,x=(e-p)/h,S=v*s+x*c>0,C=b(p,m,h,S);if(!S){let e=-g,t=-_;return t<e-1e-9&&(t+=2*Math.PI),Ir({__bk2d:`trimmed`,basis:C,tStart:e,tEnd:t})}let w=_;return w<g-1e-9&&(w+=2*Math.PI),Ir({__bk2d:`trimmed`,basis:C,tStart:g,tEnd:w})}function Kr(e,t,n,r,i,a,o){return Ir(x(e,t,n,r,i??1,a??0,o??!0))}function qr(e,t,n,r,i,a,o,s,c){return Ir({...x(e,t,n,r,o??1,s??0,c??!0),__bk2d:`ellipse`,startAngle:i,endAngle:a})}function Jr(e){return Ir(S(e))}function Yr(e,t){let n=e,r=n.length,i=Math.max(1,Math.min(t?.degMax??3,r-1)),a=[0],o=[i+1],s=r-i-1;for(let e=1;e<=s;e++)a.push(e/(s+1)),o.push(1);return a.push(1),o.push(i+1),Ir({__bk2d:`bspline`,poles:n,knots:a,multiplicities:o,degree:i,isPeriodic:!1})}function Xr(e,t){return h(Fr(e),t)}function Zr(e,t){return{point:h(Fr(e),t),tangent:g(Fr(e),t)}}function Qr(e){return _(Fr(e))}function $r(e){let t=Fr(e);for(;t.__bk2d===`trimmed`&&t.basis;)t=t.basis;return v(t)}function ei(e,t,n){return Ir({__bk2d:`trimmed`,basis:Fr(e),tStart:t,tEnd:n})}function ti(e){return Ir(JSON.parse(JSON.stringify(Fr(e))))}function ni(e,t){let n=Fr(e),r=_(n),i=[];for(let e=0;e<=20;e++){let a=r.first+(r.last-r.first)*e/20,[o,s]=h(n,a),[c,l]=g(n,a),u=Math.sqrt(c*c+l*l)||1;i.push([o-l/u*t,s+c/u*t])}return Ir(S(i.length<=25?i:i.filter((e,t)=>t%2==0||t===i.length-1)))}function ri(e,t,n){return Ir(C(Fr(e),t,n))}function ii(e,t,n,r){return Ir(w(Fr(e),t,n,r))}function ai(e,t,n,r){return Ir(ee(Fr(e),t,n,r))}function oi(e,t,n){return Ir(te(Fr(e),t,n))}function si(e,t,n,r,i){return Ir(ne(Fr(e),t,n,r,i))}function ci(e){return e}function li(){return{type:`identity2d`,delete(){}}}function ui(e,t,n,r,i){return{type:`affinity2d`,axOriginX:e,axOriginY:t,axDirX:n,axDirY:r,ratio:i,delete(){}}}function di(e,t){return{type:`translate2d`,dx:e,dy:t,delete(){}}}function fi(e,t,n,r,i,a,o){return{type:`mirror2d`,cx:e,cy:t,mode:n,originX:r,originY:i,dirX:a,dirY:o,delete(){}}}function pi(e,t,n){return{type:`rotate2d`,angle:e,cx:t,cy:n,delete(){}}}function mi(e,t,n){return{type:`scale2d`,sx:e,sy:e,cx:t,cy:n,delete(){}}}function hi(e,t,n){let r=e;r.dx=(Number(r.dx)||0)+t,r.dy=(Number(r.dy)||0)+n}function gi(e,t){let n=e,r=t;n.dx=(Number(n.dx)||0)+(Number(r.dx)||0),n.dy=(Number(n.dy)||0)+(Number(r.dy)||0),r.type===`scale2d`&&(n.type=`scale2d`,n.sx=r.sx,n.sy=r.sy)}function _i(e,t){let n=t;return n.type===`translate2d`?ri(e,Number(n.dx)||0,Number(n.dy)||0):n.type===`rotate2d`?ii(e,Number(n.angle)||0,Number(n.cx)||0,Number(n.cy)||0):n.type===`scale2d`?ai(e,Number(n.sx)||1,Number(n.cx)||0,Number(n.cy)||0):n.type===`mirror2d`?oi(e,Number(n.ox)||0,Number(n.oy)||0):n.type===`affinity2d`?ai(e,Number(n.ratio)||1,Number(n.axOriginX)||0,Number(n.axOriginY)||0):Number(n.dx)||Number(n.dy)?ri(e,Number(n.dx)||0,Number(n.dy)||0):e}function vi(e,t,n){let r=re(Fr(e),Fr(t),n);return{points:r.points,segments:r.segments.map(e=>Ir(e))}}function yi(e,t,n){let r=Fr(e),i=_(r),a=(e,r,i)=>{if(e.__bk2d===`line`){let a=(t-e.ox)*e.dx+(n-e.oy)*e.dy,o=Math.max(r,Math.min(i,a)),[s,c]=h(e,o);return{param:o,distance:Math.sqrt((s-t)**2+(c-n)**2)}}let a=r,o=1/0;for(let s=0;s<=200;s++){let c=r+(i-r)*s/200,[l,u]=h(e,c),d=(l-t)**2+(u-n)**2;d<o&&(o=d,a=c)}return{param:a,distance:Math.sqrt(o)}};if(r.__bk2d===`trimmed`&&r.basis){let e=r.tStart,t=r.tEnd,n=a(r.basis,e,t);if(!n)return null;let i=t-e,o=i>1e-15?(n.param-e)/i:0;return{param:Math.max(0,Math.min(1,o)),distance:n.distance}}return a(r,i.first,i.last)}function bi(e,t,n,r,i,a){let o=1/0;for(let s=0;s<=20;s++){let c=n+(r-n)*(s/20),[l,u]=h(Fr(e),c);for(let e=0;e<=20;e++){let n=i+(a-i)*(e/20),[r,s]=h(Fr(t),n),c=Math.sqrt((r-l)**2+(s-u)**2);c<o&&(o=c)}}return o}function xi(e,t){let n=Fr(e),r=_(n),i=Math.min(Math.max(t+1,10),100),a=[];for(let e=0;e<i;e++){let t=r.first+(r.last-r.first)*e/(i-1);a.push(h(n,t))}let o=Math.min(3,i-1),s=a.length,c=[],l=[],u=s-o-1;c.push(0),l.push(o+1);for(let e=1;e<=u;e++)c.push(e/(u+1)),l.push(1);return c.push(1),l.push(o+1),Ir({__bk2d:`bspline`,poles:a,knots:c,multiplicities:l,degree:o,isPeriodic:!1})}function Si(e){let t=Fr(e);for(;t.__bk2d===`trimmed`&&t.basis;)t=t.basis;if(t.__bk2d!==`bspline`)return[e];let n=t.poles,r=t.degree,i=[];for(let e=0;e<t.knots.length;e++)for(let n=0;n<t.multiplicities[e];n++)i.push(t.knots[e]);let a=n.length-1+r+1;if(r<1||i.length!==a+1)return[Ir(S(n))];let o=e=>[e[0],e[1]],s=[],c=r,l=r+1,u=[];for(let e=0;e<=r;e++)u[e]=o(n[e]);let d=[];for(;l<a;){let e=l;for(;l<a&&i[l+1]===i[l];)l++;let t=l-e+1;if(t<r){let e=i[l]-i[c],n=[];for(let a=r;a>t;a--)n[a-t-1]=e/(i[c+a]-i[c]);let s=r-t;for(let e=1;e<=s;e++){let i=s-e,c=t+e;for(let e=r;e>=c;e--){let t=n[e-c],r=u[e],i=u[e-1];u[e]=[t*r[0]+(1-t)*i[0],t*r[1]+(1-t)*i[1]]}l<a&&(d[i]=o(u[r]))}}if(s.push(u),l<a){for(let e=r-t;e<=r;e++)d[e]=o(n[l-r+e]);u=d,d=[],c=l,l++}}return s.map(e=>Ir(S(e)))}function Ci(){return me()}function wi(e,t,n){he(e,Fr(t),n)}function Ti(e){return{xMin:e.xMin,yMin:e.yMin,xMax:e.xMax,yMax:e.yMax}}function Ei(e,t){e.xMin=Math.min(e.xMin,t.xMin),e.yMin=Math.min(e.yMin,t.yMin),e.xMax=Math.max(e.xMax,t.xMax),e.yMax=Math.max(e.yMax,t.yMax)}function Di(e,t){return e.xMax<t.xMin||e.xMin>t.xMax||e.yMax<t.yMin||e.yMin>t.yMax}function Oi(e,t,n){return t<e.xMin||t>e.xMax||n<e.yMin||n>e.yMax}function ki(e){let t=Fr(e);for(;t.__bk2d===`trimmed`&&t.basis;)t=t.basis;return t.__bk2d===`circle`?{cx:t.cx,cy:t.cy,radius:t.radius,isDirect:t.sense!==!1}:null}function Ai(e){let t=Fr(e);for(;t.__bk2d===`trimmed`&&t.basis;)t=t.basis;return t.__bk2d===`ellipse`?{majorRadius:t.majorRadius,minorRadius:t.minorRadius,xAxisAngle:t.xDirAngle??0,isDirect:t.sense!==!1}:null}function ji(e){let t=Fr(e);for(;t.__bk2d===`trimmed`&&t.basis;)t=t.basis;return t.__bk2d===`bezier`&&Array.isArray(t.poles)?t.poles:null}function Mi(e){let t=Fr(e);for(;t.__bk2d===`trimmed`&&t.basis;)t=t.basis;return t.__bk2d===`bezier`&&Array.isArray(t.poles)?t.poles.length-1:null}function Ni(e){return fe(Fr(e))}function Pi(e){return Ir(pe(e))}function Fi(e,t){let n=_(Fr(e)),r=[n.first,...t.sort((e,t)=>e-t),n.last],i=[];for(let t=0;t<r.length-1;t++){let a=r[t]??n.first,o=r[t+1]??n.last;i.push(ei(e,a,o))}return i}function Ii(e,t,n,r,i,a){let o=Fr(n),[s,c,l]=r,[u,d,f]=i,[p,m,g]=a,v=d*g-f*m,y=f*p-u*g,b=u*m-d*p,x=(e,t)=>[s+e*p+t*v,c+e*m+t*y,l+e*g+t*b],S=o.__bk2d;if(S===`line`){let t=_(o),[n,r]=h(o,t.first),[i,a]=h(o,t.last),s=x(n,r),c=x(i,a);return T(`edge`,e.makeLineEdge(s[0],s[1],s[2],c[0],c[1],c[2]))}if(S===`trimmed`){let t=o;if(t.basis&&t.basis.__bk2d===`line`){let[t,n]=h(o,0),[r,i]=h(o,1),a=x(t,n),s=x(r,i);return T(`edge`,e.makeLineEdge(a[0],a[1],a[2],s[0],s[1],s[2]))}if(t.basis&&t.basis.__bk2d===`circle`){let t=_(o),[n,r]=h(o,t.first),[i,a]=h(o,(t.first+t.last)/2),[s,c]=h(o,t.last),l=x(n,r),u=x(i,a),d=x(s,c);return T(`edge`,e.makeArcEdge(l[0],l[1],l[2],u[0],u[1],u[2],d[0],d[1],d[2]))}}if(S===`circle`){let t=o;if(t.cx!==void 0&&t.radius!==void 0){let[n,r,i]=x(t.cx,t.cy);return T(`edge`,e.makeCircleEdge(n,r,i,u,d,f,t.radius))}let n=_(o),[r,i]=h(o,n.first),[a,s]=h(o,(n.first+n.last)/2),[c,l]=h(o,n.last),p=x(r,i),m=x(a,s),g=x(c,l);return T(`edge`,e.makeArcEdge(p[0],p[1],p[2],m[0],m[1],m[2],g[0],g[1],g[2]))}let C=_(o),w=(C.last-C.first)/24,ee=[];for(let e=0;e<=24;e++){let[t,n]=h(o,C.first+e*w),[r,i,a]=x(t,n);ee.push(r,i,a)}let te=new t.VectorDouble;for(let e of ee)te.push_back(e);try{return T(`edge`,e.interpolatePoints(te,!1))}finally{te.delete()}}function Li(e,t,n,r){let i=Fr(n),a=_(i),o=E(r),s=new t.VectorDouble;for(let t=0;t<=30;t++){let[n,r]=h(i,a.first+(a.last-a.first)*t/30),c=e.pointOnSurface(o,n,r);try{s.push_back(c.get(0)),s.push_back(c.get(1)),s.push_back(c.get(2))}finally{c.delete()}}try{return T(`edge`,e.interpolatePoints(s,!1))}finally{s.delete()}}function Ri(e){return e}function zi(){return Ir(y(0,0,1,0))}function Bi(e,t){e.buildCurves3d(E(t))}function Vi(e,t,n,r){return T(`wire`,e.fixWireOnFace(E(t),E(n),r))}function Hi(e){try{let t=we(e.modified),n=we(e.generated),r=we(e.deleted),i=e=>{let t=new Map,n=0;for(;n+1<e.length;){let r=e[n]??0,i=e[n+1]??0;n+=2;let a=[];for(let t=0;t<i&&n<e.length;t++,n++)a.push(e[n]??0);t.set(r,a)}return t};return{id:e.resultId,evolution:{modified:i(t),generated:i(n),deleted:new Set(r)}}}finally{e.delete()}}function Ui(e,t,n,r,i,a,o,s){let c=Se(t,o);try{let{id:t,evolution:o}=Hi(e.translateWithHistory(E(n),r,i,a,c,s));return{shape:D(e,t),evolution:o}}finally{c.delete()}}function Wi(e,t,n,r,i,a,o,s){let c=o??[0,0,1],l=s??[0,0,0],u=Se(t,i);try{let{id:t,evolution:i}=Hi(e.rotateWithHistory(E(n),l[0],l[1],l[2],c[0],c[1],c[2],r,u,a));return{shape:D(e,t),evolution:i}}finally{u.delete()}}function Gi(e,t,n,r,i,a,o){let s=Se(t,a);try{let{id:t,evolution:a}=Hi(e.mirrorWithHistory(E(n),r[0],r[1],r[2],i[0],i[1],i[2],s,o));return{shape:D(e,t),evolution:a}}finally{s.delete()}}function Ki(e,t,n,r,i,a,o){let s=Se(t,a);try{let{id:t,evolution:a}=Hi(e.scaleWithHistory(E(n),r[0],r[1],r[2],i,s,o));return{shape:D(e,t),evolution:a}}finally{s.delete()}}function qi(e,t,n,r,i,a){let o=e(t,n,r,i),s=new Map;for(let e of a)s.set(e,[e]);return{shape:o,evolution:{modified:s,generated:new Map,deleted:new Set}}}function Ji(e,t,n,r,i,a,o){let s=Se(t,i);try{let{id:t,evolution:i}=Hi(e.fuseWithHistory(E(n),E(r),s,a));return{shape:D(e,t),evolution:i,diagnostics:{hasErrors:!1,hasWarnings:!1,messages:[]}}}finally{s.delete()}}function Yi(e,t,n,r,i,a,o){let s=Se(t,i);try{let{id:t,evolution:i}=Hi(e.cutWithHistory(E(n),Ae(e,r),s,a));return{shape:D(e,t),evolution:i,diagnostics:{hasErrors:!1,hasWarnings:!1,messages:[]}}}finally{s.delete()}}function Xi(e,t,n,r,i,a,o){let s=Se(t,i);try{let{id:t,evolution:i}=Hi(e.intersectWithHistory(E(n),Ae(e,r),s,a));return{shape:D(e,t),evolution:i,diagnostics:{hasErrors:!1,hasWarnings:!1,messages:[]}}}finally{s.delete()}}function Zi(e,t,n,r,i,a,o){let s=Ee(r,i),c=xe(t,r.map(E)),l=Se(t,a);try{let{id:t,evolution:r}=Hi(e.filletWithHistory(E(n),c,s,l,o));return{shape:D(e,t),evolution:r}}finally{c.delete(),l.delete()}}function Qi(e,t,n,r,i,a,o){let s=Ee(r,i),c=xe(t,r.map(E)),l=Se(t,a);try{let{id:t,evolution:r}=Hi(e.chamferWithHistory(E(n),c,s,l,o));return{shape:D(e,t),evolution:r}}finally{c.delete(),l.delete()}}function $i(e,t,n,r,i,a,o,s){let c=xe(t,r.map(E)),l=Se(t,a);try{let{id:t,evolution:r}=Hi(e.shellWithHistory(E(n),c,i,s??.001,l,o));return{shape:D(e,t),evolution:r}}finally{c.delete(),l.delete()}}function ea(e,t,n,r,i,a){let o=Se(t,i);try{let{id:t,evolution:i}=Hi(e.thickenWithHistory(E(n),r,.001,o,a));return{shape:D(e,t),evolution:i}}finally{o.delete()}}function ta(e,t,n,r,i,a,o){let s=Se(t,i);try{let{id:t,evolution:i}=Hi(e.offsetWithHistory(E(n),r,o??1e-6,s,a));return{shape:D(e,t),evolution:i}}finally{s.delete()}}function na(e,t,n,r,i){let[a,o,s]=r,c=E(t);for(let t of n){let n=(typeof i==`number`?i:i(t))*Math.PI/180;c=e.draft(c,E(t),n,a,o,s)}return{shape:D(e,c),evolution:{modified:new Map,generated:new Map,deleted:new Set}}}function ra(e,t,n,r,i,a,o){let s=e(r,i),c=t(s,`face`),l=new Map,u=Math.min(a.length,c.length);for(let e=0;e<u;e++){let t=c[e],r=a[e];t!==void 0&&r!==void 0&&l.set(r,[n(t,o)])}return{shape:s,evolution:{modified:l,generated:new Map,deleted:new Set}}}function ia(e,t,n,r){if(n.length<4)throw Error(`hullFromPoints: need at least 4 points`);let{points:i,faces:a}=m(n,r);if(a.length<4)throw Error(`hullFromPoints: degenerate hull (fewer than 4 faces)`);return br(e,t,[...i],[...a],r)}function aa(e,t,n,r){let i=Math.max(r,1),a=[];for(let r of n){let n=e.tessellate(E(r),i,i*.5);try{let e=n.positionCount,r=n.getPositionsPtr()>>2;for(let n=0;n<e;n+=3)a.push({x:t.HEAPF32[r+n]??0,y:t.HEAPF32[r+n+1]??0,z:t.HEAPF32[r+n+2]??0})}finally{n.delete()}}return a}function oa(e,t,n,r){if(n.length===0)throw Error(`hull: no shapes provided`);let i=aa(e,t,n,r);if(i.length<4)throw Error(`hull: fewer than 4 vertices extracted from input shapes`);return ia(e,t,i,r)}function sa(e){throw Error(`occt-wasm: ${e} is not yet implemented`)}var ca=class e{oc;kernelId=`occt-wasm`;Module;k;owner;constructor(e,t,n){this.Module=e,this.k=Oe(t,e),this.oc=ke(e,this.k),this.owner=n}static fromKernel(t){return new e(t.getRawModule(),t.getRawKernel(),t)}get retainedKernelOwner(){return this.owner}dispose(e){ye(e)?this.k.release(e.id):typeof e.delete==`function`&&e.delete()}executeBatch(e){sa(`executeBatch`)}checkpoint(){sa(`checkpoint`)}checkpointCount(){sa(`checkpointCount`)}restoreCheckpoint(e){sa(`restoreCheckpoint`)}discardCheckpoint(e){sa(`discardCheckpoint`)}makeBox(e,t,n){return Be(this.k,e,t,n)}makeCylinder(e,t,n,r){return Ve(this.k,e,t,n,r)}makeSphere(e,t){return He(this.k,e,t)}makeCone(e,t,n,r,i){return Ue(this.k,e,t,n,r,i)}makeTorus(e,t,n,r){return We(this.k,e,t,n,r)}makeEllipsoid(e,t,n){return Ge(this.k,e,t,n)}makeBoxFromCorners(e,t){return Ke(this.k,e,t)}makeRectangle(e,t){return qe(this.k,e,t)}fuse(e,t,n){return je(this.k,e,t,n)}cut(e,t,n){return Me(this.k,e,t,n)}intersect(e,t,n){return Ne(this.k,e,t,n)}section(e,t,n){return Pe(this.k,e,t,n)}fuseAll(e,t){return Fe(this.k,this.Module,e,t)}cutAll(e,t,n){return Ie(this.k,this.Module,e,t,n)}split(e,t){return Le(this.k,this.Module,e,t)}checkBoolean(e,t,n){return Re(this.k,e,t,n)}meshBoolean(e,t,n,r,i,a){return ze(e,t,n,r,i,a)}makeVertex(e,t,n){return ir(this.k,e,t,n)}makeEdge(e,t,n){return ar(this.k,e)}makeWire(e){return or(this.k,this.Module,e)}makeFace(e,t){return cr(this.k,e,t)}makeLineEdge(e,t){return lr(this.k,e,t)}makeCircleEdge(e,t,n){return ur(this.k,e,t,n)}makeCircleArc(e,t,n,r,i){return dr(this.k,e,t,n,r,i)}makeArcEdge(e,t,n){return fr(this.k,e,t,n)}makeEllipseEdge(e,t,n,r,i){return pr(this.k,e,t,n,r)}makeEllipseArc(e,t,n,r,i,a,o){return mr(this.k,e,t,n,r,i,a)}makeBezierEdge(e){return hr(this.k,this.Module,e)}makeTangentArc(e,t,n){return gr(this.k,e,t,n)}makeHelixWire(e,t,n,r,i,a){return _r(this.k,e,t,n,r,i)}makeWireFromMixed(e){return sr(this.k,this.Module,e)}makeCompound(e){return vr(this.k,this.Module,e)}solidFromShell(e){return yr(this.k,e)}hull(e,t){return oa(this.k,this.Module,e,t)}hullFromPoints(e,t){return ia(this.k,this.Module,e,t)}buildSolidFromFaces(e,t,n){return br(this.k,this.Module,e,t,n)}makeNonPlanarFace(e){return xr(this.k,e)}addHolesInFace(e,t){return Sr(this.k,this.Module,e,t)}removeHolesFromFace(e){return Cr(this.k,this.Module,e)}makeFaceOnSurface(e,t){return wr(this.k,e,t)}bsplineSurface(e,t,n){return Tr(this.k,this.Module,e,t,n)}triangulatedSurface(e,t,n){return Er(this.k,this.Module,e,t,n)}buildTriFace(e,t,n){return Dr(this.k,e,t,n)}sewAndSolidify(e,t){return Or(this.k,this.Module,e,t)}createPoint3d(e,t,n){return kr(e,t,n)}createDirection3d(e,t,n){return Ar(e,t,n)}createVector3d(e,t,n){return jr(e,t,n)}createAxis1(e,t,n,r,i,a){return Mr(e,t,n,r,i,a)}createAxis2(e,t,n,r,i,a,o,s,c){return Nr(e,t,n,r,i,a,o,s,c)}createAxis3(e,t,n,r,i,a,o,s,c){return Pr(e,t,n,r,i,a,o,s,c)}extrude(e,t,n){return yn(this.k,e,t,n)}revolve(e,t,n){return bn(this.k,e,t,n)}loft(e,t,n,r){return xn(this.k,this.Module,e,t,n,r)}sweep(e,t,n){return Sn(this.k,e,t,n)}simplePipe(e,t){return Cn(this.k,e,t)}helicalSweep(e,t,n,r,i,a){throw Error(`helicalSweep on occt-wasm requires profile positioning+orientation logic not yet implemented; brepkit has a native implementation`)}sweepWithOptions(e,t,n,r,i){sa(`sweepWithOptions`)}sweepPipeShell(e,t,n){return wn(this.k,e,t,n)}loftAdvanced(e,t){return Tn(this.k,this.Module,e,t)}buildExtrusionLaw(e,t,n){return En(this.k,e,t,n)}revolveVec(e,t,n,r){return Dn(this.k,e,t,n,r)}draftPrism(e,t,n,r,i,a){return On(this.k,e,t,n,r,i,a)}fillet(e,t,n){return sn(this.k,this.Module,e,t,n)}chamfer(e,t,n){return cn(this.k,this.Module,e,t,n)}chamferDistAngle(e,t,n,r){return ln(this.k,this.Module,e,t,n,r)}shell(e,t,n,r){return un(this.k,this.Module,e,t,n,r)}thicken(e,t){return dn(this.k,e,t)}offset(e,t,n){return fn(this.k,e,t,n)}filletVariable(e,t){return pn(this.k,e,t)}draft(e,t,n,r,i){return mn(this.k,e,t,n,r,i)}defeature(e,t){return hn(this.k,this.Module,e,t)}offsetWire2D(e,t,n){return gn(this.k,e,t,n)}simplify(e){return _n(this.k,e)}reverseShape(e){return vn(this.k,e)}composeTransform(e){return kn(e)}transform(e,t){return An(this.k,this.Module,e,t)}translate(e,t,n,r){return jn(this.k,e,t,n,r)}rotate(e,t,n,r){return Mn(this.k,e,t,n,r)}mirror(e,t,n){return Nn(this.k,e,t,n)}scale(e,t,n){return Pn(this.k,e,t,n)}generalTransform(e,t,n,r){return Fn(this.k,this.Module,e,t,n,r)}generalTransformNonOrthogonal(e,t,n){return Fn(this.k,this.Module,e,t,n,!1)}positionOnCurve(e,t,n){return In(this.k,this.Module,e,t,n)}linearPattern(e,t,n,r){return Ln(this.k,e,t,n,r)}circularPattern(e,t,n,r,i){return Rn(this.k,e,t,n,r,i)}transformBatch(e){return zn(this.k,e)}translateWithHistory(e,t,n,r,i,a){return Ui(this.k,this.Module,e,t,n,r,i,a)}rotateWithHistory(e,t,n,r,i,a){return Wi(this.k,this.Module,e,t,n,r,i,a)}mirrorWithHistory(e,t,n,r,i){return Gi(this.k,this.Module,e,t,n,r,i)}scaleWithHistory(e,t,n,r,i){return Ki(this.k,this.Module,e,t,n,r,i)}generalTransformWithHistory(e,t,n,r,i,a){return qi((e,t,n,r)=>this.generalTransform(e,t,n,r),e,t,n,r,i)}fuseWithHistory(e,t,n,r,i){return Ji(this.k,this.Module,e,t,n,r,i)}cutWithHistory(e,t,n,r,i){return Yi(this.k,this.Module,e,t,n,r,i)}intersectWithHistory(e,t,n,r,i){return Xi(this.k,this.Module,e,t,n,r,i)}filletWithHistory(e,t,n,r,i){return Zi(this.k,this.Module,e,t,n,r,i)}chamferWithHistory(e,t,n,r,i){return Qi(this.k,this.Module,e,t,n,r,i)}shellWithHistory(e,t,n,r,i,a){return $i(this.k,this.Module,e,t,n,r,i,a)}thickenWithHistory(e,t,n,r){return ea(this.k,this.Module,e,t,n,r)}offsetWithHistory(e,t,n,r,i){return ta(this.k,this.Module,e,t,n,r,i)}draftWithHistory(e,t,n,r,i,a,o){return na(this.k,e,t,n,i)}applyComposedTransformWithHistory(e,t,n,r){return ra((e,t)=>this.transform(e,t),(e,t)=>this.iterShapes(e,t),(e,t)=>this.hashCode(e,t),e,t,n,r)}mesh(e,t){return ht(this.k,this.Module,e,t)}meshEdges(e,t,n){return _t(this.k,this.Module,e,t,n)}hasTriangulation(e){return vt(this.k,e)}meshShape(e,t,n){yt(this.k,e,t,n)}exportSTEP(e){return Hn(this.k,this.makeCompound.bind(this),e)}exportSTL(e,t,n,r){return Un(this.k,this.mesh.bind(this),e,t,n,r)}importSTEP(e){return Gn(this.k,e)}importSTL(e){return Kn(this.k,this.Module,e)}exportIGES(e){return qn(this.k,this.makeCompound.bind(this),e)}importIGES(e){return Jn(this.k,e)}exportSTEPAssembly(e,t){return Yn(this.k,this.Module,e,t)}export3MF(e,t){throw Error(`export3MF is only available with the brepkit kernel`)}exportGLB(e,t){return Xn(this.mesh.bind(this),e,t)}exportOBJ(e,t){return Zn(this.mesh.bind(this),e,t)}exportPLY(e,t){return Qn(this.mesh.bind(this),e,t)}import3MF(e){throw Error(`import3MF is only available with the brepkit kernel`)}importOBJ(e){throw Error(`importOBJ is only available with the brepkit kernel`)}importGLB(e){throw Error(`importGLB is only available with the brepkit kernel`)}toBREP(e){return $n(this.k,e)}fromBREP(e){return er(this.k,e)}createXCAFDocument(e){return tr(this.k,this.Module,e)}writeXCAFToSTEP(e,t){return nr(this.k,e,t)}exportSTEPConfigured(e,t){return rr(this.k,this.Module,e,t)}volume(e){return Vt(this.k,e)}area(e){return Ht(this.k,e)}length(e){return Ut(this.k,e)}centerOfMass(e){return Wt(this.k,e)}linearCenterOfMass(e){return Gt(this.k,e)}boundingBox(e){return Kt(this.k,e)}distance(e,t){return Qt(this.k,this.Module,e,t)}surfaceCurvature(e,t,n){return on(this.k,e,t,n)}surfaceCenterOfMass(e){return qt(this.k,e)}measureBulk(e,t){return Jt(this.k,e,t)}createDistanceQuery(e){return Yt(this.k,e)}iterShapes(e,t){return Je(this.k,e,t)}iterShapeList(e,t){throw Error(`iterShapeList is not applicable to occt-wasm: the arena model has no TopTools_ListOfShape handles`)}shapeType(e){return Ye(this.k,e)}isSame(e,t){return Xe(this.k,e,t)}isEqual(e,t){return Ze(this.k,e,t)}downcast(e,t){return Qe(this.k,e,t)}hashCode(e,t){return $e(this.k,e,t)}isNull(e){return et(this.k,e)}shapeOrientation(e){return tt(this.k,e)}edgeToFaceMap(e){return nt(this.k,e)}sharedEdges(e,t){return rt(this.k,e,t)}adjacentFaces(e,t){return it(this.k,e,t)}sew(e,t){return at(this.k,this.Module,e,t)}curveType(e){return xt(this.k,e)}curveParameters(e){return St(this.k,e)}curvePointAtParam(e,t){return Ct(this.k,e,t)}curveTangent(e,t){return wt(this.k,e,t)}curveIsClosed(e){return Tt(this.k,e)}curveIsPeriodic(e){return Et(this.k,e)}curvePeriod(e){return Dt(this.k,e)}interpolatePoints(e,t){return Ot(this.k,this.Module,e,t)}approximatePoints(e,t){return kt(this.k,this.Module,e,t)}curveDegreeElevate(e,t){sa(`curveDegreeElevate`)}curveKnotInsert(e,t,n){sa(`curveKnotInsert`)}curveKnotRemove(e,t,n){sa(`curveKnotRemove`)}curveSplit(e,t){sa(`curveSplit`)}createCurveAdaptor(e){sa(`createCurveAdaptor`)}getBezierPenultimatePole(e){sa(`getBezierPenultimatePole`)}vertexPosition(e){return jt(this.k,e)}surfaceType(e){return Mt(this.k,e)}uvBounds(e){return Nt(this.k,e)}outerWire(e){return Pt(this.k,e)}surfaceNormal(e,t,n){return Ft(this.k,e,t,n)}pointOnSurface(e,t,n){return It(this.k,e,t,n)}uvFromPoint(e,t){return Lt(this.k,e,t)}projectPointOnFace(e,t){return Rt(this.k,e,t)}classifyPointOnFace(e,t,n,r){return zt(this.k,e,t,n,r)}classifyPointRobust(e,t,n){sa(`classifyPointRobust`)}classifyPointWinding(e,t,n){sa(`classifyPointWinding`)}approximateSurfaceLspia(e,t,n,r,i,a,o,s,c){sa(`approximateSurfaceLspia`)}untrimFace(e,t,n){sa(`untrimFace`)}getSurfaceCylinderData(e){sa(`getSurfaceCylinderData`)}reverseSurfaceU(e){sa(`reverseSurfaceU`)}detectSmallFeatures(e,t,n){sa(`detectSmallFeatures`)}recognizeFeatures(e,t){sa(`recognizeFeatures`)}projectEdges(e,t,n,r){return Bt(this.k,this.Module,e,t,n,r)}isValid(e){return st(this.k,e)}healSolid(e){return ct(this.k,e)}healFace(e){return lt(this.k,e)}healWire(e,t){return ut(this.k,e,t)}mergeCoincidentVertices(e,t){return dt(this.k,e,t)}removeDegenerateEdges(e,t){return ft(this.k,e,t)}fixFaceOrientations(e){return pt(this.k,e)}fixShape(e){return mt(this.k,e)}fixSelfIntersection(e){sa(`fixSelfIntersection`)}createPoint2d(e,t){return Lr(e,t)}createDirection2d(e,t){return Rr(e,t)}createVector2d(e,t){return zr(e,t)}createAxis2d(e,t,n,r){return Br(e,t,n,r)}wrapCurve2dHandle(e){return Vr(e)}createCurve2dAdaptor(e){sa(`createCurve2dAdaptor`)}makeLine2d(e,t,n,r){return Hr(e,t,n,r)}makeCircle2d(e,t,n,r){return Ur(e,t,n,r)}makeArc2dThreePoints(e,t,n,r,i,a){return Wr(e,t,n,r,i,a)}makeArc2dTangent(e,t,n,r,i,a){return Gr(e,t,n,r,i,a)}makeEllipse2d(e,t,n,r,i,a,o){return Kr(e,t,n,r,i,a,o)}makeEllipseArc2d(e,t,n,r,i,a,o,s,c){return qr(e,t,n,r,i,a,o,s,c)}makeBezier2d(e){return Jr(e)}makeBSpline2d(e,t){return Yr(e)}evaluateCurve2d(e,t){return Xr(e,t)}evaluateCurve2dD1(e,t){return Zr(e,t)}getCurve2dBounds(e){return Qr(e)}getCurve2dType(e){return $r(e)}trimCurve2d(e,t,n){return ei(e,t,n)}reverseCurve2d(e){}copyCurve2d(e){return ti(e)}offsetCurve2d(e,t){return ni(e,t)}translateCurve2d(e,t,n){return ri(e,t,n)}rotateCurve2d(e,t,n,r){return ii(e,t,n,r)}scaleCurve2d(e,t,n,r){return ai(e,t,n,r)}mirrorCurve2dAtPoint(e,t,n){return oi(e,t,n)}mirrorCurve2dAcrossAxis(e,t,n,r,i){return si(e,t,n,r,i)}affinityTransform2d(e,t,n,r,i,a){return ci(e)}createIdentityGTrsf2d(){return li()}createAffinityGTrsf2d(e,t,n,r,i){return ui(e,t,n,r,i)}createTranslationGTrsf2d(e,t){return di(e,t)}createMirrorGTrsf2d(e,t,n,r,i,a,o){return fi(e,t,n,r,i,a,o)}createRotationGTrsf2d(e,t,n){return pi(e,t,n)}createScaleGTrsf2d(e,t,n){return mi(e,t,n)}setGTrsf2dTranslationPart(e,t,n){hi(e,t,n)}multiplyGTrsf2d(e,t){gi(e,t)}transformCurve2dGeneral(e,t){return _i(e,t)}intersectCurves2d(e,t,n){return vi(e,t,n)}projectPointOnCurve2d(e,t,n){return yi(e,t,n)}distanceBetweenCurves2d(e,t,n,r,i,a){return bi(e,t,n,r,i,a)}approximateCurve2dAsBSpline(e,t,n,r){return xi(e,r)}decomposeBSpline2dToBeziers(e){return Si(e)}createBoundingBox2d(){return Ci()}addCurveToBBox2d(e,t,n){wi(e,t,n)}getBBox2dBounds(e){return Ti(e)}mergeBBox2d(e,t){Ei(e,t)}isBBox2dOut(e,t){return Di(e,t)}isBBox2dOutPoint(e,t,n){return Oi(e,t,n)}getCurve2dCircleData(e){return ki(e)}getCurve2dEllipseData(e){return Ai(e)}getCurve2dBezierPoles(e){return ji(e)}getCurve2dBezierDegree(e){return Mi(e)}getCurve2dBSplineData(e){sa(`getCurve2dBSplineData`)}serializeCurve2d(e){return Ni(e)}deserializeCurve2d(e){return Pi(e)}splitCurve2d(e,t){return Fi(e,t)}liftCurve2dToPlane(e,t,n,r){return Ii(this.k,this.Module,e,t,n,r)}buildEdgeOnSurface(e,t){return Li(this.k,this.Module,e,t)}extractSurfaceFromFace(e){return Ri(e)}extractCurve2dFromEdge(e,t){return zi()}buildCurves3d(e){Bi(this.k,e)}fixWireOnFace(e,t,n){return Vi(this.k,e,t,n)}fillSurface(e,t){sa(`fillSurface`)}getNurbsCurveData(e){return At(this.k,e)}};function O(e){return{ok:!0,value:e}}function k(e){return{ok:!1,error:e}}var la=O(void 0);function ua(e){return e.ok}function A(e){return!e.ok}function da(e,t){return e.ok?O(t(e.value)):e}function fa(e,t){return e.ok?e:k(t(e.error))}function pa(e,t){return e.ok?t(e.value):e}var ma=pa;function ha(e,t){return e.ok?e:t}function ga(e,t){return e.ok?e:t(e.error)}function _a(e,t){return e.ok?t.ok?O([e.value,t.value]):t:e}var va=ka;function ya(e,t){return e.ok&&t(e.value),e}function ba(e,t){return e.ok||t(e.error),e}function xa(e){return e.ok?e.value:e}function Sa(e,t,n){return e.ok?O(t(e.value)):k(n(e.error))}function Ca(e,t){return e==null?k(t()):O(e)}function wa(e){if(typeof e==`object`&&e&&`kind`in e&&`code`in e&&`message`in e){let t=e;return`[${t.kind}] ${t.code}: ${t.message}`}return String(e)}function j(e){if(e.ok)return e.value;throw Error(`Called unwrap() on an Err: ${wa(e.error)}`)}function Ta(e,t){return e.ok?e.value:t}function Ea(e,t){return e.ok?e.value:t(e.error)}function Da(e){if(!e.ok)return e.error;throw Error(`Called unwrapErr() on an Ok: ${String(e.value)}`)}function Oa(e,t){return e.ok?t.ok(e.value):t.err(e.error)}function ka(e){let t=[];for(let n of e){if(!n.ok)return n;t.push(n.value)}return O(t)}function Aa(e,t){try{return O(e())}catch(e){return k(t(e))}}async function ja(e,t){try{return O(await e())}catch(e){return k(t(e))}}function Ma(e){function t(e){return typeof e==`object`&&!!e&&`ok`in e&&typeof e.ok==`boolean`}let n=t(e)?e:O(e);function r(e){return{then(t){return e.ok?r(t(e.value)):r(e)},get result(){return e}}}return r(n)}var Na=class extends Error{location;constructor(e,t){super(`Bug in ${e}: ${t}`),this.name=`BrepBugError`,this.location=e}};function M(e,t){throw new Na(e,t)}var Pa=[{pattern:/invalid edge configuration|edges?.*(not|fail|invalid)/i,translation:`The edges may not form a continuous loop. Check that edges connect end-to-end without gaps.`},{pattern:/BRepAlgoAPI.*failed|boolean.*operation.*failed/i,translation:`Boolean operation failed. Common causes: overlapping faces, zero-thickness geometry, or degenerate shapes. Try healing input shapes first.`},{pattern:/fillet.*radius.*too.*large|fillet.*failed/i,translation:`Fillet operation failed. The radius may be too large for the selected edges. Try reducing the radius or check that edges have enough room.`},{pattern:/chamfer.*failed|chamfer.*distance.*too.*large/i,translation:`Chamfer operation failed. The distance may be too large for the selected edges. Try reducing the distance or check edge geometry.`},{pattern:/shell.*failed|offset.*failed/i,translation:`Shell/offset operation failed. The thickness may be too large, or the shape may have complex geometry. Try reducing thickness.`},{pattern:/sweep.*failed|pipe.*failed/i,translation:`Sweep operation failed. Check that the profile and spine are compatible, and that the spine has no sharp twists or self-intersections.`},{pattern:/loft.*failed/i,translation:`Loft operation failed. Profiles may be incompatible or have different orientations. Ensure profiles are ordered consistently.`},{pattern:/extrude.*failed|prism.*failed/i,translation:`Extrusion failed. The profile may be invalid or self-intersecting. Check that the profile forms a valid closed wire.`},{pattern:/revolve.*failed|revolution.*failed/i,translation:`Revolution operation failed. The profile may intersect the axis of revolution, or the angle may be invalid.`},{pattern:/self.*intersect|self-intersect/i,translation:`Shape has self-intersections. The operation resulted in overlapping geometry. Simplify the input or adjust parameters.`},{pattern:/degener|degenerat/i,translation:`Degenerate geometry detected. The shape has edges or faces with zero length/area. Check input geometry for collapsed elements.`},{pattern:/BRepCheck.*fail|shape.*invalid|shape.*not.*valid/i,translation:`Shape validation failed. The resulting shape has invalid topology. Try healing the shape or checking input geometry.`}],Fa={FUSE_FAILED:`Try autoHeal() on both operands before the boolean operation. Check for overlapping faces or zero-thickness geometry.`,CUT_FAILED:`Try autoHeal() on both operands before the boolean operation. Check for overlapping faces or zero-thickness geometry.`,FUSE_NOT_3D:`The boolean result was not a 3D solid. Ensure both input shapes are valid 3D solids, not shells or open surfaces.`,CUT_NOT_3D:`The boolean result was not a 3D solid. Ensure both input shapes are valid 3D solids, not shells or open surfaces.`,INTERSECT_NOT_3D:`The boolean result was not a 3D solid. Ensure both input shapes are valid 3D solids, not shells or open surfaces.`,SWEEP_FAILED:`Ensure the spine curve has no sharp corners or self-intersections. Try simplifying the profile or using a smoother path.`,LOFT_FAILED:`Check that all profiles have the same number of edges and consistent orientation. Try reordering profiles.`,FILLET_NOT_3D:`The fillet radius may be too large for the selected edges. Try a smaller radius or check that adjacent faces have enough room.`,CHAMFER_NOT_3D:`The chamfer distance may be too large. Try a smaller distance or check edge geometry.`,SHELL_NOT_3D:`The shell thickness may be too large for the shape. Try reducing thickness or removing problematic faces.`,OFFSET_NOT_3D:`The offset distance may be too large for the shape geometry. Try a smaller distance.`,DRAFT_FAILED:`The draft angle may be too large or the selected faces incompatible. Try a smaller angle or different faces.`};function Ia(e){return Fa[e]}function La(e){for(let{pattern:t,translation:n}of Pa)if(t.test(e))return`${n} (kernel: ${e})`;return e}var N={BSPLINE_FAILED:`BSPLINE_FAILED`,FACE_BUILD_FAILED:`FACE_BUILD_FAILED`,SWEEP_FAILED:`SWEEP_FAILED`,LOFT_FAILED:`LOFT_FAILED`,FUSE_FAILED:`FUSE_FAILED`,CUT_FAILED:`CUT_FAILED`,HEAL_NO_EFFECT:`HEAL_NO_EFFECT`,BOOLEAN_HAS_ERRORS:`BOOLEAN_HAS_ERRORS`,VARIABLE_FILLET_FAILED:`VARIABLE_FILLET_FAILED`,POSITION_ON_CURVE_FAILED:`POSITION_ON_CURVE_FAILED`,FIX_SHAPE_FAILED:`FIX_SHAPE_FAILED`,SOLID_FROM_SHELL_FAILED:`SOLID_FROM_SHELL_FAILED`,FIX_SELF_INTERSECTION_FAILED:`FIX_SELF_INTERSECTION_FAILED`,ELLIPSE_RADII:`ELLIPSE_RADII`,FUSE_ALL_EMPTY:`FUSE_ALL_EMPTY`,FILLET_NO_EDGES:`FILLET_NO_EDGES`,CHAMFER_NO_EDGES:`CHAMFER_NO_EDGES`,CHAMFER_ANGLE_NO_EDGES:`CHAMFER_ANGLE_NO_EDGES`,CHAMFER_ANGLE_BAD_DISTANCE:`CHAMFER_ANGLE_BAD_DISTANCE`,CHAMFER_ANGLE_BAD_ANGLE:`CHAMFER_ANGLE_BAD_ANGLE`,BEZIER_MIN_POINTS:`BEZIER_MIN_POINTS`,POLYGON_MIN_POINTS:`POLYGON_MIN_POINTS`,ZERO_LENGTH_EXTRUSION:`ZERO_LENGTH_EXTRUSION`,ZERO_TWIST_ANGLE:`ZERO_TWIST_ANGLE`,LOFT_EMPTY:`LOFT_EMPTY`,UNSUPPORTED_PROFILE:`UNSUPPORTED_PROFILE`,UNKNOWN_PLANE:`UNKNOWN_PLANE`,NULL_SHAPE_INPUT:`NULL_SHAPE_INPUT`,INVALID_FILLET_RADIUS:`INVALID_FILLET_RADIUS`,INVALID_CHAMFER_DISTANCE:`INVALID_CHAMFER_DISTANCE`,INVALID_THICKNESS:`INVALID_THICKNESS`,ZERO_OFFSET:`ZERO_OFFSET`,NO_EDGES:`NO_EDGES`,NO_FACES:`NO_FACES`,DRAFT_NO_FACES:`DRAFT_NO_FACES`,DRAFT_INVALID_ANGLE:`DRAFT_INVALID_ANGLE`,DRAFT_NOT_3D:`DRAFT_NOT_3D`,DRAFT_FAILED:`DRAFT_FAILED`,FUSE_NOT_3D:`FUSE_NOT_3D`,CUT_NOT_3D:`CUT_NOT_3D`,INTERSECT_NOT_3D:`INTERSECT_NOT_3D`,FUSE_ALL_NOT_3D:`FUSE_ALL_NOT_3D`,CUT_ALL_NOT_3D:`CUT_ALL_NOT_3D`,LOFT_NOT_3D:`LOFT_NOT_3D`,SWEEP_NOT_3D:`SWEEP_NOT_3D`,REVOLUTION_NOT_3D:`REVOLUTION_NOT_3D`,FILLET_NOT_3D:`FILLET_NOT_3D`,CHAMFER_NOT_3D:`CHAMFER_NOT_3D`,CHAMFER_ANGLE_NOT_3D:`CHAMFER_ANGLE_NOT_3D`,CHAMFER_ANGLE_FAILED:`CHAMFER_ANGLE_FAILED`,CSG_NOT_3D:`CSG_NOT_3D`,SHELL_NOT_3D:`SHELL_NOT_3D`,OFFSET_NOT_3D:`OFFSET_NOT_3D`,NULL_SHAPE:`NULL_SHAPE`,NO_WRAPPER:`NO_WRAPPER`,WELD_NOT_SHELL:`WELD_NOT_SHELL`,SOLID_BUILD_FAILED:`SOLID_BUILD_FAILED`,OFFSET_NOT_WIRE:`OFFSET_NOT_WIRE`,UNKNOWN_SURFACE_TYPE:`UNKNOWN_SURFACE_TYPE`,UNKNOWN_CURVE_TYPE:`UNKNOWN_CURVE_TYPE`,SWEEP_START_NOT_WIRE:`SWEEP_START_NOT_WIRE`,SWEEP_END_NOT_WIRE:`SWEEP_END_NOT_WIRE`,STEP_EXPORT_FAILED:`STEP_EXPORT_FAILED`,STEP_EXPORT_CONFIGURED_FAILED:`STEP_EXPORT_CONFIGURED_FAILED`,STEP_FILE_READ_ERROR:`STEP_FILE_READ_ERROR`,STEP_EXPORT_CRASHED:`STEP_EXPORT_CRASHED`,STEP_EXPORT_UNSERIALIZABLE:`STEP_EXPORT_UNSERIALIZABLE`,STL_EXPORT_FAILED:`STL_EXPORT_FAILED`,STL_FILE_READ_ERROR:`STL_FILE_READ_ERROR`,STL_EXPORT_CRASHED:`STL_EXPORT_CRASHED`,STL_EXPORT_UNSERIALIZABLE:`STL_EXPORT_UNSERIALIZABLE`,STEP_IMPORT_FAILED:`STEP_IMPORT_FAILED`,STL_IMPORT_FAILED:`STL_IMPORT_FAILED`,IGES_EXPORT_FAILED:`IGES_EXPORT_FAILED`,IGES_IMPORT_FAILED:`IGES_IMPORT_FAILED`,DXF_IMPORT_FAILED:`DXF_IMPORT_FAILED`,OBJ_IMPORT_FAILED:`OBJ_IMPORT_FAILED`,THREEMF_IMPORT_FAILED:`THREEMF_IMPORT_FAILED`,PARAMETER_NOT_FOUND:`PARAMETER_NOT_FOUND`,INTERSECTION_FAILED:`INTERSECTION_FAILED`,SELF_INTERSECTION_FAILED:`SELF_INTERSECTION_FAILED`,STRAIGHT_SKELETON_FAILED:`STRAIGHT_SKELETON_FAILED`,CENTER_OF_MASS_FAILED:`CENTER_OF_MASS_FAILED`,COMPOUND_NO_FACES:`COMPOUND_NO_FACES`,COMPOUND_FACE_NOT_FOUND:`COMPOUND_FACE_NOT_FOUND`,FINDER_NOT_UNIQUE:`FINDER_NOT_UNIQUE`,HULL_EMPTY_INPUT:`HULL_EMPTY_INPUT`,HULL_FAILED:`HULL_FAILED`,HULL_DEGENERATE:`HULL_DEGENERATE`,HULL_NOT_3D:`HULL_NOT_3D`,MINKOWSKI_FAILED:`MINKOWSKI_FAILED`,MINKOWSKI_NULL_TOOL:`MINKOWSKI_NULL_TOOL`,MINKOWSKI_NOT_3D:`MINKOWSKI_NOT_3D`,POLYHEDRON_INSUFFICIENT_POINTS:`POLYHEDRON_INSUFFICIENT_POINTS`,POLYHEDRON_INSUFFICIENT_FACES:`POLYHEDRON_INSUFFICIENT_FACES`,POLYHEDRON_INVALID_INDEX:`POLYHEDRON_INVALID_INDEX`,POLYHEDRON_FAILED:`POLYHEDRON_FAILED`,VALIDATION_FAILED:`VALIDATION_FAILED`,ROOF_FAILED:`ROOF_FAILED`,MULTI_SWEEP_INSUFFICIENT_SECTIONS:`MULTI_SWEEP_INSUFFICIENT_SECTIONS`,MULTI_SWEEP_FAILED:`MULTI_SWEEP_FAILED`,GUIDED_SWEEP_FAILED:`GUIDED_SWEEP_FAILED`,SURFACE_GRID_TOO_SMALL:`SURFACE_GRID_TOO_SMALL`,SURFACE_GRID_JAGGED:`SURFACE_GRID_JAGGED`,SURFACE_FAILED:`SURFACE_FAILED`,ASSEMBLY_MATE_INVALID:`ASSEMBLY_MATE_INVALID`,ASSEMBLY_SOLVE_FAILED:`ASSEMBLY_SOLVE_FAILED`,ASSEMBLY_NOT_CONVERGED:`ASSEMBLY_NOT_CONVERGED`,BLUEPRINT_EMPTY_CURVES:`BLUEPRINT_EMPTY_CURVES`,COMPOUND_BLUEPRINT_EMPTY:`COMPOUND_BLUEPRINT_EMPTY`,GLB_IMPORT_FAILED:`GLB_IMPORT_FAILED`,FONT_FETCH_FAILED:`FONT_FETCH_FAILED`,FONT_PARSE_FAILED:`FONT_PARSE_FAILED`,NO_FONT_LOADED:`NO_FONT_LOADED`,CURVE2D_CONSTRUCTION_FAILED:`CURVE2D_CONSTRUCTION_FAILED`,CURVE2D_INVALID_RADIUS:`CURVE2D_INVALID_RADIUS`,CURVE2D_TRANSFORM_FAILED:`CURVE2D_TRANSFORM_FAILED`,CURVE2D_QUERY_FAILED:`CURVE2D_QUERY_FAILED`,CURVE2D_INTERSECTION_FAILED:`CURVE2D_INTERSECTION_FAILED`,CURVE2D_BRIDGE_FAILED:`CURVE2D_BRIDGE_FAILED`,CLONE_FAILED:`CLONE_FAILED`,SIMPLIFY_FAILED:`SIMPLIFY_FAILED`,TO_BREP_FAILED:`TO_BREP_FAILED`,UNSUPPORTED_CAPABILITY:`UNSUPPORTED_CAPABILITY`};function Ra(e,t,n,r,i,a){let o={kind:e,code:t,message:n,cause:r};if(a){let e={...o,suggestion:a};return i?{...e,metadata:i}:e}return i?{...o,metadata:i}:o}function P(e,t,n,r,i){return Ra(`KERNEL_OPERATION`,e,t,n,r,i)}function F(e,t,n,r,i){return Ra(`VALIDATION`,e,t,n,r,i)}function za(e,t,n,r,i){return Ra(`TYPE_CAST`,e,t,n,r,i)}function Ba(e,t,n,r,i){return Ra(`SKETCHER_STATE`,e,t,n,r,i)}function Va(e,t,n,r,i){return Ra(`MODULE_INIT`,e,t,n,r,i)}function Ha(e,t,n,r,i){return Ra(`COMPUTATION`,e,t,n,r,i)}function Ua(e,t,n,r,i){return Ra(`IO`,e,t,n,r,i)}function Wa(e,t,n,r,i){return Ra(`QUERY`,e,t,n,r,i)}function Ga(e,t,n,r,i){return Ra(`UNSUPPORTED`,e,t,n,r,i)}function Ka(e,n,r){return(n<0||n>=e.length)&&M(r??`safeIndex`,`Index ${n} is out of bounds (array length ${e.length})`),t(e,n)}function qa(e){return`makeLine2d`in e}var Ja=[`boolean`,`loft`,`extrude`,`shell`,`fillet`,`mesh`,`edgeMesh`,`transform`],Ya=Object.create(null),Xa=Object.create(null);function Za(){for(let e of Ja)Ya[e]=0,Xa[e]=0}Za();function Qa(e){let t=performance.now();return()=>{Ya[e]=(Ya[e]??0)+(performance.now()-t),Xa[e]=(Xa[e]??0)+1}}function $a(){let e={};for(let t of Ja)e[t]={totalMs:Ya[t]??0,count:Xa[t]??0};return e}function eo(){Za()}var to;function no(){to=void 0}function ro(e){return to??=typeof e.BooleanBatch==`function`,to}function io(e){return e===`commonFace`?1:e===`sameFace`?2:0}function ao(e,t,n={}){if(!ro(e))return null;let r=Qa(`boolean`),i=new e.BooleanBatch;try{for(let e of t)i.addShape(e);return i.fuseAll(io(n.optimisation),!!n.simplify,n.fuzzyValue??0)}finally{i.delete(),r()}}function oo(e,t,n,r={}){if(!ro(e))return null;if(n.length===0)return t;let i=Qa(`boolean`),a=new e.BooleanBatch;try{for(let e of n)a.addShape(e);return a.cutAll(t,io(r.optimisation),!!r.simplify,r.fuzzyValue??0)}finally{a.delete(),i()}}var so=2147483647,co;function lo(){co=void 0}function uo(e){return co??=typeof e.MeasurementExtractor?.extract==`function`,co}function fo(e,t,n=!1){if(uo(e)){let r=e.MeasurementExtractor.extract(t,n);try{let t=r.getDataPtr()/8,n=r.getDataSize(),i=e.HEAPF64.slice(t,t+n);return{volume:i[0]??0,area:i[1]??0,length:i[2]??0,centerOfMass:[i[3]??0,i[4]??0,i[5]??0],boundingBox:{min:[i[6]??0,i[7]??0,i[8]??0],max:[i[9]??0,i[10]??0,i[11]??0]}}}finally{r.delete()}}return{volume:po(e,t),area:mo(e,t),length:n?ho(e,t):0,centerOfMass:go(e,t),boundingBox:vo(e,t)}}function po(e,t){let n=new e.GProp_GProps_1;e.BRepGProp.VolumeProperties_1(t,n,!0,!1,!1);let r=n.Mass();return n.delete(),r}function mo(e,t){let n=new e.GProp_GProps_1;e.BRepGProp.SurfaceProperties_2(t,n,1e-7,!0);let r=n.Mass();return n.delete(),r}function ho(e,t){let n=new e.GProp_GProps_1;e.BRepGProp.LinearProperties(t,n,!0,!1);let r=n.Mass();return n.delete(),r}function go(e,t){let n=new e.GProp_GProps_1;e.BRepGProp.VolumeProperties_1(t,n,!0,!1,!1);let r=n.CentreOfMass(),i=[r.X(),r.Y(),r.Z()];return r.delete(),n.delete(),i}function _o(e,t){let n=new e.GProp_GProps_1;e.BRepGProp.LinearProperties(t,n,!0,!1);let r=n.CentreOfMass(),i=[r.X(),r.Y(),r.Z()];return r.delete(),n.delete(),i}function vo(e,t){let n=new e.Bnd_Box;e.BRepBndLib.Add(t,n,!0);let r={min:[n.GetXMin(),n.GetYMin(),n.GetZMin()],max:[n.GetXMax(),n.GetYMax(),n.GetZMax()]};return n.delete(),r}function yo(e,t,n){let r=new e.BRepExtrema_DistShapeShape_1;r.LoadS1(t),r.LoadS2(n);let i=new e.Message_ProgressRange_1;if(r.Perform(i),!r.IsDone())throw i.delete(),r.delete(),Error(`BRepExtrema_DistShapeShape failed`);let a=r.Value(),o=r.PointOnShape1(1),s=r.PointOnShape2(1),c={value:a,point1:[o.X(),o.Y(),o.Z()],point2:[s.X(),s.Y(),s.Z()]};return o.delete(),s.delete(),i.delete(),r.delete(),c}function bo(e,t,n,r,i=1e-6){if(!e.BRepClass_FaceClassifier)throw Error(`BRepClass_FaceClassifier not available in this WASM build`);let a=new e.gp_Pnt2d_3(n,r),o=new e.BRepClass_FaceClassifier_3(t,a,i),s=o.State();a.delete(),o.delete();let c=e.TopAbs_State;return s===c.TopAbs_IN?`in`:s===c.TopAbs_ON?`on`:`out`}function xo(e){return{volume:t=>po(e,t),area:t=>mo(e,t),length:t=>ho(e,t),centerOfMass:t=>go(e,t),linearCenterOfMass:t=>_o(e,t),boundingBox:t=>vo(e,t),distance:(t,n)=>yo(e,t,n),classifyPointOnFace:(t,n,r,i)=>bo(e,t,n,r,i),measureBulk:(t,n)=>fo(e,t,n)}}var So={vertex:7,edge:6,wire:5,face:4,shell:3,solid:2,compsolid:1,compound:0};function Co(e,t,n){let r=e.TopologyExtractor.extract(t,So[n]),i=r.getShapesCount(),a=[];for(let e=0;e<i;e++)a.push(r.getShape(e));return r.delete(),a}var wo=new WeakMap;function To(e,t,n){let r=wo.get(e);if(!r){let t=e.TopAbs_ShapeEnum;r={vertex:t.TopAbs_VERTEX,edge:t.TopAbs_EDGE,wire:t.TopAbs_WIRE,face:t.TopAbs_FACE,shell:t.TopAbs_SHELL,solid:t.TopAbs_SOLID,compsolid:t.TopAbs_COMPSOLID,compound:t.TopAbs_COMPOUND},wo.set(e,r)}let i=new e.TopExp_Explorer_2(t,r[n],e.TopAbs_ShapeEnum.TopAbs_SHAPE),a=[],o=new Map;for(;i.More();){let t=i.Current(),n=e.shapeHashCode(t,so),r=o.get(n);r?r.some(e=>e.IsSame(t))||(r.push(t),a.push(t)):(o.set(n,[t]),a.push(t)),i.Next()}return i.delete(),a}function Eo(e,t,n){return e.TopologyExtractor?Co(e,t,n):To(e,t,n)}var Do=new WeakMap;function Oo(e){let t=Do.get(e);if(!t){let n=e.TopAbs_ShapeEnum;t=new Map([[n.TopAbs_VERTEX,`vertex`],[n.TopAbs_EDGE,`edge`],[n.TopAbs_WIRE,`wire`],[n.TopAbs_FACE,`face`],[n.TopAbs_SHELL,`shell`],[n.TopAbs_SOLID,`solid`],[n.TopAbs_COMPSOLID,`compsolid`],[n.TopAbs_COMPOUND,`compound`]]),Do.set(e,t)}return t}function ko(e,t){if(t.IsNull())throw Error(`Cannot determine shape type: shape is null`);let n=Oo(e).get(t.ShapeType());if(!n)throw Error(`Unknown shape type enum value`);return n}function Ao(e,t){let n=new e.BRepCheck_Analyzer(t,!0,!1,!1),r=n.IsValid_2();return n.delete(),r}function jo(e,t,n=1e-6){let r=new e.BRepBuilderAPI_Sewing(n,!0,!0,!0,!1);for(let e of t)r.Add(e);let i=new e.Message_ProgressRange_1;r.Perform(i);let a=r.SewedShape();return i.delete(),r.delete(),a}function Mo(e,t,n){if(e.TopTools_ListIteratorOfListOfShape){let r=new e.TopTools_ListIteratorOfListOfShape(t);for(;r.More();)n(r.Value()),r.Next();r.delete()}else{let r=new e.TopTools_ListOfShape_3(t);for(;r.Size()>0;)n(r.First_1()),r.RemoveFirst();r.delete()}}function No(e,t){return e.IsSame(t)}function Po(e,t){return e.IsEqual(t)}function Fo(e){return{iterShapes:(t,n)=>Eo(e,t,n),iterShapeList:(t,n)=>{Mo(e,t,n)},shapeType:t=>ko(e,t),isSame:(e,t)=>No(e,t),isEqual:(e,t)=>Po(e,t),isValid:t=>Ao(e,t),sew:(t,n)=>jo(e,t,n)}}var Io=.001;function Lo(e,t,n){n===`commonFace`&&t.SetGlue(e.BOPAlgo_GlueEnum.BOPAlgo_GlueShift),n===`sameFace`&&t.SetGlue(e.BOPAlgo_GlueEnum.BOPAlgo_GlueFull)}function Ro(e,t){e.SetRunParallel(!0),e.SetUseOBB?.(!0),t!==void 0&&t>0&&e.SetFuzzyValue?.(t)}function zo(e,t){if(t.length<3)return 0;let n=t[0];if(!n)return 0;let r=new e.Bnd_Box;if(e.BRepBndLib.Add(n,r,!0),r.IsVoid())return r.delete(),0;let i=r.CornerMin(),a=r.CornerMax(),o=a.X()-i.X(),s=a.Y()-i.Y(),c=a.Z()-i.Z();return i.delete(),a.delete(),r.delete(),Math.sqrt(o*o+s*s+c*c)>1?1e-5:0}function Bo(e,t){let n=new e.TopoDS_Builder,r=new e.TopoDS_Compound;n.MakeCompound(r);for(let e of t)n.Add(r,e);return n.delete(),r}function Vo(e,t,n,r={}){let i=Qa(`boolean`);try{let{optimisation:i,simplify:a=!1,fuzzyValue:o}=r,s=new e.Message_ProgressRange_1,c=new e.BRepAlgoAPI_Fuse_3(t,n,s);Lo(e,c,i),Ro(c,o),c.Build(s),a&&c.SimplifyResult(!0,!0,Io);let l=c.Shape();return c.delete(),s.delete(),l}finally{i()}}function Ho(e,t,n,r={}){let i=Qa(`boolean`);try{let{optimisation:i,simplify:a=!1,fuzzyValue:o}=r,s=new e.Message_ProgressRange_1,c=new e.BRepAlgoAPI_Cut_3(t,n,s);Lo(e,c,i),Ro(c,o),c.Build(s),a&&c.SimplifyResult(!0,!0,Io);let l=c.Shape();return c.delete(),s.delete(),l}finally{i()}}function Uo(e,t,n,r={}){let i=Qa(`boolean`);try{let{optimisation:i,simplify:a=!1,fuzzyValue:o}=r,s=new e.Message_ProgressRange_1,c=new e.BRepAlgoAPI_Common_3(t,n,s);Lo(e,c,i),Ro(c,o),c.Build(s),a&&c.SimplifyResult(!0,!0,Io);let l=c.Shape();return c.delete(),s.delete(),l}finally{i()}}function Wo(e,t,n,r=!0){let i=new e.Message_ProgressRange_1,a=new e.BRepAlgoAPI_Section_3(t,n,!1);if(a.Approximation(r),Ro(a),a.Build(i),!a.IsDone())throw a.delete(),i.delete(),Error(`BRepAlgoAPI_Section build failed`);let o=a.Shape();return a.delete(),i.delete(),o}function Go(e,t,n={}){let r=ao(e,t,n);if(r!==null)return r;let i=Qa(`boolean`);try{let{optimisation:r,simplify:i=!1}=n,a=n.fuzzyValue??zo(e,t),o=new e.TopTools_ListOfShape_1;for(let e of t)o.Append_1(e);let s=new e.BRepAlgoAPI_BuilderAlgo_1;s.SetArguments(o),Lo(e,s,r),Ro(s,a);let c=new e.Message_ProgressRange_1;s.Build(c);let l=s.Shape();if(i){let t=new e.ShapeUpgrade_UnifySameDomain_2(l,!0,!0,!1);t.Build(),l=t.Shape(),t.delete()}return o.delete(),s.delete(),c.delete(),l}finally{i()}}function Ko(e,n,r,i,a){a.signal?.throwIfAborted();let o=i-r;if(o===1)return t(n,r);if(o===2)return Vo(e,n[r],n[r+1],{...a,simplify:!1});let s=r+Math.ceil(o/2);return Vo(e,Ko(e,n,r,s,a),Ko(e,n,s,i,a),{...a,simplify:!1})}function qo(e,t,n={}){let r=Ko(e,t,0,t.length,n);if(n.simplify){let t=new e.ShapeUpgrade_UnifySameDomain_2(r,!0,!0,!1);t.Build();let n=t.Shape();return t.delete(),n}return r}function Jo(e,n,r={}){if(n.length===0)throw Error(`fuseAll requires at least one shape`);if(n.length===1)return t(n,0);let{strategy:i=`native`}=r;return i===`pairwise`?qo(e,n,r):Go(e,n,r)}function Yo(e,t,n){if(!e.BRepAlgoAPI_Splitter)throw Error(`BRepAlgoAPI_Splitter not available in this WASM build`);let r=new e.TopTools_ListOfShape_1;r.Append_1(t);let i=new e.TopTools_ListOfShape_1;for(let e of n)i.Append_1(e);let a=new e.BRepAlgoAPI_Splitter;a.SetArguments(r),a.SetTools(i),Ro(a);let o=new e.Message_ProgressRange_1;a.Build(o);let s=a.Shape();return a.delete(),o.delete(),r.delete(),i.delete(),s}function Xo(e,t,n,r={}){if(n.length===0)return t;let i=oo(e,t,n,r);if(i!==null)return i;let a=Bo(e,n),o=Ho(e,t,a,r);return a.delete(),o}function Zo(e,t,n,r,i){let a=[];return t.IsNull()&&a.push({operand:`base`,issue:`null-shape`,message:`Base shape is null`}),n.IsNull()&&a.push({operand:`tool`,issue:`null-shape`,message:`Tool shape is null`}),a.length>0?{valid:!1,issues:a}:(i(t)||a.push({operand:`base`,issue:`not-valid`,message:`Base shape fails BRepCheck validation. Try autoHeal() first.`}),i(n)||a.push({operand:`tool`,issue:`not-valid`,message:`Tool shape fails BRepCheck validation. Try autoHeal() first.`}),{valid:a.length===0,issues:a})}function Qo(e){return{fuse:(t,n,r)=>Vo(e,t,n,r),cut:(t,n,r)=>Ho(e,t,n,r),intersect:(t,n,r)=>Uo(e,t,n,r),section:(t,n,r)=>Wo(e,t,n,r),fuseAll:(t,n)=>Jo(e,t,n),cutAll:(t,n,r)=>Xo(e,t,n,r),split:(t,n)=>Yo(e,t,n),checkBoolean:(t,n,r)=>Zo(e,t,n,r,t=>Ao(e,t))}}var $o={fuse:0,cut:1,intersect:2};function es(e,t,n,r={}){let{glueMode:i=0,fuzzyValue:a=0}=r;if(typeof e.BooleanPipeline==`function`){let r=new e.BooleanPipeline;try{for(let e of n)r.addStep($o[e.op],e.tool);let e=r.execute(t,i,a);return e.IsNull()?null:e}finally{r.delete()}}}function ts(e){return{booleanPipeline:(t,n,r)=>es(e,t,n,r)??null}}function ns(e,t,n,r){let i=new e.gp_Pnt_3(t,n,r),a=new e.BRepBuilderAPI_MakeVertex(i),o=a.Vertex();return a.delete(),i.delete(),o}function rs(e,t,n,r){let i=n!==void 0&&r!==void 0?new e.BRepBuilderAPI_MakeEdge_24(t,n,r):new e.BRepBuilderAPI_MakeEdge_24(t),a=i.Edge();return i.delete(),a}function is(e,t){let n=new e.BRepBuilderAPI_MakeWire_1;for(let e of t)n.Add_1(e);let r=new e.Message_ProgressRange_1;n.Build(r);let i=n.Wire();return n.delete(),r.delete(),i}function as(e,t,n=!0){if(n){let n=new e.BRepBuilderAPI_MakeFace_15(t,!1),r=n.Face();return n.delete(),r}let r=new e.BRepOffsetAPI_MakeFilling(3,15,2,!1,1e-5,1e-4,.01,.1,8,9),i=Eo(e,t,`edge`);for(let t of i)r.Add_1(t,e.GeomAbs_Shape.GeomAbs_C0,!0);let a=new e.Message_ProgressRange_1;r.Build(a);let o=r.Shape();return r.delete(),a.delete(),o}function os(e,t,n,r){let i=new e.BRepPrimAPI_MakeBox_2(t,n,r),a=i.Solid();return i.delete(),a}function ss(e,t,n,r=[0,0,0],i=[0,0,1]){let a=new e.gp_Pnt_3(...r),o=new e.gp_Dir_5(...i),s=new e.gp_Ax2_4(a,o),c=new e.BRepPrimAPI_MakeCylinder_3(s,t,n),l=c.Shape();return c.delete(),s.delete(),a.delete(),o.delete(),l}function cs(e,t,n=[0,0,0]){if(n[0]===0&&n[1]===0&&n[2]===0){let n=new e.BRepPrimAPI_MakeSphere_1(t),r=n.Shape();return n.delete(),r}let r=new e.gp_Pnt_3(...n),i=new e.BRepPrimAPI_MakeSphere_2(r,t),a=i.Shape();return i.delete(),r.delete(),a}function ls(e,t,n,r,i=[0,0,0],a=[0,0,1]){let o=new e.gp_Pnt_3(...i),s=new e.gp_Dir_5(...a),c=new e.gp_Ax2_4(o,s),l=new e.BRepPrimAPI_MakeCone_3(c,t,n,r),u=l.Shape();return l.delete(),c.delete(),o.delete(),s.delete(),u}function us(e,t,n,r){let i=new e.gp_Pnt_3(t[0],t[1],t[2]),a=new e.gp_Pnt_3(n[0],n[1],n[2]),o=new e.gp_Pnt_3(r[0],r[1],r[2]),s=new e.BRepBuilderAPI_MakeEdge_3(i,a),c=new e.BRepBuilderAPI_MakeEdge_3(a,o),l=new e.BRepBuilderAPI_MakeEdge_3(o,i),u=new e.BRepBuilderAPI_MakeWire_1;u.Add_1(s.Edge()),u.Add_1(c.Edge()),u.Add_1(l.Edge());let d=null;if(u.IsDone()){let t=new e.BRepBuilderAPI_MakeFace_15(u.Wire(),!1);t.IsDone()&&(d=t.Face()),t.delete()}return u.delete(),s.delete(),c.delete(),l.delete(),i.delete(),a.delete(),o.delete(),d}function ds(e,t){let n=new e.BRepBuilderAPI_MakeWire_1;for(let r of t){let t=r.ShapeType();t===e.TopAbs_ShapeEnum.TopAbs_EDGE?n.Add_1(r):t===e.TopAbs_ShapeEnum.TopAbs_WIRE&&n.Add_2(r)}let r=new e.Message_ProgressRange_1;n.Build(r);let i=n.Wire();return n.delete(),r.delete(),i}function fs(e,t,n,r=[0,0,0],i=[0,0,1]){let a=new e.gp_Pnt_3(...r),o=new e.gp_Dir_5(...i),s=new e.gp_Ax2_4(a,o),c=new e.BRepPrimAPI_MakeTorus_5(s,t,n),l=c.Shape();return c.delete(),s.delete(),a.delete(),o.delete(),l}function ps(e){return{makeVertex:(t,n,r)=>ns(e,t,n,r),makeEdge:(t,n,r)=>rs(e,t,n,r),makeWire:t=>is(e,t),makeWireFromMixed:t=>ds(e,t),makeFace:(t,n)=>as(e,t,n),makeBox:(t,n,r)=>os(e,t,n,r),makeCylinder:(t,n,r,i)=>ss(e,t,n,r,i),makeSphere:(t,n)=>cs(e,t,n),makeCone:(t,n,r,i,a)=>ls(e,t,n,r,i,a),makeTorus:(t,n,r,i)=>fs(e,t,n,r,i),buildTriFace:(t,n,r)=>us(e,t,n,r)}}function ms(e,t){let n=e[t];if(n===void 0)throw Error(`Index ${t} out of bounds`);return n}function hs(e,t,n){let r=[],i=Math.max(n,1);for(let n of t){new e.BRepMesh_IncrementalMeshWrapper(n,i,!1,i*.5,!1).delete();let t=new e.TopExp_Explorer_2(n,e.TopAbs_ShapeEnum.TopAbs_FACE,e.TopAbs_ShapeEnum.TopAbs_SHAPE);for(;t.More();){let n=e.TopoDS_Cast.Face(t.Current()),i=new e.TopLoc_Location_1,a=e.BRep_Tool_Triangulation(n,i,0);if(!a.IsNull()){let e=i.Transformation(),t=a.get().NbNodes();for(let n=1;n<=t;n++){let t=a.get().Node(n),i=t.Transformed(e);r.push({x:i.X(),y:i.Y(),z:i.Z()}),i.delete(),t.delete()}e.delete()}i.delete(),t.Next()}t.delete()}return r}function gs(e,t,n){let{faces:r,points:i}=t,a=[];for(let[t,n,o]of r){let r=ms(i,t),s=ms(i,n),c=ms(i,o),l=us(e,[r.x,r.y,r.z],[s.x,s.y,s.z],[c.x,c.y,c.z]);l!==null&&a.push(l)}if(a.length<4)throw Error(`hull: only ${a.length} faces built, need at least 4 for a solid`);let o=Math.max(n,1e-4),s=new e.BRepBuilderAPI_Sewing(o,!0,!0,!0,!1);for(let e of a)s.Add(e);let c=new e.Message_ProgressRange_1;s.Perform(c),c.delete();let l=s.SewedShape();s.delete();let u=new e.TopExp_Explorer_2(l,e.TopAbs_ShapeEnum.TopAbs_SHELL,e.TopAbs_ShapeEnum.TopAbs_SHAPE);if(u.More()){let t=e.TopoDS_Cast.Shell(u.Current());u.delete();let n=new e.BRepBuilderAPI_MakeSolid_1;n.Add(t);let r=new e.Message_ProgressRange_1;if(n.Build(r),r.delete(),n.IsDone()){let r=n.Solid();n.delete(),t.delete();let i=new e.GProp_GProps_1;e.BRepGProp.VolumeProperties_1(r,i,!1,!1,!1);let a=i.Mass();return i.delete(),a<0&&r.Complement(),r}return t.delete(),n.delete(),l}return u.delete(),l}function _s(e,t,n){if(t.length===0)throw Error(`hull: no shapes provided`);let r=hs(e,t,n);if(r.length<4)throw Error(`hull: fewer than 4 vertices extracted from input shapes`);let i=m(r,n);if(i.faces.length<4)throw Error(`hull: degenerate hull (fewer than 4 faces)`);return gs(e,i,n)}function vs(e,t,n,r){return gs(e,{points:t,faces:n},r)}function ys(e,t,n){if(t.length<4)throw Error(`hullFromPoints: fewer than 4 points`);let r=m(t,n);if(r.faces.length<4)throw Error(`hullFromPoints: degenerate hull (fewer than 4 faces)`);return gs(e,r,n)}function bs(e){return{hull:(t,n)=>_s(e,t,n),hullFromPoints:(t,n)=>ys(e,t,n),buildSolidFromFaces:(t,n,r)=>vs(e,t,n,r)}}function xs(e,t,n){let r=new e.gp_Pnt_3(t[0],t[1],t[2]),i=new e.gp_Pnt_3(n[0],n[1],n[2]),a=new e.BRepBuilderAPI_MakeEdge_3(r,i),o=a.Edge();return a.delete(),r.delete(),i.delete(),o}function Ss(e,t,n,r){let i=new e.gp_Pnt_3(t[0],t[1],t[2]),a=new e.gp_Dir_5(n[0],n[1],n[2]),o=new e.gp_Ax2_4(i,a),s=new e.gp_Circ_2(o,r),c=new e.BRepBuilderAPI_MakeEdge_8(s),l=c.Edge();return c.delete(),s.delete(),o.delete(),a.delete(),i.delete(),l}function Cs(e,t,n,r,i,a){let o=new e.gp_Pnt_3(t[0],t[1],t[2]),s=new e.gp_Dir_5(n[0],n[1],n[2]),c=new e.gp_Ax2_4(o,s),l=new e.gp_Circ_2(c,r),u=new e.BRepBuilderAPI_MakeEdge_9(l,i,a),d=u.Edge();return u.delete(),l.delete(),c.delete(),s.delete(),o.delete(),d}function ws(e,t,n,r){let i=new e.gp_Pnt_3(t[0],t[1],t[2]),a=new e.gp_Pnt_3(n[0],n[1],n[2]),o=new e.gp_Pnt_3(r[0],r[1],r[2]),s=new e.GC_MakeArcOfCircle_4(i,a,o).Value().get(),c=new e.Handle_Geom_Curve_2(s),l=new e.BRepBuilderAPI_MakeEdge_24(c),u=l.Edge();return l.delete(),c.delete(),i.delete(),a.delete(),o.delete(),u}function Ts(e,t,n,r){let i=new e.gp_Pnt_3(t[0],t[1],t[2]),a=new e.gp_Vec_4(n[0],n[1],n[2]),o=new e.gp_Pnt_3(r[0],r[1],r[2]),s=new e.GC_MakeArcOfCircle_5(i,a,o).Value().get(),c=new e.Handle_Geom_Curve_2(s),l=new e.BRepBuilderAPI_MakeEdge_24(c),u=l.Edge();return l.delete(),c.delete(),i.delete(),a.delete(),o.delete(),u}function Es(e,t,n,r,i,a){let o=new e.gp_Pnt_3(t[0],t[1],t[2]),s=new e.gp_Dir_5(n[0],n[1],n[2]),c;if(a){let t=new e.gp_Dir_5(a[0],a[1],a[2]);c=new e.gp_Ax2_2(o,s,t),t.delete()}else c=new e.gp_Ax2_4(o,s);let l=new e.gp_Elips_2(c,r,i),u=new e.BRepBuilderAPI_MakeEdge_12(l),d=u.Edge();return u.delete(),l.delete(),c.delete(),s.delete(),o.delete(),d}function Ds(e,t,n,r,i,a,o,s){let c=new e.gp_Pnt_3(t[0],t[1],t[2]),l=new e.gp_Dir_5(n[0],n[1],n[2]),u;if(s){let t=new e.gp_Dir_5(s[0],s[1],s[2]);u=new e.gp_Ax2_2(c,l,t),t.delete()}else u=new e.gp_Ax2_4(c,l);let d=new e.gp_Elips_2(u,r,i),f=new e.BRepBuilderAPI_MakeEdge_13(d,a,o),p=f.Edge();return f.delete(),d.delete(),u.delete(),l.delete(),c.delete(),p}function Os(e,n){let r=new e.TColgp_Array1OfPnt_2(1,n.length);for(let i=0;i<n.length;i++){let a=t(n,i),o=new e.gp_Pnt_3(a[0],a[1],a[2]);r.SetValue_1(i+1,o),o.delete()}let i=new e.Geom_BezierCurve_1(r),a=new e.Handle_Geom_Curve_2(i),o=new e.BRepBuilderAPI_MakeEdge_24(a),s=o.Edge();return o.delete(),a.delete(),r.delete(),s}function ks(e,t,n,r,i=[0,0,0],a=[0,0,1],o=!1){let s=e.HelixWireBuilder;if(typeof s?.build==`function`){let e=s.build(r,t,n,i[0],i[1],i[2],a[0],a[1],a[2],o);if(!e.IsNull())return e}let c=n/t,l=o?-2*Math.PI:2*Math.PI,u=new e.gp_Pnt_3(i[0],i[1],i[2]),d=new e.gp_Dir_5(a[0],a[1],a[2]),f=new e.gp_Ax3_5(u,d),p=new e.Geom_CylindricalSurface_1(f,r);f.delete();let m=new e.gp_Pnt2d_3(0,0),h=new e.gp_Dir2d_5(l,t),g=new e.Geom2d_Line_3(m,h),_=g.Value(0),v=g.Value(c*Math.sqrt((2*Math.PI)**2+t**2)),y=new e.GCE2d_MakeSegment_1(_,v),b=new e.Handle_Geom2d_Curve_2(y.Value().get()),x=new e.Handle_Geom_Surface_2(p),S=new e.BRepBuilderAPI_MakeEdge_30(b,x),C=S.Edge();e.BRepLib.BuildCurves3d_2(C);let w=new e.BRepBuilderAPI_MakeWire_2(C),ee=w.Wire();return w.delete(),S.delete(),b.delete(),x.delete(),_.delete(),v.delete(),g.delete(),m.delete(),h.delete(),d.delete(),u.delete(),ee}function As(e,t,n,r){let i=Math.sqrt(t*n/r),a=t/i,o=n/i,s=new e.gp_Pnt_3(0,0,0),c=new e.gp_Dir_5(0,1,0),l=new e.gp_Ax1_2(s,c),u=new e.gp_Dir_5(0,0,1),d=new e.gp_Ax1_2(s,u),f=new e.gp_Dir_5(1,0,0),p=new e.gp_Ax1_2(s,f),m=new e.gp_GTrsf_1;m.SetAffinity_1(l,a);let h=new e.gp_GTrsf_1;h.SetAffinity_1(d,i);let g=new e.gp_GTrsf_1;return g.SetAffinity_1(p,o),m.Multiply(h),m.Multiply(g),h.delete(),g.delete(),l.delete(),d.delete(),p.delete(),c.delete(),u.delete(),f.delete(),s.delete(),{transform:m,applyToPoint(t){let n=t.XYZ();m.Transforms_1(n);let r=new e.gp_Pnt_2(n);return n.delete(),r}}}function js(e,t,n,r){let i=new e.gp_Sphere_1;i.SetRadius(1);let a=new e.Geom_SphericalSurface_2(i),o=e.GeomConvert.SurfaceToBSplineSurface(a.UReversed()).get();i.delete(),a.delete();try{let i=As(e,t,n,r),a=o.NbUPoles(),s=o.NbVPoles();for(let t=1;t<=a;t++)for(let n=1;n<=s;n++){let r=e.bsplineSurfacePole(o,t,n),a=i.applyToPoint(r);o.SetPole_1(t,n,a),r.delete(),a.delete()}i.transform.delete();let c=new e.BRepBuilderAPI_MakeShell_2(o.UReversed(),!1),l=c.Shell();c.delete();let u=new e.ShapeFix_Solid_1,d=u.SolidFromShell(l);return u.delete(),d}finally{o.delete()}}function Ms(e,t){let n=new e.TopoDS_Builder,r=new e.TopoDS_Compound;n.MakeCompound(r);for(let e of t)n.Add(r,e);return n.delete(),r}function Ns(e,t,n){let r=new e.gp_Pnt_3(t[0],t[1],t[2]),i=new e.gp_Pnt_3(n[0],n[1],n[2]),a=new e.BRepPrimAPI_MakeBox_4(r,i),o=a.Solid();return a.delete(),r.delete(),i.delete(),o}function Ps(e,t){let n=new e.ShapeFix_Solid_1,r=n.SolidFromShell(e.TopoDS_Cast.Shell(t));return n.delete(),r}function Fs(e,t){return e.BRepToolsWrapper.Write(t)}function Is(e,t){return e.BRepToolsWrapper.Read(t)}function Ls(e,t,n={}){let r=n.unit??`MM`;e.Interface_Static.SetCVal(`xstep.cascade.unit`,r),e.Interface_Static.SetCVal(`write.step.unit`,r),e.Interface_Static.SetIVal(`write.surfacecurve.mode`,0),e.Interface_Static.SetIVal(`write.precision.mode`,0),e.Interface_Static.SetIVal(`write.step.assembly`,2),e.Interface_Static.SetIVal(`write.step.schema`,5),new e.STEPCAFControl_Writer_1().delete();let i=new e.TCollection_ExtendedString_2(`XmlOcaf`,!0),a=new e.TDocStd_Document(i);i.delete();let o=a.Main(),s=e.XCAFDoc_DocumentTool.ShapeTool(o).get(),c=e.XCAFDoc_DocumentTool.ColorTool(o).get();e.XCAFDoc_ShapeTool.SetAutoNaming(!1);for(let n of t){let t=s.AddShape(n.shape,!1,!0),r=new e.TCollection_ExtendedString_2(n.name,!0);if(e.TDataStd_Name.Set_1(t,r),r.delete(),n.color){let[r,i,a,o]=n.color,s=new e.Quantity_ColorRGBA_5(r/255,i/255,a/255,o/255);c.SetColor_6(t,s,e.XCAFDoc_ColorType.XCAFDoc_ColorSurf),s.delete()}}let l=new e.XSControl_WorkSession,u=new e.Handle_XSControl_WorkSession_2(l),d=new e.STEPCAFControl_Writer_2(u,!1),f=new e.Handle_TDocStd_Document_2(a),p=new e.Message_ProgressRange_1;d.Transfer_1(f,e.STEPControl_StepModelType.STEPControl_AsIs,null,p),p.delete();let m=`assembly_export_${Date.now()}.step`,h=d.Write_1(m),g=``;if(h===e.IFSelect_ReturnStatus.IFSelect_RetDone){let t=e.FS.readFile(`/`+m);g=new TextDecoder().decode(t),e.FS.unlink(`/`+m)}return d.delete(),u.delete(),f.delete(),a.delete(),g}function Rs(e,t){try{t.delete()}catch{}}function zs(e,t,n){let r=xs(e,[0,0,0],[t,0,0]),i=xs(e,[t,0,0],[t,n,0]),a=xs(e,[t,n,0],[0,n,0]),o=xs(e,[0,n,0],[0,0,0]),s=new e.BRepBuilderAPI_MakeWire_1;s.Add_1(r),s.Add_1(i),s.Add_1(a),s.Add_1(o);let c=s.Wire();s.delete(),r.delete(),i.delete(),a.delete(),o.delete();let l=new e.BRepBuilderAPI_MakeFace_15(c,!1),u=l.Face();return l.delete(),u}function Bs(e,t,n,r){return new e.gp_Pnt_3(t,n,r)}function Vs(e,t,n,r){return new e.gp_Dir_5(t,n,r)}function Hs(e,t,n,r){return new e.gp_Vec_4(t,n,r)}function Us(e,t,n,r,i,a,o){let s=new e.gp_Pnt_3(t,n,r),c=new e.gp_Dir_5(i,a,o),l=new e.gp_Ax1_2(s,c);return s.delete(),c.delete(),l}function Ws(e,t,n,r,i,a,o,s,c,l){let u=new e.gp_Pnt_3(t,n,r),d=new e.gp_Dir_5(i,a,o),f;if(s!==void 0&&c!==void 0&&l!==void 0){let t=new e.gp_Dir_5(s,c,l);f=new e.gp_Ax2_2(u,d,t),t.delete()}else f=new e.gp_Ax2_4(u,d);return u.delete(),d.delete(),f}function Gs(e,t,n,r,i,a,o,s,c,l){let u=new e.gp_Pnt_3(t,n,r),d=new e.gp_Dir_5(i,a,o),f;if(s!==void 0&&c!==void 0&&l!==void 0){let t=new e.gp_Dir_5(s,c,l);f=new e.gp_Ax3_3(u,d,t),t.delete()}else f=new e.gp_Ax3_5(u,d);return u.delete(),d.delete(),f}function Ks(e){return{makeLineEdge:(t,n)=>xs(e,t,n),makeCircleEdge:(t,n,r)=>Ss(e,t,n,r),makeCircleArc:(t,n,r,i,a)=>Cs(e,t,n,r,i,a),makeArcEdge:(t,n,r)=>ws(e,t,n,r),makeEllipseEdge:(t,n,r,i,a)=>Es(e,t,n,r,i,a),makeEllipseArc:(t,n,r,i,a,o,s)=>Ds(e,t,n,r,i,a,o,s),makeBezierEdge:t=>Os(e,t),makeTangentArc:(t,n,r)=>Ts(e,t,n,r),makeHelixWire:(t,n,r,i,a,o)=>ks(e,t,n,r,i,a,o),makeCompound:t=>Ms(e,t),makeBoxFromCorners:(t,n)=>Ns(e,t,n),makeRectangle:(t,n)=>zs(e,t,n),solidFromShell:t=>Ps(e,t),makeEllipsoid:(t,n,r)=>js(e,t,n,r),toBREP:t=>Fs(e,t),fromBREP:t=>Is(e,t),exportSTEPAssembly:(t,n)=>Ls(e,t,n??{}),dispose:t=>{Rs(e,t)},createPoint3d:(t,n,r)=>Bs(e,t,n,r),createDirection3d:(t,n,r)=>Vs(e,t,n,r),createVector3d:(t,n,r)=>Hs(e,t,n,r),createAxis1:(t,n,r,i,a,o)=>Us(e,t,n,r,i,a,o),createAxis2:(t,n,r,i,a,o,s,c,l)=>Ws(e,t,n,r,i,a,o,s,c,l),createAxis3:(t,n,r,i,a,o,s,c,l)=>Gs(e,t,n,r,i,a,o,s,c,l)}}function qs(e,t,n,r){let i=Qa(`extrude`);try{let i=new e.gp_Vec_4(n[0]*r,n[1]*r,n[2]*r),a=new e.BRepPrimAPI_MakePrism_1(t,i,!1,!0),o=a.Shape();return a.delete(),i.delete(),o}finally{i()}}function Js(e,t,n,r){let i=new e.BRepPrimAPI_MakeRevol_1(t,n,r,!1),a=i.Shape();return i.delete(),a}function Ys(e,t,n=!1,r,i){let a=Qa(`loft`);try{let a=new e.BRepOffsetAPI_ThruSections(!0,n,1e-6);r&&a.AddVertex(r);for(let e of t)a.AddWire(e);i&&a.AddVertex(i);let o=new e.Message_ProgressRange_1;a.Build(o);let s=a.Shape();return a.delete(),o.delete(),s}finally{a()}}function Xs(e,t,n,r={}){let{transitionMode:i}=r,a=new e.BRepOffsetAPI_MakePipeShell(n);typeof a.SetIsBuildHistory==`function`&&a.SetIsBuildHistory(!1),i!==void 0&&a.SetTransitionMode(i),a.Add_1(t,!1,!1);let o=new e.Message_ProgressRange_1;if(a.Build(o),o.delete(),!a.IsDone())throw a.delete(),Error(`Sweep build failed (IsDone=false)`);a.MakeSolid();let s=a.Shape();return a.delete(),s}function Zs(e,t,n){let r=new e.BRepOffsetAPI_MakePipe_1(n,t),i=new e.Message_ProgressRange_1;r.Build(i),i.delete();let a=r.Shape();if(a.ShapeType()===e.TopAbs_ShapeEnum.TopAbs_SHELL){let t=new e.BRepBuilderAPI_MakeSolid_1,n=e.TopoDS_Cast.Shell(a);t.Add(n);let i=new e.Message_ProgressRange_1;t.Build(i),i.delete();let o=t.IsDone()?t.Solid():a;return n.delete(),t.delete(),r.delete(),o}return r.delete(),a}var Qs,$s;function ec(){Qs=void 0}function tc(){$s=void 0}function nc(e){return Qs??=typeof e.LoftBatch==`function`,Qs}function rc(e){return $s??=typeof e.ExtrudeBatch==`function`,$s}function ic(e,t){if(t.length===0)return[];if(nc(e)){let n=Qa(`loft`),r=new e.LoftBatch;try{for(let e of t){let t=r.beginLoft(e.solid??!0,e.ruled??!1,e.tolerance??1e-6);e.startVertex&&r.setStartVertex(t,e.startVertex);for(let n of e.wires)r.addWire(t,n);e.endVertex&&r.setEndVertex(t,e.endVertex)}let e=r.execute();try{let t=e.getShapesCount();return Array.from({length:t},(t,n)=>e.getShape(n))}finally{e.delete()}}finally{r.delete(),n()}}return t.map(t=>Ys(e,t.wires,t.ruled??!1,t.startVertex,t.endVertex))}function ac(e,t){if(t.length===0)return[];if(rc(e)){let n=Qa(`extrude`),r=new e.ExtrudeBatch;try{for(let e of t)r.addExtrude(e.face,e.direction[0]*e.length,e.direction[1]*e.length,e.direction[2]*e.length);let e=r.execute();try{let t=e.getShapesCount();return Array.from({length:t},(t,n)=>e.getShape(n))}finally{e.delete()}}finally{r.delete(),n()}}return t.map(t=>qs(e,t.face,t.direction,t.length))}function oc(e){return{extrude:(t,n,r)=>qs(e,t,n,r),revolve:(t,n,r)=>Js(e,t,n,r),loft:(t,n,r,i)=>Ys(e,t,n,r,i),sweep:(t,n,r)=>Xs(e,t,n,r??{}),simplePipe:(t,n)=>Zs(e,t,n),loftBatch:t=>ic(e,t),extrudeBatch:t=>ac(e,t)}}function sc(e,t,n,r){let i=Qa(`fillet`);try{let i=new e.BRepFilletAPI_MakeFillet(t,e.ChFi3d_FilletShape.ChFi3d_Rational);for(let t of n){let n=typeof r==`function`?r(t):r,a=e.TopoDS_Cast.Edge(t);if(typeof n==`number`)n>0&&i.Add_2(n,a);else{let[e,t]=n;e>0&&t>0&&i.Add_3(e,t,a)}}let a=i.Shape();return i.delete(),a}finally{i()}}function cc(e,t,n,r){let i=new e.BRepFilletAPI_MakeChamfer(t),a=null;function o(){if(a)return a;a=new Map;let n=new e.TopExp_Explorer_2(t,e.TopAbs_ShapeEnum.TopAbs_FACE,e.TopAbs_ShapeEnum.TopAbs_SHAPE);for(;n.More();){let t=e.TopoDS_Cast.Face(n.Current()),r=new e.TopExp_Explorer_2(t,e.TopAbs_ShapeEnum.TopAbs_EDGE,e.TopAbs_ShapeEnum.TopAbs_SHAPE);for(;r.More();){let n=e.shapeHashCode(r.Current(),2147483647);a.has(n)||a.set(n,t),r.Next()}r.delete(),n.Next()}return n.delete(),a}function s(t){return o().get(e.shapeHashCode(t,2147483647))??null}for(let t of n){let n=typeof r==`function`?r(t):r,a=e.TopoDS_Cast.Edge(t);if(typeof n==`number`)n>0&&i.Add_2(n,a);else{let[e,r]=n;if(e>0&&r>0){let n=s(t);n&&i.Add_3(e,r,a,n)}}}let c=i.Shape();return i.delete(),c}function lc(e,t,n,r,i=.001){let a=Qa(`shell`);try{let a=new e.TopTools_ListOfShape_1;for(let e of n)a.Append_1(e);let o=new e.Message_ProgressRange_1,s=new e.BRepOffsetAPI_MakeThickSolid;s.MakeThickSolidByJoin(t,a,-r,i,e.BRepOffset_Mode.BRepOffset_Skin,!1,!1,e.GeomAbs_JoinType.GeomAbs_Arc,!1,o);let c=s.Shape();return s.delete(),a.delete(),o.delete(),c}finally{a()}}function uc(e,t,n){let r=new e.BRepOffsetAPI_MakeThickSolid;r.MakeThickSolidBySimple(t,n);let i=new e.Message_ProgressRange_1;r.Build(i);let a=r.Shape();return r.delete(),i.delete(),a}function dc(e,t,n,r,i){let a=new e.BRepFilletAPI_MakeChamfer(t),o=i*Math.PI/180,s=new Map,c=new e.TopExp_Explorer_2(t,e.TopAbs_ShapeEnum.TopAbs_FACE,e.TopAbs_ShapeEnum.TopAbs_SHAPE);for(;c.More();){let t=e.TopoDS_Cast.Face(c.Current()),n=new e.TopExp_Explorer_2(t,e.TopAbs_ShapeEnum.TopAbs_EDGE,e.TopAbs_ShapeEnum.TopAbs_SHAPE);for(;n.More();){let r=e.shapeHashCode(n.Current(),2147483647);s.has(r)||s.set(r,t),n.Next()}n.delete(),c.Next()}c.delete();for(let t of n){let n=s.get(e.shapeHashCode(t,2147483647))??null;n&&r>0&&a.AddDA(r,o,e.TopoDS_Cast.Edge(t),n)}let l=a.Shape();return a.delete(),l}function fc(e,t,n,r){let i;i=typeof r==`string`?{arc:e.GeomAbs_JoinType.GeomAbs_Arc,intersection:e.GeomAbs_JoinType.GeomAbs_Intersection,tangent:e.GeomAbs_JoinType.GeomAbs_Tangent}[r]??e.GeomAbs_JoinType.GeomAbs_Arc:r??e.GeomAbs_JoinType.GeomAbs_Arc;let a=new e.BRepOffsetAPI_MakeOffset_3(t,i,!1);a.Perform(n,0);let o=a.Shape();return a.delete(),o}function pc(e,t,n,r=1e-6){let i=new e.Message_ProgressRange_1,a=new e.BRepOffsetAPI_MakeOffsetShape;a.PerformByJoin(t,n,r,e.BRepOffset_Mode.BRepOffset_Skin,!1,!1,e.GeomAbs_JoinType.GeomAbs_Arc,!1,i);let o=a.Shape();return a.delete(),i.delete(),o}var mc,hc;function gc(){mc=void 0}function _c(){hc=void 0}function vc(e){return mc??=typeof e.ShellBatch==`function`,mc}function yc(e){return hc??=typeof e.FilletBatch==`function`,hc}function bc(e,t){if(t.length===0)return[];if(vc(e)){let n=Qa(`shell`),r=new e.ShellBatch;try{for(let e of t){let t=r.beginShell(e.shape,e.thickness,e.tolerance??.001);for(let n of e.faces)r.addFaceToRemove(t,n)}let e=r.execute();try{let t=e.getShapesCount();return Array.from({length:t},(t,n)=>e.getShape(n))}finally{e.delete()}}finally{r.delete(),n()}}return t.map(t=>lc(e,t.shape,t.faces,t.thickness,t.tolerance??.001))}function xc(e,t){if(t.length===0)return[];if(yc(e)){let n=Qa(`fillet`),r=new e.FilletBatch;try{for(let e of t){let t=r.beginFillet(e.shape);for(let n of e.edges)n.r2===void 0?r.addEdge(t,n.edge,n.radius):r.addEdgeVariable(t,n.edge,n.radius,n.r2)}let e=r.execute();try{let t=e.getShapesCount();return Array.from({length:t},(t,n)=>e.getShape(n))}finally{e.delete()}}finally{r.delete(),n()}}return t.map(t=>{let n=t.edges.map(e=>e.edge);return sc(e,t.shape,n,e=>{let n=t.edges.find(t=>t.edge===e);return n?n.r2===void 0?n.radius:[n.radius,n.r2]:0})})}function Sc(e){return{fillet:(t,n,r)=>sc(e,t,n,r),chamfer:(t,n,r)=>cc(e,t,n,r),chamferDistAngle:(t,n,r,i)=>dc(e,t,n,r,i),shell:(t,n,r,i)=>lc(e,t,n,r,i),thicken:(t,n)=>uc(e,t,n),offset:(t,n,r)=>pc(e,t,n,r),offsetWire2D:(t,n,r)=>fc(e,t,n,r),shellBatch:t=>bc(e,t),filletBatch:t=>xc(e,t)}}var Cc;function wc(){Cc=void 0}function Tc(e){return Cc??=typeof e.TransformBatch==`function`,Cc}function Ec(e,t){if(t.length===0)return[];let n=Qa(`transform`);try{if(Tc(e)){let n=new e.TransformBatch;try{for(let e of t)switch(e.type){case`translate`:n.addTranslate(e.shape,e.x,e.y,e.z);break;case`rotate`:n.addRotate(e.shape,e.angle*Math.PI/180,...e.axis,...e.center);break;case`scale`:n.addScale(e.shape,...e.center,e.factor);break;case`mirror`:n.addMirror(e.shape,...e.origin,...e.normal);break}let e=n.execute();try{let t=e.getShapesCount();return Array.from({length:t},(t,n)=>e.getShape(n))}finally{e.delete()}}finally{n.delete()}}return t.map(t=>{switch(t.type){case`translate`:return Oc(e,t.shape,t.x,t.y,t.z);case`rotate`:return kc(e,t.shape,t.angle,[...t.axis],[...t.center]);case`scale`:return jc(e,t.shape,[...t.center],t.factor);case`mirror`:return Ac(e,t.shape,[...t.origin],[...t.normal])}})}finally{n()}}function Dc(e,t,n){let r=new e.BRepBuilderAPI_Transform_2(t,n,!0,!1),i=r.ModifiedShape(t);return r.delete(),i}function Oc(e,t,n,r,i){let a=new e.gp_Trsf_1,o=new e.gp_Vec_4(n,r,i);a.SetTranslation_1(o);let s=Dc(e,t,a);return a.delete(),o.delete(),s}function kc(e,t,n,r=[0,0,1],i=[0,0,0]){let a=new e.gp_Trsf_1,o=new e.gp_Pnt_3(...i),s=new e.gp_Dir_5(...r),c=new e.gp_Ax1_2(o,s);a.SetRotation_1(c,n*Math.PI/180);let l=Dc(e,t,a);return a.delete(),c.delete(),o.delete(),s.delete(),l}function Ac(e,t,n,r){let i=new e.gp_Trsf_1,a=new e.gp_Pnt_3(...n),o=new e.gp_Dir_5(...r),s=new e.gp_Ax2_4(a,o);i.SetMirror_3(s);let c=Dc(e,t,i);return i.delete(),s.delete(),a.delete(),o.delete(),c}function jc(e,t,n,r){let i=new e.gp_Trsf_1,a=new e.gp_Pnt_3(...n);i.SetScale(a,r);let o=Dc(e,t,i);return i.delete(),a.delete(),o}function Mc(e,t,n,r,i){if(i){let i=new e.gp_Trsf_1;i.SetValues(n[0],n[1],n[2],r[0],n[3],n[4],n[5],r[1],n[6],n[7],n[8],r[2]);let a=new e.BRepBuilderAPI_Transform_2(t,i,!0,!1),o=a.ModifiedShape(t);return a.delete(),i.delete(),o}let a=new e.gp_GTrsf_1;for(let e=0;e<3;e++)for(let t=0;t<3;t++)a.SetValue(e+1,t+1,n[e*3+t]);let o=new e.gp_XYZ_2(r[0],r[1],r[2]);a.SetTranslationPart(o),o.delete();let s=new e.BRepBuilderAPI_GTransform_2(t,a,!0),c=s.ModifiedShape(t);return s.delete(),a.delete(),c}function Nc(e,t){let n=new e.ShapeUpgrade_UnifySameDomain_2(t,!0,!0,!1);n.Build();let r=n.Shape();return n.delete(),r}function Pc(e){return{transform:(t,n)=>Dc(e,t,n),translate:(t,n,r,i)=>Oc(e,t,n,r,i),rotate:(t,n,r,i)=>kc(e,t,n,r,i),mirror:(t,n,r)=>Ac(e,t,n,r),scale:(t,n,r)=>jc(e,t,n,r),transformBatch:t=>Ec(e,t),generalTransform:(t,n,r,i)=>Mc(e,t,n,r,i),simplify:t=>Nc(e,t)}}function Fc(e,t,n){if(n===0)return new Float32Array;let r=t/4;return e.slice(r,r+n)}function Ic(e,t,n){let r=Qa(`mesh`);try{let r=e.MeshExtractor.extract(t,n.tolerance,n.angularTolerance,!!n.skipNormals,!!n.includeUVs),i=r.getVerticesSize(),a=r.getNormalsSize(),o=r.getTrianglesSize(),s=r.getFaceGroupsSize(),c=r.getUvsSize(),l=Fc(e.HEAPF32,r.getVerticesPtr(),i),u=n.skipNormals||a===0?new Float32Array:Fc(e.HEAPF32,r.getNormalsPtr(),a),d=r.getTrianglesPtr()/4,f=e.HEAPU32.slice(d,d+o),p=c>0?Fc(e.HEAPF32,r.getUvsPtr(),c):new Float32Array,m=[];if(s>0){let t=r.getFaceGroupsPtr()/4,n=e.HEAP32.slice(t,t+s);for(let e=0;e<n.length;e+=3)m.push({start:n[e],count:n[e+1],faceHash:n[e+2]})}return r.delete(),{vertices:l,normals:u,triangles:f,uvs:p,faceGroups:m}}finally{r()}}function Lc(e,t,n,r){let i=Qa(`edgeMesh`);try{let i=e.EdgeMeshExtractor.extract(t,n,r),a=i.getLinesSize(),o=i.getEdgeGroupsSize(),s=Fc(e.HEAPF32,i.getLinesPtr(),a),c=[];if(o>0){let t=i.getEdgeGroupsPtr()/4,n=e.HEAP32.slice(t,t+o);for(let e=0;e<n.length;e+=3)c.push({start:n[e],count:n[e+1],edgeHash:n[e+2]})}return i.delete(),{lines:s,edgeGroups:c}}finally{i()}}function Rc(e){return{mesh:(t,n)=>Ic(e,t,n),meshEdges:(t,n,r)=>Lc(e,t,n,r)}}var zc=0;function Bc(e,t){return`${e}_${++zc}.${t}`}function Vc(e,t){let n=e.StepStreamIO;if(typeof n?.exportSTEP==`function`&&t.length===1)return n.exportSTEP(t[0],5);let r=new e.STEPControl_Writer_1;e.Interface_Static.SetIVal(`write.step.schema`,5),r.Model(!0).delete();let i=new e.Message_ProgressRange_1;for(let n of t)r.Transfer_1(n,e.STEPControl_StepModelType.STEPControl_AsIs,!0,i);let a=Bc(`_export`,`step`),o=r.Write(a);if(r.delete(),i.delete(),o===e.IFSelect_ReturnStatus.IFSelect_RetDone){let t=e.FS.readFile(`/`+a);return e.FS.unlink(`/`+a),new TextDecoder().decode(t)}throw Error(`STEP export failed: writer did not complete successfully`)}function Hc(e,t,n=!1){let r=Bc(`_export`,`stl`);if(e.StlAPI.Write(t,r,!n)){let t=e.FS.readFile(`/`+r);return e.FS.unlink(`/`+r),n?t.buffer:new TextDecoder().decode(t)}throw Error(`STL export failed: StlAPI.Write returned false`)}function Uc(e,t){let n=new e.IGESControl_Writer_1;for(let e of t)n.AddShape(e);n.ComputeModel();let r=Bc(`_export`,`iges`),i=n.Write_2(r);if(n.delete(),i){let t=e.FS.readFile(`/`+r);return e.FS.unlink(`/`+r),new TextDecoder().decode(t)}throw Error(`IGES export failed: writer did not complete successfully`)}function Wc(e,t){let n=typeof t==`string`?t:new TextDecoder().decode(new Uint8Array(t)),r=e.StepStreamIO;if(typeof r?.importSTEP==`function`){let e=r.importSTEP(n);if(e.IsNull())throw Error(`Failed to import STEP file: stream reader could not parse the input data`);return[e]}let i=Bc(`_import`,`step`),a=new TextEncoder().encode(n);e.FS.writeFile(`/`+i,a);let o=new e.STEPControl_Reader_1;if(o.ReadFile(i)){e.FS.unlink(`/`+i);let t=new e.Message_ProgressRange_1;o.TransferRoots(t),t.delete();let n=o.OneShape();return o.delete(),[n]}throw e.FS.unlink(`/`+i),o.delete(),Error(`Failed to import STEP file: reader could not parse the input data`)}function Gc(e,t){let n=Bc(`_import`,`stl`),r=typeof t==`string`?new TextEncoder().encode(t):new Uint8Array(t);e.FS.writeFile(`/`+n,r);let i=new e.StlAPI_Reader,a=new e.TopoDS_Shape;if(i.Read_1(a,`/`+n)){e.FS.unlink(`/`+n);let t=new e.ShapeUpgrade_UnifySameDomain_2(a,!0,!0,!1);t.Build();let r=t.Shape(),o=new e.BRepBuilderAPI_MakeSolid_1;o.Add(e.TopoDS_Cast.Shell(r));let s=o.Solid();return a.delete(),t.delete(),o.delete(),i.delete(),s}throw e.FS.unlink(`/`+n),a.delete(),i.delete(),Error(`Failed to import STL file: reader could not parse the input data`)}function Kc(e,t){let n=Bc(`_import`,`iges`),r=typeof t==`string`?new TextEncoder().encode(t):new Uint8Array(t);e.FS.writeFile(`/`+n,r);let i=new e.IGESControl_Reader_1;if(i.ReadFile(n)===e.IFSelect_ReturnStatus.IFSelect_RetDone){e.FS.unlink(`/`+n);let t=new e.Message_ProgressRange_1;i.TransferRoots(t),t.delete();let r=i.OneShape();return i.delete(),[r]}throw e.FS.unlink(`/`+n),i.delete(),Error(`Failed to import IGES file: reader could not parse the input data`)}function qc(e){return{exportSTEP:t=>Vc(e,t),exportSTL:(t,n)=>Hc(e,t,n),importSTEP:t=>Wc(e,t),importSTL:t=>Gc(e,t),exportIGES:t=>Uc(e,t),importIGES:t=>Kc(e,t)}}function Jc(e,t){let n=e.BRep_Tool.Pnt(t),r=[n.X(),n.Y(),n.Z()];return n.delete(),r}function Yc(e){let t=e.GeomAbs_SurfaceType;return new Map([[t.GeomAbs_Plane,`plane`],[t.GeomAbs_Cylinder,`cylinder`],[t.GeomAbs_Cone,`cone`],[t.GeomAbs_Sphere,`sphere`],[t.GeomAbs_Torus,`torus`],[t.GeomAbs_BezierSurface,`bezier`],[t.GeomAbs_BSplineSurface,`bspline`],[t.GeomAbs_SurfaceOfRevolution,`revolution`],[t.GeomAbs_SurfaceOfExtrusion,`extrusion`],[t.GeomAbs_OffsetSurface,`offset`],[t.GeomAbs_OtherSurface,`other`]])}var Xc=new WeakMap;function Zc(e,t){let n=Xc.get(e);n||(n=Yc(e),Xc.set(e,n));let r=new e.BRepAdaptor_Surface_2(t,!1),i=r.GetType();return r.delete(),n.get(i)??`other`}function Qc(e,t){let n=e.BRepTools.UVBounds_1(t);return{uMin:n.UMin,uMax:n.UMax,vMin:n.VMin,vMax:n.VMax}}function $c(e,t){return e.BRepTools.OuterWire(t)}function el(e,t,n,r){let i=new e.BRepGProp_Face_2(t,!1),a=new e.gp_Pnt_1,o=new e.gp_Vec_1;i.Normal(n,r,a,o);let s=[o.X(),o.Y(),o.Z()];return i.delete(),a.delete(),o.delete(),s}function tl(e,t,n,r){let i=new e.BRepAdaptor_Surface_2(t,!1),a=new e.gp_Pnt_1;i.D0(n,r,a);let o=[a.X(),a.Y(),a.Z()];return i.delete(),a.delete(),o}function nl(e,t,n){let r=e.BRep_Tool.Surface_2(t),i=new e.gp_Pnt_3(n[0],n[1],n[2]),a=new e.GeomAPI_ProjectPointOnSurf_2(i,r,e.Extrema_ExtAlgo.Extrema_ExtAlgo_Grad),o=null;if(a.NbPoints()>0){let e=a.LowerDistanceParameters();o=[e.U,e.V]}return a.delete(),i.delete(),o}function rl(e,t,n){let r=e.BRep_Tool.Surface_2(t),i=new e.gp_Pnt_3(n[0],n[1],n[2]),a=new e.GeomAPI_ProjectPointOnSurf_2(i,r,e.Extrema_ExtAlgo.Extrema_ExtAlgo_Grad),o;if(a.NbPoints()>0){let e=a.NearestPoint();o=[e.X(),e.Y(),e.Z()],e.delete()}else o=n;return a.delete(),i.delete(),o}function il(e,t,n){let r=t.ShapeType()===e.TopAbs_ShapeEnum.TopAbs_WIRE?new e.BRepAdaptor_CompCurve_2(t,!1):new e.BRepAdaptor_Curve_2(t),i=new e.gp_Pnt_1,a=new e.gp_Vec_1;r.D1(n,i,a);let o={point:[i.X(),i.Y(),i.Z()],tangent:[a.X(),a.Y(),a.Z()]};return r.delete(),i.delete(),a.delete(),o}function al(e,t){let n=t.ShapeType()===e.TopAbs_ShapeEnum.TopAbs_WIRE?new e.BRepAdaptor_CompCurve_2(t,!1):new e.BRepAdaptor_Curve_2(t),r=[n.FirstParameter(),n.LastParameter()];return n.delete(),r}function ol(e,t,n){let r=t.ShapeType()===e.TopAbs_ShapeEnum.TopAbs_WIRE?new e.BRepAdaptor_CompCurve_2(t,!1):new e.BRepAdaptor_Curve_2(t),i=r.Value(n),a=[i.X(),i.Y(),i.Z()];return i.delete(),r.delete(),a}function sl(e,t){let n=t.ShapeType()===e.TopAbs_ShapeEnum.TopAbs_WIRE?new e.BRepAdaptor_CompCurve_2(t,!1):new e.BRepAdaptor_Curve_2(t),r=n.IsClosed();return n.delete(),r}function cl(e,t){let n=t.ShapeType()===e.TopAbs_ShapeEnum.TopAbs_WIRE?new e.BRepAdaptor_CompCurve_2(t,!1):new e.BRepAdaptor_Curve_2(t),r=n.IsPeriodic();return n.delete(),r}function ll(e,t){let n=t.ShapeType()===e.TopAbs_ShapeEnum.TopAbs_WIRE?new e.BRepAdaptor_CompCurve_2(t,!1):new e.BRepAdaptor_Curve_2(t),r=n.Period();return n.delete(),r}function ul(e,t){let n=t.ShapeType()===e.TopAbs_ShapeEnum.TopAbs_WIRE?new e.BRepAdaptor_CompCurve_2(t,!1):new e.BRepAdaptor_Curve_2(t),r=n.GetType();return n.delete(),{0:`LINE`,1:`CIRCLE`,2:`ELLIPSE`,3:`HYPERBOLA`,4:`PARABOLA`,5:`BEZIER_CURVE`,6:`BSPLINE_CURVE`,7:`OFFSET_CURVE`,8:`OTHER_CURVE`}[typeof r==`number`?r:Number(r?.value??r)]??`OTHER_CURVE`}function dl(e,t){let n=t.Orientation_1(),r=e.TopAbs_Orientation;return n===r.TopAbs_FORWARD?`forward`:n===r.TopAbs_REVERSED?`reversed`:n===r.TopAbs_INTERNAL?`internal`:`external`}function fl(e,t,n){switch(n??pl(e,t)){case`vertex`:return e.TopoDS_Cast.Vertex(t);case`edge`:return e.TopoDS_Cast.Edge(t);case`wire`:return e.TopoDS_Cast.Wire(t);case`face`:return e.TopoDS_Cast.Face(t);case`shell`:return e.TopoDS_Cast.Shell(t);case`solid`:return e.TopoDS_Cast.Solid(t);case`compsolid`:return e.TopoDS_Cast.CompSolid(t);default:return e.TopoDS_Cast.Compound(t)}}function pl(e,t){let n=t.ShapeType(),r=e.TopAbs_ShapeEnum;return n===r.TopAbs_VERTEX?`vertex`:n===r.TopAbs_EDGE?`edge`:n===r.TopAbs_WIRE?`wire`:n===r.TopAbs_FACE?`face`:n===r.TopAbs_SHELL?`shell`:n===r.TopAbs_SOLID?`solid`:n===r.TopAbs_COMPSOLID?`compsolid`:`compound`}function ml(e,t,n){return e.shapeHashCode(t,n)}function hl(e,t){return t.IsNull()}function gl(e,t){return t.Reversed()}function _l(e,t){let n=new e.TopExp_Explorer_2(t,e.TopAbs_ShapeEnum.TopAbs_FACE,e.TopAbs_ShapeEnum.TopAbs_SHAPE),r=new e.TopLoc_Location_1,i=!1;for(;n.More();){let t=e.TopoDS_Cast.Face(n.Current());if(!e.BRep_Tool_Triangulation(t,r,0).IsNull()){i=!0;break}n.Next()}return n.delete(),r.delete(),i}function vl(e,t,n,r){new e.BRepMesh_IncrementalMeshWrapper(t,n,!1,r,!1).delete()}function yl(e,t){let n=new e.BRepAdaptor_Curve_2(t);try{let e=n.Bezier().get(),t=e.NbPoles();if(t<2)return null;let r=e.Pole(t-1),i=[r.X(),r.Y(),r.Z()];return r.delete(),i}catch{return null}finally{n.delete()}}function bl(e,t){return t.ShapeType()===e.TopAbs_ShapeEnum.TopAbs_WIRE?new e.BRepAdaptor_CompCurve_2(t,!1):new e.BRepAdaptor_Curve_2(t)}function xl(e,t){let n=new e.GeomAdaptor_Surface_2(t),r=n.GetType();if((typeof r==`number`?r:Number(r?.value??r))!==1)return n.delete(),null;let i=n.Cylinder(),a={radius:i.Radius(),isDirect:i.Direct()};return i.delete(),n.delete(),a}function Sl(e,t){return t.get().UReversed()}function Cl(e){return{vertexPosition:t=>Jc(e,t),surfaceType:t=>Zc(e,t),uvBounds:t=>Qc(e,t),outerWire:t=>$c(e,t),surfaceNormal:(t,n,r)=>el(e,t,n,r),pointOnSurface:(t,n,r)=>tl(e,t,n,r),uvFromPoint:(t,n)=>nl(e,t,n),projectPointOnFace:(t,n)=>rl(e,t,n),curveTangent:(t,n)=>il(e,t,n),curveParameters:t=>al(e,t),shapeOrientation:t=>dl(e,t),downcast:(t,n)=>fl(e,t,n),hashCode:(t,n)=>ml(e,t,n),isNull:t=>hl(e,t),hasTriangulation:t=>_l(e,t),meshShape:(t,n,r)=>{vl(e,t,n,r)},getBezierPenultimatePole:t=>yl(e,t),createCurveAdaptor:t=>bl(e,t),reverseShape:t=>gl(e,t),curvePointAtParam:(t,n)=>ol(e,t,n),curveIsClosed:t=>sl(e,t),curveIsPeriodic:t=>cl(e,t),curvePeriod:t=>ll(e,t),curveType:t=>ul(e,t),getSurfaceCylinderData:t=>xl(e,t),reverseSurfaceU:t=>Sl(e,t)}}function wl(e,t){let n=new e.BRepAdaptor_Curve_2(t);try{let t=n.GetType(),r=typeof t==`number`?t:Number(t?.value??t),i=e.GeomAbs_CurveType,a=typeof i.GeomAbs_BSplineCurve==`number`?i.GeomAbs_BSplineCurve:Number(i.GeomAbs_BSplineCurve?.value??i.GeomAbs_BSplineCurve),o=typeof i.GeomAbs_BezierCurve==`number`?i.GeomAbs_BezierCurve:Number(i.GeomAbs_BezierCurve?.value??i.GeomAbs_BezierCurve);if(r!==a&&r!==o)return null;let s=n.BSpline(),c=s.get(),l=c.Degree(),u=c.NbPoles(),d=c.NbKnots(),f=c.IsPeriodic(),p=c.IsRational(),m=[];for(let e=1;e<=u;e++){let t=c.Pole(e);m.push([t.X(),t.Y(),t.Z()]),t.delete()}let h=[];for(let e=1;e<=u;e++)h.push(c.Weight(e));let g=[],_=[];for(let e=1;e<=d;e++)g.push(c.Knot(e)),_.push(c.Multiplicity(e));let v={degree:l,poles:m,weights:h,knots:g,multiplicities:_,isPeriodic:f,isRational:p};return s.delete(),v}catch{return null}finally{n.delete()}}function Tl(e,t){let n=new e.BRepAdaptor_Surface_2(t,!1);try{let t=n.GetType(),r=typeof t==`number`?t:Number(t?.value??t),i=e.GeomAbs_SurfaceType;if(r!==(typeof i.GeomAbs_BSplineSurface==`number`?i.GeomAbs_BSplineSurface:Number(i.GeomAbs_BSplineSurface?.value??i.GeomAbs_BSplineSurface)))return null;let a=n.BSpline(),o=a.get(),s=o.UDegree(),c=o.VDegree(),l=o.NbUPoles(),u=o.NbVPoles(),d=o.IsUPeriodic(),f=o.IsVPeriodic(),p=o.IsURational()||o.IsVRational(),m=[],h=[];for(let e=1;e<=l;e++){let t=[],n=[];for(let r=1;r<=u;r++){let i=o.Pole(e,r);t.push([i.X(),i.Y(),i.Z()]),i.delete(),n.push(o.Weight(e,r))}m.push(t),h.push(n)}let g=o.NbUKnots(),_=[],v=[];for(let e=1;e<=g;e++)_.push(o.UKnot(e)),v.push(o.UMultiplicity(e));let y=o.NbVKnots(),b=[],x=[];for(let e=1;e<=y;e++)b.push(o.VKnot(e)),x.push(o.VMultiplicity(e));let S={degreeU:s,degreeV:c,nbPolesU:l,nbPolesV:u,poles:m,weights:h,knotsU:_,knotsV:b,multiplicitiesU:v,multiplicitiesV:x,isPeriodicU:d,isPeriodicV:f,isRational:p};return a.delete(),S}catch{return null}finally{n.delete()}}function El(e){return{getNurbsCurveData:t=>wl(e,t),getNurbsSurfaceData:t=>Tl(e,t)}}function Dl(e,t,n={}){let{tolerance:r=1e-8}=n,i=new e.TColgp_Array1OfPnt_2(1,t.length),a=new e.gp_Pnt_1,o=1;for(let e of t)a.SetCoord_2(e[0],e[1],e[2]),i.SetValue_1(o++,a);a.delete();let s=new e.GeomAPI_PointsToBSpline_2(i,3,8,e.GeomAbs_Shape.GeomAbs_C2,r);if(i.delete(),!s.IsDone())throw s.delete(),Error(`Interpolation failed — GeomAPI_PointsToBSpline did not converge`);let c=s.Curve(),l=new e.Handle_Geom_Curve_2(c.get()),u=new e.BRepBuilderAPI_MakeEdge_24(l),d=u.Edge();return u.delete(),s.delete(),d}function Ol(e,t,n={}){let{tolerance:r=.001,degMin:i=1,degMax:a=6,smoothing:o=null}=n,s=new e.TColgp_Array1OfPnt_2(1,t.length),c=new e.gp_Pnt_1,l=1;for(let e of t)c.SetCoord_2(e[0],e[1],e[2]),s.SetValue_1(l++,c);c.delete();let u;if(u=o?new e.GeomAPI_PointsToBSpline_5(s,o[0],o[1],o[2],a,e.GeomAbs_Shape.GeomAbs_C2,r):new e.GeomAPI_PointsToBSpline_2(s,i,a,e.GeomAbs_Shape.GeomAbs_C2,r),s.delete(),!u.IsDone())throw u.delete(),Error(`Approximation failed — GeomAPI_PointsToBSpline did not converge`);let d=u.Curve(),f=new e.Handle_Geom_Curve_2(d.get()),p=new e.BRepBuilderAPI_MakeEdge_24(f),m=p.Edge();return p.delete(),u.delete(),m}function kl(e){return{interpolatePoints:(t,n)=>Dl(e,t,n??{}),approximatePoints:(t,n)=>Ol(e,t,n??{})}}function Al(e,t){let n=new e.ShapeFix_Solid_2(t),r=new e.Message_ProgressRange_1;n.Perform(r),r.delete();let i=n.Solid();return n.delete(),i.IsNull()?null:i}function jl(e,t){let n=new e.ShapeFix_Face_2(t);n.Perform();let r=n.Face();return n.delete(),r}function Ml(e,t,n){let r;n?r=new e.ShapeFix_Wire_2(t,n,1e-6):(r=new e.ShapeFix_Wire_1,r.Load_1(t)),r.Perform();let i=r.Wire();return r.delete(),i}function Nl(e){return{healSolid:t=>Al(e,t),healFace:t=>jl(e,t),healWire:(t,n)=>Ml(e,t,n)}}var Pl={modified:new Map,generated:new Map,deleted:new Set};function Fl(e,t,n){let r=new Map;if(n===0)return r;let i=e.slice(t/4,t/4+n),a=0;for(;a+1<i.length;){let e=i[a++],t=i[a++];if(t<0||a+t>i.length)break;let n=[];for(let e=0;e<t;e++)n.push(i[a++]);r.set(e,n)}return r}function Il(e,t){try{let n=Fl(e.HEAP32,t.getModifiedPtr(),t.getModifiedSize()),r=Fl(e.HEAP32,t.getGeneratedPtr(),t.getGeneratedSize()),i=new Set,a=t.getDeletedSize();if(a>0){let n=t.getDeletedPtr()/4,r=e.HEAP32.slice(n,n+a);for(let e=0;e<r.length;e++)i.add(r[e])}return{modified:n,generated:r,deleted:i}}finally{t.delete()}}function Ll(e,t,n){let r=[];if(t.Size()===0)return r;if(e.TopTools_ListIteratorOfListOfShape){let i=new e.TopTools_ListIteratorOfListOfShape(t);for(;i.More();)r.push(e.shapeHashCode(i.Value(),n)),i.Next();i.delete()}else{let i=new e.TopTools_ListOfShape_3(t);for(;i.Size()>0;)r.push(e.shapeHashCode(i.First_1(),n)),i.RemoveFirst();i.delete()}return r}function Rl(e,t,n,r,i){if(r.length===0)return Pl;let a=Array.isArray(n)?n:[n];if(e.EvolutionExtractor){let n,r,o;if(a.length===1)n=a[0];else{r=new e.TopoDS_Builder,o=new e.TopoDS_Compound,r.MakeCompound(o);for(let e of a)r.Add(o,e);n=o}let s;try{s=e.EvolutionExtractor.extract(t,n,i)}catch{}finally{r?.delete(),o?.delete()}if(s!==void 0)return Il(e,s)}let o=new Map,s=new Map,c=new Set,l=new Set(r),u=new Map;for(let t of a){let n=new e.TopExp_Explorer_2(t,e.TopAbs_ShapeEnum.TopAbs_FACE,e.TopAbs_ShapeEnum.TopAbs_SHAPE);for(;n.More();){let t=n.Current(),r=e.shapeHashCode(t,i);l.has(r)&&u.set(r,t),n.Next()}n.delete()}for(let[n,r]of u){if(t.IsDeleted?.(r)){c.add(n);continue}let a=t.Modified(r);a.Size()>0&&o.set(n,Ll(e,a,i));let l=t.Generated(r);l.Size()>0&&s.set(n,Ll(e,l,i))}return{modified:o,generated:s,deleted:c}}function zl(e,t,n,r,i){let a=new e.BRepBuilderAPI_Transform_2(t,n,!0,!1),o=a.Shape(),s=r.length===0?Pl:Rl(e,a,t,r,i);return a.delete(),{shape:o,evolution:s}}function Bl(e,t,n,r,i,a,o){return a&&t.SimplifyResult(!0,!0,.001),{shape:t.Shape(),evolution:Rl(e,t,n,r,i),diagnostics:o??{hasErrors:!1,hasWarnings:!1,messages:[]}}}function Vl(e,t,n,r,i){return{shape:t.Shape(),evolution:Rl(e,t,n,r,i)}}function Hl(e,t,n,r,i,a,o){let s=new e.gp_Trsf_1,c=new e.gp_Vec_4(n,r,i);s.SetTranslation_1(c),c.delete();let l=zl(e,t,s,a,o);return s.delete(),l}function Ul(e,t,n,r,i,a=[0,0,1],o=[0,0,0]){let s=new e.gp_Trsf_1,c=new e.gp_Pnt_3(o[0],o[1],o[2]),l=new e.gp_Dir_5(a[0],a[1],a[2]),u=new e.gp_Ax1_2(c,l);s.SetRotation_1(u,n),c.delete(),l.delete(),u.delete();let d=zl(e,t,s,r,i);return s.delete(),d}function Wl(e,t,n,r,i,a){let o=new e.gp_Trsf_1,s=new e.gp_Pnt_3(n[0],n[1],n[2]),c=new e.gp_Dir_5(r[0],r[1],r[2]),l=new e.gp_Ax2_4(s,c);o.SetMirror_3(l),s.delete(),c.delete(),l.delete();let u=zl(e,t,o,i,a);return o.delete(),u}function Gl(e,t,n,r,i,a){let o=new e.gp_Trsf_1,s=new e.gp_Pnt_3(n[0],n[1],n[2]);o.SetScale(s,r),s.delete();let c=zl(e,t,o,i,a);return o.delete(),c}function Kl(e,t,n,r,i,a,o){let s=new e.gp_Trsf_1;s.SetValues(n[0],n[1],n[2],r[0],n[3],n[4],n[5],r[1],n[6],n[7],n[8],r[2]);let c=zl(e,t,s,a,o);return s.delete(),c}function ql(e){return{hasErrors:e.HasErrors(),hasWarnings:e.HasWarnings(),messages:[]}}function Jl(e,t,n,r,i,a={}){let o=new e.Message_ProgressRange_1,s=new e.BRepAlgoAPI_Fuse_3(t,n,o);Lo(e,s,a.optimisation),Ro(s,a.fuzzyValue),s.Build(o);let c=ql(s),l=Bl(e,s,[t,n],r,i,a.simplify??!1,c);return s.delete(),o.delete(),l}function Yl(e,t,n,r,i,a={}){let o=new e.Message_ProgressRange_1,s=new e.BRepAlgoAPI_Cut_3(t,n,o);Lo(e,s,a.optimisation),Ro(s,a.fuzzyValue),s.Build(o);let c=ql(s),l=Bl(e,s,[t,n],r,i,a.simplify??!1,c);return s.delete(),o.delete(),l}function Xl(e,t,n,r,i,a={}){let o=new e.Message_ProgressRange_1,s=new e.BRepAlgoAPI_Common_3(t,n,o);Lo(e,s,a.optimisation),Ro(s,a.fuzzyValue),s.Build(o);let c=ql(s),l=Bl(e,s,[t,n],r,i,a.simplify??!1,c);return s.delete(),o.delete(),l}function Zl(e,t,n,r,i,a){let o=new e.BRepFilletAPI_MakeFillet(t,e.ChFi3d_FilletShape.ChFi3d_Rational);for(let t of n){let n=typeof r==`function`?r(t):r;Array.isArray(n)?o.Add_3(n[0],n[1],e.TopoDS_Cast.Edge(t)):o.Add_2(n,e.TopoDS_Cast.Edge(t))}let s=new e.Message_ProgressRange_1;o.Build(s),s.delete();let c=Vl(e,o,t,i,a);return o.delete(),c}function Ql(e,t,n,r,i,a){let o=new e.BRepFilletAPI_MakeChamfer(t),s=new e.TopExp_Explorer_2(t,e.TopAbs_ShapeEnum.TopAbs_FACE,e.TopAbs_ShapeEnum.TopAbs_SHAPE),c=new Map;for(;s.More();){let t=e.TopoDS_Cast.Face(s.Current()),n=new e.TopExp_Explorer_2(t,e.TopAbs_ShapeEnum.TopAbs_EDGE,e.TopAbs_ShapeEnum.TopAbs_SHAPE);for(;n.More();)c.set(e.shapeHashCode(n.Current(),a),t),n.Next();n.delete(),s.Next()}s.delete();for(let t of n){let n=typeof r==`function`?r(t):r,i=c.get(e.shapeHashCode(t,a));if(Array.isArray(n)&&i)o.Add_3(n[0],n[1],e.TopoDS_Cast.Edge(t),i);else{let r=Array.isArray(n)?n[0]:n;o.Add_2(r,e.TopoDS_Cast.Edge(t))}}let l=new e.Message_ProgressRange_1;o.Build(l),l.delete();let u=Vl(e,o,t,i,a);return o.delete(),u}function $l(e,t,n,r,i,a,o=.001){let s=new e.BRepOffsetAPI_MakeThickSolid,c=new e.TopTools_ListOfShape_1;for(let e of n)c.Append_1(e);let l=new e.Message_ProgressRange_1;s.MakeThickSolidByJoin(t,c,-r,o,e.BRepOffset_Mode.BRepOffset_Skin,!1,!1,e.GeomAbs_JoinType.GeomAbs_Arc,!1,l),l.delete(),c.delete();let u=Vl(e,s,t,i,a);return s.delete(),u}function eu(e,t,n,r,i){let a=new e.BRepOffsetAPI_MakeThickSolid;a.MakeThickSolidBySimple(t,n);let o=new e.Message_ProgressRange_1;a.Build(o),o.delete();let s=Vl(e,a,t,r,i);return a.delete(),s}function tu(e,t,n,r,i,a=1e-6){let o=new e.BRepOffsetAPI_MakeOffsetShape,s=new e.Message_ProgressRange_1;o.PerformByJoin(t,n,a,e.BRepOffset_Mode.BRepOffset_Skin,!1,!1,e.GeomAbs_JoinType.GeomAbs_Arc,!1,s),s.delete();let c=Vl(e,o,t,r,i);return o.delete(),c}function nu(e,t,n,r,i,a,o,s){if(!e.BRepOffsetAPI_DraftAngle)throw Error(`BRepOffsetAPI_DraftAngle not available in this WASM build. Rebuild brepjs-opencascade with the updated build config.`);let[c,l,u]=r,[d,f,p]=i,m=new e.gp_Dir_5(c,l,u),h=new e.gp_Pnt_3(d,f,p),g=new e.gp_Pln_3(h,m),_=new e.BRepOffsetAPI_DraftAngle_2(t);try{for(let t of n){let n=(typeof a==`function`?a(t):a)*Math.PI/180;_.Add(e.TopoDS_Cast.Face(t),m,n,g,!0)}let r=new e.Message_ProgressRange_1;return _.Build(r),r.delete(),Vl(e,_,t,o,s)}finally{_.delete(),g.delete(),h.delete(),m.delete()}}function ru(e){return{translateWithHistory:(t,n,r,i,a,o)=>Hl(e,t,n,r,i,a,o),rotateWithHistory:(t,n,r,i,a,o)=>Ul(e,t,n,r,i,a,o),mirrorWithHistory:(t,n,r,i,a)=>Wl(e,t,n,r,i,a),scaleWithHistory:(t,n,r,i,a)=>Gl(e,t,n,r,i,a),generalTransformWithHistory:(t,n,r,i,a,o)=>Kl(e,t,n,r,i,a,o),fuseWithHistory:(t,n,r,i,a)=>Jl(e,t,n,r,i,a),cutWithHistory:(t,n,r,i,a)=>Yl(e,t,n,r,i,a),intersectWithHistory:(t,n,r,i,a)=>Xl(e,t,n,r,i,a),filletWithHistory:(t,n,r,i,a)=>Zl(e,t,n,r,i,a),chamferWithHistory:(t,n,r,i,a)=>Ql(e,t,n,r,i,a),shellWithHistory:(t,n,r,i,a,o)=>$l(e,t,n,r,i,a,o),thickenWithHistory:(t,n,r,i)=>eu(e,t,n,r,i),offsetWithHistory:(t,n,r,i,a)=>tu(e,t,n,r,i,a),draftWithHistory:(t,n,r,i,a,o,s)=>nu(e,t,n,r,i,a,o,s)}}function iu(e,t,n,r){let i=new e.gp_GTrsf_1;for(let e=0;e<3;e++)for(let t=0;t<3;t++)i.SetValue(e+1,t+1,n[e*3+t]);let a=new e.gp_XYZ_2(r[0],r[1],r[2]);i.SetTranslationPart(a),a.delete();let o=new e.BRepBuilderAPI_GTransform_2(t,i,!0),s=o.Shape();return o.delete(),i.delete(),s}function au(e,t){let n=new e.gp_Trsf_1;for(let r of t){let t=new e.gp_Trsf_1;if(r.type===`translate`){let n=new e.gp_Vec_4(r.x,r.y,r.z);t.SetTranslation_1(n),n.delete()}else{let n=r.axis??[0,0,1],i=r.center??[0,0,0],a=new e.gp_Pnt_3(i[0],i[1],i[2]),o=new e.gp_Dir_5(n[0],n[1],n[2]),s=new e.gp_Ax1_2(a,o);t.SetRotation_1(s,r.angle*Math.PI/180),s.delete(),o.delete(),a.delete()}n.PreMultiply(t),t.delete()}return{handle:n,dispose:()=>n.delete()}}function ou(e,t,n,r,i){return zl(e,t,n,r,i)}function su(e,t){if(!t)return;let n=e.BRepBuilderAPI_TransitionMode;switch(t){case`transformed`:return n.BRepBuilderAPI_Transformed;case`round`:return n.BRepBuilderAPI_RoundCorner;case`right`:return n.BRepBuilderAPI_RightCorner}}function cu(e,t,n,r={}){let i=new e.BRepOffsetAPI_MakePipeShell(n);typeof i.SetIsBuildHistory==`function`&&i.SetIsBuildHistory(!1),r.tolerance!==void 0&&i.SetTolerance(r.tolerance,r.boundTolerance??r.tolerance,r.angularTolerance??1e-7),r.maxDegree!==void 0&&i.SetMaxDegree(r.maxDegree),r.maxSegments!==void 0&&i.SetMaxSegments(r.maxSegments);let a=su(e,r.transitionMode);a!==void 0&&i.SetTransitionMode(a),r.support?i.SetMode_4(r.support):r.frenet&&i.SetMode_1(!0),r.auxiliary&&i.SetMode_5(r.auxiliary,!1,e.BRepFill_TypeOfContact.BRepFill_NoContact);let o=!!r.contact,s=!!r.correction;r.law?i.SetLaw_1(t,r.law,o,s):i.Add_1(t,o,s);let c=new e.Message_ProgressRange_1;if(i.Build(c),c.delete(),!i.IsDone())throw i.delete(),Error(`Sweep pipe shell build failed (IsDone=false)`);if(r.shellMode){let e=i.Shape(),t=i.FirstShape(),n=i.LastShape();return i.delete(),{shape:e,firstShape:t,lastShape:n}}i.MakeSolid();let l=i.Shape();return i.delete(),l}function lu(e,t,n={}){let r=n.solid??!0,i=n.ruled??!1,a=new e.BRepOffsetAPI_ThruSections(r,i,n.tolerance??1e-6);n.startVertex&&a.AddVertex(n.startVertex);for(let e of t)a.AddWire(e);n.endVertex&&a.AddVertex(n.endVertex);let o=new e.Message_ProgressRange_1;a.Build(o),o.delete();let s=a.Shape();return a.delete(),s}function uu(e,t,n,r){if(t===`linear`){let t=new e.Law_Linear;return t.Set(0,1,n,r),t}let i=new e.Law_S;return i.Set_1(0,1,n,r),i}function du(e,t,n,r,i){let a=new e.gp_Pnt_3(n[0],n[1],n[2]),o=new e.gp_Dir_5(r[0],r[1],r[2]),s=new e.gp_Ax1_2(a,o),c=new e.BRepPrimAPI_MakeRevol_1(t,s,i,!1),l=c.Shape();return c.delete(),s.delete(),o.delete(),a.delete(),l}function fu(e,t,n,r,i){let a=[],o=new e.gp_Trsf_1;for(let s=0;s<i;s++){let i=n[0]*r*s,c=n[1]*r*s,l=n[2]*r*s,u=new e.gp_Vec_4(i,c,l);o.SetTranslation_1(u),u.delete();let d=new e.BRepBuilderAPI_Transform_2(t,o,!0,!1);a.push(d.Shape()),d.delete()}return o.delete(),a}function pu(e,t,n,r,i,a){let o=[],s=new e.gp_Pnt_3(n[0],n[1],n[2]),c=new e.gp_Dir_5(r[0],r[1],r[2]),l=new e.gp_Ax1_2(s,c),u=new e.gp_Trsf_1;for(let n=0;n<a;n++){let r=i*n*Math.PI/180;u.SetRotation_1(l,r);let a=new e.BRepBuilderAPI_Transform_2(t,u,!0,!1);o.push(a.Shape()),a.delete()}return u.delete(),l.delete(),c.delete(),s.delete(),o}function mu(e,t,n,r){let i=n.ShapeType()===e.TopAbs_ShapeEnum.TopAbs_WIRE?new e.BRepAdaptor_CompCurve_2(n,!1):new e.BRepAdaptor_Curve_2(n),a=new e.gp_Pnt_1,o=new e.gp_Vec_1;try{i.D1(r,a,o);let n=new e.gp_Dir_2(o),s=new(e.gp_Ax3_5??e.gp_Ax3_4)(a,n),c=new e.gp_Trsf_1;c.SetTransformation_2(s),c.Invert();let l=new e.BRepBuilderAPI_Transform_2(t,c,!0,!1),u=l.Shape();return l.delete(),c.delete(),s.delete(),n.delete(),u}finally{o.delete(),a.delete(),i.delete()}}function hu(e,t){let n=new e.BRepOffsetAPI_MakeFilling(3,15,2,!1,1e-5,1e-4,.01,.1,8,9),r=new e.TopExp_Explorer_2(t,e.TopAbs_ShapeEnum.TopAbs_EDGE,e.TopAbs_ShapeEnum.TopAbs_SHAPE);for(;r.More();){let t=e.TopoDS_Cast.Edge(r.Current());n.Add_1(t,e.GeomAbs_Shape.GeomAbs_C0,!0),r.Next()}r.delete();let i=new e.Message_ProgressRange_1;n.Build(i),i.delete();let a=n.Shape();return n.delete(),a}function gu(e,t,n){let r=new e.BRepBuilderAPI_MakeFace_2(t);for(let e of n)r.Add(e);let i=r.Face();r.delete();let a=new e.ShapeFix_Face_2(i);a.FixOrientation_1(),a.Perform();let o=a.Face();return a.delete(),o}function _u(e,t){let n=e.BRepTools.OuterWire(t),r=e.BRep_Tool.Surface_2(t);try{let t=new e.BRepBuilderAPI_MakeFace_21(r,n,!0),i=t.Face();t.delete();let a=new e.ShapeFix_Face_2(i);a.FixOrientation_1(),a.Perform();let o=a.Face();return a.delete(),o}finally{r.delete(),n.delete()}}function vu(e,t,n){let r=t,i=!1;try{t.ShapeType!==void 0&&(r=e.BRep_Tool.Surface_2(t),i=!0)}catch{}let a=new e.BRepBuilderAPI_MakeFace_21(r,n,!0),o=a.Face();return a.delete(),i&&r.delete(),o}function yu(e,n,r,i){let a=new e.TColgp_Array2OfPnt_2(1,r,1,i);for(let o=0;o<r;o++)for(let r=0;r<i;r++){let s=t(n,o*i+r),c=new e.gp_Pnt_3(s[0],s[1],s[2]);a.SetValue_1(o+1,r+1,c),c.delete()}let o=new e.GeomAPI_PointsToBSplineSurface_2(a,3,8,e.GeomAbs_Shape.GeomAbs_C2,.001),s=o.Surface();a.delete();let c=new e.BRepBuilderAPI_MakeFace_8(s,1e-6),l=c.Face();return c.delete(),o.delete(),l}function bu(e,n,r,i){let a=new e.BRepBuilderAPI_Sewing(1e-6,!0,!0,!0,!1);for(let o=0;o<r-1;o++)for(let r=0;r<i-1;r++){let s=o*i+r,c=(o+1)*i+r,l=o*i+(r+1),u=(o+1)*i+(r+1),d=t(n,s),f=t(n,c),p=t(n,l),m=t(n,u),h=xu(e,d,f,p);a.Add(h);let g=xu(e,f,m,p);a.Add(g)}let o=new e.Message_ProgressRange_1;a.Perform(o),o.delete();let s=a.SewedShape();return a.delete(),s}function xu(e,t,n,r){let i=new e.gp_Pnt_3(t[0],t[1],t[2]),a=new e.gp_Pnt_3(n[0],n[1],n[2]),o=new e.gp_Pnt_3(r[0],r[1],r[2]),s=new e.BRepBuilderAPI_MakeEdge_3(i,a),c=new e.BRepBuilderAPI_MakeEdge_3(a,o),l=new e.BRepBuilderAPI_MakeEdge_3(o,i),u=new e.BRepBuilderAPI_MakeWire_4(s.Edge(),c.Edge(),l.Edge()),d=u.Wire(),f=new e.BRepBuilderAPI_MakeFace_15(d,!0),p=f.Face();return f.delete(),u.delete(),l.delete(),c.delete(),s.delete(),o.delete(),a.delete(),i.delete(),p}function Su(e,t,n){let r=new e.BRepBuilderAPI_Sewing(n,!0,!0,!0,!1);for(let e of t)r.Add(e);let i=new e.Message_ProgressRange_1;r.Perform(i),i.delete();let a=r.SewedShape();r.delete();let o=new e.ShapeFix_Solid_1;try{let t=e.TopoDS_Cast.Shell(a);return o.SolidFromShell(t)}catch{return a}finally{o.delete()}}function Cu(e,t){let n=new e.ShapeFix_Shape_1(t),r=new e.Message_ProgressRange_1;n.Perform(r);let i=n.Shape();return r.delete(),n.delete(),i}function wu(e,t){let n=new e.ShapeFix_Wire_1;n.Load_1(t),n.FixSelfIntersection();let r=n.Wire();return n.delete(),r}function Tu(){return{gaussian:0,mean:0,max:0,min:0,maxDirection:[1,0,0],minDirection:[0,1,0]}}function Eu(e,t,n,r,i,a){let o=e*n-t*t;if(Math.abs(o)<1e-15)return null;let s=(e*a-2*t*i+n*r)/(2*o),c=(r*a-i*i)/o,l=Math.sqrt(Math.max(0,s*s-c)),u=s+l,d=s-l,f=(n*i-t*a)/o,p=(e*i-t*r)/o,m=(n*r-t*i)/o,h,g;return Math.abs(f)>1e-15?(h=f,g=u-m):Math.abs(p)>1e-15?(h=u-(e*a-t*i)/o,g=p):(h=1,g=0),{mean:s,gaussian:c,k1:u,k2:d,du1:h,dv1:g}}function Du(e,t,n,r){let i=new e.BRepAdaptor_Surface_2(t,!1),a=new e.gp_Pnt_1,o=new e.gp_Vec_1,s=new e.gp_Vec_1,c=new e.gp_Vec_1,l=new e.gp_Vec_1,u=new e.gp_Vec_1;i.D2(n,r,a,o,s,c,l,u);let d=o.Dot(o),f=o.Dot(s),p=s.Dot(s),m=o.Crossed(s),h=m.Magnitude(),g=Tu();if(h>=1e-15){m.Divide(h);let e=Eu(d,f,p,c.Dot(m),u.Dot(m),l.Dot(m));e&&(g={gaussian:e.gaussian,mean:e.mean,max:e.k1,min:e.k2,maxDirection:Ou(o,s,e.du1,e.dv1),minDirection:Ou(o,s,-e.dv1,e.du1)})}return a.delete(),o.delete(),s.delete(),c.delete(),l.delete(),u.delete(),m.delete(),i.delete(),g}function Ou(e,t,n,r){let i=n*e.X()+r*t.X(),a=n*e.Y()+r*t.Y(),o=n*e.Z()+r*t.Z(),s=Math.sqrt(i*i+a*a+o*o);return s<1e-15?[1,0,0]:[i/s,a/s,o/s]}function ku(e,t){let n=new e.GProp_GProps_1;e.BRepGProp.SurfaceProperties_2(t,n,1e-7,!0);let r=n.CentreOfMass(),i=[r.X(),r.Y(),r.Z()];return r.delete(),n.delete(),i}function Au(e,t){let n=new e.BRepExtrema_DistShapeShape_1;return n.LoadS1(t),{distanceTo(t){n.LoadS2(t);let r=new e.Message_ProgressRange_1;if(n.Perform(r),r.delete(),!n.IsDone())throw Error(`BRepExtrema_DistShapeShape failed`);let i=n.Value(),a=n.PointOnShape1(1),o=n.PointOnShape2(1),s={value:i,point1:[a.X(),a.Y(),a.Z()],point2:[o.X(),o.Y(),o.Z()]};return a.delete(),o.delete(),s},dispose(){n.delete()}}}function ju(e,t,n,r,i){let a=new e.HLRBRep_Algo_1;a.Add_2(t,0);let o=new e.gp_Pnt_3(n[0],n[1],n[2]),s=new e.gp_Dir_5(r[0],r[1],r[2]),c;if(i){let t=new e.gp_Dir_5(i[0],i[1],i[2]);c=new e.gp_Ax2_2(o,s,t),t.delete()}else c=new e.gp_Ax2_4(o,s);let l=new e.HLRAlgo_Projector_2(c);a.Projector_1(l),a.Update(),a.Hide_1();let u=new e.Handle_HLRBRep_Algo_2(a),d=new e.HLRBRep_HLRToShape(u),f={visible:{outline:d.OutLineVCompound_1(),smooth:d.Rg1LineVCompound_1(),sharp:d.VCompound_1()},hidden:{outline:d.OutLineHCompound_1(),smooth:d.Rg1LineHCompound_1(),sharp:d.HCompound_1()}};for(let t of[f.visible,f.hidden])for(let n of[t.outline,t.smooth,t.sharp])n.IsNull()||e.BRepLib.BuildCurves3d_2(n);return d.delete(),u.delete(),l.delete(),c.delete(),s.delete(),o.delete(),f}function Mu(e,t,n,r,i,a,o){let s=a*Math.PI/180,c=+!!o,l=new e.BRepFeat_MakeDPrism(t,n,r,s,c,!0);if(i!==null){let t=new e.Message_ProgressRange_1;l.Perform_1(i,t),t.delete()}else l.PerformThruAll();let u=l.Shape();return l.delete(),u}function Nu(e,t){let n=new e.TCollection_ExtendedString_2(`XmlOcaf`,!0),r=new e.TDocStd_Document(n);n.delete(),e.XCAFDoc_ShapeTool.SetAutoNaming(!1);let i=r.Main(),a=e.XCAFDoc_DocumentTool.ShapeTool(i).get(),o=e.XCAFDoc_DocumentTool.ColorTool(i).get();for(let n of t){let t=a.NewShape();a.SetShape(t,n.shape);let r=new e.TCollection_ExtendedString_2(n.name,!0);if(e.TDataStd_Name.Set_1(t,r),r.delete(),n.color){let[r,i,a,s]=n.color,c=new e.Quantity_ColorRGBA_5(r/255,i/255,a/255,s/255);o.SetColor_3(t,c,e.XCAFDoc_ColorType.XCAFDoc_ColorSurf),c.delete()}}return a.UpdateAssemblies(),r}function Pu(e,t,n={}){if(n.unit||n.modelUnit){new e.STEPCAFControl_Writer_1().delete();let t=(n.modelUnit??n.unit??`MM`).toUpperCase(),r=(n.unit??n.modelUnit??`MM`).toUpperCase();e.Interface_Static.SetCVal(`xstep.cascade.unit`,t),e.Interface_Static.SetCVal(`write.step.unit`,r)}let r=new e.XSControl_WorkSession,i=new e.Handle_XSControl_WorkSession_2(r),a=new e.STEPCAFControl_Writer_2(i,!1);a.SetColorMode(!0),a.SetLayerMode(!0),a.SetNameMode(!0),e.Interface_Static.SetIVal(`write.surfacecurve.mode`,!0),e.Interface_Static.SetIVal(`write.precision.mode`,0),e.Interface_Static.SetIVal(`write.step.assembly`,2),e.Interface_Static.SetIVal(`write.step.schema`,5);let o=new e.Handle_TDocStd_Document_2(t),s=new e.Message_ProgressRange_1;a.Transfer_1(o,e.STEPControl_StepModelType.STEPControl_AsIs,null,s),s.delete();let c=Bc(`_xcaf_export`,`step`),l=a.Write(c),u=``;if(l===e.IFSelect_ReturnStatus.IFSelect_RetDone){let t=e.FS.readFile(`/`+c);u=new TextDecoder().decode(t),e.FS.unlink(`/`+c)}return a.delete(),i.delete(),u}function Fu(e,t){new e.STEPCAFControl_Writer_1().delete();let n=new e.TCollection_ExtendedString_2(`XmlOcaf`,!0),r=new e.TDocStd_Document(n);n.delete();let i=r.Main(),a=e.XCAFDoc_DocumentTool.ShapeTool(i).get(),o=e.XCAFDoc_DocumentTool.ColorTool(i).get();e.XCAFDoc_ShapeTool.SetAutoNaming(!1);for(let n of t){let t=a.AddShape(n.shape,!1,!0);if(n.name){let r=new e.TCollection_ExtendedString_2(n.name,!0);e.TDataStd_Name.Set_1(t,r),r.delete()}if(n.color){let[r,i,a,s]=n.color,c=new e.Quantity_ColorRGBA_5(r/255,i/255,a/255,s/255);o.SetColor_3(t,c,e.XCAFDoc_ColorType.XCAFDoc_ColorSurf),c.delete()}}let s=new e.XSControl_WorkSession,c=new e.Handle_XSControl_WorkSession_2(s),l=new e.STEPCAFControl_Writer_2(c,!1),u=new e.Handle_TDocStd_Document_2(r),d=new e.Message_ProgressRange_1;l.Transfer_1(u,e.STEPControl_StepModelType.STEPControl_AsIs,null,d),d.delete();let f=Bc(`_step_cfg_export`,`step`),p=l.Write(f),m=``;if(p===e.IFSelect_ReturnStatus.IFSelect_RetDone){let t=e.FS.readFile(`/`+f);m=new TextDecoder().decode(t),e.FS.unlink(`/`+f)}return l.delete(),c.delete(),u.delete(),r.delete(),m}function Iu(e,t){let n=new e.STEPControl_Writer_1;n.Model(!0).delete();let r=new e.Message_ProgressRange_1;for(let i of t)n.Transfer(i.shape,e.STEPControl_StepModelType.STEPControl_AsIs,!0,r);let i=Bc(`_step_cfg_export`,`step`),a=n.Write(i);if(n.delete(),r.delete(),a===e.IFSelect_ReturnStatus.IFSelect_RetDone){let t=e.FS.readFile(`/`+i);return e.FS.unlink(`/`+i),new TextDecoder().decode(t)}throw Error(`STEP configured export failed: writer did not complete successfully`)}function Lu(e,t,n={}){let r=n.unit??`MM`,i=n.modelUnit??r,a=n.schema??5;return e.Interface_Static.SetCVal(`xstep.cascade.unit`,i),e.Interface_Static.SetCVal(`write.step.unit`,r),e.Interface_Static.SetIVal(`write.surfacecurve.mode`,!0),e.Interface_Static.SetIVal(`write.precision.mode`,0),e.Interface_Static.SetIVal(`write.step.assembly`,2),e.Interface_Static.SetIVal(`write.step.schema`,a),t.some(e=>e.name||e.color)?Fu(e,t):Iu(e,t)}function Ru(e){return{composeTransform:t=>au(e,t),applyComposedTransformWithHistory:(t,n,r,i)=>ou(e,t,n,r,i),sweepPipeShell:(t,n,r)=>cu(e,t,n,r??{}),loftAdvanced:(t,n)=>lu(e,t,n??{}),buildExtrusionLaw:(t,n,r)=>uu(e,t,n,r),revolveVec:(t,n,r,i)=>du(e,t,n,r,i),positionOnCurve:(t,n,r)=>mu(e,t,n,r),linearPattern:(t,n,r,i)=>fu(e,t,n,r,i),circularPattern:(t,n,r,i,a)=>pu(e,t,n,r,i,a),makeNonPlanarFace:t=>hu(e,t),addHolesInFace:(t,n)=>gu(e,t,n),removeHolesFromFace:t=>_u(e,t),makeFaceOnSurface:(t,n)=>vu(e,t,n),bsplineSurface:(t,n,r)=>yu(e,t,n,r),triangulatedSurface:(t,n,r)=>bu(e,t,n,r),sewAndSolidify:(t,n)=>Su(e,t,n),fixShape:t=>Cu(e,t),fixSelfIntersection:t=>wu(e,t),surfaceCurvature:(t,n,r)=>Du(e,t,n,r),surfaceCenterOfMass:t=>ku(e,t),createDistanceQuery:t=>Au(e,t),projectEdges:(t,n,r,i)=>ju(e,t,n,r,i),draftPrism:(t,n,r,i,a,o)=>Mu(e,t,n,r,i,a,o),generalTransformNonOrthogonal:(t,n,r)=>iu(e,t,n,r),createXCAFDocument:t=>Nu(e,t),writeXCAFToSTEP:(t,n)=>Pu(e,t,n??{}),exportSTEPConfigured:(t,n)=>Lu(e,t,n??{})}}var zu=()=>{};function Bu(e){return e}function Vu(e){let t=Bu(e);for(;t.__bk2d===`trimmed`;)t=t.basis;return t}function Hu(e){return e}function Uu(e,t){return{x:e,y:t}}function Wu(e,t){let n=Math.sqrt(e*e+t*t);if(n<1e-15)throw Error(`occt: createDirection2d called with zero-length vector`);return{x:e/n,y:t/n}}function Gu(e,t){return{x:e,y:t}}function Ku(e,t,n,r){return{px:e,py:t,dx:n,dy:r,delete:zu}}function qu(e){return e}function Ju(e){return e}function Yu(e,t,n,r){return y(e,t,n,r)}function Xu(e,t,n,r){return b(e,t,n,r)}function Zu(e,t,n,r,i,a){let o=2*(e*(r-a)+n*(a-t)+i*(t-r));if(Math.abs(o)<1e-12)return y(e,t,i,a);let s=((e*e+t*t)*(r-a)+(n*n+r*r)*(a-t)+(i*i+a*a)*(t-r))/o,c=((e*e+t*t)*(i-n)+(n*n+r*r)*(e-i)+(i*i+a*a)*(n-e))/o,l=Math.sqrt((e-s)**2+(t-c)**2),u=Math.atan2(t-c,e-s),d=Math.atan2(r-c,n-s),f=Math.atan2(a-c,i-s),p=d-u;p<0&&(p+=2*Math.PI);let m=f-u;m<0&&(m+=2*Math.PI);let h=p<m,g=b(s,c,l,h);if(!h){let e=-u,t=-f;return t<e-1e-9&&(t+=2*Math.PI),{__bk2d:`trimmed`,basis:g,tStart:e,tEnd:t}}let _=f;return _<u-1e-9&&(_+=2*Math.PI),{__bk2d:`trimmed`,basis:g,tStart:u,tEnd:_}}function Qu(e,t,n,r,i,a){let o=Math.sqrt(n*n+r*r),s=o>0?n/o:0,c=o>0?r/o:0,l=e-i,u=t-a,d=2*(u*s-l*c);if(Math.abs(d)<1e-12)return y(e,t,i,a);let f=-(l*l+u*u)/d,p=e-f*c,m=t+f*s,h=Math.abs(f),g=Math.atan2(t-m,e-p),_=Math.atan2(a-m,i-p),v=-(t-m)/h,b=(e-p)/h,x=s*v+c*b,S;if(x>0){let e=_-g;e<=0&&(e+=2*Math.PI),S=g+e/2}else{let e=_-g;e>=0&&(e-=2*Math.PI),S=g+e/2}return Zu(e,t,p+h*Math.cos(S),m+h*Math.sin(S),i,a)}function $u(e,t,n,r,i,a,o){return x(e,t,n,r,i,a,o)}function ed(e,t,n,r,i,a,o,s,c){return{__bk2d:`trimmed`,basis:x(e,t,n,r,o,s,c),tStart:i,tEnd:a}}function td(e){return S(e)}function nd(e,t){let n=e.length,r=Math.min(3,n-1),i=[],a=[];i.push(0),a.push(r+1);let o=n-r-1;for(let e=1;e<=o;e++)i.push(e/(o+1)),a.push(1);return i.push(1),a.push(r+1),{__bk2d:`bspline`,poles:[...e],knots:i,multiplicities:a,degree:r,isPeriodic:!1}}function rd(e,t){return h(Bu(e),t)}function id(e,t){return{point:h(Bu(e),t),tangent:g(Bu(e),t)}}function ad(e){return _(Bu(e))}function od(e){return v(Vu(e))}function sd(e,t,n){return{__bk2d:`trimmed`,basis:Bu(e),tStart:t,tEnd:n}}function cd(e){return JSON.parse(JSON.stringify(e))}function ld(e,t){let n=Bu(e),r=_(n),i=[];for(let e=0;e<=30;e++){let a=r.first+(r.last-r.first)*e/30,[o,s]=h(n,a),[c,l]=g(n,a),u=Math.sqrt(c*c+l*l);u>1e-12?i.push([o-l/u*t,s+c/u*t]):i.push([o,s])}return nd(i)}function ud(e,t,n){return C(Bu(e),t,n)}function dd(e,t,n,r){return w(Bu(e),t,n,r)}function fd(e,t,n,r){return ee(Bu(e),t,n,r)}function pd(e,t,n){return te(Bu(e),t,n)}function md(e,t,n,r,i){return ne(Bu(e),t,n,r,i)}function hd(e,t,n,r,i,a){return Td(e,vd(t,n,r,i,a))}function gd(e,t,n){return{m:e,tx:t,ty:n,delete:zu}}function _d(){return gd([1,0,0,0,1,0,0,0,1],0,0)}function vd(e,n,r,i,a){let o=Math.sqrt(r*r+i*i);if(o<1e-15)return _d();let s=-i/o,c=r/o,l=a-1,u=[1+l*s*s,l*s*c,0,l*c*s,1+l*c*c,0,0,0,1];return gd(u,e-t(u,0)*e-t(u,1)*n,n-t(u,3)*e-t(u,4)*n)}function yd(e,t){return gd([1,0,0,0,1,0,0,0,1],e,t)}function bd(e,n,r,i,a,o,s){if(r===`axis`&&o!==void 0&&s!==void 0){let r=Math.sqrt(o*o+s*s),c=o/r,l=s/r,u=[2*c*c-1,2*c*l,0,2*c*l,2*l*l-1,0,0,0,1],d=i??e,f=a??n;return gd(u,d-t(u,0)*d-t(u,1)*f,f-t(u,3)*d-t(u,4)*f)}return gd([-1,0,0,0,-1,0,0,0,1],2*e,2*n)}function xd(e,t,n){let r=Math.cos(e),i=Math.sin(e);return gd([r,-i,0,i,r,0,0,0,1],t-r*t+i*n,n-i*t-r*n)}function Sd(e,t,n){return gd([e,0,0,0,e,0,0,0,1],t*(1-e),n*(1-e))}function Cd(e,t,n){e.tx=t,e.ty=n}function wd(e,n){let r=e.m,i=n.m,a=e=>t(r,e),o=e=>t(i,e);e.m=[a(0)*o(0)+a(1)*o(3)+a(2)*o(6),a(0)*o(1)+a(1)*o(4)+a(2)*o(7),a(0)*o(2)+a(1)*o(5)+a(2)*o(8),a(3)*o(0)+a(4)*o(3)+a(5)*o(6),a(3)*o(1)+a(4)*o(4)+a(5)*o(7),a(3)*o(2)+a(4)*o(5)+a(5)*o(8),a(6)*o(0)+a(7)*o(3)+a(8)*o(6),a(6)*o(1)+a(7)*o(4)+a(8)*o(7),a(6)*o(2)+a(7)*o(5)+a(8)*o(8)];let s=e.tx,c=e.ty,l=Number(n.tx)||0,u=Number(n.ty)||0;e.tx=a(0)*l+a(1)*u+s,e.ty=a(3)*l+a(4)*u+c}function Td(e,n){let r=Bu(e),i=n.m??[1,0,0,0,1,0,0,0,1],a=Number(n.tx)||0,o=Number(n.ty)||0,s=t(i,0),c=t(i,1),l=t(i,3),u=t(i,4);if(Math.abs(s-1)<1e-12&&Math.abs(u-1)<1e-12&&Math.abs(c)<1e-12&&Math.abs(l)<1e-12)return C(r,a,o);let d=_(r),f=[];for(let e=0;e<=20;e++){let[t,n]=h(r,d.first+(d.last-d.first)*e/20);f.push([s*t+c*n+a,l*t+u*n+o])}return S(f)}function Ed(e,t,n){let r=re(Bu(e),Bu(t),n),i=r.segments.map(e=>Object.assign(e,{delete(){}}));return{points:r.points,segments:i}}function Dd(e,t,n){let r=Bu(e),i=_(r);if(r.__bk2d===`line`){let e=t-r.ox,a=n-r.oy,o=Math.max(i.first,Math.min(i.last,e*r.dx+a*r.dy)),[s,c]=h(r,o);return{param:o,distance:Math.sqrt((s-t)**2+(c-n)**2)}}if(r.__bk2d===`circle`){let e=Math.atan2(n-r.cy,t-r.cx),i=r.sense?e:-e;for(;i<0;)i+=2*Math.PI;for(;i>2*Math.PI;)i-=2*Math.PI;let[a,o]=h(r,i);return{param:i,distance:Math.sqrt((a-t)**2+(o-n)**2)}}if(!isFinite(i.first)||!isFinite(i.last))return null;let a=i.first,o=1/0,s=(i.last-i.first)/200;for(let e=0;e<=200;e++){let c=i.first+e*s,[l,u]=h(r,c),d=(l-t)**2+(u-n)**2;d<o&&(o=d,a=c)}for(let e=0;e<10;e++){let[e,o]=h(r,a),[s,c]=g(r,a),l=(e-t)*s+(o-n)*c,u=s*s+c*c;if(u<1e-20)break;let d=l/u,f=Math.max(i.first,Math.min(i.last,a-d));if(Math.abs(f-a)<1e-14)break;a=f}let[c,l]=h(r,a);return{param:a,distance:Math.sqrt((c-t)**2+(l-n)**2)}}function Od(e,t,n,r,i,a){let o=Bu(e),s=Bu(t),c=n,l=i,u=1/0;for(let e=0;e<=50;e++){let t=n+(r-n)*e/50,[d,f]=h(o,t);for(let e=0;e<=50;e++){let n=i+(a-i)*e/50,[r,o]=h(s,n),p=(r-d)**2+(o-f)**2;p<u&&(u=p,c=t,l=n)}}let d=c,f=l;for(let c=0;c<20;c++){let[c,l]=h(s,f),u=Dd(e,c,l);if(u){let e=Math.max(n,Math.min(r,u.param)),t=Math.abs(e-d)<1e-12;if(d=e,t)break}let[p,m]=h(o,d),g=Dd(t,p,m);if(g){let e=Math.max(i,Math.min(a,g.param)),t=Math.abs(e-f)<1e-12;if(f=e,t)break}}let[p,m]=h(o,d),[g,_]=h(s,f);return Math.sqrt((g-p)**2+(_-m)**2)}function kd(e,n,r,i){let a=Bu(e),o=_(a),s=Math.max(3,{C0:1,C1:2,C2:3,C3:4}[r]??4),c=Math.max(100,i*10),l=[],u=1/0;for(let e=0;e<3&&u>n;e++){l=[];for(let e=0;e<=c;e++){let t=o.first+(o.last-o.first)*e/c;l.push(h(a,t))}u=0;for(let e=0;e<c;e++){let[n,r]=h(a,o.first+(o.last-o.first)*(e+.5)/c),i=t(l,e),s=t(l,e+1),d=(i[0]+s[0])/2,f=(i[1]+s[1])/2,p=Math.sqrt((n-d)**2+(r-f)**2);p>u&&(u=p)}u>n&&(c=Math.min(c*2,500))}return nd(l,{degMax:s})}function Ad(e){let n=Vu(e);if(n.__bk2d===`bezier`)return[e];if(n.__bk2d!==`bspline`)return Ad(kd(e,1e-6,`C2`,10));let r=_(Bu(e)),i=r.first,a=r.last,o=[];for(let e of n.knots)e>i+1e-12&&e<a-1e-12&&o.push(e);let s=[i,...o,a],c=[];for(let e=0;e<s.length-1;e++){let r=t(s,e),i=t(s,e+1),a=i-r;if(a<1e-15)continue;let o=h(n,r),l=h(n,i),u=g(n,r),d=g(n,i),f=a/3,p={__bk2d:`bezier`,poles:[o,[o[0]+u[0]*f,o[1]+u[1]*f],[l[0]-d[0]*f,l[1]-d[1]*f],l]};c.push(p)}return c.length>0?c:[e]}function jd(){return me()}function Md(e,t,n){he(Hu(e),Bu(t),n)}function Nd(e){let t=Hu(e);return{xMin:t.xMin,yMin:t.yMin,xMax:t.xMax,yMax:t.yMax}}function Pd(e,t){let n=Hu(e),r=Hu(t);n.xMin=Math.min(n.xMin,r.xMin),n.yMin=Math.min(n.yMin,r.yMin),n.xMax=Math.max(n.xMax,r.xMax),n.yMax=Math.max(n.yMax,r.yMax)}function Fd(e,t){let n=Hu(e),r=Hu(t);return n.xMax<r.xMin||r.xMax<n.xMin||n.yMax<r.yMin||r.yMax<n.yMin}function Id(e,t,n){let r=Hu(e);return t<r.xMin||t>r.xMax||n<r.yMin||n>r.yMax}function Ld(e){let t=Vu(e);return t.__bk2d===`circle`?{cx:t.cx,cy:t.cy,radius:t.radius,isDirect:t.sense}:null}function Rd(e){let t=Vu(e);return t.__bk2d===`ellipse`?{majorRadius:t.majorRadius,minorRadius:t.minorRadius,xAxisAngle:t.xDirAngle,isDirect:t.sense}:null}function zd(e){let t=Vu(e);return t.__bk2d===`bezier`?[...t.poles]:null}function Bd(e){let t=Vu(e);return t.__bk2d===`bezier`?t.poles.length-1:null}function Vd(e){let t=Vu(e);return t.__bk2d===`bspline`?{poles:[...t.poles],knots:[...t.knots],multiplicities:[...t.multiplicities],degree:t.degree,isPeriodic:t.isPeriodic}:null}function Hd(e){return fe(Bu(e))}function Ud(e){return pe(e)}function Wd(e,t){let n=Bu(e),r=_(n),i=[r.first,...[...t].sort((e,t)=>e-t),r.last],a=[];for(let e=0;e<i.length-1;e++)a.push({__bk2d:`trimmed`,basis:n,tStart:i[e],tEnd:i[e+1]});return a}function Gd(e,t,n){let r=new e.gp_Pnt_3(t[0],t[1],t[2]),i=new e.gp_Pnt_3(n[0],n[1],n[2]),a=new e.BRepBuilderAPI_MakeEdge_3(r,i),o=a.Edge();return a.delete(),r.delete(),i.delete(),o}function Kd(e,t,n,r){let i=new e.gp_Pnt_3(t[0],t[1],t[2]),a=new e.gp_Pnt_3(n[0],n[1],n[2]),o=new e.gp_Pnt_3(r[0],r[1],r[2]),s=new e.GC_MakeArcOfCircle_4(i,a,o).Value().get(),c=new e.Handle_Geom_Curve_2(s),l=new e.BRepBuilderAPI_MakeEdge_24(c),u=l.Edge();return l.delete(),c.delete(),i.delete(),a.delete(),o.delete(),u}function qd(e,n){let r=new e.TColgp_Array1OfPnt_2(1,n.length),i=new e.gp_Pnt_1;for(let e=0;e<n.length;e++){let a=t(n,e);i.SetCoord_2(a[0],a[1],a[2]),r.SetValue_1(e+1,i)}i.delete();let a=new e.GeomAPI_PointsToBSpline_2(r,3,8,e.GeomAbs_Shape.GeomAbs_C2,1e-6);if(r.delete(),!a.IsDone())throw a.delete(),Error(`Interpolation failed — GeomAPI_PointsToBSpline did not converge`);let o=a.Curve(),s=new e.Handle_Geom_Curve_2(o.get()),c=new e.BRepBuilderAPI_MakeEdge_24(s),l=c.Edge();return c.delete(),a.delete(),l}function Jd(e,n,r,i,a){let o=Bu(n),s=[i[1]*a[2]-i[2]*a[1],i[2]*a[0]-i[0]*a[2],i[0]*a[1]-i[1]*a[0]],c=(e,t)=>[r[0]+e*a[0]+t*s[0],r[1]+e*a[1]+t*s[1],r[2]+e*a[2]+t*s[2]];if(o.__bk2d===`line`)return Gd(e,c(o.ox,o.oy),c(o.ox+o.dx*o.len,o.oy+o.dy*o.len));if(o.__bk2d===`circle`||o.__bk2d===`trimmed`){let t=o;for(;t.__bk2d===`trimmed`;)t=t.basis;if(t.__bk2d===`circle`){let n=t,r=c(n.cx,n.cy),a=n.sense?i:[-i[0],-i[1],-i[2]];if(o.__bk2d===`circle`){let t=new e.gp_Pnt_3(r[0],r[1],r[2]),i=new e.gp_Dir_5(a[0],a[1],a[2]),o=new e.gp_Ax2_4(t,i),s=new e.gp_Circ_2(o,n.radius),c=new e.BRepBuilderAPI_MakeEdge_8(s),l=c.Edge();return c.delete(),s.delete(),o.delete(),i.delete(),t.delete(),l}let s=_(o),[l,u]=h(o,s.first),[d,f]=h(o,(s.first+s.last)/2),[p,m]=h(o,s.last);return Kd(e,c(l,u),c(d,f),c(p,m))}}if(o.__bk2d===`bezier`||o.__bk2d===`bspline`){let n=o.poles.map(([e,t])=>c(e,t));return n.length===2?Gd(e,t(n,0),t(n,1)):qd(e,n)}let l=_(o),u=[];for(let e=0;e<=60;e++){let[t,n]=h(o,l.first+(l.last-l.first)*e/60);u.push(c(t,n))}return qd(e,u)}function Yd(e,t,n){let r=Bu(t),i=_(r),a=[];for(let e=0;e<=60;e++){let[t,o]=h(r,i.first+(i.last-i.first)*e/60),s=n.get().Value(t,o);a.push([s.X(),s.Y(),s.Z()]),s.delete()}return qd(e,a)}function Xd(e,t){return e.BRep_Tool.Surface_2(t)}function Zd(e,t,n){let r=new e.BRepAdaptor_Curve2d_2(t,n),i=Number(r.FirstParameter()),a=Number(r.LastParameter()),o=[];for(let e=0;e<=30;e++){let t=i+(a-i)*e/30,n=r.Value(t);o.push([n.X(),n.Y()]),n.delete()}return r.delete(),nd(o)}function Qd(e,t){e.BRepLib.BuildCurves3d_2(t)}function $d(e,t,n,r){let i=new e.ShapeFix_Wire_2(t,n,r);i.FixEdgeCurves();let a=i.Wire();return i.delete(),a}function ef(e,t,n={}){let{order:r=3,nbPtsOnCur:i=15,nbIter:a=2,tol3d:o=1e-5,tol2d:s=1e-4,maxDeg:c=8,maxSeg:l=9}=n,u=new e.BRepOffsetAPI_MakeFilling(r,i,a,!1,o,s,.01,.1,c,l);for(let n=0;n<t.length;n++){let r=Eo(e,t[n],`edge`);for(let t of r)u.Add_1(t,e.GeomAbs_Shape.GeomAbs_C0,n===0)}let d=new e.Message_ProgressRange_1;u.Build(d);let f=u.Shape();return u.delete(),d.delete(),f}function tf(e){return{wrapCurve2dHandle:e=>qu(e),createCurve2dAdaptor:e=>Ju(e),createPoint2d:(e,t)=>Uu(e,t),createDirection2d:(e,t)=>Wu(e,t),createVector2d:(e,t)=>Gu(e,t),createAxis2d:(e,t,n,r)=>Ku(e,t,n,r),makeLine2d:(e,t,n,r)=>Yu(e,t,n,r),makeCircle2d:(e,t,n,r)=>Xu(e,t,n,r),makeArc2dThreePoints:(e,t,n,r,i,a)=>Zu(e,t,n,r,i,a),makeArc2dTangent:(e,t,n,r,i,a)=>Qu(e,t,n,r,i,a),makeEllipse2d:(e,t,n,r,i,a,o)=>$u(e,t,n,r,i,a,o),makeEllipseArc2d:(e,t,n,r,i,a,o,s,c)=>ed(e,t,n,r,i,a,o,s,c),makeBezier2d:e=>td(e),makeBSpline2d:(e,t)=>nd(e,t),evaluateCurve2d:(e,t)=>rd(e,t),evaluateCurve2dD1:(e,t)=>id(e,t),getCurve2dBounds:e=>ad(e),getCurve2dType:e=>od(e),trimCurve2d:(e,t,n)=>sd(e,t,n),reverseCurve2d:e=>{},copyCurve2d:e=>cd(e),offsetCurve2d:(e,t)=>ld(e,t),translateCurve2d:(e,t,n)=>ud(e,t,n),rotateCurve2d:(e,t,n,r)=>dd(e,t,n,r),scaleCurve2d:(e,t,n,r)=>fd(e,t,n,r),mirrorCurve2dAtPoint:(e,t,n)=>pd(e,t,n),mirrorCurve2dAcrossAxis:(e,t,n,r,i)=>md(e,t,n,r,i),affinityTransform2d:(e,t,n,r,i,a)=>hd(e,t,n,r,i,a),createIdentityGTrsf2d:()=>_d(),createAffinityGTrsf2d:(e,t,n,r,i)=>vd(e,t,n,r,i),createTranslationGTrsf2d:(e,t)=>yd(e,t),createMirrorGTrsf2d:(e,t,n,r,i,a,o)=>bd(e,t,n,r,i,a,o),createRotationGTrsf2d:(e,t,n)=>xd(e,t,n),createScaleGTrsf2d:(e,t,n)=>Sd(e,t,n),setGTrsf2dTranslationPart:(e,t,n)=>{Cd(e,t,n)},multiplyGTrsf2d:(e,t)=>{wd(e,t)},transformCurve2dGeneral:(e,t)=>Td(e,t),intersectCurves2d:(e,t,n)=>Ed(e,t,n),projectPointOnCurve2d:(e,t,n)=>Dd(e,t,n),distanceBetweenCurves2d:(e,t,n,r,i,a)=>Od(e,t,n,r,i,a),approximateCurve2dAsBSpline:(e,t,n,r)=>kd(e,t,n,r),decomposeBSpline2dToBeziers:e=>Ad(e),createBoundingBox2d:()=>jd(),addCurveToBBox2d:(e,t,n)=>{Md(e,t,n)},getBBox2dBounds:e=>Nd(e),mergeBBox2d:(e,t)=>{Pd(e,t)},isBBox2dOut:(e,t)=>Fd(e,t),isBBox2dOutPoint:(e,t,n)=>Id(e,t,n),getCurve2dCircleData:e=>Ld(e),getCurve2dEllipseData:e=>Rd(e),getCurve2dBezierPoles:e=>zd(e),getCurve2dBezierDegree:e=>Bd(e),getCurve2dBSplineData:e=>Vd(e),serializeCurve2d:e=>Hd(e),deserializeCurve2d:e=>Ud(e),splitCurve2d:(e,t)=>Wd(e,t),liftCurve2dToPlane:(t,n,r,i)=>Jd(e,t,n,r,i),buildEdgeOnSurface:(t,n)=>Yd(e,t,n),extractSurfaceFromFace:t=>Xd(e,t),extractCurve2dFromEdge:(t,n)=>Zd(e,t,n),buildCurves3d:t=>{Qd(e,t)},fixWireOnFace:(t,n,r)=>$d(e,t,n,r),fillSurface:(t,n)=>ef(e,t,n)}}function nf(){let e=e=>()=>{throw Error(`${e} is only available with the brepkit kernel`)};return{export3MF:e(`export3MF`),exportGLB:e(`exportGLB`),exportOBJ:e(`exportOBJ`),exportPLY:e(`exportPLY`),import3MF:e(`import3MF`),importOBJ:e(`importOBJ`),importGLB:e(`importGLB`),filletVariable:e(`filletVariable`),helicalSweep:e(`helicalSweep`),sweepWithOptions:e(`sweepWithOptions`),defeature:e(`defeature`),detectSmallFeatures:e(`detectSmallFeatures`),recognizeFeatures:e(`recognizeFeatures`),meshBoolean:(()=>{throw Error(`meshBoolean is only available with the brepkit kernel`)}),edgeToFaceMap:e(`edgeToFaceMap`),sharedEdges:e(`sharedEdges`),adjacentFaces:e(`adjacentFaces`),curveDegreeElevate:e(`curveDegreeElevate`),curveKnotInsert:e(`curveKnotInsert`),curveKnotRemove:e(`curveKnotRemove`),curveSplit:e(`curveSplit`),approximateSurfaceLspia:e(`approximateSurfaceLspia`),untrimFace:e(`untrimFace`),mergeCoincidentVertices:e(`mergeCoincidentVertices`),removeDegenerateEdges:e(`removeDegenerateEdges`),fixFaceOrientations:e(`fixFaceOrientations`),classifyPointRobust:e(`classifyPointRobust`),classifyPointWinding:e(`classifyPointWinding`),executeBatch:e(`executeBatch`),checkpoint:e(`checkpoint`),checkpointCount:e(`checkpointCount`),restoreCheckpoint:e(`restoreCheckpoint`),discardCheckpoint:e(`discardCheckpoint`)}}function rf(e){return{draft:(t,n,r,i,a)=>nu(e,t,n,r,i,a,[],1).shape}}var af=class{oc;kernelId=`occt`;constructor(e){this.oc=e,Object.assign(this,Qo(e),ts(e),bs(e),ps(e),Ks(e),oc(e),Sc(e),Pc(e),Rc(e),qc(e),xo(e),Fo(e),Cl(e),El(e),kl(e),Nl(e),ru(e),Ru(e),tf(e),rf(e),nf())}},of=()=>{};function sf(e){return typeof e==`object`&&!!e&&e.__brepkit}function cf(e,t){return{__brepkit:!0,type:e,id:t,delete:of,HashCode(e){return t%e},IsNull(){return!1}}}function I(e){return cf(`solid`,e)}function lf(e){return cf(`face`,e)}function uf(e){return cf(`edge`,e)}function df(e){return cf(`wire`,e)}function ff(e){return cf(`shell`,e)}function pf(e){let t=cf(`compound`,e);return Of.has(e)?{...t,delete:()=>Of.delete(e)}:t}function mf(e){return cf(`vertex`,e)}function L(e,t){if(!sf(e))throw Error(`brepkit: expected a BrepkitHandle, got `+typeof e);if(t&&e.type!==t)throw Error(`brepkit: expected ${t} handle, got ${e.type}`);return e.id}function R(e){return Array.from(e)}function hf(e,t){if(!sf(e))throw Error(`brepkit: expected a BrepkitHandle, got `+typeof e);if(e.type!==`solid`)throw Error(`brepkit: ${t} requires a solid, got ${e.type}. Consider using makeCompound() to combine shapes first.`);return e.id}function gf(e,t,n){if(!sf(t))throw Error(`brepkit: expected a BrepkitHandle, got `+typeof t);if(t.type===`solid`)return[t.id];if(t.type===`compound`){let r=R(e.getCompoundSolids(t.id));if(r.length>0)return r;throw Error(`brepkit: ${n} received a compound with no solids.`)}throw Error(`brepkit: ${n} requires a solid or compound of solids, got ${t.type}.`)}function _f(e,t,n,r,i,a){let o=e-r,s=t-i,c=n-a;return Math.sqrt(o*o+s*s+c*c)}function vf(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}function yf(e,t,n){return[1,0,0,e,0,1,0,t,0,0,1,n,0,0,0,1]}function bf(e,t=[0,0,1],n=[0,0,0]){let r=e*Math.PI/180,i=Math.cos(r),a=Math.sin(r),o=1-i,s=Math.sqrt(t[0]**2+t[1]**2+t[2]**2),[c,l,u]=[t[0]/s,t[1]/s,t[2]/s],d=o*c*c+i,f=o*c*l-a*u,p=o*c*u+a*l,m=o*l*c+a*u,h=o*l*l+i,g=o*l*u-a*c,_=o*u*c-a*l,v=o*u*l+a*c,y=o*u*u+i,[b,x,S]=n;return[d,f,p,b-(d*b+f*x+p*S),m,h,g,x-(m*b+h*x+g*S),_,v,y,S-(_*b+v*x+y*S),0,0,0,1]}function xf(e,t){let[n,r,i]=e;return[t,0,0,n*(1-t),0,t,0,r*(1-t),0,0,t,i*(1-t),0,0,0,1]}function Sf(e,n){let r=n=>t(e,n);return[r(0),r(1),r(2),n[0],r(3),r(4),r(5),n[1],r(6),r(7),r(8),n[2],0,0,0,1]}function Cf(e,t){let[n,r,i]=e,a=Math.sqrt(t[0]**2+t[1]**2+t[2]**2),o=t[0]/a,s=t[1]/a,c=t[2]/a,l=2*(n*o+r*s+i*c);return[1-2*o*o,-2*o*s,-2*o*c,l*o,-2*s*o,1-2*s*s,-2*s*c,l*s,-2*c*o,-2*c*s,1-2*c*c,l*c,0,0,0,1]}function wf(e,t){let n=Array(16).fill(0);for(let r=0;r<4;r++)for(let i=0;i<4;i++)for(let a=0;a<4;a++)n[r*4+i]=n[r*4+i]+e[r*4+a]*t[a*4+i];return n}var Tf=.01,Ef=9e5;function Df(){return Ef++}var Of=new Map,kf=new Set;function Af(e,t){kf.has(e)||(kf.add(e),console.warn(`brepkit: ${t}`))}function jf(e){return e.optimisation!==void 0||e.simplify!==void 0||e.strategy!==void 0||e.fuzzyValue!==void 0}function Mf(e){return e}function Nf(e){let t=e;for(;t.__bk2d===`trimmed`;)t=t.basis;return t}function Pf(e){return e}function Ff(e,t){if(typeof t!=`function`)return t;let n;for(let r of e){let e;try{e=t(r)}catch{throw Error(`brepkit does not support variable draft with multiple distinct angles. Use the OCCT kernel for per-face angle variation, or use a uniform angle.`)}if(n===void 0)n=e;else if(e!==n)throw Error(`brepkit does not support variable draft with multiple distinct angles. Use the OCCT kernel for per-face angle variation, or use a uniform angle.`)}if(n===void 0)throw Error(`draft: no faces provided`);return n}function If(e,t,n){let r=Of.get(t);return r?r.flatMap(t=>t.type===n?[t]:Wf(e,t,n)):n===`solid`?R(e.getCompoundSolids(t)).map(I):n===`face`||n===`edge`||n===`vertex`||n===`wire`?R(e.getCompoundSolids(t)).map(I).flatMap(t=>Wf(e,t,n)):[]}function Lf(e,t,n){switch(n){case`face`:return R(e.getSolidFaces(t)).map(lf);case`edge`:return R(e.getSolidEdges(t)).map(uf);case`vertex`:return R(e.getSolidVertices(t)).map(mf);case`wire`:return R(e.getSolidFaces(t)).flatMap(t=>R(e.getFaceWires(t)).map(df));default:return[]}}function Rf(e,t,n){let r=R(e.getShellFaces(t)).map(lf),i=new Set,a=[];for(let t of r)for(let r of Wf(e,t,n)){let e=L(r);i.has(e)||(i.add(e),a.push(r))}return a}function zf(e,t,n){return n===`face`?R(e.getShellFaces(t)).map(lf):n===`edge`||n===`vertex`?Rf(e,t,n):[]}function Bf(e,t,n,r){return r===`face`?[t]:r===`edge`?R(e.getFaceEdges(n)).map(uf):r===`vertex`?R(e.getFaceVertices(n)).map(mf):r===`wire`?R(e.getFaceWires(n)).map(df):[]}function Vf(e,n){let r=R(e.getWireEdges(n)),i=new Set,a=[];for(let n of r){let r=e.getEdgeVertices(n),o=[[t(r,0),t(r,1),t(r,2)],[t(r,3),t(r,4),t(r,5)]];for(let[t,n,r]of o){let o=`${t},${n},${r}`;i.has(o)||(i.add(o),a.push(mf(e.makeVertex(t,n,r))))}}return a}function Hf(e,t,n,r){return r===`wire`?[t]:r===`edge`?R(e.getWireEdges(n)).map(uf):r===`vertex`?Vf(e,n):[]}function Uf(e,n,r,i){if(i===`edge`)return[n];if(i===`vertex`){let n=e.getEdgeVertices(r),i=e.makeVertex(t(n,0),t(n,1),t(n,2)),a=e.makeVertex(t(n,3),t(n,4),t(n,5));return[mf(i),mf(a)]}return[]}function Wf(e,t,n){let r=L(t);switch(t.type){case`compound`:return If(e,r,n);case`solid`:return Lf(e,r,n);case`shell`:return zf(e,r,n);case`face`:return Bf(e,t,r,n);case`wire`:return Hf(e,t,r,n);case`edge`:return Uf(e,t,r,n);default:return[]}}function Gf(e,t,n){if(Array.isArray(t))for(let e of t)n(e)}function Kf(e,t){if(sf(t))return t.type;throw Error(`brepkit: cannot determine shape type of non-brepkit handle`)}function qf(e,t,n){return sf(t)&&sf(n)&&t.id===n.id&&t.type===n.type}function Jf(e,t,n){return qf(e,t,n)}function Yf(e,t,n){return t}function Xf(e,t,n){return sf(t)?t.id%n:0}function Zf(e,t){return!t||!sf(t)}function Qf(e,t){let n=L(t);return e.getShapeOrientation(n)}function $f(e,t){let n=hf(t,`edgeToFaceMap`);return e.edgeToFaceMap(n)}function ep(e,t,n){let r=L(t,`face`),i=L(n,`face`);return Array.from(e.sharedEdges(r,i)).map(e=>uf(e))}function tp(e,t,n){let r=hf(t,`adjacentFaces`),i=L(n,`face`);return Array.from(e.adjacentFaces(r,i)).map(e=>lf(e))}function np(e,t){let n=t;return n.type===`face`?[n.id]:n.type===`solid`?R(e.getSolidFaces(n.id)):n.type===`shell`?R(e.getShellFaces(n.id)):[]}function rp(e,t,n){let r=t.flatMap(t=>np(e,t)),i=n??1e-7;try{return ff(e.weldShellsAndFaces(r,i))}catch(e){console.warn(`brepkit: weldShellsAndFaces failed, falling back to sewFaces:`,e)}return ff(e.sewFaces(r,i))}function ip(e){return{iterShapes:(t,n)=>Wf(e,t,n),iterShapeList:(t,n)=>{Gf(e,t,n)},shapeType:t=>Kf(e,t),isSame:(t,n)=>qf(e,t,n),isEqual:(t,n)=>Jf(e,t,n),downcast:(t,n)=>Yf(e,t,n),hashCode:(t,n)=>Xf(e,t,n),isNull:t=>Zf(e,t),shapeOrientation:t=>Qf(e,t),edgeToFaceMap:t=>$f(e,t),sharedEdges:(t,n)=>ep(e,t,n),adjacentFaces:(t,n)=>tp(e,t,n),sew:(t,n)=>rp(e,t,n)}}function ap(e,t){return n(e.getVertexPosition(L(t,`vertex`)))}function op(e,t){return e.getSurfaceType(L(t,`face`))}function sp(e,n){let r=e.getSurfaceDomain(L(n,`face`));return{uMin:t(r,0),uMax:t(r,1),vMin:t(r,2),vMax:t(r,3)}}function cp(e,t){return df(e.getFaceOuterWire(L(t,`face`)))}function lp(e,t,r,i){return n(e.evaluateSurfaceNormal(L(t,`face`),r,i))}function up(e,t,r,i){return n(e.evaluateSurface(L(t,`face`),r,i))}function dp(e,n,r){try{let i=e.projectPointOnSurface(L(n,`face`),r[0],r[1],r[2]);return[t(i,0),t(i,1)]}catch(e){return console.warn(`brepkit: uvFromPoint failed:`,e),null}}function fp(e,t,r){return n(e.projectPointOnSurface(L(t,`face`),r[0],r[1],r[2]),2)}function pp(e,r,i){let a=r,o,s=i;if(a.type===`wire`){let n=R(e.getWireEdges(a.id));o=t(n,n.length-1);let r=0;for(let a of n){let n=e.getEdgeCurveParameters(a),c=t(n,1)-t(n,0);if(i<=r+c||a===o){o=a,s=Math.min(t(n,0)+(i-r),t(n,1));break}r+=c}}else o=L(r,`edge`);let c=e.evaluateEdgeCurveD1(o,s);return{point:n(c,0),tangent:n(c,3)}}function mp(e,n){let r=n;if(r.type===`wire`){let n=R(e.getWireEdges(r.id));if(n.length===0)return[0,0];let i=0;for(let r of n){let n=e.getEdgeCurveParameters(r);i+=t(n,1)-t(n,0)}return[0,i]}let i=e.getEdgeCurveParameters(L(n,`edge`));return[t(i,0),t(i,1)]}function hp(e,r,i){let a=r;if(a.type===`wire`){let r=R(e.getWireEdges(a.id)),o=0;for(let a of r){let s=e.getEdgeCurveParameters(a),c=t(s,1)-t(s,0);if(i<=o+c||a===r[r.length-1]){let r=t(s,0)+(i-o);return n(e.evaluateEdgeCurve(a,Math.min(r,t(s,1))))}o+=c}return n(e.evaluateEdgeCurve(t(r,0),i))}return n(e.evaluateEdgeCurve(L(r,`edge`),i))}function gp(e,r){let i=r;if(i.type===`wire`){let r=R(e.getWireEdges(i.id));if(r.length===0)return!1;if(r.length===1)return _p(e.getEdgeVertices(t(r,0)));let a=[];for(let t of r){let r=e.getEdgeVertices(t);a.push(n(r,0)),a.push(n(r,3))}let o=[];for(let e of a){let t=o.findIndex(t=>_f(t[0],t[1],t[2],e[0],e[1],e[2])<1e-7);t>=0?o.splice(t,1):o.push(e)}return o.length===0}return _p(e.getEdgeVertices(L(r,`edge`)))}function _p(e){return _f(t(e,0),t(e,1),t(e,2),t(e,3),t(e,4),t(e,5))<1e-7}function vp(e,t){let n=t;try{if(n.type===`edge`||n.type===`wire`&&R(e.getWireEdges(n.id)).length===1)return gp(e,t)}catch{}return!1}function yp(e,t){try{if(vp(e,t)){let n=mp(e,t);return n[1]-n[0]}}catch{}return 0}function bp(e,t){if(t.type===`wire`){let n=Wf(e,t,`edge`)[0];return n?e.getEdgeCurveType(L(n,`edge`)):`LINE`}return e.getEdgeCurveType(L(t,`edge`))}function xp(e,t,n){let r=L(t,`edge`);return uf(e.curveDegreeElevate(r,n))}function Sp(e,t,n,r){let i=L(t,`edge`);return uf(e.curveKnotInsert(i,n,r))}function Cp(e,t,n,r){let i=L(t,`edge`);return uf(e.curveKnotRemove(i,n,r))}function wp(e,n,r){let i=L(n,`edge`),a=e.curveSplit(i,r);return[uf(t(a,0)),uf(t(a,1))]}function Tp(e,t,n,r,i,a,o,s,c,l){return lf(e.approximateSurfaceLspia(t,n,r,i,a,o,s,c,l))}function Ep(e,t,n,r){let i=L(t,`face`);return lf(e.untrimFace(i,n,r))}function Dp(e,t){return t}function Op(e,t){let r=rm(e,t);return!r||r.controlPoints.length<6?null:n(r.controlPoints,r.controlPoints.length-6)}function kp(e,t){if(sf(t)&&t.type===`face`){let n=t.id,r=JSON.parse(e.getAnalyticSurfaceParams(n));if(r.type===`cylinder`)return{radius:r.radius,isDirect:!0}}return null}function Ap(e,t){return t}function jp(e,n,r,i,a){a!==void 0&&Af(`classify-tolerance`,`classifyPointOnFace() tolerance parameter is not supported; brepkit uses domain-based classification.`);let o=L(n,`face`),s=e.getSurfaceDomain(o);return r<t(s,0)||r>t(s,1)||i<t(s,2)||i>t(s,3)?`out`:`in`}function Mp(e,t,n,r){let i=hf(t,`classifyPointRobust`);return e.classifyPointRobust(i,n[0],n[1],n[2],r)}function Np(e,t,n,r){let i=hf(t,`classifyPointWinding`);return e.classifyPointWinding(i,n[0],n[1],n[2],r)}function Pp(e,t,n,r){let i=hf(t,`detectSmallFeatures`);return Array.from(e.detectSmallFeatures(i,n,r)).map(e=>lf(e))}function Fp(e,t,n){let r=hf(t,`recognizeFeatures`);return e.recognizeFeatures(r,n)}function Ip(e,t,n,r,i){let a=Wf(e,t,`edge`),o=a.length>0?a[0]:t;return{visible:{outline:o,smooth:o,sharp:o},hidden:{outline:o,smooth:o,sharp:o}}}function Lp(e,t){let n=L(t,`edge`),r=e.getNurbsCurveData(n);if(!r)return null;let i=JSON.parse(r);return{degree:i.degree,poles:i.controlPoints,weights:i.weights,knots:i.distinctKnots,multiplicities:i.multiplicities,isPeriodic:i.periodic,isRational:i.rational}}function Rp(e,t){return JSON.parse(e.getNurbsSurfaceDataParity(L(t,`face`)))}function zp(e){return{vertexPosition:t=>ap(e,t),surfaceType:t=>op(e,t),uvBounds:t=>sp(e,t),outerWire:t=>cp(e,t),surfaceNormal:(t,n,r)=>lp(e,t,n,r),pointOnSurface:(t,n,r)=>up(e,t,n,r),uvFromPoint:(t,n)=>dp(e,t,n),projectPointOnFace:(t,n)=>fp(e,t,n),curveTangent:(t,n)=>pp(e,t,n),curveParameters:t=>mp(e,t),curvePointAtParam:(t,n)=>hp(e,t,n),curveIsClosed:t=>gp(e,t),curveIsPeriodic:t=>vp(e,t),curvePeriod:t=>yp(e,t),curveType:t=>bp(e,t),curveDegreeElevate:(t,n)=>xp(e,t,n),curveKnotInsert:(t,n,r)=>Sp(e,t,n,r),curveKnotRemove:(t,n,r)=>Cp(e,t,n,r),curveSplit:(t,n)=>wp(e,t,n),approximateSurfaceLspia:(t,n,r,i,a,o,s,c,l)=>Tp(e,t,n,r,i,a,o,s,c,l),untrimFace:(t,n,r)=>Ep(e,t,n,r),createCurveAdaptor:t=>Dp(e,t),getBezierPenultimatePole:t=>Op(e,t),getSurfaceCylinderData:t=>kp(e,t),reverseSurfaceU:t=>Ap(e,t),classifyPointOnFace:(t,n,r,i)=>jp(e,t,n,r,i),classifyPointRobust:(t,n,r)=>Mp(e,t,n,r),classifyPointWinding:(t,n,r)=>Np(e,t,n,r),detectSmallFeatures:(t,n,r)=>Pp(e,t,n,r),recognizeFeatures:(t,n)=>Fp(e,t,n),projectEdges:(t,n,r,i)=>Ip(e,t,n,r,i),getNurbsCurveData:t=>Lp(e,t),getNurbsSurfaceData:t=>Rp(e,t)}}function Bp(e,t,n){if(Array.isArray(n)&&n.length===16)return $p(e,t,n);throw Error(`brepkit: transform expects a 16-element matrix array`)}function Vp(e,t,n,r,i){return $p(e,t,yf(n,r,i))}function Hp(e,t,n,r,i){return $p(e,t,bf(n,r,i))}function Up(e,t,n,r){let i=t;return i.type===`solid`?I(e.mirror(i.id,n[0],n[1],n[2],r[0],r[1],r[2])):$p(e,t,Cf(n,r))}function Wp(e,t,n,r){return $p(e,t,xf(n,r))}function Gp(e,t,n,r,i){return $p(e,t,Sf(n,r))}function Kp(e,t,n,r){return $p(e,t,Sf(n,r))}function qp(e,t,n,r){let{point:i,tangent:a}=pp(e,n,r),[o,s,c]=a,l=Math.sqrt(o*o+s*s+c*c);if(l<1e-12)return Vp(e,t,i[0],i[1],i[2]);let u=o/l,d=s/l,f=c/l,p=t;if(Math.abs(f+1)<1e-10)p=Hp(e,p,180,[1,0,0]);else if(Math.abs(f-1)>1e-10){let t=[-d,u,0],n=180/Math.PI*Math.acos(Math.max(-1,Math.min(1,f)));p=Hp(e,p,n,t)}return Vp(e,p,i[0],i[1],i[2])}function Jp(e,t,n,r,i){let a=[t];for(let o=1;o<i;o++){let i=r*o;a.push(Vp(e,t,n[0]*i,n[1]*i,n[2]*i))}return a}function Yp(e,t,n,r,i,a){let o=[t];for(let s=1;s<a;s++)o.push(Hp(e,t,i*s,r,n));return o}function Xp(e,t,n,r,i,a,o,s){return pf(e.gridPattern(hf(t,`gridPattern`),n[0],n[1],n[2],r[0],r[1],r[2],i,a,o,s))}function Zp(e,t){return t.map(t=>{switch(t.type){case`translate`:return Vp(e,t.shape,t.x,t.y,t.z);case`rotate`:return Hp(e,t.shape,t.angle,t.axis,t.center);case`scale`:return Wp(e,t.shape,t.center,t.factor);case`mirror`:return Up(e,t.shape,t.origin,t.normal)}})}function Qp(e){return{transform:(t,n)=>Bp(e,t,n),translate:(t,n,r,i)=>Vp(e,t,n,r,i),rotate:(t,n,r,i)=>Hp(e,t,n,r,i),mirror:(t,n,r)=>Up(e,t,n,r),scale:(t,n,r)=>Wp(e,t,n,r),generalTransform:(t,n,r,i)=>Gp(e,t,n,r,i),generalTransformNonOrthogonal:(t,n,r)=>Kp(e,t,n,r),positionOnCurve:(t,n,r)=>qp(e,t,n,r),linearPattern:(t,n,r,i)=>Jp(e,t,n,r,i),circularPattern:(t,n,r,i,a)=>Yp(e,t,n,r,i,a),gridPattern:(t,n,r,i,a,o,s)=>Xp(e,t,n,r,i,a,o,s),transformBatch:t=>Zp(e,t)}}function $p(e,t,n){let r=t;if(!sf(t))throw Error(`brepkit: applyMatrix requires a BrepkitHandle`);switch(r.type){case`solid`:{let t=e.copySolid(r.id);return e.transformSolid(t,n),I(t)}case`face`:{if(typeof e.copyFace!=`function`)throw Error(`brepkit: applyMatrix for faces requires copyFace/transformFace WASM exports`);let t=e.copyFace(r.id);return e.transformFace(t,n),lf(t)}case`wire`:{if(typeof e.copyWire!=`function`||typeof e.transformWire!=`function`)throw Error(`brepkit: applyMatrix for wires requires copyWire/transformWire WASM exports`);let t=e.copyWire(r.id);return e.transformWire(t,n),df(t)}case`edge`:{if(typeof e.copyEdge!=`function`||typeof e.transformEdge!=`function`)throw Error(`brepkit: applyMatrix for edges requires copyEdge/transformEdge WASM exports`);let t=e.copyEdge(r.id);return e.transformEdge(t,n),uf(t)}default:throw Error(`brepkit: applyMatrix does not support '${r.type}' shapes`)}}function em(e,t){return!!(e&&(e[0]!==0||e[1]!==0||e[2]!==0)||t&&(t[0]!==0||t[1]!==0||t[2]!==1))}function tm(e,t,n,r){let i=t;if(r&&(r[0]!==0||r[1]!==0||r[2]!==1)){let[t,n,a]=r,o=Math.sqrt(t*t+n*n+a*a),s=t/o,c=n/o,l=a/o;if(Math.abs(l+1)<1e-10)i=Hp(e,i,180,[1,0,0]);else if(Math.abs(l-1)>1e-10){let t=[-c,s,0],n=180/Math.PI*Math.acos(Math.max(-1,Math.min(1,l)));i=Hp(e,i,n,t)}}return n&&(n[0]!==0||n[1]!==0||n[2]!==0)&&(i=Vp(e,i,n[0],n[1],n[2])),i}function nm(e,t){let r,i=t;if(i.type===`solid`||i.type===`compound`){let n=Wf(e,t,`face`);if(n.length===0)throw Error(`brepkit: extractPlaneFromFace: no faces found`);let i=n[0];if(!i)throw Error(`brepkit: extractPlaneFromFace: no faces found`);let a=L(i,`face`),o=0;for(let t of n){let n=L(t,`face`);try{let t=e.faceArea(n,Tf);t>o&&(o=t,a=n)}catch{}}r=a}else r=L(t,`face`);let a=n(e.getFaceNormal(r)),o=e.tessellateFace(r,1).positions;return o.length>=3?{point:n(o),normal:a}:{point:[0,0,0],normal:a}}function rm(e,n){let r=n;if(r.type!==`edge`)return null;let i=e.getEdgeNurbsData(r.id);if(i){let e=JSON.parse(i);return{degree:e.degree,knots:e.knots,controlPoints:e.controlPoints,weights:e.weights}}let a=e.getEdgeVertices(r.id);return{degree:1,knots:[0,0,1,1],controlPoints:[t(a,0),t(a,1),t(a,2),t(a,3),t(a,4),t(a,5)],weights:[1,1]}}function im(e,t){if(!sf(t))return!1;if(t.type!==`solid`)return!0;try{return e.validateSolidRelaxed(t.id)===0}catch(e){return console.warn(`brepkit: isValid check failed:`,e),!1}}function am(e,t){if(!sf(t))return!1;if(t.type!==`solid`)return!0;try{return e.validateSolid(t.id)===0}catch(e){return console.warn(`brepkit: isValidStrict check failed:`,e),!1}}function om(e,t){let n=t;if(n.type!==`solid`)throw Error(`brepkit: healSolid requires a solid, got ${n.type}. Consider using makeCompound() to combine shapes first.`);try{let n=e.repairSolid(L(t));return n>0&&console.warn(`brepkit: repairSolid left ${n} error(s) on solid.`),t}catch(n){try{return e.healSolid(L(t)),t}catch(e){return console.warn(`brepkit: healSolid failed (repairSolid error:`,n,`, healSolid error:`,e,`)`),null}}}function sm(e,t){return t}function cm(e,t,n){return t}function lm(e,t,n){let r=hf(t,`mergeCoincidentVertices`);return e.mergeCoincidentVertices(r,n)}function um(e,t,n){let r=hf(t,`removeDegenerateEdges`);return e.removeDegenerateEdges(r,n)}function dm(e,t){let n=hf(t,`fixFaceOrientations`);return e.fixFaceOrientations(n)}function fm(e,t){let n=t;return n.type===`solid`&&e.healSolid(n.id),t}function pm(e,t){return t}function mm(e,t){if(!sf(t)||t.type!==`solid`)return null;try{return typeof e.validateSolidDetails==`function`?e.validateSolidDetails(t.id):null}catch{return null}}function hm(e){return{isValid:t=>im(e,t),isValidStrict:t=>am(e,t),healSolid:t=>om(e,t),healFace:t=>sm(e,t),healWire:(t,n)=>cm(e,t,n),fixShape:t=>fm(e,t),fixSelfIntersection:t=>pm(e,t),mergeCoincidentVertices:(t,n)=>lm(e,t,n),removeDegenerateEdges:(t,n)=>um(e,t,n),fixFaceOrientations:t=>dm(e,t),validationDetails:t=>mm(e,t)}}function gm(e){if(!(e instanceof Error))return!1;let t=e.message;return t.startsWith(`empty result:`)||t.includes(`produced empty result`)||t.includes(`produces empty result`)}function _m(e,t){return t.type===`compound`?R(e.getCompoundSolids(t.id)).length===0:!1}function vm(e){return pf(e.makeCompound([]))}function ym(e,t,n,r){if(r&&jf(r)&&Af(`boolean-options`,`BooleanOptions (optimisation, simplify, strategy, fuzzyValue) not supported; ignored.`),_m(e,t))return n;if(_m(e,n))return t;let i=hf(t,`fuse`),a=n;if(a.type===`compound`){let t=R(e.getCompoundSolids(a.id)),n=i;for(let r of t)n=e.fuse(n,r);return I(n)}return I(e.fuse(i,hf(n,`fuse`)))}function bm(e,t,n,r){if(r&&jf(r)&&Af(`boolean-options`,`BooleanOptions (optimisation, simplify, strategy, fuzzyValue) not supported; ignored.`),_m(e,t))return vm(e);if(_m(e,n))return t;let i=hf(t,`cut`),a=n;if(a.type===`compound`){let t=R(e.getCompoundSolids(a.id)),n=i;for(let r of t)try{n=e.cut(n,r)}catch(t){if(gm(t))return vm(e);throw t}return I(n)}try{return I(e.cut(i,hf(n,`cut`)))}catch(t){if(gm(t))return vm(e);throw t}}function xm(e,t,n,r){if(r&&jf(r)&&Af(`boolean-options`,`BooleanOptions (optimisation, simplify, strategy, fuzzyValue) not supported; ignored.`),_m(e,t)||_m(e,n))return vm(e);try{return I(e.intersect(hf(t,`intersect`),hf(n,`intersect`)))}catch(t){if(gm(t))return vm(e);throw t}}function Sm(e,n,r,i){let{point:a,normal:o}=nm(e,r),s=sf(n)&&n.type===`solid`?n.id:L(n,`solid`),c=R(e.section(s,a[0],a[1],a[2],o[0],o[1],o[2]));if(c.length===0)return pf(e.makeCompound([]));let l=[];for(let n=0;n<c.length;n++){let r=R(e.getFaceWires(t(c,n)));for(let e=0;e<r.length;e++)l.push(df(t(r,e)))}let[u]=l;if(l.length===1&&u!==void 0)return u;let d=Df();return Of.set(d,l),pf(d)}function Cm(e,n,r){if(n.length===0)throw Error(`brepkit: fuseAll requires at least one shape`);if(n.length===1)return t(n,0);if(e.compoundFuse){let t=[];for(let r of n){let n=r;n.type===`compound`?t.push(...R(e.getCompoundSolids(n.id))):t.push(hf(r,`fuseAll`))}if(t.length===0)throw Error(`brepkit: fuseAll resolved to zero solid IDs`);return I(e.compoundFuse(new Uint32Array(t)))}let i=[...n];for(;i.length>1;){let t=[];for(let n=0;n<i.length;n+=2)n+1<i.length?t.push(ym(e,i[n],i[n+1],r)):t.push(i[n]);i=t}return t(i,0)}function wm(e,t,n,r){if(n.length===0)return t;if(n.length===1)return bm(e,t,n[0],r);let i=hf(t,`cutAll`),a=[];for(let t of n){let n=t;n.type===`compound`?a.push(...R(e.getCompoundSolids(n.id))):a.push(hf(t,`cutAll`))}return a.length===0?t:I(e.compoundCut(i,new Uint32Array(a)))}function Tm(e,t,n){if(n.length===0)throw Error(`brepkit: split requires at least one tool`);let{point:r,normal:i}=nm(e,n[0]),a=R(e.split(L(t,`solid`),r[0],r[1],r[2],i[0],i[1],i[2]));return pf(e.makeCompound(a))}function Em(e,t,n,r,i,a,o){let s=e.meshBoolean(t,n,r,i,a,o);return{vertices:new Float32Array(s.positions),normals:new Float32Array(s.normals),triangles:new Uint32Array(s.indices),uvs:new Float32Array,faceGroups:[{start:0,count:s.indices.length,faceHash:0}]}}function Dm(e,t,n,r,i){let a=[];return(!sf(t)||t.IsNull())&&a.push({operand:`base`,issue:`null-shape`,message:`Base shape is null`}),(!sf(n)||n.IsNull())&&a.push({operand:`tool`,issue:`null-shape`,message:`Tool shape is null`}),a.length>0?{valid:!1,issues:a}:(i(t)||a.push({operand:`base`,issue:`not-valid`,message:`Base shape fails BRepCheck validation. Try autoHeal() first.`}),i(n)||a.push({operand:`tool`,issue:`not-valid`,message:`Tool shape fails BRepCheck validation. Try autoHeal() first.`}),{valid:a.length===0,issues:a})}function Om(e,n,r){let i=[];for(let r of n){let n=r;if(n.type===`solid`){let r=R(e.getSolidVertices(n.id));for(let n of r){let r=e.getVertexPosition(n);i.push(t(r,0),t(r,1),t(r,2))}}else if(n.type===`vertex`){let r=e.getVertexPosition(n.id);i.push(t(r,0),t(r,1),t(r,2))}}if(i.length<12)throw Error(`brepkit: hull requires enough points`);return I(e.convexHull(i))}function km(e,t,n){if(t.length<4)throw Error(`brepkit: hull needs at least 4 points`);let r=[];for(let e of t)r.push(e.x,e.y,e.z);return I(e.convexHull(r))}function Am(e,n,r,i){let a=new Float64Array(n.length*3);for(let e=0;e<n.length;e++){let r=t(n,e);a[e*3]=r.x,a[e*3+1]=r.y,a[e*3+2]=r.z}let o=new Uint32Array(r.length*3);for(let e=0;e<r.length;e++){let n=t(r,e);o[e*3]=n[0],o[e*3+1]=n[1],o[e*3+2]=n[2]}return I(e.importIndexedMesh(a,o))}function jm(e){return{fuse:(t,n,r)=>ym(e,t,n,r),cut:(t,n,r)=>bm(e,t,n,r),intersect:(t,n,r)=>xm(e,t,n,r),section:(t,n,r)=>Sm(e,t,n,r),fuseAll:(t,n)=>Cm(e,t,n),cutAll:(t,n,r)=>wm(e,t,n,r),split:(t,n)=>Tm(e,t,n),meshBoolean:(t,n,r,i,a,o)=>Em(e,t,n,r,i,a,o),checkBoolean:(t,n,r)=>Dm(e,t,n,r,t=>im(e,t)),hull:(t,n)=>Om(e,t,n),hullFromPoints:(t,n)=>km(e,t,n),buildSolidFromFaces:(t,n,r)=>Am(e,t,n,r)}}function Mm(e,t,n,r){return mf(e.makeVertex(t,n,r))}function Nm(e,t,n,r){if(t&&typeof t==`object`&&`origin`in t&&`direction`in t){let{origin:i,direction:a}=t,o=n??0,s=r??1;return Um(e,[i[0]+a[0]*o,i[1]+a[1]*o,i[2]+a[2]*o],[i[0]+a[0]*s,i[1]+a[1]*s,i[2]+a[2]*s])}if(sf(t)&&t.type===`edge`)return t;throw Error(`brepkit: makeEdge requires a curve with origin/direction, or an edge handle`)}function Pm(e,t){let n=[];for(let r of t){let t=r;if(t.type===`wire`)for(let r of R(e.getWireEdges(t.id)))n.push(r);else n.push(L(r,`edge`))}return df(e.makeWire(n,!0))}function Fm(e,t,n){let r=t,i=r.type===`edge`?e.makeWire([r.id],!0):L(t,`wire`);return lf(n?e.makePlanarFaceFromWire(i):e.makeFaceFromWire(i))}function Im(e,t,n,r){return I(e.makeBox(t,n,r))}function Lm(e,t,n){return lf(e.makeRectangle(t,n))}function Rm(e,t,n,r,i){let a=I(e.makeCylinder(t,n));return em(r,i)?tm(e,a,r,i):a}function zm(e,t,n){let r=I(e.makeSphere(t,32));return n&&(n[0]!==0||n[1]!==0||n[2]!==0)?Vp(e,r,n[0],n[1],n[2]):r}function Bm(e,t,n,r,i,a){let o=I(e.makeCone(t,n,r));return em(i,a)?tm(e,o,i,a):o}function Vm(e,t,n,r,i){let a=I(e.makeTorus(t,n,32));return em(r,i)?tm(e,a,r,i):a}function Hm(e,t,n,r){let i=Math.max(t,n,r);return Gp(e,zm(e,i),[t/i,0,0,0,n/i,0,0,0,r/i],[0,0,0],!1)}function Um(e,t,n){return uf(e.makeLineEdge(t[0],t[1],t[2],n[0],n[1],n[2]))}function Wm(e,t,n,r){let i=Math.sqrt(n[0]**2+n[1]**2+n[2]**2);return uf(e.makeCircleEdge(t[0],t[1],t[2],n[0]/i,n[1]/i,n[2]/i,r))}function Gm(e,t,n,r,i,a){return yh(e,t,n,r,i,a)}function Km(e,t,n,r,i,a){let o=2*(e*(r-a)+n*(a-t)+i*(t-r));return Math.abs(o)<1e-12?null:[((e**2+t**2)*(r-a)+(n**2+r**2)*(a-t)+(i**2+a**2)*(t-r))/o,((e**2+t**2)*(i-n)+(n**2+r**2)*(e-i)+(i**2+a**2)*(n-e))/o]}function qm(e,t,n,r){let i=[n[0]-t[0],n[1]-t[1],n[2]-t[2]],a=[r[0]-t[0],r[1]-t[1],r[2]-t[2]],o=[i[1]*a[2]-i[2]*a[1],i[2]*a[0]-i[0]*a[2],i[0]*a[1]-i[1]*a[0]],s=Math.sqrt(o[0]**2+o[1]**2+o[2]**2);if(s<1e-12)return Um(e,t,r);let c=[o[0]/s,o[1]/s,o[2]/s],l=Math.sqrt(i[0]**2+i[1]**2+i[2]**2),u=[i[0]/l,i[1]/l,i[2]/l],d=[c[1]*u[2]-c[2]*u[1],c[2]*u[0]-c[0]*u[2],c[0]*u[1]-c[1]*u[0]],f=e=>{let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return[n*u[0]+r*u[1]+i*u[2],n*d[0]+r*d[1]+i*d[2]]},[p,m]=f(t),[h,g]=f(n),[_,v]=f(r),y=Km(p,m,h,g,_,v);if(!y)return Um(e,t,r);let[b,x]=y,S=[t[0]+b*u[0]+x*d[0],t[1]+b*u[1]+x*d[1],t[2]+b*u[2]+x*d[2]];return uf(e.makeCircleArc3d(t[0],t[1],t[2],r[0],r[1],r[2],S[0],S[1],S[2],c[0],c[1],c[2]))}function Jm(e,t,n,r,i,a){let o=Math.sqrt(n[0]**2+n[1]**2+n[2]**2);if(a!==void 0){let s=Math.sqrt(a[0]**2+a[1]**2+a[2]**2);return uf(e.makeEllipseEdgeWithRef(t[0],t[1],t[2],n[0]/o,n[1]/o,n[2]/o,r,i,a[0]/s,a[1]/s,a[2]/s))}return uf(e.makeEllipseEdge(t[0],t[1],t[2],n[0]/o,n[1]/o,n[2]/o,r,i))}function Ym(e,t,n,r,i,a,o,s){return bh(e,t,n,r,i,a,o,s)}function Xm(e,n){if(n.length<2)throw Error(`brepkit: bezier requires at least 2 points`);let r=n.length-1,i=n.length,a=[...Array(r+1).fill(0),...Array(r+1).fill(1)],o=Array(i).fill(1),s=n.flatMap(([e,t,n])=>[e,t,n]),c=t(n,0),l=t(n,i-1);return uf(e.makeNurbsEdge(c[0],c[1],c[2],l[0],l[1],l[2],r,a,s,o))}function Zm(e,t,n,r){return uf(e.makeTangentArc3d(t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]))}function Qm(e,t,n,r,i,a,o){let s=n/t,c=Math.max(4,Math.ceil(s*16)),l=i?.[0]??0,u=i?.[1]??0,d=i?.[2]??0,f=o?-1:1,p=[];for(let e=0;e<=c;e++){let t=e/c,i=f*2*Math.PI*s*t;p.push([l+r*Math.cos(i),u+r*Math.sin(i),d+n*t])}return Pm(e,[dh(e,p)])}function $m(e,t){let n=[];for(let r of t){let t=r;if(t.type===`edge`)n.push(t.id);else if(t.type===`wire`)for(let r of R(e.getWireEdges(t.id)))n.push(r)}if(n.length===0)throw Error(`brepkit: makeWireFromMixed requires at least one edge`);return df(e.makeWire(n,!1))}function eh(e,t){let n=t.filter(sf);if(n.length===0)throw Error(`brepkit: makeCompound requires at least one shape`);if(n.every(e=>e.type===`solid`))return pf(e.makeCompound(n.map(e=>e.id)));let r=Df();return Of.set(r,n),pf(r)}function th(e,t,n){let r=Im(e,Math.abs(n[0]-t[0]),Math.abs(n[1]-t[1]),Math.abs(n[2]-t[2])),i=Math.min(t[0],n[0]),a=Math.min(t[1],n[1]),o=Math.min(t[2],n[2]);return i!==0||a!==0||o!==0?Vp(e,r,i,a,o):r}function nh(e,t){let n=t;if(n.type===`solid`)return t;if(n.type===`shell`){try{return e.getSolidFaces(n.id),I(n.id)}catch{}return I(e.solidFromShell(n.id))}return I(e.solidFromShell(L(t,`shell`)))}function rh(e,t){return Fm(e,t,!1)}function ih(e,t,n){let r=n.map(e=>L(e,`wire`));return lf(e.addHolesToFace(L(t,`face`),r))}function ah(e,t){return lf(e.removeHolesFromFace(L(t,`face`)))}function oh(e,t,n){return Fm(e,n,!1)}function sh(e,t,n,r){let i=[];for(let[e,n,r]of t)i.push(e,n,r);let a=Math.min(3,n-1),o=Math.min(3,r-1);try{return lf(e.interpolateSurface(i,n,r,a,o))}catch{return ch(e,t,n,r)}}function ch(e,n,r,i){let a=[];for(let o=0;o<r-1;o++)for(let r=0;r<i-1;r++){let s=o*i+r,c=(o+1)*i+r,l=o*i+(r+1),u=(o+1)*i+(r+1),d=lh(e,t(n,s),t(n,c),t(n,l));d&&a.push(d);let f=lh(e,t(n,c),t(n,u),t(n,l));f&&a.push(f)}if(a.length===0)throw Error(`brepkit: no valid faces in surface grid`);return rp(e,a,1e-6)}function lh(e,t,n,r){let i=n[0]-t[0],a=n[1]-t[1],o=n[2]-t[2],s=r[0]-t[0],c=r[1]-t[1],l=r[2]-t[2],u=a*l-o*c,d=o*s-i*l,f=i*c-a*s;if(Math.sqrt(u*u+d*d+f*f)<1e-12)return null;try{return Fm(e,Pm(e,[Um(e,t,n),Um(e,n,r),Um(e,r,t)]))}catch(e){return console.warn(`brepkit: makeNonPlanarFace failed:`,e),null}}function uh(e,t,n){let r=t.map(e=>L(e,`face`));return I(e.sewFaces(r,n))}function dh(e,n,r){if(r?.tolerance!==void 0&&Af(`interpolate-tolerance`,`interpolatePoints() tolerance parameter is not supported; brepkit uses chord-length parameterisation.`),n.length<2)throw Error(`brepkit: need at least 2 points`);if(n.length===2)return Um(e,t(n,0),t(n,1));let i=Math.min(3,n.length-1),a=n.flatMap(([e,t,n])=>[e,t,n]);return uf(e.interpolatePoints(a,i))}function fh(e,t,n){let r=n?.degMax??3,i=n?.tolerance??1e-6,a=[];for(let e of t)a.push(e[0],e[1],e[2]);let o=Math.max(r+1,Math.min(t.length,Math.ceil(t.length*.7)));return uf(e.approximateCurveLspia(a,r,o,i,100))}function ph(e,t,n,r){return{x:t,y:n,z:r}}function mh(e,t,n,r){let i=Math.sqrt(t*t+n*n+r*r);return{x:t/i,y:n/i,z:r/i}}function hh(e,t,n,r){return{x:t,y:n,z:r}}function gh(e,t,n,r,i,a,o){return{origin:[t,n,r],direction:[i,a,o]}}function _h(e,t,n,r,i,a,o,s,c,l){return{origin:[t,n,r],z:[i,a,o],x:s===void 0?void 0:[s,c,l]}}function vh(e,t,n,r,i,a,o,s,c,l){return{origin:[t,n,r],z:[i,a,o],x:s===void 0?void 0:[s,c,l]}}function yh(e,n,r,i,a,o){let s=Math.sqrt(r[0]**2+r[1]**2+r[2]**2),c=[r[0]/s,r[1]/s,r[2]/s],l=Math.abs(c[0])<.9?[1,0,0]:[0,1,0],u=[c[1]*l[2]-c[2]*l[1],c[2]*l[0]-c[0]*l[2],c[0]*l[1]-c[1]*l[0]],d=Math.sqrt(u[0]**2+u[1]**2+u[2]**2),f=[u[0]/d,u[1]/d,u[2]/d],p=[c[1]*f[2]-c[2]*f[1],c[2]*f[0]-c[0]*f[2],c[0]*f[1]-c[1]*f[0]],m=Math.ceil(Math.abs(o-a)/(Math.PI/2)),h=(o-a)/m,g=[],_=[];for(let e=0;e<=m;e++){let t=a+e*h,r=Math.cos(t),o=Math.sin(t),s=n[0]+i*(r*f[0]+o*p[0]),c=n[1]+i*(r*f[1]+o*p[1]),l=n[2]+i*(r*f[2]+o*p[2]);if(e>0){let t=a+(e-.5)*h,r=Math.cos(t),o=Math.sin(t),s=i/Math.cos(h/2),c=n[0]+s*(r*f[0]+o*p[0]),l=n[1]+s*(r*f[1]+o*p[1]),u=n[2]+s*(r*f[2]+o*p[2]);g.push(c,l,u),_.push(Math.cos(h/2))}g.push(s,c,l),_.push(1)}let v=[,,,].fill(0);for(let e=1;e<m;e++)v.push(e,e);v.push(...[,,,].fill(m));let y=t(v,v.length-1);for(let e=0;e<v.length;e++)v[e]=t(v,e)/y;let b=t(g,0),x=t(g,1),S=t(g,2),C=t(g,g.length-3),w=t(g,g.length-2),ee=t(g,g.length-1);return uf(e.makeNurbsEdge(b,x,S,C,w,ee,2,v,g,_))}function bh(e,n,r,i,a,o,s,c){let l=Math.sqrt(r[0]**2+r[1]**2+r[2]**2),u=[r[0]/l,r[1]/l,r[2]/l],d;if(c){let e=Math.sqrt(c[0]**2+c[1]**2+c[2]**2);d=[c[0]/e,c[1]/e,c[2]/e]}else{let e=Math.abs(u[0])<.9?[1,0,0]:[0,1,0],t=[u[1]*e[2]-u[2]*e[1],u[2]*e[0]-u[0]*e[2],u[0]*e[1]-u[1]*e[0]],n=Math.sqrt(t[0]**2+t[1]**2+t[2]**2);d=[t[0]/n,t[1]/n,t[2]/n]}let f=[u[1]*d[2]-u[2]*d[1],u[2]*d[0]-u[0]*d[2],u[0]*d[1]-u[1]*d[0]],p=Math.ceil(Math.abs(s-o)/(Math.PI/2)),m=(s-o)/p,h=[],g=[];for(let e=0;e<=p;e++){let t=o+e*m,r=Math.cos(t),s=Math.sin(t),c=n[0]+i*r*d[0]+a*s*f[0],l=n[1]+i*r*d[1]+a*s*f[1],u=n[2]+i*r*d[2]+a*s*f[2];if(e>0){let t=o+(e-.5)*m,r=Math.cos(t),s=Math.sin(t),c=1/Math.cos(m/2),l=n[0]+i*c*r*d[0]+a*c*s*f[0],u=n[1]+i*c*r*d[1]+a*c*s*f[1],p=n[2]+i*c*r*d[2]+a*c*s*f[2];h.push(l,u,p),g.push(Math.cos(m/2))}h.push(c,l,u),g.push(1)}let _=[,,,].fill(0);for(let e=1;e<p;e++)_.push(e,e);_.push(...[,,,].fill(p));let v=t(_,_.length-1);for(let e=0;e<_.length;e++)_[e]=t(_,e)/v;let y=t(h,0),b=t(h,1),x=t(h,2),S=t(h,h.length-3),C=t(h,h.length-2),w=t(h,h.length-1);return uf(e.makeNurbsEdge(y,b,x,S,C,w,2,_,h,g))}function xh(e){return{makeVertex:(t,n,r)=>Mm(e,t,n,r),makeEdge:(t,n,r)=>Nm(e,t,n,r),makeWire:t=>Pm(e,t),makeWireFromMixed:t=>$m(e,t),makeFace:(t,n)=>Fm(e,t,n),makeBox:(t,n,r)=>Im(e,t,n,r),makeRectangle:(t,n)=>Lm(e,t,n),makeCylinder:(t,n,r,i)=>Rm(e,t,n,r,i),makeSphere:(t,n)=>zm(e,t,n),makeCone:(t,n,r,i,a)=>Bm(e,t,n,r,i,a),makeTorus:(t,n,r,i)=>Vm(e,t,n,r,i),makeEllipsoid:(t,n,r)=>Hm(e,t,n,r),makeLineEdge:(t,n)=>Um(e,t,n),makeCircleEdge:(t,n,r)=>Wm(e,t,n,r),makeCircleArc:(t,n,r,i,a)=>Gm(e,t,n,r,i,a),makeArcEdge:(t,n,r)=>qm(e,t,n,r),makeEllipseEdge:(t,n,r,i,a)=>Jm(e,t,n,r,i,a),makeEllipseArc:(t,n,r,i,a,o,s)=>Ym(e,t,n,r,i,a,o,s),makeBezierEdge:t=>Xm(e,t),makeTangentArc:(t,n,r)=>Zm(e,t,n,r),makeHelixWire:(t,n,r,i,a,o)=>Qm(e,t,n,r,i,a,o),makeCompound:t=>eh(e,t),makeBoxFromCorners:(t,n)=>th(e,t,n),solidFromShell:t=>nh(e,t),makeNonPlanarFace:t=>rh(e,t),addHolesInFace:(t,n)=>ih(e,t,n),removeHolesFromFace:t=>ah(e,t),makeFaceOnSurface:(t,n)=>oh(e,t,n),bsplineSurface:(t,n,r)=>sh(e,t,n,r),triangulatedSurface:(t,n,r)=>ch(e,t,n,r),buildTriFace:(t,n,r)=>lh(e,t,n,r),sewAndSolidify:(t,n)=>uh(e,t,n),interpolatePoints:(t,n)=>dh(e,t,n),approximatePoints:(t,n)=>fh(e,t,n),createPoint3d:(t,n,r)=>ph(e,t,n,r),createDirection3d:(t,n,r)=>mh(e,t,n,r),createVector3d:(t,n,r)=>hh(e,t,n,r),createAxis1:(t,n,r,i,a,o)=>gh(e,t,n,r,i,a,o),createAxis2:(t,n,r,i,a,o,s,c,l)=>_h(e,t,n,r,i,a,o,s,c,l),createAxis3:(t,n,r,i,a,o,s,c,l)=>vh(e,t,n,r,i,a,o,s,c,l)}}function Sh(e,t,n,r){let i=hf(t,`fillet`),a=n.map(e=>L(e,`edge`));if(typeof r==`number`)return I(e.fillet(i,a,r));let o=[];for(let[e,t]of n.entries()){let n=a[e]??0,i;i=typeof r==`function`?r(t):r;let[s,c]=Array.isArray(i)?i:[i,i];o.push({edge:n,startRadius:s,endRadius:c})}return I(e.filletVariable(i,JSON.stringify(o)))}function Ch(e,t,n,r){let i=hf(t,`chamfer`),a=n.map(e=>L(e,`edge`));if(typeof r==`number`)return I(e.chamfer(i,a,r));if(Array.isArray(r)){let[t,n]=r;return typeof e.chamferAsymmetric==`function`?I(e.chamferAsymmetric(i,a,t,n)):(Af(`chamfer-asymmetric`,`chamferAsymmetric not available; using averaged distance.`),I(e.chamfer(i,a,(t+n)/2)))}let o=new Map;for(let[e,t]of n.entries()){let n=r(t),i=a[e];if(i===void 0)continue;let[s,c]=Array.isArray(n)?n:[n,n],l=`${s},${c}`,u=o.get(l);u?u.ids.push(i):o.set(l,{ids:[i],d1:s,d2:c})}let s=i;for(let t of o.values())t.d1===t.d2?s=e.chamfer(s,t.ids,t.d1):typeof e.chamferAsymmetric==`function`?s=e.chamferAsymmetric(s,t.ids,t.d1,t.d2):(Af(`chamfer-callback`,`chamferAsymmetric not available; asymmetric edges use averaged distance.`),s=e.chamfer(s,t.ids,(t.d1+t.d2)/2));return I(s)}function wh(e,t,n,r,i){let a=r*Math.tan(i*Math.PI/180),o=hf(t,`chamferDistAngle`),s=n.map(e=>L(e,`edge`));return typeof e.chamferAsymmetric==`function`?I(e.chamferAsymmetric(o,s,r,a)):(Af(`chamfer-dist-angle`,`chamferAsymmetric not available; using averaged distance.`),I(e.chamfer(o,s,(r+a)/2)))}function Th(e,n){let r=R(e.getFaceVertices(n));if(r.length<1)return null;let i=0,a=0,o=0;for(let n of r){let r=e.getVertexPosition(n);i+=t(r,0),a+=t(r,1),o+=t(r,2)}let s=r.length;return{x:i/s,y:a/s,z:o/s}}function Eh(e,t,n){try{let r=e.getFaceNormal(t),i=-1,a=-2;for(let t of n)try{let n=e.getFaceNormal(t),o=(r[0]??0)*(n[0]??0)+(r[1]??0)*(n[1]??0)+(r[2]??0)*(n[2]??0);o>a&&(a=o,i=t)}catch{}if(i>=0&&a>.99)return i}catch{}return null}function Dh(e,t,n){try{let r=Th(e,t);if(r===null)return null;let i=-1,a=1/0;for(let t of n)try{let n=Th(e,t);if(n===null)continue;let o=Math.sqrt((r.x-n.x)**2+(r.y-n.y)**2+(r.z-n.z)**2);o<a&&(a=o,i=t)}catch{}if(i>=0&&a<.001)return i}catch{}return null}function Oh(e,t,n,r){if(r.has(t))return t;let i=Eh(e,t,n);if(i!==null)return i;let a=Dh(e,t,n);return a===null?t:a}function kh(e,t,n,r,i){i!==void 0&&Af(`shell-tolerance`,`shell() tolerance parameter is not supported; brepkit uses its own internal tolerance.`);let a=hf(t,`shell`),o=R(e.getSolidFaces(a)),s=new Set(o),c=n.map(t=>Oh(e,L(t,`face`),o,s));return I(e.shell(a,r,c))}function Ah(e,t,n){let r=t;if(r.type===`face`)return I(e.thicken(r.id,n));throw Error(`brepkit: thicken() requires a face`)}function jh(e,t,n,r){r!==void 0&&Af(`offset-tolerance`,`offset() tolerance parameter is not supported; brepkit uses its own internal tolerance.`);let i=t;if(i.type===`face`)return I(e.thicken(i.id,n));let a=hf(t,`offset`);return I(e.offsetSolidV2(a,n))}function Mh(e,t,n){let r=hf(t,`filletVariable`);return I(e.filletVariable(r,n))}function Nh(e,t,n,r,i,a){let o=hf(t,`draft`),s=n.map(e=>L(e,`face`));return I(e.draft(o,s,r[0],r[1],r[2],i[0],i[1],i[2],a))}function Ph(e,t,n){let r=hf(t,`defeature`),i=n.map(e=>L(e,`face`));return I(e.defeature(r,i))}function Fh(e){switch(e){case`arc`:case`tangent`:return`arc`;case`intersection`:return`intersection`;default:return`intersection`}}function Ih(e,n,r,i){if(typeof e.offsetWire2DWithJoin==`function`)return df(e.offsetWire2DWithJoin(L(n,`wire`),r,Fh(i)));let a=Wf(e,n,`edge`);if(a.length===0)return n;let o=[];for(let n of a){let r=e.getEdgeVertices(L(n,`edge`));o.push(t(r,0),t(r,1))}if(o.length<6)return n;let s=e.offsetPolygon2d(o,r,1e-10),c=[];for(let e=0;e<s.length;e+=2)c.push(t(s,e),t(s,e+1),0);return df(e.makePolygonWire(c))}function Lh(e,t){if(t.type===`solid`)try{e.healSolid(L(t))}catch(e){console.warn(`brepkit: healing failed in simplify:`,e)}return t}function Rh(e,t){let n=t,r=e.reverseShape(n.id);return cf(n.type,r)}function zh(e){return{fillet:(t,n,r)=>Sh(e,t,n,r),chamfer:(t,n,r)=>Ch(e,t,n,r),chamferDistAngle:(t,n,r,i)=>wh(e,t,n,r,i),shell:(t,n,r,i)=>kh(e,t,n,r,i),thicken:(t,n)=>Ah(e,t,n),offset:(t,n,r)=>jh(e,t,n,r),filletVariable:(t,n)=>Mh(e,t,n),draft:(t,n,r,i,a)=>Nh(e,t,n,r,i,Ff(n,a)),defeature:(t,n)=>Ph(e,t,n),offsetWire2D:(t,n,r)=>Ih(e,t,n,r),simplify:t=>Lh(e,t),reverseShape:t=>Rh(e,t)}}function Bh(e,t){let n=JSON.parse(e),r=n.evolution;if(!r||typeof r.modified!=`object`||typeof r.generated!=`object`)throw Error(`brepkit: invalid evolution JSON structure`);let i=I(n.solid),a=e=>{let n=new Map;for(let[r,i]of Object.entries(e)){let e=Number(r)%t,a=i.map(e=>e%t),o=n.get(e);o?o.push(...a):n.set(e,a)}return n},o=a(r.modified),s=a(r.generated),c=new Set;for(let e of r.deleted)c.add(e%t);return{shape:i,evolution:{modified:o,generated:s,deleted:c}}}function Vh(e,t){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return n*n+r*r+i*i}function Hh(e,n){try{let r=e.tessellateFace(n,1).positions;if(r.length<3)return[0,0,0];let i=0,a=0,o=0,s=r.length/3;for(let e=0;e<r.length;e+=3)i+=t(r,e),a+=t(r,e+1),o+=t(r,e+2);return[i/s,a/s,o/s]}catch{return[0,0,0]}}function Uh(e,t,n){try{return{hash:n,normal:e.getFaceNormal(t),centroid:Hh(e,t)}}catch{return{hash:n,normal:[0,0,0],centroid:Hh(e,t)}}}var Wh=.707,Gh=100,Kh=.05;function qh(e,n){let r=-1/0,i=[];for(let a=0;a<n.length;a++){let o=t(n,a),s=(e.normal[0]??0)*(o.normal[0]??0)+(e.normal[1]??0)*(o.normal[1]??0)+(e.normal[2]??0)*(o.normal[2]??0);if(s<Wh)continue;let c=Vh(e.centroid,o.centroid);if(c>Gh)continue;let l=s-c/Gh;l>r&&(r=l),i.push({idx:a,score:l})}return{matches:i,bestScore:r}}function Jh(e,t){let n=1/0,r;for(let i of t){let t=Vh(e.centroid,i.centroid);t<n&&(n=t,r=i)}return r}function Yh(e,n,r,i,a,o,s,c){let l=n;if(l.type!==`solid`)return;let u=R(e.getSolidFaces(l.id)),d=Math.min(u.length,r.length),f=[];for(let n=0;n<d;n++){let i=t(u,n);f.push(Uh(e,i,r[n]??i%a))}let p=i.map(t=>Uh(e,t,t%a)),m=new Set;for(let e of p){let{matches:n,bestScore:r}=qh(e,f);if(n.length>0){for(let i of n)if(i.score>=r-Kh){let n=t(f,i.idx),r=o.get(n.hash)??[];r.push(e.hash),o.set(n.hash,r),m.add(i.idx)}}else{let t=Jh(e,f);if(t){let n=s.get(t.hash)??[];n.push(e.hash),s.set(t.hash,n)}}}for(let e=0;e<f.length;e++)m.has(e)||c.add(t(f,e).hash)}function Xh(e,t,n,r,i,a,o,s){let c=new Set(s),l=new Map(a);Yh(e,t,n,r,i,a,o,s),s.clear();for(let e of c)s.add(e);for(let e of n){let t=!l.has(e)&&a.has(e)&&(a.get(e)?.length??0)>0,n=o.has(e)&&(o.get(e)?.length??0)>0;!t&&!n&&s.add(e)}}function Zh(e,n,r,i,a,o){let s=n.filter(e=>!r.has(e));s.length>0&&e.length>0&&a.set(t(e,0),s);for(let t of e)i.has(t)||o.add(t)}function Qh(e,n,r,i,a,o,s,c,l){let u=new Set(i);if(r.some(e=>u.has(e))){let t=new Set(r);for(let e of r)u.has(e)&&o.set(e,[e]);let d=i.filter(e=>!t.has(e)),f=n.filter(e=>!u.has(e%a));l&&d.length>0&&f.length>0?Xh(e,l,d,f,a,o,s,c):Zh(i,r,u,t,s,c)}else if(l)Yh(e,l,i,n,a,o,s,c);else{for(let e=0;e<i.length&&e<r.length;e++)o.set(t(i,e),[t(r,e)]);r.length>i.length&&i.length>0&&s.set(t(i,0),r.slice(i.length))}}function $h(e,n,r,i,a,o){let s=n,c=new Map,l=new Map,u=new Set;if(s.type===`solid`){let n=R(e.getSolidFaces(s.id)),d=n.map(e=>e%i);if(a)for(let e=0;e<r.length&&e<d.length;e++)c.set(t(r,e),[t(d,e)]);else Qh(e,n,d,r,i,c,l,u,o)}return{shape:n,evolution:{modified:c,generated:l,deleted:u}}}function eg(e,t,n,r,i){for(let[a,o]of e){let s=[];for(let e of o){r.add(e);let i=t.get(e);i?s.push(...i):n.has(e)||s.push(e)}s.length>0?e.set(a,s):(e.delete(a),i?.add(a))}}function tg(e,t){let n=new Set;eg(t.combinedModified,e.evolution.modified,e.evolution.deleted,n,t.combinedDeleted),eg(t.combinedGenerated,e.evolution.modified,e.evolution.deleted,n);for(let[r,i]of e.evolution.modified)t.combinedModified.has(r)||n.has(r)||t.combinedModified.set(r,[...i]);for(let[r,i]of e.evolution.generated){if(n.has(r))continue;let e=t.combinedGenerated.get(r)??[];t.combinedGenerated.set(r,[...e,...i])}for(let n of e.evolution.deleted)t.inputFaceHashSet.has(n)&&t.combinedDeleted.add(n)}function ng(e,t,n,r,i,a){let o=R(e.getCompoundSolids(n)),s=t,c={combinedModified:new Map,combinedGenerated:new Map,combinedDeleted:new Set,inputFaceHashSet:new Set(r)};for(let e of o){let t=s;if(t.type!==`solid`)break;let n=Bh(a(t.id,e),i);s=n.shape,tg(n,c)}return{shape:s,accum:c}}function rg(e,t,n,r,i,a,o,s,c){let l={hasErrors:!1,hasWarnings:!1,messages:[]},u=t,d=n;if(r.length>0&&u.type===`solid`){if(d.type===`solid`)try{return{...Bh(o(u.id,d.id),i),diagnostics:l}}catch(e){if(!gm(e))throw e}if(d.type===`compound`){let{shape:n,accum:a}=ng(e,t,d.id,r,i,o);return{shape:n,evolution:{modified:a.combinedModified,generated:a.combinedGenerated,deleted:a.combinedDeleted},diagnostics:l}}}return{...$h(e,s(t,n,a),r,i,!1,t),diagnostics:l}}function ig(e,t,n,r,i,a,o){return $h(e,Vp(e,t,n,r,i),a,o,!0)}function ag(e,t,n,r,i,a,o){return $h(e,Hp(e,t,n*180/Math.PI,a,o),r,i,!0)}function og(e,t,n,r,i,a){return $h(e,Up(e,t,n,r),i,a,!0)}function sg(e,t,n,r,i,a){return $h(e,Wp(e,t,n,r),i,a,!0)}function cg(e,t,n,r,i,a,o){return $h(e,Gp(e,t,n,r,i),a,o,!0)}function lg(e,t,n,r,i,a){return rg(e,t,n,r,i,a,(t,n)=>e.fuseWithEvolution(t,n),(t,n,r)=>ym(e,t,n,r),`fuseWithHistory`)}function ug(e,t,n,r,i,a){return rg(e,t,n,r,i,a,(t,n)=>e.cutWithEvolution(t,n),(t,n,r)=>bm(e,t,n,r),`cutWithHistory`)}function dg(e,t,n,r,i,a){return rg(e,t,n,r,i,a,(t,n)=>e.intersectWithEvolution(t,n),(t,n,r)=>xm(e,t,n,r),`intersectWithHistory`)}function fg(e,t,n,r,i,a){return $h(e,Sh(e,t,n,r),i,a,!1,t)}function pg(e,t,n,r,i,a){return $h(e,Ch(e,t,n,r),i,a,!1,t)}function mg(e,t,n,r,i,a,o){return $h(e,kh(e,t,n,r,o),i,a,!1,t)}function hg(e,t,n,r,i){return $h(e,Ah(e,t,n),r,i,!1,t)}function gg(e,t,n,r,i,a){return $h(e,jh(e,t,n,a),r,i,!1,t)}function _g(e,t,n,r,i,a,o,s){return $h(e,Nh(e,t,n,r,i,a),o,s,!1,t)}function vg(e,t,n,r,i){return $h(e,$p(e,t,n),r,i,!0)}function yg(e,t){let n=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];for(let e of t)n=wf(e.type===`translate`?yf(e.x,e.y,e.z):bf(e.angle,e.axis,e.center),n);return{handle:n,dispose:()=>{}}}function bg(e){return{translateWithHistory:(t,n,r,i,a,o)=>ig(e,t,n,r,i,a,o),rotateWithHistory:(t,n,r,i,a,o)=>ag(e,t,n,r,i,a,o),mirrorWithHistory:(t,n,r,i,a)=>og(e,t,n,r,i,a),scaleWithHistory:(t,n,r,i,a)=>sg(e,t,n,r,i,a),generalTransformWithHistory:(t,n,r,i,a,o)=>cg(e,t,n,r,i,a,o),fuseWithHistory:(t,n,r,i,a)=>lg(e,t,n,r,i,a),cutWithHistory:(t,n,r,i,a)=>ug(e,t,n,r,i,a),intersectWithHistory:(t,n,r,i,a)=>dg(e,t,n,r,i,a),filletWithHistory:(t,n,r,i,a)=>fg(e,t,n,r,i,a),chamferWithHistory:(t,n,r,i,a)=>pg(e,t,n,r,i,a),shellWithHistory:(t,n,r,i,a,o)=>mg(e,t,n,r,i,a,o),thickenWithHistory:(t,n,r,i)=>hg(e,t,n,r,i),offsetWithHistory:(t,n,r,i,a)=>gg(e,t,n,r,i,a),draftWithHistory:(t,n,r,i,a,o,s)=>_g(e,t,n,r,i,Ff(n,a),o,s),applyComposedTransformWithHistory:(t,n,r,i)=>vg(e,t,n,r,i),composeTransform:t=>yg(e,t)}}function xg(e,t){if(t.length===0)return``;let n=[];for(let r of t){let t=gf(e,r,`exportSTEP`);for(let r of t){let t=e.exportStep(r);n.push(new TextDecoder().decode(t))}}return n.join(`
|
|
6
6
|
`)}function Sg(e,n,r){let i=gf(e,n,`exportSTL`);if(r)return e.exportStl(t(i,0),Tf).buffer;let a=e.exportStlAscii(t(i,0),Tf);return new TextDecoder().decode(a)}function Cg(e,t){let n=typeof t==`string`?new TextEncoder().encode(t):new Uint8Array(t);return R(e.importStep(n)).map(I)}function wg(e,t){let n=typeof t==`string`?new TextEncoder().encode(t):new Uint8Array(t);return I(e.importStl(n))}function Tg(e,t){if(t.length===0)return``;let n=[];for(let r of t){let t=gf(e,r,`exportIGES`);for(let r of t){let t=e.exportIges(r);n.push(new TextDecoder().decode(t))}}return n.join(`
|
|
7
|
-
`)}function Eg(e,t){let n=typeof t==`string`?new TextEncoder().encode(t):new Uint8Array(t);return R(e.importIges(n)).map(I)}function Dg(e,t,n){return t.length===0?``:xg(e,t.map(e=>e.shape))}function Og(e,t,n){let r=hf(t,`export3MF`);return vf(e.export3mf(r,n))}function kg(e,t,n){let r=hf(t,`exportGLB`);return vf(e.exportGlb(r,n))}function Ag(e,t,n){let r=hf(t,`exportOBJ`);return vf(e.exportObj(r,n))}function jg(e,t,n){let r=hf(t,`exportPLY`);return vf(e.exportPly(r,n))}function Mg(e,t){return R(e.import3mf(new Uint8Array(t))).map(e=>I(e))}function Ng(e,t){return I(e.importObj(new Uint8Array(t)))}function Pg(e,t){return I(e.importGlb(new Uint8Array(t)))}function Fg(e,t){let n=t;return n.type===`solid`?e.toBREP(n.id):(Af(`brep-non-solid`,`toBREP for non-solid shapes uses STEP format.`),xg(e,[t]))}function Ig(e,t){if(typeof e.fromBREP==`function`&&t.trimStart().startsWith(`{`))return I(e.fromBREP(t));let n=Cg(e,t)[0];if(!n)throw Error(`brepkit: fromBREP produced no shapes`);return n}function Lg(e,t){return{__brepkit_xcaf:!0,shapes:t,delete:of}}function Rg(e,t,n){return t&&t.__brepkit_xcaf&&Array.isArray(t.shapes)?xg(e,t.shapes.map(e=>e.shape)):``}function zg(e,t,n){return xg(e,t.map(e=>e.shape))}function Bg(e){return{exportSTEP:t=>xg(e,t),exportSTL:(t,n)=>Sg(e,t,n),importSTEP:t=>Cg(e,t),importSTL:t=>wg(e,t),exportIGES:t=>Tg(e,t),importIGES:t=>Eg(e,t),exportSTEPAssembly:(t,n)=>Dg(e,t,n),export3MF:(t,n)=>Og(e,t,n),exportGLB:(t,n)=>kg(e,t,n),exportOBJ:(t,n)=>Ag(e,t,n),exportPLY:(t,n)=>jg(e,t,n),import3MF:t=>Mg(e,t),importOBJ:t=>Ng(e,t),importGLB:t=>Pg(e,t),toBREP:t=>Fg(e,t),fromBREP:t=>Ig(e,t),createXCAFDocument:t=>Lg(e,t),writeXCAFToSTEP:(t,n)=>Rg(e,t,n),exportSTEPConfigured:(t,n)=>zg(e,t,n)}}function Vg(e,t){return{x:e,y:t}}function Hg(e,t){let n=Math.sqrt(e*e+t*t);if(n<1e-15)throw Error(`brepkit: createDirection2d called with zero-length vector`);return{x:e/n,y:t/n}}function Ug(e,t){return{x:e,y:t}}function Wg(e,t,n,r){return{px:e,py:t,dx:n,dy:r,delete:of}}function Gg(e){return e}function Kg(e){return e}function qg(e,t,n,r){return y(e,t,n,r)}function Jg(e,t,n,r){return b(e,t,n,r)}function Yg(e,t,n,r,i,a){let o=2*(e*(r-a)+n*(a-t)+i*(t-r));if(Math.abs(o)<1e-12)return y(e,t,i,a);let s=((e*e+t*t)*(r-a)+(n*n+r*r)*(a-t)+(i*i+a*a)*(t-r))/o,c=((e*e+t*t)*(i-n)+(n*n+r*r)*(e-i)+(i*i+a*a)*(n-e))/o,l=Math.sqrt((e-s)**2+(t-c)**2),u=Math.atan2(t-c,e-s),d=Math.atan2(r-c,n-s),f=Math.atan2(a-c,i-s),p=d-u;p<0&&(p+=2*Math.PI);let m=f-u;m<0&&(m+=2*Math.PI);let h=p<m,g=b(s,c,l,h);if(!h){let e=-u,t=-f;return t<e-1e-9&&(t+=2*Math.PI),{__bk2d:`trimmed`,basis:g,tStart:e,tEnd:t}}let _=f;return _<u-1e-9&&(_+=2*Math.PI),{__bk2d:`trimmed`,basis:g,tStart:u,tEnd:_}}function Xg(e,t,n,r,i,a){let o=Math.sqrt(n*n+r*r),s=o>0?n/o:0,c=o>0?r/o:0,l=e-i,u=t-a,d=2*(u*s-l*c);if(Math.abs(d)<1e-12)return y(e,t,i,a);let f=-(l*l+u*u)/d,p=e-f*c,m=t+f*s,h=Math.abs(f),g=Math.atan2(t-m,e-p),_=Math.atan2(a-m,i-p),v=-(t-m)/h,b=(e-p)/h,x=s*v+c*b,S;if(x>0){let e=_-g;e<=0&&(e+=2*Math.PI),S=g+e/2}else{let e=_-g;e>=0&&(e-=2*Math.PI),S=g+e/2}return Yg(e,t,p+h*Math.cos(S),m+h*Math.sin(S),i,a)}function Zg(e,t,n,r,i,a,o){return x(e,t,n,r,i,a,o)}function Qg(e,t,n,r,i,a,o,s,c){return{__bk2d:`trimmed`,basis:x(e,t,n,r,o,s,c),tStart:i,tEnd:a}}function $g(e){return S(e)}function e_(e,t){let n=e.length,r=Math.min(3,n-1),i=[],a=[];i.push(0),a.push(r+1);let o=n-r-1;for(let e=1;e<=o;e++)i.push(e/(o+1)),a.push(1);return i.push(1),a.push(r+1),{__bk2d:`bspline`,poles:[...e],knots:i,multiplicities:a,degree:r,isPeriodic:!1}}function t_(e,t){return h(Mf(e),t)}function n_(e,t){return{point:h(Mf(e),t),tangent:g(Mf(e),t)}}function r_(e){return _(Mf(e))}function i_(e){return v(Nf(e))}function a_(e,t,n){return{__bk2d:`trimmed`,basis:Mf(e),tStart:t,tEnd:n}}function o_(e){return JSON.parse(JSON.stringify(e))}function s_(e,t){let n=Mf(e),r=_(n),i=[];for(let e=0;e<=30;e++){let a=r.first+(r.last-r.first)*e/30,[o,s]=h(n,a),[c,l]=g(n,a),u=Math.sqrt(c*c+l*l);u>1e-12?i.push([o-l/u*t,s+c/u*t]):i.push([o,s])}return e_(i)}function c_(e,t,n){return C(Mf(e),t,n)}function l_(e,t,n,r){return w(Mf(e),t,n,r)}function u_(e,t,n,r){return ee(Mf(e),t,n,r)}function d_(e,t,n){return te(Mf(e),t,n)}function f_(e,t,n,r,i){return ne(Mf(e),t,n,r,i)}function p_(e,t,n,r,i,a){return C_(e,g_(t,n,r,i,a))}function m_(e,t,n){return{m:e,tx:t,ty:n,delete:of}}function h_(){return m_([1,0,0,0,1,0,0,0,1],0,0)}function g_(e,n,r,i,a){let o=Math.sqrt(r*r+i*i);if(o<1e-15)return h_();let s=-i/o,c=r/o,l=a-1,u=[1+l*s*s,l*s*c,0,l*c*s,1+l*c*c,0,0,0,1];return m_(u,e-t(u,0)*e-t(u,1)*n,n-t(u,3)*e-t(u,4)*n)}function __(e,t){return m_([1,0,0,0,1,0,0,0,1],e,t)}function v_(e,n,r,i,a,o,s){if(r===`axis`&&o!==void 0&&s!==void 0){let r=Math.sqrt(o*o+s*s),c=o/r,l=s/r,u=[2*c*c-1,2*c*l,0,2*c*l,2*l*l-1,0,0,0,1],d=i??e,f=a??n;return m_(u,d-t(u,0)*d-t(u,1)*f,f-t(u,3)*d-t(u,4)*f)}return m_([-1,0,0,0,-1,0,0,0,1],2*e,2*n)}function y_(e,t,n){let r=Math.cos(e),i=Math.sin(e);return m_([r,-i,0,i,r,0,0,0,1],t-r*t+i*n,n-i*t-r*n)}function b_(e,t,n){return m_([e,0,0,0,e,0,0,0,1],t*(1-e),n*(1-e))}function x_(e,t,n){e.tx=t,e.ty=n}function S_(e,n){let r=e.m,i=n.m,a=e=>t(r,e),o=e=>t(i,e);e.m=[a(0)*o(0)+a(1)*o(3)+a(2)*o(6),a(0)*o(1)+a(1)*o(4)+a(2)*o(7),a(0)*o(2)+a(1)*o(5)+a(2)*o(8),a(3)*o(0)+a(4)*o(3)+a(5)*o(6),a(3)*o(1)+a(4)*o(4)+a(5)*o(7),a(3)*o(2)+a(4)*o(5)+a(5)*o(8),a(6)*o(0)+a(7)*o(3)+a(8)*o(6),a(6)*o(1)+a(7)*o(4)+a(8)*o(7),a(6)*o(2)+a(7)*o(5)+a(8)*o(8)];let s=e.tx,c=e.ty,l=Number(n.tx)||0,u=Number(n.ty)||0;e.tx=a(0)*l+a(1)*u+s,e.ty=a(3)*l+a(4)*u+c}function C_(e,n){let r=Mf(e),i=n.m??[1,0,0,0,1,0,0,0,1],a=Number(n.tx)||0,o=Number(n.ty)||0,s=t(i,0),c=t(i,1),l=t(i,3),u=t(i,4);if(Math.abs(s-1)<1e-12&&Math.abs(u-1)<1e-12&&Math.abs(c)<1e-12&&Math.abs(l)<1e-12)return C(r,a,o);let d=_(r),f=[];for(let e=0;e<=20;e++){let[t,n]=h(r,d.first+(d.last-d.first)*e/20);f.push([s*t+c*n+a,l*t+u*n+o])}return S(f)}function w_(e,t,n){let r=re(Mf(e),Mf(t),n),i=r.segments.map(e=>Object.assign(e,{delete(){}}));return{points:r.points,segments:i}}function T_(e,t,n){let r=Mf(e),i=_(r);if(r.__bk2d===`line`){let e=t-r.ox,a=n-r.oy,o=Math.max(i.first,Math.min(i.last,e*r.dx+a*r.dy)),[s,c]=h(r,o);return{param:o,distance:Math.sqrt((s-t)**2+(c-n)**2)}}if(r.__bk2d===`circle`){let e=Math.atan2(n-r.cy,t-r.cx),i=r.sense?e:-e;for(;i<0;)i+=2*Math.PI;for(;i>2*Math.PI;)i-=2*Math.PI;let[a,o]=h(r,i);return{param:i,distance:Math.sqrt((a-t)**2+(o-n)**2)}}if(!isFinite(i.first)||!isFinite(i.last))return null;let a=i.first,o=1/0,s=(i.last-i.first)/200;for(let e=0;e<=200;e++){let c=i.first+e*s,[l,u]=h(r,c),d=(l-t)**2+(u-n)**2;d<o&&(o=d,a=c)}for(let e=0;e<10;e++){let[e,o]=h(r,a),[s,c]=g(r,a),l=(e-t)*s+(o-n)*c,u=s*s+c*c;if(u<1e-20)break;let d=l/u,f=Math.max(i.first,Math.min(i.last,a-d));if(Math.abs(f-a)<1e-14)break;a=f}let[c,l]=h(r,a);return{param:a,distance:Math.sqrt((c-t)**2+(l-n)**2)}}function E_(e,t,n,r,i,a){let o=Mf(e),s=Mf(t),c=n,l=i,u=1/0;for(let e=0;e<=50;e++){let t=n+(r-n)*e/50,[d,f]=h(o,t);for(let e=0;e<=50;e++){let n=i+(a-i)*e/50,[r,o]=h(s,n),p=(r-d)**2+(o-f)**2;p<u&&(u=p,c=t,l=n)}}let d=c,f=l;for(let c=0;c<20;c++){let[c,l]=h(s,f),u=T_(e,c,l);if(u){let e=Math.max(n,Math.min(r,u.param)),t=Math.abs(e-d)<1e-12;if(d=e,t)break}let[p,m]=h(o,d),g=T_(t,p,m);if(g){let e=Math.max(i,Math.min(a,g.param)),t=Math.abs(e-f)<1e-12;if(f=e,t)break}}let[p,m]=h(o,d),[g,_]=h(s,f);return Math.sqrt((g-p)**2+(_-m)**2)}function D_(e,n,r,i){let a=Mf(e),o=_(a),s=Math.max(3,{C0:1,C1:2,C2:3,C3:4}[r]??4),c=Math.max(100,i*10),l=[],u=1/0;for(let e=0;e<3&&u>n;e++){l=[];for(let e=0;e<=c;e++){let t=o.first+(o.last-o.first)*e/c;l.push(h(a,t))}u=0;for(let e=0;e<c;e++){let[n,r]=h(a,o.first+(o.last-o.first)*(e+.5)/c),i=t(l,e),s=t(l,e+1),d=(i[0]+s[0])/2,f=(i[1]+s[1])/2,p=Math.sqrt((n-d)**2+(r-f)**2);p>u&&(u=p)}u>n&&(c=Math.min(c*2,500))}return e_(l,{degMax:s})}function O_(e){let n=Nf(e);if(n.__bk2d===`bezier`)return[e];if(n.__bk2d!==`bspline`)return O_(D_(e,1e-6,`C2`,10));let r=_(Mf(e)),i=r.first,a=r.last,o=[];for(let e of n.knots)e>i+1e-12&&e<a-1e-12&&o.push(e);let s=[i,...o,a],c=[];for(let e=0;e<s.length-1;e++){let r=t(s,e),i=t(s,e+1),a=i-r;if(a<1e-15)continue;let o=h(n,r),l=h(n,i),u=g(n,r),d=g(n,i),f=a/3,p={__bk2d:`bezier`,poles:[o,[o[0]+u[0]*f,o[1]+u[1]*f],[l[0]-d[0]*f,l[1]-d[1]*f],l]};c.push(p)}return c.length>0?c:[e]}function k_(){return me()}function A_(e,t,n){he(Pf(e),Mf(t),n)}function j_(e){let t=Pf(e);return{xMin:t.xMin,yMin:t.yMin,xMax:t.xMax,yMax:t.yMax}}function M_(e,t){let n=Pf(e),r=Pf(t);n.xMin=Math.min(n.xMin,r.xMin),n.yMin=Math.min(n.yMin,r.yMin),n.xMax=Math.max(n.xMax,r.xMax),n.yMax=Math.max(n.yMax,r.yMax)}function N_(e,t){let n=Pf(e),r=Pf(t);return n.xMax<r.xMin||r.xMax<n.xMin||n.yMax<r.yMin||r.yMax<n.yMin}function P_(e,t,n){let r=Pf(e);return t<r.xMin||t>r.xMax||n<r.yMin||n>r.yMax}function F_(e){let t=Nf(e);return t.__bk2d===`circle`?{cx:t.cx,cy:t.cy,radius:t.radius,isDirect:t.sense}:null}function I_(e){let t=Nf(e);return t.__bk2d===`ellipse`?{majorRadius:t.majorRadius,minorRadius:t.minorRadius,xAxisAngle:t.xDirAngle,isDirect:t.sense}:null}function L_(e){let t=Nf(e);return t.__bk2d===`bezier`?[...t.poles]:null}function R_(e){let t=Nf(e);return t.__bk2d===`bezier`?t.poles.length-1:null}function z_(e){let t=Nf(e);return t.__bk2d===`bspline`?{poles:[...t.poles],knots:[...t.knots],multiplicities:[...t.multiplicities],degree:t.degree,isPeriodic:t.isPeriodic}:null}function B_(e){return fe(Mf(e))}function V_(e){return pe(e)}function H_(e,t){let n=Mf(e),r=_(n),i=[r.first,...[...t].sort((e,t)=>e-t),r.last],a=[];for(let e=0;e<i.length-1;e++)a.push({__bk2d:`trimmed`,basis:n,tStart:i[e],tEnd:i[e+1]});return a}function U_(e,n,r,i,a){let o=Mf(n),s=[i[1]*a[2]-i[2]*a[1],i[2]*a[0]-i[0]*a[2],i[0]*a[1]-i[1]*a[0]],c=(e,t)=>[r[0]+e*a[0]+t*s[0],r[1]+e*a[1]+t*s[1],r[2]+e*a[2]+t*s[2]];if(o.__bk2d===`line`)return Um(e,c(o.ox,o.oy),c(o.ox+o.dx*o.len,o.oy+o.dy*o.len));if(o.__bk2d===`circle`||o.__bk2d===`trimmed`){let n=o;for(;n.__bk2d===`trimmed`;)n=n.basis;if(n.__bk2d===`circle`){let r=n,a=c(r.cx,r.cy),s=r.sense?i:[-i[0],-i[1],-i[2]],l=_(o),u;u=o.__bk2d===`trimmed`?Math.abs(o.tEnd-o.tStart):2*Math.PI;let d=u>Math.PI?4:u>Math.PI/2?2:1,f=(l.last-l.first)/d,p=[];for(let t=0;t<d;t++){let[n,r]=h(o,l.first+t*f),[i,u]=h(o,l.first+(t+1)*f);p.push(e.makeCircleArc3d(...c(n,r),...c(i,u),...a,...s))}return p.length===1?uf(t(p,0)):df(e.makeWire(p,!1))}}if(o.__bk2d===`bezier`||o.__bk2d===`bspline`){let n=o.poles.map(([e,t])=>c(e,t));if(n.length===2)return Um(e,t(n,0),t(n,1));let r=Math.min(3,n.length-1),i=n.flatMap(([e,t,n])=>[e,t,n]);return uf(e.interpolatePoints(i,r))}let l=_(o),u=[];for(let e=0;e<=100;e++){let[t,n]=h(o,l.first+(l.last-l.first)*e/100);u.push(c(t,n))}return dh(e,u)}function W_(e,t,r){if(!sf(r))throw Error(`brepkit: buildEdgeOnSurface requires a face handle as surface`);let i=L(r,`face`),a=Mf(t),o=_(a),s=e.getSurfaceType(i)===`plane`?50:100,c=[];for(let t=0;t<=s;t++){let[r,l]=h(a,o.first+(o.last-o.first)*t/s);c.push(n(e.evaluateSurface(i,r,l)))}return dh(e,c)}function G_(e){return e}function K_(e,n,r,i){let a=0;for(;e.length<r;){let o=[];for(let r=0;r<e.length-1;r++){let a=t(e,r),s=t(e,r+1),c=(a.t+s.t)/2,l=n(c),u=(a.uv[0]+s.uv[0])/2,d=(a.uv[1]+s.uv[1])/2;Math.sqrt((l[0]-u)**2+(l[1]-d)**2)>i&&o.push({index:r+1,t:c,uv:l})}if(o.length===0)break;let s=r-e.length;for(let n=o.length-1;n>=0&&s>0;n--){let r=t(o,n);e.splice(r.index,0,{t:r.t,uv:r.uv}),s--}if(a++,a>3)break}}function q_(e,n,r){let i=L(n,`edge`),a=L(r,`face`),o=e.getEdgeCurveParameters(i),s=o[0]??0,c=o[1]??1,l=[];for(let e=0;e<=20;e++)l.push(s+(c-s)*e/20);let u=n=>{let r=e.evaluateEdgeCurve(i,n),o=e.projectPointOnSurface(a,t(r,0),t(r,1),t(r,2));return[t(o,0),t(o,1)]},d=l.map(e=>({t:e,uv:u(e)}));K_(d,u,80,.05);let f=d.map(e=>e.uv);if(f.length>=2)return e_(f);let p=e.getEdgeVertices(i);if(p.length>=6){let n=e.projectPointOnSurface(a,t(p,0),t(p,1),t(p,2)),r=e.projectPointOnSurface(a,t(p,3),t(p,4),t(p,5));return y(t(n,0),t(n,1),t(r,0),t(r,1))}throw Error(`brepkit: extractCurve2dFromEdge: degenerate edge (${p.length} coords)`)}function J_(e,t,n){return e}function Y_(e,n,r){if(n.length>=1){let r=Wf(e,n[0],`edge`);if(r.length===4){let n=[],i=[];for(let a of r){let r=L(a,`edge`),o=e.getEdgeCurveParameters(r),s=t(o,0),c=t(o,1),l=[];for(let n=0;n<=10;n++){let i=s+(c-s)*n/10,a=e.evaluateEdgeCurve(r,i);l.push(t(a,0),t(a,1),t(a,2))}n.push(...l),i.push(11)}try{return lf(e.fillCoonsPatch(n,i))}catch(e){console.warn(`brepkit: Coons patch failed, falling back:`,e)}}}let i=n[0];if(!i)throw Error(`fillSurface: no wires provided`);return rh(e,i)}function X_(e){return{createPoint2d:(e,t)=>Vg(e,t),createDirection2d:(e,t)=>Hg(e,t),createVector2d:(e,t)=>Ug(e,t),createAxis2d:(e,t,n,r)=>Wg(e,t,n,r),wrapCurve2dHandle:e=>Gg(e),createCurve2dAdaptor:e=>Kg(e),makeLine2d:(e,t,n,r)=>qg(e,t,n,r),makeCircle2d:(e,t,n,r)=>Jg(e,t,n,r),makeArc2dThreePoints:(e,t,n,r,i,a)=>Yg(e,t,n,r,i,a),makeArc2dTangent:(e,t,n,r,i,a)=>Xg(e,t,n,r,i,a),makeEllipse2d:(e,t,n,r,i,a,o)=>Zg(e,t,n,r,i,a,o),makeEllipseArc2d:(e,t,n,r,i,a,o,s,c)=>Qg(e,t,n,r,i,a,o,s,c),makeBezier2d:e=>$g(e),makeBSpline2d:(e,t)=>e_(e,t),evaluateCurve2d:(e,t)=>t_(e,t),evaluateCurve2dD1:(e,t)=>n_(e,t),getCurve2dBounds:e=>r_(e),getCurve2dType:e=>i_(e),trimCurve2d:(e,t,n)=>a_(e,t,n),reverseCurve2d:e=>{},copyCurve2d:e=>o_(e),offsetCurve2d:(e,t)=>s_(e,t),translateCurve2d:(e,t,n)=>c_(e,t,n),rotateCurve2d:(e,t,n,r)=>l_(e,t,n,r),scaleCurve2d:(e,t,n,r)=>u_(e,t,n,r),mirrorCurve2dAtPoint:(e,t,n)=>d_(e,t,n),mirrorCurve2dAcrossAxis:(e,t,n,r,i)=>f_(e,t,n,r,i),affinityTransform2d:(e,t,n,r,i,a)=>p_(e,t,n,r,i,a),createIdentityGTrsf2d:()=>h_(),createAffinityGTrsf2d:(e,t,n,r,i)=>g_(e,t,n,r,i),createTranslationGTrsf2d:(e,t)=>__(e,t),createMirrorGTrsf2d:(e,t,n,r,i,a,o)=>v_(e,t,n,r,i,a,o),createRotationGTrsf2d:(e,t,n)=>y_(e,t,n),createScaleGTrsf2d:(e,t,n)=>b_(e,t,n),setGTrsf2dTranslationPart:(e,t,n)=>{x_(e,t,n)},multiplyGTrsf2d:(e,t)=>{S_(e,t)},transformCurve2dGeneral:(e,t)=>C_(e,t),intersectCurves2d:(e,t,n)=>w_(e,t,n),projectPointOnCurve2d:(e,t,n)=>T_(e,t,n),distanceBetweenCurves2d:(e,t,n,r,i,a)=>E_(e,t,n,r,i,a),approximateCurve2dAsBSpline:(e,t,n,r)=>D_(e,t,n,r),decomposeBSpline2dToBeziers:e=>O_(e),createBoundingBox2d:()=>k_(),addCurveToBBox2d:(e,t,n)=>{A_(e,t,n)},getBBox2dBounds:e=>j_(e),mergeBBox2d:(e,t)=>{M_(e,t)},isBBox2dOut:(e,t)=>N_(e,t),isBBox2dOutPoint:(e,t,n)=>P_(e,t,n),getCurve2dCircleData:e=>F_(e),getCurve2dEllipseData:e=>I_(e),getCurve2dBezierPoles:e=>L_(e),getCurve2dBezierDegree:e=>R_(e),getCurve2dBSplineData:e=>z_(e),serializeCurve2d:e=>B_(e),deserializeCurve2d:e=>V_(e),splitCurve2d:(e,t)=>H_(e,t),liftCurve2dToPlane:(t,n,r,i)=>U_(e,t,n,r,i),buildEdgeOnSurface:(t,n)=>W_(e,t,n),extractSurfaceFromFace:e=>G_(e),extractCurve2dFromEdge:(t,n)=>q_(e,t,n),buildCurves3d:e=>{},fixWireOnFace:(e,t,n)=>J_(e,t,n),fillSurface:(t,n)=>Y_(e,t,n)}}function Z_(e,t){let n=t;if(n.type===`solid`)return e.volume(L(t),Tf);if(n.type===`compound`){let n=Wf(e,t,`solid`),r=0;for(let t of n)r+=e.volume(L(t),Tf);return r}return 0}function Q_(e,t){let n=t;if(n.type===`face`)return e.faceArea(L(t),Tf);if(n.type===`solid`)return e.surfaceArea(L(t),Tf);if(n.type===`compound`){let n=Wf(e,t,`face`),r=0;for(let t of n)r+=e.faceArea(L(t),Tf);return r}return 0}function $_(e,t){let n=t;if(n.type===`edge`)return e.edgeLength(L(t));if(n.type===`face`)return e.facePerimeter(L(t));if(n.type===`wire`)return e.wireLength(n.id);throw Error(`brepkit: length() requires an edge, wire, or face`)}function ev(e,n){let r=e.getEdgeVertices(n);return[(t(r,0)+t(r,3))/2,(t(r,1)+t(r,4))/2,(t(r,2)+t(r,5))/2]}function tv(e,t){let r=t;if(r.type===`solid`)return n(e.centerOfMass(L(t),Tf));if(r.type===`face`){let n=sp(e,t);return up(e,t,(n.uMin+n.uMax)/2,(n.vMin+n.vMax)/2)}if(r.type===`edge`)return ev(e,r.id);if(r.type===`vertex`)return ap(e,t);let i=Wf(e,t,`vertex`);if(i.length>0){let t=0,n=0,r=0;for(let a of i){let i=ap(e,a);t+=i[0],n+=i[1],r+=i[2]}return[t/i.length,n/i.length,r/i.length]}return[0,0,0]}function nv(e,t){let n=t;return n.type===`edge`?ev(e,n.id):tv(e,t)}function rv(e,t){let r=t;if(r.type===`solid`){let r=e.boundingBox(L(t));return{min:n(r,0),max:n(r,3)}}if(r.type===`vertex`){let n=ap(e,t);return{min:[...n],max:[...n]}}let i=Wf(e,t,`vertex`);if(i.length===0)return{min:[0,0,0],max:[0,0,0]};let a=ap(e,i[0]),o=a[0],s=a[1],c=a[2],l=a[0],u=a[1],d=a[2];for(let t=1;t<i.length;t++){let n=ap(e,i[t]);n[0]<o&&(o=n[0]),n[0]>l&&(l=n[0]),n[1]<s&&(s=n[1]),n[1]>u&&(u=n[1]),n[2]<c&&(c=n[2]),n[2]>d&&(d=n[2])}return{min:[o,s,c],max:[l,u,d]}}function iv(e,r,i){let a=r,o=i;if(a.type===`solid`&&o.type===`solid`){let r=e.solidToSolidDistance(a.id,o.id);return{value:t(r,0),point1:n(r,1),point2:n(r,4)}}if(a.type===`vertex`&&(o.type===`solid`||o.type===`face`||o.type===`edge`)){let r=n(e.getVertexPosition(a.id)),i=o.type===`solid`?e.pointToSolidDistance(r[0],r[1],r[2],o.id):o.type===`face`?e.pointToFaceDistance(r[0],r[1],r[2],o.id):e.pointToEdgeDistance(r[0],r[1],r[2],o.id);return{value:t(i,0),point1:r,point2:n(i,1)}}let s=r=>{if(r.type===`vertex`)return n(e.getVertexPosition(r.id));if(r.type===`solid`){let n=e.boundingBox(r.id);return[(t(n,0)+t(n,3))/2,(t(n,1)+t(n,4))/2,(t(n,2)+t(n,5))/2]}return[0,0,0]},c=s(a),l=s(o),u=l[0]-c[0],d=l[1]-c[1],f=l[2]-c[2];return{value:Math.sqrt(u*u+d*d+f*f),point1:c,point2:l}}function av(e,r,i,a){let o=L(r,`face`),s=e.measureCurvatureAtSurface(o,i,a);if(s.length<8)throw Error(`brepkit: measureCurvatureAtSurface returned ${s.length} values, expected 8`);let c=t(s,0),l=t(s,1);return{gaussian:c*l,mean:(c+l)/2,max:Math.max(c,l),min:Math.min(c,l),maxDirection:n(s,2),minDirection:n(s,5)}}function ov(e,n){let r=e.tessellateFace(L(n,`face`),.1),i=r.positions,a=r.indices,o=0,s=0,c=0,l=0;for(let e=0;e<a.length;e+=3){let n=t(a,e)*3,r=t(a,e+1)*3,u=t(a,e+2)*3,d=t(i,n),f=t(i,n+1),p=t(i,n+2),m=t(i,r),h=t(i,r+1),g=t(i,r+2),_=t(i,u),v=t(i,u+1),y=t(i,u+2),b=(d+m+_)/3,x=(f+h+v)/3,S=(p+g+y)/3,C=m-d,w=h-f,ee=g-p,te=_-d,ne=v-f,re=y-p,ie=.5*Math.sqrt((w*re-ee*ne)**2+(ee*te-C*re)**2+(C*ne-w*te)**2);o+=b*ie,s+=x*ie,c+=S*ie,l+=ie}return l<1e-30?[0,0,0]:[o/l,s/l,c/l]}function sv(e,t){let n=n=>iv(e,t,n);return{distanceTo(e){return n(e)},dispose(){}}}function cv(e,t,n=!1){let r=t,i=r.type===`edge`||r.type===`wire`||r.type===`face`;return{volume:Z_(e,t),area:Q_(e,t),length:n&&i?$_(e,t):0,centerOfMass:tv(e,t),boundingBox:rv(e,t)}}function lv(e){return{volume:t=>Z_(e,t),area:t=>Q_(e,t),length:t=>$_(e,t),centerOfMass:t=>tv(e,t),linearCenterOfMass:t=>nv(e,t),boundingBox:t=>rv(e,t),distance:(t,n)=>iv(e,t,n),surfaceCurvature:(t,n,r)=>av(e,t,n,r),surfaceCenterOfMass:t=>ov(e,t),createDistanceQuery:t=>sv(e,t),measureBulk:(t,n)=>cv(e,t,n)}}function uv(e,t,n){let r=L(t),i=t,a=n.tolerance||.01,o=n.angularTolerance>0?n.angularTolerance:void 0,s;if(i.type===`solid`)s=pv(e,r,a,!!n.includeUVs,o);else if(i.type===`face`)s=gv(e,r,a,0,o);else throw Error(`brepkit: cannot mesh shape of type '${i.type}'`);return n.skipNormals&&(s.normals=new Float32Array),n.includeUVs||(s.uvs=new Float32Array),s}function dv(e,n,r,i){i>0&&Af(`mesh-edges-angular`,`meshEdges angularTolerance is not supported; only linear deflection is used.`);let a=n;if(a.type!==`solid`)return{lines:new Float32Array,edgeGroups:[]};let o=e.meshEdgesAll(a.id,r),s=o.positions,c=o.offsets,l=o.edgeCount,u=[];for(let e=0;e<l;e++){let n=t(c,e),r=((e+1<l?t(c,e+1):s.length)-n)/3;u.push({start:n/3,count:r,edgeHash:e})}return{lines:new Float32Array(s),edgeGroups:u}}function fv(e,t){return!1}function pv(e,t,n,r,i){try{return mv(e,t,n,r,i)}catch(r){return console.warn(`brepkit: tessellateSolidGrouped failed (solidId=${t}), falling back to per-face:`,r),hv(e,t,n,i)}}function mv(e,n,r,i,a){let o=e.tessellateSolidGrouped(n,r,a),s=JSON.parse(o),c=R(e.getSolidFaces(n)),l=s.faceOffsets.length-1;if(l!==c.length)throw Error(`faceOffsets/faceIds length mismatch: ${l} groups vs ${c.length} faces`);let u=[];for(let e=0;e<s.faceOffsets.length-1;e++){let n=t(s.faceOffsets,e),r=t(s.faceOffsets,e+1)-n;r!==0&&u.push({start:n,count:r,faceHash:c[e]??0})}let d=new Float32Array;if(i){let t=s.positions.length/3*2;try{let i=e.tessellateSolidUV(n,r,a),o=JSON.parse(i);d=o.uvs.length===t?new Float32Array(o.uvs):new Float32Array(t)}catch{d=new Float32Array(t)}}return{vertices:new Float32Array(s.positions),normals:new Float32Array(s.normals),triangles:new Uint32Array(s.indices),uvs:d,faceGroups:u}}function hv(e,t,n,r){let i=R(e.getSolidFaces(t)),a=[],o=[],s=[],c=[],l=[],u=0;for(let t of i)try{let i=e.tessellateFace(t,n,r),d=i.positions,f=i.normals,p=i.indices,m=d.length/3;if(m===0)continue;let h=s.length;for(let e of d)a.push(e);for(let e of f)o.push(e);for(let e of p)s.push(e+u);for(let e=0;e<m;e++)c.push(0,0);l.push({start:h,count:p.length,faceHash:t}),u+=m}catch(e){console.warn(`brepkit: face tessellation failed (faceId=${t}):`,e)}return{vertices:new Float32Array(a),normals:new Float32Array(o),triangles:new Uint32Array(s),uvs:new Float32Array(c),faceGroups:l}}function gv(e,t,n,r,i){let a=e.tessellateFace(t,n,i),o=a.positions,s=a.normals,c=a.indices,l=o.length/3,u=[];for(let e=0;e<l;e++)u.push(0,0);return{vertices:new Float32Array(o),normals:new Float32Array(s),triangles:new Uint32Array(c),uvs:new Float32Array(u),faceGroups:[{start:0,count:c.length,faceHash:r}]}}function _v(e){return{mesh:(t,n)=>uv(e,t,n),meshEdges:(t,n,r)=>dv(e,t,n,r),hasTriangulation:t=>fv(e,t),meshShape:(e,t,n)=>{}}}function vv(e){return e.sketchNew()}function yv(e,t,n,r,i){return e.sketchAddPoint(t,n,r,i)}function bv(e,t,n){e.sketchAddConstraint(t,n)}function xv(e,t,n,r){return e.sketchSolve(t,n,r)}function Sv(e,t,n,r,i){return e.sketchAddArc(t,n,r,i)}function Cv(e,t){let n=e.sketchDof(t);return typeof n==`string`?n:String(n)}function wv(e){return{sketchNew:()=>vv(e),sketchAddPoint:(t,n,r,i)=>yv(e,t,n,r,i),sketchAddArc:(t,n,r,i)=>Sv(e,t,n,r,i),sketchAddConstraint:(t,n)=>{bv(e,t,n)},sketchSolve:(t,n,r)=>xv(e,t,n,r),sketchDof:t=>Cv(e,t)}}function Tv(e,t,n,r){return I(e.extrude(L(t,`face`),n[0],n[1],n[2],r))}function Ev(e,t,n,r){if(n&&typeof n==`object`&&`origin`in n&&`direction`in n){let{origin:i,direction:a}=n,o=180/Math.PI*r;return o>360&&(o=360),I(e.revolve(L(t,`face`),i[0],i[1],i[2],a[0],a[1],a[2],o))}throw Error(`brepkit: revolve requires axis with origin and direction`)}function Dv(e,t,n,r,i){let a=180/Math.PI*i;return a>360&&(a=360),I(e.revolve(L(t,`face`),n[0],n[1],n[2],r[0],r[1],r[2],a))}function Ov(e,t,n,r,i){(n!==void 0||r!==void 0||i!==void 0)&&Af(`loft-options`,`Loft options (ruled, startShape, endShape) not supported; ignored.`);let a=t.map(t=>{let n=t;return n.type===`wire`?e.makeFaceFromWire(n.id):L(t,`face`)});return I(e.loft(a))}function kv(e){switch(e){case 0:return`rmf`;case 1:return`rightCorner`;case 2:return`roundCorner`;default:return}}function Av(e,t,n,r){let i=r?.transitionMode===void 0?void 0:kv(r.transitionMode),a=t,o=a.type===`wire`?e.makeFaceFromWire(a.id):L(t,`face`);if(n.type===`wire`){let t=Wf(e,n,`edge`).map(e=>L(e,`edge`));if(i&&t.length===1){let n=t[0];if(n!==void 0)return I(e.sweepWithOptions(o,n,i,[],0,`transformed`))}return i&&t.length>1&&Af(`sweep-transition-multi-edge`,`Sweep transition mode not supported for multi-edge wires; ignored.`),I(e.sweepAlongEdges(o,t))}if(i){let t=L(n,`edge`);return I(e.sweepWithOptions(o,t,i,[],0,`transformed`))}let s=rm(e,n);if(!s)throw Error(`brepkit: sweep spine must be an edge or wire`);return I(e.sweep(o,s.degree,s.knots,s.controlPoints,s.weights))}function jv(e,t,n){let r=t,i=r.type===`wire`?e.makeFaceFromWire(r.id):L(t,`face`);if(n.type===`wire`){let t=Wf(e,n,`edge`).map(e=>L(e,`edge`));return I(e.sweepAlongEdges(i,t))}let a=rm(e,n);if(!a)throw Error(`brepkit: pipe spine must be an edge or wire`);return I(e.pipe(i,a.degree,a.knots,a.controlPoints,a.weights))}function Mv(e,t,n,r,i,a,o){let s=L(t,`face`);return I(e.helicalSweep(s,n[0],n[1],n[2],r[0],r[1],r[2],i,a,o))}function Nv(e,t,n,r,i,a){let o=L(t,`face`),s=L(n,`edge`);return I(e.sweepWithOptions(o,s,r,i,a,`transformed`))}function Pv(e){switch(e){case`right`:return`rightCorner`;case`round`:return`roundCorner`;case`transformed`:return`rmf`;default:return}}function Fv(e,t,n){return n?{shape:e,firstShape:t,lastShape:t}:e}function Iv(e,t,n,r){try{return I(e.sweepWithOptions(t,n,r,[],0,`transformed`))}catch(e){console.warn(`brepkit: sweepWithOptions failed, falling back to sweepSmooth/simplePipe:`,e);return}}function Lv(e,t){try{if(t.type!==`wire`)return{edgeId:L(t,`edge`)};let n=Wf(e,t,`edge`);if(n.length===1){let e=n[0];return e?{edgeId:L(e,`edge`)}:void 0}Af(`sweepPipeShell-transition-multi-edge`,`sweepPipeShell transition mode not supported for multi-edge wires; ignored.`);return}catch(e){console.warn(`brepkit: resolveContactModeEdge failed for unexpected spine type, falling through:`,e);return}}function Rv(e,t,n,r){let i=Lv(e,n);if(i)return Iv(e,t,i.edgeId,r)}function zv(e,t,n){let r=rm(e,n);if(!(!r||r.degree<=1))try{return I(e.sweepSmooth(t,r.degree,r.knots,r.controlPoints,r.weights))}catch(e){console.warn(`brepkit: sweepSmooth failed, falling back to simplePipe:`,e);return}}function Bv(e,t,n,r){let i=t,a=i.type===`wire`?e.makeFaceFromWire(i.id):L(t,`face`),o=!!(r&&r.shellMode),s=r?.transitionMode,c=s?Pv(s):void 0;if(c){let r=Rv(e,a,n,c);if(r)return Fv(r,t,o)}return Fv(zv(e,a,n)||jv(e,t,n),t,o)}function Vv(e,t,n){let r=t.map(t=>{let n=t;return n.type===`wire`?e.makeFaceFromWire(n.id):L(t,`face`)});try{let t={};if(n?.ruled!==void 0&&(t.ruled=n.ruled),n?.solid!==void 0&&(t.solid=n.solid),n?.tolerance!==void 0&&(t.tolerance=n.tolerance),n?.startVertex){let r=e.getVertexPosition(L(n.startVertex,`vertex`));t.startPoint=[r[0],r[1],r[2]]}if(n?.endVertex){let r=e.getVertexPosition(L(n.endVertex,`vertex`));t.endPoint=[r[0],r[1],r[2]]}return I(e.loftWithOptions(r,JSON.stringify(t)))}catch(e){console.warn(`brepkit: loftWithOptions failed, falling back to smooth/basic loft:`,e)}if(!n?.ruled)try{return I(e.loftSmooth(r))}catch(e){console.warn(`brepkit: loftSmooth failed, falling back to basic loft:`,e)}return Ov(e,t)}function Hv(e,t,n,r){let i={type:`extrusionLaw`,profile:t,length:n,endFactor:r,Trim(e,t,n){return i},delete:of};return i}function Uv(e,t,n,r,i,a,o){if(i!==null){let r=Tv(e,n,lp(e,n,0,0),i);return o?ym(e,t,r):r}return t}function Wv(e){return{extrude:(t,n,r)=>Tv(e,t,n,r),revolve:(t,n,r)=>Ev(e,t,n,r),revolveVec:(t,n,r,i)=>Dv(e,t,n,r,i),loft:(t,n,r,i)=>Ov(e,t,n,r,i),sweep:(t,n,r)=>Av(e,t,n,r),simplePipe:(t,n)=>jv(e,t,n),helicalSweep:(t,n,r,i,a,o)=>Mv(e,t,n,r,i,a,o),sweepWithOptions:(t,n,r,i,a)=>Nv(e,t,n,r,i,a),sweepPipeShell:(t,n,r)=>Bv(e,t,n,r),loftAdvanced:(t,n)=>Vv(e,t,n),buildExtrusionLaw:(t,n,r)=>Hv(e,t,n,r),draftPrism:(t,n,r,i,a,o)=>Uv(e,t,n,r,i,a,o)}}function Gv(e){return{dispose:()=>{},executeBatch:t=>e.executeBatch(t),checkpoint:()=>e.checkpoint(),checkpointCount:()=>e.checkpointCount(),restoreCheckpoint:t=>{e.restore(t)},discardCheckpoint:t=>{e.discardCheckpoint(t)}}}var Kv=class{oc;kernelId=`brepkit`;bk;constructor(e){this.bk=e,this.oc=e;let t=this.bk;Object.assign(this,jm(t),xh(t),Wv(t),zh(t),Qp(t),_v(t),Bg(t),lv(t),ip(t),zp(t),hm(t),bg(t),wv(t),X_(t),Gv(t))}};function z(e){throw Error(`manifold: ${e} is not implemented`)}var qv=new Set(`makeBox.makeBoxWithCorners.makeCylinder.makeSphere.makeCone.makeTorus.makeEllipsoid.makeFuse.makeCut.makeCommon.translateShape.rotateShape.scaleShape.mirrorShape.transformShape.generalTransform.generalTransformNonOrthogonal.gridPattern.extrude.revolve.revolveVec.loft.loftAdvanced.sweep.simplePipe.sweepWithOptions.sweepPipeShell.helicalSweep.draftPrism.fillet.chamfer.chamferDistAngle.shell.thicken.offset.filletVariable.draft.defeature.simplify.reverseShape.hull.hullFromPoints.sewAndSolidify`.split(`.`));function Jv(e){return qv.has(e)}function Yv(e,t,n){return{op:e,params:t,inputs:n,replayable:Jv(e)&&n.every(e=>e.replayable)}}function Xv(e,t){return{manifold:e,node:t}}function B(e){return e.manifold}function V(e){return e.node}function Zv(e){if(e&&typeof e==`object`&&`manifold`in e&&`node`in e)return e}var Qv=[`occt`,`occt-wasm`];function $v(){for(let e of Qv)try{return U(e)}catch{}}function ey(e){let t=$v();if(!t)throw Error(`manifold: ${e} requires a registered occt kernel; none is available`);return t}var ty=new WeakMap,ny=[0,0,0],ry=[0,0,1];function iy(e){return Math.hypot(e[0],e[1],e[2])}function ay(e){let t=iy(e);return t===0?[...ry]:[e[0]/t,e[1]/t,e[2]/t]}function oy(e){let[t,n,r]=ay(e);return[0,180/Math.PI*Math.atan2(Math.hypot(t,n),r),180/Math.PI*Math.atan2(n,t)]}function sy(e){let t=e.Manifold;function n(e,t,n){let r=e;return n[0]===0&&n[1]===0&&n[2]>0||(r=r.rotate(oy(n))),(t[0]!==0||t[1]!==0||t[2]!==0)&&(r=r.translate(t)),r}return{makeBox:(e,n,r)=>Xv(t.cube([e,n,r],!1),Yv(`makeBox`,{width:e,height:n,depth:r},[])),makeBoxFromCorners:(e,n)=>{let r=[Math.abs(n[0]-e[0]),Math.abs(n[1]-e[1]),Math.abs(n[2]-e[2])],i=[Math.min(e[0],n[0]),Math.min(e[1],n[1]),Math.min(e[2],n[2])];return Xv(t.cube(r,!1).translate(i),Yv(`makeBoxWithCorners`,{p1:e,p2:n},[]))},makeCylinder:(e,r,i=ny,a=ry)=>Xv(n(t.cylinder(r,e,e,0,!1),i,a),Yv(`makeCylinder`,{radius:e,height:r,center:i,direction:a},[])),makeSphere:(e,n=ny)=>{let r=t.sphere(e,0);return(n[0]!==0||n[1]!==0||n[2]!==0)&&(r=r.translate(n)),Xv(r,Yv(`makeSphere`,{radius:e,center:n},[]))},makeCone:(e,r,i,a=ny,o=ry)=>Xv(n(t.cylinder(i,e,r,0,!1),a,o),Yv(`makeCone`,{radius1:e,radius2:r,height:i,center:a,direction:o},[])),makeTorus:(r,i,a=ny,o=ry)=>{let s=Math.max(3,e.getCircularSegments(i)),c=[];for(let e=0;e<s;e++){let t=e/s*Math.PI*2;c.push([r+i*Math.cos(t),i*Math.sin(t)])}return Xv(n(t.revolve([c],0),a,o),Yv(`makeTorus`,{majorRadius:r,minorRadius:i,center:a,direction:o},[]))},makeEllipsoid:(e,n,r)=>Xv(t.sphere(1,0).scale([e,n,r]),Yv(`makeEllipsoid`,{aLength:e,bLength:n,cLength:r},[])),makeRectangle:()=>z(`makeRectangle`)}}function cy(e){return e}function ly(e,t,n){switch(n){case`cut`:case`subtract`:case`difference`:return e.subtract(t);case`intersect`:case`common`:case`intersection`:return e.intersect(t);default:return e.add(t)}}function uy(e){let t=V(cy(e)).params,n=t.normal,r=t.origin;if(!n||!r)throw Error(`manifold: section/split plane must carry normal+origin params`);return{normal:n,offset:n[0]*r[0]+n[1]*r[1]+n[2]*r[2]}}function dy(e){let t=new Uint32Array(e.triVerts),n=e.vertProperties.length/3,r=new Float32Array(n*3);for(let t=0;t<n;t++)r[t*3]=e.vertProperties[t*3]??0,r[t*3+1]=e.vertProperties[t*3+1]??0,r[t*3+2]=e.vertProperties[t*3+2]??0;return{vertices:r,normals:new Float32Array,triangles:t,uvs:new Float32Array,faceGroups:[{start:0,count:t.length,faceHash:0}]}}function fy(e){let t=e.Manifold;function n(e,t,n){let r=cy(e),i=cy(t);return Xv(B(r).add(B(i)),Yv(`makeFuse`,{},[V(r),V(i)]))}function r(e,t,n){let r=cy(e),i=cy(t);return Xv(B(r).subtract(B(i)),Yv(`makeCut`,{},[V(r),V(i)]))}function i(e,t,n){let r=cy(e),i=cy(t);return Xv(B(r).intersect(B(i)),Yv(`makeCommon`,{},[V(r),V(i)]))}function a(e,n){if(e.length===0)throw Error(`manifold: fuseAll requires at least one shape`);let r=e.map(cy),[i]=r;if(i===void 0)throw Error(`manifold: fuseAll requires at least one shape`);return r.length===1?i:Xv(t.union(r.map(B)),Yv(`makeFuse`,{},r.map(V)))}function o(e,n,r){let i=cy(e);if(n.length===0)return i;let a=n.map(cy);return Xv(t.difference([B(i),...a.map(B)]),Yv(`makeCut`,{},[V(i),...a.map(V)]))}function s(e,t,n){let r=cy(e),{normal:i,offset:a}=uy(t),[o]=B(r).splitByPlane(i,a);return Xv(o,Yv(`section`,{normal:i,offset:a},[V(r),V(cy(t))]))}function c(e,n){let r=cy(e),[i]=n;if(i===void 0)throw Error(`manifold: split requires at least one tool`);let a=cy(i),{normal:o,offset:s}=uy(i),[c,l]=B(r).splitByPlane(o,s);return Xv(t.union([c,l]),Yv(`split`,{normal:o,offset:s},[V(r),V(a)]))}function l(e,t,n){let r=[],i=cy(e),a=cy(t);return(B(i)===void 0||B(i).isEmpty())&&r.push({operand:`base`,issue:`null-shape`,message:`Base shape is empty`}),(B(a)===void 0||B(a).isEmpty())&&r.push({operand:`tool`,issue:`null-shape`,message:`Tool shape is empty`}),{valid:r.length===0,issues:r}}function u(n,r,i,a,o,s){let c=new e.Mesh({numProp:3,vertProperties:new Float32Array(n),triVerts:new Uint32Array(r)}),l=new e.Mesh({numProp:3,vertProperties:new Float32Array(i),triVerts:new Uint32Array(a)});return dy(ly(t.ofMesh(c),t.ofMesh(l),o).getMesh())}return{fuse:n,cut:r,intersect:i,section:s,fuseAll:a,cutAll:o,split:c,checkBoolean:l,meshBoolean:u}}function py(e){return e}function my(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function hy(e){let t=Math.hypot(e[0],e[1],e[2]);return t<1e-12?[0,0,1]:[e[0]/t,e[1]/t,e[2]/t]}function gy(e,t,n){let r=my();return r[12]=e,r[13]=t,r[14]=n,r}function _y(e,t,n){let r=e*Math.PI/180,[i,a,o]=hy(t),s=Math.cos(r),c=Math.sin(r),l=1-s,u=l*i*i+s,d=l*i*a+c*o,f=l*i*o-c*a,p=l*i*a-c*o,m=l*a*a+s,h=l*a*o+c*i,g=l*i*o+c*a,_=l*a*o-c*i,v=l*o*o+s,y=my();return y[0]=u,y[1]=d,y[2]=f,y[4]=p,y[5]=m,y[6]=h,y[8]=g,y[9]=_,y[10]=v,y[12]=n[0]-(u*n[0]+p*n[1]+g*n[2]),y[13]=n[1]-(d*n[0]+m*n[1]+_*n[2]),y[14]=n[2]-(f*n[0]+h*n[1]+v*n[2]),y}function vy(e,t){let n=my();return n[0]=t,n[5]=t,n[10]=t,n[12]=e[0]*(1-t),n[13]=e[1]*(1-t),n[14]=e[2]*(1-t),n}function yy(e,t){let[n,r,i]=hy(t),a=1-2*n*n,o=1-2*r*r,s=1-2*i*i,c=-2*n*r,l=-2*n*i,u=-2*r*i,d=my();d[0]=a,d[1]=c,d[2]=l,d[4]=c,d[5]=o,d[6]=u,d[8]=l,d[9]=u,d[10]=s;let f=e[0]*n+e[1]*r+e[2]*i;return d[12]=2*f*n,d[13]=2*f*r,d[14]=2*f*i,d}function by(e,t){let n=my();return n[0]=e[0],n[1]=e[3],n[2]=e[6],n[4]=e[1],n[5]=e[4],n[6]=e[7],n[8]=e[2],n[9]=e[5],n[10]=e[8],n[12]=t[0],n[13]=t[1],n[14]=t[2],n}function xy(e,t,n,r,i){return Xv(e.transform(t),Yv(n,r,[i]))}function Sy(e,t,n,r){let i=py(e);return xy(B(i),gy(t,n,r),`translateShape`,{x:t,y:n,z:r},V(i))}function Cy(e,t,n=[0,0,1],r=[0,0,0]){let i=py(e);return xy(B(i),_y(t,n,r),`rotateShape`,{angle:t,axis:n,center:r},V(i))}function wy(e,t,n){let r=py(e);return xy(B(r),yy(t,n),`mirrorShape`,{origin:t,normal:n},V(r))}function Ty(e,t,n){let r=py(e);return xy(B(r),vy(t,n),`scaleShape`,{center:t,factor:n},V(r))}function Ey(e,t){if(!Array.isArray(t)||t.length!==16)throw Error(`manifold: transform expects a 16-element column-major matrix`);let n=py(e);return xy(B(n),t,`transformShape`,{matrix:[...t]},V(n))}function Dy(e,t,n,r){let i=py(e);return xy(B(i),by(t,n),`generalTransform`,{linear:t,translation:n,isOrthogonal:r},V(i))}function Oy(e,t,n){let r=py(e);return xy(B(r),by(t,n),`generalTransformNonOrthogonal`,{linear:t,translation:n},V(r))}function ky(e){let t=my();for(let n of e)t=Fy(n.type===`translate`?gy(n.x,n.y,n.z):_y(n.angle,n.axis??[0,0,1],n.center??[0,0,0]),t);return{handle:t,dispose:()=>{}}}function Ay(e,t,n,r){let i=[e];for(let a=1;a<r;a++){let r=n*a;i.push(Sy(e,t[0]*r,t[1]*r,t[2]*r))}return i}function jy(e,t,n,r,i){let a=[e];for(let o=1;o<i;o++)a.push(Cy(e,r*o,n,t));return a}function My(e,t,n,r,i,a,o,s){let c=py(t),l=[],u=[];for(let e=0;e<o;e++)for(let t=0;t<s;t++){let o=n[0]*i*e+r[0]*a*t,s=n[1]*i*e+r[1]*a*t,d=n[2]*i*e+r[2]*a*t;l.push(B(c).transform(gy(o,s,d))),u.push(V(c))}return Xv(l.length===1?l[0]:e.Manifold.union(l),Yv(`gridPattern`,{directionX:n,directionY:r,spacingX:i,spacingY:a,countX:o,countY:s},u))}function Ny(e){return e.map(e=>{switch(e.type){case`translate`:return Sy(e.shape,e.x,e.y,e.z);case`rotate`:return Cy(e.shape,e.angle,e.axis,e.center);case`scale`:return Ty(e.shape,e.center,e.factor);case`mirror`:return wy(e.shape,e.origin,e.normal)}})}function Py(e){return{composeTransform:ky,transform:Ey,translate:Sy,rotate:Cy,mirror:wy,scale:Ty,generalTransform:Dy,generalTransformNonOrthogonal:Oy,positionOnCurve:()=>z(`positionOnCurve`),linearPattern:Ay,circularPattern:jy,gridPattern:(t,n,r,i,a,o,s)=>My(e,t,n,r,i,a,o,s),transformBatch:Ny}}function Fy(e,t){let n=my();for(let r=0;r<4;r++)for(let i=0;i<4;i++){let a=0;for(let n=0;n<4;n++){let o=e[n*4+i]??0,s=t[r*4+n]??0;a+=o*s}n[r*4+i]=a}return n}function Iy(e){let t=e.Manifold;function n(e,n){let r=e.map(e=>[e.x,e.y,e.z]);return Xv(t.hull(r),Yv(`hullFromPoints`,{points:r,tolerance:n},[]))}function r(e,n){let r=e.map(e=>B(e));return Xv(t.hull(r),Yv(`hull`,{tolerance:n},e.map(e=>V(e))))}function i(e,t){let n=e[0];return n||z(`sewAndSolidify (no input faces on manifold kernel)`),Xv(B(n),Yv(`sewAndSolidify`,{tolerance:t},e.map(e=>V(e))))}return{makeVertex:()=>z(`makeVertex`),makeEdge:()=>z(`makeEdge`),makeWire:()=>z(`makeWire`),makeFace:()=>z(`makeFace`),makeLineEdge:()=>z(`makeLineEdge`),makeCircleEdge:()=>z(`makeCircleEdge`),makeCircleArc:()=>z(`makeCircleArc`),makeArcEdge:()=>z(`makeArcEdge`),makeEllipseEdge:()=>z(`makeEllipseEdge`),makeEllipseArc:()=>z(`makeEllipseArc`),makeBezierEdge:()=>z(`makeBezierEdge`),makeTangentArc:()=>z(`makeTangentArc`),makeHelixWire:()=>z(`makeHelixWire`),makeWireFromMixed:()=>z(`makeWireFromMixed`),makeCompound:()=>z(`makeCompound`),solidFromShell:()=>z(`solidFromShell`),hull:r,hullFromPoints:n,buildSolidFromFaces:()=>z(`buildSolidFromFaces`),makeNonPlanarFace:()=>z(`makeNonPlanarFace`),addHolesInFace:()=>z(`addHolesInFace`),removeHolesFromFace:()=>z(`removeHolesFromFace`),makeFaceOnSurface:()=>z(`makeFaceOnSurface`),bsplineSurface:(e,t,n)=>ey(`bsplineSurface`).bsplineSurface(e,t,n),triangulatedSurface:(e,t,n)=>ey(`triangulatedSurface`).triangulatedSurface(e,t,n),buildTriFace:()=>z(`buildTriFace`),sewAndSolidify:i,createPoint3d:()=>z(`createPoint3d`),createDirection3d:()=>z(`createDirection3d`),createVector3d:()=>z(`createVector3d`),createAxis1:()=>z(`createAxis1`),createAxis2:()=>z(`createAxis2`),createAxis3:()=>z(`createAxis3`)}}function Ly(e){return e}function Ry(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function zy(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function By(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function Vy(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function Hy(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function Uy(e){return Math.hypot(e[0],e[1],e[2])}function Wy(e){let t=Uy(e);return t<1e-12?[0,0,1]:[e[0]/t,e[1]/t,e[2]/t]}function Gy(e){return Wy(zy(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function Ky(e){let t=Wy(e),n=Gy(t);return{xAxis:n,yAxis:Wy(zy(t,n))}}function qy(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n]??[0,0],i=e[(n+1)%e.length]??[0,0];t+=r[0]*i[1]-i[0]*r[1]}return t/2}function Jy(e){return qy(e)<0?[...e].reverse():e}function Yy(e){return e.node?.params}function Xy(e){let t=Ly(e),n=Yy(t),r=n?.outline??n?.polygon??n?.points;if(r&&r.length>=3){let e=n?.origin??[0,0,0],t=Jy(r.map(e=>[e[0],e[1]]));if(n?.xAxis&&n.yAxis)return{outline:t,origin:e,xAxis:n.xAxis,yAxis:n.yAxis};let{xAxis:i,yAxis:a}=Ky(n?.normal??[0,0,1]);return{outline:t,origin:e,xAxis:i,yAxis:a}}return Zy(t)}function Zy(e){let t=B(e)?.getMesh?.();if(!t)throw Error(`manifold: profile carries no recorded outline and no mesh to derive one`);let n=t.numProp,r=Math.floor(t.vertProperties.length/n),i=[],a=0;for(let e=0;e<r;e++)i.push([t.vertProperties[e*n]??0,t.vertProperties[e*n+1]??0]),a+=t.vertProperties[e*n+2]??0;a/=Math.max(1,r);let o=Qy(i);return{outline:Jy(o.length>=3?o:[[-.5,-.5],[.5,-.5],[0,.5]]),origin:[0,0,a],xAxis:[1,0,0],yAxis:[0,1,0]}}function Qy(e){let t=[...e].sort((e,t)=>e[0]===t[0]?e[1]-t[1]:e[0]-t[0]);if(t.length<3)return[...t];let n=(e,t,n)=>(t[0]-e[0])*(n[1]-e[1])-(t[1]-e[1])*(n[0]-e[0]),r=[];for(let e of t){for(;r.length>=2&&n(r[r.length-2]??e,r[r.length-1]??e,e)<=0;)r.pop();r.push(e)}let i=[];for(let e=t.length-1;e>=0;e--){let r=t[e]??[0,0];for(;i.length>=2&&n(i[i.length-2]??r,i[i.length-1]??r,r)<=0;)i.pop();i.push(r)}return r.pop(),i.pop(),[...r,...i]}function $y(e){let t=[];for(let n=1;n+1<e;n++)t.push(0,n,n+1);return t}function eb(e,t,n=1){return e.outline.map(e=>{let r=e[0]*n,i=e[1]*n;return[t.origin[0]+t.xAxis[0]*r+t.yAxis[0]*i,t.origin[1]+t.xAxis[1]*r+t.yAxis[1]*i,t.origin[2]+t.xAxis[2]*r+t.yAxis[2]*i]})}function tb(e,t){if(t.length<2)throw Error(`manifold: skinning requires at least two rings`);let n=t[0]?.length??0;if(n<3)throw Error(`manifold: skinning requires rings of at least three points`);let r=[];for(let e of t){if(e.length!==n)throw Error(`manifold: skinning requires all rings to share a vertex count`);for(let t of e)r.push(t[0],t[1],t[2])}let i=nb(t.length,n),a=new e.Mesh({numProp:3,vertProperties:Float32Array.from(r),triVerts:Uint32Array.from(i)});return new e.Manifold(a)}function nb(e,t){let n=[];for(let r=0;r+1<e;r++){let e=r*t,i=(r+1)*t;for(let r=0;r<t;r++){let a=(r+1)%t;n.push(e+r,e+a,i+a),n.push(e+r,i+a,i+r)}}let r=$y(t);for(let e=0;e<r.length;e+=3)n.push(r[e]??0,r[e+2]??0,r[e+1]??0);let i=(e-1)*t,a=$y(t);for(let e=0;e<a.length;e+=3)n.push(i+(a[e]??0),i+(a[e+1]??0),i+(a[e+2]??0));return n}function rb(e,t){let n=[];if(e.length===0)return n;let r=t=>{let n=e[Math.max(0,t-1)]??e[t]??[0,0,0];return Wy(By(e[Math.min(e.length-1,t+1)]??e[t]??[0,0,0],n))},i=r(0),a=Wy(By(t,Hy(i,Ry(t,i))));Uy(a)<1e-9&&(a=Gy(i)),n.push({origin:e[0]??[0,0,0],xAxis:a,yAxis:Wy(zy(i,a)),tangent:i});for(let t=1;t<e.length;t++){let o=e[t-1]??[0,0,0],s=e[t]??[0,0,0],c=By(s,o),l=Ry(c,c),u=a;if(l>1e-18){let e=By(a,Hy(c,2/l*Ry(c,a))),n=By(i,Hy(c,2/l*Ry(c,i))),o=By(r(t),n),s=Ry(o,o);u=s>1e-18?By(e,Hy(o,2/s*Ry(o,e))):e}let d=r(t),f=Wy(By(u,Hy(d,Ry(u,d)))),p=Wy(zy(d,f));n.push({origin:s,xAxis:f,yAxis:p,tangent:d}),i=d,a=f}return n}var ib=Math.PI/180;function ab(e){return e}function ob(e){let t=180/Math.PI*e;return t>360?360:t}function sb(e){let t=e;if(t&&typeof t.X==`function`&&typeof t.Y==`function`&&typeof t.Z==`function`)return[t.X(),t.Y(),t.Z()]}function cb(e){if(e&&typeof e==`object`){let t=e;if(`origin`in t&&`direction`in t)return{origin:t.origin,direction:t.direction};let n=e;if(typeof n.Location==`function`&&typeof n.Direction==`function`){let e=sb(n.Location()),t=sb(n.Direction());if(e&&t)return{origin:e,direction:t}}}}function lb(e){return e.outline.map(e=>[e[0],e[1]])}function ub(e){return{outline:e.outline,origin:e.origin,xAxis:e.xAxis,yAxis:e.yAxis}}function db(e){return{origin:e.origin,xAxis:e.xAxis,yAxis:e.yAxis,tangent:Wy(zy(e.xAxis,e.yAxis))}}function fb(e){let t=0;for(let n of e.outline)t=Math.max(t,Math.hypot(n[0],n[1]));return t||1}function pb(e){let t=B(e)?.getMesh?.();if(!t)return[];let n=t.numProp,r=Math.floor(t.vertProperties.length/n),i=[];for(let e=0;e<r;e++)i.push([t.vertProperties[e*n]??0,t.vertProperties[e*n+1]??0,t.vertProperties[e*n+2]??0]);return i}function mb(e,t){let n=ab(e),r=n.node?.params,i=r?.path??r?.points;if(i&&i.length>=2)return i.map(e=>[e[0],e[1],e[2]]);let a=pb(n);if(a.length>=2)return a;let o=[],s=Math.max(2,t);for(let e=0;e<s;e++)o.push([0,0,e/(s-1)]);return o}function hb(e){return e?.node??Yv(`spine`,{},[])}function gb(e,t,n){let r=e;if(!(Math.abs(n[0])<1e-9&&Math.abs(n[1])<1e-9&&n[2]>0)){let e=Math.atan2(Math.hypot(n[0],n[1]),n[2])*(180/Math.PI),t=Math.atan2(n[1],n[0])*(180/Math.PI);r=r.rotate([0,e,t])}let i=t.origin;return(i[0]!==0||i[1]!==0||i[2]!==0)&&(r=r.translate([i[0],i[1],i[2]])),r}function _b(e,t,n){let r=Wy(n);return e.outline.map(n=>{let i=By(Vy(e.origin,Vy(Hy(e.xAxis,n[0]),Hy(e.yAxis,n[1]))),t),a=i[0]*r[0]+i[1]*r[1]+i[2]*r[2];return[Uy(By(i,Hy(r,a))),a]})}function vb(e,t,n){let r=e,i=Wy(n);if(!(Math.abs(i[0])<1e-9&&Math.abs(i[2])<1e-9&&i[1]>0)){let e=Math.acos(Math.max(-1,Math.min(1,i[1])))*(180/Math.PI),t=zy([0,1,0],i);Uy(t)<1e-9&&(t=[1,0,0]),t=Wy(t),r=r.rotate([t[0]*e,t[1]*e,t[2]*e])}return(t[0]!==0||t[1]!==0||t[2]!==0)&&(r=r.translate([t[0],t[1],t[2]])),r}function yb(e,t,n,r,i){let a=Wy(t),{xAxis:o,yAxis:s}=Ky(a),c=i*2*Math.PI,l=Math.max(8,Math.ceil(Math.abs(i)*24)),u=r*i,d=[];for(let t=0;t<=l;t++){let r=t/l,i=c*r,f=Vy(Hy(o,n*Math.cos(i)),Hy(s,n*Math.sin(i)));d.push(Vy(e,Vy(f,Hy(a,u*r))))}return d}function bb(e){if(e.length!==0)return t=>{let n=t*(e.length-1),r=Math.floor(n),i=Math.min(e.length-1,r+1),a=n-r;return(e[r]??1)*(1-a)+(e[i]??1)*a}}function xb(e,t,n,r){let i=Xy(t),a=Wy([n[0],n[1],n[2]]),o=Uy([n[0]*r,n[1]*r,n[2]*r]);return Xv(gb(e.Manifold.extrude([lb(i)],o),i,a),Yv(`extrude`,{outline:i.outline,origin:i.origin,xAxis:i.xAxis,yAxis:i.yAxis,direction:[n[0],n[1],n[2]],length:r},[V(ab(t))]))}function Sb(e,t,n,r,i,a,o){let s=Xy(t),c=ob(i),l=_b(s,n,r);return Xv(vb(e.Manifold.revolve([l],0,c),n,r),Yv(a,o,[V(ab(t))]))}function Cb(e,t,n,r){if(t.length<2)throw Error(`manifold: loft requires at least two profiles`);let i=t.map(Xy),a=i[0]?.outline.length??0;return Xv(tb(e,i.map(e=>{if(e.outline.length!==a)throw Error(`manifold: loft profiles must share a vertex count for mesh skinning`);return eb(e,db(e))})),Yv(n,{sections:i.map(ub),...r},t.map(e=>V(ab(e)))))}function wb(e,t,n,r,i,a,o){let s=Xy(t),c=rb(n,s.xAxis),l=c.length;return Xv(tb(e,c.map((e,t)=>eb(s,e,o?o(l>1?t/(l-1):0):1))),Yv(i,{section:ub(s),path:n.map(e=>[e[0],e[1],e[2]]),...a},[V(ab(t)),r]))}function Tb(e,t,n,r,i,a){if(r===null)return t;let o=Xy(n),s=Wy(zy(o.xAxis,o.yAxis)),c=Math.tan(i*ib),l={origin:Vy(o.origin,Hy(s,r)),xAxis:o.xAxis,yAxis:o.yAxis,tangent:s},u=1+c*r/fb(o),d=tb(e,[eb(o,db(o),1),eb(o,l,u)]),f=Yv(`draftPrism`,{outline:o.outline,origin:o.origin,xAxis:o.xAxis,yAxis:o.yAxis,height:r,angleDeg:i,fuse:a},[V(ab(n))]);if(a){let e=ab(t);return Xv(B(e).add(d),Yv(`makeFuse`,{},[V(e),f]))}return Xv(d,f)}function Eb(e){return{revolve:(t,n,r)=>{let i=cb(n);if(!i)throw Error(`manifold: revolve could not read the axis; pass {origin,direction}, a gp_Ax1, or use revolveVec`);let{origin:a,direction:o}=i;return Sb(e,t,a,o,r,`revolve`,{...ub(Xy(t)),axisOrigin:[a[0],a[1],a[2]],axisDirection:[o[0],o[1],o[2]],angleDeg:ob(r)})},revolveVec:(t,n,r,i)=>Sb(e,t,n,r,i,`revolveVec`,{...ub(Xy(t)),center:[n[0],n[1],n[2]],direction:[r[0],r[1],r[2]],angleDeg:ob(i)})}}function Db(e){return{sweep:(t,n,r)=>{let i={};return r?.transitionMode!==void 0&&(i.transitionMode=r.transitionMode),wb(e,t,mb(n,16),hb(n),`sweep`,i)},simplePipe:(t,n)=>wb(e,t,mb(n,16),hb(n),`simplePipe`,{}),sweepWithOptions:(t,n,r,i,a)=>wb(e,t,mb(n,Math.max(2,a||16)),hb(n),`sweepWithOptions`,{contactMode:r,scaleValues:[...i],segments:a},bb(i)),sweepPipeShell:(t,n,r)=>{let i={};r?.transitionMode!==void 0&&(i.transitionMode=r.transitionMode);let a=wb(e,t,mb(n,16),hb(n),`sweepPipeShell`,i);return r?.shellMode?{shape:a,firstShape:t,lastShape:t}:a},helicalSweep:(t,n,r,i,a,o)=>wb(e,t,yb(n,r,i,a,o),hb(t),`helicalSweep`,{axisOrigin:[n[0],n[1],n[2]],axisDirection:[r[0],r[1],r[2]],radius:i,pitch:a,turns:o})}}function Ob(e){return{extrude:(t,n,r)=>xb(e,t,n,r),...Eb(e),loft:(t,n)=>Cb(e,t,`loft`,{ruled:n??!1}),loftAdvanced:(t,n)=>Cb(e,t,`loftAdvanced`,{solid:n?.solid??!0,ruled:n?.ruled??!1,tolerance:n?.tolerance}),...Db(e),draftPrism:(t,n,r,i,a,o)=>Tb(e,t,n,i,a,o),buildExtrusionLaw:(e,t,n)=>({type:`extrusionLaw`,profile:e,length:t,endFactor:n}),loftBatch:()=>z(`loftBatch`),extrudeBatch:()=>z(`extrudeBatch`)}}var kb=16;function Ab(e){return typeof e?.translate==`function`?e.translate([0,0,0]):e}function jb(e,t,n){if(!(n>0))return Ab(t);let r=Pb(e,n);return r===void 0||typeof t?.minkowskiDifference!=`function`||typeof t?.minkowskiSum!=`function`?Ab(t):t.minkowskiDifference(r).minkowskiSum(r)}function Mb(e,t,n){if(n===0)return Ab(t);let r=Pb(e,Math.abs(n));return r===void 0?Ab(t):n>0?typeof t?.minkowskiSum==`function`?t.minkowskiSum(r):Ab(t):typeof t?.minkowskiDifference==`function`?t.minkowskiDifference(r):Ab(t)}function Nb(e,t,n,r){if(n===0)return Ab(t);if(r)return Mb(e,t,Math.abs(n));let i=Mb(e,t,-Math.abs(n));return typeof t?.subtract==`function`?t.subtract(i):Ab(t)}function Pb(e,t){let n=e?.Manifold;if(typeof n?.sphere==`function`)return n.sphere(t,kb)}function Fb(e){return e}function Ib(e){let t=e;if(t!=null){if(typeof t.index==`number`)return t.index;if(typeof t.id==`number`)return t.id}}function Lb(e){let{min:t,max:n}=e;if(!(t===void 0||n===void 0||t.length<3||n.length<3))return[((t[0]??0)+(n[0]??0))/2,((t[1]??0)+(n[1]??0))/2,((t[2]??0)+(n[2]??0))/2]}function Rb(e){let t=e;if(t?.box!==void 0)return Lb(t.box);let n=(e?.manifold)?.boundingBox?.();return n===void 0?void 0:Lb(n)}function zb(e){let t=e.length;if(t===0)return{kind:`all`,count:t};let n=[];for(let t of e){let e=Rb(t);if(e===void 0){n.length=0;break}n.push(e)}if(n.length===t)return{kind:`witness`,count:t,points:n};let r=[];for(let t of e){let e=Ib(t);if(e===void 0){r.length=0;break}r.push(e)}return r.length===t?{kind:`index`,count:t,indices:r}:{kind:`all`,count:t}}function Bb(e){return typeof e==`function`&&z(`fillet (per-edge radius callback)`),e}function Vb(e){return typeof e==`number`?e:e[0]}function Hb(e){let t=e.match(/[-+]?\d*\.?\d+/);return t?Number(t[0]):0}function Ub(e,t,n,r,i){let a=Fb(n),o=Bb(i),s=zb(r);return Xv(jb(e,B(a),Vb(o)),Yv(t,{radius:o,selection:s},[V(a)]))}function Wb(e,t,n,r,i){let a=Fb(t),o=zb(n);return Xv(jb(e,B(a),r),Yv(`chamferDistAngle`,{distance:r,angleDeg:i,selection:o},[V(a)]))}function Gb(e,t,n,r,i){let a=Fb(t),o=zb(n);return Xv(Nb(e,B(a),r,!1),Yv(`shell`,i===void 0?{thickness:r,selection:o}:{thickness:r,selection:o,tolerance:i},[V(a)]))}function Kb(e,t,n){let r=Fb(t);return Xv(Nb(e,B(r),n,!0),Yv(`thicken`,{thickness:n},[V(r)]))}function qb(e,t,n,r){let i=Fb(t);return Xv(Mb(e,B(i),n),Yv(`offset`,r===void 0?{distance:n}:{distance:n,tolerance:r},[V(i)]))}function Jb(e,t,n){let r=Fb(t);return Xv(jb(e,B(r),Hb(n)),Yv(`filletVariable`,{spec:n},[V(r)]))}function Yb(e,t,n,r,i){typeof i==`function`&&z(`draft (per-face angle callback)`);let a=Fb(e),o=zb(t);return Xv(Ab(B(a)),Yv(`draft`,{pullDirection:n,neutralPlane:r,angleDeg:i,selection:o},[V(a)]))}function Xb(e,t){let n=Fb(e),r=zb(t);return Xv(Ab(B(n)),Yv(`defeature`,{selection:r},[V(n)]))}function Zb(e){let t=Fb(e),n=B(t);return Xv(typeof n?.simplify==`function`?n.simplify():Ab(n),Yv(`simplify`,{},[V(t)]))}function Qb(e){let t=Fb(e),n=B(t);return Xv(typeof n?.mirror==`function`?n.mirror([1,0,0]):Ab(n),Yv(`reverseShape`,{},[V(t)]))}function $b(e,t){let n=Fb(t.shape),r=zb(t.edges.map(e=>e.edge)),i=t.edges.map(e=>e.r2===void 0?e.radius:[e.radius,e.r2]),a=t.edges[0]?.radius??0;return Xv(jb(e,B(n),a),Yv(`fillet`,{radii:i,selection:r},[V(n)]))}function ex(e){return{fillet:(t,n,r)=>Ub(e,`fillet`,t,n,r),chamfer:(t,n,r)=>Ub(e,`chamfer`,t,n,r),chamferDistAngle:(t,n,r,i)=>Wb(e,t,n,r,i),shell:(t,n,r,i)=>Gb(e,t,n,r,i),thicken:(t,n)=>Kb(e,t,n),offset:(t,n,r)=>qb(e,t,n,r),filletVariable:(t,n)=>Jb(e,t,n),draft:(e,t,n,r,i)=>Yb(e,t,n,r,i),defeature:(e,t)=>Xb(e,t),offsetWire2D:()=>z(`offsetWire2D`),simplify:e=>Zb(e),reverseShape:e=>Qb(e),shellBatch:t=>t.map(t=>Gb(e,t.shape,t.faces,t.thickness,t.tolerance)),filletBatch:t=>t.map(t=>$b(e,t))}}function tx(e){return B(e).getMesh()}function nx(e){let t=e.numProp,n=e.vertProperties.length/t;if(t===3)return new Float32Array(e.vertProperties);let r=new Float32Array(n*3);for(let i=0;i<n;i++)r[i*3]=e.vertProperties[i*t]??0,r[i*3+1]=e.vertProperties[i*t+1]??0,r[i*3+2]=e.vertProperties[i*t+2]??0;return r}function rx(e,t){let n=new Float32Array(e.length);for(let r=0;r<t.length;r+=3){let i=(t[r]??0)*3,a=(t[r+1]??0)*3,o=(t[r+2]??0)*3,s=e[i]??0,c=e[i+1]??0,l=e[i+2]??0,u=(e[a]??0)-s,d=(e[a+1]??0)-c,f=(e[a+2]??0)-l,p=(e[o]??0)-s,m=(e[o+1]??0)-c,h=(e[o+2]??0)-l,g=d*h-f*m,_=f*p-u*h,v=u*m-d*p;for(let e of[i,a,o])n[e]=(n[e]??0)+g,n[e+1]=(n[e+1]??0)+_,n[e+2]=(n[e+2]??0)+v}for(let e=0;e<n.length;e+=3){let t=n[e]??0,r=n[e+1]??0,i=n[e+2]??0,a=Math.sqrt(t*t+r*r+i*i);a>1e-12&&(n[e]=t/a,n[e+1]=r/a,n[e+2]=i/a)}return n}function ix(e){let t=e.triVerts.length/3,{runIndex:n,runOriginalID:r}=e;if(!n||!r||n.length<2)return[{start:0,count:e.triVerts.length,faceHash:0}];let i=[];for(let e=0;e+1<n.length;e++){let a=n[e]??0,o=(n[e+1]??t*3)-a;o!==0&&i.push({start:a,count:o,faceHash:r[e]??0})}return i}function ax(e,t){let n=tx(e),r=nx(n),i=new Uint32Array(n.triVerts);return{vertices:r,normals:t.skipNormals?new Float32Array:rx(r,i),triangles:i,uvs:t.includeUVs?new Float32Array(r.length/3*2):new Float32Array,faceGroups:ix(n)}}function ox(e,t,n){let r=tx(e),i=nx(r),a=r.triVerts,o=[],s=[],c=new Set,l=i.length/3,u=e=>{o.push(i[e*3]??0,i[e*3+1]??0,i[e*3+2]??0)};for(let e=0;e<a.length;e+=3){let t=a[e]??0,n=a[e+1]??0,r=a[e+2]??0;for(let[e,i]of[[t,n],[n,r],[r,t]]){let t=Math.min(e,i),n=Math.max(e,i),r=t*l+n;if(c.has(r))continue;c.add(r);let a=o.length/3;u(t),u(n),s.push({start:a,count:2,edgeHash:r})}}return{lines:new Float32Array(o),edgeGroups:s}}function sx(e){return!0}function cx(e){return{mesh:(e,t)=>ax(e,t),meshEdges:(e,t,n)=>ox(e,t,n),hasTriangulation:e=>sx(e),meshShape:(e,t,n)=>{}}}function lx(e,t=[0,0,0]){return Array.isArray(e)&&e.length>=3?[Number(e[0]),Number(e[1]),Number(e[2])]:[...t]}function H(e,t=0){return typeof e==`number`?e:t}function ux(e,t=``){return typeof e==`string`?e:t}function dx(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function fx(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function px(e,t,n,r){return dx(t,dx(fx(n,e[0]),fx(r,e[1])))}function mx(e,t){let n=t.outline??[];if(n.length<3)throw Error(`manifold replay: profile outline needs at least three points`);let r=lx(t.origin),i=lx(t.xAxis,[1,0,0]),a=lx(t.yAxis,[0,1,0]),o=n.map(e=>px(e,r,i,a)),s=[];for(let t=0;t<o.length;t++){let n=o[t]??r,i=o[(t+1)%o.length]??r;s.push(e.makeLineEdge([n[0],n[1],n[2]],[i[0],i[1],i[2]]))}let c=e.makeWire(s),l=e.makeFace(c,!0);for(let t of s)e.dispose(t);return l}function hx(e,t){return mx(e,t)}function gx(e,t){let n=e.boundingBox(t);return[(n.min[0]+n.max[0])/2,(n.min[1]+n.max[1])/2,(n.min[2]+n.max[2])/2]}function _x(e,t){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return n*n+r*r+i*i}function vx(e,t,n,r){let i=e.iterShapes(t,r);if(!n||n.kind===`all`)return i;if(n.kind===`witness`){let t=n.points??[],r=i.map(t=>gx(e,t)),a=[],o=new Set;for(let e of t){let t=-1,n=1/0;for(let a=0;a<i.length;a++){if(o.has(a))continue;let i=_x(e,r[a]??[0,0,0]);i<n&&(n=i,t=a)}let s=i[t];t>=0&&s!==void 0&&(o.add(t),a.push(s))}return a}if(n.kind===`index`){let e=n.indices??[],t=[];for(let n of e){let e=i[n];e!==void 0&&t.push(e)}return t}let a=n.regions??[],o=e=>a.some(t=>e[0]>=t.min[0]&&e[0]<=t.max[0]&&e[1]>=t.min[1]&&e[1]<=t.max[1]&&e[2]>=t.min[2]&&e[2]<=t.max[2]);return i.filter(t=>o(gx(e,t)))}function yx(e){let t=e.selection;return t===void 0?void 0:t}function bx(e){let t=e[0];if(t===void 0)throw Error(`manifold replay: op requires an input shape`);return t}function xx(e,t,n){return e.createAxis1(t[0],t[1],t[2],n[0],n[1],n[2])}function Sx(e,t){return(n,r)=>{let i=mx(n,r),a=lx(r[e]),o=lx(r[t],[0,0,1]),s=H(r.angleDeg,360);return n.revolve(i,xx(n,a,o),Math.PI/180*s)}}var Cx={makeBox:(e,t)=>e.makeBox(H(t.width),H(t.height),H(t.depth)),makeBoxWithCorners:(e,t)=>e.makeBoxFromCorners(lx(t.p1),lx(t.p2)),makeCylinder:(e,t)=>e.makeCylinder(H(t.radius),H(t.height),lx(t.center),lx(t.direction,[0,0,1])),makeSphere:(e,t)=>e.makeSphere(H(t.radius),lx(t.center)),makeCone:(e,t)=>e.makeCone(H(t.radius1),H(t.radius2),H(t.height),lx(t.center),lx(t.direction,[0,0,1])),makeTorus:(e,t)=>e.makeTorus(H(t.majorRadius),H(t.minorRadius),lx(t.center),lx(t.direction,[0,0,1])),makeEllipsoid:(e,t)=>e.makeEllipsoid(H(t.aLength),H(t.bLength),H(t.cLength)),makeFuse:(e,t,n)=>{if(n.length<2)return bx(n);let r=bx(n);for(let t of n.slice(1))r=e.fuse(r,t);return r},makeCut:(e,t,n)=>{let r=bx(n);return e.cutAll(r,n.slice(1))},makeCommon:(e,t,n)=>{let r=bx(n);for(let t of n.slice(1))r=e.intersect(r,t);return r},translateShape:(e,t,n)=>e.translate(bx(n),H(t.x),H(t.y),H(t.z)),rotateShape:(e,t,n)=>e.rotate(bx(n),H(t.angle),lx(t.axis,[0,0,1]),lx(t.center)),scaleShape:(e,t,n)=>e.scale(bx(n),lx(t.center),H(t.factor,1)),mirrorShape:(e,t,n)=>e.mirror(bx(n),lx(t.origin),lx(t.normal,[1,0,0])),transformShape:(e,t,n)=>e.transform(bx(n),t.matrix),generalTransform:(e,t,n)=>e.generalTransform(bx(n),t.linear,lx(t.translation),!!t.isOrthogonal),generalTransformNonOrthogonal:(e,t,n)=>e.generalTransformNonOrthogonal(bx(n),t.linear,lx(t.translation)),gridPattern:(e,t,n)=>{if(typeof e.gridPattern!=`function`)throw Error(`manifold replay: target kernel lacks gridPattern`);return e.gridPattern(bx(n),lx(t.directionX),lx(t.directionY),H(t.spacingX),H(t.spacingY),H(t.countX,1),H(t.countY,1))},extrude:(e,t)=>{let n=mx(e,t);return e.extrude(n,lx(t.direction,[0,0,1]),H(t.length,1))},revolve:Sx(`axisOrigin`,`axisDirection`),revolveVec:Sx(`center`,`direction`),loft:(e,t)=>{let n=(t.sections??[]).map(t=>wx(e,t));return e.loft(n,!!t.ruled)},loftAdvanced:(e,t)=>{let n=(t.sections??[]).map(t=>wx(e,t)),r={solid:t.solid!==!1,ruled:!!t.ruled};return typeof t.tolerance==`number`&&(r.tolerance=t.tolerance),e.loftAdvanced(n,r)},sweep:(e,t)=>e.sweep(Tx(e,t),Ex(e,t)),simplePipe:(e,t)=>e.simplePipe(Tx(e,t),Ex(e,t)),sweepWithOptions:(e,t)=>e.sweepWithOptions(Tx(e,t),Ex(e,t),ux(t.contactMode),t.scaleValues??[],H(t.segments,0)),sweepPipeShell:(e,t)=>{let n=e.sweepPipeShell(Tx(e,t),Ex(e,t));return Dx(n)?n.shape:n},helicalSweep:(e,t)=>e.helicalSweep(Tx(e,t),lx(t.axisOrigin),lx(t.axisDirection,[0,0,1]),H(t.radius),H(t.pitch),H(t.turns,1)),draftPrism:(e,t)=>{let n=mx(e,t);return e.draftPrism(n,n,n,H(t.height),H(t.angleDeg),!!t.fuse)},fillet:(e,t,n)=>{let r=bx(n),i=vx(e,r,yx(t),`edge`),a=t.radii,o=t.radius;if(a&&a.length>1){let t=new Map;for(let e=0;e<i.length;e++){let n=i[e],r=a[e]??a[a.length-1];n!==void 0&&r!==void 0&&t.set(n,r)}return e.fillet(r,i,e=>t.get(e)??0)}let s=a?.[0]??o;return e.fillet(r,i,s??0)},chamfer:(e,t,n)=>{let r=bx(n),i=vx(e,r,yx(t),`edge`);return e.chamfer(r,i,t.radius)},chamferDistAngle:(e,t,n)=>{let r=bx(n),i=vx(e,r,yx(t),`edge`);return e.chamferDistAngle(r,i,H(t.distance),H(t.angleDeg))},shell:(e,t,n)=>{let r=bx(n),i=vx(e,r,yx(t),`face`);return typeof t.tolerance==`number`?e.shell(r,i,H(t.thickness),t.tolerance):e.shell(r,i,H(t.thickness))},thicken:(e,t,n)=>e.thicken(bx(n),H(t.thickness)),offset:(e,t,n)=>typeof t.tolerance==`number`?e.offset(bx(n),H(t.distance),t.tolerance):e.offset(bx(n),H(t.distance)),filletVariable:(e,t,n)=>e.filletVariable(bx(n),ux(t.spec)),draft:(e,t,n)=>{let r=bx(n),i=vx(e,r,yx(t),`face`);return e.draft(r,i,lx(t.pullDirection,[0,0,1]),lx(t.neutralPlane),H(t.angleDeg))},defeature:(e,t,n)=>{let r=bx(n),i=vx(e,r,yx(t),`face`);return e.defeature(r,i)},simplify:(e,t,n)=>e.simplify(bx(n)),reverseShape:(e,t,n)=>e.reverseShape(bx(n)),hull:(e,t,n)=>e.hull([...n],H(t.tolerance)),hullFromPoints:(e,t)=>{let n=t.points??[];return e.hullFromPoints(n.map(e=>({x:e[0],y:e[1],z:e[2]})),H(t.tolerance))},sewAndSolidify:(e,t,n)=>e.sewAndSolidify([...n],H(t.tolerance))};function wx(e,t){let n=hx(e,t);return e.iterShapes(n,`wire`)[0]??n}function Tx(e,t){let n=t.section;return n?hx(e,n):mx(e,t)}function Ex(e,t){let n=t.path??[];if(n.length<2)throw Error(`manifold replay: sweep spine needs at least two path points`);let r=[];for(let t=0;t+1<n.length;t++){let i=n[t]??[0,0,0],a=n[t+1]??[0,0,0];r.push(e.makeLineEdge([i[0],i[1],i[2]],[a[0],a[1],a[2]]))}let i=e.makeWire(r);for(let t of r)e.dispose(t);return i}function Dx(e){return typeof e==`object`&&!!e&&`shape`in e&&`firstShape`in e&&`lastShape`in e}function Ox(e,t,n,r){let i=n.get(e);if(i!==void 0)return i;if(!e.replayable)throw Error(`manifold replay: op '${e.op}' is not replayable (raw-mesh origin or unsupported)`);let a=Cx[e.op];if(!a)throw Error(`manifold replay: no replay handler for op '${e.op}'`);let o=e.inputs.map(e=>Ox(e,t,n,r)),s=a(t,e.params,o);return n.set(e,s),r.add(s),s}function kx(e,t,n=new Map){let r=new Set,i=Ox(e,t,n,r);for(let e of r)e!==i&&t.dispose(e);return i}function Ax(e){return B(e)}function jx(e){return Ax(e).boundingBox()}function Mx(e){return Ax(e)?.getMesh?.()}function Nx(e,t){let n=t*e.numProp;return[e.vertProperties[n]??0,e.vertProperties[n+1]??0,e.vertProperties[n+2]??0]}function Px(e,t){let n=t*3;return[e.triVerts[n]??0,e.triVerts[n+1]??0,e.triVerts[n+2]??0]}function Fx(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function Ix(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function Lx(e){let t=jx(e);return[(t.min[0]+t.max[0])/2,(t.min[1]+t.max[1])/2,(t.min[2]+t.max[2])/2]}function Rx(e){let t=Math.floor(e.vertProperties.length/e.numProp);if(t===0)return[0,0,0];let n=[0,0,0];for(let r=0;r<t;r++){let t=Nx(e,r);n[0]+=t[0],n[1]+=t[1],n[2]+=t[2]}return[n[0]/t,n[1]/t,n[2]/t]}function zx(e){let t=Mx(e);if(!t)return Lx(e);let n=Math.floor(t.triVerts.length/3),r=0,i=[0,0,0];for(let e=0;e<n;e++){let[n,a,o]=Px(t,e),s=Nx(t,n),c=Nx(t,a),l=Nx(t,o),u=Ix(s,Fx(c,l))/6;r+=u,i[0]+=(s[0]+c[0]+l[0])/4*u,i[1]+=(s[1]+c[1]+l[1])/4*u,i[2]+=(s[2]+c[2]+l[2])/4*u}return Math.abs(r)<1e-12?Rx(t):[i[0]/r,i[1]/r,i[2]/r]}function Bx(e){let t=Mx(e);if(!t)return Lx(e);let n=Math.floor(t.triVerts.length/3),r=0,i=[0,0,0];for(let e=0;e<n;e++){let[n,a,o]=Px(t,e),s=Nx(t,n),c=Nx(t,a),l=Nx(t,o),u=Fx([c[0]-s[0],c[1]-s[1],c[2]-s[2]],[l[0]-s[0],l[1]-s[1],l[2]-s[2]]),d=Math.hypot(u[0],u[1],u[2])/2;r+=d,i[0]+=(s[0]+c[0]+l[0])/3*d,i[1]+=(s[1]+c[1]+l[1])/3*d,i[2]+=(s[2]+c[2]+l[2])/3*d}return r<1e-12?Rx(t):[i[0]/r,i[1]/r,i[2]/r]}function Vx(e){return Ax(e).volume()}function Hx(e){return Ax(e).surfaceArea()}function Ux(e){let t=jx(e);return{min:[...t.min],max:[...t.max]}}function Wx(e){return zx(e)}function Gx(e,t){let n=(e,t,n,r)=>{if(t<n)return[t,n];if(r<e)return[e,r];let i=(Math.max(e,n)+Math.min(t,r))/2;return[i,i]},[r,i]=n(e.min[0],e.max[0],t.min[0],t.max[0]),[a,o]=n(e.min[1],e.max[1],t.min[1],t.max[1]),[s,c]=n(e.min[2],e.max[2],t.min[2],t.max[2]),l=i-r,u=o-a,d=c-s;return{value:Math.sqrt(l*l+u*u+d*d),point1:[r,a,s],point2:[i,o,c]}}function Kx(e,t){return Gx(jx(e),jx(t))}function qx(e,t=!1){return{volume:Vx(e),area:Hx(e),length:0,centerOfMass:Wx(e),boundingBox:Ux(e)}}function Jx(e,t,n){let r=$v();if(!r)throw Error(`manifold: surfaceCurvature requires a registered occt kernel; none is available`);let i=Zv(e);if(!i)return r.surfaceCurvature(e,t,n);if(!i.node.replayable)throw Error(`manifold: surfaceCurvature unsupported; shape originates from a non-replayable op (raw mesh import or mesh boolean)`);let a=ty.get(i.node)??(()=>{let e=kx(i.node,r);return ty.set(i.node,e),e})();return r.surfaceCurvature(a,t,n)}function Yx(e){return{volume:e=>Vx(e),area:e=>Hx(e),length:()=>z(`length`),centerOfMass:e=>Wx(e),linearCenterOfMass:e=>Wx(e),boundingBox:e=>Ux(e),distance:(e,t)=>Kx(e,t),surfaceCurvature:(e,t,n)=>Jx(e,t,n),surfaceCenterOfMass:e=>Bx(e),measureBulk:(e,t)=>qx(e,t),createDistanceQuery:e=>({distanceTo:t=>Kx(e,t),dispose:()=>{}})}}function Xx(e,t){let n=Zv(e);if(!n)throw Error(`manifold: ${t} requires a manifold shape handle`);if(!n.node.replayable)throw Error(`manifold: ${t} unsupported; shape originates from a non-replayable op (raw mesh import or mesh boolean)`);let r=ey(t),i=ty.get(n.node);if(i!==void 0)return{occt:r,brep:i};let a=kx(n.node,r);return ty.set(n.node,a),{occt:r,brep:a}}function Zx(e){function t(e){if(Zv(e))return`solid`;let{occt:t,brep:n}=Xx(e,`shapeType`);return t.shapeType(n)}function n(e,t){let n=Zv(e),r=Zv(t);return!n||!r?!1:n.manifold===r.manifold}function r(e,t){return n(e,t)}function i(e,t){if(!Zv(e))return 0;let{occt:n,brep:r}=Xx(e,`hashCode`);return n.hashCode(r,t)}function a(e){let t=Zv(e);if(!t)return!0;let n=B(t);return!n||typeof n.isEmpty==`function`&&n.isEmpty()}function o(e){return`forward`}function s(e,t){let n=Zv(e);if(!n)return[];if(t===`solid`)return[e];if(t!==`edge`&&t!==`face`||!n.node.replayable)return[];let r=$v();if(!r)return[];let i=ty.get(n.node)??(()=>{let e=kx(n.node,r);return ty.set(n.node,e),e})();return r.iterShapes(i,t).map((e,t)=>({__manifoldSub:!0,index:t,box:r.boundingBox(e)}))}function c(e,t){ey(`iterShapeList`).iterShapeList(e,t)}function l(e){let{occt:t,brep:n}=Xx(e,`edgeToFaceMap`);return t.edgeToFaceMap(n)}function u(e,t){return ey(`sharedEdges`).sharedEdges(e,t)}function d(e,t){let{occt:n,brep:r}=Xx(e,`adjacentFaces`);return n.adjacentFaces(r,t)}return{iterShapes:s,iterShapeList:c,shapeType:t,isSame:n,isEqual:r,downcast:e=>e,hashCode:i,isNull:a,shapeOrientation:o,edgeToFaceMap:l,sharedEdges:u,adjacentFaces:d,sew:()=>{throw Error(`manifold: sew is unsupported on the mesh kernel; use a B-rep kernel`)}}}function Qx(e){return B(e).getMesh()}function $x(e){return e.numProp&&e.numProp>=3?e.numProp:3}function eS(e){return Math.floor(e.vertProperties.length/$x(e))}function tS(e,t){let n=t*$x(e);return[e.vertProperties[n]??0,e.vertProperties[n+1]??0,e.vertProperties[n+2]??0]}function nS(e,t){let n=t*3;return[e.triVerts[n]??0,e.triVerts[n+1]??0,e.triVerts[n+2]??0]}function rS(e,t,n){let r=t[0]-e[0],i=t[1]-e[1],a=t[2]-e[2],o=n[0]-e[0],s=n[1]-e[1],c=n[2]-e[2],l=i*c-a*s,u=a*o-r*c,d=r*s-i*o,f=Math.hypot(l,u,d)||1;return[l/f,u/f,d/f]}function iS(e,t){let n=Qx(e),r=Math.floor(n.triVerts.length/3);if(t){let e=new ArrayBuffer(84+r*50),t=new DataView(e);t.setUint32(80,r,!0);let i=84;for(let e=0;e<r;e++){let[r,a,o]=nS(n,e),s=tS(n,r),c=tS(n,a),l=tS(n,o),u=rS(s,c,l);t.setFloat32(i,u[0],!0),t.setFloat32(i+4,u[1],!0),t.setFloat32(i+8,u[2],!0),i+=12;for(let e of[s,c,l])t.setFloat32(i,e[0],!0),t.setFloat32(i+4,e[1],!0),t.setFloat32(i+8,e[2],!0),i+=12;t.setUint16(i,0,!0),i+=2}return e}let i=[`solid manifold`];for(let e=0;e<r;e++){let[t,r,a]=nS(n,e),o=tS(n,t),s=tS(n,r),c=tS(n,a),l=rS(o,s,c);i.push(` facet normal ${l[0]} ${l[1]} ${l[2]}`),i.push(` outer loop`);for(let e of[o,s,c])i.push(` vertex ${e[0]} ${e[1]} ${e[2]}`);i.push(` endloop`),i.push(` endfacet`)}return i.push(`endsolid manifold`),i.join(`
|
|
8
|
-
`)}function
|
|
9
|
-
`)).buffer}function
|
|
10
|
-
`)){let t=e.trim();if(t.startsWith(`v `)){let e=t.slice(2).trim().split(/\s+/);r.push(Number(e[0]),Number(e[1]),Number(e[2]))}else if(t.startsWith(`f `)){let e=t.slice(2).trim().split(/\s+/).map(e=>{let t=e.split(`/`)[0]??``,n=Number(t);return n>0?n-1:r.length/3+n});for(let t=1;t+1<e.length;t++)i.push(e[0]??0,e[t]??0,e[t+1]??0)}}return sS(e,{vertProperties:Float32Array.from(r),triVerts:Uint32Array.from(i)})}function lS(e,t){let n=new Uint8Array(t),r=new TextDecoder().decode(n.subarray(0,Math.min(n.length,80))).trimStart().toLowerCase().startsWith(`solid`)&&fS(n),i=[];if(r){let e=new TextDecoder().decode(n).match(/vertex\s+(\S+)\s+(\S+)\s+(\S+)/g)??[];for(let t of e){let e=t.trim().split(/\s+/);i.push(Number(e[1]),Number(e[2]),Number(e[3]))}}else{let e=new DataView(t),n=e.getUint32(80,!0),r=84;for(let t=0;t<n;t++){r+=12;for(let t=0;t<3;t++)i.push(e.getFloat32(r,!0),e.getFloat32(r+4,!0),e.getFloat32(r+8,!0)),r+=12;r+=2}}let a=dS(i);return sS(e,{vertProperties:Float32Array.from(a.vertices),triVerts:Uint32Array.from(a.indices)})}var uS=1e6;function dS(e){let t=[],n=[],r=new Map;for(let i=0;i+2<e.length;i+=3){let a=e[i]??0,o=e[i+1]??0,s=e[i+2]??0,c=`${Math.round(a*uS)},${Math.round(o*uS)},${Math.round(s*uS)}`,l=r.get(c);l===void 0&&(l=t.length/3,r.set(c,l),t.push(a,o,s)),n.push(l)}return{vertices:t,indices:n}}function fS(e){return e.length<84?!0:84+new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(80,!0)*50!==e.length}var pS=1e-6;function mS(e,t){let n=V(t);if(n.replayable)return kx(n,e)}function hS(e,t){let n=Qx(t),r=Math.floor(n.triVerts.length/3),i=[];for(let t=0;t<r;t++){let[r,a,o]=nS(n,t),s=e.buildTriFace(tS(n,r),tS(n,a),tS(n,o));s&&i.push(s)}if(i.length===0)throw Error(`manifold: cannot export — shape has no triangles to facet`);return e.sewAndSolidify(i,pS)}function gS(e){let t=ey(`B-rep export`),n=mS(t,e);return n===void 0?(console.warn(`manifold: exact B-rep unavailable (non-replayable op-graph); exporting faceted approximation`),{occt:t,brep:hS(t,e)}):{occt:t,brep:n}}function _S(e,t,n,r){let i=t.mesh(n,{tolerance:.01,angularTolerance:.5});return sS(e,{vertProperties:Float32Array.from(i.vertices),triVerts:Uint32Array.from(i.triangles)},r)}var vS=1179937895,yS=2,bS=1313821514,xS=5130562,SS=5126,CS=5125,wS=5123,TS=5121,ES=34962,DS=34963,OS=4;function kS(e){return e+3&-4}function AS(e){let t=Qx(e),n=t.numProp&&t.numProp>=3?t.numProp:3,r=Math.floor(t.vertProperties.length/n),i=t.triVerts.length,a=new Float32Array(r*3),o=1/0,s=1/0,c=1/0,l=-1/0,u=-1/0,d=-1/0;for(let e=0;e<r;e++){let r=t.vertProperties[e*n]??0,i=t.vertProperties[e*n+1]??0,f=t.vertProperties[e*n+2]??0;a[e*3]=r,a[e*3+1]=i,a[e*3+2]=f,r<o&&(o=r),i<s&&(s=i),f<c&&(c=f),r>l&&(l=r),i>u&&(u=i),f>d&&(d=f)}r===0&&(o=s=c=l=u=d=0);let f=Uint32Array.from(t.triVerts),p=a.byteLength,m=kS(p),h=m+f.byteLength,g={asset:{version:`2.0`,generator:`brepjs manifold kernel`},scene:0,scenes:[{nodes:[0]}],nodes:[{mesh:0}],meshes:[{primitives:[{attributes:{POSITION:0},indices:1,mode:OS}]}],accessors:[{bufferView:0,componentType:SS,count:r,type:`VEC3`,min:[o,s,c],max:[l,u,d]},{bufferView:1,componentType:CS,count:i,type:`SCALAR`}],bufferViews:[{buffer:0,byteOffset:0,byteLength:p,target:ES},{buffer:0,byteOffset:m,byteLength:f.byteLength,target:DS}],buffers:[{byteLength:h}]},_=new TextEncoder().encode(JSON.stringify(g)),v=kS(_.length),y=kS(h),b=20+v+8+y,x=new ArrayBuffer(b),S=new DataView(x),C=new Uint8Array(x);S.setUint32(0,vS,!0),S.setUint32(4,yS,!0),S.setUint32(8,b,!0);let w=12;S.setUint32(w,v,!0),S.setUint32(w+4,bS,!0),w+=8,C.set(_,w);for(let e=_.length;e<v;e++)C[w+e]=32;return w+=v,S.setUint32(w,y,!0),S.setUint32(w+4,xS,!0),w+=8,C.set(new Uint8Array(a.buffer,a.byteOffset,p),w),C.set(new Uint8Array(f.buffer,f.byteOffset,f.byteLength),w+m),x}function jS(e,t){let n=new DataView(t);if(n.getUint32(0,!0)!==vS)throw Error(`manifold: importGLB — not a binary glTF (bad magic)`);let r=n.getUint32(8,!0),i,a,o=12;for(;o<r;){let e=n.getUint32(o,!0),r=n.getUint32(o+4,!0),s=new Uint8Array(t,o+8,e);r===bS?i=JSON.parse(new TextDecoder().decode(s)):r===xS&&(a=s),o+=8+e}if(!i||typeof i!=`object`||!a)throw Error(`manifold: importGLB — missing JSON or BIN chunk`);let s=i,c=s.meshes?.[0]?.primitives[0],l=s.accessors??[],u=s.bufferViews??[];if(!c||c.attributes.POSITION===void 0)throw Error(`manifold: importGLB — no POSITION attribute`);let d=l[c.attributes.POSITION];if(!d)throw Error(`manifold: importGLB — invalid POSITION accessor`);let f=u[d.bufferView];if(!f)throw Error(`manifold: importGLB — invalid POSITION bufferView`);let p=new Float32Array(a.buffer.slice(a.byteOffset+(f.byteOffset??0),a.byteOffset+(f.byteOffset??0)+d.count*3*4)),m;if(c.indices!==void 0){let e=l[c.indices];if(!e)throw Error(`manifold: importGLB — invalid indices accessor`);let t=u[e.bufferView];if(!t)throw Error(`manifold: importGLB — invalid indices bufferView`);let n=e.componentType===CS?4:e.componentType===wS?2:+(e.componentType===TS);if(n===0)throw Error(`manifold: importGLB — unsupported index component type ${e.componentType}`);let r=a.byteOffset+(t.byteOffset??0),i=new DataView(a.buffer,r,e.count*n);m=new Uint32Array(e.count);for(let t=0;t<e.count;t++){let e=t*n;m[t]=n===4?i.getUint32(e,!0):n===2?i.getUint16(e,!0):i.getUint8(e)}}else m=Uint32Array.from({length:d.count},(e,t)=>t);return sS(e,{vertProperties:p,triVerts:m},`importGLB`)}function MS(e){return{exportSTL:(e,t)=>iS(e,t),exportOBJ:e=>aS(e),exportPLY:e=>oS(e),importSTL:t=>lS(e,typeof t==`string`?new TextEncoder().encode(t).buffer:t),importOBJ:t=>cS(e,t),exportSTEP:e=>ey(`exportSTEP`).exportSTEP(e.map(e=>gS(e).brep)),exportIGES:e=>ey(`exportIGES`).exportIGES(e.map(e=>gS(e).brep)),toBREP:e=>{let{occt:t,brep:n}=gS(e);return t.toBREP(n)},exportSTEPAssembly:(e,t)=>{let n=ey(`exportSTEPAssembly`),r=e.map(e=>{let t={shape:gS(e.shape).brep,name:e.name};return e.color===void 0?t:{...t,color:e.color}});return n.exportSTEPAssembly(r,t)},createXCAFDocument:e=>{let t=ey(`createXCAFDocument`),n=e.map(e=>{let t={shape:gS(e.shape).brep,name:e.name};return e.color===void 0?t:{...t,color:e.color}});return t.createXCAFDocument(n)},writeXCAFToSTEP:(e,t)=>ey(`writeXCAFToSTEP`).writeXCAFToSTEP(e,t),exportSTEPConfigured:(e,t)=>{let n=ey(`exportSTEPConfigured`),r=e.map(e=>{let t={shape:gS(e.shape).brep},n=e.name===void 0?t:{...t,name:e.name};return e.color===void 0?n:{...n,color:e.color}});return n.exportSTEPConfigured(r,t)},importSTEP:t=>{let n=ey(`importSTEP`);return n.importSTEP(t).map(t=>_S(e,n,t,`importSTEP`))},importIGES:t=>{let n=ey(`importIGES`);return n.importIGES(t).map(t=>_S(e,n,t,`importIGES`))},fromBREP:t=>{let n=ey(`fromBREP`);return _S(e,n,n.fromBREP(t),`fromBREP`)},exportGLB:e=>AS(e),importGLB:t=>jS(e,t),export3MF:()=>{throw Error(`manifold: 3MF IO is unsupported on the mesh kernel; export GLB/STL/OBJ or use a B-rep kernel`)},import3MF:()=>{throw Error(`manifold: 3MF IO is unsupported on the mesh kernel; export GLB/STL/OBJ or use a B-rep kernel`)}}}function NS(e){return B(e).getMesh()}function PS(e,t){let n=t*(e.numProp&&e.numProp>=3?e.numProp:3);return[e.vertProperties[n]??0,e.vertProperties[n+1]??0,e.vertProperties[n+2]??0]}function FS(e,t){let n=Zv(e);if(!n)throw Error(`manifold: exact geometry query requires a manifold shape handle`);let r=$v();if(!r)throw Error(`manifold: exact geometry query unsupported on manifold kernel; no B-rep kernel registered`);if(!n.node.replayable)throw Error(`manifold: exact geometry query unsupported; shape originates from a non-replayable op (raw mesh import or mesh boolean)`);let i=ty.get(n.node);return i===void 0&&(i=kx(n.node,r),ty.set(n.node,i)),t(i,r)}function IS(e){return{curveType:e=>FS(e,(e,t)=>t.curveType(e)),curveParameters:e=>FS(e,(e,t)=>t.curveParameters(e)),curvePointAtParam:(e,t)=>FS(e,(e,n)=>n.curvePointAtParam(e,t)),curveTangent:(e,t)=>FS(e,(e,n)=>n.curveTangent(e,t)),curveIsClosed:e=>FS(e,(e,t)=>t.curveIsClosed(e)),curveIsPeriodic:e=>FS(e,(e,t)=>t.curveIsPeriodic(e)),curvePeriod:e=>FS(e,(e,t)=>t.curvePeriod(e)),interpolatePoints:(e,t)=>ey(`interpolatePoints`).interpolatePoints(e,t),approximatePoints:(e,t)=>ey(`approximatePoints`).approximatePoints(e,t),curveDegreeElevate:(e,t)=>FS(e,(e,n)=>n.curveDegreeElevate(e,t)),curveKnotInsert:(e,t,n)=>FS(e,(e,r)=>r.curveKnotInsert(e,t,n)),curveKnotRemove:(e,t,n)=>FS(e,(e,r)=>r.curveKnotRemove(e,t,n)),curveSplit:(e,t)=>FS(e,(e,n)=>n.curveSplit(e,t)),createCurveAdaptor:e=>FS(e,(e,t)=>t.createCurveAdaptor(e)),getBezierPenultimatePole:e=>FS(e,(e,t)=>t.getBezierPenultimatePole(e)),getNurbsCurveData:e=>FS(e,(e,t)=>t.getNurbsCurveData?.(e)??null),vertexPosition:e=>Zv(e)?PS(NS(e),0):FS(e,(e,t)=>t.vertexPosition(e)),surfaceType:e=>FS(e,(e,t)=>t.surfaceType(e)),uvBounds:e=>FS(e,(e,t)=>t.uvBounds(e)),outerWire:e=>FS(e,(e,t)=>t.outerWire(e)),surfaceNormal:(e,t,n)=>FS(e,(e,r)=>r.surfaceNormal(e,t,n)),pointOnSurface:(e,t,n)=>FS(e,(e,r)=>r.pointOnSurface(e,t,n)),uvFromPoint:(e,t)=>FS(e,(e,n)=>n.uvFromPoint(e,t)),projectPointOnFace:(e,t)=>FS(e,(e,n)=>n.projectPointOnFace(e,t)),classifyPointOnFace:(e,t,n,r)=>FS(e,(e,i)=>i.classifyPointOnFace(e,t,n,r)),classifyPointRobust:(e,t,n)=>FS(e,(e,r)=>r.classifyPointRobust(e,t,n)),classifyPointWinding:(e,t,n)=>FS(e,(e,r)=>r.classifyPointWinding(e,t,n)),approximateSurfaceLspia:(e,t,n,r,i,a,o,s,c)=>ey(`approximateSurfaceLspia`).approximateSurfaceLspia(e,t,n,r,i,a,o,s,c),untrimFace:(e,t,n)=>FS(e,(e,r)=>r.untrimFace(e,t,n)),getSurfaceCylinderData:e=>FS(e,(e,t)=>t.getSurfaceCylinderData(e)),reverseSurfaceU:e=>ey(`reverseSurfaceU`).reverseSurfaceU(e),detectSmallFeatures:(e,t,n)=>FS(e,(e,r)=>r.detectSmallFeatures(e,t,n)),recognizeFeatures:(e,t)=>FS(e,(e,n)=>n.recognizeFeatures(e,t)),projectEdges:(e,t,n,r)=>FS(e,(e,i)=>i.projectEdges(e,t,n,r)),getNurbsSurfaceData:e=>FS(e,(e,t)=>t.getNurbsSurfaceData?.(e)??null)}}var LS={hasErrors:!1,hasWarnings:!1,messages:[]};function RS(){return{modified:new Map,generated:new Map,deleted:new Set}}function zS(e){return{shape:e,evolution:RS()}}function BS(e){return{shape:e,evolution:RS(),diagnostics:LS}}function VS(e){let t=Py(e),n=fy(e),r=ex(e);return{translateWithHistory:(e,n,r,i)=>zS(t.translate(e,n,r,i)),rotateWithHistory:(e,n,r,i,a,o)=>zS(t.rotate(e,n,a,o)),mirrorWithHistory:(e,n,r)=>zS(t.mirror(e,n,r)),scaleWithHistory:(e,n,r)=>zS(t.scale(e,n,r)),generalTransformWithHistory:(e,n,r,i)=>zS(t.generalTransform(e,n,r,i)),fuseWithHistory:(e,t,r,i,a)=>BS(n.fuse(e,t,a)),cutWithHistory:(e,t,r,i,a)=>BS(n.cut(e,t,a)),intersectWithHistory:(e,t,r,i,a)=>BS(n.intersect(e,t,a)),filletWithHistory:(e,t,n)=>zS(r.fillet(e,t,n)),chamferWithHistory:(e,t,n)=>zS(r.chamfer(e,t,n)),shellWithHistory:(e,t,n,i,a,o)=>zS(r.shell(e,t,n,o)),thickenWithHistory:(e,t)=>zS(r.thicken(e,t)),offsetWithHistory:(e,t,n,i,a)=>zS(r.offset(e,t,a)),draftWithHistory:(e,t,n,i,a)=>zS(r.draft(e,t,n,i,a)),applyComposedTransformWithHistory:(e,n)=>zS(t.transform(e,n))}}function HS(e){let t=e?.manifold;if(!t||typeof t.isEmpty==`function`&&t.isEmpty())return!1;if(typeof t.status==`function`){let e=t.status(),n=typeof e==`number`?e:Number(e?.value??e);if(!Number.isNaN(n)&&n!==0)return!1}return!0}function US(e){return{isValid:e=>HS(e),isValidStrict:e=>HS(e),healSolid:e=>HS(e)?e:null,healFace:e=>e,healWire:e=>e,mergeCoincidentVertices:()=>0,removeDegenerateEdges:()=>0,fixFaceOrientations:()=>0,fixShape:e=>e,fixSelfIntersection:e=>e}}var WS=`createPoint2d.createDirection2d.createVector2d.createAxis2d.wrapCurve2dHandle.createCurve2dAdaptor.makeLine2d.makeCircle2d.makeArc2dThreePoints.makeArc2dTangent.makeEllipse2d.makeEllipseArc2d.makeBezier2d.makeBSpline2d.evaluateCurve2d.evaluateCurve2dD1.getCurve2dBounds.getCurve2dType.trimCurve2d.reverseCurve2d.copyCurve2d.offsetCurve2d.translateCurve2d.rotateCurve2d.scaleCurve2d.mirrorCurve2dAtPoint.mirrorCurve2dAcrossAxis.affinityTransform2d.createIdentityGTrsf2d.createAffinityGTrsf2d.createTranslationGTrsf2d.createMirrorGTrsf2d.createRotationGTrsf2d.createScaleGTrsf2d.setGTrsf2dTranslationPart.multiplyGTrsf2d.transformCurve2dGeneral.intersectCurves2d.projectPointOnCurve2d.distanceBetweenCurves2d.approximateCurve2dAsBSpline.decomposeBSpline2dToBeziers.createBoundingBox2d.addCurveToBBox2d.getBBox2dBounds.mergeBBox2d.isBBox2dOut.isBBox2dOutPoint.getCurve2dCircleData.getCurve2dEllipseData.getCurve2dBezierPoles.getCurve2dBezierDegree.getCurve2dBSplineData.serializeCurve2d.deserializeCurve2d.splitCurve2d.liftCurve2dToPlane.buildEdgeOnSurface.extractSurfaceFromFace.extractCurve2dFromEdge.buildCurves3d.fixWireOnFace.fillSurface`.split(`.`);function GS(e){let t=$v();if(!t)throw Error(`manifold: ${e} unsupported on manifold kernel; no B-rep kernel registered`);return t}function KS(e){let t={};for(let e of WS)t[e]=(...t)=>GS(e)[e](...t);return t}function qS(e){return{sketchNew:()=>z(`sketchNew`),sketchAddPoint:()=>z(`sketchAddPoint`),sketchAddArc:()=>z(`sketchAddArc`),sketchAddConstraint:()=>z(`sketchAddConstraint`),sketchSolve:()=>z(`sketchSolve`),sketchDof:()=>z(`sketchDof`)}}function JS(e){return{projectEdges:()=>z(`projectEdges`)}}function YS(e){return{dispose(e){let t=Zv(e);if(t){let e=ty.get(t.node);e!==void 0&&($v()?.dispose(e),ty.delete(t.node))}(e?.manifold)?.delete?.()},executeBatch:()=>z(`executeBatch`),checkpoint:()=>z(`checkpoint`),checkpointCount:()=>0,restoreCheckpoint:()=>z(`restoreCheckpoint`),discardCheckpoint:()=>z(`discardCheckpoint`)}}var XS=class{oc;kernelId=`manifold`;constructor(e){this.oc=e,Object.assign(this,sy(e),fy(e),Py(e),Iy(e),Ob(e),ex(e),cx(e),Yx(e),Zx(e),MS(e),IS(e),VS(e),US(e),KS(e),qS(e),JS(e),YS(e))}};function ZS(e){return`projectEdges`in e}function QS(e){return`sketchNew`in e&&`sketchDof`in e}var $S=new Map,eC=null,tC=null;function nC(e){rC(`manifold`,new XS(e))}function rC(e,t){$S.set(e,t),eC||=e,e===eC&&(tC=t)}function U(e){if(!e&&tC)return tC;let t=e??eC;if(!t)throw Error(`brepjs kernel not initialized. Call initFromOC() or registerKernel() before using the library.`);let n=$S.get(t);if(!n)throw Error(`brepjs: kernel '${t}' is not registered.`);return n}function iC(e){let t=U(e);if(!qa(t))throw Error(`brepjs: current kernel does not support 2D operations.`);return t}function aC(){return eC}function oC(e,t){let n=eC;eC=e,tC=$S.get(e)??null;try{let e=t();if(e instanceof Promise)throw Error(`withKernel() callback returned a Promise. Async code must use getKernel(id) directly — the kernel override is restored synchronously in finally.`);return e}finally{eC=n,tC=n?$S.get(n)??null:null}}function sC(e){lo(),wc(),no(),ec(),tc(),gc(),_c();let t=new af(e);rC(`occt`,t),eC=`occt`,tC=t}function cC(){let e=U(),t=e.makeBox(1,1,1);try{e.dispose(t)}catch{}}async function lC(){if(eC)return eC;try{let{OcctKernel:e}=await import(`occt-wasm`),t=await e.init();return rC(`occt-wasm`,ca.fromKernel(t)),`occt-wasm`}catch{}try{return sC(await(await import(`brepjs-opencascade`)).default()),`occt`}catch{}try{let e=await import(`brepkit-wasm`);return typeof e.default==`function`&&await e.default(),rC(`brepkit`,new Kv(new e.BrepKernel)),`brepkit`}catch{}throw Error(`brepjs: no kernel package found. Install one of:
|
|
7
|
+
`)}function Eg(e,t){let n=typeof t==`string`?new TextEncoder().encode(t):new Uint8Array(t);return R(e.importIges(n)).map(I)}function Dg(e,t,n){return t.length===0?``:xg(e,t.map(e=>e.shape))}function Og(e,t,n){let r=hf(t,`export3MF`);return vf(e.export3mf(r,n))}function kg(e,t,n){let r=hf(t,`exportGLB`);return vf(e.exportGlb(r,n))}function Ag(e,t,n){let r=hf(t,`exportOBJ`);return vf(e.exportObj(r,n))}function jg(e,t,n){let r=hf(t,`exportPLY`);return vf(e.exportPly(r,n))}function Mg(e,t){return R(e.import3mf(new Uint8Array(t))).map(e=>I(e))}function Ng(e,t){return I(e.importObj(new Uint8Array(t)))}function Pg(e,t){return I(e.importGlb(new Uint8Array(t)))}function Fg(e,t){let n=t;return n.type===`solid`?e.toBREP(n.id):(Af(`brep-non-solid`,`toBREP for non-solid shapes uses STEP format.`),xg(e,[t]))}function Ig(e,t){if(typeof e.fromBREP==`function`&&t.trimStart().startsWith(`{`))return I(e.fromBREP(t));let n=Cg(e,t)[0];if(!n)throw Error(`brepkit: fromBREP produced no shapes`);return n}function Lg(e,t){return{__brepkit_xcaf:!0,shapes:t,delete:of}}function Rg(e,t,n){return t&&t.__brepkit_xcaf&&Array.isArray(t.shapes)?xg(e,t.shapes.map(e=>e.shape)):``}function zg(e,t,n){return xg(e,t.map(e=>e.shape))}function Bg(e){return{exportSTEP:t=>xg(e,t),exportSTL:(t,n)=>Sg(e,t,n),importSTEP:t=>Cg(e,t),importSTL:t=>wg(e,t),exportIGES:t=>Tg(e,t),importIGES:t=>Eg(e,t),exportSTEPAssembly:(t,n)=>Dg(e,t,n),export3MF:(t,n)=>Og(e,t,n),exportGLB:(t,n)=>kg(e,t,n),exportOBJ:(t,n)=>Ag(e,t,n),exportPLY:(t,n)=>jg(e,t,n),import3MF:t=>Mg(e,t),importOBJ:t=>Ng(e,t),importGLB:t=>Pg(e,t),toBREP:t=>Fg(e,t),fromBREP:t=>Ig(e,t),createXCAFDocument:t=>Lg(e,t),writeXCAFToSTEP:(t,n)=>Rg(e,t,n),exportSTEPConfigured:(t,n)=>zg(e,t,n)}}function Vg(e,t){return{x:e,y:t}}function Hg(e,t){let n=Math.sqrt(e*e+t*t);if(n<1e-15)throw Error(`brepkit: createDirection2d called with zero-length vector`);return{x:e/n,y:t/n}}function Ug(e,t){return{x:e,y:t}}function Wg(e,t,n,r){return{px:e,py:t,dx:n,dy:r,delete:of}}function Gg(e){return e}function Kg(e){return e}function qg(e,t,n,r){return y(e,t,n,r)}function Jg(e,t,n,r){return b(e,t,n,r)}function Yg(e,t,n,r,i,a){let o=2*(e*(r-a)+n*(a-t)+i*(t-r));if(Math.abs(o)<1e-12)return y(e,t,i,a);let s=((e*e+t*t)*(r-a)+(n*n+r*r)*(a-t)+(i*i+a*a)*(t-r))/o,c=((e*e+t*t)*(i-n)+(n*n+r*r)*(e-i)+(i*i+a*a)*(n-e))/o,l=Math.sqrt((e-s)**2+(t-c)**2),u=Math.atan2(t-c,e-s),d=Math.atan2(r-c,n-s),f=Math.atan2(a-c,i-s),p=d-u;p<0&&(p+=2*Math.PI);let m=f-u;m<0&&(m+=2*Math.PI);let h=p<m,g=b(s,c,l,h);if(!h){let e=-u,t=-f;return t<e-1e-9&&(t+=2*Math.PI),{__bk2d:`trimmed`,basis:g,tStart:e,tEnd:t}}let _=f;return _<u-1e-9&&(_+=2*Math.PI),{__bk2d:`trimmed`,basis:g,tStart:u,tEnd:_}}function Xg(e,t,n,r,i,a){let o=Math.sqrt(n*n+r*r),s=o>0?n/o:0,c=o>0?r/o:0,l=e-i,u=t-a,d=2*(u*s-l*c);if(Math.abs(d)<1e-12)return y(e,t,i,a);let f=-(l*l+u*u)/d,p=e-f*c,m=t+f*s,h=Math.abs(f),g=Math.atan2(t-m,e-p),_=Math.atan2(a-m,i-p),v=-(t-m)/h,b=(e-p)/h,x=s*v+c*b,S;if(x>0){let e=_-g;e<=0&&(e+=2*Math.PI),S=g+e/2}else{let e=_-g;e>=0&&(e-=2*Math.PI),S=g+e/2}return Yg(e,t,p+h*Math.cos(S),m+h*Math.sin(S),i,a)}function Zg(e,t,n,r,i,a,o){return x(e,t,n,r,i,a,o)}function Qg(e,t,n,r,i,a,o,s,c){return{__bk2d:`trimmed`,basis:x(e,t,n,r,o,s,c),tStart:i,tEnd:a}}function $g(e){return S(e)}function e_(e,t){let n=e.length,r=Math.min(3,n-1),i=[],a=[];i.push(0),a.push(r+1);let o=n-r-1;for(let e=1;e<=o;e++)i.push(e/(o+1)),a.push(1);return i.push(1),a.push(r+1),{__bk2d:`bspline`,poles:[...e],knots:i,multiplicities:a,degree:r,isPeriodic:!1}}function t_(e,t){return h(Mf(e),t)}function n_(e,t){return{point:h(Mf(e),t),tangent:g(Mf(e),t)}}function r_(e){return _(Mf(e))}function i_(e){return v(Nf(e))}function a_(e,t,n){return{__bk2d:`trimmed`,basis:Mf(e),tStart:t,tEnd:n}}function o_(e){return JSON.parse(JSON.stringify(e))}function s_(e,t){let n=Mf(e),r=_(n),i=[];for(let e=0;e<=30;e++){let a=r.first+(r.last-r.first)*e/30,[o,s]=h(n,a),[c,l]=g(n,a),u=Math.sqrt(c*c+l*l);u>1e-12?i.push([o-l/u*t,s+c/u*t]):i.push([o,s])}return e_(i)}function c_(e,t,n){return C(Mf(e),t,n)}function l_(e,t,n,r){return w(Mf(e),t,n,r)}function u_(e,t,n,r){return ee(Mf(e),t,n,r)}function d_(e,t,n){return te(Mf(e),t,n)}function f_(e,t,n,r,i){return ne(Mf(e),t,n,r,i)}function p_(e,t,n,r,i,a){return C_(e,g_(t,n,r,i,a))}function m_(e,t,n){return{m:e,tx:t,ty:n,delete:of}}function h_(){return m_([1,0,0,0,1,0,0,0,1],0,0)}function g_(e,n,r,i,a){let o=Math.sqrt(r*r+i*i);if(o<1e-15)return h_();let s=-i/o,c=r/o,l=a-1,u=[1+l*s*s,l*s*c,0,l*c*s,1+l*c*c,0,0,0,1];return m_(u,e-t(u,0)*e-t(u,1)*n,n-t(u,3)*e-t(u,4)*n)}function __(e,t){return m_([1,0,0,0,1,0,0,0,1],e,t)}function v_(e,n,r,i,a,o,s){if(r===`axis`&&o!==void 0&&s!==void 0){let r=Math.sqrt(o*o+s*s),c=o/r,l=s/r,u=[2*c*c-1,2*c*l,0,2*c*l,2*l*l-1,0,0,0,1],d=i??e,f=a??n;return m_(u,d-t(u,0)*d-t(u,1)*f,f-t(u,3)*d-t(u,4)*f)}return m_([-1,0,0,0,-1,0,0,0,1],2*e,2*n)}function y_(e,t,n){let r=Math.cos(e),i=Math.sin(e);return m_([r,-i,0,i,r,0,0,0,1],t-r*t+i*n,n-i*t-r*n)}function b_(e,t,n){return m_([e,0,0,0,e,0,0,0,1],t*(1-e),n*(1-e))}function x_(e,t,n){e.tx=t,e.ty=n}function S_(e,n){let r=e.m,i=n.m,a=e=>t(r,e),o=e=>t(i,e);e.m=[a(0)*o(0)+a(1)*o(3)+a(2)*o(6),a(0)*o(1)+a(1)*o(4)+a(2)*o(7),a(0)*o(2)+a(1)*o(5)+a(2)*o(8),a(3)*o(0)+a(4)*o(3)+a(5)*o(6),a(3)*o(1)+a(4)*o(4)+a(5)*o(7),a(3)*o(2)+a(4)*o(5)+a(5)*o(8),a(6)*o(0)+a(7)*o(3)+a(8)*o(6),a(6)*o(1)+a(7)*o(4)+a(8)*o(7),a(6)*o(2)+a(7)*o(5)+a(8)*o(8)];let s=e.tx,c=e.ty,l=Number(n.tx)||0,u=Number(n.ty)||0;e.tx=a(0)*l+a(1)*u+s,e.ty=a(3)*l+a(4)*u+c}function C_(e,n){let r=Mf(e),i=n.m??[1,0,0,0,1,0,0,0,1],a=Number(n.tx)||0,o=Number(n.ty)||0,s=t(i,0),c=t(i,1),l=t(i,3),u=t(i,4);if(Math.abs(s-1)<1e-12&&Math.abs(u-1)<1e-12&&Math.abs(c)<1e-12&&Math.abs(l)<1e-12)return C(r,a,o);let d=_(r),f=[];for(let e=0;e<=20;e++){let[t,n]=h(r,d.first+(d.last-d.first)*e/20);f.push([s*t+c*n+a,l*t+u*n+o])}return S(f)}function w_(e,t,n){let r=re(Mf(e),Mf(t),n),i=r.segments.map(e=>Object.assign(e,{delete(){}}));return{points:r.points,segments:i}}function T_(e,t,n){let r=Mf(e),i=_(r);if(r.__bk2d===`line`){let e=t-r.ox,a=n-r.oy,o=Math.max(i.first,Math.min(i.last,e*r.dx+a*r.dy)),[s,c]=h(r,o);return{param:o,distance:Math.sqrt((s-t)**2+(c-n)**2)}}if(r.__bk2d===`circle`){let e=Math.atan2(n-r.cy,t-r.cx),i=r.sense?e:-e;for(;i<0;)i+=2*Math.PI;for(;i>2*Math.PI;)i-=2*Math.PI;let[a,o]=h(r,i);return{param:i,distance:Math.sqrt((a-t)**2+(o-n)**2)}}if(!isFinite(i.first)||!isFinite(i.last))return null;let a=i.first,o=1/0,s=(i.last-i.first)/200;for(let e=0;e<=200;e++){let c=i.first+e*s,[l,u]=h(r,c),d=(l-t)**2+(u-n)**2;d<o&&(o=d,a=c)}for(let e=0;e<10;e++){let[e,o]=h(r,a),[s,c]=g(r,a),l=(e-t)*s+(o-n)*c,u=s*s+c*c;if(u<1e-20)break;let d=l/u,f=Math.max(i.first,Math.min(i.last,a-d));if(Math.abs(f-a)<1e-14)break;a=f}let[c,l]=h(r,a);return{param:a,distance:Math.sqrt((c-t)**2+(l-n)**2)}}function E_(e,t,n,r,i,a){let o=Mf(e),s=Mf(t),c=n,l=i,u=1/0;for(let e=0;e<=50;e++){let t=n+(r-n)*e/50,[d,f]=h(o,t);for(let e=0;e<=50;e++){let n=i+(a-i)*e/50,[r,o]=h(s,n),p=(r-d)**2+(o-f)**2;p<u&&(u=p,c=t,l=n)}}let d=c,f=l;for(let c=0;c<20;c++){let[c,l]=h(s,f),u=T_(e,c,l);if(u){let e=Math.max(n,Math.min(r,u.param)),t=Math.abs(e-d)<1e-12;if(d=e,t)break}let[p,m]=h(o,d),g=T_(t,p,m);if(g){let e=Math.max(i,Math.min(a,g.param)),t=Math.abs(e-f)<1e-12;if(f=e,t)break}}let[p,m]=h(o,d),[g,_]=h(s,f);return Math.sqrt((g-p)**2+(_-m)**2)}function D_(e,n,r,i){let a=Mf(e),o=_(a),s=Math.max(3,{C0:1,C1:2,C2:3,C3:4}[r]??4),c=Math.max(100,i*10),l=[],u=1/0;for(let e=0;e<3&&u>n;e++){l=[];for(let e=0;e<=c;e++){let t=o.first+(o.last-o.first)*e/c;l.push(h(a,t))}u=0;for(let e=0;e<c;e++){let[n,r]=h(a,o.first+(o.last-o.first)*(e+.5)/c),i=t(l,e),s=t(l,e+1),d=(i[0]+s[0])/2,f=(i[1]+s[1])/2,p=Math.sqrt((n-d)**2+(r-f)**2);p>u&&(u=p)}u>n&&(c=Math.min(c*2,500))}return e_(l,{degMax:s})}function O_(e){let n=Nf(e);if(n.__bk2d===`bezier`)return[e];if(n.__bk2d!==`bspline`)return O_(D_(e,1e-6,`C2`,10));let r=_(Mf(e)),i=r.first,a=r.last,o=[];for(let e of n.knots)e>i+1e-12&&e<a-1e-12&&o.push(e);let s=[i,...o,a],c=[];for(let e=0;e<s.length-1;e++){let r=t(s,e),i=t(s,e+1),a=i-r;if(a<1e-15)continue;let o=h(n,r),l=h(n,i),u=g(n,r),d=g(n,i),f=a/3,p={__bk2d:`bezier`,poles:[o,[o[0]+u[0]*f,o[1]+u[1]*f],[l[0]-d[0]*f,l[1]-d[1]*f],l]};c.push(p)}return c.length>0?c:[e]}function k_(){return me()}function A_(e,t,n){he(Pf(e),Mf(t),n)}function j_(e){let t=Pf(e);return{xMin:t.xMin,yMin:t.yMin,xMax:t.xMax,yMax:t.yMax}}function M_(e,t){let n=Pf(e),r=Pf(t);n.xMin=Math.min(n.xMin,r.xMin),n.yMin=Math.min(n.yMin,r.yMin),n.xMax=Math.max(n.xMax,r.xMax),n.yMax=Math.max(n.yMax,r.yMax)}function N_(e,t){let n=Pf(e),r=Pf(t);return n.xMax<r.xMin||r.xMax<n.xMin||n.yMax<r.yMin||r.yMax<n.yMin}function P_(e,t,n){let r=Pf(e);return t<r.xMin||t>r.xMax||n<r.yMin||n>r.yMax}function F_(e){let t=Nf(e);return t.__bk2d===`circle`?{cx:t.cx,cy:t.cy,radius:t.radius,isDirect:t.sense}:null}function I_(e){let t=Nf(e);return t.__bk2d===`ellipse`?{majorRadius:t.majorRadius,minorRadius:t.minorRadius,xAxisAngle:t.xDirAngle,isDirect:t.sense}:null}function L_(e){let t=Nf(e);return t.__bk2d===`bezier`?[...t.poles]:null}function R_(e){let t=Nf(e);return t.__bk2d===`bezier`?t.poles.length-1:null}function z_(e){let t=Nf(e);return t.__bk2d===`bspline`?{poles:[...t.poles],knots:[...t.knots],multiplicities:[...t.multiplicities],degree:t.degree,isPeriodic:t.isPeriodic}:null}function B_(e){return fe(Mf(e))}function V_(e){return pe(e)}function H_(e,t){let n=Mf(e),r=_(n),i=[r.first,...[...t].sort((e,t)=>e-t),r.last],a=[];for(let e=0;e<i.length-1;e++)a.push({__bk2d:`trimmed`,basis:n,tStart:i[e],tEnd:i[e+1]});return a}function U_(e,n,r,i,a){let o=Mf(n),s=[i[1]*a[2]-i[2]*a[1],i[2]*a[0]-i[0]*a[2],i[0]*a[1]-i[1]*a[0]],c=(e,t)=>[r[0]+e*a[0]+t*s[0],r[1]+e*a[1]+t*s[1],r[2]+e*a[2]+t*s[2]];if(o.__bk2d===`line`)return Um(e,c(o.ox,o.oy),c(o.ox+o.dx*o.len,o.oy+o.dy*o.len));if(o.__bk2d===`circle`||o.__bk2d===`trimmed`){let n=o;for(;n.__bk2d===`trimmed`;)n=n.basis;if(n.__bk2d===`circle`){let r=n,a=c(r.cx,r.cy),s=r.sense?i:[-i[0],-i[1],-i[2]],l=_(o),u;u=o.__bk2d===`trimmed`?Math.abs(o.tEnd-o.tStart):2*Math.PI;let d=u>Math.PI?4:u>Math.PI/2?2:1,f=(l.last-l.first)/d,p=[];for(let t=0;t<d;t++){let[n,r]=h(o,l.first+t*f),[i,u]=h(o,l.first+(t+1)*f);p.push(e.makeCircleArc3d(...c(n,r),...c(i,u),...a,...s))}return p.length===1?uf(t(p,0)):df(e.makeWire(p,!1))}}if(o.__bk2d===`bezier`||o.__bk2d===`bspline`){let n=o.poles.map(([e,t])=>c(e,t));if(n.length===2)return Um(e,t(n,0),t(n,1));let r=Math.min(3,n.length-1),i=n.flatMap(([e,t,n])=>[e,t,n]);return uf(e.interpolatePoints(i,r))}let l=_(o),u=[];for(let e=0;e<=100;e++){let[t,n]=h(o,l.first+(l.last-l.first)*e/100);u.push(c(t,n))}return dh(e,u)}function W_(e,t,r){if(!sf(r))throw Error(`brepkit: buildEdgeOnSurface requires a face handle as surface`);let i=L(r,`face`),a=Mf(t),o=_(a),s=e.getSurfaceType(i)===`plane`?50:100,c=[];for(let t=0;t<=s;t++){let[r,l]=h(a,o.first+(o.last-o.first)*t/s);c.push(n(e.evaluateSurface(i,r,l)))}return dh(e,c)}function G_(e){return e}function K_(e,n,r,i){let a=0;for(;e.length<r;){let o=[];for(let r=0;r<e.length-1;r++){let a=t(e,r),s=t(e,r+1),c=(a.t+s.t)/2,l=n(c),u=(a.uv[0]+s.uv[0])/2,d=(a.uv[1]+s.uv[1])/2;Math.sqrt((l[0]-u)**2+(l[1]-d)**2)>i&&o.push({index:r+1,t:c,uv:l})}if(o.length===0)break;let s=r-e.length;for(let n=o.length-1;n>=0&&s>0;n--){let r=t(o,n);e.splice(r.index,0,{t:r.t,uv:r.uv}),s--}if(a++,a>3)break}}function q_(e,n,r){let i=L(n,`edge`),a=L(r,`face`),o=e.getEdgeCurveParameters(i),s=o[0]??0,c=o[1]??1,l=[];for(let e=0;e<=20;e++)l.push(s+(c-s)*e/20);let u=n=>{let r=e.evaluateEdgeCurve(i,n),o=e.projectPointOnSurface(a,t(r,0),t(r,1),t(r,2));return[t(o,0),t(o,1)]},d=l.map(e=>({t:e,uv:u(e)}));K_(d,u,80,.05);let f=d.map(e=>e.uv);if(f.length>=2)return e_(f);let p=e.getEdgeVertices(i);if(p.length>=6){let n=e.projectPointOnSurface(a,t(p,0),t(p,1),t(p,2)),r=e.projectPointOnSurface(a,t(p,3),t(p,4),t(p,5));return y(t(n,0),t(n,1),t(r,0),t(r,1))}throw Error(`brepkit: extractCurve2dFromEdge: degenerate edge (${p.length} coords)`)}function J_(e,t,n){return e}function Y_(e,n,r){if(n.length>=1){let r=Wf(e,n[0],`edge`);if(r.length===4){let n=[],i=[];for(let a of r){let r=L(a,`edge`),o=e.getEdgeCurveParameters(r),s=t(o,0),c=t(o,1),l=[];for(let n=0;n<=10;n++){let i=s+(c-s)*n/10,a=e.evaluateEdgeCurve(r,i);l.push(t(a,0),t(a,1),t(a,2))}n.push(...l),i.push(11)}try{return lf(e.fillCoonsPatch(n,i))}catch(e){console.warn(`brepkit: Coons patch failed, falling back:`,e)}}}let i=n[0];if(!i)throw Error(`fillSurface: no wires provided`);return rh(e,i)}function X_(e){return{createPoint2d:(e,t)=>Vg(e,t),createDirection2d:(e,t)=>Hg(e,t),createVector2d:(e,t)=>Ug(e,t),createAxis2d:(e,t,n,r)=>Wg(e,t,n,r),wrapCurve2dHandle:e=>Gg(e),createCurve2dAdaptor:e=>Kg(e),makeLine2d:(e,t,n,r)=>qg(e,t,n,r),makeCircle2d:(e,t,n,r)=>Jg(e,t,n,r),makeArc2dThreePoints:(e,t,n,r,i,a)=>Yg(e,t,n,r,i,a),makeArc2dTangent:(e,t,n,r,i,a)=>Xg(e,t,n,r,i,a),makeEllipse2d:(e,t,n,r,i,a,o)=>Zg(e,t,n,r,i,a,o),makeEllipseArc2d:(e,t,n,r,i,a,o,s,c)=>Qg(e,t,n,r,i,a,o,s,c),makeBezier2d:e=>$g(e),makeBSpline2d:(e,t)=>e_(e,t),evaluateCurve2d:(e,t)=>t_(e,t),evaluateCurve2dD1:(e,t)=>n_(e,t),getCurve2dBounds:e=>r_(e),getCurve2dType:e=>i_(e),trimCurve2d:(e,t,n)=>a_(e,t,n),reverseCurve2d:e=>{},copyCurve2d:e=>o_(e),offsetCurve2d:(e,t)=>s_(e,t),translateCurve2d:(e,t,n)=>c_(e,t,n),rotateCurve2d:(e,t,n,r)=>l_(e,t,n,r),scaleCurve2d:(e,t,n,r)=>u_(e,t,n,r),mirrorCurve2dAtPoint:(e,t,n)=>d_(e,t,n),mirrorCurve2dAcrossAxis:(e,t,n,r,i)=>f_(e,t,n,r,i),affinityTransform2d:(e,t,n,r,i,a)=>p_(e,t,n,r,i,a),createIdentityGTrsf2d:()=>h_(),createAffinityGTrsf2d:(e,t,n,r,i)=>g_(e,t,n,r,i),createTranslationGTrsf2d:(e,t)=>__(e,t),createMirrorGTrsf2d:(e,t,n,r,i,a,o)=>v_(e,t,n,r,i,a,o),createRotationGTrsf2d:(e,t,n)=>y_(e,t,n),createScaleGTrsf2d:(e,t,n)=>b_(e,t,n),setGTrsf2dTranslationPart:(e,t,n)=>{x_(e,t,n)},multiplyGTrsf2d:(e,t)=>{S_(e,t)},transformCurve2dGeneral:(e,t)=>C_(e,t),intersectCurves2d:(e,t,n)=>w_(e,t,n),projectPointOnCurve2d:(e,t,n)=>T_(e,t,n),distanceBetweenCurves2d:(e,t,n,r,i,a)=>E_(e,t,n,r,i,a),approximateCurve2dAsBSpline:(e,t,n,r)=>D_(e,t,n,r),decomposeBSpline2dToBeziers:e=>O_(e),createBoundingBox2d:()=>k_(),addCurveToBBox2d:(e,t,n)=>{A_(e,t,n)},getBBox2dBounds:e=>j_(e),mergeBBox2d:(e,t)=>{M_(e,t)},isBBox2dOut:(e,t)=>N_(e,t),isBBox2dOutPoint:(e,t,n)=>P_(e,t,n),getCurve2dCircleData:e=>F_(e),getCurve2dEllipseData:e=>I_(e),getCurve2dBezierPoles:e=>L_(e),getCurve2dBezierDegree:e=>R_(e),getCurve2dBSplineData:e=>z_(e),serializeCurve2d:e=>B_(e),deserializeCurve2d:e=>V_(e),splitCurve2d:(e,t)=>H_(e,t),liftCurve2dToPlane:(t,n,r,i)=>U_(e,t,n,r,i),buildEdgeOnSurface:(t,n)=>W_(e,t,n),extractSurfaceFromFace:e=>G_(e),extractCurve2dFromEdge:(t,n)=>q_(e,t,n),buildCurves3d:e=>{},fixWireOnFace:(e,t,n)=>J_(e,t,n),fillSurface:(t,n)=>Y_(e,t,n)}}function Z_(e,t){let n=t;if(n.type===`solid`)return e.volume(L(t),Tf);if(n.type===`compound`){let n=Wf(e,t,`solid`),r=0;for(let t of n)r+=e.volume(L(t),Tf);return r}return 0}function Q_(e,t){let n=t;if(n.type===`face`)return e.faceArea(L(t),Tf);if(n.type===`solid`)return e.surfaceArea(L(t),Tf);if(n.type===`compound`){let n=Wf(e,t,`face`),r=0;for(let t of n)r+=e.faceArea(L(t),Tf);return r}return 0}function $_(e,t){let n=t;if(n.type===`edge`)return e.edgeLength(L(t));if(n.type===`face`)return e.facePerimeter(L(t));if(n.type===`wire`)return e.wireLength(n.id);throw Error(`brepkit: length() requires an edge, wire, or face`)}function ev(e,n){let r=e.getEdgeVertices(n);return[(t(r,0)+t(r,3))/2,(t(r,1)+t(r,4))/2,(t(r,2)+t(r,5))/2]}function tv(e,t){let r=t;if(r.type===`solid`)return n(e.centerOfMass(L(t),Tf));if(r.type===`face`){let n=sp(e,t);return up(e,t,(n.uMin+n.uMax)/2,(n.vMin+n.vMax)/2)}if(r.type===`edge`)return ev(e,r.id);if(r.type===`vertex`)return ap(e,t);let i=Wf(e,t,`vertex`);if(i.length>0){let t=0,n=0,r=0;for(let a of i){let i=ap(e,a);t+=i[0],n+=i[1],r+=i[2]}return[t/i.length,n/i.length,r/i.length]}return[0,0,0]}function nv(e,t){let n=t;return n.type===`edge`?ev(e,n.id):tv(e,t)}function rv(e,t){let r=t;if(r.type===`solid`){let r=e.boundingBox(L(t));return{min:n(r,0),max:n(r,3)}}if(r.type===`vertex`){let n=ap(e,t);return{min:[...n],max:[...n]}}let i=Wf(e,t,`vertex`);if(i.length===0)return{min:[0,0,0],max:[0,0,0]};let a=ap(e,i[0]),o=a[0],s=a[1],c=a[2],l=a[0],u=a[1],d=a[2];for(let t=1;t<i.length;t++){let n=ap(e,i[t]);n[0]<o&&(o=n[0]),n[0]>l&&(l=n[0]),n[1]<s&&(s=n[1]),n[1]>u&&(u=n[1]),n[2]<c&&(c=n[2]),n[2]>d&&(d=n[2])}return{min:[o,s,c],max:[l,u,d]}}function iv(e,r,i){let a=r,o=i;if(a.type===`solid`&&o.type===`solid`){let r=e.solidToSolidDistance(a.id,o.id);return{value:t(r,0),point1:n(r,1),point2:n(r,4)}}if(a.type===`vertex`&&(o.type===`solid`||o.type===`face`||o.type===`edge`)){let r=n(e.getVertexPosition(a.id)),i=o.type===`solid`?e.pointToSolidDistance(r[0],r[1],r[2],o.id):o.type===`face`?e.pointToFaceDistance(r[0],r[1],r[2],o.id):e.pointToEdgeDistance(r[0],r[1],r[2],o.id);return{value:t(i,0),point1:r,point2:n(i,1)}}let s=r=>{if(r.type===`vertex`)return n(e.getVertexPosition(r.id));if(r.type===`solid`){let n=e.boundingBox(r.id);return[(t(n,0)+t(n,3))/2,(t(n,1)+t(n,4))/2,(t(n,2)+t(n,5))/2]}return[0,0,0]},c=s(a),l=s(o),u=l[0]-c[0],d=l[1]-c[1],f=l[2]-c[2];return{value:Math.sqrt(u*u+d*d+f*f),point1:c,point2:l}}function av(e,r,i,a){let o=L(r,`face`),s=e.measureCurvatureAtSurface(o,i,a);if(s.length<8)throw Error(`brepkit: measureCurvatureAtSurface returned ${s.length} values, expected 8`);let c=t(s,0),l=t(s,1);return{gaussian:c*l,mean:(c+l)/2,max:Math.max(c,l),min:Math.min(c,l),maxDirection:n(s,2),minDirection:n(s,5)}}function ov(e,n){let r=e.tessellateFace(L(n,`face`),.1),i=r.positions,a=r.indices,o=0,s=0,c=0,l=0;for(let e=0;e<a.length;e+=3){let n=t(a,e)*3,r=t(a,e+1)*3,u=t(a,e+2)*3,d=t(i,n),f=t(i,n+1),p=t(i,n+2),m=t(i,r),h=t(i,r+1),g=t(i,r+2),_=t(i,u),v=t(i,u+1),y=t(i,u+2),b=(d+m+_)/3,x=(f+h+v)/3,S=(p+g+y)/3,C=m-d,w=h-f,ee=g-p,te=_-d,ne=v-f,re=y-p,ie=.5*Math.sqrt((w*re-ee*ne)**2+(ee*te-C*re)**2+(C*ne-w*te)**2);o+=b*ie,s+=x*ie,c+=S*ie,l+=ie}return l<1e-30?[0,0,0]:[o/l,s/l,c/l]}function sv(e,t){let n=n=>iv(e,t,n);return{distanceTo(e){return n(e)},dispose(){}}}function cv(e,t,n=!1){let r=t,i=r.type===`edge`||r.type===`wire`||r.type===`face`;return{volume:Z_(e,t),area:Q_(e,t),length:n&&i?$_(e,t):0,centerOfMass:tv(e,t),boundingBox:rv(e,t)}}function lv(e){return{volume:t=>Z_(e,t),area:t=>Q_(e,t),length:t=>$_(e,t),centerOfMass:t=>tv(e,t),linearCenterOfMass:t=>nv(e,t),boundingBox:t=>rv(e,t),distance:(t,n)=>iv(e,t,n),surfaceCurvature:(t,n,r)=>av(e,t,n,r),surfaceCenterOfMass:t=>ov(e,t),createDistanceQuery:t=>sv(e,t),measureBulk:(t,n)=>cv(e,t,n)}}function uv(e,t,n){let r=L(t),i=t,a=n.tolerance||.01,o=n.angularTolerance>0?n.angularTolerance:void 0,s;if(i.type===`solid`)s=pv(e,r,a,!!n.includeUVs,o);else if(i.type===`face`)s=gv(e,r,a,0,o);else throw Error(`brepkit: cannot mesh shape of type '${i.type}'`);return n.skipNormals&&(s.normals=new Float32Array),n.includeUVs||(s.uvs=new Float32Array),s}function dv(e,n,r,i){i>0&&Af(`mesh-edges-angular`,`meshEdges angularTolerance is not supported; only linear deflection is used.`);let a=n;if(a.type!==`solid`)return{lines:new Float32Array,edgeGroups:[]};let o=e.meshEdgesAll(a.id,r),s=o.positions,c=o.offsets,l=o.edgeCount,u=[];for(let e=0;e<l;e++){let n=t(c,e),r=((e+1<l?t(c,e+1):s.length)-n)/3;u.push({start:n/3,count:r,edgeHash:e})}return{lines:new Float32Array(s),edgeGroups:u}}function fv(e,t){return!1}function pv(e,t,n,r,i){try{return mv(e,t,n,r,i)}catch(r){return console.warn(`brepkit: tessellateSolidGrouped failed (solidId=${t}), falling back to per-face:`,r),hv(e,t,n,i)}}function mv(e,n,r,i,a){let o=e.tessellateSolidGrouped(n,r,a),s=JSON.parse(o),c=R(e.getSolidFaces(n)),l=s.faceOffsets.length-1;if(l!==c.length)throw Error(`faceOffsets/faceIds length mismatch: ${l} groups vs ${c.length} faces`);let u=[];for(let e=0;e<s.faceOffsets.length-1;e++){let n=t(s.faceOffsets,e),r=t(s.faceOffsets,e+1)-n;r!==0&&u.push({start:n,count:r,faceHash:c[e]??0})}let d=new Float32Array;if(i){let t=s.positions.length/3*2;try{let i=e.tessellateSolidUV(n,r,a),o=JSON.parse(i);d=o.uvs.length===t?new Float32Array(o.uvs):new Float32Array(t)}catch{d=new Float32Array(t)}}return{vertices:new Float32Array(s.positions),normals:new Float32Array(s.normals),triangles:new Uint32Array(s.indices),uvs:d,faceGroups:u}}function hv(e,t,n,r){let i=R(e.getSolidFaces(t)),a=[],o=[],s=[],c=[],l=[],u=0;for(let t of i)try{let i=e.tessellateFace(t,n,r),d=i.positions,f=i.normals,p=i.indices,m=d.length/3;if(m===0)continue;let h=s.length;for(let e of d)a.push(e);for(let e of f)o.push(e);for(let e of p)s.push(e+u);for(let e=0;e<m;e++)c.push(0,0);l.push({start:h,count:p.length,faceHash:t}),u+=m}catch(e){console.warn(`brepkit: face tessellation failed (faceId=${t}):`,e)}return{vertices:new Float32Array(a),normals:new Float32Array(o),triangles:new Uint32Array(s),uvs:new Float32Array(c),faceGroups:l}}function gv(e,t,n,r,i){let a=e.tessellateFace(t,n,i),o=a.positions,s=a.normals,c=a.indices,l=o.length/3,u=[];for(let e=0;e<l;e++)u.push(0,0);return{vertices:new Float32Array(o),normals:new Float32Array(s),triangles:new Uint32Array(c),uvs:new Float32Array(u),faceGroups:[{start:0,count:c.length,faceHash:r}]}}function _v(e){return{mesh:(t,n)=>uv(e,t,n),meshEdges:(t,n,r)=>dv(e,t,n,r),hasTriangulation:t=>fv(e,t),meshShape:(e,t,n)=>{}}}function vv(e){return e.sketchNew()}function yv(e,t,n,r,i){return e.sketchAddPoint(t,n,r,i)}function bv(e,t,n){e.sketchAddConstraint(t,n)}function xv(e,t,n,r){return e.sketchSolve(t,n,r)}function Sv(e,t,n,r,i){return e.sketchAddArc(t,n,r,i)}function Cv(e,t){let n=e.sketchDof(t);return typeof n==`string`?n:String(n)}function wv(e){return{sketchNew:()=>vv(e),sketchAddPoint:(t,n,r,i)=>yv(e,t,n,r,i),sketchAddArc:(t,n,r,i)=>Sv(e,t,n,r,i),sketchAddConstraint:(t,n)=>{bv(e,t,n)},sketchSolve:(t,n,r)=>xv(e,t,n,r),sketchDof:t=>Cv(e,t)}}function Tv(e,t,n,r){return I(e.extrude(L(t,`face`),n[0],n[1],n[2],r))}function Ev(e,t,n,r){if(n&&typeof n==`object`&&`origin`in n&&`direction`in n){let{origin:i,direction:a}=n,o=180/Math.PI*r;return o>360&&(o=360),I(e.revolve(L(t,`face`),i[0],i[1],i[2],a[0],a[1],a[2],o))}throw Error(`brepkit: revolve requires axis with origin and direction`)}function Dv(e,t,n,r,i){let a=180/Math.PI*i;return a>360&&(a=360),I(e.revolve(L(t,`face`),n[0],n[1],n[2],r[0],r[1],r[2],a))}function Ov(e,t,n,r,i){(n!==void 0||r!==void 0||i!==void 0)&&Af(`loft-options`,`Loft options (ruled, startShape, endShape) not supported; ignored.`);let a=t.map(t=>{let n=t;return n.type===`wire`?e.makeFaceFromWire(n.id):L(t,`face`)});return I(e.loft(a))}function kv(e){switch(e){case 0:return`rmf`;case 1:return`rightCorner`;case 2:return`roundCorner`;default:return}}function Av(e,t,n,r){let i=r?.transitionMode===void 0?void 0:kv(r.transitionMode),a=t,o=a.type===`wire`?e.makeFaceFromWire(a.id):L(t,`face`);if(n.type===`wire`){let t=Wf(e,n,`edge`).map(e=>L(e,`edge`));if(i&&t.length===1){let n=t[0];if(n!==void 0)return I(e.sweepWithOptions(o,n,i,[],0,`transformed`))}return i&&t.length>1&&Af(`sweep-transition-multi-edge`,`Sweep transition mode not supported for multi-edge wires; ignored.`),I(e.sweepAlongEdges(o,t))}if(i){let t=L(n,`edge`);return I(e.sweepWithOptions(o,t,i,[],0,`transformed`))}let s=rm(e,n);if(!s)throw Error(`brepkit: sweep spine must be an edge or wire`);return I(e.sweep(o,s.degree,s.knots,s.controlPoints,s.weights))}function jv(e,t,n){let r=t,i=r.type===`wire`?e.makeFaceFromWire(r.id):L(t,`face`);if(n.type===`wire`){let t=Wf(e,n,`edge`).map(e=>L(e,`edge`));return I(e.sweepAlongEdges(i,t))}let a=rm(e,n);if(!a)throw Error(`brepkit: pipe spine must be an edge or wire`);return I(e.pipe(i,a.degree,a.knots,a.controlPoints,a.weights))}function Mv(e,t,n,r,i,a,o){let s=L(t,`face`);return I(e.helicalSweep(s,n[0],n[1],n[2],r[0],r[1],r[2],i,a,o))}function Nv(e,t,n,r,i,a){let o=L(t,`face`),s=L(n,`edge`);return I(e.sweepWithOptions(o,s,r,i,a,`transformed`))}function Pv(e){switch(e){case`right`:return`rightCorner`;case`round`:return`roundCorner`;case`transformed`:return`rmf`;default:return}}function Fv(e,t,n){return n?{shape:e,firstShape:t,lastShape:t}:e}function Iv(e,t,n,r){try{return I(e.sweepWithOptions(t,n,r,[],0,`transformed`))}catch(e){console.warn(`brepkit: sweepWithOptions failed, falling back to sweepSmooth/simplePipe:`,e);return}}function Lv(e,t){try{if(t.type!==`wire`)return{edgeId:L(t,`edge`)};let n=Wf(e,t,`edge`);if(n.length===1){let e=n[0];return e?{edgeId:L(e,`edge`)}:void 0}Af(`sweepPipeShell-transition-multi-edge`,`sweepPipeShell transition mode not supported for multi-edge wires; ignored.`);return}catch(e){console.warn(`brepkit: resolveContactModeEdge failed for unexpected spine type, falling through:`,e);return}}function Rv(e,t,n,r){let i=Lv(e,n);if(i)return Iv(e,t,i.edgeId,r)}function zv(e,t,n){let r=rm(e,n);if(!(!r||r.degree<=1))try{return I(e.sweepSmooth(t,r.degree,r.knots,r.controlPoints,r.weights))}catch(e){console.warn(`brepkit: sweepSmooth failed, falling back to simplePipe:`,e);return}}function Bv(e,t,n,r){let i=t,a=i.type===`wire`?e.makeFaceFromWire(i.id):L(t,`face`),o=!!(r&&r.shellMode),s=r?.transitionMode,c=s?Pv(s):void 0;if(c){let r=Rv(e,a,n,c);if(r)return Fv(r,t,o)}return Fv(zv(e,a,n)||jv(e,t,n),t,o)}function Vv(e,t,n){let r=t.map(t=>{let n=t;return n.type===`wire`?e.makeFaceFromWire(n.id):L(t,`face`)});try{let t={};if(n?.ruled!==void 0&&(t.ruled=n.ruled),n?.solid!==void 0&&(t.solid=n.solid),n?.tolerance!==void 0&&(t.tolerance=n.tolerance),n?.startVertex){let r=e.getVertexPosition(L(n.startVertex,`vertex`));t.startPoint=[r[0],r[1],r[2]]}if(n?.endVertex){let r=e.getVertexPosition(L(n.endVertex,`vertex`));t.endPoint=[r[0],r[1],r[2]]}return I(e.loftWithOptions(r,JSON.stringify(t)))}catch(e){console.warn(`brepkit: loftWithOptions failed, falling back to smooth/basic loft:`,e)}if(!n?.ruled)try{return I(e.loftSmooth(r))}catch(e){console.warn(`brepkit: loftSmooth failed, falling back to basic loft:`,e)}return Ov(e,t)}function Hv(e,t,n,r){let i={type:`extrusionLaw`,profile:t,length:n,endFactor:r,Trim(e,t,n){return i},delete:of};return i}function Uv(e,t,n,r,i,a,o){if(i!==null){let r=Tv(e,n,lp(e,n,0,0),i);return o?ym(e,t,r):r}return t}function Wv(e){return{extrude:(t,n,r)=>Tv(e,t,n,r),revolve:(t,n,r)=>Ev(e,t,n,r),revolveVec:(t,n,r,i)=>Dv(e,t,n,r,i),loft:(t,n,r,i)=>Ov(e,t,n,r,i),sweep:(t,n,r)=>Av(e,t,n,r),simplePipe:(t,n)=>jv(e,t,n),helicalSweep:(t,n,r,i,a,o)=>Mv(e,t,n,r,i,a,o),sweepWithOptions:(t,n,r,i,a)=>Nv(e,t,n,r,i,a),sweepPipeShell:(t,n,r)=>Bv(e,t,n,r),loftAdvanced:(t,n)=>Vv(e,t,n),buildExtrusionLaw:(t,n,r)=>Hv(e,t,n,r),draftPrism:(t,n,r,i,a,o)=>Uv(e,t,n,r,i,a,o)}}function Gv(e){return{dispose:()=>{},executeBatch:t=>e.executeBatch(t),checkpoint:()=>e.checkpoint(),checkpointCount:()=>e.checkpointCount(),restoreCheckpoint:t=>{e.restore(t)},discardCheckpoint:t=>{e.discardCheckpoint(t)}}}var Kv=class{oc;kernelId=`brepkit`;bk;constructor(e){this.bk=e,this.oc=e;let t=this.bk;Object.assign(this,jm(t),xh(t),Wv(t),zh(t),Qp(t),_v(t),Bg(t),lv(t),ip(t),zp(t),hm(t),bg(t),wv(t),X_(t),Gv(t))}};function z(e){throw Error(`manifold: ${e} is not implemented`)}var qv=new Set(`makeBox.makeBoxWithCorners.makeCylinder.makeSphere.makeCone.makeTorus.makeEllipsoid.makeFuse.makeCut.makeCommon.translateShape.rotateShape.scaleShape.mirrorShape.transformShape.generalTransform.generalTransformNonOrthogonal.gridPattern.extrude.revolve.revolveVec.loft.loftAdvanced.sweep.simplePipe.sweepWithOptions.sweepPipeShell.helicalSweep.draftPrism.fillet.chamfer.chamferDistAngle.shell.thicken.offset.filletVariable.draft.defeature.simplify.reverseShape.hull.hullFromPoints.sewAndSolidify`.split(`.`));function Jv(e){return qv.has(e)}function Yv(e,t,n){return{op:e,params:t,inputs:n,replayable:Jv(e)&&n.every(e=>e.replayable)}}function Xv(e,t){return{manifold:e,node:t}}function B(e){return e.manifold}function V(e){return e.node}function Zv(e){if(e&&typeof e==`object`&&`manifold`in e&&`node`in e)return e}function Qv(){try{return U(`occt`)}catch{return}}function $v(e){let t=Qv();if(!t)throw Error(`manifold: ${e} requires a registered occt kernel; none is available`);return t}var ey=new WeakMap,ty=[0,0,0],ny=[0,0,1];function ry(e){return Math.hypot(e[0],e[1],e[2])}function iy(e){let t=ry(e);return t===0?[...ny]:[e[0]/t,e[1]/t,e[2]/t]}function ay(e){let[t,n,r]=iy(e);return[0,180/Math.PI*Math.atan2(Math.hypot(t,n),r),180/Math.PI*Math.atan2(n,t)]}function oy(e){let t=e.Manifold;function n(e,t,n){let r=e;return n[0]===0&&n[1]===0&&n[2]>0||(r=r.rotate(ay(n))),(t[0]!==0||t[1]!==0||t[2]!==0)&&(r=r.translate(t)),r}return{makeBox:(e,n,r)=>Xv(t.cube([e,n,r],!1),Yv(`makeBox`,{width:e,height:n,depth:r},[])),makeBoxFromCorners:(e,n)=>{let r=[Math.abs(n[0]-e[0]),Math.abs(n[1]-e[1]),Math.abs(n[2]-e[2])],i=[Math.min(e[0],n[0]),Math.min(e[1],n[1]),Math.min(e[2],n[2])];return Xv(t.cube(r,!1).translate(i),Yv(`makeBoxWithCorners`,{p1:e,p2:n},[]))},makeCylinder:(e,r,i=ty,a=ny)=>Xv(n(t.cylinder(r,e,e,0,!1),i,a),Yv(`makeCylinder`,{radius:e,height:r,center:i,direction:a},[])),makeSphere:(e,n=ty)=>{let r=t.sphere(e,0);return(n[0]!==0||n[1]!==0||n[2]!==0)&&(r=r.translate(n)),Xv(r,Yv(`makeSphere`,{radius:e,center:n},[]))},makeCone:(e,r,i,a=ty,o=ny)=>Xv(n(t.cylinder(i,e,r,0,!1),a,o),Yv(`makeCone`,{radius1:e,radius2:r,height:i,center:a,direction:o},[])),makeTorus:(r,i,a=ty,o=ny)=>{let s=Math.max(3,e.getCircularSegments(i)),c=[];for(let e=0;e<s;e++){let t=e/s*Math.PI*2;c.push([r+i*Math.cos(t),i*Math.sin(t)])}return Xv(n(t.revolve([c],0),a,o),Yv(`makeTorus`,{majorRadius:r,minorRadius:i,center:a,direction:o},[]))},makeEllipsoid:(e,n,r)=>Xv(t.sphere(1,0).scale([e,n,r]),Yv(`makeEllipsoid`,{aLength:e,bLength:n,cLength:r},[])),makeRectangle:()=>z(`makeRectangle`)}}function sy(e){return e}function cy(e,t,n){switch(n){case`cut`:case`subtract`:case`difference`:return e.subtract(t);case`intersect`:case`common`:case`intersection`:return e.intersect(t);default:return e.add(t)}}function ly(e){let t=V(sy(e)).params,n=t.normal,r=t.origin;if(!n||!r)throw Error(`manifold: section/split plane must carry normal+origin params`);return{normal:n,offset:n[0]*r[0]+n[1]*r[1]+n[2]*r[2]}}function uy(e){let t=new Uint32Array(e.triVerts),n=e.vertProperties.length/3,r=new Float32Array(n*3);for(let t=0;t<n;t++)r[t*3]=e.vertProperties[t*3]??0,r[t*3+1]=e.vertProperties[t*3+1]??0,r[t*3+2]=e.vertProperties[t*3+2]??0;return{vertices:r,normals:new Float32Array,triangles:t,uvs:new Float32Array,faceGroups:[{start:0,count:t.length,faceHash:0}]}}function dy(e){let t=e.Manifold;function n(e,t,n){let r=sy(e),i=sy(t);return Xv(B(r).add(B(i)),Yv(`makeFuse`,{},[V(r),V(i)]))}function r(e,t,n){let r=sy(e),i=sy(t);return Xv(B(r).subtract(B(i)),Yv(`makeCut`,{},[V(r),V(i)]))}function i(e,t,n){let r=sy(e),i=sy(t);return Xv(B(r).intersect(B(i)),Yv(`makeCommon`,{},[V(r),V(i)]))}function a(e,n){if(e.length===0)throw Error(`manifold: fuseAll requires at least one shape`);let r=e.map(sy),[i]=r;if(i===void 0)throw Error(`manifold: fuseAll requires at least one shape`);return r.length===1?i:Xv(t.union(r.map(B)),Yv(`makeFuse`,{},r.map(V)))}function o(e,n,r){let i=sy(e);if(n.length===0)return i;let a=n.map(sy);return Xv(t.difference([B(i),...a.map(B)]),Yv(`makeCut`,{},[V(i),...a.map(V)]))}function s(e,t,n){let r=sy(e),{normal:i,offset:a}=ly(t),[o]=B(r).splitByPlane(i,a);return Xv(o,Yv(`section`,{normal:i,offset:a},[V(r),V(sy(t))]))}function c(e,n){let r=sy(e),[i]=n;if(i===void 0)throw Error(`manifold: split requires at least one tool`);let a=sy(i),{normal:o,offset:s}=ly(i),[c,l]=B(r).splitByPlane(o,s);return Xv(t.union([c,l]),Yv(`split`,{normal:o,offset:s},[V(r),V(a)]))}function l(e,t,n){let r=[],i=sy(e),a=sy(t);return(B(i)===void 0||B(i).isEmpty())&&r.push({operand:`base`,issue:`null-shape`,message:`Base shape is empty`}),(B(a)===void 0||B(a).isEmpty())&&r.push({operand:`tool`,issue:`null-shape`,message:`Tool shape is empty`}),{valid:r.length===0,issues:r}}function u(n,r,i,a,o,s){let c=new e.Mesh({numProp:3,vertProperties:new Float32Array(n),triVerts:new Uint32Array(r)}),l=new e.Mesh({numProp:3,vertProperties:new Float32Array(i),triVerts:new Uint32Array(a)});return uy(cy(t.ofMesh(c),t.ofMesh(l),o).getMesh())}return{fuse:n,cut:r,intersect:i,section:s,fuseAll:a,cutAll:o,split:c,checkBoolean:l,meshBoolean:u}}function fy(e){return e}function py(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function my(e){let t=Math.hypot(e[0],e[1],e[2]);return t<1e-12?[0,0,1]:[e[0]/t,e[1]/t,e[2]/t]}function hy(e,t,n){let r=py();return r[12]=e,r[13]=t,r[14]=n,r}function gy(e,t,n){let r=e*Math.PI/180,[i,a,o]=my(t),s=Math.cos(r),c=Math.sin(r),l=1-s,u=l*i*i+s,d=l*i*a+c*o,f=l*i*o-c*a,p=l*i*a-c*o,m=l*a*a+s,h=l*a*o+c*i,g=l*i*o+c*a,_=l*a*o-c*i,v=l*o*o+s,y=py();return y[0]=u,y[1]=d,y[2]=f,y[4]=p,y[5]=m,y[6]=h,y[8]=g,y[9]=_,y[10]=v,y[12]=n[0]-(u*n[0]+p*n[1]+g*n[2]),y[13]=n[1]-(d*n[0]+m*n[1]+_*n[2]),y[14]=n[2]-(f*n[0]+h*n[1]+v*n[2]),y}function _y(e,t){let n=py();return n[0]=t,n[5]=t,n[10]=t,n[12]=e[0]*(1-t),n[13]=e[1]*(1-t),n[14]=e[2]*(1-t),n}function vy(e,t){let[n,r,i]=my(t),a=1-2*n*n,o=1-2*r*r,s=1-2*i*i,c=-2*n*r,l=-2*n*i,u=-2*r*i,d=py();d[0]=a,d[1]=c,d[2]=l,d[4]=c,d[5]=o,d[6]=u,d[8]=l,d[9]=u,d[10]=s;let f=e[0]*n+e[1]*r+e[2]*i;return d[12]=2*f*n,d[13]=2*f*r,d[14]=2*f*i,d}function yy(e,t){let n=py();return n[0]=e[0],n[1]=e[3],n[2]=e[6],n[4]=e[1],n[5]=e[4],n[6]=e[7],n[8]=e[2],n[9]=e[5],n[10]=e[8],n[12]=t[0],n[13]=t[1],n[14]=t[2],n}function by(e,t,n,r,i){return Xv(e.transform(t),Yv(n,r,[i]))}function xy(e,t,n,r){let i=fy(e);return by(B(i),hy(t,n,r),`translateShape`,{x:t,y:n,z:r},V(i))}function Sy(e,t,n=[0,0,1],r=[0,0,0]){let i=fy(e);return by(B(i),gy(t,n,r),`rotateShape`,{angle:t,axis:n,center:r},V(i))}function Cy(e,t,n){let r=fy(e);return by(B(r),vy(t,n),`mirrorShape`,{origin:t,normal:n},V(r))}function wy(e,t,n){let r=fy(e);return by(B(r),_y(t,n),`scaleShape`,{center:t,factor:n},V(r))}function Ty(e,t){if(!Array.isArray(t)||t.length!==16)throw Error(`manifold: transform expects a 16-element column-major matrix`);let n=fy(e);return by(B(n),t,`transformShape`,{matrix:[...t]},V(n))}function Ey(e,t,n,r){let i=fy(e);return by(B(i),yy(t,n),`generalTransform`,{linear:t,translation:n,isOrthogonal:r},V(i))}function Dy(e,t,n){let r=fy(e);return by(B(r),yy(t,n),`generalTransformNonOrthogonal`,{linear:t,translation:n},V(r))}function Oy(e){let t=py();for(let n of e)t=Py(n.type===`translate`?hy(n.x,n.y,n.z):gy(n.angle,n.axis??[0,0,1],n.center??[0,0,0]),t);return{handle:t,dispose:()=>{}}}function ky(e,t,n,r){let i=[e];for(let a=1;a<r;a++){let r=n*a;i.push(xy(e,t[0]*r,t[1]*r,t[2]*r))}return i}function Ay(e,t,n,r,i){let a=[e];for(let o=1;o<i;o++)a.push(Sy(e,r*o,n,t));return a}function jy(e,t,n,r,i,a,o,s){let c=fy(t),l=[],u=[];for(let e=0;e<o;e++)for(let t=0;t<s;t++){let o=n[0]*i*e+r[0]*a*t,s=n[1]*i*e+r[1]*a*t,d=n[2]*i*e+r[2]*a*t;l.push(B(c).transform(hy(o,s,d))),u.push(V(c))}return Xv(l.length===1?l[0]:e.Manifold.union(l),Yv(`gridPattern`,{directionX:n,directionY:r,spacingX:i,spacingY:a,countX:o,countY:s},u))}function My(e){return e.map(e=>{switch(e.type){case`translate`:return xy(e.shape,e.x,e.y,e.z);case`rotate`:return Sy(e.shape,e.angle,e.axis,e.center);case`scale`:return wy(e.shape,e.center,e.factor);case`mirror`:return Cy(e.shape,e.origin,e.normal)}})}function Ny(e){return{composeTransform:Oy,transform:Ty,translate:xy,rotate:Sy,mirror:Cy,scale:wy,generalTransform:Ey,generalTransformNonOrthogonal:Dy,positionOnCurve:()=>z(`positionOnCurve`),linearPattern:ky,circularPattern:Ay,gridPattern:(t,n,r,i,a,o,s)=>jy(e,t,n,r,i,a,o,s),transformBatch:My}}function Py(e,t){let n=py();for(let r=0;r<4;r++)for(let i=0;i<4;i++){let a=0;for(let n=0;n<4;n++){let o=e[n*4+i]??0,s=t[r*4+n]??0;a+=o*s}n[r*4+i]=a}return n}function Fy(e){let t=e.Manifold;function n(e,n){let r=e.map(e=>[e.x,e.y,e.z]);return Xv(t.hull(r),Yv(`hullFromPoints`,{points:r,tolerance:n},[]))}function r(e,n){let r=e.map(e=>B(e));return Xv(t.hull(r),Yv(`hull`,{tolerance:n},e.map(e=>V(e))))}function i(e,t){let n=e[0];return n||z(`sewAndSolidify (no input faces on manifold kernel)`),Xv(B(n),Yv(`sewAndSolidify`,{tolerance:t},e.map(e=>V(e))))}return{makeVertex:()=>z(`makeVertex`),makeEdge:()=>z(`makeEdge`),makeWire:()=>z(`makeWire`),makeFace:()=>z(`makeFace`),makeLineEdge:()=>z(`makeLineEdge`),makeCircleEdge:()=>z(`makeCircleEdge`),makeCircleArc:()=>z(`makeCircleArc`),makeArcEdge:()=>z(`makeArcEdge`),makeEllipseEdge:()=>z(`makeEllipseEdge`),makeEllipseArc:()=>z(`makeEllipseArc`),makeBezierEdge:()=>z(`makeBezierEdge`),makeTangentArc:()=>z(`makeTangentArc`),makeHelixWire:()=>z(`makeHelixWire`),makeWireFromMixed:()=>z(`makeWireFromMixed`),makeCompound:()=>z(`makeCompound`),solidFromShell:()=>z(`solidFromShell`),hull:r,hullFromPoints:n,buildSolidFromFaces:()=>z(`buildSolidFromFaces`),makeNonPlanarFace:()=>z(`makeNonPlanarFace`),addHolesInFace:()=>z(`addHolesInFace`),removeHolesFromFace:()=>z(`removeHolesFromFace`),makeFaceOnSurface:()=>z(`makeFaceOnSurface`),bsplineSurface:(e,t,n)=>$v(`bsplineSurface`).bsplineSurface(e,t,n),triangulatedSurface:(e,t,n)=>$v(`triangulatedSurface`).triangulatedSurface(e,t,n),buildTriFace:()=>z(`buildTriFace`),sewAndSolidify:i,createPoint3d:()=>z(`createPoint3d`),createDirection3d:()=>z(`createDirection3d`),createVector3d:()=>z(`createVector3d`),createAxis1:()=>z(`createAxis1`),createAxis2:()=>z(`createAxis2`),createAxis3:()=>z(`createAxis3`)}}function Iy(e){return e}function Ly(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function Ry(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function zy(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function By(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function Vy(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function Hy(e){return Math.hypot(e[0],e[1],e[2])}function Uy(e){let t=Hy(e);return t<1e-12?[0,0,1]:[e[0]/t,e[1]/t,e[2]/t]}function Wy(e){return Uy(Ry(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function Gy(e){let t=Uy(e),n=Wy(t);return{xAxis:n,yAxis:Uy(Ry(t,n))}}function Ky(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n]??[0,0],i=e[(n+1)%e.length]??[0,0];t+=r[0]*i[1]-i[0]*r[1]}return t/2}function qy(e){return Ky(e)<0?[...e].reverse():e}function Jy(e){return e.node?.params}function Yy(e){let t=Iy(e),n=Jy(t),r=n?.outline??n?.polygon??n?.points;if(r&&r.length>=3){let e=n?.origin??[0,0,0],t=qy(r.map(e=>[e[0],e[1]]));if(n?.xAxis&&n.yAxis)return{outline:t,origin:e,xAxis:n.xAxis,yAxis:n.yAxis};let{xAxis:i,yAxis:a}=Gy(n?.normal??[0,0,1]);return{outline:t,origin:e,xAxis:i,yAxis:a}}return Xy(t)}function Xy(e){let t=B(e)?.getMesh?.();if(!t)throw Error(`manifold: profile carries no recorded outline and no mesh to derive one`);let n=t.numProp,r=Math.floor(t.vertProperties.length/n),i=[],a=0;for(let e=0;e<r;e++)i.push([t.vertProperties[e*n]??0,t.vertProperties[e*n+1]??0]),a+=t.vertProperties[e*n+2]??0;a/=Math.max(1,r);let o=Zy(i);return{outline:qy(o.length>=3?o:[[-.5,-.5],[.5,-.5],[0,.5]]),origin:[0,0,a],xAxis:[1,0,0],yAxis:[0,1,0]}}function Zy(e){let t=[...e].sort((e,t)=>e[0]===t[0]?e[1]-t[1]:e[0]-t[0]);if(t.length<3)return[...t];let n=(e,t,n)=>(t[0]-e[0])*(n[1]-e[1])-(t[1]-e[1])*(n[0]-e[0]),r=[];for(let e of t){for(;r.length>=2&&n(r[r.length-2]??e,r[r.length-1]??e,e)<=0;)r.pop();r.push(e)}let i=[];for(let e=t.length-1;e>=0;e--){let r=t[e]??[0,0];for(;i.length>=2&&n(i[i.length-2]??r,i[i.length-1]??r,r)<=0;)i.pop();i.push(r)}return r.pop(),i.pop(),[...r,...i]}function Qy(e){let t=[];for(let n=1;n+1<e;n++)t.push(0,n,n+1);return t}function $y(e,t,n=1){return e.outline.map(e=>{let r=e[0]*n,i=e[1]*n;return[t.origin[0]+t.xAxis[0]*r+t.yAxis[0]*i,t.origin[1]+t.xAxis[1]*r+t.yAxis[1]*i,t.origin[2]+t.xAxis[2]*r+t.yAxis[2]*i]})}function eb(e,t){if(t.length<2)throw Error(`manifold: skinning requires at least two rings`);let n=t[0]?.length??0;if(n<3)throw Error(`manifold: skinning requires rings of at least three points`);let r=[];for(let e of t){if(e.length!==n)throw Error(`manifold: skinning requires all rings to share a vertex count`);for(let t of e)r.push(t[0],t[1],t[2])}let i=tb(t.length,n),a=new e.Mesh({numProp:3,vertProperties:Float32Array.from(r),triVerts:Uint32Array.from(i)});return new e.Manifold(a)}function tb(e,t){let n=[];for(let r=0;r+1<e;r++){let e=r*t,i=(r+1)*t;for(let r=0;r<t;r++){let a=(r+1)%t;n.push(e+r,e+a,i+a),n.push(e+r,i+a,i+r)}}let r=Qy(t);for(let e=0;e<r.length;e+=3)n.push(r[e]??0,r[e+2]??0,r[e+1]??0);let i=(e-1)*t,a=Qy(t);for(let e=0;e<a.length;e+=3)n.push(i+(a[e]??0),i+(a[e+1]??0),i+(a[e+2]??0));return n}function nb(e,t){let n=[];if(e.length===0)return n;let r=t=>{let n=e[Math.max(0,t-1)]??e[t]??[0,0,0];return Uy(zy(e[Math.min(e.length-1,t+1)]??e[t]??[0,0,0],n))},i=r(0),a=Uy(zy(t,Vy(i,Ly(t,i))));Hy(a)<1e-9&&(a=Wy(i)),n.push({origin:e[0]??[0,0,0],xAxis:a,yAxis:Uy(Ry(i,a)),tangent:i});for(let t=1;t<e.length;t++){let o=e[t-1]??[0,0,0],s=e[t]??[0,0,0],c=zy(s,o),l=Ly(c,c),u=a;if(l>1e-18){let e=zy(a,Vy(c,2/l*Ly(c,a))),n=zy(i,Vy(c,2/l*Ly(c,i))),o=zy(r(t),n),s=Ly(o,o);u=s>1e-18?zy(e,Vy(o,2/s*Ly(o,e))):e}let d=r(t),f=Uy(zy(u,Vy(d,Ly(u,d)))),p=Uy(Ry(d,f));n.push({origin:s,xAxis:f,yAxis:p,tangent:d}),i=d,a=f}return n}var rb=Math.PI/180;function ib(e){return e}function ab(e){let t=180/Math.PI*e;return t>360?360:t}function ob(e){let t=e;if(t&&typeof t.X==`function`&&typeof t.Y==`function`&&typeof t.Z==`function`)return[t.X(),t.Y(),t.Z()]}function sb(e){if(e&&typeof e==`object`){let t=e;if(`origin`in t&&`direction`in t)return{origin:t.origin,direction:t.direction};let n=e;if(typeof n.Location==`function`&&typeof n.Direction==`function`){let e=ob(n.Location()),t=ob(n.Direction());if(e&&t)return{origin:e,direction:t}}}}function cb(e){return e.outline.map(e=>[e[0],e[1]])}function lb(e){return{outline:e.outline,origin:e.origin,xAxis:e.xAxis,yAxis:e.yAxis}}function ub(e){return{origin:e.origin,xAxis:e.xAxis,yAxis:e.yAxis,tangent:Uy(Ry(e.xAxis,e.yAxis))}}function db(e){let t=0;for(let n of e.outline)t=Math.max(t,Math.hypot(n[0],n[1]));return t||1}function fb(e){let t=B(e)?.getMesh?.();if(!t)return[];let n=t.numProp,r=Math.floor(t.vertProperties.length/n),i=[];for(let e=0;e<r;e++)i.push([t.vertProperties[e*n]??0,t.vertProperties[e*n+1]??0,t.vertProperties[e*n+2]??0]);return i}function pb(e,t){let n=ib(e),r=n.node?.params,i=r?.path??r?.points;if(i&&i.length>=2)return i.map(e=>[e[0],e[1],e[2]]);let a=fb(n);if(a.length>=2)return a;let o=[],s=Math.max(2,t);for(let e=0;e<s;e++)o.push([0,0,e/(s-1)]);return o}function mb(e){return e?.node??Yv(`spine`,{},[])}function hb(e,t,n){let r=e;if(!(Math.abs(n[0])<1e-9&&Math.abs(n[1])<1e-9&&n[2]>0)){let e=Math.atan2(Math.hypot(n[0],n[1]),n[2])*(180/Math.PI),t=Math.atan2(n[1],n[0])*(180/Math.PI);r=r.rotate([0,e,t])}let i=t.origin;return(i[0]!==0||i[1]!==0||i[2]!==0)&&(r=r.translate([i[0],i[1],i[2]])),r}function gb(e,t,n){let r=Uy(n);return e.outline.map(n=>{let i=zy(By(e.origin,By(Vy(e.xAxis,n[0]),Vy(e.yAxis,n[1]))),t),a=i[0]*r[0]+i[1]*r[1]+i[2]*r[2];return[Hy(zy(i,Vy(r,a))),a]})}function _b(e,t,n){let r=e,i=Uy(n);if(!(Math.abs(i[0])<1e-9&&Math.abs(i[2])<1e-9&&i[1]>0)){let e=Math.acos(Math.max(-1,Math.min(1,i[1])))*(180/Math.PI),t=Ry([0,1,0],i);Hy(t)<1e-9&&(t=[1,0,0]),t=Uy(t),r=r.rotate([t[0]*e,t[1]*e,t[2]*e])}return(t[0]!==0||t[1]!==0||t[2]!==0)&&(r=r.translate([t[0],t[1],t[2]])),r}function vb(e,t,n,r,i){let a=Uy(t),{xAxis:o,yAxis:s}=Gy(a),c=i*2*Math.PI,l=Math.max(8,Math.ceil(Math.abs(i)*24)),u=r*i,d=[];for(let t=0;t<=l;t++){let r=t/l,i=c*r,f=By(Vy(o,n*Math.cos(i)),Vy(s,n*Math.sin(i)));d.push(By(e,By(f,Vy(a,u*r))))}return d}function yb(e){if(e.length!==0)return t=>{let n=t*(e.length-1),r=Math.floor(n),i=Math.min(e.length-1,r+1),a=n-r;return(e[r]??1)*(1-a)+(e[i]??1)*a}}function bb(e,t,n,r){let i=Yy(t),a=Uy([n[0],n[1],n[2]]),o=Hy([n[0]*r,n[1]*r,n[2]*r]);return Xv(hb(e.Manifold.extrude([cb(i)],o),i,a),Yv(`extrude`,{outline:i.outline,origin:i.origin,xAxis:i.xAxis,yAxis:i.yAxis,direction:[n[0],n[1],n[2]],length:r},[V(ib(t))]))}function xb(e,t,n,r,i,a,o){let s=Yy(t),c=ab(i),l=gb(s,n,r);return Xv(_b(e.Manifold.revolve([l],0,c),n,r),Yv(a,o,[V(ib(t))]))}function Sb(e,t,n,r){if(t.length<2)throw Error(`manifold: loft requires at least two profiles`);let i=t.map(Yy),a=i[0]?.outline.length??0;return Xv(eb(e,i.map(e=>{if(e.outline.length!==a)throw Error(`manifold: loft profiles must share a vertex count for mesh skinning`);return $y(e,ub(e))})),Yv(n,{sections:i.map(lb),...r},t.map(e=>V(ib(e)))))}function Cb(e,t,n,r,i,a,o){let s=Yy(t),c=nb(n,s.xAxis),l=c.length;return Xv(eb(e,c.map((e,t)=>$y(s,e,o?o(l>1?t/(l-1):0):1))),Yv(i,{section:lb(s),path:n.map(e=>[e[0],e[1],e[2]]),...a},[V(ib(t)),r]))}function wb(e,t,n,r,i,a){if(r===null)return t;let o=Yy(n),s=Uy(Ry(o.xAxis,o.yAxis)),c=Math.tan(i*rb),l={origin:By(o.origin,Vy(s,r)),xAxis:o.xAxis,yAxis:o.yAxis,tangent:s},u=1+c*r/db(o),d=eb(e,[$y(o,ub(o),1),$y(o,l,u)]),f=Yv(`draftPrism`,{outline:o.outline,origin:o.origin,xAxis:o.xAxis,yAxis:o.yAxis,height:r,angleDeg:i,fuse:a},[V(ib(n))]);if(a){let e=ib(t);return Xv(B(e).add(d),Yv(`makeFuse`,{},[V(e),f]))}return Xv(d,f)}function Tb(e){return{revolve:(t,n,r)=>{let i=sb(n);if(!i)throw Error(`manifold: revolve could not read the axis; pass {origin,direction}, a gp_Ax1, or use revolveVec`);let{origin:a,direction:o}=i;return xb(e,t,a,o,r,`revolve`,{...lb(Yy(t)),axisOrigin:[a[0],a[1],a[2]],axisDirection:[o[0],o[1],o[2]],angleDeg:ab(r)})},revolveVec:(t,n,r,i)=>xb(e,t,n,r,i,`revolveVec`,{...lb(Yy(t)),center:[n[0],n[1],n[2]],direction:[r[0],r[1],r[2]],angleDeg:ab(i)})}}function Eb(e){return{sweep:(t,n,r)=>{let i={};return r?.transitionMode!==void 0&&(i.transitionMode=r.transitionMode),Cb(e,t,pb(n,16),mb(n),`sweep`,i)},simplePipe:(t,n)=>Cb(e,t,pb(n,16),mb(n),`simplePipe`,{}),sweepWithOptions:(t,n,r,i,a)=>Cb(e,t,pb(n,Math.max(2,a||16)),mb(n),`sweepWithOptions`,{contactMode:r,scaleValues:[...i],segments:a},yb(i)),sweepPipeShell:(t,n,r)=>{let i={};r?.transitionMode!==void 0&&(i.transitionMode=r.transitionMode);let a=Cb(e,t,pb(n,16),mb(n),`sweepPipeShell`,i);return r?.shellMode?{shape:a,firstShape:t,lastShape:t}:a},helicalSweep:(t,n,r,i,a,o)=>Cb(e,t,vb(n,r,i,a,o),mb(t),`helicalSweep`,{axisOrigin:[n[0],n[1],n[2]],axisDirection:[r[0],r[1],r[2]],radius:i,pitch:a,turns:o})}}function Db(e){return{extrude:(t,n,r)=>bb(e,t,n,r),...Tb(e),loft:(t,n)=>Sb(e,t,`loft`,{ruled:n??!1}),loftAdvanced:(t,n)=>Sb(e,t,`loftAdvanced`,{solid:n?.solid??!0,ruled:n?.ruled??!1,tolerance:n?.tolerance}),...Eb(e),draftPrism:(t,n,r,i,a,o)=>wb(e,t,n,i,a,o),buildExtrusionLaw:(e,t,n)=>({type:`extrusionLaw`,profile:e,length:t,endFactor:n}),loftBatch:()=>z(`loftBatch`),extrudeBatch:()=>z(`extrudeBatch`)}}var Ob=16;function kb(e){return typeof e?.translate==`function`?e.translate([0,0,0]):e}function Ab(e,t,n){if(!(n>0))return kb(t);let r=Nb(e,n);return r===void 0||typeof t?.minkowskiDifference!=`function`||typeof t?.minkowskiSum!=`function`?kb(t):t.minkowskiDifference(r).minkowskiSum(r)}function jb(e,t,n){if(n===0)return kb(t);let r=Nb(e,Math.abs(n));return r===void 0?kb(t):n>0?typeof t?.minkowskiSum==`function`?t.minkowskiSum(r):kb(t):typeof t?.minkowskiDifference==`function`?t.minkowskiDifference(r):kb(t)}function Mb(e,t,n,r){if(n===0)return kb(t);if(r)return jb(e,t,Math.abs(n));let i=jb(e,t,-Math.abs(n));return typeof t?.subtract==`function`?t.subtract(i):kb(t)}function Nb(e,t){let n=e?.Manifold;if(typeof n?.sphere==`function`)return n.sphere(t,Ob)}function Pb(e){return e}function Fb(e){let t=e;if(t!=null){if(typeof t.index==`number`)return t.index;if(typeof t.id==`number`)return t.id}}function Ib(e){let{min:t,max:n}=e;if(!(t===void 0||n===void 0||t.length<3||n.length<3))return[((t[0]??0)+(n[0]??0))/2,((t[1]??0)+(n[1]??0))/2,((t[2]??0)+(n[2]??0))/2]}function Lb(e){let t=e;if(t?.box!==void 0)return Ib(t.box);let n=(e?.manifold)?.boundingBox?.();return n===void 0?void 0:Ib(n)}function Rb(e){let t=e.length;if(t===0)return{kind:`all`,count:t};let n=[];for(let t of e){let e=Lb(t);if(e===void 0){n.length=0;break}n.push(e)}if(n.length===t)return{kind:`witness`,count:t,points:n};let r=[];for(let t of e){let e=Fb(t);if(e===void 0){r.length=0;break}r.push(e)}return r.length===t?{kind:`index`,count:t,indices:r}:{kind:`all`,count:t}}function zb(e){return typeof e==`function`&&z(`fillet (per-edge radius callback)`),e}function Bb(e){return typeof e==`number`?e:e[0]}function Vb(e){let t=e.match(/[-+]?\d*\.?\d+/);return t?Number(t[0]):0}function Hb(e,t,n,r,i){let a=Pb(n),o=zb(i),s=Rb(r);return Xv(Ab(e,B(a),Bb(o)),Yv(t,{radius:o,selection:s},[V(a)]))}function Ub(e,t,n,r,i){let a=Pb(t),o=Rb(n);return Xv(Ab(e,B(a),r),Yv(`chamferDistAngle`,{distance:r,angleDeg:i,selection:o},[V(a)]))}function Wb(e,t,n,r,i){let a=Pb(t),o=Rb(n);return Xv(Mb(e,B(a),r,!1),Yv(`shell`,i===void 0?{thickness:r,selection:o}:{thickness:r,selection:o,tolerance:i},[V(a)]))}function Gb(e,t,n){let r=Pb(t);return Xv(Mb(e,B(r),n,!0),Yv(`thicken`,{thickness:n},[V(r)]))}function Kb(e,t,n,r){let i=Pb(t);return Xv(jb(e,B(i),n),Yv(`offset`,r===void 0?{distance:n}:{distance:n,tolerance:r},[V(i)]))}function qb(e,t,n){let r=Pb(t);return Xv(Ab(e,B(r),Vb(n)),Yv(`filletVariable`,{spec:n},[V(r)]))}function Jb(e,t,n,r,i){typeof i==`function`&&z(`draft (per-face angle callback)`);let a=Pb(e),o=Rb(t);return Xv(kb(B(a)),Yv(`draft`,{pullDirection:n,neutralPlane:r,angleDeg:i,selection:o},[V(a)]))}function Yb(e,t){let n=Pb(e),r=Rb(t);return Xv(kb(B(n)),Yv(`defeature`,{selection:r},[V(n)]))}function Xb(e){let t=Pb(e),n=B(t);return Xv(typeof n?.simplify==`function`?n.simplify():kb(n),Yv(`simplify`,{},[V(t)]))}function Zb(e){let t=Pb(e),n=B(t);return Xv(typeof n?.mirror==`function`?n.mirror([1,0,0]):kb(n),Yv(`reverseShape`,{},[V(t)]))}function Qb(e,t){let n=Pb(t.shape),r=Rb(t.edges.map(e=>e.edge)),i=t.edges.map(e=>e.r2===void 0?e.radius:[e.radius,e.r2]),a=t.edges[0]?.radius??0;return Xv(Ab(e,B(n),a),Yv(`fillet`,{radii:i,selection:r},[V(n)]))}function $b(e){return{fillet:(t,n,r)=>Hb(e,`fillet`,t,n,r),chamfer:(t,n,r)=>Hb(e,`chamfer`,t,n,r),chamferDistAngle:(t,n,r,i)=>Ub(e,t,n,r,i),shell:(t,n,r,i)=>Wb(e,t,n,r,i),thicken:(t,n)=>Gb(e,t,n),offset:(t,n,r)=>Kb(e,t,n,r),filletVariable:(t,n)=>qb(e,t,n),draft:(e,t,n,r,i)=>Jb(e,t,n,r,i),defeature:(e,t)=>Yb(e,t),offsetWire2D:()=>z(`offsetWire2D`),simplify:e=>Xb(e),reverseShape:e=>Zb(e),shellBatch:t=>t.map(t=>Wb(e,t.shape,t.faces,t.thickness,t.tolerance)),filletBatch:t=>t.map(t=>Qb(e,t))}}function ex(e){return B(e).getMesh()}function tx(e){let t=e.numProp,n=e.vertProperties.length/t;if(t===3)return new Float32Array(e.vertProperties);let r=new Float32Array(n*3);for(let i=0;i<n;i++)r[i*3]=e.vertProperties[i*t]??0,r[i*3+1]=e.vertProperties[i*t+1]??0,r[i*3+2]=e.vertProperties[i*t+2]??0;return r}function nx(e,t){let n=new Float32Array(e.length);for(let r=0;r<t.length;r+=3){let i=(t[r]??0)*3,a=(t[r+1]??0)*3,o=(t[r+2]??0)*3,s=e[i]??0,c=e[i+1]??0,l=e[i+2]??0,u=(e[a]??0)-s,d=(e[a+1]??0)-c,f=(e[a+2]??0)-l,p=(e[o]??0)-s,m=(e[o+1]??0)-c,h=(e[o+2]??0)-l,g=d*h-f*m,_=f*p-u*h,v=u*m-d*p;for(let e of[i,a,o])n[e]=(n[e]??0)+g,n[e+1]=(n[e+1]??0)+_,n[e+2]=(n[e+2]??0)+v}for(let e=0;e<n.length;e+=3){let t=n[e]??0,r=n[e+1]??0,i=n[e+2]??0,a=Math.sqrt(t*t+r*r+i*i);a>1e-12&&(n[e]=t/a,n[e+1]=r/a,n[e+2]=i/a)}return n}function rx(e){let t=e.triVerts.length/3,{runIndex:n,runOriginalID:r}=e;if(!n||!r||n.length<2)return[{start:0,count:e.triVerts.length,faceHash:0}];let i=[];for(let e=0;e+1<n.length;e++){let a=n[e]??0,o=(n[e+1]??t*3)-a;o!==0&&i.push({start:a,count:o,faceHash:r[e]??0})}return i}function ix(e,t){let n=ex(e),r=tx(n),i=new Uint32Array(n.triVerts);return{vertices:r,normals:t.skipNormals?new Float32Array:nx(r,i),triangles:i,uvs:t.includeUVs?new Float32Array(r.length/3*2):new Float32Array,faceGroups:rx(n)}}function ax(e,t,n){let r=ex(e),i=tx(r),a=r.triVerts,o=[],s=[],c=new Set,l=i.length/3,u=e=>{o.push(i[e*3]??0,i[e*3+1]??0,i[e*3+2]??0)};for(let e=0;e<a.length;e+=3){let t=a[e]??0,n=a[e+1]??0,r=a[e+2]??0;for(let[e,i]of[[t,n],[n,r],[r,t]]){let t=Math.min(e,i),n=Math.max(e,i),r=t*l+n;if(c.has(r))continue;c.add(r);let a=o.length/3;u(t),u(n),s.push({start:a,count:2,edgeHash:r})}}return{lines:new Float32Array(o),edgeGroups:s}}function ox(e){return!0}function sx(e){return{mesh:(e,t)=>ix(e,t),meshEdges:(e,t,n)=>ax(e,t,n),hasTriangulation:e=>ox(e),meshShape:(e,t,n)=>{}}}function cx(e,t=[0,0,0]){return Array.isArray(e)&&e.length>=3?[Number(e[0]),Number(e[1]),Number(e[2])]:[...t]}function H(e,t=0){return typeof e==`number`?e:t}function lx(e,t=``){return typeof e==`string`?e:t}function ux(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function dx(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function fx(e,t,n,r){return ux(t,ux(dx(n,e[0]),dx(r,e[1])))}function px(e,t){let n=t.outline??[];if(n.length<3)throw Error(`manifold replay: profile outline needs at least three points`);let r=cx(t.origin),i=cx(t.xAxis,[1,0,0]),a=cx(t.yAxis,[0,1,0]),o=n.map(e=>fx(e,r,i,a)),s=[];for(let t=0;t<o.length;t++){let n=o[t]??r,i=o[(t+1)%o.length]??r;s.push(e.makeLineEdge([n[0],n[1],n[2]],[i[0],i[1],i[2]]))}let c=e.makeWire(s),l=e.makeFace(c,!0);for(let t of s)e.dispose(t);return l}function mx(e,t){return px(e,t)}function hx(e,t){let n=e.boundingBox(t);return[(n.min[0]+n.max[0])/2,(n.min[1]+n.max[1])/2,(n.min[2]+n.max[2])/2]}function gx(e,t){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return n*n+r*r+i*i}function _x(e,t,n,r){let i=e.iterShapes(t,r);if(!n||n.kind===`all`)return i;if(n.kind===`witness`){let t=n.points??[],r=i.map(t=>hx(e,t)),a=[],o=new Set;for(let e of t){let t=-1,n=1/0;for(let a=0;a<i.length;a++){if(o.has(a))continue;let i=gx(e,r[a]??[0,0,0]);i<n&&(n=i,t=a)}let s=i[t];t>=0&&s!==void 0&&(o.add(t),a.push(s))}return a}if(n.kind===`index`){let e=n.indices??[],t=[];for(let n of e){let e=i[n];e!==void 0&&t.push(e)}return t}let a=n.regions??[],o=e=>a.some(t=>e[0]>=t.min[0]&&e[0]<=t.max[0]&&e[1]>=t.min[1]&&e[1]<=t.max[1]&&e[2]>=t.min[2]&&e[2]<=t.max[2]);return i.filter(t=>o(hx(e,t)))}function vx(e){let t=e.selection;return t===void 0?void 0:t}function yx(e){let t=e[0];if(t===void 0)throw Error(`manifold replay: op requires an input shape`);return t}function bx(e,t,n){return e.createAxis1(t[0],t[1],t[2],n[0],n[1],n[2])}function xx(e,t){return(n,r)=>{let i=px(n,r),a=cx(r[e]),o=cx(r[t],[0,0,1]),s=H(r.angleDeg,360);return n.revolve(i,bx(n,a,o),Math.PI/180*s)}}var Sx={makeBox:(e,t)=>e.makeBox(H(t.width),H(t.height),H(t.depth)),makeBoxWithCorners:(e,t)=>e.makeBoxFromCorners(cx(t.p1),cx(t.p2)),makeCylinder:(e,t)=>e.makeCylinder(H(t.radius),H(t.height),cx(t.center),cx(t.direction,[0,0,1])),makeSphere:(e,t)=>e.makeSphere(H(t.radius),cx(t.center)),makeCone:(e,t)=>e.makeCone(H(t.radius1),H(t.radius2),H(t.height),cx(t.center),cx(t.direction,[0,0,1])),makeTorus:(e,t)=>e.makeTorus(H(t.majorRadius),H(t.minorRadius),cx(t.center),cx(t.direction,[0,0,1])),makeEllipsoid:(e,t)=>e.makeEllipsoid(H(t.aLength),H(t.bLength),H(t.cLength)),makeFuse:(e,t,n)=>{if(n.length<2)return yx(n);let r=yx(n);for(let t of n.slice(1))r=e.fuse(r,t);return r},makeCut:(e,t,n)=>{let r=yx(n);return e.cutAll(r,n.slice(1))},makeCommon:(e,t,n)=>{let r=yx(n);for(let t of n.slice(1))r=e.intersect(r,t);return r},translateShape:(e,t,n)=>e.translate(yx(n),H(t.x),H(t.y),H(t.z)),rotateShape:(e,t,n)=>e.rotate(yx(n),H(t.angle),cx(t.axis,[0,0,1]),cx(t.center)),scaleShape:(e,t,n)=>e.scale(yx(n),cx(t.center),H(t.factor,1)),mirrorShape:(e,t,n)=>e.mirror(yx(n),cx(t.origin),cx(t.normal,[1,0,0])),transformShape:(e,t,n)=>e.transform(yx(n),t.matrix),generalTransform:(e,t,n)=>e.generalTransform(yx(n),t.linear,cx(t.translation),!!t.isOrthogonal),generalTransformNonOrthogonal:(e,t,n)=>e.generalTransformNonOrthogonal(yx(n),t.linear,cx(t.translation)),gridPattern:(e,t,n)=>{if(typeof e.gridPattern!=`function`)throw Error(`manifold replay: target kernel lacks gridPattern`);return e.gridPattern(yx(n),cx(t.directionX),cx(t.directionY),H(t.spacingX),H(t.spacingY),H(t.countX,1),H(t.countY,1))},extrude:(e,t)=>{let n=px(e,t);return e.extrude(n,cx(t.direction,[0,0,1]),H(t.length,1))},revolve:xx(`axisOrigin`,`axisDirection`),revolveVec:xx(`center`,`direction`),loft:(e,t)=>{let n=(t.sections??[]).map(t=>Cx(e,t));return e.loft(n,!!t.ruled)},loftAdvanced:(e,t)=>{let n=(t.sections??[]).map(t=>Cx(e,t)),r={solid:t.solid!==!1,ruled:!!t.ruled};return typeof t.tolerance==`number`&&(r.tolerance=t.tolerance),e.loftAdvanced(n,r)},sweep:(e,t)=>e.sweep(wx(e,t),Tx(e,t)),simplePipe:(e,t)=>e.simplePipe(wx(e,t),Tx(e,t)),sweepWithOptions:(e,t)=>e.sweepWithOptions(wx(e,t),Tx(e,t),lx(t.contactMode),t.scaleValues??[],H(t.segments,0)),sweepPipeShell:(e,t)=>{let n=e.sweepPipeShell(wx(e,t),Tx(e,t));return Ex(n)?n.shape:n},helicalSweep:(e,t)=>e.helicalSweep(wx(e,t),cx(t.axisOrigin),cx(t.axisDirection,[0,0,1]),H(t.radius),H(t.pitch),H(t.turns,1)),draftPrism:(e,t)=>{let n=px(e,t);return e.draftPrism(n,n,n,H(t.height),H(t.angleDeg),!!t.fuse)},fillet:(e,t,n)=>{let r=yx(n),i=_x(e,r,vx(t),`edge`),a=t.radii,o=t.radius;if(a&&a.length>1){let t=new Map;for(let e=0;e<i.length;e++){let n=i[e],r=a[e]??a[a.length-1];n!==void 0&&r!==void 0&&t.set(n,r)}return e.fillet(r,i,e=>t.get(e)??0)}let s=a?.[0]??o;return e.fillet(r,i,s??0)},chamfer:(e,t,n)=>{let r=yx(n),i=_x(e,r,vx(t),`edge`);return e.chamfer(r,i,t.radius)},chamferDistAngle:(e,t,n)=>{let r=yx(n),i=_x(e,r,vx(t),`edge`);return e.chamferDistAngle(r,i,H(t.distance),H(t.angleDeg))},shell:(e,t,n)=>{let r=yx(n),i=_x(e,r,vx(t),`face`);return typeof t.tolerance==`number`?e.shell(r,i,H(t.thickness),t.tolerance):e.shell(r,i,H(t.thickness))},thicken:(e,t,n)=>e.thicken(yx(n),H(t.thickness)),offset:(e,t,n)=>typeof t.tolerance==`number`?e.offset(yx(n),H(t.distance),t.tolerance):e.offset(yx(n),H(t.distance)),filletVariable:(e,t,n)=>e.filletVariable(yx(n),lx(t.spec)),draft:(e,t,n)=>{let r=yx(n),i=_x(e,r,vx(t),`face`);return e.draft(r,i,cx(t.pullDirection,[0,0,1]),cx(t.neutralPlane),H(t.angleDeg))},defeature:(e,t,n)=>{let r=yx(n),i=_x(e,r,vx(t),`face`);return e.defeature(r,i)},simplify:(e,t,n)=>e.simplify(yx(n)),reverseShape:(e,t,n)=>e.reverseShape(yx(n)),hull:(e,t,n)=>e.hull([...n],H(t.tolerance)),hullFromPoints:(e,t)=>{let n=t.points??[];return e.hullFromPoints(n.map(e=>({x:e[0],y:e[1],z:e[2]})),H(t.tolerance))},sewAndSolidify:(e,t,n)=>e.sewAndSolidify([...n],H(t.tolerance))};function Cx(e,t){let n=mx(e,t);return e.iterShapes(n,`wire`)[0]??n}function wx(e,t){let n=t.section;return n?mx(e,n):px(e,t)}function Tx(e,t){let n=t.path??[];if(n.length<2)throw Error(`manifold replay: sweep spine needs at least two path points`);let r=[];for(let t=0;t+1<n.length;t++){let i=n[t]??[0,0,0],a=n[t+1]??[0,0,0];r.push(e.makeLineEdge([i[0],i[1],i[2]],[a[0],a[1],a[2]]))}let i=e.makeWire(r);for(let t of r)e.dispose(t);return i}function Ex(e){return typeof e==`object`&&!!e&&`shape`in e&&`firstShape`in e&&`lastShape`in e}function Dx(e,t,n,r){let i=n.get(e);if(i!==void 0)return i;if(!e.replayable)throw Error(`manifold replay: op '${e.op}' is not replayable (raw-mesh origin or unsupported)`);let a=Sx[e.op];if(!a)throw Error(`manifold replay: no replay handler for op '${e.op}'`);let o=e.inputs.map(e=>Dx(e,t,n,r)),s=a(t,e.params,o);return n.set(e,s),r.add(s),s}function Ox(e,t,n=new Map){let r=new Set,i=Dx(e,t,n,r);for(let e of r)e!==i&&t.dispose(e);return i}function kx(e){return B(e)}function Ax(e){return kx(e).boundingBox()}function jx(e){return kx(e)?.getMesh?.()}function Mx(e,t){let n=t*e.numProp;return[e.vertProperties[n]??0,e.vertProperties[n+1]??0,e.vertProperties[n+2]??0]}function Nx(e,t){let n=t*3;return[e.triVerts[n]??0,e.triVerts[n+1]??0,e.triVerts[n+2]??0]}function Px(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function Fx(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function Ix(e){let t=Ax(e);return[(t.min[0]+t.max[0])/2,(t.min[1]+t.max[1])/2,(t.min[2]+t.max[2])/2]}function Lx(e){let t=Math.floor(e.vertProperties.length/e.numProp);if(t===0)return[0,0,0];let n=[0,0,0];for(let r=0;r<t;r++){let t=Mx(e,r);n[0]+=t[0],n[1]+=t[1],n[2]+=t[2]}return[n[0]/t,n[1]/t,n[2]/t]}function Rx(e){let t=jx(e);if(!t)return Ix(e);let n=Math.floor(t.triVerts.length/3),r=0,i=[0,0,0];for(let e=0;e<n;e++){let[n,a,o]=Nx(t,e),s=Mx(t,n),c=Mx(t,a),l=Mx(t,o),u=Fx(s,Px(c,l))/6;r+=u,i[0]+=(s[0]+c[0]+l[0])/4*u,i[1]+=(s[1]+c[1]+l[1])/4*u,i[2]+=(s[2]+c[2]+l[2])/4*u}return Math.abs(r)<1e-12?Lx(t):[i[0]/r,i[1]/r,i[2]/r]}function zx(e){let t=jx(e);if(!t)return Ix(e);let n=Math.floor(t.triVerts.length/3),r=0,i=[0,0,0];for(let e=0;e<n;e++){let[n,a,o]=Nx(t,e),s=Mx(t,n),c=Mx(t,a),l=Mx(t,o),u=Px([c[0]-s[0],c[1]-s[1],c[2]-s[2]],[l[0]-s[0],l[1]-s[1],l[2]-s[2]]),d=Math.hypot(u[0],u[1],u[2])/2;r+=d,i[0]+=(s[0]+c[0]+l[0])/3*d,i[1]+=(s[1]+c[1]+l[1])/3*d,i[2]+=(s[2]+c[2]+l[2])/3*d}return r<1e-12?Lx(t):[i[0]/r,i[1]/r,i[2]/r]}function Bx(e){return kx(e).volume()}function Vx(e){return kx(e).surfaceArea()}function Hx(e){let t=Ax(e);return{min:[...t.min],max:[...t.max]}}function Ux(e){return Rx(e)}function Wx(e,t){let n=(e,t,n,r)=>{if(t<n)return[t,n];if(r<e)return[e,r];let i=(Math.max(e,n)+Math.min(t,r))/2;return[i,i]},[r,i]=n(e.min[0],e.max[0],t.min[0],t.max[0]),[a,o]=n(e.min[1],e.max[1],t.min[1],t.max[1]),[s,c]=n(e.min[2],e.max[2],t.min[2],t.max[2]),l=i-r,u=o-a,d=c-s;return{value:Math.sqrt(l*l+u*u+d*d),point1:[r,a,s],point2:[i,o,c]}}function Gx(e,t){return Wx(Ax(e),Ax(t))}function Kx(e,t=!1){return{volume:Bx(e),area:Vx(e),length:0,centerOfMass:Ux(e),boundingBox:Hx(e)}}function qx(e,t,n){let r=Qv();if(!r)throw Error(`manifold: surfaceCurvature requires a registered occt kernel; none is available`);let i=Zv(e);if(!i)return r.surfaceCurvature(e,t,n);if(!i.node.replayable)throw Error(`manifold: surfaceCurvature unsupported; shape originates from a non-replayable op (raw mesh import or mesh boolean)`);let a=ey.get(i.node)??(()=>{let e=Ox(i.node,r);return ey.set(i.node,e),e})();return r.surfaceCurvature(a,t,n)}function Jx(e){return{volume:e=>Bx(e),area:e=>Vx(e),length:()=>z(`length`),centerOfMass:e=>Ux(e),linearCenterOfMass:e=>Ux(e),boundingBox:e=>Hx(e),distance:(e,t)=>Gx(e,t),surfaceCurvature:(e,t,n)=>qx(e,t,n),surfaceCenterOfMass:e=>zx(e),measureBulk:(e,t)=>Kx(e,t),createDistanceQuery:e=>({distanceTo:t=>Gx(e,t),dispose:()=>{}})}}function Yx(e,t){let n=Zv(e);if(!n)throw Error(`manifold: ${t} requires a manifold shape handle`);if(!n.node.replayable)throw Error(`manifold: ${t} unsupported; shape originates from a non-replayable op (raw mesh import or mesh boolean)`);let r=$v(t),i=ey.get(n.node);if(i!==void 0)return{occt:r,brep:i};let a=Ox(n.node,r);return ey.set(n.node,a),{occt:r,brep:a}}function Xx(e){function t(e){let{occt:t,brep:n}=Yx(e,`shapeType`);return t.shapeType(n)}function n(e,t){let n=Zv(e),r=Zv(t);return!n||!r?!1:n.manifold===r.manifold}function r(e,t){return n(e,t)}function i(e,t){if(!Zv(e))return 0;let{occt:n,brep:r}=Yx(e,`hashCode`);return n.hashCode(r,t)}function a(e){let t=Zv(e);if(!t)return!0;let n=B(t);return!n||typeof n.isEmpty==`function`&&n.isEmpty()}function o(e){return`forward`}function s(e,t){let n=Zv(e);if(!n)return[];if(t===`solid`)return[e];if(t!==`edge`&&t!==`face`||!n.node.replayable)return[];let r=Qv();if(!r)return[];let i=ey.get(n.node)??(()=>{let e=Ox(n.node,r);return ey.set(n.node,e),e})();return r.iterShapes(i,t).map((e,t)=>({__manifoldSub:!0,index:t,box:r.boundingBox(e)}))}function c(e,t){$v(`iterShapeList`).iterShapeList(e,t)}function l(e){let{occt:t,brep:n}=Yx(e,`edgeToFaceMap`);return t.edgeToFaceMap(n)}function u(e,t){return $v(`sharedEdges`).sharedEdges(e,t)}function d(e,t){let{occt:n,brep:r}=Yx(e,`adjacentFaces`);return n.adjacentFaces(r,t)}return{iterShapes:s,iterShapeList:c,shapeType:t,isSame:n,isEqual:r,downcast:e=>e,hashCode:i,isNull:a,shapeOrientation:o,edgeToFaceMap:l,sharedEdges:u,adjacentFaces:d,sew:()=>{throw Error(`manifold: sew is unsupported on the mesh kernel; use a B-rep kernel`)}}}function Zx(e){return B(e).getMesh()}function Qx(e){return e.numProp&&e.numProp>=3?e.numProp:3}function $x(e){return Math.floor(e.vertProperties.length/Qx(e))}function eS(e,t){let n=t*Qx(e);return[e.vertProperties[n]??0,e.vertProperties[n+1]??0,e.vertProperties[n+2]??0]}function tS(e,t){let n=t*3;return[e.triVerts[n]??0,e.triVerts[n+1]??0,e.triVerts[n+2]??0]}function nS(e,t,n){let r=t[0]-e[0],i=t[1]-e[1],a=t[2]-e[2],o=n[0]-e[0],s=n[1]-e[1],c=n[2]-e[2],l=i*c-a*s,u=a*o-r*c,d=r*s-i*o,f=Math.hypot(l,u,d)||1;return[l/f,u/f,d/f]}function rS(e,t){let n=Zx(e),r=Math.floor(n.triVerts.length/3);if(t){let e=new ArrayBuffer(84+r*50),t=new DataView(e);t.setUint32(80,r,!0);let i=84;for(let e=0;e<r;e++){let[r,a,o]=tS(n,e),s=eS(n,r),c=eS(n,a),l=eS(n,o),u=nS(s,c,l);t.setFloat32(i,u[0],!0),t.setFloat32(i+4,u[1],!0),t.setFloat32(i+8,u[2],!0),i+=12;for(let e of[s,c,l])t.setFloat32(i,e[0],!0),t.setFloat32(i+4,e[1],!0),t.setFloat32(i+8,e[2],!0),i+=12;t.setUint16(i,0,!0),i+=2}return e}let i=[`solid manifold`];for(let e=0;e<r;e++){let[t,r,a]=tS(n,e),o=eS(n,t),s=eS(n,r),c=eS(n,a),l=nS(o,s,c);i.push(` facet normal ${l[0]} ${l[1]} ${l[2]}`),i.push(` outer loop`);for(let e of[o,s,c])i.push(` vertex ${e[0]} ${e[1]} ${e[2]}`);i.push(` endloop`),i.push(` endfacet`)}return i.push(`endsolid manifold`),i.join(`
|
|
8
|
+
`)}function iS(e){let t=Zx(e),n=$x(t),r=Math.floor(t.triVerts.length/3),i=[`# exported by brepjs manifold kernel`];for(let e=0;e<n;e++){let n=eS(t,e);i.push(`v ${n[0]} ${n[1]} ${n[2]}`)}for(let e=0;e<r;e++){let[n,r,a]=tS(t,e);i.push(`f ${n+1} ${r+1} ${a+1}`)}return new TextEncoder().encode(i.join(`
|
|
9
|
+
`)).buffer}function aS(e){let t=Zx(e),n=$x(t),r=Math.floor(t.triVerts.length/3),i=`ply\nformat binary_little_endian 1.0\nelement vertex ${n}\nproperty float x\nproperty float y\nproperty float z\nelement face ${r}\nproperty list uchar uint vertex_indices\nend_header\n`,a=new TextEncoder().encode(i),o=new ArrayBuffer(n*12+r*13),s=new DataView(o),c=0;for(let e=0;e<n;e++){let n=eS(t,e);s.setFloat32(c,n[0],!0),s.setFloat32(c+4,n[1],!0),s.setFloat32(c+8,n[2],!0),c+=12}for(let e=0;e<r;e++){let[n,r,i]=tS(t,e);s.setUint8(c,3),c+=1,s.setUint32(c,n,!0),s.setUint32(c+4,r,!0),s.setUint32(c+8,i,!0),c+=12}let l=new Uint8Array(a.length+o.byteLength);return l.set(a,0),l.set(new Uint8Array(o),a.length),l.buffer}function oS(e,t,n=`importMesh`){let r=new e.Mesh({numProp:3,vertProperties:t.vertProperties,triVerts:t.triVerts});return Xv(new e.Manifold(r),Yv(n,{},[]))}function sS(e,t){let n=new TextDecoder().decode(new Uint8Array(t)),r=[],i=[];for(let e of n.split(`
|
|
10
|
+
`)){let t=e.trim();if(t.startsWith(`v `)){let e=t.slice(2).trim().split(/\s+/);r.push(Number(e[0]),Number(e[1]),Number(e[2]))}else if(t.startsWith(`f `)){let e=t.slice(2).trim().split(/\s+/).map(e=>{let t=e.split(`/`)[0]??``,n=Number(t);return n>0?n-1:r.length/3+n});for(let t=1;t+1<e.length;t++)i.push(e[0]??0,e[t]??0,e[t+1]??0)}}return oS(e,{vertProperties:Float32Array.from(r),triVerts:Uint32Array.from(i)})}function cS(e,t){let n=new Uint8Array(t),r=new TextDecoder().decode(n.subarray(0,Math.min(n.length,80))).trimStart().toLowerCase().startsWith(`solid`)&&dS(n),i=[];if(r){let e=new TextDecoder().decode(n).match(/vertex\s+(\S+)\s+(\S+)\s+(\S+)/g)??[];for(let t of e){let e=t.trim().split(/\s+/);i.push(Number(e[1]),Number(e[2]),Number(e[3]))}}else{let e=new DataView(t),n=e.getUint32(80,!0),r=84;for(let t=0;t<n;t++){r+=12;for(let t=0;t<3;t++)i.push(e.getFloat32(r,!0),e.getFloat32(r+4,!0),e.getFloat32(r+8,!0)),r+=12;r+=2}}let a=uS(i);return oS(e,{vertProperties:Float32Array.from(a.vertices),triVerts:Uint32Array.from(a.indices)})}var lS=1e6;function uS(e){let t=[],n=[],r=new Map;for(let i=0;i+2<e.length;i+=3){let a=e[i]??0,o=e[i+1]??0,s=e[i+2]??0,c=`${Math.round(a*lS)},${Math.round(o*lS)},${Math.round(s*lS)}`,l=r.get(c);l===void 0&&(l=t.length/3,r.set(c,l),t.push(a,o,s)),n.push(l)}return{vertices:t,indices:n}}function dS(e){return e.length<84?!0:84+new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(80,!0)*50!==e.length}var fS=1e-6;function pS(e,t){let n=V(t);if(n.replayable)return Ox(n,e)}function mS(e,t){let n=Zx(t),r=Math.floor(n.triVerts.length/3),i=[];for(let t=0;t<r;t++){let[r,a,o]=tS(n,t),s=e.buildTriFace(eS(n,r),eS(n,a),eS(n,o));s&&i.push(s)}if(i.length===0)throw Error(`manifold: cannot export — shape has no triangles to facet`);return e.sewAndSolidify(i,fS)}function hS(e){let t=$v(`B-rep export`),n=pS(t,e);return n===void 0?(console.warn(`manifold: exact B-rep unavailable (non-replayable op-graph); exporting faceted approximation`),{occt:t,brep:mS(t,e)}):{occt:t,brep:n}}function gS(e,t,n,r){let i=t.mesh(n,{tolerance:.01,angularTolerance:.5});return oS(e,{vertProperties:Float32Array.from(i.vertices),triVerts:Uint32Array.from(i.triangles)},r)}var _S=1179937895,vS=2,yS=1313821514,bS=5130562,xS=5126,SS=5125,CS=5123,wS=5121,TS=34962,ES=34963,DS=4;function OS(e){return e+3&-4}function kS(e){let t=Zx(e),n=t.numProp&&t.numProp>=3?t.numProp:3,r=Math.floor(t.vertProperties.length/n),i=t.triVerts.length,a=new Float32Array(r*3),o=1/0,s=1/0,c=1/0,l=-1/0,u=-1/0,d=-1/0;for(let e=0;e<r;e++){let r=t.vertProperties[e*n]??0,i=t.vertProperties[e*n+1]??0,f=t.vertProperties[e*n+2]??0;a[e*3]=r,a[e*3+1]=i,a[e*3+2]=f,r<o&&(o=r),i<s&&(s=i),f<c&&(c=f),r>l&&(l=r),i>u&&(u=i),f>d&&(d=f)}r===0&&(o=s=c=l=u=d=0);let f=Uint32Array.from(t.triVerts),p=a.byteLength,m=OS(p),h=m+f.byteLength,g={asset:{version:`2.0`,generator:`brepjs manifold kernel`},scene:0,scenes:[{nodes:[0]}],nodes:[{mesh:0}],meshes:[{primitives:[{attributes:{POSITION:0},indices:1,mode:DS}]}],accessors:[{bufferView:0,componentType:xS,count:r,type:`VEC3`,min:[o,s,c],max:[l,u,d]},{bufferView:1,componentType:SS,count:i,type:`SCALAR`}],bufferViews:[{buffer:0,byteOffset:0,byteLength:p,target:TS},{buffer:0,byteOffset:m,byteLength:f.byteLength,target:ES}],buffers:[{byteLength:h}]},_=new TextEncoder().encode(JSON.stringify(g)),v=OS(_.length),y=OS(h),b=20+v+8+y,x=new ArrayBuffer(b),S=new DataView(x),C=new Uint8Array(x);S.setUint32(0,_S,!0),S.setUint32(4,vS,!0),S.setUint32(8,b,!0);let w=12;S.setUint32(w,v,!0),S.setUint32(w+4,yS,!0),w+=8,C.set(_,w);for(let e=_.length;e<v;e++)C[w+e]=32;return w+=v,S.setUint32(w,y,!0),S.setUint32(w+4,bS,!0),w+=8,C.set(new Uint8Array(a.buffer,a.byteOffset,p),w),C.set(new Uint8Array(f.buffer,f.byteOffset,f.byteLength),w+m),x}function AS(e,t){let n=new DataView(t);if(n.getUint32(0,!0)!==_S)throw Error(`manifold: importGLB — not a binary glTF (bad magic)`);let r=n.getUint32(8,!0),i,a,o=12;for(;o<r;){let e=n.getUint32(o,!0),r=n.getUint32(o+4,!0),s=new Uint8Array(t,o+8,e);r===yS?i=JSON.parse(new TextDecoder().decode(s)):r===bS&&(a=s),o+=8+e}if(!i||typeof i!=`object`||!a)throw Error(`manifold: importGLB — missing JSON or BIN chunk`);let s=i,c=s.meshes?.[0]?.primitives[0],l=s.accessors??[],u=s.bufferViews??[];if(!c||c.attributes.POSITION===void 0)throw Error(`manifold: importGLB — no POSITION attribute`);let d=l[c.attributes.POSITION];if(!d)throw Error(`manifold: importGLB — invalid POSITION accessor`);let f=u[d.bufferView];if(!f)throw Error(`manifold: importGLB — invalid POSITION bufferView`);let p=new Float32Array(a.buffer.slice(a.byteOffset+(f.byteOffset??0),a.byteOffset+(f.byteOffset??0)+d.count*3*4)),m;if(c.indices!==void 0){let e=l[c.indices];if(!e)throw Error(`manifold: importGLB — invalid indices accessor`);let t=u[e.bufferView];if(!t)throw Error(`manifold: importGLB — invalid indices bufferView`);let n=e.componentType===SS?4:e.componentType===CS?2:+(e.componentType===wS);if(n===0)throw Error(`manifold: importGLB — unsupported index component type ${e.componentType}`);let r=a.byteOffset+(t.byteOffset??0),i=new DataView(a.buffer,r,e.count*n);m=new Uint32Array(e.count);for(let t=0;t<e.count;t++){let e=t*n;m[t]=n===4?i.getUint32(e,!0):n===2?i.getUint16(e,!0):i.getUint8(e)}}else m=Uint32Array.from({length:d.count},(e,t)=>t);return oS(e,{vertProperties:p,triVerts:m},`importGLB`)}function jS(e){return{exportSTL:(e,t)=>rS(e,t),exportOBJ:e=>iS(e),exportPLY:e=>aS(e),importSTL:t=>cS(e,typeof t==`string`?new TextEncoder().encode(t).buffer:t),importOBJ:t=>sS(e,t),exportSTEP:e=>$v(`exportSTEP`).exportSTEP(e.map(e=>hS(e).brep)),exportIGES:e=>$v(`exportIGES`).exportIGES(e.map(e=>hS(e).brep)),toBREP:e=>{let{occt:t,brep:n}=hS(e);return t.toBREP(n)},exportSTEPAssembly:(e,t)=>{let n=$v(`exportSTEPAssembly`),r=e.map(e=>{let t={shape:hS(e.shape).brep,name:e.name};return e.color===void 0?t:{...t,color:e.color}});return n.exportSTEPAssembly(r,t)},createXCAFDocument:e=>{let t=$v(`createXCAFDocument`),n=e.map(e=>{let t={shape:hS(e.shape).brep,name:e.name};return e.color===void 0?t:{...t,color:e.color}});return t.createXCAFDocument(n)},writeXCAFToSTEP:(e,t)=>$v(`writeXCAFToSTEP`).writeXCAFToSTEP(e,t),exportSTEPConfigured:(e,t)=>{let n=$v(`exportSTEPConfigured`),r=e.map(e=>{let t={shape:hS(e.shape).brep},n=e.name===void 0?t:{...t,name:e.name};return e.color===void 0?n:{...n,color:e.color}});return n.exportSTEPConfigured(r,t)},importSTEP:t=>{let n=$v(`importSTEP`);return n.importSTEP(t).map(t=>gS(e,n,t,`importSTEP`))},importIGES:t=>{let n=$v(`importIGES`);return n.importIGES(t).map(t=>gS(e,n,t,`importIGES`))},fromBREP:t=>{let n=$v(`fromBREP`);return gS(e,n,n.fromBREP(t),`fromBREP`)},exportGLB:e=>kS(e),importGLB:t=>AS(e,t),export3MF:()=>{throw Error(`manifold: 3MF IO is unsupported on the mesh kernel; export GLB/STL/OBJ or use a B-rep kernel`)},import3MF:()=>{throw Error(`manifold: 3MF IO is unsupported on the mesh kernel; export GLB/STL/OBJ or use a B-rep kernel`)}}}function MS(e){return B(e).getMesh()}function NS(e,t){let n=t*(e.numProp&&e.numProp>=3?e.numProp:3);return[e.vertProperties[n]??0,e.vertProperties[n+1]??0,e.vertProperties[n+2]??0]}function PS(e,t){let n=Zv(e);if(!n)throw Error(`manifold: exact geometry query requires a manifold shape handle`);let r=Qv();if(!r)throw Error(`manifold: exact geometry query unsupported on manifold kernel; no B-rep kernel registered`);if(!n.node.replayable)throw Error(`manifold: exact geometry query unsupported; shape originates from a non-replayable op (raw mesh import or mesh boolean)`);let i=ey.get(n.node);return i===void 0&&(i=Ox(n.node,r),ey.set(n.node,i)),t(i,r)}function FS(e){return{curveType:e=>PS(e,(e,t)=>t.curveType(e)),curveParameters:e=>PS(e,(e,t)=>t.curveParameters(e)),curvePointAtParam:(e,t)=>PS(e,(e,n)=>n.curvePointAtParam(e,t)),curveTangent:(e,t)=>PS(e,(e,n)=>n.curveTangent(e,t)),curveIsClosed:e=>PS(e,(e,t)=>t.curveIsClosed(e)),curveIsPeriodic:e=>PS(e,(e,t)=>t.curveIsPeriodic(e)),curvePeriod:e=>PS(e,(e,t)=>t.curvePeriod(e)),interpolatePoints:(e,t)=>$v(`interpolatePoints`).interpolatePoints(e,t),approximatePoints:(e,t)=>$v(`approximatePoints`).approximatePoints(e,t),curveDegreeElevate:(e,t)=>PS(e,(e,n)=>n.curveDegreeElevate(e,t)),curveKnotInsert:(e,t,n)=>PS(e,(e,r)=>r.curveKnotInsert(e,t,n)),curveKnotRemove:(e,t,n)=>PS(e,(e,r)=>r.curveKnotRemove(e,t,n)),curveSplit:(e,t)=>PS(e,(e,n)=>n.curveSplit(e,t)),createCurveAdaptor:e=>PS(e,(e,t)=>t.createCurveAdaptor(e)),getBezierPenultimatePole:e=>PS(e,(e,t)=>t.getBezierPenultimatePole(e)),getNurbsCurveData:e=>PS(e,(e,t)=>t.getNurbsCurveData?.(e)??null),vertexPosition:e=>Zv(e)?NS(MS(e),0):PS(e,(e,t)=>t.vertexPosition(e)),surfaceType:e=>PS(e,(e,t)=>t.surfaceType(e)),uvBounds:e=>PS(e,(e,t)=>t.uvBounds(e)),outerWire:e=>PS(e,(e,t)=>t.outerWire(e)),surfaceNormal:(e,t,n)=>PS(e,(e,r)=>r.surfaceNormal(e,t,n)),pointOnSurface:(e,t,n)=>PS(e,(e,r)=>r.pointOnSurface(e,t,n)),uvFromPoint:(e,t)=>PS(e,(e,n)=>n.uvFromPoint(e,t)),projectPointOnFace:(e,t)=>PS(e,(e,n)=>n.projectPointOnFace(e,t)),classifyPointOnFace:(e,t,n,r)=>PS(e,(e,i)=>i.classifyPointOnFace(e,t,n,r)),classifyPointRobust:(e,t,n)=>PS(e,(e,r)=>r.classifyPointRobust(e,t,n)),classifyPointWinding:(e,t,n)=>PS(e,(e,r)=>r.classifyPointWinding(e,t,n)),approximateSurfaceLspia:(e,t,n,r,i,a,o,s,c)=>$v(`approximateSurfaceLspia`).approximateSurfaceLspia(e,t,n,r,i,a,o,s,c),untrimFace:(e,t,n)=>PS(e,(e,r)=>r.untrimFace(e,t,n)),getSurfaceCylinderData:e=>PS(e,(e,t)=>t.getSurfaceCylinderData(e)),reverseSurfaceU:e=>$v(`reverseSurfaceU`).reverseSurfaceU(e),detectSmallFeatures:(e,t,n)=>PS(e,(e,r)=>r.detectSmallFeatures(e,t,n)),recognizeFeatures:(e,t)=>PS(e,(e,n)=>n.recognizeFeatures(e,t)),projectEdges:(e,t,n,r)=>PS(e,(e,i)=>i.projectEdges(e,t,n,r)),getNurbsSurfaceData:e=>PS(e,(e,t)=>t.getNurbsSurfaceData?.(e)??null)}}var IS={hasErrors:!1,hasWarnings:!1,messages:[]};function LS(){return{modified:new Map,generated:new Map,deleted:new Set}}function RS(e){return{shape:e,evolution:LS()}}function zS(e){return{shape:e,evolution:LS(),diagnostics:IS}}function BS(e){let t=Ny(e),n=dy(e),r=$b(e);return{translateWithHistory:(e,n,r,i)=>RS(t.translate(e,n,r,i)),rotateWithHistory:(e,n,r,i,a,o)=>RS(t.rotate(e,n,a,o)),mirrorWithHistory:(e,n,r)=>RS(t.mirror(e,n,r)),scaleWithHistory:(e,n,r)=>RS(t.scale(e,n,r)),generalTransformWithHistory:(e,n,r,i)=>RS(t.generalTransform(e,n,r,i)),fuseWithHistory:(e,t,r,i,a)=>zS(n.fuse(e,t,a)),cutWithHistory:(e,t,r,i,a)=>zS(n.cut(e,t,a)),intersectWithHistory:(e,t,r,i,a)=>zS(n.intersect(e,t,a)),filletWithHistory:(e,t,n)=>RS(r.fillet(e,t,n)),chamferWithHistory:(e,t,n)=>RS(r.chamfer(e,t,n)),shellWithHistory:(e,t,n,i,a,o)=>RS(r.shell(e,t,n,o)),thickenWithHistory:(e,t)=>RS(r.thicken(e,t)),offsetWithHistory:(e,t,n,i,a)=>RS(r.offset(e,t,a)),draftWithHistory:(e,t,n,i,a)=>RS(r.draft(e,t,n,i,a)),applyComposedTransformWithHistory:(e,n)=>RS(t.transform(e,n))}}function VS(e){let t=e?.manifold;if(!t||typeof t.isEmpty==`function`&&t.isEmpty())return!1;if(typeof t.status==`function`){let e=t.status(),n=typeof e==`number`?e:Number(e?.value??e);if(!Number.isNaN(n)&&n!==0)return!1}return!0}function HS(e){return{isValid:e=>VS(e),isValidStrict:e=>VS(e),healSolid:e=>VS(e)?e:null,healFace:e=>e,healWire:e=>e,mergeCoincidentVertices:()=>0,removeDegenerateEdges:()=>0,fixFaceOrientations:()=>0,fixShape:e=>e,fixSelfIntersection:e=>e}}var US=`createPoint2d.createDirection2d.createVector2d.createAxis2d.wrapCurve2dHandle.createCurve2dAdaptor.makeLine2d.makeCircle2d.makeArc2dThreePoints.makeArc2dTangent.makeEllipse2d.makeEllipseArc2d.makeBezier2d.makeBSpline2d.evaluateCurve2d.evaluateCurve2dD1.getCurve2dBounds.getCurve2dType.trimCurve2d.reverseCurve2d.copyCurve2d.offsetCurve2d.translateCurve2d.rotateCurve2d.scaleCurve2d.mirrorCurve2dAtPoint.mirrorCurve2dAcrossAxis.affinityTransform2d.createIdentityGTrsf2d.createAffinityGTrsf2d.createTranslationGTrsf2d.createMirrorGTrsf2d.createRotationGTrsf2d.createScaleGTrsf2d.setGTrsf2dTranslationPart.multiplyGTrsf2d.transformCurve2dGeneral.intersectCurves2d.projectPointOnCurve2d.distanceBetweenCurves2d.approximateCurve2dAsBSpline.decomposeBSpline2dToBeziers.createBoundingBox2d.addCurveToBBox2d.getBBox2dBounds.mergeBBox2d.isBBox2dOut.isBBox2dOutPoint.getCurve2dCircleData.getCurve2dEllipseData.getCurve2dBezierPoles.getCurve2dBezierDegree.getCurve2dBSplineData.serializeCurve2d.deserializeCurve2d.splitCurve2d.liftCurve2dToPlane.buildEdgeOnSurface.extractSurfaceFromFace.extractCurve2dFromEdge.buildCurves3d.fixWireOnFace.fillSurface`.split(`.`);function WS(e){let t;try{t=U(`occt`)}catch{throw Error(`manifold: ${e} unsupported on manifold kernel; no B-rep kernel registered`)}return t}function GS(e){let t={};for(let e of US)t[e]=(...t)=>WS(e)[e](...t);return t}function KS(e){return{sketchNew:()=>z(`sketchNew`),sketchAddPoint:()=>z(`sketchAddPoint`),sketchAddArc:()=>z(`sketchAddArc`),sketchAddConstraint:()=>z(`sketchAddConstraint`),sketchSolve:()=>z(`sketchSolve`),sketchDof:()=>z(`sketchDof`)}}function qS(e){return{projectEdges:()=>z(`projectEdges`)}}function JS(e){return{dispose(e){let t=Zv(e);if(t){let e=ey.get(t.node);e!==void 0&&(Qv()?.dispose(e),ey.delete(t.node))}(e?.manifold)?.delete?.()},executeBatch:()=>z(`executeBatch`),checkpoint:()=>z(`checkpoint`),checkpointCount:()=>0,restoreCheckpoint:()=>z(`restoreCheckpoint`),discardCheckpoint:()=>z(`discardCheckpoint`)}}var YS=class{oc;kernelId=`manifold`;constructor(e){this.oc=e,Object.assign(this,oy(e),dy(e),Ny(e),Fy(e),Db(e),$b(e),sx(e),Jx(e),Xx(e),jS(e),FS(e),BS(e),HS(e),GS(e),KS(e),qS(e),JS(e))}};function XS(e){return`projectEdges`in e}function ZS(e){return`sketchNew`in e&&`sketchDof`in e}var QS=new Map,$S=null,eC=null;function tC(e){nC(`manifold`,new YS(e))}function nC(e,t){QS.set(e,t),$S||=e,e===$S&&(eC=t)}function U(e){if(!e&&eC)return eC;let t=e??$S;if(!t)throw Error(`brepjs kernel not initialized. Call initFromOC() or registerKernel() before using the library.`);let n=QS.get(t);if(!n)throw Error(`brepjs: kernel '${t}' is not registered.`);return n}function rC(e){let t=U(e);if(!qa(t))throw Error(`brepjs: current kernel does not support 2D operations.`);return t}function iC(){return $S}function aC(e,t){let n=$S;$S=e,eC=QS.get(e)??null;try{let e=t();if(e instanceof Promise)throw Error(`withKernel() callback returned a Promise. Async code must use getKernel(id) directly — the kernel override is restored synchronously in finally.`);return e}finally{$S=n,eC=n?QS.get(n)??null:null}}function oC(e){lo(),wc(),no(),ec(),tc(),gc(),_c();let t=new af(e);nC(`occt`,t),$S=`occt`,eC=t}function sC(){let e=U(),t=e.makeBox(1,1,1);try{e.dispose(t)}catch{}}async function cC(){if($S)return $S;try{let{OcctKernel:e}=await import(`occt-wasm`),t=await e.init();return nC(`occt-wasm`,ca.fromKernel(t)),`occt-wasm`}catch{}try{return oC(await(await import(`brepjs-opencascade`)).default()),`occt`}catch{}try{let e=await import(`brepkit-wasm`);return typeof e.default==`function`&&await e.default(),nC(`brepkit`,new Kv(new e.BrepKernel)),`brepkit`}catch{}throw Error(`brepjs: no kernel package found. Install one of:
|
|
11
11
|
npm install occt-wasm (recommended, default)
|
|
12
12
|
npm install brepjs-opencascade
|
|
13
|
-
npm install brepkit-wasm`)}function uC(){var e=typeof SuppressedError==`function`?SuppressedError:function(e,t){var n=Error();return n.name=`SuppressedError`,n.error=e,n.suppressed=t,n},t={},n=[];function r(e,t){if(t!=null){if(Object(t)!==t)throw TypeError(`using declarations can only be used with objects, functions, null, or undefined.`);if(e)var r=t[Symbol.asyncDispose||Symbol.for(`Symbol.asyncDispose`)];if(r===void 0&&(r=t[Symbol.dispose||Symbol.for(`Symbol.dispose`)],e))var i=r;if(typeof r!=`function`)throw TypeError(`Object is not disposable.`);i&&(r=function(){try{i.call(t)}catch(e){return Promise.reject(e)}}),n.push({v:t,d:r,a:e})}else e&&n.push({d:t,a:e});return t}return{e:t,u:r.bind(null,!1),a:r.bind(null,!0),d:function(){var r,i=this.e,a=0;function o(){for(;r=n.pop();)try{if(!r.a&&a===1)return a=0,n.push(r),Promise.resolve().then(o);if(r.d){var e=r.d.call(r.v);if(r.a)return a|=2,Promise.resolve(e).then(o,s)}else a|=1}catch(e){return s(e)}if(a===1)return i===t?Promise.resolve():Promise.reject(i);if(i!==t)throw i}function s(n){return i=i===t?n:new e(n,i),o()}return o()}}}var dC=Symbol;dC.dispose??=Symbol.for(`Symbol.dispose`),dC.asyncDispose??=Symbol.for(`Symbol.asyncDispose`);var fC=globalThis;fC.FinalizationRegistry||=(console.warn(`brepjs: FinalizationRegistry unavailable — garbage collection will not work`),class{register(e,t,n){}unregister(e){return!1}});var pC={liveHandles:0,peakHandles:0,gcCollected:0,scopeEnters:0,scopeExits:0};function mC(){return{...pC}}function hC(){pC.liveHandles=0,pC.peakHandles=0,pC.gcCollected=0,pC.scopeEnters=0,pC.scopeExits=0}function gC(){pC.liveHandles++,pC.liveHandles>pC.peakHandles&&(pC.peakHandles=pC.liveHandles)}function _C(){pC.liveHandles--}function vC(){pC.gcCollected++,pC.liveHandles--}var yC=new FinalizationRegistry(e=>{vC();try{e.delete()}catch{}});function bC(e){let t=!1,n=()=>{if(!t){t=!0,_C(),yC.unregister(r);try{e.delete()}catch{}}},r={get wrapped(){if(t)throw Error(`Shape handle has been disposed`);return e},get disposed(){return t},[Symbol.dispose](){n()},delete(){n()}};return gC(),yC.register(r,e,r),r}function xC(e){let t=!1,n={get value(){if(t)throw Error(`kernel handle has been disposed`);return e},get disposed(){return t},[Symbol.dispose](){if(!t){t=!0,_C(),yC.unregister(n);try{e.delete()}catch{}}}};return gC(),yC.register(n,e,n),n}var SC=class{handles=[];constructor(){pC.scopeEnters++}register(e){return this.handles.push(()=>{try{e.delete()}catch{}}),e}track(e){return this.handles.push(()=>{try{e[Symbol.dispose]()}catch{}}),e}[Symbol.dispose](){pC.scopeExits++;for(let e=this.handles.length-1;e>=0;e--)this.handles[e]?.();this.handles.length=0}};function CC(e){try{var t=uC();return e(t.u(new SC))}catch(e){t.e=e}finally{t.d()}}function wC(e,t){yC.register(e,t,t)}function TC(e){yC.unregister(e)}function EC(e){try{var t=uC();return e(t.u(new SC))}catch(e){t.e=e}finally{t.d()}}async function DC(e){try{var t=uC();return await e(t.u(new SC))}catch(e){t.e=e}finally{t.d()}}function OC(e){return!e.disposed}function kC(e){return e.__is2D!==!0}function AC(e){return e.__is2D===!0}function jC(e){if(!kC(e))throw Error(`Expected 3D shape, got 2D`);return e}function MC(e){if(!AC(e))throw Error(`Expected 2D shape, got 3D`);return e}var NC=new WeakMap;function PC(e,t){NC.set(e,t)}function FC(e,t){let n=NC.get(t);if(n!==void 0)return n;let r=e.shapeType(t);return NC.set(t,r),r}function IC(e){return FC(U(),e.wrapped)}function LC(e){return U().curveIsClosed(e.wrapped)}function RC(e){return U().isValid(e.wrapped)}function zC(e){let t=U();if(!t.isValid(e.wrapped))return!1;let n=t.isValidStrict?.bind(t)??t.isValid.bind(t);try{let r=t.solidFromShell(e.wrapped),i=n(r);try{t.dispose(r)}catch{}return i}catch{return!1}}function BC(e){return U().isValid(e.wrapped)}function VC(e){return LC(e)?O(e):k(`Wire is not closed: start and end points do not coincide`)}function HC(e){return RC(e)?O(e):k(`Face orientation is inconsistent or face is invalid`)}function UC(e){return zC(e)?O(e):k(`Shell is not manifold: has free edges or is invalid`)}function WC(e){return BC(e)?O(e):k(`Solid failed BRepCheck validation`)}function GC(e){return U().surfaceType(e.wrapped)===`plane`}function KC(e){let t=U(),n=n=>{try{let r=t.makeFace(e.wrapped,n),i=t.surfaceType(r);try{t.dispose(r)}catch{}return i===`plane`}catch{return!1}};return n(!0)?!0:n(!1)}function qC(e){return GC(e)?O(e):k(`Face is not planar: underlying surface is not a geometric plane`)}function JC(e){return KC(e)?O(e):k(`Wire is not planar: edges do not lie in a common plane`)}function YC(e,t){return t===`2D`&&(e.__is2D=!0),e}function XC(e,t){return YC(bC(e),t)}function ZC(e,t){return YC(bC(e),t)}function QC(e,t){return YC(bC(e),t)}function $C(e,t){return YC(bC(e),t)}function ew(e){return YC(bC(e))}function tw(e){return YC(bC(e))}function nw(e){return YC(bC(e))}function rw(e,t){return YC(bC(e),t)}function iw(e){return IC(e)===`vertex`}function aw(e){return IC(e)===`edge`}function ow(e){return IC(e)===`wire`}function sw(e){return IC(e)===`face`}function cw(e){return IC(e)===`shell`}function lw(e){return IC(e)===`solid`}function uw(e){return IC(e)===`compound`}function dw(e){let t=IC(e);return t===`shell`||t===`solid`||t===`compsolid`?!0:t===`compound`?kC(e):!1}function fw(e){let t=IC(e);return t===`edge`||t===`wire`}function W(e,t){let n=U(),r=FC(n,e),i=n.downcast(e,r);return r===`vertex`?XC(i,t):r===`edge`?ZC(i,t):r===`wire`?QC(i,t):r===`face`?$C(i,t):r===`shell`?ew(i):r===`solid`?tw(i):r===`compsolid`?nw(i):rw(i,t)}function pw(e){return W(e)}function mw(e,t,n){PC(e,t);let r=U().downcast(e,t);return t===`vertex`?XC(r,n):t===`edge`?ZC(r,n):t===`wire`?QC(r,n):t===`face`?$C(r,n):t===`shell`?ew(r):t===`solid`?tw(r):t===`compsolid`?nw(r):rw(r,n)}function hw(e,t,n,r,i){let a={kind:e,code:t,message:n,cause:r};return i?{...a,suggestion:i}:a}var gw={KERNEL_OPERATION:(e,t,n,r)=>hw(`KERNEL_OPERATION`,e,t,n,r),VALIDATION:(e,t,n,r)=>hw(`VALIDATION`,e,t,n,r),TYPE_CAST:(e,t,n,r)=>hw(`TYPE_CAST`,e,t,n,r),SKETCHER_STATE:(e,t,n,r)=>hw(`SKETCHER_STATE`,e,t,n,r),MODULE_INIT:(e,t,n,r)=>hw(`MODULE_INIT`,e,t,n,r),COMPUTATION:(e,t,n,r)=>hw(`COMPUTATION`,e,t,n,r),IO:(e,t,n,r)=>hw(`IO`,e,t,n,r),QUERY:(e,t,n,r)=>hw(`QUERY`,e,t,n,r),UNSUPPORTED:(e,t,n,r)=>hw(`UNSUPPORTED`,e,t,n,r)};function _w(e,t,n,r=`KERNEL_OPERATION`){try{return O(W(e()))}catch(e){let i=e instanceof Error?e.message:String(e),a=r===`KERNEL_OPERATION`?La(i):i,o=Ia(t);return k(gw[r](t,`${n}: ${a}`,e,o))}}function vw(e,t,n,r=`KERNEL_OPERATION`){try{return O(e())}catch(e){let i=e instanceof Error?e.message:String(e),a=r===`KERNEL_OPERATION`?La(i):i,o=Ia(t);return k(gw[r](t,`${n}: ${a}`,e,o))}}function yw(e,t,n,r=`KERNEL_OPERATION`){try{var i=uC();let a=i.u(new SC);return _w(()=>e(a),t,n,r)}catch(e){i.e=e}finally{i.d()}}function bw(e,t){let n=U().iterShapes(e,t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=mw(n[e],t);return r}var xw=new WeakMap;function Sw(e){let t=xw.get(e.wrapped);return t||(t={},xw.set(e.wrapped,t)),t}function Cw(e){return xw.get(e.wrapped)}function ww(e){xw.delete(e.wrapped)}function Tw(e){let t=Sw(e);if(t.edges)return t.edges;let n=bw(e.wrapped,`edge`);return t.edges=n,n}function Ew(e){let t=Sw(e);if(t.faces)return t.faces;let n=bw(e.wrapped,`face`);return t.faces=n,n}function Dw(e){let t=Sw(e);if(t.wires)return t.wires;let n=bw(e.wrapped,`wire`);return t.wires=n,n}function Ow(e){let t=Sw(e);if(t.vertices)return t.vertices;let n=bw(e.wrapped,`vertex`);return t.vertices=n,n}function kw(e){let t=Sw(e);if(t.solids)return t.solids;let n=bw(e.wrapped,`solid`);return t.solids=n,n}function Aw(e){let t=Sw(e);if(t.shells)return t.shells;let n=bw(e.wrapped,`shell`);return t.shells=n,n}function jw(e){let t=Sw(e);if(t.compSolids)return t.compSolids;let n=bw(e.wrapped,`compsolid`);return t.compSolids=n,n}function*Mw(e){for(let t of U().iterShapes(e.wrapped,`edge`))yield mw(t,`edge`)}function*Nw(e){for(let t of U().iterShapes(e.wrapped,`face`))yield mw(t,`face`)}function*Pw(e){for(let t of U().iterShapes(e.wrapped,`wire`))yield mw(t,`wire`)}function*Fw(e){for(let t of U().iterShapes(e.wrapped,`vertex`))yield mw(t,`vertex`)}function*Iw(e){for(let t of U().iterShapes(e.wrapped,`solid`))yield mw(t,`solid`)}function*Lw(e){for(let t of U().iterShapes(e.wrapped,`shell`))yield mw(t,`shell`)}function*Rw(e){for(let t of U().iterShapes(e.wrapped,`compsolid`))yield mw(t,`compsolid`)}function zw(e){let t=Sw(e);if(t.bounds)return t.bounds;let{min:n,max:r}=U().boundingBox(e.wrapped),i={xMin:n[0],xMax:r[0],yMin:n[1],yMax:r[1],zMin:n[2],zMax:r[2]};return t.bounds=i,i}function Bw(e){return FC(U(),e.wrapped)}function Vw(e){let t=Sw(e);if(t.surfaceType!==void 0)return t.surfaceType;let n=U().surfaceType(e.wrapped);return t.surfaceType=n,n}function Hw(e){let t=Sw(e);if(t.isValid!==void 0)return t.isValid;let n=U().isValid(e.wrapped);return t.isValid=n,n}function Uw(e){return{kind:Bw(e),faceCount:Ew(e).length,edgeCount:Tw(e).length,wireCount:Dw(e).length,vertexCount:Ow(e).length,valid:Hw(e),bounds:zw(e)}}function Ww(e){return U().vertexPosition(e.wrapped)}var G=2147483647,Gw=Math.PI/180,Kw=180/Math.PI;function qw(e){return e.length===2?[e[0],e[1],0]:[e[0],e[1],e[2]]}function Jw(e){return[e[0],e[1]]}var Yw={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function Xw(e){if(typeof e==`string`){let t=Yw[e];if(!t)throw Error(`Unknown direction: ${e}`);return t}return e}function Zw(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function Qw(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function $w(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function eT(e){return[-e[0],-e[1],-e[2]]}function tT(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function nT(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function rT(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function iT(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function aT(e,t){return rT(Qw(e,t))}function oT(e){let t=rT(e);return t<1e-10?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function sT(e,t,n=1e-5){return Math.abs(e[0]-t[0])<n&&Math.abs(e[1]-t[1])<n&&Math.abs(e[2]-t[2])<n}function cT(e,t=1e-10){return iT(e)<t*t}function lT(e,t){let n=tT(e,t),r=rT(e),i=rT(t);if(r<1e-10||i<1e-10)return 0;let a=Math.max(-1,Math.min(1,n/(r*i)));return Math.acos(a)}function uT(e,t,n){let r=Qw(e,t),i=iT(n);return i<1e-20?e:Qw(e,$w(n,tT(r,n)/i))}function dT(e,t,n){let r=oT(t),i=Math.cos(n),a=Math.sin(n),o=tT(e,r),s=nT(r,e);return[e[0]*i+s[0]*a+r[0]*o*(1-i),e[1]*i+s[1]*a+r[1]*o*(1-i),e[2]*i+s[2]*a+r[2]*o*(1-i)]}var fT=e=>Math.round(e*1e3)/1e3;function pT(e){return`x: ${fT(e[0])}, y: ${fT(e[1])}, z: ${fT(e[2])}`}function mT(e,t=null,n=[0,0,1]){let r=oT(n);if(cT(r))throw Error(`Plane normal must be non-zero`);let i;if(t)i=oT(t);else{let[e,t,n]=r,a=Math.abs(e),o=Math.abs(t),s=Math.abs(n),c;c=a<=o&&a<=s?[1,0,0]:o<=s?[0,1,0]:[0,0,1];let l=c[1]*n-c[2]*t,u=c[2]*e-c[0]*n,d=c[0]*t-c[1]*e;i=Math.sqrt(l*l+u*u+d*d)>1e-12?oT([l,u,d]):[1,0,0]}if(cT(i))throw Error(`Plane xDir must be non-zero`);let a=oT(nT(r,i));return{origin:e,xDir:i,yDir:a,zDir:r}}var hT={XY:{xDir:[1,0,0],normal:[0,0,1]},YZ:{xDir:[0,1,0],normal:[1,0,0]},ZX:{xDir:[0,0,1],normal:[0,1,0]},XZ:{xDir:[1,0,0],normal:[0,-1,0]},YX:{xDir:[0,1,0],normal:[0,0,-1]},ZY:{xDir:[0,0,1],normal:[-1,0,0]},front:{xDir:[1,0,0],normal:[0,0,1]},back:{xDir:[-1,0,0],normal:[0,0,-1]},left:{xDir:[0,0,1],normal:[-1,0,0]},right:{xDir:[0,0,-1],normal:[1,0,0]},top:{xDir:[1,0,0],normal:[0,1,0]},bottom:{xDir:[1,0,0],normal:[0,-1,0]}};function gT(e,t=[0,0,0]){let n=hT[e];if(!n)return k(F(`UNKNOWN_PLANE`,`Could not find plane ${e}`));let r;return r=typeof t==`number`?$w(n.normal,t):qw(t),O(mT(r,n.xDir,n.normal))}function _T(e,t){return typeof e==`string`?gT(e,t):O(e)}function vT(e,t){return e&&typeof e!=`string`?{...e}:j(_T(e??`XY`,t))}function yT(e,t){let[n,r]=t;return Zw(Zw(e.origin,$w(e.xDir,n)),$w(e.yDir,r))}function bT(e,t){return{...e,origin:Zw(e.origin,t)}}function xT(e,t,n=[1,0,0]){let r=t*Gw,i=dT(e.zDir,n,r),a=dT(e.xDir,n,r),o=oT(nT(i,a));return{origin:e.origin,xDir:a,yDir:o,zDir:i}}var ST={compound:0,solidCompound:1,solid:2,shell:3,face:4,wire:5,edge:6,vertex:7,shape:8},CT=e=>ST[e],wT={vertex:`vertex`,edge:`edge`,wire:`wire`,face:`face`,shell:`shell`,solid:`solid`,solidCompound:`compsolid`,compound:`compound`,shape:`compound`},TT=function*(e,t){let n=wT[t];if(n){let t=U().iterShapes(e,n);for(let e of t)yield e}},ET=e=>U().isNull(e)?k(za(`NULL_SHAPE`,`This shape has no type, it is null`)):O(e.ShapeType());function DT(e){if(U().isNull(e))return k(za(`NULL_SHAPE`,`This shape has no type, it is null`));try{return O(U().downcast(e))}catch{return k(za(`NO_WRAPPER`,`Could not find a wrapper for this shape type`))}}function OT(e){return U().isNull(e)?k(za(`NULL_SHAPE`,`Cannot cast a null shape`)):O(W(e))}function kT(e){return U().shapeType(e.wrapped)===`compsolid`}function AT(e){return OT(U().fromBREP(e))}var jT={plane:`PLANE`,cylinder:`CYLINDRE`,cone:`CONE`,sphere:`SPHERE`,torus:`TORUS`,bezier:`BEZIER_SURFACE`,bspline:`BSPLINE_SURFACE`,revolution:`REVOLUTION_SURFACE`,extrusion:`EXTRUSION_SURFACE`,offset:`OFFSET_SURFACE`,other:`OTHER_SURFACE`};function MT(e){return O(jT[Vw(e)])}function NT(e){return j(MT(e))}function PT(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function FT(e){return W(U().reverseShape(e.wrapped))}function IT(e){return U().uvBounds(e.wrapped)}function LT(e,t,n){let r=IT(e),i=t*(r.uMax-r.uMin)+r.uMin,a=n*(r.vMax-r.vMin)+r.vMin;return U().pointOnSurface(e.wrapped,i,a)}function RT(e,t){let n=qw(t);return U().uvFromPoint(e.wrapped,n)||[0,0]}function zT(e,t){let n=qw(t);try{let t=n,r=U().uvFromPoint(e.wrapped,t);if(!r)return k(za(`PROJECTION_FAILED`,`No projection found on the face`));let i=U().projectPointOnFace(e.wrapped,t),a=n[0]-i[0],o=n[1]-i[1],s=n[2]-i[2];return O({uv:r,point:i,distance:Math.sqrt(a*a+o*o+s*s)})}catch(e){return k(za(`PROJECTION_FAILED`,`Point projection failed: ${e instanceof Error?e.message:String(e)}`))}}function BT(e,t){let n,r;if(t)[n,r]=RT(e,t);else{let t=IT(e);n=.5*(t.uMin+t.uMax),r=.5*(t.vMin+t.vMax)}return U().surfaceNormal(e.wrapped,n,r)}function VT(e){return U().surfaceCenterOfMass(e.wrapped)}function HT(e,t,n=1e-6){let[r,i]=RT(e,t);return U().classifyPointOnFace(e.wrapped,r,i,n)}function UT(e){return W(U().outerWire(e.wrapped))}function WT(e){return W(U().removeHolesFromFace(e.wrapped))}function GT(e){let t=UT(e);return Array.from(TT(e.wrapped,`wire`)).map(e=>W(j(DT(e)))).filter(e=>!U().isSame(e.wrapped,t.wrapped))}function KT(e,t){let n=Sw(e),r=new Map;for(let n of Ew(e))r.set(U().hashCode(n.wrapped,G),t);n.faceOrigins=r}function qT(e){return Cw(e)?.faceOrigins}function JT(e,t,n){let r=new Map;for(let e of t){let t=qT(e);if(t)for(let[e,n]of t)r.set(e,n)}if(r.size===0)return;let i=new Map;for(let[t,n]of r){if(e.deleted.has(t))continue;let r=e.modified.get(t);if(r&&r.length>0)for(let e of r)i.set(e,n);else i.set(t,n);let a=e.generated.get(t);if(a)for(let e of a)i.has(e)||i.set(e,0)}if(i.size>0){let e=Sw(n);e.faceOrigins=i}}function YT(e,t,n){let r=-1/0,i;for(let a of n){let n=e[0]*a.normal[0]+e[1]*a.normal[1]+e[2]*a.normal[2];if(n<.707)continue;let o=t[0]-a.centroid[0],s=t[1]-a.centroid[1],c=t[2]-a.centroid[2],l=o*o+s*s+c*c;if(l>100)continue;let u=n-l/100;u>r&&(r=u,i=a.origin)}return i}function XT(e,t){let n=new Map;for(let t of e){let e=qT(t);if(e)for(let[t,r]of e)n.set(t,r)}if(n.size===0)return;let r=U(),i=new Map,a=Ew(t),o=[];for(let e of a){let t=r.hashCode(e.wrapped,G),a=n.get(t);a===void 0?o.push(e):i.set(t,a)}if(o.length>0){let t=[];for(let n of e){let e=qT(n);if(e)for(let i of Ew(n)){let n=r.hashCode(i.wrapped,G),a=e.get(n);if(a!==void 0)try{let e=r.uvBounds(i.wrapped),n=r.surfaceNormal(i.wrapped,.5*(e.uMin+e.uMax),.5*(e.vMin+e.vMax)),o=r.surfaceCenterOfMass(i.wrapped);t.push({origin:a,normal:n,centroid:o})}catch{}}}if(t.length>0)for(let e of o){let n=r.hashCode(e.wrapped,G);try{let a=r.uvBounds(e.wrapped),o=YT(r.surfaceNormal(e.wrapped,.5*(a.uMin+a.uMax),.5*(a.vMin+a.vMax)),r.surfaceCenterOfMass(e.wrapped),t);o!==void 0&&i.set(n,o)}catch{}}}if(i.size>0){let e=Sw(t);e.faceOrigins=i}}var ZT=new WeakMap,QT=new WeakMap;function $T(e){return ZT.has(e.wrapped)}function eE(e){let t=ZT.get(e.wrapped);return t||(t=new Map,ZT.set(e.wrapped,t)),t}function tE(e){let t=QT.get(e.wrapped);return t||(t=new Map,QT.set(e.wrapped,t)),t}function nE(e,t,n){let r=Array.isArray(t)?t:Ew(e).filter(t),i=eE(e),a=i.get(n)??new Set;for(let e of r)a.add(U().hashCode(e.wrapped,G));return i.set(n,a),e}function rE(e,t){let n=ZT.get(e.wrapped);if(!n)return[];let r=n.get(t);if(!r||r.size===0)return[];let i=[];for(let t of Ew(e)){let e=U().hashCode(t.wrapped,G);r.has(e)&&i.push(t)}return i}function iE(e){let t=new Map,n=ZT.get(e.wrapped);if(!n)return t;let r=Ew(e),i=new Map;for(let e of r)i.set(U().hashCode(e.wrapped,G),e);for(let[e,r]of n){let n=[];for(let e of r){let t=i.get(e);t&&n.push(t)}n.length>0&&t.set(e,n)}return t}function aE(e,t,n){return tE(e).set(t,n),e}function oE(e,t){return QT.get(e.wrapped)?.get(t)}function sE(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function cE(e,t,n){let r=eE(n);for(let i of t){let t=ZT.get(i.wrapped);if(!t)continue;let a=new Map;for(let[e,n]of t)for(let t of n){let n=a.get(t)??[];n.push(e),a.set(t,n)}for(let[t,n]of a){if(e.deleted.has(t))continue;let i=e.modified.get(t),a=i&&i.length>0?i:[t];for(let e of a)for(let t of n)sE(r,t,e)}let o=QT.get(i.wrapped);if(o){let e=tE(n);for(let[t,n]of o)e.has(t)||e.set(t,n)}}}var lE=new WeakMap,uE=new WeakMap;function dE(e){return lE.has(e.wrapped)||uE.has(e.wrapped)}function fE(e){let t=uE.get(e.wrapped);return t||(t=new Map,uE.set(e.wrapped,t)),t}function pE(e){if(typeof e==`string`){let t=e.startsWith(`#`)?e.slice(1):e;return t.length===3&&(t=t.charAt(0)+t.charAt(0)+t.charAt(1)+t.charAt(1)+t.charAt(2)+t.charAt(2)),[parseInt(t.slice(0,2),16)/255,parseInt(t.slice(2,4),16)/255,parseInt(t.slice(4,6),16)/255,1]}return e.length===3?[e[0],e[1],e[2],1]:[e[0],e[1],e[2],e[3]]}function mE(e,t){return lE.set(e.wrapped,pE(t)),e}function hE(e,t,n){let r=pE(n),i=fE(e);for(let e of t)i.set(U().hashCode(e.wrapped,G),r);return e}function gE(e){return lE.get(e.wrapped)}function _E(e,t){let n=uE.get(e.wrapped);if(n)return n.get(U().hashCode(t.wrapped,G))}function vE(e,t,n){for(let e of t){let t=lE.get(e.wrapped);if(t){lE.set(n.wrapped,t);break}}let r=fE(n);for(let n of t){let t=uE.get(n.wrapped);if(!(!t||t.size===0))for(let[n,i]of t){if(e.deleted.has(n))continue;let t=e.modified.get(n);if(t&&t.length>0)for(let e of t)r.set(e,i);else r.set(n,i)}}}function yE(e){if(!e.some(e=>qT(e)!==void 0||$T(e)||dE(e)))return[];let t=U(),n=[];for(let r of e){let e=t.iterShapes(r.wrapped,`face`);for(let r of e)n.push(t.hashCode(r,G))}return n}function bE(e,t,n){JT(e,t,n),cE(e,t,n),vE(e,t,n)}function xE(e,t){XT(e,t)}function SE(e,t){let n=yE([e]),{shape:r,evolution:i}=U().translateWithHistory(e.wrapped,t[0],t[1],t[2],n,G),a=W(r);return bE(i,[e],a),a}function CE(e,t,n=[0,0,0],r=[0,0,1]){let i=yE([e]),{shape:a,evolution:o}=U().rotateWithHistory(e.wrapped,t*Gw,i,G,r,n),s=W(a);return bE(o,[e],s),s}function wE(e,t=[0,1,0],n=[0,0,0]){let r=yE([e]),{shape:i,evolution:a}=U().mirrorWithHistory(e.wrapped,n,t,r,G),o=W(i);return bE(a,[e],o),o}function TE(e,t,n=[0,0,0]){let r=yE([e]),{shape:i,evolution:a}=U().scaleWithHistory(e.wrapped,n,t,r,G),o=W(i);return bE(a,[e],o),o}function EE(e,t,n){let r=U().boundingBox(e.wrapped),i=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]],a=n?.auto===!0;function o(e,t,n){return e!==void 0&&t>1e-12?e/t:e===void 0&&a?n:1}let s=1;a&&(t[0]!==void 0&&i[0]>1e-12?s=t[0]/i[0]:t[1]!==void 0&&i[1]>1e-12?s=t[1]/i[1]:t[2]!==void 0&&i[2]>1e-12&&(s=t[2]/i[2]));let c=[o(t[0],i[0],s),o(t[1],i[1],s),o(t[2],i[2],s)];return Math.abs(c[0]-c[1])<1e-6&&Math.abs(c[1]-c[2])<1e-6?O(TE(e,c[0])):k(F(N.VALIDATION_FAILED,`resize: non-uniform scaling is not supported (WASM build lacks BRepBuilderAPI_GTransform).`,void 0,void 0,`Use auto: true to scale proportionally, or set all three dimensions to achieve uniform scaling.`))}function DE(e){if(`linear`in e)return O({linear:e.linear,translation:e.translation});let[t,n,r,i]=e,a=1e-10;return Math.abs(i[0])>a||Math.abs(i[1])>a||Math.abs(i[2])>a||Math.abs(i[3]-1)>a?k(F(N.VALIDATION_FAILED,`applyMatrix: invalid bottom row [${String(i[0])}, ${String(i[1])}, ${String(i[2])}, ${String(i[3])}]. Must be [0, 0, 0, 1] for an affine transform.`)):O({linear:[t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]],translation:[t[3],n[3],r[3]]})}function OE(e){return e[0]*(e[4]*e[8]-e[5]*e[7])-e[1]*(e[3]*e[8]-e[5]*e[6])+e[2]*(e[3]*e[7]-e[4]*e[6])}function kE(e){let t=1e-8,n=e[0]*e[0]+e[3]*e[3]+e[6]*e[6],r=e[1]*e[1]+e[4]*e[4]+e[7]*e[7],i=e[2]*e[2]+e[5]*e[5]+e[8]*e[8],a=e[0]*e[1]+e[3]*e[4]+e[6]*e[7],o=e[0]*e[2]+e[3]*e[5]+e[6]*e[8],s=e[1]*e[2]+e[4]*e[5]+e[7]*e[8];return!(Math.abs(a)>t||Math.abs(o)>t||Math.abs(s)>t||Math.abs(n-r)>t||Math.abs(n-i)>t)}function AE(e,t){let n=DE(t);if(!n.ok)return n;let{linear:r,translation:i}=n.value,a=OE(r);if(Math.abs(a)<1e-12)return k(F(N.VALIDATION_FAILED,`applyMatrix: singular matrix (determinant ≈ 0). Cannot apply a non-invertible transform.`));if(kE(r)){let t=yE([e]),{shape:n,evolution:a}=U().generalTransformWithHistory(e.wrapped,r,i,!0,t,G),o=W(n);return bE(a,[e],o),O(o)}let o=W(U().generalTransformNonOrthogonal(e.wrapped,r,i));return xE([e],o),O(o)}function jE(e){let t=e.map(e=>e.type===`translate`?{type:`translate`,x:e.v[0],y:e.v[1],z:e.v[2]}:{type:`rotate`,angle:e.angle,axis:e.axis,center:e.center}),{handle:n,dispose:r}=U().composeTransform(t);return{trsf:n,cleanup:r}}function ME(e,t){let n=yE([e]),{shape:r,evolution:i}=U().applyComposedTransformWithHistory(e.wrapped,t.trsf,n,G),a=W(r);return bE(i,[e],a),a}function NE(e){return _w(()=>U().downcast(e.wrapped),N.CLONE_FAILED,`Failed to clone shape`)}function PE(e){return vw(()=>U().toBREP(e.wrapped),N.TO_BREP_FAILED,`Failed to serialize shape to BREP`)}function FE(e){return U().hashCode(e.wrapped,G)}function IE(e){return U().isNull(e.wrapped)}function LE(e,t){return U().isSame(e.wrapped,t.wrapped)}function RE(e,t){return U().isEqual(e.wrapped,t.wrapped)}function zE(e){return _w(()=>U().simplify(e.wrapped),N.SIMPLIFY_FAILED,`Failed to simplify shape`)}function BE(e){return U().curveType(e.wrapped)}function VE(e){let[t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function HE(e){let[,t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function UE(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curvePointAtParam(e.wrapped,i)}function WE(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curveTangent(e.wrapped,i).tangent}function GE(e){return U().length(e.wrapped)}function KE(e){return U().curveIsClosed(e.wrapped)}function qE(e){return U().curveIsPeriodic(e.wrapped)}function JE(e){return U().curvePeriod(e.wrapped)}function YE(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function XE(e){return W(U().reverseShape(e.wrapped))}function ZE(e,t={}){if(e.length<2)return k(za(`INTERPOLATE_MIN_POINTS`,`Interpolation requires at least 2 points`));try{let n=W(U().interpolatePoints(e,t));return aw(n)?O(n):k(za(`INTERPOLATE_NOT_EDGE`,`Interpolation did not produce an edge`))}catch(e){return k(za(`INTERPOLATE_FAILED`,`Interpolation failed: ${e instanceof Error?e.message:String(e)}`))}}function QE(e,t={}){if(e.length<2)return k(za(`APPROXIMATE_MIN_POINTS`,`Approximation requires at least 2 points`));try{let n=W(U().approximatePoints(e,t));return aw(n)?O(n):k(za(`APPROXIMATE_NOT_EDGE`,`Approximation did not produce an edge`))}catch(e){return k(za(`APPROXIMATE_FAILED`,`Approximation failed: ${e instanceof Error?e.message:String(e)}`))}}function $E(e,t,n=`arc`){let r=W(U().offsetWire2D(e.wrapped,t,{arc:`arc`,intersection:`intersection`,tangent:`tangent`,chamfer:`intersection`}[n]));return ow(r)?O(r):(r[Symbol.dispose](),k(za(`OFFSET_NOT_WIRE`,`Offset did not produce a Wire`)))}function eD(e,t,n,r=!1){return`${e}:${t}:${n}:${r}`}function tD(e,t){return`edge:${e}:${t}`}var nD=new WeakMap,rD=new WeakMap;function iD(e,t){let n=nD.get(e);if(n)return n.get(t)}function aD(e,t,n){let r=nD.get(e);r||(r=new Map,nD.set(e,r)),r.set(t,n)}function oD(e,t){let n=rD.get(e);if(n)return n.get(t)}function sD(e,t,n){let r=rD.get(e);r||(r=new Map,rD.set(e,r)),r.set(t,n)}function cD(){nD=new WeakMap,rD=new WeakMap}function lD(){let e=new WeakMap,t=new WeakMap;return{getMesh(t,n){return e.get(t)?.get(n)},setMesh(t,n,r){let i=e.get(t);i||(i=new Map,e.set(t,i)),i.set(n,r)},getEdgeMesh(e,n){return t.get(e)?.get(n)},setEdgeMesh(e,n,r){let i=t.get(e);i||(i=new Map,t.set(e,i)),i.set(n,r)},clear(){e=new WeakMap,t=new WeakMap}}}function uD(e,{tolerance:t=.001,angularTolerance:n=.1,skipNormals:r=!1,includeUVs:i=!1,cache:a=!0,signal:o}={}){o?.throwIfAborted();let s=eD(t,n,r,i);if(a){let t=iD(e.wrapped,s);if(t)return t}let c=U().mesh(e.wrapped,{tolerance:t,angularTolerance:n,skipNormals:r,includeUVs:i,...o?{signal:o}:{}}),l=qT(e),u={vertices:c.vertices,normals:c.normals,triangles:c.triangles,uvs:c.uvs,faceGroups:c.faceGroups.map(e=>({start:e.start,count:e.count,faceId:e.faceHash,origin:l?.get(e.faceHash)??0}))};return a&&aD(e.wrapped,s,u),u}function dD(e,{tolerance:t=.001,angularTolerance:n=.1,cache:r=!0}={}){let i=tD(t,n);if(r){let t=oD(e.wrapped,i);if(t)return t}let a=U().meshEdges(e.wrapped,t,n),o={lines:a.lines,edgeGroups:a.edgeGroups.map(e=>({start:e.start,count:e.count,edgeId:e.edgeHash}))};return r&&sD(e.wrapped,i,o),o}function fD(e,t){return e instanceof Error&&e.message.startsWith(`${t} export failed`)?Ua(`${t}_EXPORT_FAILED`,`Failed to write ${t} file`,e):e instanceof WebAssembly.RuntimeError?Ua(`${t}_EXPORT_CRASHED`,`${t} export crashed the kernel (${e.message}); the shape likely contains geometry the ${t} writer cannot serialize`,e):Ua(`${t}_FILE_READ_ERROR`,`Failed to read exported ${t} file`,e)}function pD(e){let t;try{t=kw(e)}catch{return``}if(t.length<=1)return``;let n=[];return t.forEach((e,t)=>{try{zw(e)}catch(e){if(e instanceof TypeError)throw e;n.push(t)}}),n.length===0?`; could not localize the offending sub-solid among ${t.length} solids`:`; offending sub-solid${n.length>1?`s`:``} (of ${t.length}): index ${n.join(`, `)}`}function mD(e,t){try{return zw(e),null}catch(n){if(n instanceof TypeError)throw n;return Ua(`${t}_EXPORT_UNSERIALIZABLE`,`${t} export aborted: the shape contains degenerate geometry the ${t} writer cannot serialize (bounding-box evaluation failed); export was skipped to avoid crashing the kernel${pD(e)}`,n)}}function hD(e){let t=mD(e,`STEP`);if(t)return k(t);try{let t=U().exportSTEP([e.wrapped]);return O(new Blob([t],{type:`application/STEP`}))}catch(e){return k(fD(e,`STEP`))}}function gD(e,{tolerance:t=.001,angularTolerance:n=.1,binary:r=!1}={}){let i=mD(e,`STL`);if(i)return k(i);try{U().hasTriangulation(e.wrapped)||U().meshShape(e.wrapped,t,n);let i=U().exportSTL(e.wrapped,r,t,n);return O(new Blob([i],{type:`application/sla`}))}catch(e){return k(fD(e,`STL`))}}function _D(e){try{let t=U().exportIGES([e.wrapped]);return O(new Blob([t],{type:`application/iges`}))}catch(e){return k(Ua(`IGES_EXPORT_FAILED`,`Failed to write IGES file`,e))}}function vD(e,t){let n=t?.coarseTolerance??.5,r=t?.fineTolerance??.05,i=t?.angularTolerance??.5;return{coarse:uD(e,{tolerance:n,angularTolerance:i}),fine:uD(e,{tolerance:r,angularTolerance:i*.2})}}function yD(e,t,n){if(t<0||t>=e.length)throw Error(n??`Index ${t} out of bounds (length ${e.length})`);return e[t]}function bD(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[0]}function xD(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[e.length-1]}function SD(e){return Array.from(Array(e).keys())}function CD(e){return SD(Math.min(...e.map(e=>e.length))).map(t=>e.map(e=>e[t]))}function wD(e,t){return ZC(U().makeLineEdge([...e],[...t]))}function TD(e,t=[0,0,0],n=[0,0,1]){return ZC(U().makeCircleEdge([...t],[...n],e))}function ED(e,t,n=[0,0,0],r=[0,0,1],i){return t>e?k(F(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(ZC(U().makeEllipseEdge([...n],[...r],e,t,i?[...i]:void 0)))}function DD(e,t,n,r=[0,0,0],i=[0,0,1],a=!1){return QC(U().makeHelixWire(e,t,n,[...r],[...i],a))}function OD(e,t,n){return ZC(U().makeArcEdge([...e],[...t],[...n]))}function kD(e,t,n,r,i=[0,0,0],a=[0,0,1],o){return t>e?k(F(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(ZC(U().makeEllipseArc([...i],[...a],e,t,n,r,o?[...o]:void 0)))}function AD(e,{tolerance:t=.001,smoothing:n=null,degMax:r=6,degMin:i=1}={}){try{let a=e.map(e=>[...e]);return O(ZC(U().approximatePoints(a,{tolerance:t,degMin:i,degMax:r,smoothing:n})))}catch{return k(P(`BSPLINE_FAILED`,`B-spline approximation failed`))}}function jD(e,{periodic:t=!1,tolerance:n=1e-7}={}){try{let r=e.map(e=>[...e]);return O(ZC(U().interpolatePoints(r,{periodic:t,tolerance:n})))}catch{return k(P(`BSPLINE_INTERP_FAILED`,`B-spline interpolation failed`))}}function MD(e){if(e.length<2)return k(F(`BEZIER_MIN_POINTS`,`Need at least 2 points for a Bezier curve, got ${e.length}`,void 0,{pointCount:e.length}));let t=e.map(e=>[...e]);return O(ZC(U().makeBezierEdge(t)))}function ND(e,t,n){return ZC(U().makeTangentArc([...e],[...t],[...n]))}function PD(e){try{return O(QC(U().makeWireFromMixed(e.map(e=>e.wrapped))))}catch(e){return k(P(`WIRE_BUILD_FAILED`,`Failed to build the wire: ${e instanceof Error?e.message:`unknown error`}`))}}function FD(e,t){try{let n=U().makeFace(e.wrapped,!0);if(t&&t.length>0){let e=zD($C(n),t);return GC(e)?O(e):k(F(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}let r=$C(n);return GC(r)?O(r):k(F(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}catch{return k(P(`FACE_BUILD_FAILED`,`Failed to build the face. Your wire might be non planar.`))}}function ID(e){return FD(UT(e))}function LD(e,t){return $C(U().makeFaceOnSurface(e.wrapped,t.wrapped))}function RD(e){try{return pa(OT(U().makeNonPlanarFace(e.wrapped)),e=>sw(e)?O(e):k(P(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`)))}catch{return k(P(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`))}}function zD(e,t){return $C(U().addHolesInFace(e.wrapped,t.map(e=>e.wrapped)))}function BD(e){return e.length<3?k(F(`POLYGON_MIN_POINTS`,`You need at least 3 points to make a polygon`)):pa(PD(CD([e,[...e.slice(1),e[0]]]).map(([e,t])=>wD(e,t))),e=>FD(e))}function VD(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function HD(e,t,n,r,i){let a=W(e);if(!dw(a)){let o=e.ShapeType(),s=[`COMPOUND`,`COMPSOLID`,`SOLID`,`SHELL`,`FACE`,`WIRE`,`EDGE`,`VERTEX`,`SHAPE`][o]??`UNKNOWN(${o})`;return a[Symbol.dispose](),k(za(t,`${n}. Got ${s} instead.`,void 0,i?{diagnostics:i}:void 0,r))}return O(a)}function UD(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;let c=VD(e,`fuse: first operand`);if(A(c))return c;let l=VD(t,`fuse: second operand`);if(A(l))return l;if(!s)return HD(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);let u=yE([e,t]),{shape:d,evolution:f,diagnostics:p}=U().fuseWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(U().isNull(d))return U().dispose(d),console.warn(`brepjs: fuse history path produced null result; retrying without evolution tracking.`,p),HD(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);console.warn(`brepjs: fuse reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=HD(d,`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`,`Common causes: overlapping coplanar faces, zero-thickness geometry, or non-manifold input. Try autoHeal() on inputs first.`,p);return m.ok&&bE(f,[e,t],m.value),m}function WD(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;let c=VD(e,`cut: base`);if(A(c))return c;let l=VD(t,`cut: tool`);if(A(l))return l;if(!s)return HD(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);let u=yE([e,t]),{shape:d,evolution:f,diagnostics:p}=U().cutWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(U().isNull(d))return U().dispose(d),console.warn(`brepjs: cut history path produced null result; retrying without evolution tracking.`,p),HD(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);console.warn(`brepjs: cut reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=HD(d,`CUT_NOT_3D`,`Cut did not produce a 3D shape`,`Common causes: tool does not fully intersect the base, or produces a zero-thickness sliver. Ensure the tool extends through the shape.`,p);return m.ok&&bE(f,[e,t],m.value),m}function GD(e,t,{simplify:n=!1,signal:r,fuzzyValue:i,unsafe:a,trackEvolution:o=!0}={}){if(r?.aborted)throw r.reason;let s=VD(e,`intersect: first operand`);if(A(s))return s;let c=VD(t,`intersect: second operand`);if(A(c))return c;if(!o)return HD(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);let l=yE([e,t]),{shape:u,evolution:d,diagnostics:f}=U().intersectWithHistory(e.wrapped,t.wrapped,l,G,{simplify:n,fuzzyValue:i});if(f.hasErrors){if(U().isNull(u))return U().dispose(u),console.warn(`brepjs: intersect history path produced null result; retrying without evolution tracking.`,f),HD(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);console.warn(`brepjs: intersect reported OCCT warnings/errors but produced a shape. Continuing with result.`,f)}let p=HD(u,`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`,`Shapes may not overlap. Verify they share a common volume before intersecting.`,f);return p.ok&&bE(d,[e,t],p.value),p}function KD(e,t,n,r,i,a,o,s){if(o?.aborted)throw o.reason;let c=n-t;if(c===1)return O(yD(e,t));if(c===2)return UD(yD(e,t),yD(e,t+1),{optimisation:r,simplify:!1,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}});let l=t+Math.ceil(c/2),u=KD(e,t,l,r,i,a,o,s);if(A(u))return u;let d=KD(e,l,n,r,i,a,o,s);return A(d)?d:UD(u.value,d.value,{optimisation:r,simplify:i,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}})}function qD(e,{optimisation:t=`none`,simplify:n=!1,strategy:r=`native`,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;if(e.length===0)return k(F(`FUSE_ALL_EMPTY`,`fuseAll requires at least one shape`));if(e.length===1)return O(bD(e));for(let t=0;t<e.length;t++){let n=VD(yD(e,t),`fuseAll: shape at index ${t}`);if(A(n))return n}if(r===`native`){let o=HD(U().fuseAll(e.map(e=>e.wrapped),{optimisation:t,simplify:n,strategy:r,fuzzyValue:a,...i?{signal:i}:{}}),`FUSE_ALL_NOT_3D`,`fuseAll did not produce a 3D shape`);return o.ok&&s&&xE(e,o.value),o}return KD(e,0,e.length,t,n,s,i,a)}function JD(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;if(t.length===0)return O(e);let c=VD(e,`cutAll: base`);if(A(c))return c;for(let e=0;e<t.length;e++){let n=VD(yD(t,e),`cutAll: tool at index ${e}`);if(A(n))return n}let l=[e,...t],u=HD(U().cutAll(e.wrapped,t.map(e=>e.wrapped),{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_ALL_NOT_3D`,`cutAll did not produce a 3D shape`);return u.ok&&s&&xE(l,u.value),u}function YD(e,t){let n=U(),r=$w(e.xDir,t),i=$w(e.yDir,t),a=$w(e.xDir,-t),o=$w(e.yDir,-t),s=e.origin,c=[...Zw(Zw(s,a),o)],l=[...Zw(Zw(s,r),o)],u=[...Zw(Zw(s,r),i)],d=[...Zw(Zw(s,a),i)],f=[n.makeLineEdge(c,l),n.makeLineEdge(l,u),n.makeLineEdge(u,d),n.makeLineEdge(d,c)],p=n.makeWire(f),m=n.makeFace(p,!0);for(let e of f)e.delete();return p.delete(),m}function XD(e,t,{approximation:n=!0,planeSize:r=1e4}={}){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`section: shape is a null shape`));let i=YD(typeof t==`string`?j(_T(t)):t,r);try{return O(W(U().section(e.wrapped,i,n)))}catch(e){let n=e instanceof Error?e.message:String(e),r=typeof t==`string`?t:`custom`;return k(P(`SECTION_FAILED`,`Section with ${r} plane failed: ${n}`,e,{operation:`section`,plane:r},`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`))}finally{i.delete()}}function ZD(e){let t=U(),n=new Map,r=new Map;for(let i of e){let e=Ow(i),a=e[0]?t.hashCode(e[0].wrapped,G):-1,o=e.length>1&&e[1]?t.hashCode(e[1].wrapped,G):a;r.set(i,[a,o]);for(let e of[a,o]){let t=n.get(e)??[];t.push(i),n.set(e,t)}}return{vertexToEdges:n,edgeVertexHashes:r}}function QD(e,t,n){let r=t.vertexToEdges.get(e);if(r)for(let i of r){if(n.has(i))continue;let r=t.edgeVertexHashes.get(i);if(r)return n.add(i),{edge:i,nextTip:r[0]===e?r[1]:r[0]}}}function $D(e,t,n){n.add(e);let r=[e],i=t.edgeVertexHashes.get(e);if(!i)return r;let a=[i[1],i[0]];for(let e=0;e<2;e++){let i=a[e];if(i===void 0)continue;let o=QD(i,t,n);for(;o;)e===0?r.push(o.edge):r.unshift(o.edge),i=o.nextTip,o=QD(i,t,n)}return r}function eO(e){let t=U(),n=ZD(e),r=new Set,i=[];for(let a of e){if(r.has(a))continue;let e=$D(a,n,r);try{let n=t.makeWire(e.map(e=>e.wrapped));i.push(W(n))}catch{}}return i}function tO(e){let t=U(),n=0,r=-1;for(let i=0;i<e.length;i++){let a=e[i];if(!a)continue;let o=t.boundingBox(a.wrapped),s=o.max[0]-o.min[0],c=o.max[1]-o.min[1],l=o.max[2]-o.min[2],u=s*s+c*c+l*l;u>r&&(r=u,n=i)}return n}function nO(e,t,n={}){let r=XD(e,t,n);if(!r.ok)return r;let i=Dw(r.value);if(i.length===0){let e=Tw(r.value);if(e.length===0)return k(P(`SECTION_FAILED`,`sectionToFace: section produced no geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));i.push(...eO(e))}if(i.length===0)return k(P(`SECTION_FAILED`,`sectionToFace: section produced no usable geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));let a=tO(i),o=yD(i,a),s=i.filter((e,t)=>t!==a);return FD(o,s.length>0?s:void 0)}function rO(e,t){if(t.length===0)return O(e);if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`split: shape is a null shape`));for(let e=0;e<t.length;e++)if(U().isNull(yD(t,e).wrapped))return k(F(N.NULL_SHAPE_INPUT,`splitShape: tool at index ${e} is a null shape`));try{return O(W(U().split(e.wrapped,t.map(e=>e.wrapped))))}catch(e){let n=e instanceof Error?e.message:String(e);return k(P(`SPLIT_FAILED`,`Split operation failed on ${t.length} tool(s): ${n}`,e,{operation:`split`,toolCount:t.length},`The splitting tools may not intersect the shape. Ensure tools cross through the shape's interior.`))}}function iO(e,t,n={}){let r=[];for(let i of t){let t=XD(e,i,n);if(A(t))return t;r.push(t.value)}return O(r)}function aO(e,t,n){if(t.length===0)return O(e);let r=n?.optimisation===`commonFace`?1:n?.optimisation===`sameFace`?2:0,i=U(),a=t.map(e=>({op:e.op,tool:e.tool.wrapped}));try{let o=i.booleanPipeline?.(e.wrapped,a,{glueMode:r});if(o===void 0)return oO(e,t,n);if(o===null)return k(P(`BOOLEAN_PIPELINE_FAILED`,`Boolean pipeline returned null shape`));let s=W(o);return dw(s)?O(s):k(za(`BOOLEAN_PIPELINE_NOT_3D`,`Pipeline result is not a 3D shape`))}catch(e){return k(P(`BOOLEAN_PIPELINE_FAILED`,e instanceof Error?e.message:String(e)))}}function oO(e,t,n){let r=e,i={...n?.optimisation?{optimisation:n.optimisation}:{},unsafe:!0};for(let e of t){let t=e.op===`fuse`?UD(r,e.tool,i):e.op===`cut`?WD(r,e.tool,i):GD(r,e.tool,i);if(A(t))return t;r=j(t)}return O(r)}function sO(e){return j(OT(j(DT(U().sew(e.map(e=>e.wrapped))))))}function cO(e,t=!1){let n=sO(e);return!t&&!cw(n)?k(za(`WELD_NOT_SHELL`,`Could not make a shell from faces and shells`)):O(n)}function lO(e,t,n=[0,0,0],r=[0,0,1]){return tw(U().makeCylinder(e,t,[...n],[...r]))}function uO(e){return tw(U().makeSphere(e))}function dO(e,t,n,r=[0,0,0],i=[0,0,1]){return tw(U().makeCone(e,t,n,[...r],[...i]))}function fO(e,t,n=[0,0,0],r=[0,0,1]){return tw(U().makeTorus(e,t,[...n],[...r]))}function pO(e,t,n){return tw(U().makeEllipsoid(e,t,n))}function mO(e){return XC(U().makeVertex(e[0],e[1],e[2]))}function hO(e,t,n=1e-6){return pa(DT(U().offset(e.wrapped,t,n)),e=>pa(OT(e),e=>dw(e)?O(e):k(za(`OFFSET_NOT_3D`,`Could not offset to a 3d shape`))))}function gO(e){return rw(U().makeCompound(e.map(e=>e.wrapped)))}function _O(e){let t=sO(e);return pa(OT(U().solidFromShell(t.wrapped)),e=>lw(e)?O(e):k(za(`SOLID_BUILD_FAILED`,`Could not make a solid of faces and shells`)))}function vO(e){return{position:e.vertices,normal:e.normals,index:e.triangles}}function yO(e){return{position:e.vertices,normal:e.normals,index:e.triangles,groups:e.faceGroups.map((e,t)=>({start:e.start,count:e.count,materialIndex:t,faceId:e.faceId}))}}function bO(e){return{position:e.lines}}function xO(e,t){return{coarse:vO(e.coarse),fine:vO(e.fine),coarseDistance:t?.coarse??50,fineDistance:t?.fine??0}}function SO(e,t,n,r){if(t.length===0)return k(F(`CHAMFER_ANGLE_NO_EDGES`,`chamferDistAngle requires at least one edge`,void 0,{edgeCount:0}));if(n<=0)return k(F(`CHAMFER_ANGLE_BAD_DISTANCE`,`distance must be positive, got ${n}`,void 0,{distance:n}));if(r<=0||r>=90)return k(F(`CHAMFER_ANGLE_BAD_ANGLE`,`angleDeg must be in range (0, 90), got ${r}`,void 0,{angleDeg:r}));let i;try{let a=U(),o=t.map(e=>e.wrapped);i=a.chamferDistAngle(e.wrapped,o,n,r)}catch(e){return k(P(`CHAMFER_ANGLE_FAILED`,`chamferDistAngle kernel call failed: ${e instanceof Error?e.message:String(e)}`,e,{distance:n,angleDeg:r,edgeCount:t.length}))}let a=DT(i);if(A(a))return a;let o=W(a.value);return dw(o)?O(o):(o[Symbol.dispose](),k(za(`CHAMFER_ANGLE_NOT_3D`,`chamferDistAngle did not produce a 3D shape`)))}function CO(e,t){return e.map(e=>mw(e,t))}function wO(e,t){let n=U(),r=n.iterShapes(e,t),i=[],a=new Map;for(let e of r){let t=n.hashCode(e,G),r=a.get(t);r?r.some(t=>n.isSame(t,e))||(r.push(e),i.push(e)):(a.set(t,[e]),i.push(e))}return CO(i,t)}function TO(e){let t=Sw(e);if(t.edgeToFaces)return t.edgeToFaces;let n=U(),r=new Map,i=n.iterShapes(e.wrapped,`face`);for(let e of i){let t=n.iterShapes(e,`edge`);for(let i of t){let t=n.hashCode(i,G),a=r.get(t);a||(a=[],r.set(t,a)),a.some(t=>n.isSame(t.edge,i)&&n.isSame(t.face,e))||a.push({edge:i,face:e})}}return t.edgeToFaces=r,r}function EO(e,t){let n=U(),r=TO(e),i=n.hashCode(t.wrapped,G),a=r.get(i)??[],o=[],s=new Map;for(let e of a){if(!n.isSame(e.edge,t.wrapped))continue;let r=n.hashCode(e.face,G),i=s.get(r);i?i.some(t=>n.isSame(t,e.face))||(i.push(e.face),o.push(e.face)):(s.set(r,[e.face]),o.push(e.face))}return CO(o,`face`)}function DO(e){return wO(e.wrapped,`edge`)}function OO(e){return wO(e.wrapped,`wire`)}function kO(e){return wO(e.wrapped,`vertex`)}function AO(e,t){let n=U(),r=TO(e),i=wO(t.wrapped,`edge`),a=[],o=new Map;for(let e of i){let i=n.hashCode(e.wrapped,G),s=r.get(i)??[];for(let e of s){if(n.isSame(e.face,t.wrapped))continue;let r=n.hashCode(e.face,G),i=o.get(r);i?i.some(t=>n.isSame(t,e.face))||(i.push(e.face),a.push(e.face)):(o.set(r,[e.face]),a.push(e.face))}}return CO(a,`face`)}function jO(e,t){let n=U(),r=n.iterShapes(e.wrapped,`edge`),i=n.iterShapes(t.wrapped,`edge`),a=new Map;for(let e of i){let t=n.hashCode(e,G),r=a.get(t);r||(r=[],a.set(t,r)),r.push(e)}let o=[];for(let e of r)a.get(n.hashCode(e,2147483647))?.some(t=>n.isSame(e,t))&&o.push(e);return CO(o,`edge`)}function MO(e){let t=U();return t.getNurbsCurveData?t.getNurbsCurveData(e.wrapped):null}function NO(e){let t=U();return t.getNurbsSurfaceData?t.getNurbsSurfaceData(e.wrapped):null}var PO={cut:WD,cutAll:JD,fuse:UD,fuseAll:qD};function FO(e){return{totalInputs:e.totalInputs,batchAttempts:e.batchAttempts,batchSucceeded:e.batchSucceeded,singletonFallbacks:e.singletonFallbacks,failedInputs:[...e.failedInputs].sort((e,t)=>e-t)}}function IO(e,t,n={}){return LO(PO,e,t,n)}function LO(e,t,n,r={}){if(r.signal?.aborted)throw r.signal.reason;let i={totalInputs:n.length,batchAttempts:0,batchSucceeded:0,singletonFallbacks:0,failedInputs:new Set},a=RO(e,t,n,0,r,i);return A(a)?a:O({shape:a.value,telemetry:FO(i)})}function RO(e,t,n,r,i,a){if(n.length===0)return O(t);if(n.length===1)return zO(e,t,n,r,i,a);a.batchAttempts++;let o=WO(()=>e.cutAll(t,n,i));if(o&&o.ok)return a.batchSucceeded++,o;if(i.signal?.aborted)throw i.signal.reason;let s=Math.floor(n.length/2),c=RO(e,t,n.slice(0,s),r,i,a);return c.ok?RO(e,c.value,n.slice(s),r+s,i,a):c}function zO(e,t,n,r,i,a){a.singletonFallbacks++;let o=bD(n),s=WO(()=>e.cut(t,o,i));if(s&&s.ok)return s;if(i.signal?.aborted)throw i.signal.reason;return a.failedInputs.add(r),O(t)}function BO(e,t={}){return VO(PO,e,t)}function VO(e,t,n={}){if(n.signal?.aborted)throw n.signal.reason;if(t.length===0)return k(F(N.FUSE_ALL_EMPTY,`fuseAllBisect requires at least one shape`));let r={totalInputs:t.length,batchAttempts:0,batchSucceeded:0,singletonFallbacks:0,failedInputs:new Set},i=HO(e,t,0,n,r);return A(i)?i:O({shape:i.value,telemetry:FO(r)})}function HO(e,t,n,r,i){if(t.length===1)return O(bD(t));i.batchAttempts++;let a=WO(()=>e.fuseAll(t,r));if(a&&a.ok)return i.batchSucceeded++,a;if(r.signal?.aborted)throw r.signal.reason;let o=Math.floor(t.length/2);return UO(e,HO(e,t.slice(0,o),n,r,i),HO(e,t.slice(o),n+o,r,i),t,n,o,r,i)}function UO(e,t,n,r,i,a,o,s){if(t.ok&&n.ok){s.singletonFallbacks++;let c=WO(()=>e.fuse(t.value,n.value,o));if(c&&c.ok)return c;for(let e=a;e<r.length;e++)s.failedInputs.add(i+e);return t}if(t.ok){for(let e=a;e<r.length;e++)s.failedInputs.add(i+e);return t}if(n.ok){for(let e=0;e<a;e++)s.failedInputs.add(i+e);return n}return t}function WO(e){try{return e()}catch{return null}}function GO(e,t,n){return U().checkBoolean(e.wrapped,t.wrapped,n)}function KO(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function qO(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function JO(e,t,n,r){let i=W(e);if(!dw(i)){let a=e.ShapeType(),o=[`COMPOUND`,`COMPSOLID`,`SOLID`,`SHELL`,`FACE`,`WIRE`,`EDGE`,`VERTEX`,`SHAPE`][a]??`UNKNOWN(${a})`;return i[Symbol.dispose](),k(za(t,`${n}. Got ${o} instead.`,void 0,void 0,r))}return O(i)}function YO(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>r.get(U().hashCode(e,2147483647))??1}}function XO(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=KO(e,`fuseWithEvolution: first operand`);if(A(o))return o;let s=KO(t,`fuseWithEvolution: second operand`);if(A(s))return s;let c=yE([e,t]),{shape:l,evolution:u}=U().fuseWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=JO(l,`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`,`Common causes: overlapping coplanar faces, zero-thickness geometry, or non-manifold input. Try autoHeal() on inputs first.`);return d.ok?(bE(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function ZO(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=KO(e,`cutWithEvolution: base`);if(A(o))return o;let s=KO(t,`cutWithEvolution: tool`);if(A(s))return s;let c=yE([e,t]),{shape:l,evolution:u}=U().cutWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=JO(l,`CUT_NOT_3D`,`Cut did not produce a 3D shape`,`Common causes: tool does not fully intersect the base, or produces a zero-thickness sliver. Ensure the tool extends through the shape.`);return d.ok?(bE(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function QO(e,t,{simplify:n=!1,signal:r,fuzzyValue:i}={}){if(r?.aborted)throw r.reason;let a=KO(e,`intersectWithEvolution: first operand`);if(A(a))return a;let o=KO(t,`intersectWithEvolution: second operand`);if(A(o))return o;let s=yE([e,t]),{shape:c,evolution:l}=U().intersectWithHistory(e.wrapped,t.wrapped,s,G,{simplify:n,fuzzyValue:i}),u=JO(c,`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`,`Shapes may not overlap. Verify they share a common volume before intersecting.`);return u.ok?(bE(l,[e,t],u.value),O({shape:u.value,evolution:l})):u}function $O(e,t,n){let r=qO(e,`filletWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(F(`INVALID_FILLET_RADIUS`,`Fillet radius must be positive`,void 0,void 0,`Provide a positive radius value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(F(`INVALID_FILLET_RADIUS`,`Fillet radii must both be positive`,void 0,void 0,`Both radius values must be greater than 0`));let i=t??Tw(e);if(i.length===0)return k(F(N.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));try{let t,r;if(typeof n==`function`){let e=YO(i,n);if(!e)return k(F(N.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=yE([e]),{shape:o,evolution:s}=U().filletWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return dw(c)?(bE(s,[e],c),O({shape:c,evolution:s})):k(P(N.FILLET_NOT_3D,`Fillet result is not a 3D shape`))}catch(e){return k(P(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:i.length,radius:n}))}}function ek(e,t,n){let r=qO(e,`chamferWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(F(`INVALID_CHAMFER_DISTANCE`,`Chamfer distance must be positive`,void 0,void 0,`Provide a positive distance value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(F(`INVALID_CHAMFER_DISTANCE`,`Chamfer distances must both be positive`,void 0,void 0,`Both distance values must be greater than 0`));let i=t??Tw(e);if(i.length===0)return k(F(N.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=YO(i,n);if(!e)return k(F(N.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=yE([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return dw(c)?(bE(s,[e],c),O({shape:c,evolution:s})):k(P(N.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`))}catch(e){return k(P(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:i.length,distance:n}))}}function tk(e,t,n,r=.001){let i=qO(e,`shellWithEvolution: shape`);if(A(i))return i;if(n<=0)return k(F(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(F(`NO_FACES`,`At least one face must be specified for shell`));try{let i=yE([e]),{shape:a,evolution:o}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,i,G,r),s=W(a);return dw(s)?(bE(o,[e],s),O({shape:s,evolution:o})):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}catch(e){return k(P(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function nk(e,t,n){try{let r=W(U().positionOnCurve(e.wrapped,t.wrapped,n));return dw(r)?O(r):k(P(N.POSITION_ON_CURVE_FAILED,`positionOnCurve did not produce a 3D shape`))}catch(e){return k(P(N.POSITION_ON_CURVE_FAILED,`Failed to position shape on curve at param ${n}`,e))}}function rk(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function ik(e,t){if(typeof e==`number`&&e<=0)return k(F(t.code,t.scalar,void 0,void 0,t.scalarHint));if(Array.isArray(e)&&(e[0]<=0||e[1]<=0))return k(F(t.code,t.pair,void 0,void 0,t.pairHint))}function ak(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>{let t=r.get(U().hashCode(e,G));if(t===void 0)throw Error(`fillet/chamfer: edge hash not found — possible hash collision`);return t}}}function ok(e,t,n,r,i){let a=W(t);return dw(a)?(bE(e,n,a),O(a)):k(P(r,i))}function sk(e,t){if(typeof t!=`function`)return{filteredFaces:[...e],kernelAngle:t};let n=[],r=new Map;for(let i of e){let e=t(i);e===null||e===0||Math.abs(e)>=90||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return{filteredFaces:n,kernelAngle:e=>{let t=r.get(U().hashCode(e,G));if(t===void 0)throw Error(`draft: face hash not found — possible hash collision`);return t}}}function ck(e,t){let n=rk(e,`thicken: shape`);if(A(n))return n;try{let n=yE([e]),{shape:r,evolution:i}=U().thickenWithHistory(e.wrapped,t,n,G),a=W(r);return bE(i,[e],a),O(a)}catch(e){return k(P(`THICKEN_FAILED`,`Thicken operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function lk(e,t,n){let r=rk(e,`fillet: shape`);if(A(r))return r;let i=ik(n,{code:`INVALID_FILLET_RADIUS`,scalar:`Fillet radius must be positive`,pair:`Fillet radii must both be positive`,scalarHint:`Provide a positive radius value greater than 0`,pairHint:`Both radius values must be greater than 0`});if(i)return i;let a=t??Tw(e);if(a.length===0)return k(F(N.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));if(typeof n==`function`){let e=ak(a,n);return e?O({filteredEdges:e.edges,kernelRadius:e.kernelParam,selectedCount:a.length}):k(F(N.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`))}return O({filteredEdges:[...a],kernelRadius:n,selectedCount:a.length})}function uk(e,t,n,{trackEvolution:r=!0}={}){let i=lk(e,t,n);if(A(i))return i;let{filteredEdges:a,kernelRadius:o,selectedCount:s}=i.value;try{let t=a.map(e=>e.wrapped);if(!r){let n=W(U().fillet(e.wrapped,t,o));return dw(n)?O(n):k(P(N.FILLET_NOT_3D,`Fillet result is not a 3D shape`))}let n=yE([e]),{shape:i,evolution:s}=U().filletWithHistory(e.wrapped,t,o,n,G);return ok(s,i,[e],N.FILLET_NOT_3D,`Fillet result is not a 3D shape`)}catch(e){return k(P(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:s,radius:n}))}}function dk(e,t,n){let r=rk(e,`chamfer: shape`);if(A(r))return r;let i=ik(n,{code:`INVALID_CHAMFER_DISTANCE`,scalar:`Chamfer distance must be positive`,pair:`Chamfer distances must both be positive`,scalarHint:`Provide a positive distance value greater than 0`,pairHint:`Both distance values must be greater than 0`});if(i)return i;let a=t??Tw(e);if(a.length===0)return k(F(N.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=ak(a,n);if(!e)return k(F(N.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...a],r=n;let i=yE([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,i,G);return ok(s,o,[e],N.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)}catch(e){return k(P(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:a.length,distance:n}))}}function fk(e,t,n,r=.001,{trackEvolution:i=!0}={}){let a=rk(e,`shell: shape`);if(A(a))return a;if(n<=0)return k(F(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(F(`NO_FACES`,`At least one face must be specified for shell`));try{if(!i){let i=W(U().shell(e.wrapped,t.map(e=>e.wrapped),n,r));return dw(i)?O(i):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}let a=yE([e]),{shape:o,evolution:s}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,a,G,r),c=W(o);return dw(c)?(bE(s,[e],c),O(c)):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}catch(e){return k(P(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function pk(e,t,n=1e-6){let r=rk(e,`offset: shape`);if(A(r))return r;if(Math.abs(t)<1e-10)return k(F(`ZERO_OFFSET`,`Offset distance cannot be zero`));try{let r=yE([e]),{shape:i,evolution:a}=U().offsetWithHistory(e.wrapped,t,r,G,n),o=W(i);return dw(o)?(bE(a,[e],o),O(o)):k(P(`OFFSET_RESULT_NOT_3D`,`Offset result is not a 3D shape`))}catch(e){return k(P(`OFFSET_FAILED`,`Offset operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function mk(e,t,n){let r=rk(e,`draft: shape`);if(A(r))return r;if(typeof n==`number`){if(Math.abs(n)<1e-10)return k(F(N.DRAFT_INVALID_ANGLE,`Draft angle cannot be zero`,void 0,void 0,`Provide a non-zero angle in degrees`));if(Math.abs(n)>=90)return k(F(N.DRAFT_INVALID_ANGLE,`Draft angle must be between -90 and 90 degrees (exclusive)`,void 0,void 0,`Typical draft angles are 1-5 degrees for injection molding`))}if(t.length===0)return k(F(N.DRAFT_NO_FACES,`No faces specified for draft`,void 0,void 0,`Select at least one face to apply the draft angle to`))}function hk(e,t,n,r,i){let a=mk(e,t,i);if(a)return a;try{let{filteredFaces:a,kernelAngle:o}=sk(t,i);if(a.length===0)return k(F(N.DRAFT_NO_FACES,`No faces with valid draft angle`,void 0,void 0,`Check that the angle callback returns non-zero values between -90 and 90 degrees`));let s=yE([e]),{shape:c,evolution:l}=U().draftWithHistory(e.wrapped,a.map(e=>e.wrapped),[n[0],n[1],n[2]],[r[0],r[1],r[2]],o,s,G);return ok(l,c,[e],N.DRAFT_NOT_3D,`Draft result is not a 3D shape`)}catch(e){let n=e instanceof Error?e.message:String(e);return k(P(N.DRAFT_FAILED,`Draft operation failed: ${n}`,e,{operation:`draft`,faceCount:t.length,angle:i}))}}function gk(e,t,n){if(n.length===0)return k(F(N.VARIABLE_FILLET_FAILED,`radii must contain at least one radius spec`));for(let e of n)if(e.radius<=0)return k(F(N.VARIABLE_FILLET_FAILED,`All radius values must be positive`));let r=U();try{let i=JSON.stringify({edge:r.hashCode(t.wrapped,G),radii:n.map(e=>({param:e.param,radius:e.radius}))}),a=W(r.filletVariable(e.wrapped,i));return dw(a)?lw(a)?O(a):(a[Symbol.dispose](),k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a solid`))):(a[Symbol.dispose](),k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a 3D shape`)))}catch(e){return k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet failed`,e))}}function _k(e){return Hw(e)}function vk(e){if(!lw(e))return k(F(`NOT_A_SOLID`,`Input shape is not a solid`));let t=_k(e);try{let n=U().healSolid(e.wrapped);if(!n)return t?O(e):k(P(N.HEAL_NO_EFFECT,`Solid healing had no effect — shape is still invalid`));let r=W(n);return lw(r)?(ww(r),_k(r)?O(r):k(P(`HEAL_SOLID_INCOMPLETE`,`Healed result is still invalid after ShapeFix_Solid`))):k(P(`HEAL_RESULT_NOT_SOLID`,`Healed result is not a solid`))}catch(e){return k(P(`HEAL_SOLID_FAILED`,`Solid healing failed`,e))}}function yk(e){if(!sw(e))return k(F(`NOT_A_FACE`,`Input shape is not a face`));try{let t=W(U().healFace(e.wrapped));return sw(t)?O(t):k(P(`HEAL_RESULT_NOT_FACE`,`Healed result is not a face`))}catch(e){return k(P(`HEAL_FACE_FAILED`,`Face healing failed`,e))}}function bk(e,t){if(!ow(e))return k(F(`NOT_A_WIRE`,`Input shape is not a wire`));try{let n=W(U().healWire(e.wrapped,t?.wrapped));return ow(n)?O(n):k(P(`HEAL_RESULT_NOT_WIRE`,`Healed result is not a wire`))}catch(e){return k(P(`HEAL_WIRE_FAILED`,`Wire healing failed`,e))}}function xk(e){return lw(e)?vk(e):sw(e)?yk(e):ow(e)?bk(e):O(e)}function Sk(e,t){let n=t?.fixWires!==!1,r=t?.fixFaces!==!1,i=t?.fixSolids!==!1,a=t?.fixSelfIntersection===!0,o=t?.sewTolerance,s=[],c=[];if(_k(e))return O({shape:e,report:{isValid:!0,alreadyValid:!0,wiresHealed:0,facesHealed:0,solidHealed:!1,steps:[`Shape already valid`],diagnostics:[{name:`validation`,attempted:!0,succeeded:!0}]}});s.push(`Shape invalid — applying shape-level healing`);let l=Dw(e).length,u=Ew(e).length,d=e,f=!1;if(o!==void 0)try{d=W(U().sew([d.wrapped],o)),s.push(`Applied sewing with tolerance ${o}`),c.push({name:`sew`,attempted:!0,succeeded:!0,detail:`tolerance=${o}`})}catch(e){let t=e instanceof Error?e.message:String(e);s.push(`Sewing failed: ${t}`),c.push({name:`sew`,attempted:!0,succeeded:!1,detail:t})}if(a&&n){let e=Dw(d),t=0;for(let n of e)try{U().fixSelfIntersection(n.wrapped),t++}catch{}s.push(`Self-intersection fix: ${t}/${e.length} wires`),c.push({name:`fixSelfIntersection`,attempted:!0,succeeded:t>0,detail:`${t}/${e.length} wires fixed`})}if(lw(d)&&i||sw(d)&&r||ow(d)&&n){let t=xk(d);ua(t)?(d=t.value,lw(e)?(f=!0,s.push(`Applied ShapeFix_Solid`),c.push({name:`healSolid`,attempted:!0,succeeded:!0})):sw(e)?(s.push(`Applied ShapeFix_Face`),c.push({name:`healFace`,attempted:!0,succeeded:!0})):(s.push(`Applied ShapeFix_Wire`),c.push({name:`healWire`,attempted:!0,succeeded:!0}))):(s.push(`Shape-level healing failed`),c.push({name:`healShape`,attempted:!0,succeeded:!1}))}else c.push({name:`healShape`,attempted:!1,succeeded:!1,detail:`skipped by options`});let p=Dw(d).length,m=Ew(d).length,h=Math.abs(p-l),g=Math.abs(m-u);h>0&&s.push(`Wire count changed by ${h}`),g>0&&s.push(`Face count changed by ${g}`);let _=_k(d);return s.push(_?`Final validation: valid`:`Final validation: still invalid`),c.push({name:`finalValidation`,attempted:!0,succeeded:_}),O({shape:d,report:{isValid:_,alreadyValid:!1,wiresHealed:h,facesHealed:g,solidHealed:f,steps:s,diagnostics:c}})}function Ck(e){try{return O(W(U().fixShape(e.wrapped)))}catch(e){return k(P(N.FIX_SHAPE_FAILED,`ShapeFix_Shape failed`,e))}}function wk(e){try{let t=W(U().solidFromShell(e.wrapped));return lw(t)?_k(t)?O(t):k(P(N.SOLID_FROM_SHELL_FAILED,`solidFromShell produced an invalid solid`)):k(P(N.SOLID_FROM_SHELL_FAILED,`solidFromShell did not produce a solid`))}catch(e){return k(P(N.SOLID_FROM_SHELL_FAILED,`Failed to create solid from shell`,e))}}function Tk(e){try{let t=W(U().fixSelfIntersection(e.wrapped));return ow(t)?O(t):k(P(N.FIX_SELF_INTERSECTION_FAILED,`Result is not a wire`))}catch(e){return k(P(N.FIX_SELF_INTERSECTION_FAILED,`Failed to fix wire self-intersection`,e))}}function Ek(e,t,n,r){let i=tw(U().makeBox(e,t,n)),a=r?.at??(r?.centered?[0,0,0]:void 0);return a?SE(i,[a[0]-e/2,a[1]-t/2,a[2]-n/2]):i}function Dk(e,t,n){let r=n?.at??[0,0,0],i=n?.axis??[0,0,1],a=lO(e,t,r,i);if(n?.centered){let e=[-i[0]*t*.5,-i[1]*t*.5,-i[2]*t*.5];a=SE(a,e)}return a}function Ok(e,t){let n=uO(e);return t?.at&&(n=SE(n,t.at)),n}function kk(e,t,n,r){let i=r?.at??[0,0,0],a=r?.axis??[0,0,1],o=dO(e,t,n,i,a);if(r?.centered){let e=[-a[0]*n*.5,-a[1]*n*.5,-a[2]*n*.5];o=SE(o,e)}return o}function Ak(e,t,n){return fO(e,t,n?.at??[0,0,0],n?.axis??[0,0,1])}function jk(e,t,n,r){let i=pO(e,t,n);return r?.at&&(i=SE(i,r.at)),i}function Mk(e,t){return wD(e,t)}function Nk(e,t){let n=t?.axis??[0,0,1];return TD(e,t?.at??[0,0,0],n)}function Pk(e,t,n){let r=n?.axis??[0,0,1];return ED(e,t,n?.at??[0,0,0],r,n?.xDir)}function Fk(e,t,n,r){return DD(e,t,n,r?.at??[0,0,0],r?.axis??[0,0,1],r?.lefthand??!1)}function Ik(e,t,n){return OD(e,t,n)}function Lk(e,t,n,r,i){let a=i?.axis??[0,0,1];return kD(e,t,n*Gw,r*Gw,i?.at??[0,0,0],a,i?.xDir)}function Rk(e,t){return AD(e,t)}function zk(e){return MD(e)}function Bk(e,t,n){return ND(e,t,n)}function Vk(e){return PD(e)}function Hk(e){return pa(PD(e),e=>LC(e)?O(e):k(F(`WIRE_NOT_CLOSED`,`Assembled wire is not closed: start and end points do not coincide`)))}function Uk(e,t){return FD(e,t)}function Wk(e){return RD(e)}function Gk(e,t){return LD(e,t)}function Kk(e){return BD(e)}function qk(e){return mO(e)}function Jk(e){return gO(e)}function Yk(e){return _O(e)}function Xk(e,t,n){return hO(e,t,n)}function Zk(e,t){return cO(e,t)}function Qk(e,t){return zD(e,t)}function $k(){return`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(Number(e)^crypto.getRandomValues(new Uint8Array(1))[0]&15>>Number(e)/4).toString(16))}function eA(e=[]){let t=e.map(({shape:e,name:t,color:n,alpha:r})=>{let i=n??`#f00`;i.indexOf(`#`)===0&&(i=i.slice(1)),i.length===3&&(i=i.replace(/([0-9a-f])/gi,`$1$1`));let a=parseInt(i.substring(0,2),16),o=parseInt(i.substring(2,4),16),s=parseInt(i.substring(4,6),16),c=Math.round((r??1)*255);return{shape:e.wrapped,name:t??$k(),color:[a,o,s,c]}});return xC(U().createXCAFDocument(t))}function tA(e=[],{unit:t,modelUnit:n}={}){let r=e=>{let t=e;return t.indexOf(`#`)===0&&(t=t.slice(1)),t.length===3&&(t=t.replace(/([0-9a-f])/gi,`$1$1`)),[parseInt(t.substring(0,2),16),parseInt(t.substring(2,4),16),parseInt(t.substring(4,6),16)]},i=U(),a=e.map(({shape:e,name:t,color:n,alpha:i})=>{let[a,o,s]=r(n??`#f00`);return{shape:e.wrapped,name:t??$k(),color:[a,o,s,Math.round((i??1)*255)]}}),o=i.createXCAFDocument(a);try{let e=i.writeXCAFToSTEP(o,{unit:t,modelUnit:n});return e?O(new Blob([e],{type:`application/STEP`})):k(Ua(`STEP_EXPORT_FAILED`,`Failed to write STEP file`))}finally{o.delete()}}function nA(e,t,n,r,i){if(n<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(cT(t))return k(F(`PATTERN_ZERO_DIRECTION`,`Pattern direction cannot be zero`));let a=oT(t);return qD(U().linearPattern(e.wrapped,[...a],r,n).map(e=>W(e)),{optimisation:`sameFace`,...i,unsafe:!0})}function rA(e,t,n,r=360,i=[0,0,0],a){if(n<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(cT(t))return k(F(`PATTERN_ZERO_AXIS`,`Pattern axis cannot be zero`));let o=r/n;return qD(U().circularPattern(e.wrapped,[...i],[...t],o,n).map(e=>W(e)),{optimisation:`sameFace`,...a,unsafe:!0})}function iA(e,t={}){return{name:e,children:[],...t.shape===void 0?{}:{shape:t.shape},...t.translate===void 0?{}:{translate:t.translate},...t.rotate===void 0?{}:{rotate:t.rotate},...t.metadata===void 0?{}:{metadata:t.metadata}}}function aA(e,t){return{...e,children:[...e.children,t]}}function oA(e,t){let n=e.children.findIndex(e=>e.name===t);if(n===-1)return e;let r=[...e.children];return r.splice(n,1),{...e,children:r}}function sA(e,t){return{...e,...t.shape===void 0?{}:{shape:t.shape},...t.translate===void 0?{}:{translate:t.translate},...t.rotate===void 0?{}:{rotate:t.rotate},...t.metadata===void 0?{}:{metadata:t.metadata}}}function cA(e,t){if(e.name===t)return e;for(let n of e.children){let e=cA(n,t);if(e)return e}}function lA(e,t,n=0){t(e,n);for(let r of e.children)lA(r,t,n+1)}function uA(e){let t=1;for(let n of e.children)t+=uA(n);return t}function dA(e){let t=[];return lA(e,e=>{e.shape&&t.push(e.shape)}),t}function fA(){return{steps:[],shapes:new Map}}function pA(e,t,n){let r={...t,timestamp:Date.now()},i=new Map(e.shapes);return i.set(t.outputId,n),{steps:[...e.steps,r],shapes:i}}function mA(e){if(e.steps.length===0)return e;let t=e.steps.slice(0,-1),n=new Set;for(let e of t){n.add(e.outputId);for(let t of e.inputIds)n.add(t)}let r=new Map;for(let[t,i]of e.shapes)n.has(t)&&r.set(t,i);return{steps:t,shapes:r}}function hA(e,t){return e.steps.find(e=>e.id===t)}function gA(e,t){return e.shapes.get(t)}function _A(e){return e.steps.length}function vA(e,t){let n=e.steps.findIndex(e=>e.id===t);return n===-1?[]:e.steps.slice(n)}function yA(e,t,n){let r=new Map(e.shapes);return r.set(t,n),{...e,shapes:r}}function bA(){return{operations:new Map}}function xA(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function SA(e,t){let n=new Set(e.steps.map(e=>e.outputId)),r={steps:[],shapes:new Map};for(let[t,i]of e.shapes)n.has(t)||(r=yA(r,t,i));for(let n of e.steps){let e=t.operations.get(n.type);if(!e)return k(Ha(`REPLAY_UNKNOWN_OP`,`Unknown operation type: ${n.type}`));let i=[];for(let e of n.inputIds){let t=r.shapes.get(e);if(!t)return k(Ha(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${n.id}`));i.push(t)}try{let t=e(i,n.parameters);r=pA(r,{id:n.id,type:n.type,parameters:n.parameters,inputIds:n.inputIds,outputId:n.outputId},t)}catch(e){return k(Ha(`REPLAY_STEP_FAILED`,`Step ${n.id} (${n.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(r)}function CA(e,t,n){let r=e.steps.findIndex(e=>e.id===t);if(r===-1)return k(Ha(`REPLAY_STEP_NOT_FOUND`,`Step not found: ${t}`));let i=new Map(e.shapes);for(let t=r;t<e.steps.length;t++){let n=e.steps[t];n&&i.delete(n.outputId)}let a={steps:e.steps.slice(0,r),shapes:i};for(let t=r;t<e.steps.length;t++){let r=e.steps[t];if(!r)continue;let i=n.operations.get(r.type);if(!i)return k(Ha(`REPLAY_UNKNOWN_OP`,`Unknown operation type: ${r.type}`));let o=[];for(let e of r.inputIds){let t=a.shapes.get(e);if(!t)return k(Ha(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${r.id}`));o.push(t)}try{let e=i(o,r.parameters);a=pA(a,{id:r.id,type:r.type,parameters:r.parameters,inputIds:r.inputIds,outputId:r.outputId},e)}catch(e){return k(Ha(`REPLAY_STEP_FAILED`,`Step ${r.id} (${r.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(a)}function wA(e,t,n,r){return e.steps.findIndex(e=>e.id===t)===-1?k(Ha(`MODIFY_STEP_NOT_FOUND`,`Step not found: ${t}`)):CA({steps:e.steps.map(e=>e.id===t?{...e,parameters:n}:e),shapes:e.shapes},t,r)}function TA(e){let t={};for(let[n,r]of e.shapes){let e=PE(r);if(!e.ok)return k(Ha(`SERIALIZE_SHAPE_FAILED`,`Failed to serialize shape "${n}": ${e.error.message}`));t[n]=e.value}return O({steps:e.steps,shapes:t})}function EA(e){let t=new Map;for(let[n,r]of Object.entries(e.shapes))try{let e=AT(r);if(!e.ok)return k(Ha(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e.error.message}`));t.set(n,e.value)}catch(e){return k(Ha(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e instanceof Error?e.message:String(e)}`))}return O({steps:e.steps,shapes:t})}var DA=new WeakMap;function OA(e,t){return DA.get(e)?.get(t)}function kA(e,t,n){let r=DA.get(e);r||(r=new Map,DA.set(e,r)),r.set(t,n)}function AA(e){return U().isNull(e.wrapped)}function jA(e){return k(F(N.NULL_SHAPE_INPUT,`${e}: shape is a null shape`))}function MA(e){let t=OA(e.wrapped,`volume`);if(t)return O(t);if(AA(e))return jA(`measureVolumeProps`);let n=U(),r=n.volume(e.wrapped),i=vw(()=>n.centerOfMass(e.wrapped),N.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!i.ok)return i;let a={mass:r,volume:r,centerOfMass:i.value};return kA(e.wrapped,`volume`,a),O(a)}function NA(e){let t=OA(e.wrapped,`surface`);if(t)return O(t);if(AA(e))return jA(`measureSurfaceProps`);let n=U(),r=n.area(e.wrapped),i=vw(()=>n.centerOfMass(e.wrapped),N.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!i.ok)return i;let a={mass:r,area:r,centerOfMass:i.value};return kA(e.wrapped,`surface`,a),O(a)}function PA(e){let t=OA(e.wrapped,`linear`);if(t)return O(t);if(AA(e))return jA(`measureLinearProps`);let n=U(),r=n.length(e.wrapped),i={mass:r,length:r,centerOfMass:n.linearCenterOfMass(e.wrapped)};return kA(e.wrapped,`linear`,i),O(i)}function FA(e){let t=MA(e);return t.ok?O(t.value.mass):t}function IA(e){let t=NA(e);return t.ok?O(t.value.mass):t}function LA(e){let t=PA(e);return t.ok?O(t.value.mass):t}function RA(e,t){return AA(e)||AA(t)?jA(`measureDistance`):O(U().distance(e.wrapped,t.wrapped).value)}function zA(e,t){if(AA(e)||AA(t))return jA(`measureDistanceProps`);let n=U().distance(e.wrapped,t.wrapped);return O({distance:n.value,point1:n.point1,point2:n.point2})}function BA(e){if(AA(e))return jA(`createDistanceQuery`);let t=U().createDistanceQuery(e.wrapped);return O({distanceTo(e){return AA(e)?jA(`createDistanceQuery.distanceTo`):O(t.distanceTo(e.wrapped).value)},dispose(){t.dispose()}})}function VA(e,t,n){if(AA(e))return jA(`measureCurvatureAt`);let r=U().surfaceCurvature(e.wrapped,t,n);return O({mean:r.mean,gaussian:r.gaussian,maxCurvature:r.max,minCurvature:r.min,maxDirection:r.maxDirection,minDirection:r.minDirection})}function HA(e){if(AA(e))return jA(`measureCurvatureAtMid`);let t=IT(e),n=(t.uMin+t.uMax)/2,r=(t.vMin+t.vMax)/2,i=U().surfaceCurvature(e.wrapped,n,r);return O({mean:i.mean,gaussian:i.gaussian,maxCurvature:i.max,minCurvature:i.min,maxDirection:i.maxDirection,minDirection:i.minDirection})}var UA=1e-9,WA=1e-8,GA=1e-6,KA=([e,t],[n,r],i=GA)=>Math.abs(e-n)<=i&&Math.abs(t-r)<=i,qA=([e,t],[n,r])=>[e+n,t+r],JA=([e,t],[n,r])=>[e-n,t-r],YA=([e,t],n)=>[e*n,t*n],XA=([e,t],[n,r]=[0,0])=>Math.sqrt((e-n)**2+(t-r)**2),ZA=([e,t],[n,r]=[0,0])=>(e-n)**2+(t-r)**2;function QA([e,t],[n,r]){return e*r-t*n}var $A=([e,t],[n,r]=[0,0])=>Math.atan2(r*e-t*n,e*n+t*r),ej=([e,t],[n,r]=[0,0])=>Math.atan2(r-t,n-e),tj=(e,t,n=[0,0])=>{let[r,i]=e,[a,o]=n,s=r-a,c=i-o,l=Math.sin(t),u=Math.cos(t),d=s*u-c*l,f=s*l+c*u;return[d+a,f+o]};function nj([e,t]){let n=Math.sqrt(e*e+t*t);return n<1e-12?[0,0]:[e/n,t/n]}var rj=(e,t)=>[Math.cos(t)*e,Math.sin(t)*e],ij=([e,t])=>[Math.sqrt(e*e+t*t),Math.atan2(t,e)],aj=([e,t])=>{let n=nj([e,t]);return n[0]===0&&n[1]===0&&M(`normalize2d`,`Cannot normalize zero-length vector`),n};function oj(e,t){let n,r=0;for(let i=0;i<e.length;i++){let a=e[i];if(t(a))if(r++,r===1)n=a;else break}return r===1?O(n):k(Wa(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found ${r===0?0:`2+`} element(s)`))}function sj(e,t,n,r){let i=e=>n([...t,e]),a=e=>t.every(t=>t(e));function o(t){switch(e){case`edge`:return Tw(t);case`face`:return Ew(t);case`wire`:return Dw(t);case`vertex`:return Ow(t)}}let s=e=>{let n=o(e);return t.length===0?n.slice():n.filter(a)},c=()=>sj(e,[],n,r),l={_filters:t,_topoKind:e,when:e=>i(e),inList:e=>{let t=new Map;for(let n of e){let e=FE(n),r=t.get(e);r?r.push(n):t.set(e,[n])}return i(e=>{let n=t.get(FE(e));return!!n&&n.some(t=>LE(t,e))})},not:e=>{let t=e(c());return i(e=>!t.shouldKeep(e))},either:e=>{let t=e.map(e=>e(c()));return i(e=>t.some(t=>t.shouldKeep(e)))},findAll:e=>s(e),findUnique:e=>oj(o(e),a),shouldKeep:a,and:e=>i(t=>e.shouldKeep(t)),or:e=>{let t=a;return n([n=>t(n)||e.shouldKeep(n)])},negate:()=>{let e=a;return n([t=>!e(t)])}},u=r(l,i);return{...l,...u}}var cj={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function lj(e){return typeof e==`string`?cj[e]??[0,0,1]:e}function uj(e,t,n){let r=U(),i=r.makeVertex(t[0],t[1],t[2]);return t=>{let a=r.distance(i,t.wrapped).value;return Math.abs(a-e)<n}}function dj(e,t){let n=oT(lj(e));return e=>{let r=U(),[i,a]=r.curveParameters(e.wrapped),o=(i+a)/2,{tangent:s}=r.curveTangent(e.wrapped,o),c=oT(s),l=Math.acos(Math.min(1,Math.abs(tT(c,n))));return Math.abs(l-Gw*t)<1e-6}}function fj(e){return sj(`edge`,e,fj,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(dj(e,t)),ofLength:(e,t=.001)=>n(n=>Math.abs(GE(n)-e)<t),ofCurveType:e=>n(t=>BE(t)===e),parallelTo:(t=`Z`)=>fj(e).inDirection(t,0),atDistance:(e,t=[0,0,0])=>n(uj(e,t,1e-6))}))}function pj(){return fj([])}function mj(e,t){let n=oT(lj(e));return e=>{let r=BT(e),i=Math.acos(Math.min(1,Math.abs(tT(oT(r),n))));return Math.abs(i-Gw*t)<1e-6}}function hj(e){return sj(`face`,e,hj,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(mj(e,t)),parallelTo:(t=`Z`)=>hj(e).inDirection(t,0),ofSurfaceType:e=>n(t=>{let n=MT(t);return ua(n)&&n.value===e}),ofArea:(e,t=.001)=>n(n=>{let r=IA(n);return ua(r)&&Math.abs(r.value-e)<t}),atDistance:(e,t=[0,0,0])=>n(uj(e,t,1e-6))}))}function gj(){return hj([])}function _j(e){return sj(`wire`,e,_j,(e,t)=>({isClosed:()=>t(e=>KE(e)),isOpen:()=>t(e=>!KE(e)),ofEdgeCount:e=>t(t=>Tw(t).length===e)}))}function vj(){return _j([])}function yj(e,t){return typeof e==`object`&&`_topoKind`in e?e.findUnique(t):typeof e!=`function`&&sw(e)?O(e):e(gj()).findUnique(t)}function bj(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`}function xj(e,t){let n=10**t,r=t<0?e:.01/n+e;return Math.round(r*n)/n}function Sj(e){return Math.round(e*100)/100}function Cj(e){return Math.round(e*1e5)/1e5}var wj=([e,t])=>`(${Sj(e)},${Sj(t)})`,Tj=(e,t=1e-9)=>{let n=e;return Math.abs(e)<t&&(n=0),n.toFixed(-Math.log10(t))},Ej=(e,t=1e-9)=>Array.from(new Map(e.map(([e,n])=>[`[${Tj(e,t)},${Tj(n,t)}]`,[e,n]])).values()),Dj=class{_wrapped;_deleted=!1;constructor(e){this._wrapped=e??iC().createBoundingBox2d(),wC(this,this._wrapped)}get wrapped(){if(this._deleted)throw Error(`This object has been deleted`);return this._wrapped}delete(){this._deleted||(this._deleted=!0,TC(this._wrapped),typeof this._wrapped.delete==`function`&&this._wrapped.delete())}[Symbol.dispose](){this.delete()}get repr(){let[e,t]=this.bounds;return`${wj(e)} - ${wj(t)}`}get bounds(){let{xMin:e,yMin:t,xMax:n,yMax:r}=iC().getBBox2dBounds(this.wrapped);return[[e,t],[n,r]]}get center(){let[[e,t],[n,r]]=this.bounds;return[e+(n-e)/2,t+(r-t)/2]}get width(){let[[e],[t]]=this.bounds;return Math.abs(t-e)}get height(){let[[,e],[,t]]=this.bounds;return Math.abs(t-e)}outsidePoint(e=1){let[t,n]=this.bounds,r=n[0]-t[0],i=n[1]-t[1];return[n[0]+r/100*e,n[1]+i/100*e*.9]}add(e){iC().mergeBBox2d(this.wrapped,e.wrapped)}isOut(e){return iC().isBBox2dOut(this.wrapped,e.wrapped)}containsPoint(e){return!iC().isBBox2dOutPoint(this.wrapped,e[0],e[1])}};function Oj(e){return new kj(U().deserializeCurve2d(e))}var kj=class e{_wrapped;_deleted=!1;_boundingBox;_firstPoint=null;_lastPoint=null;_firstParameter=null;_lastParameter=null;constructor(e){this._wrapped=U().wrapCurve2dHandle(e),this._boundingBox=null,typeof this._wrapped.delete==`function`&&wC(this,this._wrapped)}get wrapped(){if(this._deleted)throw Error(`This object has been deleted`);return this._wrapped}delete(){this._deleted||(this._deleted=!0,typeof this._wrapped.delete==`function`&&(TC(this._wrapped),this._wrapped.delete()))}[Symbol.dispose](){this.delete()}get boundingBox(){if(this._boundingBox)return this._boundingBox;let e=U(),t=e.createBoundingBox2d();return e.addCurveToBBox2d(t,this.wrapped,1e-6),this._boundingBox=new Dj(t),this._boundingBox}get repr(){return`${this.geomType} ${wj(this.firstPoint)} - ${wj(this.lastPoint)}`}serialize(){return U().serializeCurve2d(this.wrapped)}value(e){return U().evaluateCurve2d(this.wrapped,e)}get firstPoint(){return this._firstPoint===null&&(this._firstPoint=this.value(this.firstParameter)),this._firstPoint}get lastPoint(){return this._lastPoint===null&&(this._lastPoint=this.value(this.lastParameter)),this._lastPoint}get firstParameter(){return this._firstParameter===null&&(this._firstParameter=U().getCurve2dBounds(this.wrapped).first),this._firstParameter}get lastParameter(){return this._lastParameter===null&&(this._lastParameter=U().getCurve2dBounds(this.wrapped).last),this._lastParameter}get geomType(){return U().getCurve2dType(this.wrapped)}clone(){let t=new e(U().copyCurve2d(this.wrapped));return t._firstPoint=this._firstPoint,t._lastPoint=this._lastPoint,t._firstParameter=this._firstParameter,t._lastParameter=this._lastParameter,t}reverse(){U().reverseCurve2d(this.wrapped);let e=this._firstPoint;this._firstPoint=this._lastPoint,this._lastPoint=e;let t=this._firstParameter;this._firstParameter=this._lastParameter,this._lastParameter=t}distanceFromPoint(e){let t=U().projectPointOnCurve2d(this.wrapped,e[0],e[1]),n=t?t.distance:1/0;return Math.min(n,XA(e,this.firstPoint),XA(e,this.lastPoint))}distanceFromCurve(e){let t;try{t=U().distanceBetweenCurves2d(this.wrapped,e.wrapped,this.firstParameter,this.lastParameter,e.firstParameter,e.lastParameter)}catch{t=1/0}return Math.min(t,this.distanceFromPoint(e.firstPoint),this.distanceFromPoint(e.lastPoint),e.distanceFromPoint(this.firstPoint),e.distanceFromPoint(this.lastPoint))}distanceFrom(e){return bj(e)?this.distanceFromPoint(e):this.distanceFromCurve(e)}isOnCurve(e){return this.distanceFromPoint(e)<1e-9}parameter(e,t=1e-9){let n,r,i=!1;try{let t=U().projectPointOnCurve2d(this.wrapped,e[0],e[1]);t?(n=t.distance,r=t.param):i=!0}catch{i=!0}return i?KA(e,this.firstPoint,t)?O(this.firstParameter):KA(e,this.lastPoint,t)?O(this.lastParameter):k(Ha(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n===void 0||r===void 0?k(Ha(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n>t?k(Ha(`POINT_NOT_ON_CURVE`,`Point ${wj(e)} not on curve ${this.repr}, ${n.toFixed(9)}`)):O(r)}tangentAt(e){let t;if(Array.isArray(e))t=j(this.parameter(e));else{let n=U().getCurve2dBounds(this.wrapped);t=(n.last-n.first)*e+n.first}return U().evaluateCurve2dD1(this.wrapped,t).tangent}splitAt(n,r=1e-9){let i=n.map(e=>bj(e)?j(this.parameter(e,r)):e);i=Array.from(new Map(i.map(e=>[xj(e,-Math.log10(r)),e])).values()).sort((e,t)=>e-t);let a=this.firstParameter,o=this.lastParameter;return a>o&&i.reverse(),Math.abs(t(i,0)-a)<r*100&&(i=i.slice(1)),!i.length||(Math.abs(t(i,i.length-1)-o)<r*100&&(i=i.slice(0,-1)),!i.length)?[this]:U().splitCurve2d(this.wrapped,i).map(t=>new e(t))}},Aj=(e,t=1e-4,n=`C0`,r=200)=>new kj(iC().approximateCurve2dAsBSpline(e.wrapped,t,n,r)),jj=e=>(e.geomType!==`BSPLINE_CURVE`&&M(`BSplineToBezier`,`You can only convert a Bspline`),iC().decomposeBSpline2dToBeziers(e.wrapped).map(e=>new kj(e)));function Mj(e,t={tolerance:1e-4,continuity:`C0`,maxSegments:300}){let n=iC();return e.flatMap(e=>{let r=e.geomType;if(r===`ELLIPSE`||r===`CIRCLE`&&KA(e.firstPoint,e.lastPoint))return e.splitAt([.5]);if([`LINE`,`ELLIPSE`,`CIRCLE`].includes(r))return e;if(r===`BEZIER_CURVE`){let t=n.getCurve2dBezierDegree(e.wrapped);if(t!==null&&[1,2,3].includes(t))return e}return Mj(jj(r===`BSPLINE_CURVE`?e:Aj(e,t.tolerance,t.continuity,t.maxSegments)),t)})}var Nj=(e,t)=>{let n=new kj(U().makeLine2d(e[0],e[1],t[0],t[1]));return KA(n.firstPoint,e)||n.reverse(),n},Pj=(e,t,n)=>{let r=new kj(U().makeArc2dThreePoints(e[0],e[1],t[0],t[1],n[0],n[1]));if(!KA(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new kj(e)}return r},Fj=(e,t,n)=>{let r=new kj(U().makeArc2dTangent(e[0],e[1],t[0],t[1],n[0],n[1]));if(!KA(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new kj(e)}return r},Ij=(e,t=[0,0])=>new kj(U().makeCircle2d(t[0],t[1],e,!0)),Lj=(e,t,n=[1,0],r=[0,0],i=!0)=>new kj(U().makeEllipse2d(r[0],r[1],e,t,n[0],n[1],i)),Rj=(e,t,n,r,i=[0,0],a,o=!0)=>new kj(U().makeEllipseArc2d(i[0],i[1],e,t,n,r,a[0],a[1],o)),zj=(e,t,n)=>{let r=[[e[0],e[1]],...t.map(e=>[e[0],e[1]]),[n[0],n[1]]];return new kj(U().makeBezier2d(r))};function Bj(e,{tolerance:t=.001,smoothing:n=null,degMax:r=3,degMin:i=1}={}){try{let a=e.map(e=>[e[0],e[1]]);return O(new kj(U().makeBSpline2d(a,{tolerance:t,smoothing:n,degMax:r,degMin:i,continuity:`C2`})))}catch{return k(Ha(`BSPLINE_2D_FAILED`,`B-spline approximation failed`))}}var Vj=(e,t,n,r=!1)=>{let i=YA(qA(e,t),.5),a=XA(n,e)*(r?-1:1);return Pj(e,qA(YA(aj(JA(i,n)),a),n),t)},Hj=(e,n)=>{let r=iC(),i=e.geomType,[a,o]=n,s=`${Cj(a)} ${Cj(o)}`;if(i===`LINE`)return`L ${s}`;if(i===`BEZIER_CURVE`){let n=r.getCurve2dBezierPoles(e.wrapped);n||M(`adaptedCurveToPathElem`,`Expected Bezier poles`);let i=n.length-1;if(i===1)return`L ${s}`;if(i===2){let[e,r]=t(n,1);return`Q ${Sj(e)} ${Sj(r)} ${s}`}if(i===3){let[e,r]=t(n,1),[i,a]=t(n,2);return`C ${Sj(e)} ${Sj(r)} ${Sj(i)} ${Sj(a)} ${s}`}}if(i===`CIRCLE`){let t=r.getCurve2dCircleData(e.wrapped);t||M(`adaptedCurveToPathElem`,`Expected circle data`);let{radius:n,isDirect:i}=t,c=r.getCurve2dBounds(e.wrapped),l=(c.last-c.first)*Kw,u=l===360?`${Cj(a)} ${Cj(o+1e-4)}`:s;return`A ${n} ${n} 0 ${Math.abs(l)>180?`1`:`0`} ${i?`1`:`0`} ${u}`}if(i===`ELLIPSE`){let t=r.getCurve2dEllipseData(e.wrapped);t||M(`adaptedCurveToPathElem`,`Expected ellipse data`);let{majorRadius:n,minorRadius:i,xAxisAngle:c,isDirect:l}=t,u=r.getCurve2dBounds(e.wrapped),d=(u.last-u.first)*Kw,f=d===360?`${Cj(a)} ${Cj(o+1e-4)}`:s,p=180-c*Kw;return`A ${Cj(n)} ${Cj(i)} ${Cj(p)} ${Math.abs(d)>180?`1`:`0`} ${l?`1`:`0`} ${f}`}M(`adaptedCurveToPathElem`,`Unsupported curve type: ${i}`)},Uj=e=>{let t=U(),n=t.createBoundingBox2d();return e.forEach(e=>{t.addCurveToBBox2d(n,e.wrapped,1e-6)}),new Dj(n)};function Wj(e,t){let n=U();return e.map(e=>ZC(n.liftCurve2dToPlane(e.wrapped,[...t.origin],[...t.zDir],[...t.xDir])))}var Gj=(e,t)=>{let n=U();return e.map(e=>ZC(n.buildEdgeOnSurface(e.wrapped,t)))},Kj=(e,t)=>{let n=U();return e.map(e=>t?new kj(n.transformCurve2dGeneral(e.wrapped,t)):e.clone())},qj=(e,t,n=[0,0])=>U().createAffinityGTrsf2d(n[0],n[1],t[0],t[1],e),Jj=e=>U().createTranslationGTrsf2d(e[0],e[1]),Yj=(e,t=[0,0],n=`center`)=>n===`center`?U().createMirrorGTrsf2d(e[0],e[1],`point`):U().createMirrorGTrsf2d(0,0,`axis`,t[0],t[1],e[0],e[1]),Xj=(e,t=[0,0])=>U().createRotationGTrsf2d(e,t[0],t[1]),Zj=(e,t=[0,0])=>U().createScaleGTrsf2d(e,t[0],t[1]);function Qj(e,t,n=`original`){let r=U(),i=r.extractSurfaceFromFace(t.wrapped),a=IT(t),o=null;if(n===`original`&&NT(t)!==`PLANE`){if(NT(t)!==`CYLINDRE`)return k(F(`UNSUPPORTED_FACE_TYPE`,`Only planar and cylindrical faces can be unwrapped for sketching`));let e=r.getSurfaceCylinderData(i);if(!e)return k(F(`UNSUPPORTED_FACE_TYPE`,`Could not extract cylinder data from face surface`));e.isDirect||(i=r.reverseSurfaceU(i)),o=qj(1/e.radius,[0,1])}if(n===`bounds`){o=r.createIdentityGTrsf2d();try{r.setGTrsf2dTranslationPart(o,0,0);let e=r.createAffinityGTrsf2d(0,0,0,1,a.uMax-a.uMin);if(r.multiplyGTrsf2d(o,e),e.delete(),a.uMin!==0){let e=r.createIdentityGTrsf2d();r.setGTrsf2dTranslationPart(e,-a.uMin,0),r.multiplyGTrsf2d(o,e),e.delete()}let t=r.createAffinityGTrsf2d(0,0,1,0,a.vMax-a.vMin);if(r.multiplyGTrsf2d(o,t),t.delete(),a.vMin!==0){let e=r.createIdentityGTrsf2d();r.setGTrsf2dTranslationPart(e,0,-a.vMin),r.multiplyGTrsf2d(o,e),e.delete()}}catch(e){throw o.delete(),e}}let s=Gj(Kj(e,o),i);return o&&o.delete(),O(s)}function $j(e,t){let n=U(),r=new kj(n.extractCurve2dFromEdge(e.wrapped,t.wrapped));return YE(e)===`backward`&&n.reverseCurve2d(r.wrapped),r}var eM=(e,t=1)=>`${e.bounds[0][0]-t} ${-e.bounds[1][1]-t} ${e.width+2*t} ${e.height+2*t}`,tM=(e,t,n=1)=>`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${eM(t,n)}" fill="none" stroke="black" stroke-width="0.6%" vector-effect="non-scaling-stroke">
|
|
13
|
+
npm install brepkit-wasm`)}function lC(){var e=typeof SuppressedError==`function`?SuppressedError:function(e,t){var n=Error();return n.name=`SuppressedError`,n.error=e,n.suppressed=t,n},t={},n=[];function r(e,t){if(t!=null){if(Object(t)!==t)throw TypeError(`using declarations can only be used with objects, functions, null, or undefined.`);if(e)var r=t[Symbol.asyncDispose||Symbol.for(`Symbol.asyncDispose`)];if(r===void 0&&(r=t[Symbol.dispose||Symbol.for(`Symbol.dispose`)],e))var i=r;if(typeof r!=`function`)throw TypeError(`Object is not disposable.`);i&&(r=function(){try{i.call(t)}catch(e){return Promise.reject(e)}}),n.push({v:t,d:r,a:e})}else e&&n.push({d:t,a:e});return t}return{e:t,u:r.bind(null,!1),a:r.bind(null,!0),d:function(){var r,i=this.e,a=0;function o(){for(;r=n.pop();)try{if(!r.a&&a===1)return a=0,n.push(r),Promise.resolve().then(o);if(r.d){var e=r.d.call(r.v);if(r.a)return a|=2,Promise.resolve(e).then(o,s)}else a|=1}catch(e){return s(e)}if(a===1)return i===t?Promise.resolve():Promise.reject(i);if(i!==t)throw i}function s(n){return i=i===t?n:new e(n,i),o()}return o()}}}var uC=Symbol;uC.dispose??=Symbol.for(`Symbol.dispose`),uC.asyncDispose??=Symbol.for(`Symbol.asyncDispose`);var dC=globalThis;dC.FinalizationRegistry||=(console.warn(`brepjs: FinalizationRegistry unavailable — garbage collection will not work`),class{register(e,t,n){}unregister(e){return!1}});var fC={liveHandles:0,peakHandles:0,gcCollected:0,scopeEnters:0,scopeExits:0};function pC(){return{...fC}}function mC(){fC.liveHandles=0,fC.peakHandles=0,fC.gcCollected=0,fC.scopeEnters=0,fC.scopeExits=0}function hC(){fC.liveHandles++,fC.liveHandles>fC.peakHandles&&(fC.peakHandles=fC.liveHandles)}function gC(){fC.liveHandles--}function _C(){fC.gcCollected++,fC.liveHandles--}var vC=new FinalizationRegistry(e=>{_C();try{e.delete()}catch{}});function yC(e){let t=!1,n=()=>{if(!t){t=!0,gC(),vC.unregister(r);try{e.delete()}catch{}}},r={get wrapped(){if(t)throw Error(`Shape handle has been disposed`);return e},get disposed(){return t},[Symbol.dispose](){n()},delete(){n()}};return hC(),vC.register(r,e,r),r}function bC(e){let t=!1,n={get value(){if(t)throw Error(`kernel handle has been disposed`);return e},get disposed(){return t},[Symbol.dispose](){if(!t){t=!0,gC(),vC.unregister(n);try{e.delete()}catch{}}}};return hC(),vC.register(n,e,n),n}var xC=class{handles=[];constructor(){fC.scopeEnters++}register(e){return this.handles.push(()=>{try{e.delete()}catch{}}),e}track(e){return this.handles.push(()=>{try{e[Symbol.dispose]()}catch{}}),e}[Symbol.dispose](){fC.scopeExits++;for(let e=this.handles.length-1;e>=0;e--)this.handles[e]?.();this.handles.length=0}};function SC(e){try{var t=lC();return e(t.u(new xC))}catch(e){t.e=e}finally{t.d()}}function CC(e,t){vC.register(e,t,t)}function wC(e){vC.unregister(e)}function TC(e){try{var t=lC();return e(t.u(new xC))}catch(e){t.e=e}finally{t.d()}}async function EC(e){try{var t=lC();return await e(t.u(new xC))}catch(e){t.e=e}finally{t.d()}}function DC(e){return!e.disposed}function OC(e){return e.__is2D!==!0}function kC(e){return e.__is2D===!0}function AC(e){if(!OC(e))throw Error(`Expected 3D shape, got 2D`);return e}function jC(e){if(!kC(e))throw Error(`Expected 2D shape, got 3D`);return e}var MC=new WeakMap;function NC(e,t){MC.set(e,t)}function PC(e,t){let n=MC.get(t);if(n!==void 0)return n;let r=e.shapeType(t);return MC.set(t,r),r}function FC(e){return PC(U(),e.wrapped)}function IC(e){return U().curveIsClosed(e.wrapped)}function LC(e){return U().isValid(e.wrapped)}function RC(e){let t=U();if(!t.isValid(e.wrapped))return!1;let n=t.isValidStrict?.bind(t)??t.isValid.bind(t);try{let r=t.solidFromShell(e.wrapped),i=n(r);try{t.dispose(r)}catch{}return i}catch{return!1}}function zC(e){return U().isValid(e.wrapped)}function BC(e){return IC(e)?O(e):k(`Wire is not closed: start and end points do not coincide`)}function VC(e){return LC(e)?O(e):k(`Face orientation is inconsistent or face is invalid`)}function HC(e){return RC(e)?O(e):k(`Shell is not manifold: has free edges or is invalid`)}function UC(e){return zC(e)?O(e):k(`Solid failed BRepCheck validation`)}function WC(e){return U().surfaceType(e.wrapped)===`plane`}function GC(e){let t=U(),n=n=>{try{let r=t.makeFace(e.wrapped,n),i=t.surfaceType(r);try{t.dispose(r)}catch{}return i===`plane`}catch{return!1}};return n(!0)?!0:n(!1)}function KC(e){return WC(e)?O(e):k(`Face is not planar: underlying surface is not a geometric plane`)}function qC(e){return GC(e)?O(e):k(`Wire is not planar: edges do not lie in a common plane`)}function JC(e,t){return t===`2D`&&(e.__is2D=!0),e}function YC(e,t){return JC(yC(e),t)}function XC(e,t){return JC(yC(e),t)}function ZC(e,t){return JC(yC(e),t)}function QC(e,t){return JC(yC(e),t)}function $C(e){return JC(yC(e))}function ew(e){return JC(yC(e))}function tw(e){return JC(yC(e))}function nw(e,t){return JC(yC(e),t)}function rw(e){return FC(e)===`vertex`}function iw(e){return FC(e)===`edge`}function aw(e){return FC(e)===`wire`}function ow(e){return FC(e)===`face`}function sw(e){return FC(e)===`shell`}function cw(e){return FC(e)===`solid`}function lw(e){return FC(e)===`compound`}function uw(e){let t=FC(e);return t===`shell`||t===`solid`||t===`compsolid`?!0:t===`compound`?OC(e):!1}function dw(e){let t=FC(e);return t===`edge`||t===`wire`}function W(e,t){let n=U(),r=PC(n,e),i=n.downcast(e,r);return r===`vertex`?YC(i,t):r===`edge`?XC(i,t):r===`wire`?ZC(i,t):r===`face`?QC(i,t):r===`shell`?$C(i):r===`solid`?ew(i):r===`compsolid`?tw(i):nw(i,t)}function fw(e){return W(e)}function pw(e,t,n){NC(e,t);let r=U().downcast(e,t);return t===`vertex`?YC(r,n):t===`edge`?XC(r,n):t===`wire`?ZC(r,n):t===`face`?QC(r,n):t===`shell`?$C(r):t===`solid`?ew(r):t===`compsolid`?tw(r):nw(r,n)}function mw(e,t,n,r,i){let a={kind:e,code:t,message:n,cause:r};return i?{...a,suggestion:i}:a}var hw={KERNEL_OPERATION:(e,t,n,r)=>mw(`KERNEL_OPERATION`,e,t,n,r),VALIDATION:(e,t,n,r)=>mw(`VALIDATION`,e,t,n,r),TYPE_CAST:(e,t,n,r)=>mw(`TYPE_CAST`,e,t,n,r),SKETCHER_STATE:(e,t,n,r)=>mw(`SKETCHER_STATE`,e,t,n,r),MODULE_INIT:(e,t,n,r)=>mw(`MODULE_INIT`,e,t,n,r),COMPUTATION:(e,t,n,r)=>mw(`COMPUTATION`,e,t,n,r),IO:(e,t,n,r)=>mw(`IO`,e,t,n,r),QUERY:(e,t,n,r)=>mw(`QUERY`,e,t,n,r),UNSUPPORTED:(e,t,n,r)=>mw(`UNSUPPORTED`,e,t,n,r)};function gw(e,t,n,r=`KERNEL_OPERATION`){try{return O(W(e()))}catch(e){let i=e instanceof Error?e.message:String(e),a=r===`KERNEL_OPERATION`?La(i):i,o=Ia(t);return k(hw[r](t,`${n}: ${a}`,e,o))}}function _w(e,t,n,r=`KERNEL_OPERATION`){try{return O(e())}catch(e){let i=e instanceof Error?e.message:String(e),a=r===`KERNEL_OPERATION`?La(i):i,o=Ia(t);return k(hw[r](t,`${n}: ${a}`,e,o))}}function vw(e,t,n,r=`KERNEL_OPERATION`){try{var i=lC();let a=i.u(new xC);return gw(()=>e(a),t,n,r)}catch(e){i.e=e}finally{i.d()}}function yw(e,t){let n=U().iterShapes(e,t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=pw(n[e],t);return r}var bw=new WeakMap;function xw(e){let t=bw.get(e.wrapped);return t||(t={},bw.set(e.wrapped,t)),t}function Sw(e){return bw.get(e.wrapped)}function Cw(e){bw.delete(e.wrapped)}function ww(e){let t=xw(e);if(t.edges)return t.edges;let n=yw(e.wrapped,`edge`);return t.edges=n,n}function Tw(e){let t=xw(e);if(t.faces)return t.faces;let n=yw(e.wrapped,`face`);return t.faces=n,n}function Ew(e){let t=xw(e);if(t.wires)return t.wires;let n=yw(e.wrapped,`wire`);return t.wires=n,n}function Dw(e){let t=xw(e);if(t.vertices)return t.vertices;let n=yw(e.wrapped,`vertex`);return t.vertices=n,n}function Ow(e){let t=xw(e);if(t.solids)return t.solids;let n=yw(e.wrapped,`solid`);return t.solids=n,n}function kw(e){let t=xw(e);if(t.shells)return t.shells;let n=yw(e.wrapped,`shell`);return t.shells=n,n}function Aw(e){let t=xw(e);if(t.compSolids)return t.compSolids;let n=yw(e.wrapped,`compsolid`);return t.compSolids=n,n}function*jw(e){for(let t of U().iterShapes(e.wrapped,`edge`))yield pw(t,`edge`)}function*Mw(e){for(let t of U().iterShapes(e.wrapped,`face`))yield pw(t,`face`)}function*Nw(e){for(let t of U().iterShapes(e.wrapped,`wire`))yield pw(t,`wire`)}function*Pw(e){for(let t of U().iterShapes(e.wrapped,`vertex`))yield pw(t,`vertex`)}function*Fw(e){for(let t of U().iterShapes(e.wrapped,`solid`))yield pw(t,`solid`)}function*Iw(e){for(let t of U().iterShapes(e.wrapped,`shell`))yield pw(t,`shell`)}function*Lw(e){for(let t of U().iterShapes(e.wrapped,`compsolid`))yield pw(t,`compsolid`)}function Rw(e){let t=xw(e);if(t.bounds)return t.bounds;let{min:n,max:r}=U().boundingBox(e.wrapped),i={xMin:n[0],xMax:r[0],yMin:n[1],yMax:r[1],zMin:n[2],zMax:r[2]};return t.bounds=i,i}function zw(e){return PC(U(),e.wrapped)}function Bw(e){let t=xw(e);if(t.surfaceType!==void 0)return t.surfaceType;let n=U().surfaceType(e.wrapped);return t.surfaceType=n,n}function Vw(e){let t=xw(e);if(t.isValid!==void 0)return t.isValid;let n=U().isValid(e.wrapped);return t.isValid=n,n}function Hw(e){return{kind:zw(e),faceCount:Tw(e).length,edgeCount:ww(e).length,wireCount:Ew(e).length,vertexCount:Dw(e).length,valid:Vw(e),bounds:Rw(e)}}function Uw(e){return U().vertexPosition(e.wrapped)}var G=2147483647,Ww=Math.PI/180,Gw=180/Math.PI;function Kw(e){return e.length===2?[e[0],e[1],0]:[e[0],e[1],e[2]]}function qw(e){return[e[0],e[1]]}var Jw={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function Yw(e){if(typeof e==`string`){let t=Jw[e];if(!t)throw Error(`Unknown direction: ${e}`);return t}return e}function Xw(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function Zw(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function Qw(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function $w(e){return[-e[0],-e[1],-e[2]]}function eT(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function tT(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function nT(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function rT(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function iT(e,t){return nT(Zw(e,t))}function aT(e){let t=nT(e);return t<1e-10?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function oT(e,t,n=1e-5){return Math.abs(e[0]-t[0])<n&&Math.abs(e[1]-t[1])<n&&Math.abs(e[2]-t[2])<n}function sT(e,t=1e-10){return rT(e)<t*t}function cT(e,t){let n=eT(e,t),r=nT(e),i=nT(t);if(r<1e-10||i<1e-10)return 0;let a=Math.max(-1,Math.min(1,n/(r*i)));return Math.acos(a)}function lT(e,t,n){let r=Zw(e,t),i=rT(n);return i<1e-20?e:Zw(e,Qw(n,eT(r,n)/i))}function uT(e,t,n){let r=aT(t),i=Math.cos(n),a=Math.sin(n),o=eT(e,r),s=tT(r,e);return[e[0]*i+s[0]*a+r[0]*o*(1-i),e[1]*i+s[1]*a+r[1]*o*(1-i),e[2]*i+s[2]*a+r[2]*o*(1-i)]}var dT=e=>Math.round(e*1e3)/1e3;function fT(e){return`x: ${dT(e[0])}, y: ${dT(e[1])}, z: ${dT(e[2])}`}function pT(e,t=null,n=[0,0,1]){let r=aT(n);if(sT(r))throw Error(`Plane normal must be non-zero`);let i;if(t)i=aT(t);else{let[e,t,n]=r,a=Math.abs(e),o=Math.abs(t),s=Math.abs(n),c;c=a<=o&&a<=s?[1,0,0]:o<=s?[0,1,0]:[0,0,1];let l=c[1]*n-c[2]*t,u=c[2]*e-c[0]*n,d=c[0]*t-c[1]*e;i=Math.sqrt(l*l+u*u+d*d)>1e-12?aT([l,u,d]):[1,0,0]}if(sT(i))throw Error(`Plane xDir must be non-zero`);let a=aT(tT(r,i));return{origin:e,xDir:i,yDir:a,zDir:r}}var mT={XY:{xDir:[1,0,0],normal:[0,0,1]},YZ:{xDir:[0,1,0],normal:[1,0,0]},ZX:{xDir:[0,0,1],normal:[0,1,0]},XZ:{xDir:[1,0,0],normal:[0,-1,0]},YX:{xDir:[0,1,0],normal:[0,0,-1]},ZY:{xDir:[0,0,1],normal:[-1,0,0]},front:{xDir:[1,0,0],normal:[0,0,1]},back:{xDir:[-1,0,0],normal:[0,0,-1]},left:{xDir:[0,0,1],normal:[-1,0,0]},right:{xDir:[0,0,-1],normal:[1,0,0]},top:{xDir:[1,0,0],normal:[0,1,0]},bottom:{xDir:[1,0,0],normal:[0,-1,0]}};function hT(e,t=[0,0,0]){let n=mT[e];if(!n)return k(F(`UNKNOWN_PLANE`,`Could not find plane ${e}`));let r;return r=typeof t==`number`?Qw(n.normal,t):Kw(t),O(pT(r,n.xDir,n.normal))}function gT(e,t){return typeof e==`string`?hT(e,t):O(e)}function _T(e,t){return e&&typeof e!=`string`?{...e}:j(gT(e??`XY`,t))}function vT(e,t){let[n,r]=t;return Xw(Xw(e.origin,Qw(e.xDir,n)),Qw(e.yDir,r))}function yT(e,t){return{...e,origin:Xw(e.origin,t)}}function bT(e,t,n=[1,0,0]){let r=t*Ww,i=uT(e.zDir,n,r),a=uT(e.xDir,n,r),o=aT(tT(i,a));return{origin:e.origin,xDir:a,yDir:o,zDir:i}}var xT={compound:0,solidCompound:1,solid:2,shell:3,face:4,wire:5,edge:6,vertex:7,shape:8},ST=e=>xT[e],CT={vertex:`vertex`,edge:`edge`,wire:`wire`,face:`face`,shell:`shell`,solid:`solid`,solidCompound:`compsolid`,compound:`compound`,shape:`compound`},wT=function*(e,t){let n=CT[t];if(n){let t=U().iterShapes(e,n);for(let e of t)yield e}},TT=e=>U().isNull(e)?k(za(`NULL_SHAPE`,`This shape has no type, it is null`)):O(e.ShapeType());function ET(e){if(U().isNull(e))return k(za(`NULL_SHAPE`,`This shape has no type, it is null`));try{return O(U().downcast(e))}catch{return k(za(`NO_WRAPPER`,`Could not find a wrapper for this shape type`))}}function DT(e){return U().isNull(e)?k(za(`NULL_SHAPE`,`Cannot cast a null shape`)):O(W(e))}function OT(e){return U().shapeType(e.wrapped)===`compsolid`}function kT(e){return DT(U().fromBREP(e))}var AT={plane:`PLANE`,cylinder:`CYLINDRE`,cone:`CONE`,sphere:`SPHERE`,torus:`TORUS`,bezier:`BEZIER_SURFACE`,bspline:`BSPLINE_SURFACE`,revolution:`REVOLUTION_SURFACE`,extrusion:`EXTRUSION_SURFACE`,offset:`OFFSET_SURFACE`,other:`OTHER_SURFACE`};function jT(e){return O(AT[Bw(e)])}function MT(e){return j(jT(e))}function NT(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function PT(e){return W(U().reverseShape(e.wrapped))}function FT(e){return U().uvBounds(e.wrapped)}function IT(e,t,n){let r=FT(e),i=t*(r.uMax-r.uMin)+r.uMin,a=n*(r.vMax-r.vMin)+r.vMin;return U().pointOnSurface(e.wrapped,i,a)}function LT(e,t){let n=Kw(t);return U().uvFromPoint(e.wrapped,n)||[0,0]}function RT(e,t){let n=Kw(t);try{let t=n,r=U().uvFromPoint(e.wrapped,t);if(!r)return k(za(`PROJECTION_FAILED`,`No projection found on the face`));let i=U().projectPointOnFace(e.wrapped,t),a=n[0]-i[0],o=n[1]-i[1],s=n[2]-i[2];return O({uv:r,point:i,distance:Math.sqrt(a*a+o*o+s*s)})}catch(e){return k(za(`PROJECTION_FAILED`,`Point projection failed: ${e instanceof Error?e.message:String(e)}`))}}function zT(e,t){let n,r;if(t)[n,r]=LT(e,t);else{let t=FT(e);n=.5*(t.uMin+t.uMax),r=.5*(t.vMin+t.vMax)}return U().surfaceNormal(e.wrapped,n,r)}function BT(e){return U().surfaceCenterOfMass(e.wrapped)}function VT(e,t,n=1e-6){let[r,i]=LT(e,t);return U().classifyPointOnFace(e.wrapped,r,i,n)}function HT(e){return W(U().outerWire(e.wrapped))}function UT(e){return W(U().removeHolesFromFace(e.wrapped))}function WT(e){let t=HT(e);return Array.from(wT(e.wrapped,`wire`)).map(e=>W(j(ET(e)))).filter(e=>!U().isSame(e.wrapped,t.wrapped))}function GT(e,t){let n=xw(e),r=new Map;for(let n of Tw(e))r.set(U().hashCode(n.wrapped,G),t);n.faceOrigins=r}function KT(e){return Sw(e)?.faceOrigins}function qT(e,t,n){let r=new Map;for(let e of t){let t=KT(e);if(t)for(let[e,n]of t)r.set(e,n)}if(r.size===0)return;let i=new Map;for(let[t,n]of r){if(e.deleted.has(t))continue;let r=e.modified.get(t);if(r&&r.length>0)for(let e of r)i.set(e,n);else i.set(t,n);let a=e.generated.get(t);if(a)for(let e of a)i.has(e)||i.set(e,0)}if(i.size>0){let e=xw(n);e.faceOrigins=i}}function JT(e,t,n){let r=-1/0,i;for(let a of n){let n=e[0]*a.normal[0]+e[1]*a.normal[1]+e[2]*a.normal[2];if(n<.707)continue;let o=t[0]-a.centroid[0],s=t[1]-a.centroid[1],c=t[2]-a.centroid[2],l=o*o+s*s+c*c;if(l>100)continue;let u=n-l/100;u>r&&(r=u,i=a.origin)}return i}function YT(e,t){let n=new Map;for(let t of e){let e=KT(t);if(e)for(let[t,r]of e)n.set(t,r)}if(n.size===0)return;let r=U(),i=new Map,a=Tw(t),o=[];for(let e of a){let t=r.hashCode(e.wrapped,G),a=n.get(t);a===void 0?o.push(e):i.set(t,a)}if(o.length>0){let t=[];for(let n of e){let e=KT(n);if(e)for(let i of Tw(n)){let n=r.hashCode(i.wrapped,G),a=e.get(n);if(a!==void 0)try{let e=r.uvBounds(i.wrapped),n=r.surfaceNormal(i.wrapped,.5*(e.uMin+e.uMax),.5*(e.vMin+e.vMax)),o=r.surfaceCenterOfMass(i.wrapped);t.push({origin:a,normal:n,centroid:o})}catch{}}}if(t.length>0)for(let e of o){let n=r.hashCode(e.wrapped,G);try{let a=r.uvBounds(e.wrapped),o=JT(r.surfaceNormal(e.wrapped,.5*(a.uMin+a.uMax),.5*(a.vMin+a.vMax)),r.surfaceCenterOfMass(e.wrapped),t);o!==void 0&&i.set(n,o)}catch{}}}if(i.size>0){let e=xw(t);e.faceOrigins=i}}var XT=new WeakMap,ZT=new WeakMap;function QT(e){return XT.has(e.wrapped)}function $T(e){let t=XT.get(e.wrapped);return t||(t=new Map,XT.set(e.wrapped,t)),t}function eE(e){let t=ZT.get(e.wrapped);return t||(t=new Map,ZT.set(e.wrapped,t)),t}function tE(e,t,n){let r=Array.isArray(t)?t:Tw(e).filter(t),i=$T(e),a=i.get(n)??new Set;for(let e of r)a.add(U().hashCode(e.wrapped,G));return i.set(n,a),e}function nE(e,t){let n=XT.get(e.wrapped);if(!n)return[];let r=n.get(t);if(!r||r.size===0)return[];let i=[];for(let t of Tw(e)){let e=U().hashCode(t.wrapped,G);r.has(e)&&i.push(t)}return i}function rE(e){let t=new Map,n=XT.get(e.wrapped);if(!n)return t;let r=Tw(e),i=new Map;for(let e of r)i.set(U().hashCode(e.wrapped,G),e);for(let[e,r]of n){let n=[];for(let e of r){let t=i.get(e);t&&n.push(t)}n.length>0&&t.set(e,n)}return t}function iE(e,t,n){return eE(e).set(t,n),e}function aE(e,t){return ZT.get(e.wrapped)?.get(t)}function oE(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function sE(e,t,n){let r=$T(n);for(let i of t){let t=XT.get(i.wrapped);if(!t)continue;let a=new Map;for(let[e,n]of t)for(let t of n){let n=a.get(t)??[];n.push(e),a.set(t,n)}for(let[t,n]of a){if(e.deleted.has(t))continue;let i=e.modified.get(t),a=i&&i.length>0?i:[t];for(let e of a)for(let t of n)oE(r,t,e)}let o=ZT.get(i.wrapped);if(o){let e=eE(n);for(let[t,n]of o)e.has(t)||e.set(t,n)}}}var cE=new WeakMap,lE=new WeakMap;function uE(e){return cE.has(e.wrapped)||lE.has(e.wrapped)}function dE(e){let t=lE.get(e.wrapped);return t||(t=new Map,lE.set(e.wrapped,t)),t}function fE(e){if(typeof e==`string`){let t=e.startsWith(`#`)?e.slice(1):e;return t.length===3&&(t=t.charAt(0)+t.charAt(0)+t.charAt(1)+t.charAt(1)+t.charAt(2)+t.charAt(2)),[parseInt(t.slice(0,2),16)/255,parseInt(t.slice(2,4),16)/255,parseInt(t.slice(4,6),16)/255,1]}return e.length===3?[e[0],e[1],e[2],1]:[e[0],e[1],e[2],e[3]]}function pE(e,t){return cE.set(e.wrapped,fE(t)),e}function mE(e,t,n){let r=fE(n),i=dE(e);for(let e of t)i.set(U().hashCode(e.wrapped,G),r);return e}function hE(e){return cE.get(e.wrapped)}function gE(e,t){let n=lE.get(e.wrapped);if(n)return n.get(U().hashCode(t.wrapped,G))}function _E(e,t,n){for(let e of t){let t=cE.get(e.wrapped);if(t){cE.set(n.wrapped,t);break}}let r=dE(n);for(let n of t){let t=lE.get(n.wrapped);if(!(!t||t.size===0))for(let[n,i]of t){if(e.deleted.has(n))continue;let t=e.modified.get(n);if(t&&t.length>0)for(let e of t)r.set(e,i);else r.set(n,i)}}}function vE(e){if(!e.some(e=>KT(e)!==void 0||QT(e)||uE(e)))return[];let t=U(),n=[];for(let r of e){let e=t.iterShapes(r.wrapped,`face`);for(let r of e)n.push(t.hashCode(r,G))}return n}function yE(e,t,n){qT(e,t,n),sE(e,t,n),_E(e,t,n)}function bE(e,t){YT(e,t)}function xE(e,t){let n=vE([e]),{shape:r,evolution:i}=U().translateWithHistory(e.wrapped,t[0],t[1],t[2],n,G),a=W(r);return yE(i,[e],a),a}function SE(e,t,n=[0,0,0],r=[0,0,1]){let i=vE([e]),{shape:a,evolution:o}=U().rotateWithHistory(e.wrapped,t*Ww,i,G,r,n),s=W(a);return yE(o,[e],s),s}function CE(e,t=[0,1,0],n=[0,0,0]){let r=vE([e]),{shape:i,evolution:a}=U().mirrorWithHistory(e.wrapped,n,t,r,G),o=W(i);return yE(a,[e],o),o}function wE(e,t,n=[0,0,0]){let r=vE([e]),{shape:i,evolution:a}=U().scaleWithHistory(e.wrapped,n,t,r,G),o=W(i);return yE(a,[e],o),o}function TE(e,t,n){let r=U().boundingBox(e.wrapped),i=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]],a=n?.auto===!0;function o(e,t,n){return e!==void 0&&t>1e-12?e/t:e===void 0&&a?n:1}let s=1;a&&(t[0]!==void 0&&i[0]>1e-12?s=t[0]/i[0]:t[1]!==void 0&&i[1]>1e-12?s=t[1]/i[1]:t[2]!==void 0&&i[2]>1e-12&&(s=t[2]/i[2]));let c=[o(t[0],i[0],s),o(t[1],i[1],s),o(t[2],i[2],s)];return Math.abs(c[0]-c[1])<1e-6&&Math.abs(c[1]-c[2])<1e-6?O(wE(e,c[0])):k(F(N.VALIDATION_FAILED,`resize: non-uniform scaling is not supported (WASM build lacks BRepBuilderAPI_GTransform).`,void 0,void 0,`Use auto: true to scale proportionally, or set all three dimensions to achieve uniform scaling.`))}function EE(e){if(`linear`in e)return O({linear:e.linear,translation:e.translation});let[t,n,r,i]=e,a=1e-10;return Math.abs(i[0])>a||Math.abs(i[1])>a||Math.abs(i[2])>a||Math.abs(i[3]-1)>a?k(F(N.VALIDATION_FAILED,`applyMatrix: invalid bottom row [${String(i[0])}, ${String(i[1])}, ${String(i[2])}, ${String(i[3])}]. Must be [0, 0, 0, 1] for an affine transform.`)):O({linear:[t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]],translation:[t[3],n[3],r[3]]})}function DE(e){return e[0]*(e[4]*e[8]-e[5]*e[7])-e[1]*(e[3]*e[8]-e[5]*e[6])+e[2]*(e[3]*e[7]-e[4]*e[6])}function OE(e){let t=1e-8,n=e[0]*e[0]+e[3]*e[3]+e[6]*e[6],r=e[1]*e[1]+e[4]*e[4]+e[7]*e[7],i=e[2]*e[2]+e[5]*e[5]+e[8]*e[8],a=e[0]*e[1]+e[3]*e[4]+e[6]*e[7],o=e[0]*e[2]+e[3]*e[5]+e[6]*e[8],s=e[1]*e[2]+e[4]*e[5]+e[7]*e[8];return!(Math.abs(a)>t||Math.abs(o)>t||Math.abs(s)>t||Math.abs(n-r)>t||Math.abs(n-i)>t)}function kE(e,t){let n=EE(t);if(!n.ok)return n;let{linear:r,translation:i}=n.value,a=DE(r);if(Math.abs(a)<1e-12)return k(F(N.VALIDATION_FAILED,`applyMatrix: singular matrix (determinant ≈ 0). Cannot apply a non-invertible transform.`));if(OE(r)){let t=vE([e]),{shape:n,evolution:a}=U().generalTransformWithHistory(e.wrapped,r,i,!0,t,G),o=W(n);return yE(a,[e],o),O(o)}let o=W(U().generalTransformNonOrthogonal(e.wrapped,r,i));return bE([e],o),O(o)}function AE(e){let t=e.map(e=>e.type===`translate`?{type:`translate`,x:e.v[0],y:e.v[1],z:e.v[2]}:{type:`rotate`,angle:e.angle,axis:e.axis,center:e.center}),{handle:n,dispose:r}=U().composeTransform(t);return{trsf:n,cleanup:r}}function jE(e,t){let n=vE([e]),{shape:r,evolution:i}=U().applyComposedTransformWithHistory(e.wrapped,t.trsf,n,G),a=W(r);return yE(i,[e],a),a}function ME(e){return gw(()=>U().downcast(e.wrapped),N.CLONE_FAILED,`Failed to clone shape`)}function NE(e){return _w(()=>U().toBREP(e.wrapped),N.TO_BREP_FAILED,`Failed to serialize shape to BREP`)}function PE(e){return U().hashCode(e.wrapped,G)}function FE(e){return U().isNull(e.wrapped)}function IE(e,t){return U().isSame(e.wrapped,t.wrapped)}function LE(e,t){return U().isEqual(e.wrapped,t.wrapped)}function RE(e){return gw(()=>U().simplify(e.wrapped),N.SIMPLIFY_FAILED,`Failed to simplify shape`)}function zE(e){return U().curveType(e.wrapped)}function BE(e){let[t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function VE(e){let[,t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function HE(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curvePointAtParam(e.wrapped,i)}function UE(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curveTangent(e.wrapped,i).tangent}function WE(e){return U().length(e.wrapped)}function GE(e){return U().curveIsClosed(e.wrapped)}function KE(e){return U().curveIsPeriodic(e.wrapped)}function qE(e){return U().curvePeriod(e.wrapped)}function JE(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function YE(e){return W(U().reverseShape(e.wrapped))}function XE(e,t={}){if(e.length<2)return k(za(`INTERPOLATE_MIN_POINTS`,`Interpolation requires at least 2 points`));try{let n=W(U().interpolatePoints(e,t));return iw(n)?O(n):k(za(`INTERPOLATE_NOT_EDGE`,`Interpolation did not produce an edge`))}catch(e){return k(za(`INTERPOLATE_FAILED`,`Interpolation failed: ${e instanceof Error?e.message:String(e)}`))}}function ZE(e,t={}){if(e.length<2)return k(za(`APPROXIMATE_MIN_POINTS`,`Approximation requires at least 2 points`));try{let n=W(U().approximatePoints(e,t));return iw(n)?O(n):k(za(`APPROXIMATE_NOT_EDGE`,`Approximation did not produce an edge`))}catch(e){return k(za(`APPROXIMATE_FAILED`,`Approximation failed: ${e instanceof Error?e.message:String(e)}`))}}function QE(e,t,n=`arc`){let r=W(U().offsetWire2D(e.wrapped,t,{arc:`arc`,intersection:`intersection`,tangent:`tangent`,chamfer:`intersection`}[n]));return aw(r)?O(r):(r[Symbol.dispose](),k(za(`OFFSET_NOT_WIRE`,`Offset did not produce a Wire`)))}function $E(e,t,n,r=!1){return`${e}:${t}:${n}:${r}`}function eD(e,t){return`edge:${e}:${t}`}var tD=new WeakMap,nD=new WeakMap;function rD(e,t){let n=tD.get(e);if(n)return n.get(t)}function iD(e,t,n){let r=tD.get(e);r||(r=new Map,tD.set(e,r)),r.set(t,n)}function aD(e,t){let n=nD.get(e);if(n)return n.get(t)}function oD(e,t,n){let r=nD.get(e);r||(r=new Map,nD.set(e,r)),r.set(t,n)}function sD(){tD=new WeakMap,nD=new WeakMap}function cD(){let e=new WeakMap,t=new WeakMap;return{getMesh(t,n){return e.get(t)?.get(n)},setMesh(t,n,r){let i=e.get(t);i||(i=new Map,e.set(t,i)),i.set(n,r)},getEdgeMesh(e,n){return t.get(e)?.get(n)},setEdgeMesh(e,n,r){let i=t.get(e);i||(i=new Map,t.set(e,i)),i.set(n,r)},clear(){e=new WeakMap,t=new WeakMap}}}function lD(e,{tolerance:t=.001,angularTolerance:n=.1,skipNormals:r=!1,includeUVs:i=!1,cache:a=!0,signal:o}={}){o?.throwIfAborted();let s=$E(t,n,r,i);if(a){let t=rD(e.wrapped,s);if(t)return t}let c=U().mesh(e.wrapped,{tolerance:t,angularTolerance:n,skipNormals:r,includeUVs:i,...o?{signal:o}:{}}),l=KT(e),u={vertices:c.vertices,normals:c.normals,triangles:c.triangles,uvs:c.uvs,faceGroups:c.faceGroups.map(e=>({start:e.start,count:e.count,faceId:e.faceHash,origin:l?.get(e.faceHash)??0}))};return a&&iD(e.wrapped,s,u),u}function uD(e,{tolerance:t=.001,angularTolerance:n=.1,cache:r=!0}={}){let i=eD(t,n);if(r){let t=aD(e.wrapped,i);if(t)return t}let a=U().meshEdges(e.wrapped,t,n),o={lines:a.lines,edgeGroups:a.edgeGroups.map(e=>({start:e.start,count:e.count,edgeId:e.edgeHash}))};return r&&oD(e.wrapped,i,o),o}function dD(e,t){return e instanceof Error&&e.message.startsWith(`${t} export failed`)?Ua(`${t}_EXPORT_FAILED`,`Failed to write ${t} file`,e):e instanceof WebAssembly.RuntimeError?Ua(`${t}_EXPORT_CRASHED`,`${t} export crashed the kernel (${e.message}); the shape likely contains geometry the ${t} writer cannot serialize`,e):Ua(`${t}_FILE_READ_ERROR`,`Failed to read exported ${t} file`,e)}function fD(e){let t;try{t=Ow(e)}catch{return``}if(t.length<=1)return``;let n=[];return t.forEach((e,t)=>{try{Rw(e)}catch(e){if(e instanceof TypeError)throw e;n.push(t)}}),n.length===0?`; could not localize the offending sub-solid among ${t.length} solids`:`; offending sub-solid${n.length>1?`s`:``} (of ${t.length}): index ${n.join(`, `)}`}function pD(e,t){try{return Rw(e),null}catch(n){if(n instanceof TypeError)throw n;return Ua(`${t}_EXPORT_UNSERIALIZABLE`,`${t} export aborted: the shape contains degenerate geometry the ${t} writer cannot serialize (bounding-box evaluation failed); export was skipped to avoid crashing the kernel${fD(e)}`,n)}}function mD(e){let t=pD(e,`STEP`);if(t)return k(t);try{let t=U().exportSTEP([e.wrapped]);return O(new Blob([t],{type:`application/STEP`}))}catch(e){return k(dD(e,`STEP`))}}function hD(e,{tolerance:t=.001,angularTolerance:n=.1,binary:r=!1}={}){let i=pD(e,`STL`);if(i)return k(i);try{U().hasTriangulation(e.wrapped)||U().meshShape(e.wrapped,t,n);let i=U().exportSTL(e.wrapped,r,t,n);return O(new Blob([i],{type:`application/sla`}))}catch(e){return k(dD(e,`STL`))}}function gD(e){try{let t=U().exportIGES([e.wrapped]);return O(new Blob([t],{type:`application/iges`}))}catch(e){return k(Ua(`IGES_EXPORT_FAILED`,`Failed to write IGES file`,e))}}function _D(e,t){let n=t?.coarseTolerance??.5,r=t?.fineTolerance??.05,i=t?.angularTolerance??.5;return{coarse:lD(e,{tolerance:n,angularTolerance:i}),fine:lD(e,{tolerance:r,angularTolerance:i*.2})}}function vD(e,t,n){if(t<0||t>=e.length)throw Error(n??`Index ${t} out of bounds (length ${e.length})`);return e[t]}function yD(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[0]}function bD(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[e.length-1]}function xD(e){return Array.from(Array(e).keys())}function SD(e){return xD(Math.min(...e.map(e=>e.length))).map(t=>e.map(e=>e[t]))}function CD(e,t){return XC(U().makeLineEdge([...e],[...t]))}function wD(e,t=[0,0,0],n=[0,0,1]){return XC(U().makeCircleEdge([...t],[...n],e))}function TD(e,t,n=[0,0,0],r=[0,0,1],i){return t>e?k(F(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(XC(U().makeEllipseEdge([...n],[...r],e,t,i?[...i]:void 0)))}function ED(e,t,n,r=[0,0,0],i=[0,0,1],a=!1){return ZC(U().makeHelixWire(e,t,n,[...r],[...i],a))}function DD(e,t,n){return XC(U().makeArcEdge([...e],[...t],[...n]))}function OD(e,t,n,r,i=[0,0,0],a=[0,0,1],o){return t>e?k(F(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(XC(U().makeEllipseArc([...i],[...a],e,t,n,r,o?[...o]:void 0)))}function kD(e,{tolerance:t=.001,smoothing:n=null,degMax:r=6,degMin:i=1}={}){try{let a=e.map(e=>[...e]);return O(XC(U().approximatePoints(a,{tolerance:t,degMin:i,degMax:r,smoothing:n})))}catch{return k(P(`BSPLINE_FAILED`,`B-spline approximation failed`))}}function AD(e,{periodic:t=!1,tolerance:n=1e-7}={}){try{let r=e.map(e=>[...e]);return O(XC(U().interpolatePoints(r,{periodic:t,tolerance:n})))}catch{return k(P(`BSPLINE_INTERP_FAILED`,`B-spline interpolation failed`))}}function jD(e){if(e.length<2)return k(F(`BEZIER_MIN_POINTS`,`Need at least 2 points for a Bezier curve, got ${e.length}`,void 0,{pointCount:e.length}));let t=e.map(e=>[...e]);return O(XC(U().makeBezierEdge(t)))}function MD(e,t,n){return XC(U().makeTangentArc([...e],[...t],[...n]))}function ND(e){try{return O(ZC(U().makeWireFromMixed(e.map(e=>e.wrapped))))}catch(e){return k(P(`WIRE_BUILD_FAILED`,`Failed to build the wire: ${e instanceof Error?e.message:`unknown error`}`))}}function PD(e,t){try{let n=U().makeFace(e.wrapped,!0);if(t&&t.length>0){let e=RD(QC(n),t);return WC(e)?O(e):k(F(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}let r=QC(n);return WC(r)?O(r):k(F(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}catch{return k(P(`FACE_BUILD_FAILED`,`Failed to build the face. Your wire might be non planar.`))}}function FD(e){return PD(HT(e))}function ID(e,t){return QC(U().makeFaceOnSurface(e.wrapped,t.wrapped))}function LD(e){try{return pa(DT(U().makeNonPlanarFace(e.wrapped)),e=>ow(e)?O(e):k(P(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`)))}catch{return k(P(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`))}}function RD(e,t){return QC(U().addHolesInFace(e.wrapped,t.map(e=>e.wrapped)))}function zD(e){return e.length<3?k(F(`POLYGON_MIN_POINTS`,`You need at least 3 points to make a polygon`)):pa(ND(SD([e,[...e.slice(1),e[0]]]).map(([e,t])=>CD(e,t))),e=>PD(e))}function BD(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function VD(e,t,n,r,i){let a=W(e);if(!uw(a)){let o=e.ShapeType(),s=[`COMPOUND`,`COMPSOLID`,`SOLID`,`SHELL`,`FACE`,`WIRE`,`EDGE`,`VERTEX`,`SHAPE`][o]??`UNKNOWN(${o})`;return a[Symbol.dispose](),k(za(t,`${n}. Got ${s} instead.`,void 0,i?{diagnostics:i}:void 0,r))}return O(a)}function HD(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;let c=BD(e,`fuse: first operand`);if(A(c))return c;let l=BD(t,`fuse: second operand`);if(A(l))return l;if(!s)return VD(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);let u=vE([e,t]),{shape:d,evolution:f,diagnostics:p}=U().fuseWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(U().isNull(d))return U().dispose(d),console.warn(`brepjs: fuse history path produced null result; retrying without evolution tracking.`,p),VD(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);console.warn(`brepjs: fuse reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=VD(d,`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`,`Common causes: overlapping coplanar faces, zero-thickness geometry, or non-manifold input. Try autoHeal() on inputs first.`,p);return m.ok&&yE(f,[e,t],m.value),m}function UD(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;let c=BD(e,`cut: base`);if(A(c))return c;let l=BD(t,`cut: tool`);if(A(l))return l;if(!s)return VD(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);let u=vE([e,t]),{shape:d,evolution:f,diagnostics:p}=U().cutWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(U().isNull(d))return U().dispose(d),console.warn(`brepjs: cut history path produced null result; retrying without evolution tracking.`,p),VD(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);console.warn(`brepjs: cut reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=VD(d,`CUT_NOT_3D`,`Cut did not produce a 3D shape`,`Common causes: tool does not fully intersect the base, or produces a zero-thickness sliver. Ensure the tool extends through the shape.`,p);return m.ok&&yE(f,[e,t],m.value),m}function WD(e,t,{simplify:n=!1,signal:r,fuzzyValue:i,unsafe:a,trackEvolution:o=!0}={}){if(r?.aborted)throw r.reason;let s=BD(e,`intersect: first operand`);if(A(s))return s;let c=BD(t,`intersect: second operand`);if(A(c))return c;if(!o)return VD(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);let l=vE([e,t]),{shape:u,evolution:d,diagnostics:f}=U().intersectWithHistory(e.wrapped,t.wrapped,l,G,{simplify:n,fuzzyValue:i});if(f.hasErrors){if(U().isNull(u))return U().dispose(u),console.warn(`brepjs: intersect history path produced null result; retrying without evolution tracking.`,f),VD(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);console.warn(`brepjs: intersect reported OCCT warnings/errors but produced a shape. Continuing with result.`,f)}let p=VD(u,`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`,`Shapes may not overlap. Verify they share a common volume before intersecting.`,f);return p.ok&&yE(d,[e,t],p.value),p}function GD(e,t,n,r,i,a,o,s){if(o?.aborted)throw o.reason;let c=n-t;if(c===1)return O(vD(e,t));if(c===2)return HD(vD(e,t),vD(e,t+1),{optimisation:r,simplify:!1,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}});let l=t+Math.ceil(c/2),u=GD(e,t,l,r,i,a,o,s);if(A(u))return u;let d=GD(e,l,n,r,i,a,o,s);return A(d)?d:HD(u.value,d.value,{optimisation:r,simplify:i,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}})}function KD(e,{optimisation:t=`none`,simplify:n=!1,strategy:r=`native`,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;if(e.length===0)return k(F(`FUSE_ALL_EMPTY`,`fuseAll requires at least one shape`));if(e.length===1)return O(yD(e));for(let t=0;t<e.length;t++){let n=BD(vD(e,t),`fuseAll: shape at index ${t}`);if(A(n))return n}if(r===`native`){let o=VD(U().fuseAll(e.map(e=>e.wrapped),{optimisation:t,simplify:n,strategy:r,fuzzyValue:a,...i?{signal:i}:{}}),`FUSE_ALL_NOT_3D`,`fuseAll did not produce a 3D shape`);return o.ok&&s&&bE(e,o.value),o}return GD(e,0,e.length,t,n,s,i,a)}function qD(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;if(t.length===0)return O(e);let c=BD(e,`cutAll: base`);if(A(c))return c;for(let e=0;e<t.length;e++){let n=BD(vD(t,e),`cutAll: tool at index ${e}`);if(A(n))return n}let l=[e,...t],u=VD(U().cutAll(e.wrapped,t.map(e=>e.wrapped),{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_ALL_NOT_3D`,`cutAll did not produce a 3D shape`);return u.ok&&s&&bE(l,u.value),u}function JD(e,t){let n=U(),r=Qw(e.xDir,t),i=Qw(e.yDir,t),a=Qw(e.xDir,-t),o=Qw(e.yDir,-t),s=e.origin,c=[...Xw(Xw(s,a),o)],l=[...Xw(Xw(s,r),o)],u=[...Xw(Xw(s,r),i)],d=[...Xw(Xw(s,a),i)],f=[n.makeLineEdge(c,l),n.makeLineEdge(l,u),n.makeLineEdge(u,d),n.makeLineEdge(d,c)],p=n.makeWire(f),m=n.makeFace(p,!0);for(let e of f)e.delete();return p.delete(),m}function YD(e,t,{approximation:n=!0,planeSize:r=1e4}={}){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`section: shape is a null shape`));let i=JD(typeof t==`string`?j(gT(t)):t,r);try{return O(W(U().section(e.wrapped,i,n)))}catch(e){let n=e instanceof Error?e.message:String(e),r=typeof t==`string`?t:`custom`;return k(P(`SECTION_FAILED`,`Section with ${r} plane failed: ${n}`,e,{operation:`section`,plane:r},`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`))}finally{i.delete()}}function XD(e){let t=U(),n=new Map,r=new Map;for(let i of e){let e=Dw(i),a=e[0]?t.hashCode(e[0].wrapped,G):-1,o=e.length>1&&e[1]?t.hashCode(e[1].wrapped,G):a;r.set(i,[a,o]);for(let e of[a,o]){let t=n.get(e)??[];t.push(i),n.set(e,t)}}return{vertexToEdges:n,edgeVertexHashes:r}}function ZD(e,t,n){let r=t.vertexToEdges.get(e);if(r)for(let i of r){if(n.has(i))continue;let r=t.edgeVertexHashes.get(i);if(r)return n.add(i),{edge:i,nextTip:r[0]===e?r[1]:r[0]}}}function QD(e,t,n){n.add(e);let r=[e],i=t.edgeVertexHashes.get(e);if(!i)return r;let a=[i[1],i[0]];for(let e=0;e<2;e++){let i=a[e];if(i===void 0)continue;let o=ZD(i,t,n);for(;o;)e===0?r.push(o.edge):r.unshift(o.edge),i=o.nextTip,o=ZD(i,t,n)}return r}function $D(e){let t=U(),n=XD(e),r=new Set,i=[];for(let a of e){if(r.has(a))continue;let e=QD(a,n,r);try{let n=t.makeWire(e.map(e=>e.wrapped));i.push(W(n))}catch{}}return i}function eO(e){let t=U(),n=0,r=-1;for(let i=0;i<e.length;i++){let a=e[i];if(!a)continue;let o=t.boundingBox(a.wrapped),s=o.max[0]-o.min[0],c=o.max[1]-o.min[1],l=o.max[2]-o.min[2],u=s*s+c*c+l*l;u>r&&(r=u,n=i)}return n}function tO(e,t,n={}){let r=YD(e,t,n);if(!r.ok)return r;let i=Ew(r.value);if(i.length===0){let e=ww(r.value);if(e.length===0)return k(P(`SECTION_FAILED`,`sectionToFace: section produced no geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));i.push(...$D(e))}if(i.length===0)return k(P(`SECTION_FAILED`,`sectionToFace: section produced no usable geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));let a=eO(i),o=vD(i,a),s=i.filter((e,t)=>t!==a);return PD(o,s.length>0?s:void 0)}function nO(e,t){if(t.length===0)return O(e);if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`split: shape is a null shape`));for(let e=0;e<t.length;e++)if(U().isNull(vD(t,e).wrapped))return k(F(N.NULL_SHAPE_INPUT,`splitShape: tool at index ${e} is a null shape`));try{return O(W(U().split(e.wrapped,t.map(e=>e.wrapped))))}catch(e){let n=e instanceof Error?e.message:String(e);return k(P(`SPLIT_FAILED`,`Split operation failed on ${t.length} tool(s): ${n}`,e,{operation:`split`,toolCount:t.length},`The splitting tools may not intersect the shape. Ensure tools cross through the shape's interior.`))}}function rO(e,t,n={}){let r=[];for(let i of t){let t=YD(e,i,n);if(A(t))return t;r.push(t.value)}return O(r)}function iO(e,t,n){if(t.length===0)return O(e);let r=n?.optimisation===`commonFace`?1:n?.optimisation===`sameFace`?2:0,i=U(),a=t.map(e=>({op:e.op,tool:e.tool.wrapped}));try{let o=i.booleanPipeline?.(e.wrapped,a,{glueMode:r});if(o===void 0)return aO(e,t,n);if(o===null)return k(P(`BOOLEAN_PIPELINE_FAILED`,`Boolean pipeline returned null shape`));let s=W(o);return uw(s)?O(s):k(za(`BOOLEAN_PIPELINE_NOT_3D`,`Pipeline result is not a 3D shape`))}catch(e){return k(P(`BOOLEAN_PIPELINE_FAILED`,e instanceof Error?e.message:String(e)))}}function aO(e,t,n){let r=e,i={...n?.optimisation?{optimisation:n.optimisation}:{},unsafe:!0};for(let e of t){let t=e.op===`fuse`?HD(r,e.tool,i):e.op===`cut`?UD(r,e.tool,i):WD(r,e.tool,i);if(A(t))return t;r=j(t)}return O(r)}function oO(e){return j(DT(j(ET(U().sew(e.map(e=>e.wrapped))))))}function sO(e,t=!1){let n=oO(e);return!t&&!sw(n)?k(za(`WELD_NOT_SHELL`,`Could not make a shell from faces and shells`)):O(n)}function cO(e,t,n=[0,0,0],r=[0,0,1]){return ew(U().makeCylinder(e,t,[...n],[...r]))}function lO(e){return ew(U().makeSphere(e))}function uO(e,t,n,r=[0,0,0],i=[0,0,1]){return ew(U().makeCone(e,t,n,[...r],[...i]))}function dO(e,t,n=[0,0,0],r=[0,0,1]){return ew(U().makeTorus(e,t,[...n],[...r]))}function fO(e,t,n){return ew(U().makeEllipsoid(e,t,n))}function pO(e){return YC(U().makeVertex(e[0],e[1],e[2]))}function mO(e,t,n=1e-6){return pa(ET(U().offset(e.wrapped,t,n)),e=>pa(DT(e),e=>uw(e)?O(e):k(za(`OFFSET_NOT_3D`,`Could not offset to a 3d shape`))))}function hO(e){return nw(U().makeCompound(e.map(e=>e.wrapped)))}function gO(e){let t=oO(e);return pa(DT(U().solidFromShell(t.wrapped)),e=>cw(e)?O(e):k(za(`SOLID_BUILD_FAILED`,`Could not make a solid of faces and shells`)))}function _O(e){return{position:e.vertices,normal:e.normals,index:e.triangles}}function vO(e){return{position:e.vertices,normal:e.normals,index:e.triangles,groups:e.faceGroups.map((e,t)=>({start:e.start,count:e.count,materialIndex:t,faceId:e.faceId}))}}function yO(e){return{position:e.lines}}function bO(e,t){return{coarse:_O(e.coarse),fine:_O(e.fine),coarseDistance:t?.coarse??50,fineDistance:t?.fine??0}}function xO(e,t,n,r){if(t.length===0)return k(F(`CHAMFER_ANGLE_NO_EDGES`,`chamferDistAngle requires at least one edge`,void 0,{edgeCount:0}));if(n<=0)return k(F(`CHAMFER_ANGLE_BAD_DISTANCE`,`distance must be positive, got ${n}`,void 0,{distance:n}));if(r<=0||r>=90)return k(F(`CHAMFER_ANGLE_BAD_ANGLE`,`angleDeg must be in range (0, 90), got ${r}`,void 0,{angleDeg:r}));let i;try{let a=U(),o=t.map(e=>e.wrapped);i=a.chamferDistAngle(e.wrapped,o,n,r)}catch(e){return k(P(`CHAMFER_ANGLE_FAILED`,`chamferDistAngle kernel call failed: ${e instanceof Error?e.message:String(e)}`,e,{distance:n,angleDeg:r,edgeCount:t.length}))}let a=ET(i);if(A(a))return a;let o=W(a.value);return uw(o)?O(o):(o[Symbol.dispose](),k(za(`CHAMFER_ANGLE_NOT_3D`,`chamferDistAngle did not produce a 3D shape`)))}function SO(e,t){return e.map(e=>pw(e,t))}function CO(e,t){let n=U(),r=n.iterShapes(e,t),i=[],a=new Map;for(let e of r){let t=n.hashCode(e,G),r=a.get(t);r?r.some(t=>n.isSame(t,e))||(r.push(e),i.push(e)):(a.set(t,[e]),i.push(e))}return SO(i,t)}function wO(e){let t=xw(e);if(t.edgeToFaces)return t.edgeToFaces;let n=U(),r=new Map,i=n.iterShapes(e.wrapped,`face`);for(let e of i){let t=n.iterShapes(e,`edge`);for(let i of t){let t=n.hashCode(i,G),a=r.get(t);a||(a=[],r.set(t,a)),a.some(t=>n.isSame(t.edge,i)&&n.isSame(t.face,e))||a.push({edge:i,face:e})}}return t.edgeToFaces=r,r}function TO(e,t){let n=U(),r=wO(e),i=n.hashCode(t.wrapped,G),a=r.get(i)??[],o=[],s=new Map;for(let e of a){if(!n.isSame(e.edge,t.wrapped))continue;let r=n.hashCode(e.face,G),i=s.get(r);i?i.some(t=>n.isSame(t,e.face))||(i.push(e.face),o.push(e.face)):(s.set(r,[e.face]),o.push(e.face))}return SO(o,`face`)}function EO(e){return CO(e.wrapped,`edge`)}function DO(e){return CO(e.wrapped,`wire`)}function OO(e){return CO(e.wrapped,`vertex`)}function kO(e,t){let n=U(),r=wO(e),i=CO(t.wrapped,`edge`),a=[],o=new Map;for(let e of i){let i=n.hashCode(e.wrapped,G),s=r.get(i)??[];for(let e of s){if(n.isSame(e.face,t.wrapped))continue;let r=n.hashCode(e.face,G),i=o.get(r);i?i.some(t=>n.isSame(t,e.face))||(i.push(e.face),a.push(e.face)):(o.set(r,[e.face]),a.push(e.face))}}return SO(a,`face`)}function AO(e,t){let n=U(),r=n.iterShapes(e.wrapped,`edge`),i=n.iterShapes(t.wrapped,`edge`),a=new Map;for(let e of i){let t=n.hashCode(e,G),r=a.get(t);r||(r=[],a.set(t,r)),r.push(e)}let o=[];for(let e of r)a.get(n.hashCode(e,2147483647))?.some(t=>n.isSame(e,t))&&o.push(e);return SO(o,`edge`)}function jO(e){let t=U();return t.getNurbsCurveData?t.getNurbsCurveData(e.wrapped):null}function MO(e){let t=U();return t.getNurbsSurfaceData?t.getNurbsSurfaceData(e.wrapped):null}var NO={cut:UD,cutAll:qD,fuse:HD,fuseAll:KD};function PO(e){return{totalInputs:e.totalInputs,batchAttempts:e.batchAttempts,batchSucceeded:e.batchSucceeded,singletonFallbacks:e.singletonFallbacks,failedInputs:[...e.failedInputs].sort((e,t)=>e-t)}}function FO(e,t,n={}){return IO(NO,e,t,n)}function IO(e,t,n,r={}){if(r.signal?.aborted)throw r.signal.reason;let i={totalInputs:n.length,batchAttempts:0,batchSucceeded:0,singletonFallbacks:0,failedInputs:new Set},a=LO(e,t,n,0,r,i);return A(a)?a:O({shape:a.value,telemetry:PO(i)})}function LO(e,t,n,r,i,a){if(n.length===0)return O(t);if(n.length===1)return RO(e,t,n,r,i,a);a.batchAttempts++;let o=UO(()=>e.cutAll(t,n,i));if(o&&o.ok)return a.batchSucceeded++,o;if(i.signal?.aborted)throw i.signal.reason;let s=Math.floor(n.length/2),c=LO(e,t,n.slice(0,s),r,i,a);return c.ok?LO(e,c.value,n.slice(s),r+s,i,a):c}function RO(e,t,n,r,i,a){a.singletonFallbacks++;let o=yD(n),s=UO(()=>e.cut(t,o,i));if(s&&s.ok)return s;if(i.signal?.aborted)throw i.signal.reason;return a.failedInputs.add(r),O(t)}function zO(e,t={}){return BO(NO,e,t)}function BO(e,t,n={}){if(n.signal?.aborted)throw n.signal.reason;if(t.length===0)return k(F(N.FUSE_ALL_EMPTY,`fuseAllBisect requires at least one shape`));let r={totalInputs:t.length,batchAttempts:0,batchSucceeded:0,singletonFallbacks:0,failedInputs:new Set},i=VO(e,t,0,n,r);return A(i)?i:O({shape:i.value,telemetry:PO(r)})}function VO(e,t,n,r,i){if(t.length===1)return O(yD(t));i.batchAttempts++;let a=UO(()=>e.fuseAll(t,r));if(a&&a.ok)return i.batchSucceeded++,a;if(r.signal?.aborted)throw r.signal.reason;let o=Math.floor(t.length/2);return HO(e,VO(e,t.slice(0,o),n,r,i),VO(e,t.slice(o),n+o,r,i),t,n,o,r,i)}function HO(e,t,n,r,i,a,o,s){if(t.ok&&n.ok){s.singletonFallbacks++;let c=UO(()=>e.fuse(t.value,n.value,o));if(c&&c.ok)return c;for(let e=a;e<r.length;e++)s.failedInputs.add(i+e);return t}if(t.ok){for(let e=a;e<r.length;e++)s.failedInputs.add(i+e);return t}if(n.ok){for(let e=0;e<a;e++)s.failedInputs.add(i+e);return n}return t}function UO(e){try{return e()}catch{return null}}function WO(e,t,n){return U().checkBoolean(e.wrapped,t.wrapped,n)}function GO(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function KO(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function qO(e,t,n,r){let i=W(e);if(!uw(i)){let a=e.ShapeType(),o=[`COMPOUND`,`COMPSOLID`,`SOLID`,`SHELL`,`FACE`,`WIRE`,`EDGE`,`VERTEX`,`SHAPE`][a]??`UNKNOWN(${a})`;return i[Symbol.dispose](),k(za(t,`${n}. Got ${o} instead.`,void 0,void 0,r))}return O(i)}function JO(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>r.get(U().hashCode(e,2147483647))??1}}function YO(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=GO(e,`fuseWithEvolution: first operand`);if(A(o))return o;let s=GO(t,`fuseWithEvolution: second operand`);if(A(s))return s;let c=vE([e,t]),{shape:l,evolution:u}=U().fuseWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=qO(l,`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`,`Common causes: overlapping coplanar faces, zero-thickness geometry, or non-manifold input. Try autoHeal() on inputs first.`);return d.ok?(yE(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function XO(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=GO(e,`cutWithEvolution: base`);if(A(o))return o;let s=GO(t,`cutWithEvolution: tool`);if(A(s))return s;let c=vE([e,t]),{shape:l,evolution:u}=U().cutWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=qO(l,`CUT_NOT_3D`,`Cut did not produce a 3D shape`,`Common causes: tool does not fully intersect the base, or produces a zero-thickness sliver. Ensure the tool extends through the shape.`);return d.ok?(yE(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function ZO(e,t,{simplify:n=!1,signal:r,fuzzyValue:i}={}){if(r?.aborted)throw r.reason;let a=GO(e,`intersectWithEvolution: first operand`);if(A(a))return a;let o=GO(t,`intersectWithEvolution: second operand`);if(A(o))return o;let s=vE([e,t]),{shape:c,evolution:l}=U().intersectWithHistory(e.wrapped,t.wrapped,s,G,{simplify:n,fuzzyValue:i}),u=qO(c,`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`,`Shapes may not overlap. Verify they share a common volume before intersecting.`);return u.ok?(yE(l,[e,t],u.value),O({shape:u.value,evolution:l})):u}function QO(e,t,n){let r=KO(e,`filletWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(F(`INVALID_FILLET_RADIUS`,`Fillet radius must be positive`,void 0,void 0,`Provide a positive radius value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(F(`INVALID_FILLET_RADIUS`,`Fillet radii must both be positive`,void 0,void 0,`Both radius values must be greater than 0`));let i=t??ww(e);if(i.length===0)return k(F(N.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));try{let t,r;if(typeof n==`function`){let e=JO(i,n);if(!e)return k(F(N.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=vE([e]),{shape:o,evolution:s}=U().filletWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return uw(c)?(yE(s,[e],c),O({shape:c,evolution:s})):k(P(N.FILLET_NOT_3D,`Fillet result is not a 3D shape`))}catch(e){return k(P(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:i.length,radius:n}))}}function $O(e,t,n){let r=KO(e,`chamferWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(F(`INVALID_CHAMFER_DISTANCE`,`Chamfer distance must be positive`,void 0,void 0,`Provide a positive distance value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(F(`INVALID_CHAMFER_DISTANCE`,`Chamfer distances must both be positive`,void 0,void 0,`Both distance values must be greater than 0`));let i=t??ww(e);if(i.length===0)return k(F(N.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=JO(i,n);if(!e)return k(F(N.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=vE([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return uw(c)?(yE(s,[e],c),O({shape:c,evolution:s})):k(P(N.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`))}catch(e){return k(P(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:i.length,distance:n}))}}function ek(e,t,n,r=.001){let i=KO(e,`shellWithEvolution: shape`);if(A(i))return i;if(n<=0)return k(F(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(F(`NO_FACES`,`At least one face must be specified for shell`));try{let i=vE([e]),{shape:a,evolution:o}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,i,G,r),s=W(a);return uw(s)?(yE(o,[e],s),O({shape:s,evolution:o})):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}catch(e){return k(P(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function tk(e,t,n){try{let r=W(U().positionOnCurve(e.wrapped,t.wrapped,n));return uw(r)?O(r):k(P(N.POSITION_ON_CURVE_FAILED,`positionOnCurve did not produce a 3D shape`))}catch(e){return k(P(N.POSITION_ON_CURVE_FAILED,`Failed to position shape on curve at param ${n}`,e))}}function nk(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function rk(e,t){if(typeof e==`number`&&e<=0)return k(F(t.code,t.scalar,void 0,void 0,t.scalarHint));if(Array.isArray(e)&&(e[0]<=0||e[1]<=0))return k(F(t.code,t.pair,void 0,void 0,t.pairHint))}function ik(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>{let t=r.get(U().hashCode(e,G));if(t===void 0)throw Error(`fillet/chamfer: edge hash not found — possible hash collision`);return t}}}function ak(e,t,n,r,i){let a=W(t);return uw(a)?(yE(e,n,a),O(a)):k(P(r,i))}function ok(e,t){if(typeof t!=`function`)return{filteredFaces:[...e],kernelAngle:t};let n=[],r=new Map;for(let i of e){let e=t(i);e===null||e===0||Math.abs(e)>=90||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return{filteredFaces:n,kernelAngle:e=>{let t=r.get(U().hashCode(e,G));if(t===void 0)throw Error(`draft: face hash not found — possible hash collision`);return t}}}function sk(e,t){let n=nk(e,`thicken: shape`);if(A(n))return n;try{let n=vE([e]),{shape:r,evolution:i}=U().thickenWithHistory(e.wrapped,t,n,G),a=W(r);return yE(i,[e],a),O(a)}catch(e){return k(P(`THICKEN_FAILED`,`Thicken operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function ck(e,t,n){let r=nk(e,`fillet: shape`);if(A(r))return r;let i=rk(n,{code:`INVALID_FILLET_RADIUS`,scalar:`Fillet radius must be positive`,pair:`Fillet radii must both be positive`,scalarHint:`Provide a positive radius value greater than 0`,pairHint:`Both radius values must be greater than 0`});if(i)return i;let a=t??ww(e);if(a.length===0)return k(F(N.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));if(typeof n==`function`){let e=ik(a,n);return e?O({filteredEdges:e.edges,kernelRadius:e.kernelParam,selectedCount:a.length}):k(F(N.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`))}return O({filteredEdges:[...a],kernelRadius:n,selectedCount:a.length})}function lk(e,t,n,{trackEvolution:r=!0}={}){let i=ck(e,t,n);if(A(i))return i;let{filteredEdges:a,kernelRadius:o,selectedCount:s}=i.value;try{let t=a.map(e=>e.wrapped);if(!r){let n=W(U().fillet(e.wrapped,t,o));return uw(n)?O(n):k(P(N.FILLET_NOT_3D,`Fillet result is not a 3D shape`))}let n=vE([e]),{shape:i,evolution:s}=U().filletWithHistory(e.wrapped,t,o,n,G);return ak(s,i,[e],N.FILLET_NOT_3D,`Fillet result is not a 3D shape`)}catch(e){return k(P(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:s,radius:n}))}}function uk(e,t,n){let r=nk(e,`chamfer: shape`);if(A(r))return r;let i=rk(n,{code:`INVALID_CHAMFER_DISTANCE`,scalar:`Chamfer distance must be positive`,pair:`Chamfer distances must both be positive`,scalarHint:`Provide a positive distance value greater than 0`,pairHint:`Both distance values must be greater than 0`});if(i)return i;let a=t??ww(e);if(a.length===0)return k(F(N.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=ik(a,n);if(!e)return k(F(N.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...a],r=n;let i=vE([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,i,G);return ak(s,o,[e],N.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)}catch(e){return k(P(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:a.length,distance:n}))}}function dk(e,t,n,r=.001,{trackEvolution:i=!0}={}){let a=nk(e,`shell: shape`);if(A(a))return a;if(n<=0)return k(F(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(F(`NO_FACES`,`At least one face must be specified for shell`));try{if(!i){let i=W(U().shell(e.wrapped,t.map(e=>e.wrapped),n,r));return uw(i)?O(i):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}let a=vE([e]),{shape:o,evolution:s}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,a,G,r),c=W(o);return uw(c)?(yE(s,[e],c),O(c)):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}catch(e){return k(P(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function fk(e,t,n=1e-6){let r=nk(e,`offset: shape`);if(A(r))return r;if(Math.abs(t)<1e-10)return k(F(`ZERO_OFFSET`,`Offset distance cannot be zero`));try{let r=vE([e]),{shape:i,evolution:a}=U().offsetWithHistory(e.wrapped,t,r,G,n),o=W(i);return uw(o)?(yE(a,[e],o),O(o)):k(P(`OFFSET_RESULT_NOT_3D`,`Offset result is not a 3D shape`))}catch(e){return k(P(`OFFSET_FAILED`,`Offset operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function pk(e,t,n){let r=nk(e,`draft: shape`);if(A(r))return r;if(typeof n==`number`){if(Math.abs(n)<1e-10)return k(F(N.DRAFT_INVALID_ANGLE,`Draft angle cannot be zero`,void 0,void 0,`Provide a non-zero angle in degrees`));if(Math.abs(n)>=90)return k(F(N.DRAFT_INVALID_ANGLE,`Draft angle must be between -90 and 90 degrees (exclusive)`,void 0,void 0,`Typical draft angles are 1-5 degrees for injection molding`))}if(t.length===0)return k(F(N.DRAFT_NO_FACES,`No faces specified for draft`,void 0,void 0,`Select at least one face to apply the draft angle to`))}function mk(e,t,n,r,i){let a=pk(e,t,i);if(a)return a;try{let{filteredFaces:a,kernelAngle:o}=ok(t,i);if(a.length===0)return k(F(N.DRAFT_NO_FACES,`No faces with valid draft angle`,void 0,void 0,`Check that the angle callback returns non-zero values between -90 and 90 degrees`));let s=vE([e]),{shape:c,evolution:l}=U().draftWithHistory(e.wrapped,a.map(e=>e.wrapped),[n[0],n[1],n[2]],[r[0],r[1],r[2]],o,s,G);return ak(l,c,[e],N.DRAFT_NOT_3D,`Draft result is not a 3D shape`)}catch(e){let n=e instanceof Error?e.message:String(e);return k(P(N.DRAFT_FAILED,`Draft operation failed: ${n}`,e,{operation:`draft`,faceCount:t.length,angle:i}))}}function hk(e,t,n){if(n.length===0)return k(F(N.VARIABLE_FILLET_FAILED,`radii must contain at least one radius spec`));for(let e of n)if(e.radius<=0)return k(F(N.VARIABLE_FILLET_FAILED,`All radius values must be positive`));let r=U();try{let i=JSON.stringify({edge:r.hashCode(t.wrapped,G),radii:n.map(e=>({param:e.param,radius:e.radius}))}),a=W(r.filletVariable(e.wrapped,i));return uw(a)?cw(a)?O(a):(a[Symbol.dispose](),k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a solid`))):(a[Symbol.dispose](),k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a 3D shape`)))}catch(e){return k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet failed`,e))}}function gk(e){return Vw(e)}function _k(e){if(!cw(e))return k(F(`NOT_A_SOLID`,`Input shape is not a solid`));let t=gk(e);try{let n=U().healSolid(e.wrapped);if(!n)return t?O(e):k(P(N.HEAL_NO_EFFECT,`Solid healing had no effect — shape is still invalid`));let r=W(n);return cw(r)?(Cw(r),gk(r)?O(r):k(P(`HEAL_SOLID_INCOMPLETE`,`Healed result is still invalid after ShapeFix_Solid`))):k(P(`HEAL_RESULT_NOT_SOLID`,`Healed result is not a solid`))}catch(e){return k(P(`HEAL_SOLID_FAILED`,`Solid healing failed`,e))}}function vk(e){if(!ow(e))return k(F(`NOT_A_FACE`,`Input shape is not a face`));try{let t=W(U().healFace(e.wrapped));return ow(t)?O(t):k(P(`HEAL_RESULT_NOT_FACE`,`Healed result is not a face`))}catch(e){return k(P(`HEAL_FACE_FAILED`,`Face healing failed`,e))}}function yk(e,t){if(!aw(e))return k(F(`NOT_A_WIRE`,`Input shape is not a wire`));try{let n=W(U().healWire(e.wrapped,t?.wrapped));return aw(n)?O(n):k(P(`HEAL_RESULT_NOT_WIRE`,`Healed result is not a wire`))}catch(e){return k(P(`HEAL_WIRE_FAILED`,`Wire healing failed`,e))}}function bk(e){return cw(e)?_k(e):ow(e)?vk(e):aw(e)?yk(e):O(e)}function xk(e,t){let n=t?.fixWires!==!1,r=t?.fixFaces!==!1,i=t?.fixSolids!==!1,a=t?.fixSelfIntersection===!0,o=t?.sewTolerance,s=[],c=[];if(gk(e))return O({shape:e,report:{isValid:!0,alreadyValid:!0,wiresHealed:0,facesHealed:0,solidHealed:!1,steps:[`Shape already valid`],diagnostics:[{name:`validation`,attempted:!0,succeeded:!0}]}});s.push(`Shape invalid — applying shape-level healing`);let l=Ew(e).length,u=Tw(e).length,d=e,f=!1;if(o!==void 0)try{d=W(U().sew([d.wrapped],o)),s.push(`Applied sewing with tolerance ${o}`),c.push({name:`sew`,attempted:!0,succeeded:!0,detail:`tolerance=${o}`})}catch(e){let t=e instanceof Error?e.message:String(e);s.push(`Sewing failed: ${t}`),c.push({name:`sew`,attempted:!0,succeeded:!1,detail:t})}if(a&&n){let e=Ew(d),t=0;for(let n of e)try{U().fixSelfIntersection(n.wrapped),t++}catch{}s.push(`Self-intersection fix: ${t}/${e.length} wires`),c.push({name:`fixSelfIntersection`,attempted:!0,succeeded:t>0,detail:`${t}/${e.length} wires fixed`})}if(cw(d)&&i||ow(d)&&r||aw(d)&&n){let t=bk(d);ua(t)?(d=t.value,cw(e)?(f=!0,s.push(`Applied ShapeFix_Solid`),c.push({name:`healSolid`,attempted:!0,succeeded:!0})):ow(e)?(s.push(`Applied ShapeFix_Face`),c.push({name:`healFace`,attempted:!0,succeeded:!0})):(s.push(`Applied ShapeFix_Wire`),c.push({name:`healWire`,attempted:!0,succeeded:!0}))):(s.push(`Shape-level healing failed`),c.push({name:`healShape`,attempted:!0,succeeded:!1}))}else c.push({name:`healShape`,attempted:!1,succeeded:!1,detail:`skipped by options`});let p=Ew(d).length,m=Tw(d).length,h=Math.abs(p-l),g=Math.abs(m-u);h>0&&s.push(`Wire count changed by ${h}`),g>0&&s.push(`Face count changed by ${g}`);let _=gk(d);return s.push(_?`Final validation: valid`:`Final validation: still invalid`),c.push({name:`finalValidation`,attempted:!0,succeeded:_}),O({shape:d,report:{isValid:_,alreadyValid:!1,wiresHealed:h,facesHealed:g,solidHealed:f,steps:s,diagnostics:c}})}function Sk(e){try{return O(W(U().fixShape(e.wrapped)))}catch(e){return k(P(N.FIX_SHAPE_FAILED,`ShapeFix_Shape failed`,e))}}function Ck(e){try{let t=W(U().solidFromShell(e.wrapped));return cw(t)?gk(t)?O(t):k(P(N.SOLID_FROM_SHELL_FAILED,`solidFromShell produced an invalid solid`)):k(P(N.SOLID_FROM_SHELL_FAILED,`solidFromShell did not produce a solid`))}catch(e){return k(P(N.SOLID_FROM_SHELL_FAILED,`Failed to create solid from shell`,e))}}function wk(e){try{let t=W(U().fixSelfIntersection(e.wrapped));return aw(t)?O(t):k(P(N.FIX_SELF_INTERSECTION_FAILED,`Result is not a wire`))}catch(e){return k(P(N.FIX_SELF_INTERSECTION_FAILED,`Failed to fix wire self-intersection`,e))}}function Tk(e,t,n,r){let i=ew(U().makeBox(e,t,n)),a=r?.at??(r?.centered?[0,0,0]:void 0);return a?xE(i,[a[0]-e/2,a[1]-t/2,a[2]-n/2]):i}function Ek(e,t,n){let r=n?.at??[0,0,0],i=n?.axis??[0,0,1],a=cO(e,t,r,i);if(n?.centered){let e=[-i[0]*t*.5,-i[1]*t*.5,-i[2]*t*.5];a=xE(a,e)}return a}function Dk(e,t){let n=lO(e);return t?.at&&(n=xE(n,t.at)),n}function Ok(e,t,n,r){let i=r?.at??[0,0,0],a=r?.axis??[0,0,1],o=uO(e,t,n,i,a);if(r?.centered){let e=[-a[0]*n*.5,-a[1]*n*.5,-a[2]*n*.5];o=xE(o,e)}return o}function kk(e,t,n){return dO(e,t,n?.at??[0,0,0],n?.axis??[0,0,1])}function Ak(e,t,n,r){let i=fO(e,t,n);return r?.at&&(i=xE(i,r.at)),i}function jk(e,t){return CD(e,t)}function Mk(e,t){let n=t?.axis??[0,0,1];return wD(e,t?.at??[0,0,0],n)}function Nk(e,t,n){let r=n?.axis??[0,0,1];return TD(e,t,n?.at??[0,0,0],r,n?.xDir)}function Pk(e,t,n,r){return ED(e,t,n,r?.at??[0,0,0],r?.axis??[0,0,1],r?.lefthand??!1)}function Fk(e,t,n){return DD(e,t,n)}function Ik(e,t,n,r,i){let a=i?.axis??[0,0,1];return OD(e,t,n*Ww,r*Ww,i?.at??[0,0,0],a,i?.xDir)}function Lk(e,t){return kD(e,t)}function Rk(e){return jD(e)}function zk(e,t,n){return MD(e,t,n)}function Bk(e){return ND(e)}function Vk(e){return pa(ND(e),e=>IC(e)?O(e):k(F(`WIRE_NOT_CLOSED`,`Assembled wire is not closed: start and end points do not coincide`)))}function Hk(e,t){return PD(e,t)}function Uk(e){return LD(e)}function Wk(e,t){return ID(e,t)}function Gk(e){return zD(e)}function Kk(e){return pO(e)}function qk(e){return hO(e)}function Jk(e){return gO(e)}function Yk(e,t,n){return mO(e,t,n)}function Xk(e,t){return sO(e,t)}function Zk(e,t){return RD(e,t)}function Qk(){return`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(Number(e)^crypto.getRandomValues(new Uint8Array(1))[0]&15>>Number(e)/4).toString(16))}function $k(e=[]){let t=e.map(({shape:e,name:t,color:n,alpha:r})=>{let i=n??`#f00`;i.indexOf(`#`)===0&&(i=i.slice(1)),i.length===3&&(i=i.replace(/([0-9a-f])/gi,`$1$1`));let a=parseInt(i.substring(0,2),16),o=parseInt(i.substring(2,4),16),s=parseInt(i.substring(4,6),16),c=Math.round((r??1)*255);return{shape:e.wrapped,name:t??Qk(),color:[a,o,s,c]}});return bC(U().createXCAFDocument(t))}function eA(e=[],{unit:t,modelUnit:n}={}){let r=e=>{let t=e;return t.indexOf(`#`)===0&&(t=t.slice(1)),t.length===3&&(t=t.replace(/([0-9a-f])/gi,`$1$1`)),[parseInt(t.substring(0,2),16),parseInt(t.substring(2,4),16),parseInt(t.substring(4,6),16)]},i=U(),a=e.map(({shape:e,name:t,color:n,alpha:i})=>{let[a,o,s]=r(n??`#f00`);return{shape:e.wrapped,name:t??Qk(),color:[a,o,s,Math.round((i??1)*255)]}}),o=i.createXCAFDocument(a);try{let e=i.writeXCAFToSTEP(o,{unit:t,modelUnit:n});return e?O(new Blob([e],{type:`application/STEP`})):k(Ua(`STEP_EXPORT_FAILED`,`Failed to write STEP file`))}finally{o.delete()}}function tA(e,t,n,r,i){if(n<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(sT(t))return k(F(`PATTERN_ZERO_DIRECTION`,`Pattern direction cannot be zero`));let a=aT(t);return KD(U().linearPattern(e.wrapped,[...a],r,n).map(e=>W(e)),{optimisation:`sameFace`,...i,unsafe:!0})}function nA(e,t,n,r=360,i=[0,0,0],a){if(n<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(sT(t))return k(F(`PATTERN_ZERO_AXIS`,`Pattern axis cannot be zero`));let o=r/n;return KD(U().circularPattern(e.wrapped,[...i],[...t],o,n).map(e=>W(e)),{optimisation:`sameFace`,...a,unsafe:!0})}function rA(e,t={}){return{name:e,children:[],...t.shape===void 0?{}:{shape:t.shape},...t.translate===void 0?{}:{translate:t.translate},...t.rotate===void 0?{}:{rotate:t.rotate},...t.metadata===void 0?{}:{metadata:t.metadata}}}function iA(e,t){return{...e,children:[...e.children,t]}}function aA(e,t){let n=e.children.findIndex(e=>e.name===t);if(n===-1)return e;let r=[...e.children];return r.splice(n,1),{...e,children:r}}function oA(e,t){return{...e,...t.shape===void 0?{}:{shape:t.shape},...t.translate===void 0?{}:{translate:t.translate},...t.rotate===void 0?{}:{rotate:t.rotate},...t.metadata===void 0?{}:{metadata:t.metadata}}}function sA(e,t){if(e.name===t)return e;for(let n of e.children){let e=sA(n,t);if(e)return e}}function cA(e,t,n=0){t(e,n);for(let r of e.children)cA(r,t,n+1)}function lA(e){let t=1;for(let n of e.children)t+=lA(n);return t}function uA(e){let t=[];return cA(e,e=>{e.shape&&t.push(e.shape)}),t}function dA(){return{steps:[],shapes:new Map}}function fA(e,t,n){let r={...t,timestamp:Date.now()},i=new Map(e.shapes);return i.set(t.outputId,n),{steps:[...e.steps,r],shapes:i}}function pA(e){if(e.steps.length===0)return e;let t=e.steps.slice(0,-1),n=new Set;for(let e of t){n.add(e.outputId);for(let t of e.inputIds)n.add(t)}let r=new Map;for(let[t,i]of e.shapes)n.has(t)&&r.set(t,i);return{steps:t,shapes:r}}function mA(e,t){return e.steps.find(e=>e.id===t)}function hA(e,t){return e.shapes.get(t)}function gA(e){return e.steps.length}function _A(e,t){let n=e.steps.findIndex(e=>e.id===t);return n===-1?[]:e.steps.slice(n)}function vA(e,t,n){let r=new Map(e.shapes);return r.set(t,n),{...e,shapes:r}}function yA(){return{operations:new Map}}function bA(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function xA(e,t){let n=new Set(e.steps.map(e=>e.outputId)),r={steps:[],shapes:new Map};for(let[t,i]of e.shapes)n.has(t)||(r=vA(r,t,i));for(let n of e.steps){let e=t.operations.get(n.type);if(!e)return k(Ha(`REPLAY_UNKNOWN_OP`,`Unknown operation type: ${n.type}`));let i=[];for(let e of n.inputIds){let t=r.shapes.get(e);if(!t)return k(Ha(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${n.id}`));i.push(t)}try{let t=e(i,n.parameters);r=fA(r,{id:n.id,type:n.type,parameters:n.parameters,inputIds:n.inputIds,outputId:n.outputId},t)}catch(e){return k(Ha(`REPLAY_STEP_FAILED`,`Step ${n.id} (${n.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(r)}function SA(e,t,n){let r=e.steps.findIndex(e=>e.id===t);if(r===-1)return k(Ha(`REPLAY_STEP_NOT_FOUND`,`Step not found: ${t}`));let i=new Map(e.shapes);for(let t=r;t<e.steps.length;t++){let n=e.steps[t];n&&i.delete(n.outputId)}let a={steps:e.steps.slice(0,r),shapes:i};for(let t=r;t<e.steps.length;t++){let r=e.steps[t];if(!r)continue;let i=n.operations.get(r.type);if(!i)return k(Ha(`REPLAY_UNKNOWN_OP`,`Unknown operation type: ${r.type}`));let o=[];for(let e of r.inputIds){let t=a.shapes.get(e);if(!t)return k(Ha(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${r.id}`));o.push(t)}try{let e=i(o,r.parameters);a=fA(a,{id:r.id,type:r.type,parameters:r.parameters,inputIds:r.inputIds,outputId:r.outputId},e)}catch(e){return k(Ha(`REPLAY_STEP_FAILED`,`Step ${r.id} (${r.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(a)}function CA(e,t,n,r){return e.steps.findIndex(e=>e.id===t)===-1?k(Ha(`MODIFY_STEP_NOT_FOUND`,`Step not found: ${t}`)):SA({steps:e.steps.map(e=>e.id===t?{...e,parameters:n}:e),shapes:e.shapes},t,r)}function wA(e){let t={};for(let[n,r]of e.shapes){let e=NE(r);if(!e.ok)return k(Ha(`SERIALIZE_SHAPE_FAILED`,`Failed to serialize shape "${n}": ${e.error.message}`));t[n]=e.value}return O({steps:e.steps,shapes:t})}function TA(e){let t=new Map;for(let[n,r]of Object.entries(e.shapes))try{let e=kT(r);if(!e.ok)return k(Ha(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e.error.message}`));t.set(n,e.value)}catch(e){return k(Ha(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e instanceof Error?e.message:String(e)}`))}return O({steps:e.steps,shapes:t})}var EA=new WeakMap;function DA(e,t){return EA.get(e)?.get(t)}function OA(e,t,n){let r=EA.get(e);r||(r=new Map,EA.set(e,r)),r.set(t,n)}function kA(e){return U().isNull(e.wrapped)}function AA(e){return k(F(N.NULL_SHAPE_INPUT,`${e}: shape is a null shape`))}function jA(e){let t=DA(e.wrapped,`volume`);if(t)return O(t);if(kA(e))return AA(`measureVolumeProps`);let n=U(),r=n.volume(e.wrapped),i=_w(()=>n.centerOfMass(e.wrapped),N.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!i.ok)return i;let a={mass:r,volume:r,centerOfMass:i.value};return OA(e.wrapped,`volume`,a),O(a)}function MA(e){let t=DA(e.wrapped,`surface`);if(t)return O(t);if(kA(e))return AA(`measureSurfaceProps`);let n=U(),r=n.area(e.wrapped),i=_w(()=>n.centerOfMass(e.wrapped),N.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!i.ok)return i;let a={mass:r,area:r,centerOfMass:i.value};return OA(e.wrapped,`surface`,a),O(a)}function NA(e){let t=DA(e.wrapped,`linear`);if(t)return O(t);if(kA(e))return AA(`measureLinearProps`);let n=U(),r=n.length(e.wrapped),i={mass:r,length:r,centerOfMass:n.linearCenterOfMass(e.wrapped)};return OA(e.wrapped,`linear`,i),O(i)}function PA(e){let t=jA(e);return t.ok?O(t.value.mass):t}function FA(e){let t=MA(e);return t.ok?O(t.value.mass):t}function IA(e){let t=NA(e);return t.ok?O(t.value.mass):t}function LA(e,t){return kA(e)||kA(t)?AA(`measureDistance`):O(U().distance(e.wrapped,t.wrapped).value)}function RA(e,t){if(kA(e)||kA(t))return AA(`measureDistanceProps`);let n=U().distance(e.wrapped,t.wrapped);return O({distance:n.value,point1:n.point1,point2:n.point2})}function zA(e){if(kA(e))return AA(`createDistanceQuery`);let t=U().createDistanceQuery(e.wrapped);return O({distanceTo(e){return kA(e)?AA(`createDistanceQuery.distanceTo`):O(t.distanceTo(e.wrapped).value)},dispose(){t.dispose()}})}function BA(e,t,n){if(kA(e))return AA(`measureCurvatureAt`);let r=U().surfaceCurvature(e.wrapped,t,n);return O({mean:r.mean,gaussian:r.gaussian,maxCurvature:r.max,minCurvature:r.min,maxDirection:r.maxDirection,minDirection:r.minDirection})}function VA(e){if(kA(e))return AA(`measureCurvatureAtMid`);let t=FT(e),n=(t.uMin+t.uMax)/2,r=(t.vMin+t.vMax)/2,i=U().surfaceCurvature(e.wrapped,n,r);return O({mean:i.mean,gaussian:i.gaussian,maxCurvature:i.max,minCurvature:i.min,maxDirection:i.maxDirection,minDirection:i.minDirection})}var HA=1e-9,UA=1e-8,WA=1e-6,GA=([e,t],[n,r],i=WA)=>Math.abs(e-n)<=i&&Math.abs(t-r)<=i,KA=([e,t],[n,r])=>[e+n,t+r],qA=([e,t],[n,r])=>[e-n,t-r],JA=([e,t],n)=>[e*n,t*n],YA=([e,t],[n,r]=[0,0])=>Math.sqrt((e-n)**2+(t-r)**2),XA=([e,t],[n,r]=[0,0])=>(e-n)**2+(t-r)**2;function ZA([e,t],[n,r]){return e*r-t*n}var QA=([e,t],[n,r]=[0,0])=>Math.atan2(r*e-t*n,e*n+t*r),$A=([e,t],[n,r]=[0,0])=>Math.atan2(r-t,n-e),ej=(e,t,n=[0,0])=>{let[r,i]=e,[a,o]=n,s=r-a,c=i-o,l=Math.sin(t),u=Math.cos(t),d=s*u-c*l,f=s*l+c*u;return[d+a,f+o]};function tj([e,t]){let n=Math.sqrt(e*e+t*t);return n<1e-12?[0,0]:[e/n,t/n]}var nj=(e,t)=>[Math.cos(t)*e,Math.sin(t)*e],rj=([e,t])=>[Math.sqrt(e*e+t*t),Math.atan2(t,e)],ij=([e,t])=>{let n=tj([e,t]);return n[0]===0&&n[1]===0&&M(`normalize2d`,`Cannot normalize zero-length vector`),n};function aj(e,t){let n,r=0;for(let i=0;i<e.length;i++){let a=e[i];if(t(a))if(r++,r===1)n=a;else break}return r===1?O(n):k(Wa(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found ${r===0?0:`2+`} element(s)`))}function oj(e,t,n,r){let i=e=>n([...t,e]),a=e=>t.every(t=>t(e));function o(t){switch(e){case`edge`:return ww(t);case`face`:return Tw(t);case`wire`:return Ew(t);case`vertex`:return Dw(t)}}let s=e=>{let n=o(e);return t.length===0?n.slice():n.filter(a)},c=()=>oj(e,[],n,r),l={_filters:t,_topoKind:e,when:e=>i(e),inList:e=>{let t=new Map;for(let n of e){let e=PE(n),r=t.get(e);r?r.push(n):t.set(e,[n])}return i(e=>{let n=t.get(PE(e));return!!n&&n.some(t=>IE(t,e))})},not:e=>{let t=e(c());return i(e=>!t.shouldKeep(e))},either:e=>{let t=e.map(e=>e(c()));return i(e=>t.some(t=>t.shouldKeep(e)))},findAll:e=>s(e),findUnique:e=>aj(o(e),a),shouldKeep:a,and:e=>i(t=>e.shouldKeep(t)),or:e=>{let t=a;return n([n=>t(n)||e.shouldKeep(n)])},negate:()=>{let e=a;return n([t=>!e(t)])}},u=r(l,i);return{...l,...u}}var sj={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function cj(e){return typeof e==`string`?sj[e]??[0,0,1]:e}function lj(e,t,n){let r=U(),i=r.makeVertex(t[0],t[1],t[2]);return t=>{let a=r.distance(i,t.wrapped).value;return Math.abs(a-e)<n}}function uj(e,t){let n=aT(cj(e));return e=>{let r=U(),[i,a]=r.curveParameters(e.wrapped),o=(i+a)/2,{tangent:s}=r.curveTangent(e.wrapped,o),c=aT(s),l=Math.acos(Math.min(1,Math.abs(eT(c,n))));return Math.abs(l-Ww*t)<1e-6}}function dj(e){return oj(`edge`,e,dj,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(uj(e,t)),ofLength:(e,t=.001)=>n(n=>Math.abs(WE(n)-e)<t),ofCurveType:e=>n(t=>zE(t)===e),parallelTo:(t=`Z`)=>dj(e).inDirection(t,0),atDistance:(e,t=[0,0,0])=>n(lj(e,t,1e-6))}))}function fj(){return dj([])}function pj(e,t){let n=aT(cj(e));return e=>{let r=zT(e),i=Math.acos(Math.min(1,Math.abs(eT(aT(r),n))));return Math.abs(i-Ww*t)<1e-6}}function mj(e){return oj(`face`,e,mj,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(pj(e,t)),parallelTo:(t=`Z`)=>mj(e).inDirection(t,0),ofSurfaceType:e=>n(t=>{let n=jT(t);return ua(n)&&n.value===e}),ofArea:(e,t=.001)=>n(n=>{let r=FA(n);return ua(r)&&Math.abs(r.value-e)<t}),atDistance:(e,t=[0,0,0])=>n(lj(e,t,1e-6))}))}function hj(){return mj([])}function gj(e){return oj(`wire`,e,gj,(e,t)=>({isClosed:()=>t(e=>GE(e)),isOpen:()=>t(e=>!GE(e)),ofEdgeCount:e=>t(t=>ww(t).length===e)}))}function _j(){return gj([])}function vj(e,t){return typeof e==`object`&&`_topoKind`in e?e.findUnique(t):typeof e!=`function`&&ow(e)?O(e):e(hj()).findUnique(t)}function yj(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`}function bj(e,t){let n=10**t,r=t<0?e:.01/n+e;return Math.round(r*n)/n}function xj(e){return Math.round(e*100)/100}function Sj(e){return Math.round(e*1e5)/1e5}var Cj=([e,t])=>`(${xj(e)},${xj(t)})`,wj=(e,t=1e-9)=>{let n=e;return Math.abs(e)<t&&(n=0),n.toFixed(-Math.log10(t))},Tj=(e,t=1e-9)=>Array.from(new Map(e.map(([e,n])=>[`[${wj(e,t)},${wj(n,t)}]`,[e,n]])).values()),Ej=class{_wrapped;_deleted=!1;constructor(e){this._wrapped=e??rC().createBoundingBox2d(),CC(this,this._wrapped)}get wrapped(){if(this._deleted)throw Error(`This object has been deleted`);return this._wrapped}delete(){this._deleted||(this._deleted=!0,wC(this._wrapped),typeof this._wrapped.delete==`function`&&this._wrapped.delete())}[Symbol.dispose](){this.delete()}get repr(){let[e,t]=this.bounds;return`${Cj(e)} - ${Cj(t)}`}get bounds(){let{xMin:e,yMin:t,xMax:n,yMax:r}=rC().getBBox2dBounds(this.wrapped);return[[e,t],[n,r]]}get center(){let[[e,t],[n,r]]=this.bounds;return[e+(n-e)/2,t+(r-t)/2]}get width(){let[[e],[t]]=this.bounds;return Math.abs(t-e)}get height(){let[[,e],[,t]]=this.bounds;return Math.abs(t-e)}outsidePoint(e=1){let[t,n]=this.bounds,r=n[0]-t[0],i=n[1]-t[1];return[n[0]+r/100*e,n[1]+i/100*e*.9]}add(e){rC().mergeBBox2d(this.wrapped,e.wrapped)}isOut(e){return rC().isBBox2dOut(this.wrapped,e.wrapped)}containsPoint(e){return!rC().isBBox2dOutPoint(this.wrapped,e[0],e[1])}};function Dj(e){return new Oj(U().deserializeCurve2d(e))}var Oj=class e{_wrapped;_deleted=!1;_boundingBox;_firstPoint=null;_lastPoint=null;_firstParameter=null;_lastParameter=null;constructor(e){this._wrapped=U().wrapCurve2dHandle(e),this._boundingBox=null,typeof this._wrapped.delete==`function`&&CC(this,this._wrapped)}get wrapped(){if(this._deleted)throw Error(`This object has been deleted`);return this._wrapped}delete(){this._deleted||(this._deleted=!0,typeof this._wrapped.delete==`function`&&(wC(this._wrapped),this._wrapped.delete()))}[Symbol.dispose](){this.delete()}get boundingBox(){if(this._boundingBox)return this._boundingBox;let e=U(),t=e.createBoundingBox2d();return e.addCurveToBBox2d(t,this.wrapped,1e-6),this._boundingBox=new Ej(t),this._boundingBox}get repr(){return`${this.geomType} ${Cj(this.firstPoint)} - ${Cj(this.lastPoint)}`}serialize(){return U().serializeCurve2d(this.wrapped)}value(e){return U().evaluateCurve2d(this.wrapped,e)}get firstPoint(){return this._firstPoint===null&&(this._firstPoint=this.value(this.firstParameter)),this._firstPoint}get lastPoint(){return this._lastPoint===null&&(this._lastPoint=this.value(this.lastParameter)),this._lastPoint}get firstParameter(){return this._firstParameter===null&&(this._firstParameter=U().getCurve2dBounds(this.wrapped).first),this._firstParameter}get lastParameter(){return this._lastParameter===null&&(this._lastParameter=U().getCurve2dBounds(this.wrapped).last),this._lastParameter}get geomType(){return U().getCurve2dType(this.wrapped)}clone(){let t=new e(U().copyCurve2d(this.wrapped));return t._firstPoint=this._firstPoint,t._lastPoint=this._lastPoint,t._firstParameter=this._firstParameter,t._lastParameter=this._lastParameter,t}reverse(){U().reverseCurve2d(this.wrapped);let e=this._firstPoint;this._firstPoint=this._lastPoint,this._lastPoint=e;let t=this._firstParameter;this._firstParameter=this._lastParameter,this._lastParameter=t}distanceFromPoint(e){let t=U().projectPointOnCurve2d(this.wrapped,e[0],e[1]),n=t?t.distance:1/0;return Math.min(n,YA(e,this.firstPoint),YA(e,this.lastPoint))}distanceFromCurve(e){let t;try{t=U().distanceBetweenCurves2d(this.wrapped,e.wrapped,this.firstParameter,this.lastParameter,e.firstParameter,e.lastParameter)}catch{t=1/0}return Math.min(t,this.distanceFromPoint(e.firstPoint),this.distanceFromPoint(e.lastPoint),e.distanceFromPoint(this.firstPoint),e.distanceFromPoint(this.lastPoint))}distanceFrom(e){return yj(e)?this.distanceFromPoint(e):this.distanceFromCurve(e)}isOnCurve(e){return this.distanceFromPoint(e)<1e-9}parameter(e,t=1e-9){let n,r,i=!1;try{let t=U().projectPointOnCurve2d(this.wrapped,e[0],e[1]);t?(n=t.distance,r=t.param):i=!0}catch{i=!0}return i?GA(e,this.firstPoint,t)?O(this.firstParameter):GA(e,this.lastPoint,t)?O(this.lastParameter):k(Ha(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n===void 0||r===void 0?k(Ha(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n>t?k(Ha(`POINT_NOT_ON_CURVE`,`Point ${Cj(e)} not on curve ${this.repr}, ${n.toFixed(9)}`)):O(r)}tangentAt(e){let t;if(Array.isArray(e))t=j(this.parameter(e));else{let n=U().getCurve2dBounds(this.wrapped);t=(n.last-n.first)*e+n.first}return U().evaluateCurve2dD1(this.wrapped,t).tangent}splitAt(n,r=1e-9){let i=n.map(e=>yj(e)?j(this.parameter(e,r)):e);i=Array.from(new Map(i.map(e=>[bj(e,-Math.log10(r)),e])).values()).sort((e,t)=>e-t);let a=this.firstParameter,o=this.lastParameter;return a>o&&i.reverse(),Math.abs(t(i,0)-a)<r*100&&(i=i.slice(1)),!i.length||(Math.abs(t(i,i.length-1)-o)<r*100&&(i=i.slice(0,-1)),!i.length)?[this]:U().splitCurve2d(this.wrapped,i).map(t=>new e(t))}},kj=(e,t=1e-4,n=`C0`,r=200)=>new Oj(rC().approximateCurve2dAsBSpline(e.wrapped,t,n,r)),Aj=e=>(e.geomType!==`BSPLINE_CURVE`&&M(`BSplineToBezier`,`You can only convert a Bspline`),rC().decomposeBSpline2dToBeziers(e.wrapped).map(e=>new Oj(e)));function jj(e,t={tolerance:1e-4,continuity:`C0`,maxSegments:300}){let n=rC();return e.flatMap(e=>{let r=e.geomType;if(r===`ELLIPSE`||r===`CIRCLE`&&GA(e.firstPoint,e.lastPoint))return e.splitAt([.5]);if([`LINE`,`ELLIPSE`,`CIRCLE`].includes(r))return e;if(r===`BEZIER_CURVE`){let t=n.getCurve2dBezierDegree(e.wrapped);if(t!==null&&[1,2,3].includes(t))return e}return jj(Aj(r===`BSPLINE_CURVE`?e:kj(e,t.tolerance,t.continuity,t.maxSegments)),t)})}var Mj=(e,t)=>{let n=new Oj(U().makeLine2d(e[0],e[1],t[0],t[1]));return GA(n.firstPoint,e)||n.reverse(),n},Nj=(e,t,n)=>{let r=new Oj(U().makeArc2dThreePoints(e[0],e[1],t[0],t[1],n[0],n[1]));if(!GA(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new Oj(e)}return r},Pj=(e,t,n)=>{let r=new Oj(U().makeArc2dTangent(e[0],e[1],t[0],t[1],n[0],n[1]));if(!GA(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new Oj(e)}return r},Fj=(e,t=[0,0])=>new Oj(U().makeCircle2d(t[0],t[1],e,!0)),Ij=(e,t,n=[1,0],r=[0,0],i=!0)=>new Oj(U().makeEllipse2d(r[0],r[1],e,t,n[0],n[1],i)),Lj=(e,t,n,r,i=[0,0],a,o=!0)=>new Oj(U().makeEllipseArc2d(i[0],i[1],e,t,n,r,a[0],a[1],o)),Rj=(e,t,n)=>{let r=[[e[0],e[1]],...t.map(e=>[e[0],e[1]]),[n[0],n[1]]];return new Oj(U().makeBezier2d(r))};function zj(e,{tolerance:t=.001,smoothing:n=null,degMax:r=3,degMin:i=1}={}){try{let a=e.map(e=>[e[0],e[1]]);return O(new Oj(U().makeBSpline2d(a,{tolerance:t,smoothing:n,degMax:r,degMin:i,continuity:`C2`})))}catch{return k(Ha(`BSPLINE_2D_FAILED`,`B-spline approximation failed`))}}var Bj=(e,t,n,r=!1)=>{let i=JA(KA(e,t),.5),a=YA(n,e)*(r?-1:1);return Nj(e,KA(JA(ij(qA(i,n)),a),n),t)},Vj=(e,n)=>{let r=rC(),i=e.geomType,[a,o]=n,s=`${Sj(a)} ${Sj(o)}`;if(i===`LINE`)return`L ${s}`;if(i===`BEZIER_CURVE`){let n=r.getCurve2dBezierPoles(e.wrapped);n||M(`adaptedCurveToPathElem`,`Expected Bezier poles`);let i=n.length-1;if(i===1)return`L ${s}`;if(i===2){let[e,r]=t(n,1);return`Q ${xj(e)} ${xj(r)} ${s}`}if(i===3){let[e,r]=t(n,1),[i,a]=t(n,2);return`C ${xj(e)} ${xj(r)} ${xj(i)} ${xj(a)} ${s}`}}if(i===`CIRCLE`){let t=r.getCurve2dCircleData(e.wrapped);t||M(`adaptedCurveToPathElem`,`Expected circle data`);let{radius:n,isDirect:i}=t,c=r.getCurve2dBounds(e.wrapped),l=(c.last-c.first)*Gw,u=l===360?`${Sj(a)} ${Sj(o+1e-4)}`:s;return`A ${n} ${n} 0 ${Math.abs(l)>180?`1`:`0`} ${i?`1`:`0`} ${u}`}if(i===`ELLIPSE`){let t=r.getCurve2dEllipseData(e.wrapped);t||M(`adaptedCurveToPathElem`,`Expected ellipse data`);let{majorRadius:n,minorRadius:i,xAxisAngle:c,isDirect:l}=t,u=r.getCurve2dBounds(e.wrapped),d=(u.last-u.first)*Gw,f=d===360?`${Sj(a)} ${Sj(o+1e-4)}`:s,p=180-c*Gw;return`A ${Sj(n)} ${Sj(i)} ${Sj(p)} ${Math.abs(d)>180?`1`:`0`} ${l?`1`:`0`} ${f}`}M(`adaptedCurveToPathElem`,`Unsupported curve type: ${i}`)},Hj=e=>{let t=U(),n=t.createBoundingBox2d();return e.forEach(e=>{t.addCurveToBBox2d(n,e.wrapped,1e-6)}),new Ej(n)};function Uj(e,t){let n=U();return e.map(e=>XC(n.liftCurve2dToPlane(e.wrapped,[...t.origin],[...t.zDir],[...t.xDir])))}var Wj=(e,t)=>{let n=U();return e.map(e=>XC(n.buildEdgeOnSurface(e.wrapped,t)))},Gj=(e,t)=>{let n=U();return e.map(e=>t?new Oj(n.transformCurve2dGeneral(e.wrapped,t)):e.clone())},Kj=(e,t,n=[0,0])=>U().createAffinityGTrsf2d(n[0],n[1],t[0],t[1],e),qj=e=>U().createTranslationGTrsf2d(e[0],e[1]),Jj=(e,t=[0,0],n=`center`)=>n===`center`?U().createMirrorGTrsf2d(e[0],e[1],`point`):U().createMirrorGTrsf2d(0,0,`axis`,t[0],t[1],e[0],e[1]),Yj=(e,t=[0,0])=>U().createRotationGTrsf2d(e,t[0],t[1]),Xj=(e,t=[0,0])=>U().createScaleGTrsf2d(e,t[0],t[1]);function Zj(e,t,n=`original`){let r=U(),i=r.extractSurfaceFromFace(t.wrapped),a=FT(t),o=null;if(n===`original`&&MT(t)!==`PLANE`){if(MT(t)!==`CYLINDRE`)return k(F(`UNSUPPORTED_FACE_TYPE`,`Only planar and cylindrical faces can be unwrapped for sketching`));let e=r.getSurfaceCylinderData(i);if(!e)return k(F(`UNSUPPORTED_FACE_TYPE`,`Could not extract cylinder data from face surface`));e.isDirect||(i=r.reverseSurfaceU(i)),o=Kj(1/e.radius,[0,1])}if(n===`bounds`){o=r.createIdentityGTrsf2d();try{r.setGTrsf2dTranslationPart(o,0,0);let e=r.createAffinityGTrsf2d(0,0,0,1,a.uMax-a.uMin);if(r.multiplyGTrsf2d(o,e),e.delete(),a.uMin!==0){let e=r.createIdentityGTrsf2d();r.setGTrsf2dTranslationPart(e,-a.uMin,0),r.multiplyGTrsf2d(o,e),e.delete()}let t=r.createAffinityGTrsf2d(0,0,1,0,a.vMax-a.vMin);if(r.multiplyGTrsf2d(o,t),t.delete(),a.vMin!==0){let e=r.createIdentityGTrsf2d();r.setGTrsf2dTranslationPart(e,0,-a.vMin),r.multiplyGTrsf2d(o,e),e.delete()}}catch(e){throw o.delete(),e}}let s=Wj(Gj(e,o),i);return o&&o.delete(),O(s)}function Qj(e,t){let n=U(),r=new Oj(n.extractCurve2dFromEdge(e.wrapped,t.wrapped));return JE(e)===`backward`&&n.reverseCurve2d(r.wrapped),r}var $j=(e,t=1)=>`${e.bounds[0][0]-t} ${-e.bounds[1][1]-t} ${e.width+2*t} ${e.height+2*t}`,eM=(e,t,n=1)=>`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${$j(t,n)}" fill="none" stroke="black" stroke-width="0.6%" vector-effect="non-scaling-stroke">
|
|
14
14
|
${e}
|
|
15
|
-
</svg>`;function
|
|
16
|
-
`)}get boundingBox(){return this._boundingBox||=Uj(this.curves),this._boundingBox}get orientation(){if(this._orientation)return this._orientation;if(this._guessedOrientation)return this._guessedOrientation;let e=this.curves.flatMap(e=>e.geomType===`LINE`?[e.firstPoint]:[e.firstPoint,e.value(.5)]),t=e.map((t,n)=>{let r=yD(e,(n+1)%e.length);return(r[0]-t[0])*(r[1]+t[1])}).reduce((e,t)=>e+t,0);return this._guessedOrientation=t>0?`clockwise`:`counterClockwise`,this._guessedOrientation}stretch(t,n,r=[0,0]){return new e(Kj(this.curves,qj(t,n,r)))}scale(t,n){let r=n||this.boundingBox.center;return new e(Kj(this.curves,Zj(t,r)))}rotate(t,n){return new e(Kj(this.curves,Xj(t*Gw,n)))}translate(t,n=0){let r=bj(t)?t:[t,n];return new e(Kj(this.curves,Jj(r)))}mirror(t,n=[0,0],r=`center`){return new e(Kj(this.curves,Yj(t,n,r)))}sketchOnPlane(e,t){let n=e&&typeof e!=`string`?{...e}:vT(e,t);return{wire:nM(Wj(this.curves,n)),defaultOrigin:n.origin,defaultDirection:n.zDir}}sketchOnFace(e,t){let n=U(),r=nM(j(Qj(this.curves,e,t)));n.buildCurves3d(r.wrapped);let i=n.fixWireOnFace(r.wrapped,e.wrapped,1e-9);return r.delete(),{wire:QC(i),baseFace:e}}subFace(e,t){let n=qw(t||[...VT(e)]);return j(FD(this.translate(RT(e,n)).sketchOnFace(e,`original`).wire))}punchHole(e,t,{height:n=null,origin:r=null,draftAngle:i=0}={}){let a=j(yj(t,e)),o=this.subFace(a,r);return j(OT(U().draftPrism(e.wrapped,o.wrapped,a.wrapped,n,i,!1)))}toSVGPathD(){let e=this.clone().mirror([1,0],[0,0],`plane`),t=Mj(e.curves).flatMap(e=>Hj(e,e.lastPoint)),[n,r]=bD(e.curves).firstPoint;return`M ${Cj(n)} ${Cj(r)} ${t.join(` `)}${e.isClosed()?` Z`:``}`}toSVGPath(){return`<path d="${this.toSVGPathD()}" />`}toSVGViewBox(e=1){return eM(this.boundingBox,e)}toSVGPaths(){return[this.toSVGPathD()]}toSVG(e=1){return tM(this.toSVGPath(),this.boundingBox,e)}get firstPoint(){return bD(this.curves).firstPoint}get lastPoint(){return xD(this.curves).lastPoint}isInside(e){if(!this.boundingBox.containsPoint(e))return!1;let t=U(),n=Nj(e,this.boundingBox.outsidePoint());try{if(this.curves.find(t=>t.isOnCurve(e)))return!1;let r=[],i=0;return this.curves.forEach(e=>{if(e.boundingBox.isOut(n.boundingBox))return;let a=t.intersectCurves2d(n.wrapped,e.wrapped,1e-9);for(let e of a.points)r.some(t=>KA(t,e,1e-9))||(r.push(e),i++);for(let e of a.segments)e.delete()}),!!(i%2)}finally{n.delete()}}isClosed(){return KA(this.firstPoint,this.lastPoint)}intersects(e){if(this.boundingBox.isOut(e.boundingBox))return!1;let t=U();for(let n of this.curves)for(let r of e.curves){if(n.boundingBox.isOut(r.boundingBox))continue;let e=t.intersectCurves2d(n.wrapped,r.wrapped,1e-9);if(e.points.length||e.segments.length)return!0}return!1}},iM=class{constructor(){this.ids=[],this.values=[],this.length=0}clear(){this.length=0}push(e,t){let n=this.length++;for(;n>0;){let e=n-1>>1,r=this.values[e];if(t>=r)break;this.ids[n]=this.ids[e],this.values[n]=r,n=e}this.ids[n]=e,this.values[n]=t}pop(){if(this.length===0)return;let e=this.ids,t=this.values,n=e[0],r=--this.length;if(r>0){let n=e[r],i=t[r],a=0,o=r>>1;for(;a<o;){let n=(a<<1)+1,o=n+1,s=n+(o<r&+(t[o]<t[n]));if(t[s]>=i)break;e[a]=e[s],t[a]=t[s],a=s}e[a]=n,t[a]=i}return n}peek(){return this.length>0?this.ids[0]:void 0}peekValue(){return this.length>0?this.values[0]:void 0}shrink(){this.ids.length=this.values.length=this.length}},aM=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],oM=3,sM=class e{static from(t,n=0){if(n%8!=0)throw Error(`byteOffset must be 8-byte aligned.`);if(!t||t.byteLength===void 0||t.buffer)throw Error(`Data must be an instance of ArrayBuffer or SharedArrayBuffer.`);let[r,i]=new Uint8Array(t,n+0,2);if(r!==251)throw Error(`Data does not appear to be in a Flatbush format.`);let a=i>>4;if(a!==oM)throw Error(`Got v${a} data when expected v${oM}.`);let o=aM[i&15];if(!o)throw Error(`Unrecognized array type.`);let[s]=new Uint16Array(t,n+2,1),[c]=new Uint32Array(t,n+4,1);return new e(c,s,o,void 0,t,n)}constructor(e,t=16,n=Float64Array,r=ArrayBuffer,i,a=0){if(e===void 0)throw Error(`Missing required argument: numItems.`);if(isNaN(e)||e<=0)throw Error(`Unexpected numItems value: ${e}.`);this.numItems=+e,this.nodeSize=Math.min(Math.max(+t,2),65535),this.byteOffset=a;let o=e,s=o;this._levelBounds=[o*4];do o=Math.ceil(o/this.nodeSize),s+=o,this._levelBounds.push(s*4);while(o!==1);this.ArrayType=n,this.IndexArrayType=s<16384?Uint16Array:Uint32Array;let c=aM.indexOf(n),l=s*4*n.BYTES_PER_ELEMENT;if(c<0)throw Error(`Unexpected typed array class: ${n}.`);if(i)this.data=i,this._boxes=new n(i,a+8,s*4),this._indices=new this.IndexArrayType(i,a+8+l,s),this._pos=s*4,this.minX=this._boxes[this._pos-4],this.minY=this._boxes[this._pos-3],this.maxX=this._boxes[this._pos-2],this.maxY=this._boxes[this._pos-1];else{let i=this.data=new r(8+l+s*this.IndexArrayType.BYTES_PER_ELEMENT);this._boxes=new n(i,8,s*4),this._indices=new this.IndexArrayType(i,8+l,s),this._pos=0,this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,new Uint8Array(i,0,2).set([251,(oM<<4)+c]),new Uint16Array(i,2,1)[0]=t,new Uint32Array(i,4,1)[0]=e}this._queue=new iM}add(e,t,n=e,r=t){let i=this._pos>>2,a=this._boxes;return this._indices[i]=i,a[this._pos++]=e,a[this._pos++]=t,a[this._pos++]=n,a[this._pos++]=r,e<this.minX&&(this.minX=e),t<this.minY&&(this.minY=t),n>this.maxX&&(this.maxX=n),r>this.maxY&&(this.maxY=r),i}finish(){if(this._pos>>2!==this.numItems)throw Error(`Added ${this._pos>>2} items when expected ${this.numItems}.`);let e=this._boxes;if(this.numItems<=this.nodeSize){e[this._pos++]=this.minX,e[this._pos++]=this.minY,e[this._pos++]=this.maxX,e[this._pos++]=this.maxY;return}let t=this.maxX-this.minX||1,n=this.maxY-this.minY||1,r=new Uint32Array(this.numItems),i=65535;for(let a=0,o=0;a<this.numItems;a++){let s=e[o++],c=e[o++],l=e[o++],u=e[o++];r[a]=dM(Math.floor(i*((s+l)/2-this.minX)/t),Math.floor(i*((c+u)/2-this.minY)/n))}lM(r,e,this._indices,0,this.numItems-1,this.nodeSize);for(let t=0,n=0;t<this._levelBounds.length-1;t++){let r=this._levelBounds[t];for(;n<r;){let t=n,i=e[n++],a=e[n++],o=e[n++],s=e[n++];for(let t=1;t<this.nodeSize&&n<r;t++)i=Math.min(i,e[n++]),a=Math.min(a,e[n++]),o=Math.max(o,e[n++]),s=Math.max(s,e[n++]);this._indices[this._pos>>2]=t,e[this._pos++]=i,e[this._pos++]=a,e[this._pos++]=o,e[this._pos++]=s}}}search(e,t,n,r,i){if(this._pos!==this._boxes.length)throw Error(`Data not yet indexed - call index.finish().`);let a=this._boxes.length-4,o=[],s=[];for(;a!==void 0;){let c=Math.min(a+this.nodeSize*4,cM(a,this._levelBounds));for(let l=a;l<c;l+=4){let c=this._boxes[l];if(n<c)continue;let u=this._boxes[l+1];if(r<u)continue;let d=this._boxes[l+2];if(e>d)continue;let f=this._boxes[l+3];if(t>f)continue;let p=this._indices[l>>2]|0;a>=this.numItems*4?o.push(p):(i===void 0||i(p,c,u,d,f))&&s.push(p)}a=o.pop()}return s}neighbors(e,t,n=1/0,r=1/0,i){if(this._pos!==this._boxes.length)throw Error(`Data not yet indexed - call index.finish().`);let a=this._boxes.length-4,o=this._queue,s=[],c=r*r;outer:for(;a!==void 0;){let r=Math.min(a+this.nodeSize*4,cM(a,this._levelBounds));for(let n=a;n<r;n+=4){let r=this._indices[n>>2]|0,s=this._boxes[n],l=this._boxes[n+1],u=this._boxes[n+2],d=this._boxes[n+3],f=e<s?s-e:e>u?e-u:0,p=t<l?l-t:t>d?t-d:0,m=f*f+p*p;m>c||(a>=this.numItems*4?o.push(r<<1,m):(i===void 0||i(r))&&o.push((r<<1)+1,m))}for(;o.length&&o.peek()&1;)if(o.peekValue()>c||(s.push(o.pop()>>1),s.length===n))break outer;a=o.length?o.pop()>>1:void 0}return o.clear(),s}};function cM(e,t){let n=0,r=t.length-1;for(;n<r;){let i=n+r>>1;t[i]>e?r=i:n=i+1}return t[n]}function lM(e,t,n,r,i,a){let o=[r,i];for(;o.length;){let r=o.pop()||0,i=o.pop()||0;if(r-i<=a&&Math.floor(i/a)>=Math.floor(r/a))continue;let s=e[i],c=e[i+r>>1],l=e[r],u=s>c==s>l?c<s==c<l?l:c:s,d=i-1,f=r+1;for(;;){do d++;while(e[d]<u);do f--;while(e[f]>u);if(d>=f)break;uM(e,t,n,d,f)}o.push(i,f,f+1,r)}}function uM(e,t,n,r,i){let a=e[r];e[r]=e[i],e[i]=a;let o=4*r,s=4*i,c=t[o],l=t[o+1],u=t[o+2],d=t[o+3];t[o]=t[s],t[o+1]=t[s+1],t[o+2]=t[s+2],t[o+3]=t[s+3],t[s]=c,t[s+1]=l,t[s+2]=u,t[s+3]=d;let f=n[r];n[r]=n[i],n[i]=f}function dM(e,t){let n=e^t,r=65535^n,i=65535^(e|t),a=e&(t^65535),o=n|r>>1,s=n>>1^n,c=i>>1^r&a>>1^i,l=n&i>>1^a>>1^a;n=o,r=s,i=c,a=l,o=n&n>>2^r&r>>2,s=n&r>>2^r&(n^r)>>2,c^=n&i>>2^r&a>>2,l^=r&i>>2^(n^r)&a>>2,n=o,r=s,i=c,a=l,o=n&n>>4^r&r>>4,s=n&r>>4^r&(n^r)>>4,c^=n&i>>4^r&a>>4,l^=r&i>>4^(n^r)&a>>4,n=o,r=s,i=c,a=l,c^=n&i>>8^r&a>>8,l^=r&i>>8^(n^r)&a>>8,n=c^c>>1,r=l^l>>1;let u=e^t,d=r|65535^(u|n);return u=(u|u<<8)&16711935,u=(u|u<<4)&252645135,u=(u|u<<2)&858993459,u=(u|u<<1)&1431655765,d=(d|d<<8)&16711935,d=(d|d<<4)&252645135,d=(d|d<<2)&858993459,d=(d|d<<1)&1431655765,(d<<1|u)>>>0}var fM=(e,t,n=1e-9)=>{if(e.boundingBox.isOut(t.boundingBox))return O({intersections:[],commonSegments:[],commonSegmentsPoints:[]});let r=iC(),i,a;try{let o=r.intersectCurves2d(e.wrapped,t.wrapped,n);i=o.points,a=o.segments.map(e=>new kj(e))}catch(e){return k(Ha(`INTERSECTION_FAILED`,`Intersections failed between curves`,e))}let o=a.filter(e=>KA(e.firstPoint,e.lastPoint,n)).map(e=>e.firstPoint);o.length&&(i.push(...o),a=a.filter(e=>!KA(e.firstPoint,e.lastPoint,n)));let s=a.flatMap(e=>[e.firstPoint,e.lastPoint]);return O({intersections:i,commonSegments:a,commonSegmentsPoints:s})},pM=(e,t=1e-9)=>{let n=iC(),r;try{let i=n.intersectCurves2d(e.wrapped,e.wrapped,t);r=i.points;for(let e of i.segments)e.delete()}catch(e){return k(Ha(`SELF_INTERSECTION_FAILED`,`Self intersection failed`,e))}return O(r)},mM=(e,n,r)=>{let i=aj(JA(n,e)),a=[i[1],-i[0]],o=[t(a,0)*r,t(a,1)*r];return{firstPoint:qA(e,o),lastPoint:qA(n,o)}},hM=(e,t)=>{let n=e.geomType,r=iC();if(n===`CIRCLE`){let n=r.getCurve2dCircleData(e.wrapped);if(!n)return Nj(e.firstPoint,e.lastPoint);let{cx:i,cy:a,radius:o,isDirect:s}=n,c=t*(s?1:-1),l=o+c;if(l<1e-10){let t=[i,a],n=e=>{let[n,r]=aj(JA(e,t));return qA(e,[c*n,c*r])};return{collapsed:!0,firstPoint:n(e.firstPoint),lastPoint:n(e.lastPoint)}}let u=new kj(r.makeCircle2d(i,a,l,s)),d;try{d=r.trimCurve2d(u.wrapped,e.firstParameter,e.lastParameter)}finally{u.delete()}return new kj(d)}if(n===`LINE`){let{firstPoint:n,lastPoint:r}=mM(e.firstPoint,e.lastPoint,t);return Nj(n,r)}let i=new kj(r.offsetCurve2d(e.wrapped,t)),a=Aj(i);if(i.delete(),j(pM(a)).length){let e=a.firstPoint,t=a.lastPoint;return a.delete(),{collapsed:!0,firstPoint:e,lastPoint:t}}return a};function gM(e,n,r){let i=QA(e.tangentAt(1),n.tangentAt(0));if(Math.abs(i)<1e-10)return null;let a=Math.abs(r)*(i>0?-1:1),o=hM(e,a),s=hM(n,a);if(!(o instanceof kj)||!(s instanceof kj))return null;let c=fM(o,s,1e-9);if(!ua(c))return null;let l=c.value.intersections.at(-1);if(!bj(l))return null;let u=l,d=(e,t)=>{let[n,r]=t.tangentAt(u),i=qA(u,YA(aj([-r,n]),a)),o=j(e.parameter(i,1e-6));return e.splitAt([o])},f=d(e,o),p=d(n,s);return{first:t(f,0),second:t(p,1),center:u}}function _M(e,t,n){let r=gM(e,t,n);if(!r)return[e,t];let{first:i,second:a,center:o}=r;return[i,Vj(i.lastPoint,a.firstPoint,o),a]}function vM(e,t,n){let r=gM(e,t,n);if(!r)return[e,t];let{first:i,second:a}=r;return[i,Nj(i.lastPoint,a.firstPoint),a]}function yM(e,n,r){let i=QA(aj(e.tangentAt(1)),aj(n.tangentAt(0))),a=Math.asin(i);if(Math.abs(i)<1e-10)return[e,n];let o=i>0?-1:1,s=Math.abs(r)*Math.sin(a/2)*o,c=hM(e,s),l=hM(n,s);if(!(c instanceof kj)||!(l instanceof kj))return[e,n];let u=fM(c,l,1e-9);if(!ua(u))return[e,n];let d=u.value.intersections.at(-1);if(!bj(d))return[e,n];let f=Ij(r,d),p=j(fM(e,f)).intersections[0],m=j(fM(n,f)).intersections.at(-1);if(!p||!m)return[e,n];let h=e.splitAt([p]),g=n.splitAt([m]),_=t(h,0),v=t(g,g.length-1);try{return[_,Pj(_.lastPoint,e.lastPoint,v.firstPoint),v]}catch{return[e,n]}}var bM=class e{blueprints;_boundingBox;constructor(e){this.blueprints=e,this._boundingBox=null}get repr(){return[`Blueprints`,...this.blueprints.map(e=>e.repr)].join(`
|
|
17
|
-
`)}clone(){return new e(this.blueprints.map(e=>e.clone()))}get boundingBox(){if(!this._boundingBox){let e=new
|
|
18
|
-
`),this.boundingBox,e)}},
|
|
19
|
-
`)}stretch(t,n,r){return new e(this.blueprints.map(e=>e.stretch(t,n,r)))}rotate(t,n){return new e(this.blueprints.map(e=>e.rotate(t,n)))}scale(t,n){let r=n||this.boundingBox.center;return new e(this.blueprints.map(e=>e.scale(t,r)))}translate(t,n=0){return new e(this.blueprints.map(e=>typeof t==`number`?e.translate(t,n):e.translate(t)))}mirror(t,n,r){return new e(this.blueprints.map(e=>e.mirror(t,n,r)))}sketchOnPlane(e,t){return this.blueprints.map(n=>n.sketchOnPlane(e,t))}sketchOnFace(e,t){return this.blueprints.map(n=>n.sketchOnFace(e,t))}punchHole(e,t,n={}){return bD(this.blueprints).punchHole(e,t,n)}toSVGViewBox(e=1){return eM(this.boundingBox,e)}toSVGPaths(){return this.blueprints.flatMap(e=>e.toSVGPaths())}toSVGGroup(){return`<g>${this.blueprints.map(e=>e.toSVGPath()).join(``)}</g>`}toSVG(e=1){return tM(this.toSVGGroup(),this.boundingBox,e)}},SM=e=>{if(e.length===0)return[];if(e.length===1)return[[Ka(e,0,`groupByBoundingBoxOverlap`)]];let t=new sM(e.length);for(let n of e){let[[e,r],[i,a]]=n.boundingBox.bounds;t.add(e,r,i,a)}t.finish();let n=e.map((n,r)=>{let[[i,a],[o,s]]=n.boundingBox.bounds;return t.search(i,a,o,s).filter(t=>t>r&&!n.boundingBox.isOut(Ka(e,t,`groupByBoundingBoxOverlap`).boundingBox))}),r=[],i=Array(n.length);return n.forEach((t,n)=>{let a=i[n];a||(a=[],r.push(a)),a.push(Ka(e,n,`groupByBoundingBoxOverlap`)),t.length&&t.forEach(e=>{i[e]=a})}),r},CM=e=>e.map((t,n)=>{let r=Ka(t.curves,0,`addContainmentInfo`),i=r.value((r.lastParameter+r.firstParameter)/2);return{blueprint:t,isIn:e.filter((e,t)=>n===t?!1:e.isInside(i))}}),wM=(e,t)=>e.flatMap(({blueprint:e})=>EM(t.filter(({blueprint:t,isIn:n})=>t===e||n.indexOf(e)!==-1))),TM=(e,t)=>[t.filter(({isIn:e})=>e.length<=1),...EM(CM(e.map(({blueprint:e})=>e)))],EM=e=>{if(!e.length)return[];let t=e.filter(({isIn:e})=>!e.length),n=e.filter(({isIn:e})=>e.length>1);return t.length===1&&n.length===0?[e]:t.length>1?wM(t,e):TM(n,e)},DM=e=>new bM(SM(e).map(CM).flatMap(EM).map(e=>e.length===1?Ka(e,0,`organiseBlueprints`).blueprint:(e.sort((e,t)=>e.isIn.length-t.isIn.length),new xM(e.map(({blueprint:e})=>e))))),OM=e=>e===`symmetric`||typeof e==`number`||Array.isArray(e)&&e.length===2,kM=e=>{let t;t=e?OM(e)?{endTangent:e}:{endTangent:0,...e}:{endTangent:[1,0]};let{endTangent:n,startFactor:r=1,endFactor:i=1,startTangent:a}=t,o;o=typeof n==`number`?rj(1,n*Gw):n;let s;return s=typeof a==`number`?rj(1,a*Gw):a,{endTangent:o,startFactor:r,endFactor:i,startTangent:s}};function AM(e,t,n){return e<t?{majorRadius:t,minorRadius:e,rotationAngle:n+90}:{majorRadius:e,minorRadius:t,rotationAngle:n}}function jM(e,t,n,r,i,a,o,s){let c=i*Gw,l=e=>XA(s(e)),u=l(rj(n,c)),d=l(rj(r,c+Math.PI/2)),f=aj(s(tj([1,0],c))),[,p]=ij(f),{cx:m,cy:h,startAngle:g,endAngle:_,clockwise:v,rx:y,ry:b}=PM(e,t,u,d,p,a,o),x=Rj(y,b,v?g:_,v?_:g,[m,h],f);return v||x.reverse(),x}function MM(e,t,n,r,i){let a=Math.PI*2,o=NM(1,0,e,t),s=NM(e,t,-n,-r);for(;s>a;)s-=a;for(;s<0;)s+=a;i||(s-=a);let c=o+s;for(;c>a;)c-=a;for(;c<0;)c+=a;return{startAngle:o,deltaAngle:s,endAngle:c}}function NM(e,t,n,r){let i=e*n+t*r,a=Math.sqrt((e*e+t*t)*(n*n+r*r));a<1e-12&&M(`radianAngle`,`Cannot compute angle between zero-length vectors`);let o=Math.acos(Math.max(-1,Math.min(1,i/a)));return e*r-t*n<0&&(o=-o),o}function PM([e,t],[n,r],i,a,o,s,c){i<0&&(i=-i),a<0&&(a=-a),(i<1e-10||a<1e-10)&&M(`convertSvgEllipseParams`,`rx and ry cannot be 0`);let l=Math.sin(o),u=Math.cos(o),d=(e-n)/2,f=(t-r)/2,p=(e+n)/2,m=(t+r)/2,h=u*d+l*f,g=u*f-l*d,_=h*h/(i*i)+g*g/(a*a);_>1&&(i*=Math.sqrt(_),a*=Math.sqrt(_));let v=i*a,y=i*g,b=a*h,x=y*y+b*b;x||M(`convertSvgEllipseParams`,`Start point cannot be same as end point`);let S=Math.sqrt(Math.abs((v*v-x)/x));s===c&&(S=-S);let C=S*y/a,w=-S*b/i,ee=u*C-l*w+p,te=l*C+u*w+m,ne=(h-C)/i,re=(h+C)/i,{startAngle:ie,deltaAngle:ae,endAngle:oe}=MM(ne,(g-w)/a,re,(g+w)/a,c);return{cx:ee,cy:te,startAngle:ie,deltaAngle:ae,endAngle:oe,clockwise:c,rx:i,ry:a}}var FM={chamfer:vM,dogbone:yM,fillet:_M};function IM(e,t){if(typeof e==`function`)return e;let n=FM[t];return(t,r)=>n(t,r,e)}var LM=class{pointer;firstPoint;pendingCurves;_nextCorner;constructor(e=[0,0]){this.pointer=e,this.firstPoint=e,this._nextCorner=null,this.pendingCurves=[]}_convertToUV([e,t]){return[e,t]}_convertFromUV([e,t]){return[e,t]}_lastCurve(){let e=this.pendingCurves.length;return e===0?null:this.pendingCurves[e-1]}_requireLastCurve(e,t){let n=this._lastCurve();return n||M(e,`You need a previous curve to ${t}`),n}_resolveRelative(e,t){return[this.pointer[0]+e,this.pointer[1]+t]}_saveCurveAndAdvance(e,t){return this.saveCurve(e),this.pointer=t,this}get penPosition(){return this.pointer}get penAngle(){let e=this._lastCurve();if(!e)return 0;let[t,n]=e.tangentAt(1);return Math.atan2(n,t)*Kw}movePointerTo(e){return this.pendingCurves.length&&M(`Sketcher2d.movePointerTo`,`You can only move the pointer if there is no curve defined`),this.pointer=e,this.firstPoint=e,this}saveCurve(e){if(!this._nextCorner){this.pendingCurves.push(e);return}let t=this.pendingCurves.pop();t||M(`Sketcher2d.saveCurve`,`No previous curve available for custom corner`),this.pendingCurves.push(...this._nextCorner(t,e)),this._nextCorner=null}lineTo(e){let t=Nj(this._convertToUV(this.pointer),this._convertToUV(e));return this._saveCurveAndAdvance(t,e)}line(e,t){return this.lineTo(this._resolveRelative(e,t))}vLine(e){return this.line(0,e)}hLine(e){return this.line(e,0)}vLineTo(e){return this.lineTo([this.pointer[0],e])}hLineTo(e){return this.lineTo([e,this.pointer[1]])}polarLineTo([e,t]){return this.lineTo(rj(e,t*Gw))}polarLine(e,t){let[n,r]=rj(e,t*Gw);return this.line(n,r)}tangentLine(e){let t=this._requireLastCurve(`Sketcher2d.tangentLine`,`sketch a tangent line`),n=aj(this._convertFromUV(t.tangentAt(1)));return this.line(n[0]*e,n[1]*e)}threePointsArcTo(e,t){let n=Pj(this._convertToUV(this.pointer),this._convertToUV(t),this._convertToUV(e));return this._saveCurveAndAdvance(n,e)}threePointsArc(e,t,n,r){let[i,a]=this.pointer;return this.threePointsArcTo([i+e,a+t],[i+n,a+r])}sagittaArcTo(e,t){let[n,r]=this.pointer,[i,a]=e,o=(n+i)/2,s=(r+a)/2,c=-(a-r),l=i-n,u=Math.sqrt(c**2+l**2);u<1e-12&&M(`sagittaArcTo`,`Start and end points cannot be identical`);let d=[o+c/u*t,s+l/u*t],f=Pj(this._convertToUV(this.pointer),this._convertToUV(d),this._convertToUV(e));return this._saveCurveAndAdvance(f,e)}sagittaArc(e,t,n){return this.sagittaArcTo(this._resolveRelative(e,t),n)}vSagittaArc(e,t){return this.sagittaArc(0,e,t)}hSagittaArc(e,t){return this.sagittaArc(e,0,t)}bulgeArcTo(e,t){if(!t)return this.lineTo(e);let n=XA(this.pointer,e)/2;return this.sagittaArcTo(e,-t*n)}bulgeArc(e,t,n){return this.bulgeArcTo(this._resolveRelative(e,t),n)}vBulgeArc(e,t){return this.bulgeArc(0,e,t)}hBulgeArc(e,t){return this.bulgeArc(e,0,t)}tangentArcTo(e){let t=this._requireLastCurve(`Sketcher2d.tangentArc`,`sketch a tangent arc`),n=Fj(this._convertToUV(this.pointer),t.tangentAt(1),this._convertToUV(e));return this._saveCurveAndAdvance(n,e)}tangentArc(e,t){return this.tangentArcTo(this._resolveRelative(e,t))}ellipseTo(e,t,n,r=0,i=!1,a=!1){let{majorRadius:o,minorRadius:s,rotationAngle:c}=AM(t,n,r),l=jM(this._convertToUV(this.pointer),this._convertToUV(e),o,s,c,i,a,e=>this._convertToUV(e));return this._saveCurveAndAdvance(l,e)}ellipse(e,t,n,r,i=0,a=!1,o=!1){return this.ellipseTo(this._resolveRelative(e,t),n,r,i,a,o)}halfEllipseTo(e,t,n=!1){let r=ej(e,this.pointer),i=XA(e,this.pointer);return this.ellipseTo(e,i/2,t,r*Kw,!0,n)}halfEllipse(e,t,n,r=!1){return this.halfEllipseTo(this._resolveRelative(e,t),n,r)}bezierCurveTo(e,t){let n=t.length===2&&!Array.isArray(t[0])?[t]:t,r=zj(this._convertToUV(this.pointer),n.map(e=>this._convertToUV(e)),this._convertToUV(e));return this._saveCurveAndAdvance(r,e)}quadraticBezierCurveTo(e,t){return this.bezierCurveTo(e,[t])}cubicBezierCurveTo(e,t,n){return this.bezierCurveTo(e,[t,n])}smoothSplineTo(e,t){let{endTangent:n,startTangent:r,startFactor:i,endFactor:a}=kM(t),o=this._lastCurve(),s=XA(this.pointer,e)*.25,c;c=r||(o?this._convertFromUV(o.tangentAt(1)):[1,0]),c=aj(c);let l=[this.pointer[0]+c[0]*i*s,this.pointer[1]+c[1]*i*s],u;u=n===`symmetric`?[-c[0],-c[1]]:n,u=aj(u);let d=[e[0]-u[0]*a*s,e[1]-u[1]*a*s];return this.cubicBezierCurveTo(e,l,d)}smoothSpline(e,t,n){return this.smoothSplineTo(this._resolveRelative(e,t),n)}customCorner(e,t=`fillet`){return this.pendingCurves.length||M(`Sketcher2d.customCorner`,`You need a curve defined to fillet the angle`),this._nextCorner=IM(e,t),this}_customCornerLastWithFirst(e,t=`fillet`){if(!e)return;let n=this.pendingCurves.pop(),r=this.pendingCurves.shift();(!n||!r)&&M(`Sketcher2d._customCornerLastWithFirst`,`Not enough curves to close and fillet`),this.pendingCurves.push(...IM(e,t)(n,r))}_closeSketch(){KA(this.pointer,this.firstPoint)||this.lineTo(this.firstPoint)}_closeWithMirror(){KA(this.pointer,this.firstPoint)&&M(`Sketcher2d._closeWithMirror`,`Cannot close with a mirror when the sketch is already closed`);let e=[this.pointer[0]-this.firstPoint[0],this.pointer[1]-this.firstPoint[1]],t=this._convertToUV(this.pointer),n=this._convertToUV(e),r=this.pendingCurves.map(e=>new kj(U().mirrorCurve2dAcrossAxis(e.wrapped,t[0],t[1],n[0],n[1])));r.reverse();for(let e of r)e.reverse();this.pendingCurves.push(...r),this.pointer=this.firstPoint}},RM=class extends LM{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new rM(this.pendingCurves)}close(){return this._closeSketch(),this.done()}closeWithMirror(){return this._closeWithMirror(),this.close()}closeWithCustomCorner(e,t=`fillet`){return this._closeSketch(),this._customCornerLastWithFirst(e,t),this.done()}},zM=2*Math.PI;function BM(e){let t=e%zM,n=t<0?t+zM:t;return n<Math.PI?n:n===Math.PI?0:Math.abs(n-zM)}function VM(e){return e.curves.map((t,n)=>({firstCurve:t,secondCurve:yD(e.curves,(n+1)%e.curves.length),point:t.lastPoint}))}function HM(e){let t=t=>HM([...e,t]),n=t=>e.every(e=>e(t));return{shouldKeep:n,when:e=>t(e),inList:e=>t(t=>e.some(e=>KA(e,t.point))),atDistance:(e,n=[0,0])=>t(t=>Math.abs(XA(n,t.point)-e)<1e-9),atPoint:e=>t(t=>KA(e,t.point)),inBox:(e,n)=>{let r=Math.min(e[0],n[0]),i=Math.max(e[0],n[0]),a=Math.min(e[1],n[1]),o=Math.max(e[1],n[1]);return t(e=>{let[t,n]=e.point;return t>=r&&t<=i&&n>=a&&n<=o})},ofAngle:e=>t(t=>{let n=t.firstCurve.tangentAt(1),r=t.secondCurve.tangentAt(0);return Math.abs(BM($A(n,r))-BM(Gw*e))<1e-9}),not:e=>{let n=e(HM([]));return t(e=>!n.shouldKeep(e))},either:e=>{let n=e.map(e=>e(HM([])));return t(e=>n.some(t=>t.shouldKeep(e)))},find:e=>VM(e).filter(n)}}function UM(){return HM([])}var WM=(e,t,n=0)=>{let r=[...Array(t).keys()].map(n=>{let r=-(Math.PI*2/t)*n;return[e*Math.sin(r),e*Math.cos(r)]}),i=xD(r),a=new RM().movePointerTo([i[0],i[1]]);return n?r.forEach(([e,t])=>a.sagittaArcTo([e,t],n)):r.forEach(([e,t])=>a.lineTo([e,t])),a.done()},GM=(e,t,n=0)=>{let{rx:r=0,ry:i=0}=typeof n==`number`?{ry:n,rx:n}:n,a=Math.min(r,e/2),o=Math.min(i,t/2),s=a&&o;s||(a=0,o=0);let c=a===o,l=new RM([Math.min(0,-(e/2-a)),-t/2]),u=(e,t)=>{s&&(c?l.tangentArc(e,t):l.ellipse(e,t,a,o,0,!1,!0))};return a<e/2&&l.hLine(e-2*a),u(a,o),o<t/2&&l.vLine(t-2*o),u(-a,o),a<e/2&&l.hLine(-(e-2*a)),u(-a,-o),o<t/2&&l.vLine(-(t-2*o)),u(a,-o),l.close()},KM=(e,t)=>KA(e,t,UA);function qM(e){return`${e[0].toFixed(9)},${e[1].toFixed(9)}`}function JM(e,t){let n=qM(e),r=qM(t);return n<r?`${n}|${r}`:`${r}|${n}`}function YM(e){let t=e[0];return t===void 0&&M(`startOfSegment`,`empty segment`),t.firstPoint}function XM(e){let t=e[e.length-1];return t===void 0&&M(`endOfSegment`,`empty segment`),t.lastPoint}function ZM(e){return[...e].reverse().map(e=>{let t=e.clone();return t.reverse(),t})}function QM(e){return[...e].reverse().map(ZM)}function $M(e){let t=(e.lastParameter+e.firstParameter)/2;return e.value(t)}function eN(e,t){let n=qM(t);for(let r=0;r<e.length;r++){let i=e[r];if(i!==void 0&&qM(i.firstPoint)===n&&KM(t,i.firstPoint))return r}for(let n=0;n<e.length;n++){let r=e[n];if(r!==void 0&&KM(t,r.firstPoint))return n}return-1}function tN(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i];if(a!==void 0&&qM(a.firstPoint)===t&&qM(a.lastPoint)===n&&r(a))return i}for(let t=0;t<e.length;t++){let n=e[t];if(n!==void 0&&r(n))return t}return-1}function nN(e,t){return t<=0?e:e.slice(t).concat(e.slice(0,t))}function rN(e,t){return nN(e,eN(e,t))}function iN(e,t){let n=qM(t.firstPoint),r=qM(t.lastPoint),i=e=>KM(t.firstPoint,e.firstPoint)&&KM(t.lastPoint,e.lastPoint),a=e=>KM(t.lastPoint,e.firstPoint)&&KM(t.firstPoint,e.lastPoint);function o(e,t,n,r){let i=tN(e,t,n,r);return i===-1?null:nN(e,i)}let s=o(e,n,r,i);if(s!==null)return s;let c=o(e,r,n,a);if(c!==null)return c;let l=ZM(e),u=o(l,n,r,i);if(u!==null)return u;let d=o(l,r,n,a);if(d!==null)return d;M(`rotateToStartAtSegment`,`failed to rotate to segment start`)}function*aN(e,t,n){let r=new Set(t.map(qM)),i=new Set(n.map(e=>JM(e.firstPoint,e.lastPoint))),a=e=>r.has(qM(e))?!0:t.some(t=>KM(t,e)),o=(e,t)=>i.has(JM(e,t))?!0:n.some(n=>KM(n.firstPoint,e)&&KM(n.lastPoint,t)||KM(n.firstPoint,t)&&KM(n.lastPoint,e)),s=[];for(let t of e){if(KM(t.firstPoint,t.lastPoint)){s.push(t);continue}let e=a(t.lastPoint),n=o(t.firstPoint,t.lastPoint);e?(s.push(t),yield s,s=[]):n?(s.length&&(yield s,s=[]),yield[t]):s.push(t)}s.length&&(yield s)}function oN(e,t,n){return e.filter(e=>{let r=t.filter(t=>KM(t.firstPoint,e)||KM(t.lastPoint,e)),i=r.length%2?r.filter(t=>!(KM(t.firstPoint,e)&&KM(t.lastPoint,e))):r;if(i.length===0||i.length%2)return!1;let a=i.map(e=>n.isInside($M(e)));return!(a.every(Boolean)||a.every(e=>!e))})}function sN(e,n){let r=[],i=[],a=e.curves.map(()=>[]),o=n.curves.map(()=>[]),s=new sM(n.curves.length);for(let e of n.curves){let[[t,n],[r,i]]=e.boundingBox.bounds;s.add(t,n,r,i)}return s.finish(),e.curves.forEach((e,c)=>{let[[l,u],[d,f]]=e.boundingBox.bounds,p=s.search(l,u,d,f);for(let s of p){let{intersections:l,commonSegments:u,commonSegmentsPoints:d}=j(fM(e,t(n.curves,s),UA/100));r.push(...l),a[c]?.push(...l),o[s]?.push(...l),i.push(...u),r.push(...d),a[c]?.push(...d),o[s]?.push(...d)}}),{allIntersections:Ej(r,UA),allCommonSegments:i,firstCurvePoints:a,secondCurvePoints:o}}function cN(e,t){return CD([e,t]).flatMap(([e,t])=>t.length===0?[e]:e.splitAt(t,UA/100))}function lN(e,t,n){return e.some(([e,r])=>e===void 0||r===void 0?!1:KM(e,t)&&KM(r,n)||KM(e,n)&&KM(r,t))}function uN(e,t){let{allIntersections:n,allCommonSegments:r,firstCurvePoints:i,secondCurvePoints:a}=sN(e,t);if(n.length<=1)return null;let o=cN(e.curves,i),s=cN(t.curves,a),c=r.map(e=>[e.firstPoint,e.lastPoint]),l=oN(oN(n,o,t),s,e);if(l.length===0&&r.length===0)return null;if(r.length===0){let e=l[0];if(e===void 0)return null;o=rN(o,e),s=rN(s,e)}else{let e=r[0];if(e===void 0)return null;o=iN(o,e),s=iN(s,e)}let u=Array.from(aN(o,l,r)),d=Array.from(aN(s,l,r)),f=u[0],p=d[0];if(f!==void 0&&p!==void 0){let e=!KM(XM(p),XM(f)),t=r.length>0&&p.length!==1;(e||t)&&(d=QM(d))}let m=Math.max(u.length,d.length),h=[];for(let e=0;e<m;e++){let t=u[e],n=d[e];if(t===void 0||n===void 0){let e=t??n;if(e===void 0)continue;h.push([e,e]);continue}lN(c,YM(t),XM(t))?h.push([t,`same`]):h.push([t,n])}return h}function dN(e){if(e.length<2)return e;let n=[],r=0;for(;r<e.length;){let i=t(e,r);if(i.geomType!==`LINE`){n.push(i),r++;continue}let a=i.lastPoint,o=r+1;for(;o<e.length;){let n=t(e,o);if(n.geomType!==`LINE`||!KM(a,n.firstPoint))break;let r=JA(a,i.firstPoint),s=JA(n.lastPoint,n.firstPoint);if(Math.abs(QA(r,s))>1e-9)break;a=n.lastPoint,o++}o>r+1?n.push(Nj(i.firstPoint,a)):n.push(i),r=o}return n}function fN(e){let t=e.map(e=>e.firstPoint),n=e.map(e=>e.lastPoint),r=CD([t,n.slice(-1).concat(n.slice(0,-1))]).map(([e,t],n)=>e===void 0||t===void 0||KM(e,t)?null:n).filter(e=>e!==null);if(r.length===0)return[e];let i=CD([r.slice(0,-1),r.slice(1)]).map(([t,n])=>e.slice(t,n)),a=e.slice(r[r.length-1]),o=r[0];return o!==void 0&&o!==0&&(a=a.concat(e.slice(0,o))),i.push(a),i}function pN(e,t,n){return t===1?{curves:[...e],segmentsIn:1,lastWasSame:null}:t===2||t===0?{curves:[],segmentsIn:null,lastWasSame:null}:t===null?{curves:[],segmentsIn:null,lastWasSame:n?[...n,...e]:e}:{curves:[],segmentsIn:t,lastWasSame:n}}function mN(e,t,n,r,i,a,o){let s=[],c=0,l=e[0];if(l!==void 0){let t=$M(l),n=r.isInside(t);(i.firstInside===`keep`&&n||i.firstInside===`remove`&&!n)&&(c+=1,s.push(...e))}let u=t[0];if(u!==void 0){let e=$M(u),r=n.isInside(e);if(i.secondInside===`keep`&&r||i.secondInside===`remove`&&!r){let e=t;c===1&&(e=ZM(t)),c+=1,s.push(...e)}}return a===null&&c===1&&o!==null&&(s=[...o,...s]),{curves:s,segmentsIn:c===1?c:a,lastWasSame:c===1?null:o}}function hN(e,t,n){let r=uN(e,t);if(r===null)return gN(e,t);if(r.every(([,e])=>e===`same`))return{identical:!0};let i=null,a=null,o=r.flatMap(([r,o])=>{if(o===`same`){let e=pN(r,i,a);return i=e.segmentsIn,a=e.lastWasSame,e.curves}let s=mN(r,o,e,t,n,i,a);return i=s.segmentsIn,a=s.lastWasSame,s.curves}),s=a;s!==null&&i===1&&(o=[...s,...o]);let c=fN(dN(o)).filter(e=>e.length>0).map(e=>new rM(e));if(c.length===0)return null;if(c.length===1){let e=c[0];return e===void 0?null:e}return DM(c)}function gN(e,t){let n=e.curves[0],r=t.curves[0];return{identical:!1,firstCurveInSecond:n!==void 0&&t.isInside($M(n)),secondCurveInFirst:r!==void 0&&e.isInside($M(r))}}function _N(e,t){let n=hN(e,t,{firstInside:`remove`,secondInside:`remove`});return n===null||n instanceof rM||n instanceof bM?n:n.identical?e.clone():n.firstCurveInSecond?t.clone():n.secondCurveInFirst?e.clone():new bM([e,t])}function vN(e,t){let n=hN(e,t,{firstInside:`remove`,secondInside:`keep`});return n===null||n instanceof rM||n instanceof bM?n:n.identical||n.firstCurveInSecond?null:n.secondCurveInFirst?new bM([new xM([e,t])]):e.clone()}function yN(e,t){let n=hN(e,t,{firstInside:`keep`,secondInside:`keep`});return n===null||n instanceof rM||n instanceof bM?n:n.identical||n.firstCurveInSecond?e.clone():n.secondCurveInFirst?t.clone():null}var bN=(e,t)=>{if(e instanceof rM&&t instanceof rM){let n=[];return e.curves.forEach(e=>{t.curves.forEach(t=>{let{intersections:r,commonSegmentsPoints:i}=j(fM(e,t));n.push(...r),n.push(...i)})}),n=Ej(n),n.length>1}if(e instanceof xM||e instanceof bM)return e.blueprints.some(e=>bN(e,t));if(t instanceof xM||t instanceof bM)return t.blueprints.some(t=>bN(e,t));M(`genericIntersects`,`Unhandled shape combination in genericIntersects`)},xN=(e,t)=>{if(e instanceof xM){if(t instanceof rM)return wN(t,e);if(t instanceof xM)return EN(e,t)}if(t instanceof xM){if(e instanceof rM)return wN(e,t);if(e instanceof xM)return EN(e,t)}if(e instanceof rM&&t instanceof rM)return _N(e,t);M(`genericFuse`,`Unhandled shape combination in genericFuse`)},SN=e=>{let t=new Map,n=[];return e.forEach((r,i)=>{let a;t.has(i)?a=t.get(i):(a={current:r,fusedWith:new Set([i])},n.push(a)),e.slice(i+1).forEach((e,n)=>{let r=a.current,o=i+n+1;if(a.fusedWith.has(o))return;let s=e,c=!1;if(t.has(o)&&(s=t.get(o).current,c=!0),r.boundingBox.isOut(s.boundingBox)||!bN(r,s))return;let l;if(r instanceof bM||s instanceof bM){let e=DN(r,s);e===null&&M(`fuseIntersectingBlueprints`,`fuse2D returned null for non-null inputs`),l=e}else l=xN(r,s);if(!(l instanceof rM||l instanceof xM)){if(l instanceof bM&&l.blueprints.length===2)return;l instanceof bM&&l.blueprints.length===1?l=Ka(l.blueprints,0,`fuseIntersectingBlueprints`):l instanceof bM||M(`fuseIntersectingBlueprints`,`Fuse produced unexpected non-blueprint result`)}a.fusedWith.add(o),a.current=l,c||t.set(o,a)})}),DM(n.map(({current:e})=>e).flatMap(e=>CN(e)))},CN=e=>e instanceof rM?[e]:e instanceof xM?e.blueprints:e instanceof bM?e.blueprints.flatMap(e=>CN(e)):[],wN=(e,t)=>{let n=_N(e,Ka(t.blueprints,0,`fuseBlueprintWithCompound`)),r=t.blueprints.slice(1).map(t=>vN(t,e));return DM([...CN(n),...r.flatMap(e=>CN(e))])};function TN(e,t){let n=[];for(let r of e)for(let e of t)n.push([r,e]);return n}var EN=(e,t)=>{let n=Ka(e.blueprints,0,`fuseCompoundWithCompound`),r=Ka(t.blueprints,0,`fuseCompoundWithCompound`),i=_N(n,r),a=t.blueprints.slice(1).map(e=>vN(e,n)),o=e.blueprints.slice(1).map(e=>vN(e,r)),s=TN(e.blueprints.slice(1),t.blueprints.slice(1)).flatMap(([e,t])=>CN(yN(e,t)));return DM([...CN(i),...a.flatMap(e=>CN(e)),...o.flatMap(e=>CN(e)),...s])},DN=(e,t)=>{if(e===null)return t?.clone()??null;if(t===null)return e.clone();if(!(e instanceof bM)&&t instanceof bM)return SN([e,...t.blueprints]);if(!(t instanceof bM)&&e instanceof bM)return SN([t,...e.blueprints]);if(e instanceof bM&&t instanceof bM){let n=DN(Ka(e.blueprints,0,`fuse2D`),t);return e.blueprints.slice(1).forEach(e=>{n=DN(e,n)}),n}if(e instanceof xM){if(t instanceof bM)return DN(t,e);if(t instanceof rM)return wN(t,e);if(t instanceof xM)return EN(e,t)}if(t instanceof xM){if(e instanceof bM)return DN(e,t);if(e instanceof rM)return wN(e,t);if(e instanceof xM)return EN(e,t)}return e instanceof rM&&t instanceof rM?_N(e,t):null},ON=e=>{let t=e.flatMap(e=>e===null?[]:e instanceof bM?e.blueprints:e);return t.length===1?Ka(t,0,`mergeNonIntersecting`):new bM(t)},kN=(e,t)=>{if(e===null)return null;if(t===null)return e.clone();if(e instanceof bM)return ON(e.blueprints.map(e=>kN(e,t)));if(e instanceof xM){let n=Ka(e.blueprints,0,`cut2D`);if(t instanceof rM&&!t.intersects(n))return n.isInside(t.firstPoint)?DM([n,...CN(DN(t,new bM(e.blueprints.slice(1))))]):e.clone();{let r=kN(n,t);return e.blueprints.slice(1).forEach(e=>{r=kN(r,e)}),r}}if(t instanceof bM){let n=e;for(let e of t.blueprints)n=kN(n,e);return n}if(t instanceof xM){let n=vN(e,Ka(t.blueprints,0,`cut2D`));return t.blueprints.slice(1).forEach(t=>{n=DN(n,yN(t,e))}),n}return vN(e,t)};function AN(e,t){if(e===null||t===null)return null;if(e instanceof rM&&t instanceof rM)return yN(e,t);if(e instanceof bM)return ON(e.blueprints.map(e=>AN(e,t)));if(e instanceof xM){let n=Ka(e.blueprints,0,`intersect2D`),r=e.blueprints.slice(1);if(r.length===0)return AN(n,t);let i=AN(n,t);for(let e of r)i=kN(i,e);return i}if(t instanceof bM)return ON(t.blueprints.map(t=>AN(e,t)));if(t instanceof xM){let n=Ka(t.blueprints,0,`intersect2D`),r=t.blueprints.slice(1);if(r.length===0)return AN(n,e);let i=AN(n,e);for(let e of r)i=kN(i,e);return i}M(`intersect2D`,`Unhandled Shape2D combination`)}function jN(e,{profile:t,endFactor:n=1}){return e<1e-10?k(F(`INVALID_EXTRUSION_LENGTH`,`Extrusion length too small (< 1e-10)`)):t!==`s-curve`&&t!==`linear`?k(F(`UNSUPPORTED_PROFILE`,`Unsupported extrusion profile: ${String(t)}`)):O(U().buildExtrusionLaw(t,e,n).Trim(0,e,1e-6))}function MN(e,t){let n=U(),r=n.makeLineEdge([...e],[...t]);return W(n.makeWire([r]))}function NN(e,t,n,r,i,a=!1){return W(U().makeHelixWire(e,t,n,[...r],[...i],a))}function PN(e,t,n={},r=!1){if(n.mode===`simple`&&!r){let n=W(U().simplePipe(e.wrapped,t.wrapped));return dw(n)?O(n):k(za(`SWEEP_NOT_3D`,`Simple pipe did not produce a 3D shape`))}let{frenet:i=!1,auxiliarySpine:a,law:o=null,transitionMode:s=`right`,withContact:c,support:l,forceProfileSpineOthogonality:u,tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h}=n,g=U(),_=s===`round`?!0:!!u,v=g.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:s,contact:!!c,correction:_,frenet:i,shellMode:r,...a?.wrapped?{auxiliary:a.wrapped}:{},...o===null?{}:{law:o},...l===null?{}:{support:l},tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h});if(r&&typeof v==`object`&&`firstShape`in v){let e=W(v.shape);if(!dw(e))return k(za(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`));let t=W(v.firstShape),n=W(v.lastShape);return ow(t)?ow(n)?O([e,t,n]):k(za(`SWEEP_END_NOT_WIRE`,`Sweep did not produce an end Wire`)):k(za(`SWEEP_START_NOT_WIRE`,`Sweep did not produce a start Wire`))}let y=W(v);return dw(y)?O(y):k(za(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`))}function FN(e,t,n,r){return PN(e,MN(t,Zw(t,n)),{support:r})}function IN(e,t,n,r,i=!1){let a=rT(n);if(a<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let o=MN(t,Zw(t,n)),s=null;if(r){let e=jN(a,r);if(A(e))return e;s=e.value}return PN(e,o,{law:s},i)}function LN(e,t,n,r,i,a=!1){if(Math.abs(t)<1e-10)return k(F(`ZERO_TWIST_ANGLE`,`Twist angle cannot be zero`));let o=rT(r);if(o<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let s=MN(n,Zw(n,r)),c=t<0,l=NN(360/Math.abs(t)*o,o,1,n,r,c),u=null;if(i){let e=jN(o,i);if(A(e))return e;u=e.value}return PN(e,s,{auxiliarySpine:l,law:u},a)}function RN(e){let t=e.map(e=>e.location);for(let e=0;e<t.length;e++){let n=t[e];if(n!==void 0&&(n<0||n>1))return F(N.MULTI_SWEEP_FAILED,`Section ${e} location ${n} is out of range [0, 1]`)}let n=t.filter(e=>e!==void 0);for(let e=1;e<n.length;e++)if((n[e]??0)<=(n[e-1]??0))return F(N.MULTI_SWEEP_FAILED,`Section locations must be strictly increasing`)}function zN(e,t,n){let[r,i]=n.curveParameters(t.wrapped),a=i-r,o=Array(e.length);for(let t=0;t<e.length;t++){let n=e[t]?.location;o[t]=n===void 0?NaN:r+n*a}let s=-1,c=r;for(let t=0;t<=e.length;t++){let n=t===e.length;if(!n&&!Number.isNaN(o[t]??NaN)||n){let e=n?i:o[t]??i,a=t-s-1;for(let t=1;t<=a;t++)o[s+t]=c+t/(a+1)*(e-c);n||(s=t,c=o[t]??r)}}for(let e=1;e<o.length;e++)if((o[e]??0)<=(o[e-1]??0))return k(F(N.MULTI_SWEEP_FAILED,`Computed section parameters are not strictly increasing at index ${e} (${o[e-1]?.toFixed(4)} >= ${o[e]?.toFixed(4)})`));return O(o)}function BN(e,t,n){if(e.length<2)return k(F(N.MULTI_SWEEP_INSUFFICIENT_SECTIONS,`Multi-section sweep requires at least 2 sections, got ${e.length}`));let{solid:r=!0,ruled:i=!1,tolerance:a=1e-6}=n??{},o=RN(e);if(o)return k(o);try{let n=U(),o=zN(e,t,n);if(A(o))return o;let s=o.value,c=[];for(let r=0;r<e.length;r++){let i=s[r],a=e[r];if(i===void 0||a===void 0)continue;let o=n.positionOnCurve(a.wire.wrapped,t.wrapped,i);c.push(n.downcast(o,`wire`))}let l=W(n.loftAdvanced(c,{solid:r,ruled:i,tolerance:a}));return dw(l)?O(l):k(za(`MULTI_SWEEP_NOT_3D`,`Multi-section sweep did not produce a 3D shape`))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.MULTI_SWEEP_FAILED,`Multi-section sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function VN(e,t,n,r={}){let{transition:i=`transformed`,solid:a=!0,tolerance:o}=r;try{let r=U(),s=!a,c=n.length>0?n[0]?.wrapped:void 0,l=r.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:i,...c?{auxiliary:c}:{},shellMode:s,...o===void 0?{}:{tolerance:o,boundTolerance:o}}),u=W(typeof l==`object`&&`shape`in l?l.shape:l);return dw(u)?O(u):k(za(`GUIDED_SWEEP_NOT_3D`,`Guided sweep did not produce a 3D shape`))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.GUIDED_SWEEP_FAILED,`Guided sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function HN(e,t){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`extrude: face is a null shape`));if(rT(t)<1e-10)return k(F(`EXTRUDE_ZERO_VECTOR`,`extrude: extrusion vector has zero length`));try{let n=U(),r=rT(t),i=oT(t),a=n.extrude(e.wrapped,[...i],r);return O(tw(n.downcast(a,`solid`)))}catch(e){return k(P(`EXTRUDE_FAILED`,`Extrusion operation failed`,e,{operation:`extrude`,vectorLength:rT(t)}))}}function UN(e,t=[0,0,0],n=[0,0,1],r=360){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`revolve: face is a null shape`));try{let i=W(U().revolveVec(e.wrapped,[...t],[...n],r));return dw(i)?O(i):k(za(`REVOLUTION_NOT_3D`,`Revolution did not produce a 3D shape`))}catch(e){return k(P(`REVOLVE_FAILED`,`Revolution operation failed`,e,{operation:`revolve`,angle:r}))}}function WN(e){if(e.length===0)return O([]);let t=U(),n=[];for(let t=0;t<e.length;t++){let r=e[t];if(!r)continue;let i=typeof r.height==`number`?[0,0,r.height]:r.height,a=rT(i);if(a<1e-10)return k(F(`EXTRUDE_ALL_ZERO_VECTOR`,`extrudeAll: entry ${t} has zero-length extrusion vector`));let o=[...oT(i)];n.push({face:r.face.wrapped,direction:o,length:a})}try{return O((t.extrudeBatch?.(n)??n.map(e=>t.extrude(e.face,e.direction,e.length))).map(e=>tw(t.downcast(e,`solid`))))}catch(e){return k(P(`EXTRUDE_ALL_FAILED`,`Batch extrusion operation failed`,e))}}var GN=e(((e,t)=>{t.exports={}}));
|
|
15
|
+
</svg>`;function tM(e){let t=e.map(e=>e.wrapped);return ZC(U().makeWire(t))}var nM=class e{curves;_boundingBox;_orientation;_guessedOrientation;constructor(e){e.length===0&&M(`Blueprint`,`requires at least one curve — use createBlueprint() for Result-based validation`),this.curves=e,this._boundingBox=null,this._orientation=null,this._guessedOrientation=null}delete(){this.curves.forEach(e=>{e.delete()}),this._boundingBox&&this._boundingBox.delete()}[Symbol.dispose](){this.delete()}clone(){return new e(this.curves.map(e=>e.clone()))}get repr(){return[`Blueprint`,...this.curves.map(e=>e.repr)].join(`
|
|
16
|
+
`)}get boundingBox(){return this._boundingBox||=Hj(this.curves),this._boundingBox}get orientation(){if(this._orientation)return this._orientation;if(this._guessedOrientation)return this._guessedOrientation;let e=this.curves.flatMap(e=>e.geomType===`LINE`?[e.firstPoint]:[e.firstPoint,e.value(.5)]),t=e.map((t,n)=>{let r=vD(e,(n+1)%e.length);return(r[0]-t[0])*(r[1]+t[1])}).reduce((e,t)=>e+t,0);return this._guessedOrientation=t>0?`clockwise`:`counterClockwise`,this._guessedOrientation}stretch(t,n,r=[0,0]){return new e(Gj(this.curves,Kj(t,n,r)))}scale(t,n){let r=n||this.boundingBox.center;return new e(Gj(this.curves,Xj(t,r)))}rotate(t,n){return new e(Gj(this.curves,Yj(t*Ww,n)))}translate(t,n=0){let r=yj(t)?t:[t,n];return new e(Gj(this.curves,qj(r)))}mirror(t,n=[0,0],r=`center`){return new e(Gj(this.curves,Jj(t,n,r)))}sketchOnPlane(e,t){let n=e&&typeof e!=`string`?{...e}:_T(e,t);return{wire:tM(Uj(this.curves,n)),defaultOrigin:n.origin,defaultDirection:n.zDir}}sketchOnFace(e,t){let n=U(),r=tM(j(Zj(this.curves,e,t)));n.buildCurves3d(r.wrapped);let i=n.fixWireOnFace(r.wrapped,e.wrapped,1e-9);return r.delete(),{wire:ZC(i),baseFace:e}}subFace(e,t){let n=Kw(t||[...BT(e)]);return j(PD(this.translate(LT(e,n)).sketchOnFace(e,`original`).wire))}punchHole(e,t,{height:n=null,origin:r=null,draftAngle:i=0}={}){let a=j(vj(t,e)),o=this.subFace(a,r);return j(DT(U().draftPrism(e.wrapped,o.wrapped,a.wrapped,n,i,!1)))}toSVGPathD(){let e=this.clone().mirror([1,0],[0,0],`plane`),t=jj(e.curves).flatMap(e=>Vj(e,e.lastPoint)),[n,r]=yD(e.curves).firstPoint;return`M ${Sj(n)} ${Sj(r)} ${t.join(` `)}${e.isClosed()?` Z`:``}`}toSVGPath(){return`<path d="${this.toSVGPathD()}" />`}toSVGViewBox(e=1){return $j(this.boundingBox,e)}toSVGPaths(){return[this.toSVGPathD()]}toSVG(e=1){return eM(this.toSVGPath(),this.boundingBox,e)}get firstPoint(){return yD(this.curves).firstPoint}get lastPoint(){return bD(this.curves).lastPoint}isInside(e){if(!this.boundingBox.containsPoint(e))return!1;let t=U(),n=Mj(e,this.boundingBox.outsidePoint());try{if(this.curves.find(t=>t.isOnCurve(e)))return!1;let r=[],i=0;return this.curves.forEach(e=>{if(e.boundingBox.isOut(n.boundingBox))return;let a=t.intersectCurves2d(n.wrapped,e.wrapped,1e-9);for(let e of a.points)r.some(t=>GA(t,e,1e-9))||(r.push(e),i++);for(let e of a.segments)e.delete()}),!!(i%2)}finally{n.delete()}}isClosed(){return GA(this.firstPoint,this.lastPoint)}intersects(e){if(this.boundingBox.isOut(e.boundingBox))return!1;let t=U();for(let n of this.curves)for(let r of e.curves){if(n.boundingBox.isOut(r.boundingBox))continue;let e=t.intersectCurves2d(n.wrapped,r.wrapped,1e-9);if(e.points.length||e.segments.length)return!0}return!1}},rM=class{constructor(){this.ids=[],this.values=[],this.length=0}clear(){this.length=0}push(e,t){let n=this.length++;for(;n>0;){let e=n-1>>1,r=this.values[e];if(t>=r)break;this.ids[n]=this.ids[e],this.values[n]=r,n=e}this.ids[n]=e,this.values[n]=t}pop(){if(this.length===0)return;let e=this.ids,t=this.values,n=e[0],r=--this.length;if(r>0){let n=e[r],i=t[r],a=0,o=r>>1;for(;a<o;){let n=(a<<1)+1,o=n+1,s=n+(o<r&+(t[o]<t[n]));if(t[s]>=i)break;e[a]=e[s],t[a]=t[s],a=s}e[a]=n,t[a]=i}return n}peek(){return this.length>0?this.ids[0]:void 0}peekValue(){return this.length>0?this.values[0]:void 0}shrink(){this.ids.length=this.values.length=this.length}},iM=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],aM=3,oM=class e{static from(t,n=0){if(n%8!=0)throw Error(`byteOffset must be 8-byte aligned.`);if(!t||t.byteLength===void 0||t.buffer)throw Error(`Data must be an instance of ArrayBuffer or SharedArrayBuffer.`);let[r,i]=new Uint8Array(t,n+0,2);if(r!==251)throw Error(`Data does not appear to be in a Flatbush format.`);let a=i>>4;if(a!==aM)throw Error(`Got v${a} data when expected v${aM}.`);let o=iM[i&15];if(!o)throw Error(`Unrecognized array type.`);let[s]=new Uint16Array(t,n+2,1),[c]=new Uint32Array(t,n+4,1);return new e(c,s,o,void 0,t,n)}constructor(e,t=16,n=Float64Array,r=ArrayBuffer,i,a=0){if(e===void 0)throw Error(`Missing required argument: numItems.`);if(isNaN(e)||e<=0)throw Error(`Unexpected numItems value: ${e}.`);this.numItems=+e,this.nodeSize=Math.min(Math.max(+t,2),65535),this.byteOffset=a;let o=e,s=o;this._levelBounds=[o*4];do o=Math.ceil(o/this.nodeSize),s+=o,this._levelBounds.push(s*4);while(o!==1);this.ArrayType=n,this.IndexArrayType=s<16384?Uint16Array:Uint32Array;let c=iM.indexOf(n),l=s*4*n.BYTES_PER_ELEMENT;if(c<0)throw Error(`Unexpected typed array class: ${n}.`);if(i)this.data=i,this._boxes=new n(i,a+8,s*4),this._indices=new this.IndexArrayType(i,a+8+l,s),this._pos=s*4,this.minX=this._boxes[this._pos-4],this.minY=this._boxes[this._pos-3],this.maxX=this._boxes[this._pos-2],this.maxY=this._boxes[this._pos-1];else{let i=this.data=new r(8+l+s*this.IndexArrayType.BYTES_PER_ELEMENT);this._boxes=new n(i,8,s*4),this._indices=new this.IndexArrayType(i,8+l,s),this._pos=0,this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,new Uint8Array(i,0,2).set([251,(aM<<4)+c]),new Uint16Array(i,2,1)[0]=t,new Uint32Array(i,4,1)[0]=e}this._queue=new rM}add(e,t,n=e,r=t){let i=this._pos>>2,a=this._boxes;return this._indices[i]=i,a[this._pos++]=e,a[this._pos++]=t,a[this._pos++]=n,a[this._pos++]=r,e<this.minX&&(this.minX=e),t<this.minY&&(this.minY=t),n>this.maxX&&(this.maxX=n),r>this.maxY&&(this.maxY=r),i}finish(){if(this._pos>>2!==this.numItems)throw Error(`Added ${this._pos>>2} items when expected ${this.numItems}.`);let e=this._boxes;if(this.numItems<=this.nodeSize){e[this._pos++]=this.minX,e[this._pos++]=this.minY,e[this._pos++]=this.maxX,e[this._pos++]=this.maxY;return}let t=this.maxX-this.minX||1,n=this.maxY-this.minY||1,r=new Uint32Array(this.numItems),i=65535;for(let a=0,o=0;a<this.numItems;a++){let s=e[o++],c=e[o++],l=e[o++],u=e[o++];r[a]=uM(Math.floor(i*((s+l)/2-this.minX)/t),Math.floor(i*((c+u)/2-this.minY)/n))}cM(r,e,this._indices,0,this.numItems-1,this.nodeSize);for(let t=0,n=0;t<this._levelBounds.length-1;t++){let r=this._levelBounds[t];for(;n<r;){let t=n,i=e[n++],a=e[n++],o=e[n++],s=e[n++];for(let t=1;t<this.nodeSize&&n<r;t++)i=Math.min(i,e[n++]),a=Math.min(a,e[n++]),o=Math.max(o,e[n++]),s=Math.max(s,e[n++]);this._indices[this._pos>>2]=t,e[this._pos++]=i,e[this._pos++]=a,e[this._pos++]=o,e[this._pos++]=s}}}search(e,t,n,r,i){if(this._pos!==this._boxes.length)throw Error(`Data not yet indexed - call index.finish().`);let a=this._boxes.length-4,o=[],s=[];for(;a!==void 0;){let c=Math.min(a+this.nodeSize*4,sM(a,this._levelBounds));for(let l=a;l<c;l+=4){let c=this._boxes[l];if(n<c)continue;let u=this._boxes[l+1];if(r<u)continue;let d=this._boxes[l+2];if(e>d)continue;let f=this._boxes[l+3];if(t>f)continue;let p=this._indices[l>>2]|0;a>=this.numItems*4?o.push(p):(i===void 0||i(p,c,u,d,f))&&s.push(p)}a=o.pop()}return s}neighbors(e,t,n=1/0,r=1/0,i){if(this._pos!==this._boxes.length)throw Error(`Data not yet indexed - call index.finish().`);let a=this._boxes.length-4,o=this._queue,s=[],c=r*r;outer:for(;a!==void 0;){let r=Math.min(a+this.nodeSize*4,sM(a,this._levelBounds));for(let n=a;n<r;n+=4){let r=this._indices[n>>2]|0,s=this._boxes[n],l=this._boxes[n+1],u=this._boxes[n+2],d=this._boxes[n+3],f=e<s?s-e:e>u?e-u:0,p=t<l?l-t:t>d?t-d:0,m=f*f+p*p;m>c||(a>=this.numItems*4?o.push(r<<1,m):(i===void 0||i(r))&&o.push((r<<1)+1,m))}for(;o.length&&o.peek()&1;)if(o.peekValue()>c||(s.push(o.pop()>>1),s.length===n))break outer;a=o.length?o.pop()>>1:void 0}return o.clear(),s}};function sM(e,t){let n=0,r=t.length-1;for(;n<r;){let i=n+r>>1;t[i]>e?r=i:n=i+1}return t[n]}function cM(e,t,n,r,i,a){let o=[r,i];for(;o.length;){let r=o.pop()||0,i=o.pop()||0;if(r-i<=a&&Math.floor(i/a)>=Math.floor(r/a))continue;let s=e[i],c=e[i+r>>1],l=e[r],u=s>c==s>l?c<s==c<l?l:c:s,d=i-1,f=r+1;for(;;){do d++;while(e[d]<u);do f--;while(e[f]>u);if(d>=f)break;lM(e,t,n,d,f)}o.push(i,f,f+1,r)}}function lM(e,t,n,r,i){let a=e[r];e[r]=e[i],e[i]=a;let o=4*r,s=4*i,c=t[o],l=t[o+1],u=t[o+2],d=t[o+3];t[o]=t[s],t[o+1]=t[s+1],t[o+2]=t[s+2],t[o+3]=t[s+3],t[s]=c,t[s+1]=l,t[s+2]=u,t[s+3]=d;let f=n[r];n[r]=n[i],n[i]=f}function uM(e,t){let n=e^t,r=65535^n,i=65535^(e|t),a=e&(t^65535),o=n|r>>1,s=n>>1^n,c=i>>1^r&a>>1^i,l=n&i>>1^a>>1^a;n=o,r=s,i=c,a=l,o=n&n>>2^r&r>>2,s=n&r>>2^r&(n^r)>>2,c^=n&i>>2^r&a>>2,l^=r&i>>2^(n^r)&a>>2,n=o,r=s,i=c,a=l,o=n&n>>4^r&r>>4,s=n&r>>4^r&(n^r)>>4,c^=n&i>>4^r&a>>4,l^=r&i>>4^(n^r)&a>>4,n=o,r=s,i=c,a=l,c^=n&i>>8^r&a>>8,l^=r&i>>8^(n^r)&a>>8,n=c^c>>1,r=l^l>>1;let u=e^t,d=r|65535^(u|n);return u=(u|u<<8)&16711935,u=(u|u<<4)&252645135,u=(u|u<<2)&858993459,u=(u|u<<1)&1431655765,d=(d|d<<8)&16711935,d=(d|d<<4)&252645135,d=(d|d<<2)&858993459,d=(d|d<<1)&1431655765,(d<<1|u)>>>0}var dM=(e,t,n=1e-9)=>{if(e.boundingBox.isOut(t.boundingBox))return O({intersections:[],commonSegments:[],commonSegmentsPoints:[]});let r=rC(),i,a;try{let o=r.intersectCurves2d(e.wrapped,t.wrapped,n);i=o.points,a=o.segments.map(e=>new Oj(e))}catch(e){return k(Ha(`INTERSECTION_FAILED`,`Intersections failed between curves`,e))}let o=a.filter(e=>GA(e.firstPoint,e.lastPoint,n)).map(e=>e.firstPoint);o.length&&(i.push(...o),a=a.filter(e=>!GA(e.firstPoint,e.lastPoint,n)));let s=a.flatMap(e=>[e.firstPoint,e.lastPoint]);return O({intersections:i,commonSegments:a,commonSegmentsPoints:s})},fM=(e,t=1e-9)=>{let n=rC(),r;try{let i=n.intersectCurves2d(e.wrapped,e.wrapped,t);r=i.points;for(let e of i.segments)e.delete()}catch(e){return k(Ha(`SELF_INTERSECTION_FAILED`,`Self intersection failed`,e))}return O(r)},pM=(e,n,r)=>{let i=ij(qA(n,e)),a=[i[1],-i[0]],o=[t(a,0)*r,t(a,1)*r];return{firstPoint:KA(e,o),lastPoint:KA(n,o)}},mM=(e,t)=>{let n=e.geomType,r=rC();if(n===`CIRCLE`){let n=r.getCurve2dCircleData(e.wrapped);if(!n)return Mj(e.firstPoint,e.lastPoint);let{cx:i,cy:a,radius:o,isDirect:s}=n,c=t*(s?1:-1),l=o+c;if(l<1e-10){let t=[i,a],n=e=>{let[n,r]=ij(qA(e,t));return KA(e,[c*n,c*r])};return{collapsed:!0,firstPoint:n(e.firstPoint),lastPoint:n(e.lastPoint)}}let u=new Oj(r.makeCircle2d(i,a,l,s)),d;try{d=r.trimCurve2d(u.wrapped,e.firstParameter,e.lastParameter)}finally{u.delete()}return new Oj(d)}if(n===`LINE`){let{firstPoint:n,lastPoint:r}=pM(e.firstPoint,e.lastPoint,t);return Mj(n,r)}let i=new Oj(r.offsetCurve2d(e.wrapped,t)),a=kj(i);if(i.delete(),j(fM(a)).length){let e=a.firstPoint,t=a.lastPoint;return a.delete(),{collapsed:!0,firstPoint:e,lastPoint:t}}return a};function hM(e,n,r){let i=ZA(e.tangentAt(1),n.tangentAt(0));if(Math.abs(i)<1e-10)return null;let a=Math.abs(r)*(i>0?-1:1),o=mM(e,a),s=mM(n,a);if(!(o instanceof Oj)||!(s instanceof Oj))return null;let c=dM(o,s,1e-9);if(!ua(c))return null;let l=c.value.intersections.at(-1);if(!yj(l))return null;let u=l,d=(e,t)=>{let[n,r]=t.tangentAt(u),i=KA(u,JA(ij([-r,n]),a)),o=j(e.parameter(i,1e-6));return e.splitAt([o])},f=d(e,o),p=d(n,s);return{first:t(f,0),second:t(p,1),center:u}}function gM(e,t,n){let r=hM(e,t,n);if(!r)return[e,t];let{first:i,second:a,center:o}=r;return[i,Bj(i.lastPoint,a.firstPoint,o),a]}function _M(e,t,n){let r=hM(e,t,n);if(!r)return[e,t];let{first:i,second:a}=r;return[i,Mj(i.lastPoint,a.firstPoint),a]}function vM(e,n,r){let i=ZA(ij(e.tangentAt(1)),ij(n.tangentAt(0))),a=Math.asin(i);if(Math.abs(i)<1e-10)return[e,n];let o=i>0?-1:1,s=Math.abs(r)*Math.sin(a/2)*o,c=mM(e,s),l=mM(n,s);if(!(c instanceof Oj)||!(l instanceof Oj))return[e,n];let u=dM(c,l,1e-9);if(!ua(u))return[e,n];let d=u.value.intersections.at(-1);if(!yj(d))return[e,n];let f=Fj(r,d),p=j(dM(e,f)).intersections[0],m=j(dM(n,f)).intersections.at(-1);if(!p||!m)return[e,n];let h=e.splitAt([p]),g=n.splitAt([m]),_=t(h,0),v=t(g,g.length-1);try{return[_,Nj(_.lastPoint,e.lastPoint,v.firstPoint),v]}catch{return[e,n]}}var yM=class e{blueprints;_boundingBox;constructor(e){this.blueprints=e,this._boundingBox=null}get repr(){return[`Blueprints`,...this.blueprints.map(e=>e.repr)].join(`
|
|
17
|
+
`)}clone(){return new e(this.blueprints.map(e=>e.clone()))}get boundingBox(){if(!this._boundingBox){let e=new Ej;this.blueprints.forEach(t=>{e.add(t.boundingBox)}),this._boundingBox=e}return this._boundingBox}stretch(t,n,r){return new e(this.blueprints.map(e=>e.stretch(t,n,r)))}rotate(t,n){return new e(this.blueprints.map(e=>e.rotate(t,n)))}scale(t,n){let r=n||this.boundingBox.center;return new e(this.blueprints.map(e=>e.scale(t,r)))}translate(t,n=0){return new e(this.blueprints.map(e=>typeof t==`number`?e.translate(t,n):e.translate(t)))}mirror(t,n,r){return new e(this.blueprints.map(e=>e.mirror(t,n,r)))}sketchOnPlane(e,t){return this.blueprints.map(n=>n.sketchOnPlane(e,t))}sketchOnFace(e,t){return this.blueprints.map(n=>n.sketchOnFace(e,t))}punchHole(e,t,n={}){let r=e;return this.blueprints.forEach(e=>{r=e.punchHole(r,t,n)}),r}toSVGViewBox(e=1){return $j(this.boundingBox,e)}toSVGPaths(){return this.blueprints.map(e=>e.toSVGPaths())}toSVG(e=1){return eM(this.blueprints.map(e=>e instanceof nM?e.toSVGPath():e.toSVGGroup()).join(`
|
|
18
|
+
`),this.boundingBox,e)}},bM=class e{blueprints;_boundingBox;constructor(e){e.length===0&&M(`CompoundBlueprint`,`requires at least one blueprint (the outer boundary) — use createCompoundBlueprint() for Result-based validation`),this.blueprints=e,this._boundingBox=null}clone(){return new e(this.blueprints.map(e=>e.clone()))}get boundingBox(){if(!this._boundingBox){let e=new Ej;this.blueprints.forEach(t=>{e.add(t.boundingBox)}),this._boundingBox=e}return this._boundingBox}get repr(){return[`Compound Blueprints`,`-- Outline`,yD(this.blueprints).repr,`-- Holes`,...this.blueprints.slice(1).map(e=>e.repr)].join(`
|
|
19
|
+
`)}stretch(t,n,r){return new e(this.blueprints.map(e=>e.stretch(t,n,r)))}rotate(t,n){return new e(this.blueprints.map(e=>e.rotate(t,n)))}scale(t,n){let r=n||this.boundingBox.center;return new e(this.blueprints.map(e=>e.scale(t,r)))}translate(t,n=0){return new e(this.blueprints.map(e=>typeof t==`number`?e.translate(t,n):e.translate(t)))}mirror(t,n,r){return new e(this.blueprints.map(e=>e.mirror(t,n,r)))}sketchOnPlane(e,t){return this.blueprints.map(n=>n.sketchOnPlane(e,t))}sketchOnFace(e,t){return this.blueprints.map(n=>n.sketchOnFace(e,t))}punchHole(e,t,n={}){return yD(this.blueprints).punchHole(e,t,n)}toSVGViewBox(e=1){return $j(this.boundingBox,e)}toSVGPaths(){return this.blueprints.flatMap(e=>e.toSVGPaths())}toSVGGroup(){return`<g>${this.blueprints.map(e=>e.toSVGPath()).join(``)}</g>`}toSVG(e=1){return eM(this.toSVGGroup(),this.boundingBox,e)}},xM=e=>{if(e.length===0)return[];if(e.length===1)return[[Ka(e,0,`groupByBoundingBoxOverlap`)]];let t=new oM(e.length);for(let n of e){let[[e,r],[i,a]]=n.boundingBox.bounds;t.add(e,r,i,a)}t.finish();let n=e.map((n,r)=>{let[[i,a],[o,s]]=n.boundingBox.bounds;return t.search(i,a,o,s).filter(t=>t>r&&!n.boundingBox.isOut(Ka(e,t,`groupByBoundingBoxOverlap`).boundingBox))}),r=[],i=Array(n.length);return n.forEach((t,n)=>{let a=i[n];a||(a=[],r.push(a)),a.push(Ka(e,n,`groupByBoundingBoxOverlap`)),t.length&&t.forEach(e=>{i[e]=a})}),r},SM=e=>e.map((t,n)=>{let r=Ka(t.curves,0,`addContainmentInfo`),i=r.value((r.lastParameter+r.firstParameter)/2);return{blueprint:t,isIn:e.filter((e,t)=>n===t?!1:e.isInside(i))}}),CM=(e,t)=>e.flatMap(({blueprint:e})=>TM(t.filter(({blueprint:t,isIn:n})=>t===e||n.indexOf(e)!==-1))),wM=(e,t)=>[t.filter(({isIn:e})=>e.length<=1),...TM(SM(e.map(({blueprint:e})=>e)))],TM=e=>{if(!e.length)return[];let t=e.filter(({isIn:e})=>!e.length),n=e.filter(({isIn:e})=>e.length>1);return t.length===1&&n.length===0?[e]:t.length>1?CM(t,e):wM(n,e)},EM=e=>new yM(xM(e).map(SM).flatMap(TM).map(e=>e.length===1?Ka(e,0,`organiseBlueprints`).blueprint:(e.sort((e,t)=>e.isIn.length-t.isIn.length),new bM(e.map(({blueprint:e})=>e))))),DM=e=>e===`symmetric`||typeof e==`number`||Array.isArray(e)&&e.length===2,OM=e=>{let t;t=e?DM(e)?{endTangent:e}:{endTangent:0,...e}:{endTangent:[1,0]};let{endTangent:n,startFactor:r=1,endFactor:i=1,startTangent:a}=t,o;o=typeof n==`number`?nj(1,n*Ww):n;let s;return s=typeof a==`number`?nj(1,a*Ww):a,{endTangent:o,startFactor:r,endFactor:i,startTangent:s}};function kM(e,t,n){return e<t?{majorRadius:t,minorRadius:e,rotationAngle:n+90}:{majorRadius:e,minorRadius:t,rotationAngle:n}}function AM(e,t,n,r,i,a,o,s){let c=i*Ww,l=e=>YA(s(e)),u=l(nj(n,c)),d=l(nj(r,c+Math.PI/2)),f=ij(s(ej([1,0],c))),[,p]=rj(f),{cx:m,cy:h,startAngle:g,endAngle:_,clockwise:v,rx:y,ry:b}=NM(e,t,u,d,p,a,o),x=Lj(y,b,v?g:_,v?_:g,[m,h],f);return v||x.reverse(),x}function jM(e,t,n,r,i){let a=Math.PI*2,o=MM(1,0,e,t),s=MM(e,t,-n,-r);for(;s>a;)s-=a;for(;s<0;)s+=a;i||(s-=a);let c=o+s;for(;c>a;)c-=a;for(;c<0;)c+=a;return{startAngle:o,deltaAngle:s,endAngle:c}}function MM(e,t,n,r){let i=e*n+t*r,a=Math.sqrt((e*e+t*t)*(n*n+r*r));a<1e-12&&M(`radianAngle`,`Cannot compute angle between zero-length vectors`);let o=Math.acos(Math.max(-1,Math.min(1,i/a)));return e*r-t*n<0&&(o=-o),o}function NM([e,t],[n,r],i,a,o,s,c){i<0&&(i=-i),a<0&&(a=-a),(i<1e-10||a<1e-10)&&M(`convertSvgEllipseParams`,`rx and ry cannot be 0`);let l=Math.sin(o),u=Math.cos(o),d=(e-n)/2,f=(t-r)/2,p=(e+n)/2,m=(t+r)/2,h=u*d+l*f,g=u*f-l*d,_=h*h/(i*i)+g*g/(a*a);_>1&&(i*=Math.sqrt(_),a*=Math.sqrt(_));let v=i*a,y=i*g,b=a*h,x=y*y+b*b;x||M(`convertSvgEllipseParams`,`Start point cannot be same as end point`);let S=Math.sqrt(Math.abs((v*v-x)/x));s===c&&(S=-S);let C=S*y/a,w=-S*b/i,ee=u*C-l*w+p,te=l*C+u*w+m,ne=(h-C)/i,re=(h+C)/i,{startAngle:ie,deltaAngle:ae,endAngle:oe}=jM(ne,(g-w)/a,re,(g+w)/a,c);return{cx:ee,cy:te,startAngle:ie,deltaAngle:ae,endAngle:oe,clockwise:c,rx:i,ry:a}}var PM={chamfer:_M,dogbone:vM,fillet:gM};function FM(e,t){if(typeof e==`function`)return e;let n=PM[t];return(t,r)=>n(t,r,e)}var IM=class{pointer;firstPoint;pendingCurves;_nextCorner;constructor(e=[0,0]){this.pointer=e,this.firstPoint=e,this._nextCorner=null,this.pendingCurves=[]}_convertToUV([e,t]){return[e,t]}_convertFromUV([e,t]){return[e,t]}_lastCurve(){let e=this.pendingCurves.length;return e===0?null:this.pendingCurves[e-1]}_requireLastCurve(e,t){let n=this._lastCurve();return n||M(e,`You need a previous curve to ${t}`),n}_resolveRelative(e,t){return[this.pointer[0]+e,this.pointer[1]+t]}_saveCurveAndAdvance(e,t){return this.saveCurve(e),this.pointer=t,this}get penPosition(){return this.pointer}get penAngle(){let e=this._lastCurve();if(!e)return 0;let[t,n]=e.tangentAt(1);return Math.atan2(n,t)*Gw}movePointerTo(e){return this.pendingCurves.length&&M(`Sketcher2d.movePointerTo`,`You can only move the pointer if there is no curve defined`),this.pointer=e,this.firstPoint=e,this}saveCurve(e){if(!this._nextCorner){this.pendingCurves.push(e);return}let t=this.pendingCurves.pop();t||M(`Sketcher2d.saveCurve`,`No previous curve available for custom corner`),this.pendingCurves.push(...this._nextCorner(t,e)),this._nextCorner=null}lineTo(e){let t=Mj(this._convertToUV(this.pointer),this._convertToUV(e));return this._saveCurveAndAdvance(t,e)}line(e,t){return this.lineTo(this._resolveRelative(e,t))}vLine(e){return this.line(0,e)}hLine(e){return this.line(e,0)}vLineTo(e){return this.lineTo([this.pointer[0],e])}hLineTo(e){return this.lineTo([e,this.pointer[1]])}polarLineTo([e,t]){return this.lineTo(nj(e,t*Ww))}polarLine(e,t){let[n,r]=nj(e,t*Ww);return this.line(n,r)}tangentLine(e){let t=this._requireLastCurve(`Sketcher2d.tangentLine`,`sketch a tangent line`),n=ij(this._convertFromUV(t.tangentAt(1)));return this.line(n[0]*e,n[1]*e)}threePointsArcTo(e,t){let n=Nj(this._convertToUV(this.pointer),this._convertToUV(t),this._convertToUV(e));return this._saveCurveAndAdvance(n,e)}threePointsArc(e,t,n,r){let[i,a]=this.pointer;return this.threePointsArcTo([i+e,a+t],[i+n,a+r])}sagittaArcTo(e,t){let[n,r]=this.pointer,[i,a]=e,o=(n+i)/2,s=(r+a)/2,c=-(a-r),l=i-n,u=Math.sqrt(c**2+l**2);u<1e-12&&M(`sagittaArcTo`,`Start and end points cannot be identical`);let d=[o+c/u*t,s+l/u*t],f=Nj(this._convertToUV(this.pointer),this._convertToUV(d),this._convertToUV(e));return this._saveCurveAndAdvance(f,e)}sagittaArc(e,t,n){return this.sagittaArcTo(this._resolveRelative(e,t),n)}vSagittaArc(e,t){return this.sagittaArc(0,e,t)}hSagittaArc(e,t){return this.sagittaArc(e,0,t)}bulgeArcTo(e,t){if(!t)return this.lineTo(e);let n=YA(this.pointer,e)/2;return this.sagittaArcTo(e,-t*n)}bulgeArc(e,t,n){return this.bulgeArcTo(this._resolveRelative(e,t),n)}vBulgeArc(e,t){return this.bulgeArc(0,e,t)}hBulgeArc(e,t){return this.bulgeArc(e,0,t)}tangentArcTo(e){let t=this._requireLastCurve(`Sketcher2d.tangentArc`,`sketch a tangent arc`),n=Pj(this._convertToUV(this.pointer),t.tangentAt(1),this._convertToUV(e));return this._saveCurveAndAdvance(n,e)}tangentArc(e,t){return this.tangentArcTo(this._resolveRelative(e,t))}ellipseTo(e,t,n,r=0,i=!1,a=!1){let{majorRadius:o,minorRadius:s,rotationAngle:c}=kM(t,n,r),l=AM(this._convertToUV(this.pointer),this._convertToUV(e),o,s,c,i,a,e=>this._convertToUV(e));return this._saveCurveAndAdvance(l,e)}ellipse(e,t,n,r,i=0,a=!1,o=!1){return this.ellipseTo(this._resolveRelative(e,t),n,r,i,a,o)}halfEllipseTo(e,t,n=!1){let r=$A(e,this.pointer),i=YA(e,this.pointer);return this.ellipseTo(e,i/2,t,r*Gw,!0,n)}halfEllipse(e,t,n,r=!1){return this.halfEllipseTo(this._resolveRelative(e,t),n,r)}bezierCurveTo(e,t){let n=t.length===2&&!Array.isArray(t[0])?[t]:t,r=Rj(this._convertToUV(this.pointer),n.map(e=>this._convertToUV(e)),this._convertToUV(e));return this._saveCurveAndAdvance(r,e)}quadraticBezierCurveTo(e,t){return this.bezierCurveTo(e,[t])}cubicBezierCurveTo(e,t,n){return this.bezierCurveTo(e,[t,n])}smoothSplineTo(e,t){let{endTangent:n,startTangent:r,startFactor:i,endFactor:a}=OM(t),o=this._lastCurve(),s=YA(this.pointer,e)*.25,c;c=r||(o?this._convertFromUV(o.tangentAt(1)):[1,0]),c=ij(c);let l=[this.pointer[0]+c[0]*i*s,this.pointer[1]+c[1]*i*s],u;u=n===`symmetric`?[-c[0],-c[1]]:n,u=ij(u);let d=[e[0]-u[0]*a*s,e[1]-u[1]*a*s];return this.cubicBezierCurveTo(e,l,d)}smoothSpline(e,t,n){return this.smoothSplineTo(this._resolveRelative(e,t),n)}customCorner(e,t=`fillet`){return this.pendingCurves.length||M(`Sketcher2d.customCorner`,`You need a curve defined to fillet the angle`),this._nextCorner=FM(e,t),this}_customCornerLastWithFirst(e,t=`fillet`){if(!e)return;let n=this.pendingCurves.pop(),r=this.pendingCurves.shift();(!n||!r)&&M(`Sketcher2d._customCornerLastWithFirst`,`Not enough curves to close and fillet`),this.pendingCurves.push(...FM(e,t)(n,r))}_closeSketch(){GA(this.pointer,this.firstPoint)||this.lineTo(this.firstPoint)}_closeWithMirror(){GA(this.pointer,this.firstPoint)&&M(`Sketcher2d._closeWithMirror`,`Cannot close with a mirror when the sketch is already closed`);let e=[this.pointer[0]-this.firstPoint[0],this.pointer[1]-this.firstPoint[1]],t=this._convertToUV(this.pointer),n=this._convertToUV(e),r=this.pendingCurves.map(e=>new Oj(U().mirrorCurve2dAcrossAxis(e.wrapped,t[0],t[1],n[0],n[1])));r.reverse();for(let e of r)e.reverse();this.pendingCurves.push(...r),this.pointer=this.firstPoint}},LM=class extends IM{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new nM(this.pendingCurves)}close(){return this._closeSketch(),this.done()}closeWithMirror(){return this._closeWithMirror(),this.close()}closeWithCustomCorner(e,t=`fillet`){return this._closeSketch(),this._customCornerLastWithFirst(e,t),this.done()}},RM=2*Math.PI;function zM(e){let t=e%RM,n=t<0?t+RM:t;return n<Math.PI?n:n===Math.PI?0:Math.abs(n-RM)}function BM(e){return e.curves.map((t,n)=>({firstCurve:t,secondCurve:vD(e.curves,(n+1)%e.curves.length),point:t.lastPoint}))}function VM(e){let t=t=>VM([...e,t]),n=t=>e.every(e=>e(t));return{shouldKeep:n,when:e=>t(e),inList:e=>t(t=>e.some(e=>GA(e,t.point))),atDistance:(e,n=[0,0])=>t(t=>Math.abs(YA(n,t.point)-e)<1e-9),atPoint:e=>t(t=>GA(e,t.point)),inBox:(e,n)=>{let r=Math.min(e[0],n[0]),i=Math.max(e[0],n[0]),a=Math.min(e[1],n[1]),o=Math.max(e[1],n[1]);return t(e=>{let[t,n]=e.point;return t>=r&&t<=i&&n>=a&&n<=o})},ofAngle:e=>t(t=>{let n=t.firstCurve.tangentAt(1),r=t.secondCurve.tangentAt(0);return Math.abs(zM(QA(n,r))-zM(Ww*e))<1e-9}),not:e=>{let n=e(VM([]));return t(e=>!n.shouldKeep(e))},either:e=>{let n=e.map(e=>e(VM([])));return t(e=>n.some(t=>t.shouldKeep(e)))},find:e=>BM(e).filter(n)}}function HM(){return VM([])}var UM=(e,t,n=0)=>{let r=[...Array(t).keys()].map(n=>{let r=-(Math.PI*2/t)*n;return[e*Math.sin(r),e*Math.cos(r)]}),i=bD(r),a=new LM().movePointerTo([i[0],i[1]]);return n?r.forEach(([e,t])=>a.sagittaArcTo([e,t],n)):r.forEach(([e,t])=>a.lineTo([e,t])),a.done()},WM=(e,t,n=0)=>{let{rx:r=0,ry:i=0}=typeof n==`number`?{ry:n,rx:n}:n,a=Math.min(r,e/2),o=Math.min(i,t/2),s=a&&o;s||(a=0,o=0);let c=a===o,l=new LM([Math.min(0,-(e/2-a)),-t/2]),u=(e,t)=>{s&&(c?l.tangentArc(e,t):l.ellipse(e,t,a,o,0,!1,!0))};return a<e/2&&l.hLine(e-2*a),u(a,o),o<t/2&&l.vLine(t-2*o),u(-a,o),a<e/2&&l.hLine(-(e-2*a)),u(-a,-o),o<t/2&&l.vLine(-(t-2*o)),u(a,-o),l.close()},GM=(e,t)=>GA(e,t,HA);function KM(e){return`${e[0].toFixed(9)},${e[1].toFixed(9)}`}function qM(e,t){let n=KM(e),r=KM(t);return n<r?`${n}|${r}`:`${r}|${n}`}function JM(e){let t=e[0];return t===void 0&&M(`startOfSegment`,`empty segment`),t.firstPoint}function YM(e){let t=e[e.length-1];return t===void 0&&M(`endOfSegment`,`empty segment`),t.lastPoint}function XM(e){return[...e].reverse().map(e=>{let t=e.clone();return t.reverse(),t})}function ZM(e){return[...e].reverse().map(XM)}function QM(e){let t=(e.lastParameter+e.firstParameter)/2;return e.value(t)}function $M(e,t){let n=KM(t);for(let r=0;r<e.length;r++){let i=e[r];if(i!==void 0&&KM(i.firstPoint)===n&&GM(t,i.firstPoint))return r}for(let n=0;n<e.length;n++){let r=e[n];if(r!==void 0&&GM(t,r.firstPoint))return n}return-1}function eN(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i];if(a!==void 0&&KM(a.firstPoint)===t&&KM(a.lastPoint)===n&&r(a))return i}for(let t=0;t<e.length;t++){let n=e[t];if(n!==void 0&&r(n))return t}return-1}function tN(e,t){return t<=0?e:e.slice(t).concat(e.slice(0,t))}function nN(e,t){return tN(e,$M(e,t))}function rN(e,t){let n=KM(t.firstPoint),r=KM(t.lastPoint),i=e=>GM(t.firstPoint,e.firstPoint)&&GM(t.lastPoint,e.lastPoint),a=e=>GM(t.lastPoint,e.firstPoint)&&GM(t.firstPoint,e.lastPoint);function o(e,t,n,r){let i=eN(e,t,n,r);return i===-1?null:tN(e,i)}let s=o(e,n,r,i);if(s!==null)return s;let c=o(e,r,n,a);if(c!==null)return c;let l=XM(e),u=o(l,n,r,i);if(u!==null)return u;let d=o(l,r,n,a);if(d!==null)return d;M(`rotateToStartAtSegment`,`failed to rotate to segment start`)}function*iN(e,t,n){let r=new Set(t.map(KM)),i=new Set(n.map(e=>qM(e.firstPoint,e.lastPoint))),a=e=>r.has(KM(e))?!0:t.some(t=>GM(t,e)),o=(e,t)=>i.has(qM(e,t))?!0:n.some(n=>GM(n.firstPoint,e)&&GM(n.lastPoint,t)||GM(n.firstPoint,t)&&GM(n.lastPoint,e)),s=[];for(let t of e){if(GM(t.firstPoint,t.lastPoint)){s.push(t);continue}let e=a(t.lastPoint),n=o(t.firstPoint,t.lastPoint);e?(s.push(t),yield s,s=[]):n?(s.length&&(yield s,s=[]),yield[t]):s.push(t)}s.length&&(yield s)}function aN(e,t,n){return e.filter(e=>{let r=t.filter(t=>GM(t.firstPoint,e)||GM(t.lastPoint,e)),i=r.length%2?r.filter(t=>!(GM(t.firstPoint,e)&&GM(t.lastPoint,e))):r;if(i.length===0||i.length%2)return!1;let a=i.map(e=>n.isInside(QM(e)));return!(a.every(Boolean)||a.every(e=>!e))})}function oN(e,n){let r=[],i=[],a=e.curves.map(()=>[]),o=n.curves.map(()=>[]),s=new oM(n.curves.length);for(let e of n.curves){let[[t,n],[r,i]]=e.boundingBox.bounds;s.add(t,n,r,i)}return s.finish(),e.curves.forEach((e,c)=>{let[[l,u],[d,f]]=e.boundingBox.bounds,p=s.search(l,u,d,f);for(let s of p){let{intersections:l,commonSegments:u,commonSegmentsPoints:d}=j(dM(e,t(n.curves,s),HA/100));r.push(...l),a[c]?.push(...l),o[s]?.push(...l),i.push(...u),r.push(...d),a[c]?.push(...d),o[s]?.push(...d)}}),{allIntersections:Tj(r,HA),allCommonSegments:i,firstCurvePoints:a,secondCurvePoints:o}}function sN(e,t){return SD([e,t]).flatMap(([e,t])=>t.length===0?[e]:e.splitAt(t,HA/100))}function cN(e,t,n){return e.some(([e,r])=>e===void 0||r===void 0?!1:GM(e,t)&&GM(r,n)||GM(e,n)&&GM(r,t))}function lN(e,t){let{allIntersections:n,allCommonSegments:r,firstCurvePoints:i,secondCurvePoints:a}=oN(e,t);if(n.length<=1)return null;let o=sN(e.curves,i),s=sN(t.curves,a),c=r.map(e=>[e.firstPoint,e.lastPoint]),l=aN(aN(n,o,t),s,e);if(l.length===0&&r.length===0)return null;if(r.length===0){let e=l[0];if(e===void 0)return null;o=nN(o,e),s=nN(s,e)}else{let e=r[0];if(e===void 0)return null;o=rN(o,e),s=rN(s,e)}let u=Array.from(iN(o,l,r)),d=Array.from(iN(s,l,r)),f=u[0],p=d[0];if(f!==void 0&&p!==void 0){let e=!GM(YM(p),YM(f)),t=r.length>0&&p.length!==1;(e||t)&&(d=ZM(d))}let m=Math.max(u.length,d.length),h=[];for(let e=0;e<m;e++){let t=u[e],n=d[e];if(t===void 0||n===void 0){let e=t??n;if(e===void 0)continue;h.push([e,e]);continue}cN(c,JM(t),YM(t))?h.push([t,`same`]):h.push([t,n])}return h}function uN(e){if(e.length<2)return e;let n=[],r=0;for(;r<e.length;){let i=t(e,r);if(i.geomType!==`LINE`){n.push(i),r++;continue}let a=i.lastPoint,o=r+1;for(;o<e.length;){let n=t(e,o);if(n.geomType!==`LINE`||!GM(a,n.firstPoint))break;let r=qA(a,i.firstPoint),s=qA(n.lastPoint,n.firstPoint);if(Math.abs(ZA(r,s))>1e-9)break;a=n.lastPoint,o++}o>r+1?n.push(Mj(i.firstPoint,a)):n.push(i),r=o}return n}function dN(e){let t=e.map(e=>e.firstPoint),n=e.map(e=>e.lastPoint),r=SD([t,n.slice(-1).concat(n.slice(0,-1))]).map(([e,t],n)=>e===void 0||t===void 0||GM(e,t)?null:n).filter(e=>e!==null);if(r.length===0)return[e];let i=SD([r.slice(0,-1),r.slice(1)]).map(([t,n])=>e.slice(t,n)),a=e.slice(r[r.length-1]),o=r[0];return o!==void 0&&o!==0&&(a=a.concat(e.slice(0,o))),i.push(a),i}function fN(e,t,n){return t===1?{curves:[...e],segmentsIn:1,lastWasSame:null}:t===2||t===0?{curves:[],segmentsIn:null,lastWasSame:null}:t===null?{curves:[],segmentsIn:null,lastWasSame:n?[...n,...e]:e}:{curves:[],segmentsIn:t,lastWasSame:n}}function pN(e,t,n,r,i,a,o){let s=[],c=0,l=e[0];if(l!==void 0){let t=QM(l),n=r.isInside(t);(i.firstInside===`keep`&&n||i.firstInside===`remove`&&!n)&&(c+=1,s.push(...e))}let u=t[0];if(u!==void 0){let e=QM(u),r=n.isInside(e);if(i.secondInside===`keep`&&r||i.secondInside===`remove`&&!r){let e=t;c===1&&(e=XM(t)),c+=1,s.push(...e)}}return a===null&&c===1&&o!==null&&(s=[...o,...s]),{curves:s,segmentsIn:c===1?c:a,lastWasSame:c===1?null:o}}function mN(e,t,n){let r=lN(e,t);if(r===null)return hN(e,t);if(r.every(([,e])=>e===`same`))return{identical:!0};let i=null,a=null,o=r.flatMap(([r,o])=>{if(o===`same`){let e=fN(r,i,a);return i=e.segmentsIn,a=e.lastWasSame,e.curves}let s=pN(r,o,e,t,n,i,a);return i=s.segmentsIn,a=s.lastWasSame,s.curves}),s=a;s!==null&&i===1&&(o=[...s,...o]);let c=dN(uN(o)).filter(e=>e.length>0).map(e=>new nM(e));if(c.length===0)return null;if(c.length===1){let e=c[0];return e===void 0?null:e}return EM(c)}function hN(e,t){let n=e.curves[0],r=t.curves[0];return{identical:!1,firstCurveInSecond:n!==void 0&&t.isInside(QM(n)),secondCurveInFirst:r!==void 0&&e.isInside(QM(r))}}function gN(e,t){let n=mN(e,t,{firstInside:`remove`,secondInside:`remove`});return n===null||n instanceof nM||n instanceof yM?n:n.identical?e.clone():n.firstCurveInSecond?t.clone():n.secondCurveInFirst?e.clone():new yM([e,t])}function _N(e,t){let n=mN(e,t,{firstInside:`remove`,secondInside:`keep`});return n===null||n instanceof nM||n instanceof yM?n:n.identical||n.firstCurveInSecond?null:n.secondCurveInFirst?new yM([new bM([e,t])]):e.clone()}function vN(e,t){let n=mN(e,t,{firstInside:`keep`,secondInside:`keep`});return n===null||n instanceof nM||n instanceof yM?n:n.identical||n.firstCurveInSecond?e.clone():n.secondCurveInFirst?t.clone():null}var yN=(e,t)=>{if(e instanceof nM&&t instanceof nM){let n=[];return e.curves.forEach(e=>{t.curves.forEach(t=>{let{intersections:r,commonSegmentsPoints:i}=j(dM(e,t));n.push(...r),n.push(...i)})}),n=Tj(n),n.length>1}if(e instanceof bM||e instanceof yM)return e.blueprints.some(e=>yN(e,t));if(t instanceof bM||t instanceof yM)return t.blueprints.some(t=>yN(e,t));M(`genericIntersects`,`Unhandled shape combination in genericIntersects`)},bN=(e,t)=>{if(e instanceof bM){if(t instanceof nM)return CN(t,e);if(t instanceof bM)return TN(e,t)}if(t instanceof bM){if(e instanceof nM)return CN(e,t);if(e instanceof bM)return TN(e,t)}if(e instanceof nM&&t instanceof nM)return gN(e,t);M(`genericFuse`,`Unhandled shape combination in genericFuse`)},xN=e=>{let t=new Map,n=[];return e.forEach((r,i)=>{let a;t.has(i)?a=t.get(i):(a={current:r,fusedWith:new Set([i])},n.push(a)),e.slice(i+1).forEach((e,n)=>{let r=a.current,o=i+n+1;if(a.fusedWith.has(o))return;let s=e,c=!1;if(t.has(o)&&(s=t.get(o).current,c=!0),r.boundingBox.isOut(s.boundingBox)||!yN(r,s))return;let l;if(r instanceof yM||s instanceof yM){let e=EN(r,s);e===null&&M(`fuseIntersectingBlueprints`,`fuse2D returned null for non-null inputs`),l=e}else l=bN(r,s);if(!(l instanceof nM||l instanceof bM)){if(l instanceof yM&&l.blueprints.length===2)return;l instanceof yM&&l.blueprints.length===1?l=Ka(l.blueprints,0,`fuseIntersectingBlueprints`):l instanceof yM||M(`fuseIntersectingBlueprints`,`Fuse produced unexpected non-blueprint result`)}a.fusedWith.add(o),a.current=l,c||t.set(o,a)})}),EM(n.map(({current:e})=>e).flatMap(e=>SN(e)))},SN=e=>e instanceof nM?[e]:e instanceof bM?e.blueprints:e instanceof yM?e.blueprints.flatMap(e=>SN(e)):[],CN=(e,t)=>{let n=gN(e,Ka(t.blueprints,0,`fuseBlueprintWithCompound`)),r=t.blueprints.slice(1).map(t=>_N(t,e));return EM([...SN(n),...r.flatMap(e=>SN(e))])};function wN(e,t){let n=[];for(let r of e)for(let e of t)n.push([r,e]);return n}var TN=(e,t)=>{let n=Ka(e.blueprints,0,`fuseCompoundWithCompound`),r=Ka(t.blueprints,0,`fuseCompoundWithCompound`),i=gN(n,r),a=t.blueprints.slice(1).map(e=>_N(e,n)),o=e.blueprints.slice(1).map(e=>_N(e,r)),s=wN(e.blueprints.slice(1),t.blueprints.slice(1)).flatMap(([e,t])=>SN(vN(e,t)));return EM([...SN(i),...a.flatMap(e=>SN(e)),...o.flatMap(e=>SN(e)),...s])},EN=(e,t)=>{if(e===null)return t?.clone()??null;if(t===null)return e.clone();if(!(e instanceof yM)&&t instanceof yM)return xN([e,...t.blueprints]);if(!(t instanceof yM)&&e instanceof yM)return xN([t,...e.blueprints]);if(e instanceof yM&&t instanceof yM){let n=EN(Ka(e.blueprints,0,`fuse2D`),t);return e.blueprints.slice(1).forEach(e=>{n=EN(e,n)}),n}if(e instanceof bM){if(t instanceof yM)return EN(t,e);if(t instanceof nM)return CN(t,e);if(t instanceof bM)return TN(e,t)}if(t instanceof bM){if(e instanceof yM)return EN(e,t);if(e instanceof nM)return CN(e,t);if(e instanceof bM)return TN(e,t)}return e instanceof nM&&t instanceof nM?gN(e,t):null},DN=e=>{let t=e.flatMap(e=>e===null?[]:e instanceof yM?e.blueprints:e);return t.length===1?Ka(t,0,`mergeNonIntersecting`):new yM(t)},ON=(e,t)=>{if(e===null)return null;if(t===null)return e.clone();if(e instanceof yM)return DN(e.blueprints.map(e=>ON(e,t)));if(e instanceof bM){let n=Ka(e.blueprints,0,`cut2D`);if(t instanceof nM&&!t.intersects(n))return n.isInside(t.firstPoint)?EM([n,...SN(EN(t,new yM(e.blueprints.slice(1))))]):e.clone();{let r=ON(n,t);return e.blueprints.slice(1).forEach(e=>{r=ON(r,e)}),r}}if(t instanceof yM){let n=e;for(let e of t.blueprints)n=ON(n,e);return n}if(t instanceof bM){let n=_N(e,Ka(t.blueprints,0,`cut2D`));return t.blueprints.slice(1).forEach(t=>{n=EN(n,vN(t,e))}),n}return _N(e,t)};function kN(e,t){if(e===null||t===null)return null;if(e instanceof nM&&t instanceof nM)return vN(e,t);if(e instanceof yM)return DN(e.blueprints.map(e=>kN(e,t)));if(e instanceof bM){let n=Ka(e.blueprints,0,`intersect2D`),r=e.blueprints.slice(1);if(r.length===0)return kN(n,t);let i=kN(n,t);for(let e of r)i=ON(i,e);return i}if(t instanceof yM)return DN(t.blueprints.map(t=>kN(e,t)));if(t instanceof bM){let n=Ka(t.blueprints,0,`intersect2D`),r=t.blueprints.slice(1);if(r.length===0)return kN(n,e);let i=kN(n,e);for(let e of r)i=ON(i,e);return i}M(`intersect2D`,`Unhandled Shape2D combination`)}function AN(e,{profile:t,endFactor:n=1}){return e<1e-10?k(F(`INVALID_EXTRUSION_LENGTH`,`Extrusion length too small (< 1e-10)`)):t!==`s-curve`&&t!==`linear`?k(F(`UNSUPPORTED_PROFILE`,`Unsupported extrusion profile: ${String(t)}`)):O(U().buildExtrusionLaw(t,e,n).Trim(0,e,1e-6))}function jN(e,t){let n=U(),r=n.makeLineEdge([...e],[...t]);return W(n.makeWire([r]))}function MN(e,t,n,r,i,a=!1){return W(U().makeHelixWire(e,t,n,[...r],[...i],a))}function NN(e,t,n={},r=!1){if(n.mode===`simple`&&!r){let n=W(U().simplePipe(e.wrapped,t.wrapped));return uw(n)?O(n):k(za(`SWEEP_NOT_3D`,`Simple pipe did not produce a 3D shape`))}let{frenet:i=!1,auxiliarySpine:a,law:o=null,transitionMode:s=`right`,withContact:c,support:l,forceProfileSpineOthogonality:u,tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h}=n,g=U(),_=s===`round`?!0:!!u,v=g.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:s,contact:!!c,correction:_,frenet:i,shellMode:r,...a?.wrapped?{auxiliary:a.wrapped}:{},...o===null?{}:{law:o},...l===null?{}:{support:l},tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h});if(r&&typeof v==`object`&&`firstShape`in v){let e=W(v.shape);if(!uw(e))return k(za(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`));let t=W(v.firstShape),n=W(v.lastShape);return aw(t)?aw(n)?O([e,t,n]):k(za(`SWEEP_END_NOT_WIRE`,`Sweep did not produce an end Wire`)):k(za(`SWEEP_START_NOT_WIRE`,`Sweep did not produce a start Wire`))}let y=W(v);return uw(y)?O(y):k(za(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`))}function PN(e,t,n,r){return NN(e,jN(t,Xw(t,n)),{support:r})}function FN(e,t,n,r,i=!1){let a=nT(n);if(a<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let o=jN(t,Xw(t,n)),s=null;if(r){let e=AN(a,r);if(A(e))return e;s=e.value}return NN(e,o,{law:s},i)}function IN(e,t,n,r,i,a=!1){if(Math.abs(t)<1e-10)return k(F(`ZERO_TWIST_ANGLE`,`Twist angle cannot be zero`));let o=nT(r);if(o<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let s=jN(n,Xw(n,r)),c=t<0,l=MN(360/Math.abs(t)*o,o,1,n,r,c),u=null;if(i){let e=AN(o,i);if(A(e))return e;u=e.value}return NN(e,s,{auxiliarySpine:l,law:u},a)}function LN(e){let t=e.map(e=>e.location);for(let e=0;e<t.length;e++){let n=t[e];if(n!==void 0&&(n<0||n>1))return F(N.MULTI_SWEEP_FAILED,`Section ${e} location ${n} is out of range [0, 1]`)}let n=t.filter(e=>e!==void 0);for(let e=1;e<n.length;e++)if((n[e]??0)<=(n[e-1]??0))return F(N.MULTI_SWEEP_FAILED,`Section locations must be strictly increasing`)}function RN(e,t,n){let[r,i]=n.curveParameters(t.wrapped),a=i-r,o=Array(e.length);for(let t=0;t<e.length;t++){let n=e[t]?.location;o[t]=n===void 0?NaN:r+n*a}let s=-1,c=r;for(let t=0;t<=e.length;t++){let n=t===e.length;if(!n&&!Number.isNaN(o[t]??NaN)||n){let e=n?i:o[t]??i,a=t-s-1;for(let t=1;t<=a;t++)o[s+t]=c+t/(a+1)*(e-c);n||(s=t,c=o[t]??r)}}for(let e=1;e<o.length;e++)if((o[e]??0)<=(o[e-1]??0))return k(F(N.MULTI_SWEEP_FAILED,`Computed section parameters are not strictly increasing at index ${e} (${o[e-1]?.toFixed(4)} >= ${o[e]?.toFixed(4)})`));return O(o)}function zN(e,t,n){if(e.length<2)return k(F(N.MULTI_SWEEP_INSUFFICIENT_SECTIONS,`Multi-section sweep requires at least 2 sections, got ${e.length}`));let{solid:r=!0,ruled:i=!1,tolerance:a=1e-6}=n??{},o=LN(e);if(o)return k(o);try{let n=U(),o=RN(e,t,n);if(A(o))return o;let s=o.value,c=[];for(let r=0;r<e.length;r++){let i=s[r],a=e[r];if(i===void 0||a===void 0)continue;let o=n.positionOnCurve(a.wire.wrapped,t.wrapped,i);c.push(n.downcast(o,`wire`))}let l=W(n.loftAdvanced(c,{solid:r,ruled:i,tolerance:a}));return uw(l)?O(l):k(za(`MULTI_SWEEP_NOT_3D`,`Multi-section sweep did not produce a 3D shape`))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.MULTI_SWEEP_FAILED,`Multi-section sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function BN(e,t,n,r={}){let{transition:i=`transformed`,solid:a=!0,tolerance:o}=r;try{let r=U(),s=!a,c=n.length>0?n[0]?.wrapped:void 0,l=r.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:i,...c?{auxiliary:c}:{},shellMode:s,...o===void 0?{}:{tolerance:o,boundTolerance:o}}),u=W(typeof l==`object`&&`shape`in l?l.shape:l);return uw(u)?O(u):k(za(`GUIDED_SWEEP_NOT_3D`,`Guided sweep did not produce a 3D shape`))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.GUIDED_SWEEP_FAILED,`Guided sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function VN(e,t){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`extrude: face is a null shape`));if(nT(t)<1e-10)return k(F(`EXTRUDE_ZERO_VECTOR`,`extrude: extrusion vector has zero length`));try{let n=U(),r=nT(t),i=aT(t),a=n.extrude(e.wrapped,[...i],r);return O(ew(n.downcast(a,`solid`)))}catch(e){return k(P(`EXTRUDE_FAILED`,`Extrusion operation failed`,e,{operation:`extrude`,vectorLength:nT(t)}))}}function HN(e,t=[0,0,0],n=[0,0,1],r=360){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`revolve: face is a null shape`));try{let i=W(U().revolveVec(e.wrapped,[...t],[...n],r));return uw(i)?O(i):k(za(`REVOLUTION_NOT_3D`,`Revolution did not produce a 3D shape`))}catch(e){return k(P(`REVOLVE_FAILED`,`Revolution operation failed`,e,{operation:`revolve`,angle:r}))}}function UN(e){if(e.length===0)return O([]);let t=U(),n=[];for(let t=0;t<e.length;t++){let r=e[t];if(!r)continue;let i=typeof r.height==`number`?[0,0,r.height]:r.height,a=nT(i);if(a<1e-10)return k(F(`EXTRUDE_ALL_ZERO_VECTOR`,`extrudeAll: entry ${t} has zero-length extrusion vector`));let o=[...aT(i)];n.push({face:r.face.wrapped,direction:o,length:a})}try{return O((t.extrudeBatch?.(n)??n.map(e=>t.extrude(e.face,e.direction,e.length))).map(e=>ew(t.downcast(e,`solid`))))}catch(e){return k(P(`EXTRUDE_ALL_FAILED`,`Batch extrusion operation failed`,e))}}var WN=e(((e,t)=>{t.exports={}}));
|
|
20
20
|
/*! https://mths.be/codepointat v0.2.0 by @mathias */
|
|
21
|
-
String.prototype.codePointAt||(function(){var e=function(){try{var e={},t=Object.defineProperty,n=t(e,e,e)&&t}catch{}return n}(),t=function(e){if(this==null)throw TypeError();var t=String(this),n=t.length,r=e?Number(e):0;if(r!=r&&(r=0),!(r<0||r>=n)){var i=t.charCodeAt(r),a;return i>=55296&&i<=56319&&n>r+1&&(a=t.charCodeAt(r+1),a>=56320&&a<=57343)?(i-55296)*1024+a-56320+65536:i}};e?e(String.prototype,`codePointAt`,{value:t,configurable:!0,writable:!0}):String.prototype.codePointAt=t})();var KN=0,qN=-3;function JN(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function YN(e,t){this.source=e,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=t,this.destLen=0,this.ltree=new JN,this.dtree=new JN}var XN=new JN,ZN=new JN,QN=new Uint8Array(30),$N=new Uint16Array(30),eP=new Uint8Array(30),tP=new Uint16Array(30),nP=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),rP=new JN,iP=new Uint8Array(320);function aP(e,t,n,r){var i,a;for(i=0;i<n;++i)e[i]=0;for(i=0;i<30-n;++i)e[i+n]=i/n|0;for(a=r,i=0;i<30;++i)t[i]=a,a+=1<<e[i]}function oP(e,t){var n;for(n=0;n<7;++n)e.table[n]=0;for(e.table[7]=24,e.table[8]=152,e.table[9]=112,n=0;n<24;++n)e.trans[n]=256+n;for(n=0;n<144;++n)e.trans[24+n]=n;for(n=0;n<8;++n)e.trans[168+n]=280+n;for(n=0;n<112;++n)e.trans[176+n]=144+n;for(n=0;n<5;++n)t.table[n]=0;for(t.table[5]=32,n=0;n<32;++n)t.trans[n]=n}var sP=new Uint16Array(16);function cP(e,t,n,r){var i,a;for(i=0;i<16;++i)e.table[i]=0;for(i=0;i<r;++i)e.table[t[n+i]]++;for(e.table[0]=0,a=0,i=0;i<16;++i)sP[i]=a,a+=e.table[i];for(i=0;i<r;++i)t[n+i]&&(e.trans[sP[t[n+i]]++]=i)}function lP(e){e.bitcount--||(e.tag=e.source[e.sourceIndex++],e.bitcount=7);var t=e.tag&1;return e.tag>>>=1,t}function uP(e,t,n){if(!t)return n;for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<<e.bitcount,e.bitcount+=8;var r=e.tag&65535>>>16-t;return e.tag>>>=t,e.bitcount-=t,r+n}function dP(e,t){for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<<e.bitcount,e.bitcount+=8;var n=0,r=0,i=0,a=e.tag;do r=2*r+(a&1),a>>>=1,++i,n+=t.table[i],r-=t.table[i];while(r>=0);return e.tag=a,e.bitcount-=i,t.trans[n+r]}function fP(e,t,n){var r=uP(e,5,257),i=uP(e,5,1),a=uP(e,4,4),o,s,c;for(o=0;o<19;++o)iP[o]=0;for(o=0;o<a;++o){var l=uP(e,3,0);iP[nP[o]]=l}for(cP(rP,iP,0,19),s=0;s<r+i;){var u=dP(e,rP);switch(u){case 16:var d=iP[s-1];for(c=uP(e,2,3);c;--c)iP[s++]=d;break;case 17:for(c=uP(e,3,3);c;--c)iP[s++]=0;break;case 18:for(c=uP(e,7,11);c;--c)iP[s++]=0;break;default:iP[s++]=u;break}}cP(t,iP,0,r),cP(n,iP,r,i)}function pP(e,t,n){for(;;){var r=dP(e,t);if(r===256)return KN;if(r<256)e.dest[e.destLen++]=r;else{var i,a,o,s;for(r-=257,i=uP(e,QN[r],$N[r]),a=dP(e,n),o=e.destLen-uP(e,eP[a],tP[a]),s=o;s<o+i;++s)e.dest[e.destLen++]=e.dest[s]}}}function mP(e){for(var t,n,r;e.bitcount>8;)e.sourceIndex--,e.bitcount-=8;if(t=e.source[e.sourceIndex+1],t=256*t+e.source[e.sourceIndex],n=e.source[e.sourceIndex+3],n=256*n+e.source[e.sourceIndex+2],t!==(~n&65535))return qN;for(e.sourceIndex+=4,r=t;r;--r)e.dest[e.destLen++]=e.source[e.sourceIndex++];return e.bitcount=0,KN}function hP(e,t){var n=new YN(e,t),r,i,a;do{switch(r=lP(n),i=uP(n,2,0),i){case 0:a=mP(n);break;case 1:a=pP(n,XN,ZN);break;case 2:fP(n,n.ltree,n.dtree),a=pP(n,n.ltree,n.dtree);break;default:a=qN}if(a!==KN)throw Error(`Data error`)}while(!r);return n.destLen<n.dest.length?typeof n.dest.slice==`function`?n.dest.slice(0,n.destLen):n.dest.subarray(0,n.destLen):n.dest}oP(XN,ZN),aP(QN,$N,4,3),aP(eP,tP,2,1),QN[28]=0,$N[28]=258;var gP=hP;function _P(e,t,n,r,i){return(1-i)**3*e+3*(1-i)**2*i*t+3*(1-i)*i**2*n+i**3*r}function vP(){this.x1=NaN,this.y1=NaN,this.x2=NaN,this.y2=NaN}vP.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)},vP.prototype.addPoint=function(e,t){typeof e==`number`&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=e,this.x2=e),e<this.x1&&(this.x1=e),e>this.x2&&(this.x2=e)),typeof t==`number`&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=t,this.y2=t),t<this.y1&&(this.y1=t),t>this.y2&&(this.y2=t))},vP.prototype.addX=function(e){this.addPoint(e,null)},vP.prototype.addY=function(e){this.addPoint(null,e)},vP.prototype.addBezier=function(e,t,n,r,i,a,o,s){var c=[e,t],l=[n,r],u=[i,a],d=[o,s];this.addPoint(e,t),this.addPoint(o,s);for(var f=0;f<=1;f++){var p=6*c[f]-12*l[f]+6*u[f],m=-3*c[f]+9*l[f]-9*u[f]+3*d[f],h=3*l[f]-3*c[f];if(m===0){if(p===0)continue;var g=-h/p;0<g&&g<1&&(f===0&&this.addX(_P(c[f],l[f],u[f],d[f],g)),f===1&&this.addY(_P(c[f],l[f],u[f],d[f],g)));continue}var _=p**2-4*h*m;if(!(_<0)){var v=(-p+Math.sqrt(_))/(2*m);0<v&&v<1&&(f===0&&this.addX(_P(c[f],l[f],u[f],d[f],v)),f===1&&this.addY(_P(c[f],l[f],u[f],d[f],v)));var y=(-p-Math.sqrt(_))/(2*m);0<y&&y<1&&(f===0&&this.addX(_P(c[f],l[f],u[f],d[f],y)),f===1&&this.addY(_P(c[f],l[f],u[f],d[f],y)))}}},vP.prototype.addQuad=function(e,t,n,r,i,a){var o=e+2/3*(n-e),s=t+2/3*(r-t),c=o+1/3*(i-e),l=s+1/3*(a-t);this.addBezier(e,t,o,s,c,l,i,a)};function yP(){this.commands=[],this.fill=`black`,this.stroke=null,this.strokeWidth=1}yP.prototype.moveTo=function(e,t){this.commands.push({type:`M`,x:e,y:t})},yP.prototype.lineTo=function(e,t){this.commands.push({type:`L`,x:e,y:t})},yP.prototype.curveTo=yP.prototype.bezierCurveTo=function(e,t,n,r,i,a){this.commands.push({type:`C`,x1:e,y1:t,x2:n,y2:r,x:i,y:a})},yP.prototype.quadTo=yP.prototype.quadraticCurveTo=function(e,t,n,r){this.commands.push({type:`Q`,x1:e,y1:t,x:n,y:r})},yP.prototype.close=yP.prototype.closePath=function(){this.commands.push({type:`Z`})},yP.prototype.extend=function(e){if(e.commands)e=e.commands;else if(e instanceof vP){var t=e;this.moveTo(t.x1,t.y1),this.lineTo(t.x2,t.y1),this.lineTo(t.x2,t.y2),this.lineTo(t.x1,t.y2),this.close();return}Array.prototype.push.apply(this.commands,e)},yP.prototype.getBoundingBox=function(){for(var e=new vP,t=0,n=0,r=0,i=0,a=0;a<this.commands.length;a++){var o=this.commands[a];switch(o.type){case`M`:e.addPoint(o.x,o.y),t=r=o.x,n=i=o.y;break;case`L`:e.addPoint(o.x,o.y),r=o.x,i=o.y;break;case`Q`:e.addQuad(r,i,o.x1,o.y1,o.x,o.y),r=o.x,i=o.y;break;case`C`:e.addBezier(r,i,o.x1,o.y1,o.x2,o.y2,o.x,o.y),r=o.x,i=o.y;break;case`Z`:r=t,i=n;break;default:throw Error(`Unexpected path command `+o.type)}}return e.isEmpty()&&e.addPoint(0,0),e},yP.prototype.draw=function(e){e.beginPath();for(var t=0;t<this.commands.length;t+=1){var n=this.commands[t];n.type===`M`?e.moveTo(n.x,n.y):n.type===`L`?e.lineTo(n.x,n.y):n.type===`C`?e.bezierCurveTo(n.x1,n.y1,n.x2,n.y2,n.x,n.y):n.type===`Q`?e.quadraticCurveTo(n.x1,n.y1,n.x,n.y):n.type===`Z`&&e.closePath()}this.fill&&(e.fillStyle=this.fill,e.fill()),this.stroke&&(e.strokeStyle=this.stroke,e.lineWidth=this.strokeWidth,e.stroke())},yP.prototype.toPathData=function(e){e=e===void 0?2:e;function t(t){return Math.round(t)===t?``+Math.round(t):t.toFixed(e)}function n(){for(var e=arguments,n=``,r=0;r<arguments.length;r+=1){var i=e[r];i>=0&&r>0&&(n+=` `),n+=t(i)}return n}for(var r=``,i=0;i<this.commands.length;i+=1){var a=this.commands[i];a.type===`M`?r+=`M`+n(a.x,a.y):a.type===`L`?r+=`L`+n(a.x,a.y):a.type===`C`?r+=`C`+n(a.x1,a.y1,a.x2,a.y2,a.x,a.y):a.type===`Q`?r+=`Q`+n(a.x1,a.y1,a.x,a.y):a.type===`Z`&&(r+=`Z`)}return r},yP.prototype.toSVG=function(e){var t=`<path d="`;return t+=this.toPathData(e),t+=`"`,this.fill&&this.fill!==`black`&&(this.fill===null?t+=` fill="none"`:t+=` fill="`+this.fill+`"`),this.stroke&&(t+=` stroke="`+this.stroke+`" stroke-width="`+this.strokeWidth+`"`),t+=`/>`,t},yP.prototype.toDOMElement=function(e){var t=this.toPathData(e),n=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return n.setAttribute(`d`,t),n};function bP(e){throw Error(e)}function xP(e,t){e||bP(t)}var K={fail:bP,argument:xP,assert:xP},SP=32768,CP=2147483648,wP={},q={},J={};function TP(e){return function(){return e}}q.BYTE=function(e){return K.argument(e>=0&&e<=255,`Byte value should be between 0 and 255.`),[e]},J.BYTE=TP(1),q.CHAR=function(e){return[e.charCodeAt(0)]},J.CHAR=TP(1),q.CHARARRAY=function(e){e===void 0&&(e=``,console.warn(`Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name.`));for(var t=[],n=0;n<e.length;n+=1)t[n]=e.charCodeAt(n);return t},J.CHARARRAY=function(e){return e===void 0?0:e.length},q.USHORT=function(e){return[e>>8&255,e&255]},J.USHORT=TP(2),q.SHORT=function(e){return e>=SP&&(e=-(2*SP-e)),[e>>8&255,e&255]},J.SHORT=TP(2),q.UINT24=function(e){return[e>>16&255,e>>8&255,e&255]},J.UINT24=TP(3),q.ULONG=function(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]},J.ULONG=TP(4),q.LONG=function(e){return e>=CP&&(e=-(2*CP-e)),[e>>24&255,e>>16&255,e>>8&255,e&255]},J.LONG=TP(4),q.FIXED=q.ULONG,J.FIXED=J.ULONG,q.FWORD=q.SHORT,J.FWORD=J.SHORT,q.UFWORD=q.USHORT,J.UFWORD=J.USHORT,q.LONGDATETIME=function(e){return[0,0,0,0,e>>24&255,e>>16&255,e>>8&255,e&255]},J.LONGDATETIME=TP(8),q.TAG=function(e){return K.argument(e.length===4,`Tag should be exactly 4 ASCII characters.`),[e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3)]},J.TAG=TP(4),q.Card8=q.BYTE,J.Card8=J.BYTE,q.Card16=q.USHORT,J.Card16=J.USHORT,q.OffSize=q.BYTE,J.OffSize=J.BYTE,q.SID=q.USHORT,J.SID=J.USHORT,q.NUMBER=function(e){return e>=-107&&e<=107?[e+139]:e>=108&&e<=1131?(e-=108,[(e>>8)+247,e&255]):e>=-1131&&e<=-108?(e=-e-108,[(e>>8)+251,e&255]):e>=-32768&&e<=32767?q.NUMBER16(e):q.NUMBER32(e)},J.NUMBER=function(e){return q.NUMBER(e).length},q.NUMBER16=function(e){return[28,e>>8&255,e&255]},J.NUMBER16=TP(3),q.NUMBER32=function(e){return[29,e>>24&255,e>>16&255,e>>8&255,e&255]},J.NUMBER32=TP(5),q.REAL=function(e){var t=e.toString(),n=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(t);if(n){var r=parseFloat(`1e`+((n[2]?+n[2]:0)+n[1].length));t=(Math.round(e*r)/r).toString()}for(var i=``,a=0,o=t.length;a<o;a+=1){var s=t[a];s===`e`?i+=t[++a]===`-`?`c`:`b`:s===`.`?i+=`a`:s===`-`?i+=`e`:i+=s}i+=i.length&1?`f`:`ff`;for(var c=[30],l=0,u=i.length;l<u;l+=2)c.push(parseInt(i.substr(l,2),16));return c},J.REAL=function(e){return q.REAL(e).length},q.NAME=q.CHARARRAY,J.NAME=J.CHARARRAY,q.STRING=q.CHARARRAY,J.STRING=J.CHARARRAY,wP.UTF8=function(e,t,n){for(var r=[],i=n,a=0;a<i;a++,t+=1)r[a]=e.getUint8(t);return String.fromCharCode.apply(null,r)},wP.UTF16=function(e,t,n){for(var r=[],i=n/2,a=0;a<i;a++,t+=2)r[a]=e.getUint16(t);return String.fromCharCode.apply(null,r)},q.UTF16=function(e){for(var t=[],n=0;n<e.length;n+=1){var r=e.charCodeAt(n);t[t.length]=r>>8&255,t[t.length]=r&255}return t},J.UTF16=function(e){return e.length*2};var EP={"x-mac-croatian":`ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®Š™´¨≠ŽØ∞±≤≥∆µ∂∑∏š∫ªºΩžø¿¡¬√ƒ≈ƫȅ\xA0ÀÃÕŒœĐ—“”‘’÷◊©⁄€‹›Æ»–·‚„‰ÂćÁčÈÍÎÏÌÓÔđÒÚÛÙıˆ˜¯πË˚¸Êæˇ`,"x-mac-cyrillic":`АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњјЅ¬√ƒ≈∆«»…\xA0ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю`,"x-mac-gaelic":`ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØḂ±≤≥ḃĊċḊḋḞḟĠġṀæøṁṖṗɼƒſṠ«»…\xA0ÀÃÕŒœ–—“”‘’ṡẛÿŸṪ€‹›Ŷŷṫ·Ỳỳ⁊ÂÊÁËÈÍÎÏÌÓÔ♣ÒÚÛÙıÝýŴŵẄẅẀẁẂẃ`,"x-mac-greek":`Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩάΝ¬ΟΡ≈Τ«»…\xA0ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ`,"x-mac-icelandic":`ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûüݰ¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»…\xA0ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€ÐðÞþý·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ`,"x-mac-inuit":`ᐃᐄᐅᐆᐊᐋᐱᐲᐳᐴᐸᐹᑉᑎᑏᑐᑑᑕᑖᑦᑭᑮᑯᑰᑲᑳᒃᒋᒌᒍᒎᒐᒑ°ᒡᒥᒦ•¶ᒧ®©™ᒨᒪᒫᒻᓂᓃᓄᓅᓇᓈᓐᓯᓰᓱᓲᓴᓵᔅᓕᓖᓗᓘᓚᓛᓪᔨᔩᔪᔫᔭ…\xA0ᔮᔾᕕᕖᕗ–—“”‘’ᕘᕙᕚᕝᕆᕇᕈᕉᕋᕌᕐᕿᖀᖁᖂᖃᖄᖅᖏᖐᖑᖒᖓᖔᖕᙱᙲᙳᙴᙵᙶᖖᖠᖡᖢᖣᖤᖥᖦᕼŁł`,"x-mac-ce":`ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅņѬ√ńŇ∆«»…\xA0ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ`,macintosh:`ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»…\xA0ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ`,"x-mac-romanian":`ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ĂȘ∞±≤≥¥µ∂∑∏π∫ªºΩăș¿¡¬√ƒ≈∆«»…\xA0ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›Țț‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ`,"x-mac-turkish":`ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»…\xA0ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ`};wP.MACSTRING=function(e,t,n,r){var i=EP[r];if(i!==void 0){for(var a=``,o=0;o<n;o++){var s=e.getUint8(t+o);s<=127?a+=String.fromCharCode(s):a+=i[s&127]}return a}};var DP=typeof WeakMap==`function`&&new WeakMap,OP,kP=function(e){if(!OP)for(var t in OP={},EP)OP[t]=new String(t);var n=OP[e];if(n!==void 0){if(DP){var r=DP.get(n);if(r!==void 0)return r}var i=EP[e];if(i!==void 0){for(var a={},o=0;o<i.length;o++)a[i.charCodeAt(o)]=o+128;return DP&&DP.set(n,a),a}}};q.MACSTRING=function(e,t){var n=kP(t);if(n!==void 0){for(var r=[],i=0;i<e.length;i++){var a=e.charCodeAt(i);if(a>=128&&(a=n[a],a===void 0))return;r[i]=a}return r}},J.MACSTRING=function(e,t){var n=q.MACSTRING(e,t);return n===void 0?0:n.length};function AP(e){return e>=-128&&e<=127}function jP(e,t,n){for(var r=0,i=e.length;t<i&&r<64&&e[t]===0;)++t,++r;return n.push(128|r-1),t}function MP(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(!AP(o)||o===0&&a+1<i&&e[a+1]===0)break;++a,++r}n.push(r-1);for(var s=t;s<a;++s)n.push(e[s]+256&255);return a}function NP(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(o===0||AP(o)&&a+1<i&&AP(e[a+1]))break;++a,++r}n.push(64|r-1);for(var s=t;s<a;++s){var c=e[s];n.push(c+65536>>8&255,c+256&255)}return a}q.VARDELTAS=function(e){for(var t=0,n=[];t<e.length;){var r=e[t];t=r===0?jP(e,t,n):r>=-128&&r<=127?MP(e,t,n):NP(e,t,n)}return n},q.INDEX=function(e){for(var t=1,n=[t],r=[],i=0;i<e.length;i+=1){var a=q.OBJECT(e[i]);Array.prototype.push.apply(r,a),t+=a.length,n.push(t)}if(r.length===0)return[0,0];for(var o=[],s=1+Math.floor(Math.log(t)/Math.log(2))/8|0,c=[void 0,q.BYTE,q.USHORT,q.UINT24,q.ULONG][s],l=0;l<n.length;l+=1){var u=c(n[l]);Array.prototype.push.apply(o,u)}return Array.prototype.concat(q.Card16(e.length),q.OffSize(s),o,r)},J.INDEX=function(e){return q.INDEX(e).length},q.DICT=function(e){for(var t=[],n=Object.keys(e),r=n.length,i=0;i<r;i+=1){var a=parseInt(n[i],0),o=e[a];t=t.concat(q.OPERAND(o.value,o.type)),t=t.concat(q.OPERATOR(a))}return t},J.DICT=function(e){return q.DICT(e).length},q.OPERATOR=function(e){return e<1200?[e]:[12,e-1200]},q.OPERAND=function(e,t){var n=[];if(Array.isArray(t))for(var r=0;r<t.length;r+=1)K.argument(e.length===t.length,`Not enough arguments given for type`+t),n=n.concat(q.OPERAND(e[r],t[r]));else if(t===`SID`)n=n.concat(q.NUMBER(e));else if(t===`offset`)n=n.concat(q.NUMBER32(e));else if(t===`number`)n=n.concat(q.NUMBER(e));else if(t===`real`)n=n.concat(q.REAL(e));else throw Error(`Unknown operand type `+t);return n},q.OP=q.BYTE,J.OP=J.BYTE;var PP=typeof WeakMap==`function`&&new WeakMap;q.CHARSTRING=function(e){if(PP){var t=PP.get(e);if(t!==void 0)return t}for(var n=[],r=e.length,i=0;i<r;i+=1){var a=e[i];n=n.concat(q[a.type](a.value))}return PP&&PP.set(e,n),n},J.CHARSTRING=function(e){return q.CHARSTRING(e).length},q.OBJECT=function(e){var t=q[e.type];return K.argument(t!==void 0,`No encoding function for type `+e.type),t(e.value)},J.OBJECT=function(e){var t=J[e.type];return K.argument(t!==void 0,`No sizeOf function for type `+e.type),t(e.value)},q.TABLE=function(e){for(var t=[],n=e.fields.length,r=[],i=[],a=0;a<n;a+=1){var o=e.fields[a],s=q[o.type];K.argument(s!==void 0,`No encoding function for field type `+o.type+` (`+o.name+`)`);var c=e[o.name];c===void 0&&(c=o.value);var l=s(c);o.type===`TABLE`?(i.push(t.length),t=t.concat([0,0]),r.push(l)):t=t.concat(l)}for(var u=0;u<r.length;u+=1){var d=i[u],f=t.length;K.argument(f<65536,`Table `+e.tableName+` too big.`),t[d]=f>>8,t[d+1]=f&255,t=t.concat(r[u])}return t},J.TABLE=function(e){for(var t=0,n=e.fields.length,r=0;r<n;r+=1){var i=e.fields[r],a=J[i.type];K.argument(a!==void 0,`No sizeOf function for field type `+i.type+` (`+i.name+`)`);var o=e[i.name];o===void 0&&(o=i.value),t+=a(o),i.type===`TABLE`&&(t+=2)}return t},q.RECORD=q.TABLE,J.RECORD=J.TABLE,q.LITERAL=function(e){return e},J.LITERAL=function(e){return e.length};function FP(e,t,n){if(t.length&&(t[0].name!==`coverageFormat`||t[0].value===1))for(var r=0;r<t.length;r+=1){var i=t[r];this[i.name]=i.value}if(this.tableName=e,this.fields=t,n)for(var a=Object.keys(n),o=0;o<a.length;o+=1){var s=a[o],c=n[s];this[s]!==void 0&&(this[s]=c)}}FP.prototype.encode=function(){return q.TABLE(this)},FP.prototype.sizeOf=function(){return J.TABLE(this)};function IP(e,t,n){n===void 0&&(n=t.length);var r=Array(t.length+1);r[0]={name:e+`Count`,type:`USHORT`,value:n};for(var i=0;i<t.length;i++)r[i+1]={name:e+i,type:`USHORT`,value:t[i]};return r}function LP(e,t,n){var r=t.length,i=Array(r+1);i[0]={name:e+`Count`,type:`USHORT`,value:r};for(var a=0;a<r;a++)i[a+1]={name:e+a,type:`TABLE`,value:n(t[a],a)};return i}function RP(e,t,n){var r=t.length,i=[];i[0]={name:e+`Count`,type:`USHORT`,value:r};for(var a=0;a<r;a++)i=i.concat(n(t[a],a));return i}function zP(e){e.format===1?FP.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:1}].concat(IP(`glyph`,e.glyphs))):e.format===2?FP.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:2}].concat(RP(`rangeRecord`,e.ranges,function(e){return[{name:`startGlyphID`,type:`USHORT`,value:e.start},{name:`endGlyphID`,type:`USHORT`,value:e.end},{name:`startCoverageIndex`,type:`USHORT`,value:e.index}]}))):K.assert(!1,`Coverage format must be 1 or 2.`)}zP.prototype=Object.create(FP.prototype),zP.prototype.constructor=zP;function BP(e){FP.call(this,`scriptListTable`,RP(`scriptRecord`,e,function(e,t){var n=e.script,r=n.defaultLangSys;return K.assert(!!r,`Unable to write GSUB: script `+e.tag+` has no default language system.`),[{name:`scriptTag`+t,type:`TAG`,value:e.tag},{name:`script`+t,type:`TABLE`,value:new FP(`scriptTable`,[{name:`defaultLangSys`,type:`TABLE`,value:new FP(`defaultLangSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:r.reqFeatureIndex}].concat(IP(`featureIndex`,r.featureIndexes)))}].concat(RP(`langSys`,n.langSysRecords,function(e,t){var n=e.langSys;return[{name:`langSysTag`+t,type:`TAG`,value:e.tag},{name:`langSys`+t,type:`TABLE`,value:new FP(`langSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:n.reqFeatureIndex}].concat(IP(`featureIndex`,n.featureIndexes)))}]})))}]}))}BP.prototype=Object.create(FP.prototype),BP.prototype.constructor=BP;function VP(e){FP.call(this,`featureListTable`,RP(`featureRecord`,e,function(e,t){var n=e.feature;return[{name:`featureTag`+t,type:`TAG`,value:e.tag},{name:`feature`+t,type:`TABLE`,value:new FP(`featureTable`,[{name:`featureParams`,type:`USHORT`,value:n.featureParams}].concat(IP(`lookupListIndex`,n.lookupListIndexes)))}]}))}VP.prototype=Object.create(FP.prototype),VP.prototype.constructor=VP;function HP(e,t){FP.call(this,`lookupListTable`,LP(`lookup`,e,function(e){var n=t[e.lookupType];return K.assert(!!n,`Unable to write GSUB lookup type `+e.lookupType+` tables.`),new FP(`lookupTable`,[{name:`lookupType`,type:`USHORT`,value:e.lookupType},{name:`lookupFlag`,type:`USHORT`,value:e.lookupFlag}].concat(LP(`subtable`,e.subtables,n)))}))}HP.prototype=Object.create(FP.prototype),HP.prototype.constructor=HP;var Y={Table:FP,Record:FP,Coverage:zP,ScriptList:BP,FeatureList:VP,LookupList:HP,ushortList:IP,tableList:LP,recordList:RP};function UP(e,t){return e.getUint8(t)}function WP(e,t){return e.getUint16(t,!1)}function GP(e,t){return e.getInt16(t,!1)}function KP(e,t){return e.getUint32(t,!1)}function qP(e,t){return e.getInt16(t,!1)+e.getUint16(t+2,!1)/65535}function JP(e,t){for(var n=``,r=t;r<t+4;r+=1)n+=String.fromCharCode(e.getInt8(r));return n}function YP(e,t,n){for(var r=0,i=0;i<n;i+=1)r<<=8,r+=e.getUint8(t+i);return r}function XP(e,t,n){for(var r=[],i=t;i<n;i+=1)r.push(e.getUint8(i));return r}function ZP(e){for(var t=``,n=0;n<e.length;n+=1)t+=String.fromCharCode(e[n]);return t}var QP={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function X(e,t){this.data=e,this.offset=t,this.relativeOffset=0}X.prototype.parseByte=function(){var e=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,e},X.prototype.parseChar=function(){var e=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,e},X.prototype.parseCard8=X.prototype.parseByte,X.prototype.parseUShort=function(){var e=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,e},X.prototype.parseCard16=X.prototype.parseUShort,X.prototype.parseSID=X.prototype.parseUShort,X.prototype.parseOffset16=X.prototype.parseUShort,X.prototype.parseShort=function(){var e=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,e},X.prototype.parseF2Dot14=function(){var e=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,e},X.prototype.parseULong=function(){var e=KP(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,e},X.prototype.parseOffset32=X.prototype.parseULong,X.prototype.parseFixed=function(){var e=qP(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,e},X.prototype.parseString=function(e){var t=this.data,n=this.offset+this.relativeOffset,r=``;this.relativeOffset+=e;for(var i=0;i<e;i++)r+=String.fromCharCode(t.getUint8(n+i));return r},X.prototype.parseTag=function(){return this.parseString(4)},X.prototype.parseLongDateTime=function(){var e=KP(this.data,this.offset+this.relativeOffset+4);return e-=2082844800,this.relativeOffset+=8,e},X.prototype.parseVersion=function(e){var t=WP(this.data,this.offset+this.relativeOffset),n=WP(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,e===void 0&&(e=4096),t+n/e/10},X.prototype.skip=function(e,t){t===void 0&&(t=1),this.relativeOffset+=QP[e]*t},X.prototype.parseULongList=function(e){e===void 0&&(e=this.parseULong());for(var t=Array(e),n=this.data,r=this.offset+this.relativeOffset,i=0;i<e;i++)t[i]=n.getUint32(r),r+=4;return this.relativeOffset+=e*4,t},X.prototype.parseOffset16List=X.prototype.parseUShortList=function(e){e===void 0&&(e=this.parseUShort());for(var t=Array(e),n=this.data,r=this.offset+this.relativeOffset,i=0;i<e;i++)t[i]=n.getUint16(r),r+=2;return this.relativeOffset+=e*2,t},X.prototype.parseShortList=function(e){for(var t=Array(e),n=this.data,r=this.offset+this.relativeOffset,i=0;i<e;i++)t[i]=n.getInt16(r),r+=2;return this.relativeOffset+=e*2,t},X.prototype.parseByteList=function(e){for(var t=Array(e),n=this.data,r=this.offset+this.relativeOffset,i=0;i<e;i++)t[i]=n.getUint8(r++);return this.relativeOffset+=e,t},X.prototype.parseList=function(e,t){t||(t=e,e=this.parseUShort());for(var n=Array(e),r=0;r<e;r++)n[r]=t.call(this);return n},X.prototype.parseList32=function(e,t){t||(t=e,e=this.parseULong());for(var n=Array(e),r=0;r<e;r++)n[r]=t.call(this);return n},X.prototype.parseRecordList=function(e,t){t||(t=e,e=this.parseUShort());for(var n=Array(e),r=Object.keys(t),i=0;i<e;i++){for(var a={},o=0;o<r.length;o++){var s=r[o];a[s]=t[s].call(this)}n[i]=a}return n},X.prototype.parseRecordList32=function(e,t){t||(t=e,e=this.parseULong());for(var n=Array(e),r=Object.keys(t),i=0;i<e;i++){for(var a={},o=0;o<r.length;o++){var s=r[o];a[s]=t[s].call(this)}n[i]=a}return n},X.prototype.parseStruct=function(e){if(typeof e==`function`)return e.call(this);for(var t=Object.keys(e),n={},r=0;r<t.length;r++){var i=t[r];n[i]=e[i].call(this)}return n},X.prototype.parseValueRecord=function(e){if(e===void 0&&(e=this.parseUShort()),e!==0){var t={};return e&1&&(t.xPlacement=this.parseShort()),e&2&&(t.yPlacement=this.parseShort()),e&4&&(t.xAdvance=this.parseShort()),e&8&&(t.yAdvance=this.parseShort()),e&16&&(t.xPlaDevice=void 0,this.parseShort()),e&32&&(t.yPlaDevice=void 0,this.parseShort()),e&64&&(t.xAdvDevice=void 0,this.parseShort()),e&128&&(t.yAdvDevice=void 0,this.parseShort()),t}},X.prototype.parseValueRecordList=function(){for(var e=this.parseUShort(),t=this.parseUShort(),n=Array(t),r=0;r<t;r++)n[r]=this.parseValueRecord(e);return n},X.prototype.parsePointer=function(e){var t=this.parseOffset16();if(t>0)return new X(this.data,this.offset+t).parseStruct(e)},X.prototype.parsePointer32=function(e){var t=this.parseOffset32();if(t>0)return new X(this.data,this.offset+t).parseStruct(e)},X.prototype.parseListOfLists=function(e){for(var t=this.parseOffset16List(),n=t.length,r=this.relativeOffset,i=Array(n),a=0;a<n;a++){var o=t[a];if(o===0){i[a]=void 0;continue}if(this.relativeOffset=o,e){for(var s=this.parseOffset16List(),c=Array(s.length),l=0;l<s.length;l++)this.relativeOffset=o+s[l],c[l]=e.call(this);i[a]=c}else i[a]=this.parseUShortList()}return this.relativeOffset=r,i},X.prototype.parseCoverage=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort(),n=this.parseUShort();if(t===1)return{format:1,glyphs:this.parseUShortList(n)};if(t===2){for(var r=Array(n),i=0;i<n;i++)r[i]={start:this.parseUShort(),end:this.parseUShort(),index:this.parseUShort()};return{format:2,ranges:r}}throw Error(`0x`+e.toString(16)+`: Coverage format must be 1 or 2.`)},X.prototype.parseClassDef=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{format:1,startGlyph:this.parseUShort(),classes:this.parseUShortList()};if(t===2)return{format:2,ranges:this.parseRecordList({start:X.uShort,end:X.uShort,classId:X.uShort})};throw Error(`0x`+e.toString(16)+`: ClassDef format must be 1 or 2.`)},X.list=function(e,t){return function(){return this.parseList(e,t)}},X.list32=function(e,t){return function(){return this.parseList32(e,t)}},X.recordList=function(e,t){return function(){return this.parseRecordList(e,t)}},X.recordList32=function(e,t){return function(){return this.parseRecordList32(e,t)}},X.pointer=function(e){return function(){return this.parsePointer(e)}},X.pointer32=function(e){return function(){return this.parsePointer32(e)}},X.tag=X.prototype.parseTag,X.byte=X.prototype.parseByte,X.uShort=X.offset16=X.prototype.parseUShort,X.uShortList=X.prototype.parseUShortList,X.uLong=X.offset32=X.prototype.parseULong,X.uLongList=X.prototype.parseULongList,X.struct=X.prototype.parseStruct,X.coverage=X.prototype.parseCoverage,X.classDef=X.prototype.parseClassDef;var $P={reserved:X.uShort,reqFeatureIndex:X.uShort,featureIndexes:X.uShortList};X.prototype.parseScriptList=function(){return this.parsePointer(X.recordList({tag:X.tag,script:X.pointer({defaultLangSys:X.pointer($P),langSysRecords:X.recordList({tag:X.tag,langSys:X.pointer($P)})})}))||[]},X.prototype.parseFeatureList=function(){return this.parsePointer(X.recordList({tag:X.tag,feature:X.pointer({featureParams:X.offset16,lookupListIndexes:X.uShortList})}))||[]},X.prototype.parseLookupList=function(e){return this.parsePointer(X.list(X.pointer(function(){var t=this.parseUShort();K.argument(1<=t&&t<=9,`GPOS/GSUB lookup type `+t+` unknown.`);var n=this.parseUShort(),r=n&16;return{lookupType:t,lookupFlag:n,subtables:this.parseList(X.pointer(e[t])),markFilteringSet:r?this.parseUShort():void 0}})))||[]},X.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var e=this.parseUShort(),t=this.parseUShort();return K.argument(e===1&&t<1,`GPOS/GSUB feature variations table unknown.`),this.parseRecordList32({conditionSetOffset:X.offset32,featureTableSubstitutionOffset:X.offset32})})||[]};var Z={getByte:UP,getCard8:UP,getUShort:WP,getCard16:WP,getShort:GP,getULong:KP,getFixed:qP,getTag:JP,getOffset:YP,getBytes:XP,bytesToString:ZP,Parser:X};function eF(e,t){t.parseUShort(),e.length=t.parseULong(),e.language=t.parseULong();var n;e.groupCount=n=t.parseULong(),e.glyphIndexMap={};for(var r=0;r<n;r+=1)for(var i=t.parseULong(),a=t.parseULong(),o=t.parseULong(),s=i;s<=a;s+=1)e.glyphIndexMap[s]=o,o++}function tF(e,t,n,r,i){e.length=t.parseUShort(),e.language=t.parseUShort();var a;e.segCount=a=t.parseUShort()>>1,t.skip(`uShort`,3),e.glyphIndexMap={};for(var o=new Z.Parser(n,r+i+14),s=new Z.Parser(n,r+i+16+a*2),c=new Z.Parser(n,r+i+16+a*4),l=new Z.Parser(n,r+i+16+a*6),u=r+i+16+a*8,d=0;d<a-1;d+=1)for(var f=void 0,p=o.parseUShort(),m=s.parseUShort(),h=c.parseShort(),g=l.parseUShort(),_=m;_<=p;_+=1)g===0?f=_+h&65535:(u=l.offset+l.relativeOffset-2,u+=g,u+=(_-m)*2,f=Z.getUShort(n,u),f!==0&&(f=f+h&65535)),e.glyphIndexMap[_]=f}function nF(e,t){var n={};n.version=Z.getUShort(e,t),K.argument(n.version===0,`cmap table version should be 0.`),n.numTables=Z.getUShort(e,t+2);for(var r=-1,i=n.numTables-1;i>=0;--i){var a=Z.getUShort(e,t+4+i*8),o=Z.getUShort(e,t+4+i*8+2);if(a===3&&(o===0||o===1||o===10)||a===0&&(o===0||o===1||o===2||o===3||o===4)){r=Z.getULong(e,t+4+i*8+4);break}}if(r===-1)throw Error(`No valid cmap sub-tables found.`);var s=new Z.Parser(e,t+r);if(n.format=s.parseUShort(),n.format===12)eF(n,s);else if(n.format===4)tF(n,s,e,t,r);else throw Error(`Only format 4 and 12 cmap tables are supported (found format `+n.format+`).`);return n}function rF(e,t,n){e.segments.push({end:t,start:t,delta:-(t-n),offset:0,glyphIndex:n})}function iF(e){e.segments.push({end:65535,start:65535,delta:1,offset:0})}function aF(e){var t=!0,n;for(n=e.length-1;n>0;--n)if(e.get(n).unicode>65535){console.log(`Adding CMAP format 12 (needed!)`),t=!1;break}var r=[{name:`version`,type:`USHORT`,value:0},{name:`numTables`,type:`USHORT`,value:t?1:2},{name:`platformID`,type:`USHORT`,value:3},{name:`encodingID`,type:`USHORT`,value:1},{name:`offset`,type:`ULONG`,value:t?12:20}];t||(r=r.concat([{name:`cmap12PlatformID`,type:`USHORT`,value:3},{name:`cmap12EncodingID`,type:`USHORT`,value:10},{name:`cmap12Offset`,type:`ULONG`,value:0}])),r=r.concat([{name:`format`,type:`USHORT`,value:4},{name:`cmap4Length`,type:`USHORT`,value:0},{name:`language`,type:`USHORT`,value:0},{name:`segCountX2`,type:`USHORT`,value:0},{name:`searchRange`,type:`USHORT`,value:0},{name:`entrySelector`,type:`USHORT`,value:0},{name:`rangeShift`,type:`USHORT`,value:0}]);var i=new Y.Table(`cmap`,r);for(i.segments=[],n=0;n<e.length;n+=1){for(var a=e.get(n),o=0;o<a.unicodes.length;o+=1)rF(i,a.unicodes[o],n);i.segments=i.segments.sort(function(e,t){return e.start-t.start})}iF(i);var s=i.segments.length,c=0,l=[],u=[],d=[],f=[],p=[],m=[];for(n=0;n<s;n+=1){var h=i.segments[n];h.end<=65535&&h.start<=65535?(l=l.concat({name:`end_`+n,type:`USHORT`,value:h.end}),u=u.concat({name:`start_`+n,type:`USHORT`,value:h.start}),d=d.concat({name:`idDelta_`+n,type:`SHORT`,value:h.delta}),f=f.concat({name:`idRangeOffset_`+n,type:`USHORT`,value:h.offset}),h.glyphId!==void 0&&(p=p.concat({name:`glyph_`+n,type:`USHORT`,value:h.glyphId}))):c+=1,!t&&h.glyphIndex!==void 0&&(m=m.concat({name:`cmap12Start_`+n,type:`ULONG`,value:h.start}),m=m.concat({name:`cmap12End_`+n,type:`ULONG`,value:h.end}),m=m.concat({name:`cmap12Glyph_`+n,type:`ULONG`,value:h.glyphIndex}))}if(i.segCountX2=(s-c)*2,i.searchRange=2**Math.floor(Math.log(s-c)/Math.log(2))*2,i.entrySelector=Math.log(i.searchRange/2)/Math.log(2),i.rangeShift=i.segCountX2-i.searchRange,i.fields=i.fields.concat(l),i.fields.push({name:`reservedPad`,type:`USHORT`,value:0}),i.fields=i.fields.concat(u),i.fields=i.fields.concat(d),i.fields=i.fields.concat(f),i.fields=i.fields.concat(p),i.cmap4Length=14+l.length*2+2+u.length*2+d.length*2+f.length*2+p.length*2,!t){var g=16+m.length*4;i.cmap12Offset=20+i.cmap4Length,i.fields=i.fields.concat([{name:`cmap12Format`,type:`USHORT`,value:12},{name:`cmap12Reserved`,type:`USHORT`,value:0},{name:`cmap12Length`,type:`ULONG`,value:g},{name:`cmap12Language`,type:`ULONG`,value:0},{name:`cmap12nGroups`,type:`ULONG`,value:m.length/3}]),i.fields=i.fields.concat(m)}return i}var oF={parse:nF,make:aF},sF=`.notdef,space,exclam,quotedbl,numbersign,dollar,percent,ampersand,quoteright,parenleft,parenright,asterisk,plus,comma,hyphen,period,slash,zero,one,two,three,four,five,six,seven,eight,nine,colon,semicolon,less,equal,greater,question,at,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,bracketleft,backslash,bracketright,asciicircum,underscore,quoteleft,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,braceleft,bar,braceright,asciitilde,exclamdown,cent,sterling,fraction,yen,florin,section,currency,quotesingle,quotedblleft,guillemotleft,guilsinglleft,guilsinglright,fi,fl,endash,dagger,daggerdbl,periodcentered,paragraph,bullet,quotesinglbase,quotedblbase,quotedblright,guillemotright,ellipsis,perthousand,questiondown,grave,acute,circumflex,tilde,macron,breve,dotaccent,dieresis,ring,cedilla,hungarumlaut,ogonek,caron,emdash,AE,ordfeminine,Lslash,Oslash,OE,ordmasculine,ae,dotlessi,lslash,oslash,oe,germandbls,onesuperior,logicalnot,mu,trademark,Eth,onehalf,plusminus,Thorn,onequarter,divide,brokenbar,degree,thorn,threequarters,twosuperior,registered,minus,eth,multiply,threesuperior,copyright,Aacute,Acircumflex,Adieresis,Agrave,Aring,Atilde,Ccedilla,Eacute,Ecircumflex,Edieresis,Egrave,Iacute,Icircumflex,Idieresis,Igrave,Ntilde,Oacute,Ocircumflex,Odieresis,Ograve,Otilde,Scaron,Uacute,Ucircumflex,Udieresis,Ugrave,Yacute,Ydieresis,Zcaron,aacute,acircumflex,adieresis,agrave,aring,atilde,ccedilla,eacute,ecircumflex,edieresis,egrave,iacute,icircumflex,idieresis,igrave,ntilde,oacute,ocircumflex,odieresis,ograve,otilde,scaron,uacute,ucircumflex,udieresis,ugrave,yacute,ydieresis,zcaron,exclamsmall,Hungarumlautsmall,dollaroldstyle,dollarsuperior,ampersandsmall,Acutesmall,parenleftsuperior,parenrightsuperior,266 ff,onedotenleader,zerooldstyle,oneoldstyle,twooldstyle,threeoldstyle,fouroldstyle,fiveoldstyle,sixoldstyle,sevenoldstyle,eightoldstyle,nineoldstyle,commasuperior,threequartersemdash,periodsuperior,questionsmall,asuperior,bsuperior,centsuperior,dsuperior,esuperior,isuperior,lsuperior,msuperior,nsuperior,osuperior,rsuperior,ssuperior,tsuperior,ff,ffi,ffl,parenleftinferior,parenrightinferior,Circumflexsmall,hyphensuperior,Gravesmall,Asmall,Bsmall,Csmall,Dsmall,Esmall,Fsmall,Gsmall,Hsmall,Ismall,Jsmall,Ksmall,Lsmall,Msmall,Nsmall,Osmall,Psmall,Qsmall,Rsmall,Ssmall,Tsmall,Usmall,Vsmall,Wsmall,Xsmall,Ysmall,Zsmall,colonmonetary,onefitted,rupiah,Tildesmall,exclamdownsmall,centoldstyle,Lslashsmall,Scaronsmall,Zcaronsmall,Dieresissmall,Brevesmall,Caronsmall,Dotaccentsmall,Macronsmall,figuredash,hypheninferior,Ogoneksmall,Ringsmall,Cedillasmall,questiondownsmall,oneeighth,threeeighths,fiveeighths,seveneighths,onethird,twothirds,zerosuperior,foursuperior,fivesuperior,sixsuperior,sevensuperior,eightsuperior,ninesuperior,zeroinferior,oneinferior,twoinferior,threeinferior,fourinferior,fiveinferior,sixinferior,seveninferior,eightinferior,nineinferior,centinferior,dollarinferior,periodinferior,commainferior,Agravesmall,Aacutesmall,Acircumflexsmall,Atildesmall,Adieresissmall,Aringsmall,AEsmall,Ccedillasmall,Egravesmall,Eacutesmall,Ecircumflexsmall,Edieresissmall,Igravesmall,Iacutesmall,Icircumflexsmall,Idieresissmall,Ethsmall,Ntildesmall,Ogravesmall,Oacutesmall,Ocircumflexsmall,Otildesmall,Odieresissmall,OEsmall,Oslashsmall,Ugravesmall,Uacutesmall,Ucircumflexsmall,Udieresissmall,Yacutesmall,Thornsmall,Ydieresissmall,001.000,001.001,001.002,001.003,Black,Bold,Book,Light,Medium,Regular,Roman,Semibold`.split(`,`),cF=`................................space.exclam.quotedbl.numbersign.dollar.percent.ampersand.quoteright.parenleft.parenright.asterisk.plus.comma.hyphen.period.slash.zero.one.two.three.four.five.six.seven.eight.nine.colon.semicolon.less.equal.greater.question.at.A.B.C.D.E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.Z.bracketleft.backslash.bracketright.asciicircum.underscore.quoteleft.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.braceleft.bar.braceright.asciitilde...................................exclamdown.cent.sterling.fraction.yen.florin.section.currency.quotesingle.quotedblleft.guillemotleft.guilsinglleft.guilsinglright.fi.fl..endash.dagger.daggerdbl.periodcentered..paragraph.bullet.quotesinglbase.quotedblbase.quotedblright.guillemotright.ellipsis.perthousand..questiondown..grave.acute.circumflex.tilde.macron.breve.dotaccent.dieresis..ring.cedilla..hungarumlaut.ogonek.caron.emdash.................AE..ordfeminine.....Lslash.Oslash.OE.ordmasculine......ae....dotlessi...lslash.oslash.oe.germandbls`.split(`.`),lF=`................................space.exclamsmall.Hungarumlautsmall..dollaroldstyle.dollarsuperior.ampersandsmall.Acutesmall.parenleftsuperior.parenrightsuperior.twodotenleader.onedotenleader.comma.hyphen.period.fraction.zerooldstyle.oneoldstyle.twooldstyle.threeoldstyle.fouroldstyle.fiveoldstyle.sixoldstyle.sevenoldstyle.eightoldstyle.nineoldstyle.colon.semicolon.commasuperior.threequartersemdash.periodsuperior.questionsmall..asuperior.bsuperior.centsuperior.dsuperior.esuperior...isuperior...lsuperior.msuperior.nsuperior.osuperior...rsuperior.ssuperior.tsuperior..ff.fi.fl.ffi.ffl.parenleftinferior..parenrightinferior.Circumflexsmall.hyphensuperior.Gravesmall.Asmall.Bsmall.Csmall.Dsmall.Esmall.Fsmall.Gsmall.Hsmall.Ismall.Jsmall.Ksmall.Lsmall.Msmall.Nsmall.Osmall.Psmall.Qsmall.Rsmall.Ssmall.Tsmall.Usmall.Vsmall.Wsmall.Xsmall.Ysmall.Zsmall.colonmonetary.onefitted.rupiah.Tildesmall...................................exclamdownsmall.centoldstyle.Lslashsmall...Scaronsmall.Zcaronsmall.Dieresissmall.Brevesmall.Caronsmall..Dotaccentsmall...Macronsmall...figuredash.hypheninferior...Ogoneksmall.Ringsmall.Cedillasmall....onequarter.onehalf.threequarters.questiondownsmall.oneeighth.threeeighths.fiveeighths.seveneighths.onethird.twothirds...zerosuperior.onesuperior.twosuperior.threesuperior.foursuperior.fivesuperior.sixsuperior.sevensuperior.eightsuperior.ninesuperior.zeroinferior.oneinferior.twoinferior.threeinferior.fourinferior.fiveinferior.sixinferior.seveninferior.eightinferior.nineinferior.centinferior.dollarinferior.periodinferior.commainferior.Agravesmall.Aacutesmall.Acircumflexsmall.Atildesmall.Adieresissmall.Aringsmall.AEsmall.Ccedillasmall.Egravesmall.Eacutesmall.Ecircumflexsmall.Edieresissmall.Igravesmall.Iacutesmall.Icircumflexsmall.Idieresissmall.Ethsmall.Ntildesmall.Ogravesmall.Oacutesmall.Ocircumflexsmall.Otildesmall.Odieresissmall.OEsmall.Oslashsmall.Ugravesmall.Uacutesmall.Ucircumflexsmall.Udieresissmall.Yacutesmall.Thornsmall.Ydieresissmall`.split(`.`),uF=`.notdef,.null,nonmarkingreturn,space,exclam,quotedbl,numbersign,dollar,percent,ampersand,quotesingle,parenleft,parenright,asterisk,plus,comma,hyphen,period,slash,zero,one,two,three,four,five,six,seven,eight,nine,colon,semicolon,less,equal,greater,question,at,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,bracketleft,backslash,bracketright,asciicircum,underscore,grave,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,braceleft,bar,braceright,asciitilde,Adieresis,Aring,Ccedilla,Eacute,Ntilde,Odieresis,Udieresis,aacute,agrave,acircumflex,adieresis,atilde,aring,ccedilla,eacute,egrave,ecircumflex,edieresis,iacute,igrave,icircumflex,idieresis,ntilde,oacute,ograve,ocircumflex,odieresis,otilde,uacute,ugrave,ucircumflex,udieresis,dagger,degree,cent,sterling,section,bullet,paragraph,germandbls,registered,copyright,trademark,acute,dieresis,notequal,AE,Oslash,infinity,plusminus,lessequal,greaterequal,yen,mu,partialdiff,summation,product,pi,integral,ordfeminine,ordmasculine,Omega,ae,oslash,questiondown,exclamdown,logicalnot,radical,florin,approxequal,Delta,guillemotleft,guillemotright,ellipsis,nonbreakingspace,Agrave,Atilde,Otilde,OE,oe,endash,emdash,quotedblleft,quotedblright,quoteleft,quoteright,divide,lozenge,ydieresis,Ydieresis,fraction,currency,guilsinglleft,guilsinglright,fi,fl,daggerdbl,periodcentered,quotesinglbase,quotedblbase,perthousand,Acircumflex,Ecircumflex,Aacute,Edieresis,Egrave,Iacute,Icircumflex,Idieresis,Igrave,Oacute,Ocircumflex,apple,Ograve,Uacute,Ucircumflex,Ugrave,dotlessi,circumflex,tilde,macron,breve,dotaccent,ring,cedilla,hungarumlaut,ogonek,caron,Lslash,lslash,Scaron,scaron,Zcaron,zcaron,brokenbar,Eth,eth,Yacute,yacute,Thorn,thorn,minus,multiply,onesuperior,twosuperior,threesuperior,onehalf,onequarter,threequarters,franc,Gbreve,gbreve,Idotaccent,Scedilla,scedilla,Cacute,cacute,Ccaron,ccaron,dcroat`.split(`,`);function dF(e){this.font=e}dF.prototype.charToGlyphIndex=function(e){var t=e.codePointAt(0),n=this.font.glyphs;if(n){for(var r=0;r<n.length;r+=1)for(var i=n.get(r),a=0;a<i.unicodes.length;a+=1)if(i.unicodes[a]===t)return r}return null};function fF(e){this.cmap=e}fF.prototype.charToGlyphIndex=function(e){return this.cmap.glyphIndexMap[e.codePointAt(0)]||0};function pF(e,t){this.encoding=e,this.charset=t}pF.prototype.charToGlyphIndex=function(e){var t=e.codePointAt(0),n=this.encoding[t];return this.charset.indexOf(n)};function mF(e){switch(e.version){case 1:this.names=uF.slice();break;case 2:this.names=Array(e.numberOfGlyphs);for(var t=0;t<e.numberOfGlyphs;t++)e.glyphNameIndex[t]<uF.length?this.names[t]=uF[e.glyphNameIndex[t]]:this.names[t]=e.names[e.glyphNameIndex[t]-uF.length];break;case 2.5:this.names=Array(e.numberOfGlyphs);for(var n=0;n<e.numberOfGlyphs;n++)this.names[n]=uF[n+e.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}mF.prototype.nameToGlyphIndex=function(e){return this.names.indexOf(e)},mF.prototype.glyphIndexToName=function(e){return this.names[e]};function hF(e){for(var t,n=e.tables.cmap.glyphIndexMap,r=Object.keys(n),i=0;i<r.length;i+=1){var a=r[i],o=n[a];t=e.glyphs.get(o),t.addUnicode(parseInt(a))}for(var s=0;s<e.glyphs.length;s+=1)t=e.glyphs.get(s),e.cffEncoding?e.isCIDFont?t.name=`gid`+s:t.name=e.cffEncoding.charset[s]:e.glyphNames.names&&(t.name=e.glyphNames.glyphIndexToName(s))}function gF(e){e._IndexToUnicodeMap={};for(var t=e.tables.cmap.glyphIndexMap,n=Object.keys(t),r=0;r<n.length;r+=1){var i=n[r],a=t[i];e._IndexToUnicodeMap[a]===void 0?e._IndexToUnicodeMap[a]={unicodes:[parseInt(i)]}:e._IndexToUnicodeMap[a].unicodes.push(parseInt(i))}}function _F(e,t){t.lowMemory?gF(e):hF(e)}function vF(e,t,n,r,i){e.beginPath(),e.moveTo(t,n),e.lineTo(r,i),e.stroke()}var yF={line:vF};function bF(e,t){var n=t||new yP;return{configurable:!0,get:function(){return typeof n==`function`&&(n=n()),n},set:function(e){n=e}}}function xF(e){this.bindConstructorValues(e)}xF.prototype.bindConstructorValues=function(e){this.index=e.index||0,this.name=e.name||null,this.unicode=e.unicode||void 0,this.unicodes=e.unicodes||e.unicode!==void 0?[e.unicode]:[],`xMin`in e&&(this.xMin=e.xMin),`yMin`in e&&(this.yMin=e.yMin),`xMax`in e&&(this.xMax=e.xMax),`yMax`in e&&(this.yMax=e.yMax),`advanceWidth`in e&&(this.advanceWidth=e.advanceWidth),Object.defineProperty(this,"path",bF(this,e.path))},xF.prototype.addUnicode=function(e){this.unicodes.length===0&&(this.unicode=e),this.unicodes.push(e)},xF.prototype.getBoundingBox=function(){return this.path.getBoundingBox()},xF.prototype.getPath=function(e,t,n,r,i){e=e===void 0?0:e,t=t===void 0?0:t,n=n===void 0?72:n;var a,o;r||={};var s=r.xScale,c=r.yScale;if(r.hinting&&i&&i.hinting&&(o=this.path&&i.hinting.exec(this,n)),o)a=i.hinting.getCommands(o),e=Math.round(e),t=Math.round(t),s=c=1;else{a=this.path.commands;var l=1/(this.path.unitsPerEm||1e3)*n;s===void 0&&(s=l),c===void 0&&(c=l)}for(var u=new yP,d=0;d<a.length;d+=1){var f=a[d];f.type===`M`?u.moveTo(e+f.x*s,t+-f.y*c):f.type===`L`?u.lineTo(e+f.x*s,t+-f.y*c):f.type===`Q`?u.quadraticCurveTo(e+f.x1*s,t+-f.y1*c,e+f.x*s,t+-f.y*c):f.type===`C`?u.curveTo(e+f.x1*s,t+-f.y1*c,e+f.x2*s,t+-f.y2*c,e+f.x*s,t+-f.y*c):f.type===`Z`&&u.closePath()}return u},xF.prototype.getContours=function(){if(this.points===void 0)return[];for(var e=[],t=[],n=0;n<this.points.length;n+=1){var r=this.points[n];t.push(r),r.lastPointOfContour&&(e.push(t),t=[])}return K.argument(t.length===0,`There are still points left in the current contour.`),e},xF.prototype.getMetrics=function(){for(var e=this.path.commands,t=[],n=[],r=0;r<e.length;r+=1){var i=e[r];i.type!==`Z`&&(t.push(i.x),n.push(i.y)),(i.type===`Q`||i.type===`C`)&&(t.push(i.x1),n.push(i.y1)),i.type===`C`&&(t.push(i.x2),n.push(i.y2))}var a={xMin:Math.min.apply(null,t),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,t),yMax:Math.max.apply(null,n),leftSideBearing:this.leftSideBearing};return isFinite(a.xMin)||(a.xMin=0),isFinite(a.xMax)||(a.xMax=this.advanceWidth),isFinite(a.yMin)||(a.yMin=0),isFinite(a.yMax)||(a.yMax=0),a.rightSideBearing=this.advanceWidth-a.leftSideBearing-(a.xMax-a.xMin),a},xF.prototype.draw=function(e,t,n,r,i){this.getPath(t,n,r,i).draw(e)},xF.prototype.drawPoints=function(e,t,n,r){function i(t,n,r,i){e.beginPath();for(var a=0;a<t.length;a+=1)e.moveTo(n+t[a].x*i,r+t[a].y*i),e.arc(n+t[a].x*i,r+t[a].y*i,2,0,Math.PI*2,!1);e.closePath(),e.fill()}t=t===void 0?0:t,n=n===void 0?0:n,r=r===void 0?24:r;for(var a=1/this.path.unitsPerEm*r,o=[],s=[],c=this.path,l=0;l<c.commands.length;l+=1){var u=c.commands[l];u.x!==void 0&&o.push({x:u.x,y:-u.y}),u.x1!==void 0&&s.push({x:u.x1,y:-u.y1}),u.x2!==void 0&&s.push({x:u.x2,y:-u.y2})}e.fillStyle=`blue`,i(o,t,n,a),e.fillStyle=`red`,i(s,t,n,a)},xF.prototype.drawMetrics=function(e,t,n,r){var i;t=t===void 0?0:t,n=n===void 0?0:n,r=r===void 0?24:r,i=1/this.path.unitsPerEm*r,e.lineWidth=1,e.strokeStyle=`black`,yF.line(e,t,-1e4,t,1e4),yF.line(e,-1e4,n,1e4,n);var a=this.xMin||0,o=this.yMin||0,s=this.xMax||0,c=this.yMax||0,l=this.advanceWidth||0;e.strokeStyle=`blue`,yF.line(e,t+a*i,-1e4,t+a*i,1e4),yF.line(e,t+s*i,-1e4,t+s*i,1e4),yF.line(e,-1e4,n+-o*i,1e4,n+-o*i),yF.line(e,-1e4,n+-c*i,1e4,n+-c*i),e.strokeStyle=`green`,yF.line(e,t+l*i,-1e4,t+l*i,1e4)};function SF(e,t,n){Object.defineProperty(e,t,{get:function(){return e.path,e[n]},set:function(t){e[n]=t},enumerable:!0,configurable:!0})}function CF(e,t){if(this.font=e,this.glyphs={},Array.isArray(t))for(var n=0;n<t.length;n++){var r=t[n];r.path.unitsPerEm=e.unitsPerEm,this.glyphs[n]=r}this.length=t&&t.length||0}CF.prototype.get=function(e){if(this.glyphs[e]===void 0){this.font._push(e),typeof this.glyphs[e]==`function`&&(this.glyphs[e]=this.glyphs[e]());var t=this.glyphs[e],n=this.font._IndexToUnicodeMap[e];if(n)for(var r=0;r<n.unicodes.length;r++)t.addUnicode(n.unicodes[r]);this.font.cffEncoding?this.font.isCIDFont?t.name=`gid`+e:t.name=this.font.cffEncoding.charset[e]:this.font.glyphNames.names&&(t.name=this.font.glyphNames.glyphIndexToName(e)),this.glyphs[e].advanceWidth=this.font._hmtxTableData[e].advanceWidth,this.glyphs[e].leftSideBearing=this.font._hmtxTableData[e].leftSideBearing}else typeof this.glyphs[e]==`function`&&(this.glyphs[e]=this.glyphs[e]());return this.glyphs[e]},CF.prototype.push=function(e,t){this.glyphs[e]=t,this.length++};function wF(e,t){return new xF({index:t,font:e})}function TF(e,t,n,r,i,a){return function(){var o=new xF({index:t,font:e});return o.path=function(){n(o,r,i);var t=a(e.glyphs,o);return t.unitsPerEm=e.unitsPerEm,t},SF(o,`xMin`,`_xMin`),SF(o,`xMax`,`_xMax`),SF(o,`yMin`,`_yMin`),SF(o,`yMax`,`_yMax`),o}}function EF(e,t,n,r){return function(){var i=new xF({index:t,font:e});return i.path=function(){var t=n(e,i,r);return t.unitsPerEm=e.unitsPerEm,t},i}}var DF={GlyphSet:CF,glyphLoader:wF,ttfGlyphLoader:TF,cffGlyphLoader:EF};function OF(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(var n=0;n<e.length;n+=1)if(!OF(e[n],t[n]))return!1;return!0}else return!1}function kF(e){return e.length<1240?107:e.length<33900?1131:32768}function AF(e,t,n){var r=[],i=[],a=Z.getCard16(e,t),o,s;if(a!==0){var c=Z.getByte(e,t+2);o=t+(a+1)*c+2;for(var l=t+3,u=0;u<a+1;u+=1)r.push(Z.getOffset(e,l,c)),l+=c;s=o+r[a]}else s=t+2;for(var d=0;d<r.length-1;d+=1){var f=Z.getBytes(e,o+r[d],o+r[d+1]);n&&(f=n(f)),i.push(f)}return{objects:i,startOffset:t,endOffset:s}}function jF(e,t){var n=[],r=Z.getCard16(e,t),i,a;if(r!==0){var o=Z.getByte(e,t+2);i=t+(r+1)*o+2;for(var s=t+3,c=0;c<r+1;c+=1)n.push(Z.getOffset(e,s,o)),s+=o;a=i+n[r]}else a=t+2;return{offsets:n,startOffset:t,endOffset:a}}function MF(e,t,n,r,i){var a=Z.getCard16(n,r),o=0;if(a!==0){var s=Z.getByte(n,r+2);o=r+(a+1)*s+2}var c=Z.getBytes(n,o+t[e],o+t[e+1]);return i&&(c=i(c)),c}function NF(e){for(var t=``,n=15,r=[`0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`.`,`E`,`E-`,null,`-`];;){var i=e.parseByte(),a=i>>4,o=i&15;if(a===n||(t+=r[a],o===n))break;t+=r[o]}return parseFloat(t)}function PF(e,t){var n,r,i,a;if(t===28)return n=e.parseByte(),r=e.parseByte(),n<<8|r;if(t===29)return n=e.parseByte(),r=e.parseByte(),i=e.parseByte(),a=e.parseByte(),n<<24|r<<16|i<<8|a;if(t===30)return NF(e);if(t>=32&&t<=246)return t-139;if(t>=247&&t<=250)return n=e.parseByte(),(t-247)*256+n+108;if(t>=251&&t<=254)return n=e.parseByte(),-(t-251)*256-n-108;throw Error(`Invalid b0 `+t)}function FF(e){for(var t={},n=0;n<e.length;n+=1){var r=e[n][0],i=e[n][1],a=void 0;if(a=i.length===1?i[0]:i,t.hasOwnProperty(r)&&!isNaN(t[r]))throw Error(`Object `+t+` already has key `+r);t[r]=a}return t}function IF(e,t,n){t=t===void 0?0:t;var r=new Z.Parser(e,t),i=[],a=[];for(n=n===void 0?e.length:n;r.relativeOffset<n;){var o=r.parseByte();o<=21?(o===12&&(o=1200+r.parseByte()),i.push([o,a]),a=[]):a.push(PF(r,o))}return FF(i)}function LF(e,t){return t=t<=390?sF[t]:e[t-391],t}function RF(e,t,n){for(var r={},i,a=0;a<t.length;a+=1){var o=t[a];if(Array.isArray(o.type)){var s=[];s.length=o.type.length;for(var c=0;c<o.type.length;c++)i=e[o.op]===void 0?void 0:e[o.op][c],i===void 0&&(i=o.value!==void 0&&o.value[c]!==void 0?o.value[c]:null),o.type[c]===`SID`&&(i=LF(n,i)),s[c]=i;r[o.name]=s}else i=e[o.op],i===void 0&&(i=o.value===void 0?null:o.value),o.type===`SID`&&(i=LF(n,i)),r[o.name]=i}return r}function zF(e,t){var n={};return n.formatMajor=Z.getCard8(e,t),n.formatMinor=Z.getCard8(e,t+1),n.size=Z.getCard8(e,t+2),n.offsetSize=Z.getCard8(e,t+3),n.startOffset=t,n.endOffset=t+4,n}var BF=[{name:`version`,op:0,type:`SID`},{name:`notice`,op:1,type:`SID`},{name:`copyright`,op:1200,type:`SID`},{name:`fullName`,op:2,type:`SID`},{name:`familyName`,op:3,type:`SID`},{name:`weight`,op:4,type:`SID`},{name:`isFixedPitch`,op:1201,type:`number`,value:0},{name:`italicAngle`,op:1202,type:`number`,value:0},{name:`underlinePosition`,op:1203,type:`number`,value:-100},{name:`underlineThickness`,op:1204,type:`number`,value:50},{name:`paintType`,op:1205,type:`number`,value:0},{name:`charstringType`,op:1206,type:`number`,value:2},{name:`fontMatrix`,op:1207,type:[`real`,`real`,`real`,`real`,`real`,`real`],value:[.001,0,0,.001,0,0]},{name:`uniqueId`,op:13,type:`number`},{name:`fontBBox`,op:5,type:[`number`,`number`,`number`,`number`],value:[0,0,0,0]},{name:`strokeWidth`,op:1208,type:`number`,value:0},{name:`xuid`,op:14,type:[],value:null},{name:`charset`,op:15,type:`offset`,value:0},{name:`encoding`,op:16,type:`offset`,value:0},{name:`charStrings`,op:17,type:`offset`,value:0},{name:`private`,op:18,type:[`number`,`offset`],value:[0,0]},{name:`ros`,op:1230,type:[`SID`,`SID`,`number`]},{name:`cidFontVersion`,op:1231,type:`number`,value:0},{name:`cidFontRevision`,op:1232,type:`number`,value:0},{name:`cidFontType`,op:1233,type:`number`,value:0},{name:`cidCount`,op:1234,type:`number`,value:8720},{name:`uidBase`,op:1235,type:`number`},{name:`fdArray`,op:1236,type:`offset`},{name:`fdSelect`,op:1237,type:`offset`},{name:`fontName`,op:1238,type:`SID`}],VF=[{name:`subrs`,op:19,type:`offset`,value:0},{name:`defaultWidthX`,op:20,type:`number`,value:0},{name:`nominalWidthX`,op:21,type:`number`,value:0}];function HF(e,t){return RF(IF(e,0,e.byteLength),BF,t)}function UF(e,t,n,r){return RF(IF(e,t,n),VF,r)}function WF(e,t,n,r){for(var i=[],a=0;a<n.length;a+=1){var o=HF(new DataView(new Uint8Array(n[a]).buffer),r);o._subrs=[],o._subrsBias=0,o._defaultWidthX=0,o._nominalWidthX=0;var s=o.private[0],c=o.private[1];if(s!==0&&c!==0){var l=UF(e,c+t,s,r);o._defaultWidthX=l.defaultWidthX,o._nominalWidthX=l.nominalWidthX,l.subrs!==0&&(o._subrs=AF(e,c+l.subrs+t).objects,o._subrsBias=kF(o._subrs)),o._privateDict=l}i.push(o)}return i}function GF(e,t,n,r){var i,a,o=new Z.Parser(e,t);--n;var s=[`.notdef`],c=o.parseCard8();if(c===0)for(var l=0;l<n;l+=1)i=o.parseSID(),s.push(LF(r,i));else if(c===1)for(;s.length<=n;){i=o.parseSID(),a=o.parseCard8();for(var u=0;u<=a;u+=1)s.push(LF(r,i)),i+=1}else if(c===2)for(;s.length<=n;){i=o.parseSID(),a=o.parseCard16();for(var d=0;d<=a;d+=1)s.push(LF(r,i)),i+=1}else throw Error(`Unknown charset format `+c);return s}function KF(e,t,n){var r,i={},a=new Z.Parser(e,t),o=a.parseCard8();if(o===0)for(var s=a.parseCard8(),c=0;c<s;c+=1)r=a.parseCard8(),i[r]=c;else if(o===1){var l=a.parseCard8();r=1;for(var u=0;u<l;u+=1)for(var d=a.parseCard8(),f=a.parseCard8(),p=d;p<=d+f;p+=1)i[p]=r,r+=1}else throw Error(`Unknown encoding format `+o);return new pF(i,n)}function qF(e,t,n){var r,i,a,o,s=new yP,c=[],l=0,u=!1,d=!1,f=0,p=0,m,h,g,_;if(e.isCIDFont){var v=e.tables.cff.topDict._fdSelect[t.index],y=e.tables.cff.topDict._fdArray[v];m=y._subrs,h=y._subrsBias,g=y._defaultWidthX,_=y._nominalWidthX}else m=e.tables.cff.topDict._subrs,h=e.tables.cff.topDict._subrsBias,g=e.tables.cff.topDict._defaultWidthX,_=e.tables.cff.topDict._nominalWidthX;var b=g;function x(e,t){d&&s.closePath(),s.moveTo(e,t),d=!0}function S(){c.length%2!=0&&!u&&(b=c.shift()+_),l+=c.length>>1,c.length=0,u=!0}function C(n){for(var g,v,y,w,ee,te,ne,re,ie,ae,oe,se,ce=0;ce<n.length;){var le=n[ce];switch(ce+=1,le){case 1:S();break;case 3:S();break;case 4:c.length>1&&!u&&(b=c.shift()+_,u=!0),p+=c.pop(),x(f,p);break;case 5:for(;c.length>0;)f+=c.shift(),p+=c.shift(),s.lineTo(f,p);break;case 6:for(;c.length>0&&(f+=c.shift(),s.lineTo(f,p),c.length!==0);)p+=c.shift(),s.lineTo(f,p);break;case 7:for(;c.length>0&&(p+=c.shift(),s.lineTo(f,p),c.length!==0);)f+=c.shift(),s.lineTo(f,p);break;case 8:for(;c.length>0;)r=f+c.shift(),i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),f=a+c.shift(),p=o+c.shift(),s.curveTo(r,i,a,o,f,p);break;case 10:ee=c.pop()+h,te=m[ee],te&&C(te);break;case 11:return;case 12:switch(le=n[ce],ce+=1,le){case 35:r=f+c.shift(),i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),ne=a+c.shift(),re=o+c.shift(),ie=ne+c.shift(),ae=re+c.shift(),oe=ie+c.shift(),se=ae+c.shift(),f=oe+c.shift(),p=se+c.shift(),c.shift(),s.curveTo(r,i,a,o,ne,re),s.curveTo(ie,ae,oe,se,f,p);break;case 34:r=f+c.shift(),i=p,a=r+c.shift(),o=i+c.shift(),ne=a+c.shift(),re=o,ie=ne+c.shift(),ae=o,oe=ie+c.shift(),se=p,f=oe+c.shift(),s.curveTo(r,i,a,o,ne,re),s.curveTo(ie,ae,oe,se,f,p);break;case 36:r=f+c.shift(),i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),ne=a+c.shift(),re=o,ie=ne+c.shift(),ae=o,oe=ie+c.shift(),se=ae+c.shift(),f=oe+c.shift(),s.curveTo(r,i,a,o,ne,re),s.curveTo(ie,ae,oe,se,f,p);break;case 37:r=f+c.shift(),i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),ne=a+c.shift(),re=o+c.shift(),ie=ne+c.shift(),ae=re+c.shift(),oe=ie+c.shift(),se=ae+c.shift(),Math.abs(oe-f)>Math.abs(se-p)?f=oe+c.shift():p=se+c.shift(),s.curveTo(r,i,a,o,ne,re),s.curveTo(ie,ae,oe,se,f,p);break;default:console.log(`Glyph `+t.index+`: unknown operator 1200`+le),c.length=0}break;case 14:c.length>0&&!u&&(b=c.shift()+_,u=!0),d&&=(s.closePath(),!1);break;case 18:S();break;case 19:case 20:S(),ce+=l+7>>3;break;case 21:c.length>2&&!u&&(b=c.shift()+_,u=!0),p+=c.pop(),f+=c.pop(),x(f,p);break;case 22:c.length>1&&!u&&(b=c.shift()+_,u=!0),f+=c.pop(),x(f,p);break;case 23:S();break;case 24:for(;c.length>2;)r=f+c.shift(),i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),f=a+c.shift(),p=o+c.shift(),s.curveTo(r,i,a,o,f,p);f+=c.shift(),p+=c.shift(),s.lineTo(f,p);break;case 25:for(;c.length>6;)f+=c.shift(),p+=c.shift(),s.lineTo(f,p);r=f+c.shift(),i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),f=a+c.shift(),p=o+c.shift(),s.curveTo(r,i,a,o,f,p);break;case 26:for(c.length%2&&(f+=c.shift());c.length>0;)r=f,i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),f=a,p=o+c.shift(),s.curveTo(r,i,a,o,f,p);break;case 27:for(c.length%2&&(p+=c.shift());c.length>0;)r=f+c.shift(),i=p,a=r+c.shift(),o=i+c.shift(),f=a+c.shift(),p=o,s.curveTo(r,i,a,o,f,p);break;case 28:g=n[ce],v=n[ce+1],c.push((g<<24|v<<16)>>16),ce+=2;break;case 29:ee=c.pop()+e.gsubrsBias,te=e.gsubrs[ee],te&&C(te);break;case 30:for(;c.length>0&&(r=f,i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),f=a+c.shift(),p=o+(c.length===1?c.shift():0),s.curveTo(r,i,a,o,f,p),c.length!==0);)r=f+c.shift(),i=p,a=r+c.shift(),o=i+c.shift(),p=o+c.shift(),f=a+(c.length===1?c.shift():0),s.curveTo(r,i,a,o,f,p);break;case 31:for(;c.length>0&&(r=f+c.shift(),i=p,a=r+c.shift(),o=i+c.shift(),p=o+c.shift(),f=a+(c.length===1?c.shift():0),s.curveTo(r,i,a,o,f,p),c.length!==0);)r=f,i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),f=a+c.shift(),p=o+(c.length===1?c.shift():0),s.curveTo(r,i,a,o,f,p);break;default:le<32?console.log(`Glyph `+t.index+`: unknown operator `+le):le<247?c.push(le-139):le<251?(g=n[ce],ce+=1,c.push((le-247)*256+g+108)):le<255?(g=n[ce],ce+=1,c.push(-(le-251)*256-g-108)):(g=n[ce],v=n[ce+1],y=n[ce+2],w=n[ce+3],ce+=4,c.push((g<<24|v<<16|y<<8|w)/65536))}}}return C(n),t.advanceWidth=b,s}function JF(e,t,n,r){var i=[],a,o=new Z.Parser(e,t),s=o.parseCard8();if(s===0)for(var c=0;c<n;c++){if(a=o.parseCard8(),a>=r)throw Error(`CFF table CID Font FDSelect has bad FD index value `+a+` (FD count `+r+`)`);i.push(a)}else if(s===3){var l=o.parseCard16(),u=o.parseCard16();if(u!==0)throw Error(`CFF Table CID Font FDSelect format 3 range has bad initial GID `+u);for(var d,f=0;f<l;f++){if(a=o.parseCard8(),d=o.parseCard16(),a>=r)throw Error(`CFF table CID Font FDSelect has bad FD index value `+a+` (FD count `+r+`)`);if(d>n)throw Error(`CFF Table CID Font FDSelect format 3 range has bad GID `+d);for(;u<d;u++)i.push(a);u=d}if(d!==n)throw Error(`CFF Table CID Font FDSelect format 3 range has bad final GID `+d)}else throw Error(`CFF Table CID Font FDSelect table has unsupported format `+s);return i}function YF(e,t,n,r){n.tables.cff={};var i=AF(e,AF(e,zF(e,t).endOffset,Z.bytesToString).endOffset),a=AF(e,i.endOffset,Z.bytesToString);n.gsubrs=AF(e,a.endOffset).objects,n.gsubrsBias=kF(n.gsubrs);var o=WF(e,t,i.objects,a.objects);if(o.length!==1)throw Error(`CFF table has too many fonts in 'FontSet' - count of fonts NameIndex.length = `+o.length);var s=o[0];if(n.tables.cff.topDict=s,s._privateDict&&(n.defaultWidthX=s._privateDict.defaultWidthX,n.nominalWidthX=s._privateDict.nominalWidthX),s.ros[0]!==void 0&&s.ros[1]!==void 0&&(n.isCIDFont=!0),n.isCIDFont){var c=s.fdArray,l=s.fdSelect;if(c===0||l===0)throw Error(`Font is marked as a CID font, but FDArray and/or FDSelect information is missing`);c+=t;var u=WF(e,t,AF(e,c).objects,a.objects);s._fdArray=u,l+=t,s._fdSelect=JF(e,l,n.numGlyphs,u.length)}var d=t+s.private[1],f=UF(e,d,s.private[0],a.objects);n.defaultWidthX=f.defaultWidthX,n.nominalWidthX=f.nominalWidthX,f.subrs===0?(n.subrs=[],n.subrsBias=0):(n.subrs=AF(e,d+f.subrs).objects,n.subrsBias=kF(n.subrs));var p;r.lowMemory?(p=jF(e,t+s.charStrings),n.nGlyphs=p.offsets.length):(p=AF(e,t+s.charStrings),n.nGlyphs=p.objects.length);var m=GF(e,t+s.charset,n.nGlyphs,a.objects);if(s.encoding===0?n.cffEncoding=new pF(cF,m):s.encoding===1?n.cffEncoding=new pF(lF,m):n.cffEncoding=KF(e,t+s.encoding,m),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new DF.GlyphSet(n),r.lowMemory)n._push=function(r){var i=MF(r,p.offsets,e,t+s.charStrings);n.glyphs.push(r,DF.cffGlyphLoader(n,r,qF,i))};else for(var h=0;h<n.nGlyphs;h+=1){var g=p.objects[h];n.glyphs.push(h,DF.cffGlyphLoader(n,h,qF,g))}}function XF(e,t){var n,r=sF.indexOf(e);return r>=0&&(n=r),r=t.indexOf(e),r>=0?n=r+sF.length:(n=sF.length+t.length,t.push(e)),n}function ZF(){return new Y.Record(`Header`,[{name:`major`,type:`Card8`,value:1},{name:`minor`,type:`Card8`,value:0},{name:`hdrSize`,type:`Card8`,value:4},{name:`major`,type:`Card8`,value:1}])}function QF(e){var t=new Y.Record(`Name INDEX`,[{name:`names`,type:`INDEX`,value:[]}]);t.names=[];for(var n=0;n<e.length;n+=1)t.names.push({name:`name_`+n,type:`NAME`,value:e[n]});return t}function $F(e,t,n){for(var r={},i=0;i<e.length;i+=1){var a=e[i],o=t[a.name];o!==void 0&&!OF(o,a.value)&&(a.type===`SID`&&(o=XF(o,n)),r[a.op]={name:a.name,type:a.type,value:o})}return r}function eI(e,t){var n=new Y.Record(`Top DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=$F(BF,e,t),n}function tI(e){var t=new Y.Record(`Top DICT INDEX`,[{name:`topDicts`,type:`INDEX`,value:[]}]);return t.topDicts=[{name:`topDict_0`,type:`TABLE`,value:e}],t}function nI(e){var t=new Y.Record(`String INDEX`,[{name:`strings`,type:`INDEX`,value:[]}]);t.strings=[];for(var n=0;n<e.length;n+=1)t.strings.push({name:`string_`+n,type:`STRING`,value:e[n]});return t}function rI(){return new Y.Record(`Global Subr INDEX`,[{name:`subrs`,type:`INDEX`,value:[]}])}function iI(e,t){for(var n=new Y.Record(`Charsets`,[{name:`format`,type:`Card8`,value:0}]),r=0;r<e.length;r+=1){var i=e[r],a=XF(i,t);n.fields.push({name:`glyph_`+r,type:`SID`,value:a})}return n}function aI(e){var t=[],n=e.path;t.push({name:`width`,type:`NUMBER`,value:e.advanceWidth});for(var r=0,i=0,a=0;a<n.commands.length;a+=1){var o=void 0,s=void 0,c=n.commands[a];if(c.type===`Q`){var l=1/3,u=2/3;c={type:`C`,x:c.x,y:c.y,x1:Math.round(l*r+u*c.x1),y1:Math.round(l*i+u*c.y1),x2:Math.round(l*c.x+u*c.x1),y2:Math.round(l*c.y+u*c.y1)}}if(c.type===`M`)o=Math.round(c.x-r),s=Math.round(c.y-i),t.push({name:`dx`,type:`NUMBER`,value:o}),t.push({name:`dy`,type:`NUMBER`,value:s}),t.push({name:`rmoveto`,type:`OP`,value:21}),r=Math.round(c.x),i=Math.round(c.y);else if(c.type===`L`)o=Math.round(c.x-r),s=Math.round(c.y-i),t.push({name:`dx`,type:`NUMBER`,value:o}),t.push({name:`dy`,type:`NUMBER`,value:s}),t.push({name:`rlineto`,type:`OP`,value:5}),r=Math.round(c.x),i=Math.round(c.y);else if(c.type===`C`){var d=Math.round(c.x1-r),f=Math.round(c.y1-i),p=Math.round(c.x2-c.x1),m=Math.round(c.y2-c.y1);o=Math.round(c.x-c.x2),s=Math.round(c.y-c.y2),t.push({name:`dx1`,type:`NUMBER`,value:d}),t.push({name:`dy1`,type:`NUMBER`,value:f}),t.push({name:`dx2`,type:`NUMBER`,value:p}),t.push({name:`dy2`,type:`NUMBER`,value:m}),t.push({name:`dx`,type:`NUMBER`,value:o}),t.push({name:`dy`,type:`NUMBER`,value:s}),t.push({name:`rrcurveto`,type:`OP`,value:8}),r=Math.round(c.x),i=Math.round(c.y)}}return t.push({name:`endchar`,type:`OP`,value:14}),t}function oI(e){for(var t=new Y.Record(`CharStrings INDEX`,[{name:`charStrings`,type:`INDEX`,value:[]}]),n=0;n<e.length;n+=1){var r=e.get(n),i=aI(r);t.charStrings.push({name:r.name,type:`CHARSTRING`,value:i})}return t}function sI(e,t){var n=new Y.Record(`Private DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=$F(VF,e,t),n}function cI(e,t){for(var n=new Y.Table(`CFF `,[{name:`header`,type:`RECORD`},{name:`nameIndex`,type:`RECORD`},{name:`topDictIndex`,type:`RECORD`},{name:`stringIndex`,type:`RECORD`},{name:`globalSubrIndex`,type:`RECORD`},{name:`charsets`,type:`RECORD`},{name:`charStringsIndex`,type:`RECORD`},{name:`privateDict`,type:`RECORD`}]),r=1/t.unitsPerEm,i={version:t.version,fullName:t.fullName,familyName:t.familyName,weight:t.weightName,fontBBox:t.fontBBox||[0,0,0,0],fontMatrix:[r,0,0,r,0,0],charset:999,encoding:0,charStrings:999,private:[0,999]},a={},o=[],s,c=1;c<e.length;c+=1)s=e.get(c),o.push(s.name);var l=[];n.header=ZF(),n.nameIndex=QF([t.postScriptName]);var u=eI(i,l);return n.topDictIndex=tI(u),n.globalSubrIndex=rI(),n.charsets=iI(o,l),n.charStringsIndex=oI(e),n.privateDict=sI(a,l),n.stringIndex=nI(l),i.charset=n.header.sizeOf()+n.nameIndex.sizeOf()+n.topDictIndex.sizeOf()+n.stringIndex.sizeOf()+n.globalSubrIndex.sizeOf(),i.encoding=0,i.charStrings=i.charset+n.charsets.sizeOf(),i.private[1]=i.charStrings+n.charStringsIndex.sizeOf(),u=eI(i,l),n.topDictIndex=tI(u),n}var lI={parse:YF,make:cI};function uI(e,t){var n={},r=new Z.Parser(e,t);return n.version=r.parseVersion(),n.fontRevision=Math.round(r.parseFixed()*1e3)/1e3,n.checkSumAdjustment=r.parseULong(),n.magicNumber=r.parseULong(),K.argument(n.magicNumber===1594834165,`Font header has wrong magic number.`),n.flags=r.parseUShort(),n.unitsPerEm=r.parseUShort(),n.created=r.parseLongDateTime(),n.modified=r.parseLongDateTime(),n.xMin=r.parseShort(),n.yMin=r.parseShort(),n.xMax=r.parseShort(),n.yMax=r.parseShort(),n.macStyle=r.parseUShort(),n.lowestRecPPEM=r.parseUShort(),n.fontDirectionHint=r.parseShort(),n.indexToLocFormat=r.parseShort(),n.glyphDataFormat=r.parseShort(),n}function dI(e){var t=Math.round(new Date().getTime()/1e3)+2082844800,n=t;return e.createdTimestamp&&(n=e.createdTimestamp+2082844800),new Y.Table(`head`,[{name:`version`,type:`FIXED`,value:65536},{name:`fontRevision`,type:`FIXED`,value:65536},{name:`checkSumAdjustment`,type:`ULONG`,value:0},{name:`magicNumber`,type:`ULONG`,value:1594834165},{name:`flags`,type:`USHORT`,value:0},{name:`unitsPerEm`,type:`USHORT`,value:1e3},{name:`created`,type:`LONGDATETIME`,value:n},{name:`modified`,type:`LONGDATETIME`,value:t},{name:`xMin`,type:`SHORT`,value:0},{name:`yMin`,type:`SHORT`,value:0},{name:`xMax`,type:`SHORT`,value:0},{name:`yMax`,type:`SHORT`,value:0},{name:`macStyle`,type:`USHORT`,value:0},{name:`lowestRecPPEM`,type:`USHORT`,value:0},{name:`fontDirectionHint`,type:`SHORT`,value:2},{name:`indexToLocFormat`,type:`SHORT`,value:0},{name:`glyphDataFormat`,type:`SHORT`,value:0}],e)}var fI={parse:uI,make:dI};function pI(e,t){var n={},r=new Z.Parser(e,t);return n.version=r.parseVersion(),n.ascender=r.parseShort(),n.descender=r.parseShort(),n.lineGap=r.parseShort(),n.advanceWidthMax=r.parseUShort(),n.minLeftSideBearing=r.parseShort(),n.minRightSideBearing=r.parseShort(),n.xMaxExtent=r.parseShort(),n.caretSlopeRise=r.parseShort(),n.caretSlopeRun=r.parseShort(),n.caretOffset=r.parseShort(),r.relativeOffset+=8,n.metricDataFormat=r.parseShort(),n.numberOfHMetrics=r.parseUShort(),n}function mI(e){return new Y.Table(`hhea`,[{name:`version`,type:`FIXED`,value:65536},{name:`ascender`,type:`FWORD`,value:0},{name:`descender`,type:`FWORD`,value:0},{name:`lineGap`,type:`FWORD`,value:0},{name:`advanceWidthMax`,type:`UFWORD`,value:0},{name:`minLeftSideBearing`,type:`FWORD`,value:0},{name:`minRightSideBearing`,type:`FWORD`,value:0},{name:`xMaxExtent`,type:`FWORD`,value:0},{name:`caretSlopeRise`,type:`SHORT`,value:1},{name:`caretSlopeRun`,type:`SHORT`,value:0},{name:`caretOffset`,type:`SHORT`,value:0},{name:`reserved1`,type:`SHORT`,value:0},{name:`reserved2`,type:`SHORT`,value:0},{name:`reserved3`,type:`SHORT`,value:0},{name:`reserved4`,type:`SHORT`,value:0},{name:`metricDataFormat`,type:`SHORT`,value:0},{name:`numberOfHMetrics`,type:`USHORT`,value:0}],e)}var hI={parse:pI,make:mI};function gI(e,t,n,r,i){for(var a,o,s=new Z.Parser(e,t),c=0;c<r;c+=1){c<n&&(a=s.parseUShort(),o=s.parseShort());var l=i.get(c);l.advanceWidth=a,l.leftSideBearing=o}}function _I(e,t,n,r,i){e._hmtxTableData={};for(var a,o,s=new Z.Parser(t,n),c=0;c<i;c+=1)c<r&&(a=s.parseUShort(),o=s.parseShort()),e._hmtxTableData[c]={advanceWidth:a,leftSideBearing:o}}function vI(e,t,n,r,i,a,o){o.lowMemory?_I(e,t,n,r,i):gI(t,n,r,i,a)}function yI(e){for(var t=new Y.Table(`hmtx`,[]),n=0;n<e.length;n+=1){var r=e.get(n),i=r.advanceWidth||0,a=r.leftSideBearing||0;t.fields.push({name:`advanceWidth_`+n,type:`USHORT`,value:i}),t.fields.push({name:`leftSideBearing_`+n,type:`SHORT`,value:a})}return t}var bI={parse:vI,make:yI};function xI(e){for(var t=new Y.Table(`ltag`,[{name:`version`,type:`ULONG`,value:1},{name:`flags`,type:`ULONG`,value:0},{name:`numTags`,type:`ULONG`,value:e.length}]),n=``,r=12+e.length*4,i=0;i<e.length;++i){var a=n.indexOf(e[i]);a<0&&(a=n.length,n+=e[i]),t.fields.push({name:`offset `+i,type:`USHORT`,value:r+a}),t.fields.push({name:`length `+i,type:`USHORT`,value:e[i].length})}return t.fields.push({name:`stringPool`,type:`CHARARRAY`,value:n}),t}function SI(e,t){var n=new Z.Parser(e,t),r=n.parseULong();K.argument(r===1,`Unsupported ltag table version.`),n.skip(`uLong`,1);for(var i=n.parseULong(),a=[],o=0;o<i;o++){for(var s=``,c=t+n.parseUShort(),l=n.parseUShort(),u=c;u<c+l;++u)s+=String.fromCharCode(e.getInt8(u));a.push(s)}return a}var CI={make:xI,parse:SI};function wI(e,t){var n={},r=new Z.Parser(e,t);return n.version=r.parseVersion(),n.numGlyphs=r.parseUShort(),n.version===1&&(n.maxPoints=r.parseUShort(),n.maxContours=r.parseUShort(),n.maxCompositePoints=r.parseUShort(),n.maxCompositeContours=r.parseUShort(),n.maxZones=r.parseUShort(),n.maxTwilightPoints=r.parseUShort(),n.maxStorage=r.parseUShort(),n.maxFunctionDefs=r.parseUShort(),n.maxInstructionDefs=r.parseUShort(),n.maxStackElements=r.parseUShort(),n.maxSizeOfInstructions=r.parseUShort(),n.maxComponentElements=r.parseUShort(),n.maxComponentDepth=r.parseUShort()),n}function TI(e){return new Y.Table(`maxp`,[{name:`version`,type:`FIXED`,value:20480},{name:`numGlyphs`,type:`USHORT`,value:e}])}var EI={parse:wI,make:TI},DI=[`copyright`,`fontFamily`,`fontSubfamily`,`uniqueID`,`fullName`,`version`,`postScriptName`,`trademark`,`manufacturer`,`designer`,`description`,`manufacturerURL`,`designerURL`,`license`,`licenseURL`,`reserved`,`preferredFamily`,`preferredSubfamily`,`compatibleFullName`,`sampleText`,`postScriptFindFontName`,`wwsFamily`,`wwsSubfamily`],OI={0:`en`,1:`fr`,2:`de`,3:`it`,4:`nl`,5:`sv`,6:`es`,7:`da`,8:`pt`,9:`no`,10:`he`,11:`ja`,12:`ar`,13:`fi`,14:`el`,15:`is`,16:`mt`,17:`tr`,18:`hr`,19:`zh-Hant`,20:`ur`,21:`hi`,22:`th`,23:`ko`,24:`lt`,25:`pl`,26:`hu`,27:`es`,28:`lv`,29:`se`,30:`fo`,31:`fa`,32:`ru`,33:`zh`,34:`nl-BE`,35:`ga`,36:`sq`,37:`ro`,38:`cz`,39:`sk`,40:`si`,41:`yi`,42:`sr`,43:`mk`,44:`bg`,45:`uk`,46:`be`,47:`uz`,48:`kk`,49:`az-Cyrl`,50:`az-Arab`,51:`hy`,52:`ka`,53:`mo`,54:`ky`,55:`tg`,56:`tk`,57:`mn-CN`,58:`mn`,59:`ps`,60:`ks`,61:`ku`,62:`sd`,63:`bo`,64:`ne`,65:`sa`,66:`mr`,67:`bn`,68:`as`,69:`gu`,70:`pa`,71:`or`,72:`ml`,73:`kn`,74:`ta`,75:`te`,76:`si`,77:`my`,78:`km`,79:`lo`,80:`vi`,81:`id`,82:`tl`,83:`ms`,84:`ms-Arab`,85:`am`,86:`ti`,87:`om`,88:`so`,89:`sw`,90:`rw`,91:`rn`,92:`ny`,93:`mg`,94:`eo`,128:`cy`,129:`eu`,130:`ca`,131:`la`,132:`qu`,133:`gn`,134:`ay`,135:`tt`,136:`ug`,137:`dz`,138:`jv`,139:`su`,140:`gl`,141:`af`,142:`br`,143:`iu`,144:`gd`,145:`gv`,146:`ga`,147:`to`,148:`el-polyton`,149:`kl`,150:`az`,151:`nn`},kI={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:5,11:1,12:4,13:0,14:6,15:0,16:0,17:0,18:0,19:2,20:4,21:9,22:21,23:3,24:29,25:29,26:29,27:29,28:29,29:0,30:0,31:4,32:7,33:25,34:0,35:0,36:0,37:0,38:29,39:29,40:0,41:5,42:7,43:7,44:7,45:7,46:7,47:7,48:7,49:7,50:4,51:24,52:23,53:7,54:7,55:7,56:7,57:27,58:7,59:4,60:4,61:4,62:4,63:26,64:9,65:9,66:9,67:13,68:13,69:11,70:10,71:12,72:17,73:16,74:14,75:15,76:18,77:19,78:20,79:22,80:30,81:0,82:0,83:0,84:4,85:28,86:28,87:28,88:0,89:0,90:0,91:0,92:0,93:0,94:0,128:0,129:0,130:0,131:0,132:0,133:0,134:0,135:7,136:4,137:26,138:0,139:0,140:0,141:0,142:0,143:28,144:0,145:0,146:0,147:0,148:6,149:0,150:0,151:0},AI={1078:`af`,1052:`sq`,1156:`gsw`,1118:`am`,5121:`ar-DZ`,15361:`ar-BH`,3073:`ar`,2049:`ar-IQ`,11265:`ar-JO`,13313:`ar-KW`,12289:`ar-LB`,4097:`ar-LY`,6145:`ary`,8193:`ar-OM`,16385:`ar-QA`,1025:`ar-SA`,10241:`ar-SY`,7169:`aeb`,14337:`ar-AE`,9217:`ar-YE`,1067:`hy`,1101:`as`,2092:`az-Cyrl`,1068:`az`,1133:`ba`,1069:`eu`,1059:`be`,2117:`bn`,1093:`bn-IN`,8218:`bs-Cyrl`,5146:`bs`,1150:`br`,1026:`bg`,1027:`ca`,3076:`zh-HK`,5124:`zh-MO`,2052:`zh`,4100:`zh-SG`,1028:`zh-TW`,1155:`co`,1050:`hr`,4122:`hr-BA`,1029:`cs`,1030:`da`,1164:`prs`,1125:`dv`,2067:`nl-BE`,1043:`nl`,3081:`en-AU`,10249:`en-BZ`,4105:`en-CA`,9225:`en-029`,16393:`en-IN`,6153:`en-IE`,8201:`en-JM`,17417:`en-MY`,5129:`en-NZ`,13321:`en-PH`,18441:`en-SG`,7177:`en-ZA`,11273:`en-TT`,2057:`en-GB`,1033:`en`,12297:`en-ZW`,1061:`et`,1080:`fo`,1124:`fil`,1035:`fi`,2060:`fr-BE`,3084:`fr-CA`,1036:`fr`,5132:`fr-LU`,6156:`fr-MC`,4108:`fr-CH`,1122:`fy`,1110:`gl`,1079:`ka`,3079:`de-AT`,1031:`de`,5127:`de-LI`,4103:`de-LU`,2055:`de-CH`,1032:`el`,1135:`kl`,1095:`gu`,1128:`ha`,1037:`he`,1081:`hi`,1038:`hu`,1039:`is`,1136:`ig`,1057:`id`,1117:`iu`,2141:`iu-Latn`,2108:`ga`,1076:`xh`,1077:`zu`,1040:`it`,2064:`it-CH`,1041:`ja`,1099:`kn`,1087:`kk`,1107:`km`,1158:`quc`,1159:`rw`,1089:`sw`,1111:`kok`,1042:`ko`,1088:`ky`,1108:`lo`,1062:`lv`,1063:`lt`,2094:`dsb`,1134:`lb`,1071:`mk`,2110:`ms-BN`,1086:`ms`,1100:`ml`,1082:`mt`,1153:`mi`,1146:`arn`,1102:`mr`,1148:`moh`,1104:`mn`,2128:`mn-CN`,1121:`ne`,1044:`nb`,2068:`nn`,1154:`oc`,1096:`or`,1123:`ps`,1045:`pl`,1046:`pt`,2070:`pt-PT`,1094:`pa`,1131:`qu-BO`,2155:`qu-EC`,3179:`qu`,1048:`ro`,1047:`rm`,1049:`ru`,9275:`smn`,4155:`smj-NO`,5179:`smj`,3131:`se-FI`,1083:`se`,2107:`se-SE`,8251:`sms`,6203:`sma-NO`,7227:`sms`,1103:`sa`,7194:`sr-Cyrl-BA`,3098:`sr`,6170:`sr-Latn-BA`,2074:`sr-Latn`,1132:`nso`,1074:`tn`,1115:`si`,1051:`sk`,1060:`sl`,11274:`es-AR`,16394:`es-BO`,13322:`es-CL`,9226:`es-CO`,5130:`es-CR`,7178:`es-DO`,12298:`es-EC`,17418:`es-SV`,4106:`es-GT`,18442:`es-HN`,2058:`es-MX`,19466:`es-NI`,6154:`es-PA`,15370:`es-PY`,10250:`es-PE`,20490:`es-PR`,3082:`es`,1034:`es`,21514:`es-US`,14346:`es-UY`,8202:`es-VE`,2077:`sv-FI`,1053:`sv`,1114:`syr`,1064:`tg`,2143:`tzm`,1097:`ta`,1092:`tt`,1098:`te`,1054:`th`,1105:`bo`,1055:`tr`,1090:`tk`,1152:`ug`,1058:`uk`,1070:`hsb`,1056:`ur`,2115:`uz-Cyrl`,1091:`uz`,1066:`vi`,1106:`cy`,1160:`wo`,1157:`sah`,1144:`ii`,1130:`yo`};function jI(e,t,n){switch(e){case 0:if(t===65535)return`und`;if(n)return n[t];break;case 1:return OI[t];case 3:return AI[t]}}var MI=`utf-16`,NI={0:`macintosh`,1:`x-mac-japanese`,2:`x-mac-chinesetrad`,3:`x-mac-korean`,6:`x-mac-greek`,7:`x-mac-cyrillic`,9:`x-mac-devanagai`,10:`x-mac-gurmukhi`,11:`x-mac-gujarati`,12:`x-mac-oriya`,13:`x-mac-bengali`,14:`x-mac-tamil`,15:`x-mac-telugu`,16:`x-mac-kannada`,17:`x-mac-malayalam`,18:`x-mac-sinhalese`,19:`x-mac-burmese`,20:`x-mac-khmer`,21:`x-mac-thai`,22:`x-mac-lao`,23:`x-mac-georgian`,24:`x-mac-armenian`,25:`x-mac-chinesesimp`,26:`x-mac-tibetan`,27:`x-mac-mongolian`,28:`x-mac-ethiopic`,29:`x-mac-ce`,30:`x-mac-vietnamese`,31:`x-mac-extarabic`},PI={15:`x-mac-icelandic`,17:`x-mac-turkish`,18:`x-mac-croatian`,24:`x-mac-ce`,25:`x-mac-ce`,26:`x-mac-ce`,27:`x-mac-ce`,28:`x-mac-ce`,30:`x-mac-icelandic`,37:`x-mac-romanian`,38:`x-mac-ce`,39:`x-mac-ce`,40:`x-mac-ce`,143:`x-mac-inuit`,146:`x-mac-gaelic`};function FI(e,t,n){switch(e){case 0:return MI;case 1:return PI[n]||NI[t];case 3:if(t===1||t===10)return MI;break}}function II(e,t,n){for(var r={},i=new Z.Parser(e,t),a=i.parseUShort(),o=i.parseUShort(),s=i.offset+i.parseUShort(),c=0;c<o;c++){var l=i.parseUShort(),u=i.parseUShort(),d=i.parseUShort(),f=i.parseUShort(),p=DI[f]||f,m=i.parseUShort(),h=i.parseUShort(),g=jI(l,d,n),_=FI(l,u,d);if(_!==void 0&&g!==void 0){var v=void 0;if(v=_===MI?wP.UTF16(e,s+h,m):wP.MACSTRING(e,s+h,m,_),v){var y=r[p];y===void 0&&(y=r[p]={}),y[g]=v}}}return a===1&&i.parseUShort(),r}function LI(e){var t={};for(var n in e)t[e[n]]=parseInt(n);return t}function RI(e,t,n,r,i,a){return new Y.Record(`NameRecord`,[{name:`platformID`,type:`USHORT`,value:e},{name:`encodingID`,type:`USHORT`,value:t},{name:`languageID`,type:`USHORT`,value:n},{name:`nameID`,type:`USHORT`,value:r},{name:`length`,type:`USHORT`,value:i},{name:`offset`,type:`USHORT`,value:a}])}function zI(e,t){var n=e.length,r=t.length-n+1;loop:for(var i=0;i<r;i++)for(;i<r;i++){for(var a=0;a<n;a++)if(t[i+a]!==e[a])continue loop;return i}return-1}function BI(e,t){var n=zI(e,t);if(n<0){n=t.length;for(var r=0,i=e.length;r<i;++r)t.push(e[r])}return n}function VI(e,t){var n,r=[],i={},a=LI(DI);for(var o in e){var s=a[o];if(s===void 0&&(s=o),n=parseInt(s),isNaN(n))throw Error(`Name table entry "`+o+`" does not exist, see nameTableNames for complete list.`);i[n]=e[o],r.push(n)}for(var c=LI(OI),l=LI(AI),u=[],d=[],f=0;f<r.length;f++){n=r[f];var p=i[n];for(var m in p){var h=p[m],g=1,_=c[m],v=kI[_],y=FI(g,v,_),b=q.MACSTRING(h,y);b===void 0&&(g=0,_=t.indexOf(m),_<0&&(_=t.length,t.push(m)),v=4,b=q.UTF16(h));var x=BI(b,d);u.push(RI(g,v,_,n,b.length,x));var S=l[m];if(S!==void 0){var C=q.UTF16(h),w=BI(C,d);u.push(RI(3,1,S,n,C.length,w))}}}u.sort(function(e,t){return e.platformID-t.platformID||e.encodingID-t.encodingID||e.languageID-t.languageID||e.nameID-t.nameID});for(var ee=new Y.Table(`name`,[{name:`format`,type:`USHORT`,value:0},{name:`count`,type:`USHORT`,value:u.length},{name:`stringOffset`,type:`USHORT`,value:6+u.length*12}]),te=0;te<u.length;te++)ee.fields.push({name:`record_`+te,type:`RECORD`,value:u[te]});return ee.fields.push({name:`strings`,type:`LITERAL`,value:d}),ee}var HI={parse:II,make:VI},UI=[{begin:0,end:127},{begin:128,end:255},{begin:256,end:383},{begin:384,end:591},{begin:592,end:687},{begin:688,end:767},{begin:768,end:879},{begin:880,end:1023},{begin:11392,end:11519},{begin:1024,end:1279},{begin:1328,end:1423},{begin:1424,end:1535},{begin:42240,end:42559},{begin:1536,end:1791},{begin:1984,end:2047},{begin:2304,end:2431},{begin:2432,end:2559},{begin:2560,end:2687},{begin:2688,end:2815},{begin:2816,end:2943},{begin:2944,end:3071},{begin:3072,end:3199},{begin:3200,end:3327},{begin:3328,end:3455},{begin:3584,end:3711},{begin:3712,end:3839},{begin:4256,end:4351},{begin:6912,end:7039},{begin:4352,end:4607},{begin:7680,end:7935},{begin:7936,end:8191},{begin:8192,end:8303},{begin:8304,end:8351},{begin:8352,end:8399},{begin:8400,end:8447},{begin:8448,end:8527},{begin:8528,end:8591},{begin:8592,end:8703},{begin:8704,end:8959},{begin:8960,end:9215},{begin:9216,end:9279},{begin:9280,end:9311},{begin:9312,end:9471},{begin:9472,end:9599},{begin:9600,end:9631},{begin:9632,end:9727},{begin:9728,end:9983},{begin:9984,end:10175},{begin:12288,end:12351},{begin:12352,end:12447},{begin:12448,end:12543},{begin:12544,end:12591},{begin:12592,end:12687},{begin:43072,end:43135},{begin:12800,end:13055},{begin:13056,end:13311},{begin:44032,end:55215},{begin:55296,end:57343},{begin:67840,end:67871},{begin:19968,end:40959},{begin:57344,end:63743},{begin:12736,end:12783},{begin:64256,end:64335},{begin:64336,end:65023},{begin:65056,end:65071},{begin:65040,end:65055},{begin:65104,end:65135},{begin:65136,end:65279},{begin:65280,end:65519},{begin:65520,end:65535},{begin:3840,end:4095},{begin:1792,end:1871},{begin:1920,end:1983},{begin:3456,end:3583},{begin:4096,end:4255},{begin:4608,end:4991},{begin:5024,end:5119},{begin:5120,end:5759},{begin:5760,end:5791},{begin:5792,end:5887},{begin:6016,end:6143},{begin:6144,end:6319},{begin:10240,end:10495},{begin:40960,end:42127},{begin:5888,end:5919},{begin:66304,end:66351},{begin:66352,end:66383},{begin:66560,end:66639},{begin:118784,end:119039},{begin:119808,end:120831},{begin:1044480,end:1048573},{begin:65024,end:65039},{begin:917504,end:917631},{begin:6400,end:6479},{begin:6480,end:6527},{begin:6528,end:6623},{begin:6656,end:6687},{begin:11264,end:11359},{begin:11568,end:11647},{begin:19904,end:19967},{begin:43008,end:43055},{begin:65536,end:65663},{begin:65856,end:65935},{begin:66432,end:66463},{begin:66464,end:66527},{begin:66640,end:66687},{begin:66688,end:66735},{begin:67584,end:67647},{begin:68096,end:68191},{begin:119552,end:119647},{begin:73728,end:74751},{begin:119648,end:119679},{begin:7040,end:7103},{begin:7168,end:7247},{begin:7248,end:7295},{begin:43136,end:43231},{begin:43264,end:43311},{begin:43312,end:43359},{begin:43520,end:43615},{begin:65936,end:65999},{begin:66e3,end:66047},{begin:66208,end:66271},{begin:127024,end:127135}];function WI(e){for(var t=0;t<UI.length;t+=1){var n=UI[t];if(e>=n.begin&&e<n.end)return t}return-1}function GI(e,t){var n={},r=new Z.Parser(e,t);n.version=r.parseUShort(),n.xAvgCharWidth=r.parseShort(),n.usWeightClass=r.parseUShort(),n.usWidthClass=r.parseUShort(),n.fsType=r.parseUShort(),n.ySubscriptXSize=r.parseShort(),n.ySubscriptYSize=r.parseShort(),n.ySubscriptXOffset=r.parseShort(),n.ySubscriptYOffset=r.parseShort(),n.ySuperscriptXSize=r.parseShort(),n.ySuperscriptYSize=r.parseShort(),n.ySuperscriptXOffset=r.parseShort(),n.ySuperscriptYOffset=r.parseShort(),n.yStrikeoutSize=r.parseShort(),n.yStrikeoutPosition=r.parseShort(),n.sFamilyClass=r.parseShort(),n.panose=[];for(var i=0;i<10;i++)n.panose[i]=r.parseByte();return n.ulUnicodeRange1=r.parseULong(),n.ulUnicodeRange2=r.parseULong(),n.ulUnicodeRange3=r.parseULong(),n.ulUnicodeRange4=r.parseULong(),n.achVendID=String.fromCharCode(r.parseByte(),r.parseByte(),r.parseByte(),r.parseByte()),n.fsSelection=r.parseUShort(),n.usFirstCharIndex=r.parseUShort(),n.usLastCharIndex=r.parseUShort(),n.sTypoAscender=r.parseShort(),n.sTypoDescender=r.parseShort(),n.sTypoLineGap=r.parseShort(),n.usWinAscent=r.parseUShort(),n.usWinDescent=r.parseUShort(),n.version>=1&&(n.ulCodePageRange1=r.parseULong(),n.ulCodePageRange2=r.parseULong()),n.version>=2&&(n.sxHeight=r.parseShort(),n.sCapHeight=r.parseShort(),n.usDefaultChar=r.parseUShort(),n.usBreakChar=r.parseUShort(),n.usMaxContent=r.parseUShort()),n}function KI(e){return new Y.Table(`OS/2`,[{name:`version`,type:`USHORT`,value:3},{name:`xAvgCharWidth`,type:`SHORT`,value:0},{name:`usWeightClass`,type:`USHORT`,value:0},{name:`usWidthClass`,type:`USHORT`,value:0},{name:`fsType`,type:`USHORT`,value:0},{name:`ySubscriptXSize`,type:`SHORT`,value:650},{name:`ySubscriptYSize`,type:`SHORT`,value:699},{name:`ySubscriptXOffset`,type:`SHORT`,value:0},{name:`ySubscriptYOffset`,type:`SHORT`,value:140},{name:`ySuperscriptXSize`,type:`SHORT`,value:650},{name:`ySuperscriptYSize`,type:`SHORT`,value:699},{name:`ySuperscriptXOffset`,type:`SHORT`,value:0},{name:`ySuperscriptYOffset`,type:`SHORT`,value:479},{name:`yStrikeoutSize`,type:`SHORT`,value:49},{name:`yStrikeoutPosition`,type:`SHORT`,value:258},{name:`sFamilyClass`,type:`SHORT`,value:0},{name:`bFamilyType`,type:`BYTE`,value:0},{name:`bSerifStyle`,type:`BYTE`,value:0},{name:`bWeight`,type:`BYTE`,value:0},{name:`bProportion`,type:`BYTE`,value:0},{name:`bContrast`,type:`BYTE`,value:0},{name:`bStrokeVariation`,type:`BYTE`,value:0},{name:`bArmStyle`,type:`BYTE`,value:0},{name:`bLetterform`,type:`BYTE`,value:0},{name:`bMidline`,type:`BYTE`,value:0},{name:`bXHeight`,type:`BYTE`,value:0},{name:`ulUnicodeRange1`,type:`ULONG`,value:0},{name:`ulUnicodeRange2`,type:`ULONG`,value:0},{name:`ulUnicodeRange3`,type:`ULONG`,value:0},{name:`ulUnicodeRange4`,type:`ULONG`,value:0},{name:`achVendID`,type:`CHARARRAY`,value:`XXXX`},{name:`fsSelection`,type:`USHORT`,value:0},{name:`usFirstCharIndex`,type:`USHORT`,value:0},{name:`usLastCharIndex`,type:`USHORT`,value:0},{name:`sTypoAscender`,type:`SHORT`,value:0},{name:`sTypoDescender`,type:`SHORT`,value:0},{name:`sTypoLineGap`,type:`SHORT`,value:0},{name:`usWinAscent`,type:`USHORT`,value:0},{name:`usWinDescent`,type:`USHORT`,value:0},{name:`ulCodePageRange1`,type:`ULONG`,value:0},{name:`ulCodePageRange2`,type:`ULONG`,value:0},{name:`sxHeight`,type:`SHORT`,value:0},{name:`sCapHeight`,type:`SHORT`,value:0},{name:`usDefaultChar`,type:`USHORT`,value:0},{name:`usBreakChar`,type:`USHORT`,value:0},{name:`usMaxContext`,type:`USHORT`,value:0}],e)}var qI={parse:GI,make:KI,unicodeRanges:UI,getUnicodeRange:WI};function JI(e,t){var n={},r=new Z.Parser(e,t);switch(n.version=r.parseVersion(),n.italicAngle=r.parseFixed(),n.underlinePosition=r.parseShort(),n.underlineThickness=r.parseShort(),n.isFixedPitch=r.parseULong(),n.minMemType42=r.parseULong(),n.maxMemType42=r.parseULong(),n.minMemType1=r.parseULong(),n.maxMemType1=r.parseULong(),n.version){case 1:n.names=uF.slice();break;case 2:n.numberOfGlyphs=r.parseUShort(),n.glyphNameIndex=Array(n.numberOfGlyphs);for(var i=0;i<n.numberOfGlyphs;i++)n.glyphNameIndex[i]=r.parseUShort();n.names=[];for(var a=0;a<n.numberOfGlyphs;a++)if(n.glyphNameIndex[a]>=uF.length){var o=r.parseChar();n.names.push(r.parseString(o))}break;case 2.5:n.numberOfGlyphs=r.parseUShort(),n.offset=Array(n.numberOfGlyphs);for(var s=0;s<n.numberOfGlyphs;s++)n.offset[s]=r.parseChar();break}return n}function YI(){return new Y.Table(`post`,[{name:`version`,type:`FIXED`,value:196608},{name:`italicAngle`,type:`FIXED`,value:0},{name:`underlinePosition`,type:`FWORD`,value:0},{name:`underlineThickness`,type:`FWORD`,value:0},{name:`isFixedPitch`,type:`ULONG`,value:0},{name:`minMemType42`,type:`ULONG`,value:0},{name:`maxMemType42`,type:`ULONG`,value:0},{name:`minMemType1`,type:`ULONG`,value:0},{name:`maxMemType1`,type:`ULONG`,value:0}])}var XI={parse:JI,make:YI},ZI=Array(9);ZI[1]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{substFormat:1,coverage:this.parsePointer(X.coverage),deltaGlyphId:this.parseUShort()};if(t===2)return{substFormat:2,coverage:this.parsePointer(X.coverage),substitute:this.parseOffset16List()};K.assert(!1,`0x`+e.toString(16)+`: lookup type 1 format must be 1 or 2.`)},ZI[2]=function(){var e=this.parseUShort();return K.argument(e===1,`GSUB Multiple Substitution Subtable identifier-format must be 1`),{substFormat:e,coverage:this.parsePointer(X.coverage),sequences:this.parseListOfLists()}},ZI[3]=function(){var e=this.parseUShort();return K.argument(e===1,`GSUB Alternate Substitution Subtable identifier-format must be 1`),{substFormat:e,coverage:this.parsePointer(X.coverage),alternateSets:this.parseListOfLists()}},ZI[4]=function(){var e=this.parseUShort();return K.argument(e===1,`GSUB ligature table identifier-format must be 1`),{substFormat:e,coverage:this.parsePointer(X.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var QI={sequenceIndex:X.uShort,lookupListIndex:X.uShort};ZI[5]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{substFormat:t,coverage:this.parsePointer(X.coverage),ruleSets:this.parseListOfLists(function(){var e=this.parseUShort(),t=this.parseUShort();return{input:this.parseUShortList(e-1),lookupRecords:this.parseRecordList(t,QI)}})};if(t===2)return{substFormat:t,coverage:this.parsePointer(X.coverage),classDef:this.parsePointer(X.classDef),classSets:this.parseListOfLists(function(){var e=this.parseUShort(),t=this.parseUShort();return{classes:this.parseUShortList(e-1),lookupRecords:this.parseRecordList(t,QI)}})};if(t===3){var n=this.parseUShort(),r=this.parseUShort();return{substFormat:t,coverages:this.parseList(n,X.pointer(X.coverage)),lookupRecords:this.parseRecordList(r,QI)}}K.assert(!1,`0x`+e.toString(16)+`: lookup type 5 format must be 1, 2 or 3.`)},ZI[6]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{substFormat:1,coverage:this.parsePointer(X.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(QI)}})};if(t===2)return{substFormat:2,coverage:this.parsePointer(X.coverage),backtrackClassDef:this.parsePointer(X.classDef),inputClassDef:this.parsePointer(X.classDef),lookaheadClassDef:this.parsePointer(X.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(QI)}})};if(t===3)return{substFormat:3,backtrackCoverage:this.parseList(X.pointer(X.coverage)),inputCoverage:this.parseList(X.pointer(X.coverage)),lookaheadCoverage:this.parseList(X.pointer(X.coverage)),lookupRecords:this.parseRecordList(QI)};K.assert(!1,`0x`+e.toString(16)+`: lookup type 6 format must be 1, 2 or 3.`)},ZI[7]=function(){var e=this.parseUShort();K.argument(e===1,`GSUB Extension Substitution subtable identifier-format must be 1`);var t=this.parseUShort(),n=new X(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:t,extension:ZI[t].call(n)}},ZI[8]=function(){var e=this.parseUShort();return K.argument(e===1,`GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1`),{substFormat:e,coverage:this.parsePointer(X.coverage),backtrackCoverage:this.parseList(X.pointer(X.coverage)),lookaheadCoverage:this.parseList(X.pointer(X.coverage)),substitutes:this.parseUShortList()}};function $I(e,t){t||=0;var n=new X(e,t),r=n.parseVersion(1);return K.argument(r===1||r===1.1,`Unsupported GSUB table version.`),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(ZI)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(ZI),variations:n.parseFeatureVariationsList()}}var eL=Array(9);eL[1]=function(e){return e.substFormat===1?new Y.Table(`substitutionTable`,[{name:`substFormat`,type:`USHORT`,value:1},{name:`coverage`,type:`TABLE`,value:new Y.Coverage(e.coverage)},{name:`deltaGlyphID`,type:`USHORT`,value:e.deltaGlyphId}]):new Y.Table(`substitutionTable`,[{name:`substFormat`,type:`USHORT`,value:2},{name:`coverage`,type:`TABLE`,value:new Y.Coverage(e.coverage)}].concat(Y.ushortList(`substitute`,e.substitute)))},eL[2]=function(e){return K.assert(e.substFormat===1,`Lookup type 2 substFormat must be 1.`),new Y.Table(`substitutionTable`,[{name:`substFormat`,type:`USHORT`,value:1},{name:`coverage`,type:`TABLE`,value:new Y.Coverage(e.coverage)}].concat(Y.tableList(`seqSet`,e.sequences,function(e){return new Y.Table(`sequenceSetTable`,Y.ushortList(`sequence`,e))})))},eL[3]=function(e){return K.assert(e.substFormat===1,`Lookup type 3 substFormat must be 1.`),new Y.Table(`substitutionTable`,[{name:`substFormat`,type:`USHORT`,value:1},{name:`coverage`,type:`TABLE`,value:new Y.Coverage(e.coverage)}].concat(Y.tableList(`altSet`,e.alternateSets,function(e){return new Y.Table(`alternateSetTable`,Y.ushortList(`alternate`,e))})))},eL[4]=function(e){return K.assert(e.substFormat===1,`Lookup type 4 substFormat must be 1.`),new Y.Table(`substitutionTable`,[{name:`substFormat`,type:`USHORT`,value:1},{name:`coverage`,type:`TABLE`,value:new Y.Coverage(e.coverage)}].concat(Y.tableList(`ligSet`,e.ligatureSets,function(e){return new Y.Table(`ligatureSetTable`,Y.tableList(`ligature`,e,function(e){return new Y.Table(`ligatureTable`,[{name:`ligGlyph`,type:`USHORT`,value:e.ligGlyph}].concat(Y.ushortList(`component`,e.components,e.components.length+1)))}))})))},eL[6]=function(e){if(e.substFormat===1)return new Y.Table(`chainContextTable`,[{name:`substFormat`,type:`USHORT`,value:e.substFormat},{name:`coverage`,type:`TABLE`,value:new Y.Coverage(e.coverage)}].concat(Y.tableList(`chainRuleSet`,e.chainRuleSets,function(e){return new Y.Table(`chainRuleSetTable`,Y.tableList(`chainRule`,e,function(e){var t=Y.ushortList(`backtrackGlyph`,e.backtrack,e.backtrack.length).concat(Y.ushortList(`inputGlyph`,e.input,e.input.length+1)).concat(Y.ushortList(`lookaheadGlyph`,e.lookahead,e.lookahead.length)).concat(Y.ushortList(`substitution`,[],e.lookupRecords.length));return e.lookupRecords.forEach(function(e,n){t=t.concat({name:`sequenceIndex`+n,type:`USHORT`,value:e.sequenceIndex}).concat({name:`lookupListIndex`+n,type:`USHORT`,value:e.lookupListIndex})}),new Y.Table(`chainRuleTable`,t)}))})));if(e.substFormat===2)K.assert(!1,`lookup type 6 format 2 is not yet supported.`);else if(e.substFormat===3){var t=[{name:`substFormat`,type:`USHORT`,value:e.substFormat}];return t.push({name:`backtrackGlyphCount`,type:`USHORT`,value:e.backtrackCoverage.length}),e.backtrackCoverage.forEach(function(e,n){t.push({name:`backtrackCoverage`+n,type:`TABLE`,value:new Y.Coverage(e)})}),t.push({name:`inputGlyphCount`,type:`USHORT`,value:e.inputCoverage.length}),e.inputCoverage.forEach(function(e,n){t.push({name:`inputCoverage`+n,type:`TABLE`,value:new Y.Coverage(e)})}),t.push({name:`lookaheadGlyphCount`,type:`USHORT`,value:e.lookaheadCoverage.length}),e.lookaheadCoverage.forEach(function(e,n){t.push({name:`lookaheadCoverage`+n,type:`TABLE`,value:new Y.Coverage(e)})}),t.push({name:`substitutionCount`,type:`USHORT`,value:e.lookupRecords.length}),e.lookupRecords.forEach(function(e,n){t=t.concat({name:`sequenceIndex`+n,type:`USHORT`,value:e.sequenceIndex}).concat({name:`lookupListIndex`+n,type:`USHORT`,value:e.lookupListIndex})}),new Y.Table(`chainContextTable`,t)}K.assert(!1,`lookup type 6 format must be 1, 2 or 3.`)};function tL(e){return new Y.Table(`GSUB`,[{name:`version`,type:`ULONG`,value:65536},{name:`scripts`,type:`TABLE`,value:new Y.ScriptList(e.scripts)},{name:`features`,type:`TABLE`,value:new Y.FeatureList(e.features)},{name:`lookups`,type:`TABLE`,value:new Y.LookupList(e.lookups,eL)}])}var nL={parse:$I,make:tL};function rL(e,t){var n=new Z.Parser(e,t),r=n.parseULong();K.argument(r===1,`Unsupported META table version.`),n.parseULong(),n.parseULong();for(var i=n.parseULong(),a={},o=0;o<i;o++){var s=n.parseTag(),c=n.parseULong(),l=n.parseULong();a[s]=wP.UTF8(e,t+c,l)}return a}function iL(e){var t=Object.keys(e).length,n=``,r=16+t*12,i=new Y.Table(`meta`,[{name:`version`,type:`ULONG`,value:1},{name:`flags`,type:`ULONG`,value:0},{name:`offset`,type:`ULONG`,value:r},{name:`numTags`,type:`ULONG`,value:t}]);for(var a in e){var o=n.length;n+=e[a],i.fields.push({name:`tag `+a,type:`TAG`,value:a}),i.fields.push({name:`offset `+a,type:`ULONG`,value:r+o}),i.fields.push({name:`length `+a,type:`ULONG`,value:e[a].length})}return i.fields.push({name:`stringPool`,type:`CHARARRAY`,value:n}),i}var aL={parse:rL,make:iL};function oL(e){return Math.log(e)/Math.log(2)|0}function sL(e){for(;e.length%4!=0;)e.push(0);for(var t=0,n=0;n<e.length;n+=4)t+=(e[n]<<24)+(e[n+1]<<16)+(e[n+2]<<8)+e[n+3];return t%=2**32,t}function cL(e,t,n,r){return new Y.Record(`Table Record`,[{name:`tag`,type:`TAG`,value:e===void 0?``:e},{name:`checkSum`,type:`ULONG`,value:t===void 0?0:t},{name:`offset`,type:`ULONG`,value:n===void 0?0:n},{name:`length`,type:`ULONG`,value:r===void 0?0:r}])}function lL(e){var t=new Y.Table(`sfnt`,[{name:`version`,type:`TAG`,value:`OTTO`},{name:`numTables`,type:`USHORT`,value:0},{name:`searchRange`,type:`USHORT`,value:0},{name:`entrySelector`,type:`USHORT`,value:0},{name:`rangeShift`,type:`USHORT`,value:0}]);t.tables=e,t.numTables=e.length;var n=2**oL(t.numTables);t.searchRange=16*n,t.entrySelector=oL(n),t.rangeShift=t.numTables*16-t.searchRange;for(var r=[],i=[],a=t.sizeOf()+cL().sizeOf()*t.numTables;a%4!=0;)a+=1,i.push({name:`padding`,type:`BYTE`,value:0});for(var o=0;o<e.length;o+=1){var s=e[o];K.argument(s.tableName.length===4,`Table name`+s.tableName+` is invalid.`);var c=s.sizeOf(),l=cL(s.tableName,sL(s.encode()),a,c);for(r.push({name:l.tag+` Table Record`,type:`RECORD`,value:l}),i.push({name:s.tableName+` table`,type:`RECORD`,value:s}),a+=c,K.argument(!isNaN(a),`Something went wrong calculating the offset.`);a%4!=0;)a+=1,i.push({name:`padding`,type:`BYTE`,value:0})}return r.sort(function(e,t){return e.value.tag>t.value.tag?1:-1}),t.fields=t.fields.concat(r),t.fields=t.fields.concat(i),t}function uL(e,t,n){for(var r=0;r<t.length;r+=1){var i=e.charToGlyphIndex(t[r]);if(i>0)return e.glyphs.get(i).getMetrics()}return n}function dL(e){for(var t=0,n=0;n<e.length;n+=1)t+=e[n];return t/e.length}function fL(e){for(var t=[],n=[],r=[],i=[],a=[],o=[],s=[],c,l=0,u=0,d=0,f=0,p=0,m=0;m<e.glyphs.length;m+=1){var h=e.glyphs.get(m),g=h.unicode|0;if(isNaN(h.advanceWidth))throw Error(`Glyph `+h.name+` (`+m+`): advanceWidth is not a number.`);(c>g||c===void 0)&&g>0&&(c=g),l<g&&(l=g);var _=qI.getUnicodeRange(g);if(_<32)u|=1<<_;else if(_<64)d|=1<<_-32;else if(_<96)f|=1<<_-64;else if(_<123)p|=1<<_-96;else throw Error(`Unicode ranges bits > 123 are reserved for internal usage`);if(h.name!==`.notdef`){var v=h.getMetrics();t.push(v.xMin),n.push(v.yMin),r.push(v.xMax),i.push(v.yMax),o.push(v.leftSideBearing),s.push(v.rightSideBearing),a.push(h.advanceWidth)}}var y={xMin:Math.min.apply(null,t),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,r),yMax:Math.max.apply(null,i),advanceWidthMax:Math.max.apply(null,a),advanceWidthAvg:dL(a),minLeftSideBearing:Math.min.apply(null,o),maxLeftSideBearing:Math.max.apply(null,o),minRightSideBearing:Math.min.apply(null,s)};y.ascender=e.ascender,y.descender=e.descender;var b=fI.make({flags:3,unitsPerEm:e.unitsPerEm,xMin:y.xMin,yMin:y.yMin,xMax:y.xMax,yMax:y.yMax,lowestRecPPEM:3,createdTimestamp:e.createdTimestamp}),x=hI.make({ascender:y.ascender,descender:y.descender,advanceWidthMax:y.advanceWidthMax,minLeftSideBearing:y.minLeftSideBearing,minRightSideBearing:y.minRightSideBearing,xMaxExtent:y.maxLeftSideBearing+(y.xMax-y.xMin),numberOfHMetrics:e.glyphs.length}),S=EI.make(e.glyphs.length),C=qI.make(Object.assign({xAvgCharWidth:Math.round(y.advanceWidthAvg),usFirstCharIndex:c,usLastCharIndex:l,ulUnicodeRange1:u,ulUnicodeRange2:d,ulUnicodeRange3:f,ulUnicodeRange4:p,sTypoAscender:y.ascender,sTypoDescender:y.descender,sTypoLineGap:0,usWinAscent:y.yMax,usWinDescent:Math.abs(y.yMin),ulCodePageRange1:1,sxHeight:uL(e,`xyvw`,{yMax:Math.round(y.ascender/2)}).yMax,sCapHeight:uL(e,`HIKLEFJMNTZBDPRAGOQSUVWXY`,y).yMax,usDefaultChar:e.hasChar(` `)?32:0,usBreakChar:e.hasChar(` `)?32:0},e.tables.os2)),w=bI.make(e.glyphs),ee=oF.make(e.glyphs),te=e.getEnglishName(`fontFamily`),ne=e.getEnglishName(`fontSubfamily`),re=te+` `+ne,ie=e.getEnglishName(`postScriptName`);ie||=te.replace(/\s/g,``)+`-`+ne;var ae={};for(var oe in e.names)ae[oe]=e.names[oe];ae.uniqueID||={en:e.getEnglishName(`manufacturer`)+`:`+re},ae.postScriptName||={en:ie},ae.preferredFamily||=e.names.fontFamily,ae.preferredSubfamily||=e.names.fontSubfamily;var se=[],ce=HI.make(ae,se),le=se.length>0?CI.make(se):void 0,ue=XI.make(),de=lI.make(e.glyphs,{version:e.getEnglishName(`version`),fullName:re,familyName:te,weightName:ne,postScriptName:ie,unitsPerEm:e.unitsPerEm,fontBBox:[0,y.yMin,y.ascender,y.advanceWidthMax]}),fe=e.metas&&Object.keys(e.metas).length>0?aL.make(e.metas):void 0,pe=[b,x,S,C,ce,ee,ue,de,w];le&&pe.push(le),e.tables.gsub&&pe.push(nL.make(e.tables.gsub)),fe&&pe.push(fe);for(var me=lL(pe),he=sL(me.encode()),ge=me.fields,_e=!1,ve=0;ve<ge.length;ve+=1)if(ge[ve].name===`head table`){ge[ve].value.checkSumAdjustment=2981146554-he,_e=!0;break}if(!_e)throw Error(`Could not find head table with checkSum to adjust.`);return me}var pL={make:lL,fontToTable:fL,computeCheckSum:sL};function mL(e,t){for(var n=0,r=e.length-1;n<=r;){var i=n+r>>>1,a=e[i].tag;if(a===t)return i;a<t?n=i+1:r=i-1}return-n-1}function hL(e,t){for(var n=0,r=e.length-1;n<=r;){var i=n+r>>>1,a=e[i];if(a===t)return i;a<t?n=i+1:r=i-1}return-n-1}function gL(e,t){for(var n,r=0,i=e.length-1;r<=i;){var a=r+i>>>1;n=e[a];var o=n.start;if(o===t)return n;o<t?r=a+1:i=a-1}if(r>0)return n=e[r-1],t>n.end?0:n}function _L(e,t){this.font=e,this.tableName=t}_L.prototype={searchTag:mL,binSearch:hL,getTable:function(e){var t=this.font.tables[this.tableName];return!t&&e&&(t=this.font.tables[this.tableName]=this.createDefaultTable()),t},getScriptNames:function(){var e=this.getTable();return e?e.scripts.map(function(e){return e.tag}):[]},getDefaultScriptName:function(){var e=this.getTable();if(e){for(var t=!1,n=0;n<e.scripts.length;n++){var r=e.scripts[n].tag;if(r===`DFLT`)return r;r===`latn`&&(t=!0)}if(t)return`latn`}},getScriptTable:function(e,t){var n=this.getTable(t);if(n){e||=`DFLT`;var r=n.scripts,i=mL(n.scripts,e);if(i>=0)return r[i].script;if(t){var a={tag:e,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return r.splice(-1-i,0,a),a.script}}},getLangSysTable:function(e,t,n){var r=this.getScriptTable(e,n);if(r){if(!t||t===`dflt`||t===`DFLT`)return r.defaultLangSys;var i=mL(r.langSysRecords,t);if(i>=0)return r.langSysRecords[i].langSys;if(n){var a={tag:t,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return r.langSysRecords.splice(-1-i,0,a),a.langSys}}},getFeatureTable:function(e,t,n,r){var i=this.getLangSysTable(e,t,r);if(i){for(var a,o=i.featureIndexes,s=this.font.tables[this.tableName].features,c=0;c<o.length;c++)if(a=s[o[c]],a.tag===n)return a.feature;if(r){var l=s.length;return K.assert(l===0||n>=s[l-1].tag,`Features must be added in alphabetical order.`),a={tag:n,feature:{params:0,lookupListIndexes:[]}},s.push(a),o.push(l),a.feature}}},getLookupTables:function(e,t,n,r,i){var a=this.getFeatureTable(e,t,n,i),o=[];if(a){for(var s,c=a.lookupListIndexes,l=this.font.tables[this.tableName].lookups,u=0;u<c.length;u++)s=l[c[u]],s.lookupType===r&&o.push(s);if(o.length===0&&i){s={lookupType:r,lookupFlag:0,subtables:[],markFilteringSet:void 0};var d=l.length;return l.push(s),c.push(d),[s]}}return o},getGlyphClass:function(e,t){switch(e.format){case 1:return e.startGlyph<=t&&t<e.startGlyph+e.classes.length?e.classes[t-e.startGlyph]:0;case 2:var n=gL(e.ranges,t);return n?n.classId:0}},getCoverageIndex:function(e,t){switch(e.format){case 1:var n=hL(e.glyphs,t);return n>=0?n:-1;case 2:var r=gL(e.ranges,t);return r?r.index+t-r.start:-1}},expandCoverage:function(e){if(e.format===1)return e.glyphs;for(var t=[],n=e.ranges,r=0;r<n.length;r++)for(var i=n[r],a=i.start,o=i.end,s=a;s<=o;s++)t.push(s);return t}};function vL(e){_L.call(this,e,`gpos`)}vL.prototype=_L.prototype,vL.prototype.init=function(){var e=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(e)},vL.prototype.getKerningValue=function(e,t,n){for(var r=0;r<e.length;r++)for(var i=e[r].subtables,a=0;a<i.length;a++){var o=i[a],s=this.getCoverageIndex(o.coverage,t);if(!(s<0))switch(o.posFormat){case 1:for(var c=o.pairSets[s],l=0;l<c.length;l++){var u=c[l];if(u.secondGlyph===n)return u.value1&&u.value1.xAdvance||0}break;case 2:var d=this.getGlyphClass(o.classDef1,t),f=this.getGlyphClass(o.classDef2,n),p=o.classRecords[d][f];return p.value1&&p.value1.xAdvance||0}}return 0},vL.prototype.getKerningTables=function(e,t){if(this.font.tables.gpos)return this.getLookupTables(e,t,`kern`,2)};function yL(e){_L.call(this,e,`gsub`)}function bL(e,t){var n=e.length;if(n!==t.length)return!1;for(var r=0;r<n;r++)if(e[r]!==t[r])return!1;return!0}function xL(e,t,n){for(var r=e.subtables,i=0;i<r.length;i++){var a=r[i];if(a.substFormat===t)return a}if(n)return r.push(n),n}yL.prototype=_L.prototype,yL.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:`DFLT`,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}},yL.prototype.getSingle=function(e,t,n){for(var r=[],i=this.getLookupTables(t,n,e,1),a=0;a<i.length;a++)for(var o=i[a].subtables,s=0;s<o.length;s++){var c=o[s],l=this.expandCoverage(c.coverage),u=void 0;if(c.substFormat===1){var d=c.deltaGlyphId;for(u=0;u<l.length;u++){var f=l[u];r.push({sub:f,by:f+d})}}else{var p=c.substitute;for(u=0;u<l.length;u++)r.push({sub:l[u],by:p[u]})}}return r},yL.prototype.getMultiple=function(e,t,n){for(var r=[],i=this.getLookupTables(t,n,e,2),a=0;a<i.length;a++)for(var o=i[a].subtables,s=0;s<o.length;s++){var c=o[s],l=this.expandCoverage(c.coverage),u=void 0;for(u=0;u<l.length;u++){var d=l[u],f=c.sequences[u];r.push({sub:d,by:f})}}return r},yL.prototype.getAlternates=function(e,t,n){for(var r=[],i=this.getLookupTables(t,n,e,3),a=0;a<i.length;a++)for(var o=i[a].subtables,s=0;s<o.length;s++)for(var c=o[s],l=this.expandCoverage(c.coverage),u=c.alternateSets,d=0;d<l.length;d++)r.push({sub:l[d],by:u[d]});return r},yL.prototype.getLigatures=function(e,t,n){for(var r=[],i=this.getLookupTables(t,n,e,4),a=0;a<i.length;a++)for(var o=i[a].subtables,s=0;s<o.length;s++)for(var c=o[s],l=this.expandCoverage(c.coverage),u=c.ligatureSets,d=0;d<l.length;d++)for(var f=l[d],p=u[d],m=0;m<p.length;m++){var h=p[m];r.push({sub:[f].concat(h.components),by:h.ligGlyph})}return r},yL.prototype.addSingle=function(e,t,n,r){var i=this.getLookupTables(n,r,e,1,!0)[0],a=xL(i,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});K.assert(a.coverage.format===1,`Single: unable to modify coverage table format `+a.coverage.format);var o=t.sub,s=this.binSearch(a.coverage.glyphs,o);s<0&&(s=-1-s,a.coverage.glyphs.splice(s,0,o),a.substitute.splice(s,0,0)),a.substitute[s]=t.by},yL.prototype.addMultiple=function(e,t,n,r){K.assert(t.by instanceof Array&&t.by.length>1,`Multiple: "by" must be an array of two or more ids`);var i=this.getLookupTables(n,r,e,2,!0)[0],a=xL(i,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});K.assert(a.coverage.format===1,`Multiple: unable to modify coverage table format `+a.coverage.format);var o=t.sub,s=this.binSearch(a.coverage.glyphs,o);s<0&&(s=-1-s,a.coverage.glyphs.splice(s,0,o),a.sequences.splice(s,0,0)),a.sequences[s]=t.by},yL.prototype.addAlternate=function(e,t,n,r){var i=this.getLookupTables(n,r,e,3,!0)[0],a=xL(i,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});K.assert(a.coverage.format===1,`Alternate: unable to modify coverage table format `+a.coverage.format);var o=t.sub,s=this.binSearch(a.coverage.glyphs,o);s<0&&(s=-1-s,a.coverage.glyphs.splice(s,0,o),a.alternateSets.splice(s,0,0)),a.alternateSets[s]=t.by},yL.prototype.addLigature=function(e,t,n,r){var i=this.getLookupTables(n,r,e,4,!0)[0],a=i.subtables[0];a||(a={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},i.subtables[0]=a),K.assert(a.coverage.format===1,`Ligature: unable to modify coverage table format `+a.coverage.format);var o=t.sub[0],s=t.sub.slice(1),c={ligGlyph:t.by,components:s},l=this.binSearch(a.coverage.glyphs,o);if(l>=0){for(var u=a.ligatureSets[l],d=0;d<u.length;d++)if(bL(u[d].components,s))return;u.push(c)}else l=-1-l,a.coverage.glyphs.splice(l,0,o),a.ligatureSets.splice(l,0,[c])},yL.prototype.getFeature=function(e,t,n){if(/ss\d\d/.test(e))return this.getSingle(e,t,n);switch(e){case`aalt`:case`salt`:return this.getSingle(e,t,n).concat(this.getAlternates(e,t,n));case`dlig`:case`liga`:case`rlig`:return this.getLigatures(e,t,n);case`ccmp`:return this.getMultiple(e,t,n).concat(this.getLigatures(e,t,n));case`stch`:return this.getMultiple(e,t,n)}},yL.prototype.add=function(e,t,n,r){if(/ss\d\d/.test(e))return this.addSingle(e,t,n,r);switch(e){case`aalt`:case`salt`:return typeof t.by==`number`?this.addSingle(e,t,n,r):this.addAlternate(e,t,n,r);case`dlig`:case`liga`:case`rlig`:return this.addLigature(e,t,n,r);case`ccmp`:return t.by instanceof Array?this.addMultiple(e,t,n,r):this.addLigature(e,t,n,r)}};function SL(){return typeof window<`u`}function CL(e){for(var t=new ArrayBuffer(e.length),n=new Uint8Array(t),r=0;r<e.length;++r)n[r]=e[r];return t}function wL(e){for(var t=new Buffer(e.byteLength),n=new Uint8Array(e),r=0;r<t.length;++r)t[r]=n[r];return t}function TL(e,t){if(!e)throw t}function EL(e,t,n,r,i){var a;return(t&r)>0?(a=e.parseByte(),(t&i)===0&&(a=-a),a=n+a):a=(t&i)>0?n:n+e.parseShort(),a}function DL(e,t,n){var r=new Z.Parser(t,n);e.numberOfContours=r.parseShort(),e._xMin=r.parseShort(),e._yMin=r.parseShort(),e._xMax=r.parseShort(),e._yMax=r.parseShort();var i,a;if(e.numberOfContours>0){for(var o=e.endPointIndices=[],s=0;s<e.numberOfContours;s+=1)o.push(r.parseUShort());e.instructionLength=r.parseUShort(),e.instructions=[];for(var c=0;c<e.instructionLength;c+=1)e.instructions.push(r.parseByte());var l=o[o.length-1]+1;i=[];for(var u=0;u<l;u+=1)if(a=r.parseByte(),i.push(a),(a&8)>0)for(var d=r.parseByte(),f=0;f<d;f+=1)i.push(a),u+=1;if(K.argument(i.length===l,`Bad flags.`),o.length>0){var p=[],m;if(l>0){for(var h=0;h<l;h+=1)a=i[h],m={},m.onCurve=!!(a&1),m.lastPointOfContour=o.indexOf(h)>=0,p.push(m);for(var g=0,_=0;_<l;_+=1)a=i[_],m=p[_],m.x=EL(r,a,g,2,16),g=m.x;for(var v=0,y=0;y<l;y+=1)a=i[y],m=p[y],m.y=EL(r,a,v,4,32),v=m.y}e.points=p}else e.points=[]}else if(e.numberOfContours===0)e.points=[];else{e.isComposite=!0,e.points=[],e.components=[];for(var b=!0;b;){i=r.parseUShort();var x={glyphIndex:r.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(i&1)>0?(i&2)>0?(x.dx=r.parseShort(),x.dy=r.parseShort()):x.matchedPoints=[r.parseUShort(),r.parseUShort()]:(i&2)>0?(x.dx=r.parseChar(),x.dy=r.parseChar()):x.matchedPoints=[r.parseByte(),r.parseByte()],(i&8)>0?x.xScale=x.yScale=r.parseF2Dot14():(i&64)>0?(x.xScale=r.parseF2Dot14(),x.yScale=r.parseF2Dot14()):(i&128)>0&&(x.xScale=r.parseF2Dot14(),x.scale01=r.parseF2Dot14(),x.scale10=r.parseF2Dot14(),x.yScale=r.parseF2Dot14()),e.components.push(x),b=!!(i&32)}if(i&256){e.instructionLength=r.parseUShort(),e.instructions=[];for(var S=0;S<e.instructionLength;S+=1)e.instructions.push(r.parseByte())}}}function OL(e,t){for(var n=[],r=0;r<e.length;r+=1){var i=e[r],a={x:t.xScale*i.x+t.scale01*i.y+t.dx,y:t.scale10*i.x+t.yScale*i.y+t.dy,onCurve:i.onCurve,lastPointOfContour:i.lastPointOfContour};n.push(a)}return n}function kL(e){for(var t=[],n=[],r=0;r<e.length;r+=1){var i=e[r];n.push(i),i.lastPointOfContour&&(t.push(n),n=[])}return K.argument(n.length===0,`There are still points left in the current contour.`),t}function AL(e){var t=new yP;if(!e)return t;for(var n=kL(e),r=0;r<n.length;++r){var i=n[r],a=null,o=i[i.length-1],s=i[0];if(o.onCurve)t.moveTo(o.x,o.y);else if(s.onCurve)t.moveTo(s.x,s.y);else{var c={x:(o.x+s.x)*.5,y:(o.y+s.y)*.5};t.moveTo(c.x,c.y)}for(var l=0;l<i.length;++l)if(a=o,o=s,s=i[(l+1)%i.length],o.onCurve)t.lineTo(o.x,o.y);else{var u=s;a.onCurve||((o.x+a.x)*.5,(o.y+a.y)*.5),s.onCurve||(u={x:(o.x+s.x)*.5,y:(o.y+s.y)*.5}),t.quadraticCurveTo(o.x,o.y,u.x,u.y)}t.closePath()}return t}function jL(e,t){if(t.isComposite)for(var n=0;n<t.components.length;n+=1){var r=t.components[n],i=e.get(r.glyphIndex);if(i.getPath(),i.points){var a=void 0;if(r.matchedPoints===void 0)a=OL(i.points,r);else{if(r.matchedPoints[0]>t.points.length-1||r.matchedPoints[1]>i.points.length-1)throw Error(`Matched points out of range in `+t.name);var o=t.points[r.matchedPoints[0]],s=i.points[r.matchedPoints[1]],c={xScale:r.xScale,scale01:r.scale01,scale10:r.scale10,yScale:r.yScale,dx:0,dy:0};s=OL([s],c)[0],c.dx=o.x-s.x,c.dy=o.y-s.y,a=OL(i.points,c)}t.points=t.points.concat(a)}}return AL(t.points)}function ML(e,t,n,r){for(var i=new DF.GlyphSet(r),a=0;a<n.length-1;a+=1){var o=n[a];o===n[a+1]?i.push(a,DF.glyphLoader(r,a)):i.push(a,DF.ttfGlyphLoader(r,a,DL,e,t+o,jL))}return i}function NL(e,t,n,r){var i=new DF.GlyphSet(r);return r._push=function(a){var o=n[a];o===n[a+1]?i.push(a,DF.glyphLoader(r,a)):i.push(a,DF.ttfGlyphLoader(r,a,DL,e,t+o,jL))},i}function PL(e,t,n,r,i){return i.lowMemory?NL(e,t,n,r):ML(e,t,n,r)}var FL={getPath:AL,parse:PL},IL,LL,RL,zL;function BL(e){this.font=e,this.getCommands=function(e){return FL.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function VL(e){return e}function HL(e){return Math.sign(e)*Math.round(Math.abs(e))}function UL(e){return Math.sign(e)*Math.round(Math.abs(e*2))/2}function WL(e){return Math.sign(e)*(Math.round(Math.abs(e)+.5)-.5)}function GL(e){return Math.sign(e)*Math.ceil(Math.abs(e))}function KL(e){return Math.sign(e)*Math.floor(Math.abs(e))}var qL=function(e){var t=this.srPeriod,n=this.srPhase,r=this.srThreshold,i=1;return e<0&&(e=-e,i=-1),e+=r-n,e=Math.trunc(e/t)*t,e+=n,e<0?n*i:e*i},JL={x:1,y:0,axis:`x`,distance:function(e,t,n,r){return(n?e.xo:e.x)-(r?t.xo:t.x)},interpolate:function(e,t,n,r){var i,a,o,s,c,l,u;if(!r||r===this){if(i=e.xo-t.xo,a=e.xo-n.xo,c=t.x-t.xo,l=n.x-n.xo,o=Math.abs(i),s=Math.abs(a),u=o+s,u===0){e.x=e.xo+(c+l)/2;return}e.x=e.xo+(c*s+l*o)/u;return}if(i=r.distance(e,t,!0,!0),a=r.distance(e,n,!0,!0),c=r.distance(t,t,!1,!0),l=r.distance(n,n,!1,!0),o=Math.abs(i),s=Math.abs(a),u=o+s,u===0){JL.setRelative(e,e,(c+l)/2,r,!0);return}JL.setRelative(e,e,(c*s+l*o)/u,r,!0)},normalSlope:-1/0,setRelative:function(e,t,n,r,i){if(!r||r===this){e.x=(i?t.xo:t.x)+n;return}var a=i?t.xo:t.x,o=i?t.yo:t.y,s=a+n*r.x,c=o+n*r.y;e.x=s+(e.y-c)/r.normalSlope},slope:0,touch:function(e){e.xTouched=!0},touched:function(e){return e.xTouched},untouch:function(e){e.xTouched=!1}},YL={x:0,y:1,axis:`y`,distance:function(e,t,n,r){return(n?e.yo:e.y)-(r?t.yo:t.y)},interpolate:function(e,t,n,r){var i,a,o,s,c,l,u;if(!r||r===this){if(i=e.yo-t.yo,a=e.yo-n.yo,c=t.y-t.yo,l=n.y-n.yo,o=Math.abs(i),s=Math.abs(a),u=o+s,u===0){e.y=e.yo+(c+l)/2;return}e.y=e.yo+(c*s+l*o)/u;return}if(i=r.distance(e,t,!0,!0),a=r.distance(e,n,!0,!0),c=r.distance(t,t,!1,!0),l=r.distance(n,n,!1,!0),o=Math.abs(i),s=Math.abs(a),u=o+s,u===0){YL.setRelative(e,e,(c+l)/2,r,!0);return}YL.setRelative(e,e,(c*s+l*o)/u,r,!0)},normalSlope:0,setRelative:function(e,t,n,r,i){if(!r||r===this){e.y=(i?t.yo:t.y)+n;return}var a=i?t.xo:t.x,o=i?t.yo:t.y,s=a+n*r.x;e.y=o+n*r.y+r.normalSlope*(e.x-s)},slope:1/0,touch:function(e){e.yTouched=!0},touched:function(e){return e.yTouched},untouch:function(e){e.yTouched=!1}};Object.freeze(JL),Object.freeze(YL);function XL(e,t){this.x=e,this.y=t,this.axis=void 0,this.slope=t/e,this.normalSlope=-e/t,Object.freeze(this)}XL.prototype.distance=function(e,t,n,r){return this.x*JL.distance(e,t,n,r)+this.y*YL.distance(e,t,n,r)},XL.prototype.interpolate=function(e,t,n,r){var i,a,o=r.distance(e,t,!0,!0),s=r.distance(e,n,!0,!0),c,l,u;if(i=r.distance(t,t,!1,!0),a=r.distance(n,n,!1,!0),c=Math.abs(o),l=Math.abs(s),u=c+l,u===0){this.setRelative(e,e,(i+a)/2,r,!0);return}this.setRelative(e,e,(i*l+a*c)/u,r,!0)},XL.prototype.setRelative=function(e,t,n,r,i){r||=this;var a=i?t.xo:t.x,o=i?t.yo:t.y,s=a+n*r.x,c=o+n*r.y,l=r.normalSlope,u=this.slope,d=e.x,f=e.y;e.x=(u*d-l*s+c-f)/(u-l),e.y=u*(e.x-d)+f},XL.prototype.touch=function(e){e.xTouched=!0,e.yTouched=!0};function ZL(e,t){var n=Math.sqrt(e*e+t*t);return e/=n,t/=n,e===1&&t===0?JL:e===0&&t===1?YL:new XL(e,t)}function QL(e,t,n,r){this.x=this.xo=Math.round(e*64)/64,this.y=this.yo=Math.round(t*64)/64,this.lastPointOfContour=n,this.onCurve=r,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}QL.prototype.nextTouched=function(e){for(var t=this.nextPointOnContour;!e.touched(t)&&t!==this;)t=t.nextPointOnContour;return t},QL.prototype.prevTouched=function(e){for(var t=this.prevPointOnContour;!e.touched(t)&&t!==this;)t=t.prevPointOnContour;return t};var $L=Object.freeze(new QL(0,0)),eR={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function tR(e,t){switch(this.env=e,this.stack=[],this.prog=t,e){case`glyf`:this.zp0=this.zp1=this.zp2=1,this.rp0=this.rp1=this.rp2=0;case`prep`:this.fv=this.pv=this.dpv=JL,this.round=HL}}BL.prototype.exec=function(e,t){if(typeof t!=`number`)throw Error(`Point size is not a number!`);if(!(this._errorState>2)){var n=this.font,r=this._prepState;if(!r||r.ppem!==t){var i=this._fpgmState;if(!i){tR.prototype=eR,i=this._fpgmState=new tR(`fpgm`,n.tables.fpgm),i.funcs=[],i.font=n,exports.DEBUG&&(console.log(`---EXEC FPGM---`),i.step=-1);try{LL(i)}catch(e){console.log(`Hinting error in FPGM:`+e),this._errorState=3;return}}tR.prototype=i,r=this._prepState=new tR(`prep`,n.tables.prep),r.ppem=t;var a=n.tables.cvt;if(a)for(var o=r.cvt=Array(a.length),s=t/n.unitsPerEm,c=0;c<a.length;c++)o[c]=a[c]*s;else r.cvt=[];exports.DEBUG&&(console.log(`---EXEC PREP---`),r.step=-1);try{LL(r)}catch(e){this._errorState<2&&console.log(`Hinting error in PREP:`+e),this._errorState=2}}if(!(this._errorState>1))try{return RL(e,r)}catch(e){this._errorState<1&&(console.log(`Hinting error:`+e),console.log(`Note: further hinting errors are silenced`)),this._errorState=1;return}}},RL=function(e,t){var n=t.ppem/t.font.unitsPerEm,r=n,i=e.components,a,o,s;if(tR.prototype=t,!i)s=new tR(`glyf`,e.instructions),exports.DEBUG&&(console.log(`---EXEC GLYPH---`),s.step=-1),zL(e,s,n,r),o=s.gZone;else{var c=t.font;o=[],a=[];for(var l=0;l<i.length;l++){var u=i[l],d=c.glyphs.get(u.glyphIndex);s=new tR(`glyf`,d.instructions),exports.DEBUG&&(console.log(`---EXEC COMP `+l+`---`),s.step=-1),zL(d,s,n,r);for(var f=Math.round(u.dx*n),p=Math.round(u.dy*r),m=s.gZone,h=s.contours,g=0;g<m.length;g++){var _=m[g];_.xTouched=_.yTouched=!1,_.xo=_.x+=f,_.yo=_.y+=p}var v=o.length;o.push.apply(o,m);for(var y=0;y<h.length;y++)a.push(h[y]+v)}e.instructions&&!s.inhibitGridFit&&(s=new tR(`glyf`,e.instructions),s.gZone=s.z0=s.z1=s.z2=o,s.contours=a,o.push(new QL(0,0),new QL(Math.round(e.advanceWidth*n),0)),exports.DEBUG&&(console.log(`---EXEC COMPOSITE---`),s.step=-1),LL(s),o.length-=2)}return o},zL=function(e,t,n,r){for(var i=e.points||[],a=i.length,o=t.gZone=t.z0=t.z1=t.z2=[],s=t.contours=[],c,l=0;l<a;l++)c=i[l],o[l]=new QL(c.x*n,c.y*r,c.lastPointOfContour,c.onCurve);for(var u,d,f=0;f<a;f++)c=o[f],u||(u=c,s.push(f)),c.lastPointOfContour?(c.nextPointOnContour=u,u.prevPointOnContour=c,u=void 0):(d=o[f+1],c.nextPointOnContour=d,d.prevPointOnContour=c);if(!t.inhibitGridFit){if(exports.DEBUG){console.log(`PROCESSING GLYPH`,t.stack);for(var p=0;p<a;p++)console.log(p,o[p].x,o[p].y)}if(o.push(new QL(0,0),new QL(Math.round(e.advanceWidth*n),0)),LL(t),o.length-=2,exports.DEBUG){console.log(`FINISHED GLYPH`,t.stack);for(var m=0;m<a;m++)console.log(m,o[m].x,o[m].y)}}},LL=function(e){var t=e.prog;if(t){var n=t.length,r;for(e.ip=0;e.ip<n;e.ip++){if(exports.DEBUG&&e.step++,r=IL[t[e.ip]],!r)throw Error(`unknown instruction: 0x`+Number(t[e.ip]).toString(16));r(e)}}};function nR(e){for(var t=e.tZone=Array(e.gZone.length),n=0;n<t.length;n++)t[n]=new QL(0,0)}function rR(e,t){var n=e.prog,r=e.ip,i=1,a;do if(a=n[++r],a===88)i++;else if(a===89)i--;else if(a===64)r+=n[r+1]+1;else if(a===65)r+=2*n[r+1]+1;else if(a>=176&&a<=183)r+=a-176+1;else if(a>=184&&a<=191)r+=(a-184+1)*2;else if(t&&i===1&&a===27)break;while(i>0);e.ip=r}function iR(e,t){exports.DEBUG&&console.log(t.step,`SVTCA[`+e.axis+`]`),t.fv=t.pv=t.dpv=e}function aR(e,t){exports.DEBUG&&console.log(t.step,`SPVTCA[`+e.axis+`]`),t.pv=t.dpv=e}function oR(e,t){exports.DEBUG&&console.log(t.step,`SFVTCA[`+e.axis+`]`),t.fv=e}function sR(e,t){var n=t.stack,r=n.pop(),i=n.pop(),a=t.z2[r],o=t.z1[i];exports.DEBUG&&console.log(`SPVTL[`+e+`]`,r,i);var s,c;e?(s=a.y-o.y,c=o.x-a.x):(s=o.x-a.x,c=o.y-a.y),t.pv=t.dpv=ZL(s,c)}function cR(e,t){var n=t.stack,r=n.pop(),i=n.pop(),a=t.z2[r],o=t.z1[i];exports.DEBUG&&console.log(`SFVTL[`+e+`]`,r,i);var s,c;e?(s=a.y-o.y,c=o.x-a.x):(s=o.x-a.x,c=o.y-a.y),t.fv=ZL(s,c)}function lR(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.pv=e.dpv=ZL(r,n)}function uR(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.fv=ZL(r,n)}function dR(e){var t=e.stack,n=e.pv;exports.DEBUG&&console.log(e.step,`GPV[]`),t.push(n.x*16384),t.push(n.y*16384)}function fR(e){var t=e.stack,n=e.fv;exports.DEBUG&&console.log(e.step,`GFV[]`),t.push(n.x*16384),t.push(n.y*16384)}function pR(e){e.fv=e.pv,exports.DEBUG&&console.log(e.step,`SFVTPV[]`)}function mR(e){var t=e.stack,n=t.pop(),r=t.pop(),i=t.pop(),a=t.pop(),o=t.pop(),s=e.z0,c=e.z1,l=s[n],u=s[r],d=c[i],f=c[a],p=e.z2[o];exports.DEBUG&&console.log(`ISECT[], `,n,r,i,a,o);var m=l.x,h=l.y,g=u.x,_=u.y,v=d.x,y=d.y,b=f.x,x=f.y,S=(m-g)*(y-x)-(h-_)*(v-b),C=m*_-h*g,w=v*x-y*b;p.x=(C*(v-b)-w*(m-g))/S,p.y=(C*(y-x)-w*(h-_))/S}function hR(e){e.rp0=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP0[]`,e.rp0)}function gR(e){e.rp1=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP1[]`,e.rp1)}function _R(e){e.rp2=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP2[]`,e.rp2)}function vR(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP0[]`,t),e.zp0=t,t){case 0:e.tZone||nR(e),e.z0=e.tZone;break;case 1:e.z0=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function yR(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP1[]`,t),e.zp1=t,t){case 0:e.tZone||nR(e),e.z1=e.tZone;break;case 1:e.z1=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function bR(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP2[]`,t),e.zp2=t,t){case 0:e.tZone||nR(e),e.z2=e.tZone;break;case 1:e.z2=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function xR(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZPS[]`,t),e.zp0=e.zp1=e.zp2=t,t){case 0:e.tZone||nR(e),e.z0=e.z1=e.z2=e.tZone;break;case 1:e.z0=e.z1=e.z2=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function SR(e){e.loop=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SLOOP[]`,e.loop)}function CR(e){exports.DEBUG&&console.log(e.step,`RTG[]`),e.round=HL}function wR(e){exports.DEBUG&&console.log(e.step,`RTHG[]`),e.round=WL}function TR(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SMD[]`,t),e.minDis=t/64}function ER(e){exports.DEBUG&&console.log(e.step,`ELSE[]`),rR(e,!1)}function DR(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`JMPR[]`,t),e.ip+=t-1}function OR(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCVTCI[]`,t),e.cvCutIn=t/64}function kR(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DUP[]`),t.push(t[t.length-1])}function AR(e){exports.DEBUG&&console.log(e.step,`POP[]`),e.stack.pop()}function jR(e){exports.DEBUG&&console.log(e.step,`CLEAR[]`),e.stack.length=0}function MR(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SWAP[]`),t.push(n),t.push(r)}function NR(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DEPTH[]`),t.push(t.length)}function PR(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`LOOPCALL[]`,n,r);var i=e.ip,a=e.prog;e.prog=e.funcs[n];for(var o=0;o<r;o++)LL(e),exports.DEBUG&&console.log(++e.step,o+1<r?`next loopcall`:`done loopcall`,o);e.ip=i,e.prog=a}function FR(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`CALL[]`,t);var n=e.ip,r=e.prog;e.prog=e.funcs[t],LL(e),e.ip=n,e.prog=r,exports.DEBUG&&console.log(++e.step,`returning from`,t)}function IR(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CINDEX[]`,n),t.push(t[t.length-n])}function LR(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`MINDEX[]`,n),t.push(t.splice(t.length-n,1)[0])}function RR(e){if(e.env!==`fpgm`)throw Error(`FDEF not allowed here`);var t=e.stack,n=e.prog,r=e.ip,i=t.pop(),a=r;for(exports.DEBUG&&console.log(e.step,`FDEF[]`,i);n[++r]!==45;);e.ip=r,e.funcs[i]=n.slice(a+1,r)}function zR(e,t){var n=t.stack.pop(),r=t.z0[n],i=t.fv,a=t.pv;exports.DEBUG&&console.log(t.step,`MDAP[`+e+`]`,n);var o=a.distance(r,$L);e&&(o=t.round(o)),i.setRelative(r,$L,o,a),i.touch(r),t.rp0=t.rp1=n}function BR(e,t){var n=t.z2,r=n.length-2,i,a,o;exports.DEBUG&&console.log(t.step,`IUP[`+e.axis+`]`);for(var s=0;s<r;s++)i=n[s],!e.touched(i)&&(a=i.prevTouched(e),a!==i&&(o=i.nextTouched(e),a===o&&e.setRelative(i,i,e.distance(a,a,!1,!0),e,!0),e.interpolate(i,a,o,e)))}function VR(e,t){for(var n=t.stack,r=e?t.rp1:t.rp2,i=(e?t.z0:t.z1)[r],a=t.fv,o=t.pv,s=t.loop,c=t.z2;s--;){var l=n.pop(),u=c[l],d=o.distance(i,i,!1,!0);a.setRelative(u,u,d,o),a.touch(u),exports.DEBUG&&console.log(t.step,(t.loop>1?`loop `+(t.loop-s)+`: `:``)+`SHP[`+(e?`rp1`:`rp2`)+`]`,l)}t.loop=1}function HR(e,t){var n=t.stack,r=e?t.rp1:t.rp2,i=(e?t.z0:t.z1)[r],a=t.fv,o=t.pv,s=n.pop(),c=t.z2[t.contours[s]],l=c;exports.DEBUG&&console.log(t.step,`SHC[`+e+`]`,s);var u=o.distance(i,i,!1,!0);do l!==i&&a.setRelative(l,l,u,o),l=l.nextPointOnContour;while(l!==c)}function UR(e,t){var n=t.stack,r=e?t.rp1:t.rp2,i=(e?t.z0:t.z1)[r],a=t.fv,o=t.pv,s=n.pop();exports.DEBUG&&console.log(t.step,`SHZ[`+e+`]`,s);var c;switch(s){case 0:c=t.tZone;break;case 1:c=t.gZone;break;default:throw Error(`Invalid zone`)}for(var l,u=o.distance(i,i,!1,!0),d=c.length-2,f=0;f<d;f++)l=c[f],a.setRelative(l,l,u,o)}function WR(e){for(var t=e.stack,n=e.loop,r=e.fv,i=t.pop()/64,a=e.z2;n--;){var o=t.pop(),s=a[o];exports.DEBUG&&console.log(e.step,(e.loop>1?`loop `+(e.loop-n)+`: `:``)+`SHPIX[]`,o,i),r.setRelative(s,s,i),r.touch(s)}e.loop=1}function GR(e){for(var t=e.stack,n=e.rp1,r=e.rp2,i=e.loop,a=e.z0[n],o=e.z1[r],s=e.fv,c=e.dpv,l=e.z2;i--;){var u=t.pop(),d=l[u];exports.DEBUG&&console.log(e.step,(e.loop>1?`loop `+(e.loop-i)+`: `:``)+`IP[]`,u,n,`<->`,r),s.interpolate(d,a,o,c),s.touch(d)}e.loop=1}function KR(e,t){var n=t.stack,r=n.pop()/64,i=n.pop(),a=t.z1[i],o=t.z0[t.rp0],s=t.fv,c=t.pv;s.setRelative(a,o,r,c),s.touch(a),exports.DEBUG&&console.log(t.step,`MSIRP[`+e+`]`,r,i),t.rp1=t.rp0,t.rp2=i,e&&(t.rp0=i)}function qR(e){for(var t=e.stack,n=e.rp0,r=e.z0[n],i=e.loop,a=e.fv,o=e.pv,s=e.z1;i--;){var c=t.pop(),l=s[c];exports.DEBUG&&console.log(e.step,(e.loop>1?`loop `+(e.loop-i)+`: `:``)+`ALIGNRP[]`,c),a.setRelative(l,r,0,o),a.touch(l)}e.loop=1}function JR(e){exports.DEBUG&&console.log(e.step,`RTDG[]`),e.round=UL}function YR(e,t){var n=t.stack,r=n.pop(),i=n.pop(),a=t.z0[i],o=t.fv,s=t.pv,c=t.cvt[r];exports.DEBUG&&console.log(t.step,`MIAP[`+e+`]`,r,`(`,c,`)`,i);var l=s.distance(a,$L);e&&(Math.abs(l-c)<t.cvCutIn&&(l=c),l=t.round(l)),o.setRelative(a,$L,l,s),t.zp0===0&&(a.xo=a.x,a.yo=a.y),o.touch(a),t.rp0=t.rp1=i}function XR(e){var t=e.prog,n=e.ip,r=e.stack,i=t[++n];exports.DEBUG&&console.log(e.step,`NPUSHB[]`,i);for(var a=0;a<i;a++)r.push(t[++n]);e.ip=n}function ZR(e){var t=e.ip,n=e.prog,r=e.stack,i=n[++t];exports.DEBUG&&console.log(e.step,`NPUSHW[]`,i);for(var a=0;a<i;a++){var o=n[++t]<<8|n[++t];o&32768&&(o=-((o^65535)+1)),r.push(o)}e.ip=t}function QR(e){var t=e.stack,n=e.store;n||=e.store=[];var r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,`WS`,r,i),n[i]=r}function $R(e){var t=e.stack,n=e.store,r=t.pop();exports.DEBUG&&console.log(e.step,`RS`,r);var i=n&&n[r]||0;t.push(i)}function ez(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`WCVTP`,n,r),e.cvt[r]=n/64}function tz(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`RCVT`,n),t.push(e.cvt[n]*64)}function nz(e,t){var n=t.stack,r=n.pop(),i=t.z2[r];exports.DEBUG&&console.log(t.step,`GC[`+e+`]`,r),n.push(t.dpv.distance(i,$L,e,!1)*64)}function rz(e,t){var n=t.stack,r=n.pop(),i=n.pop(),a=t.z1[r],o=t.z0[i],s=t.dpv.distance(o,a,e,e);exports.DEBUG&&console.log(t.step,`MD[`+e+`]`,r,i,`->`,s),t.stack.push(Math.round(s*64))}function iz(e){exports.DEBUG&&console.log(e.step,`MPPEM[]`),e.stack.push(e.ppem)}function az(e){exports.DEBUG&&console.log(e.step,`FLIPON[]`),e.autoFlip=!0}function oz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`LT[]`,n,r),t.push(+(r<n))}function sz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`LTEQ[]`,n,r),t.push(+(r<=n))}function cz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`GT[]`,n,r),t.push(+(r>n))}function lz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`GTEQ[]`,n,r),t.push(+(r>=n))}function uz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`EQ[]`,n,r),t.push(+(n===r))}function dz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`NEQ[]`,n,r),t.push(n===r?0:1)}function fz(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`ODD[]`,n),t.push(Math.trunc(n)%2?1:0)}function pz(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`EVEN[]`,n),t.push(Math.trunc(n)%2?0:1)}function mz(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`IF[]`,t),t||(rR(e,!0),exports.DEBUG&&console.log(e.step,`EIF[]`))}function hz(e){exports.DEBUG&&console.log(e.step,`EIF[]`)}function gz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`AND[]`,n,r),t.push(n&&r?1:0)}function _z(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`OR[]`,n,r),t.push(n||r?1:0)}function vz(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NOT[]`,n),t.push(+!n)}function yz(e,t){var n=t.stack,r=n.pop(),i=t.fv,a=t.pv,o=t.ppem,s=t.deltaBase+(e-1)*16,c=t.deltaShift,l=t.z0;exports.DEBUG&&console.log(t.step,`DELTAP[`+e+`]`,r,n);for(var u=0;u<r;u++){var d=n.pop(),f=n.pop();if(s+((f&240)>>4)===o){var p=(f&15)-8;p>=0&&p++,exports.DEBUG&&console.log(t.step,`DELTAPFIX`,d,`by`,p*c);var m=l[d];i.setRelative(m,m,p*c,a)}}}function bz(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDB[]`,t),e.deltaBase=t}function xz(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDS[]`,t),e.deltaShift=.5**t}function Sz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`ADD[]`,n,r),t.push(r+n)}function Cz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SUB[]`,n,r),t.push(r-n)}function wz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`DIV[]`,n,r),t.push(r*64/n)}function Tz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`MUL[]`,n,r),t.push(r*n/64)}function Ez(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`ABS[]`,n),t.push(Math.abs(n))}function Dz(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NEG[]`,n),t.push(-n)}function Oz(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`FLOOR[]`,n),t.push(Math.floor(n/64)*64)}function kz(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CEILING[]`,n),t.push(Math.ceil(n/64)*64)}function Az(e,t){var n=t.stack,r=n.pop();exports.DEBUG&&console.log(t.step,`ROUND[]`),n.push(t.round(r/64)*64)}function jz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`WCVTF[]`,n,r),e.cvt[r]=n*e.ppem/e.font.unitsPerEm}function Mz(e,t){var n=t.stack,r=n.pop(),i=t.ppem,a=t.deltaBase+(e-1)*16,o=t.deltaShift;exports.DEBUG&&console.log(t.step,`DELTAC[`+e+`]`,r,n);for(var s=0;s<r;s++){var c=n.pop(),l=n.pop();if(a+((l&240)>>4)===i){var u=(l&15)-8;u>=0&&u++;var d=u*o;exports.DEBUG&&console.log(t.step,`DELTACFIX`,c,`by`,d),t.cvt[c]+=d}}}function Nz(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SROUND[]`,t),e.round=qL;var n;switch(t&192){case 0:n=.5;break;case 64:n=1;break;case 128:n=2;break;default:throw Error(`invalid SROUND value`)}switch(e.srPeriod=n,t&48){case 0:e.srPhase=0;break;case 16:e.srPhase=.25*n;break;case 32:e.srPhase=.5*n;break;case 48:e.srPhase=.75*n;break;default:throw Error(`invalid SROUND value`)}t&=15,t===0?e.srThreshold=0:e.srThreshold=(t/8-.5)*n}function Pz(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`S45ROUND[]`,t),e.round=qL;var n;switch(t&192){case 0:n=Math.sqrt(2)/2;break;case 64:n=Math.sqrt(2);break;case 128:n=2*Math.sqrt(2);break;default:throw Error(`invalid S45ROUND value`)}switch(e.srPeriod=n,t&48){case 0:e.srPhase=0;break;case 16:e.srPhase=.25*n;break;case 32:e.srPhase=.5*n;break;case 48:e.srPhase=.75*n;break;default:throw Error(`invalid S45ROUND value`)}t&=15,t===0?e.srThreshold=0:e.srThreshold=(t/8-.5)*n}function Fz(e){exports.DEBUG&&console.log(e.step,`ROFF[]`),e.round=VL}function Iz(e){exports.DEBUG&&console.log(e.step,`RUTG[]`),e.round=GL}function Lz(e){exports.DEBUG&&console.log(e.step,`RDTG[]`),e.round=KL}function Rz(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANCTRL[]`,t)}function zz(e,t){var n=t.stack,r=n.pop(),i=n.pop(),a=t.z2[r],o=t.z1[i];exports.DEBUG&&console.log(t.step,`SDPVTL[`+e+`]`,r,i);var s,c;e?(s=a.y-o.y,c=o.x-a.x):(s=o.x-a.x,c=o.y-a.y),t.dpv=ZL(s,c)}function Bz(e){var t=e.stack,n=t.pop(),r=0;exports.DEBUG&&console.log(e.step,`GETINFO[]`,n),n&1&&(r=35),n&32&&(r|=4096),t.push(r)}function Vz(e){var t=e.stack,n=t.pop(),r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,`ROLL[]`),t.push(r),t.push(n),t.push(i)}function Hz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`MAX[]`,n,r),t.push(Math.max(r,n))}function Uz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`MIN[]`,n,r),t.push(Math.min(r,n))}function Wz(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANTYPE[]`,t)}function Gz(e){var t=e.stack.pop(),n=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`INSTCTRL[]`,t,n),t){case 1:e.inhibitGridFit=!!n;return;case 2:e.ignoreCvt=!!n;return;default:throw Error(`invalid INSTCTRL[] selector`)}}function Kz(e,t){var n=t.stack,r=t.prog,i=t.ip;exports.DEBUG&&console.log(t.step,`PUSHB[`+e+`]`);for(var a=0;a<e;a++)n.push(r[++i]);t.ip=i}function qz(e,t){var n=t.ip,r=t.prog,i=t.stack;exports.DEBUG&&console.log(t.ip,`PUSHW[`+e+`]`);for(var a=0;a<e;a++){var o=r[++n]<<8|r[++n];o&32768&&(o=-((o^65535)+1)),i.push(o)}t.ip=n}function Q(e,t,n,r,i,a){var o=a.stack,s=e&&o.pop(),c=o.pop(),l=a.rp0,u=a.z0[l],d=a.z1[c],f=a.minDis,p=a.fv,m=a.dpv,h,g=h=m.distance(d,u,!0,!0),_=g>=0?1:-1,v;g=Math.abs(g),e&&(v=a.cvt[s],r&&Math.abs(g-v)<a.cvCutIn&&(g=v)),n&&g<f&&(g=f),r&&(g=a.round(g)),p.setRelative(d,u,_*g,m),p.touch(d),exports.DEBUG&&console.log(a.step,(e?`MIRP[`:`MDRP[`)+(t?`M`:`m`)+(n?`>`:`_`)+(r?`R`:`_`)+(i===0?`Gr`:i===1?`Bl`:i===2?`Wh`:``)+`]`,e?s+`(`+a.cvt[s]+`,`+v+`)`:``,c,`(d =`,h,`->`,_*g,`)`),a.rp1=a.rp0,a.rp2=c,t&&(a.rp0=c)}IL=[iR.bind(void 0,YL),iR.bind(void 0,JL),aR.bind(void 0,YL),aR.bind(void 0,JL),oR.bind(void 0,YL),oR.bind(void 0,JL),sR.bind(void 0,0),sR.bind(void 0,1),cR.bind(void 0,0),cR.bind(void 0,1),lR,uR,dR,fR,pR,mR,hR,gR,_R,vR,yR,bR,xR,SR,CR,wR,TR,ER,DR,OR,void 0,void 0,kR,AR,jR,MR,NR,IR,LR,void 0,void 0,void 0,PR,FR,RR,void 0,zR.bind(void 0,0),zR.bind(void 0,1),BR.bind(void 0,YL),BR.bind(void 0,JL),VR.bind(void 0,0),VR.bind(void 0,1),HR.bind(void 0,0),HR.bind(void 0,1),UR.bind(void 0,0),UR.bind(void 0,1),WR,GR,KR.bind(void 0,0),KR.bind(void 0,1),qR,JR,YR.bind(void 0,0),YR.bind(void 0,1),XR,ZR,QR,$R,ez,tz,nz.bind(void 0,0),nz.bind(void 0,1),void 0,rz.bind(void 0,0),rz.bind(void 0,1),iz,void 0,az,void 0,void 0,oz,sz,cz,lz,uz,dz,fz,pz,mz,hz,gz,_z,vz,yz.bind(void 0,1),bz,xz,Sz,Cz,wz,Tz,Ez,Dz,Oz,kz,Az.bind(void 0,0),Az.bind(void 0,1),Az.bind(void 0,2),Az.bind(void 0,3),void 0,void 0,void 0,void 0,jz,yz.bind(void 0,2),yz.bind(void 0,3),Mz.bind(void 0,1),Mz.bind(void 0,2),Mz.bind(void 0,3),Nz,Pz,void 0,void 0,Fz,void 0,Iz,Lz,AR,AR,void 0,void 0,void 0,void 0,void 0,Rz,zz.bind(void 0,0),zz.bind(void 0,1),Bz,void 0,Vz,Hz,Uz,Wz,Gz,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,Kz.bind(void 0,1),Kz.bind(void 0,2),Kz.bind(void 0,3),Kz.bind(void 0,4),Kz.bind(void 0,5),Kz.bind(void 0,6),Kz.bind(void 0,7),Kz.bind(void 0,8),qz.bind(void 0,1),qz.bind(void 0,2),qz.bind(void 0,3),qz.bind(void 0,4),qz.bind(void 0,5),qz.bind(void 0,6),qz.bind(void 0,7),qz.bind(void 0,8),Q.bind(void 0,0,0,0,0,0),Q.bind(void 0,0,0,0,0,1),Q.bind(void 0,0,0,0,0,2),Q.bind(void 0,0,0,0,0,3),Q.bind(void 0,0,0,0,1,0),Q.bind(void 0,0,0,0,1,1),Q.bind(void 0,0,0,0,1,2),Q.bind(void 0,0,0,0,1,3),Q.bind(void 0,0,0,1,0,0),Q.bind(void 0,0,0,1,0,1),Q.bind(void 0,0,0,1,0,2),Q.bind(void 0,0,0,1,0,3),Q.bind(void 0,0,0,1,1,0),Q.bind(void 0,0,0,1,1,1),Q.bind(void 0,0,0,1,1,2),Q.bind(void 0,0,0,1,1,3),Q.bind(void 0,0,1,0,0,0),Q.bind(void 0,0,1,0,0,1),Q.bind(void 0,0,1,0,0,2),Q.bind(void 0,0,1,0,0,3),Q.bind(void 0,0,1,0,1,0),Q.bind(void 0,0,1,0,1,1),Q.bind(void 0,0,1,0,1,2),Q.bind(void 0,0,1,0,1,3),Q.bind(void 0,0,1,1,0,0),Q.bind(void 0,0,1,1,0,1),Q.bind(void 0,0,1,1,0,2),Q.bind(void 0,0,1,1,0,3),Q.bind(void 0,0,1,1,1,0),Q.bind(void 0,0,1,1,1,1),Q.bind(void 0,0,1,1,1,2),Q.bind(void 0,0,1,1,1,3),Q.bind(void 0,1,0,0,0,0),Q.bind(void 0,1,0,0,0,1),Q.bind(void 0,1,0,0,0,2),Q.bind(void 0,1,0,0,0,3),Q.bind(void 0,1,0,0,1,0),Q.bind(void 0,1,0,0,1,1),Q.bind(void 0,1,0,0,1,2),Q.bind(void 0,1,0,0,1,3),Q.bind(void 0,1,0,1,0,0),Q.bind(void 0,1,0,1,0,1),Q.bind(void 0,1,0,1,0,2),Q.bind(void 0,1,0,1,0,3),Q.bind(void 0,1,0,1,1,0),Q.bind(void 0,1,0,1,1,1),Q.bind(void 0,1,0,1,1,2),Q.bind(void 0,1,0,1,1,3),Q.bind(void 0,1,1,0,0,0),Q.bind(void 0,1,1,0,0,1),Q.bind(void 0,1,1,0,0,2),Q.bind(void 0,1,1,0,0,3),Q.bind(void 0,1,1,0,1,0),Q.bind(void 0,1,1,0,1,1),Q.bind(void 0,1,1,0,1,2),Q.bind(void 0,1,1,0,1,3),Q.bind(void 0,1,1,1,0,0),Q.bind(void 0,1,1,1,0,1),Q.bind(void 0,1,1,1,0,2),Q.bind(void 0,1,1,1,0,3),Q.bind(void 0,1,1,1,1,0),Q.bind(void 0,1,1,1,1,1),Q.bind(void 0,1,1,1,1,2),Q.bind(void 0,1,1,1,1,3)];function Jz(e){this.char=e,this.state={},this.activeState=null}function Yz(e,t,n){this.contextName=n,this.startIndex=e,this.endOffset=t}function Xz(e,t,n){this.contextName=e,this.openRange=null,this.ranges=[],this.checkStart=t,this.checkEnd=n}function Zz(e,t){this.context=e,this.index=t,this.length=e.length,this.current=e[t],this.backtrack=e.slice(0,t),this.lookahead=e.slice(t+1)}function Qz(e){this.eventId=e,this.subscribers=[]}function $z(e){var t=this,n=[`start`,`end`,`next`,`newToken`,`contextStart`,`contextEnd`,`insertToken`,`removeToken`,`removeRange`,`replaceToken`,`replaceRange`,`composeRUD`,`updateContextsRanges`];n.forEach(function(e){Object.defineProperty(t.events,e,{value:new Qz(e)})}),e&&n.forEach(function(n){var r=e[n];typeof r==`function`&&t.events[n].subscribe(r)}),[`insertToken`,`removeToken`,`removeRange`,`replaceToken`,`replaceRange`,`composeRUD`].forEach(function(e){t.events[e].subscribe(t.updateContextsRanges)})}function eB(e){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],$z.call(this,e)}Jz.prototype.setState=function(e,t){return this.state[e]=t,this.activeState={key:e,value:this.state[e]},this.activeState},Jz.prototype.getState=function(e){return this.state[e]||null},eB.prototype.inboundIndex=function(e){return e>=0&&e<this.tokens.length},eB.prototype.composeRUD=function(e){var t=this,n=!0,r=e.map(function(e){return t[e[0]].apply(t,e.slice(1).concat(n))}),i=function(e){return typeof e==`object`&&e.hasOwnProperty(`FAIL`)};if(r.every(i))return{FAIL:`composeRUD: one or more operations hasn't completed successfully`,report:r.filter(i)};this.dispatch(`composeRUD`,[r.filter(function(e){return!i(e)})])},eB.prototype.replaceRange=function(e,t,n,r){t=t===null?this.tokens.length:t;var i=n.every(function(e){return e instanceof Jz});if(!isNaN(e)&&this.inboundIndex(e)&&i){var a=this.tokens.splice.apply(this.tokens,[e,t].concat(n));return r||this.dispatch(`replaceToken`,[e,t,n]),[a,n]}else return{FAIL:`replaceRange: invalid tokens or startIndex.`}},eB.prototype.replaceToken=function(e,t,n){if(!isNaN(e)&&this.inboundIndex(e)&&t instanceof Jz){var r=this.tokens.splice(e,1,t);return n||this.dispatch(`replaceToken`,[e,t]),[r[0],t]}else return{FAIL:`replaceToken: invalid token or index.`}},eB.prototype.removeRange=function(e,t,n){t=isNaN(t)?this.tokens.length:t;var r=this.tokens.splice(e,t);return n||this.dispatch(`removeRange`,[r,e,t]),r},eB.prototype.removeToken=function(e,t){if(!isNaN(e)&&this.inboundIndex(e)){var n=this.tokens.splice(e,1);return t||this.dispatch(`removeToken`,[n,e]),n}else return{FAIL:`removeToken: invalid token index.`}},eB.prototype.insertToken=function(e,t,n){return e.every(function(e){return e instanceof Jz})?(this.tokens.splice.apply(this.tokens,[t,0].concat(e)),n||this.dispatch(`insertToken`,[e,t]),e):{FAIL:`insertToken: invalid token(s).`}},eB.prototype.registerModifier=function(e,t,n){this.events.newToken.subscribe(function(r,i){var a=[r,i],o=t===null||t.apply(this,a)===!0,s=[r,i];if(o){var c=n.apply(this,s);r.setState(e,c)}}),this.registeredModifiers.push(e)},Qz.prototype.subscribe=function(e){return typeof e==`function`?this.subscribers.push(e)-1:{FAIL:`invalid '`+this.eventId+`' event handler`}},Qz.prototype.unsubscribe=function(e){this.subscribers.splice(e,1)},Zz.prototype.setCurrentIndex=function(e){this.index=e,this.current=this.context[e],this.backtrack=this.context.slice(0,e),this.lookahead=this.context.slice(e+1)},Zz.prototype.get=function(e){switch(!0){case e===0:return this.current;case e<0&&Math.abs(e)<=this.backtrack.length:return this.backtrack.slice(e)[0];case e>0&&e<=this.lookahead.length:return this.lookahead[e-1];default:return null}},eB.prototype.rangeToText=function(e){if(e instanceof Yz)return this.getRangeTokens(e).map(function(e){return e.char}).join(``)},eB.prototype.getText=function(){return this.tokens.map(function(e){return e.char}).join(``)},eB.prototype.getContext=function(e){return this.registeredContexts[e]||null},eB.prototype.on=function(e,t){var n=this.events[e];return n?n.subscribe(t):null},eB.prototype.dispatch=function(e,t){var n=this,r=this.events[e];r instanceof Qz&&r.subscribers.forEach(function(e){e.apply(n,t||[])})},eB.prototype.registerContextChecker=function(e,t,n){if(this.getContext(e))return{FAIL:`context name '`+e+`' is already registered.`};if(typeof t!=`function`)return{FAIL:`missing context start check.`};if(typeof n!=`function`)return{FAIL:`missing context end check.`};var r=new Xz(e,t,n);return this.registeredContexts[e]=r,this.contextCheckers.push(r),r},eB.prototype.getRangeTokens=function(e){var t=e.startIndex+e.endOffset;return[].concat(this.tokens.slice(e.startIndex,t))},eB.prototype.getContextRanges=function(e){var t=this.getContext(e);return t?t.ranges:{FAIL:`context checker '`+e+`' is not registered.`}},eB.prototype.resetContextsRanges=function(){var e=this.registeredContexts;for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];n.ranges=[]}},eB.prototype.updateContextsRanges=function(){this.resetContextsRanges();for(var e=this.tokens.map(function(e){return e.char}),t=0;t<e.length;t++){var n=new Zz(e,t);this.runContextCheck(n)}this.dispatch(`updateContextsRanges`,[this.registeredContexts])},eB.prototype.setEndOffset=function(e,t){var n=this.getContext(t).openRange.startIndex,r=new Yz(n,e,t),i=this.getContext(t).ranges;return r.rangeId=t+`.`+i.length,i.push(r),this.getContext(t).openRange=null,r},eB.prototype.runContextCheck=function(e){var t=this,n=e.index;this.contextCheckers.forEach(function(r){var i=r.contextName,a=t.getContext(i).openRange;if(!a&&r.checkStart(e)&&(a=new Yz(n,null,i),t.getContext(i).openRange=a,t.dispatch(`contextStart`,[i,n])),a&&r.checkEnd(e)){var o=n-a.startIndex+1,s=t.setEndOffset(o,i);t.dispatch(`contextEnd`,[i,s])}})},eB.prototype.tokenize=function(e){this.tokens=[],this.resetContextsRanges();var t=Array.from(e);this.dispatch(`start`);for(var n=0;n<t.length;n++){var r=t[n],i=new Zz(t,n);this.dispatch(`next`,[i]),this.runContextCheck(i);var a=new Jz(r);this.tokens.push(a),this.dispatch(`newToken`,[a,i])}return this.dispatch(`end`,[this.tokens]),this.tokens};function tB(e){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(e)}function nB(e){return/[\u0630\u0690\u0621\u0631\u0661\u0671\u0622\u0632\u0672\u0692\u06C2\u0623\u0673\u0693\u06C3\u0624\u0694\u06C4\u0625\u0675\u0695\u06C5\u06E5\u0676\u0696\u06C6\u0627\u0677\u0697\u06C7\u0648\u0688\u0698\u06C8\u0689\u0699\u06C9\u068A\u06CA\u066B\u068B\u06CB\u068C\u068D\u06CD\u06FD\u068E\u06EE\u06FE\u062F\u068F\u06CF\u06EF]/.test(e)}function rB(e){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(e)}function iB(e){return/[A-z]/.test(e)}function aB(e){return/\s/.test(e)}function oB(e){this.font=e,this.features={}}function sB(e){this.id=e.id,this.tag=e.tag,this.substitution=e.substitution}function cB(e,t){if(!e)return-1;switch(t.format){case 1:return t.glyphs.indexOf(e);case 2:for(var n=t.ranges,r=0;r<n.length;r++){var i=n[r];if(e>=i.start&&e<=i.end){var a=e-i.start;return i.index+a}}break;default:return-1}return-1}function lB(e,t){return cB(e,t.coverage)===-1?null:e+t.deltaGlyphId}function uB(e,t){var n=cB(e,t.coverage);return n===-1?null:t.substitute[n]}function dB(e,t){for(var n=[],r=0;r<e.length;r++){var i=e[r],a=t.current;a=Array.isArray(a)?a[0]:a;var o=cB(a,i);o!==-1&&n.push(o)}return n.length===e.length?n:-1}function fB(e,t){var n=t.inputCoverage.length+t.lookaheadCoverage.length+t.backtrackCoverage.length;if(e.context.length<n)return[];var r=dB(t.inputCoverage,e);if(r===-1)return[];var i=t.inputCoverage.length-1;if(e.lookahead.length<t.lookaheadCoverage.length)return[];for(var a=e.lookahead.slice(i);a.length&&rB(a[0].char);)a.shift();var o=new Zz(a,0),s=dB(t.lookaheadCoverage,o),c=[].concat(e.backtrack);for(c.reverse();c.length&&rB(c[0].char);)c.shift();if(c.length<t.backtrackCoverage.length)return[];var l=new Zz(c,0),u=dB(t.backtrackCoverage,l),d=r.length===t.inputCoverage.length&&s.length===t.lookaheadCoverage.length&&u.length===t.backtrackCoverage.length,f=[];if(d)for(var p=0;p<t.lookupRecords.length;p++)for(var m=t.lookupRecords[p].lookupListIndex,h=this.getLookupByIndex(m),g=0;g<h.subtables.length;g++){var _=h.subtables[g],v=this.getLookupMethod(h,_);if(this.getSubstitutionType(h,_)===`12`)for(var y=0;y<r.length;y++){var b=v(e.get(y));b&&f.push(b)}}return f}function pB(e,t){var n=e.current,r=cB(n,t.coverage);if(r===-1)return null;for(var i,a=t.ligatureSets[r],o=0;o<a.length;o++){i=a[o];for(var s=0;s<i.components.length&&e.lookahead[s]===i.components[s];s++)if(s===i.components.length-1)return i}return null}function mB(e,t){var n=cB(e,t.coverage);return n===-1?null:t.sequences[n]}oB.prototype.getDefaultScriptFeaturesIndexes=function(){for(var e=this.font.tables.gsub.scripts,t=0;t<e.length;t++){var n=e[t];if(n.tag===`DFLT`)return n.script.defaultLangSys.featureIndexes}return[]},oB.prototype.getScriptFeaturesIndexes=function(e){if(!this.font.tables.gsub)return[];if(!e)return this.getDefaultScriptFeaturesIndexes();for(var t=this.font.tables.gsub.scripts,n=0;n<t.length;n++){var r=t[n];if(r.tag===e&&r.script.defaultLangSys)return r.script.defaultLangSys.featureIndexes;var i=r.langSysRecords;if(i)for(var a=0;a<i.length;a++){var o=i[a];if(o.tag===e)return o.langSys.featureIndexes}}return this.getDefaultScriptFeaturesIndexes()},oB.prototype.mapTagsToFeatures=function(e,t){for(var n={},r=0;r<e.length;r++){var i=e[r].tag;n[i]=e[r].feature}this.features[t].tags=n},oB.prototype.getScriptFeatures=function(e){var t=this.features[e];if(this.features.hasOwnProperty(e))return t;var n=this.getScriptFeaturesIndexes(e);if(!n)return null;var r=this.font.tables.gsub;return t=n.map(function(e){return r.features[e]}),this.features[e]=t,this.mapTagsToFeatures(t,e),t},oB.prototype.getSubstitutionType=function(e,t){return e.lookupType.toString()+t.substFormat.toString()},oB.prototype.getLookupMethod=function(e,t){var n=this;switch(this.getSubstitutionType(e,t)){case`11`:return function(e){return lB.apply(n,[e,t])};case`12`:return function(e){return uB.apply(n,[e,t])};case`63`:return function(e){return fB.apply(n,[e,t])};case`41`:return function(e){return pB.apply(n,[e,t])};case`21`:return function(e){return mB.apply(n,[e,t])};default:throw Error(`lookupType: `+e.lookupType+` - substFormat: `+t.substFormat+` is not yet supported`)}},oB.prototype.lookupFeature=function(e){var t=e.contextParams,n=t.index,r=this.getFeature({tag:e.tag,script:e.script});if(!r)return Error(`font '`+this.font.names.fullName.en+`' doesn't support feature '`+e.tag+`' for script '`+e.script+`'.`);for(var i=this.getFeatureLookups(r),a=[].concat(t.context),o=0;o<i.length;o++)for(var s=i[o],c=this.getLookupSubtables(s),l=0;l<c.length;l++){var u=c[l],d=this.getSubstitutionType(s,u),f=this.getLookupMethod(s,u),p=void 0;switch(d){case`11`:p=f(t.current),p&&a.splice(n,1,new sB({id:11,tag:e.tag,substitution:p}));break;case`12`:p=f(t.current),p&&a.splice(n,1,new sB({id:12,tag:e.tag,substitution:p}));break;case`63`:p=f(t),Array.isArray(p)&&p.length&&a.splice(n,1,new sB({id:63,tag:e.tag,substitution:p}));break;case`41`:p=f(t),p&&a.splice(n,1,new sB({id:41,tag:e.tag,substitution:p}));break;case`21`:p=f(t.current),p&&a.splice(n,1,new sB({id:21,tag:e.tag,substitution:p}));break}t=new Zz(a,n),!(Array.isArray(p)&&!p.length)&&(p=null)}return a.length?a:null},oB.prototype.supports=function(e){if(!e.script)return!1;this.getScriptFeatures(e.script);var t=this.features.hasOwnProperty(e.script);if(!e.tag)return t;var n=this.features[e.script].some(function(t){return t.tag===e.tag});return t&&n},oB.prototype.getLookupSubtables=function(e){return e.subtables||null},oB.prototype.getLookupByIndex=function(e){return this.font.tables.gsub.lookups[e]||null},oB.prototype.getFeatureLookups=function(e){return e.lookupListIndexes.map(this.getLookupByIndex.bind(this))},oB.prototype.getFeature=function(e){if(!this.font)return{FAIL:`No font was found`};this.features.hasOwnProperty(e.script)||this.getScriptFeatures(e.script);var t=this.features[e.script];return t?t.tags[e.tag]?this.features[e.script].tags[e.tag]:null:{FAIL:`No feature for script `+e.script}};function hB(e){var t=e.current,n=e.get(-1);return n===null&&tB(t)||!tB(n)&&tB(t)}function gB(e){var t=e.get(1);return t===null||!tB(t)}var _B={startCheck:hB,endCheck:gB};function vB(e){var t=e.current,n=e.get(-1);return(tB(t)||rB(t))&&!tB(n)}function yB(e){var t=e.get(1);switch(!0){case t===null:return!0;case!tB(t)&&!rB(t):var n=aB(t);if(!n)return!0;if(n){var r=!1;if(r=e.lookahead.some(function(e){return tB(e)||rB(e)}),!r)return!0}break;default:return!1}}var bB={startCheck:vB,endCheck:yB};function xB(e,t,n){t[n].setState(e.tag,e.substitution)}function SB(e,t,n){t[n].setState(e.tag,e.substitution)}function CB(e,t,n){e.substitution.forEach(function(r,i){t[n+i].setState(e.tag,r)})}function wB(e,t,n){var r=t[n];r.setState(e.tag,e.substitution.ligGlyph);for(var i=e.substitution.components.length,a=0;a<i;a++)r=t[n+a+1],r.setState(`deleted`,!0)}var TB={11:xB,12:SB,63:CB,41:wB};function EB(e,t,n){e instanceof sB&&TB[e.id]&&TB[e.id](e,t,n)}function DB(e){for(var t=[].concat(e.backtrack),n=t.length-1;n>=0;n--){var r=t[n],i=nB(r),a=rB(r);if(!i&&!a)return!0;if(i)return!1}return!1}function OB(e){if(nB(e.current))return!1;for(var t=0;t<e.lookahead.length;t++){var n=e.lookahead[t];if(!rB(n))return!0}return!1}function kB(e){var t=this,n=`arab`,r=this.featuresTags[n],i=this.tokenizer.getRangeTokens(e);if(i.length!==1){var a=new Zz(i.map(function(e){return e.getState(`glyphIndex`)}),0),o=new Zz(i.map(function(e){return e.char}),0);i.forEach(function(e,s){if(!rB(e.char)){a.setCurrentIndex(s),o.setCurrentIndex(s);var c=0;DB(o)&&(c|=1),OB(o)&&(c|=2);var l;switch(c){case 1:l=`fina`;break;case 2:l=`init`;break;case 3:l=`medi`;break}if(r.indexOf(l)!==-1){var u=t.query.lookupFeature({tag:l,script:n,contextParams:a});if(u instanceof Error)return console.info(u.message);u.forEach(function(e,t){e instanceof sB&&(EB(e,i,t),a.context[t]=e.substitution)})}}})}}function AB(e,t){return new Zz(e.map(function(e){return e.activeState.value}),t||0)}function jB(e){var t=this,n=`arab`,r=this.tokenizer.getRangeTokens(e),i=AB(r);i.context.forEach(function(e,a){i.setCurrentIndex(a);var o=t.query.lookupFeature({tag:`rlig`,script:n,contextParams:i});o.length&&(o.forEach(function(e){return EB(e,r,a)}),i=AB(r))})}function MB(e){var t=e.current,n=e.get(-1);return n===null&&iB(t)||!iB(n)&&iB(t)}function NB(e){var t=e.get(1);return t===null||!iB(t)}var PB={startCheck:MB,endCheck:NB};function FB(e,t){return new Zz(e.map(function(e){return e.activeState.value}),t||0)}function IB(e){var t=this,n=`latn`,r=this.tokenizer.getRangeTokens(e),i=FB(r);i.context.forEach(function(e,a){i.setCurrentIndex(a);var o=t.query.lookupFeature({tag:`liga`,script:n,contextParams:i});o.length&&(o.forEach(function(e){return EB(e,r,a)}),i=FB(r))})}function LB(e){this.baseDir=e||`ltr`,this.tokenizer=new eB,this.featuresTags={}}LB.prototype.setText=function(e){this.text=e},LB.prototype.contextChecks={latinWordCheck:PB,arabicWordCheck:_B,arabicSentenceCheck:bB};function RB(e){var t=this.contextChecks[e+`Check`];return this.tokenizer.registerContextChecker(e,t.startCheck,t.endCheck)}function zB(){return RB.call(this,`latinWord`),RB.call(this,`arabicWord`),RB.call(this,`arabicSentence`),this.tokenizer.tokenize(this.text)}function BB(){var e=this;this.tokenizer.getContextRanges(`arabicSentence`).forEach(function(t){var n=e.tokenizer.getRangeTokens(t);e.tokenizer.replaceRange(t.startIndex,t.endOffset,n.reverse())})}LB.prototype.registerFeatures=function(e,t){var n=this,r=t.filter(function(t){return n.query.supports({script:e,tag:t})});this.featuresTags.hasOwnProperty(e)?this.featuresTags[e]=this.featuresTags[e].concat(r):this.featuresTags[e]=r},LB.prototype.applyFeatures=function(e,t){if(!e)throw Error(`No valid font was provided to apply features`);this.query||=new oB(e);for(var n=0;n<t.length;n++){var r=t[n];this.query.supports({script:r.script})&&this.registerFeatures(r.script,r.tags)}},LB.prototype.registerModifier=function(e,t,n){this.tokenizer.registerModifier(e,t,n)};function VB(){if(this.tokenizer.registeredModifiers.indexOf(`glyphIndex`)===-1)throw Error(`glyphIndex modifier is required to apply arabic presentation features.`)}function HB(){var e=this;this.featuresTags.hasOwnProperty(`arab`)&&(VB.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){kB.call(e,t)}))}function UB(){var e=this,t=`arab`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`rlig`)!==-1&&(VB.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){jB.call(e,t)}))}function WB(){var e=this,t=`latn`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`liga`)!==-1&&(VB.call(this),this.tokenizer.getContextRanges(`latinWord`).forEach(function(t){IB.call(e,t)}))}LB.prototype.checkContextReady=function(e){return!!this.tokenizer.getContext(e)},LB.prototype.applyFeaturesToContexts=function(){this.checkContextReady(`arabicWord`)&&(HB.call(this),UB.call(this)),this.checkContextReady(`latinWord`)&&WB.call(this),this.checkContextReady(`arabicSentence`)&&BB.call(this)},LB.prototype.processText=function(e){(!this.text||this.text!==e)&&(this.setText(e),zB.call(this),this.applyFeaturesToContexts())},LB.prototype.getBidiText=function(e){return this.processText(e),this.tokenizer.getText()},LB.prototype.getTextGlyphs=function(e){this.processText(e);for(var t=[],n=0;n<this.tokenizer.tokens.length;n++){var r=this.tokenizer.tokens[n];if(!r.state.deleted){var i=r.activeState.value;t.push(Array.isArray(i)?i[0]:i)}}return t};function GB(e){e||={},e.tables=e.tables||{},e.empty||(TL(e.familyName,`When creating a new Font object, familyName is required.`),TL(e.styleName,`When creating a new Font object, styleName is required.`),TL(e.unitsPerEm,`When creating a new Font object, unitsPerEm is required.`),TL(e.ascender,`When creating a new Font object, ascender is required.`),TL(e.descender<=0,`When creating a new Font object, negative descender value is required.`),this.names={fontFamily:{en:e.familyName||` `},fontSubfamily:{en:e.styleName||` `},fullName:{en:e.fullName||e.familyName+` `+e.styleName},postScriptName:{en:e.postScriptName||(e.familyName+e.styleName).replace(/\s/g,``)},designer:{en:e.designer||` `},designerURL:{en:e.designerURL||` `},manufacturer:{en:e.manufacturer||` `},manufacturerURL:{en:e.manufacturerURL||` `},license:{en:e.license||` `},licenseURL:{en:e.licenseURL||` `},version:{en:e.version||`Version 0.1`},description:{en:e.description||` `},copyright:{en:e.copyright||` `},trademark:{en:e.trademark||` `}},this.unitsPerEm=e.unitsPerEm||1e3,this.ascender=e.ascender,this.descender=e.descender,this.createdTimestamp=e.createdTimestamp,this.tables=Object.assign(e.tables,{os2:Object.assign({usWeightClass:e.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:e.widthClass||this.usWidthClasses.MEDIUM,fsSelection:e.fsSelection||this.fsSelectionValues.REGULAR},e.tables.os2)})),this.supported=!0,this.glyphs=new DF.GlyphSet(this,e.glyphs||[]),this.encoding=new dF(this),this.position=new vL(this),this.substitution=new yL(this),this.tables=this.tables||{},this._push=null,this._hmtxTableData={},Object.defineProperty(this,"hinting",{get:function(){if(this._hinting)return this._hinting;if(this.outlinesFormat===`truetype`)return this._hinting=new BL(this)}})}GB.prototype.hasChar=function(e){return this.encoding.charToGlyphIndex(e)!==null},GB.prototype.charToGlyphIndex=function(e){return this.encoding.charToGlyphIndex(e)},GB.prototype.charToGlyph=function(e){var t=this.charToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},GB.prototype.updateFeatures=function(e){return this.defaultRenderOptions.features.map(function(t){return t.script===`latn`?{script:`latn`,tags:t.tags.filter(function(t){return e[t]})}:t})},GB.prototype.stringToGlyphs=function(e,t){var n=this,r=new LB;r.registerModifier(`glyphIndex`,null,function(e){return n.charToGlyphIndex(e.char)});var i=t?this.updateFeatures(t.features):this.defaultRenderOptions.features;r.applyFeatures(this,i);for(var a=r.getTextGlyphs(e),o=a.length,s=Array(o),c=this.glyphs.get(0),l=0;l<o;l+=1)s[l]=this.glyphs.get(a[l])||c;return s},GB.prototype.nameToGlyphIndex=function(e){return this.glyphNames.nameToGlyphIndex(e)},GB.prototype.nameToGlyph=function(e){var t=this.nameToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},GB.prototype.glyphIndexToName=function(e){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(e):``},GB.prototype.getKerningValue=function(e,t){e=e.index||e,t=t.index||t;var n=this.position.defaultKerningTables;return n?this.position.getKerningValue(n,e,t):this.kerningPairs[e+`,`+t]||0},GB.prototype.defaultRenderOptions={kerning:!0,features:[{script:`arab`,tags:[`init`,`medi`,`fina`,`rlig`]},{script:`latn`,tags:[`liga`,`rlig`]}]},GB.prototype.forEachGlyph=function(e,t,n,r,i,a){t=t===void 0?0:t,n=n===void 0?0:n,r=r===void 0?72:r,i=Object.assign({},this.defaultRenderOptions,i);var o=1/this.unitsPerEm*r,s=this.stringToGlyphs(e,i),c;if(i.kerning){var l=i.script||this.position.getDefaultScriptName();c=this.position.getKerningTables(l,i.language)}for(var u=0;u<s.length;u+=1){var d=s[u];if(a.call(this,d,t,n,r,i),d.advanceWidth&&(t+=d.advanceWidth*o),i.kerning&&u<s.length-1){var f=c?this.position.getKerningValue(c,d.index,s[u+1].index):this.getKerningValue(d,s[u+1]);t+=f*o}i.letterSpacing?t+=i.letterSpacing*r:i.tracking&&(t+=i.tracking/1e3*r)}return t},GB.prototype.getPath=function(e,t,n,r,i){var a=new yP;return this.forEachGlyph(e,t,n,r,i,function(e,t,n,r){var o=e.getPath(t,n,r,i,this);a.extend(o)}),a},GB.prototype.getPaths=function(e,t,n,r,i){var a=[];return this.forEachGlyph(e,t,n,r,i,function(e,t,n,r){var o=e.getPath(t,n,r,i,this);a.push(o)}),a},GB.prototype.getAdvanceWidth=function(e,t,n){return this.forEachGlyph(e,0,0,t,n,function(){})},GB.prototype.draw=function(e,t,n,r,i,a){this.getPath(t,n,r,i,a).draw(e)},GB.prototype.drawPoints=function(e,t,n,r,i,a){this.forEachGlyph(t,n,r,i,a,function(t,n,r,i){t.drawPoints(e,n,r,i)})},GB.prototype.drawMetrics=function(e,t,n,r,i,a){this.forEachGlyph(t,n,r,i,a,function(t,n,r,i){t.drawMetrics(e,n,r,i)})},GB.prototype.getEnglishName=function(e){var t=this.names[e];if(t)return t.en},GB.prototype.validate=function(){var e=this;function t(t){var n=e.getEnglishName(t);n&&n.trim().length}t(`fontFamily`),t(`weightName`),t(`manufacturer`),t(`copyright`),t(`version`),this.unitsPerEm},GB.prototype.toTables=function(){return pL.fontToTable(this)},GB.prototype.toBuffer=function(){return console.warn(`Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.`),this.toArrayBuffer()},GB.prototype.toArrayBuffer=function(){for(var e=this.toTables().encode(),t=new ArrayBuffer(e.length),n=new Uint8Array(t),r=0;r<e.length;r++)n[r]=e[r];return t},GB.prototype.download=function(e){var t=this.getEnglishName(`fontFamily`),n=this.getEnglishName(`fontSubfamily`);e||=t.replace(/\s/g,``)+`-`+n+`.otf`;var r=this.toArrayBuffer();if(SL())if(window.URL=window.URL||window.webkitURL,window.URL){var i=new DataView(r),a=new Blob([i],{type:`font/opentype`}),o=document.createElement(`a`);o.href=window.URL.createObjectURL(a),o.download=e;var s=document.createEvent(`MouseEvents`);s.initEvent(`click`,!0,!1),o.dispatchEvent(s)}else console.warn(`Font file could not be downloaded. Try using a different browser.`);else{var c=GN(),l=wL(r);c.writeFileSync(e,l)}},GB.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512},GB.prototype.usWidthClasses={ULTRA_CONDENSED:1,EXTRA_CONDENSED:2,CONDENSED:3,SEMI_CONDENSED:4,MEDIUM:5,SEMI_EXPANDED:6,EXPANDED:7,EXTRA_EXPANDED:8,ULTRA_EXPANDED:9},GB.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function KB(e,t){var n=JSON.stringify(e),r=256;for(var i in t){var a=parseInt(i);if(!(!a||a<256)){if(JSON.stringify(t[i])===n)return a;r<=a&&(r=a+1)}}return t[r]=e,r}function qB(e,t,n){var r=KB(t.name,n);return[{name:`tag_`+e,type:`TAG`,value:t.tag},{name:`minValue_`+e,type:`FIXED`,value:t.minValue<<16},{name:`defaultValue_`+e,type:`FIXED`,value:t.defaultValue<<16},{name:`maxValue_`+e,type:`FIXED`,value:t.maxValue<<16},{name:`flags_`+e,type:`USHORT`,value:0},{name:`nameID_`+e,type:`USHORT`,value:r}]}function JB(e,t,n){var r={},i=new Z.Parser(e,t);return r.tag=i.parseTag(),r.minValue=i.parseFixed(),r.defaultValue=i.parseFixed(),r.maxValue=i.parseFixed(),i.skip(`uShort`,1),r.name=n[i.parseUShort()]||{},r}function YB(e,t,n,r){for(var i=KB(t.name,r),a=[{name:`nameID_`+e,type:`USHORT`,value:i},{name:`flags_`+e,type:`USHORT`,value:0}],o=0;o<n.length;++o){var s=n[o].tag;a.push({name:`axis_`+e+` `+s,type:`FIXED`,value:t.coordinates[s]<<16})}return a}function XB(e,t,n,r){var i={},a=new Z.Parser(e,t);i.name=r[a.parseUShort()]||{},a.skip(`uShort`,1),i.coordinates={};for(var o=0;o<n.length;++o)i.coordinates[n[o].tag]=a.parseFixed();return i}function ZB(e,t){var n=new Y.Table(`fvar`,[{name:`version`,type:`ULONG`,value:65536},{name:`offsetToData`,type:`USHORT`,value:0},{name:`countSizePairs`,type:`USHORT`,value:2},{name:`axisCount`,type:`USHORT`,value:e.axes.length},{name:`axisSize`,type:`USHORT`,value:20},{name:`instanceCount`,type:`USHORT`,value:e.instances.length},{name:`instanceSize`,type:`USHORT`,value:4+e.axes.length*4}]);n.offsetToData=n.sizeOf();for(var r=0;r<e.axes.length;r++)n.fields=n.fields.concat(qB(r,e.axes[r],t));for(var i=0;i<e.instances.length;i++)n.fields=n.fields.concat(YB(i,e.instances[i],e.axes,t));return n}function QB(e,t,n){var r=new Z.Parser(e,t),i=r.parseULong();K.argument(i===65536,`Unsupported fvar table version.`);var a=r.parseOffset16();r.skip(`uShort`,1);for(var o=r.parseUShort(),s=r.parseUShort(),c=r.parseUShort(),l=r.parseUShort(),u=[],d=0;d<o;d++)u.push(JB(e,t+a+d*s,n));for(var f=[],p=t+a+o*s,m=0;m<c;m++)f.push(XB(e,p+m*l,u,n));return{axes:u,instances:f}}var $B={make:ZB,parse:QB},eV=function(){return{coverage:this.parsePointer(X.coverage),attachPoints:this.parseList(X.pointer(X.uShortList))}},tV=function(){var e=this.parseUShort();if(K.argument(e===1||e===2||e===3,`Unsupported CaretValue table version.`),e===1)return{coordinate:this.parseShort()};if(e===2)return{pointindex:this.parseShort()};if(e===3)return{coordinate:this.parseShort()}},nV=function(){return this.parseList(X.pointer(tV))},rV=function(){return{coverage:this.parsePointer(X.coverage),ligGlyphs:this.parseList(X.pointer(nV))}},iV=function(){return this.parseUShort(),this.parseList(X.pointer(X.coverage))};function aV(e,t){t||=0;var n=new X(e,t),r=n.parseVersion(1);K.argument(r===1||r===1.2||r===1.3,`Unsupported GDEF table version.`);var i={version:r,classDef:n.parsePointer(X.classDef),attachList:n.parsePointer(eV),ligCaretList:n.parsePointer(rV),markAttachClassDef:n.parsePointer(X.classDef)};return r>=1.2&&(i.markGlyphSets=n.parsePointer(iV)),i}var oV={parse:aV},sV=Array(10);sV[1]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{posFormat:1,coverage:this.parsePointer(X.coverage),value:this.parseValueRecord()};if(t===2)return{posFormat:2,coverage:this.parsePointer(X.coverage),values:this.parseValueRecordList()};K.assert(!1,`0x`+e.toString(16)+`: GPOS lookup type 1 format must be 1 or 2.`)},sV[2]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();K.assert(t===1||t===2,`0x`+e.toString(16)+`: GPOS lookup type 2 format must be 1 or 2.`);var n=this.parsePointer(X.coverage),r=this.parseUShort(),i=this.parseUShort();if(t===1)return{posFormat:t,coverage:n,valueFormat1:r,valueFormat2:i,pairSets:this.parseList(X.pointer(X.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(r),value2:this.parseValueRecord(i)}})))};if(t===2){var a=this.parsePointer(X.classDef),o=this.parsePointer(X.classDef),s=this.parseUShort(),c=this.parseUShort();return{posFormat:t,coverage:n,valueFormat1:r,valueFormat2:i,classDef1:a,classDef2:o,class1Count:s,class2Count:c,classRecords:this.parseList(s,X.list(c,function(){return{value1:this.parseValueRecord(r),value2:this.parseValueRecord(i)}}))}}},sV[3]=function(){return{error:`GPOS Lookup 3 not supported`}},sV[4]=function(){return{error:`GPOS Lookup 4 not supported`}},sV[5]=function(){return{error:`GPOS Lookup 5 not supported`}},sV[6]=function(){return{error:`GPOS Lookup 6 not supported`}},sV[7]=function(){return{error:`GPOS Lookup 7 not supported`}},sV[8]=function(){return{error:`GPOS Lookup 8 not supported`}},sV[9]=function(){return{error:`GPOS Lookup 9 not supported`}};function cV(e,t){t||=0;var n=new X(e,t),r=n.parseVersion(1);return K.argument(r===1||r===1.1,`Unsupported GPOS table version `+r),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(sV)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(sV),variations:n.parseFeatureVariationsList()}}var lV=Array(10);function uV(e){return new Y.Table(`GPOS`,[{name:`version`,type:`ULONG`,value:65536},{name:`scripts`,type:`TABLE`,value:new Y.ScriptList(e.scripts)},{name:`features`,type:`TABLE`,value:new Y.FeatureList(e.features)},{name:`lookups`,type:`TABLE`,value:new Y.LookupList(e.lookups,lV)}])}var dV={parse:cV,make:uV};function fV(e){var t={};e.skip(`uShort`);var n=e.parseUShort();K.argument(n===0,`Unsupported kern sub-table version.`),e.skip(`uShort`,2);var r=e.parseUShort();e.skip(`uShort`,3);for(var i=0;i<r;i+=1){var a=e.parseUShort(),o=e.parseUShort(),s=e.parseShort();t[a+`,`+o]=s}return t}function pV(e){var t={};e.skip(`uShort`),e.parseULong()>1&&console.warn(`Only the first kern subtable is supported.`),e.skip(`uLong`);var n=e.parseUShort()&255;if(e.skip(`uShort`),n===0){var r=e.parseUShort();e.skip(`uShort`,3);for(var i=0;i<r;i+=1){var a=e.parseUShort(),o=e.parseUShort(),s=e.parseShort();t[a+`,`+o]=s}}return t}function mV(e,t){var n=new Z.Parser(e,t),r=n.parseUShort();if(r===0)return fV(n);if(r===1)return pV(n);throw Error(`Unsupported kern table version (`+r+`).`)}var hV={parse:mV};function gV(e,t,n,r){for(var i=new Z.Parser(e,t),a=r?i.parseUShort:i.parseULong,o=[],s=0;s<n+1;s+=1){var c=a.call(i);r&&(c*=2),o.push(c)}return o}var _V={parse:gV};function vV(e,t){GN().readFile(e,function(e,n){if(e)return t(e.message);t(null,CL(n))})}function yV(e,t){var n=new XMLHttpRequest;n.open(`get`,e,!0),n.responseType=`arraybuffer`,n.onload=function(){return n.response?t(null,n.response):t(`Font could not be loaded: `+n.statusText)},n.onerror=function(){t(`Font could not be loaded`)},n.send()}function bV(e,t){for(var n=[],r=12,i=0;i<t;i+=1){var a=Z.getTag(e,r),o=Z.getULong(e,r+4),s=Z.getULong(e,r+8),c=Z.getULong(e,r+12);n.push({tag:a,checksum:o,offset:s,length:c,compression:!1}),r+=16}return n}function xV(e,t){for(var n=[],r=44,i=0;i<t;i+=1){var a=Z.getTag(e,r),o=Z.getULong(e,r+4),s=Z.getULong(e,r+8),c=Z.getULong(e,r+12),l=void 0;l=s<c?`WOFF`:!1,n.push({tag:a,offset:o,compression:l,compressedLength:s,length:c}),r+=20}return n}function SV(e,t){if(t.compression===`WOFF`){var n=new Uint8Array(e.buffer,t.offset+2,t.compressedLength-2),r=new Uint8Array(t.length);if(gP(n,r),r.byteLength!==t.length)throw Error(`Decompression error: `+t.tag+` decompressed length doesn't match recorded length`);return{data:new DataView(r.buffer,0),offset:0}}else return{data:e,offset:t.offset}}function CV(e,t){t??={};var n,r,i=new GB({empty:!0}),a=new DataView(e,0),o,s=[],c=Z.getTag(a,0);if(c===`\0\0\0`||c===`true`||c===`typ1`)i.outlinesFormat=`truetype`,o=Z.getUShort(a,4),s=bV(a,o);else if(c===`OTTO`)i.outlinesFormat=`cff`,o=Z.getUShort(a,4),s=bV(a,o);else if(c===`wOFF`){var l=Z.getTag(a,4);if(l===`\0\0\0`)i.outlinesFormat=`truetype`;else if(l===`OTTO`)i.outlinesFormat=`cff`;else throw Error(`Unsupported OpenType flavor `+c);o=Z.getUShort(a,12),s=xV(a,o)}else throw Error(`Unsupported OpenType signature `+c);for(var u,d,f,p,m,h,g,_,v,y,b,x,S=0;S<o;S+=1){var C=s[S],w=void 0;switch(C.tag){case`cmap`:w=SV(a,C),i.tables.cmap=oF.parse(w.data,w.offset),i.encoding=new fF(i.tables.cmap);break;case`cvt `:w=SV(a,C),x=new Z.Parser(w.data,w.offset),i.tables.cvt=x.parseShortList(C.length/2);break;case`fvar`:d=C;break;case`fpgm`:w=SV(a,C),x=new Z.Parser(w.data,w.offset),i.tables.fpgm=x.parseByteList(C.length);break;case`head`:w=SV(a,C),i.tables.head=fI.parse(w.data,w.offset),i.unitsPerEm=i.tables.head.unitsPerEm,n=i.tables.head.indexToLocFormat;break;case`hhea`:w=SV(a,C),i.tables.hhea=hI.parse(w.data,w.offset),i.ascender=i.tables.hhea.ascender,i.descender=i.tables.hhea.descender,i.numberOfHMetrics=i.tables.hhea.numberOfHMetrics;break;case`hmtx`:g=C;break;case`ltag`:w=SV(a,C),r=CI.parse(w.data,w.offset);break;case`maxp`:w=SV(a,C),i.tables.maxp=EI.parse(w.data,w.offset),i.numGlyphs=i.tables.maxp.numGlyphs;break;case`name`:y=C;break;case`OS/2`:w=SV(a,C),i.tables.os2=qI.parse(w.data,w.offset);break;case`post`:w=SV(a,C),i.tables.post=XI.parse(w.data,w.offset),i.glyphNames=new mF(i.tables.post);break;case`prep`:w=SV(a,C),x=new Z.Parser(w.data,w.offset),i.tables.prep=x.parseByteList(C.length);break;case`glyf`:f=C;break;case`loca`:v=C;break;case`CFF `:u=C;break;case`kern`:_=C;break;case`GDEF`:p=C;break;case`GPOS`:m=C;break;case`GSUB`:h=C;break;case`meta`:b=C;break}}var ee=SV(a,y);if(i.tables.name=HI.parse(ee.data,ee.offset,r),i.names=i.tables.name,f&&v){var te=n===0,ne=SV(a,v),re=_V.parse(ne.data,ne.offset,i.numGlyphs,te),ie=SV(a,f);i.glyphs=FL.parse(ie.data,ie.offset,re,i,t)}else if(u){var ae=SV(a,u);lI.parse(ae.data,ae.offset,i,t)}else throw Error(`Font doesn't contain TrueType or CFF outlines.`);var oe=SV(a,g);if(bI.parse(i,oe.data,oe.offset,i.numberOfHMetrics,i.numGlyphs,i.glyphs,t),_F(i,t),_){var se=SV(a,_);i.kerningPairs=hV.parse(se.data,se.offset)}else i.kerningPairs={};if(p){var ce=SV(a,p);i.tables.gdef=oV.parse(ce.data,ce.offset)}if(m){var le=SV(a,m);i.tables.gpos=dV.parse(le.data,le.offset),i.position.init()}if(h){var ue=SV(a,h);i.tables.gsub=nL.parse(ue.data,ue.offset)}if(d){var de=SV(a,d);i.tables.fvar=$B.parse(de.data,de.offset,i.names)}if(b){var fe=SV(a,b);i.tables.meta=aL.parse(fe.data,fe.offset),i.metas=i.tables.meta}return i}function wV(e,t,n){n??={};var r=typeof window>`u`&&!n.isUrl?vV:yV;return new Promise(function(i,a){r(e,function(e,r){if(e){if(t)return t(e);a(e)}var o;try{o=CV(r,n)}catch(e){if(t)return t(e,null);a(e)}if(t)return t(null,o);i(o)})})}function TV(e,t){return CV(CL(GN().readFileSync(e)),t)}var EV=Object.freeze({__proto__:null,Font:GB,Glyph:xF,Path:yP,BoundingBox:vP,_parse:Z,parse:CV,load:wV,loadSync:TV});function DV(e,{ruled:t=!0,startPoint:n,endPoint:r,tolerance:i=1e-6}={},a=!1){if(e.length===0&&!n&&!r)return k(F(`LOFT_EMPTY`,`Loft requires at least one wire or start/end point`));let o=U(),s=n?o.makeVertex(...qw(n)):void 0,c=r?o.makeVertex(...qw(r)):void 0;try{let n=W(o.loftAdvanced(e.map(e=>e.wrapped),{solid:!a,ruled:t,tolerance:i,...s?{startVertex:s}:{},...c?{endVertex:c}:{}}));return dw(n)?O(n):k(za(`LOFT_NOT_3D`,`Loft did not produce a 3D shape`))}catch(e){return k(P(`LOFT_FAILED`,`Loft operation failed`,e,void 0,`Common causes: wire profiles with different edge counts, self-intersecting result, or profiles too far apart. Ensure profiles are compatible and ordered.`))}}function OV(e){if(e.length===0)return O([]);let t=U(),n=[],r=e.map(e=>{let r=e.startPoint?t.makeVertex(...qw(e.startPoint)):void 0,i=e.endPoint?t.makeVertex(...qw(e.endPoint)):void 0;return r&&n.push(r),i&&n.push(i),{wires:e.wires.map(e=>e.wrapped),solid:!0,ruled:e.ruled??!0,tolerance:e.tolerance??1e-6,startVertex:r,endVertex:i}});try{let e=t.loftBatch?.(r)??r.map(e=>t.loftAdvanced(e.wires,{solid:e.solid,ruled:e.ruled,tolerance:e.tolerance,startVertex:e.startVertex,endVertex:e.endVertex})),n=[];for(let t of e){let e=W(t);if(!dw(e))return k(za(`LOFT_ALL_NOT_3D`,`Batch loft entry did not produce a 3D shape`));n.push(e)}return O(n)}catch(e){return k(P(`LOFT_ALL_FAILED`,`Batch loft operation failed`,e))}finally{for(let e of n)t.dispose(e)}}var kV=class{sketches;constructor(e){e.length===0&&M(`CompoundSketch`,`Cannot create CompoundSketch with an empty array of sketches`),this.sketches=e}delete(){this.sketches.forEach(e=>{e.delete()})}get outerSketch(){return bD(this.sketches)}get innerSketches(){return this.sketches.slice(1)}get wires(){return UV(this)}face(){return HV(this)}extrude(e,t={}){return WV(this,e,t)}revolve(e,t={}){return GV(this,e,t)}loftWith(e,t){return KV(this,e,t)}};function AV(e){let t={};e.defaultOrigin&&(t.defaultOrigin=e.defaultOrigin),e.defaultDirection&&(t.defaultDirection=e.defaultDirection);let n=new qV(e.wire,t);return e.baseFace&&(n.baseFace=e.baseFace),n}function jV(e){return new kV(e.map(AV))}function MV(e){let t;return t=e.baseFace?LD(e.baseFace,e.wire):j(FD(e.wire)),t}function NV(e){return QC(j(DT(e.wire.wrapped)))}function PV(e,t,{origin:n}={}){let r=j(FD(e.wire)),i=j(UN(r,n?qw(n):e.defaultOrigin,t?qw(t):[0,0,1]));return r.delete(),e.delete(),i}function FV(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=$w(oT(n?qw(n):e.defaultDirection),t),s=a?qw(a):e.defaultOrigin;if(r&&!i){let t=j(IN(e.wire,[...s],[...o],r));return e.delete(),t}if(i){let t=j(LN(e.wire,i,[...s],[...o],r));return e.delete(),t}let c=j(HN(j(FD(e.wire)),[...o]));return e.delete(),c}function IV(e,t,n={}){let r=VE(e.wire),i=oT($w(WE(e.wire,1e-9),-1)),a=e.defaultDirection,o=$w(nT(i,a),-1),s=t(mT([...r],[...o],[...i]),[...r]),c;if(`sketches`in s&&Array.isArray(s.sketches)){let e=s.sketches;c=e[0];for(let t=1;t<e.length;t++)e[t]?.delete()}else c=s;let l={forceProfileSpineOthogonality:!0,...n};e.baseFace&&(l.support=e.baseFace.wrapped);let u=j(PN(c.wire,e.wire,l));return e.delete(),u}function LV(e,t,n={},r=!1){let i=Array.isArray(t)?[e,...t]:[e,t],a=j(DV(i.map(e=>e.wire),n,r));return i.forEach(e=>{e.delete()}),a}var RV=e=>{let t=e.map(e=>e.wrapped),n=j(OT(U().fillSurface(t)));return sw(n)||M(`guessFaceFromWires`,`Failed to create a face`),n},zV=(e,t)=>QC(U().fixWireOnFace(e.wrapped,t.wrapped,1e-9)),BV=e=>{let t,n,r=FD(bD(e));return ua(r)?(t=r.value,n=e.slice(1)):(t=RV(e),n=e.slice(1).map(e=>zV(e,t))),zD(t,n)},VV=(e,t)=>{let n=[],r=[],i=[];e.forEach(e=>{let[a,o,s]=j(t(e));n.push(a),r.push(o),i.push(s)});let a=BV(r),o=BV(i);return j(_O([a,...n,o]))};function HV(e){return zD(e.outerSketch.face(),e.innerSketches.map(e=>e.wire))}function UV(e){return gO(e.sketches.map(e=>e.wire))}function WV(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=$w(oT(n?qw(n):e.outerSketch.defaultDirection),t);return r&&!i?VV(e.sketches,t=>IN(t.wire,a?qw(a):e.outerSketch.defaultOrigin,o,r,!0)):i?VV(e.sketches,t=>LN(t.wire,i,a?qw(a):e.outerSketch.defaultOrigin,o,r,!0)):j(HN(HV(e),o))}function GV(e,t,{origin:n}={}){let r=n?qw(n):e.outerSketch.defaultOrigin,i=t?qw(t):[0,0,1];return j(UN(HV(e),r,i))}function KV(e,t,n){e.sketches.length!==t.sketches.length&&M(`CompoundSketch.loftWith`,`You need to loft with another compound with the same number of sketches`);let r=e.sketches.map((e,r)=>{let i=yD(t.sketches,r),a={};return n.ruled!==void 0&&(a.ruled=n.ruled),e.clone().loftWith(i.clone(),a,!0)}),i=$C(j(DT(HV(e).wrapped)));return r.push(i,HV(t)),j(_O(r))}var qV=class e{wire;_defaultOrigin;_defaultDirection;_baseFace;constructor(e,{defaultOrigin:t=[0,0,0],defaultDirection:n=[0,0,1]}={}){this.wire=e,this._defaultOrigin=qw(t),this._defaultDirection=qw(n),this.baseFace=null}get baseFace(){return this._baseFace}set baseFace(e){this._baseFace&&this._baseFace.delete(),this._baseFace=e&&$C(j(DT(e.wrapped)))}delete(){this.wire.delete(),this.baseFace&&this.baseFace.delete()}clone(){let t=new e(QC(j(DT(this.wire.wrapped))),{defaultOrigin:this.defaultOrigin,defaultDirection:this.defaultDirection});return this.baseFace&&(t.baseFace=$C(j(DT(this.baseFace.wrapped)))),t}get defaultOrigin(){return this._defaultOrigin}set defaultOrigin(e){this._defaultOrigin=qw(e)}get defaultDirection(){return this._defaultDirection}set defaultDirection(e){this._defaultDirection=qw(e)}face(){return MV(this)}wires(){return NV(this)}faces(){return this.face()}revolve(e,t={}){return PV(this,e,t)}extrude(e,t={}){return FV(this,e,t)}sweepSketch(e,t={}){return IV(this,e,t)}loftWith(e,t={},n=!1){return LV(this,e,t,n)}},JV=class{sketches;constructor(e){this.sketches=e}wires(){return gO(this.sketches.map(e=>e instanceof qV?e.wire:e.wires))}faces(){return gO(this.sketches.map(e=>e.face()))}extrude(e,t={}){return gO(this.sketches.map(n=>n.extrude(e,t)))}revolve(e,t){return gO(this.sketches.map(n=>n.revolve(e,t)))}},YV={};async function XV(e,t=`default`,n=!1){if(!n&&YV[t])return O(YV[t]);let r;if(typeof e==`string`){let t;try{t=await fetch(e)}catch(t){return k(Ua(N.FONT_FETCH_FAILED,`Failed to fetch font from ${e}: ${t instanceof Error?t.message:String(t)}`,t))}if(!t.ok)return k(Ua(N.FONT_FETCH_FAILED,`Failed to fetch font from ${e}: HTTP ${t.status} ${t.statusText}`));r=await t.arrayBuffer()}else r=e;let i;try{i=EV.parse(r)}catch(e){return k(Ua(N.FONT_PARSE_FAILED,`Failed to parse font data: ${e instanceof Error?e.message:String(e)}`,e))}let a=i;return YV[t]=a,YV.default||=a,O(a)}var ZV=(e=`default`)=>YV[e],QV=function*(e){let t=null,n=null;for(let r of e){if(r.type===`Z`){t&&(yield t.close()),t=null;continue}let e=[-r.x,r.y];if(r.type===`M`){t&&(yield t.done()),t=new RM,t.movePointerTo(e),n=e;continue}n&&Math.abs(e[0]-n[0])<1e-9&&Math.abs(e[1]-n[1])<1e-9||(r.type===`L`&&t?.lineTo(e),r.type===`C`&&t?.cubicBezierCurveTo(e,[-r.x1,r.y1],[-r.x2,r.y2]),r.type===`Q`&&t?.quadraticBezierCurveTo(e,[-r.x1,r.y1]),n=e)}};function $V(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:i=`default`}={}){let a=ZV(i);a||=ZV(),a||M(`text`,`No fonts loaded. Call loadFont() before using text functions.`);let o=a.getPath(e,-t,-n,r);return DM(Array.from(QV(o.commands))).mirror([0,0])}var eH={XY:{dir:[0,0,1],xAxis:[1,0,0]},XZ:{dir:[0,-1,0],xAxis:[1,0,0]},YZ:{dir:[1,0,0],xAxis:[0,1,0]},YX:{dir:[0,0,-1],xAxis:[0,1,0]},ZX:{dir:[0,1,0],xAxis:[0,0,1]},ZY:{dir:[-1,0,0],xAxis:[0,0,1]},front:{dir:[0,-1,0],xAxis:[1,0,0]},back:{dir:[0,1,0],xAxis:[-1,0,0]},right:{dir:[-1,0,0],xAxis:[0,-1,0]},left:{dir:[1,0,0],xAxis:[0,1,0]},bottom:{dir:[0,0,1],xAxis:[1,0,0]},top:{dir:[0,0,-1],xAxis:[1,0,0]}};function tH(e){return typeof e==`string`&&e in eH}var nH=e=>e.IsNull()?[]:Tw(W(e));function rH(e,t,n=!0){let r=U().projectEdges(e.wrapped,[...t.position],[...t.direction],[...t.xAxis]);return{visible:[...nH(r.visible.sharp),...nH(r.visible.smooth),...nH(r.visible.outline)],hidden:n?[...nH(r.hidden.sharp),...nH(r.hidden.smooth),...nH(r.hidden.outline)]:[]}}function iH(e=[0,0,0],t=[0,0,1],n){if(rT(t)<1e-12)return k(F(`CAMERA_ZERO_DIRECTION`,`Camera direction cannot be a zero-length vector`));let r;if(n)r=oT(n);else{let e=nT([0,0,1],t);rT(e)<1e-12&&(e=nT([0,1,0],t)),rT(e)<1e-12&&(e=nT([1,0,0],t)),r=oT(e)}let i=oT(nT(t,r));return O({position:e,direction:oT(t),xAxis:r,yAxis:i})}function aH(e,t){let n=oT(Qw(e.position,t));return iH(e.position,n)}function oH(e){let t=eH[e];return iH([0,0,0],t.dir,t.xAxis)}function sH(e,t,n=!0){return rH(e,t,n)}var cH=(e,n=1e-7)=>{let r=new sM(e.length);e.forEach(e=>{let[t,i]=e.firstPoint;r.add(t-n,i-n,t+n,i+n)}),r.finish();let i=[],a=new Set;return e.forEach((o,s)=>{if(a.has(s))return;let c=[o],l=s;a.add(s);let u=e.length;for(;;){u--<0&&M(`stitchCurves`,`Infinite loop detected`);let[o,s]=t(c,c.length-1).lastPoint,d=r.search(o-n,s-n,o+n,s+n),f=t=>Math.abs((l-t)%e.length),p=d.filter(e=>!a.has(e)).map(n=>[t(e,n),n,f(n)]).sort(([,,e],[,,t])=>e-t);if(p.length===0){i.push(c);break}let[m,h]=t(p,0);c.push(m),a.add(h),l=h}}),i},lH=class extends LM{plane;constructor(e,t){super(),this.plane=e&&typeof e!=`string`?{...e}:j(_T(e??`XY`,t))}delete(){this.pendingCurves=[]}sagittaArcTo(e,t){return super.sagittaArcTo(e,-t)}buildWire(){try{var e=uC();this.pendingCurves.length||M(`Sketcher.buildWire`,`No lines to convert into a wire`);let t=e.u(new SC);return j(PD(Wj(this.pendingCurves,this.plane).map(e=>t.register(e))))}catch(t){e.e=t}finally{e.d()}}done(){return new qV(this.buildWire(),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}close(){return this._closeSketch(),this.done()}closeWithMirror(){KA(this.pointer,this.firstPoint)&&M(`Sketcher.closeWithMirror`,`Cannot close with a mirror when the sketch is already closed`);let e=this.buildWire(),t=yT(this.plane,this.pointer),n=nT(oT(Qw(t,yT(this.plane,this.firstPoint))),this.plane.zDir),r=j(DT(e.wrapped));return new qV(j(PD([e,QC(j(DT(U().mirror(r,qw(t),qw(n)))))])),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}closeWithCustomCorner(e,t=`fillet`){return this._closeSketch(),this._customCornerLastWithFirst(e,t),this.done()}},uH=class extends LM{face;_bounds;constructor(e,t=[0,0]){super(t),this.face=$C(j(DT(e.wrapped))),this._bounds=IT(e)}_convertToUV([e,t]){let{uMin:n,uMax:r,vMin:i,vMax:a}=this._bounds;return[n+e*(r-n),i+t*(a-i)]}_convertFromUV([e,t]){let{uMin:n,uMax:r,vMin:i,vMax:a}=this._bounds;return[(e-n)/(r-n),(t-i)/(a-i)]}_adaptSurface(){return U().extractSurfaceFromFace(this.face.wrapped)}buildWire(){let e=U(),t=this._adaptSurface(),n=j(PD(this.pendingCurves.map(n=>ZC(e.buildEdgeOnSurface(n.wrapped,t)))));return e.buildCurves3d(n.wrapped),n}done(){try{var e=uC();let t=e.u(new SC),n=this.buildWire(),r=new qV(n);if(KE(n)){let e=t.register(r.clone().face()),n=LT(e,.5,.5),i=$w(BT(e),-1);r.defaultOrigin=[n[0],n[1],n[2]],r.defaultDirection=[i[0],i[1],i[2]]}else{let e=VE(n),t=BT(this.face,[e[0],e[1],e[2]]);r.defaultOrigin=[e[0],e[1],e[2]],r.defaultDirection=[t[0],t[1],t[2]]}return r.baseFace=this.face,r}catch(t){e.e=t}finally{e.d()}}close(){return this._closeSketch(),this.done()}closeWithMirror(){return this._closeWithMirror(),this.close()}closeWithCustomCorner(e,t=`fillet`){return this._closeSketch(),this._customCornerLastWithFirst(e,t),this.done()}},dH=(e,t={})=>{let n=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(_T(t.plane??`XY`,t.origin));return new qV(j(PD([TD(e,n.origin,n.zDir)])),{defaultOrigin:[...n.origin],defaultDirection:[...n.zDir]})},fH=(e=1,t=2,n={})=>{let r=n.plane&&typeof n.plane!=`string`?{...n.plane}:j(_T(n.plane??`XY`,n.origin)),i=r.xDir,a=e,o=t;return t>e&&(i=dT(i,r.zDir,90*Gw),a=t,o=e),new qV(j(PD([j(ED(a,o,r.origin,r.zDir,i))])),{defaultOrigin:[...r.origin],defaultDirection:[...r.zDir]})},pH=(e,t,n={})=>(n.plane&&typeof n.plane!=`string`?new lH(n.plane):new lH(n.plane,n.origin)).movePointerTo([-e/2,-t/2]).hLine(e).vLine(t).hLine(-e).vLine(-t).done(),mH=(e,t,n=0,r={})=>{let i=GM(e,t,n).sketchOnPlane(r.plane,r.origin),a={};return i.defaultOrigin&&(a.defaultOrigin=i.defaultOrigin),i.defaultDirection&&(a.defaultDirection=i.defaultDirection),new qV(i.wire,a)},hH=(e,t,n=0,r={})=>{let i=[...Array(t).keys()].map(n=>{let r=-(Math.PI*2/t)*n;return[e*Math.sin(r),e*Math.cos(r)]}),a=r.plane&&typeof r.plane!=`string`?new lH(r.plane):new lH(r.plane,r.origin),o=xD(i),s=a.movePointerTo([yD(o,0),yD(o,1)]);return n?i.forEach(e=>s.sagittaArcTo([yD(e,0),yD(e,1)],n)):i.forEach(e=>s.lineTo([yD(e,0),yD(e,1)])),s.done()},gH=(e,t,n=0)=>{let r=Math.PI/t,i=Math.cos(r)*e;return n>=0?i:i+n},_H=(e,t)=>{let n=[...VT(e)],r=[...BT(e)];return new qV(j($E(UT(e),t)),{defaultOrigin:n,defaultDirection:r})},vH=(e,t={},{pointsCount:n=400,start:r=0,stop:i=1}={},a={})=>{try{var o=uC();let s=o.u(new SC),c=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(_T(t.plane??`XY`,t.origin)),l=(i-r)/n,u=[...Array(n+1).keys()].map(t=>yT(c,e(r+t*l)));return new qV(j(PD([s.register(j(AD(u,a)))])),{defaultOrigin:[...c.origin],defaultDirection:[...c.zDir]})}catch(e){o.e=e}finally{o.d()}},yH=(e,t,n,r=[0,0,0],i=[0,0,1],a=!1)=>new qV(j(PD([DD(e,t,n,qw(r),qw(i),a)]))),bH=(e,t,n)=>new lH().movePointerTo([-e/2,t/2]).hLine(e).vLine(-t).hLine(-e).close().extrude(n),xH=(e,t)=>KA(e,t,WA*100),SH=(e,t,n,r)=>{let i=e[0]-t[0],a=e[1]-t[1],o=n[0]-r[0],s=n[1]-r[1],c=i*s-a*o;if(Math.abs(c)<1e-12)return null;let l=e[0]*t[1]-e[1]*t[0],u=n[0]*r[1]-n[1]*r[0];return[(l*o-u*i)/c,(l*s-u*a)/c]};function CH(e,t,n,r,i){let a=Vj(t,n,r.original.lastPoint);e(r),e(a)}function wH(e,t,n,r,i){let a=Nj(t,n);e(r),e(a)}function TH(e,t,n,r,i){let a=SH(r.offset instanceof kj?JA(t,r.offset.tangentAt(1)):r.offset.firstPoint,t,n,i.offset instanceof kj?qA(n,i.offset.tangentAt(0)):i.offset.lastPoint);if(!a){let i=Nj(t,n);e(r),e(i);return}let o=ZA([(t[0]+n[0])/2,(t[1]+n[1])/2],a),s=ZA(t,n);if(s<1e-18||o>16*s){let i=Nj(t,n);e(r),e(i);return}let c=Nj(t,a),l=Nj(a,n);e(r),e(c),e(l)}var EH={round:CH,bevel:wH,miter:TH};function DH(e,t,n){let r=n.length===1?Ka(n,0,`rawOffsets`):OH(n,e.original.lastPoint),i=Ka(e.offset.splitAt([r],WA),0,`rawOffsets`),a=t.offset.splitAt([r],WA).at(-1);return a||M(`offset.rawOffsets`,`Split produced no trailing curve segment`),{splitPrevious:{offset:i,original:e.original},splitCurrent:{offset:a,original:t.original}}}function OH(e,t){let n=Ka(e,0,`selectClosestIntersection`),r=ZA(n,t);for(let i=1;i<e.length;i++){let a=Ka(e,i,`selectClosestIntersection`),o=ZA(a,t);o<r&&(r=o,n=a)}return n}function kH(e){let t=new Map,n=(e,n)=>{let r=t.get(e)||[];t.set(e,[...r,...n])},r=new sM(e.length);for(let t of e){let[[e,n],[i,a]]=t.boundingBox.bounds;r.add(e,n,i,a)}return r.finish(),e.forEach((t,i)=>{let[[a,o],[s,c]]=t.boundingBox.bounds,l=r.search(a,o,s,c);for(let r of l){if(r<=i)continue;let a=Ka(e,r,`offsetBlueprint`),{intersections:o,commonSegmentsPoints:s}=j(fM(t,a,WA)),c=[...o,...s].filter(e=>{let n=xH(e,t.firstPoint)||xH(e,t.lastPoint),r=xH(e,a.firstPoint)||xH(e,a.lastPoint);return!(n&&r)});c.length&&(n(i,c),n(r,c))}}),t}function AH(e,t,n={}){let r=e.orientation===`clockwise`?-t:t,i=e.curves.map(e=>({offset:hM(e,r),original:e})),a=[],o=null,s=i.at(-1);if(!s)return[];function c(e){if(e instanceof kj){a.push(e);return}o?e.offset instanceof kj?a.push(e.offset):xH(e.offset.firstPoint,e.offset.lastPoint)||a.push(Nj(e.offset.firstPoint,e.offset.lastPoint)):o=e}let l=function*(){for(let e of i.slice(0,-1))yield e;o||M(`offset.rawOffsets`,`No saved curve after iterating offset segments`),yield o};for(let e of l()){let t=s.offset.lastPoint,r=e.offset.firstPoint;if(xH(t,r)){c(s),s=e;continue}let i=[];if(s.offset instanceof kj&&e.offset instanceof kj){let{intersections:t,commonSegmentsPoints:n}=j(fM(s.offset,e.offset,WA/100));i=[...t,...n]}if(i.length>0){let{splitPrevious:t,splitCurrent:n}=DH(s,e,i);c(t),s=n;continue}let a=EH[n.lineJoinType??`round`];a(c,t,r,s,e),s=e}return c(s),a}function jH(e,n,r={}){let i=AH(e,n,r);if(i.length<2)return null;let a=kH(i);if(!a.size){let t=new rM(i);return e.intersects(t)?null:t}let o=i.flatMap((e,t)=>{if(!a.has(t))return e;let n=a.get(t)||[];return e.splitAt(n,WA*100)}),s=new sM(e.curves.length);for(let t of e.curves){let[[e,n],[r,i]]=t.boundingBox.bounds;s.add(e,n,r,i)}s.finish();let c=Math.abs(n),l=o.filter(n=>{let[[r,i],[a,o]]=n.boundingBox.bounds;return!s.search(r-c,i-c,a+c,o+c).some(r=>t(e.curves,r).distanceFrom(n)<c-WA)});if(!l.length)return null;let u=cH(l).filter(e=>e.length>1).map(e=>new rM(e)).filter(e=>e.isClosed());return u.length?u.length===1?Ka(u,0,`offsetBlueprint`):new bM(u):null}var MH=e=>{let t=Ka(e,0,`fuseAll`);for(let n=1;n<e.length;n++)t=DN(t,Ka(e,n,`fuseAll`));return t};function NH(e,t,n={}){if(e instanceof rM)return jH(e,t,n);if(e instanceof bM)return MH(e.blueprints.map(e=>NH(e,t,n)));if(e instanceof xM){let r=MH(e.blueprints.slice(1).map(e=>NH(e,-t,n)));return kN(NH(Ka(e.blueprints,0,`offset`),t,n),r)}return null}function PH(e,t){return e instanceof rM?new rM(Mj(e.curves,t)):e instanceof xM?new xM(e.blueprints.map(e=>PH(e,t))):e instanceof bM?new bM(e.blueprints.map(e=>PH(e,t))):e}function FH(e,t,n,r){let i=()=>!0;r&&(i=r.shouldKeep.bind(r));let a=[bD(t.curves)],o=(t,r)=>{i({firstCurve:t,secondCurve:r,point:t.lastPoint})?a.push(...e(t,r,n)):a.push(t,r)};t.curves.slice(1).forEach(e=>{let t=a.pop();t||M(`customCorners.modifyCorners`,`Unexpected empty curve stack during filleting`),o(t,e)});let s=a.at(-1);if(s||M(`customCorners.modifyCorners`,`Unexpected empty curve list during corner modification`),KA(bD(a).firstPoint,s.lastPoint)&&a.length>1){let e=a.pop(),t=a.shift();(!e||!t)&&M(`customCorners.modifyCorners`,`Unexpected empty curve stack during close-and-fillet`),o(e,t)}return new rM(a)}function IH(e,t,n,r){return t instanceof rM?FH(e,t,n,r):t instanceof xM?new xM(t.blueprints.map(t=>FH(e,t,n,r))):t instanceof bM?new bM(t.blueprints.map(t=>IH(e,t,n,r)).filter(e=>e!==null)):null}function LH(e,t,n){return IH(_M,e,t,n)}function RH(e,t,n){return IH(vM,e,t,n)}function zH(e,t){return e instanceof rM?AV(t):e instanceof xM?jV(t):new JV(t.map(e=>Array.isArray(e)?jV(e):AV(e)))}var BH=class e{innerShape;constructor(e=null){this.innerShape=e}clone(){return new e(this.innerShape?.clone()||null)}serialize(){if(!this.innerShape)return JSON.stringify({type:`Empty`});function e(t){if(t instanceof xM)return{type:`CompoundBlueprint`,blueprints:t.blueprints.map(e)};if(t instanceof bM)return{type:`Blueprints`,blueprints:t.blueprints.map(e)};if(t instanceof rM)return{type:`Blueprint`,curves:t.curves.map(e=>e.serialize())};M(`Drawing.serialize`,`Unknown shape type for serialization`)}return JSON.stringify(e(this.innerShape))}get boundingBox(){return this.innerShape?this.innerShape.boundingBox:new Dj}stretch(t,n,r){return this.innerShape?new e(this.innerShape.stretch(t,n,r)):new e}get repr(){return this.innerShape===null?`=== empty shape`:this.innerShape.repr}rotate(t,n){return this.innerShape?new e(this.innerShape.rotate(t,n)):new e}translate(t,n=0){return this.innerShape?new e(typeof t==`number`?this.innerShape.translate(t,n):this.innerShape.translate(t)):new e}scale(t,n){return this.innerShape?new e(this.innerShape.scale(t,n)):new e}mirror(t,n,r){return this.innerShape?new e(this.innerShape.mirror(t,n,r)):new e}cut(t){return new e(kN(this.innerShape,t.innerShape))}fuse(t){return new e(DN(this.innerShape,t.innerShape))}intersect(t){return new e(AN(this.innerShape,t.innerShape))}fillet(t,n){let r=n&&n(UM());return new e(LH(this.innerShape,t,r))}chamfer(t,n){let r=n&&n(UM());return new e(RH(this.innerShape,t,r))}sketchOnPlane(e,t){this.innerShape||M(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnPlane(e,t);return zH(this.innerShape,n)}sketchOnFace(e,t){this.innerShape||M(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnFace(e,t);return zH(this.innerShape,n)}punchHole(e,t,n={}){return this.innerShape?this.innerShape.punchHole(e,t,n):e}toSVG(e){return this.innerShape?.toSVG(e)||``}toSVGViewBox(e=1){return this.innerShape?.toSVGViewBox(e)||``}toSVGPaths(){return this.innerShape?.toSVGPaths()||[]}offset(t,n={}){return new e(NH(this.innerShape,t,n))}approximate(t,n={}){return t!==`svg`&&M(`Drawing.approximate`,`Only 'svg' is supported for now`),new e(PH(this.innerShape,n))}get blueprint(){if(!(this.innerShape instanceof rM)){if(this.innerShape instanceof bM&&this.innerShape.blueprints.length===1&&this.innerShape.blueprints[0]instanceof rM)return this.innerShape.blueprints[0];M(`Drawing.blueprint`,`This drawing is not a blueprint`)}return this.innerShape}};function VH(e){function t(e){if(e.type===`CompoundBlueprint`)return new xM(e.blueprints.map(t));if(e.type===`Blueprints`)return new bM(e.blueprints.map(t));if(e.type===`Blueprint`)return new rM(e.curves.map(e=>Oj(e)));M(`Drawing.deserialize`,`Unknown shape type for deserialization`)}return new BH(t(JSON.parse(e)))}var HH=class extends LM{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new BH(new rM(this.pendingCurves))}close(){return this._closeSketch(),this.done()}closeWithMirror(){return this._closeWithMirror(),this.close()}closeWithCustomCorner(e,t=`fillet`){return this._closeSketch(),this._customCornerLastWithFirst(e,t),this.done()}};function UH(e){let t=new HH;return e&&t.movePointerTo(e),t}function WH(e,t,n=0){return new BH(GM(e,t,n))}var GH=WH;function KH(e){return new BH(new rM([Ij(e)]))}function qH(e,t){let[n,r]=[e,t].sort((e,t)=>e-t);return new BH(new rM([Lj(r,n,r===e?[1,0]:[0,1])]))}function JH(e){return UH().movePointerTo([-e,0]).sagittaArc(2*e,0,e).sagittaArc(-2*e,0,e).close()}function YH(e,t){return UH().movePointerTo([-e,0]).halfEllipse(2*e,0,t).halfEllipse(-2*e,0,t).close()}function XH(e,t,n=0){return new BH(WM(e,t,n))}function ZH(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:i=`default`}={}){return new BH($V(e,{startX:t,startY:n,fontSize:r,fontFamily:i}))}var QH=(e,t={},n={})=>{e.length<2&&M(`drawPointsInterpolation`,`Need at least 2 points for interpolation, got ${e.length}`);let r=[j(Bj(e,t))],i=e[0],a=e[e.length-1];return n.closeShape&&i&&a&&!KA(i,a)&&r.push(Nj(a,i)),new BH(new rM(r))},$H=(e,{pointsCount:t=400,start:n=0,stop:r=1,closeShape:i=!1}={},a={})=>{let o=(r-n)/t;return QH([...Array(t+1).keys()].map(t=>e(n+t*o)),a,{closeShape:i})},eU=e=>{try{var t=uC();let n=t.u(new SC),r=GH(1e3,1e3).sketchOnPlane(),i=n.register(j(FD(r.wire))),a=cH(e.map(e=>$j(e,i))).map(e=>new rM(e));return a.length===0?new BH:a.length===1?new BH(a[0]):new BH(new bM(a))}catch(e){t.e=e}finally{t.d()}};function tU(e,t=`front`){let n;n=typeof t==`string`?j(oH(t)):t;let{visible:r,hidden:i}=sH(e,n);return{visible:eU(r),hidden:eU(i)}}function nU(e){try{var t=uC();let n=t.u(new SC),r=n.register($C(j(DT(e.wrapped)))),i=cH(Tw(n.register(UT(r))).map(t=>$j(t,e))).map(e=>new rM(e));return i.length===0?new BH:i.length===1?new BH(i[0]):new BH(new bM(i))}catch(e){t.e=e}finally{t.d()}}function rU(e,t,n){return n===void 0?e.sketchOnPlane(t):e.sketchOnPlane(t,n)}function iU(e,t){return e.fuse(t)}function aU(e,t){return e.cut(t)}function oU(e,t){return e.intersect(t)}function sU(e,t,n){return e.fillet(t,n)}function cU(e,t,n){return e.chamfer(t,n)}function lU(e,t,n=0){return typeof t==`number`?e.translate(t,n):e.translate(t)}function uU(e,t,n){return e.rotate(t,n)}function dU(e,t,n){return e.scale(t,n)}function fU(e,t,n,r){return e.mirror(t,n,r)}function pU(e){let t=e.clone();return t.reverse(),t}function mU(e){return e.boundingBox}function hU(e){return e.firstPoint}function gU(e){return e.lastPoint}function _U(e,t,n){return e.splitAt(t,n)}function vU(e,t,n){return e.parameter(t,n)}function yU(e,t){return e.tangentAt(t)}function bU(e,t){return e.isOnCurve(t)}function xU(e,t){return e.distanceFrom(t)}function SU(e){return e.length===0?k(F(N.BLUEPRINT_EMPTY_CURVES,`createBlueprint: at least one curve is required`)):O(new rM(e))}function CU(e){return e.length===0?k(F(N.COMPOUND_BLUEPRINT_EMPTY,`createCompoundBlueprint: at least one blueprint (outer boundary) is required`)):O(new xM(e))}function wU(e){return e.boundingBox}function TU(e){return e.orientation}function EU(e,t){return e.isInside(t)}function DU(e){return e.toSVGPathD()}function OU(e,t,n){return e.translate(t,n)}function kU(e,t,n){return e.rotate(t,n)}function AU(e,t,n){return e.scale(t,n)}function jU(e,t,n,r){return e.mirror(t,n,r)}function MU(e,t,n,r){return e.stretch(t,n,r)}function NU(e,t,n){return e.sketchOnPlane(t,n)}function PU(e,t,n){return e.sketchOnFace(t,n)}function FU(e,t){return n(e,t*3)}function IU(e,t){return n(e,t)}function LU(e){let t=[`# brepjs OBJ export`],n=e.vertices.length/3;for(let r=0;r<n;r++){let[n,i,a]=FU(e.vertices,r);t.push(`v ${n} ${i} ${a}`)}let r=e.normals.length/3;for(let n=0;n<r;n++){let[r,i,a]=FU(e.normals,n);t.push(`vn ${r} ${i} ${a}`)}let i=n=>{let[r,i,a]=IU(e.triangles,n);t.push(`f ${r+1}//${r+1} ${i+1}//${i+1} ${a+1}//${a+1}`)};if(e.faceGroups.length>0)for(let n of e.faceGroups){t.push(`g face_${n.faceId}`);let e=n.count/3;for(let t=0;t<e;t++)i(n.start+t*3)}else{let t=e.triangles.length/3;for(let e=0;e<t;e++)i(e*3)}return t.join(`
|
|
21
|
+
String.prototype.codePointAt||(function(){var e=function(){try{var e={},t=Object.defineProperty,n=t(e,e,e)&&t}catch{}return n}(),t=function(e){if(this==null)throw TypeError();var t=String(this),n=t.length,r=e?Number(e):0;if(r!=r&&(r=0),!(r<0||r>=n)){var i=t.charCodeAt(r),a;return i>=55296&&i<=56319&&n>r+1&&(a=t.charCodeAt(r+1),a>=56320&&a<=57343)?(i-55296)*1024+a-56320+65536:i}};e?e(String.prototype,`codePointAt`,{value:t,configurable:!0,writable:!0}):String.prototype.codePointAt=t})();var GN=0,KN=-3;function qN(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function JN(e,t){this.source=e,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=t,this.destLen=0,this.ltree=new qN,this.dtree=new qN}var YN=new qN,XN=new qN,ZN=new Uint8Array(30),QN=new Uint16Array(30),$N=new Uint8Array(30),eP=new Uint16Array(30),tP=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),nP=new qN,rP=new Uint8Array(320);function iP(e,t,n,r){var i,a;for(i=0;i<n;++i)e[i]=0;for(i=0;i<30-n;++i)e[i+n]=i/n|0;for(a=r,i=0;i<30;++i)t[i]=a,a+=1<<e[i]}function aP(e,t){var n;for(n=0;n<7;++n)e.table[n]=0;for(e.table[7]=24,e.table[8]=152,e.table[9]=112,n=0;n<24;++n)e.trans[n]=256+n;for(n=0;n<144;++n)e.trans[24+n]=n;for(n=0;n<8;++n)e.trans[168+n]=280+n;for(n=0;n<112;++n)e.trans[176+n]=144+n;for(n=0;n<5;++n)t.table[n]=0;for(t.table[5]=32,n=0;n<32;++n)t.trans[n]=n}var oP=new Uint16Array(16);function sP(e,t,n,r){var i,a;for(i=0;i<16;++i)e.table[i]=0;for(i=0;i<r;++i)e.table[t[n+i]]++;for(e.table[0]=0,a=0,i=0;i<16;++i)oP[i]=a,a+=e.table[i];for(i=0;i<r;++i)t[n+i]&&(e.trans[oP[t[n+i]]++]=i)}function cP(e){e.bitcount--||(e.tag=e.source[e.sourceIndex++],e.bitcount=7);var t=e.tag&1;return e.tag>>>=1,t}function lP(e,t,n){if(!t)return n;for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<<e.bitcount,e.bitcount+=8;var r=e.tag&65535>>>16-t;return e.tag>>>=t,e.bitcount-=t,r+n}function uP(e,t){for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<<e.bitcount,e.bitcount+=8;var n=0,r=0,i=0,a=e.tag;do r=2*r+(a&1),a>>>=1,++i,n+=t.table[i],r-=t.table[i];while(r>=0);return e.tag=a,e.bitcount-=i,t.trans[n+r]}function dP(e,t,n){var r=lP(e,5,257),i=lP(e,5,1),a=lP(e,4,4),o,s,c;for(o=0;o<19;++o)rP[o]=0;for(o=0;o<a;++o){var l=lP(e,3,0);rP[tP[o]]=l}for(sP(nP,rP,0,19),s=0;s<r+i;){var u=uP(e,nP);switch(u){case 16:var d=rP[s-1];for(c=lP(e,2,3);c;--c)rP[s++]=d;break;case 17:for(c=lP(e,3,3);c;--c)rP[s++]=0;break;case 18:for(c=lP(e,7,11);c;--c)rP[s++]=0;break;default:rP[s++]=u;break}}sP(t,rP,0,r),sP(n,rP,r,i)}function fP(e,t,n){for(;;){var r=uP(e,t);if(r===256)return GN;if(r<256)e.dest[e.destLen++]=r;else{var i,a,o,s;for(r-=257,i=lP(e,ZN[r],QN[r]),a=uP(e,n),o=e.destLen-lP(e,$N[a],eP[a]),s=o;s<o+i;++s)e.dest[e.destLen++]=e.dest[s]}}}function pP(e){for(var t,n,r;e.bitcount>8;)e.sourceIndex--,e.bitcount-=8;if(t=e.source[e.sourceIndex+1],t=256*t+e.source[e.sourceIndex],n=e.source[e.sourceIndex+3],n=256*n+e.source[e.sourceIndex+2],t!==(~n&65535))return KN;for(e.sourceIndex+=4,r=t;r;--r)e.dest[e.destLen++]=e.source[e.sourceIndex++];return e.bitcount=0,GN}function mP(e,t){var n=new JN(e,t),r,i,a;do{switch(r=cP(n),i=lP(n,2,0),i){case 0:a=pP(n);break;case 1:a=fP(n,YN,XN);break;case 2:dP(n,n.ltree,n.dtree),a=fP(n,n.ltree,n.dtree);break;default:a=KN}if(a!==GN)throw Error(`Data error`)}while(!r);return n.destLen<n.dest.length?typeof n.dest.slice==`function`?n.dest.slice(0,n.destLen):n.dest.subarray(0,n.destLen):n.dest}aP(YN,XN),iP(ZN,QN,4,3),iP($N,eP,2,1),ZN[28]=0,QN[28]=258;var hP=mP;function gP(e,t,n,r,i){return(1-i)**3*e+3*(1-i)**2*i*t+3*(1-i)*i**2*n+i**3*r}function _P(){this.x1=NaN,this.y1=NaN,this.x2=NaN,this.y2=NaN}_P.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)},_P.prototype.addPoint=function(e,t){typeof e==`number`&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=e,this.x2=e),e<this.x1&&(this.x1=e),e>this.x2&&(this.x2=e)),typeof t==`number`&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=t,this.y2=t),t<this.y1&&(this.y1=t),t>this.y2&&(this.y2=t))},_P.prototype.addX=function(e){this.addPoint(e,null)},_P.prototype.addY=function(e){this.addPoint(null,e)},_P.prototype.addBezier=function(e,t,n,r,i,a,o,s){var c=[e,t],l=[n,r],u=[i,a],d=[o,s];this.addPoint(e,t),this.addPoint(o,s);for(var f=0;f<=1;f++){var p=6*c[f]-12*l[f]+6*u[f],m=-3*c[f]+9*l[f]-9*u[f]+3*d[f],h=3*l[f]-3*c[f];if(m===0){if(p===0)continue;var g=-h/p;0<g&&g<1&&(f===0&&this.addX(gP(c[f],l[f],u[f],d[f],g)),f===1&&this.addY(gP(c[f],l[f],u[f],d[f],g)));continue}var _=p**2-4*h*m;if(!(_<0)){var v=(-p+Math.sqrt(_))/(2*m);0<v&&v<1&&(f===0&&this.addX(gP(c[f],l[f],u[f],d[f],v)),f===1&&this.addY(gP(c[f],l[f],u[f],d[f],v)));var y=(-p-Math.sqrt(_))/(2*m);0<y&&y<1&&(f===0&&this.addX(gP(c[f],l[f],u[f],d[f],y)),f===1&&this.addY(gP(c[f],l[f],u[f],d[f],y)))}}},_P.prototype.addQuad=function(e,t,n,r,i,a){var o=e+2/3*(n-e),s=t+2/3*(r-t),c=o+1/3*(i-e),l=s+1/3*(a-t);this.addBezier(e,t,o,s,c,l,i,a)};function vP(){this.commands=[],this.fill=`black`,this.stroke=null,this.strokeWidth=1}vP.prototype.moveTo=function(e,t){this.commands.push({type:`M`,x:e,y:t})},vP.prototype.lineTo=function(e,t){this.commands.push({type:`L`,x:e,y:t})},vP.prototype.curveTo=vP.prototype.bezierCurveTo=function(e,t,n,r,i,a){this.commands.push({type:`C`,x1:e,y1:t,x2:n,y2:r,x:i,y:a})},vP.prototype.quadTo=vP.prototype.quadraticCurveTo=function(e,t,n,r){this.commands.push({type:`Q`,x1:e,y1:t,x:n,y:r})},vP.prototype.close=vP.prototype.closePath=function(){this.commands.push({type:`Z`})},vP.prototype.extend=function(e){if(e.commands)e=e.commands;else if(e instanceof _P){var t=e;this.moveTo(t.x1,t.y1),this.lineTo(t.x2,t.y1),this.lineTo(t.x2,t.y2),this.lineTo(t.x1,t.y2),this.close();return}Array.prototype.push.apply(this.commands,e)},vP.prototype.getBoundingBox=function(){for(var e=new _P,t=0,n=0,r=0,i=0,a=0;a<this.commands.length;a++){var o=this.commands[a];switch(o.type){case`M`:e.addPoint(o.x,o.y),t=r=o.x,n=i=o.y;break;case`L`:e.addPoint(o.x,o.y),r=o.x,i=o.y;break;case`Q`:e.addQuad(r,i,o.x1,o.y1,o.x,o.y),r=o.x,i=o.y;break;case`C`:e.addBezier(r,i,o.x1,o.y1,o.x2,o.y2,o.x,o.y),r=o.x,i=o.y;break;case`Z`:r=t,i=n;break;default:throw Error(`Unexpected path command `+o.type)}}return e.isEmpty()&&e.addPoint(0,0),e},vP.prototype.draw=function(e){e.beginPath();for(var t=0;t<this.commands.length;t+=1){var n=this.commands[t];n.type===`M`?e.moveTo(n.x,n.y):n.type===`L`?e.lineTo(n.x,n.y):n.type===`C`?e.bezierCurveTo(n.x1,n.y1,n.x2,n.y2,n.x,n.y):n.type===`Q`?e.quadraticCurveTo(n.x1,n.y1,n.x,n.y):n.type===`Z`&&e.closePath()}this.fill&&(e.fillStyle=this.fill,e.fill()),this.stroke&&(e.strokeStyle=this.stroke,e.lineWidth=this.strokeWidth,e.stroke())},vP.prototype.toPathData=function(e){e=e===void 0?2:e;function t(t){return Math.round(t)===t?``+Math.round(t):t.toFixed(e)}function n(){for(var e=arguments,n=``,r=0;r<arguments.length;r+=1){var i=e[r];i>=0&&r>0&&(n+=` `),n+=t(i)}return n}for(var r=``,i=0;i<this.commands.length;i+=1){var a=this.commands[i];a.type===`M`?r+=`M`+n(a.x,a.y):a.type===`L`?r+=`L`+n(a.x,a.y):a.type===`C`?r+=`C`+n(a.x1,a.y1,a.x2,a.y2,a.x,a.y):a.type===`Q`?r+=`Q`+n(a.x1,a.y1,a.x,a.y):a.type===`Z`&&(r+=`Z`)}return r},vP.prototype.toSVG=function(e){var t=`<path d="`;return t+=this.toPathData(e),t+=`"`,this.fill&&this.fill!==`black`&&(this.fill===null?t+=` fill="none"`:t+=` fill="`+this.fill+`"`),this.stroke&&(t+=` stroke="`+this.stroke+`" stroke-width="`+this.strokeWidth+`"`),t+=`/>`,t},vP.prototype.toDOMElement=function(e){var t=this.toPathData(e),n=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return n.setAttribute(`d`,t),n};function yP(e){throw Error(e)}function bP(e,t){e||yP(t)}var K={fail:yP,argument:bP,assert:bP},xP=32768,SP=2147483648,CP={},q={},J={};function wP(e){return function(){return e}}q.BYTE=function(e){return K.argument(e>=0&&e<=255,`Byte value should be between 0 and 255.`),[e]},J.BYTE=wP(1),q.CHAR=function(e){return[e.charCodeAt(0)]},J.CHAR=wP(1),q.CHARARRAY=function(e){e===void 0&&(e=``,console.warn(`Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name.`));for(var t=[],n=0;n<e.length;n+=1)t[n]=e.charCodeAt(n);return t},J.CHARARRAY=function(e){return e===void 0?0:e.length},q.USHORT=function(e){return[e>>8&255,e&255]},J.USHORT=wP(2),q.SHORT=function(e){return e>=xP&&(e=-(2*xP-e)),[e>>8&255,e&255]},J.SHORT=wP(2),q.UINT24=function(e){return[e>>16&255,e>>8&255,e&255]},J.UINT24=wP(3),q.ULONG=function(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]},J.ULONG=wP(4),q.LONG=function(e){return e>=SP&&(e=-(2*SP-e)),[e>>24&255,e>>16&255,e>>8&255,e&255]},J.LONG=wP(4),q.FIXED=q.ULONG,J.FIXED=J.ULONG,q.FWORD=q.SHORT,J.FWORD=J.SHORT,q.UFWORD=q.USHORT,J.UFWORD=J.USHORT,q.LONGDATETIME=function(e){return[0,0,0,0,e>>24&255,e>>16&255,e>>8&255,e&255]},J.LONGDATETIME=wP(8),q.TAG=function(e){return K.argument(e.length===4,`Tag should be exactly 4 ASCII characters.`),[e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3)]},J.TAG=wP(4),q.Card8=q.BYTE,J.Card8=J.BYTE,q.Card16=q.USHORT,J.Card16=J.USHORT,q.OffSize=q.BYTE,J.OffSize=J.BYTE,q.SID=q.USHORT,J.SID=J.USHORT,q.NUMBER=function(e){return e>=-107&&e<=107?[e+139]:e>=108&&e<=1131?(e-=108,[(e>>8)+247,e&255]):e>=-1131&&e<=-108?(e=-e-108,[(e>>8)+251,e&255]):e>=-32768&&e<=32767?q.NUMBER16(e):q.NUMBER32(e)},J.NUMBER=function(e){return q.NUMBER(e).length},q.NUMBER16=function(e){return[28,e>>8&255,e&255]},J.NUMBER16=wP(3),q.NUMBER32=function(e){return[29,e>>24&255,e>>16&255,e>>8&255,e&255]},J.NUMBER32=wP(5),q.REAL=function(e){var t=e.toString(),n=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(t);if(n){var r=parseFloat(`1e`+((n[2]?+n[2]:0)+n[1].length));t=(Math.round(e*r)/r).toString()}for(var i=``,a=0,o=t.length;a<o;a+=1){var s=t[a];s===`e`?i+=t[++a]===`-`?`c`:`b`:s===`.`?i+=`a`:s===`-`?i+=`e`:i+=s}i+=i.length&1?`f`:`ff`;for(var c=[30],l=0,u=i.length;l<u;l+=2)c.push(parseInt(i.substr(l,2),16));return c},J.REAL=function(e){return q.REAL(e).length},q.NAME=q.CHARARRAY,J.NAME=J.CHARARRAY,q.STRING=q.CHARARRAY,J.STRING=J.CHARARRAY,CP.UTF8=function(e,t,n){for(var r=[],i=n,a=0;a<i;a++,t+=1)r[a]=e.getUint8(t);return String.fromCharCode.apply(null,r)},CP.UTF16=function(e,t,n){for(var r=[],i=n/2,a=0;a<i;a++,t+=2)r[a]=e.getUint16(t);return String.fromCharCode.apply(null,r)},q.UTF16=function(e){for(var t=[],n=0;n<e.length;n+=1){var r=e.charCodeAt(n);t[t.length]=r>>8&255,t[t.length]=r&255}return t},J.UTF16=function(e){return e.length*2};var TP={"x-mac-croatian":`ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®Š™´¨≠ŽØ∞±≤≥∆µ∂∑∏š∫ªºΩžø¿¡¬√ƒ≈ƫȅ\xA0ÀÃÕŒœĐ—“”‘’÷◊©⁄€‹›Æ»–·‚„‰ÂćÁčÈÍÎÏÌÓÔđÒÚÛÙıˆ˜¯πË˚¸Êæˇ`,"x-mac-cyrillic":`АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњјЅ¬√ƒ≈∆«»…\xA0ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю`,"x-mac-gaelic":`ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØḂ±≤≥ḃĊċḊḋḞḟĠġṀæøṁṖṗɼƒſṠ«»…\xA0ÀÃÕŒœ–—“”‘’ṡẛÿŸṪ€‹›Ŷŷṫ·Ỳỳ⁊ÂÊÁËÈÍÎÏÌÓÔ♣ÒÚÛÙıÝýŴŵẄẅẀẁẂẃ`,"x-mac-greek":`Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩάΝ¬ΟΡ≈Τ«»…\xA0ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ`,"x-mac-icelandic":`ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûüݰ¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»…\xA0ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€ÐðÞþý·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ`,"x-mac-inuit":`ᐃᐄᐅᐆᐊᐋᐱᐲᐳᐴᐸᐹᑉᑎᑏᑐᑑᑕᑖᑦᑭᑮᑯᑰᑲᑳᒃᒋᒌᒍᒎᒐᒑ°ᒡᒥᒦ•¶ᒧ®©™ᒨᒪᒫᒻᓂᓃᓄᓅᓇᓈᓐᓯᓰᓱᓲᓴᓵᔅᓕᓖᓗᓘᓚᓛᓪᔨᔩᔪᔫᔭ…\xA0ᔮᔾᕕᕖᕗ–—“”‘’ᕘᕙᕚᕝᕆᕇᕈᕉᕋᕌᕐᕿᖀᖁᖂᖃᖄᖅᖏᖐᖑᖒᖓᖔᖕᙱᙲᙳᙴᙵᙶᖖᖠᖡᖢᖣᖤᖥᖦᕼŁł`,"x-mac-ce":`ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅņѬ√ńŇ∆«»…\xA0ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ`,macintosh:`ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»…\xA0ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ`,"x-mac-romanian":`ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ĂȘ∞±≤≥¥µ∂∑∏π∫ªºΩăș¿¡¬√ƒ≈∆«»…\xA0ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›Țț‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ`,"x-mac-turkish":`ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»…\xA0ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ`};CP.MACSTRING=function(e,t,n,r){var i=TP[r];if(i!==void 0){for(var a=``,o=0;o<n;o++){var s=e.getUint8(t+o);s<=127?a+=String.fromCharCode(s):a+=i[s&127]}return a}};var EP=typeof WeakMap==`function`&&new WeakMap,DP,OP=function(e){if(!DP)for(var t in DP={},TP)DP[t]=new String(t);var n=DP[e];if(n!==void 0){if(EP){var r=EP.get(n);if(r!==void 0)return r}var i=TP[e];if(i!==void 0){for(var a={},o=0;o<i.length;o++)a[i.charCodeAt(o)]=o+128;return EP&&EP.set(n,a),a}}};q.MACSTRING=function(e,t){var n=OP(t);if(n!==void 0){for(var r=[],i=0;i<e.length;i++){var a=e.charCodeAt(i);if(a>=128&&(a=n[a],a===void 0))return;r[i]=a}return r}},J.MACSTRING=function(e,t){var n=q.MACSTRING(e,t);return n===void 0?0:n.length};function kP(e){return e>=-128&&e<=127}function AP(e,t,n){for(var r=0,i=e.length;t<i&&r<64&&e[t]===0;)++t,++r;return n.push(128|r-1),t}function jP(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(!kP(o)||o===0&&a+1<i&&e[a+1]===0)break;++a,++r}n.push(r-1);for(var s=t;s<a;++s)n.push(e[s]+256&255);return a}function MP(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(o===0||kP(o)&&a+1<i&&kP(e[a+1]))break;++a,++r}n.push(64|r-1);for(var s=t;s<a;++s){var c=e[s];n.push(c+65536>>8&255,c+256&255)}return a}q.VARDELTAS=function(e){for(var t=0,n=[];t<e.length;){var r=e[t];t=r===0?AP(e,t,n):r>=-128&&r<=127?jP(e,t,n):MP(e,t,n)}return n},q.INDEX=function(e){for(var t=1,n=[t],r=[],i=0;i<e.length;i+=1){var a=q.OBJECT(e[i]);Array.prototype.push.apply(r,a),t+=a.length,n.push(t)}if(r.length===0)return[0,0];for(var o=[],s=1+Math.floor(Math.log(t)/Math.log(2))/8|0,c=[void 0,q.BYTE,q.USHORT,q.UINT24,q.ULONG][s],l=0;l<n.length;l+=1){var u=c(n[l]);Array.prototype.push.apply(o,u)}return Array.prototype.concat(q.Card16(e.length),q.OffSize(s),o,r)},J.INDEX=function(e){return q.INDEX(e).length},q.DICT=function(e){for(var t=[],n=Object.keys(e),r=n.length,i=0;i<r;i+=1){var a=parseInt(n[i],0),o=e[a];t=t.concat(q.OPERAND(o.value,o.type)),t=t.concat(q.OPERATOR(a))}return t},J.DICT=function(e){return q.DICT(e).length},q.OPERATOR=function(e){return e<1200?[e]:[12,e-1200]},q.OPERAND=function(e,t){var n=[];if(Array.isArray(t))for(var r=0;r<t.length;r+=1)K.argument(e.length===t.length,`Not enough arguments given for type`+t),n=n.concat(q.OPERAND(e[r],t[r]));else if(t===`SID`)n=n.concat(q.NUMBER(e));else if(t===`offset`)n=n.concat(q.NUMBER32(e));else if(t===`number`)n=n.concat(q.NUMBER(e));else if(t===`real`)n=n.concat(q.REAL(e));else throw Error(`Unknown operand type `+t);return n},q.OP=q.BYTE,J.OP=J.BYTE;var NP=typeof WeakMap==`function`&&new WeakMap;q.CHARSTRING=function(e){if(NP){var t=NP.get(e);if(t!==void 0)return t}for(var n=[],r=e.length,i=0;i<r;i+=1){var a=e[i];n=n.concat(q[a.type](a.value))}return NP&&NP.set(e,n),n},J.CHARSTRING=function(e){return q.CHARSTRING(e).length},q.OBJECT=function(e){var t=q[e.type];return K.argument(t!==void 0,`No encoding function for type `+e.type),t(e.value)},J.OBJECT=function(e){var t=J[e.type];return K.argument(t!==void 0,`No sizeOf function for type `+e.type),t(e.value)},q.TABLE=function(e){for(var t=[],n=e.fields.length,r=[],i=[],a=0;a<n;a+=1){var o=e.fields[a],s=q[o.type];K.argument(s!==void 0,`No encoding function for field type `+o.type+` (`+o.name+`)`);var c=e[o.name];c===void 0&&(c=o.value);var l=s(c);o.type===`TABLE`?(i.push(t.length),t=t.concat([0,0]),r.push(l)):t=t.concat(l)}for(var u=0;u<r.length;u+=1){var d=i[u],f=t.length;K.argument(f<65536,`Table `+e.tableName+` too big.`),t[d]=f>>8,t[d+1]=f&255,t=t.concat(r[u])}return t},J.TABLE=function(e){for(var t=0,n=e.fields.length,r=0;r<n;r+=1){var i=e.fields[r],a=J[i.type];K.argument(a!==void 0,`No sizeOf function for field type `+i.type+` (`+i.name+`)`);var o=e[i.name];o===void 0&&(o=i.value),t+=a(o),i.type===`TABLE`&&(t+=2)}return t},q.RECORD=q.TABLE,J.RECORD=J.TABLE,q.LITERAL=function(e){return e},J.LITERAL=function(e){return e.length};function PP(e,t,n){if(t.length&&(t[0].name!==`coverageFormat`||t[0].value===1))for(var r=0;r<t.length;r+=1){var i=t[r];this[i.name]=i.value}if(this.tableName=e,this.fields=t,n)for(var a=Object.keys(n),o=0;o<a.length;o+=1){var s=a[o],c=n[s];this[s]!==void 0&&(this[s]=c)}}PP.prototype.encode=function(){return q.TABLE(this)},PP.prototype.sizeOf=function(){return J.TABLE(this)};function FP(e,t,n){n===void 0&&(n=t.length);var r=Array(t.length+1);r[0]={name:e+`Count`,type:`USHORT`,value:n};for(var i=0;i<t.length;i++)r[i+1]={name:e+i,type:`USHORT`,value:t[i]};return r}function IP(e,t,n){var r=t.length,i=Array(r+1);i[0]={name:e+`Count`,type:`USHORT`,value:r};for(var a=0;a<r;a++)i[a+1]={name:e+a,type:`TABLE`,value:n(t[a],a)};return i}function LP(e,t,n){var r=t.length,i=[];i[0]={name:e+`Count`,type:`USHORT`,value:r};for(var a=0;a<r;a++)i=i.concat(n(t[a],a));return i}function RP(e){e.format===1?PP.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:1}].concat(FP(`glyph`,e.glyphs))):e.format===2?PP.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:2}].concat(LP(`rangeRecord`,e.ranges,function(e){return[{name:`startGlyphID`,type:`USHORT`,value:e.start},{name:`endGlyphID`,type:`USHORT`,value:e.end},{name:`startCoverageIndex`,type:`USHORT`,value:e.index}]}))):K.assert(!1,`Coverage format must be 1 or 2.`)}RP.prototype=Object.create(PP.prototype),RP.prototype.constructor=RP;function zP(e){PP.call(this,`scriptListTable`,LP(`scriptRecord`,e,function(e,t){var n=e.script,r=n.defaultLangSys;return K.assert(!!r,`Unable to write GSUB: script `+e.tag+` has no default language system.`),[{name:`scriptTag`+t,type:`TAG`,value:e.tag},{name:`script`+t,type:`TABLE`,value:new PP(`scriptTable`,[{name:`defaultLangSys`,type:`TABLE`,value:new PP(`defaultLangSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:r.reqFeatureIndex}].concat(FP(`featureIndex`,r.featureIndexes)))}].concat(LP(`langSys`,n.langSysRecords,function(e,t){var n=e.langSys;return[{name:`langSysTag`+t,type:`TAG`,value:e.tag},{name:`langSys`+t,type:`TABLE`,value:new PP(`langSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:n.reqFeatureIndex}].concat(FP(`featureIndex`,n.featureIndexes)))}]})))}]}))}zP.prototype=Object.create(PP.prototype),zP.prototype.constructor=zP;function BP(e){PP.call(this,`featureListTable`,LP(`featureRecord`,e,function(e,t){var n=e.feature;return[{name:`featureTag`+t,type:`TAG`,value:e.tag},{name:`feature`+t,type:`TABLE`,value:new PP(`featureTable`,[{name:`featureParams`,type:`USHORT`,value:n.featureParams}].concat(FP(`lookupListIndex`,n.lookupListIndexes)))}]}))}BP.prototype=Object.create(PP.prototype),BP.prototype.constructor=BP;function VP(e,t){PP.call(this,`lookupListTable`,IP(`lookup`,e,function(e){var n=t[e.lookupType];return K.assert(!!n,`Unable to write GSUB lookup type `+e.lookupType+` tables.`),new PP(`lookupTable`,[{name:`lookupType`,type:`USHORT`,value:e.lookupType},{name:`lookupFlag`,type:`USHORT`,value:e.lookupFlag}].concat(IP(`subtable`,e.subtables,n)))}))}VP.prototype=Object.create(PP.prototype),VP.prototype.constructor=VP;var Y={Table:PP,Record:PP,Coverage:RP,ScriptList:zP,FeatureList:BP,LookupList:VP,ushortList:FP,tableList:IP,recordList:LP};function HP(e,t){return e.getUint8(t)}function UP(e,t){return e.getUint16(t,!1)}function WP(e,t){return e.getInt16(t,!1)}function GP(e,t){return e.getUint32(t,!1)}function KP(e,t){return e.getInt16(t,!1)+e.getUint16(t+2,!1)/65535}function qP(e,t){for(var n=``,r=t;r<t+4;r+=1)n+=String.fromCharCode(e.getInt8(r));return n}function JP(e,t,n){for(var r=0,i=0;i<n;i+=1)r<<=8,r+=e.getUint8(t+i);return r}function YP(e,t,n){for(var r=[],i=t;i<n;i+=1)r.push(e.getUint8(i));return r}function XP(e){for(var t=``,n=0;n<e.length;n+=1)t+=String.fromCharCode(e[n]);return t}var ZP={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function X(e,t){this.data=e,this.offset=t,this.relativeOffset=0}X.prototype.parseByte=function(){var e=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,e},X.prototype.parseChar=function(){var e=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,e},X.prototype.parseCard8=X.prototype.parseByte,X.prototype.parseUShort=function(){var e=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,e},X.prototype.parseCard16=X.prototype.parseUShort,X.prototype.parseSID=X.prototype.parseUShort,X.prototype.parseOffset16=X.prototype.parseUShort,X.prototype.parseShort=function(){var e=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,e},X.prototype.parseF2Dot14=function(){var e=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,e},X.prototype.parseULong=function(){var e=GP(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,e},X.prototype.parseOffset32=X.prototype.parseULong,X.prototype.parseFixed=function(){var e=KP(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,e},X.prototype.parseString=function(e){var t=this.data,n=this.offset+this.relativeOffset,r=``;this.relativeOffset+=e;for(var i=0;i<e;i++)r+=String.fromCharCode(t.getUint8(n+i));return r},X.prototype.parseTag=function(){return this.parseString(4)},X.prototype.parseLongDateTime=function(){var e=GP(this.data,this.offset+this.relativeOffset+4);return e-=2082844800,this.relativeOffset+=8,e},X.prototype.parseVersion=function(e){var t=UP(this.data,this.offset+this.relativeOffset),n=UP(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,e===void 0&&(e=4096),t+n/e/10},X.prototype.skip=function(e,t){t===void 0&&(t=1),this.relativeOffset+=ZP[e]*t},X.prototype.parseULongList=function(e){e===void 0&&(e=this.parseULong());for(var t=Array(e),n=this.data,r=this.offset+this.relativeOffset,i=0;i<e;i++)t[i]=n.getUint32(r),r+=4;return this.relativeOffset+=e*4,t},X.prototype.parseOffset16List=X.prototype.parseUShortList=function(e){e===void 0&&(e=this.parseUShort());for(var t=Array(e),n=this.data,r=this.offset+this.relativeOffset,i=0;i<e;i++)t[i]=n.getUint16(r),r+=2;return this.relativeOffset+=e*2,t},X.prototype.parseShortList=function(e){for(var t=Array(e),n=this.data,r=this.offset+this.relativeOffset,i=0;i<e;i++)t[i]=n.getInt16(r),r+=2;return this.relativeOffset+=e*2,t},X.prototype.parseByteList=function(e){for(var t=Array(e),n=this.data,r=this.offset+this.relativeOffset,i=0;i<e;i++)t[i]=n.getUint8(r++);return this.relativeOffset+=e,t},X.prototype.parseList=function(e,t){t||(t=e,e=this.parseUShort());for(var n=Array(e),r=0;r<e;r++)n[r]=t.call(this);return n},X.prototype.parseList32=function(e,t){t||(t=e,e=this.parseULong());for(var n=Array(e),r=0;r<e;r++)n[r]=t.call(this);return n},X.prototype.parseRecordList=function(e,t){t||(t=e,e=this.parseUShort());for(var n=Array(e),r=Object.keys(t),i=0;i<e;i++){for(var a={},o=0;o<r.length;o++){var s=r[o];a[s]=t[s].call(this)}n[i]=a}return n},X.prototype.parseRecordList32=function(e,t){t||(t=e,e=this.parseULong());for(var n=Array(e),r=Object.keys(t),i=0;i<e;i++){for(var a={},o=0;o<r.length;o++){var s=r[o];a[s]=t[s].call(this)}n[i]=a}return n},X.prototype.parseStruct=function(e){if(typeof e==`function`)return e.call(this);for(var t=Object.keys(e),n={},r=0;r<t.length;r++){var i=t[r];n[i]=e[i].call(this)}return n},X.prototype.parseValueRecord=function(e){if(e===void 0&&(e=this.parseUShort()),e!==0){var t={};return e&1&&(t.xPlacement=this.parseShort()),e&2&&(t.yPlacement=this.parseShort()),e&4&&(t.xAdvance=this.parseShort()),e&8&&(t.yAdvance=this.parseShort()),e&16&&(t.xPlaDevice=void 0,this.parseShort()),e&32&&(t.yPlaDevice=void 0,this.parseShort()),e&64&&(t.xAdvDevice=void 0,this.parseShort()),e&128&&(t.yAdvDevice=void 0,this.parseShort()),t}},X.prototype.parseValueRecordList=function(){for(var e=this.parseUShort(),t=this.parseUShort(),n=Array(t),r=0;r<t;r++)n[r]=this.parseValueRecord(e);return n},X.prototype.parsePointer=function(e){var t=this.parseOffset16();if(t>0)return new X(this.data,this.offset+t).parseStruct(e)},X.prototype.parsePointer32=function(e){var t=this.parseOffset32();if(t>0)return new X(this.data,this.offset+t).parseStruct(e)},X.prototype.parseListOfLists=function(e){for(var t=this.parseOffset16List(),n=t.length,r=this.relativeOffset,i=Array(n),a=0;a<n;a++){var o=t[a];if(o===0){i[a]=void 0;continue}if(this.relativeOffset=o,e){for(var s=this.parseOffset16List(),c=Array(s.length),l=0;l<s.length;l++)this.relativeOffset=o+s[l],c[l]=e.call(this);i[a]=c}else i[a]=this.parseUShortList()}return this.relativeOffset=r,i},X.prototype.parseCoverage=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort(),n=this.parseUShort();if(t===1)return{format:1,glyphs:this.parseUShortList(n)};if(t===2){for(var r=Array(n),i=0;i<n;i++)r[i]={start:this.parseUShort(),end:this.parseUShort(),index:this.parseUShort()};return{format:2,ranges:r}}throw Error(`0x`+e.toString(16)+`: Coverage format must be 1 or 2.`)},X.prototype.parseClassDef=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{format:1,startGlyph:this.parseUShort(),classes:this.parseUShortList()};if(t===2)return{format:2,ranges:this.parseRecordList({start:X.uShort,end:X.uShort,classId:X.uShort})};throw Error(`0x`+e.toString(16)+`: ClassDef format must be 1 or 2.`)},X.list=function(e,t){return function(){return this.parseList(e,t)}},X.list32=function(e,t){return function(){return this.parseList32(e,t)}},X.recordList=function(e,t){return function(){return this.parseRecordList(e,t)}},X.recordList32=function(e,t){return function(){return this.parseRecordList32(e,t)}},X.pointer=function(e){return function(){return this.parsePointer(e)}},X.pointer32=function(e){return function(){return this.parsePointer32(e)}},X.tag=X.prototype.parseTag,X.byte=X.prototype.parseByte,X.uShort=X.offset16=X.prototype.parseUShort,X.uShortList=X.prototype.parseUShortList,X.uLong=X.offset32=X.prototype.parseULong,X.uLongList=X.prototype.parseULongList,X.struct=X.prototype.parseStruct,X.coverage=X.prototype.parseCoverage,X.classDef=X.prototype.parseClassDef;var QP={reserved:X.uShort,reqFeatureIndex:X.uShort,featureIndexes:X.uShortList};X.prototype.parseScriptList=function(){return this.parsePointer(X.recordList({tag:X.tag,script:X.pointer({defaultLangSys:X.pointer(QP),langSysRecords:X.recordList({tag:X.tag,langSys:X.pointer(QP)})})}))||[]},X.prototype.parseFeatureList=function(){return this.parsePointer(X.recordList({tag:X.tag,feature:X.pointer({featureParams:X.offset16,lookupListIndexes:X.uShortList})}))||[]},X.prototype.parseLookupList=function(e){return this.parsePointer(X.list(X.pointer(function(){var t=this.parseUShort();K.argument(1<=t&&t<=9,`GPOS/GSUB lookup type `+t+` unknown.`);var n=this.parseUShort(),r=n&16;return{lookupType:t,lookupFlag:n,subtables:this.parseList(X.pointer(e[t])),markFilteringSet:r?this.parseUShort():void 0}})))||[]},X.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var e=this.parseUShort(),t=this.parseUShort();return K.argument(e===1&&t<1,`GPOS/GSUB feature variations table unknown.`),this.parseRecordList32({conditionSetOffset:X.offset32,featureTableSubstitutionOffset:X.offset32})})||[]};var Z={getByte:HP,getCard8:HP,getUShort:UP,getCard16:UP,getShort:WP,getULong:GP,getFixed:KP,getTag:qP,getOffset:JP,getBytes:YP,bytesToString:XP,Parser:X};function $P(e,t){t.parseUShort(),e.length=t.parseULong(),e.language=t.parseULong();var n;e.groupCount=n=t.parseULong(),e.glyphIndexMap={};for(var r=0;r<n;r+=1)for(var i=t.parseULong(),a=t.parseULong(),o=t.parseULong(),s=i;s<=a;s+=1)e.glyphIndexMap[s]=o,o++}function eF(e,t,n,r,i){e.length=t.parseUShort(),e.language=t.parseUShort();var a;e.segCount=a=t.parseUShort()>>1,t.skip(`uShort`,3),e.glyphIndexMap={};for(var o=new Z.Parser(n,r+i+14),s=new Z.Parser(n,r+i+16+a*2),c=new Z.Parser(n,r+i+16+a*4),l=new Z.Parser(n,r+i+16+a*6),u=r+i+16+a*8,d=0;d<a-1;d+=1)for(var f=void 0,p=o.parseUShort(),m=s.parseUShort(),h=c.parseShort(),g=l.parseUShort(),_=m;_<=p;_+=1)g===0?f=_+h&65535:(u=l.offset+l.relativeOffset-2,u+=g,u+=(_-m)*2,f=Z.getUShort(n,u),f!==0&&(f=f+h&65535)),e.glyphIndexMap[_]=f}function tF(e,t){var n={};n.version=Z.getUShort(e,t),K.argument(n.version===0,`cmap table version should be 0.`),n.numTables=Z.getUShort(e,t+2);for(var r=-1,i=n.numTables-1;i>=0;--i){var a=Z.getUShort(e,t+4+i*8),o=Z.getUShort(e,t+4+i*8+2);if(a===3&&(o===0||o===1||o===10)||a===0&&(o===0||o===1||o===2||o===3||o===4)){r=Z.getULong(e,t+4+i*8+4);break}}if(r===-1)throw Error(`No valid cmap sub-tables found.`);var s=new Z.Parser(e,t+r);if(n.format=s.parseUShort(),n.format===12)$P(n,s);else if(n.format===4)eF(n,s,e,t,r);else throw Error(`Only format 4 and 12 cmap tables are supported (found format `+n.format+`).`);return n}function nF(e,t,n){e.segments.push({end:t,start:t,delta:-(t-n),offset:0,glyphIndex:n})}function rF(e){e.segments.push({end:65535,start:65535,delta:1,offset:0})}function iF(e){var t=!0,n;for(n=e.length-1;n>0;--n)if(e.get(n).unicode>65535){console.log(`Adding CMAP format 12 (needed!)`),t=!1;break}var r=[{name:`version`,type:`USHORT`,value:0},{name:`numTables`,type:`USHORT`,value:t?1:2},{name:`platformID`,type:`USHORT`,value:3},{name:`encodingID`,type:`USHORT`,value:1},{name:`offset`,type:`ULONG`,value:t?12:20}];t||(r=r.concat([{name:`cmap12PlatformID`,type:`USHORT`,value:3},{name:`cmap12EncodingID`,type:`USHORT`,value:10},{name:`cmap12Offset`,type:`ULONG`,value:0}])),r=r.concat([{name:`format`,type:`USHORT`,value:4},{name:`cmap4Length`,type:`USHORT`,value:0},{name:`language`,type:`USHORT`,value:0},{name:`segCountX2`,type:`USHORT`,value:0},{name:`searchRange`,type:`USHORT`,value:0},{name:`entrySelector`,type:`USHORT`,value:0},{name:`rangeShift`,type:`USHORT`,value:0}]);var i=new Y.Table(`cmap`,r);for(i.segments=[],n=0;n<e.length;n+=1){for(var a=e.get(n),o=0;o<a.unicodes.length;o+=1)nF(i,a.unicodes[o],n);i.segments=i.segments.sort(function(e,t){return e.start-t.start})}rF(i);var s=i.segments.length,c=0,l=[],u=[],d=[],f=[],p=[],m=[];for(n=0;n<s;n+=1){var h=i.segments[n];h.end<=65535&&h.start<=65535?(l=l.concat({name:`end_`+n,type:`USHORT`,value:h.end}),u=u.concat({name:`start_`+n,type:`USHORT`,value:h.start}),d=d.concat({name:`idDelta_`+n,type:`SHORT`,value:h.delta}),f=f.concat({name:`idRangeOffset_`+n,type:`USHORT`,value:h.offset}),h.glyphId!==void 0&&(p=p.concat({name:`glyph_`+n,type:`USHORT`,value:h.glyphId}))):c+=1,!t&&h.glyphIndex!==void 0&&(m=m.concat({name:`cmap12Start_`+n,type:`ULONG`,value:h.start}),m=m.concat({name:`cmap12End_`+n,type:`ULONG`,value:h.end}),m=m.concat({name:`cmap12Glyph_`+n,type:`ULONG`,value:h.glyphIndex}))}if(i.segCountX2=(s-c)*2,i.searchRange=2**Math.floor(Math.log(s-c)/Math.log(2))*2,i.entrySelector=Math.log(i.searchRange/2)/Math.log(2),i.rangeShift=i.segCountX2-i.searchRange,i.fields=i.fields.concat(l),i.fields.push({name:`reservedPad`,type:`USHORT`,value:0}),i.fields=i.fields.concat(u),i.fields=i.fields.concat(d),i.fields=i.fields.concat(f),i.fields=i.fields.concat(p),i.cmap4Length=14+l.length*2+2+u.length*2+d.length*2+f.length*2+p.length*2,!t){var g=16+m.length*4;i.cmap12Offset=20+i.cmap4Length,i.fields=i.fields.concat([{name:`cmap12Format`,type:`USHORT`,value:12},{name:`cmap12Reserved`,type:`USHORT`,value:0},{name:`cmap12Length`,type:`ULONG`,value:g},{name:`cmap12Language`,type:`ULONG`,value:0},{name:`cmap12nGroups`,type:`ULONG`,value:m.length/3}]),i.fields=i.fields.concat(m)}return i}var aF={parse:tF,make:iF},oF=`.notdef,space,exclam,quotedbl,numbersign,dollar,percent,ampersand,quoteright,parenleft,parenright,asterisk,plus,comma,hyphen,period,slash,zero,one,two,three,four,five,six,seven,eight,nine,colon,semicolon,less,equal,greater,question,at,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,bracketleft,backslash,bracketright,asciicircum,underscore,quoteleft,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,braceleft,bar,braceright,asciitilde,exclamdown,cent,sterling,fraction,yen,florin,section,currency,quotesingle,quotedblleft,guillemotleft,guilsinglleft,guilsinglright,fi,fl,endash,dagger,daggerdbl,periodcentered,paragraph,bullet,quotesinglbase,quotedblbase,quotedblright,guillemotright,ellipsis,perthousand,questiondown,grave,acute,circumflex,tilde,macron,breve,dotaccent,dieresis,ring,cedilla,hungarumlaut,ogonek,caron,emdash,AE,ordfeminine,Lslash,Oslash,OE,ordmasculine,ae,dotlessi,lslash,oslash,oe,germandbls,onesuperior,logicalnot,mu,trademark,Eth,onehalf,plusminus,Thorn,onequarter,divide,brokenbar,degree,thorn,threequarters,twosuperior,registered,minus,eth,multiply,threesuperior,copyright,Aacute,Acircumflex,Adieresis,Agrave,Aring,Atilde,Ccedilla,Eacute,Ecircumflex,Edieresis,Egrave,Iacute,Icircumflex,Idieresis,Igrave,Ntilde,Oacute,Ocircumflex,Odieresis,Ograve,Otilde,Scaron,Uacute,Ucircumflex,Udieresis,Ugrave,Yacute,Ydieresis,Zcaron,aacute,acircumflex,adieresis,agrave,aring,atilde,ccedilla,eacute,ecircumflex,edieresis,egrave,iacute,icircumflex,idieresis,igrave,ntilde,oacute,ocircumflex,odieresis,ograve,otilde,scaron,uacute,ucircumflex,udieresis,ugrave,yacute,ydieresis,zcaron,exclamsmall,Hungarumlautsmall,dollaroldstyle,dollarsuperior,ampersandsmall,Acutesmall,parenleftsuperior,parenrightsuperior,266 ff,onedotenleader,zerooldstyle,oneoldstyle,twooldstyle,threeoldstyle,fouroldstyle,fiveoldstyle,sixoldstyle,sevenoldstyle,eightoldstyle,nineoldstyle,commasuperior,threequartersemdash,periodsuperior,questionsmall,asuperior,bsuperior,centsuperior,dsuperior,esuperior,isuperior,lsuperior,msuperior,nsuperior,osuperior,rsuperior,ssuperior,tsuperior,ff,ffi,ffl,parenleftinferior,parenrightinferior,Circumflexsmall,hyphensuperior,Gravesmall,Asmall,Bsmall,Csmall,Dsmall,Esmall,Fsmall,Gsmall,Hsmall,Ismall,Jsmall,Ksmall,Lsmall,Msmall,Nsmall,Osmall,Psmall,Qsmall,Rsmall,Ssmall,Tsmall,Usmall,Vsmall,Wsmall,Xsmall,Ysmall,Zsmall,colonmonetary,onefitted,rupiah,Tildesmall,exclamdownsmall,centoldstyle,Lslashsmall,Scaronsmall,Zcaronsmall,Dieresissmall,Brevesmall,Caronsmall,Dotaccentsmall,Macronsmall,figuredash,hypheninferior,Ogoneksmall,Ringsmall,Cedillasmall,questiondownsmall,oneeighth,threeeighths,fiveeighths,seveneighths,onethird,twothirds,zerosuperior,foursuperior,fivesuperior,sixsuperior,sevensuperior,eightsuperior,ninesuperior,zeroinferior,oneinferior,twoinferior,threeinferior,fourinferior,fiveinferior,sixinferior,seveninferior,eightinferior,nineinferior,centinferior,dollarinferior,periodinferior,commainferior,Agravesmall,Aacutesmall,Acircumflexsmall,Atildesmall,Adieresissmall,Aringsmall,AEsmall,Ccedillasmall,Egravesmall,Eacutesmall,Ecircumflexsmall,Edieresissmall,Igravesmall,Iacutesmall,Icircumflexsmall,Idieresissmall,Ethsmall,Ntildesmall,Ogravesmall,Oacutesmall,Ocircumflexsmall,Otildesmall,Odieresissmall,OEsmall,Oslashsmall,Ugravesmall,Uacutesmall,Ucircumflexsmall,Udieresissmall,Yacutesmall,Thornsmall,Ydieresissmall,001.000,001.001,001.002,001.003,Black,Bold,Book,Light,Medium,Regular,Roman,Semibold`.split(`,`),sF=`................................space.exclam.quotedbl.numbersign.dollar.percent.ampersand.quoteright.parenleft.parenright.asterisk.plus.comma.hyphen.period.slash.zero.one.two.three.four.five.six.seven.eight.nine.colon.semicolon.less.equal.greater.question.at.A.B.C.D.E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.Z.bracketleft.backslash.bracketright.asciicircum.underscore.quoteleft.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.braceleft.bar.braceright.asciitilde...................................exclamdown.cent.sterling.fraction.yen.florin.section.currency.quotesingle.quotedblleft.guillemotleft.guilsinglleft.guilsinglright.fi.fl..endash.dagger.daggerdbl.periodcentered..paragraph.bullet.quotesinglbase.quotedblbase.quotedblright.guillemotright.ellipsis.perthousand..questiondown..grave.acute.circumflex.tilde.macron.breve.dotaccent.dieresis..ring.cedilla..hungarumlaut.ogonek.caron.emdash.................AE..ordfeminine.....Lslash.Oslash.OE.ordmasculine......ae....dotlessi...lslash.oslash.oe.germandbls`.split(`.`),cF=`................................space.exclamsmall.Hungarumlautsmall..dollaroldstyle.dollarsuperior.ampersandsmall.Acutesmall.parenleftsuperior.parenrightsuperior.twodotenleader.onedotenleader.comma.hyphen.period.fraction.zerooldstyle.oneoldstyle.twooldstyle.threeoldstyle.fouroldstyle.fiveoldstyle.sixoldstyle.sevenoldstyle.eightoldstyle.nineoldstyle.colon.semicolon.commasuperior.threequartersemdash.periodsuperior.questionsmall..asuperior.bsuperior.centsuperior.dsuperior.esuperior...isuperior...lsuperior.msuperior.nsuperior.osuperior...rsuperior.ssuperior.tsuperior..ff.fi.fl.ffi.ffl.parenleftinferior..parenrightinferior.Circumflexsmall.hyphensuperior.Gravesmall.Asmall.Bsmall.Csmall.Dsmall.Esmall.Fsmall.Gsmall.Hsmall.Ismall.Jsmall.Ksmall.Lsmall.Msmall.Nsmall.Osmall.Psmall.Qsmall.Rsmall.Ssmall.Tsmall.Usmall.Vsmall.Wsmall.Xsmall.Ysmall.Zsmall.colonmonetary.onefitted.rupiah.Tildesmall...................................exclamdownsmall.centoldstyle.Lslashsmall...Scaronsmall.Zcaronsmall.Dieresissmall.Brevesmall.Caronsmall..Dotaccentsmall...Macronsmall...figuredash.hypheninferior...Ogoneksmall.Ringsmall.Cedillasmall....onequarter.onehalf.threequarters.questiondownsmall.oneeighth.threeeighths.fiveeighths.seveneighths.onethird.twothirds...zerosuperior.onesuperior.twosuperior.threesuperior.foursuperior.fivesuperior.sixsuperior.sevensuperior.eightsuperior.ninesuperior.zeroinferior.oneinferior.twoinferior.threeinferior.fourinferior.fiveinferior.sixinferior.seveninferior.eightinferior.nineinferior.centinferior.dollarinferior.periodinferior.commainferior.Agravesmall.Aacutesmall.Acircumflexsmall.Atildesmall.Adieresissmall.Aringsmall.AEsmall.Ccedillasmall.Egravesmall.Eacutesmall.Ecircumflexsmall.Edieresissmall.Igravesmall.Iacutesmall.Icircumflexsmall.Idieresissmall.Ethsmall.Ntildesmall.Ogravesmall.Oacutesmall.Ocircumflexsmall.Otildesmall.Odieresissmall.OEsmall.Oslashsmall.Ugravesmall.Uacutesmall.Ucircumflexsmall.Udieresissmall.Yacutesmall.Thornsmall.Ydieresissmall`.split(`.`),lF=`.notdef,.null,nonmarkingreturn,space,exclam,quotedbl,numbersign,dollar,percent,ampersand,quotesingle,parenleft,parenright,asterisk,plus,comma,hyphen,period,slash,zero,one,two,three,four,five,six,seven,eight,nine,colon,semicolon,less,equal,greater,question,at,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,bracketleft,backslash,bracketright,asciicircum,underscore,grave,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,braceleft,bar,braceright,asciitilde,Adieresis,Aring,Ccedilla,Eacute,Ntilde,Odieresis,Udieresis,aacute,agrave,acircumflex,adieresis,atilde,aring,ccedilla,eacute,egrave,ecircumflex,edieresis,iacute,igrave,icircumflex,idieresis,ntilde,oacute,ograve,ocircumflex,odieresis,otilde,uacute,ugrave,ucircumflex,udieresis,dagger,degree,cent,sterling,section,bullet,paragraph,germandbls,registered,copyright,trademark,acute,dieresis,notequal,AE,Oslash,infinity,plusminus,lessequal,greaterequal,yen,mu,partialdiff,summation,product,pi,integral,ordfeminine,ordmasculine,Omega,ae,oslash,questiondown,exclamdown,logicalnot,radical,florin,approxequal,Delta,guillemotleft,guillemotright,ellipsis,nonbreakingspace,Agrave,Atilde,Otilde,OE,oe,endash,emdash,quotedblleft,quotedblright,quoteleft,quoteright,divide,lozenge,ydieresis,Ydieresis,fraction,currency,guilsinglleft,guilsinglright,fi,fl,daggerdbl,periodcentered,quotesinglbase,quotedblbase,perthousand,Acircumflex,Ecircumflex,Aacute,Edieresis,Egrave,Iacute,Icircumflex,Idieresis,Igrave,Oacute,Ocircumflex,apple,Ograve,Uacute,Ucircumflex,Ugrave,dotlessi,circumflex,tilde,macron,breve,dotaccent,ring,cedilla,hungarumlaut,ogonek,caron,Lslash,lslash,Scaron,scaron,Zcaron,zcaron,brokenbar,Eth,eth,Yacute,yacute,Thorn,thorn,minus,multiply,onesuperior,twosuperior,threesuperior,onehalf,onequarter,threequarters,franc,Gbreve,gbreve,Idotaccent,Scedilla,scedilla,Cacute,cacute,Ccaron,ccaron,dcroat`.split(`,`);function uF(e){this.font=e}uF.prototype.charToGlyphIndex=function(e){var t=e.codePointAt(0),n=this.font.glyphs;if(n){for(var r=0;r<n.length;r+=1)for(var i=n.get(r),a=0;a<i.unicodes.length;a+=1)if(i.unicodes[a]===t)return r}return null};function dF(e){this.cmap=e}dF.prototype.charToGlyphIndex=function(e){return this.cmap.glyphIndexMap[e.codePointAt(0)]||0};function fF(e,t){this.encoding=e,this.charset=t}fF.prototype.charToGlyphIndex=function(e){var t=e.codePointAt(0),n=this.encoding[t];return this.charset.indexOf(n)};function pF(e){switch(e.version){case 1:this.names=lF.slice();break;case 2:this.names=Array(e.numberOfGlyphs);for(var t=0;t<e.numberOfGlyphs;t++)e.glyphNameIndex[t]<lF.length?this.names[t]=lF[e.glyphNameIndex[t]]:this.names[t]=e.names[e.glyphNameIndex[t]-lF.length];break;case 2.5:this.names=Array(e.numberOfGlyphs);for(var n=0;n<e.numberOfGlyphs;n++)this.names[n]=lF[n+e.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}pF.prototype.nameToGlyphIndex=function(e){return this.names.indexOf(e)},pF.prototype.glyphIndexToName=function(e){return this.names[e]};function mF(e){for(var t,n=e.tables.cmap.glyphIndexMap,r=Object.keys(n),i=0;i<r.length;i+=1){var a=r[i],o=n[a];t=e.glyphs.get(o),t.addUnicode(parseInt(a))}for(var s=0;s<e.glyphs.length;s+=1)t=e.glyphs.get(s),e.cffEncoding?e.isCIDFont?t.name=`gid`+s:t.name=e.cffEncoding.charset[s]:e.glyphNames.names&&(t.name=e.glyphNames.glyphIndexToName(s))}function hF(e){e._IndexToUnicodeMap={};for(var t=e.tables.cmap.glyphIndexMap,n=Object.keys(t),r=0;r<n.length;r+=1){var i=n[r],a=t[i];e._IndexToUnicodeMap[a]===void 0?e._IndexToUnicodeMap[a]={unicodes:[parseInt(i)]}:e._IndexToUnicodeMap[a].unicodes.push(parseInt(i))}}function gF(e,t){t.lowMemory?hF(e):mF(e)}function _F(e,t,n,r,i){e.beginPath(),e.moveTo(t,n),e.lineTo(r,i),e.stroke()}var vF={line:_F};function yF(e,t){var n=t||new vP;return{configurable:!0,get:function(){return typeof n==`function`&&(n=n()),n},set:function(e){n=e}}}function bF(e){this.bindConstructorValues(e)}bF.prototype.bindConstructorValues=function(e){this.index=e.index||0,this.name=e.name||null,this.unicode=e.unicode||void 0,this.unicodes=e.unicodes||e.unicode!==void 0?[e.unicode]:[],`xMin`in e&&(this.xMin=e.xMin),`yMin`in e&&(this.yMin=e.yMin),`xMax`in e&&(this.xMax=e.xMax),`yMax`in e&&(this.yMax=e.yMax),`advanceWidth`in e&&(this.advanceWidth=e.advanceWidth),Object.defineProperty(this,"path",yF(this,e.path))},bF.prototype.addUnicode=function(e){this.unicodes.length===0&&(this.unicode=e),this.unicodes.push(e)},bF.prototype.getBoundingBox=function(){return this.path.getBoundingBox()},bF.prototype.getPath=function(e,t,n,r,i){e=e===void 0?0:e,t=t===void 0?0:t,n=n===void 0?72:n;var a,o;r||={};var s=r.xScale,c=r.yScale;if(r.hinting&&i&&i.hinting&&(o=this.path&&i.hinting.exec(this,n)),o)a=i.hinting.getCommands(o),e=Math.round(e),t=Math.round(t),s=c=1;else{a=this.path.commands;var l=1/(this.path.unitsPerEm||1e3)*n;s===void 0&&(s=l),c===void 0&&(c=l)}for(var u=new vP,d=0;d<a.length;d+=1){var f=a[d];f.type===`M`?u.moveTo(e+f.x*s,t+-f.y*c):f.type===`L`?u.lineTo(e+f.x*s,t+-f.y*c):f.type===`Q`?u.quadraticCurveTo(e+f.x1*s,t+-f.y1*c,e+f.x*s,t+-f.y*c):f.type===`C`?u.curveTo(e+f.x1*s,t+-f.y1*c,e+f.x2*s,t+-f.y2*c,e+f.x*s,t+-f.y*c):f.type===`Z`&&u.closePath()}return u},bF.prototype.getContours=function(){if(this.points===void 0)return[];for(var e=[],t=[],n=0;n<this.points.length;n+=1){var r=this.points[n];t.push(r),r.lastPointOfContour&&(e.push(t),t=[])}return K.argument(t.length===0,`There are still points left in the current contour.`),e},bF.prototype.getMetrics=function(){for(var e=this.path.commands,t=[],n=[],r=0;r<e.length;r+=1){var i=e[r];i.type!==`Z`&&(t.push(i.x),n.push(i.y)),(i.type===`Q`||i.type===`C`)&&(t.push(i.x1),n.push(i.y1)),i.type===`C`&&(t.push(i.x2),n.push(i.y2))}var a={xMin:Math.min.apply(null,t),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,t),yMax:Math.max.apply(null,n),leftSideBearing:this.leftSideBearing};return isFinite(a.xMin)||(a.xMin=0),isFinite(a.xMax)||(a.xMax=this.advanceWidth),isFinite(a.yMin)||(a.yMin=0),isFinite(a.yMax)||(a.yMax=0),a.rightSideBearing=this.advanceWidth-a.leftSideBearing-(a.xMax-a.xMin),a},bF.prototype.draw=function(e,t,n,r,i){this.getPath(t,n,r,i).draw(e)},bF.prototype.drawPoints=function(e,t,n,r){function i(t,n,r,i){e.beginPath();for(var a=0;a<t.length;a+=1)e.moveTo(n+t[a].x*i,r+t[a].y*i),e.arc(n+t[a].x*i,r+t[a].y*i,2,0,Math.PI*2,!1);e.closePath(),e.fill()}t=t===void 0?0:t,n=n===void 0?0:n,r=r===void 0?24:r;for(var a=1/this.path.unitsPerEm*r,o=[],s=[],c=this.path,l=0;l<c.commands.length;l+=1){var u=c.commands[l];u.x!==void 0&&o.push({x:u.x,y:-u.y}),u.x1!==void 0&&s.push({x:u.x1,y:-u.y1}),u.x2!==void 0&&s.push({x:u.x2,y:-u.y2})}e.fillStyle=`blue`,i(o,t,n,a),e.fillStyle=`red`,i(s,t,n,a)},bF.prototype.drawMetrics=function(e,t,n,r){var i;t=t===void 0?0:t,n=n===void 0?0:n,r=r===void 0?24:r,i=1/this.path.unitsPerEm*r,e.lineWidth=1,e.strokeStyle=`black`,vF.line(e,t,-1e4,t,1e4),vF.line(e,-1e4,n,1e4,n);var a=this.xMin||0,o=this.yMin||0,s=this.xMax||0,c=this.yMax||0,l=this.advanceWidth||0;e.strokeStyle=`blue`,vF.line(e,t+a*i,-1e4,t+a*i,1e4),vF.line(e,t+s*i,-1e4,t+s*i,1e4),vF.line(e,-1e4,n+-o*i,1e4,n+-o*i),vF.line(e,-1e4,n+-c*i,1e4,n+-c*i),e.strokeStyle=`green`,vF.line(e,t+l*i,-1e4,t+l*i,1e4)};function xF(e,t,n){Object.defineProperty(e,t,{get:function(){return e.path,e[n]},set:function(t){e[n]=t},enumerable:!0,configurable:!0})}function SF(e,t){if(this.font=e,this.glyphs={},Array.isArray(t))for(var n=0;n<t.length;n++){var r=t[n];r.path.unitsPerEm=e.unitsPerEm,this.glyphs[n]=r}this.length=t&&t.length||0}SF.prototype.get=function(e){if(this.glyphs[e]===void 0){this.font._push(e),typeof this.glyphs[e]==`function`&&(this.glyphs[e]=this.glyphs[e]());var t=this.glyphs[e],n=this.font._IndexToUnicodeMap[e];if(n)for(var r=0;r<n.unicodes.length;r++)t.addUnicode(n.unicodes[r]);this.font.cffEncoding?this.font.isCIDFont?t.name=`gid`+e:t.name=this.font.cffEncoding.charset[e]:this.font.glyphNames.names&&(t.name=this.font.glyphNames.glyphIndexToName(e)),this.glyphs[e].advanceWidth=this.font._hmtxTableData[e].advanceWidth,this.glyphs[e].leftSideBearing=this.font._hmtxTableData[e].leftSideBearing}else typeof this.glyphs[e]==`function`&&(this.glyphs[e]=this.glyphs[e]());return this.glyphs[e]},SF.prototype.push=function(e,t){this.glyphs[e]=t,this.length++};function CF(e,t){return new bF({index:t,font:e})}function wF(e,t,n,r,i,a){return function(){var o=new bF({index:t,font:e});return o.path=function(){n(o,r,i);var t=a(e.glyphs,o);return t.unitsPerEm=e.unitsPerEm,t},xF(o,`xMin`,`_xMin`),xF(o,`xMax`,`_xMax`),xF(o,`yMin`,`_yMin`),xF(o,`yMax`,`_yMax`),o}}function TF(e,t,n,r){return function(){var i=new bF({index:t,font:e});return i.path=function(){var t=n(e,i,r);return t.unitsPerEm=e.unitsPerEm,t},i}}var EF={GlyphSet:SF,glyphLoader:CF,ttfGlyphLoader:wF,cffGlyphLoader:TF};function DF(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(var n=0;n<e.length;n+=1)if(!DF(e[n],t[n]))return!1;return!0}else return!1}function OF(e){return e.length<1240?107:e.length<33900?1131:32768}function kF(e,t,n){var r=[],i=[],a=Z.getCard16(e,t),o,s;if(a!==0){var c=Z.getByte(e,t+2);o=t+(a+1)*c+2;for(var l=t+3,u=0;u<a+1;u+=1)r.push(Z.getOffset(e,l,c)),l+=c;s=o+r[a]}else s=t+2;for(var d=0;d<r.length-1;d+=1){var f=Z.getBytes(e,o+r[d],o+r[d+1]);n&&(f=n(f)),i.push(f)}return{objects:i,startOffset:t,endOffset:s}}function AF(e,t){var n=[],r=Z.getCard16(e,t),i,a;if(r!==0){var o=Z.getByte(e,t+2);i=t+(r+1)*o+2;for(var s=t+3,c=0;c<r+1;c+=1)n.push(Z.getOffset(e,s,o)),s+=o;a=i+n[r]}else a=t+2;return{offsets:n,startOffset:t,endOffset:a}}function jF(e,t,n,r,i){var a=Z.getCard16(n,r),o=0;if(a!==0){var s=Z.getByte(n,r+2);o=r+(a+1)*s+2}var c=Z.getBytes(n,o+t[e],o+t[e+1]);return i&&(c=i(c)),c}function MF(e){for(var t=``,n=15,r=[`0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`.`,`E`,`E-`,null,`-`];;){var i=e.parseByte(),a=i>>4,o=i&15;if(a===n||(t+=r[a],o===n))break;t+=r[o]}return parseFloat(t)}function NF(e,t){var n,r,i,a;if(t===28)return n=e.parseByte(),r=e.parseByte(),n<<8|r;if(t===29)return n=e.parseByte(),r=e.parseByte(),i=e.parseByte(),a=e.parseByte(),n<<24|r<<16|i<<8|a;if(t===30)return MF(e);if(t>=32&&t<=246)return t-139;if(t>=247&&t<=250)return n=e.parseByte(),(t-247)*256+n+108;if(t>=251&&t<=254)return n=e.parseByte(),-(t-251)*256-n-108;throw Error(`Invalid b0 `+t)}function PF(e){for(var t={},n=0;n<e.length;n+=1){var r=e[n][0],i=e[n][1],a=void 0;if(a=i.length===1?i[0]:i,t.hasOwnProperty(r)&&!isNaN(t[r]))throw Error(`Object `+t+` already has key `+r);t[r]=a}return t}function FF(e,t,n){t=t===void 0?0:t;var r=new Z.Parser(e,t),i=[],a=[];for(n=n===void 0?e.length:n;r.relativeOffset<n;){var o=r.parseByte();o<=21?(o===12&&(o=1200+r.parseByte()),i.push([o,a]),a=[]):a.push(NF(r,o))}return PF(i)}function IF(e,t){return t=t<=390?oF[t]:e[t-391],t}function LF(e,t,n){for(var r={},i,a=0;a<t.length;a+=1){var o=t[a];if(Array.isArray(o.type)){var s=[];s.length=o.type.length;for(var c=0;c<o.type.length;c++)i=e[o.op]===void 0?void 0:e[o.op][c],i===void 0&&(i=o.value!==void 0&&o.value[c]!==void 0?o.value[c]:null),o.type[c]===`SID`&&(i=IF(n,i)),s[c]=i;r[o.name]=s}else i=e[o.op],i===void 0&&(i=o.value===void 0?null:o.value),o.type===`SID`&&(i=IF(n,i)),r[o.name]=i}return r}function RF(e,t){var n={};return n.formatMajor=Z.getCard8(e,t),n.formatMinor=Z.getCard8(e,t+1),n.size=Z.getCard8(e,t+2),n.offsetSize=Z.getCard8(e,t+3),n.startOffset=t,n.endOffset=t+4,n}var zF=[{name:`version`,op:0,type:`SID`},{name:`notice`,op:1,type:`SID`},{name:`copyright`,op:1200,type:`SID`},{name:`fullName`,op:2,type:`SID`},{name:`familyName`,op:3,type:`SID`},{name:`weight`,op:4,type:`SID`},{name:`isFixedPitch`,op:1201,type:`number`,value:0},{name:`italicAngle`,op:1202,type:`number`,value:0},{name:`underlinePosition`,op:1203,type:`number`,value:-100},{name:`underlineThickness`,op:1204,type:`number`,value:50},{name:`paintType`,op:1205,type:`number`,value:0},{name:`charstringType`,op:1206,type:`number`,value:2},{name:`fontMatrix`,op:1207,type:[`real`,`real`,`real`,`real`,`real`,`real`],value:[.001,0,0,.001,0,0]},{name:`uniqueId`,op:13,type:`number`},{name:`fontBBox`,op:5,type:[`number`,`number`,`number`,`number`],value:[0,0,0,0]},{name:`strokeWidth`,op:1208,type:`number`,value:0},{name:`xuid`,op:14,type:[],value:null},{name:`charset`,op:15,type:`offset`,value:0},{name:`encoding`,op:16,type:`offset`,value:0},{name:`charStrings`,op:17,type:`offset`,value:0},{name:`private`,op:18,type:[`number`,`offset`],value:[0,0]},{name:`ros`,op:1230,type:[`SID`,`SID`,`number`]},{name:`cidFontVersion`,op:1231,type:`number`,value:0},{name:`cidFontRevision`,op:1232,type:`number`,value:0},{name:`cidFontType`,op:1233,type:`number`,value:0},{name:`cidCount`,op:1234,type:`number`,value:8720},{name:`uidBase`,op:1235,type:`number`},{name:`fdArray`,op:1236,type:`offset`},{name:`fdSelect`,op:1237,type:`offset`},{name:`fontName`,op:1238,type:`SID`}],BF=[{name:`subrs`,op:19,type:`offset`,value:0},{name:`defaultWidthX`,op:20,type:`number`,value:0},{name:`nominalWidthX`,op:21,type:`number`,value:0}];function VF(e,t){return LF(FF(e,0,e.byteLength),zF,t)}function HF(e,t,n,r){return LF(FF(e,t,n),BF,r)}function UF(e,t,n,r){for(var i=[],a=0;a<n.length;a+=1){var o=VF(new DataView(new Uint8Array(n[a]).buffer),r);o._subrs=[],o._subrsBias=0,o._defaultWidthX=0,o._nominalWidthX=0;var s=o.private[0],c=o.private[1];if(s!==0&&c!==0){var l=HF(e,c+t,s,r);o._defaultWidthX=l.defaultWidthX,o._nominalWidthX=l.nominalWidthX,l.subrs!==0&&(o._subrs=kF(e,c+l.subrs+t).objects,o._subrsBias=OF(o._subrs)),o._privateDict=l}i.push(o)}return i}function WF(e,t,n,r){var i,a,o=new Z.Parser(e,t);--n;var s=[`.notdef`],c=o.parseCard8();if(c===0)for(var l=0;l<n;l+=1)i=o.parseSID(),s.push(IF(r,i));else if(c===1)for(;s.length<=n;){i=o.parseSID(),a=o.parseCard8();for(var u=0;u<=a;u+=1)s.push(IF(r,i)),i+=1}else if(c===2)for(;s.length<=n;){i=o.parseSID(),a=o.parseCard16();for(var d=0;d<=a;d+=1)s.push(IF(r,i)),i+=1}else throw Error(`Unknown charset format `+c);return s}function GF(e,t,n){var r,i={},a=new Z.Parser(e,t),o=a.parseCard8();if(o===0)for(var s=a.parseCard8(),c=0;c<s;c+=1)r=a.parseCard8(),i[r]=c;else if(o===1){var l=a.parseCard8();r=1;for(var u=0;u<l;u+=1)for(var d=a.parseCard8(),f=a.parseCard8(),p=d;p<=d+f;p+=1)i[p]=r,r+=1}else throw Error(`Unknown encoding format `+o);return new fF(i,n)}function KF(e,t,n){var r,i,a,o,s=new vP,c=[],l=0,u=!1,d=!1,f=0,p=0,m,h,g,_;if(e.isCIDFont){var v=e.tables.cff.topDict._fdSelect[t.index],y=e.tables.cff.topDict._fdArray[v];m=y._subrs,h=y._subrsBias,g=y._defaultWidthX,_=y._nominalWidthX}else m=e.tables.cff.topDict._subrs,h=e.tables.cff.topDict._subrsBias,g=e.tables.cff.topDict._defaultWidthX,_=e.tables.cff.topDict._nominalWidthX;var b=g;function x(e,t){d&&s.closePath(),s.moveTo(e,t),d=!0}function S(){c.length%2!=0&&!u&&(b=c.shift()+_),l+=c.length>>1,c.length=0,u=!0}function C(n){for(var g,v,y,w,ee,te,ne,re,ie,ae,oe,se,ce=0;ce<n.length;){var le=n[ce];switch(ce+=1,le){case 1:S();break;case 3:S();break;case 4:c.length>1&&!u&&(b=c.shift()+_,u=!0),p+=c.pop(),x(f,p);break;case 5:for(;c.length>0;)f+=c.shift(),p+=c.shift(),s.lineTo(f,p);break;case 6:for(;c.length>0&&(f+=c.shift(),s.lineTo(f,p),c.length!==0);)p+=c.shift(),s.lineTo(f,p);break;case 7:for(;c.length>0&&(p+=c.shift(),s.lineTo(f,p),c.length!==0);)f+=c.shift(),s.lineTo(f,p);break;case 8:for(;c.length>0;)r=f+c.shift(),i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),f=a+c.shift(),p=o+c.shift(),s.curveTo(r,i,a,o,f,p);break;case 10:ee=c.pop()+h,te=m[ee],te&&C(te);break;case 11:return;case 12:switch(le=n[ce],ce+=1,le){case 35:r=f+c.shift(),i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),ne=a+c.shift(),re=o+c.shift(),ie=ne+c.shift(),ae=re+c.shift(),oe=ie+c.shift(),se=ae+c.shift(),f=oe+c.shift(),p=se+c.shift(),c.shift(),s.curveTo(r,i,a,o,ne,re),s.curveTo(ie,ae,oe,se,f,p);break;case 34:r=f+c.shift(),i=p,a=r+c.shift(),o=i+c.shift(),ne=a+c.shift(),re=o,ie=ne+c.shift(),ae=o,oe=ie+c.shift(),se=p,f=oe+c.shift(),s.curveTo(r,i,a,o,ne,re),s.curveTo(ie,ae,oe,se,f,p);break;case 36:r=f+c.shift(),i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),ne=a+c.shift(),re=o,ie=ne+c.shift(),ae=o,oe=ie+c.shift(),se=ae+c.shift(),f=oe+c.shift(),s.curveTo(r,i,a,o,ne,re),s.curveTo(ie,ae,oe,se,f,p);break;case 37:r=f+c.shift(),i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),ne=a+c.shift(),re=o+c.shift(),ie=ne+c.shift(),ae=re+c.shift(),oe=ie+c.shift(),se=ae+c.shift(),Math.abs(oe-f)>Math.abs(se-p)?f=oe+c.shift():p=se+c.shift(),s.curveTo(r,i,a,o,ne,re),s.curveTo(ie,ae,oe,se,f,p);break;default:console.log(`Glyph `+t.index+`: unknown operator 1200`+le),c.length=0}break;case 14:c.length>0&&!u&&(b=c.shift()+_,u=!0),d&&=(s.closePath(),!1);break;case 18:S();break;case 19:case 20:S(),ce+=l+7>>3;break;case 21:c.length>2&&!u&&(b=c.shift()+_,u=!0),p+=c.pop(),f+=c.pop(),x(f,p);break;case 22:c.length>1&&!u&&(b=c.shift()+_,u=!0),f+=c.pop(),x(f,p);break;case 23:S();break;case 24:for(;c.length>2;)r=f+c.shift(),i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),f=a+c.shift(),p=o+c.shift(),s.curveTo(r,i,a,o,f,p);f+=c.shift(),p+=c.shift(),s.lineTo(f,p);break;case 25:for(;c.length>6;)f+=c.shift(),p+=c.shift(),s.lineTo(f,p);r=f+c.shift(),i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),f=a+c.shift(),p=o+c.shift(),s.curveTo(r,i,a,o,f,p);break;case 26:for(c.length%2&&(f+=c.shift());c.length>0;)r=f,i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),f=a,p=o+c.shift(),s.curveTo(r,i,a,o,f,p);break;case 27:for(c.length%2&&(p+=c.shift());c.length>0;)r=f+c.shift(),i=p,a=r+c.shift(),o=i+c.shift(),f=a+c.shift(),p=o,s.curveTo(r,i,a,o,f,p);break;case 28:g=n[ce],v=n[ce+1],c.push((g<<24|v<<16)>>16),ce+=2;break;case 29:ee=c.pop()+e.gsubrsBias,te=e.gsubrs[ee],te&&C(te);break;case 30:for(;c.length>0&&(r=f,i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),f=a+c.shift(),p=o+(c.length===1?c.shift():0),s.curveTo(r,i,a,o,f,p),c.length!==0);)r=f+c.shift(),i=p,a=r+c.shift(),o=i+c.shift(),p=o+c.shift(),f=a+(c.length===1?c.shift():0),s.curveTo(r,i,a,o,f,p);break;case 31:for(;c.length>0&&(r=f+c.shift(),i=p,a=r+c.shift(),o=i+c.shift(),p=o+c.shift(),f=a+(c.length===1?c.shift():0),s.curveTo(r,i,a,o,f,p),c.length!==0);)r=f,i=p+c.shift(),a=r+c.shift(),o=i+c.shift(),f=a+c.shift(),p=o+(c.length===1?c.shift():0),s.curveTo(r,i,a,o,f,p);break;default:le<32?console.log(`Glyph `+t.index+`: unknown operator `+le):le<247?c.push(le-139):le<251?(g=n[ce],ce+=1,c.push((le-247)*256+g+108)):le<255?(g=n[ce],ce+=1,c.push(-(le-251)*256-g-108)):(g=n[ce],v=n[ce+1],y=n[ce+2],w=n[ce+3],ce+=4,c.push((g<<24|v<<16|y<<8|w)/65536))}}}return C(n),t.advanceWidth=b,s}function qF(e,t,n,r){var i=[],a,o=new Z.Parser(e,t),s=o.parseCard8();if(s===0)for(var c=0;c<n;c++){if(a=o.parseCard8(),a>=r)throw Error(`CFF table CID Font FDSelect has bad FD index value `+a+` (FD count `+r+`)`);i.push(a)}else if(s===3){var l=o.parseCard16(),u=o.parseCard16();if(u!==0)throw Error(`CFF Table CID Font FDSelect format 3 range has bad initial GID `+u);for(var d,f=0;f<l;f++){if(a=o.parseCard8(),d=o.parseCard16(),a>=r)throw Error(`CFF table CID Font FDSelect has bad FD index value `+a+` (FD count `+r+`)`);if(d>n)throw Error(`CFF Table CID Font FDSelect format 3 range has bad GID `+d);for(;u<d;u++)i.push(a);u=d}if(d!==n)throw Error(`CFF Table CID Font FDSelect format 3 range has bad final GID `+d)}else throw Error(`CFF Table CID Font FDSelect table has unsupported format `+s);return i}function JF(e,t,n,r){n.tables.cff={};var i=kF(e,kF(e,RF(e,t).endOffset,Z.bytesToString).endOffset),a=kF(e,i.endOffset,Z.bytesToString);n.gsubrs=kF(e,a.endOffset).objects,n.gsubrsBias=OF(n.gsubrs);var o=UF(e,t,i.objects,a.objects);if(o.length!==1)throw Error(`CFF table has too many fonts in 'FontSet' - count of fonts NameIndex.length = `+o.length);var s=o[0];if(n.tables.cff.topDict=s,s._privateDict&&(n.defaultWidthX=s._privateDict.defaultWidthX,n.nominalWidthX=s._privateDict.nominalWidthX),s.ros[0]!==void 0&&s.ros[1]!==void 0&&(n.isCIDFont=!0),n.isCIDFont){var c=s.fdArray,l=s.fdSelect;if(c===0||l===0)throw Error(`Font is marked as a CID font, but FDArray and/or FDSelect information is missing`);c+=t;var u=UF(e,t,kF(e,c).objects,a.objects);s._fdArray=u,l+=t,s._fdSelect=qF(e,l,n.numGlyphs,u.length)}var d=t+s.private[1],f=HF(e,d,s.private[0],a.objects);n.defaultWidthX=f.defaultWidthX,n.nominalWidthX=f.nominalWidthX,f.subrs===0?(n.subrs=[],n.subrsBias=0):(n.subrs=kF(e,d+f.subrs).objects,n.subrsBias=OF(n.subrs));var p;r.lowMemory?(p=AF(e,t+s.charStrings),n.nGlyphs=p.offsets.length):(p=kF(e,t+s.charStrings),n.nGlyphs=p.objects.length);var m=WF(e,t+s.charset,n.nGlyphs,a.objects);if(s.encoding===0?n.cffEncoding=new fF(sF,m):s.encoding===1?n.cffEncoding=new fF(cF,m):n.cffEncoding=GF(e,t+s.encoding,m),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new EF.GlyphSet(n),r.lowMemory)n._push=function(r){var i=jF(r,p.offsets,e,t+s.charStrings);n.glyphs.push(r,EF.cffGlyphLoader(n,r,KF,i))};else for(var h=0;h<n.nGlyphs;h+=1){var g=p.objects[h];n.glyphs.push(h,EF.cffGlyphLoader(n,h,KF,g))}}function YF(e,t){var n,r=oF.indexOf(e);return r>=0&&(n=r),r=t.indexOf(e),r>=0?n=r+oF.length:(n=oF.length+t.length,t.push(e)),n}function XF(){return new Y.Record(`Header`,[{name:`major`,type:`Card8`,value:1},{name:`minor`,type:`Card8`,value:0},{name:`hdrSize`,type:`Card8`,value:4},{name:`major`,type:`Card8`,value:1}])}function ZF(e){var t=new Y.Record(`Name INDEX`,[{name:`names`,type:`INDEX`,value:[]}]);t.names=[];for(var n=0;n<e.length;n+=1)t.names.push({name:`name_`+n,type:`NAME`,value:e[n]});return t}function QF(e,t,n){for(var r={},i=0;i<e.length;i+=1){var a=e[i],o=t[a.name];o!==void 0&&!DF(o,a.value)&&(a.type===`SID`&&(o=YF(o,n)),r[a.op]={name:a.name,type:a.type,value:o})}return r}function $F(e,t){var n=new Y.Record(`Top DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=QF(zF,e,t),n}function eI(e){var t=new Y.Record(`Top DICT INDEX`,[{name:`topDicts`,type:`INDEX`,value:[]}]);return t.topDicts=[{name:`topDict_0`,type:`TABLE`,value:e}],t}function tI(e){var t=new Y.Record(`String INDEX`,[{name:`strings`,type:`INDEX`,value:[]}]);t.strings=[];for(var n=0;n<e.length;n+=1)t.strings.push({name:`string_`+n,type:`STRING`,value:e[n]});return t}function nI(){return new Y.Record(`Global Subr INDEX`,[{name:`subrs`,type:`INDEX`,value:[]}])}function rI(e,t){for(var n=new Y.Record(`Charsets`,[{name:`format`,type:`Card8`,value:0}]),r=0;r<e.length;r+=1){var i=e[r],a=YF(i,t);n.fields.push({name:`glyph_`+r,type:`SID`,value:a})}return n}function iI(e){var t=[],n=e.path;t.push({name:`width`,type:`NUMBER`,value:e.advanceWidth});for(var r=0,i=0,a=0;a<n.commands.length;a+=1){var o=void 0,s=void 0,c=n.commands[a];if(c.type===`Q`){var l=1/3,u=2/3;c={type:`C`,x:c.x,y:c.y,x1:Math.round(l*r+u*c.x1),y1:Math.round(l*i+u*c.y1),x2:Math.round(l*c.x+u*c.x1),y2:Math.round(l*c.y+u*c.y1)}}if(c.type===`M`)o=Math.round(c.x-r),s=Math.round(c.y-i),t.push({name:`dx`,type:`NUMBER`,value:o}),t.push({name:`dy`,type:`NUMBER`,value:s}),t.push({name:`rmoveto`,type:`OP`,value:21}),r=Math.round(c.x),i=Math.round(c.y);else if(c.type===`L`)o=Math.round(c.x-r),s=Math.round(c.y-i),t.push({name:`dx`,type:`NUMBER`,value:o}),t.push({name:`dy`,type:`NUMBER`,value:s}),t.push({name:`rlineto`,type:`OP`,value:5}),r=Math.round(c.x),i=Math.round(c.y);else if(c.type===`C`){var d=Math.round(c.x1-r),f=Math.round(c.y1-i),p=Math.round(c.x2-c.x1),m=Math.round(c.y2-c.y1);o=Math.round(c.x-c.x2),s=Math.round(c.y-c.y2),t.push({name:`dx1`,type:`NUMBER`,value:d}),t.push({name:`dy1`,type:`NUMBER`,value:f}),t.push({name:`dx2`,type:`NUMBER`,value:p}),t.push({name:`dy2`,type:`NUMBER`,value:m}),t.push({name:`dx`,type:`NUMBER`,value:o}),t.push({name:`dy`,type:`NUMBER`,value:s}),t.push({name:`rrcurveto`,type:`OP`,value:8}),r=Math.round(c.x),i=Math.round(c.y)}}return t.push({name:`endchar`,type:`OP`,value:14}),t}function aI(e){for(var t=new Y.Record(`CharStrings INDEX`,[{name:`charStrings`,type:`INDEX`,value:[]}]),n=0;n<e.length;n+=1){var r=e.get(n),i=iI(r);t.charStrings.push({name:r.name,type:`CHARSTRING`,value:i})}return t}function oI(e,t){var n=new Y.Record(`Private DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=QF(BF,e,t),n}function sI(e,t){for(var n=new Y.Table(`CFF `,[{name:`header`,type:`RECORD`},{name:`nameIndex`,type:`RECORD`},{name:`topDictIndex`,type:`RECORD`},{name:`stringIndex`,type:`RECORD`},{name:`globalSubrIndex`,type:`RECORD`},{name:`charsets`,type:`RECORD`},{name:`charStringsIndex`,type:`RECORD`},{name:`privateDict`,type:`RECORD`}]),r=1/t.unitsPerEm,i={version:t.version,fullName:t.fullName,familyName:t.familyName,weight:t.weightName,fontBBox:t.fontBBox||[0,0,0,0],fontMatrix:[r,0,0,r,0,0],charset:999,encoding:0,charStrings:999,private:[0,999]},a={},o=[],s,c=1;c<e.length;c+=1)s=e.get(c),o.push(s.name);var l=[];n.header=XF(),n.nameIndex=ZF([t.postScriptName]);var u=$F(i,l);return n.topDictIndex=eI(u),n.globalSubrIndex=nI(),n.charsets=rI(o,l),n.charStringsIndex=aI(e),n.privateDict=oI(a,l),n.stringIndex=tI(l),i.charset=n.header.sizeOf()+n.nameIndex.sizeOf()+n.topDictIndex.sizeOf()+n.stringIndex.sizeOf()+n.globalSubrIndex.sizeOf(),i.encoding=0,i.charStrings=i.charset+n.charsets.sizeOf(),i.private[1]=i.charStrings+n.charStringsIndex.sizeOf(),u=$F(i,l),n.topDictIndex=eI(u),n}var cI={parse:JF,make:sI};function lI(e,t){var n={},r=new Z.Parser(e,t);return n.version=r.parseVersion(),n.fontRevision=Math.round(r.parseFixed()*1e3)/1e3,n.checkSumAdjustment=r.parseULong(),n.magicNumber=r.parseULong(),K.argument(n.magicNumber===1594834165,`Font header has wrong magic number.`),n.flags=r.parseUShort(),n.unitsPerEm=r.parseUShort(),n.created=r.parseLongDateTime(),n.modified=r.parseLongDateTime(),n.xMin=r.parseShort(),n.yMin=r.parseShort(),n.xMax=r.parseShort(),n.yMax=r.parseShort(),n.macStyle=r.parseUShort(),n.lowestRecPPEM=r.parseUShort(),n.fontDirectionHint=r.parseShort(),n.indexToLocFormat=r.parseShort(),n.glyphDataFormat=r.parseShort(),n}function uI(e){var t=Math.round(new Date().getTime()/1e3)+2082844800,n=t;return e.createdTimestamp&&(n=e.createdTimestamp+2082844800),new Y.Table(`head`,[{name:`version`,type:`FIXED`,value:65536},{name:`fontRevision`,type:`FIXED`,value:65536},{name:`checkSumAdjustment`,type:`ULONG`,value:0},{name:`magicNumber`,type:`ULONG`,value:1594834165},{name:`flags`,type:`USHORT`,value:0},{name:`unitsPerEm`,type:`USHORT`,value:1e3},{name:`created`,type:`LONGDATETIME`,value:n},{name:`modified`,type:`LONGDATETIME`,value:t},{name:`xMin`,type:`SHORT`,value:0},{name:`yMin`,type:`SHORT`,value:0},{name:`xMax`,type:`SHORT`,value:0},{name:`yMax`,type:`SHORT`,value:0},{name:`macStyle`,type:`USHORT`,value:0},{name:`lowestRecPPEM`,type:`USHORT`,value:0},{name:`fontDirectionHint`,type:`SHORT`,value:2},{name:`indexToLocFormat`,type:`SHORT`,value:0},{name:`glyphDataFormat`,type:`SHORT`,value:0}],e)}var dI={parse:lI,make:uI};function fI(e,t){var n={},r=new Z.Parser(e,t);return n.version=r.parseVersion(),n.ascender=r.parseShort(),n.descender=r.parseShort(),n.lineGap=r.parseShort(),n.advanceWidthMax=r.parseUShort(),n.minLeftSideBearing=r.parseShort(),n.minRightSideBearing=r.parseShort(),n.xMaxExtent=r.parseShort(),n.caretSlopeRise=r.parseShort(),n.caretSlopeRun=r.parseShort(),n.caretOffset=r.parseShort(),r.relativeOffset+=8,n.metricDataFormat=r.parseShort(),n.numberOfHMetrics=r.parseUShort(),n}function pI(e){return new Y.Table(`hhea`,[{name:`version`,type:`FIXED`,value:65536},{name:`ascender`,type:`FWORD`,value:0},{name:`descender`,type:`FWORD`,value:0},{name:`lineGap`,type:`FWORD`,value:0},{name:`advanceWidthMax`,type:`UFWORD`,value:0},{name:`minLeftSideBearing`,type:`FWORD`,value:0},{name:`minRightSideBearing`,type:`FWORD`,value:0},{name:`xMaxExtent`,type:`FWORD`,value:0},{name:`caretSlopeRise`,type:`SHORT`,value:1},{name:`caretSlopeRun`,type:`SHORT`,value:0},{name:`caretOffset`,type:`SHORT`,value:0},{name:`reserved1`,type:`SHORT`,value:0},{name:`reserved2`,type:`SHORT`,value:0},{name:`reserved3`,type:`SHORT`,value:0},{name:`reserved4`,type:`SHORT`,value:0},{name:`metricDataFormat`,type:`SHORT`,value:0},{name:`numberOfHMetrics`,type:`USHORT`,value:0}],e)}var mI={parse:fI,make:pI};function hI(e,t,n,r,i){for(var a,o,s=new Z.Parser(e,t),c=0;c<r;c+=1){c<n&&(a=s.parseUShort(),o=s.parseShort());var l=i.get(c);l.advanceWidth=a,l.leftSideBearing=o}}function gI(e,t,n,r,i){e._hmtxTableData={};for(var a,o,s=new Z.Parser(t,n),c=0;c<i;c+=1)c<r&&(a=s.parseUShort(),o=s.parseShort()),e._hmtxTableData[c]={advanceWidth:a,leftSideBearing:o}}function _I(e,t,n,r,i,a,o){o.lowMemory?gI(e,t,n,r,i):hI(t,n,r,i,a)}function vI(e){for(var t=new Y.Table(`hmtx`,[]),n=0;n<e.length;n+=1){var r=e.get(n),i=r.advanceWidth||0,a=r.leftSideBearing||0;t.fields.push({name:`advanceWidth_`+n,type:`USHORT`,value:i}),t.fields.push({name:`leftSideBearing_`+n,type:`SHORT`,value:a})}return t}var yI={parse:_I,make:vI};function bI(e){for(var t=new Y.Table(`ltag`,[{name:`version`,type:`ULONG`,value:1},{name:`flags`,type:`ULONG`,value:0},{name:`numTags`,type:`ULONG`,value:e.length}]),n=``,r=12+e.length*4,i=0;i<e.length;++i){var a=n.indexOf(e[i]);a<0&&(a=n.length,n+=e[i]),t.fields.push({name:`offset `+i,type:`USHORT`,value:r+a}),t.fields.push({name:`length `+i,type:`USHORT`,value:e[i].length})}return t.fields.push({name:`stringPool`,type:`CHARARRAY`,value:n}),t}function xI(e,t){var n=new Z.Parser(e,t),r=n.parseULong();K.argument(r===1,`Unsupported ltag table version.`),n.skip(`uLong`,1);for(var i=n.parseULong(),a=[],o=0;o<i;o++){for(var s=``,c=t+n.parseUShort(),l=n.parseUShort(),u=c;u<c+l;++u)s+=String.fromCharCode(e.getInt8(u));a.push(s)}return a}var SI={make:bI,parse:xI};function CI(e,t){var n={},r=new Z.Parser(e,t);return n.version=r.parseVersion(),n.numGlyphs=r.parseUShort(),n.version===1&&(n.maxPoints=r.parseUShort(),n.maxContours=r.parseUShort(),n.maxCompositePoints=r.parseUShort(),n.maxCompositeContours=r.parseUShort(),n.maxZones=r.parseUShort(),n.maxTwilightPoints=r.parseUShort(),n.maxStorage=r.parseUShort(),n.maxFunctionDefs=r.parseUShort(),n.maxInstructionDefs=r.parseUShort(),n.maxStackElements=r.parseUShort(),n.maxSizeOfInstructions=r.parseUShort(),n.maxComponentElements=r.parseUShort(),n.maxComponentDepth=r.parseUShort()),n}function wI(e){return new Y.Table(`maxp`,[{name:`version`,type:`FIXED`,value:20480},{name:`numGlyphs`,type:`USHORT`,value:e}])}var TI={parse:CI,make:wI},EI=[`copyright`,`fontFamily`,`fontSubfamily`,`uniqueID`,`fullName`,`version`,`postScriptName`,`trademark`,`manufacturer`,`designer`,`description`,`manufacturerURL`,`designerURL`,`license`,`licenseURL`,`reserved`,`preferredFamily`,`preferredSubfamily`,`compatibleFullName`,`sampleText`,`postScriptFindFontName`,`wwsFamily`,`wwsSubfamily`],DI={0:`en`,1:`fr`,2:`de`,3:`it`,4:`nl`,5:`sv`,6:`es`,7:`da`,8:`pt`,9:`no`,10:`he`,11:`ja`,12:`ar`,13:`fi`,14:`el`,15:`is`,16:`mt`,17:`tr`,18:`hr`,19:`zh-Hant`,20:`ur`,21:`hi`,22:`th`,23:`ko`,24:`lt`,25:`pl`,26:`hu`,27:`es`,28:`lv`,29:`se`,30:`fo`,31:`fa`,32:`ru`,33:`zh`,34:`nl-BE`,35:`ga`,36:`sq`,37:`ro`,38:`cz`,39:`sk`,40:`si`,41:`yi`,42:`sr`,43:`mk`,44:`bg`,45:`uk`,46:`be`,47:`uz`,48:`kk`,49:`az-Cyrl`,50:`az-Arab`,51:`hy`,52:`ka`,53:`mo`,54:`ky`,55:`tg`,56:`tk`,57:`mn-CN`,58:`mn`,59:`ps`,60:`ks`,61:`ku`,62:`sd`,63:`bo`,64:`ne`,65:`sa`,66:`mr`,67:`bn`,68:`as`,69:`gu`,70:`pa`,71:`or`,72:`ml`,73:`kn`,74:`ta`,75:`te`,76:`si`,77:`my`,78:`km`,79:`lo`,80:`vi`,81:`id`,82:`tl`,83:`ms`,84:`ms-Arab`,85:`am`,86:`ti`,87:`om`,88:`so`,89:`sw`,90:`rw`,91:`rn`,92:`ny`,93:`mg`,94:`eo`,128:`cy`,129:`eu`,130:`ca`,131:`la`,132:`qu`,133:`gn`,134:`ay`,135:`tt`,136:`ug`,137:`dz`,138:`jv`,139:`su`,140:`gl`,141:`af`,142:`br`,143:`iu`,144:`gd`,145:`gv`,146:`ga`,147:`to`,148:`el-polyton`,149:`kl`,150:`az`,151:`nn`},OI={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:5,11:1,12:4,13:0,14:6,15:0,16:0,17:0,18:0,19:2,20:4,21:9,22:21,23:3,24:29,25:29,26:29,27:29,28:29,29:0,30:0,31:4,32:7,33:25,34:0,35:0,36:0,37:0,38:29,39:29,40:0,41:5,42:7,43:7,44:7,45:7,46:7,47:7,48:7,49:7,50:4,51:24,52:23,53:7,54:7,55:7,56:7,57:27,58:7,59:4,60:4,61:4,62:4,63:26,64:9,65:9,66:9,67:13,68:13,69:11,70:10,71:12,72:17,73:16,74:14,75:15,76:18,77:19,78:20,79:22,80:30,81:0,82:0,83:0,84:4,85:28,86:28,87:28,88:0,89:0,90:0,91:0,92:0,93:0,94:0,128:0,129:0,130:0,131:0,132:0,133:0,134:0,135:7,136:4,137:26,138:0,139:0,140:0,141:0,142:0,143:28,144:0,145:0,146:0,147:0,148:6,149:0,150:0,151:0},kI={1078:`af`,1052:`sq`,1156:`gsw`,1118:`am`,5121:`ar-DZ`,15361:`ar-BH`,3073:`ar`,2049:`ar-IQ`,11265:`ar-JO`,13313:`ar-KW`,12289:`ar-LB`,4097:`ar-LY`,6145:`ary`,8193:`ar-OM`,16385:`ar-QA`,1025:`ar-SA`,10241:`ar-SY`,7169:`aeb`,14337:`ar-AE`,9217:`ar-YE`,1067:`hy`,1101:`as`,2092:`az-Cyrl`,1068:`az`,1133:`ba`,1069:`eu`,1059:`be`,2117:`bn`,1093:`bn-IN`,8218:`bs-Cyrl`,5146:`bs`,1150:`br`,1026:`bg`,1027:`ca`,3076:`zh-HK`,5124:`zh-MO`,2052:`zh`,4100:`zh-SG`,1028:`zh-TW`,1155:`co`,1050:`hr`,4122:`hr-BA`,1029:`cs`,1030:`da`,1164:`prs`,1125:`dv`,2067:`nl-BE`,1043:`nl`,3081:`en-AU`,10249:`en-BZ`,4105:`en-CA`,9225:`en-029`,16393:`en-IN`,6153:`en-IE`,8201:`en-JM`,17417:`en-MY`,5129:`en-NZ`,13321:`en-PH`,18441:`en-SG`,7177:`en-ZA`,11273:`en-TT`,2057:`en-GB`,1033:`en`,12297:`en-ZW`,1061:`et`,1080:`fo`,1124:`fil`,1035:`fi`,2060:`fr-BE`,3084:`fr-CA`,1036:`fr`,5132:`fr-LU`,6156:`fr-MC`,4108:`fr-CH`,1122:`fy`,1110:`gl`,1079:`ka`,3079:`de-AT`,1031:`de`,5127:`de-LI`,4103:`de-LU`,2055:`de-CH`,1032:`el`,1135:`kl`,1095:`gu`,1128:`ha`,1037:`he`,1081:`hi`,1038:`hu`,1039:`is`,1136:`ig`,1057:`id`,1117:`iu`,2141:`iu-Latn`,2108:`ga`,1076:`xh`,1077:`zu`,1040:`it`,2064:`it-CH`,1041:`ja`,1099:`kn`,1087:`kk`,1107:`km`,1158:`quc`,1159:`rw`,1089:`sw`,1111:`kok`,1042:`ko`,1088:`ky`,1108:`lo`,1062:`lv`,1063:`lt`,2094:`dsb`,1134:`lb`,1071:`mk`,2110:`ms-BN`,1086:`ms`,1100:`ml`,1082:`mt`,1153:`mi`,1146:`arn`,1102:`mr`,1148:`moh`,1104:`mn`,2128:`mn-CN`,1121:`ne`,1044:`nb`,2068:`nn`,1154:`oc`,1096:`or`,1123:`ps`,1045:`pl`,1046:`pt`,2070:`pt-PT`,1094:`pa`,1131:`qu-BO`,2155:`qu-EC`,3179:`qu`,1048:`ro`,1047:`rm`,1049:`ru`,9275:`smn`,4155:`smj-NO`,5179:`smj`,3131:`se-FI`,1083:`se`,2107:`se-SE`,8251:`sms`,6203:`sma-NO`,7227:`sms`,1103:`sa`,7194:`sr-Cyrl-BA`,3098:`sr`,6170:`sr-Latn-BA`,2074:`sr-Latn`,1132:`nso`,1074:`tn`,1115:`si`,1051:`sk`,1060:`sl`,11274:`es-AR`,16394:`es-BO`,13322:`es-CL`,9226:`es-CO`,5130:`es-CR`,7178:`es-DO`,12298:`es-EC`,17418:`es-SV`,4106:`es-GT`,18442:`es-HN`,2058:`es-MX`,19466:`es-NI`,6154:`es-PA`,15370:`es-PY`,10250:`es-PE`,20490:`es-PR`,3082:`es`,1034:`es`,21514:`es-US`,14346:`es-UY`,8202:`es-VE`,2077:`sv-FI`,1053:`sv`,1114:`syr`,1064:`tg`,2143:`tzm`,1097:`ta`,1092:`tt`,1098:`te`,1054:`th`,1105:`bo`,1055:`tr`,1090:`tk`,1152:`ug`,1058:`uk`,1070:`hsb`,1056:`ur`,2115:`uz-Cyrl`,1091:`uz`,1066:`vi`,1106:`cy`,1160:`wo`,1157:`sah`,1144:`ii`,1130:`yo`};function AI(e,t,n){switch(e){case 0:if(t===65535)return`und`;if(n)return n[t];break;case 1:return DI[t];case 3:return kI[t]}}var jI=`utf-16`,MI={0:`macintosh`,1:`x-mac-japanese`,2:`x-mac-chinesetrad`,3:`x-mac-korean`,6:`x-mac-greek`,7:`x-mac-cyrillic`,9:`x-mac-devanagai`,10:`x-mac-gurmukhi`,11:`x-mac-gujarati`,12:`x-mac-oriya`,13:`x-mac-bengali`,14:`x-mac-tamil`,15:`x-mac-telugu`,16:`x-mac-kannada`,17:`x-mac-malayalam`,18:`x-mac-sinhalese`,19:`x-mac-burmese`,20:`x-mac-khmer`,21:`x-mac-thai`,22:`x-mac-lao`,23:`x-mac-georgian`,24:`x-mac-armenian`,25:`x-mac-chinesesimp`,26:`x-mac-tibetan`,27:`x-mac-mongolian`,28:`x-mac-ethiopic`,29:`x-mac-ce`,30:`x-mac-vietnamese`,31:`x-mac-extarabic`},NI={15:`x-mac-icelandic`,17:`x-mac-turkish`,18:`x-mac-croatian`,24:`x-mac-ce`,25:`x-mac-ce`,26:`x-mac-ce`,27:`x-mac-ce`,28:`x-mac-ce`,30:`x-mac-icelandic`,37:`x-mac-romanian`,38:`x-mac-ce`,39:`x-mac-ce`,40:`x-mac-ce`,143:`x-mac-inuit`,146:`x-mac-gaelic`};function PI(e,t,n){switch(e){case 0:return jI;case 1:return NI[n]||MI[t];case 3:if(t===1||t===10)return jI;break}}function FI(e,t,n){for(var r={},i=new Z.Parser(e,t),a=i.parseUShort(),o=i.parseUShort(),s=i.offset+i.parseUShort(),c=0;c<o;c++){var l=i.parseUShort(),u=i.parseUShort(),d=i.parseUShort(),f=i.parseUShort(),p=EI[f]||f,m=i.parseUShort(),h=i.parseUShort(),g=AI(l,d,n),_=PI(l,u,d);if(_!==void 0&&g!==void 0){var v=void 0;if(v=_===jI?CP.UTF16(e,s+h,m):CP.MACSTRING(e,s+h,m,_),v){var y=r[p];y===void 0&&(y=r[p]={}),y[g]=v}}}return a===1&&i.parseUShort(),r}function II(e){var t={};for(var n in e)t[e[n]]=parseInt(n);return t}function LI(e,t,n,r,i,a){return new Y.Record(`NameRecord`,[{name:`platformID`,type:`USHORT`,value:e},{name:`encodingID`,type:`USHORT`,value:t},{name:`languageID`,type:`USHORT`,value:n},{name:`nameID`,type:`USHORT`,value:r},{name:`length`,type:`USHORT`,value:i},{name:`offset`,type:`USHORT`,value:a}])}function RI(e,t){var n=e.length,r=t.length-n+1;loop:for(var i=0;i<r;i++)for(;i<r;i++){for(var a=0;a<n;a++)if(t[i+a]!==e[a])continue loop;return i}return-1}function zI(e,t){var n=RI(e,t);if(n<0){n=t.length;for(var r=0,i=e.length;r<i;++r)t.push(e[r])}return n}function BI(e,t){var n,r=[],i={},a=II(EI);for(var o in e){var s=a[o];if(s===void 0&&(s=o),n=parseInt(s),isNaN(n))throw Error(`Name table entry "`+o+`" does not exist, see nameTableNames for complete list.`);i[n]=e[o],r.push(n)}for(var c=II(DI),l=II(kI),u=[],d=[],f=0;f<r.length;f++){n=r[f];var p=i[n];for(var m in p){var h=p[m],g=1,_=c[m],v=OI[_],y=PI(g,v,_),b=q.MACSTRING(h,y);b===void 0&&(g=0,_=t.indexOf(m),_<0&&(_=t.length,t.push(m)),v=4,b=q.UTF16(h));var x=zI(b,d);u.push(LI(g,v,_,n,b.length,x));var S=l[m];if(S!==void 0){var C=q.UTF16(h),w=zI(C,d);u.push(LI(3,1,S,n,C.length,w))}}}u.sort(function(e,t){return e.platformID-t.platformID||e.encodingID-t.encodingID||e.languageID-t.languageID||e.nameID-t.nameID});for(var ee=new Y.Table(`name`,[{name:`format`,type:`USHORT`,value:0},{name:`count`,type:`USHORT`,value:u.length},{name:`stringOffset`,type:`USHORT`,value:6+u.length*12}]),te=0;te<u.length;te++)ee.fields.push({name:`record_`+te,type:`RECORD`,value:u[te]});return ee.fields.push({name:`strings`,type:`LITERAL`,value:d}),ee}var VI={parse:FI,make:BI},HI=[{begin:0,end:127},{begin:128,end:255},{begin:256,end:383},{begin:384,end:591},{begin:592,end:687},{begin:688,end:767},{begin:768,end:879},{begin:880,end:1023},{begin:11392,end:11519},{begin:1024,end:1279},{begin:1328,end:1423},{begin:1424,end:1535},{begin:42240,end:42559},{begin:1536,end:1791},{begin:1984,end:2047},{begin:2304,end:2431},{begin:2432,end:2559},{begin:2560,end:2687},{begin:2688,end:2815},{begin:2816,end:2943},{begin:2944,end:3071},{begin:3072,end:3199},{begin:3200,end:3327},{begin:3328,end:3455},{begin:3584,end:3711},{begin:3712,end:3839},{begin:4256,end:4351},{begin:6912,end:7039},{begin:4352,end:4607},{begin:7680,end:7935},{begin:7936,end:8191},{begin:8192,end:8303},{begin:8304,end:8351},{begin:8352,end:8399},{begin:8400,end:8447},{begin:8448,end:8527},{begin:8528,end:8591},{begin:8592,end:8703},{begin:8704,end:8959},{begin:8960,end:9215},{begin:9216,end:9279},{begin:9280,end:9311},{begin:9312,end:9471},{begin:9472,end:9599},{begin:9600,end:9631},{begin:9632,end:9727},{begin:9728,end:9983},{begin:9984,end:10175},{begin:12288,end:12351},{begin:12352,end:12447},{begin:12448,end:12543},{begin:12544,end:12591},{begin:12592,end:12687},{begin:43072,end:43135},{begin:12800,end:13055},{begin:13056,end:13311},{begin:44032,end:55215},{begin:55296,end:57343},{begin:67840,end:67871},{begin:19968,end:40959},{begin:57344,end:63743},{begin:12736,end:12783},{begin:64256,end:64335},{begin:64336,end:65023},{begin:65056,end:65071},{begin:65040,end:65055},{begin:65104,end:65135},{begin:65136,end:65279},{begin:65280,end:65519},{begin:65520,end:65535},{begin:3840,end:4095},{begin:1792,end:1871},{begin:1920,end:1983},{begin:3456,end:3583},{begin:4096,end:4255},{begin:4608,end:4991},{begin:5024,end:5119},{begin:5120,end:5759},{begin:5760,end:5791},{begin:5792,end:5887},{begin:6016,end:6143},{begin:6144,end:6319},{begin:10240,end:10495},{begin:40960,end:42127},{begin:5888,end:5919},{begin:66304,end:66351},{begin:66352,end:66383},{begin:66560,end:66639},{begin:118784,end:119039},{begin:119808,end:120831},{begin:1044480,end:1048573},{begin:65024,end:65039},{begin:917504,end:917631},{begin:6400,end:6479},{begin:6480,end:6527},{begin:6528,end:6623},{begin:6656,end:6687},{begin:11264,end:11359},{begin:11568,end:11647},{begin:19904,end:19967},{begin:43008,end:43055},{begin:65536,end:65663},{begin:65856,end:65935},{begin:66432,end:66463},{begin:66464,end:66527},{begin:66640,end:66687},{begin:66688,end:66735},{begin:67584,end:67647},{begin:68096,end:68191},{begin:119552,end:119647},{begin:73728,end:74751},{begin:119648,end:119679},{begin:7040,end:7103},{begin:7168,end:7247},{begin:7248,end:7295},{begin:43136,end:43231},{begin:43264,end:43311},{begin:43312,end:43359},{begin:43520,end:43615},{begin:65936,end:65999},{begin:66e3,end:66047},{begin:66208,end:66271},{begin:127024,end:127135}];function UI(e){for(var t=0;t<HI.length;t+=1){var n=HI[t];if(e>=n.begin&&e<n.end)return t}return-1}function WI(e,t){var n={},r=new Z.Parser(e,t);n.version=r.parseUShort(),n.xAvgCharWidth=r.parseShort(),n.usWeightClass=r.parseUShort(),n.usWidthClass=r.parseUShort(),n.fsType=r.parseUShort(),n.ySubscriptXSize=r.parseShort(),n.ySubscriptYSize=r.parseShort(),n.ySubscriptXOffset=r.parseShort(),n.ySubscriptYOffset=r.parseShort(),n.ySuperscriptXSize=r.parseShort(),n.ySuperscriptYSize=r.parseShort(),n.ySuperscriptXOffset=r.parseShort(),n.ySuperscriptYOffset=r.parseShort(),n.yStrikeoutSize=r.parseShort(),n.yStrikeoutPosition=r.parseShort(),n.sFamilyClass=r.parseShort(),n.panose=[];for(var i=0;i<10;i++)n.panose[i]=r.parseByte();return n.ulUnicodeRange1=r.parseULong(),n.ulUnicodeRange2=r.parseULong(),n.ulUnicodeRange3=r.parseULong(),n.ulUnicodeRange4=r.parseULong(),n.achVendID=String.fromCharCode(r.parseByte(),r.parseByte(),r.parseByte(),r.parseByte()),n.fsSelection=r.parseUShort(),n.usFirstCharIndex=r.parseUShort(),n.usLastCharIndex=r.parseUShort(),n.sTypoAscender=r.parseShort(),n.sTypoDescender=r.parseShort(),n.sTypoLineGap=r.parseShort(),n.usWinAscent=r.parseUShort(),n.usWinDescent=r.parseUShort(),n.version>=1&&(n.ulCodePageRange1=r.parseULong(),n.ulCodePageRange2=r.parseULong()),n.version>=2&&(n.sxHeight=r.parseShort(),n.sCapHeight=r.parseShort(),n.usDefaultChar=r.parseUShort(),n.usBreakChar=r.parseUShort(),n.usMaxContent=r.parseUShort()),n}function GI(e){return new Y.Table(`OS/2`,[{name:`version`,type:`USHORT`,value:3},{name:`xAvgCharWidth`,type:`SHORT`,value:0},{name:`usWeightClass`,type:`USHORT`,value:0},{name:`usWidthClass`,type:`USHORT`,value:0},{name:`fsType`,type:`USHORT`,value:0},{name:`ySubscriptXSize`,type:`SHORT`,value:650},{name:`ySubscriptYSize`,type:`SHORT`,value:699},{name:`ySubscriptXOffset`,type:`SHORT`,value:0},{name:`ySubscriptYOffset`,type:`SHORT`,value:140},{name:`ySuperscriptXSize`,type:`SHORT`,value:650},{name:`ySuperscriptYSize`,type:`SHORT`,value:699},{name:`ySuperscriptXOffset`,type:`SHORT`,value:0},{name:`ySuperscriptYOffset`,type:`SHORT`,value:479},{name:`yStrikeoutSize`,type:`SHORT`,value:49},{name:`yStrikeoutPosition`,type:`SHORT`,value:258},{name:`sFamilyClass`,type:`SHORT`,value:0},{name:`bFamilyType`,type:`BYTE`,value:0},{name:`bSerifStyle`,type:`BYTE`,value:0},{name:`bWeight`,type:`BYTE`,value:0},{name:`bProportion`,type:`BYTE`,value:0},{name:`bContrast`,type:`BYTE`,value:0},{name:`bStrokeVariation`,type:`BYTE`,value:0},{name:`bArmStyle`,type:`BYTE`,value:0},{name:`bLetterform`,type:`BYTE`,value:0},{name:`bMidline`,type:`BYTE`,value:0},{name:`bXHeight`,type:`BYTE`,value:0},{name:`ulUnicodeRange1`,type:`ULONG`,value:0},{name:`ulUnicodeRange2`,type:`ULONG`,value:0},{name:`ulUnicodeRange3`,type:`ULONG`,value:0},{name:`ulUnicodeRange4`,type:`ULONG`,value:0},{name:`achVendID`,type:`CHARARRAY`,value:`XXXX`},{name:`fsSelection`,type:`USHORT`,value:0},{name:`usFirstCharIndex`,type:`USHORT`,value:0},{name:`usLastCharIndex`,type:`USHORT`,value:0},{name:`sTypoAscender`,type:`SHORT`,value:0},{name:`sTypoDescender`,type:`SHORT`,value:0},{name:`sTypoLineGap`,type:`SHORT`,value:0},{name:`usWinAscent`,type:`USHORT`,value:0},{name:`usWinDescent`,type:`USHORT`,value:0},{name:`ulCodePageRange1`,type:`ULONG`,value:0},{name:`ulCodePageRange2`,type:`ULONG`,value:0},{name:`sxHeight`,type:`SHORT`,value:0},{name:`sCapHeight`,type:`SHORT`,value:0},{name:`usDefaultChar`,type:`USHORT`,value:0},{name:`usBreakChar`,type:`USHORT`,value:0},{name:`usMaxContext`,type:`USHORT`,value:0}],e)}var KI={parse:WI,make:GI,unicodeRanges:HI,getUnicodeRange:UI};function qI(e,t){var n={},r=new Z.Parser(e,t);switch(n.version=r.parseVersion(),n.italicAngle=r.parseFixed(),n.underlinePosition=r.parseShort(),n.underlineThickness=r.parseShort(),n.isFixedPitch=r.parseULong(),n.minMemType42=r.parseULong(),n.maxMemType42=r.parseULong(),n.minMemType1=r.parseULong(),n.maxMemType1=r.parseULong(),n.version){case 1:n.names=lF.slice();break;case 2:n.numberOfGlyphs=r.parseUShort(),n.glyphNameIndex=Array(n.numberOfGlyphs);for(var i=0;i<n.numberOfGlyphs;i++)n.glyphNameIndex[i]=r.parseUShort();n.names=[];for(var a=0;a<n.numberOfGlyphs;a++)if(n.glyphNameIndex[a]>=lF.length){var o=r.parseChar();n.names.push(r.parseString(o))}break;case 2.5:n.numberOfGlyphs=r.parseUShort(),n.offset=Array(n.numberOfGlyphs);for(var s=0;s<n.numberOfGlyphs;s++)n.offset[s]=r.parseChar();break}return n}function JI(){return new Y.Table(`post`,[{name:`version`,type:`FIXED`,value:196608},{name:`italicAngle`,type:`FIXED`,value:0},{name:`underlinePosition`,type:`FWORD`,value:0},{name:`underlineThickness`,type:`FWORD`,value:0},{name:`isFixedPitch`,type:`ULONG`,value:0},{name:`minMemType42`,type:`ULONG`,value:0},{name:`maxMemType42`,type:`ULONG`,value:0},{name:`minMemType1`,type:`ULONG`,value:0},{name:`maxMemType1`,type:`ULONG`,value:0}])}var YI={parse:qI,make:JI},XI=Array(9);XI[1]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{substFormat:1,coverage:this.parsePointer(X.coverage),deltaGlyphId:this.parseUShort()};if(t===2)return{substFormat:2,coverage:this.parsePointer(X.coverage),substitute:this.parseOffset16List()};K.assert(!1,`0x`+e.toString(16)+`: lookup type 1 format must be 1 or 2.`)},XI[2]=function(){var e=this.parseUShort();return K.argument(e===1,`GSUB Multiple Substitution Subtable identifier-format must be 1`),{substFormat:e,coverage:this.parsePointer(X.coverage),sequences:this.parseListOfLists()}},XI[3]=function(){var e=this.parseUShort();return K.argument(e===1,`GSUB Alternate Substitution Subtable identifier-format must be 1`),{substFormat:e,coverage:this.parsePointer(X.coverage),alternateSets:this.parseListOfLists()}},XI[4]=function(){var e=this.parseUShort();return K.argument(e===1,`GSUB ligature table identifier-format must be 1`),{substFormat:e,coverage:this.parsePointer(X.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var ZI={sequenceIndex:X.uShort,lookupListIndex:X.uShort};XI[5]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{substFormat:t,coverage:this.parsePointer(X.coverage),ruleSets:this.parseListOfLists(function(){var e=this.parseUShort(),t=this.parseUShort();return{input:this.parseUShortList(e-1),lookupRecords:this.parseRecordList(t,ZI)}})};if(t===2)return{substFormat:t,coverage:this.parsePointer(X.coverage),classDef:this.parsePointer(X.classDef),classSets:this.parseListOfLists(function(){var e=this.parseUShort(),t=this.parseUShort();return{classes:this.parseUShortList(e-1),lookupRecords:this.parseRecordList(t,ZI)}})};if(t===3){var n=this.parseUShort(),r=this.parseUShort();return{substFormat:t,coverages:this.parseList(n,X.pointer(X.coverage)),lookupRecords:this.parseRecordList(r,ZI)}}K.assert(!1,`0x`+e.toString(16)+`: lookup type 5 format must be 1, 2 or 3.`)},XI[6]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{substFormat:1,coverage:this.parsePointer(X.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(ZI)}})};if(t===2)return{substFormat:2,coverage:this.parsePointer(X.coverage),backtrackClassDef:this.parsePointer(X.classDef),inputClassDef:this.parsePointer(X.classDef),lookaheadClassDef:this.parsePointer(X.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(ZI)}})};if(t===3)return{substFormat:3,backtrackCoverage:this.parseList(X.pointer(X.coverage)),inputCoverage:this.parseList(X.pointer(X.coverage)),lookaheadCoverage:this.parseList(X.pointer(X.coverage)),lookupRecords:this.parseRecordList(ZI)};K.assert(!1,`0x`+e.toString(16)+`: lookup type 6 format must be 1, 2 or 3.`)},XI[7]=function(){var e=this.parseUShort();K.argument(e===1,`GSUB Extension Substitution subtable identifier-format must be 1`);var t=this.parseUShort(),n=new X(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:t,extension:XI[t].call(n)}},XI[8]=function(){var e=this.parseUShort();return K.argument(e===1,`GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1`),{substFormat:e,coverage:this.parsePointer(X.coverage),backtrackCoverage:this.parseList(X.pointer(X.coverage)),lookaheadCoverage:this.parseList(X.pointer(X.coverage)),substitutes:this.parseUShortList()}};function QI(e,t){t||=0;var n=new X(e,t),r=n.parseVersion(1);return K.argument(r===1||r===1.1,`Unsupported GSUB table version.`),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(XI)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(XI),variations:n.parseFeatureVariationsList()}}var $I=Array(9);$I[1]=function(e){return e.substFormat===1?new Y.Table(`substitutionTable`,[{name:`substFormat`,type:`USHORT`,value:1},{name:`coverage`,type:`TABLE`,value:new Y.Coverage(e.coverage)},{name:`deltaGlyphID`,type:`USHORT`,value:e.deltaGlyphId}]):new Y.Table(`substitutionTable`,[{name:`substFormat`,type:`USHORT`,value:2},{name:`coverage`,type:`TABLE`,value:new Y.Coverage(e.coverage)}].concat(Y.ushortList(`substitute`,e.substitute)))},$I[2]=function(e){return K.assert(e.substFormat===1,`Lookup type 2 substFormat must be 1.`),new Y.Table(`substitutionTable`,[{name:`substFormat`,type:`USHORT`,value:1},{name:`coverage`,type:`TABLE`,value:new Y.Coverage(e.coverage)}].concat(Y.tableList(`seqSet`,e.sequences,function(e){return new Y.Table(`sequenceSetTable`,Y.ushortList(`sequence`,e))})))},$I[3]=function(e){return K.assert(e.substFormat===1,`Lookup type 3 substFormat must be 1.`),new Y.Table(`substitutionTable`,[{name:`substFormat`,type:`USHORT`,value:1},{name:`coverage`,type:`TABLE`,value:new Y.Coverage(e.coverage)}].concat(Y.tableList(`altSet`,e.alternateSets,function(e){return new Y.Table(`alternateSetTable`,Y.ushortList(`alternate`,e))})))},$I[4]=function(e){return K.assert(e.substFormat===1,`Lookup type 4 substFormat must be 1.`),new Y.Table(`substitutionTable`,[{name:`substFormat`,type:`USHORT`,value:1},{name:`coverage`,type:`TABLE`,value:new Y.Coverage(e.coverage)}].concat(Y.tableList(`ligSet`,e.ligatureSets,function(e){return new Y.Table(`ligatureSetTable`,Y.tableList(`ligature`,e,function(e){return new Y.Table(`ligatureTable`,[{name:`ligGlyph`,type:`USHORT`,value:e.ligGlyph}].concat(Y.ushortList(`component`,e.components,e.components.length+1)))}))})))},$I[6]=function(e){if(e.substFormat===1)return new Y.Table(`chainContextTable`,[{name:`substFormat`,type:`USHORT`,value:e.substFormat},{name:`coverage`,type:`TABLE`,value:new Y.Coverage(e.coverage)}].concat(Y.tableList(`chainRuleSet`,e.chainRuleSets,function(e){return new Y.Table(`chainRuleSetTable`,Y.tableList(`chainRule`,e,function(e){var t=Y.ushortList(`backtrackGlyph`,e.backtrack,e.backtrack.length).concat(Y.ushortList(`inputGlyph`,e.input,e.input.length+1)).concat(Y.ushortList(`lookaheadGlyph`,e.lookahead,e.lookahead.length)).concat(Y.ushortList(`substitution`,[],e.lookupRecords.length));return e.lookupRecords.forEach(function(e,n){t=t.concat({name:`sequenceIndex`+n,type:`USHORT`,value:e.sequenceIndex}).concat({name:`lookupListIndex`+n,type:`USHORT`,value:e.lookupListIndex})}),new Y.Table(`chainRuleTable`,t)}))})));if(e.substFormat===2)K.assert(!1,`lookup type 6 format 2 is not yet supported.`);else if(e.substFormat===3){var t=[{name:`substFormat`,type:`USHORT`,value:e.substFormat}];return t.push({name:`backtrackGlyphCount`,type:`USHORT`,value:e.backtrackCoverage.length}),e.backtrackCoverage.forEach(function(e,n){t.push({name:`backtrackCoverage`+n,type:`TABLE`,value:new Y.Coverage(e)})}),t.push({name:`inputGlyphCount`,type:`USHORT`,value:e.inputCoverage.length}),e.inputCoverage.forEach(function(e,n){t.push({name:`inputCoverage`+n,type:`TABLE`,value:new Y.Coverage(e)})}),t.push({name:`lookaheadGlyphCount`,type:`USHORT`,value:e.lookaheadCoverage.length}),e.lookaheadCoverage.forEach(function(e,n){t.push({name:`lookaheadCoverage`+n,type:`TABLE`,value:new Y.Coverage(e)})}),t.push({name:`substitutionCount`,type:`USHORT`,value:e.lookupRecords.length}),e.lookupRecords.forEach(function(e,n){t=t.concat({name:`sequenceIndex`+n,type:`USHORT`,value:e.sequenceIndex}).concat({name:`lookupListIndex`+n,type:`USHORT`,value:e.lookupListIndex})}),new Y.Table(`chainContextTable`,t)}K.assert(!1,`lookup type 6 format must be 1, 2 or 3.`)};function eL(e){return new Y.Table(`GSUB`,[{name:`version`,type:`ULONG`,value:65536},{name:`scripts`,type:`TABLE`,value:new Y.ScriptList(e.scripts)},{name:`features`,type:`TABLE`,value:new Y.FeatureList(e.features)},{name:`lookups`,type:`TABLE`,value:new Y.LookupList(e.lookups,$I)}])}var tL={parse:QI,make:eL};function nL(e,t){var n=new Z.Parser(e,t),r=n.parseULong();K.argument(r===1,`Unsupported META table version.`),n.parseULong(),n.parseULong();for(var i=n.parseULong(),a={},o=0;o<i;o++){var s=n.parseTag(),c=n.parseULong(),l=n.parseULong();a[s]=CP.UTF8(e,t+c,l)}return a}function rL(e){var t=Object.keys(e).length,n=``,r=16+t*12,i=new Y.Table(`meta`,[{name:`version`,type:`ULONG`,value:1},{name:`flags`,type:`ULONG`,value:0},{name:`offset`,type:`ULONG`,value:r},{name:`numTags`,type:`ULONG`,value:t}]);for(var a in e){var o=n.length;n+=e[a],i.fields.push({name:`tag `+a,type:`TAG`,value:a}),i.fields.push({name:`offset `+a,type:`ULONG`,value:r+o}),i.fields.push({name:`length `+a,type:`ULONG`,value:e[a].length})}return i.fields.push({name:`stringPool`,type:`CHARARRAY`,value:n}),i}var iL={parse:nL,make:rL};function aL(e){return Math.log(e)/Math.log(2)|0}function oL(e){for(;e.length%4!=0;)e.push(0);for(var t=0,n=0;n<e.length;n+=4)t+=(e[n]<<24)+(e[n+1]<<16)+(e[n+2]<<8)+e[n+3];return t%=2**32,t}function sL(e,t,n,r){return new Y.Record(`Table Record`,[{name:`tag`,type:`TAG`,value:e===void 0?``:e},{name:`checkSum`,type:`ULONG`,value:t===void 0?0:t},{name:`offset`,type:`ULONG`,value:n===void 0?0:n},{name:`length`,type:`ULONG`,value:r===void 0?0:r}])}function cL(e){var t=new Y.Table(`sfnt`,[{name:`version`,type:`TAG`,value:`OTTO`},{name:`numTables`,type:`USHORT`,value:0},{name:`searchRange`,type:`USHORT`,value:0},{name:`entrySelector`,type:`USHORT`,value:0},{name:`rangeShift`,type:`USHORT`,value:0}]);t.tables=e,t.numTables=e.length;var n=2**aL(t.numTables);t.searchRange=16*n,t.entrySelector=aL(n),t.rangeShift=t.numTables*16-t.searchRange;for(var r=[],i=[],a=t.sizeOf()+sL().sizeOf()*t.numTables;a%4!=0;)a+=1,i.push({name:`padding`,type:`BYTE`,value:0});for(var o=0;o<e.length;o+=1){var s=e[o];K.argument(s.tableName.length===4,`Table name`+s.tableName+` is invalid.`);var c=s.sizeOf(),l=sL(s.tableName,oL(s.encode()),a,c);for(r.push({name:l.tag+` Table Record`,type:`RECORD`,value:l}),i.push({name:s.tableName+` table`,type:`RECORD`,value:s}),a+=c,K.argument(!isNaN(a),`Something went wrong calculating the offset.`);a%4!=0;)a+=1,i.push({name:`padding`,type:`BYTE`,value:0})}return r.sort(function(e,t){return e.value.tag>t.value.tag?1:-1}),t.fields=t.fields.concat(r),t.fields=t.fields.concat(i),t}function lL(e,t,n){for(var r=0;r<t.length;r+=1){var i=e.charToGlyphIndex(t[r]);if(i>0)return e.glyphs.get(i).getMetrics()}return n}function uL(e){for(var t=0,n=0;n<e.length;n+=1)t+=e[n];return t/e.length}function dL(e){for(var t=[],n=[],r=[],i=[],a=[],o=[],s=[],c,l=0,u=0,d=0,f=0,p=0,m=0;m<e.glyphs.length;m+=1){var h=e.glyphs.get(m),g=h.unicode|0;if(isNaN(h.advanceWidth))throw Error(`Glyph `+h.name+` (`+m+`): advanceWidth is not a number.`);(c>g||c===void 0)&&g>0&&(c=g),l<g&&(l=g);var _=KI.getUnicodeRange(g);if(_<32)u|=1<<_;else if(_<64)d|=1<<_-32;else if(_<96)f|=1<<_-64;else if(_<123)p|=1<<_-96;else throw Error(`Unicode ranges bits > 123 are reserved for internal usage`);if(h.name!==`.notdef`){var v=h.getMetrics();t.push(v.xMin),n.push(v.yMin),r.push(v.xMax),i.push(v.yMax),o.push(v.leftSideBearing),s.push(v.rightSideBearing),a.push(h.advanceWidth)}}var y={xMin:Math.min.apply(null,t),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,r),yMax:Math.max.apply(null,i),advanceWidthMax:Math.max.apply(null,a),advanceWidthAvg:uL(a),minLeftSideBearing:Math.min.apply(null,o),maxLeftSideBearing:Math.max.apply(null,o),minRightSideBearing:Math.min.apply(null,s)};y.ascender=e.ascender,y.descender=e.descender;var b=dI.make({flags:3,unitsPerEm:e.unitsPerEm,xMin:y.xMin,yMin:y.yMin,xMax:y.xMax,yMax:y.yMax,lowestRecPPEM:3,createdTimestamp:e.createdTimestamp}),x=mI.make({ascender:y.ascender,descender:y.descender,advanceWidthMax:y.advanceWidthMax,minLeftSideBearing:y.minLeftSideBearing,minRightSideBearing:y.minRightSideBearing,xMaxExtent:y.maxLeftSideBearing+(y.xMax-y.xMin),numberOfHMetrics:e.glyphs.length}),S=TI.make(e.glyphs.length),C=KI.make(Object.assign({xAvgCharWidth:Math.round(y.advanceWidthAvg),usFirstCharIndex:c,usLastCharIndex:l,ulUnicodeRange1:u,ulUnicodeRange2:d,ulUnicodeRange3:f,ulUnicodeRange4:p,sTypoAscender:y.ascender,sTypoDescender:y.descender,sTypoLineGap:0,usWinAscent:y.yMax,usWinDescent:Math.abs(y.yMin),ulCodePageRange1:1,sxHeight:lL(e,`xyvw`,{yMax:Math.round(y.ascender/2)}).yMax,sCapHeight:lL(e,`HIKLEFJMNTZBDPRAGOQSUVWXY`,y).yMax,usDefaultChar:e.hasChar(` `)?32:0,usBreakChar:e.hasChar(` `)?32:0},e.tables.os2)),w=yI.make(e.glyphs),ee=aF.make(e.glyphs),te=e.getEnglishName(`fontFamily`),ne=e.getEnglishName(`fontSubfamily`),re=te+` `+ne,ie=e.getEnglishName(`postScriptName`);ie||=te.replace(/\s/g,``)+`-`+ne;var ae={};for(var oe in e.names)ae[oe]=e.names[oe];ae.uniqueID||={en:e.getEnglishName(`manufacturer`)+`:`+re},ae.postScriptName||={en:ie},ae.preferredFamily||=e.names.fontFamily,ae.preferredSubfamily||=e.names.fontSubfamily;var se=[],ce=VI.make(ae,se),le=se.length>0?SI.make(se):void 0,ue=YI.make(),de=cI.make(e.glyphs,{version:e.getEnglishName(`version`),fullName:re,familyName:te,weightName:ne,postScriptName:ie,unitsPerEm:e.unitsPerEm,fontBBox:[0,y.yMin,y.ascender,y.advanceWidthMax]}),fe=e.metas&&Object.keys(e.metas).length>0?iL.make(e.metas):void 0,pe=[b,x,S,C,ce,ee,ue,de,w];le&&pe.push(le),e.tables.gsub&&pe.push(tL.make(e.tables.gsub)),fe&&pe.push(fe);for(var me=cL(pe),he=oL(me.encode()),ge=me.fields,_e=!1,ve=0;ve<ge.length;ve+=1)if(ge[ve].name===`head table`){ge[ve].value.checkSumAdjustment=2981146554-he,_e=!0;break}if(!_e)throw Error(`Could not find head table with checkSum to adjust.`);return me}var fL={make:cL,fontToTable:dL,computeCheckSum:oL};function pL(e,t){for(var n=0,r=e.length-1;n<=r;){var i=n+r>>>1,a=e[i].tag;if(a===t)return i;a<t?n=i+1:r=i-1}return-n-1}function mL(e,t){for(var n=0,r=e.length-1;n<=r;){var i=n+r>>>1,a=e[i];if(a===t)return i;a<t?n=i+1:r=i-1}return-n-1}function hL(e,t){for(var n,r=0,i=e.length-1;r<=i;){var a=r+i>>>1;n=e[a];var o=n.start;if(o===t)return n;o<t?r=a+1:i=a-1}if(r>0)return n=e[r-1],t>n.end?0:n}function gL(e,t){this.font=e,this.tableName=t}gL.prototype={searchTag:pL,binSearch:mL,getTable:function(e){var t=this.font.tables[this.tableName];return!t&&e&&(t=this.font.tables[this.tableName]=this.createDefaultTable()),t},getScriptNames:function(){var e=this.getTable();return e?e.scripts.map(function(e){return e.tag}):[]},getDefaultScriptName:function(){var e=this.getTable();if(e){for(var t=!1,n=0;n<e.scripts.length;n++){var r=e.scripts[n].tag;if(r===`DFLT`)return r;r===`latn`&&(t=!0)}if(t)return`latn`}},getScriptTable:function(e,t){var n=this.getTable(t);if(n){e||=`DFLT`;var r=n.scripts,i=pL(n.scripts,e);if(i>=0)return r[i].script;if(t){var a={tag:e,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return r.splice(-1-i,0,a),a.script}}},getLangSysTable:function(e,t,n){var r=this.getScriptTable(e,n);if(r){if(!t||t===`dflt`||t===`DFLT`)return r.defaultLangSys;var i=pL(r.langSysRecords,t);if(i>=0)return r.langSysRecords[i].langSys;if(n){var a={tag:t,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return r.langSysRecords.splice(-1-i,0,a),a.langSys}}},getFeatureTable:function(e,t,n,r){var i=this.getLangSysTable(e,t,r);if(i){for(var a,o=i.featureIndexes,s=this.font.tables[this.tableName].features,c=0;c<o.length;c++)if(a=s[o[c]],a.tag===n)return a.feature;if(r){var l=s.length;return K.assert(l===0||n>=s[l-1].tag,`Features must be added in alphabetical order.`),a={tag:n,feature:{params:0,lookupListIndexes:[]}},s.push(a),o.push(l),a.feature}}},getLookupTables:function(e,t,n,r,i){var a=this.getFeatureTable(e,t,n,i),o=[];if(a){for(var s,c=a.lookupListIndexes,l=this.font.tables[this.tableName].lookups,u=0;u<c.length;u++)s=l[c[u]],s.lookupType===r&&o.push(s);if(o.length===0&&i){s={lookupType:r,lookupFlag:0,subtables:[],markFilteringSet:void 0};var d=l.length;return l.push(s),c.push(d),[s]}}return o},getGlyphClass:function(e,t){switch(e.format){case 1:return e.startGlyph<=t&&t<e.startGlyph+e.classes.length?e.classes[t-e.startGlyph]:0;case 2:var n=hL(e.ranges,t);return n?n.classId:0}},getCoverageIndex:function(e,t){switch(e.format){case 1:var n=mL(e.glyphs,t);return n>=0?n:-1;case 2:var r=hL(e.ranges,t);return r?r.index+t-r.start:-1}},expandCoverage:function(e){if(e.format===1)return e.glyphs;for(var t=[],n=e.ranges,r=0;r<n.length;r++)for(var i=n[r],a=i.start,o=i.end,s=a;s<=o;s++)t.push(s);return t}};function _L(e){gL.call(this,e,`gpos`)}_L.prototype=gL.prototype,_L.prototype.init=function(){var e=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(e)},_L.prototype.getKerningValue=function(e,t,n){for(var r=0;r<e.length;r++)for(var i=e[r].subtables,a=0;a<i.length;a++){var o=i[a],s=this.getCoverageIndex(o.coverage,t);if(!(s<0))switch(o.posFormat){case 1:for(var c=o.pairSets[s],l=0;l<c.length;l++){var u=c[l];if(u.secondGlyph===n)return u.value1&&u.value1.xAdvance||0}break;case 2:var d=this.getGlyphClass(o.classDef1,t),f=this.getGlyphClass(o.classDef2,n),p=o.classRecords[d][f];return p.value1&&p.value1.xAdvance||0}}return 0},_L.prototype.getKerningTables=function(e,t){if(this.font.tables.gpos)return this.getLookupTables(e,t,`kern`,2)};function vL(e){gL.call(this,e,`gsub`)}function yL(e,t){var n=e.length;if(n!==t.length)return!1;for(var r=0;r<n;r++)if(e[r]!==t[r])return!1;return!0}function bL(e,t,n){for(var r=e.subtables,i=0;i<r.length;i++){var a=r[i];if(a.substFormat===t)return a}if(n)return r.push(n),n}vL.prototype=gL.prototype,vL.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:`DFLT`,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}},vL.prototype.getSingle=function(e,t,n){for(var r=[],i=this.getLookupTables(t,n,e,1),a=0;a<i.length;a++)for(var o=i[a].subtables,s=0;s<o.length;s++){var c=o[s],l=this.expandCoverage(c.coverage),u=void 0;if(c.substFormat===1){var d=c.deltaGlyphId;for(u=0;u<l.length;u++){var f=l[u];r.push({sub:f,by:f+d})}}else{var p=c.substitute;for(u=0;u<l.length;u++)r.push({sub:l[u],by:p[u]})}}return r},vL.prototype.getMultiple=function(e,t,n){for(var r=[],i=this.getLookupTables(t,n,e,2),a=0;a<i.length;a++)for(var o=i[a].subtables,s=0;s<o.length;s++){var c=o[s],l=this.expandCoverage(c.coverage),u=void 0;for(u=0;u<l.length;u++){var d=l[u],f=c.sequences[u];r.push({sub:d,by:f})}}return r},vL.prototype.getAlternates=function(e,t,n){for(var r=[],i=this.getLookupTables(t,n,e,3),a=0;a<i.length;a++)for(var o=i[a].subtables,s=0;s<o.length;s++)for(var c=o[s],l=this.expandCoverage(c.coverage),u=c.alternateSets,d=0;d<l.length;d++)r.push({sub:l[d],by:u[d]});return r},vL.prototype.getLigatures=function(e,t,n){for(var r=[],i=this.getLookupTables(t,n,e,4),a=0;a<i.length;a++)for(var o=i[a].subtables,s=0;s<o.length;s++)for(var c=o[s],l=this.expandCoverage(c.coverage),u=c.ligatureSets,d=0;d<l.length;d++)for(var f=l[d],p=u[d],m=0;m<p.length;m++){var h=p[m];r.push({sub:[f].concat(h.components),by:h.ligGlyph})}return r},vL.prototype.addSingle=function(e,t,n,r){var i=this.getLookupTables(n,r,e,1,!0)[0],a=bL(i,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});K.assert(a.coverage.format===1,`Single: unable to modify coverage table format `+a.coverage.format);var o=t.sub,s=this.binSearch(a.coverage.glyphs,o);s<0&&(s=-1-s,a.coverage.glyphs.splice(s,0,o),a.substitute.splice(s,0,0)),a.substitute[s]=t.by},vL.prototype.addMultiple=function(e,t,n,r){K.assert(t.by instanceof Array&&t.by.length>1,`Multiple: "by" must be an array of two or more ids`);var i=this.getLookupTables(n,r,e,2,!0)[0],a=bL(i,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});K.assert(a.coverage.format===1,`Multiple: unable to modify coverage table format `+a.coverage.format);var o=t.sub,s=this.binSearch(a.coverage.glyphs,o);s<0&&(s=-1-s,a.coverage.glyphs.splice(s,0,o),a.sequences.splice(s,0,0)),a.sequences[s]=t.by},vL.prototype.addAlternate=function(e,t,n,r){var i=this.getLookupTables(n,r,e,3,!0)[0],a=bL(i,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});K.assert(a.coverage.format===1,`Alternate: unable to modify coverage table format `+a.coverage.format);var o=t.sub,s=this.binSearch(a.coverage.glyphs,o);s<0&&(s=-1-s,a.coverage.glyphs.splice(s,0,o),a.alternateSets.splice(s,0,0)),a.alternateSets[s]=t.by},vL.prototype.addLigature=function(e,t,n,r){var i=this.getLookupTables(n,r,e,4,!0)[0],a=i.subtables[0];a||(a={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},i.subtables[0]=a),K.assert(a.coverage.format===1,`Ligature: unable to modify coverage table format `+a.coverage.format);var o=t.sub[0],s=t.sub.slice(1),c={ligGlyph:t.by,components:s},l=this.binSearch(a.coverage.glyphs,o);if(l>=0){for(var u=a.ligatureSets[l],d=0;d<u.length;d++)if(yL(u[d].components,s))return;u.push(c)}else l=-1-l,a.coverage.glyphs.splice(l,0,o),a.ligatureSets.splice(l,0,[c])},vL.prototype.getFeature=function(e,t,n){if(/ss\d\d/.test(e))return this.getSingle(e,t,n);switch(e){case`aalt`:case`salt`:return this.getSingle(e,t,n).concat(this.getAlternates(e,t,n));case`dlig`:case`liga`:case`rlig`:return this.getLigatures(e,t,n);case`ccmp`:return this.getMultiple(e,t,n).concat(this.getLigatures(e,t,n));case`stch`:return this.getMultiple(e,t,n)}},vL.prototype.add=function(e,t,n,r){if(/ss\d\d/.test(e))return this.addSingle(e,t,n,r);switch(e){case`aalt`:case`salt`:return typeof t.by==`number`?this.addSingle(e,t,n,r):this.addAlternate(e,t,n,r);case`dlig`:case`liga`:case`rlig`:return this.addLigature(e,t,n,r);case`ccmp`:return t.by instanceof Array?this.addMultiple(e,t,n,r):this.addLigature(e,t,n,r)}};function xL(){return typeof window<`u`}function SL(e){for(var t=new ArrayBuffer(e.length),n=new Uint8Array(t),r=0;r<e.length;++r)n[r]=e[r];return t}function CL(e){for(var t=new Buffer(e.byteLength),n=new Uint8Array(e),r=0;r<t.length;++r)t[r]=n[r];return t}function wL(e,t){if(!e)throw t}function TL(e,t,n,r,i){var a;return(t&r)>0?(a=e.parseByte(),(t&i)===0&&(a=-a),a=n+a):a=(t&i)>0?n:n+e.parseShort(),a}function EL(e,t,n){var r=new Z.Parser(t,n);e.numberOfContours=r.parseShort(),e._xMin=r.parseShort(),e._yMin=r.parseShort(),e._xMax=r.parseShort(),e._yMax=r.parseShort();var i,a;if(e.numberOfContours>0){for(var o=e.endPointIndices=[],s=0;s<e.numberOfContours;s+=1)o.push(r.parseUShort());e.instructionLength=r.parseUShort(),e.instructions=[];for(var c=0;c<e.instructionLength;c+=1)e.instructions.push(r.parseByte());var l=o[o.length-1]+1;i=[];for(var u=0;u<l;u+=1)if(a=r.parseByte(),i.push(a),(a&8)>0)for(var d=r.parseByte(),f=0;f<d;f+=1)i.push(a),u+=1;if(K.argument(i.length===l,`Bad flags.`),o.length>0){var p=[],m;if(l>0){for(var h=0;h<l;h+=1)a=i[h],m={},m.onCurve=!!(a&1),m.lastPointOfContour=o.indexOf(h)>=0,p.push(m);for(var g=0,_=0;_<l;_+=1)a=i[_],m=p[_],m.x=TL(r,a,g,2,16),g=m.x;for(var v=0,y=0;y<l;y+=1)a=i[y],m=p[y],m.y=TL(r,a,v,4,32),v=m.y}e.points=p}else e.points=[]}else if(e.numberOfContours===0)e.points=[];else{e.isComposite=!0,e.points=[],e.components=[];for(var b=!0;b;){i=r.parseUShort();var x={glyphIndex:r.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(i&1)>0?(i&2)>0?(x.dx=r.parseShort(),x.dy=r.parseShort()):x.matchedPoints=[r.parseUShort(),r.parseUShort()]:(i&2)>0?(x.dx=r.parseChar(),x.dy=r.parseChar()):x.matchedPoints=[r.parseByte(),r.parseByte()],(i&8)>0?x.xScale=x.yScale=r.parseF2Dot14():(i&64)>0?(x.xScale=r.parseF2Dot14(),x.yScale=r.parseF2Dot14()):(i&128)>0&&(x.xScale=r.parseF2Dot14(),x.scale01=r.parseF2Dot14(),x.scale10=r.parseF2Dot14(),x.yScale=r.parseF2Dot14()),e.components.push(x),b=!!(i&32)}if(i&256){e.instructionLength=r.parseUShort(),e.instructions=[];for(var S=0;S<e.instructionLength;S+=1)e.instructions.push(r.parseByte())}}}function DL(e,t){for(var n=[],r=0;r<e.length;r+=1){var i=e[r],a={x:t.xScale*i.x+t.scale01*i.y+t.dx,y:t.scale10*i.x+t.yScale*i.y+t.dy,onCurve:i.onCurve,lastPointOfContour:i.lastPointOfContour};n.push(a)}return n}function OL(e){for(var t=[],n=[],r=0;r<e.length;r+=1){var i=e[r];n.push(i),i.lastPointOfContour&&(t.push(n),n=[])}return K.argument(n.length===0,`There are still points left in the current contour.`),t}function kL(e){var t=new vP;if(!e)return t;for(var n=OL(e),r=0;r<n.length;++r){var i=n[r],a=null,o=i[i.length-1],s=i[0];if(o.onCurve)t.moveTo(o.x,o.y);else if(s.onCurve)t.moveTo(s.x,s.y);else{var c={x:(o.x+s.x)*.5,y:(o.y+s.y)*.5};t.moveTo(c.x,c.y)}for(var l=0;l<i.length;++l)if(a=o,o=s,s=i[(l+1)%i.length],o.onCurve)t.lineTo(o.x,o.y);else{var u=s;a.onCurve||((o.x+a.x)*.5,(o.y+a.y)*.5),s.onCurve||(u={x:(o.x+s.x)*.5,y:(o.y+s.y)*.5}),t.quadraticCurveTo(o.x,o.y,u.x,u.y)}t.closePath()}return t}function AL(e,t){if(t.isComposite)for(var n=0;n<t.components.length;n+=1){var r=t.components[n],i=e.get(r.glyphIndex);if(i.getPath(),i.points){var a=void 0;if(r.matchedPoints===void 0)a=DL(i.points,r);else{if(r.matchedPoints[0]>t.points.length-1||r.matchedPoints[1]>i.points.length-1)throw Error(`Matched points out of range in `+t.name);var o=t.points[r.matchedPoints[0]],s=i.points[r.matchedPoints[1]],c={xScale:r.xScale,scale01:r.scale01,scale10:r.scale10,yScale:r.yScale,dx:0,dy:0};s=DL([s],c)[0],c.dx=o.x-s.x,c.dy=o.y-s.y,a=DL(i.points,c)}t.points=t.points.concat(a)}}return kL(t.points)}function jL(e,t,n,r){for(var i=new EF.GlyphSet(r),a=0;a<n.length-1;a+=1){var o=n[a];o===n[a+1]?i.push(a,EF.glyphLoader(r,a)):i.push(a,EF.ttfGlyphLoader(r,a,EL,e,t+o,AL))}return i}function ML(e,t,n,r){var i=new EF.GlyphSet(r);return r._push=function(a){var o=n[a];o===n[a+1]?i.push(a,EF.glyphLoader(r,a)):i.push(a,EF.ttfGlyphLoader(r,a,EL,e,t+o,AL))},i}function NL(e,t,n,r,i){return i.lowMemory?ML(e,t,n,r):jL(e,t,n,r)}var PL={getPath:kL,parse:NL},FL,IL,LL,RL;function zL(e){this.font=e,this.getCommands=function(e){return PL.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function BL(e){return e}function VL(e){return Math.sign(e)*Math.round(Math.abs(e))}function HL(e){return Math.sign(e)*Math.round(Math.abs(e*2))/2}function UL(e){return Math.sign(e)*(Math.round(Math.abs(e)+.5)-.5)}function WL(e){return Math.sign(e)*Math.ceil(Math.abs(e))}function GL(e){return Math.sign(e)*Math.floor(Math.abs(e))}var KL=function(e){var t=this.srPeriod,n=this.srPhase,r=this.srThreshold,i=1;return e<0&&(e=-e,i=-1),e+=r-n,e=Math.trunc(e/t)*t,e+=n,e<0?n*i:e*i},qL={x:1,y:0,axis:`x`,distance:function(e,t,n,r){return(n?e.xo:e.x)-(r?t.xo:t.x)},interpolate:function(e,t,n,r){var i,a,o,s,c,l,u;if(!r||r===this){if(i=e.xo-t.xo,a=e.xo-n.xo,c=t.x-t.xo,l=n.x-n.xo,o=Math.abs(i),s=Math.abs(a),u=o+s,u===0){e.x=e.xo+(c+l)/2;return}e.x=e.xo+(c*s+l*o)/u;return}if(i=r.distance(e,t,!0,!0),a=r.distance(e,n,!0,!0),c=r.distance(t,t,!1,!0),l=r.distance(n,n,!1,!0),o=Math.abs(i),s=Math.abs(a),u=o+s,u===0){qL.setRelative(e,e,(c+l)/2,r,!0);return}qL.setRelative(e,e,(c*s+l*o)/u,r,!0)},normalSlope:-1/0,setRelative:function(e,t,n,r,i){if(!r||r===this){e.x=(i?t.xo:t.x)+n;return}var a=i?t.xo:t.x,o=i?t.yo:t.y,s=a+n*r.x,c=o+n*r.y;e.x=s+(e.y-c)/r.normalSlope},slope:0,touch:function(e){e.xTouched=!0},touched:function(e){return e.xTouched},untouch:function(e){e.xTouched=!1}},JL={x:0,y:1,axis:`y`,distance:function(e,t,n,r){return(n?e.yo:e.y)-(r?t.yo:t.y)},interpolate:function(e,t,n,r){var i,a,o,s,c,l,u;if(!r||r===this){if(i=e.yo-t.yo,a=e.yo-n.yo,c=t.y-t.yo,l=n.y-n.yo,o=Math.abs(i),s=Math.abs(a),u=o+s,u===0){e.y=e.yo+(c+l)/2;return}e.y=e.yo+(c*s+l*o)/u;return}if(i=r.distance(e,t,!0,!0),a=r.distance(e,n,!0,!0),c=r.distance(t,t,!1,!0),l=r.distance(n,n,!1,!0),o=Math.abs(i),s=Math.abs(a),u=o+s,u===0){JL.setRelative(e,e,(c+l)/2,r,!0);return}JL.setRelative(e,e,(c*s+l*o)/u,r,!0)},normalSlope:0,setRelative:function(e,t,n,r,i){if(!r||r===this){e.y=(i?t.yo:t.y)+n;return}var a=i?t.xo:t.x,o=i?t.yo:t.y,s=a+n*r.x;e.y=o+n*r.y+r.normalSlope*(e.x-s)},slope:1/0,touch:function(e){e.yTouched=!0},touched:function(e){return e.yTouched},untouch:function(e){e.yTouched=!1}};Object.freeze(qL),Object.freeze(JL);function YL(e,t){this.x=e,this.y=t,this.axis=void 0,this.slope=t/e,this.normalSlope=-e/t,Object.freeze(this)}YL.prototype.distance=function(e,t,n,r){return this.x*qL.distance(e,t,n,r)+this.y*JL.distance(e,t,n,r)},YL.prototype.interpolate=function(e,t,n,r){var i,a,o=r.distance(e,t,!0,!0),s=r.distance(e,n,!0,!0),c,l,u;if(i=r.distance(t,t,!1,!0),a=r.distance(n,n,!1,!0),c=Math.abs(o),l=Math.abs(s),u=c+l,u===0){this.setRelative(e,e,(i+a)/2,r,!0);return}this.setRelative(e,e,(i*l+a*c)/u,r,!0)},YL.prototype.setRelative=function(e,t,n,r,i){r||=this;var a=i?t.xo:t.x,o=i?t.yo:t.y,s=a+n*r.x,c=o+n*r.y,l=r.normalSlope,u=this.slope,d=e.x,f=e.y;e.x=(u*d-l*s+c-f)/(u-l),e.y=u*(e.x-d)+f},YL.prototype.touch=function(e){e.xTouched=!0,e.yTouched=!0};function XL(e,t){var n=Math.sqrt(e*e+t*t);return e/=n,t/=n,e===1&&t===0?qL:e===0&&t===1?JL:new YL(e,t)}function ZL(e,t,n,r){this.x=this.xo=Math.round(e*64)/64,this.y=this.yo=Math.round(t*64)/64,this.lastPointOfContour=n,this.onCurve=r,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}ZL.prototype.nextTouched=function(e){for(var t=this.nextPointOnContour;!e.touched(t)&&t!==this;)t=t.nextPointOnContour;return t},ZL.prototype.prevTouched=function(e){for(var t=this.prevPointOnContour;!e.touched(t)&&t!==this;)t=t.prevPointOnContour;return t};var QL=Object.freeze(new ZL(0,0)),$L={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function eR(e,t){switch(this.env=e,this.stack=[],this.prog=t,e){case`glyf`:this.zp0=this.zp1=this.zp2=1,this.rp0=this.rp1=this.rp2=0;case`prep`:this.fv=this.pv=this.dpv=qL,this.round=VL}}zL.prototype.exec=function(e,t){if(typeof t!=`number`)throw Error(`Point size is not a number!`);if(!(this._errorState>2)){var n=this.font,r=this._prepState;if(!r||r.ppem!==t){var i=this._fpgmState;if(!i){eR.prototype=$L,i=this._fpgmState=new eR(`fpgm`,n.tables.fpgm),i.funcs=[],i.font=n,exports.DEBUG&&(console.log(`---EXEC FPGM---`),i.step=-1);try{IL(i)}catch(e){console.log(`Hinting error in FPGM:`+e),this._errorState=3;return}}eR.prototype=i,r=this._prepState=new eR(`prep`,n.tables.prep),r.ppem=t;var a=n.tables.cvt;if(a)for(var o=r.cvt=Array(a.length),s=t/n.unitsPerEm,c=0;c<a.length;c++)o[c]=a[c]*s;else r.cvt=[];exports.DEBUG&&(console.log(`---EXEC PREP---`),r.step=-1);try{IL(r)}catch(e){this._errorState<2&&console.log(`Hinting error in PREP:`+e),this._errorState=2}}if(!(this._errorState>1))try{return LL(e,r)}catch(e){this._errorState<1&&(console.log(`Hinting error:`+e),console.log(`Note: further hinting errors are silenced`)),this._errorState=1;return}}},LL=function(e,t){var n=t.ppem/t.font.unitsPerEm,r=n,i=e.components,a,o,s;if(eR.prototype=t,!i)s=new eR(`glyf`,e.instructions),exports.DEBUG&&(console.log(`---EXEC GLYPH---`),s.step=-1),RL(e,s,n,r),o=s.gZone;else{var c=t.font;o=[],a=[];for(var l=0;l<i.length;l++){var u=i[l],d=c.glyphs.get(u.glyphIndex);s=new eR(`glyf`,d.instructions),exports.DEBUG&&(console.log(`---EXEC COMP `+l+`---`),s.step=-1),RL(d,s,n,r);for(var f=Math.round(u.dx*n),p=Math.round(u.dy*r),m=s.gZone,h=s.contours,g=0;g<m.length;g++){var _=m[g];_.xTouched=_.yTouched=!1,_.xo=_.x+=f,_.yo=_.y+=p}var v=o.length;o.push.apply(o,m);for(var y=0;y<h.length;y++)a.push(h[y]+v)}e.instructions&&!s.inhibitGridFit&&(s=new eR(`glyf`,e.instructions),s.gZone=s.z0=s.z1=s.z2=o,s.contours=a,o.push(new ZL(0,0),new ZL(Math.round(e.advanceWidth*n),0)),exports.DEBUG&&(console.log(`---EXEC COMPOSITE---`),s.step=-1),IL(s),o.length-=2)}return o},RL=function(e,t,n,r){for(var i=e.points||[],a=i.length,o=t.gZone=t.z0=t.z1=t.z2=[],s=t.contours=[],c,l=0;l<a;l++)c=i[l],o[l]=new ZL(c.x*n,c.y*r,c.lastPointOfContour,c.onCurve);for(var u,d,f=0;f<a;f++)c=o[f],u||(u=c,s.push(f)),c.lastPointOfContour?(c.nextPointOnContour=u,u.prevPointOnContour=c,u=void 0):(d=o[f+1],c.nextPointOnContour=d,d.prevPointOnContour=c);if(!t.inhibitGridFit){if(exports.DEBUG){console.log(`PROCESSING GLYPH`,t.stack);for(var p=0;p<a;p++)console.log(p,o[p].x,o[p].y)}if(o.push(new ZL(0,0),new ZL(Math.round(e.advanceWidth*n),0)),IL(t),o.length-=2,exports.DEBUG){console.log(`FINISHED GLYPH`,t.stack);for(var m=0;m<a;m++)console.log(m,o[m].x,o[m].y)}}},IL=function(e){var t=e.prog;if(t){var n=t.length,r;for(e.ip=0;e.ip<n;e.ip++){if(exports.DEBUG&&e.step++,r=FL[t[e.ip]],!r)throw Error(`unknown instruction: 0x`+Number(t[e.ip]).toString(16));r(e)}}};function tR(e){for(var t=e.tZone=Array(e.gZone.length),n=0;n<t.length;n++)t[n]=new ZL(0,0)}function nR(e,t){var n=e.prog,r=e.ip,i=1,a;do if(a=n[++r],a===88)i++;else if(a===89)i--;else if(a===64)r+=n[r+1]+1;else if(a===65)r+=2*n[r+1]+1;else if(a>=176&&a<=183)r+=a-176+1;else if(a>=184&&a<=191)r+=(a-184+1)*2;else if(t&&i===1&&a===27)break;while(i>0);e.ip=r}function rR(e,t){exports.DEBUG&&console.log(t.step,`SVTCA[`+e.axis+`]`),t.fv=t.pv=t.dpv=e}function iR(e,t){exports.DEBUG&&console.log(t.step,`SPVTCA[`+e.axis+`]`),t.pv=t.dpv=e}function aR(e,t){exports.DEBUG&&console.log(t.step,`SFVTCA[`+e.axis+`]`),t.fv=e}function oR(e,t){var n=t.stack,r=n.pop(),i=n.pop(),a=t.z2[r],o=t.z1[i];exports.DEBUG&&console.log(`SPVTL[`+e+`]`,r,i);var s,c;e?(s=a.y-o.y,c=o.x-a.x):(s=o.x-a.x,c=o.y-a.y),t.pv=t.dpv=XL(s,c)}function sR(e,t){var n=t.stack,r=n.pop(),i=n.pop(),a=t.z2[r],o=t.z1[i];exports.DEBUG&&console.log(`SFVTL[`+e+`]`,r,i);var s,c;e?(s=a.y-o.y,c=o.x-a.x):(s=o.x-a.x,c=o.y-a.y),t.fv=XL(s,c)}function cR(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.pv=e.dpv=XL(r,n)}function lR(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.fv=XL(r,n)}function uR(e){var t=e.stack,n=e.pv;exports.DEBUG&&console.log(e.step,`GPV[]`),t.push(n.x*16384),t.push(n.y*16384)}function dR(e){var t=e.stack,n=e.fv;exports.DEBUG&&console.log(e.step,`GFV[]`),t.push(n.x*16384),t.push(n.y*16384)}function fR(e){e.fv=e.pv,exports.DEBUG&&console.log(e.step,`SFVTPV[]`)}function pR(e){var t=e.stack,n=t.pop(),r=t.pop(),i=t.pop(),a=t.pop(),o=t.pop(),s=e.z0,c=e.z1,l=s[n],u=s[r],d=c[i],f=c[a],p=e.z2[o];exports.DEBUG&&console.log(`ISECT[], `,n,r,i,a,o);var m=l.x,h=l.y,g=u.x,_=u.y,v=d.x,y=d.y,b=f.x,x=f.y,S=(m-g)*(y-x)-(h-_)*(v-b),C=m*_-h*g,w=v*x-y*b;p.x=(C*(v-b)-w*(m-g))/S,p.y=(C*(y-x)-w*(h-_))/S}function mR(e){e.rp0=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP0[]`,e.rp0)}function hR(e){e.rp1=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP1[]`,e.rp1)}function gR(e){e.rp2=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP2[]`,e.rp2)}function _R(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP0[]`,t),e.zp0=t,t){case 0:e.tZone||tR(e),e.z0=e.tZone;break;case 1:e.z0=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function vR(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP1[]`,t),e.zp1=t,t){case 0:e.tZone||tR(e),e.z1=e.tZone;break;case 1:e.z1=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function yR(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP2[]`,t),e.zp2=t,t){case 0:e.tZone||tR(e),e.z2=e.tZone;break;case 1:e.z2=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function bR(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZPS[]`,t),e.zp0=e.zp1=e.zp2=t,t){case 0:e.tZone||tR(e),e.z0=e.z1=e.z2=e.tZone;break;case 1:e.z0=e.z1=e.z2=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function xR(e){e.loop=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SLOOP[]`,e.loop)}function SR(e){exports.DEBUG&&console.log(e.step,`RTG[]`),e.round=VL}function CR(e){exports.DEBUG&&console.log(e.step,`RTHG[]`),e.round=UL}function wR(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SMD[]`,t),e.minDis=t/64}function TR(e){exports.DEBUG&&console.log(e.step,`ELSE[]`),nR(e,!1)}function ER(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`JMPR[]`,t),e.ip+=t-1}function DR(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCVTCI[]`,t),e.cvCutIn=t/64}function OR(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DUP[]`),t.push(t[t.length-1])}function kR(e){exports.DEBUG&&console.log(e.step,`POP[]`),e.stack.pop()}function AR(e){exports.DEBUG&&console.log(e.step,`CLEAR[]`),e.stack.length=0}function jR(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SWAP[]`),t.push(n),t.push(r)}function MR(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DEPTH[]`),t.push(t.length)}function NR(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`LOOPCALL[]`,n,r);var i=e.ip,a=e.prog;e.prog=e.funcs[n];for(var o=0;o<r;o++)IL(e),exports.DEBUG&&console.log(++e.step,o+1<r?`next loopcall`:`done loopcall`,o);e.ip=i,e.prog=a}function PR(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`CALL[]`,t);var n=e.ip,r=e.prog;e.prog=e.funcs[t],IL(e),e.ip=n,e.prog=r,exports.DEBUG&&console.log(++e.step,`returning from`,t)}function FR(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CINDEX[]`,n),t.push(t[t.length-n])}function IR(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`MINDEX[]`,n),t.push(t.splice(t.length-n,1)[0])}function LR(e){if(e.env!==`fpgm`)throw Error(`FDEF not allowed here`);var t=e.stack,n=e.prog,r=e.ip,i=t.pop(),a=r;for(exports.DEBUG&&console.log(e.step,`FDEF[]`,i);n[++r]!==45;);e.ip=r,e.funcs[i]=n.slice(a+1,r)}function RR(e,t){var n=t.stack.pop(),r=t.z0[n],i=t.fv,a=t.pv;exports.DEBUG&&console.log(t.step,`MDAP[`+e+`]`,n);var o=a.distance(r,QL);e&&(o=t.round(o)),i.setRelative(r,QL,o,a),i.touch(r),t.rp0=t.rp1=n}function zR(e,t){var n=t.z2,r=n.length-2,i,a,o;exports.DEBUG&&console.log(t.step,`IUP[`+e.axis+`]`);for(var s=0;s<r;s++)i=n[s],!e.touched(i)&&(a=i.prevTouched(e),a!==i&&(o=i.nextTouched(e),a===o&&e.setRelative(i,i,e.distance(a,a,!1,!0),e,!0),e.interpolate(i,a,o,e)))}function BR(e,t){for(var n=t.stack,r=e?t.rp1:t.rp2,i=(e?t.z0:t.z1)[r],a=t.fv,o=t.pv,s=t.loop,c=t.z2;s--;){var l=n.pop(),u=c[l],d=o.distance(i,i,!1,!0);a.setRelative(u,u,d,o),a.touch(u),exports.DEBUG&&console.log(t.step,(t.loop>1?`loop `+(t.loop-s)+`: `:``)+`SHP[`+(e?`rp1`:`rp2`)+`]`,l)}t.loop=1}function VR(e,t){var n=t.stack,r=e?t.rp1:t.rp2,i=(e?t.z0:t.z1)[r],a=t.fv,o=t.pv,s=n.pop(),c=t.z2[t.contours[s]],l=c;exports.DEBUG&&console.log(t.step,`SHC[`+e+`]`,s);var u=o.distance(i,i,!1,!0);do l!==i&&a.setRelative(l,l,u,o),l=l.nextPointOnContour;while(l!==c)}function HR(e,t){var n=t.stack,r=e?t.rp1:t.rp2,i=(e?t.z0:t.z1)[r],a=t.fv,o=t.pv,s=n.pop();exports.DEBUG&&console.log(t.step,`SHZ[`+e+`]`,s);var c;switch(s){case 0:c=t.tZone;break;case 1:c=t.gZone;break;default:throw Error(`Invalid zone`)}for(var l,u=o.distance(i,i,!1,!0),d=c.length-2,f=0;f<d;f++)l=c[f],a.setRelative(l,l,u,o)}function UR(e){for(var t=e.stack,n=e.loop,r=e.fv,i=t.pop()/64,a=e.z2;n--;){var o=t.pop(),s=a[o];exports.DEBUG&&console.log(e.step,(e.loop>1?`loop `+(e.loop-n)+`: `:``)+`SHPIX[]`,o,i),r.setRelative(s,s,i),r.touch(s)}e.loop=1}function WR(e){for(var t=e.stack,n=e.rp1,r=e.rp2,i=e.loop,a=e.z0[n],o=e.z1[r],s=e.fv,c=e.dpv,l=e.z2;i--;){var u=t.pop(),d=l[u];exports.DEBUG&&console.log(e.step,(e.loop>1?`loop `+(e.loop-i)+`: `:``)+`IP[]`,u,n,`<->`,r),s.interpolate(d,a,o,c),s.touch(d)}e.loop=1}function GR(e,t){var n=t.stack,r=n.pop()/64,i=n.pop(),a=t.z1[i],o=t.z0[t.rp0],s=t.fv,c=t.pv;s.setRelative(a,o,r,c),s.touch(a),exports.DEBUG&&console.log(t.step,`MSIRP[`+e+`]`,r,i),t.rp1=t.rp0,t.rp2=i,e&&(t.rp0=i)}function KR(e){for(var t=e.stack,n=e.rp0,r=e.z0[n],i=e.loop,a=e.fv,o=e.pv,s=e.z1;i--;){var c=t.pop(),l=s[c];exports.DEBUG&&console.log(e.step,(e.loop>1?`loop `+(e.loop-i)+`: `:``)+`ALIGNRP[]`,c),a.setRelative(l,r,0,o),a.touch(l)}e.loop=1}function qR(e){exports.DEBUG&&console.log(e.step,`RTDG[]`),e.round=HL}function JR(e,t){var n=t.stack,r=n.pop(),i=n.pop(),a=t.z0[i],o=t.fv,s=t.pv,c=t.cvt[r];exports.DEBUG&&console.log(t.step,`MIAP[`+e+`]`,r,`(`,c,`)`,i);var l=s.distance(a,QL);e&&(Math.abs(l-c)<t.cvCutIn&&(l=c),l=t.round(l)),o.setRelative(a,QL,l,s),t.zp0===0&&(a.xo=a.x,a.yo=a.y),o.touch(a),t.rp0=t.rp1=i}function YR(e){var t=e.prog,n=e.ip,r=e.stack,i=t[++n];exports.DEBUG&&console.log(e.step,`NPUSHB[]`,i);for(var a=0;a<i;a++)r.push(t[++n]);e.ip=n}function XR(e){var t=e.ip,n=e.prog,r=e.stack,i=n[++t];exports.DEBUG&&console.log(e.step,`NPUSHW[]`,i);for(var a=0;a<i;a++){var o=n[++t]<<8|n[++t];o&32768&&(o=-((o^65535)+1)),r.push(o)}e.ip=t}function ZR(e){var t=e.stack,n=e.store;n||=e.store=[];var r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,`WS`,r,i),n[i]=r}function QR(e){var t=e.stack,n=e.store,r=t.pop();exports.DEBUG&&console.log(e.step,`RS`,r);var i=n&&n[r]||0;t.push(i)}function $R(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`WCVTP`,n,r),e.cvt[r]=n/64}function ez(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`RCVT`,n),t.push(e.cvt[n]*64)}function tz(e,t){var n=t.stack,r=n.pop(),i=t.z2[r];exports.DEBUG&&console.log(t.step,`GC[`+e+`]`,r),n.push(t.dpv.distance(i,QL,e,!1)*64)}function nz(e,t){var n=t.stack,r=n.pop(),i=n.pop(),a=t.z1[r],o=t.z0[i],s=t.dpv.distance(o,a,e,e);exports.DEBUG&&console.log(t.step,`MD[`+e+`]`,r,i,`->`,s),t.stack.push(Math.round(s*64))}function rz(e){exports.DEBUG&&console.log(e.step,`MPPEM[]`),e.stack.push(e.ppem)}function iz(e){exports.DEBUG&&console.log(e.step,`FLIPON[]`),e.autoFlip=!0}function az(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`LT[]`,n,r),t.push(+(r<n))}function oz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`LTEQ[]`,n,r),t.push(+(r<=n))}function sz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`GT[]`,n,r),t.push(+(r>n))}function cz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`GTEQ[]`,n,r),t.push(+(r>=n))}function lz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`EQ[]`,n,r),t.push(+(n===r))}function uz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`NEQ[]`,n,r),t.push(n===r?0:1)}function dz(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`ODD[]`,n),t.push(Math.trunc(n)%2?1:0)}function fz(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`EVEN[]`,n),t.push(Math.trunc(n)%2?0:1)}function pz(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`IF[]`,t),t||(nR(e,!0),exports.DEBUG&&console.log(e.step,`EIF[]`))}function mz(e){exports.DEBUG&&console.log(e.step,`EIF[]`)}function hz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`AND[]`,n,r),t.push(n&&r?1:0)}function gz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`OR[]`,n,r),t.push(n||r?1:0)}function _z(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NOT[]`,n),t.push(+!n)}function vz(e,t){var n=t.stack,r=n.pop(),i=t.fv,a=t.pv,o=t.ppem,s=t.deltaBase+(e-1)*16,c=t.deltaShift,l=t.z0;exports.DEBUG&&console.log(t.step,`DELTAP[`+e+`]`,r,n);for(var u=0;u<r;u++){var d=n.pop(),f=n.pop();if(s+((f&240)>>4)===o){var p=(f&15)-8;p>=0&&p++,exports.DEBUG&&console.log(t.step,`DELTAPFIX`,d,`by`,p*c);var m=l[d];i.setRelative(m,m,p*c,a)}}}function yz(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDB[]`,t),e.deltaBase=t}function bz(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDS[]`,t),e.deltaShift=.5**t}function xz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`ADD[]`,n,r),t.push(r+n)}function Sz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SUB[]`,n,r),t.push(r-n)}function Cz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`DIV[]`,n,r),t.push(r*64/n)}function wz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`MUL[]`,n,r),t.push(r*n/64)}function Tz(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`ABS[]`,n),t.push(Math.abs(n))}function Ez(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NEG[]`,n),t.push(-n)}function Dz(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`FLOOR[]`,n),t.push(Math.floor(n/64)*64)}function Oz(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CEILING[]`,n),t.push(Math.ceil(n/64)*64)}function kz(e,t){var n=t.stack,r=n.pop();exports.DEBUG&&console.log(t.step,`ROUND[]`),n.push(t.round(r/64)*64)}function Az(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`WCVTF[]`,n,r),e.cvt[r]=n*e.ppem/e.font.unitsPerEm}function jz(e,t){var n=t.stack,r=n.pop(),i=t.ppem,a=t.deltaBase+(e-1)*16,o=t.deltaShift;exports.DEBUG&&console.log(t.step,`DELTAC[`+e+`]`,r,n);for(var s=0;s<r;s++){var c=n.pop(),l=n.pop();if(a+((l&240)>>4)===i){var u=(l&15)-8;u>=0&&u++;var d=u*o;exports.DEBUG&&console.log(t.step,`DELTACFIX`,c,`by`,d),t.cvt[c]+=d}}}function Mz(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SROUND[]`,t),e.round=KL;var n;switch(t&192){case 0:n=.5;break;case 64:n=1;break;case 128:n=2;break;default:throw Error(`invalid SROUND value`)}switch(e.srPeriod=n,t&48){case 0:e.srPhase=0;break;case 16:e.srPhase=.25*n;break;case 32:e.srPhase=.5*n;break;case 48:e.srPhase=.75*n;break;default:throw Error(`invalid SROUND value`)}t&=15,t===0?e.srThreshold=0:e.srThreshold=(t/8-.5)*n}function Nz(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`S45ROUND[]`,t),e.round=KL;var n;switch(t&192){case 0:n=Math.sqrt(2)/2;break;case 64:n=Math.sqrt(2);break;case 128:n=2*Math.sqrt(2);break;default:throw Error(`invalid S45ROUND value`)}switch(e.srPeriod=n,t&48){case 0:e.srPhase=0;break;case 16:e.srPhase=.25*n;break;case 32:e.srPhase=.5*n;break;case 48:e.srPhase=.75*n;break;default:throw Error(`invalid S45ROUND value`)}t&=15,t===0?e.srThreshold=0:e.srThreshold=(t/8-.5)*n}function Pz(e){exports.DEBUG&&console.log(e.step,`ROFF[]`),e.round=BL}function Fz(e){exports.DEBUG&&console.log(e.step,`RUTG[]`),e.round=WL}function Iz(e){exports.DEBUG&&console.log(e.step,`RDTG[]`),e.round=GL}function Lz(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANCTRL[]`,t)}function Rz(e,t){var n=t.stack,r=n.pop(),i=n.pop(),a=t.z2[r],o=t.z1[i];exports.DEBUG&&console.log(t.step,`SDPVTL[`+e+`]`,r,i);var s,c;e?(s=a.y-o.y,c=o.x-a.x):(s=o.x-a.x,c=o.y-a.y),t.dpv=XL(s,c)}function zz(e){var t=e.stack,n=t.pop(),r=0;exports.DEBUG&&console.log(e.step,`GETINFO[]`,n),n&1&&(r=35),n&32&&(r|=4096),t.push(r)}function Bz(e){var t=e.stack,n=t.pop(),r=t.pop(),i=t.pop();exports.DEBUG&&console.log(e.step,`ROLL[]`),t.push(r),t.push(n),t.push(i)}function Vz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`MAX[]`,n,r),t.push(Math.max(r,n))}function Hz(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`MIN[]`,n,r),t.push(Math.min(r,n))}function Uz(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANTYPE[]`,t)}function Wz(e){var t=e.stack.pop(),n=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`INSTCTRL[]`,t,n),t){case 1:e.inhibitGridFit=!!n;return;case 2:e.ignoreCvt=!!n;return;default:throw Error(`invalid INSTCTRL[] selector`)}}function Gz(e,t){var n=t.stack,r=t.prog,i=t.ip;exports.DEBUG&&console.log(t.step,`PUSHB[`+e+`]`);for(var a=0;a<e;a++)n.push(r[++i]);t.ip=i}function Kz(e,t){var n=t.ip,r=t.prog,i=t.stack;exports.DEBUG&&console.log(t.ip,`PUSHW[`+e+`]`);for(var a=0;a<e;a++){var o=r[++n]<<8|r[++n];o&32768&&(o=-((o^65535)+1)),i.push(o)}t.ip=n}function Q(e,t,n,r,i,a){var o=a.stack,s=e&&o.pop(),c=o.pop(),l=a.rp0,u=a.z0[l],d=a.z1[c],f=a.minDis,p=a.fv,m=a.dpv,h,g=h=m.distance(d,u,!0,!0),_=g>=0?1:-1,v;g=Math.abs(g),e&&(v=a.cvt[s],r&&Math.abs(g-v)<a.cvCutIn&&(g=v)),n&&g<f&&(g=f),r&&(g=a.round(g)),p.setRelative(d,u,_*g,m),p.touch(d),exports.DEBUG&&console.log(a.step,(e?`MIRP[`:`MDRP[`)+(t?`M`:`m`)+(n?`>`:`_`)+(r?`R`:`_`)+(i===0?`Gr`:i===1?`Bl`:i===2?`Wh`:``)+`]`,e?s+`(`+a.cvt[s]+`,`+v+`)`:``,c,`(d =`,h,`->`,_*g,`)`),a.rp1=a.rp0,a.rp2=c,t&&(a.rp0=c)}FL=[rR.bind(void 0,JL),rR.bind(void 0,qL),iR.bind(void 0,JL),iR.bind(void 0,qL),aR.bind(void 0,JL),aR.bind(void 0,qL),oR.bind(void 0,0),oR.bind(void 0,1),sR.bind(void 0,0),sR.bind(void 0,1),cR,lR,uR,dR,fR,pR,mR,hR,gR,_R,vR,yR,bR,xR,SR,CR,wR,TR,ER,DR,void 0,void 0,OR,kR,AR,jR,MR,FR,IR,void 0,void 0,void 0,NR,PR,LR,void 0,RR.bind(void 0,0),RR.bind(void 0,1),zR.bind(void 0,JL),zR.bind(void 0,qL),BR.bind(void 0,0),BR.bind(void 0,1),VR.bind(void 0,0),VR.bind(void 0,1),HR.bind(void 0,0),HR.bind(void 0,1),UR,WR,GR.bind(void 0,0),GR.bind(void 0,1),KR,qR,JR.bind(void 0,0),JR.bind(void 0,1),YR,XR,ZR,QR,$R,ez,tz.bind(void 0,0),tz.bind(void 0,1),void 0,nz.bind(void 0,0),nz.bind(void 0,1),rz,void 0,iz,void 0,void 0,az,oz,sz,cz,lz,uz,dz,fz,pz,mz,hz,gz,_z,vz.bind(void 0,1),yz,bz,xz,Sz,Cz,wz,Tz,Ez,Dz,Oz,kz.bind(void 0,0),kz.bind(void 0,1),kz.bind(void 0,2),kz.bind(void 0,3),void 0,void 0,void 0,void 0,Az,vz.bind(void 0,2),vz.bind(void 0,3),jz.bind(void 0,1),jz.bind(void 0,2),jz.bind(void 0,3),Mz,Nz,void 0,void 0,Pz,void 0,Fz,Iz,kR,kR,void 0,void 0,void 0,void 0,void 0,Lz,Rz.bind(void 0,0),Rz.bind(void 0,1),zz,void 0,Bz,Vz,Hz,Uz,Wz,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,Gz.bind(void 0,1),Gz.bind(void 0,2),Gz.bind(void 0,3),Gz.bind(void 0,4),Gz.bind(void 0,5),Gz.bind(void 0,6),Gz.bind(void 0,7),Gz.bind(void 0,8),Kz.bind(void 0,1),Kz.bind(void 0,2),Kz.bind(void 0,3),Kz.bind(void 0,4),Kz.bind(void 0,5),Kz.bind(void 0,6),Kz.bind(void 0,7),Kz.bind(void 0,8),Q.bind(void 0,0,0,0,0,0),Q.bind(void 0,0,0,0,0,1),Q.bind(void 0,0,0,0,0,2),Q.bind(void 0,0,0,0,0,3),Q.bind(void 0,0,0,0,1,0),Q.bind(void 0,0,0,0,1,1),Q.bind(void 0,0,0,0,1,2),Q.bind(void 0,0,0,0,1,3),Q.bind(void 0,0,0,1,0,0),Q.bind(void 0,0,0,1,0,1),Q.bind(void 0,0,0,1,0,2),Q.bind(void 0,0,0,1,0,3),Q.bind(void 0,0,0,1,1,0),Q.bind(void 0,0,0,1,1,1),Q.bind(void 0,0,0,1,1,2),Q.bind(void 0,0,0,1,1,3),Q.bind(void 0,0,1,0,0,0),Q.bind(void 0,0,1,0,0,1),Q.bind(void 0,0,1,0,0,2),Q.bind(void 0,0,1,0,0,3),Q.bind(void 0,0,1,0,1,0),Q.bind(void 0,0,1,0,1,1),Q.bind(void 0,0,1,0,1,2),Q.bind(void 0,0,1,0,1,3),Q.bind(void 0,0,1,1,0,0),Q.bind(void 0,0,1,1,0,1),Q.bind(void 0,0,1,1,0,2),Q.bind(void 0,0,1,1,0,3),Q.bind(void 0,0,1,1,1,0),Q.bind(void 0,0,1,1,1,1),Q.bind(void 0,0,1,1,1,2),Q.bind(void 0,0,1,1,1,3),Q.bind(void 0,1,0,0,0,0),Q.bind(void 0,1,0,0,0,1),Q.bind(void 0,1,0,0,0,2),Q.bind(void 0,1,0,0,0,3),Q.bind(void 0,1,0,0,1,0),Q.bind(void 0,1,0,0,1,1),Q.bind(void 0,1,0,0,1,2),Q.bind(void 0,1,0,0,1,3),Q.bind(void 0,1,0,1,0,0),Q.bind(void 0,1,0,1,0,1),Q.bind(void 0,1,0,1,0,2),Q.bind(void 0,1,0,1,0,3),Q.bind(void 0,1,0,1,1,0),Q.bind(void 0,1,0,1,1,1),Q.bind(void 0,1,0,1,1,2),Q.bind(void 0,1,0,1,1,3),Q.bind(void 0,1,1,0,0,0),Q.bind(void 0,1,1,0,0,1),Q.bind(void 0,1,1,0,0,2),Q.bind(void 0,1,1,0,0,3),Q.bind(void 0,1,1,0,1,0),Q.bind(void 0,1,1,0,1,1),Q.bind(void 0,1,1,0,1,2),Q.bind(void 0,1,1,0,1,3),Q.bind(void 0,1,1,1,0,0),Q.bind(void 0,1,1,1,0,1),Q.bind(void 0,1,1,1,0,2),Q.bind(void 0,1,1,1,0,3),Q.bind(void 0,1,1,1,1,0),Q.bind(void 0,1,1,1,1,1),Q.bind(void 0,1,1,1,1,2),Q.bind(void 0,1,1,1,1,3)];function qz(e){this.char=e,this.state={},this.activeState=null}function Jz(e,t,n){this.contextName=n,this.startIndex=e,this.endOffset=t}function Yz(e,t,n){this.contextName=e,this.openRange=null,this.ranges=[],this.checkStart=t,this.checkEnd=n}function Xz(e,t){this.context=e,this.index=t,this.length=e.length,this.current=e[t],this.backtrack=e.slice(0,t),this.lookahead=e.slice(t+1)}function Zz(e){this.eventId=e,this.subscribers=[]}function Qz(e){var t=this,n=[`start`,`end`,`next`,`newToken`,`contextStart`,`contextEnd`,`insertToken`,`removeToken`,`removeRange`,`replaceToken`,`replaceRange`,`composeRUD`,`updateContextsRanges`];n.forEach(function(e){Object.defineProperty(t.events,e,{value:new Zz(e)})}),e&&n.forEach(function(n){var r=e[n];typeof r==`function`&&t.events[n].subscribe(r)}),[`insertToken`,`removeToken`,`removeRange`,`replaceToken`,`replaceRange`,`composeRUD`].forEach(function(e){t.events[e].subscribe(t.updateContextsRanges)})}function $z(e){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],Qz.call(this,e)}qz.prototype.setState=function(e,t){return this.state[e]=t,this.activeState={key:e,value:this.state[e]},this.activeState},qz.prototype.getState=function(e){return this.state[e]||null},$z.prototype.inboundIndex=function(e){return e>=0&&e<this.tokens.length},$z.prototype.composeRUD=function(e){var t=this,n=!0,r=e.map(function(e){return t[e[0]].apply(t,e.slice(1).concat(n))}),i=function(e){return typeof e==`object`&&e.hasOwnProperty(`FAIL`)};if(r.every(i))return{FAIL:`composeRUD: one or more operations hasn't completed successfully`,report:r.filter(i)};this.dispatch(`composeRUD`,[r.filter(function(e){return!i(e)})])},$z.prototype.replaceRange=function(e,t,n,r){t=t===null?this.tokens.length:t;var i=n.every(function(e){return e instanceof qz});if(!isNaN(e)&&this.inboundIndex(e)&&i){var a=this.tokens.splice.apply(this.tokens,[e,t].concat(n));return r||this.dispatch(`replaceToken`,[e,t,n]),[a,n]}else return{FAIL:`replaceRange: invalid tokens or startIndex.`}},$z.prototype.replaceToken=function(e,t,n){if(!isNaN(e)&&this.inboundIndex(e)&&t instanceof qz){var r=this.tokens.splice(e,1,t);return n||this.dispatch(`replaceToken`,[e,t]),[r[0],t]}else return{FAIL:`replaceToken: invalid token or index.`}},$z.prototype.removeRange=function(e,t,n){t=isNaN(t)?this.tokens.length:t;var r=this.tokens.splice(e,t);return n||this.dispatch(`removeRange`,[r,e,t]),r},$z.prototype.removeToken=function(e,t){if(!isNaN(e)&&this.inboundIndex(e)){var n=this.tokens.splice(e,1);return t||this.dispatch(`removeToken`,[n,e]),n}else return{FAIL:`removeToken: invalid token index.`}},$z.prototype.insertToken=function(e,t,n){return e.every(function(e){return e instanceof qz})?(this.tokens.splice.apply(this.tokens,[t,0].concat(e)),n||this.dispatch(`insertToken`,[e,t]),e):{FAIL:`insertToken: invalid token(s).`}},$z.prototype.registerModifier=function(e,t,n){this.events.newToken.subscribe(function(r,i){var a=[r,i],o=t===null||t.apply(this,a)===!0,s=[r,i];if(o){var c=n.apply(this,s);r.setState(e,c)}}),this.registeredModifiers.push(e)},Zz.prototype.subscribe=function(e){return typeof e==`function`?this.subscribers.push(e)-1:{FAIL:`invalid '`+this.eventId+`' event handler`}},Zz.prototype.unsubscribe=function(e){this.subscribers.splice(e,1)},Xz.prototype.setCurrentIndex=function(e){this.index=e,this.current=this.context[e],this.backtrack=this.context.slice(0,e),this.lookahead=this.context.slice(e+1)},Xz.prototype.get=function(e){switch(!0){case e===0:return this.current;case e<0&&Math.abs(e)<=this.backtrack.length:return this.backtrack.slice(e)[0];case e>0&&e<=this.lookahead.length:return this.lookahead[e-1];default:return null}},$z.prototype.rangeToText=function(e){if(e instanceof Jz)return this.getRangeTokens(e).map(function(e){return e.char}).join(``)},$z.prototype.getText=function(){return this.tokens.map(function(e){return e.char}).join(``)},$z.prototype.getContext=function(e){return this.registeredContexts[e]||null},$z.prototype.on=function(e,t){var n=this.events[e];return n?n.subscribe(t):null},$z.prototype.dispatch=function(e,t){var n=this,r=this.events[e];r instanceof Zz&&r.subscribers.forEach(function(e){e.apply(n,t||[])})},$z.prototype.registerContextChecker=function(e,t,n){if(this.getContext(e))return{FAIL:`context name '`+e+`' is already registered.`};if(typeof t!=`function`)return{FAIL:`missing context start check.`};if(typeof n!=`function`)return{FAIL:`missing context end check.`};var r=new Yz(e,t,n);return this.registeredContexts[e]=r,this.contextCheckers.push(r),r},$z.prototype.getRangeTokens=function(e){var t=e.startIndex+e.endOffset;return[].concat(this.tokens.slice(e.startIndex,t))},$z.prototype.getContextRanges=function(e){var t=this.getContext(e);return t?t.ranges:{FAIL:`context checker '`+e+`' is not registered.`}},$z.prototype.resetContextsRanges=function(){var e=this.registeredContexts;for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];n.ranges=[]}},$z.prototype.updateContextsRanges=function(){this.resetContextsRanges();for(var e=this.tokens.map(function(e){return e.char}),t=0;t<e.length;t++){var n=new Xz(e,t);this.runContextCheck(n)}this.dispatch(`updateContextsRanges`,[this.registeredContexts])},$z.prototype.setEndOffset=function(e,t){var n=this.getContext(t).openRange.startIndex,r=new Jz(n,e,t),i=this.getContext(t).ranges;return r.rangeId=t+`.`+i.length,i.push(r),this.getContext(t).openRange=null,r},$z.prototype.runContextCheck=function(e){var t=this,n=e.index;this.contextCheckers.forEach(function(r){var i=r.contextName,a=t.getContext(i).openRange;if(!a&&r.checkStart(e)&&(a=new Jz(n,null,i),t.getContext(i).openRange=a,t.dispatch(`contextStart`,[i,n])),a&&r.checkEnd(e)){var o=n-a.startIndex+1,s=t.setEndOffset(o,i);t.dispatch(`contextEnd`,[i,s])}})},$z.prototype.tokenize=function(e){this.tokens=[],this.resetContextsRanges();var t=Array.from(e);this.dispatch(`start`);for(var n=0;n<t.length;n++){var r=t[n],i=new Xz(t,n);this.dispatch(`next`,[i]),this.runContextCheck(i);var a=new qz(r);this.tokens.push(a),this.dispatch(`newToken`,[a,i])}return this.dispatch(`end`,[this.tokens]),this.tokens};function eB(e){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(e)}function tB(e){return/[\u0630\u0690\u0621\u0631\u0661\u0671\u0622\u0632\u0672\u0692\u06C2\u0623\u0673\u0693\u06C3\u0624\u0694\u06C4\u0625\u0675\u0695\u06C5\u06E5\u0676\u0696\u06C6\u0627\u0677\u0697\u06C7\u0648\u0688\u0698\u06C8\u0689\u0699\u06C9\u068A\u06CA\u066B\u068B\u06CB\u068C\u068D\u06CD\u06FD\u068E\u06EE\u06FE\u062F\u068F\u06CF\u06EF]/.test(e)}function nB(e){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(e)}function rB(e){return/[A-z]/.test(e)}function iB(e){return/\s/.test(e)}function aB(e){this.font=e,this.features={}}function oB(e){this.id=e.id,this.tag=e.tag,this.substitution=e.substitution}function sB(e,t){if(!e)return-1;switch(t.format){case 1:return t.glyphs.indexOf(e);case 2:for(var n=t.ranges,r=0;r<n.length;r++){var i=n[r];if(e>=i.start&&e<=i.end){var a=e-i.start;return i.index+a}}break;default:return-1}return-1}function cB(e,t){return sB(e,t.coverage)===-1?null:e+t.deltaGlyphId}function lB(e,t){var n=sB(e,t.coverage);return n===-1?null:t.substitute[n]}function uB(e,t){for(var n=[],r=0;r<e.length;r++){var i=e[r],a=t.current;a=Array.isArray(a)?a[0]:a;var o=sB(a,i);o!==-1&&n.push(o)}return n.length===e.length?n:-1}function dB(e,t){var n=t.inputCoverage.length+t.lookaheadCoverage.length+t.backtrackCoverage.length;if(e.context.length<n)return[];var r=uB(t.inputCoverage,e);if(r===-1)return[];var i=t.inputCoverage.length-1;if(e.lookahead.length<t.lookaheadCoverage.length)return[];for(var a=e.lookahead.slice(i);a.length&&nB(a[0].char);)a.shift();var o=new Xz(a,0),s=uB(t.lookaheadCoverage,o),c=[].concat(e.backtrack);for(c.reverse();c.length&&nB(c[0].char);)c.shift();if(c.length<t.backtrackCoverage.length)return[];var l=new Xz(c,0),u=uB(t.backtrackCoverage,l),d=r.length===t.inputCoverage.length&&s.length===t.lookaheadCoverage.length&&u.length===t.backtrackCoverage.length,f=[];if(d)for(var p=0;p<t.lookupRecords.length;p++)for(var m=t.lookupRecords[p].lookupListIndex,h=this.getLookupByIndex(m),g=0;g<h.subtables.length;g++){var _=h.subtables[g],v=this.getLookupMethod(h,_);if(this.getSubstitutionType(h,_)===`12`)for(var y=0;y<r.length;y++){var b=v(e.get(y));b&&f.push(b)}}return f}function fB(e,t){var n=e.current,r=sB(n,t.coverage);if(r===-1)return null;for(var i,a=t.ligatureSets[r],o=0;o<a.length;o++){i=a[o];for(var s=0;s<i.components.length&&e.lookahead[s]===i.components[s];s++)if(s===i.components.length-1)return i}return null}function pB(e,t){var n=sB(e,t.coverage);return n===-1?null:t.sequences[n]}aB.prototype.getDefaultScriptFeaturesIndexes=function(){for(var e=this.font.tables.gsub.scripts,t=0;t<e.length;t++){var n=e[t];if(n.tag===`DFLT`)return n.script.defaultLangSys.featureIndexes}return[]},aB.prototype.getScriptFeaturesIndexes=function(e){if(!this.font.tables.gsub)return[];if(!e)return this.getDefaultScriptFeaturesIndexes();for(var t=this.font.tables.gsub.scripts,n=0;n<t.length;n++){var r=t[n];if(r.tag===e&&r.script.defaultLangSys)return r.script.defaultLangSys.featureIndexes;var i=r.langSysRecords;if(i)for(var a=0;a<i.length;a++){var o=i[a];if(o.tag===e)return o.langSys.featureIndexes}}return this.getDefaultScriptFeaturesIndexes()},aB.prototype.mapTagsToFeatures=function(e,t){for(var n={},r=0;r<e.length;r++){var i=e[r].tag;n[i]=e[r].feature}this.features[t].tags=n},aB.prototype.getScriptFeatures=function(e){var t=this.features[e];if(this.features.hasOwnProperty(e))return t;var n=this.getScriptFeaturesIndexes(e);if(!n)return null;var r=this.font.tables.gsub;return t=n.map(function(e){return r.features[e]}),this.features[e]=t,this.mapTagsToFeatures(t,e),t},aB.prototype.getSubstitutionType=function(e,t){return e.lookupType.toString()+t.substFormat.toString()},aB.prototype.getLookupMethod=function(e,t){var n=this;switch(this.getSubstitutionType(e,t)){case`11`:return function(e){return cB.apply(n,[e,t])};case`12`:return function(e){return lB.apply(n,[e,t])};case`63`:return function(e){return dB.apply(n,[e,t])};case`41`:return function(e){return fB.apply(n,[e,t])};case`21`:return function(e){return pB.apply(n,[e,t])};default:throw Error(`lookupType: `+e.lookupType+` - substFormat: `+t.substFormat+` is not yet supported`)}},aB.prototype.lookupFeature=function(e){var t=e.contextParams,n=t.index,r=this.getFeature({tag:e.tag,script:e.script});if(!r)return Error(`font '`+this.font.names.fullName.en+`' doesn't support feature '`+e.tag+`' for script '`+e.script+`'.`);for(var i=this.getFeatureLookups(r),a=[].concat(t.context),o=0;o<i.length;o++)for(var s=i[o],c=this.getLookupSubtables(s),l=0;l<c.length;l++){var u=c[l],d=this.getSubstitutionType(s,u),f=this.getLookupMethod(s,u),p=void 0;switch(d){case`11`:p=f(t.current),p&&a.splice(n,1,new oB({id:11,tag:e.tag,substitution:p}));break;case`12`:p=f(t.current),p&&a.splice(n,1,new oB({id:12,tag:e.tag,substitution:p}));break;case`63`:p=f(t),Array.isArray(p)&&p.length&&a.splice(n,1,new oB({id:63,tag:e.tag,substitution:p}));break;case`41`:p=f(t),p&&a.splice(n,1,new oB({id:41,tag:e.tag,substitution:p}));break;case`21`:p=f(t.current),p&&a.splice(n,1,new oB({id:21,tag:e.tag,substitution:p}));break}t=new Xz(a,n),!(Array.isArray(p)&&!p.length)&&(p=null)}return a.length?a:null},aB.prototype.supports=function(e){if(!e.script)return!1;this.getScriptFeatures(e.script);var t=this.features.hasOwnProperty(e.script);if(!e.tag)return t;var n=this.features[e.script].some(function(t){return t.tag===e.tag});return t&&n},aB.prototype.getLookupSubtables=function(e){return e.subtables||null},aB.prototype.getLookupByIndex=function(e){return this.font.tables.gsub.lookups[e]||null},aB.prototype.getFeatureLookups=function(e){return e.lookupListIndexes.map(this.getLookupByIndex.bind(this))},aB.prototype.getFeature=function(e){if(!this.font)return{FAIL:`No font was found`};this.features.hasOwnProperty(e.script)||this.getScriptFeatures(e.script);var t=this.features[e.script];return t?t.tags[e.tag]?this.features[e.script].tags[e.tag]:null:{FAIL:`No feature for script `+e.script}};function mB(e){var t=e.current,n=e.get(-1);return n===null&&eB(t)||!eB(n)&&eB(t)}function hB(e){var t=e.get(1);return t===null||!eB(t)}var gB={startCheck:mB,endCheck:hB};function _B(e){var t=e.current,n=e.get(-1);return(eB(t)||nB(t))&&!eB(n)}function vB(e){var t=e.get(1);switch(!0){case t===null:return!0;case!eB(t)&&!nB(t):var n=iB(t);if(!n)return!0;if(n){var r=!1;if(r=e.lookahead.some(function(e){return eB(e)||nB(e)}),!r)return!0}break;default:return!1}}var yB={startCheck:_B,endCheck:vB};function bB(e,t,n){t[n].setState(e.tag,e.substitution)}function xB(e,t,n){t[n].setState(e.tag,e.substitution)}function SB(e,t,n){e.substitution.forEach(function(r,i){t[n+i].setState(e.tag,r)})}function CB(e,t,n){var r=t[n];r.setState(e.tag,e.substitution.ligGlyph);for(var i=e.substitution.components.length,a=0;a<i;a++)r=t[n+a+1],r.setState(`deleted`,!0)}var wB={11:bB,12:xB,63:SB,41:CB};function TB(e,t,n){e instanceof oB&&wB[e.id]&&wB[e.id](e,t,n)}function EB(e){for(var t=[].concat(e.backtrack),n=t.length-1;n>=0;n--){var r=t[n],i=tB(r),a=nB(r);if(!i&&!a)return!0;if(i)return!1}return!1}function DB(e){if(tB(e.current))return!1;for(var t=0;t<e.lookahead.length;t++){var n=e.lookahead[t];if(!nB(n))return!0}return!1}function OB(e){var t=this,n=`arab`,r=this.featuresTags[n],i=this.tokenizer.getRangeTokens(e);if(i.length!==1){var a=new Xz(i.map(function(e){return e.getState(`glyphIndex`)}),0),o=new Xz(i.map(function(e){return e.char}),0);i.forEach(function(e,s){if(!nB(e.char)){a.setCurrentIndex(s),o.setCurrentIndex(s);var c=0;EB(o)&&(c|=1),DB(o)&&(c|=2);var l;switch(c){case 1:l=`fina`;break;case 2:l=`init`;break;case 3:l=`medi`;break}if(r.indexOf(l)!==-1){var u=t.query.lookupFeature({tag:l,script:n,contextParams:a});if(u instanceof Error)return console.info(u.message);u.forEach(function(e,t){e instanceof oB&&(TB(e,i,t),a.context[t]=e.substitution)})}}})}}function kB(e,t){return new Xz(e.map(function(e){return e.activeState.value}),t||0)}function AB(e){var t=this,n=`arab`,r=this.tokenizer.getRangeTokens(e),i=kB(r);i.context.forEach(function(e,a){i.setCurrentIndex(a);var o=t.query.lookupFeature({tag:`rlig`,script:n,contextParams:i});o.length&&(o.forEach(function(e){return TB(e,r,a)}),i=kB(r))})}function jB(e){var t=e.current,n=e.get(-1);return n===null&&rB(t)||!rB(n)&&rB(t)}function MB(e){var t=e.get(1);return t===null||!rB(t)}var NB={startCheck:jB,endCheck:MB};function PB(e,t){return new Xz(e.map(function(e){return e.activeState.value}),t||0)}function FB(e){var t=this,n=`latn`,r=this.tokenizer.getRangeTokens(e),i=PB(r);i.context.forEach(function(e,a){i.setCurrentIndex(a);var o=t.query.lookupFeature({tag:`liga`,script:n,contextParams:i});o.length&&(o.forEach(function(e){return TB(e,r,a)}),i=PB(r))})}function IB(e){this.baseDir=e||`ltr`,this.tokenizer=new $z,this.featuresTags={}}IB.prototype.setText=function(e){this.text=e},IB.prototype.contextChecks={latinWordCheck:NB,arabicWordCheck:gB,arabicSentenceCheck:yB};function LB(e){var t=this.contextChecks[e+`Check`];return this.tokenizer.registerContextChecker(e,t.startCheck,t.endCheck)}function RB(){return LB.call(this,`latinWord`),LB.call(this,`arabicWord`),LB.call(this,`arabicSentence`),this.tokenizer.tokenize(this.text)}function zB(){var e=this;this.tokenizer.getContextRanges(`arabicSentence`).forEach(function(t){var n=e.tokenizer.getRangeTokens(t);e.tokenizer.replaceRange(t.startIndex,t.endOffset,n.reverse())})}IB.prototype.registerFeatures=function(e,t){var n=this,r=t.filter(function(t){return n.query.supports({script:e,tag:t})});this.featuresTags.hasOwnProperty(e)?this.featuresTags[e]=this.featuresTags[e].concat(r):this.featuresTags[e]=r},IB.prototype.applyFeatures=function(e,t){if(!e)throw Error(`No valid font was provided to apply features`);this.query||=new aB(e);for(var n=0;n<t.length;n++){var r=t[n];this.query.supports({script:r.script})&&this.registerFeatures(r.script,r.tags)}},IB.prototype.registerModifier=function(e,t,n){this.tokenizer.registerModifier(e,t,n)};function BB(){if(this.tokenizer.registeredModifiers.indexOf(`glyphIndex`)===-1)throw Error(`glyphIndex modifier is required to apply arabic presentation features.`)}function VB(){var e=this;this.featuresTags.hasOwnProperty(`arab`)&&(BB.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){OB.call(e,t)}))}function HB(){var e=this,t=`arab`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`rlig`)!==-1&&(BB.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){AB.call(e,t)}))}function UB(){var e=this,t=`latn`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`liga`)!==-1&&(BB.call(this),this.tokenizer.getContextRanges(`latinWord`).forEach(function(t){FB.call(e,t)}))}IB.prototype.checkContextReady=function(e){return!!this.tokenizer.getContext(e)},IB.prototype.applyFeaturesToContexts=function(){this.checkContextReady(`arabicWord`)&&(VB.call(this),HB.call(this)),this.checkContextReady(`latinWord`)&&UB.call(this),this.checkContextReady(`arabicSentence`)&&zB.call(this)},IB.prototype.processText=function(e){(!this.text||this.text!==e)&&(this.setText(e),RB.call(this),this.applyFeaturesToContexts())},IB.prototype.getBidiText=function(e){return this.processText(e),this.tokenizer.getText()},IB.prototype.getTextGlyphs=function(e){this.processText(e);for(var t=[],n=0;n<this.tokenizer.tokens.length;n++){var r=this.tokenizer.tokens[n];if(!r.state.deleted){var i=r.activeState.value;t.push(Array.isArray(i)?i[0]:i)}}return t};function WB(e){e||={},e.tables=e.tables||{},e.empty||(wL(e.familyName,`When creating a new Font object, familyName is required.`),wL(e.styleName,`When creating a new Font object, styleName is required.`),wL(e.unitsPerEm,`When creating a new Font object, unitsPerEm is required.`),wL(e.ascender,`When creating a new Font object, ascender is required.`),wL(e.descender<=0,`When creating a new Font object, negative descender value is required.`),this.names={fontFamily:{en:e.familyName||` `},fontSubfamily:{en:e.styleName||` `},fullName:{en:e.fullName||e.familyName+` `+e.styleName},postScriptName:{en:e.postScriptName||(e.familyName+e.styleName).replace(/\s/g,``)},designer:{en:e.designer||` `},designerURL:{en:e.designerURL||` `},manufacturer:{en:e.manufacturer||` `},manufacturerURL:{en:e.manufacturerURL||` `},license:{en:e.license||` `},licenseURL:{en:e.licenseURL||` `},version:{en:e.version||`Version 0.1`},description:{en:e.description||` `},copyright:{en:e.copyright||` `},trademark:{en:e.trademark||` `}},this.unitsPerEm=e.unitsPerEm||1e3,this.ascender=e.ascender,this.descender=e.descender,this.createdTimestamp=e.createdTimestamp,this.tables=Object.assign(e.tables,{os2:Object.assign({usWeightClass:e.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:e.widthClass||this.usWidthClasses.MEDIUM,fsSelection:e.fsSelection||this.fsSelectionValues.REGULAR},e.tables.os2)})),this.supported=!0,this.glyphs=new EF.GlyphSet(this,e.glyphs||[]),this.encoding=new uF(this),this.position=new _L(this),this.substitution=new vL(this),this.tables=this.tables||{},this._push=null,this._hmtxTableData={},Object.defineProperty(this,"hinting",{get:function(){if(this._hinting)return this._hinting;if(this.outlinesFormat===`truetype`)return this._hinting=new zL(this)}})}WB.prototype.hasChar=function(e){return this.encoding.charToGlyphIndex(e)!==null},WB.prototype.charToGlyphIndex=function(e){return this.encoding.charToGlyphIndex(e)},WB.prototype.charToGlyph=function(e){var t=this.charToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},WB.prototype.updateFeatures=function(e){return this.defaultRenderOptions.features.map(function(t){return t.script===`latn`?{script:`latn`,tags:t.tags.filter(function(t){return e[t]})}:t})},WB.prototype.stringToGlyphs=function(e,t){var n=this,r=new IB;r.registerModifier(`glyphIndex`,null,function(e){return n.charToGlyphIndex(e.char)});var i=t?this.updateFeatures(t.features):this.defaultRenderOptions.features;r.applyFeatures(this,i);for(var a=r.getTextGlyphs(e),o=a.length,s=Array(o),c=this.glyphs.get(0),l=0;l<o;l+=1)s[l]=this.glyphs.get(a[l])||c;return s},WB.prototype.nameToGlyphIndex=function(e){return this.glyphNames.nameToGlyphIndex(e)},WB.prototype.nameToGlyph=function(e){var t=this.nameToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},WB.prototype.glyphIndexToName=function(e){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(e):``},WB.prototype.getKerningValue=function(e,t){e=e.index||e,t=t.index||t;var n=this.position.defaultKerningTables;return n?this.position.getKerningValue(n,e,t):this.kerningPairs[e+`,`+t]||0},WB.prototype.defaultRenderOptions={kerning:!0,features:[{script:`arab`,tags:[`init`,`medi`,`fina`,`rlig`]},{script:`latn`,tags:[`liga`,`rlig`]}]},WB.prototype.forEachGlyph=function(e,t,n,r,i,a){t=t===void 0?0:t,n=n===void 0?0:n,r=r===void 0?72:r,i=Object.assign({},this.defaultRenderOptions,i);var o=1/this.unitsPerEm*r,s=this.stringToGlyphs(e,i),c;if(i.kerning){var l=i.script||this.position.getDefaultScriptName();c=this.position.getKerningTables(l,i.language)}for(var u=0;u<s.length;u+=1){var d=s[u];if(a.call(this,d,t,n,r,i),d.advanceWidth&&(t+=d.advanceWidth*o),i.kerning&&u<s.length-1){var f=c?this.position.getKerningValue(c,d.index,s[u+1].index):this.getKerningValue(d,s[u+1]);t+=f*o}i.letterSpacing?t+=i.letterSpacing*r:i.tracking&&(t+=i.tracking/1e3*r)}return t},WB.prototype.getPath=function(e,t,n,r,i){var a=new vP;return this.forEachGlyph(e,t,n,r,i,function(e,t,n,r){var o=e.getPath(t,n,r,i,this);a.extend(o)}),a},WB.prototype.getPaths=function(e,t,n,r,i){var a=[];return this.forEachGlyph(e,t,n,r,i,function(e,t,n,r){var o=e.getPath(t,n,r,i,this);a.push(o)}),a},WB.prototype.getAdvanceWidth=function(e,t,n){return this.forEachGlyph(e,0,0,t,n,function(){})},WB.prototype.draw=function(e,t,n,r,i,a){this.getPath(t,n,r,i,a).draw(e)},WB.prototype.drawPoints=function(e,t,n,r,i,a){this.forEachGlyph(t,n,r,i,a,function(t,n,r,i){t.drawPoints(e,n,r,i)})},WB.prototype.drawMetrics=function(e,t,n,r,i,a){this.forEachGlyph(t,n,r,i,a,function(t,n,r,i){t.drawMetrics(e,n,r,i)})},WB.prototype.getEnglishName=function(e){var t=this.names[e];if(t)return t.en},WB.prototype.validate=function(){var e=this;function t(t){var n=e.getEnglishName(t);n&&n.trim().length}t(`fontFamily`),t(`weightName`),t(`manufacturer`),t(`copyright`),t(`version`),this.unitsPerEm},WB.prototype.toTables=function(){return fL.fontToTable(this)},WB.prototype.toBuffer=function(){return console.warn(`Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.`),this.toArrayBuffer()},WB.prototype.toArrayBuffer=function(){for(var e=this.toTables().encode(),t=new ArrayBuffer(e.length),n=new Uint8Array(t),r=0;r<e.length;r++)n[r]=e[r];return t},WB.prototype.download=function(e){var t=this.getEnglishName(`fontFamily`),n=this.getEnglishName(`fontSubfamily`);e||=t.replace(/\s/g,``)+`-`+n+`.otf`;var r=this.toArrayBuffer();if(xL())if(window.URL=window.URL||window.webkitURL,window.URL){var i=new DataView(r),a=new Blob([i],{type:`font/opentype`}),o=document.createElement(`a`);o.href=window.URL.createObjectURL(a),o.download=e;var s=document.createEvent(`MouseEvents`);s.initEvent(`click`,!0,!1),o.dispatchEvent(s)}else console.warn(`Font file could not be downloaded. Try using a different browser.`);else{var c=WN(),l=CL(r);c.writeFileSync(e,l)}},WB.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512},WB.prototype.usWidthClasses={ULTRA_CONDENSED:1,EXTRA_CONDENSED:2,CONDENSED:3,SEMI_CONDENSED:4,MEDIUM:5,SEMI_EXPANDED:6,EXPANDED:7,EXTRA_EXPANDED:8,ULTRA_EXPANDED:9},WB.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function GB(e,t){var n=JSON.stringify(e),r=256;for(var i in t){var a=parseInt(i);if(!(!a||a<256)){if(JSON.stringify(t[i])===n)return a;r<=a&&(r=a+1)}}return t[r]=e,r}function KB(e,t,n){var r=GB(t.name,n);return[{name:`tag_`+e,type:`TAG`,value:t.tag},{name:`minValue_`+e,type:`FIXED`,value:t.minValue<<16},{name:`defaultValue_`+e,type:`FIXED`,value:t.defaultValue<<16},{name:`maxValue_`+e,type:`FIXED`,value:t.maxValue<<16},{name:`flags_`+e,type:`USHORT`,value:0},{name:`nameID_`+e,type:`USHORT`,value:r}]}function qB(e,t,n){var r={},i=new Z.Parser(e,t);return r.tag=i.parseTag(),r.minValue=i.parseFixed(),r.defaultValue=i.parseFixed(),r.maxValue=i.parseFixed(),i.skip(`uShort`,1),r.name=n[i.parseUShort()]||{},r}function JB(e,t,n,r){for(var i=GB(t.name,r),a=[{name:`nameID_`+e,type:`USHORT`,value:i},{name:`flags_`+e,type:`USHORT`,value:0}],o=0;o<n.length;++o){var s=n[o].tag;a.push({name:`axis_`+e+` `+s,type:`FIXED`,value:t.coordinates[s]<<16})}return a}function YB(e,t,n,r){var i={},a=new Z.Parser(e,t);i.name=r[a.parseUShort()]||{},a.skip(`uShort`,1),i.coordinates={};for(var o=0;o<n.length;++o)i.coordinates[n[o].tag]=a.parseFixed();return i}function XB(e,t){var n=new Y.Table(`fvar`,[{name:`version`,type:`ULONG`,value:65536},{name:`offsetToData`,type:`USHORT`,value:0},{name:`countSizePairs`,type:`USHORT`,value:2},{name:`axisCount`,type:`USHORT`,value:e.axes.length},{name:`axisSize`,type:`USHORT`,value:20},{name:`instanceCount`,type:`USHORT`,value:e.instances.length},{name:`instanceSize`,type:`USHORT`,value:4+e.axes.length*4}]);n.offsetToData=n.sizeOf();for(var r=0;r<e.axes.length;r++)n.fields=n.fields.concat(KB(r,e.axes[r],t));for(var i=0;i<e.instances.length;i++)n.fields=n.fields.concat(JB(i,e.instances[i],e.axes,t));return n}function ZB(e,t,n){var r=new Z.Parser(e,t),i=r.parseULong();K.argument(i===65536,`Unsupported fvar table version.`);var a=r.parseOffset16();r.skip(`uShort`,1);for(var o=r.parseUShort(),s=r.parseUShort(),c=r.parseUShort(),l=r.parseUShort(),u=[],d=0;d<o;d++)u.push(qB(e,t+a+d*s,n));for(var f=[],p=t+a+o*s,m=0;m<c;m++)f.push(YB(e,p+m*l,u,n));return{axes:u,instances:f}}var QB={make:XB,parse:ZB},$B=function(){return{coverage:this.parsePointer(X.coverage),attachPoints:this.parseList(X.pointer(X.uShortList))}},eV=function(){var e=this.parseUShort();if(K.argument(e===1||e===2||e===3,`Unsupported CaretValue table version.`),e===1)return{coordinate:this.parseShort()};if(e===2)return{pointindex:this.parseShort()};if(e===3)return{coordinate:this.parseShort()}},tV=function(){return this.parseList(X.pointer(eV))},nV=function(){return{coverage:this.parsePointer(X.coverage),ligGlyphs:this.parseList(X.pointer(tV))}},rV=function(){return this.parseUShort(),this.parseList(X.pointer(X.coverage))};function iV(e,t){t||=0;var n=new X(e,t),r=n.parseVersion(1);K.argument(r===1||r===1.2||r===1.3,`Unsupported GDEF table version.`);var i={version:r,classDef:n.parsePointer(X.classDef),attachList:n.parsePointer($B),ligCaretList:n.parsePointer(nV),markAttachClassDef:n.parsePointer(X.classDef)};return r>=1.2&&(i.markGlyphSets=n.parsePointer(rV)),i}var aV={parse:iV},oV=Array(10);oV[1]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{posFormat:1,coverage:this.parsePointer(X.coverage),value:this.parseValueRecord()};if(t===2)return{posFormat:2,coverage:this.parsePointer(X.coverage),values:this.parseValueRecordList()};K.assert(!1,`0x`+e.toString(16)+`: GPOS lookup type 1 format must be 1 or 2.`)},oV[2]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();K.assert(t===1||t===2,`0x`+e.toString(16)+`: GPOS lookup type 2 format must be 1 or 2.`);var n=this.parsePointer(X.coverage),r=this.parseUShort(),i=this.parseUShort();if(t===1)return{posFormat:t,coverage:n,valueFormat1:r,valueFormat2:i,pairSets:this.parseList(X.pointer(X.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(r),value2:this.parseValueRecord(i)}})))};if(t===2){var a=this.parsePointer(X.classDef),o=this.parsePointer(X.classDef),s=this.parseUShort(),c=this.parseUShort();return{posFormat:t,coverage:n,valueFormat1:r,valueFormat2:i,classDef1:a,classDef2:o,class1Count:s,class2Count:c,classRecords:this.parseList(s,X.list(c,function(){return{value1:this.parseValueRecord(r),value2:this.parseValueRecord(i)}}))}}},oV[3]=function(){return{error:`GPOS Lookup 3 not supported`}},oV[4]=function(){return{error:`GPOS Lookup 4 not supported`}},oV[5]=function(){return{error:`GPOS Lookup 5 not supported`}},oV[6]=function(){return{error:`GPOS Lookup 6 not supported`}},oV[7]=function(){return{error:`GPOS Lookup 7 not supported`}},oV[8]=function(){return{error:`GPOS Lookup 8 not supported`}},oV[9]=function(){return{error:`GPOS Lookup 9 not supported`}};function sV(e,t){t||=0;var n=new X(e,t),r=n.parseVersion(1);return K.argument(r===1||r===1.1,`Unsupported GPOS table version `+r),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(oV)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(oV),variations:n.parseFeatureVariationsList()}}var cV=Array(10);function lV(e){return new Y.Table(`GPOS`,[{name:`version`,type:`ULONG`,value:65536},{name:`scripts`,type:`TABLE`,value:new Y.ScriptList(e.scripts)},{name:`features`,type:`TABLE`,value:new Y.FeatureList(e.features)},{name:`lookups`,type:`TABLE`,value:new Y.LookupList(e.lookups,cV)}])}var uV={parse:sV,make:lV};function dV(e){var t={};e.skip(`uShort`);var n=e.parseUShort();K.argument(n===0,`Unsupported kern sub-table version.`),e.skip(`uShort`,2);var r=e.parseUShort();e.skip(`uShort`,3);for(var i=0;i<r;i+=1){var a=e.parseUShort(),o=e.parseUShort(),s=e.parseShort();t[a+`,`+o]=s}return t}function fV(e){var t={};e.skip(`uShort`),e.parseULong()>1&&console.warn(`Only the first kern subtable is supported.`),e.skip(`uLong`);var n=e.parseUShort()&255;if(e.skip(`uShort`),n===0){var r=e.parseUShort();e.skip(`uShort`,3);for(var i=0;i<r;i+=1){var a=e.parseUShort(),o=e.parseUShort(),s=e.parseShort();t[a+`,`+o]=s}}return t}function pV(e,t){var n=new Z.Parser(e,t),r=n.parseUShort();if(r===0)return dV(n);if(r===1)return fV(n);throw Error(`Unsupported kern table version (`+r+`).`)}var mV={parse:pV};function hV(e,t,n,r){for(var i=new Z.Parser(e,t),a=r?i.parseUShort:i.parseULong,o=[],s=0;s<n+1;s+=1){var c=a.call(i);r&&(c*=2),o.push(c)}return o}var gV={parse:hV};function _V(e,t){WN().readFile(e,function(e,n){if(e)return t(e.message);t(null,SL(n))})}function vV(e,t){var n=new XMLHttpRequest;n.open(`get`,e,!0),n.responseType=`arraybuffer`,n.onload=function(){return n.response?t(null,n.response):t(`Font could not be loaded: `+n.statusText)},n.onerror=function(){t(`Font could not be loaded`)},n.send()}function yV(e,t){for(var n=[],r=12,i=0;i<t;i+=1){var a=Z.getTag(e,r),o=Z.getULong(e,r+4),s=Z.getULong(e,r+8),c=Z.getULong(e,r+12);n.push({tag:a,checksum:o,offset:s,length:c,compression:!1}),r+=16}return n}function bV(e,t){for(var n=[],r=44,i=0;i<t;i+=1){var a=Z.getTag(e,r),o=Z.getULong(e,r+4),s=Z.getULong(e,r+8),c=Z.getULong(e,r+12),l=void 0;l=s<c?`WOFF`:!1,n.push({tag:a,offset:o,compression:l,compressedLength:s,length:c}),r+=20}return n}function xV(e,t){if(t.compression===`WOFF`){var n=new Uint8Array(e.buffer,t.offset+2,t.compressedLength-2),r=new Uint8Array(t.length);if(hP(n,r),r.byteLength!==t.length)throw Error(`Decompression error: `+t.tag+` decompressed length doesn't match recorded length`);return{data:new DataView(r.buffer,0),offset:0}}else return{data:e,offset:t.offset}}function SV(e,t){t??={};var n,r,i=new WB({empty:!0}),a=new DataView(e,0),o,s=[],c=Z.getTag(a,0);if(c===`\0\0\0`||c===`true`||c===`typ1`)i.outlinesFormat=`truetype`,o=Z.getUShort(a,4),s=yV(a,o);else if(c===`OTTO`)i.outlinesFormat=`cff`,o=Z.getUShort(a,4),s=yV(a,o);else if(c===`wOFF`){var l=Z.getTag(a,4);if(l===`\0\0\0`)i.outlinesFormat=`truetype`;else if(l===`OTTO`)i.outlinesFormat=`cff`;else throw Error(`Unsupported OpenType flavor `+c);o=Z.getUShort(a,12),s=bV(a,o)}else throw Error(`Unsupported OpenType signature `+c);for(var u,d,f,p,m,h,g,_,v,y,b,x,S=0;S<o;S+=1){var C=s[S],w=void 0;switch(C.tag){case`cmap`:w=xV(a,C),i.tables.cmap=aF.parse(w.data,w.offset),i.encoding=new dF(i.tables.cmap);break;case`cvt `:w=xV(a,C),x=new Z.Parser(w.data,w.offset),i.tables.cvt=x.parseShortList(C.length/2);break;case`fvar`:d=C;break;case`fpgm`:w=xV(a,C),x=new Z.Parser(w.data,w.offset),i.tables.fpgm=x.parseByteList(C.length);break;case`head`:w=xV(a,C),i.tables.head=dI.parse(w.data,w.offset),i.unitsPerEm=i.tables.head.unitsPerEm,n=i.tables.head.indexToLocFormat;break;case`hhea`:w=xV(a,C),i.tables.hhea=mI.parse(w.data,w.offset),i.ascender=i.tables.hhea.ascender,i.descender=i.tables.hhea.descender,i.numberOfHMetrics=i.tables.hhea.numberOfHMetrics;break;case`hmtx`:g=C;break;case`ltag`:w=xV(a,C),r=SI.parse(w.data,w.offset);break;case`maxp`:w=xV(a,C),i.tables.maxp=TI.parse(w.data,w.offset),i.numGlyphs=i.tables.maxp.numGlyphs;break;case`name`:y=C;break;case`OS/2`:w=xV(a,C),i.tables.os2=KI.parse(w.data,w.offset);break;case`post`:w=xV(a,C),i.tables.post=YI.parse(w.data,w.offset),i.glyphNames=new pF(i.tables.post);break;case`prep`:w=xV(a,C),x=new Z.Parser(w.data,w.offset),i.tables.prep=x.parseByteList(C.length);break;case`glyf`:f=C;break;case`loca`:v=C;break;case`CFF `:u=C;break;case`kern`:_=C;break;case`GDEF`:p=C;break;case`GPOS`:m=C;break;case`GSUB`:h=C;break;case`meta`:b=C;break}}var ee=xV(a,y);if(i.tables.name=VI.parse(ee.data,ee.offset,r),i.names=i.tables.name,f&&v){var te=n===0,ne=xV(a,v),re=gV.parse(ne.data,ne.offset,i.numGlyphs,te),ie=xV(a,f);i.glyphs=PL.parse(ie.data,ie.offset,re,i,t)}else if(u){var ae=xV(a,u);cI.parse(ae.data,ae.offset,i,t)}else throw Error(`Font doesn't contain TrueType or CFF outlines.`);var oe=xV(a,g);if(yI.parse(i,oe.data,oe.offset,i.numberOfHMetrics,i.numGlyphs,i.glyphs,t),gF(i,t),_){var se=xV(a,_);i.kerningPairs=mV.parse(se.data,se.offset)}else i.kerningPairs={};if(p){var ce=xV(a,p);i.tables.gdef=aV.parse(ce.data,ce.offset)}if(m){var le=xV(a,m);i.tables.gpos=uV.parse(le.data,le.offset),i.position.init()}if(h){var ue=xV(a,h);i.tables.gsub=tL.parse(ue.data,ue.offset)}if(d){var de=xV(a,d);i.tables.fvar=QB.parse(de.data,de.offset,i.names)}if(b){var fe=xV(a,b);i.tables.meta=iL.parse(fe.data,fe.offset),i.metas=i.tables.meta}return i}function CV(e,t,n){n??={};var r=typeof window>`u`&&!n.isUrl?_V:vV;return new Promise(function(i,a){r(e,function(e,r){if(e){if(t)return t(e);a(e)}var o;try{o=SV(r,n)}catch(e){if(t)return t(e,null);a(e)}if(t)return t(null,o);i(o)})})}function wV(e,t){return SV(SL(WN().readFileSync(e)),t)}var TV=Object.freeze({__proto__:null,Font:WB,Glyph:bF,Path:vP,BoundingBox:_P,_parse:Z,parse:SV,load:CV,loadSync:wV});function EV(e,{ruled:t=!0,startPoint:n,endPoint:r,tolerance:i=1e-6}={},a=!1){if(e.length===0&&!n&&!r)return k(F(`LOFT_EMPTY`,`Loft requires at least one wire or start/end point`));let o=U(),s=n?o.makeVertex(...Kw(n)):void 0,c=r?o.makeVertex(...Kw(r)):void 0;try{let n=W(o.loftAdvanced(e.map(e=>e.wrapped),{solid:!a,ruled:t,tolerance:i,...s?{startVertex:s}:{},...c?{endVertex:c}:{}}));return uw(n)?O(n):k(za(`LOFT_NOT_3D`,`Loft did not produce a 3D shape`))}catch(e){return k(P(`LOFT_FAILED`,`Loft operation failed`,e,void 0,`Common causes: wire profiles with different edge counts, self-intersecting result, or profiles too far apart. Ensure profiles are compatible and ordered.`))}}function DV(e){if(e.length===0)return O([]);let t=U(),n=[],r=e.map(e=>{let r=e.startPoint?t.makeVertex(...Kw(e.startPoint)):void 0,i=e.endPoint?t.makeVertex(...Kw(e.endPoint)):void 0;return r&&n.push(r),i&&n.push(i),{wires:e.wires.map(e=>e.wrapped),solid:!0,ruled:e.ruled??!0,tolerance:e.tolerance??1e-6,startVertex:r,endVertex:i}});try{let e=t.loftBatch?.(r)??r.map(e=>t.loftAdvanced(e.wires,{solid:e.solid,ruled:e.ruled,tolerance:e.tolerance,startVertex:e.startVertex,endVertex:e.endVertex})),n=[];for(let t of e){let e=W(t);if(!uw(e))return k(za(`LOFT_ALL_NOT_3D`,`Batch loft entry did not produce a 3D shape`));n.push(e)}return O(n)}catch(e){return k(P(`LOFT_ALL_FAILED`,`Batch loft operation failed`,e))}finally{for(let e of n)t.dispose(e)}}var OV=class{sketches;constructor(e){e.length===0&&M(`CompoundSketch`,`Cannot create CompoundSketch with an empty array of sketches`),this.sketches=e}delete(){this.sketches.forEach(e=>{e.delete()})}get outerSketch(){return yD(this.sketches)}get innerSketches(){return this.sketches.slice(1)}get wires(){return HV(this)}face(){return VV(this)}extrude(e,t={}){return UV(this,e,t)}revolve(e,t={}){return WV(this,e,t)}loftWith(e,t){return GV(this,e,t)}};function kV(e){let t={};e.defaultOrigin&&(t.defaultOrigin=e.defaultOrigin),e.defaultDirection&&(t.defaultDirection=e.defaultDirection);let n=new KV(e.wire,t);return e.baseFace&&(n.baseFace=e.baseFace),n}function AV(e){return new OV(e.map(kV))}function jV(e){let t;return t=e.baseFace?ID(e.baseFace,e.wire):j(PD(e.wire)),t}function MV(e){return ZC(j(ET(e.wire.wrapped)))}function NV(e,t,{origin:n}={}){let r=j(PD(e.wire)),i=j(HN(r,n?Kw(n):e.defaultOrigin,t?Kw(t):[0,0,1]));return r.delete(),e.delete(),i}function PV(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=Qw(aT(n?Kw(n):e.defaultDirection),t),s=a?Kw(a):e.defaultOrigin;if(r&&!i){let t=j(FN(e.wire,[...s],[...o],r));return e.delete(),t}if(i){let t=j(IN(e.wire,i,[...s],[...o],r));return e.delete(),t}let c=j(VN(j(PD(e.wire)),[...o]));return e.delete(),c}function FV(e,t,n={}){let r=BE(e.wire),i=aT(Qw(UE(e.wire,1e-9),-1)),a=e.defaultDirection,o=Qw(tT(i,a),-1),s=t(pT([...r],[...o],[...i]),[...r]),c;if(`sketches`in s&&Array.isArray(s.sketches)){let e=s.sketches;c=e[0];for(let t=1;t<e.length;t++)e[t]?.delete()}else c=s;let l={forceProfileSpineOthogonality:!0,...n};e.baseFace&&(l.support=e.baseFace.wrapped);let u=j(NN(c.wire,e.wire,l));return e.delete(),u}function IV(e,t,n={},r=!1){let i=Array.isArray(t)?[e,...t]:[e,t],a=j(EV(i.map(e=>e.wire),n,r));return i.forEach(e=>{e.delete()}),a}var LV=e=>{let t=e.map(e=>e.wrapped),n=j(DT(U().fillSurface(t)));return ow(n)||M(`guessFaceFromWires`,`Failed to create a face`),n},RV=(e,t)=>ZC(U().fixWireOnFace(e.wrapped,t.wrapped,1e-9)),zV=e=>{let t,n,r=PD(yD(e));return ua(r)?(t=r.value,n=e.slice(1)):(t=LV(e),n=e.slice(1).map(e=>RV(e,t))),RD(t,n)},BV=(e,t)=>{let n=[],r=[],i=[];e.forEach(e=>{let[a,o,s]=j(t(e));n.push(a),r.push(o),i.push(s)});let a=zV(r),o=zV(i);return j(gO([a,...n,o]))};function VV(e){return RD(e.outerSketch.face(),e.innerSketches.map(e=>e.wire))}function HV(e){return hO(e.sketches.map(e=>e.wire))}function UV(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=Qw(aT(n?Kw(n):e.outerSketch.defaultDirection),t);return r&&!i?BV(e.sketches,t=>FN(t.wire,a?Kw(a):e.outerSketch.defaultOrigin,o,r,!0)):i?BV(e.sketches,t=>IN(t.wire,i,a?Kw(a):e.outerSketch.defaultOrigin,o,r,!0)):j(VN(VV(e),o))}function WV(e,t,{origin:n}={}){let r=n?Kw(n):e.outerSketch.defaultOrigin,i=t?Kw(t):[0,0,1];return j(HN(VV(e),r,i))}function GV(e,t,n){e.sketches.length!==t.sketches.length&&M(`CompoundSketch.loftWith`,`You need to loft with another compound with the same number of sketches`);let r=e.sketches.map((e,r)=>{let i=vD(t.sketches,r),a={};return n.ruled!==void 0&&(a.ruled=n.ruled),e.clone().loftWith(i.clone(),a,!0)}),i=QC(j(ET(VV(e).wrapped)));return r.push(i,VV(t)),j(gO(r))}var KV=class e{wire;_defaultOrigin;_defaultDirection;_baseFace;constructor(e,{defaultOrigin:t=[0,0,0],defaultDirection:n=[0,0,1]}={}){this.wire=e,this._defaultOrigin=Kw(t),this._defaultDirection=Kw(n),this.baseFace=null}get baseFace(){return this._baseFace}set baseFace(e){this._baseFace&&this._baseFace.delete(),this._baseFace=e&&QC(j(ET(e.wrapped)))}delete(){this.wire.delete(),this.baseFace&&this.baseFace.delete()}clone(){let t=new e(ZC(j(ET(this.wire.wrapped))),{defaultOrigin:this.defaultOrigin,defaultDirection:this.defaultDirection});return this.baseFace&&(t.baseFace=QC(j(ET(this.baseFace.wrapped)))),t}get defaultOrigin(){return this._defaultOrigin}set defaultOrigin(e){this._defaultOrigin=Kw(e)}get defaultDirection(){return this._defaultDirection}set defaultDirection(e){this._defaultDirection=Kw(e)}face(){return jV(this)}wires(){return MV(this)}faces(){return this.face()}revolve(e,t={}){return NV(this,e,t)}extrude(e,t={}){return PV(this,e,t)}sweepSketch(e,t={}){return FV(this,e,t)}loftWith(e,t={},n=!1){return IV(this,e,t,n)}},qV=class{sketches;constructor(e){this.sketches=e}wires(){return hO(this.sketches.map(e=>e instanceof KV?e.wire:e.wires))}faces(){return hO(this.sketches.map(e=>e.face()))}extrude(e,t={}){return hO(this.sketches.map(n=>n.extrude(e,t)))}revolve(e,t){return hO(this.sketches.map(n=>n.revolve(e,t)))}},JV={};async function YV(e,t=`default`,n=!1){if(!n&&JV[t])return O(JV[t]);let r;if(typeof e==`string`){let t;try{t=await fetch(e)}catch(t){return k(Ua(N.FONT_FETCH_FAILED,`Failed to fetch font from ${e}: ${t instanceof Error?t.message:String(t)}`,t))}if(!t.ok)return k(Ua(N.FONT_FETCH_FAILED,`Failed to fetch font from ${e}: HTTP ${t.status} ${t.statusText}`));r=await t.arrayBuffer()}else r=e;let i;try{i=TV.parse(r)}catch(e){return k(Ua(N.FONT_PARSE_FAILED,`Failed to parse font data: ${e instanceof Error?e.message:String(e)}`,e))}let a=i;return JV[t]=a,JV.default||=a,O(a)}var XV=(e=`default`)=>JV[e],ZV=function*(e){let t=null,n=null;for(let r of e){if(r.type===`Z`){t&&(yield t.close()),t=null;continue}let e=[-r.x,r.y];if(r.type===`M`){t&&(yield t.done()),t=new LM,t.movePointerTo(e),n=e;continue}n&&Math.abs(e[0]-n[0])<1e-9&&Math.abs(e[1]-n[1])<1e-9||(r.type===`L`&&t?.lineTo(e),r.type===`C`&&t?.cubicBezierCurveTo(e,[-r.x1,r.y1],[-r.x2,r.y2]),r.type===`Q`&&t?.quadraticBezierCurveTo(e,[-r.x1,r.y1]),n=e)}};function QV(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:i=`default`}={}){let a=XV(i);a||=XV(),a||M(`text`,`No fonts loaded. Call loadFont() before using text functions.`);let o=a.getPath(e,-t,-n,r);return EM(Array.from(ZV(o.commands))).mirror([0,0])}var $V={XY:{dir:[0,0,1],xAxis:[1,0,0]},XZ:{dir:[0,-1,0],xAxis:[1,0,0]},YZ:{dir:[1,0,0],xAxis:[0,1,0]},YX:{dir:[0,0,-1],xAxis:[0,1,0]},ZX:{dir:[0,1,0],xAxis:[0,0,1]},ZY:{dir:[-1,0,0],xAxis:[0,0,1]},front:{dir:[0,-1,0],xAxis:[1,0,0]},back:{dir:[0,1,0],xAxis:[-1,0,0]},right:{dir:[-1,0,0],xAxis:[0,-1,0]},left:{dir:[1,0,0],xAxis:[0,1,0]},bottom:{dir:[0,0,1],xAxis:[1,0,0]},top:{dir:[0,0,-1],xAxis:[1,0,0]}};function eH(e){return typeof e==`string`&&e in $V}var tH=e=>e.IsNull()?[]:ww(W(e));function nH(e,t,n=!0){let r=U().projectEdges(e.wrapped,[...t.position],[...t.direction],[...t.xAxis]);return{visible:[...tH(r.visible.sharp),...tH(r.visible.smooth),...tH(r.visible.outline)],hidden:n?[...tH(r.hidden.sharp),...tH(r.hidden.smooth),...tH(r.hidden.outline)]:[]}}function rH(e=[0,0,0],t=[0,0,1],n){if(nT(t)<1e-12)return k(F(`CAMERA_ZERO_DIRECTION`,`Camera direction cannot be a zero-length vector`));let r;if(n)r=aT(n);else{let e=tT([0,0,1],t);nT(e)<1e-12&&(e=tT([0,1,0],t)),nT(e)<1e-12&&(e=tT([1,0,0],t)),r=aT(e)}let i=aT(tT(t,r));return O({position:e,direction:aT(t),xAxis:r,yAxis:i})}function iH(e,t){let n=aT(Zw(e.position,t));return rH(e.position,n)}function aH(e){let t=$V[e];return rH([0,0,0],t.dir,t.xAxis)}function oH(e,t,n=!0){return nH(e,t,n)}var sH=(e,n=1e-7)=>{let r=new oM(e.length);e.forEach(e=>{let[t,i]=e.firstPoint;r.add(t-n,i-n,t+n,i+n)}),r.finish();let i=[],a=new Set;return e.forEach((o,s)=>{if(a.has(s))return;let c=[o],l=s;a.add(s);let u=e.length;for(;;){u--<0&&M(`stitchCurves`,`Infinite loop detected`);let[o,s]=t(c,c.length-1).lastPoint,d=r.search(o-n,s-n,o+n,s+n),f=t=>Math.abs((l-t)%e.length),p=d.filter(e=>!a.has(e)).map(n=>[t(e,n),n,f(n)]).sort(([,,e],[,,t])=>e-t);if(p.length===0){i.push(c);break}let[m,h]=t(p,0);c.push(m),a.add(h),l=h}}),i},cH=class extends IM{plane;constructor(e,t){super(),this.plane=e&&typeof e!=`string`?{...e}:j(gT(e??`XY`,t))}delete(){this.pendingCurves=[]}sagittaArcTo(e,t){return super.sagittaArcTo(e,-t)}buildWire(){try{var e=lC();this.pendingCurves.length||M(`Sketcher.buildWire`,`No lines to convert into a wire`);let t=e.u(new xC);return j(ND(Uj(this.pendingCurves,this.plane).map(e=>t.register(e))))}catch(t){e.e=t}finally{e.d()}}done(){return new KV(this.buildWire(),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}close(){return this._closeSketch(),this.done()}closeWithMirror(){GA(this.pointer,this.firstPoint)&&M(`Sketcher.closeWithMirror`,`Cannot close with a mirror when the sketch is already closed`);let e=this.buildWire(),t=vT(this.plane,this.pointer),n=tT(aT(Zw(t,vT(this.plane,this.firstPoint))),this.plane.zDir),r=j(ET(e.wrapped));return new KV(j(ND([e,ZC(j(ET(U().mirror(r,Kw(t),Kw(n)))))])),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}closeWithCustomCorner(e,t=`fillet`){return this._closeSketch(),this._customCornerLastWithFirst(e,t),this.done()}},lH=class extends IM{face;_bounds;constructor(e,t=[0,0]){super(t),this.face=QC(j(ET(e.wrapped))),this._bounds=FT(e)}_convertToUV([e,t]){let{uMin:n,uMax:r,vMin:i,vMax:a}=this._bounds;return[n+e*(r-n),i+t*(a-i)]}_convertFromUV([e,t]){let{uMin:n,uMax:r,vMin:i,vMax:a}=this._bounds;return[(e-n)/(r-n),(t-i)/(a-i)]}_adaptSurface(){return U().extractSurfaceFromFace(this.face.wrapped)}buildWire(){let e=U(),t=this._adaptSurface(),n=j(ND(this.pendingCurves.map(n=>XC(e.buildEdgeOnSurface(n.wrapped,t)))));return e.buildCurves3d(n.wrapped),n}done(){try{var e=lC();let t=e.u(new xC),n=this.buildWire(),r=new KV(n);if(GE(n)){let e=t.register(r.clone().face()),n=IT(e,.5,.5),i=Qw(zT(e),-1);r.defaultOrigin=[n[0],n[1],n[2]],r.defaultDirection=[i[0],i[1],i[2]]}else{let e=BE(n),t=zT(this.face,[e[0],e[1],e[2]]);r.defaultOrigin=[e[0],e[1],e[2]],r.defaultDirection=[t[0],t[1],t[2]]}return r.baseFace=this.face,r}catch(t){e.e=t}finally{e.d()}}close(){return this._closeSketch(),this.done()}closeWithMirror(){return this._closeWithMirror(),this.close()}closeWithCustomCorner(e,t=`fillet`){return this._closeSketch(),this._customCornerLastWithFirst(e,t),this.done()}},uH=(e,t={})=>{let n=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(gT(t.plane??`XY`,t.origin));return new KV(j(ND([wD(e,n.origin,n.zDir)])),{defaultOrigin:[...n.origin],defaultDirection:[...n.zDir]})},dH=(e=1,t=2,n={})=>{let r=n.plane&&typeof n.plane!=`string`?{...n.plane}:j(gT(n.plane??`XY`,n.origin)),i=r.xDir,a=e,o=t;return t>e&&(i=uT(i,r.zDir,90*Ww),a=t,o=e),new KV(j(ND([j(TD(a,o,r.origin,r.zDir,i))])),{defaultOrigin:[...r.origin],defaultDirection:[...r.zDir]})},fH=(e,t,n={})=>(n.plane&&typeof n.plane!=`string`?new cH(n.plane):new cH(n.plane,n.origin)).movePointerTo([-e/2,-t/2]).hLine(e).vLine(t).hLine(-e).vLine(-t).done(),pH=(e,t,n=0,r={})=>{let i=WM(e,t,n).sketchOnPlane(r.plane,r.origin),a={};return i.defaultOrigin&&(a.defaultOrigin=i.defaultOrigin),i.defaultDirection&&(a.defaultDirection=i.defaultDirection),new KV(i.wire,a)},mH=(e,t,n=0,r={})=>{let i=[...Array(t).keys()].map(n=>{let r=-(Math.PI*2/t)*n;return[e*Math.sin(r),e*Math.cos(r)]}),a=r.plane&&typeof r.plane!=`string`?new cH(r.plane):new cH(r.plane,r.origin),o=bD(i),s=a.movePointerTo([vD(o,0),vD(o,1)]);return n?i.forEach(e=>s.sagittaArcTo([vD(e,0),vD(e,1)],n)):i.forEach(e=>s.lineTo([vD(e,0),vD(e,1)])),s.done()},hH=(e,t,n=0)=>{let r=Math.PI/t,i=Math.cos(r)*e;return n>=0?i:i+n},gH=(e,t)=>{let n=[...BT(e)],r=[...zT(e)];return new KV(j(QE(HT(e),t)),{defaultOrigin:n,defaultDirection:r})},_H=(e,t={},{pointsCount:n=400,start:r=0,stop:i=1}={},a={})=>{try{var o=lC();let s=o.u(new xC),c=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(gT(t.plane??`XY`,t.origin)),l=(i-r)/n,u=[...Array(n+1).keys()].map(t=>vT(c,e(r+t*l)));return new KV(j(ND([s.register(j(kD(u,a)))])),{defaultOrigin:[...c.origin],defaultDirection:[...c.zDir]})}catch(e){o.e=e}finally{o.d()}},vH=(e,t,n,r=[0,0,0],i=[0,0,1],a=!1)=>new KV(j(ND([ED(e,t,n,Kw(r),Kw(i),a)]))),yH=(e,t,n)=>new cH().movePointerTo([-e/2,t/2]).hLine(e).vLine(-t).hLine(-e).close().extrude(n),bH=(e,t)=>GA(e,t,UA*100),xH=(e,t,n,r)=>{let i=e[0]-t[0],a=e[1]-t[1],o=n[0]-r[0],s=n[1]-r[1],c=i*s-a*o;if(Math.abs(c)<1e-12)return null;let l=e[0]*t[1]-e[1]*t[0],u=n[0]*r[1]-n[1]*r[0];return[(l*o-u*i)/c,(l*s-u*a)/c]};function SH(e,t,n,r,i){let a=Bj(t,n,r.original.lastPoint);e(r),e(a)}function CH(e,t,n,r,i){let a=Mj(t,n);e(r),e(a)}function wH(e,t,n,r,i){let a=xH(r.offset instanceof Oj?qA(t,r.offset.tangentAt(1)):r.offset.firstPoint,t,n,i.offset instanceof Oj?KA(n,i.offset.tangentAt(0)):i.offset.lastPoint);if(!a){let i=Mj(t,n);e(r),e(i);return}let o=XA([(t[0]+n[0])/2,(t[1]+n[1])/2],a),s=XA(t,n);if(s<1e-18||o>16*s){let i=Mj(t,n);e(r),e(i);return}let c=Mj(t,a),l=Mj(a,n);e(r),e(c),e(l)}var TH={round:SH,bevel:CH,miter:wH};function EH(e,t,n){let r=n.length===1?Ka(n,0,`rawOffsets`):DH(n,e.original.lastPoint),i=Ka(e.offset.splitAt([r],UA),0,`rawOffsets`),a=t.offset.splitAt([r],UA).at(-1);return a||M(`offset.rawOffsets`,`Split produced no trailing curve segment`),{splitPrevious:{offset:i,original:e.original},splitCurrent:{offset:a,original:t.original}}}function DH(e,t){let n=Ka(e,0,`selectClosestIntersection`),r=XA(n,t);for(let i=1;i<e.length;i++){let a=Ka(e,i,`selectClosestIntersection`),o=XA(a,t);o<r&&(r=o,n=a)}return n}function OH(e){let t=new Map,n=(e,n)=>{let r=t.get(e)||[];t.set(e,[...r,...n])},r=new oM(e.length);for(let t of e){let[[e,n],[i,a]]=t.boundingBox.bounds;r.add(e,n,i,a)}return r.finish(),e.forEach((t,i)=>{let[[a,o],[s,c]]=t.boundingBox.bounds,l=r.search(a,o,s,c);for(let r of l){if(r<=i)continue;let a=Ka(e,r,`offsetBlueprint`),{intersections:o,commonSegmentsPoints:s}=j(dM(t,a,UA)),c=[...o,...s].filter(e=>{let n=bH(e,t.firstPoint)||bH(e,t.lastPoint),r=bH(e,a.firstPoint)||bH(e,a.lastPoint);return!(n&&r)});c.length&&(n(i,c),n(r,c))}}),t}function kH(e,t,n={}){let r=e.orientation===`clockwise`?-t:t,i=e.curves.map(e=>({offset:mM(e,r),original:e})),a=[],o=null,s=i.at(-1);if(!s)return[];function c(e){if(e instanceof Oj){a.push(e);return}o?e.offset instanceof Oj?a.push(e.offset):bH(e.offset.firstPoint,e.offset.lastPoint)||a.push(Mj(e.offset.firstPoint,e.offset.lastPoint)):o=e}let l=function*(){for(let e of i.slice(0,-1))yield e;o||M(`offset.rawOffsets`,`No saved curve after iterating offset segments`),yield o};for(let e of l()){let t=s.offset.lastPoint,r=e.offset.firstPoint;if(bH(t,r)){c(s),s=e;continue}let i=[];if(s.offset instanceof Oj&&e.offset instanceof Oj){let{intersections:t,commonSegmentsPoints:n}=j(dM(s.offset,e.offset,UA/100));i=[...t,...n]}if(i.length>0){let{splitPrevious:t,splitCurrent:n}=EH(s,e,i);c(t),s=n;continue}let a=TH[n.lineJoinType??`round`];a(c,t,r,s,e),s=e}return c(s),a}function AH(e,n,r={}){let i=kH(e,n,r);if(i.length<2)return null;let a=OH(i);if(!a.size){let t=new nM(i);return e.intersects(t)?null:t}let o=i.flatMap((e,t)=>{if(!a.has(t))return e;let n=a.get(t)||[];return e.splitAt(n,UA*100)}),s=new oM(e.curves.length);for(let t of e.curves){let[[e,n],[r,i]]=t.boundingBox.bounds;s.add(e,n,r,i)}s.finish();let c=Math.abs(n),l=o.filter(n=>{let[[r,i],[a,o]]=n.boundingBox.bounds;return!s.search(r-c,i-c,a+c,o+c).some(r=>t(e.curves,r).distanceFrom(n)<c-UA)});if(!l.length)return null;let u=sH(l).filter(e=>e.length>1).map(e=>new nM(e)).filter(e=>e.isClosed());return u.length?u.length===1?Ka(u,0,`offsetBlueprint`):new yM(u):null}var jH=e=>{let t=Ka(e,0,`fuseAll`);for(let n=1;n<e.length;n++)t=EN(t,Ka(e,n,`fuseAll`));return t};function MH(e,t,n={}){if(e instanceof nM)return AH(e,t,n);if(e instanceof yM)return jH(e.blueprints.map(e=>MH(e,t,n)));if(e instanceof bM){let r=jH(e.blueprints.slice(1).map(e=>MH(e,-t,n)));return ON(MH(Ka(e.blueprints,0,`offset`),t,n),r)}return null}function NH(e,t){return e instanceof nM?new nM(jj(e.curves,t)):e instanceof bM?new bM(e.blueprints.map(e=>NH(e,t))):e instanceof yM?new yM(e.blueprints.map(e=>NH(e,t))):e}function PH(e,t,n,r){let i=()=>!0;r&&(i=r.shouldKeep.bind(r));let a=[yD(t.curves)],o=(t,r)=>{i({firstCurve:t,secondCurve:r,point:t.lastPoint})?a.push(...e(t,r,n)):a.push(t,r)};t.curves.slice(1).forEach(e=>{let t=a.pop();t||M(`customCorners.modifyCorners`,`Unexpected empty curve stack during filleting`),o(t,e)});let s=a.at(-1);if(s||M(`customCorners.modifyCorners`,`Unexpected empty curve list during corner modification`),GA(yD(a).firstPoint,s.lastPoint)&&a.length>1){let e=a.pop(),t=a.shift();(!e||!t)&&M(`customCorners.modifyCorners`,`Unexpected empty curve stack during close-and-fillet`),o(e,t)}return new nM(a)}function FH(e,t,n,r){return t instanceof nM?PH(e,t,n,r):t instanceof bM?new bM(t.blueprints.map(t=>PH(e,t,n,r))):t instanceof yM?new yM(t.blueprints.map(t=>FH(e,t,n,r)).filter(e=>e!==null)):null}function IH(e,t,n){return FH(gM,e,t,n)}function LH(e,t,n){return FH(_M,e,t,n)}function RH(e,t){return e instanceof nM?kV(t):e instanceof bM?AV(t):new qV(t.map(e=>Array.isArray(e)?AV(e):kV(e)))}var zH=class e{innerShape;constructor(e=null){this.innerShape=e}clone(){return new e(this.innerShape?.clone()||null)}serialize(){if(!this.innerShape)return JSON.stringify({type:`Empty`});function e(t){if(t instanceof bM)return{type:`CompoundBlueprint`,blueprints:t.blueprints.map(e)};if(t instanceof yM)return{type:`Blueprints`,blueprints:t.blueprints.map(e)};if(t instanceof nM)return{type:`Blueprint`,curves:t.curves.map(e=>e.serialize())};M(`Drawing.serialize`,`Unknown shape type for serialization`)}return JSON.stringify(e(this.innerShape))}get boundingBox(){return this.innerShape?this.innerShape.boundingBox:new Ej}stretch(t,n,r){return this.innerShape?new e(this.innerShape.stretch(t,n,r)):new e}get repr(){return this.innerShape===null?`=== empty shape`:this.innerShape.repr}rotate(t,n){return this.innerShape?new e(this.innerShape.rotate(t,n)):new e}translate(t,n=0){return this.innerShape?new e(typeof t==`number`?this.innerShape.translate(t,n):this.innerShape.translate(t)):new e}scale(t,n){return this.innerShape?new e(this.innerShape.scale(t,n)):new e}mirror(t,n,r){return this.innerShape?new e(this.innerShape.mirror(t,n,r)):new e}cut(t){return new e(ON(this.innerShape,t.innerShape))}fuse(t){return new e(EN(this.innerShape,t.innerShape))}intersect(t){return new e(kN(this.innerShape,t.innerShape))}fillet(t,n){let r=n&&n(HM());return new e(IH(this.innerShape,t,r))}chamfer(t,n){let r=n&&n(HM());return new e(LH(this.innerShape,t,r))}sketchOnPlane(e,t){this.innerShape||M(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnPlane(e,t);return RH(this.innerShape,n)}sketchOnFace(e,t){this.innerShape||M(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnFace(e,t);return RH(this.innerShape,n)}punchHole(e,t,n={}){return this.innerShape?this.innerShape.punchHole(e,t,n):e}toSVG(e){return this.innerShape?.toSVG(e)||``}toSVGViewBox(e=1){return this.innerShape?.toSVGViewBox(e)||``}toSVGPaths(){return this.innerShape?.toSVGPaths()||[]}offset(t,n={}){return new e(MH(this.innerShape,t,n))}approximate(t,n={}){return t!==`svg`&&M(`Drawing.approximate`,`Only 'svg' is supported for now`),new e(NH(this.innerShape,n))}get blueprint(){if(!(this.innerShape instanceof nM)){if(this.innerShape instanceof yM&&this.innerShape.blueprints.length===1&&this.innerShape.blueprints[0]instanceof nM)return this.innerShape.blueprints[0];M(`Drawing.blueprint`,`This drawing is not a blueprint`)}return this.innerShape}};function BH(e){function t(e){if(e.type===`CompoundBlueprint`)return new bM(e.blueprints.map(t));if(e.type===`Blueprints`)return new yM(e.blueprints.map(t));if(e.type===`Blueprint`)return new nM(e.curves.map(e=>Dj(e)));M(`Drawing.deserialize`,`Unknown shape type for deserialization`)}return new zH(t(JSON.parse(e)))}var VH=class extends IM{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new zH(new nM(this.pendingCurves))}close(){return this._closeSketch(),this.done()}closeWithMirror(){return this._closeWithMirror(),this.close()}closeWithCustomCorner(e,t=`fillet`){return this._closeSketch(),this._customCornerLastWithFirst(e,t),this.done()}};function HH(e){let t=new VH;return e&&t.movePointerTo(e),t}function UH(e,t,n=0){return new zH(WM(e,t,n))}var WH=UH;function GH(e){return new zH(new nM([Fj(e)]))}function KH(e,t){let[n,r]=[e,t].sort((e,t)=>e-t);return new zH(new nM([Ij(r,n,r===e?[1,0]:[0,1])]))}function qH(e){return HH().movePointerTo([-e,0]).sagittaArc(2*e,0,e).sagittaArc(-2*e,0,e).close()}function JH(e,t){return HH().movePointerTo([-e,0]).halfEllipse(2*e,0,t).halfEllipse(-2*e,0,t).close()}function YH(e,t,n=0){return new zH(UM(e,t,n))}function XH(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:i=`default`}={}){return new zH(QV(e,{startX:t,startY:n,fontSize:r,fontFamily:i}))}var ZH=(e,t={},n={})=>{e.length<2&&M(`drawPointsInterpolation`,`Need at least 2 points for interpolation, got ${e.length}`);let r=[j(zj(e,t))],i=e[0],a=e[e.length-1];return n.closeShape&&i&&a&&!GA(i,a)&&r.push(Mj(a,i)),new zH(new nM(r))},QH=(e,{pointsCount:t=400,start:n=0,stop:r=1,closeShape:i=!1}={},a={})=>{let o=(r-n)/t;return ZH([...Array(t+1).keys()].map(t=>e(n+t*o)),a,{closeShape:i})},$H=e=>{try{var t=lC();let n=t.u(new xC),r=WH(1e3,1e3).sketchOnPlane(),i=n.register(j(PD(r.wire))),a=sH(e.map(e=>Qj(e,i))).map(e=>new nM(e));return a.length===0?new zH:a.length===1?new zH(a[0]):new zH(new yM(a))}catch(e){t.e=e}finally{t.d()}};function eU(e,t=`front`){let n;n=typeof t==`string`?j(aH(t)):t;let{visible:r,hidden:i}=oH(e,n);return{visible:$H(r),hidden:$H(i)}}function tU(e){try{var t=lC();let n=t.u(new xC),r=n.register(QC(j(ET(e.wrapped)))),i=sH(ww(n.register(HT(r))).map(t=>Qj(t,e))).map(e=>new nM(e));return i.length===0?new zH:i.length===1?new zH(i[0]):new zH(new yM(i))}catch(e){t.e=e}finally{t.d()}}function nU(e,t,n){return n===void 0?e.sketchOnPlane(t):e.sketchOnPlane(t,n)}function rU(e,t){return e.fuse(t)}function iU(e,t){return e.cut(t)}function aU(e,t){return e.intersect(t)}function oU(e,t,n){return e.fillet(t,n)}function sU(e,t,n){return e.chamfer(t,n)}function cU(e,t,n=0){return typeof t==`number`?e.translate(t,n):e.translate(t)}function lU(e,t,n){return e.rotate(t,n)}function uU(e,t,n){return e.scale(t,n)}function dU(e,t,n,r){return e.mirror(t,n,r)}function fU(e){let t=e.clone();return t.reverse(),t}function pU(e){return e.boundingBox}function mU(e){return e.firstPoint}function hU(e){return e.lastPoint}function gU(e,t,n){return e.splitAt(t,n)}function _U(e,t,n){return e.parameter(t,n)}function vU(e,t){return e.tangentAt(t)}function yU(e,t){return e.isOnCurve(t)}function bU(e,t){return e.distanceFrom(t)}function xU(e){return e.length===0?k(F(N.BLUEPRINT_EMPTY_CURVES,`createBlueprint: at least one curve is required`)):O(new nM(e))}function SU(e){return e.length===0?k(F(N.COMPOUND_BLUEPRINT_EMPTY,`createCompoundBlueprint: at least one blueprint (outer boundary) is required`)):O(new bM(e))}function CU(e){return e.boundingBox}function wU(e){return e.orientation}function TU(e,t){return e.isInside(t)}function EU(e){return e.toSVGPathD()}function DU(e,t,n){return e.translate(t,n)}function OU(e,t,n){return e.rotate(t,n)}function kU(e,t,n){return e.scale(t,n)}function AU(e,t,n,r){return e.mirror(t,n,r)}function jU(e,t,n,r){return e.stretch(t,n,r)}function MU(e,t,n){return e.sketchOnPlane(t,n)}function NU(e,t,n){return e.sketchOnFace(t,n)}function PU(e,t){return n(e,t*3)}function FU(e,t){return n(e,t)}function IU(e){let t=[`# brepjs OBJ export`],n=e.vertices.length/3;for(let r=0;r<n;r++){let[n,i,a]=PU(e.vertices,r);t.push(`v ${n} ${i} ${a}`)}let r=e.normals.length/3;for(let n=0;n<r;n++){let[r,i,a]=PU(e.normals,n);t.push(`vn ${r} ${i} ${a}`)}let i=n=>{let[r,i,a]=FU(e.triangles,n);t.push(`f ${r+1}//${r+1} ${i+1}//${i+1} ${a+1}//${a+1}`)};if(e.faceGroups.length>0)for(let n of e.faceGroups){t.push(`g face_${n.faceId}`);let e=n.count/3;for(let t=0;t<e;t++)i(n.start+t*3)}else{let t=e.triangles.length/3;for(let e=0;e<t;e++)i(e*3)}return t.join(`
|
|
22
22
|
`)+`
|
|
23
|
-
`}var
|
|
23
|
+
`}var LU=5126,RU=5125,zU=34962,BU=34963;function VU(e){let n=[1/0,1/0,1/0],r=[-1/0,-1/0,-1/0];for(let i=0;i<e.length;i+=3)for(let a=0;a<3;a++){let o=t(e,i+a);o<t(n,a)&&(n[a]=o),o>t(r,a)&&(r[a]=o)}return{min:n,max:r}}function HU(e){return e+3&-4}function UU(e){let t=new Uint8Array(e),n=8192,r=[];for(let e=0;e<t.length;e+=n)r.push(String.fromCharCode(...t.subarray(e,e+n)));return btoa(r.join(``))}function WU(e,t){let n=JU(e,`base64`,t);return JSON.stringify(n)}function GU(e,t){let{doc:n,binBuffer:r}=YU(e,t),i=JSON.stringify(n),a=new TextEncoder().encode(i),o=HU(a.length),s=new Uint8Array(o);s.set(a);for(let e=a.length;e<o;e++)s[e]=32;let c=HU(r.byteLength),l=new Uint8Array(c);l.set(new Uint8Array(r));let u=20+o+8+c,d=new ArrayBuffer(u),f=new DataView(d),p=new Uint8Array(d);f.setUint32(0,1179937895,!0),f.setUint32(4,2,!0),f.setUint32(8,u,!0),f.setUint32(12,o,!0),f.setUint32(16,1313821514,!0),p.set(s,20);let m=20+o;return f.setUint32(m,c,!0),f.setUint32(m+4,5130562,!0),p.set(l,m+8),d}function KU(e,t,n,r,i){return[{bufferView:0,componentType:RU,count:e.length,type:`SCALAR`},{bufferView:1,componentType:LU,count:t.length/3,type:`VEC3`,min:r,max:i},{bufferView:2,componentType:LU,count:n.length/3,type:`VEC3`}]}function qU(e,t,n){return[{buffer:0,byteOffset:0,byteLength:e,target:BU},{buffer:0,byteOffset:HU(e),byteLength:t,target:zU},{buffer:0,byteOffset:HU(e)+t,byteLength:n,target:zU}]}function JU(e,t,n){let{vertices:r,normals:i,triangles:a}=e,o=n?.materials;if(o&&o.size>0&&e.faceGroups.length>0)return tW(e,t,o);let s=a.byteLength,c=r.byteLength,l=i.byteLength,u=HU(s)+c+l,{min:d,max:f}=VU(r),p={asset:{version:`2.0`,generator:`brepjs`},scene:0,scenes:[{nodes:[0]}],nodes:[{mesh:0}],meshes:[{primitives:[{attributes:{POSITION:1,NORMAL:2},indices:0}]}],accessors:KU(a,r,i,d,f),bufferViews:qU(s,c,l),buffers:[{byteLength:u}]};if(t===`base64`){let t=rW(e);p.buffers[0]={byteLength:u,uri:`data:application/octet-stream;base64,`+UU(t)}}return p}function YU(e,t){let n=t?.materials;if(n&&n.size>0&&e.faceGroups.length>0){let{doc:t,binBuffer:r}=nW(e,n);return{doc:t,binBuffer:r}}return{doc:JU(e,`glb`),binBuffer:rW(e)}}function XU(e,n){let{vertices:r,normals:i,triangles:a,faceGroups:o}=e,s=[],c=new Map,l=new Map;for(let e of n.values()){if(l.has(e))continue;let t=JSON.stringify([e.baseColor,e.metallic,e.roughness,e.name]),n=c.get(t);if(n!==void 0)l.set(e,n);else{let n=s.length;c.set(t,n),l.set(e,n),s.push({name:e.name??`material_${n}`,pbrMetallicRoughness:{baseColorFactor:e.baseColor??[.8,.8,.8,1],metallicFactor:e.metallic??0,roughnessFactor:e.roughness??.5}})}}let u=new Map;for(let e=0;e<o.length;e++){let t=vD(o,e),r=n.get(t.faceId),i=r===void 0?-1:l.get(r)??-1,a=u.get(i);a?a.push(e):u.set(i,[e])}let d=[];for(let[e,n]of u){let r=0;for(let e of n)r+=vD(o,e).count;let i=new Uint32Array(r),s=0;for(let e of n){let n=vD(o,e);for(let e=n.start;e<n.start+n.count;e++)i[s++]=t(a,e)}d.push({indices:i,materialIdx:e})}let f=0,p=[];for(let e of d){let t=e.indices.byteLength;p.push({byteOffset:f,byteLength:t}),f=HU(f+t)}let m=f;return{primitiveData:d,indexBufferInfos:p,verticesOffset:m,totalByteLength:m+r.byteLength+i.byteLength,uniqueMaterials:s}}function ZU(e,t,n,r){let{vertices:i,normals:a}=e,{min:o,max:s}=VU(i),c=r.length;r.push({buffer:0,byteOffset:t,byteLength:i.byteLength,target:zU});let l=n.length;n.push({bufferView:c,componentType:LU,count:i.length/3,type:`VEC3`,min:o,max:s});let u=r.length;r.push({buffer:0,byteOffset:t+i.byteLength,byteLength:a.byteLength,target:zU});let d=n.length;return n.push({bufferView:u,componentType:LU,count:a.length/3,type:`VEC3`}),{verticesAccIdx:l,normalsAccIdx:d}}function QU(e,t,n,r,i,a){let o=[];for(let s=0;s<e.length;s++){let c=vD(e,s),l=vD(t,s),u=a.length;a.push({buffer:0,byteOffset:l.byteOffset,byteLength:l.byteLength,target:BU});let d=i.length;i.push({bufferView:u,componentType:RU,count:c.indices.length,type:`SCALAR`});let f={attributes:{POSITION:n,NORMAL:r},indices:d};c.materialIdx>=0&&(f.material=c.materialIdx),o.push(f)}return o}function $U(e,t){let{primitiveData:n,indexBufferInfos:r,verticesOffset:i,totalByteLength:a,uniqueMaterials:o}=t,s=[],c=[],{verticesAccIdx:l,normalsAccIdx:u}=ZU(e,i,s,c);return{asset:{version:`2.0`,generator:`brepjs`},scene:0,scenes:[{nodes:[0]}],nodes:[{mesh:0}],meshes:[{primitives:QU(n,r,l,u,s,c)}],accessors:s,bufferViews:c,buffers:[{byteLength:a}],materials:o}}function eW(e,t){let{vertices:n,normals:r}=e,{primitiveData:i,indexBufferInfos:a,verticesOffset:o,totalByteLength:s}=t,c=new ArrayBuffer(s),l=new Uint8Array(c);for(let e=0;e<i.length;e++){let t=vD(i,e),n=vD(a,e);l.set(new Uint8Array(t.indices.buffer,t.indices.byteOffset,t.indices.byteLength),n.byteOffset)}return l.set(new Uint8Array(n.buffer,n.byteOffset,n.byteLength),o),l.set(new Uint8Array(r.buffer,r.byteOffset,r.byteLength),o+n.byteLength),c}function tW(e,t,n){let r=XU(e,n),i=$U(e,r);if(t===`base64`){let t=eW(e,r);i.buffers[0]={byteLength:r.totalByteLength,uri:`data:application/octet-stream;base64,`+UU(t)}}return i}function nW(e,t){let n=XU(e,t);return{doc:$U(e,n),binBuffer:eW(e,n)}}function rW(e){let{vertices:t,normals:n,triangles:r}=e,i=r.byteLength,a=t.byteLength,o=n.byteLength,s=HU(i)+a+o,c=new ArrayBuffer(s),l=new Uint8Array(c);return l.set(new Uint8Array(r.buffer,r.byteOffset,i),0),l.set(new Uint8Array(t.buffer,t.byteOffset,a),HU(i)),l.set(new Uint8Array(n.buffer,n.byteOffset,o),HU(i)+a),c}function iW(e,t){let n=t?.layer??`0`,r=[];r.push(`0`,`SECTION`,`2`,`HEADER`),r.push(`9`,`$ACADVER`,`1`,`AC1009`),r.push(`0`,`ENDSEC`);let i=new Set([n]);for(let t of e)t.layer&&i.add(t.layer);r.push(`0`,`SECTION`,`2`,`TABLES`),r.push(`0`,`TABLE`,`2`,`LAYER`,`70`,String(i.size));for(let e of i)r.push(`0`,`LAYER`,`2`,e,`70`,`0`,`62`,`7`,`6`,`CONTINUOUS`);r.push(`0`,`ENDTAB`),r.push(`0`,`ENDSEC`),r.push(`0`,`SECTION`,`2`,`ENTITIES`);for(let t of e){let e=t.layer??n;if(t.type===`LINE`)r.push(`0`,`LINE`,`8`,e,`10`,String(t.start[0]),`20`,String(t.start[1]),`30`,`0`,`11`,String(t.end[0]),`21`,String(t.end[1]),`31`,`0`);else{r.push(`0`,`LWPOLYLINE`,`8`,e,`90`,String(t.points.length),`70`,t.closed?`1`:`0`);for(let e of t.points)r.push(`10`,String(e[0]),`20`,String(e[1]))}}return r.push(`0`,`ENDSEC`),r.push(`0`,`EOF`),r.join(`
|
|
24
24
|
`)+`
|
|
25
|
-
`}function
|
|
26
|
-
`);n.push(` <colorgroup id="2">\n${t}\n </colorgroup>`)}if(t.length>0){let e=t.map(e=>{let t=e.displayColor===void 0?`#FFFFFFFF`:
|
|
27
|
-
`);n.push(` <basematerials id="3">\n${e}\n </basematerials>`)}return n}function
|
|
25
|
+
`}function aW(e,t){let n=t?.curveSegments??32,r=[],i=oW(e);for(let e of i)for(let t of e.curves)r.push(...sW(t,n));return iW(r,t)}function oW(e){if(`curves`in e&&Array.isArray(e.curves))return[e];if(`blueprints`in e&&Array.isArray(e.blueprints)){let t=[];for(let n of e.blueprints)t.push(...oW(n));return t}return[]}function sW(e,t){return e.geomType===`LINE`?[{type:`LINE`,start:e.firstPoint,end:e.lastPoint}]:[cW(e,t)]}function cW(e,t){let n=e.firstParameter,r=e.lastParameter,i=[];for(let a=0;a<=t;a++){let o=n+(r-n)*(a/t);i.push(e.value(o))}return{type:`POLYLINE`,points:i}}var lW=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)t=t&1?3988292384^t>>>1:t>>>1;lW[e]=t}function uW(e){let t=4294967295;for(let n of e)t=lW[(t^n)&255]^t>>>8;return(t^4294967295)>>>0}function dW(e,t,n,r){return e.setUint32(n,67324752,!0),n+=4,e.setUint16(n,20,!0),n+=2,e.setUint16(n,0,!0),n+=2,e.setUint16(n,0,!0),n+=2,e.setUint16(n,0,!0),n+=2,e.setUint16(n,0,!0),n+=2,e.setUint32(n,r.crc,!0),n+=4,e.setUint32(n,r.data.length,!0),n+=4,e.setUint32(n,r.data.length,!0),n+=4,e.setUint16(n,r.name.length,!0),n+=2,e.setUint16(n,0,!0),n+=2,t.set(r.name,n),n+=r.name.length,t.set(r.data,n),n+=r.data.length,n}function fW(e,t,n,r,i){return e.setUint32(n,33639248,!0),n+=4,e.setUint16(n,20,!0),n+=2,e.setUint16(n,20,!0),n+=2,e.setUint16(n,0,!0),n+=2,e.setUint16(n,0,!0),n+=2,e.setUint16(n,0,!0),n+=2,e.setUint16(n,0,!0),n+=2,e.setUint32(n,i.crc,!0),n+=4,e.setUint32(n,i.data.length,!0),n+=4,e.setUint32(n,i.data.length,!0),n+=4,e.setUint16(n,i.name.length,!0),n+=2,e.setUint16(n,0,!0),n+=2,e.setUint16(n,0,!0),n+=2,e.setUint16(n,0,!0),n+=2,e.setUint16(n,0,!0),n+=2,e.setUint32(n,0,!0),n+=4,e.setUint32(n,r,!0),n+=4,t.set(i.name,n),n+=i.name.length,n}function pW(e,t,n,r,i){e.setUint32(t,101010256,!0),t+=4,e.setUint16(t,0,!0),t+=2,e.setUint16(t,0,!0),t+=2,e.setUint16(t,n,!0),t+=2,e.setUint16(t,n,!0),t+=2,e.setUint32(t,i,!0),t+=4,e.setUint32(t,r,!0),t+=4,e.setUint16(t,0,!0)}function mW(e){let t=0,n=[];for(let r of e)n.push({offset:t,entry:r}),t+=30+r.name.length+r.data.length;let r=t,i=0;for(let t of e)i+=46+t.name.length;let a=t+i+22,o=new ArrayBuffer(a),s=new DataView(o),c=new Uint8Array(o),l=0;for(let{entry:e}of n)l=dW(s,c,l,e);for(let{offset:e,entry:t}of n)l=fW(s,c,l,e,t);return pW(s,l,e.length,r,i),o}function hW(e){return e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`)}function gW(e){let t=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,`0`).toUpperCase();return`#${t(e[0])}${t(e[1])}${t(e[2])}${t(e[3])}`}function _W(e){let t=[];for(let n=0;n<e.vertices.length;n+=3){let r=e.vertices[n]??0,i=e.vertices[n+1]??0,a=e.vertices[n+2]??0;t.push(` <vertex x="${r}" y="${i}" z="${a}" />`)}return t}function vW(e){let t=new Map,n=[];if(e!==void 0&&e.size>0)for(let r of e.values()){let e=gW(r);t.has(e)||(t.set(e,n.length),n.push(e))}return{colorIndexByHex:t,colorHexList:n}}function yW(e){let t=new Map,n=[];if(e!==void 0&&e.size>0)for(let r of e.values())t.has(r.name)||(t.set(r.name,n.length),n.push(r));return{materialIndexByName:t,materialList:n}}function bW(e,t,n,r,i){let a=new Map;for(let o of e.faceGroups){let e=o.start/3,s=o.count/3,c=o.faceId,l;if(n!==void 0){let e=n.get(c);if(e!==void 0){let t=i.get(e.name);t!==void 0&&(l={pid:3,p1:t})}}if(l===void 0&&t!==void 0){let e=t.get(c);if(e!==void 0){let t=gW(e),n=r.get(t);n!==void 0&&(l={pid:2,p1:n})}}if(l!==void 0)for(let t=e;t<e+s;t++)a.set(t,l)}return a}function xW(e,t){let n=[];for(let r=0;r<e.triangles.length;r+=3){let i=r/3,a=e.triangles[r]??0,o=e.triangles[r+1]??0,s=e.triangles[r+2]??0,c=t.get(i);c===void 0?n.push(` <triangle v1="${a}" v2="${o}" v3="${s}" />`):n.push(` <triangle v1="${a}" v2="${o}" v3="${s}" pid="${c.pid}" p1="${c.p1}" />`)}return n}function SW(e,t){let n=[];if(e.length>0){let t=e.map(e=>` <color color="${e}" />`).join(`
|
|
26
|
+
`);n.push(` <colorgroup id="2">\n${t}\n </colorgroup>`)}if(t.length>0){let e=t.map(e=>{let t=e.displayColor===void 0?`#FFFFFFFF`:gW(e.displayColor);return` <base name="${hW(e.name)}" displaycolor="${t}" />`}).join(`
|
|
27
|
+
`);n.push(` <basematerials id="3">\n${e}\n </basematerials>`)}return n}function CW(e,t,n,r,i){let a=_W(e),{colorIndexByHex:o,colorHexList:s}=vW(r),{materialIndexByName:c,materialList:l}=yW(i),u=xW(e,bW(e,r,i,o,c)),d=SW(s,l);return`<?xml version="1.0" encoding="UTF-8"?>
|
|
28
28
|
<model unit="${n}" xmlns="http://schemas.microsoft.com/3dmanufacturing/core/2015/02"${l.length>0?`
|
|
29
29
|
xmlns:m="http://schemas.microsoft.com/3dmanufacturing/material/2015/02"`:``}>
|
|
30
30
|
<resources>${d.length>0?`
|
|
31
31
|
`+d.join(`
|
|
32
32
|
`):``}
|
|
33
|
-
<object id="1" name="${
|
|
33
|
+
<object id="1" name="${hW(t)}" type="model">
|
|
34
34
|
<mesh>
|
|
35
35
|
<vertices>
|
|
36
36
|
${a.join(`
|
|
@@ -46,12 +46,12 @@ ${u.join(`
|
|
|
46
46
|
<build>
|
|
47
47
|
<item objectid="1" />
|
|
48
48
|
</build>
|
|
49
|
-
</model>`}function
|
|
49
|
+
</model>`}function wW(e,t={}){let{name:n=`model`,unit:r=`millimeter`,colors:i,materials:a}=t,o=new TextEncoder,s=CW(e,n,r,i,a);function c(e,t){let n=o.encode(e),r=o.encode(t);return{name:n,data:r,crc:uW(r)}}return mW([c(`[Content_Types].xml`,`<?xml version="1.0" encoding="UTF-8"?>
|
|
50
50
|
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
|
51
51
|
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
|
|
52
52
|
<Default Extension="model" ContentType="application/vnd.ms-package.3dmanufacturing-3dmodel+xml" />
|
|
53
53
|
</Types>`),c(`_rels/.rels`,`<?xml version="1.0" encoding="UTF-8"?>
|
|
54
54
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
55
55
|
<Relationship Target="/3D/3dmodel.model" Id="rel0" Type="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel" />
|
|
56
|
-
</Relationships>`),c(`3D/3dmodel.model`,s)])}function EW(e){let t=[],n=/([MmLlHhVvCcSsQqTtAaZz])([^MmLlHhVvCcSsQqTtAaZz]*)/g,r;for(;(r=n.exec(e))!==null;){let e=r[1]??``,n=(r[2]??``).trim(),i=[];if(n){let e=/[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/g,t;for(;(t=e.exec(n))!==null;)i.push(parseFloat(t[0]))}t.push({command:e,args:i})}return t}function DW(e){return[e[0],-e[1]]}function OW(e,t,n,r){let i=0;for(;i<e.length;){let a=(n?t.cx:0)+(e[i]??0),o=(n?t.cy:0)+(e[i+1]??0);i===0?(t.sx=a,t.sy=o):r.push(Nj(DW([t.cx,t.cy]),DW([a,o]))),t.cx=a,t.cy=o,i+=2}}function kW(e,t,n,r){let i=0;for(;i<e.length;){let a=(n?t.cx:0)+(e[i]??0),o=(n?t.cy:0)+(e[i+1]??0);r.push(Nj(DW([t.cx,t.cy]),DW([a,o]))),t.cx=a,t.cy=o,i+=2}}function AW(e,t,n,r){for(let i of e){let e=n?t.cx+i:i;r.push(Nj(DW([t.cx,t.cy]),DW([e,t.cy]))),t.cx=e}}function jW(e,t,n,r){for(let i of e){let e=n?t.cy+i:i;r.push(Nj(DW([t.cx,t.cy]),DW([t.cx,e]))),t.cy=e}}function MW(e,t,n,r){let i=0;for(;i+5<e.length;){let a=n?t.cx:0,o=n?t.cy:0,s=a+(e[i]??0),c=o+(e[i+1]??0),l=a+(e[i+2]??0),u=o+(e[i+3]??0),d=a+(e[i+4]??0),f=o+(e[i+5]??0);r.push(zj(DW([t.cx,t.cy]),[DW([s,c]),DW([l,u])],DW([d,f]))),t.prevControlX=l,t.prevControlY=u,t.cx=d,t.cy=f,i+=6}}function NW(e,t,n,r){let i=0;for(;i+3<e.length;){let a=n?t.cx:0,o=n?t.cy:0,s=t.lastCmd,c=s===`C`||s===`S`?2*t.cx-t.prevControlX:t.cx,l=s===`C`||s===`S`?2*t.cy-t.prevControlY:t.cy,u=a+(e[i]??0),d=o+(e[i+1]??0),f=a+(e[i+2]??0),p=o+(e[i+3]??0);r.push(zj(DW([t.cx,t.cy]),[DW([c,l]),DW([u,d])],DW([f,p]))),t.prevControlX=u,t.prevControlY=d,t.cx=f,t.cy=p,t.lastCmd=`S`,i+=4}}function PW(e,t,n,r){let i=0;for(;i+3<e.length;){let a=n?t.cx:0,o=n?t.cy:0,s=a+(e[i]??0),c=o+(e[i+1]??0),l=a+(e[i+2]??0),u=o+(e[i+3]??0);r.push(zj(DW([t.cx,t.cy]),[DW([s,c])],DW([l,u]))),t.prevControlX=s,t.prevControlY=c,t.cx=l,t.cy=u,i+=4}}function FW(e,t,n,r){let i=0;for(;i+1<e.length;){let a=n?t.cx:0,o=n?t.cy:0,s=t.lastCmd,c=s===`Q`||s===`T`?2*t.cx-t.prevControlX:t.cx,l=s===`Q`||s===`T`?2*t.cy-t.prevControlY:t.cy,u=a+(e[i]??0),d=o+(e[i+1]??0);r.push(zj(DW([t.cx,t.cy]),[DW([c,l])],DW([u,d]))),t.prevControlX=c,t.prevControlY=l,t.cx=u,t.cy=d,t.lastCmd=`T`,i+=2}}function IW(e,t,n,r,i){let a=Math.max(n,r),o=i?1:-1,s=t+2*o*a,c=[e-o*a,t+o*a],l=[e+o*a,t+o*a];try{return[Pj(DW([e,t]),DW(c),DW([e,s])),Pj(DW([e,s]),DW(l),DW([e,t]))]}catch{return[]}}function LW(e,t,n,r,i,a,o,s){let c=.5,l=e+c*(n-e),u=t+c*(r-t),d=n-e,f=r-t,p=Math.sqrt(d*d+f*f),m=Math.max(i,a),h=p/2,g=h<m?m-Math.sqrt(m*m-h*h):m,_=(o===s?-1:1)*(s?1:-1),v=-f/p,y=d/p,b=l+_*g*v,x=u+_*g*y;try{return[Pj(DW([e,t]),DW([b,x]),DW([n,r]))]}catch{return[Nj(DW([e,t]),DW([n,r]))]}}function RW(e,t,n,r){let i=0;for(;i+6<e.length;){let a=n?t.cx:0,o=n?t.cy:0,s=Math.abs(e[i]??0),c=Math.abs(e[i+1]??0),l=(e[i+3]??0)!==0,u=(e[i+4]??0)!==0,d=a+(e[i+5]??0),f=o+(e[i+6]??0);if(s===0||c===0)r.push(Nj(DW([t.cx,t.cy]),DW([d,f])));else{let e=d-t.cx,n=f-t.cy;Math.sqrt(e*e+n*n)<1e-10?r.push(...IW(t.cx,t.cy,s,c,u)):r.push(...LW(t.cx,t.cy,d,f,s,c,l,u))}t.cx=d,t.cy=f,i+=7}}function zW(e,t){(Math.abs(e.cx-e.sx)>1e-10||Math.abs(e.cy-e.sy)>1e-10)&&t.push(Nj(DW([e.cx,e.cy]),DW([e.sx,e.sy]))),e.cx=e.sx,e.cy=e.sy}function BW(e){let t=EW(e),n=[],r={cx:0,cy:0,sx:0,sy:0,prevControlX:0,prevControlY:0,lastCmd:``};for(let{command:e,args:i}of t){let t=e===e.toLowerCase(),a=e.toUpperCase();switch(a){case`M`:OW(i,r,t,n);break;case`L`:kW(i,r,t,n);break;case`H`:AW(i,r,t,n);break;case`V`:jW(i,r,t,n);break;case`C`:MW(i,r,t,n);break;case`S`:NW(i,r,t,n);break;case`Q`:PW(i,r,t,n);break;case`T`:FW(i,r,t,n);break;case`A`:RW(i,r,t,n);break;case`Z`:zW(r,n);break}a!==`S`&&a!==`T`&&(r.lastCmd=a)}return n}function VW(e){try{let t=BW(e);return t.length===0?k(Ua(`SVG_EMPTY_PATH`,`SVG path produced no curves`)):O(new rM(t))}catch(e){return k(Ua(`SVG_PARSE_FAILED`,`Failed to parse SVG path: ${e instanceof Error?e.message:String(e)}`))}}function HW(e){try{let t=/\bd\s*=\s*(?:"([^"]*)"|'([^']*)')/,n=[],r=e.toLowerCase(),i=0;for(;i<r.length;){let a=r.indexOf(`<path `,i);if(a===-1)break;let o=e.indexOf(`>`,a);if(o===-1)break;let s=e.slice(a,o+1);i=o+1;let c=t.exec(s),l=c?.[1]??c?.[2];if(!l)continue;let u=VW(l);u.ok&&n.push(u.value)}return n.length===0?k(Ua(`SVG_NO_PATHS`,`No <path> elements found in SVG`)):O(n)}catch(e){return k(Ua(`SVG_IMPORT_FAILED`,`Failed to import SVG: ${e instanceof Error?e.message:String(e)}`))}}function UW(e,t){try{let n=U(),r=e.map(e=>({shape:e.shape.wrapped,name:e.name,color:e.color?[...e.color]:void 0}));return O(n.exportSTEPConfigured(r,t))}catch(e){return k(Ua(N.STEP_EXPORT_CONFIGURED_FAILED,`Configured STEP export failed`,e))}}async function WW(e){try{let t=await e.arrayBuffer(),n=U().importSTEP(t);return n.length===0?k(Ua(`STEP_IMPORT_FAILED`,`STEP file contains no valid geometry`)):O(W(n[0]))}catch{return k(Ua(`STEP_IMPORT_FAILED`,`Failed to load STEP file`))}}async function GW(e){try{let t=await e.arrayBuffer(),n=U().importSTL(t);return n.IsNull()?k(Ua(`STL_IMPORT_FAILED`,`Failed to create solid from STL mesh`)):O(W(n))}catch{return k(Ua(`STL_IMPORT_FAILED`,`Failed to load STL file`))}}async function KW(e){try{let t=await e.arrayBuffer(),n=U().importIGES(t);return n.length===0?k(Ua(`IGES_IMPORT_FAILED`,`IGES file contains no valid geometry`)):O(W(n[0]))}catch{return k(Ua(`IGES_IMPORT_FAILED`,`Failed to load IGES file`))}}function qW(e,t,n={}){let r=$V(e,t);return new JV((typeof n.plane==`string`||n.plane===void 0?r.sketchOnPlane(n.plane,n.origin):r.sketchOnPlane(n.plane)).map(e=>Array.isArray(e)?new kV(e.map(AV)):AV(e)))}function JW(e,t){let n=t?.fontSize??1,r=ZV(t?.fontFamily);if(!r)return k(F(N.NO_FONT_LOADED,`No font loaded. Call loadFont() first.`,void 0,void 0,`Load a font with loadFont() before calling textMetrics()`));let i=r.getAdvanceWidth(e,n),a=n/r.unitsPerEm,o=r.ascender*a,s=r.descender*a;return O({width:i,height:o-s,ascender:o,descender:s})}function YW(e){let t=e?.fontSize??1,n=ZV(e?.fontFamily);if(!n)return k(F(N.NO_FONT_LOADED,`No font loaded. Call loadFont() first.`,void 0,void 0,`Load a font with loadFont() before calling fontMetrics()`));let r=t/n.unitsPerEm,i=n.ascender*r,a=n.descender*r,o=(n.tables?.os2?.sTypoLineGap??0)*r;return O({ascender:i,descender:a,unitsPerEm:n.unitsPerEm,lineHeight:i-a+o})}function XW(e,t){let n=0,r=NT(t);if(e.surfaceType!==void 0)if(r===e.surfaceType)n+=1;else return-1/0;if(e.normal!==void 0){let r=BT(t),i=e.normal[0]*r[0]+e.normal[1]*r[1]+e.normal[2]*r[2];if(i<.707)return-1/0;n+=i}if(e.centroid!==void 0){let r=VT(t),i=e.centroid[0]-r[0],a=e.centroid[1]-r[1],o=e.centroid[2]-r[2],s=i*i+a*a+o*o;if(s>100)return-1/0;n-=s/100}if(e.area!==void 0&&e.area>0){let r=IA(t);if(r.ok&&r.value>0){let t=Math.abs(Math.log(e.area/r.value));t>1&&(n-=t)}}return n}function ZW(e){let t=NT(e),n=BT(e),r=VT(e),i=IA(e);return{entityType:`face`,surfaceType:t,normal:n,centroid:r,area:i.ok?i.value:void 0}}var QW=.9;function $W(e){if(e[2]>QW)return`box:top`;if(e[2]<-.9)return`box:bottom`;if(e[1]>QW)return`box:back`;if(e[1]<-.9)return`box:front`;if(e[0]>QW)return`box:right`;if(e[0]<-.9)return`box:left`}function eG(e,t){let n=Ew(e),r=new Map;if(t===`box`){for(let e of n){let t=$W(BT(e));t!==void 0&&!r.has(t)&&r.set(t,FE(e))}return r}let i=0;for(let e of n)r.set(`${t}:face_${i}`,FE(e)),i++;return r}function tG(e,t,n){return{origin:e,role:t,hint:ZW(n)}}function nG(e,n,r){let i=e.get(n);if(!i)return e;let a=new Map;for(let[e,n]of i){if(r.deleted.has(n))continue;let i=r.modified.get(n);i&&i.length>0?a.set(e,t(i,0)):a.set(e,n)}let o=new Map;for(let[t,r]of e)t===n?o.set(t,a):o.set(t,r);return o}var rG=.1,iG=.5;function aG(e,t,n,r){let i=Ew(n),a=r??XW,o=t.get(e.origin)?.get(e.role);if(o!==void 0){for(let e of i)if(FE(e)===o)return{face:e,confidence:`exact`};return{ref:e,reason:`deleted`}}let s=-1/0,c,l=-1/0,u=[];for(let t of i){let n=a(e.hint,t);n>iG&&u.push([t,n]),n>s?(l=s,s=n,c=t):n>l&&(l=n)}return c!==void 0&&s>iG?s-l<rG&&u.length>1?{ref:e,reason:`ambiguous`,candidates:u.filter(([,e])=>e>=s-rG).map(([e])=>e)}:{face:c,confidence:`geometric-fallback`}:{ref:e,reason:`not-found`}}function oG(e){return e.type===`init`}function sG(e){return e.type===`operation`}function cG(e){return e.type===`dispose`}function lG(e){return e.success}function uG(e){return!e.success}function dG(){return{pending:new Map}}function fG(e,t){let n=new Map(e.pending);return n.set(t.id,t),{pending:n}}function pG(e,t){let n=e.pending.get(t);if(!n)return{queue:e,task:void 0};let r=new Map(e.pending);return r.delete(t),{queue:{pending:r},task:n}}function mG(e){return e.pending.size}function hG(e){return e.pending.size===0}function gG(e,t){for(let n of e.pending.values())n.reject(t);return{pending:new Map}}function _G(e,t){let n=t.data,r=e.get(n.id);if(r)if(e.delete(n.id),lG(n)){let e={};n.resultBrep!==void 0&&(e.resultBrep=n.resultBrep),n.resultData!==void 0&&(e.resultData=n.resultData),r.resolve(e)}else r.reject(Error(n.error))}function vG(e){let{worker:t,wasmUrl:n}=e,r=new Map,i=!1;function a(){return crypto.randomUUID()}function o(e){_G(r,e)}t.addEventListener(`message`,o);function s(e){return i?Promise.reject(Error(`WorkerClient has been disposed`)):new Promise((n,i)=>{r.set(e.id,{resolve:n,reject:i}),t.postMessage(e)})}return{async init(){await s({id:a(),type:`init`,...n===void 0?{}:{wasmUrl:n}})},async execute(e,t,n){return s({id:a(),type:`operation`,operation:e,shapesBrep:t,parameters:n})},dispose(){i=!0;for(let e of r.values())e.reject(Error(`WorkerClient disposed`));r.clear(),t.removeEventListener(`message`,o);let e={id:a(),type:`dispose`};t.postMessage(e)}}}function yG(){return{operations:new Map}}function bG(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function xG(e,t){let n=globalThis;n.onmessage=async r=>{let i=r.data;if(oG(i)){try{await t(i.wasmUrl);let e={id:i.id,success:!0};n.postMessage(e)}catch(e){let t={id:i.id,success:!1,error:e instanceof Error?e.message:String(e)};n.postMessage(t)}return}if(sG(i)){let t=e.operations.get(i.operation);if(!t){let e={id:i.id,success:!1,error:`Unknown operation: ${i.operation}`};n.postMessage(e);return}try{let e=t(i.shapesBrep,i.parameters),r={id:i.id,success:!0,...e.resultBrep===void 0?{}:{resultBrep:e.resultBrep},...e.resultData===void 0?{}:{resultData:e.resultData}};n.postMessage(r)}catch(e){let t={id:i.id,success:!1,error:e instanceof Error?e.message:String(e)};n.postMessage(t)}return}if(cG(i)){let e={id:i.id,success:!0};n.postMessage(e),n.close?.()}}}var SG=Object.defineProperty,CG=(e,t)=>{let n={};for(var r in e)SG(n,r,{get:e[r],enumerable:!0});return t||SG(n,Symbol.toStringTag,{value:`Module`}),n},wG=1,TG=2;function EG(e,t){t===`commonFace`&&e.SetGlue(wG),t===`sameFace`&&e.SetGlue(TG)}function DG(e){return typeof e==`number`}function OG(e){if(typeof e==`number`)return!0;if(typeof e==`object`&&e){let t=e;return`distances`in t&&Array.isArray(t.distances)&&`selectedFace`in t||`distance`in t&&`angle`in t&&`selectedFace`in t}return!1}function kG(e){return typeof e==`number`?!0:Array.isArray(e)&&e.length===2?e.every(DG):!1}function AG(e,t){let n=n=>{let r=e.findAll(n);if(r.length===0)return[];let i=0,a=aT(Ww(bD(r)),t);for(let e=1;e<r.length;e++){let n=aT(Ww(yD(r,e)),t);n<a&&(a=n,i=e)}return[yD(r,i)]},r=e=>{let t=n(e);return t.length===0?k(Wa(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found 0 element(s)`)):O(bD(t))};return{...e,findAll:n,findUnique:r}}function jG(e){return sj(`vertex`,e,jG,(t,n)=>({nearestTo:t=>AG(jG(e),t),atPosition:(e,t=1e-4)=>n(n=>aT(Ww(n),e)<t),withinBox:(e,t)=>n(n=>{let r=Ww(n);return r[0]>=e[0]-1e-6&&r[0]<=t[0]+1e-6&&r[1]>=e[1]-1e-6&&r[1]<=t[1]+1e-6&&r[2]>=e[2]-1e-6&&r[2]<=t[2]+1e-6}),atDistance:(e,t=[0,0,0],r=1e-4)=>n(n=>{let i=Ww(n);return Math.abs(aT(i,t)-e)<r})}))}function MG(){return jG([])}var NG=new Map,PG=null,FG=null;function IG(e,t){NG.set(e,t),PG||=e,e===PG&&(FG=t)}function LG(e){if(!e&&FG)return FG;let t=e??PG;if(!t)throw Error(`brepjs voxel engine not initialized. Call initVoxel() (or registerVoxel()) before using voxel operations.`);let n=NG.get(t);if(!n)throw Error(`brepjs: voxel engine '${t}' is not registered.`);return n}function RG(){return PG}function zG(e,t=`voxel`){IG(t,e),PG=t,FG=e}function BG(e){if(e.vertices.length%3!=0)return F(`VOXEL_INVALID_MESH`,`mesh.vertices length must be a multiple of 3 (flat xyz).`);if(e.triangles.length%3!=0)return F(`VOXEL_INVALID_MESH`,`mesh.triangles length must be a multiple of 3.`);let t=e.vertices.length/3;for(let n=0;n<e.triangles.length;n++){let r=e.triangles[n];if(r===void 0||r>=t)return F(`VOXEL_INVALID_TRIANGLE_INDEX`,`triangle index ${r} at position ${n} is out of range for ${t} vertices.`)}return null}function VG(e,t){return BG(e)||(t.length%3==0?null:F(`VOXEL_INVALID_QUERIES`,`queries length must be a multiple of 3 (flat xyz).`))}function HG(e){try{return O(LG(e))}catch(e){return k(Va(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function UG(e,t,n){let r=VG(e,t);if(r)return k(r);let i=HG(n);return A(i)?i:O(i.value.winding_numbers(e.vertices,e.triangles,t))}function WG(e,t,n){let r=VG(e,t);if(r)return k(r);let i=HG(n);if(A(i))return i;let a=i.value.points_inside(e.vertices,e.triangles,t);return O(Array.from(a,e=>e===1))}var GG=48,KG=2;function qG(e,t,n){let r=BG(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`repairMesh requires a non-empty triangle mesh.`));let i=t?.resolution??GG,a=t?.padding??KG;if(!Number.isInteger(i)||i<1)return k(F(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`));if(!Number.isInteger(a)||a<1)return k(F(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`));let o=HG(n);if(A(o))return o;try{try{var s=uC();let t=s.u(o.value.repair_mesh(e.vertices,e.triangles,i,a)),n=t.positions.length/3;return O({vertices:t.positions,normals:t.normals,triangles:t.indices,uvs:new Float32Array(n*2),faceGroups:[{start:0,count:t.indices.length/3,faceHash:0}]})}catch(e){s.e=e}finally{s.d()}}catch(e){return k(Ha(`VOXEL_REPAIR_FAILED`,e instanceof Error?e.message:`voxel repair failed (grid too large?).`,e))}}var JG=.001;function YG(e,t=JG){try{let n=uD(e,{tolerance:t});return n.vertices.length===0||n.triangles.length===0?k(Ha(`VOXEL_SHAPE_MESH_EMPTY`,`shape tessellated to an empty triangle mesh.`)):O({vertices:n.vertices,triangles:n.triangles})}catch(e){return k(Ha(`VOXEL_SHAPE_MESH_FAILED`,e instanceof Error?e.message:`failed to mesh shape for voxel op.`,e))}}var XG=48,ZG=2,QG={union:0,intersection:1,difference:2};function $G(e){let t=e?.resolution??XG,n=e?.padding??ZG;return!Number.isInteger(t)||t<1?k(F(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(F(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function eK(e){if(e.positions.length===0||e.indices.length===0)return k(Ha(`VOXEL_DEGENERATE_RESULT`,`the voxel operation produced an empty mesh (over-shrunk offset or disjoint operands?).`));let t=e.positions.length/3;return O({vertices:e.positions,normals:e.normals,triangles:e.indices,uvs:new Float32Array(t*2),faceGroups:[{start:0,count:e.indices.length/3,faceHash:0}]})}function tK(e,t,n,r){let i=BG(e);if(i)return k(i);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`offsetMesh requires a non-empty triangle mesh.`));if(!Number.isFinite(t))return k(F(`VOXEL_INVALID_DISTANCE`,`distance must be a finite number.`));let a=$G(n);if(A(a))return a;let o=HG(r);if(A(o))return o;try{try{var s=uC();return eK(s.u(o.value.offset_mesh(e.vertices,e.triangles,t,a.value.resolution,a.value.padding)))}catch(e){s.e=e}finally{s.d()}}catch(e){return k(Ha(`VOXEL_OFFSET_FAILED`,e instanceof Error?e.message:`voxel offset failed (grid too large?).`,e))}}function nK(e,t,n,r){let i=BG(e);if(i)return k(i);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`shellMesh requires a non-empty triangle mesh.`));if(!Number.isFinite(t)||t<=0)return k(F(`VOXEL_INVALID_THICKNESS`,`thickness must be a finite number > 0.`));let a=$G(n);if(A(a))return a;let o=HG(r);if(A(o))return o;try{try{var s=uC();return eK(s.u(o.value.shell_mesh(e.vertices,e.triangles,t,a.value.resolution,a.value.padding)))}catch(e){s.e=e}finally{s.d()}}catch(e){return k(Ha(`VOXEL_SHELL_FAILED`,e instanceof Error?e.message:`voxel shell failed (grid too large?).`,e))}}function rK(e,t,n,r,i){let a=BG(e);if(a)return k(a);let o=BG(t);if(o)return k(o);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBoolean requires a non-empty mesh for operand A.`));if(t.vertices.length===0||t.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBoolean requires a non-empty mesh for operand B.`));let s=QG[n],c=$G(r);if(A(c))return c;let l=HG(i);if(A(l))return l;try{try{var u=uC();return eK(u.u(l.value.voxel_boolean(e.vertices,e.triangles,t.vertices,t.triangles,s,c.value.resolution,c.value.padding)))}catch(e){u.e=e}finally{u.d()}}catch(e){return k(Ha(`VOXEL_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel boolean failed (grid too large?).`,e))}}function iK(e,t,n,r){let i=YG(e);return A(i)?i:tK(i.value,t,n,r)}function aK(e,t,n,r){let i=YG(e);return A(i)?i:nK(i.value,t,n,r)}function oK(e,t,n,r,i){let a=YG(e);if(A(a))return a;let o=YG(t);return A(o)?o:rK(a.value,o.value,n,r,i)}var sK={gyroid:0,schwarzP:1,diamond:2},cK=48,lK=2;function uK(e){let t=sK[e.type];if(t===void 0)return k(F(`LATTICE_INVALID_TYPE`,`lattice type must be one of gyroid, schwarzP, diamond (got '${e.type}').`));if(!(e.period>0))return k(F(`LATTICE_INVALID_PERIOD`,`period must be > 0.`));if(!(e.thickness>0))return k(F(`LATTICE_INVALID_THICKNESS`,`thickness must be > 0.`));let n=e.resolution??cK,r=e.padding??lK;return!Number.isInteger(n)||n<1?k(F(`LATTICE_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(r)||r<1?k(F(`LATTICE_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({tag:t,period:e.period,thickness:e.thickness,resolution:n,padding:r})}function dK(e){let t=e.positions.length/3;return{vertices:e.positions,normals:e.normals,triangles:e.indices,uvs:new Float32Array(t*2),faceGroups:[{start:0,count:e.indices.length/3,faceHash:0}]}}function fK(e,t,n){let r=BG(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(F(`LATTICE_EMPTY_MESH`,`latticeInfill requires a non-empty triangle mesh.`));let i=uK(t);if(A(i))return i;let a=HG(n);if(A(a))return a;let{tag:o,period:s,thickness:c,resolution:l,padding:u}=i.value;try{try{var d=uC();return O(dK(d.u(a.value.lattice_infill(e.vertices,e.triangles,l,u,o,s,c))))}catch(e){d.e=e}finally{d.d()}}catch(e){return k(Ha(`LATTICE_INFILL_FAILED`,e instanceof Error?e.message:`lattice infill failed (grid too large?).`,e))}}function pK(e,t,n){let r=YG(e);return A(r)?r:fK(r.value,t,n)}function mK(e,t,n){for(let t=0;t<3;t++){let n=e.min[t],r=e.max[t];if(n===void 0||r===void 0||!(n<r))return k(F(`LATTICE_INVALID_BOUNDS`,`bounds.min must be strictly less than bounds.max on every axis (axis ${t}).`))}let r=uK(t);if(A(r))return r;let i=HG(n);if(A(i))return i;let{tag:a,period:o,thickness:s,resolution:c,padding:l}=r.value,[u,d,f]=e.min,[p,m,h]=e.max;try{try{var g=uC();return O(dK(g.u(i.value.tpms_box(u,d,f,p,m,h,c,l,a,o,s))))}catch(e){g.e=e}finally{g.d()}}catch(e){return k(Ha(`TPMS_LATTICE_FAILED`,e instanceof Error?e.message:`tpms lattice failed (grid too large?).`,e))}}function hK(e){return U().createVector3d(e[0],e[1],e[2])}function gK(e){return U().createPoint3d(e[0],e[1],e[2])}function _K(e){return U().createDirection3d(e[0],e[1],e[2])}function vK(e){return[e.X(),e.Y(),e.Z()]}function yK(e){return[e.X(),e.Y(),e.Z()]}function bK(e){return[e.X(),e.Y(),e.Z()]}function xK(e,t){let n=hK(e);try{return t(n)}finally{n.delete()}}function SK(e,t){let n=gK(e);try{return t(n)}finally{n.delete()}}function CK(e,t){let n=_K(e);try{return t(n)}finally{n.delete()}}var wK=.299,TK=.587,EK=.114;function DK(e,t={}){if(e.length<2)return k(F(N.SURFACE_GRID_TOO_SMALL,`surfaceFromGrid: need at least 2 rows, got ${e.length}`));let n=e.length,r=e[0]?.length??0;if(r<2)return k(F(N.SURFACE_GRID_TOO_SMALL,`surfaceFromGrid: need at least 2 columns, got ${r}`));for(let t=0;t<n;t++){let n=e[t];if(!n||n.length!==r)return k(F(N.SURFACE_GRID_JAGGED,`surfaceFromGrid: row ${t} has ${n?.length??0} columns, expected ${r}`))}let{width:i=r-1,depth:a=n-1,scaleZ:o=1}=t,s=i/(r-1),c=a/(n-1);try{return OK(e,n,r,s,c,o)}catch{}try{return kK(e,n,r,s,c,o)}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.SURFACE_FAILED,`surfaceFromGrid failed: ${t}`,e))}}function OK(e,t,n,r,i,a){let o=[];for(let s=0;s<t;s++)for(let t=0;t<n;t++){let n=e[s],c=(n?n[t]??0:0)*a;o.push([t*r,s*i,c])}let s=W(U().bsplineSurface(o,t,n));return sw(s)?O(s):(s[Symbol.dispose](),k(P(N.SURFACE_FAILED,`B-spline surface did not produce a face`)))}function kK(e,t,n,r,i,a){let o=[];for(let s=0;s<t;s++)for(let t=0;t<n;t++){let n=e[s],c=(n?n[t]??0:0)*a;o.push([t*r,s*i,c])}let s=W(U().triangulatedSurface(o,t,n));return sw(s)||cw(s)?O(s):(s[Symbol.dispose](),k(P(N.SURFACE_FAILED,`surfaceFromGrid: unexpected shape type from sewing`)))}async function AK(e,t={}){let n=t.channel??`luminance`,r=Math.max(1,Math.round(t.downsample??1));if(typeof createImageBitmap!=`function`)return k(Ua(N.SURFACE_FAILED,`surfaceFromImage requires createImageBitmap (not available in this environment)`));let i;try{i=await createImageBitmap(e)}catch(e){return k(Ua(N.SURFACE_FAILED,`surfaceFromImage: failed to decode image — ${e instanceof Error?e.message:String(e)}`))}let a=i.width,o=i.height;if(a<2||o<2)return i.close(),k(F(N.SURFACE_GRID_TOO_SMALL,`surfaceFromImage: image too small (${a}x${o}), need at least 2x2`));if(typeof OffscreenCanvas!=`function`)return i.close(),k(Ua(N.SURFACE_FAILED,`surfaceFromImage requires OffscreenCanvas (not available in this environment)`));let s=new OffscreenCanvas(a,o).getContext(`2d`);if(!s)return i.close(),k(Ua(N.SURFACE_FAILED,`surfaceFromImage: could not get 2D canvas context`));s.drawImage(i,0,0),i.close();let c=s.getImageData(0,0,a,o).data,l=[];for(let e=0;e<o;e+=r){let t=[];for(let i=0;i<a;i+=r){let r=(e*a+i)*4,o=c[r]??0,s=c[r+1]??0,l=c[r+2]??0,u;switch(n){case`r`:u=o/255;break;case`g`:u=s/255;break;case`b`:u=l/255;break;default:u=(wK*o+TK*s+EK*l)/255;break}t.push(u)}l.push(t)}let u={};return t.width!==void 0&&(u.width=t.width),t.depth!==void 0&&(u.depth=t.depth),t.scaleZ!==void 0&&(u.scaleZ=t.scaleZ),DK(l,u)}function jK(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function MK(e,t={}){if(e.length===0)return k(F(N.HULL_EMPTY_INPUT,`hull: at least one shape is required`,void 0,void 0,`Provide one or more shapes to compute a convex hull`));for(let[t,n]of e.entries()){let e=jK(n,`hull: shapes[${t}]`);if(A(e))return e}let n=t.tolerance??.1;try{let t=U(),r=e.map(e=>e.wrapped),i=W(t.hull(r,n));return lw(i)?O(i):k(P(N.HULL_NOT_3D,`Hull result is not a solid; input may be degenerate`))}catch(e){let t=e instanceof Error?e.message:String(e);return t.includes(`coplanar`)||t.includes(`fewer than`)||t.includes(`degenerate`)?k(P(N.HULL_DEGENERATE,`Hull degenerate: ${t}`,e)):k(P(N.HULL_FAILED,`Hull operation failed: ${t}`,e))}}function NK(e){if(e.length<4)return k(F(N.HULL_EMPTY_INPUT,`convexHull: at least 4 points required, got ${e.length}`,void 0,void 0,`Provide 4 or more non-coplanar 3D points`));try{let t=U(),n=e.map(e=>({x:e[0],y:e[1],z:e[2]})),r=W(t.hullFromPoints(n,.1));return lw(r)?O(r):k(P(N.HULL_NOT_3D,`convexHull result is not a solid; points may be coplanar`))}catch(e){let t=e instanceof Error?e.message:String(e);return t.includes(`coplanar`)||t.includes(`fewer than`)||t.includes(`degenerate`)?k(P(N.HULL_DEGENERATE,`convexHull degenerate: ${t}`,e)):k(P(N.HULL_FAILED,`convexHull failed: ${t}`,e))}}function PK(e){let n=Ew(e);if(n.length!==1)return null;let r=t(n,0);if(Vw(r)!==`sphere`)return null;let i=U().area(r.wrapped);return Math.sqrt(i/(4*Math.PI))}function FK(e,t,n){try{let r=W(U().offset(e.wrapped,t,n));return dw(r)?O(r):(r[Symbol.dispose](),k(za(N.MINKOWSKI_NOT_3D,`Minkowski sphere offset did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.MINKOWSKI_FAILED,`Minkowski sphere offset failed: ${t}`,e,{operation:`minkowski`,fastPath:`sphere`}))}}function IK(e,t,n){let r=U();try{let i=Ow(e),a=Ow(t);if(i.length===0||a.length===0)return k(P(N.MINKOWSKI_FAILED,`Minkowski sum: one or both shapes have no vertices`,void 0,{operation:`minkowski`}));let o=[];for(let e of i){let[t,n,i]=r.vertexPosition(e.wrapped);for(let e of a){let[a,s,c]=r.vertexPosition(e.wrapped);o.push({x:t+a,y:n+s,z:i+c})}}let s=W(r.hullFromPoints(o,n));return dw(s)?O(s):(s[Symbol.dispose](),k(za(N.MINKOWSKI_NOT_3D,`Minkowski hull did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.MINKOWSKI_FAILED,`Minkowski general path failed: ${t}`,e,{operation:`minkowski`}))}}function LK(e,t,n={}){let{tolerance:r=1e-6}=n;if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`minkowski: shape is a null shape`));if(U().isNull(t.wrapped))return k(F(N.MINKOWSKI_NULL_TOOL,`minkowski: tool is a null shape`));if(!dw(e)||!dw(t))return k(F(N.MINKOWSKI_NOT_3D,`minkowski: both shape and tool must be 3D`));let i=PK(t);return i===null?IK(e,t,r):FK(e,i,r)}function RK(e,t,n={}){let{tolerance:r=1e-6}=n;if(e.length<4)return k(F(N.POLYHEDRON_INSUFFICIENT_POINTS,`polyhedron: need at least 4 points, got ${e.length}`));if(t.length<4)return k(F(N.POLYHEDRON_INSUFFICIENT_FACES,`polyhedron: need at least 4 faces, got ${t.length}`));let i=[];for(let[n,r]of t.entries()){for(let t of r)if(t<0||t>=e.length)return k(F(N.POLYHEDRON_INVALID_INDEX,`polyhedron: face ${n} has out-of-range index ${t} (${e.length} points)`));if(r.length<3)continue;let t=r[0];for(let e=1;e<r.length-1;e++)i.push([t,r[e],r[e+1]])}try{let t=U(),n=e.map(([e,t,n])=>({x:e,y:t,z:n})),a=W(t.buildSolidFromFaces(n,i,r));return lw(a)?O(a):(a[Symbol.dispose](),k(P(N.POLYHEDRON_FAILED,`Polyhedron did not produce a solid`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.POLYHEDRON_FAILED,`Polyhedron failed: ${t}`,e))}}var zK=1e-10;function BK(e,t,n,r){return e*r-t*n}function VK(e,t,n,r){return e*n+t*r}function HK(e,t){return Math.sqrt(e*e+t*t)}function UK(e,t){let n=e[(t%e.length+e.length)%e.length];if(!n)throw Error(`Invalid polygon index ${t} for length ${e.length}`);return n}function WK(e){let t=0;for(let n=0;n<e.length;n++){let r=UK(e,n),i=UK(e,n+1);t+=r.x*i.y-i.x*r.y}return t<0?[...e].reverse():e}function GK(e,t){let n=UK(e,t-1),r=UK(e,t),i=UK(e,t+1),a=r.x-n.x,o=r.y-n.y,s=HK(a,o),c=i.x-r.x,l=i.y-r.y,u=HK(c,l);if(s<zK||u<zK)return{dx:0,dy:0};let d=-o/s,f=a/s,p=-l/u,m=c/u,h=d+p,g=f+m,_=HK(h,g);if(_<zK)return{dx:d,dy:f};h/=_,g/=_;let v=VK(h,g,d,f),y=Math.abs(v)>zK?1/v:1;return{dx:h*y,dy:g*y}}function KK(e){return!e.prev||!e.next?!1:BK(e.x-e.prev.x,e.y-e.prev.y,e.next.x-e.x,e.next.y-e.y)<-1e-10}function qK(e){let t=e.map((t,n)=>{let r=GK(e,n);return{x:t.x,y:t.y,bx:r.dx,by:r.dy,origIdx:n,prev:null,next:null,active:!0}});for(let e=0;e<t.length;e++){let n=t[e],r=t[(e-1+t.length)%t.length],i=t[(e+1)%t.length];n&&r&&i&&(n.prev=r,n.next=i)}return t}function JK(e,t){let n=e;for(let e=0;e<t&&n;e++)n.active=!1,n=n.next}function YK(e){let t=1,n=e.next;for(;n!==e&&(t++,n=n.next,!(t>1e4)););return t}function XK(e,t){let n=e.bx-t.bx,r=e.by-t.by,i=t.x-e.x,a=t.y-e.y;if(Math.abs(n)<zK&&Math.abs(r)<zK)return null;let o;if(o=Math.abs(n)>Math.abs(r)?i/n:a/r,o<zK)return null;let s=Math.abs(n)>Math.abs(r)?r:n,c=Math.abs(n)>Math.abs(r)?a:i;if(Math.abs(s)>zK){let e=c/s;if(Math.abs(o-e)>1e-4*Math.max(1,Math.abs(o)))return null}return o}function ZK(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=HK(r,i);if(a<zK)return null;let o=-i/a,s=r/a,c=(e.x-t.x)*o+(e.y-t.y)*s,l=e.bx-(t.bx+n.bx)/2,u=e.by-(t.by+n.by)/2,d=l*o+u*s;if(Math.abs(d)<zK)return null;let f=-c/d;if(f<zK)return null;let p=e.x+f*e.bx,m=e.y+f*e.by,h=t.x+f*t.bx,g=t.y+f*t.by,_=n.x+f*n.bx,v=n.y+f*n.by,y=_-h,b=v-g,x=HK(y,b);if(x<zK)return f;let S=VK(p-h,m-g,y,b)/(x*x);return S<-.01||S>1.01?null:f}function QK(e){let t=[];for(let n of e){if(!n.active||!n.next)continue;let e=XK(n,n.next);if(e!==null&&e>zK){let r=n.x+e*n.bx,i=n.y+e*n.by;t.push({time:e,x:r,y:i,nodeA:n,nodeB:n.next,type:`edge`})}if(KK(n)){let e=n.next.next,r=0;for(;e!==n.prev&&e!==n&&r<1e3;){let i=ZK(n,e,e.next);if(i!==null&&i>zK){let r=n.x+i*n.bx,a=n.y+i*n.by;t.push({time:i,x:r,y:a,nodeA:n,nodeB:e,type:`split`})}e=e.next,r++}}}return t.sort((e,t)=>e.time-t.time),t}function $K(e){if(e.length<3)return O({nodes:[],faces:[]});try{return O(eq(e))}catch(e){return k(Ha(N.STRAIGHT_SKELETON_FAILED,e instanceof Error?e.message:String(e),e))}}function eq(e){let t=WK(e),n=t.length,r=[],i=Array.from({length:n},()=>[]),a=qK(t),o=0,s=n*n*2;for(;o<s;){o++;let e=a.find(e=>e.active);if(!e)break;let t=YK(e);if(t<=3){if(t===3){let t=e,n=t.next,a=n.next,o=XK(t,n),s=o!==null&&o>zK?o:0,c=(t.x+n.x+a.x)/3+s*(t.bx+n.bx+a.bx)/3,l=(t.y+n.y+a.y)/3+s*(t.by+n.by+a.by)/3,u=r.length;r.push({x:c,y:l,height:s});let d=i[t.origIdx],f=i[n.origIdx],p=i[a.origIdx];d&&d.push(u),f&&f.push(u),p&&p.push(u),t.active=!1,n.active=!1,a.active=!1}else JK(e,t);continue}let n=a.filter(e=>e.active),s=QK(n);if(s.length===0){for(let e of n)e.active=!1;break}let c=s[0];if(!c)break;if(c.type===`edge`){let e=c.nodeA,t=c.nodeB;if(!e.active||!t.active)continue;let n=r.length;r.push({x:c.x,y:c.y,height:c.time});let a=i[e.origIdx],o=i[t.origIdx];a&&a.push(n),o&&o.push(n),e.x=c.x,e.y=c.y,e.next=t.next,t.next.prev=e,t.active=!1;let s=[],l=e;do s.push({x:l.x,y:l.y}),l=l.next;while(l!==e);let u=GK(s,0);e.bx=u.dx,e.by=u.dy}else{let e=c.nodeA,t=c.nodeB;if(!e.active||!t.active)continue;let n=r.length;r.push({x:c.x,y:c.y,height:c.time});let o=i[e.origIdx];o&&o.push(n);let s=i[t.origIdx];s&&s.push(n);let l={x:c.x,y:c.y,bx:0,by:0,origIdx:e.origIdx,prev:null,next:null,active:!0};a.push(l),e.x=c.x,e.y=c.y;let u=e.next,d=t.next;e.next=d,d.prev=e,l.next=u,u.prev=l,l.prev=t,t.next=l;let f=e=>{let t=[],n=e;do t.push({x:n.x,y:n.y}),n=n.next;while(n!==e);return t},p=GK(f(e),0);e.bx=p.dx,e.by=p.dy;let m=GK(f(l),0);l.bx=m.dx,l.by=m.dy}}let c=[];for(let e=0;e<n;e++){let a=(e+1)%n,o=[UK(t,e),UK(t,a)],s=[0,0],l=i[a],u=i[e];if(l)for(let e of l){let t=r[e];t&&(o.push({x:t.x,y:t.y}),s.push(t.height))}if(u)for(let e=u.length-1;e>=0;e--){let t=u[e];if(t===void 0)continue;let n=r[t];if(!n)continue;let i=o[o.length-1];i&&HK(n.x-i.x,n.y-i.y)>zK&&(o.push({x:n.x,y:n.y}),s.push(n.height))}o.length>=3&&c.push({vertices:o,heights:s})}let l=[];for(let e of r)l.some(t=>Math.abs(t.x-e.x)<.01&&Math.abs(t.y-e.y)<.01)||l.push(e);return{nodes:l,faces:c}}function tq(e){let t=Tw(e).map(e=>{let t=VE(e);return{x:t[0],y:t[1]}}),n=t[0],r=t[t.length-1];return t.length>1&&n&&r&&Math.abs(n.x-r.x)<1e-10&&Math.abs(n.y-r.y)<1e-10&&t.pop(),t}function nq(e){let t=[];for(let n=1;n<e-1;n++)t.push([0,n,n+1]);return t}function rq(e,t,n,r,i,a){return(n-e)*(a-t)-(r-t)*(i-e)}function iq(e,t,n,r,i,a,o,s){let c=rq(n,r,i,a,e,t),l=rq(i,a,o,s,e,t),u=rq(o,s,n,r,e,t);return!((c<0||l<0||u<0)&&(c>0||l>0||u>0))}function aq(e){let t=e.length;if(t<3)return[];if(t===3)return[[0,1,2]];let n=0;for(let r=0;r<t;r++){let i=e[r],a=e[(r+1)%t];i&&a&&(n+=i.x*a.y-a.x*i.y)}let r=[],i=Array.from({length:t},(e,t)=>t);n<0&&i.reverse();let a=(t,n,r)=>{let a=e[t],o=e[n],s=e[r];if(!a||!o||!s||rq(a.x,a.y,o.x,o.y,s.x,s.y)<=0)return!1;for(let c of i){if(c===t||c===n||c===r)continue;let i=e[c];if(i&&iq(i.x,i.y,a.x,a.y,o.x,o.y,s.x,s.y))return!1}return!0};for(;i.length>3;){let e=!1;for(let t=0;t<i.length;t++){let n=i[(t-1+i.length)%i.length],o=i[t],s=i[(t+1)%i.length];if(!(n===void 0||o===void 0||s===void 0)&&a(n,o,s)){r.push([n,o,s]),i.splice(t,1),e=!0;break}}if(!e)break}if(i.length===3){let[e,t,n]=i;e!==void 0&&t!==void 0&&n!==void 0&&r.push([e,t,n])}return r}function oq(e,t,n){let r=[];for(let i of e.faces){let e=i.vertices.map((e,n)=>[e.x,e.y,(i.heights[n]??0)*t]),a=nq(e.length);for(let[t,i,o]of a){let a=e[t],s=e[i],c=e[o];if(!a||!s||!c)continue;let l=s[0]-a[0],u=s[1]-a[1],d=s[2]-a[2],f=c[0]-a[0],p=c[1]-a[1],m=c[2]-a[2],h=u*m-d*p,g=d*f-l*m,_=l*p-u*f;if(h*h+g*g+_*_<1e-20)continue;let v=n.buildTriFace(a,s,c);v!==null&&r.push(v)}}return r}function sq(e,t){let n=(t?.angle??45)*Gw,r=Math.tan(n);try{let t=tq(e);if(t.length<3)return k(P(N.ROOF_FAILED,`Wire must have at least 3 edges for roof generation`));let n=$K(t);if(!n.ok)return n;let i=n.value;if(i.faces.length===0)return k(P(N.ROOF_FAILED,`Straight skeleton computation produced no faces`));let a=U(),o=oq(i,r,a);for(let[e,n,r]of aq(t)){let i=t[e],s=t[n],c=t[r];if(!i||!s||!c)continue;let l=[i.x,i.y,0],u=[s.x,s.y,0],d=[c.x,c.y,0],f=a.buildTriFace(l,d,u);f!==null&&o.push(f)}if(o.length===0)return k(P(N.ROOF_FAILED,`No valid triangular faces could be built`));try{let e=a.sewAndSolidify(o,1e-6);return O(tw(a.fixShape(e)))}catch(e){try{let t=tw(a.sew(o,1e-6));return BC(t)?O(t):k(P(N.ROOF_FAILED,`Sew fallback produced invalid solid`,e))}catch(e){return k(P(N.ROOF_FAILED,`Failed to sew roof faces`,e))}}}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.ROOF_FAILED,`Roof generation failed: ${t}`,e))}}var cq={coincident:3,concentric:4,distance:1,angle:1};function lq(e,t){let n=new Map;for(let t of e)n.set(t,{position:[0,0,0],rotation:[1,0,0,0]});let r=[];for(let e of t)if(e.type===`coincident`&&e.entityA&&e.entityB){let t=e.entityA,i=e.entityB;if(t.entity.type===`plane`&&i.entity.type===`plane`){let e=t.entity.normal??[0,0,1],r=t.entity.origin,a=i.entity.origin,o=e[0]*(r[0]-a[0])+e[1]*(r[1]-a[1])+e[2]*(r[2]-a[2]),s=[o*e[0],o*e[1],o*e[2]];n.set(i.node,{position:s,rotation:[1,0,0,0]})}else r.push(`coincident(${t.entity.type}-${i.entity.type})`)}else if(e.type===`distance`&&e.entityA&&e.entityB&&e.value!==void 0){let t=e.entityA,i=e.entityB;if(t.entity.type===`plane`&&i.entity.type===`plane`){let r=t.entity.normal??[0,0,1],a=t.entity.origin,o=i.entity.origin,s=r[0]*(a[0]-o[0])+r[1]*(a[1]-o[1])+r[2]*(a[2]-o[2])+e.value,c=[s*r[0],s*r[1],s*r[2]];n.set(i.node,{position:c,rotation:[1,0,0,0]})}else r.push(`distance(${t.entity.type}-${i.entity.type})`)}else (e.type===`concentric`||e.type===`angle`)&&r.push(e.type);return{transforms:n,dof:r.reduce((e,t)=>e+(cq[t]??cq[t.split(`(`)[0]??``]??0),0),converged:r.length===0,unsupported:r}}function uq(e){return e.face?{type:`plane`,origin:VT(e.face),normal:BT(e.face)}:e.point?{type:`point`,origin:e.point}:null}function dq(e,t){let n=uq(e),r=uq(t);return!n||!r?k(F(N.ASSEMBLY_MATE_INVALID,`solveAssembly: could not extract geometry from mate entities`)):O({entityA:{node:e.node,entity:n},entityB:{node:t.node,entity:r}})}function fq(e){switch(e.type){case`fixed`:return O({type:`fixed`,entityA:{node:e.entity.node,entity:{type:`point`,origin:[0,0,0]}}});case`coincident`:{let t=dq(e.entityA,e.entityB);return t.ok?O({type:`coincident`,...t.value}):t}case`distance`:{let t=dq(e.entityA,e.entityB);return t.ok?O({type:`distance`,...t.value,value:e.distance}):t}case`angle`:{let t=dq(e.entityA,e.entityB);return t.ok?O({type:`angle`,...t.value,value:e.angle}):t}case`concentric`:{let t=dq(e.axisA,e.axisB);return t.ok?O({type:`concentric`,...t.value}):t}}}function pq(e,t){let n=e.mates??[];return{...e,mates:[...n,t]}}function mq(e){let t=e.mates;if(!t||t.length===0)return k(F(N.ASSEMBLY_MATE_INVALID,`solveAssembly: no mates defined`));try{let n=[];lA(e,e=>{n.push(e.name)});let r=[];for(let e of t){let t=fq(e);if(!t.ok)return t;r.push(t.value)}let i=lq(n,r);if(!i.converged){let e=i.unsupported.length>0?`Unsupported constraint types: ${i.unsupported.join(`, `)} (${i.dof} DOF unresolved)`:`Assembly constraint solver did not converge`;return k(P(N.ASSEMBLY_NOT_CONVERGED,e))}return O({transforms:i.transforms,dof:i.dof,converged:i.converged})}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.ASSEMBLY_SOLVE_FAILED,`Assembly solve failed: ${t}`,e))}}function hq(e,t,n=1e-6){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`checkInterference: first shape is a null shape`));if(U().isNull(t.wrapped))return k(F(N.NULL_SHAPE_INPUT,`checkInterference: second shape is a null shape`));let r=U().distance(e.wrapped,t.wrapped);return O({hasInterference:r.value<=n,minDistance:r.value,pointOnShape1:r.point1,pointOnShape2:r.point2})}function gq(e,n=1e-6){let r=[],i=e.map(e=>zw(e));return e.forEach((a,o)=>{for(let s=o+1;s<e.length;s++){if(_q(t(i,o),t(i,s),n))continue;let c=j(hq(a,t(e,s),n));c.hasInterference&&r.push({i:o,j:s,result:c})}}),r}function _q(e,t,n){return e.xMax+n<t.xMin||t.xMax+n<e.xMin||e.yMax+n<t.yMin||t.yMax+n<e.yMin||e.zMax+n<t.zMin||t.zMax+n<e.zMin}function vq(e){let t=e.split(/\r?\n/),n=[],r=!1,i;for(let e=0;e<t.length-1;e+=2){let a=t[e],o=t[e+1];if(a===void 0||o===void 0)continue;let s=parseInt(a.trim(),10),c=o.trim();if(!isNaN(s)){if(s===2&&c===`ENTITIES`){r=!0;continue}if(r){if(s===0){if(c===`ENDSEC`||c===`EOF`){i&&n.push(i);break}i&&n.push(i),i={type:c,layer:`0`,data:new Map};continue}i&&(s===8?i.layer=c:i.data.set(s,c))}}}return n}function yq(e,t,n=0){let r=e.get(t);if(r===void 0)return n;let i=parseFloat(r);return isNaN(i)?n:i}function bq(e){let{type:t,data:n}=e,r=U();if(t===`LINE`)return r.makeLineEdge([yq(n,10),yq(n,20),yq(n,30)],[yq(n,11),yq(n,21),yq(n,31)]);if(t===`CIRCLE`)return r.makeCircleEdge([yq(n,10),yq(n,20),yq(n,30)],[0,0,1],yq(n,40));if(t===`ARC`){let e=yq(n,50)*Math.PI/180,t=yq(n,51)*Math.PI/180;return r.makeCircleArc([yq(n,10),yq(n,20),yq(n,30)],[0,0,1],yq(n,40),e,t)}}async function xq(e,t){let n;try{n=await e.text()}catch(e){return k(Ua(N.DXF_IMPORT_FAILED,`Failed to read DXF blob`,e))}let r=vq(n),i=t?.layer===void 0?r:r.filter(e=>e.layer===t.layer);if(i.length===0)return O([]);let a=[];try{for(let e of i){let t=bq(e);t!==void 0&&a.push(t)}return a.length===0?O([]):O([QC(U().makeWire(a))])}catch(e){return k(Ua(N.DXF_IMPORT_FAILED,`Failed to convert DXF entities to geometry`,e))}finally{for(let e of a)e.delete()}}function Sq(e,t,n=1e-6){let r=U(),i=[];for(let[t,n,a]of e){let e=r.buildTriFace(t,n,a);e!==null&&i.push(e)}if(i.length===0)return k(Ua(t,`No valid triangular faces could be built`));try{return O(W(r.sewAndSolidify(i,n)))}catch{try{return O(W(r.sew(i,n)))}catch{return k(Ua(t,`Failed to sew triangular faces`))}}}function Cq(e){let t=e.split(/\s+/),n=parseFloat(t[1]??``),r=parseFloat(t[2]??``),i=parseFloat(t[3]??``);return isNaN(n)||isNaN(r)||isNaN(i)?null:[n,r,i]}function wq(e){return e.split(/\s+/).slice(1).map(e=>parseInt(e.split(`/`)[0]??``,10)).filter(e=>!isNaN(e))}async function Tq(e){let t=(await e.text()).split(`
|
|
57
|
-
`),n=[],r=[];for(let e of t){let t=e.trim();if(t.startsWith(`v `)){let e=Cq(t);e&&n.push(e)}else if(t.startsWith(`f `)){let e=wq(t);e.length>=3&&r.push(e)}}if(n.length===0||r.length===0)return k(Ua(N.OBJ_IMPORT_FAILED,`OBJ file contains no valid geometry`));try{return Eq(n,r)}catch(e){let t=e instanceof Error?e.message:String(e);return k(Ua(N.OBJ_IMPORT_FAILED,`OBJ import failed: ${t}`,e))}}function Eq(e,t){let n=[];for(let r of t)for(let t=1;t<r.length-1;t++){let i=r[0]??0,a=r[t]??0,o=r[t+1]??0,s=i>0?i-1:e.length+i,c=a>0?a-1:e.length+a,l=o>0?o-1:e.length+o,u=e[s],d=e[c],f=e[l];!u||!d||!f||n.push([u,d,f])}return Sq(n,N.OBJ_IMPORT_FAILED)}function Dq(e,t){let n=-1;for(let t=e.length-22;t>=0;t--)if(e[t]===80&&e[t+1]===75&&e[t+2]===5&&e[t+3]===6){n=t;break}if(n<0)return null;let r=new DataView(e.buffer,e.byteOffset,e.byteLength),i=r.getUint32(n+16,!0),a=i+r.getUint32(n+12,!0),o=i,s=new TextDecoder;for(;o<a&&r.getUint32(o,!0)===33639248;){let n=r.getUint16(o+28,!0),i=r.getUint16(o+30,!0),a=r.getUint16(o+32,!0),c=r.getUint32(o+42,!0);if(s.decode(e.subarray(o+46,o+46+n))===t){if(r.getUint16(c+8,!0)!==0)return null;let t=r.getUint16(c+26,!0),n=r.getUint16(c+28,!0),i=r.getUint32(c+18,!0),a=c+30+t+n;return e.subarray(a,a+i)}o+=46+n+i+a}return null}function Oq(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95}function kq(e){let t={},n=0;for(;n<e.length;){let r=e.indexOf(`="`,n);if(r<0)break;let i=r;for(;i>0&&Oq(e.charCodeAt(i-1));)i--;if(i===r){n=r+2;continue}let a=e.slice(i,r),o=r+2,s=e.indexOf(`"`,o);if(s<0)break;t[a]=e.slice(o,s),n=s+1}return t}function Aq(e,t){let n=[],r=`<${t} `,i=0;for(;i<e.length;){let t=e.indexOf(r,i);if(t<0)break;let a=e.indexOf(`>`,t);if(a<0)break;n.push(e.slice(t,a+1)),i=a+1}return n}function jq(e,t){let n=e.indexOf(`<${t}`);if(n<0)return null;let r=e.indexOf(`</${t}>`,n);return r<0?null:e.slice(n,r+t.length+3)}function Mq(e){let t=e.startsWith(`#`)?e.slice(1):e;return[parseInt(t.slice(0,2),16)/255,parseInt(t.slice(2,4),16)/255,parseInt(t.slice(4,6),16)/255,t.length>=8?parseInt(t.slice(6,8),16)/255:1]}function Nq(e){let t=new Map,n=0;for(;n<e.length;){let r=e.indexOf(`<colorgroup`,n);if(r<0)break;let i=e.indexOf(`</colorgroup>`,r);if(i<0)break;let a=e.slice(r,i+13);n=i+13;let o=e.indexOf(`>`,r);if(o<0)continue;let s=kq(e.slice(r,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of Aq(a,`color`)){let t=kq(e).color;t!==void 0&&l.push(Mq(t))}t.set(c,l)}let r=0;for(;r<e.length;){let n=e.indexOf(`<basematerials`,r);if(n<0)break;let i=e.indexOf(`</basematerials>`,n);if(i<0)break;let a=e.slice(n,i+16);r=i+16;let o=e.indexOf(`>`,n);if(o<0)continue;let s=kq(e.slice(n,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of Aq(a,`base`)){let t=kq(e).displaycolor;t===void 0?l.push([0,0,0,1]):l.push(Mq(t))}t.set(c,l)}return t}function Pq(e){let t=[],n=[],r=[],i=Nq(e);for(let n of Aq(e,`vertex`)){let e=kq(n);e.x!==void 0&&e.y!==void 0&&e.z!==void 0&&t.push([parseFloat(e.x),parseFloat(e.y),parseFloat(e.z)])}let a=null,o=null,s=jq(e,`object`);if(s!==null){let e=s.indexOf(`>`);if(e>=0){let t=kq(s.slice(0,e+1));t.pid!==void 0&&(a=parseInt(t.pid,10)),t.pindex!==void 0&&(o=parseInt(t.pindex,10))}}for(let t of Aq(e,`triangle`)){let e=kq(t);if(e.v1!==void 0&&e.v2!==void 0&&e.v3!==void 0){n.push([parseInt(e.v1,10),parseInt(e.v2,10),parseInt(e.v3,10)]);let t=null,s=e.pid??(a===null?void 0:String(a)),c=e.p1??(o===null?void 0:String(o));if(s!==void 0&&c!==void 0){let e=parseInt(s,10),n=parseInt(c,10),r=i.get(e);r!==void 0&&n<r.length&&(t=r[n]??null)}r.push(t)}}return{vertices:t,triangles:n,triangleColors:r}}function Fq(e){let t=new Map;for(let n of e){if(n===null)continue;let e=n.join(`,`),r=t.get(e);r===void 0?t.set(e,{count:1,color:n}):r.count++}let n=null;for(let e of t.values())(n===null||e.count>n.count)&&(n=e);return n===null?null:n.color}function Iq(e){let t=U(),n=e.vertices.map(([e,t,n])=>({x:e,y:t,z:n})),r=e.triangles;try{return O(W(t.buildSolidFromFaces(n,r,1e-6)))}catch{let t=[];for(let[n,r,i]of e.triangles){let a=e.vertices[n],o=e.vertices[r],s=e.vertices[i];!a||!o||!s||t.push([a,o,s])}return Sq(t,N.THREEMF_IMPORT_FAILED)}}async function Lq(e){try{let t=await e.arrayBuffer(),n=Dq(new Uint8Array(t),`3D/3dmodel.model`);if(!n)return k(Ua(N.THREEMF_IMPORT_FAILED,`3MF archive does not contain 3D/3dmodel.model (or uses unsupported compression)`));let r=Pq(new TextDecoder().decode(n));if(r.vertices.length===0||r.triangles.length===0)return k(Ua(N.THREEMF_IMPORT_FAILED,`3MF model contains no valid geometry`));let i=Iq(r);if(i.ok){let e=Fq(r.triangleColors);e!==null&&mE(i.value,e)}return i}catch(e){let t=e instanceof Error?e.message:String(e);return k(Ua(N.THREEMF_IMPORT_FAILED,`3MF import failed: ${t}`,e))}}async function Rq(e){try{let t=await e.arrayBuffer();return O(W(U().importGLB(t)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(Ua(N.GLB_IMPORT_FAILED,`Failed to import GLB: ${t}`,e))}}function $(e){return`__wrapped`in e?e.val:e}function zq(e){return $(e)}function Bq(e,t){return SE($(e),t)}function Vq(e,t,n){let r=n?.at;return CE($(e),t,r,n?.axis)}function Hq(e,t){let n=t?.at;return wE($(e),t?.normal??[1,0,0],n)}function Uq(e,t,n){return TE($(e),t,n?.center)}function Wq(e){return NE($(e))}function Gq(e,t){return AE($(e),t)}function Kq(e,t){return ME($(e),t)}function qq(e,t,n){return UD($(e),$(t),{...n,unsafe:!0})}function Jq(e,t,n){return WD($(e),$(t),{...n,unsafe:!0})}function Yq(e,t,n){return GD($(e),$(t),{...n,unsafe:!0})}function Xq(e,t,n){return XD($(e),t,n)}function Zq(e,t,n){return nO($(e),t,n)}function Qq(e,t){return rO($(e),t)}function $q(e,t,n){return iO($(e),t,n)}function eJ(e,t){if(e!==void 0)return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(pj()).findAll(t)}function tJ(e,t){return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(gj()).findAll(t)}function nJ(e){return typeof e==`object`&&!Array.isArray(e)&&typeof e!=`function`?{mode:`distAngle`,distance:e.distance,angle:e.angle}:typeof e==`function`?{mode:`standard`,distance:t=>{let n=e(t);return n===null?null:typeof n==`object`&&!Array.isArray(n)?n.distance:n}}:{mode:`standard`,distance:e}}function rJ(e,t,n){let r=$(e),i,a;return n===void 0?(i=void 0,a=t):(i=eJ(t,r),a=n),uk(r,i,a)}function iJ(e,t,n){let r=$(e),i,a;n===void 0?(i=void 0,a=t):(i=eJ(t,r),a=n);let o=nJ(a);return o.mode===`distAngle`?SO(r,[...i??Tw(r)],o.distance,o.angle):dk(r,i,o.distance)}function aJ(e,t,n,r){let i=$(e);return fk(i,tJ(t,i),n,r?.tolerance)}function oJ(e,t,n){return pk($(e),t,n?.tolerance)}function sJ(e,t){return ck($(e),t)}function cJ(e,t,n){let r=$(e);return hk(r,tJ(t,r),n.pullDirection,n.neutralPlane,n.angle)}function lJ(e){return xk($(e))}function uJ(e){return zE($(e))}function dJ(e,t){return uD($(e),t)}function fJ(e,t){return dD($(e),t)}function pJ(e){return Uw($(e))}function mJ(e){return PE($(e))}function hJ(e){return AT(e)}function gJ(e){return _k($(e))}function _J(e){return IE($(e))}function vJ(e,t){return HN($(e),typeof t==`number`?[0,0,t]:t)}function yJ(e,t){let n=t?.at??[0,0,0];return UN($(e),n,t?.axis??[0,0,1],t?.angle??360)}function bJ(e,t){return DV(e.map(e=>$(e)),t)}function xJ(e,n){if(n===void 0){let t=Ew(e);if(t.length===0)return k(F(N.COMPOUND_NO_FACES,`compoundOps: shape has no faces`));let n=bD(t),r=VT(n)[2];for(let e=1;e<t.length;e++){let i=yD(t,e),a=VT(i)[2];a>r&&(n=i,r=a)}return O(n)}if(typeof n==`function`){let r=n(gj()).findAll(e);return r.length===0?k(Wa(N.COMPOUND_FACE_NOT_FOUND,`compoundOps: face finder matched no faces`)):O(t(r,0))}return O(n)}function SJ(e){return`sketchOnPlane`in e&&typeof e.sketchOnPlane==`function`?e.sketchOnPlane(`XY`).wire:e}function CJ(e,t){let n=$(e),{at:r,radius:i,axis:a}=t,o=a??[0,0,1];if(i<=0)return k(F(`DRILL_INVALID_RADIUS`,`Drill radius must be positive`));if(cT(o))return k(F(`DRILL_ZERO_AXIS`,`Drill axis cannot be zero`));let s=oT(o),c=r.length===2?[r[0],r[1],0]:[r[0],r[1],r[2]],l;if(t.depth!==void 0)l=lO(i,t.depth,c,s);else{let e=zw(n),t=[[e.xMin,e.yMin,e.zMin],[e.xMax,e.yMin,e.zMin],[e.xMin,e.yMax,e.zMin],[e.xMax,e.yMax,e.zMin],[e.xMin,e.yMin,e.zMax],[e.xMax,e.yMin,e.zMax],[e.xMin,e.yMax,e.zMax],[e.xMax,e.yMax,e.zMax]],r=1/0,a=-1/0;for(let e of t){let t=(e[0]-c[0])*s[0]+(e[1]-c[1])*s[1]+(e[2]-c[2])*s[2];t<r&&(r=t),t>a&&(a=t)}--r,a+=1,l=lO(i,a-r,[c[0]+s[0]*r,c[1]+s[1]*r,c[2]+s[2]*r],s)}return WD(n,l,{unsafe:!0})}function wJ(e,t){let n=$(e),{profile:r,depth:i}=t;if(i<=0)return k(F(`POCKET_INVALID_DEPTH`,`Pocket depth must be positive`));let a=xJ(n,t.face);if(A(a))return a;let o=a.value,s=BT(o),c=VT(o),l=FD(SJ(r));if(A(l))return l;let u=HN(SE(l.value,c),$w(oT(s),-i));return A(u)?u:WD(n,u.value,{unsafe:!0})}function TJ(e,t){let n=$(e),{profile:r,height:i}=t;if(i<=0)return k(F(`BOSS_INVALID_HEIGHT`,`Boss height must be positive`));let a=xJ(n,t.face);if(A(a))return a;let o=a.value,s=BT(o),c=VT(o),l=FD(SJ(r));if(A(l))return l;let u=HN(SE(l.value,c),$w(oT(s),i));return A(u)?u:UD(n,u.value,{unsafe:!0})}function EJ(e,t){let n=$(e),r=t?.normal??[1,0,0],i=t?.at;return cT(r)?k(F(`MIRROR_ZERO_NORMAL`,`Mirror plane normal cannot be zero`)):UD(n,wE(n,r,i),{unsafe:!0})}function DJ(e,t){let n=$(e),{xDir:r,xCount:i,xSpacing:a,yDir:o,yCount:s,ySpacing:c}=t;if(i<1||s<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern counts must be at least 1`));if(cT(r))return k(F(`PATTERN_ZERO_DIRECTION`,`X direction cannot be zero`));if(cT(o))return k(F(`PATTERN_ZERO_DIRECTION`,`Y direction cannot be zero`));if(i===1&&s===1)return O(n);let l=oT(r),u=oT(o),d=[n];for(let e=0;e<i;e++)for(let t=0;t<s;t++){if(e===0&&t===0)continue;let r=[l[0]*a*e+u[0]*c*t,l[1]*a*e+u[1]*c*t,l[2]*a*e+u[2]*c*t];d.push(SE(n,r))}return qD(d,{unsafe:!0})}var OJ=class extends Error{code;kind;suggestion;metadata;constructor(e){let t=e.suggestion?`${e.message}\nSuggestion: ${e.suggestion}`:e.message;super(t),this.name=`BrepError`,this.code=e.code,this.kind=e.kind,e.suggestion&&(this.suggestion=e.suggestion),e.metadata&&(this.metadata=e.metadata)}};function kJ(e){if(A(e))throw new OJ(e.error);return e.value}function AJ(e){return e}function jJ(e){return e}function MJ(e){return e}function NJ(e){return e}function PJ(e){return{val:e,__wrapped:!0,translate:t=>WJ(Bq(e,t)),rotate:(t,n)=>WJ(Vq(e,t,n)),mirror:t=>WJ(Hq(e,t)),scale:(t,n)=>WJ(Uq(e,t,n)),applyMatrix:t=>WJ(kJ(Gq(e,t))),moveX:t=>WJ(Bq(e,[t,0,0])),moveY:t=>WJ(Bq(e,[0,t,0])),moveZ:t=>WJ(Bq(e,[0,0,t])),rotateX:t=>WJ(Vq(e,t,{axis:[1,0,0]})),rotateY:t=>WJ(Vq(e,t,{axis:[0,1,0]})),rotateZ:t=>WJ(Vq(e,t,{axis:[0,0,1]})),bounds:()=>zw(e),describe:()=>pJ(e),clone:()=>WJ(kJ(Wq(e))),mesh:t=>dJ(e,t),meshEdges:t=>fJ(e,t),isValid:()=>gJ(e),isEmpty:()=>_J(e),heal:()=>WJ(kJ(lJ(e))),simplify:()=>WJ(kJ(uJ(e))),toBREP:()=>kJ(mJ(e)),apply:t=>WJ(t(e)),applyResult:t=>WJ(kJ(t(e))),done:()=>e}}function FJ(e){return{fuse:(t,n)=>GJ(kJ(qq(e,$(t),{...n,unsafe:!0}))),cut:(t,n)=>GJ(kJ(Jq(e,$(t),{...n,unsafe:!0}))),intersect:(t,n)=>GJ(kJ(Yq(e,$(t),{...n,unsafe:!0}))),fuseAll:(t,n)=>GJ(NJ(kJ(qD([e,...t.map($)],{...n,unsafe:!0})))),cutAll:(t,n)=>GJ(NJ(kJ(JD(e,t,{...n,unsafe:!0})))),section:(t,n)=>WJ(kJ(Xq(e,t,n))),split:t=>WJ(kJ(Qq(e,t))),slice:(t,n)=>kJ($q(e,t,n))}}function IJ(e){return{fillet(...t){return t.length===1?GJ(NJ(kJ(rJ(AJ(e),t[0])))):GJ(NJ(kJ(rJ(AJ(e),t[0],t[1]))))},chamfer(...t){return t.length===1?GJ(NJ(kJ(iJ(AJ(e),t[0])))):GJ(NJ(kJ(iJ(AJ(e),t[0],t[1]))))},shell:(t,n,r)=>GJ(NJ(kJ(aJ(AJ(e),t,n,r)))),offset:(t,n)=>GJ(NJ(kJ(oJ(AJ(e),t,n)))),draft:(t,n)=>GJ(NJ(kJ(cJ(AJ(e),t,n))))}}function LJ(e){return{drill:t=>GJ(kJ(CJ(e,t))),pocket:t=>GJ(kJ(wJ(e,t))),boss:t=>GJ(kJ(TJ(e,t))),mirrorJoin:t=>GJ(kJ(EJ(e,t))),rectangularPattern:t=>GJ(kJ(DJ(e,t)))}}function RJ(e){return{volume:()=>kJ(FA(e)),area:()=>kJ(IA(e)),volumeProps:()=>kJ(MA(e)),surfaceProps:()=>kJ(NA(e))}}function zJ(e){return{edges:()=>Tw(e),faces:()=>Ew(e),wires:()=>Dw(e),vertices:()=>Ow(e)}}function BJ(e){return{linearPattern:(t,n,r)=>GJ(NJ(kJ(nA(e,t,n,r)))),circularPattern:(t,n,r)=>GJ(NJ(kJ(rA(e,t,n,r))))}}function VJ(e){return{...PJ(e),...FJ(e),...IJ(e),...LJ(e),...RJ(e),...zJ(e),...BJ(e)}}function HJ(e){return{...PJ(e),length:()=>GE(e),startPoint:()=>VE(e),endPoint:()=>HE(e),pointAt:t=>UE(e,t),tangentAt:t=>WE(e,t),isClosed:()=>KE(e),sweep(t,n){if(!ow(e))throw Error(`sweep requires a Wire`);let r=kJ(PN(MJ(e),$(t),n));return GJ(Array.isArray(r)?r[0]:r)}}}function UJ(e){return{...PJ(e),area:()=>kJ(IA(e)),normalAt:t=>BT(e,t),center:()=>VT(e),surfaceType:()=>kJ(MT(e)),outerWire:()=>UT(e),innerWires:()=>GT(e),extrude:t=>GJ(kJ(vJ(jJ(e),t))),revolve:t=>GJ(kJ(yJ(jJ(e),t)))}}function WJ(e){return dw(e)?VJ(e):sw(e)?UJ(e):aw(e)||ow(e)?HJ(e):PJ(e)}function GJ(e){return VJ(e)}function KJ(e){if(e&&typeof e==`object`&&`face`in e&&typeof e.face==`function`&&`_defaultOrigin`in e)return UJ(e.face());if(e&&typeof e==`object`&&`wrapped`in e)return sw(e)?UJ(e):dw(e)?VJ(e):aw(e)||ow(e)?HJ(e):PJ(e);throw Error(`shape() requires a Sketch or branded shape type`)}var qJ=.25,JJ=e=>Math.tan(e)-e;function YJ(e,t,n,r){let i=e/Math.cos(t),a=n+r*(Math.tan(t)-t);return[i*Math.cos(a),i*Math.sin(a),0]}function XJ(e,t,n,r,i){let a=[];for(let o=0;o<=r;o++){let s=.5-.5*Math.cos(o/r*Math.PI);a.push(YJ(e,s*t,n,i))}return a}function ZJ(e){return Math.max(16,Math.round(8*Math.sqrt(e)))}function QJ(e,t,n,r,i,a,o){let s=e*t/2,c=s*Math.cos(n),l=t*(1+r),u=t*(1+i-r),d=o?s-t*(1-r):s+l,f=o?s+t*(1+i+r):s-u,p=a/s,m=(Math.PI/2+2*r*Math.tan(n))/e+(o?p:-p),h=o?f:d;return{rPitch:s,rb:c,rTip:d,rRoot:f,alphaPitch:n,halfToothAngle:m,alphaTip:h<=c?0:Math.acos(Math.min(1,c/h)),toothPitch:2*Math.PI/e,isInternal:o}}function $J(e,t,n){if(t===0)return O(e);let r=JJ(e)+2*t*Math.tan(e)/n,i,a;if(r>JJ(e)?(i=e,a=Math.PI/2-1e-6):(i=1e-4,a=e),r>JJ(a)||r<JJ(i))return k(F(`GEAR_PA_OUT_OF_RANGE`,`working pressure angle out of range — target inv(αw)=${r.toFixed(4)} not in [${JJ(i).toFixed(4)}, ${JJ(a).toFixed(4)}]`,void 0,{target:r,invLo:JJ(i),invHi:JJ(a)}));for(let e=0;e<50;e++){let e=.5*(i+a);JJ(e)<r?i=e:a=e}return O(.5*(i+a))}function eY(e,t,n,r,i){return $J(e,t+n,r+i)}function tY(e,t,n,r,i){return $J(e,n-t,i-r)}function nY(e,t,n,r,i){return(e+t)*n*Math.cos(r)/(2*Math.cos(i))}function rY(e,t,n,r){if(!Number.isInteger(e)||!Number.isInteger(t)||!Number.isInteger(n))return k(F(`GEAR_NON_INTEGER_TEETH`,`tooth counts and planet count must be integers`));if(e<4||t<4||n<2)return k(F(`GEAR_TEETH_TOO_FEW`,`zs ≥ 4, zp ≥ 4, N ≥ 2 required`));if((2*e+2*t)%n!=0)return k(F(`GEAR_ASSEMBLY`,`(2·zs + 2·zp) must be divisible by N — got ${2*e+2*t} mod ${n} = ${(2*e+2*t)%n}`));let i=t+2+2*r,a=(e+t)*Math.sin(Math.PI/n);return a<=i?k(F(`GEAR_PLANET_COLLISION`,`planet tips would collide: (zs+zp)·sin(π/N) = ${a.toFixed(3)} ≤ planet tip = ${i.toFixed(3)}`)):O(void 0)}function iY(e,t,n,r,i,a,o,s){return(Math.sqrt(Math.max(0,e*e-t*t))+Math.sqrt(Math.max(0,n*n-r*r))-i*Math.sin(s))/(Math.PI*a*Math.cos(o))}function aY(e,t,n,r,i,a,o,s){return(Math.sqrt(Math.max(0,e*e-t*t))-Math.sqrt(Math.max(0,n*n-r*r))+i*Math.sin(s))/(Math.PI*a*Math.cos(o))}function oY(e,t){return 1-e*Math.sin(t)*Math.sin(t)/2}function sY(e,t,n){return Math.max(0,oY(e,t)-n)}function cY(e){return e<8?.2:.485-2.88/e}function lY(e,t,n,r){let i=e*1e3,a=cY(r);return a<=0||n<=0||t<=0?1/0:2*i/(r*t*t*n*a)}function uY(e,t,n=!1){let r=(1.4+6.5/e)*(20/(t*180/Math.PI))**.15;return n?r*.85:r}function dY(e,t,n,r,i,a=!1){return lY(e,t,n,r)*uY(r,i,a)}function fY(e){return e/2}function pY(e,t){return e+2*t}function mY(e){return e%2==0?Math.PI/e:0}function hY(e,t,n){return e*(1+t/n)+mY(n)}function gY(e={}){let t=e.moduleSize??3,n=e.sunTeeth??15,r=e.planetTeeth??12,i=e.numPlanets??3,a=(e.pressureAngleDeg??20)*Math.PI/180,o=e.sunShift??0,s=e.planetShift??0,c=rY(n,r,i,s);if(A(c))return c;let l=eY(a,o,s,n,r);if(A(l))return l;let u=nY(n,r,t,a,l.value),d=[];for(let e=0;e<i;e++){let t=e*2*Math.PI/i,a=hY(t,n,r);d.push({rotationDeg:a*180/Math.PI,position:[u*Math.cos(t),u*Math.sin(t),0]})}return O(d)}function _Y(e,t,n,r,i){let a=t*e.toothPitch,o=(t+1)%n*e.toothPitch,s=JJ(e.alphaPitch),c=a-e.halfToothAngle-s,l=a+e.halfToothAngle+s,u=XJ(e.rb,e.alphaTip,c,r,1),d=XJ(e.rb,e.alphaTip,l,r,-1).reverse(),f=bD(u),p=xD(u),m=bD(d),h=xD(d),g=[],_=e=>{i.register(e),g.push(e)},v=e.isInternal?e.rb<e.rRoot:e.rb>e.rRoot;v&&_(wD([e.rRoot*Math.cos(c),e.rRoot*Math.sin(c),0],f));let y=e.rPitch*1e-5,b=jD(u,{tolerance:y});if(A(b))return b;_(b.value),_(OD(p,[e.rTip*Math.cos(a),e.rTip*Math.sin(a),0],m));let x=jD(d,{tolerance:y});if(A(x))return x;_(x.value),v&&_(wD(h,[e.rRoot*Math.cos(l),e.rRoot*Math.sin(l),0]));let S=o-e.halfToothAngle-s,C=.5*(l+S);return S<l&&(C+=Math.PI),_(OD(v?[e.rRoot*Math.cos(l),e.rRoot*Math.sin(l),0]:h,[e.rRoot*Math.cos(C),e.rRoot*Math.sin(C),0],v?[e.rRoot*Math.cos(S),e.rRoot*Math.sin(S),0]:[e.rb*Math.cos(S),e.rb*Math.sin(S),0])),O(g)}function vY(e){return bY(e,!1)}function yY(e){return bY(e,!0)}function bY(e,t){try{var n=uC();let{teeth:r,moduleSize:i,pressureAngle:a,shift:o,clearance:s,flankThinning:c,samples:l=ZJ(i)}=e;if(r<4)return k(F(`GEAR_TEETH_TOO_FEW`,`gear needs ≥ 4 teeth, got ${r}`));if(i<=0)return k(F(`GEAR_MODULE_NONPOSITIVE`,`module must be > 0, got ${i}`));let u=QJ(r,i,a,o,s,c,t),d=n.u(new SC),f=[];for(let e=0;e<r;e++){let t=_Y(u,e,r,l,d);if(A(t))return t;f.push(...t.value)}let p=PD(f);return A(p)?p:O(p.value)}catch(e){n.e=e}finally{n.d()}}function xY(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=qJ,flankThinning:s=0,bore:c=0,samples:l}=e;if(r<=0)return k(F(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));if(l!==void 0&&(!Number.isInteger(l)||l<1))return k(F(`GEAR_SAMPLES_INVALID`,`samples must be a positive integer; got ${String(l)}`));let u=i*Math.PI/180,d=QJ(t,n,u,a,o,s,!1);if(c>0&&c>=2*d.rRoot)return k(F(`GEAR_BORE_TOO_LARGE`,`bore diameter ${c.toFixed(2)} ≥ root diameter ${(2*d.rRoot).toFixed(2)} — would erase the gear teeth`));let f=vY({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(f))return f;let p=CY(t,u,a);return OY(f.value,r,c,d,p)}function SY(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=qJ,flankThinning:s=0,ringWallThickness:c=2*e.moduleSize,samples:l}=e;if(r<=0)return k(F(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));if(c<=0)return k(F(`GEAR_WALL_NONPOSITIVE`,`ringWallThickness must be > 0`));if(l!==void 0&&(!Number.isInteger(l)||l<1))return k(F(`GEAR_SAMPLES_INVALID`,`samples must be a positive integer; got ${String(l)}`));let u=i*Math.PI/180,d=yY({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(d))return d;let f=QJ(t,n,u,a,o,s,!0),p=DY(f.rPitch+c);return A(p)?p:AY(p.value,d.value,r,f,[])}function CY(e,t,n){let r=sY(e,t,n);return r<=0?[]:[{code:`UNDERCUT_RISK`,severity:`warning`,message:`gear is undercut: increase shift by ${r.toFixed(3)} to avoid (z=${e})`,context:{deficit:r,teeth:e}}]}function wY(e){let t=EY(e);if(A(t))return t;let n=t.value,r=TY(n);if(A(r))return r;let{sun:i,planet:a,ring:o}=r.value,s=PY(n,i,a,o),c=MY(a.solid,n);a.solid.delete();let l=NY(o.solid,n.zr),u=FY(n,s);return O({sun:i.solid,planets:c,ring:l,ringTeeth:n.zr,workingPressureAngle:n.alphaW_sp,centerDistance:n.centerDistance,contactRatio:{sunPlanet:s.crSunPlanet,planetRing:s.crPlanetRing},undercutDeficit:{sun:s.undercutSun,planet:s.undercutPlanet},...s.lewisStress?{lewisStress:s.lewisStress}:{},...s.stressConcentrationFactor?{stressConcentrationFactor:s.stressConcentrationFactor}:{},diagnostics:u})}function TY(e){let t=e.samples===void 0?{}:{samples:e.samples},n={moduleSize:e.moduleSize,thickness:e.thickness,pressureAngleDeg:e.pressureAngleDeg,clearance:e.clearance,flankThinning:e.bHalf,...t},r=xY({...n,teeth:e.sunTeeth,shift:e.sunShift,bore:e.sunBore});if(A(r))return r;let i=xY({...n,teeth:e.planetTeeth,shift:e.planetShift,bore:e.planetBore});if(A(i))return r.value.solid.delete(),i;let a=SY({...n,teeth:e.zr,shift:e.ringShift,ringWallThickness:e.ringWallThickness});return A(a)?(r.value.solid.delete(),i.value.solid.delete(),a):O({sun:r.value,planet:i.value,ring:a.value})}function EY(e){let t=e.moduleSize??3,n=e.sunTeeth??15,r=e.planetTeeth??12,i=e.numPlanets??3,a=e.pressureAngleDeg??20,o=a*Math.PI/180,s=e.sunShift??0,c=e.planetShift??0,l=e.ringShift??0;if(e.thickness<=0)return k(F(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));let u=rY(n,r,i,c);if(A(u))return u;let d=pY(n,r),f=eY(o,s,c,n,r);if(A(f))return f;let p=tY(o,c,l,r,d);if(A(p))return p;let m=nY(n,r,t,o,f.value);return O({moduleSize:t,sunTeeth:n,planetTeeth:r,numPlanets:i,pressureAngleDeg:a,alpha:o,alphaW_sp:f.value,alphaW_pr:p.value,clearance:e.clearance??.25,bHalf:fY(e.backlash??0),sunShift:s,planetShift:c,ringShift:l,ringWallThickness:e.ringWallThickness??2*t,thickness:e.thickness,sunBore:e.sunBore??0,planetBore:e.planetBore??0,...e.appliedTorque===void 0?{}:{appliedTorque:e.appliedTorque},...e.samples===void 0?{}:{samples:e.samples},zr:d,centerDistance:m})}function DY(e){try{var t=uC();let n=PD([t.u(new SC).register(TD(e,[0,0,0],[0,0,1]))]);return A(n)?n:O(n.value)}catch(e){t.e=e}finally{t.d()}}function OY(e,t,n,r,i){try{var a=uC();let o=FD(e);if(A(o))return o;let s=HN(o.value,[0,0,t]);if(A(s))return s;if(n<=0)return O(jY(s.value,r,i));let c=a.u(new SC),l=kY(n/2);if(A(l))return l;c.register(l.value);let u=HN(l.value,[0,0,t+1]);if(A(u))return u;c.register(u.value);let d=c.register(SE(u.value,[0,0,-.5])),f=WD(s.value,d);return A(f)?f:O(jY(f.value,r,i))}catch(e){a.e=e}finally{a.d()}}function kY(e){let t=DY(e);return A(t)?t:FD(t.value)}function AY(e,t,n,r,i){let a=FD(e,[t]);if(A(a))return a;let o=HN(a.value,[0,0,n]);return A(o)?o:O(jY(o.value,r,i))}function jY(e,t,n=[]){return{solid:e,diagnostics:n,pitchDiameter:2*t.rPitch,baseDiameter:2*t.rb,tipDiameter:2*t.rTip,rootDiameter:2*t.rRoot}}function MY(e,t){let n=[];try{for(let r=0;r<t.numPlanets;r++){let i=r*2*Math.PI/t.numPlanets,a=CE(e,hY(i,t.sunTeeth,t.planetTeeth)*180/Math.PI);try{let e=[t.centerDistance*Math.cos(i),t.centerDistance*Math.sin(i),0];n.push(SE(a,e))}finally{a.delete()}}return n}catch(e){for(let e of n)e.delete();throw e}}function NY(e,t){let n=mY(t);if(n===0)return e;let r=CE(e,n*180/Math.PI);return e.delete(),r}function PY(e,t,n,r){let i={crSunPlanet:iY(t.tipDiameter/2,t.baseDiameter/2,n.tipDiameter/2,n.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_sp),crPlanetRing:aY(n.tipDiameter/2,n.baseDiameter/2,r.tipDiameter/2,r.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_pr),undercutSun:sY(e.sunTeeth,e.alpha,e.sunShift),undercutPlanet:sY(e.planetTeeth,e.alpha,e.planetShift)};if(e.appliedTorque!==void 0){let t=e.appliedTorque;i.lewisStress={sun:dY(t,e.moduleSize,e.thickness,e.sunTeeth,e.alpha),planet:dY(t*e.planetTeeth/e.sunTeeth,e.moduleSize,e.thickness,e.planetTeeth,e.alpha),ring:dY(t*e.zr/e.sunTeeth,e.moduleSize,e.thickness,e.zr,e.alpha,!0)},i.stressConcentrationFactor={sun:uY(e.sunTeeth,e.alpha),planet:uY(e.planetTeeth,e.alpha),ring:uY(e.zr,e.alpha,!0)}}return i}function FY(e,t){let n=[];t.crSunPlanet<1.2&&n.push({code:`CONTACT_RATIO_LOW_SUN_PLANET`,severity:`warning`,message:`sun-planet contact ratio ${t.crSunPlanet.toFixed(2)} is below 1.2 — may run unevenly`,context:{value:t.crSunPlanet}}),t.crPlanetRing<1.2&&n.push({code:`CONTACT_RATIO_LOW_PLANET_RING`,severity:`warning`,message:`planet-ring contact ratio ${t.crPlanetRing.toFixed(2)} is below 1.2 — may run unevenly`,context:{value:t.crPlanetRing}}),t.undercutSun>0&&n.push({code:`UNDERCUT_RISK_SUN`,severity:`warning`,message:`sun gear is undercut: increase sunShift by ${t.undercutSun.toFixed(3)} to avoid`,context:{deficit:t.undercutSun,sunTeeth:e.sunTeeth}}),t.undercutPlanet>0&&n.push({code:`UNDERCUT_RISK_PLANET`,severity:`warning`,message:`planet gear is undercut: increase planetShift by ${t.undercutPlanet.toFixed(3)} to avoid`,context:{deficit:t.undercutPlanet,planetTeeth:e.planetTeeth}});let r=Math.abs(e.sunShift)+Math.abs(e.planetShift)+Math.abs(e.ringShift);e.appliedTorque!==void 0&&r>.05&&n.push({code:`LEWIS_Y_SHIFT_UNCORRECTED`,severity:`info`,message:`Lewis stress uses unshifted Y(z) and K_f approximations; expect ±5% per 0.1 of profile shift`});let i=e.ringShift-(e.sunShift+2*e.planetShift);return Math.abs(i)>1e-6&&n.push({code:`PLANETARY_SHIFT_KINEMATIC_MISMATCH`,severity:`warning`,message:`ringShift should equal sunShift + 2·planetShift for both meshes to share working PA; off by ${i.toFixed(3)}`,context:{kinematicError:i,sunShift:e.sunShift,planetShift:e.planetShift,ringShift:e.ringShift}}),n}var IY=CG({addHoles:()=>Qk,bezier:()=>zk,box:()=>Ek,bsplineApprox:()=>Rk,circle:()=>Nk,compound:()=>Jk,cone:()=>kk,cylinder:()=>Dk,ellipse:()=>Pk,ellipseArc:()=>Lk,ellipsoid:()=>jk,face:()=>Uk,fill:()=>ID,filledFace:()=>Wk,helix:()=>Fk,line:()=>Mk,offsetFace:()=>Xk,polygon:()=>Kk,polyhedron:()=>RK,sewShells:()=>Zk,solid:()=>Yk,sphere:()=>Ok,subFace:()=>Gk,tangentArc:()=>Bk,threePointArc:()=>Ik,torus:()=>Ak,vertex:()=>qk,wire:()=>Vk,wireLoop:()=>Hk}),LY=CG({checkBoolean:()=>GO,convexHull:()=>NK,cut:()=>Jq,cutAll:()=>JD,cutAllBisect:()=>IO,fuse:()=>qq,fuseAll:()=>qD,fuseAllBisect:()=>BO,hull:()=>MK,intersect:()=>Yq,minkowski:()=>LK,section:()=>Xq,sectionToFace:()=>Zq,slice:()=>$q,split:()=>Qq}),RY=CG({chamfer:()=>iJ,draft:()=>cJ,fillet:()=>rJ,heal:()=>lJ,offset:()=>oJ,shell:()=>aJ,simplify:()=>uJ,thicken:()=>sJ,variableFillet:()=>gk}),zY=CG({applyMatrix:()=>Gq,clone:()=>Wq,composeTransforms:()=>jE,mirror:()=>Hq,rotate:()=>Vq,scale:()=>Uq,transformCopy:()=>Kq,translate:()=>Bq}),BY=CG({checkAllInterferences:()=>gq,checkInterference:()=>hq,createDistanceQuery:()=>BA,measureArea:()=>IA,measureCurvatureAt:()=>VA,measureCurvatureAtMid:()=>HA,measureDistance:()=>RA,measureDistanceProps:()=>zA,measureLength:()=>LA,measureLinearProps:()=>PA,measureSurfaceProps:()=>NA,measureVolume:()=>FA,measureVolumeProps:()=>MA}),VY=CG({blueprintToDXF:()=>oW,exportAssemblySTEP:()=>tA,exportDXF:()=>aW,exportGlb:()=>KU,exportGltf:()=>GU,exportIGES:()=>_D,exportOBJ:()=>LU,exportSTEP:()=>hD,exportSTEPConfigured:()=>UW,exportSTL:()=>gD,exportThreeMF:()=>TW,importDXF:()=>xq,importGLB:()=>Rq,importIGES:()=>KW,importOBJ:()=>Tq,importSTEP:()=>WW,importSTL:()=>GW,importSVG:()=>HW,importSVGPathD:()=>VW,importThreeMF:()=>Lq}),HY=CG({cornerFinder:()=>UM,edgeFinder:()=>pj,faceFinder:()=>gj,getSingleFace:()=>yj,vertexFinder:()=>MG,wireFinder:()=>vj}),UY=CG({complexExtrude:()=>IN,extrude:()=>vJ,guidedSweep:()=>VN,loft:()=>bJ,multiSectionSweep:()=>BN,revolve:()=>yJ,roof:()=>sq,supportExtrude:()=>FN,surfaceFromGrid:()=>DK,surfaceFromImage:()=>AK,sweep:()=>PN,twistExtrude:()=>LN}),WY=CG({circularPattern:()=>rA,linearPattern:()=>nA}),GY=14695981039346656037n,KY=1099511628211n,qY=18446744073709551615n;function JY(){return GY}function YY(e,t){return(e^BigInt(t&255))*KY&qY}function XY(e,t){let n=e;for(let e=0;e<t.length;e++)n=YY(n,t[e]??0);return n}var ZY=new TextEncoder;function QY(e,t){return XY(e,ZY.encode(t))}var $Y=new ArrayBuffer(8),eX=new DataView($Y),tX=new Uint8Array($Y);function nX(e,t){return eX.setFloat64(0,Object.is(t,-0)?0:t),XY(e,tX)}function rX(e,t){let n=e,r=t&qY;for(let e=0;e<8;e++)n=YY(n,Number(r&255n)),r>>=8n;return n}function iX(e,t){let n=e,r=t|0;for(let e=0;e<4;e++)n=YY(n,r&255),r>>>=8;return n}function aX(e,t){return YY(e,+!!t)}function oX(e){return(e&qY).toString(16).padStart(16,`0`)}var sX=new Set;function cX(e){return QY(JY(),e)}function lX(e){return{kind:`NumLit`,value:e,structuralHash:nX(cX(`NumLit`),e),freeParams:sX}}function uX(e){let t=cX(`Vec3Lit`);for(let n of e)t=nX(t,n);return{kind:`Vec3Lit`,value:e,structuralHash:t,freeParams:sX}}function dX(e){let t=cX(`Vec2Lit`);for(let n of e)t=nX(t,n);return{kind:`Vec2Lit`,value:e,structuralHash:t,freeParams:sX}}function fX(e){return{kind:`Param`,name:e,structuralHash:QY(cX(`Param`),e),freeParams:new Set([e])}}function pX(e,t,n){let r=QY(cX(`BinOp`),e);return r=rX(r,t.structuralHash),r=rX(r,n.structuralHash),{kind:`BinOp`,op:e,a:t,b:n,structuralHash:r,freeParams:CX(t.freeParams,n.freeParams)}}function mX(e,t){let n=QY(cX(`UnaryOp`),e);return n=rX(n,t.structuralHash),{kind:`UnaryOp`,op:e,arg:t,structuralHash:n,freeParams:t.freeParams}}function hX(e,t){let n=iX(cX(`Component`),t);return n=rX(n,e.structuralHash),{kind:`Component`,vec:e,index:t,structuralHash:n,freeParams:e.freeParams}}function gX(e,t){let n=iX(cX(`BuildVec`),e),r=new Set;for(let e of t){n=rX(n,e.structuralHash);for(let t of e.freeParams)r.add(t)}return{kind:`BuildVec`,dim:e,components:t,structuralHash:n,freeParams:r}}var _X=(e,t)=>pX(`+`,e,t),vX=(e,t)=>pX(`*`,e,t);function yX(e){return typeof e==`number`?lX(e):e}function bX(e,t){if(!Array.isArray(e))return e;let n=e;return n.every(e=>typeof e==`number`)?t===3?uX([n[0],n[1],n[2]]):dX([n[0],n[1]]):gX(t,n.map(yX))}function xX(e){return bX(e,3)}function SX(e){return bX(e,2)}function CX(e,t){if(e.size===0)return t;if(t.size===0)return e;let n=new Set(e);for(let e of t)n.add(e);return n}function wX(e){return typeof e==`number`}function TX(e,t){return wX(e)?O(e):k(F(N.NULL_SHAPE_INPUT,`${t}: expected number, got ${Array.isArray(e)?`vector(${e.length})`:typeof e}`))}function EX(e,t,n){return Array.isArray(e)&&e.length===t?O(e):k(F(N.NULL_SHAPE_INPUT,`${n}: expected Vec${t}, got ${wX(e)?`number`:`vector(${e.length})`}`))}function DX(e,t){switch(e.kind){case`NumLit`:return O(e.value);case`Vec3Lit`:return O(e.value);case`Vec2Lit`:return O(e.value);case`Param`:{let n=t[e.name];return n===void 0?k(F(N.NULL_SHAPE_INPUT,`unbound param: ${e.name}`)):O(n)}case`BinOp`:return OX(e,t);case`UnaryOp`:return kX(e,t);case`Component`:return AX(e,t);case`BuildVec`:return jX(e,t)}}function OX(e,t){let n=DX(e.a,t);if(!n.ok)return n;let r=DX(e.b,t);if(!r.ok)return r;let i=TX(n.value,`BinOp(${e.op}).a`);if(!i.ok)return i;let a=TX(r.value,`BinOp(${e.op}).b`);if(!a.ok)return a;switch(e.op){case`+`:return O(i.value+a.value);case`-`:return O(i.value-a.value);case`*`:return O(i.value*a.value);case`/`:return a.value===0?k(F(N.NULL_SHAPE_INPUT,`BinOp(/): division by zero`)):O(i.value/a.value)}}function kX(e,t){let n=DX(e.arg,t);if(!n.ok)return n;let r=TX(n.value,`UnaryOp(${e.op})`);if(!r.ok)return r;let i=r.value;switch(e.op){case`neg`:return O(-i);case`sin`:return O(Math.sin(i));case`cos`:return O(Math.cos(i));case`sqrt`:return O(Math.sqrt(i));case`abs`:return O(Math.abs(i))}}function AX(e,t){let n=DX(e.vec,t);if(!n.ok)return n;if(wX(n.value))return k(F(N.NULL_SHAPE_INPUT,`Component: cannot index a scalar`));let r=n.value,i=r[e.index];return i===void 0?k(F(N.NULL_SHAPE_INPUT,`Component: index ${e.index} out of range for Vec${r.length}`)):O(i)}function jX(e,t){if(e.components.length!==e.dim)return k(F(N.NULL_SHAPE_INPUT,`BuildVec(${e.dim}): expected ${e.dim} components, got ${e.components.length}`));let n=[];for(let r of e.components){let e=DX(r,t);if(!e.ok)return e;let i=TX(e.value,`BuildVec.component`);if(!i.ok)return i;n.push(i.value)}return O(e.dim===2?[n[0],n[1]]:[n[0],n[1],n[2]])}function MX(e,t,n){let r=DX(e,t);return r.ok?TX(r.value,n):r}function NX(e,t,n){let r=DX(e,t);if(!r.ok)return r;let i=EX(r.value,3,n);if(!i.ok)return i;let[a,o,s]=i.value;return O([a,o,s])}function PX(e,t){if(t.size===0)return Object.freeze({});let n={};for(let r of t){let t=e[r];t!==void 0&&(n[r]=t)}return Object.freeze(n)}var FX=new Set;function IX(e){return QY(JY(),e)}function LX(e,t){return rX(e,t.structuralHash)}function RX(e,t){return t===void 0?aX(e,!1):LX(aX(e,!0),t)}function zX(e,t){return t===void 0?aX(e,!1):nX(aX(e,!0),t)}function BX(...e){let t=new Set;for(let n of e)if(n)for(let e of n.freeParams)t.add(e);return t.size===0?FX:t}function VX(e,t,n){let r=yX(e),i=yX(t),a=yX(n),o=IX(`Box`);return o=LX(LX(LX(o,r),i),a),{kind:`Box`,x:r,y:i,z:a,structuralHash:o,freeParams:BX(r,i,a)}}function HX(e){let t=yX(e);return{kind:`Sphere`,radius:t,structuralHash:LX(IX(`Sphere`),t),freeParams:t.freeParams}}function UX(e,t){let n=yX(e),r=yX(t);return{kind:`Cylinder`,radius:n,height:r,structuralHash:LX(LX(IX(`Cylinder`),n),r),freeParams:BX(n,r)}}function WX(e,t,n){let r=yX(e),i=yX(t),a=yX(n),o=IX(`Cone`);return o=LX(LX(LX(o,r),i),a),{kind:`Cone`,radius1:r,radius2:i,height:a,structuralHash:o,freeParams:BX(r,i,a)}}function GX(e,t){let n=yX(e),r=yX(t);return{kind:`Torus`,majorRadius:n,minorRadius:r,structuralHash:LX(LX(IX(`Torus`),n),r),freeParams:BX(n,r)}}function KX(e){let t=e.map(xX),n=iX(IX(`Polygon`),t.length);for(let e of t)n=LX(n,e);return{kind:`Polygon`,points:t,structuralHash:n,freeParams:BX(...t)}}function qX(e){let t=yX(e);return{kind:`Circle`,radius:t,structuralHash:LX(IX(`Circle`),t),freeParams:t.freeParams}}function JX(e,t){let n=xX(e),r=xX(t);return{kind:`Line`,from:n,to:r,structuralHash:LX(LX(IX(`Line`),n),r),freeParams:BX(n,r)}}function YX(e){let t=xX(e);return{kind:`Vertex`,point:t,structuralHash:LX(IX(`Vertex`),t),freeParams:t.freeParams}}function XX(e){return{kind:`Empty`,output:e,structuralHash:QY(IX(`Empty`),e),freeParams:FX}}function ZX(){return XX(`Solid`)}function QX(){return XX(`Face`)}function $X(){return XX(`Wire`)}function eZ(e,t,n,r){return zX(LX(LX(IX(e),t),n),r)}function tZ(e,t,n){return{kind:`Fuse`,a:e,b:t,tolerance:n,structuralHash:eZ(`Fuse`,e,t,n),freeParams:BX(e,t)}}function nZ(e,t,n){return{kind:`Cut`,a:e,b:t,tolerance:n,structuralHash:eZ(`Cut`,e,t,n),freeParams:BX(e,t)}}function rZ(e,t,n){return{kind:`Intersect`,a:e,b:t,tolerance:n,structuralHash:eZ(`Intersect`,e,t,n),freeParams:BX(e,t)}}function iZ(e,t){let n=iX(IX(`FuseAll`),e.length);for(let t of e)n=LX(n,t);return n=zX(n,t),{kind:`FuseAll`,shapes:e,tolerance:t,structuralHash:n,freeParams:BX(...e)}}function aZ(e,t,n){let r=LX(IX(`CutAll`),e);r=iX(r,t.length);for(let e of t)r=LX(r,e);return r=zX(r,n),{kind:`CutAll`,base:e,tools:t,tolerance:n,structuralHash:r,freeParams:BX(e,...t)}}function oZ(e){return e===void 0?void 0:xX(e)}function sZ(e,t){let n=xX(t);return{kind:`Translate`,target:e,vector:n,structuralHash:LX(LX(IX(`Translate`),e),n),freeParams:BX(e,n)}}function cZ(e,t,n){let r=yX(t),i=oZ(n?.axis),a=oZ(n?.at),o=LX(LX(IX(`Rotate`),e),r);return o=RX(o,i),o=RX(o,a),{kind:`Rotate`,target:e,angle:r,axis:i,at:a,structuralHash:o,freeParams:BX(e,r,i,a)}}function lZ(e,t,n){let r=yX(t),i=oZ(n?.center),a=LX(LX(IX(`Scale`),e),r);return a=RX(a,i),{kind:`Scale`,target:e,factor:r,center:i,structuralHash:a,freeParams:BX(e,r,i)}}function uZ(e,t){let n=oZ(t?.normal),r=oZ(t?.at),i=LX(IX(`Mirror`),e);return i=RX(i,n),i=RX(i,r),{kind:`Mirror`,target:e,normal:n,at:r,structuralHash:i,freeParams:BX(e,n,r)}}function dZ(e){let t=iX(IX(`Compound`),e.length);for(let n of e)t=LX(t,n);return{kind:`Compound`,children:e,structuralHash:t,freeParams:BX(...e)}}function fZ(e){switch(e.kind){case`Box`:case`Sphere`:case`Cylinder`:case`Cone`:case`Torus`:return`Solid`;case`Polygon`:return`Face`;case`Circle`:case`Line`:return`Edge`;case`Vertex`:return`Vertex`;case`Empty`:return e.output;case`Fuse`:case`Cut`:case`Intersect`:return fZ(e.a);case`FuseAll`:return e.shapes[0]?fZ(e.shapes[0]):`Solid`;case`CutAll`:return fZ(e.base);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return fZ(e.target);case`Compound`:return`Compound`}}function pZ(e,t){let n=MX(e.x,t.env,`Box.x`);if(!n.ok)return n;let r=MX(e.y,t.env,`Box.y`);if(!r.ok)return r;let i=MX(e.z,t.env,`Box.z`);return i.ok?O(Ek(n.value,r.value,i.value)):i}function mZ(e,t){let n=MX(e.radius,t.env,`Sphere.radius`);return n.ok?O(Ok(n.value)):n}function hZ(e,t){let n=MX(e.radius,t.env,`Cylinder.radius`);if(!n.ok)return n;let r=MX(e.height,t.env,`Cylinder.height`);return r.ok?O(Dk(n.value,r.value)):r}function gZ(e,t){let n=MX(e.radius1,t.env,`Cone.radius1`);if(!n.ok)return n;let r=MX(e.radius2,t.env,`Cone.radius2`);if(!r.ok)return r;let i=MX(e.height,t.env,`Cone.height`);return i.ok?O(kk(n.value,r.value,i.value)):i}function _Z(e,t){let n=MX(e.majorRadius,t.env,`Torus.majorRadius`);if(!n.ok)return n;let r=MX(e.minorRadius,t.env,`Torus.minorRadius`);return r.ok?O(Ak(n.value,r.value)):r}function vZ(e,t){let n=[];for(let r of e.points){let e=NX(r,t.env,`Polygon.point`);if(!e.ok)return e;n.push(e.value)}return Kk(n)}function yZ(e,t){let n=MX(e.radius,t.env,`Circle.radius`);return n.ok?O(Nk(n.value)):n}function bZ(e,t){let n=NX(e.from,t.env,`Line.from`);if(!n.ok)return n;let r=NX(e.to,t.env,`Line.to`);return r.ok?O(Mk(n.value,r.value)):r}function xZ(e,t){let n=NX(e.point,t.env,`Vertex.point`);return n.ok?O(qk(n.value)):n}function SZ(e){return k(Ha(N.NULL_SHAPE_INPUT,`${e}: empty result has no kernel representation`))}function CZ(e,t,n){let r=e.evalNode(t);return r.ok?dw(r.value)?O(r.value):k(za(N.CSG_NOT_3D,`${n}: operand did not produce a 3D shape`)):r}function wZ(e,t){return{unsafe:!0,fuzzyValue:e.tolerance??t.tolerance}}function TZ(e,t){if(e.a.kind===`Empty`)return t.evalNode(e.b);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=CZ(t,e.a,`Fuse.a`);if(!n.ok)return n;let r=CZ(t,e.b,`Fuse.b`);return r.ok?UD(n.value,r.value,wZ(e,t)):r}function EZ(e,t){if(e.a.kind===`Empty`)return SZ(`Cut`);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=CZ(t,e.a,`Cut.a`);if(!n.ok)return n;let r=CZ(t,e.b,`Cut.b`);return r.ok?WD(n.value,r.value,wZ(e,t)):r}function DZ(e,t){if(e.a.kind===`Empty`||e.b.kind===`Empty`)return SZ(`Intersect`);let n=CZ(t,e.a,`Intersect.a`);if(!n.ok)return n;let r=CZ(t,e.b,`Intersect.b`);return r.ok?GD(n.value,r.value,wZ(e,t)):r}function OZ(e,t,n){let r=[];for(let i of t){let t=CZ(e,i,n);if(!t.ok)return t;r.push(t.value)}return O(r)}function kZ(e,t){let n=e.shapes.filter(e=>e.kind!==`Empty`);if(n.length===0)return SZ(`FuseAll`);if(n.length===1&&n[0])return t.evalNode(n[0]);let r=OZ(t,n,`FuseAll.operand`);return r.ok?qD(r.value,wZ(e,t)):r}function AZ(e,t){if(e.base.kind===`Empty`)return SZ(`CutAll`);let n=e.tools.filter(e=>e.kind!==`Empty`);if(n.length===0)return t.evalNode(e.base);let r=CZ(t,e.base,`CutAll.base`);if(!r.ok)return r;let i=OZ(t,n,`CutAll.tool`);return i.ok?JD(r.value,i.value,wZ(e,t)):i}function jZ(e){return k(Ha(N.NULL_SHAPE_INPUT,`${e}: cannot transform an Empty node`))}function MZ(e,t,n,r){return e?NX(e,t,n):O(r)}function NZ(e,t){if(e.target.kind===`Empty`)return jZ(`Translate`);let n=NX(e.vector,t.env,`Translate.vector`);if(!n.ok)return n;let r=t.evalNode(e.target);return r.ok?O(SE(r.value,n.value)):r}function PZ(e,t){if(e.target.kind===`Empty`)return jZ(`Rotate`);let n=MX(e.angle,t.env,`Rotate.angle`);if(!n.ok)return n;let r=MZ(e.axis,t.env,`Rotate.axis`,[0,0,1]);if(!r.ok)return r;let i=MZ(e.at,t.env,`Rotate.at`,[0,0,0]);if(!i.ok)return i;let a=t.evalNode(e.target);return a.ok?O(CE(a.value,n.value,i.value,r.value)):a}function FZ(e,t){if(e.target.kind===`Empty`)return jZ(`Scale`);let n=MX(e.factor,t.env,`Scale.factor`);if(!n.ok)return n;let r=MZ(e.center,t.env,`Scale.center`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(TE(i.value,n.value,r.value)):i}function IZ(e,t){if(e.target.kind===`Empty`)return jZ(`Mirror`);let n=MZ(e.normal,t.env,`Mirror.normal`,[1,0,0]);if(!n.ok)return n;let r=MZ(e.at,t.env,`Mirror.at`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(wE(i.value,n.value,r.value)):i}function LZ(e,t){let n=e.children.filter(e=>e.kind!==`Empty`);if(n.length===0)return k(Ha(N.NULL_SHAPE_INPUT,`Compound: cannot materialize a compound with zero non-empty children`));let r=[];for(let e of n){let n=t.evalNode(e);if(!n.ok)return n;r.push(n.value)}return O(Jk(r))}function RZ(){return k(Ha(N.NULL_SHAPE_INPUT,`Empty: cannot materialize an Empty node directly — only valid as boolean/transform operand`))}function zZ(e,t){switch(e.kind){case`Box`:return pZ(e,t);case`Sphere`:return mZ(e,t);case`Cylinder`:return hZ(e,t);case`Cone`:return gZ(e,t);case`Torus`:return _Z(e,t);case`Polygon`:return vZ(e,t);case`Circle`:return yZ(e,t);case`Line`:return bZ(e,t);case`Vertex`:return xZ(e,t);case`Empty`:return RZ();case`Fuse`:return TZ(e,t);case`Cut`:return EZ(e,t);case`Intersect`:return DZ(e,t);case`FuseAll`:return kZ(e,t);case`CutAll`:return AZ(e,t);case`Translate`:return NZ(e,t);case`Rotate`:return PZ(e,t);case`Scale`:return FZ(e,t);case`Mirror`:return IZ(e,t);case`Compound`:return LZ(e,t)}}function BZ(e,t){if(typeof t==`number`)return nX(aX(e,!1),t);let n=aX(e,!0);n=iX(n,t.length);for(let e of t)n=nX(n,e);return n}function VZ(e,t){if(t.size===0)return JY();let n=PX(e,t),r=Object.keys(n).sort(),i=JY();for(let e of r){i=QY(i,e);let t=n[e];t!==void 0&&(i=BZ(i,t))}return i}function HZ(e,t,n,r){let i=VZ(t,e.freeParams),a=r===void 0?`d`:nX(JY(),r).toString(16);return`${oX(e.structuralHash)}:${n}:${oX(i)}:${a}`}var UZ=class{scope=new SC;cache=new Map;registered=new WeakSet;kernelId;defaultTolerance;onStep;hits=0;misses=0;constructor(e={}){this.kernelId=e.kernel??aC()??`unregistered`,this.defaultTolerance=e.tolerance,e.onStep&&(this.onStep=e.onStep)}evaluate(e,t={}){return oC(this.kernelId,()=>this.evaluateInner(e,t))}evaluateInner(e,t){let n=HZ(e,t,this.kernelId,this.defaultTolerance),r=this.cache.get(n);if(r!==void 0)return this.hits++,this.onStep?.({node:e,cacheKey:n,cacheHit:!0}),O(r);this.misses++;let i=zZ(e,{env:t,tolerance:this.defaultTolerance,evalNode:e=>this.evaluateInner(e,t)});return i.ok?(this.registered.has(i.value)||(this.scope.register(i.value),this.registered.add(i.value)),this.cache.set(n,i.value),this.onStep?.({node:e,cacheKey:n,cacheHit:!1}),i):i}cacheStats(){return{hits:this.hits,misses:this.misses,entries:this.cache.size}}resetStats(){this.hits=0,this.misses=0}[Symbol.dispose](){this.scope[Symbol.dispose](),this.cache.clear()}};function WZ(e,t){try{var n=uC();let r=t(n.u(new UZ(e)));if(r instanceof Promise)throw Error(`withEvaluator() callback returned a Promise. Async code must construct an Evaluator directly and dispose it manually — borrowed shapes would otherwise be freed before the Promise resolves.`);return r}catch(e){n.e=e}finally{n.d()}}function GZ(e){return{csgVersion:1,root:ZZ(e)}}function KZ(e){switch(e.kind){case`NumLit`:return{kind:`NumLit`,value:e.value};case`Vec3Lit`:return{kind:`Vec3Lit`,value:[e.value[0],e.value[1],e.value[2]]};case`Vec2Lit`:return{kind:`Vec2Lit`,value:[e.value[0],e.value[1]]};case`Param`:return{kind:`Param`,name:e.name};case`BinOp`:return{kind:`BinOp`,op:e.op,a:KZ(e.a),b:KZ(e.b)};case`UnaryOp`:return{kind:`UnaryOp`,op:e.op,arg:KZ(e.arg)};case`Component`:return{kind:`Component`,vec:KZ(e.vec),index:e.index};case`BuildVec`:return{kind:`BuildVec`,dim:e.dim,components:e.components.map(KZ)}}}function qZ(e){switch(e.kind){case`Box`:return{kind:`Box`,x:KZ(e.x),y:KZ(e.y),z:KZ(e.z)};case`Sphere`:return{kind:`Sphere`,radius:KZ(e.radius)};case`Cylinder`:return{kind:`Cylinder`,radius:KZ(e.radius),height:KZ(e.height)};case`Cone`:return{kind:`Cone`,radius1:KZ(e.radius1),radius2:KZ(e.radius2),height:KZ(e.height)};case`Torus`:return{kind:`Torus`,majorRadius:KZ(e.majorRadius),minorRadius:KZ(e.minorRadius)};case`Polygon`:return{kind:`Polygon`,points:e.points.map(KZ)};case`Circle`:return{kind:`Circle`,radius:KZ(e.radius)};case`Line`:return{kind:`Line`,from:KZ(e.from),to:KZ(e.to)};case`Vertex`:return{kind:`Vertex`,point:KZ(e.point)};case`Empty`:return{kind:`Empty`,output:e.output};default:return}}function JZ(e){switch(e.kind){case`Fuse`:case`Cut`:case`Intersect`:return{kind:e.kind,a:ZZ(e.a),b:ZZ(e.b),tolerance:e.tolerance};case`FuseAll`:return{kind:`FuseAll`,shapes:e.shapes.map(ZZ),tolerance:e.tolerance};case`CutAll`:return{kind:`CutAll`,base:ZZ(e.base),tools:e.tools.map(ZZ),tolerance:e.tolerance};default:return}}function YZ(e){return e?KZ(e):void 0}function XZ(e){switch(e.kind){case`Translate`:return{kind:`Translate`,target:ZZ(e.target),vector:KZ(e.vector)};case`Rotate`:return{kind:`Rotate`,target:ZZ(e.target),angle:KZ(e.angle),axis:YZ(e.axis),at:YZ(e.at)};case`Scale`:return{kind:`Scale`,target:ZZ(e.target),factor:KZ(e.factor),center:YZ(e.center)};case`Mirror`:return{kind:`Mirror`,target:ZZ(e.target),normal:YZ(e.normal),at:YZ(e.at)};default:return}}function ZZ(e){return e.kind===`Compound`?{kind:`Compound`,children:e.children.map(ZZ)}:qZ(e)??JZ(e)??XZ(e)}function QZ(e){return k(F(N.NULL_SHAPE_INPUT,`csg.fromJSON: ${e}`))}function $Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function eQ(e){return typeof e==`number`&&Number.isFinite(e)}function tQ(e){return typeof e==`string`}function nQ(e,t){if(!Array.isArray(e)||e.length!==3)return QZ(`${t}: expected Vec3 array`);let[n,r,i]=e;return!eQ(n)||!eQ(r)||!eQ(i)?QZ(`${t}: Vec3 contains non-number`):O([n,r,i])}function rQ(e,t){if(!Array.isArray(e)||e.length!==2)return QZ(`${t}: expected Vec2 array`);let[n,r]=e;return!eQ(n)||!eQ(r)?QZ(`${t}: Vec2 contains non-number`):O([n,r])}function iQ(e){if(!$Z(e))return QZ(`input is not an object`);let t=e.csgVersion;if(t!==1)return QZ(`unsupported csgVersion ${String(t)} (expected 1)`);let n=e.root;return fQ(n)}function aQ(e){if(!$Z(e))return QZ(`expression: not an object`);let t=e.kind;switch(t){case`NumLit`:return eQ(e.value)?O(lX(e.value)):QZ(`NumLit.value`);case`Vec3Lit`:{let t=nQ(e.value,`Vec3Lit.value`);return t.ok?O(uX(t.value)):t}case`Vec2Lit`:{let t=rQ(e.value,`Vec2Lit.value`);return t.ok?O(dX(t.value)):t}case`Param`:return tQ(e.name)?O(fX(e.name)):QZ(`Param.name`);case`BinOp`:return oQ(e);case`UnaryOp`:return sQ(e);case`Component`:return cQ(e);case`BuildVec`:return lQ(e);default:return QZ(`unknown expression kind: ${String(t)}`)}}function oQ(e){let t=e.op;if(t!==`+`&&t!==`-`&&t!==`*`&&t!==`/`)return QZ(`BinOp.op: ${String(t)}`);let n=aQ(e.a);if(!n.ok)return n;let r=aQ(e.b);return r.ok?O(pX(t,n.value,r.value)):r}function sQ(e){let t=e.op;if(!tQ(t)||![`neg`,`sin`,`cos`,`sqrt`,`abs`].includes(t))return QZ(`UnaryOp.op: ${String(t)}`);let n=aQ(e.arg);return n.ok?O(mX(t,n.value)):n}function cQ(e){let t=e.index;if(t!==0&&t!==1&&t!==2)return QZ(`Component.index: ${String(t)}`);let n=aQ(e.vec);return n.ok?O(hX(n.value,t)):n}function lQ(e){let t=e.dim;if(t!==2&&t!==3)return QZ(`BuildVec.dim: ${String(t)}`);let n=e.components;if(!Array.isArray(n))return QZ(`BuildVec.components: not array`);if(n.length!==t)return QZ(`BuildVec.components: expected ${t} components, got ${n.length}`);let r=[];for(let e of n){let t=aQ(e);if(!t.ok)return t;r.push(t.value)}return O(gX(t,r))}function uQ(e,t){if(!Array.isArray(e))return QZ(`${t}: not array`);let n=[];for(let t of e){let e=fQ(t);if(!e.ok)return e;n.push(e.value)}return O(n)}function dQ(e){let t=e.tolerance;return t==null?O(void 0):eQ(t)?O(t):QZ(`tolerance: not a finite number`)}function fQ(e){if(!$Z(e))return QZ(`node: not an object`);let t=e.kind;switch(t){case`Box`:case`Sphere`:case`Cylinder`:case`Cone`:case`Torus`:case`Polygon`:case`Circle`:case`Line`:case`Vertex`:case`Empty`:return mQ(t,e);case`Fuse`:case`Cut`:case`Intersect`:return SQ(t,e);case`FuseAll`:case`CutAll`:return CQ(t,e);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return wQ(t,e);case`Compound`:return AQ(e);default:return QZ(`unknown node kind: ${String(t)}`)}}function pQ(e,t,n){let r=aQ(e[t]);return r.ok?O(n(r.value)):r}function mQ(e,t){switch(e){case`Box`:return hQ(t);case`Sphere`:return pQ(t,`radius`,HX);case`Cylinder`:return gQ(t);case`Cone`:return _Q(t);case`Torus`:return vQ(t);case`Polygon`:return yQ(t);case`Circle`:return pQ(t,`radius`,qX);case`Line`:return bQ(t);case`Vertex`:return pQ(t,`point`,YX);case`Empty`:return xQ(t)}return QZ(`unhandled primitive: ${e}`)}function hQ(e){let t=aQ(e.x);if(!t.ok)return t;let n=aQ(e.y);if(!n.ok)return n;let r=aQ(e.z);return r.ok?O(VX(t.value,n.value,r.value)):r}function gQ(e){let t=aQ(e.radius);if(!t.ok)return t;let n=aQ(e.height);return n.ok?O(UX(t.value,n.value)):n}function _Q(e){let t=aQ(e.radius1);if(!t.ok)return t;let n=aQ(e.radius2);if(!n.ok)return n;let r=aQ(e.height);return r.ok?O(WX(t.value,n.value,r.value)):r}function vQ(e){let t=aQ(e.majorRadius);if(!t.ok)return t;let n=aQ(e.minorRadius);return n.ok?O(GX(t.value,n.value)):n}function yQ(e){let t=e.points;if(!Array.isArray(t))return QZ(`Polygon.points: not array`);let n=[];for(let e of t){let t=aQ(e);if(!t.ok)return t;n.push(t.value)}return O(KX(n))}function bQ(e){let t=aQ(e.from);if(!t.ok)return t;let n=aQ(e.to);return n.ok?O(JX(t.value,n.value)):n}function xQ(e){let t=e.output;switch(t){case`Solid`:return O(ZX());case`Face`:return O(QX());case`Wire`:return O($X());default:return QZ(`Empty.output: ${String(t)}`)}}function SQ(e,t){let n=fQ(t.a);if(!n.ok)return n;let r=fQ(t.b);if(!r.ok)return r;let i=dQ(t);if(!i.ok)return i;switch(e){case`Fuse`:return O(tZ(n.value,r.value,i.value));case`Cut`:return O(nZ(n.value,r.value,i.value));case`Intersect`:return O(rZ(n.value,r.value,i.value))}}function CQ(e,t){let n=dQ(t);if(!n.ok)return n;if(e===`FuseAll`){let e=uQ(t.shapes,`FuseAll.shapes`);return e.ok?O(iZ(e.value,n.value)):e}let r=fQ(t.base);if(!r.ok)return r;let i=uQ(t.tools,`CutAll.tools`);return i.ok?O(aZ(r.value,i.value,n.value)):i}function wQ(e,t){let n=fQ(t.target);if(!n.ok)return n;switch(e){case`Translate`:return TQ(t,n.value);case`Rotate`:return DQ(t,n.value);case`Scale`:return OQ(t,n.value);case`Mirror`:return kQ(t,n.value)}}function TQ(e,t){let n=aQ(e.vector);return n.ok?O(sZ(t,n.value)):n}function EQ(e,t){if(e[t]===void 0)return O(void 0);let n=aQ(e[t]);return n.ok?O(n.value):n}function DQ(e,t){let n=aQ(e.angle);if(!n.ok)return n;let r=EQ(e,`axis`);if(!r.ok)return r;let i=EQ(e,`at`);return i.ok?O(cZ(t,n.value,{axis:r.value,at:i.value})):i}function OQ(e,t){let n=aQ(e.factor);if(!n.ok)return n;let r=EQ(e,`center`);return r.ok?O(lZ(t,n.value,{center:r.value})):r}function kQ(e,t){let n=EQ(e,`normal`);if(!n.ok)return n;let r=EQ(e,`at`);return r.ok?O(uZ(t,{normal:n.value,at:r.value})):r}function AQ(e){let t=uQ(e.children,`Compound.children`);return t.ok?O(dZ(t.value)):t}function jQ(e){return PQ(e)}function MQ(e){switch(e.kind){case`NumLit`:case`Vec3Lit`:case`Vec2Lit`:case`Param`:return e;case`BinOp`:{let t=MQ(e.a),n=MQ(e.b);if(t.kind===`NumLit`&&n.kind===`NumLit`)switch(e.op){case`+`:return lX(t.value+n.value);case`-`:return lX(t.value-n.value);case`*`:return lX(t.value*n.value);case`/`:return lX(t.value/n.value)}return t!==e.a||n!==e.b?pX(e.op,t,n):e}case`UnaryOp`:{let t=MQ(e.arg);if(t.kind===`NumLit`){let n=t.value;switch(e.op){case`neg`:return lX(-n);case`sin`:return lX(Math.sin(n));case`cos`:return lX(Math.cos(n));case`sqrt`:return lX(Math.sqrt(n));case`abs`:return lX(Math.abs(n))}}return t===e.arg?e:mX(e.op,t)}case`Component`:{let t=MQ(e.vec);return t.kind===`Vec3Lit`||t.kind===`Vec2Lit`&&(e.index===0||e.index===1)?lX(t.value[e.index]):t===e.vec?e:hX(t,e.index)}case`BuildVec`:{let t=e.components.map(MQ);return NQ(e.dim,t)||(t.some((t,n)=>t!==e.components[n])?gX(e.dim,t):e)}}}function NQ(e,t){if(t.length!==e)return;let n=[];for(let e of t){if(e.kind!==`NumLit`)return;n.push(e.value)}return e===2?dX([n[0],n[1]]):uX([n[0],n[1],n[2]])}function PQ(e){switch(e.kind){case`Box`:return VX(MQ(e.x),MQ(e.y),MQ(e.z));case`Sphere`:return HX(MQ(e.radius));case`Cylinder`:return UX(MQ(e.radius),MQ(e.height));case`Cone`:return WX(MQ(e.radius1),MQ(e.radius2),MQ(e.height));case`Torus`:return GX(MQ(e.majorRadius),MQ(e.minorRadius));case`Polygon`:return KX(e.points.map(MQ));case`Circle`:return qX(MQ(e.radius));case`Line`:return JX(MQ(e.from),MQ(e.to));case`Vertex`:return YX(MQ(e.point));case`Empty`:return e;case`Fuse`:return FQ(e.a,e.b,e.tolerance);case`Cut`:return IQ(e.a,e.b,e.tolerance);case`Intersect`:return LQ(e.a,e.b,e.tolerance);case`FuseAll`:return RQ(e.shapes,e.tolerance);case`CutAll`:return zQ(e.base,e.tools,e.tolerance);case`Translate`:return BQ(e.target,e.vector);case`Rotate`:return cZ(PQ(e.target),MQ(e.angle),{axis:e.axis?MQ(e.axis):void 0,at:e.at?MQ(e.at):void 0});case`Scale`:return lZ(PQ(e.target),MQ(e.factor),{center:e.center?MQ(e.center):void 0});case`Mirror`:return uZ(PQ(e.target),{normal:e.normal?MQ(e.normal):void 0,at:e.at?MQ(e.at):void 0});case`Compound`:return dZ(e.children.map(PQ).filter(e=>e.kind!==`Empty`))}}function FQ(e,t,n){let r=PQ(e),i=PQ(t);return r.kind===`Empty`?i:i.kind===`Empty`?r:tZ(r,i,n)}function IQ(e,t,n){let r=PQ(e),i=PQ(t);return i.kind===`Empty`||r.kind===`Empty`?r:nZ(r,i,n)}function LQ(e,t,n){let r=PQ(e),i=PQ(t);return r.kind===`Empty`?r:i.kind===`Empty`?i:rZ(r,i,n)}function RQ(e,t){let n=e.map(PQ).filter(e=>e.kind!==`Empty`);return n.length===0?ZX():n.length===1?n[0]:iZ(n,t)}function zQ(e,t,n){let r=PQ(e);if(r.kind===`Empty`)return r;let i=t.map(PQ).filter(e=>e.kind!==`Empty`);return i.length===0?r:aZ(r,i,n)}function BQ(e,t){let n=PQ(e),r=MQ(t);if(r.kind!==`Vec3Lit`)return sZ(n,r);let[i,a,o]=r.value;if(i===0&&a===0&&o===0)return n;if(n.kind===`Translate`){let e=MQ(n.vector);if(e.kind===`Vec3Lit`)return sZ(n.target,[e.value[0]+i,e.value[1]+a,e.value[2]+o])}return sZ(n,r)}function VQ(e,t,n){return HQ(e,t,n)}function HQ(e,t,n){return t(e)?n:UQ(e,t,n)}function UQ(e,t,n){switch(e.kind){case`Box`:case`Sphere`:case`Cylinder`:case`Cone`:case`Torus`:case`Polygon`:case`Circle`:case`Line`:case`Vertex`:case`Empty`:return e;case`Fuse`:return tZ(HQ(e.a,t,n),HQ(e.b,t,n),e.tolerance);case`Cut`:return nZ(HQ(e.a,t,n),HQ(e.b,t,n),e.tolerance);case`Intersect`:return rZ(HQ(e.a,t,n),HQ(e.b,t,n),e.tolerance);case`FuseAll`:return iZ(e.shapes.map(e=>HQ(e,t,n)),e.tolerance);case`CutAll`:return aZ(HQ(e.base,t,n),e.tools.map(e=>HQ(e,t,n)),e.tolerance);case`Translate`:return sZ(HQ(e.target,t,n),e.vector);case`Rotate`:return cZ(HQ(e.target,t,n),e.angle,{axis:e.axis,at:e.at});case`Scale`:return lZ(HQ(e.target,t,n),e.factor,{center:e.center});case`Mirror`:return uZ(HQ(e.target,t,n),{normal:e.normal,at:e.at});case`Compound`:return dZ(e.children.map(e=>HQ(e,t,n)))}}function WQ(e,t){t(e);for(let n of GQ(e))WQ(n,t)}function GQ(e){switch(e.kind){case`Box`:case`Sphere`:case`Cylinder`:case`Cone`:case`Torus`:case`Polygon`:case`Circle`:case`Line`:case`Vertex`:case`Empty`:return[];case`Fuse`:case`Cut`:case`Intersect`:return[e.a,e.b];case`FuseAll`:return e.shapes;case`CutAll`:return[e.base,...e.tools];case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return[e.target];case`Compound`:return e.children}}function KQ(e){let t=0;return WQ(e,()=>{t++}),t}var qQ=CG({CSG_VERSION:()=>1,Evaluator:()=>UZ,add:()=>_X,asScalarExpr:()=>yX,asVec2Expr:()=>SX,asVec3Expr:()=>xX,binOp:()=>pX,box:()=>VX,buildVec:()=>gX,circle:()=>qX,component:()=>hX,compound:()=>dZ,cone:()=>WX,cut:()=>nZ,cutAll:()=>aZ,cylinder:()=>UX,emptyFace:()=>QX,emptySolid:()=>ZX,emptyWire:()=>$X,foldExpr:()=>MQ,forEachNode:()=>WQ,fromJSON:()=>iQ,fuse:()=>tZ,fuseAll:()=>iZ,intersect:()=>rZ,line:()=>JX,mirror:()=>uZ,mul:()=>vX,nodeCount:()=>KQ,numLit:()=>lX,optimize:()=>jQ,outputKindOf:()=>fZ,param:()=>fX,polygon:()=>KX,replaceNode:()=>VQ,rotate:()=>cZ,scale:()=>lZ,sphere:()=>HX,toJSON:()=>GZ,torus:()=>GX,translate:()=>sZ,unaryOp:()=>mX,vec2Lit:()=>dX,vec3Lit:()=>uX,vertex:()=>YX,withEvaluator:()=>WZ});export{LM as BaseSketcher2d,RM as BlueprintSketcher,Na as BrepBugError,N as BrepErrorCode,OJ as BrepWrapperError,Kv as BrepkitAdapter,kV as CompoundSketch,Gw as DEG2RAD,SC as DisposalScope,uH as FaceSketcher,G as HASH_CODE_MAX,la as OK,ca as OcctWasmAdapter,Kw as RAD2DEG,qV as Sketch,lH as Sketcher,JV as Sketches,aA as addChild,Qk as addHoles,pq as addMate,pA as addStep,AO as adjacentFaces,va as all,pa as andThen,EG as applyGlue,Gq as applyMatrix,QE as approximateCurve,MC as as2D,jC as as3D,CT as asTopo,eG as assignRoles,Sk as autoHeal,zk as bezier,oW as blueprintToDXF,aO as booleanPipeline,LY as booleans,TJ as boss,Ek as box,Rk as bsplineApprox,M as bug,oH as cameraFromPlane,aH as cameraLookAt,ZW as captureHint,OT as cast,W as castShape,pw as castShape3D,iJ as chamfer,SO as chamferDistAngleShape,ek as chamferWithEvolution,gq as checkAllInterferences,GO as checkBoolean,hq as checkInterference,Nk as circle,rA as circularPattern,HT as classifyPointOnFace,cD as clearMeshCache,Wq as clone,VC as closedWire,ka as collect,dA as collectShapes,hE as colorFaces,mE as colorShape,IN as complexExtrude,jE as composeTransforms,Jk as compound,WV as compoundSketchExtrude,HV as compoundSketchFace,KV as compoundSketchLoft,GV as compoundSketchRevolve,Ha as computationError,$K as computeStraightSkeleton,kk as cone,UY as construction,NK as convexHull,UM as cornerFinder,uA as countNodes,eA as createAssembly,iA as createAssemblyNode,SU as createBlueprint,iH as createCamera,rw as createCompound,CU as createCompoundBlueprint,BA as createDistanceQuery,ZC as createEdge,$C as createFace,bC as createHandle,fA as createHistory,xC as createKernelHandle,lD as createMeshCache,gT as createNamedPlane,yG as createOperationRegistry,mT as createPlane,tG as createRef,bA as createRegistry,ew as createShell,tw as createSolid,dG as createTaskQueue,XC as createVertex,QC as createWire,vG as createWorkerClient,xG as createWorkerHandler,qQ as csg,mU as curve2dBoundingBox,xU as curve2dDistanceFrom,hU as curve2dFirstPoint,bU as curve2dIsOnCurve,gU as curve2dLastPoint,vU as curve2dParameter,_U as curve2dSplitAt,yU as curve2dTangentAt,HE as curveEndPoint,KE as curveIsClosed,qE as curveIsPeriodic,GE as curveLength,JE as curvePeriod,UE as curvePointAt,VE as curveStartPoint,WE as curveTangentAt,Jq as cut,kN as cut2D,JD as cutAll,IO as cutAllBisect,vN as cutBlueprints,ZO as cutWithEvolution,Dk as cylinder,XW as defaultScorer,pG as dequeueTask,pJ as describe,VH as deserializeDrawing,EA as deserializeHistory,AT as deserializeShape,DT as downcast,cJ as draft,UH as draw,JH as drawCircle,YH as drawEllipse,nU as drawFaceOutline,$H as drawParametricFunction,QH as drawPointsInterpolation,XH as drawPolysides,tU as drawProjection,GH as drawRectangle,WH as drawRoundedRectangle,KH as drawSingleCircle,qH as drawSingleEllipse,ZH as drawText,cU as drawingChamfer,aU as drawingCut,sU as drawingFillet,iU as drawingFuse,oU as drawingIntersect,rU as drawingToSketchOnPlane,CJ as drill,pj as edgeFinder,DO as edgesOfFace,Pk as ellipse,Lk as ellipseArc,jk as ellipsoid,fG as enqueueTask,k as err,tA as exportAssemblySTEP,aW as exportDXF,KU as exportGlb,GU as exportGltf,_D as exportIGES,LU as exportOBJ,hD as exportSTEP,UW as exportSTEPConfigured,gD as exportSTL,TW as exportThreeMF,vJ as extrude,WN as extrudeAll,Uk as face,VT as faceCenter,gj as faceFinder,NT as faceGeomType,PT as faceOrientation,EO as facesOfEdge,ID as fill,Wk as filledFace,rJ as fillet,$O as filletWithEvolution,rE as findFacesByTag,cA as findNode,hA as findStep,Tk as fixSelfIntersection,Ck as fixShape,ma as flatMap,xa as flatten,FT as flipFaceOrientation,XE as flipOrientation,YW as fontMetrics,hJ as fromBREP,bK as fromKernelDir,yK as fromKernelPnt,vK as fromKernelVec,Ca as fromNullable,qq as fuse,DN as fuse2D,qD as fuseAll,BO as fuseAllBisect,_N as fuseBlueprints,XO as fuseWithEvolution,QJ as gearGeometry,RG as getActiveVoxelId,zw as getBounds,wU as getBounds2D,jw as getCompSolids,BE as getCurveType,mC as getDisposalStats,Tw as getEdges,_E as getFaceColor,qT as getFaceOrigins,iE as getFaceTags,Ew as getFaces,ZV as getFont,FE as getHashCode,gA as getHistoryShape,U as getKernel,MO as getNurbsCurveData,NO as getNurbsSurfaceData,YE as getOrientation,TU as getOrientation2D,$a as getPerformanceStats,gE as getShapeColor,IC as getShapeKind,Aw as getShells,yj as getSingleFace,kw as getSolids,MT as getSurfaceType,oE as getTagMetadata,Ow as getVertices,LG as getVoxel,Dw as getWires,VN as guidedSweep,lJ as heal,yk as healFace,vk as healSolid,bk as healWire,Fk as helix,MK as hull,xq as importDXF,Rq as importGLB,KW as importIGES,Tq as importOBJ,WW as importSTEP,GW as importSTL,HW as importSVG,VW as importSVGPathD,Lq as importThreeMF,lC as init,nC as initFromManifold,sC as initFromOC,zG as initVoxel,GT as innerWires,ZE as interpolateCurve,Yq as intersect,AN as intersect2D,yN as intersectBlueprints,QO as intersectWithEvolution,ww as invalidateShapeCache,VY as io,Ua as ioError,AC as is2D,kC as is3D,OG as isChamferRadius,LC as isClosedWire,kT as isCompSolid,uw as isCompound,cG as isDisposeRequest,aw as isEdge,_J as isEmpty,RE as isEqualShape,A as isErr,uG as isErrorResponse,sw as isFace,kG as isFilletRadius,oG as isInitRequest,EU as isInside2D,OC as isLive,zC as isManifoldShell,DG as isNumber,ua as isOk,sG as isOperationRequest,RC as isOrientedFace,GC as isPlanarFace,KC as isPlanarWire,tH as isProjectionPlane,hG as isQueueEmpty,LE as isSameShape,fw as isShape1D,dw as isShape3D,cw as isShell,lw as isSolid,lG as isSuccessResponse,gJ as isValid,BC as isValidSolid,iw as isVertex,ow as isWire,Rw as iterCompSolids,Mw as iterEdges,Nw as iterFaces,Lw as iterShells,Iw as iterSolids,TT as iterTopo,Fw as iterVertices,Pw as iterWires,_w as kernelCall,vw as kernelCallRaw,yw as kernelCallScoped,P as kernelError,fK as latticeInfill,pK as latticeInfillShape,Mk as line,nA as linearPattern,XV as loadFont,bJ as loft,OV as loftAll,bH as makeBaseBox,xY as makeExternalGear,SY as makeInternalGear,vT as makePlane,wY as makePlanetaryGear,rH as makeProjectedEdges,UC as manifoldShell,da as map,Sa as mapBoth,fa as mapErr,Oa as match,IA as measureArea,VA as measureCurvatureAt,HA as measureCurvatureAtMid,RA as measureDistance,zA as measureDistanceProps,LA as measureLength,PA as measureLinearProps,NA as measureSurfaceProps,FA as measureVolume,MA as measureVolumeProps,BY as measurement,dJ as mesh,fJ as meshEdges,vD as meshMultiLOD,LK as minkowski,Hq as mirror,jU as mirror2D,fU as mirrorDrawing,EJ as mirrorJoin,RY as modifiers,wA as modifyStep,Va as moduleInitError,BN as multiSectionSweep,BT as normalAt,oJ as offset,Xk as offsetFace,tK as offsetMesh,iK as offsetShape,$E as offsetWire2D,O as ok,ha as or,ga as orElse,DM as organiseBlueprints,HC as orientedFace,UT as outerWire,WY as patterns,mG as pendingCount,Ma as pipeline,xT as pivotPlane,qC as planarFace,JC as planarWire,gY as planetPlacements,wJ as pocket,LT as pointOnSurface,WG as pointsInside,Kk as polygon,RK as polyhedron,gH as polysideInnerRadius,WM as polysidesBlueprint,nk as positionOnCurve,cC as prewarm,IY as primitives,sH as projectEdges,zT as projectPointOnFace,HY as query,Wa as queryError,DJ as rectangularPattern,bG as registerHandler,rC as registerKernel,xA as registerOperation,yA as registerShape,IG as registerVoxel,gG as rejectAll,oA as removeChild,WT as removeHolesFromFace,qG as repairMesh,CA as replayFrom,SA as replayHistory,hC as resetDisposalStats,eo as resetPerformanceStats,EE as resize,$ as resolve,zq as resolve3D,Xw as resolveDirection,_T as resolvePlane,aG as resolveRef,pU as reverseCurve,yJ as revolve,sq as roof,Vq as rotate,kU as rotate2D,uU as rotateDrawing,GM as roundedRectangleBlueprint,Uq as scale,AU as scale2D,dU as scaleDrawing,Xq as section,Zq as sectionToFace,TA as serializeHistory,KT as setShapeOrigin,aE as setTagMetadata,Zk as sewShells,KJ as shape,YG as shapeToMeshInput,ET as shapeType,jO as sharedEdges,aJ as shell,nK as shellMesh,aK as shellShape,tk as shellWithEvolution,uJ as simplify,dH as sketchCircle,fH as sketchEllipse,FV as sketchExtrude,MV as sketchFace,_H as sketchFaceOffset,yH as sketchHelix,LV as sketchLoft,PU as sketchOnFace2D,NU as sketchOnPlane2D,vH as sketchParametricFunction,hH as sketchPolysides,pH as sketchRectangle,PV as sketchRevolve,mH as sketchRoundedRectangle,IV as sketchSweep,qW as sketchText,NV as sketchWires,Ba as sketcherStateError,$q as slice,Yk as solid,wk as solidFromShell,mq as solveAssembly,Ok as sphere,Qq as split,_A as stepCount,vA as stepsFrom,MU as stretch2D,Gk as subFace,FN as supportExtrude,QS as supportsConstraintSketch,ZS as supportsProjection,DK as surfaceFromGrid,AK as surfaceFromImage,PN as sweep,nE as tagFaces,Bk as tangentArc,ya as tap,ba as tapErr,$V as textBlueprints,JW as textMetrics,sJ as thicken,Ik as threePointArc,mJ as toBREP,vO as toBufferGeometryData,yO as toGroupedBufferGeometryData,hK as toKernelVec,xO as toLODGeometryData,bO as toLineGeometryData,DU as toSVGPathD,Jw as toVec2,qw as toVec3,Ak as torus,mK as tpmsLattice,Kq as transformCopy,zY as transforms,Bq as translate,OU as translate2D,lU as translateDrawing,bT as translatePlane,Aa as tryCatch,ja as tryCatchAsync,LN as twistExtrude,za as typeCastError,mA as undoLast,Ga as unsupportedError,j as unwrap,Da as unwrapErr,Ta as unwrapOr,Ea as unwrapOrElse,sA as updateNode,nG as updateRoles,IT as uvBounds,RT as uvCoordinates,WC as validSolid,rY as validatePlanetary,F as validationError,gk as variableFillet,Zw as vecAdd,lT as vecAngle,nT as vecCross,aT as vecDistance,tT as vecDot,sT as vecEquals,cT as vecIsZero,rT as vecLength,iT as vecLengthSq,eT as vecNegate,oT as vecNormalize,uT as vecProjectToPlane,pT as vecRepr,dT as vecRotate,$w as vecScale,Qw as vecSub,qk as vertex,MG as vertexFinder,Ww as vertexPosition,kO as verticesOfEdge,rK as voxelBoolean,oK as voxelBooleanShapes,lA as walkAssembly,UG as windingNumbers,Vk as wire,vj as wireFinder,Hk as wireLoop,OO as wiresOfFace,oC as withKernel,CK as withKernelDir,SK as withKernelPnt,xK as withKernelVec,CC as withScope,EC as withScopeResult,DC as withScopeResultAsync,_a as zipResults};
|
|
56
|
+
</Relationships>`),c(`3D/3dmodel.model`,s)])}function TW(e){let t=[],n=/([MmLlHhVvCcSsQqTtAaZz])([^MmLlHhVvCcSsQqTtAaZz]*)/g,r;for(;(r=n.exec(e))!==null;){let e=r[1]??``,n=(r[2]??``).trim(),i=[];if(n){let e=/[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/g,t;for(;(t=e.exec(n))!==null;)i.push(parseFloat(t[0]))}t.push({command:e,args:i})}return t}function EW(e){return[e[0],-e[1]]}function DW(e,t,n,r){let i=0;for(;i<e.length;){let a=(n?t.cx:0)+(e[i]??0),o=(n?t.cy:0)+(e[i+1]??0);i===0?(t.sx=a,t.sy=o):r.push(Mj(EW([t.cx,t.cy]),EW([a,o]))),t.cx=a,t.cy=o,i+=2}}function OW(e,t,n,r){let i=0;for(;i<e.length;){let a=(n?t.cx:0)+(e[i]??0),o=(n?t.cy:0)+(e[i+1]??0);r.push(Mj(EW([t.cx,t.cy]),EW([a,o]))),t.cx=a,t.cy=o,i+=2}}function kW(e,t,n,r){for(let i of e){let e=n?t.cx+i:i;r.push(Mj(EW([t.cx,t.cy]),EW([e,t.cy]))),t.cx=e}}function AW(e,t,n,r){for(let i of e){let e=n?t.cy+i:i;r.push(Mj(EW([t.cx,t.cy]),EW([t.cx,e]))),t.cy=e}}function jW(e,t,n,r){let i=0;for(;i+5<e.length;){let a=n?t.cx:0,o=n?t.cy:0,s=a+(e[i]??0),c=o+(e[i+1]??0),l=a+(e[i+2]??0),u=o+(e[i+3]??0),d=a+(e[i+4]??0),f=o+(e[i+5]??0);r.push(Rj(EW([t.cx,t.cy]),[EW([s,c]),EW([l,u])],EW([d,f]))),t.prevControlX=l,t.prevControlY=u,t.cx=d,t.cy=f,i+=6}}function MW(e,t,n,r){let i=0;for(;i+3<e.length;){let a=n?t.cx:0,o=n?t.cy:0,s=t.lastCmd,c=s===`C`||s===`S`?2*t.cx-t.prevControlX:t.cx,l=s===`C`||s===`S`?2*t.cy-t.prevControlY:t.cy,u=a+(e[i]??0),d=o+(e[i+1]??0),f=a+(e[i+2]??0),p=o+(e[i+3]??0);r.push(Rj(EW([t.cx,t.cy]),[EW([c,l]),EW([u,d])],EW([f,p]))),t.prevControlX=u,t.prevControlY=d,t.cx=f,t.cy=p,t.lastCmd=`S`,i+=4}}function NW(e,t,n,r){let i=0;for(;i+3<e.length;){let a=n?t.cx:0,o=n?t.cy:0,s=a+(e[i]??0),c=o+(e[i+1]??0),l=a+(e[i+2]??0),u=o+(e[i+3]??0);r.push(Rj(EW([t.cx,t.cy]),[EW([s,c])],EW([l,u]))),t.prevControlX=s,t.prevControlY=c,t.cx=l,t.cy=u,i+=4}}function PW(e,t,n,r){let i=0;for(;i+1<e.length;){let a=n?t.cx:0,o=n?t.cy:0,s=t.lastCmd,c=s===`Q`||s===`T`?2*t.cx-t.prevControlX:t.cx,l=s===`Q`||s===`T`?2*t.cy-t.prevControlY:t.cy,u=a+(e[i]??0),d=o+(e[i+1]??0);r.push(Rj(EW([t.cx,t.cy]),[EW([c,l])],EW([u,d]))),t.prevControlX=c,t.prevControlY=l,t.cx=u,t.cy=d,t.lastCmd=`T`,i+=2}}function FW(e,t,n,r,i){let a=Math.max(n,r),o=i?1:-1,s=t+2*o*a,c=[e-o*a,t+o*a],l=[e+o*a,t+o*a];try{return[Nj(EW([e,t]),EW(c),EW([e,s])),Nj(EW([e,s]),EW(l),EW([e,t]))]}catch{return[]}}function IW(e,t,n,r,i,a,o,s){let c=.5,l=e+c*(n-e),u=t+c*(r-t),d=n-e,f=r-t,p=Math.sqrt(d*d+f*f),m=Math.max(i,a),h=p/2,g=h<m?m-Math.sqrt(m*m-h*h):m,_=(o===s?-1:1)*(s?1:-1),v=-f/p,y=d/p,b=l+_*g*v,x=u+_*g*y;try{return[Nj(EW([e,t]),EW([b,x]),EW([n,r]))]}catch{return[Mj(EW([e,t]),EW([n,r]))]}}function LW(e,t,n,r){let i=0;for(;i+6<e.length;){let a=n?t.cx:0,o=n?t.cy:0,s=Math.abs(e[i]??0),c=Math.abs(e[i+1]??0),l=(e[i+3]??0)!==0,u=(e[i+4]??0)!==0,d=a+(e[i+5]??0),f=o+(e[i+6]??0);if(s===0||c===0)r.push(Mj(EW([t.cx,t.cy]),EW([d,f])));else{let e=d-t.cx,n=f-t.cy;Math.sqrt(e*e+n*n)<1e-10?r.push(...FW(t.cx,t.cy,s,c,u)):r.push(...IW(t.cx,t.cy,d,f,s,c,l,u))}t.cx=d,t.cy=f,i+=7}}function RW(e,t){(Math.abs(e.cx-e.sx)>1e-10||Math.abs(e.cy-e.sy)>1e-10)&&t.push(Mj(EW([e.cx,e.cy]),EW([e.sx,e.sy]))),e.cx=e.sx,e.cy=e.sy}function zW(e){let t=TW(e),n=[],r={cx:0,cy:0,sx:0,sy:0,prevControlX:0,prevControlY:0,lastCmd:``};for(let{command:e,args:i}of t){let t=e===e.toLowerCase(),a=e.toUpperCase();switch(a){case`M`:DW(i,r,t,n);break;case`L`:OW(i,r,t,n);break;case`H`:kW(i,r,t,n);break;case`V`:AW(i,r,t,n);break;case`C`:jW(i,r,t,n);break;case`S`:MW(i,r,t,n);break;case`Q`:NW(i,r,t,n);break;case`T`:PW(i,r,t,n);break;case`A`:LW(i,r,t,n);break;case`Z`:RW(r,n);break}a!==`S`&&a!==`T`&&(r.lastCmd=a)}return n}function BW(e){try{let t=zW(e);return t.length===0?k(Ua(`SVG_EMPTY_PATH`,`SVG path produced no curves`)):O(new nM(t))}catch(e){return k(Ua(`SVG_PARSE_FAILED`,`Failed to parse SVG path: ${e instanceof Error?e.message:String(e)}`))}}function VW(e){try{let t=/\bd\s*=\s*(?:"([^"]*)"|'([^']*)')/,n=[],r=e.toLowerCase(),i=0;for(;i<r.length;){let a=r.indexOf(`<path `,i);if(a===-1)break;let o=e.indexOf(`>`,a);if(o===-1)break;let s=e.slice(a,o+1);i=o+1;let c=t.exec(s),l=c?.[1]??c?.[2];if(!l)continue;let u=BW(l);u.ok&&n.push(u.value)}return n.length===0?k(Ua(`SVG_NO_PATHS`,`No <path> elements found in SVG`)):O(n)}catch(e){return k(Ua(`SVG_IMPORT_FAILED`,`Failed to import SVG: ${e instanceof Error?e.message:String(e)}`))}}function HW(e,t){try{let n=U(),r=e.map(e=>({shape:e.shape.wrapped,name:e.name,color:e.color?[...e.color]:void 0}));return O(n.exportSTEPConfigured(r,t))}catch(e){return k(Ua(N.STEP_EXPORT_CONFIGURED_FAILED,`Configured STEP export failed`,e))}}async function UW(e){try{let t=await e.arrayBuffer(),n=U().importSTEP(t);return n.length===0?k(Ua(`STEP_IMPORT_FAILED`,`STEP file contains no valid geometry`)):O(W(n[0]))}catch{return k(Ua(`STEP_IMPORT_FAILED`,`Failed to load STEP file`))}}async function WW(e){try{let t=await e.arrayBuffer(),n=U().importSTL(t);return n.IsNull()?k(Ua(`STL_IMPORT_FAILED`,`Failed to create solid from STL mesh`)):O(W(n))}catch{return k(Ua(`STL_IMPORT_FAILED`,`Failed to load STL file`))}}async function GW(e){try{let t=await e.arrayBuffer(),n=U().importIGES(t);return n.length===0?k(Ua(`IGES_IMPORT_FAILED`,`IGES file contains no valid geometry`)):O(W(n[0]))}catch{return k(Ua(`IGES_IMPORT_FAILED`,`Failed to load IGES file`))}}function KW(e,t,n={}){let r=QV(e,t);return new qV((typeof n.plane==`string`||n.plane===void 0?r.sketchOnPlane(n.plane,n.origin):r.sketchOnPlane(n.plane)).map(e=>Array.isArray(e)?new OV(e.map(kV)):kV(e)))}function qW(e,t){let n=t?.fontSize??1,r=XV(t?.fontFamily);if(!r)return k(F(N.NO_FONT_LOADED,`No font loaded. Call loadFont() first.`,void 0,void 0,`Load a font with loadFont() before calling textMetrics()`));let i=r.getAdvanceWidth(e,n),a=n/r.unitsPerEm,o=r.ascender*a,s=r.descender*a;return O({width:i,height:o-s,ascender:o,descender:s})}function JW(e){let t=e?.fontSize??1,n=XV(e?.fontFamily);if(!n)return k(F(N.NO_FONT_LOADED,`No font loaded. Call loadFont() first.`,void 0,void 0,`Load a font with loadFont() before calling fontMetrics()`));let r=t/n.unitsPerEm,i=n.ascender*r,a=n.descender*r,o=(n.tables?.os2?.sTypoLineGap??0)*r;return O({ascender:i,descender:a,unitsPerEm:n.unitsPerEm,lineHeight:i-a+o})}function YW(e,t){let n=0,r=MT(t);if(e.surfaceType!==void 0)if(r===e.surfaceType)n+=1;else return-1/0;if(e.normal!==void 0){let r=zT(t),i=e.normal[0]*r[0]+e.normal[1]*r[1]+e.normal[2]*r[2];if(i<.707)return-1/0;n+=i}if(e.centroid!==void 0){let r=BT(t),i=e.centroid[0]-r[0],a=e.centroid[1]-r[1],o=e.centroid[2]-r[2],s=i*i+a*a+o*o;if(s>100)return-1/0;n-=s/100}if(e.area!==void 0&&e.area>0){let r=FA(t);if(r.ok&&r.value>0){let t=Math.abs(Math.log(e.area/r.value));t>1&&(n-=t)}}return n}function XW(e){let t=MT(e),n=zT(e),r=BT(e),i=FA(e);return{entityType:`face`,surfaceType:t,normal:n,centroid:r,area:i.ok?i.value:void 0}}var ZW=.9;function QW(e){if(e[2]>ZW)return`box:top`;if(e[2]<-.9)return`box:bottom`;if(e[1]>ZW)return`box:back`;if(e[1]<-.9)return`box:front`;if(e[0]>ZW)return`box:right`;if(e[0]<-.9)return`box:left`}function $W(e,t){let n=Tw(e),r=new Map;if(t===`box`){for(let e of n){let t=QW(zT(e));t!==void 0&&!r.has(t)&&r.set(t,PE(e))}return r}let i=0;for(let e of n)r.set(`${t}:face_${i}`,PE(e)),i++;return r}function eG(e,t,n){return{origin:e,role:t,hint:XW(n)}}function tG(e,n,r){let i=e.get(n);if(!i)return e;let a=new Map;for(let[e,n]of i){if(r.deleted.has(n))continue;let i=r.modified.get(n);i&&i.length>0?a.set(e,t(i,0)):a.set(e,n)}let o=new Map;for(let[t,r]of e)t===n?o.set(t,a):o.set(t,r);return o}var nG=.1,rG=.5;function iG(e,t,n,r){let i=Tw(n),a=r??YW,o=t.get(e.origin)?.get(e.role);if(o!==void 0){for(let e of i)if(PE(e)===o)return{face:e,confidence:`exact`};return{ref:e,reason:`deleted`}}let s=-1/0,c,l=-1/0,u=[];for(let t of i){let n=a(e.hint,t);n>rG&&u.push([t,n]),n>s?(l=s,s=n,c=t):n>l&&(l=n)}return c!==void 0&&s>rG?s-l<nG&&u.length>1?{ref:e,reason:`ambiguous`,candidates:u.filter(([,e])=>e>=s-nG).map(([e])=>e)}:{face:c,confidence:`geometric-fallback`}:{ref:e,reason:`not-found`}}function aG(e){return e.type===`init`}function oG(e){return e.type===`operation`}function sG(e){return e.type===`dispose`}function cG(e){return e.success}function lG(e){return!e.success}function uG(){return{pending:new Map}}function dG(e,t){let n=new Map(e.pending);return n.set(t.id,t),{pending:n}}function fG(e,t){let n=e.pending.get(t);if(!n)return{queue:e,task:void 0};let r=new Map(e.pending);return r.delete(t),{queue:{pending:r},task:n}}function pG(e){return e.pending.size}function mG(e){return e.pending.size===0}function hG(e,t){for(let n of e.pending.values())n.reject(t);return{pending:new Map}}function gG(e,t){let n=t.data,r=e.get(n.id);if(r)if(e.delete(n.id),cG(n)){let e={};n.resultBrep!==void 0&&(e.resultBrep=n.resultBrep),n.resultData!==void 0&&(e.resultData=n.resultData),r.resolve(e)}else r.reject(Error(n.error))}function _G(e){let{worker:t,wasmUrl:n}=e,r=new Map,i=!1;function a(){return crypto.randomUUID()}function o(e){gG(r,e)}t.addEventListener(`message`,o);function s(e){return i?Promise.reject(Error(`WorkerClient has been disposed`)):new Promise((n,i)=>{r.set(e.id,{resolve:n,reject:i}),t.postMessage(e)})}return{async init(){await s({id:a(),type:`init`,...n===void 0?{}:{wasmUrl:n}})},async execute(e,t,n){return s({id:a(),type:`operation`,operation:e,shapesBrep:t,parameters:n})},dispose(){i=!0;for(let e of r.values())e.reject(Error(`WorkerClient disposed`));r.clear(),t.removeEventListener(`message`,o);let e={id:a(),type:`dispose`};t.postMessage(e)}}}function vG(){return{operations:new Map}}function yG(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function bG(e,t){let n=globalThis;n.onmessage=async r=>{let i=r.data;if(aG(i)){try{await t(i.wasmUrl);let e={id:i.id,success:!0};n.postMessage(e)}catch(e){let t={id:i.id,success:!1,error:e instanceof Error?e.message:String(e)};n.postMessage(t)}return}if(oG(i)){let t=e.operations.get(i.operation);if(!t){let e={id:i.id,success:!1,error:`Unknown operation: ${i.operation}`};n.postMessage(e);return}try{let e=t(i.shapesBrep,i.parameters),r={id:i.id,success:!0,...e.resultBrep===void 0?{}:{resultBrep:e.resultBrep},...e.resultData===void 0?{}:{resultData:e.resultData}};n.postMessage(r)}catch(e){let t={id:i.id,success:!1,error:e instanceof Error?e.message:String(e)};n.postMessage(t)}return}if(sG(i)){let e={id:i.id,success:!0};n.postMessage(e),n.close?.()}}}var xG=Object.defineProperty,SG=(e,t)=>{let n={};for(var r in e)xG(n,r,{get:e[r],enumerable:!0});return t||xG(n,Symbol.toStringTag,{value:`Module`}),n},CG=1,wG=2;function TG(e,t){t===`commonFace`&&e.SetGlue(CG),t===`sameFace`&&e.SetGlue(wG)}function EG(e){return typeof e==`number`}function DG(e){if(typeof e==`number`)return!0;if(typeof e==`object`&&e){let t=e;return`distances`in t&&Array.isArray(t.distances)&&`selectedFace`in t||`distance`in t&&`angle`in t&&`selectedFace`in t}return!1}function OG(e){return typeof e==`number`?!0:Array.isArray(e)&&e.length===2?e.every(EG):!1}function kG(e,t){let n=n=>{let r=e.findAll(n);if(r.length===0)return[];let i=0,a=iT(Uw(yD(r)),t);for(let e=1;e<r.length;e++){let n=iT(Uw(vD(r,e)),t);n<a&&(a=n,i=e)}return[vD(r,i)]},r=e=>{let t=n(e);return t.length===0?k(Wa(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found 0 element(s)`)):O(yD(t))};return{...e,findAll:n,findUnique:r}}function AG(e){return oj(`vertex`,e,AG,(t,n)=>({nearestTo:t=>kG(AG(e),t),atPosition:(e,t=1e-4)=>n(n=>iT(Uw(n),e)<t),withinBox:(e,t)=>n(n=>{let r=Uw(n);return r[0]>=e[0]-1e-6&&r[0]<=t[0]+1e-6&&r[1]>=e[1]-1e-6&&r[1]<=t[1]+1e-6&&r[2]>=e[2]-1e-6&&r[2]<=t[2]+1e-6}),atDistance:(e,t=[0,0,0],r=1e-4)=>n(n=>{let i=Uw(n);return Math.abs(iT(i,t)-e)<r})}))}function jG(){return AG([])}var MG=new Map,NG=null,PG=null;function FG(e,t){MG.set(e,t),NG||=e,e===NG&&(PG=t)}function IG(e){if(!e&&PG)return PG;let t=e??NG;if(!t)throw Error(`brepjs voxel engine not initialized. Call initVoxel() (or registerVoxel()) before using voxel operations.`);let n=MG.get(t);if(!n)throw Error(`brepjs: voxel engine '${t}' is not registered.`);return n}function LG(){return NG}function RG(e,t=`voxel`){FG(t,e),NG=t,PG=e}function zG(e){if(e.vertices.length%3!=0)return F(`VOXEL_INVALID_MESH`,`mesh.vertices length must be a multiple of 3 (flat xyz).`);if(e.triangles.length%3!=0)return F(`VOXEL_INVALID_MESH`,`mesh.triangles length must be a multiple of 3.`);let t=e.vertices.length/3;for(let n=0;n<e.triangles.length;n++){let r=e.triangles[n];if(r===void 0||r>=t)return F(`VOXEL_INVALID_TRIANGLE_INDEX`,`triangle index ${r} at position ${n} is out of range for ${t} vertices.`)}return null}function BG(e,t){return zG(e)||(t.length%3==0?null:F(`VOXEL_INVALID_QUERIES`,`queries length must be a multiple of 3 (flat xyz).`))}function VG(e){try{return O(IG(e))}catch(e){return k(Va(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function HG(e,t,n){let r=BG(e,t);if(r)return k(r);let i=VG(n);return A(i)?i:O(i.value.winding_numbers(e.vertices,e.triangles,t))}function UG(e,t,n){let r=BG(e,t);if(r)return k(r);let i=VG(n);if(A(i))return i;let a=i.value.points_inside(e.vertices,e.triangles,t);return O(Array.from(a,e=>e===1))}var WG=48,GG=2;function KG(e,t,n){let r=zG(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`repairMesh requires a non-empty triangle mesh.`));let i=t?.resolution??WG,a=t?.padding??GG;if(!Number.isInteger(i)||i<1)return k(F(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`));if(!Number.isInteger(a)||a<1)return k(F(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`));let o=VG(n);if(A(o))return o;try{try{var s=lC();let t=s.u(o.value.repair_mesh(e.vertices,e.triangles,i,a)),n=t.positions.length/3;return O({vertices:t.positions,normals:t.normals,triangles:t.indices,uvs:new Float32Array(n*2),faceGroups:[{start:0,count:t.indices.length/3,faceHash:0}]})}catch(e){s.e=e}finally{s.d()}}catch(e){return k(Ha(`VOXEL_REPAIR_FAILED`,e instanceof Error?e.message:`voxel repair failed (grid too large?).`,e))}}var qG=.001;function JG(e,t=qG){try{let n=lD(e,{tolerance:t});return n.vertices.length===0||n.triangles.length===0?k(Ha(`VOXEL_SHAPE_MESH_EMPTY`,`shape tessellated to an empty triangle mesh.`)):O({vertices:n.vertices,triangles:n.triangles})}catch(e){return k(Ha(`VOXEL_SHAPE_MESH_FAILED`,e instanceof Error?e.message:`failed to mesh shape for voxel op.`,e))}}var YG=48,XG=2,ZG={union:0,intersection:1,difference:2};function QG(e){let t=e?.resolution??YG,n=e?.padding??XG;return!Number.isInteger(t)||t<1?k(F(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(F(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function $G(e){if(e.positions.length===0||e.indices.length===0)return k(Ha(`VOXEL_DEGENERATE_RESULT`,`the voxel operation produced an empty mesh (over-shrunk offset or disjoint operands?).`));let t=e.positions.length/3;return O({vertices:e.positions,normals:e.normals,triangles:e.indices,uvs:new Float32Array(t*2),faceGroups:[{start:0,count:e.indices.length/3,faceHash:0}]})}function eK(e,t,n,r){let i=zG(e);if(i)return k(i);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`offsetMesh requires a non-empty triangle mesh.`));if(!Number.isFinite(t))return k(F(`VOXEL_INVALID_DISTANCE`,`distance must be a finite number.`));let a=QG(n);if(A(a))return a;let o=VG(r);if(A(o))return o;try{try{var s=lC();return $G(s.u(o.value.offset_mesh(e.vertices,e.triangles,t,a.value.resolution,a.value.padding)))}catch(e){s.e=e}finally{s.d()}}catch(e){return k(Ha(`VOXEL_OFFSET_FAILED`,e instanceof Error?e.message:`voxel offset failed (grid too large?).`,e))}}function tK(e,t,n,r){let i=zG(e);if(i)return k(i);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`shellMesh requires a non-empty triangle mesh.`));if(!Number.isFinite(t)||t<=0)return k(F(`VOXEL_INVALID_THICKNESS`,`thickness must be a finite number > 0.`));let a=QG(n);if(A(a))return a;let o=VG(r);if(A(o))return o;try{try{var s=lC();return $G(s.u(o.value.shell_mesh(e.vertices,e.triangles,t,a.value.resolution,a.value.padding)))}catch(e){s.e=e}finally{s.d()}}catch(e){return k(Ha(`VOXEL_SHELL_FAILED`,e instanceof Error?e.message:`voxel shell failed (grid too large?).`,e))}}function nK(e,t,n,r,i){let a=zG(e);if(a)return k(a);let o=zG(t);if(o)return k(o);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBoolean requires a non-empty mesh for operand A.`));if(t.vertices.length===0||t.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBoolean requires a non-empty mesh for operand B.`));let s=ZG[n],c=QG(r);if(A(c))return c;let l=VG(i);if(A(l))return l;try{try{var u=lC();return $G(u.u(l.value.voxel_boolean(e.vertices,e.triangles,t.vertices,t.triangles,s,c.value.resolution,c.value.padding)))}catch(e){u.e=e}finally{u.d()}}catch(e){return k(Ha(`VOXEL_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel boolean failed (grid too large?).`,e))}}function rK(e,t,n,r){let i=JG(e);return A(i)?i:eK(i.value,t,n,r)}function iK(e,t,n,r){let i=JG(e);return A(i)?i:tK(i.value,t,n,r)}function aK(e,t,n,r,i){let a=JG(e);if(A(a))return a;let o=JG(t);return A(o)?o:nK(a.value,o.value,n,r,i)}var oK={gyroid:0,schwarzP:1,diamond:2},sK=48,cK=2;function lK(e){let t=oK[e.type];if(t===void 0)return k(F(`LATTICE_INVALID_TYPE`,`lattice type must be one of gyroid, schwarzP, diamond (got '${e.type}').`));if(!(e.period>0))return k(F(`LATTICE_INVALID_PERIOD`,`period must be > 0.`));if(!(e.thickness>0))return k(F(`LATTICE_INVALID_THICKNESS`,`thickness must be > 0.`));let n=e.resolution??sK,r=e.padding??cK;return!Number.isInteger(n)||n<1?k(F(`LATTICE_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(r)||r<1?k(F(`LATTICE_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({tag:t,period:e.period,thickness:e.thickness,resolution:n,padding:r})}function uK(e){let t=e.positions.length/3;return{vertices:e.positions,normals:e.normals,triangles:e.indices,uvs:new Float32Array(t*2),faceGroups:[{start:0,count:e.indices.length/3,faceHash:0}]}}function dK(e,t,n){let r=zG(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(F(`LATTICE_EMPTY_MESH`,`latticeInfill requires a non-empty triangle mesh.`));let i=lK(t);if(A(i))return i;let a=VG(n);if(A(a))return a;let{tag:o,period:s,thickness:c,resolution:l,padding:u}=i.value;try{try{var d=lC();return O(uK(d.u(a.value.lattice_infill(e.vertices,e.triangles,l,u,o,s,c))))}catch(e){d.e=e}finally{d.d()}}catch(e){return k(Ha(`LATTICE_INFILL_FAILED`,e instanceof Error?e.message:`lattice infill failed (grid too large?).`,e))}}function fK(e,t,n){let r=JG(e);return A(r)?r:dK(r.value,t,n)}function pK(e,t,n){for(let t=0;t<3;t++){let n=e.min[t],r=e.max[t];if(n===void 0||r===void 0||!(n<r))return k(F(`LATTICE_INVALID_BOUNDS`,`bounds.min must be strictly less than bounds.max on every axis (axis ${t}).`))}let r=lK(t);if(A(r))return r;let i=VG(n);if(A(i))return i;let{tag:a,period:o,thickness:s,resolution:c,padding:l}=r.value,[u,d,f]=e.min,[p,m,h]=e.max;try{try{var g=lC();return O(uK(g.u(i.value.tpms_box(u,d,f,p,m,h,c,l,a,o,s))))}catch(e){g.e=e}finally{g.d()}}catch(e){return k(Ha(`TPMS_LATTICE_FAILED`,e instanceof Error?e.message:`tpms lattice failed (grid too large?).`,e))}}function mK(e){return U().createVector3d(e[0],e[1],e[2])}function hK(e){return U().createPoint3d(e[0],e[1],e[2])}function gK(e){return U().createDirection3d(e[0],e[1],e[2])}function _K(e){return[e.X(),e.Y(),e.Z()]}function vK(e){return[e.X(),e.Y(),e.Z()]}function yK(e){return[e.X(),e.Y(),e.Z()]}function bK(e,t){let n=mK(e);try{return t(n)}finally{n.delete()}}function xK(e,t){let n=hK(e);try{return t(n)}finally{n.delete()}}function SK(e,t){let n=gK(e);try{return t(n)}finally{n.delete()}}var CK=.299,wK=.587,TK=.114;function EK(e,t={}){if(e.length<2)return k(F(N.SURFACE_GRID_TOO_SMALL,`surfaceFromGrid: need at least 2 rows, got ${e.length}`));let n=e.length,r=e[0]?.length??0;if(r<2)return k(F(N.SURFACE_GRID_TOO_SMALL,`surfaceFromGrid: need at least 2 columns, got ${r}`));for(let t=0;t<n;t++){let n=e[t];if(!n||n.length!==r)return k(F(N.SURFACE_GRID_JAGGED,`surfaceFromGrid: row ${t} has ${n?.length??0} columns, expected ${r}`))}let{width:i=r-1,depth:a=n-1,scaleZ:o=1}=t,s=i/(r-1),c=a/(n-1);try{return DK(e,n,r,s,c,o)}catch{}try{return OK(e,n,r,s,c,o)}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.SURFACE_FAILED,`surfaceFromGrid failed: ${t}`,e))}}function DK(e,t,n,r,i,a){let o=[];for(let s=0;s<t;s++)for(let t=0;t<n;t++){let n=e[s],c=(n?n[t]??0:0)*a;o.push([t*r,s*i,c])}let s=W(U().bsplineSurface(o,t,n));return ow(s)?O(s):(s[Symbol.dispose](),k(P(N.SURFACE_FAILED,`B-spline surface did not produce a face`)))}function OK(e,t,n,r,i,a){let o=[];for(let s=0;s<t;s++)for(let t=0;t<n;t++){let n=e[s],c=(n?n[t]??0:0)*a;o.push([t*r,s*i,c])}let s=W(U().triangulatedSurface(o,t,n));return ow(s)||sw(s)?O(s):(s[Symbol.dispose](),k(P(N.SURFACE_FAILED,`surfaceFromGrid: unexpected shape type from sewing`)))}async function kK(e,t={}){let n=t.channel??`luminance`,r=Math.max(1,Math.round(t.downsample??1));if(typeof createImageBitmap!=`function`)return k(Ua(N.SURFACE_FAILED,`surfaceFromImage requires createImageBitmap (not available in this environment)`));let i;try{i=await createImageBitmap(e)}catch(e){return k(Ua(N.SURFACE_FAILED,`surfaceFromImage: failed to decode image — ${e instanceof Error?e.message:String(e)}`))}let a=i.width,o=i.height;if(a<2||o<2)return i.close(),k(F(N.SURFACE_GRID_TOO_SMALL,`surfaceFromImage: image too small (${a}x${o}), need at least 2x2`));if(typeof OffscreenCanvas!=`function`)return i.close(),k(Ua(N.SURFACE_FAILED,`surfaceFromImage requires OffscreenCanvas (not available in this environment)`));let s=new OffscreenCanvas(a,o).getContext(`2d`);if(!s)return i.close(),k(Ua(N.SURFACE_FAILED,`surfaceFromImage: could not get 2D canvas context`));s.drawImage(i,0,0),i.close();let c=s.getImageData(0,0,a,o).data,l=[];for(let e=0;e<o;e+=r){let t=[];for(let i=0;i<a;i+=r){let r=(e*a+i)*4,o=c[r]??0,s=c[r+1]??0,l=c[r+2]??0,u;switch(n){case`r`:u=o/255;break;case`g`:u=s/255;break;case`b`:u=l/255;break;default:u=(CK*o+wK*s+TK*l)/255;break}t.push(u)}l.push(t)}let u={};return t.width!==void 0&&(u.width=t.width),t.depth!==void 0&&(u.depth=t.depth),t.scaleZ!==void 0&&(u.scaleZ=t.scaleZ),EK(l,u)}function AK(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function jK(e,t={}){if(e.length===0)return k(F(N.HULL_EMPTY_INPUT,`hull: at least one shape is required`,void 0,void 0,`Provide one or more shapes to compute a convex hull`));for(let[t,n]of e.entries()){let e=AK(n,`hull: shapes[${t}]`);if(A(e))return e}let n=t.tolerance??.1;try{let t=U(),r=e.map(e=>e.wrapped),i=W(t.hull(r,n));return cw(i)?O(i):k(P(N.HULL_NOT_3D,`Hull result is not a solid; input may be degenerate`))}catch(e){let t=e instanceof Error?e.message:String(e);return t.includes(`coplanar`)||t.includes(`fewer than`)||t.includes(`degenerate`)?k(P(N.HULL_DEGENERATE,`Hull degenerate: ${t}`,e)):k(P(N.HULL_FAILED,`Hull operation failed: ${t}`,e))}}function MK(e){if(e.length<4)return k(F(N.HULL_EMPTY_INPUT,`convexHull: at least 4 points required, got ${e.length}`,void 0,void 0,`Provide 4 or more non-coplanar 3D points`));try{let t=U(),n=e.map(e=>({x:e[0],y:e[1],z:e[2]})),r=W(t.hullFromPoints(n,.1));return cw(r)?O(r):k(P(N.HULL_NOT_3D,`convexHull result is not a solid; points may be coplanar`))}catch(e){let t=e instanceof Error?e.message:String(e);return t.includes(`coplanar`)||t.includes(`fewer than`)||t.includes(`degenerate`)?k(P(N.HULL_DEGENERATE,`convexHull degenerate: ${t}`,e)):k(P(N.HULL_FAILED,`convexHull failed: ${t}`,e))}}function NK(e){let n=Tw(e);if(n.length!==1)return null;let r=t(n,0);if(Bw(r)!==`sphere`)return null;let i=U().area(r.wrapped);return Math.sqrt(i/(4*Math.PI))}function PK(e,t,n){try{let r=W(U().offset(e.wrapped,t,n));return uw(r)?O(r):(r[Symbol.dispose](),k(za(N.MINKOWSKI_NOT_3D,`Minkowski sphere offset did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.MINKOWSKI_FAILED,`Minkowski sphere offset failed: ${t}`,e,{operation:`minkowski`,fastPath:`sphere`}))}}function FK(e,t,n){let r=U();try{let i=Dw(e),a=Dw(t);if(i.length===0||a.length===0)return k(P(N.MINKOWSKI_FAILED,`Minkowski sum: one or both shapes have no vertices`,void 0,{operation:`minkowski`}));let o=[];for(let e of i){let[t,n,i]=r.vertexPosition(e.wrapped);for(let e of a){let[a,s,c]=r.vertexPosition(e.wrapped);o.push({x:t+a,y:n+s,z:i+c})}}let s=W(r.hullFromPoints(o,n));return uw(s)?O(s):(s[Symbol.dispose](),k(za(N.MINKOWSKI_NOT_3D,`Minkowski hull did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.MINKOWSKI_FAILED,`Minkowski general path failed: ${t}`,e,{operation:`minkowski`}))}}function IK(e,t,n={}){let{tolerance:r=1e-6}=n;if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`minkowski: shape is a null shape`));if(U().isNull(t.wrapped))return k(F(N.MINKOWSKI_NULL_TOOL,`minkowski: tool is a null shape`));if(!uw(e)||!uw(t))return k(F(N.MINKOWSKI_NOT_3D,`minkowski: both shape and tool must be 3D`));let i=NK(t);return i===null?FK(e,t,r):PK(e,i,r)}function LK(e,t,n={}){let{tolerance:r=1e-6}=n;if(e.length<4)return k(F(N.POLYHEDRON_INSUFFICIENT_POINTS,`polyhedron: need at least 4 points, got ${e.length}`));if(t.length<4)return k(F(N.POLYHEDRON_INSUFFICIENT_FACES,`polyhedron: need at least 4 faces, got ${t.length}`));let i=[];for(let[n,r]of t.entries()){for(let t of r)if(t<0||t>=e.length)return k(F(N.POLYHEDRON_INVALID_INDEX,`polyhedron: face ${n} has out-of-range index ${t} (${e.length} points)`));if(r.length<3)continue;let t=r[0];for(let e=1;e<r.length-1;e++)i.push([t,r[e],r[e+1]])}try{let t=U(),n=e.map(([e,t,n])=>({x:e,y:t,z:n})),a=W(t.buildSolidFromFaces(n,i,r));return cw(a)?O(a):(a[Symbol.dispose](),k(P(N.POLYHEDRON_FAILED,`Polyhedron did not produce a solid`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.POLYHEDRON_FAILED,`Polyhedron failed: ${t}`,e))}}var RK=1e-10;function zK(e,t,n,r){return e*r-t*n}function BK(e,t,n,r){return e*n+t*r}function VK(e,t){return Math.sqrt(e*e+t*t)}function HK(e,t){let n=e[(t%e.length+e.length)%e.length];if(!n)throw Error(`Invalid polygon index ${t} for length ${e.length}`);return n}function UK(e){let t=0;for(let n=0;n<e.length;n++){let r=HK(e,n),i=HK(e,n+1);t+=r.x*i.y-i.x*r.y}return t<0?[...e].reverse():e}function WK(e,t){let n=HK(e,t-1),r=HK(e,t),i=HK(e,t+1),a=r.x-n.x,o=r.y-n.y,s=VK(a,o),c=i.x-r.x,l=i.y-r.y,u=VK(c,l);if(s<RK||u<RK)return{dx:0,dy:0};let d=-o/s,f=a/s,p=-l/u,m=c/u,h=d+p,g=f+m,_=VK(h,g);if(_<RK)return{dx:d,dy:f};h/=_,g/=_;let v=BK(h,g,d,f),y=Math.abs(v)>RK?1/v:1;return{dx:h*y,dy:g*y}}function GK(e){return!e.prev||!e.next?!1:zK(e.x-e.prev.x,e.y-e.prev.y,e.next.x-e.x,e.next.y-e.y)<-1e-10}function KK(e){let t=e.map((t,n)=>{let r=WK(e,n);return{x:t.x,y:t.y,bx:r.dx,by:r.dy,origIdx:n,prev:null,next:null,active:!0}});for(let e=0;e<t.length;e++){let n=t[e],r=t[(e-1+t.length)%t.length],i=t[(e+1)%t.length];n&&r&&i&&(n.prev=r,n.next=i)}return t}function qK(e,t){let n=e;for(let e=0;e<t&&n;e++)n.active=!1,n=n.next}function JK(e){let t=1,n=e.next;for(;n!==e&&(t++,n=n.next,!(t>1e4)););return t}function YK(e,t){let n=e.bx-t.bx,r=e.by-t.by,i=t.x-e.x,a=t.y-e.y;if(Math.abs(n)<RK&&Math.abs(r)<RK)return null;let o;if(o=Math.abs(n)>Math.abs(r)?i/n:a/r,o<RK)return null;let s=Math.abs(n)>Math.abs(r)?r:n,c=Math.abs(n)>Math.abs(r)?a:i;if(Math.abs(s)>RK){let e=c/s;if(Math.abs(o-e)>1e-4*Math.max(1,Math.abs(o)))return null}return o}function XK(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=VK(r,i);if(a<RK)return null;let o=-i/a,s=r/a,c=(e.x-t.x)*o+(e.y-t.y)*s,l=e.bx-(t.bx+n.bx)/2,u=e.by-(t.by+n.by)/2,d=l*o+u*s;if(Math.abs(d)<RK)return null;let f=-c/d;if(f<RK)return null;let p=e.x+f*e.bx,m=e.y+f*e.by,h=t.x+f*t.bx,g=t.y+f*t.by,_=n.x+f*n.bx,v=n.y+f*n.by,y=_-h,b=v-g,x=VK(y,b);if(x<RK)return f;let S=BK(p-h,m-g,y,b)/(x*x);return S<-.01||S>1.01?null:f}function ZK(e){let t=[];for(let n of e){if(!n.active||!n.next)continue;let e=YK(n,n.next);if(e!==null&&e>RK){let r=n.x+e*n.bx,i=n.y+e*n.by;t.push({time:e,x:r,y:i,nodeA:n,nodeB:n.next,type:`edge`})}if(GK(n)){let e=n.next.next,r=0;for(;e!==n.prev&&e!==n&&r<1e3;){let i=XK(n,e,e.next);if(i!==null&&i>RK){let r=n.x+i*n.bx,a=n.y+i*n.by;t.push({time:i,x:r,y:a,nodeA:n,nodeB:e,type:`split`})}e=e.next,r++}}}return t.sort((e,t)=>e.time-t.time),t}function QK(e){if(e.length<3)return O({nodes:[],faces:[]});try{return O($K(e))}catch(e){return k(Ha(N.STRAIGHT_SKELETON_FAILED,e instanceof Error?e.message:String(e),e))}}function $K(e){let t=UK(e),n=t.length,r=[],i=Array.from({length:n},()=>[]),a=KK(t),o=0,s=n*n*2;for(;o<s;){o++;let e=a.find(e=>e.active);if(!e)break;let t=JK(e);if(t<=3){if(t===3){let t=e,n=t.next,a=n.next,o=YK(t,n),s=o!==null&&o>RK?o:0,c=(t.x+n.x+a.x)/3+s*(t.bx+n.bx+a.bx)/3,l=(t.y+n.y+a.y)/3+s*(t.by+n.by+a.by)/3,u=r.length;r.push({x:c,y:l,height:s});let d=i[t.origIdx],f=i[n.origIdx],p=i[a.origIdx];d&&d.push(u),f&&f.push(u),p&&p.push(u),t.active=!1,n.active=!1,a.active=!1}else qK(e,t);continue}let n=a.filter(e=>e.active),s=ZK(n);if(s.length===0){for(let e of n)e.active=!1;break}let c=s[0];if(!c)break;if(c.type===`edge`){let e=c.nodeA,t=c.nodeB;if(!e.active||!t.active)continue;let n=r.length;r.push({x:c.x,y:c.y,height:c.time});let a=i[e.origIdx],o=i[t.origIdx];a&&a.push(n),o&&o.push(n),e.x=c.x,e.y=c.y,e.next=t.next,t.next.prev=e,t.active=!1;let s=[],l=e;do s.push({x:l.x,y:l.y}),l=l.next;while(l!==e);let u=WK(s,0);e.bx=u.dx,e.by=u.dy}else{let e=c.nodeA,t=c.nodeB;if(!e.active||!t.active)continue;let n=r.length;r.push({x:c.x,y:c.y,height:c.time});let o=i[e.origIdx];o&&o.push(n);let s=i[t.origIdx];s&&s.push(n);let l={x:c.x,y:c.y,bx:0,by:0,origIdx:e.origIdx,prev:null,next:null,active:!0};a.push(l),e.x=c.x,e.y=c.y;let u=e.next,d=t.next;e.next=d,d.prev=e,l.next=u,u.prev=l,l.prev=t,t.next=l;let f=e=>{let t=[],n=e;do t.push({x:n.x,y:n.y}),n=n.next;while(n!==e);return t},p=WK(f(e),0);e.bx=p.dx,e.by=p.dy;let m=WK(f(l),0);l.bx=m.dx,l.by=m.dy}}let c=[];for(let e=0;e<n;e++){let a=(e+1)%n,o=[HK(t,e),HK(t,a)],s=[0,0],l=i[a],u=i[e];if(l)for(let e of l){let t=r[e];t&&(o.push({x:t.x,y:t.y}),s.push(t.height))}if(u)for(let e=u.length-1;e>=0;e--){let t=u[e];if(t===void 0)continue;let n=r[t];if(!n)continue;let i=o[o.length-1];i&&VK(n.x-i.x,n.y-i.y)>RK&&(o.push({x:n.x,y:n.y}),s.push(n.height))}o.length>=3&&c.push({vertices:o,heights:s})}let l=[];for(let e of r)l.some(t=>Math.abs(t.x-e.x)<.01&&Math.abs(t.y-e.y)<.01)||l.push(e);return{nodes:l,faces:c}}function eq(e){let t=ww(e).map(e=>{let t=BE(e);return{x:t[0],y:t[1]}}),n=t[0],r=t[t.length-1];return t.length>1&&n&&r&&Math.abs(n.x-r.x)<1e-10&&Math.abs(n.y-r.y)<1e-10&&t.pop(),t}function tq(e){let t=[];for(let n=1;n<e-1;n++)t.push([0,n,n+1]);return t}function nq(e,t,n,r,i,a){return(n-e)*(a-t)-(r-t)*(i-e)}function rq(e,t,n,r,i,a,o,s){let c=nq(n,r,i,a,e,t),l=nq(i,a,o,s,e,t),u=nq(o,s,n,r,e,t);return!((c<0||l<0||u<0)&&(c>0||l>0||u>0))}function iq(e){let t=e.length;if(t<3)return[];if(t===3)return[[0,1,2]];let n=0;for(let r=0;r<t;r++){let i=e[r],a=e[(r+1)%t];i&&a&&(n+=i.x*a.y-a.x*i.y)}let r=[],i=Array.from({length:t},(e,t)=>t);n<0&&i.reverse();let a=(t,n,r)=>{let a=e[t],o=e[n],s=e[r];if(!a||!o||!s||nq(a.x,a.y,o.x,o.y,s.x,s.y)<=0)return!1;for(let c of i){if(c===t||c===n||c===r)continue;let i=e[c];if(i&&rq(i.x,i.y,a.x,a.y,o.x,o.y,s.x,s.y))return!1}return!0};for(;i.length>3;){let e=!1;for(let t=0;t<i.length;t++){let n=i[(t-1+i.length)%i.length],o=i[t],s=i[(t+1)%i.length];if(!(n===void 0||o===void 0||s===void 0)&&a(n,o,s)){r.push([n,o,s]),i.splice(t,1),e=!0;break}}if(!e)break}if(i.length===3){let[e,t,n]=i;e!==void 0&&t!==void 0&&n!==void 0&&r.push([e,t,n])}return r}function aq(e,t,n){let r=[];for(let i of e.faces){let e=i.vertices.map((e,n)=>[e.x,e.y,(i.heights[n]??0)*t]),a=tq(e.length);for(let[t,i,o]of a){let a=e[t],s=e[i],c=e[o];if(!a||!s||!c)continue;let l=s[0]-a[0],u=s[1]-a[1],d=s[2]-a[2],f=c[0]-a[0],p=c[1]-a[1],m=c[2]-a[2],h=u*m-d*p,g=d*f-l*m,_=l*p-u*f;if(h*h+g*g+_*_<1e-20)continue;let v=n.buildTriFace(a,s,c);v!==null&&r.push(v)}}return r}function oq(e,t){let n=(t?.angle??45)*Ww,r=Math.tan(n);try{let t=eq(e);if(t.length<3)return k(P(N.ROOF_FAILED,`Wire must have at least 3 edges for roof generation`));let n=QK(t);if(!n.ok)return n;let i=n.value;if(i.faces.length===0)return k(P(N.ROOF_FAILED,`Straight skeleton computation produced no faces`));let a=U(),o=aq(i,r,a);for(let[e,n,r]of iq(t)){let i=t[e],s=t[n],c=t[r];if(!i||!s||!c)continue;let l=[i.x,i.y,0],u=[s.x,s.y,0],d=[c.x,c.y,0],f=a.buildTriFace(l,d,u);f!==null&&o.push(f)}if(o.length===0)return k(P(N.ROOF_FAILED,`No valid triangular faces could be built`));try{let e=a.sewAndSolidify(o,1e-6);return O(ew(a.fixShape(e)))}catch(e){try{let t=ew(a.sew(o,1e-6));return zC(t)?O(t):k(P(N.ROOF_FAILED,`Sew fallback produced invalid solid`,e))}catch(e){return k(P(N.ROOF_FAILED,`Failed to sew roof faces`,e))}}}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.ROOF_FAILED,`Roof generation failed: ${t}`,e))}}var sq={coincident:3,concentric:4,distance:1,angle:1};function cq(e,t){let n=new Map;for(let t of e)n.set(t,{position:[0,0,0],rotation:[1,0,0,0]});let r=[];for(let e of t)if(e.type===`coincident`&&e.entityA&&e.entityB){let t=e.entityA,i=e.entityB;if(t.entity.type===`plane`&&i.entity.type===`plane`){let e=t.entity.normal??[0,0,1],r=t.entity.origin,a=i.entity.origin,o=e[0]*(r[0]-a[0])+e[1]*(r[1]-a[1])+e[2]*(r[2]-a[2]),s=[o*e[0],o*e[1],o*e[2]];n.set(i.node,{position:s,rotation:[1,0,0,0]})}else r.push(`coincident(${t.entity.type}-${i.entity.type})`)}else if(e.type===`distance`&&e.entityA&&e.entityB&&e.value!==void 0){let t=e.entityA,i=e.entityB;if(t.entity.type===`plane`&&i.entity.type===`plane`){let r=t.entity.normal??[0,0,1],a=t.entity.origin,o=i.entity.origin,s=r[0]*(a[0]-o[0])+r[1]*(a[1]-o[1])+r[2]*(a[2]-o[2])+e.value,c=[s*r[0],s*r[1],s*r[2]];n.set(i.node,{position:c,rotation:[1,0,0,0]})}else r.push(`distance(${t.entity.type}-${i.entity.type})`)}else (e.type===`concentric`||e.type===`angle`)&&r.push(e.type);return{transforms:n,dof:r.reduce((e,t)=>e+(sq[t]??sq[t.split(`(`)[0]??``]??0),0),converged:r.length===0,unsupported:r}}function lq(e){return e.face?{type:`plane`,origin:BT(e.face),normal:zT(e.face)}:e.point?{type:`point`,origin:e.point}:null}function uq(e,t){let n=lq(e),r=lq(t);return!n||!r?k(F(N.ASSEMBLY_MATE_INVALID,`solveAssembly: could not extract geometry from mate entities`)):O({entityA:{node:e.node,entity:n},entityB:{node:t.node,entity:r}})}function dq(e){switch(e.type){case`fixed`:return O({type:`fixed`,entityA:{node:e.entity.node,entity:{type:`point`,origin:[0,0,0]}}});case`coincident`:{let t=uq(e.entityA,e.entityB);return t.ok?O({type:`coincident`,...t.value}):t}case`distance`:{let t=uq(e.entityA,e.entityB);return t.ok?O({type:`distance`,...t.value,value:e.distance}):t}case`angle`:{let t=uq(e.entityA,e.entityB);return t.ok?O({type:`angle`,...t.value,value:e.angle}):t}case`concentric`:{let t=uq(e.axisA,e.axisB);return t.ok?O({type:`concentric`,...t.value}):t}}}function fq(e,t){let n=e.mates??[];return{...e,mates:[...n,t]}}function pq(e){let t=e.mates;if(!t||t.length===0)return k(F(N.ASSEMBLY_MATE_INVALID,`solveAssembly: no mates defined`));try{let n=[];cA(e,e=>{n.push(e.name)});let r=[];for(let e of t){let t=dq(e);if(!t.ok)return t;r.push(t.value)}let i=cq(n,r);if(!i.converged){let e=i.unsupported.length>0?`Unsupported constraint types: ${i.unsupported.join(`, `)} (${i.dof} DOF unresolved)`:`Assembly constraint solver did not converge`;return k(P(N.ASSEMBLY_NOT_CONVERGED,e))}return O({transforms:i.transforms,dof:i.dof,converged:i.converged})}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.ASSEMBLY_SOLVE_FAILED,`Assembly solve failed: ${t}`,e))}}function mq(e,t,n=1e-6){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`checkInterference: first shape is a null shape`));if(U().isNull(t.wrapped))return k(F(N.NULL_SHAPE_INPUT,`checkInterference: second shape is a null shape`));let r=U().distance(e.wrapped,t.wrapped);return O({hasInterference:r.value<=n,minDistance:r.value,pointOnShape1:r.point1,pointOnShape2:r.point2})}function hq(e,n=1e-6){let r=[],i=e.map(e=>Rw(e));return e.forEach((a,o)=>{for(let s=o+1;s<e.length;s++){if(gq(t(i,o),t(i,s),n))continue;let c=j(mq(a,t(e,s),n));c.hasInterference&&r.push({i:o,j:s,result:c})}}),r}function gq(e,t,n){return e.xMax+n<t.xMin||t.xMax+n<e.xMin||e.yMax+n<t.yMin||t.yMax+n<e.yMin||e.zMax+n<t.zMin||t.zMax+n<e.zMin}function _q(e){let t=e.split(/\r?\n/),n=[],r=!1,i;for(let e=0;e<t.length-1;e+=2){let a=t[e],o=t[e+1];if(a===void 0||o===void 0)continue;let s=parseInt(a.trim(),10),c=o.trim();if(!isNaN(s)){if(s===2&&c===`ENTITIES`){r=!0;continue}if(r){if(s===0){if(c===`ENDSEC`||c===`EOF`){i&&n.push(i);break}i&&n.push(i),i={type:c,layer:`0`,data:new Map};continue}i&&(s===8?i.layer=c:i.data.set(s,c))}}}return n}function vq(e,t,n=0){let r=e.get(t);if(r===void 0)return n;let i=parseFloat(r);return isNaN(i)?n:i}function yq(e){let{type:t,data:n}=e,r=U();if(t===`LINE`)return r.makeLineEdge([vq(n,10),vq(n,20),vq(n,30)],[vq(n,11),vq(n,21),vq(n,31)]);if(t===`CIRCLE`)return r.makeCircleEdge([vq(n,10),vq(n,20),vq(n,30)],[0,0,1],vq(n,40));if(t===`ARC`){let e=vq(n,50)*Math.PI/180,t=vq(n,51)*Math.PI/180;return r.makeCircleArc([vq(n,10),vq(n,20),vq(n,30)],[0,0,1],vq(n,40),e,t)}}async function bq(e,t){let n;try{n=await e.text()}catch(e){return k(Ua(N.DXF_IMPORT_FAILED,`Failed to read DXF blob`,e))}let r=_q(n),i=t?.layer===void 0?r:r.filter(e=>e.layer===t.layer);if(i.length===0)return O([]);let a=[];try{for(let e of i){let t=yq(e);t!==void 0&&a.push(t)}return a.length===0?O([]):O([ZC(U().makeWire(a))])}catch(e){return k(Ua(N.DXF_IMPORT_FAILED,`Failed to convert DXF entities to geometry`,e))}finally{for(let e of a)e.delete()}}function xq(e,t,n=1e-6){let r=U(),i=[];for(let[t,n,a]of e){let e=r.buildTriFace(t,n,a);e!==null&&i.push(e)}if(i.length===0)return k(Ua(t,`No valid triangular faces could be built`));try{return O(W(r.sewAndSolidify(i,n)))}catch{try{return O(W(r.sew(i,n)))}catch{return k(Ua(t,`Failed to sew triangular faces`))}}}function Sq(e){let t=e.split(/\s+/),n=parseFloat(t[1]??``),r=parseFloat(t[2]??``),i=parseFloat(t[3]??``);return isNaN(n)||isNaN(r)||isNaN(i)?null:[n,r,i]}function Cq(e){return e.split(/\s+/).slice(1).map(e=>parseInt(e.split(`/`)[0]??``,10)).filter(e=>!isNaN(e))}async function wq(e){let t=(await e.text()).split(`
|
|
57
|
+
`),n=[],r=[];for(let e of t){let t=e.trim();if(t.startsWith(`v `)){let e=Sq(t);e&&n.push(e)}else if(t.startsWith(`f `)){let e=Cq(t);e.length>=3&&r.push(e)}}if(n.length===0||r.length===0)return k(Ua(N.OBJ_IMPORT_FAILED,`OBJ file contains no valid geometry`));try{return Tq(n,r)}catch(e){let t=e instanceof Error?e.message:String(e);return k(Ua(N.OBJ_IMPORT_FAILED,`OBJ import failed: ${t}`,e))}}function Tq(e,t){let n=[];for(let r of t)for(let t=1;t<r.length-1;t++){let i=r[0]??0,a=r[t]??0,o=r[t+1]??0,s=i>0?i-1:e.length+i,c=a>0?a-1:e.length+a,l=o>0?o-1:e.length+o,u=e[s],d=e[c],f=e[l];!u||!d||!f||n.push([u,d,f])}return xq(n,N.OBJ_IMPORT_FAILED)}function Eq(e,t){let n=-1;for(let t=e.length-22;t>=0;t--)if(e[t]===80&&e[t+1]===75&&e[t+2]===5&&e[t+3]===6){n=t;break}if(n<0)return null;let r=new DataView(e.buffer,e.byteOffset,e.byteLength),i=r.getUint32(n+16,!0),a=i+r.getUint32(n+12,!0),o=i,s=new TextDecoder;for(;o<a&&r.getUint32(o,!0)===33639248;){let n=r.getUint16(o+28,!0),i=r.getUint16(o+30,!0),a=r.getUint16(o+32,!0),c=r.getUint32(o+42,!0);if(s.decode(e.subarray(o+46,o+46+n))===t){if(r.getUint16(c+8,!0)!==0)return null;let t=r.getUint16(c+26,!0),n=r.getUint16(c+28,!0),i=r.getUint32(c+18,!0),a=c+30+t+n;return e.subarray(a,a+i)}o+=46+n+i+a}return null}function Dq(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95}function Oq(e){let t={},n=0;for(;n<e.length;){let r=e.indexOf(`="`,n);if(r<0)break;let i=r;for(;i>0&&Dq(e.charCodeAt(i-1));)i--;if(i===r){n=r+2;continue}let a=e.slice(i,r),o=r+2,s=e.indexOf(`"`,o);if(s<0)break;t[a]=e.slice(o,s),n=s+1}return t}function kq(e,t){let n=[],r=`<${t} `,i=0;for(;i<e.length;){let t=e.indexOf(r,i);if(t<0)break;let a=e.indexOf(`>`,t);if(a<0)break;n.push(e.slice(t,a+1)),i=a+1}return n}function Aq(e,t){let n=e.indexOf(`<${t}`);if(n<0)return null;let r=e.indexOf(`</${t}>`,n);return r<0?null:e.slice(n,r+t.length+3)}function jq(e){let t=e.startsWith(`#`)?e.slice(1):e;return[parseInt(t.slice(0,2),16)/255,parseInt(t.slice(2,4),16)/255,parseInt(t.slice(4,6),16)/255,t.length>=8?parseInt(t.slice(6,8),16)/255:1]}function Mq(e){let t=new Map,n=0;for(;n<e.length;){let r=e.indexOf(`<colorgroup`,n);if(r<0)break;let i=e.indexOf(`</colorgroup>`,r);if(i<0)break;let a=e.slice(r,i+13);n=i+13;let o=e.indexOf(`>`,r);if(o<0)continue;let s=Oq(e.slice(r,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of kq(a,`color`)){let t=Oq(e).color;t!==void 0&&l.push(jq(t))}t.set(c,l)}let r=0;for(;r<e.length;){let n=e.indexOf(`<basematerials`,r);if(n<0)break;let i=e.indexOf(`</basematerials>`,n);if(i<0)break;let a=e.slice(n,i+16);r=i+16;let o=e.indexOf(`>`,n);if(o<0)continue;let s=Oq(e.slice(n,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of kq(a,`base`)){let t=Oq(e).displaycolor;t===void 0?l.push([0,0,0,1]):l.push(jq(t))}t.set(c,l)}return t}function Nq(e){let t=[],n=[],r=[],i=Mq(e);for(let n of kq(e,`vertex`)){let e=Oq(n);e.x!==void 0&&e.y!==void 0&&e.z!==void 0&&t.push([parseFloat(e.x),parseFloat(e.y),parseFloat(e.z)])}let a=null,o=null,s=Aq(e,`object`);if(s!==null){let e=s.indexOf(`>`);if(e>=0){let t=Oq(s.slice(0,e+1));t.pid!==void 0&&(a=parseInt(t.pid,10)),t.pindex!==void 0&&(o=parseInt(t.pindex,10))}}for(let t of kq(e,`triangle`)){let e=Oq(t);if(e.v1!==void 0&&e.v2!==void 0&&e.v3!==void 0){n.push([parseInt(e.v1,10),parseInt(e.v2,10),parseInt(e.v3,10)]);let t=null,s=e.pid??(a===null?void 0:String(a)),c=e.p1??(o===null?void 0:String(o));if(s!==void 0&&c!==void 0){let e=parseInt(s,10),n=parseInt(c,10),r=i.get(e);r!==void 0&&n<r.length&&(t=r[n]??null)}r.push(t)}}return{vertices:t,triangles:n,triangleColors:r}}function Pq(e){let t=new Map;for(let n of e){if(n===null)continue;let e=n.join(`,`),r=t.get(e);r===void 0?t.set(e,{count:1,color:n}):r.count++}let n=null;for(let e of t.values())(n===null||e.count>n.count)&&(n=e);return n===null?null:n.color}function Fq(e){let t=U(),n=e.vertices.map(([e,t,n])=>({x:e,y:t,z:n})),r=e.triangles;try{return O(W(t.buildSolidFromFaces(n,r,1e-6)))}catch{let t=[];for(let[n,r,i]of e.triangles){let a=e.vertices[n],o=e.vertices[r],s=e.vertices[i];!a||!o||!s||t.push([a,o,s])}return xq(t,N.THREEMF_IMPORT_FAILED)}}async function Iq(e){try{let t=await e.arrayBuffer(),n=Eq(new Uint8Array(t),`3D/3dmodel.model`);if(!n)return k(Ua(N.THREEMF_IMPORT_FAILED,`3MF archive does not contain 3D/3dmodel.model (or uses unsupported compression)`));let r=Nq(new TextDecoder().decode(n));if(r.vertices.length===0||r.triangles.length===0)return k(Ua(N.THREEMF_IMPORT_FAILED,`3MF model contains no valid geometry`));let i=Fq(r);if(i.ok){let e=Pq(r.triangleColors);e!==null&&pE(i.value,e)}return i}catch(e){let t=e instanceof Error?e.message:String(e);return k(Ua(N.THREEMF_IMPORT_FAILED,`3MF import failed: ${t}`,e))}}async function Lq(e){try{let t=await e.arrayBuffer();return O(W(U().importGLB(t)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(Ua(N.GLB_IMPORT_FAILED,`Failed to import GLB: ${t}`,e))}}function $(e){return`__wrapped`in e?e.val:e}function Rq(e){return $(e)}function zq(e,t){return xE($(e),t)}function Bq(e,t,n){let r=n?.at;return SE($(e),t,r,n?.axis)}function Vq(e,t){let n=t?.at;return CE($(e),t?.normal??[1,0,0],n)}function Hq(e,t,n){return wE($(e),t,n?.center)}function Uq(e){return ME($(e))}function Wq(e,t){return kE($(e),t)}function Gq(e,t){return jE($(e),t)}function Kq(e,t,n){return HD($(e),$(t),{...n,unsafe:!0})}function qq(e,t,n){return UD($(e),$(t),{...n,unsafe:!0})}function Jq(e,t,n){return WD($(e),$(t),{...n,unsafe:!0})}function Yq(e,t,n){return YD($(e),t,n)}function Xq(e,t,n){return tO($(e),t,n)}function Zq(e,t){return nO($(e),t)}function Qq(e,t,n){return rO($(e),t,n)}function $q(e,t){if(e!==void 0)return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(fj()).findAll(t)}function eJ(e,t){return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(hj()).findAll(t)}function tJ(e){return typeof e==`object`&&!Array.isArray(e)&&typeof e!=`function`?{mode:`distAngle`,distance:e.distance,angle:e.angle}:typeof e==`function`?{mode:`standard`,distance:t=>{let n=e(t);return n===null?null:typeof n==`object`&&!Array.isArray(n)?n.distance:n}}:{mode:`standard`,distance:e}}function nJ(e,t,n){let r=$(e),i,a;return n===void 0?(i=void 0,a=t):(i=$q(t,r),a=n),lk(r,i,a)}function rJ(e,t,n){let r=$(e),i,a;n===void 0?(i=void 0,a=t):(i=$q(t,r),a=n);let o=tJ(a);return o.mode===`distAngle`?xO(r,[...i??ww(r)],o.distance,o.angle):uk(r,i,o.distance)}function iJ(e,t,n,r){let i=$(e);return dk(i,eJ(t,i),n,r?.tolerance)}function aJ(e,t,n){return fk($(e),t,n?.tolerance)}function oJ(e,t){return sk($(e),t)}function sJ(e,t,n){let r=$(e);return mk(r,eJ(t,r),n.pullDirection,n.neutralPlane,n.angle)}function cJ(e){return bk($(e))}function lJ(e){return RE($(e))}function uJ(e,t){return lD($(e),t)}function dJ(e,t){return uD($(e),t)}function fJ(e){return Hw($(e))}function pJ(e){return NE($(e))}function mJ(e){return kT(e)}function hJ(e){return gk($(e))}function gJ(e){return FE($(e))}function _J(e,t){return VN($(e),typeof t==`number`?[0,0,t]:t)}function vJ(e,t){let n=t?.at??[0,0,0];return HN($(e),n,t?.axis??[0,0,1],t?.angle??360)}function yJ(e,t){return EV(e.map(e=>$(e)),t)}function bJ(e,n){if(n===void 0){let t=Tw(e);if(t.length===0)return k(F(N.COMPOUND_NO_FACES,`compoundOps: shape has no faces`));let n=yD(t),r=BT(n)[2];for(let e=1;e<t.length;e++){let i=vD(t,e),a=BT(i)[2];a>r&&(n=i,r=a)}return O(n)}if(typeof n==`function`){let r=n(hj()).findAll(e);return r.length===0?k(Wa(N.COMPOUND_FACE_NOT_FOUND,`compoundOps: face finder matched no faces`)):O(t(r,0))}return O(n)}function xJ(e){return`sketchOnPlane`in e&&typeof e.sketchOnPlane==`function`?e.sketchOnPlane(`XY`).wire:e}function SJ(e,t){let n=$(e),{at:r,radius:i,axis:a}=t,o=a??[0,0,1];if(i<=0)return k(F(`DRILL_INVALID_RADIUS`,`Drill radius must be positive`));if(sT(o))return k(F(`DRILL_ZERO_AXIS`,`Drill axis cannot be zero`));let s=aT(o),c=r.length===2?[r[0],r[1],0]:[r[0],r[1],r[2]],l;if(t.depth!==void 0)l=cO(i,t.depth,c,s);else{let e=Rw(n),t=[[e.xMin,e.yMin,e.zMin],[e.xMax,e.yMin,e.zMin],[e.xMin,e.yMax,e.zMin],[e.xMax,e.yMax,e.zMin],[e.xMin,e.yMin,e.zMax],[e.xMax,e.yMin,e.zMax],[e.xMin,e.yMax,e.zMax],[e.xMax,e.yMax,e.zMax]],r=1/0,a=-1/0;for(let e of t){let t=(e[0]-c[0])*s[0]+(e[1]-c[1])*s[1]+(e[2]-c[2])*s[2];t<r&&(r=t),t>a&&(a=t)}--r,a+=1,l=cO(i,a-r,[c[0]+s[0]*r,c[1]+s[1]*r,c[2]+s[2]*r],s)}return UD(n,l,{unsafe:!0})}function CJ(e,t){let n=$(e),{profile:r,depth:i}=t;if(i<=0)return k(F(`POCKET_INVALID_DEPTH`,`Pocket depth must be positive`));let a=bJ(n,t.face);if(A(a))return a;let o=a.value,s=zT(o),c=BT(o),l=PD(xJ(r));if(A(l))return l;let u=VN(xE(l.value,c),Qw(aT(s),-i));return A(u)?u:UD(n,u.value,{unsafe:!0})}function wJ(e,t){let n=$(e),{profile:r,height:i}=t;if(i<=0)return k(F(`BOSS_INVALID_HEIGHT`,`Boss height must be positive`));let a=bJ(n,t.face);if(A(a))return a;let o=a.value,s=zT(o),c=BT(o),l=PD(xJ(r));if(A(l))return l;let u=VN(xE(l.value,c),Qw(aT(s),i));return A(u)?u:HD(n,u.value,{unsafe:!0})}function TJ(e,t){let n=$(e),r=t?.normal??[1,0,0],i=t?.at;return sT(r)?k(F(`MIRROR_ZERO_NORMAL`,`Mirror plane normal cannot be zero`)):HD(n,CE(n,r,i),{unsafe:!0})}function EJ(e,t){let n=$(e),{xDir:r,xCount:i,xSpacing:a,yDir:o,yCount:s,ySpacing:c}=t;if(i<1||s<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern counts must be at least 1`));if(sT(r))return k(F(`PATTERN_ZERO_DIRECTION`,`X direction cannot be zero`));if(sT(o))return k(F(`PATTERN_ZERO_DIRECTION`,`Y direction cannot be zero`));if(i===1&&s===1)return O(n);let l=aT(r),u=aT(o),d=[n];for(let e=0;e<i;e++)for(let t=0;t<s;t++){if(e===0&&t===0)continue;let r=[l[0]*a*e+u[0]*c*t,l[1]*a*e+u[1]*c*t,l[2]*a*e+u[2]*c*t];d.push(xE(n,r))}return KD(d,{unsafe:!0})}var DJ=class extends Error{code;kind;suggestion;metadata;constructor(e){let t=e.suggestion?`${e.message}\nSuggestion: ${e.suggestion}`:e.message;super(t),this.name=`BrepError`,this.code=e.code,this.kind=e.kind,e.suggestion&&(this.suggestion=e.suggestion),e.metadata&&(this.metadata=e.metadata)}};function OJ(e){if(A(e))throw new DJ(e.error);return e.value}function kJ(e){return e}function AJ(e){return e}function jJ(e){return e}function MJ(e){return e}function NJ(e){return{val:e,__wrapped:!0,translate:t=>UJ(zq(e,t)),rotate:(t,n)=>UJ(Bq(e,t,n)),mirror:t=>UJ(Vq(e,t)),scale:(t,n)=>UJ(Hq(e,t,n)),applyMatrix:t=>UJ(OJ(Wq(e,t))),moveX:t=>UJ(zq(e,[t,0,0])),moveY:t=>UJ(zq(e,[0,t,0])),moveZ:t=>UJ(zq(e,[0,0,t])),rotateX:t=>UJ(Bq(e,t,{axis:[1,0,0]})),rotateY:t=>UJ(Bq(e,t,{axis:[0,1,0]})),rotateZ:t=>UJ(Bq(e,t,{axis:[0,0,1]})),bounds:()=>Rw(e),describe:()=>fJ(e),clone:()=>UJ(OJ(Uq(e))),mesh:t=>uJ(e,t),meshEdges:t=>dJ(e,t),isValid:()=>hJ(e),isEmpty:()=>gJ(e),heal:()=>UJ(OJ(cJ(e))),simplify:()=>UJ(OJ(lJ(e))),toBREP:()=>OJ(pJ(e)),apply:t=>UJ(t(e)),applyResult:t=>UJ(OJ(t(e))),done:()=>e}}function PJ(e){return{fuse:(t,n)=>WJ(OJ(Kq(e,$(t),{...n,unsafe:!0}))),cut:(t,n)=>WJ(OJ(qq(e,$(t),{...n,unsafe:!0}))),intersect:(t,n)=>WJ(OJ(Jq(e,$(t),{...n,unsafe:!0}))),fuseAll:(t,n)=>WJ(MJ(OJ(KD([e,...t.map($)],{...n,unsafe:!0})))),cutAll:(t,n)=>WJ(MJ(OJ(qD(e,t,{...n,unsafe:!0})))),section:(t,n)=>UJ(OJ(Yq(e,t,n))),split:t=>UJ(OJ(Zq(e,t))),slice:(t,n)=>OJ(Qq(e,t,n))}}function FJ(e){return{fillet(...t){return t.length===1?WJ(MJ(OJ(nJ(kJ(e),t[0])))):WJ(MJ(OJ(nJ(kJ(e),t[0],t[1]))))},chamfer(...t){return t.length===1?WJ(MJ(OJ(rJ(kJ(e),t[0])))):WJ(MJ(OJ(rJ(kJ(e),t[0],t[1]))))},shell:(t,n,r)=>WJ(MJ(OJ(iJ(kJ(e),t,n,r)))),offset:(t,n)=>WJ(MJ(OJ(aJ(kJ(e),t,n)))),draft:(t,n)=>WJ(MJ(OJ(sJ(kJ(e),t,n))))}}function IJ(e){return{drill:t=>WJ(OJ(SJ(e,t))),pocket:t=>WJ(OJ(CJ(e,t))),boss:t=>WJ(OJ(wJ(e,t))),mirrorJoin:t=>WJ(OJ(TJ(e,t))),rectangularPattern:t=>WJ(OJ(EJ(e,t)))}}function LJ(e){return{volume:()=>OJ(PA(e)),area:()=>OJ(FA(e)),volumeProps:()=>OJ(jA(e)),surfaceProps:()=>OJ(MA(e))}}function RJ(e){return{edges:()=>ww(e),faces:()=>Tw(e),wires:()=>Ew(e),vertices:()=>Dw(e)}}function zJ(e){return{linearPattern:(t,n,r)=>WJ(MJ(OJ(tA(e,t,n,r)))),circularPattern:(t,n,r)=>WJ(MJ(OJ(nA(e,t,n,r))))}}function BJ(e){return{...NJ(e),...PJ(e),...FJ(e),...IJ(e),...LJ(e),...RJ(e),...zJ(e)}}function VJ(e){return{...NJ(e),length:()=>WE(e),startPoint:()=>BE(e),endPoint:()=>VE(e),pointAt:t=>HE(e,t),tangentAt:t=>UE(e,t),isClosed:()=>GE(e),sweep(t,n){if(!aw(e))throw Error(`sweep requires a Wire`);let r=OJ(NN(jJ(e),$(t),n));return WJ(Array.isArray(r)?r[0]:r)}}}function HJ(e){return{...NJ(e),area:()=>OJ(FA(e)),normalAt:t=>zT(e,t),center:()=>BT(e),surfaceType:()=>OJ(jT(e)),outerWire:()=>HT(e),innerWires:()=>WT(e),extrude:t=>WJ(OJ(_J(AJ(e),t))),revolve:t=>WJ(OJ(vJ(AJ(e),t)))}}function UJ(e){return uw(e)?BJ(e):ow(e)?HJ(e):iw(e)||aw(e)?VJ(e):NJ(e)}function WJ(e){return BJ(e)}function GJ(e){if(e&&typeof e==`object`&&`face`in e&&typeof e.face==`function`&&`_defaultOrigin`in e)return HJ(e.face());if(e&&typeof e==`object`&&`wrapped`in e)return ow(e)?HJ(e):uw(e)?BJ(e):iw(e)||aw(e)?VJ(e):NJ(e);throw Error(`shape() requires a Sketch or branded shape type`)}var KJ=.25,qJ=e=>Math.tan(e)-e;function JJ(e,t,n,r){let i=e/Math.cos(t),a=n+r*(Math.tan(t)-t);return[i*Math.cos(a),i*Math.sin(a),0]}function YJ(e,t,n,r,i){let a=[];for(let o=0;o<=r;o++){let s=.5-.5*Math.cos(o/r*Math.PI);a.push(JJ(e,s*t,n,i))}return a}function XJ(e){return Math.max(16,Math.round(8*Math.sqrt(e)))}function ZJ(e,t,n,r,i,a,o){let s=e*t/2,c=s*Math.cos(n),l=t*(1+r),u=t*(1+i-r),d=o?s-t*(1-r):s+l,f=o?s+t*(1+i+r):s-u,p=a/s,m=(Math.PI/2+2*r*Math.tan(n))/e+(o?p:-p),h=o?f:d;return{rPitch:s,rb:c,rTip:d,rRoot:f,alphaPitch:n,halfToothAngle:m,alphaTip:h<=c?0:Math.acos(Math.min(1,c/h)),toothPitch:2*Math.PI/e,isInternal:o}}function QJ(e,t,n){if(t===0)return O(e);let r=qJ(e)+2*t*Math.tan(e)/n,i,a;if(r>qJ(e)?(i=e,a=Math.PI/2-1e-6):(i=1e-4,a=e),r>qJ(a)||r<qJ(i))return k(F(`GEAR_PA_OUT_OF_RANGE`,`working pressure angle out of range — target inv(αw)=${r.toFixed(4)} not in [${qJ(i).toFixed(4)}, ${qJ(a).toFixed(4)}]`,void 0,{target:r,invLo:qJ(i),invHi:qJ(a)}));for(let e=0;e<50;e++){let e=.5*(i+a);qJ(e)<r?i=e:a=e}return O(.5*(i+a))}function $J(e,t,n,r,i){return QJ(e,t+n,r+i)}function eY(e,t,n,r,i){return QJ(e,n-t,i-r)}function tY(e,t,n,r,i){return(e+t)*n*Math.cos(r)/(2*Math.cos(i))}function nY(e,t,n,r){if(!Number.isInteger(e)||!Number.isInteger(t)||!Number.isInteger(n))return k(F(`GEAR_NON_INTEGER_TEETH`,`tooth counts and planet count must be integers`));if(e<4||t<4||n<2)return k(F(`GEAR_TEETH_TOO_FEW`,`zs ≥ 4, zp ≥ 4, N ≥ 2 required`));if((2*e+2*t)%n!=0)return k(F(`GEAR_ASSEMBLY`,`(2·zs + 2·zp) must be divisible by N — got ${2*e+2*t} mod ${n} = ${(2*e+2*t)%n}`));let i=t+2+2*r,a=(e+t)*Math.sin(Math.PI/n);return a<=i?k(F(`GEAR_PLANET_COLLISION`,`planet tips would collide: (zs+zp)·sin(π/N) = ${a.toFixed(3)} ≤ planet tip = ${i.toFixed(3)}`)):O(void 0)}function rY(e,t,n,r,i,a,o,s){return(Math.sqrt(Math.max(0,e*e-t*t))+Math.sqrt(Math.max(0,n*n-r*r))-i*Math.sin(s))/(Math.PI*a*Math.cos(o))}function iY(e,t,n,r,i,a,o,s){return(Math.sqrt(Math.max(0,e*e-t*t))-Math.sqrt(Math.max(0,n*n-r*r))+i*Math.sin(s))/(Math.PI*a*Math.cos(o))}function aY(e,t){return 1-e*Math.sin(t)*Math.sin(t)/2}function oY(e,t,n){return Math.max(0,aY(e,t)-n)}function sY(e){return e<8?.2:.485-2.88/e}function cY(e,t,n,r){let i=e*1e3,a=sY(r);return a<=0||n<=0||t<=0?1/0:2*i/(r*t*t*n*a)}function lY(e,t,n=!1){let r=(1.4+6.5/e)*(20/(t*180/Math.PI))**.15;return n?r*.85:r}function uY(e,t,n,r,i,a=!1){return cY(e,t,n,r)*lY(r,i,a)}function dY(e){return e/2}function fY(e,t){return e+2*t}function pY(e){return e%2==0?Math.PI/e:0}function mY(e,t,n){return e*(1+t/n)+pY(n)}function hY(e={}){let t=e.moduleSize??3,n=e.sunTeeth??15,r=e.planetTeeth??12,i=e.numPlanets??3,a=(e.pressureAngleDeg??20)*Math.PI/180,o=e.sunShift??0,s=e.planetShift??0,c=nY(n,r,i,s);if(A(c))return c;let l=$J(a,o,s,n,r);if(A(l))return l;let u=tY(n,r,t,a,l.value),d=[];for(let e=0;e<i;e++){let t=e*2*Math.PI/i,a=mY(t,n,r);d.push({rotationDeg:a*180/Math.PI,position:[u*Math.cos(t),u*Math.sin(t),0]})}return O(d)}function gY(e,t,n,r,i){let a=t*e.toothPitch,o=(t+1)%n*e.toothPitch,s=qJ(e.alphaPitch),c=a-e.halfToothAngle-s,l=a+e.halfToothAngle+s,u=YJ(e.rb,e.alphaTip,c,r,1),d=YJ(e.rb,e.alphaTip,l,r,-1).reverse(),f=yD(u),p=bD(u),m=yD(d),h=bD(d),g=[],_=e=>{i.register(e),g.push(e)},v=e.isInternal?e.rb<e.rRoot:e.rb>e.rRoot;v&&_(CD([e.rRoot*Math.cos(c),e.rRoot*Math.sin(c),0],f));let y=e.rPitch*1e-5,b=AD(u,{tolerance:y});if(A(b))return b;_(b.value),_(DD(p,[e.rTip*Math.cos(a),e.rTip*Math.sin(a),0],m));let x=AD(d,{tolerance:y});if(A(x))return x;_(x.value),v&&_(CD(h,[e.rRoot*Math.cos(l),e.rRoot*Math.sin(l),0]));let S=o-e.halfToothAngle-s,C=.5*(l+S);return S<l&&(C+=Math.PI),_(DD(v?[e.rRoot*Math.cos(l),e.rRoot*Math.sin(l),0]:h,[e.rRoot*Math.cos(C),e.rRoot*Math.sin(C),0],v?[e.rRoot*Math.cos(S),e.rRoot*Math.sin(S),0]:[e.rb*Math.cos(S),e.rb*Math.sin(S),0])),O(g)}function _Y(e){return yY(e,!1)}function vY(e){return yY(e,!0)}function yY(e,t){try{var n=lC();let{teeth:r,moduleSize:i,pressureAngle:a,shift:o,clearance:s,flankThinning:c,samples:l=XJ(i)}=e;if(r<4)return k(F(`GEAR_TEETH_TOO_FEW`,`gear needs ≥ 4 teeth, got ${r}`));if(i<=0)return k(F(`GEAR_MODULE_NONPOSITIVE`,`module must be > 0, got ${i}`));let u=ZJ(r,i,a,o,s,c,t),d=n.u(new xC),f=[];for(let e=0;e<r;e++){let t=gY(u,e,r,l,d);if(A(t))return t;f.push(...t.value)}let p=ND(f);return A(p)?p:O(p.value)}catch(e){n.e=e}finally{n.d()}}function bY(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=KJ,flankThinning:s=0,bore:c=0,samples:l}=e;if(r<=0)return k(F(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));if(l!==void 0&&(!Number.isInteger(l)||l<1))return k(F(`GEAR_SAMPLES_INVALID`,`samples must be a positive integer; got ${String(l)}`));let u=i*Math.PI/180,d=ZJ(t,n,u,a,o,s,!1);if(c>0&&c>=2*d.rRoot)return k(F(`GEAR_BORE_TOO_LARGE`,`bore diameter ${c.toFixed(2)} ≥ root diameter ${(2*d.rRoot).toFixed(2)} — would erase the gear teeth`));let f=_Y({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(f))return f;let p=SY(t,u,a);return DY(f.value,r,c,d,p)}function xY(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=KJ,flankThinning:s=0,ringWallThickness:c=2*e.moduleSize,samples:l}=e;if(r<=0)return k(F(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));if(c<=0)return k(F(`GEAR_WALL_NONPOSITIVE`,`ringWallThickness must be > 0`));if(l!==void 0&&(!Number.isInteger(l)||l<1))return k(F(`GEAR_SAMPLES_INVALID`,`samples must be a positive integer; got ${String(l)}`));let u=i*Math.PI/180,d=vY({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(d))return d;let f=ZJ(t,n,u,a,o,s,!0),p=EY(f.rPitch+c);return A(p)?p:kY(p.value,d.value,r,f,[])}function SY(e,t,n){let r=oY(e,t,n);return r<=0?[]:[{code:`UNDERCUT_RISK`,severity:`warning`,message:`gear is undercut: increase shift by ${r.toFixed(3)} to avoid (z=${e})`,context:{deficit:r,teeth:e}}]}function CY(e){let t=TY(e);if(A(t))return t;let n=t.value,r=wY(n);if(A(r))return r;let{sun:i,planet:a,ring:o}=r.value,s=NY(n,i,a,o),c=jY(a.solid,n);a.solid.delete();let l=MY(o.solid,n.zr),u=PY(n,s);return O({sun:i.solid,planets:c,ring:l,ringTeeth:n.zr,workingPressureAngle:n.alphaW_sp,centerDistance:n.centerDistance,contactRatio:{sunPlanet:s.crSunPlanet,planetRing:s.crPlanetRing},undercutDeficit:{sun:s.undercutSun,planet:s.undercutPlanet},...s.lewisStress?{lewisStress:s.lewisStress}:{},...s.stressConcentrationFactor?{stressConcentrationFactor:s.stressConcentrationFactor}:{},diagnostics:u})}function wY(e){let t=e.samples===void 0?{}:{samples:e.samples},n={moduleSize:e.moduleSize,thickness:e.thickness,pressureAngleDeg:e.pressureAngleDeg,clearance:e.clearance,flankThinning:e.bHalf,...t},r=bY({...n,teeth:e.sunTeeth,shift:e.sunShift,bore:e.sunBore});if(A(r))return r;let i=bY({...n,teeth:e.planetTeeth,shift:e.planetShift,bore:e.planetBore});if(A(i))return r.value.solid.delete(),i;let a=xY({...n,teeth:e.zr,shift:e.ringShift,ringWallThickness:e.ringWallThickness});return A(a)?(r.value.solid.delete(),i.value.solid.delete(),a):O({sun:r.value,planet:i.value,ring:a.value})}function TY(e){let t=e.moduleSize??3,n=e.sunTeeth??15,r=e.planetTeeth??12,i=e.numPlanets??3,a=e.pressureAngleDeg??20,o=a*Math.PI/180,s=e.sunShift??0,c=e.planetShift??0,l=e.ringShift??0;if(e.thickness<=0)return k(F(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));let u=nY(n,r,i,c);if(A(u))return u;let d=fY(n,r),f=$J(o,s,c,n,r);if(A(f))return f;let p=eY(o,c,l,r,d);if(A(p))return p;let m=tY(n,r,t,o,f.value);return O({moduleSize:t,sunTeeth:n,planetTeeth:r,numPlanets:i,pressureAngleDeg:a,alpha:o,alphaW_sp:f.value,alphaW_pr:p.value,clearance:e.clearance??.25,bHalf:dY(e.backlash??0),sunShift:s,planetShift:c,ringShift:l,ringWallThickness:e.ringWallThickness??2*t,thickness:e.thickness,sunBore:e.sunBore??0,planetBore:e.planetBore??0,...e.appliedTorque===void 0?{}:{appliedTorque:e.appliedTorque},...e.samples===void 0?{}:{samples:e.samples},zr:d,centerDistance:m})}function EY(e){try{var t=lC();let n=ND([t.u(new xC).register(wD(e,[0,0,0],[0,0,1]))]);return A(n)?n:O(n.value)}catch(e){t.e=e}finally{t.d()}}function DY(e,t,n,r,i){try{var a=lC();let o=PD(e);if(A(o))return o;let s=VN(o.value,[0,0,t]);if(A(s))return s;if(n<=0)return O(AY(s.value,r,i));let c=a.u(new xC),l=OY(n/2);if(A(l))return l;c.register(l.value);let u=VN(l.value,[0,0,t+1]);if(A(u))return u;c.register(u.value);let d=c.register(xE(u.value,[0,0,-.5])),f=UD(s.value,d);return A(f)?f:O(AY(f.value,r,i))}catch(e){a.e=e}finally{a.d()}}function OY(e){let t=EY(e);return A(t)?t:PD(t.value)}function kY(e,t,n,r,i){let a=PD(e,[t]);if(A(a))return a;let o=VN(a.value,[0,0,n]);return A(o)?o:O(AY(o.value,r,i))}function AY(e,t,n=[]){return{solid:e,diagnostics:n,pitchDiameter:2*t.rPitch,baseDiameter:2*t.rb,tipDiameter:2*t.rTip,rootDiameter:2*t.rRoot}}function jY(e,t){let n=[];try{for(let r=0;r<t.numPlanets;r++){let i=r*2*Math.PI/t.numPlanets,a=SE(e,mY(i,t.sunTeeth,t.planetTeeth)*180/Math.PI);try{let e=[t.centerDistance*Math.cos(i),t.centerDistance*Math.sin(i),0];n.push(xE(a,e))}finally{a.delete()}}return n}catch(e){for(let e of n)e.delete();throw e}}function MY(e,t){let n=pY(t);if(n===0)return e;let r=SE(e,n*180/Math.PI);return e.delete(),r}function NY(e,t,n,r){let i={crSunPlanet:rY(t.tipDiameter/2,t.baseDiameter/2,n.tipDiameter/2,n.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_sp),crPlanetRing:iY(n.tipDiameter/2,n.baseDiameter/2,r.tipDiameter/2,r.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_pr),undercutSun:oY(e.sunTeeth,e.alpha,e.sunShift),undercutPlanet:oY(e.planetTeeth,e.alpha,e.planetShift)};if(e.appliedTorque!==void 0){let t=e.appliedTorque;i.lewisStress={sun:uY(t,e.moduleSize,e.thickness,e.sunTeeth,e.alpha),planet:uY(t*e.planetTeeth/e.sunTeeth,e.moduleSize,e.thickness,e.planetTeeth,e.alpha),ring:uY(t*e.zr/e.sunTeeth,e.moduleSize,e.thickness,e.zr,e.alpha,!0)},i.stressConcentrationFactor={sun:lY(e.sunTeeth,e.alpha),planet:lY(e.planetTeeth,e.alpha),ring:lY(e.zr,e.alpha,!0)}}return i}function PY(e,t){let n=[];t.crSunPlanet<1.2&&n.push({code:`CONTACT_RATIO_LOW_SUN_PLANET`,severity:`warning`,message:`sun-planet contact ratio ${t.crSunPlanet.toFixed(2)} is below 1.2 — may run unevenly`,context:{value:t.crSunPlanet}}),t.crPlanetRing<1.2&&n.push({code:`CONTACT_RATIO_LOW_PLANET_RING`,severity:`warning`,message:`planet-ring contact ratio ${t.crPlanetRing.toFixed(2)} is below 1.2 — may run unevenly`,context:{value:t.crPlanetRing}}),t.undercutSun>0&&n.push({code:`UNDERCUT_RISK_SUN`,severity:`warning`,message:`sun gear is undercut: increase sunShift by ${t.undercutSun.toFixed(3)} to avoid`,context:{deficit:t.undercutSun,sunTeeth:e.sunTeeth}}),t.undercutPlanet>0&&n.push({code:`UNDERCUT_RISK_PLANET`,severity:`warning`,message:`planet gear is undercut: increase planetShift by ${t.undercutPlanet.toFixed(3)} to avoid`,context:{deficit:t.undercutPlanet,planetTeeth:e.planetTeeth}});let r=Math.abs(e.sunShift)+Math.abs(e.planetShift)+Math.abs(e.ringShift);e.appliedTorque!==void 0&&r>.05&&n.push({code:`LEWIS_Y_SHIFT_UNCORRECTED`,severity:`info`,message:`Lewis stress uses unshifted Y(z) and K_f approximations; expect ±5% per 0.1 of profile shift`});let i=e.ringShift-(e.sunShift+2*e.planetShift);return Math.abs(i)>1e-6&&n.push({code:`PLANETARY_SHIFT_KINEMATIC_MISMATCH`,severity:`warning`,message:`ringShift should equal sunShift + 2·planetShift for both meshes to share working PA; off by ${i.toFixed(3)}`,context:{kinematicError:i,sunShift:e.sunShift,planetShift:e.planetShift,ringShift:e.ringShift}}),n}var FY=SG({addHoles:()=>Zk,bezier:()=>Rk,box:()=>Tk,bsplineApprox:()=>Lk,circle:()=>Mk,compound:()=>qk,cone:()=>Ok,cylinder:()=>Ek,ellipse:()=>Nk,ellipseArc:()=>Ik,ellipsoid:()=>Ak,face:()=>Hk,fill:()=>FD,filledFace:()=>Uk,helix:()=>Pk,line:()=>jk,offsetFace:()=>Yk,polygon:()=>Gk,polyhedron:()=>LK,sewShells:()=>Xk,solid:()=>Jk,sphere:()=>Dk,subFace:()=>Wk,tangentArc:()=>zk,threePointArc:()=>Fk,torus:()=>kk,vertex:()=>Kk,wire:()=>Bk,wireLoop:()=>Vk}),IY=SG({checkBoolean:()=>WO,convexHull:()=>MK,cut:()=>qq,cutAll:()=>qD,cutAllBisect:()=>FO,fuse:()=>Kq,fuseAll:()=>KD,fuseAllBisect:()=>zO,hull:()=>jK,intersect:()=>Jq,minkowski:()=>IK,section:()=>Yq,sectionToFace:()=>Xq,slice:()=>Qq,split:()=>Zq}),LY=SG({chamfer:()=>rJ,draft:()=>sJ,fillet:()=>nJ,heal:()=>cJ,offset:()=>aJ,shell:()=>iJ,simplify:()=>lJ,thicken:()=>oJ,variableFillet:()=>hk}),RY=SG({applyMatrix:()=>Wq,clone:()=>Uq,composeTransforms:()=>AE,mirror:()=>Vq,rotate:()=>Bq,scale:()=>Hq,transformCopy:()=>Gq,translate:()=>zq}),zY=SG({checkAllInterferences:()=>hq,checkInterference:()=>mq,createDistanceQuery:()=>zA,measureArea:()=>FA,measureCurvatureAt:()=>BA,measureCurvatureAtMid:()=>VA,measureDistance:()=>LA,measureDistanceProps:()=>RA,measureLength:()=>IA,measureLinearProps:()=>NA,measureSurfaceProps:()=>MA,measureVolume:()=>PA,measureVolumeProps:()=>jA}),BY=SG({blueprintToDXF:()=>aW,exportAssemblySTEP:()=>eA,exportDXF:()=>iW,exportGlb:()=>GU,exportGltf:()=>WU,exportIGES:()=>gD,exportOBJ:()=>IU,exportSTEP:()=>mD,exportSTEPConfigured:()=>HW,exportSTL:()=>hD,exportThreeMF:()=>wW,importDXF:()=>bq,importGLB:()=>Lq,importIGES:()=>GW,importOBJ:()=>wq,importSTEP:()=>UW,importSTL:()=>WW,importSVG:()=>VW,importSVGPathD:()=>BW,importThreeMF:()=>Iq}),VY=SG({cornerFinder:()=>HM,edgeFinder:()=>fj,faceFinder:()=>hj,getSingleFace:()=>vj,vertexFinder:()=>jG,wireFinder:()=>_j}),HY=SG({complexExtrude:()=>FN,extrude:()=>_J,guidedSweep:()=>BN,loft:()=>yJ,multiSectionSweep:()=>zN,revolve:()=>vJ,roof:()=>oq,supportExtrude:()=>PN,surfaceFromGrid:()=>EK,surfaceFromImage:()=>kK,sweep:()=>NN,twistExtrude:()=>IN}),UY=SG({circularPattern:()=>nA,linearPattern:()=>tA}),WY=14695981039346656037n,GY=1099511628211n,KY=18446744073709551615n;function qY(){return WY}function JY(e,t){return(e^BigInt(t&255))*GY&KY}function YY(e,t){let n=e;for(let e=0;e<t.length;e++)n=JY(n,t[e]??0);return n}var XY=new TextEncoder;function ZY(e,t){return YY(e,XY.encode(t))}var QY=new ArrayBuffer(8),$Y=new DataView(QY),eX=new Uint8Array(QY);function tX(e,t){return $Y.setFloat64(0,Object.is(t,-0)?0:t),YY(e,eX)}function nX(e,t){let n=e,r=t&KY;for(let e=0;e<8;e++)n=JY(n,Number(r&255n)),r>>=8n;return n}function rX(e,t){let n=e,r=t|0;for(let e=0;e<4;e++)n=JY(n,r&255),r>>>=8;return n}function iX(e,t){return JY(e,+!!t)}function aX(e){return(e&KY).toString(16).padStart(16,`0`)}var oX=new Set;function sX(e){return ZY(qY(),e)}function cX(e){return{kind:`NumLit`,value:e,structuralHash:tX(sX(`NumLit`),e),freeParams:oX}}function lX(e){let t=sX(`Vec3Lit`);for(let n of e)t=tX(t,n);return{kind:`Vec3Lit`,value:e,structuralHash:t,freeParams:oX}}function uX(e){let t=sX(`Vec2Lit`);for(let n of e)t=tX(t,n);return{kind:`Vec2Lit`,value:e,structuralHash:t,freeParams:oX}}function dX(e){return{kind:`Param`,name:e,structuralHash:ZY(sX(`Param`),e),freeParams:new Set([e])}}function fX(e,t,n){let r=ZY(sX(`BinOp`),e);return r=nX(r,t.structuralHash),r=nX(r,n.structuralHash),{kind:`BinOp`,op:e,a:t,b:n,structuralHash:r,freeParams:SX(t.freeParams,n.freeParams)}}function pX(e,t){let n=ZY(sX(`UnaryOp`),e);return n=nX(n,t.structuralHash),{kind:`UnaryOp`,op:e,arg:t,structuralHash:n,freeParams:t.freeParams}}function mX(e,t){let n=rX(sX(`Component`),t);return n=nX(n,e.structuralHash),{kind:`Component`,vec:e,index:t,structuralHash:n,freeParams:e.freeParams}}function hX(e,t){let n=rX(sX(`BuildVec`),e),r=new Set;for(let e of t){n=nX(n,e.structuralHash);for(let t of e.freeParams)r.add(t)}return{kind:`BuildVec`,dim:e,components:t,structuralHash:n,freeParams:r}}var gX=(e,t)=>fX(`+`,e,t),_X=(e,t)=>fX(`*`,e,t);function vX(e){return typeof e==`number`?cX(e):e}function yX(e,t){if(!Array.isArray(e))return e;let n=e;return n.every(e=>typeof e==`number`)?t===3?lX([n[0],n[1],n[2]]):uX([n[0],n[1]]):hX(t,n.map(vX))}function bX(e){return yX(e,3)}function xX(e){return yX(e,2)}function SX(e,t){if(e.size===0)return t;if(t.size===0)return e;let n=new Set(e);for(let e of t)n.add(e);return n}function CX(e){return typeof e==`number`}function wX(e,t){return CX(e)?O(e):k(F(N.NULL_SHAPE_INPUT,`${t}: expected number, got ${Array.isArray(e)?`vector(${e.length})`:typeof e}`))}function TX(e,t,n){return Array.isArray(e)&&e.length===t?O(e):k(F(N.NULL_SHAPE_INPUT,`${n}: expected Vec${t}, got ${CX(e)?`number`:`vector(${e.length})`}`))}function EX(e,t){switch(e.kind){case`NumLit`:return O(e.value);case`Vec3Lit`:return O(e.value);case`Vec2Lit`:return O(e.value);case`Param`:{let n=t[e.name];return n===void 0?k(F(N.NULL_SHAPE_INPUT,`unbound param: ${e.name}`)):O(n)}case`BinOp`:return DX(e,t);case`UnaryOp`:return OX(e,t);case`Component`:return kX(e,t);case`BuildVec`:return AX(e,t)}}function DX(e,t){let n=EX(e.a,t);if(!n.ok)return n;let r=EX(e.b,t);if(!r.ok)return r;let i=wX(n.value,`BinOp(${e.op}).a`);if(!i.ok)return i;let a=wX(r.value,`BinOp(${e.op}).b`);if(!a.ok)return a;switch(e.op){case`+`:return O(i.value+a.value);case`-`:return O(i.value-a.value);case`*`:return O(i.value*a.value);case`/`:return a.value===0?k(F(N.NULL_SHAPE_INPUT,`BinOp(/): division by zero`)):O(i.value/a.value)}}function OX(e,t){let n=EX(e.arg,t);if(!n.ok)return n;let r=wX(n.value,`UnaryOp(${e.op})`);if(!r.ok)return r;let i=r.value;switch(e.op){case`neg`:return O(-i);case`sin`:return O(Math.sin(i));case`cos`:return O(Math.cos(i));case`sqrt`:return O(Math.sqrt(i));case`abs`:return O(Math.abs(i))}}function kX(e,t){let n=EX(e.vec,t);if(!n.ok)return n;if(CX(n.value))return k(F(N.NULL_SHAPE_INPUT,`Component: cannot index a scalar`));let r=n.value,i=r[e.index];return i===void 0?k(F(N.NULL_SHAPE_INPUT,`Component: index ${e.index} out of range for Vec${r.length}`)):O(i)}function AX(e,t){if(e.components.length!==e.dim)return k(F(N.NULL_SHAPE_INPUT,`BuildVec(${e.dim}): expected ${e.dim} components, got ${e.components.length}`));let n=[];for(let r of e.components){let e=EX(r,t);if(!e.ok)return e;let i=wX(e.value,`BuildVec.component`);if(!i.ok)return i;n.push(i.value)}return O(e.dim===2?[n[0],n[1]]:[n[0],n[1],n[2]])}function jX(e,t,n){let r=EX(e,t);return r.ok?wX(r.value,n):r}function MX(e,t,n){let r=EX(e,t);if(!r.ok)return r;let i=TX(r.value,3,n);if(!i.ok)return i;let[a,o,s]=i.value;return O([a,o,s])}function NX(e,t){if(t.size===0)return Object.freeze({});let n={};for(let r of t){let t=e[r];t!==void 0&&(n[r]=t)}return Object.freeze(n)}var PX=new Set;function FX(e){return ZY(qY(),e)}function IX(e,t){return nX(e,t.structuralHash)}function LX(e,t){return t===void 0?iX(e,!1):IX(iX(e,!0),t)}function RX(e,t){return t===void 0?iX(e,!1):tX(iX(e,!0),t)}function zX(...e){let t=new Set;for(let n of e)if(n)for(let e of n.freeParams)t.add(e);return t.size===0?PX:t}function BX(e,t,n){let r=vX(e),i=vX(t),a=vX(n),o=FX(`Box`);return o=IX(IX(IX(o,r),i),a),{kind:`Box`,x:r,y:i,z:a,structuralHash:o,freeParams:zX(r,i,a)}}function VX(e){let t=vX(e);return{kind:`Sphere`,radius:t,structuralHash:IX(FX(`Sphere`),t),freeParams:t.freeParams}}function HX(e,t){let n=vX(e),r=vX(t);return{kind:`Cylinder`,radius:n,height:r,structuralHash:IX(IX(FX(`Cylinder`),n),r),freeParams:zX(n,r)}}function UX(e,t,n){let r=vX(e),i=vX(t),a=vX(n),o=FX(`Cone`);return o=IX(IX(IX(o,r),i),a),{kind:`Cone`,radius1:r,radius2:i,height:a,structuralHash:o,freeParams:zX(r,i,a)}}function WX(e,t){let n=vX(e),r=vX(t);return{kind:`Torus`,majorRadius:n,minorRadius:r,structuralHash:IX(IX(FX(`Torus`),n),r),freeParams:zX(n,r)}}function GX(e){let t=e.map(bX),n=rX(FX(`Polygon`),t.length);for(let e of t)n=IX(n,e);return{kind:`Polygon`,points:t,structuralHash:n,freeParams:zX(...t)}}function KX(e){let t=vX(e);return{kind:`Circle`,radius:t,structuralHash:IX(FX(`Circle`),t),freeParams:t.freeParams}}function qX(e,t){let n=bX(e),r=bX(t);return{kind:`Line`,from:n,to:r,structuralHash:IX(IX(FX(`Line`),n),r),freeParams:zX(n,r)}}function JX(e){let t=bX(e);return{kind:`Vertex`,point:t,structuralHash:IX(FX(`Vertex`),t),freeParams:t.freeParams}}function YX(e){return{kind:`Empty`,output:e,structuralHash:ZY(FX(`Empty`),e),freeParams:PX}}function XX(){return YX(`Solid`)}function ZX(){return YX(`Face`)}function QX(){return YX(`Wire`)}function $X(e,t,n,r){return RX(IX(IX(FX(e),t),n),r)}function eZ(e,t,n){return{kind:`Fuse`,a:e,b:t,tolerance:n,structuralHash:$X(`Fuse`,e,t,n),freeParams:zX(e,t)}}function tZ(e,t,n){return{kind:`Cut`,a:e,b:t,tolerance:n,structuralHash:$X(`Cut`,e,t,n),freeParams:zX(e,t)}}function nZ(e,t,n){return{kind:`Intersect`,a:e,b:t,tolerance:n,structuralHash:$X(`Intersect`,e,t,n),freeParams:zX(e,t)}}function rZ(e,t){let n=rX(FX(`FuseAll`),e.length);for(let t of e)n=IX(n,t);return n=RX(n,t),{kind:`FuseAll`,shapes:e,tolerance:t,structuralHash:n,freeParams:zX(...e)}}function iZ(e,t,n){let r=IX(FX(`CutAll`),e);r=rX(r,t.length);for(let e of t)r=IX(r,e);return r=RX(r,n),{kind:`CutAll`,base:e,tools:t,tolerance:n,structuralHash:r,freeParams:zX(e,...t)}}function aZ(e){return e===void 0?void 0:bX(e)}function oZ(e,t){let n=bX(t);return{kind:`Translate`,target:e,vector:n,structuralHash:IX(IX(FX(`Translate`),e),n),freeParams:zX(e,n)}}function sZ(e,t,n){let r=vX(t),i=aZ(n?.axis),a=aZ(n?.at),o=IX(IX(FX(`Rotate`),e),r);return o=LX(o,i),o=LX(o,a),{kind:`Rotate`,target:e,angle:r,axis:i,at:a,structuralHash:o,freeParams:zX(e,r,i,a)}}function cZ(e,t,n){let r=vX(t),i=aZ(n?.center),a=IX(IX(FX(`Scale`),e),r);return a=LX(a,i),{kind:`Scale`,target:e,factor:r,center:i,structuralHash:a,freeParams:zX(e,r,i)}}function lZ(e,t){let n=aZ(t?.normal),r=aZ(t?.at),i=IX(FX(`Mirror`),e);return i=LX(i,n),i=LX(i,r),{kind:`Mirror`,target:e,normal:n,at:r,structuralHash:i,freeParams:zX(e,n,r)}}function uZ(e){let t=rX(FX(`Compound`),e.length);for(let n of e)t=IX(t,n);return{kind:`Compound`,children:e,structuralHash:t,freeParams:zX(...e)}}function dZ(e){switch(e.kind){case`Box`:case`Sphere`:case`Cylinder`:case`Cone`:case`Torus`:return`Solid`;case`Polygon`:return`Face`;case`Circle`:case`Line`:return`Edge`;case`Vertex`:return`Vertex`;case`Empty`:return e.output;case`Fuse`:case`Cut`:case`Intersect`:return dZ(e.a);case`FuseAll`:return e.shapes[0]?dZ(e.shapes[0]):`Solid`;case`CutAll`:return dZ(e.base);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return dZ(e.target);case`Compound`:return`Compound`}}function fZ(e,t){let n=jX(e.x,t.env,`Box.x`);if(!n.ok)return n;let r=jX(e.y,t.env,`Box.y`);if(!r.ok)return r;let i=jX(e.z,t.env,`Box.z`);return i.ok?O(Tk(n.value,r.value,i.value)):i}function pZ(e,t){let n=jX(e.radius,t.env,`Sphere.radius`);return n.ok?O(Dk(n.value)):n}function mZ(e,t){let n=jX(e.radius,t.env,`Cylinder.radius`);if(!n.ok)return n;let r=jX(e.height,t.env,`Cylinder.height`);return r.ok?O(Ek(n.value,r.value)):r}function hZ(e,t){let n=jX(e.radius1,t.env,`Cone.radius1`);if(!n.ok)return n;let r=jX(e.radius2,t.env,`Cone.radius2`);if(!r.ok)return r;let i=jX(e.height,t.env,`Cone.height`);return i.ok?O(Ok(n.value,r.value,i.value)):i}function gZ(e,t){let n=jX(e.majorRadius,t.env,`Torus.majorRadius`);if(!n.ok)return n;let r=jX(e.minorRadius,t.env,`Torus.minorRadius`);return r.ok?O(kk(n.value,r.value)):r}function _Z(e,t){let n=[];for(let r of e.points){let e=MX(r,t.env,`Polygon.point`);if(!e.ok)return e;n.push(e.value)}return Gk(n)}function vZ(e,t){let n=jX(e.radius,t.env,`Circle.radius`);return n.ok?O(Mk(n.value)):n}function yZ(e,t){let n=MX(e.from,t.env,`Line.from`);if(!n.ok)return n;let r=MX(e.to,t.env,`Line.to`);return r.ok?O(jk(n.value,r.value)):r}function bZ(e,t){let n=MX(e.point,t.env,`Vertex.point`);return n.ok?O(Kk(n.value)):n}function xZ(e){return k(Ha(N.NULL_SHAPE_INPUT,`${e}: empty result has no kernel representation`))}function SZ(e,t,n){let r=e.evalNode(t);return r.ok?uw(r.value)?O(r.value):k(za(N.CSG_NOT_3D,`${n}: operand did not produce a 3D shape`)):r}function CZ(e,t){return{unsafe:!0,fuzzyValue:e.tolerance??t.tolerance}}function wZ(e,t){if(e.a.kind===`Empty`)return t.evalNode(e.b);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=SZ(t,e.a,`Fuse.a`);if(!n.ok)return n;let r=SZ(t,e.b,`Fuse.b`);return r.ok?HD(n.value,r.value,CZ(e,t)):r}function TZ(e,t){if(e.a.kind===`Empty`)return xZ(`Cut`);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=SZ(t,e.a,`Cut.a`);if(!n.ok)return n;let r=SZ(t,e.b,`Cut.b`);return r.ok?UD(n.value,r.value,CZ(e,t)):r}function EZ(e,t){if(e.a.kind===`Empty`||e.b.kind===`Empty`)return xZ(`Intersect`);let n=SZ(t,e.a,`Intersect.a`);if(!n.ok)return n;let r=SZ(t,e.b,`Intersect.b`);return r.ok?WD(n.value,r.value,CZ(e,t)):r}function DZ(e,t,n){let r=[];for(let i of t){let t=SZ(e,i,n);if(!t.ok)return t;r.push(t.value)}return O(r)}function OZ(e,t){let n=e.shapes.filter(e=>e.kind!==`Empty`);if(n.length===0)return xZ(`FuseAll`);if(n.length===1&&n[0])return t.evalNode(n[0]);let r=DZ(t,n,`FuseAll.operand`);return r.ok?KD(r.value,CZ(e,t)):r}function kZ(e,t){if(e.base.kind===`Empty`)return xZ(`CutAll`);let n=e.tools.filter(e=>e.kind!==`Empty`);if(n.length===0)return t.evalNode(e.base);let r=SZ(t,e.base,`CutAll.base`);if(!r.ok)return r;let i=DZ(t,n,`CutAll.tool`);return i.ok?qD(r.value,i.value,CZ(e,t)):i}function AZ(e){return k(Ha(N.NULL_SHAPE_INPUT,`${e}: cannot transform an Empty node`))}function jZ(e,t,n,r){return e?MX(e,t,n):O(r)}function MZ(e,t){if(e.target.kind===`Empty`)return AZ(`Translate`);let n=MX(e.vector,t.env,`Translate.vector`);if(!n.ok)return n;let r=t.evalNode(e.target);return r.ok?O(xE(r.value,n.value)):r}function NZ(e,t){if(e.target.kind===`Empty`)return AZ(`Rotate`);let n=jX(e.angle,t.env,`Rotate.angle`);if(!n.ok)return n;let r=jZ(e.axis,t.env,`Rotate.axis`,[0,0,1]);if(!r.ok)return r;let i=jZ(e.at,t.env,`Rotate.at`,[0,0,0]);if(!i.ok)return i;let a=t.evalNode(e.target);return a.ok?O(SE(a.value,n.value,i.value,r.value)):a}function PZ(e,t){if(e.target.kind===`Empty`)return AZ(`Scale`);let n=jX(e.factor,t.env,`Scale.factor`);if(!n.ok)return n;let r=jZ(e.center,t.env,`Scale.center`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(wE(i.value,n.value,r.value)):i}function FZ(e,t){if(e.target.kind===`Empty`)return AZ(`Mirror`);let n=jZ(e.normal,t.env,`Mirror.normal`,[1,0,0]);if(!n.ok)return n;let r=jZ(e.at,t.env,`Mirror.at`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(CE(i.value,n.value,r.value)):i}function IZ(e,t){let n=e.children.filter(e=>e.kind!==`Empty`);if(n.length===0)return k(Ha(N.NULL_SHAPE_INPUT,`Compound: cannot materialize a compound with zero non-empty children`));let r=[];for(let e of n){let n=t.evalNode(e);if(!n.ok)return n;r.push(n.value)}return O(qk(r))}function LZ(){return k(Ha(N.NULL_SHAPE_INPUT,`Empty: cannot materialize an Empty node directly — only valid as boolean/transform operand`))}function RZ(e,t){switch(e.kind){case`Box`:return fZ(e,t);case`Sphere`:return pZ(e,t);case`Cylinder`:return mZ(e,t);case`Cone`:return hZ(e,t);case`Torus`:return gZ(e,t);case`Polygon`:return _Z(e,t);case`Circle`:return vZ(e,t);case`Line`:return yZ(e,t);case`Vertex`:return bZ(e,t);case`Empty`:return LZ();case`Fuse`:return wZ(e,t);case`Cut`:return TZ(e,t);case`Intersect`:return EZ(e,t);case`FuseAll`:return OZ(e,t);case`CutAll`:return kZ(e,t);case`Translate`:return MZ(e,t);case`Rotate`:return NZ(e,t);case`Scale`:return PZ(e,t);case`Mirror`:return FZ(e,t);case`Compound`:return IZ(e,t)}}function zZ(e,t){if(typeof t==`number`)return tX(iX(e,!1),t);let n=iX(e,!0);n=rX(n,t.length);for(let e of t)n=tX(n,e);return n}function BZ(e,t){if(t.size===0)return qY();let n=NX(e,t),r=Object.keys(n).sort(),i=qY();for(let e of r){i=ZY(i,e);let t=n[e];t!==void 0&&(i=zZ(i,t))}return i}function VZ(e,t,n,r){let i=BZ(t,e.freeParams),a=r===void 0?`d`:tX(qY(),r).toString(16);return`${aX(e.structuralHash)}:${n}:${aX(i)}:${a}`}var HZ=class{scope=new xC;cache=new Map;registered=new WeakSet;kernelId;defaultTolerance;onStep;hits=0;misses=0;constructor(e={}){this.kernelId=e.kernel??iC()??`unregistered`,this.defaultTolerance=e.tolerance,e.onStep&&(this.onStep=e.onStep)}evaluate(e,t={}){return aC(this.kernelId,()=>this.evaluateInner(e,t))}evaluateInner(e,t){let n=VZ(e,t,this.kernelId,this.defaultTolerance),r=this.cache.get(n);if(r!==void 0)return this.hits++,this.onStep?.({node:e,cacheKey:n,cacheHit:!0}),O(r);this.misses++;let i=RZ(e,{env:t,tolerance:this.defaultTolerance,evalNode:e=>this.evaluateInner(e,t)});return i.ok?(this.registered.has(i.value)||(this.scope.register(i.value),this.registered.add(i.value)),this.cache.set(n,i.value),this.onStep?.({node:e,cacheKey:n,cacheHit:!1}),i):i}cacheStats(){return{hits:this.hits,misses:this.misses,entries:this.cache.size}}resetStats(){this.hits=0,this.misses=0}[Symbol.dispose](){this.scope[Symbol.dispose](),this.cache.clear()}};function UZ(e,t){try{var n=lC();let r=t(n.u(new HZ(e)));if(r instanceof Promise)throw Error(`withEvaluator() callback returned a Promise. Async code must construct an Evaluator directly and dispose it manually — borrowed shapes would otherwise be freed before the Promise resolves.`);return r}catch(e){n.e=e}finally{n.d()}}function WZ(e){return{csgVersion:1,root:XZ(e)}}function GZ(e){switch(e.kind){case`NumLit`:return{kind:`NumLit`,value:e.value};case`Vec3Lit`:return{kind:`Vec3Lit`,value:[e.value[0],e.value[1],e.value[2]]};case`Vec2Lit`:return{kind:`Vec2Lit`,value:[e.value[0],e.value[1]]};case`Param`:return{kind:`Param`,name:e.name};case`BinOp`:return{kind:`BinOp`,op:e.op,a:GZ(e.a),b:GZ(e.b)};case`UnaryOp`:return{kind:`UnaryOp`,op:e.op,arg:GZ(e.arg)};case`Component`:return{kind:`Component`,vec:GZ(e.vec),index:e.index};case`BuildVec`:return{kind:`BuildVec`,dim:e.dim,components:e.components.map(GZ)}}}function KZ(e){switch(e.kind){case`Box`:return{kind:`Box`,x:GZ(e.x),y:GZ(e.y),z:GZ(e.z)};case`Sphere`:return{kind:`Sphere`,radius:GZ(e.radius)};case`Cylinder`:return{kind:`Cylinder`,radius:GZ(e.radius),height:GZ(e.height)};case`Cone`:return{kind:`Cone`,radius1:GZ(e.radius1),radius2:GZ(e.radius2),height:GZ(e.height)};case`Torus`:return{kind:`Torus`,majorRadius:GZ(e.majorRadius),minorRadius:GZ(e.minorRadius)};case`Polygon`:return{kind:`Polygon`,points:e.points.map(GZ)};case`Circle`:return{kind:`Circle`,radius:GZ(e.radius)};case`Line`:return{kind:`Line`,from:GZ(e.from),to:GZ(e.to)};case`Vertex`:return{kind:`Vertex`,point:GZ(e.point)};case`Empty`:return{kind:`Empty`,output:e.output};default:return}}function qZ(e){switch(e.kind){case`Fuse`:case`Cut`:case`Intersect`:return{kind:e.kind,a:XZ(e.a),b:XZ(e.b),tolerance:e.tolerance};case`FuseAll`:return{kind:`FuseAll`,shapes:e.shapes.map(XZ),tolerance:e.tolerance};case`CutAll`:return{kind:`CutAll`,base:XZ(e.base),tools:e.tools.map(XZ),tolerance:e.tolerance};default:return}}function JZ(e){return e?GZ(e):void 0}function YZ(e){switch(e.kind){case`Translate`:return{kind:`Translate`,target:XZ(e.target),vector:GZ(e.vector)};case`Rotate`:return{kind:`Rotate`,target:XZ(e.target),angle:GZ(e.angle),axis:JZ(e.axis),at:JZ(e.at)};case`Scale`:return{kind:`Scale`,target:XZ(e.target),factor:GZ(e.factor),center:JZ(e.center)};case`Mirror`:return{kind:`Mirror`,target:XZ(e.target),normal:JZ(e.normal),at:JZ(e.at)};default:return}}function XZ(e){return e.kind===`Compound`?{kind:`Compound`,children:e.children.map(XZ)}:KZ(e)??qZ(e)??YZ(e)}function ZZ(e){return k(F(N.NULL_SHAPE_INPUT,`csg.fromJSON: ${e}`))}function QZ(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $Z(e){return typeof e==`number`&&Number.isFinite(e)}function eQ(e){return typeof e==`string`}function tQ(e,t){if(!Array.isArray(e)||e.length!==3)return ZZ(`${t}: expected Vec3 array`);let[n,r,i]=e;return!$Z(n)||!$Z(r)||!$Z(i)?ZZ(`${t}: Vec3 contains non-number`):O([n,r,i])}function nQ(e,t){if(!Array.isArray(e)||e.length!==2)return ZZ(`${t}: expected Vec2 array`);let[n,r]=e;return!$Z(n)||!$Z(r)?ZZ(`${t}: Vec2 contains non-number`):O([n,r])}function rQ(e){if(!QZ(e))return ZZ(`input is not an object`);let t=e.csgVersion;if(t!==1)return ZZ(`unsupported csgVersion ${String(t)} (expected 1)`);let n=e.root;return dQ(n)}function iQ(e){if(!QZ(e))return ZZ(`expression: not an object`);let t=e.kind;switch(t){case`NumLit`:return $Z(e.value)?O(cX(e.value)):ZZ(`NumLit.value`);case`Vec3Lit`:{let t=tQ(e.value,`Vec3Lit.value`);return t.ok?O(lX(t.value)):t}case`Vec2Lit`:{let t=nQ(e.value,`Vec2Lit.value`);return t.ok?O(uX(t.value)):t}case`Param`:return eQ(e.name)?O(dX(e.name)):ZZ(`Param.name`);case`BinOp`:return aQ(e);case`UnaryOp`:return oQ(e);case`Component`:return sQ(e);case`BuildVec`:return cQ(e);default:return ZZ(`unknown expression kind: ${String(t)}`)}}function aQ(e){let t=e.op;if(t!==`+`&&t!==`-`&&t!==`*`&&t!==`/`)return ZZ(`BinOp.op: ${String(t)}`);let n=iQ(e.a);if(!n.ok)return n;let r=iQ(e.b);return r.ok?O(fX(t,n.value,r.value)):r}function oQ(e){let t=e.op;if(!eQ(t)||![`neg`,`sin`,`cos`,`sqrt`,`abs`].includes(t))return ZZ(`UnaryOp.op: ${String(t)}`);let n=iQ(e.arg);return n.ok?O(pX(t,n.value)):n}function sQ(e){let t=e.index;if(t!==0&&t!==1&&t!==2)return ZZ(`Component.index: ${String(t)}`);let n=iQ(e.vec);return n.ok?O(mX(n.value,t)):n}function cQ(e){let t=e.dim;if(t!==2&&t!==3)return ZZ(`BuildVec.dim: ${String(t)}`);let n=e.components;if(!Array.isArray(n))return ZZ(`BuildVec.components: not array`);if(n.length!==t)return ZZ(`BuildVec.components: expected ${t} components, got ${n.length}`);let r=[];for(let e of n){let t=iQ(e);if(!t.ok)return t;r.push(t.value)}return O(hX(t,r))}function lQ(e,t){if(!Array.isArray(e))return ZZ(`${t}: not array`);let n=[];for(let t of e){let e=dQ(t);if(!e.ok)return e;n.push(e.value)}return O(n)}function uQ(e){let t=e.tolerance;return t==null?O(void 0):$Z(t)?O(t):ZZ(`tolerance: not a finite number`)}function dQ(e){if(!QZ(e))return ZZ(`node: not an object`);let t=e.kind;switch(t){case`Box`:case`Sphere`:case`Cylinder`:case`Cone`:case`Torus`:case`Polygon`:case`Circle`:case`Line`:case`Vertex`:case`Empty`:return pQ(t,e);case`Fuse`:case`Cut`:case`Intersect`:return xQ(t,e);case`FuseAll`:case`CutAll`:return SQ(t,e);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return CQ(t,e);case`Compound`:return kQ(e);default:return ZZ(`unknown node kind: ${String(t)}`)}}function fQ(e,t,n){let r=iQ(e[t]);return r.ok?O(n(r.value)):r}function pQ(e,t){switch(e){case`Box`:return mQ(t);case`Sphere`:return fQ(t,`radius`,VX);case`Cylinder`:return hQ(t);case`Cone`:return gQ(t);case`Torus`:return _Q(t);case`Polygon`:return vQ(t);case`Circle`:return fQ(t,`radius`,KX);case`Line`:return yQ(t);case`Vertex`:return fQ(t,`point`,JX);case`Empty`:return bQ(t)}return ZZ(`unhandled primitive: ${e}`)}function mQ(e){let t=iQ(e.x);if(!t.ok)return t;let n=iQ(e.y);if(!n.ok)return n;let r=iQ(e.z);return r.ok?O(BX(t.value,n.value,r.value)):r}function hQ(e){let t=iQ(e.radius);if(!t.ok)return t;let n=iQ(e.height);return n.ok?O(HX(t.value,n.value)):n}function gQ(e){let t=iQ(e.radius1);if(!t.ok)return t;let n=iQ(e.radius2);if(!n.ok)return n;let r=iQ(e.height);return r.ok?O(UX(t.value,n.value,r.value)):r}function _Q(e){let t=iQ(e.majorRadius);if(!t.ok)return t;let n=iQ(e.minorRadius);return n.ok?O(WX(t.value,n.value)):n}function vQ(e){let t=e.points;if(!Array.isArray(t))return ZZ(`Polygon.points: not array`);let n=[];for(let e of t){let t=iQ(e);if(!t.ok)return t;n.push(t.value)}return O(GX(n))}function yQ(e){let t=iQ(e.from);if(!t.ok)return t;let n=iQ(e.to);return n.ok?O(qX(t.value,n.value)):n}function bQ(e){let t=e.output;switch(t){case`Solid`:return O(XX());case`Face`:return O(ZX());case`Wire`:return O(QX());default:return ZZ(`Empty.output: ${String(t)}`)}}function xQ(e,t){let n=dQ(t.a);if(!n.ok)return n;let r=dQ(t.b);if(!r.ok)return r;let i=uQ(t);if(!i.ok)return i;switch(e){case`Fuse`:return O(eZ(n.value,r.value,i.value));case`Cut`:return O(tZ(n.value,r.value,i.value));case`Intersect`:return O(nZ(n.value,r.value,i.value))}}function SQ(e,t){let n=uQ(t);if(!n.ok)return n;if(e===`FuseAll`){let e=lQ(t.shapes,`FuseAll.shapes`);return e.ok?O(rZ(e.value,n.value)):e}let r=dQ(t.base);if(!r.ok)return r;let i=lQ(t.tools,`CutAll.tools`);return i.ok?O(iZ(r.value,i.value,n.value)):i}function CQ(e,t){let n=dQ(t.target);if(!n.ok)return n;switch(e){case`Translate`:return wQ(t,n.value);case`Rotate`:return EQ(t,n.value);case`Scale`:return DQ(t,n.value);case`Mirror`:return OQ(t,n.value)}}function wQ(e,t){let n=iQ(e.vector);return n.ok?O(oZ(t,n.value)):n}function TQ(e,t){if(e[t]===void 0)return O(void 0);let n=iQ(e[t]);return n.ok?O(n.value):n}function EQ(e,t){let n=iQ(e.angle);if(!n.ok)return n;let r=TQ(e,`axis`);if(!r.ok)return r;let i=TQ(e,`at`);return i.ok?O(sZ(t,n.value,{axis:r.value,at:i.value})):i}function DQ(e,t){let n=iQ(e.factor);if(!n.ok)return n;let r=TQ(e,`center`);return r.ok?O(cZ(t,n.value,{center:r.value})):r}function OQ(e,t){let n=TQ(e,`normal`);if(!n.ok)return n;let r=TQ(e,`at`);return r.ok?O(lZ(t,{normal:n.value,at:r.value})):r}function kQ(e){let t=lQ(e.children,`Compound.children`);return t.ok?O(uZ(t.value)):t}function AQ(e){return NQ(e)}function jQ(e){switch(e.kind){case`NumLit`:case`Vec3Lit`:case`Vec2Lit`:case`Param`:return e;case`BinOp`:{let t=jQ(e.a),n=jQ(e.b);if(t.kind===`NumLit`&&n.kind===`NumLit`)switch(e.op){case`+`:return cX(t.value+n.value);case`-`:return cX(t.value-n.value);case`*`:return cX(t.value*n.value);case`/`:return cX(t.value/n.value)}return t!==e.a||n!==e.b?fX(e.op,t,n):e}case`UnaryOp`:{let t=jQ(e.arg);if(t.kind===`NumLit`){let n=t.value;switch(e.op){case`neg`:return cX(-n);case`sin`:return cX(Math.sin(n));case`cos`:return cX(Math.cos(n));case`sqrt`:return cX(Math.sqrt(n));case`abs`:return cX(Math.abs(n))}}return t===e.arg?e:pX(e.op,t)}case`Component`:{let t=jQ(e.vec);return t.kind===`Vec3Lit`||t.kind===`Vec2Lit`&&(e.index===0||e.index===1)?cX(t.value[e.index]):t===e.vec?e:mX(t,e.index)}case`BuildVec`:{let t=e.components.map(jQ);return MQ(e.dim,t)||(t.some((t,n)=>t!==e.components[n])?hX(e.dim,t):e)}}}function MQ(e,t){if(t.length!==e)return;let n=[];for(let e of t){if(e.kind!==`NumLit`)return;n.push(e.value)}return e===2?uX([n[0],n[1]]):lX([n[0],n[1],n[2]])}function NQ(e){switch(e.kind){case`Box`:return BX(jQ(e.x),jQ(e.y),jQ(e.z));case`Sphere`:return VX(jQ(e.radius));case`Cylinder`:return HX(jQ(e.radius),jQ(e.height));case`Cone`:return UX(jQ(e.radius1),jQ(e.radius2),jQ(e.height));case`Torus`:return WX(jQ(e.majorRadius),jQ(e.minorRadius));case`Polygon`:return GX(e.points.map(jQ));case`Circle`:return KX(jQ(e.radius));case`Line`:return qX(jQ(e.from),jQ(e.to));case`Vertex`:return JX(jQ(e.point));case`Empty`:return e;case`Fuse`:return PQ(e.a,e.b,e.tolerance);case`Cut`:return FQ(e.a,e.b,e.tolerance);case`Intersect`:return IQ(e.a,e.b,e.tolerance);case`FuseAll`:return LQ(e.shapes,e.tolerance);case`CutAll`:return RQ(e.base,e.tools,e.tolerance);case`Translate`:return zQ(e.target,e.vector);case`Rotate`:return sZ(NQ(e.target),jQ(e.angle),{axis:e.axis?jQ(e.axis):void 0,at:e.at?jQ(e.at):void 0});case`Scale`:return cZ(NQ(e.target),jQ(e.factor),{center:e.center?jQ(e.center):void 0});case`Mirror`:return lZ(NQ(e.target),{normal:e.normal?jQ(e.normal):void 0,at:e.at?jQ(e.at):void 0});case`Compound`:return uZ(e.children.map(NQ).filter(e=>e.kind!==`Empty`))}}function PQ(e,t,n){let r=NQ(e),i=NQ(t);return r.kind===`Empty`?i:i.kind===`Empty`?r:eZ(r,i,n)}function FQ(e,t,n){let r=NQ(e),i=NQ(t);return i.kind===`Empty`||r.kind===`Empty`?r:tZ(r,i,n)}function IQ(e,t,n){let r=NQ(e),i=NQ(t);return r.kind===`Empty`?r:i.kind===`Empty`?i:nZ(r,i,n)}function LQ(e,t){let n=e.map(NQ).filter(e=>e.kind!==`Empty`);return n.length===0?XX():n.length===1?n[0]:rZ(n,t)}function RQ(e,t,n){let r=NQ(e);if(r.kind===`Empty`)return r;let i=t.map(NQ).filter(e=>e.kind!==`Empty`);return i.length===0?r:iZ(r,i,n)}function zQ(e,t){let n=NQ(e),r=jQ(t);if(r.kind!==`Vec3Lit`)return oZ(n,r);let[i,a,o]=r.value;if(i===0&&a===0&&o===0)return n;if(n.kind===`Translate`){let e=jQ(n.vector);if(e.kind===`Vec3Lit`)return oZ(n.target,[e.value[0]+i,e.value[1]+a,e.value[2]+o])}return oZ(n,r)}function BQ(e,t,n){return VQ(e,t,n)}function VQ(e,t,n){return t(e)?n:HQ(e,t,n)}function HQ(e,t,n){switch(e.kind){case`Box`:case`Sphere`:case`Cylinder`:case`Cone`:case`Torus`:case`Polygon`:case`Circle`:case`Line`:case`Vertex`:case`Empty`:return e;case`Fuse`:return eZ(VQ(e.a,t,n),VQ(e.b,t,n),e.tolerance);case`Cut`:return tZ(VQ(e.a,t,n),VQ(e.b,t,n),e.tolerance);case`Intersect`:return nZ(VQ(e.a,t,n),VQ(e.b,t,n),e.tolerance);case`FuseAll`:return rZ(e.shapes.map(e=>VQ(e,t,n)),e.tolerance);case`CutAll`:return iZ(VQ(e.base,t,n),e.tools.map(e=>VQ(e,t,n)),e.tolerance);case`Translate`:return oZ(VQ(e.target,t,n),e.vector);case`Rotate`:return sZ(VQ(e.target,t,n),e.angle,{axis:e.axis,at:e.at});case`Scale`:return cZ(VQ(e.target,t,n),e.factor,{center:e.center});case`Mirror`:return lZ(VQ(e.target,t,n),{normal:e.normal,at:e.at});case`Compound`:return uZ(e.children.map(e=>VQ(e,t,n)))}}function UQ(e,t){t(e);for(let n of WQ(e))UQ(n,t)}function WQ(e){switch(e.kind){case`Box`:case`Sphere`:case`Cylinder`:case`Cone`:case`Torus`:case`Polygon`:case`Circle`:case`Line`:case`Vertex`:case`Empty`:return[];case`Fuse`:case`Cut`:case`Intersect`:return[e.a,e.b];case`FuseAll`:return e.shapes;case`CutAll`:return[e.base,...e.tools];case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return[e.target];case`Compound`:return e.children}}function GQ(e){let t=0;return UQ(e,()=>{t++}),t}var KQ=SG({CSG_VERSION:()=>1,Evaluator:()=>HZ,add:()=>gX,asScalarExpr:()=>vX,asVec2Expr:()=>xX,asVec3Expr:()=>bX,binOp:()=>fX,box:()=>BX,buildVec:()=>hX,circle:()=>KX,component:()=>mX,compound:()=>uZ,cone:()=>UX,cut:()=>tZ,cutAll:()=>iZ,cylinder:()=>HX,emptyFace:()=>ZX,emptySolid:()=>XX,emptyWire:()=>QX,foldExpr:()=>jQ,forEachNode:()=>UQ,fromJSON:()=>rQ,fuse:()=>eZ,fuseAll:()=>rZ,intersect:()=>nZ,line:()=>qX,mirror:()=>lZ,mul:()=>_X,nodeCount:()=>GQ,numLit:()=>cX,optimize:()=>AQ,outputKindOf:()=>dZ,param:()=>dX,polygon:()=>GX,replaceNode:()=>BQ,rotate:()=>sZ,scale:()=>cZ,sphere:()=>VX,toJSON:()=>WZ,torus:()=>WX,translate:()=>oZ,unaryOp:()=>pX,vec2Lit:()=>uX,vec3Lit:()=>lX,vertex:()=>JX,withEvaluator:()=>UZ});export{IM as BaseSketcher2d,LM as BlueprintSketcher,Na as BrepBugError,N as BrepErrorCode,DJ as BrepWrapperError,Kv as BrepkitAdapter,OV as CompoundSketch,Ww as DEG2RAD,xC as DisposalScope,lH as FaceSketcher,G as HASH_CODE_MAX,la as OK,ca as OcctWasmAdapter,Gw as RAD2DEG,KV as Sketch,cH as Sketcher,qV as Sketches,iA as addChild,Zk as addHoles,fq as addMate,fA as addStep,kO as adjacentFaces,va as all,pa as andThen,TG as applyGlue,Wq as applyMatrix,ZE as approximateCurve,jC as as2D,AC as as3D,ST as asTopo,$W as assignRoles,xk as autoHeal,Rk as bezier,aW as blueprintToDXF,iO as booleanPipeline,IY as booleans,wJ as boss,Tk as box,Lk as bsplineApprox,M as bug,aH as cameraFromPlane,iH as cameraLookAt,XW as captureHint,DT as cast,W as castShape,fw as castShape3D,rJ as chamfer,xO as chamferDistAngleShape,$O as chamferWithEvolution,hq as checkAllInterferences,WO as checkBoolean,mq as checkInterference,Mk as circle,nA as circularPattern,VT as classifyPointOnFace,sD as clearMeshCache,Uq as clone,BC as closedWire,ka as collect,uA as collectShapes,mE as colorFaces,pE as colorShape,FN as complexExtrude,AE as composeTransforms,qk as compound,UV as compoundSketchExtrude,VV as compoundSketchFace,GV as compoundSketchLoft,WV as compoundSketchRevolve,Ha as computationError,QK as computeStraightSkeleton,Ok as cone,HY as construction,MK as convexHull,HM as cornerFinder,lA as countNodes,$k as createAssembly,rA as createAssemblyNode,xU as createBlueprint,rH as createCamera,nw as createCompound,SU as createCompoundBlueprint,zA as createDistanceQuery,XC as createEdge,QC as createFace,yC as createHandle,dA as createHistory,bC as createKernelHandle,cD as createMeshCache,hT as createNamedPlane,vG as createOperationRegistry,pT as createPlane,eG as createRef,yA as createRegistry,$C as createShell,ew as createSolid,uG as createTaskQueue,YC as createVertex,ZC as createWire,_G as createWorkerClient,bG as createWorkerHandler,KQ as csg,pU as curve2dBoundingBox,bU as curve2dDistanceFrom,mU as curve2dFirstPoint,yU as curve2dIsOnCurve,hU as curve2dLastPoint,_U as curve2dParameter,gU as curve2dSplitAt,vU as curve2dTangentAt,VE as curveEndPoint,GE as curveIsClosed,KE as curveIsPeriodic,WE as curveLength,qE as curvePeriod,HE as curvePointAt,BE as curveStartPoint,UE as curveTangentAt,qq as cut,ON as cut2D,qD as cutAll,FO as cutAllBisect,_N as cutBlueprints,XO as cutWithEvolution,Ek as cylinder,YW as defaultScorer,fG as dequeueTask,fJ as describe,BH as deserializeDrawing,TA as deserializeHistory,kT as deserializeShape,ET as downcast,sJ as draft,HH as draw,qH as drawCircle,JH as drawEllipse,tU as drawFaceOutline,QH as drawParametricFunction,ZH as drawPointsInterpolation,YH as drawPolysides,eU as drawProjection,WH as drawRectangle,UH as drawRoundedRectangle,GH as drawSingleCircle,KH as drawSingleEllipse,XH as drawText,sU as drawingChamfer,iU as drawingCut,oU as drawingFillet,rU as drawingFuse,aU as drawingIntersect,nU as drawingToSketchOnPlane,SJ as drill,fj as edgeFinder,EO as edgesOfFace,Nk as ellipse,Ik as ellipseArc,Ak as ellipsoid,dG as enqueueTask,k as err,eA as exportAssemblySTEP,iW as exportDXF,GU as exportGlb,WU as exportGltf,gD as exportIGES,IU as exportOBJ,mD as exportSTEP,HW as exportSTEPConfigured,hD as exportSTL,wW as exportThreeMF,_J as extrude,UN as extrudeAll,Hk as face,BT as faceCenter,hj as faceFinder,MT as faceGeomType,NT as faceOrientation,TO as facesOfEdge,FD as fill,Uk as filledFace,nJ as fillet,QO as filletWithEvolution,nE as findFacesByTag,sA as findNode,mA as findStep,wk as fixSelfIntersection,Sk as fixShape,ma as flatMap,xa as flatten,PT as flipFaceOrientation,YE as flipOrientation,JW as fontMetrics,mJ as fromBREP,yK as fromKernelDir,vK as fromKernelPnt,_K as fromKernelVec,Ca as fromNullable,Kq as fuse,EN as fuse2D,KD as fuseAll,zO as fuseAllBisect,gN as fuseBlueprints,YO as fuseWithEvolution,ZJ as gearGeometry,LG as getActiveVoxelId,Rw as getBounds,CU as getBounds2D,Aw as getCompSolids,zE as getCurveType,pC as getDisposalStats,ww as getEdges,gE as getFaceColor,KT as getFaceOrigins,rE as getFaceTags,Tw as getFaces,XV as getFont,PE as getHashCode,hA as getHistoryShape,U as getKernel,jO as getNurbsCurveData,MO as getNurbsSurfaceData,JE as getOrientation,wU as getOrientation2D,$a as getPerformanceStats,hE as getShapeColor,FC as getShapeKind,kw as getShells,vj as getSingleFace,Ow as getSolids,jT as getSurfaceType,aE as getTagMetadata,Dw as getVertices,IG as getVoxel,Ew as getWires,BN as guidedSweep,cJ as heal,vk as healFace,_k as healSolid,yk as healWire,Pk as helix,jK as hull,bq as importDXF,Lq as importGLB,GW as importIGES,wq as importOBJ,UW as importSTEP,WW as importSTL,VW as importSVG,BW as importSVGPathD,Iq as importThreeMF,cC as init,tC as initFromManifold,oC as initFromOC,RG as initVoxel,WT as innerWires,XE as interpolateCurve,Jq as intersect,kN as intersect2D,vN as intersectBlueprints,ZO as intersectWithEvolution,Cw as invalidateShapeCache,BY as io,Ua as ioError,kC as is2D,OC as is3D,DG as isChamferRadius,IC as isClosedWire,OT as isCompSolid,lw as isCompound,sG as isDisposeRequest,iw as isEdge,gJ as isEmpty,LE as isEqualShape,A as isErr,lG as isErrorResponse,ow as isFace,OG as isFilletRadius,aG as isInitRequest,TU as isInside2D,DC as isLive,RC as isManifoldShell,EG as isNumber,ua as isOk,oG as isOperationRequest,LC as isOrientedFace,WC as isPlanarFace,GC as isPlanarWire,eH as isProjectionPlane,mG as isQueueEmpty,IE as isSameShape,dw as isShape1D,uw as isShape3D,sw as isShell,cw as isSolid,cG as isSuccessResponse,hJ as isValid,zC as isValidSolid,rw as isVertex,aw as isWire,Lw as iterCompSolids,jw as iterEdges,Mw as iterFaces,Iw as iterShells,Fw as iterSolids,wT as iterTopo,Pw as iterVertices,Nw as iterWires,gw as kernelCall,_w as kernelCallRaw,vw as kernelCallScoped,P as kernelError,dK as latticeInfill,fK as latticeInfillShape,jk as line,tA as linearPattern,YV as loadFont,yJ as loft,DV as loftAll,yH as makeBaseBox,bY as makeExternalGear,xY as makeInternalGear,_T as makePlane,CY as makePlanetaryGear,nH as makeProjectedEdges,HC as manifoldShell,da as map,Sa as mapBoth,fa as mapErr,Oa as match,FA as measureArea,BA as measureCurvatureAt,VA as measureCurvatureAtMid,LA as measureDistance,RA as measureDistanceProps,IA as measureLength,NA as measureLinearProps,MA as measureSurfaceProps,PA as measureVolume,jA as measureVolumeProps,zY as measurement,uJ as mesh,dJ as meshEdges,_D as meshMultiLOD,IK as minkowski,Vq as mirror,AU as mirror2D,dU as mirrorDrawing,TJ as mirrorJoin,LY as modifiers,CA as modifyStep,Va as moduleInitError,zN as multiSectionSweep,zT as normalAt,aJ as offset,Yk as offsetFace,eK as offsetMesh,rK as offsetShape,QE as offsetWire2D,O as ok,ha as or,ga as orElse,EM as organiseBlueprints,VC as orientedFace,HT as outerWire,UY as patterns,pG as pendingCount,Ma as pipeline,bT as pivotPlane,KC as planarFace,qC as planarWire,hY as planetPlacements,CJ as pocket,IT as pointOnSurface,UG as pointsInside,Gk as polygon,LK as polyhedron,hH as polysideInnerRadius,UM as polysidesBlueprint,tk as positionOnCurve,sC as prewarm,FY as primitives,oH as projectEdges,RT as projectPointOnFace,VY as query,Wa as queryError,EJ as rectangularPattern,yG as registerHandler,nC as registerKernel,bA as registerOperation,vA as registerShape,FG as registerVoxel,hG as rejectAll,aA as removeChild,UT as removeHolesFromFace,KG as repairMesh,SA as replayFrom,xA as replayHistory,mC as resetDisposalStats,eo as resetPerformanceStats,TE as resize,$ as resolve,Rq as resolve3D,Yw as resolveDirection,gT as resolvePlane,iG as resolveRef,fU as reverseCurve,vJ as revolve,oq as roof,Bq as rotate,OU as rotate2D,lU as rotateDrawing,WM as roundedRectangleBlueprint,Hq as scale,kU as scale2D,uU as scaleDrawing,Yq as section,Xq as sectionToFace,wA as serializeHistory,GT as setShapeOrigin,iE as setTagMetadata,Xk as sewShells,GJ as shape,JG as shapeToMeshInput,TT as shapeType,AO as sharedEdges,iJ as shell,tK as shellMesh,iK as shellShape,ek as shellWithEvolution,lJ as simplify,uH as sketchCircle,dH as sketchEllipse,PV as sketchExtrude,jV as sketchFace,gH as sketchFaceOffset,vH as sketchHelix,IV as sketchLoft,NU as sketchOnFace2D,MU as sketchOnPlane2D,_H as sketchParametricFunction,mH as sketchPolysides,fH as sketchRectangle,NV as sketchRevolve,pH as sketchRoundedRectangle,FV as sketchSweep,KW as sketchText,MV as sketchWires,Ba as sketcherStateError,Qq as slice,Jk as solid,Ck as solidFromShell,pq as solveAssembly,Dk as sphere,Zq as split,gA as stepCount,_A as stepsFrom,jU as stretch2D,Wk as subFace,PN as supportExtrude,ZS as supportsConstraintSketch,XS as supportsProjection,EK as surfaceFromGrid,kK as surfaceFromImage,NN as sweep,tE as tagFaces,zk as tangentArc,ya as tap,ba as tapErr,QV as textBlueprints,qW as textMetrics,oJ as thicken,Fk as threePointArc,pJ as toBREP,_O as toBufferGeometryData,vO as toGroupedBufferGeometryData,mK as toKernelVec,bO as toLODGeometryData,yO as toLineGeometryData,EU as toSVGPathD,qw as toVec2,Kw as toVec3,kk as torus,pK as tpmsLattice,Gq as transformCopy,RY as transforms,zq as translate,DU as translate2D,cU as translateDrawing,yT as translatePlane,Aa as tryCatch,ja as tryCatchAsync,IN as twistExtrude,za as typeCastError,pA as undoLast,Ga as unsupportedError,j as unwrap,Da as unwrapErr,Ta as unwrapOr,Ea as unwrapOrElse,oA as updateNode,tG as updateRoles,FT as uvBounds,LT as uvCoordinates,UC as validSolid,nY as validatePlanetary,F as validationError,hk as variableFillet,Xw as vecAdd,cT as vecAngle,tT as vecCross,iT as vecDistance,eT as vecDot,oT as vecEquals,sT as vecIsZero,nT as vecLength,rT as vecLengthSq,$w as vecNegate,aT as vecNormalize,lT as vecProjectToPlane,fT as vecRepr,uT as vecRotate,Qw as vecScale,Zw as vecSub,Kk as vertex,jG as vertexFinder,Uw as vertexPosition,OO as verticesOfEdge,nK as voxelBoolean,aK as voxelBooleanShapes,cA as walkAssembly,HG as windingNumbers,Bk as wire,_j as wireFinder,Vk as wireLoop,DO as wiresOfFace,aC as withKernel,SK as withKernelDir,xK as withKernelPnt,bK as withKernelVec,SC as withScope,TC as withScopeResult,EC as withScopeResultAsync,_a as zipResults};
|