brepjs-cad 0.96.0 → 0.98.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 +84 -0
- package/package.json +4 -4
- package/viewer/dist/assets/brepjs-PFlLOWDy.js +60 -0
- package/viewer/dist/assets/{index-CAqC8r21.js → index-D3-CM2mC.js} +1 -1
- package/viewer/dist/assets/{kernelWorker-BDC3iPOp.js → kernelWorker-rjgVuFfG.js} +1 -1
- package/viewer/dist/index.html +1 -1
- package/viewer/dist/wasm/occt-wasm.wasm +0 -0
- package/viewer/dist/assets/brepjs-42d18nEr.js +0 -60
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports);function t(e,t){return e[t]}function n(e,t=0){return[e[t],e[t+1],e[t+2]]}var r=class extends Error{location;constructor(e,t){super(`Bug in ${e}: ${t}`),this.name=`BrepBugError`,this.location=e}};function i(e,t){throw new r(e,t)}var a={exact:!0,brepExport:!0,exactMeasurement:!0,tessellationModel:`extract-time`},o={exact:!0,brepExport:!0,exactMeasurement:!0,tessellationModel:`none`},s=Symbol.for(`brepjs.kernel.unsupportedOperation`),c=class extends Error{constructor(e){super(e),this.name=`UnsupportedKernelOperationError`,Object.defineProperty(this,s,{value:!0})}};function l(e){return e instanceof Error&&Reflect.get(e,s)===!0}function u(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}function d(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}function f(e,t){return e.x*t.x+e.y*t.y+e.z*t.z}function p(e){return Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z)}function m(e,t){let n=e.x-t.x,r=e.y-t.y,i=e.z-t.z;return n*n+r*r+i*i}function h(e,t){let n=e[t];if(n===void 0)throw Error(`Index ${t} out of bounds`);return n}function g(e,t){let n=e[t];if(n===void 0)throw Error(`Index ${t} out of bounds`);return n}function _(e,t,n,r){let i=d(u(h(e,n),h(e,t)),u(h(e,r),h(e,t))),a=p(i),o=a>1e-14?{x:i.x/a,y:i.y/a,z:i.z/a}:i;return{a:t,b:n,c:r,normal:o,offset:f(o,h(e,t)),alive:!0,outsidePoints:[]}}function v(e,t){return f(e.normal,t)-e.offset}function y(e,t){let n=t*t,r=[];for(let t of e){let e=!1;for(let i of r)if(m(t,i)<n){e=!0;break}e||r.push(t)}return r}function b(e){let t=e.length;if(t<4)return null;let n=0,r=1,i=m(h(e,0),h(e,1));for(let a=0;a<t;a++)for(let o=a+1;o<t;o++){let t=m(h(e,a),h(e,o));t>i&&(i=t,n=a,r=o)}if(i<1e-20)return null;let a=u(h(e,r),h(e,n)),o=-1,s=-1;for(let i=0;i<t;i++){if(i===n||i===r)continue;let t=d(a,u(h(e,i),h(e,n))),c=f(t,t);c>s&&(s=c,o=i)}if(o===-1||s<1e-20)return null;let c=d(u(h(e,r),h(e,n)),u(h(e,o),h(e,n))),l=p(c);if(l<1e-14)return null;let g={x:c.x/l,y:c.y/l,z:c.z/l},_=f(g,h(e,n)),v=-1,y=-1;for(let i=0;i<t;i++){if(i===n||i===r||i===o)continue;let t=Math.abs(f(g,h(e,i))-_);t>y&&(y=t,v=i)}return v===-1||y<1e-14?null:f(g,h(e,v))-_>0?[n,o,r,v]:[n,r,o,v]}function x(e,t){let n=y(e,t);if(n.length<4)throw Error(n.length===0?`No points provided for convex hull`:`Fewer than 4 non-coincident points; cannot form a 3D convex hull`);let r=b(n);if(r===null)throw Error(`All points are coplanar; cannot form a 3D convex hull`);let[i,a,o,s]=r,c={x:(h(n,i).x+h(n,a).x+h(n,o).x+h(n,s).x)/4,y:(h(n,i).y+h(n,a).y+h(n,o).y+h(n,s).y)/4,z:(h(n,i).z+h(n,a).z+h(n,o).z+h(n,s).z)/4};function l(e,t,r){let i=_(n,e,t,r),a={x:(h(n,e).x+h(n,t).x+h(n,r).x)/3,y:(h(n,e).y+h(n,t).y+h(n,r).y)/3,z:(h(n,e).z+h(n,t).z+h(n,r).z)/3},o=u(c,a);return f(i.normal,o)>0?_(n,e,r,t):i}let d=[l(i,a,o),l(i,o,s),l(i,s,a),l(a,s,o)],p=new Set([i,a,o,s]),m=1e-10;for(let e=0;e<n.length;e++)if(!p.has(e)){for(let t of d)if(v(t,h(n,e))>m){t.outsidePoints.push(e);break}}for(let e=0;e<n.length*4;e++){let e=null;for(let t of d)if(t.alive&&t.outsidePoints.length>0){e=t;break}if(e===null)break;let t=g(e.outsidePoints,0),r=v(e,h(n,t));for(let i=1;i<e.outsidePoints.length;i++){let a=g(e.outsidePoints,i),o=v(e,h(n,a));o>r&&(r=o,t=a)}let i=[];for(let e of d)e.alive&&v(e,h(n,t))>m&&i.push(e);let a=new Map;for(let e of i){let t=[[e.a,e.b],[e.b,e.c],[e.c,e.a]];for(let[e,n]of t){let t=e<n?`${e}-${n}`:`${n}-${e}`,r=a.get(t);r?r.count++:a.set(t,{a:e,b:n,count:1})}}let o=[];for(let e of a.values())e.count===1&&o.push({a:e.a,b:e.b});let s=[];for(let e of i){for(let n of e.outsidePoints)n!==t&&s.push(n);e.alive=!1,e.outsidePoints=[]}let c=[];for(let e of o){let r=_(n,e.a,e.b,t);c.push(r),d.push(r)}for(let e of s)for(let t of c)if(v(t,h(n,e))>m){t.outsidePoints.push(e);break}}let x=[];for(let e of d)e.alive&&x.push([e.a,e.b,e.c]);return{faces:x,points:n}}function S(e,t){switch(e.__bk2d){case`line`:return[e.ox+e.dx*t,e.oy+e.dy*t];case`circle`:{let n=e.sense?t:-t;return[e.cx+e.radius*Math.cos(n),e.cy+e.radius*Math.sin(n)]}case`ellipse`:{let n=e.sense?t:-t,r=Math.cos(e.xDirAngle),i=Math.sin(e.xDirAngle),a=e.majorRadius*Math.cos(n),o=e.minorRadius*Math.sin(n);return[e.cx+a*r-o*i,e.cy+a*i+o*r]}case`bezier`:return Te(e.poles,t);case`bspline`:return Ee(e,t);case`trimmed`:{let n=e.tStart+t*(e.tEnd-e.tStart);return S(e.basis,n)}}}function C(e,t){switch(e.__bk2d){case`line`:return[e.dx,e.dy];case`circle`:{let n=e.sense?t:-t,r=e.sense?1:-1;return[-e.radius*Math.sin(n)*r,e.radius*Math.cos(n)*r]}case`ellipse`:{let n=e.sense?t:-t,r=e.sense?1:-1,i=Math.cos(e.xDirAngle),a=Math.sin(e.xDirAngle),o=-e.majorRadius*Math.sin(n)*r,s=e.minorRadius*Math.cos(n)*r;return[o*i-s*a,o*a+s*i]}case`bezier`:{let n=1e-8,r=Te(e.poles,Math.max(0,t-n)),i=Te(e.poles,Math.min(1,t+n)),a=Math.min(1,t+n)-Math.max(0,t-n);return[(i[0]-r[0])/a,(i[1]-r[1])/a]}case`bspline`:{let n=1e-8,r=e.knots[0],i=e.knots[e.knots.length-1],a=Ee(e,Math.max(r,t-n)),o=Ee(e,Math.min(i,t+n)),s=Math.min(i,t+n)-Math.max(r,t-n);return[(o[0]-a[0])/s,(o[1]-a[1])/s]}case`trimmed`:{let n=e.tStart+t*(e.tEnd-e.tStart),r=C(e.basis,n),i=e.tEnd-e.tStart;return[r[0]*i,r[1]*i]}}}function w(e){switch(e.__bk2d){case`line`:return{first:0,last:e.len};case`circle`:case`ellipse`:return{first:0,last:2*Math.PI};case`bezier`:return{first:0,last:1};case`bspline`:return{first:e.knots[0],last:e.knots[e.knots.length-1]};case`trimmed`:return{first:0,last:1}}}function ee(e){switch(e.__bk2d){case`line`:return`LINE`;case`circle`:return`CIRCLE`;case`ellipse`:return`ELLIPSE`;case`bezier`:return`BEZIER_CURVE`;case`bspline`:return`BSPLINE_CURVE`;case`trimmed`:return`TRIMMED_`+ee(e.basis)}}function te(e,t,n,r){let i=n-e,a=r-t,o=Math.sqrt(i*i+a*a);return{__bk2d:`line`,ox:e,oy:t,dx:o>0?i/o:1,dy:o>0?a/o:0,len:o}}function ne(e,t,n,r=!0){return{__bk2d:`circle`,cx:e,cy:t,radius:n,sense:r}}function re(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 te(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=ne(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 ie(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 te(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,x;if(b>0){let e=_-g;e<=0&&(e+=2*Math.PI),x=g+e/2}else{let e=_-g;e>=0&&(e-=2*Math.PI),x=g+e/2}return re(e,t,p+h*Math.cos(x),m+h*Math.sin(x),i,a)}function ae(e,t,n,r,i=1,a=0,o=!0){return{__bk2d:`ellipse`,cx:e,cy:t,majorRadius:n,minorRadius:r,xDirAngle:Math.atan2(a,i),sense:o}}function oe(e){return{__bk2d:`bezier`,poles:[...e]}}function se(e,t,n){switch(e.__bk2d){case`line`:return{...e,ox:e.ox+t,oy:e.oy+n};case`circle`:return{...e,cx:e.cx+t,cy:e.cy+n};case`ellipse`:return{...e,cx:e.cx+t,cy:e.cy+n};case`bezier`:return{...e,poles:e.poles.map(([e,r])=>[e+t,r+n])};case`bspline`:return{...e,poles:e.poles.map(([e,r])=>[e+t,r+n])};case`trimmed`:return{...e,basis:se(e.basis,t,n)}}}function ce(e,t,n,r){let i=Math.cos(t),a=Math.sin(t),o=(e,t)=>{let o=e-n,s=t-r;return[n+o*i-s*a,r+o*a+s*i]};switch(e.__bk2d){case`line`:{let[t,n]=o(e.ox,e.oy),r=e.dx*i-e.dy*a,s=e.dx*a+e.dy*i;return{...e,ox:t,oy:n,dx:r,dy:s}}case`circle`:{let[t,n]=o(e.cx,e.cy);return{...e,cx:t,cy:n}}case`ellipse`:{let[n,r]=o(e.cx,e.cy);return{...e,cx:n,cy:r,xDirAngle:e.xDirAngle+t}}case`bezier`:return{...e,poles:e.poles.map(([e,t])=>o(e,t))};case`bspline`:return{...e,poles:e.poles.map(([e,t])=>o(e,t))};case`trimmed`:return{...e,basis:ce(e.basis,t,n,r)}}}function le(e,t,n,r){let i=(e,i)=>[n+(e-n)*t,r+(i-r)*t];switch(e.__bk2d){case`line`:{let[t,n]=i(e.ox,e.oy),[r,a]=i(e.ox+e.dx*e.len,e.oy+e.dy*e.len),o=r-t,s=a-n,c=Math.sqrt(o*o+s*s);return{...e,ox:t,oy:n,dx:c>0?o/c:e.dx,dy:c>0?s/c:e.dy,len:c}}case`circle`:{let[n,r]=i(e.cx,e.cy);return{...e,cx:n,cy:r,radius:e.radius*Math.abs(t)}}case`ellipse`:{let[n,r]=i(e.cx,e.cy);return{...e,cx:n,cy:r,majorRadius:e.majorRadius*Math.abs(t),minorRadius:e.minorRadius*Math.abs(t)}}case`bezier`:return{...e,poles:e.poles.map(([e,t])=>i(e,t))};case`bspline`:return{...e,poles:e.poles.map(([e,t])=>i(e,t))};case`trimmed`:return{...e,basis:le(e.basis,t,n,r)}}}function ue(e,t,n){return le(e,-1,t,n)}function de(e,t,n,r,i){let a=Math.sqrt(r*r+i*i),o=r/a,s=i/a,c=(e,r)=>{let i=e-t,a=r-n,c=i*o+a*s;return[t+2*c*o-i,n+2*c*s-a]};switch(e.__bk2d){case`line`:{let[t,n]=c(e.ox,e.oy),r=2*(e.dx*o+e.dy*s)*o-e.dx,i=2*(e.dx*o+e.dy*s)*s-e.dy;return{...e,ox:t,oy:n,dx:r,dy:i}}case`circle`:{let[t,n]=c(e.cx,e.cy);return{...e,cx:t,cy:n,sense:!e.sense}}case`ellipse`:{let[t,n]=c(e.cx,e.cy),r=o*o-s*s,i=2*o*s,a=Math.atan2(i*Math.cos(e.xDirAngle)-r*Math.sin(e.xDirAngle),r*Math.cos(e.xDirAngle)+i*Math.sin(e.xDirAngle));return{...e,cx:t,cy:n,xDirAngle:a,sense:!e.sense}}case`bezier`:return{...e,poles:e.poles.map(([e,t])=>c(e,t))};case`bspline`:return{...e,poles:e.poles.map(([e,t])=>c(e,t))};case`trimmed`:return{...e,basis:de(e.basis,t,n,r,i)}}}function fe(e,t,n){let r=pe(e),i=pe(t);return r.__bk2d===`line`&&i.__bk2d===`line`?ge(e,r,t,i,n):r.__bk2d===`line`&&i.__bk2d===`circle`?{points:_e(e,r,t,i,n),segments:[]}:r.__bk2d===`circle`&&i.__bk2d===`line`?{points:_e(t,i,e,r,n),segments:[]}:r.__bk2d===`circle`&&i.__bk2d===`circle`?{points:ye(e,r,t,i,n),segments:[]}:be(e,t,n,e===t)}function pe(e){let t=e;for(;t.__bk2d===`trimmed`;)t=t.basis;return t}function me(e,t,n){let r=w(e);return t>=r.first-n&&t<=r.last+n}function he(e,t,n){let r=w(e);if(!isFinite(r.first)||!isFinite(r.last))return null;let i=(r.last-r.first)/80,a=r.first,o=1/0;for(let s=0;s<=80;s++){let c=r.first+s*i,[l,u]=S(e,c),d=(l-t)**2+(u-n)**2;d<o&&(o=d,a=c)}let[s,c]=S(e,r.first),[l,u]=S(e,r.last),[d,f]=S(e,(r.first+r.last)/2),p=Math.max(Math.sqrt((l-s)**2+(u-c)**2),Math.sqrt((d-s)**2+(f-c)**2),1e-6)*.1;return o<p*p?a:null}function ge(e,t,n,r,i){let a=t.dx*r.dy-t.dy*r.dx;if(Math.abs(a)>=1e-14){let o=r.ox-t.ox,s=r.oy-t.oy,c=(o*r.dy-s*r.dx)/a,l=(o*t.dy-s*t.dx)/a;return!me(e,c,i)||!me(n,l,i)?{points:[],segments:[]}:{points:[[t.ox+c*t.dx,t.oy+c*t.dy]],segments:[]}}let o=r.ox-t.ox,s=r.oy-t.oy,c=o*t.dy-s*t.dx;if(Math.abs(c)>i)return{points:[],segments:[]};let l=w(e),u=w(n),d=S(n,u.first),f=S(n,u.last),p=(d[0]-t.ox)*t.dx+(d[1]-t.oy)*t.dy,m=(f[0]-t.ox)*t.dx+(f[1]-t.oy)*t.dy,h=Math.max(l.first,Math.min(p,m)),g=Math.min(l.last,Math.max(p,m));return g-h<i?{points:[],segments:[]}:{points:[],segments:[te(t.ox+h*t.dx,t.oy+h*t.dy,t.ox+g*t.dx,t.oy+g*t.dy)]}}function _e(e,t,n,r,i){let a=t.ox-r.cx,o=t.oy-r.cy,s=t.dx*t.dx+t.dy*t.dy,c=2*(a*t.dx+o*t.dy),l=a*a+o*o-r.radius*r.radius,u=c*c-4*s*l;if(u<-i)return[];let d=[],f=Math.sqrt(Math.max(0,u)),p=(-c-f)/(2*s),m=(-c+f)/(2*s);for(let r of u<i*i?[p]:[p,m]){if(!me(e,r,i))continue;let a=t.ox+r*t.dx,o=t.oy+r*t.dy,s=he(n,a,o);if(s===null)continue;let[c,l]=S(n,s);(c-a)**2+(l-o)**2>i*i*1e6||d.push([a,o])}return d}function ve(e,t,n){let r=w(e),i=w(t),a=Math.abs(r.last-r.first-2*Math.PI)<1e-10,o=Math.abs(i.last-i.first-2*Math.PI)<1e-10;if(a&&o)return[];if(a)return[S(t,i.first),S(t,i.last)];if(o)return[S(e,r.first),S(e,r.last)];let s=[],c=[[t,S(e,r.first)],[t,S(e,r.last)],[e,S(t,i.first)],[e,S(t,i.last)]];for(let[e,t]of c){let r=he(e,t[0],t[1]);if(r!==null){let[i,a]=S(e,r);(i-t[0])**2+(a-t[1])**2<n*n*100&&s.push(t)}}let l=[];for(let e of s)l.some(([t,r])=>(t-e[0])**2+(r-e[1])**2<n*n*100)||l.push(e);return l}function ye(e,t,n,r,i){let a=r.cx-t.cx,o=r.cy-t.cy,s=Math.sqrt(a*a+o*o);if(s>t.radius+r.radius+i||s<Math.abs(t.radius-r.radius)-i)return[];if(s<1e-14)return Math.abs(t.radius-r.radius)>i?[]:ve(e,n,i);let c=(t.radius*t.radius-r.radius*r.radius+s*s)/(2*s),l=t.radius*t.radius-c*c,u=Math.sqrt(Math.max(0,l)),d=t.cx+c*a/s,f=t.cy+c*o/s,p=u<i?[[d,f]]:[[d+u*o/s,f-u*a/s],[d-u*o/s,f+u*a/s]],m=[];for(let[t,r]of p){let a=he(e,t,r),o=he(n,t,r);if(a===null||o===null)continue;let[s,c]=S(e,a),[l,u]=S(n,o),d=(i*10)**2;(s-t)**2+(c-r)**2>d||(l-t)**2+(u-r)**2>d||m.push([t,r])}return m}function be(e,t,n,r=!1){let i=w(e),a=w(t);if(!isFinite(i.first)||!isFinite(i.last)||!isFinite(a.first)||!isFinite(a.last))return{points:[],segments:[]};let o=[],s=[];for(let n=0;n<=100;n++){let r=i.first+(i.last-i.first)*n/100,[c,l]=S(e,r);o.push({t:r,x:c,y:l});let u=a.first+(a.last-a.first)*n/100,[d,f]=S(t,u);s.push({t:u,x:d,y:f})}let c=Math.max(n*100,.5),l=new Float64Array(600);for(let e=0;e<100;e++){let t=s[e],n=s[e+1],r=e*6;l[r]=Math.min(t.x,n.x),l[r+1]=Math.max(t.x,n.x),l[r+2]=Math.min(t.y,n.y),l[r+3]=Math.max(t.y,n.y),l[r+4]=(t.t+n.t)/2}let u=[],d=(i.last-i.first)/5;for(let e=0;e<100;e++){let t=o[e],n=o[e+1],i=Math.min(t.x,n.x)-c,a=Math.max(t.x,n.x)+c,s=Math.min(t.y,n.y)-c,f=Math.max(t.y,n.y)+c,p=(t.t+n.t)/2;for(let e=0;e<100;e++){let t=e*6;if(a<l[t]||l[t+1]<i||f<l[t+2]||l[t+3]<s)continue;let n=l[t+4];r&&Math.abs(p-n)<d||u.push({t1:p,t2:n})}}let f=n*n,p=[];for(let{t1:o,t2:s}of u){let c=o,l=s;for(let n=0;n<20;n++){let[n,r]=S(e,c),[o,s]=S(t,l),u=n-o,d=r-s;if(u*u+d*d<f)break;let p=C(e,c),m=C(t,l),h=p[0]*-m[1]- -m[0]*p[1];if(Math.abs(h)<1e-14)break;let g=(-u*-m[1]- -d*-m[0])/h,_=(p[0]*-d-p[1]*-u)/h;c+=g,l+=_,c=Math.max(i.first,Math.min(i.last,c)),l=Math.max(a.first,Math.min(a.last,l))}let[u,d]=S(e,c),[m,h]=S(t,l);if(!(r&&Math.abs(c-l)<(i.last-i.first)*.05)&&(u-m)**2+(d-h)**2<n*n*1e6){let e=(u+m)/2,t=(d+h)/2,r=!1;for(let[i,a]of p)if((i-e)**2+(a-t)**2<n*n*1e4){r=!0;break}r||p.push([e,t])}}return{points:p,segments:[]}}function xe(e){return JSON.stringify(e)}function Se(e){return JSON.parse(e)}function Ce(){return{__bk2d_bbox:!0,xMin:1/0,yMin:1/0,xMax:-1/0,yMax:-1/0}}function we(e,t,n){let r=t.__bk2d===`trimmed`?t.basis:t;if(r.__bk2d===`line`){let n=w(t);if(!isFinite(n.first)||!isFinite(n.last))return;let[r,i]=S(t,n.first),[a,o]=S(t,n.last);e.xMin=Math.min(e.xMin,r,a),e.yMin=Math.min(e.yMin,i,o),e.xMax=Math.max(e.xMax,r,a),e.yMax=Math.max(e.yMax,i,o);return}if(r.__bk2d===`circle`){let n=w(t);if(!isFinite(n.first)||!isFinite(n.last))return;let{cx:i,cy:a,radius:o,sense:s}=r,[c,l]=S(t,n.first),[u,d]=S(t,n.last),f=Math.min(c,u),p=Math.max(c,u),m=Math.min(l,d),h=Math.max(l,d),g=t.__bk2d===`trimmed`?t.tStart:n.first,_=t.__bk2d===`trimmed`?t.tEnd:n.last;for(let e=0;e<4;e++){let t=e*Math.PI/2,n=s?t:-t;for(let e=0;e<=1;e++){let r=n+e*2*Math.PI;if(r>=g-1e-10&&r<=_+1e-10){let e=i+o*Math.cos(t),n=a+o*Math.sin(t);f=Math.min(f,e),p=Math.max(p,e),m=Math.min(m,n),h=Math.max(h,n);break}}}e.xMin=Math.min(e.xMin,f),e.yMin=Math.min(e.yMin,m),e.xMax=Math.max(e.xMax,p),e.yMax=Math.max(e.yMax,h);return}let i=w(t);if(!isFinite(i.first)||!isFinite(i.last))return;let a=(i.last-i.first)/20;for(let n=0;n<=20;n++){let[r,o]=S(t,i.first+n*a);r<e.xMin&&(e.xMin=r),o<e.yMin&&(e.yMin=o),r>e.xMax&&(e.xMax=r),o>e.yMax&&(e.yMax=o)}}function Te(e,t){let n=e.length,r=e.map(([e,t])=>[e,t]);for(let e=1;e<n;e++)for(let i=0;i<n-e;i++){let e=r[i],n=r[i+1];e[0]=(1-t)*e[0]+t*n[0],e[1]=(1-t)*e[1]+t*n[1]}return r[0]}function Ee(e,t){let n=[];for(let t=0;t<e.knots.length;t++){let r=e.multiplicities[t]??1;for(let i=0;i<r;i++)n.push(e.knots[t])}let r=e.degree,i=e.poles.length,a=n.length,o=Math.max(n[r],Math.min(n[a-r-1],t)),s=r;for(let e=r;e<a-r-1;e++)if(o>=n[e]&&o<n[e+1]){s=e;break}o>=n[a-r-1]&&(s=a-r-2);let c=[];for(let t=0;t<=r;t++){let n=Math.min(s-r+t,i-1),a=e.poles[Math.max(0,n)];c.push([a[0],a[1]])}for(let e=1;e<=r;e++)for(let t=r;t>=e;t--){let i=s-r+t,a=n[i]??0,l=(n[i+r-e+1]??1)-a,u=l>1e-15?(o-a)/l:0,d=c[t],f=c[t-1];d[0]=(1-u)*f[0]+u*d[0],d[1]=(1-u)*f[1]+u*d[1]}return c[r]}var De=.001,Oe=.1,ke={nx:0,ny:0,nz:0,ax:0,ay:0,az:0,bx:0,by:0,bz:0,cx:0,cy:0,cz:0};function Ae(e,t,n){let r=(t[n*3]??0)*3,i=(t[n*3+1]??0)*3,a=(t[n*3+2]??0)*3,o=e[r]??0,s=e[r+1]??0,c=e[r+2]??0,l=e[i]??0,u=e[i+1]??0,d=e[i+2]??0,f=e[a]??0,p=e[a+1]??0,m=e[a+2]??0,h=l-o,g=u-s,_=d-c,v=f-o,y=p-s,b=m-c,x=g*b-_*y,S=_*v-h*b,C=h*y-g*v,w=Math.hypot(x,S,C)||1;return x/=w,S/=w,C/=w,ke.nx=x,ke.ny=S,ke.nz=C,ke.ax=o,ke.ay=s,ke.az=c,ke.bx=l,ke.by=u,ke.bz=d,ke.cx=f,ke.cy=p,ke.cz=m,ke}function je(e,t){let n=Math.floor(t.length/3),r=new ArrayBuffer(84+n*50),i=new DataView(r);i.setUint32(80,n,!0);let a=84;for(let r=0;r<n;r++){let n=Ae(e,t,r);i.setFloat32(a,n.nx,!0),i.setFloat32(a+4,n.ny,!0),i.setFloat32(a+8,n.nz,!0),i.setFloat32(a+12,n.ax,!0),i.setFloat32(a+16,n.ay,!0),i.setFloat32(a+20,n.az,!0),i.setFloat32(a+24,n.bx,!0),i.setFloat32(a+28,n.by,!0),i.setFloat32(a+32,n.bz,!0),i.setFloat32(a+36,n.cx,!0),i.setFloat32(a+40,n.cy,!0),i.setFloat32(a+44,n.cz,!0),i.setUint16(a+48,0,!0),a+=50}return r}function Me(e,t){let n=Math.floor(t.length/3),r=[`solid brepjs`];for(let i=0;i<n;i++){let n=Ae(e,t,i);r.push(`facet normal ${n.nx} ${n.ny} ${n.nz}`),r.push(`outer loop`),r.push(`vertex ${n.ax} ${n.ay} ${n.az}`),r.push(`vertex ${n.bx} ${n.by} ${n.bz}`),r.push(`vertex ${n.cx} ${n.cy} ${n.cz}`),r.push(`endloop`),r.push(`endfacet`)}return r.push(`endsolid brepjs`),r.join(`
|
|
2
|
+
`)+`
|
|
3
|
+
`}var Ne=()=>{};function T(e,t){return{__occtWasm:!0,type:e,id:t,delete:Ne,HashCode(e){return t%e},IsNull(){return!1}}}function Pe(e){return typeof e==`object`&&!!e&&e.__occtWasm}function E(e){if(Pe(e))return e.id;if(typeof e==`number`)return e;throw Error(`occt-wasm: expected an OcctWasmHandle or number, got `+typeof e)}function Fe(e){switch(e.toLowerCase()){case`vertex`:return`vertex`;case`edge`:return`edge`;case`wire`:return`wire`;case`face`:return`face`;case`shell`:return`shell`;case`solid`:return`solid`;case`compsolid`:return`compsolid`;case`compound`:return`compound`;default:return`compound`}}function D(e,t){return T(Fe(e.getShapeType(t)),t)}function Ie(e,t){let n=new e.VectorUint32;for(let e of t)n.push_back(e);return n}function Le(e,t){let n=new e.VectorInt;for(let e of t)n.push_back(e);return n}function Re(e,t){let n=new e.VectorDouble;for(let e of t)n.push_back(e);return n}function ze(e){let t=[],n=e.size();for(let r=0;r<n;r++)t.push(e.get(r));return t}function Be(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}function Ve(e,t){if(typeof t==`number`)return t;if(Array.isArray(t))return t[0];if(e.length===0)throw Error(`occt-wasm: no edges provided`);let n=t(e[0]);return typeof n==`number`?n:n[0]}function He(e,t,n){let[r,i,a]=n,o=Math.sqrt(r*r+i*i+a*a);if(o<1e-10)return t;let s=r/o,c=i/o,l=a/o;if(Math.abs(l-1)<1e-10)return t;if(Math.abs(l+1)<1e-10)return e.rotate(t,0,0,0,1,0,0,Math.PI);let u=-c,d=s,f=Math.sqrt(u*u+d*d);if(f<1e-10)return t;let p=Math.acos(Math.max(-1,Math.min(1,l)));return e.rotate(t,0,0,0,u/f,d/f,0,p)}function Ue(e,t){return new Proxy(e,{get(e,n,r){let i=Reflect.get(e,n,r);return typeof i==`function`?function(...n){try{return i.apply(e,n)}catch(e){let n=WebAssembly.Exception;if(n&&e instanceof n)try{let[,n]=t.getExceptionMessage(e);throw Error(n,{cause:e})}catch(e){if(e instanceof Error&&!(e instanceof n))throw e}throw e}}:i}})}function We(e,t){let n=function(){return T(`compound`,t.makeNullShape())};return Object.assign(Object.create(e),{TopoDS_Solid:n,TopoDS_Face:n,TopoDS_Shape:n,TopoDS_Wire:n,TopoDS_Edge:n,TopoDS_Vertex:n,TopoDS_Shell:n,TopoDS_Compound:n,gp_Pnt_3:function(e,n,r){return T(`vertex`,t.makeVertex(e,n,r))},BRepBuilderAPI_MakeEdge_3:function(e,n){let r=e,i=n,a=t.vertexPosition(r.id),o=t.vertexPosition(i.id),s=t.makeLineEdge(a.get(0),a.get(1),a.get(2),o.get(0),o.get(1),o.get(2));return a.delete(),o.delete(),{Edge:()=>T(`edge`,s),delete(){}}}})}function Ge(e,t){let n=E(t),r=e.getSubShapes(n,`solid`);try{if(r.size()>1){let t=e.fuseAll(r);return{id:t,dispose:()=>{e.release(t)}}}return{id:n,dispose:()=>{}}}finally{for(let t=0,i=r.size();t<i;t++){let i=r.get(t);i!==n&&e.release(i)}r.delete()}}function Ke(e,t,n,r){return D(e,e.fuse(E(t),E(n)))}function qe(e,t,n,r){let i=Ge(e,n);try{return D(e,e.cut(E(t),i.id))}finally{i.dispose()}}function Je(e,t,n,r){let i=Ge(e,n);try{return D(e,e.intersect(E(t),i.id))}finally{i.dispose()}}function Ye(e,t,n,r){return D(e,e.section(E(t),E(n)))}function Xe(e,t,n,r){let i=Ie(t,n.map(E));try{return D(e,e.fuseAll(i))}finally{i.delete()}}function Ze(e,t,n,r,i){let a=Ie(t,r.map(E));try{return D(e,e.cutAll(E(n),a))}finally{a.delete()}}function Qe(e,t,n,r){let i=Ie(t,r.map(E));try{return D(e,e.split(E(n),i))}finally{i.delete()}}function $e(e,t,n,r){let i=[];return e.isNull(E(t))&&i.push({operand:`base`,issue:`null-shape`,message:`Base shape is null`}),e.isNull(E(n))&&i.push({operand:`tool`,issue:`null-shape`,message:`Tool shape is null`}),i.length===0&&!e.isValid(E(t))&&i.push({operand:`base`,issue:`not-valid`,message:`Base shape is not valid`}),i.length===0&&!e.isValid(E(n))&&i.push({operand:`tool`,issue:`not-valid`,message:`Tool shape is not valid`}),{valid:i.length===0,issues:i}}function et(e,t,n,r,i,a){throw Error(`occt-wasm: meshBoolean is not supported (use brepkit for mesh booleans)`)}function tt(e,t,n){return n!==t&&e.release(t),n}function nt(e,t,n,r){return T(`solid`,e.makeBox(t,n,r))}function rt(e,t,n,r,i){let a=e.makeCylinder(t,n);return i&&(a=tt(e,a,He(e,a,i))),r&&(r[0]!==0||r[1]!==0||r[2]!==0)&&(a=tt(e,a,e.translate(a,r[0],r[1],r[2]))),T(`solid`,a)}function it(e,t,n){let r=e.makeSphere(t);return n&&(n[0]!==0||n[1]!==0||n[2]!==0)&&(r=tt(e,r,e.translate(r,n[0],n[1],n[2]))),T(`solid`,r)}function at(e,t,n,r,i,a){let o=e.makeCone(t,n,r);return a&&(o=tt(e,o,He(e,o,a))),i&&(i[0]!==0||i[1]!==0||i[2]!==0)&&(o=tt(e,o,e.translate(o,i[0],i[1],i[2]))),T(`solid`,o)}function ot(e,t,n,r,i){let a=e.makeTorus(t,n);return i&&(a=tt(e,a,He(e,a,i))),r&&(r[0]!==0||r[1]!==0||r[2]!==0)&&(a=tt(e,a,e.translate(a,r[0],r[1],r[2]))),T(`solid`,a)}function st(e,t,n,r){return T(`solid`,e.makeEllipsoid(t,n,r))}function ct(e,t,n){return T(`solid`,e.makeBoxFromCorners(t[0],t[1],t[2],n[0],n[1],n[2]))}function lt(e,t,n){return T(`face`,e.makeRectangle(t,n))}function ut(e,t,n){let r=e.getSubShapes(E(t),n),i=[];try{let e=r.size();for(let t=0;t<e;t++)i.push(T(n,r.get(t)))}finally{r.delete()}return i}function dt(e,t){return Pe(t)?t.type:Fe(e.getShapeType(E(t)))}function ft(e,t,n){return e.isSame(E(t),E(n))}function pt(e,t,n){return e.isEqual(E(t),E(n))}function mt(e,t,n){return n?T(n,e.downcast(E(t),n)):t}function ht(e,t){return D(e,e.copy(E(t)))}function gt(e,t,n){return e.hashCode(E(t),n)}function _t(e,t){return e.isNull(E(t))}function vt(e,t){return e.shapeOrientation(E(t)).toLowerCase()}function yt(e,n){let r=e.edgeToFaceMap(E(n),1e6),i;try{i=ze(r)}finally{r.delete()}let a={};for(let e=0;e+1<i.length;e+=2){let n=t(i,e),r=t(i,e+1);a[n]||(a[n]=[]),a[n].push(r)}return JSON.stringify(a)}function bt(e,t,n){return e.subShapeCount(E(t),n)}function xt(e,t,n,r){let i=e.subShapeHashes(E(t),n,r);try{return ze(i)}finally{i.delete()}}function St(e,t,n){let r=e.sharedEdges(E(t),E(n)),i=[];try{let e=r.size();for(let t=0;t<e;t++)i.push(T(`edge`,r.get(t)))}finally{r.delete()}return i}function Ct(e,t,n){let r=e.adjacentFaces(E(t),E(n)),i=[];try{let e=r.size();for(let t=0;t<e;t++)i.push(T(`face`,r.get(t)))}finally{r.delete()}return i}function wt(e,t,n,r){let i=Ie(t,n.map(E));try{return D(e,e.sew(i,r??1e-6))}finally{i.delete()}}var Tt=1e-6;function Et(e,t){return e.isValid(E(t))}function Dt(e,t){let n=e.healSolid(E(t),Tt);return n===0?null:D(e,n)}function Ot(e,t){return D(e,e.healFace(E(t),Tt))}function kt(e,t,n){return D(e,e.healWire(E(t),Tt))}function At(e,t,n){return 0}function jt(e,t,n){return e.removeDegenerateEdges(E(t)),0}function Mt(e,t){return e.fixFaceOrientations(E(t)),0}function Nt(e,t){return D(e,e.fixShape(E(t)))}function Pt(e,t,n,r){let i=e.tessellate(E(n),r.tolerance,r.angularTolerance);try{let e=i.positionCount,n=i.normalCount,a=i.indexCount,o=i.getPositionsPtr()>>2,s=i.getNormalsPtr()>>2,c=i.getIndicesPtr()>>2,l=new Float32Array(e);for(let n=0;n<e;n++)l[n]=t.HEAPF32[o+n]??0;let u=new Float32Array(n);if(!r.skipNormals)for(let e=0;e<n;e++)u[e]=t.HEAPF32[s+e]??0;let d=i.uvCount,f=new Float32Array(r.includeUVs?d:0);if(r.includeUVs&&d>0){let e=i.getUvsPtr()>>2;for(let n=0;n<d;n++)f[n]=t.HEAPF32[e+n]??0}let p=new Uint32Array(a);for(let e=0;e<a;e++)p[e]=t.HEAPU32[c+e]??0;let m=[],h=i.faceGroupCount;if(h>0){let e=i.getFaceGroupsPtr()>>2;for(let n=0;n<h;n+=3)m.push({start:t.HEAP32[e+n]??0,count:t.HEAP32[e+n+1]??0,faceHash:t.HEAP32[e+n+2]??0})}return{vertices:l,normals:r.skipNormals?new Float32Array:u,triangles:p,uvs:f,faceGroups:m}}finally{i.delete()}}function Ft(e,t,n,r){for(let i=0;i+1<n;i++){let n=t+i*3,a=e[n]??0,o=e[n+1]??0,s=e[n+2]??0,c=e[n+3]??0,l=e[n+4]??0,u=e[n+5]??0;a===c&&o===l&&s===u||r.push(a,o,s,c,l,u)}}function It(e,t,n,r,i){let a=e.wireframe(E(n),r);try{let e=t.HEAPF32,n=a.getPointsPtr()>>2,r=[],i=[],o=a.edgeGroupCount,s=o>0?a.getEdgeGroupsPtr()>>2:0;for(let a=0;a<o;a+=3){let o=n+(t.HEAP32[s+a]??0),c=Math.floor((t.HEAP32[s+a+1]??0)/3),l=r.length/3;Ft(e,o,c,r),i.push({start:l,count:r.length/3-l,edgeHash:t.HEAP32[s+a+2]??0})}return{lines:new Float32Array(r),edgeGroups:i}}finally{a.delete()}}function Lt(e,t){return e.hasTriangulation(E(t))}function Rt(e,t,n,r){e.meshShape(E(t),n,r).delete()}var zt={line:`LINE`,circle:`CIRCLE`,ellipse:`ELLIPSE`,hyperbola:`HYPERBOLA`,parabola:`PARABOLA`,bezier:`BEZIER_CURVE`,bspline:`BSPLINE_CURVE`,offset:`OFFSET_CURVE`,other:`OTHER_CURVE`};function Bt(e,t){let n=e.curveType(E(t));return zt[n]??n.toUpperCase()}function Vt(e,t){let n=e.curveParameters(E(t));try{return[n.get(0),n.get(1)]}finally{n.delete()}}function Ht(e,t,n){let r=e.curvePointAtParam(E(t),n);try{return[r.get(0),r.get(1),r.get(2)]}finally{r.delete()}}function Ut(e,t,n){let r=e.curveTangent(E(t),n);try{let i=e.curvePointAtParam(E(t),n);try{return{point:[i.get(0),i.get(1),i.get(2)],tangent:[r.get(0),r.get(1),r.get(2)]}}finally{i.delete()}}finally{r.delete()}}function Wt(e,t){return e.curveIsClosed(E(t))}function Gt(e,t){return e.curveIsPeriodic(E(t))}function Kt(e,t){return 2*Math.PI}function qt(e,t,n,r){let i=[];for(let e of n)i.push(e[0],e[1],e[2]);let a=Re(t,i);try{return T(`edge`,e.interpolatePoints(a,r?.periodic??!1))}finally{a.delete()}}function Jt(e,t,n,r){let i=[];for(let e of n)i.push(e[0],e[1],e[2]);let a=Re(t,i);try{return T(`edge`,e.approximatePoints(a,r?.tolerance??.001))}finally{a.delete()}}function Yt(e,t,n){return T(`edge`,e.curveDegreeElevate(E(t),n))}function Xt(e,t,n,r){return T(`edge`,e.curveKnotInsert(E(t),n,r))}function Zt(e,t,n,r){return T(`edge`,e.curveKnotRemove(E(t),n,r))}function Qt(e,t,n){let r=e.curveSplit(E(t),n);try{return[T(`edge`,r.get(0)),T(`edge`,r.get(1))]}finally{r.delete()}}function $t(e,t){let n=en(e,t);if(!n||n.poles.length<2)return null;let r=n.poles[n.poles.length-2];return r?[r[0],r[1],r[2]]:null}function en(e,t){try{let n=e.getNurbsCurveData(E(t));try{let e=n.poles.size()/3,t=[];for(let r=0;r<e;r++)t.push([n.poles.get(r*3),n.poles.get(r*3+1),n.poles.get(r*3+2)]);let r=[];for(let e=0;e<n.knots.size();e++)r.push(n.knots.get(e));let i=[];for(let e=0;e<n.multiplicities.size();e++)i.push(n.multiplicities.get(e));let a=[];if(n.rational)for(let e=0;e<n.weights.size();e++)a.push(n.weights.get(e));else for(let t=0;t<e;t++)a.push(1);return{degree:n.degree,poles:t,weights:a,knots:r,multiplicities:i,isPeriodic:n.periodic,isRational:n.rational}}finally{n.delete()}}catch{return null}}function tn(e,t){let n=e.vertexPosition(E(t));try{return[n.get(0),n.get(1),n.get(2)]}finally{n.delete()}}function nn(e,t){return e.surfaceType(E(t)).toLowerCase()}function rn(e,t){let n=e.uvBounds(E(t));try{return{uMin:n.get(0),uMax:n.get(1),vMin:n.get(2),vMax:n.get(3)}}finally{n.delete()}}function an(e,t){return T(`wire`,e.outerWire(E(t)))}function on(e,t){return T(`face`,e.reverseSurfaceU(E(t)))}function sn(e,t,n,r){let i=e.surfaceNormal(E(t),n,r);try{return[i.get(0),i.get(1),i.get(2)]}finally{i.delete()}}function cn(e,t,n,r){let i=e.pointOnSurface(E(t),n,r);try{return[i.get(0),i.get(1),i.get(2)]}finally{i.delete()}}var ln=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],un=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dn=e=>Math.hypot(e[0],e[1],e[2]),fn=(e,t)=>[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 pn(e,t){if(nn(e,t)!==`cylinder`)return null;let n=rn(e,t),r=.5*(n.vMin+n.vMax),i=n.uMin+.25*(n.uMax-n.uMin),a=n.uMin+.5*(n.uMax-n.uMin),o=sn(e,t,i,r),s=sn(e,t,a,r),c=cn(e,t,i,r),l=cn(e,t,a,r),u=fn(o,s),d=dn(u),f=dn(ln(o,s));if(d<1e-9||f<1e-9)return null;let p=[u[0]/d,u[1]/d,u[2]/d],m=dn(ln(c,l))/f,h=[c[0]-m*o[0],c[1]-m*o[1],c[2]-m*o[2]],g=dn(ln(h,[l[0]-m*s[0],l[1]-m*s[1],l[2]-m*s[2]]))<1e-6?h:[c[0]+m*o[0],c[1]+m*o[1],c[2]+m*o[2]];return{origin:g,direction:p,radius:m,isDirect:(vt(e,t)===`reversed`?-1:1)*un(o,ln(c,g))>0}}function mn(e,t,n){let r=ln(t,e),i=ln(n,e),a=fn(r,i),o=un(a,a);if(o<1e-18)return null;let s=un(r,r),c=un(i,i),l=fn([s*i[0]-c*r[0],s*i[1]-c*r[1],s*i[2]-c*r[2]],a),u=1/(2*o);return[e[0]+l[0]*u,e[1]+l[1]*u,e[2]+l[2]*u]}function hn(e,t,n,r,i){return mn(cn(e,t,n+.1*(r-n),i),cn(e,t,n+.45*(r-n),i),cn(e,t,n+.8*(r-n),i))}function gn(e,t){let n=rn(e,t),r=[.2,.5,.8].map(r=>hn(e,t,n.uMin,n.uMax,n.vMin+r*(n.vMax-n.vMin))).filter(e=>e!==null);if(r.length<2)return null;let i=null,a=1e-9;for(let e=0;e<r.length;e++)for(let t=e+1;t<r.length;t++){let n=r[e],o=r[t];if(!n||!o)continue;let s=ln(o,n),c=dn(s);c>a&&(a=c,i={origin:n,direction:[s[0]/c,s[1]/c,s[2]/c]})}return i}function _n(e,t){let n=nn(e,t);if(n===`cylinder`){let n=pn(e,t);return n?{origin:n.origin,direction:n.direction}:null}return n===`cone`||n===`torus`||n===`revolution`?gn(e,t):null}function vn(e,t){let n=e.getFaceCylinderData(E(t));try{return n.size()<2?null:{radius:n.get(0),isDirect:n.get(1)===1}}finally{n.delete()}}function yn(e,t,n){let r=e.uvFromPoint(E(t),n[0],n[1],n[2]);try{return r.size()<2?null:[r.get(0),r.get(1)]}finally{r.delete()}}function bn(e,t,n){let r=e.projectPointOnFace(E(t),n[0],n[1],n[2]);try{return[r.get(0),r.get(1),r.get(2)]}finally{r.delete()}}function xn(e,t,n,r,i){return e.classifyPointOnFace(E(t),n,r).toLowerCase()}function Sn(e,t,n,r,i,a){let[o,s,c]=r,[l,u,d]=i,f=!!a,[p,m,h]=a??[1,0,0],g=e.projectEdges(E(n),o,s,c,l,u,d,p,m,h,f),_=n=>n===0?T(`compound`,e.makeCompound(new t.VectorUint32)):T(`compound`,n);return{visible:{outline:_(g.visibleOutline),smooth:_(g.visibleSmooth),sharp:_(g.visibleSharp)},hidden:{outline:_(g.hiddenOutline),smooth:_(g.hiddenSmooth),sharp:_(g.hiddenSharp)}}}function Cn(e,t){return e.getVolume(E(t))}function wn(e,t){return e.getSurfaceArea(E(t))}function Tn(e,t){return e.getLength(E(t))}function En(e,t){let n=e.getCenterOfMass(E(t));try{return[n.get(0),n.get(1),n.get(2)]}finally{n.delete()}}function Dn(e,t){let n=e.getLinearCenterOfMass(E(t));try{return[n.get(0),n.get(1),n.get(2)]}finally{n.delete()}}function On(e,t){let n=e.getBoundingBox(E(t),!0);return{min:[n.xmin,n.ymin,n.zmin],max:[n.xmax,n.ymax,n.zmax]}}function kn(e,t){try{let n=e.getSurfaceCenterOfMass(E(t));try{return[n.get(0),n.get(1),n.get(2)]}finally{n.delete()}}catch{return[0,0,0]}}function An(e,t,n){return{volume:Cn(e,t),area:wn(e,t),length:n?Tn(e,t):0,centerOfMass:En(e,t),boundingBox:On(e,t)}}function jn(e,t){let n=E(t);return{distanceTo(t){return{value:e.distanceBetween(n,E(t)),point1:[0,0,0],point2:[0,0,0]}},dispose:Ne}}var Mn=256;function Nn(e,t,n){let r=[],i=e.getSubShapes(n,`vertex`);try{let t=i.size();for(let n=0;n<t;n++){let t=e.vertexPosition(i.get(n));r.push([t.get(0),t.get(1),t.get(2)]),t.delete()}}finally{i.delete()}let a=e.getBoundingBox(n,!0),o=Math.sqrt((a.xmax-a.xmin)**2+(a.ymax-a.ymin)**2+(a.zmax-a.zmin)**2),s=Math.max(o*.01,1e-4),c;try{c=e.tessellate(n,s,.5)}catch{return r}try{let e=c.positionCount;if(e>0){let n=c.getPositionsPtr()>>2,i=t.HEAPF32,a=Math.floor(e/3),o=(a>Mn?Math.ceil(a/Mn):1)*3;for(let t=0;t<e;t+=o)r.push([i[n+t]??0,i[n+t+1]??0,i[n+t+2]??0])}}finally{c.delete()}return r}function Pn(e,t,n,r){let i=E(n),a=E(r),o=e.distanceBetween(i,a),s=Nn(e,t,i),c=Nn(e,t,a);if(s.length===0||c.length===0)return{value:o,point1:[0,0,0],point2:[0,0,0]};let l=1/0,u=s[0]??[0,0,0],d=c[0]??[0,0,0];for(let e of s)for(let t of c){let n=t[0]-e[0],r=t[1]-e[1],i=t[2]-e[2],a=n*n+r*r+i*i;a<l&&(l=a,u=e,d=t)}return{value:o,point1:u,point2:d}}function Fn(e,t,n,r){let i=e.pointOnSurface(t,n,r),a=[i.get(0),i.get(1),i.get(2)];return i.delete(),a}function In(e,t,n,r){let i=e.uvBounds(t),a=i.get(0),o=i.get(1),s=i.get(2),c=i.get(3);i.delete();let l=Math.max(Math.max(o-a,1e-12)*.001,1e-6),u=Math.max(Math.max(c-s,1e-12)*.001,1e-6),d=Math.min(Math.max(n,a+l),o-l),f=Math.min(Math.max(r,s+u),c-u),p=Fn(e,t,d,f),m=Fn(e,t,d+l,f),h=Fn(e,t,d-l,f),g=Fn(e,t,d,f+u),_=Fn(e,t,d,f-u),v=Fn(e,t,d+l,f+u),y=Fn(e,t,d+l,f-u),b=Fn(e,t,d-l,f+u),x=Fn(e,t,d-l,f-u),S=l*l,C=u*u,w=4*l*u;return{Pu:[(m[0]-h[0])/(2*l),(m[1]-h[1])/(2*l),(m[2]-h[2])/(2*l)],Pv:[(g[0]-_[0])/(2*u),(g[1]-_[1])/(2*u),(g[2]-_[2])/(2*u)],Puu:[(m[0]-2*p[0]+h[0])/S,(m[1]-2*p[1]+h[1])/S,(m[2]-2*p[2]+h[2])/S],Pvv:[(g[0]-2*p[0]+_[0])/C,(g[1]-2*p[1]+_[1])/C,(g[2]-2*p[2]+_[2])/C],Puv:[(v[0]-y[0]-b[0]+x[0])/w,(v[1]-y[1]-b[1]+x[1])/w,(v[2]-y[2]-b[2]+x[2])/w]}}function Ln(e,t,n,r){return Math.abs(e)+Math.abs(t)>=Math.abs(n)+Math.abs(r)?Math.abs(e)+Math.abs(t)<1e-12?[1,0]:[-t,e]:Math.abs(n)+Math.abs(r)<1e-12?[0,1]:[-r,n]}function Rn(e,t,n){let r=e[0]*t[0]+e[1]*n[0],i=e[0]*t[1]+e[1]*n[1],a=e[0]*t[2]+e[1]*n[2],o=Math.sqrt(r*r+i*i+a*a);return o<1e-12?[1,0,0]:[r/o,i/o,a/o]}function zn(e,t){let n=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(n<1e-12)return{maxDirection:[1,0,0],minDirection:[0,1,0]};let r=e[0]/n,i=e[1]/n,a=e[2]/n,o=r*t[0]+i*t[1]+a*t[2],s=t[0]-o*r,c=t[1]-o*i,l=t[2]-o*a,u=Math.sqrt(s*s+c*c+l*l);if(u<1e-12){let e=Math.abs(r)<.9?[1,0,0]:[0,1,0],t=i*e[2]-a*e[1],n=a*e[0]-r*e[2],o=r*e[1]-i*e[0],s=Math.sqrt(t*t+n*n+o*o)||1;return{maxDirection:[r,i,a],minDirection:[t/s,n/s,o/s]}}return{maxDirection:[r,i,a],minDirection:[s/u,c/u,l/u]}}function Bn(e,t,n,r,i,a){let{Pu:o,Pv:s,Puu:c,Pvv:l,Puv:u}=In(e,t,n,r),d=o[1]*s[2]-o[2]*s[1],f=o[2]*s[0]-o[0]*s[2],p=o[0]*s[1]-o[1]*s[0],m=Math.sqrt(d*d+f*f+p*p),h=o[0]*o[0]+o[1]*o[1]+o[2]*o[2],g=o[0]*s[0]+o[1]*s[1]+o[2]*s[2],_=s[0]*s[0]+s[1]*s[1]+s[2]*s[2];if(m<1e-12||h*_-g*g<1e-24)return zn(o,s);let v=(c[0]*d+c[1]*f+c[2]*p)/m,y=(u[0]*d+u[1]*f+u[2]*p)/m,b=(l[0]*d+l[1]*f+l[2]*p)/m,x=h*_-g*g,S=(v*_-y*g)/x,C=(y*_-b*g)/x,w=(y*h-v*g)/x,ee=(b*h-y*g)/x;if(Math.abs(i-a)<1e-9*(Math.abs(i)+Math.abs(a)+1))return zn(o,s);let te=Ln(S-i,C,w,ee-i),ne=Ln(S-a,C,w,ee-a);return{maxDirection:Rn(te,o,s),minDirection:Rn(ne,o,s)}}function Vn(e,t,n,r){let i=E(t),a=e.surfaceCurvature(i,n,r),o=a.get(0),s=a.get(1),c=a.get(2),l=a.get(3);a.delete();let{maxDirection:u,minDirection:d}=Bn(e,i,n,r,c,l);return{gaussian:s,mean:o,max:c,min:l,maxDirection:u,minDirection:d}}var Hn=2147483647;function Un(e,t,n,r,i){let a=Ve(r,i),o=Ie(t,r.map(E));try{return D(e,e.fillet(E(n),o,a))}finally{o.delete()}}function Wn(e,t,n,r,i){let a=Ve(r,i),o=Ie(t,r.map(E));try{return D(e,e.chamfer(E(n),o,a))}finally{o.delete()}}function Gn(e,t,n,r,i,a){let o=Ie(t,r.map(E));try{return D(e,e.chamferDistAngle(E(n),o,i,a))}finally{o.delete()}}function Kn(e,t,n,r,i,a){let o=Ie(t,r.map(E));try{return D(e,e.shell(E(n),o,i,a??.001))}finally{o.delete()}}function qn(e,t,n){return D(e,e.thicken(E(t),n,.001))}function Jn(e,t,n,r){return D(e,e.offset(E(t),n,r??1e-6))}function Yn(e,t,n,r,i){let a=e.filletVariable(t,n,r,i),o=!0;try{let t=e.getSubShapes(a,`solid`);try{let n=t.size()===1?t.get(0):-1;for(let r=0,i=t.size();r<i;r++){let i=t.get(r);i!==n&&e.release(i)}return n===-1?(o=!1,D(e,a)):D(e,n)}finally{t.delete()}}finally{o&&e.release(a)}}function Xn(e,t,n){let r=JSON.parse(n);if(r.edgeId!==void 0&&r.startRadius!==void 0&&r.endRadius!==void 0)return Yn(e,E(t),r.edgeId,r.startRadius,r.endRadius);if(r.edge!==void 0&&Array.isArray(r.radii)&&r.radii.length>0){let n=r.radii;if(n.length>2)throw new c(`occt-wasm: filletVariable supports only a linear (<=2-point) radius profile; a multi-point variable radius requires the brepkit kernel`);let i=n[0].radius,a=n[n.length-1].radius,o=E(t),s=e.getSubShapes(o,`edge`),l=-1;try{for(let t=0,n=s.size();t<n;t++){let n=s.get(t);if(e.hashCode(n,Hn)===r.edge){l=n;break}}}finally{for(let t=0,n=s.size();t<n;t++){let n=s.get(t);n!==l&&e.release(n)}s.delete()}if(l===-1)throw new c(`occt-wasm: filletVariable: target edge not found on the shape`);try{return Yn(e,o,l,i,a)}finally{e.release(l)}}throw new c(`occt-wasm: filletVariable: unrecognized spec`)}function Zn(e,t,n,r,i,a){let o=E(t);for(let t of n){let n=(typeof a==`function`?a(t):a)*Math.PI/180;o=e.draft(o,E(t),n,r[0],r[1],r[2])}return D(e,o)}function Qn(e,t,n,r){let i=Ie(t,r.map(E));try{return D(e,e.defeature(E(n),i,.001))}finally{i.delete()}}function $n(e,t,n,r){let i=0;return r===`intersection`||r===1?i=1:r===`tangent`||r===2?i=2:typeof r==`number`&&(i=r),D(e,e.offsetWire2D(E(t),n,i))}function er(e,t){return D(e,e.simplify(E(t)))}function tr(e,t){return D(e,e.reverseShape(E(t)))}function nr(e,t,n,r){let i=n[0]*r,a=n[1]*r,o=n[2]*r;return D(e,e.extrude(E(t),i,a,o))}function rr(e,t,n,r){let i=n.origin,a=n.direction;return D(e,e.revolve(E(t),i.x,i.y,i.z,a.x,a.y,a.z,r))}function ir(e,t,n,r,i,a){let o=i?E(i):0,s=a?E(a):0,c=Ie(t,n.map(E));try{return o||s?D(e,e.loftWithVertices(c,!0,r??!1,o,s)):D(e,e.loft(c,!0,r??!1))}finally{c.delete()}}function ar(e,t,n,r){let i=r?.transitionMode??0;return D(e,e.sweep(E(t),E(n),i))}function or(e,t,n){return D(e,e.simplePipe(E(t),E(n)))}function sr(e,t,n,r){let i=r?.frenet??!1,a=r?.transitionMode===`round`,o=r?.shellMode??!1,s=D(e,e.sweepPipeShell(E(t),E(n),i,a));if(o){let t=e.getSubShapes(E(s),`wire`);try{return{shape:s,firstShape:t.size()>0?D(e,t.get(0)):s,lastShape:t.size()>1?D(e,t.get(t.size()-1)):s}}finally{t.delete()}}return s}function cr(e,t,n,r){let i=r?.solid??!0,a=r?.ruled??!1,o=r?.startVertex?E(r.startVertex):0,s=r?.endVertex?E(r.endVertex):0,c=Ie(t,n.map(E));try{return o||s?D(e,e.loftWithVertices(c,i,a,o,s)):D(e,e.loft(c,i,a))}finally{c.delete()}}function lr(e,t,n,r){let i={__occtWasmLaw:!0,profile:t,length:n,endFactor:r,Trim(e,t,n){return{...i,trimFirst:e,trimLast:t}},delete(){}};return i}function ur(e,t,n,r,i){return D(e,e.revolveVec(E(t),n[0],n[1],n[2],r[0],r[1],r[2],i))}function dr(e,t,n,r,i,a,o){let s=i??10;return D(e,e.draftPrism(E(t),0,0,s,a))}function fr(e){let t=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];for(let n of e)if(n.type===`translate`)t=Be([1,0,0,n.x,0,1,0,n.y,0,0,1,n.z,0,0,0,1],t);else{let e=n.axis??[0,0,1],r=n.center??[0,0,0],i=n.angle*Math.PI/180,a=Math.cos(i),o=Math.sin(i),s=1-a,c=Math.sqrt(e[0]**2+e[1]**2+e[2]**2),[l,u,d]=[e[0]/c,e[1]/c,e[2]/c],f=s*l*l+a,p=s*l*u-o*d,m=s*l*d+o*u,h=s*u*l+o*d,g=s*u*u+a,_=s*u*d-o*l,v=s*d*l-o*u,y=s*d*u+o*l,b=s*d*d+a;t=Be([f,p,m,r[0]-(f*r[0]+p*r[1]+m*r[2]),h,g,_,r[1]-(h*r[0]+g*r[1]+_*r[2]),v,y,b,r[2]-(v*r[0]+y*r[1]+b*r[2]),0,0,0,1],t)}return{handle:{__type:`transform_matrix`,matrix:t,delete:Ne},dispose:Ne}}function pr(e){let t=e,n;return Array.isArray(t)?n=t:typeof t==`object`&&t&&(Array.isArray(t.matrix)?n=t.matrix:Array.isArray(t.elements)&&(n=t.elements)),n&&n.length===16&&(n=n.slice(0,12)),n&&n.length>=12?n:void 0}function mr(e,t,n,r){let i=pr(r);if(i){let r=Re(t,i);try{return D(e,e.transform(E(n),r))}finally{r.delete()}}return T(e.getShapeType(E(n)),e.copy(E(n)))}function hr(e,t,n,r){if(typeof e.located==`function`){let i=pr(r);if(i){let r=Re(t,i);try{return D(e,e.located(E(n),r))}finally{r.delete()}}}return mr(e,t,n,r)}function gr(e,t,n,r,i){return D(e,e.translate(E(t),n,r,i))}function _r(e,t,n,r,i){let a=r??[0,0,1],o=i??[0,0,0];return D(e,e.rotate(E(t),o[0],o[1],o[2],a[0],a[1],a[2],n))}function vr(e,t,n,r){return D(e,e.mirror(E(t),n[0],n[1],n[2],r[0],r[1],r[2]))}function yr(e,t,n,r){return D(e,e.scale(E(t),n[0],n[1],n[2],r))}function br(e,t,n,r,i,a){let o=Re(t,[r[0],r[1],r[2],i[0],r[3],r[4],r[5],i[1],r[6],r[7],r[8],i[2]]);try{return D(e,e.generalTransform(E(n),o))}finally{o.delete()}}function xr(e,t,n,r,i){let a=e.curvePointAtParam(E(r),i),[o,s,c]=(()=>{try{return[a.get(0),a.get(1),a.get(2)]}finally{a.delete()}})(),l=e.curveTangent(E(r),i),[u,d,f]=(()=>{try{return[l.get(0),l.get(1),l.get(2)]}finally{l.delete()}})(),p,m,h;Math.abs(u)<.9?(p=0,m=f,h=-d):(p=-f,m=0,h=u);let g=Math.sqrt(p*p+m*m+h*h);p/=g,m/=g,h/=g;let _=d*h-f*m,v=f*p-u*h,y=u*m-d*p,b=new t.VectorDouble;b.push_back(p),b.push_back(_),b.push_back(u),b.push_back(o),b.push_back(m),b.push_back(v),b.push_back(d),b.push_back(s),b.push_back(h),b.push_back(y),b.push_back(f),b.push_back(c);try{return D(e,e.transform(E(n),b))}finally{b.delete()}}function Sr(e,t,n,r,i){let a=e.linearPattern(E(t),n[0],n[1],n[2],r,i),o=e.getSubShapes(a,`solid`),s=[];try{let e=o.size();for(let t=0;t<e;t++)s.push(T(`solid`,o.get(t)))}finally{o.delete()}if(s.length===0){let t=e.iterShapes(a);try{let n=t.size();for(let r=0;r<n;r++)s.push(D(e,t.get(r)))}finally{t.delete()}}return e.release(a),s}function Cr(e,t,n,r,i,a){let o=e.circularPattern(E(t),n[0],n[1],n[2],r[0],r[1],r[2],i,a),s=e.getSubShapes(o,`solid`),c=[];try{let e=s.size();for(let t=0;t<e;t++)c.push(T(`solid`,s.get(t)))}finally{s.delete()}if(c.length===0){let t=e.iterShapes(o);try{let n=t.size();for(let r=0;r<n;r++)c.push(D(e,t.get(r)))}finally{t.delete()}}return e.release(o),c}function wr(e,t){return t.map(t=>{switch(t.type){case`translate`:return gr(e,t.shape,t.x,t.y,t.z);case`rotate`:return _r(e,t.shape,t.angle,t.axis,t.center);case`scale`:return yr(e,t.shape,t.center,t.factor);case`mirror`:return vr(e,t.shape,t.origin,t.normal);default:throw Error(`occt-wasm: transformBatch unknown type`)}})}function Tr(e,t){if(t===0)return{min:[0,0,0],max:[0,0,0]};let n=1/0,r=1/0,i=1/0,a=-1/0,o=-1/0,s=-1/0;for(let c=0;c<t;c++){let t=c*3,l=e[t]??0,u=e[t+1]??0,d=e[t+2]??0;l<n&&(n=l),u<r&&(r=u),d<i&&(i=d),l>a&&(a=l),u>o&&(o=u),d>s&&(s=d)}return{min:[n,r,i],max:[a,o,s]}}function Er(e,t,n,r,i,a,o,s){return{asset:{version:`2.0`,generator:`brepjs occt-wasm`},scene:0,scenes:[{nodes:[0]}],nodes:[{mesh:0}],meshes:[{primitives:[{attributes:{POSITION:0,NORMAL:1},indices:2,mode:4}]}],buffers:[{byteLength:o}],bufferViews:[{buffer:0,byteOffset:0,byteLength:r,target:34962},{buffer:0,byteOffset:r,byteLength:i,target:34962},{buffer:0,byteOffset:r+i,byteLength:a,target:34963}],accessors:[{bufferView:0,componentType:5126,count:e,type:`VEC3`,min:s.min,max:s.max},{bufferView:1,componentType:5126,count:t,type:`VEC3`},{bufferView:2,componentType:5125,count:n,type:`SCALAR`}]}}function Dr(e,t,n){if(n.length===1)return e.exportStep(E(n[0]));let r=t(n);return e.exportStep(E(r))}function Or(e,t,n,r=De,i=Oe){let{vertices:a,triangles:o}=e(t,{tolerance:r,angularTolerance:i,skipNormals:!0});return n?je(a,o):Me(a,o)}function kr(e,t){let n=typeof t==`string`?t:new TextDecoder().decode(t);return[D(e,e.importStep(n))]}function Ar(e,t,n){let r=typeof n==`string`?new TextEncoder().encode(n):new Uint8Array(n),i=t;if(i.FS)i.FS.writeFile(`/tmp/import.stl`,r);else{let t=Array.from(r,e=>String.fromCharCode(e)).join(``);return D(e,e.importStl(t))}return D(e,e.importStl(``))}function jr(e,t,n){if(n.length===1)return e.exportIges(E(n[0]));let r=t(n);return e.exportIges(E(r))}function Mr(e,t){let n=typeof t==`string`?t:new TextDecoder().decode(t);return[D(e,e.importIges(n))]}function Nr(e,t,n,r){if(n.length===0)return``;let i=zr(e,t,n);try{return Br(e,i)}finally{i.delete()}}function Pr(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=a.length/3,l=o.length,u=i.byteLength,d=a.byteLength,f=o.byteLength,p=u+d+f,m=p+(4-p%4)%4,h=Er(s,c,l,u,d,f,m,Tr(i,s)),g=new TextEncoder().encode(JSON.stringify(h)),_=g.byteLength+(4-g.byteLength%4)%4,v=20+_+8+m,y=new ArrayBuffer(v),b=new DataView(y);b.setUint32(0,1179937895,!0),b.setUint32(4,2,!0),b.setUint32(8,v,!0),b.setUint32(12,_,!0),b.setUint32(16,1313821514,!0);let x=new Uint8Array(y,20,_);x.set(g);for(let e=g.byteLength;e<_;e++)x[e]=32;let S=20+_;b.setUint32(S,m,!0),b.setUint32(S+4,5130562,!0);let C=S+8;return new Uint8Array(y,C,u).set(new Uint8Array(i.buffer,i.byteOffset,u)),new Uint8Array(y,C+u,d).set(new Uint8Array(a.buffer,a.byteOffset,d)),new Uint8Array(y,C+u+d,f).set(new Uint8Array(o.buffer,o.byteOffset,f)),y}function Fr(e,t,n){let r=e(t,{tolerance:n,angularTolerance:.5,skipNormals:!1}),i=r.vertices,a=r.normals,o=r.triangles,s=[`# brepjs OBJ export`],c=i.length/3;for(let e=0;e<c;e++){let t=e*3;s.push(`v ${i[t]??0} ${i[t+1]??0} ${i[t+2]??0}`)}let l=a.length/3;for(let e=0;e<l;e++){let t=e*3;s.push(`vn ${a[t]??0} ${a[t+1]??0} ${a[t+2]??0}`)}let u=e=>{let t=(o[e]??0)+1,n=(o[e+1]??0)+1,r=(o[e+2]??0)+1;s.push(`f ${t}//${t} ${n}//${n} ${r}//${r}`)};if(r.faceGroups.length>0)for(let e of r.faceGroups){s.push(`g face_${e.faceHash}`);let t=e.count/3;for(let n=0;n<t;n++)u(e.start+n*3)}else{let e=o.length/3;for(let t=0;t<e;t++)u(t*3)}return new TextEncoder().encode(s.join(`
|
|
4
|
+
`)+`
|
|
5
|
+
`).buffer}function Ir(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
|
+
`)+`
|
|
7
|
+
`).buffer}function Lr(e,t){return e.toBREP(E(t))}function Rr(e,t){return D(e,e.fromBREP(t))}function zr(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 Br(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 Vr(e,t,n,r){if(n.length===0)return``;let i=zr(e,t,n.map(e=>({shape:e.shape,name:e.name??``,color:e.color})));try{return Br(e,i)}finally{i.delete()}}function Hr(e,t,n,r){return T(`vertex`,e.makeVertex(t,n,r))}function Ur(e,t){throw Pe(t)?Error(`occt-wasm: makeEdge from curve handle is not implemented`):Error(`occt-wasm: makeEdge is not implemented`)}function Wr(e,t,n){let r=Ie(t,n.map(E));try{return T(`wire`,e.makeWire(r))}finally{r.delete()}}function Gr(e,t,n){let r=[],i=new Set(n.map(e=>E(e)));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 a=Ie(t,r);try{return T(`wire`,e.makeWire(a))}finally{a.delete();for(let t of r)i.has(t)||e.release(t)}}function Kr(e,t,n){return T(`face`,e.makeFace(E(t)))}function qr(e,t,n){return T(`edge`,e.makeLineEdge(t[0],t[1],t[2],n[0],n[1],n[2]))}function Jr(e,t,n,r){return T(`edge`,e.makeCircleEdge(t[0],t[1],t[2],n[0],n[1],n[2],r))}function Yr(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 Xr(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 Zr(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 Qr(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 $r(e,t,n){let r=[];for(let e of n)r.push(e[0],e[1],e[2]);let i=Re(t,r);try{return T(`edge`,e.makeBezierEdge(i))}finally{i.delete()}}function ei(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 ti(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 ni(e,t,n){let r=Ie(t,n.map(E));try{return T(`compound`,e.makeCompound(r))}finally{r.delete()}}function ri(e,t){return T(`solid`,e.solidFromShell(E(t)))}function ii(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=Ie(t,a);try{let t=e.sewAndSolidify(o,i),n=e.fixFaceOrientations(t);return n!==t&&e.release(t),D(e,n)}finally{o.delete();for(let t of a)e.release(t)}}function ai(e,t){return T(`face`,e.makeNonPlanarFace(E(t)))}function oi(e,t,n,r){let i=Ie(t,r.map(E));try{return T(`face`,e.addHolesInFace(E(n),i))}finally{i.delete()}}function si(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=Le(t,a);try{return T(`face`,e.removeHolesFromFace(E(n),o))}finally{o.delete()}}function ci(e,t,n){let r=E(t);return T(`face`,e.makeFaceOnSurface(r,E(n)))}function li(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 ui(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=Ie(t,a);try{return D(e,e.sewAndSolidify(o,.001))}finally{o.delete();for(let t of a)e.release(t)}}function di(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 fi(e,t,n,r){let i=Ie(t,n.map(E));try{let t=e.sewAndSolidify(i,r),n=e.fixFaceOrientations(t);return n!==t&&e.release(t),T(`solid`,n)}finally{i.delete()}}function pi(e,t,n){return{x:e,y:t,z:n,__type:`point3d`,delete:Ne}}function mi(e,t,n){return{x:e,y:t,z:n,__type:`direction3d`,delete:Ne}}function hi(e,t,n){return{x:e,y:t,z:n,__type:`vector3d`,delete:Ne}}function gi(e,t,n,r,i,a){return{origin:{x:e,y:t,z:n},direction:{x:r,y:i,z:a},__type:`axis1`,delete:Ne}}function _i(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:Ne}}function vi(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:Ne}}function yi(e){return e}function bi(e){return e}function xi(e,t){return{x:e,y:t}}function Si(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 Ci(e,t){return{x:e,y:t}}function wi(e,t,n,r){return{px:e,py:t,dx:n,dy:r,delete(){}}}function Ti(e){return e}function Ei(e,t,n,r){return bi(te(e,t,n,r))}function Di(e,t,n,r){return bi(ne(e,t,n,r))}function Oi(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 bi(te(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=ne(s,c,l,h);if(!h){let e=-u,t=-f;return t<e-1e-9&&(t+=2*Math.PI),bi({__bk2d:`trimmed`,basis:g,tStart:e,tEnd:t})}let _=f;return _<u-1e-9&&(_+=2*Math.PI),bi({__bk2d:`trimmed`,basis:g,tStart:u,tEnd:_})}function ki(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 bi(te(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,x=ne(p,m,h,b);if(!b){let e=-g,t=-_;return t<e-1e-9&&(t+=2*Math.PI),bi({__bk2d:`trimmed`,basis:x,tStart:e,tEnd:t})}let S=_;return S<g-1e-9&&(S+=2*Math.PI),bi({__bk2d:`trimmed`,basis:x,tStart:g,tEnd:S})}function Ai(e,t,n,r,i,a,o){return bi(ae(e,t,n,r,i??1,a??0,o??!0))}function ji(e,t,n,r,i,a,o,s,c){return bi({...ae(e,t,n,r,o??1,s??0,c??!0),__bk2d:`ellipse`,startAngle:i,endAngle:a})}function Mi(e){return bi(oe(e))}function Ni(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),bi({__bk2d:`bspline`,poles:n,knots:a,multiplicities:o,degree:i,isPeriodic:!1})}function Pi(e,t){return S(yi(e),t)}function Fi(e,t){return{point:S(yi(e),t),tangent:C(yi(e),t)}}function Ii(e){return w(yi(e))}function Li(e){let t=yi(e);for(;t.__bk2d===`trimmed`;)t=t.basis;return ee(t)}function Ri(e,t,n){return bi({__bk2d:`trimmed`,basis:yi(e),tStart:t,tEnd:n})}function zi(e){return bi(JSON.parse(JSON.stringify(yi(e))))}function Bi(e,t){let n=yi(e),r=w(n),i=[];for(let e=0;e<=20;e++){let a=r.first+(r.last-r.first)*e/20,[o,s]=S(n,a),[c,l]=C(n,a),u=Math.sqrt(c*c+l*l)||1;i.push([o-l/u*t,s+c/u*t])}return bi(oe(i.length<=25?i:i.filter((e,t)=>t%2==0||t===i.length-1)))}function Vi(e,t,n){return bi(se(yi(e),t,n))}function Hi(e,t,n,r){return bi(ce(yi(e),t,n,r))}function Ui(e,t,n,r){return bi(le(yi(e),t,n,r))}function Wi(e,t,n){return bi(ue(yi(e),t,n))}function Gi(e,t,n,r,i){return bi(de(yi(e),t,n,r,i))}function Ki(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=yi(e),_=w(g),v=[];for(let e=0;e<=20;e++){let[t,n]=S(g,_.first+(_.last-_.first)*e/20);v.push([u*t+d*n+m,f*t+p*n+h])}return bi(oe(v))}function qi(e,t,n,r,i,a){return Ki(e,t,n,r,i,a)}function Ji(){return{type:`identity2d`,delete(){}}}function Yi(e,t,n,r,i){return{type:`affinity2d`,axOriginX:e,axOriginY:t,axDirX:n,axDirY:r,ratio:i,delete(){}}}function Xi(e,t){return{type:`translate2d`,dx:e,dy:t,delete(){}}}function Zi(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 Qi(e,t,n){return{type:`rotate2d`,angle:e,cx:t,cy:n,delete(){}}}function $i(e,t,n){return{type:`scale2d`,sx:e,sy:e,cx:t,cy:n,delete(){}}}function ea(e,t,n){let r=e;r.dx=(Number(r.dx)||0)+t,r.dy=(Number(r.dy)||0)+n}function ta(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 na(e,t){let n=t;return n.type===`translate2d`?Vi(e,Number(n.dx)||0,Number(n.dy)||0):n.type===`rotate2d`?Hi(e,Number(n.angle)||0,Number(n.cx)||0,Number(n.cy)||0):n.type===`scale2d`?Ui(e,Number(n.sx)||1,Number(n.cx)||0,Number(n.cy)||0):n.type===`mirror2d`?Wi(e,Number(n.ox)||0,Number(n.oy)||0):n.type===`affinity2d`?Ki(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)?Vi(e,Number(n.dx)||0,Number(n.dy)||0):e}function ra(e,t,n){let r=fe(yi(e),yi(t),n);return{points:r.points,segments:r.segments.map(e=>bi(e))}}function ia(e,t,n){let r=yi(e),i=w(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]=S(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]=S(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`){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 aa(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]=S(yi(e),c);for(let e=0;e<=20;e++){let n=i+(a-i)*(e/20),[r,s]=S(yi(t),n),c=Math.sqrt((r-l)**2+(s-u)**2);c<o&&(o=c)}}return o}function oa(e,t){let n=yi(e),r=w(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(S(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),bi({__bk2d:`bspline`,poles:a,knots:c,multiplicities:l,degree:o,isPeriodic:!1})}function sa(e){let t=yi(e);for(;t.__bk2d===`trimmed`;)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++){let n=t.knots[e]??0,r=t.multiplicities[e]??0;for(let e=0;e<r;e++)i.push(n)}let a=n.length-1+r+1;if(r<1||i.length!==a+1)return[bi(oe(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=>bi(oe(e)))}function ca(){return Ce()}function la(e,t,n){we(e,yi(t),n)}function ua(e){return{xMin:e.xMin,yMin:e.yMin,xMax:e.xMax,yMax:e.yMax}}function da(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 fa(e,t){return e.xMax<t.xMin||e.xMin>t.xMax||e.yMax<t.yMin||e.yMin>t.yMax}function pa(e,t,n){return t<e.xMin||t>e.xMax||n<e.yMin||n>e.yMax}function ma(e){let t=yi(e);for(;t.__bk2d===`trimmed`;)t=t.basis;return t.__bk2d===`circle`?{cx:t.cx,cy:t.cy,radius:t.radius,isDirect:t.sense}:null}function ha(e){let t=yi(e);for(;t.__bk2d===`trimmed`;)t=t.basis;return t.__bk2d===`ellipse`?{majorRadius:t.majorRadius,minorRadius:t.minorRadius,xAxisAngle:t.xDirAngle,isDirect:t.sense}:null}function ga(e){let t=yi(e);for(;t.__bk2d===`trimmed`;)t=t.basis;return t.__bk2d===`bezier`?t.poles:null}function _a(e){let t=yi(e);for(;t.__bk2d===`trimmed`;)t=t.basis;return t.__bk2d===`bezier`?t.poles.length-1:null}function va(e){return xe(yi(e))}function ya(e){return bi(Se(e))}function ba(e,t){let n=w(yi(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(Ri(e,a,o))}return i}function xa(e,t,n,r,i,a){let o=yi(n),[s,c,l]=r,[u,d,f]=i,[p,m,h]=a,g=d*h-f*m,_=f*p-u*h,v=u*m-d*p,y=(e,t)=>[s+e*p+t*g,c+e*m+t*_,l+e*h+t*v],b=o.__bk2d;if(b===`line`){let t=w(o),[n,r]=S(o,t.first),[i,a]=S(o,t.last),s=y(n,r),c=y(i,a);return T(`edge`,e.makeLineEdge(s[0],s[1],s[2],c[0],c[1],c[2]))}if(b===`trimmed`){let t=o;if(t.basis&&t.basis.__bk2d===`line`){let[t,n]=S(o,0),[r,i]=S(o,1),a=y(t,n),s=y(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=w(o),[n,r]=S(o,t.first),[i,a]=S(o,(t.first+t.last)/2),[s,c]=S(o,t.last),l=y(n,r),u=y(i,a),d=y(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(b===`circle`){let t=o;if(t.cx!==void 0&&t.radius!==void 0){let[n,r,i]=y(t.cx,t.cy);return T(`edge`,e.makeCircleEdge(n,r,i,u,d,f,t.radius))}let n=w(o),[r,i]=S(o,n.first),[a,s]=S(o,(n.first+n.last)/2),[c,l]=S(o,n.last),p=y(r,i),m=y(a,s),h=y(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 x=w(o),C=(x.last-x.first)/24,ee=[];for(let e=0;e<=24;e++){let[t,n]=S(o,x.first+e*C),[r,i,a]=y(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 Sa(e,t,n,r){let i=yi(n),a=w(i),o=E(r),s=new t.VectorDouble;for(let t=0;t<=30;t++){let[n,r]=S(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 Ca(e){return e}function wa(e,t,n){let[r,i]=Vt(e,t),a=[];for(let o=0;o<=60;o++){let s=yn(e,n,Ht(e,t,r+(i-r)*o/60));s&&a.push(s)}if(a.length<2)throw Error(`occt-wasm: extractCurve2dFromEdge could not project the edge onto the face surface`);return Ni(a)}function Ta(e,t){e.buildCurves3d(E(t))}function Ea(e,t,n,r){return T(`wire`,e.fixWireOnFace(E(t),E(n),r))}function Da(e){try{let t=ze(e.modified),n=ze(e.generated),r=ze(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 Oa(e,t,n,r,i,a,o,s){let c=Le(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 ka(e,t,n,r,i,a,o,s){let c=o??[0,0,1],l=s??[0,0,0],u=Le(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 Aa(e,t,n,r,i,a,o){let s=Le(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 ja(e,t,n,r,i,a,o){let s=Le(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 Ma(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 Na(e,t,n,r,i,a,o){let s=Le(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 Pa(e,t,n,r,i,a,o){let s=Le(t,i),c;try{c=Ge(e,r);let{id:t,evolution:i}=Da(e.cutWithHistory(E(n),c.id,s,a));return{shape:D(e,t),evolution:i,diagnostics:{hasErrors:!1,hasWarnings:!1,messages:[]}}}finally{s.delete(),c?.dispose()}}function Fa(e,t,n,r,i,a,o){let s=Le(t,i),c;try{c=Ge(e,r);let{id:t,evolution:i}=Da(e.intersectWithHistory(E(n),c.id,s,a));return{shape:D(e,t),evolution:i,diagnostics:{hasErrors:!1,hasWarnings:!1,messages:[]}}}finally{s.delete(),c?.dispose()}}function Ia(e,t,n,r,i,a,o){let s=Ve(r,i),c=Ie(t,r.map(E)),l=Le(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 La(e,t,n,r,i,a,o){let s=Ve(r,i),c=Ie(t,r.map(E)),l=Le(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 Ra(e,t,n,r,i,a,o,s){let c=Ie(t,r.map(E)),l=Le(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 za(e,t,n,r,i,a){let o=Le(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 Ba(e,t,n,r,i,a,o){let s=Le(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 Va(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 Ha(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 Ua(e,t,n,r){if(n.length<4)throw Error(`hullFromPoints: need at least 4 points`);let{points:i,faces:a}=x(n,r);if(a.length<4)throw Error(`hullFromPoints: degenerate hull (fewer than 4 faces)`);return ii(e,t,[...i],[...a],r)}function Wa(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 Ga(e,t,n,r){if(n.length===0)throw Error(`hull: no shapes provided`);let i=Wa(e,t,n,r);if(i.length<4)throw Error(`hull: fewer than 4 vertices extracted from input shapes`);return Ua(e,t,i,r)}function Ka(e){throw new c(`occt-wasm: ${e} is not yet implemented`)}var qa=class e{oc;kernelId=`occt-wasm`;capabilities=a;Module;k;owner;constructor(e,t,n){this.Module=e,this.k=Ue(t,e),this.oc=We(e,this.k),this.owner=n}static fromKernel(t){let n=t.getRawModule(),r=t.getRawKernel();return new e(n,r,t)}get retainedKernelOwner(){return this.owner}dispose(e){Pe(e)?this.k.release(e.id):typeof e.delete==`function`&&e.delete()}executeBatch(e){Ka(`executeBatch`)}openCheckpoints=[];checkpoint(){let e=this.k.checkpoint();return this.openCheckpoints.push(e),e}checkpointCount(){return this.openCheckpoints.length}restoreCheckpoint(e){let t=this.openCheckpoints.lastIndexOf(e);if(t===-1)throw new r(`occtWasmAdapter.restoreCheckpoint`,`checkpoint ${e} is not open — releaseSince would erase unrelated live handles`);this.k.releaseSince(e),this.openCheckpoints.length=t}discardCheckpoint(e){this.closeCheckpoint(e)}closeCheckpoint(e){let t=this.openCheckpoints.lastIndexOf(e);t!==-1&&(this.openCheckpoints.length=t)}makeBox(e,t,n){return nt(this.k,e,t,n)}makeCylinder(e,t,n,r){return rt(this.k,e,t,n,r)}makeSphere(e,t){return it(this.k,e,t)}makeCone(e,t,n,r,i){return at(this.k,e,t,n,r,i)}makeTorus(e,t,n,r){return ot(this.k,e,t,n,r)}makeEllipsoid(e,t,n){return st(this.k,e,t,n)}makeBoxFromCorners(e,t){return ct(this.k,e,t)}makeRectangle(e,t){return lt(this.k,e,t)}fuse(e,t,n){return Ke(this.k,e,t,n)}cut(e,t,n){return qe(this.k,e,t,n)}intersect(e,t,n){return Je(this.k,e,t,n)}section(e,t,n){return Ye(this.k,e,t,n)}fuseAll(e,t){return Xe(this.k,this.Module,e,t)}cutAll(e,t,n){return Ze(this.k,this.Module,e,t,n)}split(e,t){return Qe(this.k,this.Module,e,t)}checkBoolean(e,t,n){return $e(this.k,e,t,n)}meshBoolean(e,t,n,r,i,a){return et(e,t,n,r,i,a)}makeVertex(e,t,n){return Hr(this.k,e,t,n)}makeEdge(e,t,n){return Ur(this.k,e)}makeWire(e){return Wr(this.k,this.Module,e)}makeFace(e,t){return Kr(this.k,e,t)}makeLineEdge(e,t){return qr(this.k,e,t)}makeCircleEdge(e,t,n){return Jr(this.k,e,t,n)}makeCircleArc(e,t,n,r,i){return Yr(this.k,e,t,n,r,i)}makeArcEdge(e,t,n){return Xr(this.k,e,t,n)}makeEllipseEdge(e,t,n,r,i){return Zr(this.k,e,t,n,r)}makeEllipseArc(e,t,n,r,i,a,o){return Qr(this.k,e,t,n,r,i,a)}makeBezierEdge(e){return $r(this.k,this.Module,e)}makeTangentArc(e,t,n){return ei(this.k,e,t,n)}makeHelixWire(e,t,n,r,i,a){return ti(this.k,e,t,n,r,i)}makeWireFromMixed(e){return Gr(this.k,this.Module,e)}makeCompound(e){return ni(this.k,this.Module,e)}solidFromShell(e){return ri(this.k,e)}hull(e,t){return Ga(this.k,this.Module,e,t)}hullFromPoints(e,t){return Ua(this.k,this.Module,e,t)}buildSolidFromFaces(e,t,n){return ii(this.k,this.Module,e,t,n)}makeNonPlanarFace(e){return ai(this.k,e)}addHolesInFace(e,t){return oi(this.k,this.Module,e,t)}removeHolesFromFace(e){return si(this.k,this.Module,e)}makeFaceOnSurface(e,t){return ci(this.k,e,t)}bsplineSurface(e,t,n){return li(this.k,this.Module,e,t,n)}triangulatedSurface(e,t,n){return ui(this.k,this.Module,e,t,n)}buildTriFace(e,t,n){return di(this.k,e,t,n)}sewAndSolidify(e,t){return fi(this.k,this.Module,e,t)}createPoint3d(e,t,n){return pi(e,t,n)}createDirection3d(e,t,n){return mi(e,t,n)}createVector3d(e,t,n){return hi(e,t,n)}createAxis1(e,t,n,r,i,a){return gi(e,t,n,r,i,a)}createAxis2(e,t,n,r,i,a,o,s,c){return _i(e,t,n,r,i,a,o,s,c)}createAxis3(e,t,n,r,i,a,o,s,c){return vi(e,t,n,r,i,a,o,s,c)}extrude(e,t,n){return nr(this.k,e,t,n)}revolve(e,t,n){return rr(this.k,e,t,n)}loft(e,t,n,r){return ir(this.k,this.Module,e,t,n,r)}sweep(e,t,n){return ar(this.k,e,t,n)}simplePipe(e,t){return or(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){Ka(`sweepWithOptions`)}sweepPipeShell(e,t,n){return sr(this.k,e,t,n)}loftAdvanced(e,t){return cr(this.k,this.Module,e,t)}buildExtrusionLaw(e,t,n){return lr(this.k,e,t,n)}revolveVec(e,t,n,r){return ur(this.k,e,t,n,r)}draftPrism(e,t,n,r,i,a){return dr(this.k,e,t,n,r,i,a)}fillet(e,t,n){return Un(this.k,this.Module,e,t,n)}chamfer(e,t,n){return Wn(this.k,this.Module,e,t,n)}chamferDistAngle(e,t,n,r){return Gn(this.k,this.Module,e,t,n,r)}shell(e,t,n,r){return Kn(this.k,this.Module,e,t,n,r)}thicken(e,t){return qn(this.k,e,t)}offset(e,t,n){return Jn(this.k,e,t,n)}filletVariable(e,t){return Xn(this.k,e,t)}draft(e,t,n,r,i){return Zn(this.k,e,t,n,r,i)}defeature(e,t){return Qn(this.k,this.Module,e,t)}offsetWire2D(e,t,n){return $n(this.k,e,t,n)}simplify(e){return er(this.k,e)}reverseShape(e){return tr(this.k,e)}composeTransform(e){return fr(e)}transform(e,t){return mr(this.k,this.Module,e,t)}locate(e,t){return hr(this.k,this.Module,e,t)}translate(e,t,n,r){return gr(this.k,e,t,n,r)}rotate(e,t,n,r){return _r(this.k,e,t,n,r)}mirror(e,t,n){return vr(this.k,e,t,n)}scale(e,t,n){return yr(this.k,e,t,n)}generalTransform(e,t,n,r){return br(this.k,this.Module,e,t,n,r)}generalTransformNonOrthogonal(e,t,n){return br(this.k,this.Module,e,t,n,!1)}positionOnCurve(e,t,n){return xr(this.k,this.Module,e,t,n)}linearPattern(e,t,n,r){return Sr(this.k,e,t,n,r)}circularPattern(e,t,n,r,i){return Cr(this.k,e,t,n,r,i)}transformBatch(e){return wr(this.k,e)}translateWithHistory(e,t,n,r,i,a){return Oa(this.k,this.Module,e,t,n,r,i,a)}rotateWithHistory(e,t,n,r,i,a){return ka(this.k,this.Module,e,t,n,r,i,a)}mirrorWithHistory(e,t,n,r,i){return Aa(this.k,this.Module,e,t,n,r,i)}scaleWithHistory(e,t,n,r,i){return ja(this.k,this.Module,e,t,n,r,i)}generalTransformWithHistory(e,t,n,r,i,a){return Ma((e,t,n,r)=>this.generalTransform(e,t,n,r),e,t,n,r,i)}fuseWithHistory(e,t,n,r,i){return Na(this.k,this.Module,e,t,n,r,i)}cutWithHistory(e,t,n,r,i){return Pa(this.k,this.Module,e,t,n,r,i)}intersectWithHistory(e,t,n,r,i){return Fa(this.k,this.Module,e,t,n,r,i)}filletWithHistory(e,t,n,r,i){return Ia(this.k,this.Module,e,t,n,r,i)}chamferWithHistory(e,t,n,r,i){return La(this.k,this.Module,e,t,n,r,i)}shellWithHistory(e,t,n,r,i,a){return Ra(this.k,this.Module,e,t,n,r,i,a)}thickenWithHistory(e,t,n,r){return za(this.k,this.Module,e,t,n,r)}offsetWithHistory(e,t,n,r,i){return Ba(this.k,this.Module,e,t,n,r,i)}draftWithHistory(e,t,n,r,i,a,o){return Va(this.k,e,t,n,i)}applyComposedTransformWithHistory(e,t,n,r){return Ha((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 Pt(this.k,this.Module,e,t)}meshEdges(e,t,n){return It(this.k,this.Module,e,t,n)}hasTriangulation(e){return Lt(this.k,e)}meshShape(e,t,n){Rt(this.k,e,t,n)}exportSTEP(e){return Dr(this.k,this.makeCompound.bind(this),e)}exportSTL(e,t,n,r){return Or(this.mesh.bind(this),e,t,n,r)}importSTEP(e){return kr(this.k,e)}importSTL(e){return Ar(this.k,this.Module,e)}exportIGES(e){return jr(this.k,this.makeCompound.bind(this),e)}importIGES(e){return Mr(this.k,e)}exportSTEPAssembly(e,t){return Nr(this.k,this.Module,e,t)}export3MF(e,t){throw Error(`export3MF is only available with the brepkit kernel`)}exportGLB(e,t){return Pr(this.mesh.bind(this),e,t)}exportOBJ(e,t){return Fr(this.mesh.bind(this),e,t)}exportPLY(e,t){return Ir(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 Lr(this.k,e)}fromBREP(e){return Rr(this.k,e)}createXCAFDocument(e){return zr(this.k,this.Module,e)}writeXCAFToSTEP(e,t){return Br(this.k,e,t)}exportSTEPConfigured(e,t){return Vr(this.k,this.Module,e,t)}volume(e){return Cn(this.k,e)}area(e){return wn(this.k,e)}length(e){return Tn(this.k,e)}centerOfMass(e){return En(this.k,e)}linearCenterOfMass(e){return Dn(this.k,e)}boundingBox(e){return On(this.k,e)}distance(e,t){return Pn(this.k,this.Module,e,t)}surfaceCurvature(e,t,n){return Vn(this.k,e,t,n)}surfaceCenterOfMass(e){return kn(this.k,e)}measureBulk(e,t){return An(this.k,e,t)}createDistanceQuery(e){return jn(this.k,e)}iterShapes(e,t){return ut(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 dt(this.k,e)}isSame(e,t){return ft(this.k,e,t)}isEqual(e,t){return pt(this.k,e,t)}downcast(e,t){return mt(this.k,e,t)}copyShape(e){return ht(this.k,e)}hashCode(e,t){return gt(this.k,e,t)}subShapeCount(e,t){return bt(this.k,e,t)}subShapeHashes(e,t,n){return xt(this.k,e,t,n)}isNull(e){return _t(this.k,e)}shapeOrientation(e){return vt(this.k,e)}edgeToFaceMap(e){return yt(this.k,e)}sharedEdges(e,t){return St(this.k,e,t)}adjacentFaces(e,t){return Ct(this.k,e,t)}sew(e,t){return wt(this.k,this.Module,e,t)}curveType(e){return Bt(this.k,e)}curveParameters(e){return Vt(this.k,e)}curvePointAtParam(e,t){return Ht(this.k,e,t)}curveTangent(e,t){return Ut(this.k,e,t)}curveIsClosed(e){return Wt(this.k,e)}curveIsPeriodic(e){return Gt(this.k,e)}curvePeriod(e){return Kt(this.k,e)}interpolatePoints(e,t){return qt(this.k,this.Module,e,t)}approximatePoints(e,t){return Jt(this.k,this.Module,e,t)}curveDegreeElevate(e,t){return Yt(this.k,e,t)}curveKnotInsert(e,t,n){return Xt(this.k,e,t,n)}curveKnotRemove(e,t,n){return Zt(this.k,e,t,n)}curveSplit(e,t){return Qt(this.k,e,t)}getBezierPenultimatePole(e){return $t(this.k,e)}createCurveAdaptor(e){Ka(`createCurveAdaptor`)}vertexPosition(e){return tn(this.k,e)}surfaceType(e){return nn(this.k,e)}uvBounds(e){return rn(this.k,e)}outerWire(e){return an(this.k,e)}surfaceNormal(e,t,n){return sn(this.k,e,t,n)}pointOnSurface(e,t,n){return cn(this.k,e,t,n)}uvFromPoint(e,t){return yn(this.k,e,t)}projectPointOnFace(e,t){return bn(this.k,e,t)}classifyPointOnFace(e,t,n,r){return xn(this.k,e,t,n,r)}classifyPointRobust(e,t,n){Ka(`classifyPointRobust`)}classifyPointWinding(e,t,n){Ka(`classifyPointWinding`)}approximateSurfaceLspia(e,t,n,r,i,a,o,s,c){Ka(`approximateSurfaceLspia`)}untrimFace(e,t,n){Ka(`untrimFace`)}getSurfaceCylinderData(e){return vn(this.k,e)}getSurfaceAxis(e){return _n(this.k,e)}reverseSurfaceU(e){return on(this.k,e)}detectSmallFeatures(e,t,n){Ka(`detectSmallFeatures`)}recognizeFeatures(e,t){Ka(`recognizeFeatures`)}projectEdges(e,t,n,r){return Sn(this.k,this.Module,e,t,n,r)}isValid(e){return Et(this.k,e)}healSolid(e){return Dt(this.k,e)}healFace(e){return Ot(this.k,e)}healWire(e,t){return kt(this.k,e,t)}mergeCoincidentVertices(e,t){return At(this.k,e,t)}removeDegenerateEdges(e,t){return jt(this.k,e,t)}fixFaceOrientations(e){return Mt(this.k,e)}fixShape(e){return Nt(this.k,e)}fixSelfIntersection(e){return kt(this.k,e)}createPoint2d(e,t){return xi(e,t)}createDirection2d(e,t){return Si(e,t)}createVector2d(e,t){return Ci(e,t)}createAxis2d(e,t,n,r){return wi(e,t,n,r)}wrapCurve2dHandle(e){return Ti(e)}createCurve2dAdaptor(e){Ka(`createCurve2dAdaptor`)}makeLine2d(e,t,n,r){return Ei(e,t,n,r)}makeCircle2d(e,t,n,r){return Di(e,t,n,r)}makeArc2dThreePoints(e,t,n,r,i,a){return Oi(e,t,n,r,i,a)}makeArc2dTangent(e,t,n,r,i,a){return ki(e,t,n,r,i,a)}makeEllipse2d(e,t,n,r,i,a,o){return Ai(e,t,n,r,i,a,o)}makeEllipseArc2d(e,t,n,r,i,a,o,s,c){return ji(e,t,n,r,i,a,o,s,c)}makeBezier2d(e){return Mi(e)}makeBSpline2d(e,t){return Ni(e)}evaluateCurve2d(e,t){return Pi(e,t)}evaluateCurve2dD1(e,t){return Fi(e,t)}getCurve2dBounds(e){return Ii(e)}getCurve2dType(e){return Li(e)}trimCurve2d(e,t,n){return Ri(e,t,n)}reverseCurve2d(e){}copyCurve2d(e){return zi(e)}offsetCurve2d(e,t){return Bi(e,t)}translateCurve2d(e,t,n){return Vi(e,t,n)}rotateCurve2d(e,t,n,r){return Hi(e,t,n,r)}scaleCurve2d(e,t,n,r){return Ui(e,t,n,r)}mirrorCurve2dAtPoint(e,t,n){return Wi(e,t,n)}mirrorCurve2dAcrossAxis(e,t,n,r,i){return Gi(e,t,n,r,i)}affinityTransform2d(e,t,n,r,i,a){return qi(e,t,n,r,i,a)}createIdentityGTrsf2d(){return Ji()}createAffinityGTrsf2d(e,t,n,r,i){return Yi(e,t,n,r,i)}createTranslationGTrsf2d(e,t){return Xi(e,t)}createMirrorGTrsf2d(e,t,n,r,i,a,o){return Zi(e,t,n,r,i,a,o)}createRotationGTrsf2d(e,t,n){return Qi(e,t,n)}createScaleGTrsf2d(e,t,n){return $i(e,t,n)}setGTrsf2dTranslationPart(e,t,n){ea(e,t,n)}multiplyGTrsf2d(e,t){ta(e,t)}transformCurve2dGeneral(e,t){return na(e,t)}intersectCurves2d(e,t,n){return ra(e,t,n)}projectPointOnCurve2d(e,t,n){return ia(e,t,n)}distanceBetweenCurves2d(e,t,n,r,i,a){return aa(e,t,n,r,i,a)}approximateCurve2dAsBSpline(e,t,n,r){return oa(e,r)}decomposeBSpline2dToBeziers(e){return sa(e)}createBoundingBox2d(){return ca()}addCurveToBBox2d(e,t,n){la(e,t,n)}getBBox2dBounds(e){return ua(e)}mergeBBox2d(e,t){da(e,t)}isBBox2dOut(e,t){return fa(e,t)}isBBox2dOutPoint(e,t,n){return pa(e,t,n)}getCurve2dCircleData(e){return ma(e)}getCurve2dEllipseData(e){return ha(e)}getCurve2dBezierPoles(e){return ga(e)}getCurve2dBezierDegree(e){return _a(e)}getCurve2dBSplineData(e){Ka(`getCurve2dBSplineData`)}serializeCurve2d(e){return va(e)}deserializeCurve2d(e){return ya(e)}splitCurve2d(e,t){return ba(e,t)}liftCurve2dToPlane(e,t,n,r){return xa(this.k,this.Module,e,t,n,r)}buildEdgeOnSurface(e,t){return Sa(this.k,this.Module,e,t)}extractSurfaceFromFace(e){return Ca(e)}extractCurve2dFromEdge(e,t){return wa(this.k,e,t)}buildCurves3d(e){Ta(this.k,e)}fixWireOnFace(e,t,n){return Ea(this.k,e,t,n)}fillSurface(e,t){Ka(`fillSurface`)}getNurbsCurveData(e){return en(this.k,e)}};function O(e){return{ok:!0,value:e}}function k(e){return{ok:!1,error:e}}var Ja=O(void 0);function Ya(e){return e.ok}function A(e){return!e.ok}function Xa(e,t){return e.ok?O(t(e.value)):e}function Za(e,t){return e.ok?e:k(t(e.error))}function Qa(e,t){return e.ok?t(e.value):e}var $a=Qa;function eo(e,t){return e.ok?e:t}function to(e,t){return e.ok?e:t(e.error)}function no(e,t){return e.ok?t.ok?O([e.value,t.value]):t:e}var ro=ho;function io(e,t){return e.ok&&t(e.value),e}function ao(e,t){return e.ok||t(e.error),e}function oo(e){return e.ok?e.value:e}function so(e,t,n){return e.ok?O(t(e.value)):k(n(e.error))}function co(e,t){return e==null?k(t()):O(e)}function lo(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: ${lo(e.error)}`)}function uo(e,t){return e.ok?e.value:t}function fo(e,t){return e.ok?e.value:t(e.error)}function po(e){if(!e.ok)return e.error;throw Error(`Called unwrapErr() on an Ok: ${String(e.value)}`)}function mo(e,t){return e.ok?t.ok(e.value):t.err(e.error)}function ho(e){let t=[];for(let n of e){if(!n.ok)return n;t.push(n.value)}return O(t)}function go(e,t){try{return O(e())}catch(e){return k(t(e))}}async function _o(e,t){try{return O(await e())}catch(e){return k(t(e))}}function vo(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 yo=[{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.`}],bo={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 xo(e){return bo[e]}function So(e){for(let{pattern:t,translation:n}of yo)if(t.test(e))return`${n} (kernel: ${e})`;return e}var M={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 Co(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 N(e,t,n,r,i){return Co(`KERNEL_OPERATION`,e,t,n,r,i)}function P(e,t,n,r,i){return Co(`VALIDATION`,e,t,n,r,i)}function wo(e,t,n,r,i){return Co(`TYPE_CAST`,e,t,n,r,i)}function To(e,t,n,r,i){return Co(`SKETCHER_STATE`,e,t,n,r,i)}function Eo(e,t,n,r,i){return Co(`MODULE_INIT`,e,t,n,r,i)}function Do(e,t,n,r,i){return Co(`COMPUTATION`,e,t,n,r,i)}function Oo(e,t,n,r,i){return Co(`IO`,e,t,n,r,i)}function ko(e,t,n,r,i){return Co(`QUERY`,e,t,n,r,i)}function Ao(e,t,n,r,i){return Co(`UNSUPPORTED`,e,t,n,r,i)}function jo(e,n,r){return(n<0||n>=e.length)&&i(r??`safeIndex`,`Index ${n} is out of bounds (array length ${e.length})`),t(e,n)}var Mo={draft:{tolerance:.01,angularTolerance:.5},standard:{tolerance:.001,angularTolerance:.1},fine:{tolerance:1e-4,angularTolerance:.05}},No=`standard`;function Po(){return No}function Fo(e=No){return Mo[e]}function Io(e){No=e}function Lo(e){return`makeLine2d`in e}var Ro=[`boolean`,`loft`,`extrude`,`shell`,`fillet`,`mesh`,`edgeMesh`,`transform`],zo=Object.create(null),Bo=Object.create(null);function Vo(){for(let e of Ro)zo[e]=0,Bo[e]=0}Vo();function Ho(e){let t=performance.now();return()=>{zo[e]=(zo[e]??0)+(performance.now()-t),Bo[e]=(Bo[e]??0)+1}}function Uo(){let e={};for(let t of Ro)e[t]={totalMs:zo[t]??0,count:Bo[t]??0};return e}function Wo(){Vo()}var Go;function Ko(){Go=void 0}function qo(e){return Go??=typeof e.BooleanBatch==`function`,Go}function Jo(e){return e===`commonFace`?1:e===`sameFace`?2:0}function Yo(e,t,n={}){if(!qo(e))return null;let r=Ho(`boolean`),i=new e.BooleanBatch;try{for(let e of t)i.addShape(e);return i.fuseAll(Jo(n.optimisation),!!n.simplify,n.fuzzyValue??0)}finally{i.delete(),r()}}function Xo(e,t,n,r={}){if(!qo(e))return null;if(n.length===0)return t;let i=Ho(`boolean`),a=new e.BooleanBatch;try{for(let e of n)a.addShape(e);return a.cutAll(t,Jo(r.optimisation),!!r.simplify,r.fuzzyValue??0)}finally{a.delete(),i()}}var Zo=2147483647,Qo;function $o(){Qo=void 0}function es(e){return Qo??=typeof e.MeasurementExtractor?.extract==`function`,Qo}function ts(e,t,n=!1){if(es(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:ns(e,t),area:rs(e,t),length:n?is(e,t):0,centerOfMass:as(e,t),boundingBox:ss(e,t)}}function ns(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 rs(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 is(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 as(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 os(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 ss(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 cs(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 ls(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 us(e){return{volume:t=>ns(e,t),area:t=>rs(e,t),length:t=>is(e,t),centerOfMass:t=>as(e,t),linearCenterOfMass:t=>os(e,t),boundingBox:t=>ss(e,t),distance:(t,n)=>cs(e,t,n),classifyPointOnFace:(t,n,r,i)=>ls(e,t,n,r,i),measureBulk:(t,n)=>ts(e,t,n)}}var ds={vertex:7,edge:6,wire:5,face:4,shell:3,solid:2,compsolid:1,compound:0};function fs(e,t,n){let r=e.TopologyExtractor.extract(t,ds[n]),i=r.getShapesCount(),a=[];for(let e=0;e<i;e++)a.push(r.getShape(e));return r.delete(),a}var ps=new WeakMap;function ms(e,t,n){let r=ps.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},ps.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,Zo),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 hs(e,t,n){return e.TopologyExtractor?fs(e,t,n):ms(e,t,n)}var gs=new WeakMap;function _s(e){let t=gs.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`]]),gs.set(e,t)}return t}function vs(e,t){if(t.IsNull())throw Error(`Cannot determine shape type: shape is null`);let n=_s(e).get(t.ShapeType());if(!n)throw Error(`Unknown shape type enum value`);return n}function ys(e,t){let n=new e.BRepCheck_Analyzer(t,!0,!1,!1),r=n.IsValid_2();return n.delete(),r}function bs(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 xs(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 ws(e){return{iterShapes:(t,n)=>hs(e,t,n),iterShapeList:(t,n)=>{xs(e,t,n)},shapeType:t=>vs(e,t),isSame:(e,t)=>Ss(e,t),isEqual:(e,t)=>Cs(e,t),isValid:t=>ys(e,t),sew:(t,n)=>bs(e,t,n)}}var Ts=.001;function Es(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 Os(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 ks(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 As(e,t,n,r={}){let i=Ho(`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);Es(e,c,i),Ds(c,o),c.Build(s),a&&c.SimplifyResult(!0,!0,Ts);let l=c.Shape();return c.delete(),s.delete(),l}finally{i()}}function js(e,t,n,r={}){let i=Ho(`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);Es(e,c,i),Ds(c,o),c.Build(s),a&&c.SimplifyResult(!0,!0,Ts);let l=c.Shape();return c.delete(),s.delete(),l}finally{i()}}function Ms(e,t,n,r={}){let i=Ho(`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);Es(e,c,i),Ds(c,o),c.Build(s),a&&c.SimplifyResult(!0,!0,Ts);let l=c.Shape();return c.delete(),s.delete(),l}finally{i()}}function Ns(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 Ps(e,t,n={}){let r=Yo(e,t,n);if(r!==null)return r;let i=Ho(`boolean`);try{let{optimisation:r,simplify:i=!1}=n,a=n.fuzzyValue??Os(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),Es(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 Fs(e,n,r,i,a){a.signal?.throwIfAborted();let o=i-r;if(o===1)return t(n,r);if(o===2)return As(e,n[r],n[r+1],{...a,simplify:!1});let s=r+Math.ceil(o/2);return As(e,Fs(e,n,r,s,a),Fs(e,n,s,i,a),{...a,simplify:!1})}function Is(e,t,n={}){let r=Fs(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 Ls(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`?Is(e,n,r):Ps(e,n,r)}function Rs(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 zs(e,t,n,r={}){if(n.length===0)return t;let i=Xo(e,t,n,r);if(i!==null)return i;let a=ks(e,n),o=js(e,t,a,r);return a.delete(),o}function Bs(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 Vs(e){return{fuse:(t,n,r)=>As(e,t,n,r),cut:(t,n,r)=>js(e,t,n,r),intersect:(t,n,r)=>Ms(e,t,n,r),section:(t,n,r)=>Ns(e,t,n,r),fuseAll:(t,n)=>Ls(e,t,n),cutAll:(t,n,r)=>zs(e,t,n,r),split:(t,n)=>Rs(e,t,n),checkBoolean:(t,n,r)=>Bs(e,t,n,r,t=>ys(e,t))}}var Hs={fuse:0,cut:1,intersect:2};function Us(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(Hs[e.op],e.tool);let e=r.execute(t,i,a);return e.IsNull()?null:e}finally{r.delete()}}}function Ws(e){return{booleanPipeline:(t,n,r)=>Us(e,t,n,r)??null}}function Gs(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 Ks(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 qs(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 Js(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=hs(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 Ys(e,t,n,r){let i=new e.BRepPrimAPI_MakeBox_2(t,n,r),a=i.Solid();return i.delete(),a}function Xs(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 Zs(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 Qs(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 $s(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 ec(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 tc(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 nc(e){return{makeVertex:(t,n,r)=>Gs(e,t,n,r),makeEdge:(t,n,r)=>Ks(e,t,n,r),makeWire:t=>qs(e,t),makeWireFromMixed:t=>ec(e,t),makeFace:(t,n)=>Js(e,t,n),makeBox:(t,n,r)=>Ys(e,t,n,r),makeCylinder:(t,n,r,i)=>Xs(e,t,n,r,i),makeSphere:(t,n)=>Zs(e,t,n),makeCone:(t,n,r,i,a)=>Qs(e,t,n,r,i,a),makeTorus:(t,n,r,i)=>tc(e,t,n,r,i),buildTriFace:(t,n,r)=>$s(e,t,n,r)}}function rc(e,t){let n=e[t];if(n===void 0)throw Error(`Index ${t} out of bounds`);return n}function ic(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 ac(e,t,n){let{faces:r,points:i}=t,a=[];for(let[t,n,o]of r){let r=rc(i,t),s=rc(i,n),c=rc(i,o),l=$s(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 oc(e,t,n){if(t.length===0)throw Error(`hull: no shapes provided`);let r=ic(e,t,n);if(r.length<4)throw Error(`hull: fewer than 4 vertices extracted from input shapes`);let i=x(r,n);if(i.faces.length<4)throw Error(`hull: degenerate hull (fewer than 4 faces)`);return ac(e,i,n)}function sc(e,t,n,r){return ac(e,{points:t,faces:n},r)}function cc(e,t,n){if(t.length<4)throw Error(`hullFromPoints: fewer than 4 points`);let r=x(t,n);if(r.faces.length<4)throw Error(`hullFromPoints: degenerate hull (fewer than 4 faces)`);return ac(e,r,n)}function lc(e){return{hull:(t,n)=>oc(e,t,n),hullFromPoints:(t,n)=>cc(e,t,n),buildSolidFromFaces:(t,n,r)=>sc(e,t,n,r)}}function uc(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 dc(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 fc(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 pc(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 mc(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 hc(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 gc(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 _c(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 vc(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 yc(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 bc(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=yc(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 xc(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 wc(e,t){return e.BRepToolsWrapper.Write(t)}function Tc(e,t){return e.BRepToolsWrapper.Read(t)}function Ec(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 Oc(e,t,n){let r=uc(e,[0,0,0],[t,0,0]),i=uc(e,[t,0,0],[t,n,0]),a=uc(e,[t,n,0],[0,n,0]),o=uc(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 kc(e,t,n,r){return new e.gp_Pnt_3(t,n,r)}function Ac(e,t,n,r){return new e.gp_Dir_5(t,n,r)}function jc(e,t,n,r){return new e.gp_Vec_4(t,n,r)}function Mc(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 Nc(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 Pc(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 Fc(e){return{makeLineEdge:(t,n)=>uc(e,t,n),makeCircleEdge:(t,n,r)=>dc(e,t,n,r),makeCircleArc:(t,n,r,i,a)=>fc(e,t,n,r,i,a),makeArcEdge:(t,n,r)=>pc(e,t,n,r),makeEllipseEdge:(t,n,r,i,a)=>hc(e,t,n,r,i,a),makeEllipseArc:(t,n,r,i,a,o,s)=>gc(e,t,n,r,i,a,o,s),makeBezierEdge:t=>_c(e,t),makeTangentArc:(t,n,r)=>mc(e,t,n,r),makeHelixWire:(t,n,r,i,a,o)=>vc(e,t,n,r,i,a,o),makeCompound:t=>xc(e,t),makeBoxFromCorners:(t,n)=>Sc(e,t,n),makeRectangle:(t,n)=>Oc(e,t,n),solidFromShell:t=>Cc(e,t),makeEllipsoid:(t,n,r)=>bc(e,t,n,r),toBREP:t=>wc(e,t),fromBREP:t=>Tc(e,t),exportSTEPAssembly:(t,n)=>Ec(e,t,n??{}),dispose:t=>{Dc(e,t)},createPoint3d:(t,n,r)=>kc(e,t,n,r),createDirection3d:(t,n,r)=>Ac(e,t,n,r),createVector3d:(t,n,r)=>jc(e,t,n,r),createAxis1:(t,n,r,i,a,o)=>Mc(e,t,n,r,i,a,o),createAxis2:(t,n,r,i,a,o,s,c,l)=>Nc(e,t,n,r,i,a,o,s,c,l),createAxis3:(t,n,r,i,a,o,s,c,l)=>Pc(e,t,n,r,i,a,o,s,c,l)}}function Ic(e,t,n,r){let i=Ho(`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 Lc(e,t,n,r){let i=new e.BRepPrimAPI_MakeRevol_1(t,n,r,!1),a=i.Shape();return i.delete(),a}function Rc(e,t,n=!1,r,i){let a=Ho(`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 zc(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 Bc(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 Vc,Hc;function Uc(){Vc=void 0}function Wc(){Hc=void 0}function Gc(e){return Vc??=typeof e.LoftBatch==`function`,Vc}function Kc(e){return Hc??=typeof e.ExtrudeBatch==`function`,Hc}function qc(e,t){if(t.length===0)return[];if(Gc(e)){let n=Ho(`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=>Rc(e,t.wires,t.ruled??!1,t.startVertex,t.endVertex))}function Jc(e,t){if(t.length===0)return[];if(Kc(e)){let n=Ho(`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=>Ic(e,t.face,t.direction,t.length))}function Yc(e){return{extrude:(t,n,r)=>Ic(e,t,n,r),revolve:(t,n,r)=>Lc(e,t,n,r),loft:(t,n,r,i)=>Rc(e,t,n,r,i),sweep:(t,n,r)=>zc(e,t,n,r??{}),simplePipe:(t,n)=>Bc(e,t,n),loftBatch:t=>qc(e,t),extrudeBatch:t=>Jc(e,t)}}function Xc(e,t,n,r){let i=Ho(`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 Zc(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 Qc(e,t,n,r,i=.001){let a=Ho(`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 $c(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 el(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 tl(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 nl(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 rl,il;function al(){rl=void 0}function ol(){il=void 0}function sl(e){return rl??=typeof e.ShellBatch==`function`,rl}function cl(e){return il??=typeof e.FilletBatch==`function`,il}function ll(e,t){if(t.length===0)return[];if(sl(e)){let n=Ho(`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=>Qc(e,t.shape,t.faces,t.thickness,t.tolerance??.001))}function ul(e,t){if(t.length===0)return[];if(cl(e)){let n=Ho(`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 Xc(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 dl(e){return{fillet:(t,n,r)=>Xc(e,t,n,r),chamfer:(t,n,r)=>Zc(e,t,n,r),chamferDistAngle:(t,n,r,i)=>el(e,t,n,r,i),shell:(t,n,r,i)=>Qc(e,t,n,r,i),thicken:(t,n)=>$c(e,t,n),offset:(t,n,r)=>nl(e,t,n,r),offsetWire2D:(t,n,r)=>tl(e,t,n,r),shellBatch:t=>ll(e,t),filletBatch:t=>ul(e,t)}}var fl;function pl(){fl=void 0}function ml(e){return fl??=typeof e.TransformBatch==`function`,fl}function hl(e,t){if(t.length===0)return[];let n=Ho(`transform`);try{if(ml(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 vl(e,t.shape,t.x,t.y,t.z);case`rotate`:return yl(e,t.shape,t.angle,[...t.axis],[...t.center]);case`scale`:return xl(e,t.shape,[...t.center],t.factor);case`mirror`:return bl(e,t.shape,[...t.origin],[...t.normal])}})}finally{n()}}function gl(e,t,n){let r=new e.BRepBuilderAPI_Transform_2(t,n,!0,!1),i=r.ModifiedShape(t);return r.delete(),i}function _l(e,t,n){let r=new e.BRepBuilderAPI_Transform_2(t,n,!1,!1);try{return r.ModifiedShape(t)}finally{r.delete()}}function vl(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=gl(e,t,a);return a.delete(),o.delete(),s}function yl(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=gl(e,t,a);return a.delete(),c.delete(),o.delete(),s.delete(),l}function bl(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=gl(e,t,i);return i.delete(),s.delete(),a.delete(),o.delete(),c}function xl(e,t,n,r){let i=new e.gp_Trsf_1,a=new e.gp_Pnt_3(...n);i.SetScale(a,r);let o=gl(e,t,i);return i.delete(),a.delete(),o}function Sl(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 Cl(e,t){let n=new e.ShapeUpgrade_UnifySameDomain_2(t,!0,!0,!1);n.Build();let r=n.Shape();return n.delete(),r}function wl(e){return{transform:(t,n)=>gl(e,t,n),locate:(t,n)=>_l(e,t,n),translate:(t,n,r,i)=>vl(e,t,n,r,i),rotate:(t,n,r,i)=>yl(e,t,n,r,i),mirror:(t,n,r)=>bl(e,t,n,r),scale:(t,n,r)=>xl(e,t,n,r),transformBatch:t=>hl(e,t),generalTransform:(t,n,r,i)=>Sl(e,t,n,r,i),simplify:t=>Cl(e,t)}}function Tl(e,t,n){if(n===0)return new Float32Array;let r=t/4;return e.slice(r,r+n)}function El(e,t,n){let r=Ho(`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=Tl(e.HEAPF32,r.getVerticesPtr(),i),u=n.skipNormals||a===0?new Float32Array:Tl(e.HEAPF32,r.getNormalsPtr(),a),d=r.getTrianglesPtr()/4,f=e.HEAPU32.slice(d,d+o),p=c>0?Tl(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=Ho(`edgeMesh`);try{let i=e.EdgeMeshExtractor.extract(t,n,r),a=i.getLinesSize(),o=i.getEdgeGroupsSize(),s=Tl(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 Ol(e){return{mesh:(t,n)=>El(e,t,n),meshEdges:(t,n,r)=>Dl(e,t,n,r)}}var kl=0;function Al(e,t){return`${e}_${++kl}.${t}`}function jl(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=Al(`_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 Ml(e,t,n=!1){let r=Al(`_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 Nl(e,t){let n=new e.IGESControl_Writer_1;for(let e of t)n.AddShape(e);n.ComputeModel();let r=Al(`_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 Pl(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=Al(`_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 Fl(e,t){let n=Al(`_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 Il(e,t){let n=Al(`_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 Ll(e){return{exportSTEP:t=>jl(e,t),exportSTL:(t,n)=>Ml(e,t,n),importSTEP:t=>Pl(e,t),importSTL:t=>Fl(e,t),exportIGES:t=>Nl(e,t),importIGES:t=>Il(e,t)}}function Rl(e,t){let n=e.BRep_Tool.Pnt(t),r=[n.X(),n.Y(),n.Z()];return n.delete(),r}function zl(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 Bl=new WeakMap;function Vl(e,t){let n=Bl.get(e);n||(n=zl(e),Bl.set(e,n));let r=new e.BRepAdaptor_Surface_2(t,!1),i=r.GetType();return r.delete(),n.get(i)??`other`}function Hl(e,t){let n=e.BRepTools.UVBounds_1(t);return{uMin:n.UMin,uMax:n.UMax,vMin:n.VMin,vMax:n.VMax}}function Ul(e,t){return e.BRepTools.OuterWire(t)}function Wl(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 Gl(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 ql(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 Yl(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 Xl(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 Zl(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 Ql(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 $l(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 eu(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 tu(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 nu(e,t,n){switch(n??ru(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 ru(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 iu(e,t,n){return e.shapeHashCode(t,n)}function au(e,t){return t.IsNull()}function ou(e,t){return t.Reversed()}function su(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 cu(e,t,n,r){new e.BRepMesh_IncrementalMeshWrapper(t,n,!1,r,!1).delete()}function lu(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 uu(e,t){return t.ShapeType()===e.TopAbs_ShapeEnum.TopAbs_WIRE?new e.BRepAdaptor_CompCurve_2(t,!1):new e.BRepAdaptor_Curve_2(t)}function du(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 fu(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 pu(e,t){let n=new e.BRepAdaptor_Surface_2(t,!1);try{let e=n.GetType(),t=fu(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 mu(e,t){return t.get().UReversed()}function hu(e){return{vertexPosition:t=>Rl(e,t),surfaceType:t=>Vl(e,t),uvBounds:t=>Hl(e,t),outerWire:t=>Ul(e,t),surfaceNormal:(t,n,r)=>Wl(e,t,n,r),pointOnSurface:(t,n,r)=>Gl(e,t,n,r),uvFromPoint:(t,n)=>Kl(e,t,n),projectPointOnFace:(t,n)=>ql(e,t,n),curveTangent:(t,n)=>Jl(e,t,n),curveParameters:t=>Yl(e,t),shapeOrientation:t=>tu(e,t),downcast:(t,n)=>nu(e,t,n),copyShape:t=>nu(e,t),hashCode:(t,n)=>iu(e,t,n),isNull:t=>au(e,t),hasTriangulation:t=>su(e,t),meshShape:(t,n,r)=>{cu(e,t,n,r)},getBezierPenultimatePole:t=>lu(e,t),createCurveAdaptor:t=>uu(e,t),reverseShape:t=>ou(e,t),curvePointAtParam:(t,n)=>Xl(e,t,n),curveIsClosed:t=>Zl(e,t),curveIsPeriodic:t=>Ql(e,t),curvePeriod:t=>$l(e,t),curveType:t=>eu(e,t),getSurfaceCylinderData:t=>du(e,t),getSurfaceAxis:t=>pu(e,t),reverseSurfaceU:t=>mu(e,t)}}function gu(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 _u(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 vu(e){return{getNurbsCurveData:t=>gu(e,t),getNurbsSurfaceData:t=>_u(e,t)}}function yu(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 bu(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 xu(e){return{interpolatePoints:(t,n)=>yu(e,t,n??{}),approximatePoints:(t,n)=>bu(e,t,n??{})}}function Su(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 Cu(e,t){let n=new e.ShapeFix_Face_2(t);n.Perform();let r=n.Face();return n.delete(),r}function wu(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 Tu(e){return{healSolid:t=>Su(e,t),healFace:t=>Cu(e,t),healWire:(t,n)=>wu(e,t,n)}}var Eu={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 Ou(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 ku(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 Au(e,t,n,r,i){if(r.length===0)return Eu;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 Ou(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,ku(e,a,i));let l=t.Generated(r);l.Size()>0&&s.set(n,ku(e,l,i))}return{modified:o,generated:s,deleted:c}}function ju(e,t,n,r,i){let a=new e.BRepBuilderAPI_Transform_2(t,n,!0,!1),o=a.Shape(),s=r.length===0?Eu:Au(e,a,t,r,i);return a.delete(),{shape:o,evolution:s}}function Mu(e,t,n,r,i,a,o){return a&&t.SimplifyResult(!0,!0,.001),{shape:t.Shape(),evolution:Au(e,t,n,r,i),diagnostics:o??{hasErrors:!1,hasWarnings:!1,messages:[]}}}function Nu(e,t,n,r,i){return{shape:t.Shape(),evolution:Au(e,t,n,r,i)}}function Pu(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=ju(e,t,s,a,o);return s.delete(),l}function Fu(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=ju(e,t,s,r,i);return s.delete(),d}function Iu(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=ju(e,t,o,i,a);return o.delete(),u}function Lu(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=ju(e,t,o,i,a);return o.delete(),c}function Ru(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=ju(e,t,s,a,o);return s.delete(),c}function zu(e){return{hasErrors:e.HasErrors(),hasWarnings:e.HasWarnings(),messages:[]}}function Bu(e,t,n,r,i,a={}){let o=new e.Message_ProgressRange_1,s=new e.BRepAlgoAPI_Fuse_3(t,n,o);Es(e,s,a.optimisation),Ds(s,a.fuzzyValue),s.Build(o);let c=zu(s),l=Mu(e,s,[t,n],r,i,a.simplify??!1,c);return s.delete(),o.delete(),l}function Vu(e,t,n,r,i,a={}){let o=new e.Message_ProgressRange_1,s=new e.BRepAlgoAPI_Cut_3(t,n,o);Es(e,s,a.optimisation),Ds(s,a.fuzzyValue),s.Build(o);let c=zu(s),l=Mu(e,s,[t,n],r,i,a.simplify??!1,c);return s.delete(),o.delete(),l}function Hu(e,t,n,r,i,a={}){let o=new e.Message_ProgressRange_1,s=new e.BRepAlgoAPI_Common_3(t,n,o);Es(e,s,a.optimisation),Ds(s,a.fuzzyValue),s.Build(o);let c=zu(s),l=Mu(e,s,[t,n],r,i,a.simplify??!1,c);return s.delete(),o.delete(),l}function Uu(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=Nu(e,o,t,i,a);return o.delete(),c}function Wu(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=Nu(e,o,t,i,a);return o.delete(),u}function Gu(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=Nu(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=Nu(e,a,t,r,i);return a.delete(),s}function qu(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=Nu(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(),Nu(e,_,t,o,s)}finally{_.delete(),g.delete(),h.delete(),m.delete()}}function Yu(e){return{translateWithHistory:(t,n,r,i,a,o)=>Pu(e,t,n,r,i,a,o),rotateWithHistory:(t,n,r,i,a,o)=>Fu(e,t,n,r,i,a,o),mirrorWithHistory:(t,n,r,i,a)=>Iu(e,t,n,r,i,a),scaleWithHistory:(t,n,r,i,a)=>Lu(e,t,n,r,i,a),generalTransformWithHistory:(t,n,r,i,a,o)=>Ru(e,t,n,r,i,a,o),fuseWithHistory:(t,n,r,i,a)=>Bu(e,t,n,r,i,a),cutWithHistory:(t,n,r,i,a)=>Vu(e,t,n,r,i,a),intersectWithHistory:(t,n,r,i,a)=>Hu(e,t,n,r,i,a),filletWithHistory:(t,n,r,i,a)=>Uu(e,t,n,r,i,a),chamferWithHistory:(t,n,r,i,a)=>Wu(e,t,n,r,i,a),shellWithHistory:(t,n,r,i,a,o)=>Gu(e,t,n,r,i,a,o),thickenWithHistory:(t,n,r,i)=>Ku(e,t,n,r,i),offsetWithHistory:(t,n,r,i,a)=>qu(e,t,n,r,i,a),draftWithHistory:(t,n,r,i,a,o,s)=>Ju(e,t,n,r,i,a,o,s)}}function Xu(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 Zu(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 Qu(e,t,n,r,i){return ju(e,t,n,r,i)}function $u(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 ed(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=$u(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 td(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 nd(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 rd(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 id(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 ad(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 od(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 sd(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 cd(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 ld(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 ud(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 dd(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 fd(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=pd(e,d,f,p);a.Add(h);let g=pd(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 pd(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 md(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 hd(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 gd(e,t){let n=new e.ShapeFix_Wire_1;n.Load_1(t),n.FixSelfIntersection();let r=n.Wire();return n.delete(),r}function _d(){return{gaussian:0,mean:0,max:0,min:0,maxDirection:[1,0,0],minDirection:[0,1,0]}}function vd(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 yd(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=_d();if(h>=1e-15){m.Divide(h);let e=vd(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:bd(o,s,e.du1,e.dv1),minDirection:bd(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 bd(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 xd(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 Sd(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 Cd(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 wd(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 Td(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 Ed(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=Al(`_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=Al(`_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 Od(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=Al(`_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 kd(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):Od(e,t)}function Ad(e){return{composeTransform:t=>Zu(e,t),applyComposedTransformWithHistory:(t,n,r,i)=>Qu(e,t,n,r,i),sweepPipeShell:(t,n,r)=>ed(e,t,n,r??{}),loftAdvanced:(t,n)=>td(e,t,n??{}),buildExtrusionLaw:(t,n,r)=>nd(e,t,n,r),revolveVec:(t,n,r,i)=>rd(e,t,n,r,i),positionOnCurve:(t,n,r)=>od(e,t,n,r),linearPattern:(t,n,r,i)=>id(e,t,n,r,i),circularPattern:(t,n,r,i,a)=>ad(e,t,n,r,i,a),makeNonPlanarFace:t=>sd(e,t),addHolesInFace:(t,n)=>cd(e,t,n),removeHolesFromFace:t=>ld(e,t),makeFaceOnSurface:(t,n)=>ud(e,t,n),bsplineSurface:(t,n,r)=>dd(e,t,n,r),triangulatedSurface:(t,n,r)=>fd(e,t,n,r),sewAndSolidify:(t,n)=>md(e,t,n),fixShape:t=>hd(e,t),fixSelfIntersection:t=>gd(e,t),surfaceCurvature:(t,n,r)=>yd(e,t,n,r),surfaceCenterOfMass:t=>xd(e,t),createDistanceQuery:t=>Sd(e,t),projectEdges:(t,n,r,i)=>Cd(e,t,n,r,i),draftPrism:(t,n,r,i,a,o)=>wd(e,t,n,r,i,a,o),generalTransformNonOrthogonal:(t,n,r)=>Xu(e,t,n,r),createXCAFDocument:t=>Td(e,t),writeXCAFToSTEP:(t,n)=>Ed(e,t,n??{}),exportSTEPConfigured:(t,n)=>kd(e,t,n??{})}}var jd=()=>{};function Md(e){return e}function Nd(e){let t=Md(e);for(;t.__bk2d===`trimmed`;)t=t.basis;return t}function Pd(e){return e}function Fd(e,t){return{x:e,y:t}}function Id(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 Ld(e,t){return{x:e,y:t}}function Rd(e,t,n,r){return{px:e,py:t,dx:n,dy:r,delete:jd}}function zd(e){return e}function Bd(e){return e}function Vd(e,t,n,r){return te(e,t,n,r)}function Hd(e,t,n,r){return ne(e,t,n,r)}function Ud(e,t,n,r,i,a,o){return ae(e,t,n,r,i,a,o)}function Wd(e,t,n,r,i,a,o,s,c){return{__bk2d:`trimmed`,basis:ae(e,t,n,r,o,s,c),tStart:i,tEnd:a}}function Gd(e){return oe(e)}function Kd(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 qd(e,t){return S(Md(e),t)}function Jd(e,t){return{point:S(Md(e),t),tangent:C(Md(e),t)}}function Yd(e){return w(Md(e))}function Xd(e){return ee(Nd(e))}function Zd(e,t,n){return{__bk2d:`trimmed`,basis:Md(e),tStart:t,tEnd:n}}function Qd(e){return JSON.parse(JSON.stringify(e))}function $d(e,t){let n=Md(e),r=w(n),i=[];for(let e=0;e<=30;e++){let a=r.first+(r.last-r.first)*e/30,[o,s]=S(n,a),[c,l]=C(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 Kd(i)}function ef(e,t,n){return se(Md(e),t,n)}function tf(e,t,n,r){return ce(Md(e),t,n,r)}function nf(e,t,n,r){return le(Md(e),t,n,r)}function rf(e,t,n){return ue(Md(e),t,n)}function af(e,t,n,r,i){return de(Md(e),t,n,r,i)}function of(e,t,n,r,i,a){return gf(e,lf(t,n,r,i,a))}function sf(e,t,n){return{m:e,tx:t,ty:n,delete:jd}}function cf(){return sf([1,0,0,0,1,0,0,0,1],0,0)}function lf(e,n,r,i,a){let o=Math.sqrt(r*r+i*i);if(o<1e-15)return cf();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 sf(u,e-t(u,0)*e-t(u,1)*n,n-t(u,3)*e-t(u,4)*n)}function uf(e,t){return sf([1,0,0,0,1,0,0,0,1],e,t)}function df(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 sf(u,d-t(u,0)*d-t(u,1)*f,f-t(u,3)*d-t(u,4)*f)}return sf([-1,0,0,0,-1,0,0,0,1],2*e,2*n)}function ff(e,t,n){let r=Math.cos(e),i=Math.sin(e);return sf([r,-i,0,i,r,0,0,0,1],t-r*t+i*n,n-i*t-r*n)}function pf(e,t,n){return sf([e,0,0,0,e,0,0,0,1],t*(1-e),n*(1-e))}function mf(e,t,n){e.tx=t,e.ty=n}function hf(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 gf(e,n){let r=Md(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 se(r,a,o);let d=w(r),f=[];for(let e=0;e<=20;e++){let[t,n]=S(r,d.first+(d.last-d.first)*e/20);f.push([s*t+c*n+a,l*t+u*n+o])}return oe(f)}function _f(e,t,n){let r=fe(Md(e),Md(t),n),i=r.segments.map(e=>Object.assign(e,{delete(){}}));return{points:r.points,segments:i}}function vf(e,t,n){let r=Md(e),i=w(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]=S(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]=S(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]=S(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]=S(r,a),[s,c]=C(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]=S(r,a);return{param:a,distance:Math.sqrt((c-t)**2+(l-n)**2)}}function yf(e,t,n,r,i,a){let o=Md(e),s=Md(t),c=n,l=i,u=1/0;for(let e=0;e<=50;e++){let t=n+(r-n)*e/50,[d,f]=S(o,t);for(let e=0;e<=50;e++){let n=i+(a-i)*e/50,[r,o]=S(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(s,f),u=vf(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]=S(o,d),h=vf(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]=S(o,d),[h,g]=S(s,f);return Math.sqrt((h-p)**2+(g-m)**2)}function bf(e,n,r,i){let a=Md(e),o=w(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(S(a,t))}u=0;for(let e=0;e<c;e++){let[n,r]=S(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 Kd(l,{degMax:s})}function xf(e){let n=Nd(e);if(n.__bk2d===`bezier`)return[e];if(n.__bk2d!==`bspline`)return xf(bf(e,1e-6,`C2`,10));let r=w(Md(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=S(n,r),l=S(n,i),u=C(n,r),d=C(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 Ce()}function Cf(e,t,n){we(Pd(e),Md(t),n)}function wf(e){let t=Pd(e);return{xMin:t.xMin,yMin:t.yMin,xMax:t.xMax,yMax:t.yMax}}function Tf(e,t){let n=Pd(e),r=Pd(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 Ef(e,t){let n=Pd(e),r=Pd(t);return n.xMax<r.xMin||r.xMax<n.xMin||n.yMax<r.yMin||r.yMax<n.yMin}function Df(e,t,n){let r=Pd(e);return t<r.xMin||t>r.xMax||n<r.yMin||n>r.yMax}function Of(e){let t=Nd(e);return t.__bk2d===`circle`?{cx:t.cx,cy:t.cy,radius:t.radius,isDirect:t.sense}:null}function kf(e){let t=Nd(e);return t.__bk2d===`ellipse`?{majorRadius:t.majorRadius,minorRadius:t.minorRadius,xAxisAngle:t.xDirAngle,isDirect:t.sense}:null}function Af(e){let t=Nd(e);return t.__bk2d===`bezier`?[...t.poles]:null}function jf(e){let t=Nd(e);return t.__bk2d===`bezier`?t.poles.length-1:null}function Mf(e){let t=Nd(e);return t.__bk2d===`bspline`?{poles:[...t.poles],knots:[...t.knots],multiplicities:[...t.multiplicities],degree:t.degree,isPeriodic:t.isPeriodic}:null}function Nf(e){return xe(Md(e))}function Pf(e){return Se(e)}function Ff(e,t){let n=Md(e),r=w(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 If(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 Lf(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 Rf(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 zf(e,n,r,i,a){let o=Md(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 If(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=w(o),[l,u]=S(o,s.first),[d,f]=S(o,(s.first+s.last)/2),[p,m]=S(o,s.last);return Lf(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?If(e,t(n,0),t(n,1)):Rf(e,n)}let l=w(o),u=[];for(let e=0;e<=60;e++){let[t,n]=S(o,l.first+(l.last-l.first)*e/60);u.push(c(t,n))}return Rf(e,u)}function Bf(e,t,n){let r=Md(t),i=w(r),a=[];for(let e=0;e<=60;e++){let[t,o]=S(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 Rf(e,a)}function Vf(e,t){return e.BRep_Tool.Surface_2(t)}function Hf(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(),Kd(o)}function Uf(e,t){e.BRepLib.BuildCurves3d_2(t)}function Wf(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 Gf(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=hs(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 Kf(e){return{wrapCurve2dHandle:e=>zd(e),createCurve2dAdaptor:e=>Bd(e),createPoint2d:(e,t)=>Fd(e,t),createDirection2d:(e,t)=>Id(e,t),createVector2d:(e,t)=>Ld(e,t),createAxis2d:(e,t,n,r)=>Rd(e,t,n,r),makeLine2d:(e,t,n,r)=>Vd(e,t,n,r),makeCircle2d:(e,t,n,r)=>Hd(e,t,n,r),makeArc2dThreePoints:(e,t,n,r,i,a)=>re(e,t,n,r,i,a),makeArc2dTangent:(e,t,n,r,i,a)=>ie(e,t,n,r,i,a),makeEllipse2d:(e,t,n,r,i,a,o)=>Ud(e,t,n,r,i,a,o),makeEllipseArc2d:(e,t,n,r,i,a,o,s,c)=>Wd(e,t,n,r,i,a,o,s,c),makeBezier2d:e=>Gd(e),makeBSpline2d:(e,t)=>Kd(e,t),evaluateCurve2d:(e,t)=>qd(e,t),evaluateCurve2dD1:(e,t)=>Jd(e,t),getCurve2dBounds:e=>Yd(e),getCurve2dType:e=>Xd(e),trimCurve2d:(e,t,n)=>Zd(e,t,n),reverseCurve2d:e=>{},copyCurve2d:e=>Qd(e),offsetCurve2d:(e,t)=>$d(e,t),translateCurve2d:(e,t,n)=>ef(e,t,n),rotateCurve2d:(e,t,n,r)=>tf(e,t,n,r),scaleCurve2d:(e,t,n,r)=>nf(e,t,n,r),mirrorCurve2dAtPoint:(e,t,n)=>rf(e,t,n),mirrorCurve2dAcrossAxis:(e,t,n,r,i)=>af(e,t,n,r,i),affinityTransform2d:(e,t,n,r,i,a)=>of(e,t,n,r,i,a),createIdentityGTrsf2d:()=>cf(),createAffinityGTrsf2d:(e,t,n,r,i)=>lf(e,t,n,r,i),createTranslationGTrsf2d:(e,t)=>uf(e,t),createMirrorGTrsf2d:(e,t,n,r,i,a,o)=>df(e,t,n,r,i,a,o),createRotationGTrsf2d:(e,t,n)=>ff(e,t,n),createScaleGTrsf2d:(e,t,n)=>pf(e,t,n),setGTrsf2dTranslationPart:(e,t,n)=>{mf(e,t,n)},multiplyGTrsf2d:(e,t)=>{hf(e,t)},transformCurve2dGeneral:(e,t)=>gf(e,t),intersectCurves2d:(e,t,n)=>_f(e,t,n),projectPointOnCurve2d:(e,t,n)=>vf(e,t,n),distanceBetweenCurves2d:(e,t,n,r,i,a)=>yf(e,t,n,r,i,a),approximateCurve2dAsBSpline:(e,t,n,r)=>bf(e,t,n,r),decomposeBSpline2dToBeziers:e=>xf(e),createBoundingBox2d:()=>Sf(),addCurveToBBox2d:(e,t,n)=>{Cf(e,t,n)},getBBox2dBounds:e=>wf(e),mergeBBox2d:(e,t)=>{Tf(e,t)},isBBox2dOut:(e,t)=>Ef(e,t),isBBox2dOutPoint:(e,t,n)=>Df(e,t,n),getCurve2dCircleData:e=>Of(e),getCurve2dEllipseData:e=>kf(e),getCurve2dBezierPoles:e=>Af(e),getCurve2dBezierDegree:e=>jf(e),getCurve2dBSplineData:e=>Mf(e),serializeCurve2d:e=>Nf(e),deserializeCurve2d:e=>Pf(e),splitCurve2d:(e,t)=>Ff(e,t),liftCurve2dToPlane:(t,n,r,i)=>zf(e,t,n,r,i),buildEdgeOnSurface:(t,n)=>Bf(e,t,n),extractSurfaceFromFace:t=>Vf(e,t),extractCurve2dFromEdge:(t,n)=>Hf(e,t,n),buildCurves3d:t=>{Uf(e,t)},fixWireOnFace:(t,n,r)=>Wf(e,t,n,r),fillSurface:(t,n)=>Gf(e,t,n)}}function qf(){let e=e=>()=>{throw new c(`${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 new c(`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 Jf(e){return{draft:(t,n,r,i,a)=>Ju(e,t,n,r,i,a,[],1).shape}}var Yf=class{oc;kernelId=`occt`;capabilities=a;constructor(e){this.oc=e,Object.assign(this,Vs(e),Ws(e),lc(e),nc(e),Fc(e),Yc(e),dl(e),wl(e),Ol(e),Ll(e),us(e),ws(e),hu(e),vu(e),xu(e),Tu(e),Yu(e),Ad(e),Kf(e),Jf(e),qf())}},Xf=()=>{};function Zf(e){return typeof e==`object`&&!!e&&e.__brepkit}function Qf(e,t){return{__brepkit:!0,type:e,id:t,delete:Xf,HashCode(e){return t%e},IsNull(){return!1}}}function F(e){return Qf(`solid`,e)}function $f(e){return Qf(`face`,e)}function ep(e){return Qf(`edge`,e)}function tp(e){return Qf(`wire`,e)}function np(e){return Qf(`shell`,e)}function rp(e){let t=Qf(`compound`,e);return yp.has(e)?{...t,delete:()=>yp.delete(e)}:t}function ip(e){return Qf(`vertex`,e)}function I(e,t){if(!Zf(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 L(e){return Array.from(e)}function ap(e,t){if(!Zf(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 op(e,t,n){if(!Zf(t))throw Error(`brepkit: expected a BrepkitHandle, got `+typeof t);if(t.type===`solid`)return[t.id];if(t.type===`compound`){let r=L(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 sp(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 cp(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}function lp(e,t,n){return[1,0,0,e,0,1,0,t,0,0,1,n,0,0,0,1]}function up(e,t){if(!Array.isArray(e)||e.length<3)return t;let[n,r,i]=e;return typeof n==`number`&&typeof r==`number`&&typeof i==`number`&&Number.isFinite(n)&&Number.isFinite(r)&&Number.isFinite(i)?[n,r,i]:t}function dp(e,t=[0,0,1],n=[0,0,0]){let r=up(t,[0,0,1]),i=r[0]===0&&r[1]===0&&r[2]===0?[0,0,1]:r,a=up(n,[0,0,0]),o=e*Math.PI/180,s=Math.cos(o),c=Math.sin(o),l=1-s,u=Math.sqrt(i[0]**2+i[1]**2+i[2]**2),[d,f,p]=[i[0]/u,i[1]/u,i[2]/u],m=l*d*d+s,h=l*d*f-c*p,g=l*d*p+c*f,_=l*f*d+c*p,v=l*f*f+s,y=l*f*p-c*d,b=l*p*d-c*f,x=l*p*f+c*d,S=l*p*p+s,[C,w,ee]=a;return[m,h,g,C-(m*C+h*w+g*ee),_,v,y,w-(_*C+v*w+y*ee),b,x,S,ee-(b*C+x*w+S*ee),0,0,0,1]}function fp(e,t){let[n,r,i]=up(e,[0,0,0]);return[t,0,0,n*(1-t),0,t,0,r*(1-t),0,0,t,i*(1-t),0,0,0,1]}function pp(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 mp(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 hp(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 gp=.01,_p=9e5;function vp(){return _p++}var yp=new Map,bp=new Set;function xp(e,t){bp.has(e)||(bp.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 wp(e){let t=e;for(;t.__bk2d===`trimmed`;)t=t.basis;return t}function Tp(e){return e}function Ep(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=yp.get(t);return r?r.flatMap(t=>t.type===n?[t]:Fp(e,t,n)):n===`solid`?L(e.getCompoundSolids(t)).map(F):n===`face`||n===`edge`||n===`vertex`||n===`wire`?L(e.getCompoundSolids(t)).map(F).flatMap(t=>Fp(e,t,n)):[]}function Op(e,t,n,r){switch(r){case`solid`:return[t];case`shell`:return L(e.getSolidShells(n)).map(np);case`face`:return L(e.getSolidFaces(n)).map($f);case`edge`:return L(e.getSolidEdges(n)).map(ep);case`vertex`:return L(e.getSolidVertices(n)).map(ip);case`wire`:return L(e.getSolidFaces(n)).flatMap(t=>L(e.getFaceWires(t)).map(tp));default:return[]}}function kp(e,t,n){let r=L(e.getShellFaces(t)).map($f),i=new Set,a=[];for(let t of r)for(let r of Fp(e,t,n)){let e=I(r);i.has(e)||(i.add(e),a.push(r))}return a}function Ap(e,t,n,r){return r===`shell`?[t]:r===`face`?L(e.getShellFaces(n)).map($f):r===`edge`||r===`vertex`?kp(e,n,r):[]}function jp(e,t,n,r){return r===`face`?[t]:r===`edge`?L(e.getFaceEdges(n)).map(ep):r===`vertex`?L(e.getFaceVertices(n)).map(ip):r===`wire`?L(e.getFaceWires(n)).map(tp):[]}function Mp(e,n){let r=L(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(ip(e.makeVertex(t,n,r))))}}return a}function Np(e,t,n,r){return r===`wire`?[t]:r===`edge`?L(e.getWireEdges(n)).map(ep):r===`vertex`?Mp(e,n):[]}function Pp(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[ip(i),ip(a)]}return[]}function Fp(e,t,n){let r=I(t);switch(t.type){case`compound`:return Dp(e,r,n);case`solid`:return Op(e,t,r,n);case`shell`:return Ap(e,t,r,n);case`face`:return jp(e,t,r,n);case`wire`:return Np(e,t,r,n);case`edge`:return Pp(e,t,r,n);default:return[]}}function Ip(e,t,n){if(Array.isArray(t))for(let e of t)n(e)}function Lp(e,t){if(Zf(t))return t.type;throw Error(`brepkit: cannot determine shape type of non-brepkit handle`)}function Rp(e,t,n){return Zf(t)&&Zf(n)&&t.id===n.id&&t.type===n.type}function zp(e,t,n){return Rp(e,t,n)}function Bp(e,t,n){return t}function Vp(e,t,n){return Zf(t)?t.id%n:0}function Hp(e,t){return!t||!Zf(t)}function Up(e,t){let n=I(t);return e.getShapeOrientation(n)}function Wp(e,t){let n=ap(t,`edgeToFaceMap`);return e.edgeToFaceMap(n)}function Gp(e,t,n){let r=I(t,`face`),i=I(n,`face`);return Array.from(e.sharedEdges(r,i)).map(e=>ep(e))}function Kp(e,t,n){let r=ap(t,`adjacentFaces`),i=I(n,`face`);return Array.from(e.adjacentFaces(r,i)).map(e=>$f(e))}function qp(e,t){let n=t;return n.type===`face`?[n.id]:n.type===`solid`?L(e.getSolidFaces(n.id)):n.type===`shell`?L(e.getShellFaces(n.id)):[]}function Jp(e,t,n){let r=t.flatMap(t=>qp(e,t)),i=n??1e-7;try{return np(e.weldShellsAndFaces(r,i))}catch(e){console.warn(`brepkit: weldShellsAndFaces failed, falling back to sewFaces:`,e)}return np(e.sewFaces(r,i))}function Yp(e){return{iterShapes:(t,n)=>Fp(e,t,n),iterShapeList:(t,n)=>{Ip(e,t,n)},shapeType:t=>Lp(e,t),isSame:(t,n)=>Rp(e,t,n),isEqual:(t,n)=>zp(e,t,n),downcast:(t,n)=>Bp(e,t,n),copyShape:t=>Bp(e,t),hashCode:(t,n)=>Vp(e,t,n),isNull:t=>Hp(e,t),shapeOrientation:t=>Up(e,t),edgeToFaceMap:t=>Wp(e,t),sharedEdges:(t,n)=>Gp(e,t,n),adjacentFaces:(t,n)=>Kp(e,t,n),sew:(t,n)=>Jp(e,t,n)}}function Xp(e,t){return n(e.getVertexPosition(I(t,`vertex`)))}function Zp(e,t){return e.getSurfaceType(I(t,`face`))}function Qp(e,n){let r=e.getSurfaceDomain(I(n,`face`));return{uMin:t(r,0),uMax:t(r,1),vMin:t(r,2),vMax:t(r,3)}}function $p(e,t){return tp(e.getFaceOuterWire(I(t,`face`)))}function em(e,t,r,i){return n(e.evaluateSurfaceNormal(I(t,`face`),r,i))}function tm(e,t,r,i){return n(e.evaluateSurface(I(t,`face`),r,i))}function nm(e,n,r){try{let i=e.projectPointOnSurface(I(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 rm(e,t,r){return n(e.projectPointOnSurface(I(t,`face`),r[0],r[1],r[2]),2)}function im(e,r,i){let a=r,o,s=i;if(a.type===`wire`){let n=L(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=I(r,`edge`);let c=e.evaluateEdgeCurveD1(o,s);return{point:n(c,0),tangent:n(c,3)}}function am(e,n){let r=n;if(r.type===`wire`){let n=L(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(I(n,`edge`));return[t(i,0),t(i,1)]}function om(e,r,i){let a=r;if(a.type===`wire`){let r=L(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(I(r,`edge`),i))}function sm(e,r){let i=r;if(i.type===`wire`){let r=L(e.getWireEdges(i.id));if(r.length===0)return!1;if(r.length===1)return cm(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=>sp(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 cm(e.getEdgeVertices(I(r,`edge`)))}function cm(e){return sp(t(e,0),t(e,1),t(e,2),t(e,3),t(e,4),t(e,5))<1e-7}function lm(e,t){let n=t;try{if(n.type===`edge`||n.type===`wire`&&L(e.getWireEdges(n.id)).length===1)return sm(e,t)}catch{}return!1}function um(e,t){try{if(lm(e,t)){let n=am(e,t);return n[1]-n[0]}}catch{}return 0}function dm(e,t){if(t.type===`wire`){let n=Fp(e,t,`edge`)[0];return n?e.getEdgeCurveType(I(n,`edge`)):`LINE`}return e.getEdgeCurveType(I(t,`edge`))}function fm(e,t,n){let r=I(t,`edge`);return ep(e.curveDegreeElevate(r,n))}function pm(e,t,n,r){let i=I(t,`edge`);return ep(e.curveKnotInsert(i,n,r))}function mm(e,t,n,r){let i=I(t,`edge`);return ep(e.curveKnotRemove(i,n,r))}function hm(e,n,r){let i=I(n,`edge`),a=e.curveSplit(i,r);return[ep(t(a,0)),ep(t(a,1))]}function gm(e,t,n,r,i,a,o,s,c,l){return $f(e.approximateSurfaceLspia(t,n,r,i,a,o,s,c,l))}function _m(e,t,n,r){let i=I(t,`face`);return $f(e.untrimFace(i,n,r))}function vm(e,t){return t}function ym(e,t){let r=Ym(e,t);return!r||r.controlPoints.length<6?null:n(r.controlPoints,r.controlPoints.length-6)}function bm(e,t){if(Zf(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 xm(e,t){let n=JSON.parse(e.getAnalyticSurfaceParams(I(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&&xp(`classify-tolerance`,`classifyPointOnFace() tolerance parameter is not supported; brepkit uses domain-based classification.`);let o=I(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 wm(e,t,n,r){let i=ap(t,`classifyPointRobust`);return e.classifyPointRobust(i,n[0],n[1],n[2],r)}function Tm(e,t,n,r){let i=ap(t,`classifyPointWinding`);return e.classifyPointWinding(i,n[0],n[1],n[2],r)}function Em(e,t,n,r){let i=ap(t,`detectSmallFeatures`);return Array.from(e.detectSmallFeatures(i,n,r)).map(e=>$f(e))}function Dm(e,t,n){let r=ap(t,`recognizeFeatures`);return e.recognizeFeatures(r,n)}function Om(e,t,r,i,a){let o=I(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=sp(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(ep(e.makeLineEdge(i,a,0,o,s,0)))}let r=vp();return yp.set(r,n),rp(r)},b=()=>{let e=vp();return yp.set(e,[]),rp(e)};return{visible:{outline:y(v.visible),smooth:b(),sharp:b()},hidden:{outline:y(v.hidden),smooth:b(),sharp:b()}}}function km(e,t){let n=I(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 Am(e,t){return JSON.parse(e.getNurbsSurfaceDataParity(I(t,`face`)))}function jm(e){return{vertexPosition:t=>Xp(e,t),surfaceType:t=>Zp(e,t),uvBounds:t=>Qp(e,t),outerWire:t=>$p(e,t),surfaceNormal:(t,n,r)=>em(e,t,n,r),pointOnSurface:(t,n,r)=>tm(e,t,n,r),uvFromPoint:(t,n)=>nm(e,t,n),projectPointOnFace:(t,n)=>rm(e,t,n),curveTangent:(t,n)=>im(e,t,n),curveParameters:t=>am(e,t),curvePointAtParam:(t,n)=>om(e,t,n),curveIsClosed:t=>sm(e,t),curveIsPeriodic:t=>lm(e,t),curvePeriod:t=>um(e,t),curveType:t=>dm(e,t),curveDegreeElevate:(t,n)=>fm(e,t,n),curveKnotInsert:(t,n,r)=>pm(e,t,n,r),curveKnotRemove:(t,n,r)=>mm(e,t,n,r),curveSplit:(t,n)=>hm(e,t,n),approximateSurfaceLspia:(t,n,r,i,a,o,s,c,l)=>gm(e,t,n,r,i,a,o,s,c,l),untrimFace:(t,n,r)=>_m(e,t,n,r),createCurveAdaptor:t=>vm(e,t),getBezierPenultimatePole:t=>ym(e,t),getSurfaceCylinderData:t=>bm(e,t),getSurfaceAxis:t=>xm(e,t),reverseSurfaceU:t=>Sm(e,t),classifyPointOnFace:(t,n,r,i)=>Cm(e,t,n,r,i),classifyPointRobust:(t,n,r)=>wm(e,t,n,r),classifyPointWinding:(t,n,r)=>Tm(e,t,n,r),detectSmallFeatures:(t,n,r)=>Em(e,t,n,r),recognizeFeatures:(t,n)=>Dm(e,t,n),projectEdges:(t,n,r,i)=>Om(e,t,n,r,i),getNurbsCurveData:t=>km(e,t),getNurbsSurfaceData:t=>Am(e,t)}}function Mm(e,t,n){if(Array.isArray(n)&&n.length===16)return Gm(e,t,n);throw Error(`brepkit: transform expects a 16-element matrix array`)}function Nm(e,t,n,r,i){return Gm(e,t,lp(n,r,i))}function Pm(e,t,n,r,i){return Gm(e,t,dp(n,r,i))}function Fm(e,t,n,r){let i=t;return i.type===`solid`?F(e.mirror(i.id,n[0],n[1],n[2],r[0],r[1],r[2])):Gm(e,t,mp(n,r))}function Im(e,t,n,r){return Gm(e,t,fp(n,r))}function Lm(e,t,n,r,i){return Gm(e,t,pp(n,r))}function Rm(e,t,n,r){return Gm(e,t,pp(n,r))}function zm(e,t,n,r){let{point:i,tangent:a}=im(e,n,r),[o,s,c]=a,l=Math.sqrt(o*o+s*s+c*c);if(l<1e-12)return Nm(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=Pm(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=Pm(e,p,n,t)}return Nm(e,p,i[0],i[1],i[2])}function Bm(e,t,n,r,i){let a=[t];for(let o=1;o<i;o++){let i=r*o;a.push(Nm(e,t,n[0]*i,n[1]*i,n[2]*i))}return a}function Vm(e,t,n,r,i,a){let o=[t];for(let s=1;s<a;s++)o.push(Pm(e,t,i*s,r,n));return o}function Hm(e,t,n,r,i,a,o,s){return rp(e.gridPattern(ap(t,`gridPattern`),n[0],n[1],n[2],r[0],r[1],r[2],i,a,o,s))}function Um(e,t){return t.map(t=>{switch(t.type){case`translate`:return Nm(e,t.shape,t.x,t.y,t.z);case`rotate`:return Pm(e,t.shape,t.angle,t.axis,t.center);case`scale`:return Im(e,t.shape,t.center,t.factor);case`mirror`:return Fm(e,t.shape,t.origin,t.normal)}})}function Wm(e){return{transform:(t,n)=>Mm(e,t,n),locate:(t,n)=>Mm(e,t,n),translate:(t,n,r,i)=>Nm(e,t,n,r,i),rotate:(t,n,r,i)=>Pm(e,t,n,r,i),mirror:(t,n,r)=>Fm(e,t,n,r),scale:(t,n,r)=>Im(e,t,n,r),generalTransform:(t,n,r,i)=>Lm(e,t,n,r,i),generalTransformNonOrthogonal:(t,n,r)=>Rm(e,t,n,r),positionOnCurve:(t,n,r)=>zm(e,t,n,r),linearPattern:(t,n,r,i)=>Bm(e,t,n,r,i),circularPattern:(t,n,r,i,a)=>Vm(e,t,n,r,i,a),gridPattern:(t,n,r,i,a,o,s)=>Hm(e,t,n,r,i,a,o,s),transformBatch:t=>Um(e,t)}}function Gm(e,t,n){let r=t;if(!Zf(t))throw Error(`brepkit: applyMatrix requires a BrepkitHandle`);switch(r.type){case`solid`:{let t=e.copySolid(r.id);return e.transformSolid(t,n),F(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),$f(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),tp(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),ep(t)}default:throw Error(`brepkit: applyMatrix does not support '${r.type}' shapes`)}}function Km(e,t){return!!(e&&(e[0]!==0||e[1]!==0||e[2]!==0)||t&&(t[0]!==0||t[1]!==0||t[2]!==1))}function qm(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=Pm(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=Pm(e,i,n,t)}}return n&&(n[0]!==0||n[1]!==0||n[2]!==0)&&(i=Nm(e,i,n[0],n[1],n[2])),i}function Jm(e,t){let r,i=t;if(i.type===`solid`||i.type===`compound`){let n=Fp(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=I(i,`face`),o=0;for(let t of n){let n=I(t,`face`);try{let t=e.faceArea(n,gp);t>o&&(o=t,a=n)}catch{}}r=a}else r=I(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 Ym(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 Xm(e,t){if(!Zf(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 Zm(e,t){if(!Zf(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 Qm(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(I(t));return n>0&&console.warn(`brepkit: repairSolid left ${n} error(s) on solid.`),t}catch(n){try{return e.healSolid(I(t)),t}catch(e){return console.warn(`brepkit: healSolid failed (repairSolid error:`,n,`, healSolid error:`,e,`)`),null}}}function $m(e,t){return t}function eh(e,t,n){return t}function th(e,t,n){let r=ap(t,`mergeCoincidentVertices`);return e.mergeCoincidentVertices(r,n)}function nh(e,t,n){let r=ap(t,`removeDegenerateEdges`);return e.removeDegenerateEdges(r,n)}function rh(e,t){let n=ap(t,`fixFaceOrientations`);return e.fixFaceOrientations(n)}function ih(e,t){let n=t;return n.type===`solid`&&e.healSolid(n.id),t}function ah(e,t){return t}function oh(e,t){if(!Zf(t)||t.type!==`solid`)return null;try{return typeof e.validateSolidDetails==`function`?e.validateSolidDetails(t.id):null}catch{return null}}function sh(e){return{isValid:t=>Xm(e,t),isValidStrict:t=>Zm(e,t),healSolid:t=>Qm(e,t),healFace:t=>$m(e,t),healWire:(t,n)=>eh(e,t,n),fixShape:t=>ih(e,t),fixSelfIntersection:t=>ah(e,t),mergeCoincidentVertices:(t,n)=>th(e,t,n),removeDegenerateEdges:(t,n)=>nh(e,t,n),fixFaceOrientations:t=>rh(e,t),validationDetails:t=>oh(e,t)}}function ch(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 lh(e,t){return t.type===`compound`?L(e.getCompoundSolids(t.id)).length===0:!1}function uh(e){return rp(e.makeCompound([]))}function dh(e,t,n,r){if(r&&Sp(r)&&xp(`boolean-options`,`BooleanOptions (optimisation, simplify, strategy, fuzzyValue) not supported; ignored.`),lh(e,t))return n;if(lh(e,n))return t;let i=ap(t,`fuse`),a=n;if(a.type===`compound`){let t=L(e.getCompoundSolids(a.id)),n=i;for(let r of t)n=e.fuse(n,r);return F(n)}return F(e.fuse(i,ap(n,`fuse`)))}function fh(e,t,n,r){if(r&&Sp(r)&&xp(`boolean-options`,`BooleanOptions (optimisation, simplify, strategy, fuzzyValue) not supported; ignored.`),lh(e,t))return uh(e);if(lh(e,n))return t;let i=ap(t,`cut`),a=n;if(a.type===`compound`){let t=L(e.getCompoundSolids(a.id)),n=i;for(let r of t)try{n=e.cut(n,r)}catch(t){if(ch(t))return uh(e);throw t}return F(n)}try{return F(e.cut(i,ap(n,`cut`)))}catch(t){if(ch(t))return uh(e);throw t}}function ph(e,t,n,r){if(r&&Sp(r)&&xp(`boolean-options`,`BooleanOptions (optimisation, simplify, strategy, fuzzyValue) not supported; ignored.`),lh(e,t)||lh(e,n))return uh(e);try{return F(e.intersect(ap(t,`intersect`),ap(n,`intersect`)))}catch(t){if(ch(t))return uh(e);throw t}}function mh(e,n,r,i){let{point:a,normal:o}=Jm(e,r),s=Zf(n)&&n.type===`solid`?n.id:I(n,`solid`),c=L(e.section(s,a[0],a[1],a[2],o[0],o[1],o[2]));if(c.length===0)return rp(e.makeCompound([]));let l=[];for(let n=0;n<c.length;n++){let r=L(e.getFaceWires(t(c,n)));for(let e=0;e<r.length;e++)l.push(tp(t(r,e)))}let[u]=l;if(l.length===1&&u!==void 0)return u;let d=vp();return yp.set(d,l),rp(d)}function hh(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(...L(e.getCompoundSolids(n.id))):t.push(ap(r,`fuseAll`))}if(t.length===0)throw Error(`brepkit: fuseAll resolved to zero solid IDs`);return F(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(dh(e,i[n],i[n+1],r)):t.push(i[n]);i=t}return t(i,0)}function gh(e,t,n,r){if(n.length===0)return t;if(n.length===1)return fh(e,t,n[0],r);let i=ap(t,`cutAll`),a=[];for(let t of n){let n=t;n.type===`compound`?a.push(...L(e.getCompoundSolids(n.id))):a.push(ap(t,`cutAll`))}return a.length===0?t:F(e.compoundCut(i,new Uint32Array(a)))}function _h(e,t,n){if(n.length===0)throw Error(`brepkit: split requires at least one tool`);let{point:r,normal:i}=Jm(e,n[0]),a=L(e.split(I(t,`solid`),r[0],r[1],r[2],i[0],i[1],i[2]));return rp(e.makeCompound(a))}function vh(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 yh(e,t,n,r,i){let a=[];return(!Zf(t)||t.IsNull())&&a.push({operand:`base`,issue:`null-shape`,message:`Base shape is null`}),(!Zf(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 bh(e,n,r){let i=[];for(let r of n){let n=r;if(n.type===`solid`){let r=L(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 F(e.convexHull(i))}function xh(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 F(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 F(e.importIndexedMesh(a,o))}function Ch(e){return{fuse:(t,n,r)=>dh(e,t,n,r),cut:(t,n,r)=>fh(e,t,n,r),intersect:(t,n,r)=>ph(e,t,n,r),section:(t,n,r)=>mh(e,t,n,r),fuseAll:(t,n)=>hh(e,t,n),cutAll:(t,n,r)=>gh(e,t,n,r),split:(t,n)=>_h(e,t,n),meshBoolean:(t,n,r,i,a,o)=>vh(e,t,n,r,i,a,o),checkBoolean:(t,n,r)=>yh(e,t,n,r,t=>Xm(e,t)),hull:(t,n)=>bh(e,t,n),hullFromPoints:(t,n)=>xh(e,t,n),buildSolidFromFaces:(t,n,r)=>Sh(e,t,n,r)}}function wh(e,t,n,r){return ip(e.makeVertex(t,n,r))}function Th(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 Fh(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(Zf(t)&&t.type===`edge`)return t;throw Error(`brepkit: makeEdge requires a curve with origin/direction, or an edge handle`)}function Eh(e,t){let n=[];for(let r of t){let t=r;if(t.type===`wire`)for(let r of L(e.getWireEdges(t.id)))n.push(r);else n.push(I(r,`edge`))}return tp(e.makeWire(n,!0))}function Dh(e,t,n){let r=t,i=r.type===`edge`?e.makeWire([r.id],!0):I(t,`wire`);return $f(n?e.makePlanarFaceFromWire(i):e.makeFaceFromWire(i))}function Oh(e,t,n,r){return F(e.makeBox(t,n,r))}function kh(e,t,n){return $f(e.makeRectangle(t,n))}function Ah(e,t,n,r,i){let a=F(e.makeCylinder(t,n));return Km(r,i)?qm(e,a,r,i):a}function jh(e,t,n){let r=F(e.makeSphere(t,32));return n&&(n[0]!==0||n[1]!==0||n[2]!==0)?Nm(e,r,n[0],n[1],n[2]):r}function Mh(e,t,n,r,i,a){let o=F(e.makeCone(t,n,r));return Km(i,a)?qm(e,o,i,a):o}function Nh(e,t,n,r,i){let a=F(e.makeTorus(t,n,32));return Km(r,i)?qm(e,a,r,i):a}function Ph(e,t,n,r){let i=Math.max(t,n,r);return Lm(e,jh(e,i),[t/i,0,0,0,n/i,0,0,0,r/i],[0,0,0],!1)}function Fh(e,t,n){return ep(e.makeLineEdge(t[0],t[1],t[2],n[0],n[1],n[2]))}function Ih(e,t,n,r){let i=Math.sqrt(n[0]**2+n[1]**2+n[2]**2);return ep(e.makeCircleEdge(t[0],t[1],t[2],n[0]/i,n[1]/i,n[2]/i,r))}function Lh(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 ep(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 dg(e,t,n,r,i,a)}function Rh(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 zh(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 Fh(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=Rh(p,m,h,g,_,v);if(!y)return Fh(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 ep(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 Bh(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 ep(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 ep(e.makeEllipseEdge(t[0],t[1],t[2],n[0]/o,n[1]/o,n[2]/o,r,i))}function Vh(e,t,n,r,i,a,o,s){return fg(e,t,n,r,i,a,o,s)}function Hh(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 ep(e.makeNurbsEdge(c[0],c[1],c[2],l[0],l[1],l[2],r,a,s,o))}function Uh(e,t,n,r){return ep(e.makeTangentArc3d(t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]))}function Wh(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 Eh(e,[rg(e,p)])}function Gh(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 L(e.getWireEdges(t.id)))n.push(r)}if(n.length===0)throw Error(`brepkit: makeWireFromMixed requires at least one edge`);return tp(e.makeWire(n,!1))}function Kh(e,t){let n=t.filter(Zf);if(n.length===0)throw Error(`brepkit: makeCompound requires at least one shape`);if(n.every(e=>e.type===`solid`))return rp(e.makeCompound(n.map(e=>e.id)));let r=vp();return yp.set(r,n),rp(r)}function qh(e,t,n){let r=Oh(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?Nm(e,r,i,a,o):r}function Jh(e,t){let n=t;if(n.type===`solid`)return t;if(n.type===`shell`){try{return e.getSolidFaces(n.id),F(n.id)}catch{}return F(e.solidFromShell(n.id))}return F(e.solidFromShell(I(t,`shell`)))}function Yh(e,t){return Dh(e,t,!1)}function Xh(e,t,n){let r=n.map(e=>I(e,`wire`));return $f(e.addHolesToFace(I(t,`face`),r))}function Zh(e,t){return $f(e.removeHolesFromFace(I(t,`face`)))}function Qh(e,t,n){return Dh(e,n,!1)}function $h(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 $f(e.interpolateSurface(i,n,r,a,o))}catch{return eg(e,t,n,r)}}function eg(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=tg(e,t(n,s),t(n,c),t(n,l));d&&a.push(d);let f=tg(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 Jp(e,a,1e-6)}function tg(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,Eh(e,[Fh(e,t,n),Fh(e,n,r),Fh(e,r,t)]))}catch(e){return console.warn(`brepkit: makeNonPlanarFace failed:`,e),null}}function ng(e,t,n){let r=t.map(e=>I(e,`face`));return F(e.sewFaces(r,n))}function rg(e,n,r){if(r?.tolerance!==void 0&&xp(`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 Fh(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 ep(e.interpolatePoints(a,i))}function ig(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 ep(e.approximateCurveLspia(a,r,o,i,100))}function ag(e,t,n,r){return{x:t,y:n,z:r}}function og(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 sg(e,t,n,r){return{x:t,y:n,z:r}}function cg(e,t,n,r,i,a,o){return{origin:[t,n,r],direction:[i,a,o]}}function lg(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 ug(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 dg(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 ep(e.makeNurbsEdge(b,x,S,C,w,ee,2,v,g,_))}function fg(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 ep(e.makeNurbsEdge(y,b,x,S,C,w,2,_,h,g))}function pg(e){return{makeVertex:(t,n,r)=>wh(e,t,n,r),makeEdge:(t,n,r)=>Th(e,t,n,r),makeWire:t=>Eh(e,t),makeWireFromMixed:t=>Gh(e,t),makeFace:(t,n)=>Dh(e,t,n),makeBox:(t,n,r)=>Oh(e,t,n,r),makeRectangle:(t,n)=>kh(e,t,n),makeCylinder:(t,n,r,i)=>Ah(e,t,n,r,i),makeSphere:(t,n)=>jh(e,t,n),makeCone:(t,n,r,i,a)=>Mh(e,t,n,r,i,a),makeTorus:(t,n,r,i)=>Nh(e,t,n,r,i),makeEllipsoid:(t,n,r)=>Ph(e,t,n,r),makeLineEdge:(t,n)=>Fh(e,t,n),makeCircleEdge:(t,n,r)=>Ih(e,t,n,r),makeCircleArc:(t,n,r,i,a)=>Lh(e,t,n,r,i,a),makeArcEdge:(t,n,r)=>zh(e,t,n,r),makeEllipseEdge:(t,n,r,i,a)=>Bh(e,t,n,r,i,a),makeEllipseArc:(t,n,r,i,a,o,s)=>Vh(e,t,n,r,i,a,o,s),makeBezierEdge:t=>Hh(e,t),makeTangentArc:(t,n,r)=>Uh(e,t,n,r),makeHelixWire:(t,n,r,i,a,o)=>Wh(e,t,n,r,i,a,o),makeCompound:t=>Kh(e,t),makeBoxFromCorners:(t,n)=>qh(e,t,n),solidFromShell:t=>Jh(e,t),makeNonPlanarFace:t=>Yh(e,t),addHolesInFace:(t,n)=>Xh(e,t,n),removeHolesFromFace:t=>Zh(e,t),makeFaceOnSurface:(t,n)=>Qh(e,t,n),bsplineSurface:(t,n,r)=>$h(e,t,n,r),triangulatedSurface:(t,n,r)=>eg(e,t,n,r),buildTriFace:(t,n,r)=>tg(e,t,n,r),sewAndSolidify:(t,n)=>ng(e,t,n),interpolatePoints:(t,n)=>rg(e,t,n),approximatePoints:(t,n)=>ig(e,t,n),createPoint3d:(t,n,r)=>ag(e,t,n,r),createDirection3d:(t,n,r)=>og(e,t,n,r),createVector3d:(t,n,r)=>sg(e,t,n,r),createAxis1:(t,n,r,i,a,o)=>cg(e,t,n,r,i,a,o),createAxis2:(t,n,r,i,a,o,s,c,l)=>lg(e,t,n,r,i,a,o,s,c,l),createAxis3:(t,n,r,i,a,o,s,c,l)=>ug(e,t,n,r,i,a,o,s,c,l)}}function mg(e,t,n,r){let i=ap(t,`fillet`),a=n.map(e=>I(e,`edge`));if(typeof r==`number`)return F(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 F(e.filletVariable(i,JSON.stringify(o)))}function hg(e,t,n,r){let i=ap(t,`chamfer`),a=n.map(e=>I(e,`edge`));if(typeof r==`number`)return F(e.chamfer(i,a,r));if(Array.isArray(r)){let[t,n]=r;return typeof e.chamferAsymmetric==`function`?F(e.chamferAsymmetric(i,a,t,n)):(xp(`chamfer-asymmetric`,`chamferAsymmetric not available; using averaged distance.`),F(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):(xp(`chamfer-callback`,`chamferAsymmetric not available; asymmetric edges use averaged distance.`),s=e.chamfer(s,t.ids,(t.d1+t.d2)/2));return F(s)}function gg(e,t,n,r,i){let a=r*Math.tan(i*Math.PI/180),o=ap(t,`chamferDistAngle`),s=n.map(e=>I(e,`edge`));return typeof e.chamferAsymmetric==`function`?F(e.chamferAsymmetric(o,s,r,a)):(xp(`chamfer-dist-angle`,`chamferAsymmetric not available; using averaged distance.`),F(e.chamfer(o,s,(r+a)/2)))}function _g(e,n){let r=L(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 vg(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 yg(e,t,n){try{let r=_g(e,t);if(r===null)return null;let i=-1,a=1/0;for(let t of n)try{let n=_g(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 bg(e,t,n,r){if(r.has(t))return t;let i=vg(e,t,n);if(i!==null)return i;let a=yg(e,t,n);return a===null?t:a}function xg(e,t,n,r,i){i!==void 0&&xp(`shell-tolerance`,`shell() tolerance parameter is not supported; brepkit uses its own internal tolerance.`);let a=ap(t,`shell`),o=L(e.getSolidFaces(a)),s=new Set(o),c=n.map(t=>bg(e,I(t,`face`),o,s));return F(e.shell(a,r,c))}function Sg(e,t,n){let r=t;if(r.type===`face`)return F(e.thicken(r.id,n));throw Error(`brepkit: thicken() requires a face`)}function Cg(e,t,n,r){r!==void 0&&xp(`offset-tolerance`,`offset() tolerance parameter is not supported; brepkit uses its own internal tolerance.`);let i=t;if(i.type===`face`)return F(e.thicken(i.id,n));let a=ap(t,`offset`);return F(e.offsetSolidV2(a,n))}function wg(e,t,n){let r=ap(t,`filletVariable`);return F(e.filletVariable(r,n))}function Tg(e,t,n,r,i,a){let o=ap(t,`draft`),s=n.map(e=>I(e,`face`));return F(e.draft(o,s,r[0],r[1],r[2],i[0],i[1],i[2],a))}function Eg(e,t,n){let r=ap(t,`defeature`),i=n.map(e=>I(e,`face`));return F(e.defeature(r,i))}function Dg(e){switch(e){case`arc`:case`tangent`:return`arc`;case`intersection`:return`intersection`;default:return`intersection`}}function Og(e,n,r,i){if(typeof e.offsetWire2DWithJoin==`function`)return tp(e.offsetWire2DWithJoin(I(n,`wire`),r,Dg(i)));let a=Fp(e,n,`edge`);if(a.length===0)return n;let o=[];for(let n of a){let r=e.getEdgeVertices(I(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 tp(e.makePolygonWire(c))}function kg(e,t){if(t.type===`solid`)try{e.healSolid(I(t))}catch(e){console.warn(`brepkit: healing failed in simplify:`,e)}return t}function Ag(e,t){let n=t,r=e.reverseShape(n.id);return Qf(n.type,r)}function jg(e){return{fillet:(t,n,r)=>mg(e,t,n,r),chamfer:(t,n,r)=>hg(e,t,n,r),chamferDistAngle:(t,n,r,i)=>gg(e,t,n,r,i),shell:(t,n,r,i)=>xg(e,t,n,r,i),thicken:(t,n)=>Sg(e,t,n),offset:(t,n,r)=>Cg(e,t,n,r),filletVariable:(t,n)=>wg(e,t,n),draft:(t,n,r,i,a)=>Tg(e,t,n,r,i,Ep(n,a)),defeature:(t,n)=>Eg(e,t,n),offsetWire2D:(t,n,r)=>Og(e,t,n,r),simplify:t=>kg(e,t),reverseShape:t=>Ag(e,t)}}function Mg(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=F(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 Ng(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 Pg(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 Fg(e,t,n){try{return{hash:n,normal:e.getFaceNormal(t),centroid:Pg(e,t)}}catch{return{hash:n,normal:[0,0,0],centroid:Pg(e,t)}}}var Ig=.707,Lg=100,Rg=.05;function zg(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<Ig)continue;let c=Ng(e.centroid,o.centroid);if(c>Lg)continue;let l=s-c/Lg;l>r&&(r=l),i.push({idx:a,score:l})}return{matches:i,bestScore:r}}function Bg(e,t){let n=1/0,r;for(let i of t){let t=Ng(e.centroid,i.centroid);t<n&&(n=t,r=i)}return r}function Vg(e,n,r,i,a,o,s,c){let l=n;if(l.type!==`solid`)return;let u=L(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(Fg(e,i,r[n]??i%a))}let p=i.map(t=>Fg(e,t,t%a)),m=new Set;for(let e of p){let{matches:n,bestScore:r}=zg(e,f);if(n.length>0){for(let i of n)if(i.score>=r-Rg){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=Bg(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 Hg(e,t,n,r,i,a,o,s){let c=new Set(s),l=new Map(a);Vg(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 Ug(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 Wg(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?Hg(e,l,d,f,a,o,s,c):Ug(i,r,u,t,s,c)}else if(l)Vg(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 Gg(e,n,r,i,a,o){let s=n,c=new Map,l=new Map,u=new Set;if(s.type===`solid`){let n=L(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 Wg(e,n,d,r,i,c,l,u,o)}return{shape:n,evolution:{modified:c,generated:l,deleted:u}}}function Kg(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 qg(e,t){let n=new Set;Kg(t.combinedModified,e.evolution.modified,e.evolution.deleted,n,t.combinedDeleted),Kg(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 Jg(e,t,n,r,i,a){let o=L(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=Mg(a(t.id,e),i);s=n.shape,qg(n,c)}return{shape:s,accum:c}}function Yg(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{...Mg(o(u.id,d.id),i),diagnostics:l}}catch(e){if(!ch(e))throw e}if(d.type===`compound`){let{shape:n,accum:a}=Jg(e,t,d.id,r,i,o);return{shape:n,evolution:{modified:a.combinedModified,generated:a.combinedGenerated,deleted:a.combinedDeleted},diagnostics:l}}}return{...Gg(e,s(t,n,a),r,i,!1,t),diagnostics:l}}function Xg(e,t,n,r,i,a,o){return Gg(e,Nm(e,t,n,r,i),a,o,!0)}function Zg(e,t,n,r,i,a,o){return Gg(e,Pm(e,t,n*180/Math.PI,a,o),r,i,!0)}function Qg(e,t,n,r,i,a){return Gg(e,Fm(e,t,n,r),i,a,!0)}function $g(e,t,n,r,i,a){return Gg(e,Im(e,t,n,r),i,a,!0)}function e_(e,t,n,r,i,a,o){return Gg(e,Lm(e,t,n,r,i),a,o,!0)}function t_(e,t,n,r,i,a){return Yg(e,t,n,r,i,a,(t,n)=>e.fuseWithEvolution(t,n),(t,n,r)=>dh(e,t,n,r),`fuseWithHistory`)}function n_(e,t,n,r,i,a){return Yg(e,t,n,r,i,a,(t,n)=>e.cutWithEvolution(t,n),(t,n,r)=>fh(e,t,n,r),`cutWithHistory`)}function r_(e,t,n,r,i,a){return Yg(e,t,n,r,i,a,(t,n)=>e.intersectWithEvolution(t,n),(t,n,r)=>ph(e,t,n,r),`intersectWithHistory`)}function i_(e,t,n,r,i,a){return Gg(e,mg(e,t,n,r),i,a,!1,t)}function a_(e,t,n,r,i,a){return Gg(e,hg(e,t,n,r),i,a,!1,t)}function o_(e,t,n,r,i,a,o){return Gg(e,xg(e,t,n,r,o),i,a,!1,t)}function s_(e,t,n,r,i){return Gg(e,Sg(e,t,n),r,i,!1,t)}function c_(e,t,n,r,i,a){return Gg(e,Cg(e,t,n,a),r,i,!1,t)}function l_(e,t,n,r,i,a,o,s){return Gg(e,Tg(e,t,n,r,i,a),o,s,!1,t)}function u_(e,t,n,r,i){return Gg(e,Gm(e,t,n),r,i,!0)}function d_(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=hp(e.type===`translate`?lp(e.x,e.y,e.z):dp(e.angle,e.axis,e.center),n);return{handle:n,dispose:()=>{}}}function f_(e){return{translateWithHistory:(t,n,r,i,a,o)=>Xg(e,t,n,r,i,a,o),rotateWithHistory:(t,n,r,i,a,o)=>Zg(e,t,n,r,i,a,o),mirrorWithHistory:(t,n,r,i,a)=>Qg(e,t,n,r,i,a),scaleWithHistory:(t,n,r,i,a)=>$g(e,t,n,r,i,a),generalTransformWithHistory:(t,n,r,i,a,o)=>e_(e,t,n,r,i,a,o),fuseWithHistory:(t,n,r,i,a)=>t_(e,t,n,r,i,a),cutWithHistory:(t,n,r,i,a)=>n_(e,t,n,r,i,a),intersectWithHistory:(t,n,r,i,a)=>r_(e,t,n,r,i,a),filletWithHistory:(t,n,r,i,a)=>i_(e,t,n,r,i,a),chamferWithHistory:(t,n,r,i,a)=>a_(e,t,n,r,i,a),shellWithHistory:(t,n,r,i,a,o)=>o_(e,t,n,r,i,a,o),thickenWithHistory:(t,n,r,i)=>s_(e,t,n,r,i),offsetWithHistory:(t,n,r,i,a)=>c_(e,t,n,r,i,a),draftWithHistory:(t,n,r,i,a,o,s)=>l_(e,t,n,r,i,Ep(n,a),o,s),applyComposedTransformWithHistory:(t,n,r,i)=>u_(e,t,n,r,i),composeTransform:t=>d_(e,t)}}function p_(e,t,n){let r=I(t),i=t,a=n.tolerance||.01,o=n.angularTolerance>0?n.angularTolerance:void 0,s;if(i.type===`solid`)s=g_(e,r,a,!!n.includeUVs,o);else if(i.type===`face`)s=x_(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 m_(e,n,r,i){let a=n;if(a.type!==`solid`)return{lines:new Float32Array,edgeGroups:[]};let o=i>0?i:void 0,s=e.meshEdgesAll(a.id,r,o),c=s.positions,l=s.offsets,u=s.edgeCount,d=[];for(let e=0;e<u;e++){let n=t(l,e),r=((e+1<u?t(l,e+1):c.length)-n)/3;d.push({start:n/3,count:r,edgeHash:e})}return{lines:new Float32Array(c),edgeGroups:d}}function h_(e,t){return!1}function g_(e,t,n,r,i){try{return __(e,t,n,r,i)}catch(r){return console.warn(`brepkit: tessellateSolidGrouped failed (solidId=${t}), falling back to per-face:`,r),b_(e,t,n,i)}}function __(e,t,n,r,i){return typeof e.tessellateSolidGroupedBinary==`function`?v_(e,t,n,r,i,e.tessellateSolidGroupedBinary(t,n,i)):y_(e,t,n,r,i)}function v_(e,n,r,i,a,o){let s=o.positions,c=o.normals,l=o.indices,u=o.faceOffsets,d=L(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 y_(e,n,r,i,a){let o=e.tessellateSolidGrouped(n,r,a),s=JSON.parse(o),c=L(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 b_(e,t,n,r){let i=L(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 x_(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)=>p_(e,t,n),meshEdges:(t,n,r)=>m_(e,t,n,r),hasTriangulation:t=>h_(e,t),meshShape:(e,t,n)=>{}}}function C_(e,t){if(t.length===0)return``;let n=[];for(let r of t){let t=op(e,r,`exportSTEP`);for(let r of t){let t=e.exportStep(r);n.push(new TextDecoder().decode(t))}}return n.join(`
|
|
8
|
+
`)}function w_(e,n,r,i=De,a=Oe){let{vertices:o,triangles:s}=p_(e,F(t(op(e,n,`exportSTL`),0)),{tolerance:i,angularTolerance:a,skipNormals:!0});return r?je(o,s):Me(o,s)}function T_(e,t){let n=typeof t==`string`?new TextEncoder().encode(t):new Uint8Array(t);return L(e.importStep(n)).map(F)}function E_(e,t){let n=typeof t==`string`?new TextEncoder().encode(t):new Uint8Array(t);return F(e.importStl(n))}function D_(e,t){if(t.length===0)return``;let n=[];for(let r of t){let t=op(e,r,`exportIGES`);for(let r of t){let t=e.exportIges(r);n.push(new TextDecoder().decode(t))}}return n.join(`
|
|
9
|
+
`)}function O_(e,t){let n=typeof t==`string`?new TextEncoder().encode(t):new Uint8Array(t);return L(e.importIges(n)).map(F)}function k_(e,t,n){return t.length===0?``:C_(e,t.map(e=>e.shape))}function A_(e,t,n){let r=ap(t,`export3MF`);return cp(e.export3mf(r,n))}function j_(e,t,n){let r=ap(t,`exportGLB`);return cp(e.exportGlb(r,n))}function M_(e,t,n){let r=ap(t,`exportOBJ`);return cp(e.exportObj(r,n))}function N_(e,t,n){let r=ap(t,`exportPLY`);return cp(e.exportPly(r,n))}function P_(e,t){return L(e.import3mf(new Uint8Array(t))).map(e=>F(e))}function F_(e,t){return F(e.importObj(new Uint8Array(t)))}function I_(e,t){return F(e.importGlb(new Uint8Array(t)))}function L_(e,t){let n=t;return n.type===`solid`?e.toBREP(n.id):(xp(`brep-non-solid`,`toBREP for non-solid shapes uses STEP format.`),C_(e,[t]))}function R_(e,t){if(typeof e.fromBREP==`function`&&t.trimStart().startsWith(`{`))return F(e.fromBREP(t));let n=T_(e,t)[0];if(!n)throw Error(`brepkit: fromBREP produced no shapes`);return n}function z_(e,t){return{__brepkit_xcaf:!0,shapes:t,delete:Xf}}function B_(e,t,n){return t&&t.__brepkit_xcaf&&Array.isArray(t.shapes)?C_(e,t.shapes.map(e=>e.shape)):``}function V_(e,t,n){return C_(e,t.map(e=>e.shape))}function H_(e){return{exportSTEP:t=>C_(e,t),exportSTL:(t,n,r,i)=>w_(e,t,n,r,i),importSTEP:t=>T_(e,t),importSTL:t=>E_(e,t),exportIGES:t=>D_(e,t),importIGES:t=>O_(e,t),exportSTEPAssembly:(t,n)=>k_(e,t,n),export3MF:(t,n)=>A_(e,t,n),exportGLB:(t,n)=>j_(e,t,n),exportOBJ:(t,n)=>M_(e,t,n),exportPLY:(t,n)=>N_(e,t,n),import3MF:t=>P_(e,t),importOBJ:t=>F_(e,t),importGLB:t=>I_(e,t),toBREP:t=>L_(e,t),fromBREP:t=>R_(e,t),createXCAFDocument:t=>z_(e,t),writeXCAFToSTEP:(t,n)=>B_(e,t,n),exportSTEPConfigured:(t,n)=>V_(e,t,n)}}function U_(e,t){return{x:e,y:t}}function W_(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 G_(e,t){return{x:e,y:t}}function K_(e,t,n,r){return{px:e,py:t,dx:n,dy:r,delete:Xf}}function q_(e){return e}function J_(e){return e}function Y_(e,t,n,r){return te(e,t,n,r)}function X_(e,t,n,r){return ne(e,t,n,r)}function Z_(e,t,n,r,i,a,o){return ae(e,t,n,r,i,a,o)}function Q_(e,t,n,r,i,a,o,s,c){let l=ae(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 $_(e){return oe(e)}function ev(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 tv(e,t){return S(Cp(e),t)}function nv(e,t){return{point:S(Cp(e),t),tangent:C(Cp(e),t)}}function rv(e){return w(Cp(e))}function iv(e){return ee(wp(e))}function av(e,t,n){return{__bk2d:`trimmed`,basis:Cp(e),tStart:t,tEnd:n}}function ov(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 sv(e){return JSON.parse(JSON.stringify(e))}function cv(e,t){let n=Cp(e),r=w(n),i=[];for(let e=0;e<=30;e++){let a=r.first+(r.last-r.first)*e/30,[o,s]=S(n,a),[c,l]=C(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 ev(i)}function lv(e,t,n){return se(Cp(e),t,n)}function uv(e,t,n,r){return ce(Cp(e),t,n,r)}function dv(e,t,n,r){return le(Cp(e),t,n,r)}function fv(e,t,n){return ue(Cp(e),t,n)}function pv(e,t,n,r,i){return de(Cp(e),t,n,r,i)}function mv(e,t,n,r,i,a){return wv(e,_v(t,n,r,i,a))}function hv(e,t,n){return{m:e,tx:t,ty:n,delete:Xf}}function gv(){return hv([1,0,0,0,1,0,0,0,1],0,0)}function _v(e,n,r,i,a){let o=Math.sqrt(r*r+i*i);if(o<1e-15)return gv();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 hv(u,e-t(u,0)*e-t(u,1)*n,n-t(u,3)*e-t(u,4)*n)}function vv(e,t){return hv([1,0,0,0,1,0,0,0,1],e,t)}function yv(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 hv(u,d-t(u,0)*d-t(u,1)*f,f-t(u,3)*d-t(u,4)*f)}return hv([-1,0,0,0,-1,0,0,0,1],2*e,2*n)}function bv(e,t,n){let r=Math.cos(e),i=Math.sin(e);return hv([r,-i,0,i,r,0,0,0,1],t-r*t+i*n,n-i*t-r*n)}function xv(e,t,n){return hv([e,0,0,0,e,0,0,0,1],t*(1-e),n*(1-e))}function Sv(e,t,n){e.tx=t,e.ty=n}function Cv(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 wv(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 se(r,a,o);let d=w(r),f=[];for(let e=0;e<=20;e++){let[t,n]=S(r,d.first+(d.last-d.first)*e/20);f.push([s*t+c*n+a,l*t+u*n+o])}return oe(f)}function Tv(e,t,n){let r=fe(Cp(e),Cp(t),n),i=r.segments.map(e=>Object.assign(e,{delete(){}}));return{points:r.points,segments:i}}function Ev(e,t,n){let r=Cp(e),i=w(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]=S(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]=S(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]=S(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]=S(r,a),[s,c]=C(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]=S(r,a);return{param:a,distance:Math.sqrt((c-t)**2+(l-n)**2)}}function Dv(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]=S(o,t);for(let e=0;e<=50;e++){let n=i+(a-i)*e/50,[r,o]=S(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(s,f),u=Ev(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]=S(o,d),h=Ev(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]=S(o,d),[h,g]=S(s,f);return Math.sqrt((h-p)**2+(g-m)**2)}function Ov(e,n,r,i){let a=Cp(e),o=w(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(S(a,t))}u=0;for(let e=0;e<c;e++){let[n,r]=S(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 ev(l,{degMax:s})}function kv(e){let n=wp(e);if(n.__bk2d===`bezier`)return[e];if(n.__bk2d!==`bspline`)return kv(Ov(e,1e-6,`C2`,10));let r=w(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=S(n,r),l=S(n,i),u=C(n,r),d=C(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 Av(){return Ce()}function jv(e,t,n){we(Tp(e),Cp(t),n)}function Mv(e){let t=Tp(e);return{xMin:t.xMin,yMin:t.yMin,xMax:t.xMax,yMax:t.yMax}}function Nv(e,t){let n=Tp(e),r=Tp(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 Pv(e,t){let n=Tp(e),r=Tp(t);return n.xMax<r.xMin||r.xMax<n.xMin||n.yMax<r.yMin||r.yMax<n.yMin}function Fv(e,t,n){let r=Tp(e);return t<r.xMin||t>r.xMax||n<r.yMin||n>r.yMax}function Iv(e){let t=wp(e);return t.__bk2d===`circle`?{cx:t.cx,cy:t.cy,radius:t.radius,isDirect:t.sense}:null}function Lv(e){let t=wp(e);return t.__bk2d===`ellipse`?{majorRadius:t.majorRadius,minorRadius:t.minorRadius,xAxisAngle:t.xDirAngle,isDirect:t.sense}:null}function Rv(e){let t=wp(e);return t.__bk2d===`bezier`?[...t.poles]:null}function zv(e){let t=wp(e);return t.__bk2d===`bezier`?t.poles.length-1:null}function Bv(e){let t=wp(e);return t.__bk2d===`bspline`?{poles:[...t.poles],knots:[...t.knots],multiplicities:[...t.multiplicities],degree:t.degree,isPeriodic:t.isPeriodic}:null}function Vv(e){return xe(Cp(e))}function Hv(e){return Se(e)}function Uv(e,t){let n=Cp(e),r=w(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 Wv(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 Fh(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=w(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]=S(o,l.first+t*f),[i,u]=S(o,l.first+(t+1)*f);p.push(e.makeCircleArc3d(...c(n,r),...c(i,u),...a,...s))}return p.length===1?ep(t(p,0)):tp(e.makeWire(p,!1))}if(n.__bk2d===`ellipse`){let r=n,l=c(r.cx,r.cy),u=Math.cos(r.xDirAngle),d=Math.sin(r.xDirAngle),f=[u*a[0]+d*s[0],u*a[1]+d*s[1],u*a[2]+d*s[2]],p=w(o),m=p.last-p.first,h=m*1e-4,[g,_]=S(o,p.first),[v,y]=S(o,p.first+h),b=(g-r.cx)*(y-r.cy)-(_-r.cy)*(v-r.cx)>=0?i:[-i[0],-i[1],-i[2]],x=o.__bk2d===`trimmed`?Math.abs(o.tEnd-o.tStart):2*Math.PI,C=x>Math.PI?4:x>Math.PI/2?2:1,ee=m/C,te=[];for(let t=0;t<C;t++){let[n,i]=S(o,p.first+t*ee),[a,s]=S(o,p.first+(t+1)*ee);te.push(e.makeEllipseArc3d(...c(n,i),...c(a,s),...l,...b,...f,r.majorRadius,r.minorRadius))}return te.length===1?ep(t(te,0)):tp(e.makeWire(te,!1))}}if(o.__bk2d===`bezier`||o.__bk2d===`bspline`){let n=o.poles.map(([e,t])=>c(e,t));if(n.length===2)return Fh(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 ep(e.interpolatePoints(i,r))}let l=w(o),u=[];for(let e=0;e<=100;e++){let[t,n]=S(o,l.first+(l.last-l.first)*e/100);u.push(c(t,n))}return rg(e,u)}function Gv(e,t,r){if(!Zf(r))throw Error(`brepkit: buildEdgeOnSurface requires a face handle as surface`);let i=I(r,`face`),a=Cp(t),o=w(a),s=e.getSurfaceType(i)===`plane`?50:100,c=[];for(let t=0;t<=s;t++){let[r,l]=S(a,o.first+(o.last-o.first)*t/s);c.push(n(e.evaluateSurface(i,r,l)))}return rg(e,c)}function Kv(e){return e}function qv(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 Jv(e,n,r){let i=I(n,`edge`),a=I(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)}));qv(d,u,80,.05);let f=d.map(e=>e.uv);if(f.length>=2)return ev(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 te(t(n,0),t(n,1),t(r,0),t(r,1))}throw Error(`brepkit: extractCurve2dFromEdge: degenerate edge (${p.length} coords)`)}function Yv(e,t,n){return e}function Xv(e,n,r){if(n.length>=1){let r=Fp(e,n[0],`edge`);if(r.length===4){let n=[],i=[];for(let a of r){let r=I(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 $f(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 Yh(e,i)}function Zv(e){return{createPoint2d:(e,t)=>U_(e,t),createDirection2d:(e,t)=>W_(e,t),createVector2d:(e,t)=>G_(e,t),createAxis2d:(e,t,n,r)=>K_(e,t,n,r),wrapCurve2dHandle:e=>q_(e),createCurve2dAdaptor:e=>J_(e),makeLine2d:(e,t,n,r)=>Y_(e,t,n,r),makeCircle2d:(e,t,n,r)=>X_(e,t,n,r),makeArc2dThreePoints:(e,t,n,r,i,a)=>re(e,t,n,r,i,a),makeArc2dTangent:(e,t,n,r,i,a)=>ie(e,t,n,r,i,a),makeEllipse2d:(e,t,n,r,i,a,o)=>Z_(e,t,n,r,i,a,o),makeEllipseArc2d:(e,t,n,r,i,a,o,s,c)=>Q_(e,t,n,r,i,a,o,s,c),makeBezier2d:e=>$_(e),makeBSpline2d:(e,t)=>ev(e,t),evaluateCurve2d:(e,t)=>tv(e,t),evaluateCurve2dD1:(e,t)=>nv(e,t),getCurve2dBounds:e=>rv(e),getCurve2dType:e=>iv(e),trimCurve2d:(e,t,n)=>av(e,t,n),reverseCurve2d:e=>{ov(e)},copyCurve2d:e=>sv(e),offsetCurve2d:(e,t)=>cv(e,t),translateCurve2d:(e,t,n)=>lv(e,t,n),rotateCurve2d:(e,t,n,r)=>uv(e,t,n,r),scaleCurve2d:(e,t,n,r)=>dv(e,t,n,r),mirrorCurve2dAtPoint:(e,t,n)=>fv(e,t,n),mirrorCurve2dAcrossAxis:(e,t,n,r,i)=>pv(e,t,n,r,i),affinityTransform2d:(e,t,n,r,i,a)=>mv(e,t,n,r,i,a),createIdentityGTrsf2d:()=>gv(),createAffinityGTrsf2d:(e,t,n,r,i)=>_v(e,t,n,r,i),createTranslationGTrsf2d:(e,t)=>vv(e,t),createMirrorGTrsf2d:(e,t,n,r,i,a,o)=>yv(e,t,n,r,i,a,o),createRotationGTrsf2d:(e,t,n)=>bv(e,t,n),createScaleGTrsf2d:(e,t,n)=>xv(e,t,n),setGTrsf2dTranslationPart:(e,t,n)=>{Sv(e,t,n)},multiplyGTrsf2d:(e,t)=>{Cv(e,t)},transformCurve2dGeneral:(e,t)=>wv(e,t),intersectCurves2d:(e,t,n)=>Tv(e,t,n),projectPointOnCurve2d:(e,t,n)=>Ev(e,t,n),distanceBetweenCurves2d:(e,t,n,r,i,a)=>Dv(e,t,n,r,i,a),approximateCurve2dAsBSpline:(e,t,n,r)=>Ov(e,t,n,r),decomposeBSpline2dToBeziers:e=>kv(e),createBoundingBox2d:()=>Av(),addCurveToBBox2d:(e,t,n)=>{jv(e,t,n)},getBBox2dBounds:e=>Mv(e),mergeBBox2d:(e,t)=>{Nv(e,t)},isBBox2dOut:(e,t)=>Pv(e,t),isBBox2dOutPoint:(e,t,n)=>Fv(e,t,n),getCurve2dCircleData:e=>Iv(e),getCurve2dEllipseData:e=>Lv(e),getCurve2dBezierPoles:e=>Rv(e),getCurve2dBezierDegree:e=>zv(e),getCurve2dBSplineData:e=>Bv(e),serializeCurve2d:e=>Vv(e),deserializeCurve2d:e=>Hv(e),splitCurve2d:(e,t)=>Uv(e,t),liftCurve2dToPlane:(t,n,r,i)=>Wv(e,t,n,r,i),buildEdgeOnSurface:(t,n)=>Gv(e,t,n),extractSurfaceFromFace:e=>Kv(e),extractCurve2dFromEdge:(t,n)=>Jv(e,t,n),buildCurves3d:e=>{},fixWireOnFace:(e,t,n)=>Yv(e,t,n),fillSurface:(t,n)=>Xv(e,t,n)}}function Qv(e,t){let n=t;if(n.type===`solid`)return e.volume(I(t),gp);if(n.type===`compound`){let n=Fp(e,t,`solid`),r=0;for(let t of n)r+=e.volume(I(t),gp);return r}return 0}function $v(e,t){let n=t;if(n.type===`face`)return e.faceArea(I(t),gp);if(n.type===`solid`)return e.surfaceArea(I(t),gp);if(n.type===`compound`){let n=Fp(e,t,`face`),r=0;for(let t of n)r+=e.faceArea(I(t),gp);return r}return 0}function ey(e,t){let n=t;if(n.type===`edge`)return e.edgeLength(I(t));if(n.type===`face`)return e.facePerimeter(I(t));if(n.type===`wire`)return e.wireLength(n.id);throw Error(`brepkit: length() requires an edge, wire, or face`)}function ty(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 ny(e,t){let r=t;if(r.type===`solid`)return n(e.centerOfMass(I(t),gp));if(r.type===`face`){let n=Qp(e,t);return tm(e,t,(n.uMin+n.uMax)/2,(n.vMin+n.vMax)/2)}if(r.type===`edge`)return ty(e,r.id);if(r.type===`vertex`)return Xp(e,t);let i=Fp(e,t,`vertex`);if(i.length>0){let t=0,n=0,r=0;for(let a of i){let i=Xp(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 ry(e,t){let n=t;return n.type===`edge`?ty(e,n.id):ny(e,t)}function iy(e,t){let r=t;if(r.type===`solid`){let r=e.boundingBox(I(t));return{min:n(r,0),max:n(r,3)}}if(r.type===`vertex`){let n=Xp(e,t);return{min:[...n],max:[...n]}}let i=Fp(e,t,`vertex`);if(i.length===0)return{min:[0,0,0],max:[0,0,0]};let a=Xp(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=Xp(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 ay(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 oy(e,r,i,a){let o=I(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 sy(e,n){let r=e.tessellateFace(I(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 cy(e,t){let n=n=>ay(e,t,n);return{distanceTo(e){return n(e)},dispose(){}}}function ly(e,t,n=!1){let r=t,i=r.type===`edge`||r.type===`wire`||r.type===`face`;return{volume:Qv(e,t),area:$v(e,t),length:n&&i?ey(e,t):0,centerOfMass:ny(e,t),boundingBox:iy(e,t)}}function uy(e){return{volume:t=>Qv(e,t),area:t=>$v(e,t),length:t=>ey(e,t),centerOfMass:t=>ny(e,t),linearCenterOfMass:t=>ry(e,t),boundingBox:t=>iy(e,t),distance:(t,n)=>ay(e,t,n),surfaceCurvature:(t,n,r)=>oy(e,t,n,r),surfaceCenterOfMass:t=>sy(e,t),createDistanceQuery:t=>cy(e,t),measureBulk:(t,n)=>ly(e,t,n)}}function dy(e){return e.sketchNew()}function fy(e,t,n,r,i){return e.sketchAddPoint(t,n,r,i)}function py(e,t,n){e.sketchAddConstraint(t,n)}function my(e,t,n,r){return e.sketchSolve(t,n,r)}function hy(e,t,n,r,i){return e.sketchAddArc(t,n,r,i)}function gy(e,t){let n=e.sketchDof(t);return typeof n==`string`?n:String(n)}function _y(e){return{sketchNew:()=>dy(e),sketchAddPoint:(t,n,r,i)=>fy(e,t,n,r,i),sketchAddArc:(t,n,r,i)=>hy(e,t,n,r,i),sketchAddConstraint:(t,n)=>{py(e,t,n)},sketchSolve:(t,n,r)=>my(e,t,n,r),sketchDof:t=>gy(e,t)}}function vy(e,t,n,r){return F(e.extrude(I(t,`face`),n[0],n[1],n[2],r))}function yy(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),F(e.revolve(I(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 by(e,t,n,r,i){let a=180/Math.PI*i;return a>360&&(a=360),F(e.revolve(I(t,`face`),n[0],n[1],n[2],r[0],r[1],r[2],a))}function xy(e,t,n,r,i){(n!==void 0||r!==void 0||i!==void 0)&&xp(`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):I(t,`face`)});return F(e.loft(a))}function Sy(e){switch(e){case 0:return`rmf`;case 1:return`rightCorner`;case 2:return`roundCorner`;default:return}}function Cy(e,t,n,r){let i=r?.transitionMode===void 0?void 0:Sy(r.transitionMode),a=t,o=a.type===`wire`?e.makeFaceFromWire(a.id):I(t,`face`);if(n.type===`wire`){let t=Fp(e,n,`edge`).map(e=>I(e,`edge`));if(i&&t.length===1){let n=t[0];if(n!==void 0)return F(e.sweepWithOptions(o,n,i,[],0,`transformed`))}return i&&t.length>1&&xp(`sweep-transition-multi-edge`,`Sweep transition mode not supported for multi-edge wires; ignored.`),F(e.sweepAlongEdges(o,t))}if(i){let t=I(n,`edge`);return F(e.sweepWithOptions(o,t,i,[],0,`transformed`))}let s=Ym(e,n);if(!s)throw Error(`brepkit: sweep spine must be an edge or wire`);return F(e.sweep(o,s.degree,s.knots,s.controlPoints,s.weights))}function wy(e,t,n){let r=t,i=r.type===`wire`?e.makeFaceFromWire(r.id):I(t,`face`);if(n.type===`wire`){let t=Fp(e,n,`edge`).map(e=>I(e,`edge`));return F(e.sweepAlongEdges(i,t))}let a=Ym(e,n);if(!a)throw Error(`brepkit: pipe spine must be an edge or wire`);return F(e.pipe(i,a.degree,a.knots,a.controlPoints,a.weights))}function Ty(e,t,n,r,i,a,o){let s=I(t,`face`);return F(e.helicalSweep(s,n[0],n[1],n[2],r[0],r[1],r[2],i,a,o))}function Ey(e,t,n,r,i,a){let o=I(t,`face`),s=I(n,`edge`);return F(e.sweepWithOptions(o,s,r,i,a,`transformed`))}function Dy(e){switch(e){case`right`:return`rightCorner`;case`round`:return`roundCorner`;case`transformed`:return`rmf`;default:return}}function Oy(e,t,n){return n?{shape:e,firstShape:t,lastShape:t}:e}function ky(e,t,n,r){try{return F(e.sweepWithOptions(t,n,r,[],0,`transformed`))}catch(e){console.warn(`brepkit: sweepWithOptions failed, falling back to sweepSmooth/simplePipe:`,e);return}}function Ay(e,t){try{if(t.type!==`wire`)return{edgeId:I(t,`edge`)};let n=Fp(e,t,`edge`);if(n.length===1){let e=n[0];return e?{edgeId:I(e,`edge`)}:void 0}xp(`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 jy(e,t,n,r){let i=Ay(e,n);if(i)return ky(e,t,i.edgeId,r)}function My(e,t,n){let r=Ym(e,n);if(!(!r||r.degree<=1))try{return F(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 Ny(e,t,n,r){let i=t,a=i.type===`wire`?e.makeFaceFromWire(i.id):I(t,`face`),o=!!(r&&r.shellMode),s=r?.transitionMode,c=s?Dy(s):void 0;if(c){let r=jy(e,a,n,c);if(r)return Oy(r,t,o)}return Oy(My(e,a,n)||wy(e,t,n),t,o)}function Py(e,t,n){let r=t.map(t=>{let n=t;return n.type===`wire`?e.makeFaceFromWire(n.id):I(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(I(n.startVertex,`vertex`));t.startPoint=[r[0],r[1],r[2]]}if(n?.endVertex){let r=e.getVertexPosition(I(n.endVertex,`vertex`));t.endPoint=[r[0],r[1],r[2]]}return F(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 F(e.loftSmooth(r))}catch(e){console.warn(`brepkit: loftSmooth failed, falling back to basic loft:`,e)}return xy(e,t)}function Fy(e,t,n,r){let i={type:`extrusionLaw`,profile:t,length:n,endFactor:r,Trim(e,t,n){return i},delete:Xf};return i}function Iy(e,t,n,r,i,a,o){if(i!==null){let r=vy(e,n,em(e,n,0,0),i);return o?dh(e,t,r):r}return t}function Ly(e){return{extrude:(t,n,r)=>vy(e,t,n,r),revolve:(t,n,r)=>yy(e,t,n,r),revolveVec:(t,n,r,i)=>by(e,t,n,r,i),loft:(t,n,r,i)=>xy(e,t,n,r,i),sweep:(t,n,r)=>Cy(e,t,n,r),simplePipe:(t,n)=>wy(e,t,n),helicalSweep:(t,n,r,i,a,o)=>Ty(e,t,n,r,i,a,o),sweepWithOptions:(t,n,r,i,a)=>Ey(e,t,n,r,i,a),sweepPipeShell:(t,n,r)=>Ny(e,t,n,r),loftAdvanced:(t,n)=>Py(e,t,n),buildExtrusionLaw:(t,n,r)=>Fy(e,t,n,r),draftPrism:(t,n,r,i,a,o)=>Iy(e,t,n,r,i,a,o)}}function Ry(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 zy=class{oc;kernelId=`brepkit`;capabilities=a;bk;constructor(e){this.bk=e,this.oc=e;let t=this.bk;Object.assign(this,Ch(t),pg(t),Ly(t),jg(t),Wm(t),S_(t),H_(t),uy(t),Yp(t),jm(t),sh(t),f_(t),_y(t),Zv(t),Ry(t))}};function By(e){throw Error(`manifold: ${e} is not implemented`)}var Vy=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 Hy(e){return Vy.has(e)}function R(e,t,n){return{op:e,params:t,inputs:n,replayable:Hy(e)&&n.every(e=>e.replayable)}}function z(e,t){return{manifold:e,node:t}}function B(e){return e.manifold}function Uy(e){return typeof e?.translate==`function`?e.translate([0,0,0]):e}function V(e){return e.node}function Wy(e){if(e&&typeof e==`object`&&`manifold`in e&&`node`in e)return e}var Gy=[`occt`,`occt-wasm`];function Ky(){for(let e of Gy)try{return H(e)}catch{}}function qy(e){let t=Ky();if(!t)throw new c(`manifold: ${e} requires a registered occt kernel; none is available`);return t}var Jy=new WeakMap,Yy=[0,0,0],Xy=[0,0,1];function Zy(e){return Math.hypot(e[0],e[1],e[2])}function Qy(e){let t=Zy(e);return t===0?[...Xy]:[e[0]/t,e[1]/t,e[2]/t]}function $y(e){let[t,n,r]=Qy(e);return[0,180/Math.PI*Math.atan2(Math.hypot(t,n),r),180/Math.PI*Math.atan2(n,t)]}function eb(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($y(n))),(t[0]!==0||t[1]!==0||t[2]!==0)&&(r=r.translate(t)),r}return{makeBox:(e,n,r)=>z(t.cube([e,n,r],!1),R(`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 z(t.cube(r,!1).translate(i),R(`makeBoxWithCorners`,{p1:e,p2:n},[]))},makeCylinder:(e,r,i=Yy,a=Xy)=>z(n(t.cylinder(r,e,e,0,!1),i,a),R(`makeCylinder`,{radius:e,height:r,center:i,direction:a},[])),makeSphere:(e,n=Yy)=>{let r=t.sphere(e,0);return(n[0]!==0||n[1]!==0||n[2]!==0)&&(r=r.translate(n)),z(r,R(`makeSphere`,{radius:e,center:n},[]))},makeCone:(e,r,i,a=Yy,o=Xy)=>z(n(t.cylinder(i,e,r,0,!1),a,o),R(`makeCone`,{radius1:e,radius2:r,height:i,center:a,direction:o},[])),makeTorus:(r,i,a=Yy,o=Xy)=>{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 z(n(t.revolve([c],0),a,o),R(`makeTorus`,{majorRadius:r,minorRadius:i,center:a,direction:o},[]))},makeEllipsoid:(e,n,r)=>z(t.sphere(1,0).scale([e,n,r]),R(`makeEllipsoid`,{aLength:e,bLength:n,cLength:r},[])),makeRectangle:()=>By(`makeRectangle`)}}function tb(e){return e}function nb(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 rb(e){let t=V(tb(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 ib(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 ab(e){let t=e.Manifold;function n(e,t,n){let r=tb(e),i=tb(t);return z(B(r).add(B(i)),R(`makeFuse`,{},[V(r),V(i)]))}function r(e,t,n){let r=tb(e),i=tb(t);return z(B(r).subtract(B(i)),R(`makeCut`,{},[V(r),V(i)]))}function i(e,t,n){let r=tb(e),i=tb(t);return z(B(r).intersect(B(i)),R(`makeCommon`,{},[V(r),V(i)]))}function a(e,n){if(e.length===0)throw Error(`manifold: fuseAll requires at least one shape`);let r=e.map(tb),[i]=r;if(i===void 0)throw Error(`manifold: fuseAll requires at least one shape`);return r.length===1?i:z(t.union(r.map(B)),R(`makeFuse`,{},r.map(V)))}function o(e,n,r){let i=tb(e);if(n.length===0)return i;let a=n.map(tb);return z(t.difference([B(i),...a.map(B)]),R(`makeCut`,{},[V(i),...a.map(V)]))}function s(e,t,n){let r=tb(e),{normal:i,offset:a}=rb(t),[o]=B(r).splitByPlane(i,a);return z(o,R(`section`,{normal:i,offset:a},[V(r),V(tb(t))]))}function c(e,n){let r=tb(e),[i]=n;if(i===void 0)throw Error(`manifold: split requires at least one tool`);let a=tb(i),{normal:o,offset:s}=rb(i),[c,l]=B(r).splitByPlane(o,s);return z(t.union([c,l]),R(`split`,{normal:o,offset:s},[V(r),V(a)]))}function l(e,t,n){let r=[],i=tb(e),a=tb(t);return(B(i)===void 0||B(i).isEmpty())&&r.push({operand:`base`,issue:`null-shape`,message:`Base shape is empty`}),(B(a)===void 0||B(a).isEmpty())&&r.push({operand:`tool`,issue:`null-shape`,message:`Tool shape is empty`}),{valid:r.length===0,issues:r}}function u(n,r,i,a,o,s){let c=new e.Mesh({numProp:3,vertProperties:new Float32Array(n),triVerts:new Uint32Array(r)}),l=new e.Mesh({numProp:3,vertProperties:new Float32Array(i),triVerts:new Uint32Array(a)});return ib(nb(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 ob(e){return e}function sb(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function cb(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 lb(e,t,n){let r=sb();return r[12]=e,r[13]=t,r[14]=n,r}function ub(e,t,n){let r=e,[i,a,o]=cb(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=sb();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 db(e,t){let n=sb();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 fb(e,t){let[n,r,i]=cb(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=sb();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 pb(e,t){let n=sb();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 mb(e,t,n,r,i){return z(e.transform(t),R(n,r,[i]))}function hb(e,t,n,r){let i=ob(e);return mb(B(i),lb(t,n,r),`translateShape`,{x:t,y:n,z:r},V(i))}function gb(e,t,n=[0,0,1],r=[0,0,0]){let i=ob(e);return mb(B(i),ub(t,n,r),`rotateShape`,{angle:t,axis:n,center:r},V(i))}function _b(e,t,n){let r=ob(e);return mb(B(r),fb(t,n),`mirrorShape`,{origin:t,normal:n},V(r))}function vb(e,t,n){let r=ob(e);return mb(B(r),db(t,n),`scaleShape`,{center:t,factor:n},V(r))}function yb(e,t){if(!Array.isArray(t)||t.length!==16)throw Error(`manifold: transform expects a 16-element column-major matrix`);let n=ob(e);return mb(B(n),t,`transformShape`,{matrix:[...t]},V(n))}function bb(e,t,n,r){let i=ob(e);return mb(B(i),pb(t,n),`generalTransform`,{linear:t,translation:n,isOrthogonal:r},V(i))}function xb(e,t,n){let r=ob(e);return mb(B(r),pb(t,n),`generalTransformNonOrthogonal`,{linear:t,translation:n},V(r))}function Sb(e){let t=sb();for(let n of e)t=Ob(n.type===`translate`?lb(n.x,n.y,n.z):ub(n.angle*Math.PI/180,n.axis??[0,0,1],n.center??[0,0,0]),t);return{handle:t,dispose:()=>{}}}function Cb(e,t,n,r){let i=[e];for(let a=1;a<r;a++){let r=n*a;i.push(hb(e,t[0]*r,t[1]*r,t[2]*r))}return i}function wb(e,t,n,r,i){let a=[e];for(let o=1;o<i;o++)a.push(gb(e,r*o*Math.PI/180,n,t));return a}function Tb(e,t,n,r,i,a,o,s){let c=ob(t),l=[],u=[];for(let e=0;e<o;e++)for(let t=0;t<s;t++){let o=n[0]*i*e+r[0]*a*t,s=n[1]*i*e+r[1]*a*t,d=n[2]*i*e+r[2]*a*t;l.push(B(c).transform(lb(o,s,d))),u.push(V(c))}return z(l.length===1?l[0]:e.Manifold.union(l),R(`gridPattern`,{directionX:n,directionY:r,spacingX:i,spacingY:a,countX:o,countY:s},u))}function Eb(e){return e.map(e=>{switch(e.type){case`translate`:return hb(e.shape,e.x,e.y,e.z);case`rotate`:return gb(e.shape,e.angle*Math.PI/180,e.axis,e.center);case`scale`:return vb(e.shape,e.center,e.factor);case`mirror`:return _b(e.shape,e.origin,e.normal)}})}function Db(e){return{composeTransform:Sb,transform:yb,locate:yb,translate:hb,rotate:gb,mirror:_b,scale:vb,generalTransform:bb,generalTransformNonOrthogonal:xb,positionOnCurve:()=>By(`positionOnCurve`),linearPattern:Cb,circularPattern:wb,gridPattern:(t,n,r,i,a,o,s)=>Tb(e,t,n,r,i,a,o,s),transformBatch:Eb}}function Ob(e,t){let n=sb();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 kb=2*Math.PI,Ab=e=>Math.hypot(e[0],e[1],e[2]),jb=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]];function Mb(e){return Ab(jb(e.p2,e.p1))}function Nb(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 Pb(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 Fb(e){return e.k===`line`?{first:0,last:Mb(e)}:e.k===`conic`?{first:e.a0,last:e.a1}:e.k===`helix`?{first:0,last:kb*e.turns}:{first:0,last:1}}function Ib(e,t){if(e.k===`line`){let n=t/(Mb(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 Nb(e.points,t);if(e.k===`helix`){let n=Math.cos(t),r=Math.sin(t),i=e.pitch*t/kb;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 Lb(e,t){let n;if(e.k===`line`)n=jb(e.p2,e.p1);else if(e.k===`bezier`){let r=Nb(e.points,Math.max(0,t-1e-4));n=jb(Nb(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/kb;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=Ab(n)||1;return[n[0]/r,n[1]/r,n[2]/r]}function Rb(e){if(e.k===`line`)return Mb(e);if(e.k===`helix`){let t=kb*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-kb)<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 Hb(t=>Ib(e,t),e.a0,e.a1,256)}return Hb(t=>Ib(e,t),0,1,128)}function zb(e){return e.k===`conic`?Math.abs(Math.abs(e.a1-e.a0)-kb)<1e-9:!1}function Bb(e){return zb(e)}function Vb(e){return e.k===`conic`?kb:0}function Hb(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+=Ab(jb(s,a)),a=s}return i}function Ub(e){return e}function Wb(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function Gb(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 Kb(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function qb(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function Jb(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function Yb(e){return Math.hypot(e[0],e[1],e[2])}function Xb(e){let t=Yb(e);return t<1e-12?[0,0,1]:[e[0]/t,e[1]/t,e[2]/t]}function Zb(e){return Xb(Gb(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function Qb(e){let t=Xb(e),n=Zb(t);return{xAxis:n,yAxis:Xb(Gb(t,n))}}function $b(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 ex(e){return $b(e)<0?[...e].reverse():e}function tx(e){return $b(e)>0?[...e].reverse():e}function nx(e){return e.node?.params}function rx(e){let t=Ub(e),n=nx(t),r=n?.outline??n?.polygon??n?.points;if(r&&r.length>=3){let e=n?.origin??[0,0,0],t=ex(r.map(e=>[e[0],e[1]])),i=(n?.holes)?.filter(e=>e.length>=3).map(e=>tx(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}=Qb(n?.normal??[0,0,1]);return{outline:t,holes:i,origin:e,xAxis:a,yAxis:o}}return ix(t)}function ix(e){let t=B(e)?.getMesh?.();if(!t)throw Error(`manifold: profile carries no recorded outline and no mesh to derive one`);let n=t.numProp,r=Math.floor(t.vertProperties.length/n),i=[],a=0;for(let e=0;e<r;e++)i.push([t.vertProperties[e*n]??0,t.vertProperties[e*n+1]??0]),a+=t.vertProperties[e*n+2]??0;a/=Math.max(1,r);let o=ax(i);return{outline:ex(o.length>=3?o:[[-.5,-.5],[.5,-.5],[0,.5]]),origin:[0,0,a],xAxis:[1,0,0],yAxis:[0,1,0]}}function ax(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 ox(e){let t=[];for(let n=1;n+1<e;n++)t.push(0,n,n+1);return t}function sx(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 cx(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 lx(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=dx(t.length,n),a=new e.Mesh({numProp:3,vertProperties:Float32Array.from(r),triVerts:Uint32Array.from(i)});return ux(e,new e.Manifold(a))}function ux(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 dx(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=ox(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=ox(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 fx(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 Xb(Kb(e[Math.min(e.length-1,t+1)]??e[t]??[0,0,0],n))},i=r(0),a=Xb(Kb(t,Jb(i,Wb(t,i))));Yb(a)<1e-9&&(a=Zb(i)),n.push({origin:e[0]??[0,0,0],xAxis:a,yAxis:Xb(Gb(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=Kb(s,o),l=Wb(c,c),u=a;if(l>1e-18){let e=Kb(a,Jb(c,2/l*Wb(c,a))),n=Kb(i,Jb(c,2/l*Wb(c,i))),o=Kb(r(t),n),s=Wb(o,o);u=s>1e-18?Kb(e,Jb(o,2/s*Wb(o,e))):e}let d=r(t),f=Xb(Kb(u,Jb(d,Wb(u,d)))),p=Xb(Gb(d,f));n.push({origin:s,xAxis:f,yAxis:p,tangent:d}),i=d,a=f}return n}var px=24,mx=24,hx=null;function gx(e){let t=hx?hx(Math.max(Math.abs(e),1e-6)):px;return Math.max(px,t)}var _x=[0,0,0],vx=1e-6,yx={delete:()=>{},isEmpty:()=>!1};function bx(e,t){return e[t]??_x}function xx(e,t=1){return Math.max(2,Math.ceil(Math.abs(e)/(2*Math.PI)*gx(t)))}function Sx(e){return Xb(Gb(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function Cx(e,t,n,r,i,a){let o=Xb(t),s=a?Xb(a):Sx(o),c=Xb(Gb(o,s)),l=i-r,u=xx(l,n),d=[];for(let t=0;t<=u;t++){let i=r+l*t/u;d.push(qb(e,qb(Jb(s,n*Math.cos(i)),Jb(c,n*Math.sin(i)))))}return d}function wx(e,t,n){let r=Kb(t,e),i=Kb(n,e),a=Gb(r,i);if(Yb(a)<1e-12)return[e,t,n];let o=Xb(a),s=Wb(r,r),c=Wb(i,i),l=Wb(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=qb(e,qb(Jb(r,d),Jb(i,f))),m=Yb(Kb(e,p)),h=Xb(Kb(e,p)),g=Xb(Gb(o,h)),_=(e=>Math.atan2(Wb(Kb(e,p),g),Wb(Kb(e,p),h)))(n);return _<0&&(_+=2*Math.PI),Cx(p,o,m,0,_,h)}function Tx(e){let t=[];for(let n=0;n<=mx;n++){let r=n/mx,i=e.map(e=>[...e]);for(let e=1;e<i.length;e++)for(let t=0;t<i.length-e;t++){let e=bx(i,t),n=bx(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(bx(i,0))}return t}function Ex(e){let t=0,n=0,r=0;for(let i=0;i<e.length;i++){let a=bx(e,i),o=bx(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 Yb(i)<1e-12?[0,0,1]:Xb(i)}function Dx(e,t){return Yb(Kb(e,t))<vx}function Ox(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=bx(n,n.length-1),a=Dx(bx(r,0),i),o=Dx(bx(r,r.length-1),i);!a&&o&&(r=[...r].reverse());let s=Dx(bx(r,0),i);for(let e=+!!s;e<r.length;e++)n.push(bx(r,e))}return n.length>1&&Dx(bx(n,0),bx(n,n.length-1))&&n.pop(),n}function kx(e){let t=Ex(e),n=bx(e,0),r=e.length>1?Xb(Kb(bx(e,1),n)):Sx(t);r=Xb(Kb(r,Jb(t,Wb(r,t)))),Yb(r)<1e-9&&(r=Sx(t));let i=Xb(Gb(t,r));return{outline:ex(e.map(e=>{let t=Kb(e,n);return[Wb(t,r),Wb(t,i)]})),origin:n,xAxis:r,yAxis:i}}var Ax=12;function jx(e,t){let[n,r]=e.curveParameters(t),i=Ax;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 Mx(e,t){return Ox(e.iterShapes(t,`edge`).map(t=>jx(e,t)))}function Nx(e){let t=e.getCircularSegments;typeof t==`function`&&(hx=e=>t(e));function n(e,t){return z(yx,R(`profileEdge`,t?{pts:e,curve:t}:{pts:e},[]))}function r(e,t){let n=Xb(e),r=t?Xb(t):Sx(n);return{x:r,y:Xb(Gb(n,r))}}function i(e,t,n){let r=Kb(t,e),i=Kb(n,e),a=Gb(r,i);if(Yb(a)<1e-12)return;let o=Xb(a),s=Wb(r,r),c=Wb(i,i),l=Wb(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=qb(e,qb(Jb(r,d),Jb(i,f))),m=Yb(Kb(e,p)),h=Xb(Kb(e,p)),g=Xb(Gb(o,h)),_=Math.atan2(Wb(Kb(n,p),g),Wb(Kb(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=Wy(e);if(t){let e=t.node.params;return e?.ring??e?.pts??[]}let n=Ky();return n?jx(n,e):[]}function o(e){let t=[];for(let n of e){let e=Wy(n);e&&t.push(V(e))}return t}function s(e){let t=Ox(e.map(e=>a(e)));return z(yx,R(`profileWire`,{ring:t,...t.length>=3?kx(t):void 0},o(e)))}function c(e,t){let{outline:n,origin:r,xAxis:i,yAxis:a}=kx(e);return z(yx,R(`profileFace`,{outline:n,origin:r,xAxis:i,yAxis:a},t?[t]:[]))}function l(e){let t=Wy(e);if(t){let e=t.node.params?.ring??[];if(e.length>=3)return c(e,V(t))}let n=Ky();return c(n?Mx(n,e):[],t?V(t):void 0)}function u(e,t){let n=Wy(e),r=n?.node?.params??{},i=r.origin??_x,a=r.xAxis??[1,0,0],s=r.yAxis??[0,1,0],c=e=>{let t=Kb(e,i);return[Wb(t,a),Wb(t,s)]},l=[];for(let e of t){let t=Wy(e),n;if(t)n=t.node.params?.ring??[];else{let t=Ky();n=t?Mx(t,e):[]}n.length>=3&&l.push(n.map(c))}let u=[...r.holes??[],...l],d=n?[V(n),...o(t)]:o(t);return z(yx,R(`profileFace`,{outline:r.outline??[],holes:u,origin:i,xAxis:a,yAxis:s},d))}function d(e,t,n,r,i){let a=Xb(t),o=i?Xb(i):Sx(a),s=Xb(Gb(a,o)),c=[],l=gx(Math.max(n,r));for(let t=0;t<=l;t++){let i=2*Math.PI*t/l;c.push(qb(e,qb(Jb(o,n*Math.cos(i)),Jb(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(Cx(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(Cx(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(wx(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(Tx(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=Xb(a),c=Sx(s),l=Xb(Gb(s,c)),u=o?Jb(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*px)),m=[];for(let e=0;e<=p;e++)m.push(Ib(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 Px(e){let t=e.Manifold,n=Nx(e);function r(e,n){let r=e.map(e=>[e.x,e.y,e.z]);return z(t.hull(r),R(`hullFromPoints`,{points:r,tolerance:n},[]))}function i(e,n){let r=e.map(e=>B(e));return z(t.hull(r),R(`hull`,{tolerance:n},e.map(e=>V(e))))}function a(e){let n=e.map(e=>B(e)),r=n[0];if(!r)throw Error(`manifold: makeCompound requires at least one input shape`);return z(n.length===1?r:t.union(n),R(`makeCompound`,{},e.map(e=>V(e))))}function o(e,t){let n=e[0];return n||By(`sewAndSolidify (no input faces on manifold kernel)`),z(B(n),R(`sewAndSolidify`,{tolerance:t},e.map(e=>V(e))))}return{makeVertex:(e,t,r)=>n.makeVertex(e,t,r),makeEdge:()=>By(`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:()=>By(`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:()=>By(`solidFromShell`),hull:i,hullFromPoints:r,buildSolidFromFaces:()=>By(`buildSolidFromFaces`),makeNonPlanarFace:()=>By(`makeNonPlanarFace`),addHolesInFace:(e,t)=>n.addHolesInFace(e,t),removeHolesFromFace:()=>By(`removeHolesFromFace`),makeFaceOnSurface:()=>By(`makeFaceOnSurface`),bsplineSurface:(e,t,n)=>qy(`bsplineSurface`).bsplineSurface(e,t,n),triangulatedSurface:(e,t,n)=>qy(`triangulatedSurface`).triangulatedSurface(e,t,n),buildTriFace:()=>By(`buildTriFace`),sewAndSolidify:o,createPoint3d:()=>By(`createPoint3d`),createDirection3d:()=>By(`createDirection3d`),createVector3d:()=>By(`createVector3d`),createAxis1:()=>By(`createAxis1`),createAxis2:()=>By(`createAxis2`),createAxis3:()=>By(`createAxis3`)}}var Fx=Math.PI/180;function Ix(e){return e}function Lx(e){let t=180/Math.PI*e;return t>360?360:t}function Rx(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 zx(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=Rx(n.Location()),t=Rx(n.Direction());if(e&&t)return{origin:e,direction:t}}}}function Bx(e){return e.outline.map(e=>[e[0],e[1]])}function Vx(e){return{outline:e.outline,origin:e.origin,xAxis:e.xAxis,yAxis:e.yAxis}}function Hx(e){return{origin:e.origin,xAxis:e.xAxis,yAxis:e.yAxis,tangent:Xb(Gb(e.xAxis,e.yAxis))}}function Ux(e){let t=0;for(let n of e.outline)t=Math.max(t,Math.hypot(n[0],n[1]));return t||1}function Wx(e){let t=B(e)?.getMesh?.();if(!t)return[];let n=t.numProp,r=Math.floor(t.vertProperties.length/n),i=[];for(let e=0;e<r;e++)i.push([t.vertProperties[e*n]??0,t.vertProperties[e*n+1]??0,t.vertProperties[e*n+2]??0]);return i}function Gx(e,t){let n=Ix(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=Wx(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 Kx(e){return e?.node??R(`spine`,{},[])}function qx(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 Jx(e,t,n){let r=Xb(n);return e.outline.map(n=>{let i=Kb(qb(e.origin,qb(Jb(e.xAxis,n[0]),Jb(e.yAxis,n[1]))),t),a=i[0]*r[0]+i[1]*r[1]+i[2]*r[2];return[Yb(Kb(i,Jb(r,a))),a]})}function Yx(e,t,n){let r=e,i=Xb(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=Gb([0,1,0],i);Yb(t)<1e-9&&(t=[1,0,0]),t=Xb(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 Xx(e,t,n,r,i){let a=Xb(t),{xAxis:o,yAxis:s}=Qb(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=qb(Jb(o,n*Math.cos(i)),Jb(s,n*Math.sin(i)));d.push(qb(e,qb(f,Jb(a,u*r))))}return d}function Zx(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 Qx(e,t,n,r){let i=rx(t),a=Xb([n[0],n[1],n[2]]),o=Yb([n[0]*r,n[1]*r,n[2]*r]),s=[Bx(i),...(i.holes??[]).map(e=>e.map(e=>[e[0],e[1]]))];return z(qx(ux(e,e.Manifold.extrude(s,o)),i,a),R(`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},[V(Ix(t))]))}function $x(e,t,n,r,i,a,o){let s=rx(t),c=Lx(i),l=Jx(s,n,r);return z(Yx(e.Manifold.revolve([l],0,c),n,r),R(a,o,[V(Ix(t))]))}function eS(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 tS(e,t,n,r){if(t.length<2)throw Error(`manifold: loft requires at least two profiles`);let i=t.map(rx),a=i.reduce((e,t)=>Math.max(e,t.outline.length),0),o=i.map(e=>cx({...e,outline:sx(e.outline,a)},Hx(e)));for(let e=1;e<o.length;e++)o[e]=eS(o[e]??[],o[e-1]??[]);return z(lx(e,o),R(n,{sections:i.map(Vx),...r},t.map(e=>V(Ix(e)))))}function nS(e,t,n,r,i,a,o){let s=rx(t),c=fx(n,s.xAxis),l=c.length;return z(lx(e,c.map((e,t)=>{let n=o?o(l>1?t/(l-1):0):1;return cx(s,e,n)})),R(i,{section:Vx(s),path:n.map(e=>[e[0],e[1],e[2]]),...a},[V(Ix(t)),r]))}function rS(e,t,n,r,i,a){if(r===null)return t;let o=rx(n),s=Xb(Gb(o.xAxis,o.yAxis)),c=Math.tan(i*Fx),l={origin:qb(o.origin,Jb(s,r)),xAxis:o.xAxis,yAxis:o.yAxis,tangent:s},u=1+c*r/Ux(o),d=lx(e,[cx(o,Hx(o),1),cx(o,l,u)]),f=R(`draftPrism`,{outline:o.outline,origin:o.origin,xAxis:o.xAxis,yAxis:o.yAxis,height:r,angleDeg:i,fuse:a},[V(Ix(n))]);if(a){let e=Ix(t);return z(B(e).add(d),R(`makeFuse`,{},[V(e),f]))}return z(d,f)}function iS(e){return{revolve:(t,n,r)=>{let i=zx(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 $x(e,t,a,o,r,`revolve`,{...Vx(rx(t)),axisOrigin:[a[0],a[1],a[2]],axisDirection:[o[0],o[1],o[2]],angleDeg:Lx(r)})},revolveVec:(t,n,r,i)=>$x(e,t,n,r,i,`revolveVec`,{...Vx(rx(t)),center:[n[0],n[1],n[2]],direction:[r[0],r[1],r[2]],angleDeg:Lx(i)})}}function aS(e){return{sweep:(t,n,r)=>{let i={};return r?.transitionMode!==void 0&&(i.transitionMode=r.transitionMode),nS(e,t,Gx(n,16),Kx(n),`sweep`,i)},simplePipe:(t,n)=>nS(e,t,Gx(n,16),Kx(n),`simplePipe`,{}),sweepWithOptions:(t,n,r,i,a)=>nS(e,t,Gx(n,Math.max(2,a||16)),Kx(n),`sweepWithOptions`,{contactMode:r,scaleValues:[...i],segments:a},Zx(i)),sweepPipeShell:(t,n,r)=>{let i={};r?.transitionMode!==void 0&&(i.transitionMode=r.transitionMode);let a=nS(e,t,Gx(n,16),Kx(n),`sweepPipeShell`,i);return r?.shellMode?{shape:a,firstShape:t,lastShape:t}:a},helicalSweep:(t,n,r,i,a,o)=>nS(e,t,Xx(n,r,i,a,o),Kx(t),`helicalSweep`,{axisOrigin:[n[0],n[1],n[2]],axisDirection:[r[0],r[1],r[2]],radius:i,pitch:a,turns:o})}}function oS(e){return{extrude:(t,n,r)=>Qx(e,t,n,r),...iS(e),loft:(t,n)=>tS(e,t,`loft`,{ruled:n??!1}),loftAdvanced:(t,n)=>tS(e,t,`loftAdvanced`,{solid:n?.solid??!0,ruled:n?.ruled??!1,tolerance:n?.tolerance}),...aS(e),draftPrism:(t,n,r,i,a,o)=>rS(e,t,n,i,a,o),buildExtrusionLaw:(e,t,n)=>({type:`extrusionLaw`,profile:e,length:t,endFactor:n}),loftBatch:()=>By(`loftBatch`),extrudeBatch:t=>t.map(t=>Qx(e,t.face,t.direction,t.length))}}var sS=16;function cS(e,t,n){if(!(n>0))return Uy(t);let r=dS(e,n);return r===void 0||typeof t?.minkowskiDifference!=`function`||typeof t?.minkowskiSum!=`function`?Uy(t):t.minkowskiDifference(r).minkowskiSum(r)}function lS(e,t,n){if(n===0)return Uy(t);let r=dS(e,Math.abs(n));return r===void 0?Uy(t):n>0?typeof t?.minkowskiSum==`function`?t.minkowskiSum(r):Uy(t):typeof t?.minkowskiDifference==`function`?t.minkowskiDifference(r):Uy(t)}function uS(e,t,n,r){if(n===0)return Uy(t);if(r)return lS(e,t,Math.abs(n));let i=lS(e,t,-Math.abs(n));return typeof t?.subtract==`function`?t.subtract(i):Uy(t)}function dS(e,t){let n=e?.Manifold;if(typeof n?.sphere==`function`)return n.sphere(t,sS)}function fS(e){return e}function pS(e){let t=e;if(t!=null){if(typeof t.index==`number`)return t.index;if(typeof t.id==`number`)return t.id}}function mS(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 hS(e){let t=e;if(t?.box!==void 0)return mS(t.box);let n=(e?.manifold)?.boundingBox?.();return n===void 0?void 0:mS(n)}function gS(e){let t=e.length;if(t===0)return{kind:`all`,count:t};let n=[];for(let t of e){let e=hS(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=pS(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 _S(e){return typeof e==`function`&&By(`fillet (per-edge radius callback)`),e}function vS(e){return typeof e==`number`?e:e[0]}function yS(e){let t=e.match(/[-+]?\d*\.?\d+/);return t?Number(t[0]):0}function bS(e,t,n,r,i){let a=fS(n),o=_S(i),s=gS(r);return z(cS(e,B(a),vS(o)),R(t,{radius:o,selection:s},[V(a)]))}function xS(e,t,n,r,i){let a=fS(t),o=gS(n);return z(cS(e,B(a),r),R(`chamferDistAngle`,{distance:r,angleDeg:i,selection:o},[V(a)]))}function SS(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]),ux(e,B(t).subtract(d))}catch{return}}function CS(e,t,n,r,i){let a=fS(t),o=gS(n);return z(SS(e,a,r)??uS(e,B(a),r,!1),R(`shell`,i===void 0?{thickness:r,selection:o}:{thickness:r,selection:o,tolerance:i},[V(a)]))}function wS(e,t,n){let r=fS(t);return z(uS(e,B(r),n,!0),R(`thicken`,{thickness:n},[V(r)]))}function TS(e,t,n,r){let i=fS(t);return z(lS(e,B(i),n),R(`offset`,r===void 0?{distance:n}:{distance:n,tolerance:r},[V(i)]))}function ES(e,t,n){let r=fS(t);return z(cS(e,B(r),yS(n)),R(`filletVariable`,{spec:n},[V(r)]))}function DS(e,t,n,r,i){typeof i==`function`&&By(`draft (per-face angle callback)`);let a=fS(e),o=gS(t);return z(Uy(B(a)),R(`draft`,{pullDirection:n,neutralPlane:r,angleDeg:i,selection:o},[V(a)]))}function OS(e,t){let n=fS(e),r=gS(t);return z(Uy(B(n)),R(`defeature`,{selection:r},[V(n)]))}function kS(e){let t=fS(e),n=B(t);return z(typeof n?.simplify==`function`?n.simplify():Uy(n),R(`simplify`,{},[V(t)]))}function AS(e){let t=fS(e),n=B(t);return z(typeof n?.mirror==`function`?n.mirror([1,0,0]):Uy(n),R(`reverseShape`,{},[V(t)]))}function jS(e,t){let n=fS(t.shape),r=gS(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 z(cS(e,B(n),a),R(`fillet`,{radii:i,selection:r},[V(n)]))}function MS(e){return{fillet:(t,n,r)=>bS(e,`fillet`,t,n,r),chamfer:(t,n,r)=>bS(e,`chamfer`,t,n,r),chamferDistAngle:(t,n,r,i)=>xS(e,t,n,r,i),shell:(t,n,r,i)=>CS(e,t,n,r,i),thicken:(t,n)=>wS(e,t,n),offset:(t,n,r)=>TS(e,t,n,r),filletVariable:(t,n)=>ES(e,t,n),draft:(e,t,n,r,i)=>DS(e,t,n,r,i),defeature:(e,t)=>OS(e,t),offsetWire2D:()=>By(`offsetWire2D`),simplify:e=>kS(e),reverseShape:e=>AS(e),shellBatch:t=>t.map(t=>CS(e,t.shape,t.faces,t.thickness,t.tolerance)),filletBatch:t=>t.map(t=>jS(e,t))}}function NS(e){return B(e).getMesh()}function PS(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 FS(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 IS(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 LS(e,t){let n=NS(e),r=PS(n),i=new Uint32Array(n.triVerts);return{vertices:r,normals:t.skipNormals?new Float32Array:FS(r,i),triangles:i,uvs:t.includeUVs?new Float32Array(r.length/3*2):new Float32Array,faceGroups:IS(n)}}function RS(e,t,n){let r=NS(e),i=PS(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 zS(e){return!0}function BS(e){return{mesh:(e,t)=>LS(e,t),meshEdges:(e,t,n)=>RS(e,t,n),hasTriangulation:e=>zS(e),meshShape:(e,t,n)=>{}}}function VS(e,t=[0,0,0]){return Array.isArray(e)&&e.length>=3?[Number(e[0]),Number(e[1]),Number(e[2])]:[...t]}function HS(e,t=0){return typeof e==`number`?e:t}function US(e,t=``){return typeof e==`string`?e:t}function WS(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function GS(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function KS(e,t,n,r){return WS(t,WS(GS(n,e[0]),GS(r,e[1])))}function qS(e,t){let n=t.outline??[];if(n.length<3)throw Error(`manifold replay: profile outline needs at least three points`);let r=VS(t.origin),i=VS(t.xAxis,[1,0,0]),a=VS(t.yAxis,[0,1,0]),o=n.map(e=>KS(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 JS(e,t){return qS(e,t)}function YS(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 XS(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 ZS(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=>YS(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=XS(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(YS(e,t)))}function QS(e){let t=e.selection;return t===void 0?void 0:t}function $S(e){let t=e[0];if(t===void 0)throw Error(`manifold replay: op requires an input shape`);return t}function eC(e,t,n){return e.createAxis1(t[0],t[1],t[2],n[0],n[1],n[2])}function tC(e,t){return(n,r)=>{let i=qS(n,r),a=VS(r[e]),o=VS(r[t],[0,0,1]),s=HS(r.angleDeg,360);return n.revolve(i,eC(n,a,o),Math.PI/180*s)}}var nC={makeBox:(e,t)=>e.makeBox(HS(t.width),HS(t.height),HS(t.depth)),makeBoxWithCorners:(e,t)=>e.makeBoxFromCorners(VS(t.p1),VS(t.p2)),makeCylinder:(e,t)=>e.makeCylinder(HS(t.radius),HS(t.height),VS(t.center),VS(t.direction,[0,0,1])),makeSphere:(e,t)=>e.makeSphere(HS(t.radius),VS(t.center)),makeCone:(e,t)=>e.makeCone(HS(t.radius1),HS(t.radius2),HS(t.height),VS(t.center),VS(t.direction,[0,0,1])),makeTorus:(e,t)=>e.makeTorus(HS(t.majorRadius),HS(t.minorRadius),VS(t.center),VS(t.direction,[0,0,1])),makeEllipsoid:(e,t)=>e.makeEllipsoid(HS(t.aLength),HS(t.bLength),HS(t.cLength)),makeFuse:(e,t,n)=>{if(n.length<2)return $S(n);let r=$S(n);for(let t of n.slice(1))r=e.fuse(r,t);return r},makeCut:(e,t,n)=>{let r=$S(n);return e.cutAll(r,n.slice(1))},makeCommon:(e,t,n)=>{let r=$S(n);for(let t of n.slice(1))r=e.intersect(r,t);return r},translateShape:(e,t,n)=>e.translate($S(n),HS(t.x),HS(t.y),HS(t.z)),rotateShape:(e,t,n)=>e.rotate($S(n),HS(t.angle),VS(t.axis,[0,0,1]),VS(t.center)),scaleShape:(e,t,n)=>e.scale($S(n),VS(t.center),HS(t.factor,1)),mirrorShape:(e,t,n)=>e.mirror($S(n),VS(t.origin),VS(t.normal,[1,0,0])),transformShape:(e,t,n)=>e.transform($S(n),t.matrix),generalTransform:(e,t,n)=>e.generalTransform($S(n),t.linear,VS(t.translation),!!t.isOrthogonal),generalTransformNonOrthogonal:(e,t,n)=>e.generalTransformNonOrthogonal($S(n),t.linear,VS(t.translation)),gridPattern:(e,t,n)=>{if(typeof e.gridPattern!=`function`)throw Error(`manifold replay: target kernel lacks gridPattern`);return e.gridPattern($S(n),VS(t.directionX),VS(t.directionY),HS(t.spacingX),HS(t.spacingY),HS(t.countX,1),HS(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)=>qS(e,t),extrude:(e,t)=>{let n=qS(e,t);return e.extrude(n,VS(t.direction,[0,0,1]),HS(t.length,1))},revolve:tC(`axisOrigin`,`axisDirection`),revolveVec:tC(`center`,`direction`),loft:(e,t)=>{let n=(t.sections??[]).map(t=>rC(e,t));return e.loft(n,!!t.ruled)},loftAdvanced:(e,t)=>{let n=(t.sections??[]).map(t=>rC(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(iC(e,t),aC(e,t)),simplePipe:(e,t)=>e.simplePipe(iC(e,t),aC(e,t)),sweepWithOptions:(e,t)=>e.sweepWithOptions(iC(e,t),aC(e,t),US(t.contactMode),t.scaleValues??[],HS(t.segments,0)),sweepPipeShell:(e,t)=>{let n=e.sweepPipeShell(iC(e,t),aC(e,t));return oC(n)?n.shape:n},helicalSweep:(e,t)=>e.helicalSweep(iC(e,t),VS(t.axisOrigin),VS(t.axisDirection,[0,0,1]),HS(t.radius),HS(t.pitch),HS(t.turns,1)),draftPrism:(e,t)=>{let n=qS(e,t);return e.draftPrism(n,n,n,HS(t.height),HS(t.angleDeg),!!t.fuse)},fillet:(e,t,n)=>{let r=$S(n),i=ZS(e,r,QS(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=$S(n),i=ZS(e,r,QS(t),`edge`);return e.chamfer(r,i,t.radius)},chamferDistAngle:(e,t,n)=>{let r=$S(n),i=ZS(e,r,QS(t),`edge`);return e.chamferDistAngle(r,i,HS(t.distance),HS(t.angleDeg))},shell:(e,t,n)=>{let r=$S(n),i=ZS(e,r,QS(t),`face`);return typeof t.tolerance==`number`?e.shell(r,i,HS(t.thickness),t.tolerance):e.shell(r,i,HS(t.thickness))},thicken:(e,t,n)=>e.thicken($S(n),HS(t.thickness)),offset:(e,t,n)=>typeof t.tolerance==`number`?e.offset($S(n),HS(t.distance),t.tolerance):e.offset($S(n),HS(t.distance)),filletVariable:(e,t,n)=>e.filletVariable($S(n),US(t.spec)),draft:(e,t,n)=>{let r=$S(n),i=ZS(e,r,QS(t),`face`);return e.draft(r,i,VS(t.pullDirection,[0,0,1]),VS(t.neutralPlane),HS(t.angleDeg))},defeature:(e,t,n)=>{let r=$S(n),i=ZS(e,r,QS(t),`face`);return e.defeature(r,i)},simplify:(e,t,n)=>e.simplify($S(n)),reverseShape:(e,t,n)=>e.reverseShape($S(n)),hull:(e,t,n)=>e.hull([...n],HS(t.tolerance)),hullFromPoints:(e,t)=>{let n=t.points??[];return e.hullFromPoints(n.map(e=>({x:e[0],y:e[1],z:e[2]})),HS(t.tolerance))},sewAndSolidify:(e,t,n)=>e.sewAndSolidify([...n],HS(t.tolerance))};function rC(e,t){let n=JS(e,t);return e.iterShapes(n,`wire`)[0]??n}function iC(e,t){let n=t.section;return n?JS(e,n):qS(e,t)}function aC(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 oC(e){return typeof e==`object`&&!!e&&`shape`in e&&`firstShape`in e&&`lastShape`in e}function sC(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=nC[e.op];if(!a)throw Error(`manifold replay: no replay handler for op '${e.op}'`);let o=e.inputs.map(e=>sC(e,t,n,r)),s=a(t,e.params,o);return n.set(e,s),r.add(s),s}function cC(e,t,n=new Map){let r=new Set,i=sC(e,t,n,r);for(let e of r)e!==i&&t.dispose(e);return i}function lC(e){return B(e)}function uC(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 dC(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 fC(e){let t=e;if(t&&t.__manifoldSub&&t.box)return t.box;let n=uC(e);return n?dC(n):lC(e).boundingBox()}function pC(e){return lC(e)?.getMesh?.()}function mC(e,t){let n=t*e.numProp;return[e.vertProperties[n]??0,e.vertProperties[n+1]??0,e.vertProperties[n+2]??0]}function hC(e,t){let n=t*3;return[e.triVerts[n]??0,e.triVerts[n+1]??0,e.triVerts[n+2]??0]}function gC(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 _C(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function vC(e){let t=fC(e);return[(t.min[0]+t.max[0])/2,(t.min[1]+t.max[1])/2,(t.min[2]+t.max[2])/2]}function yC(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=mC(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 bC(e){let t=pC(e);if(!t)return vC(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]=hC(t,e),s=mC(t,n),c=mC(t,a),l=mC(t,o),u=_C(s,gC(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?yC(t):[i[0]/r,i[1]/r,i[2]/r]}function xC(e){let t=pC(e);if(!t)return vC(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]=hC(t,e),s=mC(t,n),c=mC(t,a),l=mC(t,o),u=gC([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?yC(t):[i[0]/r,i[1]/r,i[2]/r]}function SC(e){return lC(e).volume()}function CC(e){let t=e;return t&&t.__nativeFace&&typeof t.area==`number`?t.area:lC(e).surfaceArea()}function wC(e){let t=e;if(t&&t.__manifoldSub&&t.box)return{min:[...t.box.min],max:[...t.box.max]};let n=fC(e);return{min:[...n.min],max:[...n.max]}}function TC(e){return bC(e)}function EC(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 DC(e,t){return EC(fC(e),fC(t))}function OC(e,t=!1){return{volume:SC(e),area:CC(e),length:0,centerOfMass:TC(e),boundingBox:wC(e)}}function kC(e,t,n){let r=Ky();if(!r)throw new c(`manifold: surfaceCurvature requires a registered occt kernel; none is available`);let i=Wy(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=Jy.get(i.node)??(()=>{let e=cC(i.node,r);return Jy.set(i.node,e),e})();return r.surfaceCurvature(a,t,n)}function AC(e){return{volume:e=>SC(e),area:e=>CC(e),length:e=>{let t=e;if(t&&t.__nativeEdge&&typeof t.length==`number`)return t.length;let n=Wy(e)?.node;return n?.op===`profileEdge`&&n.params?.curve?Rb(n.params.curve):By(`length`)},centerOfMass:e=>TC(e),linearCenterOfMass:e=>TC(e),boundingBox:e=>wC(e),distance:(e,t)=>DC(e,t),surfaceCurvature:(e,t,n)=>kC(e,t,n),surfaceCenterOfMass:e=>xC(e),measureBulk:(e,t)=>OC(e,t),createDistanceQuery:e=>({distanceTo:t=>DC(e,t),dispose:()=>{}})}}function jC(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 MC(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:jC(t,r[0]??0),normal:S,center:C,area:f,min:[p,m,h],max:[g,_,v],tris:y})}return l}function NC(e){return!!e&&typeof e==`object`&&e.__nativeFace===!0}var PC=Math.cos(45*Math.PI/180),FC=(e,t)=>e<t?e*1e9+t:t*1e9+e,IC=(e,t)=>e<t?`${e},${t}`:`${t},${e}`;function LC(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=FC(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]>PC)continue;let s=IC(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 RC(t))d.push(zC(e,n,s));return d}function RC(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 zC(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:BC(i)?`LINE`:`CIRCLE`}}function BC(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 VC(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 HC(e){return!!e&&typeof e==`object`&&e.__nativeVertex===!0}function UC(e){return!!e&&typeof e==`object`&&e.__nativeEdge===!0}function WC(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 GC(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 KC(e,t){let n=Wy(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=qy(t),i=Jy.get(n.node);if(i!==void 0)return{occt:r,brep:i};let a=cC(n.node,r);return Jy.set(n.node,a),{occt:r,brep:a}}function qC(e){if(Wy(e))return`solid`;let{occt:t,brep:n}=KC(e,`shapeType`);return t.shapeType(n)}function JC(e,t){let n=Wy(e),r=Wy(t);return!n||!r?!1:n.manifold===r.manifold}function YC(e,t){if(!Wy(e))return 0;let{occt:n,brep:r}=KC(e,`hashCode`);return n.hashCode(r,t)}function XC(e){let t=Wy(e);return t?!B(t):!0}function ZC(e,t){let n=Wy(e);if(!n)return[];if(t===`solid`)return[e];if(t===`vertex`){let e=B(n);return e&&typeof e.getMesh==`function`?VC(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=B(n);if(e&&typeof e.getMesh==`function`)return MC(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=B(n);if(e&&typeof e.getMesh==`function`)return LC(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=Ky();if(!r)return[];let i=Jy.get(n.node)??(()=>{let e=cC(n.node,r);return Jy.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 QC(e){let{occt:t,brep:n}=KC(e,`edgeToFaceMap`);return t.edgeToFaceMap(n)}function $C(e,t){let{occt:n,brep:r}=KC(e,`adjacentFaces`);return n.adjacentFaces(r,t)}function ew(e){return{iterShapes:ZC,iterShapeList:(e,t)=>{qy(`iterShapeList`).iterShapeList(e,t)},shapeType:qC,isSame:JC,isEqual:JC,downcast:e=>e,copyShape:e=>{let t=Wy(e);return t?z(Uy(B(t)),R(`translateShape`,{x:0,y:0,z:0},[t.node])):e},hashCode:YC,isNull:XC,shapeOrientation:e=>`forward`,edgeToFaceMap:QC,sharedEdges:(e,t)=>qy(`sharedEdges`).sharedEdges(e,t),adjacentFaces:$C,sew:()=>{throw Error(`manifold: sew is unsupported on the mesh kernel; use a B-rep kernel`)}}}function tw(e){return B(e).getMesh()}function nw(e){return e.numProp&&e.numProp>=3?e.numProp:3}function rw(e){return Math.floor(e.vertProperties.length/nw(e))}function iw(e,t){let n=t*nw(e);return[e.vertProperties[n]??0,e.vertProperties[n+1]??0,e.vertProperties[n+2]??0]}function aw(e,t){let n=t*3;return[e.triVerts[n]??0,e.triVerts[n+1]??0,e.triVerts[n+2]??0]}function ow(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 sw(e,t){let n=tw(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]=aw(n,e),s=iw(n,r),c=iw(n,a),l=iw(n,o),u=ow(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]=aw(n,e),o=iw(n,t),s=iw(n,r),c=iw(n,a),l=ow(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
|
+
`)}function cw(e){let t=tw(e),n=rw(t),r=Math.floor(t.triVerts.length/3),i=[`# exported by brepjs manifold kernel`];for(let e=0;e<n;e++){let n=iw(t,e);i.push(`v ${n[0]} ${n[1]} ${n[2]}`)}for(let e=0;e<r;e++){let[n,r,a]=aw(t,e);i.push(`f ${n+1} ${r+1} ${a+1}`)}return new TextEncoder().encode(i.join(`
|
|
11
|
+
`)).buffer}function lw(e){let t=tw(e),n=rw(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=iw(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]=aw(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 uw(e,t,n=`importMesh`){let r=new e.Mesh({numProp:3,vertProperties:t.vertProperties,triVerts:t.triVerts});return z(new e.Manifold(r),R(n,{},[]))}function dw(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 uw(e,{vertProperties:Float32Array.from(r),triVerts:Uint32Array.from(i)})}function fw(e,t){let n=new Uint8Array(t),r=new TextDecoder().decode(n.subarray(0,Math.min(n.length,80))).trimStart().toLowerCase().startsWith(`solid`)&&hw(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=mw(i);return uw(e,{vertProperties:Float32Array.from(a.vertices),triVerts:Uint32Array.from(a.indices)})}var pw=1e6;function mw(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*pw)},${Math.round(o*pw)},${Math.round(s*pw)}`,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 hw(e){return e.length<84?!0:84+new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(80,!0)*50!==e.length}var gw=1e-6;function _w(e,t){let n=V(t);if(n.replayable)return cC(n,e)}function vw(e,t){let n=tw(t),r=Math.floor(n.triVerts.length/3),i=[];for(let t=0;t<r;t++){let[r,a,o]=aw(n,t),s=e.buildTriFace(iw(n,r),iw(n,a),iw(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,gw)}function yw(e){let t=qy(`B-rep export`),n=_w(t,e);return n===void 0?(console.warn(`manifold: exact B-rep unavailable (non-replayable op-graph); exporting faceted approximation`),{occt:t,brep:vw(t,e)}):{occt:t,brep:n}}function bw(e,t,n,r){let i=t.mesh(n,{tolerance:.01,angularTolerance:.5});return uw(e,{vertProperties:Float32Array.from(i.vertices),triVerts:Uint32Array.from(i.triangles)},r)}var xw=1179937895,Sw=2,Cw=1313821514,ww=5130562,Tw=5126,Ew=5125,Dw=5123,Ow=5121,kw=34962,Aw=34963,jw=4;function Mw(e){return e+3&-4}function Nw(e){let t=tw(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=Mw(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:jw}]}],accessors:[{bufferView:0,componentType:Tw,count:r,type:`VEC3`,min:[o,s,c],max:[l,u,d]},{bufferView:1,componentType:Ew,count:i,type:`SCALAR`}],bufferViews:[{buffer:0,byteOffset:0,byteLength:p,target:kw},{buffer:0,byteOffset:m,byteLength:f.byteLength,target:Aw}],buffers:[{byteLength:h}]},_=new TextEncoder().encode(JSON.stringify(g)),v=Mw(_.length),y=Mw(h),b=20+v+8+y,x=new ArrayBuffer(b),S=new DataView(x),C=new Uint8Array(x);S.setUint32(0,xw,!0),S.setUint32(4,Sw,!0),S.setUint32(8,b,!0);let w=12;S.setUint32(w,v,!0),S.setUint32(w+4,Cw,!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,ww,!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 Pw(e,t){let n=new DataView(t);if(n.getUint32(0,!0)!==xw)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===Cw?i=JSON.parse(new TextDecoder().decode(s)):r===ww&&(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===Ew?4:e.componentType===Dw?2:+(e.componentType===Ow);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 uw(e,{vertProperties:p,triVerts:m},`importGLB`)}function Fw(e){return{exportSTL:(e,t)=>sw(e,t),exportOBJ:e=>cw(e),exportPLY:e=>lw(e),importSTL:t=>fw(e,typeof t==`string`?new TextEncoder().encode(t).buffer:t),importOBJ:t=>dw(e,t),exportSTEP:e=>qy(`exportSTEP`).exportSTEP(e.map(e=>yw(e).brep)),exportIGES:e=>qy(`exportIGES`).exportIGES(e.map(e=>yw(e).brep)),toBREP:e=>{let{occt:t,brep:n}=yw(e);return t.toBREP(n)},exportSTEPAssembly:(e,t)=>{let n=qy(`exportSTEPAssembly`),r=e.map(e=>{let t={shape:yw(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=qy(`createXCAFDocument`),n=e.map(e=>{let t={shape:yw(e.shape).brep,name:e.name};return e.color===void 0?t:{...t,color:e.color}});return t.createXCAFDocument(n)},writeXCAFToSTEP:(e,t)=>qy(`writeXCAFToSTEP`).writeXCAFToSTEP(e,t),exportSTEPConfigured:(e,t)=>{let n=qy(`exportSTEPConfigured`),r=e.map(e=>{let t={shape:yw(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=qy(`importSTEP`);return n.importSTEP(t).map(t=>bw(e,n,t,`importSTEP`))},importIGES:t=>{let n=qy(`importIGES`);return n.importIGES(t).map(t=>bw(e,n,t,`importIGES`))},fromBREP:t=>{let n=qy(`fromBREP`);return bw(e,n,n.fromBREP(t),`fromBREP`)},exportGLB:e=>Nw(e),importGLB:t=>Pw(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 Iw(e){return B(e).getMesh()}function Lw(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 Rw(e,t){let n=e;if(n&&n.__manifoldSub&&n.occt){let e=Ky();if(!e)throw new c(`manifold: sub-shape geometry query requires a registered occt kernel`);return t(n.occt,e)}let r=Wy(e);if(!r)throw Error(`manifold: exact geometry query requires a manifold shape handle`);let i=Ky();if(!i)throw new c(`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=Jy.get(r.node);return a===void 0&&(a=cC(r.node,i),Jy.set(r.node,a)),t(a,i)}function zw(e){let t=Wy(e);if(!t)return;let n=t.node;return n.op===`profileEdge`?n.params?.curve:void 0}function Bw(e){return{curveType:e=>{let t=zw(e);return t?Pb(t):UC(e)?e.curveType:Rw(e,(e,t)=>t.curveType(e))},curveParameters:e=>{let t=zw(e);if(t){let e=Fb(t);return[e.first,e.last]}return UC(e)?[0,e.length]:Rw(e,(e,t)=>t.curveParameters(e))},curvePointAtParam:(e,t)=>{let n=zw(e);return n?Ib(n,t):UC(e)?WC(e,t):Rw(e,(e,n)=>n.curvePointAtParam(e,t))},curveTangent:(e,t)=>{let n=zw(e);return n?{point:Ib(n,t),tangent:Lb(n,t)}:UC(e)?{point:WC(e,t),tangent:GC(e,t)}:Rw(e,(e,n)=>n.curveTangent(e,t))},curveIsClosed:e=>{let t=zw(e);return t?zb(t):Rw(e,(e,t)=>t.curveIsClosed(e))},curveIsPeriodic:e=>{let t=zw(e);return t?Bb(t):Rw(e,(e,t)=>t.curveIsPeriodic(e))},curvePeriod:e=>{let t=zw(e);return t?Vb(t):Rw(e,(e,t)=>t.curvePeriod(e))},interpolatePoints:(e,t)=>qy(`interpolatePoints`).interpolatePoints(e,t),approximatePoints:(e,t)=>qy(`approximatePoints`).approximatePoints(e,t),curveDegreeElevate:(e,t)=>Rw(e,(e,n)=>n.curveDegreeElevate(e,t)),curveKnotInsert:(e,t,n)=>Rw(e,(e,r)=>r.curveKnotInsert(e,t,n)),curveKnotRemove:(e,t,n)=>Rw(e,(e,r)=>r.curveKnotRemove(e,t,n)),curveSplit:(e,t)=>Rw(e,(e,n)=>n.curveSplit(e,t)),createCurveAdaptor:e=>Rw(e,(e,t)=>t.createCurveAdaptor(e)),getBezierPenultimatePole:e=>Rw(e,(e,t)=>t.getBezierPenultimatePole(e)),getNurbsCurveData:e=>Rw(e,(e,t)=>t.getNurbsCurveData?.(e)??null),vertexPosition:e=>HC(e)?e.point:Wy(e)?Lw(Iw(e),0):Rw(e,(e,t)=>t.vertexPosition(e)),surfaceType:e=>{if(NC(e))return`plane`;let t=Wy(e);return t&&t.node.op===`profileFace`?`plane`:Rw(e,(e,t)=>t.surfaceType(e))},uvBounds:e=>NC(e)?{uMin:0,uMax:1,vMin:0,vMax:1}:Rw(e,(e,t)=>t.uvBounds(e)),outerWire:e=>Rw(e,(e,t)=>t.outerWire(e)),surfaceNormal:(e,t,n)=>NC(e)?e.normal:Rw(e,(e,r)=>r.surfaceNormal(e,t,n)),pointOnSurface:(e,t,n)=>Rw(e,(e,r)=>r.pointOnSurface(e,t,n)),uvFromPoint:(e,t)=>Rw(e,(e,n)=>n.uvFromPoint(e,t)),projectPointOnFace:(e,t)=>Rw(e,(e,n)=>n.projectPointOnFace(e,t)),classifyPointOnFace:(e,t,n,r)=>Rw(e,(e,i)=>i.classifyPointOnFace(e,t,n,r)),classifyPointRobust:(e,t,n)=>Rw(e,(e,r)=>r.classifyPointRobust(e,t,n)),classifyPointWinding:(e,t,n)=>Rw(e,(e,r)=>r.classifyPointWinding(e,t,n)),approximateSurfaceLspia:(e,t,n,r,i,a,o,s,c)=>qy(`approximateSurfaceLspia`).approximateSurfaceLspia(e,t,n,r,i,a,o,s,c),untrimFace:(e,t,n)=>Rw(e,(e,r)=>r.untrimFace(e,t,n)),getSurfaceCylinderData:e=>Rw(e,(e,t)=>t.getSurfaceCylinderData(e)),getSurfaceAxis:e=>Rw(e,(e,t)=>t.getSurfaceAxis(e)),reverseSurfaceU:e=>qy(`reverseSurfaceU`).reverseSurfaceU(e),detectSmallFeatures:(e,t,n)=>Rw(e,(e,r)=>r.detectSmallFeatures(e,t,n)),recognizeFeatures:(e,t)=>Rw(e,(e,n)=>n.recognizeFeatures(e,t)),projectEdges:(e,t,n,r)=>Rw(e,(e,i)=>i.projectEdges(e,t,n,r)),getNurbsSurfaceData:e=>Rw(e,(e,t)=>t.getNurbsSurfaceData?.(e)??null)}}var Vw={hasErrors:!1,hasWarnings:!1,messages:[]};function Hw(){return{modified:new Map,generated:new Map,deleted:new Set}}function Uw(e){return{shape:e,evolution:Hw()}}function Ww(e){return{shape:e,evolution:Hw(),diagnostics:Vw}}function Gw(e){let t=Db(e),n=ab(e),r=MS(e);return{translateWithHistory:(e,n,r,i)=>Uw(t.translate(e,n,r,i)),rotateWithHistory:(e,n,r,i,a,o)=>Uw(t.rotate(e,n,a,o)),mirrorWithHistory:(e,n,r)=>Uw(t.mirror(e,n,r)),scaleWithHistory:(e,n,r)=>Uw(t.scale(e,n,r)),generalTransformWithHistory:(e,n,r,i)=>Uw(t.generalTransform(e,n,r,i)),fuseWithHistory:(e,t,r,i,a)=>Ww(n.fuse(e,t,a)),cutWithHistory:(e,t,r,i,a)=>Ww(n.cut(e,t,a)),intersectWithHistory:(e,t,r,i,a)=>Ww(n.intersect(e,t,a)),filletWithHistory:(e,t,n)=>Uw(r.fillet(e,t,n)),chamferWithHistory:(e,t,n)=>Uw(r.chamfer(e,t,n)),shellWithHistory:(e,t,n,i,a,o)=>Uw(r.shell(e,t,n,o)),thickenWithHistory:(e,t)=>Uw(r.thicken(e,t)),offsetWithHistory:(e,t,n,i,a)=>Uw(r.offset(e,t,a)),draftWithHistory:(e,t,n,i,a)=>Uw(r.draft(e,t,n,i,a)),applyComposedTransformWithHistory:(e,n)=>Uw(t.transform(e,n))}}function Kw(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 qw(e){return{isValid:e=>Kw(e),isValidStrict:e=>Kw(e),healSolid:e=>Kw(e)?e:null,healFace:e=>e,healWire:e=>e,mergeCoincidentVertices:()=>0,removeDegenerateEdges:()=>0,fixFaceOrientations:()=>0,fixShape:e=>e,fixSelfIntersection:e=>e}}var Jw=.004;function Yw(e){return!!e&&typeof e==`object`&&e.__nativeC2d===!0}function Xw(e,t){return{__nativeC2d:!0,k:`line`,p1:e,p2:t}}function Zw(e,t,n,r,i){return{__nativeC2d:!0,k:`conic`,c:e,u:t,v:n,a0:r,a1:i}}function Qw(e,[t,n]){return[e.a*t+e.b*n+e.tx,e.c*t+e.d*n+e.ty]}function $w(e,[t,n]){return[e.a*t+e.b*n,e.c*t+e.d*n]}function eT(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 tT(e,t){return e.k===`line`?Xw(Qw(t,e.p1),Qw(t,e.p2)):e.k===`bezier`?{__nativeC2d:!0,k:`bezier`,pts:e.pts.map(e=>Qw(t,e))}:Zw(Qw(t,e.c),$w(t,e.u),$w(t,e.v),e.a0,e.a1)}function nT(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 rT(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 iT(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 nT(r,t)}function aT(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<=Jw)return Math.max(2,Math.ceil(t/(2*Math.PI)*8));let a=2*Math.acos(Math.max(-1,1-Jw/i));return Math.max(2,Math.ceil(t/a))}function oT(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(nT(e.pts,n/24));return t}let t=e.a1-e.a0,n=aT(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 sT(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 Xw(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-_),Zw(f,[p,0],[0,p],h,_)}function cT(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(!Yw(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=rT(n,n.a0),i=rT(n,(n.a0+n.a1)/2),a=rT(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(oT(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)=>Xw([e,t],[n,r]),makeCircle2d:(e,t,n,r=!0)=>Zw([e,t],[n,0],r?[0,n]:[0,-n],0,2*Math.PI),makeArc2dThreePoints:(e,t,n,r,i,a)=>sT([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 Xw([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),Zw([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 Zw([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 Zw([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`?nT(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:nT(n.pts,t),tangent:iT(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 Zw(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 Xw([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=eT(e,t);Object.assign(e,n)},transformCurve2dGeneral:(e,t)=>tT(i(e),t),translateCurve2d:(e,t,n)=>tT(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 tT(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)=>tT(i(e),{a:t,b:0,c:0,d:t,tx:n-t*n,ty:r-t*r}),mirrorCurve2dAtPoint:(e,t,n)=>tT(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 tT(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 tT(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(Yw(t))r=oT(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,h=oT(i(e)).map(([e,n])=>[t[0]+l*e+f*n,t[1]+u*e+p*n,t[2]+d*e+m*n]);return z(n,R(`profileEdge`,{pts:h},[]))},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)=>Yw(n)?t(n,...i):r(e,n,...i)))}return s}var lT=`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 uT(e){let t=Ky();if(!t)throw Error(`manifold: ${e} unsupported on manifold kernel; no B-rep kernel registered`);return t}function dT(e){let t={};for(let e of lT)t[e]=(...t)=>uT(e)[e](...t);let n=cT(e,()=>Ky());return Object.assign(t,n),t}function fT(e){return{sketchNew:()=>By(`sketchNew`),sketchAddPoint:()=>By(`sketchAddPoint`),sketchAddArc:()=>By(`sketchAddArc`),sketchAddConstraint:()=>By(`sketchAddConstraint`),sketchSolve:()=>By(`sketchSolve`),sketchDof:()=>By(`sketchDof`)}}function pT(e){return{projectEdges:()=>By(`projectEdges`)}}function mT(e){return{dispose(e){let t=Wy(e);if(t){let e=Jy.get(t.node);e!==void 0&&(Ky()?.dispose(e),Jy.delete(t.node))}(e?.manifold)?.delete?.()},executeBatch:()=>By(`executeBatch`),checkpoint:()=>By(`checkpoint`),checkpointCount:()=>0,restoreCheckpoint:()=>By(`restoreCheckpoint`),discardCheckpoint:()=>By(`discardCheckpoint`)}}var hT={draft:30,standard:10,fine:3},gT=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?.(hT[e])}constructor(e){this.oc=e,Object.assign(this,eb(e),ab(e),Db(e),Px(e),oS(e),MS(e),BS(e),AC(e),ew(e),Fw(e),Bw(e),Gw(e),qw(e),dT(e),fT(e),pT(e),mT(e))}};function _T(e){return import(e)}function vT(e){return`projectEdges`in e}function yT(e){return`sketchNew`in e&&`sketchDof`in e}var bT=new Map,xT=null,ST=null;function CT(e){wT(`manifold`,new gT(e))}function wT(e,t){bT.set(e,t),xT||=e,e===xT&&(ST=t)}function H(e){if(!e&&ST)return ST;let t=e??xT;if(!t)throw Error(`brepjs kernel not initialized. Call initFromOC() or registerKernel() before using the library.`);let n=bT.get(t);if(!n)throw Error(`brepjs: kernel '${t}' is not registered.`);return n}function TT(e){let t=H(e);if(!Lo(t))throw Error(`brepjs: current kernel does not support 2D operations.`);return t}function ET(){return xT}function DT(e,t){let n=xT;xT=e,ST=bT.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{xT=n,ST=n?bT.get(n)??null:null}}function OT(e){return H(e).capabilities}function kT(e,t){let n=Po();try{Io(e),H().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{Io(n),H().setQuality?.(n)}}var AT=new Map;function jT(e,t){AT.set(e,t)}function MT(e){return AT.get(e)}function NT(e,t){let n=AT.get(e);if(!n)throw Error(`withTier: no tier registered for "${e}". Call registerKernelTier("${e}", { kernel, quality }) first.`);return DT(n.kernel,()=>kT(n.quality,t))}function PT(e){$o(),pl(),Ko(),Uc(),Wc(),al(),ol();let t=new Yf(e);wT(`occt`,t),xT=`occt`,ST=t}function FT(){let e=H(),t=e.makeBox(1,1,1);try{e.dispose(t)}catch{}}async function IT(){if(xT)return xT;try{let{OcctKernel:e}=await _T(`occt-wasm`),t=await e.init();return wT(`occt-wasm`,qa.fromKernel(t)),`occt-wasm`}catch{}try{return PT(await(await _T(`brepjs-opencascade`)).default()),`occt`}catch{}try{let e=await _T(`brepkit-wasm`);return typeof e.default==`function`&&await e.default(),wT(`brepkit`,new zy(new e.BrepKernel)),`brepkit`}catch{}throw Error(`brepjs: no kernel package found. Install one of:
|
|
13
|
+
npm install occt-wasm (recommended, default)
|
|
14
|
+
npm install brepjs-opencascade
|
|
15
|
+
npm install brepkit-wasm`)}function LT(){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 RT=Symbol;RT.dispose??=Symbol.for(`Symbol.dispose`),RT.asyncDispose??=Symbol.for(`Symbol.asyncDispose`);var zT=globalThis;zT.FinalizationRegistry||=(console.warn(`brepjs: FinalizationRegistry unavailable — garbage collection will not work`),class{register(e,t,n){}unregister(e){return!1}});var BT={liveHandles:0,peakHandles:0,gcCollected:0,scopeEnters:0,scopeExits:0};function VT(){return{...BT}}function HT(){BT.liveHandles=0,BT.peakHandles=0,BT.gcCollected=0,BT.scopeEnters=0,BT.scopeExits=0}function UT(){BT.liveHandles++,BT.liveHandles>BT.peakHandles&&(BT.peakHandles=BT.liveHandles)}function WT(){BT.liveHandles--}function GT(){BT.gcCollected++,BT.liveHandles--}var KT=new FinalizationRegistry(e=>{GT();try{e.delete()}catch{}});function qT(e){let t=H(),n=!1,r,i=()=>{if(r){for(let e of r)try{e()}catch{}r=void 0}},a=()=>{if(!n){n=!0,WT(),KT.unregister(o),i();try{t.dispose(e)}catch{}}},o={get wrapped(){if(n)throw Error(`Shape handle has been disposed`);return e},get disposed(){return n},[Symbol.dispose](){a()},delete(){a()},onDispose(e){if(n){e();return}(r??=[]).push(e)}};return UT(),KT.register(o,{delete:()=>{t.dispose(e)}},o),o}function JT(e){let t=()=>{};return{get wrapped(){return e},get disposed(){return!1},[Symbol.dispose]:t,delete:t,onDispose:t}}function YT(e){let t=H(),n;try{n=t.checkpoint()}catch(t){if(!l(t))throw t;return e()}let r;try{r=e()}catch(e){try{t.restoreCheckpoint(n)}catch{}throw e}return t.restoreCheckpoint(n),r}function XT(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,WT(),KT.unregister(n);try{e.delete()}catch{}}}};return UT(),KT.register(n,e,n),n}var ZT=class{handles=[];constructor(){BT.scopeEnters++}register(e){return this.handles.push(()=>{try{let t=e[Symbol.dispose];typeof t==`function`?t.call(e):e.delete()}catch{}}),e}track(e){return this.handles.push(()=>{try{e[Symbol.dispose]()}catch{}}),e}[Symbol.dispose](){BT.scopeExits++;for(let e=this.handles.length-1;e>=0;e--)this.handles[e]?.();this.handles.length=0}};function QT(e){try{var t=LT();return e(t.u(new ZT))}catch(e){t.e=e}finally{t.d()}}function $T(e,t){KT.register(e,t,t)}function eE(e){KT.unregister(e)}function tE(e){try{var t=LT();return e(t.u(new ZT))}catch(e){t.e=e}finally{t.d()}}async function nE(e){try{var t=LT();return await e(t.u(new ZT))}catch(e){t.e=e}finally{t.d()}}function rE(e){return!e.disposed}function iE(e){return e.__is2D!==!0}function aE(e){return e.__is2D===!0}function oE(e){if(!iE(e))throw Error(`Expected 3D shape, got 2D`);return e}function sE(e){if(!aE(e))throw Error(`Expected 2D shape, got 3D`);return e}var cE=new WeakMap;function lE(e,t){cE.set(e,t)}function uE(e,t){let n=cE.get(t);if(n!==void 0)return n;let r=e.shapeType(t);return cE.set(t,r),r}function dE(e){return uE(H(),e.wrapped)}function fE(e){return H().curveIsClosed(e.wrapped)}function pE(e){return H().isValid(e.wrapped)}function mE(e){let t=H();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 hE(e){return H().isValid(e.wrapped)}function gE(e){return fE(e)?O(e):k(`Wire is not closed: start and end points do not coincide`)}function _E(e){return pE(e)?O(e):k(`Face orientation is inconsistent or face is invalid`)}function vE(e){return mE(e)?O(e):k(`Shell is not manifold: has free edges or is invalid`)}function yE(e){return hE(e)?O(e):k(`Solid failed BRepCheck validation`)}function bE(e){return H().surfaceType(e.wrapped)===`plane`}function xE(e){let t=H(),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 SE(e){return bE(e)?O(e):k(`Face is not planar: underlying surface is not a geometric plane`)}function CE(e){return xE(e)?O(e):k(`Wire is not planar: edges do not lie in a common plane`)}function wE(e,t){return t===`2D`&&(e.__is2D=!0),e}function TE(e,t){return wE(qT(e),t)}function EE(e,t){return wE(qT(e),t)}function DE(e,t){return wE(qT(e),t)}function OE(e,t){return wE(qT(e),t)}function kE(e){return wE(qT(e))}function AE(e){return wE(qT(e))}function jE(e){return wE(qT(e))}function ME(e,t){return wE(qT(e),t)}function NE(e){return dE(e)===`vertex`}function PE(e){return dE(e)===`edge`}function FE(e){return dE(e)===`wire`}function IE(e){return dE(e)===`face`}function LE(e){return dE(e)===`shell`}function RE(e){return dE(e)===`solid`}function zE(e){return dE(e)===`compound`}function BE(e){let t=dE(e);return t===`shell`||t===`solid`||t===`compsolid`?!0:t===`compound`?iE(e):!1}function VE(e){let t=dE(e);return t===`edge`||t===`wire`}function HE(e,t){let n=H(),r=uE(n,e),i=n.downcast(e,r);return r===`vertex`?TE(i,t):r===`edge`?EE(i,t):r===`wire`?DE(i,t):r===`face`?OE(i,t):r===`shell`?kE(i):r===`solid`?AE(i):r===`compsolid`?jE(i):ME(i,t)}function UE(e){return HE(e)}function WE(e,t){let n=e.id,r=t.wrapped.id;(n!==void 0&&r!==void 0?n===r:t.wrapped===e)||H().dispose(e)}function U(e,t){let n=HE(e,t);return WE(e,n),n}function GE(e,t){let n=e.wrapped;if(e[Symbol.dispose](),n!==t){let e=H();e.dispose(n),e.dispose(t)}}function W(e){H().dispose(e.wrapped),e[Symbol.dispose]()}function KE(e,t,n){lE(e,t);let r=H().downcast(e,t);return t===`vertex`?TE(r,n):t===`edge`?EE(r,n):t===`wire`?DE(r,n):t===`face`?OE(r,n):t===`shell`?kE(r):t===`solid`?AE(r):t===`compsolid`?jE(r):ME(r,n)}function qE(e,t,n){let r=KE(e,t,n);return WE(e,r),r}function JE(e,t,n){return lE(e,t),wE(JT(e),n)}var G=2147483647,YE=Math.PI/180,XE=180/Math.PI;function ZE(e,t,n,r,i){let a={kind:e,code:t,message:n,cause:r};return i?{...a,suggestion:i}:a}var QE={KERNEL_OPERATION:(e,t,n,r)=>ZE(`KERNEL_OPERATION`,e,t,n,r),VALIDATION:(e,t,n,r)=>ZE(`VALIDATION`,e,t,n,r),TYPE_CAST:(e,t,n,r)=>ZE(`TYPE_CAST`,e,t,n,r),SKETCHER_STATE:(e,t,n,r)=>ZE(`SKETCHER_STATE`,e,t,n,r),MODULE_INIT:(e,t,n,r)=>ZE(`MODULE_INIT`,e,t,n,r),COMPUTATION:(e,t,n,r)=>ZE(`COMPUTATION`,e,t,n,r),IO:(e,t,n,r)=>ZE(`IO`,e,t,n,r),QUERY:(e,t,n,r)=>ZE(`QUERY`,e,t,n,r),UNSUPPORTED:(e,t,n,r)=>ZE(`UNSUPPORTED`,e,t,n,r)};function $E(e,t,n,r=`KERNEL_OPERATION`){try{return O(U(e()))}catch(e){let i=e instanceof Error?e.message:String(e),a=r===`KERNEL_OPERATION`?So(i):i,o=xo(t);return k(QE[r](t,`${n}: ${a}`,e,o))}}function eD(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`?So(i):i,o=xo(t);return k(QE[r](t,`${n}: ${a}`,e,o))}}function tD(e,t,n,r=`KERNEL_OPERATION`){try{var i=LT();let a=i.u(new ZT);return $E(()=>e(a),t,n,r)}catch(e){i.e=e}finally{i.d()}}function nD(e,t){let n=H().iterShapes(e,t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=qE(n[e],t);return r}function rD(e,t){let n=H();if(n.subShapeCount)return n.subShapeCount(e.wrapped,t);let r=n.iterShapes(e.wrapped,t);for(let e of r)n.dispose(e);return r.length}function iD(e,t){let n=H();if(n.subShapeHashes)return n.subShapeHashes(e.wrapped,t,G);let r=new Set;for(let i of n.iterShapes(e.wrapped,t))r.add(n.hashCode(i,G)),n.dispose(i);return[...r]}var aD=new WeakMap;function oD(e){let t=aD.get(e);if(!t)return;aD.delete(e);let n=[t.edges,t.faces,t.wires,t.vertices,t.shells,t.solids,t.compSolids];for(let e of n)if(e)for(let t of e)t[Symbol.dispose]()}var sD=new WeakSet;function cD(e){let t=e.wrapped,n=aD.get(t);return n||(n={},aD.set(t,n)),sD.has(e)||(sD.add(e),e.onDispose(()=>{oD(t)})),n}function lD(e){return aD.get(e.wrapped)}function uD(e){oD(e.wrapped)}function dD(e){let t=cD(e);if(t.edges)return t.edges;let n=nD(e.wrapped,`edge`);return t.edges=n,n}function fD(e){let t=cD(e);if(t.faces)return t.faces;let n=nD(e.wrapped,`face`);return t.faces=n,n}function pD(e){let t=cD(e);if(t.wires)return t.wires;let n=nD(e.wrapped,`wire`);return t.wires=n,n}function mD(e){let t=cD(e);if(t.vertices)return t.vertices;let n=nD(e.wrapped,`vertex`);return t.vertices=n,n}function hD(e){let t=cD(e);if(t.solids)return t.solids;let n=nD(e.wrapped,`solid`);return t.solids=n,n}function gD(e){let t=cD(e);if(t.shells)return t.shells;let n=nD(e.wrapped,`shell`);return t.shells=n,n}function _D(e){let t=cD(e);if(t.compSolids)return t.compSolids;let n=nD(e.wrapped,`compsolid`);return t.compSolids=n,n}function*vD(e){for(let t of H().iterShapes(e.wrapped,`edge`))yield qE(t,`edge`)}function*yD(e){for(let t of H().iterShapes(e.wrapped,`face`))yield qE(t,`face`)}function*bD(e){for(let t of H().iterShapes(e.wrapped,`wire`))yield qE(t,`wire`)}function*xD(e){for(let t of H().iterShapes(e.wrapped,`vertex`))yield qE(t,`vertex`)}function*SD(e){for(let t of H().iterShapes(e.wrapped,`solid`))yield qE(t,`solid`)}function*CD(e){for(let t of H().iterShapes(e.wrapped,`shell`))yield qE(t,`shell`)}function*wD(e){for(let t of H().iterShapes(e.wrapped,`compsolid`))yield qE(t,`compsolid`)}function TD(e){let t=cD(e);if(t.bounds)return t.bounds;let{min:n,max:r}=H().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 ED(e){return uE(H(),e.wrapped)}function DD(e){let t=cD(e);if(t.surfaceType!==void 0)return t.surfaceType;let n=H().surfaceType(e.wrapped);return t.surfaceType=n,n}function OD(e){let t=cD(e);if(t.isValid!==void 0)return t.isValid;let n=H().isValid(e.wrapped);return t.isValid=n,n}function kD(e){return{kind:ED(e),faceCount:rD(e,`face`),edgeCount:rD(e,`edge`),wireCount:rD(e,`wire`),vertexCount:rD(e,`vertex`),valid:OD(e),bounds:TD(e)}}function AD(e){return H().vertexPosition(e.wrapped)}function jD(e){return e.length===2?[e[0],e[1],0]:[e[0],e[1],e[2]]}function MD(e){return[e[0],e[1]]}var ND={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function PD(e){if(typeof e==`string`){let t=ND[e];if(!t)throw Error(`Unknown direction: ${e}`);return t}return e}function FD(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function ID(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function LD(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function RD(e){return[-e[0],-e[1],-e[2]]}function zD(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function BD(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 VD(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function HD(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function UD(e,t){return VD(ID(e,t))}function WD(e){let t=VD(e);return t<1e-10?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function GD(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 KD(e,t=1e-10){return HD(e)<t*t}function qD(e,t){let n=zD(e,t),r=VD(e),i=VD(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 JD(e,t,n){let r=ID(e,t),i=HD(n);return i<1e-20?e:ID(e,LD(n,zD(r,n)/i))}function YD(e,t,n){let r=WD(t),i=Math.cos(n),a=Math.sin(n),o=zD(e,r),s=BD(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 XD=e=>Math.round(e*1e3)/1e3;function ZD(e){return`x: ${XD(e[0])}, y: ${XD(e[1])}, z: ${XD(e[2])}`}function QD(e,t=null,n=[0,0,1]){let r=WD(n);if(KD(r))throw Error(`Plane normal must be non-zero`);let i;if(t)i=WD(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?WD([l,u,d]):[1,0,0]}if(KD(i))throw Error(`Plane xDir must be non-zero`);let a=WD(BD(r,i));return{origin:e,xDir:i,yDir:a,zDir:r}}var $D={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 eO(e,t=[0,0,0]){let n=$D[e];if(!n)return k(P(`UNKNOWN_PLANE`,`Could not find plane ${e}`));let r;return r=typeof t==`number`?LD(n.normal,t):jD(t),O(QD(r,n.xDir,n.normal))}function tO(e,t){return typeof e==`string`?eO(e,t):O(e)}function nO(e,t){return e&&typeof e!=`string`?{...e}:j(tO(e??`XY`,t))}function rO(e,t){let[n,r]=t;return FD(FD(e.origin,LD(e.xDir,n)),LD(e.yDir,r))}function iO(e,t){return{...e,origin:FD(e.origin,t)}}function aO(e,t,n=[1,0,0]){let r=t*YE,i=YD(e.zDir,n,r),a=YD(e.xDir,n,r),o=WD(BD(i,a));return{origin:e.origin,xDir:a,yDir:o,zDir:i}}var oO={compound:0,solidCompound:1,solid:2,shell:3,face:4,wire:5,edge:6,vertex:7,shape:8},sO=e=>oO[e],cO={vertex:`vertex`,edge:`edge`,wire:`wire`,face:`face`,shell:`shell`,solid:`solid`,solidCompound:`compsolid`,compound:`compound`,shape:`compound`},lO=function*(e,t){let n=H().iterShapes(e,cO[t]);for(let e of n)yield e},uO=e=>H().isNull(e)?k(wo(`NULL_SHAPE`,`This shape has no type, it is null`)):O(e.ShapeType());function dO(e){if(H().isNull(e))return k(wo(`NULL_SHAPE`,`This shape has no type, it is null`));try{return O(H().downcast(e))}catch(e){return k(wo(`NO_WRAPPER`,`Could not find a wrapper for this shape type`,e))}}function fO(e){if(H().isNull(e))return k(wo(`NULL_SHAPE`,`Cannot copy a null shape`));try{return O(H().copyShape(e))}catch(e){return k(wo(`NO_WRAPPER`,`Could not copy this shape`,e))}}function pO(e){return H().isNull(e)?k(wo(`NULL_SHAPE`,`Cannot cast a null shape`)):O(HE(e))}function mO(e){return H().shapeType(e.wrapped)===`compsolid`}function hO(e){return pO(H().fromBREP(e))}var gO={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 _O(e){return O(gO[DD(e)])}function vO(e){return j(_O(e))}function yO(e){return H().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function bO(e){return HE(H().reverseShape(e.wrapped))}function xO(e){return H().uvBounds(e.wrapped)}function SO(e,t,n){let r=xO(e),i=t*(r.uMax-r.uMin)+r.uMin,a=n*(r.vMax-r.vMin)+r.vMin;return H().pointOnSurface(e.wrapped,i,a)}function CO(e,t){let n=jD(t);return H().uvFromPoint(e.wrapped,n)||[0,0]}function wO(e,t){let n=jD(t);try{let t=n,r=H().uvFromPoint(e.wrapped,t);if(!r)return k(wo(`PROJECTION_FAILED`,`No projection found on the face`));let i=H().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(wo(`PROJECTION_FAILED`,`Point projection failed: ${e instanceof Error?e.message:String(e)}`))}}function TO(e,t){let n,r;if(t)[n,r]=CO(e,t);else{let t=xO(e);n=.5*(t.uMin+t.uMax),r=.5*(t.vMin+t.vMax)}return H().surfaceNormal(e.wrapped,n,r)}function EO(e){return H().surfaceCenterOfMass(e.wrapped)}function DO(e){return H().getSurfaceAxis(e.wrapped)}function OO(e,t,n=1e-6){let[r,i]=CO(e,t);return H().classifyPointOnFace(e.wrapped,r,i,n)}function kO(e){return HE(H().outerWire(e.wrapped))}function AO(e){return HE(H().removeHolesFromFace(e.wrapped))}function jO(e){let t=kO(e);return Array.from(lO(e.wrapped,`wire`)).map(e=>HE(j(dO(e)))).filter(e=>!H().isSame(e.wrapped,t.wrapped))}function MO(e,t){let n=cD(e),r=new Map;for(let n of iD(e,`face`))r.set(n,t);n.faceOrigins=r}function NO(e){return lD(e)?.faceOrigins}function PO(e,t,n){let r=new Map;for(let e of t){let t=NO(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,n)}if(i.size>0){let e=cD(n);e.faceOrigins=i}}var FO=100,IO=.985,LO=.1;function RO(e,t,n,r){let i=-1/0,a;for(let n of r){let r=e[0]*n.normal[0]+e[1]*n.normal[1]+e[2]*n.normal[2];if(r<.707)continue;let o=t[0]-n.centroid[0],s=t[1]-n.centroid[1],c=t[2]-n.centroid[2],l=o*o+s*s+c*c;if(l>FO)continue;let u=r-l/FO;u>i&&(i=u,a=n.origin)}if(a!==void 0)return a;if(!n)return;let o=1/0,s;for(let n of r){if(!n.planar)continue;let r=e[0]*n.normal[0]+e[1]*n.normal[1]+e[2]*n.normal[2];if(Math.abs(r)<IO)continue;let i=t[0]-n.centroid[0],a=t[1]-n.centroid[1],c=t[2]-n.centroid[2],l=i*n.normal[0]+a*n.normal[1]+c*n.normal[2];if(l*l>LO)continue;let u=Math.max(0,i*i+a*a+c*c-l*l);u<o&&(o=u,s=n.origin)}return s}function zO(e,t){let n=new Map;for(let t of e){let e=NO(t);if(e)for(let[t,r]of e)n.set(t,r)}if(n.size===0)return;let r=H(),i=new Map,a=fD(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=NO(n);if(e)for(let i of fD(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),s=r.surfaceType(i.wrapped)===`plane`;t.push({origin:a,normal:n,centroid:o,planar:s})}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=RO(r.surfaceNormal(e.wrapped,.5*(a.uMin+a.uMax),.5*(a.vMin+a.vMax)),r.surfaceCenterOfMass(e.wrapped),r.surfaceType(e.wrapped)===`plane`,t);o!==void 0&&i.set(n,o)}catch{}}}if(i.size>0){let e=cD(t);e.faceOrigins=i}}var BO=new WeakMap,VO=new WeakMap;function HO(e){return BO.has(e.wrapped)}function UO(e){let t=BO.get(e.wrapped);return t||(t=new Map,BO.set(e.wrapped,t)),t}function WO(e){let t=VO.get(e.wrapped);return t||(t=new Map,VO.set(e.wrapped,t)),t}function GO(e,t,n){let r=Array.isArray(t)?t:fD(e).filter(t),i=UO(e),a=i.get(n)??new Set;for(let e of r)a.add(H().hashCode(e.wrapped,G));return i.set(n,a),e}function KO(e,t){let n=BO.get(e.wrapped);if(!n)return[];let r=n.get(t);if(!r||r.size===0)return[];let i=[];for(let t of fD(e)){let e=H().hashCode(t.wrapped,G);r.has(e)&&i.push(t)}return i}function qO(e){let t=new Map,n=BO.get(e.wrapped);if(!n)return t;let r=fD(e),i=new Map;for(let e of r)i.set(H().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 JO(e,t,n){return WO(e).set(t,n),e}function YO(e,t){return VO.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 ZO(e,t,n){let r=UO(n);for(let i of t){let t=BO.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=VO.get(i.wrapped);if(o){let e=WO(n);for(let[t,n]of o)e.has(t)||e.set(t,n)}}}var QO=new WeakMap,$O=new WeakMap;function ek(e){return QO.has(e.wrapped)||$O.has(e.wrapped)}function tk(e){let t=$O.get(e.wrapped);return t||(t=new Map,$O.set(e.wrapped,t)),t}function nk(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 rk(e,t){return QO.set(e.wrapped,nk(t)),e}function ik(e,t,n){let r=nk(n),i=tk(e);for(let e of t)i.set(H().hashCode(e.wrapped,G),r);return e}function ak(e){return QO.get(e.wrapped)}function ok(e,t){let n=$O.get(e.wrapped);if(n)return n.get(H().hashCode(t.wrapped,G))}function sk(e,t,n){for(let e of t){let t=QO.get(e.wrapped);if(t){QO.set(n.wrapped,t);break}}let r=tk(n);for(let n of t){let t=$O.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 ck(e){return NO(e)!==void 0||HO(e)||ek(e)}function lk(e){if(!e.some(ck))return[];let t=[];for(let n of e)t.push(...iD(n,`face`));return t}function uk(e,t,n){PO(e,t,n),ZO(e,t,n),sk(e,t,n)}function dk(e,t){zO(e,t)}function fk(e,t){let n=H(),r=[...n.iterShapes(e.wrapped,`face`)],i=[...n.iterShapes(t.wrapped,`face`)];if(r.length!==i.length)return;let a=new Map;for(let e=0;e<r.length;e++){let t=r[e],o=i[e];t===void 0||o===void 0||a.set(n.hashCode(t,G),[n.hashCode(o,G)])}for(let e of r)n.dispose(e);for(let e of i)n.dispose(e);uk({modified:a,generated:new Map,deleted:new Set},[e],t)}function pk(e,t){let n=lk([e]),{shape:r,evolution:i}=H().translateWithHistory(e.wrapped,t[0],t[1],t[2],n,G),a=U(r);return uk(i,[e],a),a}function mk(e,t,n=[0,0,0],r=[0,0,1]){let i=lk([e]),{shape:a,evolution:o}=H().rotateWithHistory(e.wrapped,t*YE,i,G,r,n),s=U(a);return uk(o,[e],s),s}function hk(e,t=[0,1,0],n=[0,0,0]){let r=lk([e]),{shape:i,evolution:a}=H().mirrorWithHistory(e.wrapped,n,t,r,G),o=U(i);return uk(a,[e],o),o}function gk(e,t,n=[0,0,0]){let r=lk([e]),{shape:i,evolution:a}=H().scaleWithHistory(e.wrapped,n,t,r,G),o=U(i);return uk(a,[e],o),o}function _k(e,t,n){let r=H().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(gk(e,c[0])):k(P(M.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 vk(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(P(M.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 yk(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 bk(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 xk(e,t){let n=vk(t);if(!n.ok)return n;let{linear:r,translation:i}=n.value,a=yk(r);if(Math.abs(a)<1e-12)return k(P(M.VALIDATION_FAILED,`applyMatrix: singular matrix (determinant ≈ 0). Cannot apply a non-invertible transform.`));if(bk(r)){let t=lk([e]),{shape:n,evolution:a}=H().generalTransformWithHistory(e.wrapped,r,i,!0,t,G),o=U(n);return uk(a,[e],o),O(o)}let o=U(H().generalTransformNonOrthogonal(e.wrapped,r,i));return dk([e],o),O(o)}function Sk(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}=H().composeTransform(t);return{trsf:n,cleanup:r}}function Ck(e,t){let{trsf:n,cleanup:r}=Sk(`type`in t?[t]:t),i;try{i=U(H().locate(e.wrapped,n))}finally{r()}return ck(e)&&fk(e,i),i}function wk(e,t){let n=lk([e]),{shape:r,evolution:i}=H().applyComposedTransformWithHistory(e.wrapped,t.trsf,n,G),a=U(r);return uk(i,[e],a),a}function Tk(e){return $E(()=>H().copyShape(e.wrapped),M.CLONE_FAILED,`Failed to clone shape`)}function Ek(e){return eD(()=>H().toBREP(e.wrapped),M.TO_BREP_FAILED,`Failed to serialize shape to BREP`)}function Dk(e){return H().hashCode(e.wrapped,G)}function Ok(e){return H().isNull(e.wrapped)}function kk(e,t){return H().isSame(e.wrapped,t.wrapped)}function Ak(e,t){return H().isEqual(e.wrapped,t.wrapped)}function jk(e){return $E(()=>H().simplify(e.wrapped),M.SIMPLIFY_FAILED,`Failed to simplify shape`)}function Mk(e){return H().curveType(e.wrapped)}function Nk(e){let[t]=H().curveParameters(e.wrapped);return H().curvePointAtParam(e.wrapped,t)}function Pk(e){let[,t]=H().curveParameters(e.wrapped);return H().curvePointAtParam(e.wrapped,t)}function Fk(e,t=.5){let[n,r]=H().curveParameters(e.wrapped),i=n+(r-n)*t;return H().curvePointAtParam(e.wrapped,i)}function Ik(e,t=.5){let[n,r]=H().curveParameters(e.wrapped),i=n+(r-n)*t;return H().curveTangent(e.wrapped,i).tangent}function Lk(e){return H().length(e.wrapped)}function Rk(e){if(Mk(e)!==`CIRCLE`)return null;let t=Fk(e,0),n=Fk(e,1/3),r=Fk(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 zk(e){return H().curveIsClosed(e.wrapped)}function Bk(e){return H().curveIsPeriodic(e.wrapped)}function Vk(e){return H().curvePeriod(e.wrapped)}function Hk(e){return H().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function Uk(e){return U(H().reverseShape(e.wrapped))}function Wk(e,t={}){if(e.length<2)return k(wo(`INTERPOLATE_MIN_POINTS`,`Interpolation requires at least 2 points`));try{let n=U(H().interpolatePoints(e,t));return PE(n)?O(n):(W(n),k(wo(`INTERPOLATE_NOT_EDGE`,`Interpolation did not produce an edge`)))}catch(e){return k(wo(`INTERPOLATE_FAILED`,`Interpolation failed: ${e instanceof Error?e.message:String(e)}`))}}function Gk(e,t={}){if(e.length<2)return k(wo(`APPROXIMATE_MIN_POINTS`,`Approximation requires at least 2 points`));try{let n=U(H().approximatePoints(e,t));return PE(n)?O(n):(W(n),k(wo(`APPROXIMATE_NOT_EDGE`,`Approximation did not produce an edge`)))}catch(e){return k(wo(`APPROXIMATE_FAILED`,`Approximation failed: ${e instanceof Error?e.message:String(e)}`))}}function Kk(e,t,n=`arc`){let r=U(H().offsetWire2D(e.wrapped,t,{arc:`arc`,intersection:`intersection`,tangent:`tangent`,chamfer:`intersection`}[n]));return FE(r)?O(r):(W(r),k(wo(`OFFSET_NOT_WIRE`,`Offset did not produce a Wire`)))}function qk(e,t,n,r=!1){return`${e}:${t}:${n}:${r}`}function Jk(e,t){return`edge:${e}:${t}`}var Yk=new WeakMap,Xk=new WeakMap;function Zk(e,t){let n=Yk.get(e);if(n)return n.get(t)}function Qk(e,t,n){let r=Yk.get(e);r||(r=new Map,Yk.set(e,r)),r.set(t,n)}function $k(e,t){let n=Xk.get(e);if(n)return n.get(t)}function eA(e,t,n){let r=Xk.get(e);r||(r=new Map,Xk.set(e,r)),r.set(t,n)}function tA(){Yk=new WeakMap,Xk=new WeakMap}function nA(){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 rA(e,t={}){let n=Fo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,skipNormals:a=!1,includeUVs:o=!1,cache:s=!0,signal:c}=t;c?.throwIfAborted();let l=qk(r,i,a,o);if(s){let t=Zk(e.wrapped,l);if(t)return t}let u=H().mesh(e.wrapped,{tolerance:r,angularTolerance:i,skipNormals:a,includeUVs:o,...c?{signal:c}:{}}),d=NO(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&&Qk(e.wrapped,l,f),f}function iA(e,t={}){let n=Fo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,cache:a=!0}=t,o=Jk(r,i);if(a){let t=$k(e.wrapped,o);if(t)return t}let s=H().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&&eA(e.wrapped,o,c),c}function aA(e,t){return e instanceof Error&&e.message.startsWith(`${t} export failed`)?Oo(`${t}_EXPORT_FAILED`,`Failed to write ${t} file`,e):e instanceof WebAssembly.RuntimeError?Oo(`${t}_EXPORT_CRASHED`,`${t} export crashed the kernel (${e.message}); the shape likely contains geometry the ${t} writer cannot serialize`,e):Oo(`${t}_FILE_READ_ERROR`,`Failed to read exported ${t} file`,e)}function oA(e){let t;try{t=hD(e)}catch{return``}if(t.length<=1)return``;let n=[];return t.forEach((e,t)=>{try{TD(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 sA(e,t){try{return TD(e),null}catch(n){if(n instanceof TypeError)throw n;return Oo(`${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${oA(e)}`,n)}}function cA(e){let t=sA(e,`STEP`);if(t)return k(t);try{let t=H().exportSTEP([e.wrapped]);return O(new Blob([t],{type:`application/STEP`}))}catch(e){return k(aA(e,`STEP`))}}function lA(e,t={}){let n=Fo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,binary:a=!1}=t,o=sA(e,`STL`);if(o)return k(o);try{H().hasTriangulation(e.wrapped)||H().meshShape(e.wrapped,r,i);let t=H().exportSTL(e.wrapped,a,r,i);return O(new Blob([t],{type:`application/sla`}))}catch(e){return k(aA(e,`STL`))}}function uA(e){try{let t=H().exportIGES([e.wrapped]);return O(new Blob([t],{type:`application/iges`}))}catch(e){return k(Oo(`IGES_EXPORT_FAILED`,`Failed to write IGES file`,e))}}function dA(e,t){let n=t?.coarseTolerance??.5,r=t?.fineTolerance??.05,i=t?.angularTolerance??.5;return{coarse:rA(e,{tolerance:n,angularTolerance:i}),fine:rA(e,{tolerance:r,angularTolerance:i*.2})}}function fA(e){let t=TD(e),n=t.xMax-t.xMin,r=t.yMax-t.yMin,i=t.zMax-t.zMin;return Math.sqrt(n*n+r*r+i*i)||1}function pA(e,t){let n;if(t.tolerances&&t.tolerances.length>0)n=[...t.tolerances];else{let r=Math.max(1,Math.floor(t.levels??3)),i=t.spacing??4,a=(t.relativeTolerance??5e-4)*fA(e)||2**-52;n=[];for(let e=r-1;e>=0;e--)n.push(a*i**e)}return n.sort((e,t)=>t-e),n}function mA(e,t,n){return Math.min(e/t*n,1)}function hA(e,t={}){let n=t.angularTolerance??Fo().angularTolerance,r=t.cache??!0,i=pA(e,t),a=Math.min(...i);return i.map(i=>{let o=mA(i,a,n);return{tolerance:i,angularTolerance:o,mesh:rA(e,{tolerance:i,angularTolerance:o,cache:r,...t.signal?{signal:t.signal}:{}})}})}function gA(){return new Promise(e=>{setTimeout(e,0)})}async function _A(e,t={}){let n=t.angularTolerance??Fo().angularTolerance,r=t.cache??!0,i=t.meshLevel??((e,n,i)=>rA(e,{tolerance:n,angularTolerance:i,cache:r,...t.signal?{signal:t.signal}:{}})),a=pA(e,t),o=Math.min(...a),s=[];for(let[r,c]of a.entries()){if(t.signal?.aborted)break;let l=mA(c,o,n),u;try{u=await i(e,c,l)}catch(e){if(t.signal?.aborted)break;throw e}let d={tolerance:c,angularTolerance:l,mesh:u};if(s.push(d),t.onLevel?.(d,r),t.signal?.aborted||r===a.length-1)break;await gA()}return s}function vA(e,t,n){if(t<0||t>=e.length)throw Error(n??`Index ${t} out of bounds (length ${e.length})`);return e[t]}function yA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[0]}function bA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[e.length-1]}function xA(e){return Array.from(Array(e).keys())}function SA(e){return xA(Math.min(...e.map(e=>e.length))).map(t=>e.map(e=>e[t]))}function CA(e,t){return EE(H().makeLineEdge([...e],[...t]))}function wA(e,t=[0,0,0],n=[0,0,1]){return EE(H().makeCircleEdge([...t],[...n],e))}function TA(e,t,n=[0,0,0],r=[0,0,1],i){return t>e?k(P(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(EE(H().makeEllipseEdge([...n],[...r],e,t,i?[...i]:void 0)))}function EA(e,t,n,r=[0,0,0],i=[0,0,1],a=!1){return DE(H().makeHelixWire(e,t,n,[...r],[...i],a))}function DA(e,t,n){return EE(H().makeArcEdge([...e],[...t],[...n]))}function OA(e,t,n,r,i=[0,0,0],a=[0,0,1],o){return t>e?k(P(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(EE(H().makeEllipseArc([...i],[...a],e,t,n,r,o?[...o]:void 0)))}function kA(e,{tolerance:t=.001,smoothing:n=null,degMax:r=6,degMin:i=1}={}){try{let a=e.map(e=>[...e]);return O(EE(H().approximatePoints(a,{tolerance:t,degMin:i,degMax:r,smoothing:n})))}catch(e){return k(N(`BSPLINE_FAILED`,`B-spline approximation failed`,e))}}function AA(e,{periodic:t=!1,tolerance:n=1e-7}={}){try{let r=e.map(e=>[...e]);return O(EE(H().interpolatePoints(r,{periodic:t,tolerance:n})))}catch(e){return k(N(`BSPLINE_INTERP_FAILED`,`B-spline interpolation failed`,e))}}function jA(e){if(e.length<2)return k(P(`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(EE(H().makeBezierEdge(t)))}function MA(e,t,n){return EE(H().makeTangentArc([...e],[...t],[...n]))}function NA(e){try{return O(DE(H().makeWireFromMixed(e.map(e=>e.wrapped))))}catch(e){return k(N(`WIRE_BUILD_FAILED`,`Failed to build the wire: ${e instanceof Error?e.message:`unknown error`}`))}}function PA(e,t){try{let n=H().makeFace(e.wrapped,!0);if(t&&t.length>0){let e=RA(OE(n),t);return bE(e)?O(e):k(P(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}let r=OE(n);return bE(r)?O(r):k(P(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}catch(e){return k(N(`FACE_BUILD_FAILED`,`Failed to build the face. Your wire might be non planar.`,e))}}function FA(e){return PA(kO(e))}function IA(e,t){return OE(H().makeFaceOnSurface(e.wrapped,t.wrapped))}function LA(e){try{return Qa(pO(H().makeNonPlanarFace(e.wrapped)),e=>IE(e)?O(e):k(N(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`)))}catch(e){return k(N(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`,e))}}function RA(e,t){return OE(H().addHolesInFace(e.wrapped,t.map(e=>e.wrapped)))}function zA(e){try{var t=LT();if(e.length<3)return k(P(`POLYGON_MIN_POINTS`,`You need at least 3 points to make a polygon`));let n=[...e.slice(1),e[0]],r=t.u(new ZT);return Qa(NA(SA([e,n]).map(([e,t])=>r.register(CA(e,t)))),e=>PA(r.register(e)))}catch(e){t.e=e}finally{t.d()}}function BA(e,t){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function VA(e,t,n,r,i){let a=HE(e);if(!BE(a)){let o=dE(a).toUpperCase();return WE(e,a),W(a),k(wo(t,`${n}. Got ${o} instead.`,void 0,i?{diagnostics:i}:void 0,r))}return WE(e,a),O(a)}function HA(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=BA(e,`fuse: first operand`);if(A(c))return c;let l=BA(t,`fuse: second operand`);if(A(l))return l;if(!s)return VA(H().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);let u=lk([e,t]),{shape:d,evolution:f,diagnostics:p}=H().fuseWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(H().isNull(d))return H().dispose(d),console.warn(`brepjs: fuse history path produced null result; retrying without evolution tracking.`,p),VA(H().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=VA(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&&uk(f,[e,t],m.value),m}function UA(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=BA(e,`cut: base`);if(A(c))return c;let l=BA(t,`cut: tool`);if(A(l))return l;if(!s)return VA(H().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);let u=lk([e,t]),{shape:d,evolution:f,diagnostics:p}=H().cutWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(H().isNull(d))return H().dispose(d),console.warn(`brepjs: cut history path produced null result; retrying without evolution tracking.`,p),VA(H().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=VA(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&&uk(f,[e,t],m.value),m}function WA(e,t,{simplify:n=!1,signal:r,fuzzyValue:i,unsafe:a,trackEvolution:o=!0}={}){if(r?.aborted)throw r.reason;let s=BA(e,`intersect: first operand`);if(A(s))return s;let c=BA(t,`intersect: second operand`);if(A(c))return c;if(!o)return VA(H().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);let l=lk([e,t]),{shape:u,evolution:d,diagnostics:f}=H().intersectWithHistory(e.wrapped,t.wrapped,l,G,{simplify:n,fuzzyValue:i});if(f.hasErrors){if(H().isNull(u))return H().dispose(u),console.warn(`brepjs: intersect history path produced null result; retrying without evolution tracking.`,f),VA(H().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=VA(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&&uk(d,[e,t],p.value),p}function GA(e,t,n,r,i,a,o,s,c){if(s?.aborted)throw s.reason;let l=n-t;if(l===1)return O({shape:vA(e,t),owned:!1});if(l===2){let n=HA(vA(e,t),vA(e,t+1),{optimisation:r,simplify:a?i:!1,trackEvolution:o,fuzzyValue:c,unsafe:!0,...s?{signal:s}:{}});return A(n)?n:O({shape:n.value,owned:!0})}let u=t+Math.ceil(l/2),d=GA(e,t,u,r,i,!1,o,s,c);if(A(d))return d;let f=GA(e,u,n,r,i,!1,o,s,c);if(A(f))return d.value.owned&&W(d.value.shape),f;let p=HA(d.value.shape,f.value.shape,{optimisation:r,simplify:i,trackEvolution:o,fuzzyValue:c,unsafe:!0,...s?{signal:s}:{}});return d.value.owned&&W(d.value.shape),f.value.owned&&W(f.value.shape),A(p)?p:O({shape:p.value,owned:!0})}function KA(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(P(`FUSE_ALL_EMPTY`,`fuseAll requires at least one shape`));if(e.length===1)return O(yA(e));for(let t=0;t<e.length;t++){let n=BA(vA(e,t),`fuseAll: shape at index ${t}`);if(A(n))return n}if(r===`native`){let o=VA(H().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&&dk(e,o.value),o}let c=GA(e,0,e.length,t,n,!0,s,i,a);return A(c)?c:O(c.value.shape)}function qA(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=BA(e,`cutAll: base`);if(A(c))return c;for(let e=0;e<t.length;e++){let n=BA(vA(t,e),`cutAll: tool at index ${e}`);if(A(n))return n}let l=[e,...t],u=VA(H().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&&dk(l,u.value),u}function JA(e,t,n){if(n!==void 0)return{size:n,center:t.origin};let{min:r,max:i}=H().boundingBox(e.wrapped),a=[(r[0]+i[0])/2,(r[1]+i[1])/2,(r[2]+i[2])/2],o=zD(ID(a,t.origin),t.zDir),s=ID(a,LD(t.zDir,o)),c=Math.hypot(i[0]-r[0],i[1]-r[1],i[2]-r[2]);return{size:Math.max(c,1),center:s}}function YA(e,t,n){let r=H(),i=LD(e.xDir,t),a=LD(e.yDir,t),o=LD(e.xDir,-t),s=LD(e.yDir,-t),c=n,l=[...FD(FD(c,o),s)],u=[...FD(FD(c,i),s)],d=[...FD(FD(c,i),a)],f=[...FD(FD(c,o),a)],p=[r.makeLineEdge(l,u),r.makeLineEdge(u,d),r.makeLineEdge(d,f),r.makeLineEdge(f,l)],m=r.makeWire(p),h=r.makeFace(m,!0);for(let e of p)r.dispose(e);return r.dispose(m),h}function XA(e,t,{approximation:n=!0,planeSize:r}={}){if(H().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`section: shape is a null shape`));let i=typeof t==`string`?j(tO(t)):t,{size:a,center:o}=JA(e,i,r),s=YA(i,a,o);try{return O(U(H().section(e.wrapped,s,n)))}catch(e){let n=e instanceof Error?e.message:String(e),r=typeof t==`string`?t:`custom`;return k(N(`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{H().dispose(s)}}function ZA(e){let t=H(),n=new Map,r=new Map;for(let i of e){let e=mD(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 QA(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 $A(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=QA(i,t,n);for(;o;)e===0?r.push(o.edge):r.unshift(o.edge),i=o.nextTip,o=QA(i,t,n)}return r}function ej(e){let t=H(),n=ZA(e),r=new Set,i=[];for(let a of e){if(r.has(a))continue;let e=$A(a,n,r);try{let n=t.makeWire(e.map(e=>e.wrapped));i.push(U(n))}catch{}}return i}function tj(e){let t=H(),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 nj(e,t,n={}){let r=XA(e,t,n);if(!r.ok)return r;let i=pD(r.value);if(i.length===0){let e=dD(r.value);if(e.length===0)return k(N(`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(...ej(e))}if(i.length===0)return k(N(`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=tj(i),o=vA(i,a),s=i.filter((e,t)=>t!==a);return PA(o,s.length>0?s:void 0)}function rj(e,t){if(t.length===0)return O(e);if(H().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`split: shape is a null shape`));for(let e=0;e<t.length;e++)if(H().isNull(vA(t,e).wrapped))return k(P(M.NULL_SHAPE_INPUT,`splitShape: tool at index ${e} is a null shape`));try{return O(U(H().split(e.wrapped,t.map(e=>e.wrapped))))}catch(e){let n=e instanceof Error?e.message:String(e);return k(N(`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 ij(e,t,n={}){let r=[];for(let i of t){let t=XA(e,i,n);if(A(t))return t;r.push(t.value)}return O(r)}function aj(e,t,n){if(t.length===0)return O(e);let r=n?.optimisation===`commonFace`?1:n?.optimisation===`sameFace`?2:0,i=H(),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 oj(e,t,n);if(o===null)return k(N(`BOOLEAN_PIPELINE_FAILED`,`Boolean pipeline returned null shape`));let s=U(o);return BE(s)?O(s):(W(s),k(wo(`BOOLEAN_PIPELINE_NOT_3D`,`Pipeline result is not a 3D shape`)))}catch(e){return k(N(`BOOLEAN_PIPELINE_FAILED`,e instanceof Error?e.message:String(e)))}}function oj(e,t,n){let r=e,i={...n?.optimisation?{optimisation:n.optimisation}:{},unsafe:!0};for(let e of t){let t=e.op===`fuse`?HA(r,e.tool,i):e.op===`cut`?UA(r,e.tool,i):WA(r,e.tool,i);if(A(t))return t;r=j(t)}return O(r)}function sj(e){return U(H().sew(e.map(e=>e.wrapped)))}function cj(e,t=!1){let n=sj(e);return!t&&!LE(n)?k(wo(`WELD_NOT_SHELL`,`Could not make a shell from faces and shells`)):O(n)}function lj(e,t,n=[0,0,0],r=[0,0,1]){return AE(H().makeCylinder(e,t,[...n],[...r]))}function uj(e){return AE(H().makeSphere(e))}function dj(e,t,n,r=[0,0,0],i=[0,0,1]){return AE(H().makeCone(e,t,n,[...r],[...i]))}function fj(e,t,n=[0,0,0],r=[0,0,1]){return AE(H().makeTorus(e,t,[...n],[...r]))}function pj(e,t,n){return AE(H().makeEllipsoid(e,t,n))}function mj(e){return TE(H().makeVertex(e[0],e[1],e[2]))}function hj(e,t,n=1e-6){return Qa(dO(H().offset(e.wrapped,t,n)),e=>Qa(pO(e),e=>BE(e)?O(e):k(wo(`OFFSET_NOT_3D`,`Could not offset to a 3d shape`))))}function gj(e){return ME(H().makeCompound(e.map(e=>e.wrapped)))}function _j(e){try{var t=LT();let n=t.u(sj(e)),r=U(H().solidFromShell(n.wrapped));return RE(r)?O(r):(W(r),k(wo(`SOLID_BUILD_FAILED`,`Could not make a solid of faces and shells`)))}catch(e){t.e=e}finally{t.d()}}function vj(e){return{position:e.vertices,normal:e.normals,index:e.triangles}}function yj(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 bj(e){return{position:e.lines}}function xj(e,t){return{coarse:vj(e.coarse),fine:vj(e.fine),coarseDistance:t?.coarse??50,fineDistance:t?.fine??0}}function Sj(e,t){let n=t?.step??50,r=t?.distances;if(r&&r.length!==e.length)throw Error(`toLODGeometryLevels: distances must have one entry per level (got ${r.length} for ${e.length} levels)`);let i=e.length-1;return e.map((e,t)=>({geometry:vj(e.mesh),distance:r?.[t]??(i-t)*n}))}function Cj(e,t,n,r){if(t.length===0)return k(P(`CHAMFER_ANGLE_NO_EDGES`,`chamferDistAngle requires at least one edge`,void 0,{edgeCount:0}));if(n<=0)return k(P(`CHAMFER_ANGLE_BAD_DISTANCE`,`distance must be positive, got ${n}`,void 0,{distance:n}));if(r<=0||r>=90)return k(P(`CHAMFER_ANGLE_BAD_ANGLE`,`angleDeg must be in range (0, 90), got ${r}`,void 0,{angleDeg:r}));let i;try{let a=H(),o=t.map(e=>e.wrapped);i=a.chamferDistAngle(e.wrapped,o,n,r)}catch(e){return k(N(`CHAMFER_ANGLE_FAILED`,`chamferDistAngle kernel call failed: ${e instanceof Error?e.message:String(e)}`,e,{distance:n,angleDeg:r,edgeCount:t.length}))}let a=dO(i);if(A(a))return H().dispose(i),a;let o=U(a.value);return WE(i,o),BE(o)?O(o):(W(o),k(wo(`CHAMFER_ANGLE_NOT_3D`,`chamferDistAngle did not produce a 3D shape`)))}function wj(e){let t=H();return t.getNurbsCurveData?t.getNurbsCurveData(e.wrapped):null}function Tj(e){let t=H();return t.getNurbsSurfaceData?t.getNurbsSurfaceData(e.wrapped):null}var Ej={cut:UA,cutAll:qA,fuse:HA,fuseAll:KA};function Dj(e){return{totalInputs:e.totalInputs,batchAttempts:e.batchAttempts,batchSucceeded:e.batchSucceeded,singletonFallbacks:e.singletonFallbacks,failedInputs:[...e.failedInputs].sort((e,t)=>e-t)}}function Oj(e,t,n={}){return kj(Ej,e,t,n)}function kj(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=Aj(e,t,n,0,r,i);return A(a)?a:O({shape:a.value,telemetry:Dj(i)})}function Aj(e,t,n,r,i,a){if(n.length===0)return O(t);if(n.length===1)return jj(e,t,n,r,i,a);a.batchAttempts++;let o=Ij(()=>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=Aj(e,t,n.slice(0,s),r,i,a);return c.ok?Aj(e,c.value,n.slice(s),r+s,i,a):c}function jj(e,t,n,r,i,a){a.singletonFallbacks++;let o=yA(n),s=Ij(()=>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 Mj(e,t={}){return Nj(Ej,e,t)}function Nj(e,t,n={}){if(n.signal?.aborted)throw n.signal.reason;if(t.length===0)return k(P(M.FUSE_ALL_EMPTY,`fuseAllBisect requires at least one shape`));let r={totalInputs:t.length,batchAttempts:0,batchSucceeded:0,singletonFallbacks:0,failedInputs:new Set},i=Pj(e,t,0,n,r);return A(i)?i:O({shape:i.value,telemetry:Dj(r)})}function Pj(e,t,n,r,i){if(t.length===1)return O(yA(t));i.batchAttempts++;let a=Ij(()=>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 Fj(e,Pj(e,t.slice(0,o),n,r,i),Pj(e,t.slice(o),n+o,r,i),t,n,o,r,i)}function Fj(e,t,n,r,i,a,o,s){if(t.ok&&n.ok){s.singletonFallbacks++;let c=Ij(()=>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 Ij(e){try{return e()}catch{return null}}function Lj(e,t,n){return H().checkBoolean(e.wrapped,t.wrapped,n)}function Rj(e,t){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function zj(e,t){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Bj(e,t,n,r){let i=HE(e);if(!BE(i)){let a=dE(i).toUpperCase();return WE(e,i),W(i),k(wo(t,`${n}. Got ${a} instead.`,void 0,void 0,r))}return WE(e,i),O(i)}function Vj(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(H().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>r.get(H().hashCode(e,2147483647))??1}}function Hj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Rj(e,`fuseWithEvolution: first operand`);if(A(o))return o;let s=Rj(t,`fuseWithEvolution: second operand`);if(A(s))return s;let c=lk([e,t]),{shape:l,evolution:u}=H().fuseWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Bj(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?(uk(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function Uj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Rj(e,`cutWithEvolution: base`);if(A(o))return o;let s=Rj(t,`cutWithEvolution: tool`);if(A(s))return s;let c=lk([e,t]),{shape:l,evolution:u}=H().cutWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Bj(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?(uk(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function Wj(e,t,{simplify:n=!1,signal:r,fuzzyValue:i}={}){if(r?.aborted)throw r.reason;let a=Rj(e,`intersectWithEvolution: first operand`);if(A(a))return a;let o=Rj(t,`intersectWithEvolution: second operand`);if(A(o))return o;let s=lk([e,t]),{shape:c,evolution:l}=H().intersectWithHistory(e.wrapped,t.wrapped,s,G,{simplify:n,fuzzyValue:i}),u=Bj(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?(uk(l,[e,t],u.value),O({shape:u.value,evolution:l})):u}function Gj(e,t,n){let r=zj(e,`filletWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(P(`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(P(`INVALID_FILLET_RADIUS`,`Fillet radii must both be positive`,void 0,void 0,`Both radius values must be greater than 0`));let i=t??dD(e);if(i.length===0)return k(P(M.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=Vj(i,n);if(!e)return k(P(M.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=lk([e]),{shape:o,evolution:s}=H().filletWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=U(o);return BE(c)?(uk(s,[e],c),O({shape:c,evolution:s})):(W(c),k(N(M.FILLET_NOT_3D,`Fillet result is not a 3D shape`)))}catch(e){return k(N(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:i.length,radius:n}))}}function Kj(e,t,n){let r=zj(e,`chamferWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(P(`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(P(`INVALID_CHAMFER_DISTANCE`,`Chamfer distances must both be positive`,void 0,void 0,`Both distance values must be greater than 0`));let i=t??dD(e);if(i.length===0)return k(P(M.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=Vj(i,n);if(!e)return k(P(M.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=lk([e]),{shape:o,evolution:s}=H().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=U(o);return BE(c)?(uk(s,[e],c),O({shape:c,evolution:s})):(W(c),k(N(M.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)))}catch(e){return k(N(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:i.length,distance:n}))}}function qj(e,t,n,r=.001){let i=zj(e,`shellWithEvolution: shape`);if(A(i))return i;if(n<=0)return k(P(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(P(`NO_FACES`,`At least one face must be specified for shell`));try{let i=lk([e]),{shape:a,evolution:o}=H().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,i,G,r),s=U(a);return BE(s)?(uk(o,[e],s),O({shape:s,evolution:o})):(W(s),k(N(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}catch(e){return k(N(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function Jj(e,t,n){try{let r=U(H().positionOnCurve(e.wrapped,t.wrapped,n));return BE(r)?O(r):(W(r),k(N(M.POSITION_ON_CURVE_FAILED,`positionOnCurve did not produce a 3D shape`)))}catch(e){return k(N(M.POSITION_ON_CURVE_FAILED,`Failed to position shape on curve at param ${n}`,e))}}function Yj(e,t){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Xj(e,t){if(typeof e==`number`&&e<=0)return k(P(t.code,t.scalar,void 0,void 0,t.scalarHint));if(Array.isArray(e)&&(e[0]<=0||e[1]<=0))return k(P(t.code,t.pair,void 0,void 0,t.pairHint))}function Zj(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(H().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>{let t=r.get(H().hashCode(e,G));if(t===void 0)throw Error(`fillet/chamfer: edge hash not found — possible hash collision`);return t}}}function Qj(e,t,n,r,i){let a=U(t);return BE(a)?(uk(e,n,a),O(a)):(W(a),k(N(r,i)))}function $j(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(H().hashCode(i.wrapped,G),e))}return{filteredFaces:n,kernelAngle:e=>{let t=r.get(H().hashCode(e,G));if(t===void 0)throw Error(`draft: face hash not found — possible hash collision`);return t}}}function eM(e,t){let n=Yj(e,`thicken: shape`);if(A(n))return n;try{let n=lk([e]),{shape:r,evolution:i}=H().thickenWithHistory(e.wrapped,t,n,G),a=U(r);return uk(i,[e],a),O(a)}catch(e){return k(N(`THICKEN_FAILED`,`Thicken operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function tM(e,t,n){let r=Yj(e,`fillet: shape`);if(A(r))return r;let i=Xj(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??dD(e);if(a.length===0)return k(P(M.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=Zj(a,n);return e?O({filteredEdges:e.edges,kernelRadius:e.kernelParam,selectedCount:a.length}):k(P(M.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 nM(e,t,n,{trackEvolution:r=!0}={}){let i=tM(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=U(H().fillet(e.wrapped,t,o));return BE(n)?O(n):(W(n),k(N(M.FILLET_NOT_3D,`Fillet result is not a 3D shape`)))}let n=lk([e]),{shape:i,evolution:s}=H().filletWithHistory(e.wrapped,t,o,n,G);return Qj(s,i,[e],M.FILLET_NOT_3D,`Fillet result is not a 3D shape`)}catch(e){return k(N(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:s,radius:n}))}}function rM(e,t,n){let r=Yj(e,`chamfer: shape`);if(A(r))return r;let i=Xj(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??dD(e);if(a.length===0)return k(P(M.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=Zj(a,n);if(!e)return k(P(M.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...a],r=n;let i=lk([e]),{shape:o,evolution:s}=H().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,i,G);return Qj(s,o,[e],M.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)}catch(e){return k(N(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:a.length,distance:n}))}}function iM(e,t,n,r=.001,{trackEvolution:i=!0}={}){let a=Yj(e,`shell: shape`);if(A(a))return a;if(n<=0)return k(P(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(P(`NO_FACES`,`At least one face must be specified for shell`));try{if(!i){let i=U(H().shell(e.wrapped,t.map(e=>e.wrapped),n,r));return BE(i)?O(i):(W(i),k(N(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}let a=lk([e]),{shape:o,evolution:s}=H().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,a,G,r),c=U(o);return BE(c)?(uk(s,[e],c),O(c)):(W(c),k(N(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}catch(e){return k(N(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function aM(e,t,n=1e-6){let r=Yj(e,`offset: shape`);if(A(r))return r;if(Math.abs(t)<1e-10)return k(P(`ZERO_OFFSET`,`Offset distance cannot be zero`));try{let r=lk([e]),{shape:i,evolution:a}=H().offsetWithHistory(e.wrapped,t,r,G,n),o=U(i);return BE(o)?(uk(a,[e],o),O(o)):(W(o),k(N(`OFFSET_RESULT_NOT_3D`,`Offset result is not a 3D shape`)))}catch(e){return k(N(`OFFSET_FAILED`,`Offset operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function oM(e,t,n){let r=Yj(e,`draft: shape`);if(A(r))return r;if(typeof n==`number`){if(Math.abs(n)<1e-10)return k(P(M.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(P(M.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(P(M.DRAFT_NO_FACES,`No faces specified for draft`,void 0,void 0,`Select at least one face to apply the draft angle to`))}function sM(e,t,n,r,i){let a=oM(e,t,i);if(a)return a;try{let{filteredFaces:a,kernelAngle:o}=$j(t,i);if(a.length===0)return k(P(M.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=lk([e]),{shape:c,evolution:l}=H().draftWithHistory(e.wrapped,a.map(e=>e.wrapped),[n[0],n[1],n[2]],[r[0],r[1],r[2]],o,s,G);return Qj(l,c,[e],M.DRAFT_NOT_3D,`Draft result is not a 3D shape`)}catch(e){let n=e instanceof Error?e.message:String(e);return k(N(M.DRAFT_FAILED,`Draft operation failed: ${n}`,e,{operation:`draft`,faceCount:t.length,angle:i}))}}function cM(e,t,n){if(n.length===0)return k(P(M.VARIABLE_FILLET_FAILED,`radii must contain at least one radius spec`));for(let e of n)if(e.radius<=0)return k(P(M.VARIABLE_FILLET_FAILED,`All radius values must be positive`));let r=H();try{let i=JSON.stringify({edge:r.hashCode(t.wrapped,G),radii:n.map(e=>({param:e.param,radius:e.radius}))}),a=U(r.filletVariable(e.wrapped,i));return BE(a)?RE(a)?O(a):(W(a),k(N(M.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a solid`))):(W(a),k(N(M.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a 3D shape`)))}catch(e){return k(N(M.VARIABLE_FILLET_FAILED,`Variable-radius fillet failed`,e))}}function lM(e){return OD(e)}function uM(e){if(!RE(e))return k(P(`NOT_A_SOLID`,`Input shape is not a solid`));let t=lM(e);try{let n=H().healSolid(e.wrapped);if(!n)return t?O(e):k(N(M.HEAL_NO_EFFECT,`Solid healing had no effect — shape is still invalid`));let r=U(n);return RE(r)?(uD(r),lM(r)?O(r):(W(r),k(N(`HEAL_SOLID_INCOMPLETE`,`Healed result is still invalid after ShapeFix_Solid`)))):(W(r),k(N(`HEAL_RESULT_NOT_SOLID`,`Healed result is not a solid`)))}catch(e){return k(N(`HEAL_SOLID_FAILED`,`Solid healing failed`,e))}}function dM(e){if(!IE(e))return k(P(`NOT_A_FACE`,`Input shape is not a face`));try{let t=U(H().healFace(e.wrapped));return IE(t)?O(t):(W(t),k(N(`HEAL_RESULT_NOT_FACE`,`Healed result is not a face`)))}catch(e){return k(N(`HEAL_FACE_FAILED`,`Face healing failed`,e))}}function fM(e,t){if(!FE(e))return k(P(`NOT_A_WIRE`,`Input shape is not a wire`));try{let n=U(H().healWire(e.wrapped,t?.wrapped));return FE(n)?O(n):(W(n),k(N(`HEAL_RESULT_NOT_WIRE`,`Healed result is not a wire`)))}catch(e){return k(N(`HEAL_WIRE_FAILED`,`Wire healing failed`,e))}}function pM(e){return RE(e)?uM(e):IE(e)?dM(e):FE(e)?fM(e):O(e)}function mM(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(lM(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=pD(e).length,u=fD(e).length,d=e,f=!1,p=t=>{let n=d;d=t,n!==e&&n.wrapped!==t.wrapped&&W(n)};if(o!==void 0)try{p(U(H().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=pD(d),t=0;for(let n of e)try{H().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(RE(d)&&i||IE(d)&&r||FE(d)&&n){let t=pM(d);Ya(t)?(p(t.value),RE(e)?(f=!0,s.push(`Applied ShapeFix_Solid`),c.push({name:`healSolid`,attempted:!0,succeeded:!0})):IE(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 m=pD(d).length,h=fD(d).length,g=Math.abs(m-l),_=Math.abs(h-u);g>0&&s.push(`Wire count changed by ${g}`),_>0&&s.push(`Face count changed by ${_}`);let v=lM(d);return s.push(v?`Final validation: valid`:`Final validation: still invalid`),c.push({name:`finalValidation`,attempted:!0,succeeded:v}),O({shape:d,report:{isValid:v,alreadyValid:!1,wiresHealed:g,facesHealed:_,solidHealed:f,steps:s,diagnostics:c}})}function hM(e){try{return O(U(H().fixShape(e.wrapped)))}catch(e){return k(N(M.FIX_SHAPE_FAILED,`ShapeFix_Shape failed`,e))}}function gM(e){try{let t=U(H().solidFromShell(e.wrapped));return RE(t)?lM(t)?O(t):(W(t),k(N(M.SOLID_FROM_SHELL_FAILED,`solidFromShell produced an invalid solid`))):(W(t),k(N(M.SOLID_FROM_SHELL_FAILED,`solidFromShell did not produce a solid`)))}catch(e){return k(N(M.SOLID_FROM_SHELL_FAILED,`Failed to create solid from shell`,e))}}function _M(e){try{let t=U(H().fixSelfIntersection(e.wrapped));return FE(t)?O(t):(W(t),k(N(M.FIX_SELF_INTERSECTION_FAILED,`Result is not a wire`)))}catch(e){return k(N(M.FIX_SELF_INTERSECTION_FAILED,`Failed to fix wire self-intersection`,e))}}function vM(e,{profile:t,endFactor:n=1}){return e<1e-10?k(P(`INVALID_EXTRUSION_LENGTH`,`Extrusion length too small (< 1e-10)`)):t!==`s-curve`&&t!==`linear`?k(P(`UNSUPPORTED_PROFILE`,`Unsupported extrusion profile: ${String(t)}`)):O(H().buildExtrusionLaw(t,e,n).Trim(0,e,1e-6))}function yM(e,t){let n=H(),r=n.makeLineEdge([...e],[...t]),i=n.makeWire([r]);return n.dispose(r),U(i)}function bM(e,t,n,r,i,a=!1){return U(H().makeHelixWire(e,t,n,[...r],[...i],a))}function xM(e){let t=U(e.shape),n=U(e.firstShape),r=U(e.lastShape),i=()=>{W(t),W(n),W(r)};return BE(t)?FE(n)?FE(r)?O([t,n,r]):(i(),k(wo(`SWEEP_END_NOT_WIRE`,`Sweep did not produce an end Wire`))):(i(),k(wo(`SWEEP_START_NOT_WIRE`,`Sweep did not produce a start Wire`))):(i(),k(wo(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function SM(e,t,n={},r=!1){if(n.mode===`simple`&&!r){let n=U(H().simplePipe(e.wrapped,t.wrapped));return BE(n)?O(n):(W(n),k(wo(`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=H(),_=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)return xM(v);let y=U(v);return BE(y)?O(y):(W(y),k(wo(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function CM(e,t,n,r){return SM(e,yM(t,FD(t,n)),{support:r})}function wM(e,t,n,r,i=!1){try{var a=LT();let o=VD(n);if(o<1e-10)return k(P(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let s=FD(t,n),c=a.u(yM(t,s)),l=null;if(r){let e=vM(o,r);if(A(e))return e;l=e.value}return SM(e,c,{law:l},i)}catch(e){a.e=e}finally{a.d()}}function TM(e,t,n,r,i,a=!1){try{var o=LT();if(Math.abs(t)<1e-10)return k(P(`ZERO_TWIST_ANGLE`,`Twist angle cannot be zero`));let s=VD(r);if(s<1e-10)return k(P(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let c=FD(n,r),l=o.u(yM(n,c)),u=t<0,d=360/Math.abs(t)*s,f=o.u(bM(d,s,1,n,r,u)),p=null;if(i){let e=vM(s,i);if(A(e))return e;p=e.value}return SM(e,l,{auxiliarySpine:f,law:p},a)}catch(e){o.e=e}finally{o.d()}}function EM(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 P(M.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 P(M.MULTI_SWEEP_FAILED,`Section locations must be strictly increasing`)}function DM(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(P(M.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 OM(e,t,n){if(e.length<2)return k(P(M.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=EM(e);if(o)return k(o);try{let n=H(),o=DM(e,t,n);if(A(o))return o;let s=o.value,c=[],l=[];try{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(o),l.push(n.downcast(o,`wire`))}let o=U(n.loftAdvanced(l,{solid:r,ruled:i,tolerance:a}));return BE(o)?O(o):(W(o),k(wo(`MULTI_SWEEP_NOT_3D`,`Multi-section sweep did not produce a 3D shape`)))}finally{for(let e of l)n.dispose(e);for(let e of c)n.dispose(e)}}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.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 kM(e,t,n,r={}){let{transition:i=`transformed`,solid:a=!0,tolerance:o}=r;try{let r=H(),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=U(typeof l==`object`&&`shape`in l?l.shape:l);return BE(u)?O(u):(W(u),k(wo(`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(N(M.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 AM(e,t){if(H().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`extrude: face is a null shape`));if(VD(t)<1e-10)return k(P(`EXTRUDE_ZERO_VECTOR`,`extrude: extrusion vector has zero length`));try{let n=H(),r=VD(t),i=WD(t),a=n.extrude(e.wrapped,[...i],r),o=AE(n.downcast(a,`solid`));return WE(a,o),O(o)}catch(e){return k(N(`EXTRUDE_FAILED`,`Extrusion operation failed`,e,{operation:`extrude`,vectorLength:VD(t)}))}}function jM(e,t=[0,0,0],n=[0,0,1],r=2*Math.PI){if(H().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`revolve: face is a null shape`));try{let i=U(H().revolveVec(e.wrapped,[...t],[...n],r));return BE(i)?O(i):(W(i),k(wo(`REVOLUTION_NOT_3D`,`Revolution did not produce a 3D shape`)))}catch(e){return k(N(`REVOLVE_FAILED`,`Revolution operation failed`,e,{operation:`revolve`,angle:r}))}}function MM(e){if(e.length===0)return O([]);let t=H(),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=VD(i);if(a<1e-10)return k(P(`EXTRUDE_ALL_ZERO_VECTOR`,`extrudeAll: entry ${t} has zero-length extrusion vector`));let o=[...WD(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=>{let n=AE(t.downcast(e,`solid`));return WE(e,n),n}))}catch(e){return k(N(`EXTRUDE_ALL_FAILED`,`Batch extrusion operation failed`,e))}}function NM(e,{ruled:t=!0,startPoint:n,endPoint:r,tolerance:i=1e-6}={},a=!1){if(e.length===0&&!n&&!r)return k(P(`LOFT_EMPTY`,`Loft requires at least one wire or start/end point`));let o=H(),s=n?o.makeVertex(...jD(n)):void 0,c=r?o.makeVertex(...jD(r)):void 0;try{let n=U(o.loftAdvanced(e.map(e=>e.wrapped),{solid:!a,ruled:t,tolerance:i,...s?{startVertex:s}:{},...c?{endVertex:c}:{}}));return BE(n)?O(n):(W(n),k(wo(`LOFT_NOT_3D`,`Loft did not produce a 3D shape`)))}catch(e){return k(N(`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 PM(e){if(e.length===0)return O([]);let t=H(),n=[],r=e.map(e=>{let r=e.startPoint?t.makeVertex(...jD(e.startPoint)):void 0,i=e.endPoint?t.makeVertex(...jD(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=U(t);if(!BE(e))return W(e),k(wo(`LOFT_ALL_NOT_3D`,`Batch loft entry did not produce a 3D shape`));n.push(e)}return O(n)}catch(e){return k(N(`LOFT_ALL_FAILED`,`Batch loft operation failed`,e))}finally{for(let e of n)t.dispose(e)}}var FM=new WeakMap;function IM(e,t){return FM.get(e)?.get(t)}function LM(e,t,n){let r=FM.get(e);r||(r=new Map,FM.set(e,r)),r.set(t,n)}function RM(e){return H().isNull(e.wrapped)}function zM(e){return k(P(M.NULL_SHAPE_INPUT,`${e}: shape is a null shape`))}function BM(e){let t=IM(e.wrapped,`volume`);if(t)return O(t);if(RM(e))return zM(`measureVolumeProps`);let n=H(),r=n.shapeType(e.wrapped);if(r!==`solid`&&r!==`compsolid`&&r!==`compound`){let t={mass:0,volume:0,centerOfMass:[0,0,0]};return LM(e.wrapped,`volume`,t),O(t)}let i=n.volume(e.wrapped),a=eD(()=>n.centerOfMass(e.wrapped),M.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 LM(e.wrapped,`volume`,o),O(o)}function VM(e){let t=IM(e.wrapped,`surface`);if(t)return O(t);if(RM(e))return zM(`measureSurfaceProps`);let n=H(),r=n.area(e.wrapped),i=eD(()=>n.centerOfMass(e.wrapped),M.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 LM(e.wrapped,`surface`,a),O(a)}function HM(e){let t=IM(e.wrapped,`linear`);if(t)return O(t);if(RM(e))return zM(`measureLinearProps`);let n=H(),r=n.length(e.wrapped),i={mass:r,length:r,centerOfMass:n.linearCenterOfMass(e.wrapped)};return LM(e.wrapped,`linear`,i),O(i)}function UM(e){let t=BM(e);return t.ok?O(t.value.mass):t}function WM(e){let t=VM(e);return t.ok?O(t.value.mass):t}function GM(e){let t=HM(e);return t.ok?O(t.value.mass):t}function KM(e,t){return RM(e)||RM(t)?zM(`measureDistance`):O(H().distance(e.wrapped,t.wrapped).value)}function qM(e,t){if(RM(e)||RM(t))return zM(`measureDistanceProps`);let n=H().distance(e.wrapped,t.wrapped);return O({distance:n.value,point1:n.point1,point2:n.point2})}function JM(e){if(RM(e))return zM(`createDistanceQuery`);let t=H().createDistanceQuery(e.wrapped);return O({distanceTo(e){return RM(e)?zM(`createDistanceQuery.distanceTo`):O(t.distanceTo(e.wrapped).value)},dispose(){t.dispose()}})}function YM(e,t,n){if(RM(e))return zM(`measureCurvatureAt`);let r=H().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 XM(e){if(RM(e))return zM(`measureCurvatureAtMid`);let t=xO(e),n=(t.uMin+t.uMax)/2,r=(t.vMin+t.vMax)/2,i=H().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})}function ZM(e,t){return e.map(e=>JE(e,t))}function QM(e,t){let n=H(),r=n.iterShapes(e,t),i=[],a=new Map;for(let e of r){let r=n.hashCode(e,G),o=a.get(r);if(o?.some(t=>n.isSame(t,e))){n.dispose(e);continue}let s=qE(e,t);i.push(s),o?o.push(s.wrapped):a.set(r,[s.wrapped])}return i}function $M(e){let t=H(),n=new Map;for(let r of e){let e=t.hashCode(r.wrapped,G),i=n.get(e);i?i.push(r):n.set(e,[r])}return n}function eN(e,t,n){let r=H();return e.get(n)?.find(e=>r.isSame(e.wrapped,t))}function tN(e){let t=cD(e);if(t.edgeToFaces)return t.edgeToFaces;let n=H(),r=fD(e),i=$M(dD(e)),a=new Map;for(let e of r)for(let t of n.iterShapes(e.wrapped,`edge`)){let r=n.hashCode(t,G),o=eN(i,t,r);if(n.dispose(t),!o)continue;let s=a.get(r);s||(s=[],a.set(r,s)),s.some(t=>n.isSame(t.edge,o.wrapped)&&n.isSame(t.face,e.wrapped))||s.push({edge:o.wrapped,face:e.wrapped})}return t.edgeToFaces=a,a}function nN(e){let t=cD(e);if(t.vertexToFaces)return t.vertexToFaces;let n=H(),r=fD(e),i=$M(mD(e)),a=new Map;for(let e of r)for(let t of n.iterShapes(e.wrapped,`vertex`)){let r=n.hashCode(t,G),o=eN(i,t,r);if(n.dispose(t),!o)continue;let s=a.get(r);s||(s=[],a.set(r,s)),s.some(t=>n.isSame(t.vertex,o.wrapped)&&n.isSame(t.face,e.wrapped))||s.push({vertex:o.wrapped,face:e.wrapped})}return t.vertexToFaces=a,a}function rN(e,t){let n=H(),r=tN(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 ZM(o,`face`)}function iN(e,t){let n=H(),r=nN(e),i=n.hashCode(t.wrapped,G),a=r.get(i)??[],o=[],s=new Map;for(let e of a){if(!n.isSame(e.vertex,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 ZM(o,`face`)}function aN(e){return QM(e.wrapped,`edge`)}function oN(e){return QM(e.wrapped,`vertex`)}function sN(e){return QM(e.wrapped,`wire`)}function cN(e){return QM(e.wrapped,`vertex`)}function lN(e,t){let n=H(),r=tN(e),i=QM(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))}}for(let e of i)e[Symbol.dispose]();return ZM(a,`face`)}var uN=new Map;function dN(e,t){let n=H(),r=ET()??``;if(uN.get(r)!==!1){let i;try{i=n.sharedEdges(e.wrapped,t.wrapped);let a=i.map(e=>qE(e,`edge`));return uN.set(r,!0),a}catch(e){if(i)for(let e of i)n.dispose(e);if(!l(e))throw e;uN.set(r,!1)}}return fN(e,t)}function fN(e,t){let n=H(),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(qE(e,`edge`)):n.dispose(e);for(let e of i)n.dispose(e);return o}var pN=new Map;function mN(e,t){let n=H(),r=ET()??``;if(pN.get(r)!==!1)try{let i=n.adjacentFaces(e.wrapped,t.wrapped);pN.set(r,!0);try{return i.map(e=>n.hashCode(e,G))}finally{for(let e of i)n.dispose(e)}}catch(e){if(!l(e))throw e;pN.set(r,!1)}return lN(e,t).map(e=>n.hashCode(e.wrapped,G))}function hN(e,t){let n=0,r=vO(t);if(e.surfaceType!==void 0)if(r===e.surfaceType)n+=1;else return-1/0;if(e.normal!==void 0){let r=TO(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=WM(t);if(r.ok&&r.value>0){let t=Math.abs(Math.log(e.area/r.value));t>1&&(n-=t)}}return n}function gN(e){let t=vO(e),n=TO(e),r=EO(e),i=WM(e);return{entityType:`face`,surfaceType:t,normal:n,centroid:r,area:i.ok?i.value:void 0}}var _N=.9;function vN(e){if(e[2]>_N)return`box:top`;if(e[2]<-.9)return`box:bottom`;if(e[1]>_N)return`box:back`;if(e[1]<-.9)return`box:front`;if(e[0]>_N)return`box:right`;if(e[0]<-.9)return`box:left`}function yN(e,t){if(vO(t)!==`PLANE`)return;let n=TO(t)[2];if(n>_N)return`${e}:top`;if(n<-.9)return`${e}:bottom`}function bN(e){return vO(e)===`CYLINDRE`?`cylinder:lateral`:yN(`cylinder`,e)}function xN(e){return vO(e)===`CONE`?`cone:lateral`:yN(`cone`,e)}function SN(e){return vO(e)===`SPHERE`?`sphere:surface`:void 0}var CN={box:e=>vN(TO(e)),cylinder:bN,cone:xN,sphere:SN};function wN(e,t){let n=new Map,r=CN[t],i=H(),a=0;for(let o of i.iterShapes(e.wrapped,`face`)){let e=KE(o,`face`);try{let i=r?.(e),o=i!==void 0&&!n.has(i)?i:`${t}:face_${a}`;n.set(o,[Dk(e)]),a++}finally{GE(e,o)}}return n}function TN(e,t,n){return{origin:e,role:t,hint:gN(n)}}function EN(e,t){let n=[];for(let r of e){if(t.deleted.has(r))continue;let e=t.modified.get(r),i=e&&e.length>0?e:[r];for(let e of i)n.includes(e)||n.push(e)}return n}function DN(e,t,n){let r=e.get(t);if(!r)return e;let i=new Map;for(let[e,t]of r){let r=EN(t,n);r.length>0&&i.set(e,r)}let a=new Map;for(let[n,r]of e)a.set(n,n===t?i:r);return a}var ON=.1,kN=.5;function AN(e,t,n){let r=-1/0,i,a=-1/0,o=[];for(let s of t){let t=n(e,s);t>kN&&o.push([s,t]),t>r?(a=r,r=t,i=s):t>a&&(a=t)}return i!==void 0&&r>kN?r-a<ON&&o.length>1?{kind:`ambiguous`,candidates:o.filter(([,e])=>e>=r-ON).map(([e])=>e)}:{kind:`match`,face:i}:{kind:`none`}}function jN(e,t,n,r){let i=fD(n),a=r??hN,o=t.get(e.origin)?.get(e.role);if(o!==void 0&&o.length>0){let t=i.filter(e=>o.includes(Dk(e)));if(t.length===1){let[e]=t;if(e!==void 0)return{face:e,confidence:`exact`}}else if(t.length===0)return{ref:e,reason:`deleted`};else{let n=AN(e.hint,t,a);if(n.kind===`match`)return{face:n.face,confidence:`geometric-fallback`};if(n.kind===`ambiguous`)return{ref:e,reason:`ambiguous`,candidates:n.candidates}}}let s=AN(e.hint,i,a);return s.kind===`match`?{face:s.face,confidence:`geometric-fallback`}:s.kind===`ambiguous`?{ref:e,reason:`ambiguous`,candidates:s.candidates}:{ref:e,reason:`not-found`}}function MN(e,t){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(n*n+r*r+i*i)}function NN(e){if(e.length===0)return;let t=0,n=0,r=0;for(let i of e){let e=AD(i);t+=e[0],n+=e[1],r+=e[2]}let i=e.length;return[t/i,n/i,r/i]}function PN(e,t,n){let r=n.get(t);if(!r)return;let i=Dk(e);for(let[e,t]of r)if(t.includes(i))return e}function FN(e,t,n,r){let i=r.get(t)?.get(n);return i===void 0||i.length===0?[]:fD(e).filter(e=>i.includes(Dk(e)))}function IN(e){let t=GM(e);return{entityType:`edge`,length:t.ok?t.value:void 0,midpoint:NN(cN(e))}}function LN(e){let t=new Set,n=[];for(let r of e){let e=Dk(r);t.has(e)||(t.add(e),n.push(r))}return n}var RN=1e-6;function zN(e,t){if(t.length===void 0&&t.midpoint===void 0)return;let n,r=1/0,i=1/0;for(let a of e){let e=0;if(t.length!==void 0){let n=GM(a);n.ok&&(e+=Math.abs(n.value-t.length))}if(t.midpoint!==void 0){let n=NN(cN(a));n!==void 0&&(e+=MN(t.midpoint,n))}e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<RN))return n}function BN(e,t,n,r){let[i,a]=rN(n,t);if(i===void 0||a===void 0)return;let o=PN(i,e,r),s=PN(a,e,r);if(!(o===void 0||s===void 0))return{origin:e,faceRoles:[o,s],hint:IN(t)}}function VN(e,t,n){let[r,i]=e.faceRoles,a=FN(n,e.origin,r,t),o=FN(n,e.origin,i,t);if(a.length===0||o.length===0)return{ref:e,reason:`not-found`};let s=[];for(let e of a)for(let t of o)s.push(...dN(e,t));let c=LN(s);if(c.length===1){let[e]=c;if(e!==void 0)return{edge:e,confidence:`exact`}}if(c.length>1){let t=zN(c,e.hint);return t===void 0?{ref:e,reason:`ambiguous`,candidates:c}:{edge:t,confidence:`geometric-fallback`}}return{ref:e,reason:`not-found`}}var HN=3,UN=1e-6;function WN(e,t){let n=new Set;for(let r of e)for(let e of oN(r)){let r=Dk(e);n.add(r),t.has(r)||t.set(r,e)}return n}function GN(e,t){let n=new Set;for(let r of e)t.has(r)&&n.add(r);return n}function KN(e){let t=new Map,n;for(let r of e){let e=WN(r,t);n=n===void 0?e:GN(n,e)}if(n===void 0)return[];let r=[];for(let e of n){let n=t.get(e);n!==void 0&&r.push(n)}return r}function qN(e,t){if(t.position===void 0)return;let n,r=1/0,i=1/0;for(let a of e){let e=MN(AD(a),t.position);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<UN))return n}function JN(e,t,n,r){let i=iN(n,t);if(i.length<HN)return;let a=new Set;for(let t of i){let n=PN(t,e,r);n!==void 0&&a.add(n)}if(!(a.size<HN))return{origin:e,faceRoles:[...a].sort(),hint:{entityType:`vertex`,position:AD(t)}}}function YN(e,t,n){let r=[];for(let i of e.faceRoles){let a=FN(n,e.origin,i,t);if(a.length===0)return{ref:e,reason:`not-found`};r.push(a)}let i=KN(r);if(i.length===1){let[e]=i;if(e!==void 0)return{vertex:e,confidence:`exact`}}if(i.length>1){let t=qN(i,e.hint);return t===void 0?{ref:e,reason:`ambiguous`,candidates:i}:{vertex:t,confidence:`geometric-fallback`}}return{ref:e,reason:`not-found`}}var XN=.99,ZN=.1,QN=1e-6;function $N(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function eP(e,t){return fD(e).filter(e=>$N(TO(e),t)>XN)}function tP(e,t,n){let r=new Set([...t,...n].map(Dk)),i=new Set;for(let n of t)for(let t of mN(e,n))i.add(t);let a=[],o=new Set;for(let t of n)for(let n of mN(e,t))r.has(n)||o.has(n)||!i.has(n)||(o.add(n),a.push(n));if(a.length===0)return[];let s=new Map(fD(e).map(e=>[Dk(e),e]));return a.map(e=>s.get(e)).filter(e=>e!==void 0)}function nP(e,t){let n,r=1/0,i=1/0;for(let a of e){let e=MN(EO(a),t);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<QN))return n}function rP(e,t,n,r,i){let[a,o]=rN(r,n);if(a===void 0||o===void 0)return;let s=PN(a,e,i),c=PN(o,e,i);if(!(s===void 0||c===void 0))return{origin:e,op:t,betweenRoles:[s,c],hint:{entityType:`derived-face`,normalA:TO(a),normalB:TO(o),edgeMidpoint:NN(cN(n))}}}function iP(e,t,n){let r=FN(n,e.origin,e.betweenRoles[0],t);r.length===0&&(r=eP(n,e.hint.normalA));let i=FN(n,e.origin,e.betweenRoles[1],t);if(i.length===0&&(i=eP(n,e.hint.normalB)),r.length===0||i.length===0)return{ref:e,reason:`not-found`};let a=tP(n,r,i).filter(t=>$N(TO(t),e.hint.normalA)>ZN&&$N(TO(t),e.hint.normalB)>ZN);if(a.length===1){let[e]=a;if(e!==void 0)return{face:e,confidence:`geometric-fallback`}}if(a.length>1){let t=e.hint.edgeMidpoint&&nP(a,e.hint.edgeMidpoint);return t?{face:t,confidence:`geometric-fallback`}:{ref:e,reason:`ambiguous`,candidates:a}}return{ref:e,reason:`not-found`}}function aP(e){return typeof e==`object`&&!!e&&`origin`in e}function oP(e){return aP(e)&&`betweenRoles`in e&&`op`in e}function sP(e){return aP(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length===2}function cP(e){return aP(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length>=3}function lP(e){return aP(e)&&typeof e.role==`string`}function uP(e){return lP(e)||sP(e)||cP(e)||oP(e)}function dP(e,t){return t===void 0?{ok:!1,reason:e}:{ok:!1,reason:e,candidates:t}}function fP(e,t,n){if(oP(e)){let r=iP(e,t,n);return`face`in r?{ok:!0,entity:r.face}:dP(r.reason,r.candidates)}if(sP(e)){let r=VN(e,t,n);return`edge`in r?{ok:!0,entity:r.edge}:dP(r.reason,r.candidates)}if(cP(e)){let r=YN(e,t,n);return`vertex`in r?{ok:!0,entity:r.vertex}:dP(r.reason,r.candidates)}let r=jN(e,t,n);return`face`in r?{ok:!0,entity:r.face}:dP(r.reason,r.candidates)}function pP(e,t,n){let r=n.get(e.origin);if(r!==void 0)return r;let i=new Map([[e.origin,wN(t,e.origin)]]);return n.set(e.origin,i),i}function mP(e,t){return fP(e,pP(e,t,new Map),t)}function hP(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t!==Object.prototype&&t!==null?!1:!(`wrapped`in e)}function gP(e,t){let n=new Map,r=e=>{if(uP(e)){let r=fP(e,pP(e,t,n),t);return r.ok?r.entity:e}if(Array.isArray(e))return e.map(r);if(hP(e)){let t={};for(let[n,i]of Object.entries(e))t[n]=r(i);return t}return e},i={...e};for(let[t,n]of Object.entries(e))i[t]=r(n);return i}function _P(e,t,n,r){let i=AE(H().makeBox(e,t,n)),a=r?.at??(r?.centered?[0,0,0]:void 0);if(a)try{var o=LT();return pk(o.u(i),[a[0]-e/2,a[1]-t/2,a[2]-n/2])}catch(e){o.e=e}finally{o.d()}return i}function vP(e,t,n){let r=n?.at??[0,0,0],i=n?.axis??[0,0,1],a=lj(e,t,r,i);if(n?.centered)try{var o=LT();let e=[-i[0]*t*.5,-i[1]*t*.5,-i[2]*t*.5];return pk(o.u(a),e)}catch(e){o.e=e}finally{o.d()}return a}function yP(e,t){let n=uj(e);if(t?.at)try{var r=LT();return pk(r.u(n),t.at)}catch(e){r.e=e}finally{r.d()}return n}function bP(e,t,n,r){let i=r?.at??[0,0,0],a=r?.axis??[0,0,1],o=dj(e,t,n,i,a);if(r?.centered)try{var s=LT();let e=[-a[0]*n*.5,-a[1]*n*.5,-a[2]*n*.5];return pk(s.u(o),e)}catch(e){s.e=e}finally{s.d()}return o}function xP(e,t,n){return fj(e,t,n?.at??[0,0,0],n?.axis??[0,0,1])}function SP(e,t,n,r){let i=pj(e,t,n);if(r?.at)try{var a=LT();return pk(a.u(i),r.at)}catch(e){a.e=e}finally{a.d()}return i}function CP(e,t){return CA(e,t)}function wP(e,t){let n=t?.axis??[0,0,1];return wA(e,t?.at??[0,0,0],n)}function TP(e,t,n){let r=n?.axis??[0,0,1];return TA(e,t,n?.at??[0,0,0],r,n?.xDir)}function EP(e,t,n,r){return EA(e,t,n,r?.at??[0,0,0],r?.axis??[0,0,1],r?.lefthand??!1)}function DP(e,t,n){return DA(e,t,n)}function OP(e,t,n,r,i){let a=i?.axis??[0,0,1];return OA(e,t,n*YE,r*YE,i?.at??[0,0,0],a,i?.xDir)}function kP(e,t){return kA(e,t)}function AP(e){return jA(e)}function jP(e,t,n){return MA(e,t,n)}function MP(e){return NA(e)}function NP(e){return Qa(NA(e),e=>fE(e)?O(e):k(P(`WIRE_NOT_CLOSED`,`Assembled wire is not closed: start and end points do not coincide`)))}function PP(e,t){return PA(e,t)}function FP(e){return LA(e)}function IP(e,t){return IA(e,t)}function LP(e){return zA(e)}function RP(e){return mj(e)}function zP(e){return gj(e)}function BP(e){return _j(e)}function VP(e,t,n){return hj(e,t,n)}function HP(e,t){return cj(e,t)}function UP(e,t){return RA(e,t)}function WP(){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 GP(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??WP(),color:[a,o,s,c]}});return XT(H().createXCAFDocument(t))}function KP(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=H(),a=e.map(({shape:e,name:t,color:n,alpha:i})=>{let[a,o,s]=r(n??`#f00`);return{shape:e.wrapped,name:t??WP(),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(Oo(`STEP_EXPORT_FAILED`,`Failed to write STEP file`))}finally{o.delete()}}function qP(e,t,n,r,i){if(n<1)return k(P(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(KD(t))return k(P(`PATTERN_ZERO_DIRECTION`,`Pattern direction cannot be zero`));let a=WD(t),o=H().linearPattern(e.wrapped,[...a],r,n).map(e=>U(e));try{return KA(o,{optimisation:`sameFace`,...i,unsafe:!0})}finally{for(let e of o)e[Symbol.dispose]()}}function JP(e,t,n,r=360,i=[0,0,0],a){if(n<1)return k(P(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(KD(t))return k(P(`PATTERN_ZERO_AXIS`,`Pattern axis cannot be zero`));let o=r/n,s=H().circularPattern(e.wrapped,[...i],[...t],o,n).map(e=>U(e));try{return KA(s,{optimisation:`sameFace`,...a,unsafe:!0})}finally{for(let e of s)e[Symbol.dispose]()}}function YP(e,t,n,r,i,a,o,s){if(r<1||i<1)return k(P(`PATTERN_INVALID_COUNT`,`Grid pattern counts must be at least 1`));if(r===1&&i===1)return O(e);if(KD(t))return k(P(`PATTERN_ZERO_DIRECTION`,`Grid directionX cannot be zero`));if(KD(n))return k(P(`PATTERN_ZERO_DIRECTION`,`Grid directionY cannot be zero`));let c=H(),l=WD(t),u=WD(n);if(typeof c.gridPattern==`function`)return O(U(c.gridPattern(e.wrapped,[...l],[...u],a,o,r,i)));let d=qP(e,t,r,a,s);if(!d.ok)return d;let f=d.value,p=qP(f,n,i,o,s),m=p.ok&&p.value===f;return f!==e&&!m&&f[Symbol.dispose](),p}function XP(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 ZP(e,t){return{...e,children:[...e.children,t]}}function QP(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 $P(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 eF(e,t){if(e.name===t)return e;for(let n of e.children){let e=eF(n,t);if(e)return e}}function tF(e,t,n=0){t(e,n);for(let r of e.children)tF(r,t,n+1)}function nF(e){let t=1;for(let n of e.children)t+=nF(n);return t}function rF(e){let t=[];return tF(e,e=>{e.shape&&t.push(e.shape)}),t}function iF(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function aF(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 oF(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function sF(e){return oF(aF(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function cF(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 lF(e,t){let n=t/2,r=Math.sin(n),i=oF(e);return[Math.cos(n),i[0]*r,i[1]*r,i[2]*r]}function uF(e,t){let n=oF(e),r=oF(t),i=iF(n,r);if(i>=.999999999)return[1,0,0,0];if(i<=-.999999999)return lF(sF(n),Math.PI);let a=aF(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 dF(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 fF=Math.PI/180;function pF(e,t,n){return Math.min(n,Math.max(t,e))}function mF(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function hF(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 gF(e){return mF(hF(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function _F(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:mF(t),min:s,max:c,value:pF(n.value??0,s,c)}}function vF(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:mF(r.direction)},min:a.min,max:a.max,value:a.value,dofs:i}}function yF(e,t,n,r={}){return vF(`revolute`,e,t,n,[_F(`rotation`,n.direction,r,-180,180)])}function bF(e,t,n,r={}){return vF(`prismatic`,e,t,n,[_F(`translation`,n.direction,r,0,100)])}function xF(e,t,n,r={}){return vF(`cylindrical`,e,t,n,[_F(`rotation`,n.direction,r.rotation??{},-180,180),_F(`translation`,n.direction,r.translation??{},0,100)])}function SF(e,t,n,r={}){let i=mF(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?gF(i):mF(n)}else a=gF(i);let o=mF(hF(i,a));return vF(`planar`,e,t,{origin:n.origin,direction:i},[_F(`translation`,a,r.u??{},-100,100),_F(`translation`,o,r.v??{},-100,100),_F(`rotation`,i,r.rotation??{},-180,180)])}function CF(e,t,n,r={}){return vF(`spherical`,e,t,{origin:n,direction:[0,0,1]},[_F(`rotation`,[1,0,0],r.x??{},-180,180),_F(`rotation`,[0,1,0],r.y??{},-180,180),_F(`rotation`,[0,0,1],r.z??{},-180,180)])}function wF(e,t){let n=e.dofs.map((e,n)=>{let r=t[n];return r===void 0?e:{...e,value:pF(r,e.min,e.max)}}),r=n[0];return r?{...e,dofs:n,value:r.value}:{...e,dofs:n}}function TF(e,t){return wF(e,[t])}function EF(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=lF(t.axis,n*fF),i=cF(r,e);return{position:[e[0]-i[0],e[1]-i[1],e[2]-i[2]],rotation:r}}function DF(e,t=e.value){let n=Array.isArray(t)?t:void 0,r=n?void 0:t,i=e.axis.origin,a=kF;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=AF(a,EF(i,o,pF(s,o.min,o.max)))}return a}function OF(e,t){let n=e.joints??[];return{...e,joints:[...n,t]}}var kF={position:[0,0,0],rotation:[1,0,0,0]};function AF(e,t){let n=cF(e.rotation,t.position);return{position:[e.position[0]+n[0],e.position[1]+n[1],e.position[2]+n[2]],rotation:dF(e.rotation,t.rotation)}}function jF(e){let t=[];return tF(e,e=>{e.joints&&t.push(...e.joints)}),t}function MF(e,t={}){let n=[],r=new Set;tF(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,kF);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?AF(DF(n,i),n.offset):DF(n,i);a.set(n.child,AF(r,c))}}for(let e of o)a.has(e.child)||a.set(e.child,kF);return a}function NF(e){return jF(e).reduce((e,t)=>e+t.dofs.length,0)}var PF={position:[0,0,0],rotation:[1,0,0,0]};function FF(e,t){let n=cF(e.rotation,t);return[n[0]+e.position[0],n[1]+e.position[1],n[2]+e.position[2]]}function IF(e){return[e[0],-e[1],-e[2],-e[3]]}function LF(e,t){let[n,r,i,a]=dF(t,IF(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 RF(e,t){let n=[];tF(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 zF(e,t){return e[t]??0}function BF(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]=zF(e,a*n+t);i[a*r+n]=zF(t,a)}for(let e=0;e<n;e++){let t=e;for(let a=e+1;a<n;a++)Math.abs(zF(i,a*r+e))>Math.abs(zF(i,t*r+e))&&(t=a);if(Math.abs(zF(i,t*r+e))<1e-12)return null;if(t!==e)for(let n=e;n<r;n++){let a=zF(i,e*r+n);i[e*r+n]=zF(i,t*r+n),i[t*r+n]=a}let a=zF(i,e*r+e);for(let t=e;t<r;t++)i[e*r+t]=zF(i,e*r+t)/a;for(let t=0;t<n;t++){if(t===e)continue;let n=zF(i,t*r+e);if(n!==0)for(let a=e;a<r;a++)i[t*r+a]=zF(i,t*r+a)-n*zF(i,e*r+a)}}let a=new Float64Array(n);for(let e=0;e<n;e++)a[e]=zF(i,e*r+n);return a}function VF(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 HF(e,t){let n={},r=0;for(let i of e){let e=[];for(let n=0;n<i.count;n++)e.push(zF(t,r++));n[i.child]=e}return n}function UF(e,t,n,r,i){let a=FF(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=LF(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+=zF(e,t)**2;return Math.sqrt(o)}function WF(e,t,n,r,i,a,o,s,c,l){let u=FF(o,s);for(let d=0;d<n;d++){let f=zF(t,d),p=f+c>zF(a,d)&&f-c>=zF(i,d)?-c:c;t[d]=f+p;let m=l(t);t[d]=f;let h=FF(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=LF(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 GF(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+=zF(e,t*n+r)*zF(e,i*n+r);a[t*r+i]=s+(t===i?o:0)}let s=BF(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+=zF(e,a*n+t)*zF(s,a);c[t]=i}return c}function KF(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}=VF(RF(e,t),r.seed),p=u.length,m=n=>MF(e,HF(l,n)).get(t)??PF,h=new Float64Array(c),g=new Float64Array(c*p),_=m(u),v=UF(h,_,n,s,c),y=0;for(;y<i&&p>0&&v>a;y++){WF(g,u,p,c,d,f,_,s,1e-6,m);let e=GF(g,h,p,c,o);if(!e)break;for(let t=0;t<p;t++){let n=zF(u,t)+zF(e,t);u[t]=Math.min(zF(f,t),Math.max(zF(d,t),n))}_=m(u),v=UF(h,_,n,s,c)}return{values:HF(l,u),converged:v<=a,iterations:y,error:v}}function qF(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 JF(e,t,n,r){let i=[];tF(e,e=>{e.joints&&i.push(...e.joints)});let a=i.map(e=>({child:e.child,a:qF(e,t[e.child]),b:qF(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:MF(e,r)})}return s}var YF=Math.PI/180;function XF(e,t,n,r){let i=e*YF,a=r*YF,o=dF(lF([0,0,1],i),lF([1,0,0],a));return{position:[n*Math.cos(i),n*Math.sin(i),t],rotation:o}}function ZF(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=XF(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`?bF(i,a,s,c):yF(i,a,s,c),offset:o}})}var QF=Math.PI/180,$F=180/Math.PI;function eI(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function tI(e){return String(e===0?0:e)}function nI(e){return`${tI(e[0])} ${tI(e[1])} ${tI(e[2])}`}function rI(e,t={}){let n=t.name??`robot`,r=t.effort??0,i=t.velocity??0,a=t.meshes??{},o=[],s=[];tF(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(P(M.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' is '${e.type}'; URDF supports only revolute and prismatic joints`));if(e.offset)return k(P(M.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="${eI(n)}">`];for(let e of o){let t=a[e];t?c.push(` <link name="${eI(e)}">`,` <visual><geometry><mesh filename="${eI(t)}"/></geometry></visual>`,` </link>`):c.push(` <link name="${eI(e)}"/>`)}for(let e of s){let t=e.type===`revolute`,n=t?e.min*QF:e.min,a=t?e.max*QF:e.max,o=e.type===`prismatic`?[0,0,0]:e.axis.origin;c.push(` <joint name="${eI(`${e.parent}_to_${e.child}`)}" type="${e.type}">`,` <parent link="${eI(e.parent)}"/>`,` <child link="${eI(e.child)}"/>`,` <origin xyz="${nI(o)}" rpy="0 0 0"/>`,` <axis xyz="${nI(e.axis.direction)}"/>`,` <limit lower="${tI(n)}" upper="${tI(a)}" effort="${tI(r)}" velocity="${tI(i)}"/>`,` </joint>`)}return c.push(`</robot>`,``),O(c.join(`
|
|
16
|
+
`))}function iI(e,t){return RegExp(`\\b${t}\\s*=\\s*"([^"]*)"`).exec(e)?.[1]}function aI(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 oI(e,t){return cF(dF(dF(lF([0,0,1],t[2]),lF([0,1,0],t[1])),lF([1,0,0],t[0])),e)}function sI(e){let t=/<robot\b([^>]*)>/.exec(e);if(!t)return k(P(M.VALIDATION_FAILED,`importURDF: no <robot> element found`));let n=iI(t[1]??``,`name`)??`robot`,r=[],i=/<link\b([^>]*?)(?:\/>|>)/g;for(let t=i.exec(e);t;t=i.exec(e)){let e=iI(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=iI(e,`type`)??`fixed`;if(r===`fixed`||r===`floating`||r===`planar`)continue;let i=/<parent\b([^>]*?)\/?>/.exec(n),o=/<child\b([^>]*?)\/?>/.exec(n),s=iI(i?.[1]??``,`link`),c=iI(o?.[1]??``,`link`);if(!s||!c)return k(P(M.VALIDATION_FAILED,`importURDF: joint missing parent/child link (${iI(e,`name`)??`unnamed`})`));let l=/<origin\b([^>]*?)\/?>/.exec(n),u=/<axis\b([^>]*?)\/?>/.exec(n),d=/<limit\b([^>]*?)\/?>/.exec(n),f=aI(iI(l?.[1]??``,`xyz`),[0,0,0]),p=aI(iI(l?.[1]??``,`rpy`),[0,0,0]),m=oI(aI(iI(u?.[1]??``,`xyz`),[1,0,0]),p),h=Number(iI(d?.[1]??``,`lower`)??NaN),g=Number(iI(d?.[1]??``,`upper`)??NaN);if(r===`prismatic`){let e=Number.isFinite(h)&&Number.isFinite(g)?{min:h,max:g}:{};a.push(bF(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*$F,max:g*$F};a.push(yF(s,c,{origin:f,direction:m},e))}else return k(P(M.VALIDATION_FAILED,`importURDF: joint '${iI(e,`name`)??`unnamed`}' has unrecognized type '${r}'`))}return O({name:n,links:r,joints:a})}function cI(){return{steps:[],shapes:new Map}}function lI(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 uI(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 dI(e,t){return e.steps.find(e=>e.id===t)}function fI(e,t){return e.shapes.get(t)}function pI(e){return e.steps.length}function mI(e,t){let n=e.steps.findIndex(e=>e.id===t);return n===-1?[]:e.steps.slice(n)}function hI(e,t,n){let r=new Map(e.shapes);return r.set(t,n),{...e,shapes:r}}function gI(){return{operations:new Map}}function _I(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function vI(e,t){let[n,r]=t;return n!==void 0&&r===void 0&&BE(n)?gP(e,n):{...e}}function yI(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=hI(r,t,i));for(let n of e.steps){let e=t.operations.get(n.type);if(!e)return k(Do(`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(Do(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${n.id}`));i.push(t)}try{let t=e(i,vI(n.parameters,i));r=lI(r,{id:n.id,type:n.type,parameters:n.parameters,inputIds:n.inputIds,outputId:n.outputId},t)}catch(e){return k(Do(`REPLAY_STEP_FAILED`,`Step ${n.id} (${n.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(r)}function bI(e,t,n){let r=e.steps.findIndex(e=>e.id===t);if(r===-1)return k(Do(`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(Do(`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(Do(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${r.id}`));o.push(t)}try{let e=i(o,vI(r.parameters,o));a=lI(a,{id:r.id,type:r.type,parameters:r.parameters,inputIds:r.inputIds,outputId:r.outputId},e)}catch(e){return k(Do(`REPLAY_STEP_FAILED`,`Step ${r.id} (${r.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(a)}function xI(e,t,n,r){return e.steps.findIndex(e=>e.id===t)===-1?k(Do(`MODIFY_STEP_NOT_FOUND`,`Step not found: ${t}`)):bI({steps:e.steps.map(e=>e.id===t?{...e,parameters:n}:e),shapes:e.shapes},t,r)}function SI(e){let t={};for(let[n,r]of e.shapes){let e=Ek(r);if(!e.ok)return k(Do(`SERIALIZE_SHAPE_FAILED`,`Failed to serialize shape "${n}": ${e.error.message}`));t[n]=e.value}return O({steps:e.steps,shapes:t})}function CI(e){let t=new Map;for(let[n,r]of Object.entries(e.shapes))try{let e=hO(r);if(!e.ok)return k(Do(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e.error.message}`));t.set(n,e.value)}catch(e){return k(Do(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e instanceof Error?e.message:String(e)}`))}return O({steps:e.steps,shapes:t})}function wI(e){try{var t=LT();let{radius:n,pitch:r,height:i,depth:a=.6*r,toothHalfWidth:o=.42*r,crest:s=0,sectionsPerTurn:c=20,lefthand:l=!1,inward:u=!1}=e;if(!(n>0))return k(P(`THREAD_INVALID_RADIUS`,`radius must be > 0`));if(!(r>0))return k(P(`THREAD_INVALID_PITCH`,`pitch must be > 0`));if(!(i>0))return k(P(`THREAD_INVALID_HEIGHT`,`height must be > 0`));if(!(a>0))return k(P(`THREAD_INVALID_DEPTH`,`depth must be > 0`));if(s<0||s>=o)return k(P(`THREAD_INVALID_CREST`,`crest must be >= 0 and < toothHalfWidth`));if(c<3)return k(P(`THREAD_TOO_FEW_SECTIONS`,`sectionsPerTurn must be >= 3`));let d=i/r,f=Math.max(2,Math.round(d*c)),p=l?-1:1,m=u?-a:a,h=u?.3:-.3,g=o,_=t.u(new ZT),v=[];for(let e=0;e<=f;e++){let t=p*e*2*Math.PI/c,i=r*Math.abs(t)/(2*Math.PI),a=n*Math.cos(t),o=n*Math.sin(t),l=Math.cos(t),u=Math.sin(t),d=(e,t)=>[a+e*l,o+e*u,i+t],f=s>0?[d(h,-g),d(m,-s),d(m,s),d(h,g)]:[d(h,-g),d(m,0),d(h,g)],y=MP(f.map((e,t)=>_.register(CP(e,f[(t+1)%f.length]))));if(!Ya(y))return y;v.push(_.register(y.value))}return NM(v,{ruled:!0})}catch(e){t.e=e}finally{t.d()}}var TI=1e-9,EI=1e-8,DI=1e-6,OI=([e,t],[n,r],i=DI)=>Math.abs(e-n)<=i&&Math.abs(t-r)<=i,kI=([e,t],[n,r])=>[e+n,t+r],AI=([e,t],[n,r])=>[e-n,t-r],jI=([e,t],n)=>[e*n,t*n],MI=([e,t],[n,r]=[0,0])=>Math.sqrt((e-n)**2+(t-r)**2),NI=([e,t],[n,r]=[0,0])=>(e-n)**2+(t-r)**2;function PI([e,t],[n,r]){return e*r-t*n}var FI=([e,t],[n,r]=[0,0])=>Math.atan2(r*e-t*n,e*n+t*r),II=([e,t],[n,r]=[0,0])=>Math.atan2(r-t,n-e),LI=(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 RI([e,t]){let n=Math.sqrt(e*e+t*t);return n<1e-12?[0,0]:[e/n,t/n]}var zI=(e,t)=>[Math.cos(t)*e,Math.sin(t)*e],BI=([e,t])=>[Math.sqrt(e*e+t*t),Math.atan2(t,e)],VI=([e,t])=>{let n=RI([e,t]);return n[0]===0&&n[1]===0&&i(`normalize2d`,`Cannot normalize zero-length vector`),n};function HI(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(ko(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found ${r===0?0:`2+`} element(s)`))}function UI(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 dD(t);case`face`:return fD(t);case`wire`:return pD(t);case`vertex`:return mD(t)}}let s=e=>{let n=o(e);return t.length===0?n.slice():n.filter(a)},c=()=>UI(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=Dk(n),r=t.get(e);r?r.push(n):t.set(e,[n])}return i(e=>{let n=t.get(Dk(e));return!!n&&n.some(t=>kk(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=>HI(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 WI={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function GI(e){return typeof e==`string`?WI[e]??[0,0,1]:e}function KI(e,t,n){let r=H(),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 qI(e,t){let n=WD(GI(e));return e=>{let r=H(),[i,a]=r.curveParameters(e.wrapped),o=(i+a)/2,{tangent:s}=r.curveTangent(e.wrapped,o),c=WD(s),l=Math.acos(Math.min(1,Math.abs(zD(c,n))));return Math.abs(l-YE*t)<1e-6}}function JI(e){return UI(`edge`,e,JI,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(qI(e,t)),ofLength:(e,t=.001)=>n(n=>Math.abs(Lk(n)-e)<t),ofCurveType:e=>n(t=>Mk(t)===e),parallelTo:(t=`Z`)=>JI(e).inDirection(t,0),atDistance:(e,t=[0,0,0])=>n(KI(e,t,1e-6))}))}function YI(){return JI([])}function XI(e,t){let n=WD(GI(e));return e=>{let r=TO(e),i=Math.acos(Math.min(1,Math.abs(zD(WD(r),n))));return Math.abs(i-YE*t)<1e-6}}function ZI(e){return UI(`face`,e,ZI,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(XI(e,t)),parallelTo:(t=`Z`)=>ZI(e).inDirection(t,0),ofSurfaceType:e=>n(t=>{let n=_O(t);return Ya(n)&&n.value===e}),ofArea:(e,t=.001)=>n(n=>{let r=WM(n);return Ya(r)&&Math.abs(r.value-e)<t}),atDistance:(e,t=[0,0,0])=>n(KI(e,t,1e-6))}))}function QI(){return ZI([])}function $I(e){return UI(`wire`,e,$I,(e,t)=>({isClosed:()=>t(e=>zk(e)),isOpen:()=>t(e=>!zk(e)),ofEdgeCount:e=>t(t=>dD(t).length===e)}))}function eL(){return $I([])}function tL(e,t){return typeof e==`object`&&`_topoKind`in e?e.findUnique(t):typeof e!=`function`&&IE(e)?O(e):e(QI()).findUnique(t)}function nL(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`}function rL(e,t){let n=10**t,r=t<0?e:.01/n+e;return Math.round(r*n)/n}function iL(e){return Math.round(e*100)/100}function aL(e){return Math.round(e*1e5)/1e5}var oL=([e,t])=>`(${iL(e)},${iL(t)})`,sL=(e,t=1e-9)=>{let n=e;return Math.abs(e)<t&&(n=0),n.toFixed(-Math.log10(t))},cL=(e,t=1e-9)=>Array.from(new Map(e.map(([e,n])=>[`[${sL(e,t)},${sL(n,t)}]`,[e,n]])).values()),lL=class{_wrapped;_deleted=!1;constructor(e){this._wrapped=e??TT().createBoundingBox2d(),$T(this,this._wrapped)}get wrapped(){if(this._deleted)throw Error(`This object has been deleted`);return this._wrapped}delete(){this._deleted||(this._deleted=!0,eE(this._wrapped),typeof this._wrapped.delete==`function`&&this._wrapped.delete())}[Symbol.dispose](){this.delete()}get repr(){let[e,t]=this.bounds;return`${oL(e)} - ${oL(t)}`}get bounds(){let{xMin:e,yMin:t,xMax:n,yMax:r}=TT().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){TT().mergeBBox2d(this.wrapped,e.wrapped)}isOut(e){return TT().isBBox2dOut(this.wrapped,e.wrapped)}containsPoint(e){return!TT().isBBox2dOutPoint(this.wrapped,e[0],e[1])}};function uL(e){return new dL(H().deserializeCurve2d(e))}var dL=class e{_wrapped;_deleted=!1;_boundingBox;_firstPoint=null;_lastPoint=null;_firstParameter=null;_lastParameter=null;constructor(e){this._wrapped=H().wrapCurve2dHandle(e),this._boundingBox=null,typeof this._wrapped.delete==`function`&&$T(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`&&(eE(this._wrapped),this._wrapped.delete()))}[Symbol.dispose](){this.delete()}get boundingBox(){if(this._boundingBox)return this._boundingBox;let e=H(),t=e.createBoundingBox2d();return e.addCurveToBBox2d(t,this.wrapped,1e-6),this._boundingBox=new lL(t),this._boundingBox}get repr(){return`${this.geomType} ${oL(this.firstPoint)} - ${oL(this.lastPoint)}`}serialize(){return H().serializeCurve2d(this.wrapped)}value(e){return H().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=H().getCurve2dBounds(this.wrapped).first),this._firstParameter}get lastParameter(){return this._lastParameter===null&&(this._lastParameter=H().getCurve2dBounds(this.wrapped).last),this._lastParameter}get geomType(){return H().getCurve2dType(this.wrapped)}clone(){let t=new e(H().copyCurve2d(this.wrapped));return t._firstPoint=this._firstPoint,t._lastPoint=this._lastPoint,t._firstParameter=this._firstParameter,t._lastParameter=this._lastParameter,t}reverse(){H().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=H().projectPointOnCurve2d(this.wrapped,e[0],e[1]),n=t?t.distance:1/0;return Math.min(n,MI(e,this.firstPoint),MI(e,this.lastPoint))}distanceFromCurve(e){let t;try{t=H().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 nL(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=H().projectPointOnCurve2d(this.wrapped,e[0],e[1]);t?(n=t.distance,r=t.param):i=!0}catch{i=!0}return i?OI(e,this.firstPoint,t)?O(this.firstParameter):OI(e,this.lastPoint,t)?O(this.lastParameter):k(Do(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n===void 0||r===void 0?k(Do(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n>t?k(Do(`POINT_NOT_ON_CURVE`,`Point ${oL(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=H().getCurve2dBounds(this.wrapped);t=(n.last-n.first)*e+n.first}return H().evaluateCurve2dD1(this.wrapped,t).tangent}splitAt(n,r=1e-9){let i=n.map(e=>nL(e)?j(this.parameter(e,r)):e);i=Array.from(new Map(i.map(e=>[rL(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]:H().splitCurve2d(this.wrapped,i).map(t=>new e(t))}},fL=(e,t=1e-4,n=`C0`,r=200)=>new dL(TT().approximateCurve2dAsBSpline(e.wrapped,t,n,r)),pL=e=>(e.geomType!==`BSPLINE_CURVE`&&i(`BSplineToBezier`,`You can only convert a Bspline`),TT().decomposeBSpline2dToBeziers(e.wrapped).map(e=>new dL(e)));function mL(e,t={tolerance:1e-4,continuity:`C0`,maxSegments:300}){let n=TT();return e.flatMap(e=>{let r=e.geomType;if(r===`ELLIPSE`||r===`CIRCLE`&&OI(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 mL(pL(r===`BSPLINE_CURVE`?e:fL(e,t.tolerance,t.continuity,t.maxSegments)),t)})}var hL=(e,t)=>{let n=new dL(H().makeLine2d(e[0],e[1],t[0],t[1]));return OI(n.firstPoint,e)||n.reverse(),n},gL=(e,t,n)=>{let r=new dL(H().makeArc2dThreePoints(e[0],e[1],t[0],t[1],n[0],n[1]));if(!OI(r.firstPoint,e)){let e=H().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new dL(e)}return r},_L=(e,t,n)=>{let r=new dL(H().makeArc2dTangent(e[0],e[1],t[0],t[1],n[0],n[1]));if(!OI(r.firstPoint,e)){let e=H().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new dL(e)}return r},vL=(e,t=[0,0])=>new dL(H().makeCircle2d(t[0],t[1],e,!0)),yL=(e,t,n=[1,0],r=[0,0],i=!0)=>new dL(H().makeEllipse2d(r[0],r[1],e,t,n[0],n[1],i)),bL=(e,t,n,r,i=[0,0],a,o=!0)=>new dL(H().makeEllipseArc2d(i[0],i[1],e,t,n,r,a[0],a[1],o)),xL=(e,t,n)=>{let r=[[e[0],e[1]],...t.map(e=>[e[0],e[1]]),[n[0],n[1]]];return new dL(H().makeBezier2d(r))};function SL(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 dL(H().makeBSpline2d(a,{tolerance:t,smoothing:n,degMax:r,degMin:i,continuity:`C2`})))}catch(e){return k(Do(`BSPLINE_2D_FAILED`,`B-spline approximation failed`,e))}}var CL=(e,t,n,r=!1)=>{let i=jI(kI(e,t),.5),a=MI(n,e)*(r?-1:1);return gL(e,kI(jI(VI(AI(i,n)),a),n),t)},wL=(e,n)=>{let r=TT(),a=e.geomType,[o,s]=n,c=`${aL(o)} ${aL(s)}`;if(a===`LINE`)return`L ${c}`;if(a===`BEZIER_CURVE`){let n=r.getCurve2dBezierPoles(e.wrapped);n||i(`adaptedCurveToPathElem`,`Expected Bezier poles`);let a=n.length-1;if(a===1)return`L ${c}`;if(a===2){let[e,r]=t(n,1);return`Q ${iL(e)} ${iL(r)} ${c}`}if(a===3){let[e,r]=t(n,1),[i,a]=t(n,2);return`C ${iL(e)} ${iL(r)} ${iL(i)} ${iL(a)} ${c}`}}if(a===`CIRCLE`){let t=r.getCurve2dCircleData(e.wrapped);t||i(`adaptedCurveToPathElem`,`Expected circle data`);let{radius:n,isDirect:a}=t,l=r.getCurve2dBounds(e.wrapped),u=(l.last-l.first)*XE,d=u===360?`${aL(o)} ${aL(s+1e-4)}`:c;return`A ${n} ${n} 0 ${Math.abs(u)>180?`1`:`0`} ${a?`1`:`0`} ${d}`}if(a===`ELLIPSE`){let t=r.getCurve2dEllipseData(e.wrapped);t||i(`adaptedCurveToPathElem`,`Expected ellipse data`);let{majorRadius:n,minorRadius:a,xAxisAngle:l,isDirect:u}=t,d=r.getCurve2dBounds(e.wrapped),f=(d.last-d.first)*XE,p=f===360?`${aL(o)} ${aL(s+1e-4)}`:c,m=180-l*XE;return`A ${aL(n)} ${aL(a)} ${aL(m)} ${Math.abs(f)>180?`1`:`0`} ${u?`1`:`0`} ${p}`}i(`adaptedCurveToPathElem`,`Unsupported curve type: ${a}`)},TL=e=>{let t=H(),n=t.createBoundingBox2d();return e.forEach(e=>{t.addCurveToBBox2d(n,e.wrapped,1e-6)}),new lL(n)};function EL(e,t){let n=H();return e.map(e=>EE(n.liftCurve2dToPlane(e.wrapped,[...t.origin],[...t.zDir],[...t.xDir])))}var DL=(e,t)=>{let n=H();return e.map(e=>EE(n.buildEdgeOnSurface(e.wrapped,t)))},OL=(e,t)=>{let n=H();return e.map(e=>t?new dL(n.transformCurve2dGeneral(e.wrapped,t)):e.clone())},kL=(e,t,n=[0,0])=>H().createAffinityGTrsf2d(n[0],n[1],-t[1],t[0],e),AL=e=>H().createTranslationGTrsf2d(e[0],e[1]),jL=(e,t=[0,0],n=`center`)=>n===`center`?H().createMirrorGTrsf2d(e[0],e[1],`point`):H().createMirrorGTrsf2d(0,0,`axis`,t[0],t[1],e[0],e[1]),ML=(e,t=[0,0])=>H().createRotationGTrsf2d(e,t[0],t[1]),NL=(e,t=[0,0])=>H().createScaleGTrsf2d(e,t[0],t[1]);function PL(e,t,n=`original`){let r=H(),i=r.extractSurfaceFromFace(t.wrapped),a=xO(t),o=null;if(n===`original`&&vO(t)!==`PLANE`){if(vO(t)!==`CYLINDRE`)return k(P(`UNSUPPORTED_FACE_TYPE`,`Only planar and cylindrical faces can be unwrapped for sketching`));let e=r.getSurfaceCylinderData(i);if(!e)return k(P(`UNSUPPORTED_FACE_TYPE`,`Could not extract cylinder data from face surface`));e.isDirect||(i=r.reverseSurfaceU(i)),o=kL(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=DL(OL(e,o),i);return o&&o.delete(),O(s)}function FL(e,t){let n=H(),r=new dL(n.extractCurve2dFromEdge(e.wrapped,t.wrapped));return Hk(e)===`backward`&&n.reverseCurve2d(r.wrapped),r}var IL=(e,t=1)=>`${e.bounds[0][0]-t} ${-e.bounds[1][1]-t} ${e.width+2*t} ${e.height+2*t}`,LL=(e,t,n=1)=>`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${IL(t,n)}" fill="none" stroke="black" stroke-width="0.6%" vector-effect="non-scaling-stroke">
|
|
17
|
+
${e}
|
|
18
|
+
</svg>`;function RL(e){let t=e.map(e=>e.wrapped);return DE(H().makeWire(t))}var zL=class e{curves;_boundingBox;_orientation;_guessedOrientation;constructor(e){e.length===0&&i(`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||=TL(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=vA(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]){let i=OL(this.curves,kL(t,n,r));return new e(i)}scale(t,n){let r=n||this.boundingBox.center,i=OL(this.curves,NL(t,r));return new e(i)}rotate(t,n){let r=OL(this.curves,ML(t*YE,n));return new e(r)}translate(t,n=0){let r=nL(t)?t:[t,n],i=OL(this.curves,AL(r));return new e(i)}mirror(t,n=[0,0],r=`center`){let i=OL(this.curves,jL(t,n,r));return new e(i)}sketchOnPlane(e,t){let n=e&&typeof e!=`string`?{...e}:nO(e,t),r=EL(this.curves,n),i=RL(r);for(let e of r)e[Symbol.dispose]();return{wire:i,defaultOrigin:n.origin,defaultDirection:n.zDir}}sketchOnFace(e,t){let n=H(),r=j(PL(this.curves,e,t)),i=RL(r);for(let e of r)e[Symbol.dispose]();n.buildCurves3d(i.wrapped);let a=n.fixWireOnFace(i.wrapped,e.wrapped,1e-9);return i[Symbol.dispose](),{wire:DE(a),baseFace:e}}subFace(e,t){let n=jD(t||[...EO(e)]);return j(PA(this.translate(CO(e,n)).sketchOnFace(e,`original`).wire))}punchHole(e,t,{height:n=null,origin:r=null,draftAngle:i=0}={}){let a=j(tL(t,e)),o=this.subFace(a,r);return j(pO(H().draftPrism(e.wrapped,o.wrapped,a.wrapped,n,i,!1)))}toSVGPathD(){let e=this.clone().mirror([1,0],[0,0],`plane`),t=mL(e.curves).flatMap(e=>wL(e,e.lastPoint)),[n,r]=yA(e.curves).firstPoint;return`M ${aL(n)} ${aL(r)} ${t.join(` `)}${e.isClosed()?` Z`:``}`}toSVGPath(){return`<path d="${this.toSVGPathD()}" />`}toSVGViewBox(e=1){return IL(this.boundingBox,e)}toSVGPaths(){return[this.toSVGPathD()]}toSVG(e=1){return LL(this.toSVGPath(),this.boundingBox,e)}get firstPoint(){return yA(this.curves).firstPoint}get lastPoint(){return bA(this.curves).lastPoint}isInside(e){if(!this.boundingBox.containsPoint(e))return!1;let t=H(),n=hL(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=>OI(t,e,1e-9))||(r.push(e),i++);for(let e of a.segments)e.delete()}),!!(i%2)}finally{n.delete()}}isClosed(){return OI(this.firstPoint,this.lastPoint)}intersects(e){if(this.boundingBox.isOut(e.boundingBox))return!1;let t=H();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}},BL=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)}},VL=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],HL=3,UL=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!==HL)throw Error(`Got v${a} data when expected v${HL}.`);let o=VL[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=VL.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,(HL<<4)+c]),new Uint16Array(n,2,1)[0]=t,new Uint32Array(n,4,1)[0]=e}this._queue=new BL}add(e,t,n=e,r=t){let i=this._pos,a=i>>2,o=this._boxes;return this._indices[a]=a,o[i]=e,o[i+1]=t,o[i+2]=n,o[i+3]=r,this._pos=i+4,e<this.minX&&(this.minX=e),t<this.minY&&(this.minY=t),n>this.maxX&&(this.maxX=n),r>this.maxY&&(this.maxY=r),a}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{numItems:t,minX:n,minY:r,nodeSize:i,_indices:a,_levelBounds:o}=this,s=this.maxX-n||1,c=this.maxY-r||1,l=new Int32Array(t),u=65535,d=u/s,f=u/c;for(let i=0,a=0;i<t;i++){let t=e[a++],o=e[a++],s=e[a++],c=e[a++];l[i]=qL(d*((t+s)/2-n)|0,f*((o+c)/2-r)|0)}GL(l,e,a,0,t-1,i);let p=t*4;for(let t=0,n=0;t<o.length-1;t++){let r=o[t];for(;n<r;){let t=n,o=e[n++],s=e[n++],c=e[n++],l=e[n++];for(let t=1;t<i&&n<r;t++)o=Math.min(o,e[n++]),s=Math.min(s,e[n++]),c=Math.max(c,e[n++]),l=Math.max(l,e[n++]);a[p>>2]=t,e[p++]=o,e[p++]=s,e[p++]=c,e[p++]=l}}this._pos=p}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,l,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){let o=this._boxes,s=this._indices,c=e;for(let e=n;e>0;e--)c=s[c>>2];let l=Math.min(c+(t-e)*this.nodeSize**n,r);if(a===void 0)for(;c<l;c+=4)i.push(s[c>>2]|0);else for(;c<l;c+=4){let e=s[c>>2]|0;a(e,o[c],o[c+1],o[c+2],o[c+3])&&i.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,m=n===1,h=p;for(c.push(a.length-4<<1,0);c.length;){let r=c.ids[0];if(r&1){if(c.pop(),f.push(r>>1),f.length===n)break;continue}c.pop();let l=r>>1,p=l<u,g=Math.min(l+d,WL(l,o));for(let n=l;n<g;n+=4){let r=a[n],o=a[n+1],l=a[n+2],u=a[n+3],d=Math.max(Math.max(r-e,e-l),0),f=Math.max(Math.max(o-t,t-u),0),g=d*d+f*f;if(g>h)continue;let _=s[n>>2]|0;p?(i===void 0||i(_))&&(c.push(_<<1|1,g),m&&g<h&&(h=g)):c.push(_<<1,g)}}return c.clear(),f}};function WL(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 GL(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;KL(e,t,n,d,f)}o.push(i,f,f+1,r)}}function KL(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 qL(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 JL=(e,t,n=1e-9)=>{if(e.boundingBox.isOut(t.boundingBox))return O({intersections:[],commonSegments:[],commonSegmentsPoints:[]});let r=TT(),i,a;try{let o=r.intersectCurves2d(e.wrapped,t.wrapped,n);i=o.points,a=o.segments.map(e=>new dL(e))}catch(e){return k(Do(`INTERSECTION_FAILED`,`Intersections failed between curves`,e))}let o=a.filter(e=>OI(e.firstPoint,e.lastPoint,n)).map(e=>e.firstPoint);o.length&&(i.push(...o),a=a.filter(e=>!OI(e.firstPoint,e.lastPoint,n)));let s=a.flatMap(e=>[e.firstPoint,e.lastPoint]);return O({intersections:i,commonSegments:a,commonSegmentsPoints:s})},YL=(e,t=1e-9)=>{let n=TT(),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(Do(`SELF_INTERSECTION_FAILED`,`Self intersection failed`,e))}return O(r)},XL=(e,n,r)=>{let i=VI(AI(n,e)),a=[i[1],-i[0]],o=[t(a,0)*r,t(a,1)*r];return{firstPoint:kI(e,o),lastPoint:kI(n,o)}},ZL=(e,t)=>{let n=e.geomType,r=TT();if(n===`CIRCLE`){let n=r.getCurve2dCircleData(e.wrapped);if(!n)return hL(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]=VI(AI(e,t));return kI(e,[c*n,c*r])};return{collapsed:!0,firstPoint:n(e.firstPoint),lastPoint:n(e.lastPoint)}}let u=new dL(r.makeCircle2d(i,a,l,s)),d;try{d=r.trimCurve2d(u.wrapped,e.firstParameter,e.lastParameter)}finally{u.delete()}return new dL(d)}if(n===`LINE`){let{firstPoint:n,lastPoint:r}=XL(e.firstPoint,e.lastPoint,t);return hL(n,r)}let i=new dL(r.offsetCurve2d(e.wrapped,t)),a=fL(i);if(i.delete(),j(YL(a)).length){let e=a.firstPoint,t=a.lastPoint;return a.delete(),{collapsed:!0,firstPoint:e,lastPoint:t}}return a};function QL(e,n,r){let i=PI(e.tangentAt(1),n.tangentAt(0));if(Math.abs(i)<1e-10)return null;let a=Math.abs(r)*(i>0?-1:1),o=ZL(e,a),s=ZL(n,a);if(!(o instanceof dL)||!(s instanceof dL))return null;let c=JL(o,s,1e-9);if(!Ya(c))return null;let l=c.value.intersections.at(-1);if(!nL(l))return null;let u=l,d=(e,t)=>{let[n,r]=t.tangentAt(u),i=VI([-r,n]),o=kI(u,jI(i,a)),s=j(e.parameter(o,1e-6));return e.splitAt([s])},f=d(e,o),p=d(n,s);return{first:t(f,0),second:t(p,1),center:u}}function $L(e,t,n){let r=QL(e,t,n);if(!r)return[e,t];let{first:i,second:a,center:o}=r;return[i,CL(i.lastPoint,a.firstPoint,o),a]}function eR(e,t,n){let r=QL(e,t,n);if(!r)return[e,t];let{first:i,second:a}=r;return[i,hL(i.lastPoint,a.firstPoint),a]}function tR(e,n,r){let i=PI(VI(e.tangentAt(1)),VI(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=ZL(e,s),l=ZL(n,s);if(!(c instanceof dL)||!(l instanceof dL))return[e,n];let u=JL(c,l,1e-9);if(!Ya(u))return[e,n];let d=u.value.intersections.at(-1);if(!nL(d))return[e,n];let f=vL(r,d),p=j(JL(e,f)).intersections[0],m=j(JL(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[_,gL(_.lastPoint,e.lastPoint,v.firstPoint),v]}catch{return[e,n]}}var nR=class e{blueprints;_boundingBox;constructor(e){this.blueprints=e,this._boundingBox=null}get repr(){return[`Blueprints`,...this.blueprints.map(e=>e.repr)].join(`
|
|
20
|
+
`)}clone(){return new e(this.blueprints.map(e=>e.clone()))}get boundingBox(){if(!this._boundingBox){let e=new lL;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 IL(this.boundingBox,e)}toSVGPaths(){return this.blueprints.map(e=>e.toSVGPaths())}toSVG(e=1){return LL(this.blueprints.map(e=>e instanceof zL?e.toSVGPath():e.toSVGGroup()).join(`
|
|
21
|
+
`),this.boundingBox,e)}},rR=class e{blueprints;_boundingBox;constructor(e){e.length===0&&i(`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 lL;this.blueprints.forEach(t=>{e.add(t.boundingBox)}),this._boundingBox=e}return this._boundingBox}get repr(){return[`Compound Blueprints`,`-- Outline`,yA(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 yA(this.blueprints).punchHole(e,t,n)}toSVGViewBox(e=1){return IL(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 LL(this.toSVGGroup(),this.boundingBox,e)}},iR=e=>{if(e.length===0)return[];if(e.length===1)return[[jo(e,0,`groupByBoundingBoxOverlap`)]];let t=new UL(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(jo(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(jo(e,n,`groupByBoundingBoxOverlap`)),t.length&&t.forEach(e=>{i[e]=a})}),r},aR=e=>e.map((t,n)=>{let r=jo(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))}}),oR=(e,t)=>e.flatMap(({blueprint:e})=>cR(t.filter(({blueprint:t,isIn:n})=>t===e||n.indexOf(e)!==-1))),sR=(e,t)=>[t.filter(({isIn:e})=>e.length<=1),...cR(aR(e.map(({blueprint:e})=>e)))],cR=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?oR(t,e):sR(n,e)},lR=e=>new nR(iR(e).map(aR).flatMap(cR).map(e=>e.length===1?jo(e,0,`organiseBlueprints`).blueprint:(e.sort((e,t)=>e.isIn.length-t.isIn.length),new rR(e.map(({blueprint:e})=>e))))),uR=e=>e===`symmetric`||typeof e==`number`||Array.isArray(e)&&e.length===2,dR=e=>{let t;t=e?uR(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`?zI(1,n*YE):n;let s;return s=typeof a==`number`?zI(1,a*YE):a,{endTangent:o,startFactor:r,endFactor:i,startTangent:s}};function fR(e,t,n){return e<t?{majorRadius:t,minorRadius:e,rotationAngle:n+90}:{majorRadius:e,minorRadius:t,rotationAngle:n}}function pR(e,t,n,r,i,a,o,s){let c=i*YE,l=e=>MI(s(e)),u=l(zI(n,c)),d=l(zI(r,c+Math.PI/2)),f=VI(s(LI([1,0],c))),[,p]=BI(f),{cx:m,cy:h,startAngle:g,endAngle:_,clockwise:v,rx:y,ry:b}=gR(e,t,u,d,p,a,o),x=bL(y,b,v?g:_,v?_:g,[m,h],f);return v||x.reverse(),x}function mR(e,t,n,r,i){let a=Math.PI*2,o=hR(1,0,e,t),s=hR(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 hR(e,t,n,r){let a=e*n+t*r,o=Math.sqrt((e*e+t*t)*(n*n+r*r));o<1e-12&&i(`radianAngle`,`Cannot compute angle between zero-length vectors`);let s=Math.acos(Math.max(-1,Math.min(1,a/o)));return e*r-t*n<0&&(s=-s),s}function gR([e,t],[n,r],a,o,s,c,l){a<0&&(a=-a),o<0&&(o=-o),(a<1e-10||o<1e-10)&&i(`convertSvgEllipseParams`,`rx and ry cannot be 0`);let u=Math.sin(s),d=Math.cos(s),f=(e-n)/2,p=(t-r)/2,m=(e+n)/2,h=(t+r)/2,g=d*f+u*p,_=d*p-u*f,v=g*g/(a*a)+_*_/(o*o);v>1&&(a*=Math.sqrt(v),o*=Math.sqrt(v));let y=a*o,b=a*_,x=o*g,S=b*b+x*x;S||i(`convertSvgEllipseParams`,`Start point cannot be same as end point`);let C=Math.sqrt(Math.abs((y*y-S)/S));c===l&&(C=-C);let w=C*b/o,ee=-C*x/a,te=d*w-u*ee+m,ne=u*w+d*ee+h,re=(g-w)/a,ie=(g+w)/a,{startAngle:ae,deltaAngle:oe,endAngle:se}=mR(re,(_-ee)/o,ie,(_+ee)/o,l);return{cx:te,cy:ne,startAngle:ae,deltaAngle:oe,endAngle:se,clockwise:l,rx:a,ry:o}}var _R={chamfer:eR,dogbone:tR,fillet:$L};function vR(e,t){if(typeof e==`function`)return e;let n=_R[t];return(t,r)=>n(t,r,e)}var yR=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||i(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)*XE}movePointerTo(e){return this.pendingCurves.length&&i(`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||i(`Sketcher2d.saveCurve`,`No previous curve available for custom corner`),this.pendingCurves.push(...this._nextCorner(t,e)),this._nextCorner=null}lineTo(e){let t=hL(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(zI(e,t*YE))}polarLine(e,t){let[n,r]=zI(e,t*YE);return this.line(n,r)}tangentLine(e){let t=this._requireLastCurve(`Sketcher2d.tangentLine`,`sketch a tangent line`),n=VI(this._convertFromUV(t.tangentAt(1)));return this.line(n[0]*e,n[1]*e)}threePointsArcTo(e,t){let n=gL(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,[a,o]=e,s=(n+a)/2,c=(r+o)/2,l=-(o-r),u=a-n,d=Math.sqrt(l**2+u**2);d<1e-12&&i(`sagittaArcTo`,`Start and end points cannot be identical`);let f=[s+l/d*t,c+u/d*t],p=gL(this._convertToUV(this.pointer),this._convertToUV(f),this._convertToUV(e));return this._saveCurveAndAdvance(p,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=MI(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=_L(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}=fR(t,n,r),l=pR(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=II(e,this.pointer),i=MI(e,this.pointer);return this.ellipseTo(e,i/2,t,r*XE,!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=xL(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}=dR(t),o=this._lastCurve(),s=MI(this.pointer,e)*.25,c;c=r||(o?this._convertFromUV(o.tangentAt(1)):[1,0]),c=VI(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=VI(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||i(`Sketcher2d.customCorner`,`You need a curve defined to fillet the angle`),this._nextCorner=vR(e,t),this}_customCornerLastWithFirst(e,t=`fillet`){if(!e)return;let n=this.pendingCurves.pop(),r=this.pendingCurves.shift();(!n||!r)&&i(`Sketcher2d._customCornerLastWithFirst`,`Not enough curves to close and fillet`),this.pendingCurves.push(...vR(e,t)(n,r))}_closeSketch(){OI(this.pointer,this.firstPoint)||this.lineTo(this.firstPoint)}_closeWithMirror(){OI(this.pointer,this.firstPoint)&&i(`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 dL(H().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}},bR=class extends yR{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new zL(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()}},xR=2*Math.PI;function SR(e){let t=e%xR,n=t<0?t+xR:t;return n<Math.PI?n:n===Math.PI?0:Math.abs(n-xR)}function CR(e){return e.curves.map((t,n)=>({firstCurve:t,secondCurve:vA(e.curves,(n+1)%e.curves.length),point:t.lastPoint}))}function wR(e){let t=t=>wR([...e,t]),n=t=>e.every(e=>e(t));return{shouldKeep:n,when:e=>t(e),inList:e=>t(t=>e.some(e=>OI(e,t.point))),atDistance:(e,n=[0,0])=>t(t=>Math.abs(MI(n,t.point)-e)<1e-9),atPoint:e=>t(t=>OI(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(SR(FI(n,r))-SR(YE*e))<1e-9}),not:e=>{let n=e(wR([]));return t(e=>!n.shouldKeep(e))},either:e=>{let n=e.map(e=>e(wR([])));return t(e=>n.some(t=>t.shouldKeep(e)))},find:e=>CR(e).filter(n)}}function TR(){return wR([])}var ER=(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=bA(r),a=new bR().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()},DR=(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 bR([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()},OR=(e,t)=>OI(e,t,TI);function kR(e){return`${e[0].toFixed(9)},${e[1].toFixed(9)}`}function AR(e,t){let n=kR(e),r=kR(t);return n<r?`${n}|${r}`:`${r}|${n}`}function jR(e){let t=e[0];return t===void 0&&i(`startOfSegment`,`empty segment`),t.firstPoint}function MR(e){let t=e[e.length-1];return t===void 0&&i(`endOfSegment`,`empty segment`),t.lastPoint}function NR(e){return[...e].reverse().map(e=>{let t=e.clone();return t.reverse(),t})}function PR(e){return[...e].reverse().map(NR)}function FR(e){let t=(e.lastParameter+e.firstParameter)/2;return e.value(t)}function IR(e,t){let n=kR(t);for(let r=0;r<e.length;r++){let i=e[r];if(i!==void 0&&kR(i.firstPoint)===n&&OR(t,i.firstPoint))return r}for(let n=0;n<e.length;n++){let r=e[n];if(r!==void 0&&OR(t,r.firstPoint))return n}return-1}function LR(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i];if(a!==void 0&&kR(a.firstPoint)===t&&kR(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 RR(e,t){return t<=0?e:e.slice(t).concat(e.slice(0,t))}function zR(e,t){return RR(e,IR(e,t))}function BR(e,t){let n=kR(t.firstPoint),r=kR(t.lastPoint),a=e=>OR(t.firstPoint,e.firstPoint)&&OR(t.lastPoint,e.lastPoint),o=e=>OR(t.lastPoint,e.firstPoint)&&OR(t.firstPoint,e.lastPoint);function s(e,t,n,r){let i=LR(e,t,n,r);return i===-1?null:RR(e,i)}let c=s(e,n,r,a);if(c!==null)return c;let l=s(e,r,n,o);if(l!==null)return l;let u=NR(e),d=s(u,n,r,a);if(d!==null)return d;let f=s(u,r,n,o);if(f!==null)return f;i(`rotateToStartAtSegment`,`failed to rotate to segment start`)}function*VR(e,t,n){let r=new Set(t.map(kR)),i=new Set(n.map(e=>AR(e.firstPoint,e.lastPoint))),a=e=>r.has(kR(e))?!0:t.some(t=>OR(t,e)),o=(e,t)=>i.has(AR(e,t))?!0:n.some(n=>OR(n.firstPoint,e)&&OR(n.lastPoint,t)||OR(n.firstPoint,t)&&OR(n.lastPoint,e)),s=[];for(let t of e){if(OR(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 HR(e,t,n){return e.filter(e=>{let r=t.filter(t=>OR(t.firstPoint,e)||OR(t.lastPoint,e)),i=r.length%2?r.filter(t=>!(OR(t.firstPoint,e)&&OR(t.lastPoint,e))):r;if(i.length===0||i.length%2)return!1;let a=i.map(e=>n.isInside(FR(e)));return!(a.every(Boolean)||a.every(e=>!e))})}function UR(e,n){let r=[],i=[],a=e.curves.map(()=>[]),o=n.curves.map(()=>[]),s=new UL(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(JL(e,t(n.curves,s),TI/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:cL(r,TI),allCommonSegments:i,firstCurvePoints:a,secondCurvePoints:o}}function WR(e,t){return SA([e,t]).flatMap(([e,t])=>t.length===0?[e]:e.splitAt(t,TI/100))}function GR(e,t,n){return e.some(([e,r])=>e===void 0||r===void 0?!1:OR(e,t)&&OR(r,n)||OR(e,n)&&OR(r,t))}function KR(e,t){let{allIntersections:n,allCommonSegments:r,firstCurvePoints:i,secondCurvePoints:a}=UR(e,t);if(n.length<=1)return null;let o=WR(e.curves,i),s=WR(t.curves,a),c=r.map(e=>[e.firstPoint,e.lastPoint]),l=HR(HR(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=zR(o,e),s=zR(s,e)}else{let e=r[0];if(e===void 0)return null;o=BR(o,e),s=BR(s,e)}let u=Array.from(VR(o,l,r)),d=Array.from(VR(s,l,r)),f=u[0],p=d[0];if(f!==void 0&&p!==void 0){let e=!OR(MR(p),MR(f)),t=r.length>0&&p.length!==1;(e||t)&&(d=PR(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}GR(c,jR(t),MR(t))?h.push([t,`same`]):h.push([t,n])}return h}function qR(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`||!OR(a,n.firstPoint))break;let r=AI(a,i.firstPoint),s=AI(n.lastPoint,n.firstPoint);if(Math.abs(PI(r,s))>1e-9)break;a=n.lastPoint,o++}o>r+1?n.push(hL(i.firstPoint,a)):n.push(i),r=o}return n}function JR(e){let t=e.map(e=>e.firstPoint),n=e.map(e=>e.lastPoint),r=SA([t,n.slice(-1).concat(n.slice(0,-1))]).map(([e,t],n)=>e===void 0||t===void 0||OR(e,t)?null:n).filter(e=>e!==null);if(r.length===0)return[e];let i=SA([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 YR(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 XR(e,t,n,r,i,a,o){let s=[],c=0,l=e[0];if(l!==void 0){let t=FR(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=FR(u),r=n.isInside(e);if(i.secondInside===`keep`&&r||i.secondInside===`remove`&&!r){let e=t;c===1&&(e=NR(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 ZR(e,t,n){let r=KR(e,t);if(r===null)return QR(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=YR(r,i,a);return i=e.segmentsIn,a=e.lastWasSame,e.curves}let s=XR(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=JR(qR(o)).filter(e=>e.length>0).map(e=>new zL(e));if(c.length===0)return null;if(c.length===1){let e=c[0];return e===void 0?null:e}return lR(c)}function QR(e,t){let n=e.curves[0],r=t.curves[0];return{identical:!1,firstCurveInSecond:n!==void 0&&t.isInside(FR(n)),secondCurveInFirst:r!==void 0&&e.isInside(FR(r))}}function $R(e,t){let n=ZR(e,t,{firstInside:`remove`,secondInside:`remove`});return n===null||n instanceof zL||n instanceof nR?n:n.identical?e.clone():n.firstCurveInSecond?t.clone():n.secondCurveInFirst?e.clone():new nR([e,t])}function ez(e,t){let n=ZR(e,t,{firstInside:`remove`,secondInside:`keep`});return n===null||n instanceof zL||n instanceof nR?n:n.identical||n.firstCurveInSecond?null:n.secondCurveInFirst?new nR([new rR([e,t])]):e.clone()}function tz(e,t){let n=ZR(e,t,{firstInside:`keep`,secondInside:`keep`});return n===null||n instanceof zL||n instanceof nR?n:n.identical||n.firstCurveInSecond?e.clone():n.secondCurveInFirst?t.clone():null}var nz=(e,t)=>{if(e instanceof zL&&t instanceof zL){let n=[];return e.curves.forEach(e=>{t.curves.forEach(t=>{let{intersections:r,commonSegmentsPoints:i}=j(JL(e,t));n.push(...r),n.push(...i)})}),n=cL(n),n.length>1}if(e instanceof rR||e instanceof nR)return e.blueprints.some(e=>nz(e,t));if(t instanceof rR||t instanceof nR)return t.blueprints.some(t=>nz(e,t));i(`genericIntersects`,`Unhandled shape combination in genericIntersects`)},rz=(e,t)=>{if(e instanceof rR){if(t instanceof zL)return oz(t,e);if(t instanceof rR)return cz(e,t)}if(t instanceof rR){if(e instanceof zL)return oz(e,t);if(e instanceof rR)return cz(e,t)}if(e instanceof zL&&t instanceof zL)return $R(e,t);i(`genericFuse`,`Unhandled shape combination in genericFuse`)},iz=e=>{let t=new Map,n=[];return e.forEach((r,a)=>{let o;t.has(a)?o=t.get(a):(o={current:r,fusedWith:new Set([a])},n.push(o)),e.slice(a+1).forEach((e,n)=>{let r=o.current,s=a+n+1;if(o.fusedWith.has(s))return;let c=e,l=!1;if(t.has(s)&&(c=t.get(s).current,l=!0),r.boundingBox.isOut(c.boundingBox)||!nz(r,c))return;let u;if(r instanceof nR||c instanceof nR){let e=lz(r,c);e===null&&i(`fuseIntersectingBlueprints`,`fuse2D returned null for non-null inputs`),u=e}else u=rz(r,c);if(!(u instanceof zL||u instanceof rR)){if(u instanceof nR&&u.blueprints.length===2)return;u instanceof nR&&u.blueprints.length===1?u=jo(u.blueprints,0,`fuseIntersectingBlueprints`):u instanceof nR||i(`fuseIntersectingBlueprints`,`Fuse produced unexpected non-blueprint result`)}o.fusedWith.add(s),o.current=u,l||t.set(s,o)})}),lR(n.map(({current:e})=>e).flatMap(e=>az(e)))},az=e=>e instanceof zL?[e]:e instanceof rR?e.blueprints:e instanceof nR?e.blueprints.flatMap(e=>az(e)):[],oz=(e,t)=>{let n=$R(e,jo(t.blueprints,0,`fuseBlueprintWithCompound`)),r=t.blueprints.slice(1).map(t=>ez(t,e));return lR([...az(n),...r.flatMap(e=>az(e))])};function sz(e,t){let n=[];for(let r of e)for(let e of t)n.push([r,e]);return n}var cz=(e,t)=>{let n=jo(e.blueprints,0,`fuseCompoundWithCompound`),r=jo(t.blueprints,0,`fuseCompoundWithCompound`),i=$R(n,r),a=t.blueprints.slice(1).map(e=>ez(e,n)),o=e.blueprints.slice(1).map(e=>ez(e,r)),s=sz(e.blueprints.slice(1),t.blueprints.slice(1)).flatMap(([e,t])=>az(tz(e,t)));return lR([...az(i),...a.flatMap(e=>az(e)),...o.flatMap(e=>az(e)),...s])},lz=(e,t)=>{if(e===null)return t?.clone()??null;if(t===null)return e.clone();if(!(e instanceof nR)&&t instanceof nR)return iz([e,...t.blueprints]);if(!(t instanceof nR)&&e instanceof nR)return iz([t,...e.blueprints]);if(e instanceof nR&&t instanceof nR){let n=lz(jo(e.blueprints,0,`fuse2D`),t);return e.blueprints.slice(1).forEach(e=>{n=lz(e,n)}),n}if(e instanceof rR){if(t instanceof nR)return lz(t,e);if(t instanceof zL)return oz(t,e);if(t instanceof rR)return cz(e,t)}if(t instanceof rR){if(e instanceof nR)return lz(e,t);if(e instanceof zL)return oz(e,t);if(e instanceof rR)return cz(e,t)}return e instanceof zL&&t instanceof zL?$R(e,t):null},uz=e=>{let t=e.flatMap(e=>e===null?[]:e instanceof nR?e.blueprints:e);return t.length===1?jo(t,0,`mergeNonIntersecting`):new nR(t)},dz=(e,t)=>{if(e===null)return null;if(t===null)return e.clone();if(e instanceof nR)return uz(e.blueprints.map(e=>dz(e,t)));if(e instanceof rR){let n=jo(e.blueprints,0,`cut2D`);if(t instanceof zL&&!t.intersects(n))return n.isInside(t.firstPoint)?lR([n,...az(lz(t,new nR(e.blueprints.slice(1))))]):e.clone();{let r=dz(n,t);return e.blueprints.slice(1).forEach(e=>{r=dz(r,e)}),r}}if(t instanceof nR){let n=e;for(let e of t.blueprints)n=dz(n,e);return n}if(t instanceof rR){let n=ez(e,jo(t.blueprints,0,`cut2D`));return t.blueprints.slice(1).forEach(t=>{n=lz(n,tz(t,e))}),n}return ez(e,t)};function fz(e,t){if(e===null||t===null)return null;if(e instanceof zL&&t instanceof zL)return tz(e,t);if(e instanceof nR)return uz(e.blueprints.map(e=>fz(e,t)));if(e instanceof rR){let n=jo(e.blueprints,0,`intersect2D`),r=e.blueprints.slice(1);if(r.length===0)return fz(n,t);let i=fz(n,t);for(let e of r)i=dz(i,e);return i}if(t instanceof nR)return uz(t.blueprints.map(t=>fz(e,t)));if(t instanceof rR){let n=jo(t.blueprints,0,`intersect2D`),r=t.blueprints.slice(1);if(r.length===0)return fz(n,e);let i=fz(n,e);for(let e of r)i=dz(i,e);return i}i(`intersect2D`,`Unhandled Shape2D combination`)}var pz=e(((e,t)=>{t.exports={}}));
|
|
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 mz=0,hz=-3;function gz(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function _z(e,t){this.source=e,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=t,this.destLen=0,this.ltree=new gz,this.dtree=new gz}var vz=new gz,yz=new gz,bz=new Uint8Array(30),xz=new Uint16Array(30),Sz=new Uint8Array(30),Cz=new Uint16Array(30),wz=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Tz=new gz,Ez=new Uint8Array(320);function Dz(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 Oz(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 kz=new Uint16Array(16);function Az(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)kz[i]=a,a+=e.table[i];for(i=0;i<r;++i)t[n+i]&&(e.trans[kz[t[n+i]]++]=i)}function jz(e){e.bitcount--||(e.tag=e.source[e.sourceIndex++],e.bitcount=7);var t=e.tag&1;return e.tag>>>=1,t}function Mz(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 Nz(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 Pz(e,t,n){var r=Mz(e,5,257),i=Mz(e,5,1),a=Mz(e,4,4),o,s,c;for(o=0;o<19;++o)Ez[o]=0;for(o=0;o<a;++o){var l=Mz(e,3,0);Ez[wz[o]]=l}for(Az(Tz,Ez,0,19),s=0;s<r+i;){var u=Nz(e,Tz);switch(u){case 16:var d=Ez[s-1];for(c=Mz(e,2,3);c;--c)Ez[s++]=d;break;case 17:for(c=Mz(e,3,3);c;--c)Ez[s++]=0;break;case 18:for(c=Mz(e,7,11);c;--c)Ez[s++]=0;break;default:Ez[s++]=u;break}}Az(t,Ez,0,r),Az(n,Ez,r,i)}function Fz(e,t,n){for(;;){var r=Nz(e,t);if(r===256)return mz;if(r<256)e.dest[e.destLen++]=r;else{var i,a,o,s;for(r-=257,i=Mz(e,bz[r],xz[r]),a=Nz(e,n),o=e.destLen-Mz(e,Sz[a],Cz[a]),s=o;s<o+i;++s)e.dest[e.destLen++]=e.dest[s]}}}function Iz(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 hz;for(e.sourceIndex+=4,r=t;r;--r)e.dest[e.destLen++]=e.source[e.sourceIndex++];return e.bitcount=0,mz}function Lz(e,t){var n=new _z(e,t),r,i,a;do{switch(r=jz(n),i=Mz(n,2,0),i){case 0:a=Iz(n);break;case 1:a=Fz(n,vz,yz);break;case 2:Pz(n,n.ltree,n.dtree),a=Fz(n,n.ltree,n.dtree);break;default:a=hz}if(a!==mz)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}Oz(vz,yz),Dz(bz,xz,4,3),Dz(Sz,Cz,2,1),bz[28]=0,xz[28]=258;var Rz=Lz;function zz(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 Bz(){this.x1=NaN,this.y1=NaN,this.x2=NaN,this.y2=NaN}Bz.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)},Bz.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))},Bz.prototype.addX=function(e){this.addPoint(e,null)},Bz.prototype.addY=function(e){this.addPoint(null,e)},Bz.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(zz(c[f],l[f],u[f],d[f],g)),f===1&&this.addY(zz(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(zz(c[f],l[f],u[f],d[f],v)),f===1&&this.addY(zz(c[f],l[f],u[f],d[f],v)));var y=(-p-Math.sqrt(_))/(2*m);0<y&&y<1&&(f===0&&this.addX(zz(c[f],l[f],u[f],d[f],y)),f===1&&this.addY(zz(c[f],l[f],u[f],d[f],y)))}}},Bz.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 Vz(){this.commands=[],this.fill=`black`,this.stroke=null,this.strokeWidth=1}Vz.prototype.moveTo=function(e,t){this.commands.push({type:`M`,x:e,y:t})},Vz.prototype.lineTo=function(e,t){this.commands.push({type:`L`,x:e,y:t})},Vz.prototype.curveTo=Vz.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})},Vz.prototype.quadTo=Vz.prototype.quadraticCurveTo=function(e,t,n,r){this.commands.push({type:`Q`,x1:e,y1:t,x:n,y:r})},Vz.prototype.close=Vz.prototype.closePath=function(){this.commands.push({type:`Z`})},Vz.prototype.extend=function(e){if(e.commands)e=e.commands;else if(e instanceof Bz){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)},Vz.prototype.getBoundingBox=function(){for(var e=new Bz,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},Vz.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())},Vz.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},Vz.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},Vz.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 Hz(e){throw Error(e)}function Uz(e,t){e||Hz(t)}var K={fail:Hz,argument:Uz,assert:Uz},Wz=32768,Gz=2147483648,Kz={},q={},J={};function qz(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=qz(1),q.CHAR=function(e){return[e.charCodeAt(0)]},J.CHAR=qz(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=qz(2),q.SHORT=function(e){return e>=Wz&&(e=-(2*Wz-e)),[e>>8&255,e&255]},J.SHORT=qz(2),q.UINT24=function(e){return[e>>16&255,e>>8&255,e&255]},J.UINT24=qz(3),q.ULONG=function(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]},J.ULONG=qz(4),q.LONG=function(e){return e>=Gz&&(e=-(2*Gz-e)),[e>>24&255,e>>16&255,e>>8&255,e&255]},J.LONG=qz(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=qz(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=qz(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=qz(3),q.NUMBER32=function(e){return[29,e>>24&255,e>>16&255,e>>8&255,e&255]},J.NUMBER32=qz(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,Kz.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)},Kz.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 Jz={"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ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ`};Kz.MACSTRING=function(e,t,n,r){var i=Jz[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 Yz=typeof WeakMap==`function`&&new WeakMap,Xz,Zz=function(e){if(!Xz)for(var t in Xz={},Jz)Xz[t]=new String(t);var n=Xz[e];if(n!==void 0){if(Yz){var r=Yz.get(n);if(r!==void 0)return r}var i=Jz[e];if(i!==void 0){for(var a={},o=0;o<i.length;o++)a[i.charCodeAt(o)]=o+128;return Yz&&Yz.set(n,a),a}}};q.MACSTRING=function(e,t){var n=Zz(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 Qz(e){return e>=-128&&e<=127}function $z(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 eB(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(!Qz(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 tB(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(o===0||Qz(o)&&a+1<i&&Qz(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?$z(e,t,n):r>=-128&&r<=127?eB(e,t,n):tB(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 nB=typeof WeakMap==`function`&&new WeakMap;q.CHARSTRING=function(e){if(nB){var t=nB.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 nB&&nB.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 rB(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)}}rB.prototype.encode=function(){return q.TABLE(this)},rB.prototype.sizeOf=function(){return J.TABLE(this)};function iB(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 aB(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 oB(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 sB(e){e.format===1?rB.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:1}].concat(iB(`glyph`,e.glyphs))):e.format===2?rB.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:2}].concat(oB(`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.`)}sB.prototype=Object.create(rB.prototype),sB.prototype.constructor=sB;function cB(e){rB.call(this,`scriptListTable`,oB(`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 rB(`scriptTable`,[{name:`defaultLangSys`,type:`TABLE`,value:new rB(`defaultLangSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:r.reqFeatureIndex}].concat(iB(`featureIndex`,r.featureIndexes)))}].concat(oB(`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 rB(`langSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:n.reqFeatureIndex}].concat(iB(`featureIndex`,n.featureIndexes)))}]})))}]}))}cB.prototype=Object.create(rB.prototype),cB.prototype.constructor=cB;function lB(e){rB.call(this,`featureListTable`,oB(`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 rB(`featureTable`,[{name:`featureParams`,type:`USHORT`,value:n.featureParams}].concat(iB(`lookupListIndex`,n.lookupListIndexes)))}]}))}lB.prototype=Object.create(rB.prototype),lB.prototype.constructor=lB;function uB(e,t){rB.call(this,`lookupListTable`,aB(`lookup`,e,function(e){var n=t[e.lookupType];return K.assert(!!n,`Unable to write GSUB lookup type `+e.lookupType+` tables.`),new rB(`lookupTable`,[{name:`lookupType`,type:`USHORT`,value:e.lookupType},{name:`lookupFlag`,type:`USHORT`,value:e.lookupFlag}].concat(aB(`subtable`,e.subtables,n)))}))}uB.prototype=Object.create(rB.prototype),uB.prototype.constructor=uB;var Y={Table:rB,Record:rB,Coverage:sB,ScriptList:cB,FeatureList:lB,LookupList:uB,ushortList:iB,tableList:aB,recordList:oB};function dB(e,t){return e.getUint8(t)}function fB(e,t){return e.getUint16(t,!1)}function pB(e,t){return e.getInt16(t,!1)}function mB(e,t){return e.getUint32(t,!1)}function hB(e,t){return e.getInt16(t,!1)+e.getUint16(t+2,!1)/65535}function gB(e,t){for(var n=``,r=t;r<t+4;r+=1)n+=String.fromCharCode(e.getInt8(r));return n}function _B(e,t,n){for(var r=0,i=0;i<n;i+=1)r<<=8,r+=e.getUint8(t+i);return r}function vB(e,t,n){for(var r=[],i=t;i<n;i+=1)r.push(e.getUint8(i));return r}function yB(e){for(var t=``,n=0;n<e.length;n+=1)t+=String.fromCharCode(e[n]);return t}var bB={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=mB(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,e},X.prototype.parseOffset32=X.prototype.parseULong,X.prototype.parseFixed=function(){var e=hB(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=mB(this.data,this.offset+this.relativeOffset+4);return e-=2082844800,this.relativeOffset+=8,e},X.prototype.parseVersion=function(e){var t=fB(this.data,this.offset+this.relativeOffset),n=fB(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+=bB[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 xB={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(xB),langSysRecords:X.recordList({tag:X.tag,langSys:X.pointer(xB)})})}))||[]},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:dB,getCard8:dB,getUShort:fB,getCard16:fB,getShort:pB,getULong:mB,getFixed:hB,getTag:gB,getOffset:_B,getBytes:vB,bytesToString:yB,Parser:X};function SB(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 CB(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 wB(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)SB(n,s);else if(n.format===4)CB(n,s,e,t,r);else throw Error(`Only format 4 and 12 cmap tables are supported (found format `+n.format+`).`);return n}function TB(e,t,n){e.segments.push({end:t,start:t,delta:-(t-n),offset:0,glyphIndex:n})}function EB(e){e.segments.push({end:65535,start:65535,delta:1,offset:0})}function DB(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)TB(i,a.unicodes[o],n);i.segments=i.segments.sort(function(e,t){return e.start-t.start})}EB(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 OB={parse:wB,make:DB},kB=`.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(`,`),AB=`................................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(`.`),jB=`................................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(`.`),MB=`.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 NB(e){this.font=e}NB.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 PB(e){this.cmap=e}PB.prototype.charToGlyphIndex=function(e){return this.cmap.glyphIndexMap[e.codePointAt(0)]||0};function FB(e,t){this.encoding=e,this.charset=t}FB.prototype.charToGlyphIndex=function(e){var t=e.codePointAt(0),n=this.encoding[t];return this.charset.indexOf(n)};function IB(e){switch(e.version){case 1:this.names=MB.slice();break;case 2:this.names=Array(e.numberOfGlyphs);for(var t=0;t<e.numberOfGlyphs;t++)e.glyphNameIndex[t]<MB.length?this.names[t]=MB[e.glyphNameIndex[t]]:this.names[t]=e.names[e.glyphNameIndex[t]-MB.length];break;case 2.5:this.names=Array(e.numberOfGlyphs);for(var n=0;n<e.numberOfGlyphs;n++)this.names[n]=MB[n+e.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}IB.prototype.nameToGlyphIndex=function(e){return this.names.indexOf(e)},IB.prototype.glyphIndexToName=function(e){return this.names[e]};function LB(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 RB(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 zB(e,t){t.lowMemory?RB(e):LB(e)}function BB(e,t,n,r,i){e.beginPath(),e.moveTo(t,n),e.lineTo(r,i),e.stroke()}var VB={line:BB};function HB(e,t){var n=t||new Vz;return{configurable:!0,get:function(){return typeof n==`function`&&(n=n()),n},set:function(e){n=e}}}function UB(e){this.bindConstructorValues(e)}UB.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",HB(this,e.path))},UB.prototype.addUnicode=function(e){this.unicodes.length===0&&(this.unicode=e),this.unicodes.push(e)},UB.prototype.getBoundingBox=function(){return this.path.getBoundingBox()},UB.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 Vz,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},UB.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},UB.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},UB.prototype.draw=function(e,t,n,r,i){this.getPath(t,n,r,i).draw(e)},UB.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)},UB.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`,VB.line(e,t,-1e4,t,1e4),VB.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`,VB.line(e,t+a*i,-1e4,t+a*i,1e4),VB.line(e,t+s*i,-1e4,t+s*i,1e4),VB.line(e,-1e4,n+-o*i,1e4,n+-o*i),VB.line(e,-1e4,n+-c*i,1e4,n+-c*i),e.strokeStyle=`green`,VB.line(e,t+l*i,-1e4,t+l*i,1e4)};function WB(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 GB(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}GB.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]},GB.prototype.push=function(e,t){this.glyphs[e]=t,this.length++};function KB(e,t){return new UB({index:t,font:e})}function qB(e,t,n,r,i,a){return function(){var o=new UB({index:t,font:e});return o.path=function(){n(o,r,i);var t=a(e.glyphs,o);return t.unitsPerEm=e.unitsPerEm,t},WB(o,`xMin`,`_xMin`),WB(o,`xMax`,`_xMax`),WB(o,`yMin`,`_yMin`),WB(o,`yMax`,`_yMax`),o}}function JB(e,t,n,r){return function(){var i=new UB({index:t,font:e});return i.path=function(){var t=n(e,i,r);return t.unitsPerEm=e.unitsPerEm,t},i}}var YB={GlyphSet:GB,glyphLoader:KB,ttfGlyphLoader:qB,cffGlyphLoader:JB};function XB(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(!XB(e[n],t[n]))return!1;return!0}else return!1}function ZB(e){return e.length<1240?107:e.length<33900?1131:32768}function QB(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 $B(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 eV(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 tV(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 nV(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 tV(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 rV(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 iV(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(nV(r,o))}return rV(i)}function aV(e,t){return t=t<=390?kB[t]:e[t-391],t}function oV(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=aV(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=aV(n,i)),r[o.name]=i}return r}function sV(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 cV=[{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`}],lV=[{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 uV(e,t){return oV(iV(e,0,e.byteLength),cV,t)}function dV(e,t,n,r){return oV(iV(e,t,n),lV,r)}function fV(e,t,n,r){for(var i=[],a=0;a<n.length;a+=1){var o=uV(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=dV(e,c+t,s,r);o._defaultWidthX=l.defaultWidthX,o._nominalWidthX=l.nominalWidthX,l.subrs!==0&&(o._subrs=QB(e,c+l.subrs+t).objects,o._subrsBias=ZB(o._subrs)),o._privateDict=l}i.push(o)}return i}function pV(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(aV(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(aV(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(aV(r,i)),i+=1}else throw Error(`Unknown charset format `+c);return s}function mV(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 FB(i,n)}function hV(e,t,n){var r,i,a,o,s=new Vz,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 gV(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 _V(e,t,n,r){n.tables.cff={};var i=QB(e,QB(e,sV(e,t).endOffset,Z.bytesToString).endOffset),a=QB(e,i.endOffset,Z.bytesToString);n.gsubrs=QB(e,a.endOffset).objects,n.gsubrsBias=ZB(n.gsubrs);var o=fV(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=fV(e,t,QB(e,c).objects,a.objects);s._fdArray=u,l+=t,s._fdSelect=gV(e,l,n.numGlyphs,u.length)}var d=t+s.private[1],f=dV(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=QB(e,d+f.subrs).objects,n.subrsBias=ZB(n.subrs));var p;r.lowMemory?(p=$B(e,t+s.charStrings),n.nGlyphs=p.offsets.length):(p=QB(e,t+s.charStrings),n.nGlyphs=p.objects.length);var m=pV(e,t+s.charset,n.nGlyphs,a.objects);if(s.encoding===0?n.cffEncoding=new FB(AB,m):s.encoding===1?n.cffEncoding=new FB(jB,m):n.cffEncoding=mV(e,t+s.encoding,m),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new YB.GlyphSet(n),r.lowMemory)n._push=function(r){var i=eV(r,p.offsets,e,t+s.charStrings);n.glyphs.push(r,YB.cffGlyphLoader(n,r,hV,i))};else for(var h=0;h<n.nGlyphs;h+=1){var g=p.objects[h];n.glyphs.push(h,YB.cffGlyphLoader(n,h,hV,g))}}function vV(e,t){var n,r=kB.indexOf(e);return r>=0&&(n=r),r=t.indexOf(e),r>=0?n=r+kB.length:(n=kB.length+t.length,t.push(e)),n}function yV(){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 bV(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 xV(e,t,n){for(var r={},i=0;i<e.length;i+=1){var a=e[i],o=t[a.name];o!==void 0&&!XB(o,a.value)&&(a.type===`SID`&&(o=vV(o,n)),r[a.op]={name:a.name,type:a.type,value:o})}return r}function SV(e,t){var n=new Y.Record(`Top DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=xV(cV,e,t),n}function CV(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 wV(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 TV(){return new Y.Record(`Global Subr INDEX`,[{name:`subrs`,type:`INDEX`,value:[]}])}function EV(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=vV(i,t);n.fields.push({name:`glyph_`+r,type:`SID`,value:a})}return n}function DV(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 OV(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=DV(r);t.charStrings.push({name:r.name,type:`CHARSTRING`,value:i})}return t}function kV(e,t){var n=new Y.Record(`Private DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=xV(lV,e,t),n}function AV(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=yV(),n.nameIndex=bV([t.postScriptName]);var u=SV(i,l);return n.topDictIndex=CV(u),n.globalSubrIndex=TV(),n.charsets=EV(o,l),n.charStringsIndex=OV(e),n.privateDict=kV(a,l),n.stringIndex=wV(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=SV(i,l),n.topDictIndex=CV(u),n}var jV={parse:_V,make:AV};function MV(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 NV(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 PV={parse:MV,make:NV};function FV(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 IV(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 LV={parse:FV,make:IV};function RV(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 zV(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 BV(e,t,n,r,i,a,o){o.lowMemory?zV(e,t,n,r,i):RV(t,n,r,i,a)}function VV(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 HV={parse:BV,make:VV};function UV(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 WV(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 GV={make:UV,parse:WV};function KV(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 qV(e){return new Y.Table(`maxp`,[{name:`version`,type:`FIXED`,value:20480},{name:`numGlyphs`,type:`USHORT`,value:e}])}var JV={parse:KV,make:qV},YV=[`copyright`,`fontFamily`,`fontSubfamily`,`uniqueID`,`fullName`,`version`,`postScriptName`,`trademark`,`manufacturer`,`designer`,`description`,`manufacturerURL`,`designerURL`,`license`,`licenseURL`,`reserved`,`preferredFamily`,`preferredSubfamily`,`compatibleFullName`,`sampleText`,`postScriptFindFontName`,`wwsFamily`,`wwsSubfamily`],XV={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`},ZV={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},QV={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 $V(e,t,n){switch(e){case 0:if(t===65535)return`und`;if(n)return n[t];break;case 1:return XV[t];case 3:return QV[t]}}var eH=`utf-16`,tH={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`},nH={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 rH(e,t,n){switch(e){case 0:return eH;case 1:return nH[n]||tH[t];case 3:if(t===1||t===10)return eH;break}}function iH(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=YV[f]||f,m=i.parseUShort(),h=i.parseUShort(),g=$V(l,d,n),_=rH(l,u,d);if(_!==void 0&&g!==void 0){var v=void 0;if(v=_===eH?Kz.UTF16(e,s+h,m):Kz.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 aH(e){var t={};for(var n in e)t[e[n]]=parseInt(n);return t}function oH(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 sH(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 cH(e,t){var n=sH(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 lH(e,t){var n,r=[],i={},a=aH(YV);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=aH(XV),l=aH(QV),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=ZV[_],y=rH(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=cH(b,d);u.push(oH(g,v,_,n,b.length,x));var S=l[m];if(S!==void 0){var C=q.UTF16(h),w=cH(C,d);u.push(oH(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 uH={parse:iH,make:lH},dH=[{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 fH(e){for(var t=0;t<dH.length;t+=1){var n=dH[t];if(e>=n.begin&&e<n.end)return t}return-1}function pH(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 mH(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 hH={parse:pH,make:mH,unicodeRanges:dH,getUnicodeRange:fH};function gH(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=MB.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]>=MB.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 _H(){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 vH={parse:gH,make:_H},yH=Array(9);yH[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.`)},yH[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()}},yH[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()}},yH[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 bH={sequenceIndex:X.uShort,lookupListIndex:X.uShort};yH[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,bH)}})};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,bH)}})};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,bH)}}K.assert(!1,`0x`+e.toString(16)+`: lookup type 5 format must be 1, 2 or 3.`)},yH[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(bH)}})};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(bH)}})};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(bH)};K.assert(!1,`0x`+e.toString(16)+`: lookup type 6 format must be 1, 2 or 3.`)},yH[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:yH[t].call(n)}},yH[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 xH(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(yH)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(yH),variations:n.parseFeatureVariationsList()}}var SH=Array(9);SH[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)))},SH[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))})))},SH[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))})))},SH[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)))}))})))},SH[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 CH(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,SH)}])}var wH={parse:xH,make:CH};function TH(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]=Kz.UTF8(e,t+c,l)}return a}function EH(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 DH={parse:TH,make:EH};function OH(e){return Math.log(e)/Math.log(2)|0}function kH(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 AH(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 jH(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**OH(t.numTables);t.searchRange=16*n,t.entrySelector=OH(n),t.rangeShift=t.numTables*16-t.searchRange;for(var r=[],i=[],a=t.sizeOf()+AH().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=AH(s.tableName,kH(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 MH(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 NH(e){for(var t=0,n=0;n<e.length;n+=1)t+=e[n];return t/e.length}function PH(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 _=hH.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:NH(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=PV.make({flags:3,unitsPerEm:e.unitsPerEm,xMin:y.xMin,yMin:y.yMin,xMax:y.xMax,yMax:y.yMax,lowestRecPPEM:3,createdTimestamp:e.createdTimestamp}),x=LV.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=JV.make(e.glyphs.length),C=hH.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:MH(e,`xyvw`,{yMax:Math.round(y.ascender/2)}).yMax,sCapHeight:MH(e,`HIKLEFJMNTZBDPRAGOQSUVWXY`,y).yMax,usDefaultChar:e.hasChar(` `)?32:0,usBreakChar:e.hasChar(` `)?32:0},e.tables.os2)),w=HV.make(e.glyphs),ee=OB.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=uH.make(ae,se),le=se.length>0?GV.make(se):void 0,ue=vH.make(),de=jV.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?DH.make(e.metas):void 0,pe=[b,x,S,C,ce,ee,ue,de,w];le&&pe.push(le),e.tables.gsub&&pe.push(wH.make(e.tables.gsub)),fe&&pe.push(fe);for(var me=jH(pe),he=kH(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 FH={make:jH,fontToTable:PH,computeCheckSum:kH};function IH(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 LH(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 RH(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 zH(e,t){this.font=e,this.tableName=t}zH.prototype={searchTag:IH,binSearch:LH,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=IH(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=IH(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=RH(e.ranges,t);return n?n.classId:0}},getCoverageIndex:function(e,t){switch(e.format){case 1:var n=LH(e.glyphs,t);return n>=0?n:-1;case 2:var r=RH(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 BH(e){zH.call(this,e,`gpos`)}BH.prototype=zH.prototype,BH.prototype.init=function(){var e=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(e)},BH.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},BH.prototype.getKerningTables=function(e,t){if(this.font.tables.gpos)return this.getLookupTables(e,t,`kern`,2)};function VH(e){zH.call(this,e,`gsub`)}function HH(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 UH(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}VH.prototype=zH.prototype,VH.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:`DFLT`,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}},VH.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},VH.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},VH.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},VH.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},VH.prototype.addSingle=function(e,t,n,r){var i=this.getLookupTables(n,r,e,1,!0)[0],a=UH(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},VH.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=UH(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},VH.prototype.addAlternate=function(e,t,n,r){var i=this.getLookupTables(n,r,e,3,!0)[0],a=UH(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},VH.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(HH(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])},VH.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)}},VH.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 WH(){return typeof window<`u`}function GH(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 KH(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 qH(e,t){if(!e)throw t}function JH(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 YH(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=JH(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=JH(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 XH(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 ZH(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 QH(e){var t=new Vz;if(!e)return t;for(var n=ZH(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 $H(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=XH(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=XH([s],c)[0],c.dx=o.x-s.x,c.dy=o.y-s.y,a=XH(i.points,c)}t.points=t.points.concat(a)}}return QH(t.points)}function eU(e,t,n,r){for(var i=new YB.GlyphSet(r),a=0;a<n.length-1;a+=1){var o=n[a];o===n[a+1]?i.push(a,YB.glyphLoader(r,a)):i.push(a,YB.ttfGlyphLoader(r,a,YH,e,t+o,$H))}return i}function tU(e,t,n,r){var i=new YB.GlyphSet(r);return r._push=function(a){var o=n[a];o===n[a+1]?i.push(a,YB.glyphLoader(r,a)):i.push(a,YB.ttfGlyphLoader(r,a,YH,e,t+o,$H))},i}function nU(e,t,n,r,i){return i.lowMemory?tU(e,t,n,r):eU(e,t,n,r)}var rU={getPath:QH,parse:nU},iU,aU,oU,sU;function cU(e){this.font=e,this.getCommands=function(e){return rU.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function lU(e){return e}function uU(e){return Math.sign(e)*Math.round(Math.abs(e))}function dU(e){return Math.sign(e)*Math.round(Math.abs(e*2))/2}function fU(e){return Math.sign(e)*(Math.round(Math.abs(e)+.5)-.5)}function pU(e){return Math.sign(e)*Math.ceil(Math.abs(e))}function mU(e){return Math.sign(e)*Math.floor(Math.abs(e))}var hU=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},gU={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){gU.setRelative(e,e,(c+l)/2,r,!0);return}gU.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}},_U={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){_U.setRelative(e,e,(c+l)/2,r,!0);return}_U.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(gU),Object.freeze(_U);function vU(e,t){this.x=e,this.y=t,this.axis=void 0,this.slope=t/e,this.normalSlope=-e/t,Object.freeze(this)}vU.prototype.distance=function(e,t,n,r){return this.x*gU.distance(e,t,n,r)+this.y*_U.distance(e,t,n,r)},vU.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)},vU.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},vU.prototype.touch=function(e){e.xTouched=!0,e.yTouched=!0};function yU(e,t){var n=Math.sqrt(e*e+t*t);return e/=n,t/=n,e===1&&t===0?gU:e===0&&t===1?_U:new vU(e,t)}function bU(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)}bU.prototype.nextTouched=function(e){for(var t=this.nextPointOnContour;!e.touched(t)&&t!==this;)t=t.nextPointOnContour;return t},bU.prototype.prevTouched=function(e){for(var t=this.prevPointOnContour;!e.touched(t)&&t!==this;)t=t.prevPointOnContour;return t};var xU=Object.freeze(new bU(0,0)),SU={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function CU(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=gU,this.round=uU}}cU.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){CU.prototype=SU,i=this._fpgmState=new CU(`fpgm`,n.tables.fpgm),i.funcs=[],i.font=n,exports.DEBUG&&(console.log(`---EXEC FPGM---`),i.step=-1);try{aU(i)}catch(e){console.log(`Hinting error in FPGM:`+e),this._errorState=3;return}}CU.prototype=i,r=this._prepState=new CU(`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{aU(r)}catch(e){this._errorState<2&&console.log(`Hinting error in PREP:`+e),this._errorState=2}}if(!(this._errorState>1))try{return oU(e,r)}catch(e){this._errorState<1&&(console.log(`Hinting error:`+e),console.log(`Note: further hinting errors are silenced`)),this._errorState=1;return}}},oU=function(e,t){var n=t.ppem/t.font.unitsPerEm,r=n,i=e.components,a,o,s;if(CU.prototype=t,!i)s=new CU(`glyf`,e.instructions),exports.DEBUG&&(console.log(`---EXEC GLYPH---`),s.step=-1),sU(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 CU(`glyf`,d.instructions),exports.DEBUG&&(console.log(`---EXEC COMP `+l+`---`),s.step=-1),sU(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 CU(`glyf`,e.instructions),s.gZone=s.z0=s.z1=s.z2=o,s.contours=a,o.push(new bU(0,0),new bU(Math.round(e.advanceWidth*n),0)),exports.DEBUG&&(console.log(`---EXEC COMPOSITE---`),s.step=-1),aU(s),o.length-=2)}return o},sU=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 bU(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 bU(0,0),new bU(Math.round(e.advanceWidth*n),0)),aU(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)}}},aU=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=iU[t[e.ip]],!r)throw Error(`unknown instruction: 0x`+Number(t[e.ip]).toString(16));r(e)}}};function wU(e){for(var t=e.tZone=Array(e.gZone.length),n=0;n<t.length;n++)t[n]=new bU(0,0)}function TU(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 EU(e,t){exports.DEBUG&&console.log(t.step,`SVTCA[`+e.axis+`]`),t.fv=t.pv=t.dpv=e}function DU(e,t){exports.DEBUG&&console.log(t.step,`SPVTCA[`+e.axis+`]`),t.pv=t.dpv=e}function OU(e,t){exports.DEBUG&&console.log(t.step,`SFVTCA[`+e.axis+`]`),t.fv=e}function kU(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=yU(s,c)}function AU(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=yU(s,c)}function jU(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.pv=e.dpv=yU(r,n)}function MU(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.fv=yU(r,n)}function NU(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 PU(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 FU(e){e.fv=e.pv,exports.DEBUG&&console.log(e.step,`SFVTPV[]`)}function IU(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 LU(e){e.rp0=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP0[]`,e.rp0)}function RU(e){e.rp1=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP1[]`,e.rp1)}function zU(e){e.rp2=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP2[]`,e.rp2)}function BU(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP0[]`,t),e.zp0=t,t){case 0:e.tZone||wU(e),e.z0=e.tZone;break;case 1:e.z0=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function VU(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP1[]`,t),e.zp1=t,t){case 0:e.tZone||wU(e),e.z1=e.tZone;break;case 1:e.z1=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function HU(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP2[]`,t),e.zp2=t,t){case 0:e.tZone||wU(e),e.z2=e.tZone;break;case 1:e.z2=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function UU(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||wU(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 WU(e){e.loop=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SLOOP[]`,e.loop)}function GU(e){exports.DEBUG&&console.log(e.step,`RTG[]`),e.round=uU}function KU(e){exports.DEBUG&&console.log(e.step,`RTHG[]`),e.round=fU}function qU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SMD[]`,t),e.minDis=t/64}function JU(e){exports.DEBUG&&console.log(e.step,`ELSE[]`),TU(e,!1)}function YU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`JMPR[]`,t),e.ip+=t-1}function XU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCVTCI[]`,t),e.cvCutIn=t/64}function ZU(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DUP[]`),t.push(t[t.length-1])}function QU(e){exports.DEBUG&&console.log(e.step,`POP[]`),e.stack.pop()}function $U(e){exports.DEBUG&&console.log(e.step,`CLEAR[]`),e.stack.length=0}function eW(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 tW(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DEPTH[]`),t.push(t.length)}function nW(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++)aU(e),exports.DEBUG&&console.log(++e.step,o+1<r?`next loopcall`:`done loopcall`,o);e.ip=i,e.prog=a}function rW(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],aU(e),e.ip=n,e.prog=r,exports.DEBUG&&console.log(++e.step,`returning from`,t)}function iW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CINDEX[]`,n),t.push(t[t.length-n])}function aW(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 oW(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 sW(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,xU);e&&(o=t.round(o)),i.setRelative(r,xU,o,a),i.touch(r),t.rp0=t.rp1=n}function cW(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 lW(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 uW(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 dW(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 fW(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 pW(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 mW(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 hW(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 gW(e){exports.DEBUG&&console.log(e.step,`RTDG[]`),e.round=dU}function _W(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,xU);e&&(Math.abs(l-c)<t.cvCutIn&&(l=c),l=t.round(l)),o.setRelative(a,xU,l,s),t.zp0===0&&(a.xo=a.x,a.yo=a.y),o.touch(a),t.rp0=t.rp1=i}function vW(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 yW(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 bW(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 xW(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 SW(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 CW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`RCVT`,n),t.push(e.cvt[n]*64)}function wW(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,xU,e,!1)*64)}function TW(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 EW(e){exports.DEBUG&&console.log(e.step,`MPPEM[]`),e.stack.push(e.ppem)}function DW(e){exports.DEBUG&&console.log(e.step,`FLIPON[]`),e.autoFlip=!0}function OW(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 kW(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 AW(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 jW(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 MW(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 NW(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 PW(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 FW(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 IW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`IF[]`,t),t||(TU(e,!0),exports.DEBUG&&console.log(e.step,`EIF[]`))}function LW(e){exports.DEBUG&&console.log(e.step,`EIF[]`)}function RW(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 zW(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 BW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NOT[]`,n),t.push(+!n)}function VW(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 HW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDB[]`,t),e.deltaBase=t}function UW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDS[]`,t),e.deltaShift=.5**t}function WW(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 GW(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 KW(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 qW(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 JW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`ABS[]`,n),t.push(Math.abs(n))}function YW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NEG[]`,n),t.push(-n)}function XW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`FLOOR[]`,n),t.push(Math.floor(n/64)*64)}function ZW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CEILING[]`,n),t.push(Math.ceil(n/64)*64)}function QW(e,t){var n=t.stack,r=n.pop();exports.DEBUG&&console.log(t.step,`ROUND[]`),n.push(t.round(r/64)*64)}function $W(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 eG(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 tG(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SROUND[]`,t),e.round=hU;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 nG(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`S45ROUND[]`,t),e.round=hU;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 rG(e){exports.DEBUG&&console.log(e.step,`ROFF[]`),e.round=lU}function iG(e){exports.DEBUG&&console.log(e.step,`RUTG[]`),e.round=pU}function aG(e){exports.DEBUG&&console.log(e.step,`RDTG[]`),e.round=mU}function oG(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANCTRL[]`,t)}function sG(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=yU(s,c)}function cG(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 lG(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 uG(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 dG(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 fG(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANTYPE[]`,t)}function pG(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 mG(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 hG(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)}iU=[EU.bind(void 0,_U),EU.bind(void 0,gU),DU.bind(void 0,_U),DU.bind(void 0,gU),OU.bind(void 0,_U),OU.bind(void 0,gU),kU.bind(void 0,0),kU.bind(void 0,1),AU.bind(void 0,0),AU.bind(void 0,1),jU,MU,NU,PU,FU,IU,LU,RU,zU,BU,VU,HU,UU,WU,GU,KU,qU,JU,YU,XU,void 0,void 0,ZU,QU,$U,eW,tW,iW,aW,void 0,void 0,void 0,nW,rW,oW,void 0,sW.bind(void 0,0),sW.bind(void 0,1),cW.bind(void 0,_U),cW.bind(void 0,gU),lW.bind(void 0,0),lW.bind(void 0,1),uW.bind(void 0,0),uW.bind(void 0,1),dW.bind(void 0,0),dW.bind(void 0,1),fW,pW,mW.bind(void 0,0),mW.bind(void 0,1),hW,gW,_W.bind(void 0,0),_W.bind(void 0,1),vW,yW,bW,xW,SW,CW,wW.bind(void 0,0),wW.bind(void 0,1),void 0,TW.bind(void 0,0),TW.bind(void 0,1),EW,void 0,DW,void 0,void 0,OW,kW,AW,jW,MW,NW,PW,FW,IW,LW,RW,zW,BW,VW.bind(void 0,1),HW,UW,WW,GW,KW,qW,JW,YW,XW,ZW,QW.bind(void 0,0),QW.bind(void 0,1),QW.bind(void 0,2),QW.bind(void 0,3),void 0,void 0,void 0,void 0,$W,VW.bind(void 0,2),VW.bind(void 0,3),eG.bind(void 0,1),eG.bind(void 0,2),eG.bind(void 0,3),tG,nG,void 0,void 0,rG,void 0,iG,aG,QU,QU,void 0,void 0,void 0,void 0,void 0,oG,sG.bind(void 0,0),sG.bind(void 0,1),cG,void 0,lG,uG,dG,fG,pG,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,mG.bind(void 0,1),mG.bind(void 0,2),mG.bind(void 0,3),mG.bind(void 0,4),mG.bind(void 0,5),mG.bind(void 0,6),mG.bind(void 0,7),mG.bind(void 0,8),hG.bind(void 0,1),hG.bind(void 0,2),hG.bind(void 0,3),hG.bind(void 0,4),hG.bind(void 0,5),hG.bind(void 0,6),hG.bind(void 0,7),hG.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 gG(e){this.char=e,this.state={},this.activeState=null}function _G(e,t,n){this.contextName=n,this.startIndex=e,this.endOffset=t}function vG(e,t,n){this.contextName=e,this.openRange=null,this.ranges=[],this.checkStart=t,this.checkEnd=n}function yG(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 bG(e){this.eventId=e,this.subscribers=[]}function xG(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 bG(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 SG(e){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],xG.call(this,e)}gG.prototype.setState=function(e,t){return this.state[e]=t,this.activeState={key:e,value:this.state[e]},this.activeState},gG.prototype.getState=function(e){return this.state[e]||null},SG.prototype.inboundIndex=function(e){return e>=0&&e<this.tokens.length},SG.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)})])},SG.prototype.replaceRange=function(e,t,n,r){t=t===null?this.tokens.length:t;var i=n.every(function(e){return e instanceof gG});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.`}},SG.prototype.replaceToken=function(e,t,n){if(!isNaN(e)&&this.inboundIndex(e)&&t instanceof gG){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.`}},SG.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},SG.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.`}},SG.prototype.insertToken=function(e,t,n){return e.every(function(e){return e instanceof gG})?(this.tokens.splice.apply(this.tokens,[t,0].concat(e)),n||this.dispatch(`insertToken`,[e,t]),e):{FAIL:`insertToken: invalid token(s).`}},SG.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)},bG.prototype.subscribe=function(e){return typeof e==`function`?this.subscribers.push(e)-1:{FAIL:`invalid '`+this.eventId+`' event handler`}},bG.prototype.unsubscribe=function(e){this.subscribers.splice(e,1)},yG.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)},yG.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}},SG.prototype.rangeToText=function(e){if(e instanceof _G)return this.getRangeTokens(e).map(function(e){return e.char}).join(``)},SG.prototype.getText=function(){return this.tokens.map(function(e){return e.char}).join(``)},SG.prototype.getContext=function(e){return this.registeredContexts[e]||null},SG.prototype.on=function(e,t){var n=this.events[e];return n?n.subscribe(t):null},SG.prototype.dispatch=function(e,t){var n=this,r=this.events[e];r instanceof bG&&r.subscribers.forEach(function(e){e.apply(n,t||[])})},SG.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 vG(e,t,n);return this.registeredContexts[e]=r,this.contextCheckers.push(r),r},SG.prototype.getRangeTokens=function(e){var t=e.startIndex+e.endOffset;return[].concat(this.tokens.slice(e.startIndex,t))},SG.prototype.getContextRanges=function(e){var t=this.getContext(e);return t?t.ranges:{FAIL:`context checker '`+e+`' is not registered.`}},SG.prototype.resetContextsRanges=function(){var e=this.registeredContexts;for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];n.ranges=[]}},SG.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 yG(e,t);this.runContextCheck(n)}this.dispatch(`updateContextsRanges`,[this.registeredContexts])},SG.prototype.setEndOffset=function(e,t){var n=this.getContext(t).openRange.startIndex,r=new _G(n,e,t),i=this.getContext(t).ranges;return r.rangeId=t+`.`+i.length,i.push(r),this.getContext(t).openRange=null,r},SG.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 _G(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])}})},SG.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 yG(t,n);this.dispatch(`next`,[i]),this.runContextCheck(i);var a=new gG(r);this.tokens.push(a),this.dispatch(`newToken`,[a,i])}return this.dispatch(`end`,[this.tokens]),this.tokens};function CG(e){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(e)}function wG(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 TG(e){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(e)}function EG(e){return/[A-z]/.test(e)}function DG(e){return/\s/.test(e)}function OG(e){this.font=e,this.features={}}function kG(e){this.id=e.id,this.tag=e.tag,this.substitution=e.substitution}function AG(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 jG(e,t){return AG(e,t.coverage)===-1?null:e+t.deltaGlyphId}function MG(e,t){var n=AG(e,t.coverage);return n===-1?null:t.substitute[n]}function NG(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=AG(a,i);o!==-1&&n.push(o)}return n.length===e.length?n:-1}function PG(e,t){var n=t.inputCoverage.length+t.lookaheadCoverage.length+t.backtrackCoverage.length;if(e.context.length<n)return[];var r=NG(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&&TG(a[0].char);)a.shift();var o=new yG(a,0),s=NG(t.lookaheadCoverage,o),c=[].concat(e.backtrack);for(c.reverse();c.length&&TG(c[0].char);)c.shift();if(c.length<t.backtrackCoverage.length)return[];var l=new yG(c,0),u=NG(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 FG(e,t){var n=e.current,r=AG(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 IG(e,t){var n=AG(e,t.coverage);return n===-1?null:t.sequences[n]}OG.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[]},OG.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()},OG.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},OG.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},OG.prototype.getSubstitutionType=function(e,t){return e.lookupType.toString()+t.substFormat.toString()},OG.prototype.getLookupMethod=function(e,t){var n=this;switch(this.getSubstitutionType(e,t)){case`11`:return function(e){return jG.apply(n,[e,t])};case`12`:return function(e){return MG.apply(n,[e,t])};case`63`:return function(e){return PG.apply(n,[e,t])};case`41`:return function(e){return FG.apply(n,[e,t])};case`21`:return function(e){return IG.apply(n,[e,t])};default:throw Error(`lookupType: `+e.lookupType+` - substFormat: `+t.substFormat+` is not yet supported`)}},OG.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 kG({id:11,tag:e.tag,substitution:p}));break;case`12`:p=f(t.current),p&&a.splice(n,1,new kG({id:12,tag:e.tag,substitution:p}));break;case`63`:p=f(t),Array.isArray(p)&&p.length&&a.splice(n,1,new kG({id:63,tag:e.tag,substitution:p}));break;case`41`:p=f(t),p&&a.splice(n,1,new kG({id:41,tag:e.tag,substitution:p}));break;case`21`:p=f(t.current),p&&a.splice(n,1,new kG({id:21,tag:e.tag,substitution:p}));break}t=new yG(a,n),!(Array.isArray(p)&&!p.length)&&(p=null)}return a.length?a:null},OG.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},OG.prototype.getLookupSubtables=function(e){return e.subtables||null},OG.prototype.getLookupByIndex=function(e){return this.font.tables.gsub.lookups[e]||null},OG.prototype.getFeatureLookups=function(e){return e.lookupListIndexes.map(this.getLookupByIndex.bind(this))},OG.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 LG(e){var t=e.current,n=e.get(-1);return n===null&&CG(t)||!CG(n)&&CG(t)}function RG(e){var t=e.get(1);return t===null||!CG(t)}var zG={startCheck:LG,endCheck:RG};function BG(e){var t=e.current,n=e.get(-1);return(CG(t)||TG(t))&&!CG(n)}function VG(e){var t=e.get(1);switch(!0){case t===null:return!0;case!CG(t)&&!TG(t):var n=DG(t);if(!n)return!0;if(n){var r=!1;if(r=e.lookahead.some(function(e){return CG(e)||TG(e)}),!r)return!0}break;default:return!1}}var HG={startCheck:BG,endCheck:VG};function UG(e,t,n){t[n].setState(e.tag,e.substitution)}function WG(e,t,n){t[n].setState(e.tag,e.substitution)}function GG(e,t,n){e.substitution.forEach(function(r,i){t[n+i].setState(e.tag,r)})}function KG(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 qG={11:UG,12:WG,63:GG,41:KG};function JG(e,t,n){e instanceof kG&&qG[e.id]&&qG[e.id](e,t,n)}function YG(e){for(var t=[].concat(e.backtrack),n=t.length-1;n>=0;n--){var r=t[n],i=wG(r),a=TG(r);if(!i&&!a)return!0;if(i)return!1}return!1}function XG(e){if(wG(e.current))return!1;for(var t=0;t<e.lookahead.length;t++){var n=e.lookahead[t];if(!TG(n))return!0}return!1}function ZG(e){var t=this,n=`arab`,r=this.featuresTags[n],i=this.tokenizer.getRangeTokens(e);if(i.length!==1){var a=new yG(i.map(function(e){return e.getState(`glyphIndex`)}),0),o=new yG(i.map(function(e){return e.char}),0);i.forEach(function(e,s){if(!TG(e.char)){a.setCurrentIndex(s),o.setCurrentIndex(s);var c=0;YG(o)&&(c|=1),XG(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 kG&&(JG(e,i,t),a.context[t]=e.substitution)})}}})}}function QG(e,t){return new yG(e.map(function(e){return e.activeState.value}),t||0)}function $G(e){var t=this,n=`arab`,r=this.tokenizer.getRangeTokens(e),i=QG(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 JG(e,r,a)}),i=QG(r))})}function eK(e){var t=e.current,n=e.get(-1);return n===null&&EG(t)||!EG(n)&&EG(t)}function tK(e){var t=e.get(1);return t===null||!EG(t)}var nK={startCheck:eK,endCheck:tK};function rK(e,t){return new yG(e.map(function(e){return e.activeState.value}),t||0)}function iK(e){var t=this,n=`latn`,r=this.tokenizer.getRangeTokens(e),i=rK(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 JG(e,r,a)}),i=rK(r))})}function aK(e){this.baseDir=e||`ltr`,this.tokenizer=new SG,this.featuresTags={}}aK.prototype.setText=function(e){this.text=e},aK.prototype.contextChecks={latinWordCheck:nK,arabicWordCheck:zG,arabicSentenceCheck:HG};function oK(e){var t=this.contextChecks[e+`Check`];return this.tokenizer.registerContextChecker(e,t.startCheck,t.endCheck)}function sK(){return oK.call(this,`latinWord`),oK.call(this,`arabicWord`),oK.call(this,`arabicSentence`),this.tokenizer.tokenize(this.text)}function cK(){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())})}aK.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},aK.prototype.applyFeatures=function(e,t){if(!e)throw Error(`No valid font was provided to apply features`);this.query||=new OG(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)}},aK.prototype.registerModifier=function(e,t,n){this.tokenizer.registerModifier(e,t,n)};function lK(){if(this.tokenizer.registeredModifiers.indexOf(`glyphIndex`)===-1)throw Error(`glyphIndex modifier is required to apply arabic presentation features.`)}function uK(){var e=this;this.featuresTags.hasOwnProperty(`arab`)&&(lK.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){ZG.call(e,t)}))}function dK(){var e=this,t=`arab`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`rlig`)!==-1&&(lK.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){$G.call(e,t)}))}function fK(){var e=this,t=`latn`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`liga`)!==-1&&(lK.call(this),this.tokenizer.getContextRanges(`latinWord`).forEach(function(t){iK.call(e,t)}))}aK.prototype.checkContextReady=function(e){return!!this.tokenizer.getContext(e)},aK.prototype.applyFeaturesToContexts=function(){this.checkContextReady(`arabicWord`)&&(uK.call(this),dK.call(this)),this.checkContextReady(`latinWord`)&&fK.call(this),this.checkContextReady(`arabicSentence`)&&cK.call(this)},aK.prototype.processText=function(e){(!this.text||this.text!==e)&&(this.setText(e),sK.call(this),this.applyFeaturesToContexts())},aK.prototype.getBidiText=function(e){return this.processText(e),this.tokenizer.getText()},aK.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 pK(e){e||={},e.tables=e.tables||{},e.empty||(qH(e.familyName,`When creating a new Font object, familyName is required.`),qH(e.styleName,`When creating a new Font object, styleName is required.`),qH(e.unitsPerEm,`When creating a new Font object, unitsPerEm is required.`),qH(e.ascender,`When creating a new Font object, ascender is required.`),qH(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 YB.GlyphSet(this,e.glyphs||[]),this.encoding=new NB(this),this.position=new BH(this),this.substitution=new VH(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 cU(this)}})}pK.prototype.hasChar=function(e){return this.encoding.charToGlyphIndex(e)!==null},pK.prototype.charToGlyphIndex=function(e){return this.encoding.charToGlyphIndex(e)},pK.prototype.charToGlyph=function(e){var t=this.charToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},pK.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})},pK.prototype.stringToGlyphs=function(e,t){var n=this,r=new aK;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},pK.prototype.nameToGlyphIndex=function(e){return this.glyphNames.nameToGlyphIndex(e)},pK.prototype.nameToGlyph=function(e){var t=this.nameToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},pK.prototype.glyphIndexToName=function(e){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(e):``},pK.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},pK.prototype.defaultRenderOptions={kerning:!0,features:[{script:`arab`,tags:[`init`,`medi`,`fina`,`rlig`]},{script:`latn`,tags:[`liga`,`rlig`]}]},pK.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},pK.prototype.getPath=function(e,t,n,r,i){var a=new Vz;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},pK.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},pK.prototype.getAdvanceWidth=function(e,t,n){return this.forEachGlyph(e,0,0,t,n,function(){})},pK.prototype.draw=function(e,t,n,r,i,a){this.getPath(t,n,r,i,a).draw(e)},pK.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)})},pK.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)})},pK.prototype.getEnglishName=function(e){var t=this.names[e];if(t)return t.en},pK.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},pK.prototype.toTables=function(){return FH.fontToTable(this)},pK.prototype.toBuffer=function(){return console.warn(`Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.`),this.toArrayBuffer()},pK.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},pK.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(WH())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=pz(),l=KH(r);c.writeFileSync(e,l)}},pK.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512},pK.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},pK.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function mK(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 hK(e,t,n){var r=mK(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 gK(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 _K(e,t,n,r){for(var i=mK(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 vK(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 yK(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(hK(r,e.axes[r],t));for(var i=0;i<e.instances.length;i++)n.fields=n.fields.concat(_K(i,e.instances[i],e.axes,t));return n}function bK(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(gK(e,t+a+d*s,n));for(var f=[],p=t+a+o*s,m=0;m<c;m++)f.push(vK(e,p+m*l,u,n));return{axes:u,instances:f}}var xK={make:yK,parse:bK},SK=function(){return{coverage:this.parsePointer(X.coverage),attachPoints:this.parseList(X.pointer(X.uShortList))}},CK=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()}},wK=function(){return this.parseList(X.pointer(CK))},TK=function(){return{coverage:this.parsePointer(X.coverage),ligGlyphs:this.parseList(X.pointer(wK))}},EK=function(){return this.parseUShort(),this.parseList(X.pointer(X.coverage))};function DK(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(SK),ligCaretList:n.parsePointer(TK),markAttachClassDef:n.parsePointer(X.classDef)};return r>=1.2&&(i.markGlyphSets=n.parsePointer(EK)),i}var OK={parse:DK},kK=Array(10);kK[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.`)},kK[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)}}))}}},kK[3]=function(){return{error:`GPOS Lookup 3 not supported`}},kK[4]=function(){return{error:`GPOS Lookup 4 not supported`}},kK[5]=function(){return{error:`GPOS Lookup 5 not supported`}},kK[6]=function(){return{error:`GPOS Lookup 6 not supported`}},kK[7]=function(){return{error:`GPOS Lookup 7 not supported`}},kK[8]=function(){return{error:`GPOS Lookup 8 not supported`}},kK[9]=function(){return{error:`GPOS Lookup 9 not supported`}};function AK(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(kK)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(kK),variations:n.parseFeatureVariationsList()}}var jK=Array(10);function MK(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,jK)}])}var NK={parse:AK,make:MK};function PK(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 FK(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 IK(e,t){var n=new Z.Parser(e,t),r=n.parseUShort();if(r===0)return PK(n);if(r===1)return FK(n);throw Error(`Unsupported kern table version (`+r+`).`)}var LK={parse:IK};function RK(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 zK={parse:RK};function BK(e,t){pz().readFile(e,function(e,n){if(e)return t(e.message);t(null,GH(n))})}function VK(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 HK(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 UK(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 WK(e,t){if(t.compression===`WOFF`){var n=new Uint8Array(e.buffer,t.offset+2,t.compressedLength-2),r=new Uint8Array(t.length);if(Rz(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 GK(e,t){t??={};var n,r,i=new pK({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=HK(a,o);else if(c===`OTTO`)i.outlinesFormat=`cff`,o=Z.getUShort(a,4),s=HK(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=UK(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=WK(a,C),i.tables.cmap=OB.parse(w.data,w.offset),i.encoding=new PB(i.tables.cmap);break;case`cvt `:w=WK(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=WK(a,C),x=new Z.Parser(w.data,w.offset),i.tables.fpgm=x.parseByteList(C.length);break;case`head`:w=WK(a,C),i.tables.head=PV.parse(w.data,w.offset),i.unitsPerEm=i.tables.head.unitsPerEm,n=i.tables.head.indexToLocFormat;break;case`hhea`:w=WK(a,C),i.tables.hhea=LV.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=WK(a,C),r=GV.parse(w.data,w.offset);break;case`maxp`:w=WK(a,C),i.tables.maxp=JV.parse(w.data,w.offset),i.numGlyphs=i.tables.maxp.numGlyphs;break;case`name`:y=C;break;case`OS/2`:w=WK(a,C),i.tables.os2=hH.parse(w.data,w.offset);break;case`post`:w=WK(a,C),i.tables.post=vH.parse(w.data,w.offset),i.glyphNames=new IB(i.tables.post);break;case`prep`:w=WK(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=WK(a,y);if(i.tables.name=uH.parse(ee.data,ee.offset,r),i.names=i.tables.name,f&&v){var te=n===0,ne=WK(a,v),re=zK.parse(ne.data,ne.offset,i.numGlyphs,te),ie=WK(a,f);i.glyphs=rU.parse(ie.data,ie.offset,re,i,t)}else if(u){var ae=WK(a,u);jV.parse(ae.data,ae.offset,i,t)}else throw Error(`Font doesn't contain TrueType or CFF outlines.`);var oe=WK(a,g);if(HV.parse(i,oe.data,oe.offset,i.numberOfHMetrics,i.numGlyphs,i.glyphs,t),zB(i,t),_){var se=WK(a,_);i.kerningPairs=LK.parse(se.data,se.offset)}else i.kerningPairs={};if(p){var ce=WK(a,p);i.tables.gdef=OK.parse(ce.data,ce.offset)}if(m){var le=WK(a,m);i.tables.gpos=NK.parse(le.data,le.offset),i.position.init()}if(h){var ue=WK(a,h);i.tables.gsub=wH.parse(ue.data,ue.offset)}if(d){var de=WK(a,d);i.tables.fvar=xK.parse(de.data,de.offset,i.names)}if(b){var fe=WK(a,b);i.tables.meta=DH.parse(fe.data,fe.offset),i.metas=i.tables.meta}return i}function KK(e,t,n){n??={};var r=typeof window>`u`&&!n.isUrl?BK:VK;return new Promise(function(i,a){r(e,function(e,r){if(e){if(t)return t(e);a(e)}var o;try{o=GK(r,n)}catch(e){if(t)return t(e,null);a(e)}if(t)return t(null,o);i(o)})})}function qK(e,t){return GK(GH(pz().readFileSync(e)),t)}var JK=Object.freeze({__proto__:null,Font:pK,Glyph:UB,Path:Vz,BoundingBox:Bz,_parse:Z,parse:GK,load:KK,loadSync:qK}),YK=class e{sketches;constructor(e){e.length===0&&i(`CompoundSketch`,`Cannot create CompoundSketch with an empty array of sketches`),this.sketches=e}delete(){this.sketches.forEach(e=>{e.delete()})}get outerSketch(){return yA(this.sketches)}get innerSketches(){return this.sketches.slice(1)}get wires(){return sq(this)}face(){return oq(this)}extrude(e,t={}){return cq(this,e,t)}revolve(e,t={}){return lq(this,e,t)}loftWith(t,n={}){return Array.isArray(t)||!(t instanceof e)?i(`CompoundSketch.loftWith`,`A compound (face-with-holes) sketch can only loft to another compound sketch with the same number of sub-sketches.`):uq(this,t,n)}sweepSketch(){return i(`CompoundSketch.sweepSketch`,`Sweeping a compound (face-with-holes) profile is not supported — sweep its outer Sketch instead.`)}};function XK(e){let t={};e.defaultOrigin&&(t.defaultOrigin=e.defaultOrigin),e.defaultDirection&&(t.defaultDirection=e.defaultDirection);let n=new dq(e.wire,t);return e.baseFace&&(n.baseFace=e.baseFace),n}function ZK(e){return new YK(e.map(XK))}function QK(e){if(e instanceof dq)return e;let t=e.sketches;if(Array.isArray(t)){let[e,...n]=t;if(e instanceof dq){for(let e of n)e.delete();return e}}i(`asSketch`,`Expected a single-wire profile to loft or sweep.`)}function $K(e){let t;return t=e.baseFace?IA(e.baseFace,e.wire):j(PA(e.wire)),t}function eq(e){return DE(j(fO(e.wire.wrapped)))}function tq(e,t,{origin:n}={}){let r=j(PA(e.wire)),i=j(jM(r,n?jD(n):e.defaultOrigin,t?jD(t):[0,0,1]));return r[Symbol.dispose](),e.delete(),i}function nq(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=LD(WD(n?jD(n):e.defaultDirection),t),s=a?jD(a):e.defaultOrigin;if(r&&!i){let t=j(wM(e.wire,[...s],[...o],r));return e.delete(),t}if(i){let t=j(TM(e.wire,i,[...s],[...o],r));return e.delete(),t}let c=j(PA(e.wire)),l=j(AM(c,[...o]));return c[Symbol.dispose](),e.delete(),l}function rq(e,t,n={}){let r=Nk(e.wire),i=WD(LD(Ik(e.wire,1e-9),-1)),a=e.defaultDirection,o=LD(BD(i,a),-1),s=QK(t(QD([...r],[...o],[...i]),[...r])),c={forceProfileSpineOthogonality:!0,...n};e.baseFace&&(c.support=e.baseFace.wrapped);let l=j(SM(s.wire,e.wire,c));return e.delete(),l}function iq(e,t,n={},r=!1){let i=[e,...(Array.isArray(t)?t:[t]).map(QK)],a=j(NM(i.map(e=>e.wire),n,r));return i.forEach(e=>{e.delete()}),a}var aq=(e,t)=>{let n=j(t(yA(e))),r=e.slice(1).map(e=>j(t(e)));if(r.length===0)return n;try{return j(qA(n,r,{unsafe:!0}))}finally{n.delete();for(let e of r)e.delete()}};function oq(e){let t=e.outerSketch.face(),n=RA(t,e.innerSketches.map(e=>e.wire));return t[Symbol.dispose](),n}function sq(e){return gj(e.sketches.map(e=>e.wire))}function cq(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=LD(WD(n?jD(n):e.outerSketch.defaultDirection),t);if(r&&!i)return aq(e.sketches,t=>wM(t.wire,a?jD(a):e.outerSketch.defaultOrigin,o,r));if(i)return aq(e.sketches,t=>TM(t.wire,i,a?jD(a):e.outerSketch.defaultOrigin,o,r));let s=oq(e),c=j(AM(s,o));return s[Symbol.dispose](),c}function lq(e,t,{origin:n}={}){let r=n?jD(n):e.outerSketch.defaultOrigin,i=t?jD(t):[0,0,1],a=oq(e),o=j(jM(a,r,i));return a[Symbol.dispose](),o}function uq(e,t,n={}){e.sketches.length!==t.sketches.length&&i(`CompoundSketch.loftWith`,`You need to loft with another compound with the same number of sketches`);let r=e.sketches.map((e,r)=>{let i=vA(t.sketches,r),a={};return n.ruled!==void 0&&(a.ruled=n.ruled),e.clone().loftWith(i.clone(),a,!0)}),a=oq(e),o=OE(j(fO(a.wrapped)));a[Symbol.dispose](),r.push(o,oq(t));let s=j(_j(r));for(let e of r)e[Symbol.dispose]();return s}var dq=class e{wire;_defaultOrigin;_defaultDirection;_baseFace;constructor(e,{defaultOrigin:t=[0,0,0],defaultDirection:n=[0,0,1]}={}){this.wire=e,this._defaultOrigin=jD(t),this._defaultDirection=jD(n),this.baseFace=null}get baseFace(){return this._baseFace}set baseFace(e){this._baseFace&&this._baseFace[Symbol.dispose](),this._baseFace=e&&OE(j(fO(e.wrapped)))}delete(){this.wire[Symbol.dispose](),this.baseFace&&this.baseFace[Symbol.dispose]()}clone(){let t=DE(j(fO(this.wire.wrapped))),n=new e(t,{defaultOrigin:this.defaultOrigin,defaultDirection:this.defaultDirection});return this.baseFace&&(n.baseFace=OE(j(fO(this.baseFace.wrapped)))),n}get defaultOrigin(){return this._defaultOrigin}set defaultOrigin(e){this._defaultOrigin=jD(e)}get defaultDirection(){return this._defaultDirection}set defaultDirection(e){this._defaultDirection=jD(e)}face(){return $K(this)}wires(){return eq(this)}faces(){return this.face()}revolve(e,t={}){return tq(this,e,t)}extrude(e,t={}){return nq(this,e,t)}sweepSketch(e,t={}){return rq(this,e,t)}loftWith(e,t={},n=!1){return iq(this,e,t,n)}},fq=class{sketches;constructor(e){this.sketches=e}soleSketch(e){this.sketches.length!==1&&i(`Sketches.${e}`,`Multiple profiles — ${e} each sub-sketch individually.`);let t=yA(this.sketches);return t instanceof dq||i(`Sketches.${e}`,`${e} is only supported on single-wire profiles.`),t}face(){return this.sketches.length!==1&&i(`Sketches.face`,`Multiple profiles — use faces() to combine them.`),yA(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 gj(this.sketches.flatMap(e=>e instanceof dq?[e.wire]:e.sketches.map(e=>e.wire)))}faces(){return gj(this.sketches.map(e=>e.face()))}extrude(e,t={}){return gj(this.sketches.map(n=>n.extrude(e,t)))}revolve(e,t){return gj(this.sketches.map(n=>n.revolve(e,t)))}},pq={};async function mq(e,t=`default`,n=!1){if(!n&&pq[t])return O(pq[t]);let r;if(typeof e==`string`){let t;try{t=await fetch(e)}catch(t){return k(Oo(M.FONT_FETCH_FAILED,`Failed to fetch font from ${e}: ${t instanceof Error?t.message:String(t)}`,t))}if(!t.ok)return k(Oo(M.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=JK.parse(r)}catch(e){return k(Oo(M.FONT_PARSE_FAILED,`Failed to parse font data: ${e instanceof Error?e.message:String(e)}`,e))}let a=i;return pq[t]=a,pq.default||=a,O(a)}var hq=(e=`default`)=>pq[e],gq=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 bR,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 _q(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:a=`default`}={}){let o=hq(a);o||=hq(),o||i(`text`,`No fonts loaded. Call loadFont() before using text functions.`);let s=o.getPath(e,-t,-n,r);return lR(Array.from(gq(s.commands))).mirror([0,0])}var vq={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 yq(e){return typeof e==`string`&&e in vq}var bq=e=>{try{var t=LT();return e.IsNull()?[]:dD(t.u(U(e))).map(e=>j(Tk(e)))}catch(e){t.e=e}finally{t.d()}};function xq(e,t,n=!0){let r=H().projectEdges(e.wrapped,[...t.position],[...t.direction],[...t.xAxis]),i=[...bq(r.visible.sharp),...bq(r.visible.smooth),...bq(r.visible.outline)],a=[...bq(r.hidden.sharp),...bq(r.hidden.smooth),...bq(r.hidden.outline)],o;if(n)o=a;else{for(let e of a)e[Symbol.dispose]();o=[]}return{visible:i,hidden:o}}function Sq(e=[0,0,0],t=[0,0,1],n){if(VD(t)<1e-12)return k(P(`CAMERA_ZERO_DIRECTION`,`Camera direction cannot be a zero-length vector`));let r;if(n)r=WD(n);else{let e=BD([0,0,1],t);VD(e)<1e-12&&(e=BD([0,1,0],t)),VD(e)<1e-12&&(e=BD([1,0,0],t)),r=WD(e)}let i=WD(BD(t,r));return O({position:e,direction:WD(t),xAxis:r,yAxis:i})}function Cq(e,t){let n=WD(ID(e.position,t));return Sq(e.position,n)}function wq(e){let t=vq[e];return Sq([0,0,0],t.dir,t.xAxis)}function Tq(e,t,n=!0){return xq(e,t,n)}var Eq=(e,n=1e-7)=>{if(e.length===0)return[];let r=new UL(e.length);e.forEach(e=>{let[t,i]=e.firstPoint;r.add(t-n,i-n,t+n,i+n)}),r.finish();let a=[],o=new Set;return e.forEach((s,c)=>{if(o.has(c))return;let l=[s],u=c;o.add(c);let d=e.length;for(;;){d--<0&&i(`stitchCurves`,`Infinite loop detected`);let[s,c]=t(l,l.length-1).lastPoint,f=r.search(s-n,c-n,s+n,c+n),p=t=>Math.abs((u-t)%e.length),m=f.filter(e=>!o.has(e)).map(n=>[t(e,n),n,p(n)]).sort(([,,e],[,,t])=>e-t);if(m.length===0){a.push(l);break}let[h,g]=t(m,0);l.push(h),o.add(g),u=g}}),a},Dq=class extends yR{plane;constructor(e,t){super(),this.plane=e&&typeof e!=`string`?{...e}:j(tO(e??`XY`,t))}delete(){this.pendingCurves=[]}sagittaArcTo(e,t){return super.sagittaArcTo(e,-t)}buildWire(){try{var e=LT();this.pendingCurves.length||i(`Sketcher.buildWire`,`No lines to convert into a wire`);let t=e.u(new ZT);return j(NA(EL(this.pendingCurves,this.plane).map(e=>t.register(e))))}catch(t){e.e=t}finally{e.d()}}done(){return new dq(this.buildWire(),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}close(){return this._closeSketch(),this.done()}closeWithMirror(){OI(this.pointer,this.firstPoint)&&i(`Sketcher.closeWithMirror`,`Cannot close with a mirror when the sketch is already closed`);let e=this.buildWire(),t=rO(this.plane,this.pointer),n=BD(WD(ID(t,rO(this.plane,this.firstPoint))),this.plane.zDir),r=j(dO(e.wrapped));return new dq(j(NA([e,DE(j(dO(H().mirror(r,jD(t),jD(n)))))])),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}closeWithCustomCorner(e,t=`fillet`){return this._closeSketch(),this._customCornerLastWithFirst(e,t),this.done()}},Oq=class extends yR{face;_bounds;constructor(e,t=[0,0]){super(t),this.face=OE(j(fO(e.wrapped))),this._bounds=xO(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 H().extractSurfaceFromFace(this.face.wrapped)}buildWire(){let e=H(),t=this._adaptSurface(),n=j(NA(this.pendingCurves.map(n=>EE(e.buildEdgeOnSurface(n.wrapped,t)))));return e.buildCurves3d(n.wrapped),n}done(){try{var e=LT();let t=e.u(new ZT),n=this.buildWire(),r=new dq(n);if(zk(n)){let e=t.register(r.clone().face()),n=SO(e,.5,.5),i=LD(TO(e),-1);r.defaultOrigin=[n[0],n[1],n[2]],r.defaultDirection=[i[0],i[1],i[2]]}else{let e=Nk(n),t=TO(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()}},kq=(e,t={})=>{try{var n=LT();let r=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(tO(t.plane??`XY`,t.origin));return new dq(j(NA([n.u(new ZT).register(wA(e,r.origin,r.zDir))])),{defaultOrigin:[...r.origin],defaultDirection:[...r.zDir]})}catch(e){n.e=e}finally{n.d()}},Aq=(e=1,t=2,n={})=>{try{var r=LT();let i=n.plane&&typeof n.plane!=`string`?{...n.plane}:j(tO(n.plane??`XY`,n.origin)),a=i.xDir,o=e,s=t;return t>e&&(a=YD(a,i.zDir,90*YE),o=t,s=e),new dq(j(NA([r.u(new ZT).register(j(TA(o,s,i.origin,i.zDir,a)))])),{defaultOrigin:[...i.origin],defaultDirection:[...i.zDir]})}catch(e){r.e=e}finally{r.d()}},jq=(e,t,n={})=>(n.plane&&typeof n.plane!=`string`?new Dq(n.plane):new Dq(n.plane,n.origin)).movePointerTo([-e/2,-t/2]).hLine(e).vLine(t).hLine(-e).vLine(-t).done(),Mq=(e,t,n=0,r={})=>{let i=DR(e,t,n).sketchOnPlane(r.plane,r.origin),a={};return i.defaultOrigin&&(a.defaultOrigin=i.defaultOrigin),i.defaultDirection&&(a.defaultDirection=i.defaultDirection),new dq(i.wire,a)},Nq=(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 Dq(r.plane):new Dq(r.plane,r.origin),o=bA(i),s=a.movePointerTo([vA(o,0),vA(o,1)]);return n?i.forEach(e=>s.sagittaArcTo([vA(e,0),vA(e,1)],n)):i.forEach(e=>s.lineTo([vA(e,0),vA(e,1)])),s.done()},Pq=(e,t,n=0)=>{let r=Math.PI/t,i=Math.cos(r)*e;return n>=0?i:i+n},Fq=(e,t)=>{let n=[...EO(e)],r=[...TO(e)];return new dq(j(Kk(kO(e),t)),{defaultOrigin:n,defaultDirection:r})},Iq=(e,t={},{pointsCount:n=400,start:r=0,stop:i=1}={},a={})=>{try{var o=LT();let s=o.u(new ZT),c=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(tO(t.plane??`XY`,t.origin)),l=(i-r)/n,u=[...Array(n+1).keys()].map(t=>{let n=e(r+t*l);return rO(c,n)});return new dq(j(NA([s.register(j(kA(u,a)))])),{defaultOrigin:[...c.origin],defaultDirection:[...c.zDir]})}catch(e){o.e=e}finally{o.d()}},Lq=(e,t,n,r=[0,0,0],i=[0,0,1],a=!1)=>new dq(j(NA([EA(e,t,n,jD(r),jD(i),a)]))),Rq=(e,t,n)=>new Dq().movePointerTo([-e/2,t/2]).hLine(e).vLine(-t).hLine(-e).close().extrude(n),zq=(e,t)=>OI(e,t,EI*100),Bq=(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 Vq(e,t,n,r,i){let a=CL(t,n,r.original.lastPoint);e(r),e(a)}function Hq(e,t,n,r,i){let a=hL(t,n);e(r),e(a)}function Uq(e,t,n,r,i){let a=Bq(r.offset instanceof dL?AI(t,r.offset.tangentAt(1)):r.offset.firstPoint,t,n,i.offset instanceof dL?kI(n,i.offset.tangentAt(0)):i.offset.lastPoint);if(!a){let i=hL(t,n);e(r),e(i);return}let o=NI([(t[0]+n[0])/2,(t[1]+n[1])/2],a),s=NI(t,n);if(s<1e-18||o>16*s){let i=hL(t,n);e(r),e(i);return}let c=hL(t,a),l=hL(a,n);e(r),e(c),e(l)}var Wq={round:Vq,bevel:Hq,miter:Uq};function Gq(e,t,n){let r=n.length===1?jo(n,0,`rawOffsets`):Kq(n,e.original.lastPoint),a=jo(e.offset.splitAt([r],EI),0,`rawOffsets`),o=t.offset.splitAt([r],EI).at(-1);return o||i(`offset.rawOffsets`,`Split produced no trailing curve segment`),{splitPrevious:{offset:a,original:e.original},splitCurrent:{offset:o,original:t.original}}}function Kq(e,t){let n=jo(e,0,`selectClosestIntersection`),r=NI(n,t);for(let i=1;i<e.length;i++){let a=jo(e,i,`selectClosestIntersection`),o=NI(a,t);o<r&&(r=o,n=a)}return n}function qq(e){let t=new Map,n=(e,n)=>{let r=t.get(e)||[];t.set(e,[...r,...n])},r=new UL(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=jo(e,r,`offsetBlueprint`),{intersections:o,commonSegmentsPoints:s}=j(JL(t,a,EI)),c=[...o,...s].filter(e=>{let n=zq(e,t.firstPoint)||zq(e,t.lastPoint),r=zq(e,a.firstPoint)||zq(e,a.lastPoint);return!(n&&r)});c.length&&(n(i,c),n(r,c))}}),t}function Jq(e,t,n={}){let r=e.orientation===`clockwise`?-t:t,a=e.curves.map(e=>({offset:ZL(e,r),original:e})),o=[],s=null,c=a.at(-1);if(!c)return[];function l(e){if(e instanceof dL){o.push(e);return}s?e.offset instanceof dL?o.push(e.offset):zq(e.offset.firstPoint,e.offset.lastPoint)||o.push(hL(e.offset.firstPoint,e.offset.lastPoint)):s=e}let u=function*(){for(let e of a.slice(0,-1))yield e;s||i(`offset.rawOffsets`,`No saved curve after iterating offset segments`),yield s};for(let e of u()){let t=c.offset.lastPoint,r=e.offset.firstPoint;if(zq(t,r)){l(c),c=e;continue}let i=[];if(c.offset instanceof dL&&e.offset instanceof dL){let{intersections:t,commonSegmentsPoints:n}=j(JL(c.offset,e.offset,EI/100));i=[...t,...n]}if(i.length>0){let{splitPrevious:t,splitCurrent:n}=Gq(c,e,i);l(t),c=n;continue}let a=Wq[n.lineJoinType??`round`];a(l,t,r,c,e),c=e}return l(c),o}function Yq(e,n,r={}){let i=Jq(e,n,r);if(i.length<2)return null;let a=qq(i);if(!a.size){let t=new zL(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,EI*100)}),s=new UL(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-EI)});if(!l.length)return null;let u=Eq(l).filter(e=>e.length>1).map(e=>new zL(e)).filter(e=>e.isClosed());return u.length?u.length===1?jo(u,0,`offsetBlueprint`):new nR(u):null}var Xq=e=>{let t=jo(e,0,`fuseAll`);for(let n=1;n<e.length;n++)t=lz(t,jo(e,n,`fuseAll`));return t};function Zq(e,t,n={}){if(e instanceof zL)return Yq(e,t,n);if(e instanceof nR)return Xq(e.blueprints.map(e=>Zq(e,t,n)));if(e instanceof rR){let r=Xq(e.blueprints.slice(1).map(e=>Zq(e,-t,n)));return dz(Zq(jo(e.blueprints,0,`offset`),t,n),r)}return null}function Qq(e,t){return e instanceof zL?new zL(mL(e.curves,t)):e instanceof rR?new rR(e.blueprints.map(e=>Qq(e,t))):e instanceof nR?new nR(e.blueprints.map(e=>Qq(e,t))):e}function $q(e,t,n,r){let a=()=>!0;r&&(a=r.shouldKeep.bind(r));let o=[yA(t.curves)],s=(t,r)=>{a({firstCurve:t,secondCurve:r,point:t.lastPoint})?o.push(...e(t,r,n)):o.push(t,r)};t.curves.slice(1).forEach(e=>{let t=o.pop();t||i(`customCorners.modifyCorners`,`Unexpected empty curve stack during filleting`),s(t,e)});let c=o.at(-1);if(c||i(`customCorners.modifyCorners`,`Unexpected empty curve list during corner modification`),OI(yA(o).firstPoint,c.lastPoint)&&o.length>1){let e=o.pop(),t=o.shift();(!e||!t)&&i(`customCorners.modifyCorners`,`Unexpected empty curve stack during close-and-fillet`),s(e,t)}return new zL(o)}function eJ(e,t,n,r){return t instanceof zL?$q(e,t,n,r):t instanceof rR?new rR(t.blueprints.map(t=>$q(e,t,n,r))):t instanceof nR?new nR(t.blueprints.map(t=>eJ(e,t,n,r)).filter(e=>e!==null)):null}function tJ(e,t,n){return eJ($L,e,t,n)}function nJ(e,t,n){return eJ(eR,e,t,n)}function rJ(e,t){return e instanceof zL?XK(t):e instanceof rR?ZK(t):new fq(t.map(e=>Array.isArray(e)?ZK(e):XK(e)))}var iJ=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 rR)return{type:`CompoundBlueprint`,blueprints:t.blueprints.map(e)};if(t instanceof nR)return{type:`Blueprints`,blueprints:t.blueprints.map(e)};if(t instanceof zL)return{type:`Blueprint`,curves:t.curves.map(e=>e.serialize())};i(`Drawing.serialize`,`Unknown shape type for serialization`)}return JSON.stringify(e(this.innerShape))}get boundingBox(){return this.innerShape?this.innerShape.boundingBox:new lL}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(dz(this.innerShape,t.innerShape))}fuse(t){return new e(lz(this.innerShape,t.innerShape))}intersect(t){return new e(fz(this.innerShape,t.innerShape))}fillet(t,n){let r=n&&n(TR());return new e(tJ(this.innerShape,t,r))}chamfer(t,n){let r=n&&n(TR());return new e(nJ(this.innerShape,t,r))}sketchOnPlane(e,t){this.innerShape||i(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnPlane(e,t);return rJ(this.innerShape,n)}sketchOnFace(e,t){this.innerShape||i(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnFace(e,t);return rJ(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(Zq(this.innerShape,t,n))}approximate(t,n={}){return t!==`svg`&&i(`Drawing.approximate`,`Only 'svg' is supported for now`),new e(Qq(this.innerShape,n))}get blueprint(){if(!(this.innerShape instanceof zL)){if(this.innerShape instanceof nR&&this.innerShape.blueprints.length===1&&this.innerShape.blueprints[0]instanceof zL)return this.innerShape.blueprints[0];i(`Drawing.blueprint`,`This drawing is not a blueprint`)}return this.innerShape}};function aJ(e){function t(e){if(e.type===`CompoundBlueprint`)return new rR(e.blueprints.map(t));if(e.type===`Blueprints`)return new nR(e.blueprints.map(t));if(e.type===`Blueprint`)return new zL(e.curves.map(e=>uL(e)));i(`Drawing.deserialize`,`Unknown shape type for deserialization`)}return new iJ(t(JSON.parse(e)))}var oJ=class extends yR{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new iJ(new zL(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 sJ(e){let t=new oJ;return e&&t.movePointerTo(e),t}function cJ(e,t,n=0){return new iJ(DR(e,t,n))}var lJ=cJ;function uJ(e){return new iJ(new zL([vL(e)]))}function dJ(e,t){let[n,r]=[e,t].sort((e,t)=>e-t);return new iJ(new zL([yL(r,n,r===e?[1,0]:[0,1])]))}function fJ(e){return sJ().movePointerTo([-e,0]).sagittaArc(2*e,0,e).sagittaArc(-2*e,0,e).close()}function pJ(e,t){return sJ().movePointerTo([-e,0]).halfEllipse(2*e,0,t).halfEllipse(-2*e,0,t).close()}function mJ(e,t,n=0){return new iJ(ER(e,t,n))}function hJ(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:i=`default`}={}){return new iJ(_q(e,{startX:t,startY:n,fontSize:r,fontFamily:i}))}var gJ=(e,t={},n={})=>{e.length<2&&i(`drawPointsInterpolation`,`Need at least 2 points for interpolation, got ${e.length}`);let r=[j(SL(e,t))],a=e[0],o=e[e.length-1];return n.closeShape&&a&&o&&!OI(a,o)&&r.push(hL(o,a)),new iJ(new zL(r))},_J=(e,{pointsCount:t=400,start:n=0,stop:r=1,closeShape:i=!1}={},a={})=>{let o=(r-n)/t;return gJ([...Array(t+1).keys()].map(t=>e(n+t*o)),a,{closeShape:i})},vJ=e=>{try{var t=LT();let n=t.u(new ZT),r=lJ(1e3,1e3).sketchOnPlane();n.register(r.wire);let i=n.register(j(PA(r.wire))),a=Eq(e.map(e=>FL(e,i))).map(e=>new zL(e));return a.length===0?new iJ:a.length===1?new iJ(a[0]):new iJ(new nR(a))}catch(e){t.e=e}finally{t.d()}};function yJ(e,t=`front`){let n;n=typeof t==`string`?j(wq(t)):t;let{visible:r,hidden:i}=Tq(e,n);try{return{visible:vJ(r),hidden:vJ(i)}}finally{for(let e of r)e[Symbol.dispose]();for(let e of i)e[Symbol.dispose]()}}function bJ(e){try{var t=LT();let n=t.u(new ZT),r=n.register(OE(j(fO(e.wrapped)))),i=Eq(dD(n.register(kO(r))).map(t=>FL(t,e))).map(e=>new zL(e));return i.length===0?new iJ:i.length===1?new iJ(i[0]):new iJ(new nR(i))}catch(e){t.e=e}finally{t.d()}}function xJ(e,t,n){return n===void 0?e.sketchOnPlane(t):e.sketchOnPlane(t,n)}function SJ(e,t){return e.fuse(t)}function CJ(e,t){return e.cut(t)}function wJ(e,t){return e.intersect(t)}function TJ(e,t,n){return e.fillet(t,n)}function EJ(e,t,n){return e.chamfer(t,n)}function DJ(e,t,n=0){return typeof t==`number`?e.translate(t,n):e.translate(t)}function OJ(e,t,n){return e.rotate(t,n)}function kJ(e,t,n){return e.scale(t,n)}function AJ(e,t,n,r){return e.mirror(t,n,r)}function jJ(e){let t=e.clone();return t.reverse(),t}function MJ(e){return e.boundingBox}function NJ(e){return e.firstPoint}function PJ(e){return e.lastPoint}function FJ(e,t,n){return e.splitAt(t,n)}function IJ(e,t,n){return e.parameter(t,n)}function LJ(e,t){return e.tangentAt(t)}function RJ(e,t){return e.isOnCurve(t)}function zJ(e,t){return e.distanceFrom(t)}function BJ(e){return e.length===0?k(P(M.BLUEPRINT_EMPTY_CURVES,`createBlueprint: at least one curve is required`)):O(new zL(e))}function VJ(e){return e.length===0?k(P(M.COMPOUND_BLUEPRINT_EMPTY,`createCompoundBlueprint: at least one blueprint (outer boundary) is required`)):O(new rR(e))}function HJ(e){return e.boundingBox}function UJ(e){return e.orientation}function WJ(e,t){return e.isInside(t)}function GJ(e){return e.toSVGPathD()}function KJ(e,t,n){return e.translate(t,n)}function qJ(e,t,n){return e.rotate(t,n)}function JJ(e,t,n){return e.scale(t,n)}function YJ(e,t,n,r){return e.mirror(t,n,r)}function XJ(e,t,n,r){return e.stretch(t,n,r)}function ZJ(e,t,n){return e.sketchOnPlane(t,n)}function QJ(e,t,n){return e.sketchOnFace(t,n)}function $J(e,t){return n(e,t*3)}function eY(e,t){return n(e,t)}function tY(e){let t=[`# brepjs OBJ export`],n=e.vertices.length/3;for(let r=0;r<n;r++){let[n,i,a]=$J(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]=$J(e.normals,n);t.push(`vn ${r} ${i} ${a}`)}let i=n=>{let[r,i,a]=eY(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
|
+
`)+`
|
|
26
|
+
`}var nY=5126,rY=5125,iY=34962,aY=34963,oY=[-Math.SQRT1_2,0,0,Math.SQRT1_2];function sY(e){return e===`Z`?[{mesh:0}]:[{name:`Z_up_to_Y_up`,rotation:oY,children:[1]},{mesh:0}]}function cY(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 lY(e){return e+3&-4}function uY(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 dY(e,t){let n=hY(e,`base64`,t);return JSON.stringify(n)}function fY(e,t){let{doc:n,binBuffer:r}=gY(e,t),i=JSON.stringify(n),a=new TextEncoder().encode(i),o=lY(a.length),s=new Uint8Array(o);s.set(a);for(let e=a.length;e<o;e++)s[e]=32;let c=lY(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 pY(e,t,n,r,i){return[{bufferView:0,componentType:rY,count:e.length,type:`SCALAR`},{bufferView:1,componentType:nY,count:t.length/3,type:`VEC3`,min:r,max:i},{bufferView:2,componentType:nY,count:n.length/3,type:`VEC3`}]}function mY(e,t,n){return[{buffer:0,byteOffset:0,byteLength:e,target:aY},{buffer:0,byteOffset:lY(e),byteLength:t,target:iY},{buffer:0,byteOffset:lY(e)+t,byteLength:n,target:iY}]}function hY(e,t,n){let{vertices:r,normals:i,triangles:a}=e,o=n?.materials;if(o&&o.size>0&&e.faceGroups.length>0)return SY(e,t,o,n.upAxis??`Y`);let s=a.byteLength,c=r.byteLength,l=i.byteLength,u=lY(s)+c+l,{min:d,max:f}=cY(r),p={asset:{version:`2.0`,generator:`brepjs`},scene:0,scenes:[{nodes:[0]}],nodes:sY(n?.upAxis??`Y`),meshes:[{primitives:[{attributes:{POSITION:1,NORMAL:2},indices:0}]}],accessors:pY(a,r,i,d,f),bufferViews:mY(s,c,l),buffers:[{byteLength:u}]};if(t===`base64`){let t=wY(e);p.buffers[0]={byteLength:u,uri:`data:application/octet-stream;base64,`+uY(t)}}return p}function gY(e,t){let n=t?.materials;if(n&&n.size>0&&e.faceGroups.length>0){let{doc:r,binBuffer:i}=CY(e,n,t.upAxis??`Y`);return{doc:r,binBuffer:i}}return{doc:hY(e,`glb`,t),binBuffer:wY(e)}}function _Y(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=vA(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+=vA(o,e).count;let i=new Uint32Array(r),s=0;for(let e of n){let n=vA(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=lY(f+t)}let m=f;return{primitiveData:d,indexBufferInfos:p,verticesOffset:m,totalByteLength:m+r.byteLength+i.byteLength,uniqueMaterials:s}}function vY(e,t,n,r){let{vertices:i,normals:a}=e,{min:o,max:s}=cY(i),c=r.length;r.push({buffer:0,byteOffset:t,byteLength:i.byteLength,target:iY});let l=n.length;n.push({bufferView:c,componentType:nY,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:iY});let d=n.length;return n.push({bufferView:u,componentType:nY,count:a.length/3,type:`VEC3`}),{verticesAccIdx:l,normalsAccIdx:d}}function yY(e,t,n,r,i,a){let o=[];for(let s=0;s<e.length;s++){let c=vA(e,s),l=vA(t,s),u=a.length;a.push({buffer:0,byteOffset:l.byteOffset,byteLength:l.byteLength,target:aY});let d=i.length;i.push({bufferView:u,componentType:rY,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 bY(e,t,n=`Y`){let{primitiveData:r,indexBufferInfos:i,verticesOffset:a,totalByteLength:o,uniqueMaterials:s}=t,c=[],l=[],{verticesAccIdx:u,normalsAccIdx:d}=vY(e,a,c,l),f=yY(r,i,u,d,c,l);return{asset:{version:`2.0`,generator:`brepjs`},scene:0,scenes:[{nodes:[0]}],nodes:sY(n),meshes:[{primitives:f}],accessors:c,bufferViews:l,buffers:[{byteLength:o}],materials:s}}function xY(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=vA(i,e),n=vA(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 SY(e,t,n,r=`Y`){let i=_Y(e,n),a=bY(e,i,r);if(t===`base64`){let t=xY(e,i);a.buffers[0]={byteLength:i.totalByteLength,uri:`data:application/octet-stream;base64,`+uY(t)}}return a}function CY(e,t,n=`Y`){let r=_Y(e,t);return{doc:bY(e,r,n),binBuffer:xY(e,r)}}function wY(e){let{vertices:t,normals:n,triangles:r}=e,i=r.byteLength,a=t.byteLength,o=n.byteLength,s=lY(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),lY(i)),l.set(new Uint8Array(n.buffer,n.byteOffset,o),lY(i)+a),c}function TY(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
|
+
`)+`
|
|
28
|
+
`}function EY(e,t){let n=t?.curveSegments??32,r=[],i=DY(e);for(let e of i)for(let t of e.curves)r.push(...OY(t,n));return TY(r,t)}function DY(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(...DY(n));return t}return[]}function OY(e,t){return e.geomType===`LINE`?[{type:`LINE`,start:e.firstPoint,end:e.lastPoint}]:[kY(e,t)]}function kY(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 AY=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;AY[e]=t}function jY(e){let t=4294967295;for(let n of e)t=(AY[(t^n)&255]??0)^t>>>8;return(t^4294967295)>>>0}function MY(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 NY(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 PY(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 FY(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=MY(s,c,l,e);for(let{offset:e,entry:t}of n)l=NY(s,c,l,e,t);return PY(s,l,e.length,r,i),o}function IY(e){return e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`)}function LY(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 RY(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 zY(e){let t=new Map,n=[];if(e!==void 0&&e.size>0)for(let r of e.values()){let e=LY(r);t.has(e)||(t.set(e,n.length),n.push(e))}return{colorIndexByHex:t,colorHexList:n}}function BY(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 VY(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=LY(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 HY(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 UY(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`:LY(e.displayColor);return` <base name="${IY(e.name)}" displaycolor="${t}" />`}).join(`
|
|
30
|
+
`);n.push(` <basematerials id="3">\n${e}\n </basematerials>`)}return n}function WY(e,t,n,r,i){let a=RY(e),{colorIndexByHex:o,colorHexList:s}=zY(r),{materialIndexByName:c,materialList:l}=BY(i),u=HY(e,VY(e,r,i,o,c)),d=UY(s,l);return`<?xml version="1.0" encoding="UTF-8"?>
|
|
31
|
+
<model unit="${n}" xmlns="http://schemas.microsoft.com/3dmanufacturing/core/2015/02"${l.length>0?`
|
|
32
|
+
xmlns:m="http://schemas.microsoft.com/3dmanufacturing/material/2015/02"`:``}>
|
|
33
|
+
<resources>${d.length>0?`
|
|
34
|
+
`+d.join(`
|
|
35
|
+
`):``}
|
|
36
|
+
<object id="1" name="${IY(t)}" type="model">
|
|
37
|
+
<mesh>
|
|
38
|
+
<vertices>
|
|
39
|
+
${a.join(`
|
|
40
|
+
`)}
|
|
41
|
+
</vertices>
|
|
42
|
+
<triangles>
|
|
43
|
+
${u.join(`
|
|
44
|
+
`)}
|
|
45
|
+
</triangles>
|
|
46
|
+
</mesh>
|
|
47
|
+
</object>
|
|
48
|
+
</resources>
|
|
49
|
+
<build>
|
|
50
|
+
<item objectid="1" />
|
|
51
|
+
</build>
|
|
52
|
+
</model>`}function GY(e,t={}){let{name:n=`model`,unit:r=`millimeter`,colors:i,materials:a}=t,o=new TextEncoder,s=WY(e,n,r,i,a);function c(e,t){let n=o.encode(e),r=o.encode(t);return{name:n,data:r,crc:jY(r)}}return FY([c(`[Content_Types].xml`,`<?xml version="1.0" encoding="UTF-8"?>
|
|
53
|
+
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
|
54
|
+
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
|
|
55
|
+
<Default Extension="model" ContentType="application/vnd.ms-package.3dmanufacturing-3dmodel+xml" />
|
|
56
|
+
</Types>`),c(`_rels/.rels`,`<?xml version="1.0" encoding="UTF-8"?>
|
|
57
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
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 KY(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 qY(e){return[e[0],-e[1]]}function JY(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(hL(qY([t.cx,t.cy]),qY([a,o]))),t.cx=a,t.cy=o,i+=2}}function YY(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(hL(qY([t.cx,t.cy]),qY([a,o]))),t.cx=a,t.cy=o,i+=2}}function XY(e,t,n,r){for(let i of e){let e=n?t.cx+i:i;r.push(hL(qY([t.cx,t.cy]),qY([e,t.cy]))),t.cx=e}}function ZY(e,t,n,r){for(let i of e){let e=n?t.cy+i:i;r.push(hL(qY([t.cx,t.cy]),qY([t.cx,e]))),t.cy=e}}function QY(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(xL(qY([t.cx,t.cy]),[qY([s,c]),qY([l,u])],qY([d,f]))),t.prevControlX=l,t.prevControlY=u,t.cx=d,t.cy=f,i+=6}}function $Y(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(xL(qY([t.cx,t.cy]),[qY([c,l]),qY([u,d])],qY([f,p]))),t.prevControlX=u,t.prevControlY=d,t.cx=f,t.cy=p,t.lastCmd=`S`,i+=4}}function eX(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(xL(qY([t.cx,t.cy]),[qY([s,c])],qY([l,u]))),t.prevControlX=s,t.prevControlY=c,t.cx=l,t.cy=u,i+=4}}function tX(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(xL(qY([t.cx,t.cy]),[qY([c,l])],qY([u,d]))),t.prevControlX=c,t.prevControlY=l,t.cx=u,t.cy=d,t.lastCmd=`T`,i+=2}}function nX(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[gL(qY([e,t]),qY(c),qY([e,s])),gL(qY([e,s]),qY(l),qY([e,t]))]}catch{return[]}}function rX(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[gL(qY([e,t]),qY([b,x]),qY([n,r]))]}catch{return[hL(qY([e,t]),qY([n,r]))]}}function iX(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(hL(qY([t.cx,t.cy]),qY([d,f])));else{let e=d-t.cx,n=f-t.cy;Math.sqrt(e*e+n*n)<1e-10?r.push(...nX(t.cx,t.cy,s,c,u)):r.push(...rX(t.cx,t.cy,d,f,s,c,l,u))}t.cx=d,t.cy=f,i+=7}}function aX(e,t){(Math.abs(e.cx-e.sx)>1e-10||Math.abs(e.cy-e.sy)>1e-10)&&t.push(hL(qY([e.cx,e.cy]),qY([e.sx,e.sy]))),e.cx=e.sx,e.cy=e.sy}function oX(e){let t=KY(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`:JY(i,r,t,n);break;case`L`:YY(i,r,t,n);break;case`H`:XY(i,r,t,n);break;case`V`:ZY(i,r,t,n);break;case`C`:QY(i,r,t,n);break;case`S`:$Y(i,r,t,n);break;case`Q`:eX(i,r,t,n);break;case`T`:tX(i,r,t,n);break;case`A`:iX(i,r,t,n);break;case`Z`:aX(r,n);break}a!==`S`&&a!==`T`&&(r.lastCmd=a)}return n}function sX(e){try{let t=oX(e);return t.length===0?k(Oo(`SVG_EMPTY_PATH`,`SVG path produced no curves`)):O(new zL(t))}catch(e){return k(Oo(`SVG_PARSE_FAILED`,`Failed to parse SVG path: ${e instanceof Error?e.message:String(e)}`))}}function cX(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=sX(l);u.ok&&n.push(u.value)}return n.length===0?k(Oo(`SVG_NO_PATHS`,`No <path> elements found in SVG`)):O(n)}catch(e){return k(Oo(`SVG_IMPORT_FAILED`,`Failed to import SVG: ${e instanceof Error?e.message:String(e)}`))}}function lX(e,t){try{let n=H(),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(Oo(M.STEP_EXPORT_CONFIGURED_FAILED,`Configured STEP export failed`,e))}}async function uX(e){try{let t=await e.arrayBuffer(),n=H().importSTEP(t);if(n.length===0)return k(Oo(`STEP_IMPORT_FAILED`,`STEP file contains no valid geometry`));for(let e=1;e<n.length;e++){let t=n[e];t&&H().dispose(t)}return O(U(n[0]))}catch(e){return k(Oo(`STEP_IMPORT_FAILED`,`Failed to load STEP file`,e))}}async function dX(e){try{let t=await e.arrayBuffer(),n=H().importSTL(t);return n.IsNull()?k(Oo(`STL_IMPORT_FAILED`,`Failed to create solid from STL mesh`)):O(U(n))}catch(e){return k(Oo(`STL_IMPORT_FAILED`,`Failed to load STL file`,e))}}async function fX(e){try{let t=await e.arrayBuffer(),n=H().importIGES(t);if(n.length===0)return k(Oo(`IGES_IMPORT_FAILED`,`IGES file contains no valid geometry`));for(let e=1;e<n.length;e++){let t=n[e];t&&H().dispose(t)}return O(U(n[0]))}catch(e){return k(Oo(`IGES_IMPORT_FAILED`,`Failed to load IGES file`,e))}}function pX(e,t,n={}){let r=_q(e,t);return new fq((typeof n.plane==`string`||n.plane===void 0?r.sketchOnPlane(n.plane,n.origin):r.sketchOnPlane(n.plane)).map(e=>Array.isArray(e)?new YK(e.map(XK)):XK(e)))}function mX(e,t){let n=t?.fontSize??1,r=hq(t?.fontFamily);if(!r)return k(P(M.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 hX(e){let t=e?.fontSize??1,n=hq(e?.fontFamily);if(!n)return k(P(M.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 gX(e){return e.type===`init`}function _X(e){return e.type===`operation`}function vX(e){return e.type===`dispose`}function yX(e){return e.type===`batch`}function bX(e){return e.success}function xX(e){return!e.success}function SX(){return{pending:new Map}}function CX(e,t){let n=new Map(e.pending);return n.set(t.id,t),{pending:n}}function wX(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 TX(e){return e.pending.size}function EX(e){return e.pending.size===0}function DX(e,t){for(let n of e.pending.values())n.reject(t);return{pending:new Map}}function OX(e,t){let n=t.data,r=e.get(n.id);if(r)if(e.delete(n.id),bX(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 kX(e){let{worker:t,wasmUrl:n}=e,r=new Map,i=!1;function a(){return crypto.randomUUID()}function o(e){OX(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})},executeBatch(e){let t=e.length;return s({id:a(),type:`batch`,operations:e}).then(e=>{let n=e.resultData;if(!Array.isArray(n)||n.length!==t)throw Error(`Invalid batch response: expected ${t} results`);return 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 AX(){return{operations:new Map}}function jX(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function MX(e){return e instanceof Error?e.message:String(e)}function NX(e,t,n,r){let i=e.operations.get(t);if(!i)return{success:!1,error:`Unknown operation: ${t}`};try{let e=i(n,r);return{success:!0,...e.resultBrep===void 0?{}:{resultBrep:e.resultBrep},...e.resultData===void 0?{}:{resultData:e.resultData}}}catch(e){return{success:!1,error:MX(e)}}}function PX(e,t){return t.success?{id:e,success:!0,...t.resultBrep===void 0?{}:{resultBrep:t.resultBrep},...t.resultData===void 0?{}:{resultData:t.resultData}}:{id:e,success:!1,error:t.error??`operation failed`}}function FX(e,t){let n=globalThis;n.onmessage=async r=>{let i=r.data;if(gX(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:MX(e)};n.postMessage(t)}return}if(_X(i)){let t=NX(e,i.operation,i.shapesBrep,i.parameters);n.postMessage(PX(i.id,t));return}if(yX(i)){let t=i.operations.map(t=>NX(e,t.operation,t.shapesBrep,t.params)),r={id:i.id,success:!0,resultData:t};n.postMessage(r);return}if(vX(i)){let e={id:i.id,success:!0};n.postMessage(e),n.close?.()}}}function IX(e){let{workers:t,wasmUrl:n}=e;if(t.length===0)throw Error(`createWorkerPool requires at least one worker`);let r=t.map(e=>({client:kX({worker:e,...n===void 0?{}:{wasmUrl:n}}),inFlight:0})),i=!1;function a(){return r.reduce((e,t)=>t.inFlight<e.inFlight?t:e)}function o(e,t,n){if(i)return Promise.reject(Error(`WorkerPool has been disposed`));let r=a();return r.inFlight+=1,r.client.execute(e,t,n).finally(()=>{--r.inFlight})}function s(){if(!i){i=!0;for(let e of r)e.client.dispose()}}return{size:r.length,async init(){try{await Promise.all(r.map(e=>e.client.init()))}catch(e){throw s(),e}},execute:o,executeBatch(e){return Promise.all(e.map(e=>o(e.operation,e.shapesBrep,e.params)))},inFlight(){return r.map(e=>e.inFlight)},dispose:s}}var LX=Object.defineProperty,RX=(e,t)=>{let n={};for(var r in e)LX(n,r,{get:e[r],enumerable:!0});return t||LX(n,Symbol.toStringTag,{value:`Module`}),n},zX=1,BX=2;function VX(e,t){t===`commonFace`&&e.SetGlue(zX),t===`sameFace`&&e.SetGlue(BX)}function HX(e){return typeof e==`number`}function UX(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 WX(e){return typeof e==`number`?!0:Array.isArray(e)&&e.length===2?e.every(HX):!1}function GX(e,t){let n=n=>{let r=e.findAll(n);if(r.length===0)return[];let i=0,a=UD(AD(yA(r)),t);for(let e=1;e<r.length;e++){let n=UD(AD(vA(r,e)),t);n<a&&(a=n,i=e)}return[vA(r,i)]},r=e=>{let t=n(e);return t.length===0?k(ko(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found 0 element(s)`)):O(yA(t))};return{...e,findAll:n,findUnique:r}}function KX(e){return UI(`vertex`,e,KX,(t,n)=>({nearestTo:t=>GX(KX(e),t),atPosition:(e,t=1e-4)=>n(n=>UD(AD(n),e)<t),withinBox:(e,t)=>n(n=>{let r=AD(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=AD(n);return Math.abs(UD(i,t)-e)<r})}))}function qX(){return KX([])}var JX=new Map,YX=null,XX=null;function ZX(e,t){JX.set(e,t),YX||=e,e===YX&&(XX=t)}function QX(e){if(!e&&XX)return XX;let t=e??YX;if(!t)throw Error(`brepjs voxel engine not initialized. Call initVoxel() (or registerVoxel()) before using voxel operations.`);let n=JX.get(t);if(!n)throw Error(`brepjs: voxel engine '${t}' is not registered.`);return n}function $X(){return YX}function eZ(e,t=`voxel`){ZX(t,e),YX=t,XX=e}function tZ(e){if(e.vertices.length%3!=0)return P(`VOXEL_INVALID_MESH`,`mesh.vertices length must be a multiple of 3 (flat xyz).`);if(e.triangles.length%3!=0)return P(`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 P(`VOXEL_INVALID_TRIANGLE_INDEX`,`triangle index ${r} at position ${n} is out of range for ${t} vertices.`)}return null}function nZ(e,t){return tZ(e)||(t.length%3==0?null:P(`VOXEL_INVALID_QUERIES`,`queries length must be a multiple of 3 (flat xyz).`))}function rZ(e){try{return O(QX(e))}catch(e){return k(Eo(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function iZ(e,t,n){let r=nZ(e,t);if(r)return k(r);let i=rZ(n);return A(i)?i:O(i.value.winding_numbers(e.vertices,e.triangles,t))}function aZ(e,t,n){let r=nZ(e,t);if(r)return k(r);let i=rZ(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 oZ=48,sZ=2;function cZ(e,t,n){let r=tZ(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`repairMesh requires a non-empty triangle mesh.`));let i=t?.resolution??oZ,a=t?.padding??sZ;if(!Number.isInteger(i)||i<1)return k(P(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`));if(!Number.isInteger(a)||a<1)return k(P(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`));let o=rZ(n);if(A(o))return o;try{try{var s=LT();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(Do(`VOXEL_REPAIR_FAILED`,e instanceof Error?e.message:`voxel repair failed (grid too large?).`,e))}}var lZ=.001;function uZ(e,t=lZ){try{let n=rA(e,{tolerance:t});return n.vertices.length===0||n.triangles.length===0?k(Do(`VOXEL_SHAPE_MESH_EMPTY`,`shape tessellated to an empty triangle mesh.`)):O({vertices:n.vertices,triangles:n.triangles})}catch(e){return k(Do(`VOXEL_SHAPE_MESH_FAILED`,e instanceof Error?e.message:`failed to mesh shape for voxel op.`,e))}}var dZ=48,fZ=2,pZ={union:0,intersection:1,difference:2};function mZ(e){let t=e?.resolution??dZ,n=e?.padding??fZ;return!Number.isInteger(t)||t<1?k(P(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(P(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function hZ(e){if(e.positions.length===0||e.indices.length===0)return k(Do(`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 gZ(e,t,n,r){let i=tZ(e);if(i)return k(i);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`offsetMesh requires a non-empty triangle mesh.`));if(!Number.isFinite(t))return k(P(`VOXEL_INVALID_DISTANCE`,`distance must be a finite number.`));let a=mZ(n);if(A(a))return a;let o=rZ(r);if(A(o))return o;try{try{var s=LT();return hZ(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(Do(`VOXEL_OFFSET_FAILED`,e instanceof Error?e.message:`voxel offset failed (grid too large?).`,e))}}function _Z(e,t,n,r){let i=tZ(e);if(i)return k(i);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`shellMesh requires a non-empty triangle mesh.`));if(!Number.isFinite(t)||t<=0)return k(P(`VOXEL_INVALID_THICKNESS`,`thickness must be a finite number > 0.`));let a=mZ(n);if(A(a))return a;let o=rZ(r);if(A(o))return o;try{try{var s=LT();return hZ(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(Do(`VOXEL_SHELL_FAILED`,e instanceof Error?e.message:`voxel shell failed (grid too large?).`,e))}}function vZ(e,t,n,r,i){let a=tZ(e);if(a)return k(a);let o=tZ(t);if(o)return k(o);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`voxelBoolean requires a non-empty mesh for operand A.`));if(t.vertices.length===0||t.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`voxelBoolean requires a non-empty mesh for operand B.`));let s=pZ[n],c=mZ(r);if(A(c))return c;let l=rZ(i);if(A(l))return l;try{try{var u=LT();return hZ(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(Do(`VOXEL_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel boolean failed (grid too large?).`,e))}}function yZ(e,t,n,r){let i=uZ(e);return A(i)?i:gZ(i.value,t,n,r)}function bZ(e,t,n,r){let i=uZ(e);return A(i)?i:_Z(i.value,t,n,r)}function xZ(e,t,n,r,i){let a=uZ(e);if(A(a))return a;let o=uZ(t);return A(o)?o:vZ(a.value,o.value,n,r,i)}var SZ=48,CZ=2,wZ={union:0,intersection:1,difference:2};function TZ(e){let t=e?.resolution??SZ,n=e?.padding??CZ;return!Number.isInteger(t)||t<1?k(P(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(P(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function EZ(e){try{var t=LT();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(Do(`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 DZ(e){return{raw:e,delete(){e.free()}}}function OZ(e){return kZ(e)}function kZ(e){let t=XT(DZ(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,wZ[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=EZ(this.value);if(A(e))throw Error(e.error.message);return e.value}};return n}function AZ(e){return!e.disposed}function jZ(){return k(P(`VOXEL_FIELD_DISPOSED`,`the voxel field handle has been disposed.`))}function MZ(e,t,n){let r=tZ(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`voxelField requires a non-empty triangle mesh.`));let i=TZ(t);if(A(i))return i;let a=rZ(n);if(A(a))return a;try{return O(kZ(new a.value.VoxelField(e.vertices,e.triangles,i.value.resolution,i.value.padding)))}catch(e){return k(Do(`VOXEL_FIELD_VOXELIZE_FAILED`,e instanceof Error?e.message:`voxel field voxelization failed (grid too large or non-dense?).`,e))}}function NZ(e,t,n,r,i){let a=tZ(e);if(a)return k(a);let o=tZ(t);if(o)return k(o);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`voxelBooleanField requires a non-empty mesh for operand A.`));if(t.vertices.length===0||t.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`voxelBooleanField requires a non-empty mesh for operand B.`));let s=TZ(r);if(A(s))return s;let c=rZ(i);if(A(c))return c;try{return O(kZ(c.value.VoxelField.boolean_of(e.vertices,e.triangles,t.vertices,t.triangles,wZ[n],s.value.resolution,s.value.padding)))}catch(e){return k(Do(`VOXEL_FIELD_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel field boolean failed (grid too large or non-dense?).`,e))}}function PZ(e,t,n){if(!AZ(e)||!AZ(t))return jZ();try{return e.value.boolean(t.value,wZ[n]),O(e)}catch(e){return k(Do(`VOXEL_FIELD_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel field boolean failed (dim mismatch?).`,e))}}function FZ(e,t){if(!AZ(e))return jZ();if(!Number.isFinite(t))return k(P(`VOXEL_INVALID_DISTANCE`,`distance must be a finite number.`));try{return e.value.offset(t),O(e)}catch(e){return k(Do(`VOXEL_FIELD_OFFSET_FAILED`,e instanceof Error?e.message:`voxel field offset failed.`,e))}}function IZ(e,t){if(!AZ(e))return jZ();if(!Number.isFinite(t)||t<=0)return k(P(`VOXEL_INVALID_THICKNESS`,`thickness must be a finite number > 0.`));try{return e.value.shell(t),O(e)}catch(e){return k(Do(`VOXEL_FIELD_SHELL_FAILED`,e instanceof Error?e.message:`voxel field shell failed.`,e))}}function LZ(e){if(!AZ(e))return jZ();try{return e.value.reinit(),O(e)}catch(e){return k(Do(`VOXEL_FIELD_REINIT_FAILED`,e instanceof Error?e.message:`voxel field reinit failed.`,e))}}function RZ(e){if(!AZ(e))return jZ();try{return EZ(e.value)}catch(e){return k(Do(`VOXEL_FIELD_CONTOUR_FAILED`,e instanceof Error?e.message:`voxel field contour failed.`,e))}}function zZ(e,t,n){let r=uZ(e);return A(r)?r:MZ(r.value,t,n)}function BZ(e,t,n,r,i){let a=uZ(e);if(A(a))return a;let o=uZ(t);return A(o)?o:NZ(a.value,o.value,n,r,i)}var VZ=48,HZ=2;function UZ(e){try{return O(QX(e))}catch(e){return k(Eo(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function WZ(e){let t=e?.resolution??VZ,n=e?.padding??HZ;return!Number.isInteger(t)||t<1?k(P(`SDF_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(P(`SDF_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function GZ(e){return{raw:e,delete(){e.free()}}}var KZ={offsetField(e){return qZ(this.value.offset_field(e.value))},roundField(e){return qZ(this.value.round_field(e.value))},shellField(e){return qZ(this.value.shell_field(e.value))},smoothUnionField(e,t){return qZ(this.value.smooth_union_field(e.value,t.value))}};function qZ(e){let t=XT(GZ(e));return{get value(){return t.value.raw},get disposed(){return t.disposed},[Symbol.dispose](){t[Symbol.dispose]()},union(e){return qZ(this.value.union(e.value))},intersection(e){return qZ(this.value.intersection(e.value))},difference(e){return qZ(this.value.difference(e.value))},smoothUnion(e,t){return qZ(this.value.smooth_union(e.value,t))},smoothIntersection(e,t){return qZ(this.value.smooth_intersection(e.value,t))},smoothDifference(e,t){return qZ(this.value.smooth_difference(e.value,t))},offset(e){return qZ(this.value.offset(e))},round(e){return qZ(this.value.round(e))},shell(e){return qZ(this.value.shell(e))},onion(e){return qZ(this.value.onion(e))},...KZ,translate(e,t,n){return qZ(this.value.translate(e,t,n))},rotate(e,t,n,r){return qZ(this.value.rotate(e,t,n,r))},scale(e){return qZ(this.value.scale(e))},rasterize(e){return JZ(this.value,e)},rasterizeIn(e,t){return YZ(this.value,e,t)}}}function JZ(e,t){let n=WZ(t);if(A(n))return n;try{return O(OZ(e.rasterize(n.value.resolution,n.value.padding)))}catch(e){return XZ(e)}}function YZ(e,t,n){let r=WZ(n);if(A(r))return r;let i=ZZ(t);if(i)return k(i);try{return O(OZ(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 XZ(e)}}function XZ(e){return k(Do(`SDF_RASTERIZE_FAILED`,e instanceof Error?e.message:`SDF rasterization failed (grid too large?).`,e))}function ZZ(e){if(![...e.min,...e.max].every(e=>Number.isFinite(e)))return P(`SDF_INVALID_BOUNDS`,`bounds must be finite numbers.`);for(let t=0;t<3;t++)if(e.max[t]<=e.min[t])return P(`SDF_INVALID_BOUNDS`,`bounds max must exceed min on every axis.`);return null}function QZ(e,t){let n=UZ(t);if(A(n))return n;try{return O(qZ(e(n.value)))}catch(e){return k(Do(`SDF_BUILD_FAILED`,e instanceof Error?e.message:`SDF primitive construction failed.`,e))}}function $Z(e,t){return QZ(t=>t.Sdf.sphere(e),t)}function eQ(e,t,n,r){return QZ(r=>r.Sdf.box_(e,t,n),r)}function tQ(e,t,n,r,i){return QZ(i=>i.Sdf.rounded_box(e,t,n,r),i)}function nQ(e,t,n){return QZ(n=>n.Sdf.cylinder(e,t),n)}function rQ(e,t,n){return QZ(n=>n.Sdf.cone(e,t),n)}function iQ(e,t,n,r){return QZ(r=>r.Sdf.capsule(e[0],e[1],e[2],t[0],t[1],t[2],n),r)}function aQ(e,t,n){return QZ(n=>n.Sdf.torus(e,t),n)}function oQ(e,t,n){return QZ(n=>n.Sdf.plane(e[0],e[1],e[2],t),n)}function sQ(e){if(e.length<2)return k(P(`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(P(`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 cQ(e,t,n,r){let i=sQ(e);if(A(i))return i;let a=n?.closed??!1;return QZ(e=>e.Sdf.sweep(i.value,t.value,a),r)}var lQ={gyroid:0,schwarzP:1,diamond:2};function uQ(e,t,n,r){let i=lQ[e];return i===void 0?k(P(`SDF_INVALID_LATTICE_KIND`,`unknown lattice kind: ${e}`)):QZ(e=>e.Sdf.lattice(i,t.value,n.value),r)}function dQ(e,t,n){return QZ(n=>n.Sdf.strut_lattice(e,t.value),n)}function fQ(e){return{raw:e,delete(){e.free()}}}function pQ(e){let t=XT(fQ(e));return{get value(){return t.value.raw},get disposed(){return t.disposed},[Symbol.dispose](){t[Symbol.dispose]()}}}function mQ(e,t){let n=UZ(t);if(A(n))return n;try{return O(pQ(e(n.value)))}catch(e){return k(Do(`SDF_FIELD_BUILD_FAILED`,e instanceof Error?e.message:`scalar field construction failed.`,e))}}function hQ(e,t){return mQ(t=>t.ScalarField.constant(e),t)}function gQ(e,t,n,r,i,a){return mQ(a=>a.ScalarField.axial_ramp(e,t,n,r,i),a)}function _Q(e,t,n,r,i,a,o){return mQ(o=>o.ScalarField.radial_ramp(e[0],e[1],e[2],t,n,r,i,a),o)}function vQ(e,t,n,r){return mQ(r=>r.ScalarField.from_sdf(e.value,t,n),r)}function yQ(e,t,n,r){return mQ(r=>r.ScalarField.clamp(e.value,t,n),r)}var bQ={gyroid:0,schwarzP:1,diamond:2},xQ=48,SQ=2;function CQ(e){let t=bQ[e.type];if(t===void 0)return k(P(`LATTICE_INVALID_TYPE`,`lattice type must be one of gyroid, schwarzP, diamond (got '${e.type}').`));if(!(e.period>0))return k(P(`LATTICE_INVALID_PERIOD`,`period must be > 0.`));if(!(e.thickness>0))return k(P(`LATTICE_INVALID_THICKNESS`,`thickness must be > 0.`));let n=e.resolution??xQ,r=e.padding??SQ;return!Number.isInteger(n)||n<1?k(P(`LATTICE_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(r)||r<1?k(P(`LATTICE_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({tag:t,period:e.period,thickness:e.thickness,resolution:n,padding:r})}function wQ(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 TQ(e,t,n){let r=tZ(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(P(`LATTICE_EMPTY_MESH`,`latticeInfill requires a non-empty triangle mesh.`));let i=CQ(t);if(A(i))return i;let a=rZ(n);if(A(a))return a;let{tag:o,period:s,thickness:c,resolution:l,padding:u}=i.value;try{try{var d=LT();return O(wQ(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(Do(`LATTICE_INFILL_FAILED`,e instanceof Error?e.message:`lattice infill failed (grid too large?).`,e))}}function EQ(e,t,n){let r=uZ(e);return A(r)?r:TQ(r.value,t,n)}function DQ(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(P(`LATTICE_INVALID_BOUNDS`,`bounds.min must be strictly less than bounds.max on every axis (axis ${t}).`))}let r=CQ(t);if(A(r))return r;let i=rZ(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=LT();return O(wQ(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(Do(`TPMS_LATTICE_FAILED`,e instanceof Error?e.message:`tpms lattice failed (grid too large?).`,e))}}function OQ(e){return H().createVector3d(e[0],e[1],e[2])}function kQ(e){return H().createPoint3d(e[0],e[1],e[2])}function AQ(e){return H().createDirection3d(e[0],e[1],e[2])}function jQ(e){return[e.X(),e.Y(),e.Z()]}function MQ(e){return[e.X(),e.Y(),e.Z()]}function NQ(e){return[e.X(),e.Y(),e.Z()]}function PQ(e,t){let n=OQ(e);try{return t(n)}finally{n.delete()}}function FQ(e,t){let n=kQ(e);try{return t(n)}finally{n.delete()}}function IQ(e,t){let n=AQ(e);try{return t(n)}finally{n.delete()}}var LQ=.299,RQ=.587,zQ=.114;function BQ(e,t={}){if(e.length<2)return k(P(M.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(P(M.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(P(M.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 VQ(e,n,r,s,c,o)}catch{}try{return HQ(e,n,r,s,c,o)}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.SURFACE_FAILED,`surfaceFromGrid failed: ${t}`,e))}}function VQ(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=U(H().bsplineSurface(o,t,n));return IE(s)?O(s):(W(s),k(N(M.SURFACE_FAILED,`B-spline surface did not produce a face`)))}function HQ(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=U(H().triangulatedSurface(o,t,n));return IE(s)||LE(s)?O(s):(W(s),k(N(M.SURFACE_FAILED,`surfaceFromGrid: unexpected shape type from sewing`)))}async function UQ(e,t={}){let n=t.channel??`luminance`,r=Math.max(1,Math.round(t.downsample??1));if(typeof createImageBitmap!=`function`)return k(Oo(M.SURFACE_FAILED,`surfaceFromImage requires createImageBitmap (not available in this environment)`));let i;try{i=await createImageBitmap(e)}catch(e){return k(Oo(M.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(P(M.SURFACE_GRID_TOO_SMALL,`surfaceFromImage: image too small (${a}x${o}), need at least 2x2`));if(typeof OffscreenCanvas!=`function`)return i.close(),k(Oo(M.SURFACE_FAILED,`surfaceFromImage requires OffscreenCanvas (not available in this environment)`));let s=new OffscreenCanvas(a,o).getContext(`2d`);if(!s)return i.close(),k(Oo(M.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=(LQ*o+RQ*s+zQ*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),BQ(l,u)}function WQ(e,t){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function GQ(e,t={}){if(e.length===0)return k(P(M.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=WQ(n,`hull: shapes[${t}]`);if(A(e))return e}let n=t.tolerance??.1;try{let t=H(),r=e.map(e=>e.wrapped),i=U(t.hull(r,n));return RE(i)?O(i):(W(i),k(N(M.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(N(M.HULL_DEGENERATE,`Hull degenerate: ${t}`,e)):k(N(M.HULL_FAILED,`Hull operation failed: ${t}`,e))}}function KQ(e){if(e.length<4)return k(P(M.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=H(),n=e.map(e=>({x:e[0],y:e[1],z:e[2]})),r=U(t.hullFromPoints(n,.1));return RE(r)?O(r):(W(r),k(N(M.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(N(M.HULL_DEGENERATE,`convexHull degenerate: ${t}`,e)):k(N(M.HULL_FAILED,`convexHull failed: ${t}`,e))}}function qQ(e){let n=fD(e);if(n.length!==1)return null;let r=t(n,0);if(DD(r)!==`sphere`)return null;let i=H().area(r.wrapped);return Math.sqrt(i/(4*Math.PI))}function JQ(e,t,n){try{let r=U(H().offset(e.wrapped,t,n));return BE(r)?O(r):(W(r),k(wo(M.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(N(M.MINKOWSKI_FAILED,`Minkowski sphere offset failed: ${t}`,e,{operation:`minkowski`,fastPath:`sphere`}))}}function YQ(e,t,n){let r=H();try{let i=mD(e),a=mD(t);if(i.length===0||a.length===0)return k(N(M.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=U(r.hullFromPoints(o,n));return BE(s)?O(s):(W(s),k(wo(M.MINKOWSKI_NOT_3D,`Minkowski hull did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.MINKOWSKI_FAILED,`Minkowski general path failed: ${t}`,e,{operation:`minkowski`}))}}function XQ(e,t,n={}){let{tolerance:r=1e-6}=n;if(H().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`minkowski: shape is a null shape`));if(H().isNull(t.wrapped))return k(P(M.MINKOWSKI_NULL_TOOL,`minkowski: tool is a null shape`));if(!BE(e)||!BE(t))return k(P(M.MINKOWSKI_NOT_3D,`minkowski: both shape and tool must be 3D`));let i=qQ(t);return i===null?YQ(e,t,r):JQ(e,i,r)}function ZQ(e,t,n={}){let{tolerance:r=1e-6}=n;if(e.length<4)return k(P(M.POLYHEDRON_INSUFFICIENT_POINTS,`polyhedron: need at least 4 points, got ${e.length}`));if(t.length<4)return k(P(M.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(P(M.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=H(),n=e.map(([e,t,n])=>({x:e,y:t,z:n})),a=U(t.buildSolidFromFaces(n,i,r));return RE(a)?O(a):(W(a),k(N(M.POLYHEDRON_FAILED,`Polyhedron did not produce a solid`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.POLYHEDRON_FAILED,`Polyhedron failed: ${t}`,e))}}var QQ=1e-10;function $Q(e,t,n,r){return e*r-t*n}function e$(e,t,n,r){return e*n+t*r}function t$(e,t){return Math.sqrt(e*e+t*t)}function n$(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 r$(e){let t=0;for(let n=0;n<e.length;n++){let r=n$(e,n),i=n$(e,n+1);t+=r.x*i.y-i.x*r.y}return t<0?[...e].reverse():e}function i$(e,t){let n=n$(e,t-1),r=n$(e,t),i=n$(e,t+1),a=r.x-n.x,o=r.y-n.y,s=t$(a,o),c=i.x-r.x,l=i.y-r.y,u=t$(c,l);if(s<QQ||u<QQ)return{dx:0,dy:0};let d=-o/s,f=a/s,p=-l/u,m=c/u,h=d+p,g=f+m,_=t$(h,g);if(_<QQ)return{dx:d,dy:f};h/=_,g/=_;let v=e$(h,g,d,f),y=Math.abs(v)>QQ?1/v:1;return{dx:h*y,dy:g*y}}function a$(e){return!e.prev||!e.next?!1:$Q(e.x-e.prev.x,e.y-e.prev.y,e.next.x-e.x,e.next.y-e.y)<-1e-10}function o$(e){let t=e.map((t,n)=>{let r=i$(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 s$(e,t){let n=e;for(let e=0;e<t&&n;e++)n.active=!1,n=n.next}function c$(e){let t=1,n=e.next;for(;n!==e&&(t++,n=n.next,!(t>1e4)););return t}function l$(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)<QQ&&Math.abs(r)<QQ)return null;let o;if(o=Math.abs(n)>Math.abs(r)?i/n:a/r,o<QQ)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)>QQ){let e=c/s;if(Math.abs(o-e)>1e-4*Math.max(1,Math.abs(o)))return null}return o}function u$(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=t$(r,i);if(a<QQ)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)<QQ)return null;let f=-c/d;if(f<QQ)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=t$(y,b);if(x<QQ)return f;let S=e$(p-h,m-g,y,b)/(x*x);return S<-.01||S>1.01?null:f}function d$(e){let t=[];for(let n of e){if(!n.active||!n.next)continue;let e=l$(n,n.next);if(e!==null&&e>QQ){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(a$(n)){let e=n.next.next,r=0;for(;e!==n.prev&&e!==n&&r<1e3;){let i=u$(n,e,e.next);if(i!==null&&i>QQ){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 f$(e){if(e.length<3)return O({nodes:[],faces:[]});try{return O(p$(e))}catch(e){return k(Do(M.STRAIGHT_SKELETON_FAILED,e instanceof Error?e.message:String(e),e))}}function p$(e){let t=r$(e),n=t.length,r=[],i=Array.from({length:n},()=>[]),a=o$(t),o=0,s=n*n*2;for(;o<s;){o++;let e=a.find(e=>e.active);if(!e)break;let t=c$(e);if(t<=3){if(t===3){let t=e,n=t.next,a=n.next,o=l$(t,n),s=o!==null&&o>QQ?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 s$(e,t);continue}let n=a.filter(e=>e.active),s=d$(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=i$(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=i$(f(e),0);e.bx=p.dx,e.by=p.dy;let m=i$(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=[n$(t,e),n$(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&&t$(n.x-i.x,n.y-i.y)>QQ&&(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 m$(e){let t=dD(e).map(e=>{let t=Nk(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 h$(e){let t=[];for(let n=1;n<e-1;n++)t.push([0,n,n+1]);return t}function g$(e,t,n,r,i,a){return(n-e)*(a-t)-(r-t)*(i-e)}function _$(e,t,n,r,i,a,o,s){let c=g$(n,r,i,a,e,t),l=g$(i,a,o,s,e,t),u=g$(o,s,n,r,e,t);return!((c<0||l<0||u<0)&&(c>0||l>0||u>0))}function v$(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||g$(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&&_$(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 y$(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=h$(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 b$(e,t){let n=(t?.angle??45)*YE,r=Math.tan(n);try{let t=m$(e);if(t.length<3)return k(N(M.ROOF_FAILED,`Wire must have at least 3 edges for roof generation`));let n=f$(t);if(!n.ok)return n;let i=n.value;if(i.faces.length===0)return k(N(M.ROOF_FAILED,`Straight skeleton computation produced no faces`));let a=H(),o=y$(i,r,a);for(let[e,n,r]of v$(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(N(M.ROOF_FAILED,`No valid triangular faces could be built`));try{let e=a.sewAndSolidify(o,1e-6),t=a.fixShape(e);return t!==e&&a.dispose(e),O(AE(t))}catch(e){try{let t=AE(a.sew(o,1e-6));return hE(t)?O(t):k(N(M.ROOF_FAILED,`Sew fallback produced invalid solid`,e))}catch(e){return k(N(M.ROOF_FAILED,`Failed to sew roof faces`,e))}}finally{for(let e of o)a.dispose(e)}}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.ROOF_FAILED,`Roof generation failed: ${t}`,e))}}function x$(e){return[[1,0,0,e[0]],[0,1,0,e[1]],[0,0,1,e[2]],[0,0,0,1]]}function S$(e){let t=e[0];return t!==void 0&&typeof t[0]==`number`}function C$(e,t,n){return{__instanced:!0,source:e,placements:t,grid:n,[Symbol.dispose](){e[Symbol.dispose]()}}}function w$(e){return typeof e==`object`&&!!e&&e.__instanced===!0}function T$(e,t){return C$(e,S$(t)?t.map(x$):t.map(e=>e.map(e=>[...e])))}function E$(e,t){let{cols:n,rows:r,pitchX:i,pitchY:a}=t;if(!Number.isInteger(n)||!Number.isInteger(r)||n<1||r<1)throw RangeError(`instanceGrid: cols and rows must be positive integers, got ${n}x${r}`);let o=[];for(let e=0;e<n;e++)for(let t=0;t<r;t++)o.push(x$([e*i,t*a,0]));return C$(e,o,{cols:n,rows:r,pitchX:i,pitchY:a})}function D$(e){return e.placements.length}function O$(e,t={}){let{source:n,placements:r,grid:i}=e;return r.length===0?k(P(`INSTANCE_EMPTY`,`materialize: instance has no placements`)):t.fuse?BE(n)?i?YP(n,[1,0,0],[0,1,0],i.cols,i.rows,i.pitchX,i.pitchY):k$(n,r,!0):k(P(`MATERIALIZE_NOT_3D`,`materialize({fuse:true}) requires a 3D source shape`)):k$(n,r,!1)}function k$(e,t,n){let r=[];for(let n of t){let t=xk(e,n);if(!t.ok){for(let e of r)e[Symbol.dispose]();return t}r.push(t.value)}let i=n?KA(r,{unsafe:!0}):O(gj(r));for(let e of r)(!i.ok||e!==i.value)&&e[Symbol.dispose]();return i}function A$(e,t){return{geometry:rA(e.source,t),instances:e.placements}}var j$={coincident:3,concentric:4,distance:1,angle:1},M$=[1,0,0,0];function N$(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function P$(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function F$(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function I$(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 L$(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function R$(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function z$(e){return R$(I$(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function B$(e,t){let n=N$(cF(t.rotation,e.origin),t.position);return{type:e.type,origin:n,...e.normal?{normal:cF(t.rotation,e.normal)}:{},...e.direction?{direction:cF(t.rotation,e.direction)}:{}}}function V$(e,t,n){let r=e.normal??[0,0,1];return{position:L$(r,F$(r,P$(e.origin,t.origin))+n),rotation:M$}}function H$(e,t){let n=e.direction??[0,0,1],r=uF(t.direction??[0,0,1],n),i=cF(r,t.origin);return{position:P$(e.origin,i),rotation:r}}function U$(e,t,n){let r=R$(e.normal??[0,0,1]),i=R$(t.normal??[0,0,1]),a=Math.acos(Math.max(-1,Math.min(1,F$(i,r)))),o=I$(i,r);return{position:[0,0,0],rotation:lF(Math.hypot(o[0],o[1],o[2])<1e-9?z$(i):o,a-n)}}function W$(e,t,n){let r=P$(t,e),i=Math.hypot(r[0],r[1],r[2]);return{position:P$(N$(e,L$(i<1e-9?[1,0,0]:L$(r,1/i),n)),t),rotation:M$}}function G$(e,t,n,r){let i=R$(e);return{position:L$(i,F$(i,P$(t,n))-r),rotation:M$}}function K$(e,t,n){let r=R$(e.direction??[0,0,1]),i=N$(e.origin,L$(r,F$(r,P$(t,e.origin))));if(n===0)return{position:P$(i,t),rotation:M$};let a=P$(t,i),o=Math.hypot(a[0],a[1],a[2]);return{position:P$(N$(i,L$(o<1e-9?z$(r):L$(a,1/o),n)),t),rotation:M$}}function q$(e,t,n){let r=R$(t.direction??[0,0,1]),i=P$(t.origin,e),a=P$(i,L$(r,F$(r,i))),o=Math.hypot(a[0],a[1],a[2]);return n===0?{position:L$(a,-1),rotation:M$}:{position:P$(L$(o<1e-9?z$(r):L$(a,1/o),n),a),rotation:M$}}function J$(e,t,n){let r=R$(e.direction??[0,0,1]),i=uF(R$(t.direction??[0,0,1]),r),a=P$(cF(i,t.origin),e.origin),o=P$(a,L$(r,F$(r,a))),s=Math.hypot(o[0],o[1],o[2]);return{position:P$(L$(s<1e-9?z$(r):L$(o,1/s),n),o),rotation:i}}var Y$=new Set([`plane-plane`,`plane-point`,`point-plane`,`point-point`,`axis-axis`,`axis-point`,`point-axis`]),X$={angle:`plane`,concentric:`axis`},Z$=new Set([`coincident`,`distance`,`angle`,`concentric`]);function Q$(e,t,n){let r=X$[e];return r?t===r&&n===r:Y$.has(`${t}-${n}`)}function $$(e,t,n){switch(`${e.type}-${t.type}`){case`plane-plane`:case`plane-point`:return V$(e,t,n);case`point-plane`:return G$(t.normal??[0,0,1],e.origin,t.origin,n);case`point-point`:return W$(e.origin,t.origin,n);case`axis-axis`:return n===0?H$(e,t):J$(e,t,n);case`axis-point`:return K$(e,t.origin,n);case`point-axis`:return q$(e.origin,t,n);default:return null}}function e1(e,t,n){switch(e.type){case`concentric`:return H$(t,n);case`angle`:return U$(t,n,(e.value??0)*Math.PI/180);default:{let r=$$(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 t1(e,t){let n=new Map;for(let t of e)n.set(t,{position:[0,0,0],rotation:M$});let r=[],i=t.filter(e=>Z$.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(!Q$(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:M$},l=B$(r.entity,a);n.set(i.node,e1(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+(j$[t]??j$[t.split(`(`)[0]??``]??0),0),converged:r.length===0,unsupported:r}}function n1(e){if(e.face){let t=DO(e.face);return t?{type:`axis`,origin:t.origin,direction:t.direction}:{type:`plane`,origin:EO(e.face),normal:TO(e.face)}}if(e.edge){if(Mk(e.edge)===`LINE`)return{type:`axis`,origin:Nk(e.edge),direction:Ik(e.edge)};let t=Rk(e.edge);return t?{type:`axis`,origin:t.origin,direction:t.direction}:null}return e.point?{type:`point`,origin:e.point}:null}function r1(e,t){let n=n1(e),r=n1(t);return!n||!r?k(P(M.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 i1(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=r1(e.entityA,e.entityB);return t.ok?O({type:`coincident`,...t.value}):t}case`distance`:{let t=r1(e.entityA,e.entityB);return t.ok?O({type:`distance`,...t.value,value:e.distance}):t}case`angle`:{let t=r1(e.entityA,e.entityB);return t.ok?O({type:`angle`,...t.value,value:e.angle}):t}case`concentric`:{let t=r1(e.axisA,e.axisB);return t.ok?O({type:`concentric`,...t.value}):t}}}function a1(e,t){let n=e.mates??[];return{...e,mates:[...n,t]}}function o1(e){let t=e.mates;if(!t||t.length===0)return k(P(M.ASSEMBLY_MATE_INVALID,`solveAssembly: no mates defined`));try{let n=[];tF(e,e=>{n.push(e.name)});let r=[];for(let e of t){let t=i1(e);if(!t.ok)return t;r.push(t.value)}let i=t1(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(N(M.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(N(M.ASSEMBLY_SOLVE_FAILED,`Assembly solve failed: ${t}`,e))}}function s1(e,t,n=1e-6){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`checkInterference: first shape is a null shape`)):H().isNull(t.wrapped)?k(P(M.NULL_SHAPE_INPUT,`checkInterference: second shape is a null shape`)):YT(()=>{let r=H().distance(e.wrapped,t.wrapped);return O({hasInterference:r.value<=n,minDistance:r.value,pointOnShape1:r.point1,pointOnShape2:r.point2})})}function c1(e,n=1e-6){let r=[],i=e.map(e=>TD(e));return e.forEach((a,o)=>{for(let s=o+1;s<e.length;s++){if(l1(t(i,o),t(i,s),n))continue;let c=j(s1(a,t(e,s),n));c.hasInterference&&r.push({i:o,j:s,result:c})}}),r}function l1(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 u1(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 d1(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 f1(e){let{type:t,data:n}=e,r=H();if(t===`LINE`)return r.makeLineEdge([d1(n,10),d1(n,20),d1(n,30)],[d1(n,11),d1(n,21),d1(n,31)]);if(t===`CIRCLE`)return r.makeCircleEdge([d1(n,10),d1(n,20),d1(n,30)],[0,0,1],d1(n,40));if(t===`ARC`){let e=d1(n,50)*Math.PI/180,t=d1(n,51)*Math.PI/180;return r.makeCircleArc([d1(n,10),d1(n,20),d1(n,30)],[0,0,1],d1(n,40),e,t)}}async function p1(e,t){let n;try{n=await e.text()}catch(e){return k(Oo(M.DXF_IMPORT_FAILED,`Failed to read DXF blob`,e))}let r=u1(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=f1(e);t!==void 0&&a.push(t)}return a.length===0?O([]):O([DE(H().makeWire(a))])}catch(e){return k(Oo(M.DXF_IMPORT_FAILED,`Failed to convert DXF entities to geometry`,e))}finally{for(let e of a)e.delete()}}function m1(e,t,n=1e-6){let r=H(),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(Oo(t,`No valid triangular faces could be built`));try{let e=U(r.sewAndSolidify(i,n));for(let e of i)r.dispose(e);return O(e)}catch{try{return O(HE(r.sew(i,n)))}catch(e){return k(Oo(t,`Failed to sew triangular faces`,e))}}}function h1(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 g1(e){return e.split(/\s+/).slice(1).map(e=>parseInt(e.split(`/`)[0]??``,10)).filter(e=>!isNaN(e))}async function _1(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=h1(t);e&&n.push(e)}else if(t.startsWith(`f `)){let e=g1(t);e.length>=3&&r.push(e)}}if(n.length===0||r.length===0)return k(Oo(M.OBJ_IMPORT_FAILED,`OBJ file contains no valid geometry`));try{return v1(n,r)}catch(e){let t=e instanceof Error?e.message:String(e);return k(Oo(M.OBJ_IMPORT_FAILED,`OBJ import failed: ${t}`,e))}}function v1(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 m1(n,M.OBJ_IMPORT_FAILED)}function y1(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 b1(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95}function x1(e){let t={},n=0;for(;n<e.length;){let r=e.indexOf(`="`,n);if(r<0)break;let i=r;for(;i>0&&b1(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 S1(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 C1(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 w1(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 T1(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=x1(e.slice(r,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of S1(a,`color`)){let t=x1(e).color;t!==void 0&&l.push(w1(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=x1(e.slice(n,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of S1(a,`base`)){let t=x1(e).displaycolor;t===void 0?l.push([0,0,0,1]):l.push(w1(t))}t.set(c,l)}return t}function E1(e){let t=[],n=[],r=[],i=T1(e);for(let n of S1(e,`vertex`)){let e=x1(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=C1(e,`object`);if(s!==null){let e=s.indexOf(`>`);if(e>=0){let t=x1(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 S1(e,`triangle`)){let e=x1(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 D1(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 O1(e){let t=H(),n=e.vertices.map(([e,t,n])=>({x:e,y:t,z:n})),r=e.triangles;try{return O(U(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 m1(t,M.THREEMF_IMPORT_FAILED)}}async function k1(e){try{let t=await e.arrayBuffer(),n=y1(new Uint8Array(t),`3D/3dmodel.model`);if(!n)return k(Oo(M.THREEMF_IMPORT_FAILED,`3MF archive does not contain 3D/3dmodel.model (or uses unsupported compression)`));let r=E1(new TextDecoder().decode(n));if(r.vertices.length===0||r.triangles.length===0)return k(Oo(M.THREEMF_IMPORT_FAILED,`3MF model contains no valid geometry`));let i=O1(r);if(i.ok){let e=D1(r.triangleColors);e!==null&&rk(i.value,e)}return i}catch(e){let t=e instanceof Error?e.message:String(e);return k(Oo(M.THREEMF_IMPORT_FAILED,`3MF import failed: ${t}`,e))}}async function A1(e){try{let t=await e.arrayBuffer();return O(U(H().importGLB(t)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(Oo(M.GLB_IMPORT_FAILED,`Failed to import GLB: ${t}`,e))}}function $(e){return`__wrapped`in e?e.val:e}function j1(e){return $(e)}function M1(e,t){return pk($(e),t)}function N1(e,t){if(Array.isArray(e))throw Error(`${t}() expects an options object, e.g. ${t}(shape, { ... }), not an array of coordinates.`)}function P1(e,t,n){N1(n,`rotate`);let r=n?.at;return mk($(e),t,r,n?.axis)}function F1(e,t){N1(t,`mirror`);let n=t?.at;return hk($(e),t?.normal??[1,0,0],n)}function I1(e,t,n){return gk($(e),t,n?.center)}function L1(e){return Tk($(e))}function R1(e,t){return xk($(e),t)}function z1(e,t){return wk($(e),t)}function B1(e,t){return Ck($(e),t)}function V1(e,t,n){return HA($(e),$(t),{...n,unsafe:!0})}function H1(e,t,n){return UA($(e),$(t),{...n,unsafe:!0})}function U1(e,t){return KA(e.map(e=>$(e)),{...t,unsafe:!0})}function W1(e,t,n){return qA($(e),t.map(e=>$(e)),{...n,unsafe:!0})}function G1(e,t,n){return WA($(e),$(t),{...n,unsafe:!0})}function K1(e,t,n){return XA($(e),t,n)}function q1(e,t,n){return nj($(e),t,n)}function J1(e,t){return rj($(e),t)}function Y1(e,t,n){return ij($(e),t,n)}function X1(e,t){if(e!==void 0)return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(YI()).findAll(t)}function Z1(e,t){return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(QI()).findAll(t)}function Q1(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 $1(e,t,n){let r=$(e),i,a;return n===void 0?(i=void 0,a=t):(i=X1(t,r),a=n),nM(r,i,a)}function e0(e,t,n){let r=$(e),i,a;n===void 0?(i=void 0,a=t):(i=X1(t,r),a=n);let o=Q1(a);return o.mode===`distAngle`?Cj(r,[...i??dD(r)],o.distance,o.angle):rM(r,i,o.distance)}function t0(e,t,n,r){let i=$(e);return iM(i,Z1(t,i),n,r?.tolerance)}function n0(e,t,n){return aM($(e),t,n?.tolerance)}function r0(e,t){return eM($(e),t)}function i0(e,t,n){let r=$(e);return sM(r,Z1(t,r),n.pullDirection,n.neutralPlane,n.angle)}function a0(e){return pM($(e))}function o0(e){return jk($(e))}function s0(e,t){return rA($(e),t)}function c0(e,t){return iA($(e),t)}function l0(e){return kD($(e))}function u0(e){return Ek($(e))}function d0(e){return hO(e)}function f0(e){return lM($(e))}function p0(e){return Ok($(e))}function m0(e,t){return AM($(e),typeof t==`number`?[0,0,t]:t)}function h0(e,t){let n=t?.at??[0,0,0];return jM($(e),n,t?.axis??[0,0,1],t?.angle??2*Math.PI)}function g0(e,t){return NM(e.map(e=>$(e)),t)}function _0(e,n){if(n===void 0){let t=fD(e);if(t.length===0)return k(P(M.COMPOUND_NO_FACES,`compoundOps: shape has no faces`));let n=yA(t),r=EO(n)[2];for(let e=1;e<t.length;e++){let i=vA(t,e),a=EO(i)[2];a>r&&(n=i,r=a)}return O(n)}if(typeof n==`function`){let r=n(QI()).findAll(e);return r.length===0?k(ko(M.COMPOUND_FACE_NOT_FOUND,`compoundOps: face finder matched no faces`)):O(t(r,0))}return O(n)}function v0(e){return`sketchOnPlane`in e&&typeof e.sketchOnPlane==`function`?{wire:e.sketchOnPlane(`XY`).wire,owned:!0}:{wire:e,owned:!1}}function y0(e,t){let n=$(e),{at:r,radius:i,axis:a}=t,o=a??[0,0,1];if(i<=0)return k(P(`DRILL_INVALID_RADIUS`,`Drill radius must be positive`));if(KD(o))return k(P(`DRILL_ZERO_AXIS`,`Drill axis cannot be zero`));let s=WD(o),c=r.length===2?[r[0],r[1],0]:[r[0],r[1],r[2]],l;if(t.depth!==void 0)l=lj(i,t.depth,c,s);else{let e=TD(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=lj(i,a-r,[c[0]+s[0]*r,c[1]+s[1]*r,c[2]+s[2]*r],s)}try{return UA(n,l,{unsafe:!0})}finally{l[Symbol.dispose]()}}function b0(e,t){try{var n=LT();let r=$(e),{profile:i,depth:a}=t;if(a<=0)return k(P(`POCKET_INVALID_DEPTH`,`Pocket depth must be positive`));let o=_0(r,t.face);if(A(o))return o;let s=o.value,c=TO(s),l=EO(s),u=n.u(new ZT),{wire:d,owned:f}=v0(i);f&&u.register(d);let p=PA(d);if(A(p))return p;u.register(p.value);let m=AM(u.register(pk(p.value,l)),LD(WD(c),-a));return A(m)?m:(u.register(m.value),UA(r,m.value,{unsafe:!0}))}catch(e){n.e=e}finally{n.d()}}function x0(e,t){try{var n=LT();let r=$(e),{profile:i,height:a}=t;if(a<=0)return k(P(`BOSS_INVALID_HEIGHT`,`Boss height must be positive`));let o=_0(r,t.face);if(A(o))return o;let s=o.value,c=TO(s),l=EO(s),u=n.u(new ZT),{wire:d,owned:f}=v0(i);f&&u.register(d);let p=PA(d);if(A(p))return p;u.register(p.value);let m=AM(u.register(pk(p.value,l)),LD(WD(c),a));return A(m)?m:(u.register(m.value),HA(r,m.value,{unsafe:!0}))}catch(e){n.e=e}finally{n.d()}}function S0(e,t){try{var n=LT();let r=$(e),i=t?.normal??[1,0,0],a=t?.at;return KD(i)?k(P(`MIRROR_ZERO_NORMAL`,`Mirror plane normal cannot be zero`)):HA(r,n.u(hk(r,i,a)),{unsafe:!0})}catch(e){n.e=e}finally{n.d()}}function C0(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(P(`PATTERN_INVALID_COUNT`,`Pattern counts must be at least 1`));if(KD(r))return k(P(`PATTERN_ZERO_DIRECTION`,`X direction cannot be zero`));if(KD(o))return k(P(`PATTERN_ZERO_DIRECTION`,`Y direction cannot be zero`));if(i===1&&s===1)return O(n);let l=WD(r),u=WD(o),d=[n],f=[];for(let e=0;e<i;e++)for(let t=0;t<s;t++){if(e===0&&t===0)continue;let r=pk(n,[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(r),f.push(r)}try{return KA(d,{unsafe:!0})}finally{for(let e of f)e[Symbol.dispose]()}}var w0=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 T0(e){if(A(e))throw new w0(e.error);return e.value}function E0(e){return e}function D0(e){return e}function O0(e){return e}function k0(e){return e}function A0(e){return{val:e,__wrapped:!0,translate:t=>B0(M1(e,t)),rotate:(t,n)=>B0(P1(e,t,n)),mirror:t=>B0(F1(e,t)),scale:(t,n)=>B0(I1(e,t,n)),applyMatrix:t=>B0(T0(R1(e,t))),moveX:t=>B0(M1(e,[t,0,0])),moveY:t=>B0(M1(e,[0,t,0])),moveZ:t=>B0(M1(e,[0,0,t])),rotateX:t=>B0(P1(e,t,{axis:[1,0,0]})),rotateY:t=>B0(P1(e,t,{axis:[0,1,0]})),rotateZ:t=>B0(P1(e,t,{axis:[0,0,1]})),bounds:()=>TD(e),describe:()=>l0(e),clone:()=>B0(T0(L1(e))),mesh:t=>s0(e,t),meshEdges:t=>c0(e,t),isValid:()=>f0(e),isEmpty:()=>p0(e),heal:()=>B0(T0(a0(e))),simplify:()=>B0(T0(o0(e))),toBREP:()=>T0(u0(e)),apply:t=>B0(t(e)),applyResult:t=>B0(T0(t(e))),done:()=>e}}function j0(e){return{fuse:(t,n)=>V0(T0(V1(e,$(t),{...n,unsafe:!0}))),cut:(t,n)=>V0(T0(H1(e,$(t),{...n,unsafe:!0}))),intersect:(t,n)=>V0(T0(G1(e,$(t),{...n,unsafe:!0}))),fuseAll:(t,n)=>V0(k0(T0(KA([e,...t.map($)],{...n,unsafe:!0})))),cutAll:(t,n)=>V0(k0(T0(qA(e,t,{...n,unsafe:!0})))),section:(t,n)=>B0(T0(K1(e,t,n))),split:t=>B0(T0(J1(e,t))),slice:(t,n)=>T0(Y1(e,t,n))}}function M0(e){return{fillet(...t){return t.length===1?V0(k0(T0($1(E0(e),t[0])))):V0(k0(T0($1(E0(e),t[0],t[1]))))},chamfer(...t){return t.length===1?V0(k0(T0(e0(E0(e),t[0])))):V0(k0(T0(e0(E0(e),t[0],t[1]))))},shell:(t,n,r)=>V0(k0(T0(t0(E0(e),t,n,r)))),offset:(t,n)=>V0(k0(T0(n0(E0(e),t,n)))),draft:(t,n)=>V0(k0(T0(i0(E0(e),t,n))))}}function N0(e){return{drill:t=>V0(T0(y0(e,t))),pocket:t=>V0(T0(b0(e,t))),boss:t=>V0(T0(x0(e,t))),mirrorJoin:t=>V0(T0(S0(e,t))),rectangularPattern:t=>V0(T0(C0(e,t)))}}function P0(e){return{volume:()=>T0(UM(e)),area:()=>T0(WM(e)),volumeProps:()=>T0(BM(e)),surfaceProps:()=>T0(VM(e))}}function F0(e){return{edges:()=>dD(e),faces:()=>fD(e),wires:()=>pD(e),vertices:()=>mD(e)}}function I0(e){return{linearPattern:(t,n,r)=>V0(k0(T0(qP(e,t,n,r)))),circularPattern:(t,n,r)=>V0(k0(T0(JP(e,t,n,r))))}}function L0(e){return{...A0(e),...j0(e),...M0(e),...N0(e),...P0(e),...F0(e),...I0(e)}}function R0(e){return{...A0(e),length:()=>Lk(e),startPoint:()=>Nk(e),endPoint:()=>Pk(e),pointAt:t=>Fk(e,t),tangentAt:t=>Ik(e,t),isClosed:()=>zk(e),sweep(t,n){if(!FE(e))throw Error(`sweep requires a Wire`);let r=T0(SM(O0(e),$(t),n));return V0(Array.isArray(r)?r[0]:r)}}}function z0(e){return{...A0(e),area:()=>T0(WM(e)),normalAt:t=>TO(e,t),center:()=>EO(e),surfaceType:()=>T0(_O(e)),outerWire:()=>kO(e),innerWires:()=>jO(e),extrude:t=>V0(T0(m0(D0(e),t))),revolve:t=>V0(T0(h0(D0(e),t)))}}function B0(e){return BE(e)?L0(e):IE(e)?z0(e):PE(e)||FE(e)?R0(e):A0(e)}function V0(e){return L0(e)}function H0(e){if(e&&typeof e==`object`&&`face`in e&&typeof e.face==`function`&&`_defaultOrigin`in e)return z0(e.face());if(e&&typeof e==`object`&&`wrapped`in e)return IE(e)?z0(e):BE(e)?L0(e):PE(e)||FE(e)?R0(e):A0(e);throw Error(`shape() requires a Sketch or branded shape type`)}var U0=.25,W0=e=>Math.tan(e)-e;function G0(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 K0(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(G0(e,s*t,n,i))}return a}function q0(e){return Math.max(16,Math.round(8*Math.sqrt(e)))}function J0(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 Y0(e,t,n){if(t===0)return O(e);let r=W0(e)+2*t*Math.tan(e)/n,i,a;if(r>W0(e)?(i=e,a=Math.PI/2-1e-6):(i=1e-4,a=e),r>W0(a)||r<W0(i))return k(P(`GEAR_PA_OUT_OF_RANGE`,`working pressure angle out of range — target inv(αw)=${r.toFixed(4)} not in [${W0(i).toFixed(4)}, ${W0(a).toFixed(4)}]`,void 0,{target:r,invLo:W0(i),invHi:W0(a)}));for(let e=0;e<50;e++){let e=.5*(i+a);W0(e)<r?i=e:a=e}return O(.5*(i+a))}function X0(e,t,n,r,i){return Y0(e,t+n,r+i)}function Z0(e,t,n,r,i){return Y0(e,n-t,i-r)}function Q0(e,t,n,r,i){return(e+t)*n*Math.cos(r)/(2*Math.cos(i))}function $0(e,t,n,r){if(!Number.isInteger(e)||!Number.isInteger(t)||!Number.isInteger(n))return k(P(`GEAR_NON_INTEGER_TEETH`,`tooth counts and planet count must be integers`));if(e<4||t<4||n<2)return k(P(`GEAR_TEETH_TOO_FEW`,`zs ≥ 4, zp ≥ 4, N ≥ 2 required`));if((2*e+2*t)%n!=0)return k(P(`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(P(`GEAR_PLANET_COLLISION`,`planet tips would collide: (zs+zp)·sin(π/N) = ${a.toFixed(3)} ≤ planet tip = ${i.toFixed(3)}`)):O(void 0)}function e2(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 t2(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 n2(e,t){return 1-e*Math.sin(t)*Math.sin(t)/2}function r2(e,t,n){return Math.max(0,n2(e,t)-n)}function i2(e){return e<8?.2:.485-2.88/e}function a2(e,t,n,r){let i=e*1e3,a=i2(r);return a<=0||n<=0||t<=0?1/0:2*i/(r*t*t*n*a)}function o2(e,t,n=!1){let r=(1.4+6.5/e)*(20/(t*180/Math.PI))**.15;return n?r*.85:r}function s2(e,t,n,r,i,a=!1){return a2(e,t,n,r)*o2(r,i,a)}function c2(e){return e/2}function l2(e,t){return e+2*t}function u2(e){return e%2==0?Math.PI/e:0}function d2(e,t,n){return e*(1+t/n)+u2(n)}function f2(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=$0(n,r,i,s);if(A(c))return c;let l=X0(a,o,s,n,r);if(A(l))return l;let u=Q0(n,r,t,a,l.value),d=[];for(let e=0;e<i;e++){let t=e*2*Math.PI/i,a=d2(t,n,r);d.push({rotationDeg:a*180/Math.PI,position:[u*Math.cos(t),u*Math.sin(t),0]})}return O(d)}function p2(e,t,n,r,i){let a=t*e.toothPitch,o=(t+1)%n*e.toothPitch,s=W0(e.alphaPitch),c=a-e.halfToothAngle-s,l=a+e.halfToothAngle+s,u=K0(e.rb,e.alphaTip,c,r,1),d=K0(e.rb,e.alphaTip,l,r,-1).reverse(),f=yA(u),p=bA(u),m=yA(d),h=bA(d),g=[],_=e=>{i.register(e),g.push(e)},v=e.isInternal?e.rb<e.rRoot:e.rb>e.rRoot;v&&_(CA([e.rRoot*Math.cos(c),e.rRoot*Math.sin(c),0],f));let y=e.rPitch*1e-5,b=AA(u,{tolerance:y});if(A(b))return b;_(b.value),_(DA(p,[e.rTip*Math.cos(a),e.rTip*Math.sin(a),0],m));let x=AA(d,{tolerance:y});if(A(x))return x;_(x.value),v&&_(CA(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),_(DA(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 m2(e){return g2(e,!1)}function h2(e){return g2(e,!0)}function g2(e,t){try{var n=LT();let{teeth:r,moduleSize:i,pressureAngle:a,shift:o,clearance:s,flankThinning:c,samples:l=q0(i)}=e;if(r<4)return k(P(`GEAR_TEETH_TOO_FEW`,`gear needs ≥ 4 teeth, got ${r}`));if(i<=0)return k(P(`GEAR_MODULE_NONPOSITIVE`,`module must be > 0, got ${i}`));let u=J0(r,i,a,o,s,c,t),d=n.u(new ZT),f=[];for(let e=0;e<r;e++){let t=p2(u,e,r,l,d);if(A(t))return t;f.push(...t.value)}let p=NA(f);return A(p)?p:O(p.value)}catch(e){n.e=e}finally{n.d()}}function _2(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=U0,flankThinning:s=0,bore:c=0,samples:l}=e;if(r<=0)return k(P(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));if(l!==void 0&&(!Number.isInteger(l)||l<1))return k(P(`GEAR_SAMPLES_INVALID`,`samples must be a positive integer; got ${String(l)}`));let u=i*Math.PI/180,d=J0(t,n,u,a,o,s,!1);if(c>0&&c>=2*d.rRoot)return k(P(`GEAR_BORE_TOO_LARGE`,`bore diameter ${c.toFixed(2)} ≥ root diameter ${(2*d.rRoot).toFixed(2)} — would erase the gear teeth`));let f=m2({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(f))return f;let p=y2(t,u,a);return w2(f.value,r,c,d,p)}function v2(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=U0,flankThinning:s=0,ringWallThickness:c=2*e.moduleSize,samples:l}=e;if(r<=0)return k(P(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));if(c<=0)return k(P(`GEAR_WALL_NONPOSITIVE`,`ringWallThickness must be > 0`));if(l!==void 0&&(!Number.isInteger(l)||l<1))return k(P(`GEAR_SAMPLES_INVALID`,`samples must be a positive integer; got ${String(l)}`));let u=i*Math.PI/180,d=h2({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(d))return d;let f=J0(t,n,u,a,o,s,!0),p=C2(f.rPitch+c);return A(p)?p:E2(p.value,d.value,r,f,[])}function y2(e,t,n){let r=r2(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 b2(e){let t=S2(e);if(A(t))return t;let n=t.value,r=x2(n);if(A(r))return r;let{sun:i,planet:a,ring:o}=r.value,s=A2(n,i,a,o),c=O2(a.solid,n);a.solid.delete();let l=k2(o.solid,n.zr),u=j2(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 x2(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=_2({...n,teeth:e.sunTeeth,shift:e.sunShift,bore:e.sunBore});if(A(r))return r;let i=_2({...n,teeth:e.planetTeeth,shift:e.planetShift,bore:e.planetBore});if(A(i))return r.value.solid.delete(),i;let a=v2({...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 S2(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(P(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));let u=$0(n,r,i,c);if(A(u))return u;let d=l2(n,r),f=X0(o,s,c,n,r);if(A(f))return f;let p=Z0(o,c,l,r,d);if(A(p))return p;let m=Q0(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:c2(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 C2(e){try{var t=LT();let n=NA([t.u(new ZT).register(wA(e,[0,0,0],[0,0,1]))]);return A(n)?n:O(n.value)}catch(e){t.e=e}finally{t.d()}}function w2(e,t,n,r,i){try{var a=LT();let o=a.u(new ZT);o.register(e);let s=PA(e);if(A(s))return s;o.register(s.value);let c=AM(s.value,[0,0,t]);if(A(c))return c;if(n<=0)return O(D2(c.value,r,i));let l=a.u(new ZT);l.register(c.value);let u=T2(n/2);if(A(u))return u;l.register(u.value);let d=AM(u.value,[0,0,t+1]);if(A(d))return d;l.register(d.value);let f=l.register(pk(d.value,[0,0,-.5])),p=UA(c.value,f);return A(p)?p:O(D2(p.value,r,i))}catch(e){a.e=e}finally{a.d()}}function T2(e){let t=C2(e);return A(t)?t:PA(t.value)}function E2(e,t,n,r,i){let a=PA(e,[t]);if(A(a))return a;let o=AM(a.value,[0,0,n]);return A(o)?o:O(D2(o.value,r,i))}function D2(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 O2(e,t){let n=[];try{for(let r=0;r<t.numPlanets;r++){let i=r*2*Math.PI/t.numPlanets,a=mk(e,d2(i,t.sunTeeth,t.planetTeeth)*180/Math.PI);try{let e=[t.centerDistance*Math.cos(i),t.centerDistance*Math.sin(i),0];n.push(pk(a,e))}finally{a.delete()}}return n}catch(e){for(let e of n)e.delete();throw e}}function k2(e,t){let n=u2(t);if(n===0)return e;let r=mk(e,n*180/Math.PI);return e.delete(),r}function A2(e,t,n,r){let i={crSunPlanet:e2(t.tipDiameter/2,t.baseDiameter/2,n.tipDiameter/2,n.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_sp),crPlanetRing:t2(n.tipDiameter/2,n.baseDiameter/2,r.tipDiameter/2,r.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_pr),undercutSun:r2(e.sunTeeth,e.alpha,e.sunShift),undercutPlanet:r2(e.planetTeeth,e.alpha,e.planetShift)};if(e.appliedTorque!==void 0){let t=e.appliedTorque;i.lewisStress={sun:s2(t,e.moduleSize,e.thickness,e.sunTeeth,e.alpha),planet:s2(t*e.planetTeeth/e.sunTeeth,e.moduleSize,e.thickness,e.planetTeeth,e.alpha),ring:s2(t*e.zr/e.sunTeeth,e.moduleSize,e.thickness,e.zr,e.alpha,!0)},i.stressConcentrationFactor={sun:o2(e.sunTeeth,e.alpha),planet:o2(e.planetTeeth,e.alpha),ring:o2(e.zr,e.alpha,!0)}}return i}function j2(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 M2=RX({addHoles:()=>UP,bezier:()=>AP,box:()=>_P,bsplineApprox:()=>kP,circle:()=>wP,compound:()=>zP,cone:()=>bP,cylinder:()=>vP,ellipse:()=>TP,ellipseArc:()=>OP,ellipsoid:()=>SP,face:()=>PP,fill:()=>FA,filledFace:()=>FP,helix:()=>EP,line:()=>CP,offsetFace:()=>VP,polygon:()=>LP,polyhedron:()=>ZQ,sewShells:()=>HP,solid:()=>BP,sphere:()=>yP,subFace:()=>IP,tangentArc:()=>jP,threePointArc:()=>DP,torus:()=>xP,vertex:()=>RP,wire:()=>MP,wireLoop:()=>NP}),N2=RX({checkBoolean:()=>Lj,convexHull:()=>KQ,cut:()=>H1,cutAll:()=>qA,cutAllBisect:()=>Oj,fuse:()=>V1,fuseAll:()=>KA,fuseAllBisect:()=>Mj,hull:()=>GQ,intersect:()=>G1,minkowski:()=>XQ,section:()=>K1,sectionToFace:()=>q1,slice:()=>Y1,split:()=>J1}),P2=RX({chamfer:()=>e0,draft:()=>i0,fillet:()=>$1,heal:()=>a0,offset:()=>n0,shell:()=>t0,simplify:()=>o0,thicken:()=>r0,variableFillet:()=>cM}),F2=RX({applyMatrix:()=>R1,clone:()=>L1,composeTransforms:()=>Sk,mirror:()=>F1,rotate:()=>P1,scale:()=>I1,transformCopy:()=>z1,translate:()=>M1}),I2=RX({checkAllInterferences:()=>c1,checkInterference:()=>s1,createDistanceQuery:()=>JM,measureArea:()=>WM,measureCurvatureAt:()=>YM,measureCurvatureAtMid:()=>XM,measureDistance:()=>KM,measureDistanceProps:()=>qM,measureLength:()=>GM,measureLinearProps:()=>HM,measureSurfaceProps:()=>VM,measureVolume:()=>UM,measureVolumeProps:()=>BM}),L2=RX({blueprintToDXF:()=>EY,exportAssemblySTEP:()=>KP,exportDXF:()=>TY,exportGlb:()=>fY,exportGltf:()=>dY,exportIGES:()=>uA,exportOBJ:()=>tY,exportSTEP:()=>cA,exportSTEPConfigured:()=>lX,exportSTL:()=>lA,exportThreeMF:()=>GY,importDXF:()=>p1,importGLB:()=>A1,importIGES:()=>fX,importOBJ:()=>_1,importSTEP:()=>uX,importSTL:()=>dX,importSVG:()=>cX,importSVGPathD:()=>sX,importThreeMF:()=>k1}),R2=RX({cornerFinder:()=>TR,edgeFinder:()=>YI,faceFinder:()=>QI,getSingleFace:()=>tL,vertexFinder:()=>qX,wireFinder:()=>eL}),z2=RX({complexExtrude:()=>wM,extrude:()=>m0,guidedSweep:()=>kM,loft:()=>g0,multiSectionSweep:()=>OM,revolve:()=>h0,roof:()=>b$,supportExtrude:()=>CM,surfaceFromGrid:()=>BQ,surfaceFromImage:()=>UQ,sweep:()=>SM,twistExtrude:()=>TM}),B2=RX({circularPattern:()=>JP,linearPattern:()=>qP}),V2=14695981039346656037n,H2=1099511628211n,U2=18446744073709551615n;function W2(){return V2}function G2(e,t){return(e^BigInt(t&255))*H2&U2}function K2(e,t){let n=e;for(let e=0;e<t.length;e++)n=G2(n,t[e]??0);return n}var q2=new TextEncoder;function J2(e,t){return K2(e,q2.encode(t))}var Y2=new ArrayBuffer(8),X2=new DataView(Y2),Z2=new Uint8Array(Y2);function Q2(e,t){return X2.setFloat64(0,Object.is(t,-0)?0:t),K2(e,Z2)}function $2(e,t){let n=e,r=t&U2;for(let e=0;e<8;e++)n=G2(n,Number(r&255n)),r>>=8n;return n}function e4(e,t){let n=e,r=t|0;for(let e=0;e<4;e++)n=G2(n,r&255),r>>>=8;return n}function t4(e,t){return G2(e,+!!t)}function n4(e){return(e&U2).toString(16).padStart(16,`0`)}var r4=new Set;function i4(e){return J2(W2(),e)}function a4(e){return{kind:`NumLit`,value:e,structuralHash:Q2(i4(`NumLit`),e),freeParams:r4}}function o4(e){let t=i4(`Vec3Lit`);for(let n of e)t=Q2(t,n);return{kind:`Vec3Lit`,value:e,structuralHash:t,freeParams:r4}}function s4(e){let t=i4(`Vec2Lit`);for(let n of e)t=Q2(t,n);return{kind:`Vec2Lit`,value:e,structuralHash:t,freeParams:r4}}function c4(e){return{kind:`Param`,name:e,structuralHash:J2(i4(`Param`),e),freeParams:new Set([e])}}function l4(e,t,n){let r=J2(i4(`BinOp`),e);return r=$2(r,t.structuralHash),r=$2(r,n.structuralHash),{kind:`BinOp`,op:e,a:t,b:n,structuralHash:r,freeParams:y4(t.freeParams,n.freeParams)}}function u4(e,t){let n=J2(i4(`UnaryOp`),e);return n=$2(n,t.structuralHash),{kind:`UnaryOp`,op:e,arg:t,structuralHash:n,freeParams:t.freeParams}}function d4(e,t){let n=e4(i4(`Component`),t);return n=$2(n,e.structuralHash),{kind:`Component`,vec:e,index:t,structuralHash:n,freeParams:e.freeParams}}function f4(e,t){let n=e4(i4(`BuildVec`),e),r=new Set;for(let e of t){n=$2(n,e.structuralHash);for(let t of e.freeParams)r.add(t)}return{kind:`BuildVec`,dim:e,components:t,structuralHash:n,freeParams:r}}var p4=(e,t)=>l4(`+`,e,t),m4=(e,t)=>l4(`*`,e,t);function h4(e){return typeof e==`number`?a4(e):e}function g4(e,t){if(!Array.isArray(e))return e;let n=e;return n.every(e=>typeof e==`number`)?t===3?o4([n[0],n[1],n[2]]):s4([n[0],n[1]]):f4(t,n.map(h4))}function _4(e){return g4(e,3)}function v4(e){return g4(e,2)}function y4(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 b4(e){return typeof e==`number`}function x4(e,t){return b4(e)?O(e):k(P(M.NULL_SHAPE_INPUT,`${t}: expected number, got ${Array.isArray(e)?`vector(${e.length})`:typeof e}`))}function S4(e,t,n){return Array.isArray(e)&&e.length===t?O(e):k(P(M.NULL_SHAPE_INPUT,`${n}: expected Vec${t}, got ${b4(e)?`number`:`vector(${e.length})`}`))}function C4(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(P(M.NULL_SHAPE_INPUT,`unbound param: ${e.name}`)):O(n)}case`BinOp`:return w4(e,t);case`UnaryOp`:return T4(e,t);case`Component`:return E4(e,t);case`BuildVec`:return D4(e,t)}}function w4(e,t){let n=C4(e.a,t);if(!n.ok)return n;let r=C4(e.b,t);if(!r.ok)return r;let i=x4(n.value,`BinOp(${e.op}).a`);if(!i.ok)return i;let a=x4(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(P(M.NULL_SHAPE_INPUT,`BinOp(/): division by zero`)):O(i.value/a.value)}}function T4(e,t){let n=C4(e.arg,t);if(!n.ok)return n;let r=x4(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 E4(e,t){let n=C4(e.vec,t);if(!n.ok)return n;if(b4(n.value))return k(P(M.NULL_SHAPE_INPUT,`Component: cannot index a scalar`));let r=n.value,i=r[e.index];return i===void 0?k(P(M.NULL_SHAPE_INPUT,`Component: index ${e.index} out of range for Vec${r.length}`)):O(i)}function D4(e,t){if(e.components.length!==e.dim)return k(P(M.NULL_SHAPE_INPUT,`BuildVec(${e.dim}): expected ${e.dim} components, got ${e.components.length}`));let n=[];for(let r of e.components){let e=C4(r,t);if(!e.ok)return e;let i=x4(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 O4(e,t,n){let r=C4(e,t);return r.ok?x4(r.value,n):r}function k4(e,t,n){let r=C4(e,t);if(!r.ok)return r;let i=S4(r.value,3,n);if(!i.ok)return i;let[a,o,s]=i.value;return O([a,o,s])}function A4(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 j4=new Set;function M4(e){return J2(W2(),e)}function N4(e,t){return $2(e,t.structuralHash)}function P4(e,t){return t===void 0?t4(e,!1):N4(t4(e,!0),t)}function F4(e,t){return t===void 0?t4(e,!1):Q2(t4(e,!0),t)}function I4(...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?j4:t}function L4(e,t,n){let r=h4(e),i=h4(t),a=h4(n),o=M4(`Box`);return o=N4(N4(N4(o,r),i),a),{kind:`Box`,x:r,y:i,z:a,structuralHash:o,freeParams:I4(r,i,a)}}function R4(e){let t=h4(e);return{kind:`Sphere`,radius:t,structuralHash:N4(M4(`Sphere`),t),freeParams:t.freeParams}}function z4(e,t){let n=h4(e),r=h4(t);return{kind:`Cylinder`,radius:n,height:r,structuralHash:N4(N4(M4(`Cylinder`),n),r),freeParams:I4(n,r)}}function B4(e,t,n){let r=h4(e),i=h4(t),a=h4(n),o=M4(`Cone`);return o=N4(N4(N4(o,r),i),a),{kind:`Cone`,radius1:r,radius2:i,height:a,structuralHash:o,freeParams:I4(r,i,a)}}function V4(e,t){let n=h4(e),r=h4(t);return{kind:`Torus`,majorRadius:n,minorRadius:r,structuralHash:N4(N4(M4(`Torus`),n),r),freeParams:I4(n,r)}}function H4(e){let t=e.map(_4),n=e4(M4(`Polygon`),t.length);for(let e of t)n=N4(n,e);return{kind:`Polygon`,points:t,structuralHash:n,freeParams:I4(...t)}}function U4(e){let t=h4(e);return{kind:`Circle`,radius:t,structuralHash:N4(M4(`Circle`),t),freeParams:t.freeParams}}function W4(e,t){let n=_4(e),r=_4(t);return{kind:`Line`,from:n,to:r,structuralHash:N4(N4(M4(`Line`),n),r),freeParams:I4(n,r)}}function G4(e){let t=_4(e);return{kind:`Vertex`,point:t,structuralHash:N4(M4(`Vertex`),t),freeParams:t.freeParams}}function K4(e){return{kind:`Empty`,output:e,structuralHash:J2(M4(`Empty`),e),freeParams:j4}}function q4(){return K4(`Solid`)}function J4(){return K4(`Face`)}function Y4(){return K4(`Wire`)}function X4(e,t,n,r){return F4(N4(N4(M4(e),t),n),r)}function Z4(e,t,n){return{kind:`Fuse`,a:e,b:t,tolerance:n,structuralHash:X4(`Fuse`,e,t,n),freeParams:I4(e,t)}}function Q4(e,t,n){return{kind:`Cut`,a:e,b:t,tolerance:n,structuralHash:X4(`Cut`,e,t,n),freeParams:I4(e,t)}}function $4(e,t,n){return{kind:`Intersect`,a:e,b:t,tolerance:n,structuralHash:X4(`Intersect`,e,t,n),freeParams:I4(e,t)}}function e3(e,t){let n=e4(M4(`FuseAll`),e.length);for(let t of e)n=N4(n,t);return n=F4(n,t),{kind:`FuseAll`,shapes:e,tolerance:t,structuralHash:n,freeParams:I4(...e)}}function t3(e,t,n){let r=N4(M4(`CutAll`),e);r=e4(r,t.length);for(let e of t)r=N4(r,e);return r=F4(r,n),{kind:`CutAll`,base:e,tools:t,tolerance:n,structuralHash:r,freeParams:I4(e,...t)}}function n3(e){return e===void 0?void 0:_4(e)}function r3(e,t){let n=_4(t);return{kind:`Translate`,target:e,vector:n,structuralHash:N4(N4(M4(`Translate`),e),n),freeParams:I4(e,n)}}function i3(e,t,n){let r=h4(t),i=n3(n?.axis),a=n3(n?.at),o=N4(N4(M4(`Rotate`),e),r);return o=P4(o,i),o=P4(o,a),{kind:`Rotate`,target:e,angle:r,axis:i,at:a,structuralHash:o,freeParams:I4(e,r,i,a)}}function a3(e,t,n){let r=h4(t),i=n3(n?.center),a=N4(N4(M4(`Scale`),e),r);return a=P4(a,i),{kind:`Scale`,target:e,factor:r,center:i,structuralHash:a,freeParams:I4(e,r,i)}}function o3(e,t){let n=n3(t?.normal),r=n3(t?.at),i=N4(M4(`Mirror`),e);return i=P4(i,n),i=P4(i,r),{kind:`Mirror`,target:e,normal:n,at:r,structuralHash:i,freeParams:I4(e,n,r)}}function s3(e){let t=e4(M4(`Compound`),e.length);for(let n of e)t=N4(t,n);return{kind:`Compound`,children:e,structuralHash:t,freeParams:I4(...e)}}function c3(e,t,n=!1){let r=t.map(e=>e.map(e=>[...e])),i=e4(t4(N4(M4(`Instance`),e),n),r.length);for(let e of r)for(let t of e.flat())i=Q2(i,t);return{kind:`Instance`,source:e,placements:r,fuse:n,structuralHash:i,freeParams:I4(e)}}function l3(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 l3(e.a);case`FuseAll`:return e.shapes[0]?l3(e.shapes[0]):`Solid`;case`CutAll`:return l3(e.base);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return l3(e.target);case`Compound`:return`Compound`;case`Instance`:return e.fuse?`Solid`:`Compound`}}function u3(e,t){let n=O4(e.x,t.env,`Box.x`);if(!n.ok)return n;let r=O4(e.y,t.env,`Box.y`);if(!r.ok)return r;let i=O4(e.z,t.env,`Box.z`);return i.ok?O(_P(n.value,r.value,i.value)):i}function d3(e,t){let n=O4(e.radius,t.env,`Sphere.radius`);return n.ok?O(yP(n.value)):n}function f3(e,t){let n=O4(e.radius,t.env,`Cylinder.radius`);if(!n.ok)return n;let r=O4(e.height,t.env,`Cylinder.height`);return r.ok?O(vP(n.value,r.value)):r}function p3(e,t){let n=O4(e.radius1,t.env,`Cone.radius1`);if(!n.ok)return n;let r=O4(e.radius2,t.env,`Cone.radius2`);if(!r.ok)return r;let i=O4(e.height,t.env,`Cone.height`);return i.ok?O(bP(n.value,r.value,i.value)):i}function m3(e,t){let n=O4(e.majorRadius,t.env,`Torus.majorRadius`);if(!n.ok)return n;let r=O4(e.minorRadius,t.env,`Torus.minorRadius`);return r.ok?O(xP(n.value,r.value)):r}function h3(e,t){let n=[];for(let r of e.points){let e=k4(r,t.env,`Polygon.point`);if(!e.ok)return e;n.push(e.value)}return LP(n)}function g3(e,t){let n=O4(e.radius,t.env,`Circle.radius`);return n.ok?O(wP(n.value)):n}function _3(e,t){let n=k4(e.from,t.env,`Line.from`);if(!n.ok)return n;let r=k4(e.to,t.env,`Line.to`);return r.ok?O(CP(n.value,r.value)):r}function v3(e,t){let n=k4(e.point,t.env,`Vertex.point`);return n.ok?O(RP(n.value)):n}function y3(e){return k(Do(M.NULL_SHAPE_INPUT,`${e}: empty result has no kernel representation`))}function b3(e,t,n){let r=e.evalNode(t);return r.ok?BE(r.value)?O(r.value):k(wo(M.CSG_NOT_3D,`${n}: operand did not produce a 3D shape`)):r}function x3(e,t){return{unsafe:!0,fuzzyValue:e.tolerance??t.tolerance}}function S3(e,t){if(e.a.kind===`Empty`)return t.evalNode(e.b);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=b3(t,e.a,`Fuse.a`);if(!n.ok)return n;let r=b3(t,e.b,`Fuse.b`);return r.ok?HA(n.value,r.value,x3(e,t)):r}function C3(e,t){if(e.a.kind===`Empty`)return y3(`Cut`);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=b3(t,e.a,`Cut.a`);if(!n.ok)return n;let r=b3(t,e.b,`Cut.b`);return r.ok?UA(n.value,r.value,x3(e,t)):r}function w3(e,t){if(e.a.kind===`Empty`||e.b.kind===`Empty`)return y3(`Intersect`);let n=b3(t,e.a,`Intersect.a`);if(!n.ok)return n;let r=b3(t,e.b,`Intersect.b`);return r.ok?WA(n.value,r.value,x3(e,t)):r}function T3(e,t,n){let r=[];for(let i of t){let t=b3(e,i,n);if(!t.ok)return t;r.push(t.value)}return O(r)}function E3(e,t){let n=e.shapes.filter(e=>e.kind!==`Empty`);if(n.length===0)return y3(`FuseAll`);if(n.length===1&&n[0])return t.evalNode(n[0]);let r=T3(t,n,`FuseAll.operand`);return r.ok?KA(r.value,x3(e,t)):r}function D3(e,t){if(e.base.kind===`Empty`)return y3(`CutAll`);let n=e.tools.filter(e=>e.kind!==`Empty`);if(n.length===0)return t.evalNode(e.base);let r=b3(t,e.base,`CutAll.base`);if(!r.ok)return r;let i=T3(t,n,`CutAll.tool`);return i.ok?qA(r.value,i.value,x3(e,t)):i}function O3(e){return k(Do(M.NULL_SHAPE_INPUT,`${e}: cannot transform an Empty node`))}function k3(e,t,n,r){return e?k4(e,t,n):O(r)}function A3(e,t){let n=H(),{handle:r,dispose:i}=n.composeTransform(t),a;try{a=HE(n.locate(e.wrapped,r))}finally{i()}return ck(e)&&fk(e,a),a}function j3(e,t){if(e.target.kind===`Empty`)return O3(`Translate`);let n=k4(e.vector,t.env,`Translate.vector`);if(!n.ok)return n;let r=t.evalNode(e.target);return r.ok?O(A3(r.value,[{type:`translate`,x:n.value[0],y:n.value[1],z:n.value[2]}])):r}function M3(e,t){if(e.target.kind===`Empty`)return O3(`Rotate`);let n=O4(e.angle,t.env,`Rotate.angle`);if(!n.ok)return n;let r=k3(e.axis,t.env,`Rotate.axis`,[0,0,1]);if(!r.ok)return r;let i=k3(e.at,t.env,`Rotate.at`,[0,0,0]);if(!i.ok)return i;let a=t.evalNode(e.target);return a.ok?O(A3(a.value,[{type:`rotate`,angle:n.value,axis:r.value,center:i.value}])):a}function N3(e,t){if(e.target.kind===`Empty`)return O3(`Scale`);let n=O4(e.factor,t.env,`Scale.factor`);if(!n.ok)return n;let r=k3(e.center,t.env,`Scale.center`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(gk(i.value,n.value,r.value)):i}function P3(e,t){if(e.target.kind===`Empty`)return O3(`Mirror`);let n=k3(e.normal,t.env,`Mirror.normal`,[1,0,0]);if(!n.ok)return n;let r=k3(e.at,t.env,`Mirror.at`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(hk(i.value,n.value,r.value)):i}function F3(e,t){let n=e.children.filter(e=>e.kind!==`Empty`);if(n.length===0)return k(Do(M.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(zP(r))}function I3(){return k(Do(M.NULL_SHAPE_INPUT,`Empty: cannot materialize an Empty node directly — only valid as boolean/transform operand`))}function L3(e,t){let n=t.evalNode(e.source);return n.ok?O$(T$(n.value,e.placements),{fuse:e.fuse}):n}function R3(e,t){switch(e.kind){case`Box`:return u3(e,t);case`Sphere`:return d3(e,t);case`Cylinder`:return f3(e,t);case`Cone`:return p3(e,t);case`Torus`:return m3(e,t);case`Polygon`:return h3(e,t);case`Circle`:return g3(e,t);case`Line`:return _3(e,t);case`Vertex`:return v3(e,t);case`Empty`:return I3();case`Fuse`:return S3(e,t);case`Cut`:return C3(e,t);case`Intersect`:return w3(e,t);case`FuseAll`:return E3(e,t);case`CutAll`:return D3(e,t);case`Translate`:return j3(e,t);case`Rotate`:return M3(e,t);case`Scale`:return N3(e,t);case`Mirror`:return P3(e,t);case`Compound`:return F3(e,t);case`Instance`:return L3(e,t)}}function z3(e,t){if(typeof t==`number`)return Q2(t4(e,!1),t);let n=t4(e,!0);n=e4(n,t.length);for(let e of t)n=Q2(n,e);return n}function B3(e,t){if(t.size===0)return W2();let n=A4(e,t),r=Object.keys(n).sort(),i=W2();for(let e of r){i=J2(i,e);let t=n[e];t!==void 0&&(i=z3(i,t))}return i}function V3(e,t,n,r){let i=B3(t,e.freeParams),a=r===void 0?`d`:Q2(W2(),r).toString(16);return`${n4(e.structuralHash)}:${n}:${n4(i)}:${a}`}var H3=[1,0,0,0];function U3(e,t){let n=O4(e.angle,t,`evaluateMesh.peelRigid`);if(!n.ok)return null;let r=e.axis?k4(e.axis,t,`evaluateMesh.peelRigid`):O([0,0,1]);if(!r.ok)return null;let i=e.at?k4(e.at,t,`evaluateMesh.peelRigid`):O([0,0,0]);return i.ok?{angle:n.value,axis:r.value,center:i.value}:null}function W3(e,t){let n=e,r=H3,i=[0,0,0];for(;;)if(n.kind===`Translate`){let e=k4(n.vector,t,`evaluateMesh.peelRigid`);if(!e.ok)break;let a=cF(r,e.value);i=[i[0]+a[0],i[1]+a[1],i[2]+a[2]],n=n.target}else if(n.kind===`Rotate`){let e=U3(n,t);if(!e)break;let a=lF(e.axis,e.angle*Math.PI/180),o=dF(r,a),s=cF(r,e.center),c=cF(o,e.center);i=[i[0]+s[0]-c[0],i[1]+s[1]-c[1],i[2]+s[2]-c[2]],r=o,n=n.target}else break;return{inner:n,rot:r,trans:i}}function G3(e){return e[0]===1&&e[1]===0&&e[2]===0&&e[3]===0}function K3(e,t,n,r,i,a,o,s,c){for(let l=0;l<t.length;l+=3){let u=t[l]??0,d=t[l+1]??0,f=t[l+2]??0,p=2*(i*f-a*d),m=2*(a*u-r*f),h=2*(r*d-i*u);e[l]=u+n*p+(i*h-a*m)+o,e[l+1]=d+n*m+(a*p-r*h)+s,e[l+2]=f+n*h+(r*m-i*p)+c}}function q3(e,t,n){let[r,i,a]=n,o=G3(t);if(o&&r===0&&i===0&&a===0)return e;let s=e.vertices,c=new Float32Array(s.length);if(o){for(let e=0;e<s.length;e+=3)c[e]=(s[e]??0)+r,c[e+1]=(s[e+1]??0)+i,c[e+2]=(s[e+2]??0)+a;return{...e,vertices:c}}let[l,u,d,f]=t;K3(c,s,l,u,d,f,r,i,a);let p=e.normals,m=new Float32Array(p.length);return K3(m,p,l,u,d,f,0,0,0),{...e,vertices:c,normals:m}}function J3(e,t,n){let r=new Map,i=Math.min(t.length,n.length);for(let e=0;e<i;e++){let i=t[e],a=n[e];i!==void 0&&a!==void 0&&r.set(i,a)}return e.map(e=>({...e,faceId:r.get(e.faceId)??e.faceId}))}var Y3=class{cache=new Map;refCounts=new Map;evaluating=!1;pendingKeys=[];kernelId;defaultTolerance;maxCacheEntries;maxMeshCacheEntries;meshCache=new Map;onStep;hits=0;misses=0;evictions=0;constructor(e={}){this.kernelId=e.kernel??ET()??`unregistered`,this.defaultTolerance=e.tolerance,e.onStep&&(this.onStep=e.onStep);let t=e.maxCacheEntries;if(t!==void 0&&(!Number.isInteger(t)||t<1))throw RangeError(`Evaluator: maxCacheEntries must be a positive integer, got ${String(t)}`);this.maxCacheEntries=t;let n=e.maxMeshCacheEntries;if(n!==void 0&&(!Number.isInteger(n)||n<1))throw RangeError(`Evaluator: maxMeshCacheEntries must be a positive integer, got ${String(n)}`);this.maxMeshCacheEntries=n}evaluate(e,t={}){if(this.maxCacheEntries!==void 0&&this.evaluating)throw Error(`Evaluator.evaluate() is not reentrant when maxCacheEntries is set — do not call it from an onStep callback.`);return DT(this.kernelId,()=>{this.evaluating=!0;let n=!1;try{let r=this.evaluateInner(e,t);return this.maxCacheEntries!==void 0&&r.ok&&this.trimCache(this.maxCacheEntries),n=r.ok,r}finally{!n&&this.maxCacheEntries!==void 0&&this.rollbackPending(),this.pendingKeys.length=0,this.evaluating=!1}})}evaluateMesh(e,t={},n={}){n.signal?.throwIfAborted();let r=n.cache??!0,i=Fo(),a=n.tolerance??i.tolerance,o=n.angularTolerance??i.angularTolerance,s=`${V3(e,t,this.kernelId,this.defaultTolerance)}|${qk(a,o,n.skipNormals??!1,n.includeUVs??!1)}`;if(r){let r=this.meshCache.get(s);if(r!==void 0)return this.maxMeshCacheEntries!==void 0&&(this.meshCache.delete(s),this.meshCache.set(s,r)),O(r);let{inner:i,rot:a,trans:o}=W3(e,t);if(i!==e){let r=this.evaluateMesh(i,t,n);if(!r.ok)return r;let c=this.evaluate(i,t);if(!c.ok)return c;let l=fD(c.value).map(Dk),u=this.evaluate(e,t);if(!u.ok)return u;let d=fD(u.value).map(Dk),f=q3(r.value,a,o),p=J3(f.faceGroups,l,d),m=new Set(d);if(p.every(e=>m.has(e.faceId))){let e={...f,faceGroups:p};return this.meshCache.set(s,e),this.maxMeshCacheEntries!==void 0&&this.trimMeshCache(this.maxMeshCacheEntries),O(e)}}}let c=this.evaluate(e,t);if(!c.ok)return c;let l=DT(this.kernelId,()=>rA(c.value,n));return r&&(this.meshCache.set(s,l),this.maxMeshCacheEntries!==void 0&&this.trimMeshCache(this.maxMeshCacheEntries)),O(l)}evaluateInner(e,t){let n=V3(e,t,this.kernelId,this.defaultTolerance),r=this.cache.get(n);if(r!==void 0)return this.hits++,this.maxCacheEntries!==void 0&&(this.cache.delete(n),this.cache.set(n,r)),this.onStep?.({node:e,cacheKey:n,cacheHit:!0}),O(r);this.misses++;let i=R3(e,{env:t,tolerance:this.defaultTolerance,evalNode:e=>this.evaluateInner(e,t)});if(!i.ok)return i;let a=i.value;return this.refCounts.set(a,(this.refCounts.get(a)??0)+1),this.cache.set(n,a),this.maxCacheEntries!==void 0&&this.pendingKeys.push(n),this.onStep?.({node:e,cacheKey:n,cacheHit:!1}),i}releaseShape(e){let t=(this.refCounts.get(e)??1)-1;t<=0?(this.refCounts.delete(e),e[Symbol.dispose]()):this.refCounts.set(e,t)}trimCache(e){for(;this.cache.size>e;){let e=this.cache.keys().next();if(e.done)break;let t=e.value,n=this.cache.get(t);this.cache.delete(t),this.evictions++,n!==void 0&&this.releaseShape(n)}}trimMeshCache(e){for(;this.meshCache.size>e;){let e=this.meshCache.keys().next();if(e.done)break;this.meshCache.delete(e.value)}}rollbackPending(){for(let e of this.pendingKeys){let t=this.cache.get(e);t!==void 0&&(this.cache.delete(e),this.releaseShape(t))}}cacheStats(){return{hits:this.hits,misses:this.misses,entries:this.cache.size,evictions:this.evictions}}resetStats(){this.hits=0,this.misses=0,this.evictions=0}[Symbol.dispose](){for(let e of this.refCounts.keys())e[Symbol.dispose]();this.refCounts.clear(),this.cache.clear(),this.meshCache.clear()}};function X3(e,t){try{var n=LT();let r=t(n.u(new Y3(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 Z3(e){return{csgVersion:1,root:r6(e)}}function Q3(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:Q3(e.a),b:Q3(e.b)};case`UnaryOp`:return{kind:`UnaryOp`,op:e.op,arg:Q3(e.arg)};case`Component`:return{kind:`Component`,vec:Q3(e.vec),index:e.index};case`BuildVec`:return{kind:`BuildVec`,dim:e.dim,components:e.components.map(Q3)}}}function $3(e){switch(e.kind){case`Box`:return{kind:`Box`,x:Q3(e.x),y:Q3(e.y),z:Q3(e.z)};case`Sphere`:return{kind:`Sphere`,radius:Q3(e.radius)};case`Cylinder`:return{kind:`Cylinder`,radius:Q3(e.radius),height:Q3(e.height)};case`Cone`:return{kind:`Cone`,radius1:Q3(e.radius1),radius2:Q3(e.radius2),height:Q3(e.height)};case`Torus`:return{kind:`Torus`,majorRadius:Q3(e.majorRadius),minorRadius:Q3(e.minorRadius)};case`Polygon`:return{kind:`Polygon`,points:e.points.map(Q3)};case`Circle`:return{kind:`Circle`,radius:Q3(e.radius)};case`Line`:return{kind:`Line`,from:Q3(e.from),to:Q3(e.to)};case`Vertex`:return{kind:`Vertex`,point:Q3(e.point)};case`Empty`:return{kind:`Empty`,output:e.output};default:return}}function e6(e){switch(e.kind){case`Fuse`:case`Cut`:case`Intersect`:return{kind:e.kind,a:r6(e.a),b:r6(e.b),tolerance:e.tolerance};case`FuseAll`:return{kind:`FuseAll`,shapes:e.shapes.map(r6),tolerance:e.tolerance};case`CutAll`:return{kind:`CutAll`,base:r6(e.base),tools:e.tools.map(r6),tolerance:e.tolerance};default:return}}function t6(e){return e?Q3(e):void 0}function n6(e){switch(e.kind){case`Translate`:return{kind:`Translate`,target:r6(e.target),vector:Q3(e.vector)};case`Rotate`:return{kind:`Rotate`,target:r6(e.target),angle:Q3(e.angle),axis:t6(e.axis),at:t6(e.at)};case`Scale`:return{kind:`Scale`,target:r6(e.target),factor:Q3(e.factor),center:t6(e.center)};case`Mirror`:return{kind:`Mirror`,target:r6(e.target),normal:t6(e.normal),at:t6(e.at)};default:return}}function r6(e){return e.kind===`Compound`?{kind:`Compound`,children:e.children.map(r6)}:e.kind===`Instance`?{kind:`Instance`,source:r6(e.source),placements:e.placements,fuse:e.fuse}:$3(e)??e6(e)??n6(e)}function i6(e){return k(P(M.NULL_SHAPE_INPUT,`csg.fromJSON: ${e}`))}function a6(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function o6(e){return typeof e==`number`&&Number.isFinite(e)}function s6(e){return typeof e==`string`}function c6(e,t){if(!Array.isArray(e)||e.length!==3)return i6(`${t}: expected Vec3 array`);let[n,r,i]=e;return!o6(n)||!o6(r)||!o6(i)?i6(`${t}: Vec3 contains non-number`):O([n,r,i])}function l6(e,t){if(!Array.isArray(e)||e.length!==2)return i6(`${t}: expected Vec2 array`);let[n,r]=e;return!o6(n)||!o6(r)?i6(`${t}: Vec2 contains non-number`):O([n,r])}function u6(e){if(!a6(e))return i6(`input is not an object`);let t=e.csgVersion;if(t!==1)return i6(`unsupported csgVersion ${String(t)} (expected 1)`);let n=e.root;return v6(n)}function d6(e){if(!a6(e))return i6(`expression: not an object`);let t=e.kind;switch(t){case`NumLit`:return o6(e.value)?O(a4(e.value)):i6(`NumLit.value`);case`Vec3Lit`:{let t=c6(e.value,`Vec3Lit.value`);return t.ok?O(o4(t.value)):t}case`Vec2Lit`:{let t=l6(e.value,`Vec2Lit.value`);return t.ok?O(s4(t.value)):t}case`Param`:return s6(e.name)?O(c4(e.name)):i6(`Param.name`);case`BinOp`:return f6(e);case`UnaryOp`:return p6(e);case`Component`:return m6(e);case`BuildVec`:return h6(e);default:return i6(`unknown expression kind: ${String(t)}`)}}function f6(e){let t=e.op;if(t!==`+`&&t!==`-`&&t!==`*`&&t!==`/`)return i6(`BinOp.op: ${String(t)}`);let n=d6(e.a);if(!n.ok)return n;let r=d6(e.b);return r.ok?O(l4(t,n.value,r.value)):r}function p6(e){let t=e.op;if(!s6(t)||![`neg`,`sin`,`cos`,`sqrt`,`abs`].includes(t))return i6(`UnaryOp.op: ${String(t)}`);let n=d6(e.arg);return n.ok?O(u4(t,n.value)):n}function m6(e){let t=e.index;if(t!==0&&t!==1&&t!==2)return i6(`Component.index: ${String(t)}`);let n=d6(e.vec);return n.ok?O(d4(n.value,t)):n}function h6(e){let t=e.dim;if(t!==2&&t!==3)return i6(`BuildVec.dim: ${String(t)}`);let n=e.components;if(!Array.isArray(n))return i6(`BuildVec.components: not array`);if(n.length!==t)return i6(`BuildVec.components: expected ${t} components, got ${n.length}`);let r=[];for(let e of n){let t=d6(e);if(!t.ok)return t;r.push(t.value)}return O(f4(t,r))}function g6(e,t){if(!Array.isArray(e))return i6(`${t}: not array`);let n=[];for(let t of e){let e=v6(t);if(!e.ok)return e;n.push(e.value)}return O(n)}function _6(e){let t=e.tolerance;return t==null?O(void 0):o6(t)?O(t):i6(`tolerance: not a finite number`)}function v6(e){if(!a6(e))return i6(`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 b6(t,e);case`Fuse`:case`Cut`:case`Intersect`:return O6(t,e);case`FuseAll`:case`CutAll`:return k6(t,e);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return A6(t,e);case`Compound`:return I6(e);case`Instance`:return R6(e);default:return i6(`unknown node kind: ${String(t)}`)}}function y6(e,t,n){let r=d6(e[t]);return r.ok?O(n(r.value)):r}function b6(e,t){switch(e){case`Box`:return x6(t);case`Sphere`:return y6(t,`radius`,R4);case`Cylinder`:return S6(t);case`Cone`:return C6(t);case`Torus`:return w6(t);case`Polygon`:return T6(t);case`Circle`:return y6(t,`radius`,U4);case`Line`:return E6(t);case`Vertex`:return y6(t,`point`,G4);case`Empty`:return D6(t)}return i6(`unhandled primitive: ${e}`)}function x6(e){let t=d6(e.x);if(!t.ok)return t;let n=d6(e.y);if(!n.ok)return n;let r=d6(e.z);return r.ok?O(L4(t.value,n.value,r.value)):r}function S6(e){let t=d6(e.radius);if(!t.ok)return t;let n=d6(e.height);return n.ok?O(z4(t.value,n.value)):n}function C6(e){let t=d6(e.radius1);if(!t.ok)return t;let n=d6(e.radius2);if(!n.ok)return n;let r=d6(e.height);return r.ok?O(B4(t.value,n.value,r.value)):r}function w6(e){let t=d6(e.majorRadius);if(!t.ok)return t;let n=d6(e.minorRadius);return n.ok?O(V4(t.value,n.value)):n}function T6(e){let t=e.points;if(!Array.isArray(t))return i6(`Polygon.points: not array`);let n=[];for(let e of t){let t=d6(e);if(!t.ok)return t;n.push(t.value)}return O(H4(n))}function E6(e){let t=d6(e.from);if(!t.ok)return t;let n=d6(e.to);return n.ok?O(W4(t.value,n.value)):n}function D6(e){let t=e.output;switch(t){case`Solid`:return O(q4());case`Face`:return O(J4());case`Wire`:return O(Y4());default:return i6(`Empty.output: ${String(t)}`)}}function O6(e,t){let n=v6(t.a);if(!n.ok)return n;let r=v6(t.b);if(!r.ok)return r;let i=_6(t);if(!i.ok)return i;switch(e){case`Fuse`:return O(Z4(n.value,r.value,i.value));case`Cut`:return O(Q4(n.value,r.value,i.value));case`Intersect`:return O($4(n.value,r.value,i.value))}}function k6(e,t){let n=_6(t);if(!n.ok)return n;if(e===`FuseAll`){let e=g6(t.shapes,`FuseAll.shapes`);return e.ok?O(e3(e.value,n.value)):e}let r=v6(t.base);if(!r.ok)return r;let i=g6(t.tools,`CutAll.tools`);return i.ok?O(t3(r.value,i.value,n.value)):i}function A6(e,t){let n=v6(t.target);if(!n.ok)return n;switch(e){case`Translate`:return j6(t,n.value);case`Rotate`:return N6(t,n.value);case`Scale`:return P6(t,n.value);case`Mirror`:return F6(t,n.value)}}function j6(e,t){let n=d6(e.vector);return n.ok?O(r3(t,n.value)):n}function M6(e,t){if(e[t]===void 0)return O(void 0);let n=d6(e[t]);return n.ok?O(n.value):n}function N6(e,t){let n=d6(e.angle);if(!n.ok)return n;let r=M6(e,`axis`);if(!r.ok)return r;let i=M6(e,`at`);return i.ok?O(i3(t,n.value,{axis:r.value,at:i.value})):i}function P6(e,t){let n=d6(e.factor);if(!n.ok)return n;let r=M6(e,`center`);return r.ok?O(a3(t,n.value,{center:r.value})):r}function F6(e,t){let n=M6(e,`normal`);if(!n.ok)return n;let r=M6(e,`at`);return r.ok?O(o3(t,{normal:n.value,at:r.value})):r}function I6(e){let t=g6(e.children,`Compound.children`);return t.ok?O(s3(t.value)):t}function L6(e){return Array.isArray(e)&&e.length===4&&e.every(e=>Array.isArray(e)&&e.length===4&&e.every(o6))}function R6(e){let t=v6(e.source);if(!t.ok)return t;let n=e.placements;return!Array.isArray(n)||!n.every(L6)?i6(`Instance.placements must be an array of 4x4 number matrices`):O(c3(t.value,n,e.fuse===!0))}function z6(e){return H6(e)}function B6(e){switch(e.kind){case`NumLit`:case`Vec3Lit`:case`Vec2Lit`:case`Param`:return e;case`BinOp`:{let t=B6(e.a),n=B6(e.b);if(t.kind===`NumLit`&&n.kind===`NumLit`)switch(e.op){case`+`:return a4(t.value+n.value);case`-`:return a4(t.value-n.value);case`*`:return a4(t.value*n.value);case`/`:return a4(t.value/n.value)}return t!==e.a||n!==e.b?l4(e.op,t,n):e}case`UnaryOp`:{let t=B6(e.arg);if(t.kind===`NumLit`){let n=t.value;switch(e.op){case`neg`:return a4(-n);case`sin`:return a4(Math.sin(n));case`cos`:return a4(Math.cos(n));case`sqrt`:return a4(Math.sqrt(n));case`abs`:return a4(Math.abs(n))}}return t===e.arg?e:u4(e.op,t)}case`Component`:{let t=B6(e.vec);return t.kind===`Vec3Lit`||t.kind===`Vec2Lit`&&(e.index===0||e.index===1)?a4(t.value[e.index]):t===e.vec?e:d4(t,e.index)}case`BuildVec`:{let t=e.components.map(B6);return V6(e.dim,t)||(t.some((t,n)=>t!==e.components[n])?f4(e.dim,t):e)}}}function V6(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?s4([n[0],n[1]]):o4([n[0],n[1],n[2]])}function H6(e){switch(e.kind){case`Box`:return L4(B6(e.x),B6(e.y),B6(e.z));case`Sphere`:return R4(B6(e.radius));case`Cylinder`:return z4(B6(e.radius),B6(e.height));case`Cone`:return B4(B6(e.radius1),B6(e.radius2),B6(e.height));case`Torus`:return V4(B6(e.majorRadius),B6(e.minorRadius));case`Polygon`:return H4(e.points.map(B6));case`Circle`:return U4(B6(e.radius));case`Line`:return W4(B6(e.from),B6(e.to));case`Vertex`:return G4(B6(e.point));case`Empty`:return e;case`Fuse`:return U6(e.a,e.b,e.tolerance);case`Cut`:return W6(e.a,e.b,e.tolerance);case`Intersect`:return G6(e.a,e.b,e.tolerance);case`FuseAll`:return K6(e.shapes,e.tolerance);case`CutAll`:return q6(e.base,e.tools,e.tolerance);case`Translate`:return J6(e.target,e.vector);case`Rotate`:return i3(H6(e.target),B6(e.angle),{axis:e.axis?B6(e.axis):void 0,at:e.at?B6(e.at):void 0});case`Scale`:return a3(H6(e.target),B6(e.factor),{center:e.center?B6(e.center):void 0});case`Mirror`:return o3(H6(e.target),{normal:e.normal?B6(e.normal):void 0,at:e.at?B6(e.at):void 0});case`Compound`:return s3(e.children.map(H6).filter(e=>e.kind!==`Empty`));case`Instance`:return c3(H6(e.source),e.placements,e.fuse)}}function U6(e,t,n){let r=H6(e),i=H6(t);return r.kind===`Empty`?i:i.kind===`Empty`?r:Z4(r,i,n)}function W6(e,t,n){let r=H6(e),i=H6(t);return i.kind===`Empty`||r.kind===`Empty`?r:Q4(r,i,n)}function G6(e,t,n){let r=H6(e),i=H6(t);return r.kind===`Empty`?r:i.kind===`Empty`?i:$4(r,i,n)}function K6(e,t){let n=e.map(H6).filter(e=>e.kind!==`Empty`);return n.length===0?q4():n.length===1?n[0]:e3(n,t)}function q6(e,t,n){let r=H6(e);if(r.kind===`Empty`)return r;let i=t.map(H6).filter(e=>e.kind!==`Empty`);return i.length===0?r:t3(r,i,n)}function J6(e,t){let n=H6(e),r=B6(t);if(r.kind!==`Vec3Lit`)return r3(n,r);let[i,a,o]=r.value;if(i===0&&a===0&&o===0)return n;if(n.kind===`Translate`){let e=B6(n.vector);if(e.kind===`Vec3Lit`)return r3(n.target,[e.value[0]+i,e.value[1]+a,e.value[2]+o])}return r3(n,r)}function Y6(e,t,n){return X6(e,t,n)}function X6(e,t,n){return t(e)?n:Z6(e,t,n)}function Z6(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 Z4(X6(e.a,t,n),X6(e.b,t,n),e.tolerance);case`Cut`:return Q4(X6(e.a,t,n),X6(e.b,t,n),e.tolerance);case`Intersect`:return $4(X6(e.a,t,n),X6(e.b,t,n),e.tolerance);case`FuseAll`:return e3(e.shapes.map(e=>X6(e,t,n)),e.tolerance);case`CutAll`:return t3(X6(e.base,t,n),e.tools.map(e=>X6(e,t,n)),e.tolerance);case`Translate`:return r3(X6(e.target,t,n),e.vector);case`Rotate`:return i3(X6(e.target,t,n),e.angle,{axis:e.axis,at:e.at});case`Scale`:return a3(X6(e.target,t,n),e.factor,{center:e.center});case`Mirror`:return o3(X6(e.target,t,n),{normal:e.normal,at:e.at});case`Compound`:return s3(e.children.map(e=>X6(e,t,n)));case`Instance`:return c3(X6(e.source,t,n),e.placements,e.fuse)}}function Q6(e,t){t(e);for(let n of $6(e))Q6(n,t)}function $6(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;case`Instance`:return[e.source]}}function e8(e){let t=0;return Q6(e,()=>{t++}),t}var t8=RX({CSG_VERSION:()=>1,Evaluator:()=>Y3,add:()=>p4,asScalarExpr:()=>h4,asVec2Expr:()=>v4,asVec3Expr:()=>_4,binOp:()=>l4,box:()=>L4,buildVec:()=>f4,circle:()=>U4,component:()=>d4,compound:()=>s3,cone:()=>B4,cut:()=>Q4,cutAll:()=>t3,cylinder:()=>z4,emptyFace:()=>J4,emptySolid:()=>q4,emptyWire:()=>Y4,foldExpr:()=>B6,forEachNode:()=>Q6,fromJSON:()=>u6,fuse:()=>Z4,fuseAll:()=>e3,instance:()=>c3,intersect:()=>$4,line:()=>W4,mirror:()=>o3,mul:()=>m4,nodeCount:()=>e8,numLit:()=>a4,optimize:()=>z6,outputKindOf:()=>l3,param:()=>c4,polygon:()=>H4,replaceNode:()=>Y6,rotate:()=>i3,scale:()=>a3,sphere:()=>R4,toJSON:()=>Z3,torus:()=>V4,translate:()=>r3,unaryOp:()=>u4,vec2Lit:()=>s4,vec3Lit:()=>o4,vertex:()=>G4,withEvaluator:()=>X3});export{yR as BaseSketcher2d,bR as BlueprintSketcher,r as BrepBugError,M as BrepErrorCode,w0 as BrepWrapperError,zy as BrepkitAdapter,YK as CompoundSketch,o as DEFAULT_CAPABILITIES,YE as DEG2RAD,ZT as DisposalScope,a as EXACT_BREP_CAPABILITIES,Oq as FaceSketcher,G as HASH_CODE_MAX,Ja as OK,qa as OcctWasmAdapter,XE as RAD2DEG,dq as Sketch,Dq as Sketcher,fq as Sketches,ZP as addChild,UP as addHoles,OF as addJoint,a1 as addMate,lI as addStep,lN as adjacentFaces,ro as all,Qa as andThen,VX as applyGlue,R1 as applyMatrix,Gk as approximateCurve,sE as as2D,oE as as3D,sO as asTopo,wN as assignRoles,mM as autoHeal,AP as bezier,EY as blueprintToDXF,aj as booleanPipeline,N2 as booleans,x0 as boss,_P as box,kP as bsplineApprox,i as bug,wq as cameraFromPlane,Cq as cameraLookAt,gN as captureHint,pO as cast,HE as castShape,UE as castShape3D,e0 as chamfer,Cj as chamferDistAngleShape,Kj as chamferWithEvolution,c1 as checkAllInterferences,Lj as checkBoolean,s1 as checkInterference,wP as circle,JP as circularPattern,OO as classifyPointOnFace,tA as clearMeshCache,L1 as clone,gE as closedWire,ho as collect,rF as collectShapes,ik as colorFaces,rk as colorShape,wM as complexExtrude,Sk as composeTransforms,zP as compound,cq as compoundSketchExtrude,oq as compoundSketchFace,uq as compoundSketchLoft,lq as compoundSketchRevolve,Do as computationError,f$ as computeStraightSkeleton,bP as cone,z2 as construction,KQ as convexHull,TR as cornerFinder,nF as countNodes,GP as createAssembly,XP as createAssemblyNode,BJ as createBlueprint,Sq as createCamera,ME as createCompound,VJ as createCompoundBlueprint,rP as createDerivedFaceRef,JM as createDistanceQuery,EE as createEdge,BN as createEdgeRef,OE as createFace,qT as createHandle,cI as createHistory,XT as createKernelHandle,nA as createMeshCache,eO as createNamedPlane,AX as createOperationRegistry,QD as createPlane,TN as createRef,gI as createRegistry,kE as createShell,AE as createSolid,SX as createTaskQueue,TE as createVertex,JN as createVertexRef,DE as createWire,kX as createWorkerClient,FX as createWorkerHandler,IX as createWorkerPool,t8 as csg,Po as currentQuality,MJ as curve2dBoundingBox,zJ as curve2dDistanceFrom,NJ as curve2dFirstPoint,RJ as curve2dIsOnCurve,PJ as curve2dLastPoint,IJ as curve2dParameter,FJ as curve2dSplitAt,LJ as curve2dTangentAt,Rk as curveAxis,Pk as curveEndPoint,zk as curveIsClosed,Bk as curveIsPeriodic,Lk as curveLength,Vk as curvePeriod,Fk as curvePointAt,Nk as curveStartPoint,Ik as curveTangentAt,H1 as cut,dz as cut2D,W1 as cutAll,Oj as cutAllBisect,ez as cutBlueprints,Uj as cutWithEvolution,vP as cylinder,xF as cylindricalJoint,hN as defaultScorer,wX as dequeueTask,l0 as describe,aJ as deserializeDrawing,CI as deserializeHistory,hO as deserializeShape,dO as downcast,i0 as draft,sJ as draw,fJ as drawCircle,pJ as drawEllipse,bJ as drawFaceOutline,_J as drawParametricFunction,gJ as drawPointsInterpolation,mJ as drawPolysides,yJ as drawProjection,lJ as drawRectangle,cJ as drawRoundedRectangle,uJ as drawSingleCircle,dJ as drawSingleEllipse,hJ as drawText,EJ as drawingChamfer,CJ as drawingCut,TJ as drawingFillet,SJ as drawingFuse,wJ as drawingIntersect,xJ as drawingToSketchOnPlane,y0 as drill,YI as edgeFinder,aN as edgesOfFace,TP as ellipse,OP as ellipseArc,SP as ellipsoid,CX as enqueueTask,k as err,KP as exportAssemblySTEP,TY as exportDXF,fY as exportGlb,dY as exportGltf,uA as exportIGES,tY as exportOBJ,cA as exportSTEP,lX as exportSTEPConfigured,lA as exportSTL,GY as exportThreeMF,rI as exportURDF,m0 as extrude,MM as extrudeAll,PP as face,DO as faceAxis,EO as faceCenter,QI as faceFinder,vO as faceGeomType,yO as faceOrientation,rN as facesOfEdge,iN as facesOfVertex,PZ as fieldBoolean,RZ as fieldContour,FZ as fieldOffset,LZ as fieldReinit,IZ as fieldShell,FA as fill,FP as filledFace,$1 as fillet,Gj as filletWithEvolution,KO as findFacesByTag,eF as findNode,dI as findStep,_M as fixSelfIntersection,hM as fixShape,$a as flatMap,oo as flatten,bO as flipFaceOrientation,Uk as flipOrientation,hX as fontMetrics,MF as forwardKinematics,d0 as fromBREP,NQ as fromKernelDir,MQ as fromKernelPnt,jQ as fromKernelVec,co as fromNullable,V1 as fuse,lz as fuse2D,U1 as fuseAll,Mj as fuseAllBisect,$R as fuseBlueprints,Hj as fuseWithEvolution,J0 as gearGeometry,$X as getActiveVoxelId,TD as getBounds,HJ as getBounds2D,_D as getCompSolids,Mk as getCurveType,VT as getDisposalStats,dD as getEdges,ok as getFaceColor,NO as getFaceOrigins,qO as getFaceTags,fD as getFaces,hq as getFont,Dk as getHashCode,fI as getHistoryShape,H as getKernel,OT as getKernelCapabilities,MT as getKernelTier,wj as getNurbsCurveData,Tj as getNurbsSurfaceData,Hk as getOrientation,UJ as getOrientation2D,Uo as getPerformanceStats,ak as getShapeColor,dE as getShapeKind,gD as getShells,tL as getSingleFace,hD as getSolids,_O as getSurfaceType,YO as getTagMetadata,mD as getVertices,QX as getVoxel,pD as getWires,YP as gridPattern,kM as guidedSweep,a0 as heal,dM as healFace,uM as healSolid,fM as healWire,EP as helix,GQ as hull,p1 as importDXF,A1 as importGLB,fX as importIGES,_1 as importOBJ,uX as importSTEP,dX as importSTL,cX as importSVG,sX as importSVGPathD,k1 as importThreeMF,sI as importURDF,IT as init,CT as initFromManifold,PT as initFromOC,eZ as initVoxel,jO as innerWires,T$ as instance,D$ as instanceCount,E$ as instanceGrid,A$ as instancedMesh,Wk as interpolateCurve,G1 as intersect,fz as intersect2D,tz as intersectBlueprints,Wj as intersectWithEvolution,uD as invalidateShapeCache,KF as inverseKinematics,L2 as io,Oo as ioError,aE as is2D,iE as is3D,yX as isBatchRequest,UX as isChamferRadius,fE as isClosedWire,mO as isCompSolid,zE as isCompound,oP as isDerivedFaceRef,vX as isDisposeRequest,PE as isEdge,sP as isEdgeRef,p0 as isEmpty,Ak as isEqualShape,A as isErr,xX as isErrorResponse,IE as isFace,lP as isFaceRef,WX as isFilletRadius,gX as isInitRequest,WJ as isInside2D,w$ as isInstanced,uP as isLineageRef,rE as isLive,mE as isManifoldShell,HX as isNumber,Ya as isOk,_X as isOperationRequest,pE as isOrientedFace,bE as isPlanarFace,xE as isPlanarWire,yq as isProjectionPlane,EX as isQueueEmpty,kk as isSameShape,VE as isShape1D,BE as isShape3D,LE as isShell,RE as isSolid,bX as isSuccessResponse,f0 as isValid,hE as isValidSolid,NE as isVertex,cP as isVertexRef,FE as isWire,wD as iterCompSolids,vD as iterEdges,yD as iterFaces,CD as iterShells,SD as iterSolids,lO as iterTopo,xD as iterVertices,bD as iterWires,JF as jointTrajectory,DF as jointTransform,ZF as jointsFromDH,$E as kernelCall,eD as kernelCallRaw,tD as kernelCallScoped,N as kernelError,TQ as latticeInfill,EQ as latticeInfillShape,CP as line,qP as linearPattern,mq as loadFont,B1 as locate,g0 as loft,PM as loftAll,Rq as makeBaseBox,_2 as makeExternalGear,v2 as makeInternalGear,nO as makePlane,b2 as makePlanetaryGear,xq as makeProjectedEdges,vE as manifoldShell,Xa as map,so as mapBoth,Za as mapErr,mo as match,O$ as materialize,WM as measureArea,YM as measureCurvatureAt,XM as measureCurvatureAtMid,KM as measureDistance,qM as measureDistanceProps,GM as measureLength,HM as measureLinearProps,VM as measureSurfaceProps,UM as measureVolume,BM as measureVolumeProps,I2 as measurement,NF as mechanismDOF,s0 as mesh,c0 as meshEdges,hA as meshLODs,_A as meshLODsProgressive,dA as meshMultiLOD,XQ as minkowski,F1 as mirror,YJ as mirror2D,AJ as mirrorDrawing,S0 as mirrorJoin,P2 as modifiers,xI as modifyStep,Eo as moduleInitError,OM as multiSectionSweep,TO as normalAt,n0 as offset,VP as offsetFace,gZ as offsetMesh,yZ as offsetShape,Kk as offsetWire2D,O as ok,eo as or,to as orElse,lR as organiseBlueprints,_E as orientedFace,kO as outerWire,B2 as patterns,TX as pendingCount,vo as pipeline,aO as pivotPlane,SE as planarFace,SF as planarJoint,CE as planarWire,f2 as planetPlacements,b0 as pocket,SO as pointOnSurface,aZ as pointsInside,LP as polygon,ZQ as polyhedron,Pq as polysideInnerRadius,ER as polysidesBlueprint,Jj as positionOnCurve,FT as prewarm,M2 as primitives,bF as prismaticJoint,Tq as projectEdges,wO as projectPointOnFace,R2 as query,ko as queryError,C0 as rectangularPattern,jX as registerHandler,wT as registerKernel,jT as registerKernelTier,_I as registerOperation,hI as registerShape,ZX as registerVoxel,DX as rejectAll,QP as removeChild,AO as removeHolesFromFace,cZ as repairMesh,bI as replayFrom,yI as replayHistory,HT as resetDisposalStats,Wo as resetPerformanceStats,_k as resize,$ as resolve,j1 as resolve3D,iP as resolveDerivedFaceRef,PD as resolveDirection,VN as resolveEdgeRef,fP as resolveLineageRef,tO as resolvePlane,jN as resolveRef,mP as resolveRefIn,gP as resolveRefParams,YN as resolveVertexRef,jJ as reverseCurve,yF as revoluteJoint,h0 as revolve,b$ as roof,P1 as rotate,qJ as rotate2D,OJ as rotateDrawing,DR as roundedRectangleBlueprint,I1 as scale,JJ as scale2D,kJ as scaleDrawing,eQ as sdfBox,iQ as sdfCapsule,rQ as sdfCone,nQ as sdfCylinder,gQ as sdfFieldAxialRamp,yQ as sdfFieldClamp,hQ as sdfFieldConst,vQ as sdfFieldFromSdf,_Q as sdfFieldRadialRamp,uQ as sdfLattice,oQ as sdfPlane,tQ as sdfRoundedBox,$Z as sdfSphere,dQ as sdfStrutLattice,cQ as sdfSweep,aQ as sdfTorus,K1 as section,q1 as sectionToFace,SI as serializeHistory,TF as setJointValue,wF as setJointValues,MO as setShapeOrigin,JO as setTagMetadata,HP as sewShells,H0 as shape,uZ as shapeToMeshInput,uO as shapeType,dN as sharedEdges,t0 as shell,_Z as shellMesh,bZ as shellShape,qj as shellWithEvolution,o0 as simplify,kq as sketchCircle,Aq as sketchEllipse,nq as sketchExtrude,$K as sketchFace,Fq as sketchFaceOffset,Lq as sketchHelix,iq as sketchLoft,QJ as sketchOnFace2D,ZJ as sketchOnPlane2D,Iq as sketchParametricFunction,Nq as sketchPolysides,jq as sketchRectangle,tq as sketchRevolve,Mq as sketchRoundedRectangle,rq as sketchSweep,pX as sketchText,eq as sketchWires,To as sketcherStateError,Y1 as slice,BP as solid,gM as solidFromShell,o1 as solveAssembly,yP as sphere,CF as sphericalJoint,J1 as split,pI as stepCount,mI as stepsFrom,XJ as stretch2D,IP as subFace,CM as supportExtrude,yT as supportsConstraintSketch,vT as supportsProjection,BQ as surfaceFromGrid,UQ as surfaceFromImage,SM as sweep,GO as tagFaces,jP as tangentArc,io as tap,ao as tapErr,_q as textBlueprints,mX as textMetrics,r0 as thicken,wI as thread,DP as threePointArc,u0 as toBREP,vj as toBufferGeometryData,yj as toGroupedBufferGeometryData,OQ as toKernelVec,xj as toLODGeometryData,Sj as toLODGeometryLevels,bj as toLineGeometryData,GJ as toSVGPathD,MD as toVec2,jD as toVec3,xP as torus,DQ as tpmsLattice,z1 as transformCopy,F2 as transforms,M1 as translate,KJ as translate2D,DJ as translateDrawing,iO as translatePlane,go as tryCatch,_o as tryCatchAsync,TM as twistExtrude,wo as typeCastError,uI as undoLast,Ao as unsupportedError,j as unwrap,po as unwrapErr,uo as unwrapOr,fo as unwrapOrElse,$P as updateNode,DN as updateRoles,xO as uvBounds,CO as uvCoordinates,yE as validSolid,$0 as validatePlanetary,P as validationError,cM as variableFillet,FD as vecAdd,qD as vecAngle,BD as vecCross,UD as vecDistance,zD as vecDot,GD as vecEquals,KD as vecIsZero,VD as vecLength,HD as vecLengthSq,RD as vecNegate,WD as vecNormalize,JD as vecProjectToPlane,ZD as vecRepr,YD as vecRotate,LD as vecScale,ID as vecSub,RP as vertex,qX as vertexFinder,AD as vertexPosition,cN as verticesOfEdge,oN as verticesOfFace,vZ as voxelBoolean,NZ as voxelBooleanField,BZ as voxelBooleanFieldShapes,xZ as voxelBooleanShapes,MZ as voxelField,zZ as voxelFieldFromShape,tF as walkAssembly,iZ as windingNumbers,MP as wire,eL as wireFinder,NP as wireLoop,sN as wiresOfFace,DT as withKernel,IQ as withKernelDir,FQ as withKernelPnt,PQ as withKernelVec,kT as withQuality,QT as withScope,tE as withScopeResult,nE as withScopeResultAsync,NT as withTier,no as zipResults};
|