brepjs-verify 0.24.2 → 0.26.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 +74 -0
- package/package.json +1 -1
- package/viewer/dist/assets/{brepjs-CLmCNBtl.js → brepjs--Y77m6Ep.js} +18 -18
- package/viewer/dist/assets/{index-Bw8jgYfD.js → index-BryWZEsB.js} +1 -1
- package/viewer/dist/assets/{kernelWorker--ZofVuMc.js → kernelWorker-aIBoIbHI.js} +1 -1
- package/viewer/dist/index.html +1 -1
|
@@ -4,36 +4,36 @@ var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports);function
|
|
|
4
4
|
`)+`
|
|
5
5
|
`).buffer}function br(e,t,n){let r=e(t,{tolerance:n,angularTolerance:.5,skipNormals:!1}),i=r.vertices,a=r.normals,o=r.triangles,s=i.length/3,c=o.length/3,l=a.length===i.length,u=[`ply`,`format ascii 1.0`,`comment brepjs PLY export`,`element vertex ${s}`,`property float x`,`property float y`,`property float z`];l&&u.push(`property float nx`,`property float ny`,`property float nz`),u.push(`element face ${c}`,`property list uchar int vertex_index`,`end_header`);for(let e=0;e<s;e++){let t=e*3,n=i[t]??0,r=i[t+1]??0,o=i[t+2]??0;if(l){let e=a[t]??0,i=a[t+1]??0,s=a[t+2]??0;u.push(`${n} ${r} ${o} ${e} ${i} ${s}`)}else u.push(`${n} ${r} ${o}`)}for(let e=0;e<c;e++){let t=o[e*3]??0,n=o[e*3+1]??0,r=o[e*3+2]??0;u.push(`3 ${t} ${n} ${r}`)}return new TextEncoder().encode(u.join(`
|
|
6
6
|
`)+`
|
|
7
|
-
`).buffer}function xr(e,t){return e.toBREP(E(t))}function Sr(e,t){return D(e,e.fromBREP(t))}function Cr(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 wr(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 Tr(e,t,n,r){if(n.length===0)return``;let i=Cr(e,t,n.map(e=>({shape:e.shape,name:e.name??``,color:e.color})));try{return wr(e,i)}finally{i.delete()}}function Er(e,t,n,r){return T(`vertex`,e.makeVertex(t,n,r))}function Dr(e,t){throw De(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=ke(t,n.map(E));try{return T(`wire`,e.makeWire(r))}finally{r.delete()}}function kr(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=ke(t,r);try{return T(`wire`,e.makeWire(i))}finally{i.delete()}}function Ar(e,t,n){return T(`face`,e.makeFace(E(t)))}function jr(e,t,n){return T(`edge`,e.makeLineEdge(t[0],t[1],t[2],n[0],n[1],n[2]))}function Mr(e,t,n,r){return T(`edge`,e.makeCircleEdge(t[0],t[1],t[2],n[0],n[1],n[2],r))}function Nr(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 Pr(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 Fr(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 Ir(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 Lr(e,t,n){let r=[];for(let e of n)r.push(e[0],e[1],e[2]);let i=je(t,r);try{return T(`edge`,e.makeBezierEdge(i))}finally{i.delete()}}function Rr(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 zr(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,f=e.makeHelixWire(o,s,c,l,u,d,t,n,r);return e.buildCurves3d(f),T(`wire`,f)}function Br(e,t,n){let r=ke(t,n.map(E));try{return T(`compound`,e.makeCompound(r))}finally{r.delete()}}function Vr(e,t){return T(`solid`,e.solidFromShell(E(t)))}function Hr(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=ke(t,a);try{let t=e.sewAndSolidify(o,i);return t=e.fixFaceOrientations(t),D(e,t)}finally{o.delete()}}function Ur(e,t){return T(`face`,e.makeNonPlanarFace(E(t)))}function Wr(e,t,n,r){let i=ke(t,r.map(E));try{return T(`face`,e.addHolesInFace(E(n),i))}finally{i.delete()}}function Gr(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=Ae(t,a);try{return T(`face`,e.removeHolesFromFace(E(n),o))}finally{o.delete()}}function Kr(e,t,n){let r=E(t);return T(`face`,e.makeFaceOnSurface(r,E(n)))}function qr(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 Jr(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=ke(t,a);try{return D(e,e.sewAndSolidify(o,.001))}finally{o.delete()}}function Yr(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 Xr(e,t,n,r){let i=ke(t,n.map(E));try{let t=e.sewAndSolidify(i,r);return t=e.fixFaceOrientations(t),T(`solid`,t)}finally{i.delete()}}function Zr(e,t,n){return{x:e,y:t,z:n,__type:`point3d`,delete:Ee}}function Qr(e,t,n){return{x:e,y:t,z:n,__type:`direction3d`,delete:Ee}}function $r(e,t,n){return{x:e,y:t,z:n,__type:`vector3d`,delete:Ee}}function ei(e,t,n,r,i,a){return{origin:{x:e,y:t,z:n},direction:{x:r,y:i,z:a},__type:`axis1`,delete:Ee}}function ti(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:Ee}}function ni(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:Ee}}function ri(e){return e}function ii(e){return e}function ai(e,t){return{x:e,y:t}}function oi(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 si(e,t){return{x:e,y:t}}function ci(e,t,n,r){return{px:e,py:t,dx:n,dy:r,delete(){}}}function li(e){return e}function ui(e,t,n,r){return ii(x(e,t,n,r))}function di(e,t,n,r){return ii(S(e,t,n,r))}function fi(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 ii(x(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=S(s,c,l,h);if(!h){let e=-u,t=-f;return t<e-1e-9&&(t+=2*Math.PI),ii({__bk2d:`trimmed`,basis:g,tStart:e,tEnd:t})}let _=f;return _<u-1e-9&&(_+=2*Math.PI),ii({__bk2d:`trimmed`,basis:g,tStart:u,tEnd:_})}function pi(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 ii(x(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,y=(e-p)/h,b=v*s+y*c>0,C=S(p,m,h,b);if(!b){let e=-g,t=-_;return t<e-1e-9&&(t+=2*Math.PI),ii({__bk2d:`trimmed`,basis:C,tStart:e,tEnd:t})}let w=_;return w<g-1e-9&&(w+=2*Math.PI),ii({__bk2d:`trimmed`,basis:C,tStart:g,tEnd:w})}function mi(e,t,n,r,i,a,o){return ii(C(e,t,n,r,i??1,a??0,o??!0))}function hi(e,t,n,r,i,a,o,s,c){return ii({...C(e,t,n,r,o??1,s??0,c??!0),__bk2d:`ellipse`,startAngle:i,endAngle:a})}function gi(e){return ii(w(e))}function _i(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),ii({__bk2d:`bspline`,poles:n,knots:a,multiplicities:o,degree:i,isPeriodic:!1})}function vi(e,t){return _(ri(e),t)}function yi(e,t){return{point:_(ri(e),t),tangent:v(ri(e),t)}}function bi(e){return y(ri(e))}function xi(e){let t=ri(e);for(;t.__bk2d===`trimmed`&&t.basis;)t=t.basis;return b(t)}function Si(e,t,n){return ii({__bk2d:`trimmed`,basis:ri(e),tStart:t,tEnd:n})}function Ci(e){return ii(JSON.parse(JSON.stringify(ri(e))))}function wi(e,t){let n=ri(e),r=y(n),i=[];for(let e=0;e<=20;e++){let a=r.first+(r.last-r.first)*e/20,[o,s]=_(n,a),[c,l]=v(n,a),u=Math.sqrt(c*c+l*l)||1;i.push([o-l/u*t,s+c/u*t])}return ii(w(i.length<=25?i:i.filter((e,t)=>t%2==0||t===i.length-1)))}function Ti(e,t,n){return ii(ee(ri(e),t,n))}function Ei(e,t,n,r){return ii(te(ri(e),t,n,r))}function Di(e,t,n,r){return ii(ne(ri(e),t,n,r))}function Oi(e,t,n){return ii(re(ri(e),t,n))}function ki(e,t,n,r,i){return ii(ie(ri(e),t,n,r,i))}function Ai(e,t,n,r,i,a){let o=Math.sqrt(r*r+i*i);if(o<1e-15)return e;let s=-i/o,c=r/o,l=a-1,u=1+l*s*s,d=l*s*c,f=l*c*s,p=1+l*c*c,m=t-u*t-d*n,h=n-f*t-p*n,g=ri(e),v=y(g),b=[];for(let e=0;e<=20;e++){let[t,n]=_(g,v.first+(v.last-v.first)*e/20);b.push([u*t+d*n+m,f*t+p*n+h])}return ii(w(b))}function ji(e,t,n,r,i,a){return Ai(e,t,n,r,i,a)}function Mi(){return{type:`identity2d`,delete(){}}}function Ni(e,t,n,r,i){return{type:`affinity2d`,axOriginX:e,axOriginY:t,axDirX:n,axDirY:r,ratio:i,delete(){}}}function Pi(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 Ii(e,t,n){return{type:`rotate2d`,angle:e,cx:t,cy:n,delete(){}}}function Li(e,t,n){return{type:`scale2d`,sx:e,sy:e,cx:t,cy:n,delete(){}}}function Ri(e,t,n){let r=e;r.dx=(Number(r.dx)||0)+t,r.dy=(Number(r.dy)||0)+n}function zi(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 Bi(e,t){let n=t;return n.type===`translate2d`?Ti(e,Number(n.dx)||0,Number(n.dy)||0):n.type===`rotate2d`?Ei(e,Number(n.angle)||0,Number(n.cx)||0,Number(n.cy)||0):n.type===`scale2d`?Di(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.axOriginX)||0,Number(n.axOriginY)||0,Number(n.axDirX)||0,Number(n.axDirY)||0,Number(n.ratio)||1):Number(n.dx)||Number(n.dy)?Ti(e,Number(n.dx)||0,Number(n.dy)||0):e}function Vi(e,t,n){let r=ae(ri(e),ri(t),n);return{points:r.points,segments:r.segments.map(e=>ii(e))}}function Hi(e,t,n){let r=ri(e),i=y(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]=_(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]=_(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 Ui(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]=_(ri(e),c);for(let e=0;e<=20;e++){let n=i+(a-i)*(e/20),[r,s]=_(ri(t),n),c=Math.sqrt((r-l)**2+(s-u)**2);c<o&&(o=c)}}return o}function Wi(e,t){let n=ri(e),r=y(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(_(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),ii({__bk2d:`bspline`,poles:a,knots:c,multiplicities:l,degree:o,isPeriodic:!1})}function Gi(e){let t=ri(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[ii(w(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=>ii(w(e)))}function Ki(){return ge()}function qi(e,t,n){_e(e,ri(t),n)}function Ji(e){return{xMin:e.xMin,yMin:e.yMin,xMax:e.xMax,yMax:e.yMax}}function Yi(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 Xi(e,t){return e.xMax<t.xMin||e.xMin>t.xMax||e.yMax<t.yMin||e.yMin>t.yMax}function Zi(e,t,n){return t<e.xMin||t>e.xMax||n<e.yMin||n>e.yMax}function Qi(e){let t=ri(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 $i(e){let t=ri(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 ea(e){let t=ri(e);for(;t.__bk2d===`trimmed`&&t.basis;)t=t.basis;return t.__bk2d===`bezier`&&Array.isArray(t.poles)?t.poles:null}function ta(e){let t=ri(e);for(;t.__bk2d===`trimmed`&&t.basis;)t=t.basis;return t.__bk2d===`bezier`&&Array.isArray(t.poles)?t.poles.length-1:null}function na(e){return me(ri(e))}function ra(e){return ii(he(e))}function ia(e,t){let n=y(ri(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(Si(e,a,o))}return i}function aa(e,t,n,r,i,a){let o=ri(n),[s,c,l]=r,[u,d,f]=i,[p,m,h]=a,g=d*h-f*m,v=f*p-u*h,b=u*m-d*p,x=(e,t)=>[s+e*p+t*g,c+e*m+t*v,l+e*h+t*b],S=o.__bk2d;if(S===`line`){let t=y(o),[n,r]=_(o,t.first),[i,a]=_(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]=_(o,0),[r,i]=_(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=y(o),[n,r]=_(o,t.first),[i,a]=_(o,(t.first+t.last)/2),[s,c]=_(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=y(o),[r,i]=_(o,n.first),[a,s]=_(o,(n.first+n.last)/2),[c,l]=_(o,n.last),p=x(r,i),m=x(a,s),h=x(c,l);return T(`edge`,e.makeArcEdge(p[0],p[1],p[2],m[0],m[1],m[2],h[0],h[1],h[2]))}let C=y(o),w=(C.last-C.first)/24,ee=[];for(let e=0;e<=24;e++){let[t,n]=_(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 oa(e,t,n,r){let i=ri(n),a=y(i),o=E(r),s=new t.VectorDouble;for(let t=0;t<=30;t++){let[n,r]=_(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 sa(e){return e}function ca(){return ii(x(0,0,1,0))}function la(e,t){e.buildCurves3d(E(t))}function ua(e,t,n,r){return T(`wire`,e.fixWireOnFace(E(t),E(n),r))}function da(e){try{let t=Me(e.modified),n=Me(e.generated),r=Me(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 fa(e,t,n,r,i,a,o,s){let c=Ae(t,o);try{let{id:t,evolution:o}=da(e.translateWithHistory(E(n),r,i,a,c,s));return{shape:D(e,t),evolution:o}}finally{c.delete()}}function pa(e,t,n,r,i,a,o,s){let c=o??[0,0,1],l=s??[0,0,0],u=Ae(t,i);try{let{id:t,evolution:i}=da(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 ma(e,t,n,r,i,a,o){let s=Ae(t,a);try{let{id:t,evolution:a}=da(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 ha(e,t,n,r,i,a,o){let s=Ae(t,a);try{let{id:t,evolution:a}=da(e.scaleWithHistory(E(n),r[0],r[1],r[2],i,s,o));return{shape:D(e,t),evolution:a}}finally{s.delete()}}function ga(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 _a(e,t,n,r,i,a,o){let s=Ae(t,i);try{let{id:t,evolution:i}=da(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 va(e,t,n,r,i,a,o){let s=Ae(t,i);try{let{id:t,evolution:i}=da(e.cutWithHistory(E(n),Re(e,r),s,a));return{shape:D(e,t),evolution:i,diagnostics:{hasErrors:!1,hasWarnings:!1,messages:[]}}}finally{s.delete()}}function ya(e,t,n,r,i,a,o){let s=Ae(t,i);try{let{id:t,evolution:i}=da(e.intersectWithHistory(E(n),Re(e,r),s,a));return{shape:D(e,t),evolution:i,diagnostics:{hasErrors:!1,hasWarnings:!1,messages:[]}}}finally{s.delete()}}function ba(e,t,n,r,i,a,o){let s=Pe(r,i),c=ke(t,r.map(E)),l=Ae(t,a);try{let{id:t,evolution:r}=da(e.filletWithHistory(E(n),c,s,l,o));return{shape:D(e,t),evolution:r}}finally{c.delete(),l.delete()}}function xa(e,t,n,r,i,a,o){let s=Pe(r,i),c=ke(t,r.map(E)),l=Ae(t,a);try{let{id:t,evolution:r}=da(e.chamferWithHistory(E(n),c,s,l,o));return{shape:D(e,t),evolution:r}}finally{c.delete(),l.delete()}}function Sa(e,t,n,r,i,a,o,s){let c=ke(t,r.map(E)),l=Ae(t,a);try{let{id:t,evolution:r}=da(e.shellWithHistory(E(n),c,i,s??.001,l,o));return{shape:D(e,t),evolution:r}}finally{c.delete(),l.delete()}}function Ca(e,t,n,r,i,a){let o=Ae(t,i);try{let{id:t,evolution:i}=da(e.thickenWithHistory(E(n),r,.001,o,a));return{shape:D(e,t),evolution:i}}finally{o.delete()}}function wa(e,t,n,r,i,a,o){let s=Ae(t,i);try{let{id:t,evolution:i}=da(e.offsetWithHistory(E(n),r,o??1e-6,s,a));return{shape:D(e,t),evolution:i}}finally{s.delete()}}function Ta(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 Ea(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 Da(e,t,n,r){if(n.length<4)throw Error(`hullFromPoints: need at least 4 points`);let{points:i,faces:a}=g(n,r);if(a.length<4)throw Error(`hullFromPoints: degenerate hull (fewer than 4 faces)`);return Hr(e,t,[...i],[...a],r)}function Oa(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 ka(e,t,n,r){if(n.length===0)throw Error(`hull: no shapes provided`);let i=Oa(e,t,n,r);if(i.length<4)throw Error(`hull: fewer than 4 vertices extracted from input shapes`);return Da(e,t,i,r)}function Aa(e){throw Error(`occt-wasm: ${e} is not yet implemented`)}var ja=class e{oc;kernelId=`occt-wasm`;capabilities=r;Module;k;owner;constructor(e,t,n){this.Module=e,this.k=Ie(t,e),this.oc=Le(e,this.k),this.owner=n}static fromKernel(t){return new e(t.getRawModule(),t.getRawKernel(),t)}get retainedKernelOwner(){return this.owner}dispose(e){De(e)?this.k.release(e.id):typeof e.delete==`function`&&e.delete()}executeBatch(e){Aa(`executeBatch`)}checkpoint(){Aa(`checkpoint`)}checkpointCount(){Aa(`checkpointCount`)}restoreCheckpoint(e){Aa(`restoreCheckpoint`)}discardCheckpoint(e){Aa(`discardCheckpoint`)}makeBox(e,t,n){return Je(this.k,e,t,n)}makeCylinder(e,t,n,r){return Ye(this.k,e,t,n,r)}makeSphere(e,t){return Xe(this.k,e,t)}makeCone(e,t,n,r,i){return Ze(this.k,e,t,n,r,i)}makeTorus(e,t,n,r){return Qe(this.k,e,t,n,r)}makeEllipsoid(e,t,n){return $e(this.k,e,t,n)}makeBoxFromCorners(e,t){return et(this.k,e,t)}makeRectangle(e,t){return tt(this.k,e,t)}fuse(e,t,n){return ze(this.k,e,t,n)}cut(e,t,n){return Be(this.k,e,t,n)}intersect(e,t,n){return Ve(this.k,e,t,n)}section(e,t,n){return He(this.k,e,t,n)}fuseAll(e,t){return Ue(this.k,this.Module,e,t)}cutAll(e,t,n){return We(this.k,this.Module,e,t,n)}split(e,t){return Ge(this.k,this.Module,e,t)}checkBoolean(e,t,n){return Ke(this.k,e,t,n)}meshBoolean(e,t,n,r,i,a){return qe(e,t,n,r,i,a)}makeVertex(e,t,n){return Er(this.k,e,t,n)}makeEdge(e,t,n){return Dr(this.k,e)}makeWire(e){return Or(this.k,this.Module,e)}makeFace(e,t){return Ar(this.k,e,t)}makeLineEdge(e,t){return jr(this.k,e,t)}makeCircleEdge(e,t,n){return Mr(this.k,e,t,n)}makeCircleArc(e,t,n,r,i){return Nr(this.k,e,t,n,r,i)}makeArcEdge(e,t,n){return Pr(this.k,e,t,n)}makeEllipseEdge(e,t,n,r,i){return Fr(this.k,e,t,n,r)}makeEllipseArc(e,t,n,r,i,a,o){return Ir(this.k,e,t,n,r,i,a)}makeBezierEdge(e){return Lr(this.k,this.Module,e)}makeTangentArc(e,t,n){return Rr(this.k,e,t,n)}makeHelixWire(e,t,n,r,i,a){return zr(this.k,e,t,n,r,i)}makeWireFromMixed(e){return kr(this.k,this.Module,e)}makeCompound(e){return Br(this.k,this.Module,e)}solidFromShell(e){return Vr(this.k,e)}hull(e,t){return ka(this.k,this.Module,e,t)}hullFromPoints(e,t){return Da(this.k,this.Module,e,t)}buildSolidFromFaces(e,t,n){return Hr(this.k,this.Module,e,t,n)}makeNonPlanarFace(e){return Ur(this.k,e)}addHolesInFace(e,t){return Wr(this.k,this.Module,e,t)}removeHolesFromFace(e){return Gr(this.k,this.Module,e)}makeFaceOnSurface(e,t){return Kr(this.k,e,t)}bsplineSurface(e,t,n){return qr(this.k,this.Module,e,t,n)}triangulatedSurface(e,t,n){return Jr(this.k,this.Module,e,t,n)}buildTriFace(e,t,n){return Yr(this.k,e,t,n)}sewAndSolidify(e,t){return Xr(this.k,this.Module,e,t)}createPoint3d(e,t,n){return Zr(e,t,n)}createDirection3d(e,t,n){return Qr(e,t,n)}createVector3d(e,t,n){return $r(e,t,n)}createAxis1(e,t,n,r,i,a){return ei(e,t,n,r,i,a)}createAxis2(e,t,n,r,i,a,o,s,c){return ti(e,t,n,r,i,a,o,s,c)}createAxis3(e,t,n,r,i,a,o,s,c){return ni(e,t,n,r,i,a,o,s,c)}extrude(e,t,n){return Hn(this.k,e,t,n)}revolve(e,t,n){return Un(this.k,e,t,n)}loft(e,t,n,r){return Wn(this.k,this.Module,e,t,n,r)}sweep(e,t,n){return Gn(this.k,e,t,n)}simplePipe(e,t){return Kn(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){Aa(`sweepWithOptions`)}sweepPipeShell(e,t,n){return qn(this.k,e,t,n)}loftAdvanced(e,t){return Jn(this.k,this.Module,e,t)}buildExtrusionLaw(e,t,n){return Yn(this.k,e,t,n)}revolveVec(e,t,n,r){return Xn(this.k,e,t,n,r)}draftPrism(e,t,n,r,i,a){return Zn(this.k,e,t,n,r,i,a)}fillet(e,t,n){return An(this.k,this.Module,e,t,n)}chamfer(e,t,n){return jn(this.k,this.Module,e,t,n)}chamferDistAngle(e,t,n,r){return Mn(this.k,this.Module,e,t,n,r)}shell(e,t,n,r){return Nn(this.k,this.Module,e,t,n,r)}thicken(e,t){return Pn(this.k,e,t)}offset(e,t,n){return Fn(this.k,e,t,n)}filletVariable(e,t){return In(this.k,e,t)}draft(e,t,n,r,i){return Ln(this.k,e,t,n,r,i)}defeature(e,t){return Rn(this.k,this.Module,e,t)}offsetWire2D(e,t,n){return zn(this.k,e,t,n)}simplify(e){return Bn(this.k,e)}reverseShape(e){return Vn(this.k,e)}composeTransform(e){return Qn(e)}transform(e,t){return $n(this.k,this.Module,e,t)}translate(e,t,n,r){return er(this.k,e,t,n,r)}rotate(e,t,n,r){return tr(this.k,e,t,n,r)}mirror(e,t,n){return nr(this.k,e,t,n)}scale(e,t,n){return rr(this.k,e,t,n)}generalTransform(e,t,n,r){return ir(this.k,this.Module,e,t,n,r)}generalTransformNonOrthogonal(e,t,n){return ir(this.k,this.Module,e,t,n,!1)}positionOnCurve(e,t,n){return ar(this.k,this.Module,e,t,n)}linearPattern(e,t,n,r){return or(this.k,e,t,n,r)}circularPattern(e,t,n,r,i){return sr(this.k,e,t,n,r,i)}transformBatch(e){return cr(this.k,e)}translateWithHistory(e,t,n,r,i,a){return fa(this.k,this.Module,e,t,n,r,i,a)}rotateWithHistory(e,t,n,r,i,a){return pa(this.k,this.Module,e,t,n,r,i,a)}mirrorWithHistory(e,t,n,r,i){return ma(this.k,this.Module,e,t,n,r,i)}scaleWithHistory(e,t,n,r,i){return ha(this.k,this.Module,e,t,n,r,i)}generalTransformWithHistory(e,t,n,r,i,a){return ga((e,t,n,r)=>this.generalTransform(e,t,n,r),e,t,n,r,i)}fuseWithHistory(e,t,n,r,i){return _a(this.k,this.Module,e,t,n,r,i)}cutWithHistory(e,t,n,r,i){return va(this.k,this.Module,e,t,n,r,i)}intersectWithHistory(e,t,n,r,i){return ya(this.k,this.Module,e,t,n,r,i)}filletWithHistory(e,t,n,r,i){return ba(this.k,this.Module,e,t,n,r,i)}chamferWithHistory(e,t,n,r,i){return xa(this.k,this.Module,e,t,n,r,i)}shellWithHistory(e,t,n,r,i,a){return Sa(this.k,this.Module,e,t,n,r,i,a)}thickenWithHistory(e,t,n,r){return Ca(this.k,this.Module,e,t,n,r)}offsetWithHistory(e,t,n,r,i){return wa(this.k,this.Module,e,t,n,r,i)}draftWithHistory(e,t,n,r,i,a,o){return Ta(this.k,e,t,n,i)}applyComposedTransformWithHistory(e,t,n,r){return Ea((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 Ct(this.k,this.Module,e,t)}meshEdges(e,t,n){return Tt(this.k,this.Module,e,t,n)}hasTriangulation(e){return Et(this.k,e)}meshShape(e,t,n){Dt(this.k,e,t,n)}exportSTEP(e){return dr(this.k,this.makeCompound.bind(this),e)}exportSTL(e,t,n,r){return fr(this.mesh.bind(this),e,t,n,r)}importSTEP(e){return pr(this.k,e)}importSTL(e){return mr(this.k,this.Module,e)}exportIGES(e){return hr(this.k,this.makeCompound.bind(this),e)}importIGES(e){return gr(this.k,e)}exportSTEPAssembly(e,t){return _r(this.k,this.Module,e,t)}export3MF(e,t){throw Error(`export3MF is only available with the brepkit kernel`)}exportGLB(e,t){return vr(this.mesh.bind(this),e,t)}exportOBJ(e,t){return yr(this.mesh.bind(this),e,t)}exportPLY(e,t){return br(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 xr(this.k,e)}fromBREP(e){return Sr(this.k,e)}createXCAFDocument(e){return Cr(this.k,this.Module,e)}writeXCAFToSTEP(e,t){return wr(this.k,e,t)}exportSTEPConfigured(e,t){return Tr(this.k,this.Module,e,t)}volume(e){return dn(this.k,e)}area(e){return fn(this.k,e)}length(e){return pn(this.k,e)}centerOfMass(e){return mn(this.k,e)}linearCenterOfMass(e){return hn(this.k,e)}boundingBox(e){return gn(this.k,e)}distance(e,t){return Sn(this.k,this.Module,e,t)}surfaceCurvature(e,t,n){return kn(this.k,e,t,n)}surfaceCenterOfMass(e){return _n(this.k,e)}measureBulk(e,t){return vn(this.k,e,t)}createDistanceQuery(e){return yn(this.k,e)}iterShapes(e,t){return nt(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 rt(this.k,e)}isSame(e,t){return it(this.k,e,t)}isEqual(e,t){return at(this.k,e,t)}downcast(e,t){return ot(this.k,e,t)}hashCode(e,t){return st(this.k,e,t)}isNull(e){return ct(this.k,e)}shapeOrientation(e){return lt(this.k,e)}edgeToFaceMap(e){return ut(this.k,e)}sharedEdges(e,t){return dt(this.k,e,t)}adjacentFaces(e,t){return ft(this.k,e,t)}sew(e,t){return pt(this.k,this.Module,e,t)}curveType(e){return kt(this.k,e)}curveParameters(e){return At(this.k,e)}curvePointAtParam(e,t){return jt(this.k,e,t)}curveTangent(e,t){return Mt(this.k,e,t)}curveIsClosed(e){return Nt(this.k,e)}curveIsPeriodic(e){return Pt(this.k,e)}curvePeriod(e){return Ft(this.k,e)}interpolatePoints(e,t){return It(this.k,this.Module,e,t)}approximatePoints(e,t){return Lt(this.k,this.Module,e,t)}curveDegreeElevate(e,t){return Rt(this.k,e,t)}curveKnotInsert(e,t,n){return zt(this.k,e,t,n)}curveKnotRemove(e,t,n){return Bt(this.k,e,t,n)}curveSplit(e,t){return Vt(this.k,e,t)}getBezierPenultimatePole(e){return Ht(this.k,e)}createCurveAdaptor(e){Aa(`createCurveAdaptor`)}vertexPosition(e){return Wt(this.k,e)}surfaceType(e){return Gt(this.k,e)}uvBounds(e){return Kt(this.k,e)}outerWire(e){return qt(this.k,e)}surfaceNormal(e,t,n){return Jt(this.k,e,t,n)}pointOnSurface(e,t,n){return Yt(this.k,e,t,n)}uvFromPoint(e,t){return sn(this.k,e,t)}projectPointOnFace(e,t){return cn(this.k,e,t)}classifyPointOnFace(e,t,n,r){return ln(this.k,e,t,n,r)}classifyPointRobust(e,t,n){Aa(`classifyPointRobust`)}classifyPointWinding(e,t,n){Aa(`classifyPointWinding`)}approximateSurfaceLspia(e,t,n,r,i,a,o,s,c){Aa(`approximateSurfaceLspia`)}untrimFace(e,t,n){Aa(`untrimFace`)}getSurfaceCylinderData(e){return on(this.k,e)}getSurfaceAxis(e){return an(this.k,e)}reverseSurfaceU(e){Aa(`reverseSurfaceU`)}detectSmallFeatures(e,t,n){Aa(`detectSmallFeatures`)}recognizeFeatures(e,t){Aa(`recognizeFeatures`)}projectEdges(e,t,n,r){return un(this.k,this.Module,e,t,n,r)}isValid(e){return ht(this.k,e)}healSolid(e){return gt(this.k,e)}healFace(e){return _t(this.k,e)}healWire(e,t){return vt(this.k,e,t)}mergeCoincidentVertices(e,t){return yt(this.k,e,t)}removeDegenerateEdges(e,t){return bt(this.k,e,t)}fixFaceOrientations(e){return xt(this.k,e)}fixShape(e){return St(this.k,e)}fixSelfIntersection(e){Aa(`fixSelfIntersection`)}createPoint2d(e,t){return ai(e,t)}createDirection2d(e,t){return oi(e,t)}createVector2d(e,t){return si(e,t)}createAxis2d(e,t,n,r){return ci(e,t,n,r)}wrapCurve2dHandle(e){return li(e)}createCurve2dAdaptor(e){Aa(`createCurve2dAdaptor`)}makeLine2d(e,t,n,r){return ui(e,t,n,r)}makeCircle2d(e,t,n,r){return di(e,t,n,r)}makeArc2dThreePoints(e,t,n,r,i,a){return fi(e,t,n,r,i,a)}makeArc2dTangent(e,t,n,r,i,a){return pi(e,t,n,r,i,a)}makeEllipse2d(e,t,n,r,i,a,o){return mi(e,t,n,r,i,a,o)}makeEllipseArc2d(e,t,n,r,i,a,o,s,c){return hi(e,t,n,r,i,a,o,s,c)}makeBezier2d(e){return gi(e)}makeBSpline2d(e,t){return _i(e)}evaluateCurve2d(e,t){return vi(e,t)}evaluateCurve2dD1(e,t){return yi(e,t)}getCurve2dBounds(e){return bi(e)}getCurve2dType(e){return xi(e)}trimCurve2d(e,t,n){return Si(e,t,n)}reverseCurve2d(e){}copyCurve2d(e){return Ci(e)}offsetCurve2d(e,t){return wi(e,t)}translateCurve2d(e,t,n){return Ti(e,t,n)}rotateCurve2d(e,t,n,r){return Ei(e,t,n,r)}scaleCurve2d(e,t,n,r){return Di(e,t,n,r)}mirrorCurve2dAtPoint(e,t,n){return Oi(e,t,n)}mirrorCurve2dAcrossAxis(e,t,n,r,i){return ki(e,t,n,r,i)}affinityTransform2d(e,t,n,r,i,a){return ji(e,t,n,r,i,a)}createIdentityGTrsf2d(){return Mi()}createAffinityGTrsf2d(e,t,n,r,i){return Ni(e,t,n,r,i)}createTranslationGTrsf2d(e,t){return Pi(e,t)}createMirrorGTrsf2d(e,t,n,r,i,a,o){return Fi(e,t,n,r,i,a,o)}createRotationGTrsf2d(e,t,n){return Ii(e,t,n)}createScaleGTrsf2d(e,t,n){return Li(e,t,n)}setGTrsf2dTranslationPart(e,t,n){Ri(e,t,n)}multiplyGTrsf2d(e,t){zi(e,t)}transformCurve2dGeneral(e,t){return Bi(e,t)}intersectCurves2d(e,t,n){return Vi(e,t,n)}projectPointOnCurve2d(e,t,n){return Hi(e,t,n)}distanceBetweenCurves2d(e,t,n,r,i,a){return Ui(e,t,n,r,i,a)}approximateCurve2dAsBSpline(e,t,n,r){return Wi(e,r)}decomposeBSpline2dToBeziers(e){return Gi(e)}createBoundingBox2d(){return Ki()}addCurveToBBox2d(e,t,n){qi(e,t,n)}getBBox2dBounds(e){return Ji(e)}mergeBBox2d(e,t){Yi(e,t)}isBBox2dOut(e,t){return Xi(e,t)}isBBox2dOutPoint(e,t,n){return Zi(e,t,n)}getCurve2dCircleData(e){return Qi(e)}getCurve2dEllipseData(e){return $i(e)}getCurve2dBezierPoles(e){return ea(e)}getCurve2dBezierDegree(e){return ta(e)}getCurve2dBSplineData(e){Aa(`getCurve2dBSplineData`)}serializeCurve2d(e){return na(e)}deserializeCurve2d(e){return ra(e)}splitCurve2d(e,t){return ia(e,t)}liftCurve2dToPlane(e,t,n,r){return aa(this.k,this.Module,e,t,n,r)}buildEdgeOnSurface(e,t){return oa(this.k,this.Module,e,t)}extractSurfaceFromFace(e){return sa(e)}extractCurve2dFromEdge(e,t){return ca()}buildCurves3d(e){la(this.k,e)}fixWireOnFace(e,t,n){return ua(this.k,e,t,n)}fillSurface(e,t){Aa(`fillSurface`)}getNurbsCurveData(e){return Ut(this.k,e)}};function O(e){return{ok:!0,value:e}}function k(e){return{ok:!1,error:e}}var Ma=O(void 0);function Na(e){return e.ok}function A(e){return!e.ok}function Pa(e,t){return e.ok?O(t(e.value)):e}function Fa(e,t){return e.ok?e:k(t(e.error))}function Ia(e,t){return e.ok?t(e.value):e}var La=Ia;function Ra(e,t){return e.ok?e:t}function za(e,t){return e.ok?e:t(e.error)}function Ba(e,t){return e.ok?t.ok?O([e.value,t.value]):t:e}var Va=Qa;function Ha(e,t){return e.ok&&t(e.value),e}function Ua(e,t){return e.ok||t(e.error),e}function Wa(e){return e.ok?e.value:e}function Ga(e,t,n){return e.ok?O(t(e.value)):k(n(e.error))}function Ka(e,t){return e==null?k(t()):O(e)}function qa(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: ${qa(e.error)}`)}function Ja(e,t){return e.ok?e.value:t}function Ya(e,t){return e.ok?e.value:t(e.error)}function Xa(e){if(!e.ok)return e.error;throw Error(`Called unwrapErr() on an Ok: ${String(e.value)}`)}function Za(e,t){return e.ok?t.ok(e.value):t.err(e.error)}function Qa(e){let t=[];for(let n of e){if(!n.ok)return n;t.push(n.value)}return O(t)}function $a(e,t){try{return O(e())}catch(e){return k(t(e))}}async function eo(e,t){try{return O(await e())}catch(e){return k(t(e))}}function to(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 no=class extends Error{location;constructor(e,t){super(`Bug in ${e}: ${t}`),this.name=`BrepBugError`,this.location=e}};function M(e,t){throw new no(e,t)}var ro=[{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.`}],io={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 ao(e){return io[e]}function oo(e){for(let{pattern:t,translation:n}of ro)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 so(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 so(`KERNEL_OPERATION`,e,t,n,r,i)}function F(e,t,n,r,i){return so(`VALIDATION`,e,t,n,r,i)}function co(e,t,n,r,i){return so(`TYPE_CAST`,e,t,n,r,i)}function lo(e,t,n,r,i){return so(`SKETCHER_STATE`,e,t,n,r,i)}function uo(e,t,n,r,i){return so(`MODULE_INIT`,e,t,n,r,i)}function fo(e,t,n,r,i){return so(`COMPUTATION`,e,t,n,r,i)}function po(e,t,n,r,i){return so(`IO`,e,t,n,r,i)}function mo(e,t,n,r,i){return so(`QUERY`,e,t,n,r,i)}function ho(e,t,n,r,i){return so(`UNSUPPORTED`,e,t,n,r,i)}function go(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)}var _o={draft:{tolerance:.01,angularTolerance:.5},standard:{tolerance:.001,angularTolerance:.1},fine:{tolerance:1e-4,angularTolerance:.05}},vo=`standard`;function yo(){return vo}function bo(e=vo){return _o[e]}function xo(e){vo=e}function So(e){return`makeLine2d`in e}var Co=[`boolean`,`loft`,`extrude`,`shell`,`fillet`,`mesh`,`edgeMesh`,`transform`],wo=Object.create(null),To=Object.create(null);function Eo(){for(let e of Co)wo[e]=0,To[e]=0}Eo();function Do(e){let t=performance.now();return()=>{wo[e]=(wo[e]??0)+(performance.now()-t),To[e]=(To[e]??0)+1}}function Oo(){let e={};for(let t of Co)e[t]={totalMs:wo[t]??0,count:To[t]??0};return e}function ko(){Eo()}var Ao;function jo(){Ao=void 0}function Mo(e){return Ao??=typeof e.BooleanBatch==`function`,Ao}function No(e){return e===`commonFace`?1:e===`sameFace`?2:0}function Po(e,t,n={}){if(!Mo(e))return null;let r=Do(`boolean`),i=new e.BooleanBatch;try{for(let e of t)i.addShape(e);return i.fuseAll(No(n.optimisation),!!n.simplify,n.fuzzyValue??0)}finally{i.delete(),r()}}function Fo(e,t,n,r={}){if(!Mo(e))return null;if(n.length===0)return t;let i=Do(`boolean`),a=new e.BooleanBatch;try{for(let e of n)a.addShape(e);return a.cutAll(t,No(r.optimisation),!!r.simplify,r.fuzzyValue??0)}finally{a.delete(),i()}}var Io=2147483647,Lo;function Ro(){Lo=void 0}function zo(e){return Lo??=typeof e.MeasurementExtractor?.extract==`function`,Lo}function Bo(e,t,n=!1){if(zo(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:Vo(e,t),area:Ho(e,t),length:n?Uo(e,t):0,centerOfMass:Wo(e,t),boundingBox:Ko(e,t)}}function Vo(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 Ho(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 Uo(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 Wo(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 Go(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 Ko(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 qo(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 Jo(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 Yo(e){return{volume:t=>Vo(e,t),area:t=>Ho(e,t),length:t=>Uo(e,t),centerOfMass:t=>Wo(e,t),linearCenterOfMass:t=>Go(e,t),boundingBox:t=>Ko(e,t),distance:(t,n)=>qo(e,t,n),classifyPointOnFace:(t,n,r,i)=>Jo(e,t,n,r,i),measureBulk:(t,n)=>Bo(e,t,n)}}var Xo={vertex:7,edge:6,wire:5,face:4,shell:3,solid:2,compsolid:1,compound:0};function Zo(e,t,n){let r=e.TopologyExtractor.extract(t,Xo[n]),i=r.getShapesCount(),a=[];for(let e=0;e<i;e++)a.push(r.getShape(e));return r.delete(),a}var Qo=new WeakMap;function $o(e,t,n){let r=Qo.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},Qo.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,Io),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 es(e,t,n){return e.TopologyExtractor?Zo(e,t,n):$o(e,t,n)}var ts=new WeakMap;function ns(e){let t=ts.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`]]),ts.set(e,t)}return t}function rs(e,t){if(t.IsNull())throw Error(`Cannot determine shape type: shape is null`);let n=ns(e).get(t.ShapeType());if(!n)throw Error(`Unknown shape type enum value`);return n}function is(e,t){let n=new e.BRepCheck_Analyzer(t,!0,!1,!1),r=n.IsValid_2();return n.delete(),r}function as(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 os(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 ss(e,t){return e.IsSame(t)}function cs(e,t){return e.IsEqual(t)}function ls(e){return{iterShapes:(t,n)=>es(e,t,n),iterShapeList:(t,n)=>{os(e,t,n)},shapeType:t=>rs(e,t),isSame:(e,t)=>ss(e,t),isEqual:(e,t)=>cs(e,t),isValid:t=>is(e,t),sew:(t,n)=>as(e,t,n)}}var us=.001;function ds(e,t,n){n===`commonFace`&&t.SetGlue(e.BOPAlgo_GlueEnum.BOPAlgo_GlueShift),n===`sameFace`&&t.SetGlue(e.BOPAlgo_GlueEnum.BOPAlgo_GlueFull)}function fs(e,t){e.SetRunParallel(!0),e.SetUseOBB?.(!0),t!==void 0&&t>0&&e.SetFuzzyValue?.(t)}function ps(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 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 hs(e,t,n,r={}){let i=Do(`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);ds(e,c,i),fs(c,o),c.Build(s),a&&c.SimplifyResult(!0,!0,us);let l=c.Shape();return c.delete(),s.delete(),l}finally{i()}}function gs(e,t,n,r={}){let i=Do(`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);ds(e,c,i),fs(c,o),c.Build(s),a&&c.SimplifyResult(!0,!0,us);let l=c.Shape();return c.delete(),s.delete(),l}finally{i()}}function _s(e,t,n,r={}){let i=Do(`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);ds(e,c,i),fs(c,o),c.Build(s),a&&c.SimplifyResult(!0,!0,us);let l=c.Shape();return c.delete(),s.delete(),l}finally{i()}}function vs(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),fs(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 ys(e,t,n={}){let r=Po(e,t,n);if(r!==null)return r;let i=Do(`boolean`);try{let{optimisation:r,simplify:i=!1}=n,a=n.fuzzyValue??ps(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),ds(e,s,r),fs(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 bs(e,n,r,i,a){a.signal?.throwIfAborted();let o=i-r;if(o===1)return t(n,r);if(o===2)return hs(e,n[r],n[r+1],{...a,simplify:!1});let s=r+Math.ceil(o/2);return hs(e,bs(e,n,r,s,a),bs(e,n,s,i,a),{...a,simplify:!1})}function xs(e,t,n={}){let r=bs(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 Ss(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`?xs(e,n,r):ys(e,n,r)}function Cs(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),fs(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 ws(e,t,n,r={}){if(n.length===0)return t;let i=Fo(e,t,n,r);if(i!==null)return i;let a=ms(e,n),o=gs(e,t,a,r);return a.delete(),o}function Ts(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 Es(e){return{fuse:(t,n,r)=>hs(e,t,n,r),cut:(t,n,r)=>gs(e,t,n,r),intersect:(t,n,r)=>_s(e,t,n,r),section:(t,n,r)=>vs(e,t,n,r),fuseAll:(t,n)=>Ss(e,t,n),cutAll:(t,n,r)=>ws(e,t,n,r),split:(t,n)=>Cs(e,t,n),checkBoolean:(t,n,r)=>Ts(e,t,n,r,t=>is(e,t))}}var Ds={fuse:0,cut:1,intersect:2};function Os(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(Ds[e.op],e.tool);let e=r.execute(t,i,a);return e.IsNull()?null:e}finally{r.delete()}}}function ks(e){return{booleanPipeline:(t,n,r)=>Os(e,t,n,r)??null}}function As(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 js(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 Ms(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 Ns(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=es(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 Ps(e,t,n,r){let i=new e.BRepPrimAPI_MakeBox_2(t,n,r),a=i.Solid();return i.delete(),a}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_MakeCylinder_3(s,t,n),l=c.Shape();return c.delete(),s.delete(),a.delete(),o.delete(),l}function Is(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 Rs(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 zs(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 Bs(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 Vs(e){return{makeVertex:(t,n,r)=>As(e,t,n,r),makeEdge:(t,n,r)=>js(e,t,n,r),makeWire:t=>Ms(e,t),makeWireFromMixed:t=>zs(e,t),makeFace:(t,n)=>Ns(e,t,n),makeBox:(t,n,r)=>Ps(e,t,n,r),makeCylinder:(t,n,r,i)=>Fs(e,t,n,r,i),makeSphere:(t,n)=>Is(e,t,n),makeCone:(t,n,r,i,a)=>Ls(e,t,n,r,i,a),makeTorus:(t,n,r,i)=>Bs(e,t,n,r,i),buildTriFace:(t,n,r)=>Rs(e,t,n,r)}}function Hs(e,t){let n=e[t];if(n===void 0)throw Error(`Index ${t} out of bounds`);return n}function Us(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 Ws(e,t,n){let{faces:r,points:i}=t,a=[];for(let[t,n,o]of r){let r=Hs(i,t),s=Hs(i,n),c=Hs(i,o),l=Rs(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 Gs(e,t,n){if(t.length===0)throw Error(`hull: no shapes provided`);let r=Us(e,t,n);if(r.length<4)throw Error(`hull: fewer than 4 vertices extracted from input shapes`);let i=g(r,n);if(i.faces.length<4)throw Error(`hull: degenerate hull (fewer than 4 faces)`);return Ws(e,i,n)}function Ks(e,t,n,r){return Ws(e,{points:t,faces:n},r)}function qs(e,t,n){if(t.length<4)throw Error(`hullFromPoints: fewer than 4 points`);let r=g(t,n);if(r.faces.length<4)throw Error(`hullFromPoints: degenerate hull (fewer than 4 faces)`);return Ws(e,r,n)}function Js(e){return{hull:(t,n)=>Gs(e,t,n),hullFromPoints:(t,n)=>qs(e,t,n),buildSolidFromFaces:(t,n,r)=>Ks(e,t,n,r)}}function Ys(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 Xs(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 Zs(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 Qs(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 $s(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 ec(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 tc(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 nc(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 rc(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 ic(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 ac(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=ic(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 oc(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 sc(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 cc(e,t){let n=new e.ShapeFix_Solid_1,r=n.SolidFromShell(e.TopoDS_Cast.Shell(t));return n.delete(),r}function lc(e,t){return e.BRepToolsWrapper.Write(t)}function uc(e,t){return e.BRepToolsWrapper.Read(t)}function dc(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 fc(e,t){try{t.delete()}catch{}}function pc(e,t,n){let r=Ys(e,[0,0,0],[t,0,0]),i=Ys(e,[t,0,0],[t,n,0]),a=Ys(e,[t,n,0],[0,n,0]),o=Ys(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 mc(e,t,n,r){return new e.gp_Pnt_3(t,n,r)}function hc(e,t,n,r){return new e.gp_Dir_5(t,n,r)}function gc(e,t,n,r){return new e.gp_Vec_4(t,n,r)}function _c(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 vc(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 yc(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 bc(e){return{makeLineEdge:(t,n)=>Ys(e,t,n),makeCircleEdge:(t,n,r)=>Xs(e,t,n,r),makeCircleArc:(t,n,r,i,a)=>Zs(e,t,n,r,i,a),makeArcEdge:(t,n,r)=>Qs(e,t,n,r),makeEllipseEdge:(t,n,r,i,a)=>ec(e,t,n,r,i,a),makeEllipseArc:(t,n,r,i,a,o,s)=>tc(e,t,n,r,i,a,o,s),makeBezierEdge:t=>nc(e,t),makeTangentArc:(t,n,r)=>$s(e,t,n,r),makeHelixWire:(t,n,r,i,a,o)=>rc(e,t,n,r,i,a,o),makeCompound:t=>oc(e,t),makeBoxFromCorners:(t,n)=>sc(e,t,n),makeRectangle:(t,n)=>pc(e,t,n),solidFromShell:t=>cc(e,t),makeEllipsoid:(t,n,r)=>ac(e,t,n,r),toBREP:t=>lc(e,t),fromBREP:t=>uc(e,t),exportSTEPAssembly:(t,n)=>dc(e,t,n??{}),dispose:t=>{fc(e,t)},createPoint3d:(t,n,r)=>mc(e,t,n,r),createDirection3d:(t,n,r)=>hc(e,t,n,r),createVector3d:(t,n,r)=>gc(e,t,n,r),createAxis1:(t,n,r,i,a,o)=>_c(e,t,n,r,i,a,o),createAxis2:(t,n,r,i,a,o,s,c,l)=>vc(e,t,n,r,i,a,o,s,c,l),createAxis3:(t,n,r,i,a,o,s,c,l)=>yc(e,t,n,r,i,a,o,s,c,l)}}function xc(e,t,n,r){let i=Do(`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 Sc(e,t,n,r){let i=new e.BRepPrimAPI_MakeRevol_1(t,n,r,!1),a=i.Shape();return i.delete(),a}function Cc(e,t,n=!1,r,i){let a=Do(`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 wc(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 Tc(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=a;if(t.IsDone()){let n=t.Solid(),r=new e.BRepCheck_Analyzer(n,!0,!1,!1);r.IsValid_2()?o=n:n.delete(),r.delete()}return n.delete(),t.delete(),r.delete(),o}return r.delete(),a}var Ec,Dc;function Oc(){Ec=void 0}function kc(){Dc=void 0}function Ac(e){return Ec??=typeof e.LoftBatch==`function`,Ec}function jc(e){return Dc??=typeof e.ExtrudeBatch==`function`,Dc}function Mc(e,t){if(t.length===0)return[];if(Ac(e)){let n=Do(`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=>Cc(e,t.wires,t.ruled??!1,t.startVertex,t.endVertex))}function Nc(e,t){if(t.length===0)return[];if(jc(e)){let n=Do(`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=>xc(e,t.face,t.direction,t.length))}function Pc(e){return{extrude:(t,n,r)=>xc(e,t,n,r),revolve:(t,n,r)=>Sc(e,t,n,r),loft:(t,n,r,i)=>Cc(e,t,n,r,i),sweep:(t,n,r)=>wc(e,t,n,r??{}),simplePipe:(t,n)=>Tc(e,t,n),loftBatch:t=>Mc(e,t),extrudeBatch:t=>Nc(e,t)}}function Fc(e,t,n,r){let i=Do(`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 Ic(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=Do(`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 Rc(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 zc(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 Bc(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 Vc(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 Hc,Uc;function Wc(){Hc=void 0}function Gc(){Uc=void 0}function Kc(e){return Hc??=typeof e.ShellBatch==`function`,Hc}function qc(e){return Uc??=typeof e.FilletBatch==`function`,Uc}function Jc(e,t){if(t.length===0)return[];if(Kc(e)){let n=Do(`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 Yc(e,t){if(t.length===0)return[];if(qc(e)){let n=Do(`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 Fc(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 Xc(e){return{fillet:(t,n,r)=>Fc(e,t,n,r),chamfer:(t,n,r)=>Ic(e,t,n,r),chamferDistAngle:(t,n,r,i)=>zc(e,t,n,r,i),shell:(t,n,r,i)=>Lc(e,t,n,r,i),thicken:(t,n)=>Rc(e,t,n),offset:(t,n,r)=>Vc(e,t,n,r),offsetWire2D:(t,n,r)=>Bc(e,t,n,r),shellBatch:t=>Jc(e,t),filletBatch:t=>Yc(e,t)}}var Zc;function Qc(){Zc=void 0}function $c(e){return Zc??=typeof e.TransformBatch==`function`,Zc}function el(e,t){if(t.length===0)return[];let n=Do(`transform`);try{if($c(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 nl(e,t.shape,t.x,t.y,t.z);case`rotate`:return rl(e,t.shape,t.angle,[...t.axis],[...t.center]);case`scale`:return al(e,t.shape,[...t.center],t.factor);case`mirror`:return il(e,t.shape,[...t.origin],[...t.normal])}})}finally{n()}}function tl(e,t,n){let r=new e.BRepBuilderAPI_Transform_2(t,n,!0,!1),i=r.ModifiedShape(t);return r.delete(),i}function nl(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=tl(e,t,a);return a.delete(),o.delete(),s}function rl(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=tl(e,t,a);return a.delete(),c.delete(),o.delete(),s.delete(),l}function il(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=tl(e,t,i);return i.delete(),s.delete(),a.delete(),o.delete(),c}function al(e,t,n,r){let i=new e.gp_Trsf_1,a=new e.gp_Pnt_3(...n);i.SetScale(a,r);let o=tl(e,t,i);return i.delete(),a.delete(),o}function ol(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 sl(e,t){let n=new e.ShapeUpgrade_UnifySameDomain_2(t,!0,!0,!1);n.Build();let r=n.Shape();return n.delete(),r}function cl(e){return{transform:(t,n)=>tl(e,t,n),translate:(t,n,r,i)=>nl(e,t,n,r,i),rotate:(t,n,r,i)=>rl(e,t,n,r,i),mirror:(t,n,r)=>il(e,t,n,r),scale:(t,n,r)=>al(e,t,n,r),transformBatch:t=>el(e,t),generalTransform:(t,n,r,i)=>ol(e,t,n,r,i),simplify:t=>sl(e,t)}}function ll(e,t,n){if(n===0)return new Float32Array;let r=t/4;return e.slice(r,r+n)}function ul(e,t,n){let r=Do(`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=ll(e.HEAPF32,r.getVerticesPtr(),i),u=n.skipNormals||a===0?new Float32Array:ll(e.HEAPF32,r.getNormalsPtr(),a),d=r.getTrianglesPtr()/4,f=e.HEAPU32.slice(d,d+o),p=c>0?ll(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 dl(e,t,n,r){let i=Do(`edgeMesh`);try{let i=e.EdgeMeshExtractor.extract(t,n,r),a=i.getLinesSize(),o=i.getEdgeGroupsSize(),s=ll(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 fl(e){return{mesh:(t,n)=>ul(e,t,n),meshEdges:(t,n,r)=>dl(e,t,n,r)}}var pl=0;function ml(e,t){return`${e}_${++pl}.${t}`}function hl(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=ml(`_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 gl(e,t,n=!1){let r=ml(`_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 _l(e,t){let n=new e.IGESControl_Writer_1;for(let e of t)n.AddShape(e);n.ComputeModel();let r=ml(`_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 vl(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=ml(`_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 yl(e,t){let n=ml(`_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 bl(e,t){let n=ml(`_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 xl(e){return{exportSTEP:t=>hl(e,t),exportSTL:(t,n)=>gl(e,t,n),importSTEP:t=>vl(e,t),importSTL:t=>yl(e,t),exportIGES:t=>_l(e,t),importIGES:t=>bl(e,t)}}function Sl(e,t){let n=e.BRep_Tool.Pnt(t),r=[n.X(),n.Y(),n.Z()];return n.delete(),r}function Cl(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 wl=new WeakMap;function Tl(e,t){let n=wl.get(e);n||(n=Cl(e),wl.set(e,n));let r=new e.BRepAdaptor_Surface_2(t,!1),i=r.GetType();return r.delete(),n.get(i)??`other`}function El(e,t){let n=e.BRepTools.UVBounds_1(t);return{uMin:n.UMin,uMax:n.UMax,vMin:n.VMin,vMax:n.VMax}}function Dl(e,t){return e.BRepTools.OuterWire(t)}function Ol(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 kl(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 Al(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 jl(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 Ml(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 Nl(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 Pl(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 Fl(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 Il(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 Rl(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 zl(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 Bl(e,t,n){switch(n??Vl(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 Vl(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 Hl(e,t,n){return e.shapeHashCode(t,n)}function Ul(e,t){return t.IsNull()}function Wl(e,t){return t.Reversed()}function Gl(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 Kl(e,t,n,r){new e.BRepMesh_IncrementalMeshWrapper(t,n,!1,r,!1).delete()}function ql(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 Jl(e,t){return t.ShapeType()===e.TopAbs_ShapeEnum.TopAbs_WIRE?new e.BRepAdaptor_CompCurve_2(t,!1):new e.BRepAdaptor_Curve_2(t)}function Yl(e,t){let n=t.get();if(typeof n.Cylinder!=`function`)return null;let r=n.Cylinder(),i={radius:r.Radius(),isDirect:r.Direct()};return r.delete(),i}function Xl(e,t){let n=null;try{if(t===7)return e.AxeOfRevolution();if(t===1)n=e.Cylinder();else if(t===2)n=e.Cone();else if(t===4)n=e.Torus();else return null;let r=n.Axis();return n.delete(),r}catch{return n?.delete?.(),null}}function Zl(e,t){let n=new e.BRepAdaptor_Surface_2(t,!1);try{let e=n.GetType(),t=Xl(n,typeof e==`number`?e:Number(e?.value??e));if(!t)return null;let r=null,i=null;try{return r=t.Location(),i=t.Direction(),{origin:[r.X(),r.Y(),r.Z()],direction:[i.X(),i.Y(),i.Z()]}}finally{r?.delete?.(),i?.delete?.(),t.delete()}}finally{n.delete()}}function Ql(e,t){return t.get().UReversed()}function $l(e){return{vertexPosition:t=>Sl(e,t),surfaceType:t=>Tl(e,t),uvBounds:t=>El(e,t),outerWire:t=>Dl(e,t),surfaceNormal:(t,n,r)=>Ol(e,t,n,r),pointOnSurface:(t,n,r)=>kl(e,t,n,r),uvFromPoint:(t,n)=>Al(e,t,n),projectPointOnFace:(t,n)=>jl(e,t,n),curveTangent:(t,n)=>Ml(e,t,n),curveParameters:t=>Nl(e,t),shapeOrientation:t=>zl(e,t),downcast:(t,n)=>Bl(e,t,n),hashCode:(t,n)=>Hl(e,t,n),isNull:t=>Ul(e,t),hasTriangulation:t=>Gl(e,t),meshShape:(t,n,r)=>{Kl(e,t,n,r)},getBezierPenultimatePole:t=>ql(e,t),createCurveAdaptor:t=>Jl(e,t),reverseShape:t=>Wl(e,t),curvePointAtParam:(t,n)=>Pl(e,t,n),curveIsClosed:t=>Fl(e,t),curveIsPeriodic:t=>Il(e,t),curvePeriod:t=>Ll(e,t),curveType:t=>Rl(e,t),getSurfaceCylinderData:t=>Yl(e,t),getSurfaceAxis:t=>Zl(e,t),reverseSurfaceU:t=>Ql(e,t)}}function eu(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 tu(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 nu(e){return{getNurbsCurveData:t=>eu(e,t),getNurbsSurfaceData:t=>tu(e,t)}}function ru(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 iu(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 au(e){return{interpolatePoints:(t,n)=>ru(e,t,n??{}),approximatePoints:(t,n)=>iu(e,t,n??{})}}function ou(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 su(e,t){let n=new e.ShapeFix_Face_2(t);n.Perform();let r=n.Face();return n.delete(),r}function cu(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 lu(e){return{healSolid:t=>ou(e,t),healFace:t=>su(e,t),healWire:(t,n)=>cu(e,t,n)}}var uu={modified:new Map,generated:new Map,deleted:new Set};function du(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 fu(e,t){try{let n=du(e.HEAP32,t.getModifiedPtr(),t.getModifiedSize()),r=du(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 pu(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 mu(e,t,n,r,i){if(r.length===0)return uu;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 fu(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,pu(e,a,i));let l=t.Generated(r);l.Size()>0&&s.set(n,pu(e,l,i))}return{modified:o,generated:s,deleted:c}}function hu(e,t,n,r,i){let a=new e.BRepBuilderAPI_Transform_2(t,n,!0,!1),o=a.Shape(),s=r.length===0?uu:mu(e,a,t,r,i);return a.delete(),{shape:o,evolution:s}}function gu(e,t,n,r,i,a,o){return a&&t.SimplifyResult(!0,!0,.001),{shape:t.Shape(),evolution:mu(e,t,n,r,i),diagnostics:o??{hasErrors:!1,hasWarnings:!1,messages:[]}}}function _u(e,t,n,r,i){return{shape:t.Shape(),evolution:mu(e,t,n,r,i)}}function vu(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=hu(e,t,s,a,o);return s.delete(),l}function yu(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=hu(e,t,s,r,i);return s.delete(),d}function bu(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=hu(e,t,o,i,a);return o.delete(),u}function xu(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=hu(e,t,o,i,a);return o.delete(),c}function Su(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=hu(e,t,s,a,o);return s.delete(),c}function Cu(e){return{hasErrors:e.HasErrors(),hasWarnings:e.HasWarnings(),messages:[]}}function wu(e,t,n,r,i,a={}){let o=new e.Message_ProgressRange_1,s=new e.BRepAlgoAPI_Fuse_3(t,n,o);ds(e,s,a.optimisation),fs(s,a.fuzzyValue),s.Build(o);let c=Cu(s),l=gu(e,s,[t,n],r,i,a.simplify??!1,c);return s.delete(),o.delete(),l}function Tu(e,t,n,r,i,a={}){let o=new e.Message_ProgressRange_1,s=new e.BRepAlgoAPI_Cut_3(t,n,o);ds(e,s,a.optimisation),fs(s,a.fuzzyValue),s.Build(o);let c=Cu(s),l=gu(e,s,[t,n],r,i,a.simplify??!1,c);return s.delete(),o.delete(),l}function Eu(e,t,n,r,i,a={}){let o=new e.Message_ProgressRange_1,s=new e.BRepAlgoAPI_Common_3(t,n,o);ds(e,s,a.optimisation),fs(s,a.fuzzyValue),s.Build(o);let c=Cu(s),l=gu(e,s,[t,n],r,i,a.simplify??!1,c);return s.delete(),o.delete(),l}function Du(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=_u(e,o,t,i,a);return o.delete(),c}function Ou(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=_u(e,o,t,i,a);return o.delete(),u}function ku(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=_u(e,s,t,i,a);return s.delete(),u}function Au(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=_u(e,a,t,r,i);return a.delete(),s}function ju(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=_u(e,o,t,r,i);return o.delete(),c}function Mu(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(),_u(e,_,t,o,s)}finally{_.delete(),g.delete(),h.delete(),m.delete()}}function Nu(e){return{translateWithHistory:(t,n,r,i,a,o)=>vu(e,t,n,r,i,a,o),rotateWithHistory:(t,n,r,i,a,o)=>yu(e,t,n,r,i,a,o),mirrorWithHistory:(t,n,r,i,a)=>bu(e,t,n,r,i,a),scaleWithHistory:(t,n,r,i,a)=>xu(e,t,n,r,i,a),generalTransformWithHistory:(t,n,r,i,a,o)=>Su(e,t,n,r,i,a,o),fuseWithHistory:(t,n,r,i,a)=>wu(e,t,n,r,i,a),cutWithHistory:(t,n,r,i,a)=>Tu(e,t,n,r,i,a),intersectWithHistory:(t,n,r,i,a)=>Eu(e,t,n,r,i,a),filletWithHistory:(t,n,r,i,a)=>Du(e,t,n,r,i,a),chamferWithHistory:(t,n,r,i,a)=>Ou(e,t,n,r,i,a),shellWithHistory:(t,n,r,i,a,o)=>ku(e,t,n,r,i,a,o),thickenWithHistory:(t,n,r,i)=>Au(e,t,n,r,i),offsetWithHistory:(t,n,r,i,a)=>ju(e,t,n,r,i,a),draftWithHistory:(t,n,r,i,a,o,s)=>Mu(e,t,n,r,i,a,o,s)}}function Pu(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 Fu(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 Iu(e,t,n,r,i){return hu(e,t,n,r,i)}function Lu(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 Ru(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=Lu(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 zu(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 Bu(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 Vu(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 Hu(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 Uu(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 Wu(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 Gu(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 Ku(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 qu(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 Ju(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 Xu(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=Zu(e,d,f,p);a.Add(h);let g=Zu(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 Zu(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 Qu(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 $u(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 ed(e,t){let n=new e.ShapeFix_Wire_1;n.Load_1(t),n.FixSelfIntersection();let r=n.Wire();return n.delete(),r}function td(){return{gaussian:0,mean:0,max:0,min:0,maxDirection:[1,0,0],minDirection:[0,1,0]}}function nd(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 rd(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=td();if(h>=1e-15){m.Divide(h);let e=nd(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:id(o,s,e.du1,e.dv1),minDirection:id(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 id(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 ad(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 od(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 sd(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 cd(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 ld(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 ud(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=ml(`_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 dd(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=ml(`_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 fd(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=ml(`_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 pd(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)?dd(e,t):fd(e,t)}function md(e){return{composeTransform:t=>Fu(e,t),applyComposedTransformWithHistory:(t,n,r,i)=>Iu(e,t,n,r,i),sweepPipeShell:(t,n,r)=>Ru(e,t,n,r??{}),loftAdvanced:(t,n)=>zu(e,t,n??{}),buildExtrusionLaw:(t,n,r)=>Bu(e,t,n,r),revolveVec:(t,n,r,i)=>Vu(e,t,n,r,i),positionOnCurve:(t,n,r)=>Wu(e,t,n,r),linearPattern:(t,n,r,i)=>Hu(e,t,n,r,i),circularPattern:(t,n,r,i,a)=>Uu(e,t,n,r,i,a),makeNonPlanarFace:t=>Gu(e,t),addHolesInFace:(t,n)=>Ku(e,t,n),removeHolesFromFace:t=>qu(e,t),makeFaceOnSurface:(t,n)=>Ju(e,t,n),bsplineSurface:(t,n,r)=>Yu(e,t,n,r),triangulatedSurface:(t,n,r)=>Xu(e,t,n,r),sewAndSolidify:(t,n)=>Qu(e,t,n),fixShape:t=>$u(e,t),fixSelfIntersection:t=>ed(e,t),surfaceCurvature:(t,n,r)=>rd(e,t,n,r),surfaceCenterOfMass:t=>ad(e,t),createDistanceQuery:t=>od(e,t),projectEdges:(t,n,r,i)=>sd(e,t,n,r,i),draftPrism:(t,n,r,i,a,o)=>cd(e,t,n,r,i,a,o),generalTransformNonOrthogonal:(t,n,r)=>Pu(e,t,n,r),createXCAFDocument:t=>ld(e,t),writeXCAFToSTEP:(t,n)=>ud(e,t,n??{}),exportSTEPConfigured:(t,n)=>pd(e,t,n??{})}}var hd=()=>{};function gd(e){return e}function _d(e){let t=gd(e);for(;t.__bk2d===`trimmed`;)t=t.basis;return t}function vd(e){return e}function yd(e,t){return{x:e,y:t}}function bd(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 xd(e,t){return{x:e,y:t}}function Sd(e,t,n,r){return{px:e,py:t,dx:n,dy:r,delete:hd}}function Cd(e){return e}function wd(e){return e}function Td(e,t,n,r){return x(e,t,n,r)}function Ed(e,t,n,r){return S(e,t,n,r)}function Dd(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 x(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=S(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 Od(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 x(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,y=(e-p)/h,b=s*v+c*y,S;if(b>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 Dd(e,t,p+h*Math.cos(S),m+h*Math.sin(S),i,a)}function kd(e,t,n,r,i,a,o){return C(e,t,n,r,i,a,o)}function Ad(e,t,n,r,i,a,o,s,c){return{__bk2d:`trimmed`,basis:C(e,t,n,r,o,s,c),tStart:i,tEnd:a}}function jd(e){return w(e)}function Md(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 Nd(e,t){return _(gd(e),t)}function Pd(e,t){return{point:_(gd(e),t),tangent:v(gd(e),t)}}function Fd(e){return y(gd(e))}function Id(e){return b(_d(e))}function Ld(e,t,n){return{__bk2d:`trimmed`,basis:gd(e),tStart:t,tEnd:n}}function Rd(e){return JSON.parse(JSON.stringify(e))}function zd(e,t){let n=gd(e),r=y(n),i=[];for(let e=0;e<=30;e++){let a=r.first+(r.last-r.first)*e/30,[o,s]=_(n,a),[c,l]=v(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 Md(i)}function Bd(e,t,n){return ee(gd(e),t,n)}function Vd(e,t,n,r){return te(gd(e),t,n,r)}function Hd(e,t,n,r){return ne(gd(e),t,n,r)}function Ud(e,t,n){return re(gd(e),t,n)}function Wd(e,t,n,r,i){return ie(gd(e),t,n,r,i)}function Gd(e,t,n,r,i,a){return tf(e,Jd(t,n,r,i,a))}function Kd(e,t,n){return{m:e,tx:t,ty:n,delete:hd}}function qd(){return Kd([1,0,0,0,1,0,0,0,1],0,0)}function Jd(e,n,r,i,a){let o=Math.sqrt(r*r+i*i);if(o<1e-15)return qd();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 Kd(u,e-t(u,0)*e-t(u,1)*n,n-t(u,3)*e-t(u,4)*n)}function Yd(e,t){return Kd([1,0,0,0,1,0,0,0,1],e,t)}function Xd(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 Kd(u,d-t(u,0)*d-t(u,1)*f,f-t(u,3)*d-t(u,4)*f)}return Kd([-1,0,0,0,-1,0,0,0,1],2*e,2*n)}function Zd(e,t,n){let r=Math.cos(e),i=Math.sin(e);return Kd([r,-i,0,i,r,0,0,0,1],t-r*t+i*n,n-i*t-r*n)}function Qd(e,t,n){return Kd([e,0,0,0,e,0,0,0,1],t*(1-e),n*(1-e))}function $d(e,t,n){e.tx=t,e.ty=n}function ef(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 tf(e,n){let r=gd(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 ee(r,a,o);let d=y(r),f=[];for(let e=0;e<=20;e++){let[t,n]=_(r,d.first+(d.last-d.first)*e/20);f.push([s*t+c*n+a,l*t+u*n+o])}return w(f)}function nf(e,t,n){let r=ae(gd(e),gd(t),n),i=r.segments.map(e=>Object.assign(e,{delete(){}}));return{points:r.points,segments:i}}function rf(e,t,n){let r=gd(e),i=y(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]=_(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]=_(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]=_(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]=_(r,a),[s,c]=v(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]=_(r,a);return{param:a,distance:Math.sqrt((c-t)**2+(l-n)**2)}}function af(e,t,n,r,i,a){let o=gd(e),s=gd(t),c=n,l=i,u=1/0;for(let e=0;e<=50;e++){let t=n+(r-n)*e/50,[d,f]=_(o,t);for(let e=0;e<=50;e++){let n=i+(a-i)*e/50,[r,o]=_(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]=_(s,f),u=rf(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]=_(o,d),h=rf(t,p,m);if(h){let e=Math.max(i,Math.min(a,h.param)),t=Math.abs(e-f)<1e-12;if(f=e,t)break}}let[p,m]=_(o,d),[h,g]=_(s,f);return Math.sqrt((h-p)**2+(g-m)**2)}function of(e,n,r,i){let a=gd(e),o=y(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(_(a,t))}u=0;for(let e=0;e<c;e++){let[n,r]=_(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 Md(l,{degMax:s})}function sf(e){let n=_d(e);if(n.__bk2d===`bezier`)return[e];if(n.__bk2d!==`bspline`)return sf(of(e,1e-6,`C2`,10));let r=y(gd(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=_(n,r),l=_(n,i),u=v(n,r),d=v(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 cf(){return ge()}function lf(e,t,n){_e(vd(e),gd(t),n)}function uf(e){let t=vd(e);return{xMin:t.xMin,yMin:t.yMin,xMax:t.xMax,yMax:t.yMax}}function df(e,t){let n=vd(e),r=vd(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 ff(e,t){let n=vd(e),r=vd(t);return n.xMax<r.xMin||r.xMax<n.xMin||n.yMax<r.yMin||r.yMax<n.yMin}function pf(e,t,n){let r=vd(e);return t<r.xMin||t>r.xMax||n<r.yMin||n>r.yMax}function mf(e){let t=_d(e);return t.__bk2d===`circle`?{cx:t.cx,cy:t.cy,radius:t.radius,isDirect:t.sense}:null}function hf(e){let t=_d(e);return t.__bk2d===`ellipse`?{majorRadius:t.majorRadius,minorRadius:t.minorRadius,xAxisAngle:t.xDirAngle,isDirect:t.sense}:null}function gf(e){let t=_d(e);return t.__bk2d===`bezier`?[...t.poles]:null}function _f(e){let t=_d(e);return t.__bk2d===`bezier`?t.poles.length-1:null}function vf(e){let t=_d(e);return t.__bk2d===`bspline`?{poles:[...t.poles],knots:[...t.knots],multiplicities:[...t.multiplicities],degree:t.degree,isPeriodic:t.isPeriodic}:null}function yf(e){return me(gd(e))}function bf(e){return he(e)}function xf(e,t){let n=gd(e),r=y(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 Sf(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 Cf(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 wf(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 Tf(e,n,r,i,a){let o=gd(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 Sf(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=y(o),[l,u]=_(o,s.first),[d,f]=_(o,(s.first+s.last)/2),[p,m]=_(o,s.last);return Cf(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?Sf(e,t(n,0),t(n,1)):wf(e,n)}let l=y(o),u=[];for(let e=0;e<=60;e++){let[t,n]=_(o,l.first+(l.last-l.first)*e/60);u.push(c(t,n))}return wf(e,u)}function Ef(e,t,n){let r=gd(t),i=y(r),a=[];for(let e=0;e<=60;e++){let[t,o]=_(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 wf(e,a)}function Df(e,t){return e.BRep_Tool.Surface_2(t)}function Of(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(),Md(o)}function kf(e,t){e.BRepLib.BuildCurves3d_2(t)}function Af(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 jf(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=es(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 Mf(e){return{wrapCurve2dHandle:e=>Cd(e),createCurve2dAdaptor:e=>wd(e),createPoint2d:(e,t)=>yd(e,t),createDirection2d:(e,t)=>bd(e,t),createVector2d:(e,t)=>xd(e,t),createAxis2d:(e,t,n,r)=>Sd(e,t,n,r),makeLine2d:(e,t,n,r)=>Td(e,t,n,r),makeCircle2d:(e,t,n,r)=>Ed(e,t,n,r),makeArc2dThreePoints:(e,t,n,r,i,a)=>Dd(e,t,n,r,i,a),makeArc2dTangent:(e,t,n,r,i,a)=>Od(e,t,n,r,i,a),makeEllipse2d:(e,t,n,r,i,a,o)=>kd(e,t,n,r,i,a,o),makeEllipseArc2d:(e,t,n,r,i,a,o,s,c)=>Ad(e,t,n,r,i,a,o,s,c),makeBezier2d:e=>jd(e),makeBSpline2d:(e,t)=>Md(e,t),evaluateCurve2d:(e,t)=>Nd(e,t),evaluateCurve2dD1:(e,t)=>Pd(e,t),getCurve2dBounds:e=>Fd(e),getCurve2dType:e=>Id(e),trimCurve2d:(e,t,n)=>Ld(e,t,n),reverseCurve2d:e=>{},copyCurve2d:e=>Rd(e),offsetCurve2d:(e,t)=>zd(e,t),translateCurve2d:(e,t,n)=>Bd(e,t,n),rotateCurve2d:(e,t,n,r)=>Vd(e,t,n,r),scaleCurve2d:(e,t,n,r)=>Hd(e,t,n,r),mirrorCurve2dAtPoint:(e,t,n)=>Ud(e,t,n),mirrorCurve2dAcrossAxis:(e,t,n,r,i)=>Wd(e,t,n,r,i),affinityTransform2d:(e,t,n,r,i,a)=>Gd(e,t,n,r,i,a),createIdentityGTrsf2d:()=>qd(),createAffinityGTrsf2d:(e,t,n,r,i)=>Jd(e,t,n,r,i),createTranslationGTrsf2d:(e,t)=>Yd(e,t),createMirrorGTrsf2d:(e,t,n,r,i,a,o)=>Xd(e,t,n,r,i,a,o),createRotationGTrsf2d:(e,t,n)=>Zd(e,t,n),createScaleGTrsf2d:(e,t,n)=>Qd(e,t,n),setGTrsf2dTranslationPart:(e,t,n)=>{$d(e,t,n)},multiplyGTrsf2d:(e,t)=>{ef(e,t)},transformCurve2dGeneral:(e,t)=>tf(e,t),intersectCurves2d:(e,t,n)=>nf(e,t,n),projectPointOnCurve2d:(e,t,n)=>rf(e,t,n),distanceBetweenCurves2d:(e,t,n,r,i,a)=>af(e,t,n,r,i,a),approximateCurve2dAsBSpline:(e,t,n,r)=>of(e,t,n,r),decomposeBSpline2dToBeziers:e=>sf(e),createBoundingBox2d:()=>cf(),addCurveToBBox2d:(e,t,n)=>{lf(e,t,n)},getBBox2dBounds:e=>uf(e),mergeBBox2d:(e,t)=>{df(e,t)},isBBox2dOut:(e,t)=>ff(e,t),isBBox2dOutPoint:(e,t,n)=>pf(e,t,n),getCurve2dCircleData:e=>mf(e),getCurve2dEllipseData:e=>hf(e),getCurve2dBezierPoles:e=>gf(e),getCurve2dBezierDegree:e=>_f(e),getCurve2dBSplineData:e=>vf(e),serializeCurve2d:e=>yf(e),deserializeCurve2d:e=>bf(e),splitCurve2d:(e,t)=>xf(e,t),liftCurve2dToPlane:(t,n,r,i)=>Tf(e,t,n,r,i),buildEdgeOnSurface:(t,n)=>Ef(e,t,n),extractSurfaceFromFace:t=>Df(e,t),extractCurve2dFromEdge:(t,n)=>Of(e,t,n),buildCurves3d:t=>{kf(e,t)},fixWireOnFace:(t,n,r)=>Af(e,t,n,r),fillSurface:(t,n)=>jf(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 Pf(e){return{draft:(t,n,r,i,a)=>Mu(e,t,n,r,i,a,[],1).shape}}var Ff=class{oc;kernelId=`occt`;capabilities=r;constructor(e){this.oc=e,Object.assign(this,Es(e),ks(e),Js(e),Vs(e),bc(e),Pc(e),Xc(e),cl(e),fl(e),xl(e),Yo(e),ls(e),$l(e),nu(e),au(e),lu(e),Nu(e),md(e),Mf(e),Pf(e),Nf())}},If=()=>{};function Lf(e){return typeof e==`object`&&!!e&&e.__brepkit}function Rf(e,t){return{__brepkit:!0,type:e,id:t,delete:If,HashCode(e){return t%e},IsNull(){return!1}}}function I(e){return Rf(`solid`,e)}function zf(e){return Rf(`face`,e)}function Bf(e){return Rf(`edge`,e)}function Vf(e){return Rf(`wire`,e)}function Hf(e){return Rf(`shell`,e)}function Uf(e){let t=Rf(`compound`,e);return ip.has(e)?{...t,delete:()=>ip.delete(e)}:t}function Wf(e){return Rf(`vertex`,e)}function L(e,t){if(!Lf(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 Gf(e,t){if(!Lf(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 Kf(e,t,n){if(!Lf(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 qf(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 Jf(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 Xf(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 Zf(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 Qf(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 $f(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 ep(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 tp=.01,np=9e5;function rp(){return np++}var ip=new Map,ap=new Set;function op(e,t){ap.has(e)||(ap.add(e),console.warn(`brepkit: ${t}`))}function sp(e){return e.optimisation!==void 0||e.simplify!==void 0||e.strategy!==void 0||e.fuzzyValue!==void 0}function cp(e){return e}function lp(e){let t=e;for(;t.__bk2d===`trimmed`;)t=t.basis;return t}function up(e){return e}function dp(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 fp(e,t,n){let r=ip.get(t);return r?r.flatMap(t=>t.type===n?[t]:bp(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=>bp(e,t,n)):[]}function pp(e,t,n,r){switch(r){case`solid`:return[t];case`shell`:return R(e.getSolidShells(n)).map(Hf);case`face`:return R(e.getSolidFaces(n)).map(zf);case`edge`:return R(e.getSolidEdges(n)).map(Bf);case`vertex`:return R(e.getSolidVertices(n)).map(Wf);case`wire`:return R(e.getSolidFaces(n)).flatMap(t=>R(e.getFaceWires(t)).map(Vf));default:return[]}}function mp(e,t,n){let r=R(e.getShellFaces(t)).map(zf),i=new Set,a=[];for(let t of r)for(let r of bp(e,t,n)){let e=L(r);i.has(e)||(i.add(e),a.push(r))}return a}function hp(e,t,n,r){return r===`shell`?[t]:r===`face`?R(e.getShellFaces(n)).map(zf):r===`edge`||r===`vertex`?mp(e,n,r):[]}function gp(e,t,n,r){return r===`face`?[t]:r===`edge`?R(e.getFaceEdges(n)).map(Bf):r===`vertex`?R(e.getFaceVertices(n)).map(Wf):r===`wire`?R(e.getFaceWires(n)).map(Vf):[]}function _p(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(Wf(e.makeVertex(t,n,r))))}}return a}function vp(e,t,n,r){return r===`wire`?[t]:r===`edge`?R(e.getWireEdges(n)).map(Bf):r===`vertex`?_p(e,n):[]}function yp(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[Wf(i),Wf(a)]}return[]}function bp(e,t,n){let r=L(t);switch(t.type){case`compound`:return fp(e,r,n);case`solid`:return pp(e,t,r,n);case`shell`:return hp(e,t,r,n);case`face`:return gp(e,t,r,n);case`wire`:return vp(e,t,r,n);case`edge`:return yp(e,t,r,n);default:return[]}}function xp(e,t,n){if(Array.isArray(t))for(let e of t)n(e)}function Sp(e,t){if(Lf(t))return t.type;throw Error(`brepkit: cannot determine shape type of non-brepkit handle`)}function Cp(e,t,n){return Lf(t)&&Lf(n)&&t.id===n.id&&t.type===n.type}function wp(e,t,n){return Cp(e,t,n)}function Tp(e,t,n){return t}function Ep(e,t,n){return Lf(t)?t.id%n:0}function Dp(e,t){return!t||!Lf(t)}function Op(e,t){let n=L(t);return e.getShapeOrientation(n)}function kp(e,t){let n=Gf(t,`edgeToFaceMap`);return e.edgeToFaceMap(n)}function Ap(e,t,n){let r=L(t,`face`),i=L(n,`face`);return Array.from(e.sharedEdges(r,i)).map(e=>Bf(e))}function jp(e,t,n){let r=Gf(t,`adjacentFaces`),i=L(n,`face`);return Array.from(e.adjacentFaces(r,i)).map(e=>zf(e))}function Mp(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 Np(e,t,n){let r=t.flatMap(t=>Mp(e,t)),i=n??1e-7;try{return Hf(e.weldShellsAndFaces(r,i))}catch(e){console.warn(`brepkit: weldShellsAndFaces failed, falling back to sewFaces:`,e)}return Hf(e.sewFaces(r,i))}function Pp(e){return{iterShapes:(t,n)=>bp(e,t,n),iterShapeList:(t,n)=>{xp(e,t,n)},shapeType:t=>Sp(e,t),isSame:(t,n)=>Cp(e,t,n),isEqual:(t,n)=>wp(e,t,n),downcast:(t,n)=>Tp(e,t,n),hashCode:(t,n)=>Ep(e,t,n),isNull:t=>Dp(e,t),shapeOrientation:t=>Op(e,t),edgeToFaceMap:t=>kp(e,t),sharedEdges:(t,n)=>Ap(e,t,n),adjacentFaces:(t,n)=>jp(e,t,n),sew:(t,n)=>Np(e,t,n)}}function Fp(e,t){return n(e.getVertexPosition(L(t,`vertex`)))}function Ip(e,t){return e.getSurfaceType(L(t,`face`))}function Lp(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 Rp(e,t){return Vf(e.getFaceOuterWire(L(t,`face`)))}function zp(e,t,r,i){return n(e.evaluateSurfaceNormal(L(t,`face`),r,i))}function Bp(e,t,r,i){return n(e.evaluateSurface(L(t,`face`),r,i))}function Vp(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 Hp(e,t,r){return n(e.projectPointOnSurface(L(t,`face`),r[0],r[1],r[2]),2)}function Up(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 Wp(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 Gp(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 Kp(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 qp(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=>qf(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 qp(e.getEdgeVertices(L(r,`edge`)))}function qp(e){return qf(t(e,0),t(e,1),t(e,2),t(e,3),t(e,4),t(e,5))<1e-7}function Jp(e,t){let n=t;try{if(n.type===`edge`||n.type===`wire`&&R(e.getWireEdges(n.id)).length===1)return Kp(e,t)}catch{}return!1}function Yp(e,t){try{if(Jp(e,t)){let n=Wp(e,t);return n[1]-n[0]}}catch{}return 0}function Xp(e,t){if(t.type===`wire`){let n=bp(e,t,`edge`)[0];return n?e.getEdgeCurveType(L(n,`edge`)):`LINE`}return e.getEdgeCurveType(L(t,`edge`))}function Zp(e,t,n){let r=L(t,`edge`);return Bf(e.curveDegreeElevate(r,n))}function Qp(e,t,n,r){let i=L(t,`edge`);return Bf(e.curveKnotInsert(i,n,r))}function $p(e,t,n,r){let i=L(t,`edge`);return Bf(e.curveKnotRemove(i,n,r))}function em(e,n,r){let i=L(n,`edge`),a=e.curveSplit(i,r);return[Bf(t(a,0)),Bf(t(a,1))]}function tm(e,t,n,r,i,a,o,s,c,l){return zf(e.approximateSurfaceLspia(t,n,r,i,a,o,s,c,l))}function nm(e,t,n,r){let i=L(t,`face`);return zf(e.untrimFace(i,n,r))}function rm(e,t){return t}function im(e,t){let r=Pm(e,t);return!r||r.controlPoints.length<6?null:n(r.controlPoints,r.controlPoints.length-6)}function am(e,t){if(Lf(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 om(e,t){let n=JSON.parse(e.getAnalyticSurfaceParams(L(t,`face`))),r=n.type===`cylinder`?n.origin:n.type===`cone`?n.apex:null;if(!r||!n.axis)return null;let[i,a,o]=r,[s,c,l]=n.axis,u=Math.hypot(s,c,l);return u<1e-12?null:{origin:[i,a,o],direction:[s/u,c/u,l/u]}}function sm(e,t){return t}function cm(e,n,r,i,a){a!==void 0&&op(`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 lm(e,t,n,r){let i=Gf(t,`classifyPointRobust`);return e.classifyPointRobust(i,n[0],n[1],n[2],r)}function um(e,t,n,r){let i=Gf(t,`classifyPointWinding`);return e.classifyPointWinding(i,n[0],n[1],n[2],r)}function dm(e,t,n,r){let i=Gf(t,`detectSmallFeatures`);return Array.from(e.detectSmallFeatures(i,n,r)).map(e=>zf(e))}function fm(e,t,n){let r=Gf(t,`recognizeFeatures`);return e.recognizeFeatures(r,n)}function pm(e,t,r,i,a){let o=L(t),[s,c,l]=r,[u,d,f]=i,[p,m,h]=a??[1,0,0],g=.1;try{let t=e.boundingBox(o),[r,i,a]=n(t,0),[s,c,l]=n(t,3),u=qf(r,i,a,s,c,l);u>0&&(g=Math.max(u*.001,1e-6))}catch{}let _=e.projectEdges(o,s,c,l,u,d,f,p,m,h,!0,g),v;try{v=JSON.parse(_)}catch{v={visible:[],hidden:[]}}let y=t=>{let n=[];for(let r of t)for(let t=0;t+3<r.length;t+=2){let i=r[t],a=r[t+1],o=r[t+2],s=r[t+3];i===void 0||a===void 0||o===void 0||s===void 0||i===o&&a===s||n.push(Bf(e.makeLineEdge(i,a,0,o,s,0)))}let r=rp();return ip.set(r,n),Uf(r)},b=()=>{let e=rp();return ip.set(e,[]),Uf(e)};return{visible:{outline:y(v.visible),smooth:b(),sharp:b()},hidden:{outline:y(v.hidden),smooth:b(),sharp:b()}}}function mm(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 hm(e,t){return JSON.parse(e.getNurbsSurfaceDataParity(L(t,`face`)))}function gm(e){return{vertexPosition:t=>Fp(e,t),surfaceType:t=>Ip(e,t),uvBounds:t=>Lp(e,t),outerWire:t=>Rp(e,t),surfaceNormal:(t,n,r)=>zp(e,t,n,r),pointOnSurface:(t,n,r)=>Bp(e,t,n,r),uvFromPoint:(t,n)=>Vp(e,t,n),projectPointOnFace:(t,n)=>Hp(e,t,n),curveTangent:(t,n)=>Up(e,t,n),curveParameters:t=>Wp(e,t),curvePointAtParam:(t,n)=>Gp(e,t,n),curveIsClosed:t=>Kp(e,t),curveIsPeriodic:t=>Jp(e,t),curvePeriod:t=>Yp(e,t),curveType:t=>Xp(e,t),curveDegreeElevate:(t,n)=>Zp(e,t,n),curveKnotInsert:(t,n,r)=>Qp(e,t,n,r),curveKnotRemove:(t,n,r)=>$p(e,t,n,r),curveSplit:(t,n)=>em(e,t,n),approximateSurfaceLspia:(t,n,r,i,a,o,s,c,l)=>tm(e,t,n,r,i,a,o,s,c,l),untrimFace:(t,n,r)=>nm(e,t,n,r),createCurveAdaptor:t=>rm(e,t),getBezierPenultimatePole:t=>im(e,t),getSurfaceCylinderData:t=>am(e,t),getSurfaceAxis:t=>om(e,t),reverseSurfaceU:t=>sm(e,t),classifyPointOnFace:(t,n,r,i)=>cm(e,t,n,r,i),classifyPointRobust:(t,n,r)=>lm(e,t,n,r),classifyPointWinding:(t,n,r)=>um(e,t,n,r),detectSmallFeatures:(t,n,r)=>dm(e,t,n,r),recognizeFeatures:(t,n)=>fm(e,t,n),projectEdges:(t,n,r,i)=>pm(e,t,n,r,i),getNurbsCurveData:t=>mm(e,t),getNurbsSurfaceData:t=>hm(e,t)}}function _m(e,t,n){if(Array.isArray(n)&&n.length===16)return Am(e,t,n);throw Error(`brepkit: transform expects a 16-element matrix array`)}function vm(e,t,n,r,i){return Am(e,t,Yf(n,r,i))}function ym(e,t,n,r,i){return Am(e,t,Xf(n,r,i))}function bm(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])):Am(e,t,$f(n,r))}function xm(e,t,n,r){return Am(e,t,Zf(n,r))}function Sm(e,t,n,r,i){return Am(e,t,Qf(n,r))}function Cm(e,t,n,r){return Am(e,t,Qf(n,r))}function wm(e,t,n,r){let{point:i,tangent:a}=Up(e,n,r),[o,s,c]=a,l=Math.sqrt(o*o+s*s+c*c);if(l<1e-12)return vm(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=ym(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=ym(e,p,n,t)}return vm(e,p,i[0],i[1],i[2])}function Tm(e,t,n,r,i){let a=[t];for(let o=1;o<i;o++){let i=r*o;a.push(vm(e,t,n[0]*i,n[1]*i,n[2]*i))}return a}function Em(e,t,n,r,i,a){let o=[t];for(let s=1;s<a;s++)o.push(ym(e,t,i*s,r,n));return o}function Dm(e,t,n,r,i,a,o,s){return Uf(e.gridPattern(Gf(t,`gridPattern`),n[0],n[1],n[2],r[0],r[1],r[2],i,a,o,s))}function Om(e,t){return t.map(t=>{switch(t.type){case`translate`:return vm(e,t.shape,t.x,t.y,t.z);case`rotate`:return ym(e,t.shape,t.angle,t.axis,t.center);case`scale`:return xm(e,t.shape,t.center,t.factor);case`mirror`:return bm(e,t.shape,t.origin,t.normal)}})}function km(e){return{transform:(t,n)=>_m(e,t,n),translate:(t,n,r,i)=>vm(e,t,n,r,i),rotate:(t,n,r,i)=>ym(e,t,n,r,i),mirror:(t,n,r)=>bm(e,t,n,r),scale:(t,n,r)=>xm(e,t,n,r),generalTransform:(t,n,r,i)=>Sm(e,t,n,r,i),generalTransformNonOrthogonal:(t,n,r)=>Cm(e,t,n,r),positionOnCurve:(t,n,r)=>wm(e,t,n,r),linearPattern:(t,n,r,i)=>Tm(e,t,n,r,i),circularPattern:(t,n,r,i,a)=>Em(e,t,n,r,i,a),gridPattern:(t,n,r,i,a,o,s)=>Dm(e,t,n,r,i,a,o,s),transformBatch:t=>Om(e,t)}}function Am(e,t,n){let r=t;if(!Lf(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),zf(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),Vf(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),Bf(t)}default:throw Error(`brepkit: applyMatrix does not support '${r.type}' shapes`)}}function jm(e,t){return!!(e&&(e[0]!==0||e[1]!==0||e[2]!==0)||t&&(t[0]!==0||t[1]!==0||t[2]!==1))}function Mm(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=ym(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=ym(e,i,n,t)}}return n&&(n[0]!==0||n[1]!==0||n[2]!==0)&&(i=vm(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=bp(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,tp);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 Pm(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 Fm(e,t){if(!Lf(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 Im(e,t){if(!Lf(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 Lm(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 Rm(e,t){return t}function zm(e,t,n){return t}function Bm(e,t,n){let r=Gf(t,`mergeCoincidentVertices`);return e.mergeCoincidentVertices(r,n)}function Vm(e,t,n){let r=Gf(t,`removeDegenerateEdges`);return e.removeDegenerateEdges(r,n)}function Hm(e,t){let n=Gf(t,`fixFaceOrientations`);return e.fixFaceOrientations(n)}function Um(e,t){let n=t;return n.type===`solid`&&e.healSolid(n.id),t}function Wm(e,t){return t}function Gm(e,t){if(!Lf(t)||t.type!==`solid`)return null;try{return typeof e.validateSolidDetails==`function`?e.validateSolidDetails(t.id):null}catch{return null}}function Km(e){return{isValid:t=>Fm(e,t),isValidStrict:t=>Im(e,t),healSolid:t=>Lm(e,t),healFace:t=>Rm(e,t),healWire:(t,n)=>zm(e,t,n),fixShape:t=>Um(e,t),fixSelfIntersection:t=>Wm(e,t),mergeCoincidentVertices:(t,n)=>Bm(e,t,n),removeDegenerateEdges:(t,n)=>Vm(e,t,n),fixFaceOrientations:t=>Hm(e,t),validationDetails:t=>Gm(e,t)}}function qm(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 Jm(e,t){return t.type===`compound`?R(e.getCompoundSolids(t.id)).length===0:!1}function Ym(e){return Uf(e.makeCompound([]))}function Xm(e,t,n,r){if(r&&sp(r)&&op(`boolean-options`,`BooleanOptions (optimisation, simplify, strategy, fuzzyValue) not supported; ignored.`),Jm(e,t))return n;if(Jm(e,n))return t;let i=Gf(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,Gf(n,`fuse`)))}function Zm(e,t,n,r){if(r&&sp(r)&&op(`boolean-options`,`BooleanOptions (optimisation, simplify, strategy, fuzzyValue) not supported; ignored.`),Jm(e,t))return Ym(e);if(Jm(e,n))return t;let i=Gf(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(qm(t))return Ym(e);throw t}return I(n)}try{return I(e.cut(i,Gf(n,`cut`)))}catch(t){if(qm(t))return Ym(e);throw t}}function Qm(e,t,n,r){if(r&&sp(r)&&op(`boolean-options`,`BooleanOptions (optimisation, simplify, strategy, fuzzyValue) not supported; ignored.`),Jm(e,t)||Jm(e,n))return Ym(e);try{return I(e.intersect(Gf(t,`intersect`),Gf(n,`intersect`)))}catch(t){if(qm(t))return Ym(e);throw t}}function $m(e,n,r,i){let{point:a,normal:o}=Nm(e,r),s=Lf(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 Uf(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(Vf(t(r,e)))}let[u]=l;if(l.length===1&&u!==void 0)return u;let d=rp();return ip.set(d,l),Uf(d)}function eh(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(Gf(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(Xm(e,i[n],i[n+1],r)):t.push(i[n]);i=t}return t(i,0)}function th(e,t,n,r){if(n.length===0)return t;if(n.length===1)return Zm(e,t,n[0],r);let i=Gf(t,`cutAll`),a=[];for(let t of n){let n=t;n.type===`compound`?a.push(...R(e.getCompoundSolids(n.id))):a.push(Gf(t,`cutAll`))}return a.length===0?t:I(e.compoundCut(i,new Uint32Array(a)))}function nh(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 Uf(e.makeCompound(a))}function rh(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 ih(e,t,n,r,i){let a=[];return(!Lf(t)||t.IsNull())&&a.push({operand:`base`,issue:`null-shape`,message:`Base shape is null`}),(!Lf(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 ah(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 oh(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 sh(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 ch(e){return{fuse:(t,n,r)=>Xm(e,t,n,r),cut:(t,n,r)=>Zm(e,t,n,r),intersect:(t,n,r)=>Qm(e,t,n,r),section:(t,n,r)=>$m(e,t,n,r),fuseAll:(t,n)=>eh(e,t,n),cutAll:(t,n,r)=>th(e,t,n,r),split:(t,n)=>nh(e,t,n),meshBoolean:(t,n,r,i,a,o)=>rh(e,t,n,r,i,a,o),checkBoolean:(t,n,r)=>ih(e,t,n,r,t=>Fm(e,t)),hull:(t,n)=>ah(e,t,n),hullFromPoints:(t,n)=>oh(e,t,n),buildSolidFromFaces:(t,n,r)=>sh(e,t,n,r)}}function lh(e,t,n,r){return Wf(e.makeVertex(t,n,r))}function uh(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 bh(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(Lf(t)&&t.type===`edge`)return t;throw Error(`brepkit: makeEdge requires a curve with origin/direction, or an edge handle`)}function dh(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 Vf(e.makeWire(n,!0))}function fh(e,t,n){let r=t,i=r.type===`edge`?e.makeWire([r.id],!0):L(t,`wire`);return zf(n?e.makePlanarFaceFromWire(i):e.makeFaceFromWire(i))}function ph(e,t,n,r){return I(e.makeBox(t,n,r))}function mh(e,t,n){return zf(e.makeRectangle(t,n))}function hh(e,t,n,r,i){let a=I(e.makeCylinder(t,n));return jm(r,i)?Mm(e,a,r,i):a}function gh(e,t,n){let r=I(e.makeSphere(t,32));return n&&(n[0]!==0||n[1]!==0||n[2]!==0)?vm(e,r,n[0],n[1],n[2]):r}function _h(e,t,n,r,i,a){let o=I(e.makeCone(t,n,r));return jm(i,a)?Mm(e,o,i,a):o}function vh(e,t,n,r,i){let a=I(e.makeTorus(t,n,32));return jm(r,i)?Mm(e,a,r,i):a}function yh(e,t,n,r){let i=Math.max(t,n,r);return Sm(e,gh(e,i),[t/i,0,0,0,n/i,0,0,0,r/i],[0,0,0],!1)}function bh(e,t,n){return Bf(e.makeLineEdge(t[0],t[1],t[2],n[0],n[1],n[2]))}function xh(e,t,n,r){let i=Math.sqrt(n[0]**2+n[1]**2+n[2]**2);return Bf(e.makeCircleEdge(t[0],t[1],t[2],n[0]/i,n[1]/i,n[2]/i,r))}function Sh(e,t,n,r,i,a){let o=a-i,s=1e-9;if(o>s&&o<2*Math.PI-s){let o=Math.hypot(n[0],n[1],n[2]),s=[n[0]/o,n[1]/o,n[2]/o],c=Math.abs(s[0])<.9?[1,0,0]:[0,1,0],l=[s[1]*c[2]-s[2]*c[1],s[2]*c[0]-s[0]*c[2],s[0]*c[1]-s[1]*c[0]],u=Math.hypot(l[0],l[1],l[2]),d=[l[0]/u,l[1]/u,l[2]/u],f=[s[1]*d[2]-s[2]*d[1],s[2]*d[0]-s[0]*d[2],s[0]*d[1]-s[1]*d[0]],p=e=>{let n=Math.cos(e),i=Math.sin(e);return[t[0]+r*(n*d[0]+i*f[0]),t[1]+r*(n*d[1]+i*f[1]),t[2]+r*(n*d[2]+i*f[2])]},m=p(i),h=p(a);return Bf(e.makeCircleArc3d(m[0],m[1],m[2],h[0],h[1],h[2],t[0],t[1],t[2],s[0],s[1],s[2]))}return Xh(e,t,n,r,i,a)}function Ch(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 wh(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 bh(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=Ch(p,m,h,g,_,v);if(!y)return bh(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 Bf(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 Th(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 Bf(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 Bf(e.makeEllipseEdge(t[0],t[1],t[2],n[0]/o,n[1]/o,n[2]/o,r,i))}function Eh(e,t,n,r,i,a,o,s){return Zh(e,t,n,r,i,a,o,s)}function Dh(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 Bf(e.makeNurbsEdge(c[0],c[1],c[2],l[0],l[1],l[2],r,a,s,o))}function Oh(e,t,n,r){return Bf(e.makeTangentArc3d(t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]))}function kh(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 dh(e,[Hh(e,p)])}function Ah(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 Vf(e.makeWire(n,!1))}function jh(e,t){let n=t.filter(Lf);if(n.length===0)throw Error(`brepkit: makeCompound requires at least one shape`);if(n.every(e=>e.type===`solid`))return Uf(e.makeCompound(n.map(e=>e.id)));let r=rp();return ip.set(r,n),Uf(r)}function Mh(e,t,n){let r=ph(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?vm(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 Ph(e,t){return fh(e,t,!1)}function Fh(e,t,n){let r=n.map(e=>L(e,`wire`));return zf(e.addHolesToFace(L(t,`face`),r))}function Ih(e,t){return zf(e.removeHolesFromFace(L(t,`face`)))}function Lh(e,t,n){return fh(e,n,!1)}function Rh(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 zf(e.interpolateSurface(i,n,r,a,o))}catch{return zh(e,t,n,r)}}function zh(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=Bh(e,t(n,s),t(n,c),t(n,l));d&&a.push(d);let f=Bh(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 Np(e,a,1e-6)}function Bh(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 fh(e,dh(e,[bh(e,t,n),bh(e,n,r),bh(e,r,t)]))}catch(e){return console.warn(`brepkit: makeNonPlanarFace failed:`,e),null}}function Vh(e,t,n){let r=t.map(e=>L(e,`face`));return I(e.sewFaces(r,n))}function Hh(e,n,r){if(r?.tolerance!==void 0&&op(`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 bh(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 Bf(e.interpolatePoints(a,i))}function Uh(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 Bf(e.approximateCurveLspia(a,r,o,i,100))}function Wh(e,t,n,r){return{x:t,y:n,z:r}}function Gh(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 Kh(e,t,n,r){return{x:t,y:n,z:r}}function qh(e,t,n,r,i,a,o){return{origin:[t,n,r],direction:[i,a,o]}}function Jh(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,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 Xh(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 Bf(e.makeNurbsEdge(b,x,S,C,w,ee,2,v,g,_))}function Zh(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 Bf(e.makeNurbsEdge(y,b,x,S,C,w,2,_,h,g))}function Qh(e){return{makeVertex:(t,n,r)=>lh(e,t,n,r),makeEdge:(t,n,r)=>uh(e,t,n,r),makeWire:t=>dh(e,t),makeWireFromMixed:t=>Ah(e,t),makeFace:(t,n)=>fh(e,t,n),makeBox:(t,n,r)=>ph(e,t,n,r),makeRectangle:(t,n)=>mh(e,t,n),makeCylinder:(t,n,r,i)=>hh(e,t,n,r,i),makeSphere:(t,n)=>gh(e,t,n),makeCone:(t,n,r,i,a)=>_h(e,t,n,r,i,a),makeTorus:(t,n,r,i)=>vh(e,t,n,r,i),makeEllipsoid:(t,n,r)=>yh(e,t,n,r),makeLineEdge:(t,n)=>bh(e,t,n),makeCircleEdge:(t,n,r)=>xh(e,t,n,r),makeCircleArc:(t,n,r,i,a)=>Sh(e,t,n,r,i,a),makeArcEdge:(t,n,r)=>wh(e,t,n,r),makeEllipseEdge:(t,n,r,i,a)=>Th(e,t,n,r,i,a),makeEllipseArc:(t,n,r,i,a,o,s)=>Eh(e,t,n,r,i,a,o,s),makeBezierEdge:t=>Dh(e,t),makeTangentArc:(t,n,r)=>Oh(e,t,n,r),makeHelixWire:(t,n,r,i,a,o)=>kh(e,t,n,r,i,a,o),makeCompound:t=>jh(e,t),makeBoxFromCorners:(t,n)=>Mh(e,t,n),solidFromShell:t=>Nh(e,t),makeNonPlanarFace:t=>Ph(e,t),addHolesInFace:(t,n)=>Fh(e,t,n),removeHolesFromFace:t=>Ih(e,t),makeFaceOnSurface:(t,n)=>Lh(e,t,n),bsplineSurface:(t,n,r)=>Rh(e,t,n,r),triangulatedSurface:(t,n,r)=>zh(e,t,n,r),buildTriFace:(t,n,r)=>Bh(e,t,n,r),sewAndSolidify:(t,n)=>Vh(e,t,n),interpolatePoints:(t,n)=>Hh(e,t,n),approximatePoints:(t,n)=>Uh(e,t,n),createPoint3d:(t,n,r)=>Wh(e,t,n,r),createDirection3d:(t,n,r)=>Gh(e,t,n,r),createVector3d:(t,n,r)=>Kh(e,t,n,r),createAxis1:(t,n,r,i,a,o)=>qh(e,t,n,r,i,a,o),createAxis2:(t,n,r,i,a,o,s,c,l)=>Jh(e,t,n,r,i,a,o,s,c,l),createAxis3:(t,n,r,i,a,o,s,c,l)=>Yh(e,t,n,r,i,a,o,s,c,l)}}function $h(e,t,n,r){let i=Gf(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 eg(e,t,n,r){let i=Gf(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)):(op(`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):(op(`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 tg(e,t,n,r,i){let a=r*Math.tan(i*Math.PI/180),o=Gf(t,`chamferDistAngle`),s=n.map(e=>L(e,`edge`));return typeof e.chamferAsymmetric==`function`?I(e.chamferAsymmetric(o,s,r,a)):(op(`chamfer-dist-angle`,`chamferAsymmetric not available; using averaged distance.`),I(e.chamfer(o,s,(r+a)/2)))}function ng(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 rg(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 ig(e,t,n){try{let r=ng(e,t);if(r===null)return null;let i=-1,a=1/0;for(let t of n)try{let n=ng(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 ag(e,t,n,r){if(r.has(t))return t;let i=rg(e,t,n);if(i!==null)return i;let a=ig(e,t,n);return a===null?t:a}function og(e,t,n,r,i){i!==void 0&&op(`shell-tolerance`,`shell() tolerance parameter is not supported; brepkit uses its own internal tolerance.`);let a=Gf(t,`shell`),o=R(e.getSolidFaces(a)),s=new Set(o),c=n.map(t=>ag(e,L(t,`face`),o,s));return I(e.shell(a,r,c))}function sg(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 cg(e,t,n,r){r!==void 0&&op(`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=Gf(t,`offset`);return I(e.offsetSolidV2(a,n))}function lg(e,t,n){let r=Gf(t,`filletVariable`);return I(e.filletVariable(r,n))}function ug(e,t,n,r,i,a){let o=Gf(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 dg(e,t,n){let r=Gf(t,`defeature`),i=n.map(e=>L(e,`face`));return I(e.defeature(r,i))}function fg(e){switch(e){case`arc`:case`tangent`:return`arc`;case`intersection`:return`intersection`;default:return`intersection`}}function pg(e,n,r,i){if(typeof e.offsetWire2DWithJoin==`function`)return Vf(e.offsetWire2DWithJoin(L(n,`wire`),r,fg(i)));let a=bp(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 Vf(e.makePolygonWire(c))}function mg(e,t){if(t.type===`solid`)try{e.healSolid(L(t))}catch(e){console.warn(`brepkit: healing failed in simplify:`,e)}return t}function hg(e,t){let n=t,r=e.reverseShape(n.id);return Rf(n.type,r)}function gg(e){return{fillet:(t,n,r)=>$h(e,t,n,r),chamfer:(t,n,r)=>eg(e,t,n,r),chamferDistAngle:(t,n,r,i)=>tg(e,t,n,r,i),shell:(t,n,r,i)=>og(e,t,n,r,i),thicken:(t,n)=>sg(e,t,n),offset:(t,n,r)=>cg(e,t,n,r),filletVariable:(t,n)=>lg(e,t,n),draft:(t,n,r,i,a)=>ug(e,t,n,r,i,dp(n,a)),defeature:(t,n)=>dg(e,t,n),offsetWire2D:(t,n,r)=>pg(e,t,n,r),simplify:t=>mg(e,t),reverseShape:t=>hg(e,t)}}function _g(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 vg(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 yg(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 bg(e,t,n){try{return{hash:n,normal:e.getFaceNormal(t),centroid:yg(e,t)}}catch{return{hash:n,normal:[0,0,0],centroid:yg(e,t)}}}var xg=.707,Sg=100,Cg=.05;function wg(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<xg)continue;let c=vg(e.centroid,o.centroid);if(c>Sg)continue;let l=s-c/Sg;l>r&&(r=l),i.push({idx:a,score:l})}return{matches:i,bestScore:r}}function Tg(e,t){let n=1/0,r;for(let i of t){let t=vg(e.centroid,i.centroid);t<n&&(n=t,r=i)}return r}function Eg(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(bg(e,i,r[n]??i%a))}let p=i.map(t=>bg(e,t,t%a)),m=new Set;for(let e of p){let{matches:n,bestScore:r}=wg(e,f);if(n.length>0){for(let i of n)if(i.score>=r-Cg){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=Tg(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 Dg(e,t,n,r,i,a,o,s){let c=new Set(s),l=new Map(a);Eg(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 Og(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 kg(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?Dg(e,l,d,f,a,o,s,c):Og(i,r,u,t,s,c)}else if(l)Eg(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 Ag(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 kg(e,n,d,r,i,c,l,u,o)}return{shape:n,evolution:{modified:c,generated:l,deleted:u}}}function jg(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 Mg(e,t){let n=new Set;jg(t.combinedModified,e.evolution.modified,e.evolution.deleted,n,t.combinedDeleted),jg(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=_g(a(t.id,e),i);s=n.shape,Mg(n,c)}return{shape:s,accum:c}}function Pg(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{..._g(o(u.id,d.id),i),diagnostics:l}}catch(e){if(!qm(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{...Ag(e,s(t,n,a),r,i,!1,t),diagnostics:l}}function Fg(e,t,n,r,i,a,o){return Ag(e,vm(e,t,n,r,i),a,o,!0)}function Ig(e,t,n,r,i,a,o){return Ag(e,ym(e,t,n*180/Math.PI,a,o),r,i,!0)}function Lg(e,t,n,r,i,a){return Ag(e,bm(e,t,n,r),i,a,!0)}function Rg(e,t,n,r,i,a){return Ag(e,xm(e,t,n,r),i,a,!0)}function zg(e,t,n,r,i,a,o){return Ag(e,Sm(e,t,n,r,i),a,o,!0)}function Bg(e,t,n,r,i,a){return Pg(e,t,n,r,i,a,(t,n)=>e.fuseWithEvolution(t,n),(t,n,r)=>Xm(e,t,n,r),`fuseWithHistory`)}function Vg(e,t,n,r,i,a){return Pg(e,t,n,r,i,a,(t,n)=>e.cutWithEvolution(t,n),(t,n,r)=>Zm(e,t,n,r),`cutWithHistory`)}function Hg(e,t,n,r,i,a){return Pg(e,t,n,r,i,a,(t,n)=>e.intersectWithEvolution(t,n),(t,n,r)=>Qm(e,t,n,r),`intersectWithHistory`)}function Ug(e,t,n,r,i,a){return Ag(e,$h(e,t,n,r),i,a,!1,t)}function Wg(e,t,n,r,i,a){return Ag(e,eg(e,t,n,r),i,a,!1,t)}function Gg(e,t,n,r,i,a,o){return Ag(e,og(e,t,n,r,o),i,a,!1,t)}function Kg(e,t,n,r,i){return Ag(e,sg(e,t,n),r,i,!1,t)}function qg(e,t,n,r,i,a){return Ag(e,cg(e,t,n,a),r,i,!1,t)}function Jg(e,t,n,r,i,a,o,s){return Ag(e,ug(e,t,n,r,i,a),o,s,!1,t)}function Yg(e,t,n,r,i){return Ag(e,Am(e,t,n),r,i,!0)}function Xg(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=ep(e.type===`translate`?Yf(e.x,e.y,e.z):Xf(e.angle,e.axis,e.center),n);return{handle:n,dispose:()=>{}}}function Zg(e){return{translateWithHistory:(t,n,r,i,a,o)=>Fg(e,t,n,r,i,a,o),rotateWithHistory:(t,n,r,i,a,o)=>Ig(e,t,n,r,i,a,o),mirrorWithHistory:(t,n,r,i,a)=>Lg(e,t,n,r,i,a),scaleWithHistory:(t,n,r,i,a)=>Rg(e,t,n,r,i,a),generalTransformWithHistory:(t,n,r,i,a,o)=>zg(e,t,n,r,i,a,o),fuseWithHistory:(t,n,r,i,a)=>Bg(e,t,n,r,i,a),cutWithHistory:(t,n,r,i,a)=>Vg(e,t,n,r,i,a),intersectWithHistory:(t,n,r,i,a)=>Hg(e,t,n,r,i,a),filletWithHistory:(t,n,r,i,a)=>Ug(e,t,n,r,i,a),chamferWithHistory:(t,n,r,i,a)=>Wg(e,t,n,r,i,a),shellWithHistory:(t,n,r,i,a,o)=>Gg(e,t,n,r,i,a,o),thickenWithHistory:(t,n,r,i)=>Kg(e,t,n,r,i),offsetWithHistory:(t,n,r,i,a)=>qg(e,t,n,r,i,a),draftWithHistory:(t,n,r,i,a,o,s)=>Jg(e,t,n,r,i,dp(n,a),o,s),applyComposedTransformWithHistory:(t,n,r,i)=>Yg(e,t,n,r,i),composeTransform:t=>Xg(e,t)}}function Qg(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=t_(e,r,a,!!n.includeUVs,o);else if(i.type===`face`)s=o_(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 $g(e,n,r,i){i>0&&op(`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 e_(e,t){return!1}function t_(e,t,n,r,i){try{return n_(e,t,n,r,i)}catch(r){return console.warn(`brepkit: tessellateSolidGrouped failed (solidId=${t}), falling back to per-face:`,r),a_(e,t,n,i)}}function n_(e,t,n,r,i){return typeof e.tessellateSolidGroupedBinary==`function`?r_(e,t,n,r,i,e.tessellateSolidGroupedBinary(t,n,i)):i_(e,t,n,r,i)}function r_(e,n,r,i,a,o){let s=o.positions,c=o.normals,l=o.indices,u=o.faceOffsets,d=R(e.getSolidFaces(n)),f=u.length-1;if(f!==d.length)throw Error(`faceOffsets/faceIds length mismatch: ${f} groups vs ${d.length} faces`);let p=[];for(let e=0;e<u.length-1;e++){let n=t(u,e),r=t(u,e+1)-n;r!==0&&p.push({start:n,count:r,faceHash:d[e]??0})}let m=new Float32Array;if(i){let t=s.length/3*2;try{let i=e.tessellateSolidUV(n,r,a),o=JSON.parse(i);m=o.uvs.length===t?new Float32Array(o.uvs):new Float32Array(t)}catch{m=new Float32Array(t)}}return{vertices:s,normals:c,triangles:l,uvs:m,faceGroups:p}}function i_(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 a_(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 o_(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 s_(e){return{mesh:(t,n)=>Qg(e,t,n),meshEdges:(t,n,r)=>$g(e,t,n,r),hasTriangulation:t=>e_(e,t),meshShape:(e,t,n)=>{}}}function c_(e,t){if(t.length===0)return``;let n=[];for(let r of t){let t=Kf(e,r,`exportSTEP`);for(let r of t){let t=e.exportStep(r);n.push(new TextDecoder().decode(t))}}return n.join(`
|
|
8
|
-
`)}function
|
|
9
|
-
`)}function p_(e,t){let n=typeof t==`string`?new TextEncoder().encode(t):new Uint8Array(t);return R(e.importIges(n)).map(I)}function m_(e,t,n){return t.length===0?``:c_(e,t.map(e=>e.shape))}function h_(e,t,n){let r=Gf(t,`export3MF`);return Jf(e.export3mf(r,n))}function g_(e,t,n){let r=Gf(t,`exportGLB`);return Jf(e.exportGlb(r,n))}function __(e,t,n){let r=Gf(t,`exportOBJ`);return Jf(e.exportObj(r,n))}function v_(e,t,n){let r=Gf(t,`exportPLY`);return Jf(e.exportPly(r,n))}function y_(e,t){return R(e.import3mf(new Uint8Array(t))).map(e=>I(e))}function b_(e,t){return I(e.importObj(new Uint8Array(t)))}function x_(e,t){return I(e.importGlb(new Uint8Array(t)))}function S_(e,t){let n=t;return n.type===`solid`?e.toBREP(n.id):(op(`brep-non-solid`,`toBREP for non-solid shapes uses STEP format.`),c_(e,[t]))}function C_(e,t){if(typeof e.fromBREP==`function`&&t.trimStart().startsWith(`{`))return I(e.fromBREP(t));let n=u_(e,t)[0];if(!n)throw Error(`brepkit: fromBREP produced no shapes`);return n}function w_(e,t){return{__brepkit_xcaf:!0,shapes:t,delete:If}}function T_(e,t,n){return t&&t.__brepkit_xcaf&&Array.isArray(t.shapes)?c_(e,t.shapes.map(e=>e.shape)):``}function E_(e,t,n){return c_(e,t.map(e=>e.shape))}function D_(e){return{exportSTEP:t=>c_(e,t),exportSTL:(t,n,r,i)=>l_(e,t,n,r,i),importSTEP:t=>u_(e,t),importSTL:t=>d_(e,t),exportIGES:t=>f_(e,t),importIGES:t=>p_(e,t),exportSTEPAssembly:(t,n)=>m_(e,t,n),export3MF:(t,n)=>h_(e,t,n),exportGLB:(t,n)=>g_(e,t,n),exportOBJ:(t,n)=>__(e,t,n),exportPLY:(t,n)=>v_(e,t,n),import3MF:t=>y_(e,t),importOBJ:t=>b_(e,t),importGLB:t=>x_(e,t),toBREP:t=>S_(e,t),fromBREP:t=>C_(e,t),createXCAFDocument:t=>w_(e,t),writeXCAFToSTEP:(t,n)=>T_(e,t,n),exportSTEPConfigured:(t,n)=>E_(e,t,n)}}function O_(e,t){return{x:e,y:t}}function k_(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 A_(e,t){return{x:e,y:t}}function j_(e,t,n,r){return{px:e,py:t,dx:n,dy:r,delete:If}}function M_(e){return e}function N_(e){return e}function P_(e,t,n,r){return x(e,t,n,r)}function F_(e,t,n,r){return S(e,t,n,r)}function I_(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 x(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=S(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 L_(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 x(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,y=(e-p)/h,b=s*v+c*y,S;if(b>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 I_(e,t,p+h*Math.cos(S),m+h*Math.sin(S),i,a)}function R_(e,t,n,r,i,a,o){return C(e,t,n,r,i,a,o)}function z_(e,t,n,r,i,a,o,s,c){let l=C(e,t,n,r,o,s,c),u=c!==!1,d=u?i:-i,f=u?a:-a;return f<d-1e-9&&(f+=2*Math.PI),{__bk2d:`trimmed`,basis:l,tStart:d,tEnd:f}}function B_(e){return w(e)}function V_(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 H_(e,t){return _(cp(e),t)}function U_(e,t){return{point:_(cp(e),t),tangent:v(cp(e),t)}}function W_(e){return y(cp(e))}function G_(e){return b(lp(e))}function K_(e,t,n){return{__bk2d:`trimmed`,basis:cp(e),tStart:t,tEnd:n}}function q_(e){let t=e;switch(t.__bk2d){case`line`:{let e=t;e.ox+=e.dx*e.len,e.oy+=e.dy*e.len,e.dx=-e.dx,e.dy=-e.dy;break}case`circle`:case`ellipse`:{let e=t;e.sense=!e.sense;break}case`trimmed`:{let e=t;[e.tStart,e.tEnd]=[e.tEnd,e.tStart];break}case`bezier`:{let e=t;e.poles=[...e.poles].reverse();break}case`bspline`:{let e=t;e.poles=[...e.poles].reverse();let n=e.knots[0],r=e.knots[e.knots.length-1];n!==void 0&&r!==void 0&&(e.knots=e.knots.map(e=>n+r-e).reverse()),Array.isArray(e.weights)&&(e.weights=[...e.weights].reverse());break}default:break}}function J_(e){return JSON.parse(JSON.stringify(e))}function Y_(e,t){let n=cp(e),r=y(n),i=[];for(let e=0;e<=30;e++){let a=r.first+(r.last-r.first)*e/30,[o,s]=_(n,a),[c,l]=v(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 V_(i)}function X_(e,t,n){return ee(cp(e),t,n)}function Z_(e,t,n,r){return te(cp(e),t,n,r)}function Q_(e,t,n,r){return ne(cp(e),t,n,r)}function $_(e,t,n){return re(cp(e),t,n)}function ev(e,t,n,r,i){return ie(cp(e),t,n,r,i)}function tv(e,t,n,r,i,a){return dv(e,iv(t,n,r,i,a))}function nv(e,t,n){return{m:e,tx:t,ty:n,delete:If}}function rv(){return nv([1,0,0,0,1,0,0,0,1],0,0)}function iv(e,n,r,i,a){let o=Math.sqrt(r*r+i*i);if(o<1e-15)return rv();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 nv(u,e-t(u,0)*e-t(u,1)*n,n-t(u,3)*e-t(u,4)*n)}function av(e,t){return nv([1,0,0,0,1,0,0,0,1],e,t)}function ov(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 nv(u,d-t(u,0)*d-t(u,1)*f,f-t(u,3)*d-t(u,4)*f)}return nv([-1,0,0,0,-1,0,0,0,1],2*e,2*n)}function sv(e,t,n){let r=Math.cos(e),i=Math.sin(e);return nv([r,-i,0,i,r,0,0,0,1],t-r*t+i*n,n-i*t-r*n)}function cv(e,t,n){return nv([e,0,0,0,e,0,0,0,1],t*(1-e),n*(1-e))}function lv(e,t,n){e.tx=t,e.ty=n}function uv(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 dv(e,n){let r=cp(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 ee(r,a,o);let d=y(r),f=[];for(let e=0;e<=20;e++){let[t,n]=_(r,d.first+(d.last-d.first)*e/20);f.push([s*t+c*n+a,l*t+u*n+o])}return w(f)}function fv(e,t,n){let r=ae(cp(e),cp(t),n),i=r.segments.map(e=>Object.assign(e,{delete(){}}));return{points:r.points,segments:i}}function pv(e,t,n){let r=cp(e),i=y(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]=_(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]=_(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]=_(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]=_(r,a),[s,c]=v(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]=_(r,a);return{param:a,distance:Math.sqrt((c-t)**2+(l-n)**2)}}function mv(e,t,n,r,i,a){let o=cp(e),s=cp(t),c=n,l=i,u=1/0;for(let e=0;e<=50;e++){let t=n+(r-n)*e/50,[d,f]=_(o,t);for(let e=0;e<=50;e++){let n=i+(a-i)*e/50,[r,o]=_(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]=_(s,f),u=pv(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]=_(o,d),h=pv(t,p,m);if(h){let e=Math.max(i,Math.min(a,h.param)),t=Math.abs(e-f)<1e-12;if(f=e,t)break}}let[p,m]=_(o,d),[h,g]=_(s,f);return Math.sqrt((h-p)**2+(g-m)**2)}function hv(e,n,r,i){let a=cp(e),o=y(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(_(a,t))}u=0;for(let e=0;e<c;e++){let[n,r]=_(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 V_(l,{degMax:s})}function gv(e){let n=lp(e);if(n.__bk2d===`bezier`)return[e];if(n.__bk2d!==`bspline`)return gv(hv(e,1e-6,`C2`,10));let r=y(cp(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=_(n,r),l=_(n,i),u=v(n,r),d=v(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 _v(){return ge()}function vv(e,t,n){_e(up(e),cp(t),n)}function yv(e){let t=up(e);return{xMin:t.xMin,yMin:t.yMin,xMax:t.xMax,yMax:t.yMax}}function bv(e,t){let n=up(e),r=up(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 xv(e,t){let n=up(e),r=up(t);return n.xMax<r.xMin||r.xMax<n.xMin||n.yMax<r.yMin||r.yMax<n.yMin}function Sv(e,t,n){let r=up(e);return t<r.xMin||t>r.xMax||n<r.yMin||n>r.yMax}function Cv(e){let t=lp(e);return t.__bk2d===`circle`?{cx:t.cx,cy:t.cy,radius:t.radius,isDirect:t.sense}:null}function wv(e){let t=lp(e);return t.__bk2d===`ellipse`?{majorRadius:t.majorRadius,minorRadius:t.minorRadius,xAxisAngle:t.xDirAngle,isDirect:t.sense}:null}function Tv(e){let t=lp(e);return t.__bk2d===`bezier`?[...t.poles]:null}function Ev(e){let t=lp(e);return t.__bk2d===`bezier`?t.poles.length-1:null}function Dv(e){let t=lp(e);return t.__bk2d===`bspline`?{poles:[...t.poles],knots:[...t.knots],multiplicities:[...t.multiplicities],degree:t.degree,isPeriodic:t.isPeriodic}:null}function Ov(e){return me(cp(e))}function kv(e){return he(e)}function Av(e,t){let n=cp(e),r=y(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 jv(e,n,r,i,a){let o=cp(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 bh(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=y(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]=_(o,l.first+t*f),[i,u]=_(o,l.first+(t+1)*f);p.push(e.makeCircleArc3d(...c(n,r),...c(i,u),...a,...s))}return p.length===1?Bf(t(p,0)):Vf(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 bh(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 Bf(e.interpolatePoints(i,r))}let l=y(o),u=[];for(let e=0;e<=100;e++){let[t,n]=_(o,l.first+(l.last-l.first)*e/100);u.push(c(t,n))}return Hh(e,u)}function Mv(e,t,r){if(!Lf(r))throw Error(`brepkit: buildEdgeOnSurface requires a face handle as surface`);let i=L(r,`face`),a=cp(t),o=y(a),s=e.getSurfaceType(i)===`plane`?50:100,c=[];for(let t=0;t<=s;t++){let[r,l]=_(a,o.first+(o.last-o.first)*t/s);c.push(n(e.evaluateSurface(i,r,l)))}return Hh(e,c)}function Nv(e){return e}function Pv(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 Fv(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)}));Pv(d,u,80,.05);let f=d.map(e=>e.uv);if(f.length>=2)return V_(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 x(t(n,0),t(n,1),t(r,0),t(r,1))}throw Error(`brepkit: extractCurve2dFromEdge: degenerate edge (${p.length} coords)`)}function Iv(e,t,n){return e}function Lv(e,n,r){if(n.length>=1){let r=bp(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 zf(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 Ph(e,i)}function Rv(e){return{createPoint2d:(e,t)=>O_(e,t),createDirection2d:(e,t)=>k_(e,t),createVector2d:(e,t)=>A_(e,t),createAxis2d:(e,t,n,r)=>j_(e,t,n,r),wrapCurve2dHandle:e=>M_(e),createCurve2dAdaptor:e=>N_(e),makeLine2d:(e,t,n,r)=>P_(e,t,n,r),makeCircle2d:(e,t,n,r)=>F_(e,t,n,r),makeArc2dThreePoints:(e,t,n,r,i,a)=>I_(e,t,n,r,i,a),makeArc2dTangent:(e,t,n,r,i,a)=>L_(e,t,n,r,i,a),makeEllipse2d:(e,t,n,r,i,a,o)=>R_(e,t,n,r,i,a,o),makeEllipseArc2d:(e,t,n,r,i,a,o,s,c)=>z_(e,t,n,r,i,a,o,s,c),makeBezier2d:e=>B_(e),makeBSpline2d:(e,t)=>V_(e,t),evaluateCurve2d:(e,t)=>H_(e,t),evaluateCurve2dD1:(e,t)=>U_(e,t),getCurve2dBounds:e=>W_(e),getCurve2dType:e=>G_(e),trimCurve2d:(e,t,n)=>K_(e,t,n),reverseCurve2d:e=>{q_(e)},copyCurve2d:e=>J_(e),offsetCurve2d:(e,t)=>Y_(e,t),translateCurve2d:(e,t,n)=>X_(e,t,n),rotateCurve2d:(e,t,n,r)=>Z_(e,t,n,r),scaleCurve2d:(e,t,n,r)=>Q_(e,t,n,r),mirrorCurve2dAtPoint:(e,t,n)=>$_(e,t,n),mirrorCurve2dAcrossAxis:(e,t,n,r,i)=>ev(e,t,n,r,i),affinityTransform2d:(e,t,n,r,i,a)=>tv(e,t,n,r,i,a),createIdentityGTrsf2d:()=>rv(),createAffinityGTrsf2d:(e,t,n,r,i)=>iv(e,t,n,r,i),createTranslationGTrsf2d:(e,t)=>av(e,t),createMirrorGTrsf2d:(e,t,n,r,i,a,o)=>ov(e,t,n,r,i,a,o),createRotationGTrsf2d:(e,t,n)=>sv(e,t,n),createScaleGTrsf2d:(e,t,n)=>cv(e,t,n),setGTrsf2dTranslationPart:(e,t,n)=>{lv(e,t,n)},multiplyGTrsf2d:(e,t)=>{uv(e,t)},transformCurve2dGeneral:(e,t)=>dv(e,t),intersectCurves2d:(e,t,n)=>fv(e,t,n),projectPointOnCurve2d:(e,t,n)=>pv(e,t,n),distanceBetweenCurves2d:(e,t,n,r,i,a)=>mv(e,t,n,r,i,a),approximateCurve2dAsBSpline:(e,t,n,r)=>hv(e,t,n,r),decomposeBSpline2dToBeziers:e=>gv(e),createBoundingBox2d:()=>_v(),addCurveToBBox2d:(e,t,n)=>{vv(e,t,n)},getBBox2dBounds:e=>yv(e),mergeBBox2d:(e,t)=>{bv(e,t)},isBBox2dOut:(e,t)=>xv(e,t),isBBox2dOutPoint:(e,t,n)=>Sv(e,t,n),getCurve2dCircleData:e=>Cv(e),getCurve2dEllipseData:e=>wv(e),getCurve2dBezierPoles:e=>Tv(e),getCurve2dBezierDegree:e=>Ev(e),getCurve2dBSplineData:e=>Dv(e),serializeCurve2d:e=>Ov(e),deserializeCurve2d:e=>kv(e),splitCurve2d:(e,t)=>Av(e,t),liftCurve2dToPlane:(t,n,r,i)=>jv(e,t,n,r,i),buildEdgeOnSurface:(t,n)=>Mv(e,t,n),extractSurfaceFromFace:e=>Nv(e),extractCurve2dFromEdge:(t,n)=>Fv(e,t,n),buildCurves3d:e=>{},fixWireOnFace:(e,t,n)=>Iv(e,t,n),fillSurface:(t,n)=>Lv(e,t,n)}}function zv(e,t){let n=t;if(n.type===`solid`)return e.volume(L(t),tp);if(n.type===`compound`){let n=bp(e,t,`solid`),r=0;for(let t of n)r+=e.volume(L(t),tp);return r}return 0}function Bv(e,t){let n=t;if(n.type===`face`)return e.faceArea(L(t),tp);if(n.type===`solid`)return e.surfaceArea(L(t),tp);if(n.type===`compound`){let n=bp(e,t,`face`),r=0;for(let t of n)r+=e.faceArea(L(t),tp);return r}return 0}function Vv(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 Hv(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 Uv(e,t){let r=t;if(r.type===`solid`)return n(e.centerOfMass(L(t),tp));if(r.type===`face`){let n=Lp(e,t);return Bp(e,t,(n.uMin+n.uMax)/2,(n.vMin+n.vMax)/2)}if(r.type===`edge`)return Hv(e,r.id);if(r.type===`vertex`)return Fp(e,t);let i=bp(e,t,`vertex`);if(i.length>0){let t=0,n=0,r=0;for(let a of i){let i=Fp(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 Wv(e,t){let n=t;return n.type===`edge`?Hv(e,n.id):Uv(e,t)}function Gv(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=Fp(e,t);return{min:[...n],max:[...n]}}let i=bp(e,t,`vertex`);if(i.length===0)return{min:[0,0,0],max:[0,0,0]};let a=Fp(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=Fp(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 Kv(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 qv(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 Jv(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 Yv(e,t){let n=n=>Kv(e,t,n);return{distanceTo(e){return n(e)},dispose(){}}}function Xv(e,t,n=!1){let r=t,i=r.type===`edge`||r.type===`wire`||r.type===`face`;return{volume:zv(e,t),area:Bv(e,t),length:n&&i?Vv(e,t):0,centerOfMass:Uv(e,t),boundingBox:Gv(e,t)}}function Zv(e){return{volume:t=>zv(e,t),area:t=>Bv(e,t),length:t=>Vv(e,t),centerOfMass:t=>Uv(e,t),linearCenterOfMass:t=>Wv(e,t),boundingBox:t=>Gv(e,t),distance:(t,n)=>Kv(e,t,n),surfaceCurvature:(t,n,r)=>qv(e,t,n,r),surfaceCenterOfMass:t=>Jv(e,t),createDistanceQuery:t=>Yv(e,t),measureBulk:(t,n)=>Xv(e,t,n)}}function Qv(e){return e.sketchNew()}function $v(e,t,n,r,i){return e.sketchAddPoint(t,n,r,i)}function ey(e,t,n){e.sketchAddConstraint(t,n)}function ty(e,t,n,r){return e.sketchSolve(t,n,r)}function ny(e,t,n,r,i){return e.sketchAddArc(t,n,r,i)}function ry(e,t){let n=e.sketchDof(t);return typeof n==`string`?n:String(n)}function iy(e){return{sketchNew:()=>Qv(e),sketchAddPoint:(t,n,r,i)=>$v(e,t,n,r,i),sketchAddArc:(t,n,r,i)=>ny(e,t,n,r,i),sketchAddConstraint:(t,n)=>{ey(e,t,n)},sketchSolve:(t,n,r)=>ty(e,t,n,r),sketchDof:t=>ry(e,t)}}function ay(e,t,n,r){return I(e.extrude(L(t,`face`),n[0],n[1],n[2],r))}function oy(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 sy(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 cy(e,t,n,r,i){(n!==void 0||r!==void 0||i!==void 0)&&op(`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 ly(e){switch(e){case 0:return`rmf`;case 1:return`rightCorner`;case 2:return`roundCorner`;default:return}}function uy(e,t,n,r){let i=r?.transitionMode===void 0?void 0:ly(r.transitionMode),a=t,o=a.type===`wire`?e.makeFaceFromWire(a.id):L(t,`face`);if(n.type===`wire`){let t=bp(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&&op(`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=Pm(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 dy(e,t,n){let r=t,i=r.type===`wire`?e.makeFaceFromWire(r.id):L(t,`face`);if(n.type===`wire`){let t=bp(e,n,`edge`).map(e=>L(e,`edge`));return I(e.sweepAlongEdges(i,t))}let a=Pm(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 fy(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 py(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 my(e){switch(e){case`right`:return`rightCorner`;case`round`:return`roundCorner`;case`transformed`:return`rmf`;default:return}}function hy(e,t,n){return n?{shape:e,firstShape:t,lastShape:t}:e}function gy(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 _y(e,t){try{if(t.type!==`wire`)return{edgeId:L(t,`edge`)};let n=bp(e,t,`edge`);if(n.length===1){let e=n[0];return e?{edgeId:L(e,`edge`)}:void 0}op(`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 vy(e,t,n,r){let i=_y(e,n);if(i)return gy(e,t,i.edgeId,r)}function yy(e,t,n){let r=Pm(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 by(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?my(s):void 0;if(c){let r=vy(e,a,n,c);if(r)return hy(r,t,o)}return hy(yy(e,a,n)||dy(e,t,n),t,o)}function xy(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 cy(e,t)}function Sy(e,t,n,r){let i={type:`extrusionLaw`,profile:t,length:n,endFactor:r,Trim(e,t,n){return i},delete:If};return i}function Cy(e,t,n,r,i,a,o){if(i!==null){let r=ay(e,n,zp(e,n,0,0),i);return o?Xm(e,t,r):r}return t}function wy(e){return{extrude:(t,n,r)=>ay(e,t,n,r),revolve:(t,n,r)=>oy(e,t,n,r),revolveVec:(t,n,r,i)=>sy(e,t,n,r,i),loft:(t,n,r,i)=>cy(e,t,n,r,i),sweep:(t,n,r)=>uy(e,t,n,r),simplePipe:(t,n)=>dy(e,t,n),helicalSweep:(t,n,r,i,a,o)=>fy(e,t,n,r,i,a,o),sweepWithOptions:(t,n,r,i,a)=>py(e,t,n,r,i,a),sweepPipeShell:(t,n,r)=>by(e,t,n,r),loftAdvanced:(t,n)=>xy(e,t,n),buildExtrusionLaw:(t,n,r)=>Sy(e,t,n,r),draftPrism:(t,n,r,i,a,o)=>Cy(e,t,n,r,i,a,o)}}function Ty(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 Ey=class{oc;kernelId=`brepkit`;capabilities=r;bk;constructor(e){this.bk=e,this.oc=e;let t=this.bk;Object.assign(this,ch(t),Qh(t),wy(t),gg(t),km(t),s_(t),D_(t),Zv(t),Pp(t),gm(t),Km(t),Zg(t),iy(t),Rv(t),Ty(t))}};function Dy(e){throw Error(`manifold: ${e} is not implemented`)}var Oy=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.profileEdge.profileWire.profileFace`.split(`.`));function ky(e){return Oy.has(e)}function z(e,t,n){return{op:e,params:t,inputs:n,replayable:ky(e)&&n.every(e=>e.replayable)}}function B(e,t){return{manifold:e,node:t}}function V(e){return e.manifold}function H(e){return e.node}function Ay(e){if(e&&typeof e==`object`&&`manifold`in e&&`node`in e)return e}var jy=[`occt`,`occt-wasm`];function My(){for(let e of jy)try{return U(e)}catch{}}function Ny(e){let t=My();if(!t)throw Error(`manifold: ${e} requires a registered occt kernel; none is available`);return t}var Py=new WeakMap,Fy=[0,0,0],Iy=[0,0,1];function Ly(e){return Math.hypot(e[0],e[1],e[2])}function Ry(e){let t=Ly(e);return t===0?[...Iy]:[e[0]/t,e[1]/t,e[2]/t]}function zy(e){let[t,n,r]=Ry(e);return[0,180/Math.PI*Math.atan2(Math.hypot(t,n),r),180/Math.PI*Math.atan2(n,t)]}function By(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(zy(n))),(t[0]!==0||t[1]!==0||t[2]!==0)&&(r=r.translate(t)),r}return{makeBox:(e,n,r)=>B(t.cube([e,n,r],!1),z(`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 B(t.cube(r,!1).translate(i),z(`makeBoxWithCorners`,{p1:e,p2:n},[]))},makeCylinder:(e,r,i=Fy,a=Iy)=>B(n(t.cylinder(r,e,e,0,!1),i,a),z(`makeCylinder`,{radius:e,height:r,center:i,direction:a},[])),makeSphere:(e,n=Fy)=>{let r=t.sphere(e,0);return(n[0]!==0||n[1]!==0||n[2]!==0)&&(r=r.translate(n)),B(r,z(`makeSphere`,{radius:e,center:n},[]))},makeCone:(e,r,i,a=Fy,o=Iy)=>B(n(t.cylinder(i,e,r,0,!1),a,o),z(`makeCone`,{radius1:e,radius2:r,height:i,center:a,direction:o},[])),makeTorus:(r,i,a=Fy,o=Iy)=>{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 B(n(t.revolve([c],0),a,o),z(`makeTorus`,{majorRadius:r,minorRadius:i,center:a,direction:o},[]))},makeEllipsoid:(e,n,r)=>B(t.sphere(1,0).scale([e,n,r]),z(`makeEllipsoid`,{aLength:e,bLength:n,cLength:r},[])),makeRectangle:()=>Dy(`makeRectangle`)}}function Vy(e){return e}function Hy(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=H(Vy(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 Wy(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 Gy(e){let t=e.Manifold;function n(e,t,n){let r=Vy(e),i=Vy(t);return B(V(r).add(V(i)),z(`makeFuse`,{},[H(r),H(i)]))}function r(e,t,n){let r=Vy(e),i=Vy(t);return B(V(r).subtract(V(i)),z(`makeCut`,{},[H(r),H(i)]))}function i(e,t,n){let r=Vy(e),i=Vy(t);return B(V(r).intersect(V(i)),z(`makeCommon`,{},[H(r),H(i)]))}function a(e,n){if(e.length===0)throw Error(`manifold: fuseAll requires at least one shape`);let r=e.map(Vy),[i]=r;if(i===void 0)throw Error(`manifold: fuseAll requires at least one shape`);return r.length===1?i:B(t.union(r.map(V)),z(`makeFuse`,{},r.map(H)))}function o(e,n,r){let i=Vy(e);if(n.length===0)return i;let a=n.map(Vy);return B(t.difference([V(i),...a.map(V)]),z(`makeCut`,{},[H(i),...a.map(H)]))}function s(e,t,n){let r=Vy(e),{normal:i,offset:a}=Uy(t),[o]=V(r).splitByPlane(i,a);return B(o,z(`section`,{normal:i,offset:a},[H(r),H(Vy(t))]))}function c(e,n){let r=Vy(e),[i]=n;if(i===void 0)throw Error(`manifold: split requires at least one tool`);let a=Vy(i),{normal:o,offset:s}=Uy(i),[c,l]=V(r).splitByPlane(o,s);return B(t.union([c,l]),z(`split`,{normal:o,offset:s},[H(r),H(a)]))}function l(e,t,n){let r=[],i=Vy(e),a=Vy(t);return(V(i)===void 0||V(i).isEmpty())&&r.push({operand:`base`,issue:`null-shape`,message:`Base shape is empty`}),(V(a)===void 0||V(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 Wy(Hy(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 Ky(e){return e}function qy(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function Jy(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 Yy(e,t,n){let r=qy();return r[12]=e,r[13]=t,r[14]=n,r}function Xy(e,t,n){let r=e,[i,a,o]=Jy(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=qy();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 Zy(e,t){let n=qy();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 Qy(e,t){let[n,r,i]=Jy(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=qy();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 $y(e,t){let n=qy();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 eb(e,t,n,r,i){return B(e.transform(t),z(n,r,[i]))}function tb(e,t,n,r){let i=Ky(e);return eb(V(i),Yy(t,n,r),`translateShape`,{x:t,y:n,z:r},H(i))}function nb(e,t,n=[0,0,1],r=[0,0,0]){let i=Ky(e);return eb(V(i),Xy(t,n,r),`rotateShape`,{angle:t,axis:n,center:r},H(i))}function rb(e,t,n){let r=Ky(e);return eb(V(r),Qy(t,n),`mirrorShape`,{origin:t,normal:n},H(r))}function ib(e,t,n){let r=Ky(e);return eb(V(r),Zy(t,n),`scaleShape`,{center:t,factor:n},H(r))}function ab(e,t){if(!Array.isArray(t)||t.length!==16)throw Error(`manifold: transform expects a 16-element column-major matrix`);let n=Ky(e);return eb(V(n),t,`transformShape`,{matrix:[...t]},H(n))}function ob(e,t,n,r){let i=Ky(e);return eb(V(i),$y(t,n),`generalTransform`,{linear:t,translation:n,isOrthogonal:r},H(i))}function sb(e,t,n){let r=Ky(e);return eb(V(r),$y(t,n),`generalTransformNonOrthogonal`,{linear:t,translation:n},H(r))}function cb(e){let t=qy();for(let n of e)t=mb(n.type===`translate`?Yy(n.x,n.y,n.z):Xy(n.angle*Math.PI/180,n.axis??[0,0,1],n.center??[0,0,0]),t);return{handle:t,dispose:()=>{}}}function lb(e,t,n,r){let i=[e];for(let a=1;a<r;a++){let r=n*a;i.push(tb(e,t[0]*r,t[1]*r,t[2]*r))}return i}function ub(e,t,n,r,i){let a=[e];for(let o=1;o<i;o++)a.push(nb(e,r*o*Math.PI/180,n,t));return a}function db(e,t,n,r,i,a,o,s){let c=Ky(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(V(c).transform(Yy(o,s,d))),u.push(H(c))}return B(l.length===1?l[0]:e.Manifold.union(l),z(`gridPattern`,{directionX:n,directionY:r,spacingX:i,spacingY:a,countX:o,countY:s},u))}function fb(e){return e.map(e=>{switch(e.type){case`translate`:return tb(e.shape,e.x,e.y,e.z);case`rotate`:return nb(e.shape,e.angle*Math.PI/180,e.axis,e.center);case`scale`:return ib(e.shape,e.center,e.factor);case`mirror`:return rb(e.shape,e.origin,e.normal)}})}function pb(e){return{composeTransform:cb,transform:ab,translate:tb,rotate:nb,mirror:rb,scale:ib,generalTransform:ob,generalTransformNonOrthogonal:sb,positionOnCurve:()=>Dy(`positionOnCurve`),linearPattern:lb,circularPattern:ub,gridPattern:(t,n,r,i,a,o,s)=>db(e,t,n,r,i,a,o,s),transformBatch:fb}}function mb(e,t){let n=qy();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}var hb=2*Math.PI,gb=e=>Math.hypot(e[0],e[1],e[2]),_b=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]];function vb(e){return gb(_b(e.p2,e.p1))}function yb(e,t){let n=e.map(e=>[e[0],e[1],e[2]]);for(let e=1;e<n.length;e++)for(let r=0;r<n.length-e;r++){let e=n[r]??[0,0,0],i=n[r+1]??[0,0,0];n[r]=[e[0]*(1-t)+i[0]*t,e[1]*(1-t)+i[1]*t,e[2]*(1-t)+i[2]*t]}return n[0]??[0,0,0]}function bb(e){return e.k===`line`?`LINE`:e.k===`bezier`?`BEZIER`:e.k===`helix`?`BSPLINE`:Math.abs(e.rx-e.ry)<1e-9*Math.max(1,e.rx)?`CIRCLE`:`ELLIPSE`}function xb(e){return e.k===`line`?{first:0,last:vb(e)}:e.k===`conic`?{first:e.a0,last:e.a1}:e.k===`helix`?{first:0,last:hb*e.turns}:{first:0,last:1}}function Sb(e,t){if(e.k===`line`){let n=t/(vb(e)||1);return[e.p1[0]+(e.p2[0]-e.p1[0])*n,e.p1[1]+(e.p2[1]-e.p1[1])*n,e.p1[2]+(e.p2[2]-e.p1[2])*n]}if(e.k===`bezier`)return yb(e.points,t);if(e.k===`helix`){let n=Math.cos(t),r=Math.sin(t),i=e.pitch*t/hb;return[e.center[0]+e.radius*(n*e.x[0]+r*e.y[0])+i*e.axis[0],e.center[1]+e.radius*(n*e.x[1]+r*e.y[1])+i*e.axis[1],e.center[2]+e.radius*(n*e.x[2]+r*e.y[2])+i*e.axis[2]]}let n=Math.cos(t),r=Math.sin(t);return[e.center[0]+e.rx*n*e.x[0]+e.ry*r*e.y[0],e.center[1]+e.rx*n*e.x[1]+e.ry*r*e.y[1],e.center[2]+e.rx*n*e.x[2]+e.ry*r*e.y[2]]}function Cb(e,t){let n;if(e.k===`line`)n=_b(e.p2,e.p1);else if(e.k===`bezier`){let r=yb(e.points,Math.max(0,t-1e-4));n=_b(yb(e.points,Math.min(1,t+1e-4)),r)}else if(e.k===`helix`){let r=Math.cos(t),i=Math.sin(t),a=e.pitch/hb;n=[e.radius*(-i*e.x[0]+r*e.y[0])+a*e.axis[0],e.radius*(-i*e.x[1]+r*e.y[1])+a*e.axis[1],e.radius*(-i*e.x[2]+r*e.y[2])+a*e.axis[2]]}else{let r=Math.cos(t),i=Math.sin(t);n=[-e.rx*i*e.x[0]+e.ry*r*e.y[0],-e.rx*i*e.x[1]+e.ry*r*e.y[1],-e.rx*i*e.x[2]+e.ry*r*e.y[2]]}let r=gb(n)||1;return[n[0]/r,n[1]/r,n[2]/r]}function wb(e){if(e.k===`line`)return vb(e);if(e.k===`helix`){let t=hb*e.radius;return e.turns*Math.sqrt(t*t+e.pitch*e.pitch)}if(e.k===`conic`){let t=Math.abs(e.a1-e.a0);if(Math.abs(e.rx-e.ry)<1e-9*Math.max(1,e.rx))return e.rx*t;if(Math.abs(t-hb)<1e-9){let t=e.rx,n=e.ry,r=(t-n)*(t-n)/((t+n)*(t+n));return Math.PI*(t+n)*(1+3*r/(10+Math.sqrt(4-3*r)))}return Ob(t=>Sb(e,t),e.a0,e.a1,256)}return Ob(t=>Sb(e,t),0,1,128)}function Tb(e){return e.k===`conic`?Math.abs(Math.abs(e.a1-e.a0)-hb)<1e-9:!1}function Eb(e){return Tb(e)}function Db(e){return e.k===`conic`?hb:0}function Ob(e,t,n,r){let i=0,a=e(t);for(let o=1;o<=r;o++){let s=e(t+(n-t)*o/r);i+=gb(_b(s,a)),a=s}return i}function kb(e){return e}function Ab(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function jb(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 Mb(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function Nb(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function Pb(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function Fb(e){return Math.hypot(e[0],e[1],e[2])}function Ib(e){let t=Fb(e);return t<1e-12?[0,0,1]:[e[0]/t,e[1]/t,e[2]/t]}function Lb(e){return Ib(jb(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function Rb(e){let t=Ib(e),n=Lb(t);return{xAxis:n,yAxis:Ib(jb(t,n))}}function zb(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 Bb(e){return zb(e)<0?[...e].reverse():e}function Vb(e){return zb(e)>0?[...e].reverse():e}function Hb(e){return e.node?.params}function Ub(e){let t=kb(e),n=Hb(t),r=n?.outline??n?.polygon??n?.points;if(r&&r.length>=3){let e=n?.origin??[0,0,0],t=Bb(r.map(e=>[e[0],e[1]])),i=(n?.holes)?.filter(e=>e.length>=3).map(e=>Vb(e.map(e=>[e[0],e[1]])));if(n?.xAxis&&n.yAxis)return{outline:t,holes:i,origin:e,xAxis:n.xAxis,yAxis:n.yAxis};let{xAxis:a,yAxis:o}=Rb(n?.normal??[0,0,1]);return{outline:t,holes:i,origin:e,xAxis:a,yAxis:o}}return Wb(t)}function Wb(e){let t=V(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=Gb(i);return{outline:Bb(o.length>=3?o:[[-.5,-.5],[.5,-.5],[0,.5]]),origin:[0,0,a],xAxis:[1,0,0],yAxis:[0,1,0]}}function Gb(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 Kb(e){let t=[];for(let n=1;n+1<e;n++)t.push(0,n,n+1);return t}function qb(e,t){let n=e.length;if(n<2||t<=n)return e.map(e=>[e[0],e[1]]);let r=[],i=0;for(let t=0;t<n;t++){let a=e[t]??[0,0],o=e[(t+1)%n]??[0,0],s=Math.hypot(o[0]-a[0],o[1]-a[1]);r.push(s),i+=s}if(i===0)return e.map(e=>[e[0],e[1]]);let a=t-n,o=r.map(e=>a*e/i),s=o.map(e=>Math.floor(e)),c=s.reduce((e,t)=>e+t,0),l=o.map((e,t)=>({i:t,f:e-Math.floor(e)})).sort((e,t)=>t.f-e.f);for(let e=0;c<a;e++,c++){let t=l[e%l.length]?.i??0;s[t]=(s[t]??0)+1}let u=[];for(let t=0;t<n;t++){let r=e[t]??[0,0],i=e[(t+1)%n]??[0,0];u.push([r[0],r[1]]);let a=s[t]??0;for(let e=1;e<=a;e++){let t=e/(a+1);u.push([r[0]+(i[0]-r[0])*t,r[1]+(i[1]-r[1])*t])}}return u}function Jb(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 Yb(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=Zb(t.length,n),a=new e.Mesh({numProp:3,vertProperties:Float32Array.from(r),triVerts:Uint32Array.from(i)});return Xb(e,new e.Manifold(a))}function Xb(e,t){if(typeof t.volume!=`function`||t.volume()>=0)return t;let n=t.getMesh(),r=n.triVerts;for(let e=0;e+2<r.length;e+=3){let t=r[e+1]??0;r[e+1]=r[e+2]??0,r[e+2]=t}let i=new e.Mesh({numProp:n.numProp,vertProperties:n.vertProperties,triVerts:r}),a=new e.Manifold(i);return typeof t.delete==`function`&&t.delete(),a}function Zb(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=Kb(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=Kb(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 Qb(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 Ib(Mb(e[Math.min(e.length-1,t+1)]??e[t]??[0,0,0],n))},i=r(0),a=Ib(Mb(t,Pb(i,Ab(t,i))));Fb(a)<1e-9&&(a=Lb(i)),n.push({origin:e[0]??[0,0,0],xAxis:a,yAxis:Ib(jb(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=Mb(s,o),l=Ab(c,c),u=a;if(l>1e-18){let e=Mb(a,Pb(c,2/l*Ab(c,a))),n=Mb(i,Pb(c,2/l*Ab(c,i))),o=Mb(r(t),n),s=Ab(o,o);u=s>1e-18?Mb(e,Pb(o,2/s*Ab(o,e))):e}let d=r(t),f=Ib(Mb(u,Pb(d,Ab(u,d)))),p=Ib(jb(d,f));n.push({origin:s,xAxis:f,yAxis:p,tangent:d}),i=d,a=f}return n}var $b=24,ex=24,tx=null;function nx(e){let t=tx?tx(Math.max(Math.abs(e),1e-6)):$b;return Math.max($b,t)}var rx=[0,0,0],ix=1e-6,ax={delete:()=>{},isEmpty:()=>!1};function ox(e,t){return e[t]??rx}function sx(e,t=1){return Math.max(2,Math.ceil(Math.abs(e)/(2*Math.PI)*nx(t)))}function cx(e){return Ib(jb(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function lx(e,t,n,r,i,a){let o=Ib(t),s=a?Ib(a):cx(o),c=Ib(jb(o,s)),l=i-r,u=sx(l,n),d=[];for(let t=0;t<=u;t++){let i=r+l*t/u;d.push(Nb(e,Nb(Pb(s,n*Math.cos(i)),Pb(c,n*Math.sin(i)))))}return d}function ux(e,t,n){let r=Mb(t,e),i=Mb(n,e),a=jb(r,i);if(Fb(a)<1e-12)return[e,t,n];let o=Ib(a),s=Ab(r,r),c=Ab(i,i),l=Ab(r,i),u=2*(s*c-l*l);if(Math.abs(u)<1e-18)return[e,t,n];let d=c*(s-l)/u,f=s*(c-l)/u,p=Nb(e,Nb(Pb(r,d),Pb(i,f))),m=Fb(Mb(e,p)),h=Ib(Mb(e,p)),g=Ib(jb(o,h)),_=(e=>Math.atan2(Ab(Mb(e,p),g),Ab(Mb(e,p),h)))(n);return _<0&&(_+=2*Math.PI),lx(p,o,m,0,_,h)}function dx(e){let t=[];for(let n=0;n<=ex;n++){let r=n/ex,i=e.map(e=>[...e]);for(let e=1;e<i.length;e++)for(let t=0;t<i.length-e;t++){let e=ox(i,t),n=ox(i,t+1);i[t]=[e[0]*(1-r)+n[0]*r,e[1]*(1-r)+n[1]*r,e[2]*(1-r)+n[2]*r]}t.push(ox(i,0))}return t}function fx(e){let t=0,n=0,r=0;for(let i=0;i<e.length;i++){let a=ox(e,i),o=ox(e,(i+1)%e.length);t+=(a[1]-o[1])*(a[2]+o[2]),n+=(a[2]-o[2])*(a[0]+o[0]),r+=(a[0]-o[0])*(a[1]+o[1])}let i=[t,n,r];return Fb(i)<1e-12?[0,0,1]:Ib(i)}function px(e,t){return Fb(Mb(e,t))<ix}function mx(e){let t=e[0];if(!t)return[];let n=[...t];for(let t=1;t<e.length;t++){let r=e[t]??[];if(r.length===0)continue;let i=ox(n,n.length-1),a=px(ox(r,0),i),o=px(ox(r,r.length-1),i);!a&&o&&(r=[...r].reverse());let s=px(ox(r,0),i);for(let e=+!!s;e<r.length;e++)n.push(ox(r,e))}return n.length>1&&px(ox(n,0),ox(n,n.length-1))&&n.pop(),n}function hx(e){let t=fx(e),n=ox(e,0),r=e.length>1?Ib(Mb(ox(e,1),n)):cx(t);r=Ib(Mb(r,Pb(t,Ab(r,t)))),Fb(r)<1e-9&&(r=cx(t));let i=Ib(jb(t,r));return{outline:Bb(e.map(e=>{let t=Mb(e,n);return[Ab(t,r),Ab(t,i)]})),origin:n,xAxis:r,yAxis:i}}var gx=12;function _x(e,t){let[n,r]=e.curveParameters(t),i=gx;try{e.curveType(t)===`line`&&(i=1)}catch{}let a=[];for(let o=0;o<=i;o++)a.push(e.curvePointAtParam(t,n+(r-n)*o/i));return a}function vx(e,t){return mx(e.iterShapes(t,`edge`).map(t=>_x(e,t)))}function yx(e){let t=e.getCircularSegments;typeof t==`function`&&(tx=e=>t(e));function n(e,t){return B(ax,z(`profileEdge`,t?{pts:e,curve:t}:{pts:e},[]))}function r(e,t){let n=Ib(e),r=t?Ib(t):cx(n);return{x:r,y:Ib(jb(n,r))}}function i(e,t,n){let r=Mb(t,e),i=Mb(n,e),a=jb(r,i);if(Fb(a)<1e-12)return;let o=Ib(a),s=Ab(r,r),c=Ab(i,i),l=Ab(r,i),u=2*(s*c-l*l);if(Math.abs(u)<1e-18)return;let d=c*(s-l)/u,f=s*(c-l)/u,p=Nb(e,Nb(Pb(r,d),Pb(i,f))),m=Fb(Mb(e,p)),h=Ib(Mb(e,p)),g=Ib(jb(o,h)),_=Math.atan2(Ab(Mb(n,p),g),Ab(Mb(n,p),h));return _<0&&(_+=2*Math.PI),{k:`conic`,center:p,x:h,y:g,rx:m,ry:m,a0:0,a1:_}}function a(e){let t=Ay(e);if(t){let e=t.node.params;return e?.ring??e?.pts??[]}let n=My();return n?_x(n,e):[]}function o(e){let t=[];for(let n of e){let e=Ay(n);e&&t.push(H(e))}return t}function s(e){let t=mx(e.map(e=>a(e)));return B(ax,z(`profileWire`,{ring:t,...t.length>=3?hx(t):void 0},o(e)))}function c(e,t){let{outline:n,origin:r,xAxis:i,yAxis:a}=hx(e);return B(ax,z(`profileFace`,{outline:n,origin:r,xAxis:i,yAxis:a},t?[t]:[]))}function l(e){let t=Ay(e);if(t){let e=t.node.params?.ring??[];if(e.length>=3)return c(e,H(t))}let n=My();return c(n?vx(n,e):[],t?H(t):void 0)}function u(e,t){let n=Ay(e),r=n?.node?.params??{},i=r.origin??rx,a=r.xAxis??[1,0,0],s=r.yAxis??[0,1,0],c=e=>{let t=Mb(e,i);return[Ab(t,a),Ab(t,s)]},l=[];for(let e of t){let t=Ay(e),n;if(t)n=t.node.params?.ring??[];else{let t=My();n=t?vx(t,e):[]}n.length>=3&&l.push(n.map(c))}let u=[...r.holes??[],...l],d=n?[H(n),...o(t)]:o(t);return B(ax,z(`profileFace`,{outline:r.outline??[],holes:u,origin:i,xAxis:a,yAxis:s},d))}function d(e,t,n,r,i){let a=Ib(t),o=i?Ib(i):cx(a),s=Ib(jb(a,o)),c=[],l=nx(Math.max(n,r));for(let t=0;t<=l;t++){let i=2*Math.PI*t/l;c.push(Nb(e,Nb(Pb(o,n*Math.cos(i)),Pb(s,r*Math.sin(i)))))}return c}return{makeVertex:(e,t,r)=>n([[e,t,r]]),makeLineEdge:(e,t)=>n([e,t],{k:`line`,p1:e,p2:t}),makeCircleEdge:(e,t,i)=>{let{x:a,y:o}=r(t);return n(lx(e,t,i,0,2*Math.PI),{k:`conic`,center:e,x:a,y:o,rx:i,ry:i,a0:0,a1:2*Math.PI})},makeCircleArc:(e,t,i,a,o)=>{let{x:s,y:c}=r(t);return n(lx(e,t,i,a,o),{k:`conic`,center:e,x:s,y:c,rx:i,ry:i,a0:a,a1:o})},makeArcEdge:(e,t,r)=>n(ux(e,t,r),i(e,t,r)),makeEllipseEdge:(e,t,i,a,o)=>{let{x:s,y:c}=r(t,o);return n(d(e,t,i,a,o),{k:`conic`,center:e,x:s,y:c,rx:i,ry:a,a0:0,a1:2*Math.PI})},makeBezierEdge:e=>n(dx(e),{k:`bezier`,points:e.map(e=>[...e])}),makeTangentArc:(e,t,r)=>n([e,r],{k:`line`,p1:e,p2:r}),makeHelixWire:(e,t,r,i=[0,0,0],a=[0,0,1],o=!1)=>{let s=Ib(a),c=cx(s),l=Ib(jb(s,c)),u=o?Pb(l,-1):l,d=e===0?0:t/e,f={k:`helix`,center:i,axis:s,x:c,y:u,radius:r,pitch:e,turns:d},p=Math.max(8,Math.ceil(d*$b)),m=[];for(let e=0;e<=p;e++)m.push(Sb(f,2*Math.PI*d*e/p));return n(m,f)},makeWire:e=>s(e),makeWireFromMixed:e=>s(e),makeFace:l,addHolesInFace:u,makePolygonFace:e=>c(e)}}function bx(e){let t=e.Manifold,n=yx(e);function r(e,n){let r=e.map(e=>[e.x,e.y,e.z]);return B(t.hull(r),z(`hullFromPoints`,{points:r,tolerance:n},[]))}function i(e,n){let r=e.map(e=>V(e));return B(t.hull(r),z(`hull`,{tolerance:n},e.map(e=>H(e))))}function a(e){let n=e.map(e=>V(e)),r=n[0];if(!r)throw Error(`manifold: makeCompound requires at least one input shape`);return B(n.length===1?r:t.union(n),z(`makeCompound`,{},e.map(e=>H(e))))}function o(e,t){let n=e[0];return n||Dy(`sewAndSolidify (no input faces on manifold kernel)`),B(V(n),z(`sewAndSolidify`,{tolerance:t},e.map(e=>H(e))))}return{makeVertex:(e,t,r)=>n.makeVertex(e,t,r),makeEdge:()=>Dy(`makeEdge`),makeWire:e=>n.makeWire(e),makeFace:(e,t)=>n.makeFace(e,t),makeLineEdge:(e,t)=>n.makeLineEdge(e,t),makeCircleEdge:(e,t,r)=>n.makeCircleEdge(e,t,r),makeCircleArc:(e,t,r,i,a)=>n.makeCircleArc(e,t,r,i,a),makeArcEdge:(e,t,r)=>n.makeArcEdge(e,t,r),makeEllipseEdge:(e,t,r,i,a)=>n.makeEllipseEdge(e,t,r,i,a),makeEllipseArc:()=>Dy(`makeEllipseArc`),makeBezierEdge:e=>n.makeBezierEdge(e),makeTangentArc:(e,t,r)=>n.makeTangentArc(e,t,r),makeHelixWire:(e,t,r,i,a,o)=>n.makeHelixWire(e,t,r,i,a,o),makeWireFromMixed:e=>n.makeWireFromMixed(e),makeCompound:a,solidFromShell:()=>Dy(`solidFromShell`),hull:i,hullFromPoints:r,buildSolidFromFaces:()=>Dy(`buildSolidFromFaces`),makeNonPlanarFace:()=>Dy(`makeNonPlanarFace`),addHolesInFace:(e,t)=>n.addHolesInFace(e,t),removeHolesFromFace:()=>Dy(`removeHolesFromFace`),makeFaceOnSurface:()=>Dy(`makeFaceOnSurface`),bsplineSurface:(e,t,n)=>Ny(`bsplineSurface`).bsplineSurface(e,t,n),triangulatedSurface:(e,t,n)=>Ny(`triangulatedSurface`).triangulatedSurface(e,t,n),buildTriFace:()=>Dy(`buildTriFace`),sewAndSolidify:o,createPoint3d:()=>Dy(`createPoint3d`),createDirection3d:()=>Dy(`createDirection3d`),createVector3d:()=>Dy(`createVector3d`),createAxis1:()=>Dy(`createAxis1`),createAxis2:()=>Dy(`createAxis2`),createAxis3:()=>Dy(`createAxis3`)}}var xx=Math.PI/180;function Sx(e){return e}function Cx(e){let t=180/Math.PI*e;return t>360?360:t}function wx(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 Tx(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=wx(n.Location()),t=wx(n.Direction());if(e&&t)return{origin:e,direction:t}}}}function Ex(e){return e.outline.map(e=>[e[0],e[1]])}function Dx(e){return{outline:e.outline,origin:e.origin,xAxis:e.xAxis,yAxis:e.yAxis}}function Ox(e){return{origin:e.origin,xAxis:e.xAxis,yAxis:e.yAxis,tangent:Ib(jb(e.xAxis,e.yAxis))}}function kx(e){let t=0;for(let n of e.outline)t=Math.max(t,Math.hypot(n[0],n[1]));return t||1}function Ax(e){let t=V(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 jx(e,t){let n=Sx(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=Ax(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 Mx(e){return e?.node??z(`spine`,{},[])}function Nx(e,t,n){let r=t.xAxis,i=t.yAxis,a=t.origin,o=[r[0],r[1],r[2],0,i[0],i[1],i[2],0,n[0],n[1],n[2],0,a[0],a[1],a[2],1];return e.transform(o)}function Px(e,t,n){let r=Ib(n);return e.outline.map(n=>{let i=Mb(Nb(e.origin,Nb(Pb(e.xAxis,n[0]),Pb(e.yAxis,n[1]))),t),a=i[0]*r[0]+i[1]*r[1]+i[2]*r[2];return[Fb(Mb(i,Pb(r,a))),a]})}function Fx(e,t,n){let r=e,i=Ib(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=jb([0,1,0],i);Fb(t)<1e-9&&(t=[1,0,0]),t=Ib(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 Ix(e,t,n,r,i){let a=Ib(t),{xAxis:o,yAxis:s}=Rb(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=Nb(Pb(o,n*Math.cos(i)),Pb(s,n*Math.sin(i)));d.push(Nb(e,Nb(f,Pb(a,u*r))))}return d}function Lx(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 Rx(e,t,n,r){let i=Ub(t),a=Ib([n[0],n[1],n[2]]),o=Fb([n[0]*r,n[1]*r,n[2]*r]),s=[Ex(i),...(i.holes??[]).map(e=>e.map(e=>[e[0],e[1]]))];return B(Nx(Xb(e,e.Manifold.extrude(s,o)),i,a),z(`extrude`,{outline:i.outline,holes:i.holes,origin:i.origin,xAxis:i.xAxis,yAxis:i.yAxis,direction:[n[0],n[1],n[2]],length:r},[H(Sx(t))]))}function zx(e,t,n,r,i,a,o){let s=Ub(t),c=Cx(i),l=Px(s,n,r);return B(Fx(e.Manifold.revolve([l],0,c),n,r),z(a,o,[H(Sx(t))]))}function Bx(e,t){let n=e.length;if(n===0||t.length!==n)return e;let r=0,i=1/0;for(let a=0;a<n;a++){let o=0;for(let r=0;r<n&&o<i;r++){let i=e[(r+a)%n]??[0,0,0],s=t[r]??[0,0,0],c=i[0]-s[0],l=i[1]-s[1],u=i[2]-s[2];o+=c*c+l*l+u*u}o<i&&(i=o,r=a)}if(r===0)return e;let a=[];for(let t=0;t<n;t++)a.push(e[(t+r)%n]??[0,0,0]);return a}function Vx(e,t,n,r){if(t.length<2)throw Error(`manifold: loft requires at least two profiles`);let i=t.map(Ub),a=i.reduce((e,t)=>Math.max(e,t.outline.length),0),o=i.map(e=>Jb({...e,outline:qb(e.outline,a)},Ox(e)));for(let e=1;e<o.length;e++)o[e]=Bx(o[e]??[],o[e-1]??[]);return B(Yb(e,o),z(n,{sections:i.map(Dx),...r},t.map(e=>H(Sx(e)))))}function Hx(e,t,n,r,i,a,o){let s=Ub(t),c=Qb(n,s.xAxis),l=c.length;return B(Yb(e,c.map((e,t)=>Jb(s,e,o?o(l>1?t/(l-1):0):1))),z(i,{section:Dx(s),path:n.map(e=>[e[0],e[1],e[2]]),...a},[H(Sx(t)),r]))}function Ux(e,t,n,r,i,a){if(r===null)return t;let o=Ub(n),s=Ib(jb(o.xAxis,o.yAxis)),c=Math.tan(i*xx),l={origin:Nb(o.origin,Pb(s,r)),xAxis:o.xAxis,yAxis:o.yAxis,tangent:s},u=1+c*r/kx(o),d=Yb(e,[Jb(o,Ox(o),1),Jb(o,l,u)]),f=z(`draftPrism`,{outline:o.outline,origin:o.origin,xAxis:o.xAxis,yAxis:o.yAxis,height:r,angleDeg:i,fuse:a},[H(Sx(n))]);if(a){let e=Sx(t);return B(V(e).add(d),z(`makeFuse`,{},[H(e),f]))}return B(d,f)}function Wx(e){return{revolve:(t,n,r)=>{let i=Tx(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 zx(e,t,a,o,r,`revolve`,{...Dx(Ub(t)),axisOrigin:[a[0],a[1],a[2]],axisDirection:[o[0],o[1],o[2]],angleDeg:Cx(r)})},revolveVec:(t,n,r,i)=>zx(e,t,n,r,i,`revolveVec`,{...Dx(Ub(t)),center:[n[0],n[1],n[2]],direction:[r[0],r[1],r[2]],angleDeg:Cx(i)})}}function Gx(e){return{sweep:(t,n,r)=>{let i={};return r?.transitionMode!==void 0&&(i.transitionMode=r.transitionMode),Hx(e,t,jx(n,16),Mx(n),`sweep`,i)},simplePipe:(t,n)=>Hx(e,t,jx(n,16),Mx(n),`simplePipe`,{}),sweepWithOptions:(t,n,r,i,a)=>Hx(e,t,jx(n,Math.max(2,a||16)),Mx(n),`sweepWithOptions`,{contactMode:r,scaleValues:[...i],segments:a},Lx(i)),sweepPipeShell:(t,n,r)=>{let i={};r?.transitionMode!==void 0&&(i.transitionMode=r.transitionMode);let a=Hx(e,t,jx(n,16),Mx(n),`sweepPipeShell`,i);return r?.shellMode?{shape:a,firstShape:t,lastShape:t}:a},helicalSweep:(t,n,r,i,a,o)=>Hx(e,t,Ix(n,r,i,a,o),Mx(t),`helicalSweep`,{axisOrigin:[n[0],n[1],n[2]],axisDirection:[r[0],r[1],r[2]],radius:i,pitch:a,turns:o})}}function Kx(e){return{extrude:(t,n,r)=>Rx(e,t,n,r),...Wx(e),loft:(t,n)=>Vx(e,t,`loft`,{ruled:n??!1}),loftAdvanced:(t,n)=>Vx(e,t,`loftAdvanced`,{solid:n?.solid??!0,ruled:n?.ruled??!1,tolerance:n?.tolerance}),...Gx(e),draftPrism:(t,n,r,i,a,o)=>Ux(e,t,n,i,a,o),buildExtrusionLaw:(e,t,n)=>({type:`extrusionLaw`,profile:e,length:t,endFactor:n}),loftBatch:()=>Dy(`loftBatch`),extrudeBatch:t=>t.map(t=>Rx(e,t.face,t.direction,t.length))}}var qx=16;function Jx(e){return typeof e?.translate==`function`?e.translate([0,0,0]):e}function Yx(e,t,n){if(!(n>0))return Jx(t);let r=Qx(e,n);return r===void 0||typeof t?.minkowskiDifference!=`function`||typeof t?.minkowskiSum!=`function`?Jx(t):t.minkowskiDifference(r).minkowskiSum(r)}function Xx(e,t,n){if(n===0)return Jx(t);let r=Qx(e,Math.abs(n));return r===void 0?Jx(t):n>0?typeof t?.minkowskiSum==`function`?t.minkowskiSum(r):Jx(t):typeof t?.minkowskiDifference==`function`?t.minkowskiDifference(r):Jx(t)}function Zx(e,t,n,r){if(n===0)return Jx(t);if(r)return Xx(e,t,Math.abs(n));let i=Xx(e,t,-Math.abs(n));return typeof t?.subtract==`function`?t.subtract(i):Jx(t)}function Qx(e,t){let n=e?.Manifold;if(typeof n?.sphere==`function`)return n.sphere(t,qx)}function $x(e){return e}function eS(e){let t=e;if(t!=null){if(typeof t.index==`number`)return t.index;if(typeof t.id==`number`)return t.id}}function tS(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 nS(e){let t=e;if(t?.box!==void 0)return tS(t.box);let n=(e?.manifold)?.boundingBox?.();return n===void 0?void 0:tS(n)}function rS(e){let t=e.length;if(t===0)return{kind:`all`,count:t};let n=[];for(let t of e){let e=nS(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=eS(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 iS(e){return typeof e==`function`&&Dy(`fillet (per-edge radius callback)`),e}function aS(e){return typeof e==`number`?e:e[0]}function oS(e){let t=e.match(/[-+]?\d*\.?\d+/);return t?Number(t[0]):0}function sS(e,t,n,r,i){let a=$x(n),o=iS(i),s=rS(r);return B(Yx(e,V(a),aS(o)),z(t,{radius:o,selection:s},[H(a)]))}function cS(e,t,n,r,i){let a=$x(t),o=rS(n);return B(Yx(e,V(a),r),z(`chamferDistAngle`,{distance:r,angleDeg:i,selection:o},[H(a)]))}function lS(e,t,n){let r=t.node;if(r?.op!==`extrude`)return;let i=r.params??{},a=i.outline,o=i.origin,s=i.direction,c=i.length;if(!a||a.length<3||!o||!s||typeof c!=`number`)return;let l=Math.abs(n);try{let n=new e.CrossSection([a.map(e=>[e[0],e[1]])]).offset(-l);if(typeof n.isEmpty==`function`&&n.isEmpty())return;let r=e.Manifold.extrude(n,c),i=Math.hypot(s[0],s[1],s[2])||1,u=Math.abs(s[0])<1e-9&&Math.abs(s[1])<1e-9&&s[2]>0,d=r;if(!u){let e=Math.atan2(Math.hypot(s[0],s[1]),s[2])*(180/Math.PI),t=Math.atan2(s[1],s[0])*(180/Math.PI);d=d.rotate([0,e,t])}return d=d.translate([o[0]+s[0]/i*l,o[1]+s[1]/i*l,o[2]+s[2]/i*l]),Xb(e,V(t).subtract(d))}catch{return}}function uS(e,t,n,r,i){let a=$x(t),o=rS(n);return B(lS(e,a,r)??Zx(e,V(a),r,!1),z(`shell`,i===void 0?{thickness:r,selection:o}:{thickness:r,selection:o,tolerance:i},[H(a)]))}function dS(e,t,n){let r=$x(t);return B(Zx(e,V(r),n,!0),z(`thicken`,{thickness:n},[H(r)]))}function fS(e,t,n,r){let i=$x(t);return B(Xx(e,V(i),n),z(`offset`,r===void 0?{distance:n}:{distance:n,tolerance:r},[H(i)]))}function pS(e,t,n){let r=$x(t);return B(Yx(e,V(r),oS(n)),z(`filletVariable`,{spec:n},[H(r)]))}function mS(e,t,n,r,i){typeof i==`function`&&Dy(`draft (per-face angle callback)`);let a=$x(e),o=rS(t);return B(Jx(V(a)),z(`draft`,{pullDirection:n,neutralPlane:r,angleDeg:i,selection:o},[H(a)]))}function hS(e,t){let n=$x(e),r=rS(t);return B(Jx(V(n)),z(`defeature`,{selection:r},[H(n)]))}function gS(e){let t=$x(e),n=V(t);return B(typeof n?.simplify==`function`?n.simplify():Jx(n),z(`simplify`,{},[H(t)]))}function _S(e){let t=$x(e),n=V(t);return B(typeof n?.mirror==`function`?n.mirror([1,0,0]):Jx(n),z(`reverseShape`,{},[H(t)]))}function vS(e,t){let n=$x(t.shape),r=rS(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 B(Yx(e,V(n),a),z(`fillet`,{radii:i,selection:r},[H(n)]))}function yS(e){return{fillet:(t,n,r)=>sS(e,`fillet`,t,n,r),chamfer:(t,n,r)=>sS(e,`chamfer`,t,n,r),chamferDistAngle:(t,n,r,i)=>cS(e,t,n,r,i),shell:(t,n,r,i)=>uS(e,t,n,r,i),thicken:(t,n)=>dS(e,t,n),offset:(t,n,r)=>fS(e,t,n,r),filletVariable:(t,n)=>pS(e,t,n),draft:(e,t,n,r,i)=>mS(e,t,n,r,i),defeature:(e,t)=>hS(e,t),offsetWire2D:()=>Dy(`offsetWire2D`),simplify:e=>gS(e),reverseShape:e=>_S(e),shellBatch:t=>t.map(t=>uS(e,t.shape,t.faces,t.thickness,t.tolerance)),filletBatch:t=>t.map(t=>vS(e,t))}}function bS(e){return V(e).getMesh()}function xS(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 SS(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 CS(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 wS(e,t){let n=bS(e),r=xS(n),i=new Uint32Array(n.triVerts);return{vertices:r,normals:t.skipNormals?new Float32Array:SS(r,i),triangles:i,uvs:t.includeUVs?new Float32Array(r.length/3*2):new Float32Array,faceGroups:CS(n)}}function TS(e,t,n){let r=bS(e),i=xS(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 ES(e){return!0}function DS(e){return{mesh:(e,t)=>wS(e,t),meshEdges:(e,t,n)=>TS(e,t,n),hasTriangulation:e=>ES(e),meshShape:(e,t,n)=>{}}}function OS(e,t=[0,0,0]){return Array.isArray(e)&&e.length>=3?[Number(e[0]),Number(e[1]),Number(e[2])]:[...t]}function kS(e,t=0){return typeof e==`number`?e:t}function AS(e,t=``){return typeof e==`string`?e:t}function jS(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function MS(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function NS(e,t,n,r){return jS(t,jS(MS(n,e[0]),MS(r,e[1])))}function PS(e,t){let n=t.outline??[];if(n.length<3)throw Error(`manifold replay: profile outline needs at least three points`);let r=OS(t.origin),i=OS(t.xAxis,[1,0,0]),a=OS(t.yAxis,[0,1,0]),o=n.map(e=>NS(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 FS(e,t){return PS(e,t)}function IS(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 LS(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 RS(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=>IS(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=LS(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(IS(e,t)))}function zS(e){let t=e.selection;return t===void 0?void 0:t}function BS(e){let t=e[0];if(t===void 0)throw Error(`manifold replay: op requires an input shape`);return t}function VS(e,t,n){return e.createAxis1(t[0],t[1],t[2],n[0],n[1],n[2])}function HS(e,t){return(n,r)=>{let i=PS(n,r),a=OS(r[e]),o=OS(r[t],[0,0,1]),s=kS(r.angleDeg,360);return n.revolve(i,VS(n,a,o),Math.PI/180*s)}}var US={makeBox:(e,t)=>e.makeBox(kS(t.width),kS(t.height),kS(t.depth)),makeBoxWithCorners:(e,t)=>e.makeBoxFromCorners(OS(t.p1),OS(t.p2)),makeCylinder:(e,t)=>e.makeCylinder(kS(t.radius),kS(t.height),OS(t.center),OS(t.direction,[0,0,1])),makeSphere:(e,t)=>e.makeSphere(kS(t.radius),OS(t.center)),makeCone:(e,t)=>e.makeCone(kS(t.radius1),kS(t.radius2),kS(t.height),OS(t.center),OS(t.direction,[0,0,1])),makeTorus:(e,t)=>e.makeTorus(kS(t.majorRadius),kS(t.minorRadius),OS(t.center),OS(t.direction,[0,0,1])),makeEllipsoid:(e,t)=>e.makeEllipsoid(kS(t.aLength),kS(t.bLength),kS(t.cLength)),makeFuse:(e,t,n)=>{if(n.length<2)return BS(n);let r=BS(n);for(let t of n.slice(1))r=e.fuse(r,t);return r},makeCut:(e,t,n)=>{let r=BS(n);return e.cutAll(r,n.slice(1))},makeCommon:(e,t,n)=>{let r=BS(n);for(let t of n.slice(1))r=e.intersect(r,t);return r},translateShape:(e,t,n)=>e.translate(BS(n),kS(t.x),kS(t.y),kS(t.z)),rotateShape:(e,t,n)=>e.rotate(BS(n),kS(t.angle),OS(t.axis,[0,0,1]),OS(t.center)),scaleShape:(e,t,n)=>e.scale(BS(n),OS(t.center),kS(t.factor,1)),mirrorShape:(e,t,n)=>e.mirror(BS(n),OS(t.origin),OS(t.normal,[1,0,0])),transformShape:(e,t,n)=>e.transform(BS(n),t.matrix),generalTransform:(e,t,n)=>e.generalTransform(BS(n),t.linear,OS(t.translation),!!t.isOrthogonal),generalTransformNonOrthogonal:(e,t,n)=>e.generalTransformNonOrthogonal(BS(n),t.linear,OS(t.translation)),gridPattern:(e,t,n)=>{if(typeof e.gridPattern!=`function`)throw Error(`manifold replay: target kernel lacks gridPattern`);return e.gridPattern(BS(n),OS(t.directionX),OS(t.directionY),kS(t.spacingX),kS(t.spacingY),kS(t.countX,1),kS(t.countY,1))},profileEdge:(e,t)=>{let n=t.pts??[],r=n[0]??[0,0,0],i=n.length>1?n[n.length-1]??r:[r[0]+.001,r[1],r[2]];return e.makeLineEdge([r[0],r[1],r[2]],[i[0],i[1],i[2]])},profileWire:(e,t)=>{let n=t.ring??[],r=[];for(let t=0;t<n.length;t++){let i=n[t]??[0,0,0],a=n[(t+1)%n.length]??i;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},profileFace:(e,t)=>PS(e,t),extrude:(e,t)=>{let n=PS(e,t);return e.extrude(n,OS(t.direction,[0,0,1]),kS(t.length,1))},revolve:HS(`axisOrigin`,`axisDirection`),revolveVec:HS(`center`,`direction`),loft:(e,t)=>{let n=(t.sections??[]).map(t=>WS(e,t));return e.loft(n,!!t.ruled)},loftAdvanced:(e,t)=>{let n=(t.sections??[]).map(t=>WS(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(GS(e,t),KS(e,t)),simplePipe:(e,t)=>e.simplePipe(GS(e,t),KS(e,t)),sweepWithOptions:(e,t)=>e.sweepWithOptions(GS(e,t),KS(e,t),AS(t.contactMode),t.scaleValues??[],kS(t.segments,0)),sweepPipeShell:(e,t)=>{let n=e.sweepPipeShell(GS(e,t),KS(e,t));return qS(n)?n.shape:n},helicalSweep:(e,t)=>e.helicalSweep(GS(e,t),OS(t.axisOrigin),OS(t.axisDirection,[0,0,1]),kS(t.radius),kS(t.pitch),kS(t.turns,1)),draftPrism:(e,t)=>{let n=PS(e,t);return e.draftPrism(n,n,n,kS(t.height),kS(t.angleDeg),!!t.fuse)},fillet:(e,t,n)=>{let r=BS(n),i=RS(e,r,zS(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=BS(n),i=RS(e,r,zS(t),`edge`);return e.chamfer(r,i,t.radius)},chamferDistAngle:(e,t,n)=>{let r=BS(n),i=RS(e,r,zS(t),`edge`);return e.chamferDistAngle(r,i,kS(t.distance),kS(t.angleDeg))},shell:(e,t,n)=>{let r=BS(n),i=RS(e,r,zS(t),`face`);return typeof t.tolerance==`number`?e.shell(r,i,kS(t.thickness),t.tolerance):e.shell(r,i,kS(t.thickness))},thicken:(e,t,n)=>e.thicken(BS(n),kS(t.thickness)),offset:(e,t,n)=>typeof t.tolerance==`number`?e.offset(BS(n),kS(t.distance),t.tolerance):e.offset(BS(n),kS(t.distance)),filletVariable:(e,t,n)=>e.filletVariable(BS(n),AS(t.spec)),draft:(e,t,n)=>{let r=BS(n),i=RS(e,r,zS(t),`face`);return e.draft(r,i,OS(t.pullDirection,[0,0,1]),OS(t.neutralPlane),kS(t.angleDeg))},defeature:(e,t,n)=>{let r=BS(n),i=RS(e,r,zS(t),`face`);return e.defeature(r,i)},simplify:(e,t,n)=>e.simplify(BS(n)),reverseShape:(e,t,n)=>e.reverseShape(BS(n)),hull:(e,t,n)=>e.hull([...n],kS(t.tolerance)),hullFromPoints:(e,t)=>{let n=t.points??[];return e.hullFromPoints(n.map(e=>({x:e[0],y:e[1],z:e[2]})),kS(t.tolerance))},sewAndSolidify:(e,t,n)=>e.sewAndSolidify([...n],kS(t.tolerance))};function WS(e,t){let n=FS(e,t);return e.iterShapes(n,`wire`)[0]??n}function GS(e,t){let n=t.section;return n?FS(e,n):PS(e,t)}function KS(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 qS(e){return typeof e==`object`&&!!e&&`shape`in e&&`firstShape`in e&&`lastShape`in e}function JS(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=US[e.op];if(!a)throw Error(`manifold replay: no replay handler for op '${e.op}'`);let o=e.inputs.map(e=>JS(e,t,n,r)),s=a(t,e.params,o);return n.set(e,s),r.add(s),s}function YS(e,t,n=new Map){let r=new Set,i=JS(e,t,n,r);for(let e of r)e!==i&&t.dispose(e);return i}function XS(e){return V(e)}function ZS(e){let t=e?.node?.params;if(!t)return;let n=t.pts??t.ring;if(n&&n.length)return n;let r=t.outline;if(r&&r.length){let e=t.origin??[0,0,0],n=t.xAxis??[1,0,0],i=t.yAxis??[0,1,0];return r.map(t=>[e[0]+n[0]*t[0]+i[0]*t[1],e[1]+n[1]*t[0]+i[1]*t[1],e[2]+n[2]*t[0]+i[2]*t[1]])}}function QS(e){let t=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0];for(let r of e)for(let e=0;e<3;e++){let i=r[e]??0;i<(t[e]??1/0)&&(t[e]=i),i>(n[e]??-1/0)&&(n[e]=i)}return{min:t,max:n}}function $S(e){let t=e;if(t&&t.__manifoldSub&&t.box)return t.box;let n=ZS(e);return n?QS(n):XS(e).boundingBox()}function eC(e){return XS(e)?.getMesh?.()}function tC(e,t){let n=t*e.numProp;return[e.vertProperties[n]??0,e.vertProperties[n+1]??0,e.vertProperties[n+2]??0]}function nC(e,t){let n=t*3;return[e.triVerts[n]??0,e.triVerts[n+1]??0,e.triVerts[n+2]??0]}function rC(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 iC(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function aC(e){let t=$S(e);return[(t.min[0]+t.max[0])/2,(t.min[1]+t.max[1])/2,(t.min[2]+t.max[2])/2]}function oC(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=tC(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 sC(e){let t=eC(e);if(!t)return aC(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]=nC(t,e),s=tC(t,n),c=tC(t,a),l=tC(t,o),u=iC(s,rC(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?oC(t):[i[0]/r,i[1]/r,i[2]/r]}function cC(e){let t=eC(e);if(!t)return aC(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]=nC(t,e),s=tC(t,n),c=tC(t,a),l=tC(t,o),u=rC([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?oC(t):[i[0]/r,i[1]/r,i[2]/r]}function lC(e){return XS(e).volume()}function uC(e){let t=e;return t&&t.__nativeFace&&typeof t.area==`number`?t.area:XS(e).surfaceArea()}function dC(e){let t=e;if(t&&t.__manifoldSub&&t.box)return{min:[...t.box.min],max:[...t.box.max]};let n=$S(e);return{min:[...n.min],max:[...n.max]}}function fC(e){return sC(e)}function pC(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 mC(e,t){return pC($S(e),$S(t))}function hC(e,t=!1){return{volume:lC(e),area:uC(e),length:0,centerOfMass:fC(e),boundingBox:dC(e)}}function gC(e,t,n){let r=My();if(!r)throw Error(`manifold: surfaceCurvature requires a registered occt kernel; none is available`);let i=Ay(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=Py.get(i.node)??(()=>{let e=YS(i.node,r);return Py.set(i.node,e),e})();return r.surfaceCurvature(a,t,n)}function _C(e){return{volume:e=>lC(e),area:e=>uC(e),length:e=>{let t=e;if(t&&t.__nativeEdge&&typeof t.length==`number`)return t.length;let n=Ay(e)?.node;return n?.op===`profileEdge`&&n.params?.curve?wb(n.params.curve):Dy(`length`)},centerOfMass:e=>fC(e),linearCenterOfMass:e=>fC(e),boundingBox:e=>dC(e),distance:(e,t)=>mC(e,t),surfaceCurvature:(e,t,n)=>gC(e,t,n),surfaceCenterOfMass:e=>cC(e),measureBulk:(e,t)=>hC(e,t),createDistanceQuery:e=>({distanceTo:t=>mC(e,t),dispose:()=>{}})}}function vC(e,t){let{runIndex:n,runOriginalID:r}=e;if(!n||!r)return 0;let i=t*3;for(let e=0;e<r.length;e++){let t=n[e]??0,a=n[e+1]??2**53-1;if(i>=t&&i<a)return r[e]??0}return 0}function yC(e){let t=e,n=t.triVerts,r=t.vertProperties,i=t.numProp||3,a=t.faceID,o=n.length/3,s=e=>{let t=e*i;return[r[t]??0,r[t+1]??0,r[t+2]??0]},c=new Map;for(let e=0;e<o;e++){let t=a?a[e]??e:e,n=c.get(t);n||(n=[],c.set(t,n)),n.push(e)}let l=[];for(let[e,r]of c){let i=0,a=0,o=0,c=0,u=0,d=0,f=0,p=1/0,m=1/0,h=1/0,g=-1/0,_=-1/0,v=-1/0,y=new Float32Array(r.length*9),b=0;for(let e of r){let t=s(n[e*3]??0),r=s(n[e*3+1]??0),l=s(n[e*3+2]??0),x=r[0]-t[0],S=r[1]-t[1],C=r[2]-t[2],w=l[0]-t[0],ee=l[1]-t[1],te=l[2]-t[2],ne=S*te-C*ee,re=C*w-x*te,ie=x*ee-S*w;i+=ne,a+=re,o+=ie;let ae=.5*Math.hypot(ne,re,ie);f+=ae;let oe=(t[0]+r[0]+l[0])/3,se=(t[1]+r[1]+l[1])/3,ce=(t[2]+r[2]+l[2])/3;c+=ae*oe,u+=ae*se,d+=ae*ce;for(let e of[t,r,l])e[0]<p&&(p=e[0]),e[1]<m&&(m=e[1]),e[2]<h&&(h=e[2]),e[0]>g&&(g=e[0]),e[1]>_&&(_=e[1]),e[2]>v&&(v=e[2]),y[b++]=e[0],y[b++]=e[1],y[b++]=e[2]}let x=Math.hypot(i,a,o)||1,S=[i/x,a/x,o/x],C=f>0?[c/f,u/f,d/f]:[0,0,0];l.push({__nativeFace:!0,faceId:e,originId:vC(t,r[0]??0),normal:S,center:C,area:f,min:[p,m,h],max:[g,_,v],tris:y})}return l}function bC(e){return!!e&&typeof e==`object`&&e.__nativeFace===!0}var xC=Math.cos(45*Math.PI/180),SC=(e,t)=>e<t?e*1e9+t:t*1e9+e,CC=(e,t)=>e<t?`${e},${t}`:`${t},${e}`;function wC(e){let t=e,n=t.triVerts,r=t.vertProperties,i=t.numProp||3,a=t.faceID,o=n.length/3;if(!a)return[];let s=e=>{let t=e*i;return[r[t]??0,r[t+1]??0,r[t+2]??0]},c=e=>{let t=s(n[e*3]??0),r=s(n[e*3+1]??0),i=s(n[e*3+2]??0),a=r[0]-t[0],o=r[1]-t[1],c=r[2]-t[2],l=i[0]-t[0],u=i[1]-t[1],d=i[2]-t[2],f=o*d-c*u,p=c*l-a*d,m=a*u-o*l,h=Math.hypot(f,p,m)||1;return[f/h,p/h,m/h]},l=new Map;for(let e=0;e<o;e++){let t=n[e*3]??0,r=n[e*3+1]??0,i=n[e*3+2]??0,o=a[e]??e,s=c(e);for(let[e,n]of[[t,r],[r,i],[i,t]]){let t=SC(e,n),r=l.get(t);r||(r={v:[e,n],faces:[],nrm:[]},l.set(t,r)),r.faces.push(o),r.nrm.push(s)}}let u=new Map;for(let{v:e,faces:t,nrm:n}of l.values()){if(t.length!==2)continue;let[r,i]=t;if(r===i)continue;let[a,o]=n;if(a[0]*o[0]+a[1]*o[1]+a[2]*o[2]>xC)continue;let s=CC(r,i),c=u.get(s);c||(c={faces:r<i?[r,i]:[i,r],segs:[]},u.set(s,c)),c.segs.push(e)}let d=[];for(let{faces:e,segs:t}of u.values())for(let n of TC(t))d.push(EC(e,n,s));return d}function TC(e){let t=new Map,n=new Set,r=(e,n)=>{let r=t.get(e);r||(r=[],t.set(e,r)),r.push(n)};e.forEach(([e,t],n)=>{r(e,n),r(t,n)});let i=(t,n)=>{let r=e[t]??[n,n];return r[0]===n?r[1]:r[0]},a=[];for(let r=0;r<e.length;r++){if(n.has(r))continue;n.add(r);let o=e[r]??[0,0],s=[o[0],o[1]];for(let r=0;r<e.length;r++){let e=s[s.length-1]??0,r=(t.get(e)??[]).find(e=>!n.has(e));if(r===void 0)break;n.add(r),s.push(i(r,e))}for(let r=0;r<e.length;r++){let e=s[0]??0,r=(t.get(e)??[]).find(e=>!n.has(e));if(r===void 0)break;n.add(r),s.unshift(i(r,e))}a.push(s)}return a}function EC(e,t,n){let r=t.length,i=new Float32Array(r*3),a=new Float32Array(r),o=1/0,s=1/0,c=1/0,l=-1/0,u=-1/0,d=-1/0,f=0,p=null;for(let e=0;e<r;e++){let r=n(t[e]??0);i[e*3]=r[0],i[e*3+1]=r[1],i[e*3+2]=r[2],p&&(f+=Math.hypot(r[0]-p[0],r[1]-p[1],r[2]-p[2])),a[e]=f,p=r,r[0]<o&&(o=r[0]),r[1]<s&&(s=r[1]),r[2]<c&&(c=r[2]),r[0]>l&&(l=r[0]),r[1]>u&&(u=r[1]),r[2]>d&&(d=r[2])}return{__nativeEdge:!0,faces:e,pts:i,arc:a,length:f,min:[o,s,c],max:[l,u,d],curveType:DC(i)?`LINE`:`CIRCLE`}}function DC(e){let t=e.length/3;if(t<=2)return!0;let n=e[0]??0,r=e[1]??0,i=e[2]??0,a=e[(t-1)*3]??0,o=e[(t-1)*3+1]??0,s=e[(t-1)*3+2]??0,c=a-n,l=o-r,u=s-i,d=Math.hypot(c,l,u)||1;c/=d,l/=d,u/=d;for(let a=1;a<t-1;a++){let t=(e[a*3]??0)-n,o=(e[a*3+1]??0)-r,s=(e[a*3+2]??0)-i,f=t*c+o*l+s*u,p=t-f*c,m=o-f*l,h=s-f*u;if(Math.hypot(p,m,h)>1e-6*Math.max(1,d))return!1}return!0}function OC(e){let t=e,n=t.triVerts,r=t.vertProperties,i=t.numProp||3,a=t.faceID;if(!a)return[];let o=n.length/3,s=new Map;for(let e=0;e<o;e++){let t=a[e]??e;for(let r=0;r<3;r++){let i=n[e*3+r]??0,a=s.get(i);a||(a=new Set,s.set(i,a)),a.add(t)}}let c=[];for(let[e,t]of s){if(t.size<3)continue;let n=e*i;c.push({__nativeVertex:!0,point:[r[n]??0,r[n+1]??0,r[n+2]??0]})}return c}function kC(e){return!!e&&typeof e==`object`&&e.__nativeVertex===!0}function AC(e){return!!e&&typeof e==`object`&&e.__nativeEdge===!0}function jC(e,t){let{pts:n,arc:r}=e,i=r.length;if(i===0)return[0,0,0];if(t<=0)return[n[0]??0,n[1]??0,n[2]??0];if(t>=e.length)return[n[(i-1)*3]??0,n[(i-1)*3+1]??0,n[(i-1)*3+2]??0];let a=1;for(;a<i&&(r[a]??0)<t;)a++;let o=r[a-1]??0,s=r[a]??o,c=s>o?(t-o)/(s-o):0,l=(a-1)*3,u=a*3;return[(n[l]??0)+((n[u]??0)-(n[l]??0))*c,(n[l+1]??0)+((n[u+1]??0)-(n[l+1]??0))*c,(n[l+2]??0)+((n[u+2]??0)-(n[l+2]??0))*c]}function MC(e,t){let{pts:n,arc:r}=e,i=r.length;if(i<2)return[1,0,0];let a=1;for(;a<i-1&&(r[a]??0)<t;)a++;let o=(a-1)*3,s=a*3,c=(n[s]??0)-(n[o]??0),l=(n[s+1]??0)-(n[o+1]??0),u=(n[s+2]??0)-(n[o+2]??0),d=Math.hypot(c,l,u)||1;return[c/d,l/d,u/d]}function NC(e,t){let n=Ay(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=Ny(t),i=Py.get(n.node);if(i!==void 0)return{occt:r,brep:i};let a=YS(n.node,r);return Py.set(n.node,a),{occt:r,brep:a}}function PC(e){if(Ay(e))return`solid`;let{occt:t,brep:n}=NC(e,`shapeType`);return t.shapeType(n)}function FC(e,t){let n=Ay(e),r=Ay(t);return!n||!r?!1:n.manifold===r.manifold}function IC(e,t){if(!Ay(e))return 0;let{occt:n,brep:r}=NC(e,`hashCode`);return n.hashCode(r,t)}function LC(e){let t=Ay(e);return t?!V(t):!0}function RC(e,t){let n=Ay(e);if(!n)return[];if(t===`solid`)return[e];if(t===`vertex`){let e=V(n);return e&&typeof e.getMesh==`function`?OC(e.getMesh()).map((e,t)=>({...e,__manifoldSub:!0,index:t,box:{min:e.point,max:e.point},parent:n.node,subType:`vertex`})):[]}if(t!==`edge`&&t!==`face`)return[];if(t===`face`){let e=V(n);if(e&&typeof e.getMesh==`function`)return yC(e.getMesh()).map((e,t)=>({...e,__manifoldSub:!0,index:t,box:{min:e.min,max:e.max},parent:n.node,subType:`face`}))}if(t===`edge`){let e=V(n);if(e&&typeof e.getMesh==`function`)return wC(e.getMesh()).map((e,t)=>({...e,__manifoldSub:!0,index:t,box:{min:e.min,max:e.max},parent:n.node,subType:`edge`}))}if(!n.node.replayable)return[];let r=My();if(!r)return[];let i=Py.get(n.node)??(()=>{let e=YS(n.node,r);return Py.set(n.node,e),e})();return r.iterShapes(i,t).map((e,i)=>({__manifoldSub:!0,index:i,box:r.boundingBox(e),occt:e,parent:n.node,subType:t}))}function zC(e){let{occt:t,brep:n}=NC(e,`edgeToFaceMap`);return t.edgeToFaceMap(n)}function BC(e,t){let{occt:n,brep:r}=NC(e,`adjacentFaces`);return n.adjacentFaces(r,t)}function VC(e){return{iterShapes:RC,iterShapeList:(e,t)=>{Ny(`iterShapeList`).iterShapeList(e,t)},shapeType:PC,isSame:FC,isEqual:FC,downcast:e=>e,hashCode:IC,isNull:LC,shapeOrientation:e=>`forward`,edgeToFaceMap:zC,sharedEdges:(e,t)=>Ny(`sharedEdges`).sharedEdges(e,t),adjacentFaces:BC,sew:()=>{throw Error(`manifold: sew is unsupported on the mesh kernel; use a B-rep kernel`)}}}function HC(e){return V(e).getMesh()}function UC(e){return e.numProp&&e.numProp>=3?e.numProp:3}function WC(e){return Math.floor(e.vertProperties.length/UC(e))}function GC(e,t){let n=t*UC(e);return[e.vertProperties[n]??0,e.vertProperties[n+1]??0,e.vertProperties[n+2]??0]}function KC(e,t){let n=t*3;return[e.triVerts[n]??0,e.triVerts[n+1]??0,e.triVerts[n+2]??0]}function qC(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 JC(e,t){let n=HC(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]=KC(n,e),s=GC(n,r),c=GC(n,a),l=GC(n,o),u=qC(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]=KC(n,e),o=GC(n,t),s=GC(n,r),c=GC(n,a),l=qC(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(`
|
|
7
|
+
`).buffer}function xr(e,t){return e.toBREP(E(t))}function Sr(e,t){return D(e,e.fromBREP(t))}function Cr(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 wr(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 Tr(e,t,n,r){if(n.length===0)return``;let i=Cr(e,t,n.map(e=>({shape:e.shape,name:e.name??``,color:e.color})));try{return wr(e,i)}finally{i.delete()}}function Er(e,t,n,r){return T(`vertex`,e.makeVertex(t,n,r))}function Dr(e,t){throw De(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=ke(t,n.map(E));try{return T(`wire`,e.makeWire(r))}finally{r.delete()}}function kr(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=ke(t,r);try{return T(`wire`,e.makeWire(i))}finally{i.delete()}}function Ar(e,t,n){return T(`face`,e.makeFace(E(t)))}function jr(e,t,n){return T(`edge`,e.makeLineEdge(t[0],t[1],t[2],n[0],n[1],n[2]))}function Mr(e,t,n,r){return T(`edge`,e.makeCircleEdge(t[0],t[1],t[2],n[0],n[1],n[2],r))}function Nr(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 Pr(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 Fr(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 Ir(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 Lr(e,t,n){let r=[];for(let e of n)r.push(e[0],e[1],e[2]);let i=je(t,r);try{return T(`edge`,e.makeBezierEdge(i))}finally{i.delete()}}function Rr(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 zr(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,f=e.makeHelixWire(o,s,c,l,u,d,t,n,r);return e.buildCurves3d(f),T(`wire`,f)}function Br(e,t,n){let r=ke(t,n.map(E));try{return T(`compound`,e.makeCompound(r))}finally{r.delete()}}function Vr(e,t){return T(`solid`,e.solidFromShell(E(t)))}function Hr(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=ke(t,a);try{let t=e.sewAndSolidify(o,i);return t=e.fixFaceOrientations(t),D(e,t)}finally{o.delete()}}function Ur(e,t){return T(`face`,e.makeNonPlanarFace(E(t)))}function Wr(e,t,n,r){let i=ke(t,r.map(E));try{return T(`face`,e.addHolesInFace(E(n),i))}finally{i.delete()}}function Gr(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=Ae(t,a);try{return T(`face`,e.removeHolesFromFace(E(n),o))}finally{o.delete()}}function Kr(e,t,n){let r=E(t);return T(`face`,e.makeFaceOnSurface(r,E(n)))}function qr(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 Jr(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=ke(t,a);try{return D(e,e.sewAndSolidify(o,.001))}finally{o.delete()}}function Yr(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 Xr(e,t,n,r){let i=ke(t,n.map(E));try{let t=e.sewAndSolidify(i,r);return t=e.fixFaceOrientations(t),T(`solid`,t)}finally{i.delete()}}function Zr(e,t,n){return{x:e,y:t,z:n,__type:`point3d`,delete:Ee}}function Qr(e,t,n){return{x:e,y:t,z:n,__type:`direction3d`,delete:Ee}}function $r(e,t,n){return{x:e,y:t,z:n,__type:`vector3d`,delete:Ee}}function ei(e,t,n,r,i,a){return{origin:{x:e,y:t,z:n},direction:{x:r,y:i,z:a},__type:`axis1`,delete:Ee}}function ti(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:Ee}}function ni(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:Ee}}function ri(e){return e}function ii(e){return e}function ai(e,t){return{x:e,y:t}}function oi(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 si(e,t){return{x:e,y:t}}function ci(e,t,n,r){return{px:e,py:t,dx:n,dy:r,delete(){}}}function li(e){return e}function ui(e,t,n,r){return ii(x(e,t,n,r))}function di(e,t,n,r){return ii(S(e,t,n,r))}function fi(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 ii(x(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=S(s,c,l,h);if(!h){let e=-u,t=-f;return t<e-1e-9&&(t+=2*Math.PI),ii({__bk2d:`trimmed`,basis:g,tStart:e,tEnd:t})}let _=f;return _<u-1e-9&&(_+=2*Math.PI),ii({__bk2d:`trimmed`,basis:g,tStart:u,tEnd:_})}function pi(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 ii(x(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,y=(e-p)/h,b=v*s+y*c>0,C=S(p,m,h,b);if(!b){let e=-g,t=-_;return t<e-1e-9&&(t+=2*Math.PI),ii({__bk2d:`trimmed`,basis:C,tStart:e,tEnd:t})}let w=_;return w<g-1e-9&&(w+=2*Math.PI),ii({__bk2d:`trimmed`,basis:C,tStart:g,tEnd:w})}function mi(e,t,n,r,i,a,o){return ii(C(e,t,n,r,i??1,a??0,o??!0))}function hi(e,t,n,r,i,a,o,s,c){return ii({...C(e,t,n,r,o??1,s??0,c??!0),__bk2d:`ellipse`,startAngle:i,endAngle:a})}function gi(e){return ii(w(e))}function _i(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),ii({__bk2d:`bspline`,poles:n,knots:a,multiplicities:o,degree:i,isPeriodic:!1})}function vi(e,t){return _(ri(e),t)}function yi(e,t){return{point:_(ri(e),t),tangent:v(ri(e),t)}}function bi(e){return y(ri(e))}function xi(e){let t=ri(e);for(;t.__bk2d===`trimmed`&&t.basis;)t=t.basis;return b(t)}function Si(e,t,n){return ii({__bk2d:`trimmed`,basis:ri(e),tStart:t,tEnd:n})}function Ci(e){return ii(JSON.parse(JSON.stringify(ri(e))))}function wi(e,t){let n=ri(e),r=y(n),i=[];for(let e=0;e<=20;e++){let a=r.first+(r.last-r.first)*e/20,[o,s]=_(n,a),[c,l]=v(n,a),u=Math.sqrt(c*c+l*l)||1;i.push([o-l/u*t,s+c/u*t])}return ii(w(i.length<=25?i:i.filter((e,t)=>t%2==0||t===i.length-1)))}function Ti(e,t,n){return ii(ee(ri(e),t,n))}function Ei(e,t,n,r){return ii(te(ri(e),t,n,r))}function Di(e,t,n,r){return ii(ne(ri(e),t,n,r))}function Oi(e,t,n){return ii(re(ri(e),t,n))}function ki(e,t,n,r,i){return ii(ie(ri(e),t,n,r,i))}function Ai(e,t,n,r,i,a){let o=Math.sqrt(r*r+i*i);if(o<1e-15)return e;let s=-i/o,c=r/o,l=a-1,u=1+l*s*s,d=l*s*c,f=l*c*s,p=1+l*c*c,m=t-u*t-d*n,h=n-f*t-p*n,g=ri(e),v=y(g),b=[];for(let e=0;e<=20;e++){let[t,n]=_(g,v.first+(v.last-v.first)*e/20);b.push([u*t+d*n+m,f*t+p*n+h])}return ii(w(b))}function ji(e,t,n,r,i,a){return Ai(e,t,n,r,i,a)}function Mi(){return{type:`identity2d`,delete(){}}}function Ni(e,t,n,r,i){return{type:`affinity2d`,axOriginX:e,axOriginY:t,axDirX:n,axDirY:r,ratio:i,delete(){}}}function Pi(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 Ii(e,t,n){return{type:`rotate2d`,angle:e,cx:t,cy:n,delete(){}}}function Li(e,t,n){return{type:`scale2d`,sx:e,sy:e,cx:t,cy:n,delete(){}}}function Ri(e,t,n){let r=e;r.dx=(Number(r.dx)||0)+t,r.dy=(Number(r.dy)||0)+n}function zi(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 Bi(e,t){let n=t;return n.type===`translate2d`?Ti(e,Number(n.dx)||0,Number(n.dy)||0):n.type===`rotate2d`?Ei(e,Number(n.angle)||0,Number(n.cx)||0,Number(n.cy)||0):n.type===`scale2d`?Di(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.axOriginX)||0,Number(n.axOriginY)||0,Number(n.axDirX)||0,Number(n.axDirY)||0,Number(n.ratio)||1):Number(n.dx)||Number(n.dy)?Ti(e,Number(n.dx)||0,Number(n.dy)||0):e}function Vi(e,t,n){let r=ae(ri(e),ri(t),n);return{points:r.points,segments:r.segments.map(e=>ii(e))}}function Hi(e,t,n){let r=ri(e),i=y(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]=_(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]=_(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 Ui(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]=_(ri(e),c);for(let e=0;e<=20;e++){let n=i+(a-i)*(e/20),[r,s]=_(ri(t),n),c=Math.sqrt((r-l)**2+(s-u)**2);c<o&&(o=c)}}return o}function Wi(e,t){let n=ri(e),r=y(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(_(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),ii({__bk2d:`bspline`,poles:a,knots:c,multiplicities:l,degree:o,isPeriodic:!1})}function Gi(e){let t=ri(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[ii(w(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=>ii(w(e)))}function Ki(){return ge()}function qi(e,t,n){_e(e,ri(t),n)}function Ji(e){return{xMin:e.xMin,yMin:e.yMin,xMax:e.xMax,yMax:e.yMax}}function Yi(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 Xi(e,t){return e.xMax<t.xMin||e.xMin>t.xMax||e.yMax<t.yMin||e.yMin>t.yMax}function Zi(e,t,n){return t<e.xMin||t>e.xMax||n<e.yMin||n>e.yMax}function Qi(e){let t=ri(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 $i(e){let t=ri(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 ea(e){let t=ri(e);for(;t.__bk2d===`trimmed`&&t.basis;)t=t.basis;return t.__bk2d===`bezier`&&Array.isArray(t.poles)?t.poles:null}function ta(e){let t=ri(e);for(;t.__bk2d===`trimmed`&&t.basis;)t=t.basis;return t.__bk2d===`bezier`&&Array.isArray(t.poles)?t.poles.length-1:null}function na(e){return me(ri(e))}function ra(e){return ii(he(e))}function ia(e,t){let n=y(ri(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(Si(e,a,o))}return i}function aa(e,t,n,r,i,a){let o=ri(n),[s,c,l]=r,[u,d,f]=i,[p,m,h]=a,g=d*h-f*m,v=f*p-u*h,b=u*m-d*p,x=(e,t)=>[s+e*p+t*g,c+e*m+t*v,l+e*h+t*b],S=o.__bk2d;if(S===`line`){let t=y(o),[n,r]=_(o,t.first),[i,a]=_(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]=_(o,0),[r,i]=_(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=y(o),[n,r]=_(o,t.first),[i,a]=_(o,(t.first+t.last)/2),[s,c]=_(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=y(o),[r,i]=_(o,n.first),[a,s]=_(o,(n.first+n.last)/2),[c,l]=_(o,n.last),p=x(r,i),m=x(a,s),h=x(c,l);return T(`edge`,e.makeArcEdge(p[0],p[1],p[2],m[0],m[1],m[2],h[0],h[1],h[2]))}let C=y(o),w=(C.last-C.first)/24,ee=[];for(let e=0;e<=24;e++){let[t,n]=_(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 oa(e,t,n,r){let i=ri(n),a=y(i),o=E(r),s=new t.VectorDouble;for(let t=0;t<=30;t++){let[n,r]=_(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 sa(e){return e}function ca(){return ii(x(0,0,1,0))}function la(e,t){e.buildCurves3d(E(t))}function ua(e,t,n,r){return T(`wire`,e.fixWireOnFace(E(t),E(n),r))}function da(e){try{let t=Me(e.modified),n=Me(e.generated),r=Me(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 fa(e,t,n,r,i,a,o,s){let c=Ae(t,o);try{let{id:t,evolution:o}=da(e.translateWithHistory(E(n),r,i,a,c,s));return{shape:D(e,t),evolution:o}}finally{c.delete()}}function pa(e,t,n,r,i,a,o,s){let c=o??[0,0,1],l=s??[0,0,0],u=Ae(t,i);try{let{id:t,evolution:i}=da(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 ma(e,t,n,r,i,a,o){let s=Ae(t,a);try{let{id:t,evolution:a}=da(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 ha(e,t,n,r,i,a,o){let s=Ae(t,a);try{let{id:t,evolution:a}=da(e.scaleWithHistory(E(n),r[0],r[1],r[2],i,s,o));return{shape:D(e,t),evolution:a}}finally{s.delete()}}function ga(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 _a(e,t,n,r,i,a,o){let s=Ae(t,i);try{let{id:t,evolution:i}=da(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 va(e,t,n,r,i,a,o){let s=Ae(t,i);try{let{id:t,evolution:i}=da(e.cutWithHistory(E(n),Re(e,r),s,a));return{shape:D(e,t),evolution:i,diagnostics:{hasErrors:!1,hasWarnings:!1,messages:[]}}}finally{s.delete()}}function ya(e,t,n,r,i,a,o){let s=Ae(t,i);try{let{id:t,evolution:i}=da(e.intersectWithHistory(E(n),Re(e,r),s,a));return{shape:D(e,t),evolution:i,diagnostics:{hasErrors:!1,hasWarnings:!1,messages:[]}}}finally{s.delete()}}function ba(e,t,n,r,i,a,o){let s=Pe(r,i),c=ke(t,r.map(E)),l=Ae(t,a);try{let{id:t,evolution:r}=da(e.filletWithHistory(E(n),c,s,l,o));return{shape:D(e,t),evolution:r}}finally{c.delete(),l.delete()}}function xa(e,t,n,r,i,a,o){let s=Pe(r,i),c=ke(t,r.map(E)),l=Ae(t,a);try{let{id:t,evolution:r}=da(e.chamferWithHistory(E(n),c,s,l,o));return{shape:D(e,t),evolution:r}}finally{c.delete(),l.delete()}}function Sa(e,t,n,r,i,a,o,s){let c=ke(t,r.map(E)),l=Ae(t,a);try{let{id:t,evolution:r}=da(e.shellWithHistory(E(n),c,i,s??.001,l,o));return{shape:D(e,t),evolution:r}}finally{c.delete(),l.delete()}}function Ca(e,t,n,r,i,a){let o=Ae(t,i);try{let{id:t,evolution:i}=da(e.thickenWithHistory(E(n),r,.001,o,a));return{shape:D(e,t),evolution:i}}finally{o.delete()}}function wa(e,t,n,r,i,a,o){let s=Ae(t,i);try{let{id:t,evolution:i}=da(e.offsetWithHistory(E(n),r,o??1e-6,s,a));return{shape:D(e,t),evolution:i}}finally{s.delete()}}function Ta(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 Ea(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 Da(e,t,n,r){if(n.length<4)throw Error(`hullFromPoints: need at least 4 points`);let{points:i,faces:a}=g(n,r);if(a.length<4)throw Error(`hullFromPoints: degenerate hull (fewer than 4 faces)`);return Hr(e,t,[...i],[...a],r)}function Oa(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 ka(e,t,n,r){if(n.length===0)throw Error(`hull: no shapes provided`);let i=Oa(e,t,n,r);if(i.length<4)throw Error(`hull: fewer than 4 vertices extracted from input shapes`);return Da(e,t,i,r)}function Aa(e){throw Error(`occt-wasm: ${e} is not yet implemented`)}var ja=class e{oc;kernelId=`occt-wasm`;capabilities=r;Module;k;owner;constructor(e,t,n){this.Module=e,this.k=Ie(t,e),this.oc=Le(e,this.k),this.owner=n}static fromKernel(t){return new e(t.getRawModule(),t.getRawKernel(),t)}get retainedKernelOwner(){return this.owner}dispose(e){De(e)?this.k.release(e.id):typeof e.delete==`function`&&e.delete()}executeBatch(e){Aa(`executeBatch`)}checkpoint(){Aa(`checkpoint`)}checkpointCount(){Aa(`checkpointCount`)}restoreCheckpoint(e){Aa(`restoreCheckpoint`)}discardCheckpoint(e){Aa(`discardCheckpoint`)}makeBox(e,t,n){return Je(this.k,e,t,n)}makeCylinder(e,t,n,r){return Ye(this.k,e,t,n,r)}makeSphere(e,t){return Xe(this.k,e,t)}makeCone(e,t,n,r,i){return Ze(this.k,e,t,n,r,i)}makeTorus(e,t,n,r){return Qe(this.k,e,t,n,r)}makeEllipsoid(e,t,n){return $e(this.k,e,t,n)}makeBoxFromCorners(e,t){return et(this.k,e,t)}makeRectangle(e,t){return tt(this.k,e,t)}fuse(e,t,n){return ze(this.k,e,t,n)}cut(e,t,n){return Be(this.k,e,t,n)}intersect(e,t,n){return Ve(this.k,e,t,n)}section(e,t,n){return He(this.k,e,t,n)}fuseAll(e,t){return Ue(this.k,this.Module,e,t)}cutAll(e,t,n){return We(this.k,this.Module,e,t,n)}split(e,t){return Ge(this.k,this.Module,e,t)}checkBoolean(e,t,n){return Ke(this.k,e,t,n)}meshBoolean(e,t,n,r,i,a){return qe(e,t,n,r,i,a)}makeVertex(e,t,n){return Er(this.k,e,t,n)}makeEdge(e,t,n){return Dr(this.k,e)}makeWire(e){return Or(this.k,this.Module,e)}makeFace(e,t){return Ar(this.k,e,t)}makeLineEdge(e,t){return jr(this.k,e,t)}makeCircleEdge(e,t,n){return Mr(this.k,e,t,n)}makeCircleArc(e,t,n,r,i){return Nr(this.k,e,t,n,r,i)}makeArcEdge(e,t,n){return Pr(this.k,e,t,n)}makeEllipseEdge(e,t,n,r,i){return Fr(this.k,e,t,n,r)}makeEllipseArc(e,t,n,r,i,a,o){return Ir(this.k,e,t,n,r,i,a)}makeBezierEdge(e){return Lr(this.k,this.Module,e)}makeTangentArc(e,t,n){return Rr(this.k,e,t,n)}makeHelixWire(e,t,n,r,i,a){return zr(this.k,e,t,n,r,i)}makeWireFromMixed(e){return kr(this.k,this.Module,e)}makeCompound(e){return Br(this.k,this.Module,e)}solidFromShell(e){return Vr(this.k,e)}hull(e,t){return ka(this.k,this.Module,e,t)}hullFromPoints(e,t){return Da(this.k,this.Module,e,t)}buildSolidFromFaces(e,t,n){return Hr(this.k,this.Module,e,t,n)}makeNonPlanarFace(e){return Ur(this.k,e)}addHolesInFace(e,t){return Wr(this.k,this.Module,e,t)}removeHolesFromFace(e){return Gr(this.k,this.Module,e)}makeFaceOnSurface(e,t){return Kr(this.k,e,t)}bsplineSurface(e,t,n){return qr(this.k,this.Module,e,t,n)}triangulatedSurface(e,t,n){return Jr(this.k,this.Module,e,t,n)}buildTriFace(e,t,n){return Yr(this.k,e,t,n)}sewAndSolidify(e,t){return Xr(this.k,this.Module,e,t)}createPoint3d(e,t,n){return Zr(e,t,n)}createDirection3d(e,t,n){return Qr(e,t,n)}createVector3d(e,t,n){return $r(e,t,n)}createAxis1(e,t,n,r,i,a){return ei(e,t,n,r,i,a)}createAxis2(e,t,n,r,i,a,o,s,c){return ti(e,t,n,r,i,a,o,s,c)}createAxis3(e,t,n,r,i,a,o,s,c){return ni(e,t,n,r,i,a,o,s,c)}extrude(e,t,n){return Hn(this.k,e,t,n)}revolve(e,t,n){return Un(this.k,e,t,n)}loft(e,t,n,r){return Wn(this.k,this.Module,e,t,n,r)}sweep(e,t,n){return Gn(this.k,e,t,n)}simplePipe(e,t){return Kn(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){Aa(`sweepWithOptions`)}sweepPipeShell(e,t,n){return qn(this.k,e,t,n)}loftAdvanced(e,t){return Jn(this.k,this.Module,e,t)}buildExtrusionLaw(e,t,n){return Yn(this.k,e,t,n)}revolveVec(e,t,n,r){return Xn(this.k,e,t,n,r)}draftPrism(e,t,n,r,i,a){return Zn(this.k,e,t,n,r,i,a)}fillet(e,t,n){return An(this.k,this.Module,e,t,n)}chamfer(e,t,n){return jn(this.k,this.Module,e,t,n)}chamferDistAngle(e,t,n,r){return Mn(this.k,this.Module,e,t,n,r)}shell(e,t,n,r){return Nn(this.k,this.Module,e,t,n,r)}thicken(e,t){return Pn(this.k,e,t)}offset(e,t,n){return Fn(this.k,e,t,n)}filletVariable(e,t){return In(this.k,e,t)}draft(e,t,n,r,i){return Ln(this.k,e,t,n,r,i)}defeature(e,t){return Rn(this.k,this.Module,e,t)}offsetWire2D(e,t,n){return zn(this.k,e,t,n)}simplify(e){return Bn(this.k,e)}reverseShape(e){return Vn(this.k,e)}composeTransform(e){return Qn(e)}transform(e,t){return $n(this.k,this.Module,e,t)}translate(e,t,n,r){return er(this.k,e,t,n,r)}rotate(e,t,n,r){return tr(this.k,e,t,n,r)}mirror(e,t,n){return nr(this.k,e,t,n)}scale(e,t,n){return rr(this.k,e,t,n)}generalTransform(e,t,n,r){return ir(this.k,this.Module,e,t,n,r)}generalTransformNonOrthogonal(e,t,n){return ir(this.k,this.Module,e,t,n,!1)}positionOnCurve(e,t,n){return ar(this.k,this.Module,e,t,n)}linearPattern(e,t,n,r){return or(this.k,e,t,n,r)}circularPattern(e,t,n,r,i){return sr(this.k,e,t,n,r,i)}transformBatch(e){return cr(this.k,e)}translateWithHistory(e,t,n,r,i,a){return fa(this.k,this.Module,e,t,n,r,i,a)}rotateWithHistory(e,t,n,r,i,a){return pa(this.k,this.Module,e,t,n,r,i,a)}mirrorWithHistory(e,t,n,r,i){return ma(this.k,this.Module,e,t,n,r,i)}scaleWithHistory(e,t,n,r,i){return ha(this.k,this.Module,e,t,n,r,i)}generalTransformWithHistory(e,t,n,r,i,a){return ga((e,t,n,r)=>this.generalTransform(e,t,n,r),e,t,n,r,i)}fuseWithHistory(e,t,n,r,i){return _a(this.k,this.Module,e,t,n,r,i)}cutWithHistory(e,t,n,r,i){return va(this.k,this.Module,e,t,n,r,i)}intersectWithHistory(e,t,n,r,i){return ya(this.k,this.Module,e,t,n,r,i)}filletWithHistory(e,t,n,r,i){return ba(this.k,this.Module,e,t,n,r,i)}chamferWithHistory(e,t,n,r,i){return xa(this.k,this.Module,e,t,n,r,i)}shellWithHistory(e,t,n,r,i,a){return Sa(this.k,this.Module,e,t,n,r,i,a)}thickenWithHistory(e,t,n,r){return Ca(this.k,this.Module,e,t,n,r)}offsetWithHistory(e,t,n,r,i){return wa(this.k,this.Module,e,t,n,r,i)}draftWithHistory(e,t,n,r,i,a,o){return Ta(this.k,e,t,n,i)}applyComposedTransformWithHistory(e,t,n,r){return Ea((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 Ct(this.k,this.Module,e,t)}meshEdges(e,t,n){return Tt(this.k,this.Module,e,t,n)}hasTriangulation(e){return Et(this.k,e)}meshShape(e,t,n){Dt(this.k,e,t,n)}exportSTEP(e){return dr(this.k,this.makeCompound.bind(this),e)}exportSTL(e,t,n,r){return fr(this.mesh.bind(this),e,t,n,r)}importSTEP(e){return pr(this.k,e)}importSTL(e){return mr(this.k,this.Module,e)}exportIGES(e){return hr(this.k,this.makeCompound.bind(this),e)}importIGES(e){return gr(this.k,e)}exportSTEPAssembly(e,t){return _r(this.k,this.Module,e,t)}export3MF(e,t){throw Error(`export3MF is only available with the brepkit kernel`)}exportGLB(e,t){return vr(this.mesh.bind(this),e,t)}exportOBJ(e,t){return yr(this.mesh.bind(this),e,t)}exportPLY(e,t){return br(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 xr(this.k,e)}fromBREP(e){return Sr(this.k,e)}createXCAFDocument(e){return Cr(this.k,this.Module,e)}writeXCAFToSTEP(e,t){return wr(this.k,e,t)}exportSTEPConfigured(e,t){return Tr(this.k,this.Module,e,t)}volume(e){return dn(this.k,e)}area(e){return fn(this.k,e)}length(e){return pn(this.k,e)}centerOfMass(e){return mn(this.k,e)}linearCenterOfMass(e){return hn(this.k,e)}boundingBox(e){return gn(this.k,e)}distance(e,t){return Sn(this.k,this.Module,e,t)}surfaceCurvature(e,t,n){return kn(this.k,e,t,n)}surfaceCenterOfMass(e){return _n(this.k,e)}measureBulk(e,t){return vn(this.k,e,t)}createDistanceQuery(e){return yn(this.k,e)}iterShapes(e,t){return nt(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 rt(this.k,e)}isSame(e,t){return it(this.k,e,t)}isEqual(e,t){return at(this.k,e,t)}downcast(e,t){return ot(this.k,e,t)}hashCode(e,t){return st(this.k,e,t)}isNull(e){return ct(this.k,e)}shapeOrientation(e){return lt(this.k,e)}edgeToFaceMap(e){return ut(this.k,e)}sharedEdges(e,t){return dt(this.k,e,t)}adjacentFaces(e,t){return ft(this.k,e,t)}sew(e,t){return pt(this.k,this.Module,e,t)}curveType(e){return kt(this.k,e)}curveParameters(e){return At(this.k,e)}curvePointAtParam(e,t){return jt(this.k,e,t)}curveTangent(e,t){return Mt(this.k,e,t)}curveIsClosed(e){return Nt(this.k,e)}curveIsPeriodic(e){return Pt(this.k,e)}curvePeriod(e){return Ft(this.k,e)}interpolatePoints(e,t){return It(this.k,this.Module,e,t)}approximatePoints(e,t){return Lt(this.k,this.Module,e,t)}curveDegreeElevate(e,t){return Rt(this.k,e,t)}curveKnotInsert(e,t,n){return zt(this.k,e,t,n)}curveKnotRemove(e,t,n){return Bt(this.k,e,t,n)}curveSplit(e,t){return Vt(this.k,e,t)}getBezierPenultimatePole(e){return Ht(this.k,e)}createCurveAdaptor(e){Aa(`createCurveAdaptor`)}vertexPosition(e){return Wt(this.k,e)}surfaceType(e){return Gt(this.k,e)}uvBounds(e){return Kt(this.k,e)}outerWire(e){return qt(this.k,e)}surfaceNormal(e,t,n){return Jt(this.k,e,t,n)}pointOnSurface(e,t,n){return Yt(this.k,e,t,n)}uvFromPoint(e,t){return sn(this.k,e,t)}projectPointOnFace(e,t){return cn(this.k,e,t)}classifyPointOnFace(e,t,n,r){return ln(this.k,e,t,n,r)}classifyPointRobust(e,t,n){Aa(`classifyPointRobust`)}classifyPointWinding(e,t,n){Aa(`classifyPointWinding`)}approximateSurfaceLspia(e,t,n,r,i,a,o,s,c){Aa(`approximateSurfaceLspia`)}untrimFace(e,t,n){Aa(`untrimFace`)}getSurfaceCylinderData(e){return on(this.k,e)}getSurfaceAxis(e){return an(this.k,e)}reverseSurfaceU(e){Aa(`reverseSurfaceU`)}detectSmallFeatures(e,t,n){Aa(`detectSmallFeatures`)}recognizeFeatures(e,t){Aa(`recognizeFeatures`)}projectEdges(e,t,n,r){return un(this.k,this.Module,e,t,n,r)}isValid(e){return ht(this.k,e)}healSolid(e){return gt(this.k,e)}healFace(e){return _t(this.k,e)}healWire(e,t){return vt(this.k,e,t)}mergeCoincidentVertices(e,t){return yt(this.k,e,t)}removeDegenerateEdges(e,t){return bt(this.k,e,t)}fixFaceOrientations(e){return xt(this.k,e)}fixShape(e){return St(this.k,e)}fixSelfIntersection(e){Aa(`fixSelfIntersection`)}createPoint2d(e,t){return ai(e,t)}createDirection2d(e,t){return oi(e,t)}createVector2d(e,t){return si(e,t)}createAxis2d(e,t,n,r){return ci(e,t,n,r)}wrapCurve2dHandle(e){return li(e)}createCurve2dAdaptor(e){Aa(`createCurve2dAdaptor`)}makeLine2d(e,t,n,r){return ui(e,t,n,r)}makeCircle2d(e,t,n,r){return di(e,t,n,r)}makeArc2dThreePoints(e,t,n,r,i,a){return fi(e,t,n,r,i,a)}makeArc2dTangent(e,t,n,r,i,a){return pi(e,t,n,r,i,a)}makeEllipse2d(e,t,n,r,i,a,o){return mi(e,t,n,r,i,a,o)}makeEllipseArc2d(e,t,n,r,i,a,o,s,c){return hi(e,t,n,r,i,a,o,s,c)}makeBezier2d(e){return gi(e)}makeBSpline2d(e,t){return _i(e)}evaluateCurve2d(e,t){return vi(e,t)}evaluateCurve2dD1(e,t){return yi(e,t)}getCurve2dBounds(e){return bi(e)}getCurve2dType(e){return xi(e)}trimCurve2d(e,t,n){return Si(e,t,n)}reverseCurve2d(e){}copyCurve2d(e){return Ci(e)}offsetCurve2d(e,t){return wi(e,t)}translateCurve2d(e,t,n){return Ti(e,t,n)}rotateCurve2d(e,t,n,r){return Ei(e,t,n,r)}scaleCurve2d(e,t,n,r){return Di(e,t,n,r)}mirrorCurve2dAtPoint(e,t,n){return Oi(e,t,n)}mirrorCurve2dAcrossAxis(e,t,n,r,i){return ki(e,t,n,r,i)}affinityTransform2d(e,t,n,r,i,a){return ji(e,t,n,r,i,a)}createIdentityGTrsf2d(){return Mi()}createAffinityGTrsf2d(e,t,n,r,i){return Ni(e,t,n,r,i)}createTranslationGTrsf2d(e,t){return Pi(e,t)}createMirrorGTrsf2d(e,t,n,r,i,a,o){return Fi(e,t,n,r,i,a,o)}createRotationGTrsf2d(e,t,n){return Ii(e,t,n)}createScaleGTrsf2d(e,t,n){return Li(e,t,n)}setGTrsf2dTranslationPart(e,t,n){Ri(e,t,n)}multiplyGTrsf2d(e,t){zi(e,t)}transformCurve2dGeneral(e,t){return Bi(e,t)}intersectCurves2d(e,t,n){return Vi(e,t,n)}projectPointOnCurve2d(e,t,n){return Hi(e,t,n)}distanceBetweenCurves2d(e,t,n,r,i,a){return Ui(e,t,n,r,i,a)}approximateCurve2dAsBSpline(e,t,n,r){return Wi(e,r)}decomposeBSpline2dToBeziers(e){return Gi(e)}createBoundingBox2d(){return Ki()}addCurveToBBox2d(e,t,n){qi(e,t,n)}getBBox2dBounds(e){return Ji(e)}mergeBBox2d(e,t){Yi(e,t)}isBBox2dOut(e,t){return Xi(e,t)}isBBox2dOutPoint(e,t,n){return Zi(e,t,n)}getCurve2dCircleData(e){return Qi(e)}getCurve2dEllipseData(e){return $i(e)}getCurve2dBezierPoles(e){return ea(e)}getCurve2dBezierDegree(e){return ta(e)}getCurve2dBSplineData(e){Aa(`getCurve2dBSplineData`)}serializeCurve2d(e){return na(e)}deserializeCurve2d(e){return ra(e)}splitCurve2d(e,t){return ia(e,t)}liftCurve2dToPlane(e,t,n,r){return aa(this.k,this.Module,e,t,n,r)}buildEdgeOnSurface(e,t){return oa(this.k,this.Module,e,t)}extractSurfaceFromFace(e){return sa(e)}extractCurve2dFromEdge(e,t){return ca()}buildCurves3d(e){la(this.k,e)}fixWireOnFace(e,t,n){return ua(this.k,e,t,n)}fillSurface(e,t){Aa(`fillSurface`)}getNurbsCurveData(e){return Ut(this.k,e)}};function O(e){return{ok:!0,value:e}}function k(e){return{ok:!1,error:e}}var Ma=O(void 0);function Na(e){return e.ok}function A(e){return!e.ok}function Pa(e,t){return e.ok?O(t(e.value)):e}function Fa(e,t){return e.ok?e:k(t(e.error))}function Ia(e,t){return e.ok?t(e.value):e}var La=Ia;function Ra(e,t){return e.ok?e:t}function za(e,t){return e.ok?e:t(e.error)}function Ba(e,t){return e.ok?t.ok?O([e.value,t.value]):t:e}var Va=Qa;function Ha(e,t){return e.ok&&t(e.value),e}function Ua(e,t){return e.ok||t(e.error),e}function Wa(e){return e.ok?e.value:e}function Ga(e,t,n){return e.ok?O(t(e.value)):k(n(e.error))}function Ka(e,t){return e==null?k(t()):O(e)}function qa(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: ${qa(e.error)}`)}function Ja(e,t){return e.ok?e.value:t}function Ya(e,t){return e.ok?e.value:t(e.error)}function Xa(e){if(!e.ok)return e.error;throw Error(`Called unwrapErr() on an Ok: ${String(e.value)}`)}function Za(e,t){return e.ok?t.ok(e.value):t.err(e.error)}function Qa(e){let t=[];for(let n of e){if(!n.ok)return n;t.push(n.value)}return O(t)}function $a(e,t){try{return O(e())}catch(e){return k(t(e))}}async function eo(e,t){try{return O(await e())}catch(e){return k(t(e))}}function to(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 no=class extends Error{location;constructor(e,t){super(`Bug in ${e}: ${t}`),this.name=`BrepBugError`,this.location=e}};function M(e,t){throw new no(e,t)}var ro=[{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.`}],io={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 ao(e){return io[e]}function oo(e){for(let{pattern:t,translation:n}of ro)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 so(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 so(`KERNEL_OPERATION`,e,t,n,r,i)}function F(e,t,n,r,i){return so(`VALIDATION`,e,t,n,r,i)}function co(e,t,n,r,i){return so(`TYPE_CAST`,e,t,n,r,i)}function lo(e,t,n,r,i){return so(`SKETCHER_STATE`,e,t,n,r,i)}function uo(e,t,n,r,i){return so(`MODULE_INIT`,e,t,n,r,i)}function I(e,t,n,r,i){return so(`COMPUTATION`,e,t,n,r,i)}function fo(e,t,n,r,i){return so(`IO`,e,t,n,r,i)}function po(e,t,n,r,i){return so(`QUERY`,e,t,n,r,i)}function mo(e,t,n,r,i){return so(`UNSUPPORTED`,e,t,n,r,i)}function ho(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)}var go={draft:{tolerance:.01,angularTolerance:.5},standard:{tolerance:.001,angularTolerance:.1},fine:{tolerance:1e-4,angularTolerance:.05}},_o=`standard`;function vo(){return _o}function yo(e=_o){return go[e]}function bo(e){_o=e}function xo(e){return`makeLine2d`in e}var So=[`boolean`,`loft`,`extrude`,`shell`,`fillet`,`mesh`,`edgeMesh`,`transform`],Co=Object.create(null),wo=Object.create(null);function To(){for(let e of So)Co[e]=0,wo[e]=0}To();function Eo(e){let t=performance.now();return()=>{Co[e]=(Co[e]??0)+(performance.now()-t),wo[e]=(wo[e]??0)+1}}function Do(){let e={};for(let t of So)e[t]={totalMs:Co[t]??0,count:wo[t]??0};return e}function Oo(){To()}var ko;function Ao(){ko=void 0}function jo(e){return ko??=typeof e.BooleanBatch==`function`,ko}function Mo(e){return e===`commonFace`?1:e===`sameFace`?2:0}function No(e,t,n={}){if(!jo(e))return null;let r=Eo(`boolean`),i=new e.BooleanBatch;try{for(let e of t)i.addShape(e);return i.fuseAll(Mo(n.optimisation),!!n.simplify,n.fuzzyValue??0)}finally{i.delete(),r()}}function Po(e,t,n,r={}){if(!jo(e))return null;if(n.length===0)return t;let i=Eo(`boolean`),a=new e.BooleanBatch;try{for(let e of n)a.addShape(e);return a.cutAll(t,Mo(r.optimisation),!!r.simplify,r.fuzzyValue??0)}finally{a.delete(),i()}}var Fo=2147483647,Io;function Lo(){Io=void 0}function Ro(e){return Io??=typeof e.MeasurementExtractor?.extract==`function`,Io}function zo(e,t,n=!1){if(Ro(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:Bo(e,t),area:Vo(e,t),length:n?Ho(e,t):0,centerOfMass:Uo(e,t),boundingBox:Go(e,t)}}function Bo(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 Vo(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 Uo(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 Wo(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 Go(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 Ko(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 qo(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 Jo(e){return{volume:t=>Bo(e,t),area:t=>Vo(e,t),length:t=>Ho(e,t),centerOfMass:t=>Uo(e,t),linearCenterOfMass:t=>Wo(e,t),boundingBox:t=>Go(e,t),distance:(t,n)=>Ko(e,t,n),classifyPointOnFace:(t,n,r,i)=>qo(e,t,n,r,i),measureBulk:(t,n)=>zo(e,t,n)}}var Yo={vertex:7,edge:6,wire:5,face:4,shell:3,solid:2,compsolid:1,compound:0};function Xo(e,t,n){let r=e.TopologyExtractor.extract(t,Yo[n]),i=r.getShapesCount(),a=[];for(let e=0;e<i;e++)a.push(r.getShape(e));return r.delete(),a}var Zo=new WeakMap;function Qo(e,t,n){let r=Zo.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},Zo.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,Fo),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 $o(e,t,n){return e.TopologyExtractor?Xo(e,t,n):Qo(e,t,n)}var es=new WeakMap;function ts(e){let t=es.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`]]),es.set(e,t)}return t}function ns(e,t){if(t.IsNull())throw Error(`Cannot determine shape type: shape is null`);let n=ts(e).get(t.ShapeType());if(!n)throw Error(`Unknown shape type enum value`);return n}function rs(e,t){let n=new e.BRepCheck_Analyzer(t,!0,!1,!1),r=n.IsValid_2();return n.delete(),r}function is(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 as(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 os(e,t){return e.IsSame(t)}function ss(e,t){return e.IsEqual(t)}function cs(e){return{iterShapes:(t,n)=>$o(e,t,n),iterShapeList:(t,n)=>{as(e,t,n)},shapeType:t=>ns(e,t),isSame:(e,t)=>os(e,t),isEqual:(e,t)=>ss(e,t),isValid:t=>rs(e,t),sew:(t,n)=>is(e,t,n)}}var ls=.001;function us(e,t,n){n===`commonFace`&&t.SetGlue(e.BOPAlgo_GlueEnum.BOPAlgo_GlueShift),n===`sameFace`&&t.SetGlue(e.BOPAlgo_GlueEnum.BOPAlgo_GlueFull)}function ds(e,t){e.SetRunParallel(!0),e.SetUseOBB?.(!0),t!==void 0&&t>0&&e.SetFuzzyValue?.(t)}function fs(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 ps(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 ms(e,t,n,r={}){let i=Eo(`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);us(e,c,i),ds(c,o),c.Build(s),a&&c.SimplifyResult(!0,!0,ls);let l=c.Shape();return c.delete(),s.delete(),l}finally{i()}}function hs(e,t,n,r={}){let i=Eo(`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);us(e,c,i),ds(c,o),c.Build(s),a&&c.SimplifyResult(!0,!0,ls);let l=c.Shape();return c.delete(),s.delete(),l}finally{i()}}function gs(e,t,n,r={}){let i=Eo(`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);us(e,c,i),ds(c,o),c.Build(s),a&&c.SimplifyResult(!0,!0,ls);let l=c.Shape();return c.delete(),s.delete(),l}finally{i()}}function _s(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),ds(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 vs(e,t,n={}){let r=No(e,t,n);if(r!==null)return r;let i=Eo(`boolean`);try{let{optimisation:r,simplify:i=!1}=n,a=n.fuzzyValue??fs(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),us(e,s,r),ds(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 ys(e,n,r,i,a){a.signal?.throwIfAborted();let o=i-r;if(o===1)return t(n,r);if(o===2)return ms(e,n[r],n[r+1],{...a,simplify:!1});let s=r+Math.ceil(o/2);return ms(e,ys(e,n,r,s,a),ys(e,n,s,i,a),{...a,simplify:!1})}function bs(e,t,n={}){let r=ys(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 xs(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`?bs(e,n,r):vs(e,n,r)}function Ss(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),ds(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 Cs(e,t,n,r={}){if(n.length===0)return t;let i=Po(e,t,n,r);if(i!==null)return i;let a=ps(e,n),o=hs(e,t,a,r);return a.delete(),o}function ws(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 Ts(e){return{fuse:(t,n,r)=>ms(e,t,n,r),cut:(t,n,r)=>hs(e,t,n,r),intersect:(t,n,r)=>gs(e,t,n,r),section:(t,n,r)=>_s(e,t,n,r),fuseAll:(t,n)=>xs(e,t,n),cutAll:(t,n,r)=>Cs(e,t,n,r),split:(t,n)=>Ss(e,t,n),checkBoolean:(t,n,r)=>ws(e,t,n,r,t=>rs(e,t))}}var Es={fuse:0,cut:1,intersect:2};function Ds(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(Es[e.op],e.tool);let e=r.execute(t,i,a);return e.IsNull()?null:e}finally{r.delete()}}}function Os(e){return{booleanPipeline:(t,n,r)=>Ds(e,t,n,r)??null}}function ks(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 As(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 js(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 Ms(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=$o(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 Ns(e,t,n,r){let i=new e.BRepPrimAPI_MakeBox_2(t,n,r),a=i.Solid();return i.delete(),a}function Ps(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 Fs(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 Is(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 Ls(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 Rs(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 zs(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 Bs(e){return{makeVertex:(t,n,r)=>ks(e,t,n,r),makeEdge:(t,n,r)=>As(e,t,n,r),makeWire:t=>js(e,t),makeWireFromMixed:t=>Rs(e,t),makeFace:(t,n)=>Ms(e,t,n),makeBox:(t,n,r)=>Ns(e,t,n,r),makeCylinder:(t,n,r,i)=>Ps(e,t,n,r,i),makeSphere:(t,n)=>Fs(e,t,n),makeCone:(t,n,r,i,a)=>Is(e,t,n,r,i,a),makeTorus:(t,n,r,i)=>zs(e,t,n,r,i),buildTriFace:(t,n,r)=>Ls(e,t,n,r)}}function Vs(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 Us(e,t,n){let{faces:r,points:i}=t,a=[];for(let[t,n,o]of r){let r=Vs(i,t),s=Vs(i,n),c=Vs(i,o),l=Ls(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 Ws(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=g(r,n);if(i.faces.length<4)throw Error(`hull: degenerate hull (fewer than 4 faces)`);return Us(e,i,n)}function Gs(e,t,n,r){return Us(e,{points:t,faces:n},r)}function Ks(e,t,n){if(t.length<4)throw Error(`hullFromPoints: fewer than 4 points`);let r=g(t,n);if(r.faces.length<4)throw Error(`hullFromPoints: degenerate hull (fewer than 4 faces)`);return Us(e,r,n)}function qs(e){return{hull:(t,n)=>Ws(e,t,n),hullFromPoints:(t,n)=>Ks(e,t,n),buildSolidFromFaces:(t,n,r)=>Gs(e,t,n,r)}}function Js(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 Ys(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 Xs(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 Zs(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 Qs(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 $s(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 ec(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 tc(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 nc(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 rc(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 ic(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=rc(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 ac(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 oc(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 sc(e,t){let n=new e.ShapeFix_Solid_1,r=n.SolidFromShell(e.TopoDS_Cast.Shell(t));return n.delete(),r}function cc(e,t){return e.BRepToolsWrapper.Write(t)}function lc(e,t){return e.BRepToolsWrapper.Read(t)}function uc(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 dc(e,t){try{t.delete()}catch{}}function fc(e,t,n){let r=Js(e,[0,0,0],[t,0,0]),i=Js(e,[t,0,0],[t,n,0]),a=Js(e,[t,n,0],[0,n,0]),o=Js(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 pc(e,t,n,r){return new e.gp_Pnt_3(t,n,r)}function mc(e,t,n,r){return new e.gp_Dir_5(t,n,r)}function hc(e,t,n,r){return new e.gp_Vec_4(t,n,r)}function gc(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 _c(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 vc(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 yc(e){return{makeLineEdge:(t,n)=>Js(e,t,n),makeCircleEdge:(t,n,r)=>Ys(e,t,n,r),makeCircleArc:(t,n,r,i,a)=>Xs(e,t,n,r,i,a),makeArcEdge:(t,n,r)=>Zs(e,t,n,r),makeEllipseEdge:(t,n,r,i,a)=>$s(e,t,n,r,i,a),makeEllipseArc:(t,n,r,i,a,o,s)=>ec(e,t,n,r,i,a,o,s),makeBezierEdge:t=>tc(e,t),makeTangentArc:(t,n,r)=>Qs(e,t,n,r),makeHelixWire:(t,n,r,i,a,o)=>nc(e,t,n,r,i,a,o),makeCompound:t=>ac(e,t),makeBoxFromCorners:(t,n)=>oc(e,t,n),makeRectangle:(t,n)=>fc(e,t,n),solidFromShell:t=>sc(e,t),makeEllipsoid:(t,n,r)=>ic(e,t,n,r),toBREP:t=>cc(e,t),fromBREP:t=>lc(e,t),exportSTEPAssembly:(t,n)=>uc(e,t,n??{}),dispose:t=>{dc(e,t)},createPoint3d:(t,n,r)=>pc(e,t,n,r),createDirection3d:(t,n,r)=>mc(e,t,n,r),createVector3d:(t,n,r)=>hc(e,t,n,r),createAxis1:(t,n,r,i,a,o)=>gc(e,t,n,r,i,a,o),createAxis2:(t,n,r,i,a,o,s,c,l)=>_c(e,t,n,r,i,a,o,s,c,l),createAxis3:(t,n,r,i,a,o,s,c,l)=>vc(e,t,n,r,i,a,o,s,c,l)}}function bc(e,t,n,r){let i=Eo(`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 xc(e,t,n,r){let i=new e.BRepPrimAPI_MakeRevol_1(t,n,r,!1),a=i.Shape();return i.delete(),a}function Sc(e,t,n=!1,r,i){let a=Eo(`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 Cc(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 wc(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=a;if(t.IsDone()){let n=t.Solid(),r=new e.BRepCheck_Analyzer(n,!0,!1,!1);r.IsValid_2()?o=n:n.delete(),r.delete()}return n.delete(),t.delete(),r.delete(),o}return r.delete(),a}var Tc,Ec;function Dc(){Tc=void 0}function Oc(){Ec=void 0}function kc(e){return Tc??=typeof e.LoftBatch==`function`,Tc}function Ac(e){return Ec??=typeof e.ExtrudeBatch==`function`,Ec}function jc(e,t){if(t.length===0)return[];if(kc(e)){let n=Eo(`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=>Sc(e,t.wires,t.ruled??!1,t.startVertex,t.endVertex))}function Mc(e,t){if(t.length===0)return[];if(Ac(e)){let n=Eo(`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=>bc(e,t.face,t.direction,t.length))}function Nc(e){return{extrude:(t,n,r)=>bc(e,t,n,r),revolve:(t,n,r)=>xc(e,t,n,r),loft:(t,n,r,i)=>Sc(e,t,n,r,i),sweep:(t,n,r)=>Cc(e,t,n,r??{}),simplePipe:(t,n)=>wc(e,t,n),loftBatch:t=>jc(e,t),extrudeBatch:t=>Mc(e,t)}}function Pc(e,t,n,r){let i=Eo(`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 Fc(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 Ic(e,t,n,r,i=.001){let a=Eo(`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 Lc(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 Rc(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 zc(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 Bc(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 Vc,Hc;function Uc(){Vc=void 0}function Wc(){Hc=void 0}function Gc(e){return Vc??=typeof e.ShellBatch==`function`,Vc}function Kc(e){return Hc??=typeof e.FilletBatch==`function`,Hc}function qc(e,t){if(t.length===0)return[];if(Gc(e)){let n=Eo(`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=>Ic(e,t.shape,t.faces,t.thickness,t.tolerance??.001))}function Jc(e,t){if(t.length===0)return[];if(Kc(e)){let n=Eo(`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 Pc(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 Yc(e){return{fillet:(t,n,r)=>Pc(e,t,n,r),chamfer:(t,n,r)=>Fc(e,t,n,r),chamferDistAngle:(t,n,r,i)=>Rc(e,t,n,r,i),shell:(t,n,r,i)=>Ic(e,t,n,r,i),thicken:(t,n)=>Lc(e,t,n),offset:(t,n,r)=>Bc(e,t,n,r),offsetWire2D:(t,n,r)=>zc(e,t,n,r),shellBatch:t=>qc(e,t),filletBatch:t=>Jc(e,t)}}var Xc;function Zc(){Xc=void 0}function Qc(e){return Xc??=typeof e.TransformBatch==`function`,Xc}function $c(e,t){if(t.length===0)return[];let n=Eo(`transform`);try{if(Qc(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 tl(e,t.shape,t.x,t.y,t.z);case`rotate`:return nl(e,t.shape,t.angle,[...t.axis],[...t.center]);case`scale`:return il(e,t.shape,[...t.center],t.factor);case`mirror`:return rl(e,t.shape,[...t.origin],[...t.normal])}})}finally{n()}}function el(e,t,n){let r=new e.BRepBuilderAPI_Transform_2(t,n,!0,!1),i=r.ModifiedShape(t);return r.delete(),i}function tl(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=el(e,t,a);return a.delete(),o.delete(),s}function nl(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=el(e,t,a);return a.delete(),c.delete(),o.delete(),s.delete(),l}function rl(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=el(e,t,i);return i.delete(),s.delete(),a.delete(),o.delete(),c}function il(e,t,n,r){let i=new e.gp_Trsf_1,a=new e.gp_Pnt_3(...n);i.SetScale(a,r);let o=el(e,t,i);return i.delete(),a.delete(),o}function al(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 ol(e,t){let n=new e.ShapeUpgrade_UnifySameDomain_2(t,!0,!0,!1);n.Build();let r=n.Shape();return n.delete(),r}function sl(e){return{transform:(t,n)=>el(e,t,n),translate:(t,n,r,i)=>tl(e,t,n,r,i),rotate:(t,n,r,i)=>nl(e,t,n,r,i),mirror:(t,n,r)=>rl(e,t,n,r),scale:(t,n,r)=>il(e,t,n,r),transformBatch:t=>$c(e,t),generalTransform:(t,n,r,i)=>al(e,t,n,r,i),simplify:t=>ol(e,t)}}function cl(e,t,n){if(n===0)return new Float32Array;let r=t/4;return e.slice(r,r+n)}function ll(e,t,n){let r=Eo(`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=cl(e.HEAPF32,r.getVerticesPtr(),i),u=n.skipNormals||a===0?new Float32Array:cl(e.HEAPF32,r.getNormalsPtr(),a),d=r.getTrianglesPtr()/4,f=e.HEAPU32.slice(d,d+o),p=c>0?cl(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 ul(e,t,n,r){let i=Eo(`edgeMesh`);try{let i=e.EdgeMeshExtractor.extract(t,n,r),a=i.getLinesSize(),o=i.getEdgeGroupsSize(),s=cl(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 dl(e){return{mesh:(t,n)=>ll(e,t,n),meshEdges:(t,n,r)=>ul(e,t,n,r)}}var fl=0;function pl(e,t){return`${e}_${++fl}.${t}`}function ml(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=pl(`_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 hl(e,t,n=!1){let r=pl(`_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 gl(e,t){let n=new e.IGESControl_Writer_1;for(let e of t)n.AddShape(e);n.ComputeModel();let r=pl(`_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 _l(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=pl(`_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 vl(e,t){let n=pl(`_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 yl(e,t){let n=pl(`_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 bl(e){return{exportSTEP:t=>ml(e,t),exportSTL:(t,n)=>hl(e,t,n),importSTEP:t=>_l(e,t),importSTL:t=>vl(e,t),exportIGES:t=>gl(e,t),importIGES:t=>yl(e,t)}}function xl(e,t){let n=e.BRep_Tool.Pnt(t),r=[n.X(),n.Y(),n.Z()];return n.delete(),r}function Sl(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 Cl=new WeakMap;function wl(e,t){let n=Cl.get(e);n||(n=Sl(e),Cl.set(e,n));let r=new e.BRepAdaptor_Surface_2(t,!1),i=r.GetType();return r.delete(),n.get(i)??`other`}function Tl(e,t){let n=e.BRepTools.UVBounds_1(t);return{uMin:n.UMin,uMax:n.UMax,vMin:n.VMin,vMax:n.VMax}}function El(e,t){return e.BRepTools.OuterWire(t)}function Dl(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 Ol(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 kl(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 Al(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 jl(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 Ml(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 Nl(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 Pl(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 Fl(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 Il(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 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.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 Rl(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 zl(e,t,n){switch(n??Bl(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 Bl(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 Vl(e,t,n){return e.shapeHashCode(t,n)}function Hl(e,t){return t.IsNull()}function Ul(e,t){return t.Reversed()}function Wl(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 Gl(e,t,n,r){new e.BRepMesh_IncrementalMeshWrapper(t,n,!1,r,!1).delete()}function Kl(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 ql(e,t){return t.ShapeType()===e.TopAbs_ShapeEnum.TopAbs_WIRE?new e.BRepAdaptor_CompCurve_2(t,!1):new e.BRepAdaptor_Curve_2(t)}function Jl(e,t){let n=t.get();if(typeof n.Cylinder!=`function`)return null;let r=n.Cylinder(),i={radius:r.Radius(),isDirect:r.Direct()};return r.delete(),i}function Yl(e,t){let n=null;try{if(t===7)return e.AxeOfRevolution();if(t===1)n=e.Cylinder();else if(t===2)n=e.Cone();else if(t===4)n=e.Torus();else return null;let r=n.Axis();return n.delete(),r}catch{return n?.delete?.(),null}}function Xl(e,t){let n=new e.BRepAdaptor_Surface_2(t,!1);try{let e=n.GetType(),t=Yl(n,typeof e==`number`?e:Number(e?.value??e));if(!t)return null;let r=null,i=null;try{return r=t.Location(),i=t.Direction(),{origin:[r.X(),r.Y(),r.Z()],direction:[i.X(),i.Y(),i.Z()]}}finally{r?.delete?.(),i?.delete?.(),t.delete()}}finally{n.delete()}}function Zl(e,t){return t.get().UReversed()}function Ql(e){return{vertexPosition:t=>xl(e,t),surfaceType:t=>wl(e,t),uvBounds:t=>Tl(e,t),outerWire:t=>El(e,t),surfaceNormal:(t,n,r)=>Dl(e,t,n,r),pointOnSurface:(t,n,r)=>Ol(e,t,n,r),uvFromPoint:(t,n)=>kl(e,t,n),projectPointOnFace:(t,n)=>Al(e,t,n),curveTangent:(t,n)=>jl(e,t,n),curveParameters:t=>Ml(e,t),shapeOrientation:t=>Rl(e,t),downcast:(t,n)=>zl(e,t,n),hashCode:(t,n)=>Vl(e,t,n),isNull:t=>Hl(e,t),hasTriangulation:t=>Wl(e,t),meshShape:(t,n,r)=>{Gl(e,t,n,r)},getBezierPenultimatePole:t=>Kl(e,t),createCurveAdaptor:t=>ql(e,t),reverseShape:t=>Ul(e,t),curvePointAtParam:(t,n)=>Nl(e,t,n),curveIsClosed:t=>Pl(e,t),curveIsPeriodic:t=>Fl(e,t),curvePeriod:t=>Il(e,t),curveType:t=>Ll(e,t),getSurfaceCylinderData:t=>Jl(e,t),getSurfaceAxis:t=>Xl(e,t),reverseSurfaceU:t=>Zl(e,t)}}function $l(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 eu(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 tu(e){return{getNurbsCurveData:t=>$l(e,t),getNurbsSurfaceData:t=>eu(e,t)}}function nu(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 ru(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 iu(e){return{interpolatePoints:(t,n)=>nu(e,t,n??{}),approximatePoints:(t,n)=>ru(e,t,n??{})}}function au(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 ou(e,t){let n=new e.ShapeFix_Face_2(t);n.Perform();let r=n.Face();return n.delete(),r}function su(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 cu(e){return{healSolid:t=>au(e,t),healFace:t=>ou(e,t),healWire:(t,n)=>su(e,t,n)}}var lu={modified:new Map,generated:new Map,deleted:new Set};function uu(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 du(e,t){try{let n=uu(e.HEAP32,t.getModifiedPtr(),t.getModifiedSize()),r=uu(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 fu(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 pu(e,t,n,r,i){if(r.length===0)return lu;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 du(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,fu(e,a,i));let l=t.Generated(r);l.Size()>0&&s.set(n,fu(e,l,i))}return{modified:o,generated:s,deleted:c}}function mu(e,t,n,r,i){let a=new e.BRepBuilderAPI_Transform_2(t,n,!0,!1),o=a.Shape(),s=r.length===0?lu:pu(e,a,t,r,i);return a.delete(),{shape:o,evolution:s}}function hu(e,t,n,r,i,a,o){return a&&t.SimplifyResult(!0,!0,.001),{shape:t.Shape(),evolution:pu(e,t,n,r,i),diagnostics:o??{hasErrors:!1,hasWarnings:!1,messages:[]}}}function gu(e,t,n,r,i){return{shape:t.Shape(),evolution:pu(e,t,n,r,i)}}function _u(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=mu(e,t,s,a,o);return s.delete(),l}function vu(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=mu(e,t,s,r,i);return s.delete(),d}function yu(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=mu(e,t,o,i,a);return o.delete(),u}function bu(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=mu(e,t,o,i,a);return o.delete(),c}function xu(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=mu(e,t,s,a,o);return s.delete(),c}function Su(e){return{hasErrors:e.HasErrors(),hasWarnings:e.HasWarnings(),messages:[]}}function Cu(e,t,n,r,i,a={}){let o=new e.Message_ProgressRange_1,s=new e.BRepAlgoAPI_Fuse_3(t,n,o);us(e,s,a.optimisation),ds(s,a.fuzzyValue),s.Build(o);let c=Su(s),l=hu(e,s,[t,n],r,i,a.simplify??!1,c);return s.delete(),o.delete(),l}function wu(e,t,n,r,i,a={}){let o=new e.Message_ProgressRange_1,s=new e.BRepAlgoAPI_Cut_3(t,n,o);us(e,s,a.optimisation),ds(s,a.fuzzyValue),s.Build(o);let c=Su(s),l=hu(e,s,[t,n],r,i,a.simplify??!1,c);return s.delete(),o.delete(),l}function Tu(e,t,n,r,i,a={}){let o=new e.Message_ProgressRange_1,s=new e.BRepAlgoAPI_Common_3(t,n,o);us(e,s,a.optimisation),ds(s,a.fuzzyValue),s.Build(o);let c=Su(s),l=hu(e,s,[t,n],r,i,a.simplify??!1,c);return s.delete(),o.delete(),l}function Eu(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=gu(e,o,t,i,a);return o.delete(),c}function Du(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=gu(e,o,t,i,a);return o.delete(),u}function Ou(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=gu(e,s,t,i,a);return s.delete(),u}function ku(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=gu(e,a,t,r,i);return a.delete(),s}function Au(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=gu(e,o,t,r,i);return o.delete(),c}function ju(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(),gu(e,_,t,o,s)}finally{_.delete(),g.delete(),h.delete(),m.delete()}}function Mu(e){return{translateWithHistory:(t,n,r,i,a,o)=>_u(e,t,n,r,i,a,o),rotateWithHistory:(t,n,r,i,a,o)=>vu(e,t,n,r,i,a,o),mirrorWithHistory:(t,n,r,i,a)=>yu(e,t,n,r,i,a),scaleWithHistory:(t,n,r,i,a)=>bu(e,t,n,r,i,a),generalTransformWithHistory:(t,n,r,i,a,o)=>xu(e,t,n,r,i,a,o),fuseWithHistory:(t,n,r,i,a)=>Cu(e,t,n,r,i,a),cutWithHistory:(t,n,r,i,a)=>wu(e,t,n,r,i,a),intersectWithHistory:(t,n,r,i,a)=>Tu(e,t,n,r,i,a),filletWithHistory:(t,n,r,i,a)=>Eu(e,t,n,r,i,a),chamferWithHistory:(t,n,r,i,a)=>Du(e,t,n,r,i,a),shellWithHistory:(t,n,r,i,a,o)=>Ou(e,t,n,r,i,a,o),thickenWithHistory:(t,n,r,i)=>ku(e,t,n,r,i),offsetWithHistory:(t,n,r,i,a)=>Au(e,t,n,r,i,a),draftWithHistory:(t,n,r,i,a,o,s)=>ju(e,t,n,r,i,a,o,s)}}function Nu(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 Pu(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 Fu(e,t,n,r,i){return mu(e,t,n,r,i)}function Iu(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 Lu(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=Iu(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 Ru(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 zu(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 Bu(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 Vu(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 Hu(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 Uu(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 Wu(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 Ku(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 qu(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 Ju(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 Yu(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 Zu(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 Qu(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 $u(e,t){let n=new e.ShapeFix_Wire_1;n.Load_1(t),n.FixSelfIntersection();let r=n.Wire();return n.delete(),r}function ed(){return{gaussian:0,mean:0,max:0,min:0,maxDirection:[1,0,0],minDirection:[0,1,0]}}function td(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 nd(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=ed();if(h>=1e-15){m.Divide(h);let e=td(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:rd(o,s,e.du1,e.dv1),minDirection:rd(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 rd(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 id(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 ad(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 od(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 sd(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 cd(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 ld(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=pl(`_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 ud(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=pl(`_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 dd(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=pl(`_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 fd(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)?ud(e,t):dd(e,t)}function pd(e){return{composeTransform:t=>Pu(e,t),applyComposedTransformWithHistory:(t,n,r,i)=>Fu(e,t,n,r,i),sweepPipeShell:(t,n,r)=>Lu(e,t,n,r??{}),loftAdvanced:(t,n)=>Ru(e,t,n??{}),buildExtrusionLaw:(t,n,r)=>zu(e,t,n,r),revolveVec:(t,n,r,i)=>Bu(e,t,n,r,i),positionOnCurve:(t,n,r)=>Uu(e,t,n,r),linearPattern:(t,n,r,i)=>Vu(e,t,n,r,i),circularPattern:(t,n,r,i,a)=>Hu(e,t,n,r,i,a),makeNonPlanarFace:t=>Wu(e,t),addHolesInFace:(t,n)=>Gu(e,t,n),removeHolesFromFace:t=>Ku(e,t),makeFaceOnSurface:(t,n)=>qu(e,t,n),bsplineSurface:(t,n,r)=>Ju(e,t,n,r),triangulatedSurface:(t,n,r)=>Yu(e,t,n,r),sewAndSolidify:(t,n)=>Zu(e,t,n),fixShape:t=>Qu(e,t),fixSelfIntersection:t=>$u(e,t),surfaceCurvature:(t,n,r)=>nd(e,t,n,r),surfaceCenterOfMass:t=>id(e,t),createDistanceQuery:t=>ad(e,t),projectEdges:(t,n,r,i)=>od(e,t,n,r,i),draftPrism:(t,n,r,i,a,o)=>sd(e,t,n,r,i,a,o),generalTransformNonOrthogonal:(t,n,r)=>Nu(e,t,n,r),createXCAFDocument:t=>cd(e,t),writeXCAFToSTEP:(t,n)=>ld(e,t,n??{}),exportSTEPConfigured:(t,n)=>fd(e,t,n??{})}}var md=()=>{};function hd(e){return e}function gd(e){let t=hd(e);for(;t.__bk2d===`trimmed`;)t=t.basis;return t}function _d(e){return e}function vd(e,t){return{x:e,y:t}}function yd(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 bd(e,t){return{x:e,y:t}}function xd(e,t,n,r){return{px:e,py:t,dx:n,dy:r,delete:md}}function Sd(e){return e}function Cd(e){return e}function wd(e,t,n,r){return x(e,t,n,r)}function Td(e,t,n,r){return S(e,t,n,r)}function Ed(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 x(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=S(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 Dd(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 x(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,y=(e-p)/h,b=s*v+c*y,S;if(b>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 Ed(e,t,p+h*Math.cos(S),m+h*Math.sin(S),i,a)}function Od(e,t,n,r,i,a,o){return C(e,t,n,r,i,a,o)}function kd(e,t,n,r,i,a,o,s,c){return{__bk2d:`trimmed`,basis:C(e,t,n,r,o,s,c),tStart:i,tEnd:a}}function Ad(e){return w(e)}function jd(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 Md(e,t){return _(hd(e),t)}function Nd(e,t){return{point:_(hd(e),t),tangent:v(hd(e),t)}}function Pd(e){return y(hd(e))}function Fd(e){return b(gd(e))}function Id(e,t,n){return{__bk2d:`trimmed`,basis:hd(e),tStart:t,tEnd:n}}function Ld(e){return JSON.parse(JSON.stringify(e))}function Rd(e,t){let n=hd(e),r=y(n),i=[];for(let e=0;e<=30;e++){let a=r.first+(r.last-r.first)*e/30,[o,s]=_(n,a),[c,l]=v(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 jd(i)}function zd(e,t,n){return ee(hd(e),t,n)}function Bd(e,t,n,r){return te(hd(e),t,n,r)}function Vd(e,t,n,r){return ne(hd(e),t,n,r)}function Hd(e,t,n){return re(hd(e),t,n)}function Ud(e,t,n,r,i){return ie(hd(e),t,n,r,i)}function Wd(e,t,n,r,i,a){return ef(e,qd(t,n,r,i,a))}function Gd(e,t,n){return{m:e,tx:t,ty:n,delete:md}}function Kd(){return Gd([1,0,0,0,1,0,0,0,1],0,0)}function qd(e,n,r,i,a){let o=Math.sqrt(r*r+i*i);if(o<1e-15)return Kd();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 Jd(e,t){return Gd([1,0,0,0,1,0,0,0,1],e,t)}function Yd(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 Zd(e,t,n){return Gd([e,0,0,0,e,0,0,0,1],t*(1-e),n*(1-e))}function Qd(e,t,n){e.tx=t,e.ty=n}function $d(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 ef(e,n){let r=hd(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 ee(r,a,o);let d=y(r),f=[];for(let e=0;e<=20;e++){let[t,n]=_(r,d.first+(d.last-d.first)*e/20);f.push([s*t+c*n+a,l*t+u*n+o])}return w(f)}function tf(e,t,n){let r=ae(hd(e),hd(t),n),i=r.segments.map(e=>Object.assign(e,{delete(){}}));return{points:r.points,segments:i}}function nf(e,t,n){let r=hd(e),i=y(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]=_(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]=_(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]=_(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]=_(r,a),[s,c]=v(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]=_(r,a);return{param:a,distance:Math.sqrt((c-t)**2+(l-n)**2)}}function rf(e,t,n,r,i,a){let o=hd(e),s=hd(t),c=n,l=i,u=1/0;for(let e=0;e<=50;e++){let t=n+(r-n)*e/50,[d,f]=_(o,t);for(let e=0;e<=50;e++){let n=i+(a-i)*e/50,[r,o]=_(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]=_(s,f),u=nf(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]=_(o,d),h=nf(t,p,m);if(h){let e=Math.max(i,Math.min(a,h.param)),t=Math.abs(e-f)<1e-12;if(f=e,t)break}}let[p,m]=_(o,d),[h,g]=_(s,f);return Math.sqrt((h-p)**2+(g-m)**2)}function af(e,n,r,i){let a=hd(e),o=y(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(_(a,t))}u=0;for(let e=0;e<c;e++){let[n,r]=_(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 jd(l,{degMax:s})}function of(e){let n=gd(e);if(n.__bk2d===`bezier`)return[e];if(n.__bk2d!==`bspline`)return of(af(e,1e-6,`C2`,10));let r=y(hd(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=_(n,r),l=_(n,i),u=v(n,r),d=v(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 sf(){return ge()}function cf(e,t,n){_e(_d(e),hd(t),n)}function lf(e){let t=_d(e);return{xMin:t.xMin,yMin:t.yMin,xMax:t.xMax,yMax:t.yMax}}function uf(e,t){let n=_d(e),r=_d(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 df(e,t){let n=_d(e),r=_d(t);return n.xMax<r.xMin||r.xMax<n.xMin||n.yMax<r.yMin||r.yMax<n.yMin}function ff(e,t,n){let r=_d(e);return t<r.xMin||t>r.xMax||n<r.yMin||n>r.yMax}function pf(e){let t=gd(e);return t.__bk2d===`circle`?{cx:t.cx,cy:t.cy,radius:t.radius,isDirect:t.sense}:null}function mf(e){let t=gd(e);return t.__bk2d===`ellipse`?{majorRadius:t.majorRadius,minorRadius:t.minorRadius,xAxisAngle:t.xDirAngle,isDirect:t.sense}:null}function hf(e){let t=gd(e);return t.__bk2d===`bezier`?[...t.poles]:null}function gf(e){let t=gd(e);return t.__bk2d===`bezier`?t.poles.length-1:null}function _f(e){let t=gd(e);return t.__bk2d===`bspline`?{poles:[...t.poles],knots:[...t.knots],multiplicities:[...t.multiplicities],degree:t.degree,isPeriodic:t.isPeriodic}:null}function vf(e){return me(hd(e))}function yf(e){return he(e)}function bf(e,t){let n=hd(e),r=y(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 xf(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 Sf(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 Cf(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 wf(e,n,r,i,a){let o=hd(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 xf(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=y(o),[l,u]=_(o,s.first),[d,f]=_(o,(s.first+s.last)/2),[p,m]=_(o,s.last);return Sf(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?xf(e,t(n,0),t(n,1)):Cf(e,n)}let l=y(o),u=[];for(let e=0;e<=60;e++){let[t,n]=_(o,l.first+(l.last-l.first)*e/60);u.push(c(t,n))}return Cf(e,u)}function Tf(e,t,n){let r=hd(t),i=y(r),a=[];for(let e=0;e<=60;e++){let[t,o]=_(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 Cf(e,a)}function Ef(e,t){return e.BRep_Tool.Surface_2(t)}function Df(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(),jd(o)}function Of(e,t){e.BRepLib.BuildCurves3d_2(t)}function kf(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 Af(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=$o(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 jf(e){return{wrapCurve2dHandle:e=>Sd(e),createCurve2dAdaptor:e=>Cd(e),createPoint2d:(e,t)=>vd(e,t),createDirection2d:(e,t)=>yd(e,t),createVector2d:(e,t)=>bd(e,t),createAxis2d:(e,t,n,r)=>xd(e,t,n,r),makeLine2d:(e,t,n,r)=>wd(e,t,n,r),makeCircle2d:(e,t,n,r)=>Td(e,t,n,r),makeArc2dThreePoints:(e,t,n,r,i,a)=>Ed(e,t,n,r,i,a),makeArc2dTangent:(e,t,n,r,i,a)=>Dd(e,t,n,r,i,a),makeEllipse2d:(e,t,n,r,i,a,o)=>Od(e,t,n,r,i,a,o),makeEllipseArc2d:(e,t,n,r,i,a,o,s,c)=>kd(e,t,n,r,i,a,o,s,c),makeBezier2d:e=>Ad(e),makeBSpline2d:(e,t)=>jd(e,t),evaluateCurve2d:(e,t)=>Md(e,t),evaluateCurve2dD1:(e,t)=>Nd(e,t),getCurve2dBounds:e=>Pd(e),getCurve2dType:e=>Fd(e),trimCurve2d:(e,t,n)=>Id(e,t,n),reverseCurve2d:e=>{},copyCurve2d:e=>Ld(e),offsetCurve2d:(e,t)=>Rd(e,t),translateCurve2d:(e,t,n)=>zd(e,t,n),rotateCurve2d:(e,t,n,r)=>Bd(e,t,n,r),scaleCurve2d:(e,t,n,r)=>Vd(e,t,n,r),mirrorCurve2dAtPoint:(e,t,n)=>Hd(e,t,n),mirrorCurve2dAcrossAxis:(e,t,n,r,i)=>Ud(e,t,n,r,i),affinityTransform2d:(e,t,n,r,i,a)=>Wd(e,t,n,r,i,a),createIdentityGTrsf2d:()=>Kd(),createAffinityGTrsf2d:(e,t,n,r,i)=>qd(e,t,n,r,i),createTranslationGTrsf2d:(e,t)=>Jd(e,t),createMirrorGTrsf2d:(e,t,n,r,i,a,o)=>Yd(e,t,n,r,i,a,o),createRotationGTrsf2d:(e,t,n)=>Xd(e,t,n),createScaleGTrsf2d:(e,t,n)=>Zd(e,t,n),setGTrsf2dTranslationPart:(e,t,n)=>{Qd(e,t,n)},multiplyGTrsf2d:(e,t)=>{$d(e,t)},transformCurve2dGeneral:(e,t)=>ef(e,t),intersectCurves2d:(e,t,n)=>tf(e,t,n),projectPointOnCurve2d:(e,t,n)=>nf(e,t,n),distanceBetweenCurves2d:(e,t,n,r,i,a)=>rf(e,t,n,r,i,a),approximateCurve2dAsBSpline:(e,t,n,r)=>af(e,t,n,r),decomposeBSpline2dToBeziers:e=>of(e),createBoundingBox2d:()=>sf(),addCurveToBBox2d:(e,t,n)=>{cf(e,t,n)},getBBox2dBounds:e=>lf(e),mergeBBox2d:(e,t)=>{uf(e,t)},isBBox2dOut:(e,t)=>df(e,t),isBBox2dOutPoint:(e,t,n)=>ff(e,t,n),getCurve2dCircleData:e=>pf(e),getCurve2dEllipseData:e=>mf(e),getCurve2dBezierPoles:e=>hf(e),getCurve2dBezierDegree:e=>gf(e),getCurve2dBSplineData:e=>_f(e),serializeCurve2d:e=>vf(e),deserializeCurve2d:e=>yf(e),splitCurve2d:(e,t)=>bf(e,t),liftCurve2dToPlane:(t,n,r,i)=>wf(e,t,n,r,i),buildEdgeOnSurface:(t,n)=>Tf(e,t,n),extractSurfaceFromFace:t=>Ef(e,t),extractCurve2dFromEdge:(t,n)=>Df(e,t,n),buildCurves3d:t=>{Of(e,t)},fixWireOnFace:(t,n,r)=>kf(e,t,n,r),fillSurface:(t,n)=>Af(e,t,n)}}function Mf(){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 Nf(e){return{draft:(t,n,r,i,a)=>ju(e,t,n,r,i,a,[],1).shape}}var Pf=class{oc;kernelId=`occt`;capabilities=r;constructor(e){this.oc=e,Object.assign(this,Ts(e),Os(e),qs(e),Bs(e),yc(e),Nc(e),Yc(e),sl(e),dl(e),bl(e),Jo(e),cs(e),Ql(e),tu(e),iu(e),cu(e),Mu(e),pd(e),jf(e),Nf(e),Mf())}},Ff=()=>{};function If(e){return typeof e==`object`&&!!e&&e.__brepkit}function Lf(e,t){return{__brepkit:!0,type:e,id:t,delete:Ff,HashCode(e){return t%e},IsNull(){return!1}}}function L(e){return Lf(`solid`,e)}function Rf(e){return Lf(`face`,e)}function zf(e){return Lf(`edge`,e)}function Bf(e){return Lf(`wire`,e)}function Vf(e){return Lf(`shell`,e)}function Hf(e){let t=Lf(`compound`,e);return rp.has(e)?{...t,delete:()=>rp.delete(e)}:t}function Uf(e){return Lf(`vertex`,e)}function R(e,t){if(!If(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 z(e){return Array.from(e)}function Wf(e,t){if(!If(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(!If(t))throw Error(`brepkit: expected a BrepkitHandle, got `+typeof t);if(t.type===`solid`)return[t.id];if(t.type===`compound`){let r=z(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 Kf(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 qf(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}function Jf(e,t,n){return[1,0,0,e,0,1,0,t,0,0,1,n,0,0,0,1]}function Yf(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 Zf(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 Qf(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 $f(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 ep=.01,tp=9e5;function np(){return tp++}var rp=new Map,ip=new Set;function ap(e,t){ip.has(e)||(ip.add(e),console.warn(`brepkit: ${t}`))}function op(e){return e.optimisation!==void 0||e.simplify!==void 0||e.strategy!==void 0||e.fuzzyValue!==void 0}function sp(e){return e}function cp(e){let t=e;for(;t.__bk2d===`trimmed`;)t=t.basis;return t}function lp(e){return e}function up(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 dp(e,t,n){let r=rp.get(t);return r?r.flatMap(t=>t.type===n?[t]:yp(e,t,n)):n===`solid`?z(e.getCompoundSolids(t)).map(L):n===`face`||n===`edge`||n===`vertex`||n===`wire`?z(e.getCompoundSolids(t)).map(L).flatMap(t=>yp(e,t,n)):[]}function fp(e,t,n,r){switch(r){case`solid`:return[t];case`shell`:return z(e.getSolidShells(n)).map(Vf);case`face`:return z(e.getSolidFaces(n)).map(Rf);case`edge`:return z(e.getSolidEdges(n)).map(zf);case`vertex`:return z(e.getSolidVertices(n)).map(Uf);case`wire`:return z(e.getSolidFaces(n)).flatMap(t=>z(e.getFaceWires(t)).map(Bf));default:return[]}}function pp(e,t,n){let r=z(e.getShellFaces(t)).map(Rf),i=new Set,a=[];for(let t of r)for(let r of yp(e,t,n)){let e=R(r);i.has(e)||(i.add(e),a.push(r))}return a}function mp(e,t,n,r){return r===`shell`?[t]:r===`face`?z(e.getShellFaces(n)).map(Rf):r===`edge`||r===`vertex`?pp(e,n,r):[]}function hp(e,t,n,r){return r===`face`?[t]:r===`edge`?z(e.getFaceEdges(n)).map(zf):r===`vertex`?z(e.getFaceVertices(n)).map(Uf):r===`wire`?z(e.getFaceWires(n)).map(Bf):[]}function gp(e,n){let r=z(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(Uf(e.makeVertex(t,n,r))))}}return a}function _p(e,t,n,r){return r===`wire`?[t]:r===`edge`?z(e.getWireEdges(n)).map(zf):r===`vertex`?gp(e,n):[]}function vp(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[Uf(i),Uf(a)]}return[]}function yp(e,t,n){let r=R(t);switch(t.type){case`compound`:return dp(e,r,n);case`solid`:return fp(e,t,r,n);case`shell`:return mp(e,t,r,n);case`face`:return hp(e,t,r,n);case`wire`:return _p(e,t,r,n);case`edge`:return vp(e,t,r,n);default:return[]}}function bp(e,t,n){if(Array.isArray(t))for(let e of t)n(e)}function xp(e,t){if(If(t))return t.type;throw Error(`brepkit: cannot determine shape type of non-brepkit handle`)}function Sp(e,t,n){return If(t)&&If(n)&&t.id===n.id&&t.type===n.type}function Cp(e,t,n){return Sp(e,t,n)}function wp(e,t,n){return t}function Tp(e,t,n){return If(t)?t.id%n:0}function Ep(e,t){return!t||!If(t)}function Dp(e,t){let n=R(t);return e.getShapeOrientation(n)}function Op(e,t){let n=Wf(t,`edgeToFaceMap`);return e.edgeToFaceMap(n)}function kp(e,t,n){let r=R(t,`face`),i=R(n,`face`);return Array.from(e.sharedEdges(r,i)).map(e=>zf(e))}function Ap(e,t,n){let r=Wf(t,`adjacentFaces`),i=R(n,`face`);return Array.from(e.adjacentFaces(r,i)).map(e=>Rf(e))}function jp(e,t){let n=t;return n.type===`face`?[n.id]:n.type===`solid`?z(e.getSolidFaces(n.id)):n.type===`shell`?z(e.getShellFaces(n.id)):[]}function Mp(e,t,n){let r=t.flatMap(t=>jp(e,t)),i=n??1e-7;try{return Vf(e.weldShellsAndFaces(r,i))}catch(e){console.warn(`brepkit: weldShellsAndFaces failed, falling back to sewFaces:`,e)}return Vf(e.sewFaces(r,i))}function Np(e){return{iterShapes:(t,n)=>yp(e,t,n),iterShapeList:(t,n)=>{bp(e,t,n)},shapeType:t=>xp(e,t),isSame:(t,n)=>Sp(e,t,n),isEqual:(t,n)=>Cp(e,t,n),downcast:(t,n)=>wp(e,t,n),hashCode:(t,n)=>Tp(e,t,n),isNull:t=>Ep(e,t),shapeOrientation:t=>Dp(e,t),edgeToFaceMap:t=>Op(e,t),sharedEdges:(t,n)=>kp(e,t,n),adjacentFaces:(t,n)=>Ap(e,t,n),sew:(t,n)=>Mp(e,t,n)}}function Pp(e,t){return n(e.getVertexPosition(R(t,`vertex`)))}function Fp(e,t){return e.getSurfaceType(R(t,`face`))}function Ip(e,n){let r=e.getSurfaceDomain(R(n,`face`));return{uMin:t(r,0),uMax:t(r,1),vMin:t(r,2),vMax:t(r,3)}}function Lp(e,t){return Bf(e.getFaceOuterWire(R(t,`face`)))}function Rp(e,t,r,i){return n(e.evaluateSurfaceNormal(R(t,`face`),r,i))}function zp(e,t,r,i){return n(e.evaluateSurface(R(t,`face`),r,i))}function Bp(e,n,r){try{let i=e.projectPointOnSurface(R(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 Vp(e,t,r){return n(e.projectPointOnSurface(R(t,`face`),r[0],r[1],r[2]),2)}function Hp(e,r,i){let a=r,o,s=i;if(a.type===`wire`){let n=z(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=R(r,`edge`);let c=e.evaluateEdgeCurveD1(o,s);return{point:n(c,0),tangent:n(c,3)}}function Up(e,n){let r=n;if(r.type===`wire`){let n=z(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(R(n,`edge`));return[t(i,0),t(i,1)]}function Wp(e,r,i){let a=r;if(a.type===`wire`){let r=z(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(R(r,`edge`),i))}function Gp(e,r){let i=r;if(i.type===`wire`){let r=z(e.getWireEdges(i.id));if(r.length===0)return!1;if(r.length===1)return Kp(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=>Kf(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 Kp(e.getEdgeVertices(R(r,`edge`)))}function Kp(e){return Kf(t(e,0),t(e,1),t(e,2),t(e,3),t(e,4),t(e,5))<1e-7}function qp(e,t){let n=t;try{if(n.type===`edge`||n.type===`wire`&&z(e.getWireEdges(n.id)).length===1)return Gp(e,t)}catch{}return!1}function Jp(e,t){try{if(qp(e,t)){let n=Up(e,t);return n[1]-n[0]}}catch{}return 0}function Yp(e,t){if(t.type===`wire`){let n=yp(e,t,`edge`)[0];return n?e.getEdgeCurveType(R(n,`edge`)):`LINE`}return e.getEdgeCurveType(R(t,`edge`))}function Xp(e,t,n){let r=R(t,`edge`);return zf(e.curveDegreeElevate(r,n))}function Zp(e,t,n,r){let i=R(t,`edge`);return zf(e.curveKnotInsert(i,n,r))}function Qp(e,t,n,r){let i=R(t,`edge`);return zf(e.curveKnotRemove(i,n,r))}function $p(e,n,r){let i=R(n,`edge`),a=e.curveSplit(i,r);return[zf(t(a,0)),zf(t(a,1))]}function em(e,t,n,r,i,a,o,s,c,l){return Rf(e.approximateSurfaceLspia(t,n,r,i,a,o,s,c,l))}function tm(e,t,n,r){let i=R(t,`face`);return Rf(e.untrimFace(i,n,r))}function nm(e,t){return t}function rm(e,t){let r=Nm(e,t);return!r||r.controlPoints.length<6?null:n(r.controlPoints,r.controlPoints.length-6)}function im(e,t){if(If(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 am(e,t){let n=JSON.parse(e.getAnalyticSurfaceParams(R(t,`face`))),r=n.type===`cylinder`?n.origin:n.type===`cone`?n.apex:null;if(!r||!n.axis)return null;let[i,a,o]=r,[s,c,l]=n.axis,u=Math.hypot(s,c,l);return u<1e-12?null:{origin:[i,a,o],direction:[s/u,c/u,l/u]}}function om(e,t){return t}function sm(e,n,r,i,a){a!==void 0&&ap(`classify-tolerance`,`classifyPointOnFace() tolerance parameter is not supported; brepkit uses domain-based classification.`);let o=R(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 cm(e,t,n,r){let i=Wf(t,`classifyPointRobust`);return e.classifyPointRobust(i,n[0],n[1],n[2],r)}function lm(e,t,n,r){let i=Wf(t,`classifyPointWinding`);return e.classifyPointWinding(i,n[0],n[1],n[2],r)}function um(e,t,n,r){let i=Wf(t,`detectSmallFeatures`);return Array.from(e.detectSmallFeatures(i,n,r)).map(e=>Rf(e))}function dm(e,t,n){let r=Wf(t,`recognizeFeatures`);return e.recognizeFeatures(r,n)}function fm(e,t,r,i,a){let o=R(t),[s,c,l]=r,[u,d,f]=i,[p,m,h]=a??[1,0,0],g=.1;try{let t=e.boundingBox(o),[r,i,a]=n(t,0),[s,c,l]=n(t,3),u=Kf(r,i,a,s,c,l);u>0&&(g=Math.max(u*.001,1e-6))}catch{}let _=e.projectEdges(o,s,c,l,u,d,f,p,m,h,!0,g),v;try{v=JSON.parse(_)}catch{v={visible:[],hidden:[]}}let y=t=>{let n=[];for(let r of t)for(let t=0;t+3<r.length;t+=2){let i=r[t],a=r[t+1],o=r[t+2],s=r[t+3];i===void 0||a===void 0||o===void 0||s===void 0||i===o&&a===s||n.push(zf(e.makeLineEdge(i,a,0,o,s,0)))}let r=np();return rp.set(r,n),Hf(r)},b=()=>{let e=np();return rp.set(e,[]),Hf(e)};return{visible:{outline:y(v.visible),smooth:b(),sharp:b()},hidden:{outline:y(v.hidden),smooth:b(),sharp:b()}}}function pm(e,t){let n=R(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 mm(e,t){return JSON.parse(e.getNurbsSurfaceDataParity(R(t,`face`)))}function hm(e){return{vertexPosition:t=>Pp(e,t),surfaceType:t=>Fp(e,t),uvBounds:t=>Ip(e,t),outerWire:t=>Lp(e,t),surfaceNormal:(t,n,r)=>Rp(e,t,n,r),pointOnSurface:(t,n,r)=>zp(e,t,n,r),uvFromPoint:(t,n)=>Bp(e,t,n),projectPointOnFace:(t,n)=>Vp(e,t,n),curveTangent:(t,n)=>Hp(e,t,n),curveParameters:t=>Up(e,t),curvePointAtParam:(t,n)=>Wp(e,t,n),curveIsClosed:t=>Gp(e,t),curveIsPeriodic:t=>qp(e,t),curvePeriod:t=>Jp(e,t),curveType:t=>Yp(e,t),curveDegreeElevate:(t,n)=>Xp(e,t,n),curveKnotInsert:(t,n,r)=>Zp(e,t,n,r),curveKnotRemove:(t,n,r)=>Qp(e,t,n,r),curveSplit:(t,n)=>$p(e,t,n),approximateSurfaceLspia:(t,n,r,i,a,o,s,c,l)=>em(e,t,n,r,i,a,o,s,c,l),untrimFace:(t,n,r)=>tm(e,t,n,r),createCurveAdaptor:t=>nm(e,t),getBezierPenultimatePole:t=>rm(e,t),getSurfaceCylinderData:t=>im(e,t),getSurfaceAxis:t=>am(e,t),reverseSurfaceU:t=>om(e,t),classifyPointOnFace:(t,n,r,i)=>sm(e,t,n,r,i),classifyPointRobust:(t,n,r)=>cm(e,t,n,r),classifyPointWinding:(t,n,r)=>lm(e,t,n,r),detectSmallFeatures:(t,n,r)=>um(e,t,n,r),recognizeFeatures:(t,n)=>dm(e,t,n),projectEdges:(t,n,r,i)=>fm(e,t,n,r,i),getNurbsCurveData:t=>pm(e,t),getNurbsSurfaceData:t=>mm(e,t)}}function gm(e,t,n){if(Array.isArray(n)&&n.length===16)return km(e,t,n);throw Error(`brepkit: transform expects a 16-element matrix array`)}function _m(e,t,n,r,i){return km(e,t,Jf(n,r,i))}function vm(e,t,n,r,i){return km(e,t,Yf(n,r,i))}function ym(e,t,n,r){let i=t;return i.type===`solid`?L(e.mirror(i.id,n[0],n[1],n[2],r[0],r[1],r[2])):km(e,t,Qf(n,r))}function bm(e,t,n,r){return km(e,t,Xf(n,r))}function xm(e,t,n,r,i){return km(e,t,Zf(n,r))}function Sm(e,t,n,r){return km(e,t,Zf(n,r))}function Cm(e,t,n,r){let{point:i,tangent:a}=Hp(e,n,r),[o,s,c]=a,l=Math.sqrt(o*o+s*s+c*c);if(l<1e-12)return _m(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=vm(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=vm(e,p,n,t)}return _m(e,p,i[0],i[1],i[2])}function wm(e,t,n,r,i){let a=[t];for(let o=1;o<i;o++){let i=r*o;a.push(_m(e,t,n[0]*i,n[1]*i,n[2]*i))}return a}function Tm(e,t,n,r,i,a){let o=[t];for(let s=1;s<a;s++)o.push(vm(e,t,i*s,r,n));return o}function Em(e,t,n,r,i,a,o,s){return Hf(e.gridPattern(Wf(t,`gridPattern`),n[0],n[1],n[2],r[0],r[1],r[2],i,a,o,s))}function Dm(e,t){return t.map(t=>{switch(t.type){case`translate`:return _m(e,t.shape,t.x,t.y,t.z);case`rotate`:return vm(e,t.shape,t.angle,t.axis,t.center);case`scale`:return bm(e,t.shape,t.center,t.factor);case`mirror`:return ym(e,t.shape,t.origin,t.normal)}})}function Om(e){return{transform:(t,n)=>gm(e,t,n),translate:(t,n,r,i)=>_m(e,t,n,r,i),rotate:(t,n,r,i)=>vm(e,t,n,r,i),mirror:(t,n,r)=>ym(e,t,n,r),scale:(t,n,r)=>bm(e,t,n,r),generalTransform:(t,n,r,i)=>xm(e,t,n,r,i),generalTransformNonOrthogonal:(t,n,r)=>Sm(e,t,n,r),positionOnCurve:(t,n,r)=>Cm(e,t,n,r),linearPattern:(t,n,r,i)=>wm(e,t,n,r,i),circularPattern:(t,n,r,i,a)=>Tm(e,t,n,r,i,a),gridPattern:(t,n,r,i,a,o,s)=>Em(e,t,n,r,i,a,o,s),transformBatch:t=>Dm(e,t)}}function km(e,t,n){let r=t;if(!If(t))throw Error(`brepkit: applyMatrix requires a BrepkitHandle`);switch(r.type){case`solid`:{let t=e.copySolid(r.id);return e.transformSolid(t,n),L(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),Rf(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),Bf(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),zf(t)}default:throw Error(`brepkit: applyMatrix does not support '${r.type}' shapes`)}}function Am(e,t){return!!(e&&(e[0]!==0||e[1]!==0||e[2]!==0)||t&&(t[0]!==0||t[1]!==0||t[2]!==1))}function jm(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=vm(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=vm(e,i,n,t)}}return n&&(n[0]!==0||n[1]!==0||n[2]!==0)&&(i=_m(e,i,n[0],n[1],n[2])),i}function Mm(e,t){let r,i=t;if(i.type===`solid`||i.type===`compound`){let n=yp(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=R(i,`face`),o=0;for(let t of n){let n=R(t,`face`);try{let t=e.faceArea(n,ep);t>o&&(o=t,a=n)}catch{}}r=a}else r=R(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 Nm(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 Pm(e,t){if(!If(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 Fm(e,t){if(!If(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 Im(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(R(t));return n>0&&console.warn(`brepkit: repairSolid left ${n} error(s) on solid.`),t}catch(n){try{return e.healSolid(R(t)),t}catch(e){return console.warn(`brepkit: healSolid failed (repairSolid error:`,n,`, healSolid error:`,e,`)`),null}}}function Lm(e,t){return t}function Rm(e,t,n){return t}function zm(e,t,n){let r=Wf(t,`mergeCoincidentVertices`);return e.mergeCoincidentVertices(r,n)}function Bm(e,t,n){let r=Wf(t,`removeDegenerateEdges`);return e.removeDegenerateEdges(r,n)}function Vm(e,t){let n=Wf(t,`fixFaceOrientations`);return e.fixFaceOrientations(n)}function Hm(e,t){let n=t;return n.type===`solid`&&e.healSolid(n.id),t}function Um(e,t){return t}function Wm(e,t){if(!If(t)||t.type!==`solid`)return null;try{return typeof e.validateSolidDetails==`function`?e.validateSolidDetails(t.id):null}catch{return null}}function Gm(e){return{isValid:t=>Pm(e,t),isValidStrict:t=>Fm(e,t),healSolid:t=>Im(e,t),healFace:t=>Lm(e,t),healWire:(t,n)=>Rm(e,t,n),fixShape:t=>Hm(e,t),fixSelfIntersection:t=>Um(e,t),mergeCoincidentVertices:(t,n)=>zm(e,t,n),removeDegenerateEdges:(t,n)=>Bm(e,t,n),fixFaceOrientations:t=>Vm(e,t),validationDetails:t=>Wm(e,t)}}function Km(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 qm(e,t){return t.type===`compound`?z(e.getCompoundSolids(t.id)).length===0:!1}function Jm(e){return Hf(e.makeCompound([]))}function Ym(e,t,n,r){if(r&&op(r)&&ap(`boolean-options`,`BooleanOptions (optimisation, simplify, strategy, fuzzyValue) not supported; ignored.`),qm(e,t))return n;if(qm(e,n))return t;let i=Wf(t,`fuse`),a=n;if(a.type===`compound`){let t=z(e.getCompoundSolids(a.id)),n=i;for(let r of t)n=e.fuse(n,r);return L(n)}return L(e.fuse(i,Wf(n,`fuse`)))}function Xm(e,t,n,r){if(r&&op(r)&&ap(`boolean-options`,`BooleanOptions (optimisation, simplify, strategy, fuzzyValue) not supported; ignored.`),qm(e,t))return Jm(e);if(qm(e,n))return t;let i=Wf(t,`cut`),a=n;if(a.type===`compound`){let t=z(e.getCompoundSolids(a.id)),n=i;for(let r of t)try{n=e.cut(n,r)}catch(t){if(Km(t))return Jm(e);throw t}return L(n)}try{return L(e.cut(i,Wf(n,`cut`)))}catch(t){if(Km(t))return Jm(e);throw t}}function Zm(e,t,n,r){if(r&&op(r)&&ap(`boolean-options`,`BooleanOptions (optimisation, simplify, strategy, fuzzyValue) not supported; ignored.`),qm(e,t)||qm(e,n))return Jm(e);try{return L(e.intersect(Wf(t,`intersect`),Wf(n,`intersect`)))}catch(t){if(Km(t))return Jm(e);throw t}}function Qm(e,n,r,i){let{point:a,normal:o}=Mm(e,r),s=If(n)&&n.type===`solid`?n.id:R(n,`solid`),c=z(e.section(s,a[0],a[1],a[2],o[0],o[1],o[2]));if(c.length===0)return Hf(e.makeCompound([]));let l=[];for(let n=0;n<c.length;n++){let r=z(e.getFaceWires(t(c,n)));for(let e=0;e<r.length;e++)l.push(Bf(t(r,e)))}let[u]=l;if(l.length===1&&u!==void 0)return u;let d=np();return rp.set(d,l),Hf(d)}function $m(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(...z(e.getCompoundSolids(n.id))):t.push(Wf(r,`fuseAll`))}if(t.length===0)throw Error(`brepkit: fuseAll resolved to zero solid IDs`);return L(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 eh(e,t,n,r){if(n.length===0)return t;if(n.length===1)return Xm(e,t,n[0],r);let i=Wf(t,`cutAll`),a=[];for(let t of n){let n=t;n.type===`compound`?a.push(...z(e.getCompoundSolids(n.id))):a.push(Wf(t,`cutAll`))}return a.length===0?t:L(e.compoundCut(i,new Uint32Array(a)))}function th(e,t,n){if(n.length===0)throw Error(`brepkit: split requires at least one tool`);let{point:r,normal:i}=Mm(e,n[0]),a=z(e.split(R(t,`solid`),r[0],r[1],r[2],i[0],i[1],i[2]));return Hf(e.makeCompound(a))}function nh(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 rh(e,t,n,r,i){let a=[];return(!If(t)||t.IsNull())&&a.push({operand:`base`,issue:`null-shape`,message:`Base shape is null`}),(!If(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 ih(e,n,r){let i=[];for(let r of n){let n=r;if(n.type===`solid`){let r=z(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 L(e.convexHull(i))}function ah(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 L(e.convexHull(r))}function oh(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 L(e.importIndexedMesh(a,o))}function sh(e){return{fuse:(t,n,r)=>Ym(e,t,n,r),cut:(t,n,r)=>Xm(e,t,n,r),intersect:(t,n,r)=>Zm(e,t,n,r),section:(t,n,r)=>Qm(e,t,n,r),fuseAll:(t,n)=>$m(e,t,n),cutAll:(t,n,r)=>eh(e,t,n,r),split:(t,n)=>th(e,t,n),meshBoolean:(t,n,r,i,a,o)=>nh(e,t,n,r,i,a,o),checkBoolean:(t,n,r)=>rh(e,t,n,r,t=>Pm(e,t)),hull:(t,n)=>ih(e,t,n),hullFromPoints:(t,n)=>ah(e,t,n),buildSolidFromFaces:(t,n,r)=>oh(e,t,n,r)}}function ch(e,t,n,r){return Uf(e.makeVertex(t,n,r))}function lh(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 yh(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(If(t)&&t.type===`edge`)return t;throw Error(`brepkit: makeEdge requires a curve with origin/direction, or an edge handle`)}function uh(e,t){let n=[];for(let r of t){let t=r;if(t.type===`wire`)for(let r of z(e.getWireEdges(t.id)))n.push(r);else n.push(R(r,`edge`))}return Bf(e.makeWire(n,!0))}function dh(e,t,n){let r=t,i=r.type===`edge`?e.makeWire([r.id],!0):R(t,`wire`);return Rf(n?e.makePlanarFaceFromWire(i):e.makeFaceFromWire(i))}function fh(e,t,n,r){return L(e.makeBox(t,n,r))}function ph(e,t,n){return Rf(e.makeRectangle(t,n))}function mh(e,t,n,r,i){let a=L(e.makeCylinder(t,n));return Am(r,i)?jm(e,a,r,i):a}function hh(e,t,n){let r=L(e.makeSphere(t,32));return n&&(n[0]!==0||n[1]!==0||n[2]!==0)?_m(e,r,n[0],n[1],n[2]):r}function gh(e,t,n,r,i,a){let o=L(e.makeCone(t,n,r));return Am(i,a)?jm(e,o,i,a):o}function _h(e,t,n,r,i){let a=L(e.makeTorus(t,n,32));return Am(r,i)?jm(e,a,r,i):a}function vh(e,t,n,r){let i=Math.max(t,n,r);return xm(e,hh(e,i),[t/i,0,0,0,n/i,0,0,0,r/i],[0,0,0],!1)}function yh(e,t,n){return zf(e.makeLineEdge(t[0],t[1],t[2],n[0],n[1],n[2]))}function bh(e,t,n,r){let i=Math.sqrt(n[0]**2+n[1]**2+n[2]**2);return zf(e.makeCircleEdge(t[0],t[1],t[2],n[0]/i,n[1]/i,n[2]/i,r))}function xh(e,t,n,r,i,a){let o=a-i,s=1e-9;if(o>s&&o<2*Math.PI-s){let o=Math.hypot(n[0],n[1],n[2]),s=[n[0]/o,n[1]/o,n[2]/o],c=Math.abs(s[0])<.9?[1,0,0]:[0,1,0],l=[s[1]*c[2]-s[2]*c[1],s[2]*c[0]-s[0]*c[2],s[0]*c[1]-s[1]*c[0]],u=Math.hypot(l[0],l[1],l[2]),d=[l[0]/u,l[1]/u,l[2]/u],f=[s[1]*d[2]-s[2]*d[1],s[2]*d[0]-s[0]*d[2],s[0]*d[1]-s[1]*d[0]],p=e=>{let n=Math.cos(e),i=Math.sin(e);return[t[0]+r*(n*d[0]+i*f[0]),t[1]+r*(n*d[1]+i*f[1]),t[2]+r*(n*d[2]+i*f[2])]},m=p(i),h=p(a);return zf(e.makeCircleArc3d(m[0],m[1],m[2],h[0],h[1],h[2],t[0],t[1],t[2],s[0],s[1],s[2]))}return Yh(e,t,n,r,i,a)}function Sh(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 Ch(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 yh(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=Sh(p,m,h,g,_,v);if(!y)return yh(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 zf(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 wh(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 zf(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 zf(e.makeEllipseEdge(t[0],t[1],t[2],n[0]/o,n[1]/o,n[2]/o,r,i))}function Th(e,t,n,r,i,a,o,s){return Xh(e,t,n,r,i,a,o,s)}function Eh(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 zf(e.makeNurbsEdge(c[0],c[1],c[2],l[0],l[1],l[2],r,a,s,o))}function Dh(e,t,n,r){return zf(e.makeTangentArc3d(t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]))}function Oh(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 uh(e,[Vh(e,p)])}function kh(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 z(e.getWireEdges(t.id)))n.push(r)}if(n.length===0)throw Error(`brepkit: makeWireFromMixed requires at least one edge`);return Bf(e.makeWire(n,!1))}function Ah(e,t){let n=t.filter(If);if(n.length===0)throw Error(`brepkit: makeCompound requires at least one shape`);if(n.every(e=>e.type===`solid`))return Hf(e.makeCompound(n.map(e=>e.id)));let r=np();return rp.set(r,n),Hf(r)}function jh(e,t,n){let r=fh(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?_m(e,r,i,a,o):r}function Mh(e,t){let n=t;if(n.type===`solid`)return t;if(n.type===`shell`){try{return e.getSolidFaces(n.id),L(n.id)}catch{}return L(e.solidFromShell(n.id))}return L(e.solidFromShell(R(t,`shell`)))}function Nh(e,t){return dh(e,t,!1)}function Ph(e,t,n){let r=n.map(e=>R(e,`wire`));return Rf(e.addHolesToFace(R(t,`face`),r))}function Fh(e,t){return Rf(e.removeHolesFromFace(R(t,`face`)))}function Ih(e,t,n){return dh(e,n,!1)}function Lh(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 Rf(e.interpolateSurface(i,n,r,a,o))}catch{return Rh(e,t,n,r)}}function Rh(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=zh(e,t(n,s),t(n,c),t(n,l));d&&a.push(d);let f=zh(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 Mp(e,a,1e-6)}function zh(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 dh(e,uh(e,[yh(e,t,n),yh(e,n,r),yh(e,r,t)]))}catch(e){return console.warn(`brepkit: makeNonPlanarFace failed:`,e),null}}function Bh(e,t,n){let r=t.map(e=>R(e,`face`));return L(e.sewFaces(r,n))}function Vh(e,n,r){if(r?.tolerance!==void 0&&ap(`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 yh(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 zf(e.interpolatePoints(a,i))}function Hh(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 zf(e.approximateCurveLspia(a,r,o,i,100))}function Uh(e,t,n,r){return{x:t,y:n,z:r}}function Wh(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 Gh(e,t,n,r){return{x:t,y:n,z:r}}function Kh(e,t,n,r,i,a,o){return{origin:[t,n,r],direction:[i,a,o]}}function qh(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 Jh(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 zf(e.makeNurbsEdge(b,x,S,C,w,ee,2,v,g,_))}function Xh(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 zf(e.makeNurbsEdge(y,b,x,S,C,w,2,_,h,g))}function Zh(e){return{makeVertex:(t,n,r)=>ch(e,t,n,r),makeEdge:(t,n,r)=>lh(e,t,n,r),makeWire:t=>uh(e,t),makeWireFromMixed:t=>kh(e,t),makeFace:(t,n)=>dh(e,t,n),makeBox:(t,n,r)=>fh(e,t,n,r),makeRectangle:(t,n)=>ph(e,t,n),makeCylinder:(t,n,r,i)=>mh(e,t,n,r,i),makeSphere:(t,n)=>hh(e,t,n),makeCone:(t,n,r,i,a)=>gh(e,t,n,r,i,a),makeTorus:(t,n,r,i)=>_h(e,t,n,r,i),makeEllipsoid:(t,n,r)=>vh(e,t,n,r),makeLineEdge:(t,n)=>yh(e,t,n),makeCircleEdge:(t,n,r)=>bh(e,t,n,r),makeCircleArc:(t,n,r,i,a)=>xh(e,t,n,r,i,a),makeArcEdge:(t,n,r)=>Ch(e,t,n,r),makeEllipseEdge:(t,n,r,i,a)=>wh(e,t,n,r,i,a),makeEllipseArc:(t,n,r,i,a,o,s)=>Th(e,t,n,r,i,a,o,s),makeBezierEdge:t=>Eh(e,t),makeTangentArc:(t,n,r)=>Dh(e,t,n,r),makeHelixWire:(t,n,r,i,a,o)=>Oh(e,t,n,r,i,a,o),makeCompound:t=>Ah(e,t),makeBoxFromCorners:(t,n)=>jh(e,t,n),solidFromShell:t=>Mh(e,t),makeNonPlanarFace:t=>Nh(e,t),addHolesInFace:(t,n)=>Ph(e,t,n),removeHolesFromFace:t=>Fh(e,t),makeFaceOnSurface:(t,n)=>Ih(e,t,n),bsplineSurface:(t,n,r)=>Lh(e,t,n,r),triangulatedSurface:(t,n,r)=>Rh(e,t,n,r),buildTriFace:(t,n,r)=>zh(e,t,n,r),sewAndSolidify:(t,n)=>Bh(e,t,n),interpolatePoints:(t,n)=>Vh(e,t,n),approximatePoints:(t,n)=>Hh(e,t,n),createPoint3d:(t,n,r)=>Uh(e,t,n,r),createDirection3d:(t,n,r)=>Wh(e,t,n,r),createVector3d:(t,n,r)=>Gh(e,t,n,r),createAxis1:(t,n,r,i,a,o)=>Kh(e,t,n,r,i,a,o),createAxis2:(t,n,r,i,a,o,s,c,l)=>qh(e,t,n,r,i,a,o,s,c,l),createAxis3:(t,n,r,i,a,o,s,c,l)=>Jh(e,t,n,r,i,a,o,s,c,l)}}function Qh(e,t,n,r){let i=Wf(t,`fillet`),a=n.map(e=>R(e,`edge`));if(typeof r==`number`)return L(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 L(e.filletVariable(i,JSON.stringify(o)))}function $h(e,t,n,r){let i=Wf(t,`chamfer`),a=n.map(e=>R(e,`edge`));if(typeof r==`number`)return L(e.chamfer(i,a,r));if(Array.isArray(r)){let[t,n]=r;return typeof e.chamferAsymmetric==`function`?L(e.chamferAsymmetric(i,a,t,n)):(ap(`chamfer-asymmetric`,`chamferAsymmetric not available; using averaged distance.`),L(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):(ap(`chamfer-callback`,`chamferAsymmetric not available; asymmetric edges use averaged distance.`),s=e.chamfer(s,t.ids,(t.d1+t.d2)/2));return L(s)}function eg(e,t,n,r,i){let a=r*Math.tan(i*Math.PI/180),o=Wf(t,`chamferDistAngle`),s=n.map(e=>R(e,`edge`));return typeof e.chamferAsymmetric==`function`?L(e.chamferAsymmetric(o,s,r,a)):(ap(`chamfer-dist-angle`,`chamferAsymmetric not available; using averaged distance.`),L(e.chamfer(o,s,(r+a)/2)))}function tg(e,n){let r=z(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 ng(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 rg(e,t,n){try{let r=tg(e,t);if(r===null)return null;let i=-1,a=1/0;for(let t of n)try{let n=tg(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 ig(e,t,n,r){if(r.has(t))return t;let i=ng(e,t,n);if(i!==null)return i;let a=rg(e,t,n);return a===null?t:a}function ag(e,t,n,r,i){i!==void 0&&ap(`shell-tolerance`,`shell() tolerance parameter is not supported; brepkit uses its own internal tolerance.`);let a=Wf(t,`shell`),o=z(e.getSolidFaces(a)),s=new Set(o),c=n.map(t=>ig(e,R(t,`face`),o,s));return L(e.shell(a,r,c))}function og(e,t,n){let r=t;if(r.type===`face`)return L(e.thicken(r.id,n));throw Error(`brepkit: thicken() requires a face`)}function sg(e,t,n,r){r!==void 0&&ap(`offset-tolerance`,`offset() tolerance parameter is not supported; brepkit uses its own internal tolerance.`);let i=t;if(i.type===`face`)return L(e.thicken(i.id,n));let a=Wf(t,`offset`);return L(e.offsetSolidV2(a,n))}function cg(e,t,n){let r=Wf(t,`filletVariable`);return L(e.filletVariable(r,n))}function lg(e,t,n,r,i,a){let o=Wf(t,`draft`),s=n.map(e=>R(e,`face`));return L(e.draft(o,s,r[0],r[1],r[2],i[0],i[1],i[2],a))}function ug(e,t,n){let r=Wf(t,`defeature`),i=n.map(e=>R(e,`face`));return L(e.defeature(r,i))}function dg(e){switch(e){case`arc`:case`tangent`:return`arc`;case`intersection`:return`intersection`;default:return`intersection`}}function fg(e,n,r,i){if(typeof e.offsetWire2DWithJoin==`function`)return Bf(e.offsetWire2DWithJoin(R(n,`wire`),r,dg(i)));let a=yp(e,n,`edge`);if(a.length===0)return n;let o=[];for(let n of a){let r=e.getEdgeVertices(R(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 Bf(e.makePolygonWire(c))}function pg(e,t){if(t.type===`solid`)try{e.healSolid(R(t))}catch(e){console.warn(`brepkit: healing failed in simplify:`,e)}return t}function mg(e,t){let n=t,r=e.reverseShape(n.id);return Lf(n.type,r)}function hg(e){return{fillet:(t,n,r)=>Qh(e,t,n,r),chamfer:(t,n,r)=>$h(e,t,n,r),chamferDistAngle:(t,n,r,i)=>eg(e,t,n,r,i),shell:(t,n,r,i)=>ag(e,t,n,r,i),thicken:(t,n)=>og(e,t,n),offset:(t,n,r)=>sg(e,t,n,r),filletVariable:(t,n)=>cg(e,t,n),draft:(t,n,r,i,a)=>lg(e,t,n,r,i,up(n,a)),defeature:(t,n)=>ug(e,t,n),offsetWire2D:(t,n,r)=>fg(e,t,n,r),simplify:t=>pg(e,t),reverseShape:t=>mg(e,t)}}function gg(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=L(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 _g(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 vg(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 yg(e,t,n){try{return{hash:n,normal:e.getFaceNormal(t),centroid:vg(e,t)}}catch{return{hash:n,normal:[0,0,0],centroid:vg(e,t)}}}var bg=.707,xg=100,Sg=.05;function Cg(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<bg)continue;let c=_g(e.centroid,o.centroid);if(c>xg)continue;let l=s-c/xg;l>r&&(r=l),i.push({idx:a,score:l})}return{matches:i,bestScore:r}}function wg(e,t){let n=1/0,r;for(let i of t){let t=_g(e.centroid,i.centroid);t<n&&(n=t,r=i)}return r}function Tg(e,n,r,i,a,o,s,c){let l=n;if(l.type!==`solid`)return;let u=z(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(yg(e,i,r[n]??i%a))}let p=i.map(t=>yg(e,t,t%a)),m=new Set;for(let e of p){let{matches:n,bestScore:r}=Cg(e,f);if(n.length>0){for(let i of n)if(i.score>=r-Sg){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=wg(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 Eg(e,t,n,r,i,a,o,s){let c=new Set(s),l=new Map(a);Tg(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 Dg(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 Og(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?Eg(e,l,d,f,a,o,s,c):Dg(i,r,u,t,s,c)}else if(l)Tg(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 kg(e,n,r,i,a,o){let s=n,c=new Map,l=new Map,u=new Set;if(s.type===`solid`){let n=z(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 Og(e,n,d,r,i,c,l,u,o)}return{shape:n,evolution:{modified:c,generated:l,deleted:u}}}function Ag(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 jg(e,t){let n=new Set;Ag(t.combinedModified,e.evolution.modified,e.evolution.deleted,n,t.combinedDeleted),Ag(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 Mg(e,t,n,r,i,a){let o=z(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=gg(a(t.id,e),i);s=n.shape,jg(n,c)}return{shape:s,accum:c}}function Ng(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{...gg(o(u.id,d.id),i),diagnostics:l}}catch(e){if(!Km(e))throw e}if(d.type===`compound`){let{shape:n,accum:a}=Mg(e,t,d.id,r,i,o);return{shape:n,evolution:{modified:a.combinedModified,generated:a.combinedGenerated,deleted:a.combinedDeleted},diagnostics:l}}}return{...kg(e,s(t,n,a),r,i,!1,t),diagnostics:l}}function Pg(e,t,n,r,i,a,o){return kg(e,_m(e,t,n,r,i),a,o,!0)}function Fg(e,t,n,r,i,a,o){return kg(e,vm(e,t,n*180/Math.PI,a,o),r,i,!0)}function Ig(e,t,n,r,i,a){return kg(e,ym(e,t,n,r),i,a,!0)}function Lg(e,t,n,r,i,a){return kg(e,bm(e,t,n,r),i,a,!0)}function Rg(e,t,n,r,i,a,o){return kg(e,xm(e,t,n,r,i),a,o,!0)}function zg(e,t,n,r,i,a){return Ng(e,t,n,r,i,a,(t,n)=>e.fuseWithEvolution(t,n),(t,n,r)=>Ym(e,t,n,r),`fuseWithHistory`)}function Bg(e,t,n,r,i,a){return Ng(e,t,n,r,i,a,(t,n)=>e.cutWithEvolution(t,n),(t,n,r)=>Xm(e,t,n,r),`cutWithHistory`)}function Vg(e,t,n,r,i,a){return Ng(e,t,n,r,i,a,(t,n)=>e.intersectWithEvolution(t,n),(t,n,r)=>Zm(e,t,n,r),`intersectWithHistory`)}function Hg(e,t,n,r,i,a){return kg(e,Qh(e,t,n,r),i,a,!1,t)}function Ug(e,t,n,r,i,a){return kg(e,$h(e,t,n,r),i,a,!1,t)}function Wg(e,t,n,r,i,a,o){return kg(e,ag(e,t,n,r,o),i,a,!1,t)}function Gg(e,t,n,r,i){return kg(e,og(e,t,n),r,i,!1,t)}function Kg(e,t,n,r,i,a){return kg(e,sg(e,t,n,a),r,i,!1,t)}function qg(e,t,n,r,i,a,o,s){return kg(e,lg(e,t,n,r,i,a),o,s,!1,t)}function Jg(e,t,n,r,i){return kg(e,km(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=$f(e.type===`translate`?Jf(e.x,e.y,e.z):Yf(e.angle,e.axis,e.center),n);return{handle:n,dispose:()=>{}}}function Xg(e){return{translateWithHistory:(t,n,r,i,a,o)=>Pg(e,t,n,r,i,a,o),rotateWithHistory:(t,n,r,i,a,o)=>Fg(e,t,n,r,i,a,o),mirrorWithHistory:(t,n,r,i,a)=>Ig(e,t,n,r,i,a),scaleWithHistory:(t,n,r,i,a)=>Lg(e,t,n,r,i,a),generalTransformWithHistory:(t,n,r,i,a,o)=>Rg(e,t,n,r,i,a,o),fuseWithHistory:(t,n,r,i,a)=>zg(e,t,n,r,i,a),cutWithHistory:(t,n,r,i,a)=>Bg(e,t,n,r,i,a),intersectWithHistory:(t,n,r,i,a)=>Vg(e,t,n,r,i,a),filletWithHistory:(t,n,r,i,a)=>Hg(e,t,n,r,i,a),chamferWithHistory:(t,n,r,i,a)=>Ug(e,t,n,r,i,a),shellWithHistory:(t,n,r,i,a,o)=>Wg(e,t,n,r,i,a,o),thickenWithHistory:(t,n,r,i)=>Gg(e,t,n,r,i),offsetWithHistory:(t,n,r,i,a)=>Kg(e,t,n,r,i,a),draftWithHistory:(t,n,r,i,a,o,s)=>qg(e,t,n,r,i,up(n,a),o,s),applyComposedTransformWithHistory:(t,n,r,i)=>Jg(e,t,n,r,i),composeTransform:t=>Yg(e,t)}}function Zg(e,t,n){let r=R(t),i=t,a=n.tolerance||.01,o=n.angularTolerance>0?n.angularTolerance:void 0,s;if(i.type===`solid`)s=e_(e,r,a,!!n.includeUVs,o);else if(i.type===`face`)s=a_(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 Qg(e,n,r,i){i>0&&ap(`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 $g(e,t){return!1}function e_(e,t,n,r,i){try{return t_(e,t,n,r,i)}catch(r){return console.warn(`brepkit: tessellateSolidGrouped failed (solidId=${t}), falling back to per-face:`,r),i_(e,t,n,i)}}function t_(e,t,n,r,i){return typeof e.tessellateSolidGroupedBinary==`function`?n_(e,t,n,r,i,e.tessellateSolidGroupedBinary(t,n,i)):r_(e,t,n,r,i)}function n_(e,n,r,i,a,o){let s=o.positions,c=o.normals,l=o.indices,u=o.faceOffsets,d=z(e.getSolidFaces(n)),f=u.length-1;if(f!==d.length)throw Error(`faceOffsets/faceIds length mismatch: ${f} groups vs ${d.length} faces`);let p=[];for(let e=0;e<u.length-1;e++){let n=t(u,e),r=t(u,e+1)-n;r!==0&&p.push({start:n,count:r,faceHash:d[e]??0})}let m=new Float32Array;if(i){let t=s.length/3*2;try{let i=e.tessellateSolidUV(n,r,a),o=JSON.parse(i);m=o.uvs.length===t?new Float32Array(o.uvs):new Float32Array(t)}catch{m=new Float32Array(t)}}return{vertices:s,normals:c,triangles:l,uvs:m,faceGroups:p}}function r_(e,n,r,i,a){let o=e.tessellateSolidGrouped(n,r,a),s=JSON.parse(o),c=z(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 i_(e,t,n,r){let i=z(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 a_(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 o_(e){return{mesh:(t,n)=>Zg(e,t,n),meshEdges:(t,n,r)=>Qg(e,t,n,r),hasTriangulation:t=>$g(e,t),meshShape:(e,t,n)=>{}}}function s_(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(`
|
|
8
|
+
`)}function c_(e,n,r,i=be,a=xe){let{vertices:o,triangles:s}=Zg(e,L(t(Gf(e,n,`exportSTL`),0)),{tolerance:i,angularTolerance:a,skipNormals:!0});return r?we(o,s):Te(o,s)}function l_(e,t){let n=typeof t==`string`?new TextEncoder().encode(t):new Uint8Array(t);return z(e.importStep(n)).map(L)}function u_(e,t){let n=typeof t==`string`?new TextEncoder().encode(t):new Uint8Array(t);return L(e.importStl(n))}function d_(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(`
|
|
9
|
+
`)}function f_(e,t){let n=typeof t==`string`?new TextEncoder().encode(t):new Uint8Array(t);return z(e.importIges(n)).map(L)}function p_(e,t,n){return t.length===0?``:s_(e,t.map(e=>e.shape))}function m_(e,t,n){let r=Wf(t,`export3MF`);return qf(e.export3mf(r,n))}function h_(e,t,n){let r=Wf(t,`exportGLB`);return qf(e.exportGlb(r,n))}function g_(e,t,n){let r=Wf(t,`exportOBJ`);return qf(e.exportObj(r,n))}function __(e,t,n){let r=Wf(t,`exportPLY`);return qf(e.exportPly(r,n))}function v_(e,t){return z(e.import3mf(new Uint8Array(t))).map(e=>L(e))}function y_(e,t){return L(e.importObj(new Uint8Array(t)))}function b_(e,t){return L(e.importGlb(new Uint8Array(t)))}function x_(e,t){let n=t;return n.type===`solid`?e.toBREP(n.id):(ap(`brep-non-solid`,`toBREP for non-solid shapes uses STEP format.`),s_(e,[t]))}function S_(e,t){if(typeof e.fromBREP==`function`&&t.trimStart().startsWith(`{`))return L(e.fromBREP(t));let n=l_(e,t)[0];if(!n)throw Error(`brepkit: fromBREP produced no shapes`);return n}function C_(e,t){return{__brepkit_xcaf:!0,shapes:t,delete:Ff}}function w_(e,t,n){return t&&t.__brepkit_xcaf&&Array.isArray(t.shapes)?s_(e,t.shapes.map(e=>e.shape)):``}function T_(e,t,n){return s_(e,t.map(e=>e.shape))}function E_(e){return{exportSTEP:t=>s_(e,t),exportSTL:(t,n,r,i)=>c_(e,t,n,r,i),importSTEP:t=>l_(e,t),importSTL:t=>u_(e,t),exportIGES:t=>d_(e,t),importIGES:t=>f_(e,t),exportSTEPAssembly:(t,n)=>p_(e,t,n),export3MF:(t,n)=>m_(e,t,n),exportGLB:(t,n)=>h_(e,t,n),exportOBJ:(t,n)=>g_(e,t,n),exportPLY:(t,n)=>__(e,t,n),import3MF:t=>v_(e,t),importOBJ:t=>y_(e,t),importGLB:t=>b_(e,t),toBREP:t=>x_(e,t),fromBREP:t=>S_(e,t),createXCAFDocument:t=>C_(e,t),writeXCAFToSTEP:(t,n)=>w_(e,t,n),exportSTEPConfigured:(t,n)=>T_(e,t,n)}}function D_(e,t){return{x:e,y:t}}function O_(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 k_(e,t){return{x:e,y:t}}function A_(e,t,n,r){return{px:e,py:t,dx:n,dy:r,delete:Ff}}function j_(e){return e}function M_(e){return e}function N_(e,t,n,r){return x(e,t,n,r)}function P_(e,t,n,r){return S(e,t,n,r)}function F_(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 x(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=S(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 I_(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 x(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,y=(e-p)/h,b=s*v+c*y,S;if(b>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 F_(e,t,p+h*Math.cos(S),m+h*Math.sin(S),i,a)}function L_(e,t,n,r,i,a,o){return C(e,t,n,r,i,a,o)}function R_(e,t,n,r,i,a,o,s,c){let l=C(e,t,n,r,o,s,c),u=c!==!1,d=u?i:-i,f=u?a:-a;return f<d-1e-9&&(f+=2*Math.PI),{__bk2d:`trimmed`,basis:l,tStart:d,tEnd:f}}function z_(e){return w(e)}function B_(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 V_(e,t){return _(sp(e),t)}function H_(e,t){return{point:_(sp(e),t),tangent:v(sp(e),t)}}function U_(e){return y(sp(e))}function W_(e){return b(cp(e))}function G_(e,t,n){return{__bk2d:`trimmed`,basis:sp(e),tStart:t,tEnd:n}}function K_(e){let t=e;switch(t.__bk2d){case`line`:{let e=t;e.ox+=e.dx*e.len,e.oy+=e.dy*e.len,e.dx=-e.dx,e.dy=-e.dy;break}case`circle`:case`ellipse`:{let e=t;e.sense=!e.sense;break}case`trimmed`:{let e=t;[e.tStart,e.tEnd]=[e.tEnd,e.tStart];break}case`bezier`:{let e=t;e.poles=[...e.poles].reverse();break}case`bspline`:{let e=t;e.poles=[...e.poles].reverse();let n=e.knots[0],r=e.knots[e.knots.length-1];n!==void 0&&r!==void 0&&(e.knots=e.knots.map(e=>n+r-e).reverse()),Array.isArray(e.weights)&&(e.weights=[...e.weights].reverse());break}default:break}}function q_(e){return JSON.parse(JSON.stringify(e))}function J_(e,t){let n=sp(e),r=y(n),i=[];for(let e=0;e<=30;e++){let a=r.first+(r.last-r.first)*e/30,[o,s]=_(n,a),[c,l]=v(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 B_(i)}function Y_(e,t,n){return ee(sp(e),t,n)}function X_(e,t,n,r){return te(sp(e),t,n,r)}function Z_(e,t,n,r){return ne(sp(e),t,n,r)}function Q_(e,t,n){return re(sp(e),t,n)}function $_(e,t,n,r,i){return ie(sp(e),t,n,r,i)}function ev(e,t,n,r,i,a){return uv(e,rv(t,n,r,i,a))}function tv(e,t,n){return{m:e,tx:t,ty:n,delete:Ff}}function nv(){return tv([1,0,0,0,1,0,0,0,1],0,0)}function rv(e,n,r,i,a){let o=Math.sqrt(r*r+i*i);if(o<1e-15)return nv();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 tv(u,e-t(u,0)*e-t(u,1)*n,n-t(u,3)*e-t(u,4)*n)}function iv(e,t){return tv([1,0,0,0,1,0,0,0,1],e,t)}function av(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 tv(u,d-t(u,0)*d-t(u,1)*f,f-t(u,3)*d-t(u,4)*f)}return tv([-1,0,0,0,-1,0,0,0,1],2*e,2*n)}function ov(e,t,n){let r=Math.cos(e),i=Math.sin(e);return tv([r,-i,0,i,r,0,0,0,1],t-r*t+i*n,n-i*t-r*n)}function sv(e,t,n){return tv([e,0,0,0,e,0,0,0,1],t*(1-e),n*(1-e))}function cv(e,t,n){e.tx=t,e.ty=n}function lv(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 uv(e,n){let r=sp(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 ee(r,a,o);let d=y(r),f=[];for(let e=0;e<=20;e++){let[t,n]=_(r,d.first+(d.last-d.first)*e/20);f.push([s*t+c*n+a,l*t+u*n+o])}return w(f)}function dv(e,t,n){let r=ae(sp(e),sp(t),n),i=r.segments.map(e=>Object.assign(e,{delete(){}}));return{points:r.points,segments:i}}function fv(e,t,n){let r=sp(e),i=y(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]=_(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]=_(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]=_(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]=_(r,a),[s,c]=v(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]=_(r,a);return{param:a,distance:Math.sqrt((c-t)**2+(l-n)**2)}}function pv(e,t,n,r,i,a){let o=sp(e),s=sp(t),c=n,l=i,u=1/0;for(let e=0;e<=50;e++){let t=n+(r-n)*e/50,[d,f]=_(o,t);for(let e=0;e<=50;e++){let n=i+(a-i)*e/50,[r,o]=_(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]=_(s,f),u=fv(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]=_(o,d),h=fv(t,p,m);if(h){let e=Math.max(i,Math.min(a,h.param)),t=Math.abs(e-f)<1e-12;if(f=e,t)break}}let[p,m]=_(o,d),[h,g]=_(s,f);return Math.sqrt((h-p)**2+(g-m)**2)}function mv(e,n,r,i){let a=sp(e),o=y(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(_(a,t))}u=0;for(let e=0;e<c;e++){let[n,r]=_(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 B_(l,{degMax:s})}function hv(e){let n=cp(e);if(n.__bk2d===`bezier`)return[e];if(n.__bk2d!==`bspline`)return hv(mv(e,1e-6,`C2`,10));let r=y(sp(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=_(n,r),l=_(n,i),u=v(n,r),d=v(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 gv(){return ge()}function _v(e,t,n){_e(lp(e),sp(t),n)}function vv(e){let t=lp(e);return{xMin:t.xMin,yMin:t.yMin,xMax:t.xMax,yMax:t.yMax}}function yv(e,t){let n=lp(e),r=lp(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 bv(e,t){let n=lp(e),r=lp(t);return n.xMax<r.xMin||r.xMax<n.xMin||n.yMax<r.yMin||r.yMax<n.yMin}function xv(e,t,n){let r=lp(e);return t<r.xMin||t>r.xMax||n<r.yMin||n>r.yMax}function Sv(e){let t=cp(e);return t.__bk2d===`circle`?{cx:t.cx,cy:t.cy,radius:t.radius,isDirect:t.sense}:null}function Cv(e){let t=cp(e);return t.__bk2d===`ellipse`?{majorRadius:t.majorRadius,minorRadius:t.minorRadius,xAxisAngle:t.xDirAngle,isDirect:t.sense}:null}function wv(e){let t=cp(e);return t.__bk2d===`bezier`?[...t.poles]:null}function Tv(e){let t=cp(e);return t.__bk2d===`bezier`?t.poles.length-1:null}function Ev(e){let t=cp(e);return t.__bk2d===`bspline`?{poles:[...t.poles],knots:[...t.knots],multiplicities:[...t.multiplicities],degree:t.degree,isPeriodic:t.isPeriodic}:null}function Dv(e){return me(sp(e))}function Ov(e){return he(e)}function kv(e,t){let n=sp(e),r=y(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 Av(e,n,r,i,a){let o=sp(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 yh(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=y(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]=_(o,l.first+t*f),[i,u]=_(o,l.first+(t+1)*f);p.push(e.makeCircleArc3d(...c(n,r),...c(i,u),...a,...s))}return p.length===1?zf(t(p,0)):Bf(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 yh(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 zf(e.interpolatePoints(i,r))}let l=y(o),u=[];for(let e=0;e<=100;e++){let[t,n]=_(o,l.first+(l.last-l.first)*e/100);u.push(c(t,n))}return Vh(e,u)}function jv(e,t,r){if(!If(r))throw Error(`brepkit: buildEdgeOnSurface requires a face handle as surface`);let i=R(r,`face`),a=sp(t),o=y(a),s=e.getSurfaceType(i)===`plane`?50:100,c=[];for(let t=0;t<=s;t++){let[r,l]=_(a,o.first+(o.last-o.first)*t/s);c.push(n(e.evaluateSurface(i,r,l)))}return Vh(e,c)}function Mv(e){return e}function Nv(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 Pv(e,n,r){let i=R(n,`edge`),a=R(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)}));Nv(d,u,80,.05);let f=d.map(e=>e.uv);if(f.length>=2)return B_(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 x(t(n,0),t(n,1),t(r,0),t(r,1))}throw Error(`brepkit: extractCurve2dFromEdge: degenerate edge (${p.length} coords)`)}function Fv(e,t,n){return e}function Iv(e,n,r){if(n.length>=1){let r=yp(e,n[0],`edge`);if(r.length===4){let n=[],i=[];for(let a of r){let r=R(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 Rf(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 Nh(e,i)}function Lv(e){return{createPoint2d:(e,t)=>D_(e,t),createDirection2d:(e,t)=>O_(e,t),createVector2d:(e,t)=>k_(e,t),createAxis2d:(e,t,n,r)=>A_(e,t,n,r),wrapCurve2dHandle:e=>j_(e),createCurve2dAdaptor:e=>M_(e),makeLine2d:(e,t,n,r)=>N_(e,t,n,r),makeCircle2d:(e,t,n,r)=>P_(e,t,n,r),makeArc2dThreePoints:(e,t,n,r,i,a)=>F_(e,t,n,r,i,a),makeArc2dTangent:(e,t,n,r,i,a)=>I_(e,t,n,r,i,a),makeEllipse2d:(e,t,n,r,i,a,o)=>L_(e,t,n,r,i,a,o),makeEllipseArc2d:(e,t,n,r,i,a,o,s,c)=>R_(e,t,n,r,i,a,o,s,c),makeBezier2d:e=>z_(e),makeBSpline2d:(e,t)=>B_(e,t),evaluateCurve2d:(e,t)=>V_(e,t),evaluateCurve2dD1:(e,t)=>H_(e,t),getCurve2dBounds:e=>U_(e),getCurve2dType:e=>W_(e),trimCurve2d:(e,t,n)=>G_(e,t,n),reverseCurve2d:e=>{K_(e)},copyCurve2d:e=>q_(e),offsetCurve2d:(e,t)=>J_(e,t),translateCurve2d:(e,t,n)=>Y_(e,t,n),rotateCurve2d:(e,t,n,r)=>X_(e,t,n,r),scaleCurve2d:(e,t,n,r)=>Z_(e,t,n,r),mirrorCurve2dAtPoint:(e,t,n)=>Q_(e,t,n),mirrorCurve2dAcrossAxis:(e,t,n,r,i)=>$_(e,t,n,r,i),affinityTransform2d:(e,t,n,r,i,a)=>ev(e,t,n,r,i,a),createIdentityGTrsf2d:()=>nv(),createAffinityGTrsf2d:(e,t,n,r,i)=>rv(e,t,n,r,i),createTranslationGTrsf2d:(e,t)=>iv(e,t),createMirrorGTrsf2d:(e,t,n,r,i,a,o)=>av(e,t,n,r,i,a,o),createRotationGTrsf2d:(e,t,n)=>ov(e,t,n),createScaleGTrsf2d:(e,t,n)=>sv(e,t,n),setGTrsf2dTranslationPart:(e,t,n)=>{cv(e,t,n)},multiplyGTrsf2d:(e,t)=>{lv(e,t)},transformCurve2dGeneral:(e,t)=>uv(e,t),intersectCurves2d:(e,t,n)=>dv(e,t,n),projectPointOnCurve2d:(e,t,n)=>fv(e,t,n),distanceBetweenCurves2d:(e,t,n,r,i,a)=>pv(e,t,n,r,i,a),approximateCurve2dAsBSpline:(e,t,n,r)=>mv(e,t,n,r),decomposeBSpline2dToBeziers:e=>hv(e),createBoundingBox2d:()=>gv(),addCurveToBBox2d:(e,t,n)=>{_v(e,t,n)},getBBox2dBounds:e=>vv(e),mergeBBox2d:(e,t)=>{yv(e,t)},isBBox2dOut:(e,t)=>bv(e,t),isBBox2dOutPoint:(e,t,n)=>xv(e,t,n),getCurve2dCircleData:e=>Sv(e),getCurve2dEllipseData:e=>Cv(e),getCurve2dBezierPoles:e=>wv(e),getCurve2dBezierDegree:e=>Tv(e),getCurve2dBSplineData:e=>Ev(e),serializeCurve2d:e=>Dv(e),deserializeCurve2d:e=>Ov(e),splitCurve2d:(e,t)=>kv(e,t),liftCurve2dToPlane:(t,n,r,i)=>Av(e,t,n,r,i),buildEdgeOnSurface:(t,n)=>jv(e,t,n),extractSurfaceFromFace:e=>Mv(e),extractCurve2dFromEdge:(t,n)=>Pv(e,t,n),buildCurves3d:e=>{},fixWireOnFace:(e,t,n)=>Fv(e,t,n),fillSurface:(t,n)=>Iv(e,t,n)}}function Rv(e,t){let n=t;if(n.type===`solid`)return e.volume(R(t),ep);if(n.type===`compound`){let n=yp(e,t,`solid`),r=0;for(let t of n)r+=e.volume(R(t),ep);return r}return 0}function zv(e,t){let n=t;if(n.type===`face`)return e.faceArea(R(t),ep);if(n.type===`solid`)return e.surfaceArea(R(t),ep);if(n.type===`compound`){let n=yp(e,t,`face`),r=0;for(let t of n)r+=e.faceArea(R(t),ep);return r}return 0}function Bv(e,t){let n=t;if(n.type===`edge`)return e.edgeLength(R(t));if(n.type===`face`)return e.facePerimeter(R(t));if(n.type===`wire`)return e.wireLength(n.id);throw Error(`brepkit: length() requires an edge, wire, or face`)}function Vv(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 Hv(e,t){let r=t;if(r.type===`solid`)return n(e.centerOfMass(R(t),ep));if(r.type===`face`){let n=Ip(e,t);return zp(e,t,(n.uMin+n.uMax)/2,(n.vMin+n.vMax)/2)}if(r.type===`edge`)return Vv(e,r.id);if(r.type===`vertex`)return Pp(e,t);let i=yp(e,t,`vertex`);if(i.length>0){let t=0,n=0,r=0;for(let a of i){let i=Pp(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 Uv(e,t){let n=t;return n.type===`edge`?Vv(e,n.id):Hv(e,t)}function Wv(e,t){let r=t;if(r.type===`solid`){let r=e.boundingBox(R(t));return{min:n(r,0),max:n(r,3)}}if(r.type===`vertex`){let n=Pp(e,t);return{min:[...n],max:[...n]}}let i=yp(e,t,`vertex`);if(i.length===0)return{min:[0,0,0],max:[0,0,0]};let a=Pp(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=Pp(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 Gv(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 Kv(e,r,i,a){let o=R(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 qv(e,n){let r=e.tessellateFace(R(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 Jv(e,t){let n=n=>Gv(e,t,n);return{distanceTo(e){return n(e)},dispose(){}}}function Yv(e,t,n=!1){let r=t,i=r.type===`edge`||r.type===`wire`||r.type===`face`;return{volume:Rv(e,t),area:zv(e,t),length:n&&i?Bv(e,t):0,centerOfMass:Hv(e,t),boundingBox:Wv(e,t)}}function Xv(e){return{volume:t=>Rv(e,t),area:t=>zv(e,t),length:t=>Bv(e,t),centerOfMass:t=>Hv(e,t),linearCenterOfMass:t=>Uv(e,t),boundingBox:t=>Wv(e,t),distance:(t,n)=>Gv(e,t,n),surfaceCurvature:(t,n,r)=>Kv(e,t,n,r),surfaceCenterOfMass:t=>qv(e,t),createDistanceQuery:t=>Jv(e,t),measureBulk:(t,n)=>Yv(e,t,n)}}function Zv(e){return e.sketchNew()}function Qv(e,t,n,r,i){return e.sketchAddPoint(t,n,r,i)}function $v(e,t,n){e.sketchAddConstraint(t,n)}function ey(e,t,n,r){return e.sketchSolve(t,n,r)}function ty(e,t,n,r,i){return e.sketchAddArc(t,n,r,i)}function ny(e,t){let n=e.sketchDof(t);return typeof n==`string`?n:String(n)}function ry(e){return{sketchNew:()=>Zv(e),sketchAddPoint:(t,n,r,i)=>Qv(e,t,n,r,i),sketchAddArc:(t,n,r,i)=>ty(e,t,n,r,i),sketchAddConstraint:(t,n)=>{$v(e,t,n)},sketchSolve:(t,n,r)=>ey(e,t,n,r),sketchDof:t=>ny(e,t)}}function iy(e,t,n,r){return L(e.extrude(R(t,`face`),n[0],n[1],n[2],r))}function ay(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),L(e.revolve(R(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 oy(e,t,n,r,i){let a=180/Math.PI*i;return a>360&&(a=360),L(e.revolve(R(t,`face`),n[0],n[1],n[2],r[0],r[1],r[2],a))}function sy(e,t,n,r,i){(n!==void 0||r!==void 0||i!==void 0)&&ap(`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):R(t,`face`)});return L(e.loft(a))}function cy(e){switch(e){case 0:return`rmf`;case 1:return`rightCorner`;case 2:return`roundCorner`;default:return}}function ly(e,t,n,r){let i=r?.transitionMode===void 0?void 0:cy(r.transitionMode),a=t,o=a.type===`wire`?e.makeFaceFromWire(a.id):R(t,`face`);if(n.type===`wire`){let t=yp(e,n,`edge`).map(e=>R(e,`edge`));if(i&&t.length===1){let n=t[0];if(n!==void 0)return L(e.sweepWithOptions(o,n,i,[],0,`transformed`))}return i&&t.length>1&&ap(`sweep-transition-multi-edge`,`Sweep transition mode not supported for multi-edge wires; ignored.`),L(e.sweepAlongEdges(o,t))}if(i){let t=R(n,`edge`);return L(e.sweepWithOptions(o,t,i,[],0,`transformed`))}let s=Nm(e,n);if(!s)throw Error(`brepkit: sweep spine must be an edge or wire`);return L(e.sweep(o,s.degree,s.knots,s.controlPoints,s.weights))}function uy(e,t,n){let r=t,i=r.type===`wire`?e.makeFaceFromWire(r.id):R(t,`face`);if(n.type===`wire`){let t=yp(e,n,`edge`).map(e=>R(e,`edge`));return L(e.sweepAlongEdges(i,t))}let a=Nm(e,n);if(!a)throw Error(`brepkit: pipe spine must be an edge or wire`);return L(e.pipe(i,a.degree,a.knots,a.controlPoints,a.weights))}function dy(e,t,n,r,i,a,o){let s=R(t,`face`);return L(e.helicalSweep(s,n[0],n[1],n[2],r[0],r[1],r[2],i,a,o))}function fy(e,t,n,r,i,a){let o=R(t,`face`),s=R(n,`edge`);return L(e.sweepWithOptions(o,s,r,i,a,`transformed`))}function py(e){switch(e){case`right`:return`rightCorner`;case`round`:return`roundCorner`;case`transformed`:return`rmf`;default:return}}function my(e,t,n){return n?{shape:e,firstShape:t,lastShape:t}:e}function hy(e,t,n,r){try{return L(e.sweepWithOptions(t,n,r,[],0,`transformed`))}catch(e){console.warn(`brepkit: sweepWithOptions failed, falling back to sweepSmooth/simplePipe:`,e);return}}function gy(e,t){try{if(t.type!==`wire`)return{edgeId:R(t,`edge`)};let n=yp(e,t,`edge`);if(n.length===1){let e=n[0];return e?{edgeId:R(e,`edge`)}:void 0}ap(`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 _y(e,t,n,r){let i=gy(e,n);if(i)return hy(e,t,i.edgeId,r)}function vy(e,t,n){let r=Nm(e,n);if(!(!r||r.degree<=1))try{return L(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 yy(e,t,n,r){let i=t,a=i.type===`wire`?e.makeFaceFromWire(i.id):R(t,`face`),o=!!(r&&r.shellMode),s=r?.transitionMode,c=s?py(s):void 0;if(c){let r=_y(e,a,n,c);if(r)return my(r,t,o)}return my(vy(e,a,n)||uy(e,t,n),t,o)}function by(e,t,n){let r=t.map(t=>{let n=t;return n.type===`wire`?e.makeFaceFromWire(n.id):R(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(R(n.startVertex,`vertex`));t.startPoint=[r[0],r[1],r[2]]}if(n?.endVertex){let r=e.getVertexPosition(R(n.endVertex,`vertex`));t.endPoint=[r[0],r[1],r[2]]}return L(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 L(e.loftSmooth(r))}catch(e){console.warn(`brepkit: loftSmooth failed, falling back to basic loft:`,e)}return sy(e,t)}function xy(e,t,n,r){let i={type:`extrusionLaw`,profile:t,length:n,endFactor:r,Trim(e,t,n){return i},delete:Ff};return i}function Sy(e,t,n,r,i,a,o){if(i!==null){let r=iy(e,n,Rp(e,n,0,0),i);return o?Ym(e,t,r):r}return t}function Cy(e){return{extrude:(t,n,r)=>iy(e,t,n,r),revolve:(t,n,r)=>ay(e,t,n,r),revolveVec:(t,n,r,i)=>oy(e,t,n,r,i),loft:(t,n,r,i)=>sy(e,t,n,r,i),sweep:(t,n,r)=>ly(e,t,n,r),simplePipe:(t,n)=>uy(e,t,n),helicalSweep:(t,n,r,i,a,o)=>dy(e,t,n,r,i,a,o),sweepWithOptions:(t,n,r,i,a)=>fy(e,t,n,r,i,a),sweepPipeShell:(t,n,r)=>yy(e,t,n,r),loftAdvanced:(t,n)=>by(e,t,n),buildExtrusionLaw:(t,n,r)=>xy(e,t,n,r),draftPrism:(t,n,r,i,a,o)=>Sy(e,t,n,r,i,a,o)}}function wy(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 Ty=class{oc;kernelId=`brepkit`;capabilities=r;bk;constructor(e){this.bk=e,this.oc=e;let t=this.bk;Object.assign(this,sh(t),Zh(t),Cy(t),hg(t),Om(t),o_(t),E_(t),Xv(t),Np(t),hm(t),Gm(t),Xg(t),ry(t),Lv(t),wy(t))}};function Ey(e){throw Error(`manifold: ${e} is not implemented`)}var Dy=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.profileEdge.profileWire.profileFace`.split(`.`));function Oy(e){return Dy.has(e)}function B(e,t,n){return{op:e,params:t,inputs:n,replayable:Oy(e)&&n.every(e=>e.replayable)}}function ky(e,t){return{manifold:e,node:t}}function V(e){return e.manifold}function H(e){return e.node}function Ay(e){if(e&&typeof e==`object`&&`manifold`in e&&`node`in e)return e}var jy=[`occt`,`occt-wasm`];function My(){for(let e of jy)try{return U(e)}catch{}}function Ny(e){let t=My();if(!t)throw Error(`manifold: ${e} requires a registered occt kernel; none is available`);return t}var Py=new WeakMap,Fy=[0,0,0],Iy=[0,0,1];function Ly(e){return Math.hypot(e[0],e[1],e[2])}function Ry(e){let t=Ly(e);return t===0?[...Iy]:[e[0]/t,e[1]/t,e[2]/t]}function zy(e){let[t,n,r]=Ry(e);return[0,180/Math.PI*Math.atan2(Math.hypot(t,n),r),180/Math.PI*Math.atan2(n,t)]}function By(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(zy(n))),(t[0]!==0||t[1]!==0||t[2]!==0)&&(r=r.translate(t)),r}return{makeBox:(e,n,r)=>ky(t.cube([e,n,r],!1),B(`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 ky(t.cube(r,!1).translate(i),B(`makeBoxWithCorners`,{p1:e,p2:n},[]))},makeCylinder:(e,r,i=Fy,a=Iy)=>ky(n(t.cylinder(r,e,e,0,!1),i,a),B(`makeCylinder`,{radius:e,height:r,center:i,direction:a},[])),makeSphere:(e,n=Fy)=>{let r=t.sphere(e,0);return(n[0]!==0||n[1]!==0||n[2]!==0)&&(r=r.translate(n)),ky(r,B(`makeSphere`,{radius:e,center:n},[]))},makeCone:(e,r,i,a=Fy,o=Iy)=>ky(n(t.cylinder(i,e,r,0,!1),a,o),B(`makeCone`,{radius1:e,radius2:r,height:i,center:a,direction:o},[])),makeTorus:(r,i,a=Fy,o=Iy)=>{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 ky(n(t.revolve([c],0),a,o),B(`makeTorus`,{majorRadius:r,minorRadius:i,center:a,direction:o},[]))},makeEllipsoid:(e,n,r)=>ky(t.sphere(1,0).scale([e,n,r]),B(`makeEllipsoid`,{aLength:e,bLength:n,cLength:r},[])),makeRectangle:()=>Ey(`makeRectangle`)}}function Vy(e){return e}function Hy(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=H(Vy(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 Wy(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 Gy(e){let t=e.Manifold;function n(e,t,n){let r=Vy(e),i=Vy(t);return ky(V(r).add(V(i)),B(`makeFuse`,{},[H(r),H(i)]))}function r(e,t,n){let r=Vy(e),i=Vy(t);return ky(V(r).subtract(V(i)),B(`makeCut`,{},[H(r),H(i)]))}function i(e,t,n){let r=Vy(e),i=Vy(t);return ky(V(r).intersect(V(i)),B(`makeCommon`,{},[H(r),H(i)]))}function a(e,n){if(e.length===0)throw Error(`manifold: fuseAll requires at least one shape`);let r=e.map(Vy),[i]=r;if(i===void 0)throw Error(`manifold: fuseAll requires at least one shape`);return r.length===1?i:ky(t.union(r.map(V)),B(`makeFuse`,{},r.map(H)))}function o(e,n,r){let i=Vy(e);if(n.length===0)return i;let a=n.map(Vy);return ky(t.difference([V(i),...a.map(V)]),B(`makeCut`,{},[H(i),...a.map(H)]))}function s(e,t,n){let r=Vy(e),{normal:i,offset:a}=Uy(t),[o]=V(r).splitByPlane(i,a);return ky(o,B(`section`,{normal:i,offset:a},[H(r),H(Vy(t))]))}function c(e,n){let r=Vy(e),[i]=n;if(i===void 0)throw Error(`manifold: split requires at least one tool`);let a=Vy(i),{normal:o,offset:s}=Uy(i),[c,l]=V(r).splitByPlane(o,s);return ky(t.union([c,l]),B(`split`,{normal:o,offset:s},[H(r),H(a)]))}function l(e,t,n){let r=[],i=Vy(e),a=Vy(t);return(V(i)===void 0||V(i).isEmpty())&&r.push({operand:`base`,issue:`null-shape`,message:`Base shape is empty`}),(V(a)===void 0||V(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 Wy(Hy(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 Ky(e){return e}function qy(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function Jy(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 Yy(e,t,n){let r=qy();return r[12]=e,r[13]=t,r[14]=n,r}function Xy(e,t,n){let r=e,[i,a,o]=Jy(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=qy();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 Zy(e,t){let n=qy();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 Qy(e,t){let[n,r,i]=Jy(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=qy();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 $y(e,t){let n=qy();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 eb(e,t,n,r,i){return ky(e.transform(t),B(n,r,[i]))}function tb(e,t,n,r){let i=Ky(e);return eb(V(i),Yy(t,n,r),`translateShape`,{x:t,y:n,z:r},H(i))}function nb(e,t,n=[0,0,1],r=[0,0,0]){let i=Ky(e);return eb(V(i),Xy(t,n,r),`rotateShape`,{angle:t,axis:n,center:r},H(i))}function rb(e,t,n){let r=Ky(e);return eb(V(r),Qy(t,n),`mirrorShape`,{origin:t,normal:n},H(r))}function ib(e,t,n){let r=Ky(e);return eb(V(r),Zy(t,n),`scaleShape`,{center:t,factor:n},H(r))}function ab(e,t){if(!Array.isArray(t)||t.length!==16)throw Error(`manifold: transform expects a 16-element column-major matrix`);let n=Ky(e);return eb(V(n),t,`transformShape`,{matrix:[...t]},H(n))}function ob(e,t,n,r){let i=Ky(e);return eb(V(i),$y(t,n),`generalTransform`,{linear:t,translation:n,isOrthogonal:r},H(i))}function sb(e,t,n){let r=Ky(e);return eb(V(r),$y(t,n),`generalTransformNonOrthogonal`,{linear:t,translation:n},H(r))}function cb(e){let t=qy();for(let n of e)t=mb(n.type===`translate`?Yy(n.x,n.y,n.z):Xy(n.angle*Math.PI/180,n.axis??[0,0,1],n.center??[0,0,0]),t);return{handle:t,dispose:()=>{}}}function lb(e,t,n,r){let i=[e];for(let a=1;a<r;a++){let r=n*a;i.push(tb(e,t[0]*r,t[1]*r,t[2]*r))}return i}function ub(e,t,n,r,i){let a=[e];for(let o=1;o<i;o++)a.push(nb(e,r*o*Math.PI/180,n,t));return a}function db(e,t,n,r,i,a,o,s){let c=Ky(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(V(c).transform(Yy(o,s,d))),u.push(H(c))}return ky(l.length===1?l[0]:e.Manifold.union(l),B(`gridPattern`,{directionX:n,directionY:r,spacingX:i,spacingY:a,countX:o,countY:s},u))}function fb(e){return e.map(e=>{switch(e.type){case`translate`:return tb(e.shape,e.x,e.y,e.z);case`rotate`:return nb(e.shape,e.angle*Math.PI/180,e.axis,e.center);case`scale`:return ib(e.shape,e.center,e.factor);case`mirror`:return rb(e.shape,e.origin,e.normal)}})}function pb(e){return{composeTransform:cb,transform:ab,translate:tb,rotate:nb,mirror:rb,scale:ib,generalTransform:ob,generalTransformNonOrthogonal:sb,positionOnCurve:()=>Ey(`positionOnCurve`),linearPattern:lb,circularPattern:ub,gridPattern:(t,n,r,i,a,o,s)=>db(e,t,n,r,i,a,o,s),transformBatch:fb}}function mb(e,t){let n=qy();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}var hb=2*Math.PI,gb=e=>Math.hypot(e[0],e[1],e[2]),_b=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]];function vb(e){return gb(_b(e.p2,e.p1))}function yb(e,t){let n=e.map(e=>[e[0],e[1],e[2]]);for(let e=1;e<n.length;e++)for(let r=0;r<n.length-e;r++){let e=n[r]??[0,0,0],i=n[r+1]??[0,0,0];n[r]=[e[0]*(1-t)+i[0]*t,e[1]*(1-t)+i[1]*t,e[2]*(1-t)+i[2]*t]}return n[0]??[0,0,0]}function bb(e){return e.k===`line`?`LINE`:e.k===`bezier`?`BEZIER`:e.k===`helix`?`BSPLINE`:Math.abs(e.rx-e.ry)<1e-9*Math.max(1,e.rx)?`CIRCLE`:`ELLIPSE`}function xb(e){return e.k===`line`?{first:0,last:vb(e)}:e.k===`conic`?{first:e.a0,last:e.a1}:e.k===`helix`?{first:0,last:hb*e.turns}:{first:0,last:1}}function Sb(e,t){if(e.k===`line`){let n=t/(vb(e)||1);return[e.p1[0]+(e.p2[0]-e.p1[0])*n,e.p1[1]+(e.p2[1]-e.p1[1])*n,e.p1[2]+(e.p2[2]-e.p1[2])*n]}if(e.k===`bezier`)return yb(e.points,t);if(e.k===`helix`){let n=Math.cos(t),r=Math.sin(t),i=e.pitch*t/hb;return[e.center[0]+e.radius*(n*e.x[0]+r*e.y[0])+i*e.axis[0],e.center[1]+e.radius*(n*e.x[1]+r*e.y[1])+i*e.axis[1],e.center[2]+e.radius*(n*e.x[2]+r*e.y[2])+i*e.axis[2]]}let n=Math.cos(t),r=Math.sin(t);return[e.center[0]+e.rx*n*e.x[0]+e.ry*r*e.y[0],e.center[1]+e.rx*n*e.x[1]+e.ry*r*e.y[1],e.center[2]+e.rx*n*e.x[2]+e.ry*r*e.y[2]]}function Cb(e,t){let n;if(e.k===`line`)n=_b(e.p2,e.p1);else if(e.k===`bezier`){let r=yb(e.points,Math.max(0,t-1e-4));n=_b(yb(e.points,Math.min(1,t+1e-4)),r)}else if(e.k===`helix`){let r=Math.cos(t),i=Math.sin(t),a=e.pitch/hb;n=[e.radius*(-i*e.x[0]+r*e.y[0])+a*e.axis[0],e.radius*(-i*e.x[1]+r*e.y[1])+a*e.axis[1],e.radius*(-i*e.x[2]+r*e.y[2])+a*e.axis[2]]}else{let r=Math.cos(t),i=Math.sin(t);n=[-e.rx*i*e.x[0]+e.ry*r*e.y[0],-e.rx*i*e.x[1]+e.ry*r*e.y[1],-e.rx*i*e.x[2]+e.ry*r*e.y[2]]}let r=gb(n)||1;return[n[0]/r,n[1]/r,n[2]/r]}function wb(e){if(e.k===`line`)return vb(e);if(e.k===`helix`){let t=hb*e.radius;return e.turns*Math.sqrt(t*t+e.pitch*e.pitch)}if(e.k===`conic`){let t=Math.abs(e.a1-e.a0);if(Math.abs(e.rx-e.ry)<1e-9*Math.max(1,e.rx))return e.rx*t;if(Math.abs(t-hb)<1e-9){let t=e.rx,n=e.ry,r=(t-n)*(t-n)/((t+n)*(t+n));return Math.PI*(t+n)*(1+3*r/(10+Math.sqrt(4-3*r)))}return Ob(t=>Sb(e,t),e.a0,e.a1,256)}return Ob(t=>Sb(e,t),0,1,128)}function Tb(e){return e.k===`conic`?Math.abs(Math.abs(e.a1-e.a0)-hb)<1e-9:!1}function Eb(e){return Tb(e)}function Db(e){return e.k===`conic`?hb:0}function Ob(e,t,n,r){let i=0,a=e(t);for(let o=1;o<=r;o++){let s=e(t+(n-t)*o/r);i+=gb(_b(s,a)),a=s}return i}function kb(e){return e}function Ab(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function jb(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 Mb(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function Nb(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function Pb(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function Fb(e){return Math.hypot(e[0],e[1],e[2])}function Ib(e){let t=Fb(e);return t<1e-12?[0,0,1]:[e[0]/t,e[1]/t,e[2]/t]}function Lb(e){return Ib(jb(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function Rb(e){let t=Ib(e),n=Lb(t);return{xAxis:n,yAxis:Ib(jb(t,n))}}function zb(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 Bb(e){return zb(e)<0?[...e].reverse():e}function Vb(e){return zb(e)>0?[...e].reverse():e}function Hb(e){return e.node?.params}function Ub(e){let t=kb(e),n=Hb(t),r=n?.outline??n?.polygon??n?.points;if(r&&r.length>=3){let e=n?.origin??[0,0,0],t=Bb(r.map(e=>[e[0],e[1]])),i=(n?.holes)?.filter(e=>e.length>=3).map(e=>Vb(e.map(e=>[e[0],e[1]])));if(n?.xAxis&&n.yAxis)return{outline:t,holes:i,origin:e,xAxis:n.xAxis,yAxis:n.yAxis};let{xAxis:a,yAxis:o}=Rb(n?.normal??[0,0,1]);return{outline:t,holes:i,origin:e,xAxis:a,yAxis:o}}return Wb(t)}function Wb(e){let t=V(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=Gb(i);return{outline:Bb(o.length>=3?o:[[-.5,-.5],[.5,-.5],[0,.5]]),origin:[0,0,a],xAxis:[1,0,0],yAxis:[0,1,0]}}function Gb(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 Kb(e){let t=[];for(let n=1;n+1<e;n++)t.push(0,n,n+1);return t}function qb(e,t){let n=e.length;if(n<2||t<=n)return e.map(e=>[e[0],e[1]]);let r=[],i=0;for(let t=0;t<n;t++){let a=e[t]??[0,0],o=e[(t+1)%n]??[0,0],s=Math.hypot(o[0]-a[0],o[1]-a[1]);r.push(s),i+=s}if(i===0)return e.map(e=>[e[0],e[1]]);let a=t-n,o=r.map(e=>a*e/i),s=o.map(e=>Math.floor(e)),c=s.reduce((e,t)=>e+t,0),l=o.map((e,t)=>({i:t,f:e-Math.floor(e)})).sort((e,t)=>t.f-e.f);for(let e=0;c<a;e++,c++){let t=l[e%l.length]?.i??0;s[t]=(s[t]??0)+1}let u=[];for(let t=0;t<n;t++){let r=e[t]??[0,0],i=e[(t+1)%n]??[0,0];u.push([r[0],r[1]]);let a=s[t]??0;for(let e=1;e<=a;e++){let t=e/(a+1);u.push([r[0]+(i[0]-r[0])*t,r[1]+(i[1]-r[1])*t])}}return u}function Jb(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 Yb(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=Zb(t.length,n),a=new e.Mesh({numProp:3,vertProperties:Float32Array.from(r),triVerts:Uint32Array.from(i)});return Xb(e,new e.Manifold(a))}function Xb(e,t){if(typeof t.volume!=`function`||t.volume()>=0)return t;let n=t.getMesh(),r=n.triVerts;for(let e=0;e+2<r.length;e+=3){let t=r[e+1]??0;r[e+1]=r[e+2]??0,r[e+2]=t}let i=new e.Mesh({numProp:n.numProp,vertProperties:n.vertProperties,triVerts:r}),a=new e.Manifold(i);return typeof t.delete==`function`&&t.delete(),a}function Zb(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=Kb(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=Kb(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 Qb(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 Ib(Mb(e[Math.min(e.length-1,t+1)]??e[t]??[0,0,0],n))},i=r(0),a=Ib(Mb(t,Pb(i,Ab(t,i))));Fb(a)<1e-9&&(a=Lb(i)),n.push({origin:e[0]??[0,0,0],xAxis:a,yAxis:Ib(jb(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=Mb(s,o),l=Ab(c,c),u=a;if(l>1e-18){let e=Mb(a,Pb(c,2/l*Ab(c,a))),n=Mb(i,Pb(c,2/l*Ab(c,i))),o=Mb(r(t),n),s=Ab(o,o);u=s>1e-18?Mb(e,Pb(o,2/s*Ab(o,e))):e}let d=r(t),f=Ib(Mb(u,Pb(d,Ab(u,d)))),p=Ib(jb(d,f));n.push({origin:s,xAxis:f,yAxis:p,tangent:d}),i=d,a=f}return n}var $b=24,ex=24,tx=null;function nx(e){let t=tx?tx(Math.max(Math.abs(e),1e-6)):$b;return Math.max($b,t)}var rx=[0,0,0],ix=1e-6,ax={delete:()=>{},isEmpty:()=>!1};function ox(e,t){return e[t]??rx}function sx(e,t=1){return Math.max(2,Math.ceil(Math.abs(e)/(2*Math.PI)*nx(t)))}function cx(e){return Ib(jb(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function lx(e,t,n,r,i,a){let o=Ib(t),s=a?Ib(a):cx(o),c=Ib(jb(o,s)),l=i-r,u=sx(l,n),d=[];for(let t=0;t<=u;t++){let i=r+l*t/u;d.push(Nb(e,Nb(Pb(s,n*Math.cos(i)),Pb(c,n*Math.sin(i)))))}return d}function ux(e,t,n){let r=Mb(t,e),i=Mb(n,e),a=jb(r,i);if(Fb(a)<1e-12)return[e,t,n];let o=Ib(a),s=Ab(r,r),c=Ab(i,i),l=Ab(r,i),u=2*(s*c-l*l);if(Math.abs(u)<1e-18)return[e,t,n];let d=c*(s-l)/u,f=s*(c-l)/u,p=Nb(e,Nb(Pb(r,d),Pb(i,f))),m=Fb(Mb(e,p)),h=Ib(Mb(e,p)),g=Ib(jb(o,h)),_=(e=>Math.atan2(Ab(Mb(e,p),g),Ab(Mb(e,p),h)))(n);return _<0&&(_+=2*Math.PI),lx(p,o,m,0,_,h)}function dx(e){let t=[];for(let n=0;n<=ex;n++){let r=n/ex,i=e.map(e=>[...e]);for(let e=1;e<i.length;e++)for(let t=0;t<i.length-e;t++){let e=ox(i,t),n=ox(i,t+1);i[t]=[e[0]*(1-r)+n[0]*r,e[1]*(1-r)+n[1]*r,e[2]*(1-r)+n[2]*r]}t.push(ox(i,0))}return t}function fx(e){let t=0,n=0,r=0;for(let i=0;i<e.length;i++){let a=ox(e,i),o=ox(e,(i+1)%e.length);t+=(a[1]-o[1])*(a[2]+o[2]),n+=(a[2]-o[2])*(a[0]+o[0]),r+=(a[0]-o[0])*(a[1]+o[1])}let i=[t,n,r];return Fb(i)<1e-12?[0,0,1]:Ib(i)}function px(e,t){return Fb(Mb(e,t))<ix}function mx(e){let t=e[0];if(!t)return[];let n=[...t];for(let t=1;t<e.length;t++){let r=e[t]??[];if(r.length===0)continue;let i=ox(n,n.length-1),a=px(ox(r,0),i),o=px(ox(r,r.length-1),i);!a&&o&&(r=[...r].reverse());let s=px(ox(r,0),i);for(let e=+!!s;e<r.length;e++)n.push(ox(r,e))}return n.length>1&&px(ox(n,0),ox(n,n.length-1))&&n.pop(),n}function hx(e){let t=fx(e),n=ox(e,0),r=e.length>1?Ib(Mb(ox(e,1),n)):cx(t);r=Ib(Mb(r,Pb(t,Ab(r,t)))),Fb(r)<1e-9&&(r=cx(t));let i=Ib(jb(t,r));return{outline:Bb(e.map(e=>{let t=Mb(e,n);return[Ab(t,r),Ab(t,i)]})),origin:n,xAxis:r,yAxis:i}}var gx=12;function _x(e,t){let[n,r]=e.curveParameters(t),i=gx;try{e.curveType(t)===`line`&&(i=1)}catch{}let a=[];for(let o=0;o<=i;o++)a.push(e.curvePointAtParam(t,n+(r-n)*o/i));return a}function vx(e,t){return mx(e.iterShapes(t,`edge`).map(t=>_x(e,t)))}function yx(e){let t=e.getCircularSegments;typeof t==`function`&&(tx=e=>t(e));function n(e,t){return ky(ax,B(`profileEdge`,t?{pts:e,curve:t}:{pts:e},[]))}function r(e,t){let n=Ib(e),r=t?Ib(t):cx(n);return{x:r,y:Ib(jb(n,r))}}function i(e,t,n){let r=Mb(t,e),i=Mb(n,e),a=jb(r,i);if(Fb(a)<1e-12)return;let o=Ib(a),s=Ab(r,r),c=Ab(i,i),l=Ab(r,i),u=2*(s*c-l*l);if(Math.abs(u)<1e-18)return;let d=c*(s-l)/u,f=s*(c-l)/u,p=Nb(e,Nb(Pb(r,d),Pb(i,f))),m=Fb(Mb(e,p)),h=Ib(Mb(e,p)),g=Ib(jb(o,h)),_=Math.atan2(Ab(Mb(n,p),g),Ab(Mb(n,p),h));return _<0&&(_+=2*Math.PI),{k:`conic`,center:p,x:h,y:g,rx:m,ry:m,a0:0,a1:_}}function a(e){let t=Ay(e);if(t){let e=t.node.params;return e?.ring??e?.pts??[]}let n=My();return n?_x(n,e):[]}function o(e){let t=[];for(let n of e){let e=Ay(n);e&&t.push(H(e))}return t}function s(e){let t=mx(e.map(e=>a(e)));return ky(ax,B(`profileWire`,{ring:t,...t.length>=3?hx(t):void 0},o(e)))}function c(e,t){let{outline:n,origin:r,xAxis:i,yAxis:a}=hx(e);return ky(ax,B(`profileFace`,{outline:n,origin:r,xAxis:i,yAxis:a},t?[t]:[]))}function l(e){let t=Ay(e);if(t){let e=t.node.params?.ring??[];if(e.length>=3)return c(e,H(t))}let n=My();return c(n?vx(n,e):[],t?H(t):void 0)}function u(e,t){let n=Ay(e),r=n?.node?.params??{},i=r.origin??rx,a=r.xAxis??[1,0,0],s=r.yAxis??[0,1,0],c=e=>{let t=Mb(e,i);return[Ab(t,a),Ab(t,s)]},l=[];for(let e of t){let t=Ay(e),n;if(t)n=t.node.params?.ring??[];else{let t=My();n=t?vx(t,e):[]}n.length>=3&&l.push(n.map(c))}let u=[...r.holes??[],...l],d=n?[H(n),...o(t)]:o(t);return ky(ax,B(`profileFace`,{outline:r.outline??[],holes:u,origin:i,xAxis:a,yAxis:s},d))}function d(e,t,n,r,i){let a=Ib(t),o=i?Ib(i):cx(a),s=Ib(jb(a,o)),c=[],l=nx(Math.max(n,r));for(let t=0;t<=l;t++){let i=2*Math.PI*t/l;c.push(Nb(e,Nb(Pb(o,n*Math.cos(i)),Pb(s,r*Math.sin(i)))))}return c}return{makeVertex:(e,t,r)=>n([[e,t,r]]),makeLineEdge:(e,t)=>n([e,t],{k:`line`,p1:e,p2:t}),makeCircleEdge:(e,t,i)=>{let{x:a,y:o}=r(t);return n(lx(e,t,i,0,2*Math.PI),{k:`conic`,center:e,x:a,y:o,rx:i,ry:i,a0:0,a1:2*Math.PI})},makeCircleArc:(e,t,i,a,o)=>{let{x:s,y:c}=r(t);return n(lx(e,t,i,a,o),{k:`conic`,center:e,x:s,y:c,rx:i,ry:i,a0:a,a1:o})},makeArcEdge:(e,t,r)=>n(ux(e,t,r),i(e,t,r)),makeEllipseEdge:(e,t,i,a,o)=>{let{x:s,y:c}=r(t,o);return n(d(e,t,i,a,o),{k:`conic`,center:e,x:s,y:c,rx:i,ry:a,a0:0,a1:2*Math.PI})},makeBezierEdge:e=>n(dx(e),{k:`bezier`,points:e.map(e=>[...e])}),makeTangentArc:(e,t,r)=>n([e,r],{k:`line`,p1:e,p2:r}),makeHelixWire:(e,t,r,i=[0,0,0],a=[0,0,1],o=!1)=>{let s=Ib(a),c=cx(s),l=Ib(jb(s,c)),u=o?Pb(l,-1):l,d=e===0?0:t/e,f={k:`helix`,center:i,axis:s,x:c,y:u,radius:r,pitch:e,turns:d},p=Math.max(8,Math.ceil(d*$b)),m=[];for(let e=0;e<=p;e++)m.push(Sb(f,2*Math.PI*d*e/p));return n(m,f)},makeWire:e=>s(e),makeWireFromMixed:e=>s(e),makeFace:l,addHolesInFace:u,makePolygonFace:e=>c(e)}}function bx(e){let t=e.Manifold,n=yx(e);function r(e,n){let r=e.map(e=>[e.x,e.y,e.z]);return ky(t.hull(r),B(`hullFromPoints`,{points:r,tolerance:n},[]))}function i(e,n){let r=e.map(e=>V(e));return ky(t.hull(r),B(`hull`,{tolerance:n},e.map(e=>H(e))))}function a(e){let n=e.map(e=>V(e)),r=n[0];if(!r)throw Error(`manifold: makeCompound requires at least one input shape`);return ky(n.length===1?r:t.union(n),B(`makeCompound`,{},e.map(e=>H(e))))}function o(e,t){let n=e[0];return n||Ey(`sewAndSolidify (no input faces on manifold kernel)`),ky(V(n),B(`sewAndSolidify`,{tolerance:t},e.map(e=>H(e))))}return{makeVertex:(e,t,r)=>n.makeVertex(e,t,r),makeEdge:()=>Ey(`makeEdge`),makeWire:e=>n.makeWire(e),makeFace:(e,t)=>n.makeFace(e,t),makeLineEdge:(e,t)=>n.makeLineEdge(e,t),makeCircleEdge:(e,t,r)=>n.makeCircleEdge(e,t,r),makeCircleArc:(e,t,r,i,a)=>n.makeCircleArc(e,t,r,i,a),makeArcEdge:(e,t,r)=>n.makeArcEdge(e,t,r),makeEllipseEdge:(e,t,r,i,a)=>n.makeEllipseEdge(e,t,r,i,a),makeEllipseArc:()=>Ey(`makeEllipseArc`),makeBezierEdge:e=>n.makeBezierEdge(e),makeTangentArc:(e,t,r)=>n.makeTangentArc(e,t,r),makeHelixWire:(e,t,r,i,a,o)=>n.makeHelixWire(e,t,r,i,a,o),makeWireFromMixed:e=>n.makeWireFromMixed(e),makeCompound:a,solidFromShell:()=>Ey(`solidFromShell`),hull:i,hullFromPoints:r,buildSolidFromFaces:()=>Ey(`buildSolidFromFaces`),makeNonPlanarFace:()=>Ey(`makeNonPlanarFace`),addHolesInFace:(e,t)=>n.addHolesInFace(e,t),removeHolesFromFace:()=>Ey(`removeHolesFromFace`),makeFaceOnSurface:()=>Ey(`makeFaceOnSurface`),bsplineSurface:(e,t,n)=>Ny(`bsplineSurface`).bsplineSurface(e,t,n),triangulatedSurface:(e,t,n)=>Ny(`triangulatedSurface`).triangulatedSurface(e,t,n),buildTriFace:()=>Ey(`buildTriFace`),sewAndSolidify:o,createPoint3d:()=>Ey(`createPoint3d`),createDirection3d:()=>Ey(`createDirection3d`),createVector3d:()=>Ey(`createVector3d`),createAxis1:()=>Ey(`createAxis1`),createAxis2:()=>Ey(`createAxis2`),createAxis3:()=>Ey(`createAxis3`)}}var xx=Math.PI/180;function Sx(e){return e}function Cx(e){let t=180/Math.PI*e;return t>360?360:t}function wx(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 Tx(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=wx(n.Location()),t=wx(n.Direction());if(e&&t)return{origin:e,direction:t}}}}function Ex(e){return e.outline.map(e=>[e[0],e[1]])}function Dx(e){return{outline:e.outline,origin:e.origin,xAxis:e.xAxis,yAxis:e.yAxis}}function Ox(e){return{origin:e.origin,xAxis:e.xAxis,yAxis:e.yAxis,tangent:Ib(jb(e.xAxis,e.yAxis))}}function kx(e){let t=0;for(let n of e.outline)t=Math.max(t,Math.hypot(n[0],n[1]));return t||1}function Ax(e){let t=V(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 jx(e,t){let n=Sx(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=Ax(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 Mx(e){return e?.node??B(`spine`,{},[])}function Nx(e,t,n){let r=t.xAxis,i=t.yAxis,a=t.origin,o=[r[0],r[1],r[2],0,i[0],i[1],i[2],0,n[0],n[1],n[2],0,a[0],a[1],a[2],1];return e.transform(o)}function Px(e,t,n){let r=Ib(n);return e.outline.map(n=>{let i=Mb(Nb(e.origin,Nb(Pb(e.xAxis,n[0]),Pb(e.yAxis,n[1]))),t),a=i[0]*r[0]+i[1]*r[1]+i[2]*r[2];return[Fb(Mb(i,Pb(r,a))),a]})}function Fx(e,t,n){let r=e,i=Ib(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=jb([0,1,0],i);Fb(t)<1e-9&&(t=[1,0,0]),t=Ib(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 Ix(e,t,n,r,i){let a=Ib(t),{xAxis:o,yAxis:s}=Rb(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=Nb(Pb(o,n*Math.cos(i)),Pb(s,n*Math.sin(i)));d.push(Nb(e,Nb(f,Pb(a,u*r))))}return d}function Lx(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 Rx(e,t,n,r){let i=Ub(t),a=Ib([n[0],n[1],n[2]]),o=Fb([n[0]*r,n[1]*r,n[2]*r]),s=[Ex(i),...(i.holes??[]).map(e=>e.map(e=>[e[0],e[1]]))];return ky(Nx(Xb(e,e.Manifold.extrude(s,o)),i,a),B(`extrude`,{outline:i.outline,holes:i.holes,origin:i.origin,xAxis:i.xAxis,yAxis:i.yAxis,direction:[n[0],n[1],n[2]],length:r},[H(Sx(t))]))}function zx(e,t,n,r,i,a,o){let s=Ub(t),c=Cx(i),l=Px(s,n,r);return ky(Fx(e.Manifold.revolve([l],0,c),n,r),B(a,o,[H(Sx(t))]))}function Bx(e,t){let n=e.length;if(n===0||t.length!==n)return e;let r=0,i=1/0;for(let a=0;a<n;a++){let o=0;for(let r=0;r<n&&o<i;r++){let i=e[(r+a)%n]??[0,0,0],s=t[r]??[0,0,0],c=i[0]-s[0],l=i[1]-s[1],u=i[2]-s[2];o+=c*c+l*l+u*u}o<i&&(i=o,r=a)}if(r===0)return e;let a=[];for(let t=0;t<n;t++)a.push(e[(t+r)%n]??[0,0,0]);return a}function Vx(e,t,n,r){if(t.length<2)throw Error(`manifold: loft requires at least two profiles`);let i=t.map(Ub),a=i.reduce((e,t)=>Math.max(e,t.outline.length),0),o=i.map(e=>Jb({...e,outline:qb(e.outline,a)},Ox(e)));for(let e=1;e<o.length;e++)o[e]=Bx(o[e]??[],o[e-1]??[]);return ky(Yb(e,o),B(n,{sections:i.map(Dx),...r},t.map(e=>H(Sx(e)))))}function Hx(e,t,n,r,i,a,o){let s=Ub(t),c=Qb(n,s.xAxis),l=c.length;return ky(Yb(e,c.map((e,t)=>Jb(s,e,o?o(l>1?t/(l-1):0):1))),B(i,{section:Dx(s),path:n.map(e=>[e[0],e[1],e[2]]),...a},[H(Sx(t)),r]))}function Ux(e,t,n,r,i,a){if(r===null)return t;let o=Ub(n),s=Ib(jb(o.xAxis,o.yAxis)),c=Math.tan(i*xx),l={origin:Nb(o.origin,Pb(s,r)),xAxis:o.xAxis,yAxis:o.yAxis,tangent:s},u=1+c*r/kx(o),d=Yb(e,[Jb(o,Ox(o),1),Jb(o,l,u)]),f=B(`draftPrism`,{outline:o.outline,origin:o.origin,xAxis:o.xAxis,yAxis:o.yAxis,height:r,angleDeg:i,fuse:a},[H(Sx(n))]);if(a){let e=Sx(t);return ky(V(e).add(d),B(`makeFuse`,{},[H(e),f]))}return ky(d,f)}function Wx(e){return{revolve:(t,n,r)=>{let i=Tx(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 zx(e,t,a,o,r,`revolve`,{...Dx(Ub(t)),axisOrigin:[a[0],a[1],a[2]],axisDirection:[o[0],o[1],o[2]],angleDeg:Cx(r)})},revolveVec:(t,n,r,i)=>zx(e,t,n,r,i,`revolveVec`,{...Dx(Ub(t)),center:[n[0],n[1],n[2]],direction:[r[0],r[1],r[2]],angleDeg:Cx(i)})}}function Gx(e){return{sweep:(t,n,r)=>{let i={};return r?.transitionMode!==void 0&&(i.transitionMode=r.transitionMode),Hx(e,t,jx(n,16),Mx(n),`sweep`,i)},simplePipe:(t,n)=>Hx(e,t,jx(n,16),Mx(n),`simplePipe`,{}),sweepWithOptions:(t,n,r,i,a)=>Hx(e,t,jx(n,Math.max(2,a||16)),Mx(n),`sweepWithOptions`,{contactMode:r,scaleValues:[...i],segments:a},Lx(i)),sweepPipeShell:(t,n,r)=>{let i={};r?.transitionMode!==void 0&&(i.transitionMode=r.transitionMode);let a=Hx(e,t,jx(n,16),Mx(n),`sweepPipeShell`,i);return r?.shellMode?{shape:a,firstShape:t,lastShape:t}:a},helicalSweep:(t,n,r,i,a,o)=>Hx(e,t,Ix(n,r,i,a,o),Mx(t),`helicalSweep`,{axisOrigin:[n[0],n[1],n[2]],axisDirection:[r[0],r[1],r[2]],radius:i,pitch:a,turns:o})}}function Kx(e){return{extrude:(t,n,r)=>Rx(e,t,n,r),...Wx(e),loft:(t,n)=>Vx(e,t,`loft`,{ruled:n??!1}),loftAdvanced:(t,n)=>Vx(e,t,`loftAdvanced`,{solid:n?.solid??!0,ruled:n?.ruled??!1,tolerance:n?.tolerance}),...Gx(e),draftPrism:(t,n,r,i,a,o)=>Ux(e,t,n,i,a,o),buildExtrusionLaw:(e,t,n)=>({type:`extrusionLaw`,profile:e,length:t,endFactor:n}),loftBatch:()=>Ey(`loftBatch`),extrudeBatch:t=>t.map(t=>Rx(e,t.face,t.direction,t.length))}}var qx=16;function Jx(e){return typeof e?.translate==`function`?e.translate([0,0,0]):e}function Yx(e,t,n){if(!(n>0))return Jx(t);let r=Qx(e,n);return r===void 0||typeof t?.minkowskiDifference!=`function`||typeof t?.minkowskiSum!=`function`?Jx(t):t.minkowskiDifference(r).minkowskiSum(r)}function Xx(e,t,n){if(n===0)return Jx(t);let r=Qx(e,Math.abs(n));return r===void 0?Jx(t):n>0?typeof t?.minkowskiSum==`function`?t.minkowskiSum(r):Jx(t):typeof t?.minkowskiDifference==`function`?t.minkowskiDifference(r):Jx(t)}function Zx(e,t,n,r){if(n===0)return Jx(t);if(r)return Xx(e,t,Math.abs(n));let i=Xx(e,t,-Math.abs(n));return typeof t?.subtract==`function`?t.subtract(i):Jx(t)}function Qx(e,t){let n=e?.Manifold;if(typeof n?.sphere==`function`)return n.sphere(t,qx)}function $x(e){return e}function eS(e){let t=e;if(t!=null){if(typeof t.index==`number`)return t.index;if(typeof t.id==`number`)return t.id}}function tS(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 nS(e){let t=e;if(t?.box!==void 0)return tS(t.box);let n=(e?.manifold)?.boundingBox?.();return n===void 0?void 0:tS(n)}function rS(e){let t=e.length;if(t===0)return{kind:`all`,count:t};let n=[];for(let t of e){let e=nS(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=eS(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 iS(e){return typeof e==`function`&&Ey(`fillet (per-edge radius callback)`),e}function aS(e){return typeof e==`number`?e:e[0]}function oS(e){let t=e.match(/[-+]?\d*\.?\d+/);return t?Number(t[0]):0}function sS(e,t,n,r,i){let a=$x(n),o=iS(i),s=rS(r);return ky(Yx(e,V(a),aS(o)),B(t,{radius:o,selection:s},[H(a)]))}function cS(e,t,n,r,i){let a=$x(t),o=rS(n);return ky(Yx(e,V(a),r),B(`chamferDistAngle`,{distance:r,angleDeg:i,selection:o},[H(a)]))}function lS(e,t,n){let r=t.node;if(r?.op!==`extrude`)return;let i=r.params??{},a=i.outline,o=i.origin,s=i.direction,c=i.length;if(!a||a.length<3||!o||!s||typeof c!=`number`)return;let l=Math.abs(n);try{let n=new e.CrossSection([a.map(e=>[e[0],e[1]])]).offset(-l);if(typeof n.isEmpty==`function`&&n.isEmpty())return;let r=e.Manifold.extrude(n,c),i=Math.hypot(s[0],s[1],s[2])||1,u=Math.abs(s[0])<1e-9&&Math.abs(s[1])<1e-9&&s[2]>0,d=r;if(!u){let e=Math.atan2(Math.hypot(s[0],s[1]),s[2])*(180/Math.PI),t=Math.atan2(s[1],s[0])*(180/Math.PI);d=d.rotate([0,e,t])}return d=d.translate([o[0]+s[0]/i*l,o[1]+s[1]/i*l,o[2]+s[2]/i*l]),Xb(e,V(t).subtract(d))}catch{return}}function uS(e,t,n,r,i){let a=$x(t),o=rS(n);return ky(lS(e,a,r)??Zx(e,V(a),r,!1),B(`shell`,i===void 0?{thickness:r,selection:o}:{thickness:r,selection:o,tolerance:i},[H(a)]))}function dS(e,t,n){let r=$x(t);return ky(Zx(e,V(r),n,!0),B(`thicken`,{thickness:n},[H(r)]))}function fS(e,t,n,r){let i=$x(t);return ky(Xx(e,V(i),n),B(`offset`,r===void 0?{distance:n}:{distance:n,tolerance:r},[H(i)]))}function pS(e,t,n){let r=$x(t);return ky(Yx(e,V(r),oS(n)),B(`filletVariable`,{spec:n},[H(r)]))}function mS(e,t,n,r,i){typeof i==`function`&&Ey(`draft (per-face angle callback)`);let a=$x(e),o=rS(t);return ky(Jx(V(a)),B(`draft`,{pullDirection:n,neutralPlane:r,angleDeg:i,selection:o},[H(a)]))}function hS(e,t){let n=$x(e),r=rS(t);return ky(Jx(V(n)),B(`defeature`,{selection:r},[H(n)]))}function gS(e){let t=$x(e),n=V(t);return ky(typeof n?.simplify==`function`?n.simplify():Jx(n),B(`simplify`,{},[H(t)]))}function _S(e){let t=$x(e),n=V(t);return ky(typeof n?.mirror==`function`?n.mirror([1,0,0]):Jx(n),B(`reverseShape`,{},[H(t)]))}function vS(e,t){let n=$x(t.shape),r=rS(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 ky(Yx(e,V(n),a),B(`fillet`,{radii:i,selection:r},[H(n)]))}function yS(e){return{fillet:(t,n,r)=>sS(e,`fillet`,t,n,r),chamfer:(t,n,r)=>sS(e,`chamfer`,t,n,r),chamferDistAngle:(t,n,r,i)=>cS(e,t,n,r,i),shell:(t,n,r,i)=>uS(e,t,n,r,i),thicken:(t,n)=>dS(e,t,n),offset:(t,n,r)=>fS(e,t,n,r),filletVariable:(t,n)=>pS(e,t,n),draft:(e,t,n,r,i)=>mS(e,t,n,r,i),defeature:(e,t)=>hS(e,t),offsetWire2D:()=>Ey(`offsetWire2D`),simplify:e=>gS(e),reverseShape:e=>_S(e),shellBatch:t=>t.map(t=>uS(e,t.shape,t.faces,t.thickness,t.tolerance)),filletBatch:t=>t.map(t=>vS(e,t))}}function bS(e){return V(e).getMesh()}function xS(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 SS(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 CS(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 wS(e,t){let n=bS(e),r=xS(n),i=new Uint32Array(n.triVerts);return{vertices:r,normals:t.skipNormals?new Float32Array:SS(r,i),triangles:i,uvs:t.includeUVs?new Float32Array(r.length/3*2):new Float32Array,faceGroups:CS(n)}}function TS(e,t,n){let r=bS(e),i=xS(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 ES(e){return!0}function DS(e){return{mesh:(e,t)=>wS(e,t),meshEdges:(e,t,n)=>TS(e,t,n),hasTriangulation:e=>ES(e),meshShape:(e,t,n)=>{}}}function OS(e,t=[0,0,0]){return Array.isArray(e)&&e.length>=3?[Number(e[0]),Number(e[1]),Number(e[2])]:[...t]}function kS(e,t=0){return typeof e==`number`?e:t}function AS(e,t=``){return typeof e==`string`?e:t}function jS(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function MS(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function NS(e,t,n,r){return jS(t,jS(MS(n,e[0]),MS(r,e[1])))}function PS(e,t){let n=t.outline??[];if(n.length<3)throw Error(`manifold replay: profile outline needs at least three points`);let r=OS(t.origin),i=OS(t.xAxis,[1,0,0]),a=OS(t.yAxis,[0,1,0]),o=n.map(e=>NS(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 FS(e,t){return PS(e,t)}function IS(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 LS(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 RS(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=>IS(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=LS(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(IS(e,t)))}function zS(e){let t=e.selection;return t===void 0?void 0:t}function BS(e){let t=e[0];if(t===void 0)throw Error(`manifold replay: op requires an input shape`);return t}function VS(e,t,n){return e.createAxis1(t[0],t[1],t[2],n[0],n[1],n[2])}function HS(e,t){return(n,r)=>{let i=PS(n,r),a=OS(r[e]),o=OS(r[t],[0,0,1]),s=kS(r.angleDeg,360);return n.revolve(i,VS(n,a,o),Math.PI/180*s)}}var US={makeBox:(e,t)=>e.makeBox(kS(t.width),kS(t.height),kS(t.depth)),makeBoxWithCorners:(e,t)=>e.makeBoxFromCorners(OS(t.p1),OS(t.p2)),makeCylinder:(e,t)=>e.makeCylinder(kS(t.radius),kS(t.height),OS(t.center),OS(t.direction,[0,0,1])),makeSphere:(e,t)=>e.makeSphere(kS(t.radius),OS(t.center)),makeCone:(e,t)=>e.makeCone(kS(t.radius1),kS(t.radius2),kS(t.height),OS(t.center),OS(t.direction,[0,0,1])),makeTorus:(e,t)=>e.makeTorus(kS(t.majorRadius),kS(t.minorRadius),OS(t.center),OS(t.direction,[0,0,1])),makeEllipsoid:(e,t)=>e.makeEllipsoid(kS(t.aLength),kS(t.bLength),kS(t.cLength)),makeFuse:(e,t,n)=>{if(n.length<2)return BS(n);let r=BS(n);for(let t of n.slice(1))r=e.fuse(r,t);return r},makeCut:(e,t,n)=>{let r=BS(n);return e.cutAll(r,n.slice(1))},makeCommon:(e,t,n)=>{let r=BS(n);for(let t of n.slice(1))r=e.intersect(r,t);return r},translateShape:(e,t,n)=>e.translate(BS(n),kS(t.x),kS(t.y),kS(t.z)),rotateShape:(e,t,n)=>e.rotate(BS(n),kS(t.angle),OS(t.axis,[0,0,1]),OS(t.center)),scaleShape:(e,t,n)=>e.scale(BS(n),OS(t.center),kS(t.factor,1)),mirrorShape:(e,t,n)=>e.mirror(BS(n),OS(t.origin),OS(t.normal,[1,0,0])),transformShape:(e,t,n)=>e.transform(BS(n),t.matrix),generalTransform:(e,t,n)=>e.generalTransform(BS(n),t.linear,OS(t.translation),!!t.isOrthogonal),generalTransformNonOrthogonal:(e,t,n)=>e.generalTransformNonOrthogonal(BS(n),t.linear,OS(t.translation)),gridPattern:(e,t,n)=>{if(typeof e.gridPattern!=`function`)throw Error(`manifold replay: target kernel lacks gridPattern`);return e.gridPattern(BS(n),OS(t.directionX),OS(t.directionY),kS(t.spacingX),kS(t.spacingY),kS(t.countX,1),kS(t.countY,1))},profileEdge:(e,t)=>{let n=t.pts??[],r=n[0]??[0,0,0],i=n.length>1?n[n.length-1]??r:[r[0]+.001,r[1],r[2]];return e.makeLineEdge([r[0],r[1],r[2]],[i[0],i[1],i[2]])},profileWire:(e,t)=>{let n=t.ring??[],r=[];for(let t=0;t<n.length;t++){let i=n[t]??[0,0,0],a=n[(t+1)%n.length]??i;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},profileFace:(e,t)=>PS(e,t),extrude:(e,t)=>{let n=PS(e,t);return e.extrude(n,OS(t.direction,[0,0,1]),kS(t.length,1))},revolve:HS(`axisOrigin`,`axisDirection`),revolveVec:HS(`center`,`direction`),loft:(e,t)=>{let n=(t.sections??[]).map(t=>WS(e,t));return e.loft(n,!!t.ruled)},loftAdvanced:(e,t)=>{let n=(t.sections??[]).map(t=>WS(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(GS(e,t),KS(e,t)),simplePipe:(e,t)=>e.simplePipe(GS(e,t),KS(e,t)),sweepWithOptions:(e,t)=>e.sweepWithOptions(GS(e,t),KS(e,t),AS(t.contactMode),t.scaleValues??[],kS(t.segments,0)),sweepPipeShell:(e,t)=>{let n=e.sweepPipeShell(GS(e,t),KS(e,t));return qS(n)?n.shape:n},helicalSweep:(e,t)=>e.helicalSweep(GS(e,t),OS(t.axisOrigin),OS(t.axisDirection,[0,0,1]),kS(t.radius),kS(t.pitch),kS(t.turns,1)),draftPrism:(e,t)=>{let n=PS(e,t);return e.draftPrism(n,n,n,kS(t.height),kS(t.angleDeg),!!t.fuse)},fillet:(e,t,n)=>{let r=BS(n),i=RS(e,r,zS(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=BS(n),i=RS(e,r,zS(t),`edge`);return e.chamfer(r,i,t.radius)},chamferDistAngle:(e,t,n)=>{let r=BS(n),i=RS(e,r,zS(t),`edge`);return e.chamferDistAngle(r,i,kS(t.distance),kS(t.angleDeg))},shell:(e,t,n)=>{let r=BS(n),i=RS(e,r,zS(t),`face`);return typeof t.tolerance==`number`?e.shell(r,i,kS(t.thickness),t.tolerance):e.shell(r,i,kS(t.thickness))},thicken:(e,t,n)=>e.thicken(BS(n),kS(t.thickness)),offset:(e,t,n)=>typeof t.tolerance==`number`?e.offset(BS(n),kS(t.distance),t.tolerance):e.offset(BS(n),kS(t.distance)),filletVariable:(e,t,n)=>e.filletVariable(BS(n),AS(t.spec)),draft:(e,t,n)=>{let r=BS(n),i=RS(e,r,zS(t),`face`);return e.draft(r,i,OS(t.pullDirection,[0,0,1]),OS(t.neutralPlane),kS(t.angleDeg))},defeature:(e,t,n)=>{let r=BS(n),i=RS(e,r,zS(t),`face`);return e.defeature(r,i)},simplify:(e,t,n)=>e.simplify(BS(n)),reverseShape:(e,t,n)=>e.reverseShape(BS(n)),hull:(e,t,n)=>e.hull([...n],kS(t.tolerance)),hullFromPoints:(e,t)=>{let n=t.points??[];return e.hullFromPoints(n.map(e=>({x:e[0],y:e[1],z:e[2]})),kS(t.tolerance))},sewAndSolidify:(e,t,n)=>e.sewAndSolidify([...n],kS(t.tolerance))};function WS(e,t){let n=FS(e,t);return e.iterShapes(n,`wire`)[0]??n}function GS(e,t){let n=t.section;return n?FS(e,n):PS(e,t)}function KS(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 qS(e){return typeof e==`object`&&!!e&&`shape`in e&&`firstShape`in e&&`lastShape`in e}function JS(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=US[e.op];if(!a)throw Error(`manifold replay: no replay handler for op '${e.op}'`);let o=e.inputs.map(e=>JS(e,t,n,r)),s=a(t,e.params,o);return n.set(e,s),r.add(s),s}function YS(e,t,n=new Map){let r=new Set,i=JS(e,t,n,r);for(let e of r)e!==i&&t.dispose(e);return i}function XS(e){return V(e)}function ZS(e){let t=e?.node?.params;if(!t)return;let n=t.pts??t.ring;if(n&&n.length)return n;let r=t.outline;if(r&&r.length){let e=t.origin??[0,0,0],n=t.xAxis??[1,0,0],i=t.yAxis??[0,1,0];return r.map(t=>[e[0]+n[0]*t[0]+i[0]*t[1],e[1]+n[1]*t[0]+i[1]*t[1],e[2]+n[2]*t[0]+i[2]*t[1]])}}function QS(e){let t=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0];for(let r of e)for(let e=0;e<3;e++){let i=r[e]??0;i<(t[e]??1/0)&&(t[e]=i),i>(n[e]??-1/0)&&(n[e]=i)}return{min:t,max:n}}function $S(e){let t=e;if(t&&t.__manifoldSub&&t.box)return t.box;let n=ZS(e);return n?QS(n):XS(e).boundingBox()}function eC(e){return XS(e)?.getMesh?.()}function tC(e,t){let n=t*e.numProp;return[e.vertProperties[n]??0,e.vertProperties[n+1]??0,e.vertProperties[n+2]??0]}function nC(e,t){let n=t*3;return[e.triVerts[n]??0,e.triVerts[n+1]??0,e.triVerts[n+2]??0]}function rC(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 iC(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function aC(e){let t=$S(e);return[(t.min[0]+t.max[0])/2,(t.min[1]+t.max[1])/2,(t.min[2]+t.max[2])/2]}function oC(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=tC(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 sC(e){let t=eC(e);if(!t)return aC(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]=nC(t,e),s=tC(t,n),c=tC(t,a),l=tC(t,o),u=iC(s,rC(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?oC(t):[i[0]/r,i[1]/r,i[2]/r]}function cC(e){let t=eC(e);if(!t)return aC(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]=nC(t,e),s=tC(t,n),c=tC(t,a),l=tC(t,o),u=rC([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?oC(t):[i[0]/r,i[1]/r,i[2]/r]}function lC(e){return XS(e).volume()}function uC(e){let t=e;return t&&t.__nativeFace&&typeof t.area==`number`?t.area:XS(e).surfaceArea()}function dC(e){let t=e;if(t&&t.__manifoldSub&&t.box)return{min:[...t.box.min],max:[...t.box.max]};let n=$S(e);return{min:[...n.min],max:[...n.max]}}function fC(e){return sC(e)}function pC(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 mC(e,t){return pC($S(e),$S(t))}function hC(e,t=!1){return{volume:lC(e),area:uC(e),length:0,centerOfMass:fC(e),boundingBox:dC(e)}}function gC(e,t,n){let r=My();if(!r)throw Error(`manifold: surfaceCurvature requires a registered occt kernel; none is available`);let i=Ay(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=Py.get(i.node)??(()=>{let e=YS(i.node,r);return Py.set(i.node,e),e})();return r.surfaceCurvature(a,t,n)}function _C(e){return{volume:e=>lC(e),area:e=>uC(e),length:e=>{let t=e;if(t&&t.__nativeEdge&&typeof t.length==`number`)return t.length;let n=Ay(e)?.node;return n?.op===`profileEdge`&&n.params?.curve?wb(n.params.curve):Ey(`length`)},centerOfMass:e=>fC(e),linearCenterOfMass:e=>fC(e),boundingBox:e=>dC(e),distance:(e,t)=>mC(e,t),surfaceCurvature:(e,t,n)=>gC(e,t,n),surfaceCenterOfMass:e=>cC(e),measureBulk:(e,t)=>hC(e,t),createDistanceQuery:e=>({distanceTo:t=>mC(e,t),dispose:()=>{}})}}function vC(e,t){let{runIndex:n,runOriginalID:r}=e;if(!n||!r)return 0;let i=t*3;for(let e=0;e<r.length;e++){let t=n[e]??0,a=n[e+1]??2**53-1;if(i>=t&&i<a)return r[e]??0}return 0}function yC(e){let t=e,n=t.triVerts,r=t.vertProperties,i=t.numProp||3,a=t.faceID,o=n.length/3,s=e=>{let t=e*i;return[r[t]??0,r[t+1]??0,r[t+2]??0]},c=new Map;for(let e=0;e<o;e++){let t=a?a[e]??e:e,n=c.get(t);n||(n=[],c.set(t,n)),n.push(e)}let l=[];for(let[e,r]of c){let i=0,a=0,o=0,c=0,u=0,d=0,f=0,p=1/0,m=1/0,h=1/0,g=-1/0,_=-1/0,v=-1/0,y=new Float32Array(r.length*9),b=0;for(let e of r){let t=s(n[e*3]??0),r=s(n[e*3+1]??0),l=s(n[e*3+2]??0),x=r[0]-t[0],S=r[1]-t[1],C=r[2]-t[2],w=l[0]-t[0],ee=l[1]-t[1],te=l[2]-t[2],ne=S*te-C*ee,re=C*w-x*te,ie=x*ee-S*w;i+=ne,a+=re,o+=ie;let ae=.5*Math.hypot(ne,re,ie);f+=ae;let oe=(t[0]+r[0]+l[0])/3,se=(t[1]+r[1]+l[1])/3,ce=(t[2]+r[2]+l[2])/3;c+=ae*oe,u+=ae*se,d+=ae*ce;for(let e of[t,r,l])e[0]<p&&(p=e[0]),e[1]<m&&(m=e[1]),e[2]<h&&(h=e[2]),e[0]>g&&(g=e[0]),e[1]>_&&(_=e[1]),e[2]>v&&(v=e[2]),y[b++]=e[0],y[b++]=e[1],y[b++]=e[2]}let x=Math.hypot(i,a,o)||1,S=[i/x,a/x,o/x],C=f>0?[c/f,u/f,d/f]:[0,0,0];l.push({__nativeFace:!0,faceId:e,originId:vC(t,r[0]??0),normal:S,center:C,area:f,min:[p,m,h],max:[g,_,v],tris:y})}return l}function bC(e){return!!e&&typeof e==`object`&&e.__nativeFace===!0}var xC=Math.cos(45*Math.PI/180),SC=(e,t)=>e<t?e*1e9+t:t*1e9+e,CC=(e,t)=>e<t?`${e},${t}`:`${t},${e}`;function wC(e){let t=e,n=t.triVerts,r=t.vertProperties,i=t.numProp||3,a=t.faceID,o=n.length/3;if(!a)return[];let s=e=>{let t=e*i;return[r[t]??0,r[t+1]??0,r[t+2]??0]},c=e=>{let t=s(n[e*3]??0),r=s(n[e*3+1]??0),i=s(n[e*3+2]??0),a=r[0]-t[0],o=r[1]-t[1],c=r[2]-t[2],l=i[0]-t[0],u=i[1]-t[1],d=i[2]-t[2],f=o*d-c*u,p=c*l-a*d,m=a*u-o*l,h=Math.hypot(f,p,m)||1;return[f/h,p/h,m/h]},l=new Map;for(let e=0;e<o;e++){let t=n[e*3]??0,r=n[e*3+1]??0,i=n[e*3+2]??0,o=a[e]??e,s=c(e);for(let[e,n]of[[t,r],[r,i],[i,t]]){let t=SC(e,n),r=l.get(t);r||(r={v:[e,n],faces:[],nrm:[]},l.set(t,r)),r.faces.push(o),r.nrm.push(s)}}let u=new Map;for(let{v:e,faces:t,nrm:n}of l.values()){if(t.length!==2)continue;let[r,i]=t;if(r===i)continue;let[a,o]=n;if(a[0]*o[0]+a[1]*o[1]+a[2]*o[2]>xC)continue;let s=CC(r,i),c=u.get(s);c||(c={faces:r<i?[r,i]:[i,r],segs:[]},u.set(s,c)),c.segs.push(e)}let d=[];for(let{faces:e,segs:t}of u.values())for(let n of TC(t))d.push(EC(e,n,s));return d}function TC(e){let t=new Map,n=new Set,r=(e,n)=>{let r=t.get(e);r||(r=[],t.set(e,r)),r.push(n)};e.forEach(([e,t],n)=>{r(e,n),r(t,n)});let i=(t,n)=>{let r=e[t]??[n,n];return r[0]===n?r[1]:r[0]},a=[];for(let r=0;r<e.length;r++){if(n.has(r))continue;n.add(r);let o=e[r]??[0,0],s=[o[0],o[1]];for(let r=0;r<e.length;r++){let e=s[s.length-1]??0,r=(t.get(e)??[]).find(e=>!n.has(e));if(r===void 0)break;n.add(r),s.push(i(r,e))}for(let r=0;r<e.length;r++){let e=s[0]??0,r=(t.get(e)??[]).find(e=>!n.has(e));if(r===void 0)break;n.add(r),s.unshift(i(r,e))}a.push(s)}return a}function EC(e,t,n){let r=t.length,i=new Float32Array(r*3),a=new Float32Array(r),o=1/0,s=1/0,c=1/0,l=-1/0,u=-1/0,d=-1/0,f=0,p=null;for(let e=0;e<r;e++){let r=n(t[e]??0);i[e*3]=r[0],i[e*3+1]=r[1],i[e*3+2]=r[2],p&&(f+=Math.hypot(r[0]-p[0],r[1]-p[1],r[2]-p[2])),a[e]=f,p=r,r[0]<o&&(o=r[0]),r[1]<s&&(s=r[1]),r[2]<c&&(c=r[2]),r[0]>l&&(l=r[0]),r[1]>u&&(u=r[1]),r[2]>d&&(d=r[2])}return{__nativeEdge:!0,faces:e,pts:i,arc:a,length:f,min:[o,s,c],max:[l,u,d],curveType:DC(i)?`LINE`:`CIRCLE`}}function DC(e){let t=e.length/3;if(t<=2)return!0;let n=e[0]??0,r=e[1]??0,i=e[2]??0,a=e[(t-1)*3]??0,o=e[(t-1)*3+1]??0,s=e[(t-1)*3+2]??0,c=a-n,l=o-r,u=s-i,d=Math.hypot(c,l,u)||1;c/=d,l/=d,u/=d;for(let a=1;a<t-1;a++){let t=(e[a*3]??0)-n,o=(e[a*3+1]??0)-r,s=(e[a*3+2]??0)-i,f=t*c+o*l+s*u,p=t-f*c,m=o-f*l,h=s-f*u;if(Math.hypot(p,m,h)>1e-6*Math.max(1,d))return!1}return!0}function OC(e){let t=e,n=t.triVerts,r=t.vertProperties,i=t.numProp||3,a=t.faceID;if(!a)return[];let o=n.length/3,s=new Map;for(let e=0;e<o;e++){let t=a[e]??e;for(let r=0;r<3;r++){let i=n[e*3+r]??0,a=s.get(i);a||(a=new Set,s.set(i,a)),a.add(t)}}let c=[];for(let[e,t]of s){if(t.size<3)continue;let n=e*i;c.push({__nativeVertex:!0,point:[r[n]??0,r[n+1]??0,r[n+2]??0]})}return c}function kC(e){return!!e&&typeof e==`object`&&e.__nativeVertex===!0}function AC(e){return!!e&&typeof e==`object`&&e.__nativeEdge===!0}function jC(e,t){let{pts:n,arc:r}=e,i=r.length;if(i===0)return[0,0,0];if(t<=0)return[n[0]??0,n[1]??0,n[2]??0];if(t>=e.length)return[n[(i-1)*3]??0,n[(i-1)*3+1]??0,n[(i-1)*3+2]??0];let a=1;for(;a<i&&(r[a]??0)<t;)a++;let o=r[a-1]??0,s=r[a]??o,c=s>o?(t-o)/(s-o):0,l=(a-1)*3,u=a*3;return[(n[l]??0)+((n[u]??0)-(n[l]??0))*c,(n[l+1]??0)+((n[u+1]??0)-(n[l+1]??0))*c,(n[l+2]??0)+((n[u+2]??0)-(n[l+2]??0))*c]}function MC(e,t){let{pts:n,arc:r}=e,i=r.length;if(i<2)return[1,0,0];let a=1;for(;a<i-1&&(r[a]??0)<t;)a++;let o=(a-1)*3,s=a*3,c=(n[s]??0)-(n[o]??0),l=(n[s+1]??0)-(n[o+1]??0),u=(n[s+2]??0)-(n[o+2]??0),d=Math.hypot(c,l,u)||1;return[c/d,l/d,u/d]}function NC(e,t){let n=Ay(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=Ny(t),i=Py.get(n.node);if(i!==void 0)return{occt:r,brep:i};let a=YS(n.node,r);return Py.set(n.node,a),{occt:r,brep:a}}function PC(e){if(Ay(e))return`solid`;let{occt:t,brep:n}=NC(e,`shapeType`);return t.shapeType(n)}function FC(e,t){let n=Ay(e),r=Ay(t);return!n||!r?!1:n.manifold===r.manifold}function IC(e,t){if(!Ay(e))return 0;let{occt:n,brep:r}=NC(e,`hashCode`);return n.hashCode(r,t)}function LC(e){let t=Ay(e);return t?!V(t):!0}function RC(e,t){let n=Ay(e);if(!n)return[];if(t===`solid`)return[e];if(t===`vertex`){let e=V(n);return e&&typeof e.getMesh==`function`?OC(e.getMesh()).map((e,t)=>({...e,__manifoldSub:!0,index:t,box:{min:e.point,max:e.point},parent:n.node,subType:`vertex`})):[]}if(t!==`edge`&&t!==`face`)return[];if(t===`face`){let e=V(n);if(e&&typeof e.getMesh==`function`)return yC(e.getMesh()).map((e,t)=>({...e,__manifoldSub:!0,index:t,box:{min:e.min,max:e.max},parent:n.node,subType:`face`}))}if(t===`edge`){let e=V(n);if(e&&typeof e.getMesh==`function`)return wC(e.getMesh()).map((e,t)=>({...e,__manifoldSub:!0,index:t,box:{min:e.min,max:e.max},parent:n.node,subType:`edge`}))}if(!n.node.replayable)return[];let r=My();if(!r)return[];let i=Py.get(n.node)??(()=>{let e=YS(n.node,r);return Py.set(n.node,e),e})();return r.iterShapes(i,t).map((e,i)=>({__manifoldSub:!0,index:i,box:r.boundingBox(e),occt:e,parent:n.node,subType:t}))}function zC(e){let{occt:t,brep:n}=NC(e,`edgeToFaceMap`);return t.edgeToFaceMap(n)}function BC(e,t){let{occt:n,brep:r}=NC(e,`adjacentFaces`);return n.adjacentFaces(r,t)}function VC(e){return{iterShapes:RC,iterShapeList:(e,t)=>{Ny(`iterShapeList`).iterShapeList(e,t)},shapeType:PC,isSame:FC,isEqual:FC,downcast:e=>e,hashCode:IC,isNull:LC,shapeOrientation:e=>`forward`,edgeToFaceMap:zC,sharedEdges:(e,t)=>Ny(`sharedEdges`).sharedEdges(e,t),adjacentFaces:BC,sew:()=>{throw Error(`manifold: sew is unsupported on the mesh kernel; use a B-rep kernel`)}}}function HC(e){return V(e).getMesh()}function UC(e){return e.numProp&&e.numProp>=3?e.numProp:3}function WC(e){return Math.floor(e.vertProperties.length/UC(e))}function GC(e,t){let n=t*UC(e);return[e.vertProperties[n]??0,e.vertProperties[n+1]??0,e.vertProperties[n+2]??0]}function KC(e,t){let n=t*3;return[e.triVerts[n]??0,e.triVerts[n+1]??0,e.triVerts[n+2]??0]}function qC(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 JC(e,t){let n=HC(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]=KC(n,e),s=GC(n,r),c=GC(n,a),l=GC(n,o),u=qC(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]=KC(n,e),o=GC(n,t),s=GC(n,r),c=GC(n,a),l=qC(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(`
|
|
10
10
|
`)}function YC(e){let t=HC(e),n=WC(t),r=Math.floor(t.triVerts.length/3),i=[`# exported by brepjs manifold kernel`];for(let e=0;e<n;e++){let n=GC(t,e);i.push(`v ${n[0]} ${n[1]} ${n[2]}`)}for(let e=0;e<r;e++){let[n,r,a]=KC(t,e);i.push(`f ${n+1} ${r+1} ${a+1}`)}return new TextEncoder().encode(i.join(`
|
|
11
|
-
`)).buffer}function XC(e){let t=HC(e),n=WC(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=GC(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]=KC(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 ZC(e,t,n=`importMesh`){let r=new e.Mesh({numProp:3,vertProperties:t.vertProperties,triVerts:t.triVerts});return
|
|
12
|
-
`)){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 ZC(e,{vertProperties:Float32Array.from(r),triVerts:Uint32Array.from(i)})}function $C(e,t){let n=new Uint8Array(t),r=new TextDecoder().decode(n.subarray(0,Math.min(n.length,80))).trimStart().toLowerCase().startsWith(`solid`)&&nw(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=tw(i);return ZC(e,{vertProperties:Float32Array.from(a.vertices),triVerts:Uint32Array.from(a.indices)})}var ew=1e6;function tw(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*ew)},${Math.round(o*ew)},${Math.round(s*ew)}`,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 nw(e){return e.length<84?!0:84+new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(80,!0)*50!==e.length}var rw=1e-6;function iw(e,t){let n=H(t);if(n.replayable)return YS(n,e)}function aw(e,t){let n=HC(t),r=Math.floor(n.triVerts.length/3),i=[];for(let t=0;t<r;t++){let[r,a,o]=KC(n,t),s=e.buildTriFace(GC(n,r),GC(n,a),GC(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,rw)}function ow(e){let t=Ny(`B-rep export`),n=iw(t,e);return n===void 0?(console.warn(`manifold: exact B-rep unavailable (non-replayable op-graph); exporting faceted approximation`),{occt:t,brep:aw(t,e)}):{occt:t,brep:n}}function sw(e,t,n,r){let i=t.mesh(n,{tolerance:.01,angularTolerance:.5});return ZC(e,{vertProperties:Float32Array.from(i.vertices),triVerts:Uint32Array.from(i.triangles)},r)}var cw=1179937895,lw=2,uw=1313821514,dw=5130562,fw=5126,pw=5125,mw=5123,hw=5121,gw=34962,_w=34963,vw=4;function yw(e){return e+3&-4}function bw(e){let t=HC(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=yw(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:vw}]}],accessors:[{bufferView:0,componentType:fw,count:r,type:`VEC3`,min:[o,s,c],max:[l,u,d]},{bufferView:1,componentType:pw,count:i,type:`SCALAR`}],bufferViews:[{buffer:0,byteOffset:0,byteLength:p,target:gw},{buffer:0,byteOffset:m,byteLength:f.byteLength,target:_w}],buffers:[{byteLength:h}]},_=new TextEncoder().encode(JSON.stringify(g)),v=yw(_.length),y=yw(h),b=20+v+8+y,x=new ArrayBuffer(b),S=new DataView(x),C=new Uint8Array(x);S.setUint32(0,cw,!0),S.setUint32(4,lw,!0),S.setUint32(8,b,!0);let w=12;S.setUint32(w,v,!0),S.setUint32(w+4,uw,!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,dw,!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 xw(e,t){let n=new DataView(t);if(n.getUint32(0,!0)!==cw)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===uw?i=JSON.parse(new TextDecoder().decode(s)):r===dw&&(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===pw?4:e.componentType===mw?2:+(e.componentType===hw);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 ZC(e,{vertProperties:p,triVerts:m},`importGLB`)}function Sw(e){return{exportSTL:(e,t)=>JC(e,t),exportOBJ:e=>YC(e),exportPLY:e=>XC(e),importSTL:t=>$C(e,typeof t==`string`?new TextEncoder().encode(t).buffer:t),importOBJ:t=>QC(e,t),exportSTEP:e=>Ny(`exportSTEP`).exportSTEP(e.map(e=>ow(e).brep)),exportIGES:e=>Ny(`exportIGES`).exportIGES(e.map(e=>ow(e).brep)),toBREP:e=>{let{occt:t,brep:n}=ow(e);return t.toBREP(n)},exportSTEPAssembly:(e,t)=>{let n=Ny(`exportSTEPAssembly`),r=e.map(e=>{let t={shape:ow(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=Ny(`createXCAFDocument`),n=e.map(e=>{let t={shape:ow(e.shape).brep,name:e.name};return e.color===void 0?t:{...t,color:e.color}});return t.createXCAFDocument(n)},writeXCAFToSTEP:(e,t)=>Ny(`writeXCAFToSTEP`).writeXCAFToSTEP(e,t),exportSTEPConfigured:(e,t)=>{let n=Ny(`exportSTEPConfigured`),r=e.map(e=>{let t={shape:ow(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=Ny(`importSTEP`);return n.importSTEP(t).map(t=>sw(e,n,t,`importSTEP`))},importIGES:t=>{let n=Ny(`importIGES`);return n.importIGES(t).map(t=>sw(e,n,t,`importIGES`))},fromBREP:t=>{let n=Ny(`fromBREP`);return sw(e,n,n.fromBREP(t),`fromBREP`)},exportGLB:e=>bw(e),importGLB:t=>xw(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 Cw(e){return V(e).getMesh()}function ww(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 Tw(e,t){let n=e;if(n&&n.__manifoldSub&&n.occt){let e=My();if(!e)throw Error(`manifold: sub-shape geometry query requires a registered occt kernel`);return t(n.occt,e)}let r=Ay(e);if(!r)throw Error(`manifold: exact geometry query requires a manifold shape handle`);let i=My();if(!i)throw Error(`manifold: exact geometry query unsupported on manifold kernel; no B-rep kernel registered`);if(!r.node.replayable)throw Error(`manifold: exact geometry query unsupported; shape originates from a non-replayable op (raw mesh import or mesh boolean)`);let a=Py.get(r.node);return a===void 0&&(a=YS(r.node,i),Py.set(r.node,a)),t(a,i)}function Ew(e){let t=Ay(e);if(!t)return;let n=t.node;return n.op===`profileEdge`?n.params?.curve:void 0}function Dw(e){return{curveType:e=>{let t=Ew(e);return t?bb(t):AC(e)?e.curveType:Tw(e,(e,t)=>t.curveType(e))},curveParameters:e=>{let t=Ew(e);if(t){let e=xb(t);return[e.first,e.last]}return AC(e)?[0,e.length]:Tw(e,(e,t)=>t.curveParameters(e))},curvePointAtParam:(e,t)=>{let n=Ew(e);return n?Sb(n,t):AC(e)?jC(e,t):Tw(e,(e,n)=>n.curvePointAtParam(e,t))},curveTangent:(e,t)=>{let n=Ew(e);return n?{point:Sb(n,t),tangent:Cb(n,t)}:AC(e)?{point:jC(e,t),tangent:MC(e,t)}:Tw(e,(e,n)=>n.curveTangent(e,t))},curveIsClosed:e=>{let t=Ew(e);return t?Tb(t):Tw(e,(e,t)=>t.curveIsClosed(e))},curveIsPeriodic:e=>{let t=Ew(e);return t?Eb(t):Tw(e,(e,t)=>t.curveIsPeriodic(e))},curvePeriod:e=>{let t=Ew(e);return t?Db(t):Tw(e,(e,t)=>t.curvePeriod(e))},interpolatePoints:(e,t)=>Ny(`interpolatePoints`).interpolatePoints(e,t),approximatePoints:(e,t)=>Ny(`approximatePoints`).approximatePoints(e,t),curveDegreeElevate:(e,t)=>Tw(e,(e,n)=>n.curveDegreeElevate(e,t)),curveKnotInsert:(e,t,n)=>Tw(e,(e,r)=>r.curveKnotInsert(e,t,n)),curveKnotRemove:(e,t,n)=>Tw(e,(e,r)=>r.curveKnotRemove(e,t,n)),curveSplit:(e,t)=>Tw(e,(e,n)=>n.curveSplit(e,t)),createCurveAdaptor:e=>Tw(e,(e,t)=>t.createCurveAdaptor(e)),getBezierPenultimatePole:e=>Tw(e,(e,t)=>t.getBezierPenultimatePole(e)),getNurbsCurveData:e=>Tw(e,(e,t)=>t.getNurbsCurveData?.(e)??null),vertexPosition:e=>kC(e)?e.point:Ay(e)?ww(Cw(e),0):Tw(e,(e,t)=>t.vertexPosition(e)),surfaceType:e=>{if(bC(e))return`plane`;let t=Ay(e);return t&&t.node.op===`profileFace`?`plane`:Tw(e,(e,t)=>t.surfaceType(e))},uvBounds:e=>bC(e)?{uMin:0,uMax:1,vMin:0,vMax:1}:Tw(e,(e,t)=>t.uvBounds(e)),outerWire:e=>Tw(e,(e,t)=>t.outerWire(e)),surfaceNormal:(e,t,n)=>bC(e)?e.normal:Tw(e,(e,r)=>r.surfaceNormal(e,t,n)),pointOnSurface:(e,t,n)=>Tw(e,(e,r)=>r.pointOnSurface(e,t,n)),uvFromPoint:(e,t)=>Tw(e,(e,n)=>n.uvFromPoint(e,t)),projectPointOnFace:(e,t)=>Tw(e,(e,n)=>n.projectPointOnFace(e,t)),classifyPointOnFace:(e,t,n,r)=>Tw(e,(e,i)=>i.classifyPointOnFace(e,t,n,r)),classifyPointRobust:(e,t,n)=>Tw(e,(e,r)=>r.classifyPointRobust(e,t,n)),classifyPointWinding:(e,t,n)=>Tw(e,(e,r)=>r.classifyPointWinding(e,t,n)),approximateSurfaceLspia:(e,t,n,r,i,a,o,s,c)=>Ny(`approximateSurfaceLspia`).approximateSurfaceLspia(e,t,n,r,i,a,o,s,c),untrimFace:(e,t,n)=>Tw(e,(e,r)=>r.untrimFace(e,t,n)),getSurfaceCylinderData:e=>Tw(e,(e,t)=>t.getSurfaceCylinderData(e)),getSurfaceAxis:e=>Tw(e,(e,t)=>t.getSurfaceAxis(e)),reverseSurfaceU:e=>Ny(`reverseSurfaceU`).reverseSurfaceU(e),detectSmallFeatures:(e,t,n)=>Tw(e,(e,r)=>r.detectSmallFeatures(e,t,n)),recognizeFeatures:(e,t)=>Tw(e,(e,n)=>n.recognizeFeatures(e,t)),projectEdges:(e,t,n,r)=>Tw(e,(e,i)=>i.projectEdges(e,t,n,r)),getNurbsSurfaceData:e=>Tw(e,(e,t)=>t.getNurbsSurfaceData?.(e)??null)}}var Ow={hasErrors:!1,hasWarnings:!1,messages:[]};function kw(){return{modified:new Map,generated:new Map,deleted:new Set}}function Aw(e){return{shape:e,evolution:kw()}}function jw(e){return{shape:e,evolution:kw(),diagnostics:Ow}}function Mw(e){let t=pb(e),n=Gy(e),r=yS(e);return{translateWithHistory:(e,n,r,i)=>Aw(t.translate(e,n,r,i)),rotateWithHistory:(e,n,r,i,a,o)=>Aw(t.rotate(e,n,a,o)),mirrorWithHistory:(e,n,r)=>Aw(t.mirror(e,n,r)),scaleWithHistory:(e,n,r)=>Aw(t.scale(e,n,r)),generalTransformWithHistory:(e,n,r,i)=>Aw(t.generalTransform(e,n,r,i)),fuseWithHistory:(e,t,r,i,a)=>jw(n.fuse(e,t,a)),cutWithHistory:(e,t,r,i,a)=>jw(n.cut(e,t,a)),intersectWithHistory:(e,t,r,i,a)=>jw(n.intersect(e,t,a)),filletWithHistory:(e,t,n)=>Aw(r.fillet(e,t,n)),chamferWithHistory:(e,t,n)=>Aw(r.chamfer(e,t,n)),shellWithHistory:(e,t,n,i,a,o)=>Aw(r.shell(e,t,n,o)),thickenWithHistory:(e,t)=>Aw(r.thicken(e,t)),offsetWithHistory:(e,t,n,i,a)=>Aw(r.offset(e,t,a)),draftWithHistory:(e,t,n,i,a)=>Aw(r.draft(e,t,n,i,a)),applyComposedTransformWithHistory:(e,n)=>Aw(t.transform(e,n))}}function Nw(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 Pw(e){return{isValid:e=>Nw(e),isValidStrict:e=>Nw(e),healSolid:e=>Nw(e)?e:null,healFace:e=>e,healWire:e=>e,mergeCoincidentVertices:()=>0,removeDegenerateEdges:()=>0,fixFaceOrientations:()=>0,fixShape:e=>e,fixSelfIntersection:e=>e}}var Fw=.004;function Iw(e){return!!e&&typeof e==`object`&&e.__nativeC2d===!0}function Lw(e,t){return{__nativeC2d:!0,k:`line`,p1:e,p2:t}}function Rw(e,t,n,r,i){return{__nativeC2d:!0,k:`conic`,c:e,u:t,v:n,a0:r,a1:i}}function zw(e,[t,n]){return[e.a*t+e.b*n+e.tx,e.c*t+e.d*n+e.ty]}function Bw(e,[t,n]){return[e.a*t+e.b*n,e.c*t+e.d*n]}function Vw(e,t){return{a:e.a*t.a+e.b*t.c,b:e.a*t.b+e.b*t.d,c:e.c*t.a+e.d*t.c,d:e.c*t.b+e.d*t.d,tx:e.a*t.tx+e.b*t.ty+e.tx,ty:e.c*t.tx+e.d*t.ty+e.ty}}function Hw(e,t){return e.k===`line`?Lw(zw(t,e.p1),zw(t,e.p2)):e.k===`bezier`?{__nativeC2d:!0,k:`bezier`,pts:e.pts.map(e=>zw(t,e))}:Rw(zw(t,e.c),Bw(t,e.u),Bw(t,e.v),e.a0,e.a1)}function Uw(e,t){let n=e.map(e=>[e[0],e[1]]);for(let e=1;e<n.length;e++)for(let r=0;r<n.length-e;r++){let e=n[r]??[0,0],i=n[r+1]??[0,0];n[r]=[e[0]*(1-t)+i[0]*t,e[1]*(1-t)+i[1]*t]}return n[0]??[0,0]}function Ww(e,t){let n=Math.cos(t),r=Math.sin(t);return[e.c[0]+e.u[0]*n+e.v[0]*r,e.c[1]+e.u[1]*n+e.v[1]*r]}function Gw(e,t){let n=e.length-1;if(n<1)return[0,0];let r=[];for(let t=0;t<n;t++){let i=e[t]??[0,0],a=e[t+1]??[0,0];r.push([n*(a[0]-i[0]),n*(a[1]-i[1])])}return Uw(r,t)}function Kw(e){let t=Math.abs(e.a1-e.a0),n=Math.hypot(e.u[0],e.u[1]),r=Math.hypot(e.v[0],e.v[1]),i=Math.max(n,r);if(i<=Fw)return Math.max(2,Math.ceil(t/(2*Math.PI)*8));let a=2*Math.acos(Math.max(-1,1-Fw/i));return Math.max(2,Math.ceil(t/a))}function qw(e){if(e.k===`line`)return[e.p1,e.p2];if(e.k===`bezier`){let t=[];for(let n=0;n<=24;n++)t.push(Uw(e.pts,n/24));return t}let t=e.a1-e.a0,n=Kw(e),r=[];for(let i=0;i<=n;i++){let a=e.a0+t*i/n,o=Math.cos(a),s=Math.sin(a);r.push([e.c[0]+e.u[0]*o+e.v[0]*s,e.c[1]+e.u[1]*o+e.v[1]*s])}return r}function Jw(e,t,n){let r=e[0],i=e[1],a=t[0],o=t[1],s=n[0],c=n[1],l=2*(r*(o-c)+a*(c-i)+s*(i-o));if(Math.abs(l)<1e-12)return Lw(e,n);let u=((r*r+i*i)*(o-c)+(a*a+o*o)*(c-i)+(s*s+c*c)*(i-o))/l,d=((r*r+i*i)*(s-a)+(a*a+o*o)*(r-s)+(s*s+c*c)*(a-r))/l,f=[u,d],p=Math.hypot(r-u,i-d),m=e=>Math.atan2(e[1]-d,e[0]-u),h=m(e),g=m(t),_=m(n),v=e=>(e%(2*Math.PI)+2*Math.PI)%(2*Math.PI),y=v(g-h),b=v(_-h);return _=y<=b?h+b:h-v(h-_),Rw(f,[p,0],[0,p],h,_)}function Yw(e,t){let n={delete:()=>{},isEmpty:()=>!1};function r(e,...n){let r=t(),i=r?.[e];if(!i)throw Error(`manifold 2D: ${e} needs an OCCT kernel (none registered)`);return i.call(r,...n)}let i=e=>e;function a(e){let n=t();if(!n)throw Error(`manifold 2D: ${e} needs an OCCT kernel (none registered)`);return n}function o(e){if(!Iw(e))return e;let t=a(`toOcct`),n=i(e);if(n.k===`line`)return t.makeLine2d(n.p1[0],n.p1[1],n.p2[0],n.p2[1]);if(n.k===`bezier`)return t.makeBezier2d(n.pts);let r=Math.hypot(n.u[0],n.u[1]),o=Math.hypot(n.v[0],n.v[1]),s=Math.abs(Math.abs(n.a1-n.a0)-2*Math.PI)<1e-9,c=n.u[0]*n.v[1]-n.u[1]*n.v[0]>=0;if(Math.abs(r-o)<1e-9*Math.max(1,r)){if(s)return t.makeCircle2d(n.c[0],n.c[1],r,c);let e=Ww(n,n.a0),i=Ww(n,(n.a0+n.a1)/2),a=Ww(n,n.a1);return t.makeArc2dThreePoints(e[0],e[1],i[0],i[1],a[0],a[1])}let l=n.u[0]*n.v[0]+n.u[1]*n.v[1];if(Math.abs(l)<1e-9*Math.max(1,r*o)){let e=n.u[0]/r,i=n.u[1]/r;return s?t.makeEllipse2d(n.c[0],n.c[1],r,o,e,i,c):t.makeEllipseArc2d(n.c[0],n.c[1],r,o,n.a0,n.a1,e,i,c)}return t.makeBSpline2d(qw(n).map(e=>[e[0],e[1]]))}let s={createPoint2d:(e,t)=>({x:e,y:t}),createDirection2d:(e,t)=>({x:e,y:t}),createVector2d:(e,t)=>({x:e,y:t}),createAxis2d:(e,t,n,r)=>({px:e,py:t,dx:n,dy:r}),wrapCurve2dHandle:e=>e,createCurve2dAdaptor:e=>e,makeLine2d:(e,t,n,r)=>Lw([e,t],[n,r]),makeCircle2d:(e,t,n,r=!0)=>Rw([e,t],[n,0],r?[0,n]:[0,-n],0,2*Math.PI),makeArc2dThreePoints:(e,t,n,r,i,a)=>Jw([e,t],[n,r],[i,a]),makeArc2dTangent:(e,t,n,r,i,a)=>{let o=Math.hypot(n,r)||1,s=-r/o,c=n/o,l=[i-e,a-t],u=s*l[0]+c*l[1];if(Math.abs(u)<1e-12)return Lw([e,t],[i,a]);let d=(l[0]*l[0]+l[1]*l[1])/(2*u),f=e+s*d,p=t+c*d,m=Math.hypot(e-f,t-p),h=Math.atan2(t-p,e-f),g=Math.atan2(a-p,i-f);s*n+c*r;let _=e=>(e%(2*Math.PI)+2*Math.PI)%(2*Math.PI),v=[-(t-p),e-f];return g=v[0]*n+v[1]*r>=0?h+_(g-h):h-_(h-g),Rw([f,p],[m,0],[0,m],h,g)},makeEllipse2d:(e,t,n,r,i=1,a=0,o=!0)=>{let s=Math.hypot(i,a)||1,c=i/s*n,l=a/s*n,u=-a/s*r*(o?1:-1),d=i/s*r*(o?1:-1);return Rw([e,t],[c,l],[u,d],0,2*Math.PI)},makeEllipseArc2d:(e,t,n,r,i,a,o=1,s=0,c=!0)=>{let l=Math.hypot(o,s)||1,u=o/l*n,d=s/l*n,f=-s/l*r*(c?1:-1),p=o/l*r*(c?1:-1);return Rw([e,t],[u,d],[f,p],i,a)},makeBezier2d:e=>({__nativeC2d:!0,k:`bezier`,pts:e.map(e=>[e[0],e[1]])}),evaluateCurve2d:(e,t)=>{let n=i(e);if(n.k===`line`){let e=n.p2[0]-n.p1[0],r=n.p2[1]-n.p1[1],i=Math.hypot(e,r)||1;return[n.p1[0]+e*t/i,n.p1[1]+r*t/i]}return n.k===`bezier`?Uw(n.pts,t):[n.c[0]+n.u[0]*Math.cos(t)+n.v[0]*Math.sin(t),n.c[1]+n.u[1]*Math.cos(t)+n.v[1]*Math.sin(t)]},evaluateCurve2dD1:(e,t)=>{let n=i(e);if(n.k===`line`){let e=n.p2[0]-n.p1[0],r=n.p2[1]-n.p1[1],i=Math.hypot(e,r)||1;return{point:[n.p1[0]+e*t/i,n.p1[1]+r*t/i],tangent:[e/i,r/i]}}if(n.k===`bezier`)return{point:Uw(n.pts,t),tangent:Gw(n.pts,t)};let r=Math.cos(t),a=Math.sin(t);return{point:[n.c[0]+n.u[0]*r+n.v[0]*a,n.c[1]+n.u[1]*r+n.v[1]*a],tangent:[-n.u[0]*a+n.v[0]*r,-n.u[1]*a+n.v[1]*r]}},getCurve2dBounds:e=>{let t=i(e);return t.k===`conic`?{first:t.a0,last:t.a1}:t.k===`line`?{first:0,last:Math.hypot(t.p2[0]-t.p1[0],t.p2[1]-t.p1[1])}:{first:0,last:1}},getCurve2dType:e=>{let t=i(e);return t.k===`line`?`LINE`:t.k===`bezier`?`BEZIER`:`CIRCLE`},reverseCurve2d:e=>{let t=i(e);if(t.k===`line`){let e=t.p1;t.p1=t.p2,t.p2=e}else if(t.k===`bezier`)t.pts.reverse();else{let e=t.a0;t.a0=t.a1,t.a1=e}},copyCurve2d:e=>structuredClone(i(e)),trimCurve2d:(e,t,n)=>{let r=i(e);if(r.k===`conic`)return Rw(r.c,r.u,r.v,t,n);if(r.k===`line`){let e=r.p2[0]-r.p1[0],i=r.p2[1]-r.p1[1],a=Math.hypot(e,i)||1;return Lw([r.p1[0]+e*t/a,r.p1[1]+i*t/a],[r.p1[0]+e*n/a,r.p1[1]+i*n/a])}return structuredClone(r)},createIdentityGTrsf2d:()=>({a:1,b:0,c:0,d:1,tx:0,ty:0}),createTranslationGTrsf2d:(e,t)=>({a:1,b:0,c:0,d:1,tx:e,ty:t}),createRotationGTrsf2d:(e,t,n)=>{let r=Math.cos(e),i=Math.sin(e);return{a:r,b:-i,c:i,d:r,tx:t-(r*t-i*n),ty:n-(i*t+r*n)}},createScaleGTrsf2d:(e,t,n)=>({a:e,b:0,c:0,d:e,tx:t-e*t,ty:n-e*n}),createMirrorGTrsf2d:(e,t,n,r=0,i=0,a=1,o=0)=>{if(n===`point`)return{a:-1,b:0,c:0,d:-1,tx:2*e,ty:2*t};let s=Math.hypot(a,o)||1,c=a/s,l=o/s,u=c*c-l*l,d=2*c*l;return{a:u,b:d,c:d,d:-u,tx:r-(u*r+d*i),ty:i-(d*r-u*i)}},createAffinityGTrsf2d:(e,t,n,r,i)=>{let a=Math.hypot(n,r)||1,o=n/a,s=r/a,c=-s,l=o,u=o*o+i*c*c,d=o*s+i*c*l,f=s*o+i*l*c,p=s*s+i*l*l;return{a:u,b:d,c:f,d:p,tx:e-(u*e+d*t),ty:t-(f*e+p*t)}},setGTrsf2dTranslationPart:(e,t,n)=>{let r=e;r.tx=t,r.ty=n},multiplyGTrsf2d:(e,t)=>{let n=Vw(e,t);Object.assign(e,n)},transformCurve2dGeneral:(e,t)=>Hw(i(e),t),translateCurve2d:(e,t,n)=>Hw(i(e),{a:1,b:0,c:0,d:1,tx:t,ty:n}),rotateCurve2d:(e,t,n,r)=>{let a=Math.cos(t),o=Math.sin(t);return Hw(i(e),{a,b:-o,c:o,d:a,tx:n-(a*n-o*r),ty:r-(o*n+a*r)})},scaleCurve2d:(e,t,n,r)=>Hw(i(e),{a:t,b:0,c:0,d:t,tx:n-t*n,ty:r-t*r}),mirrorCurve2dAtPoint:(e,t,n)=>Hw(i(e),{a:-1,b:0,c:0,d:-1,tx:2*t,ty:2*n}),mirrorCurve2dAcrossAxis:(e,t,n,r,a)=>{let o=Math.hypot(r,a)||1,s=r/o,c=a/o,l=s*s-c*c,u=2*s*c;return Hw(i(e),{a:l,b:u,c:u,d:-l,tx:t-(l*t+u*n),ty:n-(u*t-l*n)})},affinityTransform2d:(e,t,n,r,a,o)=>{let s=Math.hypot(r,a)||1,c=r/s,l=a/s,u=-l,d=c,f=c*c+o*u*u,p=c*l+o*u*d,m=l*c+o*d*u,h=l*l+o*d*d;return Hw(i(e),{a:f,b:p,c:m,d:h,tx:t-(f*t+p*n),ty:n-(m*t+h*n)})},createBoundingBox2d:()=>({min:[1/0,1/0],max:[-1/0,-1/0]}),addCurveToBBox2d:(e,t)=>{let n=e,r;if(Iw(t))r=qw(i(t));else{let e=a(`addCurveToBBox2d`),{first:n,last:i}=e.getCurve2dBounds(t);r=[];for(let a=0;a<=32;a++)r.push(e.evaluateCurve2d(t,n+(i-n)*a/32))}for(let[e,t]of r)e<n.min[0]&&(n.min[0]=e),t<n.min[1]&&(n.min[1]=t),e>n.max[0]&&(n.max[0]=e),t>n.max[1]&&(n.max[1]=t)},getBBox2dBounds:e=>{let t=e;return{xMin:t.min[0],yMin:t.min[1],xMax:t.max[0],yMax:t.max[1]}},mergeBBox2d:(e,t)=>{let n=e,r=t;n.min[0]=Math.min(n.min[0],r.min[0]),n.min[1]=Math.min(n.min[1],r.min[1]),n.max[0]=Math.max(n.max[0],r.max[0]),n.max[1]=Math.max(n.max[1],r.max[1])},isBBox2dOut:(e,t)=>{let n=e,r=t;return n.max[0]<r.min[0]||n.min[0]>r.max[0]||n.max[1]<r.min[1]||n.min[1]>r.max[1]},isBBox2dOutPoint:(e,t,n)=>{let r=e;return t<r.min[0]||t>r.max[0]||n<r.min[1]||n>r.max[1]},getCurve2dCircleData:e=>{let t=i(e);if(t.k!==`conic`)return null;let n=Math.hypot(t.u[0],t.u[1]),r=Math.hypot(t.v[0],t.v[1]);return Math.abs(n-r)>1e-6?null:{cx:t.c[0],cy:t.c[1],radius:n,isDirect:!0}},liftCurve2dToPlane:(e,t,r,a)=>{let o=r[0],s=r[1],c=r[2],l=a[0],u=a[1],d=a[2],f=s*d-c*u,p=c*l-o*d,m=o*u-s*l;return B(n,z(`profileEdge`,{pts:qw(i(e)).map(([e,n])=>[t[0]+l*e+f*n,t[1]+u*e+p*n,t[2]+d*e+m*n])},[]))},makeBSpline2d:(e,t)=>a(`makeBSpline2d`).makeBSpline2d(e,t),offsetCurve2d:(e,t)=>a(`offsetCurve2d`).offsetCurve2d(o(e),t),intersectCurves2d:(e,t,n)=>a(`intersectCurves2d`).intersectCurves2d(o(e),o(t),n),projectPointOnCurve2d:(e,t,n)=>a(`projectPointOnCurve2d`).projectPointOnCurve2d(o(e),t,n),distanceBetweenCurves2d:(e,t,n,r,i,s)=>a(`distanceBetweenCurves2d`).distanceBetweenCurves2d(o(e),o(t),n,r,i,s),approximateCurve2dAsBSpline:(e,t,n,r)=>a(`approximateCurve2dAsBSpline`).approximateCurve2dAsBSpline(o(e),t,n,r),decomposeBSpline2dToBeziers:e=>a(`decomposeBSpline2dToBeziers`).decomposeBSpline2dToBeziers(o(e)),serializeCurve2d:e=>a(`serializeCurve2d`).serializeCurve2d(o(e)),deserializeCurve2d:e=>a(`deserializeCurve2d`).deserializeCurve2d(e),splitCurve2d:(e,t)=>a(`splitCurve2d`).splitCurve2d(o(e),t),getCurve2dEllipseData:e=>a(`getCurve2dEllipseData`).getCurve2dEllipseData(o(e)),getCurve2dBezierPoles:e=>a(`getCurve2dBezierPoles`).getCurve2dBezierPoles(o(e)),getCurve2dBezierDegree:e=>a(`getCurve2dBezierDegree`).getCurve2dBezierDegree(o(e)),getCurve2dBSplineData:e=>a(`getCurve2dBSplineData`).getCurve2dBSplineData(o(e)),buildEdgeOnSurface:(e,t)=>a(`buildEdgeOnSurface`).buildEdgeOnSurface(o(e),t),extractSurfaceFromFace:e=>a(`extractSurfaceFromFace`).extractSurfaceFromFace(e),extractCurve2dFromEdge:(e,t)=>a(`extractCurve2dFromEdge`).extractCurve2dFromEdge(e,t),buildCurves3d:e=>{a(`buildCurves3d`).buildCurves3d(e)},fixWireOnFace:(e,t,n)=>a(`fixWireOnFace`).fixWireOnFace(e,t,n),fillSurface:(e,t)=>a(`fillSurface`).fillSurface(e,t)};for(let e of[`evaluateCurve2d`,`evaluateCurve2dD1`,`getCurve2dBounds`,`getCurve2dType`,`reverseCurve2d`,`copyCurve2d`,`trimCurve2d`,`transformCurve2dGeneral`,`translateCurve2d`,`rotateCurve2d`,`scaleCurve2d`,`mirrorCurve2dAtPoint`,`mirrorCurve2dAcrossAxis`,`affinityTransform2d`,`getCurve2dCircleData`,`liftCurve2dToPlane`]){let t=s[e];t&&(s[e]=((n,...i)=>Iw(n)?t(n,...i):r(e,n,...i)))}return s}var Xw=`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 Zw(e){let t=My();if(!t)throw Error(`manifold: ${e} unsupported on manifold kernel; no B-rep kernel registered`);return t}function Qw(e){let t={};for(let e of Xw)t[e]=(...t)=>Zw(e)[e](...t);let n=Yw(e,()=>My());return Object.assign(t,n),t}function $w(e){return{sketchNew:()=>Dy(`sketchNew`),sketchAddPoint:()=>Dy(`sketchAddPoint`),sketchAddArc:()=>Dy(`sketchAddArc`),sketchAddConstraint:()=>Dy(`sketchAddConstraint`),sketchSolve:()=>Dy(`sketchSolve`),sketchDof:()=>Dy(`sketchDof`)}}function eT(e){return{projectEdges:()=>Dy(`projectEdges`)}}function tT(e){return{dispose(e){let t=Ay(e);if(t){let e=Py.get(t.node);e!==void 0&&(My()?.dispose(e),Py.delete(t.node))}(e?.manifold)?.delete?.()},executeBatch:()=>Dy(`executeBatch`),checkpoint:()=>Dy(`checkpoint`),checkpointCount:()=>0,restoreCheckpoint:()=>Dy(`restoreCheckpoint`),discardCheckpoint:()=>Dy(`discardCheckpoint`)}}var nT={draft:30,standard:10,fine:3},rT=class{oc;kernelId=`manifold`;capabilities={exact:!1,brepExport:!1,exactMeasurement:!1,tessellationModel:`build-time`};setQuality(e){let t=this.oc;t.setCircularSegments?.(0),t.setMinCircularEdgeLength?.(0),t.setMinCircularAngle?.(nT[e])}constructor(e){this.oc=e,Object.assign(this,By(e),Gy(e),pb(e),bx(e),Kx(e),yS(e),DS(e),_C(e),VC(e),Sw(e),Dw(e),Mw(e),Pw(e),Qw(e),$w(e),eT(e),tT(e))}};function iT(e){return`projectEdges`in e}function aT(e){return`sketchNew`in e&&`sketchDof`in e}var oT=new Map,sT=null,cT=null;function lT(e){uT(`manifold`,new rT(e))}function uT(e,t){oT.set(e,t),sT||=e,e===sT&&(cT=t)}function U(e){if(!e&&cT)return cT;let t=e??sT;if(!t)throw Error(`brepjs kernel not initialized. Call initFromOC() or registerKernel() before using the library.`);let n=oT.get(t);if(!n)throw Error(`brepjs: kernel '${t}' is not registered.`);return n}function dT(e){let t=U(e);if(!So(t))throw Error(`brepjs: current kernel does not support 2D operations.`);return t}function fT(){return sT}function pT(e,t){let n=sT;sT=e,cT=oT.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{sT=n,cT=n?oT.get(n)??null:null}}function mT(e){return U(e).capabilities}function hT(e,t){let n=yo();try{xo(e),U().setQuality?.(e);let n=t();if(n instanceof Promise)throw Error(`withQuality() callback returned a Promise. Async code must read currentQuality()/getKernel() directly.`);return n}finally{xo(n),U().setQuality?.(n)}}var gT=new Map;function _T(e,t){gT.set(e,t)}function vT(e){return gT.get(e)}function yT(e,t){let n=gT.get(e);if(!n)throw Error(`withTier: no tier registered for "${e}". Call registerKernelTier("${e}", { kernel, quality }) first.`);return pT(n.kernel,()=>hT(n.quality,t))}function bT(e){Ro(),Qc(),jo(),Oc(),kc(),Wc(),Gc();let t=new Ff(e);uT(`occt`,t),sT=`occt`,cT=t}function xT(){let e=U(),t=e.makeBox(1,1,1);try{e.dispose(t)}catch{}}async function ST(){if(sT)return sT;try{let{OcctKernel:e}=await import(`occt-wasm`),t=await e.init();return uT(`occt-wasm`,ja.fromKernel(t)),`occt-wasm`}catch{}try{return bT(await(await import(`brepjs-opencascade`)).default()),`occt`}catch{}try{let e=await import(`brepkit-wasm`);return typeof e.default==`function`&&await e.default(),uT(`brepkit`,new Ey(new e.BrepKernel)),`brepkit`}catch{}throw Error(`brepjs: no kernel package found. Install one of:
|
|
11
|
+
`)).buffer}function XC(e){let t=HC(e),n=WC(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=GC(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]=KC(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 ZC(e,t,n=`importMesh`){let r=new e.Mesh({numProp:3,vertProperties:t.vertProperties,triVerts:t.triVerts});return ky(new e.Manifold(r),B(n,{},[]))}function QC(e,t){let n=new TextDecoder().decode(new Uint8Array(t)),r=[],i=[];for(let e of n.split(`
|
|
12
|
+
`)){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 ZC(e,{vertProperties:Float32Array.from(r),triVerts:Uint32Array.from(i)})}function $C(e,t){let n=new Uint8Array(t),r=new TextDecoder().decode(n.subarray(0,Math.min(n.length,80))).trimStart().toLowerCase().startsWith(`solid`)&&nw(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=tw(i);return ZC(e,{vertProperties:Float32Array.from(a.vertices),triVerts:Uint32Array.from(a.indices)})}var ew=1e6;function tw(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*ew)},${Math.round(o*ew)},${Math.round(s*ew)}`,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 nw(e){return e.length<84?!0:84+new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(80,!0)*50!==e.length}var rw=1e-6;function iw(e,t){let n=H(t);if(n.replayable)return YS(n,e)}function aw(e,t){let n=HC(t),r=Math.floor(n.triVerts.length/3),i=[];for(let t=0;t<r;t++){let[r,a,o]=KC(n,t),s=e.buildTriFace(GC(n,r),GC(n,a),GC(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,rw)}function ow(e){let t=Ny(`B-rep export`),n=iw(t,e);return n===void 0?(console.warn(`manifold: exact B-rep unavailable (non-replayable op-graph); exporting faceted approximation`),{occt:t,brep:aw(t,e)}):{occt:t,brep:n}}function sw(e,t,n,r){let i=t.mesh(n,{tolerance:.01,angularTolerance:.5});return ZC(e,{vertProperties:Float32Array.from(i.vertices),triVerts:Uint32Array.from(i.triangles)},r)}var cw=1179937895,lw=2,uw=1313821514,dw=5130562,fw=5126,pw=5125,mw=5123,hw=5121,gw=34962,_w=34963,vw=4;function yw(e){return e+3&-4}function bw(e){let t=HC(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=yw(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:vw}]}],accessors:[{bufferView:0,componentType:fw,count:r,type:`VEC3`,min:[o,s,c],max:[l,u,d]},{bufferView:1,componentType:pw,count:i,type:`SCALAR`}],bufferViews:[{buffer:0,byteOffset:0,byteLength:p,target:gw},{buffer:0,byteOffset:m,byteLength:f.byteLength,target:_w}],buffers:[{byteLength:h}]},_=new TextEncoder().encode(JSON.stringify(g)),v=yw(_.length),y=yw(h),b=20+v+8+y,x=new ArrayBuffer(b),S=new DataView(x),C=new Uint8Array(x);S.setUint32(0,cw,!0),S.setUint32(4,lw,!0),S.setUint32(8,b,!0);let w=12;S.setUint32(w,v,!0),S.setUint32(w+4,uw,!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,dw,!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 xw(e,t){let n=new DataView(t);if(n.getUint32(0,!0)!==cw)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===uw?i=JSON.parse(new TextDecoder().decode(s)):r===dw&&(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===pw?4:e.componentType===mw?2:+(e.componentType===hw);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 ZC(e,{vertProperties:p,triVerts:m},`importGLB`)}function Sw(e){return{exportSTL:(e,t)=>JC(e,t),exportOBJ:e=>YC(e),exportPLY:e=>XC(e),importSTL:t=>$C(e,typeof t==`string`?new TextEncoder().encode(t).buffer:t),importOBJ:t=>QC(e,t),exportSTEP:e=>Ny(`exportSTEP`).exportSTEP(e.map(e=>ow(e).brep)),exportIGES:e=>Ny(`exportIGES`).exportIGES(e.map(e=>ow(e).brep)),toBREP:e=>{let{occt:t,brep:n}=ow(e);return t.toBREP(n)},exportSTEPAssembly:(e,t)=>{let n=Ny(`exportSTEPAssembly`),r=e.map(e=>{let t={shape:ow(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=Ny(`createXCAFDocument`),n=e.map(e=>{let t={shape:ow(e.shape).brep,name:e.name};return e.color===void 0?t:{...t,color:e.color}});return t.createXCAFDocument(n)},writeXCAFToSTEP:(e,t)=>Ny(`writeXCAFToSTEP`).writeXCAFToSTEP(e,t),exportSTEPConfigured:(e,t)=>{let n=Ny(`exportSTEPConfigured`),r=e.map(e=>{let t={shape:ow(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=Ny(`importSTEP`);return n.importSTEP(t).map(t=>sw(e,n,t,`importSTEP`))},importIGES:t=>{let n=Ny(`importIGES`);return n.importIGES(t).map(t=>sw(e,n,t,`importIGES`))},fromBREP:t=>{let n=Ny(`fromBREP`);return sw(e,n,n.fromBREP(t),`fromBREP`)},exportGLB:e=>bw(e),importGLB:t=>xw(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 Cw(e){return V(e).getMesh()}function ww(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 Tw(e,t){let n=e;if(n&&n.__manifoldSub&&n.occt){let e=My();if(!e)throw Error(`manifold: sub-shape geometry query requires a registered occt kernel`);return t(n.occt,e)}let r=Ay(e);if(!r)throw Error(`manifold: exact geometry query requires a manifold shape handle`);let i=My();if(!i)throw Error(`manifold: exact geometry query unsupported on manifold kernel; no B-rep kernel registered`);if(!r.node.replayable)throw Error(`manifold: exact geometry query unsupported; shape originates from a non-replayable op (raw mesh import or mesh boolean)`);let a=Py.get(r.node);return a===void 0&&(a=YS(r.node,i),Py.set(r.node,a)),t(a,i)}function Ew(e){let t=Ay(e);if(!t)return;let n=t.node;return n.op===`profileEdge`?n.params?.curve:void 0}function Dw(e){return{curveType:e=>{let t=Ew(e);return t?bb(t):AC(e)?e.curveType:Tw(e,(e,t)=>t.curveType(e))},curveParameters:e=>{let t=Ew(e);if(t){let e=xb(t);return[e.first,e.last]}return AC(e)?[0,e.length]:Tw(e,(e,t)=>t.curveParameters(e))},curvePointAtParam:(e,t)=>{let n=Ew(e);return n?Sb(n,t):AC(e)?jC(e,t):Tw(e,(e,n)=>n.curvePointAtParam(e,t))},curveTangent:(e,t)=>{let n=Ew(e);return n?{point:Sb(n,t),tangent:Cb(n,t)}:AC(e)?{point:jC(e,t),tangent:MC(e,t)}:Tw(e,(e,n)=>n.curveTangent(e,t))},curveIsClosed:e=>{let t=Ew(e);return t?Tb(t):Tw(e,(e,t)=>t.curveIsClosed(e))},curveIsPeriodic:e=>{let t=Ew(e);return t?Eb(t):Tw(e,(e,t)=>t.curveIsPeriodic(e))},curvePeriod:e=>{let t=Ew(e);return t?Db(t):Tw(e,(e,t)=>t.curvePeriod(e))},interpolatePoints:(e,t)=>Ny(`interpolatePoints`).interpolatePoints(e,t),approximatePoints:(e,t)=>Ny(`approximatePoints`).approximatePoints(e,t),curveDegreeElevate:(e,t)=>Tw(e,(e,n)=>n.curveDegreeElevate(e,t)),curveKnotInsert:(e,t,n)=>Tw(e,(e,r)=>r.curveKnotInsert(e,t,n)),curveKnotRemove:(e,t,n)=>Tw(e,(e,r)=>r.curveKnotRemove(e,t,n)),curveSplit:(e,t)=>Tw(e,(e,n)=>n.curveSplit(e,t)),createCurveAdaptor:e=>Tw(e,(e,t)=>t.createCurveAdaptor(e)),getBezierPenultimatePole:e=>Tw(e,(e,t)=>t.getBezierPenultimatePole(e)),getNurbsCurveData:e=>Tw(e,(e,t)=>t.getNurbsCurveData?.(e)??null),vertexPosition:e=>kC(e)?e.point:Ay(e)?ww(Cw(e),0):Tw(e,(e,t)=>t.vertexPosition(e)),surfaceType:e=>{if(bC(e))return`plane`;let t=Ay(e);return t&&t.node.op===`profileFace`?`plane`:Tw(e,(e,t)=>t.surfaceType(e))},uvBounds:e=>bC(e)?{uMin:0,uMax:1,vMin:0,vMax:1}:Tw(e,(e,t)=>t.uvBounds(e)),outerWire:e=>Tw(e,(e,t)=>t.outerWire(e)),surfaceNormal:(e,t,n)=>bC(e)?e.normal:Tw(e,(e,r)=>r.surfaceNormal(e,t,n)),pointOnSurface:(e,t,n)=>Tw(e,(e,r)=>r.pointOnSurface(e,t,n)),uvFromPoint:(e,t)=>Tw(e,(e,n)=>n.uvFromPoint(e,t)),projectPointOnFace:(e,t)=>Tw(e,(e,n)=>n.projectPointOnFace(e,t)),classifyPointOnFace:(e,t,n,r)=>Tw(e,(e,i)=>i.classifyPointOnFace(e,t,n,r)),classifyPointRobust:(e,t,n)=>Tw(e,(e,r)=>r.classifyPointRobust(e,t,n)),classifyPointWinding:(e,t,n)=>Tw(e,(e,r)=>r.classifyPointWinding(e,t,n)),approximateSurfaceLspia:(e,t,n,r,i,a,o,s,c)=>Ny(`approximateSurfaceLspia`).approximateSurfaceLspia(e,t,n,r,i,a,o,s,c),untrimFace:(e,t,n)=>Tw(e,(e,r)=>r.untrimFace(e,t,n)),getSurfaceCylinderData:e=>Tw(e,(e,t)=>t.getSurfaceCylinderData(e)),getSurfaceAxis:e=>Tw(e,(e,t)=>t.getSurfaceAxis(e)),reverseSurfaceU:e=>Ny(`reverseSurfaceU`).reverseSurfaceU(e),detectSmallFeatures:(e,t,n)=>Tw(e,(e,r)=>r.detectSmallFeatures(e,t,n)),recognizeFeatures:(e,t)=>Tw(e,(e,n)=>n.recognizeFeatures(e,t)),projectEdges:(e,t,n,r)=>Tw(e,(e,i)=>i.projectEdges(e,t,n,r)),getNurbsSurfaceData:e=>Tw(e,(e,t)=>t.getNurbsSurfaceData?.(e)??null)}}var Ow={hasErrors:!1,hasWarnings:!1,messages:[]};function kw(){return{modified:new Map,generated:new Map,deleted:new Set}}function Aw(e){return{shape:e,evolution:kw()}}function jw(e){return{shape:e,evolution:kw(),diagnostics:Ow}}function Mw(e){let t=pb(e),n=Gy(e),r=yS(e);return{translateWithHistory:(e,n,r,i)=>Aw(t.translate(e,n,r,i)),rotateWithHistory:(e,n,r,i,a,o)=>Aw(t.rotate(e,n,a,o)),mirrorWithHistory:(e,n,r)=>Aw(t.mirror(e,n,r)),scaleWithHistory:(e,n,r)=>Aw(t.scale(e,n,r)),generalTransformWithHistory:(e,n,r,i)=>Aw(t.generalTransform(e,n,r,i)),fuseWithHistory:(e,t,r,i,a)=>jw(n.fuse(e,t,a)),cutWithHistory:(e,t,r,i,a)=>jw(n.cut(e,t,a)),intersectWithHistory:(e,t,r,i,a)=>jw(n.intersect(e,t,a)),filletWithHistory:(e,t,n)=>Aw(r.fillet(e,t,n)),chamferWithHistory:(e,t,n)=>Aw(r.chamfer(e,t,n)),shellWithHistory:(e,t,n,i,a,o)=>Aw(r.shell(e,t,n,o)),thickenWithHistory:(e,t)=>Aw(r.thicken(e,t)),offsetWithHistory:(e,t,n,i,a)=>Aw(r.offset(e,t,a)),draftWithHistory:(e,t,n,i,a)=>Aw(r.draft(e,t,n,i,a)),applyComposedTransformWithHistory:(e,n)=>Aw(t.transform(e,n))}}function Nw(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 Pw(e){return{isValid:e=>Nw(e),isValidStrict:e=>Nw(e),healSolid:e=>Nw(e)?e:null,healFace:e=>e,healWire:e=>e,mergeCoincidentVertices:()=>0,removeDegenerateEdges:()=>0,fixFaceOrientations:()=>0,fixShape:e=>e,fixSelfIntersection:e=>e}}var Fw=.004;function Iw(e){return!!e&&typeof e==`object`&&e.__nativeC2d===!0}function Lw(e,t){return{__nativeC2d:!0,k:`line`,p1:e,p2:t}}function Rw(e,t,n,r,i){return{__nativeC2d:!0,k:`conic`,c:e,u:t,v:n,a0:r,a1:i}}function zw(e,[t,n]){return[e.a*t+e.b*n+e.tx,e.c*t+e.d*n+e.ty]}function Bw(e,[t,n]){return[e.a*t+e.b*n,e.c*t+e.d*n]}function Vw(e,t){return{a:e.a*t.a+e.b*t.c,b:e.a*t.b+e.b*t.d,c:e.c*t.a+e.d*t.c,d:e.c*t.b+e.d*t.d,tx:e.a*t.tx+e.b*t.ty+e.tx,ty:e.c*t.tx+e.d*t.ty+e.ty}}function Hw(e,t){return e.k===`line`?Lw(zw(t,e.p1),zw(t,e.p2)):e.k===`bezier`?{__nativeC2d:!0,k:`bezier`,pts:e.pts.map(e=>zw(t,e))}:Rw(zw(t,e.c),Bw(t,e.u),Bw(t,e.v),e.a0,e.a1)}function Uw(e,t){let n=e.map(e=>[e[0],e[1]]);for(let e=1;e<n.length;e++)for(let r=0;r<n.length-e;r++){let e=n[r]??[0,0],i=n[r+1]??[0,0];n[r]=[e[0]*(1-t)+i[0]*t,e[1]*(1-t)+i[1]*t]}return n[0]??[0,0]}function Ww(e,t){let n=Math.cos(t),r=Math.sin(t);return[e.c[0]+e.u[0]*n+e.v[0]*r,e.c[1]+e.u[1]*n+e.v[1]*r]}function Gw(e,t){let n=e.length-1;if(n<1)return[0,0];let r=[];for(let t=0;t<n;t++){let i=e[t]??[0,0],a=e[t+1]??[0,0];r.push([n*(a[0]-i[0]),n*(a[1]-i[1])])}return Uw(r,t)}function Kw(e){let t=Math.abs(e.a1-e.a0),n=Math.hypot(e.u[0],e.u[1]),r=Math.hypot(e.v[0],e.v[1]),i=Math.max(n,r);if(i<=Fw)return Math.max(2,Math.ceil(t/(2*Math.PI)*8));let a=2*Math.acos(Math.max(-1,1-Fw/i));return Math.max(2,Math.ceil(t/a))}function qw(e){if(e.k===`line`)return[e.p1,e.p2];if(e.k===`bezier`){let t=[];for(let n=0;n<=24;n++)t.push(Uw(e.pts,n/24));return t}let t=e.a1-e.a0,n=Kw(e),r=[];for(let i=0;i<=n;i++){let a=e.a0+t*i/n,o=Math.cos(a),s=Math.sin(a);r.push([e.c[0]+e.u[0]*o+e.v[0]*s,e.c[1]+e.u[1]*o+e.v[1]*s])}return r}function Jw(e,t,n){let r=e[0],i=e[1],a=t[0],o=t[1],s=n[0],c=n[1],l=2*(r*(o-c)+a*(c-i)+s*(i-o));if(Math.abs(l)<1e-12)return Lw(e,n);let u=((r*r+i*i)*(o-c)+(a*a+o*o)*(c-i)+(s*s+c*c)*(i-o))/l,d=((r*r+i*i)*(s-a)+(a*a+o*o)*(r-s)+(s*s+c*c)*(a-r))/l,f=[u,d],p=Math.hypot(r-u,i-d),m=e=>Math.atan2(e[1]-d,e[0]-u),h=m(e),g=m(t),_=m(n),v=e=>(e%(2*Math.PI)+2*Math.PI)%(2*Math.PI),y=v(g-h),b=v(_-h);return _=y<=b?h+b:h-v(h-_),Rw(f,[p,0],[0,p],h,_)}function Yw(e,t){let n={delete:()=>{},isEmpty:()=>!1};function r(e,...n){let r=t(),i=r?.[e];if(!i)throw Error(`manifold 2D: ${e} needs an OCCT kernel (none registered)`);return i.call(r,...n)}let i=e=>e;function a(e){let n=t();if(!n)throw Error(`manifold 2D: ${e} needs an OCCT kernel (none registered)`);return n}function o(e){if(!Iw(e))return e;let t=a(`toOcct`),n=i(e);if(n.k===`line`)return t.makeLine2d(n.p1[0],n.p1[1],n.p2[0],n.p2[1]);if(n.k===`bezier`)return t.makeBezier2d(n.pts);let r=Math.hypot(n.u[0],n.u[1]),o=Math.hypot(n.v[0],n.v[1]),s=Math.abs(Math.abs(n.a1-n.a0)-2*Math.PI)<1e-9,c=n.u[0]*n.v[1]-n.u[1]*n.v[0]>=0;if(Math.abs(r-o)<1e-9*Math.max(1,r)){if(s)return t.makeCircle2d(n.c[0],n.c[1],r,c);let e=Ww(n,n.a0),i=Ww(n,(n.a0+n.a1)/2),a=Ww(n,n.a1);return t.makeArc2dThreePoints(e[0],e[1],i[0],i[1],a[0],a[1])}let l=n.u[0]*n.v[0]+n.u[1]*n.v[1];if(Math.abs(l)<1e-9*Math.max(1,r*o)){let e=n.u[0]/r,i=n.u[1]/r;return s?t.makeEllipse2d(n.c[0],n.c[1],r,o,e,i,c):t.makeEllipseArc2d(n.c[0],n.c[1],r,o,n.a0,n.a1,e,i,c)}return t.makeBSpline2d(qw(n).map(e=>[e[0],e[1]]))}let s={createPoint2d:(e,t)=>({x:e,y:t}),createDirection2d:(e,t)=>({x:e,y:t}),createVector2d:(e,t)=>({x:e,y:t}),createAxis2d:(e,t,n,r)=>({px:e,py:t,dx:n,dy:r}),wrapCurve2dHandle:e=>e,createCurve2dAdaptor:e=>e,makeLine2d:(e,t,n,r)=>Lw([e,t],[n,r]),makeCircle2d:(e,t,n,r=!0)=>Rw([e,t],[n,0],r?[0,n]:[0,-n],0,2*Math.PI),makeArc2dThreePoints:(e,t,n,r,i,a)=>Jw([e,t],[n,r],[i,a]),makeArc2dTangent:(e,t,n,r,i,a)=>{let o=Math.hypot(n,r)||1,s=-r/o,c=n/o,l=[i-e,a-t],u=s*l[0]+c*l[1];if(Math.abs(u)<1e-12)return Lw([e,t],[i,a]);let d=(l[0]*l[0]+l[1]*l[1])/(2*u),f=e+s*d,p=t+c*d,m=Math.hypot(e-f,t-p),h=Math.atan2(t-p,e-f),g=Math.atan2(a-p,i-f);s*n+c*r;let _=e=>(e%(2*Math.PI)+2*Math.PI)%(2*Math.PI),v=[-(t-p),e-f];return g=v[0]*n+v[1]*r>=0?h+_(g-h):h-_(h-g),Rw([f,p],[m,0],[0,m],h,g)},makeEllipse2d:(e,t,n,r,i=1,a=0,o=!0)=>{let s=Math.hypot(i,a)||1,c=i/s*n,l=a/s*n,u=-a/s*r*(o?1:-1),d=i/s*r*(o?1:-1);return Rw([e,t],[c,l],[u,d],0,2*Math.PI)},makeEllipseArc2d:(e,t,n,r,i,a,o=1,s=0,c=!0)=>{let l=Math.hypot(o,s)||1,u=o/l*n,d=s/l*n,f=-s/l*r*(c?1:-1),p=o/l*r*(c?1:-1);return Rw([e,t],[u,d],[f,p],i,a)},makeBezier2d:e=>({__nativeC2d:!0,k:`bezier`,pts:e.map(e=>[e[0],e[1]])}),evaluateCurve2d:(e,t)=>{let n=i(e);if(n.k===`line`){let e=n.p2[0]-n.p1[0],r=n.p2[1]-n.p1[1],i=Math.hypot(e,r)||1;return[n.p1[0]+e*t/i,n.p1[1]+r*t/i]}return n.k===`bezier`?Uw(n.pts,t):[n.c[0]+n.u[0]*Math.cos(t)+n.v[0]*Math.sin(t),n.c[1]+n.u[1]*Math.cos(t)+n.v[1]*Math.sin(t)]},evaluateCurve2dD1:(e,t)=>{let n=i(e);if(n.k===`line`){let e=n.p2[0]-n.p1[0],r=n.p2[1]-n.p1[1],i=Math.hypot(e,r)||1;return{point:[n.p1[0]+e*t/i,n.p1[1]+r*t/i],tangent:[e/i,r/i]}}if(n.k===`bezier`)return{point:Uw(n.pts,t),tangent:Gw(n.pts,t)};let r=Math.cos(t),a=Math.sin(t);return{point:[n.c[0]+n.u[0]*r+n.v[0]*a,n.c[1]+n.u[1]*r+n.v[1]*a],tangent:[-n.u[0]*a+n.v[0]*r,-n.u[1]*a+n.v[1]*r]}},getCurve2dBounds:e=>{let t=i(e);return t.k===`conic`?{first:t.a0,last:t.a1}:t.k===`line`?{first:0,last:Math.hypot(t.p2[0]-t.p1[0],t.p2[1]-t.p1[1])}:{first:0,last:1}},getCurve2dType:e=>{let t=i(e);return t.k===`line`?`LINE`:t.k===`bezier`?`BEZIER`:`CIRCLE`},reverseCurve2d:e=>{let t=i(e);if(t.k===`line`){let e=t.p1;t.p1=t.p2,t.p2=e}else if(t.k===`bezier`)t.pts.reverse();else{let e=t.a0;t.a0=t.a1,t.a1=e}},copyCurve2d:e=>structuredClone(i(e)),trimCurve2d:(e,t,n)=>{let r=i(e);if(r.k===`conic`)return Rw(r.c,r.u,r.v,t,n);if(r.k===`line`){let e=r.p2[0]-r.p1[0],i=r.p2[1]-r.p1[1],a=Math.hypot(e,i)||1;return Lw([r.p1[0]+e*t/a,r.p1[1]+i*t/a],[r.p1[0]+e*n/a,r.p1[1]+i*n/a])}return structuredClone(r)},createIdentityGTrsf2d:()=>({a:1,b:0,c:0,d:1,tx:0,ty:0}),createTranslationGTrsf2d:(e,t)=>({a:1,b:0,c:0,d:1,tx:e,ty:t}),createRotationGTrsf2d:(e,t,n)=>{let r=Math.cos(e),i=Math.sin(e);return{a:r,b:-i,c:i,d:r,tx:t-(r*t-i*n),ty:n-(i*t+r*n)}},createScaleGTrsf2d:(e,t,n)=>({a:e,b:0,c:0,d:e,tx:t-e*t,ty:n-e*n}),createMirrorGTrsf2d:(e,t,n,r=0,i=0,a=1,o=0)=>{if(n===`point`)return{a:-1,b:0,c:0,d:-1,tx:2*e,ty:2*t};let s=Math.hypot(a,o)||1,c=a/s,l=o/s,u=c*c-l*l,d=2*c*l;return{a:u,b:d,c:d,d:-u,tx:r-(u*r+d*i),ty:i-(d*r-u*i)}},createAffinityGTrsf2d:(e,t,n,r,i)=>{let a=Math.hypot(n,r)||1,o=n/a,s=r/a,c=-s,l=o,u=o*o+i*c*c,d=o*s+i*c*l,f=s*o+i*l*c,p=s*s+i*l*l;return{a:u,b:d,c:f,d:p,tx:e-(u*e+d*t),ty:t-(f*e+p*t)}},setGTrsf2dTranslationPart:(e,t,n)=>{let r=e;r.tx=t,r.ty=n},multiplyGTrsf2d:(e,t)=>{let n=Vw(e,t);Object.assign(e,n)},transformCurve2dGeneral:(e,t)=>Hw(i(e),t),translateCurve2d:(e,t,n)=>Hw(i(e),{a:1,b:0,c:0,d:1,tx:t,ty:n}),rotateCurve2d:(e,t,n,r)=>{let a=Math.cos(t),o=Math.sin(t);return Hw(i(e),{a,b:-o,c:o,d:a,tx:n-(a*n-o*r),ty:r-(o*n+a*r)})},scaleCurve2d:(e,t,n,r)=>Hw(i(e),{a:t,b:0,c:0,d:t,tx:n-t*n,ty:r-t*r}),mirrorCurve2dAtPoint:(e,t,n)=>Hw(i(e),{a:-1,b:0,c:0,d:-1,tx:2*t,ty:2*n}),mirrorCurve2dAcrossAxis:(e,t,n,r,a)=>{let o=Math.hypot(r,a)||1,s=r/o,c=a/o,l=s*s-c*c,u=2*s*c;return Hw(i(e),{a:l,b:u,c:u,d:-l,tx:t-(l*t+u*n),ty:n-(u*t-l*n)})},affinityTransform2d:(e,t,n,r,a,o)=>{let s=Math.hypot(r,a)||1,c=r/s,l=a/s,u=-l,d=c,f=c*c+o*u*u,p=c*l+o*u*d,m=l*c+o*d*u,h=l*l+o*d*d;return Hw(i(e),{a:f,b:p,c:m,d:h,tx:t-(f*t+p*n),ty:n-(m*t+h*n)})},createBoundingBox2d:()=>({min:[1/0,1/0],max:[-1/0,-1/0]}),addCurveToBBox2d:(e,t)=>{let n=e,r;if(Iw(t))r=qw(i(t));else{let e=a(`addCurveToBBox2d`),{first:n,last:i}=e.getCurve2dBounds(t);r=[];for(let a=0;a<=32;a++)r.push(e.evaluateCurve2d(t,n+(i-n)*a/32))}for(let[e,t]of r)e<n.min[0]&&(n.min[0]=e),t<n.min[1]&&(n.min[1]=t),e>n.max[0]&&(n.max[0]=e),t>n.max[1]&&(n.max[1]=t)},getBBox2dBounds:e=>{let t=e;return{xMin:t.min[0],yMin:t.min[1],xMax:t.max[0],yMax:t.max[1]}},mergeBBox2d:(e,t)=>{let n=e,r=t;n.min[0]=Math.min(n.min[0],r.min[0]),n.min[1]=Math.min(n.min[1],r.min[1]),n.max[0]=Math.max(n.max[0],r.max[0]),n.max[1]=Math.max(n.max[1],r.max[1])},isBBox2dOut:(e,t)=>{let n=e,r=t;return n.max[0]<r.min[0]||n.min[0]>r.max[0]||n.max[1]<r.min[1]||n.min[1]>r.max[1]},isBBox2dOutPoint:(e,t,n)=>{let r=e;return t<r.min[0]||t>r.max[0]||n<r.min[1]||n>r.max[1]},getCurve2dCircleData:e=>{let t=i(e);if(t.k!==`conic`)return null;let n=Math.hypot(t.u[0],t.u[1]),r=Math.hypot(t.v[0],t.v[1]);return Math.abs(n-r)>1e-6?null:{cx:t.c[0],cy:t.c[1],radius:n,isDirect:!0}},liftCurve2dToPlane:(e,t,r,a)=>{let o=r[0],s=r[1],c=r[2],l=a[0],u=a[1],d=a[2],f=s*d-c*u,p=c*l-o*d,m=o*u-s*l;return ky(n,B(`profileEdge`,{pts:qw(i(e)).map(([e,n])=>[t[0]+l*e+f*n,t[1]+u*e+p*n,t[2]+d*e+m*n])},[]))},makeBSpline2d:(e,t)=>a(`makeBSpline2d`).makeBSpline2d(e,t),offsetCurve2d:(e,t)=>a(`offsetCurve2d`).offsetCurve2d(o(e),t),intersectCurves2d:(e,t,n)=>a(`intersectCurves2d`).intersectCurves2d(o(e),o(t),n),projectPointOnCurve2d:(e,t,n)=>a(`projectPointOnCurve2d`).projectPointOnCurve2d(o(e),t,n),distanceBetweenCurves2d:(e,t,n,r,i,s)=>a(`distanceBetweenCurves2d`).distanceBetweenCurves2d(o(e),o(t),n,r,i,s),approximateCurve2dAsBSpline:(e,t,n,r)=>a(`approximateCurve2dAsBSpline`).approximateCurve2dAsBSpline(o(e),t,n,r),decomposeBSpline2dToBeziers:e=>a(`decomposeBSpline2dToBeziers`).decomposeBSpline2dToBeziers(o(e)),serializeCurve2d:e=>a(`serializeCurve2d`).serializeCurve2d(o(e)),deserializeCurve2d:e=>a(`deserializeCurve2d`).deserializeCurve2d(e),splitCurve2d:(e,t)=>a(`splitCurve2d`).splitCurve2d(o(e),t),getCurve2dEllipseData:e=>a(`getCurve2dEllipseData`).getCurve2dEllipseData(o(e)),getCurve2dBezierPoles:e=>a(`getCurve2dBezierPoles`).getCurve2dBezierPoles(o(e)),getCurve2dBezierDegree:e=>a(`getCurve2dBezierDegree`).getCurve2dBezierDegree(o(e)),getCurve2dBSplineData:e=>a(`getCurve2dBSplineData`).getCurve2dBSplineData(o(e)),buildEdgeOnSurface:(e,t)=>a(`buildEdgeOnSurface`).buildEdgeOnSurface(o(e),t),extractSurfaceFromFace:e=>a(`extractSurfaceFromFace`).extractSurfaceFromFace(e),extractCurve2dFromEdge:(e,t)=>a(`extractCurve2dFromEdge`).extractCurve2dFromEdge(e,t),buildCurves3d:e=>{a(`buildCurves3d`).buildCurves3d(e)},fixWireOnFace:(e,t,n)=>a(`fixWireOnFace`).fixWireOnFace(e,t,n),fillSurface:(e,t)=>a(`fillSurface`).fillSurface(e,t)};for(let e of[`evaluateCurve2d`,`evaluateCurve2dD1`,`getCurve2dBounds`,`getCurve2dType`,`reverseCurve2d`,`copyCurve2d`,`trimCurve2d`,`transformCurve2dGeneral`,`translateCurve2d`,`rotateCurve2d`,`scaleCurve2d`,`mirrorCurve2dAtPoint`,`mirrorCurve2dAcrossAxis`,`affinityTransform2d`,`getCurve2dCircleData`,`liftCurve2dToPlane`]){let t=s[e];t&&(s[e]=((n,...i)=>Iw(n)?t(n,...i):r(e,n,...i)))}return s}var Xw=`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 Zw(e){let t=My();if(!t)throw Error(`manifold: ${e} unsupported on manifold kernel; no B-rep kernel registered`);return t}function Qw(e){let t={};for(let e of Xw)t[e]=(...t)=>Zw(e)[e](...t);let n=Yw(e,()=>My());return Object.assign(t,n),t}function $w(e){return{sketchNew:()=>Ey(`sketchNew`),sketchAddPoint:()=>Ey(`sketchAddPoint`),sketchAddArc:()=>Ey(`sketchAddArc`),sketchAddConstraint:()=>Ey(`sketchAddConstraint`),sketchSolve:()=>Ey(`sketchSolve`),sketchDof:()=>Ey(`sketchDof`)}}function eT(e){return{projectEdges:()=>Ey(`projectEdges`)}}function tT(e){return{dispose(e){let t=Ay(e);if(t){let e=Py.get(t.node);e!==void 0&&(My()?.dispose(e),Py.delete(t.node))}(e?.manifold)?.delete?.()},executeBatch:()=>Ey(`executeBatch`),checkpoint:()=>Ey(`checkpoint`),checkpointCount:()=>0,restoreCheckpoint:()=>Ey(`restoreCheckpoint`),discardCheckpoint:()=>Ey(`discardCheckpoint`)}}var nT={draft:30,standard:10,fine:3},rT=class{oc;kernelId=`manifold`;capabilities={exact:!1,brepExport:!1,exactMeasurement:!1,tessellationModel:`build-time`};setQuality(e){let t=this.oc;t.setCircularSegments?.(0),t.setMinCircularEdgeLength?.(0),t.setMinCircularAngle?.(nT[e])}constructor(e){this.oc=e,Object.assign(this,By(e),Gy(e),pb(e),bx(e),Kx(e),yS(e),DS(e),_C(e),VC(e),Sw(e),Dw(e),Mw(e),Pw(e),Qw(e),$w(e),eT(e),tT(e))}};function iT(e){return`projectEdges`in e}function aT(e){return`sketchNew`in e&&`sketchDof`in e}var oT=new Map,sT=null,cT=null;function lT(e){uT(`manifold`,new rT(e))}function uT(e,t){oT.set(e,t),sT||=e,e===sT&&(cT=t)}function U(e){if(!e&&cT)return cT;let t=e??sT;if(!t)throw Error(`brepjs kernel not initialized. Call initFromOC() or registerKernel() before using the library.`);let n=oT.get(t);if(!n)throw Error(`brepjs: kernel '${t}' is not registered.`);return n}function dT(e){let t=U(e);if(!xo(t))throw Error(`brepjs: current kernel does not support 2D operations.`);return t}function fT(){return sT}function pT(e,t){let n=sT;sT=e,cT=oT.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{sT=n,cT=n?oT.get(n)??null:null}}function mT(e){return U(e).capabilities}function hT(e,t){let n=vo();try{bo(e),U().setQuality?.(e);let n=t();if(n instanceof Promise)throw Error(`withQuality() callback returned a Promise. Async code must read currentQuality()/getKernel() directly.`);return n}finally{bo(n),U().setQuality?.(n)}}var gT=new Map;function _T(e,t){gT.set(e,t)}function vT(e){return gT.get(e)}function yT(e,t){let n=gT.get(e);if(!n)throw Error(`withTier: no tier registered for "${e}". Call registerKernelTier("${e}", { kernel, quality }) first.`);return pT(n.kernel,()=>hT(n.quality,t))}function bT(e){Lo(),Zc(),Ao(),Dc(),Oc(),Uc(),Wc();let t=new Pf(e);uT(`occt`,t),sT=`occt`,cT=t}function xT(){let e=U(),t=e.makeBox(1,1,1);try{e.dispose(t)}catch{}}async function ST(){if(sT)return sT;try{let{OcctKernel:e}=await import(`occt-wasm`),t=await e.init();return uT(`occt-wasm`,ja.fromKernel(t)),`occt-wasm`}catch{}try{return bT(await(await import(`brepjs-opencascade`)).default()),`occt`}catch{}try{let e=await import(`brepkit-wasm`);return typeof e.default==`function`&&await e.default(),uT(`brepkit`,new Ty(new e.BrepKernel)),`brepkit`}catch{}throw Error(`brepjs: no kernel package found. Install one of:
|
|
13
13
|
npm install occt-wasm (recommended, default)
|
|
14
14
|
npm install brepjs-opencascade
|
|
15
|
-
npm install brepkit-wasm`)}function CT(){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 wT=Symbol;wT.dispose??=Symbol.for(`Symbol.dispose`),wT.asyncDispose??=Symbol.for(`Symbol.asyncDispose`);var TT=globalThis;TT.FinalizationRegistry||=(console.warn(`brepjs: FinalizationRegistry unavailable — garbage collection will not work`),class{register(e,t,n){}unregister(e){return!1}});var ET={liveHandles:0,peakHandles:0,gcCollected:0,scopeEnters:0,scopeExits:0};function DT(){return{...ET}}function OT(){ET.liveHandles=0,ET.peakHandles=0,ET.gcCollected=0,ET.scopeEnters=0,ET.scopeExits=0}function kT(){ET.liveHandles++,ET.liveHandles>ET.peakHandles&&(ET.peakHandles=ET.liveHandles)}function AT(){ET.liveHandles--}function jT(){ET.gcCollected++,ET.liveHandles--}var MT=new FinalizationRegistry(e=>{jT();try{e.delete()}catch{}});function NT(e){let t=!1,n=()=>{if(!t){t=!0,AT(),MT.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 kT(),MT.register(r,e,r),r}function PT(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,AT(),MT.unregister(n);try{e.delete()}catch{}}}};return kT(),MT.register(n,e,n),n}var FT=class{handles=[];constructor(){ET.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](){ET.scopeExits++;for(let e=this.handles.length-1;e>=0;e--)this.handles[e]?.();this.handles.length=0}};function IT(e){try{var t=CT();return e(t.u(new FT))}catch(e){t.e=e}finally{t.d()}}function LT(e,t){MT.register(e,t,t)}function RT(e){MT.unregister(e)}function zT(e){try{var t=CT();return e(t.u(new FT))}catch(e){t.e=e}finally{t.d()}}async function BT(e){try{var t=CT();return await e(t.u(new FT))}catch(e){t.e=e}finally{t.d()}}function VT(e){return!e.disposed}function HT(e){return e.__is2D!==!0}function UT(e){return e.__is2D===!0}function WT(e){if(!HT(e))throw Error(`Expected 3D shape, got 2D`);return e}function GT(e){if(!UT(e))throw Error(`Expected 2D shape, got 3D`);return e}var KT=new WeakMap;function qT(e,t){KT.set(e,t)}function JT(e,t){let n=KT.get(t);if(n!==void 0)return n;let r=e.shapeType(t);return KT.set(t,r),r}function YT(e){return JT(U(),e.wrapped)}function XT(e){return U().curveIsClosed(e.wrapped)}function ZT(e){return U().isValid(e.wrapped)}function QT(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 $T(e){return U().isValid(e.wrapped)}function eE(e){return XT(e)?O(e):k(`Wire is not closed: start and end points do not coincide`)}function tE(e){return ZT(e)?O(e):k(`Face orientation is inconsistent or face is invalid`)}function nE(e){return QT(e)?O(e):k(`Shell is not manifold: has free edges or is invalid`)}function rE(e){return $T(e)?O(e):k(`Solid failed BRepCheck validation`)}function iE(e){return U().surfaceType(e.wrapped)===`plane`}function aE(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 oE(e){return iE(e)?O(e):k(`Face is not planar: underlying surface is not a geometric plane`)}function sE(e){return aE(e)?O(e):k(`Wire is not planar: edges do not lie in a common plane`)}function cE(e,t){return t===`2D`&&(e.__is2D=!0),e}function lE(e,t){return cE(NT(e),t)}function uE(e,t){return cE(NT(e),t)}function dE(e,t){return cE(NT(e),t)}function fE(e,t){return cE(NT(e),t)}function pE(e){return cE(NT(e))}function mE(e){return cE(NT(e))}function hE(e){return cE(NT(e))}function gE(e,t){return cE(NT(e),t)}function _E(e){return YT(e)===`vertex`}function vE(e){return YT(e)===`edge`}function yE(e){return YT(e)===`wire`}function bE(e){return YT(e)===`face`}function xE(e){return YT(e)===`shell`}function SE(e){return YT(e)===`solid`}function CE(e){return YT(e)===`compound`}function wE(e){let t=YT(e);return t===`shell`||t===`solid`||t===`compsolid`?!0:t===`compound`?HT(e):!1}function TE(e){let t=YT(e);return t===`edge`||t===`wire`}function W(e,t){let n=U(),r=JT(n,e),i=n.downcast(e,r);return r===`vertex`?lE(i,t):r===`edge`?uE(i,t):r===`wire`?dE(i,t):r===`face`?fE(i,t):r===`shell`?pE(i):r===`solid`?mE(i):r===`compsolid`?hE(i):gE(i,t)}function EE(e){return W(e)}function DE(e,t,n){qT(e,t);let r=U().downcast(e,t);return t===`vertex`?lE(r,n):t===`edge`?uE(r,n):t===`wire`?dE(r,n):t===`face`?fE(r,n):t===`shell`?pE(r):t===`solid`?mE(r):t===`compsolid`?hE(r):gE(r,n)}function OE(e,t,n,r,i){let a={kind:e,code:t,message:n,cause:r};return i?{...a,suggestion:i}:a}var kE={KERNEL_OPERATION:(e,t,n,r)=>OE(`KERNEL_OPERATION`,e,t,n,r),VALIDATION:(e,t,n,r)=>OE(`VALIDATION`,e,t,n,r),TYPE_CAST:(e,t,n,r)=>OE(`TYPE_CAST`,e,t,n,r),SKETCHER_STATE:(e,t,n,r)=>OE(`SKETCHER_STATE`,e,t,n,r),MODULE_INIT:(e,t,n,r)=>OE(`MODULE_INIT`,e,t,n,r),COMPUTATION:(e,t,n,r)=>OE(`COMPUTATION`,e,t,n,r),IO:(e,t,n,r)=>OE(`IO`,e,t,n,r),QUERY:(e,t,n,r)=>OE(`QUERY`,e,t,n,r),UNSUPPORTED:(e,t,n,r)=>OE(`UNSUPPORTED`,e,t,n,r)};function AE(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`?oo(i):i,o=ao(t);return k(kE[r](t,`${n}: ${a}`,e,o))}}function jE(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`?oo(i):i,o=ao(t);return k(kE[r](t,`${n}: ${a}`,e,o))}}function ME(e,t,n,r=`KERNEL_OPERATION`){try{var i=CT();let a=i.u(new FT);return AE(()=>e(a),t,n,r)}catch(e){i.e=e}finally{i.d()}}function NE(e,t){let n=U().iterShapes(e,t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=DE(n[e],t);return r}var PE=new WeakMap;function FE(e){let t=PE.get(e.wrapped);return t||(t={},PE.set(e.wrapped,t)),t}function IE(e){return PE.get(e.wrapped)}function LE(e){PE.delete(e.wrapped)}function RE(e){let t=FE(e);if(t.edges)return t.edges;let n=NE(e.wrapped,`edge`);return t.edges=n,n}function zE(e){let t=FE(e);if(t.faces)return t.faces;let n=NE(e.wrapped,`face`);return t.faces=n,n}function BE(e){let t=FE(e);if(t.wires)return t.wires;let n=NE(e.wrapped,`wire`);return t.wires=n,n}function VE(e){let t=FE(e);if(t.vertices)return t.vertices;let n=NE(e.wrapped,`vertex`);return t.vertices=n,n}function HE(e){let t=FE(e);if(t.solids)return t.solids;let n=NE(e.wrapped,`solid`);return t.solids=n,n}function UE(e){let t=FE(e);if(t.shells)return t.shells;let n=NE(e.wrapped,`shell`);return t.shells=n,n}function WE(e){let t=FE(e);if(t.compSolids)return t.compSolids;let n=NE(e.wrapped,`compsolid`);return t.compSolids=n,n}function*GE(e){for(let t of U().iterShapes(e.wrapped,`edge`))yield DE(t,`edge`)}function*KE(e){for(let t of U().iterShapes(e.wrapped,`face`))yield DE(t,`face`)}function*qE(e){for(let t of U().iterShapes(e.wrapped,`wire`))yield DE(t,`wire`)}function*JE(e){for(let t of U().iterShapes(e.wrapped,`vertex`))yield DE(t,`vertex`)}function*YE(e){for(let t of U().iterShapes(e.wrapped,`solid`))yield DE(t,`solid`)}function*XE(e){for(let t of U().iterShapes(e.wrapped,`shell`))yield DE(t,`shell`)}function*ZE(e){for(let t of U().iterShapes(e.wrapped,`compsolid`))yield DE(t,`compsolid`)}function QE(e){let t=FE(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 $E(e){return JT(U(),e.wrapped)}function eD(e){let t=FE(e);if(t.surfaceType!==void 0)return t.surfaceType;let n=U().surfaceType(e.wrapped);return t.surfaceType=n,n}function tD(e){let t=FE(e);if(t.isValid!==void 0)return t.isValid;let n=U().isValid(e.wrapped);return t.isValid=n,n}function nD(e){return{kind:$E(e),faceCount:zE(e).length,edgeCount:RE(e).length,wireCount:BE(e).length,vertexCount:VE(e).length,valid:tD(e),bounds:QE(e)}}function rD(e){return U().vertexPosition(e.wrapped)}var G=2147483647,iD=Math.PI/180,aD=180/Math.PI;function oD(e){return e.length===2?[e[0],e[1],0]:[e[0],e[1],e[2]]}function sD(e){return[e[0],e[1]]}var cD={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function lD(e){if(typeof e==`string`){let t=cD[e];if(!t)throw Error(`Unknown direction: ${e}`);return t}return e}function uD(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function dD(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function fD(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function pD(e){return[-e[0],-e[1],-e[2]]}function mD(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function hD(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 gD(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function _D(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function vD(e,t){return gD(dD(e,t))}function yD(e){let t=gD(e);return t<1e-10?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function bD(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 xD(e,t=1e-10){return _D(e)<t*t}function SD(e,t){let n=mD(e,t),r=gD(e),i=gD(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 CD(e,t,n){let r=dD(e,t),i=_D(n);return i<1e-20?e:dD(e,fD(n,mD(r,n)/i))}function wD(e,t,n){let r=yD(t),i=Math.cos(n),a=Math.sin(n),o=mD(e,r),s=hD(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 TD=e=>Math.round(e*1e3)/1e3;function ED(e){return`x: ${TD(e[0])}, y: ${TD(e[1])}, z: ${TD(e[2])}`}function DD(e,t=null,n=[0,0,1]){let r=yD(n);if(xD(r))throw Error(`Plane normal must be non-zero`);let i;if(t)i=yD(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?yD([l,u,d]):[1,0,0]}if(xD(i))throw Error(`Plane xDir must be non-zero`);let a=yD(hD(r,i));return{origin:e,xDir:i,yDir:a,zDir:r}}var OD={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 kD(e,t=[0,0,0]){let n=OD[e];if(!n)return k(F(`UNKNOWN_PLANE`,`Could not find plane ${e}`));let r;return r=typeof t==`number`?fD(n.normal,t):oD(t),O(DD(r,n.xDir,n.normal))}function AD(e,t){return typeof e==`string`?kD(e,t):O(e)}function jD(e,t){return e&&typeof e!=`string`?{...e}:j(AD(e??`XY`,t))}function MD(e,t){let[n,r]=t;return uD(uD(e.origin,fD(e.xDir,n)),fD(e.yDir,r))}function ND(e,t){return{...e,origin:uD(e.origin,t)}}function PD(e,t,n=[1,0,0]){let r=t*iD,i=wD(e.zDir,n,r),a=wD(e.xDir,n,r),o=yD(hD(i,a));return{origin:e.origin,xDir:a,yDir:o,zDir:i}}var FD={compound:0,solidCompound:1,solid:2,shell:3,face:4,wire:5,edge:6,vertex:7,shape:8},ID=e=>FD[e],LD={vertex:`vertex`,edge:`edge`,wire:`wire`,face:`face`,shell:`shell`,solid:`solid`,solidCompound:`compsolid`,compound:`compound`,shape:`compound`},RD=function*(e,t){let n=LD[t];if(n){let t=U().iterShapes(e,n);for(let e of t)yield e}},zD=e=>U().isNull(e)?k(co(`NULL_SHAPE`,`This shape has no type, it is null`)):O(e.ShapeType());function BD(e){if(U().isNull(e))return k(co(`NULL_SHAPE`,`This shape has no type, it is null`));try{return O(U().downcast(e))}catch{return k(co(`NO_WRAPPER`,`Could not find a wrapper for this shape type`))}}function VD(e){return U().isNull(e)?k(co(`NULL_SHAPE`,`Cannot cast a null shape`)):O(W(e))}function HD(e){return U().shapeType(e.wrapped)===`compsolid`}function UD(e){return VD(U().fromBREP(e))}var WD={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 GD(e){return O(WD[eD(e)])}function KD(e){return j(GD(e))}function qD(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function JD(e){return W(U().reverseShape(e.wrapped))}function YD(e){return U().uvBounds(e.wrapped)}function XD(e,t,n){let r=YD(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 ZD(e,t){let n=oD(t);return U().uvFromPoint(e.wrapped,n)||[0,0]}function QD(e,t){let n=oD(t);try{let t=n,r=U().uvFromPoint(e.wrapped,t);if(!r)return k(co(`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(co(`PROJECTION_FAILED`,`Point projection failed: ${e instanceof Error?e.message:String(e)}`))}}function $D(e,t){let n,r;if(t)[n,r]=ZD(e,t);else{let t=YD(e);n=.5*(t.uMin+t.uMax),r=.5*(t.vMin+t.vMax)}return U().surfaceNormal(e.wrapped,n,r)}function eO(e){return U().surfaceCenterOfMass(e.wrapped)}function tO(e){return U().getSurfaceAxis(e.wrapped)}function nO(e,t,n=1e-6){let[r,i]=ZD(e,t);return U().classifyPointOnFace(e.wrapped,r,i,n)}function rO(e){return W(U().outerWire(e.wrapped))}function iO(e){return W(U().removeHolesFromFace(e.wrapped))}function aO(e){let t=rO(e);return Array.from(RD(e.wrapped,`wire`)).map(e=>W(j(BD(e)))).filter(e=>!U().isSame(e.wrapped,t.wrapped))}function oO(e,t){let n=FE(e),r=new Map;for(let n of zE(e))r.set(U().hashCode(n.wrapped,G),t);n.faceOrigins=r}function sO(e){return IE(e)?.faceOrigins}function cO(e,t,n){let r=new Map;for(let e of t){let t=sO(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=FE(n);e.faceOrigins=i}}function lO(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 uO(e,t){let n=new Map;for(let t of e){let e=sO(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=zE(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=sO(n);if(e)for(let i of zE(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=lO(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=FE(t);e.faceOrigins=i}}var dO=new WeakMap,fO=new WeakMap;function pO(e){return dO.has(e.wrapped)}function mO(e){let t=dO.get(e.wrapped);return t||(t=new Map,dO.set(e.wrapped,t)),t}function hO(e){let t=fO.get(e.wrapped);return t||(t=new Map,fO.set(e.wrapped,t)),t}function gO(e,t,n){let r=Array.isArray(t)?t:zE(e).filter(t),i=mO(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 _O(e,t){let n=dO.get(e.wrapped);if(!n)return[];let r=n.get(t);if(!r||r.size===0)return[];let i=[];for(let t of zE(e)){let e=U().hashCode(t.wrapped,G);r.has(e)&&i.push(t)}return i}function vO(e){let t=new Map,n=dO.get(e.wrapped);if(!n)return t;let r=zE(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 yO(e,t,n){return hO(e).set(t,n),e}function bO(e,t){return fO.get(e.wrapped)?.get(t)}function xO(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function SO(e,t,n){let r=mO(n);for(let i of t){let t=dO.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)xO(r,t,e)}let o=fO.get(i.wrapped);if(o){let e=hO(n);for(let[t,n]of o)e.has(t)||e.set(t,n)}}}var CO=new WeakMap,wO=new WeakMap;function TO(e){return CO.has(e.wrapped)||wO.has(e.wrapped)}function EO(e){let t=wO.get(e.wrapped);return t||(t=new Map,wO.set(e.wrapped,t)),t}function DO(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 OO(e,t){return CO.set(e.wrapped,DO(t)),e}function kO(e,t,n){let r=DO(n),i=EO(e);for(let e of t)i.set(U().hashCode(e.wrapped,G),r);return e}function AO(e){return CO.get(e.wrapped)}function jO(e,t){let n=wO.get(e.wrapped);if(n)return n.get(U().hashCode(t.wrapped,G))}function MO(e,t,n){for(let e of t){let t=CO.get(e.wrapped);if(t){CO.set(n.wrapped,t);break}}let r=EO(n);for(let n of t){let t=wO.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 NO(e){if(!e.some(e=>sO(e)!==void 0||pO(e)||TO(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 PO(e,t,n){cO(e,t,n),SO(e,t,n),MO(e,t,n)}function FO(e,t){uO(e,t)}function IO(e,t){let n=NO([e]),{shape:r,evolution:i}=U().translateWithHistory(e.wrapped,t[0],t[1],t[2],n,G),a=W(r);return PO(i,[e],a),a}function LO(e,t,n=[0,0,0],r=[0,0,1]){let i=NO([e]),{shape:a,evolution:o}=U().rotateWithHistory(e.wrapped,t*iD,i,G,r,n),s=W(a);return PO(o,[e],s),s}function RO(e,t=[0,1,0],n=[0,0,0]){let r=NO([e]),{shape:i,evolution:a}=U().mirrorWithHistory(e.wrapped,n,t,r,G),o=W(i);return PO(a,[e],o),o}function zO(e,t,n=[0,0,0]){let r=NO([e]),{shape:i,evolution:a}=U().scaleWithHistory(e.wrapped,n,t,r,G),o=W(i);return PO(a,[e],o),o}function BO(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(zO(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 VO(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 HO(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 UO(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 WO(e,t){let n=VO(t);if(!n.ok)return n;let{linear:r,translation:i}=n.value,a=HO(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(UO(r)){let t=NO([e]),{shape:n,evolution:a}=U().generalTransformWithHistory(e.wrapped,r,i,!0,t,G),o=W(n);return PO(a,[e],o),O(o)}let o=W(U().generalTransformNonOrthogonal(e.wrapped,r,i));return FO([e],o),O(o)}function GO(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 KO(e,t){let n=NO([e]),{shape:r,evolution:i}=U().applyComposedTransformWithHistory(e.wrapped,t.trsf,n,G),a=W(r);return PO(i,[e],a),a}function qO(e){return AE(()=>U().downcast(e.wrapped),N.CLONE_FAILED,`Failed to clone shape`)}function JO(e){return jE(()=>U().toBREP(e.wrapped),N.TO_BREP_FAILED,`Failed to serialize shape to BREP`)}function YO(e){return U().hashCode(e.wrapped,G)}function XO(e){return U().isNull(e.wrapped)}function ZO(e,t){return U().isSame(e.wrapped,t.wrapped)}function QO(e,t){return U().isEqual(e.wrapped,t.wrapped)}function $O(e){return AE(()=>U().simplify(e.wrapped),N.SIMPLIFY_FAILED,`Failed to simplify shape`)}function ek(e){return U().curveType(e.wrapped)}function tk(e){let[t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function nk(e){let[,t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function rk(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curvePointAtParam(e.wrapped,i)}function ik(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curveTangent(e.wrapped,i).tangent}function ak(e){return U().length(e.wrapped)}function ok(e){if(ek(e)!==`CIRCLE`)return null;let t=rk(e,0),n=rk(e,1/3),r=rk(e,2/3),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=o[0]*o[0]+o[1]*o[1]+o[2]*o[2];if(s<1e-18)return null;let c=i[0]*i[0]+i[1]*i[1]+i[2]*i[2],l=a[0]*a[0]+a[1]*a[1]+a[2]*a[2],u=[c*a[0]-l*i[0],c*a[1]-l*i[1],c*a[2]-l*i[2]],d=[u[1]*o[2]-u[2]*o[1],u[2]*o[0]-u[0]*o[2],u[0]*o[1]-u[1]*o[0]],f=1/(2*s),p=[t[0]+d[0]*f,t[1]+d[1]*f,t[2]+d[2]*f],m=Math.sqrt(s);return{origin:p,direction:[o[0]/m,o[1]/m,o[2]/m]}}function sk(e){return U().curveIsClosed(e.wrapped)}function ck(e){return U().curveIsPeriodic(e.wrapped)}function lk(e){return U().curvePeriod(e.wrapped)}function uk(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function dk(e){return W(U().reverseShape(e.wrapped))}function fk(e,t={}){if(e.length<2)return k(co(`INTERPOLATE_MIN_POINTS`,`Interpolation requires at least 2 points`));try{let n=W(U().interpolatePoints(e,t));return vE(n)?O(n):k(co(`INTERPOLATE_NOT_EDGE`,`Interpolation did not produce an edge`))}catch(e){return k(co(`INTERPOLATE_FAILED`,`Interpolation failed: ${e instanceof Error?e.message:String(e)}`))}}function pk(e,t={}){if(e.length<2)return k(co(`APPROXIMATE_MIN_POINTS`,`Approximation requires at least 2 points`));try{let n=W(U().approximatePoints(e,t));return vE(n)?O(n):k(co(`APPROXIMATE_NOT_EDGE`,`Approximation did not produce an edge`))}catch(e){return k(co(`APPROXIMATE_FAILED`,`Approximation failed: ${e instanceof Error?e.message:String(e)}`))}}function mk(e,t,n=`arc`){let r=W(U().offsetWire2D(e.wrapped,t,{arc:`arc`,intersection:`intersection`,tangent:`tangent`,chamfer:`intersection`}[n]));return yE(r)?O(r):(r[Symbol.dispose](),k(co(`OFFSET_NOT_WIRE`,`Offset did not produce a Wire`)))}function hk(e,t,n,r=!1){return`${e}:${t}:${n}:${r}`}function gk(e,t){return`edge:${e}:${t}`}var _k=new WeakMap,vk=new WeakMap;function yk(e,t){let n=_k.get(e);if(n)return n.get(t)}function bk(e,t,n){let r=_k.get(e);r||(r=new Map,_k.set(e,r)),r.set(t,n)}function xk(e,t){let n=vk.get(e);if(n)return n.get(t)}function Sk(e,t,n){let r=vk.get(e);r||(r=new Map,vk.set(e,r)),r.set(t,n)}function Ck(){_k=new WeakMap,vk=new WeakMap}function wk(){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 Tk(e,t={}){let n=bo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,skipNormals:a=!1,includeUVs:o=!1,cache:s=!0,signal:c}=t;c?.throwIfAborted();let l=hk(r,i,a,o);if(s){let t=yk(e.wrapped,l);if(t)return t}let u=U().mesh(e.wrapped,{tolerance:r,angularTolerance:i,skipNormals:a,includeUVs:o,...c?{signal:c}:{}}),d=sO(e),f={vertices:u.vertices,normals:u.normals,triangles:u.triangles,uvs:u.uvs,faceGroups:u.faceGroups.map(e=>({start:e.start,count:e.count,faceId:e.faceHash,origin:d?.get(e.faceHash)??0}))};return s&&bk(e.wrapped,l,f),f}function Ek(e,t={}){let n=bo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,cache:a=!0}=t,o=gk(r,i);if(a){let t=xk(e.wrapped,o);if(t)return t}let s=U().meshEdges(e.wrapped,r,i),c={lines:s.lines,edgeGroups:s.edgeGroups.map(e=>({start:e.start,count:e.count,edgeId:e.edgeHash}))};return a&&Sk(e.wrapped,o,c),c}function Dk(e,t){return e instanceof Error&&e.message.startsWith(`${t} export failed`)?po(`${t}_EXPORT_FAILED`,`Failed to write ${t} file`,e):e instanceof WebAssembly.RuntimeError?po(`${t}_EXPORT_CRASHED`,`${t} export crashed the kernel (${e.message}); the shape likely contains geometry the ${t} writer cannot serialize`,e):po(`${t}_FILE_READ_ERROR`,`Failed to read exported ${t} file`,e)}function Ok(e){let t;try{t=HE(e)}catch{return``}if(t.length<=1)return``;let n=[];return t.forEach((e,t)=>{try{QE(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 kk(e,t){try{return QE(e),null}catch(n){if(n instanceof TypeError)throw n;return po(`${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${Ok(e)}`,n)}}function Ak(e){let t=kk(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(Dk(e,`STEP`))}}function jk(e,t={}){let n=bo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,binary:a=!1}=t,o=kk(e,`STL`);if(o)return k(o);try{U().hasTriangulation(e.wrapped)||U().meshShape(e.wrapped,r,i);let t=U().exportSTL(e.wrapped,a,r,i);return O(new Blob([t],{type:`application/sla`}))}catch(e){return k(Dk(e,`STL`))}}function Mk(e){try{let t=U().exportIGES([e.wrapped]);return O(new Blob([t],{type:`application/iges`}))}catch(e){return k(po(`IGES_EXPORT_FAILED`,`Failed to write IGES file`,e))}}function Nk(e,t){let n=t?.coarseTolerance??.5,r=t?.fineTolerance??.05,i=t?.angularTolerance??.5;return{coarse:Tk(e,{tolerance:n,angularTolerance:i}),fine:Tk(e,{tolerance:r,angularTolerance:i*.2})}}function Pk(e,t,n){if(t<0||t>=e.length)throw Error(n??`Index ${t} out of bounds (length ${e.length})`);return e[t]}function Fk(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[0]}function Ik(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[e.length-1]}function Lk(e){return Array.from(Array(e).keys())}function Rk(e){return Lk(Math.min(...e.map(e=>e.length))).map(t=>e.map(e=>e[t]))}function zk(e,t){return uE(U().makeLineEdge([...e],[...t]))}function Bk(e,t=[0,0,0],n=[0,0,1]){return uE(U().makeCircleEdge([...t],[...n],e))}function Vk(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(uE(U().makeEllipseEdge([...n],[...r],e,t,i?[...i]:void 0)))}function Hk(e,t,n,r=[0,0,0],i=[0,0,1],a=!1){return dE(U().makeHelixWire(e,t,n,[...r],[...i],a))}function Uk(e,t,n){return uE(U().makeArcEdge([...e],[...t],[...n]))}function Wk(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(uE(U().makeEllipseArc([...i],[...a],e,t,n,r,o?[...o]:void 0)))}function Gk(e,{tolerance:t=.001,smoothing:n=null,degMax:r=6,degMin:i=1}={}){try{let a=e.map(e=>[...e]);return O(uE(U().approximatePoints(a,{tolerance:t,degMin:i,degMax:r,smoothing:n})))}catch{return k(P(`BSPLINE_FAILED`,`B-spline approximation failed`))}}function Kk(e,{periodic:t=!1,tolerance:n=1e-7}={}){try{let r=e.map(e=>[...e]);return O(uE(U().interpolatePoints(r,{periodic:t,tolerance:n})))}catch{return k(P(`BSPLINE_INTERP_FAILED`,`B-spline interpolation failed`))}}function qk(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(uE(U().makeBezierEdge(t)))}function Jk(e,t,n){return uE(U().makeTangentArc([...e],[...t],[...n]))}function Yk(e){try{return O(dE(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 Xk(e,t){try{let n=U().makeFace(e.wrapped,!0);if(t&&t.length>0){let e=eA(fE(n),t);return iE(e)?O(e):k(F(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}let r=fE(n);return iE(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 Zk(e){return Xk(rO(e))}function Qk(e,t){return fE(U().makeFaceOnSurface(e.wrapped,t.wrapped))}function $k(e){try{return Ia(VD(U().makeNonPlanarFace(e.wrapped)),e=>bE(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 eA(e,t){return fE(U().addHolesInFace(e.wrapped,t.map(e=>e.wrapped)))}function tA(e){return e.length<3?k(F(`POLYGON_MIN_POINTS`,`You need at least 3 points to make a polygon`)):Ia(Yk(Rk([e,[...e.slice(1),e[0]]]).map(([e,t])=>zk(e,t))),e=>Xk(e))}function nA(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function rA(e,t,n,r,i){let a=W(e);if(!wE(a)){let o=e.ShapeType(),s=[`COMPOUND`,`COMPSOLID`,`SOLID`,`SHELL`,`FACE`,`WIRE`,`EDGE`,`VERTEX`,`SHAPE`][o]??`UNKNOWN(${o})`;return a[Symbol.dispose](),k(co(t,`${n}. Got ${s} instead.`,void 0,i?{diagnostics:i}:void 0,r))}return O(a)}function iA(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=nA(e,`fuse: first operand`);if(A(c))return c;let l=nA(t,`fuse: second operand`);if(A(l))return l;if(!s)return rA(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);let u=NO([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),rA(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=rA(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&&PO(f,[e,t],m.value),m}function aA(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=nA(e,`cut: base`);if(A(c))return c;let l=nA(t,`cut: tool`);if(A(l))return l;if(!s)return rA(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);let u=NO([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),rA(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=rA(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&&PO(f,[e,t],m.value),m}function oA(e,t,{simplify:n=!1,signal:r,fuzzyValue:i,unsafe:a,trackEvolution:o=!0}={}){if(r?.aborted)throw r.reason;let s=nA(e,`intersect: first operand`);if(A(s))return s;let c=nA(t,`intersect: second operand`);if(A(c))return c;if(!o)return rA(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);let l=NO([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),rA(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=rA(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&&PO(d,[e,t],p.value),p}function sA(e,t,n,r,i,a,o,s){if(o?.aborted)throw o.reason;let c=n-t;if(c===1)return O(Pk(e,t));if(c===2)return iA(Pk(e,t),Pk(e,t+1),{optimisation:r,simplify:!1,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}});let l=t+Math.ceil(c/2),u=sA(e,t,l,r,i,a,o,s);if(A(u))return u;let d=sA(e,l,n,r,i,a,o,s);return A(d)?d:iA(u.value,d.value,{optimisation:r,simplify:i,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}})}function cA(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(Fk(e));for(let t=0;t<e.length;t++){let n=nA(Pk(e,t),`fuseAll: shape at index ${t}`);if(A(n))return n}if(r===`native`){let o=rA(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&&FO(e,o.value),o}return sA(e,0,e.length,t,n,s,i,a)}function lA(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=nA(e,`cutAll: base`);if(A(c))return c;for(let e=0;e<t.length;e++){let n=nA(Pk(t,e),`cutAll: tool at index ${e}`);if(A(n))return n}let l=[e,...t],u=rA(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&&FO(l,u.value),u}function uA(e,t){let n=U(),r=fD(e.xDir,t),i=fD(e.yDir,t),a=fD(e.xDir,-t),o=fD(e.yDir,-t),s=e.origin,c=[...uD(uD(s,a),o)],l=[...uD(uD(s,r),o)],u=[...uD(uD(s,r),i)],d=[...uD(uD(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 dA(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=uA(typeof t==`string`?j(AD(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 fA(e){let t=U(),n=new Map,r=new Map;for(let i of e){let e=VE(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 pA(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 mA(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=pA(i,t,n);for(;o;)e===0?r.push(o.edge):r.unshift(o.edge),i=o.nextTip,o=pA(i,t,n)}return r}function hA(e){let t=U(),n=fA(e),r=new Set,i=[];for(let a of e){if(r.has(a))continue;let e=mA(a,n,r);try{let n=t.makeWire(e.map(e=>e.wrapped));i.push(W(n))}catch{}}return i}function gA(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 _A(e,t,n={}){let r=dA(e,t,n);if(!r.ok)return r;let i=BE(r.value);if(i.length===0){let e=RE(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(...hA(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=gA(i),o=Pk(i,a),s=i.filter((e,t)=>t!==a);return Xk(o,s.length>0?s:void 0)}function vA(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(Pk(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 yA(e,t,n={}){let r=[];for(let i of t){let t=dA(e,i,n);if(A(t))return t;r.push(t.value)}return O(r)}function bA(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 xA(e,t,n);if(o===null)return k(P(`BOOLEAN_PIPELINE_FAILED`,`Boolean pipeline returned null shape`));let s=W(o);return wE(s)?O(s):k(co(`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 xA(e,t,n){let r=e,i={...n?.optimisation?{optimisation:n.optimisation}:{},unsafe:!0};for(let e of t){let t=e.op===`fuse`?iA(r,e.tool,i):e.op===`cut`?aA(r,e.tool,i):oA(r,e.tool,i);if(A(t))return t;r=j(t)}return O(r)}function SA(e){return j(VD(j(BD(U().sew(e.map(e=>e.wrapped))))))}function CA(e,t=!1){let n=SA(e);return!t&&!xE(n)?k(co(`WELD_NOT_SHELL`,`Could not make a shell from faces and shells`)):O(n)}function wA(e,t,n=[0,0,0],r=[0,0,1]){return mE(U().makeCylinder(e,t,[...n],[...r]))}function TA(e){return mE(U().makeSphere(e))}function EA(e,t,n,r=[0,0,0],i=[0,0,1]){return mE(U().makeCone(e,t,n,[...r],[...i]))}function DA(e,t,n=[0,0,0],r=[0,0,1]){return mE(U().makeTorus(e,t,[...n],[...r]))}function OA(e,t,n){return mE(U().makeEllipsoid(e,t,n))}function kA(e){return lE(U().makeVertex(e[0],e[1],e[2]))}function AA(e,t,n=1e-6){return Ia(BD(U().offset(e.wrapped,t,n)),e=>Ia(VD(e),e=>wE(e)?O(e):k(co(`OFFSET_NOT_3D`,`Could not offset to a 3d shape`))))}function jA(e){return gE(U().makeCompound(e.map(e=>e.wrapped)))}function MA(e){let t=SA(e);return Ia(VD(U().solidFromShell(t.wrapped)),e=>SE(e)?O(e):k(co(`SOLID_BUILD_FAILED`,`Could not make a solid of faces and shells`)))}function NA(e){return{position:e.vertices,normal:e.normals,index:e.triangles}}function PA(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 FA(e){return{position:e.lines}}function IA(e,t){return{coarse:NA(e.coarse),fine:NA(e.fine),coarseDistance:t?.coarse??50,fineDistance:t?.fine??0}}function LA(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=BD(i);if(A(a))return a;let o=W(a.value);return wE(o)?O(o):(o[Symbol.dispose](),k(co(`CHAMFER_ANGLE_NOT_3D`,`chamferDistAngle did not produce a 3D shape`)))}function RA(e,t){return e.map(e=>DE(e,t))}function zA(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 RA(i,t)}function BA(e){let t=FE(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 VA(e,t){let n=U(),r=BA(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 RA(o,`face`)}function HA(e){return zA(e.wrapped,`edge`)}function UA(e){return zA(e.wrapped,`wire`)}function WA(e){return zA(e.wrapped,`vertex`)}function GA(e,t){let n=U(),r=BA(e),i=zA(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 RA(a,`face`)}function KA(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 RA(o,`edge`)}function qA(e){let t=U();return t.getNurbsCurveData?t.getNurbsCurveData(e.wrapped):null}function JA(e){let t=U();return t.getNurbsSurfaceData?t.getNurbsSurfaceData(e.wrapped):null}var YA={cut:aA,cutAll:lA,fuse:iA,fuseAll:cA};function XA(e){return{totalInputs:e.totalInputs,batchAttempts:e.batchAttempts,batchSucceeded:e.batchSucceeded,singletonFallbacks:e.singletonFallbacks,failedInputs:[...e.failedInputs].sort((e,t)=>e-t)}}function ZA(e,t,n={}){return QA(YA,e,t,n)}function QA(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=$A(e,t,n,0,r,i);return A(a)?a:O({shape:a.value,telemetry:XA(i)})}function $A(e,t,n,r,i,a){if(n.length===0)return O(t);if(n.length===1)return ej(e,t,n,r,i,a);a.batchAttempts++;let o=aj(()=>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=$A(e,t,n.slice(0,s),r,i,a);return c.ok?$A(e,c.value,n.slice(s),r+s,i,a):c}function ej(e,t,n,r,i,a){a.singletonFallbacks++;let o=Fk(n),s=aj(()=>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 tj(e,t={}){return nj(YA,e,t)}function nj(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=rj(e,t,0,n,r);return A(i)?i:O({shape:i.value,telemetry:XA(r)})}function rj(e,t,n,r,i){if(t.length===1)return O(Fk(t));i.batchAttempts++;let a=aj(()=>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 ij(e,rj(e,t.slice(0,o),n,r,i),rj(e,t.slice(o),n+o,r,i),t,n,o,r,i)}function ij(e,t,n,r,i,a,o,s){if(t.ok&&n.ok){s.singletonFallbacks++;let c=aj(()=>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 aj(e){try{return e()}catch{return null}}function oj(e,t,n){return U().checkBoolean(e.wrapped,t.wrapped,n)}function sj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function cj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function lj(e,t,n,r){let i=W(e);if(!wE(i)){let a=e.ShapeType(),o=[`COMPOUND`,`COMPSOLID`,`SOLID`,`SHELL`,`FACE`,`WIRE`,`EDGE`,`VERTEX`,`SHAPE`][a]??`UNKNOWN(${a})`;return i[Symbol.dispose](),k(co(t,`${n}. Got ${o} instead.`,void 0,void 0,r))}return O(i)}function uj(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 dj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=sj(e,`fuseWithEvolution: first operand`);if(A(o))return o;let s=sj(t,`fuseWithEvolution: second operand`);if(A(s))return s;let c=NO([e,t]),{shape:l,evolution:u}=U().fuseWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=lj(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?(PO(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function fj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=sj(e,`cutWithEvolution: base`);if(A(o))return o;let s=sj(t,`cutWithEvolution: tool`);if(A(s))return s;let c=NO([e,t]),{shape:l,evolution:u}=U().cutWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=lj(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?(PO(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function pj(e,t,{simplify:n=!1,signal:r,fuzzyValue:i}={}){if(r?.aborted)throw r.reason;let a=sj(e,`intersectWithEvolution: first operand`);if(A(a))return a;let o=sj(t,`intersectWithEvolution: second operand`);if(A(o))return o;let s=NO([e,t]),{shape:c,evolution:l}=U().intersectWithHistory(e.wrapped,t.wrapped,s,G,{simplify:n,fuzzyValue:i}),u=lj(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?(PO(l,[e,t],u.value),O({shape:u.value,evolution:l})):u}function mj(e,t,n){let r=cj(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??RE(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=uj(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=NO([e]),{shape:o,evolution:s}=U().filletWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return wE(c)?(PO(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 hj(e,t,n){let r=cj(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??RE(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=uj(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=NO([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return wE(c)?(PO(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 gj(e,t,n,r=.001){let i=cj(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=NO([e]),{shape:a,evolution:o}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,i,G,r),s=W(a);return wE(s)?(PO(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 _j(e,t,n){try{let r=W(U().positionOnCurve(e.wrapped,t.wrapped,n));return wE(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 vj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function yj(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 bj(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 xj(e,t,n,r,i){let a=W(t);return wE(a)?(PO(e,n,a),O(a)):k(P(r,i))}function Sj(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 Cj(e,t){let n=vj(e,`thicken: shape`);if(A(n))return n;try{let n=NO([e]),{shape:r,evolution:i}=U().thickenWithHistory(e.wrapped,t,n,G),a=W(r);return PO(i,[e],a),O(a)}catch(e){return k(P(`THICKEN_FAILED`,`Thicken operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function wj(e,t,n){let r=vj(e,`fillet: shape`);if(A(r))return r;let i=yj(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??RE(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=bj(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 Tj(e,t,n,{trackEvolution:r=!0}={}){let i=wj(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 wE(n)?O(n):k(P(N.FILLET_NOT_3D,`Fillet result is not a 3D shape`))}let n=NO([e]),{shape:i,evolution:s}=U().filletWithHistory(e.wrapped,t,o,n,G);return xj(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 Ej(e,t,n){let r=vj(e,`chamfer: shape`);if(A(r))return r;let i=yj(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??RE(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=bj(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=NO([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,i,G);return xj(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 Dj(e,t,n,r=.001,{trackEvolution:i=!0}={}){let a=vj(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 wE(i)?O(i):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}let a=NO([e]),{shape:o,evolution:s}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,a,G,r),c=W(o);return wE(c)?(PO(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 Oj(e,t,n=1e-6){let r=vj(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=NO([e]),{shape:i,evolution:a}=U().offsetWithHistory(e.wrapped,t,r,G,n),o=W(i);return wE(o)?(PO(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 kj(e,t,n){let r=vj(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 Aj(e,t,n,r,i){let a=kj(e,t,i);if(a)return a;try{let{filteredFaces:a,kernelAngle:o}=Sj(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=NO([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 xj(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 jj(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 wE(a)?SE(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 Mj(e){return tD(e)}function Nj(e){if(!SE(e))return k(F(`NOT_A_SOLID`,`Input shape is not a solid`));let t=Mj(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 SE(r)?(LE(r),Mj(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 Pj(e){if(!bE(e))return k(F(`NOT_A_FACE`,`Input shape is not a face`));try{let t=W(U().healFace(e.wrapped));return bE(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 Fj(e,t){if(!yE(e))return k(F(`NOT_A_WIRE`,`Input shape is not a wire`));try{let n=W(U().healWire(e.wrapped,t?.wrapped));return yE(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 Ij(e){return SE(e)?Nj(e):bE(e)?Pj(e):yE(e)?Fj(e):O(e)}function Lj(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(Mj(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=BE(e).length,u=zE(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=BE(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(SE(d)&&i||bE(d)&&r||yE(d)&&n){let t=Ij(d);Na(t)?(d=t.value,SE(e)?(f=!0,s.push(`Applied ShapeFix_Solid`),c.push({name:`healSolid`,attempted:!0,succeeded:!0})):bE(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=BE(d).length,m=zE(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 _=Mj(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 Rj(e){try{return O(W(U().fixShape(e.wrapped)))}catch(e){return k(P(N.FIX_SHAPE_FAILED,`ShapeFix_Shape failed`,e))}}function zj(e){try{let t=W(U().solidFromShell(e.wrapped));return SE(t)?Mj(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 Bj(e){try{let t=W(U().fixSelfIntersection(e.wrapped));return yE(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 Vj(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 Hj(e,t){let n=U(),r=n.makeLineEdge([...e],[...t]);return W(n.makeWire([r]))}function Uj(e,t,n,r,i,a=!1){return W(U().makeHelixWire(e,t,n,[...r],[...i],a))}function Wj(e,t,n={},r=!1){if(n.mode===`simple`&&!r){let n=W(U().simplePipe(e.wrapped,t.wrapped));return wE(n)?O(n):k(co(`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(!wE(e))return k(co(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`));let t=W(v.firstShape),n=W(v.lastShape);return yE(t)?yE(n)?O([e,t,n]):k(co(`SWEEP_END_NOT_WIRE`,`Sweep did not produce an end Wire`)):k(co(`SWEEP_START_NOT_WIRE`,`Sweep did not produce a start Wire`))}let y=W(v);return wE(y)?O(y):k(co(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`))}function Gj(e,t,n,r){return Wj(e,Hj(t,uD(t,n)),{support:r})}function Kj(e,t,n,r,i=!1){let a=gD(n);if(a<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let o=Hj(t,uD(t,n)),s=null;if(r){let e=Vj(a,r);if(A(e))return e;s=e.value}return Wj(e,o,{law:s},i)}function qj(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=gD(r);if(o<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let s=Hj(n,uD(n,r)),c=t<0,l=Uj(360/Math.abs(t)*o,o,1,n,r,c),u=null;if(i){let e=Vj(o,i);if(A(e))return e;u=e.value}return Wj(e,s,{auxiliarySpine:l,law:u},a)}function Jj(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 Yj(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 Xj(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=Jj(e);if(o)return k(o);try{let n=U(),o=Yj(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 wE(l)?O(l):k(co(`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 Zj(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 wE(u)?O(u):k(co(`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 Qj(e,t){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`extrude: face is a null shape`));if(gD(t)<1e-10)return k(F(`EXTRUDE_ZERO_VECTOR`,`extrude: extrusion vector has zero length`));try{let n=U(),r=gD(t),i=yD(t),a=n.extrude(e.wrapped,[...i],r);return O(mE(n.downcast(a,`solid`)))}catch(e){return k(P(`EXTRUDE_FAILED`,`Extrusion operation failed`,e,{operation:`extrude`,vectorLength:gD(t)}))}}function $j(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 wE(i)?O(i):k(co(`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 eM(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=gD(i);if(a<1e-10)return k(F(`EXTRUDE_ALL_ZERO_VECTOR`,`extrudeAll: entry ${t} has zero-length extrusion vector`));let o=[...yD(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=>mE(t.downcast(e,`solid`))))}catch(e){return k(P(`EXTRUDE_ALL_FAILED`,`Batch extrusion operation failed`,e))}}function tM(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(...oD(n)):void 0,c=r?o.makeVertex(...oD(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 wE(n)?O(n):k(co(`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 nM(e){if(e.length===0)return O([]);let t=U(),n=[],r=e.map(e=>{let r=e.startPoint?t.makeVertex(...oD(e.startPoint)):void 0,i=e.endPoint?t.makeVertex(...oD(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(!wE(e))return k(co(`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)}}function rM(e,t,n,r){let i=mE(U().makeBox(e,t,n)),a=r?.at??(r?.centered?[0,0,0]:void 0);return a?IO(i,[a[0]-e/2,a[1]-t/2,a[2]-n/2]):i}function iM(e,t,n){let r=n?.at??[0,0,0],i=n?.axis??[0,0,1],a=wA(e,t,r,i);if(n?.centered){let e=[-i[0]*t*.5,-i[1]*t*.5,-i[2]*t*.5];a=IO(a,e)}return a}function aM(e,t){let n=TA(e);return t?.at&&(n=IO(n,t.at)),n}function oM(e,t,n,r){let i=r?.at??[0,0,0],a=r?.axis??[0,0,1],o=EA(e,t,n,i,a);if(r?.centered){let e=[-a[0]*n*.5,-a[1]*n*.5,-a[2]*n*.5];o=IO(o,e)}return o}function sM(e,t,n){return DA(e,t,n?.at??[0,0,0],n?.axis??[0,0,1])}function cM(e,t,n,r){let i=OA(e,t,n);return r?.at&&(i=IO(i,r.at)),i}function lM(e,t){return zk(e,t)}function uM(e,t){let n=t?.axis??[0,0,1];return Bk(e,t?.at??[0,0,0],n)}function dM(e,t,n){let r=n?.axis??[0,0,1];return Vk(e,t,n?.at??[0,0,0],r,n?.xDir)}function fM(e,t,n,r){return Hk(e,t,n,r?.at??[0,0,0],r?.axis??[0,0,1],r?.lefthand??!1)}function pM(e,t,n){return Uk(e,t,n)}function mM(e,t,n,r,i){let a=i?.axis??[0,0,1];return Wk(e,t,n*iD,r*iD,i?.at??[0,0,0],a,i?.xDir)}function hM(e,t){return Gk(e,t)}function gM(e){return qk(e)}function _M(e,t,n){return Jk(e,t,n)}function vM(e){return Yk(e)}function yM(e){return Ia(Yk(e),e=>XT(e)?O(e):k(F(`WIRE_NOT_CLOSED`,`Assembled wire is not closed: start and end points do not coincide`)))}function bM(e,t){return Xk(e,t)}function xM(e){return $k(e)}function SM(e,t){return Qk(e,t)}function CM(e){return tA(e)}function wM(e){return kA(e)}function TM(e){return jA(e)}function EM(e){return MA(e)}function DM(e,t,n){return AA(e,t,n)}function OM(e,t){return CA(e,t)}function kM(e,t){return eA(e,t)}function AM(){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 jM(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??AM(),color:[a,o,s,c]}});return PT(U().createXCAFDocument(t))}function MM(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??AM(),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(po(`STEP_EXPORT_FAILED`,`Failed to write STEP file`))}finally{o.delete()}}function NM(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(xD(t))return k(F(`PATTERN_ZERO_DIRECTION`,`Pattern direction cannot be zero`));let a=yD(t);return cA(U().linearPattern(e.wrapped,[...a],r,n).map(e=>W(e)),{optimisation:`sameFace`,...i,unsafe:!0})}function PM(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(xD(t))return k(F(`PATTERN_ZERO_AXIS`,`Pattern axis cannot be zero`));let o=r/n;return cA(U().circularPattern(e.wrapped,[...i],[...t],o,n).map(e=>W(e)),{optimisation:`sameFace`,...a,unsafe:!0})}function FM(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 IM(e,t){return{...e,children:[...e.children,t]}}function LM(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 RM(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 zM(e,t){if(e.name===t)return e;for(let n of e.children){let e=zM(n,t);if(e)return e}}function BM(e,t,n=0){t(e,n);for(let r of e.children)BM(r,t,n+1)}function VM(e){let t=1;for(let n of e.children)t+=VM(n);return t}function HM(e){let t=[];return BM(e,e=>{e.shape&&t.push(e.shape)}),t}function UM(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function WM(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 GM(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function KM(e){return GM(WM(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function qM(e,t){let[n,r,i,a]=e,o=2*(i*t[2]-a*t[1]),s=2*(a*t[0]-r*t[2]),c=2*(r*t[1]-i*t[0]);return[t[0]+n*o+(i*c-a*s),t[1]+n*s+(a*o-r*c),t[2]+n*c+(r*s-i*o)]}function JM(e,t){let n=t/2,r=Math.sin(n),i=GM(e);return[Math.cos(n),i[0]*r,i[1]*r,i[2]*r]}function YM(e,t){let n=GM(e),r=GM(t),i=UM(n,r);if(i>=.999999999)return[1,0,0,0];if(i<=-.999999999)return JM(KM(n),Math.PI);let a=WM(n,r),o=Math.hypot(1+i,a[0],a[1],a[2])||1;return[(1+i)/o,a[0]/o,a[1]/o,a[2]/o]}function XM(e,t){let[n,r,i,a]=e,[o,s,c,l]=t;return[n*o-r*s-i*c-a*l,n*s+r*o+i*l-a*c,n*c-r*l+i*o+a*s,n*l+r*c-i*s+a*o]}var ZM=Math.PI/180;function QM(e,t,n){return Math.min(n,Math.max(t,e))}function $M(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function eN(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 tN(e){return $M(eN(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function nN(e,t,n,r,i){let a=n.min??r,o=n.max??i,s=Math.min(a,o),c=Math.max(a,o);return{kind:e,axis:$M(t),min:s,max:c,value:QM(n.value??0,s,c)}}function rN(e,t,n,r,i){let a=i[0]??{kind:`rotation`,axis:[0,0,1],min:0,max:0,value:0};return{type:e,parent:t,child:n,axis:{origin:r.origin,direction:$M(r.direction)},min:a.min,max:a.max,value:a.value,dofs:i}}function iN(e,t,n,r={}){return rN(`revolute`,e,t,n,[nN(`rotation`,n.direction,r,-180,180)])}function aN(e,t,n,r={}){return rN(`prismatic`,e,t,n,[nN(`translation`,n.direction,r,0,100)])}function oN(e,t,n,r={}){return rN(`cylindrical`,e,t,n,[nN(`rotation`,n.direction,r.rotation??{},-180,180),nN(`translation`,n.direction,r.translation??{},0,100)])}function sN(e,t,n,r={}){let i=$M(n.direction),a;if(r.uDirection){let e=r.uDirection,t=e[0]*i[0]+e[1]*i[1]+e[2]*i[2],n=[e[0]-t*i[0],e[1]-t*i[1],e[2]-t*i[2]];a=Math.hypot(n[0],n[1],n[2])<1e-9?tN(i):$M(n)}else a=tN(i);let o=$M(eN(i,a));return rN(`planar`,e,t,{origin:n.origin,direction:i},[nN(`translation`,a,r.u??{},-100,100),nN(`translation`,o,r.v??{},-100,100),nN(`rotation`,i,r.rotation??{},-180,180)])}function cN(e,t,n,r={}){return rN(`spherical`,e,t,{origin:n,direction:[0,0,1]},[nN(`rotation`,[1,0,0],r.x??{},-180,180),nN(`rotation`,[0,1,0],r.y??{},-180,180),nN(`rotation`,[0,0,1],r.z??{},-180,180)])}function lN(e,t){let n=e.dofs.map((e,n)=>{let r=t[n];return r===void 0?e:{...e,value:QM(r,e.min,e.max)}}),r=n[0];return r?{...e,dofs:n,value:r.value}:{...e,dofs:n}}function uN(e,t){return lN(e,[t])}function dN(e,t,n){if(t.kind===`translation`)return{position:[t.axis[0]*n,t.axis[1]*n,t.axis[2]*n],rotation:[1,0,0,0]};let r=JM(t.axis,n*ZM),i=qM(r,e);return{position:[e[0]-i[0],e[1]-i[1],e[2]-i[2]],rotation:r}}function fN(e,t=e.value){let n=Array.isArray(t)?t:void 0,r=n?void 0:t,i=e.axis.origin,a=mN;for(let t=0;t<e.dofs.length;t++){let o=e.dofs[t];if(!o)continue;let s=n?n[t]??o.value:t===0?r??o.value:o.value;a=hN(a,dN(i,o,QM(s,o.min,o.max)))}return a}function pN(e,t){let n=e.joints??[];return{...e,joints:[...n,t]}}var mN={position:[0,0,0],rotation:[1,0,0,0]};function hN(e,t){let n=qM(e.rotation,t.position);return{position:[e.position[0]+n[0],e.position[1]+n[1],e.position[2]+n[2]],rotation:XM(e.rotation,t.rotation)}}function gN(e){let t=[];return BM(e,e=>{e.joints&&t.push(...e.joints)}),t}function _N(e,t={}){let n=[],r=new Set;BM(e,e=>{r.add(e.name),e.joints&&n.push(...e.joints)});let i=new Map;for(let e of n)i.set(e.child,e),r.add(e.parent),r.add(e.child);let a=new Map;for(let e of r)i.has(e)||a.set(e,mN);let o=[...n],s=!0;for(;s&&o.length>0;){s=!1;for(let e=o.length-1;e>=0;e--){let n=o[e];if(!n)continue;let r=a.get(n.parent);if(!r||(o.splice(e,1),s=!0,a.has(n.child)))continue;let i=t[n.child]??n.value,c=n.offset?hN(fN(n,i),n.offset):fN(n,i);a.set(n.child,hN(r,c))}}for(let e of o)a.has(e.child)||a.set(e.child,mN);return a}function vN(e){return gN(e).reduce((e,t)=>e+t.dofs.length,0)}var yN={position:[0,0,0],rotation:[1,0,0,0]};function bN(e,t){let n=qM(e.rotation,t);return[n[0]+e.position[0],n[1]+e.position[1],n[2]+e.position[2]]}function xN(e){return[e[0],-e[1],-e[2],-e[3]]}function SN(e,t){let[n,r,i,a]=XM(t,xN(e)),o=Math.hypot(n,r,i,a)||1;n/=o,r/=o,i/=o,a/=o,n<0&&(n=-n,r=-r,i=-i,a=-a);let s=Math.hypot(r,i,a);if(s<1e-12)return[0,0,0];let c=2*Math.atan2(s,n)/s;return[r*c,i*c,a*c]}function CN(e,t){let n=[];BM(e,e=>{e.joints&&n.push(...e.joints)});let r=new Map;for(let e of n)r.set(e.child,e);let i=[],a=new Set,o=t;for(;o&&r.has(o)&&!a.has(o);){a.add(o);let e=r.get(o);if(!e)break;i.push(e),o=e.parent}return i.reverse()}function wN(e,t){return e[t]??0}function TN(e,t,n){let r=n+1,i=new Float64Array(n*r);for(let a=0;a<n;a++){for(let t=0;t<n;t++)i[a*r+t]=wN(e,a*n+t);i[a*r+n]=wN(t,a)}for(let e=0;e<n;e++){let t=e;for(let a=e+1;a<n;a++)Math.abs(wN(i,a*r+e))>Math.abs(wN(i,t*r+e))&&(t=a);if(Math.abs(wN(i,t*r+e))<1e-12)return null;if(t!==e)for(let n=e;n<r;n++){let a=wN(i,e*r+n);i[e*r+n]=wN(i,t*r+n),i[t*r+n]=a}let a=wN(i,e*r+e);for(let t=e;t<r;t++)i[e*r+t]=wN(i,e*r+t)/a;for(let t=0;t<n;t++){if(t===e)continue;let n=wN(i,t*r+e);if(n!==0)for(let a=e;a<r;a++)i[t*r+a]=wN(i,t*r+a)-n*wN(i,e*r+a)}}let a=new Float64Array(n);for(let e=0;e<n;e++)a[e]=wN(i,e*r+n);return a}function EN(e,t){let n=[],r=[],i=[],a=[];for(let o of e){let e=t?.[o.child];n.push({child:o.child,count:o.dofs.length}),o.dofs.forEach((t,n)=>{let o=(Array.isArray(e)?e[n]:n===0?e:void 0)??t.value;r.push(Math.min(t.max,Math.max(t.min,o))),i.push(t.min),a.push(t.max)})}return{segments:n,q:Float64Array.from(r),lo:Float64Array.from(i),hi:Float64Array.from(a)}}function DN(e,t){let n={},r=0;for(let i of e){let e=[];for(let n=0;n<i.count;n++)e.push(wN(t,r++));n[i.child]=e}return n}function ON(e,t,n,r,i){let a=bN(t,r);if(e[0]=n.position[0]-a[0],e[1]=n.position[1]-a[1],e[2]=n.position[2]-a[2],i===6&&n.rotation){let r=SN(t.rotation,n.rotation);e[3]=r[0],e[4]=r[1],e[5]=r[2]}let o=0;for(let t=0;t<i;t++)o+=wN(e,t)**2;return Math.sqrt(o)}function kN(e,t,n,r,i,a,o,s,c,l){let u=bN(o,s);for(let d=0;d<n;d++){let f=wN(t,d),p=f+c>wN(a,d)&&f-c>=wN(i,d)?-c:c;t[d]=f+p;let m=l(t);t[d]=f;let h=bN(m,s);if(e[d]=(h[0]-u[0])/p,e[n+d]=(h[1]-u[1])/p,e[2*n+d]=(h[2]-u[2])/p,r===6){let t=SN(o.rotation,m.rotation);e[3*n+d]=t[0]/p,e[4*n+d]=t[1]/p,e[5*n+d]=t[2]/p}}}function AN(e,t,n,r,i){let a=new Float64Array(r*r),o=i*i;for(let t=0;t<r;t++)for(let i=0;i<r;i++){let s=0;for(let r=0;r<n;r++)s+=wN(e,t*n+r)*wN(e,i*n+r);a[t*r+i]=s+(t===i?o:0)}let s=TN(a,t,r);if(!s)return null;let c=new Float64Array(n);for(let t=0;t<n;t++){let i=0;for(let a=0;a<r;a++)i+=wN(e,a*n+t)*wN(s,a);c[t]=i}return c}function jN(e,t,n,r={}){let i=r.maxIterations??200,a=r.tolerance??1e-5,o=r.damping??.05,s=r.tip??[0,0,0],c=n.rotation===void 0?3:6,{segments:l,q:u,lo:d,hi:f}=EN(CN(e,t),r.seed),p=u.length,m=n=>_N(e,DN(l,n)).get(t)??yN,h=new Float64Array(c),g=new Float64Array(c*p),_=m(u),v=ON(h,_,n,s,c),y=0;for(;y<i&&p>0&&v>a;y++){kN(g,u,p,c,d,f,_,s,1e-6,m);let e=AN(g,h,p,c,o);if(!e)break;for(let t=0;t<p;t++){let n=wN(u,t)+wN(e,t);u[t]=Math.min(wN(f,t),Math.max(wN(d,t),n))}_=m(u),v=ON(h,_,n,s,c)}return{values:DN(l,u),converged:v<=a,iterations:y,error:v}}function MN(e,t){return e.dofs.map((e,n)=>{let r=(Array.isArray(t)?t[n]:n===0?t:void 0)??e.value;return Math.min(e.max,Math.max(e.min,r))})}function NN(e,t,n,r){let i=[];BM(e,e=>{e.joints&&i.push(...e.joints)});let a=i.map(e=>({child:e.child,a:MN(e,t[e.child]),b:MN(e,n[e.child])})),o=Math.max(1,Math.floor(r)),s=[];for(let t=0;t<=o;t++){let n=t/o,r={};for(let e of a)r[e.child]=e.a.map((t,r)=>t+((e.b[r]??t)-t)*n);s.push({t:n,values:r,poses:_N(e,r)})}return s}var PN=Math.PI/180;function FN(e,t,n,r){let i=e*PN,a=r*PN,o=XM(JM([0,0,1],i),JM([1,0,0],a));return{position:[n*Math.cos(i),n*Math.sin(i),t],rotation:o}}function IN(e,t={}){let n=t.base??`base`,r=e.map((e,t)=>e.name??`link${t+1}`);return e.map((e,t)=>{let i=t===0?n:r[t-1]??`link${t}`,a=r[t]??`link${t+1}`,o=FN(e.theta,e.d,e.a,e.alpha),s={origin:[0,0,0],direction:[0,0,1]},c={...e.min===void 0?{}:{min:e.min},...e.max===void 0?{}:{max:e.max},...e.value===void 0?{}:{value:e.value}};return{...e.type===`prismatic`?aN(i,a,s,c):iN(i,a,s,c),offset:o}})}var LN=Math.PI/180,RN=180/Math.PI;function zN(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function BN(e){return String(e===0?0:e)}function VN(e){return`${BN(e[0])} ${BN(e[1])} ${BN(e[2])}`}function HN(e,t={}){let n=t.name??`robot`,r=t.effort??0,i=t.velocity??0,a=t.meshes??{},o=[],s=[];BM(e,e=>{o.push(e.name),e.joints&&s.push(...e.joints)});for(let e of s){if(e.type!==`revolute`&&e.type!==`prismatic`)return k(F(N.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' is '${e.type}'; URDF supports only revolute and prismatic joints`));if(e.offset)return k(F(N.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' carries a fixed offset (e.g. a DH link) that URDF cannot represent as a single joint`))}let c=[`<?xml version="1.0"?>`,`<robot name="${zN(n)}">`];for(let e of o){let t=a[e];t?c.push(` <link name="${zN(e)}">`,` <visual><geometry><mesh filename="${zN(t)}"/></geometry></visual>`,` </link>`):c.push(` <link name="${zN(e)}"/>`)}for(let e of s){let t=e.type===`revolute`,n=t?e.min*LN:e.min,a=t?e.max*LN:e.max,o=e.type===`prismatic`?[0,0,0]:e.axis.origin;c.push(` <joint name="${zN(`${e.parent}_to_${e.child}`)}" type="${e.type}">`,` <parent link="${zN(e.parent)}"/>`,` <child link="${zN(e.child)}"/>`,` <origin xyz="${VN(o)}" rpy="0 0 0"/>`,` <axis xyz="${VN(e.axis.direction)}"/>`,` <limit lower="${BN(n)}" upper="${BN(a)}" effort="${BN(r)}" velocity="${BN(i)}"/>`,` </joint>`)}return c.push(`</robot>`,``),O(c.join(`
|
|
16
|
-
`))}function UN(e,t){return RegExp(`\\b${t}\\s*=\\s*"([^"]*)"`).exec(e)?.[1]}function WN(e,t){if(!e)return t;let n=e.trim().split(/\s+/).map(Number);return[n[0]??0,n[1]??0,n[2]??0]}function GN(e,t){return qM(XM(XM(JM([0,0,1],t[2]),JM([0,1,0],t[1])),JM([1,0,0],t[0])),e)}function KN(e){let t=/<robot\b([^>]*)>/.exec(e);if(!t)return k(F(N.VALIDATION_FAILED,`importURDF: no <robot> element found`));let n=UN(t[1]??``,`name`)??`robot`,r=[],i=/<link\b([^>]*?)(?:\/>|>)/g;for(let t=i.exec(e);t;t=i.exec(e)){let e=UN(t[1]??``,`name`);e&&r.push(e)}let a=[],o=/<joint\b([^>]*)>([\s\S]*?)<\/joint>/g;for(let t=o.exec(e);t;t=o.exec(e)){let e=t[1]??``,n=t[2]??``,r=UN(e,`type`)??`fixed`;if(r===`fixed`||r===`floating`||r===`planar`)continue;let i=/<parent\b([^>]*?)\/?>/.exec(n),o=/<child\b([^>]*?)\/?>/.exec(n),s=UN(i?.[1]??``,`link`),c=UN(o?.[1]??``,`link`);if(!s||!c)return k(F(N.VALIDATION_FAILED,`importURDF: joint missing parent/child link (${UN(e,`name`)??`unnamed`})`));let l=/<origin\b([^>]*?)\/?>/.exec(n),u=/<axis\b([^>]*?)\/?>/.exec(n),d=/<limit\b([^>]*?)\/?>/.exec(n),f=WN(UN(l?.[1]??``,`xyz`),[0,0,0]),p=WN(UN(l?.[1]??``,`rpy`),[0,0,0]),m=GN(WN(UN(u?.[1]??``,`xyz`),[1,0,0]),p),h=Number(UN(d?.[1]??``,`lower`)??NaN),g=Number(UN(d?.[1]??``,`upper`)??NaN);if(r===`prismatic`){let e=Number.isFinite(h)&&Number.isFinite(g)?{min:h,max:g}:{};a.push(aN(s,c,{origin:f,direction:m},e))}else if(r===`revolute`||r===`continuous`){let e=r===`continuous`||!Number.isFinite(h)||!Number.isFinite(g)?{min:-180,max:180}:{min:h*RN,max:g*RN};a.push(iN(s,c,{origin:f,direction:m},e))}else return k(F(N.VALIDATION_FAILED,`importURDF: joint '${UN(e,`name`)??`unnamed`}' has unrecognized type '${r}'`))}return O({name:n,links:r,joints:a})}function qN(){return{steps:[],shapes:new Map}}function JN(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 YN(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 XN(e,t){return e.steps.find(e=>e.id===t)}function ZN(e,t){return e.shapes.get(t)}function QN(e){return e.steps.length}function $N(e,t){let n=e.steps.findIndex(e=>e.id===t);return n===-1?[]:e.steps.slice(n)}function eP(e,t,n){let r=new Map(e.shapes);return r.set(t,n),{...e,shapes:r}}function tP(){return{operations:new Map}}function nP(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function rP(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=eP(r,t,i));for(let n of e.steps){let e=t.operations.get(n.type);if(!e)return k(fo(`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(fo(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${n.id}`));i.push(t)}try{let t=e(i,n.parameters);r=JN(r,{id:n.id,type:n.type,parameters:n.parameters,inputIds:n.inputIds,outputId:n.outputId},t)}catch(e){return k(fo(`REPLAY_STEP_FAILED`,`Step ${n.id} (${n.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(r)}function iP(e,t,n){let r=e.steps.findIndex(e=>e.id===t);if(r===-1)return k(fo(`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(fo(`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(fo(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${r.id}`));o.push(t)}try{let e=i(o,r.parameters);a=JN(a,{id:r.id,type:r.type,parameters:r.parameters,inputIds:r.inputIds,outputId:r.outputId},e)}catch(e){return k(fo(`REPLAY_STEP_FAILED`,`Step ${r.id} (${r.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(a)}function aP(e,t,n,r){return e.steps.findIndex(e=>e.id===t)===-1?k(fo(`MODIFY_STEP_NOT_FOUND`,`Step not found: ${t}`)):iP({steps:e.steps.map(e=>e.id===t?{...e,parameters:n}:e),shapes:e.shapes},t,r)}function oP(e){let t={};for(let[n,r]of e.shapes){let e=JO(r);if(!e.ok)return k(fo(`SERIALIZE_SHAPE_FAILED`,`Failed to serialize shape "${n}": ${e.error.message}`));t[n]=e.value}return O({steps:e.steps,shapes:t})}function sP(e){let t=new Map;for(let[n,r]of Object.entries(e.shapes))try{let e=UD(r);if(!e.ok)return k(fo(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e.error.message}`));t.set(n,e.value)}catch(e){return k(fo(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e instanceof Error?e.message:String(e)}`))}return O({steps:e.steps,shapes:t})}function cP(e){try{var t=CT();let{radius:n,pitch:r,height:i,depth:a=.6*r,toothHalfWidth:o=.42*r,sectionsPerTurn:s=20,lefthand:c=!1,inward:l=!1}=e;if(!(n>0))return k(F(`THREAD_INVALID_RADIUS`,`radius must be > 0`));if(!(r>0))return k(F(`THREAD_INVALID_PITCH`,`pitch must be > 0`));if(!(i>0))return k(F(`THREAD_INVALID_HEIGHT`,`height must be > 0`));if(!(a>0))return k(F(`THREAD_INVALID_DEPTH`,`depth must be > 0`));if(s<3)return k(F(`THREAD_TOO_FEW_SECTIONS`,`sectionsPerTurn must be >= 3`));let u=i/r,d=Math.max(2,Math.round(u*s)),f=c?-1:1,p=l?-a:a,m=l?.3:-.3,h=o,g=t.u(new FT),_=[];for(let e=0;e<=d;e++){let t=f*e*2*Math.PI/s,i=r*Math.abs(t)/(2*Math.PI),a=n*Math.cos(t),o=n*Math.sin(t),c=Math.cos(t),l=Math.sin(t),u=(e,t)=>[a+e*c,o+e*l,i+t],d=u(m,-h),v=u(p,0),y=u(m,h),b=vM([g.register(lM(d,v)),g.register(lM(v,y)),g.register(lM(y,d))]);if(!Na(b))return b;_.push(g.register(b.value))}return tM(_,{ruled:!0})}catch(e){t.e=e}finally{t.d()}}var lP=new WeakMap;function uP(e,t){return lP.get(e)?.get(t)}function dP(e,t,n){let r=lP.get(e);r||(r=new Map,lP.set(e,r)),r.set(t,n)}function fP(e){return U().isNull(e.wrapped)}function pP(e){return k(F(N.NULL_SHAPE_INPUT,`${e}: shape is a null shape`))}function mP(e){let t=uP(e.wrapped,`volume`);if(t)return O(t);if(fP(e))return pP(`measureVolumeProps`);let n=U(),r=n.shapeType(e.wrapped);if(r!==`solid`&&r!==`compsolid`&&r!==`compound`){let t={mass:0,volume:0,centerOfMass:[0,0,0]};return dP(e.wrapped,`volume`,t),O(t)}let i=n.volume(e.wrapped),a=jE(()=>n.centerOfMass(e.wrapped),N.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!a.ok)return a;let o={mass:i,volume:i,centerOfMass:a.value};return dP(e.wrapped,`volume`,o),O(o)}function hP(e){let t=uP(e.wrapped,`surface`);if(t)return O(t);if(fP(e))return pP(`measureSurfaceProps`);let n=U(),r=n.area(e.wrapped),i=jE(()=>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 dP(e.wrapped,`surface`,a),O(a)}function gP(e){let t=uP(e.wrapped,`linear`);if(t)return O(t);if(fP(e))return pP(`measureLinearProps`);let n=U(),r=n.length(e.wrapped),i={mass:r,length:r,centerOfMass:n.linearCenterOfMass(e.wrapped)};return dP(e.wrapped,`linear`,i),O(i)}function _P(e){let t=mP(e);return t.ok?O(t.value.mass):t}function vP(e){let t=hP(e);return t.ok?O(t.value.mass):t}function yP(e){let t=gP(e);return t.ok?O(t.value.mass):t}function bP(e,t){return fP(e)||fP(t)?pP(`measureDistance`):O(U().distance(e.wrapped,t.wrapped).value)}function xP(e,t){if(fP(e)||fP(t))return pP(`measureDistanceProps`);let n=U().distance(e.wrapped,t.wrapped);return O({distance:n.value,point1:n.point1,point2:n.point2})}function SP(e){if(fP(e))return pP(`createDistanceQuery`);let t=U().createDistanceQuery(e.wrapped);return O({distanceTo(e){return fP(e)?pP(`createDistanceQuery.distanceTo`):O(t.distanceTo(e.wrapped).value)},dispose(){t.dispose()}})}function CP(e,t,n){if(fP(e))return pP(`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 wP(e){if(fP(e))return pP(`measureCurvatureAtMid`);let t=YD(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 TP=1e-9,EP=1e-8,DP=1e-6,OP=([e,t],[n,r],i=DP)=>Math.abs(e-n)<=i&&Math.abs(t-r)<=i,kP=([e,t],[n,r])=>[e+n,t+r],AP=([e,t],[n,r])=>[e-n,t-r],jP=([e,t],n)=>[e*n,t*n],MP=([e,t],[n,r]=[0,0])=>Math.sqrt((e-n)**2+(t-r)**2),NP=([e,t],[n,r]=[0,0])=>(e-n)**2+(t-r)**2;function PP([e,t],[n,r]){return e*r-t*n}var FP=([e,t],[n,r]=[0,0])=>Math.atan2(r*e-t*n,e*n+t*r),IP=([e,t],[n,r]=[0,0])=>Math.atan2(r-t,n-e),LP=(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 RP([e,t]){let n=Math.sqrt(e*e+t*t);return n<1e-12?[0,0]:[e/n,t/n]}var zP=(e,t)=>[Math.cos(t)*e,Math.sin(t)*e],BP=([e,t])=>[Math.sqrt(e*e+t*t),Math.atan2(t,e)],VP=([e,t])=>{let n=RP([e,t]);return n[0]===0&&n[1]===0&&M(`normalize2d`,`Cannot normalize zero-length vector`),n};function HP(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(mo(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found ${r===0?0:`2+`} element(s)`))}function UP(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 RE(t);case`face`:return zE(t);case`wire`:return BE(t);case`vertex`:return VE(t)}}let s=e=>{let n=o(e);return t.length===0?n.slice():n.filter(a)},c=()=>UP(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=YO(n),r=t.get(e);r?r.push(n):t.set(e,[n])}return i(e=>{let n=t.get(YO(e));return!!n&&n.some(t=>ZO(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=>HP(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 WP={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function GP(e){return typeof e==`string`?WP[e]??[0,0,1]:e}function KP(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 qP(e,t){let n=yD(GP(e));return e=>{let r=U(),[i,a]=r.curveParameters(e.wrapped),o=(i+a)/2,{tangent:s}=r.curveTangent(e.wrapped,o),c=yD(s),l=Math.acos(Math.min(1,Math.abs(mD(c,n))));return Math.abs(l-iD*t)<1e-6}}function JP(e){return UP(`edge`,e,JP,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(qP(e,t)),ofLength:(e,t=.001)=>n(n=>Math.abs(ak(n)-e)<t),ofCurveType:e=>n(t=>ek(t)===e),parallelTo:(t=`Z`)=>JP(e).inDirection(t,0),atDistance:(e,t=[0,0,0])=>n(KP(e,t,1e-6))}))}function YP(){return JP([])}function XP(e,t){let n=yD(GP(e));return e=>{let r=$D(e),i=Math.acos(Math.min(1,Math.abs(mD(yD(r),n))));return Math.abs(i-iD*t)<1e-6}}function ZP(e){return UP(`face`,e,ZP,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(XP(e,t)),parallelTo:(t=`Z`)=>ZP(e).inDirection(t,0),ofSurfaceType:e=>n(t=>{let n=GD(t);return Na(n)&&n.value===e}),ofArea:(e,t=.001)=>n(n=>{let r=vP(n);return Na(r)&&Math.abs(r.value-e)<t}),atDistance:(e,t=[0,0,0])=>n(KP(e,t,1e-6))}))}function QP(){return ZP([])}function $P(e){return UP(`wire`,e,$P,(e,t)=>({isClosed:()=>t(e=>sk(e)),isOpen:()=>t(e=>!sk(e)),ofEdgeCount:e=>t(t=>RE(t).length===e)}))}function eF(){return $P([])}function tF(e,t){return typeof e==`object`&&`_topoKind`in e?e.findUnique(t):typeof e!=`function`&&bE(e)?O(e):e(QP()).findUnique(t)}function nF(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`}function rF(e,t){let n=10**t,r=t<0?e:.01/n+e;return Math.round(r*n)/n}function iF(e){return Math.round(e*100)/100}function aF(e){return Math.round(e*1e5)/1e5}var oF=([e,t])=>`(${iF(e)},${iF(t)})`,sF=(e,t=1e-9)=>{let n=e;return Math.abs(e)<t&&(n=0),n.toFixed(-Math.log10(t))},cF=(e,t=1e-9)=>Array.from(new Map(e.map(([e,n])=>[`[${sF(e,t)},${sF(n,t)}]`,[e,n]])).values()),lF=class{_wrapped;_deleted=!1;constructor(e){this._wrapped=e??dT().createBoundingBox2d(),LT(this,this._wrapped)}get wrapped(){if(this._deleted)throw Error(`This object has been deleted`);return this._wrapped}delete(){this._deleted||(this._deleted=!0,RT(this._wrapped),typeof this._wrapped.delete==`function`&&this._wrapped.delete())}[Symbol.dispose](){this.delete()}get repr(){let[e,t]=this.bounds;return`${oF(e)} - ${oF(t)}`}get bounds(){let{xMin:e,yMin:t,xMax:n,yMax:r}=dT().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){dT().mergeBBox2d(this.wrapped,e.wrapped)}isOut(e){return dT().isBBox2dOut(this.wrapped,e.wrapped)}containsPoint(e){return!dT().isBBox2dOutPoint(this.wrapped,e[0],e[1])}};function uF(e){return new dF(U().deserializeCurve2d(e))}var dF=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`&<(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`&&(RT(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 lF(t),this._boundingBox}get repr(){return`${this.geomType} ${oF(this.firstPoint)} - ${oF(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,MP(e,this.firstPoint),MP(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 nF(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?OP(e,this.firstPoint,t)?O(this.firstParameter):OP(e,this.lastPoint,t)?O(this.lastParameter):k(fo(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n===void 0||r===void 0?k(fo(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n>t?k(fo(`POINT_NOT_ON_CURVE`,`Point ${oF(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=>nF(e)?j(this.parameter(e,r)):e);i=Array.from(new Map(i.map(e=>[rF(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))}},fF=(e,t=1e-4,n=`C0`,r=200)=>new dF(dT().approximateCurve2dAsBSpline(e.wrapped,t,n,r)),pF=e=>(e.geomType!==`BSPLINE_CURVE`&&M(`BSplineToBezier`,`You can only convert a Bspline`),dT().decomposeBSpline2dToBeziers(e.wrapped).map(e=>new dF(e)));function mF(e,t={tolerance:1e-4,continuity:`C0`,maxSegments:300}){let n=dT();return e.flatMap(e=>{let r=e.geomType;if(r===`ELLIPSE`||r===`CIRCLE`&&OP(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 mF(pF(r===`BSPLINE_CURVE`?e:fF(e,t.tolerance,t.continuity,t.maxSegments)),t)})}var hF=(e,t)=>{let n=new dF(U().makeLine2d(e[0],e[1],t[0],t[1]));return OP(n.firstPoint,e)||n.reverse(),n},gF=(e,t,n)=>{let r=new dF(U().makeArc2dThreePoints(e[0],e[1],t[0],t[1],n[0],n[1]));if(!OP(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new dF(e)}return r},_F=(e,t,n)=>{let r=new dF(U().makeArc2dTangent(e[0],e[1],t[0],t[1],n[0],n[1]));if(!OP(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new dF(e)}return r},vF=(e,t=[0,0])=>new dF(U().makeCircle2d(t[0],t[1],e,!0)),yF=(e,t,n=[1,0],r=[0,0],i=!0)=>new dF(U().makeEllipse2d(r[0],r[1],e,t,n[0],n[1],i)),bF=(e,t,n,r,i=[0,0],a,o=!0)=>new dF(U().makeEllipseArc2d(i[0],i[1],e,t,n,r,a[0],a[1],o)),xF=(e,t,n)=>{let r=[[e[0],e[1]],...t.map(e=>[e[0],e[1]]),[n[0],n[1]]];return new dF(U().makeBezier2d(r))};function SF(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 dF(U().makeBSpline2d(a,{tolerance:t,smoothing:n,degMax:r,degMin:i,continuity:`C2`})))}catch{return k(fo(`BSPLINE_2D_FAILED`,`B-spline approximation failed`))}}var CF=(e,t,n,r=!1)=>{let i=jP(kP(e,t),.5),a=MP(n,e)*(r?-1:1);return gF(e,kP(jP(VP(AP(i,n)),a),n),t)},wF=(e,n)=>{let r=dT(),i=e.geomType,[a,o]=n,s=`${aF(a)} ${aF(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 ${iF(e)} ${iF(r)} ${s}`}if(i===3){let[e,r]=t(n,1),[i,a]=t(n,2);return`C ${iF(e)} ${iF(r)} ${iF(i)} ${iF(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)*aD,u=l===360?`${aF(a)} ${aF(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)*aD,f=d===360?`${aF(a)} ${aF(o+1e-4)}`:s,p=180-c*aD;return`A ${aF(n)} ${aF(i)} ${aF(p)} ${Math.abs(d)>180?`1`:`0`} ${l?`1`:`0`} ${f}`}M(`adaptedCurveToPathElem`,`Unsupported curve type: ${i}`)},TF=e=>{let t=U(),n=t.createBoundingBox2d();return e.forEach(e=>{t.addCurveToBBox2d(n,e.wrapped,1e-6)}),new lF(n)};function EF(e,t){let n=U();return e.map(e=>uE(n.liftCurve2dToPlane(e.wrapped,[...t.origin],[...t.zDir],[...t.xDir])))}var DF=(e,t)=>{let n=U();return e.map(e=>uE(n.buildEdgeOnSurface(e.wrapped,t)))},OF=(e,t)=>{let n=U();return e.map(e=>t?new dF(n.transformCurve2dGeneral(e.wrapped,t)):e.clone())},kF=(e,t,n=[0,0])=>U().createAffinityGTrsf2d(n[0],n[1],-t[1],t[0],e),AF=e=>U().createTranslationGTrsf2d(e[0],e[1]),jF=(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]),MF=(e,t=[0,0])=>U().createRotationGTrsf2d(e,t[0],t[1]),NF=(e,t=[0,0])=>U().createScaleGTrsf2d(e,t[0],t[1]);function PF(e,t,n=`original`){let r=U(),i=r.extractSurfaceFromFace(t.wrapped),a=YD(t),o=null;if(n===`original`&&KD(t)!==`PLANE`){if(KD(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=kF(1/e.radius,[1,0])}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=DF(OF(e,o),i);return o&&o.delete(),O(s)}function FF(e,t){let n=U(),r=new dF(n.extractCurve2dFromEdge(e.wrapped,t.wrapped));return uk(e)===`backward`&&n.reverseCurve2d(r.wrapped),r}var IF=(e,t=1)=>`${e.bounds[0][0]-t} ${-e.bounds[1][1]-t} ${e.width+2*t} ${e.height+2*t}`,LF=(e,t,n=1)=>`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${IF(t,n)}" fill="none" stroke="black" stroke-width="0.6%" vector-effect="non-scaling-stroke">
|
|
15
|
+
npm install brepkit-wasm`)}function CT(){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 wT=Symbol;wT.dispose??=Symbol.for(`Symbol.dispose`),wT.asyncDispose??=Symbol.for(`Symbol.asyncDispose`);var TT=globalThis;TT.FinalizationRegistry||=(console.warn(`brepjs: FinalizationRegistry unavailable — garbage collection will not work`),class{register(e,t,n){}unregister(e){return!1}});var ET={liveHandles:0,peakHandles:0,gcCollected:0,scopeEnters:0,scopeExits:0};function DT(){return{...ET}}function OT(){ET.liveHandles=0,ET.peakHandles=0,ET.gcCollected=0,ET.scopeEnters=0,ET.scopeExits=0}function kT(){ET.liveHandles++,ET.liveHandles>ET.peakHandles&&(ET.peakHandles=ET.liveHandles)}function AT(){ET.liveHandles--}function jT(){ET.gcCollected++,ET.liveHandles--}var MT=new FinalizationRegistry(e=>{jT();try{e.delete()}catch{}});function NT(e){let t=!1,n=()=>{if(!t){t=!0,AT(),MT.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 kT(),MT.register(r,e,r),r}function PT(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,AT(),MT.unregister(n);try{e.delete()}catch{}}}};return kT(),MT.register(n,e,n),n}var FT=class{handles=[];constructor(){ET.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](){ET.scopeExits++;for(let e=this.handles.length-1;e>=0;e--)this.handles[e]?.();this.handles.length=0}};function IT(e){try{var t=CT();return e(t.u(new FT))}catch(e){t.e=e}finally{t.d()}}function LT(e,t){MT.register(e,t,t)}function RT(e){MT.unregister(e)}function zT(e){try{var t=CT();return e(t.u(new FT))}catch(e){t.e=e}finally{t.d()}}async function BT(e){try{var t=CT();return await e(t.u(new FT))}catch(e){t.e=e}finally{t.d()}}function VT(e){return!e.disposed}function HT(e){return e.__is2D!==!0}function UT(e){return e.__is2D===!0}function WT(e){if(!HT(e))throw Error(`Expected 3D shape, got 2D`);return e}function GT(e){if(!UT(e))throw Error(`Expected 2D shape, got 3D`);return e}var KT=new WeakMap;function qT(e,t){KT.set(e,t)}function JT(e,t){let n=KT.get(t);if(n!==void 0)return n;let r=e.shapeType(t);return KT.set(t,r),r}function YT(e){return JT(U(),e.wrapped)}function XT(e){return U().curveIsClosed(e.wrapped)}function ZT(e){return U().isValid(e.wrapped)}function QT(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 $T(e){return U().isValid(e.wrapped)}function eE(e){return XT(e)?O(e):k(`Wire is not closed: start and end points do not coincide`)}function tE(e){return ZT(e)?O(e):k(`Face orientation is inconsistent or face is invalid`)}function nE(e){return QT(e)?O(e):k(`Shell is not manifold: has free edges or is invalid`)}function rE(e){return $T(e)?O(e):k(`Solid failed BRepCheck validation`)}function iE(e){return U().surfaceType(e.wrapped)===`plane`}function aE(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 oE(e){return iE(e)?O(e):k(`Face is not planar: underlying surface is not a geometric plane`)}function sE(e){return aE(e)?O(e):k(`Wire is not planar: edges do not lie in a common plane`)}function cE(e,t){return t===`2D`&&(e.__is2D=!0),e}function lE(e,t){return cE(NT(e),t)}function uE(e,t){return cE(NT(e),t)}function dE(e,t){return cE(NT(e),t)}function fE(e,t){return cE(NT(e),t)}function pE(e){return cE(NT(e))}function mE(e){return cE(NT(e))}function hE(e){return cE(NT(e))}function gE(e,t){return cE(NT(e),t)}function _E(e){return YT(e)===`vertex`}function vE(e){return YT(e)===`edge`}function yE(e){return YT(e)===`wire`}function bE(e){return YT(e)===`face`}function xE(e){return YT(e)===`shell`}function SE(e){return YT(e)===`solid`}function CE(e){return YT(e)===`compound`}function wE(e){let t=YT(e);return t===`shell`||t===`solid`||t===`compsolid`?!0:t===`compound`?HT(e):!1}function TE(e){let t=YT(e);return t===`edge`||t===`wire`}function W(e,t){let n=U(),r=JT(n,e),i=n.downcast(e,r);return r===`vertex`?lE(i,t):r===`edge`?uE(i,t):r===`wire`?dE(i,t):r===`face`?fE(i,t):r===`shell`?pE(i):r===`solid`?mE(i):r===`compsolid`?hE(i):gE(i,t)}function EE(e){return W(e)}function DE(e,t,n){qT(e,t);let r=U().downcast(e,t);return t===`vertex`?lE(r,n):t===`edge`?uE(r,n):t===`wire`?dE(r,n):t===`face`?fE(r,n):t===`shell`?pE(r):t===`solid`?mE(r):t===`compsolid`?hE(r):gE(r,n)}function OE(e,t,n,r,i){let a={kind:e,code:t,message:n,cause:r};return i?{...a,suggestion:i}:a}var kE={KERNEL_OPERATION:(e,t,n,r)=>OE(`KERNEL_OPERATION`,e,t,n,r),VALIDATION:(e,t,n,r)=>OE(`VALIDATION`,e,t,n,r),TYPE_CAST:(e,t,n,r)=>OE(`TYPE_CAST`,e,t,n,r),SKETCHER_STATE:(e,t,n,r)=>OE(`SKETCHER_STATE`,e,t,n,r),MODULE_INIT:(e,t,n,r)=>OE(`MODULE_INIT`,e,t,n,r),COMPUTATION:(e,t,n,r)=>OE(`COMPUTATION`,e,t,n,r),IO:(e,t,n,r)=>OE(`IO`,e,t,n,r),QUERY:(e,t,n,r)=>OE(`QUERY`,e,t,n,r),UNSUPPORTED:(e,t,n,r)=>OE(`UNSUPPORTED`,e,t,n,r)};function AE(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`?oo(i):i,o=ao(t);return k(kE[r](t,`${n}: ${a}`,e,o))}}function jE(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`?oo(i):i,o=ao(t);return k(kE[r](t,`${n}: ${a}`,e,o))}}function ME(e,t,n,r=`KERNEL_OPERATION`){try{var i=CT();let a=i.u(new FT);return AE(()=>e(a),t,n,r)}catch(e){i.e=e}finally{i.d()}}function NE(e,t){let n=U().iterShapes(e,t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=DE(n[e],t);return r}var PE=new WeakMap;function FE(e){let t=PE.get(e.wrapped);return t||(t={},PE.set(e.wrapped,t)),t}function IE(e){return PE.get(e.wrapped)}function LE(e){PE.delete(e.wrapped)}function RE(e){let t=FE(e);if(t.edges)return t.edges;let n=NE(e.wrapped,`edge`);return t.edges=n,n}function zE(e){let t=FE(e);if(t.faces)return t.faces;let n=NE(e.wrapped,`face`);return t.faces=n,n}function BE(e){let t=FE(e);if(t.wires)return t.wires;let n=NE(e.wrapped,`wire`);return t.wires=n,n}function VE(e){let t=FE(e);if(t.vertices)return t.vertices;let n=NE(e.wrapped,`vertex`);return t.vertices=n,n}function HE(e){let t=FE(e);if(t.solids)return t.solids;let n=NE(e.wrapped,`solid`);return t.solids=n,n}function UE(e){let t=FE(e);if(t.shells)return t.shells;let n=NE(e.wrapped,`shell`);return t.shells=n,n}function WE(e){let t=FE(e);if(t.compSolids)return t.compSolids;let n=NE(e.wrapped,`compsolid`);return t.compSolids=n,n}function*GE(e){for(let t of U().iterShapes(e.wrapped,`edge`))yield DE(t,`edge`)}function*KE(e){for(let t of U().iterShapes(e.wrapped,`face`))yield DE(t,`face`)}function*qE(e){for(let t of U().iterShapes(e.wrapped,`wire`))yield DE(t,`wire`)}function*JE(e){for(let t of U().iterShapes(e.wrapped,`vertex`))yield DE(t,`vertex`)}function*YE(e){for(let t of U().iterShapes(e.wrapped,`solid`))yield DE(t,`solid`)}function*XE(e){for(let t of U().iterShapes(e.wrapped,`shell`))yield DE(t,`shell`)}function*ZE(e){for(let t of U().iterShapes(e.wrapped,`compsolid`))yield DE(t,`compsolid`)}function QE(e){let t=FE(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 $E(e){return JT(U(),e.wrapped)}function eD(e){let t=FE(e);if(t.surfaceType!==void 0)return t.surfaceType;let n=U().surfaceType(e.wrapped);return t.surfaceType=n,n}function tD(e){let t=FE(e);if(t.isValid!==void 0)return t.isValid;let n=U().isValid(e.wrapped);return t.isValid=n,n}function nD(e){return{kind:$E(e),faceCount:zE(e).length,edgeCount:RE(e).length,wireCount:BE(e).length,vertexCount:VE(e).length,valid:tD(e),bounds:QE(e)}}function rD(e){return U().vertexPosition(e.wrapped)}var G=2147483647,iD=Math.PI/180,aD=180/Math.PI;function oD(e){return e.length===2?[e[0],e[1],0]:[e[0],e[1],e[2]]}function sD(e){return[e[0],e[1]]}var cD={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function lD(e){if(typeof e==`string`){let t=cD[e];if(!t)throw Error(`Unknown direction: ${e}`);return t}return e}function uD(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function dD(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function fD(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function pD(e){return[-e[0],-e[1],-e[2]]}function mD(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function hD(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 gD(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function _D(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function vD(e,t){return gD(dD(e,t))}function yD(e){let t=gD(e);return t<1e-10?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function bD(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 xD(e,t=1e-10){return _D(e)<t*t}function SD(e,t){let n=mD(e,t),r=gD(e),i=gD(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 CD(e,t,n){let r=dD(e,t),i=_D(n);return i<1e-20?e:dD(e,fD(n,mD(r,n)/i))}function wD(e,t,n){let r=yD(t),i=Math.cos(n),a=Math.sin(n),o=mD(e,r),s=hD(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 TD=e=>Math.round(e*1e3)/1e3;function ED(e){return`x: ${TD(e[0])}, y: ${TD(e[1])}, z: ${TD(e[2])}`}function DD(e,t=null,n=[0,0,1]){let r=yD(n);if(xD(r))throw Error(`Plane normal must be non-zero`);let i;if(t)i=yD(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?yD([l,u,d]):[1,0,0]}if(xD(i))throw Error(`Plane xDir must be non-zero`);let a=yD(hD(r,i));return{origin:e,xDir:i,yDir:a,zDir:r}}var OD={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 kD(e,t=[0,0,0]){let n=OD[e];if(!n)return k(F(`UNKNOWN_PLANE`,`Could not find plane ${e}`));let r;return r=typeof t==`number`?fD(n.normal,t):oD(t),O(DD(r,n.xDir,n.normal))}function AD(e,t){return typeof e==`string`?kD(e,t):O(e)}function jD(e,t){return e&&typeof e!=`string`?{...e}:j(AD(e??`XY`,t))}function MD(e,t){let[n,r]=t;return uD(uD(e.origin,fD(e.xDir,n)),fD(e.yDir,r))}function ND(e,t){return{...e,origin:uD(e.origin,t)}}function PD(e,t,n=[1,0,0]){let r=t*iD,i=wD(e.zDir,n,r),a=wD(e.xDir,n,r),o=yD(hD(i,a));return{origin:e.origin,xDir:a,yDir:o,zDir:i}}var FD={compound:0,solidCompound:1,solid:2,shell:3,face:4,wire:5,edge:6,vertex:7,shape:8},ID=e=>FD[e],LD={vertex:`vertex`,edge:`edge`,wire:`wire`,face:`face`,shell:`shell`,solid:`solid`,solidCompound:`compsolid`,compound:`compound`,shape:`compound`},RD=function*(e,t){let n=LD[t];if(n){let t=U().iterShapes(e,n);for(let e of t)yield e}},zD=e=>U().isNull(e)?k(co(`NULL_SHAPE`,`This shape has no type, it is null`)):O(e.ShapeType());function BD(e){if(U().isNull(e))return k(co(`NULL_SHAPE`,`This shape has no type, it is null`));try{return O(U().downcast(e))}catch{return k(co(`NO_WRAPPER`,`Could not find a wrapper for this shape type`))}}function VD(e){return U().isNull(e)?k(co(`NULL_SHAPE`,`Cannot cast a null shape`)):O(W(e))}function HD(e){return U().shapeType(e.wrapped)===`compsolid`}function UD(e){return VD(U().fromBREP(e))}var WD={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 GD(e){return O(WD[eD(e)])}function KD(e){return j(GD(e))}function qD(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function JD(e){return W(U().reverseShape(e.wrapped))}function YD(e){return U().uvBounds(e.wrapped)}function XD(e,t,n){let r=YD(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 ZD(e,t){let n=oD(t);return U().uvFromPoint(e.wrapped,n)||[0,0]}function QD(e,t){let n=oD(t);try{let t=n,r=U().uvFromPoint(e.wrapped,t);if(!r)return k(co(`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(co(`PROJECTION_FAILED`,`Point projection failed: ${e instanceof Error?e.message:String(e)}`))}}function $D(e,t){let n,r;if(t)[n,r]=ZD(e,t);else{let t=YD(e);n=.5*(t.uMin+t.uMax),r=.5*(t.vMin+t.vMax)}return U().surfaceNormal(e.wrapped,n,r)}function eO(e){return U().surfaceCenterOfMass(e.wrapped)}function tO(e){return U().getSurfaceAxis(e.wrapped)}function nO(e,t,n=1e-6){let[r,i]=ZD(e,t);return U().classifyPointOnFace(e.wrapped,r,i,n)}function rO(e){return W(U().outerWire(e.wrapped))}function iO(e){return W(U().removeHolesFromFace(e.wrapped))}function aO(e){let t=rO(e);return Array.from(RD(e.wrapped,`wire`)).map(e=>W(j(BD(e)))).filter(e=>!U().isSame(e.wrapped,t.wrapped))}function oO(e,t){let n=FE(e),r=new Map;for(let n of zE(e))r.set(U().hashCode(n.wrapped,G),t);n.faceOrigins=r}function sO(e){return IE(e)?.faceOrigins}function cO(e,t,n){let r=new Map;for(let e of t){let t=sO(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=FE(n);e.faceOrigins=i}}function lO(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 uO(e,t){let n=new Map;for(let t of e){let e=sO(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=zE(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=sO(n);if(e)for(let i of zE(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=lO(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=FE(t);e.faceOrigins=i}}var dO=new WeakMap,fO=new WeakMap;function pO(e){return dO.has(e.wrapped)}function mO(e){let t=dO.get(e.wrapped);return t||(t=new Map,dO.set(e.wrapped,t)),t}function hO(e){let t=fO.get(e.wrapped);return t||(t=new Map,fO.set(e.wrapped,t)),t}function gO(e,t,n){let r=Array.isArray(t)?t:zE(e).filter(t),i=mO(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 _O(e,t){let n=dO.get(e.wrapped);if(!n)return[];let r=n.get(t);if(!r||r.size===0)return[];let i=[];for(let t of zE(e)){let e=U().hashCode(t.wrapped,G);r.has(e)&&i.push(t)}return i}function vO(e){let t=new Map,n=dO.get(e.wrapped);if(!n)return t;let r=zE(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 yO(e,t,n){return hO(e).set(t,n),e}function bO(e,t){return fO.get(e.wrapped)?.get(t)}function xO(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function SO(e,t,n){let r=mO(n);for(let i of t){let t=dO.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)xO(r,t,e)}let o=fO.get(i.wrapped);if(o){let e=hO(n);for(let[t,n]of o)e.has(t)||e.set(t,n)}}}var CO=new WeakMap,wO=new WeakMap;function TO(e){return CO.has(e.wrapped)||wO.has(e.wrapped)}function EO(e){let t=wO.get(e.wrapped);return t||(t=new Map,wO.set(e.wrapped,t)),t}function DO(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 OO(e,t){return CO.set(e.wrapped,DO(t)),e}function kO(e,t,n){let r=DO(n),i=EO(e);for(let e of t)i.set(U().hashCode(e.wrapped,G),r);return e}function AO(e){return CO.get(e.wrapped)}function jO(e,t){let n=wO.get(e.wrapped);if(n)return n.get(U().hashCode(t.wrapped,G))}function MO(e,t,n){for(let e of t){let t=CO.get(e.wrapped);if(t){CO.set(n.wrapped,t);break}}let r=EO(n);for(let n of t){let t=wO.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 NO(e){if(!e.some(e=>sO(e)!==void 0||pO(e)||TO(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 PO(e,t,n){cO(e,t,n),SO(e,t,n),MO(e,t,n)}function FO(e,t){uO(e,t)}function IO(e,t){let n=NO([e]),{shape:r,evolution:i}=U().translateWithHistory(e.wrapped,t[0],t[1],t[2],n,G),a=W(r);return PO(i,[e],a),a}function LO(e,t,n=[0,0,0],r=[0,0,1]){let i=NO([e]),{shape:a,evolution:o}=U().rotateWithHistory(e.wrapped,t*iD,i,G,r,n),s=W(a);return PO(o,[e],s),s}function RO(e,t=[0,1,0],n=[0,0,0]){let r=NO([e]),{shape:i,evolution:a}=U().mirrorWithHistory(e.wrapped,n,t,r,G),o=W(i);return PO(a,[e],o),o}function zO(e,t,n=[0,0,0]){let r=NO([e]),{shape:i,evolution:a}=U().scaleWithHistory(e.wrapped,n,t,r,G),o=W(i);return PO(a,[e],o),o}function BO(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(zO(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 VO(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 HO(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 UO(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 WO(e,t){let n=VO(t);if(!n.ok)return n;let{linear:r,translation:i}=n.value,a=HO(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(UO(r)){let t=NO([e]),{shape:n,evolution:a}=U().generalTransformWithHistory(e.wrapped,r,i,!0,t,G),o=W(n);return PO(a,[e],o),O(o)}let o=W(U().generalTransformNonOrthogonal(e.wrapped,r,i));return FO([e],o),O(o)}function GO(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 KO(e,t){let n=NO([e]),{shape:r,evolution:i}=U().applyComposedTransformWithHistory(e.wrapped,t.trsf,n,G),a=W(r);return PO(i,[e],a),a}function qO(e){return AE(()=>U().downcast(e.wrapped),N.CLONE_FAILED,`Failed to clone shape`)}function JO(e){return jE(()=>U().toBREP(e.wrapped),N.TO_BREP_FAILED,`Failed to serialize shape to BREP`)}function YO(e){return U().hashCode(e.wrapped,G)}function XO(e){return U().isNull(e.wrapped)}function ZO(e,t){return U().isSame(e.wrapped,t.wrapped)}function QO(e,t){return U().isEqual(e.wrapped,t.wrapped)}function $O(e){return AE(()=>U().simplify(e.wrapped),N.SIMPLIFY_FAILED,`Failed to simplify shape`)}function ek(e){return U().curveType(e.wrapped)}function tk(e){let[t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function nk(e){let[,t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function rk(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curvePointAtParam(e.wrapped,i)}function ik(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curveTangent(e.wrapped,i).tangent}function ak(e){return U().length(e.wrapped)}function ok(e){if(ek(e)!==`CIRCLE`)return null;let t=rk(e,0),n=rk(e,1/3),r=rk(e,2/3),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=o[0]*o[0]+o[1]*o[1]+o[2]*o[2];if(s<1e-18)return null;let c=i[0]*i[0]+i[1]*i[1]+i[2]*i[2],l=a[0]*a[0]+a[1]*a[1]+a[2]*a[2],u=[c*a[0]-l*i[0],c*a[1]-l*i[1],c*a[2]-l*i[2]],d=[u[1]*o[2]-u[2]*o[1],u[2]*o[0]-u[0]*o[2],u[0]*o[1]-u[1]*o[0]],f=1/(2*s),p=[t[0]+d[0]*f,t[1]+d[1]*f,t[2]+d[2]*f],m=Math.sqrt(s);return{origin:p,direction:[o[0]/m,o[1]/m,o[2]/m]}}function sk(e){return U().curveIsClosed(e.wrapped)}function ck(e){return U().curveIsPeriodic(e.wrapped)}function lk(e){return U().curvePeriod(e.wrapped)}function uk(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function dk(e){return W(U().reverseShape(e.wrapped))}function fk(e,t={}){if(e.length<2)return k(co(`INTERPOLATE_MIN_POINTS`,`Interpolation requires at least 2 points`));try{let n=W(U().interpolatePoints(e,t));return vE(n)?O(n):k(co(`INTERPOLATE_NOT_EDGE`,`Interpolation did not produce an edge`))}catch(e){return k(co(`INTERPOLATE_FAILED`,`Interpolation failed: ${e instanceof Error?e.message:String(e)}`))}}function pk(e,t={}){if(e.length<2)return k(co(`APPROXIMATE_MIN_POINTS`,`Approximation requires at least 2 points`));try{let n=W(U().approximatePoints(e,t));return vE(n)?O(n):k(co(`APPROXIMATE_NOT_EDGE`,`Approximation did not produce an edge`))}catch(e){return k(co(`APPROXIMATE_FAILED`,`Approximation failed: ${e instanceof Error?e.message:String(e)}`))}}function mk(e,t,n=`arc`){let r=W(U().offsetWire2D(e.wrapped,t,{arc:`arc`,intersection:`intersection`,tangent:`tangent`,chamfer:`intersection`}[n]));return yE(r)?O(r):(r[Symbol.dispose](),k(co(`OFFSET_NOT_WIRE`,`Offset did not produce a Wire`)))}function hk(e,t,n,r=!1){return`${e}:${t}:${n}:${r}`}function gk(e,t){return`edge:${e}:${t}`}var _k=new WeakMap,vk=new WeakMap;function yk(e,t){let n=_k.get(e);if(n)return n.get(t)}function bk(e,t,n){let r=_k.get(e);r||(r=new Map,_k.set(e,r)),r.set(t,n)}function xk(e,t){let n=vk.get(e);if(n)return n.get(t)}function Sk(e,t,n){let r=vk.get(e);r||(r=new Map,vk.set(e,r)),r.set(t,n)}function Ck(){_k=new WeakMap,vk=new WeakMap}function wk(){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 Tk(e,t={}){let n=yo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,skipNormals:a=!1,includeUVs:o=!1,cache:s=!0,signal:c}=t;c?.throwIfAborted();let l=hk(r,i,a,o);if(s){let t=yk(e.wrapped,l);if(t)return t}let u=U().mesh(e.wrapped,{tolerance:r,angularTolerance:i,skipNormals:a,includeUVs:o,...c?{signal:c}:{}}),d=sO(e),f={vertices:u.vertices,normals:u.normals,triangles:u.triangles,uvs:u.uvs,faceGroups:u.faceGroups.map(e=>({start:e.start,count:e.count,faceId:e.faceHash,origin:d?.get(e.faceHash)??0}))};return s&&bk(e.wrapped,l,f),f}function Ek(e,t={}){let n=yo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,cache:a=!0}=t,o=gk(r,i);if(a){let t=xk(e.wrapped,o);if(t)return t}let s=U().meshEdges(e.wrapped,r,i),c={lines:s.lines,edgeGroups:s.edgeGroups.map(e=>({start:e.start,count:e.count,edgeId:e.edgeHash}))};return a&&Sk(e.wrapped,o,c),c}function Dk(e,t){return e instanceof Error&&e.message.startsWith(`${t} export failed`)?fo(`${t}_EXPORT_FAILED`,`Failed to write ${t} file`,e):e instanceof WebAssembly.RuntimeError?fo(`${t}_EXPORT_CRASHED`,`${t} export crashed the kernel (${e.message}); the shape likely contains geometry the ${t} writer cannot serialize`,e):fo(`${t}_FILE_READ_ERROR`,`Failed to read exported ${t} file`,e)}function Ok(e){let t;try{t=HE(e)}catch{return``}if(t.length<=1)return``;let n=[];return t.forEach((e,t)=>{try{QE(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 kk(e,t){try{return QE(e),null}catch(n){if(n instanceof TypeError)throw n;return fo(`${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${Ok(e)}`,n)}}function Ak(e){let t=kk(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(Dk(e,`STEP`))}}function jk(e,t={}){let n=yo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,binary:a=!1}=t,o=kk(e,`STL`);if(o)return k(o);try{U().hasTriangulation(e.wrapped)||U().meshShape(e.wrapped,r,i);let t=U().exportSTL(e.wrapped,a,r,i);return O(new Blob([t],{type:`application/sla`}))}catch(e){return k(Dk(e,`STL`))}}function Mk(e){try{let t=U().exportIGES([e.wrapped]);return O(new Blob([t],{type:`application/iges`}))}catch(e){return k(fo(`IGES_EXPORT_FAILED`,`Failed to write IGES file`,e))}}function Nk(e,t){let n=t?.coarseTolerance??.5,r=t?.fineTolerance??.05,i=t?.angularTolerance??.5;return{coarse:Tk(e,{tolerance:n,angularTolerance:i}),fine:Tk(e,{tolerance:r,angularTolerance:i*.2})}}function Pk(e,t,n){if(t<0||t>=e.length)throw Error(n??`Index ${t} out of bounds (length ${e.length})`);return e[t]}function Fk(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[0]}function Ik(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[e.length-1]}function Lk(e){return Array.from(Array(e).keys())}function Rk(e){return Lk(Math.min(...e.map(e=>e.length))).map(t=>e.map(e=>e[t]))}function zk(e,t){return uE(U().makeLineEdge([...e],[...t]))}function Bk(e,t=[0,0,0],n=[0,0,1]){return uE(U().makeCircleEdge([...t],[...n],e))}function Vk(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(uE(U().makeEllipseEdge([...n],[...r],e,t,i?[...i]:void 0)))}function Hk(e,t,n,r=[0,0,0],i=[0,0,1],a=!1){return dE(U().makeHelixWire(e,t,n,[...r],[...i],a))}function Uk(e,t,n){return uE(U().makeArcEdge([...e],[...t],[...n]))}function Wk(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(uE(U().makeEllipseArc([...i],[...a],e,t,n,r,o?[...o]:void 0)))}function Gk(e,{tolerance:t=.001,smoothing:n=null,degMax:r=6,degMin:i=1}={}){try{let a=e.map(e=>[...e]);return O(uE(U().approximatePoints(a,{tolerance:t,degMin:i,degMax:r,smoothing:n})))}catch{return k(P(`BSPLINE_FAILED`,`B-spline approximation failed`))}}function Kk(e,{periodic:t=!1,tolerance:n=1e-7}={}){try{let r=e.map(e=>[...e]);return O(uE(U().interpolatePoints(r,{periodic:t,tolerance:n})))}catch{return k(P(`BSPLINE_INTERP_FAILED`,`B-spline interpolation failed`))}}function qk(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(uE(U().makeBezierEdge(t)))}function Jk(e,t,n){return uE(U().makeTangentArc([...e],[...t],[...n]))}function Yk(e){try{return O(dE(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 Xk(e,t){try{let n=U().makeFace(e.wrapped,!0);if(t&&t.length>0){let e=eA(fE(n),t);return iE(e)?O(e):k(F(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}let r=fE(n);return iE(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 Zk(e){return Xk(rO(e))}function Qk(e,t){return fE(U().makeFaceOnSurface(e.wrapped,t.wrapped))}function $k(e){try{return Ia(VD(U().makeNonPlanarFace(e.wrapped)),e=>bE(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 eA(e,t){return fE(U().addHolesInFace(e.wrapped,t.map(e=>e.wrapped)))}function tA(e){return e.length<3?k(F(`POLYGON_MIN_POINTS`,`You need at least 3 points to make a polygon`)):Ia(Yk(Rk([e,[...e.slice(1),e[0]]]).map(([e,t])=>zk(e,t))),e=>Xk(e))}function nA(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function rA(e,t,n,r,i){let a=W(e);if(!wE(a)){let o=e.ShapeType(),s=[`COMPOUND`,`COMPSOLID`,`SOLID`,`SHELL`,`FACE`,`WIRE`,`EDGE`,`VERTEX`,`SHAPE`][o]??`UNKNOWN(${o})`;return a[Symbol.dispose](),k(co(t,`${n}. Got ${s} instead.`,void 0,i?{diagnostics:i}:void 0,r))}return O(a)}function iA(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=nA(e,`fuse: first operand`);if(A(c))return c;let l=nA(t,`fuse: second operand`);if(A(l))return l;if(!s)return rA(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);let u=NO([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),rA(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=rA(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&&PO(f,[e,t],m.value),m}function aA(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=nA(e,`cut: base`);if(A(c))return c;let l=nA(t,`cut: tool`);if(A(l))return l;if(!s)return rA(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);let u=NO([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),rA(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=rA(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&&PO(f,[e,t],m.value),m}function oA(e,t,{simplify:n=!1,signal:r,fuzzyValue:i,unsafe:a,trackEvolution:o=!0}={}){if(r?.aborted)throw r.reason;let s=nA(e,`intersect: first operand`);if(A(s))return s;let c=nA(t,`intersect: second operand`);if(A(c))return c;if(!o)return rA(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);let l=NO([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),rA(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=rA(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&&PO(d,[e,t],p.value),p}function sA(e,t,n,r,i,a,o,s){if(o?.aborted)throw o.reason;let c=n-t;if(c===1)return O(Pk(e,t));if(c===2)return iA(Pk(e,t),Pk(e,t+1),{optimisation:r,simplify:!1,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}});let l=t+Math.ceil(c/2),u=sA(e,t,l,r,i,a,o,s);if(A(u))return u;let d=sA(e,l,n,r,i,a,o,s);return A(d)?d:iA(u.value,d.value,{optimisation:r,simplify:i,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}})}function cA(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(Fk(e));for(let t=0;t<e.length;t++){let n=nA(Pk(e,t),`fuseAll: shape at index ${t}`);if(A(n))return n}if(r===`native`){let o=rA(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&&FO(e,o.value),o}return sA(e,0,e.length,t,n,s,i,a)}function lA(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=nA(e,`cutAll: base`);if(A(c))return c;for(let e=0;e<t.length;e++){let n=nA(Pk(t,e),`cutAll: tool at index ${e}`);if(A(n))return n}let l=[e,...t],u=rA(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&&FO(l,u.value),u}function uA(e,t){let n=U(),r=fD(e.xDir,t),i=fD(e.yDir,t),a=fD(e.xDir,-t),o=fD(e.yDir,-t),s=e.origin,c=[...uD(uD(s,a),o)],l=[...uD(uD(s,r),o)],u=[...uD(uD(s,r),i)],d=[...uD(uD(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 dA(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=uA(typeof t==`string`?j(AD(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 fA(e){let t=U(),n=new Map,r=new Map;for(let i of e){let e=VE(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 pA(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 mA(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=pA(i,t,n);for(;o;)e===0?r.push(o.edge):r.unshift(o.edge),i=o.nextTip,o=pA(i,t,n)}return r}function hA(e){let t=U(),n=fA(e),r=new Set,i=[];for(let a of e){if(r.has(a))continue;let e=mA(a,n,r);try{let n=t.makeWire(e.map(e=>e.wrapped));i.push(W(n))}catch{}}return i}function gA(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 _A(e,t,n={}){let r=dA(e,t,n);if(!r.ok)return r;let i=BE(r.value);if(i.length===0){let e=RE(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(...hA(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=gA(i),o=Pk(i,a),s=i.filter((e,t)=>t!==a);return Xk(o,s.length>0?s:void 0)}function vA(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(Pk(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 yA(e,t,n={}){let r=[];for(let i of t){let t=dA(e,i,n);if(A(t))return t;r.push(t.value)}return O(r)}function bA(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 xA(e,t,n);if(o===null)return k(P(`BOOLEAN_PIPELINE_FAILED`,`Boolean pipeline returned null shape`));let s=W(o);return wE(s)?O(s):k(co(`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 xA(e,t,n){let r=e,i={...n?.optimisation?{optimisation:n.optimisation}:{},unsafe:!0};for(let e of t){let t=e.op===`fuse`?iA(r,e.tool,i):e.op===`cut`?aA(r,e.tool,i):oA(r,e.tool,i);if(A(t))return t;r=j(t)}return O(r)}function SA(e){return j(VD(j(BD(U().sew(e.map(e=>e.wrapped))))))}function CA(e,t=!1){let n=SA(e);return!t&&!xE(n)?k(co(`WELD_NOT_SHELL`,`Could not make a shell from faces and shells`)):O(n)}function wA(e,t,n=[0,0,0],r=[0,0,1]){return mE(U().makeCylinder(e,t,[...n],[...r]))}function TA(e){return mE(U().makeSphere(e))}function EA(e,t,n,r=[0,0,0],i=[0,0,1]){return mE(U().makeCone(e,t,n,[...r],[...i]))}function DA(e,t,n=[0,0,0],r=[0,0,1]){return mE(U().makeTorus(e,t,[...n],[...r]))}function OA(e,t,n){return mE(U().makeEllipsoid(e,t,n))}function kA(e){return lE(U().makeVertex(e[0],e[1],e[2]))}function AA(e,t,n=1e-6){return Ia(BD(U().offset(e.wrapped,t,n)),e=>Ia(VD(e),e=>wE(e)?O(e):k(co(`OFFSET_NOT_3D`,`Could not offset to a 3d shape`))))}function jA(e){return gE(U().makeCompound(e.map(e=>e.wrapped)))}function MA(e){let t=SA(e);return Ia(VD(U().solidFromShell(t.wrapped)),e=>SE(e)?O(e):k(co(`SOLID_BUILD_FAILED`,`Could not make a solid of faces and shells`)))}function NA(e){return{position:e.vertices,normal:e.normals,index:e.triangles}}function PA(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 FA(e){return{position:e.lines}}function IA(e,t){return{coarse:NA(e.coarse),fine:NA(e.fine),coarseDistance:t?.coarse??50,fineDistance:t?.fine??0}}function LA(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=BD(i);if(A(a))return a;let o=W(a.value);return wE(o)?O(o):(o[Symbol.dispose](),k(co(`CHAMFER_ANGLE_NOT_3D`,`chamferDistAngle did not produce a 3D shape`)))}function RA(e,t){return e.map(e=>DE(e,t))}function zA(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 RA(i,t)}function BA(e){let t=FE(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 VA(e,t){let n=U(),r=BA(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 RA(o,`face`)}function HA(e){return zA(e.wrapped,`edge`)}function UA(e){return zA(e.wrapped,`wire`)}function WA(e){return zA(e.wrapped,`vertex`)}function GA(e,t){let n=U(),r=BA(e),i=zA(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 RA(a,`face`)}function KA(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 RA(o,`edge`)}function qA(e){let t=U();return t.getNurbsCurveData?t.getNurbsCurveData(e.wrapped):null}function JA(e){let t=U();return t.getNurbsSurfaceData?t.getNurbsSurfaceData(e.wrapped):null}var YA={cut:aA,cutAll:lA,fuse:iA,fuseAll:cA};function XA(e){return{totalInputs:e.totalInputs,batchAttempts:e.batchAttempts,batchSucceeded:e.batchSucceeded,singletonFallbacks:e.singletonFallbacks,failedInputs:[...e.failedInputs].sort((e,t)=>e-t)}}function ZA(e,t,n={}){return QA(YA,e,t,n)}function QA(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=$A(e,t,n,0,r,i);return A(a)?a:O({shape:a.value,telemetry:XA(i)})}function $A(e,t,n,r,i,a){if(n.length===0)return O(t);if(n.length===1)return ej(e,t,n,r,i,a);a.batchAttempts++;let o=aj(()=>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=$A(e,t,n.slice(0,s),r,i,a);return c.ok?$A(e,c.value,n.slice(s),r+s,i,a):c}function ej(e,t,n,r,i,a){a.singletonFallbacks++;let o=Fk(n),s=aj(()=>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 tj(e,t={}){return nj(YA,e,t)}function nj(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=rj(e,t,0,n,r);return A(i)?i:O({shape:i.value,telemetry:XA(r)})}function rj(e,t,n,r,i){if(t.length===1)return O(Fk(t));i.batchAttempts++;let a=aj(()=>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 ij(e,rj(e,t.slice(0,o),n,r,i),rj(e,t.slice(o),n+o,r,i),t,n,o,r,i)}function ij(e,t,n,r,i,a,o,s){if(t.ok&&n.ok){s.singletonFallbacks++;let c=aj(()=>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 aj(e){try{return e()}catch{return null}}function oj(e,t,n){return U().checkBoolean(e.wrapped,t.wrapped,n)}function sj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function cj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function lj(e,t,n,r){let i=W(e);if(!wE(i)){let a=e.ShapeType(),o=[`COMPOUND`,`COMPSOLID`,`SOLID`,`SHELL`,`FACE`,`WIRE`,`EDGE`,`VERTEX`,`SHAPE`][a]??`UNKNOWN(${a})`;return i[Symbol.dispose](),k(co(t,`${n}. Got ${o} instead.`,void 0,void 0,r))}return O(i)}function uj(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 dj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=sj(e,`fuseWithEvolution: first operand`);if(A(o))return o;let s=sj(t,`fuseWithEvolution: second operand`);if(A(s))return s;let c=NO([e,t]),{shape:l,evolution:u}=U().fuseWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=lj(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?(PO(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function fj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=sj(e,`cutWithEvolution: base`);if(A(o))return o;let s=sj(t,`cutWithEvolution: tool`);if(A(s))return s;let c=NO([e,t]),{shape:l,evolution:u}=U().cutWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=lj(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?(PO(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function pj(e,t,{simplify:n=!1,signal:r,fuzzyValue:i}={}){if(r?.aborted)throw r.reason;let a=sj(e,`intersectWithEvolution: first operand`);if(A(a))return a;let o=sj(t,`intersectWithEvolution: second operand`);if(A(o))return o;let s=NO([e,t]),{shape:c,evolution:l}=U().intersectWithHistory(e.wrapped,t.wrapped,s,G,{simplify:n,fuzzyValue:i}),u=lj(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?(PO(l,[e,t],u.value),O({shape:u.value,evolution:l})):u}function mj(e,t,n){let r=cj(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??RE(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=uj(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=NO([e]),{shape:o,evolution:s}=U().filletWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return wE(c)?(PO(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 hj(e,t,n){let r=cj(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??RE(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=uj(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=NO([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return wE(c)?(PO(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 gj(e,t,n,r=.001){let i=cj(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=NO([e]),{shape:a,evolution:o}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,i,G,r),s=W(a);return wE(s)?(PO(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 _j(e,t,n){try{let r=W(U().positionOnCurve(e.wrapped,t.wrapped,n));return wE(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 vj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function yj(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 bj(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 xj(e,t,n,r,i){let a=W(t);return wE(a)?(PO(e,n,a),O(a)):k(P(r,i))}function Sj(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 Cj(e,t){let n=vj(e,`thicken: shape`);if(A(n))return n;try{let n=NO([e]),{shape:r,evolution:i}=U().thickenWithHistory(e.wrapped,t,n,G),a=W(r);return PO(i,[e],a),O(a)}catch(e){return k(P(`THICKEN_FAILED`,`Thicken operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function wj(e,t,n){let r=vj(e,`fillet: shape`);if(A(r))return r;let i=yj(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??RE(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=bj(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 Tj(e,t,n,{trackEvolution:r=!0}={}){let i=wj(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 wE(n)?O(n):k(P(N.FILLET_NOT_3D,`Fillet result is not a 3D shape`))}let n=NO([e]),{shape:i,evolution:s}=U().filletWithHistory(e.wrapped,t,o,n,G);return xj(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 Ej(e,t,n){let r=vj(e,`chamfer: shape`);if(A(r))return r;let i=yj(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??RE(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=bj(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=NO([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,i,G);return xj(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 Dj(e,t,n,r=.001,{trackEvolution:i=!0}={}){let a=vj(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 wE(i)?O(i):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}let a=NO([e]),{shape:o,evolution:s}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,a,G,r),c=W(o);return wE(c)?(PO(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 Oj(e,t,n=1e-6){let r=vj(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=NO([e]),{shape:i,evolution:a}=U().offsetWithHistory(e.wrapped,t,r,G,n),o=W(i);return wE(o)?(PO(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 kj(e,t,n){let r=vj(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 Aj(e,t,n,r,i){let a=kj(e,t,i);if(a)return a;try{let{filteredFaces:a,kernelAngle:o}=Sj(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=NO([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 xj(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 jj(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 wE(a)?SE(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 Mj(e){return tD(e)}function Nj(e){if(!SE(e))return k(F(`NOT_A_SOLID`,`Input shape is not a solid`));let t=Mj(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 SE(r)?(LE(r),Mj(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 Pj(e){if(!bE(e))return k(F(`NOT_A_FACE`,`Input shape is not a face`));try{let t=W(U().healFace(e.wrapped));return bE(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 Fj(e,t){if(!yE(e))return k(F(`NOT_A_WIRE`,`Input shape is not a wire`));try{let n=W(U().healWire(e.wrapped,t?.wrapped));return yE(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 Ij(e){return SE(e)?Nj(e):bE(e)?Pj(e):yE(e)?Fj(e):O(e)}function Lj(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(Mj(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=BE(e).length,u=zE(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=BE(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(SE(d)&&i||bE(d)&&r||yE(d)&&n){let t=Ij(d);Na(t)?(d=t.value,SE(e)?(f=!0,s.push(`Applied ShapeFix_Solid`),c.push({name:`healSolid`,attempted:!0,succeeded:!0})):bE(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=BE(d).length,m=zE(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 _=Mj(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 Rj(e){try{return O(W(U().fixShape(e.wrapped)))}catch(e){return k(P(N.FIX_SHAPE_FAILED,`ShapeFix_Shape failed`,e))}}function zj(e){try{let t=W(U().solidFromShell(e.wrapped));return SE(t)?Mj(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 Bj(e){try{let t=W(U().fixSelfIntersection(e.wrapped));return yE(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 Vj(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 Hj(e,t){let n=U(),r=n.makeLineEdge([...e],[...t]);return W(n.makeWire([r]))}function Uj(e,t,n,r,i,a=!1){return W(U().makeHelixWire(e,t,n,[...r],[...i],a))}function Wj(e,t,n={},r=!1){if(n.mode===`simple`&&!r){let n=W(U().simplePipe(e.wrapped,t.wrapped));return wE(n)?O(n):k(co(`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(!wE(e))return k(co(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`));let t=W(v.firstShape),n=W(v.lastShape);return yE(t)?yE(n)?O([e,t,n]):k(co(`SWEEP_END_NOT_WIRE`,`Sweep did not produce an end Wire`)):k(co(`SWEEP_START_NOT_WIRE`,`Sweep did not produce a start Wire`))}let y=W(v);return wE(y)?O(y):k(co(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`))}function Gj(e,t,n,r){return Wj(e,Hj(t,uD(t,n)),{support:r})}function Kj(e,t,n,r,i=!1){let a=gD(n);if(a<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let o=Hj(t,uD(t,n)),s=null;if(r){let e=Vj(a,r);if(A(e))return e;s=e.value}return Wj(e,o,{law:s},i)}function qj(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=gD(r);if(o<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let s=Hj(n,uD(n,r)),c=t<0,l=Uj(360/Math.abs(t)*o,o,1,n,r,c),u=null;if(i){let e=Vj(o,i);if(A(e))return e;u=e.value}return Wj(e,s,{auxiliarySpine:l,law:u},a)}function Jj(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 Yj(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 Xj(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=Jj(e);if(o)return k(o);try{let n=U(),o=Yj(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 wE(l)?O(l):k(co(`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 Zj(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 wE(u)?O(u):k(co(`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 Qj(e,t){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`extrude: face is a null shape`));if(gD(t)<1e-10)return k(F(`EXTRUDE_ZERO_VECTOR`,`extrude: extrusion vector has zero length`));try{let n=U(),r=gD(t),i=yD(t),a=n.extrude(e.wrapped,[...i],r);return O(mE(n.downcast(a,`solid`)))}catch(e){return k(P(`EXTRUDE_FAILED`,`Extrusion operation failed`,e,{operation:`extrude`,vectorLength:gD(t)}))}}function $j(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 wE(i)?O(i):k(co(`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 eM(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=gD(i);if(a<1e-10)return k(F(`EXTRUDE_ALL_ZERO_VECTOR`,`extrudeAll: entry ${t} has zero-length extrusion vector`));let o=[...yD(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=>mE(t.downcast(e,`solid`))))}catch(e){return k(P(`EXTRUDE_ALL_FAILED`,`Batch extrusion operation failed`,e))}}function tM(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(...oD(n)):void 0,c=r?o.makeVertex(...oD(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 wE(n)?O(n):k(co(`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 nM(e){if(e.length===0)return O([]);let t=U(),n=[],r=e.map(e=>{let r=e.startPoint?t.makeVertex(...oD(e.startPoint)):void 0,i=e.endPoint?t.makeVertex(...oD(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(!wE(e))return k(co(`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)}}function rM(e,t,n,r){let i=mE(U().makeBox(e,t,n)),a=r?.at??(r?.centered?[0,0,0]:void 0);return a?IO(i,[a[0]-e/2,a[1]-t/2,a[2]-n/2]):i}function iM(e,t,n){let r=n?.at??[0,0,0],i=n?.axis??[0,0,1],a=wA(e,t,r,i);if(n?.centered){let e=[-i[0]*t*.5,-i[1]*t*.5,-i[2]*t*.5];a=IO(a,e)}return a}function aM(e,t){let n=TA(e);return t?.at&&(n=IO(n,t.at)),n}function oM(e,t,n,r){let i=r?.at??[0,0,0],a=r?.axis??[0,0,1],o=EA(e,t,n,i,a);if(r?.centered){let e=[-a[0]*n*.5,-a[1]*n*.5,-a[2]*n*.5];o=IO(o,e)}return o}function sM(e,t,n){return DA(e,t,n?.at??[0,0,0],n?.axis??[0,0,1])}function cM(e,t,n,r){let i=OA(e,t,n);return r?.at&&(i=IO(i,r.at)),i}function lM(e,t){return zk(e,t)}function uM(e,t){let n=t?.axis??[0,0,1];return Bk(e,t?.at??[0,0,0],n)}function dM(e,t,n){let r=n?.axis??[0,0,1];return Vk(e,t,n?.at??[0,0,0],r,n?.xDir)}function fM(e,t,n,r){return Hk(e,t,n,r?.at??[0,0,0],r?.axis??[0,0,1],r?.lefthand??!1)}function pM(e,t,n){return Uk(e,t,n)}function mM(e,t,n,r,i){let a=i?.axis??[0,0,1];return Wk(e,t,n*iD,r*iD,i?.at??[0,0,0],a,i?.xDir)}function hM(e,t){return Gk(e,t)}function gM(e){return qk(e)}function _M(e,t,n){return Jk(e,t,n)}function vM(e){return Yk(e)}function yM(e){return Ia(Yk(e),e=>XT(e)?O(e):k(F(`WIRE_NOT_CLOSED`,`Assembled wire is not closed: start and end points do not coincide`)))}function bM(e,t){return Xk(e,t)}function xM(e){return $k(e)}function SM(e,t){return Qk(e,t)}function CM(e){return tA(e)}function wM(e){return kA(e)}function TM(e){return jA(e)}function EM(e){return MA(e)}function DM(e,t,n){return AA(e,t,n)}function OM(e,t){return CA(e,t)}function kM(e,t){return eA(e,t)}function AM(){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 jM(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??AM(),color:[a,o,s,c]}});return PT(U().createXCAFDocument(t))}function MM(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??AM(),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(fo(`STEP_EXPORT_FAILED`,`Failed to write STEP file`))}finally{o.delete()}}function NM(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(xD(t))return k(F(`PATTERN_ZERO_DIRECTION`,`Pattern direction cannot be zero`));let a=yD(t);return cA(U().linearPattern(e.wrapped,[...a],r,n).map(e=>W(e)),{optimisation:`sameFace`,...i,unsafe:!0})}function PM(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(xD(t))return k(F(`PATTERN_ZERO_AXIS`,`Pattern axis cannot be zero`));let o=r/n;return cA(U().circularPattern(e.wrapped,[...i],[...t],o,n).map(e=>W(e)),{optimisation:`sameFace`,...a,unsafe:!0})}function FM(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 IM(e,t){return{...e,children:[...e.children,t]}}function LM(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 RM(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 zM(e,t){if(e.name===t)return e;for(let n of e.children){let e=zM(n,t);if(e)return e}}function BM(e,t,n=0){t(e,n);for(let r of e.children)BM(r,t,n+1)}function VM(e){let t=1;for(let n of e.children)t+=VM(n);return t}function HM(e){let t=[];return BM(e,e=>{e.shape&&t.push(e.shape)}),t}function UM(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function WM(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 GM(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function KM(e){return GM(WM(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function qM(e,t){let[n,r,i,a]=e,o=2*(i*t[2]-a*t[1]),s=2*(a*t[0]-r*t[2]),c=2*(r*t[1]-i*t[0]);return[t[0]+n*o+(i*c-a*s),t[1]+n*s+(a*o-r*c),t[2]+n*c+(r*s-i*o)]}function JM(e,t){let n=t/2,r=Math.sin(n),i=GM(e);return[Math.cos(n),i[0]*r,i[1]*r,i[2]*r]}function YM(e,t){let n=GM(e),r=GM(t),i=UM(n,r);if(i>=.999999999)return[1,0,0,0];if(i<=-.999999999)return JM(KM(n),Math.PI);let a=WM(n,r),o=Math.hypot(1+i,a[0],a[1],a[2])||1;return[(1+i)/o,a[0]/o,a[1]/o,a[2]/o]}function XM(e,t){let[n,r,i,a]=e,[o,s,c,l]=t;return[n*o-r*s-i*c-a*l,n*s+r*o+i*l-a*c,n*c-r*l+i*o+a*s,n*l+r*c-i*s+a*o]}var ZM=Math.PI/180;function QM(e,t,n){return Math.min(n,Math.max(t,e))}function $M(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function eN(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 tN(e){return $M(eN(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function nN(e,t,n,r,i){let a=n.min??r,o=n.max??i,s=Math.min(a,o),c=Math.max(a,o);return{kind:e,axis:$M(t),min:s,max:c,value:QM(n.value??0,s,c)}}function rN(e,t,n,r,i){let a=i[0]??{kind:`rotation`,axis:[0,0,1],min:0,max:0,value:0};return{type:e,parent:t,child:n,axis:{origin:r.origin,direction:$M(r.direction)},min:a.min,max:a.max,value:a.value,dofs:i}}function iN(e,t,n,r={}){return rN(`revolute`,e,t,n,[nN(`rotation`,n.direction,r,-180,180)])}function aN(e,t,n,r={}){return rN(`prismatic`,e,t,n,[nN(`translation`,n.direction,r,0,100)])}function oN(e,t,n,r={}){return rN(`cylindrical`,e,t,n,[nN(`rotation`,n.direction,r.rotation??{},-180,180),nN(`translation`,n.direction,r.translation??{},0,100)])}function sN(e,t,n,r={}){let i=$M(n.direction),a;if(r.uDirection){let e=r.uDirection,t=e[0]*i[0]+e[1]*i[1]+e[2]*i[2],n=[e[0]-t*i[0],e[1]-t*i[1],e[2]-t*i[2]];a=Math.hypot(n[0],n[1],n[2])<1e-9?tN(i):$M(n)}else a=tN(i);let o=$M(eN(i,a));return rN(`planar`,e,t,{origin:n.origin,direction:i},[nN(`translation`,a,r.u??{},-100,100),nN(`translation`,o,r.v??{},-100,100),nN(`rotation`,i,r.rotation??{},-180,180)])}function cN(e,t,n,r={}){return rN(`spherical`,e,t,{origin:n,direction:[0,0,1]},[nN(`rotation`,[1,0,0],r.x??{},-180,180),nN(`rotation`,[0,1,0],r.y??{},-180,180),nN(`rotation`,[0,0,1],r.z??{},-180,180)])}function lN(e,t){let n=e.dofs.map((e,n)=>{let r=t[n];return r===void 0?e:{...e,value:QM(r,e.min,e.max)}}),r=n[0];return r?{...e,dofs:n,value:r.value}:{...e,dofs:n}}function uN(e,t){return lN(e,[t])}function dN(e,t,n){if(t.kind===`translation`)return{position:[t.axis[0]*n,t.axis[1]*n,t.axis[2]*n],rotation:[1,0,0,0]};let r=JM(t.axis,n*ZM),i=qM(r,e);return{position:[e[0]-i[0],e[1]-i[1],e[2]-i[2]],rotation:r}}function fN(e,t=e.value){let n=Array.isArray(t)?t:void 0,r=n?void 0:t,i=e.axis.origin,a=mN;for(let t=0;t<e.dofs.length;t++){let o=e.dofs[t];if(!o)continue;let s=n?n[t]??o.value:t===0?r??o.value:o.value;a=hN(a,dN(i,o,QM(s,o.min,o.max)))}return a}function pN(e,t){let n=e.joints??[];return{...e,joints:[...n,t]}}var mN={position:[0,0,0],rotation:[1,0,0,0]};function hN(e,t){let n=qM(e.rotation,t.position);return{position:[e.position[0]+n[0],e.position[1]+n[1],e.position[2]+n[2]],rotation:XM(e.rotation,t.rotation)}}function gN(e){let t=[];return BM(e,e=>{e.joints&&t.push(...e.joints)}),t}function _N(e,t={}){let n=[],r=new Set;BM(e,e=>{r.add(e.name),e.joints&&n.push(...e.joints)});let i=new Map;for(let e of n)i.set(e.child,e),r.add(e.parent),r.add(e.child);let a=new Map;for(let e of r)i.has(e)||a.set(e,mN);let o=[...n],s=!0;for(;s&&o.length>0;){s=!1;for(let e=o.length-1;e>=0;e--){let n=o[e];if(!n)continue;let r=a.get(n.parent);if(!r||(o.splice(e,1),s=!0,a.has(n.child)))continue;let i=t[n.child]??n.value,c=n.offset?hN(fN(n,i),n.offset):fN(n,i);a.set(n.child,hN(r,c))}}for(let e of o)a.has(e.child)||a.set(e.child,mN);return a}function vN(e){return gN(e).reduce((e,t)=>e+t.dofs.length,0)}var yN={position:[0,0,0],rotation:[1,0,0,0]};function bN(e,t){let n=qM(e.rotation,t);return[n[0]+e.position[0],n[1]+e.position[1],n[2]+e.position[2]]}function xN(e){return[e[0],-e[1],-e[2],-e[3]]}function SN(e,t){let[n,r,i,a]=XM(t,xN(e)),o=Math.hypot(n,r,i,a)||1;n/=o,r/=o,i/=o,a/=o,n<0&&(n=-n,r=-r,i=-i,a=-a);let s=Math.hypot(r,i,a);if(s<1e-12)return[0,0,0];let c=2*Math.atan2(s,n)/s;return[r*c,i*c,a*c]}function CN(e,t){let n=[];BM(e,e=>{e.joints&&n.push(...e.joints)});let r=new Map;for(let e of n)r.set(e.child,e);let i=[],a=new Set,o=t;for(;o&&r.has(o)&&!a.has(o);){a.add(o);let e=r.get(o);if(!e)break;i.push(e),o=e.parent}return i.reverse()}function wN(e,t){return e[t]??0}function TN(e,t,n){let r=n+1,i=new Float64Array(n*r);for(let a=0;a<n;a++){for(let t=0;t<n;t++)i[a*r+t]=wN(e,a*n+t);i[a*r+n]=wN(t,a)}for(let e=0;e<n;e++){let t=e;for(let a=e+1;a<n;a++)Math.abs(wN(i,a*r+e))>Math.abs(wN(i,t*r+e))&&(t=a);if(Math.abs(wN(i,t*r+e))<1e-12)return null;if(t!==e)for(let n=e;n<r;n++){let a=wN(i,e*r+n);i[e*r+n]=wN(i,t*r+n),i[t*r+n]=a}let a=wN(i,e*r+e);for(let t=e;t<r;t++)i[e*r+t]=wN(i,e*r+t)/a;for(let t=0;t<n;t++){if(t===e)continue;let n=wN(i,t*r+e);if(n!==0)for(let a=e;a<r;a++)i[t*r+a]=wN(i,t*r+a)-n*wN(i,e*r+a)}}let a=new Float64Array(n);for(let e=0;e<n;e++)a[e]=wN(i,e*r+n);return a}function EN(e,t){let n=[],r=[],i=[],a=[];for(let o of e){let e=t?.[o.child];n.push({child:o.child,count:o.dofs.length}),o.dofs.forEach((t,n)=>{let o=(Array.isArray(e)?e[n]:n===0?e:void 0)??t.value;r.push(Math.min(t.max,Math.max(t.min,o))),i.push(t.min),a.push(t.max)})}return{segments:n,q:Float64Array.from(r),lo:Float64Array.from(i),hi:Float64Array.from(a)}}function DN(e,t){let n={},r=0;for(let i of e){let e=[];for(let n=0;n<i.count;n++)e.push(wN(t,r++));n[i.child]=e}return n}function ON(e,t,n,r,i){let a=bN(t,r);if(e[0]=n.position[0]-a[0],e[1]=n.position[1]-a[1],e[2]=n.position[2]-a[2],i===6&&n.rotation){let r=SN(t.rotation,n.rotation);e[3]=r[0],e[4]=r[1],e[5]=r[2]}let o=0;for(let t=0;t<i;t++)o+=wN(e,t)**2;return Math.sqrt(o)}function kN(e,t,n,r,i,a,o,s,c,l){let u=bN(o,s);for(let d=0;d<n;d++){let f=wN(t,d),p=f+c>wN(a,d)&&f-c>=wN(i,d)?-c:c;t[d]=f+p;let m=l(t);t[d]=f;let h=bN(m,s);if(e[d]=(h[0]-u[0])/p,e[n+d]=(h[1]-u[1])/p,e[2*n+d]=(h[2]-u[2])/p,r===6){let t=SN(o.rotation,m.rotation);e[3*n+d]=t[0]/p,e[4*n+d]=t[1]/p,e[5*n+d]=t[2]/p}}}function AN(e,t,n,r,i){let a=new Float64Array(r*r),o=i*i;for(let t=0;t<r;t++)for(let i=0;i<r;i++){let s=0;for(let r=0;r<n;r++)s+=wN(e,t*n+r)*wN(e,i*n+r);a[t*r+i]=s+(t===i?o:0)}let s=TN(a,t,r);if(!s)return null;let c=new Float64Array(n);for(let t=0;t<n;t++){let i=0;for(let a=0;a<r;a++)i+=wN(e,a*n+t)*wN(s,a);c[t]=i}return c}function jN(e,t,n,r={}){let i=r.maxIterations??200,a=r.tolerance??1e-5,o=r.damping??.05,s=r.tip??[0,0,0],c=n.rotation===void 0?3:6,{segments:l,q:u,lo:d,hi:f}=EN(CN(e,t),r.seed),p=u.length,m=n=>_N(e,DN(l,n)).get(t)??yN,h=new Float64Array(c),g=new Float64Array(c*p),_=m(u),v=ON(h,_,n,s,c),y=0;for(;y<i&&p>0&&v>a;y++){kN(g,u,p,c,d,f,_,s,1e-6,m);let e=AN(g,h,p,c,o);if(!e)break;for(let t=0;t<p;t++){let n=wN(u,t)+wN(e,t);u[t]=Math.min(wN(f,t),Math.max(wN(d,t),n))}_=m(u),v=ON(h,_,n,s,c)}return{values:DN(l,u),converged:v<=a,iterations:y,error:v}}function MN(e,t){return e.dofs.map((e,n)=>{let r=(Array.isArray(t)?t[n]:n===0?t:void 0)??e.value;return Math.min(e.max,Math.max(e.min,r))})}function NN(e,t,n,r){let i=[];BM(e,e=>{e.joints&&i.push(...e.joints)});let a=i.map(e=>({child:e.child,a:MN(e,t[e.child]),b:MN(e,n[e.child])})),o=Math.max(1,Math.floor(r)),s=[];for(let t=0;t<=o;t++){let n=t/o,r={};for(let e of a)r[e.child]=e.a.map((t,r)=>t+((e.b[r]??t)-t)*n);s.push({t:n,values:r,poses:_N(e,r)})}return s}var PN=Math.PI/180;function FN(e,t,n,r){let i=e*PN,a=r*PN,o=XM(JM([0,0,1],i),JM([1,0,0],a));return{position:[n*Math.cos(i),n*Math.sin(i),t],rotation:o}}function IN(e,t={}){let n=t.base??`base`,r=e.map((e,t)=>e.name??`link${t+1}`);return e.map((e,t)=>{let i=t===0?n:r[t-1]??`link${t}`,a=r[t]??`link${t+1}`,o=FN(e.theta,e.d,e.a,e.alpha),s={origin:[0,0,0],direction:[0,0,1]},c={...e.min===void 0?{}:{min:e.min},...e.max===void 0?{}:{max:e.max},...e.value===void 0?{}:{value:e.value}};return{...e.type===`prismatic`?aN(i,a,s,c):iN(i,a,s,c),offset:o}})}var LN=Math.PI/180,RN=180/Math.PI;function zN(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function BN(e){return String(e===0?0:e)}function VN(e){return`${BN(e[0])} ${BN(e[1])} ${BN(e[2])}`}function HN(e,t={}){let n=t.name??`robot`,r=t.effort??0,i=t.velocity??0,a=t.meshes??{},o=[],s=[];BM(e,e=>{o.push(e.name),e.joints&&s.push(...e.joints)});for(let e of s){if(e.type!==`revolute`&&e.type!==`prismatic`)return k(F(N.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' is '${e.type}'; URDF supports only revolute and prismatic joints`));if(e.offset)return k(F(N.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' carries a fixed offset (e.g. a DH link) that URDF cannot represent as a single joint`))}let c=[`<?xml version="1.0"?>`,`<robot name="${zN(n)}">`];for(let e of o){let t=a[e];t?c.push(` <link name="${zN(e)}">`,` <visual><geometry><mesh filename="${zN(t)}"/></geometry></visual>`,` </link>`):c.push(` <link name="${zN(e)}"/>`)}for(let e of s){let t=e.type===`revolute`,n=t?e.min*LN:e.min,a=t?e.max*LN:e.max,o=e.type===`prismatic`?[0,0,0]:e.axis.origin;c.push(` <joint name="${zN(`${e.parent}_to_${e.child}`)}" type="${e.type}">`,` <parent link="${zN(e.parent)}"/>`,` <child link="${zN(e.child)}"/>`,` <origin xyz="${VN(o)}" rpy="0 0 0"/>`,` <axis xyz="${VN(e.axis.direction)}"/>`,` <limit lower="${BN(n)}" upper="${BN(a)}" effort="${BN(r)}" velocity="${BN(i)}"/>`,` </joint>`)}return c.push(`</robot>`,``),O(c.join(`
|
|
16
|
+
`))}function UN(e,t){return RegExp(`\\b${t}\\s*=\\s*"([^"]*)"`).exec(e)?.[1]}function WN(e,t){if(!e)return t;let n=e.trim().split(/\s+/).map(Number);return[n[0]??0,n[1]??0,n[2]??0]}function GN(e,t){return qM(XM(XM(JM([0,0,1],t[2]),JM([0,1,0],t[1])),JM([1,0,0],t[0])),e)}function KN(e){let t=/<robot\b([^>]*)>/.exec(e);if(!t)return k(F(N.VALIDATION_FAILED,`importURDF: no <robot> element found`));let n=UN(t[1]??``,`name`)??`robot`,r=[],i=/<link\b([^>]*?)(?:\/>|>)/g;for(let t=i.exec(e);t;t=i.exec(e)){let e=UN(t[1]??``,`name`);e&&r.push(e)}let a=[],o=/<joint\b([^>]*)>([\s\S]*?)<\/joint>/g;for(let t=o.exec(e);t;t=o.exec(e)){let e=t[1]??``,n=t[2]??``,r=UN(e,`type`)??`fixed`;if(r===`fixed`||r===`floating`||r===`planar`)continue;let i=/<parent\b([^>]*?)\/?>/.exec(n),o=/<child\b([^>]*?)\/?>/.exec(n),s=UN(i?.[1]??``,`link`),c=UN(o?.[1]??``,`link`);if(!s||!c)return k(F(N.VALIDATION_FAILED,`importURDF: joint missing parent/child link (${UN(e,`name`)??`unnamed`})`));let l=/<origin\b([^>]*?)\/?>/.exec(n),u=/<axis\b([^>]*?)\/?>/.exec(n),d=/<limit\b([^>]*?)\/?>/.exec(n),f=WN(UN(l?.[1]??``,`xyz`),[0,0,0]),p=WN(UN(l?.[1]??``,`rpy`),[0,0,0]),m=GN(WN(UN(u?.[1]??``,`xyz`),[1,0,0]),p),h=Number(UN(d?.[1]??``,`lower`)??NaN),g=Number(UN(d?.[1]??``,`upper`)??NaN);if(r===`prismatic`){let e=Number.isFinite(h)&&Number.isFinite(g)?{min:h,max:g}:{};a.push(aN(s,c,{origin:f,direction:m},e))}else if(r===`revolute`||r===`continuous`){let e=r===`continuous`||!Number.isFinite(h)||!Number.isFinite(g)?{min:-180,max:180}:{min:h*RN,max:g*RN};a.push(iN(s,c,{origin:f,direction:m},e))}else return k(F(N.VALIDATION_FAILED,`importURDF: joint '${UN(e,`name`)??`unnamed`}' has unrecognized type '${r}'`))}return O({name:n,links:r,joints:a})}function qN(){return{steps:[],shapes:new Map}}function JN(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 YN(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 XN(e,t){return e.steps.find(e=>e.id===t)}function ZN(e,t){return e.shapes.get(t)}function QN(e){return e.steps.length}function $N(e,t){let n=e.steps.findIndex(e=>e.id===t);return n===-1?[]:e.steps.slice(n)}function eP(e,t,n){let r=new Map(e.shapes);return r.set(t,n),{...e,shapes:r}}function tP(){return{operations:new Map}}function nP(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function rP(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=eP(r,t,i));for(let n of e.steps){let e=t.operations.get(n.type);if(!e)return k(I(`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(I(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${n.id}`));i.push(t)}try{let t=e(i,n.parameters);r=JN(r,{id:n.id,type:n.type,parameters:n.parameters,inputIds:n.inputIds,outputId:n.outputId},t)}catch(e){return k(I(`REPLAY_STEP_FAILED`,`Step ${n.id} (${n.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(r)}function iP(e,t,n){let r=e.steps.findIndex(e=>e.id===t);if(r===-1)return k(I(`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(I(`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(I(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${r.id}`));o.push(t)}try{let e=i(o,r.parameters);a=JN(a,{id:r.id,type:r.type,parameters:r.parameters,inputIds:r.inputIds,outputId:r.outputId},e)}catch(e){return k(I(`REPLAY_STEP_FAILED`,`Step ${r.id} (${r.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(a)}function aP(e,t,n,r){return e.steps.findIndex(e=>e.id===t)===-1?k(I(`MODIFY_STEP_NOT_FOUND`,`Step not found: ${t}`)):iP({steps:e.steps.map(e=>e.id===t?{...e,parameters:n}:e),shapes:e.shapes},t,r)}function oP(e){let t={};for(let[n,r]of e.shapes){let e=JO(r);if(!e.ok)return k(I(`SERIALIZE_SHAPE_FAILED`,`Failed to serialize shape "${n}": ${e.error.message}`));t[n]=e.value}return O({steps:e.steps,shapes:t})}function sP(e){let t=new Map;for(let[n,r]of Object.entries(e.shapes))try{let e=UD(r);if(!e.ok)return k(I(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e.error.message}`));t.set(n,e.value)}catch(e){return k(I(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e instanceof Error?e.message:String(e)}`))}return O({steps:e.steps,shapes:t})}function cP(e){try{var t=CT();let{radius:n,pitch:r,height:i,depth:a=.6*r,toothHalfWidth:o=.42*r,sectionsPerTurn:s=20,lefthand:c=!1,inward:l=!1}=e;if(!(n>0))return k(F(`THREAD_INVALID_RADIUS`,`radius must be > 0`));if(!(r>0))return k(F(`THREAD_INVALID_PITCH`,`pitch must be > 0`));if(!(i>0))return k(F(`THREAD_INVALID_HEIGHT`,`height must be > 0`));if(!(a>0))return k(F(`THREAD_INVALID_DEPTH`,`depth must be > 0`));if(s<3)return k(F(`THREAD_TOO_FEW_SECTIONS`,`sectionsPerTurn must be >= 3`));let u=i/r,d=Math.max(2,Math.round(u*s)),f=c?-1:1,p=l?-a:a,m=l?.3:-.3,h=o,g=t.u(new FT),_=[];for(let e=0;e<=d;e++){let t=f*e*2*Math.PI/s,i=r*Math.abs(t)/(2*Math.PI),a=n*Math.cos(t),o=n*Math.sin(t),c=Math.cos(t),l=Math.sin(t),u=(e,t)=>[a+e*c,o+e*l,i+t],d=u(m,-h),v=u(p,0),y=u(m,h),b=vM([g.register(lM(d,v)),g.register(lM(v,y)),g.register(lM(y,d))]);if(!Na(b))return b;_.push(g.register(b.value))}return tM(_,{ruled:!0})}catch(e){t.e=e}finally{t.d()}}var lP=new WeakMap;function uP(e,t){return lP.get(e)?.get(t)}function dP(e,t,n){let r=lP.get(e);r||(r=new Map,lP.set(e,r)),r.set(t,n)}function fP(e){return U().isNull(e.wrapped)}function pP(e){return k(F(N.NULL_SHAPE_INPUT,`${e}: shape is a null shape`))}function mP(e){let t=uP(e.wrapped,`volume`);if(t)return O(t);if(fP(e))return pP(`measureVolumeProps`);let n=U(),r=n.shapeType(e.wrapped);if(r!==`solid`&&r!==`compsolid`&&r!==`compound`){let t={mass:0,volume:0,centerOfMass:[0,0,0]};return dP(e.wrapped,`volume`,t),O(t)}let i=n.volume(e.wrapped),a=jE(()=>n.centerOfMass(e.wrapped),N.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!a.ok)return a;let o={mass:i,volume:i,centerOfMass:a.value};return dP(e.wrapped,`volume`,o),O(o)}function hP(e){let t=uP(e.wrapped,`surface`);if(t)return O(t);if(fP(e))return pP(`measureSurfaceProps`);let n=U(),r=n.area(e.wrapped),i=jE(()=>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 dP(e.wrapped,`surface`,a),O(a)}function gP(e){let t=uP(e.wrapped,`linear`);if(t)return O(t);if(fP(e))return pP(`measureLinearProps`);let n=U(),r=n.length(e.wrapped),i={mass:r,length:r,centerOfMass:n.linearCenterOfMass(e.wrapped)};return dP(e.wrapped,`linear`,i),O(i)}function _P(e){let t=mP(e);return t.ok?O(t.value.mass):t}function vP(e){let t=hP(e);return t.ok?O(t.value.mass):t}function yP(e){let t=gP(e);return t.ok?O(t.value.mass):t}function bP(e,t){return fP(e)||fP(t)?pP(`measureDistance`):O(U().distance(e.wrapped,t.wrapped).value)}function xP(e,t){if(fP(e)||fP(t))return pP(`measureDistanceProps`);let n=U().distance(e.wrapped,t.wrapped);return O({distance:n.value,point1:n.point1,point2:n.point2})}function SP(e){if(fP(e))return pP(`createDistanceQuery`);let t=U().createDistanceQuery(e.wrapped);return O({distanceTo(e){return fP(e)?pP(`createDistanceQuery.distanceTo`):O(t.distanceTo(e.wrapped).value)},dispose(){t.dispose()}})}function CP(e,t,n){if(fP(e))return pP(`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 wP(e){if(fP(e))return pP(`measureCurvatureAtMid`);let t=YD(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 TP=1e-9,EP=1e-8,DP=1e-6,OP=([e,t],[n,r],i=DP)=>Math.abs(e-n)<=i&&Math.abs(t-r)<=i,kP=([e,t],[n,r])=>[e+n,t+r],AP=([e,t],[n,r])=>[e-n,t-r],jP=([e,t],n)=>[e*n,t*n],MP=([e,t],[n,r]=[0,0])=>Math.sqrt((e-n)**2+(t-r)**2),NP=([e,t],[n,r]=[0,0])=>(e-n)**2+(t-r)**2;function PP([e,t],[n,r]){return e*r-t*n}var FP=([e,t],[n,r]=[0,0])=>Math.atan2(r*e-t*n,e*n+t*r),IP=([e,t],[n,r]=[0,0])=>Math.atan2(r-t,n-e),LP=(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 RP([e,t]){let n=Math.sqrt(e*e+t*t);return n<1e-12?[0,0]:[e/n,t/n]}var zP=(e,t)=>[Math.cos(t)*e,Math.sin(t)*e],BP=([e,t])=>[Math.sqrt(e*e+t*t),Math.atan2(t,e)],VP=([e,t])=>{let n=RP([e,t]);return n[0]===0&&n[1]===0&&M(`normalize2d`,`Cannot normalize zero-length vector`),n};function HP(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(po(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found ${r===0?0:`2+`} element(s)`))}function UP(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 RE(t);case`face`:return zE(t);case`wire`:return BE(t);case`vertex`:return VE(t)}}let s=e=>{let n=o(e);return t.length===0?n.slice():n.filter(a)},c=()=>UP(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=YO(n),r=t.get(e);r?r.push(n):t.set(e,[n])}return i(e=>{let n=t.get(YO(e));return!!n&&n.some(t=>ZO(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=>HP(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 WP={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function GP(e){return typeof e==`string`?WP[e]??[0,0,1]:e}function KP(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 qP(e,t){let n=yD(GP(e));return e=>{let r=U(),[i,a]=r.curveParameters(e.wrapped),o=(i+a)/2,{tangent:s}=r.curveTangent(e.wrapped,o),c=yD(s),l=Math.acos(Math.min(1,Math.abs(mD(c,n))));return Math.abs(l-iD*t)<1e-6}}function JP(e){return UP(`edge`,e,JP,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(qP(e,t)),ofLength:(e,t=.001)=>n(n=>Math.abs(ak(n)-e)<t),ofCurveType:e=>n(t=>ek(t)===e),parallelTo:(t=`Z`)=>JP(e).inDirection(t,0),atDistance:(e,t=[0,0,0])=>n(KP(e,t,1e-6))}))}function YP(){return JP([])}function XP(e,t){let n=yD(GP(e));return e=>{let r=$D(e),i=Math.acos(Math.min(1,Math.abs(mD(yD(r),n))));return Math.abs(i-iD*t)<1e-6}}function ZP(e){return UP(`face`,e,ZP,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(XP(e,t)),parallelTo:(t=`Z`)=>ZP(e).inDirection(t,0),ofSurfaceType:e=>n(t=>{let n=GD(t);return Na(n)&&n.value===e}),ofArea:(e,t=.001)=>n(n=>{let r=vP(n);return Na(r)&&Math.abs(r.value-e)<t}),atDistance:(e,t=[0,0,0])=>n(KP(e,t,1e-6))}))}function QP(){return ZP([])}function $P(e){return UP(`wire`,e,$P,(e,t)=>({isClosed:()=>t(e=>sk(e)),isOpen:()=>t(e=>!sk(e)),ofEdgeCount:e=>t(t=>RE(t).length===e)}))}function eF(){return $P([])}function tF(e,t){return typeof e==`object`&&`_topoKind`in e?e.findUnique(t):typeof e!=`function`&&bE(e)?O(e):e(QP()).findUnique(t)}function nF(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`}function rF(e,t){let n=10**t,r=t<0?e:.01/n+e;return Math.round(r*n)/n}function iF(e){return Math.round(e*100)/100}function aF(e){return Math.round(e*1e5)/1e5}var oF=([e,t])=>`(${iF(e)},${iF(t)})`,sF=(e,t=1e-9)=>{let n=e;return Math.abs(e)<t&&(n=0),n.toFixed(-Math.log10(t))},cF=(e,t=1e-9)=>Array.from(new Map(e.map(([e,n])=>[`[${sF(e,t)},${sF(n,t)}]`,[e,n]])).values()),lF=class{_wrapped;_deleted=!1;constructor(e){this._wrapped=e??dT().createBoundingBox2d(),LT(this,this._wrapped)}get wrapped(){if(this._deleted)throw Error(`This object has been deleted`);return this._wrapped}delete(){this._deleted||(this._deleted=!0,RT(this._wrapped),typeof this._wrapped.delete==`function`&&this._wrapped.delete())}[Symbol.dispose](){this.delete()}get repr(){let[e,t]=this.bounds;return`${oF(e)} - ${oF(t)}`}get bounds(){let{xMin:e,yMin:t,xMax:n,yMax:r}=dT().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){dT().mergeBBox2d(this.wrapped,e.wrapped)}isOut(e){return dT().isBBox2dOut(this.wrapped,e.wrapped)}containsPoint(e){return!dT().isBBox2dOutPoint(this.wrapped,e[0],e[1])}};function uF(e){return new dF(U().deserializeCurve2d(e))}var dF=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`&<(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`&&(RT(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 lF(t),this._boundingBox}get repr(){return`${this.geomType} ${oF(this.firstPoint)} - ${oF(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,MP(e,this.firstPoint),MP(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 nF(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?OP(e,this.firstPoint,t)?O(this.firstParameter):OP(e,this.lastPoint,t)?O(this.lastParameter):k(I(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n===void 0||r===void 0?k(I(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n>t?k(I(`POINT_NOT_ON_CURVE`,`Point ${oF(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=>nF(e)?j(this.parameter(e,r)):e);i=Array.from(new Map(i.map(e=>[rF(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))}},fF=(e,t=1e-4,n=`C0`,r=200)=>new dF(dT().approximateCurve2dAsBSpline(e.wrapped,t,n,r)),pF=e=>(e.geomType!==`BSPLINE_CURVE`&&M(`BSplineToBezier`,`You can only convert a Bspline`),dT().decomposeBSpline2dToBeziers(e.wrapped).map(e=>new dF(e)));function mF(e,t={tolerance:1e-4,continuity:`C0`,maxSegments:300}){let n=dT();return e.flatMap(e=>{let r=e.geomType;if(r===`ELLIPSE`||r===`CIRCLE`&&OP(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 mF(pF(r===`BSPLINE_CURVE`?e:fF(e,t.tolerance,t.continuity,t.maxSegments)),t)})}var hF=(e,t)=>{let n=new dF(U().makeLine2d(e[0],e[1],t[0],t[1]));return OP(n.firstPoint,e)||n.reverse(),n},gF=(e,t,n)=>{let r=new dF(U().makeArc2dThreePoints(e[0],e[1],t[0],t[1],n[0],n[1]));if(!OP(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new dF(e)}return r},_F=(e,t,n)=>{let r=new dF(U().makeArc2dTangent(e[0],e[1],t[0],t[1],n[0],n[1]));if(!OP(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new dF(e)}return r},vF=(e,t=[0,0])=>new dF(U().makeCircle2d(t[0],t[1],e,!0)),yF=(e,t,n=[1,0],r=[0,0],i=!0)=>new dF(U().makeEllipse2d(r[0],r[1],e,t,n[0],n[1],i)),bF=(e,t,n,r,i=[0,0],a,o=!0)=>new dF(U().makeEllipseArc2d(i[0],i[1],e,t,n,r,a[0],a[1],o)),xF=(e,t,n)=>{let r=[[e[0],e[1]],...t.map(e=>[e[0],e[1]]),[n[0],n[1]]];return new dF(U().makeBezier2d(r))};function SF(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 dF(U().makeBSpline2d(a,{tolerance:t,smoothing:n,degMax:r,degMin:i,continuity:`C2`})))}catch{return k(I(`BSPLINE_2D_FAILED`,`B-spline approximation failed`))}}var CF=(e,t,n,r=!1)=>{let i=jP(kP(e,t),.5),a=MP(n,e)*(r?-1:1);return gF(e,kP(jP(VP(AP(i,n)),a),n),t)},wF=(e,n)=>{let r=dT(),i=e.geomType,[a,o]=n,s=`${aF(a)} ${aF(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 ${iF(e)} ${iF(r)} ${s}`}if(i===3){let[e,r]=t(n,1),[i,a]=t(n,2);return`C ${iF(e)} ${iF(r)} ${iF(i)} ${iF(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)*aD,u=l===360?`${aF(a)} ${aF(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)*aD,f=d===360?`${aF(a)} ${aF(o+1e-4)}`:s,p=180-c*aD;return`A ${aF(n)} ${aF(i)} ${aF(p)} ${Math.abs(d)>180?`1`:`0`} ${l?`1`:`0`} ${f}`}M(`adaptedCurveToPathElem`,`Unsupported curve type: ${i}`)},TF=e=>{let t=U(),n=t.createBoundingBox2d();return e.forEach(e=>{t.addCurveToBBox2d(n,e.wrapped,1e-6)}),new lF(n)};function EF(e,t){let n=U();return e.map(e=>uE(n.liftCurve2dToPlane(e.wrapped,[...t.origin],[...t.zDir],[...t.xDir])))}var DF=(e,t)=>{let n=U();return e.map(e=>uE(n.buildEdgeOnSurface(e.wrapped,t)))},OF=(e,t)=>{let n=U();return e.map(e=>t?new dF(n.transformCurve2dGeneral(e.wrapped,t)):e.clone())},kF=(e,t,n=[0,0])=>U().createAffinityGTrsf2d(n[0],n[1],-t[1],t[0],e),AF=e=>U().createTranslationGTrsf2d(e[0],e[1]),jF=(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]),MF=(e,t=[0,0])=>U().createRotationGTrsf2d(e,t[0],t[1]),NF=(e,t=[0,0])=>U().createScaleGTrsf2d(e,t[0],t[1]);function PF(e,t,n=`original`){let r=U(),i=r.extractSurfaceFromFace(t.wrapped),a=YD(t),o=null;if(n===`original`&&KD(t)!==`PLANE`){if(KD(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=kF(1/e.radius,[1,0])}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=DF(OF(e,o),i);return o&&o.delete(),O(s)}function FF(e,t){let n=U(),r=new dF(n.extractCurve2dFromEdge(e.wrapped,t.wrapped));return uk(e)===`backward`&&n.reverseCurve2d(r.wrapped),r}var IF=(e,t=1)=>`${e.bounds[0][0]-t} ${-e.bounds[1][1]-t} ${e.width+2*t} ${e.height+2*t}`,LF=(e,t,n=1)=>`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${IF(t,n)}" fill="none" stroke="black" stroke-width="0.6%" vector-effect="non-scaling-stroke">
|
|
17
17
|
${e}
|
|
18
18
|
</svg>`;function RF(e){let t=e.map(e=>e.wrapped);return dE(U().makeWire(t))}var zF=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(`
|
|
19
|
-
`)}get boundingBox(){return this._boundingBox||=TF(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=Pk(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(OF(this.curves,kF(t,n,r)))}scale(t,n){let r=n||this.boundingBox.center;return new e(OF(this.curves,NF(t,r)))}rotate(t,n){return new e(OF(this.curves,MF(t*iD,n)))}translate(t,n=0){let r=nF(t)?t:[t,n];return new e(OF(this.curves,AF(r)))}mirror(t,n=[0,0],r=`center`){return new e(OF(this.curves,jF(t,n,r)))}sketchOnPlane(e,t){let n=e&&typeof e!=`string`?{...e}:jD(e,t);return{wire:RF(EF(this.curves,n)),defaultOrigin:n.origin,defaultDirection:n.zDir}}sketchOnFace(e,t){let n=U(),r=RF(j(PF(this.curves,e,t)));n.buildCurves3d(r.wrapped);let i=n.fixWireOnFace(r.wrapped,e.wrapped,1e-9);return r.delete(),{wire:dE(i),baseFace:e}}subFace(e,t){let n=oD(t||[...eO(e)]);return j(Xk(this.translate(ZD(e,n)).sketchOnFace(e,`original`).wire))}punchHole(e,t,{height:n=null,origin:r=null,draftAngle:i=0}={}){let a=j(tF(t,e)),o=this.subFace(a,r);return j(VD(U().draftPrism(e.wrapped,o.wrapped,a.wrapped,n,i,!1)))}toSVGPathD(){let e=this.clone().mirror([1,0],[0,0],`plane`),t=mF(e.curves).flatMap(e=>wF(e,e.lastPoint)),[n,r]=Fk(e.curves).firstPoint;return`M ${aF(n)} ${aF(r)} ${t.join(` `)}${e.isClosed()?` Z`:``}`}toSVGPath(){return`<path d="${this.toSVGPathD()}" />`}toSVGViewBox(e=1){return IF(this.boundingBox,e)}toSVGPaths(){return[this.toSVGPathD()]}toSVG(e=1){return LF(this.toSVGPath(),this.boundingBox,e)}get firstPoint(){return Fk(this.curves).firstPoint}get lastPoint(){return Ik(this.curves).lastPoint}isInside(e){if(!this.boundingBox.containsPoint(e))return!1;let t=U(),n=hF(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=>OP(t,e,1e-9))||(r.push(e),i++);for(let e of a.segments)e.delete()}),!!(i%2)}finally{n.delete()}}isClosed(){return OP(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}},BF=class{constructor(e=1/0,t=Float64Array,n=Uint32Array){let r=e!==1/0;this.ids=r?new n(e):[],this.values=r?new t(e):[],this.capacity=e,this.length=0}clear(){this.length=0}push(e,t){if(this.length===this.capacity)throw RangeError(`Queue is at capacity.`);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(){Array.isArray(this.ids)&&(this.ids.length=this.length),Array.isArray(this.values)&&(this.values.length=this.length)}},VF=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],HF=3,UF=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||`buffer`in t)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!==HF)throw Error(`Got v${a} data when expected v${HF}.`);let o=VF[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=VF.indexOf(n),l=s*4*n.BYTES_PER_ELEMENT;if(c<0)throw Error(`Unexpected typed array class: ${n}.`);let u=n,d=this.IndexArrayType;if(i)this.data=i,this._boxes=new u(i,a+8,s*4),this._indices=new d(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 n=this.data=new r(8+l+s*this.IndexArrayType.BYTES_PER_ELEMENT);this._boxes=new u(n,8,s*4),this._indices=new d(n,8+l,s),this._pos=0,this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,new Uint8Array(n,0,2).set([251,(HF<<4)+c]),new Uint16Array(n,2,1)[0]=t,new Uint32Array(n,4,1)[0]=e}this._queue=new BF}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 Int32Array(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]=qF(Math.floor(i*((s+l)/2-this.minX)/t),Math.floor(i*((c+u)/2-this.minY)/n))}GF(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{_boxes:a,_levelBounds:o,_indices:s,nodeSize:c}=this,l=this.numItems*4,u=a.length-4,d=o.length-1,f=[],p=[],m=!1;for(;u!==void 0;){let h=Math.min(u+c*4,o[d]),g=u>=l;if(m)this._collectContained(u,h,d,g,f,p,i);else for(let o=u;o<h;o+=4){let c=a[o];if(n<c)continue;let l=a[o+1];if(r<l)continue;let u=a[o+2];if(e>u)continue;let m=a[o+3];if(t>m)continue;let h=s[o>>2]|0;if(g){let i=+(e<=c&&t<=l&&n>=u&&r>=m);f.push(h|i,d-1)}else (i===void 0||i(h,c,l,u,m))&&p.push(h)}d=f.pop(),u=f.pop(),u!==void 0&&(m=(u&1)==1,u&=-2)}return p}_collectContained(e,t,n,r,i,a,o){let s=this._boxes,c=this._indices;if(r)for(let r=e;r<t;r+=4)i.push(c[r>>2]|1,n-1);else for(let n=e;n<t;n+=4){let e=c[n>>2]|0;(o===void 0||o(e,s[n],s[n+1],s[n+2],s[n+3]))&&a.push(e)}}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{_boxes:a,_levelBounds:o,_indices:s,_queue:c,nodeSize:l}=this,u=this.numItems*4,d=l*4,f=[],p=r*r;for(c.push(a.length-4<<1,0);c.length;){let r=c.ids[0];if(r&1){if(c.values[0]>p||(c.pop(),f.push(r>>1),f.length===n))break;continue}c.pop();let l=r>>1,m=l<u,h=Math.min(l+d,WF(l,o));for(let n=l;n<h;n+=4){let r=s[n>>2]|0,o=a[n],l=a[n+1],u=a[n+2],d=a[n+3],f=e<o?o-e:e>u?e-u:0,h=t<l?l-t:t>d?t-d:0,g=f*f+h*h;g>p||(m?(i===void 0||i(r))&&c.push(r<<1|1,g):c.push(r<<1,g))}}return c.clear(),f}};function WF(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 GF(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;KF(e,t,n,d,f)}o.push(i,f,f+1,r)}}function KF(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 qF(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^(i>>1^r&a>>1),l=a^(n&i>>1^a>>1);return n=o&o>>2^s&s>>2,r=o&s>>2^s&(o^s)>>2,i=c^(o&c>>2^s&l>>2),a=l^(s&c>>2^(o^s)&l>>2),o=n&n>>4^r&r>>4,s=n&r>>4^r&(n^r)>>4,c=i^(n&i>>4^r&a>>4),l=a^(r&i>>4^(n^r)&a>>4),i=c^(o&c>>8^s&l>>8),a=l^(s&c>>8^(o^s)&l>>8),i^=i>>1,a^=a>>1,n=e^t,r=a|65535^(n|i),n=(n|n<<8)&16711935,n=(n|n<<4)&252645135,n=(n|n<<2)&858993459,n=(n|n<<1)&1431655765,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,((r<<1|n)>>>0)-2147483648}var JF=(e,t,n=1e-9)=>{if(e.boundingBox.isOut(t.boundingBox))return O({intersections:[],commonSegments:[],commonSegmentsPoints:[]});let r=dT(),i,a;try{let o=r.intersectCurves2d(e.wrapped,t.wrapped,n);i=o.points,a=o.segments.map(e=>new dF(e))}catch(e){return k(fo(`INTERSECTION_FAILED`,`Intersections failed between curves`,e))}let o=a.filter(e=>OP(e.firstPoint,e.lastPoint,n)).map(e=>e.firstPoint);o.length&&(i.push(...o),a=a.filter(e=>!OP(e.firstPoint,e.lastPoint,n)));let s=a.flatMap(e=>[e.firstPoint,e.lastPoint]);return O({intersections:i,commonSegments:a,commonSegmentsPoints:s})},YF=(e,t=1e-9)=>{let n=dT(),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(fo(`SELF_INTERSECTION_FAILED`,`Self intersection failed`,e))}return O(r)},XF=(e,n,r)=>{let i=VP(AP(n,e)),a=[i[1],-i[0]],o=[t(a,0)*r,t(a,1)*r];return{firstPoint:kP(e,o),lastPoint:kP(n,o)}},ZF=(e,t)=>{let n=e.geomType,r=dT();if(n===`CIRCLE`){let n=r.getCurve2dCircleData(e.wrapped);if(!n)return hF(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]=VP(AP(e,t));return kP(e,[c*n,c*r])};return{collapsed:!0,firstPoint:n(e.firstPoint),lastPoint:n(e.lastPoint)}}let u=new dF(r.makeCircle2d(i,a,l,s)),d;try{d=r.trimCurve2d(u.wrapped,e.firstParameter,e.lastParameter)}finally{u.delete()}return new dF(d)}if(n===`LINE`){let{firstPoint:n,lastPoint:r}=XF(e.firstPoint,e.lastPoint,t);return hF(n,r)}let i=new dF(r.offsetCurve2d(e.wrapped,t)),a=fF(i);if(i.delete(),j(YF(a)).length){let e=a.firstPoint,t=a.lastPoint;return a.delete(),{collapsed:!0,firstPoint:e,lastPoint:t}}return a};function QF(e,n,r){let i=PP(e.tangentAt(1),n.tangentAt(0));if(Math.abs(i)<1e-10)return null;let a=Math.abs(r)*(i>0?-1:1),o=ZF(e,a),s=ZF(n,a);if(!(o instanceof dF)||!(s instanceof dF))return null;let c=JF(o,s,1e-9);if(!Na(c))return null;let l=c.value.intersections.at(-1);if(!nF(l))return null;let u=l,d=(e,t)=>{let[n,r]=t.tangentAt(u),i=kP(u,jP(VP([-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 $F(e,t,n){let r=QF(e,t,n);if(!r)return[e,t];let{first:i,second:a,center:o}=r;return[i,CF(i.lastPoint,a.firstPoint,o),a]}function eI(e,t,n){let r=QF(e,t,n);if(!r)return[e,t];let{first:i,second:a}=r;return[i,hF(i.lastPoint,a.firstPoint),a]}function tI(e,n,r){let i=PP(VP(e.tangentAt(1)),VP(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=ZF(e,s),l=ZF(n,s);if(!(c instanceof dF)||!(l instanceof dF))return[e,n];let u=JF(c,l,1e-9);if(!Na(u))return[e,n];let d=u.value.intersections.at(-1);if(!nF(d))return[e,n];let f=vF(r,d),p=j(JF(e,f)).intersections[0],m=j(JF(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[_,gF(_.lastPoint,e.lastPoint,v.firstPoint),v]}catch{return[e,n]}}var nI=class e{blueprints;_boundingBox;constructor(e){this.blueprints=e,this._boundingBox=null}get repr(){return[`Blueprints`,...this.blueprints.map(e=>e.repr)].join(`
|
|
19
|
+
`)}get boundingBox(){return this._boundingBox||=TF(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=Pk(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(OF(this.curves,kF(t,n,r)))}scale(t,n){let r=n||this.boundingBox.center;return new e(OF(this.curves,NF(t,r)))}rotate(t,n){return new e(OF(this.curves,MF(t*iD,n)))}translate(t,n=0){let r=nF(t)?t:[t,n];return new e(OF(this.curves,AF(r)))}mirror(t,n=[0,0],r=`center`){return new e(OF(this.curves,jF(t,n,r)))}sketchOnPlane(e,t){let n=e&&typeof e!=`string`?{...e}:jD(e,t);return{wire:RF(EF(this.curves,n)),defaultOrigin:n.origin,defaultDirection:n.zDir}}sketchOnFace(e,t){let n=U(),r=RF(j(PF(this.curves,e,t)));n.buildCurves3d(r.wrapped);let i=n.fixWireOnFace(r.wrapped,e.wrapped,1e-9);return r.delete(),{wire:dE(i),baseFace:e}}subFace(e,t){let n=oD(t||[...eO(e)]);return j(Xk(this.translate(ZD(e,n)).sketchOnFace(e,`original`).wire))}punchHole(e,t,{height:n=null,origin:r=null,draftAngle:i=0}={}){let a=j(tF(t,e)),o=this.subFace(a,r);return j(VD(U().draftPrism(e.wrapped,o.wrapped,a.wrapped,n,i,!1)))}toSVGPathD(){let e=this.clone().mirror([1,0],[0,0],`plane`),t=mF(e.curves).flatMap(e=>wF(e,e.lastPoint)),[n,r]=Fk(e.curves).firstPoint;return`M ${aF(n)} ${aF(r)} ${t.join(` `)}${e.isClosed()?` Z`:``}`}toSVGPath(){return`<path d="${this.toSVGPathD()}" />`}toSVGViewBox(e=1){return IF(this.boundingBox,e)}toSVGPaths(){return[this.toSVGPathD()]}toSVG(e=1){return LF(this.toSVGPath(),this.boundingBox,e)}get firstPoint(){return Fk(this.curves).firstPoint}get lastPoint(){return Ik(this.curves).lastPoint}isInside(e){if(!this.boundingBox.containsPoint(e))return!1;let t=U(),n=hF(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=>OP(t,e,1e-9))||(r.push(e),i++);for(let e of a.segments)e.delete()}),!!(i%2)}finally{n.delete()}}isClosed(){return OP(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}},BF=class{constructor(e=1/0,t=Float64Array,n=Uint32Array){let r=e!==1/0;this.ids=r?new n(e):[],this.values=r?new t(e):[],this.capacity=e,this.length=0}clear(){this.length=0}push(e,t){if(this.length===this.capacity)throw RangeError(`Queue is at capacity.`);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(){Array.isArray(this.ids)&&(this.ids.length=this.length),Array.isArray(this.values)&&(this.values.length=this.length)}},VF=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],HF=3,UF=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||`buffer`in t)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!==HF)throw Error(`Got v${a} data when expected v${HF}.`);let o=VF[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=VF.indexOf(n),l=s*4*n.BYTES_PER_ELEMENT;if(c<0)throw Error(`Unexpected typed array class: ${n}.`);let u=n,d=this.IndexArrayType;if(i)this.data=i,this._boxes=new u(i,a+8,s*4),this._indices=new d(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 n=this.data=new r(8+l+s*this.IndexArrayType.BYTES_PER_ELEMENT);this._boxes=new u(n,8,s*4),this._indices=new d(n,8+l,s),this._pos=0,this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,new Uint8Array(n,0,2).set([251,(HF<<4)+c]),new Uint16Array(n,2,1)[0]=t,new Uint32Array(n,4,1)[0]=e}this._queue=new BF}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 Int32Array(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]=qF(Math.floor(i*((s+l)/2-this.minX)/t),Math.floor(i*((c+u)/2-this.minY)/n))}GF(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{_boxes:a,_levelBounds:o,_indices:s,nodeSize:c}=this,l=this.numItems*4,u=a.length-4,d=o.length-1,f=[],p=[],m=!1;for(;u!==void 0;){let h=Math.min(u+c*4,o[d]),g=u>=l;if(m)this._collectContained(u,h,d,g,f,p,i);else for(let o=u;o<h;o+=4){let c=a[o];if(n<c)continue;let l=a[o+1];if(r<l)continue;let u=a[o+2];if(e>u)continue;let m=a[o+3];if(t>m)continue;let h=s[o>>2]|0;if(g){let i=+(e<=c&&t<=l&&n>=u&&r>=m);f.push(h|i,d-1)}else (i===void 0||i(h,c,l,u,m))&&p.push(h)}d=f.pop(),u=f.pop(),u!==void 0&&(m=(u&1)==1,u&=-2)}return p}_collectContained(e,t,n,r,i,a,o){let s=this._boxes,c=this._indices;if(r)for(let r=e;r<t;r+=4)i.push(c[r>>2]|1,n-1);else for(let n=e;n<t;n+=4){let e=c[n>>2]|0;(o===void 0||o(e,s[n],s[n+1],s[n+2],s[n+3]))&&a.push(e)}}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{_boxes:a,_levelBounds:o,_indices:s,_queue:c,nodeSize:l}=this,u=this.numItems*4,d=l*4,f=[],p=r*r;for(c.push(a.length-4<<1,0);c.length;){let r=c.ids[0];if(r&1){if(c.values[0]>p||(c.pop(),f.push(r>>1),f.length===n))break;continue}c.pop();let l=r>>1,m=l<u,h=Math.min(l+d,WF(l,o));for(let n=l;n<h;n+=4){let r=s[n>>2]|0,o=a[n],l=a[n+1],u=a[n+2],d=a[n+3],f=e<o?o-e:e>u?e-u:0,h=t<l?l-t:t>d?t-d:0,g=f*f+h*h;g>p||(m?(i===void 0||i(r))&&c.push(r<<1|1,g):c.push(r<<1,g))}}return c.clear(),f}};function WF(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 GF(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;KF(e,t,n,d,f)}o.push(i,f,f+1,r)}}function KF(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 qF(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^(i>>1^r&a>>1),l=a^(n&i>>1^a>>1);return n=o&o>>2^s&s>>2,r=o&s>>2^s&(o^s)>>2,i=c^(o&c>>2^s&l>>2),a=l^(s&c>>2^(o^s)&l>>2),o=n&n>>4^r&r>>4,s=n&r>>4^r&(n^r)>>4,c=i^(n&i>>4^r&a>>4),l=a^(r&i>>4^(n^r)&a>>4),i=c^(o&c>>8^s&l>>8),a=l^(s&c>>8^(o^s)&l>>8),i^=i>>1,a^=a>>1,n=e^t,r=a|65535^(n|i),n=(n|n<<8)&16711935,n=(n|n<<4)&252645135,n=(n|n<<2)&858993459,n=(n|n<<1)&1431655765,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,((r<<1|n)>>>0)-2147483648}var JF=(e,t,n=1e-9)=>{if(e.boundingBox.isOut(t.boundingBox))return O({intersections:[],commonSegments:[],commonSegmentsPoints:[]});let r=dT(),i,a;try{let o=r.intersectCurves2d(e.wrapped,t.wrapped,n);i=o.points,a=o.segments.map(e=>new dF(e))}catch(e){return k(I(`INTERSECTION_FAILED`,`Intersections failed between curves`,e))}let o=a.filter(e=>OP(e.firstPoint,e.lastPoint,n)).map(e=>e.firstPoint);o.length&&(i.push(...o),a=a.filter(e=>!OP(e.firstPoint,e.lastPoint,n)));let s=a.flatMap(e=>[e.firstPoint,e.lastPoint]);return O({intersections:i,commonSegments:a,commonSegmentsPoints:s})},YF=(e,t=1e-9)=>{let n=dT(),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(I(`SELF_INTERSECTION_FAILED`,`Self intersection failed`,e))}return O(r)},XF=(e,n,r)=>{let i=VP(AP(n,e)),a=[i[1],-i[0]],o=[t(a,0)*r,t(a,1)*r];return{firstPoint:kP(e,o),lastPoint:kP(n,o)}},ZF=(e,t)=>{let n=e.geomType,r=dT();if(n===`CIRCLE`){let n=r.getCurve2dCircleData(e.wrapped);if(!n)return hF(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]=VP(AP(e,t));return kP(e,[c*n,c*r])};return{collapsed:!0,firstPoint:n(e.firstPoint),lastPoint:n(e.lastPoint)}}let u=new dF(r.makeCircle2d(i,a,l,s)),d;try{d=r.trimCurve2d(u.wrapped,e.firstParameter,e.lastParameter)}finally{u.delete()}return new dF(d)}if(n===`LINE`){let{firstPoint:n,lastPoint:r}=XF(e.firstPoint,e.lastPoint,t);return hF(n,r)}let i=new dF(r.offsetCurve2d(e.wrapped,t)),a=fF(i);if(i.delete(),j(YF(a)).length){let e=a.firstPoint,t=a.lastPoint;return a.delete(),{collapsed:!0,firstPoint:e,lastPoint:t}}return a};function QF(e,n,r){let i=PP(e.tangentAt(1),n.tangentAt(0));if(Math.abs(i)<1e-10)return null;let a=Math.abs(r)*(i>0?-1:1),o=ZF(e,a),s=ZF(n,a);if(!(o instanceof dF)||!(s instanceof dF))return null;let c=JF(o,s,1e-9);if(!Na(c))return null;let l=c.value.intersections.at(-1);if(!nF(l))return null;let u=l,d=(e,t)=>{let[n,r]=t.tangentAt(u),i=kP(u,jP(VP([-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 $F(e,t,n){let r=QF(e,t,n);if(!r)return[e,t];let{first:i,second:a,center:o}=r;return[i,CF(i.lastPoint,a.firstPoint,o),a]}function eI(e,t,n){let r=QF(e,t,n);if(!r)return[e,t];let{first:i,second:a}=r;return[i,hF(i.lastPoint,a.firstPoint),a]}function tI(e,n,r){let i=PP(VP(e.tangentAt(1)),VP(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=ZF(e,s),l=ZF(n,s);if(!(c instanceof dF)||!(l instanceof dF))return[e,n];let u=JF(c,l,1e-9);if(!Na(u))return[e,n];let d=u.value.intersections.at(-1);if(!nF(d))return[e,n];let f=vF(r,d),p=j(JF(e,f)).intersections[0],m=j(JF(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[_,gF(_.lastPoint,e.lastPoint,v.firstPoint),v]}catch{return[e,n]}}var nI=class e{blueprints;_boundingBox;constructor(e){this.blueprints=e,this._boundingBox=null}get repr(){return[`Blueprints`,...this.blueprints.map(e=>e.repr)].join(`
|
|
20
20
|
`)}clone(){return new e(this.blueprints.map(e=>e.clone()))}get boundingBox(){if(!this._boundingBox){let e=new lF;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 IF(this.boundingBox,e)}toSVGPaths(){return this.blueprints.map(e=>e.toSVGPaths())}toSVG(e=1){return LF(this.blueprints.map(e=>e instanceof zF?e.toSVGPath():e.toSVGGroup()).join(`
|
|
21
21
|
`),this.boundingBox,e)}},rI=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 lF;this.blueprints.forEach(t=>{e.add(t.boundingBox)}),this._boundingBox=e}return this._boundingBox}get repr(){return[`Compound Blueprints`,`-- Outline`,Fk(this.blueprints).repr,`-- Holes`,...this.blueprints.slice(1).map(e=>e.repr)].join(`
|
|
22
|
-
`)}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 Fk(this.blueprints).punchHole(e,t,n)}toSVGViewBox(e=1){return IF(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 LF(this.toSVGGroup(),this.boundingBox,e)}},iI=e=>{if(e.length===0)return[];if(e.length===1)return[[go(e,0,`groupByBoundingBoxOverlap`)]];let t=new UF(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(go(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(go(e,n,`groupByBoundingBoxOverlap`)),t.length&&t.forEach(e=>{i[e]=a})}),r},aI=e=>e.map((t,n)=>{let r=go(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))}}),oI=(e,t)=>e.flatMap(({blueprint:e})=>cI(t.filter(({blueprint:t,isIn:n})=>t===e||n.indexOf(e)!==-1))),sI=(e,t)=>[t.filter(({isIn:e})=>e.length<=1),...cI(aI(e.map(({blueprint:e})=>e)))],cI=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?oI(t,e):sI(n,e)},lI=e=>new nI(iI(e).map(aI).flatMap(cI).map(e=>e.length===1?go(e,0,`organiseBlueprints`).blueprint:(e.sort((e,t)=>e.isIn.length-t.isIn.length),new rI(e.map(({blueprint:e})=>e))))),uI=e=>e===`symmetric`||typeof e==`number`||Array.isArray(e)&&e.length===2,dI=e=>{let t;t=e?uI(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`?zP(1,n*iD):n;let s;return s=typeof a==`number`?zP(1,a*iD):a,{endTangent:o,startFactor:r,endFactor:i,startTangent:s}};function fI(e,t,n){return e<t?{majorRadius:t,minorRadius:e,rotationAngle:n+90}:{majorRadius:e,minorRadius:t,rotationAngle:n}}function pI(e,t,n,r,i,a,o,s){let c=i*iD,l=e=>MP(s(e)),u=l(zP(n,c)),d=l(zP(r,c+Math.PI/2)),f=VP(s(LP([1,0],c))),[,p]=BP(f),{cx:m,cy:h,startAngle:g,endAngle:_,clockwise:v,rx:y,ry:b}=gI(e,t,u,d,p,a,o),x=bF(y,b,v?g:_,v?_:g,[m,h],f);return v||x.reverse(),x}function mI(e,t,n,r,i){let a=Math.PI*2,o=hI(1,0,e,t),s=hI(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 hI(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 gI([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}=mI(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 _I={chamfer:eI,dogbone:tI,fillet:$F};function vI(e,t){if(typeof e==`function`)return e;let n=_I[t];return(t,r)=>n(t,r,e)}var yI=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)*aD}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=hF(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(zP(e,t*iD))}polarLine(e,t){let[n,r]=zP(e,t*iD);return this.line(n,r)}tangentLine(e){let t=this._requireLastCurve(`Sketcher2d.tangentLine`,`sketch a tangent line`),n=VP(this._convertFromUV(t.tangentAt(1)));return this.line(n[0]*e,n[1]*e)}threePointsArcTo(e,t){let n=gF(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=gF(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=MP(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=_F(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}=fI(t,n,r),l=pI(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=IP(e,this.pointer),i=MP(e,this.pointer);return this.ellipseTo(e,i/2,t,r*aD,!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=xF(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}=dI(t),o=this._lastCurve(),s=MP(this.pointer,e)*.25,c;c=r||(o?this._convertFromUV(o.tangentAt(1)):[1,0]),c=VP(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=VP(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=vI(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(...vI(e,t)(n,r))}_closeSketch(){OP(this.pointer,this.firstPoint)||this.lineTo(this.firstPoint)}_closeWithMirror(){OP(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 dF(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}},bI=class extends yI{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new zF(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()}},xI=2*Math.PI;function SI(e){let t=e%xI,n=t<0?t+xI:t;return n<Math.PI?n:n===Math.PI?0:Math.abs(n-xI)}function CI(e){return e.curves.map((t,n)=>({firstCurve:t,secondCurve:Pk(e.curves,(n+1)%e.curves.length),point:t.lastPoint}))}function wI(e){let t=t=>wI([...e,t]),n=t=>e.every(e=>e(t));return{shouldKeep:n,when:e=>t(e),inList:e=>t(t=>e.some(e=>OP(e,t.point))),atDistance:(e,n=[0,0])=>t(t=>Math.abs(MP(n,t.point)-e)<1e-9),atPoint:e=>t(t=>OP(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(SI(FP(n,r))-SI(iD*e))<1e-9}),not:e=>{let n=e(wI([]));return t(e=>!n.shouldKeep(e))},either:e=>{let n=e.map(e=>e(wI([])));return t(e=>n.some(t=>t.shouldKeep(e)))},find:e=>CI(e).filter(n)}}function TI(){return wI([])}var EI=(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=Ik(r),a=new bI().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()},DI=(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 bI([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()},OI=(e,t)=>OP(e,t,TP);function kI(e){return`${e[0].toFixed(9)},${e[1].toFixed(9)}`}function AI(e,t){let n=kI(e),r=kI(t);return n<r?`${n}|${r}`:`${r}|${n}`}function jI(e){let t=e[0];return t===void 0&&M(`startOfSegment`,`empty segment`),t.firstPoint}function MI(e){let t=e[e.length-1];return t===void 0&&M(`endOfSegment`,`empty segment`),t.lastPoint}function NI(e){return[...e].reverse().map(e=>{let t=e.clone();return t.reverse(),t})}function PI(e){return[...e].reverse().map(NI)}function FI(e){let t=(e.lastParameter+e.firstParameter)/2;return e.value(t)}function II(e,t){let n=kI(t);for(let r=0;r<e.length;r++){let i=e[r];if(i!==void 0&&kI(i.firstPoint)===n&&OI(t,i.firstPoint))return r}for(let n=0;n<e.length;n++){let r=e[n];if(r!==void 0&&OI(t,r.firstPoint))return n}return-1}function LI(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i];if(a!==void 0&&kI(a.firstPoint)===t&&kI(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 RI(e,t){return t<=0?e:e.slice(t).concat(e.slice(0,t))}function zI(e,t){return RI(e,II(e,t))}function BI(e,t){let n=kI(t.firstPoint),r=kI(t.lastPoint),i=e=>OI(t.firstPoint,e.firstPoint)&&OI(t.lastPoint,e.lastPoint),a=e=>OI(t.lastPoint,e.firstPoint)&&OI(t.firstPoint,e.lastPoint);function o(e,t,n,r){let i=LI(e,t,n,r);return i===-1?null:RI(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=NI(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*VI(e,t,n){let r=new Set(t.map(kI)),i=new Set(n.map(e=>AI(e.firstPoint,e.lastPoint))),a=e=>r.has(kI(e))?!0:t.some(t=>OI(t,e)),o=(e,t)=>i.has(AI(e,t))?!0:n.some(n=>OI(n.firstPoint,e)&&OI(n.lastPoint,t)||OI(n.firstPoint,t)&&OI(n.lastPoint,e)),s=[];for(let t of e){if(OI(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 HI(e,t,n){return e.filter(e=>{let r=t.filter(t=>OI(t.firstPoint,e)||OI(t.lastPoint,e)),i=r.length%2?r.filter(t=>!(OI(t.firstPoint,e)&&OI(t.lastPoint,e))):r;if(i.length===0||i.length%2)return!1;let a=i.map(e=>n.isInside(FI(e)));return!(a.every(Boolean)||a.every(e=>!e))})}function UI(e,n){let r=[],i=[],a=e.curves.map(()=>[]),o=n.curves.map(()=>[]),s=new UF(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(JF(e,t(n.curves,s),TP/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:cF(r,TP),allCommonSegments:i,firstCurvePoints:a,secondCurvePoints:o}}function WI(e,t){return Rk([e,t]).flatMap(([e,t])=>t.length===0?[e]:e.splitAt(t,TP/100))}function GI(e,t,n){return e.some(([e,r])=>e===void 0||r===void 0?!1:OI(e,t)&&OI(r,n)||OI(e,n)&&OI(r,t))}function KI(e,t){let{allIntersections:n,allCommonSegments:r,firstCurvePoints:i,secondCurvePoints:a}=UI(e,t);if(n.length<=1)return null;let o=WI(e.curves,i),s=WI(t.curves,a),c=r.map(e=>[e.firstPoint,e.lastPoint]),l=HI(HI(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=zI(o,e),s=zI(s,e)}else{let e=r[0];if(e===void 0)return null;o=BI(o,e),s=BI(s,e)}let u=Array.from(VI(o,l,r)),d=Array.from(VI(s,l,r)),f=u[0],p=d[0];if(f!==void 0&&p!==void 0){let e=!OI(MI(p),MI(f)),t=r.length>0&&p.length!==1;(e||t)&&(d=PI(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}GI(c,jI(t),MI(t))?h.push([t,`same`]):h.push([t,n])}return h}function qI(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`||!OI(a,n.firstPoint))break;let r=AP(a,i.firstPoint),s=AP(n.lastPoint,n.firstPoint);if(Math.abs(PP(r,s))>1e-9)break;a=n.lastPoint,o++}o>r+1?n.push(hF(i.firstPoint,a)):n.push(i),r=o}return n}function JI(e){let t=e.map(e=>e.firstPoint),n=e.map(e=>e.lastPoint),r=Rk([t,n.slice(-1).concat(n.slice(0,-1))]).map(([e,t],n)=>e===void 0||t===void 0||OI(e,t)?null:n).filter(e=>e!==null);if(r.length===0)return[e];let i=Rk([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 YI(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 XI(e,t,n,r,i,a,o){let s=[],c=0,l=e[0];if(l!==void 0){let t=FI(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=FI(u),r=n.isInside(e);if(i.secondInside===`keep`&&r||i.secondInside===`remove`&&!r){let e=t;c===1&&(e=NI(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 ZI(e,t,n){let r=KI(e,t);if(r===null)return QI(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=YI(r,i,a);return i=e.segmentsIn,a=e.lastWasSame,e.curves}let s=XI(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=JI(qI(o)).filter(e=>e.length>0).map(e=>new zF(e));if(c.length===0)return null;if(c.length===1){let e=c[0];return e===void 0?null:e}return lI(c)}function QI(e,t){let n=e.curves[0],r=t.curves[0];return{identical:!1,firstCurveInSecond:n!==void 0&&t.isInside(FI(n)),secondCurveInFirst:r!==void 0&&e.isInside(FI(r))}}function $I(e,t){let n=ZI(e,t,{firstInside:`remove`,secondInside:`remove`});return n===null||n instanceof zF||n instanceof nI?n:n.identical?e.clone():n.firstCurveInSecond?t.clone():n.secondCurveInFirst?e.clone():new nI([e,t])}function eL(e,t){let n=ZI(e,t,{firstInside:`remove`,secondInside:`keep`});return n===null||n instanceof zF||n instanceof nI?n:n.identical||n.firstCurveInSecond?null:n.secondCurveInFirst?new nI([new rI([e,t])]):e.clone()}function tL(e,t){let n=ZI(e,t,{firstInside:`keep`,secondInside:`keep`});return n===null||n instanceof zF||n instanceof nI?n:n.identical||n.firstCurveInSecond?e.clone():n.secondCurveInFirst?t.clone():null}var nL=(e,t)=>{if(e instanceof zF&&t instanceof zF){let n=[];return e.curves.forEach(e=>{t.curves.forEach(t=>{let{intersections:r,commonSegmentsPoints:i}=j(JF(e,t));n.push(...r),n.push(...i)})}),n=cF(n),n.length>1}if(e instanceof rI||e instanceof nI)return e.blueprints.some(e=>nL(e,t));if(t instanceof rI||t instanceof nI)return t.blueprints.some(t=>nL(e,t));M(`genericIntersects`,`Unhandled shape combination in genericIntersects`)},rL=(e,t)=>{if(e instanceof rI){if(t instanceof zF)return oL(t,e);if(t instanceof rI)return cL(e,t)}if(t instanceof rI){if(e instanceof zF)return oL(e,t);if(e instanceof rI)return cL(e,t)}if(e instanceof zF&&t instanceof zF)return $I(e,t);M(`genericFuse`,`Unhandled shape combination in genericFuse`)},iL=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)||!nL(r,s))return;let l;if(r instanceof nI||s instanceof nI){let e=lL(r,s);e===null&&M(`fuseIntersectingBlueprints`,`fuse2D returned null for non-null inputs`),l=e}else l=rL(r,s);if(!(l instanceof zF||l instanceof rI)){if(l instanceof nI&&l.blueprints.length===2)return;l instanceof nI&&l.blueprints.length===1?l=go(l.blueprints,0,`fuseIntersectingBlueprints`):l instanceof nI||M(`fuseIntersectingBlueprints`,`Fuse produced unexpected non-blueprint result`)}a.fusedWith.add(o),a.current=l,c||t.set(o,a)})}),lI(n.map(({current:e})=>e).flatMap(e=>aL(e)))},aL=e=>e instanceof zF?[e]:e instanceof rI?e.blueprints:e instanceof nI?e.blueprints.flatMap(e=>aL(e)):[],oL=(e,t)=>{let n=$I(e,go(t.blueprints,0,`fuseBlueprintWithCompound`)),r=t.blueprints.slice(1).map(t=>eL(t,e));return lI([...aL(n),...r.flatMap(e=>aL(e))])};function sL(e,t){let n=[];for(let r of e)for(let e of t)n.push([r,e]);return n}var cL=(e,t)=>{let n=go(e.blueprints,0,`fuseCompoundWithCompound`),r=go(t.blueprints,0,`fuseCompoundWithCompound`),i=$I(n,r),a=t.blueprints.slice(1).map(e=>eL(e,n)),o=e.blueprints.slice(1).map(e=>eL(e,r)),s=sL(e.blueprints.slice(1),t.blueprints.slice(1)).flatMap(([e,t])=>aL(tL(e,t)));return lI([...aL(i),...a.flatMap(e=>aL(e)),...o.flatMap(e=>aL(e)),...s])},lL=(e,t)=>{if(e===null)return t?.clone()??null;if(t===null)return e.clone();if(!(e instanceof nI)&&t instanceof nI)return iL([e,...t.blueprints]);if(!(t instanceof nI)&&e instanceof nI)return iL([t,...e.blueprints]);if(e instanceof nI&&t instanceof nI){let n=lL(go(e.blueprints,0,`fuse2D`),t);return e.blueprints.slice(1).forEach(e=>{n=lL(e,n)}),n}if(e instanceof rI){if(t instanceof nI)return lL(t,e);if(t instanceof zF)return oL(t,e);if(t instanceof rI)return cL(e,t)}if(t instanceof rI){if(e instanceof nI)return lL(e,t);if(e instanceof zF)return oL(e,t);if(e instanceof rI)return cL(e,t)}return e instanceof zF&&t instanceof zF?$I(e,t):null},uL=e=>{let t=e.flatMap(e=>e===null?[]:e instanceof nI?e.blueprints:e);return t.length===1?go(t,0,`mergeNonIntersecting`):new nI(t)},dL=(e,t)=>{if(e===null)return null;if(t===null)return e.clone();if(e instanceof nI)return uL(e.blueprints.map(e=>dL(e,t)));if(e instanceof rI){let n=go(e.blueprints,0,`cut2D`);if(t instanceof zF&&!t.intersects(n))return n.isInside(t.firstPoint)?lI([n,...aL(lL(t,new nI(e.blueprints.slice(1))))]):e.clone();{let r=dL(n,t);return e.blueprints.slice(1).forEach(e=>{r=dL(r,e)}),r}}if(t instanceof nI){let n=e;for(let e of t.blueprints)n=dL(n,e);return n}if(t instanceof rI){let n=eL(e,go(t.blueprints,0,`cut2D`));return t.blueprints.slice(1).forEach(t=>{n=lL(n,tL(t,e))}),n}return eL(e,t)};function fL(e,t){if(e===null||t===null)return null;if(e instanceof zF&&t instanceof zF)return tL(e,t);if(e instanceof nI)return uL(e.blueprints.map(e=>fL(e,t)));if(e instanceof rI){let n=go(e.blueprints,0,`intersect2D`),r=e.blueprints.slice(1);if(r.length===0)return fL(n,t);let i=fL(n,t);for(let e of r)i=dL(i,e);return i}if(t instanceof nI)return uL(t.blueprints.map(t=>fL(e,t)));if(t instanceof rI){let n=go(t.blueprints,0,`intersect2D`),r=t.blueprints.slice(1);if(r.length===0)return fL(n,e);let i=fL(n,e);for(let e of r)i=dL(i,e);return i}M(`intersect2D`,`Unhandled Shape2D combination`)}var pL=e(((e,t)=>{t.exports={}}));
|
|
22
|
+
`)}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 Fk(this.blueprints).punchHole(e,t,n)}toSVGViewBox(e=1){return IF(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 LF(this.toSVGGroup(),this.boundingBox,e)}},iI=e=>{if(e.length===0)return[];if(e.length===1)return[[ho(e,0,`groupByBoundingBoxOverlap`)]];let t=new UF(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(ho(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(ho(e,n,`groupByBoundingBoxOverlap`)),t.length&&t.forEach(e=>{i[e]=a})}),r},aI=e=>e.map((t,n)=>{let r=ho(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))}}),oI=(e,t)=>e.flatMap(({blueprint:e})=>cI(t.filter(({blueprint:t,isIn:n})=>t===e||n.indexOf(e)!==-1))),sI=(e,t)=>[t.filter(({isIn:e})=>e.length<=1),...cI(aI(e.map(({blueprint:e})=>e)))],cI=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?oI(t,e):sI(n,e)},lI=e=>new nI(iI(e).map(aI).flatMap(cI).map(e=>e.length===1?ho(e,0,`organiseBlueprints`).blueprint:(e.sort((e,t)=>e.isIn.length-t.isIn.length),new rI(e.map(({blueprint:e})=>e))))),uI=e=>e===`symmetric`||typeof e==`number`||Array.isArray(e)&&e.length===2,dI=e=>{let t;t=e?uI(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`?zP(1,n*iD):n;let s;return s=typeof a==`number`?zP(1,a*iD):a,{endTangent:o,startFactor:r,endFactor:i,startTangent:s}};function fI(e,t,n){return e<t?{majorRadius:t,minorRadius:e,rotationAngle:n+90}:{majorRadius:e,minorRadius:t,rotationAngle:n}}function pI(e,t,n,r,i,a,o,s){let c=i*iD,l=e=>MP(s(e)),u=l(zP(n,c)),d=l(zP(r,c+Math.PI/2)),f=VP(s(LP([1,0],c))),[,p]=BP(f),{cx:m,cy:h,startAngle:g,endAngle:_,clockwise:v,rx:y,ry:b}=gI(e,t,u,d,p,a,o),x=bF(y,b,v?g:_,v?_:g,[m,h],f);return v||x.reverse(),x}function mI(e,t,n,r,i){let a=Math.PI*2,o=hI(1,0,e,t),s=hI(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 hI(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 gI([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}=mI(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 _I={chamfer:eI,dogbone:tI,fillet:$F};function vI(e,t){if(typeof e==`function`)return e;let n=_I[t];return(t,r)=>n(t,r,e)}var yI=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)*aD}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=hF(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(zP(e,t*iD))}polarLine(e,t){let[n,r]=zP(e,t*iD);return this.line(n,r)}tangentLine(e){let t=this._requireLastCurve(`Sketcher2d.tangentLine`,`sketch a tangent line`),n=VP(this._convertFromUV(t.tangentAt(1)));return this.line(n[0]*e,n[1]*e)}threePointsArcTo(e,t){let n=gF(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=gF(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=MP(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=_F(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}=fI(t,n,r),l=pI(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=IP(e,this.pointer),i=MP(e,this.pointer);return this.ellipseTo(e,i/2,t,r*aD,!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=xF(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}=dI(t),o=this._lastCurve(),s=MP(this.pointer,e)*.25,c;c=r||(o?this._convertFromUV(o.tangentAt(1)):[1,0]),c=VP(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=VP(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=vI(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(...vI(e,t)(n,r))}_closeSketch(){OP(this.pointer,this.firstPoint)||this.lineTo(this.firstPoint)}_closeWithMirror(){OP(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 dF(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}},bI=class extends yI{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new zF(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()}},xI=2*Math.PI;function SI(e){let t=e%xI,n=t<0?t+xI:t;return n<Math.PI?n:n===Math.PI?0:Math.abs(n-xI)}function CI(e){return e.curves.map((t,n)=>({firstCurve:t,secondCurve:Pk(e.curves,(n+1)%e.curves.length),point:t.lastPoint}))}function wI(e){let t=t=>wI([...e,t]),n=t=>e.every(e=>e(t));return{shouldKeep:n,when:e=>t(e),inList:e=>t(t=>e.some(e=>OP(e,t.point))),atDistance:(e,n=[0,0])=>t(t=>Math.abs(MP(n,t.point)-e)<1e-9),atPoint:e=>t(t=>OP(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(SI(FP(n,r))-SI(iD*e))<1e-9}),not:e=>{let n=e(wI([]));return t(e=>!n.shouldKeep(e))},either:e=>{let n=e.map(e=>e(wI([])));return t(e=>n.some(t=>t.shouldKeep(e)))},find:e=>CI(e).filter(n)}}function TI(){return wI([])}var EI=(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=Ik(r),a=new bI().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()},DI=(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 bI([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()},OI=(e,t)=>OP(e,t,TP);function kI(e){return`${e[0].toFixed(9)},${e[1].toFixed(9)}`}function AI(e,t){let n=kI(e),r=kI(t);return n<r?`${n}|${r}`:`${r}|${n}`}function jI(e){let t=e[0];return t===void 0&&M(`startOfSegment`,`empty segment`),t.firstPoint}function MI(e){let t=e[e.length-1];return t===void 0&&M(`endOfSegment`,`empty segment`),t.lastPoint}function NI(e){return[...e].reverse().map(e=>{let t=e.clone();return t.reverse(),t})}function PI(e){return[...e].reverse().map(NI)}function FI(e){let t=(e.lastParameter+e.firstParameter)/2;return e.value(t)}function II(e,t){let n=kI(t);for(let r=0;r<e.length;r++){let i=e[r];if(i!==void 0&&kI(i.firstPoint)===n&&OI(t,i.firstPoint))return r}for(let n=0;n<e.length;n++){let r=e[n];if(r!==void 0&&OI(t,r.firstPoint))return n}return-1}function LI(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i];if(a!==void 0&&kI(a.firstPoint)===t&&kI(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 RI(e,t){return t<=0?e:e.slice(t).concat(e.slice(0,t))}function zI(e,t){return RI(e,II(e,t))}function BI(e,t){let n=kI(t.firstPoint),r=kI(t.lastPoint),i=e=>OI(t.firstPoint,e.firstPoint)&&OI(t.lastPoint,e.lastPoint),a=e=>OI(t.lastPoint,e.firstPoint)&&OI(t.firstPoint,e.lastPoint);function o(e,t,n,r){let i=LI(e,t,n,r);return i===-1?null:RI(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=NI(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*VI(e,t,n){let r=new Set(t.map(kI)),i=new Set(n.map(e=>AI(e.firstPoint,e.lastPoint))),a=e=>r.has(kI(e))?!0:t.some(t=>OI(t,e)),o=(e,t)=>i.has(AI(e,t))?!0:n.some(n=>OI(n.firstPoint,e)&&OI(n.lastPoint,t)||OI(n.firstPoint,t)&&OI(n.lastPoint,e)),s=[];for(let t of e){if(OI(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 HI(e,t,n){return e.filter(e=>{let r=t.filter(t=>OI(t.firstPoint,e)||OI(t.lastPoint,e)),i=r.length%2?r.filter(t=>!(OI(t.firstPoint,e)&&OI(t.lastPoint,e))):r;if(i.length===0||i.length%2)return!1;let a=i.map(e=>n.isInside(FI(e)));return!(a.every(Boolean)||a.every(e=>!e))})}function UI(e,n){let r=[],i=[],a=e.curves.map(()=>[]),o=n.curves.map(()=>[]),s=new UF(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(JF(e,t(n.curves,s),TP/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:cF(r,TP),allCommonSegments:i,firstCurvePoints:a,secondCurvePoints:o}}function WI(e,t){return Rk([e,t]).flatMap(([e,t])=>t.length===0?[e]:e.splitAt(t,TP/100))}function GI(e,t,n){return e.some(([e,r])=>e===void 0||r===void 0?!1:OI(e,t)&&OI(r,n)||OI(e,n)&&OI(r,t))}function KI(e,t){let{allIntersections:n,allCommonSegments:r,firstCurvePoints:i,secondCurvePoints:a}=UI(e,t);if(n.length<=1)return null;let o=WI(e.curves,i),s=WI(t.curves,a),c=r.map(e=>[e.firstPoint,e.lastPoint]),l=HI(HI(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=zI(o,e),s=zI(s,e)}else{let e=r[0];if(e===void 0)return null;o=BI(o,e),s=BI(s,e)}let u=Array.from(VI(o,l,r)),d=Array.from(VI(s,l,r)),f=u[0],p=d[0];if(f!==void 0&&p!==void 0){let e=!OI(MI(p),MI(f)),t=r.length>0&&p.length!==1;(e||t)&&(d=PI(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}GI(c,jI(t),MI(t))?h.push([t,`same`]):h.push([t,n])}return h}function qI(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`||!OI(a,n.firstPoint))break;let r=AP(a,i.firstPoint),s=AP(n.lastPoint,n.firstPoint);if(Math.abs(PP(r,s))>1e-9)break;a=n.lastPoint,o++}o>r+1?n.push(hF(i.firstPoint,a)):n.push(i),r=o}return n}function JI(e){let t=e.map(e=>e.firstPoint),n=e.map(e=>e.lastPoint),r=Rk([t,n.slice(-1).concat(n.slice(0,-1))]).map(([e,t],n)=>e===void 0||t===void 0||OI(e,t)?null:n).filter(e=>e!==null);if(r.length===0)return[e];let i=Rk([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 YI(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 XI(e,t,n,r,i,a,o){let s=[],c=0,l=e[0];if(l!==void 0){let t=FI(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=FI(u),r=n.isInside(e);if(i.secondInside===`keep`&&r||i.secondInside===`remove`&&!r){let e=t;c===1&&(e=NI(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 ZI(e,t,n){let r=KI(e,t);if(r===null)return QI(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=YI(r,i,a);return i=e.segmentsIn,a=e.lastWasSame,e.curves}let s=XI(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=JI(qI(o)).filter(e=>e.length>0).map(e=>new zF(e));if(c.length===0)return null;if(c.length===1){let e=c[0];return e===void 0?null:e}return lI(c)}function QI(e,t){let n=e.curves[0],r=t.curves[0];return{identical:!1,firstCurveInSecond:n!==void 0&&t.isInside(FI(n)),secondCurveInFirst:r!==void 0&&e.isInside(FI(r))}}function $I(e,t){let n=ZI(e,t,{firstInside:`remove`,secondInside:`remove`});return n===null||n instanceof zF||n instanceof nI?n:n.identical?e.clone():n.firstCurveInSecond?t.clone():n.secondCurveInFirst?e.clone():new nI([e,t])}function eL(e,t){let n=ZI(e,t,{firstInside:`remove`,secondInside:`keep`});return n===null||n instanceof zF||n instanceof nI?n:n.identical||n.firstCurveInSecond?null:n.secondCurveInFirst?new nI([new rI([e,t])]):e.clone()}function tL(e,t){let n=ZI(e,t,{firstInside:`keep`,secondInside:`keep`});return n===null||n instanceof zF||n instanceof nI?n:n.identical||n.firstCurveInSecond?e.clone():n.secondCurveInFirst?t.clone():null}var nL=(e,t)=>{if(e instanceof zF&&t instanceof zF){let n=[];return e.curves.forEach(e=>{t.curves.forEach(t=>{let{intersections:r,commonSegmentsPoints:i}=j(JF(e,t));n.push(...r),n.push(...i)})}),n=cF(n),n.length>1}if(e instanceof rI||e instanceof nI)return e.blueprints.some(e=>nL(e,t));if(t instanceof rI||t instanceof nI)return t.blueprints.some(t=>nL(e,t));M(`genericIntersects`,`Unhandled shape combination in genericIntersects`)},rL=(e,t)=>{if(e instanceof rI){if(t instanceof zF)return oL(t,e);if(t instanceof rI)return cL(e,t)}if(t instanceof rI){if(e instanceof zF)return oL(e,t);if(e instanceof rI)return cL(e,t)}if(e instanceof zF&&t instanceof zF)return $I(e,t);M(`genericFuse`,`Unhandled shape combination in genericFuse`)},iL=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)||!nL(r,s))return;let l;if(r instanceof nI||s instanceof nI){let e=lL(r,s);e===null&&M(`fuseIntersectingBlueprints`,`fuse2D returned null for non-null inputs`),l=e}else l=rL(r,s);if(!(l instanceof zF||l instanceof rI)){if(l instanceof nI&&l.blueprints.length===2)return;l instanceof nI&&l.blueprints.length===1?l=ho(l.blueprints,0,`fuseIntersectingBlueprints`):l instanceof nI||M(`fuseIntersectingBlueprints`,`Fuse produced unexpected non-blueprint result`)}a.fusedWith.add(o),a.current=l,c||t.set(o,a)})}),lI(n.map(({current:e})=>e).flatMap(e=>aL(e)))},aL=e=>e instanceof zF?[e]:e instanceof rI?e.blueprints:e instanceof nI?e.blueprints.flatMap(e=>aL(e)):[],oL=(e,t)=>{let n=$I(e,ho(t.blueprints,0,`fuseBlueprintWithCompound`)),r=t.blueprints.slice(1).map(t=>eL(t,e));return lI([...aL(n),...r.flatMap(e=>aL(e))])};function sL(e,t){let n=[];for(let r of e)for(let e of t)n.push([r,e]);return n}var cL=(e,t)=>{let n=ho(e.blueprints,0,`fuseCompoundWithCompound`),r=ho(t.blueprints,0,`fuseCompoundWithCompound`),i=$I(n,r),a=t.blueprints.slice(1).map(e=>eL(e,n)),o=e.blueprints.slice(1).map(e=>eL(e,r)),s=sL(e.blueprints.slice(1),t.blueprints.slice(1)).flatMap(([e,t])=>aL(tL(e,t)));return lI([...aL(i),...a.flatMap(e=>aL(e)),...o.flatMap(e=>aL(e)),...s])},lL=(e,t)=>{if(e===null)return t?.clone()??null;if(t===null)return e.clone();if(!(e instanceof nI)&&t instanceof nI)return iL([e,...t.blueprints]);if(!(t instanceof nI)&&e instanceof nI)return iL([t,...e.blueprints]);if(e instanceof nI&&t instanceof nI){let n=lL(ho(e.blueprints,0,`fuse2D`),t);return e.blueprints.slice(1).forEach(e=>{n=lL(e,n)}),n}if(e instanceof rI){if(t instanceof nI)return lL(t,e);if(t instanceof zF)return oL(t,e);if(t instanceof rI)return cL(e,t)}if(t instanceof rI){if(e instanceof nI)return lL(e,t);if(e instanceof zF)return oL(e,t);if(e instanceof rI)return cL(e,t)}return e instanceof zF&&t instanceof zF?$I(e,t):null},uL=e=>{let t=e.flatMap(e=>e===null?[]:e instanceof nI?e.blueprints:e);return t.length===1?ho(t,0,`mergeNonIntersecting`):new nI(t)},dL=(e,t)=>{if(e===null)return null;if(t===null)return e.clone();if(e instanceof nI)return uL(e.blueprints.map(e=>dL(e,t)));if(e instanceof rI){let n=ho(e.blueprints,0,`cut2D`);if(t instanceof zF&&!t.intersects(n))return n.isInside(t.firstPoint)?lI([n,...aL(lL(t,new nI(e.blueprints.slice(1))))]):e.clone();{let r=dL(n,t);return e.blueprints.slice(1).forEach(e=>{r=dL(r,e)}),r}}if(t instanceof nI){let n=e;for(let e of t.blueprints)n=dL(n,e);return n}if(t instanceof rI){let n=eL(e,ho(t.blueprints,0,`cut2D`));return t.blueprints.slice(1).forEach(t=>{n=lL(n,tL(t,e))}),n}return eL(e,t)};function fL(e,t){if(e===null||t===null)return null;if(e instanceof zF&&t instanceof zF)return tL(e,t);if(e instanceof nI)return uL(e.blueprints.map(e=>fL(e,t)));if(e instanceof rI){let n=ho(e.blueprints,0,`intersect2D`),r=e.blueprints.slice(1);if(r.length===0)return fL(n,t);let i=fL(n,t);for(let e of r)i=dL(i,e);return i}if(t instanceof nI)return uL(t.blueprints.map(t=>fL(e,t)));if(t instanceof rI){let n=ho(t.blueprints,0,`intersect2D`),r=t.blueprints.slice(1);if(r.length===0)return fL(n,e);let i=fL(n,e);for(let e of r)i=dL(i,e);return i}M(`intersect2D`,`Unhandled Shape2D combination`)}var pL=e(((e,t)=>{t.exports={}}));
|
|
23
23
|
/*! https://mths.be/codepointat v0.2.0 by @mathias */
|
|
24
|
-
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 mL=0,hL=-3;function gL(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function _L(e,t){this.source=e,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=t,this.destLen=0,this.ltree=new gL,this.dtree=new gL}var vL=new gL,yL=new gL,bL=new Uint8Array(30),xL=new Uint16Array(30),SL=new Uint8Array(30),CL=new Uint16Array(30),wL=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),TL=new gL,EL=new Uint8Array(320);function DL(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 OL(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 kL=new Uint16Array(16);function AL(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)kL[i]=a,a+=e.table[i];for(i=0;i<r;++i)t[n+i]&&(e.trans[kL[t[n+i]]++]=i)}function jL(e){e.bitcount--||(e.tag=e.source[e.sourceIndex++],e.bitcount=7);var t=e.tag&1;return e.tag>>>=1,t}function ML(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 NL(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 PL(e,t,n){var r=ML(e,5,257),i=ML(e,5,1),a=ML(e,4,4),o,s,c;for(o=0;o<19;++o)EL[o]=0;for(o=0;o<a;++o){var l=ML(e,3,0);EL[wL[o]]=l}for(AL(TL,EL,0,19),s=0;s<r+i;){var u=NL(e,TL);switch(u){case 16:var d=EL[s-1];for(c=ML(e,2,3);c;--c)EL[s++]=d;break;case 17:for(c=ML(e,3,3);c;--c)EL[s++]=0;break;case 18:for(c=ML(e,7,11);c;--c)EL[s++]=0;break;default:EL[s++]=u;break}}AL(t,EL,0,r),AL(n,EL,r,i)}function FL(e,t,n){for(;;){var r=NL(e,t);if(r===256)return mL;if(r<256)e.dest[e.destLen++]=r;else{var i,a,o,s;for(r-=257,i=ML(e,bL[r],xL[r]),a=NL(e,n),o=e.destLen-ML(e,SL[a],CL[a]),s=o;s<o+i;++s)e.dest[e.destLen++]=e.dest[s]}}}function IL(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 hL;for(e.sourceIndex+=4,r=t;r;--r)e.dest[e.destLen++]=e.source[e.sourceIndex++];return e.bitcount=0,mL}function LL(e,t){var n=new _L(e,t),r,i,a;do{switch(r=jL(n),i=ML(n,2,0),i){case 0:a=IL(n);break;case 1:a=FL(n,vL,yL);break;case 2:PL(n,n.ltree,n.dtree),a=FL(n,n.ltree,n.dtree);break;default:a=hL}if(a!==mL)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}OL(vL,yL),DL(bL,xL,4,3),DL(SL,CL,2,1),bL[28]=0,xL[28]=258;var RL=LL;function zL(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 BL(){this.x1=NaN,this.y1=NaN,this.x2=NaN,this.y2=NaN}BL.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)},BL.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))},BL.prototype.addX=function(e){this.addPoint(e,null)},BL.prototype.addY=function(e){this.addPoint(null,e)},BL.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(zL(c[f],l[f],u[f],d[f],g)),f===1&&this.addY(zL(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(zL(c[f],l[f],u[f],d[f],v)),f===1&&this.addY(zL(c[f],l[f],u[f],d[f],v)));var y=(-p-Math.sqrt(_))/(2*m);0<y&&y<1&&(f===0&&this.addX(zL(c[f],l[f],u[f],d[f],y)),f===1&&this.addY(zL(c[f],l[f],u[f],d[f],y)))}}},BL.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 VL(){this.commands=[],this.fill=`black`,this.stroke=null,this.strokeWidth=1}VL.prototype.moveTo=function(e,t){this.commands.push({type:`M`,x:e,y:t})},VL.prototype.lineTo=function(e,t){this.commands.push({type:`L`,x:e,y:t})},VL.prototype.curveTo=VL.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})},VL.prototype.quadTo=VL.prototype.quadraticCurveTo=function(e,t,n,r){this.commands.push({type:`Q`,x1:e,y1:t,x:n,y:r})},VL.prototype.close=VL.prototype.closePath=function(){this.commands.push({type:`Z`})},VL.prototype.extend=function(e){if(e.commands)e=e.commands;else if(e instanceof BL){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)},VL.prototype.getBoundingBox=function(){for(var e=new BL,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},VL.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())},VL.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},VL.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},VL.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 HL(e){throw Error(e)}function UL(e,t){e||HL(t)}var K={fail:HL,argument:UL,assert:UL},WL=32768,GL=2147483648,KL={},q={},J={};function qL(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=qL(1),q.CHAR=function(e){return[e.charCodeAt(0)]},J.CHAR=qL(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=qL(2),q.SHORT=function(e){return e>=WL&&(e=-(2*WL-e)),[e>>8&255,e&255]},J.SHORT=qL(2),q.UINT24=function(e){return[e>>16&255,e>>8&255,e&255]},J.UINT24=qL(3),q.ULONG=function(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]},J.ULONG=qL(4),q.LONG=function(e){return e>=GL&&(e=-(2*GL-e)),[e>>24&255,e>>16&255,e>>8&255,e&255]},J.LONG=qL(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=qL(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=qL(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=qL(3),q.NUMBER32=function(e){return[29,e>>24&255,e>>16&255,e>>8&255,e&255]},J.NUMBER32=qL(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,KL.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)},KL.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 JL={"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ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ`};KL.MACSTRING=function(e,t,n,r){var i=JL[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 YL=typeof WeakMap==`function`&&new WeakMap,XL,ZL=function(e){if(!XL)for(var t in XL={},JL)XL[t]=new String(t);var n=XL[e];if(n!==void 0){if(YL){var r=YL.get(n);if(r!==void 0)return r}var i=JL[e];if(i!==void 0){for(var a={},o=0;o<i.length;o++)a[i.charCodeAt(o)]=o+128;return YL&&YL.set(n,a),a}}};q.MACSTRING=function(e,t){var n=ZL(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 QL(e){return e>=-128&&e<=127}function $L(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 eR(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(!QL(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 tR(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(o===0||QL(o)&&a+1<i&&QL(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?$L(e,t,n):r>=-128&&r<=127?eR(e,t,n):tR(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 nR=typeof WeakMap==`function`&&new WeakMap;q.CHARSTRING=function(e){if(nR){var t=nR.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 nR&&nR.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 rR(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)}}rR.prototype.encode=function(){return q.TABLE(this)},rR.prototype.sizeOf=function(){return J.TABLE(this)};function iR(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 aR(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 oR(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 sR(e){e.format===1?rR.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:1}].concat(iR(`glyph`,e.glyphs))):e.format===2?rR.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:2}].concat(oR(`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.`)}sR.prototype=Object.create(rR.prototype),sR.prototype.constructor=sR;function cR(e){rR.call(this,`scriptListTable`,oR(`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 rR(`scriptTable`,[{name:`defaultLangSys`,type:`TABLE`,value:new rR(`defaultLangSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:r.reqFeatureIndex}].concat(iR(`featureIndex`,r.featureIndexes)))}].concat(oR(`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 rR(`langSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:n.reqFeatureIndex}].concat(iR(`featureIndex`,n.featureIndexes)))}]})))}]}))}cR.prototype=Object.create(rR.prototype),cR.prototype.constructor=cR;function lR(e){rR.call(this,`featureListTable`,oR(`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 rR(`featureTable`,[{name:`featureParams`,type:`USHORT`,value:n.featureParams}].concat(iR(`lookupListIndex`,n.lookupListIndexes)))}]}))}lR.prototype=Object.create(rR.prototype),lR.prototype.constructor=lR;function uR(e,t){rR.call(this,`lookupListTable`,aR(`lookup`,e,function(e){var n=t[e.lookupType];return K.assert(!!n,`Unable to write GSUB lookup type `+e.lookupType+` tables.`),new rR(`lookupTable`,[{name:`lookupType`,type:`USHORT`,value:e.lookupType},{name:`lookupFlag`,type:`USHORT`,value:e.lookupFlag}].concat(aR(`subtable`,e.subtables,n)))}))}uR.prototype=Object.create(rR.prototype),uR.prototype.constructor=uR;var Y={Table:rR,Record:rR,Coverage:sR,ScriptList:cR,FeatureList:lR,LookupList:uR,ushortList:iR,tableList:aR,recordList:oR};function dR(e,t){return e.getUint8(t)}function fR(e,t){return e.getUint16(t,!1)}function pR(e,t){return e.getInt16(t,!1)}function mR(e,t){return e.getUint32(t,!1)}function hR(e,t){return e.getInt16(t,!1)+e.getUint16(t+2,!1)/65535}function gR(e,t){for(var n=``,r=t;r<t+4;r+=1)n+=String.fromCharCode(e.getInt8(r));return n}function _R(e,t,n){for(var r=0,i=0;i<n;i+=1)r<<=8,r+=e.getUint8(t+i);return r}function vR(e,t,n){for(var r=[],i=t;i<n;i+=1)r.push(e.getUint8(i));return r}function yR(e){for(var t=``,n=0;n<e.length;n+=1)t+=String.fromCharCode(e[n]);return t}var bR={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=mR(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,e},X.prototype.parseOffset32=X.prototype.parseULong,X.prototype.parseFixed=function(){var e=hR(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=mR(this.data,this.offset+this.relativeOffset+4);return e-=2082844800,this.relativeOffset+=8,e},X.prototype.parseVersion=function(e){var t=fR(this.data,this.offset+this.relativeOffset),n=fR(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+=bR[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 xR={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(xR),langSysRecords:X.recordList({tag:X.tag,langSys:X.pointer(xR)})})}))||[]},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:dR,getCard8:dR,getUShort:fR,getCard16:fR,getShort:pR,getULong:mR,getFixed:hR,getTag:gR,getOffset:_R,getBytes:vR,bytesToString:yR,Parser:X};function SR(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 CR(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 wR(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)SR(n,s);else if(n.format===4)CR(n,s,e,t,r);else throw Error(`Only format 4 and 12 cmap tables are supported (found format `+n.format+`).`);return n}function TR(e,t,n){e.segments.push({end:t,start:t,delta:-(t-n),offset:0,glyphIndex:n})}function ER(e){e.segments.push({end:65535,start:65535,delta:1,offset:0})}function DR(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)TR(i,a.unicodes[o],n);i.segments=i.segments.sort(function(e,t){return e.start-t.start})}ER(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 OR={parse:wR,make:DR},kR=`.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(`,`),AR=`................................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(`.`),jR=`................................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(`.`),MR=`.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 NR(e){this.font=e}NR.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 PR(e){this.cmap=e}PR.prototype.charToGlyphIndex=function(e){return this.cmap.glyphIndexMap[e.codePointAt(0)]||0};function FR(e,t){this.encoding=e,this.charset=t}FR.prototype.charToGlyphIndex=function(e){var t=e.codePointAt(0),n=this.encoding[t];return this.charset.indexOf(n)};function IR(e){switch(e.version){case 1:this.names=MR.slice();break;case 2:this.names=Array(e.numberOfGlyphs);for(var t=0;t<e.numberOfGlyphs;t++)e.glyphNameIndex[t]<MR.length?this.names[t]=MR[e.glyphNameIndex[t]]:this.names[t]=e.names[e.glyphNameIndex[t]-MR.length];break;case 2.5:this.names=Array(e.numberOfGlyphs);for(var n=0;n<e.numberOfGlyphs;n++)this.names[n]=MR[n+e.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}IR.prototype.nameToGlyphIndex=function(e){return this.names.indexOf(e)},IR.prototype.glyphIndexToName=function(e){return this.names[e]};function LR(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 RR(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 zR(e,t){t.lowMemory?RR(e):LR(e)}function BR(e,t,n,r,i){e.beginPath(),e.moveTo(t,n),e.lineTo(r,i),e.stroke()}var VR={line:BR};function HR(e,t){var n=t||new VL;return{configurable:!0,get:function(){return typeof n==`function`&&(n=n()),n},set:function(e){n=e}}}function UR(e){this.bindConstructorValues(e)}UR.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",HR(this,e.path))},UR.prototype.addUnicode=function(e){this.unicodes.length===0&&(this.unicode=e),this.unicodes.push(e)},UR.prototype.getBoundingBox=function(){return this.path.getBoundingBox()},UR.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 VL,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},UR.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},UR.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},UR.prototype.draw=function(e,t,n,r,i){this.getPath(t,n,r,i).draw(e)},UR.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)},UR.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`,VR.line(e,t,-1e4,t,1e4),VR.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`,VR.line(e,t+a*i,-1e4,t+a*i,1e4),VR.line(e,t+s*i,-1e4,t+s*i,1e4),VR.line(e,-1e4,n+-o*i,1e4,n+-o*i),VR.line(e,-1e4,n+-c*i,1e4,n+-c*i),e.strokeStyle=`green`,VR.line(e,t+l*i,-1e4,t+l*i,1e4)};function WR(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 GR(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}GR.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]},GR.prototype.push=function(e,t){this.glyphs[e]=t,this.length++};function KR(e,t){return new UR({index:t,font:e})}function qR(e,t,n,r,i,a){return function(){var o=new UR({index:t,font:e});return o.path=function(){n(o,r,i);var t=a(e.glyphs,o);return t.unitsPerEm=e.unitsPerEm,t},WR(o,`xMin`,`_xMin`),WR(o,`xMax`,`_xMax`),WR(o,`yMin`,`_yMin`),WR(o,`yMax`,`_yMax`),o}}function JR(e,t,n,r){return function(){var i=new UR({index:t,font:e});return i.path=function(){var t=n(e,i,r);return t.unitsPerEm=e.unitsPerEm,t},i}}var YR={GlyphSet:GR,glyphLoader:KR,ttfGlyphLoader:qR,cffGlyphLoader:JR};function XR(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(!XR(e[n],t[n]))return!1;return!0}else return!1}function ZR(e){return e.length<1240?107:e.length<33900?1131:32768}function QR(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 $R(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 ez(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 tz(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 nz(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 tz(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 rz(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 iz(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(nz(r,o))}return rz(i)}function az(e,t){return t=t<=390?kR[t]:e[t-391],t}function oz(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=az(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=az(n,i)),r[o.name]=i}return r}function sz(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 cz=[{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`}],lz=[{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 uz(e,t){return oz(iz(e,0,e.byteLength),cz,t)}function dz(e,t,n,r){return oz(iz(e,t,n),lz,r)}function fz(e,t,n,r){for(var i=[],a=0;a<n.length;a+=1){var o=uz(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=dz(e,c+t,s,r);o._defaultWidthX=l.defaultWidthX,o._nominalWidthX=l.nominalWidthX,l.subrs!==0&&(o._subrs=QR(e,c+l.subrs+t).objects,o._subrsBias=ZR(o._subrs)),o._privateDict=l}i.push(o)}return i}function pz(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(az(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(az(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(az(r,i)),i+=1}else throw Error(`Unknown charset format `+c);return s}function mz(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 FR(i,n)}function hz(e,t,n){var r,i,a,o,s=new VL,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 gz(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 _z(e,t,n,r){n.tables.cff={};var i=QR(e,QR(e,sz(e,t).endOffset,Z.bytesToString).endOffset),a=QR(e,i.endOffset,Z.bytesToString);n.gsubrs=QR(e,a.endOffset).objects,n.gsubrsBias=ZR(n.gsubrs);var o=fz(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=fz(e,t,QR(e,c).objects,a.objects);s._fdArray=u,l+=t,s._fdSelect=gz(e,l,n.numGlyphs,u.length)}var d=t+s.private[1],f=dz(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=QR(e,d+f.subrs).objects,n.subrsBias=ZR(n.subrs));var p;r.lowMemory?(p=$R(e,t+s.charStrings),n.nGlyphs=p.offsets.length):(p=QR(e,t+s.charStrings),n.nGlyphs=p.objects.length);var m=pz(e,t+s.charset,n.nGlyphs,a.objects);if(s.encoding===0?n.cffEncoding=new FR(AR,m):s.encoding===1?n.cffEncoding=new FR(jR,m):n.cffEncoding=mz(e,t+s.encoding,m),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new YR.GlyphSet(n),r.lowMemory)n._push=function(r){var i=ez(r,p.offsets,e,t+s.charStrings);n.glyphs.push(r,YR.cffGlyphLoader(n,r,hz,i))};else for(var h=0;h<n.nGlyphs;h+=1){var g=p.objects[h];n.glyphs.push(h,YR.cffGlyphLoader(n,h,hz,g))}}function vz(e,t){var n,r=kR.indexOf(e);return r>=0&&(n=r),r=t.indexOf(e),r>=0?n=r+kR.length:(n=kR.length+t.length,t.push(e)),n}function yz(){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 bz(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 xz(e,t,n){for(var r={},i=0;i<e.length;i+=1){var a=e[i],o=t[a.name];o!==void 0&&!XR(o,a.value)&&(a.type===`SID`&&(o=vz(o,n)),r[a.op]={name:a.name,type:a.type,value:o})}return r}function Sz(e,t){var n=new Y.Record(`Top DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=xz(cz,e,t),n}function Cz(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 wz(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 Tz(){return new Y.Record(`Global Subr INDEX`,[{name:`subrs`,type:`INDEX`,value:[]}])}function Ez(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=vz(i,t);n.fields.push({name:`glyph_`+r,type:`SID`,value:a})}return n}function Dz(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 Oz(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=Dz(r);t.charStrings.push({name:r.name,type:`CHARSTRING`,value:i})}return t}function kz(e,t){var n=new Y.Record(`Private DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=xz(lz,e,t),n}function Az(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=yz(),n.nameIndex=bz([t.postScriptName]);var u=Sz(i,l);return n.topDictIndex=Cz(u),n.globalSubrIndex=Tz(),n.charsets=Ez(o,l),n.charStringsIndex=Oz(e),n.privateDict=kz(a,l),n.stringIndex=wz(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=Sz(i,l),n.topDictIndex=Cz(u),n}var jz={parse:_z,make:Az};function Mz(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 Nz(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 Pz={parse:Mz,make:Nz};function Fz(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 Iz(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 Lz={parse:Fz,make:Iz};function Rz(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 zz(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 Bz(e,t,n,r,i,a,o){o.lowMemory?zz(e,t,n,r,i):Rz(t,n,r,i,a)}function Vz(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 Hz={parse:Bz,make:Vz};function Uz(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 Wz(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 Gz={make:Uz,parse:Wz};function Kz(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 qz(e){return new Y.Table(`maxp`,[{name:`version`,type:`FIXED`,value:20480},{name:`numGlyphs`,type:`USHORT`,value:e}])}var Jz={parse:Kz,make:qz},Yz=[`copyright`,`fontFamily`,`fontSubfamily`,`uniqueID`,`fullName`,`version`,`postScriptName`,`trademark`,`manufacturer`,`designer`,`description`,`manufacturerURL`,`designerURL`,`license`,`licenseURL`,`reserved`,`preferredFamily`,`preferredSubfamily`,`compatibleFullName`,`sampleText`,`postScriptFindFontName`,`wwsFamily`,`wwsSubfamily`],Xz={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`},Zz={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},Qz={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 $z(e,t,n){switch(e){case 0:if(t===65535)return`und`;if(n)return n[t];break;case 1:return Xz[t];case 3:return Qz[t]}}var eB=`utf-16`,tB={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`},nB={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 rB(e,t,n){switch(e){case 0:return eB;case 1:return nB[n]||tB[t];case 3:if(t===1||t===10)return eB;break}}function iB(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=Yz[f]||f,m=i.parseUShort(),h=i.parseUShort(),g=$z(l,d,n),_=rB(l,u,d);if(_!==void 0&&g!==void 0){var v=void 0;if(v=_===eB?KL.UTF16(e,s+h,m):KL.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 aB(e){var t={};for(var n in e)t[e[n]]=parseInt(n);return t}function oB(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 sB(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 cB(e,t){var n=sB(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 lB(e,t){var n,r=[],i={},a=aB(Yz);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=aB(Xz),l=aB(Qz),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=Zz[_],y=rB(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=cB(b,d);u.push(oB(g,v,_,n,b.length,x));var S=l[m];if(S!==void 0){var C=q.UTF16(h),w=cB(C,d);u.push(oB(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 uB={parse:iB,make:lB},dB=[{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 fB(e){for(var t=0;t<dB.length;t+=1){var n=dB[t];if(e>=n.begin&&e<n.end)return t}return-1}function pB(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 mB(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 hB={parse:pB,make:mB,unicodeRanges:dB,getUnicodeRange:fB};function gB(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=MR.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]>=MR.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 _B(){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 vB={parse:gB,make:_B},yB=Array(9);yB[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.`)},yB[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()}},yB[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()}},yB[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 bB={sequenceIndex:X.uShort,lookupListIndex:X.uShort};yB[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,bB)}})};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,bB)}})};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,bB)}}K.assert(!1,`0x`+e.toString(16)+`: lookup type 5 format must be 1, 2 or 3.`)},yB[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(bB)}})};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(bB)}})};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(bB)};K.assert(!1,`0x`+e.toString(16)+`: lookup type 6 format must be 1, 2 or 3.`)},yB[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:yB[t].call(n)}},yB[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 xB(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(yB)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(yB),variations:n.parseFeatureVariationsList()}}var SB=Array(9);SB[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)))},SB[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))})))},SB[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))})))},SB[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)))}))})))},SB[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 CB(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,SB)}])}var wB={parse:xB,make:CB};function TB(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]=KL.UTF8(e,t+c,l)}return a}function EB(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 DB={parse:TB,make:EB};function OB(e){return Math.log(e)/Math.log(2)|0}function kB(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 AB(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 jB(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**OB(t.numTables);t.searchRange=16*n,t.entrySelector=OB(n),t.rangeShift=t.numTables*16-t.searchRange;for(var r=[],i=[],a=t.sizeOf()+AB().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=AB(s.tableName,kB(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 MB(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 NB(e){for(var t=0,n=0;n<e.length;n+=1)t+=e[n];return t/e.length}function PB(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 _=hB.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:NB(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=Pz.make({flags:3,unitsPerEm:e.unitsPerEm,xMin:y.xMin,yMin:y.yMin,xMax:y.xMax,yMax:y.yMax,lowestRecPPEM:3,createdTimestamp:e.createdTimestamp}),x=Lz.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=Jz.make(e.glyphs.length),C=hB.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:MB(e,`xyvw`,{yMax:Math.round(y.ascender/2)}).yMax,sCapHeight:MB(e,`HIKLEFJMNTZBDPRAGOQSUVWXY`,y).yMax,usDefaultChar:e.hasChar(` `)?32:0,usBreakChar:e.hasChar(` `)?32:0},e.tables.os2)),w=Hz.make(e.glyphs),ee=OR.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=uB.make(ae,se),le=se.length>0?Gz.make(se):void 0,ue=vB.make(),de=jz.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?DB.make(e.metas):void 0,pe=[b,x,S,C,ce,ee,ue,de,w];le&&pe.push(le),e.tables.gsub&&pe.push(wB.make(e.tables.gsub)),fe&&pe.push(fe);for(var me=jB(pe),he=kB(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 FB={make:jB,fontToTable:PB,computeCheckSum:kB};function IB(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 LB(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 RB(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 zB(e,t){this.font=e,this.tableName=t}zB.prototype={searchTag:IB,binSearch:LB,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=IB(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=IB(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=RB(e.ranges,t);return n?n.classId:0}},getCoverageIndex:function(e,t){switch(e.format){case 1:var n=LB(e.glyphs,t);return n>=0?n:-1;case 2:var r=RB(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 BB(e){zB.call(this,e,`gpos`)}BB.prototype=zB.prototype,BB.prototype.init=function(){var e=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(e)},BB.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},BB.prototype.getKerningTables=function(e,t){if(this.font.tables.gpos)return this.getLookupTables(e,t,`kern`,2)};function VB(e){zB.call(this,e,`gsub`)}function HB(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 UB(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}VB.prototype=zB.prototype,VB.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:`DFLT`,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}},VB.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},VB.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},VB.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},VB.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},VB.prototype.addSingle=function(e,t,n,r){var i=this.getLookupTables(n,r,e,1,!0)[0],a=UB(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},VB.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=UB(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},VB.prototype.addAlternate=function(e,t,n,r){var i=this.getLookupTables(n,r,e,3,!0)[0],a=UB(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},VB.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(HB(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])},VB.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)}},VB.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 WB(){return typeof window<`u`}function GB(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 KB(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 qB(e,t){if(!e)throw t}function JB(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 YB(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=JB(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=JB(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 XB(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 ZB(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 QB(e){var t=new VL;if(!e)return t;for(var n=ZB(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 $B(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=XB(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=XB([s],c)[0],c.dx=o.x-s.x,c.dy=o.y-s.y,a=XB(i.points,c)}t.points=t.points.concat(a)}}return QB(t.points)}function eV(e,t,n,r){for(var i=new YR.GlyphSet(r),a=0;a<n.length-1;a+=1){var o=n[a];o===n[a+1]?i.push(a,YR.glyphLoader(r,a)):i.push(a,YR.ttfGlyphLoader(r,a,YB,e,t+o,$B))}return i}function tV(e,t,n,r){var i=new YR.GlyphSet(r);return r._push=function(a){var o=n[a];o===n[a+1]?i.push(a,YR.glyphLoader(r,a)):i.push(a,YR.ttfGlyphLoader(r,a,YB,e,t+o,$B))},i}function nV(e,t,n,r,i){return i.lowMemory?tV(e,t,n,r):eV(e,t,n,r)}var rV={getPath:QB,parse:nV},iV,aV,oV,sV;function cV(e){this.font=e,this.getCommands=function(e){return rV.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function lV(e){return e}function uV(e){return Math.sign(e)*Math.round(Math.abs(e))}function dV(e){return Math.sign(e)*Math.round(Math.abs(e*2))/2}function fV(e){return Math.sign(e)*(Math.round(Math.abs(e)+.5)-.5)}function pV(e){return Math.sign(e)*Math.ceil(Math.abs(e))}function mV(e){return Math.sign(e)*Math.floor(Math.abs(e))}var hV=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},gV={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){gV.setRelative(e,e,(c+l)/2,r,!0);return}gV.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}},_V={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){_V.setRelative(e,e,(c+l)/2,r,!0);return}_V.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(gV),Object.freeze(_V);function vV(e,t){this.x=e,this.y=t,this.axis=void 0,this.slope=t/e,this.normalSlope=-e/t,Object.freeze(this)}vV.prototype.distance=function(e,t,n,r){return this.x*gV.distance(e,t,n,r)+this.y*_V.distance(e,t,n,r)},vV.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)},vV.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},vV.prototype.touch=function(e){e.xTouched=!0,e.yTouched=!0};function yV(e,t){var n=Math.sqrt(e*e+t*t);return e/=n,t/=n,e===1&&t===0?gV:e===0&&t===1?_V:new vV(e,t)}function bV(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)}bV.prototype.nextTouched=function(e){for(var t=this.nextPointOnContour;!e.touched(t)&&t!==this;)t=t.nextPointOnContour;return t},bV.prototype.prevTouched=function(e){for(var t=this.prevPointOnContour;!e.touched(t)&&t!==this;)t=t.prevPointOnContour;return t};var xV=Object.freeze(new bV(0,0)),SV={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function CV(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=gV,this.round=uV}}cV.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){CV.prototype=SV,i=this._fpgmState=new CV(`fpgm`,n.tables.fpgm),i.funcs=[],i.font=n,exports.DEBUG&&(console.log(`---EXEC FPGM---`),i.step=-1);try{aV(i)}catch(e){console.log(`Hinting error in FPGM:`+e),this._errorState=3;return}}CV.prototype=i,r=this._prepState=new CV(`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{aV(r)}catch(e){this._errorState<2&&console.log(`Hinting error in PREP:`+e),this._errorState=2}}if(!(this._errorState>1))try{return oV(e,r)}catch(e){this._errorState<1&&(console.log(`Hinting error:`+e),console.log(`Note: further hinting errors are silenced`)),this._errorState=1;return}}},oV=function(e,t){var n=t.ppem/t.font.unitsPerEm,r=n,i=e.components,a,o,s;if(CV.prototype=t,!i)s=new CV(`glyf`,e.instructions),exports.DEBUG&&(console.log(`---EXEC GLYPH---`),s.step=-1),sV(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 CV(`glyf`,d.instructions),exports.DEBUG&&(console.log(`---EXEC COMP `+l+`---`),s.step=-1),sV(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 CV(`glyf`,e.instructions),s.gZone=s.z0=s.z1=s.z2=o,s.contours=a,o.push(new bV(0,0),new bV(Math.round(e.advanceWidth*n),0)),exports.DEBUG&&(console.log(`---EXEC COMPOSITE---`),s.step=-1),aV(s),o.length-=2)}return o},sV=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 bV(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 bV(0,0),new bV(Math.round(e.advanceWidth*n),0)),aV(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)}}},aV=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=iV[t[e.ip]],!r)throw Error(`unknown instruction: 0x`+Number(t[e.ip]).toString(16));r(e)}}};function wV(e){for(var t=e.tZone=Array(e.gZone.length),n=0;n<t.length;n++)t[n]=new bV(0,0)}function TV(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 EV(e,t){exports.DEBUG&&console.log(t.step,`SVTCA[`+e.axis+`]`),t.fv=t.pv=t.dpv=e}function DV(e,t){exports.DEBUG&&console.log(t.step,`SPVTCA[`+e.axis+`]`),t.pv=t.dpv=e}function OV(e,t){exports.DEBUG&&console.log(t.step,`SFVTCA[`+e.axis+`]`),t.fv=e}function kV(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=yV(s,c)}function AV(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=yV(s,c)}function jV(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.pv=e.dpv=yV(r,n)}function MV(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.fv=yV(r,n)}function NV(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 PV(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 FV(e){e.fv=e.pv,exports.DEBUG&&console.log(e.step,`SFVTPV[]`)}function IV(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 LV(e){e.rp0=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP0[]`,e.rp0)}function RV(e){e.rp1=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP1[]`,e.rp1)}function zV(e){e.rp2=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP2[]`,e.rp2)}function BV(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP0[]`,t),e.zp0=t,t){case 0:e.tZone||wV(e),e.z0=e.tZone;break;case 1:e.z0=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function VV(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP1[]`,t),e.zp1=t,t){case 0:e.tZone||wV(e),e.z1=e.tZone;break;case 1:e.z1=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function HV(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP2[]`,t),e.zp2=t,t){case 0:e.tZone||wV(e),e.z2=e.tZone;break;case 1:e.z2=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function UV(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||wV(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 WV(e){e.loop=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SLOOP[]`,e.loop)}function GV(e){exports.DEBUG&&console.log(e.step,`RTG[]`),e.round=uV}function KV(e){exports.DEBUG&&console.log(e.step,`RTHG[]`),e.round=fV}function qV(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SMD[]`,t),e.minDis=t/64}function JV(e){exports.DEBUG&&console.log(e.step,`ELSE[]`),TV(e,!1)}function YV(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`JMPR[]`,t),e.ip+=t-1}function XV(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCVTCI[]`,t),e.cvCutIn=t/64}function ZV(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DUP[]`),t.push(t[t.length-1])}function QV(e){exports.DEBUG&&console.log(e.step,`POP[]`),e.stack.pop()}function $V(e){exports.DEBUG&&console.log(e.step,`CLEAR[]`),e.stack.length=0}function eH(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 tH(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DEPTH[]`),t.push(t.length)}function nH(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++)aV(e),exports.DEBUG&&console.log(++e.step,o+1<r?`next loopcall`:`done loopcall`,o);e.ip=i,e.prog=a}function rH(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],aV(e),e.ip=n,e.prog=r,exports.DEBUG&&console.log(++e.step,`returning from`,t)}function iH(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CINDEX[]`,n),t.push(t[t.length-n])}function aH(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 oH(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 sH(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,xV);e&&(o=t.round(o)),i.setRelative(r,xV,o,a),i.touch(r),t.rp0=t.rp1=n}function cH(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 lH(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 uH(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 dH(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 fH(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 pH(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 mH(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 hH(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 gH(e){exports.DEBUG&&console.log(e.step,`RTDG[]`),e.round=dV}function _H(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,xV);e&&(Math.abs(l-c)<t.cvCutIn&&(l=c),l=t.round(l)),o.setRelative(a,xV,l,s),t.zp0===0&&(a.xo=a.x,a.yo=a.y),o.touch(a),t.rp0=t.rp1=i}function vH(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 yH(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 bH(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 xH(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 SH(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 CH(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`RCVT`,n),t.push(e.cvt[n]*64)}function wH(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,xV,e,!1)*64)}function TH(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 EH(e){exports.DEBUG&&console.log(e.step,`MPPEM[]`),e.stack.push(e.ppem)}function DH(e){exports.DEBUG&&console.log(e.step,`FLIPON[]`),e.autoFlip=!0}function OH(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 kH(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 AH(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 jH(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 MH(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 NH(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 PH(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 FH(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 IH(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`IF[]`,t),t||(TV(e,!0),exports.DEBUG&&console.log(e.step,`EIF[]`))}function LH(e){exports.DEBUG&&console.log(e.step,`EIF[]`)}function RH(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 zH(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 BH(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NOT[]`,n),t.push(+!n)}function VH(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 HH(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDB[]`,t),e.deltaBase=t}function UH(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDS[]`,t),e.deltaShift=.5**t}function WH(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 GH(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 KH(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 qH(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 JH(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`ABS[]`,n),t.push(Math.abs(n))}function YH(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NEG[]`,n),t.push(-n)}function XH(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`FLOOR[]`,n),t.push(Math.floor(n/64)*64)}function ZH(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CEILING[]`,n),t.push(Math.ceil(n/64)*64)}function QH(e,t){var n=t.stack,r=n.pop();exports.DEBUG&&console.log(t.step,`ROUND[]`),n.push(t.round(r/64)*64)}function $H(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 eU(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 tU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SROUND[]`,t),e.round=hV;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 nU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`S45ROUND[]`,t),e.round=hV;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 rU(e){exports.DEBUG&&console.log(e.step,`ROFF[]`),e.round=lV}function iU(e){exports.DEBUG&&console.log(e.step,`RUTG[]`),e.round=pV}function aU(e){exports.DEBUG&&console.log(e.step,`RDTG[]`),e.round=mV}function oU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANCTRL[]`,t)}function sU(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=yV(s,c)}function cU(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 lU(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 uU(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 dU(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 fU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANTYPE[]`,t)}function pU(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 mU(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 hU(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)}iV=[EV.bind(void 0,_V),EV.bind(void 0,gV),DV.bind(void 0,_V),DV.bind(void 0,gV),OV.bind(void 0,_V),OV.bind(void 0,gV),kV.bind(void 0,0),kV.bind(void 0,1),AV.bind(void 0,0),AV.bind(void 0,1),jV,MV,NV,PV,FV,IV,LV,RV,zV,BV,VV,HV,UV,WV,GV,KV,qV,JV,YV,XV,void 0,void 0,ZV,QV,$V,eH,tH,iH,aH,void 0,void 0,void 0,nH,rH,oH,void 0,sH.bind(void 0,0),sH.bind(void 0,1),cH.bind(void 0,_V),cH.bind(void 0,gV),lH.bind(void 0,0),lH.bind(void 0,1),uH.bind(void 0,0),uH.bind(void 0,1),dH.bind(void 0,0),dH.bind(void 0,1),fH,pH,mH.bind(void 0,0),mH.bind(void 0,1),hH,gH,_H.bind(void 0,0),_H.bind(void 0,1),vH,yH,bH,xH,SH,CH,wH.bind(void 0,0),wH.bind(void 0,1),void 0,TH.bind(void 0,0),TH.bind(void 0,1),EH,void 0,DH,void 0,void 0,OH,kH,AH,jH,MH,NH,PH,FH,IH,LH,RH,zH,BH,VH.bind(void 0,1),HH,UH,WH,GH,KH,qH,JH,YH,XH,ZH,QH.bind(void 0,0),QH.bind(void 0,1),QH.bind(void 0,2),QH.bind(void 0,3),void 0,void 0,void 0,void 0,$H,VH.bind(void 0,2),VH.bind(void 0,3),eU.bind(void 0,1),eU.bind(void 0,2),eU.bind(void 0,3),tU,nU,void 0,void 0,rU,void 0,iU,aU,QV,QV,void 0,void 0,void 0,void 0,void 0,oU,sU.bind(void 0,0),sU.bind(void 0,1),cU,void 0,lU,uU,dU,fU,pU,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,mU.bind(void 0,1),mU.bind(void 0,2),mU.bind(void 0,3),mU.bind(void 0,4),mU.bind(void 0,5),mU.bind(void 0,6),mU.bind(void 0,7),mU.bind(void 0,8),hU.bind(void 0,1),hU.bind(void 0,2),hU.bind(void 0,3),hU.bind(void 0,4),hU.bind(void 0,5),hU.bind(void 0,6),hU.bind(void 0,7),hU.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 gU(e){this.char=e,this.state={},this.activeState=null}function _U(e,t,n){this.contextName=n,this.startIndex=e,this.endOffset=t}function vU(e,t,n){this.contextName=e,this.openRange=null,this.ranges=[],this.checkStart=t,this.checkEnd=n}function yU(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 bU(e){this.eventId=e,this.subscribers=[]}function xU(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 bU(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 SU(e){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],xU.call(this,e)}gU.prototype.setState=function(e,t){return this.state[e]=t,this.activeState={key:e,value:this.state[e]},this.activeState},gU.prototype.getState=function(e){return this.state[e]||null},SU.prototype.inboundIndex=function(e){return e>=0&&e<this.tokens.length},SU.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)})])},SU.prototype.replaceRange=function(e,t,n,r){t=t===null?this.tokens.length:t;var i=n.every(function(e){return e instanceof gU});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.`}},SU.prototype.replaceToken=function(e,t,n){if(!isNaN(e)&&this.inboundIndex(e)&&t instanceof gU){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.`}},SU.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},SU.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.`}},SU.prototype.insertToken=function(e,t,n){return e.every(function(e){return e instanceof gU})?(this.tokens.splice.apply(this.tokens,[t,0].concat(e)),n||this.dispatch(`insertToken`,[e,t]),e):{FAIL:`insertToken: invalid token(s).`}},SU.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)},bU.prototype.subscribe=function(e){return typeof e==`function`?this.subscribers.push(e)-1:{FAIL:`invalid '`+this.eventId+`' event handler`}},bU.prototype.unsubscribe=function(e){this.subscribers.splice(e,1)},yU.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)},yU.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}},SU.prototype.rangeToText=function(e){if(e instanceof _U)return this.getRangeTokens(e).map(function(e){return e.char}).join(``)},SU.prototype.getText=function(){return this.tokens.map(function(e){return e.char}).join(``)},SU.prototype.getContext=function(e){return this.registeredContexts[e]||null},SU.prototype.on=function(e,t){var n=this.events[e];return n?n.subscribe(t):null},SU.prototype.dispatch=function(e,t){var n=this,r=this.events[e];r instanceof bU&&r.subscribers.forEach(function(e){e.apply(n,t||[])})},SU.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 vU(e,t,n);return this.registeredContexts[e]=r,this.contextCheckers.push(r),r},SU.prototype.getRangeTokens=function(e){var t=e.startIndex+e.endOffset;return[].concat(this.tokens.slice(e.startIndex,t))},SU.prototype.getContextRanges=function(e){var t=this.getContext(e);return t?t.ranges:{FAIL:`context checker '`+e+`' is not registered.`}},SU.prototype.resetContextsRanges=function(){var e=this.registeredContexts;for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];n.ranges=[]}},SU.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 yU(e,t);this.runContextCheck(n)}this.dispatch(`updateContextsRanges`,[this.registeredContexts])},SU.prototype.setEndOffset=function(e,t){var n=this.getContext(t).openRange.startIndex,r=new _U(n,e,t),i=this.getContext(t).ranges;return r.rangeId=t+`.`+i.length,i.push(r),this.getContext(t).openRange=null,r},SU.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 _U(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])}})},SU.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 yU(t,n);this.dispatch(`next`,[i]),this.runContextCheck(i);var a=new gU(r);this.tokens.push(a),this.dispatch(`newToken`,[a,i])}return this.dispatch(`end`,[this.tokens]),this.tokens};function CU(e){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(e)}function wU(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 TU(e){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(e)}function EU(e){return/[A-z]/.test(e)}function DU(e){return/\s/.test(e)}function OU(e){this.font=e,this.features={}}function kU(e){this.id=e.id,this.tag=e.tag,this.substitution=e.substitution}function AU(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 jU(e,t){return AU(e,t.coverage)===-1?null:e+t.deltaGlyphId}function MU(e,t){var n=AU(e,t.coverage);return n===-1?null:t.substitute[n]}function NU(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=AU(a,i);o!==-1&&n.push(o)}return n.length===e.length?n:-1}function PU(e,t){var n=t.inputCoverage.length+t.lookaheadCoverage.length+t.backtrackCoverage.length;if(e.context.length<n)return[];var r=NU(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&&TU(a[0].char);)a.shift();var o=new yU(a,0),s=NU(t.lookaheadCoverage,o),c=[].concat(e.backtrack);for(c.reverse();c.length&&TU(c[0].char);)c.shift();if(c.length<t.backtrackCoverage.length)return[];var l=new yU(c,0),u=NU(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 FU(e,t){var n=e.current,r=AU(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 IU(e,t){var n=AU(e,t.coverage);return n===-1?null:t.sequences[n]}OU.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[]},OU.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()},OU.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},OU.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},OU.prototype.getSubstitutionType=function(e,t){return e.lookupType.toString()+t.substFormat.toString()},OU.prototype.getLookupMethod=function(e,t){var n=this;switch(this.getSubstitutionType(e,t)){case`11`:return function(e){return jU.apply(n,[e,t])};case`12`:return function(e){return MU.apply(n,[e,t])};case`63`:return function(e){return PU.apply(n,[e,t])};case`41`:return function(e){return FU.apply(n,[e,t])};case`21`:return function(e){return IU.apply(n,[e,t])};default:throw Error(`lookupType: `+e.lookupType+` - substFormat: `+t.substFormat+` is not yet supported`)}},OU.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 kU({id:11,tag:e.tag,substitution:p}));break;case`12`:p=f(t.current),p&&a.splice(n,1,new kU({id:12,tag:e.tag,substitution:p}));break;case`63`:p=f(t),Array.isArray(p)&&p.length&&a.splice(n,1,new kU({id:63,tag:e.tag,substitution:p}));break;case`41`:p=f(t),p&&a.splice(n,1,new kU({id:41,tag:e.tag,substitution:p}));break;case`21`:p=f(t.current),p&&a.splice(n,1,new kU({id:21,tag:e.tag,substitution:p}));break}t=new yU(a,n),!(Array.isArray(p)&&!p.length)&&(p=null)}return a.length?a:null},OU.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},OU.prototype.getLookupSubtables=function(e){return e.subtables||null},OU.prototype.getLookupByIndex=function(e){return this.font.tables.gsub.lookups[e]||null},OU.prototype.getFeatureLookups=function(e){return e.lookupListIndexes.map(this.getLookupByIndex.bind(this))},OU.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 LU(e){var t=e.current,n=e.get(-1);return n===null&&CU(t)||!CU(n)&&CU(t)}function RU(e){var t=e.get(1);return t===null||!CU(t)}var zU={startCheck:LU,endCheck:RU};function BU(e){var t=e.current,n=e.get(-1);return(CU(t)||TU(t))&&!CU(n)}function VU(e){var t=e.get(1);switch(!0){case t===null:return!0;case!CU(t)&&!TU(t):var n=DU(t);if(!n)return!0;if(n){var r=!1;if(r=e.lookahead.some(function(e){return CU(e)||TU(e)}),!r)return!0}break;default:return!1}}var HU={startCheck:BU,endCheck:VU};function UU(e,t,n){t[n].setState(e.tag,e.substitution)}function WU(e,t,n){t[n].setState(e.tag,e.substitution)}function GU(e,t,n){e.substitution.forEach(function(r,i){t[n+i].setState(e.tag,r)})}function KU(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 qU={11:UU,12:WU,63:GU,41:KU};function JU(e,t,n){e instanceof kU&&qU[e.id]&&qU[e.id](e,t,n)}function YU(e){for(var t=[].concat(e.backtrack),n=t.length-1;n>=0;n--){var r=t[n],i=wU(r),a=TU(r);if(!i&&!a)return!0;if(i)return!1}return!1}function XU(e){if(wU(e.current))return!1;for(var t=0;t<e.lookahead.length;t++){var n=e.lookahead[t];if(!TU(n))return!0}return!1}function ZU(e){var t=this,n=`arab`,r=this.featuresTags[n],i=this.tokenizer.getRangeTokens(e);if(i.length!==1){var a=new yU(i.map(function(e){return e.getState(`glyphIndex`)}),0),o=new yU(i.map(function(e){return e.char}),0);i.forEach(function(e,s){if(!TU(e.char)){a.setCurrentIndex(s),o.setCurrentIndex(s);var c=0;YU(o)&&(c|=1),XU(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 kU&&(JU(e,i,t),a.context[t]=e.substitution)})}}})}}function QU(e,t){return new yU(e.map(function(e){return e.activeState.value}),t||0)}function $U(e){var t=this,n=`arab`,r=this.tokenizer.getRangeTokens(e),i=QU(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 JU(e,r,a)}),i=QU(r))})}function eW(e){var t=e.current,n=e.get(-1);return n===null&&EU(t)||!EU(n)&&EU(t)}function tW(e){var t=e.get(1);return t===null||!EU(t)}var nW={startCheck:eW,endCheck:tW};function rW(e,t){return new yU(e.map(function(e){return e.activeState.value}),t||0)}function iW(e){var t=this,n=`latn`,r=this.tokenizer.getRangeTokens(e),i=rW(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 JU(e,r,a)}),i=rW(r))})}function aW(e){this.baseDir=e||`ltr`,this.tokenizer=new SU,this.featuresTags={}}aW.prototype.setText=function(e){this.text=e},aW.prototype.contextChecks={latinWordCheck:nW,arabicWordCheck:zU,arabicSentenceCheck:HU};function oW(e){var t=this.contextChecks[e+`Check`];return this.tokenizer.registerContextChecker(e,t.startCheck,t.endCheck)}function sW(){return oW.call(this,`latinWord`),oW.call(this,`arabicWord`),oW.call(this,`arabicSentence`),this.tokenizer.tokenize(this.text)}function cW(){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())})}aW.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},aW.prototype.applyFeatures=function(e,t){if(!e)throw Error(`No valid font was provided to apply features`);this.query||=new OU(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)}},aW.prototype.registerModifier=function(e,t,n){this.tokenizer.registerModifier(e,t,n)};function lW(){if(this.tokenizer.registeredModifiers.indexOf(`glyphIndex`)===-1)throw Error(`glyphIndex modifier is required to apply arabic presentation features.`)}function uW(){var e=this;this.featuresTags.hasOwnProperty(`arab`)&&(lW.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){ZU.call(e,t)}))}function dW(){var e=this,t=`arab`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`rlig`)!==-1&&(lW.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){$U.call(e,t)}))}function fW(){var e=this,t=`latn`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`liga`)!==-1&&(lW.call(this),this.tokenizer.getContextRanges(`latinWord`).forEach(function(t){iW.call(e,t)}))}aW.prototype.checkContextReady=function(e){return!!this.tokenizer.getContext(e)},aW.prototype.applyFeaturesToContexts=function(){this.checkContextReady(`arabicWord`)&&(uW.call(this),dW.call(this)),this.checkContextReady(`latinWord`)&&fW.call(this),this.checkContextReady(`arabicSentence`)&&cW.call(this)},aW.prototype.processText=function(e){(!this.text||this.text!==e)&&(this.setText(e),sW.call(this),this.applyFeaturesToContexts())},aW.prototype.getBidiText=function(e){return this.processText(e),this.tokenizer.getText()},aW.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 pW(e){e||={},e.tables=e.tables||{},e.empty||(qB(e.familyName,`When creating a new Font object, familyName is required.`),qB(e.styleName,`When creating a new Font object, styleName is required.`),qB(e.unitsPerEm,`When creating a new Font object, unitsPerEm is required.`),qB(e.ascender,`When creating a new Font object, ascender is required.`),qB(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 YR.GlyphSet(this,e.glyphs||[]),this.encoding=new NR(this),this.position=new BB(this),this.substitution=new VB(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 cV(this)}})}pW.prototype.hasChar=function(e){return this.encoding.charToGlyphIndex(e)!==null},pW.prototype.charToGlyphIndex=function(e){return this.encoding.charToGlyphIndex(e)},pW.prototype.charToGlyph=function(e){var t=this.charToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},pW.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})},pW.prototype.stringToGlyphs=function(e,t){var n=this,r=new aW;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},pW.prototype.nameToGlyphIndex=function(e){return this.glyphNames.nameToGlyphIndex(e)},pW.prototype.nameToGlyph=function(e){var t=this.nameToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},pW.prototype.glyphIndexToName=function(e){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(e):``},pW.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},pW.prototype.defaultRenderOptions={kerning:!0,features:[{script:`arab`,tags:[`init`,`medi`,`fina`,`rlig`]},{script:`latn`,tags:[`liga`,`rlig`]}]},pW.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},pW.prototype.getPath=function(e,t,n,r,i){var a=new VL;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},pW.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},pW.prototype.getAdvanceWidth=function(e,t,n){return this.forEachGlyph(e,0,0,t,n,function(){})},pW.prototype.draw=function(e,t,n,r,i,a){this.getPath(t,n,r,i,a).draw(e)},pW.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)})},pW.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)})},pW.prototype.getEnglishName=function(e){var t=this.names[e];if(t)return t.en},pW.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},pW.prototype.toTables=function(){return FB.fontToTable(this)},pW.prototype.toBuffer=function(){return console.warn(`Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.`),this.toArrayBuffer()},pW.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},pW.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(WB())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=pL(),l=KB(r);c.writeFileSync(e,l)}},pW.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512},pW.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},pW.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function mW(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 hW(e,t,n){var r=mW(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 gW(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 _W(e,t,n,r){for(var i=mW(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 vW(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 yW(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(hW(r,e.axes[r],t));for(var i=0;i<e.instances.length;i++)n.fields=n.fields.concat(_W(i,e.instances[i],e.axes,t));return n}function bW(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(gW(e,t+a+d*s,n));for(var f=[],p=t+a+o*s,m=0;m<c;m++)f.push(vW(e,p+m*l,u,n));return{axes:u,instances:f}}var xW={make:yW,parse:bW},SW=function(){return{coverage:this.parsePointer(X.coverage),attachPoints:this.parseList(X.pointer(X.uShortList))}},CW=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()}},wW=function(){return this.parseList(X.pointer(CW))},TW=function(){return{coverage:this.parsePointer(X.coverage),ligGlyphs:this.parseList(X.pointer(wW))}},EW=function(){return this.parseUShort(),this.parseList(X.pointer(X.coverage))};function DW(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(SW),ligCaretList:n.parsePointer(TW),markAttachClassDef:n.parsePointer(X.classDef)};return r>=1.2&&(i.markGlyphSets=n.parsePointer(EW)),i}var OW={parse:DW},kW=Array(10);kW[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.`)},kW[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)}}))}}},kW[3]=function(){return{error:`GPOS Lookup 3 not supported`}},kW[4]=function(){return{error:`GPOS Lookup 4 not supported`}},kW[5]=function(){return{error:`GPOS Lookup 5 not supported`}},kW[6]=function(){return{error:`GPOS Lookup 6 not supported`}},kW[7]=function(){return{error:`GPOS Lookup 7 not supported`}},kW[8]=function(){return{error:`GPOS Lookup 8 not supported`}},kW[9]=function(){return{error:`GPOS Lookup 9 not supported`}};function AW(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(kW)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(kW),variations:n.parseFeatureVariationsList()}}var jW=Array(10);function MW(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,jW)}])}var NW={parse:AW,make:MW};function PW(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 FW(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 IW(e,t){var n=new Z.Parser(e,t),r=n.parseUShort();if(r===0)return PW(n);if(r===1)return FW(n);throw Error(`Unsupported kern table version (`+r+`).`)}var LW={parse:IW};function RW(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 zW={parse:RW};function BW(e,t){pL().readFile(e,function(e,n){if(e)return t(e.message);t(null,GB(n))})}function VW(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 HW(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 UW(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 WW(e,t){if(t.compression===`WOFF`){var n=new Uint8Array(e.buffer,t.offset+2,t.compressedLength-2),r=new Uint8Array(t.length);if(RL(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 GW(e,t){t??={};var n,r,i=new pW({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=HW(a,o);else if(c===`OTTO`)i.outlinesFormat=`cff`,o=Z.getUShort(a,4),s=HW(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=UW(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=WW(a,C),i.tables.cmap=OR.parse(w.data,w.offset),i.encoding=new PR(i.tables.cmap);break;case`cvt `:w=WW(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=WW(a,C),x=new Z.Parser(w.data,w.offset),i.tables.fpgm=x.parseByteList(C.length);break;case`head`:w=WW(a,C),i.tables.head=Pz.parse(w.data,w.offset),i.unitsPerEm=i.tables.head.unitsPerEm,n=i.tables.head.indexToLocFormat;break;case`hhea`:w=WW(a,C),i.tables.hhea=Lz.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=WW(a,C),r=Gz.parse(w.data,w.offset);break;case`maxp`:w=WW(a,C),i.tables.maxp=Jz.parse(w.data,w.offset),i.numGlyphs=i.tables.maxp.numGlyphs;break;case`name`:y=C;break;case`OS/2`:w=WW(a,C),i.tables.os2=hB.parse(w.data,w.offset);break;case`post`:w=WW(a,C),i.tables.post=vB.parse(w.data,w.offset),i.glyphNames=new IR(i.tables.post);break;case`prep`:w=WW(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=WW(a,y);if(i.tables.name=uB.parse(ee.data,ee.offset,r),i.names=i.tables.name,f&&v){var te=n===0,ne=WW(a,v),re=zW.parse(ne.data,ne.offset,i.numGlyphs,te),ie=WW(a,f);i.glyphs=rV.parse(ie.data,ie.offset,re,i,t)}else if(u){var ae=WW(a,u);jz.parse(ae.data,ae.offset,i,t)}else throw Error(`Font doesn't contain TrueType or CFF outlines.`);var oe=WW(a,g);if(Hz.parse(i,oe.data,oe.offset,i.numberOfHMetrics,i.numGlyphs,i.glyphs,t),zR(i,t),_){var se=WW(a,_);i.kerningPairs=LW.parse(se.data,se.offset)}else i.kerningPairs={};if(p){var ce=WW(a,p);i.tables.gdef=OW.parse(ce.data,ce.offset)}if(m){var le=WW(a,m);i.tables.gpos=NW.parse(le.data,le.offset),i.position.init()}if(h){var ue=WW(a,h);i.tables.gsub=wB.parse(ue.data,ue.offset)}if(d){var de=WW(a,d);i.tables.fvar=xW.parse(de.data,de.offset,i.names)}if(b){var fe=WW(a,b);i.tables.meta=DB.parse(fe.data,fe.offset),i.metas=i.tables.meta}return i}function KW(e,t,n){n??={};var r=typeof window>`u`&&!n.isUrl?BW:VW;return new Promise(function(i,a){r(e,function(e,r){if(e){if(t)return t(e);a(e)}var o;try{o=GW(r,n)}catch(e){if(t)return t(e,null);a(e)}if(t)return t(null,o);i(o)})})}function qW(e,t){return GW(GB(pL().readFileSync(e)),t)}var JW=Object.freeze({__proto__:null,Font:pW,Glyph:UR,Path:VL,BoundingBox:BL,_parse:Z,parse:GW,load:KW,loadSync:qW}),YW=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 Fk(this.sketches)}get innerSketches(){return this.sketches.slice(1)}get wires(){return oG(this)}face(){return aG(this)}extrude(e,t={}){return sG(this,e,t)}revolve(e,t={}){return cG(this,e,t)}loftWith(e,t){return lG(this,e,t)}};function XW(e){let t={};e.defaultOrigin&&(t.defaultOrigin=e.defaultOrigin),e.defaultDirection&&(t.defaultDirection=e.defaultDirection);let n=new uG(e.wire,t);return e.baseFace&&(n.baseFace=e.baseFace),n}function ZW(e){return new YW(e.map(XW))}function QW(e){let t;return t=e.baseFace?Qk(e.baseFace,e.wire):j(Xk(e.wire)),t}function $W(e){return dE(j(BD(e.wire.wrapped)))}function eG(e,t,{origin:n}={}){let r=j(Xk(e.wire)),i=j($j(r,n?oD(n):e.defaultOrigin,t?oD(t):[0,0,1]));return r.delete(),e.delete(),i}function tG(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=fD(yD(n?oD(n):e.defaultDirection),t),s=a?oD(a):e.defaultOrigin;if(r&&!i){let t=j(Kj(e.wire,[...s],[...o],r));return e.delete(),t}if(i){let t=j(qj(e.wire,i,[...s],[...o],r));return e.delete(),t}let c=j(Qj(j(Xk(e.wire)),[...o]));return e.delete(),c}function nG(e,t,n={}){let r=tk(e.wire),i=yD(fD(ik(e.wire,1e-9),-1)),a=e.defaultDirection,o=fD(hD(i,a),-1),s=t(DD([...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(Wj(c.wire,e.wire,l));return e.delete(),u}function rG(e,t,n={},r=!1){let i=Array.isArray(t)?[e,...t]:[e,t],a=j(tM(i.map(e=>e.wire),n,r));return i.forEach(e=>{e.delete()}),a}var iG=(e,t)=>{let n=j(t(Fk(e))),r=e.slice(1).map(e=>j(t(e)));if(r.length===0)return n;try{return j(lA(n,r,{unsafe:!0}))}finally{n.delete();for(let e of r)e.delete()}};function aG(e){return eA(e.outerSketch.face(),e.innerSketches.map(e=>e.wire))}function oG(e){return jA(e.sketches.map(e=>e.wire))}function sG(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=fD(yD(n?oD(n):e.outerSketch.defaultDirection),t);return r&&!i?iG(e.sketches,t=>Kj(t.wire,a?oD(a):e.outerSketch.defaultOrigin,o,r)):i?iG(e.sketches,t=>qj(t.wire,i,a?oD(a):e.outerSketch.defaultOrigin,o,r)):j(Qj(aG(e),o))}function cG(e,t,{origin:n}={}){let r=n?oD(n):e.outerSketch.defaultOrigin,i=t?oD(t):[0,0,1];return j($j(aG(e),r,i))}function lG(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=Pk(t.sketches,r),a={};return n.ruled!==void 0&&(a.ruled=n.ruled),e.clone().loftWith(i.clone(),a,!0)}),i=fE(j(BD(aG(e).wrapped)));return r.push(i,aG(t)),j(MA(r))}var uG=class e{wire;_defaultOrigin;_defaultDirection;_baseFace;constructor(e,{defaultOrigin:t=[0,0,0],defaultDirection:n=[0,0,1]}={}){this.wire=e,this._defaultOrigin=oD(t),this._defaultDirection=oD(n),this.baseFace=null}get baseFace(){return this._baseFace}set baseFace(e){this._baseFace&&this._baseFace.delete(),this._baseFace=e&&fE(j(BD(e.wrapped)))}delete(){this.wire.delete(),this.baseFace&&this.baseFace.delete()}clone(){let t=new e(dE(j(BD(this.wire.wrapped))),{defaultOrigin:this.defaultOrigin,defaultDirection:this.defaultDirection});return this.baseFace&&(t.baseFace=fE(j(BD(this.baseFace.wrapped)))),t}get defaultOrigin(){return this._defaultOrigin}set defaultOrigin(e){this._defaultOrigin=oD(e)}get defaultDirection(){return this._defaultDirection}set defaultDirection(e){this._defaultDirection=oD(e)}face(){return QW(this)}wires(){return $W(this)}faces(){return this.face()}revolve(e,t={}){return eG(this,e,t)}extrude(e,t={}){return tG(this,e,t)}sweepSketch(e,t={}){return nG(this,e,t)}loftWith(e,t={},n=!1){return rG(this,e,t,n)}},dG=class{sketches;constructor(e){this.sketches=e}wires(){return jA(this.sketches.map(e=>e instanceof uG?e.wire:e.wires))}faces(){return jA(this.sketches.map(e=>e.face()))}extrude(e,t={}){return jA(this.sketches.map(n=>n.extrude(e,t)))}revolve(e,t){return jA(this.sketches.map(n=>n.revolve(e,t)))}},fG={};async function pG(e,t=`default`,n=!1){if(!n&&fG[t])return O(fG[t]);let r;if(typeof e==`string`){let t;try{t=await fetch(e)}catch(t){return k(po(N.FONT_FETCH_FAILED,`Failed to fetch font from ${e}: ${t instanceof Error?t.message:String(t)}`,t))}if(!t.ok)return k(po(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=JW.parse(r)}catch(e){return k(po(N.FONT_PARSE_FAILED,`Failed to parse font data: ${e instanceof Error?e.message:String(e)}`,e))}let a=i;return fG[t]=a,fG.default||=a,O(a)}var mG=(e=`default`)=>fG[e],hG=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 bI,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 gG(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:i=`default`}={}){let a=mG(i);a||=mG(),a||M(`text`,`No fonts loaded. Call loadFont() before using text functions.`);let o=a.getPath(e,-t,-n,r);return lI(Array.from(hG(o.commands))).mirror([0,0])}var _G={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 vG(e){return typeof e==`string`&&e in _G}var yG=e=>e.IsNull()?[]:RE(W(e));function bG(e,t,n=!0){let r=U().projectEdges(e.wrapped,[...t.position],[...t.direction],[...t.xAxis]);return{visible:[...yG(r.visible.sharp),...yG(r.visible.smooth),...yG(r.visible.outline)],hidden:n?[...yG(r.hidden.sharp),...yG(r.hidden.smooth),...yG(r.hidden.outline)]:[]}}function xG(e=[0,0,0],t=[0,0,1],n){if(gD(t)<1e-12)return k(F(`CAMERA_ZERO_DIRECTION`,`Camera direction cannot be a zero-length vector`));let r;if(n)r=yD(n);else{let e=hD([0,0,1],t);gD(e)<1e-12&&(e=hD([0,1,0],t)),gD(e)<1e-12&&(e=hD([1,0,0],t)),r=yD(e)}let i=yD(hD(t,r));return O({position:e,direction:yD(t),xAxis:r,yAxis:i})}function SG(e,t){let n=yD(dD(e.position,t));return xG(e.position,n)}function CG(e){let t=_G[e];return xG([0,0,0],t.dir,t.xAxis)}function wG(e,t,n=!0){return bG(e,t,n)}var TG=(e,n=1e-7)=>{if(e.length===0)return[];let r=new UF(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},EG=class extends yI{plane;constructor(e,t){super(),this.plane=e&&typeof e!=`string`?{...e}:j(AD(e??`XY`,t))}delete(){this.pendingCurves=[]}sagittaArcTo(e,t){return super.sagittaArcTo(e,-t)}buildWire(){try{var e=CT();this.pendingCurves.length||M(`Sketcher.buildWire`,`No lines to convert into a wire`);let t=e.u(new FT);return j(Yk(EF(this.pendingCurves,this.plane).map(e=>t.register(e))))}catch(t){e.e=t}finally{e.d()}}done(){return new uG(this.buildWire(),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}close(){return this._closeSketch(),this.done()}closeWithMirror(){OP(this.pointer,this.firstPoint)&&M(`Sketcher.closeWithMirror`,`Cannot close with a mirror when the sketch is already closed`);let e=this.buildWire(),t=MD(this.plane,this.pointer),n=hD(yD(dD(t,MD(this.plane,this.firstPoint))),this.plane.zDir),r=j(BD(e.wrapped));return new uG(j(Yk([e,dE(j(BD(U().mirror(r,oD(t),oD(n)))))])),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}closeWithCustomCorner(e,t=`fillet`){return this._closeSketch(),this._customCornerLastWithFirst(e,t),this.done()}},DG=class extends yI{face;_bounds;constructor(e,t=[0,0]){super(t),this.face=fE(j(BD(e.wrapped))),this._bounds=YD(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(Yk(this.pendingCurves.map(n=>uE(e.buildEdgeOnSurface(n.wrapped,t)))));return e.buildCurves3d(n.wrapped),n}done(){try{var e=CT();let t=e.u(new FT),n=this.buildWire(),r=new uG(n);if(sk(n)){let e=t.register(r.clone().face()),n=XD(e,.5,.5),i=fD($D(e),-1);r.defaultOrigin=[n[0],n[1],n[2]],r.defaultDirection=[i[0],i[1],i[2]]}else{let e=tk(n),t=$D(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()}},OG=(e,t={})=>{let n=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(AD(t.plane??`XY`,t.origin));return new uG(j(Yk([Bk(e,n.origin,n.zDir)])),{defaultOrigin:[...n.origin],defaultDirection:[...n.zDir]})},kG=(e=1,t=2,n={})=>{let r=n.plane&&typeof n.plane!=`string`?{...n.plane}:j(AD(n.plane??`XY`,n.origin)),i=r.xDir,a=e,o=t;return t>e&&(i=wD(i,r.zDir,90*iD),a=t,o=e),new uG(j(Yk([j(Vk(a,o,r.origin,r.zDir,i))])),{defaultOrigin:[...r.origin],defaultDirection:[...r.zDir]})},AG=(e,t,n={})=>(n.plane&&typeof n.plane!=`string`?new EG(n.plane):new EG(n.plane,n.origin)).movePointerTo([-e/2,-t/2]).hLine(e).vLine(t).hLine(-e).vLine(-t).done(),jG=(e,t,n=0,r={})=>{let i=DI(e,t,n).sketchOnPlane(r.plane,r.origin),a={};return i.defaultOrigin&&(a.defaultOrigin=i.defaultOrigin),i.defaultDirection&&(a.defaultDirection=i.defaultDirection),new uG(i.wire,a)},MG=(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 EG(r.plane):new EG(r.plane,r.origin),o=Ik(i),s=a.movePointerTo([Pk(o,0),Pk(o,1)]);return n?i.forEach(e=>s.sagittaArcTo([Pk(e,0),Pk(e,1)],n)):i.forEach(e=>s.lineTo([Pk(e,0),Pk(e,1)])),s.done()},NG=(e,t,n=0)=>{let r=Math.PI/t,i=Math.cos(r)*e;return n>=0?i:i+n},PG=(e,t)=>{let n=[...eO(e)],r=[...$D(e)];return new uG(j(mk(rO(e),t)),{defaultOrigin:n,defaultDirection:r})},FG=(e,t={},{pointsCount:n=400,start:r=0,stop:i=1}={},a={})=>{try{var o=CT();let s=o.u(new FT),c=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(AD(t.plane??`XY`,t.origin)),l=(i-r)/n,u=[...Array(n+1).keys()].map(t=>MD(c,e(r+t*l)));return new uG(j(Yk([s.register(j(Gk(u,a)))])),{defaultOrigin:[...c.origin],defaultDirection:[...c.zDir]})}catch(e){o.e=e}finally{o.d()}},IG=(e,t,n,r=[0,0,0],i=[0,0,1],a=!1)=>new uG(j(Yk([Hk(e,t,n,oD(r),oD(i),a)]))),LG=(e,t,n)=>new EG().movePointerTo([-e/2,t/2]).hLine(e).vLine(-t).hLine(-e).close().extrude(n),RG=(e,t)=>OP(e,t,EP*100),zG=(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 BG(e,t,n,r,i){let a=CF(t,n,r.original.lastPoint);e(r),e(a)}function VG(e,t,n,r,i){let a=hF(t,n);e(r),e(a)}function HG(e,t,n,r,i){let a=zG(r.offset instanceof dF?AP(t,r.offset.tangentAt(1)):r.offset.firstPoint,t,n,i.offset instanceof dF?kP(n,i.offset.tangentAt(0)):i.offset.lastPoint);if(!a){let i=hF(t,n);e(r),e(i);return}let o=NP([(t[0]+n[0])/2,(t[1]+n[1])/2],a),s=NP(t,n);if(s<1e-18||o>16*s){let i=hF(t,n);e(r),e(i);return}let c=hF(t,a),l=hF(a,n);e(r),e(c),e(l)}var UG={round:BG,bevel:VG,miter:HG};function WG(e,t,n){let r=n.length===1?go(n,0,`rawOffsets`):GG(n,e.original.lastPoint),i=go(e.offset.splitAt([r],EP),0,`rawOffsets`),a=t.offset.splitAt([r],EP).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 GG(e,t){let n=go(e,0,`selectClosestIntersection`),r=NP(n,t);for(let i=1;i<e.length;i++){let a=go(e,i,`selectClosestIntersection`),o=NP(a,t);o<r&&(r=o,n=a)}return n}function KG(e){let t=new Map,n=(e,n)=>{let r=t.get(e)||[];t.set(e,[...r,...n])},r=new UF(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=go(e,r,`offsetBlueprint`),{intersections:o,commonSegmentsPoints:s}=j(JF(t,a,EP)),c=[...o,...s].filter(e=>{let n=RG(e,t.firstPoint)||RG(e,t.lastPoint),r=RG(e,a.firstPoint)||RG(e,a.lastPoint);return!(n&&r)});c.length&&(n(i,c),n(r,c))}}),t}function qG(e,t,n={}){let r=e.orientation===`clockwise`?-t:t,i=e.curves.map(e=>({offset:ZF(e,r),original:e})),a=[],o=null,s=i.at(-1);if(!s)return[];function c(e){if(e instanceof dF){a.push(e);return}o?e.offset instanceof dF?a.push(e.offset):RG(e.offset.firstPoint,e.offset.lastPoint)||a.push(hF(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(RG(t,r)){c(s),s=e;continue}let i=[];if(s.offset instanceof dF&&e.offset instanceof dF){let{intersections:t,commonSegmentsPoints:n}=j(JF(s.offset,e.offset,EP/100));i=[...t,...n]}if(i.length>0){let{splitPrevious:t,splitCurrent:n}=WG(s,e,i);c(t),s=n;continue}let a=UG[n.lineJoinType??`round`];a(c,t,r,s,e),s=e}return c(s),a}function JG(e,n,r={}){let i=qG(e,n,r);if(i.length<2)return null;let a=KG(i);if(!a.size){let t=new zF(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,EP*100)}),s=new UF(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-EP)});if(!l.length)return null;let u=TG(l).filter(e=>e.length>1).map(e=>new zF(e)).filter(e=>e.isClosed());return u.length?u.length===1?go(u,0,`offsetBlueprint`):new nI(u):null}var YG=e=>{let t=go(e,0,`fuseAll`);for(let n=1;n<e.length;n++)t=lL(t,go(e,n,`fuseAll`));return t};function XG(e,t,n={}){if(e instanceof zF)return JG(e,t,n);if(e instanceof nI)return YG(e.blueprints.map(e=>XG(e,t,n)));if(e instanceof rI){let r=YG(e.blueprints.slice(1).map(e=>XG(e,-t,n)));return dL(XG(go(e.blueprints,0,`offset`),t,n),r)}return null}function ZG(e,t){return e instanceof zF?new zF(mF(e.curves,t)):e instanceof rI?new rI(e.blueprints.map(e=>ZG(e,t))):e instanceof nI?new nI(e.blueprints.map(e=>ZG(e,t))):e}function QG(e,t,n,r){let i=()=>!0;r&&(i=r.shouldKeep.bind(r));let a=[Fk(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`),OP(Fk(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 zF(a)}function $G(e,t,n,r){return t instanceof zF?QG(e,t,n,r):t instanceof rI?new rI(t.blueprints.map(t=>QG(e,t,n,r))):t instanceof nI?new nI(t.blueprints.map(t=>$G(e,t,n,r)).filter(e=>e!==null)):null}function eK(e,t,n){return $G($F,e,t,n)}function tK(e,t,n){return $G(eI,e,t,n)}function nK(e,t){return e instanceof zF?XW(t):e instanceof rI?ZW(t):new dG(t.map(e=>Array.isArray(e)?ZW(e):XW(e)))}var rK=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 rI)return{type:`CompoundBlueprint`,blueprints:t.blueprints.map(e)};if(t instanceof nI)return{type:`Blueprints`,blueprints:t.blueprints.map(e)};if(t instanceof zF)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 lF}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(dL(this.innerShape,t.innerShape))}fuse(t){return new e(lL(this.innerShape,t.innerShape))}intersect(t){return new e(fL(this.innerShape,t.innerShape))}fillet(t,n){let r=n&&n(TI());return new e(eK(this.innerShape,t,r))}chamfer(t,n){let r=n&&n(TI());return new e(tK(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 nK(this.innerShape,n)}sketchOnFace(e,t){this.innerShape||M(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnFace(e,t);return nK(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(XG(this.innerShape,t,n))}approximate(t,n={}){return t!==`svg`&&M(`Drawing.approximate`,`Only 'svg' is supported for now`),new e(ZG(this.innerShape,n))}get blueprint(){if(!(this.innerShape instanceof zF)){if(this.innerShape instanceof nI&&this.innerShape.blueprints.length===1&&this.innerShape.blueprints[0]instanceof zF)return this.innerShape.blueprints[0];M(`Drawing.blueprint`,`This drawing is not a blueprint`)}return this.innerShape}};function iK(e){function t(e){if(e.type===`CompoundBlueprint`)return new rI(e.blueprints.map(t));if(e.type===`Blueprints`)return new nI(e.blueprints.map(t));if(e.type===`Blueprint`)return new zF(e.curves.map(e=>uF(e)));M(`Drawing.deserialize`,`Unknown shape type for deserialization`)}return new rK(t(JSON.parse(e)))}var aK=class extends yI{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new rK(new zF(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 oK(e){let t=new aK;return e&&t.movePointerTo(e),t}function sK(e,t,n=0){return new rK(DI(e,t,n))}var cK=sK;function lK(e){return new rK(new zF([vF(e)]))}function uK(e,t){let[n,r]=[e,t].sort((e,t)=>e-t);return new rK(new zF([yF(r,n,r===e?[1,0]:[0,1])]))}function dK(e){return oK().movePointerTo([-e,0]).sagittaArc(2*e,0,e).sagittaArc(-2*e,0,e).close()}function fK(e,t){return oK().movePointerTo([-e,0]).halfEllipse(2*e,0,t).halfEllipse(-2*e,0,t).close()}function pK(e,t,n=0){return new rK(EI(e,t,n))}function mK(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:i=`default`}={}){return new rK(gG(e,{startX:t,startY:n,fontSize:r,fontFamily:i}))}var hK=(e,t={},n={})=>{e.length<2&&M(`drawPointsInterpolation`,`Need at least 2 points for interpolation, got ${e.length}`);let r=[j(SF(e,t))],i=e[0],a=e[e.length-1];return n.closeShape&&i&&a&&!OP(i,a)&&r.push(hF(a,i)),new rK(new zF(r))},gK=(e,{pointsCount:t=400,start:n=0,stop:r=1,closeShape:i=!1}={},a={})=>{let o=(r-n)/t;return hK([...Array(t+1).keys()].map(t=>e(n+t*o)),a,{closeShape:i})},_K=e=>{try{var t=CT();let n=t.u(new FT),r=cK(1e3,1e3).sketchOnPlane(),i=n.register(j(Xk(r.wire))),a=TG(e.map(e=>FF(e,i))).map(e=>new zF(e));return a.length===0?new rK:a.length===1?new rK(a[0]):new rK(new nI(a))}catch(e){t.e=e}finally{t.d()}};function vK(e,t=`front`){let n;n=typeof t==`string`?j(CG(t)):t;let{visible:r,hidden:i}=wG(e,n);return{visible:_K(r),hidden:_K(i)}}function yK(e){try{var t=CT();let n=t.u(new FT),r=n.register(fE(j(BD(e.wrapped)))),i=TG(RE(n.register(rO(r))).map(t=>FF(t,e))).map(e=>new zF(e));return i.length===0?new rK:i.length===1?new rK(i[0]):new rK(new nI(i))}catch(e){t.e=e}finally{t.d()}}function bK(e,t,n){return n===void 0?e.sketchOnPlane(t):e.sketchOnPlane(t,n)}function xK(e,t){return e.fuse(t)}function SK(e,t){return e.cut(t)}function CK(e,t){return e.intersect(t)}function wK(e,t,n){return e.fillet(t,n)}function TK(e,t,n){return e.chamfer(t,n)}function EK(e,t,n=0){return typeof t==`number`?e.translate(t,n):e.translate(t)}function DK(e,t,n){return e.rotate(t,n)}function OK(e,t,n){return e.scale(t,n)}function kK(e,t,n,r){return e.mirror(t,n,r)}function AK(e){let t=e.clone();return t.reverse(),t}function jK(e){return e.boundingBox}function MK(e){return e.firstPoint}function NK(e){return e.lastPoint}function PK(e,t,n){return e.splitAt(t,n)}function FK(e,t,n){return e.parameter(t,n)}function IK(e,t){return e.tangentAt(t)}function LK(e,t){return e.isOnCurve(t)}function RK(e,t){return e.distanceFrom(t)}function zK(e){return e.length===0?k(F(N.BLUEPRINT_EMPTY_CURVES,`createBlueprint: at least one curve is required`)):O(new zF(e))}function BK(e){return e.length===0?k(F(N.COMPOUND_BLUEPRINT_EMPTY,`createCompoundBlueprint: at least one blueprint (outer boundary) is required`)):O(new rI(e))}function VK(e){return e.boundingBox}function HK(e){return e.orientation}function UK(e,t){return e.isInside(t)}function WK(e){return e.toSVGPathD()}function GK(e,t,n){return e.translate(t,n)}function KK(e,t,n){return e.rotate(t,n)}function qK(e,t,n){return e.scale(t,n)}function JK(e,t,n,r){return e.mirror(t,n,r)}function YK(e,t,n,r){return e.stretch(t,n,r)}function XK(e,t,n){return e.sketchOnPlane(t,n)}function ZK(e,t,n){return e.sketchOnFace(t,n)}function QK(e,t){return n(e,t*3)}function $K(e,t){return n(e,t)}function eq(e){let t=[`# brepjs OBJ export`],n=e.vertices.length/3;for(let r=0;r<n;r++){let[n,i,a]=QK(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]=QK(e.normals,n);t.push(`vn ${r} ${i} ${a}`)}let i=n=>{let[r,i,a]=$K(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(`
|
|
24
|
+
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 mL=0,hL=-3;function gL(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function _L(e,t){this.source=e,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=t,this.destLen=0,this.ltree=new gL,this.dtree=new gL}var vL=new gL,yL=new gL,bL=new Uint8Array(30),xL=new Uint16Array(30),SL=new Uint8Array(30),CL=new Uint16Array(30),wL=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),TL=new gL,EL=new Uint8Array(320);function DL(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 OL(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 kL=new Uint16Array(16);function AL(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)kL[i]=a,a+=e.table[i];for(i=0;i<r;++i)t[n+i]&&(e.trans[kL[t[n+i]]++]=i)}function jL(e){e.bitcount--||(e.tag=e.source[e.sourceIndex++],e.bitcount=7);var t=e.tag&1;return e.tag>>>=1,t}function ML(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 NL(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 PL(e,t,n){var r=ML(e,5,257),i=ML(e,5,1),a=ML(e,4,4),o,s,c;for(o=0;o<19;++o)EL[o]=0;for(o=0;o<a;++o){var l=ML(e,3,0);EL[wL[o]]=l}for(AL(TL,EL,0,19),s=0;s<r+i;){var u=NL(e,TL);switch(u){case 16:var d=EL[s-1];for(c=ML(e,2,3);c;--c)EL[s++]=d;break;case 17:for(c=ML(e,3,3);c;--c)EL[s++]=0;break;case 18:for(c=ML(e,7,11);c;--c)EL[s++]=0;break;default:EL[s++]=u;break}}AL(t,EL,0,r),AL(n,EL,r,i)}function FL(e,t,n){for(;;){var r=NL(e,t);if(r===256)return mL;if(r<256)e.dest[e.destLen++]=r;else{var i,a,o,s;for(r-=257,i=ML(e,bL[r],xL[r]),a=NL(e,n),o=e.destLen-ML(e,SL[a],CL[a]),s=o;s<o+i;++s)e.dest[e.destLen++]=e.dest[s]}}}function IL(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 hL;for(e.sourceIndex+=4,r=t;r;--r)e.dest[e.destLen++]=e.source[e.sourceIndex++];return e.bitcount=0,mL}function LL(e,t){var n=new _L(e,t),r,i,a;do{switch(r=jL(n),i=ML(n,2,0),i){case 0:a=IL(n);break;case 1:a=FL(n,vL,yL);break;case 2:PL(n,n.ltree,n.dtree),a=FL(n,n.ltree,n.dtree);break;default:a=hL}if(a!==mL)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}OL(vL,yL),DL(bL,xL,4,3),DL(SL,CL,2,1),bL[28]=0,xL[28]=258;var RL=LL;function zL(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 BL(){this.x1=NaN,this.y1=NaN,this.x2=NaN,this.y2=NaN}BL.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)},BL.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))},BL.prototype.addX=function(e){this.addPoint(e,null)},BL.prototype.addY=function(e){this.addPoint(null,e)},BL.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(zL(c[f],l[f],u[f],d[f],g)),f===1&&this.addY(zL(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(zL(c[f],l[f],u[f],d[f],v)),f===1&&this.addY(zL(c[f],l[f],u[f],d[f],v)));var y=(-p-Math.sqrt(_))/(2*m);0<y&&y<1&&(f===0&&this.addX(zL(c[f],l[f],u[f],d[f],y)),f===1&&this.addY(zL(c[f],l[f],u[f],d[f],y)))}}},BL.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 VL(){this.commands=[],this.fill=`black`,this.stroke=null,this.strokeWidth=1}VL.prototype.moveTo=function(e,t){this.commands.push({type:`M`,x:e,y:t})},VL.prototype.lineTo=function(e,t){this.commands.push({type:`L`,x:e,y:t})},VL.prototype.curveTo=VL.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})},VL.prototype.quadTo=VL.prototype.quadraticCurveTo=function(e,t,n,r){this.commands.push({type:`Q`,x1:e,y1:t,x:n,y:r})},VL.prototype.close=VL.prototype.closePath=function(){this.commands.push({type:`Z`})},VL.prototype.extend=function(e){if(e.commands)e=e.commands;else if(e instanceof BL){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)},VL.prototype.getBoundingBox=function(){for(var e=new BL,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},VL.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())},VL.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},VL.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},VL.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 HL(e){throw Error(e)}function UL(e,t){e||HL(t)}var K={fail:HL,argument:UL,assert:UL},WL=32768,GL=2147483648,KL={},q={},J={};function qL(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=qL(1),q.CHAR=function(e){return[e.charCodeAt(0)]},J.CHAR=qL(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=qL(2),q.SHORT=function(e){return e>=WL&&(e=-(2*WL-e)),[e>>8&255,e&255]},J.SHORT=qL(2),q.UINT24=function(e){return[e>>16&255,e>>8&255,e&255]},J.UINT24=qL(3),q.ULONG=function(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]},J.ULONG=qL(4),q.LONG=function(e){return e>=GL&&(e=-(2*GL-e)),[e>>24&255,e>>16&255,e>>8&255,e&255]},J.LONG=qL(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=qL(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=qL(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=qL(3),q.NUMBER32=function(e){return[29,e>>24&255,e>>16&255,e>>8&255,e&255]},J.NUMBER32=qL(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,KL.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)},KL.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 JL={"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ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ`};KL.MACSTRING=function(e,t,n,r){var i=JL[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 YL=typeof WeakMap==`function`&&new WeakMap,XL,ZL=function(e){if(!XL)for(var t in XL={},JL)XL[t]=new String(t);var n=XL[e];if(n!==void 0){if(YL){var r=YL.get(n);if(r!==void 0)return r}var i=JL[e];if(i!==void 0){for(var a={},o=0;o<i.length;o++)a[i.charCodeAt(o)]=o+128;return YL&&YL.set(n,a),a}}};q.MACSTRING=function(e,t){var n=ZL(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 QL(e){return e>=-128&&e<=127}function $L(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 eR(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(!QL(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 tR(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(o===0||QL(o)&&a+1<i&&QL(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?$L(e,t,n):r>=-128&&r<=127?eR(e,t,n):tR(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 nR=typeof WeakMap==`function`&&new WeakMap;q.CHARSTRING=function(e){if(nR){var t=nR.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 nR&&nR.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 rR(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)}}rR.prototype.encode=function(){return q.TABLE(this)},rR.prototype.sizeOf=function(){return J.TABLE(this)};function iR(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 aR(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 oR(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 sR(e){e.format===1?rR.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:1}].concat(iR(`glyph`,e.glyphs))):e.format===2?rR.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:2}].concat(oR(`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.`)}sR.prototype=Object.create(rR.prototype),sR.prototype.constructor=sR;function cR(e){rR.call(this,`scriptListTable`,oR(`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 rR(`scriptTable`,[{name:`defaultLangSys`,type:`TABLE`,value:new rR(`defaultLangSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:r.reqFeatureIndex}].concat(iR(`featureIndex`,r.featureIndexes)))}].concat(oR(`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 rR(`langSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:n.reqFeatureIndex}].concat(iR(`featureIndex`,n.featureIndexes)))}]})))}]}))}cR.prototype=Object.create(rR.prototype),cR.prototype.constructor=cR;function lR(e){rR.call(this,`featureListTable`,oR(`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 rR(`featureTable`,[{name:`featureParams`,type:`USHORT`,value:n.featureParams}].concat(iR(`lookupListIndex`,n.lookupListIndexes)))}]}))}lR.prototype=Object.create(rR.prototype),lR.prototype.constructor=lR;function uR(e,t){rR.call(this,`lookupListTable`,aR(`lookup`,e,function(e){var n=t[e.lookupType];return K.assert(!!n,`Unable to write GSUB lookup type `+e.lookupType+` tables.`),new rR(`lookupTable`,[{name:`lookupType`,type:`USHORT`,value:e.lookupType},{name:`lookupFlag`,type:`USHORT`,value:e.lookupFlag}].concat(aR(`subtable`,e.subtables,n)))}))}uR.prototype=Object.create(rR.prototype),uR.prototype.constructor=uR;var Y={Table:rR,Record:rR,Coverage:sR,ScriptList:cR,FeatureList:lR,LookupList:uR,ushortList:iR,tableList:aR,recordList:oR};function dR(e,t){return e.getUint8(t)}function fR(e,t){return e.getUint16(t,!1)}function pR(e,t){return e.getInt16(t,!1)}function mR(e,t){return e.getUint32(t,!1)}function hR(e,t){return e.getInt16(t,!1)+e.getUint16(t+2,!1)/65535}function gR(e,t){for(var n=``,r=t;r<t+4;r+=1)n+=String.fromCharCode(e.getInt8(r));return n}function _R(e,t,n){for(var r=0,i=0;i<n;i+=1)r<<=8,r+=e.getUint8(t+i);return r}function vR(e,t,n){for(var r=[],i=t;i<n;i+=1)r.push(e.getUint8(i));return r}function yR(e){for(var t=``,n=0;n<e.length;n+=1)t+=String.fromCharCode(e[n]);return t}var bR={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=mR(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,e},X.prototype.parseOffset32=X.prototype.parseULong,X.prototype.parseFixed=function(){var e=hR(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=mR(this.data,this.offset+this.relativeOffset+4);return e-=2082844800,this.relativeOffset+=8,e},X.prototype.parseVersion=function(e){var t=fR(this.data,this.offset+this.relativeOffset),n=fR(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+=bR[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 xR={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(xR),langSysRecords:X.recordList({tag:X.tag,langSys:X.pointer(xR)})})}))||[]},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:dR,getCard8:dR,getUShort:fR,getCard16:fR,getShort:pR,getULong:mR,getFixed:hR,getTag:gR,getOffset:_R,getBytes:vR,bytesToString:yR,Parser:X};function SR(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 CR(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 wR(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)SR(n,s);else if(n.format===4)CR(n,s,e,t,r);else throw Error(`Only format 4 and 12 cmap tables are supported (found format `+n.format+`).`);return n}function TR(e,t,n){e.segments.push({end:t,start:t,delta:-(t-n),offset:0,glyphIndex:n})}function ER(e){e.segments.push({end:65535,start:65535,delta:1,offset:0})}function DR(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)TR(i,a.unicodes[o],n);i.segments=i.segments.sort(function(e,t){return e.start-t.start})}ER(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 OR={parse:wR,make:DR},kR=`.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(`,`),AR=`................................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(`.`),jR=`................................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(`.`),MR=`.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 NR(e){this.font=e}NR.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 PR(e){this.cmap=e}PR.prototype.charToGlyphIndex=function(e){return this.cmap.glyphIndexMap[e.codePointAt(0)]||0};function FR(e,t){this.encoding=e,this.charset=t}FR.prototype.charToGlyphIndex=function(e){var t=e.codePointAt(0),n=this.encoding[t];return this.charset.indexOf(n)};function IR(e){switch(e.version){case 1:this.names=MR.slice();break;case 2:this.names=Array(e.numberOfGlyphs);for(var t=0;t<e.numberOfGlyphs;t++)e.glyphNameIndex[t]<MR.length?this.names[t]=MR[e.glyphNameIndex[t]]:this.names[t]=e.names[e.glyphNameIndex[t]-MR.length];break;case 2.5:this.names=Array(e.numberOfGlyphs);for(var n=0;n<e.numberOfGlyphs;n++)this.names[n]=MR[n+e.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}IR.prototype.nameToGlyphIndex=function(e){return this.names.indexOf(e)},IR.prototype.glyphIndexToName=function(e){return this.names[e]};function LR(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 RR(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 zR(e,t){t.lowMemory?RR(e):LR(e)}function BR(e,t,n,r,i){e.beginPath(),e.moveTo(t,n),e.lineTo(r,i),e.stroke()}var VR={line:BR};function HR(e,t){var n=t||new VL;return{configurable:!0,get:function(){return typeof n==`function`&&(n=n()),n},set:function(e){n=e}}}function UR(e){this.bindConstructorValues(e)}UR.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",HR(this,e.path))},UR.prototype.addUnicode=function(e){this.unicodes.length===0&&(this.unicode=e),this.unicodes.push(e)},UR.prototype.getBoundingBox=function(){return this.path.getBoundingBox()},UR.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 VL,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},UR.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},UR.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},UR.prototype.draw=function(e,t,n,r,i){this.getPath(t,n,r,i).draw(e)},UR.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)},UR.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`,VR.line(e,t,-1e4,t,1e4),VR.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`,VR.line(e,t+a*i,-1e4,t+a*i,1e4),VR.line(e,t+s*i,-1e4,t+s*i,1e4),VR.line(e,-1e4,n+-o*i,1e4,n+-o*i),VR.line(e,-1e4,n+-c*i,1e4,n+-c*i),e.strokeStyle=`green`,VR.line(e,t+l*i,-1e4,t+l*i,1e4)};function WR(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 GR(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}GR.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]},GR.prototype.push=function(e,t){this.glyphs[e]=t,this.length++};function KR(e,t){return new UR({index:t,font:e})}function qR(e,t,n,r,i,a){return function(){var o=new UR({index:t,font:e});return o.path=function(){n(o,r,i);var t=a(e.glyphs,o);return t.unitsPerEm=e.unitsPerEm,t},WR(o,`xMin`,`_xMin`),WR(o,`xMax`,`_xMax`),WR(o,`yMin`,`_yMin`),WR(o,`yMax`,`_yMax`),o}}function JR(e,t,n,r){return function(){var i=new UR({index:t,font:e});return i.path=function(){var t=n(e,i,r);return t.unitsPerEm=e.unitsPerEm,t},i}}var YR={GlyphSet:GR,glyphLoader:KR,ttfGlyphLoader:qR,cffGlyphLoader:JR};function XR(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(!XR(e[n],t[n]))return!1;return!0}else return!1}function ZR(e){return e.length<1240?107:e.length<33900?1131:32768}function QR(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 $R(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 ez(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 tz(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 nz(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 tz(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 rz(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 iz(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(nz(r,o))}return rz(i)}function az(e,t){return t=t<=390?kR[t]:e[t-391],t}function oz(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=az(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=az(n,i)),r[o.name]=i}return r}function sz(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 cz=[{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`}],lz=[{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 uz(e,t){return oz(iz(e,0,e.byteLength),cz,t)}function dz(e,t,n,r){return oz(iz(e,t,n),lz,r)}function fz(e,t,n,r){for(var i=[],a=0;a<n.length;a+=1){var o=uz(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=dz(e,c+t,s,r);o._defaultWidthX=l.defaultWidthX,o._nominalWidthX=l.nominalWidthX,l.subrs!==0&&(o._subrs=QR(e,c+l.subrs+t).objects,o._subrsBias=ZR(o._subrs)),o._privateDict=l}i.push(o)}return i}function pz(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(az(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(az(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(az(r,i)),i+=1}else throw Error(`Unknown charset format `+c);return s}function mz(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 FR(i,n)}function hz(e,t,n){var r,i,a,o,s=new VL,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 gz(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 _z(e,t,n,r){n.tables.cff={};var i=QR(e,QR(e,sz(e,t).endOffset,Z.bytesToString).endOffset),a=QR(e,i.endOffset,Z.bytesToString);n.gsubrs=QR(e,a.endOffset).objects,n.gsubrsBias=ZR(n.gsubrs);var o=fz(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=fz(e,t,QR(e,c).objects,a.objects);s._fdArray=u,l+=t,s._fdSelect=gz(e,l,n.numGlyphs,u.length)}var d=t+s.private[1],f=dz(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=QR(e,d+f.subrs).objects,n.subrsBias=ZR(n.subrs));var p;r.lowMemory?(p=$R(e,t+s.charStrings),n.nGlyphs=p.offsets.length):(p=QR(e,t+s.charStrings),n.nGlyphs=p.objects.length);var m=pz(e,t+s.charset,n.nGlyphs,a.objects);if(s.encoding===0?n.cffEncoding=new FR(AR,m):s.encoding===1?n.cffEncoding=new FR(jR,m):n.cffEncoding=mz(e,t+s.encoding,m),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new YR.GlyphSet(n),r.lowMemory)n._push=function(r){var i=ez(r,p.offsets,e,t+s.charStrings);n.glyphs.push(r,YR.cffGlyphLoader(n,r,hz,i))};else for(var h=0;h<n.nGlyphs;h+=1){var g=p.objects[h];n.glyphs.push(h,YR.cffGlyphLoader(n,h,hz,g))}}function vz(e,t){var n,r=kR.indexOf(e);return r>=0&&(n=r),r=t.indexOf(e),r>=0?n=r+kR.length:(n=kR.length+t.length,t.push(e)),n}function yz(){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 bz(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 xz(e,t,n){for(var r={},i=0;i<e.length;i+=1){var a=e[i],o=t[a.name];o!==void 0&&!XR(o,a.value)&&(a.type===`SID`&&(o=vz(o,n)),r[a.op]={name:a.name,type:a.type,value:o})}return r}function Sz(e,t){var n=new Y.Record(`Top DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=xz(cz,e,t),n}function Cz(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 wz(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 Tz(){return new Y.Record(`Global Subr INDEX`,[{name:`subrs`,type:`INDEX`,value:[]}])}function Ez(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=vz(i,t);n.fields.push({name:`glyph_`+r,type:`SID`,value:a})}return n}function Dz(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 Oz(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=Dz(r);t.charStrings.push({name:r.name,type:`CHARSTRING`,value:i})}return t}function kz(e,t){var n=new Y.Record(`Private DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=xz(lz,e,t),n}function Az(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=yz(),n.nameIndex=bz([t.postScriptName]);var u=Sz(i,l);return n.topDictIndex=Cz(u),n.globalSubrIndex=Tz(),n.charsets=Ez(o,l),n.charStringsIndex=Oz(e),n.privateDict=kz(a,l),n.stringIndex=wz(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=Sz(i,l),n.topDictIndex=Cz(u),n}var jz={parse:_z,make:Az};function Mz(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 Nz(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 Pz={parse:Mz,make:Nz};function Fz(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 Iz(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 Lz={parse:Fz,make:Iz};function Rz(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 zz(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 Bz(e,t,n,r,i,a,o){o.lowMemory?zz(e,t,n,r,i):Rz(t,n,r,i,a)}function Vz(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 Hz={parse:Bz,make:Vz};function Uz(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 Wz(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 Gz={make:Uz,parse:Wz};function Kz(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 qz(e){return new Y.Table(`maxp`,[{name:`version`,type:`FIXED`,value:20480},{name:`numGlyphs`,type:`USHORT`,value:e}])}var Jz={parse:Kz,make:qz},Yz=[`copyright`,`fontFamily`,`fontSubfamily`,`uniqueID`,`fullName`,`version`,`postScriptName`,`trademark`,`manufacturer`,`designer`,`description`,`manufacturerURL`,`designerURL`,`license`,`licenseURL`,`reserved`,`preferredFamily`,`preferredSubfamily`,`compatibleFullName`,`sampleText`,`postScriptFindFontName`,`wwsFamily`,`wwsSubfamily`],Xz={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`},Zz={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},Qz={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 $z(e,t,n){switch(e){case 0:if(t===65535)return`und`;if(n)return n[t];break;case 1:return Xz[t];case 3:return Qz[t]}}var eB=`utf-16`,tB={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`},nB={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 rB(e,t,n){switch(e){case 0:return eB;case 1:return nB[n]||tB[t];case 3:if(t===1||t===10)return eB;break}}function iB(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=Yz[f]||f,m=i.parseUShort(),h=i.parseUShort(),g=$z(l,d,n),_=rB(l,u,d);if(_!==void 0&&g!==void 0){var v=void 0;if(v=_===eB?KL.UTF16(e,s+h,m):KL.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 aB(e){var t={};for(var n in e)t[e[n]]=parseInt(n);return t}function oB(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 sB(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 cB(e,t){var n=sB(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 lB(e,t){var n,r=[],i={},a=aB(Yz);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=aB(Xz),l=aB(Qz),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=Zz[_],y=rB(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=cB(b,d);u.push(oB(g,v,_,n,b.length,x));var S=l[m];if(S!==void 0){var C=q.UTF16(h),w=cB(C,d);u.push(oB(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 uB={parse:iB,make:lB},dB=[{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 fB(e){for(var t=0;t<dB.length;t+=1){var n=dB[t];if(e>=n.begin&&e<n.end)return t}return-1}function pB(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 mB(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 hB={parse:pB,make:mB,unicodeRanges:dB,getUnicodeRange:fB};function gB(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=MR.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]>=MR.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 _B(){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 vB={parse:gB,make:_B},yB=Array(9);yB[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.`)},yB[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()}},yB[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()}},yB[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 bB={sequenceIndex:X.uShort,lookupListIndex:X.uShort};yB[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,bB)}})};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,bB)}})};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,bB)}}K.assert(!1,`0x`+e.toString(16)+`: lookup type 5 format must be 1, 2 or 3.`)},yB[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(bB)}})};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(bB)}})};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(bB)};K.assert(!1,`0x`+e.toString(16)+`: lookup type 6 format must be 1, 2 or 3.`)},yB[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:yB[t].call(n)}},yB[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 xB(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(yB)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(yB),variations:n.parseFeatureVariationsList()}}var SB=Array(9);SB[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)))},SB[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))})))},SB[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))})))},SB[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)))}))})))},SB[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 CB(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,SB)}])}var wB={parse:xB,make:CB};function TB(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]=KL.UTF8(e,t+c,l)}return a}function EB(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 DB={parse:TB,make:EB};function OB(e){return Math.log(e)/Math.log(2)|0}function kB(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 AB(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 jB(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**OB(t.numTables);t.searchRange=16*n,t.entrySelector=OB(n),t.rangeShift=t.numTables*16-t.searchRange;for(var r=[],i=[],a=t.sizeOf()+AB().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=AB(s.tableName,kB(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 MB(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 NB(e){for(var t=0,n=0;n<e.length;n+=1)t+=e[n];return t/e.length}function PB(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 _=hB.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:NB(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=Pz.make({flags:3,unitsPerEm:e.unitsPerEm,xMin:y.xMin,yMin:y.yMin,xMax:y.xMax,yMax:y.yMax,lowestRecPPEM:3,createdTimestamp:e.createdTimestamp}),x=Lz.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=Jz.make(e.glyphs.length),C=hB.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:MB(e,`xyvw`,{yMax:Math.round(y.ascender/2)}).yMax,sCapHeight:MB(e,`HIKLEFJMNTZBDPRAGOQSUVWXY`,y).yMax,usDefaultChar:e.hasChar(` `)?32:0,usBreakChar:e.hasChar(` `)?32:0},e.tables.os2)),w=Hz.make(e.glyphs),ee=OR.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=uB.make(ae,se),le=se.length>0?Gz.make(se):void 0,ue=vB.make(),de=jz.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?DB.make(e.metas):void 0,pe=[b,x,S,C,ce,ee,ue,de,w];le&&pe.push(le),e.tables.gsub&&pe.push(wB.make(e.tables.gsub)),fe&&pe.push(fe);for(var me=jB(pe),he=kB(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 FB={make:jB,fontToTable:PB,computeCheckSum:kB};function IB(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 LB(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 RB(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 zB(e,t){this.font=e,this.tableName=t}zB.prototype={searchTag:IB,binSearch:LB,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=IB(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=IB(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=RB(e.ranges,t);return n?n.classId:0}},getCoverageIndex:function(e,t){switch(e.format){case 1:var n=LB(e.glyphs,t);return n>=0?n:-1;case 2:var r=RB(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 BB(e){zB.call(this,e,`gpos`)}BB.prototype=zB.prototype,BB.prototype.init=function(){var e=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(e)},BB.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},BB.prototype.getKerningTables=function(e,t){if(this.font.tables.gpos)return this.getLookupTables(e,t,`kern`,2)};function VB(e){zB.call(this,e,`gsub`)}function HB(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 UB(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}VB.prototype=zB.prototype,VB.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:`DFLT`,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}},VB.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},VB.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},VB.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},VB.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},VB.prototype.addSingle=function(e,t,n,r){var i=this.getLookupTables(n,r,e,1,!0)[0],a=UB(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},VB.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=UB(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},VB.prototype.addAlternate=function(e,t,n,r){var i=this.getLookupTables(n,r,e,3,!0)[0],a=UB(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},VB.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(HB(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])},VB.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)}},VB.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 WB(){return typeof window<`u`}function GB(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 KB(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 qB(e,t){if(!e)throw t}function JB(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 YB(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=JB(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=JB(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 XB(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 ZB(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 QB(e){var t=new VL;if(!e)return t;for(var n=ZB(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 $B(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=XB(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=XB([s],c)[0],c.dx=o.x-s.x,c.dy=o.y-s.y,a=XB(i.points,c)}t.points=t.points.concat(a)}}return QB(t.points)}function eV(e,t,n,r){for(var i=new YR.GlyphSet(r),a=0;a<n.length-1;a+=1){var o=n[a];o===n[a+1]?i.push(a,YR.glyphLoader(r,a)):i.push(a,YR.ttfGlyphLoader(r,a,YB,e,t+o,$B))}return i}function tV(e,t,n,r){var i=new YR.GlyphSet(r);return r._push=function(a){var o=n[a];o===n[a+1]?i.push(a,YR.glyphLoader(r,a)):i.push(a,YR.ttfGlyphLoader(r,a,YB,e,t+o,$B))},i}function nV(e,t,n,r,i){return i.lowMemory?tV(e,t,n,r):eV(e,t,n,r)}var rV={getPath:QB,parse:nV},iV,aV,oV,sV;function cV(e){this.font=e,this.getCommands=function(e){return rV.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function lV(e){return e}function uV(e){return Math.sign(e)*Math.round(Math.abs(e))}function dV(e){return Math.sign(e)*Math.round(Math.abs(e*2))/2}function fV(e){return Math.sign(e)*(Math.round(Math.abs(e)+.5)-.5)}function pV(e){return Math.sign(e)*Math.ceil(Math.abs(e))}function mV(e){return Math.sign(e)*Math.floor(Math.abs(e))}var hV=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},gV={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){gV.setRelative(e,e,(c+l)/2,r,!0);return}gV.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}},_V={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){_V.setRelative(e,e,(c+l)/2,r,!0);return}_V.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(gV),Object.freeze(_V);function vV(e,t){this.x=e,this.y=t,this.axis=void 0,this.slope=t/e,this.normalSlope=-e/t,Object.freeze(this)}vV.prototype.distance=function(e,t,n,r){return this.x*gV.distance(e,t,n,r)+this.y*_V.distance(e,t,n,r)},vV.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)},vV.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},vV.prototype.touch=function(e){e.xTouched=!0,e.yTouched=!0};function yV(e,t){var n=Math.sqrt(e*e+t*t);return e/=n,t/=n,e===1&&t===0?gV:e===0&&t===1?_V:new vV(e,t)}function bV(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)}bV.prototype.nextTouched=function(e){for(var t=this.nextPointOnContour;!e.touched(t)&&t!==this;)t=t.nextPointOnContour;return t},bV.prototype.prevTouched=function(e){for(var t=this.prevPointOnContour;!e.touched(t)&&t!==this;)t=t.prevPointOnContour;return t};var xV=Object.freeze(new bV(0,0)),SV={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function CV(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=gV,this.round=uV}}cV.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){CV.prototype=SV,i=this._fpgmState=new CV(`fpgm`,n.tables.fpgm),i.funcs=[],i.font=n,exports.DEBUG&&(console.log(`---EXEC FPGM---`),i.step=-1);try{aV(i)}catch(e){console.log(`Hinting error in FPGM:`+e),this._errorState=3;return}}CV.prototype=i,r=this._prepState=new CV(`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{aV(r)}catch(e){this._errorState<2&&console.log(`Hinting error in PREP:`+e),this._errorState=2}}if(!(this._errorState>1))try{return oV(e,r)}catch(e){this._errorState<1&&(console.log(`Hinting error:`+e),console.log(`Note: further hinting errors are silenced`)),this._errorState=1;return}}},oV=function(e,t){var n=t.ppem/t.font.unitsPerEm,r=n,i=e.components,a,o,s;if(CV.prototype=t,!i)s=new CV(`glyf`,e.instructions),exports.DEBUG&&(console.log(`---EXEC GLYPH---`),s.step=-1),sV(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 CV(`glyf`,d.instructions),exports.DEBUG&&(console.log(`---EXEC COMP `+l+`---`),s.step=-1),sV(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 CV(`glyf`,e.instructions),s.gZone=s.z0=s.z1=s.z2=o,s.contours=a,o.push(new bV(0,0),new bV(Math.round(e.advanceWidth*n),0)),exports.DEBUG&&(console.log(`---EXEC COMPOSITE---`),s.step=-1),aV(s),o.length-=2)}return o},sV=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 bV(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 bV(0,0),new bV(Math.round(e.advanceWidth*n),0)),aV(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)}}},aV=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=iV[t[e.ip]],!r)throw Error(`unknown instruction: 0x`+Number(t[e.ip]).toString(16));r(e)}}};function wV(e){for(var t=e.tZone=Array(e.gZone.length),n=0;n<t.length;n++)t[n]=new bV(0,0)}function TV(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 EV(e,t){exports.DEBUG&&console.log(t.step,`SVTCA[`+e.axis+`]`),t.fv=t.pv=t.dpv=e}function DV(e,t){exports.DEBUG&&console.log(t.step,`SPVTCA[`+e.axis+`]`),t.pv=t.dpv=e}function OV(e,t){exports.DEBUG&&console.log(t.step,`SFVTCA[`+e.axis+`]`),t.fv=e}function kV(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=yV(s,c)}function AV(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=yV(s,c)}function jV(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.pv=e.dpv=yV(r,n)}function MV(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.fv=yV(r,n)}function NV(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 PV(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 FV(e){e.fv=e.pv,exports.DEBUG&&console.log(e.step,`SFVTPV[]`)}function IV(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 LV(e){e.rp0=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP0[]`,e.rp0)}function RV(e){e.rp1=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP1[]`,e.rp1)}function zV(e){e.rp2=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP2[]`,e.rp2)}function BV(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP0[]`,t),e.zp0=t,t){case 0:e.tZone||wV(e),e.z0=e.tZone;break;case 1:e.z0=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function VV(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP1[]`,t),e.zp1=t,t){case 0:e.tZone||wV(e),e.z1=e.tZone;break;case 1:e.z1=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function HV(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP2[]`,t),e.zp2=t,t){case 0:e.tZone||wV(e),e.z2=e.tZone;break;case 1:e.z2=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function UV(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||wV(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 WV(e){e.loop=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SLOOP[]`,e.loop)}function GV(e){exports.DEBUG&&console.log(e.step,`RTG[]`),e.round=uV}function KV(e){exports.DEBUG&&console.log(e.step,`RTHG[]`),e.round=fV}function qV(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SMD[]`,t),e.minDis=t/64}function JV(e){exports.DEBUG&&console.log(e.step,`ELSE[]`),TV(e,!1)}function YV(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`JMPR[]`,t),e.ip+=t-1}function XV(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCVTCI[]`,t),e.cvCutIn=t/64}function ZV(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DUP[]`),t.push(t[t.length-1])}function QV(e){exports.DEBUG&&console.log(e.step,`POP[]`),e.stack.pop()}function $V(e){exports.DEBUG&&console.log(e.step,`CLEAR[]`),e.stack.length=0}function eH(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 tH(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DEPTH[]`),t.push(t.length)}function nH(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++)aV(e),exports.DEBUG&&console.log(++e.step,o+1<r?`next loopcall`:`done loopcall`,o);e.ip=i,e.prog=a}function rH(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],aV(e),e.ip=n,e.prog=r,exports.DEBUG&&console.log(++e.step,`returning from`,t)}function iH(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CINDEX[]`,n),t.push(t[t.length-n])}function aH(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 oH(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 sH(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,xV);e&&(o=t.round(o)),i.setRelative(r,xV,o,a),i.touch(r),t.rp0=t.rp1=n}function cH(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 lH(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 uH(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 dH(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 fH(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 pH(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 mH(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 hH(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 gH(e){exports.DEBUG&&console.log(e.step,`RTDG[]`),e.round=dV}function _H(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,xV);e&&(Math.abs(l-c)<t.cvCutIn&&(l=c),l=t.round(l)),o.setRelative(a,xV,l,s),t.zp0===0&&(a.xo=a.x,a.yo=a.y),o.touch(a),t.rp0=t.rp1=i}function vH(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 yH(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 bH(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 xH(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 SH(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 CH(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`RCVT`,n),t.push(e.cvt[n]*64)}function wH(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,xV,e,!1)*64)}function TH(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 EH(e){exports.DEBUG&&console.log(e.step,`MPPEM[]`),e.stack.push(e.ppem)}function DH(e){exports.DEBUG&&console.log(e.step,`FLIPON[]`),e.autoFlip=!0}function OH(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 kH(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 AH(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 jH(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 MH(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 NH(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 PH(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 FH(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 IH(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`IF[]`,t),t||(TV(e,!0),exports.DEBUG&&console.log(e.step,`EIF[]`))}function LH(e){exports.DEBUG&&console.log(e.step,`EIF[]`)}function RH(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 zH(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 BH(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NOT[]`,n),t.push(+!n)}function VH(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 HH(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDB[]`,t),e.deltaBase=t}function UH(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDS[]`,t),e.deltaShift=.5**t}function WH(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 GH(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 KH(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 qH(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 JH(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`ABS[]`,n),t.push(Math.abs(n))}function YH(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NEG[]`,n),t.push(-n)}function XH(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`FLOOR[]`,n),t.push(Math.floor(n/64)*64)}function ZH(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CEILING[]`,n),t.push(Math.ceil(n/64)*64)}function QH(e,t){var n=t.stack,r=n.pop();exports.DEBUG&&console.log(t.step,`ROUND[]`),n.push(t.round(r/64)*64)}function $H(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 eU(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 tU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SROUND[]`,t),e.round=hV;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 nU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`S45ROUND[]`,t),e.round=hV;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 rU(e){exports.DEBUG&&console.log(e.step,`ROFF[]`),e.round=lV}function iU(e){exports.DEBUG&&console.log(e.step,`RUTG[]`),e.round=pV}function aU(e){exports.DEBUG&&console.log(e.step,`RDTG[]`),e.round=mV}function oU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANCTRL[]`,t)}function sU(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=yV(s,c)}function cU(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 lU(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 uU(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 dU(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 fU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANTYPE[]`,t)}function pU(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 mU(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 hU(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)}iV=[EV.bind(void 0,_V),EV.bind(void 0,gV),DV.bind(void 0,_V),DV.bind(void 0,gV),OV.bind(void 0,_V),OV.bind(void 0,gV),kV.bind(void 0,0),kV.bind(void 0,1),AV.bind(void 0,0),AV.bind(void 0,1),jV,MV,NV,PV,FV,IV,LV,RV,zV,BV,VV,HV,UV,WV,GV,KV,qV,JV,YV,XV,void 0,void 0,ZV,QV,$V,eH,tH,iH,aH,void 0,void 0,void 0,nH,rH,oH,void 0,sH.bind(void 0,0),sH.bind(void 0,1),cH.bind(void 0,_V),cH.bind(void 0,gV),lH.bind(void 0,0),lH.bind(void 0,1),uH.bind(void 0,0),uH.bind(void 0,1),dH.bind(void 0,0),dH.bind(void 0,1),fH,pH,mH.bind(void 0,0),mH.bind(void 0,1),hH,gH,_H.bind(void 0,0),_H.bind(void 0,1),vH,yH,bH,xH,SH,CH,wH.bind(void 0,0),wH.bind(void 0,1),void 0,TH.bind(void 0,0),TH.bind(void 0,1),EH,void 0,DH,void 0,void 0,OH,kH,AH,jH,MH,NH,PH,FH,IH,LH,RH,zH,BH,VH.bind(void 0,1),HH,UH,WH,GH,KH,qH,JH,YH,XH,ZH,QH.bind(void 0,0),QH.bind(void 0,1),QH.bind(void 0,2),QH.bind(void 0,3),void 0,void 0,void 0,void 0,$H,VH.bind(void 0,2),VH.bind(void 0,3),eU.bind(void 0,1),eU.bind(void 0,2),eU.bind(void 0,3),tU,nU,void 0,void 0,rU,void 0,iU,aU,QV,QV,void 0,void 0,void 0,void 0,void 0,oU,sU.bind(void 0,0),sU.bind(void 0,1),cU,void 0,lU,uU,dU,fU,pU,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,mU.bind(void 0,1),mU.bind(void 0,2),mU.bind(void 0,3),mU.bind(void 0,4),mU.bind(void 0,5),mU.bind(void 0,6),mU.bind(void 0,7),mU.bind(void 0,8),hU.bind(void 0,1),hU.bind(void 0,2),hU.bind(void 0,3),hU.bind(void 0,4),hU.bind(void 0,5),hU.bind(void 0,6),hU.bind(void 0,7),hU.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 gU(e){this.char=e,this.state={},this.activeState=null}function _U(e,t,n){this.contextName=n,this.startIndex=e,this.endOffset=t}function vU(e,t,n){this.contextName=e,this.openRange=null,this.ranges=[],this.checkStart=t,this.checkEnd=n}function yU(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 bU(e){this.eventId=e,this.subscribers=[]}function xU(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 bU(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 SU(e){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],xU.call(this,e)}gU.prototype.setState=function(e,t){return this.state[e]=t,this.activeState={key:e,value:this.state[e]},this.activeState},gU.prototype.getState=function(e){return this.state[e]||null},SU.prototype.inboundIndex=function(e){return e>=0&&e<this.tokens.length},SU.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)})])},SU.prototype.replaceRange=function(e,t,n,r){t=t===null?this.tokens.length:t;var i=n.every(function(e){return e instanceof gU});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.`}},SU.prototype.replaceToken=function(e,t,n){if(!isNaN(e)&&this.inboundIndex(e)&&t instanceof gU){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.`}},SU.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},SU.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.`}},SU.prototype.insertToken=function(e,t,n){return e.every(function(e){return e instanceof gU})?(this.tokens.splice.apply(this.tokens,[t,0].concat(e)),n||this.dispatch(`insertToken`,[e,t]),e):{FAIL:`insertToken: invalid token(s).`}},SU.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)},bU.prototype.subscribe=function(e){return typeof e==`function`?this.subscribers.push(e)-1:{FAIL:`invalid '`+this.eventId+`' event handler`}},bU.prototype.unsubscribe=function(e){this.subscribers.splice(e,1)},yU.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)},yU.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}},SU.prototype.rangeToText=function(e){if(e instanceof _U)return this.getRangeTokens(e).map(function(e){return e.char}).join(``)},SU.prototype.getText=function(){return this.tokens.map(function(e){return e.char}).join(``)},SU.prototype.getContext=function(e){return this.registeredContexts[e]||null},SU.prototype.on=function(e,t){var n=this.events[e];return n?n.subscribe(t):null},SU.prototype.dispatch=function(e,t){var n=this,r=this.events[e];r instanceof bU&&r.subscribers.forEach(function(e){e.apply(n,t||[])})},SU.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 vU(e,t,n);return this.registeredContexts[e]=r,this.contextCheckers.push(r),r},SU.prototype.getRangeTokens=function(e){var t=e.startIndex+e.endOffset;return[].concat(this.tokens.slice(e.startIndex,t))},SU.prototype.getContextRanges=function(e){var t=this.getContext(e);return t?t.ranges:{FAIL:`context checker '`+e+`' is not registered.`}},SU.prototype.resetContextsRanges=function(){var e=this.registeredContexts;for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];n.ranges=[]}},SU.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 yU(e,t);this.runContextCheck(n)}this.dispatch(`updateContextsRanges`,[this.registeredContexts])},SU.prototype.setEndOffset=function(e,t){var n=this.getContext(t).openRange.startIndex,r=new _U(n,e,t),i=this.getContext(t).ranges;return r.rangeId=t+`.`+i.length,i.push(r),this.getContext(t).openRange=null,r},SU.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 _U(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])}})},SU.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 yU(t,n);this.dispatch(`next`,[i]),this.runContextCheck(i);var a=new gU(r);this.tokens.push(a),this.dispatch(`newToken`,[a,i])}return this.dispatch(`end`,[this.tokens]),this.tokens};function CU(e){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(e)}function wU(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 TU(e){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(e)}function EU(e){return/[A-z]/.test(e)}function DU(e){return/\s/.test(e)}function OU(e){this.font=e,this.features={}}function kU(e){this.id=e.id,this.tag=e.tag,this.substitution=e.substitution}function AU(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 jU(e,t){return AU(e,t.coverage)===-1?null:e+t.deltaGlyphId}function MU(e,t){var n=AU(e,t.coverage);return n===-1?null:t.substitute[n]}function NU(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=AU(a,i);o!==-1&&n.push(o)}return n.length===e.length?n:-1}function PU(e,t){var n=t.inputCoverage.length+t.lookaheadCoverage.length+t.backtrackCoverage.length;if(e.context.length<n)return[];var r=NU(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&&TU(a[0].char);)a.shift();var o=new yU(a,0),s=NU(t.lookaheadCoverage,o),c=[].concat(e.backtrack);for(c.reverse();c.length&&TU(c[0].char);)c.shift();if(c.length<t.backtrackCoverage.length)return[];var l=new yU(c,0),u=NU(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 FU(e,t){var n=e.current,r=AU(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 IU(e,t){var n=AU(e,t.coverage);return n===-1?null:t.sequences[n]}OU.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[]},OU.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()},OU.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},OU.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},OU.prototype.getSubstitutionType=function(e,t){return e.lookupType.toString()+t.substFormat.toString()},OU.prototype.getLookupMethod=function(e,t){var n=this;switch(this.getSubstitutionType(e,t)){case`11`:return function(e){return jU.apply(n,[e,t])};case`12`:return function(e){return MU.apply(n,[e,t])};case`63`:return function(e){return PU.apply(n,[e,t])};case`41`:return function(e){return FU.apply(n,[e,t])};case`21`:return function(e){return IU.apply(n,[e,t])};default:throw Error(`lookupType: `+e.lookupType+` - substFormat: `+t.substFormat+` is not yet supported`)}},OU.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 kU({id:11,tag:e.tag,substitution:p}));break;case`12`:p=f(t.current),p&&a.splice(n,1,new kU({id:12,tag:e.tag,substitution:p}));break;case`63`:p=f(t),Array.isArray(p)&&p.length&&a.splice(n,1,new kU({id:63,tag:e.tag,substitution:p}));break;case`41`:p=f(t),p&&a.splice(n,1,new kU({id:41,tag:e.tag,substitution:p}));break;case`21`:p=f(t.current),p&&a.splice(n,1,new kU({id:21,tag:e.tag,substitution:p}));break}t=new yU(a,n),!(Array.isArray(p)&&!p.length)&&(p=null)}return a.length?a:null},OU.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},OU.prototype.getLookupSubtables=function(e){return e.subtables||null},OU.prototype.getLookupByIndex=function(e){return this.font.tables.gsub.lookups[e]||null},OU.prototype.getFeatureLookups=function(e){return e.lookupListIndexes.map(this.getLookupByIndex.bind(this))},OU.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 LU(e){var t=e.current,n=e.get(-1);return n===null&&CU(t)||!CU(n)&&CU(t)}function RU(e){var t=e.get(1);return t===null||!CU(t)}var zU={startCheck:LU,endCheck:RU};function BU(e){var t=e.current,n=e.get(-1);return(CU(t)||TU(t))&&!CU(n)}function VU(e){var t=e.get(1);switch(!0){case t===null:return!0;case!CU(t)&&!TU(t):var n=DU(t);if(!n)return!0;if(n){var r=!1;if(r=e.lookahead.some(function(e){return CU(e)||TU(e)}),!r)return!0}break;default:return!1}}var HU={startCheck:BU,endCheck:VU};function UU(e,t,n){t[n].setState(e.tag,e.substitution)}function WU(e,t,n){t[n].setState(e.tag,e.substitution)}function GU(e,t,n){e.substitution.forEach(function(r,i){t[n+i].setState(e.tag,r)})}function KU(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 qU={11:UU,12:WU,63:GU,41:KU};function JU(e,t,n){e instanceof kU&&qU[e.id]&&qU[e.id](e,t,n)}function YU(e){for(var t=[].concat(e.backtrack),n=t.length-1;n>=0;n--){var r=t[n],i=wU(r),a=TU(r);if(!i&&!a)return!0;if(i)return!1}return!1}function XU(e){if(wU(e.current))return!1;for(var t=0;t<e.lookahead.length;t++){var n=e.lookahead[t];if(!TU(n))return!0}return!1}function ZU(e){var t=this,n=`arab`,r=this.featuresTags[n],i=this.tokenizer.getRangeTokens(e);if(i.length!==1){var a=new yU(i.map(function(e){return e.getState(`glyphIndex`)}),0),o=new yU(i.map(function(e){return e.char}),0);i.forEach(function(e,s){if(!TU(e.char)){a.setCurrentIndex(s),o.setCurrentIndex(s);var c=0;YU(o)&&(c|=1),XU(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 kU&&(JU(e,i,t),a.context[t]=e.substitution)})}}})}}function QU(e,t){return new yU(e.map(function(e){return e.activeState.value}),t||0)}function $U(e){var t=this,n=`arab`,r=this.tokenizer.getRangeTokens(e),i=QU(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 JU(e,r,a)}),i=QU(r))})}function eW(e){var t=e.current,n=e.get(-1);return n===null&&EU(t)||!EU(n)&&EU(t)}function tW(e){var t=e.get(1);return t===null||!EU(t)}var nW={startCheck:eW,endCheck:tW};function rW(e,t){return new yU(e.map(function(e){return e.activeState.value}),t||0)}function iW(e){var t=this,n=`latn`,r=this.tokenizer.getRangeTokens(e),i=rW(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 JU(e,r,a)}),i=rW(r))})}function aW(e){this.baseDir=e||`ltr`,this.tokenizer=new SU,this.featuresTags={}}aW.prototype.setText=function(e){this.text=e},aW.prototype.contextChecks={latinWordCheck:nW,arabicWordCheck:zU,arabicSentenceCheck:HU};function oW(e){var t=this.contextChecks[e+`Check`];return this.tokenizer.registerContextChecker(e,t.startCheck,t.endCheck)}function sW(){return oW.call(this,`latinWord`),oW.call(this,`arabicWord`),oW.call(this,`arabicSentence`),this.tokenizer.tokenize(this.text)}function cW(){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())})}aW.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},aW.prototype.applyFeatures=function(e,t){if(!e)throw Error(`No valid font was provided to apply features`);this.query||=new OU(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)}},aW.prototype.registerModifier=function(e,t,n){this.tokenizer.registerModifier(e,t,n)};function lW(){if(this.tokenizer.registeredModifiers.indexOf(`glyphIndex`)===-1)throw Error(`glyphIndex modifier is required to apply arabic presentation features.`)}function uW(){var e=this;this.featuresTags.hasOwnProperty(`arab`)&&(lW.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){ZU.call(e,t)}))}function dW(){var e=this,t=`arab`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`rlig`)!==-1&&(lW.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){$U.call(e,t)}))}function fW(){var e=this,t=`latn`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`liga`)!==-1&&(lW.call(this),this.tokenizer.getContextRanges(`latinWord`).forEach(function(t){iW.call(e,t)}))}aW.prototype.checkContextReady=function(e){return!!this.tokenizer.getContext(e)},aW.prototype.applyFeaturesToContexts=function(){this.checkContextReady(`arabicWord`)&&(uW.call(this),dW.call(this)),this.checkContextReady(`latinWord`)&&fW.call(this),this.checkContextReady(`arabicSentence`)&&cW.call(this)},aW.prototype.processText=function(e){(!this.text||this.text!==e)&&(this.setText(e),sW.call(this),this.applyFeaturesToContexts())},aW.prototype.getBidiText=function(e){return this.processText(e),this.tokenizer.getText()},aW.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 pW(e){e||={},e.tables=e.tables||{},e.empty||(qB(e.familyName,`When creating a new Font object, familyName is required.`),qB(e.styleName,`When creating a new Font object, styleName is required.`),qB(e.unitsPerEm,`When creating a new Font object, unitsPerEm is required.`),qB(e.ascender,`When creating a new Font object, ascender is required.`),qB(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 YR.GlyphSet(this,e.glyphs||[]),this.encoding=new NR(this),this.position=new BB(this),this.substitution=new VB(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 cV(this)}})}pW.prototype.hasChar=function(e){return this.encoding.charToGlyphIndex(e)!==null},pW.prototype.charToGlyphIndex=function(e){return this.encoding.charToGlyphIndex(e)},pW.prototype.charToGlyph=function(e){var t=this.charToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},pW.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})},pW.prototype.stringToGlyphs=function(e,t){var n=this,r=new aW;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},pW.prototype.nameToGlyphIndex=function(e){return this.glyphNames.nameToGlyphIndex(e)},pW.prototype.nameToGlyph=function(e){var t=this.nameToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},pW.prototype.glyphIndexToName=function(e){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(e):``},pW.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},pW.prototype.defaultRenderOptions={kerning:!0,features:[{script:`arab`,tags:[`init`,`medi`,`fina`,`rlig`]},{script:`latn`,tags:[`liga`,`rlig`]}]},pW.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},pW.prototype.getPath=function(e,t,n,r,i){var a=new VL;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},pW.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},pW.prototype.getAdvanceWidth=function(e,t,n){return this.forEachGlyph(e,0,0,t,n,function(){})},pW.prototype.draw=function(e,t,n,r,i,a){this.getPath(t,n,r,i,a).draw(e)},pW.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)})},pW.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)})},pW.prototype.getEnglishName=function(e){var t=this.names[e];if(t)return t.en},pW.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},pW.prototype.toTables=function(){return FB.fontToTable(this)},pW.prototype.toBuffer=function(){return console.warn(`Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.`),this.toArrayBuffer()},pW.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},pW.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(WB())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=pL(),l=KB(r);c.writeFileSync(e,l)}},pW.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512},pW.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},pW.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function mW(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 hW(e,t,n){var r=mW(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 gW(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 _W(e,t,n,r){for(var i=mW(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 vW(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 yW(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(hW(r,e.axes[r],t));for(var i=0;i<e.instances.length;i++)n.fields=n.fields.concat(_W(i,e.instances[i],e.axes,t));return n}function bW(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(gW(e,t+a+d*s,n));for(var f=[],p=t+a+o*s,m=0;m<c;m++)f.push(vW(e,p+m*l,u,n));return{axes:u,instances:f}}var xW={make:yW,parse:bW},SW=function(){return{coverage:this.parsePointer(X.coverage),attachPoints:this.parseList(X.pointer(X.uShortList))}},CW=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()}},wW=function(){return this.parseList(X.pointer(CW))},TW=function(){return{coverage:this.parsePointer(X.coverage),ligGlyphs:this.parseList(X.pointer(wW))}},EW=function(){return this.parseUShort(),this.parseList(X.pointer(X.coverage))};function DW(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(SW),ligCaretList:n.parsePointer(TW),markAttachClassDef:n.parsePointer(X.classDef)};return r>=1.2&&(i.markGlyphSets=n.parsePointer(EW)),i}var OW={parse:DW},kW=Array(10);kW[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.`)},kW[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)}}))}}},kW[3]=function(){return{error:`GPOS Lookup 3 not supported`}},kW[4]=function(){return{error:`GPOS Lookup 4 not supported`}},kW[5]=function(){return{error:`GPOS Lookup 5 not supported`}},kW[6]=function(){return{error:`GPOS Lookup 6 not supported`}},kW[7]=function(){return{error:`GPOS Lookup 7 not supported`}},kW[8]=function(){return{error:`GPOS Lookup 8 not supported`}},kW[9]=function(){return{error:`GPOS Lookup 9 not supported`}};function AW(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(kW)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(kW),variations:n.parseFeatureVariationsList()}}var jW=Array(10);function MW(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,jW)}])}var NW={parse:AW,make:MW};function PW(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 FW(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 IW(e,t){var n=new Z.Parser(e,t),r=n.parseUShort();if(r===0)return PW(n);if(r===1)return FW(n);throw Error(`Unsupported kern table version (`+r+`).`)}var LW={parse:IW};function RW(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 zW={parse:RW};function BW(e,t){pL().readFile(e,function(e,n){if(e)return t(e.message);t(null,GB(n))})}function VW(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 HW(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 UW(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 WW(e,t){if(t.compression===`WOFF`){var n=new Uint8Array(e.buffer,t.offset+2,t.compressedLength-2),r=new Uint8Array(t.length);if(RL(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 GW(e,t){t??={};var n,r,i=new pW({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=HW(a,o);else if(c===`OTTO`)i.outlinesFormat=`cff`,o=Z.getUShort(a,4),s=HW(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=UW(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=WW(a,C),i.tables.cmap=OR.parse(w.data,w.offset),i.encoding=new PR(i.tables.cmap);break;case`cvt `:w=WW(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=WW(a,C),x=new Z.Parser(w.data,w.offset),i.tables.fpgm=x.parseByteList(C.length);break;case`head`:w=WW(a,C),i.tables.head=Pz.parse(w.data,w.offset),i.unitsPerEm=i.tables.head.unitsPerEm,n=i.tables.head.indexToLocFormat;break;case`hhea`:w=WW(a,C),i.tables.hhea=Lz.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=WW(a,C),r=Gz.parse(w.data,w.offset);break;case`maxp`:w=WW(a,C),i.tables.maxp=Jz.parse(w.data,w.offset),i.numGlyphs=i.tables.maxp.numGlyphs;break;case`name`:y=C;break;case`OS/2`:w=WW(a,C),i.tables.os2=hB.parse(w.data,w.offset);break;case`post`:w=WW(a,C),i.tables.post=vB.parse(w.data,w.offset),i.glyphNames=new IR(i.tables.post);break;case`prep`:w=WW(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=WW(a,y);if(i.tables.name=uB.parse(ee.data,ee.offset,r),i.names=i.tables.name,f&&v){var te=n===0,ne=WW(a,v),re=zW.parse(ne.data,ne.offset,i.numGlyphs,te),ie=WW(a,f);i.glyphs=rV.parse(ie.data,ie.offset,re,i,t)}else if(u){var ae=WW(a,u);jz.parse(ae.data,ae.offset,i,t)}else throw Error(`Font doesn't contain TrueType or CFF outlines.`);var oe=WW(a,g);if(Hz.parse(i,oe.data,oe.offset,i.numberOfHMetrics,i.numGlyphs,i.glyphs,t),zR(i,t),_){var se=WW(a,_);i.kerningPairs=LW.parse(se.data,se.offset)}else i.kerningPairs={};if(p){var ce=WW(a,p);i.tables.gdef=OW.parse(ce.data,ce.offset)}if(m){var le=WW(a,m);i.tables.gpos=NW.parse(le.data,le.offset),i.position.init()}if(h){var ue=WW(a,h);i.tables.gsub=wB.parse(ue.data,ue.offset)}if(d){var de=WW(a,d);i.tables.fvar=xW.parse(de.data,de.offset,i.names)}if(b){var fe=WW(a,b);i.tables.meta=DB.parse(fe.data,fe.offset),i.metas=i.tables.meta}return i}function KW(e,t,n){n??={};var r=typeof window>`u`&&!n.isUrl?BW:VW;return new Promise(function(i,a){r(e,function(e,r){if(e){if(t)return t(e);a(e)}var o;try{o=GW(r,n)}catch(e){if(t)return t(e,null);a(e)}if(t)return t(null,o);i(o)})})}function qW(e,t){return GW(GB(pL().readFileSync(e)),t)}var JW=Object.freeze({__proto__:null,Font:pW,Glyph:UR,Path:VL,BoundingBox:BL,_parse:Z,parse:GW,load:KW,loadSync:qW}),YW=class e{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 Fk(this.sketches)}get innerSketches(){return this.sketches.slice(1)}get wires(){return sG(this)}face(){return oG(this)}extrude(e,t={}){return cG(this,e,t)}revolve(e,t={}){return lG(this,e,t)}loftWith(t,n={}){return Array.isArray(t)||!(t instanceof e)?M(`CompoundSketch.loftWith`,`A compound (face-with-holes) sketch can only loft to another compound sketch with the same number of sub-sketches.`):uG(this,t,n)}sweepSketch(){return M(`CompoundSketch.sweepSketch`,`Sweeping a compound (face-with-holes) profile is not supported — sweep its outer Sketch instead.`)}};function XW(e){let t={};e.defaultOrigin&&(t.defaultOrigin=e.defaultOrigin),e.defaultDirection&&(t.defaultDirection=e.defaultDirection);let n=new dG(e.wire,t);return e.baseFace&&(n.baseFace=e.baseFace),n}function ZW(e){return new YW(e.map(XW))}function QW(e){if(e instanceof dG)return e;let t=e.sketches;if(Array.isArray(t)){let[e,...n]=t;if(e instanceof dG){for(let e of n)e.delete();return e}}M(`asSketch`,`Expected a single-wire profile to loft or sweep.`)}function $W(e){let t;return t=e.baseFace?Qk(e.baseFace,e.wire):j(Xk(e.wire)),t}function eG(e){return dE(j(BD(e.wire.wrapped)))}function tG(e,t,{origin:n}={}){let r=j(Xk(e.wire)),i=j($j(r,n?oD(n):e.defaultOrigin,t?oD(t):[0,0,1]));return r.delete(),e.delete(),i}function nG(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=fD(yD(n?oD(n):e.defaultDirection),t),s=a?oD(a):e.defaultOrigin;if(r&&!i){let t=j(Kj(e.wire,[...s],[...o],r));return e.delete(),t}if(i){let t=j(qj(e.wire,i,[...s],[...o],r));return e.delete(),t}let c=j(Qj(j(Xk(e.wire)),[...o]));return e.delete(),c}function rG(e,t,n={}){let r=tk(e.wire),i=yD(fD(ik(e.wire,1e-9),-1)),a=e.defaultDirection,o=fD(hD(i,a),-1),s=QW(t(DD([...r],[...o],[...i]),[...r])),c={forceProfileSpineOthogonality:!0,...n};e.baseFace&&(c.support=e.baseFace.wrapped);let l=j(Wj(s.wire,e.wire,c));return e.delete(),l}function iG(e,t,n={},r=!1){let i=[e,...(Array.isArray(t)?t:[t]).map(QW)],a=j(tM(i.map(e=>e.wire),n,r));return i.forEach(e=>{e.delete()}),a}var aG=(e,t)=>{let n=j(t(Fk(e))),r=e.slice(1).map(e=>j(t(e)));if(r.length===0)return n;try{return j(lA(n,r,{unsafe:!0}))}finally{n.delete();for(let e of r)e.delete()}};function oG(e){return eA(e.outerSketch.face(),e.innerSketches.map(e=>e.wire))}function sG(e){return jA(e.sketches.map(e=>e.wire))}function cG(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=fD(yD(n?oD(n):e.outerSketch.defaultDirection),t);return r&&!i?aG(e.sketches,t=>Kj(t.wire,a?oD(a):e.outerSketch.defaultOrigin,o,r)):i?aG(e.sketches,t=>qj(t.wire,i,a?oD(a):e.outerSketch.defaultOrigin,o,r)):j(Qj(oG(e),o))}function lG(e,t,{origin:n}={}){let r=n?oD(n):e.outerSketch.defaultOrigin,i=t?oD(t):[0,0,1];return j($j(oG(e),r,i))}function uG(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=Pk(t.sketches,r),a={};return n.ruled!==void 0&&(a.ruled=n.ruled),e.clone().loftWith(i.clone(),a,!0)}),i=fE(j(BD(oG(e).wrapped)));return r.push(i,oG(t)),j(MA(r))}var dG=class e{wire;_defaultOrigin;_defaultDirection;_baseFace;constructor(e,{defaultOrigin:t=[0,0,0],defaultDirection:n=[0,0,1]}={}){this.wire=e,this._defaultOrigin=oD(t),this._defaultDirection=oD(n),this.baseFace=null}get baseFace(){return this._baseFace}set baseFace(e){this._baseFace&&this._baseFace.delete(),this._baseFace=e&&fE(j(BD(e.wrapped)))}delete(){this.wire.delete(),this.baseFace&&this.baseFace.delete()}clone(){let t=new e(dE(j(BD(this.wire.wrapped))),{defaultOrigin:this.defaultOrigin,defaultDirection:this.defaultDirection});return this.baseFace&&(t.baseFace=fE(j(BD(this.baseFace.wrapped)))),t}get defaultOrigin(){return this._defaultOrigin}set defaultOrigin(e){this._defaultOrigin=oD(e)}get defaultDirection(){return this._defaultDirection}set defaultDirection(e){this._defaultDirection=oD(e)}face(){return $W(this)}wires(){return eG(this)}faces(){return this.face()}revolve(e,t={}){return tG(this,e,t)}extrude(e,t={}){return nG(this,e,t)}sweepSketch(e,t={}){return rG(this,e,t)}loftWith(e,t={},n=!1){return iG(this,e,t,n)}},fG=class{sketches;constructor(e){this.sketches=e}soleSketch(e){this.sketches.length!==1&&M(`Sketches.${e}`,`Multiple profiles — ${e} each sub-sketch individually.`);let t=Fk(this.sketches);return t instanceof dG||M(`Sketches.${e}`,`${e} is only supported on single-wire profiles.`),t}face(){return this.sketches.length!==1&&M(`Sketches.face`,`Multiple profiles — use faces() to combine them.`),Fk(this.sketches).face()}loftWith(e,t,n){return this.soleSketch(`loftWith`).loftWith(e,t,n)}sweepSketch(e,t){return this.soleSketch(`sweepSketch`).sweepSketch(e,t)}wires(){return jA(this.sketches.map(e=>e instanceof dG?e.wire:e.wires))}faces(){return jA(this.sketches.map(e=>e.face()))}extrude(e,t={}){return jA(this.sketches.map(n=>n.extrude(e,t)))}revolve(e,t){return jA(this.sketches.map(n=>n.revolve(e,t)))}},pG={};async function mG(e,t=`default`,n=!1){if(!n&&pG[t])return O(pG[t]);let r;if(typeof e==`string`){let t;try{t=await fetch(e)}catch(t){return k(fo(N.FONT_FETCH_FAILED,`Failed to fetch font from ${e}: ${t instanceof Error?t.message:String(t)}`,t))}if(!t.ok)return k(fo(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=JW.parse(r)}catch(e){return k(fo(N.FONT_PARSE_FAILED,`Failed to parse font data: ${e instanceof Error?e.message:String(e)}`,e))}let a=i;return pG[t]=a,pG.default||=a,O(a)}var hG=(e=`default`)=>pG[e],gG=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 bI,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 _G(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:i=`default`}={}){let a=hG(i);a||=hG(),a||M(`text`,`No fonts loaded. Call loadFont() before using text functions.`);let o=a.getPath(e,-t,-n,r);return lI(Array.from(gG(o.commands))).mirror([0,0])}var vG={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 yG(e){return typeof e==`string`&&e in vG}var bG=e=>e.IsNull()?[]:RE(W(e));function xG(e,t,n=!0){let r=U().projectEdges(e.wrapped,[...t.position],[...t.direction],[...t.xAxis]);return{visible:[...bG(r.visible.sharp),...bG(r.visible.smooth),...bG(r.visible.outline)],hidden:n?[...bG(r.hidden.sharp),...bG(r.hidden.smooth),...bG(r.hidden.outline)]:[]}}function SG(e=[0,0,0],t=[0,0,1],n){if(gD(t)<1e-12)return k(F(`CAMERA_ZERO_DIRECTION`,`Camera direction cannot be a zero-length vector`));let r;if(n)r=yD(n);else{let e=hD([0,0,1],t);gD(e)<1e-12&&(e=hD([0,1,0],t)),gD(e)<1e-12&&(e=hD([1,0,0],t)),r=yD(e)}let i=yD(hD(t,r));return O({position:e,direction:yD(t),xAxis:r,yAxis:i})}function CG(e,t){let n=yD(dD(e.position,t));return SG(e.position,n)}function wG(e){let t=vG[e];return SG([0,0,0],t.dir,t.xAxis)}function TG(e,t,n=!0){return xG(e,t,n)}var EG=(e,n=1e-7)=>{if(e.length===0)return[];let r=new UF(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},DG=class extends yI{plane;constructor(e,t){super(),this.plane=e&&typeof e!=`string`?{...e}:j(AD(e??`XY`,t))}delete(){this.pendingCurves=[]}sagittaArcTo(e,t){return super.sagittaArcTo(e,-t)}buildWire(){try{var e=CT();this.pendingCurves.length||M(`Sketcher.buildWire`,`No lines to convert into a wire`);let t=e.u(new FT);return j(Yk(EF(this.pendingCurves,this.plane).map(e=>t.register(e))))}catch(t){e.e=t}finally{e.d()}}done(){return new dG(this.buildWire(),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}close(){return this._closeSketch(),this.done()}closeWithMirror(){OP(this.pointer,this.firstPoint)&&M(`Sketcher.closeWithMirror`,`Cannot close with a mirror when the sketch is already closed`);let e=this.buildWire(),t=MD(this.plane,this.pointer),n=hD(yD(dD(t,MD(this.plane,this.firstPoint))),this.plane.zDir),r=j(BD(e.wrapped));return new dG(j(Yk([e,dE(j(BD(U().mirror(r,oD(t),oD(n)))))])),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}closeWithCustomCorner(e,t=`fillet`){return this._closeSketch(),this._customCornerLastWithFirst(e,t),this.done()}},OG=class extends yI{face;_bounds;constructor(e,t=[0,0]){super(t),this.face=fE(j(BD(e.wrapped))),this._bounds=YD(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(Yk(this.pendingCurves.map(n=>uE(e.buildEdgeOnSurface(n.wrapped,t)))));return e.buildCurves3d(n.wrapped),n}done(){try{var e=CT();let t=e.u(new FT),n=this.buildWire(),r=new dG(n);if(sk(n)){let e=t.register(r.clone().face()),n=XD(e,.5,.5),i=fD($D(e),-1);r.defaultOrigin=[n[0],n[1],n[2]],r.defaultDirection=[i[0],i[1],i[2]]}else{let e=tk(n),t=$D(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()}},kG=(e,t={})=>{let n=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(AD(t.plane??`XY`,t.origin));return new dG(j(Yk([Bk(e,n.origin,n.zDir)])),{defaultOrigin:[...n.origin],defaultDirection:[...n.zDir]})},AG=(e=1,t=2,n={})=>{let r=n.plane&&typeof n.plane!=`string`?{...n.plane}:j(AD(n.plane??`XY`,n.origin)),i=r.xDir,a=e,o=t;return t>e&&(i=wD(i,r.zDir,90*iD),a=t,o=e),new dG(j(Yk([j(Vk(a,o,r.origin,r.zDir,i))])),{defaultOrigin:[...r.origin],defaultDirection:[...r.zDir]})},jG=(e,t,n={})=>(n.plane&&typeof n.plane!=`string`?new DG(n.plane):new DG(n.plane,n.origin)).movePointerTo([-e/2,-t/2]).hLine(e).vLine(t).hLine(-e).vLine(-t).done(),MG=(e,t,n=0,r={})=>{let i=DI(e,t,n).sketchOnPlane(r.plane,r.origin),a={};return i.defaultOrigin&&(a.defaultOrigin=i.defaultOrigin),i.defaultDirection&&(a.defaultDirection=i.defaultDirection),new dG(i.wire,a)},NG=(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 DG(r.plane):new DG(r.plane,r.origin),o=Ik(i),s=a.movePointerTo([Pk(o,0),Pk(o,1)]);return n?i.forEach(e=>s.sagittaArcTo([Pk(e,0),Pk(e,1)],n)):i.forEach(e=>s.lineTo([Pk(e,0),Pk(e,1)])),s.done()},PG=(e,t,n=0)=>{let r=Math.PI/t,i=Math.cos(r)*e;return n>=0?i:i+n},FG=(e,t)=>{let n=[...eO(e)],r=[...$D(e)];return new dG(j(mk(rO(e),t)),{defaultOrigin:n,defaultDirection:r})},IG=(e,t={},{pointsCount:n=400,start:r=0,stop:i=1}={},a={})=>{try{var o=CT();let s=o.u(new FT),c=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(AD(t.plane??`XY`,t.origin)),l=(i-r)/n,u=[...Array(n+1).keys()].map(t=>MD(c,e(r+t*l)));return new dG(j(Yk([s.register(j(Gk(u,a)))])),{defaultOrigin:[...c.origin],defaultDirection:[...c.zDir]})}catch(e){o.e=e}finally{o.d()}},LG=(e,t,n,r=[0,0,0],i=[0,0,1],a=!1)=>new dG(j(Yk([Hk(e,t,n,oD(r),oD(i),a)]))),RG=(e,t,n)=>new DG().movePointerTo([-e/2,t/2]).hLine(e).vLine(-t).hLine(-e).close().extrude(n),zG=(e,t)=>OP(e,t,EP*100),BG=(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 VG(e,t,n,r,i){let a=CF(t,n,r.original.lastPoint);e(r),e(a)}function HG(e,t,n,r,i){let a=hF(t,n);e(r),e(a)}function UG(e,t,n,r,i){let a=BG(r.offset instanceof dF?AP(t,r.offset.tangentAt(1)):r.offset.firstPoint,t,n,i.offset instanceof dF?kP(n,i.offset.tangentAt(0)):i.offset.lastPoint);if(!a){let i=hF(t,n);e(r),e(i);return}let o=NP([(t[0]+n[0])/2,(t[1]+n[1])/2],a),s=NP(t,n);if(s<1e-18||o>16*s){let i=hF(t,n);e(r),e(i);return}let c=hF(t,a),l=hF(a,n);e(r),e(c),e(l)}var WG={round:VG,bevel:HG,miter:UG};function GG(e,t,n){let r=n.length===1?ho(n,0,`rawOffsets`):KG(n,e.original.lastPoint),i=ho(e.offset.splitAt([r],EP),0,`rawOffsets`),a=t.offset.splitAt([r],EP).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 KG(e,t){let n=ho(e,0,`selectClosestIntersection`),r=NP(n,t);for(let i=1;i<e.length;i++){let a=ho(e,i,`selectClosestIntersection`),o=NP(a,t);o<r&&(r=o,n=a)}return n}function qG(e){let t=new Map,n=(e,n)=>{let r=t.get(e)||[];t.set(e,[...r,...n])},r=new UF(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=ho(e,r,`offsetBlueprint`),{intersections:o,commonSegmentsPoints:s}=j(JF(t,a,EP)),c=[...o,...s].filter(e=>{let n=zG(e,t.firstPoint)||zG(e,t.lastPoint),r=zG(e,a.firstPoint)||zG(e,a.lastPoint);return!(n&&r)});c.length&&(n(i,c),n(r,c))}}),t}function JG(e,t,n={}){let r=e.orientation===`clockwise`?-t:t,i=e.curves.map(e=>({offset:ZF(e,r),original:e})),a=[],o=null,s=i.at(-1);if(!s)return[];function c(e){if(e instanceof dF){a.push(e);return}o?e.offset instanceof dF?a.push(e.offset):zG(e.offset.firstPoint,e.offset.lastPoint)||a.push(hF(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(zG(t,r)){c(s),s=e;continue}let i=[];if(s.offset instanceof dF&&e.offset instanceof dF){let{intersections:t,commonSegmentsPoints:n}=j(JF(s.offset,e.offset,EP/100));i=[...t,...n]}if(i.length>0){let{splitPrevious:t,splitCurrent:n}=GG(s,e,i);c(t),s=n;continue}let a=WG[n.lineJoinType??`round`];a(c,t,r,s,e),s=e}return c(s),a}function YG(e,n,r={}){let i=JG(e,n,r);if(i.length<2)return null;let a=qG(i);if(!a.size){let t=new zF(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,EP*100)}),s=new UF(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-EP)});if(!l.length)return null;let u=EG(l).filter(e=>e.length>1).map(e=>new zF(e)).filter(e=>e.isClosed());return u.length?u.length===1?ho(u,0,`offsetBlueprint`):new nI(u):null}var XG=e=>{let t=ho(e,0,`fuseAll`);for(let n=1;n<e.length;n++)t=lL(t,ho(e,n,`fuseAll`));return t};function ZG(e,t,n={}){if(e instanceof zF)return YG(e,t,n);if(e instanceof nI)return XG(e.blueprints.map(e=>ZG(e,t,n)));if(e instanceof rI){let r=XG(e.blueprints.slice(1).map(e=>ZG(e,-t,n)));return dL(ZG(ho(e.blueprints,0,`offset`),t,n),r)}return null}function QG(e,t){return e instanceof zF?new zF(mF(e.curves,t)):e instanceof rI?new rI(e.blueprints.map(e=>QG(e,t))):e instanceof nI?new nI(e.blueprints.map(e=>QG(e,t))):e}function $G(e,t,n,r){let i=()=>!0;r&&(i=r.shouldKeep.bind(r));let a=[Fk(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`),OP(Fk(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 zF(a)}function eK(e,t,n,r){return t instanceof zF?$G(e,t,n,r):t instanceof rI?new rI(t.blueprints.map(t=>$G(e,t,n,r))):t instanceof nI?new nI(t.blueprints.map(t=>eK(e,t,n,r)).filter(e=>e!==null)):null}function tK(e,t,n){return eK($F,e,t,n)}function nK(e,t,n){return eK(eI,e,t,n)}function rK(e,t){return e instanceof zF?XW(t):e instanceof rI?ZW(t):new fG(t.map(e=>Array.isArray(e)?ZW(e):XW(e)))}var iK=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 rI)return{type:`CompoundBlueprint`,blueprints:t.blueprints.map(e)};if(t instanceof nI)return{type:`Blueprints`,blueprints:t.blueprints.map(e)};if(t instanceof zF)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 lF}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(dL(this.innerShape,t.innerShape))}fuse(t){return new e(lL(this.innerShape,t.innerShape))}intersect(t){return new e(fL(this.innerShape,t.innerShape))}fillet(t,n){let r=n&&n(TI());return new e(tK(this.innerShape,t,r))}chamfer(t,n){let r=n&&n(TI());return new e(nK(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 rK(this.innerShape,n)}sketchOnFace(e,t){this.innerShape||M(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnFace(e,t);return rK(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(ZG(this.innerShape,t,n))}approximate(t,n={}){return t!==`svg`&&M(`Drawing.approximate`,`Only 'svg' is supported for now`),new e(QG(this.innerShape,n))}get blueprint(){if(!(this.innerShape instanceof zF)){if(this.innerShape instanceof nI&&this.innerShape.blueprints.length===1&&this.innerShape.blueprints[0]instanceof zF)return this.innerShape.blueprints[0];M(`Drawing.blueprint`,`This drawing is not a blueprint`)}return this.innerShape}};function aK(e){function t(e){if(e.type===`CompoundBlueprint`)return new rI(e.blueprints.map(t));if(e.type===`Blueprints`)return new nI(e.blueprints.map(t));if(e.type===`Blueprint`)return new zF(e.curves.map(e=>uF(e)));M(`Drawing.deserialize`,`Unknown shape type for deserialization`)}return new iK(t(JSON.parse(e)))}var oK=class extends yI{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new iK(new zF(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 sK(e){let t=new oK;return e&&t.movePointerTo(e),t}function cK(e,t,n=0){return new iK(DI(e,t,n))}var lK=cK;function uK(e){return new iK(new zF([vF(e)]))}function dK(e,t){let[n,r]=[e,t].sort((e,t)=>e-t);return new iK(new zF([yF(r,n,r===e?[1,0]:[0,1])]))}function fK(e){return sK().movePointerTo([-e,0]).sagittaArc(2*e,0,e).sagittaArc(-2*e,0,e).close()}function pK(e,t){return sK().movePointerTo([-e,0]).halfEllipse(2*e,0,t).halfEllipse(-2*e,0,t).close()}function mK(e,t,n=0){return new iK(EI(e,t,n))}function hK(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:i=`default`}={}){return new iK(_G(e,{startX:t,startY:n,fontSize:r,fontFamily:i}))}var gK=(e,t={},n={})=>{e.length<2&&M(`drawPointsInterpolation`,`Need at least 2 points for interpolation, got ${e.length}`);let r=[j(SF(e,t))],i=e[0],a=e[e.length-1];return n.closeShape&&i&&a&&!OP(i,a)&&r.push(hF(a,i)),new iK(new zF(r))},_K=(e,{pointsCount:t=400,start:n=0,stop:r=1,closeShape:i=!1}={},a={})=>{let o=(r-n)/t;return gK([...Array(t+1).keys()].map(t=>e(n+t*o)),a,{closeShape:i})},vK=e=>{try{var t=CT();let n=t.u(new FT),r=lK(1e3,1e3).sketchOnPlane(),i=n.register(j(Xk(r.wire))),a=EG(e.map(e=>FF(e,i))).map(e=>new zF(e));return a.length===0?new iK:a.length===1?new iK(a[0]):new iK(new nI(a))}catch(e){t.e=e}finally{t.d()}};function yK(e,t=`front`){let n;n=typeof t==`string`?j(wG(t)):t;let{visible:r,hidden:i}=TG(e,n);return{visible:vK(r),hidden:vK(i)}}function bK(e){try{var t=CT();let n=t.u(new FT),r=n.register(fE(j(BD(e.wrapped)))),i=EG(RE(n.register(rO(r))).map(t=>FF(t,e))).map(e=>new zF(e));return i.length===0?new iK:i.length===1?new iK(i[0]):new iK(new nI(i))}catch(e){t.e=e}finally{t.d()}}function xK(e,t,n){return n===void 0?e.sketchOnPlane(t):e.sketchOnPlane(t,n)}function SK(e,t){return e.fuse(t)}function CK(e,t){return e.cut(t)}function wK(e,t){return e.intersect(t)}function TK(e,t,n){return e.fillet(t,n)}function EK(e,t,n){return e.chamfer(t,n)}function DK(e,t,n=0){return typeof t==`number`?e.translate(t,n):e.translate(t)}function OK(e,t,n){return e.rotate(t,n)}function kK(e,t,n){return e.scale(t,n)}function AK(e,t,n,r){return e.mirror(t,n,r)}function jK(e){let t=e.clone();return t.reverse(),t}function MK(e){return e.boundingBox}function NK(e){return e.firstPoint}function PK(e){return e.lastPoint}function FK(e,t,n){return e.splitAt(t,n)}function IK(e,t,n){return e.parameter(t,n)}function LK(e,t){return e.tangentAt(t)}function RK(e,t){return e.isOnCurve(t)}function zK(e,t){return e.distanceFrom(t)}function BK(e){return e.length===0?k(F(N.BLUEPRINT_EMPTY_CURVES,`createBlueprint: at least one curve is required`)):O(new zF(e))}function VK(e){return e.length===0?k(F(N.COMPOUND_BLUEPRINT_EMPTY,`createCompoundBlueprint: at least one blueprint (outer boundary) is required`)):O(new rI(e))}function HK(e){return e.boundingBox}function UK(e){return e.orientation}function WK(e,t){return e.isInside(t)}function GK(e){return e.toSVGPathD()}function KK(e,t,n){return e.translate(t,n)}function qK(e,t,n){return e.rotate(t,n)}function JK(e,t,n){return e.scale(t,n)}function YK(e,t,n,r){return e.mirror(t,n,r)}function XK(e,t,n,r){return e.stretch(t,n,r)}function ZK(e,t,n){return e.sketchOnPlane(t,n)}function QK(e,t,n){return e.sketchOnFace(t,n)}function $K(e,t){return n(e,t*3)}function eq(e,t){return n(e,t)}function tq(e){let t=[`# brepjs OBJ export`],n=e.vertices.length/3;for(let r=0;r<n;r++){let[n,i,a]=$K(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]=$K(e.normals,n);t.push(`vn ${r} ${i} ${a}`)}let i=n=>{let[r,i,a]=eq(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(`
|
|
25
25
|
`)+`
|
|
26
|
-
`}var
|
|
26
|
+
`}var nq=5126,rq=5125,iq=34962,aq=34963,oq=[-Math.SQRT1_2,0,0,Math.SQRT1_2];function sq(e){return e===`Z`?[{mesh:0}]:[{name:`Z_up_to_Y_up`,rotation:oq,children:[1]},{mesh:0}]}function cq(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 lq(e){return e+3&-4}function uq(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 dq(e,t){let n=hq(e,`base64`,t);return JSON.stringify(n)}function fq(e,t){let{doc:n,binBuffer:r}=gq(e,t),i=JSON.stringify(n),a=new TextEncoder().encode(i),o=lq(a.length),s=new Uint8Array(o);s.set(a);for(let e=a.length;e<o;e++)s[e]=32;let c=lq(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 pq(e,t,n,r,i){return[{bufferView:0,componentType:rq,count:e.length,type:`SCALAR`},{bufferView:1,componentType:nq,count:t.length/3,type:`VEC3`,min:r,max:i},{bufferView:2,componentType:nq,count:n.length/3,type:`VEC3`}]}function mq(e,t,n){return[{buffer:0,byteOffset:0,byteLength:e,target:aq},{buffer:0,byteOffset:lq(e),byteLength:t,target:iq},{buffer:0,byteOffset:lq(e)+t,byteLength:n,target:iq}]}function hq(e,t,n){let{vertices:r,normals:i,triangles:a}=e,o=n?.materials;if(o&&o.size>0&&e.faceGroups.length>0)return Sq(e,t,o,n.upAxis??`Y`);let s=a.byteLength,c=r.byteLength,l=i.byteLength,u=lq(s)+c+l,{min:d,max:f}=cq(r),p={asset:{version:`2.0`,generator:`brepjs`},scene:0,scenes:[{nodes:[0]}],nodes:sq(n?.upAxis??`Y`),meshes:[{primitives:[{attributes:{POSITION:1,NORMAL:2},indices:0}]}],accessors:pq(a,r,i,d,f),bufferViews:mq(s,c,l),buffers:[{byteLength:u}]};if(t===`base64`){let t=wq(e);p.buffers[0]={byteLength:u,uri:`data:application/octet-stream;base64,`+uq(t)}}return p}function gq(e,t){let n=t?.materials;if(n&&n.size>0&&e.faceGroups.length>0){let{doc:r,binBuffer:i}=Cq(e,n,t.upAxis??`Y`);return{doc:r,binBuffer:i}}return{doc:hq(e,`glb`,t),binBuffer:wq(e)}}function _q(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=Pk(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+=Pk(o,e).count;let i=new Uint32Array(r),s=0;for(let e of n){let n=Pk(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=lq(f+t)}let m=f;return{primitiveData:d,indexBufferInfos:p,verticesOffset:m,totalByteLength:m+r.byteLength+i.byteLength,uniqueMaterials:s}}function vq(e,t,n,r){let{vertices:i,normals:a}=e,{min:o,max:s}=cq(i),c=r.length;r.push({buffer:0,byteOffset:t,byteLength:i.byteLength,target:iq});let l=n.length;n.push({bufferView:c,componentType:nq,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:iq});let d=n.length;return n.push({bufferView:u,componentType:nq,count:a.length/3,type:`VEC3`}),{verticesAccIdx:l,normalsAccIdx:d}}function yq(e,t,n,r,i,a){let o=[];for(let s=0;s<e.length;s++){let c=Pk(e,s),l=Pk(t,s),u=a.length;a.push({buffer:0,byteOffset:l.byteOffset,byteLength:l.byteLength,target:aq});let d=i.length;i.push({bufferView:u,componentType:rq,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 bq(e,t,n=`Y`){let{primitiveData:r,indexBufferInfos:i,verticesOffset:a,totalByteLength:o,uniqueMaterials:s}=t,c=[],l=[],{verticesAccIdx:u,normalsAccIdx:d}=vq(e,a,c,l),f=yq(r,i,u,d,c,l);return{asset:{version:`2.0`,generator:`brepjs`},scene:0,scenes:[{nodes:[0]}],nodes:sq(n),meshes:[{primitives:f}],accessors:c,bufferViews:l,buffers:[{byteLength:o}],materials:s}}function xq(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=Pk(i,e),n=Pk(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 Sq(e,t,n,r=`Y`){let i=_q(e,n),a=bq(e,i,r);if(t===`base64`){let t=xq(e,i);a.buffers[0]={byteLength:i.totalByteLength,uri:`data:application/octet-stream;base64,`+uq(t)}}return a}function Cq(e,t,n=`Y`){let r=_q(e,t);return{doc:bq(e,r,n),binBuffer:xq(e,r)}}function wq(e){let{vertices:t,normals:n,triangles:r}=e,i=r.byteLength,a=t.byteLength,o=n.byteLength,s=lq(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),lq(i)),l.set(new Uint8Array(n.buffer,n.byteOffset,o),lq(i)+a),c}function Tq(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(`
|
|
27
27
|
`)+`
|
|
28
|
-
`}function
|
|
29
|
-
`);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`:
|
|
30
|
-
`);n.push(` <basematerials id="3">\n${e}\n </basematerials>`)}return n}function
|
|
28
|
+
`}function Eq(e,t){let n=t?.curveSegments??32,r=[],i=Dq(e);for(let e of i)for(let t of e.curves)r.push(...Oq(t,n));return Tq(r,t)}function Dq(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(...Dq(n));return t}return[]}function Oq(e,t){return e.geomType===`LINE`?[{type:`LINE`,start:e.firstPoint,end:e.lastPoint}]:[kq(e,t)]}function kq(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 Aq=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;Aq[e]=t}function jq(e){let t=4294967295;for(let n of e)t=Aq[(t^n)&255]^t>>>8;return(t^4294967295)>>>0}function Mq(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 Nq(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 Pq(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 Fq(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=Mq(s,c,l,e);for(let{offset:e,entry:t}of n)l=Nq(s,c,l,e,t);return Pq(s,l,e.length,r,i),o}function Iq(e){return e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`)}function Lq(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 Rq(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 zq(e){let t=new Map,n=[];if(e!==void 0&&e.size>0)for(let r of e.values()){let e=Lq(r);t.has(e)||(t.set(e,n.length),n.push(e))}return{colorIndexByHex:t,colorHexList:n}}function Bq(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 Vq(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=Lq(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 Hq(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 Uq(e,t){let n=[];if(e.length>0){let t=e.map(e=>` <color color="${e}" />`).join(`
|
|
29
|
+
`);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`:Lq(e.displayColor);return` <base name="${Iq(e.name)}" displaycolor="${t}" />`}).join(`
|
|
30
|
+
`);n.push(` <basematerials id="3">\n${e}\n </basematerials>`)}return n}function Wq(e,t,n,r,i){let a=Rq(e),{colorIndexByHex:o,colorHexList:s}=zq(r),{materialIndexByName:c,materialList:l}=Bq(i),u=Hq(e,Vq(e,r,i,o,c)),d=Uq(s,l);return`<?xml version="1.0" encoding="UTF-8"?>
|
|
31
31
|
<model unit="${n}" xmlns="http://schemas.microsoft.com/3dmanufacturing/core/2015/02"${l.length>0?`
|
|
32
32
|
xmlns:m="http://schemas.microsoft.com/3dmanufacturing/material/2015/02"`:``}>
|
|
33
33
|
<resources>${d.length>0?`
|
|
34
34
|
`+d.join(`
|
|
35
35
|
`):``}
|
|
36
|
-
<object id="1" name="${
|
|
36
|
+
<object id="1" name="${Iq(t)}" type="model">
|
|
37
37
|
<mesh>
|
|
38
38
|
<vertices>
|
|
39
39
|
${a.join(`
|
|
@@ -49,12 +49,12 @@ ${u.join(`
|
|
|
49
49
|
<build>
|
|
50
50
|
<item objectid="1" />
|
|
51
51
|
</build>
|
|
52
|
-
</model>`}function
|
|
52
|
+
</model>`}function Gq(e,t={}){let{name:n=`model`,unit:r=`millimeter`,colors:i,materials:a}=t,o=new TextEncoder,s=Wq(e,n,r,i,a);function c(e,t){let n=o.encode(e),r=o.encode(t);return{name:n,data:r,crc:jq(r)}}return Fq([c(`[Content_Types].xml`,`<?xml version="1.0" encoding="UTF-8"?>
|
|
53
53
|
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
|
54
54
|
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
|
|
55
55
|
<Default Extension="model" ContentType="application/vnd.ms-package.3dmanufacturing-3dmodel+xml" />
|
|
56
56
|
</Types>`),c(`_rels/.rels`,`<?xml version="1.0" encoding="UTF-8"?>
|
|
57
57
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
58
58
|
<Relationship Target="/3D/3dmodel.model" Id="rel0" Type="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel" />
|
|
59
|
-
</Relationships>`),c(`3D/3dmodel.model`,s)])}function Gq(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 Kq(e){return[e[0],-e[1]]}function qq(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(hF(Kq([t.cx,t.cy]),Kq([a,o]))),t.cx=a,t.cy=o,i+=2}}function Jq(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(hF(Kq([t.cx,t.cy]),Kq([a,o]))),t.cx=a,t.cy=o,i+=2}}function Yq(e,t,n,r){for(let i of e){let e=n?t.cx+i:i;r.push(hF(Kq([t.cx,t.cy]),Kq([e,t.cy]))),t.cx=e}}function Xq(e,t,n,r){for(let i of e){let e=n?t.cy+i:i;r.push(hF(Kq([t.cx,t.cy]),Kq([t.cx,e]))),t.cy=e}}function Zq(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(xF(Kq([t.cx,t.cy]),[Kq([s,c]),Kq([l,u])],Kq([d,f]))),t.prevControlX=l,t.prevControlY=u,t.cx=d,t.cy=f,i+=6}}function Qq(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(xF(Kq([t.cx,t.cy]),[Kq([c,l]),Kq([u,d])],Kq([f,p]))),t.prevControlX=u,t.prevControlY=d,t.cx=f,t.cy=p,t.lastCmd=`S`,i+=4}}function $q(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(xF(Kq([t.cx,t.cy]),[Kq([s,c])],Kq([l,u]))),t.prevControlX=s,t.prevControlY=c,t.cx=l,t.cy=u,i+=4}}function eJ(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(xF(Kq([t.cx,t.cy]),[Kq([c,l])],Kq([u,d]))),t.prevControlX=c,t.prevControlY=l,t.cx=u,t.cy=d,t.lastCmd=`T`,i+=2}}function tJ(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[gF(Kq([e,t]),Kq(c),Kq([e,s])),gF(Kq([e,s]),Kq(l),Kq([e,t]))]}catch{return[]}}function nJ(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[gF(Kq([e,t]),Kq([b,x]),Kq([n,r]))]}catch{return[hF(Kq([e,t]),Kq([n,r]))]}}function rJ(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(hF(Kq([t.cx,t.cy]),Kq([d,f])));else{let e=d-t.cx,n=f-t.cy;Math.sqrt(e*e+n*n)<1e-10?r.push(...tJ(t.cx,t.cy,s,c,u)):r.push(...nJ(t.cx,t.cy,d,f,s,c,l,u))}t.cx=d,t.cy=f,i+=7}}function iJ(e,t){(Math.abs(e.cx-e.sx)>1e-10||Math.abs(e.cy-e.sy)>1e-10)&&t.push(hF(Kq([e.cx,e.cy]),Kq([e.sx,e.sy]))),e.cx=e.sx,e.cy=e.sy}function aJ(e){let t=Gq(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`:qq(i,r,t,n);break;case`L`:Jq(i,r,t,n);break;case`H`:Yq(i,r,t,n);break;case`V`:Xq(i,r,t,n);break;case`C`:Zq(i,r,t,n);break;case`S`:Qq(i,r,t,n);break;case`Q`:$q(i,r,t,n);break;case`T`:eJ(i,r,t,n);break;case`A`:rJ(i,r,t,n);break;case`Z`:iJ(r,n);break}a!==`S`&&a!==`T`&&(r.lastCmd=a)}return n}function oJ(e){try{let t=aJ(e);return t.length===0?k(po(`SVG_EMPTY_PATH`,`SVG path produced no curves`)):O(new zF(t))}catch(e){return k(po(`SVG_PARSE_FAILED`,`Failed to parse SVG path: ${e instanceof Error?e.message:String(e)}`))}}function sJ(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=oJ(l);u.ok&&n.push(u.value)}return n.length===0?k(po(`SVG_NO_PATHS`,`No <path> elements found in SVG`)):O(n)}catch(e){return k(po(`SVG_IMPORT_FAILED`,`Failed to import SVG: ${e instanceof Error?e.message:String(e)}`))}}function cJ(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(po(N.STEP_EXPORT_CONFIGURED_FAILED,`Configured STEP export failed`,e))}}async function lJ(e){try{let t=await e.arrayBuffer(),n=U().importSTEP(t);return n.length===0?k(po(`STEP_IMPORT_FAILED`,`STEP file contains no valid geometry`)):O(W(n[0]))}catch{return k(po(`STEP_IMPORT_FAILED`,`Failed to load STEP file`))}}async function uJ(e){try{let t=await e.arrayBuffer(),n=U().importSTL(t);return n.IsNull()?k(po(`STL_IMPORT_FAILED`,`Failed to create solid from STL mesh`)):O(W(n))}catch{return k(po(`STL_IMPORT_FAILED`,`Failed to load STL file`))}}async function dJ(e){try{let t=await e.arrayBuffer(),n=U().importIGES(t);return n.length===0?k(po(`IGES_IMPORT_FAILED`,`IGES file contains no valid geometry`)):O(W(n[0]))}catch{return k(po(`IGES_IMPORT_FAILED`,`Failed to load IGES file`))}}function fJ(e,t,n={}){let r=gG(e,t);return new dG((typeof n.plane==`string`||n.plane===void 0?r.sketchOnPlane(n.plane,n.origin):r.sketchOnPlane(n.plane)).map(e=>Array.isArray(e)?new YW(e.map(XW)):XW(e)))}function pJ(e,t){let n=t?.fontSize??1,r=mG(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 mJ(e){let t=e?.fontSize??1,n=mG(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 hJ(e,t){let n=0,r=KD(t);if(e.surfaceType!==void 0)if(r===e.surfaceType)n+=1;else return-1/0;if(e.normal!==void 0){let r=$D(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=eO(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=vP(t);if(r.ok&&r.value>0){let t=Math.abs(Math.log(e.area/r.value));t>1&&(n-=t)}}return n}function gJ(e){let t=KD(e),n=$D(e),r=eO(e),i=vP(e);return{entityType:`face`,surfaceType:t,normal:n,centroid:r,area:i.ok?i.value:void 0}}var _J=.9;function vJ(e){if(e[2]>_J)return`box:top`;if(e[2]<-.9)return`box:bottom`;if(e[1]>_J)return`box:back`;if(e[1]<-.9)return`box:front`;if(e[0]>_J)return`box:right`;if(e[0]<-.9)return`box:left`}function yJ(e,t){let n=zE(e),r=new Map;if(t===`box`){for(let e of n){let t=vJ($D(e));t!==void 0&&!r.has(t)&&r.set(t,YO(e))}return r}let i=0;for(let e of n)r.set(`${t}:face_${i}`,YO(e)),i++;return r}function bJ(e,t,n){return{origin:e,role:t,hint:gJ(n)}}function xJ(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 SJ=.1,CJ=.5;function wJ(e,t,n,r){let i=zE(n),a=r??hJ,o=t.get(e.origin)?.get(e.role);if(o!==void 0){for(let e of i)if(YO(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>CJ&&u.push([t,n]),n>s?(l=s,s=n,c=t):n>l&&(l=n)}return c!==void 0&&s>CJ?s-l<SJ&&u.length>1?{ref:e,reason:`ambiguous`,candidates:u.filter(([,e])=>e>=s-SJ).map(([e])=>e)}:{face:c,confidence:`geometric-fallback`}:{ref:e,reason:`not-found`}}function TJ(e){return e.type===`init`}function EJ(e){return e.type===`operation`}function DJ(e){return e.type===`dispose`}function OJ(e){return e.success}function kJ(e){return!e.success}function AJ(){return{pending:new Map}}function jJ(e,t){let n=new Map(e.pending);return n.set(t.id,t),{pending:n}}function MJ(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 NJ(e){return e.pending.size}function PJ(e){return e.pending.size===0}function FJ(e,t){for(let n of e.pending.values())n.reject(t);return{pending:new Map}}function IJ(e,t){let n=t.data,r=e.get(n.id);if(r)if(e.delete(n.id),OJ(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 LJ(e){let{worker:t,wasmUrl:n}=e,r=new Map,i=!1;function a(){return crypto.randomUUID()}function o(e){IJ(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 RJ(){return{operations:new Map}}function zJ(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function BJ(e,t){let n=globalThis;n.onmessage=async r=>{let i=r.data;if(TJ(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(EJ(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(DJ(i)){let e={id:i.id,success:!0};n.postMessage(e),n.close?.()}}}var VJ=Object.defineProperty,HJ=(e,t)=>{let n={};for(var r in e)VJ(n,r,{get:e[r],enumerable:!0});return t||VJ(n,Symbol.toStringTag,{value:`Module`}),n},UJ=1,WJ=2;function GJ(e,t){t===`commonFace`&&e.SetGlue(UJ),t===`sameFace`&&e.SetGlue(WJ)}function KJ(e){return typeof e==`number`}function qJ(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 JJ(e){return typeof e==`number`?!0:Array.isArray(e)&&e.length===2?e.every(KJ):!1}function YJ(e,t){let n=n=>{let r=e.findAll(n);if(r.length===0)return[];let i=0,a=vD(rD(Fk(r)),t);for(let e=1;e<r.length;e++){let n=vD(rD(Pk(r,e)),t);n<a&&(a=n,i=e)}return[Pk(r,i)]},r=e=>{let t=n(e);return t.length===0?k(mo(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found 0 element(s)`)):O(Fk(t))};return{...e,findAll:n,findUnique:r}}function XJ(e){return UP(`vertex`,e,XJ,(t,n)=>({nearestTo:t=>YJ(XJ(e),t),atPosition:(e,t=1e-4)=>n(n=>vD(rD(n),e)<t),withinBox:(e,t)=>n(n=>{let r=rD(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=rD(n);return Math.abs(vD(i,t)-e)<r})}))}function ZJ(){return XJ([])}var QJ=new Map,$J=null,eY=null;function tY(e,t){QJ.set(e,t),$J||=e,e===$J&&(eY=t)}function nY(e){if(!e&&eY)return eY;let t=e??$J;if(!t)throw Error(`brepjs voxel engine not initialized. Call initVoxel() (or registerVoxel()) before using voxel operations.`);let n=QJ.get(t);if(!n)throw Error(`brepjs: voxel engine '${t}' is not registered.`);return n}function rY(){return $J}function iY(e,t=`voxel`){tY(t,e),$J=t,eY=e}function aY(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 oY(e,t){return aY(e)||(t.length%3==0?null:F(`VOXEL_INVALID_QUERIES`,`queries length must be a multiple of 3 (flat xyz).`))}function sY(e){try{return O(nY(e))}catch(e){return k(uo(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function cY(e,t,n){let r=oY(e,t);if(r)return k(r);let i=sY(n);return A(i)?i:O(i.value.winding_numbers(e.vertices,e.triangles,t))}function lY(e,t,n){let r=oY(e,t);if(r)return k(r);let i=sY(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 uY=48,dY=2;function fY(e,t,n){let r=aY(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??uY,a=t?.padding??dY;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=sY(n);if(A(o))return o;try{try{var s=CT();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(fo(`VOXEL_REPAIR_FAILED`,e instanceof Error?e.message:`voxel repair failed (grid too large?).`,e))}}var pY=.001;function mY(e,t=pY){try{let n=Tk(e,{tolerance:t});return n.vertices.length===0||n.triangles.length===0?k(fo(`VOXEL_SHAPE_MESH_EMPTY`,`shape tessellated to an empty triangle mesh.`)):O({vertices:n.vertices,triangles:n.triangles})}catch(e){return k(fo(`VOXEL_SHAPE_MESH_FAILED`,e instanceof Error?e.message:`failed to mesh shape for voxel op.`,e))}}var hY=48,gY=2,_Y={union:0,intersection:1,difference:2};function vY(e){let t=e?.resolution??hY,n=e?.padding??gY;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 yY(e){if(e.positions.length===0||e.indices.length===0)return k(fo(`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 bY(e,t,n,r){let i=aY(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=vY(n);if(A(a))return a;let o=sY(r);if(A(o))return o;try{try{var s=CT();return yY(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(fo(`VOXEL_OFFSET_FAILED`,e instanceof Error?e.message:`voxel offset failed (grid too large?).`,e))}}function xY(e,t,n,r){let i=aY(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=vY(n);if(A(a))return a;let o=sY(r);if(A(o))return o;try{try{var s=CT();return yY(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(fo(`VOXEL_SHELL_FAILED`,e instanceof Error?e.message:`voxel shell failed (grid too large?).`,e))}}function SY(e,t,n,r,i){let a=aY(e);if(a)return k(a);let o=aY(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=_Y[n],c=vY(r);if(A(c))return c;let l=sY(i);if(A(l))return l;try{try{var u=CT();return yY(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(fo(`VOXEL_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel boolean failed (grid too large?).`,e))}}function CY(e,t,n,r){let i=mY(e);return A(i)?i:bY(i.value,t,n,r)}function wY(e,t,n,r){let i=mY(e);return A(i)?i:xY(i.value,t,n,r)}function TY(e,t,n,r,i){let a=mY(e);if(A(a))return a;let o=mY(t);return A(o)?o:SY(a.value,o.value,n,r,i)}var EY=48,DY=2,OY={union:0,intersection:1,difference:2};function kY(e){let t=e?.resolution??EY,n=e?.padding??DY;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 AY(e){try{var t=CT();let n=e.contour(),{positions:r,normals:i,indices:a}=t.u({value:n,[Symbol.dispose](){n.free()}}).value;if(r.length===0||a.length===0)return k(fo(`VOXEL_DEGENERATE_RESULT`,`the voxel field contoured to an empty mesh (over-shrunk offset or disjoint operands?).`));let o=r.length/3;return O({vertices:r,normals:i,triangles:a,uvs:new Float32Array(o*2),faceGroups:[{start:0,count:a.length/3,faceHash:0}]})}catch(e){t.e=e}finally{t.d()}}function jY(e){return{raw:e,delete(){e.free()}}}function MY(e){return NY(e)}function NY(e){let t=PT(jY(e)),n={get value(){return t.value.raw},get disposed(){return t.disposed},[Symbol.dispose](){t[Symbol.dispose]()},boolean(e,t){return this.value.boolean(e.value,OY[t]),n},offset(e){return this.value.offset(e),n},shell(e){return this.value.shell(e),n},reinit(){return this.value.reinit(),n},contour(){let e=AY(this.value);if(A(e))throw Error(e.error.message);return e.value}};return n}function PY(e){return!e.disposed}function FY(){return k(F(`VOXEL_FIELD_DISPOSED`,`the voxel field handle has been disposed.`))}function IY(e,t,n){let r=aY(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelField requires a non-empty triangle mesh.`));let i=kY(t);if(A(i))return i;let a=sY(n);if(A(a))return a;try{return O(NY(new a.value.VoxelField(e.vertices,e.triangles,i.value.resolution,i.value.padding)))}catch(e){return k(fo(`VOXEL_FIELD_VOXELIZE_FAILED`,e instanceof Error?e.message:`voxel field voxelization failed (grid too large or non-dense?).`,e))}}function LY(e,t,n,r,i){let a=aY(e);if(a)return k(a);let o=aY(t);if(o)return k(o);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBooleanField requires a non-empty mesh for operand A.`));if(t.vertices.length===0||t.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBooleanField requires a non-empty mesh for operand B.`));let s=kY(r);if(A(s))return s;let c=sY(i);if(A(c))return c;try{return O(NY(c.value.VoxelField.boolean_of(e.vertices,e.triangles,t.vertices,t.triangles,OY[n],s.value.resolution,s.value.padding)))}catch(e){return k(fo(`VOXEL_FIELD_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel field boolean failed (grid too large or non-dense?).`,e))}}function RY(e,t,n){if(!PY(e)||!PY(t))return FY();try{return e.value.boolean(t.value,OY[n]),O(e)}catch(e){return k(fo(`VOXEL_FIELD_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel field boolean failed (dim mismatch?).`,e))}}function zY(e,t){if(!PY(e))return FY();if(!Number.isFinite(t))return k(F(`VOXEL_INVALID_DISTANCE`,`distance must be a finite number.`));try{return e.value.offset(t),O(e)}catch(e){return k(fo(`VOXEL_FIELD_OFFSET_FAILED`,e instanceof Error?e.message:`voxel field offset failed.`,e))}}function BY(e,t){if(!PY(e))return FY();if(!Number.isFinite(t)||t<=0)return k(F(`VOXEL_INVALID_THICKNESS`,`thickness must be a finite number > 0.`));try{return e.value.shell(t),O(e)}catch(e){return k(fo(`VOXEL_FIELD_SHELL_FAILED`,e instanceof Error?e.message:`voxel field shell failed.`,e))}}function VY(e){if(!PY(e))return FY();try{return e.value.reinit(),O(e)}catch(e){return k(fo(`VOXEL_FIELD_REINIT_FAILED`,e instanceof Error?e.message:`voxel field reinit failed.`,e))}}function HY(e){if(!PY(e))return FY();try{return AY(e.value)}catch(e){return k(fo(`VOXEL_FIELD_CONTOUR_FAILED`,e instanceof Error?e.message:`voxel field contour failed.`,e))}}function UY(e,t,n){let r=mY(e);return A(r)?r:IY(r.value,t,n)}function WY(e,t,n,r,i){let a=mY(e);if(A(a))return a;let o=mY(t);return A(o)?o:LY(a.value,o.value,n,r,i)}var GY=48,KY=2;function qY(e){try{return O(nY(e))}catch(e){return k(uo(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function JY(e){let t=e?.resolution??GY,n=e?.padding??KY;return!Number.isInteger(t)||t<1?k(F(`SDF_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(F(`SDF_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function YY(e){return{raw:e,delete(){e.free()}}}var XY={offsetField(e){return ZY(this.value.offset_field(e.value))},roundField(e){return ZY(this.value.round_field(e.value))},shellField(e){return ZY(this.value.shell_field(e.value))},smoothUnionField(e,t){return ZY(this.value.smooth_union_field(e.value,t.value))}};function ZY(e){let t=PT(YY(e));return{get value(){return t.value.raw},get disposed(){return t.disposed},[Symbol.dispose](){t[Symbol.dispose]()},union(e){return ZY(this.value.union(e.value))},intersection(e){return ZY(this.value.intersection(e.value))},difference(e){return ZY(this.value.difference(e.value))},smoothUnion(e,t){return ZY(this.value.smooth_union(e.value,t))},smoothIntersection(e,t){return ZY(this.value.smooth_intersection(e.value,t))},smoothDifference(e,t){return ZY(this.value.smooth_difference(e.value,t))},offset(e){return ZY(this.value.offset(e))},round(e){return ZY(this.value.round(e))},shell(e){return ZY(this.value.shell(e))},onion(e){return ZY(this.value.onion(e))},...XY,translate(e,t,n){return ZY(this.value.translate(e,t,n))},rotate(e,t,n,r){return ZY(this.value.rotate(e,t,n,r))},scale(e){return ZY(this.value.scale(e))},rasterize(e){return QY(this.value,e)},rasterizeIn(e,t){return $Y(this.value,e,t)}}}function QY(e,t){let n=JY(t);if(A(n))return n;try{return O(MY(e.rasterize(n.value.resolution,n.value.padding)))}catch(e){return eX(e)}}function $Y(e,t,n){let r=JY(n);if(A(r))return r;let i=tX(t);if(i)return k(i);try{return O(MY(e.rasterize_in(t.min[0],t.min[1],t.min[2],t.max[0],t.max[1],t.max[2],r.value.resolution,r.value.padding)))}catch(e){return eX(e)}}function eX(e){return k(fo(`SDF_RASTERIZE_FAILED`,e instanceof Error?e.message:`SDF rasterization failed (grid too large?).`,e))}function tX(e){if(![...e.min,...e.max].every(e=>Number.isFinite(e)))return F(`SDF_INVALID_BOUNDS`,`bounds must be finite numbers.`);for(let t=0;t<3;t++)if(e.max[t]<=e.min[t])return F(`SDF_INVALID_BOUNDS`,`bounds max must exceed min on every axis.`);return null}function nX(e,t){let n=qY(t);if(A(n))return n;try{return O(ZY(e(n.value)))}catch(e){return k(fo(`SDF_BUILD_FAILED`,e instanceof Error?e.message:`SDF primitive construction failed.`,e))}}function rX(e,t){return nX(t=>t.Sdf.sphere(e),t)}function iX(e,t,n,r){return nX(r=>r.Sdf.box_(e,t,n),r)}function aX(e,t,n,r,i){return nX(i=>i.Sdf.rounded_box(e,t,n,r),i)}function oX(e,t,n){return nX(n=>n.Sdf.cylinder(e,t),n)}function sX(e,t,n){return nX(n=>n.Sdf.cone(e,t),n)}function cX(e,t,n,r){return nX(r=>r.Sdf.capsule(e[0],e[1],e[2],t[0],t[1],t[2],n),r)}function lX(e,t,n){return nX(n=>n.Sdf.torus(e,t),n)}function uX(e,t,n){return nX(n=>n.Sdf.plane(e[0],e[1],e[2],t),n)}function dX(e){if(e.length<2)return k(F(`SDF_INVALID_SPINE`,`sweep spine needs at least 2 points.`));let t=new Float64Array(e.length*3);for(let n=0;n<e.length;n++){let r=e[n];if(!r.every(e=>Number.isFinite(e)))return k(F(`SDF_INVALID_SPINE`,`sweep spine coordinates must be finite.`));t[n*3]=r[0],t[n*3+1]=r[1],t[n*3+2]=r[2]}return O(t)}function fX(e,t,n,r){let i=dX(e);if(A(i))return i;let a=n?.closed??!1;return nX(e=>e.Sdf.sweep(i.value,t.value,a),r)}var pX={gyroid:0,schwarzP:1,diamond:2};function mX(e,t,n,r){let i=pX[e];return i===void 0?k(F(`SDF_INVALID_LATTICE_KIND`,`unknown lattice kind: ${e}`)):nX(e=>e.Sdf.lattice(i,t.value,n.value),r)}function hX(e,t,n){return nX(n=>n.Sdf.strut_lattice(e,t.value),n)}function gX(e){return{raw:e,delete(){e.free()}}}function _X(e){let t=PT(gX(e));return{get value(){return t.value.raw},get disposed(){return t.disposed},[Symbol.dispose](){t[Symbol.dispose]()}}}function vX(e,t){let n=qY(t);if(A(n))return n;try{return O(_X(e(n.value)))}catch(e){return k(fo(`SDF_FIELD_BUILD_FAILED`,e instanceof Error?e.message:`scalar field construction failed.`,e))}}function yX(e,t){return vX(t=>t.ScalarField.constant(e),t)}function bX(e,t,n,r,i,a){return vX(a=>a.ScalarField.axial_ramp(e,t,n,r,i),a)}function xX(e,t,n,r,i,a,o){return vX(o=>o.ScalarField.radial_ramp(e[0],e[1],e[2],t,n,r,i,a),o)}function SX(e,t,n,r){return vX(r=>r.ScalarField.from_sdf(e.value,t,n),r)}function CX(e,t,n,r){return vX(r=>r.ScalarField.clamp(e.value,t,n),r)}var wX={gyroid:0,schwarzP:1,diamond:2},TX=48,EX=2;function DX(e){let t=wX[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??TX,r=e.padding??EX;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 OX(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 kX(e,t,n){let r=aY(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=DX(t);if(A(i))return i;let a=sY(n);if(A(a))return a;let{tag:o,period:s,thickness:c,resolution:l,padding:u}=i.value;try{try{var d=CT();return O(OX(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(fo(`LATTICE_INFILL_FAILED`,e instanceof Error?e.message:`lattice infill failed (grid too large?).`,e))}}function AX(e,t,n){let r=mY(e);return A(r)?r:kX(r.value,t,n)}function jX(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=DX(t);if(A(r))return r;let i=sY(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=CT();return O(OX(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(fo(`TPMS_LATTICE_FAILED`,e instanceof Error?e.message:`tpms lattice failed (grid too large?).`,e))}}function MX(e){return U().createVector3d(e[0],e[1],e[2])}function NX(e){return U().createPoint3d(e[0],e[1],e[2])}function PX(e){return U().createDirection3d(e[0],e[1],e[2])}function FX(e){return[e.X(),e.Y(),e.Z()]}function IX(e){return[e.X(),e.Y(),e.Z()]}function LX(e){return[e.X(),e.Y(),e.Z()]}function RX(e,t){let n=MX(e);try{return t(n)}finally{n.delete()}}function zX(e,t){let n=NX(e);try{return t(n)}finally{n.delete()}}function BX(e,t){let n=PX(e);try{return t(n)}finally{n.delete()}}var VX=.299,HX=.587,UX=.114;function WX(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 GX(e,n,r,s,c,o)}catch{}try{return KX(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 GX(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 bE(s)?O(s):(s[Symbol.dispose](),k(P(N.SURFACE_FAILED,`B-spline surface did not produce a face`)))}function KX(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 bE(s)||xE(s)?O(s):(s[Symbol.dispose](),k(P(N.SURFACE_FAILED,`surfaceFromGrid: unexpected shape type from sewing`)))}async function qX(e,t={}){let n=t.channel??`luminance`,r=Math.max(1,Math.round(t.downsample??1));if(typeof createImageBitmap!=`function`)return k(po(N.SURFACE_FAILED,`surfaceFromImage requires createImageBitmap (not available in this environment)`));let i;try{i=await createImageBitmap(e)}catch(e){return k(po(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(po(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(po(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=(VX*o+HX*s+UX*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),WX(l,u)}function JX(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function YX(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=JX(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 SE(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 XX(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 SE(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 ZX(e){let n=zE(e);if(n.length!==1)return null;let r=t(n,0);if(eD(r)!==`sphere`)return null;let i=U().area(r.wrapped);return Math.sqrt(i/(4*Math.PI))}function QX(e,t,n){try{let r=W(U().offset(e.wrapped,t,n));return wE(r)?O(r):(r[Symbol.dispose](),k(co(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 $X(e,t,n){let r=U();try{let i=VE(e),a=VE(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 wE(s)?O(s):(s[Symbol.dispose](),k(co(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 eZ(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(!wE(e)||!wE(t))return k(F(N.MINKOWSKI_NOT_3D,`minkowski: both shape and tool must be 3D`));let i=ZX(t);return i===null?$X(e,t,r):QX(e,i,r)}function tZ(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 SE(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 nZ=1e-10;function rZ(e,t,n,r){return e*r-t*n}function iZ(e,t,n,r){return e*n+t*r}function aZ(e,t){return Math.sqrt(e*e+t*t)}function oZ(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 sZ(e){let t=0;for(let n=0;n<e.length;n++){let r=oZ(e,n),i=oZ(e,n+1);t+=r.x*i.y-i.x*r.y}return t<0?[...e].reverse():e}function cZ(e,t){let n=oZ(e,t-1),r=oZ(e,t),i=oZ(e,t+1),a=r.x-n.x,o=r.y-n.y,s=aZ(a,o),c=i.x-r.x,l=i.y-r.y,u=aZ(c,l);if(s<nZ||u<nZ)return{dx:0,dy:0};let d=-o/s,f=a/s,p=-l/u,m=c/u,h=d+p,g=f+m,_=aZ(h,g);if(_<nZ)return{dx:d,dy:f};h/=_,g/=_;let v=iZ(h,g,d,f),y=Math.abs(v)>nZ?1/v:1;return{dx:h*y,dy:g*y}}function lZ(e){return!e.prev||!e.next?!1:rZ(e.x-e.prev.x,e.y-e.prev.y,e.next.x-e.x,e.next.y-e.y)<-1e-10}function uZ(e){let t=e.map((t,n)=>{let r=cZ(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 dZ(e,t){let n=e;for(let e=0;e<t&&n;e++)n.active=!1,n=n.next}function fZ(e){let t=1,n=e.next;for(;n!==e&&(t++,n=n.next,!(t>1e4)););return t}function pZ(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)<nZ&&Math.abs(r)<nZ)return null;let o;if(o=Math.abs(n)>Math.abs(r)?i/n:a/r,o<nZ)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)>nZ){let e=c/s;if(Math.abs(o-e)>1e-4*Math.max(1,Math.abs(o)))return null}return o}function mZ(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=aZ(r,i);if(a<nZ)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)<nZ)return null;let f=-c/d;if(f<nZ)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=aZ(y,b);if(x<nZ)return f;let S=iZ(p-h,m-g,y,b)/(x*x);return S<-.01||S>1.01?null:f}function hZ(e){let t=[];for(let n of e){if(!n.active||!n.next)continue;let e=pZ(n,n.next);if(e!==null&&e>nZ){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(lZ(n)){let e=n.next.next,r=0;for(;e!==n.prev&&e!==n&&r<1e3;){let i=mZ(n,e,e.next);if(i!==null&&i>nZ){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 gZ(e){if(e.length<3)return O({nodes:[],faces:[]});try{return O(_Z(e))}catch(e){return k(fo(N.STRAIGHT_SKELETON_FAILED,e instanceof Error?e.message:String(e),e))}}function _Z(e){let t=sZ(e),n=t.length,r=[],i=Array.from({length:n},()=>[]),a=uZ(t),o=0,s=n*n*2;for(;o<s;){o++;let e=a.find(e=>e.active);if(!e)break;let t=fZ(e);if(t<=3){if(t===3){let t=e,n=t.next,a=n.next,o=pZ(t,n),s=o!==null&&o>nZ?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 dZ(e,t);continue}let n=a.filter(e=>e.active),s=hZ(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=cZ(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=cZ(f(e),0);e.bx=p.dx,e.by=p.dy;let m=cZ(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=[oZ(t,e),oZ(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&&aZ(n.x-i.x,n.y-i.y)>nZ&&(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 vZ(e){let t=RE(e).map(e=>{let t=tk(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 yZ(e){let t=[];for(let n=1;n<e-1;n++)t.push([0,n,n+1]);return t}function bZ(e,t,n,r,i,a){return(n-e)*(a-t)-(r-t)*(i-e)}function xZ(e,t,n,r,i,a,o,s){let c=bZ(n,r,i,a,e,t),l=bZ(i,a,o,s,e,t),u=bZ(o,s,n,r,e,t);return!((c<0||l<0||u<0)&&(c>0||l>0||u>0))}function SZ(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||bZ(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&&xZ(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 CZ(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=yZ(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 wZ(e,t){let n=(t?.angle??45)*iD,r=Math.tan(n);try{let t=vZ(e);if(t.length<3)return k(P(N.ROOF_FAILED,`Wire must have at least 3 edges for roof generation`));let n=gZ(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=CZ(i,r,a);for(let[e,n,r]of SZ(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(mE(a.fixShape(e)))}catch(e){try{let t=mE(a.sew(o,1e-6));return $T(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 TZ={coincident:3,concentric:4,distance:1,angle:1},EZ=[1,0,0,0];function DZ(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function OZ(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function kZ(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function AZ(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 jZ(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function MZ(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function NZ(e){return MZ(AZ(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function PZ(e,t){let n=DZ(qM(t.rotation,e.origin),t.position);return{type:e.type,origin:n,...e.normal?{normal:qM(t.rotation,e.normal)}:{},...e.direction?{direction:qM(t.rotation,e.direction)}:{}}}function FZ(e,t,n){let r=e.normal??[0,0,1];return{position:jZ(r,kZ(r,OZ(e.origin,t.origin))+n),rotation:EZ}}function IZ(e,t){let n=e.direction??[0,0,1],r=YM(t.direction??[0,0,1],n),i=qM(r,t.origin);return{position:OZ(e.origin,i),rotation:r}}function LZ(e,t,n){let r=MZ(e.normal??[0,0,1]),i=MZ(t.normal??[0,0,1]),a=Math.acos(Math.max(-1,Math.min(1,kZ(i,r)))),o=AZ(i,r);return{position:[0,0,0],rotation:JM(Math.hypot(o[0],o[1],o[2])<1e-9?NZ(i):o,a-n)}}function RZ(e,t,n){let r=OZ(t,e),i=Math.hypot(r[0],r[1],r[2]);return{position:OZ(DZ(e,jZ(i<1e-9?[1,0,0]:jZ(r,1/i),n)),t),rotation:EZ}}function zZ(e,t,n,r){let i=MZ(e);return{position:jZ(i,kZ(i,OZ(t,n))-r),rotation:EZ}}function BZ(e,t,n){let r=MZ(e.direction??[0,0,1]),i=DZ(e.origin,jZ(r,kZ(r,OZ(t,e.origin))));if(n===0)return{position:OZ(i,t),rotation:EZ};let a=OZ(t,i),o=Math.hypot(a[0],a[1],a[2]);return{position:OZ(DZ(i,jZ(o<1e-9?NZ(r):jZ(a,1/o),n)),t),rotation:EZ}}function VZ(e,t,n){let r=MZ(t.direction??[0,0,1]),i=OZ(t.origin,e),a=OZ(i,jZ(r,kZ(r,i))),o=Math.hypot(a[0],a[1],a[2]);return n===0?{position:jZ(a,-1),rotation:EZ}:{position:OZ(jZ(o<1e-9?NZ(r):jZ(a,1/o),n),a),rotation:EZ}}function HZ(e,t,n){let r=MZ(e.direction??[0,0,1]),i=YM(MZ(t.direction??[0,0,1]),r),a=OZ(qM(i,t.origin),e.origin),o=OZ(a,jZ(r,kZ(r,a))),s=Math.hypot(o[0],o[1],o[2]);return{position:OZ(jZ(s<1e-9?NZ(r):jZ(o,1/s),n),o),rotation:i}}var UZ=new Set([`plane-plane`,`plane-point`,`point-plane`,`point-point`,`axis-axis`,`axis-point`,`point-axis`]),WZ={angle:`plane`,concentric:`axis`},GZ=new Set([`coincident`,`distance`,`angle`,`concentric`]);function KZ(e,t,n){let r=WZ[e];return r?t===r&&n===r:UZ.has(`${t}-${n}`)}function qZ(e,t,n){switch(`${e.type}-${t.type}`){case`plane-plane`:case`plane-point`:return FZ(e,t,n);case`point-plane`:return zZ(t.normal??[0,0,1],e.origin,t.origin,n);case`point-point`:return RZ(e.origin,t.origin,n);case`axis-axis`:return n===0?IZ(e,t):HZ(e,t,n);case`axis-point`:return BZ(e,t.origin,n);case`point-axis`:return VZ(e.origin,t,n);default:return null}}function JZ(e,t,n){switch(e.type){case`concentric`:return IZ(t,n);case`angle`:return LZ(t,n,(e.value??0)*Math.PI/180);default:{let r=qZ(t,n,e.type===`distance`?e.value??0:0);if(!r)throw Error(`solveMate: unsupported entity pair escaped filter: ${t.type}-${n.type}`);return r}}}function YZ(e,t){let n=new Map;for(let t of e)n.set(t,{position:[0,0,0],rotation:EZ});let r=[],i=t.filter(e=>GZ.has(e.type)&&e.entityA&&e.entityB),a=new Set;for(let e of i)e.entityB&&a.add(e.entityB.node);let o=new Set;for(let t of e)a.has(t)||o.add(t);for(let e of t)e.type===`fixed`&&e.entityA&&o.add(e.entityA.node);let s=[];for(let e of i){if(!e.entityA||!e.entityB)continue;let t=e.entityA.entity.type,n=e.entityB.entity.type;if(!KZ(e.type,t,n)){r.push(`${e.type}(${t}-${n})`);continue}s.push(e)}let c=!0;for(;c&&s.length>0;){c=!1;for(let e=s.length-1;e>=0;e--){let t=s[e];if(!t?.entityA||!t.entityB)continue;let r=t.entityA,i=t.entityB;if(!o.has(r.node)||(s.splice(e,1),c=!0,o.has(i.node)))continue;let a=n.get(r.node)??{position:[0,0,0],rotation:EZ},l=PZ(r.entity,a);n.set(i.node,JZ(t,l,i.entity)),o.add(i.node)}}for(let e of s)r.push(`${e.type}(unanchored)`);return{transforms:n,dof:r.reduce((e,t)=>e+(TZ[t]??TZ[t.split(`(`)[0]??``]??0),0),converged:r.length===0,unsupported:r}}function XZ(e){if(e.face){let t=tO(e.face);return t?{type:`axis`,origin:t.origin,direction:t.direction}:{type:`plane`,origin:eO(e.face),normal:$D(e.face)}}if(e.edge){if(ek(e.edge)===`LINE`)return{type:`axis`,origin:tk(e.edge),direction:ik(e.edge)};let t=ok(e.edge);return t?{type:`axis`,origin:t.origin,direction:t.direction}:null}return e.point?{type:`point`,origin:e.point}:null}function ZZ(e,t){let n=XZ(e),r=XZ(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 QZ(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=ZZ(e.entityA,e.entityB);return t.ok?O({type:`coincident`,...t.value}):t}case`distance`:{let t=ZZ(e.entityA,e.entityB);return t.ok?O({type:`distance`,...t.value,value:e.distance}):t}case`angle`:{let t=ZZ(e.entityA,e.entityB);return t.ok?O({type:`angle`,...t.value,value:e.angle}):t}case`concentric`:{let t=ZZ(e.axisA,e.axisB);return t.ok?O({type:`concentric`,...t.value}):t}}}function $Z(e,t){let n=e.mates??[];return{...e,mates:[...n,t]}}function eQ(e){let t=e.mates;if(!t||t.length===0)return k(F(N.ASSEMBLY_MATE_INVALID,`solveAssembly: no mates defined`));try{let n=[];BM(e,e=>{n.push(e.name)});let r=[];for(let e of t){let t=QZ(e);if(!t.ok)return t;r.push(t.value)}let i=YZ(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 tQ(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 nQ(e,n=1e-6){let r=[],i=e.map(e=>QE(e));return e.forEach((a,o)=>{for(let s=o+1;s<e.length;s++){if(rQ(t(i,o),t(i,s),n))continue;let c=j(tQ(a,t(e,s),n));c.hasInterference&&r.push({i:o,j:s,result:c})}}),r}function rQ(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 iQ(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 aQ(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 oQ(e){let{type:t,data:n}=e,r=U();if(t===`LINE`)return r.makeLineEdge([aQ(n,10),aQ(n,20),aQ(n,30)],[aQ(n,11),aQ(n,21),aQ(n,31)]);if(t===`CIRCLE`)return r.makeCircleEdge([aQ(n,10),aQ(n,20),aQ(n,30)],[0,0,1],aQ(n,40));if(t===`ARC`){let e=aQ(n,50)*Math.PI/180,t=aQ(n,51)*Math.PI/180;return r.makeCircleArc([aQ(n,10),aQ(n,20),aQ(n,30)],[0,0,1],aQ(n,40),e,t)}}async function sQ(e,t){let n;try{n=await e.text()}catch(e){return k(po(N.DXF_IMPORT_FAILED,`Failed to read DXF blob`,e))}let r=iQ(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=oQ(e);t!==void 0&&a.push(t)}return a.length===0?O([]):O([dE(U().makeWire(a))])}catch(e){return k(po(N.DXF_IMPORT_FAILED,`Failed to convert DXF entities to geometry`,e))}finally{for(let e of a)e.delete()}}function cQ(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(po(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(po(t,`Failed to sew triangular faces`))}}}function lQ(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 uQ(e){return e.split(/\s+/).slice(1).map(e=>parseInt(e.split(`/`)[0]??``,10)).filter(e=>!isNaN(e))}async function dQ(e){let t=(await e.text()).split(`
|
|
60
|
-
`),n=[],r=[];for(let e of t){let t=e.trim();if(t.startsWith(`v `)){let e=lQ(t);e&&n.push(e)}else if(t.startsWith(`f `)){let e=uQ(t);e.length>=3&&r.push(e)}}if(n.length===0||r.length===0)return k(po(N.OBJ_IMPORT_FAILED,`OBJ file contains no valid geometry`));try{return fQ(n,r)}catch(e){let t=e instanceof Error?e.message:String(e);return k(po(N.OBJ_IMPORT_FAILED,`OBJ import failed: ${t}`,e))}}function fQ(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 cQ(n,N.OBJ_IMPORT_FAILED)}function pQ(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 mQ(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95}function hQ(e){let t={},n=0;for(;n<e.length;){let r=e.indexOf(`="`,n);if(r<0)break;let i=r;for(;i>0&&mQ(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 gQ(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 _Q(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 vQ(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 yQ(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=hQ(e.slice(r,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of gQ(a,`color`)){let t=hQ(e).color;t!==void 0&&l.push(vQ(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=hQ(e.slice(n,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of gQ(a,`base`)){let t=hQ(e).displaycolor;t===void 0?l.push([0,0,0,1]):l.push(vQ(t))}t.set(c,l)}return t}function bQ(e){let t=[],n=[],r=[],i=yQ(e);for(let n of gQ(e,`vertex`)){let e=hQ(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=_Q(e,`object`);if(s!==null){let e=s.indexOf(`>`);if(e>=0){let t=hQ(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 gQ(e,`triangle`)){let e=hQ(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 xQ(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 SQ(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 cQ(t,N.THREEMF_IMPORT_FAILED)}}async function CQ(e){try{let t=await e.arrayBuffer(),n=pQ(new Uint8Array(t),`3D/3dmodel.model`);if(!n)return k(po(N.THREEMF_IMPORT_FAILED,`3MF archive does not contain 3D/3dmodel.model (or uses unsupported compression)`));let r=bQ(new TextDecoder().decode(n));if(r.vertices.length===0||r.triangles.length===0)return k(po(N.THREEMF_IMPORT_FAILED,`3MF model contains no valid geometry`));let i=SQ(r);if(i.ok){let e=xQ(r.triangleColors);e!==null&&OO(i.value,e)}return i}catch(e){let t=e instanceof Error?e.message:String(e);return k(po(N.THREEMF_IMPORT_FAILED,`3MF import failed: ${t}`,e))}}async function wQ(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(po(N.GLB_IMPORT_FAILED,`Failed to import GLB: ${t}`,e))}}function $(e){return`__wrapped`in e?e.val:e}function TQ(e){return $(e)}function EQ(e,t){return IO($(e),t)}function DQ(e,t,n){let r=n?.at;return LO($(e),t,r,n?.axis)}function OQ(e,t){let n=t?.at;return RO($(e),t?.normal??[1,0,0],n)}function kQ(e,t,n){return zO($(e),t,n?.center)}function AQ(e){return qO($(e))}function jQ(e,t){return WO($(e),t)}function MQ(e,t){return KO($(e),t)}function NQ(e,t,n){return iA($(e),$(t),{...n,unsafe:!0})}function PQ(e,t,n){return aA($(e),$(t),{...n,unsafe:!0})}function FQ(e,t,n){return oA($(e),$(t),{...n,unsafe:!0})}function IQ(e,t,n){return dA($(e),t,n)}function LQ(e,t,n){return _A($(e),t,n)}function RQ(e,t){return vA($(e),t)}function zQ(e,t,n){return yA($(e),t,n)}function BQ(e,t){if(e!==void 0)return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(YP()).findAll(t)}function VQ(e,t){return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(QP()).findAll(t)}function HQ(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 UQ(e,t,n){let r=$(e),i,a;return n===void 0?(i=void 0,a=t):(i=BQ(t,r),a=n),Tj(r,i,a)}function WQ(e,t,n){let r=$(e),i,a;n===void 0?(i=void 0,a=t):(i=BQ(t,r),a=n);let o=HQ(a);return o.mode===`distAngle`?LA(r,[...i??RE(r)],o.distance,o.angle):Ej(r,i,o.distance)}function GQ(e,t,n,r){let i=$(e);return Dj(i,VQ(t,i),n,r?.tolerance)}function KQ(e,t,n){return Oj($(e),t,n?.tolerance)}function qQ(e,t){return Cj($(e),t)}function JQ(e,t,n){let r=$(e);return Aj(r,VQ(t,r),n.pullDirection,n.neutralPlane,n.angle)}function YQ(e){return Ij($(e))}function XQ(e){return $O($(e))}function ZQ(e,t){return Tk($(e),t)}function QQ(e,t){return Ek($(e),t)}function $Q(e){return nD($(e))}function e$(e){return JO($(e))}function t$(e){return UD(e)}function n$(e){return Mj($(e))}function r$(e){return XO($(e))}function i$(e,t){return Qj($(e),typeof t==`number`?[0,0,t]:t)}function a$(e,t){let n=t?.at??[0,0,0];return $j($(e),n,t?.axis??[0,0,1],t?.angle??360)}function o$(e,t){return tM(e.map(e=>$(e)),t)}function s$(e,n){if(n===void 0){let t=zE(e);if(t.length===0)return k(F(N.COMPOUND_NO_FACES,`compoundOps: shape has no faces`));let n=Fk(t),r=eO(n)[2];for(let e=1;e<t.length;e++){let i=Pk(t,e),a=eO(i)[2];a>r&&(n=i,r=a)}return O(n)}if(typeof n==`function`){let r=n(QP()).findAll(e);return r.length===0?k(mo(N.COMPOUND_FACE_NOT_FOUND,`compoundOps: face finder matched no faces`)):O(t(r,0))}return O(n)}function c$(e){return`sketchOnPlane`in e&&typeof e.sketchOnPlane==`function`?e.sketchOnPlane(`XY`).wire:e}function l$(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(xD(o))return k(F(`DRILL_ZERO_AXIS`,`Drill axis cannot be zero`));let s=yD(o),c=r.length===2?[r[0],r[1],0]:[r[0],r[1],r[2]],l;if(t.depth!==void 0)l=wA(i,t.depth,c,s);else{let e=QE(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=wA(i,a-r,[c[0]+s[0]*r,c[1]+s[1]*r,c[2]+s[2]*r],s)}return aA(n,l,{unsafe:!0})}function u$(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=s$(n,t.face);if(A(a))return a;let o=a.value,s=$D(o),c=eO(o),l=Xk(c$(r));if(A(l))return l;let u=Qj(IO(l.value,c),fD(yD(s),-i));return A(u)?u:aA(n,u.value,{unsafe:!0})}function d$(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=s$(n,t.face);if(A(a))return a;let o=a.value,s=$D(o),c=eO(o),l=Xk(c$(r));if(A(l))return l;let u=Qj(IO(l.value,c),fD(yD(s),i));return A(u)?u:iA(n,u.value,{unsafe:!0})}function f$(e,t){let n=$(e),r=t?.normal??[1,0,0],i=t?.at;return xD(r)?k(F(`MIRROR_ZERO_NORMAL`,`Mirror plane normal cannot be zero`)):iA(n,RO(n,r,i),{unsafe:!0})}function p$(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(xD(r))return k(F(`PATTERN_ZERO_DIRECTION`,`X direction cannot be zero`));if(xD(o))return k(F(`PATTERN_ZERO_DIRECTION`,`Y direction cannot be zero`));if(i===1&&s===1)return O(n);let l=yD(r),u=yD(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(IO(n,r))}return cA(d,{unsafe:!0})}var m$=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 h$(e){if(A(e))throw new m$(e.error);return e.value}function g$(e){return e}function _$(e){return e}function v$(e){return e}function y$(e){return e}function b$(e){return{val:e,__wrapped:!0,translate:t=>A$(EQ(e,t)),rotate:(t,n)=>A$(DQ(e,t,n)),mirror:t=>A$(OQ(e,t)),scale:(t,n)=>A$(kQ(e,t,n)),applyMatrix:t=>A$(h$(jQ(e,t))),moveX:t=>A$(EQ(e,[t,0,0])),moveY:t=>A$(EQ(e,[0,t,0])),moveZ:t=>A$(EQ(e,[0,0,t])),rotateX:t=>A$(DQ(e,t,{axis:[1,0,0]})),rotateY:t=>A$(DQ(e,t,{axis:[0,1,0]})),rotateZ:t=>A$(DQ(e,t,{axis:[0,0,1]})),bounds:()=>QE(e),describe:()=>$Q(e),clone:()=>A$(h$(AQ(e))),mesh:t=>ZQ(e,t),meshEdges:t=>QQ(e,t),isValid:()=>n$(e),isEmpty:()=>r$(e),heal:()=>A$(h$(YQ(e))),simplify:()=>A$(h$(XQ(e))),toBREP:()=>h$(e$(e)),apply:t=>A$(t(e)),applyResult:t=>A$(h$(t(e))),done:()=>e}}function x$(e){return{fuse:(t,n)=>j$(h$(NQ(e,$(t),{...n,unsafe:!0}))),cut:(t,n)=>j$(h$(PQ(e,$(t),{...n,unsafe:!0}))),intersect:(t,n)=>j$(h$(FQ(e,$(t),{...n,unsafe:!0}))),fuseAll:(t,n)=>j$(y$(h$(cA([e,...t.map($)],{...n,unsafe:!0})))),cutAll:(t,n)=>j$(y$(h$(lA(e,t,{...n,unsafe:!0})))),section:(t,n)=>A$(h$(IQ(e,t,n))),split:t=>A$(h$(RQ(e,t))),slice:(t,n)=>h$(zQ(e,t,n))}}function S$(e){return{fillet(...t){return t.length===1?j$(y$(h$(UQ(g$(e),t[0])))):j$(y$(h$(UQ(g$(e),t[0],t[1]))))},chamfer(...t){return t.length===1?j$(y$(h$(WQ(g$(e),t[0])))):j$(y$(h$(WQ(g$(e),t[0],t[1]))))},shell:(t,n,r)=>j$(y$(h$(GQ(g$(e),t,n,r)))),offset:(t,n)=>j$(y$(h$(KQ(g$(e),t,n)))),draft:(t,n)=>j$(y$(h$(JQ(g$(e),t,n))))}}function C$(e){return{drill:t=>j$(h$(l$(e,t))),pocket:t=>j$(h$(u$(e,t))),boss:t=>j$(h$(d$(e,t))),mirrorJoin:t=>j$(h$(f$(e,t))),rectangularPattern:t=>j$(h$(p$(e,t)))}}function w$(e){return{volume:()=>h$(_P(e)),area:()=>h$(vP(e)),volumeProps:()=>h$(mP(e)),surfaceProps:()=>h$(hP(e))}}function T$(e){return{edges:()=>RE(e),faces:()=>zE(e),wires:()=>BE(e),vertices:()=>VE(e)}}function E$(e){return{linearPattern:(t,n,r)=>j$(y$(h$(NM(e,t,n,r)))),circularPattern:(t,n,r)=>j$(y$(h$(PM(e,t,n,r))))}}function D$(e){return{...b$(e),...x$(e),...S$(e),...C$(e),...w$(e),...T$(e),...E$(e)}}function O$(e){return{...b$(e),length:()=>ak(e),startPoint:()=>tk(e),endPoint:()=>nk(e),pointAt:t=>rk(e,t),tangentAt:t=>ik(e,t),isClosed:()=>sk(e),sweep(t,n){if(!yE(e))throw Error(`sweep requires a Wire`);let r=h$(Wj(v$(e),$(t),n));return j$(Array.isArray(r)?r[0]:r)}}}function k$(e){return{...b$(e),area:()=>h$(vP(e)),normalAt:t=>$D(e,t),center:()=>eO(e),surfaceType:()=>h$(GD(e)),outerWire:()=>rO(e),innerWires:()=>aO(e),extrude:t=>j$(h$(i$(_$(e),t))),revolve:t=>j$(h$(a$(_$(e),t)))}}function A$(e){return wE(e)?D$(e):bE(e)?k$(e):vE(e)||yE(e)?O$(e):b$(e)}function j$(e){return D$(e)}function M$(e){if(e&&typeof e==`object`&&`face`in e&&typeof e.face==`function`&&`_defaultOrigin`in e)return k$(e.face());if(e&&typeof e==`object`&&`wrapped`in e)return bE(e)?k$(e):wE(e)?D$(e):vE(e)||yE(e)?O$(e):b$(e);throw Error(`shape() requires a Sketch or branded shape type`)}var N$=.25,P$=e=>Math.tan(e)-e;function F$(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 I$(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(F$(e,s*t,n,i))}return a}function L$(e){return Math.max(16,Math.round(8*Math.sqrt(e)))}function R$(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 z$(e,t,n){if(t===0)return O(e);let r=P$(e)+2*t*Math.tan(e)/n,i,a;if(r>P$(e)?(i=e,a=Math.PI/2-1e-6):(i=1e-4,a=e),r>P$(a)||r<P$(i))return k(F(`GEAR_PA_OUT_OF_RANGE`,`working pressure angle out of range — target inv(αw)=${r.toFixed(4)} not in [${P$(i).toFixed(4)}, ${P$(a).toFixed(4)}]`,void 0,{target:r,invLo:P$(i),invHi:P$(a)}));for(let e=0;e<50;e++){let e=.5*(i+a);P$(e)<r?i=e:a=e}return O(.5*(i+a))}function B$(e,t,n,r,i){return z$(e,t+n,r+i)}function V$(e,t,n,r,i){return z$(e,n-t,i-r)}function H$(e,t,n,r,i){return(e+t)*n*Math.cos(r)/(2*Math.cos(i))}function U$(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 W$(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 G$(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 K$(e,t){return 1-e*Math.sin(t)*Math.sin(t)/2}function q$(e,t,n){return Math.max(0,K$(e,t)-n)}function J$(e){return e<8?.2:.485-2.88/e}function Y$(e,t,n,r){let i=e*1e3,a=J$(r);return a<=0||n<=0||t<=0?1/0:2*i/(r*t*t*n*a)}function X$(e,t,n=!1){let r=(1.4+6.5/e)*(20/(t*180/Math.PI))**.15;return n?r*.85:r}function Z$(e,t,n,r,i,a=!1){return Y$(e,t,n,r)*X$(r,i,a)}function Q$(e){return e/2}function $$(e,t){return e+2*t}function e1(e){return e%2==0?Math.PI/e:0}function t1(e,t,n){return e*(1+t/n)+e1(n)}function n1(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=U$(n,r,i,s);if(A(c))return c;let l=B$(a,o,s,n,r);if(A(l))return l;let u=H$(n,r,t,a,l.value),d=[];for(let e=0;e<i;e++){let t=e*2*Math.PI/i,a=t1(t,n,r);d.push({rotationDeg:a*180/Math.PI,position:[u*Math.cos(t),u*Math.sin(t),0]})}return O(d)}function r1(e,t,n,r,i){let a=t*e.toothPitch,o=(t+1)%n*e.toothPitch,s=P$(e.alphaPitch),c=a-e.halfToothAngle-s,l=a+e.halfToothAngle+s,u=I$(e.rb,e.alphaTip,c,r,1),d=I$(e.rb,e.alphaTip,l,r,-1).reverse(),f=Fk(u),p=Ik(u),m=Fk(d),h=Ik(d),g=[],_=e=>{i.register(e),g.push(e)},v=e.isInternal?e.rb<e.rRoot:e.rb>e.rRoot;v&&_(zk([e.rRoot*Math.cos(c),e.rRoot*Math.sin(c),0],f));let y=e.rPitch*1e-5,b=Kk(u,{tolerance:y});if(A(b))return b;_(b.value),_(Uk(p,[e.rTip*Math.cos(a),e.rTip*Math.sin(a),0],m));let x=Kk(d,{tolerance:y});if(A(x))return x;_(x.value),v&&_(zk(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),_(Uk(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 i1(e){return o1(e,!1)}function a1(e){return o1(e,!0)}function o1(e,t){try{var n=CT();let{teeth:r,moduleSize:i,pressureAngle:a,shift:o,clearance:s,flankThinning:c,samples:l=L$(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=R$(r,i,a,o,s,c,t),d=n.u(new FT),f=[];for(let e=0;e<r;e++){let t=r1(u,e,r,l,d);if(A(t))return t;f.push(...t.value)}let p=Yk(f);return A(p)?p:O(p.value)}catch(e){n.e=e}finally{n.d()}}function s1(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=N$,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=R$(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=i1({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(f))return f;let p=l1(t,u,a);return m1(f.value,r,c,d,p)}function c1(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=N$,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=a1({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(d))return d;let f=R$(t,n,u,a,o,s,!0),p=p1(f.rPitch+c);return A(p)?p:g1(p.value,d.value,r,f,[])}function l1(e,t,n){let r=q$(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 u1(e){let t=f1(e);if(A(t))return t;let n=t.value,r=d1(n);if(A(r))return r;let{sun:i,planet:a,ring:o}=r.value,s=b1(n,i,a,o),c=v1(a.solid,n);a.solid.delete();let l=y1(o.solid,n.zr),u=x1(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 d1(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=s1({...n,teeth:e.sunTeeth,shift:e.sunShift,bore:e.sunBore});if(A(r))return r;let i=s1({...n,teeth:e.planetTeeth,shift:e.planetShift,bore:e.planetBore});if(A(i))return r.value.solid.delete(),i;let a=c1({...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 f1(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=U$(n,r,i,c);if(A(u))return u;let d=$$(n,r),f=B$(o,s,c,n,r);if(A(f))return f;let p=V$(o,c,l,r,d);if(A(p))return p;let m=H$(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:Q$(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 p1(e){try{var t=CT();let n=Yk([t.u(new FT).register(Bk(e,[0,0,0],[0,0,1]))]);return A(n)?n:O(n.value)}catch(e){t.e=e}finally{t.d()}}function m1(e,t,n,r,i){try{var a=CT();let o=Xk(e);if(A(o))return o;let s=Qj(o.value,[0,0,t]);if(A(s))return s;if(n<=0)return O(_1(s.value,r,i));let c=a.u(new FT),l=h1(n/2);if(A(l))return l;c.register(l.value);let u=Qj(l.value,[0,0,t+1]);if(A(u))return u;c.register(u.value);let d=c.register(IO(u.value,[0,0,-.5])),f=aA(s.value,d);return A(f)?f:O(_1(f.value,r,i))}catch(e){a.e=e}finally{a.d()}}function h1(e){let t=p1(e);return A(t)?t:Xk(t.value)}function g1(e,t,n,r,i){let a=Xk(e,[t]);if(A(a))return a;let o=Qj(a.value,[0,0,n]);return A(o)?o:O(_1(o.value,r,i))}function _1(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 v1(e,t){let n=[];try{for(let r=0;r<t.numPlanets;r++){let i=r*2*Math.PI/t.numPlanets,a=LO(e,t1(i,t.sunTeeth,t.planetTeeth)*180/Math.PI);try{let e=[t.centerDistance*Math.cos(i),t.centerDistance*Math.sin(i),0];n.push(IO(a,e))}finally{a.delete()}}return n}catch(e){for(let e of n)e.delete();throw e}}function y1(e,t){let n=e1(t);if(n===0)return e;let r=LO(e,n*180/Math.PI);return e.delete(),r}function b1(e,t,n,r){let i={crSunPlanet:W$(t.tipDiameter/2,t.baseDiameter/2,n.tipDiameter/2,n.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_sp),crPlanetRing:G$(n.tipDiameter/2,n.baseDiameter/2,r.tipDiameter/2,r.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_pr),undercutSun:q$(e.sunTeeth,e.alpha,e.sunShift),undercutPlanet:q$(e.planetTeeth,e.alpha,e.planetShift)};if(e.appliedTorque!==void 0){let t=e.appliedTorque;i.lewisStress={sun:Z$(t,e.moduleSize,e.thickness,e.sunTeeth,e.alpha),planet:Z$(t*e.planetTeeth/e.sunTeeth,e.moduleSize,e.thickness,e.planetTeeth,e.alpha),ring:Z$(t*e.zr/e.sunTeeth,e.moduleSize,e.thickness,e.zr,e.alpha,!0)},i.stressConcentrationFactor={sun:X$(e.sunTeeth,e.alpha),planet:X$(e.planetTeeth,e.alpha),ring:X$(e.zr,e.alpha,!0)}}return i}function x1(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 S1=HJ({addHoles:()=>kM,bezier:()=>gM,box:()=>rM,bsplineApprox:()=>hM,circle:()=>uM,compound:()=>TM,cone:()=>oM,cylinder:()=>iM,ellipse:()=>dM,ellipseArc:()=>mM,ellipsoid:()=>cM,face:()=>bM,fill:()=>Zk,filledFace:()=>xM,helix:()=>fM,line:()=>lM,offsetFace:()=>DM,polygon:()=>CM,polyhedron:()=>tZ,sewShells:()=>OM,solid:()=>EM,sphere:()=>aM,subFace:()=>SM,tangentArc:()=>_M,threePointArc:()=>pM,torus:()=>sM,vertex:()=>wM,wire:()=>vM,wireLoop:()=>yM}),C1=HJ({checkBoolean:()=>oj,convexHull:()=>XX,cut:()=>PQ,cutAll:()=>lA,cutAllBisect:()=>ZA,fuse:()=>NQ,fuseAll:()=>cA,fuseAllBisect:()=>tj,hull:()=>YX,intersect:()=>FQ,minkowski:()=>eZ,section:()=>IQ,sectionToFace:()=>LQ,slice:()=>zQ,split:()=>RQ}),w1=HJ({chamfer:()=>WQ,draft:()=>JQ,fillet:()=>UQ,heal:()=>YQ,offset:()=>KQ,shell:()=>GQ,simplify:()=>XQ,thicken:()=>qQ,variableFillet:()=>jj}),T1=HJ({applyMatrix:()=>jQ,clone:()=>AQ,composeTransforms:()=>GO,mirror:()=>OQ,rotate:()=>DQ,scale:()=>kQ,transformCopy:()=>MQ,translate:()=>EQ}),E1=HJ({checkAllInterferences:()=>nQ,checkInterference:()=>tQ,createDistanceQuery:()=>SP,measureArea:()=>vP,measureCurvatureAt:()=>CP,measureCurvatureAtMid:()=>wP,measureDistance:()=>bP,measureDistanceProps:()=>xP,measureLength:()=>yP,measureLinearProps:()=>gP,measureSurfaceProps:()=>hP,measureVolume:()=>_P,measureVolumeProps:()=>mP}),D1=HJ({blueprintToDXF:()=>Tq,exportAssemblySTEP:()=>MM,exportDXF:()=>wq,exportGlb:()=>dq,exportGltf:()=>uq,exportIGES:()=>Mk,exportOBJ:()=>eq,exportSTEP:()=>Ak,exportSTEPConfigured:()=>cJ,exportSTL:()=>jk,exportThreeMF:()=>Wq,importDXF:()=>sQ,importGLB:()=>wQ,importIGES:()=>dJ,importOBJ:()=>dQ,importSTEP:()=>lJ,importSTL:()=>uJ,importSVG:()=>sJ,importSVGPathD:()=>oJ,importThreeMF:()=>CQ}),O1=HJ({cornerFinder:()=>TI,edgeFinder:()=>YP,faceFinder:()=>QP,getSingleFace:()=>tF,vertexFinder:()=>ZJ,wireFinder:()=>eF}),k1=HJ({complexExtrude:()=>Kj,extrude:()=>i$,guidedSweep:()=>Zj,loft:()=>o$,multiSectionSweep:()=>Xj,revolve:()=>a$,roof:()=>wZ,supportExtrude:()=>Gj,surfaceFromGrid:()=>WX,surfaceFromImage:()=>qX,sweep:()=>Wj,twistExtrude:()=>qj}),A1=HJ({circularPattern:()=>PM,linearPattern:()=>NM}),j1=14695981039346656037n,M1=1099511628211n,N1=18446744073709551615n;function P1(){return j1}function F1(e,t){return(e^BigInt(t&255))*M1&N1}function I1(e,t){let n=e;for(let e=0;e<t.length;e++)n=F1(n,t[e]??0);return n}var L1=new TextEncoder;function R1(e,t){return I1(e,L1.encode(t))}var z1=new ArrayBuffer(8),B1=new DataView(z1),V1=new Uint8Array(z1);function H1(e,t){return B1.setFloat64(0,Object.is(t,-0)?0:t),I1(e,V1)}function U1(e,t){let n=e,r=t&N1;for(let e=0;e<8;e++)n=F1(n,Number(r&255n)),r>>=8n;return n}function W1(e,t){let n=e,r=t|0;for(let e=0;e<4;e++)n=F1(n,r&255),r>>>=8;return n}function G1(e,t){return F1(e,+!!t)}function K1(e){return(e&N1).toString(16).padStart(16,`0`)}var q1=new Set;function J1(e){return R1(P1(),e)}function Y1(e){return{kind:`NumLit`,value:e,structuralHash:H1(J1(`NumLit`),e),freeParams:q1}}function X1(e){let t=J1(`Vec3Lit`);for(let n of e)t=H1(t,n);return{kind:`Vec3Lit`,value:e,structuralHash:t,freeParams:q1}}function Z1(e){let t=J1(`Vec2Lit`);for(let n of e)t=H1(t,n);return{kind:`Vec2Lit`,value:e,structuralHash:t,freeParams:q1}}function Q1(e){return{kind:`Param`,name:e,structuralHash:R1(J1(`Param`),e),freeParams:new Set([e])}}function $1(e,t,n){let r=R1(J1(`BinOp`),e);return r=U1(r,t.structuralHash),r=U1(r,n.structuralHash),{kind:`BinOp`,op:e,a:t,b:n,structuralHash:r,freeParams:l0(t.freeParams,n.freeParams)}}function e0(e,t){let n=R1(J1(`UnaryOp`),e);return n=U1(n,t.structuralHash),{kind:`UnaryOp`,op:e,arg:t,structuralHash:n,freeParams:t.freeParams}}function t0(e,t){let n=W1(J1(`Component`),t);return n=U1(n,e.structuralHash),{kind:`Component`,vec:e,index:t,structuralHash:n,freeParams:e.freeParams}}function n0(e,t){let n=W1(J1(`BuildVec`),e),r=new Set;for(let e of t){n=U1(n,e.structuralHash);for(let t of e.freeParams)r.add(t)}return{kind:`BuildVec`,dim:e,components:t,structuralHash:n,freeParams:r}}var r0=(e,t)=>$1(`+`,e,t),i0=(e,t)=>$1(`*`,e,t);function a0(e){return typeof e==`number`?Y1(e):e}function o0(e,t){if(!Array.isArray(e))return e;let n=e;return n.every(e=>typeof e==`number`)?t===3?X1([n[0],n[1],n[2]]):Z1([n[0],n[1]]):n0(t,n.map(a0))}function s0(e){return o0(e,3)}function c0(e){return o0(e,2)}function l0(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 u0(e){return typeof e==`number`}function d0(e,t){return u0(e)?O(e):k(F(N.NULL_SHAPE_INPUT,`${t}: expected number, got ${Array.isArray(e)?`vector(${e.length})`:typeof e}`))}function f0(e,t,n){return Array.isArray(e)&&e.length===t?O(e):k(F(N.NULL_SHAPE_INPUT,`${n}: expected Vec${t}, got ${u0(e)?`number`:`vector(${e.length})`}`))}function p0(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 m0(e,t);case`UnaryOp`:return h0(e,t);case`Component`:return g0(e,t);case`BuildVec`:return _0(e,t)}}function m0(e,t){let n=p0(e.a,t);if(!n.ok)return n;let r=p0(e.b,t);if(!r.ok)return r;let i=d0(n.value,`BinOp(${e.op}).a`);if(!i.ok)return i;let a=d0(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 h0(e,t){let n=p0(e.arg,t);if(!n.ok)return n;let r=d0(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 g0(e,t){let n=p0(e.vec,t);if(!n.ok)return n;if(u0(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 _0(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=p0(r,t);if(!e.ok)return e;let i=d0(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 v0(e,t,n){let r=p0(e,t);return r.ok?d0(r.value,n):r}function y0(e,t,n){let r=p0(e,t);if(!r.ok)return r;let i=f0(r.value,3,n);if(!i.ok)return i;let[a,o,s]=i.value;return O([a,o,s])}function b0(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 x0=new Set;function S0(e){return R1(P1(),e)}function C0(e,t){return U1(e,t.structuralHash)}function w0(e,t){return t===void 0?G1(e,!1):C0(G1(e,!0),t)}function T0(e,t){return t===void 0?G1(e,!1):H1(G1(e,!0),t)}function E0(...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?x0:t}function D0(e,t,n){let r=a0(e),i=a0(t),a=a0(n),o=S0(`Box`);return o=C0(C0(C0(o,r),i),a),{kind:`Box`,x:r,y:i,z:a,structuralHash:o,freeParams:E0(r,i,a)}}function O0(e){let t=a0(e);return{kind:`Sphere`,radius:t,structuralHash:C0(S0(`Sphere`),t),freeParams:t.freeParams}}function k0(e,t){let n=a0(e),r=a0(t);return{kind:`Cylinder`,radius:n,height:r,structuralHash:C0(C0(S0(`Cylinder`),n),r),freeParams:E0(n,r)}}function A0(e,t,n){let r=a0(e),i=a0(t),a=a0(n),o=S0(`Cone`);return o=C0(C0(C0(o,r),i),a),{kind:`Cone`,radius1:r,radius2:i,height:a,structuralHash:o,freeParams:E0(r,i,a)}}function j0(e,t){let n=a0(e),r=a0(t);return{kind:`Torus`,majorRadius:n,minorRadius:r,structuralHash:C0(C0(S0(`Torus`),n),r),freeParams:E0(n,r)}}function M0(e){let t=e.map(s0),n=W1(S0(`Polygon`),t.length);for(let e of t)n=C0(n,e);return{kind:`Polygon`,points:t,structuralHash:n,freeParams:E0(...t)}}function N0(e){let t=a0(e);return{kind:`Circle`,radius:t,structuralHash:C0(S0(`Circle`),t),freeParams:t.freeParams}}function P0(e,t){let n=s0(e),r=s0(t);return{kind:`Line`,from:n,to:r,structuralHash:C0(C0(S0(`Line`),n),r),freeParams:E0(n,r)}}function F0(e){let t=s0(e);return{kind:`Vertex`,point:t,structuralHash:C0(S0(`Vertex`),t),freeParams:t.freeParams}}function I0(e){return{kind:`Empty`,output:e,structuralHash:R1(S0(`Empty`),e),freeParams:x0}}function L0(){return I0(`Solid`)}function R0(){return I0(`Face`)}function z0(){return I0(`Wire`)}function B0(e,t,n,r){return T0(C0(C0(S0(e),t),n),r)}function V0(e,t,n){return{kind:`Fuse`,a:e,b:t,tolerance:n,structuralHash:B0(`Fuse`,e,t,n),freeParams:E0(e,t)}}function H0(e,t,n){return{kind:`Cut`,a:e,b:t,tolerance:n,structuralHash:B0(`Cut`,e,t,n),freeParams:E0(e,t)}}function U0(e,t,n){return{kind:`Intersect`,a:e,b:t,tolerance:n,structuralHash:B0(`Intersect`,e,t,n),freeParams:E0(e,t)}}function W0(e,t){let n=W1(S0(`FuseAll`),e.length);for(let t of e)n=C0(n,t);return n=T0(n,t),{kind:`FuseAll`,shapes:e,tolerance:t,structuralHash:n,freeParams:E0(...e)}}function G0(e,t,n){let r=C0(S0(`CutAll`),e);r=W1(r,t.length);for(let e of t)r=C0(r,e);return r=T0(r,n),{kind:`CutAll`,base:e,tools:t,tolerance:n,structuralHash:r,freeParams:E0(e,...t)}}function K0(e){return e===void 0?void 0:s0(e)}function q0(e,t){let n=s0(t);return{kind:`Translate`,target:e,vector:n,structuralHash:C0(C0(S0(`Translate`),e),n),freeParams:E0(e,n)}}function J0(e,t,n){let r=a0(t),i=K0(n?.axis),a=K0(n?.at),o=C0(C0(S0(`Rotate`),e),r);return o=w0(o,i),o=w0(o,a),{kind:`Rotate`,target:e,angle:r,axis:i,at:a,structuralHash:o,freeParams:E0(e,r,i,a)}}function Y0(e,t,n){let r=a0(t),i=K0(n?.center),a=C0(C0(S0(`Scale`),e),r);return a=w0(a,i),{kind:`Scale`,target:e,factor:r,center:i,structuralHash:a,freeParams:E0(e,r,i)}}function X0(e,t){let n=K0(t?.normal),r=K0(t?.at),i=C0(S0(`Mirror`),e);return i=w0(i,n),i=w0(i,r),{kind:`Mirror`,target:e,normal:n,at:r,structuralHash:i,freeParams:E0(e,n,r)}}function Z0(e){let t=W1(S0(`Compound`),e.length);for(let n of e)t=C0(t,n);return{kind:`Compound`,children:e,structuralHash:t,freeParams:E0(...e)}}function Q0(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 Q0(e.a);case`FuseAll`:return e.shapes[0]?Q0(e.shapes[0]):`Solid`;case`CutAll`:return Q0(e.base);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return Q0(e.target);case`Compound`:return`Compound`}}function $0(e,t){let n=v0(e.x,t.env,`Box.x`);if(!n.ok)return n;let r=v0(e.y,t.env,`Box.y`);if(!r.ok)return r;let i=v0(e.z,t.env,`Box.z`);return i.ok?O(rM(n.value,r.value,i.value)):i}function e2(e,t){let n=v0(e.radius,t.env,`Sphere.radius`);return n.ok?O(aM(n.value)):n}function t2(e,t){let n=v0(e.radius,t.env,`Cylinder.radius`);if(!n.ok)return n;let r=v0(e.height,t.env,`Cylinder.height`);return r.ok?O(iM(n.value,r.value)):r}function n2(e,t){let n=v0(e.radius1,t.env,`Cone.radius1`);if(!n.ok)return n;let r=v0(e.radius2,t.env,`Cone.radius2`);if(!r.ok)return r;let i=v0(e.height,t.env,`Cone.height`);return i.ok?O(oM(n.value,r.value,i.value)):i}function r2(e,t){let n=v0(e.majorRadius,t.env,`Torus.majorRadius`);if(!n.ok)return n;let r=v0(e.minorRadius,t.env,`Torus.minorRadius`);return r.ok?O(sM(n.value,r.value)):r}function i2(e,t){let n=[];for(let r of e.points){let e=y0(r,t.env,`Polygon.point`);if(!e.ok)return e;n.push(e.value)}return CM(n)}function a2(e,t){let n=v0(e.radius,t.env,`Circle.radius`);return n.ok?O(uM(n.value)):n}function o2(e,t){let n=y0(e.from,t.env,`Line.from`);if(!n.ok)return n;let r=y0(e.to,t.env,`Line.to`);return r.ok?O(lM(n.value,r.value)):r}function s2(e,t){let n=y0(e.point,t.env,`Vertex.point`);return n.ok?O(wM(n.value)):n}function c2(e){return k(fo(N.NULL_SHAPE_INPUT,`${e}: empty result has no kernel representation`))}function l2(e,t,n){let r=e.evalNode(t);return r.ok?wE(r.value)?O(r.value):k(co(N.CSG_NOT_3D,`${n}: operand did not produce a 3D shape`)):r}function u2(e,t){return{unsafe:!0,fuzzyValue:e.tolerance??t.tolerance}}function d2(e,t){if(e.a.kind===`Empty`)return t.evalNode(e.b);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=l2(t,e.a,`Fuse.a`);if(!n.ok)return n;let r=l2(t,e.b,`Fuse.b`);return r.ok?iA(n.value,r.value,u2(e,t)):r}function f2(e,t){if(e.a.kind===`Empty`)return c2(`Cut`);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=l2(t,e.a,`Cut.a`);if(!n.ok)return n;let r=l2(t,e.b,`Cut.b`);return r.ok?aA(n.value,r.value,u2(e,t)):r}function p2(e,t){if(e.a.kind===`Empty`||e.b.kind===`Empty`)return c2(`Intersect`);let n=l2(t,e.a,`Intersect.a`);if(!n.ok)return n;let r=l2(t,e.b,`Intersect.b`);return r.ok?oA(n.value,r.value,u2(e,t)):r}function m2(e,t,n){let r=[];for(let i of t){let t=l2(e,i,n);if(!t.ok)return t;r.push(t.value)}return O(r)}function h2(e,t){let n=e.shapes.filter(e=>e.kind!==`Empty`);if(n.length===0)return c2(`FuseAll`);if(n.length===1&&n[0])return t.evalNode(n[0]);let r=m2(t,n,`FuseAll.operand`);return r.ok?cA(r.value,u2(e,t)):r}function g2(e,t){if(e.base.kind===`Empty`)return c2(`CutAll`);let n=e.tools.filter(e=>e.kind!==`Empty`);if(n.length===0)return t.evalNode(e.base);let r=l2(t,e.base,`CutAll.base`);if(!r.ok)return r;let i=m2(t,n,`CutAll.tool`);return i.ok?lA(r.value,i.value,u2(e,t)):i}function _2(e){return k(fo(N.NULL_SHAPE_INPUT,`${e}: cannot transform an Empty node`))}function v2(e,t,n,r){return e?y0(e,t,n):O(r)}function y2(e,t){if(e.target.kind===`Empty`)return _2(`Translate`);let n=y0(e.vector,t.env,`Translate.vector`);if(!n.ok)return n;let r=t.evalNode(e.target);return r.ok?O(IO(r.value,n.value)):r}function b2(e,t){if(e.target.kind===`Empty`)return _2(`Rotate`);let n=v0(e.angle,t.env,`Rotate.angle`);if(!n.ok)return n;let r=v2(e.axis,t.env,`Rotate.axis`,[0,0,1]);if(!r.ok)return r;let i=v2(e.at,t.env,`Rotate.at`,[0,0,0]);if(!i.ok)return i;let a=t.evalNode(e.target);return a.ok?O(LO(a.value,n.value,i.value,r.value)):a}function x2(e,t){if(e.target.kind===`Empty`)return _2(`Scale`);let n=v0(e.factor,t.env,`Scale.factor`);if(!n.ok)return n;let r=v2(e.center,t.env,`Scale.center`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(zO(i.value,n.value,r.value)):i}function S2(e,t){if(e.target.kind===`Empty`)return _2(`Mirror`);let n=v2(e.normal,t.env,`Mirror.normal`,[1,0,0]);if(!n.ok)return n;let r=v2(e.at,t.env,`Mirror.at`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(RO(i.value,n.value,r.value)):i}function C2(e,t){let n=e.children.filter(e=>e.kind!==`Empty`);if(n.length===0)return k(fo(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(TM(r))}function w2(){return k(fo(N.NULL_SHAPE_INPUT,`Empty: cannot materialize an Empty node directly — only valid as boolean/transform operand`))}function T2(e,t){switch(e.kind){case`Box`:return $0(e,t);case`Sphere`:return e2(e,t);case`Cylinder`:return t2(e,t);case`Cone`:return n2(e,t);case`Torus`:return r2(e,t);case`Polygon`:return i2(e,t);case`Circle`:return a2(e,t);case`Line`:return o2(e,t);case`Vertex`:return s2(e,t);case`Empty`:return w2();case`Fuse`:return d2(e,t);case`Cut`:return f2(e,t);case`Intersect`:return p2(e,t);case`FuseAll`:return h2(e,t);case`CutAll`:return g2(e,t);case`Translate`:return y2(e,t);case`Rotate`:return b2(e,t);case`Scale`:return x2(e,t);case`Mirror`:return S2(e,t);case`Compound`:return C2(e,t)}}function E2(e,t){if(typeof t==`number`)return H1(G1(e,!1),t);let n=G1(e,!0);n=W1(n,t.length);for(let e of t)n=H1(n,e);return n}function D2(e,t){if(t.size===0)return P1();let n=b0(e,t),r=Object.keys(n).sort(),i=P1();for(let e of r){i=R1(i,e);let t=n[e];t!==void 0&&(i=E2(i,t))}return i}function O2(e,t,n,r){let i=D2(t,e.freeParams),a=r===void 0?`d`:H1(P1(),r).toString(16);return`${K1(e.structuralHash)}:${n}:${K1(i)}:${a}`}var k2=class{scope=new FT;cache=new Map;registered=new WeakSet;kernelId;defaultTolerance;onStep;hits=0;misses=0;constructor(e={}){this.kernelId=e.kernel??fT()??`unregistered`,this.defaultTolerance=e.tolerance,e.onStep&&(this.onStep=e.onStep)}evaluate(e,t={}){return pT(this.kernelId,()=>this.evaluateInner(e,t))}evaluateInner(e,t){let n=O2(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=T2(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 A2(e,t){try{var n=CT();let r=t(n.u(new k2(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 j2(e){return{csgVersion:1,root:L2(e)}}function M2(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:M2(e.a),b:M2(e.b)};case`UnaryOp`:return{kind:`UnaryOp`,op:e.op,arg:M2(e.arg)};case`Component`:return{kind:`Component`,vec:M2(e.vec),index:e.index};case`BuildVec`:return{kind:`BuildVec`,dim:e.dim,components:e.components.map(M2)}}}function N2(e){switch(e.kind){case`Box`:return{kind:`Box`,x:M2(e.x),y:M2(e.y),z:M2(e.z)};case`Sphere`:return{kind:`Sphere`,radius:M2(e.radius)};case`Cylinder`:return{kind:`Cylinder`,radius:M2(e.radius),height:M2(e.height)};case`Cone`:return{kind:`Cone`,radius1:M2(e.radius1),radius2:M2(e.radius2),height:M2(e.height)};case`Torus`:return{kind:`Torus`,majorRadius:M2(e.majorRadius),minorRadius:M2(e.minorRadius)};case`Polygon`:return{kind:`Polygon`,points:e.points.map(M2)};case`Circle`:return{kind:`Circle`,radius:M2(e.radius)};case`Line`:return{kind:`Line`,from:M2(e.from),to:M2(e.to)};case`Vertex`:return{kind:`Vertex`,point:M2(e.point)};case`Empty`:return{kind:`Empty`,output:e.output};default:return}}function P2(e){switch(e.kind){case`Fuse`:case`Cut`:case`Intersect`:return{kind:e.kind,a:L2(e.a),b:L2(e.b),tolerance:e.tolerance};case`FuseAll`:return{kind:`FuseAll`,shapes:e.shapes.map(L2),tolerance:e.tolerance};case`CutAll`:return{kind:`CutAll`,base:L2(e.base),tools:e.tools.map(L2),tolerance:e.tolerance};default:return}}function F2(e){return e?M2(e):void 0}function I2(e){switch(e.kind){case`Translate`:return{kind:`Translate`,target:L2(e.target),vector:M2(e.vector)};case`Rotate`:return{kind:`Rotate`,target:L2(e.target),angle:M2(e.angle),axis:F2(e.axis),at:F2(e.at)};case`Scale`:return{kind:`Scale`,target:L2(e.target),factor:M2(e.factor),center:F2(e.center)};case`Mirror`:return{kind:`Mirror`,target:L2(e.target),normal:F2(e.normal),at:F2(e.at)};default:return}}function L2(e){return e.kind===`Compound`?{kind:`Compound`,children:e.children.map(L2)}:N2(e)??P2(e)??I2(e)}function R2(e){return k(F(N.NULL_SHAPE_INPUT,`csg.fromJSON: ${e}`))}function z2(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function B2(e){return typeof e==`number`&&Number.isFinite(e)}function V2(e){return typeof e==`string`}function H2(e,t){if(!Array.isArray(e)||e.length!==3)return R2(`${t}: expected Vec3 array`);let[n,r,i]=e;return!B2(n)||!B2(r)||!B2(i)?R2(`${t}: Vec3 contains non-number`):O([n,r,i])}function U2(e,t){if(!Array.isArray(e)||e.length!==2)return R2(`${t}: expected Vec2 array`);let[n,r]=e;return!B2(n)||!B2(r)?R2(`${t}: Vec2 contains non-number`):O([n,r])}function W2(e){if(!z2(e))return R2(`input is not an object`);let t=e.csgVersion;if(t!==1)return R2(`unsupported csgVersion ${String(t)} (expected 1)`);let n=e.root;return Q2(n)}function G2(e){if(!z2(e))return R2(`expression: not an object`);let t=e.kind;switch(t){case`NumLit`:return B2(e.value)?O(Y1(e.value)):R2(`NumLit.value`);case`Vec3Lit`:{let t=H2(e.value,`Vec3Lit.value`);return t.ok?O(X1(t.value)):t}case`Vec2Lit`:{let t=U2(e.value,`Vec2Lit.value`);return t.ok?O(Z1(t.value)):t}case`Param`:return V2(e.name)?O(Q1(e.name)):R2(`Param.name`);case`BinOp`:return K2(e);case`UnaryOp`:return q2(e);case`Component`:return J2(e);case`BuildVec`:return Y2(e);default:return R2(`unknown expression kind: ${String(t)}`)}}function K2(e){let t=e.op;if(t!==`+`&&t!==`-`&&t!==`*`&&t!==`/`)return R2(`BinOp.op: ${String(t)}`);let n=G2(e.a);if(!n.ok)return n;let r=G2(e.b);return r.ok?O($1(t,n.value,r.value)):r}function q2(e){let t=e.op;if(!V2(t)||![`neg`,`sin`,`cos`,`sqrt`,`abs`].includes(t))return R2(`UnaryOp.op: ${String(t)}`);let n=G2(e.arg);return n.ok?O(e0(t,n.value)):n}function J2(e){let t=e.index;if(t!==0&&t!==1&&t!==2)return R2(`Component.index: ${String(t)}`);let n=G2(e.vec);return n.ok?O(t0(n.value,t)):n}function Y2(e){let t=e.dim;if(t!==2&&t!==3)return R2(`BuildVec.dim: ${String(t)}`);let n=e.components;if(!Array.isArray(n))return R2(`BuildVec.components: not array`);if(n.length!==t)return R2(`BuildVec.components: expected ${t} components, got ${n.length}`);let r=[];for(let e of n){let t=G2(e);if(!t.ok)return t;r.push(t.value)}return O(n0(t,r))}function X2(e,t){if(!Array.isArray(e))return R2(`${t}: not array`);let n=[];for(let t of e){let e=Q2(t);if(!e.ok)return e;n.push(e.value)}return O(n)}function Z2(e){let t=e.tolerance;return t==null?O(void 0):B2(t)?O(t):R2(`tolerance: not a finite number`)}function Q2(e){if(!z2(e))return R2(`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 e4(t,e);case`Fuse`:case`Cut`:case`Intersect`:return c4(t,e);case`FuseAll`:case`CutAll`:return l4(t,e);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return u4(t,e);case`Compound`:return g4(e);default:return R2(`unknown node kind: ${String(t)}`)}}function $2(e,t,n){let r=G2(e[t]);return r.ok?O(n(r.value)):r}function e4(e,t){switch(e){case`Box`:return t4(t);case`Sphere`:return $2(t,`radius`,O0);case`Cylinder`:return n4(t);case`Cone`:return r4(t);case`Torus`:return i4(t);case`Polygon`:return a4(t);case`Circle`:return $2(t,`radius`,N0);case`Line`:return o4(t);case`Vertex`:return $2(t,`point`,F0);case`Empty`:return s4(t)}return R2(`unhandled primitive: ${e}`)}function t4(e){let t=G2(e.x);if(!t.ok)return t;let n=G2(e.y);if(!n.ok)return n;let r=G2(e.z);return r.ok?O(D0(t.value,n.value,r.value)):r}function n4(e){let t=G2(e.radius);if(!t.ok)return t;let n=G2(e.height);return n.ok?O(k0(t.value,n.value)):n}function r4(e){let t=G2(e.radius1);if(!t.ok)return t;let n=G2(e.radius2);if(!n.ok)return n;let r=G2(e.height);return r.ok?O(A0(t.value,n.value,r.value)):r}function i4(e){let t=G2(e.majorRadius);if(!t.ok)return t;let n=G2(e.minorRadius);return n.ok?O(j0(t.value,n.value)):n}function a4(e){let t=e.points;if(!Array.isArray(t))return R2(`Polygon.points: not array`);let n=[];for(let e of t){let t=G2(e);if(!t.ok)return t;n.push(t.value)}return O(M0(n))}function o4(e){let t=G2(e.from);if(!t.ok)return t;let n=G2(e.to);return n.ok?O(P0(t.value,n.value)):n}function s4(e){let t=e.output;switch(t){case`Solid`:return O(L0());case`Face`:return O(R0());case`Wire`:return O(z0());default:return R2(`Empty.output: ${String(t)}`)}}function c4(e,t){let n=Q2(t.a);if(!n.ok)return n;let r=Q2(t.b);if(!r.ok)return r;let i=Z2(t);if(!i.ok)return i;switch(e){case`Fuse`:return O(V0(n.value,r.value,i.value));case`Cut`:return O(H0(n.value,r.value,i.value));case`Intersect`:return O(U0(n.value,r.value,i.value))}}function l4(e,t){let n=Z2(t);if(!n.ok)return n;if(e===`FuseAll`){let e=X2(t.shapes,`FuseAll.shapes`);return e.ok?O(W0(e.value,n.value)):e}let r=Q2(t.base);if(!r.ok)return r;let i=X2(t.tools,`CutAll.tools`);return i.ok?O(G0(r.value,i.value,n.value)):i}function u4(e,t){let n=Q2(t.target);if(!n.ok)return n;switch(e){case`Translate`:return d4(t,n.value);case`Rotate`:return p4(t,n.value);case`Scale`:return m4(t,n.value);case`Mirror`:return h4(t,n.value)}}function d4(e,t){let n=G2(e.vector);return n.ok?O(q0(t,n.value)):n}function f4(e,t){if(e[t]===void 0)return O(void 0);let n=G2(e[t]);return n.ok?O(n.value):n}function p4(e,t){let n=G2(e.angle);if(!n.ok)return n;let r=f4(e,`axis`);if(!r.ok)return r;let i=f4(e,`at`);return i.ok?O(J0(t,n.value,{axis:r.value,at:i.value})):i}function m4(e,t){let n=G2(e.factor);if(!n.ok)return n;let r=f4(e,`center`);return r.ok?O(Y0(t,n.value,{center:r.value})):r}function h4(e,t){let n=f4(e,`normal`);if(!n.ok)return n;let r=f4(e,`at`);return r.ok?O(X0(t,{normal:n.value,at:r.value})):r}function g4(e){let t=X2(e.children,`Compound.children`);return t.ok?O(Z0(t.value)):t}function _4(e){return b4(e)}function v4(e){switch(e.kind){case`NumLit`:case`Vec3Lit`:case`Vec2Lit`:case`Param`:return e;case`BinOp`:{let t=v4(e.a),n=v4(e.b);if(t.kind===`NumLit`&&n.kind===`NumLit`)switch(e.op){case`+`:return Y1(t.value+n.value);case`-`:return Y1(t.value-n.value);case`*`:return Y1(t.value*n.value);case`/`:return Y1(t.value/n.value)}return t!==e.a||n!==e.b?$1(e.op,t,n):e}case`UnaryOp`:{let t=v4(e.arg);if(t.kind===`NumLit`){let n=t.value;switch(e.op){case`neg`:return Y1(-n);case`sin`:return Y1(Math.sin(n));case`cos`:return Y1(Math.cos(n));case`sqrt`:return Y1(Math.sqrt(n));case`abs`:return Y1(Math.abs(n))}}return t===e.arg?e:e0(e.op,t)}case`Component`:{let t=v4(e.vec);return t.kind===`Vec3Lit`||t.kind===`Vec2Lit`&&(e.index===0||e.index===1)?Y1(t.value[e.index]):t===e.vec?e:t0(t,e.index)}case`BuildVec`:{let t=e.components.map(v4);return y4(e.dim,t)||(t.some((t,n)=>t!==e.components[n])?n0(e.dim,t):e)}}}function y4(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?Z1([n[0],n[1]]):X1([n[0],n[1],n[2]])}function b4(e){switch(e.kind){case`Box`:return D0(v4(e.x),v4(e.y),v4(e.z));case`Sphere`:return O0(v4(e.radius));case`Cylinder`:return k0(v4(e.radius),v4(e.height));case`Cone`:return A0(v4(e.radius1),v4(e.radius2),v4(e.height));case`Torus`:return j0(v4(e.majorRadius),v4(e.minorRadius));case`Polygon`:return M0(e.points.map(v4));case`Circle`:return N0(v4(e.radius));case`Line`:return P0(v4(e.from),v4(e.to));case`Vertex`:return F0(v4(e.point));case`Empty`:return e;case`Fuse`:return x4(e.a,e.b,e.tolerance);case`Cut`:return S4(e.a,e.b,e.tolerance);case`Intersect`:return C4(e.a,e.b,e.tolerance);case`FuseAll`:return w4(e.shapes,e.tolerance);case`CutAll`:return T4(e.base,e.tools,e.tolerance);case`Translate`:return E4(e.target,e.vector);case`Rotate`:return J0(b4(e.target),v4(e.angle),{axis:e.axis?v4(e.axis):void 0,at:e.at?v4(e.at):void 0});case`Scale`:return Y0(b4(e.target),v4(e.factor),{center:e.center?v4(e.center):void 0});case`Mirror`:return X0(b4(e.target),{normal:e.normal?v4(e.normal):void 0,at:e.at?v4(e.at):void 0});case`Compound`:return Z0(e.children.map(b4).filter(e=>e.kind!==`Empty`))}}function x4(e,t,n){let r=b4(e),i=b4(t);return r.kind===`Empty`?i:i.kind===`Empty`?r:V0(r,i,n)}function S4(e,t,n){let r=b4(e),i=b4(t);return i.kind===`Empty`||r.kind===`Empty`?r:H0(r,i,n)}function C4(e,t,n){let r=b4(e),i=b4(t);return r.kind===`Empty`?r:i.kind===`Empty`?i:U0(r,i,n)}function w4(e,t){let n=e.map(b4).filter(e=>e.kind!==`Empty`);return n.length===0?L0():n.length===1?n[0]:W0(n,t)}function T4(e,t,n){let r=b4(e);if(r.kind===`Empty`)return r;let i=t.map(b4).filter(e=>e.kind!==`Empty`);return i.length===0?r:G0(r,i,n)}function E4(e,t){let n=b4(e),r=v4(t);if(r.kind!==`Vec3Lit`)return q0(n,r);let[i,a,o]=r.value;if(i===0&&a===0&&o===0)return n;if(n.kind===`Translate`){let e=v4(n.vector);if(e.kind===`Vec3Lit`)return q0(n.target,[e.value[0]+i,e.value[1]+a,e.value[2]+o])}return q0(n,r)}function D4(e,t,n){return O4(e,t,n)}function O4(e,t,n){return t(e)?n:k4(e,t,n)}function k4(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 V0(O4(e.a,t,n),O4(e.b,t,n),e.tolerance);case`Cut`:return H0(O4(e.a,t,n),O4(e.b,t,n),e.tolerance);case`Intersect`:return U0(O4(e.a,t,n),O4(e.b,t,n),e.tolerance);case`FuseAll`:return W0(e.shapes.map(e=>O4(e,t,n)),e.tolerance);case`CutAll`:return G0(O4(e.base,t,n),e.tools.map(e=>O4(e,t,n)),e.tolerance);case`Translate`:return q0(O4(e.target,t,n),e.vector);case`Rotate`:return J0(O4(e.target,t,n),e.angle,{axis:e.axis,at:e.at});case`Scale`:return Y0(O4(e.target,t,n),e.factor,{center:e.center});case`Mirror`:return X0(O4(e.target,t,n),{normal:e.normal,at:e.at});case`Compound`:return Z0(e.children.map(e=>O4(e,t,n)))}}function A4(e,t){t(e);for(let n of j4(e))A4(n,t)}function j4(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 M4(e){let t=0;return A4(e,()=>{t++}),t}var N4=HJ({CSG_VERSION:()=>1,Evaluator:()=>k2,add:()=>r0,asScalarExpr:()=>a0,asVec2Expr:()=>c0,asVec3Expr:()=>s0,binOp:()=>$1,box:()=>D0,buildVec:()=>n0,circle:()=>N0,component:()=>t0,compound:()=>Z0,cone:()=>A0,cut:()=>H0,cutAll:()=>G0,cylinder:()=>k0,emptyFace:()=>R0,emptySolid:()=>L0,emptyWire:()=>z0,foldExpr:()=>v4,forEachNode:()=>A4,fromJSON:()=>W2,fuse:()=>V0,fuseAll:()=>W0,intersect:()=>U0,line:()=>P0,mirror:()=>X0,mul:()=>i0,nodeCount:()=>M4,numLit:()=>Y1,optimize:()=>_4,outputKindOf:()=>Q0,param:()=>Q1,polygon:()=>M0,replaceNode:()=>D4,rotate:()=>J0,scale:()=>Y0,sphere:()=>O0,toJSON:()=>j2,torus:()=>j0,translate:()=>q0,unaryOp:()=>e0,vec2Lit:()=>Z1,vec3Lit:()=>X1,vertex:()=>F0,withEvaluator:()=>A2});export{yI as BaseSketcher2d,bI as BlueprintSketcher,no as BrepBugError,N as BrepErrorCode,m$ as BrepWrapperError,Ey as BrepkitAdapter,YW as CompoundSketch,i as DEFAULT_CAPABILITIES,iD as DEG2RAD,FT as DisposalScope,r as EXACT_BREP_CAPABILITIES,DG as FaceSketcher,G as HASH_CODE_MAX,Ma as OK,ja as OcctWasmAdapter,aD as RAD2DEG,uG as Sketch,EG as Sketcher,dG as Sketches,IM as addChild,kM as addHoles,pN as addJoint,$Z as addMate,JN as addStep,GA as adjacentFaces,Va as all,Ia as andThen,GJ as applyGlue,jQ as applyMatrix,pk as approximateCurve,GT as as2D,WT as as3D,ID as asTopo,yJ as assignRoles,Lj as autoHeal,gM as bezier,Tq as blueprintToDXF,bA as booleanPipeline,C1 as booleans,d$ as boss,rM as box,hM as bsplineApprox,M as bug,CG as cameraFromPlane,SG as cameraLookAt,gJ as captureHint,VD as cast,W as castShape,EE as castShape3D,WQ as chamfer,LA as chamferDistAngleShape,hj as chamferWithEvolution,nQ as checkAllInterferences,oj as checkBoolean,tQ as checkInterference,uM as circle,PM as circularPattern,nO as classifyPointOnFace,Ck as clearMeshCache,AQ as clone,eE as closedWire,Qa as collect,HM as collectShapes,kO as colorFaces,OO as colorShape,Kj as complexExtrude,GO as composeTransforms,TM as compound,sG as compoundSketchExtrude,aG as compoundSketchFace,lG as compoundSketchLoft,cG as compoundSketchRevolve,fo as computationError,gZ as computeStraightSkeleton,oM as cone,k1 as construction,XX as convexHull,TI as cornerFinder,VM as countNodes,jM as createAssembly,FM as createAssemblyNode,zK as createBlueprint,xG as createCamera,gE as createCompound,BK as createCompoundBlueprint,SP as createDistanceQuery,uE as createEdge,fE as createFace,NT as createHandle,qN as createHistory,PT as createKernelHandle,wk as createMeshCache,kD as createNamedPlane,RJ as createOperationRegistry,DD as createPlane,bJ as createRef,tP as createRegistry,pE as createShell,mE as createSolid,AJ as createTaskQueue,lE as createVertex,dE as createWire,LJ as createWorkerClient,BJ as createWorkerHandler,N4 as csg,yo as currentQuality,jK as curve2dBoundingBox,RK as curve2dDistanceFrom,MK as curve2dFirstPoint,LK as curve2dIsOnCurve,NK as curve2dLastPoint,FK as curve2dParameter,PK as curve2dSplitAt,IK as curve2dTangentAt,ok as curveAxis,nk as curveEndPoint,sk as curveIsClosed,ck as curveIsPeriodic,ak as curveLength,lk as curvePeriod,rk as curvePointAt,tk as curveStartPoint,ik as curveTangentAt,PQ as cut,dL as cut2D,lA as cutAll,ZA as cutAllBisect,eL as cutBlueprints,fj as cutWithEvolution,iM as cylinder,oN as cylindricalJoint,hJ as defaultScorer,MJ as dequeueTask,$Q as describe,iK as deserializeDrawing,sP as deserializeHistory,UD as deserializeShape,BD as downcast,JQ as draft,oK as draw,dK as drawCircle,fK as drawEllipse,yK as drawFaceOutline,gK as drawParametricFunction,hK as drawPointsInterpolation,pK as drawPolysides,vK as drawProjection,cK as drawRectangle,sK as drawRoundedRectangle,lK as drawSingleCircle,uK as drawSingleEllipse,mK as drawText,TK as drawingChamfer,SK as drawingCut,wK as drawingFillet,xK as drawingFuse,CK as drawingIntersect,bK as drawingToSketchOnPlane,l$ as drill,YP as edgeFinder,HA as edgesOfFace,dM as ellipse,mM as ellipseArc,cM as ellipsoid,jJ as enqueueTask,k as err,MM as exportAssemblySTEP,wq as exportDXF,dq as exportGlb,uq as exportGltf,Mk as exportIGES,eq as exportOBJ,Ak as exportSTEP,cJ as exportSTEPConfigured,jk as exportSTL,Wq as exportThreeMF,HN as exportURDF,i$ as extrude,eM as extrudeAll,bM as face,tO as faceAxis,eO as faceCenter,QP as faceFinder,KD as faceGeomType,qD as faceOrientation,VA as facesOfEdge,RY as fieldBoolean,HY as fieldContour,zY as fieldOffset,VY as fieldReinit,BY as fieldShell,Zk as fill,xM as filledFace,UQ as fillet,mj as filletWithEvolution,_O as findFacesByTag,zM as findNode,XN as findStep,Bj as fixSelfIntersection,Rj as fixShape,La as flatMap,Wa as flatten,JD as flipFaceOrientation,dk as flipOrientation,mJ as fontMetrics,_N as forwardKinematics,t$ as fromBREP,LX as fromKernelDir,IX as fromKernelPnt,FX as fromKernelVec,Ka as fromNullable,NQ as fuse,lL as fuse2D,cA as fuseAll,tj as fuseAllBisect,$I as fuseBlueprints,dj as fuseWithEvolution,R$ as gearGeometry,rY as getActiveVoxelId,QE as getBounds,VK as getBounds2D,WE as getCompSolids,ek as getCurveType,DT as getDisposalStats,RE as getEdges,jO as getFaceColor,sO as getFaceOrigins,vO as getFaceTags,zE as getFaces,mG as getFont,YO as getHashCode,ZN as getHistoryShape,U as getKernel,mT as getKernelCapabilities,vT as getKernelTier,qA as getNurbsCurveData,JA as getNurbsSurfaceData,uk as getOrientation,HK as getOrientation2D,Oo as getPerformanceStats,AO as getShapeColor,YT as getShapeKind,UE as getShells,tF as getSingleFace,HE as getSolids,GD as getSurfaceType,bO as getTagMetadata,VE as getVertices,nY as getVoxel,BE as getWires,Zj as guidedSweep,YQ as heal,Pj as healFace,Nj as healSolid,Fj as healWire,fM as helix,YX as hull,sQ as importDXF,wQ as importGLB,dJ as importIGES,dQ as importOBJ,lJ as importSTEP,uJ as importSTL,sJ as importSVG,oJ as importSVGPathD,CQ as importThreeMF,KN as importURDF,ST as init,lT as initFromManifold,bT as initFromOC,iY as initVoxel,aO as innerWires,fk as interpolateCurve,FQ as intersect,fL as intersect2D,tL as intersectBlueprints,pj as intersectWithEvolution,LE as invalidateShapeCache,jN as inverseKinematics,D1 as io,po as ioError,UT as is2D,HT as is3D,qJ as isChamferRadius,XT as isClosedWire,HD as isCompSolid,CE as isCompound,DJ as isDisposeRequest,vE as isEdge,r$ as isEmpty,QO as isEqualShape,A as isErr,kJ as isErrorResponse,bE as isFace,JJ as isFilletRadius,TJ as isInitRequest,UK as isInside2D,VT as isLive,QT as isManifoldShell,KJ as isNumber,Na as isOk,EJ as isOperationRequest,ZT as isOrientedFace,iE as isPlanarFace,aE as isPlanarWire,vG as isProjectionPlane,PJ as isQueueEmpty,ZO as isSameShape,TE as isShape1D,wE as isShape3D,xE as isShell,SE as isSolid,OJ as isSuccessResponse,n$ as isValid,$T as isValidSolid,_E as isVertex,yE as isWire,ZE as iterCompSolids,GE as iterEdges,KE as iterFaces,XE as iterShells,YE as iterSolids,RD as iterTopo,JE as iterVertices,qE as iterWires,NN as jointTrajectory,fN as jointTransform,IN as jointsFromDH,AE as kernelCall,jE as kernelCallRaw,ME as kernelCallScoped,P as kernelError,kX as latticeInfill,AX as latticeInfillShape,lM as line,NM as linearPattern,pG as loadFont,o$ as loft,nM as loftAll,LG as makeBaseBox,s1 as makeExternalGear,c1 as makeInternalGear,jD as makePlane,u1 as makePlanetaryGear,bG as makeProjectedEdges,nE as manifoldShell,Pa as map,Ga as mapBoth,Fa as mapErr,Za as match,vP as measureArea,CP as measureCurvatureAt,wP as measureCurvatureAtMid,bP as measureDistance,xP as measureDistanceProps,yP as measureLength,gP as measureLinearProps,hP as measureSurfaceProps,_P as measureVolume,mP as measureVolumeProps,E1 as measurement,vN as mechanismDOF,ZQ as mesh,QQ as meshEdges,Nk as meshMultiLOD,eZ as minkowski,OQ as mirror,JK as mirror2D,kK as mirrorDrawing,f$ as mirrorJoin,w1 as modifiers,aP as modifyStep,uo as moduleInitError,Xj as multiSectionSweep,$D as normalAt,KQ as offset,DM as offsetFace,bY as offsetMesh,CY as offsetShape,mk as offsetWire2D,O as ok,Ra as or,za as orElse,lI as organiseBlueprints,tE as orientedFace,rO as outerWire,A1 as patterns,NJ as pendingCount,to as pipeline,PD as pivotPlane,oE as planarFace,sN as planarJoint,sE as planarWire,n1 as planetPlacements,u$ as pocket,XD as pointOnSurface,lY as pointsInside,CM as polygon,tZ as polyhedron,NG as polysideInnerRadius,EI as polysidesBlueprint,_j as positionOnCurve,xT as prewarm,S1 as primitives,aN as prismaticJoint,wG as projectEdges,QD as projectPointOnFace,O1 as query,mo as queryError,p$ as rectangularPattern,zJ as registerHandler,uT as registerKernel,_T as registerKernelTier,nP as registerOperation,eP as registerShape,tY as registerVoxel,FJ as rejectAll,LM as removeChild,iO as removeHolesFromFace,fY as repairMesh,iP as replayFrom,rP as replayHistory,OT as resetDisposalStats,ko as resetPerformanceStats,BO as resize,$ as resolve,TQ as resolve3D,lD as resolveDirection,AD as resolvePlane,wJ as resolveRef,AK as reverseCurve,iN as revoluteJoint,a$ as revolve,wZ as roof,DQ as rotate,KK as rotate2D,DK as rotateDrawing,DI as roundedRectangleBlueprint,kQ as scale,qK as scale2D,OK as scaleDrawing,iX as sdfBox,cX as sdfCapsule,sX as sdfCone,oX as sdfCylinder,bX as sdfFieldAxialRamp,CX as sdfFieldClamp,yX as sdfFieldConst,SX as sdfFieldFromSdf,xX as sdfFieldRadialRamp,mX as sdfLattice,uX as sdfPlane,aX as sdfRoundedBox,rX as sdfSphere,hX as sdfStrutLattice,fX as sdfSweep,lX as sdfTorus,IQ as section,LQ as sectionToFace,oP as serializeHistory,uN as setJointValue,lN as setJointValues,oO as setShapeOrigin,yO as setTagMetadata,OM as sewShells,M$ as shape,mY as shapeToMeshInput,zD as shapeType,KA as sharedEdges,GQ as shell,xY as shellMesh,wY as shellShape,gj as shellWithEvolution,XQ as simplify,OG as sketchCircle,kG as sketchEllipse,tG as sketchExtrude,QW as sketchFace,PG as sketchFaceOffset,IG as sketchHelix,rG as sketchLoft,ZK as sketchOnFace2D,XK as sketchOnPlane2D,FG as sketchParametricFunction,MG as sketchPolysides,AG as sketchRectangle,eG as sketchRevolve,jG as sketchRoundedRectangle,nG as sketchSweep,fJ as sketchText,$W as sketchWires,lo as sketcherStateError,zQ as slice,EM as solid,zj as solidFromShell,eQ as solveAssembly,aM as sphere,cN as sphericalJoint,RQ as split,QN as stepCount,$N as stepsFrom,YK as stretch2D,SM as subFace,Gj as supportExtrude,aT as supportsConstraintSketch,iT as supportsProjection,WX as surfaceFromGrid,qX as surfaceFromImage,Wj as sweep,gO as tagFaces,_M as tangentArc,Ha as tap,Ua as tapErr,gG as textBlueprints,pJ as textMetrics,qQ as thicken,cP as thread,pM as threePointArc,e$ as toBREP,NA as toBufferGeometryData,PA as toGroupedBufferGeometryData,MX as toKernelVec,IA as toLODGeometryData,FA as toLineGeometryData,WK as toSVGPathD,sD as toVec2,oD as toVec3,sM as torus,jX as tpmsLattice,MQ as transformCopy,T1 as transforms,EQ as translate,GK as translate2D,EK as translateDrawing,ND as translatePlane,$a as tryCatch,eo as tryCatchAsync,qj as twistExtrude,co as typeCastError,YN as undoLast,ho as unsupportedError,j as unwrap,Xa as unwrapErr,Ja as unwrapOr,Ya as unwrapOrElse,RM as updateNode,xJ as updateRoles,YD as uvBounds,ZD as uvCoordinates,rE as validSolid,U$ as validatePlanetary,F as validationError,jj as variableFillet,uD as vecAdd,SD as vecAngle,hD as vecCross,vD as vecDistance,mD as vecDot,bD as vecEquals,xD as vecIsZero,gD as vecLength,_D as vecLengthSq,pD as vecNegate,yD as vecNormalize,CD as vecProjectToPlane,ED as vecRepr,wD as vecRotate,fD as vecScale,dD as vecSub,wM as vertex,ZJ as vertexFinder,rD as vertexPosition,WA as verticesOfEdge,SY as voxelBoolean,LY as voxelBooleanField,WY as voxelBooleanFieldShapes,TY as voxelBooleanShapes,IY as voxelField,UY as voxelFieldFromShape,BM as walkAssembly,cY as windingNumbers,vM as wire,eF as wireFinder,yM as wireLoop,UA as wiresOfFace,pT as withKernel,BX as withKernelDir,zX as withKernelPnt,RX as withKernelVec,hT as withQuality,IT as withScope,zT as withScopeResult,BT as withScopeResultAsync,yT as withTier,Ba as zipResults};
|
|
59
|
+
</Relationships>`),c(`3D/3dmodel.model`,s)])}function Kq(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 qq(e){return[e[0],-e[1]]}function Jq(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(hF(qq([t.cx,t.cy]),qq([a,o]))),t.cx=a,t.cy=o,i+=2}}function Yq(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(hF(qq([t.cx,t.cy]),qq([a,o]))),t.cx=a,t.cy=o,i+=2}}function Xq(e,t,n,r){for(let i of e){let e=n?t.cx+i:i;r.push(hF(qq([t.cx,t.cy]),qq([e,t.cy]))),t.cx=e}}function Zq(e,t,n,r){for(let i of e){let e=n?t.cy+i:i;r.push(hF(qq([t.cx,t.cy]),qq([t.cx,e]))),t.cy=e}}function Qq(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(xF(qq([t.cx,t.cy]),[qq([s,c]),qq([l,u])],qq([d,f]))),t.prevControlX=l,t.prevControlY=u,t.cx=d,t.cy=f,i+=6}}function $q(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(xF(qq([t.cx,t.cy]),[qq([c,l]),qq([u,d])],qq([f,p]))),t.prevControlX=u,t.prevControlY=d,t.cx=f,t.cy=p,t.lastCmd=`S`,i+=4}}function eJ(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(xF(qq([t.cx,t.cy]),[qq([s,c])],qq([l,u]))),t.prevControlX=s,t.prevControlY=c,t.cx=l,t.cy=u,i+=4}}function tJ(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(xF(qq([t.cx,t.cy]),[qq([c,l])],qq([u,d]))),t.prevControlX=c,t.prevControlY=l,t.cx=u,t.cy=d,t.lastCmd=`T`,i+=2}}function nJ(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[gF(qq([e,t]),qq(c),qq([e,s])),gF(qq([e,s]),qq(l),qq([e,t]))]}catch{return[]}}function rJ(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[gF(qq([e,t]),qq([b,x]),qq([n,r]))]}catch{return[hF(qq([e,t]),qq([n,r]))]}}function iJ(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(hF(qq([t.cx,t.cy]),qq([d,f])));else{let e=d-t.cx,n=f-t.cy;Math.sqrt(e*e+n*n)<1e-10?r.push(...nJ(t.cx,t.cy,s,c,u)):r.push(...rJ(t.cx,t.cy,d,f,s,c,l,u))}t.cx=d,t.cy=f,i+=7}}function aJ(e,t){(Math.abs(e.cx-e.sx)>1e-10||Math.abs(e.cy-e.sy)>1e-10)&&t.push(hF(qq([e.cx,e.cy]),qq([e.sx,e.sy]))),e.cx=e.sx,e.cy=e.sy}function oJ(e){let t=Kq(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`:Jq(i,r,t,n);break;case`L`:Yq(i,r,t,n);break;case`H`:Xq(i,r,t,n);break;case`V`:Zq(i,r,t,n);break;case`C`:Qq(i,r,t,n);break;case`S`:$q(i,r,t,n);break;case`Q`:eJ(i,r,t,n);break;case`T`:tJ(i,r,t,n);break;case`A`:iJ(i,r,t,n);break;case`Z`:aJ(r,n);break}a!==`S`&&a!==`T`&&(r.lastCmd=a)}return n}function sJ(e){try{let t=oJ(e);return t.length===0?k(fo(`SVG_EMPTY_PATH`,`SVG path produced no curves`)):O(new zF(t))}catch(e){return k(fo(`SVG_PARSE_FAILED`,`Failed to parse SVG path: ${e instanceof Error?e.message:String(e)}`))}}function cJ(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=sJ(l);u.ok&&n.push(u.value)}return n.length===0?k(fo(`SVG_NO_PATHS`,`No <path> elements found in SVG`)):O(n)}catch(e){return k(fo(`SVG_IMPORT_FAILED`,`Failed to import SVG: ${e instanceof Error?e.message:String(e)}`))}}function lJ(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(fo(N.STEP_EXPORT_CONFIGURED_FAILED,`Configured STEP export failed`,e))}}async function uJ(e){try{let t=await e.arrayBuffer(),n=U().importSTEP(t);return n.length===0?k(fo(`STEP_IMPORT_FAILED`,`STEP file contains no valid geometry`)):O(W(n[0]))}catch{return k(fo(`STEP_IMPORT_FAILED`,`Failed to load STEP file`))}}async function dJ(e){try{let t=await e.arrayBuffer(),n=U().importSTL(t);return n.IsNull()?k(fo(`STL_IMPORT_FAILED`,`Failed to create solid from STL mesh`)):O(W(n))}catch{return k(fo(`STL_IMPORT_FAILED`,`Failed to load STL file`))}}async function fJ(e){try{let t=await e.arrayBuffer(),n=U().importIGES(t);return n.length===0?k(fo(`IGES_IMPORT_FAILED`,`IGES file contains no valid geometry`)):O(W(n[0]))}catch{return k(fo(`IGES_IMPORT_FAILED`,`Failed to load IGES file`))}}function pJ(e,t,n={}){let r=_G(e,t);return new fG((typeof n.plane==`string`||n.plane===void 0?r.sketchOnPlane(n.plane,n.origin):r.sketchOnPlane(n.plane)).map(e=>Array.isArray(e)?new YW(e.map(XW)):XW(e)))}function mJ(e,t){let n=t?.fontSize??1,r=hG(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 hJ(e){let t=e?.fontSize??1,n=hG(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 gJ(e,t){let n=0,r=KD(t);if(e.surfaceType!==void 0)if(r===e.surfaceType)n+=1;else return-1/0;if(e.normal!==void 0){let r=$D(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=eO(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=vP(t);if(r.ok&&r.value>0){let t=Math.abs(Math.log(e.area/r.value));t>1&&(n-=t)}}return n}function _J(e){let t=KD(e),n=$D(e),r=eO(e),i=vP(e);return{entityType:`face`,surfaceType:t,normal:n,centroid:r,area:i.ok?i.value:void 0}}var vJ=.9;function yJ(e){if(e[2]>vJ)return`box:top`;if(e[2]<-.9)return`box:bottom`;if(e[1]>vJ)return`box:back`;if(e[1]<-.9)return`box:front`;if(e[0]>vJ)return`box:right`;if(e[0]<-.9)return`box:left`}function bJ(e,t){let n=zE(e),r=new Map;if(t===`box`){for(let e of n){let t=yJ($D(e));t!==void 0&&!r.has(t)&&r.set(t,YO(e))}return r}let i=0;for(let e of n)r.set(`${t}:face_${i}`,YO(e)),i++;return r}function xJ(e,t,n){return{origin:e,role:t,hint:_J(n)}}function SJ(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 CJ=.1,wJ=.5;function TJ(e,t,n,r){let i=zE(n),a=r??gJ,o=t.get(e.origin)?.get(e.role);if(o!==void 0){for(let e of i)if(YO(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>wJ&&u.push([t,n]),n>s?(l=s,s=n,c=t):n>l&&(l=n)}return c!==void 0&&s>wJ?s-l<CJ&&u.length>1?{ref:e,reason:`ambiguous`,candidates:u.filter(([,e])=>e>=s-CJ).map(([e])=>e)}:{face:c,confidence:`geometric-fallback`}:{ref:e,reason:`not-found`}}function EJ(e){return e.type===`init`}function DJ(e){return e.type===`operation`}function OJ(e){return e.type===`dispose`}function kJ(e){return e.success}function AJ(e){return!e.success}function jJ(){return{pending:new Map}}function MJ(e,t){let n=new Map(e.pending);return n.set(t.id,t),{pending:n}}function NJ(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 PJ(e){return e.pending.size}function FJ(e){return e.pending.size===0}function IJ(e,t){for(let n of e.pending.values())n.reject(t);return{pending:new Map}}function LJ(e,t){let n=t.data,r=e.get(n.id);if(r)if(e.delete(n.id),kJ(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 RJ(e){let{worker:t,wasmUrl:n}=e,r=new Map,i=!1;function a(){return crypto.randomUUID()}function o(e){LJ(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 zJ(){return{operations:new Map}}function BJ(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function VJ(e,t){let n=globalThis;n.onmessage=async r=>{let i=r.data;if(EJ(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(DJ(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(OJ(i)){let e={id:i.id,success:!0};n.postMessage(e),n.close?.()}}}var HJ=Object.defineProperty,UJ=(e,t)=>{let n={};for(var r in e)HJ(n,r,{get:e[r],enumerable:!0});return t||HJ(n,Symbol.toStringTag,{value:`Module`}),n},WJ=1,GJ=2;function KJ(e,t){t===`commonFace`&&e.SetGlue(WJ),t===`sameFace`&&e.SetGlue(GJ)}function qJ(e){return typeof e==`number`}function JJ(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 YJ(e){return typeof e==`number`?!0:Array.isArray(e)&&e.length===2?e.every(qJ):!1}function XJ(e,t){let n=n=>{let r=e.findAll(n);if(r.length===0)return[];let i=0,a=vD(rD(Fk(r)),t);for(let e=1;e<r.length;e++){let n=vD(rD(Pk(r,e)),t);n<a&&(a=n,i=e)}return[Pk(r,i)]},r=e=>{let t=n(e);return t.length===0?k(po(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found 0 element(s)`)):O(Fk(t))};return{...e,findAll:n,findUnique:r}}function ZJ(e){return UP(`vertex`,e,ZJ,(t,n)=>({nearestTo:t=>XJ(ZJ(e),t),atPosition:(e,t=1e-4)=>n(n=>vD(rD(n),e)<t),withinBox:(e,t)=>n(n=>{let r=rD(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=rD(n);return Math.abs(vD(i,t)-e)<r})}))}function QJ(){return ZJ([])}var $J=new Map,eY=null,tY=null;function nY(e,t){$J.set(e,t),eY||=e,e===eY&&(tY=t)}function rY(e){if(!e&&tY)return tY;let t=e??eY;if(!t)throw Error(`brepjs voxel engine not initialized. Call initVoxel() (or registerVoxel()) before using voxel operations.`);let n=$J.get(t);if(!n)throw Error(`brepjs: voxel engine '${t}' is not registered.`);return n}function iY(){return eY}function aY(e,t=`voxel`){nY(t,e),eY=t,tY=e}function oY(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 sY(e,t){return oY(e)||(t.length%3==0?null:F(`VOXEL_INVALID_QUERIES`,`queries length must be a multiple of 3 (flat xyz).`))}function cY(e){try{return O(rY(e))}catch(e){return k(uo(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function lY(e,t,n){let r=sY(e,t);if(r)return k(r);let i=cY(n);return A(i)?i:O(i.value.winding_numbers(e.vertices,e.triangles,t))}function uY(e,t,n){let r=sY(e,t);if(r)return k(r);let i=cY(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 dY=48,fY=2;function pY(e,t,n){let r=oY(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??dY,a=t?.padding??fY;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=cY(n);if(A(o))return o;try{try{var s=CT();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(I(`VOXEL_REPAIR_FAILED`,e instanceof Error?e.message:`voxel repair failed (grid too large?).`,e))}}var mY=.001;function hY(e,t=mY){try{let n=Tk(e,{tolerance:t});return n.vertices.length===0||n.triangles.length===0?k(I(`VOXEL_SHAPE_MESH_EMPTY`,`shape tessellated to an empty triangle mesh.`)):O({vertices:n.vertices,triangles:n.triangles})}catch(e){return k(I(`VOXEL_SHAPE_MESH_FAILED`,e instanceof Error?e.message:`failed to mesh shape for voxel op.`,e))}}var gY=48,_Y=2,vY={union:0,intersection:1,difference:2};function yY(e){let t=e?.resolution??gY,n=e?.padding??_Y;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 bY(e){if(e.positions.length===0||e.indices.length===0)return k(I(`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 xY(e,t,n,r){let i=oY(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=yY(n);if(A(a))return a;let o=cY(r);if(A(o))return o;try{try{var s=CT();return bY(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(I(`VOXEL_OFFSET_FAILED`,e instanceof Error?e.message:`voxel offset failed (grid too large?).`,e))}}function SY(e,t,n,r){let i=oY(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=yY(n);if(A(a))return a;let o=cY(r);if(A(o))return o;try{try{var s=CT();return bY(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(I(`VOXEL_SHELL_FAILED`,e instanceof Error?e.message:`voxel shell failed (grid too large?).`,e))}}function CY(e,t,n,r,i){let a=oY(e);if(a)return k(a);let o=oY(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=vY[n],c=yY(r);if(A(c))return c;let l=cY(i);if(A(l))return l;try{try{var u=CT();return bY(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(I(`VOXEL_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel boolean failed (grid too large?).`,e))}}function wY(e,t,n,r){let i=hY(e);return A(i)?i:xY(i.value,t,n,r)}function TY(e,t,n,r){let i=hY(e);return A(i)?i:SY(i.value,t,n,r)}function EY(e,t,n,r,i){let a=hY(e);if(A(a))return a;let o=hY(t);return A(o)?o:CY(a.value,o.value,n,r,i)}var DY=48,OY=2,kY={union:0,intersection:1,difference:2};function AY(e){let t=e?.resolution??DY,n=e?.padding??OY;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 jY(e){try{var t=CT();let n=e.contour(),{positions:r,normals:i,indices:a}=t.u({value:n,[Symbol.dispose](){n.free()}}).value;if(r.length===0||a.length===0)return k(I(`VOXEL_DEGENERATE_RESULT`,`the voxel field contoured to an empty mesh (over-shrunk offset or disjoint operands?).`));let o=r.length/3;return O({vertices:r,normals:i,triangles:a,uvs:new Float32Array(o*2),faceGroups:[{start:0,count:a.length/3,faceHash:0}]})}catch(e){t.e=e}finally{t.d()}}function MY(e){return{raw:e,delete(){e.free()}}}function NY(e){return PY(e)}function PY(e){let t=PT(MY(e)),n={get value(){return t.value.raw},get disposed(){return t.disposed},[Symbol.dispose](){t[Symbol.dispose]()},boolean(e,t){return this.value.boolean(e.value,kY[t]),n},offset(e){return this.value.offset(e),n},shell(e){return this.value.shell(e),n},reinit(){return this.value.reinit(),n},contour(){let e=jY(this.value);if(A(e))throw Error(e.error.message);return e.value}};return n}function FY(e){return!e.disposed}function IY(){return k(F(`VOXEL_FIELD_DISPOSED`,`the voxel field handle has been disposed.`))}function LY(e,t,n){let r=oY(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelField requires a non-empty triangle mesh.`));let i=AY(t);if(A(i))return i;let a=cY(n);if(A(a))return a;try{return O(PY(new a.value.VoxelField(e.vertices,e.triangles,i.value.resolution,i.value.padding)))}catch(e){return k(I(`VOXEL_FIELD_VOXELIZE_FAILED`,e instanceof Error?e.message:`voxel field voxelization failed (grid too large or non-dense?).`,e))}}function RY(e,t,n,r,i){let a=oY(e);if(a)return k(a);let o=oY(t);if(o)return k(o);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBooleanField requires a non-empty mesh for operand A.`));if(t.vertices.length===0||t.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBooleanField requires a non-empty mesh for operand B.`));let s=AY(r);if(A(s))return s;let c=cY(i);if(A(c))return c;try{return O(PY(c.value.VoxelField.boolean_of(e.vertices,e.triangles,t.vertices,t.triangles,kY[n],s.value.resolution,s.value.padding)))}catch(e){return k(I(`VOXEL_FIELD_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel field boolean failed (grid too large or non-dense?).`,e))}}function zY(e,t,n){if(!FY(e)||!FY(t))return IY();try{return e.value.boolean(t.value,kY[n]),O(e)}catch(e){return k(I(`VOXEL_FIELD_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel field boolean failed (dim mismatch?).`,e))}}function BY(e,t){if(!FY(e))return IY();if(!Number.isFinite(t))return k(F(`VOXEL_INVALID_DISTANCE`,`distance must be a finite number.`));try{return e.value.offset(t),O(e)}catch(e){return k(I(`VOXEL_FIELD_OFFSET_FAILED`,e instanceof Error?e.message:`voxel field offset failed.`,e))}}function VY(e,t){if(!FY(e))return IY();if(!Number.isFinite(t)||t<=0)return k(F(`VOXEL_INVALID_THICKNESS`,`thickness must be a finite number > 0.`));try{return e.value.shell(t),O(e)}catch(e){return k(I(`VOXEL_FIELD_SHELL_FAILED`,e instanceof Error?e.message:`voxel field shell failed.`,e))}}function HY(e){if(!FY(e))return IY();try{return e.value.reinit(),O(e)}catch(e){return k(I(`VOXEL_FIELD_REINIT_FAILED`,e instanceof Error?e.message:`voxel field reinit failed.`,e))}}function UY(e){if(!FY(e))return IY();try{return jY(e.value)}catch(e){return k(I(`VOXEL_FIELD_CONTOUR_FAILED`,e instanceof Error?e.message:`voxel field contour failed.`,e))}}function WY(e,t,n){let r=hY(e);return A(r)?r:LY(r.value,t,n)}function GY(e,t,n,r,i){let a=hY(e);if(A(a))return a;let o=hY(t);return A(o)?o:RY(a.value,o.value,n,r,i)}var KY=48,qY=2;function JY(e){try{return O(rY(e))}catch(e){return k(uo(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function YY(e){let t=e?.resolution??KY,n=e?.padding??qY;return!Number.isInteger(t)||t<1?k(F(`SDF_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(F(`SDF_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function XY(e){return{raw:e,delete(){e.free()}}}var ZY={offsetField(e){return QY(this.value.offset_field(e.value))},roundField(e){return QY(this.value.round_field(e.value))},shellField(e){return QY(this.value.shell_field(e.value))},smoothUnionField(e,t){return QY(this.value.smooth_union_field(e.value,t.value))}};function QY(e){let t=PT(XY(e));return{get value(){return t.value.raw},get disposed(){return t.disposed},[Symbol.dispose](){t[Symbol.dispose]()},union(e){return QY(this.value.union(e.value))},intersection(e){return QY(this.value.intersection(e.value))},difference(e){return QY(this.value.difference(e.value))},smoothUnion(e,t){return QY(this.value.smooth_union(e.value,t))},smoothIntersection(e,t){return QY(this.value.smooth_intersection(e.value,t))},smoothDifference(e,t){return QY(this.value.smooth_difference(e.value,t))},offset(e){return QY(this.value.offset(e))},round(e){return QY(this.value.round(e))},shell(e){return QY(this.value.shell(e))},onion(e){return QY(this.value.onion(e))},...ZY,translate(e,t,n){return QY(this.value.translate(e,t,n))},rotate(e,t,n,r){return QY(this.value.rotate(e,t,n,r))},scale(e){return QY(this.value.scale(e))},rasterize(e){return $Y(this.value,e)},rasterizeIn(e,t){return eX(this.value,e,t)}}}function $Y(e,t){let n=YY(t);if(A(n))return n;try{return O(NY(e.rasterize(n.value.resolution,n.value.padding)))}catch(e){return tX(e)}}function eX(e,t,n){let r=YY(n);if(A(r))return r;let i=nX(t);if(i)return k(i);try{return O(NY(e.rasterize_in(t.min[0],t.min[1],t.min[2],t.max[0],t.max[1],t.max[2],r.value.resolution,r.value.padding)))}catch(e){return tX(e)}}function tX(e){return k(I(`SDF_RASTERIZE_FAILED`,e instanceof Error?e.message:`SDF rasterization failed (grid too large?).`,e))}function nX(e){if(![...e.min,...e.max].every(e=>Number.isFinite(e)))return F(`SDF_INVALID_BOUNDS`,`bounds must be finite numbers.`);for(let t=0;t<3;t++)if(e.max[t]<=e.min[t])return F(`SDF_INVALID_BOUNDS`,`bounds max must exceed min on every axis.`);return null}function rX(e,t){let n=JY(t);if(A(n))return n;try{return O(QY(e(n.value)))}catch(e){return k(I(`SDF_BUILD_FAILED`,e instanceof Error?e.message:`SDF primitive construction failed.`,e))}}function iX(e,t){return rX(t=>t.Sdf.sphere(e),t)}function aX(e,t,n,r){return rX(r=>r.Sdf.box_(e,t,n),r)}function oX(e,t,n,r,i){return rX(i=>i.Sdf.rounded_box(e,t,n,r),i)}function sX(e,t,n){return rX(n=>n.Sdf.cylinder(e,t),n)}function cX(e,t,n){return rX(n=>n.Sdf.cone(e,t),n)}function lX(e,t,n,r){return rX(r=>r.Sdf.capsule(e[0],e[1],e[2],t[0],t[1],t[2],n),r)}function uX(e,t,n){return rX(n=>n.Sdf.torus(e,t),n)}function dX(e,t,n){return rX(n=>n.Sdf.plane(e[0],e[1],e[2],t),n)}function fX(e){if(e.length<2)return k(F(`SDF_INVALID_SPINE`,`sweep spine needs at least 2 points.`));let t=new Float64Array(e.length*3);for(let n=0;n<e.length;n++){let r=e[n];if(!r.every(e=>Number.isFinite(e)))return k(F(`SDF_INVALID_SPINE`,`sweep spine coordinates must be finite.`));t[n*3]=r[0],t[n*3+1]=r[1],t[n*3+2]=r[2]}return O(t)}function pX(e,t,n,r){let i=fX(e);if(A(i))return i;let a=n?.closed??!1;return rX(e=>e.Sdf.sweep(i.value,t.value,a),r)}var mX={gyroid:0,schwarzP:1,diamond:2};function hX(e,t,n,r){let i=mX[e];return i===void 0?k(F(`SDF_INVALID_LATTICE_KIND`,`unknown lattice kind: ${e}`)):rX(e=>e.Sdf.lattice(i,t.value,n.value),r)}function gX(e,t,n){return rX(n=>n.Sdf.strut_lattice(e,t.value),n)}function _X(e){return{raw:e,delete(){e.free()}}}function vX(e){let t=PT(_X(e));return{get value(){return t.value.raw},get disposed(){return t.disposed},[Symbol.dispose](){t[Symbol.dispose]()}}}function yX(e,t){let n=JY(t);if(A(n))return n;try{return O(vX(e(n.value)))}catch(e){return k(I(`SDF_FIELD_BUILD_FAILED`,e instanceof Error?e.message:`scalar field construction failed.`,e))}}function bX(e,t){return yX(t=>t.ScalarField.constant(e),t)}function xX(e,t,n,r,i,a){return yX(a=>a.ScalarField.axial_ramp(e,t,n,r,i),a)}function SX(e,t,n,r,i,a,o){return yX(o=>o.ScalarField.radial_ramp(e[0],e[1],e[2],t,n,r,i,a),o)}function CX(e,t,n,r){return yX(r=>r.ScalarField.from_sdf(e.value,t,n),r)}function wX(e,t,n,r){return yX(r=>r.ScalarField.clamp(e.value,t,n),r)}var TX={gyroid:0,schwarzP:1,diamond:2},EX=48,DX=2;function OX(e){let t=TX[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??EX,r=e.padding??DX;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 kX(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 AX(e,t,n){let r=oY(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=OX(t);if(A(i))return i;let a=cY(n);if(A(a))return a;let{tag:o,period:s,thickness:c,resolution:l,padding:u}=i.value;try{try{var d=CT();return O(kX(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(I(`LATTICE_INFILL_FAILED`,e instanceof Error?e.message:`lattice infill failed (grid too large?).`,e))}}function jX(e,t,n){let r=hY(e);return A(r)?r:AX(r.value,t,n)}function MX(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=OX(t);if(A(r))return r;let i=cY(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=CT();return O(kX(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(I(`TPMS_LATTICE_FAILED`,e instanceof Error?e.message:`tpms lattice failed (grid too large?).`,e))}}function NX(e){return U().createVector3d(e[0],e[1],e[2])}function PX(e){return U().createPoint3d(e[0],e[1],e[2])}function FX(e){return U().createDirection3d(e[0],e[1],e[2])}function IX(e){return[e.X(),e.Y(),e.Z()]}function LX(e){return[e.X(),e.Y(),e.Z()]}function RX(e){return[e.X(),e.Y(),e.Z()]}function zX(e,t){let n=NX(e);try{return t(n)}finally{n.delete()}}function BX(e,t){let n=PX(e);try{return t(n)}finally{n.delete()}}function VX(e,t){let n=FX(e);try{return t(n)}finally{n.delete()}}var HX=.299,UX=.587,WX=.114;function GX(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 KX(e,n,r,s,c,o)}catch{}try{return qX(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 KX(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 bE(s)?O(s):(s[Symbol.dispose](),k(P(N.SURFACE_FAILED,`B-spline surface did not produce a face`)))}function qX(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 bE(s)||xE(s)?O(s):(s[Symbol.dispose](),k(P(N.SURFACE_FAILED,`surfaceFromGrid: unexpected shape type from sewing`)))}async function JX(e,t={}){let n=t.channel??`luminance`,r=Math.max(1,Math.round(t.downsample??1));if(typeof createImageBitmap!=`function`)return k(fo(N.SURFACE_FAILED,`surfaceFromImage requires createImageBitmap (not available in this environment)`));let i;try{i=await createImageBitmap(e)}catch(e){return k(fo(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(fo(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(fo(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=(HX*o+UX*s+WX*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),GX(l,u)}function YX(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function XX(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=YX(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 SE(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 ZX(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 SE(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 QX(e){let n=zE(e);if(n.length!==1)return null;let r=t(n,0);if(eD(r)!==`sphere`)return null;let i=U().area(r.wrapped);return Math.sqrt(i/(4*Math.PI))}function $X(e,t,n){try{let r=W(U().offset(e.wrapped,t,n));return wE(r)?O(r):(r[Symbol.dispose](),k(co(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 eZ(e,t,n){let r=U();try{let i=VE(e),a=VE(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 wE(s)?O(s):(s[Symbol.dispose](),k(co(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 tZ(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(!wE(e)||!wE(t))return k(F(N.MINKOWSKI_NOT_3D,`minkowski: both shape and tool must be 3D`));let i=QX(t);return i===null?eZ(e,t,r):$X(e,i,r)}function nZ(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 SE(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 rZ=1e-10;function iZ(e,t,n,r){return e*r-t*n}function aZ(e,t,n,r){return e*n+t*r}function oZ(e,t){return Math.sqrt(e*e+t*t)}function sZ(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 cZ(e){let t=0;for(let n=0;n<e.length;n++){let r=sZ(e,n),i=sZ(e,n+1);t+=r.x*i.y-i.x*r.y}return t<0?[...e].reverse():e}function lZ(e,t){let n=sZ(e,t-1),r=sZ(e,t),i=sZ(e,t+1),a=r.x-n.x,o=r.y-n.y,s=oZ(a,o),c=i.x-r.x,l=i.y-r.y,u=oZ(c,l);if(s<rZ||u<rZ)return{dx:0,dy:0};let d=-o/s,f=a/s,p=-l/u,m=c/u,h=d+p,g=f+m,_=oZ(h,g);if(_<rZ)return{dx:d,dy:f};h/=_,g/=_;let v=aZ(h,g,d,f),y=Math.abs(v)>rZ?1/v:1;return{dx:h*y,dy:g*y}}function uZ(e){return!e.prev||!e.next?!1:iZ(e.x-e.prev.x,e.y-e.prev.y,e.next.x-e.x,e.next.y-e.y)<-1e-10}function dZ(e){let t=e.map((t,n)=>{let r=lZ(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 fZ(e,t){let n=e;for(let e=0;e<t&&n;e++)n.active=!1,n=n.next}function pZ(e){let t=1,n=e.next;for(;n!==e&&(t++,n=n.next,!(t>1e4)););return t}function mZ(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)<rZ&&Math.abs(r)<rZ)return null;let o;if(o=Math.abs(n)>Math.abs(r)?i/n:a/r,o<rZ)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)>rZ){let e=c/s;if(Math.abs(o-e)>1e-4*Math.max(1,Math.abs(o)))return null}return o}function hZ(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=oZ(r,i);if(a<rZ)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)<rZ)return null;let f=-c/d;if(f<rZ)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=oZ(y,b);if(x<rZ)return f;let S=aZ(p-h,m-g,y,b)/(x*x);return S<-.01||S>1.01?null:f}function gZ(e){let t=[];for(let n of e){if(!n.active||!n.next)continue;let e=mZ(n,n.next);if(e!==null&&e>rZ){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(uZ(n)){let e=n.next.next,r=0;for(;e!==n.prev&&e!==n&&r<1e3;){let i=hZ(n,e,e.next);if(i!==null&&i>rZ){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 _Z(e){if(e.length<3)return O({nodes:[],faces:[]});try{return O(vZ(e))}catch(e){return k(I(N.STRAIGHT_SKELETON_FAILED,e instanceof Error?e.message:String(e),e))}}function vZ(e){let t=cZ(e),n=t.length,r=[],i=Array.from({length:n},()=>[]),a=dZ(t),o=0,s=n*n*2;for(;o<s;){o++;let e=a.find(e=>e.active);if(!e)break;let t=pZ(e);if(t<=3){if(t===3){let t=e,n=t.next,a=n.next,o=mZ(t,n),s=o!==null&&o>rZ?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 fZ(e,t);continue}let n=a.filter(e=>e.active),s=gZ(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=lZ(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=lZ(f(e),0);e.bx=p.dx,e.by=p.dy;let m=lZ(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=[sZ(t,e),sZ(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&&oZ(n.x-i.x,n.y-i.y)>rZ&&(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 yZ(e){let t=RE(e).map(e=>{let t=tk(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 bZ(e){let t=[];for(let n=1;n<e-1;n++)t.push([0,n,n+1]);return t}function xZ(e,t,n,r,i,a){return(n-e)*(a-t)-(r-t)*(i-e)}function SZ(e,t,n,r,i,a,o,s){let c=xZ(n,r,i,a,e,t),l=xZ(i,a,o,s,e,t),u=xZ(o,s,n,r,e,t);return!((c<0||l<0||u<0)&&(c>0||l>0||u>0))}function CZ(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||xZ(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&&SZ(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 wZ(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=bZ(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 TZ(e,t){let n=(t?.angle??45)*iD,r=Math.tan(n);try{let t=yZ(e);if(t.length<3)return k(P(N.ROOF_FAILED,`Wire must have at least 3 edges for roof generation`));let n=_Z(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=wZ(i,r,a);for(let[e,n,r]of CZ(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(mE(a.fixShape(e)))}catch(e){try{let t=mE(a.sew(o,1e-6));return $T(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 EZ={coincident:3,concentric:4,distance:1,angle:1},DZ=[1,0,0,0];function OZ(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function kZ(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function AZ(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function jZ(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 MZ(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function NZ(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function PZ(e){return NZ(jZ(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function FZ(e,t){let n=OZ(qM(t.rotation,e.origin),t.position);return{type:e.type,origin:n,...e.normal?{normal:qM(t.rotation,e.normal)}:{},...e.direction?{direction:qM(t.rotation,e.direction)}:{}}}function IZ(e,t,n){let r=e.normal??[0,0,1];return{position:MZ(r,AZ(r,kZ(e.origin,t.origin))+n),rotation:DZ}}function LZ(e,t){let n=e.direction??[0,0,1],r=YM(t.direction??[0,0,1],n),i=qM(r,t.origin);return{position:kZ(e.origin,i),rotation:r}}function RZ(e,t,n){let r=NZ(e.normal??[0,0,1]),i=NZ(t.normal??[0,0,1]),a=Math.acos(Math.max(-1,Math.min(1,AZ(i,r)))),o=jZ(i,r);return{position:[0,0,0],rotation:JM(Math.hypot(o[0],o[1],o[2])<1e-9?PZ(i):o,a-n)}}function zZ(e,t,n){let r=kZ(t,e),i=Math.hypot(r[0],r[1],r[2]);return{position:kZ(OZ(e,MZ(i<1e-9?[1,0,0]:MZ(r,1/i),n)),t),rotation:DZ}}function BZ(e,t,n,r){let i=NZ(e);return{position:MZ(i,AZ(i,kZ(t,n))-r),rotation:DZ}}function VZ(e,t,n){let r=NZ(e.direction??[0,0,1]),i=OZ(e.origin,MZ(r,AZ(r,kZ(t,e.origin))));if(n===0)return{position:kZ(i,t),rotation:DZ};let a=kZ(t,i),o=Math.hypot(a[0],a[1],a[2]);return{position:kZ(OZ(i,MZ(o<1e-9?PZ(r):MZ(a,1/o),n)),t),rotation:DZ}}function HZ(e,t,n){let r=NZ(t.direction??[0,0,1]),i=kZ(t.origin,e),a=kZ(i,MZ(r,AZ(r,i))),o=Math.hypot(a[0],a[1],a[2]);return n===0?{position:MZ(a,-1),rotation:DZ}:{position:kZ(MZ(o<1e-9?PZ(r):MZ(a,1/o),n),a),rotation:DZ}}function UZ(e,t,n){let r=NZ(e.direction??[0,0,1]),i=YM(NZ(t.direction??[0,0,1]),r),a=kZ(qM(i,t.origin),e.origin),o=kZ(a,MZ(r,AZ(r,a))),s=Math.hypot(o[0],o[1],o[2]);return{position:kZ(MZ(s<1e-9?PZ(r):MZ(o,1/s),n),o),rotation:i}}var WZ=new Set([`plane-plane`,`plane-point`,`point-plane`,`point-point`,`axis-axis`,`axis-point`,`point-axis`]),GZ={angle:`plane`,concentric:`axis`},KZ=new Set([`coincident`,`distance`,`angle`,`concentric`]);function qZ(e,t,n){let r=GZ[e];return r?t===r&&n===r:WZ.has(`${t}-${n}`)}function JZ(e,t,n){switch(`${e.type}-${t.type}`){case`plane-plane`:case`plane-point`:return IZ(e,t,n);case`point-plane`:return BZ(t.normal??[0,0,1],e.origin,t.origin,n);case`point-point`:return zZ(e.origin,t.origin,n);case`axis-axis`:return n===0?LZ(e,t):UZ(e,t,n);case`axis-point`:return VZ(e,t.origin,n);case`point-axis`:return HZ(e.origin,t,n);default:return null}}function YZ(e,t,n){switch(e.type){case`concentric`:return LZ(t,n);case`angle`:return RZ(t,n,(e.value??0)*Math.PI/180);default:{let r=JZ(t,n,e.type===`distance`?e.value??0:0);if(!r)throw Error(`solveMate: unsupported entity pair escaped filter: ${t.type}-${n.type}`);return r}}}function XZ(e,t){let n=new Map;for(let t of e)n.set(t,{position:[0,0,0],rotation:DZ});let r=[],i=t.filter(e=>KZ.has(e.type)&&e.entityA&&e.entityB),a=new Set;for(let e of i)e.entityB&&a.add(e.entityB.node);let o=new Set;for(let t of e)a.has(t)||o.add(t);for(let e of t)e.type===`fixed`&&e.entityA&&o.add(e.entityA.node);let s=[];for(let e of i){if(!e.entityA||!e.entityB)continue;let t=e.entityA.entity.type,n=e.entityB.entity.type;if(!qZ(e.type,t,n)){r.push(`${e.type}(${t}-${n})`);continue}s.push(e)}let c=!0;for(;c&&s.length>0;){c=!1;for(let e=s.length-1;e>=0;e--){let t=s[e];if(!t?.entityA||!t.entityB)continue;let r=t.entityA,i=t.entityB;if(!o.has(r.node)||(s.splice(e,1),c=!0,o.has(i.node)))continue;let a=n.get(r.node)??{position:[0,0,0],rotation:DZ},l=FZ(r.entity,a);n.set(i.node,YZ(t,l,i.entity)),o.add(i.node)}}for(let e of s)r.push(`${e.type}(unanchored)`);return{transforms:n,dof:r.reduce((e,t)=>e+(EZ[t]??EZ[t.split(`(`)[0]??``]??0),0),converged:r.length===0,unsupported:r}}function ZZ(e){if(e.face){let t=tO(e.face);return t?{type:`axis`,origin:t.origin,direction:t.direction}:{type:`plane`,origin:eO(e.face),normal:$D(e.face)}}if(e.edge){if(ek(e.edge)===`LINE`)return{type:`axis`,origin:tk(e.edge),direction:ik(e.edge)};let t=ok(e.edge);return t?{type:`axis`,origin:t.origin,direction:t.direction}:null}return e.point?{type:`point`,origin:e.point}:null}function QZ(e,t){let n=ZZ(e),r=ZZ(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 $Z(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=QZ(e.entityA,e.entityB);return t.ok?O({type:`coincident`,...t.value}):t}case`distance`:{let t=QZ(e.entityA,e.entityB);return t.ok?O({type:`distance`,...t.value,value:e.distance}):t}case`angle`:{let t=QZ(e.entityA,e.entityB);return t.ok?O({type:`angle`,...t.value,value:e.angle}):t}case`concentric`:{let t=QZ(e.axisA,e.axisB);return t.ok?O({type:`concentric`,...t.value}):t}}}function eQ(e,t){let n=e.mates??[];return{...e,mates:[...n,t]}}function tQ(e){let t=e.mates;if(!t||t.length===0)return k(F(N.ASSEMBLY_MATE_INVALID,`solveAssembly: no mates defined`));try{let n=[];BM(e,e=>{n.push(e.name)});let r=[];for(let e of t){let t=$Z(e);if(!t.ok)return t;r.push(t.value)}let i=XZ(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 nQ(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 rQ(e,n=1e-6){let r=[],i=e.map(e=>QE(e));return e.forEach((a,o)=>{for(let s=o+1;s<e.length;s++){if(iQ(t(i,o),t(i,s),n))continue;let c=j(nQ(a,t(e,s),n));c.hasInterference&&r.push({i:o,j:s,result:c})}}),r}function iQ(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 aQ(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 oQ(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 sQ(e){let{type:t,data:n}=e,r=U();if(t===`LINE`)return r.makeLineEdge([oQ(n,10),oQ(n,20),oQ(n,30)],[oQ(n,11),oQ(n,21),oQ(n,31)]);if(t===`CIRCLE`)return r.makeCircleEdge([oQ(n,10),oQ(n,20),oQ(n,30)],[0,0,1],oQ(n,40));if(t===`ARC`){let e=oQ(n,50)*Math.PI/180,t=oQ(n,51)*Math.PI/180;return r.makeCircleArc([oQ(n,10),oQ(n,20),oQ(n,30)],[0,0,1],oQ(n,40),e,t)}}async function cQ(e,t){let n;try{n=await e.text()}catch(e){return k(fo(N.DXF_IMPORT_FAILED,`Failed to read DXF blob`,e))}let r=aQ(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=sQ(e);t!==void 0&&a.push(t)}return a.length===0?O([]):O([dE(U().makeWire(a))])}catch(e){return k(fo(N.DXF_IMPORT_FAILED,`Failed to convert DXF entities to geometry`,e))}finally{for(let e of a)e.delete()}}function lQ(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(fo(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(fo(t,`Failed to sew triangular faces`))}}}function uQ(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 dQ(e){return e.split(/\s+/).slice(1).map(e=>parseInt(e.split(`/`)[0]??``,10)).filter(e=>!isNaN(e))}async function fQ(e){let t=(await e.text()).split(`
|
|
60
|
+
`),n=[],r=[];for(let e of t){let t=e.trim();if(t.startsWith(`v `)){let e=uQ(t);e&&n.push(e)}else if(t.startsWith(`f `)){let e=dQ(t);e.length>=3&&r.push(e)}}if(n.length===0||r.length===0)return k(fo(N.OBJ_IMPORT_FAILED,`OBJ file contains no valid geometry`));try{return pQ(n,r)}catch(e){let t=e instanceof Error?e.message:String(e);return k(fo(N.OBJ_IMPORT_FAILED,`OBJ import failed: ${t}`,e))}}function pQ(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 lQ(n,N.OBJ_IMPORT_FAILED)}function mQ(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 hQ(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95}function gQ(e){let t={},n=0;for(;n<e.length;){let r=e.indexOf(`="`,n);if(r<0)break;let i=r;for(;i>0&&hQ(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 _Q(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 vQ(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 yQ(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 bQ(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=gQ(e.slice(r,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of _Q(a,`color`)){let t=gQ(e).color;t!==void 0&&l.push(yQ(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=gQ(e.slice(n,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of _Q(a,`base`)){let t=gQ(e).displaycolor;t===void 0?l.push([0,0,0,1]):l.push(yQ(t))}t.set(c,l)}return t}function xQ(e){let t=[],n=[],r=[],i=bQ(e);for(let n of _Q(e,`vertex`)){let e=gQ(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=vQ(e,`object`);if(s!==null){let e=s.indexOf(`>`);if(e>=0){let t=gQ(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 _Q(e,`triangle`)){let e=gQ(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 SQ(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 CQ(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 lQ(t,N.THREEMF_IMPORT_FAILED)}}async function wQ(e){try{let t=await e.arrayBuffer(),n=mQ(new Uint8Array(t),`3D/3dmodel.model`);if(!n)return k(fo(N.THREEMF_IMPORT_FAILED,`3MF archive does not contain 3D/3dmodel.model (or uses unsupported compression)`));let r=xQ(new TextDecoder().decode(n));if(r.vertices.length===0||r.triangles.length===0)return k(fo(N.THREEMF_IMPORT_FAILED,`3MF model contains no valid geometry`));let i=CQ(r);if(i.ok){let e=SQ(r.triangleColors);e!==null&&OO(i.value,e)}return i}catch(e){let t=e instanceof Error?e.message:String(e);return k(fo(N.THREEMF_IMPORT_FAILED,`3MF import failed: ${t}`,e))}}async function TQ(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(fo(N.GLB_IMPORT_FAILED,`Failed to import GLB: ${t}`,e))}}function $(e){return`__wrapped`in e?e.val:e}function EQ(e){return $(e)}function DQ(e,t){return IO($(e),t)}function OQ(e,t,n){let r=n?.at;return LO($(e),t,r,n?.axis)}function kQ(e,t){let n=t?.at;return RO($(e),t?.normal??[1,0,0],n)}function AQ(e,t,n){return zO($(e),t,n?.center)}function jQ(e){return qO($(e))}function MQ(e,t){return WO($(e),t)}function NQ(e,t){return KO($(e),t)}function PQ(e,t,n){return iA($(e),$(t),{...n,unsafe:!0})}function FQ(e,t,n){return aA($(e),$(t),{...n,unsafe:!0})}function IQ(e,t){return cA(e.map(e=>$(e)),{...t,unsafe:!0})}function LQ(e,t,n){return lA($(e),t.map(e=>$(e)),{...n,unsafe:!0})}function RQ(e,t,n){return oA($(e),$(t),{...n,unsafe:!0})}function zQ(e,t,n){return dA($(e),t,n)}function BQ(e,t,n){return _A($(e),t,n)}function VQ(e,t){return vA($(e),t)}function HQ(e,t,n){return yA($(e),t,n)}function UQ(e,t){if(e!==void 0)return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(YP()).findAll(t)}function WQ(e,t){return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(QP()).findAll(t)}function GQ(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 KQ(e,t,n){let r=$(e),i,a;return n===void 0?(i=void 0,a=t):(i=UQ(t,r),a=n),Tj(r,i,a)}function qQ(e,t,n){let r=$(e),i,a;n===void 0?(i=void 0,a=t):(i=UQ(t,r),a=n);let o=GQ(a);return o.mode===`distAngle`?LA(r,[...i??RE(r)],o.distance,o.angle):Ej(r,i,o.distance)}function JQ(e,t,n,r){let i=$(e);return Dj(i,WQ(t,i),n,r?.tolerance)}function YQ(e,t,n){return Oj($(e),t,n?.tolerance)}function XQ(e,t){return Cj($(e),t)}function ZQ(e,t,n){let r=$(e);return Aj(r,WQ(t,r),n.pullDirection,n.neutralPlane,n.angle)}function QQ(e){return Ij($(e))}function $Q(e){return $O($(e))}function e$(e,t){return Tk($(e),t)}function t$(e,t){return Ek($(e),t)}function n$(e){return nD($(e))}function r$(e){return JO($(e))}function i$(e){return UD(e)}function a$(e){return Mj($(e))}function o$(e){return XO($(e))}function s$(e,t){return Qj($(e),typeof t==`number`?[0,0,t]:t)}function c$(e,t){let n=t?.at??[0,0,0];return $j($(e),n,t?.axis??[0,0,1],t?.angle??360)}function l$(e,t){return tM(e.map(e=>$(e)),t)}function u$(e,n){if(n===void 0){let t=zE(e);if(t.length===0)return k(F(N.COMPOUND_NO_FACES,`compoundOps: shape has no faces`));let n=Fk(t),r=eO(n)[2];for(let e=1;e<t.length;e++){let i=Pk(t,e),a=eO(i)[2];a>r&&(n=i,r=a)}return O(n)}if(typeof n==`function`){let r=n(QP()).findAll(e);return r.length===0?k(po(N.COMPOUND_FACE_NOT_FOUND,`compoundOps: face finder matched no faces`)):O(t(r,0))}return O(n)}function d$(e){return`sketchOnPlane`in e&&typeof e.sketchOnPlane==`function`?e.sketchOnPlane(`XY`).wire:e}function f$(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(xD(o))return k(F(`DRILL_ZERO_AXIS`,`Drill axis cannot be zero`));let s=yD(o),c=r.length===2?[r[0],r[1],0]:[r[0],r[1],r[2]],l;if(t.depth!==void 0)l=wA(i,t.depth,c,s);else{let e=QE(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=wA(i,a-r,[c[0]+s[0]*r,c[1]+s[1]*r,c[2]+s[2]*r],s)}return aA(n,l,{unsafe:!0})}function p$(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=u$(n,t.face);if(A(a))return a;let o=a.value,s=$D(o),c=eO(o),l=Xk(d$(r));if(A(l))return l;let u=Qj(IO(l.value,c),fD(yD(s),-i));return A(u)?u:aA(n,u.value,{unsafe:!0})}function m$(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=u$(n,t.face);if(A(a))return a;let o=a.value,s=$D(o),c=eO(o),l=Xk(d$(r));if(A(l))return l;let u=Qj(IO(l.value,c),fD(yD(s),i));return A(u)?u:iA(n,u.value,{unsafe:!0})}function h$(e,t){let n=$(e),r=t?.normal??[1,0,0],i=t?.at;return xD(r)?k(F(`MIRROR_ZERO_NORMAL`,`Mirror plane normal cannot be zero`)):iA(n,RO(n,r,i),{unsafe:!0})}function g$(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(xD(r))return k(F(`PATTERN_ZERO_DIRECTION`,`X direction cannot be zero`));if(xD(o))return k(F(`PATTERN_ZERO_DIRECTION`,`Y direction cannot be zero`));if(i===1&&s===1)return O(n);let l=yD(r),u=yD(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(IO(n,r))}return cA(d,{unsafe:!0})}var _$=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 v$(e){if(A(e))throw new _$(e.error);return e.value}function y$(e){return e}function b$(e){return e}function x$(e){return e}function S$(e){return e}function C$(e){return{val:e,__wrapped:!0,translate:t=>N$(DQ(e,t)),rotate:(t,n)=>N$(OQ(e,t,n)),mirror:t=>N$(kQ(e,t)),scale:(t,n)=>N$(AQ(e,t,n)),applyMatrix:t=>N$(v$(MQ(e,t))),moveX:t=>N$(DQ(e,[t,0,0])),moveY:t=>N$(DQ(e,[0,t,0])),moveZ:t=>N$(DQ(e,[0,0,t])),rotateX:t=>N$(OQ(e,t,{axis:[1,0,0]})),rotateY:t=>N$(OQ(e,t,{axis:[0,1,0]})),rotateZ:t=>N$(OQ(e,t,{axis:[0,0,1]})),bounds:()=>QE(e),describe:()=>n$(e),clone:()=>N$(v$(jQ(e))),mesh:t=>e$(e,t),meshEdges:t=>t$(e,t),isValid:()=>a$(e),isEmpty:()=>o$(e),heal:()=>N$(v$(QQ(e))),simplify:()=>N$(v$($Q(e))),toBREP:()=>v$(r$(e)),apply:t=>N$(t(e)),applyResult:t=>N$(v$(t(e))),done:()=>e}}function w$(e){return{fuse:(t,n)=>P$(v$(PQ(e,$(t),{...n,unsafe:!0}))),cut:(t,n)=>P$(v$(FQ(e,$(t),{...n,unsafe:!0}))),intersect:(t,n)=>P$(v$(RQ(e,$(t),{...n,unsafe:!0}))),fuseAll:(t,n)=>P$(S$(v$(cA([e,...t.map($)],{...n,unsafe:!0})))),cutAll:(t,n)=>P$(S$(v$(lA(e,t,{...n,unsafe:!0})))),section:(t,n)=>N$(v$(zQ(e,t,n))),split:t=>N$(v$(VQ(e,t))),slice:(t,n)=>v$(HQ(e,t,n))}}function T$(e){return{fillet(...t){return t.length===1?P$(S$(v$(KQ(y$(e),t[0])))):P$(S$(v$(KQ(y$(e),t[0],t[1]))))},chamfer(...t){return t.length===1?P$(S$(v$(qQ(y$(e),t[0])))):P$(S$(v$(qQ(y$(e),t[0],t[1]))))},shell:(t,n,r)=>P$(S$(v$(JQ(y$(e),t,n,r)))),offset:(t,n)=>P$(S$(v$(YQ(y$(e),t,n)))),draft:(t,n)=>P$(S$(v$(ZQ(y$(e),t,n))))}}function E$(e){return{drill:t=>P$(v$(f$(e,t))),pocket:t=>P$(v$(p$(e,t))),boss:t=>P$(v$(m$(e,t))),mirrorJoin:t=>P$(v$(h$(e,t))),rectangularPattern:t=>P$(v$(g$(e,t)))}}function D$(e){return{volume:()=>v$(_P(e)),area:()=>v$(vP(e)),volumeProps:()=>v$(mP(e)),surfaceProps:()=>v$(hP(e))}}function O$(e){return{edges:()=>RE(e),faces:()=>zE(e),wires:()=>BE(e),vertices:()=>VE(e)}}function k$(e){return{linearPattern:(t,n,r)=>P$(S$(v$(NM(e,t,n,r)))),circularPattern:(t,n,r)=>P$(S$(v$(PM(e,t,n,r))))}}function A$(e){return{...C$(e),...w$(e),...T$(e),...E$(e),...D$(e),...O$(e),...k$(e)}}function j$(e){return{...C$(e),length:()=>ak(e),startPoint:()=>tk(e),endPoint:()=>nk(e),pointAt:t=>rk(e,t),tangentAt:t=>ik(e,t),isClosed:()=>sk(e),sweep(t,n){if(!yE(e))throw Error(`sweep requires a Wire`);let r=v$(Wj(x$(e),$(t),n));return P$(Array.isArray(r)?r[0]:r)}}}function M$(e){return{...C$(e),area:()=>v$(vP(e)),normalAt:t=>$D(e,t),center:()=>eO(e),surfaceType:()=>v$(GD(e)),outerWire:()=>rO(e),innerWires:()=>aO(e),extrude:t=>P$(v$(s$(b$(e),t))),revolve:t=>P$(v$(c$(b$(e),t)))}}function N$(e){return wE(e)?A$(e):bE(e)?M$(e):vE(e)||yE(e)?j$(e):C$(e)}function P$(e){return A$(e)}function F$(e){if(e&&typeof e==`object`&&`face`in e&&typeof e.face==`function`&&`_defaultOrigin`in e)return M$(e.face());if(e&&typeof e==`object`&&`wrapped`in e)return bE(e)?M$(e):wE(e)?A$(e):vE(e)||yE(e)?j$(e):C$(e);throw Error(`shape() requires a Sketch or branded shape type`)}var I$=.25,L$=e=>Math.tan(e)-e;function R$(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 z$(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(R$(e,s*t,n,i))}return a}function B$(e){return Math.max(16,Math.round(8*Math.sqrt(e)))}function V$(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 H$(e,t,n){if(t===0)return O(e);let r=L$(e)+2*t*Math.tan(e)/n,i,a;if(r>L$(e)?(i=e,a=Math.PI/2-1e-6):(i=1e-4,a=e),r>L$(a)||r<L$(i))return k(F(`GEAR_PA_OUT_OF_RANGE`,`working pressure angle out of range — target inv(αw)=${r.toFixed(4)} not in [${L$(i).toFixed(4)}, ${L$(a).toFixed(4)}]`,void 0,{target:r,invLo:L$(i),invHi:L$(a)}));for(let e=0;e<50;e++){let e=.5*(i+a);L$(e)<r?i=e:a=e}return O(.5*(i+a))}function U$(e,t,n,r,i){return H$(e,t+n,r+i)}function W$(e,t,n,r,i){return H$(e,n-t,i-r)}function G$(e,t,n,r,i){return(e+t)*n*Math.cos(r)/(2*Math.cos(i))}function K$(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 q$(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 J$(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 Y$(e,t){return 1-e*Math.sin(t)*Math.sin(t)/2}function X$(e,t,n){return Math.max(0,Y$(e,t)-n)}function Z$(e){return e<8?.2:.485-2.88/e}function Q$(e,t,n,r){let i=e*1e3,a=Z$(r);return a<=0||n<=0||t<=0?1/0:2*i/(r*t*t*n*a)}function $$(e,t,n=!1){let r=(1.4+6.5/e)*(20/(t*180/Math.PI))**.15;return n?r*.85:r}function e1(e,t,n,r,i,a=!1){return Q$(e,t,n,r)*$$(r,i,a)}function t1(e){return e/2}function n1(e,t){return e+2*t}function r1(e){return e%2==0?Math.PI/e:0}function i1(e,t,n){return e*(1+t/n)+r1(n)}function a1(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=K$(n,r,i,s);if(A(c))return c;let l=U$(a,o,s,n,r);if(A(l))return l;let u=G$(n,r,t,a,l.value),d=[];for(let e=0;e<i;e++){let t=e*2*Math.PI/i,a=i1(t,n,r);d.push({rotationDeg:a*180/Math.PI,position:[u*Math.cos(t),u*Math.sin(t),0]})}return O(d)}function o1(e,t,n,r,i){let a=t*e.toothPitch,o=(t+1)%n*e.toothPitch,s=L$(e.alphaPitch),c=a-e.halfToothAngle-s,l=a+e.halfToothAngle+s,u=z$(e.rb,e.alphaTip,c,r,1),d=z$(e.rb,e.alphaTip,l,r,-1).reverse(),f=Fk(u),p=Ik(u),m=Fk(d),h=Ik(d),g=[],_=e=>{i.register(e),g.push(e)},v=e.isInternal?e.rb<e.rRoot:e.rb>e.rRoot;v&&_(zk([e.rRoot*Math.cos(c),e.rRoot*Math.sin(c),0],f));let y=e.rPitch*1e-5,b=Kk(u,{tolerance:y});if(A(b))return b;_(b.value),_(Uk(p,[e.rTip*Math.cos(a),e.rTip*Math.sin(a),0],m));let x=Kk(d,{tolerance:y});if(A(x))return x;_(x.value),v&&_(zk(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),_(Uk(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 s1(e){return l1(e,!1)}function c1(e){return l1(e,!0)}function l1(e,t){try{var n=CT();let{teeth:r,moduleSize:i,pressureAngle:a,shift:o,clearance:s,flankThinning:c,samples:l=B$(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=V$(r,i,a,o,s,c,t),d=n.u(new FT),f=[];for(let e=0;e<r;e++){let t=o1(u,e,r,l,d);if(A(t))return t;f.push(...t.value)}let p=Yk(f);return A(p)?p:O(p.value)}catch(e){n.e=e}finally{n.d()}}function u1(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=I$,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=V$(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=s1({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(f))return f;let p=f1(t,u,a);return _1(f.value,r,c,d,p)}function d1(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=I$,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=c1({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(d))return d;let f=V$(t,n,u,a,o,s,!0),p=g1(f.rPitch+c);return A(p)?p:y1(p.value,d.value,r,f,[])}function f1(e,t,n){let r=X$(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 p1(e){let t=h1(e);if(A(t))return t;let n=t.value,r=m1(n);if(A(r))return r;let{sun:i,planet:a,ring:o}=r.value,s=C1(n,i,a,o),c=x1(a.solid,n);a.solid.delete();let l=S1(o.solid,n.zr),u=w1(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 m1(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=u1({...n,teeth:e.sunTeeth,shift:e.sunShift,bore:e.sunBore});if(A(r))return r;let i=u1({...n,teeth:e.planetTeeth,shift:e.planetShift,bore:e.planetBore});if(A(i))return r.value.solid.delete(),i;let a=d1({...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 h1(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=K$(n,r,i,c);if(A(u))return u;let d=n1(n,r),f=U$(o,s,c,n,r);if(A(f))return f;let p=W$(o,c,l,r,d);if(A(p))return p;let m=G$(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:t1(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 g1(e){try{var t=CT();let n=Yk([t.u(new FT).register(Bk(e,[0,0,0],[0,0,1]))]);return A(n)?n:O(n.value)}catch(e){t.e=e}finally{t.d()}}function _1(e,t,n,r,i){try{var a=CT();let o=Xk(e);if(A(o))return o;let s=Qj(o.value,[0,0,t]);if(A(s))return s;if(n<=0)return O(b1(s.value,r,i));let c=a.u(new FT),l=v1(n/2);if(A(l))return l;c.register(l.value);let u=Qj(l.value,[0,0,t+1]);if(A(u))return u;c.register(u.value);let d=c.register(IO(u.value,[0,0,-.5])),f=aA(s.value,d);return A(f)?f:O(b1(f.value,r,i))}catch(e){a.e=e}finally{a.d()}}function v1(e){let t=g1(e);return A(t)?t:Xk(t.value)}function y1(e,t,n,r,i){let a=Xk(e,[t]);if(A(a))return a;let o=Qj(a.value,[0,0,n]);return A(o)?o:O(b1(o.value,r,i))}function b1(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 x1(e,t){let n=[];try{for(let r=0;r<t.numPlanets;r++){let i=r*2*Math.PI/t.numPlanets,a=LO(e,i1(i,t.sunTeeth,t.planetTeeth)*180/Math.PI);try{let e=[t.centerDistance*Math.cos(i),t.centerDistance*Math.sin(i),0];n.push(IO(a,e))}finally{a.delete()}}return n}catch(e){for(let e of n)e.delete();throw e}}function S1(e,t){let n=r1(t);if(n===0)return e;let r=LO(e,n*180/Math.PI);return e.delete(),r}function C1(e,t,n,r){let i={crSunPlanet:q$(t.tipDiameter/2,t.baseDiameter/2,n.tipDiameter/2,n.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_sp),crPlanetRing:J$(n.tipDiameter/2,n.baseDiameter/2,r.tipDiameter/2,r.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_pr),undercutSun:X$(e.sunTeeth,e.alpha,e.sunShift),undercutPlanet:X$(e.planetTeeth,e.alpha,e.planetShift)};if(e.appliedTorque!==void 0){let t=e.appliedTorque;i.lewisStress={sun:e1(t,e.moduleSize,e.thickness,e.sunTeeth,e.alpha),planet:e1(t*e.planetTeeth/e.sunTeeth,e.moduleSize,e.thickness,e.planetTeeth,e.alpha),ring:e1(t*e.zr/e.sunTeeth,e.moduleSize,e.thickness,e.zr,e.alpha,!0)},i.stressConcentrationFactor={sun:$$(e.sunTeeth,e.alpha),planet:$$(e.planetTeeth,e.alpha),ring:$$(e.zr,e.alpha,!0)}}return i}function w1(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 T1=UJ({addHoles:()=>kM,bezier:()=>gM,box:()=>rM,bsplineApprox:()=>hM,circle:()=>uM,compound:()=>TM,cone:()=>oM,cylinder:()=>iM,ellipse:()=>dM,ellipseArc:()=>mM,ellipsoid:()=>cM,face:()=>bM,fill:()=>Zk,filledFace:()=>xM,helix:()=>fM,line:()=>lM,offsetFace:()=>DM,polygon:()=>CM,polyhedron:()=>nZ,sewShells:()=>OM,solid:()=>EM,sphere:()=>aM,subFace:()=>SM,tangentArc:()=>_M,threePointArc:()=>pM,torus:()=>sM,vertex:()=>wM,wire:()=>vM,wireLoop:()=>yM}),E1=UJ({checkBoolean:()=>oj,convexHull:()=>ZX,cut:()=>FQ,cutAll:()=>lA,cutAllBisect:()=>ZA,fuse:()=>PQ,fuseAll:()=>cA,fuseAllBisect:()=>tj,hull:()=>XX,intersect:()=>RQ,minkowski:()=>tZ,section:()=>zQ,sectionToFace:()=>BQ,slice:()=>HQ,split:()=>VQ}),D1=UJ({chamfer:()=>qQ,draft:()=>ZQ,fillet:()=>KQ,heal:()=>QQ,offset:()=>YQ,shell:()=>JQ,simplify:()=>$Q,thicken:()=>XQ,variableFillet:()=>jj}),O1=UJ({applyMatrix:()=>MQ,clone:()=>jQ,composeTransforms:()=>GO,mirror:()=>kQ,rotate:()=>OQ,scale:()=>AQ,transformCopy:()=>NQ,translate:()=>DQ}),k1=UJ({checkAllInterferences:()=>rQ,checkInterference:()=>nQ,createDistanceQuery:()=>SP,measureArea:()=>vP,measureCurvatureAt:()=>CP,measureCurvatureAtMid:()=>wP,measureDistance:()=>bP,measureDistanceProps:()=>xP,measureLength:()=>yP,measureLinearProps:()=>gP,measureSurfaceProps:()=>hP,measureVolume:()=>_P,measureVolumeProps:()=>mP}),A1=UJ({blueprintToDXF:()=>Eq,exportAssemblySTEP:()=>MM,exportDXF:()=>Tq,exportGlb:()=>fq,exportGltf:()=>dq,exportIGES:()=>Mk,exportOBJ:()=>tq,exportSTEP:()=>Ak,exportSTEPConfigured:()=>lJ,exportSTL:()=>jk,exportThreeMF:()=>Gq,importDXF:()=>cQ,importGLB:()=>TQ,importIGES:()=>fJ,importOBJ:()=>fQ,importSTEP:()=>uJ,importSTL:()=>dJ,importSVG:()=>cJ,importSVGPathD:()=>sJ,importThreeMF:()=>wQ}),j1=UJ({cornerFinder:()=>TI,edgeFinder:()=>YP,faceFinder:()=>QP,getSingleFace:()=>tF,vertexFinder:()=>QJ,wireFinder:()=>eF}),M1=UJ({complexExtrude:()=>Kj,extrude:()=>s$,guidedSweep:()=>Zj,loft:()=>l$,multiSectionSweep:()=>Xj,revolve:()=>c$,roof:()=>TZ,supportExtrude:()=>Gj,surfaceFromGrid:()=>GX,surfaceFromImage:()=>JX,sweep:()=>Wj,twistExtrude:()=>qj}),N1=UJ({circularPattern:()=>PM,linearPattern:()=>NM}),P1=14695981039346656037n,F1=1099511628211n,I1=18446744073709551615n;function L1(){return P1}function R1(e,t){return(e^BigInt(t&255))*F1&I1}function z1(e,t){let n=e;for(let e=0;e<t.length;e++)n=R1(n,t[e]??0);return n}var B1=new TextEncoder;function V1(e,t){return z1(e,B1.encode(t))}var H1=new ArrayBuffer(8),U1=new DataView(H1),W1=new Uint8Array(H1);function G1(e,t){return U1.setFloat64(0,Object.is(t,-0)?0:t),z1(e,W1)}function K1(e,t){let n=e,r=t&I1;for(let e=0;e<8;e++)n=R1(n,Number(r&255n)),r>>=8n;return n}function q1(e,t){let n=e,r=t|0;for(let e=0;e<4;e++)n=R1(n,r&255),r>>>=8;return n}function J1(e,t){return R1(e,+!!t)}function Y1(e){return(e&I1).toString(16).padStart(16,`0`)}var X1=new Set;function Z1(e){return V1(L1(),e)}function Q1(e){return{kind:`NumLit`,value:e,structuralHash:G1(Z1(`NumLit`),e),freeParams:X1}}function $1(e){let t=Z1(`Vec3Lit`);for(let n of e)t=G1(t,n);return{kind:`Vec3Lit`,value:e,structuralHash:t,freeParams:X1}}function e0(e){let t=Z1(`Vec2Lit`);for(let n of e)t=G1(t,n);return{kind:`Vec2Lit`,value:e,structuralHash:t,freeParams:X1}}function t0(e){return{kind:`Param`,name:e,structuralHash:V1(Z1(`Param`),e),freeParams:new Set([e])}}function n0(e,t,n){let r=V1(Z1(`BinOp`),e);return r=K1(r,t.structuralHash),r=K1(r,n.structuralHash),{kind:`BinOp`,op:e,a:t,b:n,structuralHash:r,freeParams:f0(t.freeParams,n.freeParams)}}function r0(e,t){let n=V1(Z1(`UnaryOp`),e);return n=K1(n,t.structuralHash),{kind:`UnaryOp`,op:e,arg:t,structuralHash:n,freeParams:t.freeParams}}function i0(e,t){let n=q1(Z1(`Component`),t);return n=K1(n,e.structuralHash),{kind:`Component`,vec:e,index:t,structuralHash:n,freeParams:e.freeParams}}function a0(e,t){let n=q1(Z1(`BuildVec`),e),r=new Set;for(let e of t){n=K1(n,e.structuralHash);for(let t of e.freeParams)r.add(t)}return{kind:`BuildVec`,dim:e,components:t,structuralHash:n,freeParams:r}}var o0=(e,t)=>n0(`+`,e,t),s0=(e,t)=>n0(`*`,e,t);function c0(e){return typeof e==`number`?Q1(e):e}function l0(e,t){if(!Array.isArray(e))return e;let n=e;return n.every(e=>typeof e==`number`)?t===3?$1([n[0],n[1],n[2]]):e0([n[0],n[1]]):a0(t,n.map(c0))}function u0(e){return l0(e,3)}function d0(e){return l0(e,2)}function f0(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 p0(e){return typeof e==`number`}function m0(e,t){return p0(e)?O(e):k(F(N.NULL_SHAPE_INPUT,`${t}: expected number, got ${Array.isArray(e)?`vector(${e.length})`:typeof e}`))}function h0(e,t,n){return Array.isArray(e)&&e.length===t?O(e):k(F(N.NULL_SHAPE_INPUT,`${n}: expected Vec${t}, got ${p0(e)?`number`:`vector(${e.length})`}`))}function g0(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 _0(e,t);case`UnaryOp`:return v0(e,t);case`Component`:return y0(e,t);case`BuildVec`:return b0(e,t)}}function _0(e,t){let n=g0(e.a,t);if(!n.ok)return n;let r=g0(e.b,t);if(!r.ok)return r;let i=m0(n.value,`BinOp(${e.op}).a`);if(!i.ok)return i;let a=m0(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 v0(e,t){let n=g0(e.arg,t);if(!n.ok)return n;let r=m0(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 y0(e,t){let n=g0(e.vec,t);if(!n.ok)return n;if(p0(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 b0(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=g0(r,t);if(!e.ok)return e;let i=m0(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 x0(e,t,n){let r=g0(e,t);return r.ok?m0(r.value,n):r}function S0(e,t,n){let r=g0(e,t);if(!r.ok)return r;let i=h0(r.value,3,n);if(!i.ok)return i;let[a,o,s]=i.value;return O([a,o,s])}function C0(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 w0=new Set;function T0(e){return V1(L1(),e)}function E0(e,t){return K1(e,t.structuralHash)}function D0(e,t){return t===void 0?J1(e,!1):E0(J1(e,!0),t)}function O0(e,t){return t===void 0?J1(e,!1):G1(J1(e,!0),t)}function k0(...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?w0:t}function A0(e,t,n){let r=c0(e),i=c0(t),a=c0(n),o=T0(`Box`);return o=E0(E0(E0(o,r),i),a),{kind:`Box`,x:r,y:i,z:a,structuralHash:o,freeParams:k0(r,i,a)}}function j0(e){let t=c0(e);return{kind:`Sphere`,radius:t,structuralHash:E0(T0(`Sphere`),t),freeParams:t.freeParams}}function M0(e,t){let n=c0(e),r=c0(t);return{kind:`Cylinder`,radius:n,height:r,structuralHash:E0(E0(T0(`Cylinder`),n),r),freeParams:k0(n,r)}}function N0(e,t,n){let r=c0(e),i=c0(t),a=c0(n),o=T0(`Cone`);return o=E0(E0(E0(o,r),i),a),{kind:`Cone`,radius1:r,radius2:i,height:a,structuralHash:o,freeParams:k0(r,i,a)}}function P0(e,t){let n=c0(e),r=c0(t);return{kind:`Torus`,majorRadius:n,minorRadius:r,structuralHash:E0(E0(T0(`Torus`),n),r),freeParams:k0(n,r)}}function F0(e){let t=e.map(u0),n=q1(T0(`Polygon`),t.length);for(let e of t)n=E0(n,e);return{kind:`Polygon`,points:t,structuralHash:n,freeParams:k0(...t)}}function I0(e){let t=c0(e);return{kind:`Circle`,radius:t,structuralHash:E0(T0(`Circle`),t),freeParams:t.freeParams}}function L0(e,t){let n=u0(e),r=u0(t);return{kind:`Line`,from:n,to:r,structuralHash:E0(E0(T0(`Line`),n),r),freeParams:k0(n,r)}}function R0(e){let t=u0(e);return{kind:`Vertex`,point:t,structuralHash:E0(T0(`Vertex`),t),freeParams:t.freeParams}}function z0(e){return{kind:`Empty`,output:e,structuralHash:V1(T0(`Empty`),e),freeParams:w0}}function B0(){return z0(`Solid`)}function V0(){return z0(`Face`)}function H0(){return z0(`Wire`)}function U0(e,t,n,r){return O0(E0(E0(T0(e),t),n),r)}function W0(e,t,n){return{kind:`Fuse`,a:e,b:t,tolerance:n,structuralHash:U0(`Fuse`,e,t,n),freeParams:k0(e,t)}}function G0(e,t,n){return{kind:`Cut`,a:e,b:t,tolerance:n,structuralHash:U0(`Cut`,e,t,n),freeParams:k0(e,t)}}function K0(e,t,n){return{kind:`Intersect`,a:e,b:t,tolerance:n,structuralHash:U0(`Intersect`,e,t,n),freeParams:k0(e,t)}}function q0(e,t){let n=q1(T0(`FuseAll`),e.length);for(let t of e)n=E0(n,t);return n=O0(n,t),{kind:`FuseAll`,shapes:e,tolerance:t,structuralHash:n,freeParams:k0(...e)}}function J0(e,t,n){let r=E0(T0(`CutAll`),e);r=q1(r,t.length);for(let e of t)r=E0(r,e);return r=O0(r,n),{kind:`CutAll`,base:e,tools:t,tolerance:n,structuralHash:r,freeParams:k0(e,...t)}}function Y0(e){return e===void 0?void 0:u0(e)}function X0(e,t){let n=u0(t);return{kind:`Translate`,target:e,vector:n,structuralHash:E0(E0(T0(`Translate`),e),n),freeParams:k0(e,n)}}function Z0(e,t,n){let r=c0(t),i=Y0(n?.axis),a=Y0(n?.at),o=E0(E0(T0(`Rotate`),e),r);return o=D0(o,i),o=D0(o,a),{kind:`Rotate`,target:e,angle:r,axis:i,at:a,structuralHash:o,freeParams:k0(e,r,i,a)}}function Q0(e,t,n){let r=c0(t),i=Y0(n?.center),a=E0(E0(T0(`Scale`),e),r);return a=D0(a,i),{kind:`Scale`,target:e,factor:r,center:i,structuralHash:a,freeParams:k0(e,r,i)}}function $0(e,t){let n=Y0(t?.normal),r=Y0(t?.at),i=E0(T0(`Mirror`),e);return i=D0(i,n),i=D0(i,r),{kind:`Mirror`,target:e,normal:n,at:r,structuralHash:i,freeParams:k0(e,n,r)}}function e2(e){let t=q1(T0(`Compound`),e.length);for(let n of e)t=E0(t,n);return{kind:`Compound`,children:e,structuralHash:t,freeParams:k0(...e)}}function t2(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 t2(e.a);case`FuseAll`:return e.shapes[0]?t2(e.shapes[0]):`Solid`;case`CutAll`:return t2(e.base);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return t2(e.target);case`Compound`:return`Compound`}}function n2(e,t){let n=x0(e.x,t.env,`Box.x`);if(!n.ok)return n;let r=x0(e.y,t.env,`Box.y`);if(!r.ok)return r;let i=x0(e.z,t.env,`Box.z`);return i.ok?O(rM(n.value,r.value,i.value)):i}function r2(e,t){let n=x0(e.radius,t.env,`Sphere.radius`);return n.ok?O(aM(n.value)):n}function i2(e,t){let n=x0(e.radius,t.env,`Cylinder.radius`);if(!n.ok)return n;let r=x0(e.height,t.env,`Cylinder.height`);return r.ok?O(iM(n.value,r.value)):r}function a2(e,t){let n=x0(e.radius1,t.env,`Cone.radius1`);if(!n.ok)return n;let r=x0(e.radius2,t.env,`Cone.radius2`);if(!r.ok)return r;let i=x0(e.height,t.env,`Cone.height`);return i.ok?O(oM(n.value,r.value,i.value)):i}function o2(e,t){let n=x0(e.majorRadius,t.env,`Torus.majorRadius`);if(!n.ok)return n;let r=x0(e.minorRadius,t.env,`Torus.minorRadius`);return r.ok?O(sM(n.value,r.value)):r}function s2(e,t){let n=[];for(let r of e.points){let e=S0(r,t.env,`Polygon.point`);if(!e.ok)return e;n.push(e.value)}return CM(n)}function c2(e,t){let n=x0(e.radius,t.env,`Circle.radius`);return n.ok?O(uM(n.value)):n}function l2(e,t){let n=S0(e.from,t.env,`Line.from`);if(!n.ok)return n;let r=S0(e.to,t.env,`Line.to`);return r.ok?O(lM(n.value,r.value)):r}function u2(e,t){let n=S0(e.point,t.env,`Vertex.point`);return n.ok?O(wM(n.value)):n}function d2(e){return k(I(N.NULL_SHAPE_INPUT,`${e}: empty result has no kernel representation`))}function f2(e,t,n){let r=e.evalNode(t);return r.ok?wE(r.value)?O(r.value):k(co(N.CSG_NOT_3D,`${n}: operand did not produce a 3D shape`)):r}function p2(e,t){return{unsafe:!0,fuzzyValue:e.tolerance??t.tolerance}}function m2(e,t){if(e.a.kind===`Empty`)return t.evalNode(e.b);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=f2(t,e.a,`Fuse.a`);if(!n.ok)return n;let r=f2(t,e.b,`Fuse.b`);return r.ok?iA(n.value,r.value,p2(e,t)):r}function h2(e,t){if(e.a.kind===`Empty`)return d2(`Cut`);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=f2(t,e.a,`Cut.a`);if(!n.ok)return n;let r=f2(t,e.b,`Cut.b`);return r.ok?aA(n.value,r.value,p2(e,t)):r}function g2(e,t){if(e.a.kind===`Empty`||e.b.kind===`Empty`)return d2(`Intersect`);let n=f2(t,e.a,`Intersect.a`);if(!n.ok)return n;let r=f2(t,e.b,`Intersect.b`);return r.ok?oA(n.value,r.value,p2(e,t)):r}function _2(e,t,n){let r=[];for(let i of t){let t=f2(e,i,n);if(!t.ok)return t;r.push(t.value)}return O(r)}function v2(e,t){let n=e.shapes.filter(e=>e.kind!==`Empty`);if(n.length===0)return d2(`FuseAll`);if(n.length===1&&n[0])return t.evalNode(n[0]);let r=_2(t,n,`FuseAll.operand`);return r.ok?cA(r.value,p2(e,t)):r}function y2(e,t){if(e.base.kind===`Empty`)return d2(`CutAll`);let n=e.tools.filter(e=>e.kind!==`Empty`);if(n.length===0)return t.evalNode(e.base);let r=f2(t,e.base,`CutAll.base`);if(!r.ok)return r;let i=_2(t,n,`CutAll.tool`);return i.ok?lA(r.value,i.value,p2(e,t)):i}function b2(e){return k(I(N.NULL_SHAPE_INPUT,`${e}: cannot transform an Empty node`))}function x2(e,t,n,r){return e?S0(e,t,n):O(r)}function S2(e,t){if(e.target.kind===`Empty`)return b2(`Translate`);let n=S0(e.vector,t.env,`Translate.vector`);if(!n.ok)return n;let r=t.evalNode(e.target);return r.ok?O(IO(r.value,n.value)):r}function C2(e,t){if(e.target.kind===`Empty`)return b2(`Rotate`);let n=x0(e.angle,t.env,`Rotate.angle`);if(!n.ok)return n;let r=x2(e.axis,t.env,`Rotate.axis`,[0,0,1]);if(!r.ok)return r;let i=x2(e.at,t.env,`Rotate.at`,[0,0,0]);if(!i.ok)return i;let a=t.evalNode(e.target);return a.ok?O(LO(a.value,n.value,i.value,r.value)):a}function w2(e,t){if(e.target.kind===`Empty`)return b2(`Scale`);let n=x0(e.factor,t.env,`Scale.factor`);if(!n.ok)return n;let r=x2(e.center,t.env,`Scale.center`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(zO(i.value,n.value,r.value)):i}function T2(e,t){if(e.target.kind===`Empty`)return b2(`Mirror`);let n=x2(e.normal,t.env,`Mirror.normal`,[1,0,0]);if(!n.ok)return n;let r=x2(e.at,t.env,`Mirror.at`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(RO(i.value,n.value,r.value)):i}function E2(e,t){let n=e.children.filter(e=>e.kind!==`Empty`);if(n.length===0)return k(I(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(TM(r))}function D2(){return k(I(N.NULL_SHAPE_INPUT,`Empty: cannot materialize an Empty node directly — only valid as boolean/transform operand`))}function O2(e,t){switch(e.kind){case`Box`:return n2(e,t);case`Sphere`:return r2(e,t);case`Cylinder`:return i2(e,t);case`Cone`:return a2(e,t);case`Torus`:return o2(e,t);case`Polygon`:return s2(e,t);case`Circle`:return c2(e,t);case`Line`:return l2(e,t);case`Vertex`:return u2(e,t);case`Empty`:return D2();case`Fuse`:return m2(e,t);case`Cut`:return h2(e,t);case`Intersect`:return g2(e,t);case`FuseAll`:return v2(e,t);case`CutAll`:return y2(e,t);case`Translate`:return S2(e,t);case`Rotate`:return C2(e,t);case`Scale`:return w2(e,t);case`Mirror`:return T2(e,t);case`Compound`:return E2(e,t)}}function k2(e,t){if(typeof t==`number`)return G1(J1(e,!1),t);let n=J1(e,!0);n=q1(n,t.length);for(let e of t)n=G1(n,e);return n}function A2(e,t){if(t.size===0)return L1();let n=C0(e,t),r=Object.keys(n).sort(),i=L1();for(let e of r){i=V1(i,e);let t=n[e];t!==void 0&&(i=k2(i,t))}return i}function j2(e,t,n,r){let i=A2(t,e.freeParams),a=r===void 0?`d`:G1(L1(),r).toString(16);return`${Y1(e.structuralHash)}:${n}:${Y1(i)}:${a}`}var M2=class{scope=new FT;cache=new Map;registered=new WeakSet;kernelId;defaultTolerance;onStep;hits=0;misses=0;constructor(e={}){this.kernelId=e.kernel??fT()??`unregistered`,this.defaultTolerance=e.tolerance,e.onStep&&(this.onStep=e.onStep)}evaluate(e,t={}){return pT(this.kernelId,()=>this.evaluateInner(e,t))}evaluateInner(e,t){let n=j2(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=O2(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 N2(e,t){try{var n=CT();let r=t(n.u(new M2(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 P2(e){return{csgVersion:1,root:B2(e)}}function F2(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:F2(e.a),b:F2(e.b)};case`UnaryOp`:return{kind:`UnaryOp`,op:e.op,arg:F2(e.arg)};case`Component`:return{kind:`Component`,vec:F2(e.vec),index:e.index};case`BuildVec`:return{kind:`BuildVec`,dim:e.dim,components:e.components.map(F2)}}}function I2(e){switch(e.kind){case`Box`:return{kind:`Box`,x:F2(e.x),y:F2(e.y),z:F2(e.z)};case`Sphere`:return{kind:`Sphere`,radius:F2(e.radius)};case`Cylinder`:return{kind:`Cylinder`,radius:F2(e.radius),height:F2(e.height)};case`Cone`:return{kind:`Cone`,radius1:F2(e.radius1),radius2:F2(e.radius2),height:F2(e.height)};case`Torus`:return{kind:`Torus`,majorRadius:F2(e.majorRadius),minorRadius:F2(e.minorRadius)};case`Polygon`:return{kind:`Polygon`,points:e.points.map(F2)};case`Circle`:return{kind:`Circle`,radius:F2(e.radius)};case`Line`:return{kind:`Line`,from:F2(e.from),to:F2(e.to)};case`Vertex`:return{kind:`Vertex`,point:F2(e.point)};case`Empty`:return{kind:`Empty`,output:e.output};default:return}}function L2(e){switch(e.kind){case`Fuse`:case`Cut`:case`Intersect`:return{kind:e.kind,a:B2(e.a),b:B2(e.b),tolerance:e.tolerance};case`FuseAll`:return{kind:`FuseAll`,shapes:e.shapes.map(B2),tolerance:e.tolerance};case`CutAll`:return{kind:`CutAll`,base:B2(e.base),tools:e.tools.map(B2),tolerance:e.tolerance};default:return}}function R2(e){return e?F2(e):void 0}function z2(e){switch(e.kind){case`Translate`:return{kind:`Translate`,target:B2(e.target),vector:F2(e.vector)};case`Rotate`:return{kind:`Rotate`,target:B2(e.target),angle:F2(e.angle),axis:R2(e.axis),at:R2(e.at)};case`Scale`:return{kind:`Scale`,target:B2(e.target),factor:F2(e.factor),center:R2(e.center)};case`Mirror`:return{kind:`Mirror`,target:B2(e.target),normal:R2(e.normal),at:R2(e.at)};default:return}}function B2(e){return e.kind===`Compound`?{kind:`Compound`,children:e.children.map(B2)}:I2(e)??L2(e)??z2(e)}function V2(e){return k(F(N.NULL_SHAPE_INPUT,`csg.fromJSON: ${e}`))}function H2(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function U2(e){return typeof e==`number`&&Number.isFinite(e)}function W2(e){return typeof e==`string`}function G2(e,t){if(!Array.isArray(e)||e.length!==3)return V2(`${t}: expected Vec3 array`);let[n,r,i]=e;return!U2(n)||!U2(r)||!U2(i)?V2(`${t}: Vec3 contains non-number`):O([n,r,i])}function K2(e,t){if(!Array.isArray(e)||e.length!==2)return V2(`${t}: expected Vec2 array`);let[n,r]=e;return!U2(n)||!U2(r)?V2(`${t}: Vec2 contains non-number`):O([n,r])}function q2(e){if(!H2(e))return V2(`input is not an object`);let t=e.csgVersion;if(t!==1)return V2(`unsupported csgVersion ${String(t)} (expected 1)`);let n=e.root;return t4(n)}function J2(e){if(!H2(e))return V2(`expression: not an object`);let t=e.kind;switch(t){case`NumLit`:return U2(e.value)?O(Q1(e.value)):V2(`NumLit.value`);case`Vec3Lit`:{let t=G2(e.value,`Vec3Lit.value`);return t.ok?O($1(t.value)):t}case`Vec2Lit`:{let t=K2(e.value,`Vec2Lit.value`);return t.ok?O(e0(t.value)):t}case`Param`:return W2(e.name)?O(t0(e.name)):V2(`Param.name`);case`BinOp`:return Y2(e);case`UnaryOp`:return X2(e);case`Component`:return Z2(e);case`BuildVec`:return Q2(e);default:return V2(`unknown expression kind: ${String(t)}`)}}function Y2(e){let t=e.op;if(t!==`+`&&t!==`-`&&t!==`*`&&t!==`/`)return V2(`BinOp.op: ${String(t)}`);let n=J2(e.a);if(!n.ok)return n;let r=J2(e.b);return r.ok?O(n0(t,n.value,r.value)):r}function X2(e){let t=e.op;if(!W2(t)||![`neg`,`sin`,`cos`,`sqrt`,`abs`].includes(t))return V2(`UnaryOp.op: ${String(t)}`);let n=J2(e.arg);return n.ok?O(r0(t,n.value)):n}function Z2(e){let t=e.index;if(t!==0&&t!==1&&t!==2)return V2(`Component.index: ${String(t)}`);let n=J2(e.vec);return n.ok?O(i0(n.value,t)):n}function Q2(e){let t=e.dim;if(t!==2&&t!==3)return V2(`BuildVec.dim: ${String(t)}`);let n=e.components;if(!Array.isArray(n))return V2(`BuildVec.components: not array`);if(n.length!==t)return V2(`BuildVec.components: expected ${t} components, got ${n.length}`);let r=[];for(let e of n){let t=J2(e);if(!t.ok)return t;r.push(t.value)}return O(a0(t,r))}function $2(e,t){if(!Array.isArray(e))return V2(`${t}: not array`);let n=[];for(let t of e){let e=t4(t);if(!e.ok)return e;n.push(e.value)}return O(n)}function e4(e){let t=e.tolerance;return t==null?O(void 0):U2(t)?O(t):V2(`tolerance: not a finite number`)}function t4(e){if(!H2(e))return V2(`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 r4(t,e);case`Fuse`:case`Cut`:case`Intersect`:return d4(t,e);case`FuseAll`:case`CutAll`:return f4(t,e);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return p4(t,e);case`Compound`:return y4(e);default:return V2(`unknown node kind: ${String(t)}`)}}function n4(e,t,n){let r=J2(e[t]);return r.ok?O(n(r.value)):r}function r4(e,t){switch(e){case`Box`:return i4(t);case`Sphere`:return n4(t,`radius`,j0);case`Cylinder`:return a4(t);case`Cone`:return o4(t);case`Torus`:return s4(t);case`Polygon`:return c4(t);case`Circle`:return n4(t,`radius`,I0);case`Line`:return l4(t);case`Vertex`:return n4(t,`point`,R0);case`Empty`:return u4(t)}return V2(`unhandled primitive: ${e}`)}function i4(e){let t=J2(e.x);if(!t.ok)return t;let n=J2(e.y);if(!n.ok)return n;let r=J2(e.z);return r.ok?O(A0(t.value,n.value,r.value)):r}function a4(e){let t=J2(e.radius);if(!t.ok)return t;let n=J2(e.height);return n.ok?O(M0(t.value,n.value)):n}function o4(e){let t=J2(e.radius1);if(!t.ok)return t;let n=J2(e.radius2);if(!n.ok)return n;let r=J2(e.height);return r.ok?O(N0(t.value,n.value,r.value)):r}function s4(e){let t=J2(e.majorRadius);if(!t.ok)return t;let n=J2(e.minorRadius);return n.ok?O(P0(t.value,n.value)):n}function c4(e){let t=e.points;if(!Array.isArray(t))return V2(`Polygon.points: not array`);let n=[];for(let e of t){let t=J2(e);if(!t.ok)return t;n.push(t.value)}return O(F0(n))}function l4(e){let t=J2(e.from);if(!t.ok)return t;let n=J2(e.to);return n.ok?O(L0(t.value,n.value)):n}function u4(e){let t=e.output;switch(t){case`Solid`:return O(B0());case`Face`:return O(V0());case`Wire`:return O(H0());default:return V2(`Empty.output: ${String(t)}`)}}function d4(e,t){let n=t4(t.a);if(!n.ok)return n;let r=t4(t.b);if(!r.ok)return r;let i=e4(t);if(!i.ok)return i;switch(e){case`Fuse`:return O(W0(n.value,r.value,i.value));case`Cut`:return O(G0(n.value,r.value,i.value));case`Intersect`:return O(K0(n.value,r.value,i.value))}}function f4(e,t){let n=e4(t);if(!n.ok)return n;if(e===`FuseAll`){let e=$2(t.shapes,`FuseAll.shapes`);return e.ok?O(q0(e.value,n.value)):e}let r=t4(t.base);if(!r.ok)return r;let i=$2(t.tools,`CutAll.tools`);return i.ok?O(J0(r.value,i.value,n.value)):i}function p4(e,t){let n=t4(t.target);if(!n.ok)return n;switch(e){case`Translate`:return m4(t,n.value);case`Rotate`:return g4(t,n.value);case`Scale`:return _4(t,n.value);case`Mirror`:return v4(t,n.value)}}function m4(e,t){let n=J2(e.vector);return n.ok?O(X0(t,n.value)):n}function h4(e,t){if(e[t]===void 0)return O(void 0);let n=J2(e[t]);return n.ok?O(n.value):n}function g4(e,t){let n=J2(e.angle);if(!n.ok)return n;let r=h4(e,`axis`);if(!r.ok)return r;let i=h4(e,`at`);return i.ok?O(Z0(t,n.value,{axis:r.value,at:i.value})):i}function _4(e,t){let n=J2(e.factor);if(!n.ok)return n;let r=h4(e,`center`);return r.ok?O(Q0(t,n.value,{center:r.value})):r}function v4(e,t){let n=h4(e,`normal`);if(!n.ok)return n;let r=h4(e,`at`);return r.ok?O($0(t,{normal:n.value,at:r.value})):r}function y4(e){let t=$2(e.children,`Compound.children`);return t.ok?O(e2(t.value)):t}function b4(e){return C4(e)}function x4(e){switch(e.kind){case`NumLit`:case`Vec3Lit`:case`Vec2Lit`:case`Param`:return e;case`BinOp`:{let t=x4(e.a),n=x4(e.b);if(t.kind===`NumLit`&&n.kind===`NumLit`)switch(e.op){case`+`:return Q1(t.value+n.value);case`-`:return Q1(t.value-n.value);case`*`:return Q1(t.value*n.value);case`/`:return Q1(t.value/n.value)}return t!==e.a||n!==e.b?n0(e.op,t,n):e}case`UnaryOp`:{let t=x4(e.arg);if(t.kind===`NumLit`){let n=t.value;switch(e.op){case`neg`:return Q1(-n);case`sin`:return Q1(Math.sin(n));case`cos`:return Q1(Math.cos(n));case`sqrt`:return Q1(Math.sqrt(n));case`abs`:return Q1(Math.abs(n))}}return t===e.arg?e:r0(e.op,t)}case`Component`:{let t=x4(e.vec);return t.kind===`Vec3Lit`||t.kind===`Vec2Lit`&&(e.index===0||e.index===1)?Q1(t.value[e.index]):t===e.vec?e:i0(t,e.index)}case`BuildVec`:{let t=e.components.map(x4);return S4(e.dim,t)||(t.some((t,n)=>t!==e.components[n])?a0(e.dim,t):e)}}}function S4(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?e0([n[0],n[1]]):$1([n[0],n[1],n[2]])}function C4(e){switch(e.kind){case`Box`:return A0(x4(e.x),x4(e.y),x4(e.z));case`Sphere`:return j0(x4(e.radius));case`Cylinder`:return M0(x4(e.radius),x4(e.height));case`Cone`:return N0(x4(e.radius1),x4(e.radius2),x4(e.height));case`Torus`:return P0(x4(e.majorRadius),x4(e.minorRadius));case`Polygon`:return F0(e.points.map(x4));case`Circle`:return I0(x4(e.radius));case`Line`:return L0(x4(e.from),x4(e.to));case`Vertex`:return R0(x4(e.point));case`Empty`:return e;case`Fuse`:return w4(e.a,e.b,e.tolerance);case`Cut`:return T4(e.a,e.b,e.tolerance);case`Intersect`:return E4(e.a,e.b,e.tolerance);case`FuseAll`:return D4(e.shapes,e.tolerance);case`CutAll`:return O4(e.base,e.tools,e.tolerance);case`Translate`:return k4(e.target,e.vector);case`Rotate`:return Z0(C4(e.target),x4(e.angle),{axis:e.axis?x4(e.axis):void 0,at:e.at?x4(e.at):void 0});case`Scale`:return Q0(C4(e.target),x4(e.factor),{center:e.center?x4(e.center):void 0});case`Mirror`:return $0(C4(e.target),{normal:e.normal?x4(e.normal):void 0,at:e.at?x4(e.at):void 0});case`Compound`:return e2(e.children.map(C4).filter(e=>e.kind!==`Empty`))}}function w4(e,t,n){let r=C4(e),i=C4(t);return r.kind===`Empty`?i:i.kind===`Empty`?r:W0(r,i,n)}function T4(e,t,n){let r=C4(e),i=C4(t);return i.kind===`Empty`||r.kind===`Empty`?r:G0(r,i,n)}function E4(e,t,n){let r=C4(e),i=C4(t);return r.kind===`Empty`?r:i.kind===`Empty`?i:K0(r,i,n)}function D4(e,t){let n=e.map(C4).filter(e=>e.kind!==`Empty`);return n.length===0?B0():n.length===1?n[0]:q0(n,t)}function O4(e,t,n){let r=C4(e);if(r.kind===`Empty`)return r;let i=t.map(C4).filter(e=>e.kind!==`Empty`);return i.length===0?r:J0(r,i,n)}function k4(e,t){let n=C4(e),r=x4(t);if(r.kind!==`Vec3Lit`)return X0(n,r);let[i,a,o]=r.value;if(i===0&&a===0&&o===0)return n;if(n.kind===`Translate`){let e=x4(n.vector);if(e.kind===`Vec3Lit`)return X0(n.target,[e.value[0]+i,e.value[1]+a,e.value[2]+o])}return X0(n,r)}function A4(e,t,n){return j4(e,t,n)}function j4(e,t,n){return t(e)?n:M4(e,t,n)}function M4(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 W0(j4(e.a,t,n),j4(e.b,t,n),e.tolerance);case`Cut`:return G0(j4(e.a,t,n),j4(e.b,t,n),e.tolerance);case`Intersect`:return K0(j4(e.a,t,n),j4(e.b,t,n),e.tolerance);case`FuseAll`:return q0(e.shapes.map(e=>j4(e,t,n)),e.tolerance);case`CutAll`:return J0(j4(e.base,t,n),e.tools.map(e=>j4(e,t,n)),e.tolerance);case`Translate`:return X0(j4(e.target,t,n),e.vector);case`Rotate`:return Z0(j4(e.target,t,n),e.angle,{axis:e.axis,at:e.at});case`Scale`:return Q0(j4(e.target,t,n),e.factor,{center:e.center});case`Mirror`:return $0(j4(e.target,t,n),{normal:e.normal,at:e.at});case`Compound`:return e2(e.children.map(e=>j4(e,t,n)))}}function N4(e,t){t(e);for(let n of P4(e))N4(n,t)}function P4(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 F4(e){let t=0;return N4(e,()=>{t++}),t}var I4=UJ({CSG_VERSION:()=>1,Evaluator:()=>M2,add:()=>o0,asScalarExpr:()=>c0,asVec2Expr:()=>d0,asVec3Expr:()=>u0,binOp:()=>n0,box:()=>A0,buildVec:()=>a0,circle:()=>I0,component:()=>i0,compound:()=>e2,cone:()=>N0,cut:()=>G0,cutAll:()=>J0,cylinder:()=>M0,emptyFace:()=>V0,emptySolid:()=>B0,emptyWire:()=>H0,foldExpr:()=>x4,forEachNode:()=>N4,fromJSON:()=>q2,fuse:()=>W0,fuseAll:()=>q0,intersect:()=>K0,line:()=>L0,mirror:()=>$0,mul:()=>s0,nodeCount:()=>F4,numLit:()=>Q1,optimize:()=>b4,outputKindOf:()=>t2,param:()=>t0,polygon:()=>F0,replaceNode:()=>A4,rotate:()=>Z0,scale:()=>Q0,sphere:()=>j0,toJSON:()=>P2,torus:()=>P0,translate:()=>X0,unaryOp:()=>r0,vec2Lit:()=>e0,vec3Lit:()=>$1,vertex:()=>R0,withEvaluator:()=>N2});export{yI as BaseSketcher2d,bI as BlueprintSketcher,no as BrepBugError,N as BrepErrorCode,_$ as BrepWrapperError,Ty as BrepkitAdapter,YW as CompoundSketch,i as DEFAULT_CAPABILITIES,iD as DEG2RAD,FT as DisposalScope,r as EXACT_BREP_CAPABILITIES,OG as FaceSketcher,G as HASH_CODE_MAX,Ma as OK,ja as OcctWasmAdapter,aD as RAD2DEG,dG as Sketch,DG as Sketcher,fG as Sketches,IM as addChild,kM as addHoles,pN as addJoint,eQ as addMate,JN as addStep,GA as adjacentFaces,Va as all,Ia as andThen,KJ as applyGlue,MQ as applyMatrix,pk as approximateCurve,GT as as2D,WT as as3D,ID as asTopo,bJ as assignRoles,Lj as autoHeal,gM as bezier,Eq as blueprintToDXF,bA as booleanPipeline,E1 as booleans,m$ as boss,rM as box,hM as bsplineApprox,M as bug,wG as cameraFromPlane,CG as cameraLookAt,_J as captureHint,VD as cast,W as castShape,EE as castShape3D,qQ as chamfer,LA as chamferDistAngleShape,hj as chamferWithEvolution,rQ as checkAllInterferences,oj as checkBoolean,nQ as checkInterference,uM as circle,PM as circularPattern,nO as classifyPointOnFace,Ck as clearMeshCache,jQ as clone,eE as closedWire,Qa as collect,HM as collectShapes,kO as colorFaces,OO as colorShape,Kj as complexExtrude,GO as composeTransforms,TM as compound,cG as compoundSketchExtrude,oG as compoundSketchFace,uG as compoundSketchLoft,lG as compoundSketchRevolve,I as computationError,_Z as computeStraightSkeleton,oM as cone,M1 as construction,ZX as convexHull,TI as cornerFinder,VM as countNodes,jM as createAssembly,FM as createAssemblyNode,BK as createBlueprint,SG as createCamera,gE as createCompound,VK as createCompoundBlueprint,SP as createDistanceQuery,uE as createEdge,fE as createFace,NT as createHandle,qN as createHistory,PT as createKernelHandle,wk as createMeshCache,kD as createNamedPlane,zJ as createOperationRegistry,DD as createPlane,xJ as createRef,tP as createRegistry,pE as createShell,mE as createSolid,jJ as createTaskQueue,lE as createVertex,dE as createWire,RJ as createWorkerClient,VJ as createWorkerHandler,I4 as csg,vo as currentQuality,MK as curve2dBoundingBox,zK as curve2dDistanceFrom,NK as curve2dFirstPoint,RK as curve2dIsOnCurve,PK as curve2dLastPoint,IK as curve2dParameter,FK as curve2dSplitAt,LK as curve2dTangentAt,ok as curveAxis,nk as curveEndPoint,sk as curveIsClosed,ck as curveIsPeriodic,ak as curveLength,lk as curvePeriod,rk as curvePointAt,tk as curveStartPoint,ik as curveTangentAt,FQ as cut,dL as cut2D,LQ as cutAll,ZA as cutAllBisect,eL as cutBlueprints,fj as cutWithEvolution,iM as cylinder,oN as cylindricalJoint,gJ as defaultScorer,NJ as dequeueTask,n$ as describe,aK as deserializeDrawing,sP as deserializeHistory,UD as deserializeShape,BD as downcast,ZQ as draft,sK as draw,fK as drawCircle,pK as drawEllipse,bK as drawFaceOutline,_K as drawParametricFunction,gK as drawPointsInterpolation,mK as drawPolysides,yK as drawProjection,lK as drawRectangle,cK as drawRoundedRectangle,uK as drawSingleCircle,dK as drawSingleEllipse,hK as drawText,EK as drawingChamfer,CK as drawingCut,TK as drawingFillet,SK as drawingFuse,wK as drawingIntersect,xK as drawingToSketchOnPlane,f$ as drill,YP as edgeFinder,HA as edgesOfFace,dM as ellipse,mM as ellipseArc,cM as ellipsoid,MJ as enqueueTask,k as err,MM as exportAssemblySTEP,Tq as exportDXF,fq as exportGlb,dq as exportGltf,Mk as exportIGES,tq as exportOBJ,Ak as exportSTEP,lJ as exportSTEPConfigured,jk as exportSTL,Gq as exportThreeMF,HN as exportURDF,s$ as extrude,eM as extrudeAll,bM as face,tO as faceAxis,eO as faceCenter,QP as faceFinder,KD as faceGeomType,qD as faceOrientation,VA as facesOfEdge,zY as fieldBoolean,UY as fieldContour,BY as fieldOffset,HY as fieldReinit,VY as fieldShell,Zk as fill,xM as filledFace,KQ as fillet,mj as filletWithEvolution,_O as findFacesByTag,zM as findNode,XN as findStep,Bj as fixSelfIntersection,Rj as fixShape,La as flatMap,Wa as flatten,JD as flipFaceOrientation,dk as flipOrientation,hJ as fontMetrics,_N as forwardKinematics,i$ as fromBREP,RX as fromKernelDir,LX as fromKernelPnt,IX as fromKernelVec,Ka as fromNullable,PQ as fuse,lL as fuse2D,IQ as fuseAll,tj as fuseAllBisect,$I as fuseBlueprints,dj as fuseWithEvolution,V$ as gearGeometry,iY as getActiveVoxelId,QE as getBounds,HK as getBounds2D,WE as getCompSolids,ek as getCurveType,DT as getDisposalStats,RE as getEdges,jO as getFaceColor,sO as getFaceOrigins,vO as getFaceTags,zE as getFaces,hG as getFont,YO as getHashCode,ZN as getHistoryShape,U as getKernel,mT as getKernelCapabilities,vT as getKernelTier,qA as getNurbsCurveData,JA as getNurbsSurfaceData,uk as getOrientation,UK as getOrientation2D,Do as getPerformanceStats,AO as getShapeColor,YT as getShapeKind,UE as getShells,tF as getSingleFace,HE as getSolids,GD as getSurfaceType,bO as getTagMetadata,VE as getVertices,rY as getVoxel,BE as getWires,Zj as guidedSweep,QQ as heal,Pj as healFace,Nj as healSolid,Fj as healWire,fM as helix,XX as hull,cQ as importDXF,TQ as importGLB,fJ as importIGES,fQ as importOBJ,uJ as importSTEP,dJ as importSTL,cJ as importSVG,sJ as importSVGPathD,wQ as importThreeMF,KN as importURDF,ST as init,lT as initFromManifold,bT as initFromOC,aY as initVoxel,aO as innerWires,fk as interpolateCurve,RQ as intersect,fL as intersect2D,tL as intersectBlueprints,pj as intersectWithEvolution,LE as invalidateShapeCache,jN as inverseKinematics,A1 as io,fo as ioError,UT as is2D,HT as is3D,JJ as isChamferRadius,XT as isClosedWire,HD as isCompSolid,CE as isCompound,OJ as isDisposeRequest,vE as isEdge,o$ as isEmpty,QO as isEqualShape,A as isErr,AJ as isErrorResponse,bE as isFace,YJ as isFilletRadius,EJ as isInitRequest,WK as isInside2D,VT as isLive,QT as isManifoldShell,qJ as isNumber,Na as isOk,DJ as isOperationRequest,ZT as isOrientedFace,iE as isPlanarFace,aE as isPlanarWire,yG as isProjectionPlane,FJ as isQueueEmpty,ZO as isSameShape,TE as isShape1D,wE as isShape3D,xE as isShell,SE as isSolid,kJ as isSuccessResponse,a$ as isValid,$T as isValidSolid,_E as isVertex,yE as isWire,ZE as iterCompSolids,GE as iterEdges,KE as iterFaces,XE as iterShells,YE as iterSolids,RD as iterTopo,JE as iterVertices,qE as iterWires,NN as jointTrajectory,fN as jointTransform,IN as jointsFromDH,AE as kernelCall,jE as kernelCallRaw,ME as kernelCallScoped,P as kernelError,AX as latticeInfill,jX as latticeInfillShape,lM as line,NM as linearPattern,mG as loadFont,l$ as loft,nM as loftAll,RG as makeBaseBox,u1 as makeExternalGear,d1 as makeInternalGear,jD as makePlane,p1 as makePlanetaryGear,xG as makeProjectedEdges,nE as manifoldShell,Pa as map,Ga as mapBoth,Fa as mapErr,Za as match,vP as measureArea,CP as measureCurvatureAt,wP as measureCurvatureAtMid,bP as measureDistance,xP as measureDistanceProps,yP as measureLength,gP as measureLinearProps,hP as measureSurfaceProps,_P as measureVolume,mP as measureVolumeProps,k1 as measurement,vN as mechanismDOF,e$ as mesh,t$ as meshEdges,Nk as meshMultiLOD,tZ as minkowski,kQ as mirror,YK as mirror2D,AK as mirrorDrawing,h$ as mirrorJoin,D1 as modifiers,aP as modifyStep,uo as moduleInitError,Xj as multiSectionSweep,$D as normalAt,YQ as offset,DM as offsetFace,xY as offsetMesh,wY as offsetShape,mk as offsetWire2D,O as ok,Ra as or,za as orElse,lI as organiseBlueprints,tE as orientedFace,rO as outerWire,N1 as patterns,PJ as pendingCount,to as pipeline,PD as pivotPlane,oE as planarFace,sN as planarJoint,sE as planarWire,a1 as planetPlacements,p$ as pocket,XD as pointOnSurface,uY as pointsInside,CM as polygon,nZ as polyhedron,PG as polysideInnerRadius,EI as polysidesBlueprint,_j as positionOnCurve,xT as prewarm,T1 as primitives,aN as prismaticJoint,TG as projectEdges,QD as projectPointOnFace,j1 as query,po as queryError,g$ as rectangularPattern,BJ as registerHandler,uT as registerKernel,_T as registerKernelTier,nP as registerOperation,eP as registerShape,nY as registerVoxel,IJ as rejectAll,LM as removeChild,iO as removeHolesFromFace,pY as repairMesh,iP as replayFrom,rP as replayHistory,OT as resetDisposalStats,Oo as resetPerformanceStats,BO as resize,$ as resolve,EQ as resolve3D,lD as resolveDirection,AD as resolvePlane,TJ as resolveRef,jK as reverseCurve,iN as revoluteJoint,c$ as revolve,TZ as roof,OQ as rotate,qK as rotate2D,OK as rotateDrawing,DI as roundedRectangleBlueprint,AQ as scale,JK as scale2D,kK as scaleDrawing,aX as sdfBox,lX as sdfCapsule,cX as sdfCone,sX as sdfCylinder,xX as sdfFieldAxialRamp,wX as sdfFieldClamp,bX as sdfFieldConst,CX as sdfFieldFromSdf,SX as sdfFieldRadialRamp,hX as sdfLattice,dX as sdfPlane,oX as sdfRoundedBox,iX as sdfSphere,gX as sdfStrutLattice,pX as sdfSweep,uX as sdfTorus,zQ as section,BQ as sectionToFace,oP as serializeHistory,uN as setJointValue,lN as setJointValues,oO as setShapeOrigin,yO as setTagMetadata,OM as sewShells,F$ as shape,hY as shapeToMeshInput,zD as shapeType,KA as sharedEdges,JQ as shell,SY as shellMesh,TY as shellShape,gj as shellWithEvolution,$Q as simplify,kG as sketchCircle,AG as sketchEllipse,nG as sketchExtrude,$W as sketchFace,FG as sketchFaceOffset,LG as sketchHelix,iG as sketchLoft,QK as sketchOnFace2D,ZK as sketchOnPlane2D,IG as sketchParametricFunction,NG as sketchPolysides,jG as sketchRectangle,tG as sketchRevolve,MG as sketchRoundedRectangle,rG as sketchSweep,pJ as sketchText,eG as sketchWires,lo as sketcherStateError,HQ as slice,EM as solid,zj as solidFromShell,tQ as solveAssembly,aM as sphere,cN as sphericalJoint,VQ as split,QN as stepCount,$N as stepsFrom,XK as stretch2D,SM as subFace,Gj as supportExtrude,aT as supportsConstraintSketch,iT as supportsProjection,GX as surfaceFromGrid,JX as surfaceFromImage,Wj as sweep,gO as tagFaces,_M as tangentArc,Ha as tap,Ua as tapErr,_G as textBlueprints,mJ as textMetrics,XQ as thicken,cP as thread,pM as threePointArc,r$ as toBREP,NA as toBufferGeometryData,PA as toGroupedBufferGeometryData,NX as toKernelVec,IA as toLODGeometryData,FA as toLineGeometryData,GK as toSVGPathD,sD as toVec2,oD as toVec3,sM as torus,MX as tpmsLattice,NQ as transformCopy,O1 as transforms,DQ as translate,KK as translate2D,DK as translateDrawing,ND as translatePlane,$a as tryCatch,eo as tryCatchAsync,qj as twistExtrude,co as typeCastError,YN as undoLast,mo as unsupportedError,j as unwrap,Xa as unwrapErr,Ja as unwrapOr,Ya as unwrapOrElse,RM as updateNode,SJ as updateRoles,YD as uvBounds,ZD as uvCoordinates,rE as validSolid,K$ as validatePlanetary,F as validationError,jj as variableFillet,uD as vecAdd,SD as vecAngle,hD as vecCross,vD as vecDistance,mD as vecDot,bD as vecEquals,xD as vecIsZero,gD as vecLength,_D as vecLengthSq,pD as vecNegate,yD as vecNormalize,CD as vecProjectToPlane,ED as vecRepr,wD as vecRotate,fD as vecScale,dD as vecSub,wM as vertex,QJ as vertexFinder,rD as vertexPosition,WA as verticesOfEdge,CY as voxelBoolean,RY as voxelBooleanField,GY as voxelBooleanFieldShapes,EY as voxelBooleanShapes,LY as voxelField,WY as voxelFieldFromShape,BM as walkAssembly,lY as windingNumbers,vM as wire,eF as wireFinder,yM as wireLoop,UA as wiresOfFace,pT as withKernel,VX as withKernelDir,BX as withKernelPnt,zX as withKernelVec,hT as withQuality,IT as withScope,zT as withScopeResult,BT as withScopeResultAsync,yT as withTier,Ba as zipResults};
|