brepjs-cad 0.75.0 → 0.76.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.
@@ -12,28 +12,28 @@ var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports);function
12
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 tw(e,{vertProperties:Float32Array.from(r),triVerts:Uint32Array.from(i)})}function rw(e,t){let n=new Uint8Array(t),r=new TextDecoder().decode(n.subarray(0,Math.min(n.length,80))).trimStart().toLowerCase().startsWith(`solid`)&&ow(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=aw(i);return tw(e,{vertProperties:Float32Array.from(a.vertices),triVerts:Uint32Array.from(a.indices)})}var iw=1e6;function aw(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*iw)},${Math.round(o*iw)},${Math.round(s*iw)}`,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 ow(e){return e.length<84?!0:84+new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(80,!0)*50!==e.length}var sw=1e-6;function cw(e,t){let n=H(t);if(n.replayable)return $S(n,e)}function lw(e,t){let n=KC(t),r=Math.floor(n.triVerts.length/3),i=[];for(let t=0;t<r;t++){let[r,a,o]=XC(n,t),s=e.buildTriFace(YC(n,r),YC(n,a),YC(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,sw)}function uw(e){let t=Ly(`B-rep export`),n=cw(t,e);return n===void 0?(console.warn(`manifold: exact B-rep unavailable (non-replayable op-graph); exporting faceted approximation`),{occt:t,brep:lw(t,e)}):{occt:t,brep:n}}function dw(e,t,n,r){let i=t.mesh(n,{tolerance:.01,angularTolerance:.5});return tw(e,{vertProperties:Float32Array.from(i.vertices),triVerts:Uint32Array.from(i.triangles)},r)}var fw=1179937895,pw=2,mw=1313821514,hw=5130562,gw=5126,_w=5125,vw=5123,yw=5121,bw=34962,xw=34963,Sw=4;function Cw(e){return e+3&-4}function ww(e){let t=KC(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=Cw(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:Sw}]}],accessors:[{bufferView:0,componentType:gw,count:r,type:`VEC3`,min:[o,s,c],max:[l,u,d]},{bufferView:1,componentType:_w,count:i,type:`SCALAR`}],bufferViews:[{buffer:0,byteOffset:0,byteLength:p,target:bw},{buffer:0,byteOffset:m,byteLength:f.byteLength,target:xw}],buffers:[{byteLength:h}]},_=new TextEncoder().encode(JSON.stringify(g)),v=Cw(_.length),y=Cw(h),b=20+v+8+y,x=new ArrayBuffer(b),S=new DataView(x),C=new Uint8Array(x);S.setUint32(0,fw,!0),S.setUint32(4,pw,!0),S.setUint32(8,b,!0);let w=12;S.setUint32(w,v,!0),S.setUint32(w+4,mw,!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,hw,!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 Tw(e,t){let n=new DataView(t);if(n.getUint32(0,!0)!==fw)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===mw?i=JSON.parse(new TextDecoder().decode(s)):r===hw&&(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===_w?4:e.componentType===vw?2:+(e.componentType===yw);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 tw(e,{vertProperties:p,triVerts:m},`importGLB`)}function Ew(e){return{exportSTL:(e,t)=>QC(e,t),exportOBJ:e=>$C(e),exportPLY:e=>ew(e),importSTL:t=>rw(e,typeof t==`string`?new TextEncoder().encode(t).buffer:t),importOBJ:t=>nw(e,t),exportSTEP:e=>Ly(`exportSTEP`).exportSTEP(e.map(e=>uw(e).brep)),exportIGES:e=>Ly(`exportIGES`).exportIGES(e.map(e=>uw(e).brep)),toBREP:e=>{let{occt:t,brep:n}=uw(e);return t.toBREP(n)},exportSTEPAssembly:(e,t)=>{let n=Ly(`exportSTEPAssembly`),r=e.map(e=>{let t={shape:uw(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=Ly(`createXCAFDocument`),n=e.map(e=>{let t={shape:uw(e.shape).brep,name:e.name};return e.color===void 0?t:{...t,color:e.color}});return t.createXCAFDocument(n)},writeXCAFToSTEP:(e,t)=>Ly(`writeXCAFToSTEP`).writeXCAFToSTEP(e,t),exportSTEPConfigured:(e,t)=>{let n=Ly(`exportSTEPConfigured`),r=e.map(e=>{let t={shape:uw(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=Ly(`importSTEP`);return n.importSTEP(t).map(t=>dw(e,n,t,`importSTEP`))},importIGES:t=>{let n=Ly(`importIGES`);return n.importIGES(t).map(t=>dw(e,n,t,`importIGES`))},fromBREP:t=>{let n=Ly(`fromBREP`);return dw(e,n,n.fromBREP(t),`fromBREP`)},exportGLB:e=>ww(e),importGLB:t=>Tw(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 Dw(e){return V(e).getMesh()}function Ow(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 kw(e,t){let n=e;if(n&&n.__manifoldSub&&n.occt){let e=Iy();if(!e)throw Error(`manifold: sub-shape geometry query requires a registered occt kernel`);return t(n.occt,e)}let r=Py(e);if(!r)throw Error(`manifold: exact geometry query requires a manifold shape handle`);let i=Iy();if(!i)throw Error(`manifold: exact geometry query unsupported on manifold kernel; no B-rep kernel registered`);if(!r.node.replayable)throw Error(`manifold: exact geometry query unsupported; shape originates from a non-replayable op (raw mesh import or mesh boolean)`);let a=Ry.get(r.node);return a===void 0&&(a=$S(r.node,i),Ry.set(r.node,a)),t(a,i)}function Aw(e){let t=Py(e);if(!t)return;let n=t.node;return n.op===`profileEdge`?n.params?.curve:void 0}function jw(e){return{curveType:e=>{let t=Aw(e);return t?wb(t):PC(e)?e.curveType:kw(e,(e,t)=>t.curveType(e))},curveParameters:e=>{let t=Aw(e);if(t){let e=Tb(t);return[e.first,e.last]}return PC(e)?[0,e.length]:kw(e,(e,t)=>t.curveParameters(e))},curvePointAtParam:(e,t)=>{let n=Aw(e);return n?Eb(n,t):PC(e)?FC(e,t):kw(e,(e,n)=>n.curvePointAtParam(e,t))},curveTangent:(e,t)=>{let n=Aw(e);return n?{point:Eb(n,t),tangent:Db(n,t)}:PC(e)?{point:FC(e,t),tangent:IC(e,t)}:kw(e,(e,n)=>n.curveTangent(e,t))},curveIsClosed:e=>{let t=Aw(e);return t?kb(t):kw(e,(e,t)=>t.curveIsClosed(e))},curveIsPeriodic:e=>{let t=Aw(e);return t?Ab(t):kw(e,(e,t)=>t.curveIsPeriodic(e))},curvePeriod:e=>{let t=Aw(e);return t?jb(t):kw(e,(e,t)=>t.curvePeriod(e))},interpolatePoints:(e,t)=>Ly(`interpolatePoints`).interpolatePoints(e,t),approximatePoints:(e,t)=>Ly(`approximatePoints`).approximatePoints(e,t),curveDegreeElevate:(e,t)=>kw(e,(e,n)=>n.curveDegreeElevate(e,t)),curveKnotInsert:(e,t,n)=>kw(e,(e,r)=>r.curveKnotInsert(e,t,n)),curveKnotRemove:(e,t,n)=>kw(e,(e,r)=>r.curveKnotRemove(e,t,n)),curveSplit:(e,t)=>kw(e,(e,n)=>n.curveSplit(e,t)),createCurveAdaptor:e=>kw(e,(e,t)=>t.createCurveAdaptor(e)),getBezierPenultimatePole:e=>kw(e,(e,t)=>t.getBezierPenultimatePole(e)),getNurbsCurveData:e=>kw(e,(e,t)=>t.getNurbsCurveData?.(e)??null),vertexPosition:e=>NC(e)?e.point:Py(e)?Ow(Dw(e),0):kw(e,(e,t)=>t.vertexPosition(e)),surfaceType:e=>{if(wC(e))return`plane`;let t=Py(e);return t&&t.node.op===`profileFace`?`plane`:kw(e,(e,t)=>t.surfaceType(e))},uvBounds:e=>wC(e)?{uMin:0,uMax:1,vMin:0,vMax:1}:kw(e,(e,t)=>t.uvBounds(e)),outerWire:e=>kw(e,(e,t)=>t.outerWire(e)),surfaceNormal:(e,t,n)=>wC(e)?e.normal:kw(e,(e,r)=>r.surfaceNormal(e,t,n)),pointOnSurface:(e,t,n)=>kw(e,(e,r)=>r.pointOnSurface(e,t,n)),uvFromPoint:(e,t)=>kw(e,(e,n)=>n.uvFromPoint(e,t)),projectPointOnFace:(e,t)=>kw(e,(e,n)=>n.projectPointOnFace(e,t)),classifyPointOnFace:(e,t,n,r)=>kw(e,(e,i)=>i.classifyPointOnFace(e,t,n,r)),classifyPointRobust:(e,t,n)=>kw(e,(e,r)=>r.classifyPointRobust(e,t,n)),classifyPointWinding:(e,t,n)=>kw(e,(e,r)=>r.classifyPointWinding(e,t,n)),approximateSurfaceLspia:(e,t,n,r,i,a,o,s,c)=>Ly(`approximateSurfaceLspia`).approximateSurfaceLspia(e,t,n,r,i,a,o,s,c),untrimFace:(e,t,n)=>kw(e,(e,r)=>r.untrimFace(e,t,n)),getSurfaceCylinderData:e=>kw(e,(e,t)=>t.getSurfaceCylinderData(e)),getSurfaceAxis:e=>kw(e,(e,t)=>t.getSurfaceAxis(e)),reverseSurfaceU:e=>Ly(`reverseSurfaceU`).reverseSurfaceU(e),detectSmallFeatures:(e,t,n)=>kw(e,(e,r)=>r.detectSmallFeatures(e,t,n)),recognizeFeatures:(e,t)=>kw(e,(e,n)=>n.recognizeFeatures(e,t)),projectEdges:(e,t,n,r)=>kw(e,(e,i)=>i.projectEdges(e,t,n,r)),getNurbsSurfaceData:e=>kw(e,(e,t)=>t.getNurbsSurfaceData?.(e)??null)}}var Mw={hasErrors:!1,hasWarnings:!1,messages:[]};function Nw(){return{modified:new Map,generated:new Map,deleted:new Set}}function Pw(e){return{shape:e,evolution:Nw()}}function Fw(e){return{shape:e,evolution:Nw(),diagnostics:Mw}}function Iw(e){let t=_b(e),n=Yy(e),r=CS(e);return{translateWithHistory:(e,n,r,i)=>Pw(t.translate(e,n,r,i)),rotateWithHistory:(e,n,r,i,a,o)=>Pw(t.rotate(e,n,a,o)),mirrorWithHistory:(e,n,r)=>Pw(t.mirror(e,n,r)),scaleWithHistory:(e,n,r)=>Pw(t.scale(e,n,r)),generalTransformWithHistory:(e,n,r,i)=>Pw(t.generalTransform(e,n,r,i)),fuseWithHistory:(e,t,r,i,a)=>Fw(n.fuse(e,t,a)),cutWithHistory:(e,t,r,i,a)=>Fw(n.cut(e,t,a)),intersectWithHistory:(e,t,r,i,a)=>Fw(n.intersect(e,t,a)),filletWithHistory:(e,t,n)=>Pw(r.fillet(e,t,n)),chamferWithHistory:(e,t,n)=>Pw(r.chamfer(e,t,n)),shellWithHistory:(e,t,n,i,a,o)=>Pw(r.shell(e,t,n,o)),thickenWithHistory:(e,t)=>Pw(r.thicken(e,t)),offsetWithHistory:(e,t,n,i,a)=>Pw(r.offset(e,t,a)),draftWithHistory:(e,t,n,i,a)=>Pw(r.draft(e,t,n,i,a)),applyComposedTransformWithHistory:(e,n)=>Pw(t.transform(e,n))}}function Lw(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 Rw(e){return{isValid:e=>Lw(e),isValidStrict:e=>Lw(e),healSolid:e=>Lw(e)?e:null,healFace:e=>e,healWire:e=>e,mergeCoincidentVertices:()=>0,removeDegenerateEdges:()=>0,fixFaceOrientations:()=>0,fixShape:e=>e,fixSelfIntersection:e=>e}}var zw=.004;function Bw(e){return!!e&&typeof e==`object`&&e.__nativeC2d===!0}function Vw(e,t){return{__nativeC2d:!0,k:`line`,p1:e,p2:t}}function Hw(e,t,n,r,i){return{__nativeC2d:!0,k:`conic`,c:e,u:t,v:n,a0:r,a1:i}}function Uw(e,[t,n]){return[e.a*t+e.b*n+e.tx,e.c*t+e.d*n+e.ty]}function Ww(e,[t,n]){return[e.a*t+e.b*n,e.c*t+e.d*n]}function Gw(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 Kw(e,t){return e.k===`line`?Vw(Uw(t,e.p1),Uw(t,e.p2)):e.k===`bezier`?{__nativeC2d:!0,k:`bezier`,pts:e.pts.map(e=>Uw(t,e))}:Hw(Uw(t,e.c),Ww(t,e.u),Ww(t,e.v),e.a0,e.a1)}function qw(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 Jw(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 Yw(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 qw(r,t)}function Xw(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<=zw)return Math.max(2,Math.ceil(t/(2*Math.PI)*8));let a=2*Math.acos(Math.max(-1,1-zw/i));return Math.max(2,Math.ceil(t/a))}function Zw(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(qw(e.pts,n/24));return t}let t=e.a1-e.a0,n=Xw(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 Qw(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 Vw(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-_),Hw(f,[p,0],[0,p],h,_)}function $w(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(!Bw(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=Jw(n,n.a0),i=Jw(n,(n.a0+n.a1)/2),a=Jw(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(Zw(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)=>Vw([e,t],[n,r]),makeCircle2d:(e,t,n,r=!0)=>Hw([e,t],[n,0],r?[0,n]:[0,-n],0,2*Math.PI),makeArc2dThreePoints:(e,t,n,r,i,a)=>Qw([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 Vw([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),Hw([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 Hw([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 Hw([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`?qw(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:qw(n.pts,t),tangent:Yw(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 Hw(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 Vw([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=Gw(e,t);Object.assign(e,n)},transformCurve2dGeneral:(e,t)=>Kw(i(e),t),translateCurve2d:(e,t,n)=>Kw(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 Kw(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)=>Kw(i(e),{a:t,b:0,c:0,d:t,tx:n-t*n,ty:r-t*r}),mirrorCurve2dAtPoint:(e,t,n)=>Kw(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 Kw(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 Kw(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(Bw(t))r=Zw(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=Zw(i(e)).map(([e,n])=>[t[0]+l*e+f*n,t[1]+u*e+p*n,t[2]+d*e+m*n]);return Ny(n,B(`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)=>Bw(n)?t(n,...i):r(e,n,...i)))}return s}var eT=`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 tT(e){let t=Iy();if(!t)throw Error(`manifold: ${e} unsupported on manifold kernel; no B-rep kernel registered`);return t}function nT(e){let t={};for(let e of eT)t[e]=(...t)=>tT(e)[e](...t);let n=$w(e,()=>Iy());return Object.assign(t,n),t}function rT(e){return{sketchNew:()=>Ay(`sketchNew`),sketchAddPoint:()=>Ay(`sketchAddPoint`),sketchAddArc:()=>Ay(`sketchAddArc`),sketchAddConstraint:()=>Ay(`sketchAddConstraint`),sketchSolve:()=>Ay(`sketchSolve`),sketchDof:()=>Ay(`sketchDof`)}}function iT(e){return{projectEdges:()=>Ay(`projectEdges`)}}function aT(e){return{dispose(e){let t=Py(e);if(t){let e=Ry.get(t.node);e!==void 0&&(Iy()?.dispose(e),Ry.delete(t.node))}(e?.manifold)?.delete?.()},executeBatch:()=>Ay(`executeBatch`),checkpoint:()=>Ay(`checkpoint`),checkpointCount:()=>0,restoreCheckpoint:()=>Ay(`restoreCheckpoint`),discardCheckpoint:()=>Ay(`discardCheckpoint`)}}var oT={draft:30,standard:10,fine:3},sT=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?.(oT[e])}constructor(e){this.oc=e,Object.assign(this,Wy(e),Yy(e),_b(e),wx(e),Xx(e),CS(e),jS(e),xC(e),GC(e),Ew(e),jw(e),Iw(e),Rw(e),nT(e),rT(e),iT(e),aT(e))}};function cT(e){return import(e)}function lT(e){return`projectEdges`in e}function uT(e){return`sketchNew`in e&&`sketchDof`in e}var dT=new Map,fT=null,pT=null;function mT(e){hT(`manifold`,new sT(e))}function hT(e,t){dT.set(e,t),fT||=e,e===fT&&(pT=t)}function U(e){if(!e&&pT)return pT;let t=e??fT;if(!t)throw Error(`brepjs kernel not initialized. Call initFromOC() or registerKernel() before using the library.`);let n=dT.get(t);if(!n)throw Error(`brepjs: kernel '${t}' is not registered.`);return n}function gT(e){let t=U(e);if(!Do(t))throw Error(`brepjs: current kernel does not support 2D operations.`);return t}function _T(){return fT}function vT(e,t){let n=fT;fT=e,pT=dT.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{fT=n,pT=n?dT.get(n)??null:null}}function yT(e){return U(e).capabilities}function bT(e,t){let n=wo();try{Eo(e),U().setQuality?.(e);let n=t();if(n instanceof Promise)throw Error(`withQuality() callback returned a Promise. Async code must read currentQuality()/getKernel() directly.`);return n}finally{Eo(n),U().setQuality?.(n)}}var xT=new Map;function ST(e,t){xT.set(e,t)}function CT(e){return xT.get(e)}function wT(e,t){let n=xT.get(e);if(!n)throw Error(`withTier: no tier registered for "${e}". Call registerKernelTier("${e}", { kernel, quality }) first.`);return vT(n.kernel,()=>bT(n.quality,t))}function TT(e){Uo(),rl(),Io(),Nc(),Pc(),Yc(),Xc();let t=new zf(e);hT(`occt`,t),fT=`occt`,pT=t}function ET(){let e=U(),t=e.makeBox(1,1,1);try{e.dispose(t)}catch{}}async function DT(){if(fT)return fT;try{let{OcctKernel:e}=await cT(`occt-wasm`),t=await e.init();return hT(`occt-wasm`,La.fromKernel(t)),`occt-wasm`}catch{}try{return TT(await(await cT(`brepjs-opencascade`)).default()),`occt`}catch{}try{let e=await cT(`brepkit-wasm`);return typeof e.default==`function`&&await e.default(),hT(`brepkit`,new ky(new e.BrepKernel)),`brepkit`}catch{}throw Error(`brepjs: no kernel package found. Install one of:
13
13
  npm install occt-wasm (recommended, default)
14
14
  npm install brepjs-opencascade
15
- npm install brepkit-wasm`)}function OT(){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 kT=Symbol;kT.dispose??=Symbol.for(`Symbol.dispose`),kT.asyncDispose??=Symbol.for(`Symbol.asyncDispose`);var AT=globalThis;AT.FinalizationRegistry||=(console.warn(`brepjs: FinalizationRegistry unavailable — garbage collection will not work`),class{register(e,t,n){}unregister(e){return!1}});var jT={liveHandles:0,peakHandles:0,gcCollected:0,scopeEnters:0,scopeExits:0};function MT(){return{...jT}}function NT(){jT.liveHandles=0,jT.peakHandles=0,jT.gcCollected=0,jT.scopeEnters=0,jT.scopeExits=0}function PT(){jT.liveHandles++,jT.liveHandles>jT.peakHandles&&(jT.peakHandles=jT.liveHandles)}function FT(){jT.liveHandles--}function IT(){jT.gcCollected++,jT.liveHandles--}var LT=new FinalizationRegistry(e=>{IT();try{e.delete()}catch{}});function RT(e){let t=U(),n=!1,r,i=()=>{if(r){for(let e of r)try{e()}catch{}r=void 0}},a=()=>{if(!n){n=!0,FT(),LT.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 PT(),LT.register(o,{delete:()=>{t.dispose(e)}},o),o}function zT(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,FT(),LT.unregister(n);try{e.delete()}catch{}}}};return PT(),LT.register(n,e,n),n}var BT=class{handles=[];constructor(){jT.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](){jT.scopeExits++;for(let e=this.handles.length-1;e>=0;e--)this.handles[e]?.();this.handles.length=0}};function VT(e){try{var t=OT();return e(t.u(new BT))}catch(e){t.e=e}finally{t.d()}}function HT(e,t){LT.register(e,t,t)}function UT(e){LT.unregister(e)}function WT(e){try{var t=OT();return e(t.u(new BT))}catch(e){t.e=e}finally{t.d()}}async function GT(e){try{var t=OT();return await e(t.u(new BT))}catch(e){t.e=e}finally{t.d()}}function KT(e){return!e.disposed}function qT(e){return e.__is2D!==!0}function JT(e){return e.__is2D===!0}function YT(e){if(!qT(e))throw Error(`Expected 3D shape, got 2D`);return e}function XT(e){if(!JT(e))throw Error(`Expected 2D shape, got 3D`);return e}var ZT=new WeakMap;function QT(e,t){ZT.set(e,t)}function $T(e,t){let n=ZT.get(t);if(n!==void 0)return n;let r=e.shapeType(t);return ZT.set(t,r),r}function eE(e){return $T(U(),e.wrapped)}function tE(e){return U().curveIsClosed(e.wrapped)}function nE(e){return U().isValid(e.wrapped)}function rE(e){let t=U();if(!t.isValid(e.wrapped))return!1;let n=t.isValidStrict?.bind(t)??t.isValid.bind(t);try{let r=t.solidFromShell(e.wrapped),i=n(r);try{t.dispose(r)}catch{}return i}catch{return!1}}function iE(e){return U().isValid(e.wrapped)}function aE(e){return tE(e)?O(e):k(`Wire is not closed: start and end points do not coincide`)}function oE(e){return nE(e)?O(e):k(`Face orientation is inconsistent or face is invalid`)}function sE(e){return rE(e)?O(e):k(`Shell is not manifold: has free edges or is invalid`)}function cE(e){return iE(e)?O(e):k(`Solid failed BRepCheck validation`)}function lE(e){return U().surfaceType(e.wrapped)===`plane`}function uE(e){let t=U(),n=n=>{try{let r=t.makeFace(e.wrapped,n),i=t.surfaceType(r);try{t.dispose(r)}catch{}return i===`plane`}catch{return!1}};return n(!0)?!0:n(!1)}function dE(e){return lE(e)?O(e):k(`Face is not planar: underlying surface is not a geometric plane`)}function fE(e){return uE(e)?O(e):k(`Wire is not planar: edges do not lie in a common plane`)}function pE(e,t){return t===`2D`&&(e.__is2D=!0),e}function mE(e,t){return pE(RT(e),t)}function hE(e,t){return pE(RT(e),t)}function gE(e,t){return pE(RT(e),t)}function _E(e,t){return pE(RT(e),t)}function vE(e){return pE(RT(e))}function yE(e){return pE(RT(e))}function bE(e){return pE(RT(e))}function xE(e,t){return pE(RT(e),t)}function SE(e){return eE(e)===`vertex`}function CE(e){return eE(e)===`edge`}function wE(e){return eE(e)===`wire`}function TE(e){return eE(e)===`face`}function EE(e){return eE(e)===`shell`}function DE(e){return eE(e)===`solid`}function OE(e){return eE(e)===`compound`}function kE(e){let t=eE(e);return t===`shell`||t===`solid`||t===`compsolid`?!0:t===`compound`?qT(e):!1}function AE(e){let t=eE(e);return t===`edge`||t===`wire`}function jE(e,t){let n=U(),r=$T(n,e),i=n.downcast(e,r);return r===`vertex`?mE(i,t):r===`edge`?hE(i,t):r===`wire`?gE(i,t):r===`face`?_E(i,t):r===`shell`?vE(i):r===`solid`?yE(i):r===`compsolid`?bE(i):xE(i,t)}function ME(e){return jE(e)}function NE(e,t){let n=e.id,r=t.wrapped.id;(n!==void 0&&r!==void 0?n===r:t.wrapped===e)||U().dispose(e)}function W(e,t){let n=jE(e,t);return NE(e,n),n}function PE(e,t){let n=e.wrapped;if(e[Symbol.dispose](),n!==t){let e=U();e.dispose(n),e.dispose(t)}}function FE(e){U().dispose(e.wrapped),e[Symbol.dispose]()}function IE(e,t,n){QT(e,t);let r=U().downcast(e,t);return t===`vertex`?mE(r,n):t===`edge`?hE(r,n):t===`wire`?gE(r,n):t===`face`?_E(r,n):t===`shell`?vE(r):t===`solid`?yE(r):t===`compsolid`?bE(r):xE(r,n)}function LE(e,t,n){let r=IE(e,t,n);return NE(e,r),r}function RE(e,t,n,r,i){let a={kind:e,code:t,message:n,cause:r};return i?{...a,suggestion:i}:a}var zE={KERNEL_OPERATION:(e,t,n,r)=>RE(`KERNEL_OPERATION`,e,t,n,r),VALIDATION:(e,t,n,r)=>RE(`VALIDATION`,e,t,n,r),TYPE_CAST:(e,t,n,r)=>RE(`TYPE_CAST`,e,t,n,r),SKETCHER_STATE:(e,t,n,r)=>RE(`SKETCHER_STATE`,e,t,n,r),MODULE_INIT:(e,t,n,r)=>RE(`MODULE_INIT`,e,t,n,r),COMPUTATION:(e,t,n,r)=>RE(`COMPUTATION`,e,t,n,r),IO:(e,t,n,r)=>RE(`IO`,e,t,n,r),QUERY:(e,t,n,r)=>RE(`QUERY`,e,t,n,r),UNSUPPORTED:(e,t,n,r)=>RE(`UNSUPPORTED`,e,t,n,r)};function BE(e,t,n,r=`KERNEL_OPERATION`){try{return O(W(e()))}catch(e){let i=e instanceof Error?e.message:String(e),a=r===`KERNEL_OPERATION`?po(i):i,o=fo(t);return k(zE[r](t,`${n}: ${a}`,e,o))}}function VE(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`?po(i):i,o=fo(t);return k(zE[r](t,`${n}: ${a}`,e,o))}}function HE(e,t,n,r=`KERNEL_OPERATION`){try{var i=OT();let a=i.u(new BT);return BE(()=>e(a),t,n,r)}catch(e){i.e=e}finally{i.d()}}function UE(e,t){let n=U().iterShapes(e,t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=LE(n[e],t);return r}var WE=new WeakMap;function GE(e){let t=WE.get(e);if(!t)return;WE.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 KE=new WeakSet;function qE(e){let t=e.wrapped,n=WE.get(t);return n||(n={},WE.set(t,n)),KE.has(e)||(KE.add(e),e.onDispose(()=>{GE(t)})),n}function JE(e){return WE.get(e.wrapped)}function YE(e){GE(e.wrapped)}function XE(e){let t=qE(e);if(t.edges)return t.edges;let n=UE(e.wrapped,`edge`);return t.edges=n,n}function ZE(e){let t=qE(e);if(t.faces)return t.faces;let n=UE(e.wrapped,`face`);return t.faces=n,n}function QE(e){let t=qE(e);if(t.wires)return t.wires;let n=UE(e.wrapped,`wire`);return t.wires=n,n}function $E(e){let t=qE(e);if(t.vertices)return t.vertices;let n=UE(e.wrapped,`vertex`);return t.vertices=n,n}function eD(e){let t=qE(e);if(t.solids)return t.solids;let n=UE(e.wrapped,`solid`);return t.solids=n,n}function tD(e){let t=qE(e);if(t.shells)return t.shells;let n=UE(e.wrapped,`shell`);return t.shells=n,n}function nD(e){let t=qE(e);if(t.compSolids)return t.compSolids;let n=UE(e.wrapped,`compsolid`);return t.compSolids=n,n}function*rD(e){for(let t of U().iterShapes(e.wrapped,`edge`))yield LE(t,`edge`)}function*iD(e){for(let t of U().iterShapes(e.wrapped,`face`))yield LE(t,`face`)}function*aD(e){for(let t of U().iterShapes(e.wrapped,`wire`))yield LE(t,`wire`)}function*oD(e){for(let t of U().iterShapes(e.wrapped,`vertex`))yield LE(t,`vertex`)}function*sD(e){for(let t of U().iterShapes(e.wrapped,`solid`))yield LE(t,`solid`)}function*cD(e){for(let t of U().iterShapes(e.wrapped,`shell`))yield LE(t,`shell`)}function*lD(e){for(let t of U().iterShapes(e.wrapped,`compsolid`))yield LE(t,`compsolid`)}function uD(e){let t=qE(e);if(t.bounds)return t.bounds;let{min:n,max:r}=U().boundingBox(e.wrapped),i={xMin:n[0],xMax:r[0],yMin:n[1],yMax:r[1],zMin:n[2],zMax:r[2]};return t.bounds=i,i}function dD(e){return $T(U(),e.wrapped)}function fD(e){let t=qE(e);if(t.surfaceType!==void 0)return t.surfaceType;let n=U().surfaceType(e.wrapped);return t.surfaceType=n,n}function pD(e){let t=qE(e);if(t.isValid!==void 0)return t.isValid;let n=U().isValid(e.wrapped);return t.isValid=n,n}function mD(e){return{kind:dD(e),faceCount:ZE(e).length,edgeCount:XE(e).length,wireCount:QE(e).length,vertexCount:$E(e).length,valid:pD(e),bounds:uD(e)}}function hD(e){return U().vertexPosition(e.wrapped)}var G=2147483647,gD=Math.PI/180,_D=180/Math.PI;function vD(e){return e.length===2?[e[0],e[1],0]:[e[0],e[1],e[2]]}function yD(e){return[e[0],e[1]]}var bD={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function xD(e){if(typeof e==`string`){let t=bD[e];if(!t)throw Error(`Unknown direction: ${e}`);return t}return e}function SD(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function CD(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function wD(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function TD(e){return[-e[0],-e[1],-e[2]]}function ED(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function DD(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 OD(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function kD(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function AD(e,t){return OD(CD(e,t))}function jD(e){let t=OD(e);return t<1e-10?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function MD(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 ND(e,t=1e-10){return kD(e)<t*t}function PD(e,t){let n=ED(e,t),r=OD(e),i=OD(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 FD(e,t,n){let r=CD(e,t),i=kD(n);return i<1e-20?e:CD(e,wD(n,ED(r,n)/i))}function ID(e,t,n){let r=jD(t),i=Math.cos(n),a=Math.sin(n),o=ED(e,r),s=DD(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 LD=e=>Math.round(e*1e3)/1e3;function RD(e){return`x: ${LD(e[0])}, y: ${LD(e[1])}, z: ${LD(e[2])}`}function zD(e,t=null,n=[0,0,1]){let r=jD(n);if(ND(r))throw Error(`Plane normal must be non-zero`);let i;if(t)i=jD(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?jD([l,u,d]):[1,0,0]}if(ND(i))throw Error(`Plane xDir must be non-zero`);let a=jD(DD(r,i));return{origin:e,xDir:i,yDir:a,zDir:r}}var BD={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 VD(e,t=[0,0,0]){let n=BD[e];if(!n)return k(F(`UNKNOWN_PLANE`,`Could not find plane ${e}`));let r;return r=typeof t==`number`?wD(n.normal,t):vD(t),O(zD(r,n.xDir,n.normal))}function HD(e,t){return typeof e==`string`?VD(e,t):O(e)}function UD(e,t){return e&&typeof e!=`string`?{...e}:j(HD(e??`XY`,t))}function WD(e,t){let[n,r]=t;return SD(SD(e.origin,wD(e.xDir,n)),wD(e.yDir,r))}function GD(e,t){return{...e,origin:SD(e.origin,t)}}function KD(e,t,n=[1,0,0]){let r=t*gD,i=ID(e.zDir,n,r),a=ID(e.xDir,n,r),o=jD(DD(i,a));return{origin:e.origin,xDir:a,yDir:o,zDir:i}}var qD={compound:0,solidCompound:1,solid:2,shell:3,face:4,wire:5,edge:6,vertex:7,shape:8},JD=e=>qD[e],YD={vertex:`vertex`,edge:`edge`,wire:`wire`,face:`face`,shell:`shell`,solid:`solid`,solidCompound:`compsolid`,compound:`compound`,shape:`compound`},XD=function*(e,t){let n=U().iterShapes(e,YD[t]);for(let e of n)yield e},ZD=e=>U().isNull(e)?k(ho(`NULL_SHAPE`,`This shape has no type, it is null`)):O(e.ShapeType());function QD(e){if(U().isNull(e))return k(ho(`NULL_SHAPE`,`This shape has no type, it is null`));try{return O(U().downcast(e))}catch(e){return k(ho(`NO_WRAPPER`,`Could not find a wrapper for this shape type`,e))}}function $D(e){if(U().isNull(e))return k(ho(`NULL_SHAPE`,`Cannot copy a null shape`));try{return O(U().copyShape(e))}catch(e){return k(ho(`NO_WRAPPER`,`Could not copy this shape`,e))}}function eO(e){return U().isNull(e)?k(ho(`NULL_SHAPE`,`Cannot cast a null shape`)):O(jE(e))}function tO(e){return U().shapeType(e.wrapped)===`compsolid`}function nO(e){return eO(U().fromBREP(e))}var rO={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 iO(e){return O(rO[fD(e)])}function aO(e){return j(iO(e))}function oO(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function sO(e){return jE(U().reverseShape(e.wrapped))}function cO(e){return U().uvBounds(e.wrapped)}function lO(e,t,n){let r=cO(e),i=t*(r.uMax-r.uMin)+r.uMin,a=n*(r.vMax-r.vMin)+r.vMin;return U().pointOnSurface(e.wrapped,i,a)}function uO(e,t){let n=vD(t);return U().uvFromPoint(e.wrapped,n)||[0,0]}function dO(e,t){let n=vD(t);try{let t=n,r=U().uvFromPoint(e.wrapped,t);if(!r)return k(ho(`PROJECTION_FAILED`,`No projection found on the face`));let i=U().projectPointOnFace(e.wrapped,t),a=n[0]-i[0],o=n[1]-i[1],s=n[2]-i[2];return O({uv:r,point:i,distance:Math.sqrt(a*a+o*o+s*s)})}catch(e){return k(ho(`PROJECTION_FAILED`,`Point projection failed: ${e instanceof Error?e.message:String(e)}`))}}function fO(e,t){let n,r;if(t)[n,r]=uO(e,t);else{let t=cO(e);n=.5*(t.uMin+t.uMax),r=.5*(t.vMin+t.vMax)}return U().surfaceNormal(e.wrapped,n,r)}function pO(e){return U().surfaceCenterOfMass(e.wrapped)}function mO(e){return U().getSurfaceAxis(e.wrapped)}function hO(e,t,n=1e-6){let[r,i]=uO(e,t);return U().classifyPointOnFace(e.wrapped,r,i,n)}function gO(e){return jE(U().outerWire(e.wrapped))}function _O(e){return jE(U().removeHolesFromFace(e.wrapped))}function vO(e){let t=gO(e);return Array.from(XD(e.wrapped,`wire`)).map(e=>jE(j(QD(e)))).filter(e=>!U().isSame(e.wrapped,t.wrapped))}function yO(e,t){let n=qE(e),r=U(),i=new Map;for(let n of r.iterShapes(e.wrapped,`face`))i.set(r.hashCode(n,G),t),r.dispose(n);n.faceOrigins=i}function bO(e){return JE(e)?.faceOrigins}function xO(e,t,n){let r=new Map;for(let e of t){let t=bO(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=qE(n);e.faceOrigins=i}}var SO=100,CO=.985,wO=.1;function TO(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>SO)continue;let u=r-l/SO;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)<CO)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>wO)continue;let u=Math.max(0,i*i+a*a+c*c-l*l);u<o&&(o=u,s=n.origin)}return s}function EO(e,t){let n=new Map;for(let t of e){let e=bO(t);if(e)for(let[t,r]of e)n.set(t,r)}if(n.size===0)return;let r=U(),i=new Map,a=ZE(t),o=[];for(let e of a){let t=r.hashCode(e.wrapped,G),a=n.get(t);a===void 0?o.push(e):i.set(t,a)}if(o.length>0){let t=[];for(let n of e){let e=bO(n);if(e)for(let i of ZE(n)){let n=r.hashCode(i.wrapped,G),a=e.get(n);if(a!==void 0)try{let e=r.uvBounds(i.wrapped),n=r.surfaceNormal(i.wrapped,.5*(e.uMin+e.uMax),.5*(e.vMin+e.vMax)),o=r.surfaceCenterOfMass(i.wrapped),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=TO(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=qE(t);e.faceOrigins=i}}var DO=new WeakMap,OO=new WeakMap;function kO(e){return DO.has(e.wrapped)}function AO(e){let t=DO.get(e.wrapped);return t||(t=new Map,DO.set(e.wrapped,t)),t}function jO(e){let t=OO.get(e.wrapped);return t||(t=new Map,OO.set(e.wrapped,t)),t}function MO(e,t,n){let r=Array.isArray(t)?t:ZE(e).filter(t),i=AO(e),a=i.get(n)??new Set;for(let e of r)a.add(U().hashCode(e.wrapped,G));return i.set(n,a),e}function NO(e,t){let n=DO.get(e.wrapped);if(!n)return[];let r=n.get(t);if(!r||r.size===0)return[];let i=[];for(let t of ZE(e)){let e=U().hashCode(t.wrapped,G);r.has(e)&&i.push(t)}return i}function PO(e){let t=new Map,n=DO.get(e.wrapped);if(!n)return t;let r=ZE(e),i=new Map;for(let e of r)i.set(U().hashCode(e.wrapped,G),e);for(let[e,r]of n){let n=[];for(let e of r){let t=i.get(e);t&&n.push(t)}n.length>0&&t.set(e,n)}return t}function FO(e,t,n){return jO(e).set(t,n),e}function IO(e,t){return OO.get(e.wrapped)?.get(t)}function LO(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function RO(e,t,n){let r=AO(n);for(let i of t){let t=DO.get(i.wrapped);if(!t)continue;let a=new Map;for(let[e,n]of t)for(let t of n){let n=a.get(t)??[];n.push(e),a.set(t,n)}for(let[t,n]of a){if(e.deleted.has(t))continue;let i=e.modified.get(t),a=i&&i.length>0?i:[t];for(let e of a)for(let t of n)LO(r,t,e)}let o=OO.get(i.wrapped);if(o){let e=jO(n);for(let[t,n]of o)e.has(t)||e.set(t,n)}}}var zO=new WeakMap,BO=new WeakMap;function VO(e){return zO.has(e.wrapped)||BO.has(e.wrapped)}function HO(e){let t=BO.get(e.wrapped);return t||(t=new Map,BO.set(e.wrapped,t)),t}function UO(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 WO(e,t){return zO.set(e.wrapped,UO(t)),e}function GO(e,t,n){let r=UO(n),i=HO(e);for(let e of t)i.set(U().hashCode(e.wrapped,G),r);return e}function KO(e){return zO.get(e.wrapped)}function qO(e,t){let n=BO.get(e.wrapped);if(n)return n.get(U().hashCode(t.wrapped,G))}function JO(e,t,n){for(let e of t){let t=zO.get(e.wrapped);if(t){zO.set(n.wrapped,t);break}}let r=HO(n);for(let n of t){let t=BO.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 YO(e){return bO(e)!==void 0||kO(e)||VO(e)}function XO(e){if(!e.some(YO))return[];let t=U(),n=[];for(let r of e){let e=t.iterShapes(r.wrapped,`face`);for(let r of e)n.push(t.hashCode(r,G)),t.dispose(r)}return n}function ZO(e,t,n){xO(e,t,n),RO(e,t,n),JO(e,t,n)}function QO(e,t){EO(e,t)}function $O(e,t){let n=U(),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);ZO({modified:a,generated:new Map,deleted:new Set},[e],t)}function ek(e,t){let n=XO([e]),{shape:r,evolution:i}=U().translateWithHistory(e.wrapped,t[0],t[1],t[2],n,G),a=W(r);return ZO(i,[e],a),a}function tk(e,t,n=[0,0,0],r=[0,0,1]){let i=XO([e]),{shape:a,evolution:o}=U().rotateWithHistory(e.wrapped,t*gD,i,G,r,n),s=W(a);return ZO(o,[e],s),s}function nk(e,t=[0,1,0],n=[0,0,0]){let r=XO([e]),{shape:i,evolution:a}=U().mirrorWithHistory(e.wrapped,n,t,r,G),o=W(i);return ZO(a,[e],o),o}function rk(e,t,n=[0,0,0]){let r=XO([e]),{shape:i,evolution:a}=U().scaleWithHistory(e.wrapped,n,t,r,G),o=W(i);return ZO(a,[e],o),o}function ik(e,t,n){let r=U().boundingBox(e.wrapped),i=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]],a=n?.auto===!0;function o(e,t,n){return e!==void 0&&t>1e-12?e/t:e===void 0&&a?n:1}let s=1;a&&(t[0]!==void 0&&i[0]>1e-12?s=t[0]/i[0]:t[1]!==void 0&&i[1]>1e-12?s=t[1]/i[1]:t[2]!==void 0&&i[2]>1e-12&&(s=t[2]/i[2]));let c=[o(t[0],i[0],s),o(t[1],i[1],s),o(t[2],i[2],s)];return Math.abs(c[0]-c[1])<1e-6&&Math.abs(c[1]-c[2])<1e-6?O(rk(e,c[0])):k(F(N.VALIDATION_FAILED,`resize: non-uniform scaling is not supported (WASM build lacks BRepBuilderAPI_GTransform).`,void 0,void 0,`Use auto: true to scale proportionally, or set all three dimensions to achieve uniform scaling.`))}function ak(e){if(`linear`in e)return O({linear:e.linear,translation:e.translation});let[t,n,r,i]=e,a=1e-10;return Math.abs(i[0])>a||Math.abs(i[1])>a||Math.abs(i[2])>a||Math.abs(i[3]-1)>a?k(F(N.VALIDATION_FAILED,`applyMatrix: invalid bottom row [${String(i[0])}, ${String(i[1])}, ${String(i[2])}, ${String(i[3])}]. Must be [0, 0, 0, 1] for an affine transform.`)):O({linear:[t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]],translation:[t[3],n[3],r[3]]})}function ok(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 sk(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 ck(e,t){let n=ak(t);if(!n.ok)return n;let{linear:r,translation:i}=n.value,a=ok(r);if(Math.abs(a)<1e-12)return k(F(N.VALIDATION_FAILED,`applyMatrix: singular matrix (determinant ≈ 0). Cannot apply a non-invertible transform.`));if(sk(r)){let t=XO([e]),{shape:n,evolution:a}=U().generalTransformWithHistory(e.wrapped,r,i,!0,t,G),o=W(n);return ZO(a,[e],o),O(o)}let o=W(U().generalTransformNonOrthogonal(e.wrapped,r,i));return QO([e],o),O(o)}function lk(e){let t=e.map(e=>e.type===`translate`?{type:`translate`,x:e.v[0],y:e.v[1],z:e.v[2]}:{type:`rotate`,angle:e.angle,axis:e.axis,center:e.center}),{handle:n,dispose:r}=U().composeTransform(t);return{trsf:n,cleanup:r}}function uk(e,t){let{trsf:n,cleanup:r}=lk(`type`in t?[t]:t),i;try{i=W(U().locate(e.wrapped,n))}finally{r()}return YO(e)&&$O(e,i),i}function dk(e,t){let n=XO([e]),{shape:r,evolution:i}=U().applyComposedTransformWithHistory(e.wrapped,t.trsf,n,G),a=W(r);return ZO(i,[e],a),a}function fk(e){return BE(()=>U().copyShape(e.wrapped),N.CLONE_FAILED,`Failed to clone shape`)}function pk(e){return VE(()=>U().toBREP(e.wrapped),N.TO_BREP_FAILED,`Failed to serialize shape to BREP`)}function mk(e){return U().hashCode(e.wrapped,G)}function hk(e){return U().isNull(e.wrapped)}function gk(e,t){return U().isSame(e.wrapped,t.wrapped)}function _k(e,t){return U().isEqual(e.wrapped,t.wrapped)}function vk(e){return BE(()=>U().simplify(e.wrapped),N.SIMPLIFY_FAILED,`Failed to simplify shape`)}function yk(e){return U().curveType(e.wrapped)}function bk(e){let[t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function xk(e){let[,t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function Sk(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curvePointAtParam(e.wrapped,i)}function Ck(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curveTangent(e.wrapped,i).tangent}function wk(e){return U().length(e.wrapped)}function Tk(e){if(yk(e)!==`CIRCLE`)return null;let t=Sk(e,0),n=Sk(e,1/3),r=Sk(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 Ek(e){return U().curveIsClosed(e.wrapped)}function Dk(e){return U().curveIsPeriodic(e.wrapped)}function Ok(e){return U().curvePeriod(e.wrapped)}function kk(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function Ak(e){return W(U().reverseShape(e.wrapped))}function jk(e,t={}){if(e.length<2)return k(ho(`INTERPOLATE_MIN_POINTS`,`Interpolation requires at least 2 points`));try{let n=W(U().interpolatePoints(e,t));return CE(n)?O(n):(FE(n),k(ho(`INTERPOLATE_NOT_EDGE`,`Interpolation did not produce an edge`)))}catch(e){return k(ho(`INTERPOLATE_FAILED`,`Interpolation failed: ${e instanceof Error?e.message:String(e)}`))}}function Mk(e,t={}){if(e.length<2)return k(ho(`APPROXIMATE_MIN_POINTS`,`Approximation requires at least 2 points`));try{let n=W(U().approximatePoints(e,t));return CE(n)?O(n):(FE(n),k(ho(`APPROXIMATE_NOT_EDGE`,`Approximation did not produce an edge`)))}catch(e){return k(ho(`APPROXIMATE_FAILED`,`Approximation failed: ${e instanceof Error?e.message:String(e)}`))}}function Nk(e,t,n=`arc`){let r=W(U().offsetWire2D(e.wrapped,t,{arc:`arc`,intersection:`intersection`,tangent:`tangent`,chamfer:`intersection`}[n]));return wE(r)?O(r):(FE(r),k(ho(`OFFSET_NOT_WIRE`,`Offset did not produce a Wire`)))}function Pk(e,t,n,r=!1){return`${e}:${t}:${n}:${r}`}function Fk(e,t){return`edge:${e}:${t}`}var Ik=new WeakMap,Lk=new WeakMap;function Rk(e,t){let n=Ik.get(e);if(n)return n.get(t)}function zk(e,t,n){let r=Ik.get(e);r||(r=new Map,Ik.set(e,r)),r.set(t,n)}function Bk(e,t){let n=Lk.get(e);if(n)return n.get(t)}function Vk(e,t,n){let r=Lk.get(e);r||(r=new Map,Lk.set(e,r)),r.set(t,n)}function Hk(){Ik=new WeakMap,Lk=new WeakMap}function Uk(){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 Wk(e,t={}){let n=To(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,skipNormals:a=!1,includeUVs:o=!1,cache:s=!0,signal:c}=t;c?.throwIfAborted();let l=Pk(r,i,a,o);if(s){let t=Rk(e.wrapped,l);if(t)return t}let u=U().mesh(e.wrapped,{tolerance:r,angularTolerance:i,skipNormals:a,includeUVs:o,...c?{signal:c}:{}}),d=bO(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&&zk(e.wrapped,l,f),f}function Gk(e,t={}){let n=To(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,cache:a=!0}=t,o=Fk(r,i);if(a){let t=Bk(e.wrapped,o);if(t)return t}let s=U().meshEdges(e.wrapped,r,i),c={lines:s.lines,edgeGroups:s.edgeGroups.map(e=>({start:e.start,count:e.count,edgeId:e.edgeHash}))};return a&&Vk(e.wrapped,o,c),c}function Kk(e,t){return e instanceof Error&&e.message.startsWith(`${t} export failed`)?vo(`${t}_EXPORT_FAILED`,`Failed to write ${t} file`,e):e instanceof WebAssembly.RuntimeError?vo(`${t}_EXPORT_CRASHED`,`${t} export crashed the kernel (${e.message}); the shape likely contains geometry the ${t} writer cannot serialize`,e):vo(`${t}_FILE_READ_ERROR`,`Failed to read exported ${t} file`,e)}function qk(e){let t;try{t=eD(e)}catch{return``}if(t.length<=1)return``;let n=[];return t.forEach((e,t)=>{try{uD(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 Jk(e,t){try{return uD(e),null}catch(n){if(n instanceof TypeError)throw n;return vo(`${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${qk(e)}`,n)}}function Yk(e){let t=Jk(e,`STEP`);if(t)return k(t);try{let t=U().exportSTEP([e.wrapped]);return O(new Blob([t],{type:`application/STEP`}))}catch(e){return k(Kk(e,`STEP`))}}function Xk(e,t={}){let n=To(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,binary:a=!1}=t,o=Jk(e,`STL`);if(o)return k(o);try{U().hasTriangulation(e.wrapped)||U().meshShape(e.wrapped,r,i);let t=U().exportSTL(e.wrapped,a,r,i);return O(new Blob([t],{type:`application/sla`}))}catch(e){return k(Kk(e,`STL`))}}function Zk(e){try{let t=U().exportIGES([e.wrapped]);return O(new Blob([t],{type:`application/iges`}))}catch(e){return k(vo(`IGES_EXPORT_FAILED`,`Failed to write IGES file`,e))}}function Qk(e,t){let n=t?.coarseTolerance??.5,r=t?.fineTolerance??.05,i=t?.angularTolerance??.5;return{coarse:Wk(e,{tolerance:n,angularTolerance:i}),fine:Wk(e,{tolerance:r,angularTolerance:i*.2})}}function $k(e){let t=uD(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 eA(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)*$k(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 tA(e,t,n){return Math.min(e/t*n,1)}function nA(e,t={}){let n=t.angularTolerance??To().angularTolerance,r=t.cache??!0,i=eA(e,t),a=Math.min(...i);return i.map(i=>{let o=tA(i,a,n);return{tolerance:i,angularTolerance:o,mesh:Wk(e,{tolerance:i,angularTolerance:o,cache:r,...t.signal?{signal:t.signal}:{}})}})}function rA(){return new Promise(e=>{setTimeout(e,0)})}async function iA(e,t={}){let n=t.angularTolerance??To().angularTolerance,r=t.cache??!0,i=t.meshLevel??((e,n,i)=>Wk(e,{tolerance:n,angularTolerance:i,cache:r,...t.signal?{signal:t.signal}:{}})),a=eA(e,t),o=Math.min(...a),s=[];for(let[r,c]of a.entries()){if(t.signal?.aborted)break;let l=tA(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 rA()}return s}function aA(e,t,n){if(t<0||t>=e.length)throw Error(n??`Index ${t} out of bounds (length ${e.length})`);return e[t]}function oA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[0]}function sA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[e.length-1]}function cA(e){return Array.from(Array(e).keys())}function lA(e){return cA(Math.min(...e.map(e=>e.length))).map(t=>e.map(e=>e[t]))}function uA(e,t){return hE(U().makeLineEdge([...e],[...t]))}function dA(e,t=[0,0,0],n=[0,0,1]){return hE(U().makeCircleEdge([...t],[...n],e))}function fA(e,t,n=[0,0,0],r=[0,0,1],i){return t>e?k(F(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(hE(U().makeEllipseEdge([...n],[...r],e,t,i?[...i]:void 0)))}function pA(e,t,n,r=[0,0,0],i=[0,0,1],a=!1){return gE(U().makeHelixWire(e,t,n,[...r],[...i],a))}function mA(e,t,n){return hE(U().makeArcEdge([...e],[...t],[...n]))}function hA(e,t,n,r,i=[0,0,0],a=[0,0,1],o){return t>e?k(F(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(hE(U().makeEllipseArc([...i],[...a],e,t,n,r,o?[...o]:void 0)))}function gA(e,{tolerance:t=.001,smoothing:n=null,degMax:r=6,degMin:i=1}={}){try{let a=e.map(e=>[...e]);return O(hE(U().approximatePoints(a,{tolerance:t,degMin:i,degMax:r,smoothing:n})))}catch(e){return k(P(`BSPLINE_FAILED`,`B-spline approximation failed`,e))}}function _A(e,{periodic:t=!1,tolerance:n=1e-7}={}){try{let r=e.map(e=>[...e]);return O(hE(U().interpolatePoints(r,{periodic:t,tolerance:n})))}catch(e){return k(P(`BSPLINE_INTERP_FAILED`,`B-spline interpolation failed`,e))}}function vA(e){if(e.length<2)return k(F(`BEZIER_MIN_POINTS`,`Need at least 2 points for a Bezier curve, got ${e.length}`,void 0,{pointCount:e.length}));let t=e.map(e=>[...e]);return O(hE(U().makeBezierEdge(t)))}function yA(e,t,n){return hE(U().makeTangentArc([...e],[...t],[...n]))}function bA(e){try{return O(gE(U().makeWireFromMixed(e.map(e=>e.wrapped))))}catch(e){return k(P(`WIRE_BUILD_FAILED`,`Failed to build the wire: ${e instanceof Error?e.message:`unknown error`}`))}}function xA(e,t){try{let n=U().makeFace(e.wrapped,!0);if(t&&t.length>0){let e=TA(_E(n),t);return lE(e)?O(e):k(F(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}let r=_E(n);return lE(r)?O(r):k(F(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}catch(e){return k(P(`FACE_BUILD_FAILED`,`Failed to build the face. Your wire might be non planar.`,e))}}function SA(e){return xA(gO(e))}function CA(e,t){return _E(U().makeFaceOnSurface(e.wrapped,t.wrapped))}function wA(e){try{return Ha(eO(U().makeNonPlanarFace(e.wrapped)),e=>TE(e)?O(e):k(P(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`)))}catch(e){return k(P(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`,e))}}function TA(e,t){return _E(U().addHolesInFace(e.wrapped,t.map(e=>e.wrapped)))}function EA(e){try{var t=OT();if(e.length<3)return k(F(`POLYGON_MIN_POINTS`,`You need at least 3 points to make a polygon`));let n=[...e.slice(1),e[0]],r=t.u(new BT);return Ha(bA(lA([e,n]).map(([e,t])=>r.register(uA(e,t)))),e=>xA(r.register(e)))}catch(e){t.e=e}finally{t.d()}}function DA(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function OA(e,t,n,r,i){let a=jE(e);if(!kE(a)){let o=eE(a).toUpperCase();return NE(e,a),FE(a),k(ho(t,`${n}. Got ${o} instead.`,void 0,i?{diagnostics:i}:void 0,r))}return NE(e,a),O(a)}function kA(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=DA(e,`fuse: first operand`);if(A(c))return c;let l=DA(t,`fuse: second operand`);if(A(l))return l;if(!s)return OA(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);let u=XO([e,t]),{shape:d,evolution:f,diagnostics:p}=U().fuseWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(U().isNull(d))return U().dispose(d),console.warn(`brepjs: fuse history path produced null result; retrying without evolution tracking.`,p),OA(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);console.warn(`brepjs: fuse reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=OA(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&&ZO(f,[e,t],m.value),m}function AA(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;let c=DA(e,`cut: base`);if(A(c))return c;let l=DA(t,`cut: tool`);if(A(l))return l;if(!s)return OA(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);let u=XO([e,t]),{shape:d,evolution:f,diagnostics:p}=U().cutWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(U().isNull(d))return U().dispose(d),console.warn(`brepjs: cut history path produced null result; retrying without evolution tracking.`,p),OA(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);console.warn(`brepjs: cut reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=OA(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&&ZO(f,[e,t],m.value),m}function jA(e,t,{simplify:n=!1,signal:r,fuzzyValue:i,unsafe:a,trackEvolution:o=!0}={}){if(r?.aborted)throw r.reason;let s=DA(e,`intersect: first operand`);if(A(s))return s;let c=DA(t,`intersect: second operand`);if(A(c))return c;if(!o)return OA(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);let l=XO([e,t]),{shape:u,evolution:d,diagnostics:f}=U().intersectWithHistory(e.wrapped,t.wrapped,l,G,{simplify:n,fuzzyValue:i});if(f.hasErrors){if(U().isNull(u))return U().dispose(u),console.warn(`brepjs: intersect history path produced null result; retrying without evolution tracking.`,f),OA(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);console.warn(`brepjs: intersect reported OCCT warnings/errors but produced a shape. Continuing with result.`,f)}let p=OA(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&&ZO(d,[e,t],p.value),p}function MA(e,t,n,r,i,a,o,s){if(o?.aborted)throw o.reason;let c=n-t;if(c===1)return O(aA(e,t));if(c===2)return kA(aA(e,t),aA(e,t+1),{optimisation:r,simplify:!1,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}});let l=t+Math.ceil(c/2),u=MA(e,t,l,r,i,a,o,s);if(A(u))return u;let d=MA(e,l,n,r,i,a,o,s);return A(d)?d:kA(u.value,d.value,{optimisation:r,simplify:i,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}})}function NA(e,{optimisation:t=`none`,simplify:n=!1,strategy:r=`native`,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;if(e.length===0)return k(F(`FUSE_ALL_EMPTY`,`fuseAll requires at least one shape`));if(e.length===1)return O(oA(e));for(let t=0;t<e.length;t++){let n=DA(aA(e,t),`fuseAll: shape at index ${t}`);if(A(n))return n}if(r===`native`){let o=OA(U().fuseAll(e.map(e=>e.wrapped),{optimisation:t,simplify:n,strategy:r,fuzzyValue:a,...i?{signal:i}:{}}),`FUSE_ALL_NOT_3D`,`fuseAll did not produce a 3D shape`);return o.ok&&s&&QO(e,o.value),o}return MA(e,0,e.length,t,n,s,i,a)}function PA(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=DA(e,`cutAll: base`);if(A(c))return c;for(let e=0;e<t.length;e++){let n=DA(aA(t,e),`cutAll: tool at index ${e}`);if(A(n))return n}let l=[e,...t],u=OA(U().cutAll(e.wrapped,t.map(e=>e.wrapped),{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_ALL_NOT_3D`,`cutAll did not produce a 3D shape`);return u.ok&&s&&QO(l,u.value),u}function FA(e,t){let n=U(),r=wD(e.xDir,t),i=wD(e.yDir,t),a=wD(e.xDir,-t),o=wD(e.yDir,-t),s=e.origin,c=[...SD(SD(s,a),o)],l=[...SD(SD(s,r),o)],u=[...SD(SD(s,r),i)],d=[...SD(SD(s,a),i)],f=[n.makeLineEdge(c,l),n.makeLineEdge(l,u),n.makeLineEdge(u,d),n.makeLineEdge(d,c)],p=n.makeWire(f),m=n.makeFace(p,!0);for(let e of f)n.dispose(e);return n.dispose(p),m}function IA(e,t,{approximation:n=!0,planeSize:r=1e4}={}){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`section: shape is a null shape`));let i=FA(typeof t==`string`?j(HD(t)):t,r);try{return O(W(U().section(e.wrapped,i,n)))}catch(e){let n=e instanceof Error?e.message:String(e),r=typeof t==`string`?t:`custom`;return k(P(`SECTION_FAILED`,`Section with ${r} plane failed: ${n}`,e,{operation:`section`,plane:r},`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`))}finally{U().dispose(i)}}function LA(e){let t=U(),n=new Map,r=new Map;for(let i of e){let e=$E(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 RA(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 zA(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=RA(i,t,n);for(;o;)e===0?r.push(o.edge):r.unshift(o.edge),i=o.nextTip,o=RA(i,t,n)}return r}function BA(e){let t=U(),n=LA(e),r=new Set,i=[];for(let a of e){if(r.has(a))continue;let e=zA(a,n,r);try{let n=t.makeWire(e.map(e=>e.wrapped));i.push(W(n))}catch{}}return i}function VA(e){let t=U(),n=0,r=-1;for(let i=0;i<e.length;i++){let a=e[i];if(!a)continue;let o=t.boundingBox(a.wrapped),s=o.max[0]-o.min[0],c=o.max[1]-o.min[1],l=o.max[2]-o.min[2],u=s*s+c*c+l*l;u>r&&(r=u,n=i)}return n}function HA(e,t,n={}){let r=IA(e,t,n);if(!r.ok)return r;let i=QE(r.value);if(i.length===0){let e=XE(r.value);if(e.length===0)return k(P(`SECTION_FAILED`,`sectionToFace: section produced no geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));i.push(...BA(e))}if(i.length===0)return k(P(`SECTION_FAILED`,`sectionToFace: section produced no usable geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));let a=VA(i),o=aA(i,a),s=i.filter((e,t)=>t!==a);return xA(o,s.length>0?s:void 0)}function UA(e,t){if(t.length===0)return O(e);if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`split: shape is a null shape`));for(let e=0;e<t.length;e++)if(U().isNull(aA(t,e).wrapped))return k(F(N.NULL_SHAPE_INPUT,`splitShape: tool at index ${e} is a null shape`));try{return O(W(U().split(e.wrapped,t.map(e=>e.wrapped))))}catch(e){let n=e instanceof Error?e.message:String(e);return k(P(`SPLIT_FAILED`,`Split operation failed on ${t.length} tool(s): ${n}`,e,{operation:`split`,toolCount:t.length},`The splitting tools may not intersect the shape. Ensure tools cross through the shape's interior.`))}}function WA(e,t,n={}){let r=[];for(let i of t){let t=IA(e,i,n);if(A(t))return t;r.push(t.value)}return O(r)}function GA(e,t,n){if(t.length===0)return O(e);let r=n?.optimisation===`commonFace`?1:n?.optimisation===`sameFace`?2:0,i=U(),a=t.map(e=>({op:e.op,tool:e.tool.wrapped}));try{let o=i.booleanPipeline?.(e.wrapped,a,{glueMode:r});if(o===void 0)return KA(e,t,n);if(o===null)return k(P(`BOOLEAN_PIPELINE_FAILED`,`Boolean pipeline returned null shape`));let s=W(o);return kE(s)?O(s):(FE(s),k(ho(`BOOLEAN_PIPELINE_NOT_3D`,`Pipeline result is not a 3D shape`)))}catch(e){return k(P(`BOOLEAN_PIPELINE_FAILED`,e instanceof Error?e.message:String(e)))}}function KA(e,t,n){let r=e,i={...n?.optimisation?{optimisation:n.optimisation}:{},unsafe:!0};for(let e of t){let t=e.op===`fuse`?kA(r,e.tool,i):e.op===`cut`?AA(r,e.tool,i):jA(r,e.tool,i);if(A(t))return t;r=j(t)}return O(r)}function qA(e){return W(U().sew(e.map(e=>e.wrapped)))}function JA(e,t=!1){let n=qA(e);return!t&&!EE(n)?k(ho(`WELD_NOT_SHELL`,`Could not make a shell from faces and shells`)):O(n)}function YA(e,t,n=[0,0,0],r=[0,0,1]){return yE(U().makeCylinder(e,t,[...n],[...r]))}function XA(e){return yE(U().makeSphere(e))}function ZA(e,t,n,r=[0,0,0],i=[0,0,1]){return yE(U().makeCone(e,t,n,[...r],[...i]))}function QA(e,t,n=[0,0,0],r=[0,0,1]){return yE(U().makeTorus(e,t,[...n],[...r]))}function $A(e,t,n){return yE(U().makeEllipsoid(e,t,n))}function ej(e){return mE(U().makeVertex(e[0],e[1],e[2]))}function tj(e,t,n=1e-6){return Ha(QD(U().offset(e.wrapped,t,n)),e=>Ha(eO(e),e=>kE(e)?O(e):k(ho(`OFFSET_NOT_3D`,`Could not offset to a 3d shape`))))}function nj(e){return xE(U().makeCompound(e.map(e=>e.wrapped)))}function rj(e){try{var t=OT();let n=t.u(qA(e)),r=W(U().solidFromShell(n.wrapped));return DE(r)?O(r):(FE(r),k(ho(`SOLID_BUILD_FAILED`,`Could not make a solid of faces and shells`)))}catch(e){t.e=e}finally{t.d()}}function ij(e){return{position:e.vertices,normal:e.normals,index:e.triangles}}function aj(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 oj(e){return{position:e.lines}}function sj(e,t){return{coarse:ij(e.coarse),fine:ij(e.fine),coarseDistance:t?.coarse??50,fineDistance:t?.fine??0}}function cj(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:ij(e.mesh),distance:r?.[t]??(i-t)*n}))}function lj(e,t,n,r){if(t.length===0)return k(F(`CHAMFER_ANGLE_NO_EDGES`,`chamferDistAngle requires at least one edge`,void 0,{edgeCount:0}));if(n<=0)return k(F(`CHAMFER_ANGLE_BAD_DISTANCE`,`distance must be positive, got ${n}`,void 0,{distance:n}));if(r<=0||r>=90)return k(F(`CHAMFER_ANGLE_BAD_ANGLE`,`angleDeg must be in range (0, 90), got ${r}`,void 0,{angleDeg:r}));let i;try{let a=U(),o=t.map(e=>e.wrapped);i=a.chamferDistAngle(e.wrapped,o,n,r)}catch(e){return k(P(`CHAMFER_ANGLE_FAILED`,`chamferDistAngle kernel call failed: ${e instanceof Error?e.message:String(e)}`,e,{distance:n,angleDeg:r,edgeCount:t.length}))}let a=QD(i);if(A(a))return U().dispose(i),a;let o=W(a.value);return NE(i,o),kE(o)?O(o):(FE(o),k(ho(`CHAMFER_ANGLE_NOT_3D`,`chamferDistAngle did not produce a 3D shape`)))}function uj(e){let t=U();return t.getNurbsCurveData?t.getNurbsCurveData(e.wrapped):null}function dj(e){let t=U();return t.getNurbsSurfaceData?t.getNurbsSurfaceData(e.wrapped):null}var fj={cut:AA,cutAll:PA,fuse:kA,fuseAll:NA};function pj(e){return{totalInputs:e.totalInputs,batchAttempts:e.batchAttempts,batchSucceeded:e.batchSucceeded,singletonFallbacks:e.singletonFallbacks,failedInputs:[...e.failedInputs].sort((e,t)=>e-t)}}function mj(e,t,n={}){return hj(fj,e,t,n)}function hj(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=gj(e,t,n,0,r,i);return A(a)?a:O({shape:a.value,telemetry:pj(i)})}function gj(e,t,n,r,i,a){if(n.length===0)return O(t);if(n.length===1)return _j(e,t,n,r,i,a);a.batchAttempts++;let o=Sj(()=>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=gj(e,t,n.slice(0,s),r,i,a);return c.ok?gj(e,c.value,n.slice(s),r+s,i,a):c}function _j(e,t,n,r,i,a){a.singletonFallbacks++;let o=oA(n),s=Sj(()=>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 vj(e,t={}){return yj(fj,e,t)}function yj(e,t,n={}){if(n.signal?.aborted)throw n.signal.reason;if(t.length===0)return k(F(N.FUSE_ALL_EMPTY,`fuseAllBisect requires at least one shape`));let r={totalInputs:t.length,batchAttempts:0,batchSucceeded:0,singletonFallbacks:0,failedInputs:new Set},i=bj(e,t,0,n,r);return A(i)?i:O({shape:i.value,telemetry:pj(r)})}function bj(e,t,n,r,i){if(t.length===1)return O(oA(t));i.batchAttempts++;let a=Sj(()=>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 xj(e,bj(e,t.slice(0,o),n,r,i),bj(e,t.slice(o),n+o,r,i),t,n,o,r,i)}function xj(e,t,n,r,i,a,o,s){if(t.ok&&n.ok){s.singletonFallbacks++;let c=Sj(()=>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 Sj(e){try{return e()}catch{return null}}function Cj(e,t,n){return U().checkBoolean(e.wrapped,t.wrapped,n)}function wj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Tj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Ej(e,t,n,r){let i=jE(e);if(!kE(i)){let a=eE(i).toUpperCase();return NE(e,i),FE(i),k(ho(t,`${n}. Got ${a} instead.`,void 0,void 0,r))}return NE(e,i),O(i)}function Dj(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>r.get(U().hashCode(e,2147483647))??1}}function Oj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=wj(e,`fuseWithEvolution: first operand`);if(A(o))return o;let s=wj(t,`fuseWithEvolution: second operand`);if(A(s))return s;let c=XO([e,t]),{shape:l,evolution:u}=U().fuseWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Ej(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?(ZO(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function kj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=wj(e,`cutWithEvolution: base`);if(A(o))return o;let s=wj(t,`cutWithEvolution: tool`);if(A(s))return s;let c=XO([e,t]),{shape:l,evolution:u}=U().cutWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Ej(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?(ZO(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function Aj(e,t,{simplify:n=!1,signal:r,fuzzyValue:i}={}){if(r?.aborted)throw r.reason;let a=wj(e,`intersectWithEvolution: first operand`);if(A(a))return a;let o=wj(t,`intersectWithEvolution: second operand`);if(A(o))return o;let s=XO([e,t]),{shape:c,evolution:l}=U().intersectWithHistory(e.wrapped,t.wrapped,s,G,{simplify:n,fuzzyValue:i}),u=Ej(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?(ZO(l,[e,t],u.value),O({shape:u.value,evolution:l})):u}function jj(e,t,n){let r=Tj(e,`filletWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(F(`INVALID_FILLET_RADIUS`,`Fillet radius must be positive`,void 0,void 0,`Provide a positive radius value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(F(`INVALID_FILLET_RADIUS`,`Fillet radii must both be positive`,void 0,void 0,`Both radius values must be greater than 0`));let i=t??XE(e);if(i.length===0)return k(F(N.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));try{let t,r;if(typeof n==`function`){let e=Dj(i,n);if(!e)return k(F(N.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=XO([e]),{shape:o,evolution:s}=U().filletWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return kE(c)?(ZO(s,[e],c),O({shape:c,evolution:s})):(FE(c),k(P(N.FILLET_NOT_3D,`Fillet result is not a 3D shape`)))}catch(e){return k(P(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:i.length,radius:n}))}}function Mj(e,t,n){let r=Tj(e,`chamferWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(F(`INVALID_CHAMFER_DISTANCE`,`Chamfer distance must be positive`,void 0,void 0,`Provide a positive distance value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(F(`INVALID_CHAMFER_DISTANCE`,`Chamfer distances must both be positive`,void 0,void 0,`Both distance values must be greater than 0`));let i=t??XE(e);if(i.length===0)return k(F(N.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=Dj(i,n);if(!e)return k(F(N.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=XO([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return kE(c)?(ZO(s,[e],c),O({shape:c,evolution:s})):(FE(c),k(P(N.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)))}catch(e){return k(P(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:i.length,distance:n}))}}function Nj(e,t,n,r=.001){let i=Tj(e,`shellWithEvolution: shape`);if(A(i))return i;if(n<=0)return k(F(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(F(`NO_FACES`,`At least one face must be specified for shell`));try{let i=XO([e]),{shape:a,evolution:o}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,i,G,r),s=W(a);return kE(s)?(ZO(o,[e],s),O({shape:s,evolution:o})):(FE(s),k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}catch(e){return k(P(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function Pj(e,t,n){try{let r=W(U().positionOnCurve(e.wrapped,t.wrapped,n));return kE(r)?O(r):(FE(r),k(P(N.POSITION_ON_CURVE_FAILED,`positionOnCurve did not produce a 3D shape`)))}catch(e){return k(P(N.POSITION_ON_CURVE_FAILED,`Failed to position shape on curve at param ${n}`,e))}}function Fj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Ij(e,t){if(typeof e==`number`&&e<=0)return k(F(t.code,t.scalar,void 0,void 0,t.scalarHint));if(Array.isArray(e)&&(e[0]<=0||e[1]<=0))return k(F(t.code,t.pair,void 0,void 0,t.pairHint))}function Lj(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>{let t=r.get(U().hashCode(e,G));if(t===void 0)throw Error(`fillet/chamfer: edge hash not found — possible hash collision`);return t}}}function Rj(e,t,n,r,i){let a=W(t);return kE(a)?(ZO(e,n,a),O(a)):(FE(a),k(P(r,i)))}function zj(e,t){if(typeof t!=`function`)return{filteredFaces:[...e],kernelAngle:t};let n=[],r=new Map;for(let i of e){let e=t(i);e===null||e===0||Math.abs(e)>=90||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return{filteredFaces:n,kernelAngle:e=>{let t=r.get(U().hashCode(e,G));if(t===void 0)throw Error(`draft: face hash not found — possible hash collision`);return t}}}function Bj(e,t){let n=Fj(e,`thicken: shape`);if(A(n))return n;try{let n=XO([e]),{shape:r,evolution:i}=U().thickenWithHistory(e.wrapped,t,n,G),a=W(r);return ZO(i,[e],a),O(a)}catch(e){return k(P(`THICKEN_FAILED`,`Thicken operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function Vj(e,t,n){let r=Fj(e,`fillet: shape`);if(A(r))return r;let i=Ij(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??XE(e);if(a.length===0)return k(F(N.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));if(typeof n==`function`){let e=Lj(a,n);return e?O({filteredEdges:e.edges,kernelRadius:e.kernelParam,selectedCount:a.length}):k(F(N.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`))}return O({filteredEdges:[...a],kernelRadius:n,selectedCount:a.length})}function Hj(e,t,n,{trackEvolution:r=!0}={}){let i=Vj(e,t,n);if(A(i))return i;let{filteredEdges:a,kernelRadius:o,selectedCount:s}=i.value;try{let t=a.map(e=>e.wrapped);if(!r){let n=W(U().fillet(e.wrapped,t,o));return kE(n)?O(n):k(P(N.FILLET_NOT_3D,`Fillet result is not a 3D shape`))}let n=XO([e]),{shape:i,evolution:s}=U().filletWithHistory(e.wrapped,t,o,n,G);return Rj(s,i,[e],N.FILLET_NOT_3D,`Fillet result is not a 3D shape`)}catch(e){return k(P(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:s,radius:n}))}}function Uj(e,t,n){let r=Fj(e,`chamfer: shape`);if(A(r))return r;let i=Ij(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??XE(e);if(a.length===0)return k(F(N.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=Lj(a,n);if(!e)return k(F(N.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...a],r=n;let i=XO([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,i,G);return Rj(s,o,[e],N.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)}catch(e){return k(P(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:a.length,distance:n}))}}function Wj(e,t,n,r=.001,{trackEvolution:i=!0}={}){let a=Fj(e,`shell: shape`);if(A(a))return a;if(n<=0)return k(F(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(F(`NO_FACES`,`At least one face must be specified for shell`));try{if(!i){let i=W(U().shell(e.wrapped,t.map(e=>e.wrapped),n,r));return kE(i)?O(i):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}let a=XO([e]),{shape:o,evolution:s}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,a,G,r),c=W(o);return kE(c)?(ZO(s,[e],c),O(c)):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}catch(e){return k(P(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function Gj(e,t,n=1e-6){let r=Fj(e,`offset: shape`);if(A(r))return r;if(Math.abs(t)<1e-10)return k(F(`ZERO_OFFSET`,`Offset distance cannot be zero`));try{let r=XO([e]),{shape:i,evolution:a}=U().offsetWithHistory(e.wrapped,t,r,G,n),o=W(i);return kE(o)?(ZO(a,[e],o),O(o)):k(P(`OFFSET_RESULT_NOT_3D`,`Offset result is not a 3D shape`))}catch(e){return k(P(`OFFSET_FAILED`,`Offset operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function Kj(e,t,n){let r=Fj(e,`draft: shape`);if(A(r))return r;if(typeof n==`number`){if(Math.abs(n)<1e-10)return k(F(N.DRAFT_INVALID_ANGLE,`Draft angle cannot be zero`,void 0,void 0,`Provide a non-zero angle in degrees`));if(Math.abs(n)>=90)return k(F(N.DRAFT_INVALID_ANGLE,`Draft angle must be between -90 and 90 degrees (exclusive)`,void 0,void 0,`Typical draft angles are 1-5 degrees for injection molding`))}if(t.length===0)return k(F(N.DRAFT_NO_FACES,`No faces specified for draft`,void 0,void 0,`Select at least one face to apply the draft angle to`))}function qj(e,t,n,r,i){let a=Kj(e,t,i);if(a)return a;try{let{filteredFaces:a,kernelAngle:o}=zj(t,i);if(a.length===0)return k(F(N.DRAFT_NO_FACES,`No faces with valid draft angle`,void 0,void 0,`Check that the angle callback returns non-zero values between -90 and 90 degrees`));let s=XO([e]),{shape:c,evolution:l}=U().draftWithHistory(e.wrapped,a.map(e=>e.wrapped),[n[0],n[1],n[2]],[r[0],r[1],r[2]],o,s,G);return Rj(l,c,[e],N.DRAFT_NOT_3D,`Draft result is not a 3D shape`)}catch(e){let n=e instanceof Error?e.message:String(e);return k(P(N.DRAFT_FAILED,`Draft operation failed: ${n}`,e,{operation:`draft`,faceCount:t.length,angle:i}))}}function Jj(e,t,n){if(n.length===0)return k(F(N.VARIABLE_FILLET_FAILED,`radii must contain at least one radius spec`));for(let e of n)if(e.radius<=0)return k(F(N.VARIABLE_FILLET_FAILED,`All radius values must be positive`));let r=U();try{let i=JSON.stringify({edge:r.hashCode(t.wrapped,G),radii:n.map(e=>({param:e.param,radius:e.radius}))}),a=W(r.filletVariable(e.wrapped,i));return kE(a)?DE(a)?O(a):(FE(a),k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a solid`))):(FE(a),k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a 3D shape`)))}catch(e){return k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet failed`,e))}}function Yj(e){return pD(e)}function Xj(e){if(!DE(e))return k(F(`NOT_A_SOLID`,`Input shape is not a solid`));let t=Yj(e);try{let n=U().healSolid(e.wrapped);if(!n)return t?O(e):k(P(N.HEAL_NO_EFFECT,`Solid healing had no effect — shape is still invalid`));let r=W(n);return DE(r)?(YE(r),Yj(r)?O(r):(FE(r),k(P(`HEAL_SOLID_INCOMPLETE`,`Healed result is still invalid after ShapeFix_Solid`)))):(FE(r),k(P(`HEAL_RESULT_NOT_SOLID`,`Healed result is not a solid`)))}catch(e){return k(P(`HEAL_SOLID_FAILED`,`Solid healing failed`,e))}}function Zj(e){if(!TE(e))return k(F(`NOT_A_FACE`,`Input shape is not a face`));try{let t=W(U().healFace(e.wrapped));return TE(t)?O(t):(FE(t),k(P(`HEAL_RESULT_NOT_FACE`,`Healed result is not a face`)))}catch(e){return k(P(`HEAL_FACE_FAILED`,`Face healing failed`,e))}}function Qj(e,t){if(!wE(e))return k(F(`NOT_A_WIRE`,`Input shape is not a wire`));try{let n=W(U().healWire(e.wrapped,t?.wrapped));return wE(n)?O(n):(FE(n),k(P(`HEAL_RESULT_NOT_WIRE`,`Healed result is not a wire`)))}catch(e){return k(P(`HEAL_WIRE_FAILED`,`Wire healing failed`,e))}}function $j(e){return DE(e)?Xj(e):TE(e)?Zj(e):wE(e)?Qj(e):O(e)}function eM(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(Yj(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=QE(e).length,u=ZE(e).length,d=e,f=!1,p=t=>{let n=d;d=t,n!==e&&n.wrapped!==t.wrapped&&FE(n)};if(o!==void 0)try{p(W(U().sew([d.wrapped],o))),s.push(`Applied sewing with tolerance ${o}`),c.push({name:`sew`,attempted:!0,succeeded:!0,detail:`tolerance=${o}`})}catch(e){let t=e instanceof Error?e.message:String(e);s.push(`Sewing failed: ${t}`),c.push({name:`sew`,attempted:!0,succeeded:!1,detail:t})}if(a&&n){let e=QE(d),t=0;for(let n of e)try{U().fixSelfIntersection(n.wrapped),t++}catch{}s.push(`Self-intersection fix: ${t}/${e.length} wires`),c.push({name:`fixSelfIntersection`,attempted:!0,succeeded:t>0,detail:`${t}/${e.length} wires fixed`})}if(DE(d)&&i||TE(d)&&r||wE(d)&&n){let t=$j(d);za(t)?(p(t.value),DE(e)?(f=!0,s.push(`Applied ShapeFix_Solid`),c.push({name:`healSolid`,attempted:!0,succeeded:!0})):TE(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=QE(d).length,h=ZE(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=Yj(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 tM(e){try{return O(W(U().fixShape(e.wrapped)))}catch(e){return k(P(N.FIX_SHAPE_FAILED,`ShapeFix_Shape failed`,e))}}function nM(e){try{let t=W(U().solidFromShell(e.wrapped));return DE(t)?Yj(t)?O(t):(FE(t),k(P(N.SOLID_FROM_SHELL_FAILED,`solidFromShell produced an invalid solid`))):(FE(t),k(P(N.SOLID_FROM_SHELL_FAILED,`solidFromShell did not produce a solid`)))}catch(e){return k(P(N.SOLID_FROM_SHELL_FAILED,`Failed to create solid from shell`,e))}}function rM(e){try{let t=W(U().fixSelfIntersection(e.wrapped));return wE(t)?O(t):(FE(t),k(P(N.FIX_SELF_INTERSECTION_FAILED,`Result is not a wire`)))}catch(e){return k(P(N.FIX_SELF_INTERSECTION_FAILED,`Failed to fix wire self-intersection`,e))}}function iM(e,{profile:t,endFactor:n=1}){return e<1e-10?k(F(`INVALID_EXTRUSION_LENGTH`,`Extrusion length too small (< 1e-10)`)):t!==`s-curve`&&t!==`linear`?k(F(`UNSUPPORTED_PROFILE`,`Unsupported extrusion profile: ${String(t)}`)):O(U().buildExtrusionLaw(t,e,n).Trim(0,e,1e-6))}function aM(e,t){let n=U(),r=n.makeLineEdge([...e],[...t]),i=n.makeWire([r]);return n.dispose(r),W(i)}function oM(e,t,n,r,i,a=!1){return W(U().makeHelixWire(e,t,n,[...r],[...i],a))}function sM(e){let t=W(e.shape),n=W(e.firstShape),r=W(e.lastShape),i=()=>{FE(t),FE(n),FE(r)};return kE(t)?wE(n)?wE(r)?O([t,n,r]):(i(),k(ho(`SWEEP_END_NOT_WIRE`,`Sweep did not produce an end Wire`))):(i(),k(ho(`SWEEP_START_NOT_WIRE`,`Sweep did not produce a start Wire`))):(i(),k(ho(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function cM(e,t,n={},r=!1){if(n.mode===`simple`&&!r){let n=W(U().simplePipe(e.wrapped,t.wrapped));return kE(n)?O(n):(FE(n),k(ho(`SWEEP_NOT_3D`,`Simple pipe did not produce a 3D shape`)))}let{frenet:i=!1,auxiliarySpine:a,law:o=null,transitionMode:s=`right`,withContact:c,support:l,forceProfileSpineOthogonality:u,tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h}=n,g=U(),_=s===`round`?!0:!!u,v=g.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:s,contact:!!c,correction:_,frenet:i,shellMode:r,...a?.wrapped?{auxiliary:a.wrapped}:{},...o===null?{}:{law:o},...l===null?{}:{support:l},tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h});if(r&&typeof v==`object`&&`firstShape`in v)return sM(v);let y=W(v);return kE(y)?O(y):(FE(y),k(ho(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function lM(e,t,n,r){return cM(e,aM(t,SD(t,n)),{support:r})}function uM(e,t,n,r,i=!1){try{var a=OT();let o=OD(n);if(o<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let s=SD(t,n),c=a.u(aM(t,s)),l=null;if(r){let e=iM(o,r);if(A(e))return e;l=e.value}return cM(e,c,{law:l},i)}catch(e){a.e=e}finally{a.d()}}function dM(e,t,n,r,i,a=!1){try{var o=OT();if(Math.abs(t)<1e-10)return k(F(`ZERO_TWIST_ANGLE`,`Twist angle cannot be zero`));let s=OD(r);if(s<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let c=SD(n,r),l=o.u(aM(n,c)),u=t<0,d=360/Math.abs(t)*s,f=o.u(oM(d,s,1,n,r,u)),p=null;if(i){let e=iM(s,i);if(A(e))return e;p=e.value}return cM(e,l,{auxiliarySpine:f,law:p},a)}catch(e){o.e=e}finally{o.d()}}function fM(e){let t=e.map(e=>e.location);for(let e=0;e<t.length;e++){let n=t[e];if(n!==void 0&&(n<0||n>1))return F(N.MULTI_SWEEP_FAILED,`Section ${e} location ${n} is out of range [0, 1]`)}let n=t.filter(e=>e!==void 0);for(let e=1;e<n.length;e++)if((n[e]??0)<=(n[e-1]??0))return F(N.MULTI_SWEEP_FAILED,`Section locations must be strictly increasing`)}function pM(e,t,n){let[r,i]=n.curveParameters(t.wrapped),a=i-r,o=Array(e.length);for(let t=0;t<e.length;t++){let n=e[t]?.location;o[t]=n===void 0?NaN:r+n*a}let s=-1,c=r;for(let t=0;t<=e.length;t++){let n=t===e.length;if(!n&&!Number.isNaN(o[t]??NaN)||n){let e=n?i:o[t]??i,a=t-s-1;for(let t=1;t<=a;t++)o[s+t]=c+t/(a+1)*(e-c);n||(s=t,c=o[t]??r)}}for(let e=1;e<o.length;e++)if((o[e]??0)<=(o[e-1]??0))return k(F(N.MULTI_SWEEP_FAILED,`Computed section parameters are not strictly increasing at index ${e} (${o[e-1]?.toFixed(4)} >= ${o[e]?.toFixed(4)})`));return O(o)}function mM(e,t,n){if(e.length<2)return k(F(N.MULTI_SWEEP_INSUFFICIENT_SECTIONS,`Multi-section sweep requires at least 2 sections, got ${e.length}`));let{solid:r=!0,ruled:i=!1,tolerance:a=1e-6}=n??{},o=fM(e);if(o)return k(o);try{let n=U(),o=pM(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=W(n.loftAdvanced(l,{solid:r,ruled:i,tolerance:a}));return kE(o)?O(o):(FE(o),k(ho(`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(P(N.MULTI_SWEEP_FAILED,`Multi-section sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function hM(e,t,n,r={}){let{transition:i=`transformed`,solid:a=!0,tolerance:o}=r;try{let r=U(),s=!a,c=n.length>0?n[0]?.wrapped:void 0,l=r.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:i,...c?{auxiliary:c}:{},shellMode:s,...o===void 0?{}:{tolerance:o,boundTolerance:o}}),u=W(typeof l==`object`&&`shape`in l?l.shape:l);return kE(u)?O(u):(FE(u),k(ho(`GUIDED_SWEEP_NOT_3D`,`Guided sweep did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.GUIDED_SWEEP_FAILED,`Guided sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function gM(e,t){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`extrude: face is a null shape`));if(OD(t)<1e-10)return k(F(`EXTRUDE_ZERO_VECTOR`,`extrude: extrusion vector has zero length`));try{let n=U(),r=OD(t),i=jD(t),a=n.extrude(e.wrapped,[...i],r),o=yE(n.downcast(a,`solid`));return NE(a,o),O(o)}catch(e){return k(P(`EXTRUDE_FAILED`,`Extrusion operation failed`,e,{operation:`extrude`,vectorLength:OD(t)}))}}function _M(e,t=[0,0,0],n=[0,0,1],r=2*Math.PI){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`revolve: face is a null shape`));try{let i=W(U().revolveVec(e.wrapped,[...t],[...n],r));return kE(i)?O(i):(FE(i),k(ho(`REVOLUTION_NOT_3D`,`Revolution did not produce a 3D shape`)))}catch(e){return k(P(`REVOLVE_FAILED`,`Revolution operation failed`,e,{operation:`revolve`,angle:r}))}}function vM(e){if(e.length===0)return O([]);let t=U(),n=[];for(let t=0;t<e.length;t++){let r=e[t];if(!r)continue;let i=typeof r.height==`number`?[0,0,r.height]:r.height,a=OD(i);if(a<1e-10)return k(F(`EXTRUDE_ALL_ZERO_VECTOR`,`extrudeAll: entry ${t} has zero-length extrusion vector`));let o=[...jD(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=yE(t.downcast(e,`solid`));return NE(e,n),n}))}catch(e){return k(P(`EXTRUDE_ALL_FAILED`,`Batch extrusion operation failed`,e))}}function yM(e,{ruled:t=!0,startPoint:n,endPoint:r,tolerance:i=1e-6}={},a=!1){if(e.length===0&&!n&&!r)return k(F(`LOFT_EMPTY`,`Loft requires at least one wire or start/end point`));let o=U(),s=n?o.makeVertex(...vD(n)):void 0,c=r?o.makeVertex(...vD(r)):void 0;try{let n=W(o.loftAdvanced(e.map(e=>e.wrapped),{solid:!a,ruled:t,tolerance:i,...s?{startVertex:s}:{},...c?{endVertex:c}:{}}));return kE(n)?O(n):(FE(n),k(ho(`LOFT_NOT_3D`,`Loft did not produce a 3D shape`)))}catch(e){return k(P(`LOFT_FAILED`,`Loft operation failed`,e,void 0,`Common causes: wire profiles with different edge counts, self-intersecting result, or profiles too far apart. Ensure profiles are compatible and ordered.`))}}function bM(e){if(e.length===0)return O([]);let t=U(),n=[],r=e.map(e=>{let r=e.startPoint?t.makeVertex(...vD(e.startPoint)):void 0,i=e.endPoint?t.makeVertex(...vD(e.endPoint)):void 0;return r&&n.push(r),i&&n.push(i),{wires:e.wires.map(e=>e.wrapped),solid:!0,ruled:e.ruled??!0,tolerance:e.tolerance??1e-6,startVertex:r,endVertex:i}});try{let e=t.loftBatch?.(r)??r.map(e=>t.loftAdvanced(e.wires,{solid:e.solid,ruled:e.ruled,tolerance:e.tolerance,startVertex:e.startVertex,endVertex:e.endVertex})),n=[];for(let t of e){let e=W(t);if(!kE(e))return FE(e),k(ho(`LOFT_ALL_NOT_3D`,`Batch loft entry did not produce a 3D shape`));n.push(e)}return O(n)}catch(e){return k(P(`LOFT_ALL_FAILED`,`Batch loft operation failed`,e))}finally{for(let e of n)t.dispose(e)}}var xM=new WeakMap;function SM(e,t){return xM.get(e)?.get(t)}function CM(e,t,n){let r=xM.get(e);r||(r=new Map,xM.set(e,r)),r.set(t,n)}function wM(e){return U().isNull(e.wrapped)}function TM(e){return k(F(N.NULL_SHAPE_INPUT,`${e}: shape is a null shape`))}function EM(e){let t=SM(e.wrapped,`volume`);if(t)return O(t);if(wM(e))return TM(`measureVolumeProps`);let n=U(),r=n.shapeType(e.wrapped);if(r!==`solid`&&r!==`compsolid`&&r!==`compound`){let t={mass:0,volume:0,centerOfMass:[0,0,0]};return CM(e.wrapped,`volume`,t),O(t)}let i=n.volume(e.wrapped),a=VE(()=>n.centerOfMass(e.wrapped),N.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!a.ok)return a;let o={mass:i,volume:i,centerOfMass:a.value};return CM(e.wrapped,`volume`,o),O(o)}function DM(e){let t=SM(e.wrapped,`surface`);if(t)return O(t);if(wM(e))return TM(`measureSurfaceProps`);let n=U(),r=n.area(e.wrapped),i=VE(()=>n.centerOfMass(e.wrapped),N.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!i.ok)return i;let a={mass:r,area:r,centerOfMass:i.value};return CM(e.wrapped,`surface`,a),O(a)}function OM(e){let t=SM(e.wrapped,`linear`);if(t)return O(t);if(wM(e))return TM(`measureLinearProps`);let n=U(),r=n.length(e.wrapped),i={mass:r,length:r,centerOfMass:n.linearCenterOfMass(e.wrapped)};return CM(e.wrapped,`linear`,i),O(i)}function kM(e){let t=EM(e);return t.ok?O(t.value.mass):t}function AM(e){let t=DM(e);return t.ok?O(t.value.mass):t}function jM(e){let t=OM(e);return t.ok?O(t.value.mass):t}function MM(e,t){return wM(e)||wM(t)?TM(`measureDistance`):O(U().distance(e.wrapped,t.wrapped).value)}function NM(e,t){if(wM(e)||wM(t))return TM(`measureDistanceProps`);let n=U().distance(e.wrapped,t.wrapped);return O({distance:n.value,point1:n.point1,point2:n.point2})}function PM(e){if(wM(e))return TM(`createDistanceQuery`);let t=U().createDistanceQuery(e.wrapped);return O({distanceTo(e){return wM(e)?TM(`createDistanceQuery.distanceTo`):O(t.distanceTo(e.wrapped).value)},dispose(){t.dispose()}})}function FM(e,t,n){if(wM(e))return TM(`measureCurvatureAt`);let r=U().surfaceCurvature(e.wrapped,t,n);return O({mean:r.mean,gaussian:r.gaussian,maxCurvature:r.max,minCurvature:r.min,maxDirection:r.maxDirection,minDirection:r.minDirection})}function IM(e){if(wM(e))return TM(`measureCurvatureAtMid`);let t=cO(e),n=(t.uMin+t.uMax)/2,r=(t.vMin+t.vMax)/2,i=U().surfaceCurvature(e.wrapped,n,r);return O({mean:i.mean,gaussian:i.gaussian,maxCurvature:i.max,minCurvature:i.min,maxDirection:i.maxDirection,minDirection:i.minDirection})}function LM(e,t){return e.map(e=>IE(e,t))}function RM(e,t){let n=U(),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=LE(e,t);i.push(s),o?o.push(s.wrapped):a.set(r,[s.wrapped])}return i}function zM(e){let t=U(),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 BM(e,t,n){let r=U();return e.get(n)?.find(e=>r.isSame(e.wrapped,t))}function VM(e){let t=qE(e);if(t.edgeToFaces)return t.edgeToFaces;let n=U(),r=ZE(e),i=zM(XE(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=BM(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 HM(e){let t=qE(e);if(t.vertexToFaces)return t.vertexToFaces;let n=U(),r=ZE(e),i=zM($E(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=BM(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 UM(e,t){let n=U(),r=VM(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 LM(o,`face`)}function WM(e,t){let n=U(),r=HM(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 LM(o,`face`)}function GM(e){return RM(e.wrapped,`edge`)}function KM(e){return RM(e.wrapped,`vertex`)}function qM(e){return RM(e.wrapped,`wire`)}function JM(e){return RM(e.wrapped,`vertex`)}function YM(e,t){let n=U(),r=VM(e),i=RM(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 LM(a,`face`)}function XM(e,t){let n=U(),r=n.iterShapes(e.wrapped,`edge`),i=n.iterShapes(t.wrapped,`edge`),a=new Map;for(let e of i){let t=n.hashCode(e,G),r=a.get(t);r||(r=[],a.set(t,r)),r.push(e)}let o=[];for(let e of r)a.get(n.hashCode(e,2147483647))?.some(t=>n.isSame(e,t))?o.push(LE(e,`edge`)):n.dispose(e);for(let e of i)n.dispose(e);return o}function ZM(e,t){let n=0,r=aO(t);if(e.surfaceType!==void 0)if(r===e.surfaceType)n+=1;else return-1/0;if(e.normal!==void 0){let r=fO(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=pO(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=AM(t);if(r.ok&&r.value>0){let t=Math.abs(Math.log(e.area/r.value));t>1&&(n-=t)}}return n}function QM(e){let t=aO(e),n=fO(e),r=pO(e),i=AM(e);return{entityType:`face`,surfaceType:t,normal:n,centroid:r,area:i.ok?i.value:void 0}}var $M=.9;function eN(e){if(e[2]>$M)return`box:top`;if(e[2]<-.9)return`box:bottom`;if(e[1]>$M)return`box:back`;if(e[1]<-.9)return`box:front`;if(e[0]>$M)return`box:right`;if(e[0]<-.9)return`box:left`}function tN(e,t){if(aO(t)!==`PLANE`)return;let n=fO(t)[2];if(n>$M)return`${e}:top`;if(n<-.9)return`${e}:bottom`}function nN(e){return aO(e)===`CYLINDRE`?`cylinder:lateral`:tN(`cylinder`,e)}function rN(e){return aO(e)===`CONE`?`cone:lateral`:tN(`cone`,e)}function iN(e){return aO(e)===`SPHERE`?`sphere:surface`:void 0}var aN={box:e=>eN(fO(e)),cylinder:nN,cone:rN,sphere:iN};function oN(e,t){let n=new Map,r=aN[t],i=U(),a=0;for(let o of i.iterShapes(e.wrapped,`face`)){let e=IE(o,`face`);try{let i=r?.(e),o=i!==void 0&&!n.has(i)?i:`${t}:face_${a}`;n.set(o,[mk(e)]),a++}finally{PE(e,o)}}return n}function sN(e,t,n){return{origin:e,role:t,hint:QM(n)}}function cN(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 lN(e,t,n){let r=e.get(t);if(!r)return e;let i=new Map;for(let[e,t]of r){let r=cN(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 uN=.1,dN=.5;function fN(e,t,n){let r=-1/0,i,a=-1/0,o=[];for(let s of t){let t=n(e,s);t>dN&&o.push([s,t]),t>r?(a=r,r=t,i=s):t>a&&(a=t)}return i!==void 0&&r>dN?r-a<uN&&o.length>1?{kind:`ambiguous`,candidates:o.filter(([,e])=>e>=r-uN).map(([e])=>e)}:{kind:`match`,face:i}:{kind:`none`}}function pN(e,t,n,r){let i=ZE(n),a=r??ZM,o=t.get(e.origin)?.get(e.role);if(o!==void 0&&o.length>0){let t=i.filter(e=>o.includes(mk(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=fN(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=fN(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 hN(e){if(e.length===0)return;let t=0,n=0,r=0;for(let i of e){let e=hD(i);t+=e[0],n+=e[1],r+=e[2]}let i=e.length;return[t/i,n/i,r/i]}function gN(e,t,n){let r=n.get(t);if(!r)return;let i=mk(e);for(let[e,t]of r)if(t.includes(i))return e}function _N(e,t,n,r){let i=r.get(t)?.get(n);return i===void 0||i.length===0?[]:ZE(e).filter(e=>i.includes(mk(e)))}function vN(e){let t=jM(e);return{entityType:`edge`,length:t.ok?t.value:void 0,midpoint:hN(JM(e))}}function yN(e){let t=new Set,n=[];for(let r of e){let e=mk(r);t.has(e)||(t.add(e),n.push(r))}return n}var bN=1e-6;function xN(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=jM(a);n.ok&&(e+=Math.abs(n.value-t.length))}if(t.midpoint!==void 0){let n=hN(JM(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<bN))return n}function SN(e,t,n,r){let[i,a]=UM(n,t);if(i===void 0||a===void 0)return;let o=gN(i,e,r),s=gN(a,e,r);if(!(o===void 0||s===void 0))return{origin:e,faceRoles:[o,s],hint:vN(t)}}function CN(e,t,n){let[r,i]=e.faceRoles,a=_N(n,e.origin,r,t),o=_N(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(...XM(e,t));let c=yN(s);if(c.length===1){let[e]=c;if(e!==void 0)return{edge:e,confidence:`exact`}}if(c.length>1){let t=xN(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 wN=3,TN=1e-6;function EN(e,t){let n=new Set;for(let r of e)for(let e of KM(r)){let r=mk(e);n.add(r),t.has(r)||t.set(r,e)}return n}function DN(e,t){let n=new Set;for(let r of e)t.has(r)&&n.add(r);return n}function ON(e){let t=new Map,n;for(let r of e){let e=EN(r,t);n=n===void 0?e:DN(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 kN(e,t){if(t.position===void 0)return;let n,r=1/0,i=1/0;for(let a of e){let e=mN(hD(a),t.position);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<TN))return n}function AN(e,t,n,r){let i=WM(n,t);if(i.length<wN)return;let a=new Set;for(let t of i){let n=gN(t,e,r);n!==void 0&&a.add(n)}if(!(a.size<wN))return{origin:e,faceRoles:[...a].sort(),hint:{entityType:`vertex`,position:hD(t)}}}function jN(e,t,n){let r=[];for(let i of e.faceRoles){let a=_N(n,e.origin,i,t);if(a.length===0)return{ref:e,reason:`not-found`};r.push(a)}let i=ON(r);if(i.length===1){let[e]=i;if(e!==void 0)return{vertex:e,confidence:`exact`}}if(i.length>1){let t=kN(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 MN=.99,NN=.1,PN=1e-6;function FN(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function IN(e,t){return ZE(e).filter(e=>FN(fO(e),t)>MN)}function LN(e,t,n){let r=new Set([...t,...n].map(mk)),i=new Set;for(let n of t)for(let t of YM(e,n))i.add(mk(t));let a=[],o=new Set;for(let t of n)for(let n of YM(e,t)){let e=mk(n);r.has(e)||o.has(e)||!i.has(e)||(o.add(e),a.push(n))}return a}function RN(e,t){let n,r=1/0,i=1/0;for(let a of e){let e=mN(pO(a),t);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<PN))return n}function zN(e,t,n,r,i){let[a,o]=UM(r,n);if(a===void 0||o===void 0)return;let s=gN(a,e,i),c=gN(o,e,i);if(!(s===void 0||c===void 0))return{origin:e,op:t,betweenRoles:[s,c],hint:{entityType:`derived-face`,normalA:fO(a),normalB:fO(o),edgeMidpoint:hN(JM(n))}}}function BN(e,t,n){let r=_N(n,e.origin,e.betweenRoles[0],t);r.length===0&&(r=IN(n,e.hint.normalA));let i=_N(n,e.origin,e.betweenRoles[1],t);if(i.length===0&&(i=IN(n,e.hint.normalB)),r.length===0||i.length===0)return{ref:e,reason:`not-found`};let a=LN(n,r,i).filter(t=>FN(fO(t),e.hint.normalA)>NN&&FN(fO(t),e.hint.normalB)>NN);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&&RN(a,e.hint.edgeMidpoint);return t?{face:t,confidence:`geometric-fallback`}:{ref:e,reason:`ambiguous`,candidates:a}}return{ref:e,reason:`not-found`}}function VN(e){return typeof e==`object`&&!!e&&`origin`in e}function HN(e){return VN(e)&&`betweenRoles`in e&&`op`in e}function UN(e){return VN(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length===2}function WN(e){return VN(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length>=3}function GN(e){return VN(e)&&typeof e.role==`string`}function KN(e){return GN(e)||UN(e)||WN(e)||HN(e)}function qN(e,t){return t===void 0?{ok:!1,reason:e}:{ok:!1,reason:e,candidates:t}}function JN(e,t,n){if(HN(e)){let r=BN(e,t,n);return`face`in r?{ok:!0,entity:r.face}:qN(r.reason,r.candidates)}if(UN(e)){let r=CN(e,t,n);return`edge`in r?{ok:!0,entity:r.edge}:qN(r.reason,r.candidates)}if(WN(e)){let r=jN(e,t,n);return`vertex`in r?{ok:!0,entity:r.vertex}:qN(r.reason,r.candidates)}let r=pN(e,t,n);return`face`in r?{ok:!0,entity:r.face}:qN(r.reason,r.candidates)}function YN(e,t,n){let r=n.get(e.origin);if(r!==void 0)return r;let i=new Map([[e.origin,oN(t,e.origin)]]);return n.set(e.origin,i),i}function XN(e,t){return JN(e,YN(e,t,new Map),t)}function ZN(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 QN(e,t){let n=new Map,r=e=>{if(KN(e)){let r=JN(e,YN(e,t,n),t);return r.ok?r.entity:e}if(Array.isArray(e))return e.map(r);if(ZN(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 $N(e,t,n,r){let i=yE(U().makeBox(e,t,n)),a=r?.at??(r?.centered?[0,0,0]:void 0);if(a)try{var o=OT();return ek(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 eP(e,t,n){let r=n?.at??[0,0,0],i=n?.axis??[0,0,1],a=YA(e,t,r,i);if(n?.centered)try{var o=OT();let e=[-i[0]*t*.5,-i[1]*t*.5,-i[2]*t*.5];return ek(o.u(a),e)}catch(e){o.e=e}finally{o.d()}return a}function tP(e,t){let n=XA(e);if(t?.at)try{var r=OT();return ek(r.u(n),t.at)}catch(e){r.e=e}finally{r.d()}return n}function nP(e,t,n,r){let i=r?.at??[0,0,0],a=r?.axis??[0,0,1],o=ZA(e,t,n,i,a);if(r?.centered)try{var s=OT();let e=[-a[0]*n*.5,-a[1]*n*.5,-a[2]*n*.5];return ek(s.u(o),e)}catch(e){s.e=e}finally{s.d()}return o}function rP(e,t,n){return QA(e,t,n?.at??[0,0,0],n?.axis??[0,0,1])}function iP(e,t,n,r){let i=$A(e,t,n);if(r?.at)try{var a=OT();return ek(a.u(i),r.at)}catch(e){a.e=e}finally{a.d()}return i}function aP(e,t){return uA(e,t)}function oP(e,t){let n=t?.axis??[0,0,1];return dA(e,t?.at??[0,0,0],n)}function sP(e,t,n){let r=n?.axis??[0,0,1];return fA(e,t,n?.at??[0,0,0],r,n?.xDir)}function cP(e,t,n,r){return pA(e,t,n,r?.at??[0,0,0],r?.axis??[0,0,1],r?.lefthand??!1)}function lP(e,t,n){return mA(e,t,n)}function uP(e,t,n,r,i){let a=i?.axis??[0,0,1];return hA(e,t,n*gD,r*gD,i?.at??[0,0,0],a,i?.xDir)}function dP(e,t){return gA(e,t)}function fP(e){return vA(e)}function pP(e,t,n){return yA(e,t,n)}function mP(e){return bA(e)}function hP(e){return Ha(bA(e),e=>tE(e)?O(e):k(F(`WIRE_NOT_CLOSED`,`Assembled wire is not closed: start and end points do not coincide`)))}function gP(e,t){return xA(e,t)}function _P(e){return wA(e)}function vP(e,t){return CA(e,t)}function yP(e){return EA(e)}function bP(e){return ej(e)}function xP(e){return nj(e)}function SP(e){return rj(e)}function CP(e,t,n){return tj(e,t,n)}function wP(e,t){return JA(e,t)}function TP(e,t){return TA(e,t)}function EP(){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 DP(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??EP(),color:[a,o,s,c]}});return zT(U().createXCAFDocument(t))}function OP(e=[],{unit:t,modelUnit:n}={}){let r=e=>{let t=e;return t.indexOf(`#`)===0&&(t=t.slice(1)),t.length===3&&(t=t.replace(/([0-9a-f])/gi,`$1$1`)),[parseInt(t.substring(0,2),16),parseInt(t.substring(2,4),16),parseInt(t.substring(4,6),16)]},i=U(),a=e.map(({shape:e,name:t,color:n,alpha:i})=>{let[a,o,s]=r(n??`#f00`);return{shape:e.wrapped,name:t??EP(),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(vo(`STEP_EXPORT_FAILED`,`Failed to write STEP file`))}finally{o.delete()}}function kP(e,t,n,r,i){if(n<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(ND(t))return k(F(`PATTERN_ZERO_DIRECTION`,`Pattern direction cannot be zero`));let a=jD(t),o=U().linearPattern(e.wrapped,[...a],r,n).map(e=>W(e));try{return NA(o,{optimisation:`sameFace`,...i,unsafe:!0})}finally{for(let e of o)e[Symbol.dispose]()}}function AP(e,t,n,r=360,i=[0,0,0],a){if(n<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(ND(t))return k(F(`PATTERN_ZERO_AXIS`,`Pattern axis cannot be zero`));let o=r/n,s=U().circularPattern(e.wrapped,[...i],[...t],o,n).map(e=>W(e));try{return NA(s,{optimisation:`sameFace`,...a,unsafe:!0})}finally{for(let e of s)e[Symbol.dispose]()}}function jP(e,t,n,r,i,a,o,s){if(r<1||i<1)return k(F(`PATTERN_INVALID_COUNT`,`Grid pattern counts must be at least 1`));if(r===1&&i===1)return O(e);if(ND(t))return k(F(`PATTERN_ZERO_DIRECTION`,`Grid directionX cannot be zero`));if(ND(n))return k(F(`PATTERN_ZERO_DIRECTION`,`Grid directionY cannot be zero`));let c=U(),l=jD(t),u=jD(n);if(typeof c.gridPattern==`function`)return O(W(c.gridPattern(e.wrapped,[...l],[...u],a,o,r,i)));let d=kP(e,t,r,a,s);if(!d.ok)return d;let f=d.value,p=kP(f,n,i,o,s),m=p.ok&&p.value===f;return f!==e&&!m&&f[Symbol.dispose](),p}function MP(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 NP(e,t){return{...e,children:[...e.children,t]}}function PP(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 FP(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 IP(e,t){if(e.name===t)return e;for(let n of e.children){let e=IP(n,t);if(e)return e}}function LP(e,t,n=0){t(e,n);for(let r of e.children)LP(r,t,n+1)}function RP(e){let t=1;for(let n of e.children)t+=RP(n);return t}function zP(e){let t=[];return LP(e,e=>{e.shape&&t.push(e.shape)}),t}function BP(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function VP(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 HP(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function UP(e){return HP(VP(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function WP(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 GP(e,t){let n=t/2,r=Math.sin(n),i=HP(e);return[Math.cos(n),i[0]*r,i[1]*r,i[2]*r]}function KP(e,t){let n=HP(e),r=HP(t),i=BP(n,r);if(i>=.999999999)return[1,0,0,0];if(i<=-.999999999)return GP(UP(n),Math.PI);let a=VP(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 qP(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 JP=Math.PI/180;function YP(e,t,n){return Math.min(n,Math.max(t,e))}function XP(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function ZP(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 QP(e){return XP(ZP(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function $P(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:XP(t),min:s,max:c,value:YP(n.value??0,s,c)}}function eF(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:XP(r.direction)},min:a.min,max:a.max,value:a.value,dofs:i}}function tF(e,t,n,r={}){return eF(`revolute`,e,t,n,[$P(`rotation`,n.direction,r,-180,180)])}function nF(e,t,n,r={}){return eF(`prismatic`,e,t,n,[$P(`translation`,n.direction,r,0,100)])}function rF(e,t,n,r={}){return eF(`cylindrical`,e,t,n,[$P(`rotation`,n.direction,r.rotation??{},-180,180),$P(`translation`,n.direction,r.translation??{},0,100)])}function iF(e,t,n,r={}){let i=XP(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?QP(i):XP(n)}else a=QP(i);let o=XP(ZP(i,a));return eF(`planar`,e,t,{origin:n.origin,direction:i},[$P(`translation`,a,r.u??{},-100,100),$P(`translation`,o,r.v??{},-100,100),$P(`rotation`,i,r.rotation??{},-180,180)])}function aF(e,t,n,r={}){return eF(`spherical`,e,t,{origin:n,direction:[0,0,1]},[$P(`rotation`,[1,0,0],r.x??{},-180,180),$P(`rotation`,[0,1,0],r.y??{},-180,180),$P(`rotation`,[0,0,1],r.z??{},-180,180)])}function oF(e,t){let n=e.dofs.map((e,n)=>{let r=t[n];return r===void 0?e:{...e,value:YP(r,e.min,e.max)}}),r=n[0];return r?{...e,dofs:n,value:r.value}:{...e,dofs:n}}function sF(e,t){return oF(e,[t])}function cF(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=GP(t.axis,n*JP),i=WP(r,e);return{position:[e[0]-i[0],e[1]-i[1],e[2]-i[2]],rotation:r}}function lF(e,t=e.value){let n=Array.isArray(t)?t:void 0,r=n?void 0:t,i=e.axis.origin,a=dF;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=fF(a,cF(i,o,YP(s,o.min,o.max)))}return a}function uF(e,t){let n=e.joints??[];return{...e,joints:[...n,t]}}var dF={position:[0,0,0],rotation:[1,0,0,0]};function fF(e,t){let n=WP(e.rotation,t.position);return{position:[e.position[0]+n[0],e.position[1]+n[1],e.position[2]+n[2]],rotation:qP(e.rotation,t.rotation)}}function pF(e){let t=[];return LP(e,e=>{e.joints&&t.push(...e.joints)}),t}function mF(e,t={}){let n=[],r=new Set;LP(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,dF);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?fF(lF(n,i),n.offset):lF(n,i);a.set(n.child,fF(r,c))}}for(let e of o)a.has(e.child)||a.set(e.child,dF);return a}function hF(e){return pF(e).reduce((e,t)=>e+t.dofs.length,0)}var gF={position:[0,0,0],rotation:[1,0,0,0]};function _F(e,t){let n=WP(e.rotation,t);return[n[0]+e.position[0],n[1]+e.position[1],n[2]+e.position[2]]}function vF(e){return[e[0],-e[1],-e[2],-e[3]]}function yF(e,t){let[n,r,i,a]=qP(t,vF(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 bF(e,t){let n=[];LP(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 xF(e,t){return e[t]??0}function SF(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]=xF(e,a*n+t);i[a*r+n]=xF(t,a)}for(let e=0;e<n;e++){let t=e;for(let a=e+1;a<n;a++)Math.abs(xF(i,a*r+e))>Math.abs(xF(i,t*r+e))&&(t=a);if(Math.abs(xF(i,t*r+e))<1e-12)return null;if(t!==e)for(let n=e;n<r;n++){let a=xF(i,e*r+n);i[e*r+n]=xF(i,t*r+n),i[t*r+n]=a}let a=xF(i,e*r+e);for(let t=e;t<r;t++)i[e*r+t]=xF(i,e*r+t)/a;for(let t=0;t<n;t++){if(t===e)continue;let n=xF(i,t*r+e);if(n!==0)for(let a=e;a<r;a++)i[t*r+a]=xF(i,t*r+a)-n*xF(i,e*r+a)}}let a=new Float64Array(n);for(let e=0;e<n;e++)a[e]=xF(i,e*r+n);return a}function CF(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 wF(e,t){let n={},r=0;for(let i of e){let e=[];for(let n=0;n<i.count;n++)e.push(xF(t,r++));n[i.child]=e}return n}function TF(e,t,n,r,i){let a=_F(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=yF(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+=xF(e,t)**2;return Math.sqrt(o)}function EF(e,t,n,r,i,a,o,s,c,l){let u=_F(o,s);for(let d=0;d<n;d++){let f=xF(t,d),p=f+c>xF(a,d)&&f-c>=xF(i,d)?-c:c;t[d]=f+p;let m=l(t);t[d]=f;let h=_F(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=yF(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 DF(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+=xF(e,t*n+r)*xF(e,i*n+r);a[t*r+i]=s+(t===i?o:0)}let s=SF(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+=xF(e,a*n+t)*xF(s,a);c[t]=i}return c}function OF(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}=CF(bF(e,t),r.seed),p=u.length,m=n=>mF(e,wF(l,n)).get(t)??gF,h=new Float64Array(c),g=new Float64Array(c*p),_=m(u),v=TF(h,_,n,s,c),y=0;for(;y<i&&p>0&&v>a;y++){EF(g,u,p,c,d,f,_,s,1e-6,m);let e=DF(g,h,p,c,o);if(!e)break;for(let t=0;t<p;t++){let n=xF(u,t)+xF(e,t);u[t]=Math.min(xF(f,t),Math.max(xF(d,t),n))}_=m(u),v=TF(h,_,n,s,c)}return{values:wF(l,u),converged:v<=a,iterations:y,error:v}}function kF(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 AF(e,t,n,r){let i=[];LP(e,e=>{e.joints&&i.push(...e.joints)});let a=i.map(e=>({child:e.child,a:kF(e,t[e.child]),b:kF(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 jF=Math.PI/180;function MF(e,t,n,r){let i=e*jF,a=r*jF,o=qP(GP([0,0,1],i),GP([1,0,0],a));return{position:[n*Math.cos(i),n*Math.sin(i),t],rotation:o}}function NF(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=MF(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`?nF(i,a,s,c):tF(i,a,s,c),offset:o}})}var PF=Math.PI/180,FF=180/Math.PI;function IF(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function LF(e){return String(e===0?0:e)}function RF(e){return`${LF(e[0])} ${LF(e[1])} ${LF(e[2])}`}function zF(e,t={}){let n=t.name??`robot`,r=t.effort??0,i=t.velocity??0,a=t.meshes??{},o=[],s=[];LP(e,e=>{o.push(e.name),e.joints&&s.push(...e.joints)});for(let e of s){if(e.type!==`revolute`&&e.type!==`prismatic`)return k(F(N.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' is '${e.type}'; URDF supports only revolute and prismatic joints`));if(e.offset)return k(F(N.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' carries a fixed offset (e.g. a DH link) that URDF cannot represent as a single joint`))}let c=[`<?xml version="1.0"?>`,`<robot name="${IF(n)}">`];for(let e of o){let t=a[e];t?c.push(` <link name="${IF(e)}">`,` <visual><geometry><mesh filename="${IF(t)}"/></geometry></visual>`,` </link>`):c.push(` <link name="${IF(e)}"/>`)}for(let e of s){let t=e.type===`revolute`,n=t?e.min*PF:e.min,a=t?e.max*PF:e.max,o=e.type===`prismatic`?[0,0,0]:e.axis.origin;c.push(` <joint name="${IF(`${e.parent}_to_${e.child}`)}" type="${e.type}">`,` <parent link="${IF(e.parent)}"/>`,` <child link="${IF(e.child)}"/>`,` <origin xyz="${RF(o)}" rpy="0 0 0"/>`,` <axis xyz="${RF(e.axis.direction)}"/>`,` <limit lower="${LF(n)}" upper="${LF(a)}" effort="${LF(r)}" velocity="${LF(i)}"/>`,` </joint>`)}return c.push(`</robot>`,``),O(c.join(`
16
- `))}function BF(e,t){return RegExp(`\\b${t}\\s*=\\s*"([^"]*)"`).exec(e)?.[1]}function VF(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 HF(e,t){return WP(qP(qP(GP([0,0,1],t[2]),GP([0,1,0],t[1])),GP([1,0,0],t[0])),e)}function UF(e){let t=/<robot\b([^>]*)>/.exec(e);if(!t)return k(F(N.VALIDATION_FAILED,`importURDF: no <robot> element found`));let n=BF(t[1]??``,`name`)??`robot`,r=[],i=/<link\b([^>]*?)(?:\/>|>)/g;for(let t=i.exec(e);t;t=i.exec(e)){let e=BF(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=BF(e,`type`)??`fixed`;if(r===`fixed`||r===`floating`||r===`planar`)continue;let i=/<parent\b([^>]*?)\/?>/.exec(n),o=/<child\b([^>]*?)\/?>/.exec(n),s=BF(i?.[1]??``,`link`),c=BF(o?.[1]??``,`link`);if(!s||!c)return k(F(N.VALIDATION_FAILED,`importURDF: joint missing parent/child link (${BF(e,`name`)??`unnamed`})`));let l=/<origin\b([^>]*?)\/?>/.exec(n),u=/<axis\b([^>]*?)\/?>/.exec(n),d=/<limit\b([^>]*?)\/?>/.exec(n),f=VF(BF(l?.[1]??``,`xyz`),[0,0,0]),p=VF(BF(l?.[1]??``,`rpy`),[0,0,0]),m=HF(VF(BF(u?.[1]??``,`xyz`),[1,0,0]),p),h=Number(BF(d?.[1]??``,`lower`)??NaN),g=Number(BF(d?.[1]??``,`upper`)??NaN);if(r===`prismatic`){let e=Number.isFinite(h)&&Number.isFinite(g)?{min:h,max:g}:{};a.push(nF(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*FF,max:g*FF};a.push(tF(s,c,{origin:f,direction:m},e))}else return k(F(N.VALIDATION_FAILED,`importURDF: joint '${BF(e,`name`)??`unnamed`}' has unrecognized type '${r}'`))}return O({name:n,links:r,joints:a})}function WF(){return{steps:[],shapes:new Map}}function GF(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 KF(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 qF(e,t){return e.steps.find(e=>e.id===t)}function JF(e,t){return e.shapes.get(t)}function YF(e){return e.steps.length}function XF(e,t){let n=e.steps.findIndex(e=>e.id===t);return n===-1?[]:e.steps.slice(n)}function ZF(e,t,n){let r=new Map(e.shapes);return r.set(t,n),{...e,shapes:r}}function QF(){return{operations:new Map}}function $F(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function eI(e,t){let[n,r]=t;return n!==void 0&&r===void 0&&kE(n)?QN(e,n):{...e}}function tI(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=ZF(r,t,i));for(let n of e.steps){let e=t.operations.get(n.type);if(!e)return k(I(`REPLAY_UNKNOWN_OP`,`Unknown operation type: ${n.type}`));let i=[];for(let e of n.inputIds){let t=r.shapes.get(e);if(!t)return k(I(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${n.id}`));i.push(t)}try{let t=e(i,eI(n.parameters,i));r=GF(r,{id:n.id,type:n.type,parameters:n.parameters,inputIds:n.inputIds,outputId:n.outputId},t)}catch(e){return k(I(`REPLAY_STEP_FAILED`,`Step ${n.id} (${n.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(r)}function nI(e,t,n){let r=e.steps.findIndex(e=>e.id===t);if(r===-1)return k(I(`REPLAY_STEP_NOT_FOUND`,`Step not found: ${t}`));let i=new Map(e.shapes);for(let t=r;t<e.steps.length;t++){let n=e.steps[t];n&&i.delete(n.outputId)}let a={steps:e.steps.slice(0,r),shapes:i};for(let t=r;t<e.steps.length;t++){let r=e.steps[t];if(!r)continue;let i=n.operations.get(r.type);if(!i)return k(I(`REPLAY_UNKNOWN_OP`,`Unknown operation type: ${r.type}`));let o=[];for(let e of r.inputIds){let t=a.shapes.get(e);if(!t)return k(I(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${r.id}`));o.push(t)}try{let e=i(o,eI(r.parameters,o));a=GF(a,{id:r.id,type:r.type,parameters:r.parameters,inputIds:r.inputIds,outputId:r.outputId},e)}catch(e){return k(I(`REPLAY_STEP_FAILED`,`Step ${r.id} (${r.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(a)}function rI(e,t,n,r){return e.steps.findIndex(e=>e.id===t)===-1?k(I(`MODIFY_STEP_NOT_FOUND`,`Step not found: ${t}`)):nI({steps:e.steps.map(e=>e.id===t?{...e,parameters:n}:e),shapes:e.shapes},t,r)}function iI(e){let t={};for(let[n,r]of e.shapes){let e=pk(r);if(!e.ok)return k(I(`SERIALIZE_SHAPE_FAILED`,`Failed to serialize shape "${n}": ${e.error.message}`));t[n]=e.value}return O({steps:e.steps,shapes:t})}function aI(e){let t=new Map;for(let[n,r]of Object.entries(e.shapes))try{let e=nO(r);if(!e.ok)return k(I(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e.error.message}`));t.set(n,e.value)}catch(e){return k(I(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e instanceof Error?e.message:String(e)}`))}return O({steps:e.steps,shapes:t})}function oI(e){try{var t=OT();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(F(`THREAD_INVALID_RADIUS`,`radius must be > 0`));if(!(r>0))return k(F(`THREAD_INVALID_PITCH`,`pitch must be > 0`));if(!(i>0))return k(F(`THREAD_INVALID_HEIGHT`,`height must be > 0`));if(!(a>0))return k(F(`THREAD_INVALID_DEPTH`,`depth must be > 0`));if(s<0||s>=o)return k(F(`THREAD_INVALID_CREST`,`crest must be >= 0 and < toothHalfWidth`));if(c<3)return k(F(`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 BT),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(aP(e,f[(t+1)%f.length]))));if(!za(y))return y;v.push(_.register(y.value))}return yM(v,{ruled:!0})}catch(e){t.e=e}finally{t.d()}}var sI=1e-9,cI=1e-8,lI=1e-6,uI=([e,t],[n,r],i=lI)=>Math.abs(e-n)<=i&&Math.abs(t-r)<=i,dI=([e,t],[n,r])=>[e+n,t+r],fI=([e,t],[n,r])=>[e-n,t-r],pI=([e,t],n)=>[e*n,t*n],mI=([e,t],[n,r]=[0,0])=>Math.sqrt((e-n)**2+(t-r)**2),hI=([e,t],[n,r]=[0,0])=>(e-n)**2+(t-r)**2;function gI([e,t],[n,r]){return e*r-t*n}var _I=([e,t],[n,r]=[0,0])=>Math.atan2(r*e-t*n,e*n+t*r),vI=([e,t],[n,r]=[0,0])=>Math.atan2(r-t,n-e),yI=(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 bI([e,t]){let n=Math.sqrt(e*e+t*t);return n<1e-12?[0,0]:[e/n,t/n]}var xI=(e,t)=>[Math.cos(t)*e,Math.sin(t)*e],SI=([e,t])=>[Math.sqrt(e*e+t*t),Math.atan2(t,e)],CI=([e,t])=>{let n=bI([e,t]);return n[0]===0&&n[1]===0&&M(`normalize2d`,`Cannot normalize zero-length vector`),n};function wI(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(yo(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found ${r===0?0:`2+`} element(s)`))}function TI(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 XE(t);case`face`:return ZE(t);case`wire`:return QE(t);case`vertex`:return $E(t)}}let s=e=>{let n=o(e);return t.length===0?n.slice():n.filter(a)},c=()=>TI(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=mk(n),r=t.get(e);r?r.push(n):t.set(e,[n])}return i(e=>{let n=t.get(mk(e));return!!n&&n.some(t=>gk(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=>wI(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 EI={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function DI(e){return typeof e==`string`?EI[e]??[0,0,1]:e}function OI(e,t,n){let r=U(),i=r.makeVertex(t[0],t[1],t[2]);return t=>{let a=r.distance(i,t.wrapped).value;return Math.abs(a-e)<n}}function kI(e,t){let n=jD(DI(e));return e=>{let r=U(),[i,a]=r.curveParameters(e.wrapped),o=(i+a)/2,{tangent:s}=r.curveTangent(e.wrapped,o),c=jD(s),l=Math.acos(Math.min(1,Math.abs(ED(c,n))));return Math.abs(l-gD*t)<1e-6}}function AI(e){return TI(`edge`,e,AI,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(kI(e,t)),ofLength:(e,t=.001)=>n(n=>Math.abs(wk(n)-e)<t),ofCurveType:e=>n(t=>yk(t)===e),parallelTo:(t=`Z`)=>AI(e).inDirection(t,0),atDistance:(e,t=[0,0,0])=>n(OI(e,t,1e-6))}))}function jI(){return AI([])}function MI(e,t){let n=jD(DI(e));return e=>{let r=fO(e),i=Math.acos(Math.min(1,Math.abs(ED(jD(r),n))));return Math.abs(i-gD*t)<1e-6}}function NI(e){return TI(`face`,e,NI,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(MI(e,t)),parallelTo:(t=`Z`)=>NI(e).inDirection(t,0),ofSurfaceType:e=>n(t=>{let n=iO(t);return za(n)&&n.value===e}),ofArea:(e,t=.001)=>n(n=>{let r=AM(n);return za(r)&&Math.abs(r.value-e)<t}),atDistance:(e,t=[0,0,0])=>n(OI(e,t,1e-6))}))}function PI(){return NI([])}function FI(e){return TI(`wire`,e,FI,(e,t)=>({isClosed:()=>t(e=>Ek(e)),isOpen:()=>t(e=>!Ek(e)),ofEdgeCount:e=>t(t=>XE(t).length===e)}))}function II(){return FI([])}function LI(e,t){return typeof e==`object`&&`_topoKind`in e?e.findUnique(t):typeof e!=`function`&&TE(e)?O(e):e(PI()).findUnique(t)}function RI(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`}function zI(e,t){let n=10**t,r=t<0?e:.01/n+e;return Math.round(r*n)/n}function BI(e){return Math.round(e*100)/100}function VI(e){return Math.round(e*1e5)/1e5}var HI=([e,t])=>`(${BI(e)},${BI(t)})`,UI=(e,t=1e-9)=>{let n=e;return Math.abs(e)<t&&(n=0),n.toFixed(-Math.log10(t))},WI=(e,t=1e-9)=>Array.from(new Map(e.map(([e,n])=>[`[${UI(e,t)},${UI(n,t)}]`,[e,n]])).values()),GI=class{_wrapped;_deleted=!1;constructor(e){this._wrapped=e??gT().createBoundingBox2d(),HT(this,this._wrapped)}get wrapped(){if(this._deleted)throw Error(`This object has been deleted`);return this._wrapped}delete(){this._deleted||(this._deleted=!0,UT(this._wrapped),typeof this._wrapped.delete==`function`&&this._wrapped.delete())}[Symbol.dispose](){this.delete()}get repr(){let[e,t]=this.bounds;return`${HI(e)} - ${HI(t)}`}get bounds(){let{xMin:e,yMin:t,xMax:n,yMax:r}=gT().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){gT().mergeBBox2d(this.wrapped,e.wrapped)}isOut(e){return gT().isBBox2dOut(this.wrapped,e.wrapped)}containsPoint(e){return!gT().isBBox2dOutPoint(this.wrapped,e[0],e[1])}};function KI(e){return new qI(U().deserializeCurve2d(e))}var qI=class e{_wrapped;_deleted=!1;_boundingBox;_firstPoint=null;_lastPoint=null;_firstParameter=null;_lastParameter=null;constructor(e){this._wrapped=U().wrapCurve2dHandle(e),this._boundingBox=null,typeof this._wrapped.delete==`function`&&HT(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`&&(UT(this._wrapped),this._wrapped.delete()))}[Symbol.dispose](){this.delete()}get boundingBox(){if(this._boundingBox)return this._boundingBox;let e=U(),t=e.createBoundingBox2d();return e.addCurveToBBox2d(t,this.wrapped,1e-6),this._boundingBox=new GI(t),this._boundingBox}get repr(){return`${this.geomType} ${HI(this.firstPoint)} - ${HI(this.lastPoint)}`}serialize(){return U().serializeCurve2d(this.wrapped)}value(e){return U().evaluateCurve2d(this.wrapped,e)}get firstPoint(){return this._firstPoint===null&&(this._firstPoint=this.value(this.firstParameter)),this._firstPoint}get lastPoint(){return this._lastPoint===null&&(this._lastPoint=this.value(this.lastParameter)),this._lastPoint}get firstParameter(){return this._firstParameter===null&&(this._firstParameter=U().getCurve2dBounds(this.wrapped).first),this._firstParameter}get lastParameter(){return this._lastParameter===null&&(this._lastParameter=U().getCurve2dBounds(this.wrapped).last),this._lastParameter}get geomType(){return U().getCurve2dType(this.wrapped)}clone(){let t=new e(U().copyCurve2d(this.wrapped));return t._firstPoint=this._firstPoint,t._lastPoint=this._lastPoint,t._firstParameter=this._firstParameter,t._lastParameter=this._lastParameter,t}reverse(){U().reverseCurve2d(this.wrapped);let e=this._firstPoint;this._firstPoint=this._lastPoint,this._lastPoint=e;let t=this._firstParameter;this._firstParameter=this._lastParameter,this._lastParameter=t}distanceFromPoint(e){let t=U().projectPointOnCurve2d(this.wrapped,e[0],e[1]),n=t?t.distance:1/0;return Math.min(n,mI(e,this.firstPoint),mI(e,this.lastPoint))}distanceFromCurve(e){let t;try{t=U().distanceBetweenCurves2d(this.wrapped,e.wrapped,this.firstParameter,this.lastParameter,e.firstParameter,e.lastParameter)}catch{t=1/0}return Math.min(t,this.distanceFromPoint(e.firstPoint),this.distanceFromPoint(e.lastPoint),e.distanceFromPoint(this.firstPoint),e.distanceFromPoint(this.lastPoint))}distanceFrom(e){return RI(e)?this.distanceFromPoint(e):this.distanceFromCurve(e)}isOnCurve(e){return this.distanceFromPoint(e)<1e-9}parameter(e,t=1e-9){let n,r,i=!1;try{let t=U().projectPointOnCurve2d(this.wrapped,e[0],e[1]);t?(n=t.distance,r=t.param):i=!0}catch{i=!0}return i?uI(e,this.firstPoint,t)?O(this.firstParameter):uI(e,this.lastPoint,t)?O(this.lastParameter):k(I(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n===void 0||r===void 0?k(I(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n>t?k(I(`POINT_NOT_ON_CURVE`,`Point ${HI(e)} not on curve ${this.repr}, ${n.toFixed(9)}`)):O(r)}tangentAt(e){let t;if(Array.isArray(e))t=j(this.parameter(e));else{let n=U().getCurve2dBounds(this.wrapped);t=(n.last-n.first)*e+n.first}return U().evaluateCurve2dD1(this.wrapped,t).tangent}splitAt(n,r=1e-9){let i=n.map(e=>RI(e)?j(this.parameter(e,r)):e);i=Array.from(new Map(i.map(e=>[zI(e,-Math.log10(r)),e])).values()).sort((e,t)=>e-t);let a=this.firstParameter,o=this.lastParameter;return a>o&&i.reverse(),Math.abs(t(i,0)-a)<r*100&&(i=i.slice(1)),!i.length||(Math.abs(t(i,i.length-1)-o)<r*100&&(i=i.slice(0,-1)),!i.length)?[this]:U().splitCurve2d(this.wrapped,i).map(t=>new e(t))}},JI=(e,t=1e-4,n=`C0`,r=200)=>new qI(gT().approximateCurve2dAsBSpline(e.wrapped,t,n,r)),YI=e=>(e.geomType!==`BSPLINE_CURVE`&&M(`BSplineToBezier`,`You can only convert a Bspline`),gT().decomposeBSpline2dToBeziers(e.wrapped).map(e=>new qI(e)));function XI(e,t={tolerance:1e-4,continuity:`C0`,maxSegments:300}){let n=gT();return e.flatMap(e=>{let r=e.geomType;if(r===`ELLIPSE`||r===`CIRCLE`&&uI(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 XI(YI(r===`BSPLINE_CURVE`?e:JI(e,t.tolerance,t.continuity,t.maxSegments)),t)})}var ZI=(e,t)=>{let n=new qI(U().makeLine2d(e[0],e[1],t[0],t[1]));return uI(n.firstPoint,e)||n.reverse(),n},QI=(e,t,n)=>{let r=new qI(U().makeArc2dThreePoints(e[0],e[1],t[0],t[1],n[0],n[1]));if(!uI(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new qI(e)}return r},$I=(e,t,n)=>{let r=new qI(U().makeArc2dTangent(e[0],e[1],t[0],t[1],n[0],n[1]));if(!uI(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new qI(e)}return r},eL=(e,t=[0,0])=>new qI(U().makeCircle2d(t[0],t[1],e,!0)),tL=(e,t,n=[1,0],r=[0,0],i=!0)=>new qI(U().makeEllipse2d(r[0],r[1],e,t,n[0],n[1],i)),nL=(e,t,n,r,i=[0,0],a,o=!0)=>new qI(U().makeEllipseArc2d(i[0],i[1],e,t,n,r,a[0],a[1],o)),rL=(e,t,n)=>{let r=[[e[0],e[1]],...t.map(e=>[e[0],e[1]]),[n[0],n[1]]];return new qI(U().makeBezier2d(r))};function iL(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 qI(U().makeBSpline2d(a,{tolerance:t,smoothing:n,degMax:r,degMin:i,continuity:`C2`})))}catch(e){return k(I(`BSPLINE_2D_FAILED`,`B-spline approximation failed`,e))}}var aL=(e,t,n,r=!1)=>{let i=pI(dI(e,t),.5),a=mI(n,e)*(r?-1:1);return QI(e,dI(pI(CI(fI(i,n)),a),n),t)},oL=(e,n)=>{let r=gT(),i=e.geomType,[a,o]=n,s=`${VI(a)} ${VI(o)}`;if(i===`LINE`)return`L ${s}`;if(i===`BEZIER_CURVE`){let n=r.getCurve2dBezierPoles(e.wrapped);n||M(`adaptedCurveToPathElem`,`Expected Bezier poles`);let i=n.length-1;if(i===1)return`L ${s}`;if(i===2){let[e,r]=t(n,1);return`Q ${BI(e)} ${BI(r)} ${s}`}if(i===3){let[e,r]=t(n,1),[i,a]=t(n,2);return`C ${BI(e)} ${BI(r)} ${BI(i)} ${BI(a)} ${s}`}}if(i===`CIRCLE`){let t=r.getCurve2dCircleData(e.wrapped);t||M(`adaptedCurveToPathElem`,`Expected circle data`);let{radius:n,isDirect:i}=t,c=r.getCurve2dBounds(e.wrapped),l=(c.last-c.first)*_D,u=l===360?`${VI(a)} ${VI(o+1e-4)}`:s;return`A ${n} ${n} 0 ${Math.abs(l)>180?`1`:`0`} ${i?`1`:`0`} ${u}`}if(i===`ELLIPSE`){let t=r.getCurve2dEllipseData(e.wrapped);t||M(`adaptedCurveToPathElem`,`Expected ellipse data`);let{majorRadius:n,minorRadius:i,xAxisAngle:c,isDirect:l}=t,u=r.getCurve2dBounds(e.wrapped),d=(u.last-u.first)*_D,f=d===360?`${VI(a)} ${VI(o+1e-4)}`:s,p=180-c*_D;return`A ${VI(n)} ${VI(i)} ${VI(p)} ${Math.abs(d)>180?`1`:`0`} ${l?`1`:`0`} ${f}`}M(`adaptedCurveToPathElem`,`Unsupported curve type: ${i}`)},sL=e=>{let t=U(),n=t.createBoundingBox2d();return e.forEach(e=>{t.addCurveToBBox2d(n,e.wrapped,1e-6)}),new GI(n)};function cL(e,t){let n=U();return e.map(e=>hE(n.liftCurve2dToPlane(e.wrapped,[...t.origin],[...t.zDir],[...t.xDir])))}var lL=(e,t)=>{let n=U();return e.map(e=>hE(n.buildEdgeOnSurface(e.wrapped,t)))},uL=(e,t)=>{let n=U();return e.map(e=>t?new qI(n.transformCurve2dGeneral(e.wrapped,t)):e.clone())},dL=(e,t,n=[0,0])=>U().createAffinityGTrsf2d(n[0],n[1],-t[1],t[0],e),fL=e=>U().createTranslationGTrsf2d(e[0],e[1]),pL=(e,t=[0,0],n=`center`)=>n===`center`?U().createMirrorGTrsf2d(e[0],e[1],`point`):U().createMirrorGTrsf2d(0,0,`axis`,t[0],t[1],e[0],e[1]),mL=(e,t=[0,0])=>U().createRotationGTrsf2d(e,t[0],t[1]),hL=(e,t=[0,0])=>U().createScaleGTrsf2d(e,t[0],t[1]);function gL(e,t,n=`original`){let r=U(),i=r.extractSurfaceFromFace(t.wrapped),a=cO(t),o=null;if(n===`original`&&aO(t)!==`PLANE`){if(aO(t)!==`CYLINDRE`)return k(F(`UNSUPPORTED_FACE_TYPE`,`Only planar and cylindrical faces can be unwrapped for sketching`));let e=r.getSurfaceCylinderData(i);if(!e)return k(F(`UNSUPPORTED_FACE_TYPE`,`Could not extract cylinder data from face surface`));e.isDirect||(i=r.reverseSurfaceU(i)),o=dL(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=lL(uL(e,o),i);return o&&o.delete(),O(s)}function _L(e,t){let n=U(),r=new qI(n.extractCurve2dFromEdge(e.wrapped,t.wrapped));return kk(e)===`backward`&&n.reverseCurve2d(r.wrapped),r}var vL=(e,t=1)=>`${e.bounds[0][0]-t} ${-e.bounds[1][1]-t} ${e.width+2*t} ${e.height+2*t}`,yL=(e,t,n=1)=>`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${vL(t,n)}" fill="none" stroke="black" stroke-width="0.6%" vector-effect="non-scaling-stroke">
15
+ npm install brepkit-wasm`)}function OT(){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 kT=Symbol;kT.dispose??=Symbol.for(`Symbol.dispose`),kT.asyncDispose??=Symbol.for(`Symbol.asyncDispose`);var AT=globalThis;AT.FinalizationRegistry||=(console.warn(`brepjs: FinalizationRegistry unavailable — garbage collection will not work`),class{register(e,t,n){}unregister(e){return!1}});var jT={liveHandles:0,peakHandles:0,gcCollected:0,scopeEnters:0,scopeExits:0};function MT(){return{...jT}}function NT(){jT.liveHandles=0,jT.peakHandles=0,jT.gcCollected=0,jT.scopeEnters=0,jT.scopeExits=0}function PT(){jT.liveHandles++,jT.liveHandles>jT.peakHandles&&(jT.peakHandles=jT.liveHandles)}function FT(){jT.liveHandles--}function IT(){jT.gcCollected++,jT.liveHandles--}var LT=new FinalizationRegistry(e=>{IT();try{e.delete()}catch{}});function RT(e){let t=U(),n=!1,r,i=()=>{if(r){for(let e of r)try{e()}catch{}r=void 0}},a=()=>{if(!n){n=!0,FT(),LT.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 PT(),LT.register(o,{delete:()=>{t.dispose(e)}},o),o}function zT(e){let t=()=>{};return{get wrapped(){return e},get disposed(){return!1},[Symbol.dispose]:t,delete:t,onDispose:t}}function BT(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,FT(),LT.unregister(n);try{e.delete()}catch{}}}};return PT(),LT.register(n,e,n),n}var VT=class{handles=[];constructor(){jT.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](){jT.scopeExits++;for(let e=this.handles.length-1;e>=0;e--)this.handles[e]?.();this.handles.length=0}};function HT(e){try{var t=OT();return e(t.u(new VT))}catch(e){t.e=e}finally{t.d()}}function UT(e,t){LT.register(e,t,t)}function WT(e){LT.unregister(e)}function GT(e){try{var t=OT();return e(t.u(new VT))}catch(e){t.e=e}finally{t.d()}}async function KT(e){try{var t=OT();return await e(t.u(new VT))}catch(e){t.e=e}finally{t.d()}}function qT(e){return!e.disposed}function JT(e){return e.__is2D!==!0}function YT(e){return e.__is2D===!0}function XT(e){if(!JT(e))throw Error(`Expected 3D shape, got 2D`);return e}function ZT(e){if(!YT(e))throw Error(`Expected 2D shape, got 3D`);return e}var QT=new WeakMap;function $T(e,t){QT.set(e,t)}function eE(e,t){let n=QT.get(t);if(n!==void 0)return n;let r=e.shapeType(t);return QT.set(t,r),r}function tE(e){return eE(U(),e.wrapped)}function nE(e){return U().curveIsClosed(e.wrapped)}function rE(e){return U().isValid(e.wrapped)}function iE(e){let t=U();if(!t.isValid(e.wrapped))return!1;let n=t.isValidStrict?.bind(t)??t.isValid.bind(t);try{let r=t.solidFromShell(e.wrapped),i=n(r);try{t.dispose(r)}catch{}return i}catch{return!1}}function aE(e){return U().isValid(e.wrapped)}function oE(e){return nE(e)?O(e):k(`Wire is not closed: start and end points do not coincide`)}function sE(e){return rE(e)?O(e):k(`Face orientation is inconsistent or face is invalid`)}function cE(e){return iE(e)?O(e):k(`Shell is not manifold: has free edges or is invalid`)}function lE(e){return aE(e)?O(e):k(`Solid failed BRepCheck validation`)}function uE(e){return U().surfaceType(e.wrapped)===`plane`}function dE(e){let t=U(),n=n=>{try{let r=t.makeFace(e.wrapped,n),i=t.surfaceType(r);try{t.dispose(r)}catch{}return i===`plane`}catch{return!1}};return n(!0)?!0:n(!1)}function fE(e){return uE(e)?O(e):k(`Face is not planar: underlying surface is not a geometric plane`)}function pE(e){return dE(e)?O(e):k(`Wire is not planar: edges do not lie in a common plane`)}function mE(e,t){return t===`2D`&&(e.__is2D=!0),e}function hE(e,t){return mE(RT(e),t)}function gE(e,t){return mE(RT(e),t)}function _E(e,t){return mE(RT(e),t)}function vE(e,t){return mE(RT(e),t)}function yE(e){return mE(RT(e))}function bE(e){return mE(RT(e))}function xE(e){return mE(RT(e))}function SE(e,t){return mE(RT(e),t)}function CE(e){return tE(e)===`vertex`}function wE(e){return tE(e)===`edge`}function TE(e){return tE(e)===`wire`}function EE(e){return tE(e)===`face`}function DE(e){return tE(e)===`shell`}function OE(e){return tE(e)===`solid`}function kE(e){return tE(e)===`compound`}function AE(e){let t=tE(e);return t===`shell`||t===`solid`||t===`compsolid`?!0:t===`compound`?JT(e):!1}function jE(e){let t=tE(e);return t===`edge`||t===`wire`}function ME(e,t){let n=U(),r=eE(n,e),i=n.downcast(e,r);return r===`vertex`?hE(i,t):r===`edge`?gE(i,t):r===`wire`?_E(i,t):r===`face`?vE(i,t):r===`shell`?yE(i):r===`solid`?bE(i):r===`compsolid`?xE(i):SE(i,t)}function NE(e){return ME(e)}function PE(e,t){let n=e.id,r=t.wrapped.id;(n!==void 0&&r!==void 0?n===r:t.wrapped===e)||U().dispose(e)}function W(e,t){let n=ME(e,t);return PE(e,n),n}function FE(e,t){let n=e.wrapped;if(e[Symbol.dispose](),n!==t){let e=U();e.dispose(n),e.dispose(t)}}function IE(e){U().dispose(e.wrapped),e[Symbol.dispose]()}function LE(e,t,n){$T(e,t);let r=U().downcast(e,t);return t===`vertex`?hE(r,n):t===`edge`?gE(r,n):t===`wire`?_E(r,n):t===`face`?vE(r,n):t===`shell`?yE(r):t===`solid`?bE(r):t===`compsolid`?xE(r):SE(r,n)}function RE(e,t,n){let r=LE(e,t,n);return PE(e,r),r}function zE(e,t,n){return $T(e,t),mE(zT(e),n)}function BE(e,t,n,r,i){let a={kind:e,code:t,message:n,cause:r};return i?{...a,suggestion:i}:a}var VE={KERNEL_OPERATION:(e,t,n,r)=>BE(`KERNEL_OPERATION`,e,t,n,r),VALIDATION:(e,t,n,r)=>BE(`VALIDATION`,e,t,n,r),TYPE_CAST:(e,t,n,r)=>BE(`TYPE_CAST`,e,t,n,r),SKETCHER_STATE:(e,t,n,r)=>BE(`SKETCHER_STATE`,e,t,n,r),MODULE_INIT:(e,t,n,r)=>BE(`MODULE_INIT`,e,t,n,r),COMPUTATION:(e,t,n,r)=>BE(`COMPUTATION`,e,t,n,r),IO:(e,t,n,r)=>BE(`IO`,e,t,n,r),QUERY:(e,t,n,r)=>BE(`QUERY`,e,t,n,r),UNSUPPORTED:(e,t,n,r)=>BE(`UNSUPPORTED`,e,t,n,r)};function HE(e,t,n,r=`KERNEL_OPERATION`){try{return O(W(e()))}catch(e){let i=e instanceof Error?e.message:String(e),a=r===`KERNEL_OPERATION`?po(i):i,o=fo(t);return k(VE[r](t,`${n}: ${a}`,e,o))}}function UE(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`?po(i):i,o=fo(t);return k(VE[r](t,`${n}: ${a}`,e,o))}}function WE(e,t,n,r=`KERNEL_OPERATION`){try{var i=OT();let a=i.u(new VT);return HE(()=>e(a),t,n,r)}catch(e){i.e=e}finally{i.d()}}function GE(e,t){let n=U().iterShapes(e,t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=RE(n[e],t);return r}var KE=new WeakMap;function qE(e){let t=KE.get(e);if(!t)return;KE.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 JE=new WeakSet;function YE(e){let t=e.wrapped,n=KE.get(t);return n||(n={},KE.set(t,n)),JE.has(e)||(JE.add(e),e.onDispose(()=>{qE(t)})),n}function XE(e){return KE.get(e.wrapped)}function ZE(e){qE(e.wrapped)}function QE(e){let t=YE(e);if(t.edges)return t.edges;let n=GE(e.wrapped,`edge`);return t.edges=n,n}function $E(e){let t=YE(e);if(t.faces)return t.faces;let n=GE(e.wrapped,`face`);return t.faces=n,n}function eD(e){let t=YE(e);if(t.wires)return t.wires;let n=GE(e.wrapped,`wire`);return t.wires=n,n}function tD(e){let t=YE(e);if(t.vertices)return t.vertices;let n=GE(e.wrapped,`vertex`);return t.vertices=n,n}function nD(e){let t=YE(e);if(t.solids)return t.solids;let n=GE(e.wrapped,`solid`);return t.solids=n,n}function rD(e){let t=YE(e);if(t.shells)return t.shells;let n=GE(e.wrapped,`shell`);return t.shells=n,n}function iD(e){let t=YE(e);if(t.compSolids)return t.compSolids;let n=GE(e.wrapped,`compsolid`);return t.compSolids=n,n}function*aD(e){for(let t of U().iterShapes(e.wrapped,`edge`))yield RE(t,`edge`)}function*oD(e){for(let t of U().iterShapes(e.wrapped,`face`))yield RE(t,`face`)}function*sD(e){for(let t of U().iterShapes(e.wrapped,`wire`))yield RE(t,`wire`)}function*cD(e){for(let t of U().iterShapes(e.wrapped,`vertex`))yield RE(t,`vertex`)}function*lD(e){for(let t of U().iterShapes(e.wrapped,`solid`))yield RE(t,`solid`)}function*uD(e){for(let t of U().iterShapes(e.wrapped,`shell`))yield RE(t,`shell`)}function*dD(e){for(let t of U().iterShapes(e.wrapped,`compsolid`))yield RE(t,`compsolid`)}function fD(e){let t=YE(e);if(t.bounds)return t.bounds;let{min:n,max:r}=U().boundingBox(e.wrapped),i={xMin:n[0],xMax:r[0],yMin:n[1],yMax:r[1],zMin:n[2],zMax:r[2]};return t.bounds=i,i}function pD(e){return eE(U(),e.wrapped)}function mD(e){let t=YE(e);if(t.surfaceType!==void 0)return t.surfaceType;let n=U().surfaceType(e.wrapped);return t.surfaceType=n,n}function hD(e){let t=YE(e);if(t.isValid!==void 0)return t.isValid;let n=U().isValid(e.wrapped);return t.isValid=n,n}function gD(e){return{kind:pD(e),faceCount:$E(e).length,edgeCount:QE(e).length,wireCount:eD(e).length,vertexCount:tD(e).length,valid:hD(e),bounds:fD(e)}}function _D(e){return U().vertexPosition(e.wrapped)}var G=2147483647,vD=Math.PI/180,yD=180/Math.PI;function bD(e){return e.length===2?[e[0],e[1],0]:[e[0],e[1],e[2]]}function xD(e){return[e[0],e[1]]}var SD={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function CD(e){if(typeof e==`string`){let t=SD[e];if(!t)throw Error(`Unknown direction: ${e}`);return t}return e}function wD(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function TD(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function ED(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function DD(e){return[-e[0],-e[1],-e[2]]}function OD(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function kD(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 AD(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function jD(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function MD(e,t){return AD(TD(e,t))}function ND(e){let t=AD(e);return t<1e-10?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function PD(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 FD(e,t=1e-10){return jD(e)<t*t}function ID(e,t){let n=OD(e,t),r=AD(e),i=AD(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 LD(e,t,n){let r=TD(e,t),i=jD(n);return i<1e-20?e:TD(e,ED(n,OD(r,n)/i))}function RD(e,t,n){let r=ND(t),i=Math.cos(n),a=Math.sin(n),o=OD(e,r),s=kD(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 zD=e=>Math.round(e*1e3)/1e3;function BD(e){return`x: ${zD(e[0])}, y: ${zD(e[1])}, z: ${zD(e[2])}`}function VD(e,t=null,n=[0,0,1]){let r=ND(n);if(FD(r))throw Error(`Plane normal must be non-zero`);let i;if(t)i=ND(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?ND([l,u,d]):[1,0,0]}if(FD(i))throw Error(`Plane xDir must be non-zero`);let a=ND(kD(r,i));return{origin:e,xDir:i,yDir:a,zDir:r}}var HD={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 UD(e,t=[0,0,0]){let n=HD[e];if(!n)return k(F(`UNKNOWN_PLANE`,`Could not find plane ${e}`));let r;return r=typeof t==`number`?ED(n.normal,t):bD(t),O(VD(r,n.xDir,n.normal))}function WD(e,t){return typeof e==`string`?UD(e,t):O(e)}function GD(e,t){return e&&typeof e!=`string`?{...e}:j(WD(e??`XY`,t))}function KD(e,t){let[n,r]=t;return wD(wD(e.origin,ED(e.xDir,n)),ED(e.yDir,r))}function qD(e,t){return{...e,origin:wD(e.origin,t)}}function JD(e,t,n=[1,0,0]){let r=t*vD,i=RD(e.zDir,n,r),a=RD(e.xDir,n,r),o=ND(kD(i,a));return{origin:e.origin,xDir:a,yDir:o,zDir:i}}var YD={compound:0,solidCompound:1,solid:2,shell:3,face:4,wire:5,edge:6,vertex:7,shape:8},XD=e=>YD[e],ZD={vertex:`vertex`,edge:`edge`,wire:`wire`,face:`face`,shell:`shell`,solid:`solid`,solidCompound:`compsolid`,compound:`compound`,shape:`compound`},QD=function*(e,t){let n=U().iterShapes(e,ZD[t]);for(let e of n)yield e},$D=e=>U().isNull(e)?k(ho(`NULL_SHAPE`,`This shape has no type, it is null`)):O(e.ShapeType());function eO(e){if(U().isNull(e))return k(ho(`NULL_SHAPE`,`This shape has no type, it is null`));try{return O(U().downcast(e))}catch(e){return k(ho(`NO_WRAPPER`,`Could not find a wrapper for this shape type`,e))}}function tO(e){if(U().isNull(e))return k(ho(`NULL_SHAPE`,`Cannot copy a null shape`));try{return O(U().copyShape(e))}catch(e){return k(ho(`NO_WRAPPER`,`Could not copy this shape`,e))}}function nO(e){return U().isNull(e)?k(ho(`NULL_SHAPE`,`Cannot cast a null shape`)):O(ME(e))}function rO(e){return U().shapeType(e.wrapped)===`compsolid`}function iO(e){return nO(U().fromBREP(e))}var aO={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 oO(e){return O(aO[mD(e)])}function sO(e){return j(oO(e))}function cO(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function lO(e){return ME(U().reverseShape(e.wrapped))}function uO(e){return U().uvBounds(e.wrapped)}function dO(e,t,n){let r=uO(e),i=t*(r.uMax-r.uMin)+r.uMin,a=n*(r.vMax-r.vMin)+r.vMin;return U().pointOnSurface(e.wrapped,i,a)}function fO(e,t){let n=bD(t);return U().uvFromPoint(e.wrapped,n)||[0,0]}function pO(e,t){let n=bD(t);try{let t=n,r=U().uvFromPoint(e.wrapped,t);if(!r)return k(ho(`PROJECTION_FAILED`,`No projection found on the face`));let i=U().projectPointOnFace(e.wrapped,t),a=n[0]-i[0],o=n[1]-i[1],s=n[2]-i[2];return O({uv:r,point:i,distance:Math.sqrt(a*a+o*o+s*s)})}catch(e){return k(ho(`PROJECTION_FAILED`,`Point projection failed: ${e instanceof Error?e.message:String(e)}`))}}function mO(e,t){let n,r;if(t)[n,r]=fO(e,t);else{let t=uO(e);n=.5*(t.uMin+t.uMax),r=.5*(t.vMin+t.vMax)}return U().surfaceNormal(e.wrapped,n,r)}function hO(e){return U().surfaceCenterOfMass(e.wrapped)}function gO(e){return U().getSurfaceAxis(e.wrapped)}function _O(e,t,n=1e-6){let[r,i]=fO(e,t);return U().classifyPointOnFace(e.wrapped,r,i,n)}function vO(e){return ME(U().outerWire(e.wrapped))}function yO(e){return ME(U().removeHolesFromFace(e.wrapped))}function bO(e){let t=vO(e);return Array.from(QD(e.wrapped,`wire`)).map(e=>ME(j(eO(e)))).filter(e=>!U().isSame(e.wrapped,t.wrapped))}function xO(e,t){let n=YE(e),r=U(),i=new Map;for(let n of r.iterShapes(e.wrapped,`face`))i.set(r.hashCode(n,G),t),r.dispose(n);n.faceOrigins=i}function SO(e){return XE(e)?.faceOrigins}function CO(e,t,n){let r=new Map;for(let e of t){let t=SO(e);if(t)for(let[e,n]of t)r.set(e,n)}if(r.size===0)return;let i=new Map;for(let[t,n]of r){if(e.deleted.has(t))continue;let r=e.modified.get(t);if(r&&r.length>0)for(let e of r)i.set(e,n);else i.set(t,n);let a=e.generated.get(t);if(a)for(let e of a)i.has(e)||i.set(e,n)}if(i.size>0){let e=YE(n);e.faceOrigins=i}}var wO=100,TO=.985,EO=.1;function DO(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>wO)continue;let u=r-l/wO;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)<TO)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>EO)continue;let u=Math.max(0,i*i+a*a+c*c-l*l);u<o&&(o=u,s=n.origin)}return s}function OO(e,t){let n=new Map;for(let t of e){let e=SO(t);if(e)for(let[t,r]of e)n.set(t,r)}if(n.size===0)return;let r=U(),i=new Map,a=$E(t),o=[];for(let e of a){let t=r.hashCode(e.wrapped,G),a=n.get(t);a===void 0?o.push(e):i.set(t,a)}if(o.length>0){let t=[];for(let n of e){let e=SO(n);if(e)for(let i of $E(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=DO(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=YE(t);e.faceOrigins=i}}var kO=new WeakMap,AO=new WeakMap;function jO(e){return kO.has(e.wrapped)}function MO(e){let t=kO.get(e.wrapped);return t||(t=new Map,kO.set(e.wrapped,t)),t}function NO(e){let t=AO.get(e.wrapped);return t||(t=new Map,AO.set(e.wrapped,t)),t}function PO(e,t,n){let r=Array.isArray(t)?t:$E(e).filter(t),i=MO(e),a=i.get(n)??new Set;for(let e of r)a.add(U().hashCode(e.wrapped,G));return i.set(n,a),e}function FO(e,t){let n=kO.get(e.wrapped);if(!n)return[];let r=n.get(t);if(!r||r.size===0)return[];let i=[];for(let t of $E(e)){let e=U().hashCode(t.wrapped,G);r.has(e)&&i.push(t)}return i}function IO(e){let t=new Map,n=kO.get(e.wrapped);if(!n)return t;let r=$E(e),i=new Map;for(let e of r)i.set(U().hashCode(e.wrapped,G),e);for(let[e,r]of n){let n=[];for(let e of r){let t=i.get(e);t&&n.push(t)}n.length>0&&t.set(e,n)}return t}function LO(e,t,n){return NO(e).set(t,n),e}function RO(e,t){return AO.get(e.wrapped)?.get(t)}function zO(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function BO(e,t,n){let r=MO(n);for(let i of t){let t=kO.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)zO(r,t,e)}let o=AO.get(i.wrapped);if(o){let e=NO(n);for(let[t,n]of o)e.has(t)||e.set(t,n)}}}var VO=new WeakMap,HO=new WeakMap;function UO(e){return VO.has(e.wrapped)||HO.has(e.wrapped)}function WO(e){let t=HO.get(e.wrapped);return t||(t=new Map,HO.set(e.wrapped,t)),t}function GO(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 KO(e,t){return VO.set(e.wrapped,GO(t)),e}function qO(e,t,n){let r=GO(n),i=WO(e);for(let e of t)i.set(U().hashCode(e.wrapped,G),r);return e}function JO(e){return VO.get(e.wrapped)}function YO(e,t){let n=HO.get(e.wrapped);if(n)return n.get(U().hashCode(t.wrapped,G))}function XO(e,t,n){for(let e of t){let t=VO.get(e.wrapped);if(t){VO.set(n.wrapped,t);break}}let r=WO(n);for(let n of t){let t=HO.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 ZO(e){return SO(e)!==void 0||jO(e)||UO(e)}function QO(e){if(!e.some(ZO))return[];let t=U(),n=[];for(let r of e){let e=t.iterShapes(r.wrapped,`face`);for(let r of e)n.push(t.hashCode(r,G)),t.dispose(r)}return n}function $O(e,t,n){CO(e,t,n),BO(e,t,n),XO(e,t,n)}function ek(e,t){OO(e,t)}function tk(e,t){let n=U(),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);$O({modified:a,generated:new Map,deleted:new Set},[e],t)}function nk(e,t){let n=QO([e]),{shape:r,evolution:i}=U().translateWithHistory(e.wrapped,t[0],t[1],t[2],n,G),a=W(r);return $O(i,[e],a),a}function rk(e,t,n=[0,0,0],r=[0,0,1]){let i=QO([e]),{shape:a,evolution:o}=U().rotateWithHistory(e.wrapped,t*vD,i,G,r,n),s=W(a);return $O(o,[e],s),s}function ik(e,t=[0,1,0],n=[0,0,0]){let r=QO([e]),{shape:i,evolution:a}=U().mirrorWithHistory(e.wrapped,n,t,r,G),o=W(i);return $O(a,[e],o),o}function ak(e,t,n=[0,0,0]){let r=QO([e]),{shape:i,evolution:a}=U().scaleWithHistory(e.wrapped,n,t,r,G),o=W(i);return $O(a,[e],o),o}function ok(e,t,n){let r=U().boundingBox(e.wrapped),i=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]],a=n?.auto===!0;function o(e,t,n){return e!==void 0&&t>1e-12?e/t:e===void 0&&a?n:1}let s=1;a&&(t[0]!==void 0&&i[0]>1e-12?s=t[0]/i[0]:t[1]!==void 0&&i[1]>1e-12?s=t[1]/i[1]:t[2]!==void 0&&i[2]>1e-12&&(s=t[2]/i[2]));let c=[o(t[0],i[0],s),o(t[1],i[1],s),o(t[2],i[2],s)];return Math.abs(c[0]-c[1])<1e-6&&Math.abs(c[1]-c[2])<1e-6?O(ak(e,c[0])):k(F(N.VALIDATION_FAILED,`resize: non-uniform scaling is not supported (WASM build lacks BRepBuilderAPI_GTransform).`,void 0,void 0,`Use auto: true to scale proportionally, or set all three dimensions to achieve uniform scaling.`))}function sk(e){if(`linear`in e)return O({linear:e.linear,translation:e.translation});let[t,n,r,i]=e,a=1e-10;return Math.abs(i[0])>a||Math.abs(i[1])>a||Math.abs(i[2])>a||Math.abs(i[3]-1)>a?k(F(N.VALIDATION_FAILED,`applyMatrix: invalid bottom row [${String(i[0])}, ${String(i[1])}, ${String(i[2])}, ${String(i[3])}]. Must be [0, 0, 0, 1] for an affine transform.`)):O({linear:[t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]],translation:[t[3],n[3],r[3]]})}function ck(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 lk(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 uk(e,t){let n=sk(t);if(!n.ok)return n;let{linear:r,translation:i}=n.value,a=ck(r);if(Math.abs(a)<1e-12)return k(F(N.VALIDATION_FAILED,`applyMatrix: singular matrix (determinant ≈ 0). Cannot apply a non-invertible transform.`));if(lk(r)){let t=QO([e]),{shape:n,evolution:a}=U().generalTransformWithHistory(e.wrapped,r,i,!0,t,G),o=W(n);return $O(a,[e],o),O(o)}let o=W(U().generalTransformNonOrthogonal(e.wrapped,r,i));return ek([e],o),O(o)}function dk(e){let t=e.map(e=>e.type===`translate`?{type:`translate`,x:e.v[0],y:e.v[1],z:e.v[2]}:{type:`rotate`,angle:e.angle,axis:e.axis,center:e.center}),{handle:n,dispose:r}=U().composeTransform(t);return{trsf:n,cleanup:r}}function fk(e,t){let{trsf:n,cleanup:r}=dk(`type`in t?[t]:t),i;try{i=W(U().locate(e.wrapped,n))}finally{r()}return ZO(e)&&tk(e,i),i}function pk(e,t){let n=QO([e]),{shape:r,evolution:i}=U().applyComposedTransformWithHistory(e.wrapped,t.trsf,n,G),a=W(r);return $O(i,[e],a),a}function mk(e){return HE(()=>U().copyShape(e.wrapped),N.CLONE_FAILED,`Failed to clone shape`)}function hk(e){return UE(()=>U().toBREP(e.wrapped),N.TO_BREP_FAILED,`Failed to serialize shape to BREP`)}function gk(e){return U().hashCode(e.wrapped,G)}function _k(e){return U().isNull(e.wrapped)}function vk(e,t){return U().isSame(e.wrapped,t.wrapped)}function yk(e,t){return U().isEqual(e.wrapped,t.wrapped)}function bk(e){return HE(()=>U().simplify(e.wrapped),N.SIMPLIFY_FAILED,`Failed to simplify shape`)}function xk(e){return U().curveType(e.wrapped)}function Sk(e){let[t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function Ck(e){let[,t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function wk(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curvePointAtParam(e.wrapped,i)}function Tk(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curveTangent(e.wrapped,i).tangent}function Ek(e){return U().length(e.wrapped)}function Dk(e){if(xk(e)!==`CIRCLE`)return null;let t=wk(e,0),n=wk(e,1/3),r=wk(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 Ok(e){return U().curveIsClosed(e.wrapped)}function kk(e){return U().curveIsPeriodic(e.wrapped)}function Ak(e){return U().curvePeriod(e.wrapped)}function jk(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function Mk(e){return W(U().reverseShape(e.wrapped))}function Nk(e,t={}){if(e.length<2)return k(ho(`INTERPOLATE_MIN_POINTS`,`Interpolation requires at least 2 points`));try{let n=W(U().interpolatePoints(e,t));return wE(n)?O(n):(IE(n),k(ho(`INTERPOLATE_NOT_EDGE`,`Interpolation did not produce an edge`)))}catch(e){return k(ho(`INTERPOLATE_FAILED`,`Interpolation failed: ${e instanceof Error?e.message:String(e)}`))}}function Pk(e,t={}){if(e.length<2)return k(ho(`APPROXIMATE_MIN_POINTS`,`Approximation requires at least 2 points`));try{let n=W(U().approximatePoints(e,t));return wE(n)?O(n):(IE(n),k(ho(`APPROXIMATE_NOT_EDGE`,`Approximation did not produce an edge`)))}catch(e){return k(ho(`APPROXIMATE_FAILED`,`Approximation failed: ${e instanceof Error?e.message:String(e)}`))}}function Fk(e,t,n=`arc`){let r=W(U().offsetWire2D(e.wrapped,t,{arc:`arc`,intersection:`intersection`,tangent:`tangent`,chamfer:`intersection`}[n]));return TE(r)?O(r):(IE(r),k(ho(`OFFSET_NOT_WIRE`,`Offset did not produce a Wire`)))}function Ik(e,t,n,r=!1){return`${e}:${t}:${n}:${r}`}function Lk(e,t){return`edge:${e}:${t}`}var Rk=new WeakMap,zk=new WeakMap;function Bk(e,t){let n=Rk.get(e);if(n)return n.get(t)}function Vk(e,t,n){let r=Rk.get(e);r||(r=new Map,Rk.set(e,r)),r.set(t,n)}function Hk(e,t){let n=zk.get(e);if(n)return n.get(t)}function Uk(e,t,n){let r=zk.get(e);r||(r=new Map,zk.set(e,r)),r.set(t,n)}function Wk(){Rk=new WeakMap,zk=new WeakMap}function Gk(){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 Kk(e,t={}){let n=To(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,skipNormals:a=!1,includeUVs:o=!1,cache:s=!0,signal:c}=t;c?.throwIfAborted();let l=Ik(r,i,a,o);if(s){let t=Bk(e.wrapped,l);if(t)return t}let u=U().mesh(e.wrapped,{tolerance:r,angularTolerance:i,skipNormals:a,includeUVs:o,...c?{signal:c}:{}}),d=SO(e),f={vertices:u.vertices,normals:u.normals,triangles:u.triangles,uvs:u.uvs,faceGroups:u.faceGroups.map(e=>({start:e.start,count:e.count,faceId:e.faceHash,origin:d?.get(e.faceHash)??0}))};return s&&Vk(e.wrapped,l,f),f}function qk(e,t={}){let n=To(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,cache:a=!0}=t,o=Lk(r,i);if(a){let t=Hk(e.wrapped,o);if(t)return t}let s=U().meshEdges(e.wrapped,r,i),c={lines:s.lines,edgeGroups:s.edgeGroups.map(e=>({start:e.start,count:e.count,edgeId:e.edgeHash}))};return a&&Uk(e.wrapped,o,c),c}function Jk(e,t){return e instanceof Error&&e.message.startsWith(`${t} export failed`)?vo(`${t}_EXPORT_FAILED`,`Failed to write ${t} file`,e):e instanceof WebAssembly.RuntimeError?vo(`${t}_EXPORT_CRASHED`,`${t} export crashed the kernel (${e.message}); the shape likely contains geometry the ${t} writer cannot serialize`,e):vo(`${t}_FILE_READ_ERROR`,`Failed to read exported ${t} file`,e)}function Yk(e){let t;try{t=nD(e)}catch{return``}if(t.length<=1)return``;let n=[];return t.forEach((e,t)=>{try{fD(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 Xk(e,t){try{return fD(e),null}catch(n){if(n instanceof TypeError)throw n;return vo(`${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${Yk(e)}`,n)}}function Zk(e){let t=Xk(e,`STEP`);if(t)return k(t);try{let t=U().exportSTEP([e.wrapped]);return O(new Blob([t],{type:`application/STEP`}))}catch(e){return k(Jk(e,`STEP`))}}function Qk(e,t={}){let n=To(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,binary:a=!1}=t,o=Xk(e,`STL`);if(o)return k(o);try{U().hasTriangulation(e.wrapped)||U().meshShape(e.wrapped,r,i);let t=U().exportSTL(e.wrapped,a,r,i);return O(new Blob([t],{type:`application/sla`}))}catch(e){return k(Jk(e,`STL`))}}function $k(e){try{let t=U().exportIGES([e.wrapped]);return O(new Blob([t],{type:`application/iges`}))}catch(e){return k(vo(`IGES_EXPORT_FAILED`,`Failed to write IGES file`,e))}}function eA(e,t){let n=t?.coarseTolerance??.5,r=t?.fineTolerance??.05,i=t?.angularTolerance??.5;return{coarse:Kk(e,{tolerance:n,angularTolerance:i}),fine:Kk(e,{tolerance:r,angularTolerance:i*.2})}}function tA(e){let t=fD(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 nA(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)*tA(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 rA(e,t,n){return Math.min(e/t*n,1)}function iA(e,t={}){let n=t.angularTolerance??To().angularTolerance,r=t.cache??!0,i=nA(e,t),a=Math.min(...i);return i.map(i=>{let o=rA(i,a,n);return{tolerance:i,angularTolerance:o,mesh:Kk(e,{tolerance:i,angularTolerance:o,cache:r,...t.signal?{signal:t.signal}:{}})}})}function aA(){return new Promise(e=>{setTimeout(e,0)})}async function oA(e,t={}){let n=t.angularTolerance??To().angularTolerance,r=t.cache??!0,i=t.meshLevel??((e,n,i)=>Kk(e,{tolerance:n,angularTolerance:i,cache:r,...t.signal?{signal:t.signal}:{}})),a=nA(e,t),o=Math.min(...a),s=[];for(let[r,c]of a.entries()){if(t.signal?.aborted)break;let l=rA(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 aA()}return s}function sA(e,t,n){if(t<0||t>=e.length)throw Error(n??`Index ${t} out of bounds (length ${e.length})`);return e[t]}function cA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[0]}function lA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[e.length-1]}function uA(e){return Array.from(Array(e).keys())}function dA(e){return uA(Math.min(...e.map(e=>e.length))).map(t=>e.map(e=>e[t]))}function fA(e,t){return gE(U().makeLineEdge([...e],[...t]))}function pA(e,t=[0,0,0],n=[0,0,1]){return gE(U().makeCircleEdge([...t],[...n],e))}function mA(e,t,n=[0,0,0],r=[0,0,1],i){return t>e?k(F(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(gE(U().makeEllipseEdge([...n],[...r],e,t,i?[...i]:void 0)))}function hA(e,t,n,r=[0,0,0],i=[0,0,1],a=!1){return _E(U().makeHelixWire(e,t,n,[...r],[...i],a))}function gA(e,t,n){return gE(U().makeArcEdge([...e],[...t],[...n]))}function _A(e,t,n,r,i=[0,0,0],a=[0,0,1],o){return t>e?k(F(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(gE(U().makeEllipseArc([...i],[...a],e,t,n,r,o?[...o]:void 0)))}function vA(e,{tolerance:t=.001,smoothing:n=null,degMax:r=6,degMin:i=1}={}){try{let a=e.map(e=>[...e]);return O(gE(U().approximatePoints(a,{tolerance:t,degMin:i,degMax:r,smoothing:n})))}catch(e){return k(P(`BSPLINE_FAILED`,`B-spline approximation failed`,e))}}function yA(e,{periodic:t=!1,tolerance:n=1e-7}={}){try{let r=e.map(e=>[...e]);return O(gE(U().interpolatePoints(r,{periodic:t,tolerance:n})))}catch(e){return k(P(`BSPLINE_INTERP_FAILED`,`B-spline interpolation failed`,e))}}function bA(e){if(e.length<2)return k(F(`BEZIER_MIN_POINTS`,`Need at least 2 points for a Bezier curve, got ${e.length}`,void 0,{pointCount:e.length}));let t=e.map(e=>[...e]);return O(gE(U().makeBezierEdge(t)))}function xA(e,t,n){return gE(U().makeTangentArc([...e],[...t],[...n]))}function SA(e){try{return O(_E(U().makeWireFromMixed(e.map(e=>e.wrapped))))}catch(e){return k(P(`WIRE_BUILD_FAILED`,`Failed to build the wire: ${e instanceof Error?e.message:`unknown error`}`))}}function CA(e,t){try{let n=U().makeFace(e.wrapped,!0);if(t&&t.length>0){let e=DA(vE(n),t);return uE(e)?O(e):k(F(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}let r=vE(n);return uE(r)?O(r):k(F(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}catch(e){return k(P(`FACE_BUILD_FAILED`,`Failed to build the face. Your wire might be non planar.`,e))}}function wA(e){return CA(vO(e))}function TA(e,t){return vE(U().makeFaceOnSurface(e.wrapped,t.wrapped))}function EA(e){try{return Ha(nO(U().makeNonPlanarFace(e.wrapped)),e=>EE(e)?O(e):k(P(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`)))}catch(e){return k(P(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`,e))}}function DA(e,t){return vE(U().addHolesInFace(e.wrapped,t.map(e=>e.wrapped)))}function OA(e){try{var t=OT();if(e.length<3)return k(F(`POLYGON_MIN_POINTS`,`You need at least 3 points to make a polygon`));let n=[...e.slice(1),e[0]],r=t.u(new VT);return Ha(SA(dA([e,n]).map(([e,t])=>r.register(fA(e,t)))),e=>CA(r.register(e)))}catch(e){t.e=e}finally{t.d()}}function kA(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function AA(e,t,n,r,i){let a=ME(e);if(!AE(a)){let o=tE(a).toUpperCase();return PE(e,a),IE(a),k(ho(t,`${n}. Got ${o} instead.`,void 0,i?{diagnostics:i}:void 0,r))}return PE(e,a),O(a)}function jA(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=kA(e,`fuse: first operand`);if(A(c))return c;let l=kA(t,`fuse: second operand`);if(A(l))return l;if(!s)return AA(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);let u=QO([e,t]),{shape:d,evolution:f,diagnostics:p}=U().fuseWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(U().isNull(d))return U().dispose(d),console.warn(`brepjs: fuse history path produced null result; retrying without evolution tracking.`,p),AA(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);console.warn(`brepjs: fuse reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=AA(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&&$O(f,[e,t],m.value),m}function MA(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=kA(e,`cut: base`);if(A(c))return c;let l=kA(t,`cut: tool`);if(A(l))return l;if(!s)return AA(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);let u=QO([e,t]),{shape:d,evolution:f,diagnostics:p}=U().cutWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(U().isNull(d))return U().dispose(d),console.warn(`brepjs: cut history path produced null result; retrying without evolution tracking.`,p),AA(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);console.warn(`brepjs: cut reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=AA(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&&$O(f,[e,t],m.value),m}function NA(e,t,{simplify:n=!1,signal:r,fuzzyValue:i,unsafe:a,trackEvolution:o=!0}={}){if(r?.aborted)throw r.reason;let s=kA(e,`intersect: first operand`);if(A(s))return s;let c=kA(t,`intersect: second operand`);if(A(c))return c;if(!o)return AA(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);let l=QO([e,t]),{shape:u,evolution:d,diagnostics:f}=U().intersectWithHistory(e.wrapped,t.wrapped,l,G,{simplify:n,fuzzyValue:i});if(f.hasErrors){if(U().isNull(u))return U().dispose(u),console.warn(`brepjs: intersect history path produced null result; retrying without evolution tracking.`,f),AA(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);console.warn(`brepjs: intersect reported OCCT warnings/errors but produced a shape. Continuing with result.`,f)}let p=AA(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&&$O(d,[e,t],p.value),p}function PA(e,t,n,r,i,a,o,s){if(o?.aborted)throw o.reason;let c=n-t;if(c===1)return O(sA(e,t));if(c===2)return jA(sA(e,t),sA(e,t+1),{optimisation:r,simplify:!1,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}});let l=t+Math.ceil(c/2),u=PA(e,t,l,r,i,a,o,s);if(A(u))return u;let d=PA(e,l,n,r,i,a,o,s);return A(d)?d:jA(u.value,d.value,{optimisation:r,simplify:i,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}})}function FA(e,{optimisation:t=`none`,simplify:n=!1,strategy:r=`native`,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;if(e.length===0)return k(F(`FUSE_ALL_EMPTY`,`fuseAll requires at least one shape`));if(e.length===1)return O(cA(e));for(let t=0;t<e.length;t++){let n=kA(sA(e,t),`fuseAll: shape at index ${t}`);if(A(n))return n}if(r===`native`){let o=AA(U().fuseAll(e.map(e=>e.wrapped),{optimisation:t,simplify:n,strategy:r,fuzzyValue:a,...i?{signal:i}:{}}),`FUSE_ALL_NOT_3D`,`fuseAll did not produce a 3D shape`);return o.ok&&s&&ek(e,o.value),o}return PA(e,0,e.length,t,n,s,i,a)}function IA(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;if(t.length===0)return O(e);let c=kA(e,`cutAll: base`);if(A(c))return c;for(let e=0;e<t.length;e++){let n=kA(sA(t,e),`cutAll: tool at index ${e}`);if(A(n))return n}let l=[e,...t],u=AA(U().cutAll(e.wrapped,t.map(e=>e.wrapped),{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_ALL_NOT_3D`,`cutAll did not produce a 3D shape`);return u.ok&&s&&ek(l,u.value),u}function LA(e,t){let n=U(),r=ED(e.xDir,t),i=ED(e.yDir,t),a=ED(e.xDir,-t),o=ED(e.yDir,-t),s=e.origin,c=[...wD(wD(s,a),o)],l=[...wD(wD(s,r),o)],u=[...wD(wD(s,r),i)],d=[...wD(wD(s,a),i)],f=[n.makeLineEdge(c,l),n.makeLineEdge(l,u),n.makeLineEdge(u,d),n.makeLineEdge(d,c)],p=n.makeWire(f),m=n.makeFace(p,!0);for(let e of f)n.dispose(e);return n.dispose(p),m}function RA(e,t,{approximation:n=!0,planeSize:r=1e4}={}){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`section: shape is a null shape`));let i=LA(typeof t==`string`?j(WD(t)):t,r);try{return O(W(U().section(e.wrapped,i,n)))}catch(e){let n=e instanceof Error?e.message:String(e),r=typeof t==`string`?t:`custom`;return k(P(`SECTION_FAILED`,`Section with ${r} plane failed: ${n}`,e,{operation:`section`,plane:r},`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`))}finally{U().dispose(i)}}function zA(e){let t=U(),n=new Map,r=new Map;for(let i of e){let e=tD(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 BA(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 VA(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=BA(i,t,n);for(;o;)e===0?r.push(o.edge):r.unshift(o.edge),i=o.nextTip,o=BA(i,t,n)}return r}function HA(e){let t=U(),n=zA(e),r=new Set,i=[];for(let a of e){if(r.has(a))continue;let e=VA(a,n,r);try{let n=t.makeWire(e.map(e=>e.wrapped));i.push(W(n))}catch{}}return i}function UA(e){let t=U(),n=0,r=-1;for(let i=0;i<e.length;i++){let a=e[i];if(!a)continue;let o=t.boundingBox(a.wrapped),s=o.max[0]-o.min[0],c=o.max[1]-o.min[1],l=o.max[2]-o.min[2],u=s*s+c*c+l*l;u>r&&(r=u,n=i)}return n}function WA(e,t,n={}){let r=RA(e,t,n);if(!r.ok)return r;let i=eD(r.value);if(i.length===0){let e=QE(r.value);if(e.length===0)return k(P(`SECTION_FAILED`,`sectionToFace: section produced no geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));i.push(...HA(e))}if(i.length===0)return k(P(`SECTION_FAILED`,`sectionToFace: section produced no usable geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));let a=UA(i),o=sA(i,a),s=i.filter((e,t)=>t!==a);return CA(o,s.length>0?s:void 0)}function GA(e,t){if(t.length===0)return O(e);if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`split: shape is a null shape`));for(let e=0;e<t.length;e++)if(U().isNull(sA(t,e).wrapped))return k(F(N.NULL_SHAPE_INPUT,`splitShape: tool at index ${e} is a null shape`));try{return O(W(U().split(e.wrapped,t.map(e=>e.wrapped))))}catch(e){let n=e instanceof Error?e.message:String(e);return k(P(`SPLIT_FAILED`,`Split operation failed on ${t.length} tool(s): ${n}`,e,{operation:`split`,toolCount:t.length},`The splitting tools may not intersect the shape. Ensure tools cross through the shape's interior.`))}}function KA(e,t,n={}){let r=[];for(let i of t){let t=RA(e,i,n);if(A(t))return t;r.push(t.value)}return O(r)}function qA(e,t,n){if(t.length===0)return O(e);let r=n?.optimisation===`commonFace`?1:n?.optimisation===`sameFace`?2:0,i=U(),a=t.map(e=>({op:e.op,tool:e.tool.wrapped}));try{let o=i.booleanPipeline?.(e.wrapped,a,{glueMode:r});if(o===void 0)return JA(e,t,n);if(o===null)return k(P(`BOOLEAN_PIPELINE_FAILED`,`Boolean pipeline returned null shape`));let s=W(o);return AE(s)?O(s):(IE(s),k(ho(`BOOLEAN_PIPELINE_NOT_3D`,`Pipeline result is not a 3D shape`)))}catch(e){return k(P(`BOOLEAN_PIPELINE_FAILED`,e instanceof Error?e.message:String(e)))}}function JA(e,t,n){let r=e,i={...n?.optimisation?{optimisation:n.optimisation}:{},unsafe:!0};for(let e of t){let t=e.op===`fuse`?jA(r,e.tool,i):e.op===`cut`?MA(r,e.tool,i):NA(r,e.tool,i);if(A(t))return t;r=j(t)}return O(r)}function YA(e){return W(U().sew(e.map(e=>e.wrapped)))}function XA(e,t=!1){let n=YA(e);return!t&&!DE(n)?k(ho(`WELD_NOT_SHELL`,`Could not make a shell from faces and shells`)):O(n)}function ZA(e,t,n=[0,0,0],r=[0,0,1]){return bE(U().makeCylinder(e,t,[...n],[...r]))}function QA(e){return bE(U().makeSphere(e))}function $A(e,t,n,r=[0,0,0],i=[0,0,1]){return bE(U().makeCone(e,t,n,[...r],[...i]))}function ej(e,t,n=[0,0,0],r=[0,0,1]){return bE(U().makeTorus(e,t,[...n],[...r]))}function tj(e,t,n){return bE(U().makeEllipsoid(e,t,n))}function nj(e){return hE(U().makeVertex(e[0],e[1],e[2]))}function rj(e,t,n=1e-6){return Ha(eO(U().offset(e.wrapped,t,n)),e=>Ha(nO(e),e=>AE(e)?O(e):k(ho(`OFFSET_NOT_3D`,`Could not offset to a 3d shape`))))}function ij(e){return SE(U().makeCompound(e.map(e=>e.wrapped)))}function aj(e){try{var t=OT();let n=t.u(YA(e)),r=W(U().solidFromShell(n.wrapped));return OE(r)?O(r):(IE(r),k(ho(`SOLID_BUILD_FAILED`,`Could not make a solid of faces and shells`)))}catch(e){t.e=e}finally{t.d()}}function oj(e){return{position:e.vertices,normal:e.normals,index:e.triangles}}function sj(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 cj(e){return{position:e.lines}}function lj(e,t){return{coarse:oj(e.coarse),fine:oj(e.fine),coarseDistance:t?.coarse??50,fineDistance:t?.fine??0}}function uj(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:oj(e.mesh),distance:r?.[t]??(i-t)*n}))}function dj(e,t,n,r){if(t.length===0)return k(F(`CHAMFER_ANGLE_NO_EDGES`,`chamferDistAngle requires at least one edge`,void 0,{edgeCount:0}));if(n<=0)return k(F(`CHAMFER_ANGLE_BAD_DISTANCE`,`distance must be positive, got ${n}`,void 0,{distance:n}));if(r<=0||r>=90)return k(F(`CHAMFER_ANGLE_BAD_ANGLE`,`angleDeg must be in range (0, 90), got ${r}`,void 0,{angleDeg:r}));let i;try{let a=U(),o=t.map(e=>e.wrapped);i=a.chamferDistAngle(e.wrapped,o,n,r)}catch(e){return k(P(`CHAMFER_ANGLE_FAILED`,`chamferDistAngle kernel call failed: ${e instanceof Error?e.message:String(e)}`,e,{distance:n,angleDeg:r,edgeCount:t.length}))}let a=eO(i);if(A(a))return U().dispose(i),a;let o=W(a.value);return PE(i,o),AE(o)?O(o):(IE(o),k(ho(`CHAMFER_ANGLE_NOT_3D`,`chamferDistAngle did not produce a 3D shape`)))}function fj(e){let t=U();return t.getNurbsCurveData?t.getNurbsCurveData(e.wrapped):null}function pj(e){let t=U();return t.getNurbsSurfaceData?t.getNurbsSurfaceData(e.wrapped):null}var mj={cut:MA,cutAll:IA,fuse:jA,fuseAll:FA};function hj(e){return{totalInputs:e.totalInputs,batchAttempts:e.batchAttempts,batchSucceeded:e.batchSucceeded,singletonFallbacks:e.singletonFallbacks,failedInputs:[...e.failedInputs].sort((e,t)=>e-t)}}function gj(e,t,n={}){return _j(mj,e,t,n)}function _j(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=vj(e,t,n,0,r,i);return A(a)?a:O({shape:a.value,telemetry:hj(i)})}function vj(e,t,n,r,i,a){if(n.length===0)return O(t);if(n.length===1)return yj(e,t,n,r,i,a);a.batchAttempts++;let o=wj(()=>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=vj(e,t,n.slice(0,s),r,i,a);return c.ok?vj(e,c.value,n.slice(s),r+s,i,a):c}function yj(e,t,n,r,i,a){a.singletonFallbacks++;let o=cA(n),s=wj(()=>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 bj(e,t={}){return xj(mj,e,t)}function xj(e,t,n={}){if(n.signal?.aborted)throw n.signal.reason;if(t.length===0)return k(F(N.FUSE_ALL_EMPTY,`fuseAllBisect requires at least one shape`));let r={totalInputs:t.length,batchAttempts:0,batchSucceeded:0,singletonFallbacks:0,failedInputs:new Set},i=Sj(e,t,0,n,r);return A(i)?i:O({shape:i.value,telemetry:hj(r)})}function Sj(e,t,n,r,i){if(t.length===1)return O(cA(t));i.batchAttempts++;let a=wj(()=>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 Cj(e,Sj(e,t.slice(0,o),n,r,i),Sj(e,t.slice(o),n+o,r,i),t,n,o,r,i)}function Cj(e,t,n,r,i,a,o,s){if(t.ok&&n.ok){s.singletonFallbacks++;let c=wj(()=>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 wj(e){try{return e()}catch{return null}}function Tj(e,t,n){return U().checkBoolean(e.wrapped,t.wrapped,n)}function Ej(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Dj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Oj(e,t,n,r){let i=ME(e);if(!AE(i)){let a=tE(i).toUpperCase();return PE(e,i),IE(i),k(ho(t,`${n}. Got ${a} instead.`,void 0,void 0,r))}return PE(e,i),O(i)}function kj(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>r.get(U().hashCode(e,2147483647))??1}}function Aj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Ej(e,`fuseWithEvolution: first operand`);if(A(o))return o;let s=Ej(t,`fuseWithEvolution: second operand`);if(A(s))return s;let c=QO([e,t]),{shape:l,evolution:u}=U().fuseWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Oj(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?($O(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function jj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Ej(e,`cutWithEvolution: base`);if(A(o))return o;let s=Ej(t,`cutWithEvolution: tool`);if(A(s))return s;let c=QO([e,t]),{shape:l,evolution:u}=U().cutWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Oj(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?($O(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function Mj(e,t,{simplify:n=!1,signal:r,fuzzyValue:i}={}){if(r?.aborted)throw r.reason;let a=Ej(e,`intersectWithEvolution: first operand`);if(A(a))return a;let o=Ej(t,`intersectWithEvolution: second operand`);if(A(o))return o;let s=QO([e,t]),{shape:c,evolution:l}=U().intersectWithHistory(e.wrapped,t.wrapped,s,G,{simplify:n,fuzzyValue:i}),u=Oj(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?($O(l,[e,t],u.value),O({shape:u.value,evolution:l})):u}function Nj(e,t,n){let r=Dj(e,`filletWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(F(`INVALID_FILLET_RADIUS`,`Fillet radius must be positive`,void 0,void 0,`Provide a positive radius value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(F(`INVALID_FILLET_RADIUS`,`Fillet radii must both be positive`,void 0,void 0,`Both radius values must be greater than 0`));let i=t??QE(e);if(i.length===0)return k(F(N.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));try{let t,r;if(typeof n==`function`){let e=kj(i,n);if(!e)return k(F(N.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=QO([e]),{shape:o,evolution:s}=U().filletWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return AE(c)?($O(s,[e],c),O({shape:c,evolution:s})):(IE(c),k(P(N.FILLET_NOT_3D,`Fillet result is not a 3D shape`)))}catch(e){return k(P(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:i.length,radius:n}))}}function Pj(e,t,n){let r=Dj(e,`chamferWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(F(`INVALID_CHAMFER_DISTANCE`,`Chamfer distance must be positive`,void 0,void 0,`Provide a positive distance value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(F(`INVALID_CHAMFER_DISTANCE`,`Chamfer distances must both be positive`,void 0,void 0,`Both distance values must be greater than 0`));let i=t??QE(e);if(i.length===0)return k(F(N.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=kj(i,n);if(!e)return k(F(N.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=QO([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return AE(c)?($O(s,[e],c),O({shape:c,evolution:s})):(IE(c),k(P(N.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)))}catch(e){return k(P(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:i.length,distance:n}))}}function Fj(e,t,n,r=.001){let i=Dj(e,`shellWithEvolution: shape`);if(A(i))return i;if(n<=0)return k(F(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(F(`NO_FACES`,`At least one face must be specified for shell`));try{let i=QO([e]),{shape:a,evolution:o}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,i,G,r),s=W(a);return AE(s)?($O(o,[e],s),O({shape:s,evolution:o})):(IE(s),k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}catch(e){return k(P(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function Ij(e,t,n){try{let r=W(U().positionOnCurve(e.wrapped,t.wrapped,n));return AE(r)?O(r):(IE(r),k(P(N.POSITION_ON_CURVE_FAILED,`positionOnCurve did not produce a 3D shape`)))}catch(e){return k(P(N.POSITION_ON_CURVE_FAILED,`Failed to position shape on curve at param ${n}`,e))}}function Lj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Rj(e,t){if(typeof e==`number`&&e<=0)return k(F(t.code,t.scalar,void 0,void 0,t.scalarHint));if(Array.isArray(e)&&(e[0]<=0||e[1]<=0))return k(F(t.code,t.pair,void 0,void 0,t.pairHint))}function 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(U().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>{let t=r.get(U().hashCode(e,G));if(t===void 0)throw Error(`fillet/chamfer: edge hash not found — possible hash collision`);return t}}}function Bj(e,t,n,r,i){let a=W(t);return AE(a)?($O(e,n,a),O(a)):(IE(a),k(P(r,i)))}function Vj(e,t){if(typeof t!=`function`)return{filteredFaces:[...e],kernelAngle:t};let n=[],r=new Map;for(let i of e){let e=t(i);e===null||e===0||Math.abs(e)>=90||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return{filteredFaces:n,kernelAngle:e=>{let t=r.get(U().hashCode(e,G));if(t===void 0)throw Error(`draft: face hash not found — possible hash collision`);return t}}}function Hj(e,t){let n=Lj(e,`thicken: shape`);if(A(n))return n;try{let n=QO([e]),{shape:r,evolution:i}=U().thickenWithHistory(e.wrapped,t,n,G),a=W(r);return $O(i,[e],a),O(a)}catch(e){return k(P(`THICKEN_FAILED`,`Thicken operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function Uj(e,t,n){let r=Lj(e,`fillet: shape`);if(A(r))return r;let i=Rj(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??QE(e);if(a.length===0)return k(F(N.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));if(typeof n==`function`){let e=zj(a,n);return e?O({filteredEdges:e.edges,kernelRadius:e.kernelParam,selectedCount:a.length}):k(F(N.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`))}return O({filteredEdges:[...a],kernelRadius:n,selectedCount:a.length})}function Wj(e,t,n,{trackEvolution:r=!0}={}){let i=Uj(e,t,n);if(A(i))return i;let{filteredEdges:a,kernelRadius:o,selectedCount:s}=i.value;try{let t=a.map(e=>e.wrapped);if(!r){let n=W(U().fillet(e.wrapped,t,o));return AE(n)?O(n):k(P(N.FILLET_NOT_3D,`Fillet result is not a 3D shape`))}let n=QO([e]),{shape:i,evolution:s}=U().filletWithHistory(e.wrapped,t,o,n,G);return Bj(s,i,[e],N.FILLET_NOT_3D,`Fillet result is not a 3D shape`)}catch(e){return k(P(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:s,radius:n}))}}function Gj(e,t,n){let r=Lj(e,`chamfer: shape`);if(A(r))return r;let i=Rj(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??QE(e);if(a.length===0)return k(F(N.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=zj(a,n);if(!e)return k(F(N.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...a],r=n;let i=QO([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,i,G);return Bj(s,o,[e],N.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)}catch(e){return k(P(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:a.length,distance:n}))}}function Kj(e,t,n,r=.001,{trackEvolution:i=!0}={}){let a=Lj(e,`shell: shape`);if(A(a))return a;if(n<=0)return k(F(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(F(`NO_FACES`,`At least one face must be specified for shell`));try{if(!i){let i=W(U().shell(e.wrapped,t.map(e=>e.wrapped),n,r));return AE(i)?O(i):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}let a=QO([e]),{shape:o,evolution:s}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,a,G,r),c=W(o);return AE(c)?($O(s,[e],c),O(c)):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}catch(e){return k(P(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function qj(e,t,n=1e-6){let r=Lj(e,`offset: shape`);if(A(r))return r;if(Math.abs(t)<1e-10)return k(F(`ZERO_OFFSET`,`Offset distance cannot be zero`));try{let r=QO([e]),{shape:i,evolution:a}=U().offsetWithHistory(e.wrapped,t,r,G,n),o=W(i);return AE(o)?($O(a,[e],o),O(o)):k(P(`OFFSET_RESULT_NOT_3D`,`Offset result is not a 3D shape`))}catch(e){return k(P(`OFFSET_FAILED`,`Offset operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function Jj(e,t,n){let r=Lj(e,`draft: shape`);if(A(r))return r;if(typeof n==`number`){if(Math.abs(n)<1e-10)return k(F(N.DRAFT_INVALID_ANGLE,`Draft angle cannot be zero`,void 0,void 0,`Provide a non-zero angle in degrees`));if(Math.abs(n)>=90)return k(F(N.DRAFT_INVALID_ANGLE,`Draft angle must be between -90 and 90 degrees (exclusive)`,void 0,void 0,`Typical draft angles are 1-5 degrees for injection molding`))}if(t.length===0)return k(F(N.DRAFT_NO_FACES,`No faces specified for draft`,void 0,void 0,`Select at least one face to apply the draft angle to`))}function Yj(e,t,n,r,i){let a=Jj(e,t,i);if(a)return a;try{let{filteredFaces:a,kernelAngle:o}=Vj(t,i);if(a.length===0)return k(F(N.DRAFT_NO_FACES,`No faces with valid draft angle`,void 0,void 0,`Check that the angle callback returns non-zero values between -90 and 90 degrees`));let s=QO([e]),{shape:c,evolution:l}=U().draftWithHistory(e.wrapped,a.map(e=>e.wrapped),[n[0],n[1],n[2]],[r[0],r[1],r[2]],o,s,G);return Bj(l,c,[e],N.DRAFT_NOT_3D,`Draft result is not a 3D shape`)}catch(e){let n=e instanceof Error?e.message:String(e);return k(P(N.DRAFT_FAILED,`Draft operation failed: ${n}`,e,{operation:`draft`,faceCount:t.length,angle:i}))}}function Xj(e,t,n){if(n.length===0)return k(F(N.VARIABLE_FILLET_FAILED,`radii must contain at least one radius spec`));for(let e of n)if(e.radius<=0)return k(F(N.VARIABLE_FILLET_FAILED,`All radius values must be positive`));let r=U();try{let i=JSON.stringify({edge:r.hashCode(t.wrapped,G),radii:n.map(e=>({param:e.param,radius:e.radius}))}),a=W(r.filletVariable(e.wrapped,i));return AE(a)?OE(a)?O(a):(IE(a),k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a solid`))):(IE(a),k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a 3D shape`)))}catch(e){return k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet failed`,e))}}function Zj(e){return hD(e)}function Qj(e){if(!OE(e))return k(F(`NOT_A_SOLID`,`Input shape is not a solid`));let t=Zj(e);try{let n=U().healSolid(e.wrapped);if(!n)return t?O(e):k(P(N.HEAL_NO_EFFECT,`Solid healing had no effect — shape is still invalid`));let r=W(n);return OE(r)?(ZE(r),Zj(r)?O(r):(IE(r),k(P(`HEAL_SOLID_INCOMPLETE`,`Healed result is still invalid after ShapeFix_Solid`)))):(IE(r),k(P(`HEAL_RESULT_NOT_SOLID`,`Healed result is not a solid`)))}catch(e){return k(P(`HEAL_SOLID_FAILED`,`Solid healing failed`,e))}}function $j(e){if(!EE(e))return k(F(`NOT_A_FACE`,`Input shape is not a face`));try{let t=W(U().healFace(e.wrapped));return EE(t)?O(t):(IE(t),k(P(`HEAL_RESULT_NOT_FACE`,`Healed result is not a face`)))}catch(e){return k(P(`HEAL_FACE_FAILED`,`Face healing failed`,e))}}function eM(e,t){if(!TE(e))return k(F(`NOT_A_WIRE`,`Input shape is not a wire`));try{let n=W(U().healWire(e.wrapped,t?.wrapped));return TE(n)?O(n):(IE(n),k(P(`HEAL_RESULT_NOT_WIRE`,`Healed result is not a wire`)))}catch(e){return k(P(`HEAL_WIRE_FAILED`,`Wire healing failed`,e))}}function tM(e){return OE(e)?Qj(e):EE(e)?$j(e):TE(e)?eM(e):O(e)}function nM(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(Zj(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=eD(e).length,u=$E(e).length,d=e,f=!1,p=t=>{let n=d;d=t,n!==e&&n.wrapped!==t.wrapped&&IE(n)};if(o!==void 0)try{p(W(U().sew([d.wrapped],o))),s.push(`Applied sewing with tolerance ${o}`),c.push({name:`sew`,attempted:!0,succeeded:!0,detail:`tolerance=${o}`})}catch(e){let t=e instanceof Error?e.message:String(e);s.push(`Sewing failed: ${t}`),c.push({name:`sew`,attempted:!0,succeeded:!1,detail:t})}if(a&&n){let e=eD(d),t=0;for(let n of e)try{U().fixSelfIntersection(n.wrapped),t++}catch{}s.push(`Self-intersection fix: ${t}/${e.length} wires`),c.push({name:`fixSelfIntersection`,attempted:!0,succeeded:t>0,detail:`${t}/${e.length} wires fixed`})}if(OE(d)&&i||EE(d)&&r||TE(d)&&n){let t=tM(d);za(t)?(p(t.value),OE(e)?(f=!0,s.push(`Applied ShapeFix_Solid`),c.push({name:`healSolid`,attempted:!0,succeeded:!0})):EE(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=eD(d).length,h=$E(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=Zj(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 rM(e){try{return O(W(U().fixShape(e.wrapped)))}catch(e){return k(P(N.FIX_SHAPE_FAILED,`ShapeFix_Shape failed`,e))}}function iM(e){try{let t=W(U().solidFromShell(e.wrapped));return OE(t)?Zj(t)?O(t):(IE(t),k(P(N.SOLID_FROM_SHELL_FAILED,`solidFromShell produced an invalid solid`))):(IE(t),k(P(N.SOLID_FROM_SHELL_FAILED,`solidFromShell did not produce a solid`)))}catch(e){return k(P(N.SOLID_FROM_SHELL_FAILED,`Failed to create solid from shell`,e))}}function aM(e){try{let t=W(U().fixSelfIntersection(e.wrapped));return TE(t)?O(t):(IE(t),k(P(N.FIX_SELF_INTERSECTION_FAILED,`Result is not a wire`)))}catch(e){return k(P(N.FIX_SELF_INTERSECTION_FAILED,`Failed to fix wire self-intersection`,e))}}function oM(e,{profile:t,endFactor:n=1}){return e<1e-10?k(F(`INVALID_EXTRUSION_LENGTH`,`Extrusion length too small (< 1e-10)`)):t!==`s-curve`&&t!==`linear`?k(F(`UNSUPPORTED_PROFILE`,`Unsupported extrusion profile: ${String(t)}`)):O(U().buildExtrusionLaw(t,e,n).Trim(0,e,1e-6))}function sM(e,t){let n=U(),r=n.makeLineEdge([...e],[...t]),i=n.makeWire([r]);return n.dispose(r),W(i)}function cM(e,t,n,r,i,a=!1){return W(U().makeHelixWire(e,t,n,[...r],[...i],a))}function lM(e){let t=W(e.shape),n=W(e.firstShape),r=W(e.lastShape),i=()=>{IE(t),IE(n),IE(r)};return AE(t)?TE(n)?TE(r)?O([t,n,r]):(i(),k(ho(`SWEEP_END_NOT_WIRE`,`Sweep did not produce an end Wire`))):(i(),k(ho(`SWEEP_START_NOT_WIRE`,`Sweep did not produce a start Wire`))):(i(),k(ho(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function uM(e,t,n={},r=!1){if(n.mode===`simple`&&!r){let n=W(U().simplePipe(e.wrapped,t.wrapped));return AE(n)?O(n):(IE(n),k(ho(`SWEEP_NOT_3D`,`Simple pipe did not produce a 3D shape`)))}let{frenet:i=!1,auxiliarySpine:a,law:o=null,transitionMode:s=`right`,withContact:c,support:l,forceProfileSpineOthogonality:u,tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h}=n,g=U(),_=s===`round`?!0:!!u,v=g.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:s,contact:!!c,correction:_,frenet:i,shellMode:r,...a?.wrapped?{auxiliary:a.wrapped}:{},...o===null?{}:{law:o},...l===null?{}:{support:l},tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h});if(r&&typeof v==`object`&&`firstShape`in v)return lM(v);let y=W(v);return AE(y)?O(y):(IE(y),k(ho(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function dM(e,t,n,r){return uM(e,sM(t,wD(t,n)),{support:r})}function fM(e,t,n,r,i=!1){try{var a=OT();let o=AD(n);if(o<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let s=wD(t,n),c=a.u(sM(t,s)),l=null;if(r){let e=oM(o,r);if(A(e))return e;l=e.value}return uM(e,c,{law:l},i)}catch(e){a.e=e}finally{a.d()}}function pM(e,t,n,r,i,a=!1){try{var o=OT();if(Math.abs(t)<1e-10)return k(F(`ZERO_TWIST_ANGLE`,`Twist angle cannot be zero`));let s=AD(r);if(s<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let c=wD(n,r),l=o.u(sM(n,c)),u=t<0,d=360/Math.abs(t)*s,f=o.u(cM(d,s,1,n,r,u)),p=null;if(i){let e=oM(s,i);if(A(e))return e;p=e.value}return uM(e,l,{auxiliarySpine:f,law:p},a)}catch(e){o.e=e}finally{o.d()}}function mM(e){let t=e.map(e=>e.location);for(let e=0;e<t.length;e++){let n=t[e];if(n!==void 0&&(n<0||n>1))return F(N.MULTI_SWEEP_FAILED,`Section ${e} location ${n} is out of range [0, 1]`)}let n=t.filter(e=>e!==void 0);for(let e=1;e<n.length;e++)if((n[e]??0)<=(n[e-1]??0))return F(N.MULTI_SWEEP_FAILED,`Section locations must be strictly increasing`)}function hM(e,t,n){let[r,i]=n.curveParameters(t.wrapped),a=i-r,o=Array(e.length);for(let t=0;t<e.length;t++){let n=e[t]?.location;o[t]=n===void 0?NaN:r+n*a}let s=-1,c=r;for(let t=0;t<=e.length;t++){let n=t===e.length;if(!n&&!Number.isNaN(o[t]??NaN)||n){let e=n?i:o[t]??i,a=t-s-1;for(let t=1;t<=a;t++)o[s+t]=c+t/(a+1)*(e-c);n||(s=t,c=o[t]??r)}}for(let e=1;e<o.length;e++)if((o[e]??0)<=(o[e-1]??0))return k(F(N.MULTI_SWEEP_FAILED,`Computed section parameters are not strictly increasing at index ${e} (${o[e-1]?.toFixed(4)} >= ${o[e]?.toFixed(4)})`));return O(o)}function gM(e,t,n){if(e.length<2)return k(F(N.MULTI_SWEEP_INSUFFICIENT_SECTIONS,`Multi-section sweep requires at least 2 sections, got ${e.length}`));let{solid:r=!0,ruled:i=!1,tolerance:a=1e-6}=n??{},o=mM(e);if(o)return k(o);try{let n=U(),o=hM(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=W(n.loftAdvanced(l,{solid:r,ruled:i,tolerance:a}));return AE(o)?O(o):(IE(o),k(ho(`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(P(N.MULTI_SWEEP_FAILED,`Multi-section sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function _M(e,t,n,r={}){let{transition:i=`transformed`,solid:a=!0,tolerance:o}=r;try{let r=U(),s=!a,c=n.length>0?n[0]?.wrapped:void 0,l=r.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:i,...c?{auxiliary:c}:{},shellMode:s,...o===void 0?{}:{tolerance:o,boundTolerance:o}}),u=W(typeof l==`object`&&`shape`in l?l.shape:l);return AE(u)?O(u):(IE(u),k(ho(`GUIDED_SWEEP_NOT_3D`,`Guided sweep did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.GUIDED_SWEEP_FAILED,`Guided sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function vM(e,t){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`extrude: face is a null shape`));if(AD(t)<1e-10)return k(F(`EXTRUDE_ZERO_VECTOR`,`extrude: extrusion vector has zero length`));try{let n=U(),r=AD(t),i=ND(t),a=n.extrude(e.wrapped,[...i],r),o=bE(n.downcast(a,`solid`));return PE(a,o),O(o)}catch(e){return k(P(`EXTRUDE_FAILED`,`Extrusion operation failed`,e,{operation:`extrude`,vectorLength:AD(t)}))}}function yM(e,t=[0,0,0],n=[0,0,1],r=2*Math.PI){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`revolve: face is a null shape`));try{let i=W(U().revolveVec(e.wrapped,[...t],[...n],r));return AE(i)?O(i):(IE(i),k(ho(`REVOLUTION_NOT_3D`,`Revolution did not produce a 3D shape`)))}catch(e){return k(P(`REVOLVE_FAILED`,`Revolution operation failed`,e,{operation:`revolve`,angle:r}))}}function bM(e){if(e.length===0)return O([]);let t=U(),n=[];for(let t=0;t<e.length;t++){let r=e[t];if(!r)continue;let i=typeof r.height==`number`?[0,0,r.height]:r.height,a=AD(i);if(a<1e-10)return k(F(`EXTRUDE_ALL_ZERO_VECTOR`,`extrudeAll: entry ${t} has zero-length extrusion vector`));let o=[...ND(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=bE(t.downcast(e,`solid`));return PE(e,n),n}))}catch(e){return k(P(`EXTRUDE_ALL_FAILED`,`Batch extrusion operation failed`,e))}}function xM(e,{ruled:t=!0,startPoint:n,endPoint:r,tolerance:i=1e-6}={},a=!1){if(e.length===0&&!n&&!r)return k(F(`LOFT_EMPTY`,`Loft requires at least one wire or start/end point`));let o=U(),s=n?o.makeVertex(...bD(n)):void 0,c=r?o.makeVertex(...bD(r)):void 0;try{let n=W(o.loftAdvanced(e.map(e=>e.wrapped),{solid:!a,ruled:t,tolerance:i,...s?{startVertex:s}:{},...c?{endVertex:c}:{}}));return AE(n)?O(n):(IE(n),k(ho(`LOFT_NOT_3D`,`Loft did not produce a 3D shape`)))}catch(e){return k(P(`LOFT_FAILED`,`Loft operation failed`,e,void 0,`Common causes: wire profiles with different edge counts, self-intersecting result, or profiles too far apart. Ensure profiles are compatible and ordered.`))}}function SM(e){if(e.length===0)return O([]);let t=U(),n=[],r=e.map(e=>{let r=e.startPoint?t.makeVertex(...bD(e.startPoint)):void 0,i=e.endPoint?t.makeVertex(...bD(e.endPoint)):void 0;return r&&n.push(r),i&&n.push(i),{wires:e.wires.map(e=>e.wrapped),solid:!0,ruled:e.ruled??!0,tolerance:e.tolerance??1e-6,startVertex:r,endVertex:i}});try{let e=t.loftBatch?.(r)??r.map(e=>t.loftAdvanced(e.wires,{solid:e.solid,ruled:e.ruled,tolerance:e.tolerance,startVertex:e.startVertex,endVertex:e.endVertex})),n=[];for(let t of e){let e=W(t);if(!AE(e))return IE(e),k(ho(`LOFT_ALL_NOT_3D`,`Batch loft entry did not produce a 3D shape`));n.push(e)}return O(n)}catch(e){return k(P(`LOFT_ALL_FAILED`,`Batch loft operation failed`,e))}finally{for(let e of n)t.dispose(e)}}var CM=new WeakMap;function wM(e,t){return CM.get(e)?.get(t)}function TM(e,t,n){let r=CM.get(e);r||(r=new Map,CM.set(e,r)),r.set(t,n)}function EM(e){return U().isNull(e.wrapped)}function DM(e){return k(F(N.NULL_SHAPE_INPUT,`${e}: shape is a null shape`))}function OM(e){let t=wM(e.wrapped,`volume`);if(t)return O(t);if(EM(e))return DM(`measureVolumeProps`);let n=U(),r=n.shapeType(e.wrapped);if(r!==`solid`&&r!==`compsolid`&&r!==`compound`){let t={mass:0,volume:0,centerOfMass:[0,0,0]};return TM(e.wrapped,`volume`,t),O(t)}let i=n.volume(e.wrapped),a=UE(()=>n.centerOfMass(e.wrapped),N.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!a.ok)return a;let o={mass:i,volume:i,centerOfMass:a.value};return TM(e.wrapped,`volume`,o),O(o)}function kM(e){let t=wM(e.wrapped,`surface`);if(t)return O(t);if(EM(e))return DM(`measureSurfaceProps`);let n=U(),r=n.area(e.wrapped),i=UE(()=>n.centerOfMass(e.wrapped),N.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!i.ok)return i;let a={mass:r,area:r,centerOfMass:i.value};return TM(e.wrapped,`surface`,a),O(a)}function AM(e){let t=wM(e.wrapped,`linear`);if(t)return O(t);if(EM(e))return DM(`measureLinearProps`);let n=U(),r=n.length(e.wrapped),i={mass:r,length:r,centerOfMass:n.linearCenterOfMass(e.wrapped)};return TM(e.wrapped,`linear`,i),O(i)}function jM(e){let t=OM(e);return t.ok?O(t.value.mass):t}function MM(e){let t=kM(e);return t.ok?O(t.value.mass):t}function NM(e){let t=AM(e);return t.ok?O(t.value.mass):t}function PM(e,t){return EM(e)||EM(t)?DM(`measureDistance`):O(U().distance(e.wrapped,t.wrapped).value)}function FM(e,t){if(EM(e)||EM(t))return DM(`measureDistanceProps`);let n=U().distance(e.wrapped,t.wrapped);return O({distance:n.value,point1:n.point1,point2:n.point2})}function IM(e){if(EM(e))return DM(`createDistanceQuery`);let t=U().createDistanceQuery(e.wrapped);return O({distanceTo(e){return EM(e)?DM(`createDistanceQuery.distanceTo`):O(t.distanceTo(e.wrapped).value)},dispose(){t.dispose()}})}function LM(e,t,n){if(EM(e))return DM(`measureCurvatureAt`);let r=U().surfaceCurvature(e.wrapped,t,n);return O({mean:r.mean,gaussian:r.gaussian,maxCurvature:r.max,minCurvature:r.min,maxDirection:r.maxDirection,minDirection:r.minDirection})}function RM(e){if(EM(e))return DM(`measureCurvatureAtMid`);let t=uO(e),n=(t.uMin+t.uMax)/2,r=(t.vMin+t.vMax)/2,i=U().surfaceCurvature(e.wrapped,n,r);return O({mean:i.mean,gaussian:i.gaussian,maxCurvature:i.max,minCurvature:i.min,maxDirection:i.maxDirection,minDirection:i.minDirection})}function zM(e,t){return e.map(e=>zE(e,t))}function BM(e,t){let n=U(),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=RE(e,t);i.push(s),o?o.push(s.wrapped):a.set(r,[s.wrapped])}return i}function VM(e){let t=U(),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 HM(e,t,n){let r=U();return e.get(n)?.find(e=>r.isSame(e.wrapped,t))}function UM(e){let t=YE(e);if(t.edgeToFaces)return t.edgeToFaces;let n=U(),r=$E(e),i=VM(QE(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=HM(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 WM(e){let t=YE(e);if(t.vertexToFaces)return t.vertexToFaces;let n=U(),r=$E(e),i=VM(tD(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=HM(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 GM(e,t){let n=U(),r=UM(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 KM(e,t){let n=U(),r=WM(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 qM(e){return BM(e.wrapped,`edge`)}function JM(e){return BM(e.wrapped,`vertex`)}function YM(e){return BM(e.wrapped,`wire`)}function XM(e){return BM(e.wrapped,`vertex`)}function ZM(e,t){let n=U(),r=UM(e),i=BM(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 QM=new Map;function $M(e){let t=e instanceof Error?e.message:``;return/is only available with the|is not yet implemented|requires a registered occt kernel/.test(t)}function eN(e,t){let n=U(),r=_T()??``;if(QM.get(r)!==!1){let i;try{i=n.sharedEdges(e.wrapped,t.wrapped);let a=i.map(e=>RE(e,`edge`));return QM.set(r,!0),a}catch(e){if(i)for(let e of i)n.dispose(e);if(!$M(e))throw e;QM.set(r,!1)}}return tN(e,t)}function tN(e,t){let n=U(),r=n.iterShapes(e.wrapped,`edge`),i=n.iterShapes(t.wrapped,`edge`),a=new Map;for(let e of i){let t=n.hashCode(e,G),r=a.get(t);r||(r=[],a.set(t,r)),r.push(e)}let o=[];for(let e of r)a.get(n.hashCode(e,2147483647))?.some(t=>n.isSame(e,t))?o.push(RE(e,`edge`)):n.dispose(e);for(let e of i)n.dispose(e);return o}function nN(e,t){let n=0,r=sO(t);if(e.surfaceType!==void 0)if(r===e.surfaceType)n+=1;else return-1/0;if(e.normal!==void 0){let r=mO(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=hO(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=MM(t);if(r.ok&&r.value>0){let t=Math.abs(Math.log(e.area/r.value));t>1&&(n-=t)}}return n}function rN(e){let t=sO(e),n=mO(e),r=hO(e),i=MM(e);return{entityType:`face`,surfaceType:t,normal:n,centroid:r,area:i.ok?i.value:void 0}}var iN=.9;function aN(e){if(e[2]>iN)return`box:top`;if(e[2]<-.9)return`box:bottom`;if(e[1]>iN)return`box:back`;if(e[1]<-.9)return`box:front`;if(e[0]>iN)return`box:right`;if(e[0]<-.9)return`box:left`}function oN(e,t){if(sO(t)!==`PLANE`)return;let n=mO(t)[2];if(n>iN)return`${e}:top`;if(n<-.9)return`${e}:bottom`}function sN(e){return sO(e)===`CYLINDRE`?`cylinder:lateral`:oN(`cylinder`,e)}function cN(e){return sO(e)===`CONE`?`cone:lateral`:oN(`cone`,e)}function lN(e){return sO(e)===`SPHERE`?`sphere:surface`:void 0}var uN={box:e=>aN(mO(e)),cylinder:sN,cone:cN,sphere:lN};function dN(e,t){let n=new Map,r=uN[t],i=U(),a=0;for(let o of i.iterShapes(e.wrapped,`face`)){let e=LE(o,`face`);try{let i=r?.(e),o=i!==void 0&&!n.has(i)?i:`${t}:face_${a}`;n.set(o,[gk(e)]),a++}finally{FE(e,o)}}return n}function fN(e,t,n){return{origin:e,role:t,hint:rN(n)}}function pN(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 mN(e,t,n){let r=e.get(t);if(!r)return e;let i=new Map;for(let[e,t]of r){let r=pN(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 hN=.1,gN=.5;function _N(e,t,n){let r=-1/0,i,a=-1/0,o=[];for(let s of t){let t=n(e,s);t>gN&&o.push([s,t]),t>r?(a=r,r=t,i=s):t>a&&(a=t)}return i!==void 0&&r>gN?r-a<hN&&o.length>1?{kind:`ambiguous`,candidates:o.filter(([,e])=>e>=r-hN).map(([e])=>e)}:{kind:`match`,face:i}:{kind:`none`}}function vN(e,t,n,r){let i=$E(n),a=r??nN,o=t.get(e.origin)?.get(e.role);if(o!==void 0&&o.length>0){let t=i.filter(e=>o.includes(gk(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=_N(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=_N(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 yN(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 bN(e){if(e.length===0)return;let t=0,n=0,r=0;for(let i of e){let e=_D(i);t+=e[0],n+=e[1],r+=e[2]}let i=e.length;return[t/i,n/i,r/i]}function xN(e,t,n){let r=n.get(t);if(!r)return;let i=gk(e);for(let[e,t]of r)if(t.includes(i))return e}function SN(e,t,n,r){let i=r.get(t)?.get(n);return i===void 0||i.length===0?[]:$E(e).filter(e=>i.includes(gk(e)))}function CN(e){let t=NM(e);return{entityType:`edge`,length:t.ok?t.value:void 0,midpoint:bN(XM(e))}}function wN(e){let t=new Set,n=[];for(let r of e){let e=gk(r);t.has(e)||(t.add(e),n.push(r))}return n}var TN=1e-6;function EN(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=NM(a);n.ok&&(e+=Math.abs(n.value-t.length))}if(t.midpoint!==void 0){let n=bN(XM(a));n!==void 0&&(e+=yN(t.midpoint,n))}e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<TN))return n}function DN(e,t,n,r){let[i,a]=GM(n,t);if(i===void 0||a===void 0)return;let o=xN(i,e,r),s=xN(a,e,r);if(!(o===void 0||s===void 0))return{origin:e,faceRoles:[o,s],hint:CN(t)}}function ON(e,t,n){let[r,i]=e.faceRoles,a=SN(n,e.origin,r,t),o=SN(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(...eN(e,t));let c=wN(s);if(c.length===1){let[e]=c;if(e!==void 0)return{edge:e,confidence:`exact`}}if(c.length>1){let t=EN(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 kN=3,AN=1e-6;function jN(e,t){let n=new Set;for(let r of e)for(let e of JM(r)){let r=gk(e);n.add(r),t.has(r)||t.set(r,e)}return n}function MN(e,t){let n=new Set;for(let r of e)t.has(r)&&n.add(r);return n}function NN(e){let t=new Map,n;for(let r of e){let e=jN(r,t);n=n===void 0?e:MN(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 PN(e,t){if(t.position===void 0)return;let n,r=1/0,i=1/0;for(let a of e){let e=yN(_D(a),t.position);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<AN))return n}function FN(e,t,n,r){let i=KM(n,t);if(i.length<kN)return;let a=new Set;for(let t of i){let n=xN(t,e,r);n!==void 0&&a.add(n)}if(!(a.size<kN))return{origin:e,faceRoles:[...a].sort(),hint:{entityType:`vertex`,position:_D(t)}}}function IN(e,t,n){let r=[];for(let i of e.faceRoles){let a=SN(n,e.origin,i,t);if(a.length===0)return{ref:e,reason:`not-found`};r.push(a)}let i=NN(r);if(i.length===1){let[e]=i;if(e!==void 0)return{vertex:e,confidence:`exact`}}if(i.length>1){let t=PN(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 LN=.99,RN=.1,zN=1e-6;function BN(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function VN(e,t){return $E(e).filter(e=>BN(mO(e),t)>LN)}function HN(e,t,n){let r=new Set([...t,...n].map(gk)),i=new Set;for(let n of t)for(let t of ZM(e,n))i.add(gk(t));let a=[],o=new Set;for(let t of n)for(let n of ZM(e,t)){let e=gk(n);r.has(e)||o.has(e)||!i.has(e)||(o.add(e),a.push(n))}return a}function UN(e,t){let n,r=1/0,i=1/0;for(let a of e){let e=yN(hO(a),t);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<zN))return n}function WN(e,t,n,r,i){let[a,o]=GM(r,n);if(a===void 0||o===void 0)return;let s=xN(a,e,i),c=xN(o,e,i);if(!(s===void 0||c===void 0))return{origin:e,op:t,betweenRoles:[s,c],hint:{entityType:`derived-face`,normalA:mO(a),normalB:mO(o),edgeMidpoint:bN(XM(n))}}}function GN(e,t,n){let r=SN(n,e.origin,e.betweenRoles[0],t);r.length===0&&(r=VN(n,e.hint.normalA));let i=SN(n,e.origin,e.betweenRoles[1],t);if(i.length===0&&(i=VN(n,e.hint.normalB)),r.length===0||i.length===0)return{ref:e,reason:`not-found`};let a=HN(n,r,i).filter(t=>BN(mO(t),e.hint.normalA)>RN&&BN(mO(t),e.hint.normalB)>RN);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&&UN(a,e.hint.edgeMidpoint);return t?{face:t,confidence:`geometric-fallback`}:{ref:e,reason:`ambiguous`,candidates:a}}return{ref:e,reason:`not-found`}}function KN(e){return typeof e==`object`&&!!e&&`origin`in e}function qN(e){return KN(e)&&`betweenRoles`in e&&`op`in e}function JN(e){return KN(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length===2}function YN(e){return KN(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length>=3}function XN(e){return KN(e)&&typeof e.role==`string`}function ZN(e){return XN(e)||JN(e)||YN(e)||qN(e)}function QN(e,t){return t===void 0?{ok:!1,reason:e}:{ok:!1,reason:e,candidates:t}}function $N(e,t,n){if(qN(e)){let r=GN(e,t,n);return`face`in r?{ok:!0,entity:r.face}:QN(r.reason,r.candidates)}if(JN(e)){let r=ON(e,t,n);return`edge`in r?{ok:!0,entity:r.edge}:QN(r.reason,r.candidates)}if(YN(e)){let r=IN(e,t,n);return`vertex`in r?{ok:!0,entity:r.vertex}:QN(r.reason,r.candidates)}let r=vN(e,t,n);return`face`in r?{ok:!0,entity:r.face}:QN(r.reason,r.candidates)}function eP(e,t,n){let r=n.get(e.origin);if(r!==void 0)return r;let i=new Map([[e.origin,dN(t,e.origin)]]);return n.set(e.origin,i),i}function tP(e,t){return $N(e,eP(e,t,new Map),t)}function nP(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 rP(e,t){let n=new Map,r=e=>{if(ZN(e)){let r=$N(e,eP(e,t,n),t);return r.ok?r.entity:e}if(Array.isArray(e))return e.map(r);if(nP(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 iP(e,t,n,r){let i=bE(U().makeBox(e,t,n)),a=r?.at??(r?.centered?[0,0,0]:void 0);if(a)try{var o=OT();return nk(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 aP(e,t,n){let r=n?.at??[0,0,0],i=n?.axis??[0,0,1],a=ZA(e,t,r,i);if(n?.centered)try{var o=OT();let e=[-i[0]*t*.5,-i[1]*t*.5,-i[2]*t*.5];return nk(o.u(a),e)}catch(e){o.e=e}finally{o.d()}return a}function oP(e,t){let n=QA(e);if(t?.at)try{var r=OT();return nk(r.u(n),t.at)}catch(e){r.e=e}finally{r.d()}return n}function sP(e,t,n,r){let i=r?.at??[0,0,0],a=r?.axis??[0,0,1],o=$A(e,t,n,i,a);if(r?.centered)try{var s=OT();let e=[-a[0]*n*.5,-a[1]*n*.5,-a[2]*n*.5];return nk(s.u(o),e)}catch(e){s.e=e}finally{s.d()}return o}function cP(e,t,n){return ej(e,t,n?.at??[0,0,0],n?.axis??[0,0,1])}function lP(e,t,n,r){let i=tj(e,t,n);if(r?.at)try{var a=OT();return nk(a.u(i),r.at)}catch(e){a.e=e}finally{a.d()}return i}function uP(e,t){return fA(e,t)}function dP(e,t){let n=t?.axis??[0,0,1];return pA(e,t?.at??[0,0,0],n)}function fP(e,t,n){let r=n?.axis??[0,0,1];return mA(e,t,n?.at??[0,0,0],r,n?.xDir)}function pP(e,t,n,r){return hA(e,t,n,r?.at??[0,0,0],r?.axis??[0,0,1],r?.lefthand??!1)}function mP(e,t,n){return gA(e,t,n)}function hP(e,t,n,r,i){let a=i?.axis??[0,0,1];return _A(e,t,n*vD,r*vD,i?.at??[0,0,0],a,i?.xDir)}function gP(e,t){return vA(e,t)}function _P(e){return bA(e)}function vP(e,t,n){return xA(e,t,n)}function yP(e){return SA(e)}function bP(e){return Ha(SA(e),e=>nE(e)?O(e):k(F(`WIRE_NOT_CLOSED`,`Assembled wire is not closed: start and end points do not coincide`)))}function xP(e,t){return CA(e,t)}function SP(e){return EA(e)}function CP(e,t){return TA(e,t)}function wP(e){return OA(e)}function TP(e){return nj(e)}function EP(e){return ij(e)}function DP(e){return aj(e)}function OP(e,t,n){return rj(e,t,n)}function kP(e,t){return XA(e,t)}function AP(e,t){return DA(e,t)}function jP(){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 MP(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??jP(),color:[a,o,s,c]}});return BT(U().createXCAFDocument(t))}function NP(e=[],{unit:t,modelUnit:n}={}){let r=e=>{let t=e;return t.indexOf(`#`)===0&&(t=t.slice(1)),t.length===3&&(t=t.replace(/([0-9a-f])/gi,`$1$1`)),[parseInt(t.substring(0,2),16),parseInt(t.substring(2,4),16),parseInt(t.substring(4,6),16)]},i=U(),a=e.map(({shape:e,name:t,color:n,alpha:i})=>{let[a,o,s]=r(n??`#f00`);return{shape:e.wrapped,name:t??jP(),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(vo(`STEP_EXPORT_FAILED`,`Failed to write STEP file`))}finally{o.delete()}}function PP(e,t,n,r,i){if(n<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(FD(t))return k(F(`PATTERN_ZERO_DIRECTION`,`Pattern direction cannot be zero`));let a=ND(t),o=U().linearPattern(e.wrapped,[...a],r,n).map(e=>W(e));try{return FA(o,{optimisation:`sameFace`,...i,unsafe:!0})}finally{for(let e of o)e[Symbol.dispose]()}}function FP(e,t,n,r=360,i=[0,0,0],a){if(n<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(FD(t))return k(F(`PATTERN_ZERO_AXIS`,`Pattern axis cannot be zero`));let o=r/n,s=U().circularPattern(e.wrapped,[...i],[...t],o,n).map(e=>W(e));try{return FA(s,{optimisation:`sameFace`,...a,unsafe:!0})}finally{for(let e of s)e[Symbol.dispose]()}}function IP(e,t,n,r,i,a,o,s){if(r<1||i<1)return k(F(`PATTERN_INVALID_COUNT`,`Grid pattern counts must be at least 1`));if(r===1&&i===1)return O(e);if(FD(t))return k(F(`PATTERN_ZERO_DIRECTION`,`Grid directionX cannot be zero`));if(FD(n))return k(F(`PATTERN_ZERO_DIRECTION`,`Grid directionY cannot be zero`));let c=U(),l=ND(t),u=ND(n);if(typeof c.gridPattern==`function`)return O(W(c.gridPattern(e.wrapped,[...l],[...u],a,o,r,i)));let d=PP(e,t,r,a,s);if(!d.ok)return d;let f=d.value,p=PP(f,n,i,o,s),m=p.ok&&p.value===f;return f!==e&&!m&&f[Symbol.dispose](),p}function LP(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 RP(e,t){return{...e,children:[...e.children,t]}}function zP(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 BP(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 VP(e,t){if(e.name===t)return e;for(let n of e.children){let e=VP(n,t);if(e)return e}}function HP(e,t,n=0){t(e,n);for(let r of e.children)HP(r,t,n+1)}function UP(e){let t=1;for(let n of e.children)t+=UP(n);return t}function WP(e){let t=[];return HP(e,e=>{e.shape&&t.push(e.shape)}),t}function GP(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function KP(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 qP(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function JP(e){return qP(KP(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function YP(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 XP(e,t){let n=t/2,r=Math.sin(n),i=qP(e);return[Math.cos(n),i[0]*r,i[1]*r,i[2]*r]}function ZP(e,t){let n=qP(e),r=qP(t),i=GP(n,r);if(i>=.999999999)return[1,0,0,0];if(i<=-.999999999)return XP(JP(n),Math.PI);let a=KP(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 QP(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 $P=Math.PI/180;function eF(e,t,n){return Math.min(n,Math.max(t,e))}function tF(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function nF(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 rF(e){return tF(nF(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function iF(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:tF(t),min:s,max:c,value:eF(n.value??0,s,c)}}function aF(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:tF(r.direction)},min:a.min,max:a.max,value:a.value,dofs:i}}function oF(e,t,n,r={}){return aF(`revolute`,e,t,n,[iF(`rotation`,n.direction,r,-180,180)])}function sF(e,t,n,r={}){return aF(`prismatic`,e,t,n,[iF(`translation`,n.direction,r,0,100)])}function cF(e,t,n,r={}){return aF(`cylindrical`,e,t,n,[iF(`rotation`,n.direction,r.rotation??{},-180,180),iF(`translation`,n.direction,r.translation??{},0,100)])}function lF(e,t,n,r={}){let i=tF(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?rF(i):tF(n)}else a=rF(i);let o=tF(nF(i,a));return aF(`planar`,e,t,{origin:n.origin,direction:i},[iF(`translation`,a,r.u??{},-100,100),iF(`translation`,o,r.v??{},-100,100),iF(`rotation`,i,r.rotation??{},-180,180)])}function uF(e,t,n,r={}){return aF(`spherical`,e,t,{origin:n,direction:[0,0,1]},[iF(`rotation`,[1,0,0],r.x??{},-180,180),iF(`rotation`,[0,1,0],r.y??{},-180,180),iF(`rotation`,[0,0,1],r.z??{},-180,180)])}function dF(e,t){let n=e.dofs.map((e,n)=>{let r=t[n];return r===void 0?e:{...e,value:eF(r,e.min,e.max)}}),r=n[0];return r?{...e,dofs:n,value:r.value}:{...e,dofs:n}}function fF(e,t){return dF(e,[t])}function pF(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=XP(t.axis,n*$P),i=YP(r,e);return{position:[e[0]-i[0],e[1]-i[1],e[2]-i[2]],rotation:r}}function mF(e,t=e.value){let n=Array.isArray(t)?t:void 0,r=n?void 0:t,i=e.axis.origin,a=gF;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=_F(a,pF(i,o,eF(s,o.min,o.max)))}return a}function hF(e,t){let n=e.joints??[];return{...e,joints:[...n,t]}}var gF={position:[0,0,0],rotation:[1,0,0,0]};function _F(e,t){let n=YP(e.rotation,t.position);return{position:[e.position[0]+n[0],e.position[1]+n[1],e.position[2]+n[2]],rotation:QP(e.rotation,t.rotation)}}function vF(e){let t=[];return HP(e,e=>{e.joints&&t.push(...e.joints)}),t}function yF(e,t={}){let n=[],r=new Set;HP(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,gF);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?_F(mF(n,i),n.offset):mF(n,i);a.set(n.child,_F(r,c))}}for(let e of o)a.has(e.child)||a.set(e.child,gF);return a}function bF(e){return vF(e).reduce((e,t)=>e+t.dofs.length,0)}var xF={position:[0,0,0],rotation:[1,0,0,0]};function SF(e,t){let n=YP(e.rotation,t);return[n[0]+e.position[0],n[1]+e.position[1],n[2]+e.position[2]]}function CF(e){return[e[0],-e[1],-e[2],-e[3]]}function wF(e,t){let[n,r,i,a]=QP(t,CF(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 TF(e,t){let n=[];HP(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 EF(e,t){return e[t]??0}function DF(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]=EF(e,a*n+t);i[a*r+n]=EF(t,a)}for(let e=0;e<n;e++){let t=e;for(let a=e+1;a<n;a++)Math.abs(EF(i,a*r+e))>Math.abs(EF(i,t*r+e))&&(t=a);if(Math.abs(EF(i,t*r+e))<1e-12)return null;if(t!==e)for(let n=e;n<r;n++){let a=EF(i,e*r+n);i[e*r+n]=EF(i,t*r+n),i[t*r+n]=a}let a=EF(i,e*r+e);for(let t=e;t<r;t++)i[e*r+t]=EF(i,e*r+t)/a;for(let t=0;t<n;t++){if(t===e)continue;let n=EF(i,t*r+e);if(n!==0)for(let a=e;a<r;a++)i[t*r+a]=EF(i,t*r+a)-n*EF(i,e*r+a)}}let a=new Float64Array(n);for(let e=0;e<n;e++)a[e]=EF(i,e*r+n);return a}function OF(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 kF(e,t){let n={},r=0;for(let i of e){let e=[];for(let n=0;n<i.count;n++)e.push(EF(t,r++));n[i.child]=e}return n}function AF(e,t,n,r,i){let a=SF(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=wF(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+=EF(e,t)**2;return Math.sqrt(o)}function jF(e,t,n,r,i,a,o,s,c,l){let u=SF(o,s);for(let d=0;d<n;d++){let f=EF(t,d),p=f+c>EF(a,d)&&f-c>=EF(i,d)?-c:c;t[d]=f+p;let m=l(t);t[d]=f;let h=SF(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=wF(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 MF(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+=EF(e,t*n+r)*EF(e,i*n+r);a[t*r+i]=s+(t===i?o:0)}let s=DF(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+=EF(e,a*n+t)*EF(s,a);c[t]=i}return c}function NF(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}=OF(TF(e,t),r.seed),p=u.length,m=n=>yF(e,kF(l,n)).get(t)??xF,h=new Float64Array(c),g=new Float64Array(c*p),_=m(u),v=AF(h,_,n,s,c),y=0;for(;y<i&&p>0&&v>a;y++){jF(g,u,p,c,d,f,_,s,1e-6,m);let e=MF(g,h,p,c,o);if(!e)break;for(let t=0;t<p;t++){let n=EF(u,t)+EF(e,t);u[t]=Math.min(EF(f,t),Math.max(EF(d,t),n))}_=m(u),v=AF(h,_,n,s,c)}return{values:kF(l,u),converged:v<=a,iterations:y,error:v}}function PF(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 FF(e,t,n,r){let i=[];HP(e,e=>{e.joints&&i.push(...e.joints)});let a=i.map(e=>({child:e.child,a:PF(e,t[e.child]),b:PF(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:yF(e,r)})}return s}var IF=Math.PI/180;function LF(e,t,n,r){let i=e*IF,a=r*IF,o=QP(XP([0,0,1],i),XP([1,0,0],a));return{position:[n*Math.cos(i),n*Math.sin(i),t],rotation:o}}function RF(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=LF(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`?sF(i,a,s,c):oF(i,a,s,c),offset:o}})}var zF=Math.PI/180,BF=180/Math.PI;function VF(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function HF(e){return String(e===0?0:e)}function UF(e){return`${HF(e[0])} ${HF(e[1])} ${HF(e[2])}`}function WF(e,t={}){let n=t.name??`robot`,r=t.effort??0,i=t.velocity??0,a=t.meshes??{},o=[],s=[];HP(e,e=>{o.push(e.name),e.joints&&s.push(...e.joints)});for(let e of s){if(e.type!==`revolute`&&e.type!==`prismatic`)return k(F(N.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' is '${e.type}'; URDF supports only revolute and prismatic joints`));if(e.offset)return k(F(N.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' carries a fixed offset (e.g. a DH link) that URDF cannot represent as a single joint`))}let c=[`<?xml version="1.0"?>`,`<robot name="${VF(n)}">`];for(let e of o){let t=a[e];t?c.push(` <link name="${VF(e)}">`,` <visual><geometry><mesh filename="${VF(t)}"/></geometry></visual>`,` </link>`):c.push(` <link name="${VF(e)}"/>`)}for(let e of s){let t=e.type===`revolute`,n=t?e.min*zF:e.min,a=t?e.max*zF:e.max,o=e.type===`prismatic`?[0,0,0]:e.axis.origin;c.push(` <joint name="${VF(`${e.parent}_to_${e.child}`)}" type="${e.type}">`,` <parent link="${VF(e.parent)}"/>`,` <child link="${VF(e.child)}"/>`,` <origin xyz="${UF(o)}" rpy="0 0 0"/>`,` <axis xyz="${UF(e.axis.direction)}"/>`,` <limit lower="${HF(n)}" upper="${HF(a)}" effort="${HF(r)}" velocity="${HF(i)}"/>`,` </joint>`)}return c.push(`</robot>`,``),O(c.join(`
16
+ `))}function GF(e,t){return RegExp(`\\b${t}\\s*=\\s*"([^"]*)"`).exec(e)?.[1]}function KF(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 qF(e,t){return YP(QP(QP(XP([0,0,1],t[2]),XP([0,1,0],t[1])),XP([1,0,0],t[0])),e)}function JF(e){let t=/<robot\b([^>]*)>/.exec(e);if(!t)return k(F(N.VALIDATION_FAILED,`importURDF: no <robot> element found`));let n=GF(t[1]??``,`name`)??`robot`,r=[],i=/<link\b([^>]*?)(?:\/>|>)/g;for(let t=i.exec(e);t;t=i.exec(e)){let e=GF(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=GF(e,`type`)??`fixed`;if(r===`fixed`||r===`floating`||r===`planar`)continue;let i=/<parent\b([^>]*?)\/?>/.exec(n),o=/<child\b([^>]*?)\/?>/.exec(n),s=GF(i?.[1]??``,`link`),c=GF(o?.[1]??``,`link`);if(!s||!c)return k(F(N.VALIDATION_FAILED,`importURDF: joint missing parent/child link (${GF(e,`name`)??`unnamed`})`));let l=/<origin\b([^>]*?)\/?>/.exec(n),u=/<axis\b([^>]*?)\/?>/.exec(n),d=/<limit\b([^>]*?)\/?>/.exec(n),f=KF(GF(l?.[1]??``,`xyz`),[0,0,0]),p=KF(GF(l?.[1]??``,`rpy`),[0,0,0]),m=qF(KF(GF(u?.[1]??``,`xyz`),[1,0,0]),p),h=Number(GF(d?.[1]??``,`lower`)??NaN),g=Number(GF(d?.[1]??``,`upper`)??NaN);if(r===`prismatic`){let e=Number.isFinite(h)&&Number.isFinite(g)?{min:h,max:g}:{};a.push(sF(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*BF,max:g*BF};a.push(oF(s,c,{origin:f,direction:m},e))}else return k(F(N.VALIDATION_FAILED,`importURDF: joint '${GF(e,`name`)??`unnamed`}' has unrecognized type '${r}'`))}return O({name:n,links:r,joints:a})}function YF(){return{steps:[],shapes:new Map}}function XF(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 ZF(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 QF(e,t){return e.steps.find(e=>e.id===t)}function $F(e,t){return e.shapes.get(t)}function eI(e){return e.steps.length}function tI(e,t){let n=e.steps.findIndex(e=>e.id===t);return n===-1?[]:e.steps.slice(n)}function nI(e,t,n){let r=new Map(e.shapes);return r.set(t,n),{...e,shapes:r}}function rI(){return{operations:new Map}}function iI(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function aI(e,t){let[n,r]=t;return n!==void 0&&r===void 0&&AE(n)?rP(e,n):{...e}}function oI(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=nI(r,t,i));for(let n of e.steps){let e=t.operations.get(n.type);if(!e)return k(I(`REPLAY_UNKNOWN_OP`,`Unknown operation type: ${n.type}`));let i=[];for(let e of n.inputIds){let t=r.shapes.get(e);if(!t)return k(I(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${n.id}`));i.push(t)}try{let t=e(i,aI(n.parameters,i));r=XF(r,{id:n.id,type:n.type,parameters:n.parameters,inputIds:n.inputIds,outputId:n.outputId},t)}catch(e){return k(I(`REPLAY_STEP_FAILED`,`Step ${n.id} (${n.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(r)}function sI(e,t,n){let r=e.steps.findIndex(e=>e.id===t);if(r===-1)return k(I(`REPLAY_STEP_NOT_FOUND`,`Step not found: ${t}`));let i=new Map(e.shapes);for(let t=r;t<e.steps.length;t++){let n=e.steps[t];n&&i.delete(n.outputId)}let a={steps:e.steps.slice(0,r),shapes:i};for(let t=r;t<e.steps.length;t++){let r=e.steps[t];if(!r)continue;let i=n.operations.get(r.type);if(!i)return k(I(`REPLAY_UNKNOWN_OP`,`Unknown operation type: ${r.type}`));let o=[];for(let e of r.inputIds){let t=a.shapes.get(e);if(!t)return k(I(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${r.id}`));o.push(t)}try{let e=i(o,aI(r.parameters,o));a=XF(a,{id:r.id,type:r.type,parameters:r.parameters,inputIds:r.inputIds,outputId:r.outputId},e)}catch(e){return k(I(`REPLAY_STEP_FAILED`,`Step ${r.id} (${r.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(a)}function cI(e,t,n,r){return e.steps.findIndex(e=>e.id===t)===-1?k(I(`MODIFY_STEP_NOT_FOUND`,`Step not found: ${t}`)):sI({steps:e.steps.map(e=>e.id===t?{...e,parameters:n}:e),shapes:e.shapes},t,r)}function lI(e){let t={};for(let[n,r]of e.shapes){let e=hk(r);if(!e.ok)return k(I(`SERIALIZE_SHAPE_FAILED`,`Failed to serialize shape "${n}": ${e.error.message}`));t[n]=e.value}return O({steps:e.steps,shapes:t})}function uI(e){let t=new Map;for(let[n,r]of Object.entries(e.shapes))try{let e=iO(r);if(!e.ok)return k(I(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e.error.message}`));t.set(n,e.value)}catch(e){return k(I(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e instanceof Error?e.message:String(e)}`))}return O({steps:e.steps,shapes:t})}function dI(e){try{var t=OT();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(F(`THREAD_INVALID_RADIUS`,`radius must be > 0`));if(!(r>0))return k(F(`THREAD_INVALID_PITCH`,`pitch must be > 0`));if(!(i>0))return k(F(`THREAD_INVALID_HEIGHT`,`height must be > 0`));if(!(a>0))return k(F(`THREAD_INVALID_DEPTH`,`depth must be > 0`));if(s<0||s>=o)return k(F(`THREAD_INVALID_CREST`,`crest must be >= 0 and < toothHalfWidth`));if(c<3)return k(F(`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 VT),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=yP(f.map((e,t)=>_.register(uP(e,f[(t+1)%f.length]))));if(!za(y))return y;v.push(_.register(y.value))}return xM(v,{ruled:!0})}catch(e){t.e=e}finally{t.d()}}var fI=1e-9,pI=1e-8,mI=1e-6,hI=([e,t],[n,r],i=mI)=>Math.abs(e-n)<=i&&Math.abs(t-r)<=i,gI=([e,t],[n,r])=>[e+n,t+r],_I=([e,t],[n,r])=>[e-n,t-r],vI=([e,t],n)=>[e*n,t*n],yI=([e,t],[n,r]=[0,0])=>Math.sqrt((e-n)**2+(t-r)**2),bI=([e,t],[n,r]=[0,0])=>(e-n)**2+(t-r)**2;function xI([e,t],[n,r]){return e*r-t*n}var SI=([e,t],[n,r]=[0,0])=>Math.atan2(r*e-t*n,e*n+t*r),CI=([e,t],[n,r]=[0,0])=>Math.atan2(r-t,n-e),wI=(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 TI([e,t]){let n=Math.sqrt(e*e+t*t);return n<1e-12?[0,0]:[e/n,t/n]}var EI=(e,t)=>[Math.cos(t)*e,Math.sin(t)*e],DI=([e,t])=>[Math.sqrt(e*e+t*t),Math.atan2(t,e)],OI=([e,t])=>{let n=TI([e,t]);return n[0]===0&&n[1]===0&&M(`normalize2d`,`Cannot normalize zero-length vector`),n};function kI(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(yo(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found ${r===0?0:`2+`} element(s)`))}function AI(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 QE(t);case`face`:return $E(t);case`wire`:return eD(t);case`vertex`:return tD(t)}}let s=e=>{let n=o(e);return t.length===0?n.slice():n.filter(a)},c=()=>AI(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=gk(n),r=t.get(e);r?r.push(n):t.set(e,[n])}return i(e=>{let n=t.get(gk(e));return!!n&&n.some(t=>vk(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=>kI(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 jI={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function MI(e){return typeof e==`string`?jI[e]??[0,0,1]:e}function NI(e,t,n){let r=U(),i=r.makeVertex(t[0],t[1],t[2]);return t=>{let a=r.distance(i,t.wrapped).value;return Math.abs(a-e)<n}}function PI(e,t){let n=ND(MI(e));return e=>{let r=U(),[i,a]=r.curveParameters(e.wrapped),o=(i+a)/2,{tangent:s}=r.curveTangent(e.wrapped,o),c=ND(s),l=Math.acos(Math.min(1,Math.abs(OD(c,n))));return Math.abs(l-vD*t)<1e-6}}function FI(e){return AI(`edge`,e,FI,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(PI(e,t)),ofLength:(e,t=.001)=>n(n=>Math.abs(Ek(n)-e)<t),ofCurveType:e=>n(t=>xk(t)===e),parallelTo:(t=`Z`)=>FI(e).inDirection(t,0),atDistance:(e,t=[0,0,0])=>n(NI(e,t,1e-6))}))}function II(){return FI([])}function LI(e,t){let n=ND(MI(e));return e=>{let r=mO(e),i=Math.acos(Math.min(1,Math.abs(OD(ND(r),n))));return Math.abs(i-vD*t)<1e-6}}function RI(e){return AI(`face`,e,RI,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(LI(e,t)),parallelTo:(t=`Z`)=>RI(e).inDirection(t,0),ofSurfaceType:e=>n(t=>{let n=oO(t);return za(n)&&n.value===e}),ofArea:(e,t=.001)=>n(n=>{let r=MM(n);return za(r)&&Math.abs(r.value-e)<t}),atDistance:(e,t=[0,0,0])=>n(NI(e,t,1e-6))}))}function zI(){return RI([])}function BI(e){return AI(`wire`,e,BI,(e,t)=>({isClosed:()=>t(e=>Ok(e)),isOpen:()=>t(e=>!Ok(e)),ofEdgeCount:e=>t(t=>QE(t).length===e)}))}function VI(){return BI([])}function HI(e,t){return typeof e==`object`&&`_topoKind`in e?e.findUnique(t):typeof e!=`function`&&EE(e)?O(e):e(zI()).findUnique(t)}function UI(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`}function WI(e,t){let n=10**t,r=t<0?e:.01/n+e;return Math.round(r*n)/n}function GI(e){return Math.round(e*100)/100}function KI(e){return Math.round(e*1e5)/1e5}var qI=([e,t])=>`(${GI(e)},${GI(t)})`,JI=(e,t=1e-9)=>{let n=e;return Math.abs(e)<t&&(n=0),n.toFixed(-Math.log10(t))},YI=(e,t=1e-9)=>Array.from(new Map(e.map(([e,n])=>[`[${JI(e,t)},${JI(n,t)}]`,[e,n]])).values()),XI=class{_wrapped;_deleted=!1;constructor(e){this._wrapped=e??gT().createBoundingBox2d(),UT(this,this._wrapped)}get wrapped(){if(this._deleted)throw Error(`This object has been deleted`);return this._wrapped}delete(){this._deleted||(this._deleted=!0,WT(this._wrapped),typeof this._wrapped.delete==`function`&&this._wrapped.delete())}[Symbol.dispose](){this.delete()}get repr(){let[e,t]=this.bounds;return`${qI(e)} - ${qI(t)}`}get bounds(){let{xMin:e,yMin:t,xMax:n,yMax:r}=gT().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){gT().mergeBBox2d(this.wrapped,e.wrapped)}isOut(e){return gT().isBBox2dOut(this.wrapped,e.wrapped)}containsPoint(e){return!gT().isBBox2dOutPoint(this.wrapped,e[0],e[1])}};function ZI(e){return new QI(U().deserializeCurve2d(e))}var QI=class e{_wrapped;_deleted=!1;_boundingBox;_firstPoint=null;_lastPoint=null;_firstParameter=null;_lastParameter=null;constructor(e){this._wrapped=U().wrapCurve2dHandle(e),this._boundingBox=null,typeof this._wrapped.delete==`function`&&UT(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`&&(WT(this._wrapped),this._wrapped.delete()))}[Symbol.dispose](){this.delete()}get boundingBox(){if(this._boundingBox)return this._boundingBox;let e=U(),t=e.createBoundingBox2d();return e.addCurveToBBox2d(t,this.wrapped,1e-6),this._boundingBox=new XI(t),this._boundingBox}get repr(){return`${this.geomType} ${qI(this.firstPoint)} - ${qI(this.lastPoint)}`}serialize(){return U().serializeCurve2d(this.wrapped)}value(e){return U().evaluateCurve2d(this.wrapped,e)}get firstPoint(){return this._firstPoint===null&&(this._firstPoint=this.value(this.firstParameter)),this._firstPoint}get lastPoint(){return this._lastPoint===null&&(this._lastPoint=this.value(this.lastParameter)),this._lastPoint}get firstParameter(){return this._firstParameter===null&&(this._firstParameter=U().getCurve2dBounds(this.wrapped).first),this._firstParameter}get lastParameter(){return this._lastParameter===null&&(this._lastParameter=U().getCurve2dBounds(this.wrapped).last),this._lastParameter}get geomType(){return U().getCurve2dType(this.wrapped)}clone(){let t=new e(U().copyCurve2d(this.wrapped));return t._firstPoint=this._firstPoint,t._lastPoint=this._lastPoint,t._firstParameter=this._firstParameter,t._lastParameter=this._lastParameter,t}reverse(){U().reverseCurve2d(this.wrapped);let e=this._firstPoint;this._firstPoint=this._lastPoint,this._lastPoint=e;let t=this._firstParameter;this._firstParameter=this._lastParameter,this._lastParameter=t}distanceFromPoint(e){let t=U().projectPointOnCurve2d(this.wrapped,e[0],e[1]),n=t?t.distance:1/0;return Math.min(n,yI(e,this.firstPoint),yI(e,this.lastPoint))}distanceFromCurve(e){let t;try{t=U().distanceBetweenCurves2d(this.wrapped,e.wrapped,this.firstParameter,this.lastParameter,e.firstParameter,e.lastParameter)}catch{t=1/0}return Math.min(t,this.distanceFromPoint(e.firstPoint),this.distanceFromPoint(e.lastPoint),e.distanceFromPoint(this.firstPoint),e.distanceFromPoint(this.lastPoint))}distanceFrom(e){return UI(e)?this.distanceFromPoint(e):this.distanceFromCurve(e)}isOnCurve(e){return this.distanceFromPoint(e)<1e-9}parameter(e,t=1e-9){let n,r,i=!1;try{let t=U().projectPointOnCurve2d(this.wrapped,e[0],e[1]);t?(n=t.distance,r=t.param):i=!0}catch{i=!0}return i?hI(e,this.firstPoint,t)?O(this.firstParameter):hI(e,this.lastPoint,t)?O(this.lastParameter):k(I(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n===void 0||r===void 0?k(I(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n>t?k(I(`POINT_NOT_ON_CURVE`,`Point ${qI(e)} not on curve ${this.repr}, ${n.toFixed(9)}`)):O(r)}tangentAt(e){let t;if(Array.isArray(e))t=j(this.parameter(e));else{let n=U().getCurve2dBounds(this.wrapped);t=(n.last-n.first)*e+n.first}return U().evaluateCurve2dD1(this.wrapped,t).tangent}splitAt(n,r=1e-9){let i=n.map(e=>UI(e)?j(this.parameter(e,r)):e);i=Array.from(new Map(i.map(e=>[WI(e,-Math.log10(r)),e])).values()).sort((e,t)=>e-t);let a=this.firstParameter,o=this.lastParameter;return a>o&&i.reverse(),Math.abs(t(i,0)-a)<r*100&&(i=i.slice(1)),!i.length||(Math.abs(t(i,i.length-1)-o)<r*100&&(i=i.slice(0,-1)),!i.length)?[this]:U().splitCurve2d(this.wrapped,i).map(t=>new e(t))}},$I=(e,t=1e-4,n=`C0`,r=200)=>new QI(gT().approximateCurve2dAsBSpline(e.wrapped,t,n,r)),eL=e=>(e.geomType!==`BSPLINE_CURVE`&&M(`BSplineToBezier`,`You can only convert a Bspline`),gT().decomposeBSpline2dToBeziers(e.wrapped).map(e=>new QI(e)));function tL(e,t={tolerance:1e-4,continuity:`C0`,maxSegments:300}){let n=gT();return e.flatMap(e=>{let r=e.geomType;if(r===`ELLIPSE`||r===`CIRCLE`&&hI(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 tL(eL(r===`BSPLINE_CURVE`?e:$I(e,t.tolerance,t.continuity,t.maxSegments)),t)})}var nL=(e,t)=>{let n=new QI(U().makeLine2d(e[0],e[1],t[0],t[1]));return hI(n.firstPoint,e)||n.reverse(),n},rL=(e,t,n)=>{let r=new QI(U().makeArc2dThreePoints(e[0],e[1],t[0],t[1],n[0],n[1]));if(!hI(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new QI(e)}return r},iL=(e,t,n)=>{let r=new QI(U().makeArc2dTangent(e[0],e[1],t[0],t[1],n[0],n[1]));if(!hI(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new QI(e)}return r},aL=(e,t=[0,0])=>new QI(U().makeCircle2d(t[0],t[1],e,!0)),oL=(e,t,n=[1,0],r=[0,0],i=!0)=>new QI(U().makeEllipse2d(r[0],r[1],e,t,n[0],n[1],i)),sL=(e,t,n,r,i=[0,0],a,o=!0)=>new QI(U().makeEllipseArc2d(i[0],i[1],e,t,n,r,a[0],a[1],o)),cL=(e,t,n)=>{let r=[[e[0],e[1]],...t.map(e=>[e[0],e[1]]),[n[0],n[1]]];return new QI(U().makeBezier2d(r))};function lL(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 QI(U().makeBSpline2d(a,{tolerance:t,smoothing:n,degMax:r,degMin:i,continuity:`C2`})))}catch(e){return k(I(`BSPLINE_2D_FAILED`,`B-spline approximation failed`,e))}}var uL=(e,t,n,r=!1)=>{let i=vI(gI(e,t),.5),a=yI(n,e)*(r?-1:1);return rL(e,gI(vI(OI(_I(i,n)),a),n),t)},dL=(e,n)=>{let r=gT(),i=e.geomType,[a,o]=n,s=`${KI(a)} ${KI(o)}`;if(i===`LINE`)return`L ${s}`;if(i===`BEZIER_CURVE`){let n=r.getCurve2dBezierPoles(e.wrapped);n||M(`adaptedCurveToPathElem`,`Expected Bezier poles`);let i=n.length-1;if(i===1)return`L ${s}`;if(i===2){let[e,r]=t(n,1);return`Q ${GI(e)} ${GI(r)} ${s}`}if(i===3){let[e,r]=t(n,1),[i,a]=t(n,2);return`C ${GI(e)} ${GI(r)} ${GI(i)} ${GI(a)} ${s}`}}if(i===`CIRCLE`){let t=r.getCurve2dCircleData(e.wrapped);t||M(`adaptedCurveToPathElem`,`Expected circle data`);let{radius:n,isDirect:i}=t,c=r.getCurve2dBounds(e.wrapped),l=(c.last-c.first)*yD,u=l===360?`${KI(a)} ${KI(o+1e-4)}`:s;return`A ${n} ${n} 0 ${Math.abs(l)>180?`1`:`0`} ${i?`1`:`0`} ${u}`}if(i===`ELLIPSE`){let t=r.getCurve2dEllipseData(e.wrapped);t||M(`adaptedCurveToPathElem`,`Expected ellipse data`);let{majorRadius:n,minorRadius:i,xAxisAngle:c,isDirect:l}=t,u=r.getCurve2dBounds(e.wrapped),d=(u.last-u.first)*yD,f=d===360?`${KI(a)} ${KI(o+1e-4)}`:s,p=180-c*yD;return`A ${KI(n)} ${KI(i)} ${KI(p)} ${Math.abs(d)>180?`1`:`0`} ${l?`1`:`0`} ${f}`}M(`adaptedCurveToPathElem`,`Unsupported curve type: ${i}`)},fL=e=>{let t=U(),n=t.createBoundingBox2d();return e.forEach(e=>{t.addCurveToBBox2d(n,e.wrapped,1e-6)}),new XI(n)};function pL(e,t){let n=U();return e.map(e=>gE(n.liftCurve2dToPlane(e.wrapped,[...t.origin],[...t.zDir],[...t.xDir])))}var mL=(e,t)=>{let n=U();return e.map(e=>gE(n.buildEdgeOnSurface(e.wrapped,t)))},hL=(e,t)=>{let n=U();return e.map(e=>t?new QI(n.transformCurve2dGeneral(e.wrapped,t)):e.clone())},gL=(e,t,n=[0,0])=>U().createAffinityGTrsf2d(n[0],n[1],-t[1],t[0],e),_L=e=>U().createTranslationGTrsf2d(e[0],e[1]),vL=(e,t=[0,0],n=`center`)=>n===`center`?U().createMirrorGTrsf2d(e[0],e[1],`point`):U().createMirrorGTrsf2d(0,0,`axis`,t[0],t[1],e[0],e[1]),yL=(e,t=[0,0])=>U().createRotationGTrsf2d(e,t[0],t[1]),bL=(e,t=[0,0])=>U().createScaleGTrsf2d(e,t[0],t[1]);function xL(e,t,n=`original`){let r=U(),i=r.extractSurfaceFromFace(t.wrapped),a=uO(t),o=null;if(n===`original`&&sO(t)!==`PLANE`){if(sO(t)!==`CYLINDRE`)return k(F(`UNSUPPORTED_FACE_TYPE`,`Only planar and cylindrical faces can be unwrapped for sketching`));let e=r.getSurfaceCylinderData(i);if(!e)return k(F(`UNSUPPORTED_FACE_TYPE`,`Could not extract cylinder data from face surface`));e.isDirect||(i=r.reverseSurfaceU(i)),o=gL(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=mL(hL(e,o),i);return o&&o.delete(),O(s)}function SL(e,t){let n=U(),r=new QI(n.extractCurve2dFromEdge(e.wrapped,t.wrapped));return jk(e)===`backward`&&n.reverseCurve2d(r.wrapped),r}var CL=(e,t=1)=>`${e.bounds[0][0]-t} ${-e.bounds[1][1]-t} ${e.width+2*t} ${e.height+2*t}`,wL=(e,t,n=1)=>`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${CL(t,n)}" fill="none" stroke="black" stroke-width="0.6%" vector-effect="non-scaling-stroke">
17
17
  ${e}
18
- </svg>`;function bL(e){let t=e.map(e=>e.wrapped);return gE(U().makeWire(t))}var xL=class e{curves;_boundingBox;_orientation;_guessedOrientation;constructor(e){e.length===0&&M(`Blueprint`,`requires at least one curve — use createBlueprint() for Result-based validation`),this.curves=e,this._boundingBox=null,this._orientation=null,this._guessedOrientation=null}delete(){this.curves.forEach(e=>{e.delete()}),this._boundingBox&&this._boundingBox.delete()}[Symbol.dispose](){this.delete()}clone(){return new e(this.curves.map(e=>e.clone()))}get repr(){return[`Blueprint`,...this.curves.map(e=>e.repr)].join(`
19
- `)}get boundingBox(){return this._boundingBox||=sL(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=aA(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=uL(this.curves,dL(t,n,r));return new e(i)}scale(t,n){let r=n||this.boundingBox.center,i=uL(this.curves,hL(t,r));return new e(i)}rotate(t,n){let r=uL(this.curves,mL(t*gD,n));return new e(r)}translate(t,n=0){let r=RI(t)?t:[t,n],i=uL(this.curves,fL(r));return new e(i)}mirror(t,n=[0,0],r=`center`){let i=uL(this.curves,pL(t,n,r));return new e(i)}sketchOnPlane(e,t){let n=e&&typeof e!=`string`?{...e}:UD(e,t),r=cL(this.curves,n),i=bL(r);for(let e of r)e[Symbol.dispose]();return{wire:i,defaultOrigin:n.origin,defaultDirection:n.zDir}}sketchOnFace(e,t){let n=U(),r=j(gL(this.curves,e,t)),i=bL(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:gE(a),baseFace:e}}subFace(e,t){let n=vD(t||[...pO(e)]);return j(xA(this.translate(uO(e,n)).sketchOnFace(e,`original`).wire))}punchHole(e,t,{height:n=null,origin:r=null,draftAngle:i=0}={}){let a=j(LI(t,e)),o=this.subFace(a,r);return j(eO(U().draftPrism(e.wrapped,o.wrapped,a.wrapped,n,i,!1)))}toSVGPathD(){let e=this.clone().mirror([1,0],[0,0],`plane`),t=XI(e.curves).flatMap(e=>oL(e,e.lastPoint)),[n,r]=oA(e.curves).firstPoint;return`M ${VI(n)} ${VI(r)} ${t.join(` `)}${e.isClosed()?` Z`:``}`}toSVGPath(){return`<path d="${this.toSVGPathD()}" />`}toSVGViewBox(e=1){return vL(this.boundingBox,e)}toSVGPaths(){return[this.toSVGPathD()]}toSVG(e=1){return yL(this.toSVGPath(),this.boundingBox,e)}get firstPoint(){return oA(this.curves).firstPoint}get lastPoint(){return sA(this.curves).lastPoint}isInside(e){if(!this.boundingBox.containsPoint(e))return!1;let t=U(),n=ZI(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=>uI(t,e,1e-9))||(r.push(e),i++);for(let e of a.segments)e.delete()}),!!(i%2)}finally{n.delete()}}isClosed(){return uI(this.firstPoint,this.lastPoint)}intersects(e){if(this.boundingBox.isOut(e.boundingBox))return!1;let t=U();for(let n of this.curves)for(let r of e.curves){if(n.boundingBox.isOut(r.boundingBox))continue;let e=t.intersectCurves2d(n.wrapped,r.wrapped,1e-9);if(e.points.length||e.segments.length)return!0}return!1}},SL=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)}},CL=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],wL=3,TL=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!==wL)throw Error(`Got v${a} data when expected v${wL}.`);let o=CL[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=CL.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,(wL<<4)+c]),new Uint16Array(n,2,1)[0]=t,new Uint32Array(n,4,1)[0]=e}this._queue=new SL}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]=kL(d*((t+s)/2-n)|0,f*((o+c)/2-r)|0)}DL(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,EL(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 EL(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 DL(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;OL(e,t,n,d,f)}o.push(i,f,f+1,r)}}function OL(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 kL(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 AL=(e,t,n=1e-9)=>{if(e.boundingBox.isOut(t.boundingBox))return O({intersections:[],commonSegments:[],commonSegmentsPoints:[]});let r=gT(),i,a;try{let o=r.intersectCurves2d(e.wrapped,t.wrapped,n);i=o.points,a=o.segments.map(e=>new qI(e))}catch(e){return k(I(`INTERSECTION_FAILED`,`Intersections failed between curves`,e))}let o=a.filter(e=>uI(e.firstPoint,e.lastPoint,n)).map(e=>e.firstPoint);o.length&&(i.push(...o),a=a.filter(e=>!uI(e.firstPoint,e.lastPoint,n)));let s=a.flatMap(e=>[e.firstPoint,e.lastPoint]);return O({intersections:i,commonSegments:a,commonSegmentsPoints:s})},jL=(e,t=1e-9)=>{let n=gT(),r;try{let i=n.intersectCurves2d(e.wrapped,e.wrapped,t);r=i.points;for(let e of i.segments)e.delete()}catch(e){return k(I(`SELF_INTERSECTION_FAILED`,`Self intersection failed`,e))}return O(r)},ML=(e,n,r)=>{let i=CI(fI(n,e)),a=[i[1],-i[0]],o=[t(a,0)*r,t(a,1)*r];return{firstPoint:dI(e,o),lastPoint:dI(n,o)}},NL=(e,t)=>{let n=e.geomType,r=gT();if(n===`CIRCLE`){let n=r.getCurve2dCircleData(e.wrapped);if(!n)return ZI(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]=CI(fI(e,t));return dI(e,[c*n,c*r])};return{collapsed:!0,firstPoint:n(e.firstPoint),lastPoint:n(e.lastPoint)}}let u=new qI(r.makeCircle2d(i,a,l,s)),d;try{d=r.trimCurve2d(u.wrapped,e.firstParameter,e.lastParameter)}finally{u.delete()}return new qI(d)}if(n===`LINE`){let{firstPoint:n,lastPoint:r}=ML(e.firstPoint,e.lastPoint,t);return ZI(n,r)}let i=new qI(r.offsetCurve2d(e.wrapped,t)),a=JI(i);if(i.delete(),j(jL(a)).length){let e=a.firstPoint,t=a.lastPoint;return a.delete(),{collapsed:!0,firstPoint:e,lastPoint:t}}return a};function PL(e,n,r){let i=gI(e.tangentAt(1),n.tangentAt(0));if(Math.abs(i)<1e-10)return null;let a=Math.abs(r)*(i>0?-1:1),o=NL(e,a),s=NL(n,a);if(!(o instanceof qI)||!(s instanceof qI))return null;let c=AL(o,s,1e-9);if(!za(c))return null;let l=c.value.intersections.at(-1);if(!RI(l))return null;let u=l,d=(e,t)=>{let[n,r]=t.tangentAt(u),i=CI([-r,n]),o=dI(u,pI(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 FL(e,t,n){let r=PL(e,t,n);if(!r)return[e,t];let{first:i,second:a,center:o}=r;return[i,aL(i.lastPoint,a.firstPoint,o),a]}function IL(e,t,n){let r=PL(e,t,n);if(!r)return[e,t];let{first:i,second:a}=r;return[i,ZI(i.lastPoint,a.firstPoint),a]}function LL(e,n,r){let i=gI(CI(e.tangentAt(1)),CI(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=NL(e,s),l=NL(n,s);if(!(c instanceof qI)||!(l instanceof qI))return[e,n];let u=AL(c,l,1e-9);if(!za(u))return[e,n];let d=u.value.intersections.at(-1);if(!RI(d))return[e,n];let f=eL(r,d),p=j(AL(e,f)).intersections[0],m=j(AL(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[_,QI(_.lastPoint,e.lastPoint,v.firstPoint),v]}catch{return[e,n]}}var RL=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 GI;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 vL(this.boundingBox,e)}toSVGPaths(){return this.blueprints.map(e=>e.toSVGPaths())}toSVG(e=1){return yL(this.blueprints.map(e=>e instanceof xL?e.toSVGPath():e.toSVGGroup()).join(`
21
- `),this.boundingBox,e)}},zL=class e{blueprints;_boundingBox;constructor(e){e.length===0&&M(`CompoundBlueprint`,`requires at least one blueprint (the outer boundary) — use createCompoundBlueprint() for Result-based validation`),this.blueprints=e,this._boundingBox=null}clone(){return new e(this.blueprints.map(e=>e.clone()))}get boundingBox(){if(!this._boundingBox){let e=new GI;this.blueprints.forEach(t=>{e.add(t.boundingBox)}),this._boundingBox=e}return this._boundingBox}get repr(){return[`Compound Blueprints`,`-- Outline`,oA(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 oA(this.blueprints).punchHole(e,t,n)}toSVGViewBox(e=1){return vL(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 yL(this.toSVGGroup(),this.boundingBox,e)}},BL=e=>{if(e.length===0)return[];if(e.length===1)return[[xo(e,0,`groupByBoundingBoxOverlap`)]];let t=new TL(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(xo(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(xo(e,n,`groupByBoundingBoxOverlap`)),t.length&&t.forEach(e=>{i[e]=a})}),r},VL=e=>e.map((t,n)=>{let r=xo(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))}}),HL=(e,t)=>e.flatMap(({blueprint:e})=>WL(t.filter(({blueprint:t,isIn:n})=>t===e||n.indexOf(e)!==-1))),UL=(e,t)=>[t.filter(({isIn:e})=>e.length<=1),...WL(VL(e.map(({blueprint:e})=>e)))],WL=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?HL(t,e):UL(n,e)},GL=e=>new RL(BL(e).map(VL).flatMap(WL).map(e=>e.length===1?xo(e,0,`organiseBlueprints`).blueprint:(e.sort((e,t)=>e.isIn.length-t.isIn.length),new zL(e.map(({blueprint:e})=>e))))),KL=e=>e===`symmetric`||typeof e==`number`||Array.isArray(e)&&e.length===2,qL=e=>{let t;t=e?KL(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`?xI(1,n*gD):n;let s;return s=typeof a==`number`?xI(1,a*gD):a,{endTangent:o,startFactor:r,endFactor:i,startTangent:s}};function JL(e,t,n){return e<t?{majorRadius:t,minorRadius:e,rotationAngle:n+90}:{majorRadius:e,minorRadius:t,rotationAngle:n}}function YL(e,t,n,r,i,a,o,s){let c=i*gD,l=e=>mI(s(e)),u=l(xI(n,c)),d=l(xI(r,c+Math.PI/2)),f=CI(s(yI([1,0],c))),[,p]=SI(f),{cx:m,cy:h,startAngle:g,endAngle:_,clockwise:v,rx:y,ry:b}=QL(e,t,u,d,p,a,o),x=nL(y,b,v?g:_,v?_:g,[m,h],f);return v||x.reverse(),x}function XL(e,t,n,r,i){let a=Math.PI*2,o=ZL(1,0,e,t),s=ZL(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 ZL(e,t,n,r){let i=e*n+t*r,a=Math.sqrt((e*e+t*t)*(n*n+r*r));a<1e-12&&M(`radianAngle`,`Cannot compute angle between zero-length vectors`);let o=Math.acos(Math.max(-1,Math.min(1,i/a)));return e*r-t*n<0&&(o=-o),o}function QL([e,t],[n,r],i,a,o,s,c){i<0&&(i=-i),a<0&&(a=-a),(i<1e-10||a<1e-10)&&M(`convertSvgEllipseParams`,`rx and ry cannot be 0`);let l=Math.sin(o),u=Math.cos(o),d=(e-n)/2,f=(t-r)/2,p=(e+n)/2,m=(t+r)/2,h=u*d+l*f,g=u*f-l*d,_=h*h/(i*i)+g*g/(a*a);_>1&&(i*=Math.sqrt(_),a*=Math.sqrt(_));let v=i*a,y=i*g,b=a*h,x=y*y+b*b;x||M(`convertSvgEllipseParams`,`Start point cannot be same as end point`);let S=Math.sqrt(Math.abs((v*v-x)/x));s===c&&(S=-S);let C=S*y/a,w=-S*b/i,ee=u*C-l*w+p,te=l*C+u*w+m,ne=(h-C)/i,re=(h+C)/i,{startAngle:ie,deltaAngle:ae,endAngle:oe}=XL(ne,(g-w)/a,re,(g+w)/a,c);return{cx:ee,cy:te,startAngle:ie,deltaAngle:ae,endAngle:oe,clockwise:c,rx:i,ry:a}}var $L={chamfer:IL,dogbone:LL,fillet:FL};function eR(e,t){if(typeof e==`function`)return e;let n=$L[t];return(t,r)=>n(t,r,e)}var tR=class{pointer;firstPoint;pendingCurves;_nextCorner;constructor(e=[0,0]){this.pointer=e,this.firstPoint=e,this._nextCorner=null,this.pendingCurves=[]}_convertToUV([e,t]){return[e,t]}_convertFromUV([e,t]){return[e,t]}_lastCurve(){let e=this.pendingCurves.length;return e===0?null:this.pendingCurves[e-1]}_requireLastCurve(e,t){let n=this._lastCurve();return n||M(e,`You need a previous curve to ${t}`),n}_resolveRelative(e,t){return[this.pointer[0]+e,this.pointer[1]+t]}_saveCurveAndAdvance(e,t){return this.saveCurve(e),this.pointer=t,this}get penPosition(){return this.pointer}get penAngle(){let e=this._lastCurve();if(!e)return 0;let[t,n]=e.tangentAt(1);return Math.atan2(n,t)*_D}movePointerTo(e){return this.pendingCurves.length&&M(`Sketcher2d.movePointerTo`,`You can only move the pointer if there is no curve defined`),this.pointer=e,this.firstPoint=e,this}saveCurve(e){if(!this._nextCorner){this.pendingCurves.push(e);return}let t=this.pendingCurves.pop();t||M(`Sketcher2d.saveCurve`,`No previous curve available for custom corner`),this.pendingCurves.push(...this._nextCorner(t,e)),this._nextCorner=null}lineTo(e){let t=ZI(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(xI(e,t*gD))}polarLine(e,t){let[n,r]=xI(e,t*gD);return this.line(n,r)}tangentLine(e){let t=this._requireLastCurve(`Sketcher2d.tangentLine`,`sketch a tangent line`),n=CI(this._convertFromUV(t.tangentAt(1)));return this.line(n[0]*e,n[1]*e)}threePointsArcTo(e,t){let n=QI(this._convertToUV(this.pointer),this._convertToUV(t),this._convertToUV(e));return this._saveCurveAndAdvance(n,e)}threePointsArc(e,t,n,r){let[i,a]=this.pointer;return this.threePointsArcTo([i+e,a+t],[i+n,a+r])}sagittaArcTo(e,t){let[n,r]=this.pointer,[i,a]=e,o=(n+i)/2,s=(r+a)/2,c=-(a-r),l=i-n,u=Math.sqrt(c**2+l**2);u<1e-12&&M(`sagittaArcTo`,`Start and end points cannot be identical`);let d=[o+c/u*t,s+l/u*t],f=QI(this._convertToUV(this.pointer),this._convertToUV(d),this._convertToUV(e));return this._saveCurveAndAdvance(f,e)}sagittaArc(e,t,n){return this.sagittaArcTo(this._resolveRelative(e,t),n)}vSagittaArc(e,t){return this.sagittaArc(0,e,t)}hSagittaArc(e,t){return this.sagittaArc(e,0,t)}bulgeArcTo(e,t){if(!t)return this.lineTo(e);let n=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=$I(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}=JL(t,n,r),l=YL(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=vI(e,this.pointer),i=mI(e,this.pointer);return this.ellipseTo(e,i/2,t,r*_D,!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=rL(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}=qL(t),o=this._lastCurve(),s=mI(this.pointer,e)*.25,c;c=r||(o?this._convertFromUV(o.tangentAt(1)):[1,0]),c=CI(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=CI(u);let d=[e[0]-u[0]*a*s,e[1]-u[1]*a*s];return this.cubicBezierCurveTo(e,l,d)}smoothSpline(e,t,n){return this.smoothSplineTo(this._resolveRelative(e,t),n)}customCorner(e,t=`fillet`){return this.pendingCurves.length||M(`Sketcher2d.customCorner`,`You need a curve defined to fillet the angle`),this._nextCorner=eR(e,t),this}_customCornerLastWithFirst(e,t=`fillet`){if(!e)return;let n=this.pendingCurves.pop(),r=this.pendingCurves.shift();(!n||!r)&&M(`Sketcher2d._customCornerLastWithFirst`,`Not enough curves to close and fillet`),this.pendingCurves.push(...eR(e,t)(n,r))}_closeSketch(){uI(this.pointer,this.firstPoint)||this.lineTo(this.firstPoint)}_closeWithMirror(){uI(this.pointer,this.firstPoint)&&M(`Sketcher2d._closeWithMirror`,`Cannot close with a mirror when the sketch is already closed`);let e=[this.pointer[0]-this.firstPoint[0],this.pointer[1]-this.firstPoint[1]],t=this._convertToUV(this.pointer),n=this._convertToUV(e),r=this.pendingCurves.map(e=>new qI(U().mirrorCurve2dAcrossAxis(e.wrapped,t[0],t[1],n[0],n[1])));r.reverse();for(let e of r)e.reverse();this.pendingCurves.push(...r),this.pointer=this.firstPoint}},nR=class extends tR{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new xL(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()}},rR=2*Math.PI;function iR(e){let t=e%rR,n=t<0?t+rR:t;return n<Math.PI?n:n===Math.PI?0:Math.abs(n-rR)}function aR(e){return e.curves.map((t,n)=>({firstCurve:t,secondCurve:aA(e.curves,(n+1)%e.curves.length),point:t.lastPoint}))}function oR(e){let t=t=>oR([...e,t]),n=t=>e.every(e=>e(t));return{shouldKeep:n,when:e=>t(e),inList:e=>t(t=>e.some(e=>uI(e,t.point))),atDistance:(e,n=[0,0])=>t(t=>Math.abs(mI(n,t.point)-e)<1e-9),atPoint:e=>t(t=>uI(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(iR(_I(n,r))-iR(gD*e))<1e-9}),not:e=>{let n=e(oR([]));return t(e=>!n.shouldKeep(e))},either:e=>{let n=e.map(e=>e(oR([])));return t(e=>n.some(t=>t.shouldKeep(e)))},find:e=>aR(e).filter(n)}}function sR(){return oR([])}var cR=(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=sA(r),a=new nR().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()},lR=(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 nR([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()},uR=(e,t)=>uI(e,t,sI);function dR(e){return`${e[0].toFixed(9)},${e[1].toFixed(9)}`}function fR(e,t){let n=dR(e),r=dR(t);return n<r?`${n}|${r}`:`${r}|${n}`}function pR(e){let t=e[0];return t===void 0&&M(`startOfSegment`,`empty segment`),t.firstPoint}function mR(e){let t=e[e.length-1];return t===void 0&&M(`endOfSegment`,`empty segment`),t.lastPoint}function hR(e){return[...e].reverse().map(e=>{let t=e.clone();return t.reverse(),t})}function gR(e){return[...e].reverse().map(hR)}function _R(e){let t=(e.lastParameter+e.firstParameter)/2;return e.value(t)}function vR(e,t){let n=dR(t);for(let r=0;r<e.length;r++){let i=e[r];if(i!==void 0&&dR(i.firstPoint)===n&&uR(t,i.firstPoint))return r}for(let n=0;n<e.length;n++){let r=e[n];if(r!==void 0&&uR(t,r.firstPoint))return n}return-1}function yR(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i];if(a!==void 0&&dR(a.firstPoint)===t&&dR(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 bR(e,t){return t<=0?e:e.slice(t).concat(e.slice(0,t))}function xR(e,t){return bR(e,vR(e,t))}function SR(e,t){let n=dR(t.firstPoint),r=dR(t.lastPoint),i=e=>uR(t.firstPoint,e.firstPoint)&&uR(t.lastPoint,e.lastPoint),a=e=>uR(t.lastPoint,e.firstPoint)&&uR(t.firstPoint,e.lastPoint);function o(e,t,n,r){let i=yR(e,t,n,r);return i===-1?null:bR(e,i)}let s=o(e,n,r,i);if(s!==null)return s;let c=o(e,r,n,a);if(c!==null)return c;let l=hR(e),u=o(l,n,r,i);if(u!==null)return u;let d=o(l,r,n,a);if(d!==null)return d;M(`rotateToStartAtSegment`,`failed to rotate to segment start`)}function*CR(e,t,n){let r=new Set(t.map(dR)),i=new Set(n.map(e=>fR(e.firstPoint,e.lastPoint))),a=e=>r.has(dR(e))?!0:t.some(t=>uR(t,e)),o=(e,t)=>i.has(fR(e,t))?!0:n.some(n=>uR(n.firstPoint,e)&&uR(n.lastPoint,t)||uR(n.firstPoint,t)&&uR(n.lastPoint,e)),s=[];for(let t of e){if(uR(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 wR(e,t,n){return e.filter(e=>{let r=t.filter(t=>uR(t.firstPoint,e)||uR(t.lastPoint,e)),i=r.length%2?r.filter(t=>!(uR(t.firstPoint,e)&&uR(t.lastPoint,e))):r;if(i.length===0||i.length%2)return!1;let a=i.map(e=>n.isInside(_R(e)));return!(a.every(Boolean)||a.every(e=>!e))})}function TR(e,n){let r=[],i=[],a=e.curves.map(()=>[]),o=n.curves.map(()=>[]),s=new TL(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(AL(e,t(n.curves,s),sI/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:WI(r,sI),allCommonSegments:i,firstCurvePoints:a,secondCurvePoints:o}}function ER(e,t){return lA([e,t]).flatMap(([e,t])=>t.length===0?[e]:e.splitAt(t,sI/100))}function DR(e,t,n){return e.some(([e,r])=>e===void 0||r===void 0?!1:uR(e,t)&&uR(r,n)||uR(e,n)&&uR(r,t))}function OR(e,t){let{allIntersections:n,allCommonSegments:r,firstCurvePoints:i,secondCurvePoints:a}=TR(e,t);if(n.length<=1)return null;let o=ER(e.curves,i),s=ER(t.curves,a),c=r.map(e=>[e.firstPoint,e.lastPoint]),l=wR(wR(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=xR(o,e),s=xR(s,e)}else{let e=r[0];if(e===void 0)return null;o=SR(o,e),s=SR(s,e)}let u=Array.from(CR(o,l,r)),d=Array.from(CR(s,l,r)),f=u[0],p=d[0];if(f!==void 0&&p!==void 0){let e=!uR(mR(p),mR(f)),t=r.length>0&&p.length!==1;(e||t)&&(d=gR(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}DR(c,pR(t),mR(t))?h.push([t,`same`]):h.push([t,n])}return h}function kR(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`||!uR(a,n.firstPoint))break;let r=fI(a,i.firstPoint),s=fI(n.lastPoint,n.firstPoint);if(Math.abs(gI(r,s))>1e-9)break;a=n.lastPoint,o++}o>r+1?n.push(ZI(i.firstPoint,a)):n.push(i),r=o}return n}function AR(e){let t=e.map(e=>e.firstPoint),n=e.map(e=>e.lastPoint),r=lA([t,n.slice(-1).concat(n.slice(0,-1))]).map(([e,t],n)=>e===void 0||t===void 0||uR(e,t)?null:n).filter(e=>e!==null);if(r.length===0)return[e];let i=lA([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 jR(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 MR(e,t,n,r,i,a,o){let s=[],c=0,l=e[0];if(l!==void 0){let t=_R(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=_R(u),r=n.isInside(e);if(i.secondInside===`keep`&&r||i.secondInside===`remove`&&!r){let e=t;c===1&&(e=hR(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 NR(e,t,n){let r=OR(e,t);if(r===null)return PR(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=jR(r,i,a);return i=e.segmentsIn,a=e.lastWasSame,e.curves}let s=MR(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=AR(kR(o)).filter(e=>e.length>0).map(e=>new xL(e));if(c.length===0)return null;if(c.length===1){let e=c[0];return e===void 0?null:e}return GL(c)}function PR(e,t){let n=e.curves[0],r=t.curves[0];return{identical:!1,firstCurveInSecond:n!==void 0&&t.isInside(_R(n)),secondCurveInFirst:r!==void 0&&e.isInside(_R(r))}}function FR(e,t){let n=NR(e,t,{firstInside:`remove`,secondInside:`remove`});return n===null||n instanceof xL||n instanceof RL?n:n.identical?e.clone():n.firstCurveInSecond?t.clone():n.secondCurveInFirst?e.clone():new RL([e,t])}function IR(e,t){let n=NR(e,t,{firstInside:`remove`,secondInside:`keep`});return n===null||n instanceof xL||n instanceof RL?n:n.identical||n.firstCurveInSecond?null:n.secondCurveInFirst?new RL([new zL([e,t])]):e.clone()}function LR(e,t){let n=NR(e,t,{firstInside:`keep`,secondInside:`keep`});return n===null||n instanceof xL||n instanceof RL?n:n.identical||n.firstCurveInSecond?e.clone():n.secondCurveInFirst?t.clone():null}var RR=(e,t)=>{if(e instanceof xL&&t instanceof xL){let n=[];return e.curves.forEach(e=>{t.curves.forEach(t=>{let{intersections:r,commonSegmentsPoints:i}=j(AL(e,t));n.push(...r),n.push(...i)})}),n=WI(n),n.length>1}if(e instanceof zL||e instanceof RL)return e.blueprints.some(e=>RR(e,t));if(t instanceof zL||t instanceof RL)return t.blueprints.some(t=>RR(e,t));M(`genericIntersects`,`Unhandled shape combination in genericIntersects`)},zR=(e,t)=>{if(e instanceof zL){if(t instanceof xL)return HR(t,e);if(t instanceof zL)return WR(e,t)}if(t instanceof zL){if(e instanceof xL)return HR(e,t);if(e instanceof zL)return WR(e,t)}if(e instanceof xL&&t instanceof xL)return FR(e,t);M(`genericFuse`,`Unhandled shape combination in genericFuse`)},BR=e=>{let t=new Map,n=[];return e.forEach((r,i)=>{let a;t.has(i)?a=t.get(i):(a={current:r,fusedWith:new Set([i])},n.push(a)),e.slice(i+1).forEach((e,n)=>{let r=a.current,o=i+n+1;if(a.fusedWith.has(o))return;let s=e,c=!1;if(t.has(o)&&(s=t.get(o).current,c=!0),r.boundingBox.isOut(s.boundingBox)||!RR(r,s))return;let l;if(r instanceof RL||s instanceof RL){let e=GR(r,s);e===null&&M(`fuseIntersectingBlueprints`,`fuse2D returned null for non-null inputs`),l=e}else l=zR(r,s);if(!(l instanceof xL||l instanceof zL)){if(l instanceof RL&&l.blueprints.length===2)return;l instanceof RL&&l.blueprints.length===1?l=xo(l.blueprints,0,`fuseIntersectingBlueprints`):l instanceof RL||M(`fuseIntersectingBlueprints`,`Fuse produced unexpected non-blueprint result`)}a.fusedWith.add(o),a.current=l,c||t.set(o,a)})}),GL(n.map(({current:e})=>e).flatMap(e=>VR(e)))},VR=e=>e instanceof xL?[e]:e instanceof zL?e.blueprints:e instanceof RL?e.blueprints.flatMap(e=>VR(e)):[],HR=(e,t)=>{let n=FR(e,xo(t.blueprints,0,`fuseBlueprintWithCompound`)),r=t.blueprints.slice(1).map(t=>IR(t,e));return GL([...VR(n),...r.flatMap(e=>VR(e))])};function UR(e,t){let n=[];for(let r of e)for(let e of t)n.push([r,e]);return n}var WR=(e,t)=>{let n=xo(e.blueprints,0,`fuseCompoundWithCompound`),r=xo(t.blueprints,0,`fuseCompoundWithCompound`),i=FR(n,r),a=t.blueprints.slice(1).map(e=>IR(e,n)),o=e.blueprints.slice(1).map(e=>IR(e,r)),s=UR(e.blueprints.slice(1),t.blueprints.slice(1)).flatMap(([e,t])=>VR(LR(e,t)));return GL([...VR(i),...a.flatMap(e=>VR(e)),...o.flatMap(e=>VR(e)),...s])},GR=(e,t)=>{if(e===null)return t?.clone()??null;if(t===null)return e.clone();if(!(e instanceof RL)&&t instanceof RL)return BR([e,...t.blueprints]);if(!(t instanceof RL)&&e instanceof RL)return BR([t,...e.blueprints]);if(e instanceof RL&&t instanceof RL){let n=GR(xo(e.blueprints,0,`fuse2D`),t);return e.blueprints.slice(1).forEach(e=>{n=GR(e,n)}),n}if(e instanceof zL){if(t instanceof RL)return GR(t,e);if(t instanceof xL)return HR(t,e);if(t instanceof zL)return WR(e,t)}if(t instanceof zL){if(e instanceof RL)return GR(e,t);if(e instanceof xL)return HR(e,t);if(e instanceof zL)return WR(e,t)}return e instanceof xL&&t instanceof xL?FR(e,t):null},KR=e=>{let t=e.flatMap(e=>e===null?[]:e instanceof RL?e.blueprints:e);return t.length===1?xo(t,0,`mergeNonIntersecting`):new RL(t)},qR=(e,t)=>{if(e===null)return null;if(t===null)return e.clone();if(e instanceof RL)return KR(e.blueprints.map(e=>qR(e,t)));if(e instanceof zL){let n=xo(e.blueprints,0,`cut2D`);if(t instanceof xL&&!t.intersects(n))return n.isInside(t.firstPoint)?GL([n,...VR(GR(t,new RL(e.blueprints.slice(1))))]):e.clone();{let r=qR(n,t);return e.blueprints.slice(1).forEach(e=>{r=qR(r,e)}),r}}if(t instanceof RL){let n=e;for(let e of t.blueprints)n=qR(n,e);return n}if(t instanceof zL){let n=IR(e,xo(t.blueprints,0,`cut2D`));return t.blueprints.slice(1).forEach(t=>{n=GR(n,LR(t,e))}),n}return IR(e,t)};function JR(e,t){if(e===null||t===null)return null;if(e instanceof xL&&t instanceof xL)return LR(e,t);if(e instanceof RL)return KR(e.blueprints.map(e=>JR(e,t)));if(e instanceof zL){let n=xo(e.blueprints,0,`intersect2D`),r=e.blueprints.slice(1);if(r.length===0)return JR(n,t);let i=JR(n,t);for(let e of r)i=qR(i,e);return i}if(t instanceof RL)return KR(t.blueprints.map(t=>JR(e,t)));if(t instanceof zL){let n=xo(t.blueprints,0,`intersect2D`),r=t.blueprints.slice(1);if(r.length===0)return JR(n,e);let i=JR(n,e);for(let e of r)i=qR(i,e);return i}M(`intersect2D`,`Unhandled Shape2D combination`)}var YR=e(((e,t)=>{t.exports={}}));
18
+ </svg>`;function TL(e){let t=e.map(e=>e.wrapped);return _E(U().makeWire(t))}var EL=class e{curves;_boundingBox;_orientation;_guessedOrientation;constructor(e){e.length===0&&M(`Blueprint`,`requires at least one curve — use createBlueprint() for Result-based validation`),this.curves=e,this._boundingBox=null,this._orientation=null,this._guessedOrientation=null}delete(){this.curves.forEach(e=>{e.delete()}),this._boundingBox&&this._boundingBox.delete()}[Symbol.dispose](){this.delete()}clone(){return new e(this.curves.map(e=>e.clone()))}get repr(){return[`Blueprint`,...this.curves.map(e=>e.repr)].join(`
19
+ `)}get boundingBox(){return this._boundingBox||=fL(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=sA(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=hL(this.curves,gL(t,n,r));return new e(i)}scale(t,n){let r=n||this.boundingBox.center,i=hL(this.curves,bL(t,r));return new e(i)}rotate(t,n){let r=hL(this.curves,yL(t*vD,n));return new e(r)}translate(t,n=0){let r=UI(t)?t:[t,n],i=hL(this.curves,_L(r));return new e(i)}mirror(t,n=[0,0],r=`center`){let i=hL(this.curves,vL(t,n,r));return new e(i)}sketchOnPlane(e,t){let n=e&&typeof e!=`string`?{...e}:GD(e,t),r=pL(this.curves,n),i=TL(r);for(let e of r)e[Symbol.dispose]();return{wire:i,defaultOrigin:n.origin,defaultDirection:n.zDir}}sketchOnFace(e,t){let n=U(),r=j(xL(this.curves,e,t)),i=TL(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:_E(a),baseFace:e}}subFace(e,t){let n=bD(t||[...hO(e)]);return j(CA(this.translate(fO(e,n)).sketchOnFace(e,`original`).wire))}punchHole(e,t,{height:n=null,origin:r=null,draftAngle:i=0}={}){let a=j(HI(t,e)),o=this.subFace(a,r);return j(nO(U().draftPrism(e.wrapped,o.wrapped,a.wrapped,n,i,!1)))}toSVGPathD(){let e=this.clone().mirror([1,0],[0,0],`plane`),t=tL(e.curves).flatMap(e=>dL(e,e.lastPoint)),[n,r]=cA(e.curves).firstPoint;return`M ${KI(n)} ${KI(r)} ${t.join(` `)}${e.isClosed()?` Z`:``}`}toSVGPath(){return`<path d="${this.toSVGPathD()}" />`}toSVGViewBox(e=1){return CL(this.boundingBox,e)}toSVGPaths(){return[this.toSVGPathD()]}toSVG(e=1){return wL(this.toSVGPath(),this.boundingBox,e)}get firstPoint(){return cA(this.curves).firstPoint}get lastPoint(){return lA(this.curves).lastPoint}isInside(e){if(!this.boundingBox.containsPoint(e))return!1;let t=U(),n=nL(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=>hI(t,e,1e-9))||(r.push(e),i++);for(let e of a.segments)e.delete()}),!!(i%2)}finally{n.delete()}}isClosed(){return hI(this.firstPoint,this.lastPoint)}intersects(e){if(this.boundingBox.isOut(e.boundingBox))return!1;let t=U();for(let n of this.curves)for(let r of e.curves){if(n.boundingBox.isOut(r.boundingBox))continue;let e=t.intersectCurves2d(n.wrapped,r.wrapped,1e-9);if(e.points.length||e.segments.length)return!0}return!1}},DL=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)}},OL=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],kL=3,AL=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!==kL)throw Error(`Got v${a} data when expected v${kL}.`);let o=OL[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=OL.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,(kL<<4)+c]),new Uint16Array(n,2,1)[0]=t,new Uint32Array(n,4,1)[0]=e}this._queue=new DL}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]=PL(d*((t+s)/2-n)|0,f*((o+c)/2-r)|0)}ML(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,jL(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 jL(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 ML(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;NL(e,t,n,d,f)}o.push(i,f,f+1,r)}}function NL(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 PL(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 FL=(e,t,n=1e-9)=>{if(e.boundingBox.isOut(t.boundingBox))return O({intersections:[],commonSegments:[],commonSegmentsPoints:[]});let r=gT(),i,a;try{let o=r.intersectCurves2d(e.wrapped,t.wrapped,n);i=o.points,a=o.segments.map(e=>new QI(e))}catch(e){return k(I(`INTERSECTION_FAILED`,`Intersections failed between curves`,e))}let o=a.filter(e=>hI(e.firstPoint,e.lastPoint,n)).map(e=>e.firstPoint);o.length&&(i.push(...o),a=a.filter(e=>!hI(e.firstPoint,e.lastPoint,n)));let s=a.flatMap(e=>[e.firstPoint,e.lastPoint]);return O({intersections:i,commonSegments:a,commonSegmentsPoints:s})},IL=(e,t=1e-9)=>{let n=gT(),r;try{let i=n.intersectCurves2d(e.wrapped,e.wrapped,t);r=i.points;for(let e of i.segments)e.delete()}catch(e){return k(I(`SELF_INTERSECTION_FAILED`,`Self intersection failed`,e))}return O(r)},LL=(e,n,r)=>{let i=OI(_I(n,e)),a=[i[1],-i[0]],o=[t(a,0)*r,t(a,1)*r];return{firstPoint:gI(e,o),lastPoint:gI(n,o)}},RL=(e,t)=>{let n=e.geomType,r=gT();if(n===`CIRCLE`){let n=r.getCurve2dCircleData(e.wrapped);if(!n)return nL(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]=OI(_I(e,t));return gI(e,[c*n,c*r])};return{collapsed:!0,firstPoint:n(e.firstPoint),lastPoint:n(e.lastPoint)}}let u=new QI(r.makeCircle2d(i,a,l,s)),d;try{d=r.trimCurve2d(u.wrapped,e.firstParameter,e.lastParameter)}finally{u.delete()}return new QI(d)}if(n===`LINE`){let{firstPoint:n,lastPoint:r}=LL(e.firstPoint,e.lastPoint,t);return nL(n,r)}let i=new QI(r.offsetCurve2d(e.wrapped,t)),a=$I(i);if(i.delete(),j(IL(a)).length){let e=a.firstPoint,t=a.lastPoint;return a.delete(),{collapsed:!0,firstPoint:e,lastPoint:t}}return a};function zL(e,n,r){let i=xI(e.tangentAt(1),n.tangentAt(0));if(Math.abs(i)<1e-10)return null;let a=Math.abs(r)*(i>0?-1:1),o=RL(e,a),s=RL(n,a);if(!(o instanceof QI)||!(s instanceof QI))return null;let c=FL(o,s,1e-9);if(!za(c))return null;let l=c.value.intersections.at(-1);if(!UI(l))return null;let u=l,d=(e,t)=>{let[n,r]=t.tangentAt(u),i=OI([-r,n]),o=gI(u,vI(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 BL(e,t,n){let r=zL(e,t,n);if(!r)return[e,t];let{first:i,second:a,center:o}=r;return[i,uL(i.lastPoint,a.firstPoint,o),a]}function VL(e,t,n){let r=zL(e,t,n);if(!r)return[e,t];let{first:i,second:a}=r;return[i,nL(i.lastPoint,a.firstPoint),a]}function HL(e,n,r){let i=xI(OI(e.tangentAt(1)),OI(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=RL(e,s),l=RL(n,s);if(!(c instanceof QI)||!(l instanceof QI))return[e,n];let u=FL(c,l,1e-9);if(!za(u))return[e,n];let d=u.value.intersections.at(-1);if(!UI(d))return[e,n];let f=aL(r,d),p=j(FL(e,f)).intersections[0],m=j(FL(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[_,rL(_.lastPoint,e.lastPoint,v.firstPoint),v]}catch{return[e,n]}}var UL=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 XI;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 CL(this.boundingBox,e)}toSVGPaths(){return this.blueprints.map(e=>e.toSVGPaths())}toSVG(e=1){return wL(this.blueprints.map(e=>e instanceof EL?e.toSVGPath():e.toSVGGroup()).join(`
21
+ `),this.boundingBox,e)}},WL=class e{blueprints;_boundingBox;constructor(e){e.length===0&&M(`CompoundBlueprint`,`requires at least one blueprint (the outer boundary) — use createCompoundBlueprint() for Result-based validation`),this.blueprints=e,this._boundingBox=null}clone(){return new e(this.blueprints.map(e=>e.clone()))}get boundingBox(){if(!this._boundingBox){let e=new XI;this.blueprints.forEach(t=>{e.add(t.boundingBox)}),this._boundingBox=e}return this._boundingBox}get repr(){return[`Compound Blueprints`,`-- Outline`,cA(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 cA(this.blueprints).punchHole(e,t,n)}toSVGViewBox(e=1){return CL(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 wL(this.toSVGGroup(),this.boundingBox,e)}},GL=e=>{if(e.length===0)return[];if(e.length===1)return[[xo(e,0,`groupByBoundingBoxOverlap`)]];let t=new AL(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(xo(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(xo(e,n,`groupByBoundingBoxOverlap`)),t.length&&t.forEach(e=>{i[e]=a})}),r},KL=e=>e.map((t,n)=>{let r=xo(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))}}),qL=(e,t)=>e.flatMap(({blueprint:e})=>YL(t.filter(({blueprint:t,isIn:n})=>t===e||n.indexOf(e)!==-1))),JL=(e,t)=>[t.filter(({isIn:e})=>e.length<=1),...YL(KL(e.map(({blueprint:e})=>e)))],YL=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?qL(t,e):JL(n,e)},XL=e=>new UL(GL(e).map(KL).flatMap(YL).map(e=>e.length===1?xo(e,0,`organiseBlueprints`).blueprint:(e.sort((e,t)=>e.isIn.length-t.isIn.length),new WL(e.map(({blueprint:e})=>e))))),ZL=e=>e===`symmetric`||typeof e==`number`||Array.isArray(e)&&e.length===2,QL=e=>{let t;t=e?ZL(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`?EI(1,n*vD):n;let s;return s=typeof a==`number`?EI(1,a*vD):a,{endTangent:o,startFactor:r,endFactor:i,startTangent:s}};function $L(e,t,n){return e<t?{majorRadius:t,minorRadius:e,rotationAngle:n+90}:{majorRadius:e,minorRadius:t,rotationAngle:n}}function eR(e,t,n,r,i,a,o,s){let c=i*vD,l=e=>yI(s(e)),u=l(EI(n,c)),d=l(EI(r,c+Math.PI/2)),f=OI(s(wI([1,0],c))),[,p]=DI(f),{cx:m,cy:h,startAngle:g,endAngle:_,clockwise:v,rx:y,ry:b}=rR(e,t,u,d,p,a,o),x=sL(y,b,v?g:_,v?_:g,[m,h],f);return v||x.reverse(),x}function tR(e,t,n,r,i){let a=Math.PI*2,o=nR(1,0,e,t),s=nR(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 nR(e,t,n,r){let i=e*n+t*r,a=Math.sqrt((e*e+t*t)*(n*n+r*r));a<1e-12&&M(`radianAngle`,`Cannot compute angle between zero-length vectors`);let o=Math.acos(Math.max(-1,Math.min(1,i/a)));return e*r-t*n<0&&(o=-o),o}function rR([e,t],[n,r],i,a,o,s,c){i<0&&(i=-i),a<0&&(a=-a),(i<1e-10||a<1e-10)&&M(`convertSvgEllipseParams`,`rx and ry cannot be 0`);let l=Math.sin(o),u=Math.cos(o),d=(e-n)/2,f=(t-r)/2,p=(e+n)/2,m=(t+r)/2,h=u*d+l*f,g=u*f-l*d,_=h*h/(i*i)+g*g/(a*a);_>1&&(i*=Math.sqrt(_),a*=Math.sqrt(_));let v=i*a,y=i*g,b=a*h,x=y*y+b*b;x||M(`convertSvgEllipseParams`,`Start point cannot be same as end point`);let S=Math.sqrt(Math.abs((v*v-x)/x));s===c&&(S=-S);let C=S*y/a,w=-S*b/i,ee=u*C-l*w+p,te=l*C+u*w+m,ne=(h-C)/i,re=(h+C)/i,{startAngle:ie,deltaAngle:ae,endAngle:oe}=tR(ne,(g-w)/a,re,(g+w)/a,c);return{cx:ee,cy:te,startAngle:ie,deltaAngle:ae,endAngle:oe,clockwise:c,rx:i,ry:a}}var iR={chamfer:VL,dogbone:HL,fillet:BL};function aR(e,t){if(typeof e==`function`)return e;let n=iR[t];return(t,r)=>n(t,r,e)}var oR=class{pointer;firstPoint;pendingCurves;_nextCorner;constructor(e=[0,0]){this.pointer=e,this.firstPoint=e,this._nextCorner=null,this.pendingCurves=[]}_convertToUV([e,t]){return[e,t]}_convertFromUV([e,t]){return[e,t]}_lastCurve(){let e=this.pendingCurves.length;return e===0?null:this.pendingCurves[e-1]}_requireLastCurve(e,t){let n=this._lastCurve();return n||M(e,`You need a previous curve to ${t}`),n}_resolveRelative(e,t){return[this.pointer[0]+e,this.pointer[1]+t]}_saveCurveAndAdvance(e,t){return this.saveCurve(e),this.pointer=t,this}get penPosition(){return this.pointer}get penAngle(){let e=this._lastCurve();if(!e)return 0;let[t,n]=e.tangentAt(1);return Math.atan2(n,t)*yD}movePointerTo(e){return this.pendingCurves.length&&M(`Sketcher2d.movePointerTo`,`You can only move the pointer if there is no curve defined`),this.pointer=e,this.firstPoint=e,this}saveCurve(e){if(!this._nextCorner){this.pendingCurves.push(e);return}let t=this.pendingCurves.pop();t||M(`Sketcher2d.saveCurve`,`No previous curve available for custom corner`),this.pendingCurves.push(...this._nextCorner(t,e)),this._nextCorner=null}lineTo(e){let t=nL(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(EI(e,t*vD))}polarLine(e,t){let[n,r]=EI(e,t*vD);return this.line(n,r)}tangentLine(e){let t=this._requireLastCurve(`Sketcher2d.tangentLine`,`sketch a tangent line`),n=OI(this._convertFromUV(t.tangentAt(1)));return this.line(n[0]*e,n[1]*e)}threePointsArcTo(e,t){let n=rL(this._convertToUV(this.pointer),this._convertToUV(t),this._convertToUV(e));return this._saveCurveAndAdvance(n,e)}threePointsArc(e,t,n,r){let[i,a]=this.pointer;return this.threePointsArcTo([i+e,a+t],[i+n,a+r])}sagittaArcTo(e,t){let[n,r]=this.pointer,[i,a]=e,o=(n+i)/2,s=(r+a)/2,c=-(a-r),l=i-n,u=Math.sqrt(c**2+l**2);u<1e-12&&M(`sagittaArcTo`,`Start and end points cannot be identical`);let d=[o+c/u*t,s+l/u*t],f=rL(this._convertToUV(this.pointer),this._convertToUV(d),this._convertToUV(e));return this._saveCurveAndAdvance(f,e)}sagittaArc(e,t,n){return this.sagittaArcTo(this._resolveRelative(e,t),n)}vSagittaArc(e,t){return this.sagittaArc(0,e,t)}hSagittaArc(e,t){return this.sagittaArc(e,0,t)}bulgeArcTo(e,t){if(!t)return this.lineTo(e);let n=yI(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=iL(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}=$L(t,n,r),l=eR(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=CI(e,this.pointer),i=yI(e,this.pointer);return this.ellipseTo(e,i/2,t,r*yD,!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=cL(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}=QL(t),o=this._lastCurve(),s=yI(this.pointer,e)*.25,c;c=r||(o?this._convertFromUV(o.tangentAt(1)):[1,0]),c=OI(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=OI(u);let d=[e[0]-u[0]*a*s,e[1]-u[1]*a*s];return this.cubicBezierCurveTo(e,l,d)}smoothSpline(e,t,n){return this.smoothSplineTo(this._resolveRelative(e,t),n)}customCorner(e,t=`fillet`){return this.pendingCurves.length||M(`Sketcher2d.customCorner`,`You need a curve defined to fillet the angle`),this._nextCorner=aR(e,t),this}_customCornerLastWithFirst(e,t=`fillet`){if(!e)return;let n=this.pendingCurves.pop(),r=this.pendingCurves.shift();(!n||!r)&&M(`Sketcher2d._customCornerLastWithFirst`,`Not enough curves to close and fillet`),this.pendingCurves.push(...aR(e,t)(n,r))}_closeSketch(){hI(this.pointer,this.firstPoint)||this.lineTo(this.firstPoint)}_closeWithMirror(){hI(this.pointer,this.firstPoint)&&M(`Sketcher2d._closeWithMirror`,`Cannot close with a mirror when the sketch is already closed`);let e=[this.pointer[0]-this.firstPoint[0],this.pointer[1]-this.firstPoint[1]],t=this._convertToUV(this.pointer),n=this._convertToUV(e),r=this.pendingCurves.map(e=>new QI(U().mirrorCurve2dAcrossAxis(e.wrapped,t[0],t[1],n[0],n[1])));r.reverse();for(let e of r)e.reverse();this.pendingCurves.push(...r),this.pointer=this.firstPoint}},sR=class extends oR{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new EL(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()}},cR=2*Math.PI;function lR(e){let t=e%cR,n=t<0?t+cR:t;return n<Math.PI?n:n===Math.PI?0:Math.abs(n-cR)}function uR(e){return e.curves.map((t,n)=>({firstCurve:t,secondCurve:sA(e.curves,(n+1)%e.curves.length),point:t.lastPoint}))}function dR(e){let t=t=>dR([...e,t]),n=t=>e.every(e=>e(t));return{shouldKeep:n,when:e=>t(e),inList:e=>t(t=>e.some(e=>hI(e,t.point))),atDistance:(e,n=[0,0])=>t(t=>Math.abs(yI(n,t.point)-e)<1e-9),atPoint:e=>t(t=>hI(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(lR(SI(n,r))-lR(vD*e))<1e-9}),not:e=>{let n=e(dR([]));return t(e=>!n.shouldKeep(e))},either:e=>{let n=e.map(e=>e(dR([])));return t(e=>n.some(t=>t.shouldKeep(e)))},find:e=>uR(e).filter(n)}}function fR(){return dR([])}var pR=(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=lA(r),a=new sR().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()},mR=(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 sR([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()},hR=(e,t)=>hI(e,t,fI);function gR(e){return`${e[0].toFixed(9)},${e[1].toFixed(9)}`}function _R(e,t){let n=gR(e),r=gR(t);return n<r?`${n}|${r}`:`${r}|${n}`}function vR(e){let t=e[0];return t===void 0&&M(`startOfSegment`,`empty segment`),t.firstPoint}function yR(e){let t=e[e.length-1];return t===void 0&&M(`endOfSegment`,`empty segment`),t.lastPoint}function bR(e){return[...e].reverse().map(e=>{let t=e.clone();return t.reverse(),t})}function xR(e){return[...e].reverse().map(bR)}function SR(e){let t=(e.lastParameter+e.firstParameter)/2;return e.value(t)}function CR(e,t){let n=gR(t);for(let r=0;r<e.length;r++){let i=e[r];if(i!==void 0&&gR(i.firstPoint)===n&&hR(t,i.firstPoint))return r}for(let n=0;n<e.length;n++){let r=e[n];if(r!==void 0&&hR(t,r.firstPoint))return n}return-1}function wR(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i];if(a!==void 0&&gR(a.firstPoint)===t&&gR(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 TR(e,t){return t<=0?e:e.slice(t).concat(e.slice(0,t))}function ER(e,t){return TR(e,CR(e,t))}function DR(e,t){let n=gR(t.firstPoint),r=gR(t.lastPoint),i=e=>hR(t.firstPoint,e.firstPoint)&&hR(t.lastPoint,e.lastPoint),a=e=>hR(t.lastPoint,e.firstPoint)&&hR(t.firstPoint,e.lastPoint);function o(e,t,n,r){let i=wR(e,t,n,r);return i===-1?null:TR(e,i)}let s=o(e,n,r,i);if(s!==null)return s;let c=o(e,r,n,a);if(c!==null)return c;let l=bR(e),u=o(l,n,r,i);if(u!==null)return u;let d=o(l,r,n,a);if(d!==null)return d;M(`rotateToStartAtSegment`,`failed to rotate to segment start`)}function*OR(e,t,n){let r=new Set(t.map(gR)),i=new Set(n.map(e=>_R(e.firstPoint,e.lastPoint))),a=e=>r.has(gR(e))?!0:t.some(t=>hR(t,e)),o=(e,t)=>i.has(_R(e,t))?!0:n.some(n=>hR(n.firstPoint,e)&&hR(n.lastPoint,t)||hR(n.firstPoint,t)&&hR(n.lastPoint,e)),s=[];for(let t of e){if(hR(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 kR(e,t,n){return e.filter(e=>{let r=t.filter(t=>hR(t.firstPoint,e)||hR(t.lastPoint,e)),i=r.length%2?r.filter(t=>!(hR(t.firstPoint,e)&&hR(t.lastPoint,e))):r;if(i.length===0||i.length%2)return!1;let a=i.map(e=>n.isInside(SR(e)));return!(a.every(Boolean)||a.every(e=>!e))})}function AR(e,n){let r=[],i=[],a=e.curves.map(()=>[]),o=n.curves.map(()=>[]),s=new AL(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(FL(e,t(n.curves,s),fI/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:YI(r,fI),allCommonSegments:i,firstCurvePoints:a,secondCurvePoints:o}}function jR(e,t){return dA([e,t]).flatMap(([e,t])=>t.length===0?[e]:e.splitAt(t,fI/100))}function MR(e,t,n){return e.some(([e,r])=>e===void 0||r===void 0?!1:hR(e,t)&&hR(r,n)||hR(e,n)&&hR(r,t))}function NR(e,t){let{allIntersections:n,allCommonSegments:r,firstCurvePoints:i,secondCurvePoints:a}=AR(e,t);if(n.length<=1)return null;let o=jR(e.curves,i),s=jR(t.curves,a),c=r.map(e=>[e.firstPoint,e.lastPoint]),l=kR(kR(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=ER(o,e),s=ER(s,e)}else{let e=r[0];if(e===void 0)return null;o=DR(o,e),s=DR(s,e)}let u=Array.from(OR(o,l,r)),d=Array.from(OR(s,l,r)),f=u[0],p=d[0];if(f!==void 0&&p!==void 0){let e=!hR(yR(p),yR(f)),t=r.length>0&&p.length!==1;(e||t)&&(d=xR(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}MR(c,vR(t),yR(t))?h.push([t,`same`]):h.push([t,n])}return h}function PR(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`||!hR(a,n.firstPoint))break;let r=_I(a,i.firstPoint),s=_I(n.lastPoint,n.firstPoint);if(Math.abs(xI(r,s))>1e-9)break;a=n.lastPoint,o++}o>r+1?n.push(nL(i.firstPoint,a)):n.push(i),r=o}return n}function FR(e){let t=e.map(e=>e.firstPoint),n=e.map(e=>e.lastPoint),r=dA([t,n.slice(-1).concat(n.slice(0,-1))]).map(([e,t],n)=>e===void 0||t===void 0||hR(e,t)?null:n).filter(e=>e!==null);if(r.length===0)return[e];let i=dA([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 IR(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 LR(e,t,n,r,i,a,o){let s=[],c=0,l=e[0];if(l!==void 0){let t=SR(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=SR(u),r=n.isInside(e);if(i.secondInside===`keep`&&r||i.secondInside===`remove`&&!r){let e=t;c===1&&(e=bR(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 RR(e,t,n){let r=NR(e,t);if(r===null)return zR(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=IR(r,i,a);return i=e.segmentsIn,a=e.lastWasSame,e.curves}let s=LR(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=FR(PR(o)).filter(e=>e.length>0).map(e=>new EL(e));if(c.length===0)return null;if(c.length===1){let e=c[0];return e===void 0?null:e}return XL(c)}function zR(e,t){let n=e.curves[0],r=t.curves[0];return{identical:!1,firstCurveInSecond:n!==void 0&&t.isInside(SR(n)),secondCurveInFirst:r!==void 0&&e.isInside(SR(r))}}function BR(e,t){let n=RR(e,t,{firstInside:`remove`,secondInside:`remove`});return n===null||n instanceof EL||n instanceof UL?n:n.identical?e.clone():n.firstCurveInSecond?t.clone():n.secondCurveInFirst?e.clone():new UL([e,t])}function VR(e,t){let n=RR(e,t,{firstInside:`remove`,secondInside:`keep`});return n===null||n instanceof EL||n instanceof UL?n:n.identical||n.firstCurveInSecond?null:n.secondCurveInFirst?new UL([new WL([e,t])]):e.clone()}function HR(e,t){let n=RR(e,t,{firstInside:`keep`,secondInside:`keep`});return n===null||n instanceof EL||n instanceof UL?n:n.identical||n.firstCurveInSecond?e.clone():n.secondCurveInFirst?t.clone():null}var UR=(e,t)=>{if(e instanceof EL&&t instanceof EL){let n=[];return e.curves.forEach(e=>{t.curves.forEach(t=>{let{intersections:r,commonSegmentsPoints:i}=j(FL(e,t));n.push(...r),n.push(...i)})}),n=YI(n),n.length>1}if(e instanceof WL||e instanceof UL)return e.blueprints.some(e=>UR(e,t));if(t instanceof WL||t instanceof UL)return t.blueprints.some(t=>UR(e,t));M(`genericIntersects`,`Unhandled shape combination in genericIntersects`)},WR=(e,t)=>{if(e instanceof WL){if(t instanceof EL)return qR(t,e);if(t instanceof WL)return YR(e,t)}if(t instanceof WL){if(e instanceof EL)return qR(e,t);if(e instanceof WL)return YR(e,t)}if(e instanceof EL&&t instanceof EL)return BR(e,t);M(`genericFuse`,`Unhandled shape combination in genericFuse`)},GR=e=>{let t=new Map,n=[];return e.forEach((r,i)=>{let a;t.has(i)?a=t.get(i):(a={current:r,fusedWith:new Set([i])},n.push(a)),e.slice(i+1).forEach((e,n)=>{let r=a.current,o=i+n+1;if(a.fusedWith.has(o))return;let s=e,c=!1;if(t.has(o)&&(s=t.get(o).current,c=!0),r.boundingBox.isOut(s.boundingBox)||!UR(r,s))return;let l;if(r instanceof UL||s instanceof UL){let e=XR(r,s);e===null&&M(`fuseIntersectingBlueprints`,`fuse2D returned null for non-null inputs`),l=e}else l=WR(r,s);if(!(l instanceof EL||l instanceof WL)){if(l instanceof UL&&l.blueprints.length===2)return;l instanceof UL&&l.blueprints.length===1?l=xo(l.blueprints,0,`fuseIntersectingBlueprints`):l instanceof UL||M(`fuseIntersectingBlueprints`,`Fuse produced unexpected non-blueprint result`)}a.fusedWith.add(o),a.current=l,c||t.set(o,a)})}),XL(n.map(({current:e})=>e).flatMap(e=>KR(e)))},KR=e=>e instanceof EL?[e]:e instanceof WL?e.blueprints:e instanceof UL?e.blueprints.flatMap(e=>KR(e)):[],qR=(e,t)=>{let n=BR(e,xo(t.blueprints,0,`fuseBlueprintWithCompound`)),r=t.blueprints.slice(1).map(t=>VR(t,e));return XL([...KR(n),...r.flatMap(e=>KR(e))])};function JR(e,t){let n=[];for(let r of e)for(let e of t)n.push([r,e]);return n}var YR=(e,t)=>{let n=xo(e.blueprints,0,`fuseCompoundWithCompound`),r=xo(t.blueprints,0,`fuseCompoundWithCompound`),i=BR(n,r),a=t.blueprints.slice(1).map(e=>VR(e,n)),o=e.blueprints.slice(1).map(e=>VR(e,r)),s=JR(e.blueprints.slice(1),t.blueprints.slice(1)).flatMap(([e,t])=>KR(HR(e,t)));return XL([...KR(i),...a.flatMap(e=>KR(e)),...o.flatMap(e=>KR(e)),...s])},XR=(e,t)=>{if(e===null)return t?.clone()??null;if(t===null)return e.clone();if(!(e instanceof UL)&&t instanceof UL)return GR([e,...t.blueprints]);if(!(t instanceof UL)&&e instanceof UL)return GR([t,...e.blueprints]);if(e instanceof UL&&t instanceof UL){let n=XR(xo(e.blueprints,0,`fuse2D`),t);return e.blueprints.slice(1).forEach(e=>{n=XR(e,n)}),n}if(e instanceof WL){if(t instanceof UL)return XR(t,e);if(t instanceof EL)return qR(t,e);if(t instanceof WL)return YR(e,t)}if(t instanceof WL){if(e instanceof UL)return XR(e,t);if(e instanceof EL)return qR(e,t);if(e instanceof WL)return YR(e,t)}return e instanceof EL&&t instanceof EL?BR(e,t):null},ZR=e=>{let t=e.flatMap(e=>e===null?[]:e instanceof UL?e.blueprints:e);return t.length===1?xo(t,0,`mergeNonIntersecting`):new UL(t)},QR=(e,t)=>{if(e===null)return null;if(t===null)return e.clone();if(e instanceof UL)return ZR(e.blueprints.map(e=>QR(e,t)));if(e instanceof WL){let n=xo(e.blueprints,0,`cut2D`);if(t instanceof EL&&!t.intersects(n))return n.isInside(t.firstPoint)?XL([n,...KR(XR(t,new UL(e.blueprints.slice(1))))]):e.clone();{let r=QR(n,t);return e.blueprints.slice(1).forEach(e=>{r=QR(r,e)}),r}}if(t instanceof UL){let n=e;for(let e of t.blueprints)n=QR(n,e);return n}if(t instanceof WL){let n=VR(e,xo(t.blueprints,0,`cut2D`));return t.blueprints.slice(1).forEach(t=>{n=XR(n,HR(t,e))}),n}return VR(e,t)};function $R(e,t){if(e===null||t===null)return null;if(e instanceof EL&&t instanceof EL)return HR(e,t);if(e instanceof UL)return ZR(e.blueprints.map(e=>$R(e,t)));if(e instanceof WL){let n=xo(e.blueprints,0,`intersect2D`),r=e.blueprints.slice(1);if(r.length===0)return $R(n,t);let i=$R(n,t);for(let e of r)i=QR(i,e);return i}if(t instanceof UL)return ZR(t.blueprints.map(t=>$R(e,t)));if(t instanceof WL){let n=xo(t.blueprints,0,`intersect2D`),r=t.blueprints.slice(1);if(r.length===0)return $R(n,e);let i=$R(n,e);for(let e of r)i=QR(i,e);return i}M(`intersect2D`,`Unhandled Shape2D combination`)}var ez=e(((e,t)=>{t.exports={}}));
23
23
  /*! https://mths.be/codepointat v0.2.0 by @mathias */
24
- String.prototype.codePointAt||(function(){var e=function(){try{var e={},t=Object.defineProperty,n=t(e,e,e)&&t}catch{}return n}(),t=function(e){if(this==null)throw TypeError();var t=String(this),n=t.length,r=e?Number(e):0;if(r!=r&&(r=0),!(r<0||r>=n)){var i=t.charCodeAt(r),a;return i>=55296&&i<=56319&&n>r+1&&(a=t.charCodeAt(r+1),a>=56320&&a<=57343)?(i-55296)*1024+a-56320+65536:i}};e?e(String.prototype,`codePointAt`,{value:t,configurable:!0,writable:!0}):String.prototype.codePointAt=t})();var XR=0,ZR=-3;function QR(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function $R(e,t){this.source=e,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=t,this.destLen=0,this.ltree=new QR,this.dtree=new QR}var ez=new QR,tz=new QR,nz=new Uint8Array(30),rz=new Uint16Array(30),iz=new Uint8Array(30),az=new Uint16Array(30),oz=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),sz=new QR,cz=new Uint8Array(320);function lz(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 uz(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 dz=new Uint16Array(16);function fz(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)dz[i]=a,a+=e.table[i];for(i=0;i<r;++i)t[n+i]&&(e.trans[dz[t[n+i]]++]=i)}function pz(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 hz(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 gz(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)cz[o]=0;for(o=0;o<a;++o){var l=mz(e,3,0);cz[oz[o]]=l}for(fz(sz,cz,0,19),s=0;s<r+i;){var u=hz(e,sz);switch(u){case 16:var d=cz[s-1];for(c=mz(e,2,3);c;--c)cz[s++]=d;break;case 17:for(c=mz(e,3,3);c;--c)cz[s++]=0;break;case 18:for(c=mz(e,7,11);c;--c)cz[s++]=0;break;default:cz[s++]=u;break}}fz(t,cz,0,r),fz(n,cz,r,i)}function _z(e,t,n){for(;;){var r=hz(e,t);if(r===256)return XR;if(r<256)e.dest[e.destLen++]=r;else{var i,a,o,s;for(r-=257,i=mz(e,nz[r],rz[r]),a=hz(e,n),o=e.destLen-mz(e,iz[a],az[a]),s=o;s<o+i;++s)e.dest[e.destLen++]=e.dest[s]}}}function vz(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 ZR;for(e.sourceIndex+=4,r=t;r;--r)e.dest[e.destLen++]=e.source[e.sourceIndex++];return e.bitcount=0,XR}function yz(e,t){var n=new $R(e,t),r,i,a;do{switch(r=pz(n),i=mz(n,2,0),i){case 0:a=vz(n);break;case 1:a=_z(n,ez,tz);break;case 2:gz(n,n.ltree,n.dtree),a=_z(n,n.ltree,n.dtree);break;default:a=ZR}if(a!==XR)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}uz(ez,tz),lz(nz,rz,4,3),lz(iz,az,2,1),nz[28]=0,rz[28]=258;var bz=yz;function xz(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 Sz(){this.x1=NaN,this.y1=NaN,this.x2=NaN,this.y2=NaN}Sz.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)},Sz.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))},Sz.prototype.addX=function(e){this.addPoint(e,null)},Sz.prototype.addY=function(e){this.addPoint(null,e)},Sz.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(xz(c[f],l[f],u[f],d[f],g)),f===1&&this.addY(xz(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(xz(c[f],l[f],u[f],d[f],v)),f===1&&this.addY(xz(c[f],l[f],u[f],d[f],v)));var y=(-p-Math.sqrt(_))/(2*m);0<y&&y<1&&(f===0&&this.addX(xz(c[f],l[f],u[f],d[f],y)),f===1&&this.addY(xz(c[f],l[f],u[f],d[f],y)))}}},Sz.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 Cz(){this.commands=[],this.fill=`black`,this.stroke=null,this.strokeWidth=1}Cz.prototype.moveTo=function(e,t){this.commands.push({type:`M`,x:e,y:t})},Cz.prototype.lineTo=function(e,t){this.commands.push({type:`L`,x:e,y:t})},Cz.prototype.curveTo=Cz.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})},Cz.prototype.quadTo=Cz.prototype.quadraticCurveTo=function(e,t,n,r){this.commands.push({type:`Q`,x1:e,y1:t,x:n,y:r})},Cz.prototype.close=Cz.prototype.closePath=function(){this.commands.push({type:`Z`})},Cz.prototype.extend=function(e){if(e.commands)e=e.commands;else if(e instanceof Sz){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)},Cz.prototype.getBoundingBox=function(){for(var e=new Sz,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},Cz.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())},Cz.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},Cz.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},Cz.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 wz(e){throw Error(e)}function Tz(e,t){e||wz(t)}var K={fail:wz,argument:Tz,assert:Tz},Ez=32768,Dz=2147483648,Oz={},q={},J={};function kz(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=kz(1),q.CHAR=function(e){return[e.charCodeAt(0)]},J.CHAR=kz(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=kz(2),q.SHORT=function(e){return e>=Ez&&(e=-(2*Ez-e)),[e>>8&255,e&255]},J.SHORT=kz(2),q.UINT24=function(e){return[e>>16&255,e>>8&255,e&255]},J.UINT24=kz(3),q.ULONG=function(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]},J.ULONG=kz(4),q.LONG=function(e){return e>=Dz&&(e=-(2*Dz-e)),[e>>24&255,e>>16&255,e>>8&255,e&255]},J.LONG=kz(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=kz(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=kz(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=kz(3),q.NUMBER32=function(e){return[29,e>>24&255,e>>16&255,e>>8&255,e&255]},J.NUMBER32=kz(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,Oz.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)},Oz.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 Az={"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ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ`};Oz.MACSTRING=function(e,t,n,r){var i=Az[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 jz=typeof WeakMap==`function`&&new WeakMap,Mz,Nz=function(e){if(!Mz)for(var t in Mz={},Az)Mz[t]=new String(t);var n=Mz[e];if(n!==void 0){if(jz){var r=jz.get(n);if(r!==void 0)return r}var i=Az[e];if(i!==void 0){for(var a={},o=0;o<i.length;o++)a[i.charCodeAt(o)]=o+128;return jz&&jz.set(n,a),a}}};q.MACSTRING=function(e,t){var n=Nz(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 Pz(e){return e>=-128&&e<=127}function Fz(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 Iz(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(!Pz(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 Lz(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(o===0||Pz(o)&&a+1<i&&Pz(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?Fz(e,t,n):r>=-128&&r<=127?Iz(e,t,n):Lz(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 Rz=typeof WeakMap==`function`&&new WeakMap;q.CHARSTRING=function(e){if(Rz){var t=Rz.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 Rz&&Rz.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 zz(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)}}zz.prototype.encode=function(){return q.TABLE(this)},zz.prototype.sizeOf=function(){return J.TABLE(this)};function Bz(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 Vz(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 Hz(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 Uz(e){e.format===1?zz.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:1}].concat(Bz(`glyph`,e.glyphs))):e.format===2?zz.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:2}].concat(Hz(`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.`)}Uz.prototype=Object.create(zz.prototype),Uz.prototype.constructor=Uz;function Wz(e){zz.call(this,`scriptListTable`,Hz(`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 zz(`scriptTable`,[{name:`defaultLangSys`,type:`TABLE`,value:new zz(`defaultLangSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:r.reqFeatureIndex}].concat(Bz(`featureIndex`,r.featureIndexes)))}].concat(Hz(`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 zz(`langSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:n.reqFeatureIndex}].concat(Bz(`featureIndex`,n.featureIndexes)))}]})))}]}))}Wz.prototype=Object.create(zz.prototype),Wz.prototype.constructor=Wz;function Gz(e){zz.call(this,`featureListTable`,Hz(`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 zz(`featureTable`,[{name:`featureParams`,type:`USHORT`,value:n.featureParams}].concat(Bz(`lookupListIndex`,n.lookupListIndexes)))}]}))}Gz.prototype=Object.create(zz.prototype),Gz.prototype.constructor=Gz;function Kz(e,t){zz.call(this,`lookupListTable`,Vz(`lookup`,e,function(e){var n=t[e.lookupType];return K.assert(!!n,`Unable to write GSUB lookup type `+e.lookupType+` tables.`),new zz(`lookupTable`,[{name:`lookupType`,type:`USHORT`,value:e.lookupType},{name:`lookupFlag`,type:`USHORT`,value:e.lookupFlag}].concat(Vz(`subtable`,e.subtables,n)))}))}Kz.prototype=Object.create(zz.prototype),Kz.prototype.constructor=Kz;var Y={Table:zz,Record:zz,Coverage:Uz,ScriptList:Wz,FeatureList:Gz,LookupList:Kz,ushortList:Bz,tableList:Vz,recordList:Hz};function qz(e,t){return e.getUint8(t)}function Jz(e,t){return e.getUint16(t,!1)}function Yz(e,t){return e.getInt16(t,!1)}function Xz(e,t){return e.getUint32(t,!1)}function Zz(e,t){return e.getInt16(t,!1)+e.getUint16(t+2,!1)/65535}function Qz(e,t){for(var n=``,r=t;r<t+4;r+=1)n+=String.fromCharCode(e.getInt8(r));return n}function $z(e,t,n){for(var r=0,i=0;i<n;i+=1)r<<=8,r+=e.getUint8(t+i);return r}function eB(e,t,n){for(var r=[],i=t;i<n;i+=1)r.push(e.getUint8(i));return r}function tB(e){for(var t=``,n=0;n<e.length;n+=1)t+=String.fromCharCode(e[n]);return t}var nB={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=Xz(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,e},X.prototype.parseOffset32=X.prototype.parseULong,X.prototype.parseFixed=function(){var e=Zz(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=Xz(this.data,this.offset+this.relativeOffset+4);return e-=2082844800,this.relativeOffset+=8,e},X.prototype.parseVersion=function(e){var t=Jz(this.data,this.offset+this.relativeOffset),n=Jz(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+=nB[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 rB={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(rB),langSysRecords:X.recordList({tag:X.tag,langSys:X.pointer(rB)})})}))||[]},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:qz,getCard8:qz,getUShort:Jz,getCard16:Jz,getShort:Yz,getULong:Xz,getFixed:Zz,getTag:Qz,getOffset:$z,getBytes:eB,bytesToString:tB,Parser:X};function iB(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 aB(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 oB(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)iB(n,s);else if(n.format===4)aB(n,s,e,t,r);else throw Error(`Only format 4 and 12 cmap tables are supported (found format `+n.format+`).`);return n}function sB(e,t,n){e.segments.push({end:t,start:t,delta:-(t-n),offset:0,glyphIndex:n})}function cB(e){e.segments.push({end:65535,start:65535,delta:1,offset:0})}function lB(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)sB(i,a.unicodes[o],n);i.segments=i.segments.sort(function(e,t){return e.start-t.start})}cB(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 uB={parse:oB,make:lB},dB=`.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(`,`),fB=`................................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(`.`),pB=`................................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 hB(e){this.font=e}hB.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 gB(e){this.cmap=e}gB.prototype.charToGlyphIndex=function(e){return this.cmap.glyphIndexMap[e.codePointAt(0)]||0};function _B(e,t){this.encoding=e,this.charset=t}_B.prototype.charToGlyphIndex=function(e){var t=e.codePointAt(0),n=this.encoding[t];return this.charset.indexOf(n)};function vB(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}}vB.prototype.nameToGlyphIndex=function(e){return this.names.indexOf(e)},vB.prototype.glyphIndexToName=function(e){return this.names[e]};function yB(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 bB(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 xB(e,t){t.lowMemory?bB(e):yB(e)}function SB(e,t,n,r,i){e.beginPath(),e.moveTo(t,n),e.lineTo(r,i),e.stroke()}var CB={line:SB};function wB(e,t){var n=t||new Cz;return{configurable:!0,get:function(){return typeof n==`function`&&(n=n()),n},set:function(e){n=e}}}function TB(e){this.bindConstructorValues(e)}TB.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",wB(this,e.path))},TB.prototype.addUnicode=function(e){this.unicodes.length===0&&(this.unicode=e),this.unicodes.push(e)},TB.prototype.getBoundingBox=function(){return this.path.getBoundingBox()},TB.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 Cz,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},TB.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},TB.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},TB.prototype.draw=function(e,t,n,r,i){this.getPath(t,n,r,i).draw(e)},TB.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)},TB.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`,CB.line(e,t,-1e4,t,1e4),CB.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`,CB.line(e,t+a*i,-1e4,t+a*i,1e4),CB.line(e,t+s*i,-1e4,t+s*i,1e4),CB.line(e,-1e4,n+-o*i,1e4,n+-o*i),CB.line(e,-1e4,n+-c*i,1e4,n+-c*i),e.strokeStyle=`green`,CB.line(e,t+l*i,-1e4,t+l*i,1e4)};function EB(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 DB(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}DB.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]},DB.prototype.push=function(e,t){this.glyphs[e]=t,this.length++};function OB(e,t){return new TB({index:t,font:e})}function kB(e,t,n,r,i,a){return function(){var o=new TB({index:t,font:e});return o.path=function(){n(o,r,i);var t=a(e.glyphs,o);return t.unitsPerEm=e.unitsPerEm,t},EB(o,`xMin`,`_xMin`),EB(o,`xMax`,`_xMax`),EB(o,`yMin`,`_yMin`),EB(o,`yMax`,`_yMax`),o}}function AB(e,t,n,r){return function(){var i=new TB({index:t,font:e});return i.path=function(){var t=n(e,i,r);return t.unitsPerEm=e.unitsPerEm,t},i}}var jB={GlyphSet:DB,glyphLoader:OB,ttfGlyphLoader:kB,cffGlyphLoader:AB};function MB(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(!MB(e[n],t[n]))return!1;return!0}else return!1}function NB(e){return e.length<1240?107:e.length<33900?1131:32768}function PB(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 FB(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 IB(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 LB(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 RB(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 LB(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 zB(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 BB(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(RB(r,o))}return zB(i)}function VB(e,t){return t=t<=390?dB[t]:e[t-391],t}function HB(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=VB(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=VB(n,i)),r[o.name]=i}return r}function UB(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 WB=[{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`}],GB=[{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 KB(e,t){return HB(BB(e,0,e.byteLength),WB,t)}function qB(e,t,n,r){return HB(BB(e,t,n),GB,r)}function JB(e,t,n,r){for(var i=[],a=0;a<n.length;a+=1){var o=KB(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=qB(e,c+t,s,r);o._defaultWidthX=l.defaultWidthX,o._nominalWidthX=l.nominalWidthX,l.subrs!==0&&(o._subrs=PB(e,c+l.subrs+t).objects,o._subrsBias=NB(o._subrs)),o._privateDict=l}i.push(o)}return i}function YB(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(VB(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(VB(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(VB(r,i)),i+=1}else throw Error(`Unknown charset format `+c);return s}function XB(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 _B(i,n)}function ZB(e,t,n){var r,i,a,o,s=new Cz,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 QB(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 $B(e,t,n,r){n.tables.cff={};var i=PB(e,PB(e,UB(e,t).endOffset,Z.bytesToString).endOffset),a=PB(e,i.endOffset,Z.bytesToString);n.gsubrs=PB(e,a.endOffset).objects,n.gsubrsBias=NB(n.gsubrs);var o=JB(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=JB(e,t,PB(e,c).objects,a.objects);s._fdArray=u,l+=t,s._fdSelect=QB(e,l,n.numGlyphs,u.length)}var d=t+s.private[1],f=qB(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=PB(e,d+f.subrs).objects,n.subrsBias=NB(n.subrs));var p;r.lowMemory?(p=FB(e,t+s.charStrings),n.nGlyphs=p.offsets.length):(p=PB(e,t+s.charStrings),n.nGlyphs=p.objects.length);var m=YB(e,t+s.charset,n.nGlyphs,a.objects);if(s.encoding===0?n.cffEncoding=new _B(fB,m):s.encoding===1?n.cffEncoding=new _B(pB,m):n.cffEncoding=XB(e,t+s.encoding,m),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new jB.GlyphSet(n),r.lowMemory)n._push=function(r){var i=IB(r,p.offsets,e,t+s.charStrings);n.glyphs.push(r,jB.cffGlyphLoader(n,r,ZB,i))};else for(var h=0;h<n.nGlyphs;h+=1){var g=p.objects[h];n.glyphs.push(h,jB.cffGlyphLoader(n,h,ZB,g))}}function eV(e,t){var n,r=dB.indexOf(e);return r>=0&&(n=r),r=t.indexOf(e),r>=0?n=r+dB.length:(n=dB.length+t.length,t.push(e)),n}function tV(){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 nV(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 rV(e,t,n){for(var r={},i=0;i<e.length;i+=1){var a=e[i],o=t[a.name];o!==void 0&&!MB(o,a.value)&&(a.type===`SID`&&(o=eV(o,n)),r[a.op]={name:a.name,type:a.type,value:o})}return r}function iV(e,t){var n=new Y.Record(`Top DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=rV(WB,e,t),n}function aV(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 oV(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 sV(){return new Y.Record(`Global Subr INDEX`,[{name:`subrs`,type:`INDEX`,value:[]}])}function cV(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=eV(i,t);n.fields.push({name:`glyph_`+r,type:`SID`,value:a})}return n}function lV(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 uV(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=lV(r);t.charStrings.push({name:r.name,type:`CHARSTRING`,value:i})}return t}function dV(e,t){var n=new Y.Record(`Private DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=rV(GB,e,t),n}function fV(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=tV(),n.nameIndex=nV([t.postScriptName]);var u=iV(i,l);return n.topDictIndex=aV(u),n.globalSubrIndex=sV(),n.charsets=cV(o,l),n.charStringsIndex=uV(e),n.privateDict=dV(a,l),n.stringIndex=oV(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=iV(i,l),n.topDictIndex=aV(u),n}var pV={parse:$B,make:fV};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 hV(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 gV={parse:mV,make:hV};function _V(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 vV(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 yV={parse:_V,make:vV};function bV(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 xV(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 SV(e,t,n,r,i,a,o){o.lowMemory?xV(e,t,n,r,i):bV(t,n,r,i,a)}function CV(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 wV={parse:SV,make:CV};function TV(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 EV(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 DV={make:TV,parse:EV};function OV(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 kV(e){return new Y.Table(`maxp`,[{name:`version`,type:`FIXED`,value:20480},{name:`numGlyphs`,type:`USHORT`,value:e}])}var AV={parse:OV,make:kV},jV=[`copyright`,`fontFamily`,`fontSubfamily`,`uniqueID`,`fullName`,`version`,`postScriptName`,`trademark`,`manufacturer`,`designer`,`description`,`manufacturerURL`,`designerURL`,`license`,`licenseURL`,`reserved`,`preferredFamily`,`preferredSubfamily`,`compatibleFullName`,`sampleText`,`postScriptFindFontName`,`wwsFamily`,`wwsSubfamily`],MV={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`},NV={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},PV={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 FV(e,t,n){switch(e){case 0:if(t===65535)return`und`;if(n)return n[t];break;case 1:return MV[t];case 3:return PV[t]}}var IV=`utf-16`,LV={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`},RV={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 zV(e,t,n){switch(e){case 0:return IV;case 1:return RV[n]||LV[t];case 3:if(t===1||t===10)return IV;break}}function BV(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=jV[f]||f,m=i.parseUShort(),h=i.parseUShort(),g=FV(l,d,n),_=zV(l,u,d);if(_!==void 0&&g!==void 0){var v=void 0;if(v=_===IV?Oz.UTF16(e,s+h,m):Oz.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 VV(e){var t={};for(var n in e)t[e[n]]=parseInt(n);return t}function HV(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 UV(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 WV(e,t){var n=UV(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 GV(e,t){var n,r=[],i={},a=VV(jV);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=VV(MV),l=VV(PV),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=NV[_],y=zV(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=WV(b,d);u.push(HV(g,v,_,n,b.length,x));var S=l[m];if(S!==void 0){var C=q.UTF16(h),w=WV(C,d);u.push(HV(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 KV={parse:BV,make:GV},qV=[{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 JV(e){for(var t=0;t<qV.length;t+=1){var n=qV[t];if(e>=n.begin&&e<n.end)return t}return-1}function YV(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 XV(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 ZV={parse:YV,make:XV,unicodeRanges:qV,getUnicodeRange:JV};function QV(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 $V(){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 eH={parse:QV,make:$V},tH=Array(9);tH[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.`)},tH[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()}},tH[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()}},tH[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 nH={sequenceIndex:X.uShort,lookupListIndex:X.uShort};tH[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,nH)}})};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,nH)}})};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,nH)}}K.assert(!1,`0x`+e.toString(16)+`: lookup type 5 format must be 1, 2 or 3.`)},tH[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(nH)}})};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(nH)}})};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(nH)};K.assert(!1,`0x`+e.toString(16)+`: lookup type 6 format must be 1, 2 or 3.`)},tH[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:tH[t].call(n)}},tH[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 rH(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(tH)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(tH),variations:n.parseFeatureVariationsList()}}var iH=Array(9);iH[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)))},iH[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))})))},iH[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))})))},iH[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)))}))})))},iH[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 aH(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,iH)}])}var oH={parse:rH,make:aH};function sH(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]=Oz.UTF8(e,t+c,l)}return a}function cH(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 lH={parse:sH,make:cH};function uH(e){return Math.log(e)/Math.log(2)|0}function dH(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 fH(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 pH(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**uH(t.numTables);t.searchRange=16*n,t.entrySelector=uH(n),t.rangeShift=t.numTables*16-t.searchRange;for(var r=[],i=[],a=t.sizeOf()+fH().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=fH(s.tableName,dH(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 hH(e){for(var t=0,n=0;n<e.length;n+=1)t+=e[n];return t/e.length}function gH(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 _=ZV.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:hH(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=gV.make({flags:3,unitsPerEm:e.unitsPerEm,xMin:y.xMin,yMin:y.yMin,xMax:y.xMax,yMax:y.yMax,lowestRecPPEM:3,createdTimestamp:e.createdTimestamp}),x=yV.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=AV.make(e.glyphs.length),C=ZV.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=wV.make(e.glyphs),ee=uB.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=KV.make(ae,se),le=se.length>0?DV.make(se):void 0,ue=eH.make(),de=pV.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?lH.make(e.metas):void 0,pe=[b,x,S,C,ce,ee,ue,de,w];le&&pe.push(le),e.tables.gsub&&pe.push(oH.make(e.tables.gsub)),fe&&pe.push(fe);for(var me=pH(pe),he=dH(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 _H={make:pH,fontToTable:gH,computeCheckSum:dH};function vH(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 yH(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 bH(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 xH(e,t){this.font=e,this.tableName=t}xH.prototype={searchTag:vH,binSearch:yH,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=vH(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=vH(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=bH(e.ranges,t);return n?n.classId:0}},getCoverageIndex:function(e,t){switch(e.format){case 1:var n=yH(e.glyphs,t);return n>=0?n:-1;case 2:var r=bH(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 SH(e){xH.call(this,e,`gpos`)}SH.prototype=xH.prototype,SH.prototype.init=function(){var e=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(e)},SH.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},SH.prototype.getKerningTables=function(e,t){if(this.font.tables.gpos)return this.getLookupTables(e,t,`kern`,2)};function CH(e){xH.call(this,e,`gsub`)}function wH(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 TH(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}CH.prototype=xH.prototype,CH.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:`DFLT`,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}},CH.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},CH.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},CH.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},CH.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},CH.prototype.addSingle=function(e,t,n,r){var i=this.getLookupTables(n,r,e,1,!0)[0],a=TH(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},CH.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=TH(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},CH.prototype.addAlternate=function(e,t,n,r){var i=this.getLookupTables(n,r,e,3,!0)[0],a=TH(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},CH.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(wH(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])},CH.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)}},CH.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 EH(){return typeof window<`u`}function DH(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 OH(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 kH(e,t){if(!e)throw t}function AH(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 jH(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=AH(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=AH(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 MH(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 NH(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 PH(e){var t=new Cz;if(!e)return t;for(var n=NH(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 FH(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=MH(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=MH([s],c)[0],c.dx=o.x-s.x,c.dy=o.y-s.y,a=MH(i.points,c)}t.points=t.points.concat(a)}}return PH(t.points)}function IH(e,t,n,r){for(var i=new jB.GlyphSet(r),a=0;a<n.length-1;a+=1){var o=n[a];o===n[a+1]?i.push(a,jB.glyphLoader(r,a)):i.push(a,jB.ttfGlyphLoader(r,a,jH,e,t+o,FH))}return i}function LH(e,t,n,r){var i=new jB.GlyphSet(r);return r._push=function(a){var o=n[a];o===n[a+1]?i.push(a,jB.glyphLoader(r,a)):i.push(a,jB.ttfGlyphLoader(r,a,jH,e,t+o,FH))},i}function RH(e,t,n,r,i){return i.lowMemory?LH(e,t,n,r):IH(e,t,n,r)}var zH={getPath:PH,parse:RH},BH,VH,HH,UH;function WH(e){this.font=e,this.getCommands=function(e){return zH.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function GH(e){return e}function KH(e){return Math.sign(e)*Math.round(Math.abs(e))}function qH(e){return Math.sign(e)*Math.round(Math.abs(e*2))/2}function JH(e){return Math.sign(e)*(Math.round(Math.abs(e)+.5)-.5)}function YH(e){return Math.sign(e)*Math.ceil(Math.abs(e))}function XH(e){return Math.sign(e)*Math.floor(Math.abs(e))}var ZH=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},QH={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){QH.setRelative(e,e,(c+l)/2,r,!0);return}QH.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}},$H={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){$H.setRelative(e,e,(c+l)/2,r,!0);return}$H.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(QH),Object.freeze($H);function eU(e,t){this.x=e,this.y=t,this.axis=void 0,this.slope=t/e,this.normalSlope=-e/t,Object.freeze(this)}eU.prototype.distance=function(e,t,n,r){return this.x*QH.distance(e,t,n,r)+this.y*$H.distance(e,t,n,r)},eU.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)},eU.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},eU.prototype.touch=function(e){e.xTouched=!0,e.yTouched=!0};function tU(e,t){var n=Math.sqrt(e*e+t*t);return e/=n,t/=n,e===1&&t===0?QH:e===0&&t===1?$H:new eU(e,t)}function nU(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)}nU.prototype.nextTouched=function(e){for(var t=this.nextPointOnContour;!e.touched(t)&&t!==this;)t=t.nextPointOnContour;return t},nU.prototype.prevTouched=function(e){for(var t=this.prevPointOnContour;!e.touched(t)&&t!==this;)t=t.prevPointOnContour;return t};var rU=Object.freeze(new nU(0,0)),iU={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function aU(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=QH,this.round=KH}}WH.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){aU.prototype=iU,i=this._fpgmState=new aU(`fpgm`,n.tables.fpgm),i.funcs=[],i.font=n,exports.DEBUG&&(console.log(`---EXEC FPGM---`),i.step=-1);try{VH(i)}catch(e){console.log(`Hinting error in FPGM:`+e),this._errorState=3;return}}aU.prototype=i,r=this._prepState=new aU(`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{VH(r)}catch(e){this._errorState<2&&console.log(`Hinting error in PREP:`+e),this._errorState=2}}if(!(this._errorState>1))try{return HH(e,r)}catch(e){this._errorState<1&&(console.log(`Hinting error:`+e),console.log(`Note: further hinting errors are silenced`)),this._errorState=1;return}}},HH=function(e,t){var n=t.ppem/t.font.unitsPerEm,r=n,i=e.components,a,o,s;if(aU.prototype=t,!i)s=new aU(`glyf`,e.instructions),exports.DEBUG&&(console.log(`---EXEC GLYPH---`),s.step=-1),UH(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 aU(`glyf`,d.instructions),exports.DEBUG&&(console.log(`---EXEC COMP `+l+`---`),s.step=-1),UH(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 aU(`glyf`,e.instructions),s.gZone=s.z0=s.z1=s.z2=o,s.contours=a,o.push(new nU(0,0),new nU(Math.round(e.advanceWidth*n),0)),exports.DEBUG&&(console.log(`---EXEC COMPOSITE---`),s.step=-1),VH(s),o.length-=2)}return o},UH=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 nU(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 nU(0,0),new nU(Math.round(e.advanceWidth*n),0)),VH(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)}}},VH=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=BH[t[e.ip]],!r)throw Error(`unknown instruction: 0x`+Number(t[e.ip]).toString(16));r(e)}}};function oU(e){for(var t=e.tZone=Array(e.gZone.length),n=0;n<t.length;n++)t[n]=new nU(0,0)}function sU(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 cU(e,t){exports.DEBUG&&console.log(t.step,`SVTCA[`+e.axis+`]`),t.fv=t.pv=t.dpv=e}function lU(e,t){exports.DEBUG&&console.log(t.step,`SPVTCA[`+e.axis+`]`),t.pv=t.dpv=e}function uU(e,t){exports.DEBUG&&console.log(t.step,`SFVTCA[`+e.axis+`]`),t.fv=e}function dU(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=tU(s,c)}function fU(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=tU(s,c)}function pU(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.pv=e.dpv=tU(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=tU(r,n)}function hU(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 gU(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 _U(e){e.fv=e.pv,exports.DEBUG&&console.log(e.step,`SFVTPV[]`)}function vU(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 yU(e){e.rp0=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP0[]`,e.rp0)}function bU(e){e.rp1=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP1[]`,e.rp1)}function xU(e){e.rp2=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP2[]`,e.rp2)}function SU(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP0[]`,t),e.zp0=t,t){case 0:e.tZone||oU(e),e.z0=e.tZone;break;case 1:e.z0=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function CU(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP1[]`,t),e.zp1=t,t){case 0:e.tZone||oU(e),e.z1=e.tZone;break;case 1:e.z1=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function wU(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP2[]`,t),e.zp2=t,t){case 0:e.tZone||oU(e),e.z2=e.tZone;break;case 1:e.z2=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function TU(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||oU(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 EU(e){e.loop=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SLOOP[]`,e.loop)}function DU(e){exports.DEBUG&&console.log(e.step,`RTG[]`),e.round=KH}function OU(e){exports.DEBUG&&console.log(e.step,`RTHG[]`),e.round=JH}function kU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SMD[]`,t),e.minDis=t/64}function AU(e){exports.DEBUG&&console.log(e.step,`ELSE[]`),sU(e,!1)}function jU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`JMPR[]`,t),e.ip+=t-1}function MU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCVTCI[]`,t),e.cvCutIn=t/64}function NU(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DUP[]`),t.push(t[t.length-1])}function PU(e){exports.DEBUG&&console.log(e.step,`POP[]`),e.stack.pop()}function FU(e){exports.DEBUG&&console.log(e.step,`CLEAR[]`),e.stack.length=0}function IU(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 LU(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DEPTH[]`),t.push(t.length)}function RU(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++)VH(e),exports.DEBUG&&console.log(++e.step,o+1<r?`next loopcall`:`done loopcall`,o);e.ip=i,e.prog=a}function zU(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],VH(e),e.ip=n,e.prog=r,exports.DEBUG&&console.log(++e.step,`returning from`,t)}function BU(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CINDEX[]`,n),t.push(t[t.length-n])}function VU(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 HU(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 UU(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,rU);e&&(o=t.round(o)),i.setRelative(r,rU,o,a),i.touch(r),t.rp0=t.rp1=n}function WU(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 GU(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 KU(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 qU(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 JU(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 YU(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 XU(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 ZU(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 QU(e){exports.DEBUG&&console.log(e.step,`RTDG[]`),e.round=qH}function $U(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,rU);e&&(Math.abs(l-c)<t.cvCutIn&&(l=c),l=t.round(l)),o.setRelative(a,rU,l,s),t.zp0===0&&(a.xo=a.x,a.yo=a.y),o.touch(a),t.rp0=t.rp1=i}function eW(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 tW(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 nW(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 rW(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 iW(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 aW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`RCVT`,n),t.push(e.cvt[n]*64)}function oW(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,rU,e,!1)*64)}function sW(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 cW(e){exports.DEBUG&&console.log(e.step,`MPPEM[]`),e.stack.push(e.ppem)}function lW(e){exports.DEBUG&&console.log(e.step,`FLIPON[]`),e.autoFlip=!0}function uW(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 dW(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 fW(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 pW(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 hW(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 gW(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 _W(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 vW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`IF[]`,t),t||(sU(e,!0),exports.DEBUG&&console.log(e.step,`EIF[]`))}function yW(e){exports.DEBUG&&console.log(e.step,`EIF[]`)}function bW(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 xW(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 SW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NOT[]`,n),t.push(+!n)}function CW(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 wW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDB[]`,t),e.deltaBase=t}function TW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDS[]`,t),e.deltaShift=.5**t}function EW(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 DW(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 OW(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 kW(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 AW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`ABS[]`,n),t.push(Math.abs(n))}function jW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NEG[]`,n),t.push(-n)}function MW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`FLOOR[]`,n),t.push(Math.floor(n/64)*64)}function NW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CEILING[]`,n),t.push(Math.ceil(n/64)*64)}function PW(e,t){var n=t.stack,r=n.pop();exports.DEBUG&&console.log(t.step,`ROUND[]`),n.push(t.round(r/64)*64)}function FW(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 IW(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 LW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SROUND[]`,t),e.round=ZH;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 RW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`S45ROUND[]`,t),e.round=ZH;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 zW(e){exports.DEBUG&&console.log(e.step,`ROFF[]`),e.round=GH}function BW(e){exports.DEBUG&&console.log(e.step,`RUTG[]`),e.round=YH}function VW(e){exports.DEBUG&&console.log(e.step,`RDTG[]`),e.round=XH}function HW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANCTRL[]`,t)}function UW(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=tU(s,c)}function WW(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 GW(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 KW(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 qW(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 JW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANTYPE[]`,t)}function YW(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 XW(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 ZW(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)}BH=[cU.bind(void 0,$H),cU.bind(void 0,QH),lU.bind(void 0,$H),lU.bind(void 0,QH),uU.bind(void 0,$H),uU.bind(void 0,QH),dU.bind(void 0,0),dU.bind(void 0,1),fU.bind(void 0,0),fU.bind(void 0,1),pU,mU,hU,gU,_U,vU,yU,bU,xU,SU,CU,wU,TU,EU,DU,OU,kU,AU,jU,MU,void 0,void 0,NU,PU,FU,IU,LU,BU,VU,void 0,void 0,void 0,RU,zU,HU,void 0,UU.bind(void 0,0),UU.bind(void 0,1),WU.bind(void 0,$H),WU.bind(void 0,QH),GU.bind(void 0,0),GU.bind(void 0,1),KU.bind(void 0,0),KU.bind(void 0,1),qU.bind(void 0,0),qU.bind(void 0,1),JU,YU,XU.bind(void 0,0),XU.bind(void 0,1),ZU,QU,$U.bind(void 0,0),$U.bind(void 0,1),eW,tW,nW,rW,iW,aW,oW.bind(void 0,0),oW.bind(void 0,1),void 0,sW.bind(void 0,0),sW.bind(void 0,1),cW,void 0,lW,void 0,void 0,uW,dW,fW,pW,mW,hW,gW,_W,vW,yW,bW,xW,SW,CW.bind(void 0,1),wW,TW,EW,DW,OW,kW,AW,jW,MW,NW,PW.bind(void 0,0),PW.bind(void 0,1),PW.bind(void 0,2),PW.bind(void 0,3),void 0,void 0,void 0,void 0,FW,CW.bind(void 0,2),CW.bind(void 0,3),IW.bind(void 0,1),IW.bind(void 0,2),IW.bind(void 0,3),LW,RW,void 0,void 0,zW,void 0,BW,VW,PU,PU,void 0,void 0,void 0,void 0,void 0,HW,UW.bind(void 0,0),UW.bind(void 0,1),WW,void 0,GW,KW,qW,JW,YW,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,XW.bind(void 0,1),XW.bind(void 0,2),XW.bind(void 0,3),XW.bind(void 0,4),XW.bind(void 0,5),XW.bind(void 0,6),XW.bind(void 0,7),XW.bind(void 0,8),ZW.bind(void 0,1),ZW.bind(void 0,2),ZW.bind(void 0,3),ZW.bind(void 0,4),ZW.bind(void 0,5),ZW.bind(void 0,6),ZW.bind(void 0,7),ZW.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 QW(e){this.char=e,this.state={},this.activeState=null}function $W(e,t,n){this.contextName=n,this.startIndex=e,this.endOffset=t}function eG(e,t,n){this.contextName=e,this.openRange=null,this.ranges=[],this.checkStart=t,this.checkEnd=n}function tG(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 nG(e){this.eventId=e,this.subscribers=[]}function rG(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 nG(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 iG(e){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],rG.call(this,e)}QW.prototype.setState=function(e,t){return this.state[e]=t,this.activeState={key:e,value:this.state[e]},this.activeState},QW.prototype.getState=function(e){return this.state[e]||null},iG.prototype.inboundIndex=function(e){return e>=0&&e<this.tokens.length},iG.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)})])},iG.prototype.replaceRange=function(e,t,n,r){t=t===null?this.tokens.length:t;var i=n.every(function(e){return e instanceof QW});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.`}},iG.prototype.replaceToken=function(e,t,n){if(!isNaN(e)&&this.inboundIndex(e)&&t instanceof QW){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.`}},iG.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},iG.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.`}},iG.prototype.insertToken=function(e,t,n){return e.every(function(e){return e instanceof QW})?(this.tokens.splice.apply(this.tokens,[t,0].concat(e)),n||this.dispatch(`insertToken`,[e,t]),e):{FAIL:`insertToken: invalid token(s).`}},iG.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)},nG.prototype.subscribe=function(e){return typeof e==`function`?this.subscribers.push(e)-1:{FAIL:`invalid '`+this.eventId+`' event handler`}},nG.prototype.unsubscribe=function(e){this.subscribers.splice(e,1)},tG.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)},tG.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}},iG.prototype.rangeToText=function(e){if(e instanceof $W)return this.getRangeTokens(e).map(function(e){return e.char}).join(``)},iG.prototype.getText=function(){return this.tokens.map(function(e){return e.char}).join(``)},iG.prototype.getContext=function(e){return this.registeredContexts[e]||null},iG.prototype.on=function(e,t){var n=this.events[e];return n?n.subscribe(t):null},iG.prototype.dispatch=function(e,t){var n=this,r=this.events[e];r instanceof nG&&r.subscribers.forEach(function(e){e.apply(n,t||[])})},iG.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 eG(e,t,n);return this.registeredContexts[e]=r,this.contextCheckers.push(r),r},iG.prototype.getRangeTokens=function(e){var t=e.startIndex+e.endOffset;return[].concat(this.tokens.slice(e.startIndex,t))},iG.prototype.getContextRanges=function(e){var t=this.getContext(e);return t?t.ranges:{FAIL:`context checker '`+e+`' is not registered.`}},iG.prototype.resetContextsRanges=function(){var e=this.registeredContexts;for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];n.ranges=[]}},iG.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 tG(e,t);this.runContextCheck(n)}this.dispatch(`updateContextsRanges`,[this.registeredContexts])},iG.prototype.setEndOffset=function(e,t){var n=this.getContext(t).openRange.startIndex,r=new $W(n,e,t),i=this.getContext(t).ranges;return r.rangeId=t+`.`+i.length,i.push(r),this.getContext(t).openRange=null,r},iG.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 $W(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])}})},iG.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 tG(t,n);this.dispatch(`next`,[i]),this.runContextCheck(i);var a=new QW(r);this.tokens.push(a),this.dispatch(`newToken`,[a,i])}return this.dispatch(`end`,[this.tokens]),this.tokens};function aG(e){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(e)}function oG(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 sG(e){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(e)}function cG(e){return/[A-z]/.test(e)}function lG(e){return/\s/.test(e)}function uG(e){this.font=e,this.features={}}function dG(e){this.id=e.id,this.tag=e.tag,this.substitution=e.substitution}function fG(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 pG(e,t){return fG(e,t.coverage)===-1?null:e+t.deltaGlyphId}function mG(e,t){var n=fG(e,t.coverage);return n===-1?null:t.substitute[n]}function hG(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=fG(a,i);o!==-1&&n.push(o)}return n.length===e.length?n:-1}function gG(e,t){var n=t.inputCoverage.length+t.lookaheadCoverage.length+t.backtrackCoverage.length;if(e.context.length<n)return[];var r=hG(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&&sG(a[0].char);)a.shift();var o=new tG(a,0),s=hG(t.lookaheadCoverage,o),c=[].concat(e.backtrack);for(c.reverse();c.length&&sG(c[0].char);)c.shift();if(c.length<t.backtrackCoverage.length)return[];var l=new tG(c,0),u=hG(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 _G(e,t){var n=e.current,r=fG(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 vG(e,t){var n=fG(e,t.coverage);return n===-1?null:t.sequences[n]}uG.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[]},uG.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()},uG.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},uG.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},uG.prototype.getSubstitutionType=function(e,t){return e.lookupType.toString()+t.substFormat.toString()},uG.prototype.getLookupMethod=function(e,t){var n=this;switch(this.getSubstitutionType(e,t)){case`11`:return function(e){return pG.apply(n,[e,t])};case`12`:return function(e){return mG.apply(n,[e,t])};case`63`:return function(e){return gG.apply(n,[e,t])};case`41`:return function(e){return _G.apply(n,[e,t])};case`21`:return function(e){return vG.apply(n,[e,t])};default:throw Error(`lookupType: `+e.lookupType+` - substFormat: `+t.substFormat+` is not yet supported`)}},uG.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 dG({id:11,tag:e.tag,substitution:p}));break;case`12`:p=f(t.current),p&&a.splice(n,1,new dG({id:12,tag:e.tag,substitution:p}));break;case`63`:p=f(t),Array.isArray(p)&&p.length&&a.splice(n,1,new dG({id:63,tag:e.tag,substitution:p}));break;case`41`:p=f(t),p&&a.splice(n,1,new dG({id:41,tag:e.tag,substitution:p}));break;case`21`:p=f(t.current),p&&a.splice(n,1,new dG({id:21,tag:e.tag,substitution:p}));break}t=new tG(a,n),!(Array.isArray(p)&&!p.length)&&(p=null)}return a.length?a:null},uG.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},uG.prototype.getLookupSubtables=function(e){return e.subtables||null},uG.prototype.getLookupByIndex=function(e){return this.font.tables.gsub.lookups[e]||null},uG.prototype.getFeatureLookups=function(e){return e.lookupListIndexes.map(this.getLookupByIndex.bind(this))},uG.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 yG(e){var t=e.current,n=e.get(-1);return n===null&&aG(t)||!aG(n)&&aG(t)}function bG(e){var t=e.get(1);return t===null||!aG(t)}var xG={startCheck:yG,endCheck:bG};function SG(e){var t=e.current,n=e.get(-1);return(aG(t)||sG(t))&&!aG(n)}function CG(e){var t=e.get(1);switch(!0){case t===null:return!0;case!aG(t)&&!sG(t):var n=lG(t);if(!n)return!0;if(n){var r=!1;if(r=e.lookahead.some(function(e){return aG(e)||sG(e)}),!r)return!0}break;default:return!1}}var wG={startCheck:SG,endCheck:CG};function TG(e,t,n){t[n].setState(e.tag,e.substitution)}function EG(e,t,n){t[n].setState(e.tag,e.substitution)}function DG(e,t,n){e.substitution.forEach(function(r,i){t[n+i].setState(e.tag,r)})}function OG(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 kG={11:TG,12:EG,63:DG,41:OG};function AG(e,t,n){e instanceof dG&&kG[e.id]&&kG[e.id](e,t,n)}function jG(e){for(var t=[].concat(e.backtrack),n=t.length-1;n>=0;n--){var r=t[n],i=oG(r),a=sG(r);if(!i&&!a)return!0;if(i)return!1}return!1}function MG(e){if(oG(e.current))return!1;for(var t=0;t<e.lookahead.length;t++){var n=e.lookahead[t];if(!sG(n))return!0}return!1}function NG(e){var t=this,n=`arab`,r=this.featuresTags[n],i=this.tokenizer.getRangeTokens(e);if(i.length!==1){var a=new tG(i.map(function(e){return e.getState(`glyphIndex`)}),0),o=new tG(i.map(function(e){return e.char}),0);i.forEach(function(e,s){if(!sG(e.char)){a.setCurrentIndex(s),o.setCurrentIndex(s);var c=0;jG(o)&&(c|=1),MG(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 dG&&(AG(e,i,t),a.context[t]=e.substitution)})}}})}}function PG(e,t){return new tG(e.map(function(e){return e.activeState.value}),t||0)}function FG(e){var t=this,n=`arab`,r=this.tokenizer.getRangeTokens(e),i=PG(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 AG(e,r,a)}),i=PG(r))})}function IG(e){var t=e.current,n=e.get(-1);return n===null&&cG(t)||!cG(n)&&cG(t)}function LG(e){var t=e.get(1);return t===null||!cG(t)}var RG={startCheck:IG,endCheck:LG};function zG(e,t){return new tG(e.map(function(e){return e.activeState.value}),t||0)}function BG(e){var t=this,n=`latn`,r=this.tokenizer.getRangeTokens(e),i=zG(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 AG(e,r,a)}),i=zG(r))})}function VG(e){this.baseDir=e||`ltr`,this.tokenizer=new iG,this.featuresTags={}}VG.prototype.setText=function(e){this.text=e},VG.prototype.contextChecks={latinWordCheck:RG,arabicWordCheck:xG,arabicSentenceCheck:wG};function HG(e){var t=this.contextChecks[e+`Check`];return this.tokenizer.registerContextChecker(e,t.startCheck,t.endCheck)}function UG(){return HG.call(this,`latinWord`),HG.call(this,`arabicWord`),HG.call(this,`arabicSentence`),this.tokenizer.tokenize(this.text)}function WG(){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())})}VG.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},VG.prototype.applyFeatures=function(e,t){if(!e)throw Error(`No valid font was provided to apply features`);this.query||=new uG(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)}},VG.prototype.registerModifier=function(e,t,n){this.tokenizer.registerModifier(e,t,n)};function GG(){if(this.tokenizer.registeredModifiers.indexOf(`glyphIndex`)===-1)throw Error(`glyphIndex modifier is required to apply arabic presentation features.`)}function KG(){var e=this;this.featuresTags.hasOwnProperty(`arab`)&&(GG.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){NG.call(e,t)}))}function qG(){var e=this,t=`arab`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`rlig`)!==-1&&(GG.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){FG.call(e,t)}))}function JG(){var e=this,t=`latn`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`liga`)!==-1&&(GG.call(this),this.tokenizer.getContextRanges(`latinWord`).forEach(function(t){BG.call(e,t)}))}VG.prototype.checkContextReady=function(e){return!!this.tokenizer.getContext(e)},VG.prototype.applyFeaturesToContexts=function(){this.checkContextReady(`arabicWord`)&&(KG.call(this),qG.call(this)),this.checkContextReady(`latinWord`)&&JG.call(this),this.checkContextReady(`arabicSentence`)&&WG.call(this)},VG.prototype.processText=function(e){(!this.text||this.text!==e)&&(this.setText(e),UG.call(this),this.applyFeaturesToContexts())},VG.prototype.getBidiText=function(e){return this.processText(e),this.tokenizer.getText()},VG.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 YG(e){e||={},e.tables=e.tables||{},e.empty||(kH(e.familyName,`When creating a new Font object, familyName is required.`),kH(e.styleName,`When creating a new Font object, styleName is required.`),kH(e.unitsPerEm,`When creating a new Font object, unitsPerEm is required.`),kH(e.ascender,`When creating a new Font object, ascender is required.`),kH(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 jB.GlyphSet(this,e.glyphs||[]),this.encoding=new hB(this),this.position=new SH(this),this.substitution=new CH(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 WH(this)}})}YG.prototype.hasChar=function(e){return this.encoding.charToGlyphIndex(e)!==null},YG.prototype.charToGlyphIndex=function(e){return this.encoding.charToGlyphIndex(e)},YG.prototype.charToGlyph=function(e){var t=this.charToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},YG.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})},YG.prototype.stringToGlyphs=function(e,t){var n=this,r=new VG;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},YG.prototype.nameToGlyphIndex=function(e){return this.glyphNames.nameToGlyphIndex(e)},YG.prototype.nameToGlyph=function(e){var t=this.nameToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},YG.prototype.glyphIndexToName=function(e){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(e):``},YG.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},YG.prototype.defaultRenderOptions={kerning:!0,features:[{script:`arab`,tags:[`init`,`medi`,`fina`,`rlig`]},{script:`latn`,tags:[`liga`,`rlig`]}]},YG.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},YG.prototype.getPath=function(e,t,n,r,i){var a=new Cz;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},YG.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},YG.prototype.getAdvanceWidth=function(e,t,n){return this.forEachGlyph(e,0,0,t,n,function(){})},YG.prototype.draw=function(e,t,n,r,i,a){this.getPath(t,n,r,i,a).draw(e)},YG.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)})},YG.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)})},YG.prototype.getEnglishName=function(e){var t=this.names[e];if(t)return t.en},YG.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},YG.prototype.toTables=function(){return _H.fontToTable(this)},YG.prototype.toBuffer=function(){return console.warn(`Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.`),this.toArrayBuffer()},YG.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},YG.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(EH())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=YR(),l=OH(r);c.writeFileSync(e,l)}},YG.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512},YG.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},YG.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function XG(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 ZG(e,t,n){var r=XG(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 QG(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 $G(e,t,n,r){for(var i=XG(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 eK(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 tK(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(ZG(r,e.axes[r],t));for(var i=0;i<e.instances.length;i++)n.fields=n.fields.concat($G(i,e.instances[i],e.axes,t));return n}function nK(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(QG(e,t+a+d*s,n));for(var f=[],p=t+a+o*s,m=0;m<c;m++)f.push(eK(e,p+m*l,u,n));return{axes:u,instances:f}}var rK={make:tK,parse:nK},iK=function(){return{coverage:this.parsePointer(X.coverage),attachPoints:this.parseList(X.pointer(X.uShortList))}},aK=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()}},oK=function(){return this.parseList(X.pointer(aK))},sK=function(){return{coverage:this.parsePointer(X.coverage),ligGlyphs:this.parseList(X.pointer(oK))}},cK=function(){return this.parseUShort(),this.parseList(X.pointer(X.coverage))};function lK(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(iK),ligCaretList:n.parsePointer(sK),markAttachClassDef:n.parsePointer(X.classDef)};return r>=1.2&&(i.markGlyphSets=n.parsePointer(cK)),i}var uK={parse:lK},dK=Array(10);dK[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.`)},dK[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)}}))}}},dK[3]=function(){return{error:`GPOS Lookup 3 not supported`}},dK[4]=function(){return{error:`GPOS Lookup 4 not supported`}},dK[5]=function(){return{error:`GPOS Lookup 5 not supported`}},dK[6]=function(){return{error:`GPOS Lookup 6 not supported`}},dK[7]=function(){return{error:`GPOS Lookup 7 not supported`}},dK[8]=function(){return{error:`GPOS Lookup 8 not supported`}},dK[9]=function(){return{error:`GPOS Lookup 9 not supported`}};function fK(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(dK)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(dK),variations:n.parseFeatureVariationsList()}}var pK=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,pK)}])}var hK={parse:fK,make:mK};function gK(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 _K(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 vK(e,t){var n=new Z.Parser(e,t),r=n.parseUShort();if(r===0)return gK(n);if(r===1)return _K(n);throw Error(`Unsupported kern table version (`+r+`).`)}var yK={parse:vK};function bK(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 xK={parse:bK};function SK(e,t){YR().readFile(e,function(e,n){if(e)return t(e.message);t(null,DH(n))})}function CK(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 wK(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 TK(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 EK(e,t){if(t.compression===`WOFF`){var n=new Uint8Array(e.buffer,t.offset+2,t.compressedLength-2),r=new Uint8Array(t.length);if(bz(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 DK(e,t){t??={};var n,r,i=new YG({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=wK(a,o);else if(c===`OTTO`)i.outlinesFormat=`cff`,o=Z.getUShort(a,4),s=wK(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=TK(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=EK(a,C),i.tables.cmap=uB.parse(w.data,w.offset),i.encoding=new gB(i.tables.cmap);break;case`cvt `:w=EK(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=EK(a,C),x=new Z.Parser(w.data,w.offset),i.tables.fpgm=x.parseByteList(C.length);break;case`head`:w=EK(a,C),i.tables.head=gV.parse(w.data,w.offset),i.unitsPerEm=i.tables.head.unitsPerEm,n=i.tables.head.indexToLocFormat;break;case`hhea`:w=EK(a,C),i.tables.hhea=yV.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=EK(a,C),r=DV.parse(w.data,w.offset);break;case`maxp`:w=EK(a,C),i.tables.maxp=AV.parse(w.data,w.offset),i.numGlyphs=i.tables.maxp.numGlyphs;break;case`name`:y=C;break;case`OS/2`:w=EK(a,C),i.tables.os2=ZV.parse(w.data,w.offset);break;case`post`:w=EK(a,C),i.tables.post=eH.parse(w.data,w.offset),i.glyphNames=new vB(i.tables.post);break;case`prep`:w=EK(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=EK(a,y);if(i.tables.name=KV.parse(ee.data,ee.offset,r),i.names=i.tables.name,f&&v){var te=n===0,ne=EK(a,v),re=xK.parse(ne.data,ne.offset,i.numGlyphs,te),ie=EK(a,f);i.glyphs=zH.parse(ie.data,ie.offset,re,i,t)}else if(u){var ae=EK(a,u);pV.parse(ae.data,ae.offset,i,t)}else throw Error(`Font doesn't contain TrueType or CFF outlines.`);var oe=EK(a,g);if(wV.parse(i,oe.data,oe.offset,i.numberOfHMetrics,i.numGlyphs,i.glyphs,t),xB(i,t),_){var se=EK(a,_);i.kerningPairs=yK.parse(se.data,se.offset)}else i.kerningPairs={};if(p){var ce=EK(a,p);i.tables.gdef=uK.parse(ce.data,ce.offset)}if(m){var le=EK(a,m);i.tables.gpos=hK.parse(le.data,le.offset),i.position.init()}if(h){var ue=EK(a,h);i.tables.gsub=oH.parse(ue.data,ue.offset)}if(d){var de=EK(a,d);i.tables.fvar=rK.parse(de.data,de.offset,i.names)}if(b){var fe=EK(a,b);i.tables.meta=lH.parse(fe.data,fe.offset),i.metas=i.tables.meta}return i}function OK(e,t,n){n??={};var r=typeof window>`u`&&!n.isUrl?SK:CK;return new Promise(function(i,a){r(e,function(e,r){if(e){if(t)return t(e);a(e)}var o;try{o=DK(r,n)}catch(e){if(t)return t(e,null);a(e)}if(t)return t(null,o);i(o)})})}function kK(e,t){return DK(DH(YR().readFileSync(e)),t)}var AK=Object.freeze({__proto__:null,Font:YG,Glyph:TB,Path:Cz,BoundingBox:Sz,_parse:Z,parse:DK,load:OK,loadSync:kK}),jK=class e{sketches;constructor(e){e.length===0&&M(`CompoundSketch`,`Cannot create CompoundSketch with an empty array of sketches`),this.sketches=e}delete(){this.sketches.forEach(e=>{e.delete()})}get outerSketch(){return oA(this.sketches)}get innerSketches(){return this.sketches.slice(1)}get wires(){return UK(this)}face(){return HK(this)}extrude(e,t={}){return WK(this,e,t)}revolve(e,t={}){return GK(this,e,t)}loftWith(t,n={}){return Array.isArray(t)||!(t instanceof e)?M(`CompoundSketch.loftWith`,`A compound (face-with-holes) sketch can only loft to another compound sketch with the same number of sub-sketches.`):KK(this,t,n)}sweepSketch(){return M(`CompoundSketch.sweepSketch`,`Sweeping a compound (face-with-holes) profile is not supported — sweep its outer Sketch instead.`)}};function MK(e){let t={};e.defaultOrigin&&(t.defaultOrigin=e.defaultOrigin),e.defaultDirection&&(t.defaultDirection=e.defaultDirection);let n=new qK(e.wire,t);return e.baseFace&&(n.baseFace=e.baseFace),n}function NK(e){return new jK(e.map(MK))}function PK(e){if(e instanceof qK)return e;let t=e.sketches;if(Array.isArray(t)){let[e,...n]=t;if(e instanceof qK){for(let e of n)e.delete();return e}}M(`asSketch`,`Expected a single-wire profile to loft or sweep.`)}function FK(e){let t;return t=e.baseFace?CA(e.baseFace,e.wire):j(xA(e.wire)),t}function IK(e){return gE(j($D(e.wire.wrapped)))}function LK(e,t,{origin:n}={}){let r=j(xA(e.wire)),i=j(_M(r,n?vD(n):e.defaultOrigin,t?vD(t):[0,0,1]));return r[Symbol.dispose](),e.delete(),i}function RK(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=wD(jD(n?vD(n):e.defaultDirection),t),s=a?vD(a):e.defaultOrigin;if(r&&!i){let t=j(uM(e.wire,[...s],[...o],r));return e.delete(),t}if(i){let t=j(dM(e.wire,i,[...s],[...o],r));return e.delete(),t}let c=j(xA(e.wire)),l=j(gM(c,[...o]));return c[Symbol.dispose](),e.delete(),l}function zK(e,t,n={}){let r=bk(e.wire),i=jD(wD(Ck(e.wire,1e-9),-1)),a=e.defaultDirection,o=wD(DD(i,a),-1),s=PK(t(zD([...r],[...o],[...i]),[...r])),c={forceProfileSpineOthogonality:!0,...n};e.baseFace&&(c.support=e.baseFace.wrapped);let l=j(cM(s.wire,e.wire,c));return e.delete(),l}function BK(e,t,n={},r=!1){let i=[e,...(Array.isArray(t)?t:[t]).map(PK)],a=j(yM(i.map(e=>e.wire),n,r));return i.forEach(e=>{e.delete()}),a}var VK=(e,t)=>{let n=j(t(oA(e))),r=e.slice(1).map(e=>j(t(e)));if(r.length===0)return n;try{return j(PA(n,r,{unsafe:!0}))}finally{n.delete();for(let e of r)e.delete()}};function HK(e){let t=e.outerSketch.face(),n=TA(t,e.innerSketches.map(e=>e.wire));return t[Symbol.dispose](),n}function UK(e){return nj(e.sketches.map(e=>e.wire))}function WK(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=wD(jD(n?vD(n):e.outerSketch.defaultDirection),t);if(r&&!i)return VK(e.sketches,t=>uM(t.wire,a?vD(a):e.outerSketch.defaultOrigin,o,r));if(i)return VK(e.sketches,t=>dM(t.wire,i,a?vD(a):e.outerSketch.defaultOrigin,o,r));let s=HK(e),c=j(gM(s,o));return s[Symbol.dispose](),c}function GK(e,t,{origin:n}={}){let r=n?vD(n):e.outerSketch.defaultOrigin,i=t?vD(t):[0,0,1],a=HK(e),o=j(_M(a,r,i));return a[Symbol.dispose](),o}function KK(e,t,n={}){e.sketches.length!==t.sketches.length&&M(`CompoundSketch.loftWith`,`You need to loft with another compound with the same number of sketches`);let r=e.sketches.map((e,r)=>{let i=aA(t.sketches,r),a={};return n.ruled!==void 0&&(a.ruled=n.ruled),e.clone().loftWith(i.clone(),a,!0)}),i=HK(e),a=_E(j($D(i.wrapped)));i[Symbol.dispose](),r.push(a,HK(t));let o=j(rj(r));for(let e of r)e[Symbol.dispose]();return o}var qK=class e{wire;_defaultOrigin;_defaultDirection;_baseFace;constructor(e,{defaultOrigin:t=[0,0,0],defaultDirection:n=[0,0,1]}={}){this.wire=e,this._defaultOrigin=vD(t),this._defaultDirection=vD(n),this.baseFace=null}get baseFace(){return this._baseFace}set baseFace(e){this._baseFace&&this._baseFace[Symbol.dispose](),this._baseFace=e&&_E(j($D(e.wrapped)))}delete(){this.wire[Symbol.dispose](),this.baseFace&&this.baseFace[Symbol.dispose]()}clone(){let t=gE(j($D(this.wire.wrapped))),n=new e(t,{defaultOrigin:this.defaultOrigin,defaultDirection:this.defaultDirection});return this.baseFace&&(n.baseFace=_E(j($D(this.baseFace.wrapped)))),n}get defaultOrigin(){return this._defaultOrigin}set defaultOrigin(e){this._defaultOrigin=vD(e)}get defaultDirection(){return this._defaultDirection}set defaultDirection(e){this._defaultDirection=vD(e)}face(){return FK(this)}wires(){return IK(this)}faces(){return this.face()}revolve(e,t={}){return LK(this,e,t)}extrude(e,t={}){return RK(this,e,t)}sweepSketch(e,t={}){return zK(this,e,t)}loftWith(e,t={},n=!1){return BK(this,e,t,n)}},JK=class{sketches;constructor(e){this.sketches=e}soleSketch(e){this.sketches.length!==1&&M(`Sketches.${e}`,`Multiple profiles — ${e} each sub-sketch individually.`);let t=oA(this.sketches);return t instanceof qK||M(`Sketches.${e}`,`${e} is only supported on single-wire profiles.`),t}face(){return this.sketches.length!==1&&M(`Sketches.face`,`Multiple profiles — use faces() to combine them.`),oA(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 nj(this.sketches.flatMap(e=>e instanceof qK?[e.wire]:e.sketches.map(e=>e.wire)))}faces(){return nj(this.sketches.map(e=>e.face()))}extrude(e,t={}){return nj(this.sketches.map(n=>n.extrude(e,t)))}revolve(e,t){return nj(this.sketches.map(n=>n.revolve(e,t)))}},YK={};async function XK(e,t=`default`,n=!1){if(!n&&YK[t])return O(YK[t]);let r;if(typeof e==`string`){let t;try{t=await fetch(e)}catch(t){return k(vo(N.FONT_FETCH_FAILED,`Failed to fetch font from ${e}: ${t instanceof Error?t.message:String(t)}`,t))}if(!t.ok)return k(vo(N.FONT_FETCH_FAILED,`Failed to fetch font from ${e}: HTTP ${t.status} ${t.statusText}`));r=await t.arrayBuffer()}else r=e;let i;try{i=AK.parse(r)}catch(e){return k(vo(N.FONT_PARSE_FAILED,`Failed to parse font data: ${e instanceof Error?e.message:String(e)}`,e))}let a=i;return YK[t]=a,YK.default||=a,O(a)}var ZK=(e=`default`)=>YK[e],QK=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 nR,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 $K(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:i=`default`}={}){let a=ZK(i);a||=ZK(),a||M(`text`,`No fonts loaded. Call loadFont() before using text functions.`);let o=a.getPath(e,-t,-n,r);return GL(Array.from(QK(o.commands))).mirror([0,0])}var eq={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 tq(e){return typeof e==`string`&&e in eq}var nq=e=>{try{var t=OT();return e.IsNull()?[]:XE(t.u(W(e))).map(e=>j(fk(e)))}catch(e){t.e=e}finally{t.d()}};function rq(e,t,n=!0){let r=U().projectEdges(e.wrapped,[...t.position],[...t.direction],[...t.xAxis]),i=[...nq(r.visible.sharp),...nq(r.visible.smooth),...nq(r.visible.outline)],a=[...nq(r.hidden.sharp),...nq(r.hidden.smooth),...nq(r.hidden.outline)],o;if(n)o=a;else{for(let e of a)e[Symbol.dispose]();o=[]}return{visible:i,hidden:o}}function iq(e=[0,0,0],t=[0,0,1],n){if(OD(t)<1e-12)return k(F(`CAMERA_ZERO_DIRECTION`,`Camera direction cannot be a zero-length vector`));let r;if(n)r=jD(n);else{let e=DD([0,0,1],t);OD(e)<1e-12&&(e=DD([0,1,0],t)),OD(e)<1e-12&&(e=DD([1,0,0],t)),r=jD(e)}let i=jD(DD(t,r));return O({position:e,direction:jD(t),xAxis:r,yAxis:i})}function aq(e,t){let n=jD(CD(e.position,t));return iq(e.position,n)}function oq(e){let t=eq[e];return iq([0,0,0],t.dir,t.xAxis)}function sq(e,t,n=!0){return rq(e,t,n)}var cq=(e,n=1e-7)=>{if(e.length===0)return[];let r=new TL(e.length);e.forEach(e=>{let[t,i]=e.firstPoint;r.add(t-n,i-n,t+n,i+n)}),r.finish();let i=[],a=new Set;return e.forEach((o,s)=>{if(a.has(s))return;let c=[o],l=s;a.add(s);let u=e.length;for(;;){u--<0&&M(`stitchCurves`,`Infinite loop detected`);let[o,s]=t(c,c.length-1).lastPoint,d=r.search(o-n,s-n,o+n,s+n),f=t=>Math.abs((l-t)%e.length),p=d.filter(e=>!a.has(e)).map(n=>[t(e,n),n,f(n)]).sort(([,,e],[,,t])=>e-t);if(p.length===0){i.push(c);break}let[m,h]=t(p,0);c.push(m),a.add(h),l=h}}),i},lq=class extends tR{plane;constructor(e,t){super(),this.plane=e&&typeof e!=`string`?{...e}:j(HD(e??`XY`,t))}delete(){this.pendingCurves=[]}sagittaArcTo(e,t){return super.sagittaArcTo(e,-t)}buildWire(){try{var e=OT();this.pendingCurves.length||M(`Sketcher.buildWire`,`No lines to convert into a wire`);let t=e.u(new BT);return j(bA(cL(this.pendingCurves,this.plane).map(e=>t.register(e))))}catch(t){e.e=t}finally{e.d()}}done(){return new qK(this.buildWire(),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}close(){return this._closeSketch(),this.done()}closeWithMirror(){uI(this.pointer,this.firstPoint)&&M(`Sketcher.closeWithMirror`,`Cannot close with a mirror when the sketch is already closed`);let e=this.buildWire(),t=WD(this.plane,this.pointer),n=DD(jD(CD(t,WD(this.plane,this.firstPoint))),this.plane.zDir),r=j(QD(e.wrapped));return new qK(j(bA([e,gE(j(QD(U().mirror(r,vD(t),vD(n)))))])),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}closeWithCustomCorner(e,t=`fillet`){return this._closeSketch(),this._customCornerLastWithFirst(e,t),this.done()}},uq=class extends tR{face;_bounds;constructor(e,t=[0,0]){super(t),this.face=_E(j($D(e.wrapped))),this._bounds=cO(e)}_convertToUV([e,t]){let{uMin:n,uMax:r,vMin:i,vMax:a}=this._bounds;return[n+e*(r-n),i+t*(a-i)]}_convertFromUV([e,t]){let{uMin:n,uMax:r,vMin:i,vMax:a}=this._bounds;return[(e-n)/(r-n),(t-i)/(a-i)]}_adaptSurface(){return U().extractSurfaceFromFace(this.face.wrapped)}buildWire(){let e=U(),t=this._adaptSurface(),n=j(bA(this.pendingCurves.map(n=>hE(e.buildEdgeOnSurface(n.wrapped,t)))));return e.buildCurves3d(n.wrapped),n}done(){try{var e=OT();let t=e.u(new BT),n=this.buildWire(),r=new qK(n);if(Ek(n)){let e=t.register(r.clone().face()),n=lO(e,.5,.5),i=wD(fO(e),-1);r.defaultOrigin=[n[0],n[1],n[2]],r.defaultDirection=[i[0],i[1],i[2]]}else{let e=bk(n),t=fO(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()}},dq=(e,t={})=>{try{var n=OT();let r=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(HD(t.plane??`XY`,t.origin));return new qK(j(bA([n.u(new BT).register(dA(e,r.origin,r.zDir))])),{defaultOrigin:[...r.origin],defaultDirection:[...r.zDir]})}catch(e){n.e=e}finally{n.d()}},fq=(e=1,t=2,n={})=>{try{var r=OT();let i=n.plane&&typeof n.plane!=`string`?{...n.plane}:j(HD(n.plane??`XY`,n.origin)),a=i.xDir,o=e,s=t;return t>e&&(a=ID(a,i.zDir,90*gD),o=t,s=e),new qK(j(bA([r.u(new BT).register(j(fA(o,s,i.origin,i.zDir,a)))])),{defaultOrigin:[...i.origin],defaultDirection:[...i.zDir]})}catch(e){r.e=e}finally{r.d()}},pq=(e,t,n={})=>(n.plane&&typeof n.plane!=`string`?new lq(n.plane):new lq(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=lR(e,t,n).sketchOnPlane(r.plane,r.origin),a={};return i.defaultOrigin&&(a.defaultOrigin=i.defaultOrigin),i.defaultDirection&&(a.defaultDirection=i.defaultDirection),new qK(i.wire,a)},hq=(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 lq(r.plane):new lq(r.plane,r.origin),o=sA(i),s=a.movePointerTo([aA(o,0),aA(o,1)]);return n?i.forEach(e=>s.sagittaArcTo([aA(e,0),aA(e,1)],n)):i.forEach(e=>s.lineTo([aA(e,0),aA(e,1)])),s.done()},gq=(e,t,n=0)=>{let r=Math.PI/t,i=Math.cos(r)*e;return n>=0?i:i+n},_q=(e,t)=>{let n=[...pO(e)],r=[...fO(e)];return new qK(j(Nk(gO(e),t)),{defaultOrigin:n,defaultDirection:r})},vq=(e,t={},{pointsCount:n=400,start:r=0,stop:i=1}={},a={})=>{try{var o=OT();let s=o.u(new BT),c=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(HD(t.plane??`XY`,t.origin)),l=(i-r)/n,u=[...Array(n+1).keys()].map(t=>{let n=e(r+t*l);return WD(c,n)});return new qK(j(bA([s.register(j(gA(u,a)))])),{defaultOrigin:[...c.origin],defaultDirection:[...c.zDir]})}catch(e){o.e=e}finally{o.d()}},yq=(e,t,n,r=[0,0,0],i=[0,0,1],a=!1)=>new qK(j(bA([pA(e,t,n,vD(r),vD(i),a)]))),bq=(e,t,n)=>new lq().movePointerTo([-e/2,t/2]).hLine(e).vLine(-t).hLine(-e).close().extrude(n),xq=(e,t)=>uI(e,t,cI*100),Sq=(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 Cq(e,t,n,r,i){let a=aL(t,n,r.original.lastPoint);e(r),e(a)}function wq(e,t,n,r,i){let a=ZI(t,n);e(r),e(a)}function Tq(e,t,n,r,i){let a=Sq(r.offset instanceof qI?fI(t,r.offset.tangentAt(1)):r.offset.firstPoint,t,n,i.offset instanceof qI?dI(n,i.offset.tangentAt(0)):i.offset.lastPoint);if(!a){let i=ZI(t,n);e(r),e(i);return}let o=hI([(t[0]+n[0])/2,(t[1]+n[1])/2],a),s=hI(t,n);if(s<1e-18||o>16*s){let i=ZI(t,n);e(r),e(i);return}let c=ZI(t,a),l=ZI(a,n);e(r),e(c),e(l)}var Eq={round:Cq,bevel:wq,miter:Tq};function Dq(e,t,n){let r=n.length===1?xo(n,0,`rawOffsets`):Oq(n,e.original.lastPoint),i=xo(e.offset.splitAt([r],cI),0,`rawOffsets`),a=t.offset.splitAt([r],cI).at(-1);return a||M(`offset.rawOffsets`,`Split produced no trailing curve segment`),{splitPrevious:{offset:i,original:e.original},splitCurrent:{offset:a,original:t.original}}}function Oq(e,t){let n=xo(e,0,`selectClosestIntersection`),r=hI(n,t);for(let i=1;i<e.length;i++){let a=xo(e,i,`selectClosestIntersection`),o=hI(a,t);o<r&&(r=o,n=a)}return n}function kq(e){let t=new Map,n=(e,n)=>{let r=t.get(e)||[];t.set(e,[...r,...n])},r=new TL(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=xo(e,r,`offsetBlueprint`),{intersections:o,commonSegmentsPoints:s}=j(AL(t,a,cI)),c=[...o,...s].filter(e=>{let n=xq(e,t.firstPoint)||xq(e,t.lastPoint),r=xq(e,a.firstPoint)||xq(e,a.lastPoint);return!(n&&r)});c.length&&(n(i,c),n(r,c))}}),t}function Aq(e,t,n={}){let r=e.orientation===`clockwise`?-t:t,i=e.curves.map(e=>({offset:NL(e,r),original:e})),a=[],o=null,s=i.at(-1);if(!s)return[];function c(e){if(e instanceof qI){a.push(e);return}o?e.offset instanceof qI?a.push(e.offset):xq(e.offset.firstPoint,e.offset.lastPoint)||a.push(ZI(e.offset.firstPoint,e.offset.lastPoint)):o=e}let l=function*(){for(let e of i.slice(0,-1))yield e;o||M(`offset.rawOffsets`,`No saved curve after iterating offset segments`),yield o};for(let e of l()){let t=s.offset.lastPoint,r=e.offset.firstPoint;if(xq(t,r)){c(s),s=e;continue}let i=[];if(s.offset instanceof qI&&e.offset instanceof qI){let{intersections:t,commonSegmentsPoints:n}=j(AL(s.offset,e.offset,cI/100));i=[...t,...n]}if(i.length>0){let{splitPrevious:t,splitCurrent:n}=Dq(s,e,i);c(t),s=n;continue}let a=Eq[n.lineJoinType??`round`];a(c,t,r,s,e),s=e}return c(s),a}function jq(e,n,r={}){let i=Aq(e,n,r);if(i.length<2)return null;let a=kq(i);if(!a.size){let t=new xL(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,cI*100)}),s=new TL(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-cI)});if(!l.length)return null;let u=cq(l).filter(e=>e.length>1).map(e=>new xL(e)).filter(e=>e.isClosed());return u.length?u.length===1?xo(u,0,`offsetBlueprint`):new RL(u):null}var Mq=e=>{let t=xo(e,0,`fuseAll`);for(let n=1;n<e.length;n++)t=GR(t,xo(e,n,`fuseAll`));return t};function Nq(e,t,n={}){if(e instanceof xL)return jq(e,t,n);if(e instanceof RL)return Mq(e.blueprints.map(e=>Nq(e,t,n)));if(e instanceof zL){let r=Mq(e.blueprints.slice(1).map(e=>Nq(e,-t,n)));return qR(Nq(xo(e.blueprints,0,`offset`),t,n),r)}return null}function Pq(e,t){return e instanceof xL?new xL(XI(e.curves,t)):e instanceof zL?new zL(e.blueprints.map(e=>Pq(e,t))):e instanceof RL?new RL(e.blueprints.map(e=>Pq(e,t))):e}function Fq(e,t,n,r){let i=()=>!0;r&&(i=r.shouldKeep.bind(r));let a=[oA(t.curves)],o=(t,r)=>{i({firstCurve:t,secondCurve:r,point:t.lastPoint})?a.push(...e(t,r,n)):a.push(t,r)};t.curves.slice(1).forEach(e=>{let t=a.pop();t||M(`customCorners.modifyCorners`,`Unexpected empty curve stack during filleting`),o(t,e)});let s=a.at(-1);if(s||M(`customCorners.modifyCorners`,`Unexpected empty curve list during corner modification`),uI(oA(a).firstPoint,s.lastPoint)&&a.length>1){let e=a.pop(),t=a.shift();(!e||!t)&&M(`customCorners.modifyCorners`,`Unexpected empty curve stack during close-and-fillet`),o(e,t)}return new xL(a)}function Iq(e,t,n,r){return t instanceof xL?Fq(e,t,n,r):t instanceof zL?new zL(t.blueprints.map(t=>Fq(e,t,n,r))):t instanceof RL?new RL(t.blueprints.map(t=>Iq(e,t,n,r)).filter(e=>e!==null)):null}function Lq(e,t,n){return Iq(FL,e,t,n)}function Rq(e,t,n){return Iq(IL,e,t,n)}function zq(e,t){return e instanceof xL?MK(t):e instanceof zL?NK(t):new JK(t.map(e=>Array.isArray(e)?NK(e):MK(e)))}var Bq=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 zL)return{type:`CompoundBlueprint`,blueprints:t.blueprints.map(e)};if(t instanceof RL)return{type:`Blueprints`,blueprints:t.blueprints.map(e)};if(t instanceof xL)return{type:`Blueprint`,curves:t.curves.map(e=>e.serialize())};M(`Drawing.serialize`,`Unknown shape type for serialization`)}return JSON.stringify(e(this.innerShape))}get boundingBox(){return this.innerShape?this.innerShape.boundingBox:new GI}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(qR(this.innerShape,t.innerShape))}fuse(t){return new e(GR(this.innerShape,t.innerShape))}intersect(t){return new e(JR(this.innerShape,t.innerShape))}fillet(t,n){let r=n&&n(sR());return new e(Lq(this.innerShape,t,r))}chamfer(t,n){let r=n&&n(sR());return new e(Rq(this.innerShape,t,r))}sketchOnPlane(e,t){this.innerShape||M(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnPlane(e,t);return zq(this.innerShape,n)}sketchOnFace(e,t){this.innerShape||M(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnFace(e,t);return zq(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(Nq(this.innerShape,t,n))}approximate(t,n={}){return t!==`svg`&&M(`Drawing.approximate`,`Only 'svg' is supported for now`),new e(Pq(this.innerShape,n))}get blueprint(){if(!(this.innerShape instanceof xL)){if(this.innerShape instanceof RL&&this.innerShape.blueprints.length===1&&this.innerShape.blueprints[0]instanceof xL)return this.innerShape.blueprints[0];M(`Drawing.blueprint`,`This drawing is not a blueprint`)}return this.innerShape}};function Vq(e){function t(e){if(e.type===`CompoundBlueprint`)return new zL(e.blueprints.map(t));if(e.type===`Blueprints`)return new RL(e.blueprints.map(t));if(e.type===`Blueprint`)return new xL(e.curves.map(e=>KI(e)));M(`Drawing.deserialize`,`Unknown shape type for deserialization`)}return new Bq(t(JSON.parse(e)))}var Hq=class extends tR{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new Bq(new xL(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 Uq(e){let t=new Hq;return e&&t.movePointerTo(e),t}function Wq(e,t,n=0){return new Bq(lR(e,t,n))}var Gq=Wq;function Kq(e){return new Bq(new xL([eL(e)]))}function qq(e,t){let[n,r]=[e,t].sort((e,t)=>e-t);return new Bq(new xL([tL(r,n,r===e?[1,0]:[0,1])]))}function Jq(e){return Uq().movePointerTo([-e,0]).sagittaArc(2*e,0,e).sagittaArc(-2*e,0,e).close()}function Yq(e,t){return Uq().movePointerTo([-e,0]).halfEllipse(2*e,0,t).halfEllipse(-2*e,0,t).close()}function Xq(e,t,n=0){return new Bq(cR(e,t,n))}function Zq(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:i=`default`}={}){return new Bq($K(e,{startX:t,startY:n,fontSize:r,fontFamily:i}))}var Qq=(e,t={},n={})=>{e.length<2&&M(`drawPointsInterpolation`,`Need at least 2 points for interpolation, got ${e.length}`);let r=[j(iL(e,t))],i=e[0],a=e[e.length-1];return n.closeShape&&i&&a&&!uI(i,a)&&r.push(ZI(a,i)),new Bq(new xL(r))},$q=(e,{pointsCount:t=400,start:n=0,stop:r=1,closeShape:i=!1}={},a={})=>{let o=(r-n)/t;return Qq([...Array(t+1).keys()].map(t=>e(n+t*o)),a,{closeShape:i})},eJ=e=>{try{var t=OT();let n=t.u(new BT),r=Gq(1e3,1e3).sketchOnPlane();n.register(r.wire);let i=n.register(j(xA(r.wire))),a=cq(e.map(e=>_L(e,i))).map(e=>new xL(e));return a.length===0?new Bq:a.length===1?new Bq(a[0]):new Bq(new RL(a))}catch(e){t.e=e}finally{t.d()}};function tJ(e,t=`front`){let n;n=typeof t==`string`?j(oq(t)):t;let{visible:r,hidden:i}=sq(e,n);try{return{visible:eJ(r),hidden:eJ(i)}}finally{for(let e of r)e[Symbol.dispose]();for(let e of i)e[Symbol.dispose]()}}function nJ(e){try{var t=OT();let n=t.u(new BT),r=n.register(_E(j($D(e.wrapped)))),i=cq(XE(n.register(gO(r))).map(t=>_L(t,e))).map(e=>new xL(e));return i.length===0?new Bq:i.length===1?new Bq(i[0]):new Bq(new RL(i))}catch(e){t.e=e}finally{t.d()}}function rJ(e,t,n){return n===void 0?e.sketchOnPlane(t):e.sketchOnPlane(t,n)}function iJ(e,t){return e.fuse(t)}function aJ(e,t){return e.cut(t)}function oJ(e,t){return e.intersect(t)}function sJ(e,t,n){return e.fillet(t,n)}function cJ(e,t,n){return e.chamfer(t,n)}function lJ(e,t,n=0){return typeof t==`number`?e.translate(t,n):e.translate(t)}function uJ(e,t,n){return e.rotate(t,n)}function dJ(e,t,n){return e.scale(t,n)}function fJ(e,t,n,r){return e.mirror(t,n,r)}function pJ(e){let t=e.clone();return t.reverse(),t}function mJ(e){return e.boundingBox}function hJ(e){return e.firstPoint}function gJ(e){return e.lastPoint}function _J(e,t,n){return e.splitAt(t,n)}function vJ(e,t,n){return e.parameter(t,n)}function yJ(e,t){return e.tangentAt(t)}function bJ(e,t){return e.isOnCurve(t)}function xJ(e,t){return e.distanceFrom(t)}function SJ(e){return e.length===0?k(F(N.BLUEPRINT_EMPTY_CURVES,`createBlueprint: at least one curve is required`)):O(new xL(e))}function CJ(e){return e.length===0?k(F(N.COMPOUND_BLUEPRINT_EMPTY,`createCompoundBlueprint: at least one blueprint (outer boundary) is required`)):O(new zL(e))}function wJ(e){return e.boundingBox}function TJ(e){return e.orientation}function EJ(e,t){return e.isInside(t)}function DJ(e){return e.toSVGPathD()}function OJ(e,t,n){return e.translate(t,n)}function kJ(e,t,n){return e.rotate(t,n)}function AJ(e,t,n){return e.scale(t,n)}function jJ(e,t,n,r){return e.mirror(t,n,r)}function MJ(e,t,n,r){return e.stretch(t,n,r)}function NJ(e,t,n){return e.sketchOnPlane(t,n)}function PJ(e,t,n){return e.sketchOnFace(t,n)}function FJ(e,t){return n(e,t*3)}function IJ(e,t){return n(e,t)}function LJ(e){let t=[`# brepjs OBJ export`],n=e.vertices.length/3;for(let r=0;r<n;r++){let[n,i,a]=FJ(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]=FJ(e.normals,n);t.push(`vn ${r} ${i} ${a}`)}let i=n=>{let[r,i,a]=IJ(e.triangles,n);t.push(`f ${r+1}//${r+1} ${i+1}//${i+1} ${a+1}//${a+1}`)};if(e.faceGroups.length>0)for(let n of e.faceGroups){t.push(`g face_${n.faceId}`);let e=n.count/3;for(let t=0;t<e;t++)i(n.start+t*3)}else{let t=e.triangles.length/3;for(let e=0;e<t;e++)i(e*3)}return t.join(`
24
+ String.prototype.codePointAt||(function(){var e=function(){try{var e={},t=Object.defineProperty,n=t(e,e,e)&&t}catch{}return n}(),t=function(e){if(this==null)throw TypeError();var t=String(this),n=t.length,r=e?Number(e):0;if(r!=r&&(r=0),!(r<0||r>=n)){var i=t.charCodeAt(r),a;return i>=55296&&i<=56319&&n>r+1&&(a=t.charCodeAt(r+1),a>=56320&&a<=57343)?(i-55296)*1024+a-56320+65536:i}};e?e(String.prototype,`codePointAt`,{value:t,configurable:!0,writable:!0}):String.prototype.codePointAt=t})();var tz=0,nz=-3;function rz(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function iz(e,t){this.source=e,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=t,this.destLen=0,this.ltree=new rz,this.dtree=new rz}var az=new rz,oz=new rz,sz=new Uint8Array(30),cz=new Uint16Array(30),lz=new Uint8Array(30),uz=new Uint16Array(30),dz=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),fz=new rz,pz=new Uint8Array(320);function mz(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 hz(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 gz=new Uint16Array(16);function _z(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)gz[i]=a,a+=e.table[i];for(i=0;i<r;++i)t[n+i]&&(e.trans[gz[t[n+i]]++]=i)}function vz(e){e.bitcount--||(e.tag=e.source[e.sourceIndex++],e.bitcount=7);var t=e.tag&1;return e.tag>>>=1,t}function yz(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 bz(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 xz(e,t,n){var r=yz(e,5,257),i=yz(e,5,1),a=yz(e,4,4),o,s,c;for(o=0;o<19;++o)pz[o]=0;for(o=0;o<a;++o){var l=yz(e,3,0);pz[dz[o]]=l}for(_z(fz,pz,0,19),s=0;s<r+i;){var u=bz(e,fz);switch(u){case 16:var d=pz[s-1];for(c=yz(e,2,3);c;--c)pz[s++]=d;break;case 17:for(c=yz(e,3,3);c;--c)pz[s++]=0;break;case 18:for(c=yz(e,7,11);c;--c)pz[s++]=0;break;default:pz[s++]=u;break}}_z(t,pz,0,r),_z(n,pz,r,i)}function Sz(e,t,n){for(;;){var r=bz(e,t);if(r===256)return tz;if(r<256)e.dest[e.destLen++]=r;else{var i,a,o,s;for(r-=257,i=yz(e,sz[r],cz[r]),a=bz(e,n),o=e.destLen-yz(e,lz[a],uz[a]),s=o;s<o+i;++s)e.dest[e.destLen++]=e.dest[s]}}}function Cz(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 nz;for(e.sourceIndex+=4,r=t;r;--r)e.dest[e.destLen++]=e.source[e.sourceIndex++];return e.bitcount=0,tz}function wz(e,t){var n=new iz(e,t),r,i,a;do{switch(r=vz(n),i=yz(n,2,0),i){case 0:a=Cz(n);break;case 1:a=Sz(n,az,oz);break;case 2:xz(n,n.ltree,n.dtree),a=Sz(n,n.ltree,n.dtree);break;default:a=nz}if(a!==tz)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}hz(az,oz),mz(sz,cz,4,3),mz(lz,uz,2,1),sz[28]=0,cz[28]=258;var Tz=wz;function Ez(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 Dz(){this.x1=NaN,this.y1=NaN,this.x2=NaN,this.y2=NaN}Dz.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)},Dz.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))},Dz.prototype.addX=function(e){this.addPoint(e,null)},Dz.prototype.addY=function(e){this.addPoint(null,e)},Dz.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(Ez(c[f],l[f],u[f],d[f],g)),f===1&&this.addY(Ez(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(Ez(c[f],l[f],u[f],d[f],v)),f===1&&this.addY(Ez(c[f],l[f],u[f],d[f],v)));var y=(-p-Math.sqrt(_))/(2*m);0<y&&y<1&&(f===0&&this.addX(Ez(c[f],l[f],u[f],d[f],y)),f===1&&this.addY(Ez(c[f],l[f],u[f],d[f],y)))}}},Dz.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 Oz(){this.commands=[],this.fill=`black`,this.stroke=null,this.strokeWidth=1}Oz.prototype.moveTo=function(e,t){this.commands.push({type:`M`,x:e,y:t})},Oz.prototype.lineTo=function(e,t){this.commands.push({type:`L`,x:e,y:t})},Oz.prototype.curveTo=Oz.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})},Oz.prototype.quadTo=Oz.prototype.quadraticCurveTo=function(e,t,n,r){this.commands.push({type:`Q`,x1:e,y1:t,x:n,y:r})},Oz.prototype.close=Oz.prototype.closePath=function(){this.commands.push({type:`Z`})},Oz.prototype.extend=function(e){if(e.commands)e=e.commands;else if(e instanceof Dz){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)},Oz.prototype.getBoundingBox=function(){for(var e=new Dz,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},Oz.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())},Oz.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},Oz.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},Oz.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 kz(e){throw Error(e)}function Az(e,t){e||kz(t)}var K={fail:kz,argument:Az,assert:Az},jz=32768,Mz=2147483648,Nz={},q={},J={};function Pz(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=Pz(1),q.CHAR=function(e){return[e.charCodeAt(0)]},J.CHAR=Pz(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=Pz(2),q.SHORT=function(e){return e>=jz&&(e=-(2*jz-e)),[e>>8&255,e&255]},J.SHORT=Pz(2),q.UINT24=function(e){return[e>>16&255,e>>8&255,e&255]},J.UINT24=Pz(3),q.ULONG=function(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]},J.ULONG=Pz(4),q.LONG=function(e){return e>=Mz&&(e=-(2*Mz-e)),[e>>24&255,e>>16&255,e>>8&255,e&255]},J.LONG=Pz(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=Pz(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=Pz(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=Pz(3),q.NUMBER32=function(e){return[29,e>>24&255,e>>16&255,e>>8&255,e&255]},J.NUMBER32=Pz(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,Nz.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)},Nz.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 Fz={"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ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ`};Nz.MACSTRING=function(e,t,n,r){var i=Fz[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 Iz=typeof WeakMap==`function`&&new WeakMap,Lz,Rz=function(e){if(!Lz)for(var t in Lz={},Fz)Lz[t]=new String(t);var n=Lz[e];if(n!==void 0){if(Iz){var r=Iz.get(n);if(r!==void 0)return r}var i=Fz[e];if(i!==void 0){for(var a={},o=0;o<i.length;o++)a[i.charCodeAt(o)]=o+128;return Iz&&Iz.set(n,a),a}}};q.MACSTRING=function(e,t){var n=Rz(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 zz(e){return e>=-128&&e<=127}function Bz(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 Vz(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(!zz(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 Hz(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(o===0||zz(o)&&a+1<i&&zz(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?Bz(e,t,n):r>=-128&&r<=127?Vz(e,t,n):Hz(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 Uz=typeof WeakMap==`function`&&new WeakMap;q.CHARSTRING=function(e){if(Uz){var t=Uz.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 Uz&&Uz.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 Wz(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)}}Wz.prototype.encode=function(){return q.TABLE(this)},Wz.prototype.sizeOf=function(){return J.TABLE(this)};function Gz(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 Kz(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 qz(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 Jz(e){e.format===1?Wz.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:1}].concat(Gz(`glyph`,e.glyphs))):e.format===2?Wz.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:2}].concat(qz(`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.`)}Jz.prototype=Object.create(Wz.prototype),Jz.prototype.constructor=Jz;function Yz(e){Wz.call(this,`scriptListTable`,qz(`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 Wz(`scriptTable`,[{name:`defaultLangSys`,type:`TABLE`,value:new Wz(`defaultLangSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:r.reqFeatureIndex}].concat(Gz(`featureIndex`,r.featureIndexes)))}].concat(qz(`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 Wz(`langSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:n.reqFeatureIndex}].concat(Gz(`featureIndex`,n.featureIndexes)))}]})))}]}))}Yz.prototype=Object.create(Wz.prototype),Yz.prototype.constructor=Yz;function Xz(e){Wz.call(this,`featureListTable`,qz(`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 Wz(`featureTable`,[{name:`featureParams`,type:`USHORT`,value:n.featureParams}].concat(Gz(`lookupListIndex`,n.lookupListIndexes)))}]}))}Xz.prototype=Object.create(Wz.prototype),Xz.prototype.constructor=Xz;function Zz(e,t){Wz.call(this,`lookupListTable`,Kz(`lookup`,e,function(e){var n=t[e.lookupType];return K.assert(!!n,`Unable to write GSUB lookup type `+e.lookupType+` tables.`),new Wz(`lookupTable`,[{name:`lookupType`,type:`USHORT`,value:e.lookupType},{name:`lookupFlag`,type:`USHORT`,value:e.lookupFlag}].concat(Kz(`subtable`,e.subtables,n)))}))}Zz.prototype=Object.create(Wz.prototype),Zz.prototype.constructor=Zz;var Y={Table:Wz,Record:Wz,Coverage:Jz,ScriptList:Yz,FeatureList:Xz,LookupList:Zz,ushortList:Gz,tableList:Kz,recordList:qz};function Qz(e,t){return e.getUint8(t)}function $z(e,t){return e.getUint16(t,!1)}function eB(e,t){return e.getInt16(t,!1)}function tB(e,t){return e.getUint32(t,!1)}function nB(e,t){return e.getInt16(t,!1)+e.getUint16(t+2,!1)/65535}function rB(e,t){for(var n=``,r=t;r<t+4;r+=1)n+=String.fromCharCode(e.getInt8(r));return n}function iB(e,t,n){for(var r=0,i=0;i<n;i+=1)r<<=8,r+=e.getUint8(t+i);return r}function aB(e,t,n){for(var r=[],i=t;i<n;i+=1)r.push(e.getUint8(i));return r}function oB(e){for(var t=``,n=0;n<e.length;n+=1)t+=String.fromCharCode(e[n]);return t}var sB={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=tB(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,e},X.prototype.parseOffset32=X.prototype.parseULong,X.prototype.parseFixed=function(){var e=nB(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=tB(this.data,this.offset+this.relativeOffset+4);return e-=2082844800,this.relativeOffset+=8,e},X.prototype.parseVersion=function(e){var t=$z(this.data,this.offset+this.relativeOffset),n=$z(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+=sB[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 cB={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(cB),langSysRecords:X.recordList({tag:X.tag,langSys:X.pointer(cB)})})}))||[]},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:Qz,getCard8:Qz,getUShort:$z,getCard16:$z,getShort:eB,getULong:tB,getFixed:nB,getTag:rB,getOffset:iB,getBytes:aB,bytesToString:oB,Parser:X};function lB(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 uB(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 dB(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)lB(n,s);else if(n.format===4)uB(n,s,e,t,r);else throw Error(`Only format 4 and 12 cmap tables are supported (found format `+n.format+`).`);return n}function fB(e,t,n){e.segments.push({end:t,start:t,delta:-(t-n),offset:0,glyphIndex:n})}function pB(e){e.segments.push({end:65535,start:65535,delta:1,offset:0})}function mB(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)fB(i,a.unicodes[o],n);i.segments=i.segments.sort(function(e,t){return e.start-t.start})}pB(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 hB={parse:dB,make:mB},gB=`.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(`,`),_B=`................................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(`.`),vB=`................................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(`.`),yB=`.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 bB(e){this.font=e}bB.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 xB(e){this.cmap=e}xB.prototype.charToGlyphIndex=function(e){return this.cmap.glyphIndexMap[e.codePointAt(0)]||0};function SB(e,t){this.encoding=e,this.charset=t}SB.prototype.charToGlyphIndex=function(e){var t=e.codePointAt(0),n=this.encoding[t];return this.charset.indexOf(n)};function CB(e){switch(e.version){case 1:this.names=yB.slice();break;case 2:this.names=Array(e.numberOfGlyphs);for(var t=0;t<e.numberOfGlyphs;t++)e.glyphNameIndex[t]<yB.length?this.names[t]=yB[e.glyphNameIndex[t]]:this.names[t]=e.names[e.glyphNameIndex[t]-yB.length];break;case 2.5:this.names=Array(e.numberOfGlyphs);for(var n=0;n<e.numberOfGlyphs;n++)this.names[n]=yB[n+e.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}CB.prototype.nameToGlyphIndex=function(e){return this.names.indexOf(e)},CB.prototype.glyphIndexToName=function(e){return this.names[e]};function wB(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 TB(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 EB(e,t){t.lowMemory?TB(e):wB(e)}function DB(e,t,n,r,i){e.beginPath(),e.moveTo(t,n),e.lineTo(r,i),e.stroke()}var OB={line:DB};function kB(e,t){var n=t||new Oz;return{configurable:!0,get:function(){return typeof n==`function`&&(n=n()),n},set:function(e){n=e}}}function AB(e){this.bindConstructorValues(e)}AB.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",kB(this,e.path))},AB.prototype.addUnicode=function(e){this.unicodes.length===0&&(this.unicode=e),this.unicodes.push(e)},AB.prototype.getBoundingBox=function(){return this.path.getBoundingBox()},AB.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 Oz,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},AB.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},AB.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},AB.prototype.draw=function(e,t,n,r,i){this.getPath(t,n,r,i).draw(e)},AB.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)},AB.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`,OB.line(e,t,-1e4,t,1e4),OB.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`,OB.line(e,t+a*i,-1e4,t+a*i,1e4),OB.line(e,t+s*i,-1e4,t+s*i,1e4),OB.line(e,-1e4,n+-o*i,1e4,n+-o*i),OB.line(e,-1e4,n+-c*i,1e4,n+-c*i),e.strokeStyle=`green`,OB.line(e,t+l*i,-1e4,t+l*i,1e4)};function jB(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 MB(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}MB.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]},MB.prototype.push=function(e,t){this.glyphs[e]=t,this.length++};function NB(e,t){return new AB({index:t,font:e})}function PB(e,t,n,r,i,a){return function(){var o=new AB({index:t,font:e});return o.path=function(){n(o,r,i);var t=a(e.glyphs,o);return t.unitsPerEm=e.unitsPerEm,t},jB(o,`xMin`,`_xMin`),jB(o,`xMax`,`_xMax`),jB(o,`yMin`,`_yMin`),jB(o,`yMax`,`_yMax`),o}}function FB(e,t,n,r){return function(){var i=new AB({index:t,font:e});return i.path=function(){var t=n(e,i,r);return t.unitsPerEm=e.unitsPerEm,t},i}}var IB={GlyphSet:MB,glyphLoader:NB,ttfGlyphLoader:PB,cffGlyphLoader:FB};function LB(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(!LB(e[n],t[n]))return!1;return!0}else return!1}function RB(e){return e.length<1240?107:e.length<33900?1131:32768}function zB(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 BB(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 VB(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 HB(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 UB(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 HB(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 WB(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 GB(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(UB(r,o))}return WB(i)}function KB(e,t){return t=t<=390?gB[t]:e[t-391],t}function qB(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=KB(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=KB(n,i)),r[o.name]=i}return r}function JB(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 YB=[{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`}],XB=[{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 ZB(e,t){return qB(GB(e,0,e.byteLength),YB,t)}function QB(e,t,n,r){return qB(GB(e,t,n),XB,r)}function $B(e,t,n,r){for(var i=[],a=0;a<n.length;a+=1){var o=ZB(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=QB(e,c+t,s,r);o._defaultWidthX=l.defaultWidthX,o._nominalWidthX=l.nominalWidthX,l.subrs!==0&&(o._subrs=zB(e,c+l.subrs+t).objects,o._subrsBias=RB(o._subrs)),o._privateDict=l}i.push(o)}return i}function eV(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(KB(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(KB(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(KB(r,i)),i+=1}else throw Error(`Unknown charset format `+c);return s}function tV(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 SB(i,n)}function nV(e,t,n){var r,i,a,o,s=new Oz,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 rV(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 iV(e,t,n,r){n.tables.cff={};var i=zB(e,zB(e,JB(e,t).endOffset,Z.bytesToString).endOffset),a=zB(e,i.endOffset,Z.bytesToString);n.gsubrs=zB(e,a.endOffset).objects,n.gsubrsBias=RB(n.gsubrs);var o=$B(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=$B(e,t,zB(e,c).objects,a.objects);s._fdArray=u,l+=t,s._fdSelect=rV(e,l,n.numGlyphs,u.length)}var d=t+s.private[1],f=QB(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=zB(e,d+f.subrs).objects,n.subrsBias=RB(n.subrs));var p;r.lowMemory?(p=BB(e,t+s.charStrings),n.nGlyphs=p.offsets.length):(p=zB(e,t+s.charStrings),n.nGlyphs=p.objects.length);var m=eV(e,t+s.charset,n.nGlyphs,a.objects);if(s.encoding===0?n.cffEncoding=new SB(_B,m):s.encoding===1?n.cffEncoding=new SB(vB,m):n.cffEncoding=tV(e,t+s.encoding,m),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new IB.GlyphSet(n),r.lowMemory)n._push=function(r){var i=VB(r,p.offsets,e,t+s.charStrings);n.glyphs.push(r,IB.cffGlyphLoader(n,r,nV,i))};else for(var h=0;h<n.nGlyphs;h+=1){var g=p.objects[h];n.glyphs.push(h,IB.cffGlyphLoader(n,h,nV,g))}}function aV(e,t){var n,r=gB.indexOf(e);return r>=0&&(n=r),r=t.indexOf(e),r>=0?n=r+gB.length:(n=gB.length+t.length,t.push(e)),n}function oV(){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 sV(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 cV(e,t,n){for(var r={},i=0;i<e.length;i+=1){var a=e[i],o=t[a.name];o!==void 0&&!LB(o,a.value)&&(a.type===`SID`&&(o=aV(o,n)),r[a.op]={name:a.name,type:a.type,value:o})}return r}function lV(e,t){var n=new Y.Record(`Top DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=cV(YB,e,t),n}function uV(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 dV(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 fV(){return new Y.Record(`Global Subr INDEX`,[{name:`subrs`,type:`INDEX`,value:[]}])}function pV(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=aV(i,t);n.fields.push({name:`glyph_`+r,type:`SID`,value:a})}return n}function mV(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 hV(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=mV(r);t.charStrings.push({name:r.name,type:`CHARSTRING`,value:i})}return t}function gV(e,t){var n=new Y.Record(`Private DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=cV(XB,e,t),n}function _V(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=oV(),n.nameIndex=sV([t.postScriptName]);var u=lV(i,l);return n.topDictIndex=uV(u),n.globalSubrIndex=fV(),n.charsets=pV(o,l),n.charStringsIndex=hV(e),n.privateDict=gV(a,l),n.stringIndex=dV(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=lV(i,l),n.topDictIndex=uV(u),n}var vV={parse:iV,make:_V};function yV(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 bV(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 xV={parse:yV,make:bV};function SV(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 CV(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 wV={parse:SV,make:CV};function TV(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 EV(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 DV(e,t,n,r,i,a,o){o.lowMemory?EV(e,t,n,r,i):TV(t,n,r,i,a)}function OV(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 kV={parse:DV,make:OV};function AV(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 jV(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 MV={make:AV,parse:jV};function NV(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 PV(e){return new Y.Table(`maxp`,[{name:`version`,type:`FIXED`,value:20480},{name:`numGlyphs`,type:`USHORT`,value:e}])}var FV={parse:NV,make:PV},IV=[`copyright`,`fontFamily`,`fontSubfamily`,`uniqueID`,`fullName`,`version`,`postScriptName`,`trademark`,`manufacturer`,`designer`,`description`,`manufacturerURL`,`designerURL`,`license`,`licenseURL`,`reserved`,`preferredFamily`,`preferredSubfamily`,`compatibleFullName`,`sampleText`,`postScriptFindFontName`,`wwsFamily`,`wwsSubfamily`],LV={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`},RV={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},zV={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 BV(e,t,n){switch(e){case 0:if(t===65535)return`und`;if(n)return n[t];break;case 1:return LV[t];case 3:return zV[t]}}var VV=`utf-16`,HV={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`},UV={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 WV(e,t,n){switch(e){case 0:return VV;case 1:return UV[n]||HV[t];case 3:if(t===1||t===10)return VV;break}}function GV(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=IV[f]||f,m=i.parseUShort(),h=i.parseUShort(),g=BV(l,d,n),_=WV(l,u,d);if(_!==void 0&&g!==void 0){var v=void 0;if(v=_===VV?Nz.UTF16(e,s+h,m):Nz.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 KV(e){var t={};for(var n in e)t[e[n]]=parseInt(n);return t}function qV(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 JV(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 YV(e,t){var n=JV(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 XV(e,t){var n,r=[],i={},a=KV(IV);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=KV(LV),l=KV(zV),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=RV[_],y=WV(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=YV(b,d);u.push(qV(g,v,_,n,b.length,x));var S=l[m];if(S!==void 0){var C=q.UTF16(h),w=YV(C,d);u.push(qV(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 ZV={parse:GV,make:XV},QV=[{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 $V(e){for(var t=0;t<QV.length;t+=1){var n=QV[t];if(e>=n.begin&&e<n.end)return t}return-1}function eH(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 tH(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 nH={parse:eH,make:tH,unicodeRanges:QV,getUnicodeRange:$V};function rH(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=yB.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]>=yB.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 iH(){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 aH={parse:rH,make:iH},oH=Array(9);oH[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.`)},oH[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()}},oH[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()}},oH[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 sH={sequenceIndex:X.uShort,lookupListIndex:X.uShort};oH[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,sH)}})};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,sH)}})};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,sH)}}K.assert(!1,`0x`+e.toString(16)+`: lookup type 5 format must be 1, 2 or 3.`)},oH[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(sH)}})};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(sH)}})};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(sH)};K.assert(!1,`0x`+e.toString(16)+`: lookup type 6 format must be 1, 2 or 3.`)},oH[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:oH[t].call(n)}},oH[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 cH(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(oH)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(oH),variations:n.parseFeatureVariationsList()}}var lH=Array(9);lH[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)))},lH[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))})))},lH[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))})))},lH[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)))}))})))},lH[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 uH(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,lH)}])}var dH={parse:cH,make:uH};function fH(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]=Nz.UTF8(e,t+c,l)}return a}function pH(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 mH={parse:fH,make:pH};function hH(e){return Math.log(e)/Math.log(2)|0}function gH(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 _H(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 vH(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**hH(t.numTables);t.searchRange=16*n,t.entrySelector=hH(n),t.rangeShift=t.numTables*16-t.searchRange;for(var r=[],i=[],a=t.sizeOf()+_H().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=_H(s.tableName,gH(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 yH(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 bH(e){for(var t=0,n=0;n<e.length;n+=1)t+=e[n];return t/e.length}function xH(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 _=nH.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:bH(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=xV.make({flags:3,unitsPerEm:e.unitsPerEm,xMin:y.xMin,yMin:y.yMin,xMax:y.xMax,yMax:y.yMax,lowestRecPPEM:3,createdTimestamp:e.createdTimestamp}),x=wV.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=FV.make(e.glyphs.length),C=nH.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:yH(e,`xyvw`,{yMax:Math.round(y.ascender/2)}).yMax,sCapHeight:yH(e,`HIKLEFJMNTZBDPRAGOQSUVWXY`,y).yMax,usDefaultChar:e.hasChar(` `)?32:0,usBreakChar:e.hasChar(` `)?32:0},e.tables.os2)),w=kV.make(e.glyphs),ee=hB.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=ZV.make(ae,se),le=se.length>0?MV.make(se):void 0,ue=aH.make(),de=vV.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?mH.make(e.metas):void 0,pe=[b,x,S,C,ce,ee,ue,de,w];le&&pe.push(le),e.tables.gsub&&pe.push(dH.make(e.tables.gsub)),fe&&pe.push(fe);for(var me=vH(pe),he=gH(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 SH={make:vH,fontToTable:xH,computeCheckSum:gH};function CH(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 wH(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 TH(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 EH(e,t){this.font=e,this.tableName=t}EH.prototype={searchTag:CH,binSearch:wH,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=CH(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=CH(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=TH(e.ranges,t);return n?n.classId:0}},getCoverageIndex:function(e,t){switch(e.format){case 1:var n=wH(e.glyphs,t);return n>=0?n:-1;case 2:var r=TH(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 DH(e){EH.call(this,e,`gpos`)}DH.prototype=EH.prototype,DH.prototype.init=function(){var e=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(e)},DH.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},DH.prototype.getKerningTables=function(e,t){if(this.font.tables.gpos)return this.getLookupTables(e,t,`kern`,2)};function OH(e){EH.call(this,e,`gsub`)}function kH(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 AH(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}OH.prototype=EH.prototype,OH.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:`DFLT`,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}},OH.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},OH.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},OH.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},OH.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},OH.prototype.addSingle=function(e,t,n,r){var i=this.getLookupTables(n,r,e,1,!0)[0],a=AH(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},OH.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=AH(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},OH.prototype.addAlternate=function(e,t,n,r){var i=this.getLookupTables(n,r,e,3,!0)[0],a=AH(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},OH.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(kH(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])},OH.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)}},OH.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 jH(){return typeof window<`u`}function MH(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 NH(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 PH(e,t){if(!e)throw t}function FH(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 IH(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=FH(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=FH(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 LH(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 RH(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 zH(e){var t=new Oz;if(!e)return t;for(var n=RH(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 BH(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=LH(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=LH([s],c)[0],c.dx=o.x-s.x,c.dy=o.y-s.y,a=LH(i.points,c)}t.points=t.points.concat(a)}}return zH(t.points)}function VH(e,t,n,r){for(var i=new IB.GlyphSet(r),a=0;a<n.length-1;a+=1){var o=n[a];o===n[a+1]?i.push(a,IB.glyphLoader(r,a)):i.push(a,IB.ttfGlyphLoader(r,a,IH,e,t+o,BH))}return i}function HH(e,t,n,r){var i=new IB.GlyphSet(r);return r._push=function(a){var o=n[a];o===n[a+1]?i.push(a,IB.glyphLoader(r,a)):i.push(a,IB.ttfGlyphLoader(r,a,IH,e,t+o,BH))},i}function UH(e,t,n,r,i){return i.lowMemory?HH(e,t,n,r):VH(e,t,n,r)}var WH={getPath:zH,parse:UH},GH,KH,qH,JH;function YH(e){this.font=e,this.getCommands=function(e){return WH.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function XH(e){return e}function ZH(e){return Math.sign(e)*Math.round(Math.abs(e))}function QH(e){return Math.sign(e)*Math.round(Math.abs(e*2))/2}function $H(e){return Math.sign(e)*(Math.round(Math.abs(e)+.5)-.5)}function eU(e){return Math.sign(e)*Math.ceil(Math.abs(e))}function tU(e){return Math.sign(e)*Math.floor(Math.abs(e))}var nU=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},rU={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){rU.setRelative(e,e,(c+l)/2,r,!0);return}rU.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}},iU={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){iU.setRelative(e,e,(c+l)/2,r,!0);return}iU.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(rU),Object.freeze(iU);function aU(e,t){this.x=e,this.y=t,this.axis=void 0,this.slope=t/e,this.normalSlope=-e/t,Object.freeze(this)}aU.prototype.distance=function(e,t,n,r){return this.x*rU.distance(e,t,n,r)+this.y*iU.distance(e,t,n,r)},aU.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)},aU.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},aU.prototype.touch=function(e){e.xTouched=!0,e.yTouched=!0};function oU(e,t){var n=Math.sqrt(e*e+t*t);return e/=n,t/=n,e===1&&t===0?rU:e===0&&t===1?iU:new aU(e,t)}function sU(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)}sU.prototype.nextTouched=function(e){for(var t=this.nextPointOnContour;!e.touched(t)&&t!==this;)t=t.nextPointOnContour;return t},sU.prototype.prevTouched=function(e){for(var t=this.prevPointOnContour;!e.touched(t)&&t!==this;)t=t.prevPointOnContour;return t};var cU=Object.freeze(new sU(0,0)),lU={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function uU(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=rU,this.round=ZH}}YH.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){uU.prototype=lU,i=this._fpgmState=new uU(`fpgm`,n.tables.fpgm),i.funcs=[],i.font=n,exports.DEBUG&&(console.log(`---EXEC FPGM---`),i.step=-1);try{KH(i)}catch(e){console.log(`Hinting error in FPGM:`+e),this._errorState=3;return}}uU.prototype=i,r=this._prepState=new uU(`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{KH(r)}catch(e){this._errorState<2&&console.log(`Hinting error in PREP:`+e),this._errorState=2}}if(!(this._errorState>1))try{return qH(e,r)}catch(e){this._errorState<1&&(console.log(`Hinting error:`+e),console.log(`Note: further hinting errors are silenced`)),this._errorState=1;return}}},qH=function(e,t){var n=t.ppem/t.font.unitsPerEm,r=n,i=e.components,a,o,s;if(uU.prototype=t,!i)s=new uU(`glyf`,e.instructions),exports.DEBUG&&(console.log(`---EXEC GLYPH---`),s.step=-1),JH(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 uU(`glyf`,d.instructions),exports.DEBUG&&(console.log(`---EXEC COMP `+l+`---`),s.step=-1),JH(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 uU(`glyf`,e.instructions),s.gZone=s.z0=s.z1=s.z2=o,s.contours=a,o.push(new sU(0,0),new sU(Math.round(e.advanceWidth*n),0)),exports.DEBUG&&(console.log(`---EXEC COMPOSITE---`),s.step=-1),KH(s),o.length-=2)}return o},JH=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 sU(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 sU(0,0),new sU(Math.round(e.advanceWidth*n),0)),KH(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)}}},KH=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=GH[t[e.ip]],!r)throw Error(`unknown instruction: 0x`+Number(t[e.ip]).toString(16));r(e)}}};function dU(e){for(var t=e.tZone=Array(e.gZone.length),n=0;n<t.length;n++)t[n]=new sU(0,0)}function fU(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 pU(e,t){exports.DEBUG&&console.log(t.step,`SVTCA[`+e.axis+`]`),t.fv=t.pv=t.dpv=e}function mU(e,t){exports.DEBUG&&console.log(t.step,`SPVTCA[`+e.axis+`]`),t.pv=t.dpv=e}function hU(e,t){exports.DEBUG&&console.log(t.step,`SFVTCA[`+e.axis+`]`),t.fv=e}function gU(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=oU(s,c)}function _U(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=oU(s,c)}function vU(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.pv=e.dpv=oU(r,n)}function yU(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.fv=oU(r,n)}function bU(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 xU(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 SU(e){e.fv=e.pv,exports.DEBUG&&console.log(e.step,`SFVTPV[]`)}function CU(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 wU(e){e.rp0=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP0[]`,e.rp0)}function TU(e){e.rp1=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP1[]`,e.rp1)}function EU(e){e.rp2=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP2[]`,e.rp2)}function DU(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP0[]`,t),e.zp0=t,t){case 0:e.tZone||dU(e),e.z0=e.tZone;break;case 1:e.z0=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function OU(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP1[]`,t),e.zp1=t,t){case 0:e.tZone||dU(e),e.z1=e.tZone;break;case 1:e.z1=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function kU(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP2[]`,t),e.zp2=t,t){case 0:e.tZone||dU(e),e.z2=e.tZone;break;case 1:e.z2=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function AU(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||dU(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 jU(e){e.loop=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SLOOP[]`,e.loop)}function MU(e){exports.DEBUG&&console.log(e.step,`RTG[]`),e.round=ZH}function NU(e){exports.DEBUG&&console.log(e.step,`RTHG[]`),e.round=$H}function PU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SMD[]`,t),e.minDis=t/64}function FU(e){exports.DEBUG&&console.log(e.step,`ELSE[]`),fU(e,!1)}function IU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`JMPR[]`,t),e.ip+=t-1}function LU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCVTCI[]`,t),e.cvCutIn=t/64}function RU(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DUP[]`),t.push(t[t.length-1])}function zU(e){exports.DEBUG&&console.log(e.step,`POP[]`),e.stack.pop()}function BU(e){exports.DEBUG&&console.log(e.step,`CLEAR[]`),e.stack.length=0}function VU(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 HU(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DEPTH[]`),t.push(t.length)}function UU(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++)KH(e),exports.DEBUG&&console.log(++e.step,o+1<r?`next loopcall`:`done loopcall`,o);e.ip=i,e.prog=a}function WU(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],KH(e),e.ip=n,e.prog=r,exports.DEBUG&&console.log(++e.step,`returning from`,t)}function GU(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CINDEX[]`,n),t.push(t[t.length-n])}function KU(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 qU(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 JU(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,cU);e&&(o=t.round(o)),i.setRelative(r,cU,o,a),i.touch(r),t.rp0=t.rp1=n}function YU(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 XU(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 ZU(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 QU(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 $U(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 eW(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 tW(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 nW(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 rW(e){exports.DEBUG&&console.log(e.step,`RTDG[]`),e.round=QH}function iW(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,cU);e&&(Math.abs(l-c)<t.cvCutIn&&(l=c),l=t.round(l)),o.setRelative(a,cU,l,s),t.zp0===0&&(a.xo=a.x,a.yo=a.y),o.touch(a),t.rp0=t.rp1=i}function aW(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 oW(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 sW(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 cW(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 lW(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 uW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`RCVT`,n),t.push(e.cvt[n]*64)}function dW(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,cU,e,!1)*64)}function fW(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 pW(e){exports.DEBUG&&console.log(e.step,`MPPEM[]`),e.stack.push(e.ppem)}function mW(e){exports.DEBUG&&console.log(e.step,`FLIPON[]`),e.autoFlip=!0}function hW(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 gW(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 _W(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 vW(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 yW(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 bW(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 xW(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 SW(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 CW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`IF[]`,t),t||(fU(e,!0),exports.DEBUG&&console.log(e.step,`EIF[]`))}function wW(e){exports.DEBUG&&console.log(e.step,`EIF[]`)}function TW(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 EW(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 DW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NOT[]`,n),t.push(+!n)}function OW(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 kW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDB[]`,t),e.deltaBase=t}function AW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDS[]`,t),e.deltaShift=.5**t}function jW(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 MW(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 NW(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 PW(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 FW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`ABS[]`,n),t.push(Math.abs(n))}function IW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NEG[]`,n),t.push(-n)}function LW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`FLOOR[]`,n),t.push(Math.floor(n/64)*64)}function RW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CEILING[]`,n),t.push(Math.ceil(n/64)*64)}function zW(e,t){var n=t.stack,r=n.pop();exports.DEBUG&&console.log(t.step,`ROUND[]`),n.push(t.round(r/64)*64)}function BW(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 VW(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 HW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SROUND[]`,t),e.round=nU;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 UW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`S45ROUND[]`,t),e.round=nU;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 WW(e){exports.DEBUG&&console.log(e.step,`ROFF[]`),e.round=XH}function GW(e){exports.DEBUG&&console.log(e.step,`RUTG[]`),e.round=eU}function KW(e){exports.DEBUG&&console.log(e.step,`RDTG[]`),e.round=tU}function qW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANCTRL[]`,t)}function JW(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=oU(s,c)}function YW(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 XW(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 ZW(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 QW(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 $W(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANTYPE[]`,t)}function eG(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 tG(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 nG(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)}GH=[pU.bind(void 0,iU),pU.bind(void 0,rU),mU.bind(void 0,iU),mU.bind(void 0,rU),hU.bind(void 0,iU),hU.bind(void 0,rU),gU.bind(void 0,0),gU.bind(void 0,1),_U.bind(void 0,0),_U.bind(void 0,1),vU,yU,bU,xU,SU,CU,wU,TU,EU,DU,OU,kU,AU,jU,MU,NU,PU,FU,IU,LU,void 0,void 0,RU,zU,BU,VU,HU,GU,KU,void 0,void 0,void 0,UU,WU,qU,void 0,JU.bind(void 0,0),JU.bind(void 0,1),YU.bind(void 0,iU),YU.bind(void 0,rU),XU.bind(void 0,0),XU.bind(void 0,1),ZU.bind(void 0,0),ZU.bind(void 0,1),QU.bind(void 0,0),QU.bind(void 0,1),$U,eW,tW.bind(void 0,0),tW.bind(void 0,1),nW,rW,iW.bind(void 0,0),iW.bind(void 0,1),aW,oW,sW,cW,lW,uW,dW.bind(void 0,0),dW.bind(void 0,1),void 0,fW.bind(void 0,0),fW.bind(void 0,1),pW,void 0,mW,void 0,void 0,hW,gW,_W,vW,yW,bW,xW,SW,CW,wW,TW,EW,DW,OW.bind(void 0,1),kW,AW,jW,MW,NW,PW,FW,IW,LW,RW,zW.bind(void 0,0),zW.bind(void 0,1),zW.bind(void 0,2),zW.bind(void 0,3),void 0,void 0,void 0,void 0,BW,OW.bind(void 0,2),OW.bind(void 0,3),VW.bind(void 0,1),VW.bind(void 0,2),VW.bind(void 0,3),HW,UW,void 0,void 0,WW,void 0,GW,KW,zU,zU,void 0,void 0,void 0,void 0,void 0,qW,JW.bind(void 0,0),JW.bind(void 0,1),YW,void 0,XW,ZW,QW,$W,eG,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,tG.bind(void 0,1),tG.bind(void 0,2),tG.bind(void 0,3),tG.bind(void 0,4),tG.bind(void 0,5),tG.bind(void 0,6),tG.bind(void 0,7),tG.bind(void 0,8),nG.bind(void 0,1),nG.bind(void 0,2),nG.bind(void 0,3),nG.bind(void 0,4),nG.bind(void 0,5),nG.bind(void 0,6),nG.bind(void 0,7),nG.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 rG(e){this.char=e,this.state={},this.activeState=null}function iG(e,t,n){this.contextName=n,this.startIndex=e,this.endOffset=t}function aG(e,t,n){this.contextName=e,this.openRange=null,this.ranges=[],this.checkStart=t,this.checkEnd=n}function oG(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 sG(e){this.eventId=e,this.subscribers=[]}function cG(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 sG(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 lG(e){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],cG.call(this,e)}rG.prototype.setState=function(e,t){return this.state[e]=t,this.activeState={key:e,value:this.state[e]},this.activeState},rG.prototype.getState=function(e){return this.state[e]||null},lG.prototype.inboundIndex=function(e){return e>=0&&e<this.tokens.length},lG.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)})])},lG.prototype.replaceRange=function(e,t,n,r){t=t===null?this.tokens.length:t;var i=n.every(function(e){return e instanceof rG});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.`}},lG.prototype.replaceToken=function(e,t,n){if(!isNaN(e)&&this.inboundIndex(e)&&t instanceof rG){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.`}},lG.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},lG.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.`}},lG.prototype.insertToken=function(e,t,n){return e.every(function(e){return e instanceof rG})?(this.tokens.splice.apply(this.tokens,[t,0].concat(e)),n||this.dispatch(`insertToken`,[e,t]),e):{FAIL:`insertToken: invalid token(s).`}},lG.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)},sG.prototype.subscribe=function(e){return typeof e==`function`?this.subscribers.push(e)-1:{FAIL:`invalid '`+this.eventId+`' event handler`}},sG.prototype.unsubscribe=function(e){this.subscribers.splice(e,1)},oG.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)},oG.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}},lG.prototype.rangeToText=function(e){if(e instanceof iG)return this.getRangeTokens(e).map(function(e){return e.char}).join(``)},lG.prototype.getText=function(){return this.tokens.map(function(e){return e.char}).join(``)},lG.prototype.getContext=function(e){return this.registeredContexts[e]||null},lG.prototype.on=function(e,t){var n=this.events[e];return n?n.subscribe(t):null},lG.prototype.dispatch=function(e,t){var n=this,r=this.events[e];r instanceof sG&&r.subscribers.forEach(function(e){e.apply(n,t||[])})},lG.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 aG(e,t,n);return this.registeredContexts[e]=r,this.contextCheckers.push(r),r},lG.prototype.getRangeTokens=function(e){var t=e.startIndex+e.endOffset;return[].concat(this.tokens.slice(e.startIndex,t))},lG.prototype.getContextRanges=function(e){var t=this.getContext(e);return t?t.ranges:{FAIL:`context checker '`+e+`' is not registered.`}},lG.prototype.resetContextsRanges=function(){var e=this.registeredContexts;for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];n.ranges=[]}},lG.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 oG(e,t);this.runContextCheck(n)}this.dispatch(`updateContextsRanges`,[this.registeredContexts])},lG.prototype.setEndOffset=function(e,t){var n=this.getContext(t).openRange.startIndex,r=new iG(n,e,t),i=this.getContext(t).ranges;return r.rangeId=t+`.`+i.length,i.push(r),this.getContext(t).openRange=null,r},lG.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 iG(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])}})},lG.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 oG(t,n);this.dispatch(`next`,[i]),this.runContextCheck(i);var a=new rG(r);this.tokens.push(a),this.dispatch(`newToken`,[a,i])}return this.dispatch(`end`,[this.tokens]),this.tokens};function uG(e){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(e)}function dG(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 fG(e){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(e)}function pG(e){return/[A-z]/.test(e)}function mG(e){return/\s/.test(e)}function hG(e){this.font=e,this.features={}}function gG(e){this.id=e.id,this.tag=e.tag,this.substitution=e.substitution}function _G(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 vG(e,t){return _G(e,t.coverage)===-1?null:e+t.deltaGlyphId}function yG(e,t){var n=_G(e,t.coverage);return n===-1?null:t.substitute[n]}function bG(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=_G(a,i);o!==-1&&n.push(o)}return n.length===e.length?n:-1}function xG(e,t){var n=t.inputCoverage.length+t.lookaheadCoverage.length+t.backtrackCoverage.length;if(e.context.length<n)return[];var r=bG(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&&fG(a[0].char);)a.shift();var o=new oG(a,0),s=bG(t.lookaheadCoverage,o),c=[].concat(e.backtrack);for(c.reverse();c.length&&fG(c[0].char);)c.shift();if(c.length<t.backtrackCoverage.length)return[];var l=new oG(c,0),u=bG(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 SG(e,t){var n=e.current,r=_G(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 CG(e,t){var n=_G(e,t.coverage);return n===-1?null:t.sequences[n]}hG.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[]},hG.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()},hG.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},hG.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},hG.prototype.getSubstitutionType=function(e,t){return e.lookupType.toString()+t.substFormat.toString()},hG.prototype.getLookupMethod=function(e,t){var n=this;switch(this.getSubstitutionType(e,t)){case`11`:return function(e){return vG.apply(n,[e,t])};case`12`:return function(e){return yG.apply(n,[e,t])};case`63`:return function(e){return xG.apply(n,[e,t])};case`41`:return function(e){return SG.apply(n,[e,t])};case`21`:return function(e){return CG.apply(n,[e,t])};default:throw Error(`lookupType: `+e.lookupType+` - substFormat: `+t.substFormat+` is not yet supported`)}},hG.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 gG({id:11,tag:e.tag,substitution:p}));break;case`12`:p=f(t.current),p&&a.splice(n,1,new gG({id:12,tag:e.tag,substitution:p}));break;case`63`:p=f(t),Array.isArray(p)&&p.length&&a.splice(n,1,new gG({id:63,tag:e.tag,substitution:p}));break;case`41`:p=f(t),p&&a.splice(n,1,new gG({id:41,tag:e.tag,substitution:p}));break;case`21`:p=f(t.current),p&&a.splice(n,1,new gG({id:21,tag:e.tag,substitution:p}));break}t=new oG(a,n),!(Array.isArray(p)&&!p.length)&&(p=null)}return a.length?a:null},hG.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},hG.prototype.getLookupSubtables=function(e){return e.subtables||null},hG.prototype.getLookupByIndex=function(e){return this.font.tables.gsub.lookups[e]||null},hG.prototype.getFeatureLookups=function(e){return e.lookupListIndexes.map(this.getLookupByIndex.bind(this))},hG.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 wG(e){var t=e.current,n=e.get(-1);return n===null&&uG(t)||!uG(n)&&uG(t)}function TG(e){var t=e.get(1);return t===null||!uG(t)}var EG={startCheck:wG,endCheck:TG};function DG(e){var t=e.current,n=e.get(-1);return(uG(t)||fG(t))&&!uG(n)}function OG(e){var t=e.get(1);switch(!0){case t===null:return!0;case!uG(t)&&!fG(t):var n=mG(t);if(!n)return!0;if(n){var r=!1;if(r=e.lookahead.some(function(e){return uG(e)||fG(e)}),!r)return!0}break;default:return!1}}var kG={startCheck:DG,endCheck:OG};function AG(e,t,n){t[n].setState(e.tag,e.substitution)}function jG(e,t,n){t[n].setState(e.tag,e.substitution)}function MG(e,t,n){e.substitution.forEach(function(r,i){t[n+i].setState(e.tag,r)})}function NG(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 PG={11:AG,12:jG,63:MG,41:NG};function FG(e,t,n){e instanceof gG&&PG[e.id]&&PG[e.id](e,t,n)}function IG(e){for(var t=[].concat(e.backtrack),n=t.length-1;n>=0;n--){var r=t[n],i=dG(r),a=fG(r);if(!i&&!a)return!0;if(i)return!1}return!1}function LG(e){if(dG(e.current))return!1;for(var t=0;t<e.lookahead.length;t++){var n=e.lookahead[t];if(!fG(n))return!0}return!1}function RG(e){var t=this,n=`arab`,r=this.featuresTags[n],i=this.tokenizer.getRangeTokens(e);if(i.length!==1){var a=new oG(i.map(function(e){return e.getState(`glyphIndex`)}),0),o=new oG(i.map(function(e){return e.char}),0);i.forEach(function(e,s){if(!fG(e.char)){a.setCurrentIndex(s),o.setCurrentIndex(s);var c=0;IG(o)&&(c|=1),LG(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 gG&&(FG(e,i,t),a.context[t]=e.substitution)})}}})}}function zG(e,t){return new oG(e.map(function(e){return e.activeState.value}),t||0)}function BG(e){var t=this,n=`arab`,r=this.tokenizer.getRangeTokens(e),i=zG(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 FG(e,r,a)}),i=zG(r))})}function VG(e){var t=e.current,n=e.get(-1);return n===null&&pG(t)||!pG(n)&&pG(t)}function HG(e){var t=e.get(1);return t===null||!pG(t)}var UG={startCheck:VG,endCheck:HG};function WG(e,t){return new oG(e.map(function(e){return e.activeState.value}),t||0)}function GG(e){var t=this,n=`latn`,r=this.tokenizer.getRangeTokens(e),i=WG(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 FG(e,r,a)}),i=WG(r))})}function KG(e){this.baseDir=e||`ltr`,this.tokenizer=new lG,this.featuresTags={}}KG.prototype.setText=function(e){this.text=e},KG.prototype.contextChecks={latinWordCheck:UG,arabicWordCheck:EG,arabicSentenceCheck:kG};function qG(e){var t=this.contextChecks[e+`Check`];return this.tokenizer.registerContextChecker(e,t.startCheck,t.endCheck)}function JG(){return qG.call(this,`latinWord`),qG.call(this,`arabicWord`),qG.call(this,`arabicSentence`),this.tokenizer.tokenize(this.text)}function YG(){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())})}KG.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},KG.prototype.applyFeatures=function(e,t){if(!e)throw Error(`No valid font was provided to apply features`);this.query||=new hG(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)}},KG.prototype.registerModifier=function(e,t,n){this.tokenizer.registerModifier(e,t,n)};function XG(){if(this.tokenizer.registeredModifiers.indexOf(`glyphIndex`)===-1)throw Error(`glyphIndex modifier is required to apply arabic presentation features.`)}function ZG(){var e=this;this.featuresTags.hasOwnProperty(`arab`)&&(XG.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){RG.call(e,t)}))}function QG(){var e=this,t=`arab`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`rlig`)!==-1&&(XG.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){BG.call(e,t)}))}function $G(){var e=this,t=`latn`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`liga`)!==-1&&(XG.call(this),this.tokenizer.getContextRanges(`latinWord`).forEach(function(t){GG.call(e,t)}))}KG.prototype.checkContextReady=function(e){return!!this.tokenizer.getContext(e)},KG.prototype.applyFeaturesToContexts=function(){this.checkContextReady(`arabicWord`)&&(ZG.call(this),QG.call(this)),this.checkContextReady(`latinWord`)&&$G.call(this),this.checkContextReady(`arabicSentence`)&&YG.call(this)},KG.prototype.processText=function(e){(!this.text||this.text!==e)&&(this.setText(e),JG.call(this),this.applyFeaturesToContexts())},KG.prototype.getBidiText=function(e){return this.processText(e),this.tokenizer.getText()},KG.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 eK(e){e||={},e.tables=e.tables||{},e.empty||(PH(e.familyName,`When creating a new Font object, familyName is required.`),PH(e.styleName,`When creating a new Font object, styleName is required.`),PH(e.unitsPerEm,`When creating a new Font object, unitsPerEm is required.`),PH(e.ascender,`When creating a new Font object, ascender is required.`),PH(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 IB.GlyphSet(this,e.glyphs||[]),this.encoding=new bB(this),this.position=new DH(this),this.substitution=new OH(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 YH(this)}})}eK.prototype.hasChar=function(e){return this.encoding.charToGlyphIndex(e)!==null},eK.prototype.charToGlyphIndex=function(e){return this.encoding.charToGlyphIndex(e)},eK.prototype.charToGlyph=function(e){var t=this.charToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},eK.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})},eK.prototype.stringToGlyphs=function(e,t){var n=this,r=new KG;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},eK.prototype.nameToGlyphIndex=function(e){return this.glyphNames.nameToGlyphIndex(e)},eK.prototype.nameToGlyph=function(e){var t=this.nameToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},eK.prototype.glyphIndexToName=function(e){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(e):``},eK.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},eK.prototype.defaultRenderOptions={kerning:!0,features:[{script:`arab`,tags:[`init`,`medi`,`fina`,`rlig`]},{script:`latn`,tags:[`liga`,`rlig`]}]},eK.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},eK.prototype.getPath=function(e,t,n,r,i){var a=new Oz;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},eK.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},eK.prototype.getAdvanceWidth=function(e,t,n){return this.forEachGlyph(e,0,0,t,n,function(){})},eK.prototype.draw=function(e,t,n,r,i,a){this.getPath(t,n,r,i,a).draw(e)},eK.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)})},eK.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)})},eK.prototype.getEnglishName=function(e){var t=this.names[e];if(t)return t.en},eK.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},eK.prototype.toTables=function(){return SH.fontToTable(this)},eK.prototype.toBuffer=function(){return console.warn(`Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.`),this.toArrayBuffer()},eK.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},eK.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(jH())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=ez(),l=NH(r);c.writeFileSync(e,l)}},eK.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512},eK.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},eK.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function tK(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 nK(e,t,n){var r=tK(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 rK(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 iK(e,t,n,r){for(var i=tK(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 aK(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 oK(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(nK(r,e.axes[r],t));for(var i=0;i<e.instances.length;i++)n.fields=n.fields.concat(iK(i,e.instances[i],e.axes,t));return n}function sK(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(rK(e,t+a+d*s,n));for(var f=[],p=t+a+o*s,m=0;m<c;m++)f.push(aK(e,p+m*l,u,n));return{axes:u,instances:f}}var cK={make:oK,parse:sK},lK=function(){return{coverage:this.parsePointer(X.coverage),attachPoints:this.parseList(X.pointer(X.uShortList))}},uK=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()}},dK=function(){return this.parseList(X.pointer(uK))},fK=function(){return{coverage:this.parsePointer(X.coverage),ligGlyphs:this.parseList(X.pointer(dK))}},pK=function(){return this.parseUShort(),this.parseList(X.pointer(X.coverage))};function mK(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(lK),ligCaretList:n.parsePointer(fK),markAttachClassDef:n.parsePointer(X.classDef)};return r>=1.2&&(i.markGlyphSets=n.parsePointer(pK)),i}var hK={parse:mK},gK=Array(10);gK[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.`)},gK[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)}}))}}},gK[3]=function(){return{error:`GPOS Lookup 3 not supported`}},gK[4]=function(){return{error:`GPOS Lookup 4 not supported`}},gK[5]=function(){return{error:`GPOS Lookup 5 not supported`}},gK[6]=function(){return{error:`GPOS Lookup 6 not supported`}},gK[7]=function(){return{error:`GPOS Lookup 7 not supported`}},gK[8]=function(){return{error:`GPOS Lookup 8 not supported`}},gK[9]=function(){return{error:`GPOS Lookup 9 not supported`}};function _K(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(gK)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(gK),variations:n.parseFeatureVariationsList()}}var vK=Array(10);function yK(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,vK)}])}var bK={parse:_K,make:yK};function xK(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 SK(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 CK(e,t){var n=new Z.Parser(e,t),r=n.parseUShort();if(r===0)return xK(n);if(r===1)return SK(n);throw Error(`Unsupported kern table version (`+r+`).`)}var wK={parse:CK};function TK(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 EK={parse:TK};function DK(e,t){ez().readFile(e,function(e,n){if(e)return t(e.message);t(null,MH(n))})}function OK(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 kK(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 AK(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 jK(e,t){if(t.compression===`WOFF`){var n=new Uint8Array(e.buffer,t.offset+2,t.compressedLength-2),r=new Uint8Array(t.length);if(Tz(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 MK(e,t){t??={};var n,r,i=new eK({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=kK(a,o);else if(c===`OTTO`)i.outlinesFormat=`cff`,o=Z.getUShort(a,4),s=kK(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=AK(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=jK(a,C),i.tables.cmap=hB.parse(w.data,w.offset),i.encoding=new xB(i.tables.cmap);break;case`cvt `:w=jK(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=jK(a,C),x=new Z.Parser(w.data,w.offset),i.tables.fpgm=x.parseByteList(C.length);break;case`head`:w=jK(a,C),i.tables.head=xV.parse(w.data,w.offset),i.unitsPerEm=i.tables.head.unitsPerEm,n=i.tables.head.indexToLocFormat;break;case`hhea`:w=jK(a,C),i.tables.hhea=wV.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=jK(a,C),r=MV.parse(w.data,w.offset);break;case`maxp`:w=jK(a,C),i.tables.maxp=FV.parse(w.data,w.offset),i.numGlyphs=i.tables.maxp.numGlyphs;break;case`name`:y=C;break;case`OS/2`:w=jK(a,C),i.tables.os2=nH.parse(w.data,w.offset);break;case`post`:w=jK(a,C),i.tables.post=aH.parse(w.data,w.offset),i.glyphNames=new CB(i.tables.post);break;case`prep`:w=jK(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=jK(a,y);if(i.tables.name=ZV.parse(ee.data,ee.offset,r),i.names=i.tables.name,f&&v){var te=n===0,ne=jK(a,v),re=EK.parse(ne.data,ne.offset,i.numGlyphs,te),ie=jK(a,f);i.glyphs=WH.parse(ie.data,ie.offset,re,i,t)}else if(u){var ae=jK(a,u);vV.parse(ae.data,ae.offset,i,t)}else throw Error(`Font doesn't contain TrueType or CFF outlines.`);var oe=jK(a,g);if(kV.parse(i,oe.data,oe.offset,i.numberOfHMetrics,i.numGlyphs,i.glyphs,t),EB(i,t),_){var se=jK(a,_);i.kerningPairs=wK.parse(se.data,se.offset)}else i.kerningPairs={};if(p){var ce=jK(a,p);i.tables.gdef=hK.parse(ce.data,ce.offset)}if(m){var le=jK(a,m);i.tables.gpos=bK.parse(le.data,le.offset),i.position.init()}if(h){var ue=jK(a,h);i.tables.gsub=dH.parse(ue.data,ue.offset)}if(d){var de=jK(a,d);i.tables.fvar=cK.parse(de.data,de.offset,i.names)}if(b){var fe=jK(a,b);i.tables.meta=mH.parse(fe.data,fe.offset),i.metas=i.tables.meta}return i}function NK(e,t,n){n??={};var r=typeof window>`u`&&!n.isUrl?DK:OK;return new Promise(function(i,a){r(e,function(e,r){if(e){if(t)return t(e);a(e)}var o;try{o=MK(r,n)}catch(e){if(t)return t(e,null);a(e)}if(t)return t(null,o);i(o)})})}function PK(e,t){return MK(MH(ez().readFileSync(e)),t)}var FK=Object.freeze({__proto__:null,Font:eK,Glyph:AB,Path:Oz,BoundingBox:Dz,_parse:Z,parse:MK,load:NK,loadSync:PK}),IK=class e{sketches;constructor(e){e.length===0&&M(`CompoundSketch`,`Cannot create CompoundSketch with an empty array of sketches`),this.sketches=e}delete(){this.sketches.forEach(e=>{e.delete()})}get outerSketch(){return cA(this.sketches)}get innerSketches(){return this.sketches.slice(1)}get wires(){return JK(this)}face(){return qK(this)}extrude(e,t={}){return YK(this,e,t)}revolve(e,t={}){return XK(this,e,t)}loftWith(t,n={}){return Array.isArray(t)||!(t instanceof e)?M(`CompoundSketch.loftWith`,`A compound (face-with-holes) sketch can only loft to another compound sketch with the same number of sub-sketches.`):ZK(this,t,n)}sweepSketch(){return M(`CompoundSketch.sweepSketch`,`Sweeping a compound (face-with-holes) profile is not supported — sweep its outer Sketch instead.`)}};function LK(e){let t={};e.defaultOrigin&&(t.defaultOrigin=e.defaultOrigin),e.defaultDirection&&(t.defaultDirection=e.defaultDirection);let n=new QK(e.wire,t);return e.baseFace&&(n.baseFace=e.baseFace),n}function RK(e){return new IK(e.map(LK))}function zK(e){if(e instanceof QK)return e;let t=e.sketches;if(Array.isArray(t)){let[e,...n]=t;if(e instanceof QK){for(let e of n)e.delete();return e}}M(`asSketch`,`Expected a single-wire profile to loft or sweep.`)}function BK(e){let t;return t=e.baseFace?TA(e.baseFace,e.wire):j(CA(e.wire)),t}function VK(e){return _E(j(tO(e.wire.wrapped)))}function HK(e,t,{origin:n}={}){let r=j(CA(e.wire)),i=j(yM(r,n?bD(n):e.defaultOrigin,t?bD(t):[0,0,1]));return r[Symbol.dispose](),e.delete(),i}function UK(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=ED(ND(n?bD(n):e.defaultDirection),t),s=a?bD(a):e.defaultOrigin;if(r&&!i){let t=j(fM(e.wire,[...s],[...o],r));return e.delete(),t}if(i){let t=j(pM(e.wire,i,[...s],[...o],r));return e.delete(),t}let c=j(CA(e.wire)),l=j(vM(c,[...o]));return c[Symbol.dispose](),e.delete(),l}function WK(e,t,n={}){let r=Sk(e.wire),i=ND(ED(Tk(e.wire,1e-9),-1)),a=e.defaultDirection,o=ED(kD(i,a),-1),s=zK(t(VD([...r],[...o],[...i]),[...r])),c={forceProfileSpineOthogonality:!0,...n};e.baseFace&&(c.support=e.baseFace.wrapped);let l=j(uM(s.wire,e.wire,c));return e.delete(),l}function GK(e,t,n={},r=!1){let i=[e,...(Array.isArray(t)?t:[t]).map(zK)],a=j(xM(i.map(e=>e.wire),n,r));return i.forEach(e=>{e.delete()}),a}var KK=(e,t)=>{let n=j(t(cA(e))),r=e.slice(1).map(e=>j(t(e)));if(r.length===0)return n;try{return j(IA(n,r,{unsafe:!0}))}finally{n.delete();for(let e of r)e.delete()}};function qK(e){let t=e.outerSketch.face(),n=DA(t,e.innerSketches.map(e=>e.wire));return t[Symbol.dispose](),n}function JK(e){return ij(e.sketches.map(e=>e.wire))}function YK(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=ED(ND(n?bD(n):e.outerSketch.defaultDirection),t);if(r&&!i)return KK(e.sketches,t=>fM(t.wire,a?bD(a):e.outerSketch.defaultOrigin,o,r));if(i)return KK(e.sketches,t=>pM(t.wire,i,a?bD(a):e.outerSketch.defaultOrigin,o,r));let s=qK(e),c=j(vM(s,o));return s[Symbol.dispose](),c}function XK(e,t,{origin:n}={}){let r=n?bD(n):e.outerSketch.defaultOrigin,i=t?bD(t):[0,0,1],a=qK(e),o=j(yM(a,r,i));return a[Symbol.dispose](),o}function ZK(e,t,n={}){e.sketches.length!==t.sketches.length&&M(`CompoundSketch.loftWith`,`You need to loft with another compound with the same number of sketches`);let r=e.sketches.map((e,r)=>{let i=sA(t.sketches,r),a={};return n.ruled!==void 0&&(a.ruled=n.ruled),e.clone().loftWith(i.clone(),a,!0)}),i=qK(e),a=vE(j(tO(i.wrapped)));i[Symbol.dispose](),r.push(a,qK(t));let o=j(aj(r));for(let e of r)e[Symbol.dispose]();return o}var QK=class e{wire;_defaultOrigin;_defaultDirection;_baseFace;constructor(e,{defaultOrigin:t=[0,0,0],defaultDirection:n=[0,0,1]}={}){this.wire=e,this._defaultOrigin=bD(t),this._defaultDirection=bD(n),this.baseFace=null}get baseFace(){return this._baseFace}set baseFace(e){this._baseFace&&this._baseFace[Symbol.dispose](),this._baseFace=e&&vE(j(tO(e.wrapped)))}delete(){this.wire[Symbol.dispose](),this.baseFace&&this.baseFace[Symbol.dispose]()}clone(){let t=_E(j(tO(this.wire.wrapped))),n=new e(t,{defaultOrigin:this.defaultOrigin,defaultDirection:this.defaultDirection});return this.baseFace&&(n.baseFace=vE(j(tO(this.baseFace.wrapped)))),n}get defaultOrigin(){return this._defaultOrigin}set defaultOrigin(e){this._defaultOrigin=bD(e)}get defaultDirection(){return this._defaultDirection}set defaultDirection(e){this._defaultDirection=bD(e)}face(){return BK(this)}wires(){return VK(this)}faces(){return this.face()}revolve(e,t={}){return HK(this,e,t)}extrude(e,t={}){return UK(this,e,t)}sweepSketch(e,t={}){return WK(this,e,t)}loftWith(e,t={},n=!1){return GK(this,e,t,n)}},$K=class{sketches;constructor(e){this.sketches=e}soleSketch(e){this.sketches.length!==1&&M(`Sketches.${e}`,`Multiple profiles — ${e} each sub-sketch individually.`);let t=cA(this.sketches);return t instanceof QK||M(`Sketches.${e}`,`${e} is only supported on single-wire profiles.`),t}face(){return this.sketches.length!==1&&M(`Sketches.face`,`Multiple profiles — use faces() to combine them.`),cA(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 ij(this.sketches.flatMap(e=>e instanceof QK?[e.wire]:e.sketches.map(e=>e.wire)))}faces(){return ij(this.sketches.map(e=>e.face()))}extrude(e,t={}){return ij(this.sketches.map(n=>n.extrude(e,t)))}revolve(e,t){return ij(this.sketches.map(n=>n.revolve(e,t)))}},eq={};async function tq(e,t=`default`,n=!1){if(!n&&eq[t])return O(eq[t]);let r;if(typeof e==`string`){let t;try{t=await fetch(e)}catch(t){return k(vo(N.FONT_FETCH_FAILED,`Failed to fetch font from ${e}: ${t instanceof Error?t.message:String(t)}`,t))}if(!t.ok)return k(vo(N.FONT_FETCH_FAILED,`Failed to fetch font from ${e}: HTTP ${t.status} ${t.statusText}`));r=await t.arrayBuffer()}else r=e;let i;try{i=FK.parse(r)}catch(e){return k(vo(N.FONT_PARSE_FAILED,`Failed to parse font data: ${e instanceof Error?e.message:String(e)}`,e))}let a=i;return eq[t]=a,eq.default||=a,O(a)}var nq=(e=`default`)=>eq[e],rq=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 sR,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 iq(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:i=`default`}={}){let a=nq(i);a||=nq(),a||M(`text`,`No fonts loaded. Call loadFont() before using text functions.`);let o=a.getPath(e,-t,-n,r);return XL(Array.from(rq(o.commands))).mirror([0,0])}var aq={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 oq(e){return typeof e==`string`&&e in aq}var sq=e=>{try{var t=OT();return e.IsNull()?[]:QE(t.u(W(e))).map(e=>j(mk(e)))}catch(e){t.e=e}finally{t.d()}};function cq(e,t,n=!0){let r=U().projectEdges(e.wrapped,[...t.position],[...t.direction],[...t.xAxis]),i=[...sq(r.visible.sharp),...sq(r.visible.smooth),...sq(r.visible.outline)],a=[...sq(r.hidden.sharp),...sq(r.hidden.smooth),...sq(r.hidden.outline)],o;if(n)o=a;else{for(let e of a)e[Symbol.dispose]();o=[]}return{visible:i,hidden:o}}function lq(e=[0,0,0],t=[0,0,1],n){if(AD(t)<1e-12)return k(F(`CAMERA_ZERO_DIRECTION`,`Camera direction cannot be a zero-length vector`));let r;if(n)r=ND(n);else{let e=kD([0,0,1],t);AD(e)<1e-12&&(e=kD([0,1,0],t)),AD(e)<1e-12&&(e=kD([1,0,0],t)),r=ND(e)}let i=ND(kD(t,r));return O({position:e,direction:ND(t),xAxis:r,yAxis:i})}function uq(e,t){let n=ND(TD(e.position,t));return lq(e.position,n)}function dq(e){let t=aq[e];return lq([0,0,0],t.dir,t.xAxis)}function fq(e,t,n=!0){return cq(e,t,n)}var pq=(e,n=1e-7)=>{if(e.length===0)return[];let r=new AL(e.length);e.forEach(e=>{let[t,i]=e.firstPoint;r.add(t-n,i-n,t+n,i+n)}),r.finish();let i=[],a=new Set;return e.forEach((o,s)=>{if(a.has(s))return;let c=[o],l=s;a.add(s);let u=e.length;for(;;){u--<0&&M(`stitchCurves`,`Infinite loop detected`);let[o,s]=t(c,c.length-1).lastPoint,d=r.search(o-n,s-n,o+n,s+n),f=t=>Math.abs((l-t)%e.length),p=d.filter(e=>!a.has(e)).map(n=>[t(e,n),n,f(n)]).sort(([,,e],[,,t])=>e-t);if(p.length===0){i.push(c);break}let[m,h]=t(p,0);c.push(m),a.add(h),l=h}}),i},mq=class extends oR{plane;constructor(e,t){super(),this.plane=e&&typeof e!=`string`?{...e}:j(WD(e??`XY`,t))}delete(){this.pendingCurves=[]}sagittaArcTo(e,t){return super.sagittaArcTo(e,-t)}buildWire(){try{var e=OT();this.pendingCurves.length||M(`Sketcher.buildWire`,`No lines to convert into a wire`);let t=e.u(new VT);return j(SA(pL(this.pendingCurves,this.plane).map(e=>t.register(e))))}catch(t){e.e=t}finally{e.d()}}done(){return new QK(this.buildWire(),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}close(){return this._closeSketch(),this.done()}closeWithMirror(){hI(this.pointer,this.firstPoint)&&M(`Sketcher.closeWithMirror`,`Cannot close with a mirror when the sketch is already closed`);let e=this.buildWire(),t=KD(this.plane,this.pointer),n=kD(ND(TD(t,KD(this.plane,this.firstPoint))),this.plane.zDir),r=j(eO(e.wrapped));return new QK(j(SA([e,_E(j(eO(U().mirror(r,bD(t),bD(n)))))])),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}closeWithCustomCorner(e,t=`fillet`){return this._closeSketch(),this._customCornerLastWithFirst(e,t),this.done()}},hq=class extends oR{face;_bounds;constructor(e,t=[0,0]){super(t),this.face=vE(j(tO(e.wrapped))),this._bounds=uO(e)}_convertToUV([e,t]){let{uMin:n,uMax:r,vMin:i,vMax:a}=this._bounds;return[n+e*(r-n),i+t*(a-i)]}_convertFromUV([e,t]){let{uMin:n,uMax:r,vMin:i,vMax:a}=this._bounds;return[(e-n)/(r-n),(t-i)/(a-i)]}_adaptSurface(){return U().extractSurfaceFromFace(this.face.wrapped)}buildWire(){let e=U(),t=this._adaptSurface(),n=j(SA(this.pendingCurves.map(n=>gE(e.buildEdgeOnSurface(n.wrapped,t)))));return e.buildCurves3d(n.wrapped),n}done(){try{var e=OT();let t=e.u(new VT),n=this.buildWire(),r=new QK(n);if(Ok(n)){let e=t.register(r.clone().face()),n=dO(e,.5,.5),i=ED(mO(e),-1);r.defaultOrigin=[n[0],n[1],n[2]],r.defaultDirection=[i[0],i[1],i[2]]}else{let e=Sk(n),t=mO(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()}},gq=(e,t={})=>{try{var n=OT();let r=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(WD(t.plane??`XY`,t.origin));return new QK(j(SA([n.u(new VT).register(pA(e,r.origin,r.zDir))])),{defaultOrigin:[...r.origin],defaultDirection:[...r.zDir]})}catch(e){n.e=e}finally{n.d()}},_q=(e=1,t=2,n={})=>{try{var r=OT();let i=n.plane&&typeof n.plane!=`string`?{...n.plane}:j(WD(n.plane??`XY`,n.origin)),a=i.xDir,o=e,s=t;return t>e&&(a=RD(a,i.zDir,90*vD),o=t,s=e),new QK(j(SA([r.u(new VT).register(j(mA(o,s,i.origin,i.zDir,a)))])),{defaultOrigin:[...i.origin],defaultDirection:[...i.zDir]})}catch(e){r.e=e}finally{r.d()}},vq=(e,t,n={})=>(n.plane&&typeof n.plane!=`string`?new mq(n.plane):new mq(n.plane,n.origin)).movePointerTo([-e/2,-t/2]).hLine(e).vLine(t).hLine(-e).vLine(-t).done(),yq=(e,t,n=0,r={})=>{let i=mR(e,t,n).sketchOnPlane(r.plane,r.origin),a={};return i.defaultOrigin&&(a.defaultOrigin=i.defaultOrigin),i.defaultDirection&&(a.defaultDirection=i.defaultDirection),new QK(i.wire,a)},bq=(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 mq(r.plane):new mq(r.plane,r.origin),o=lA(i),s=a.movePointerTo([sA(o,0),sA(o,1)]);return n?i.forEach(e=>s.sagittaArcTo([sA(e,0),sA(e,1)],n)):i.forEach(e=>s.lineTo([sA(e,0),sA(e,1)])),s.done()},xq=(e,t,n=0)=>{let r=Math.PI/t,i=Math.cos(r)*e;return n>=0?i:i+n},Sq=(e,t)=>{let n=[...hO(e)],r=[...mO(e)];return new QK(j(Fk(vO(e),t)),{defaultOrigin:n,defaultDirection:r})},Cq=(e,t={},{pointsCount:n=400,start:r=0,stop:i=1}={},a={})=>{try{var o=OT();let s=o.u(new VT),c=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(WD(t.plane??`XY`,t.origin)),l=(i-r)/n,u=[...Array(n+1).keys()].map(t=>{let n=e(r+t*l);return KD(c,n)});return new QK(j(SA([s.register(j(vA(u,a)))])),{defaultOrigin:[...c.origin],defaultDirection:[...c.zDir]})}catch(e){o.e=e}finally{o.d()}},wq=(e,t,n,r=[0,0,0],i=[0,0,1],a=!1)=>new QK(j(SA([hA(e,t,n,bD(r),bD(i),a)]))),Tq=(e,t,n)=>new mq().movePointerTo([-e/2,t/2]).hLine(e).vLine(-t).hLine(-e).close().extrude(n),Eq=(e,t)=>hI(e,t,pI*100),Dq=(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 Oq(e,t,n,r,i){let a=uL(t,n,r.original.lastPoint);e(r),e(a)}function kq(e,t,n,r,i){let a=nL(t,n);e(r),e(a)}function Aq(e,t,n,r,i){let a=Dq(r.offset instanceof QI?_I(t,r.offset.tangentAt(1)):r.offset.firstPoint,t,n,i.offset instanceof QI?gI(n,i.offset.tangentAt(0)):i.offset.lastPoint);if(!a){let i=nL(t,n);e(r),e(i);return}let o=bI([(t[0]+n[0])/2,(t[1]+n[1])/2],a),s=bI(t,n);if(s<1e-18||o>16*s){let i=nL(t,n);e(r),e(i);return}let c=nL(t,a),l=nL(a,n);e(r),e(c),e(l)}var jq={round:Oq,bevel:kq,miter:Aq};function Mq(e,t,n){let r=n.length===1?xo(n,0,`rawOffsets`):Nq(n,e.original.lastPoint),i=xo(e.offset.splitAt([r],pI),0,`rawOffsets`),a=t.offset.splitAt([r],pI).at(-1);return a||M(`offset.rawOffsets`,`Split produced no trailing curve segment`),{splitPrevious:{offset:i,original:e.original},splitCurrent:{offset:a,original:t.original}}}function Nq(e,t){let n=xo(e,0,`selectClosestIntersection`),r=bI(n,t);for(let i=1;i<e.length;i++){let a=xo(e,i,`selectClosestIntersection`),o=bI(a,t);o<r&&(r=o,n=a)}return n}function Pq(e){let t=new Map,n=(e,n)=>{let r=t.get(e)||[];t.set(e,[...r,...n])},r=new AL(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=xo(e,r,`offsetBlueprint`),{intersections:o,commonSegmentsPoints:s}=j(FL(t,a,pI)),c=[...o,...s].filter(e=>{let n=Eq(e,t.firstPoint)||Eq(e,t.lastPoint),r=Eq(e,a.firstPoint)||Eq(e,a.lastPoint);return!(n&&r)});c.length&&(n(i,c),n(r,c))}}),t}function Fq(e,t,n={}){let r=e.orientation===`clockwise`?-t:t,i=e.curves.map(e=>({offset:RL(e,r),original:e})),a=[],o=null,s=i.at(-1);if(!s)return[];function c(e){if(e instanceof QI){a.push(e);return}o?e.offset instanceof QI?a.push(e.offset):Eq(e.offset.firstPoint,e.offset.lastPoint)||a.push(nL(e.offset.firstPoint,e.offset.lastPoint)):o=e}let l=function*(){for(let e of i.slice(0,-1))yield e;o||M(`offset.rawOffsets`,`No saved curve after iterating offset segments`),yield o};for(let e of l()){let t=s.offset.lastPoint,r=e.offset.firstPoint;if(Eq(t,r)){c(s),s=e;continue}let i=[];if(s.offset instanceof QI&&e.offset instanceof QI){let{intersections:t,commonSegmentsPoints:n}=j(FL(s.offset,e.offset,pI/100));i=[...t,...n]}if(i.length>0){let{splitPrevious:t,splitCurrent:n}=Mq(s,e,i);c(t),s=n;continue}let a=jq[n.lineJoinType??`round`];a(c,t,r,s,e),s=e}return c(s),a}function Iq(e,n,r={}){let i=Fq(e,n,r);if(i.length<2)return null;let a=Pq(i);if(!a.size){let t=new EL(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,pI*100)}),s=new AL(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-pI)});if(!l.length)return null;let u=pq(l).filter(e=>e.length>1).map(e=>new EL(e)).filter(e=>e.isClosed());return u.length?u.length===1?xo(u,0,`offsetBlueprint`):new UL(u):null}var Lq=e=>{let t=xo(e,0,`fuseAll`);for(let n=1;n<e.length;n++)t=XR(t,xo(e,n,`fuseAll`));return t};function Rq(e,t,n={}){if(e instanceof EL)return Iq(e,t,n);if(e instanceof UL)return Lq(e.blueprints.map(e=>Rq(e,t,n)));if(e instanceof WL){let r=Lq(e.blueprints.slice(1).map(e=>Rq(e,-t,n)));return QR(Rq(xo(e.blueprints,0,`offset`),t,n),r)}return null}function zq(e,t){return e instanceof EL?new EL(tL(e.curves,t)):e instanceof WL?new WL(e.blueprints.map(e=>zq(e,t))):e instanceof UL?new UL(e.blueprints.map(e=>zq(e,t))):e}function Bq(e,t,n,r){let i=()=>!0;r&&(i=r.shouldKeep.bind(r));let a=[cA(t.curves)],o=(t,r)=>{i({firstCurve:t,secondCurve:r,point:t.lastPoint})?a.push(...e(t,r,n)):a.push(t,r)};t.curves.slice(1).forEach(e=>{let t=a.pop();t||M(`customCorners.modifyCorners`,`Unexpected empty curve stack during filleting`),o(t,e)});let s=a.at(-1);if(s||M(`customCorners.modifyCorners`,`Unexpected empty curve list during corner modification`),hI(cA(a).firstPoint,s.lastPoint)&&a.length>1){let e=a.pop(),t=a.shift();(!e||!t)&&M(`customCorners.modifyCorners`,`Unexpected empty curve stack during close-and-fillet`),o(e,t)}return new EL(a)}function Vq(e,t,n,r){return t instanceof EL?Bq(e,t,n,r):t instanceof WL?new WL(t.blueprints.map(t=>Bq(e,t,n,r))):t instanceof UL?new UL(t.blueprints.map(t=>Vq(e,t,n,r)).filter(e=>e!==null)):null}function Hq(e,t,n){return Vq(BL,e,t,n)}function Uq(e,t,n){return Vq(VL,e,t,n)}function Wq(e,t){return e instanceof EL?LK(t):e instanceof WL?RK(t):new $K(t.map(e=>Array.isArray(e)?RK(e):LK(e)))}var Gq=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 WL)return{type:`CompoundBlueprint`,blueprints:t.blueprints.map(e)};if(t instanceof UL)return{type:`Blueprints`,blueprints:t.blueprints.map(e)};if(t instanceof EL)return{type:`Blueprint`,curves:t.curves.map(e=>e.serialize())};M(`Drawing.serialize`,`Unknown shape type for serialization`)}return JSON.stringify(e(this.innerShape))}get boundingBox(){return this.innerShape?this.innerShape.boundingBox:new XI}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(QR(this.innerShape,t.innerShape))}fuse(t){return new e(XR(this.innerShape,t.innerShape))}intersect(t){return new e($R(this.innerShape,t.innerShape))}fillet(t,n){let r=n&&n(fR());return new e(Hq(this.innerShape,t,r))}chamfer(t,n){let r=n&&n(fR());return new e(Uq(this.innerShape,t,r))}sketchOnPlane(e,t){this.innerShape||M(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnPlane(e,t);return Wq(this.innerShape,n)}sketchOnFace(e,t){this.innerShape||M(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnFace(e,t);return Wq(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(Rq(this.innerShape,t,n))}approximate(t,n={}){return t!==`svg`&&M(`Drawing.approximate`,`Only 'svg' is supported for now`),new e(zq(this.innerShape,n))}get blueprint(){if(!(this.innerShape instanceof EL)){if(this.innerShape instanceof UL&&this.innerShape.blueprints.length===1&&this.innerShape.blueprints[0]instanceof EL)return this.innerShape.blueprints[0];M(`Drawing.blueprint`,`This drawing is not a blueprint`)}return this.innerShape}};function Kq(e){function t(e){if(e.type===`CompoundBlueprint`)return new WL(e.blueprints.map(t));if(e.type===`Blueprints`)return new UL(e.blueprints.map(t));if(e.type===`Blueprint`)return new EL(e.curves.map(e=>ZI(e)));M(`Drawing.deserialize`,`Unknown shape type for deserialization`)}return new Gq(t(JSON.parse(e)))}var qq=class extends oR{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new Gq(new EL(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 Jq(e){let t=new qq;return e&&t.movePointerTo(e),t}function Yq(e,t,n=0){return new Gq(mR(e,t,n))}var Xq=Yq;function Zq(e){return new Gq(new EL([aL(e)]))}function Qq(e,t){let[n,r]=[e,t].sort((e,t)=>e-t);return new Gq(new EL([oL(r,n,r===e?[1,0]:[0,1])]))}function $q(e){return Jq().movePointerTo([-e,0]).sagittaArc(2*e,0,e).sagittaArc(-2*e,0,e).close()}function eJ(e,t){return Jq().movePointerTo([-e,0]).halfEllipse(2*e,0,t).halfEllipse(-2*e,0,t).close()}function tJ(e,t,n=0){return new Gq(pR(e,t,n))}function nJ(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:i=`default`}={}){return new Gq(iq(e,{startX:t,startY:n,fontSize:r,fontFamily:i}))}var rJ=(e,t={},n={})=>{e.length<2&&M(`drawPointsInterpolation`,`Need at least 2 points for interpolation, got ${e.length}`);let r=[j(lL(e,t))],i=e[0],a=e[e.length-1];return n.closeShape&&i&&a&&!hI(i,a)&&r.push(nL(a,i)),new Gq(new EL(r))},iJ=(e,{pointsCount:t=400,start:n=0,stop:r=1,closeShape:i=!1}={},a={})=>{let o=(r-n)/t;return rJ([...Array(t+1).keys()].map(t=>e(n+t*o)),a,{closeShape:i})},aJ=e=>{try{var t=OT();let n=t.u(new VT),r=Xq(1e3,1e3).sketchOnPlane();n.register(r.wire);let i=n.register(j(CA(r.wire))),a=pq(e.map(e=>SL(e,i))).map(e=>new EL(e));return a.length===0?new Gq:a.length===1?new Gq(a[0]):new Gq(new UL(a))}catch(e){t.e=e}finally{t.d()}};function oJ(e,t=`front`){let n;n=typeof t==`string`?j(dq(t)):t;let{visible:r,hidden:i}=fq(e,n);try{return{visible:aJ(r),hidden:aJ(i)}}finally{for(let e of r)e[Symbol.dispose]();for(let e of i)e[Symbol.dispose]()}}function sJ(e){try{var t=OT();let n=t.u(new VT),r=n.register(vE(j(tO(e.wrapped)))),i=pq(QE(n.register(vO(r))).map(t=>SL(t,e))).map(e=>new EL(e));return i.length===0?new Gq:i.length===1?new Gq(i[0]):new Gq(new UL(i))}catch(e){t.e=e}finally{t.d()}}function cJ(e,t,n){return n===void 0?e.sketchOnPlane(t):e.sketchOnPlane(t,n)}function lJ(e,t){return e.fuse(t)}function uJ(e,t){return e.cut(t)}function dJ(e,t){return e.intersect(t)}function fJ(e,t,n){return e.fillet(t,n)}function pJ(e,t,n){return e.chamfer(t,n)}function mJ(e,t,n=0){return typeof t==`number`?e.translate(t,n):e.translate(t)}function hJ(e,t,n){return e.rotate(t,n)}function gJ(e,t,n){return e.scale(t,n)}function _J(e,t,n,r){return e.mirror(t,n,r)}function vJ(e){let t=e.clone();return t.reverse(),t}function yJ(e){return e.boundingBox}function bJ(e){return e.firstPoint}function xJ(e){return e.lastPoint}function SJ(e,t,n){return e.splitAt(t,n)}function CJ(e,t,n){return e.parameter(t,n)}function wJ(e,t){return e.tangentAt(t)}function TJ(e,t){return e.isOnCurve(t)}function EJ(e,t){return e.distanceFrom(t)}function DJ(e){return e.length===0?k(F(N.BLUEPRINT_EMPTY_CURVES,`createBlueprint: at least one curve is required`)):O(new EL(e))}function OJ(e){return e.length===0?k(F(N.COMPOUND_BLUEPRINT_EMPTY,`createCompoundBlueprint: at least one blueprint (outer boundary) is required`)):O(new WL(e))}function kJ(e){return e.boundingBox}function AJ(e){return e.orientation}function jJ(e,t){return e.isInside(t)}function MJ(e){return e.toSVGPathD()}function NJ(e,t,n){return e.translate(t,n)}function PJ(e,t,n){return e.rotate(t,n)}function FJ(e,t,n){return e.scale(t,n)}function IJ(e,t,n,r){return e.mirror(t,n,r)}function LJ(e,t,n,r){return e.stretch(t,n,r)}function RJ(e,t,n){return e.sketchOnPlane(t,n)}function zJ(e,t,n){return e.sketchOnFace(t,n)}function BJ(e,t){return n(e,t*3)}function VJ(e,t){return n(e,t)}function HJ(e){let t=[`# brepjs OBJ export`],n=e.vertices.length/3;for(let r=0;r<n;r++){let[n,i,a]=BJ(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]=BJ(e.normals,n);t.push(`vn ${r} ${i} ${a}`)}let i=n=>{let[r,i,a]=VJ(e.triangles,n);t.push(`f ${r+1}//${r+1} ${i+1}//${i+1} ${a+1}//${a+1}`)};if(e.faceGroups.length>0)for(let n of e.faceGroups){t.push(`g face_${n.faceId}`);let e=n.count/3;for(let t=0;t<e;t++)i(n.start+t*3)}else{let t=e.triangles.length/3;for(let e=0;e<t;e++)i(e*3)}return t.join(`
25
25
  `)+`
26
- `}var RJ=5126,zJ=5125,BJ=34962,VJ=34963,HJ=[-Math.SQRT1_2,0,0,Math.SQRT1_2];function UJ(e){return e===`Z`?[{mesh:0}]:[{name:`Z_up_to_Y_up`,rotation:HJ,children:[1]},{mesh:0}]}function WJ(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 GJ(e){return e+3&-4}function KJ(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 qJ(e,t){let n=ZJ(e,`base64`,t);return JSON.stringify(n)}function JJ(e,t){let{doc:n,binBuffer:r}=QJ(e,t),i=JSON.stringify(n),a=new TextEncoder().encode(i),o=GJ(a.length),s=new Uint8Array(o);s.set(a);for(let e=a.length;e<o;e++)s[e]=32;let c=GJ(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 YJ(e,t,n,r,i){return[{bufferView:0,componentType:zJ,count:e.length,type:`SCALAR`},{bufferView:1,componentType:RJ,count:t.length/3,type:`VEC3`,min:r,max:i},{bufferView:2,componentType:RJ,count:n.length/3,type:`VEC3`}]}function XJ(e,t,n){return[{buffer:0,byteOffset:0,byteLength:e,target:VJ},{buffer:0,byteOffset:GJ(e),byteLength:t,target:BJ},{buffer:0,byteOffset:GJ(e)+t,byteLength:n,target:BJ}]}function ZJ(e,t,n){let{vertices:r,normals:i,triangles:a}=e,o=n?.materials;if(o&&o.size>0&&e.faceGroups.length>0)return iY(e,t,o,n.upAxis??`Y`);let s=a.byteLength,c=r.byteLength,l=i.byteLength,u=GJ(s)+c+l,{min:d,max:f}=WJ(r),p={asset:{version:`2.0`,generator:`brepjs`},scene:0,scenes:[{nodes:[0]}],nodes:UJ(n?.upAxis??`Y`),meshes:[{primitives:[{attributes:{POSITION:1,NORMAL:2},indices:0}]}],accessors:YJ(a,r,i,d,f),bufferViews:XJ(s,c,l),buffers:[{byteLength:u}]};if(t===`base64`){let t=oY(e);p.buffers[0]={byteLength:u,uri:`data:application/octet-stream;base64,`+KJ(t)}}return p}function QJ(e,t){let n=t?.materials;if(n&&n.size>0&&e.faceGroups.length>0){let{doc:r,binBuffer:i}=aY(e,n,t.upAxis??`Y`);return{doc:r,binBuffer:i}}return{doc:ZJ(e,`glb`,t),binBuffer:oY(e)}}function $J(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=aA(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+=aA(o,e).count;let i=new Uint32Array(r),s=0;for(let e of n){let n=aA(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=GJ(f+t)}let m=f;return{primitiveData:d,indexBufferInfos:p,verticesOffset:m,totalByteLength:m+r.byteLength+i.byteLength,uniqueMaterials:s}}function eY(e,t,n,r){let{vertices:i,normals:a}=e,{min:o,max:s}=WJ(i),c=r.length;r.push({buffer:0,byteOffset:t,byteLength:i.byteLength,target:BJ});let l=n.length;n.push({bufferView:c,componentType:RJ,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:BJ});let d=n.length;return n.push({bufferView:u,componentType:RJ,count:a.length/3,type:`VEC3`}),{verticesAccIdx:l,normalsAccIdx:d}}function tY(e,t,n,r,i,a){let o=[];for(let s=0;s<e.length;s++){let c=aA(e,s),l=aA(t,s),u=a.length;a.push({buffer:0,byteOffset:l.byteOffset,byteLength:l.byteLength,target:VJ});let d=i.length;i.push({bufferView:u,componentType:zJ,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 nY(e,t,n=`Y`){let{primitiveData:r,indexBufferInfos:i,verticesOffset:a,totalByteLength:o,uniqueMaterials:s}=t,c=[],l=[],{verticesAccIdx:u,normalsAccIdx:d}=eY(e,a,c,l),f=tY(r,i,u,d,c,l);return{asset:{version:`2.0`,generator:`brepjs`},scene:0,scenes:[{nodes:[0]}],nodes:UJ(n),meshes:[{primitives:f}],accessors:c,bufferViews:l,buffers:[{byteLength:o}],materials:s}}function rY(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=aA(i,e),n=aA(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 iY(e,t,n,r=`Y`){let i=$J(e,n),a=nY(e,i,r);if(t===`base64`){let t=rY(e,i);a.buffers[0]={byteLength:i.totalByteLength,uri:`data:application/octet-stream;base64,`+KJ(t)}}return a}function aY(e,t,n=`Y`){let r=$J(e,t);return{doc:nY(e,r,n),binBuffer:rY(e,r)}}function oY(e){let{vertices:t,normals:n,triangles:r}=e,i=r.byteLength,a=t.byteLength,o=n.byteLength,s=GJ(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),GJ(i)),l.set(new Uint8Array(n.buffer,n.byteOffset,o),GJ(i)+a),c}function sY(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(`
26
+ `}var UJ=5126,WJ=5125,GJ=34962,KJ=34963,qJ=[-Math.SQRT1_2,0,0,Math.SQRT1_2];function JJ(e){return e===`Z`?[{mesh:0}]:[{name:`Z_up_to_Y_up`,rotation:qJ,children:[1]},{mesh:0}]}function YJ(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 XJ(e){return e+3&-4}function ZJ(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 QJ(e,t){let n=nY(e,`base64`,t);return JSON.stringify(n)}function $J(e,t){let{doc:n,binBuffer:r}=rY(e,t),i=JSON.stringify(n),a=new TextEncoder().encode(i),o=XJ(a.length),s=new Uint8Array(o);s.set(a);for(let e=a.length;e<o;e++)s[e]=32;let c=XJ(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 eY(e,t,n,r,i){return[{bufferView:0,componentType:WJ,count:e.length,type:`SCALAR`},{bufferView:1,componentType:UJ,count:t.length/3,type:`VEC3`,min:r,max:i},{bufferView:2,componentType:UJ,count:n.length/3,type:`VEC3`}]}function tY(e,t,n){return[{buffer:0,byteOffset:0,byteLength:e,target:KJ},{buffer:0,byteOffset:XJ(e),byteLength:t,target:GJ},{buffer:0,byteOffset:XJ(e)+t,byteLength:n,target:GJ}]}function nY(e,t,n){let{vertices:r,normals:i,triangles:a}=e,o=n?.materials;if(o&&o.size>0&&e.faceGroups.length>0)return lY(e,t,o,n.upAxis??`Y`);let s=a.byteLength,c=r.byteLength,l=i.byteLength,u=XJ(s)+c+l,{min:d,max:f}=YJ(r),p={asset:{version:`2.0`,generator:`brepjs`},scene:0,scenes:[{nodes:[0]}],nodes:JJ(n?.upAxis??`Y`),meshes:[{primitives:[{attributes:{POSITION:1,NORMAL:2},indices:0}]}],accessors:eY(a,r,i,d,f),bufferViews:tY(s,c,l),buffers:[{byteLength:u}]};if(t===`base64`){let t=dY(e);p.buffers[0]={byteLength:u,uri:`data:application/octet-stream;base64,`+ZJ(t)}}return p}function rY(e,t){let n=t?.materials;if(n&&n.size>0&&e.faceGroups.length>0){let{doc:r,binBuffer:i}=uY(e,n,t.upAxis??`Y`);return{doc:r,binBuffer:i}}return{doc:nY(e,`glb`,t),binBuffer:dY(e)}}function iY(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=sA(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+=sA(o,e).count;let i=new Uint32Array(r),s=0;for(let e of n){let n=sA(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=XJ(f+t)}let m=f;return{primitiveData:d,indexBufferInfos:p,verticesOffset:m,totalByteLength:m+r.byteLength+i.byteLength,uniqueMaterials:s}}function aY(e,t,n,r){let{vertices:i,normals:a}=e,{min:o,max:s}=YJ(i),c=r.length;r.push({buffer:0,byteOffset:t,byteLength:i.byteLength,target:GJ});let l=n.length;n.push({bufferView:c,componentType:UJ,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:GJ});let d=n.length;return n.push({bufferView:u,componentType:UJ,count:a.length/3,type:`VEC3`}),{verticesAccIdx:l,normalsAccIdx:d}}function oY(e,t,n,r,i,a){let o=[];for(let s=0;s<e.length;s++){let c=sA(e,s),l=sA(t,s),u=a.length;a.push({buffer:0,byteOffset:l.byteOffset,byteLength:l.byteLength,target:KJ});let d=i.length;i.push({bufferView:u,componentType:WJ,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 sY(e,t,n=`Y`){let{primitiveData:r,indexBufferInfos:i,verticesOffset:a,totalByteLength:o,uniqueMaterials:s}=t,c=[],l=[],{verticesAccIdx:u,normalsAccIdx:d}=aY(e,a,c,l),f=oY(r,i,u,d,c,l);return{asset:{version:`2.0`,generator:`brepjs`},scene:0,scenes:[{nodes:[0]}],nodes:JJ(n),meshes:[{primitives:f}],accessors:c,bufferViews:l,buffers:[{byteLength:o}],materials:s}}function cY(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=sA(i,e),n=sA(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 lY(e,t,n,r=`Y`){let i=iY(e,n),a=sY(e,i,r);if(t===`base64`){let t=cY(e,i);a.buffers[0]={byteLength:i.totalByteLength,uri:`data:application/octet-stream;base64,`+ZJ(t)}}return a}function uY(e,t,n=`Y`){let r=iY(e,t);return{doc:sY(e,r,n),binBuffer:cY(e,r)}}function dY(e){let{vertices:t,normals:n,triangles:r}=e,i=r.byteLength,a=t.byteLength,o=n.byteLength,s=XJ(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),XJ(i)),l.set(new Uint8Array(n.buffer,n.byteOffset,o),XJ(i)+a),c}function fY(e,t){let n=t?.layer??`0`,r=[];r.push(`0`,`SECTION`,`2`,`HEADER`),r.push(`9`,`$ACADVER`,`1`,`AC1009`),r.push(`0`,`ENDSEC`);let i=new Set([n]);for(let t of e)t.layer&&i.add(t.layer);r.push(`0`,`SECTION`,`2`,`TABLES`),r.push(`0`,`TABLE`,`2`,`LAYER`,`70`,String(i.size));for(let e of i)r.push(`0`,`LAYER`,`2`,e,`70`,`0`,`62`,`7`,`6`,`CONTINUOUS`);r.push(`0`,`ENDTAB`),r.push(`0`,`ENDSEC`),r.push(`0`,`SECTION`,`2`,`ENTITIES`);for(let t of e){let e=t.layer??n;if(t.type===`LINE`)r.push(`0`,`LINE`,`8`,e,`10`,String(t.start[0]),`20`,String(t.start[1]),`30`,`0`,`11`,String(t.end[0]),`21`,String(t.end[1]),`31`,`0`);else{r.push(`0`,`LWPOLYLINE`,`8`,e,`90`,String(t.points.length),`70`,t.closed?`1`:`0`);for(let e of t.points)r.push(`10`,String(e[0]),`20`,String(e[1]))}}return r.push(`0`,`ENDSEC`),r.push(`0`,`EOF`),r.join(`
27
27
  `)+`
28
- `}function cY(e,t){let n=t?.curveSegments??32,r=[],i=lY(e);for(let e of i)for(let t of e.curves)r.push(...uY(t,n));return sY(r,t)}function lY(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(...lY(n));return t}return[]}function uY(e,t){return e.geomType===`LINE`?[{type:`LINE`,start:e.firstPoint,end:e.lastPoint}]:[dY(e,t)]}function dY(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 fY=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;fY[e]=t}function pY(e){let t=4294967295;for(let n of e)t=(fY[(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 hY(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 gY(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 _Y(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=hY(s,c,l,e,t);return gY(s,l,e.length,r,i),o}function vY(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`"`,`&quot;`)}function yY(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 bY(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 xY(e){let t=new Map,n=[];if(e!==void 0&&e.size>0)for(let r of e.values()){let e=yY(r);t.has(e)||(t.set(e,n.length),n.push(e))}return{colorIndexByHex:t,colorHexList:n}}function SY(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 CY(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=yY(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 wY(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 TY(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`:yY(e.displayColor);return` <base name="${vY(e.name)}" displaycolor="${t}" />`}).join(`
30
- `);n.push(` <basematerials id="3">\n${e}\n </basematerials>`)}return n}function EY(e,t,n,r,i){let a=bY(e),{colorIndexByHex:o,colorHexList:s}=xY(r),{materialIndexByName:c,materialList:l}=SY(i),u=wY(e,CY(e,r,i,o,c)),d=TY(s,l);return`<?xml version="1.0" encoding="UTF-8"?>
28
+ `}function pY(e,t){let n=t?.curveSegments??32,r=[],i=mY(e);for(let e of i)for(let t of e.curves)r.push(...hY(t,n));return fY(r,t)}function mY(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(...mY(n));return t}return[]}function hY(e,t){return e.geomType===`LINE`?[{type:`LINE`,start:e.firstPoint,end:e.lastPoint}]:[gY(e,t)]}function gY(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 _Y=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;_Y[e]=t}function vY(e){let t=4294967295;for(let n of e)t=(_Y[(t^n)&255]??0)^t>>>8;return(t^4294967295)>>>0}function yY(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 bY(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 xY(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 SY(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=yY(s,c,l,e);for(let{offset:e,entry:t}of n)l=bY(s,c,l,e,t);return xY(s,l,e.length,r,i),o}function CY(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`"`,`&quot;`)}function wY(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 TY(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 EY(e){let t=new Map,n=[];if(e!==void 0&&e.size>0)for(let r of e.values()){let e=wY(r);t.has(e)||(t.set(e,n.length),n.push(e))}return{colorIndexByHex:t,colorHexList:n}}function DY(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 OY(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=wY(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 kY(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 AY(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`:wY(e.displayColor);return` <base name="${CY(e.name)}" displaycolor="${t}" />`}).join(`
30
+ `);n.push(` <basematerials id="3">\n${e}\n </basematerials>`)}return n}function jY(e,t,n,r,i){let a=TY(e),{colorIndexByHex:o,colorHexList:s}=EY(r),{materialIndexByName:c,materialList:l}=DY(i),u=kY(e,OY(e,r,i,o,c)),d=AY(s,l);return`<?xml version="1.0" encoding="UTF-8"?>
31
31
  <model unit="${n}" xmlns="http://schemas.microsoft.com/3dmanufacturing/core/2015/02"${l.length>0?`
32
32
  xmlns:m="http://schemas.microsoft.com/3dmanufacturing/material/2015/02"`:``}>
33
33
  <resources>${d.length>0?`
34
34
  `+d.join(`
35
35
  `):``}
36
- <object id="1" name="${vY(t)}" type="model">
36
+ <object id="1" name="${CY(t)}" type="model">
37
37
  <mesh>
38
38
  <vertices>
39
39
  ${a.join(`
@@ -49,12 +49,12 @@ ${u.join(`
49
49
  <build>
50
50
  <item objectid="1" />
51
51
  </build>
52
- </model>`}function DY(e,t={}){let{name:n=`model`,unit:r=`millimeter`,colors:i,materials:a}=t,o=new TextEncoder,s=EY(e,n,r,i,a);function c(e,t){let n=o.encode(e),r=o.encode(t);return{name:n,data:r,crc:pY(r)}}return _Y([c(`[Content_Types].xml`,`<?xml version="1.0" encoding="UTF-8"?>
52
+ </model>`}function MY(e,t={}){let{name:n=`model`,unit:r=`millimeter`,colors:i,materials:a}=t,o=new TextEncoder,s=jY(e,n,r,i,a);function c(e,t){let n=o.encode(e),r=o.encode(t);return{name:n,data:r,crc:vY(r)}}return SY([c(`[Content_Types].xml`,`<?xml version="1.0" encoding="UTF-8"?>
53
53
  <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
54
54
  <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
55
55
  <Default Extension="model" ContentType="application/vnd.ms-package.3dmanufacturing-3dmodel+xml" />
56
56
  </Types>`),c(`_rels/.rels`,`<?xml version="1.0" encoding="UTF-8"?>
57
57
  <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
58
58
  <Relationship Target="/3D/3dmodel.model" Id="rel0" Type="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel" />
59
- </Relationships>`),c(`3D/3dmodel.model`,s)])}function OY(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 kY(e){return[e[0],-e[1]]}function AY(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(ZI(kY([t.cx,t.cy]),kY([a,o]))),t.cx=a,t.cy=o,i+=2}}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);r.push(ZI(kY([t.cx,t.cy]),kY([a,o]))),t.cx=a,t.cy=o,i+=2}}function MY(e,t,n,r){for(let i of e){let e=n?t.cx+i:i;r.push(ZI(kY([t.cx,t.cy]),kY([e,t.cy]))),t.cx=e}}function NY(e,t,n,r){for(let i of e){let e=n?t.cy+i:i;r.push(ZI(kY([t.cx,t.cy]),kY([t.cx,e]))),t.cy=e}}function PY(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(rL(kY([t.cx,t.cy]),[kY([s,c]),kY([l,u])],kY([d,f]))),t.prevControlX=l,t.prevControlY=u,t.cx=d,t.cy=f,i+=6}}function FY(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(rL(kY([t.cx,t.cy]),[kY([c,l]),kY([u,d])],kY([f,p]))),t.prevControlX=u,t.prevControlY=d,t.cx=f,t.cy=p,t.lastCmd=`S`,i+=4}}function IY(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(rL(kY([t.cx,t.cy]),[kY([s,c])],kY([l,u]))),t.prevControlX=s,t.prevControlY=c,t.cx=l,t.cy=u,i+=4}}function LY(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(rL(kY([t.cx,t.cy]),[kY([c,l])],kY([u,d]))),t.prevControlX=c,t.prevControlY=l,t.cx=u,t.cy=d,t.lastCmd=`T`,i+=2}}function RY(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[QI(kY([e,t]),kY(c),kY([e,s])),QI(kY([e,s]),kY(l),kY([e,t]))]}catch{return[]}}function zY(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[QI(kY([e,t]),kY([b,x]),kY([n,r]))]}catch{return[ZI(kY([e,t]),kY([n,r]))]}}function BY(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(ZI(kY([t.cx,t.cy]),kY([d,f])));else{let e=d-t.cx,n=f-t.cy;Math.sqrt(e*e+n*n)<1e-10?r.push(...RY(t.cx,t.cy,s,c,u)):r.push(...zY(t.cx,t.cy,d,f,s,c,l,u))}t.cx=d,t.cy=f,i+=7}}function VY(e,t){(Math.abs(e.cx-e.sx)>1e-10||Math.abs(e.cy-e.sy)>1e-10)&&t.push(ZI(kY([e.cx,e.cy]),kY([e.sx,e.sy]))),e.cx=e.sx,e.cy=e.sy}function HY(e){let t=OY(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`:AY(i,r,t,n);break;case`L`:jY(i,r,t,n);break;case`H`:MY(i,r,t,n);break;case`V`:NY(i,r,t,n);break;case`C`:PY(i,r,t,n);break;case`S`:FY(i,r,t,n);break;case`Q`:IY(i,r,t,n);break;case`T`:LY(i,r,t,n);break;case`A`:BY(i,r,t,n);break;case`Z`:VY(r,n);break}a!==`S`&&a!==`T`&&(r.lastCmd=a)}return n}function UY(e){try{let t=HY(e);return t.length===0?k(vo(`SVG_EMPTY_PATH`,`SVG path produced no curves`)):O(new xL(t))}catch(e){return k(vo(`SVG_PARSE_FAILED`,`Failed to parse SVG path: ${e instanceof Error?e.message:String(e)}`))}}function WY(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=UY(l);u.ok&&n.push(u.value)}return n.length===0?k(vo(`SVG_NO_PATHS`,`No <path> elements found in SVG`)):O(n)}catch(e){return k(vo(`SVG_IMPORT_FAILED`,`Failed to import SVG: ${e instanceof Error?e.message:String(e)}`))}}function GY(e,t){try{let n=U(),r=e.map(e=>({shape:e.shape.wrapped,name:e.name,color:e.color?[...e.color]:void 0}));return O(n.exportSTEPConfigured(r,t))}catch(e){return k(vo(N.STEP_EXPORT_CONFIGURED_FAILED,`Configured STEP export failed`,e))}}async function KY(e){try{let t=await e.arrayBuffer(),n=U().importSTEP(t);return n.length===0?k(vo(`STEP_IMPORT_FAILED`,`STEP file contains no valid geometry`)):O(jE(n[0]))}catch(e){return k(vo(`STEP_IMPORT_FAILED`,`Failed to load STEP file`,e))}}async function qY(e){try{let t=await e.arrayBuffer(),n=U().importSTL(t);return n.IsNull()?k(vo(`STL_IMPORT_FAILED`,`Failed to create solid from STL mesh`)):O(jE(n))}catch(e){return k(vo(`STL_IMPORT_FAILED`,`Failed to load STL file`,e))}}async function JY(e){try{let t=await e.arrayBuffer(),n=U().importIGES(t);return n.length===0?k(vo(`IGES_IMPORT_FAILED`,`IGES file contains no valid geometry`)):O(jE(n[0]))}catch(e){return k(vo(`IGES_IMPORT_FAILED`,`Failed to load IGES file`,e))}}function YY(e,t,n={}){let r=$K(e,t);return new JK((typeof n.plane==`string`||n.plane===void 0?r.sketchOnPlane(n.plane,n.origin):r.sketchOnPlane(n.plane)).map(e=>Array.isArray(e)?new jK(e.map(MK)):MK(e)))}function XY(e,t){let n=t?.fontSize??1,r=ZK(t?.fontFamily);if(!r)return k(F(N.NO_FONT_LOADED,`No font loaded. Call loadFont() first.`,void 0,void 0,`Load a font with loadFont() before calling textMetrics()`));let i=r.getAdvanceWidth(e,n),a=n/r.unitsPerEm,o=r.ascender*a,s=r.descender*a;return O({width:i,height:o-s,ascender:o,descender:s})}function ZY(e){let t=e?.fontSize??1,n=ZK(e?.fontFamily);if(!n)return k(F(N.NO_FONT_LOADED,`No font loaded. Call loadFont() first.`,void 0,void 0,`Load a font with loadFont() before calling fontMetrics()`));let r=t/n.unitsPerEm,i=n.ascender*r,a=n.descender*r,o=(n.tables?.os2?.sTypoLineGap??0)*r;return O({ascender:i,descender:a,unitsPerEm:n.unitsPerEm,lineHeight:i-a+o})}function QY(e){return e.type===`init`}function $Y(e){return e.type===`operation`}function eX(e){return e.type===`dispose`}function tX(e){return e.type===`batch`}function nX(e){return e.success}function rX(e){return!e.success}function iX(){return{pending:new Map}}function aX(e,t){let n=new Map(e.pending);return n.set(t.id,t),{pending:n}}function oX(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 sX(e){return e.pending.size}function cX(e){return e.pending.size===0}function lX(e,t){for(let n of e.pending.values())n.reject(t);return{pending:new Map}}function uX(e,t){let n=t.data,r=e.get(n.id);if(r)if(e.delete(n.id),nX(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 dX(e){let{worker:t,wasmUrl:n}=e,r=new Map,i=!1;function a(){return crypto.randomUUID()}function o(e){uX(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 fX(){return{operations:new Map}}function pX(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 hX(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 gX(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 _X(e,t){let n=globalThis;n.onmessage=async r=>{let i=r.data;if(QY(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($Y(i)){let t=hX(e,i.operation,i.shapesBrep,i.parameters);n.postMessage(gX(i.id,t));return}if(tX(i)){let t=i.operations.map(t=>hX(e,t.operation,t.shapesBrep,t.params)),r={id:i.id,success:!0,resultData:t};n.postMessage(r);return}if(eX(i)){let e={id:i.id,success:!0};n.postMessage(e),n.close?.()}}}function vX(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:dX({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 yX=Object.defineProperty,bX=(e,t)=>{let n={};for(var r in e)yX(n,r,{get:e[r],enumerable:!0});return t||yX(n,Symbol.toStringTag,{value:`Module`}),n},xX=1,SX=2;function CX(e,t){t===`commonFace`&&e.SetGlue(xX),t===`sameFace`&&e.SetGlue(SX)}function wX(e){return typeof e==`number`}function TX(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 EX(e){return typeof e==`number`?!0:Array.isArray(e)&&e.length===2?e.every(wX):!1}function DX(e,t){let n=n=>{let r=e.findAll(n);if(r.length===0)return[];let i=0,a=AD(hD(oA(r)),t);for(let e=1;e<r.length;e++){let n=AD(hD(aA(r,e)),t);n<a&&(a=n,i=e)}return[aA(r,i)]},r=e=>{let t=n(e);return t.length===0?k(yo(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found 0 element(s)`)):O(oA(t))};return{...e,findAll:n,findUnique:r}}function OX(e){return TI(`vertex`,e,OX,(t,n)=>({nearestTo:t=>DX(OX(e),t),atPosition:(e,t=1e-4)=>n(n=>AD(hD(n),e)<t),withinBox:(e,t)=>n(n=>{let r=hD(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=hD(n);return Math.abs(AD(i,t)-e)<r})}))}function kX(){return OX([])}var AX=new Map,jX=null,MX=null;function NX(e,t){AX.set(e,t),jX||=e,e===jX&&(MX=t)}function PX(e){if(!e&&MX)return MX;let t=e??jX;if(!t)throw Error(`brepjs voxel engine not initialized. Call initVoxel() (or registerVoxel()) before using voxel operations.`);let n=AX.get(t);if(!n)throw Error(`brepjs: voxel engine '${t}' is not registered.`);return n}function FX(){return jX}function IX(e,t=`voxel`){NX(t,e),jX=t,MX=e}function LX(e){if(e.vertices.length%3!=0)return F(`VOXEL_INVALID_MESH`,`mesh.vertices length must be a multiple of 3 (flat xyz).`);if(e.triangles.length%3!=0)return F(`VOXEL_INVALID_MESH`,`mesh.triangles length must be a multiple of 3.`);let t=e.vertices.length/3;for(let n=0;n<e.triangles.length;n++){let r=e.triangles[n];if(r===void 0||r>=t)return F(`VOXEL_INVALID_TRIANGLE_INDEX`,`triangle index ${r} at position ${n} is out of range for ${t} vertices.`)}return null}function RX(e,t){return LX(e)||(t.length%3==0?null:F(`VOXEL_INVALID_QUERIES`,`queries length must be a multiple of 3 (flat xyz).`))}function zX(e){try{return O(PX(e))}catch(e){return k(_o(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function BX(e,t,n){let r=RX(e,t);if(r)return k(r);let i=zX(n);return A(i)?i:O(i.value.winding_numbers(e.vertices,e.triangles,t))}function VX(e,t,n){let r=RX(e,t);if(r)return k(r);let i=zX(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 HX=48,UX=2;function WX(e,t,n){let r=LX(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`repairMesh requires a non-empty triangle mesh.`));let i=t?.resolution??HX,a=t?.padding??UX;if(!Number.isInteger(i)||i<1)return k(F(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`));if(!Number.isInteger(a)||a<1)return k(F(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`));let o=zX(n);if(A(o))return o;try{try{var s=OT();let t=s.u(o.value.repair_mesh(e.vertices,e.triangles,i,a)),n=t.positions.length/3;return O({vertices:t.positions,normals:t.normals,triangles:t.indices,uvs:new Float32Array(n*2),faceGroups:[{start:0,count:t.indices.length/3,faceHash:0}]})}catch(e){s.e=e}finally{s.d()}}catch(e){return k(I(`VOXEL_REPAIR_FAILED`,e instanceof Error?e.message:`voxel repair failed (grid too large?).`,e))}}var GX=.001;function KX(e,t=GX){try{let n=Wk(e,{tolerance:t});return n.vertices.length===0||n.triangles.length===0?k(I(`VOXEL_SHAPE_MESH_EMPTY`,`shape tessellated to an empty triangle mesh.`)):O({vertices:n.vertices,triangles:n.triangles})}catch(e){return k(I(`VOXEL_SHAPE_MESH_FAILED`,e instanceof Error?e.message:`failed to mesh shape for voxel op.`,e))}}var qX=48,JX=2,YX={union:0,intersection:1,difference:2};function XX(e){let t=e?.resolution??qX,n=e?.padding??JX;return!Number.isInteger(t)||t<1?k(F(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(F(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function ZX(e){if(e.positions.length===0||e.indices.length===0)return k(I(`VOXEL_DEGENERATE_RESULT`,`the voxel operation produced an empty mesh (over-shrunk offset or disjoint operands?).`));let t=e.positions.length/3;return O({vertices:e.positions,normals:e.normals,triangles:e.indices,uvs:new Float32Array(t*2),faceGroups:[{start:0,count:e.indices.length/3,faceHash:0}]})}function QX(e,t,n,r){let i=LX(e);if(i)return k(i);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`offsetMesh requires a non-empty triangle mesh.`));if(!Number.isFinite(t))return k(F(`VOXEL_INVALID_DISTANCE`,`distance must be a finite number.`));let a=XX(n);if(A(a))return a;let o=zX(r);if(A(o))return o;try{try{var s=OT();return ZX(s.u(o.value.offset_mesh(e.vertices,e.triangles,t,a.value.resolution,a.value.padding)))}catch(e){s.e=e}finally{s.d()}}catch(e){return k(I(`VOXEL_OFFSET_FAILED`,e instanceof Error?e.message:`voxel offset failed (grid too large?).`,e))}}function $X(e,t,n,r){let i=LX(e);if(i)return k(i);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`shellMesh requires a non-empty triangle mesh.`));if(!Number.isFinite(t)||t<=0)return k(F(`VOXEL_INVALID_THICKNESS`,`thickness must be a finite number > 0.`));let a=XX(n);if(A(a))return a;let o=zX(r);if(A(o))return o;try{try{var s=OT();return ZX(s.u(o.value.shell_mesh(e.vertices,e.triangles,t,a.value.resolution,a.value.padding)))}catch(e){s.e=e}finally{s.d()}}catch(e){return k(I(`VOXEL_SHELL_FAILED`,e instanceof Error?e.message:`voxel shell failed (grid too large?).`,e))}}function eZ(e,t,n,r,i){let a=LX(e);if(a)return k(a);let o=LX(t);if(o)return k(o);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBoolean requires a non-empty mesh for operand A.`));if(t.vertices.length===0||t.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBoolean requires a non-empty mesh for operand B.`));let s=YX[n],c=XX(r);if(A(c))return c;let l=zX(i);if(A(l))return l;try{try{var u=OT();return ZX(u.u(l.value.voxel_boolean(e.vertices,e.triangles,t.vertices,t.triangles,s,c.value.resolution,c.value.padding)))}catch(e){u.e=e}finally{u.d()}}catch(e){return k(I(`VOXEL_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel boolean failed (grid too large?).`,e))}}function tZ(e,t,n,r){let i=KX(e);return A(i)?i:QX(i.value,t,n,r)}function nZ(e,t,n,r){let i=KX(e);return A(i)?i:$X(i.value,t,n,r)}function rZ(e,t,n,r,i){let a=KX(e);if(A(a))return a;let o=KX(t);return A(o)?o:eZ(a.value,o.value,n,r,i)}var iZ=48,aZ=2,oZ={union:0,intersection:1,difference:2};function sZ(e){let t=e?.resolution??iZ,n=e?.padding??aZ;return!Number.isInteger(t)||t<1?k(F(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(F(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function cZ(e){try{var t=OT();let n=e.contour(),{positions:r,normals:i,indices:a}=t.u({value:n,[Symbol.dispose](){n.free()}}).value;if(r.length===0||a.length===0)return k(I(`VOXEL_DEGENERATE_RESULT`,`the voxel field contoured to an empty mesh (over-shrunk offset or disjoint operands?).`));let o=r.length/3;return O({vertices:r,normals:i,triangles:a,uvs:new Float32Array(o*2),faceGroups:[{start:0,count:a.length/3,faceHash:0}]})}catch(e){t.e=e}finally{t.d()}}function lZ(e){return{raw:e,delete(){e.free()}}}function uZ(e){return dZ(e)}function dZ(e){let t=zT(lZ(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,oZ[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=cZ(this.value);if(A(e))throw Error(e.error.message);return e.value}};return n}function fZ(e){return!e.disposed}function pZ(){return k(F(`VOXEL_FIELD_DISPOSED`,`the voxel field handle has been disposed.`))}function mZ(e,t,n){let r=LX(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelField requires a non-empty triangle mesh.`));let i=sZ(t);if(A(i))return i;let a=zX(n);if(A(a))return a;try{return O(dZ(new a.value.VoxelField(e.vertices,e.triangles,i.value.resolution,i.value.padding)))}catch(e){return k(I(`VOXEL_FIELD_VOXELIZE_FAILED`,e instanceof Error?e.message:`voxel field voxelization failed (grid too large or non-dense?).`,e))}}function hZ(e,t,n,r,i){let a=LX(e);if(a)return k(a);let o=LX(t);if(o)return k(o);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBooleanField requires a non-empty mesh for operand A.`));if(t.vertices.length===0||t.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBooleanField requires a non-empty mesh for operand B.`));let s=sZ(r);if(A(s))return s;let c=zX(i);if(A(c))return c;try{return O(dZ(c.value.VoxelField.boolean_of(e.vertices,e.triangles,t.vertices,t.triangles,oZ[n],s.value.resolution,s.value.padding)))}catch(e){return k(I(`VOXEL_FIELD_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel field boolean failed (grid too large or non-dense?).`,e))}}function gZ(e,t,n){if(!fZ(e)||!fZ(t))return pZ();try{return e.value.boolean(t.value,oZ[n]),O(e)}catch(e){return k(I(`VOXEL_FIELD_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel field boolean failed (dim mismatch?).`,e))}}function _Z(e,t){if(!fZ(e))return pZ();if(!Number.isFinite(t))return k(F(`VOXEL_INVALID_DISTANCE`,`distance must be a finite number.`));try{return e.value.offset(t),O(e)}catch(e){return k(I(`VOXEL_FIELD_OFFSET_FAILED`,e instanceof Error?e.message:`voxel field offset failed.`,e))}}function vZ(e,t){if(!fZ(e))return pZ();if(!Number.isFinite(t)||t<=0)return k(F(`VOXEL_INVALID_THICKNESS`,`thickness must be a finite number > 0.`));try{return e.value.shell(t),O(e)}catch(e){return k(I(`VOXEL_FIELD_SHELL_FAILED`,e instanceof Error?e.message:`voxel field shell failed.`,e))}}function yZ(e){if(!fZ(e))return pZ();try{return e.value.reinit(),O(e)}catch(e){return k(I(`VOXEL_FIELD_REINIT_FAILED`,e instanceof Error?e.message:`voxel field reinit failed.`,e))}}function bZ(e){if(!fZ(e))return pZ();try{return cZ(e.value)}catch(e){return k(I(`VOXEL_FIELD_CONTOUR_FAILED`,e instanceof Error?e.message:`voxel field contour failed.`,e))}}function xZ(e,t,n){let r=KX(e);return A(r)?r:mZ(r.value,t,n)}function SZ(e,t,n,r,i){let a=KX(e);if(A(a))return a;let o=KX(t);return A(o)?o:hZ(a.value,o.value,n,r,i)}var CZ=48,wZ=2;function TZ(e){try{return O(PX(e))}catch(e){return k(_o(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function EZ(e){let t=e?.resolution??CZ,n=e?.padding??wZ;return!Number.isInteger(t)||t<1?k(F(`SDF_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(F(`SDF_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function DZ(e){return{raw:e,delete(){e.free()}}}var OZ={offsetField(e){return kZ(this.value.offset_field(e.value))},roundField(e){return kZ(this.value.round_field(e.value))},shellField(e){return kZ(this.value.shell_field(e.value))},smoothUnionField(e,t){return kZ(this.value.smooth_union_field(e.value,t.value))}};function kZ(e){let t=zT(DZ(e));return{get value(){return t.value.raw},get disposed(){return t.disposed},[Symbol.dispose](){t[Symbol.dispose]()},union(e){return kZ(this.value.union(e.value))},intersection(e){return kZ(this.value.intersection(e.value))},difference(e){return kZ(this.value.difference(e.value))},smoothUnion(e,t){return kZ(this.value.smooth_union(e.value,t))},smoothIntersection(e,t){return kZ(this.value.smooth_intersection(e.value,t))},smoothDifference(e,t){return kZ(this.value.smooth_difference(e.value,t))},offset(e){return kZ(this.value.offset(e))},round(e){return kZ(this.value.round(e))},shell(e){return kZ(this.value.shell(e))},onion(e){return kZ(this.value.onion(e))},...OZ,translate(e,t,n){return kZ(this.value.translate(e,t,n))},rotate(e,t,n,r){return kZ(this.value.rotate(e,t,n,r))},scale(e){return kZ(this.value.scale(e))},rasterize(e){return AZ(this.value,e)},rasterizeIn(e,t){return jZ(this.value,e,t)}}}function AZ(e,t){let n=EZ(t);if(A(n))return n;try{return O(uZ(e.rasterize(n.value.resolution,n.value.padding)))}catch(e){return MZ(e)}}function jZ(e,t,n){let r=EZ(n);if(A(r))return r;let i=NZ(t);if(i)return k(i);try{return O(uZ(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 MZ(e)}}function MZ(e){return k(I(`SDF_RASTERIZE_FAILED`,e instanceof Error?e.message:`SDF rasterization failed (grid too large?).`,e))}function NZ(e){if(![...e.min,...e.max].every(e=>Number.isFinite(e)))return F(`SDF_INVALID_BOUNDS`,`bounds must be finite numbers.`);for(let t=0;t<3;t++)if(e.max[t]<=e.min[t])return F(`SDF_INVALID_BOUNDS`,`bounds max must exceed min on every axis.`);return null}function PZ(e,t){let n=TZ(t);if(A(n))return n;try{return O(kZ(e(n.value)))}catch(e){return k(I(`SDF_BUILD_FAILED`,e instanceof Error?e.message:`SDF primitive construction failed.`,e))}}function FZ(e,t){return PZ(t=>t.Sdf.sphere(e),t)}function IZ(e,t,n,r){return PZ(r=>r.Sdf.box_(e,t,n),r)}function LZ(e,t,n,r,i){return PZ(i=>i.Sdf.rounded_box(e,t,n,r),i)}function RZ(e,t,n){return PZ(n=>n.Sdf.cylinder(e,t),n)}function zZ(e,t,n){return PZ(n=>n.Sdf.cone(e,t),n)}function BZ(e,t,n,r){return PZ(r=>r.Sdf.capsule(e[0],e[1],e[2],t[0],t[1],t[2],n),r)}function VZ(e,t,n){return PZ(n=>n.Sdf.torus(e,t),n)}function HZ(e,t,n){return PZ(n=>n.Sdf.plane(e[0],e[1],e[2],t),n)}function UZ(e){if(e.length<2)return k(F(`SDF_INVALID_SPINE`,`sweep spine needs at least 2 points.`));let t=new Float64Array(e.length*3);for(let n=0;n<e.length;n++){let r=e[n];if(!r.every(e=>Number.isFinite(e)))return k(F(`SDF_INVALID_SPINE`,`sweep spine coordinates must be finite.`));t[n*3]=r[0],t[n*3+1]=r[1],t[n*3+2]=r[2]}return O(t)}function WZ(e,t,n,r){let i=UZ(e);if(A(i))return i;let a=n?.closed??!1;return PZ(e=>e.Sdf.sweep(i.value,t.value,a),r)}var GZ={gyroid:0,schwarzP:1,diamond:2};function KZ(e,t,n,r){let i=GZ[e];return i===void 0?k(F(`SDF_INVALID_LATTICE_KIND`,`unknown lattice kind: ${e}`)):PZ(e=>e.Sdf.lattice(i,t.value,n.value),r)}function qZ(e,t,n){return PZ(n=>n.Sdf.strut_lattice(e,t.value),n)}function JZ(e){return{raw:e,delete(){e.free()}}}function YZ(e){let t=zT(JZ(e));return{get value(){return t.value.raw},get disposed(){return t.disposed},[Symbol.dispose](){t[Symbol.dispose]()}}}function XZ(e,t){let n=TZ(t);if(A(n))return n;try{return O(YZ(e(n.value)))}catch(e){return k(I(`SDF_FIELD_BUILD_FAILED`,e instanceof Error?e.message:`scalar field construction failed.`,e))}}function ZZ(e,t){return XZ(t=>t.ScalarField.constant(e),t)}function QZ(e,t,n,r,i,a){return XZ(a=>a.ScalarField.axial_ramp(e,t,n,r,i),a)}function $Z(e,t,n,r,i,a,o){return XZ(o=>o.ScalarField.radial_ramp(e[0],e[1],e[2],t,n,r,i,a),o)}function eQ(e,t,n,r){return XZ(r=>r.ScalarField.from_sdf(e.value,t,n),r)}function tQ(e,t,n,r){return XZ(r=>r.ScalarField.clamp(e.value,t,n),r)}var nQ={gyroid:0,schwarzP:1,diamond:2},rQ=48,iQ=2;function aQ(e){let t=nQ[e.type];if(t===void 0)return k(F(`LATTICE_INVALID_TYPE`,`lattice type must be one of gyroid, schwarzP, diamond (got '${e.type}').`));if(!(e.period>0))return k(F(`LATTICE_INVALID_PERIOD`,`period must be > 0.`));if(!(e.thickness>0))return k(F(`LATTICE_INVALID_THICKNESS`,`thickness must be > 0.`));let n=e.resolution??rQ,r=e.padding??iQ;return!Number.isInteger(n)||n<1?k(F(`LATTICE_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(r)||r<1?k(F(`LATTICE_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({tag:t,period:e.period,thickness:e.thickness,resolution:n,padding:r})}function oQ(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 sQ(e,t,n){let r=LX(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(F(`LATTICE_EMPTY_MESH`,`latticeInfill requires a non-empty triangle mesh.`));let i=aQ(t);if(A(i))return i;let a=zX(n);if(A(a))return a;let{tag:o,period:s,thickness:c,resolution:l,padding:u}=i.value;try{try{var d=OT();return O(oQ(d.u(a.value.lattice_infill(e.vertices,e.triangles,l,u,o,s,c))))}catch(e){d.e=e}finally{d.d()}}catch(e){return k(I(`LATTICE_INFILL_FAILED`,e instanceof Error?e.message:`lattice infill failed (grid too large?).`,e))}}function cQ(e,t,n){let r=KX(e);return A(r)?r:sQ(r.value,t,n)}function lQ(e,t,n){for(let t=0;t<3;t++){let n=e.min[t],r=e.max[t];if(n===void 0||r===void 0||!(n<r))return k(F(`LATTICE_INVALID_BOUNDS`,`bounds.min must be strictly less than bounds.max on every axis (axis ${t}).`))}let r=aQ(t);if(A(r))return r;let i=zX(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=OT();return O(oQ(g.u(i.value.tpms_box(u,d,f,p,m,h,c,l,a,o,s))))}catch(e){g.e=e}finally{g.d()}}catch(e){return k(I(`TPMS_LATTICE_FAILED`,e instanceof Error?e.message:`tpms lattice failed (grid too large?).`,e))}}function uQ(e){return U().createVector3d(e[0],e[1],e[2])}function dQ(e){return U().createPoint3d(e[0],e[1],e[2])}function fQ(e){return U().createDirection3d(e[0],e[1],e[2])}function pQ(e){return[e.X(),e.Y(),e.Z()]}function mQ(e){return[e.X(),e.Y(),e.Z()]}function hQ(e){return[e.X(),e.Y(),e.Z()]}function gQ(e,t){let n=uQ(e);try{return t(n)}finally{n.delete()}}function _Q(e,t){let n=dQ(e);try{return t(n)}finally{n.delete()}}function vQ(e,t){let n=fQ(e);try{return t(n)}finally{n.delete()}}var yQ=.299,bQ=.587,xQ=.114;function SQ(e,t={}){if(e.length<2)return k(F(N.SURFACE_GRID_TOO_SMALL,`surfaceFromGrid: need at least 2 rows, got ${e.length}`));let n=e.length,r=e[0]?.length??0;if(r<2)return k(F(N.SURFACE_GRID_TOO_SMALL,`surfaceFromGrid: need at least 2 columns, got ${r}`));for(let t=0;t<n;t++){let n=e[t];if(!n||n.length!==r)return k(F(N.SURFACE_GRID_JAGGED,`surfaceFromGrid: row ${t} has ${n?.length??0} columns, expected ${r}`))}let{width:i=r-1,depth:a=n-1,scaleZ:o=1}=t,s=i/(r-1),c=a/(n-1);try{return CQ(e,n,r,s,c,o)}catch{}try{return wQ(e,n,r,s,c,o)}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.SURFACE_FAILED,`surfaceFromGrid failed: ${t}`,e))}}function CQ(e,t,n,r,i,a){let o=[];for(let s=0;s<t;s++)for(let t=0;t<n;t++){let n=e[s],c=(n?n[t]??0:0)*a;o.push([t*r,s*i,c])}let s=W(U().bsplineSurface(o,t,n));return TE(s)?O(s):(FE(s),k(P(N.SURFACE_FAILED,`B-spline surface did not produce a face`)))}function wQ(e,t,n,r,i,a){let o=[];for(let s=0;s<t;s++)for(let t=0;t<n;t++){let n=e[s],c=(n?n[t]??0:0)*a;o.push([t*r,s*i,c])}let s=W(U().triangulatedSurface(o,t,n));return TE(s)||EE(s)?O(s):(FE(s),k(P(N.SURFACE_FAILED,`surfaceFromGrid: unexpected shape type from sewing`)))}async function TQ(e,t={}){let n=t.channel??`luminance`,r=Math.max(1,Math.round(t.downsample??1));if(typeof createImageBitmap!=`function`)return k(vo(N.SURFACE_FAILED,`surfaceFromImage requires createImageBitmap (not available in this environment)`));let i;try{i=await createImageBitmap(e)}catch(e){return k(vo(N.SURFACE_FAILED,`surfaceFromImage: failed to decode image — ${e instanceof Error?e.message:String(e)}`))}let a=i.width,o=i.height;if(a<2||o<2)return i.close(),k(F(N.SURFACE_GRID_TOO_SMALL,`surfaceFromImage: image too small (${a}x${o}), need at least 2x2`));if(typeof OffscreenCanvas!=`function`)return i.close(),k(vo(N.SURFACE_FAILED,`surfaceFromImage requires OffscreenCanvas (not available in this environment)`));let s=new OffscreenCanvas(a,o).getContext(`2d`);if(!s)return i.close(),k(vo(N.SURFACE_FAILED,`surfaceFromImage: could not get 2D canvas context`));s.drawImage(i,0,0),i.close();let c=s.getImageData(0,0,a,o).data,l=[];for(let e=0;e<o;e+=r){let t=[];for(let i=0;i<a;i+=r){let r=(e*a+i)*4,o=c[r]??0,s=c[r+1]??0,l=c[r+2]??0,u;switch(n){case`r`:u=o/255;break;case`g`:u=s/255;break;case`b`:u=l/255;break;default:u=(yQ*o+bQ*s+xQ*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),SQ(l,u)}function EQ(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function DQ(e,t={}){if(e.length===0)return k(F(N.HULL_EMPTY_INPUT,`hull: at least one shape is required`,void 0,void 0,`Provide one or more shapes to compute a convex hull`));for(let[t,n]of e.entries()){let e=EQ(n,`hull: shapes[${t}]`);if(A(e))return e}let n=t.tolerance??.1;try{let t=U(),r=e.map(e=>e.wrapped),i=W(t.hull(r,n));return DE(i)?O(i):(FE(i),k(P(N.HULL_NOT_3D,`Hull result is not a solid; input may be degenerate`)))}catch(e){let t=e instanceof Error?e.message:String(e);return t.includes(`coplanar`)||t.includes(`fewer than`)||t.includes(`degenerate`)?k(P(N.HULL_DEGENERATE,`Hull degenerate: ${t}`,e)):k(P(N.HULL_FAILED,`Hull operation failed: ${t}`,e))}}function OQ(e){if(e.length<4)return k(F(N.HULL_EMPTY_INPUT,`convexHull: at least 4 points required, got ${e.length}`,void 0,void 0,`Provide 4 or more non-coplanar 3D points`));try{let t=U(),n=e.map(e=>({x:e[0],y:e[1],z:e[2]})),r=W(t.hullFromPoints(n,.1));return DE(r)?O(r):(FE(r),k(P(N.HULL_NOT_3D,`convexHull result is not a solid; points may be coplanar`)))}catch(e){let t=e instanceof Error?e.message:String(e);return t.includes(`coplanar`)||t.includes(`fewer than`)||t.includes(`degenerate`)?k(P(N.HULL_DEGENERATE,`convexHull degenerate: ${t}`,e)):k(P(N.HULL_FAILED,`convexHull failed: ${t}`,e))}}function kQ(e){let n=ZE(e);if(n.length!==1)return null;let r=t(n,0);if(fD(r)!==`sphere`)return null;let i=U().area(r.wrapped);return Math.sqrt(i/(4*Math.PI))}function AQ(e,t,n){try{let r=W(U().offset(e.wrapped,t,n));return kE(r)?O(r):(FE(r),k(ho(N.MINKOWSKI_NOT_3D,`Minkowski sphere offset did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.MINKOWSKI_FAILED,`Minkowski sphere offset failed: ${t}`,e,{operation:`minkowski`,fastPath:`sphere`}))}}function jQ(e,t,n){let r=U();try{let i=$E(e),a=$E(t);if(i.length===0||a.length===0)return k(P(N.MINKOWSKI_FAILED,`Minkowski sum: one or both shapes have no vertices`,void 0,{operation:`minkowski`}));let o=[];for(let e of i){let[t,n,i]=r.vertexPosition(e.wrapped);for(let e of a){let[a,s,c]=r.vertexPosition(e.wrapped);o.push({x:t+a,y:n+s,z:i+c})}}let s=W(r.hullFromPoints(o,n));return kE(s)?O(s):(FE(s),k(ho(N.MINKOWSKI_NOT_3D,`Minkowski hull did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.MINKOWSKI_FAILED,`Minkowski general path failed: ${t}`,e,{operation:`minkowski`}))}}function MQ(e,t,n={}){let{tolerance:r=1e-6}=n;if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`minkowski: shape is a null shape`));if(U().isNull(t.wrapped))return k(F(N.MINKOWSKI_NULL_TOOL,`minkowski: tool is a null shape`));if(!kE(e)||!kE(t))return k(F(N.MINKOWSKI_NOT_3D,`minkowski: both shape and tool must be 3D`));let i=kQ(t);return i===null?jQ(e,t,r):AQ(e,i,r)}function NQ(e,t,n={}){let{tolerance:r=1e-6}=n;if(e.length<4)return k(F(N.POLYHEDRON_INSUFFICIENT_POINTS,`polyhedron: need at least 4 points, got ${e.length}`));if(t.length<4)return k(F(N.POLYHEDRON_INSUFFICIENT_FACES,`polyhedron: need at least 4 faces, got ${t.length}`));let i=[];for(let[n,r]of t.entries()){for(let t of r)if(t<0||t>=e.length)return k(F(N.POLYHEDRON_INVALID_INDEX,`polyhedron: face ${n} has out-of-range index ${t} (${e.length} points)`));if(r.length<3)continue;let t=r[0];for(let e=1;e<r.length-1;e++)i.push([t,r[e],r[e+1]])}try{let t=U(),n=e.map(([e,t,n])=>({x:e,y:t,z:n})),a=W(t.buildSolidFromFaces(n,i,r));return DE(a)?O(a):(FE(a),k(P(N.POLYHEDRON_FAILED,`Polyhedron did not produce a solid`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.POLYHEDRON_FAILED,`Polyhedron failed: ${t}`,e))}}var PQ=1e-10;function FQ(e,t,n,r){return e*r-t*n}function IQ(e,t,n,r){return e*n+t*r}function LQ(e,t){return Math.sqrt(e*e+t*t)}function RQ(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 zQ(e){let t=0;for(let n=0;n<e.length;n++){let r=RQ(e,n),i=RQ(e,n+1);t+=r.x*i.y-i.x*r.y}return t<0?[...e].reverse():e}function BQ(e,t){let n=RQ(e,t-1),r=RQ(e,t),i=RQ(e,t+1),a=r.x-n.x,o=r.y-n.y,s=LQ(a,o),c=i.x-r.x,l=i.y-r.y,u=LQ(c,l);if(s<PQ||u<PQ)return{dx:0,dy:0};let d=-o/s,f=a/s,p=-l/u,m=c/u,h=d+p,g=f+m,_=LQ(h,g);if(_<PQ)return{dx:d,dy:f};h/=_,g/=_;let v=IQ(h,g,d,f),y=Math.abs(v)>PQ?1/v:1;return{dx:h*y,dy:g*y}}function VQ(e){return!e.prev||!e.next?!1:FQ(e.x-e.prev.x,e.y-e.prev.y,e.next.x-e.x,e.next.y-e.y)<-1e-10}function HQ(e){let t=e.map((t,n)=>{let r=BQ(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 UQ(e,t){let n=e;for(let e=0;e<t&&n;e++)n.active=!1,n=n.next}function WQ(e){let t=1,n=e.next;for(;n!==e&&(t++,n=n.next,!(t>1e4)););return t}function GQ(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)<PQ&&Math.abs(r)<PQ)return null;let o;if(o=Math.abs(n)>Math.abs(r)?i/n:a/r,o<PQ)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)>PQ){let e=c/s;if(Math.abs(o-e)>1e-4*Math.max(1,Math.abs(o)))return null}return o}function KQ(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=LQ(r,i);if(a<PQ)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)<PQ)return null;let f=-c/d;if(f<PQ)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=LQ(y,b);if(x<PQ)return f;let S=IQ(p-h,m-g,y,b)/(x*x);return S<-.01||S>1.01?null:f}function qQ(e){let t=[];for(let n of e){if(!n.active||!n.next)continue;let e=GQ(n,n.next);if(e!==null&&e>PQ){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(VQ(n)){let e=n.next.next,r=0;for(;e!==n.prev&&e!==n&&r<1e3;){let i=KQ(n,e,e.next);if(i!==null&&i>PQ){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 JQ(e){if(e.length<3)return O({nodes:[],faces:[]});try{return O(YQ(e))}catch(e){return k(I(N.STRAIGHT_SKELETON_FAILED,e instanceof Error?e.message:String(e),e))}}function YQ(e){let t=zQ(e),n=t.length,r=[],i=Array.from({length:n},()=>[]),a=HQ(t),o=0,s=n*n*2;for(;o<s;){o++;let e=a.find(e=>e.active);if(!e)break;let t=WQ(e);if(t<=3){if(t===3){let t=e,n=t.next,a=n.next,o=GQ(t,n),s=o!==null&&o>PQ?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 UQ(e,t);continue}let n=a.filter(e=>e.active),s=qQ(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=BQ(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=BQ(f(e),0);e.bx=p.dx,e.by=p.dy;let m=BQ(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=[RQ(t,e),RQ(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&&LQ(n.x-i.x,n.y-i.y)>PQ&&(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 XQ(e){let t=XE(e).map(e=>{let t=bk(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 ZQ(e){let t=[];for(let n=1;n<e-1;n++)t.push([0,n,n+1]);return t}function QQ(e,t,n,r,i,a){return(n-e)*(a-t)-(r-t)*(i-e)}function $Q(e,t,n,r,i,a,o,s){let c=QQ(n,r,i,a,e,t),l=QQ(i,a,o,s,e,t),u=QQ(o,s,n,r,e,t);return!((c<0||l<0||u<0)&&(c>0||l>0||u>0))}function e$(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||QQ(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&&$Q(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 t$(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=ZQ(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 n$(e,t){let n=(t?.angle??45)*gD,r=Math.tan(n);try{let t=XQ(e);if(t.length<3)return k(P(N.ROOF_FAILED,`Wire must have at least 3 edges for roof generation`));let n=JQ(t);if(!n.ok)return n;let i=n.value;if(i.faces.length===0)return k(P(N.ROOF_FAILED,`Straight skeleton computation produced no faces`));let a=U(),o=t$(i,r,a);for(let[e,n,r]of e$(t)){let i=t[e],s=t[n],c=t[r];if(!i||!s||!c)continue;let l=[i.x,i.y,0],u=[s.x,s.y,0],d=[c.x,c.y,0],f=a.buildTriFace(l,d,u);f!==null&&o.push(f)}if(o.length===0)return k(P(N.ROOF_FAILED,`No valid triangular faces could be built`));try{let e=a.sewAndSolidify(o,1e-6),t=a.fixShape(e);return t!==e&&a.dispose(e),O(yE(t))}catch(e){try{let t=yE(a.sew(o,1e-6));return iE(t)?O(t):k(P(N.ROOF_FAILED,`Sew fallback produced invalid solid`,e))}catch(e){return k(P(N.ROOF_FAILED,`Failed to sew roof faces`,e))}}finally{for(let e of o)a.dispose(e)}}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.ROOF_FAILED,`Roof generation failed: ${t}`,e))}}function r$(e){return[[1,0,0,e[0]],[0,1,0,e[1]],[0,0,1,e[2]],[0,0,0,1]]}function i$(e){let t=e[0];return t!==void 0&&typeof t[0]==`number`}function a$(e,t,n){return{__instanced:!0,source:e,placements:t,grid:n,[Symbol.dispose](){e[Symbol.dispose]()}}}function o$(e){return typeof e==`object`&&!!e&&e.__instanced===!0}function s$(e,t){return a$(e,i$(t)?t.map(r$):t.map(e=>e.map(e=>[...e])))}function c$(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(r$([e*i,t*a,0]));return a$(e,o,{cols:n,rows:r,pitchX:i,pitchY:a})}function l$(e){return e.placements.length}function u$(e,t={}){let{source:n,placements:r,grid:i}=e;return r.length===0?k(F(`INSTANCE_EMPTY`,`materialize: instance has no placements`)):t.fuse?kE(n)?i?jP(n,[1,0,0],[0,1,0],i.cols,i.rows,i.pitchX,i.pitchY):d$(n,r,!0):k(F(`MATERIALIZE_NOT_3D`,`materialize({fuse:true}) requires a 3D source shape`)):d$(n,r,!1)}function d$(e,t,n){let r=[];for(let n of t){let t=ck(e,n);if(!t.ok){for(let e of r)e[Symbol.dispose]();return t}r.push(t.value)}let i=n?NA(r,{unsafe:!0}):O(nj(r));for(let e of r)(!i.ok||e!==i.value)&&e[Symbol.dispose]();return i}function f$(e,t){return{geometry:Wk(e.source,t),instances:e.placements}}var p$={coincident:3,concentric:4,distance:1,angle:1},m$=[1,0,0,0];function h$(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function g$(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function _$(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function v$(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 y$(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function b$(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function x$(e){return b$(v$(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function S$(e,t){let n=h$(WP(t.rotation,e.origin),t.position);return{type:e.type,origin:n,...e.normal?{normal:WP(t.rotation,e.normal)}:{},...e.direction?{direction:WP(t.rotation,e.direction)}:{}}}function C$(e,t,n){let r=e.normal??[0,0,1];return{position:y$(r,_$(r,g$(e.origin,t.origin))+n),rotation:m$}}function w$(e,t){let n=e.direction??[0,0,1],r=KP(t.direction??[0,0,1],n),i=WP(r,t.origin);return{position:g$(e.origin,i),rotation:r}}function T$(e,t,n){let r=b$(e.normal??[0,0,1]),i=b$(t.normal??[0,0,1]),a=Math.acos(Math.max(-1,Math.min(1,_$(i,r)))),o=v$(i,r);return{position:[0,0,0],rotation:GP(Math.hypot(o[0],o[1],o[2])<1e-9?x$(i):o,a-n)}}function E$(e,t,n){let r=g$(t,e),i=Math.hypot(r[0],r[1],r[2]);return{position:g$(h$(e,y$(i<1e-9?[1,0,0]:y$(r,1/i),n)),t),rotation:m$}}function D$(e,t,n,r){let i=b$(e);return{position:y$(i,_$(i,g$(t,n))-r),rotation:m$}}function O$(e,t,n){let r=b$(e.direction??[0,0,1]),i=h$(e.origin,y$(r,_$(r,g$(t,e.origin))));if(n===0)return{position:g$(i,t),rotation:m$};let a=g$(t,i),o=Math.hypot(a[0],a[1],a[2]);return{position:g$(h$(i,y$(o<1e-9?x$(r):y$(a,1/o),n)),t),rotation:m$}}function k$(e,t,n){let r=b$(t.direction??[0,0,1]),i=g$(t.origin,e),a=g$(i,y$(r,_$(r,i))),o=Math.hypot(a[0],a[1],a[2]);return n===0?{position:y$(a,-1),rotation:m$}:{position:g$(y$(o<1e-9?x$(r):y$(a,1/o),n),a),rotation:m$}}function A$(e,t,n){let r=b$(e.direction??[0,0,1]),i=KP(b$(t.direction??[0,0,1]),r),a=g$(WP(i,t.origin),e.origin),o=g$(a,y$(r,_$(r,a))),s=Math.hypot(o[0],o[1],o[2]);return{position:g$(y$(s<1e-9?x$(r):y$(o,1/s),n),o),rotation:i}}var j$=new Set([`plane-plane`,`plane-point`,`point-plane`,`point-point`,`axis-axis`,`axis-point`,`point-axis`]),M$={angle:`plane`,concentric:`axis`},N$=new Set([`coincident`,`distance`,`angle`,`concentric`]);function P$(e,t,n){let r=M$[e];return r?t===r&&n===r:j$.has(`${t}-${n}`)}function F$(e,t,n){switch(`${e.type}-${t.type}`){case`plane-plane`:case`plane-point`:return C$(e,t,n);case`point-plane`:return D$(t.normal??[0,0,1],e.origin,t.origin,n);case`point-point`:return E$(e.origin,t.origin,n);case`axis-axis`:return n===0?w$(e,t):A$(e,t,n);case`axis-point`:return O$(e,t.origin,n);case`point-axis`:return k$(e.origin,t,n);default:return null}}function I$(e,t,n){switch(e.type){case`concentric`:return w$(t,n);case`angle`:return T$(t,n,(e.value??0)*Math.PI/180);default:{let r=F$(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 L$(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=>N$.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(!P$(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=S$(r.entity,a);n.set(i.node,I$(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+(p$[t]??p$[t.split(`(`)[0]??``]??0),0),converged:r.length===0,unsupported:r}}function R$(e){if(e.face){let t=mO(e.face);return t?{type:`axis`,origin:t.origin,direction:t.direction}:{type:`plane`,origin:pO(e.face),normal:fO(e.face)}}if(e.edge){if(yk(e.edge)===`LINE`)return{type:`axis`,origin:bk(e.edge),direction:Ck(e.edge)};let t=Tk(e.edge);return t?{type:`axis`,origin:t.origin,direction:t.direction}:null}return e.point?{type:`point`,origin:e.point}:null}function z$(e,t){let n=R$(e),r=R$(t);return!n||!r?k(F(N.ASSEMBLY_MATE_INVALID,`solveAssembly: could not extract geometry from mate entities`)):O({entityA:{node:e.node,entity:n},entityB:{node:t.node,entity:r}})}function B$(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=z$(e.entityA,e.entityB);return t.ok?O({type:`coincident`,...t.value}):t}case`distance`:{let t=z$(e.entityA,e.entityB);return t.ok?O({type:`distance`,...t.value,value:e.distance}):t}case`angle`:{let t=z$(e.entityA,e.entityB);return t.ok?O({type:`angle`,...t.value,value:e.angle}):t}case`concentric`:{let t=z$(e.axisA,e.axisB);return t.ok?O({type:`concentric`,...t.value}):t}}}function V$(e,t){let n=e.mates??[];return{...e,mates:[...n,t]}}function H$(e){let t=e.mates;if(!t||t.length===0)return k(F(N.ASSEMBLY_MATE_INVALID,`solveAssembly: no mates defined`));try{let n=[];LP(e,e=>{n.push(e.name)});let r=[];for(let e of t){let t=B$(e);if(!t.ok)return t;r.push(t.value)}let i=L$(n,r);if(!i.converged){let e=i.unsupported.length>0?`Unsupported constraint types: ${i.unsupported.join(`, `)} (${i.dof} DOF unresolved)`:`Assembly constraint solver did not converge`;return k(P(N.ASSEMBLY_NOT_CONVERGED,e))}return O({transforms:i.transforms,dof:i.dof,converged:i.converged})}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.ASSEMBLY_SOLVE_FAILED,`Assembly solve failed: ${t}`,e))}}function U$(e,t,n=1e-6){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`checkInterference: first shape is a null shape`));if(U().isNull(t.wrapped))return k(F(N.NULL_SHAPE_INPUT,`checkInterference: second shape is a null shape`));let r=U().distance(e.wrapped,t.wrapped);return O({hasInterference:r.value<=n,minDistance:r.value,pointOnShape1:r.point1,pointOnShape2:r.point2})}function W$(e,n=1e-6){let r=[],i=e.map(e=>uD(e));return e.forEach((a,o)=>{for(let s=o+1;s<e.length;s++){if(G$(t(i,o),t(i,s),n))continue;let c=j(U$(a,t(e,s),n));c.hasInterference&&r.push({i:o,j:s,result:c})}}),r}function G$(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 K$(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 q$(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 J$(e){let{type:t,data:n}=e,r=U();if(t===`LINE`)return r.makeLineEdge([q$(n,10),q$(n,20),q$(n,30)],[q$(n,11),q$(n,21),q$(n,31)]);if(t===`CIRCLE`)return r.makeCircleEdge([q$(n,10),q$(n,20),q$(n,30)],[0,0,1],q$(n,40));if(t===`ARC`){let e=q$(n,50)*Math.PI/180,t=q$(n,51)*Math.PI/180;return r.makeCircleArc([q$(n,10),q$(n,20),q$(n,30)],[0,0,1],q$(n,40),e,t)}}async function Y$(e,t){let n;try{n=await e.text()}catch(e){return k(vo(N.DXF_IMPORT_FAILED,`Failed to read DXF blob`,e))}let r=K$(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=J$(e);t!==void 0&&a.push(t)}return a.length===0?O([]):O([gE(U().makeWire(a))])}catch(e){return k(vo(N.DXF_IMPORT_FAILED,`Failed to convert DXF entities to geometry`,e))}finally{for(let e of a)e.delete()}}function X$(e,t,n=1e-6){let r=U(),i=[];for(let[t,n,a]of e){let e=r.buildTriFace(t,n,a);e!==null&&i.push(e)}if(i.length===0)return k(vo(t,`No valid triangular faces could be built`));try{return O(jE(r.sewAndSolidify(i,n)))}catch{try{return O(jE(r.sew(i,n)))}catch(e){return k(vo(t,`Failed to sew triangular faces`,e))}}}function Z$(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 Q$(e){return e.split(/\s+/).slice(1).map(e=>parseInt(e.split(`/`)[0]??``,10)).filter(e=>!isNaN(e))}async function $$(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=Z$(t);e&&n.push(e)}else if(t.startsWith(`f `)){let e=Q$(t);e.length>=3&&r.push(e)}}if(n.length===0||r.length===0)return k(vo(N.OBJ_IMPORT_FAILED,`OBJ file contains no valid geometry`));try{return e1(n,r)}catch(e){let t=e instanceof Error?e.message:String(e);return k(vo(N.OBJ_IMPORT_FAILED,`OBJ import failed: ${t}`,e))}}function e1(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 X$(n,N.OBJ_IMPORT_FAILED)}function t1(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 n1(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95}function r1(e){let t={},n=0;for(;n<e.length;){let r=e.indexOf(`="`,n);if(r<0)break;let i=r;for(;i>0&&n1(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 i1(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 a1(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 o1(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 s1(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=r1(e.slice(r,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of i1(a,`color`)){let t=r1(e).color;t!==void 0&&l.push(o1(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=r1(e.slice(n,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of i1(a,`base`)){let t=r1(e).displaycolor;t===void 0?l.push([0,0,0,1]):l.push(o1(t))}t.set(c,l)}return t}function c1(e){let t=[],n=[],r=[],i=s1(e);for(let n of i1(e,`vertex`)){let e=r1(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=a1(e,`object`);if(s!==null){let e=s.indexOf(`>`);if(e>=0){let t=r1(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 i1(e,`triangle`)){let e=r1(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 l1(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 u1(e){let t=U(),n=e.vertices.map(([e,t,n])=>({x:e,y:t,z:n})),r=e.triangles;try{return O(jE(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 X$(t,N.THREEMF_IMPORT_FAILED)}}async function d1(e){try{let t=await e.arrayBuffer(),n=t1(new Uint8Array(t),`3D/3dmodel.model`);if(!n)return k(vo(N.THREEMF_IMPORT_FAILED,`3MF archive does not contain 3D/3dmodel.model (or uses unsupported compression)`));let r=c1(new TextDecoder().decode(n));if(r.vertices.length===0||r.triangles.length===0)return k(vo(N.THREEMF_IMPORT_FAILED,`3MF model contains no valid geometry`));let i=u1(r);if(i.ok){let e=l1(r.triangleColors);e!==null&&WO(i.value,e)}return i}catch(e){let t=e instanceof Error?e.message:String(e);return k(vo(N.THREEMF_IMPORT_FAILED,`3MF import failed: ${t}`,e))}}async function f1(e){try{let t=await e.arrayBuffer();return O(jE(U().importGLB(t)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(vo(N.GLB_IMPORT_FAILED,`Failed to import GLB: ${t}`,e))}}function $(e){return`__wrapped`in e?e.val:e}function p1(e){return $(e)}function m1(e,t){return ek($(e),t)}function h1(e,t,n){let r=n?.at;return tk($(e),t,r,n?.axis)}function g1(e,t){let n=t?.at;return nk($(e),t?.normal??[1,0,0],n)}function _1(e,t,n){return rk($(e),t,n?.center)}function v1(e){return fk($(e))}function y1(e,t){return ck($(e),t)}function b1(e,t){return dk($(e),t)}function x1(e,t){return uk($(e),t)}function S1(e,t,n){return kA($(e),$(t),{...n,unsafe:!0})}function C1(e,t,n){return AA($(e),$(t),{...n,unsafe:!0})}function w1(e,t){return NA(e.map(e=>$(e)),{...t,unsafe:!0})}function T1(e,t,n){return PA($(e),t.map(e=>$(e)),{...n,unsafe:!0})}function E1(e,t,n){return jA($(e),$(t),{...n,unsafe:!0})}function D1(e,t,n){return IA($(e),t,n)}function O1(e,t,n){return HA($(e),t,n)}function k1(e,t){return UA($(e),t)}function A1(e,t,n){return WA($(e),t,n)}function j1(e,t){if(e!==void 0)return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(jI()).findAll(t)}function M1(e,t){return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(PI()).findAll(t)}function N1(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 P1(e,t,n){let r=$(e),i,a;return n===void 0?(i=void 0,a=t):(i=j1(t,r),a=n),Hj(r,i,a)}function F1(e,t,n){let r=$(e),i,a;n===void 0?(i=void 0,a=t):(i=j1(t,r),a=n);let o=N1(a);return o.mode===`distAngle`?lj(r,[...i??XE(r)],o.distance,o.angle):Uj(r,i,o.distance)}function I1(e,t,n,r){let i=$(e);return Wj(i,M1(t,i),n,r?.tolerance)}function L1(e,t,n){return Gj($(e),t,n?.tolerance)}function R1(e,t){return Bj($(e),t)}function z1(e,t,n){let r=$(e);return qj(r,M1(t,r),n.pullDirection,n.neutralPlane,n.angle)}function B1(e){return $j($(e))}function V1(e){return vk($(e))}function H1(e,t){return Wk($(e),t)}function U1(e,t){return Gk($(e),t)}function W1(e){return mD($(e))}function G1(e){return pk($(e))}function K1(e){return nO(e)}function q1(e){return Yj($(e))}function J1(e){return hk($(e))}function Y1(e,t){return gM($(e),typeof t==`number`?[0,0,t]:t)}function X1(e,t){let n=t?.at??[0,0,0];return _M($(e),n,t?.axis??[0,0,1],t?.angle??2*Math.PI)}function Z1(e,t){return yM(e.map(e=>$(e)),t)}function Q1(e,n){if(n===void 0){let t=ZE(e);if(t.length===0)return k(F(N.COMPOUND_NO_FACES,`compoundOps: shape has no faces`));let n=oA(t),r=pO(n)[2];for(let e=1;e<t.length;e++){let i=aA(t,e),a=pO(i)[2];a>r&&(n=i,r=a)}return O(n)}if(typeof n==`function`){let r=n(PI()).findAll(e);return r.length===0?k(yo(N.COMPOUND_FACE_NOT_FOUND,`compoundOps: face finder matched no faces`)):O(t(r,0))}return O(n)}function $1(e){return`sketchOnPlane`in e&&typeof e.sketchOnPlane==`function`?{wire:e.sketchOnPlane(`XY`).wire,owned:!0}:{wire:e,owned:!1}}function e0(e,t){let n=$(e),{at:r,radius:i,axis:a}=t,o=a??[0,0,1];if(i<=0)return k(F(`DRILL_INVALID_RADIUS`,`Drill radius must be positive`));if(ND(o))return k(F(`DRILL_ZERO_AXIS`,`Drill axis cannot be zero`));let s=jD(o),c=r.length===2?[r[0],r[1],0]:[r[0],r[1],r[2]],l;if(t.depth!==void 0)l=YA(i,t.depth,c,s);else{let e=uD(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=YA(i,a-r,[c[0]+s[0]*r,c[1]+s[1]*r,c[2]+s[2]*r],s)}try{return AA(n,l,{unsafe:!0})}finally{l[Symbol.dispose]()}}function t0(e,t){try{var n=OT();let r=$(e),{profile:i,depth:a}=t;if(a<=0)return k(F(`POCKET_INVALID_DEPTH`,`Pocket depth must be positive`));let o=Q1(r,t.face);if(A(o))return o;let s=o.value,c=fO(s),l=pO(s),u=n.u(new BT),{wire:d,owned:f}=$1(i);f&&u.register(d);let p=xA(d);if(A(p))return p;u.register(p.value);let m=gM(u.register(ek(p.value,l)),wD(jD(c),-a));return A(m)?m:(u.register(m.value),AA(r,m.value,{unsafe:!0}))}catch(e){n.e=e}finally{n.d()}}function n0(e,t){try{var n=OT();let r=$(e),{profile:i,height:a}=t;if(a<=0)return k(F(`BOSS_INVALID_HEIGHT`,`Boss height must be positive`));let o=Q1(r,t.face);if(A(o))return o;let s=o.value,c=fO(s),l=pO(s),u=n.u(new BT),{wire:d,owned:f}=$1(i);f&&u.register(d);let p=xA(d);if(A(p))return p;u.register(p.value);let m=gM(u.register(ek(p.value,l)),wD(jD(c),a));return A(m)?m:(u.register(m.value),kA(r,m.value,{unsafe:!0}))}catch(e){n.e=e}finally{n.d()}}function r0(e,t){try{var n=OT();let r=$(e),i=t?.normal??[1,0,0],a=t?.at;return ND(i)?k(F(`MIRROR_ZERO_NORMAL`,`Mirror plane normal cannot be zero`)):kA(r,n.u(nk(r,i,a)),{unsafe:!0})}catch(e){n.e=e}finally{n.d()}}function i0(e,t){let n=$(e),{xDir:r,xCount:i,xSpacing:a,yDir:o,yCount:s,ySpacing:c}=t;if(i<1||s<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern counts must be at least 1`));if(ND(r))return k(F(`PATTERN_ZERO_DIRECTION`,`X direction cannot be zero`));if(ND(o))return k(F(`PATTERN_ZERO_DIRECTION`,`Y direction cannot be zero`));if(i===1&&s===1)return O(n);let l=jD(r),u=jD(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=ek(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 NA(d,{unsafe:!0})}finally{for(let e of f)e[Symbol.dispose]()}}var a0=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 o0(e){if(A(e))throw new a0(e.error);return e.value}function s0(e){return e}function c0(e){return e}function l0(e){return e}function u0(e){return e}function d0(e){return{val:e,__wrapped:!0,translate:t=>x0(m1(e,t)),rotate:(t,n)=>x0(h1(e,t,n)),mirror:t=>x0(g1(e,t)),scale:(t,n)=>x0(_1(e,t,n)),applyMatrix:t=>x0(o0(y1(e,t))),moveX:t=>x0(m1(e,[t,0,0])),moveY:t=>x0(m1(e,[0,t,0])),moveZ:t=>x0(m1(e,[0,0,t])),rotateX:t=>x0(h1(e,t,{axis:[1,0,0]})),rotateY:t=>x0(h1(e,t,{axis:[0,1,0]})),rotateZ:t=>x0(h1(e,t,{axis:[0,0,1]})),bounds:()=>uD(e),describe:()=>W1(e),clone:()=>x0(o0(v1(e))),mesh:t=>H1(e,t),meshEdges:t=>U1(e,t),isValid:()=>q1(e),isEmpty:()=>J1(e),heal:()=>x0(o0(B1(e))),simplify:()=>x0(o0(V1(e))),toBREP:()=>o0(G1(e)),apply:t=>x0(t(e)),applyResult:t=>x0(o0(t(e))),done:()=>e}}function f0(e){return{fuse:(t,n)=>S0(o0(S1(e,$(t),{...n,unsafe:!0}))),cut:(t,n)=>S0(o0(C1(e,$(t),{...n,unsafe:!0}))),intersect:(t,n)=>S0(o0(E1(e,$(t),{...n,unsafe:!0}))),fuseAll:(t,n)=>S0(u0(o0(NA([e,...t.map($)],{...n,unsafe:!0})))),cutAll:(t,n)=>S0(u0(o0(PA(e,t,{...n,unsafe:!0})))),section:(t,n)=>x0(o0(D1(e,t,n))),split:t=>x0(o0(k1(e,t))),slice:(t,n)=>o0(A1(e,t,n))}}function p0(e){return{fillet(...t){return t.length===1?S0(u0(o0(P1(s0(e),t[0])))):S0(u0(o0(P1(s0(e),t[0],t[1]))))},chamfer(...t){return t.length===1?S0(u0(o0(F1(s0(e),t[0])))):S0(u0(o0(F1(s0(e),t[0],t[1]))))},shell:(t,n,r)=>S0(u0(o0(I1(s0(e),t,n,r)))),offset:(t,n)=>S0(u0(o0(L1(s0(e),t,n)))),draft:(t,n)=>S0(u0(o0(z1(s0(e),t,n))))}}function m0(e){return{drill:t=>S0(o0(e0(e,t))),pocket:t=>S0(o0(t0(e,t))),boss:t=>S0(o0(n0(e,t))),mirrorJoin:t=>S0(o0(r0(e,t))),rectangularPattern:t=>S0(o0(i0(e,t)))}}function h0(e){return{volume:()=>o0(kM(e)),area:()=>o0(AM(e)),volumeProps:()=>o0(EM(e)),surfaceProps:()=>o0(DM(e))}}function g0(e){return{edges:()=>XE(e),faces:()=>ZE(e),wires:()=>QE(e),vertices:()=>$E(e)}}function _0(e){return{linearPattern:(t,n,r)=>S0(u0(o0(kP(e,t,n,r)))),circularPattern:(t,n,r)=>S0(u0(o0(AP(e,t,n,r))))}}function v0(e){return{...d0(e),...f0(e),...p0(e),...m0(e),...h0(e),...g0(e),..._0(e)}}function y0(e){return{...d0(e),length:()=>wk(e),startPoint:()=>bk(e),endPoint:()=>xk(e),pointAt:t=>Sk(e,t),tangentAt:t=>Ck(e,t),isClosed:()=>Ek(e),sweep(t,n){if(!wE(e))throw Error(`sweep requires a Wire`);let r=o0(cM(l0(e),$(t),n));return S0(Array.isArray(r)?r[0]:r)}}}function b0(e){return{...d0(e),area:()=>o0(AM(e)),normalAt:t=>fO(e,t),center:()=>pO(e),surfaceType:()=>o0(iO(e)),outerWire:()=>gO(e),innerWires:()=>vO(e),extrude:t=>S0(o0(Y1(c0(e),t))),revolve:t=>S0(o0(X1(c0(e),t)))}}function x0(e){return kE(e)?v0(e):TE(e)?b0(e):CE(e)||wE(e)?y0(e):d0(e)}function S0(e){return v0(e)}function C0(e){if(e&&typeof e==`object`&&`face`in e&&typeof e.face==`function`&&`_defaultOrigin`in e)return b0(e.face());if(e&&typeof e==`object`&&`wrapped`in e)return TE(e)?b0(e):kE(e)?v0(e):CE(e)||wE(e)?y0(e):d0(e);throw Error(`shape() requires a Sketch or branded shape type`)}var w0=.25,T0=e=>Math.tan(e)-e;function E0(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 D0(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(E0(e,s*t,n,i))}return a}function O0(e){return Math.max(16,Math.round(8*Math.sqrt(e)))}function k0(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 A0(e,t,n){if(t===0)return O(e);let r=T0(e)+2*t*Math.tan(e)/n,i,a;if(r>T0(e)?(i=e,a=Math.PI/2-1e-6):(i=1e-4,a=e),r>T0(a)||r<T0(i))return k(F(`GEAR_PA_OUT_OF_RANGE`,`working pressure angle out of range — target inv(αw)=${r.toFixed(4)} not in [${T0(i).toFixed(4)}, ${T0(a).toFixed(4)}]`,void 0,{target:r,invLo:T0(i),invHi:T0(a)}));for(let e=0;e<50;e++){let e=.5*(i+a);T0(e)<r?i=e:a=e}return O(.5*(i+a))}function j0(e,t,n,r,i){return A0(e,t+n,r+i)}function M0(e,t,n,r,i){return A0(e,n-t,i-r)}function N0(e,t,n,r,i){return(e+t)*n*Math.cos(r)/(2*Math.cos(i))}function P0(e,t,n,r){if(!Number.isInteger(e)||!Number.isInteger(t)||!Number.isInteger(n))return k(F(`GEAR_NON_INTEGER_TEETH`,`tooth counts and planet count must be integers`));if(e<4||t<4||n<2)return k(F(`GEAR_TEETH_TOO_FEW`,`zs ≥ 4, zp ≥ 4, N ≥ 2 required`));if((2*e+2*t)%n!=0)return k(F(`GEAR_ASSEMBLY`,`(2·zs + 2·zp) must be divisible by N — got ${2*e+2*t} mod ${n} = ${(2*e+2*t)%n}`));let i=t+2+2*r,a=(e+t)*Math.sin(Math.PI/n);return a<=i?k(F(`GEAR_PLANET_COLLISION`,`planet tips would collide: (zs+zp)·sin(π/N) = ${a.toFixed(3)} ≤ planet tip = ${i.toFixed(3)}`)):O(void 0)}function F0(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 I0(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 L0(e,t){return 1-e*Math.sin(t)*Math.sin(t)/2}function R0(e,t,n){return Math.max(0,L0(e,t)-n)}function z0(e){return e<8?.2:.485-2.88/e}function B0(e,t,n,r){let i=e*1e3,a=z0(r);return a<=0||n<=0||t<=0?1/0:2*i/(r*t*t*n*a)}function V0(e,t,n=!1){let r=(1.4+6.5/e)*(20/(t*180/Math.PI))**.15;return n?r*.85:r}function H0(e,t,n,r,i,a=!1){return B0(e,t,n,r)*V0(r,i,a)}function U0(e){return e/2}function W0(e,t){return e+2*t}function G0(e){return e%2==0?Math.PI/e:0}function K0(e,t,n){return e*(1+t/n)+G0(n)}function q0(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=P0(n,r,i,s);if(A(c))return c;let l=j0(a,o,s,n,r);if(A(l))return l;let u=N0(n,r,t,a,l.value),d=[];for(let e=0;e<i;e++){let t=e*2*Math.PI/i,a=K0(t,n,r);d.push({rotationDeg:a*180/Math.PI,position:[u*Math.cos(t),u*Math.sin(t),0]})}return O(d)}function J0(e,t,n,r,i){let a=t*e.toothPitch,o=(t+1)%n*e.toothPitch,s=T0(e.alphaPitch),c=a-e.halfToothAngle-s,l=a+e.halfToothAngle+s,u=D0(e.rb,e.alphaTip,c,r,1),d=D0(e.rb,e.alphaTip,l,r,-1).reverse(),f=oA(u),p=sA(u),m=oA(d),h=sA(d),g=[],_=e=>{i.register(e),g.push(e)},v=e.isInternal?e.rb<e.rRoot:e.rb>e.rRoot;v&&_(uA([e.rRoot*Math.cos(c),e.rRoot*Math.sin(c),0],f));let y=e.rPitch*1e-5,b=_A(u,{tolerance:y});if(A(b))return b;_(b.value),_(mA(p,[e.rTip*Math.cos(a),e.rTip*Math.sin(a),0],m));let x=_A(d,{tolerance:y});if(A(x))return x;_(x.value),v&&_(uA(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),_(mA(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 Y0(e){return Z0(e,!1)}function X0(e){return Z0(e,!0)}function Z0(e,t){try{var n=OT();let{teeth:r,moduleSize:i,pressureAngle:a,shift:o,clearance:s,flankThinning:c,samples:l=O0(i)}=e;if(r<4)return k(F(`GEAR_TEETH_TOO_FEW`,`gear needs ≥ 4 teeth, got ${r}`));if(i<=0)return k(F(`GEAR_MODULE_NONPOSITIVE`,`module must be > 0, got ${i}`));let u=k0(r,i,a,o,s,c,t),d=n.u(new BT),f=[];for(let e=0;e<r;e++){let t=J0(u,e,r,l,d);if(A(t))return t;f.push(...t.value)}let p=bA(f);return A(p)?p:O(p.value)}catch(e){n.e=e}finally{n.d()}}function Q0(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=w0,flankThinning:s=0,bore:c=0,samples:l}=e;if(r<=0)return k(F(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));if(l!==void 0&&(!Number.isInteger(l)||l<1))return k(F(`GEAR_SAMPLES_INVALID`,`samples must be a positive integer; got ${String(l)}`));let u=i*Math.PI/180,d=k0(t,n,u,a,o,s,!1);if(c>0&&c>=2*d.rRoot)return k(F(`GEAR_BORE_TOO_LARGE`,`bore diameter ${c.toFixed(2)} ≥ root diameter ${(2*d.rRoot).toFixed(2)} — would erase the gear teeth`));let f=Y0({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(f))return f;let p=e2(t,u,a);return a2(f.value,r,c,d,p)}function $0(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=w0,flankThinning:s=0,ringWallThickness:c=2*e.moduleSize,samples:l}=e;if(r<=0)return k(F(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));if(c<=0)return k(F(`GEAR_WALL_NONPOSITIVE`,`ringWallThickness must be > 0`));if(l!==void 0&&(!Number.isInteger(l)||l<1))return k(F(`GEAR_SAMPLES_INVALID`,`samples must be a positive integer; got ${String(l)}`));let u=i*Math.PI/180,d=X0({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(d))return d;let f=k0(t,n,u,a,o,s,!0),p=i2(f.rPitch+c);return A(p)?p:s2(p.value,d.value,r,f,[])}function e2(e,t,n){let r=R0(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 t2(e){let t=r2(e);if(A(t))return t;let n=t.value,r=n2(n);if(A(r))return r;let{sun:i,planet:a,ring:o}=r.value,s=d2(n,i,a,o),c=l2(a.solid,n);a.solid.delete();let l=u2(o.solid,n.zr),u=f2(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 n2(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=Q0({...n,teeth:e.sunTeeth,shift:e.sunShift,bore:e.sunBore});if(A(r))return r;let i=Q0({...n,teeth:e.planetTeeth,shift:e.planetShift,bore:e.planetBore});if(A(i))return r.value.solid.delete(),i;let a=$0({...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 r2(e){let t=e.moduleSize??3,n=e.sunTeeth??15,r=e.planetTeeth??12,i=e.numPlanets??3,a=e.pressureAngleDeg??20,o=a*Math.PI/180,s=e.sunShift??0,c=e.planetShift??0,l=e.ringShift??0;if(e.thickness<=0)return k(F(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));let u=P0(n,r,i,c);if(A(u))return u;let d=W0(n,r),f=j0(o,s,c,n,r);if(A(f))return f;let p=M0(o,c,l,r,d);if(A(p))return p;let m=N0(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:U0(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 i2(e){try{var t=OT();let n=bA([t.u(new BT).register(dA(e,[0,0,0],[0,0,1]))]);return A(n)?n:O(n.value)}catch(e){t.e=e}finally{t.d()}}function a2(e,t,n,r,i){try{var a=OT();let o=a.u(new BT);o.register(e);let s=xA(e);if(A(s))return s;o.register(s.value);let c=gM(s.value,[0,0,t]);if(A(c))return c;if(n<=0)return O(c2(c.value,r,i));let l=a.u(new BT);l.register(c.value);let u=o2(n/2);if(A(u))return u;l.register(u.value);let d=gM(u.value,[0,0,t+1]);if(A(d))return d;l.register(d.value);let f=l.register(ek(d.value,[0,0,-.5])),p=AA(c.value,f);return A(p)?p:O(c2(p.value,r,i))}catch(e){a.e=e}finally{a.d()}}function o2(e){let t=i2(e);return A(t)?t:xA(t.value)}function s2(e,t,n,r,i){let a=xA(e,[t]);if(A(a))return a;let o=gM(a.value,[0,0,n]);return A(o)?o:O(c2(o.value,r,i))}function c2(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 l2(e,t){let n=[];try{for(let r=0;r<t.numPlanets;r++){let i=r*2*Math.PI/t.numPlanets,a=tk(e,K0(i,t.sunTeeth,t.planetTeeth)*180/Math.PI);try{let e=[t.centerDistance*Math.cos(i),t.centerDistance*Math.sin(i),0];n.push(ek(a,e))}finally{a.delete()}}return n}catch(e){for(let e of n)e.delete();throw e}}function u2(e,t){let n=G0(t);if(n===0)return e;let r=tk(e,n*180/Math.PI);return e.delete(),r}function d2(e,t,n,r){let i={crSunPlanet:F0(t.tipDiameter/2,t.baseDiameter/2,n.tipDiameter/2,n.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_sp),crPlanetRing:I0(n.tipDiameter/2,n.baseDiameter/2,r.tipDiameter/2,r.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_pr),undercutSun:R0(e.sunTeeth,e.alpha,e.sunShift),undercutPlanet:R0(e.planetTeeth,e.alpha,e.planetShift)};if(e.appliedTorque!==void 0){let t=e.appliedTorque;i.lewisStress={sun:H0(t,e.moduleSize,e.thickness,e.sunTeeth,e.alpha),planet:H0(t*e.planetTeeth/e.sunTeeth,e.moduleSize,e.thickness,e.planetTeeth,e.alpha),ring:H0(t*e.zr/e.sunTeeth,e.moduleSize,e.thickness,e.zr,e.alpha,!0)},i.stressConcentrationFactor={sun:V0(e.sunTeeth,e.alpha),planet:V0(e.planetTeeth,e.alpha),ring:V0(e.zr,e.alpha,!0)}}return i}function f2(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 p2=bX({addHoles:()=>TP,bezier:()=>fP,box:()=>$N,bsplineApprox:()=>dP,circle:()=>oP,compound:()=>xP,cone:()=>nP,cylinder:()=>eP,ellipse:()=>sP,ellipseArc:()=>uP,ellipsoid:()=>iP,face:()=>gP,fill:()=>SA,filledFace:()=>_P,helix:()=>cP,line:()=>aP,offsetFace:()=>CP,polygon:()=>yP,polyhedron:()=>NQ,sewShells:()=>wP,solid:()=>SP,sphere:()=>tP,subFace:()=>vP,tangentArc:()=>pP,threePointArc:()=>lP,torus:()=>rP,vertex:()=>bP,wire:()=>mP,wireLoop:()=>hP}),m2=bX({checkBoolean:()=>Cj,convexHull:()=>OQ,cut:()=>C1,cutAll:()=>PA,cutAllBisect:()=>mj,fuse:()=>S1,fuseAll:()=>NA,fuseAllBisect:()=>vj,hull:()=>DQ,intersect:()=>E1,minkowski:()=>MQ,section:()=>D1,sectionToFace:()=>O1,slice:()=>A1,split:()=>k1}),h2=bX({chamfer:()=>F1,draft:()=>z1,fillet:()=>P1,heal:()=>B1,offset:()=>L1,shell:()=>I1,simplify:()=>V1,thicken:()=>R1,variableFillet:()=>Jj}),g2=bX({applyMatrix:()=>y1,clone:()=>v1,composeTransforms:()=>lk,mirror:()=>g1,rotate:()=>h1,scale:()=>_1,transformCopy:()=>b1,translate:()=>m1}),_2=bX({checkAllInterferences:()=>W$,checkInterference:()=>U$,createDistanceQuery:()=>PM,measureArea:()=>AM,measureCurvatureAt:()=>FM,measureCurvatureAtMid:()=>IM,measureDistance:()=>MM,measureDistanceProps:()=>NM,measureLength:()=>jM,measureLinearProps:()=>OM,measureSurfaceProps:()=>DM,measureVolume:()=>kM,measureVolumeProps:()=>EM}),v2=bX({blueprintToDXF:()=>cY,exportAssemblySTEP:()=>OP,exportDXF:()=>sY,exportGlb:()=>JJ,exportGltf:()=>qJ,exportIGES:()=>Zk,exportOBJ:()=>LJ,exportSTEP:()=>Yk,exportSTEPConfigured:()=>GY,exportSTL:()=>Xk,exportThreeMF:()=>DY,importDXF:()=>Y$,importGLB:()=>f1,importIGES:()=>JY,importOBJ:()=>$$,importSTEP:()=>KY,importSTL:()=>qY,importSVG:()=>WY,importSVGPathD:()=>UY,importThreeMF:()=>d1}),y2=bX({cornerFinder:()=>sR,edgeFinder:()=>jI,faceFinder:()=>PI,getSingleFace:()=>LI,vertexFinder:()=>kX,wireFinder:()=>II}),b2=bX({complexExtrude:()=>uM,extrude:()=>Y1,guidedSweep:()=>hM,loft:()=>Z1,multiSectionSweep:()=>mM,revolve:()=>X1,roof:()=>n$,supportExtrude:()=>lM,surfaceFromGrid:()=>SQ,surfaceFromImage:()=>TQ,sweep:()=>cM,twistExtrude:()=>dM}),x2=bX({circularPattern:()=>AP,linearPattern:()=>kP}),S2=14695981039346656037n,C2=1099511628211n,w2=18446744073709551615n;function T2(){return S2}function E2(e,t){return(e^BigInt(t&255))*C2&w2}function D2(e,t){let n=e;for(let e=0;e<t.length;e++)n=E2(n,t[e]??0);return n}var O2=new TextEncoder;function k2(e,t){return D2(e,O2.encode(t))}var A2=new ArrayBuffer(8),j2=new DataView(A2),M2=new Uint8Array(A2);function N2(e,t){return j2.setFloat64(0,Object.is(t,-0)?0:t),D2(e,M2)}function P2(e,t){let n=e,r=t&w2;for(let e=0;e<8;e++)n=E2(n,Number(r&255n)),r>>=8n;return n}function F2(e,t){let n=e,r=t|0;for(let e=0;e<4;e++)n=E2(n,r&255),r>>>=8;return n}function I2(e,t){return E2(e,+!!t)}function L2(e){return(e&w2).toString(16).padStart(16,`0`)}var R2=new Set;function z2(e){return k2(T2(),e)}function B2(e){return{kind:`NumLit`,value:e,structuralHash:N2(z2(`NumLit`),e),freeParams:R2}}function V2(e){let t=z2(`Vec3Lit`);for(let n of e)t=N2(t,n);return{kind:`Vec3Lit`,value:e,structuralHash:t,freeParams:R2}}function H2(e){let t=z2(`Vec2Lit`);for(let n of e)t=N2(t,n);return{kind:`Vec2Lit`,value:e,structuralHash:t,freeParams:R2}}function U2(e){return{kind:`Param`,name:e,structuralHash:k2(z2(`Param`),e),freeParams:new Set([e])}}function W2(e,t,n){let r=k2(z2(`BinOp`),e);return r=P2(r,t.structuralHash),r=P2(r,n.structuralHash),{kind:`BinOp`,op:e,a:t,b:n,structuralHash:r,freeParams:e4(t.freeParams,n.freeParams)}}function G2(e,t){let n=k2(z2(`UnaryOp`),e);return n=P2(n,t.structuralHash),{kind:`UnaryOp`,op:e,arg:t,structuralHash:n,freeParams:t.freeParams}}function K2(e,t){let n=F2(z2(`Component`),t);return n=P2(n,e.structuralHash),{kind:`Component`,vec:e,index:t,structuralHash:n,freeParams:e.freeParams}}function q2(e,t){let n=F2(z2(`BuildVec`),e),r=new Set;for(let e of t){n=P2(n,e.structuralHash);for(let t of e.freeParams)r.add(t)}return{kind:`BuildVec`,dim:e,components:t,structuralHash:n,freeParams:r}}var J2=(e,t)=>W2(`+`,e,t),Y2=(e,t)=>W2(`*`,e,t);function X2(e){return typeof e==`number`?B2(e):e}function Z2(e,t){if(!Array.isArray(e))return e;let n=e;return n.every(e=>typeof e==`number`)?t===3?V2([n[0],n[1],n[2]]):H2([n[0],n[1]]):q2(t,n.map(X2))}function Q2(e){return Z2(e,3)}function $2(e){return Z2(e,2)}function e4(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 t4(e){return typeof e==`number`}function n4(e,t){return t4(e)?O(e):k(F(N.NULL_SHAPE_INPUT,`${t}: expected number, got ${Array.isArray(e)?`vector(${e.length})`:typeof e}`))}function r4(e,t,n){return Array.isArray(e)&&e.length===t?O(e):k(F(N.NULL_SHAPE_INPUT,`${n}: expected Vec${t}, got ${t4(e)?`number`:`vector(${e.length})`}`))}function i4(e,t){switch(e.kind){case`NumLit`:return O(e.value);case`Vec3Lit`:return O(e.value);case`Vec2Lit`:return O(e.value);case`Param`:{let n=t[e.name];return n===void 0?k(F(N.NULL_SHAPE_INPUT,`unbound param: ${e.name}`)):O(n)}case`BinOp`:return a4(e,t);case`UnaryOp`:return o4(e,t);case`Component`:return s4(e,t);case`BuildVec`:return c4(e,t)}}function a4(e,t){let n=i4(e.a,t);if(!n.ok)return n;let r=i4(e.b,t);if(!r.ok)return r;let i=n4(n.value,`BinOp(${e.op}).a`);if(!i.ok)return i;let a=n4(r.value,`BinOp(${e.op}).b`);if(!a.ok)return a;switch(e.op){case`+`:return O(i.value+a.value);case`-`:return O(i.value-a.value);case`*`:return O(i.value*a.value);case`/`:return a.value===0?k(F(N.NULL_SHAPE_INPUT,`BinOp(/): division by zero`)):O(i.value/a.value)}}function o4(e,t){let n=i4(e.arg,t);if(!n.ok)return n;let r=n4(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 s4(e,t){let n=i4(e.vec,t);if(!n.ok)return n;if(t4(n.value))return k(F(N.NULL_SHAPE_INPUT,`Component: cannot index a scalar`));let r=n.value,i=r[e.index];return i===void 0?k(F(N.NULL_SHAPE_INPUT,`Component: index ${e.index} out of range for Vec${r.length}`)):O(i)}function c4(e,t){if(e.components.length!==e.dim)return k(F(N.NULL_SHAPE_INPUT,`BuildVec(${e.dim}): expected ${e.dim} components, got ${e.components.length}`));let n=[];for(let r of e.components){let e=i4(r,t);if(!e.ok)return e;let i=n4(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 l4(e,t,n){let r=i4(e,t);return r.ok?n4(r.value,n):r}function u4(e,t,n){let r=i4(e,t);if(!r.ok)return r;let i=r4(r.value,3,n);if(!i.ok)return i;let[a,o,s]=i.value;return O([a,o,s])}function d4(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 f4=new Set;function p4(e){return k2(T2(),e)}function m4(e,t){return P2(e,t.structuralHash)}function h4(e,t){return t===void 0?I2(e,!1):m4(I2(e,!0),t)}function g4(e,t){return t===void 0?I2(e,!1):N2(I2(e,!0),t)}function _4(...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?f4:t}function v4(e,t,n){let r=X2(e),i=X2(t),a=X2(n),o=p4(`Box`);return o=m4(m4(m4(o,r),i),a),{kind:`Box`,x:r,y:i,z:a,structuralHash:o,freeParams:_4(r,i,a)}}function y4(e){let t=X2(e);return{kind:`Sphere`,radius:t,structuralHash:m4(p4(`Sphere`),t),freeParams:t.freeParams}}function b4(e,t){let n=X2(e),r=X2(t);return{kind:`Cylinder`,radius:n,height:r,structuralHash:m4(m4(p4(`Cylinder`),n),r),freeParams:_4(n,r)}}function x4(e,t,n){let r=X2(e),i=X2(t),a=X2(n),o=p4(`Cone`);return o=m4(m4(m4(o,r),i),a),{kind:`Cone`,radius1:r,radius2:i,height:a,structuralHash:o,freeParams:_4(r,i,a)}}function S4(e,t){let n=X2(e),r=X2(t);return{kind:`Torus`,majorRadius:n,minorRadius:r,structuralHash:m4(m4(p4(`Torus`),n),r),freeParams:_4(n,r)}}function C4(e){let t=e.map(Q2),n=F2(p4(`Polygon`),t.length);for(let e of t)n=m4(n,e);return{kind:`Polygon`,points:t,structuralHash:n,freeParams:_4(...t)}}function w4(e){let t=X2(e);return{kind:`Circle`,radius:t,structuralHash:m4(p4(`Circle`),t),freeParams:t.freeParams}}function T4(e,t){let n=Q2(e),r=Q2(t);return{kind:`Line`,from:n,to:r,structuralHash:m4(m4(p4(`Line`),n),r),freeParams:_4(n,r)}}function E4(e){let t=Q2(e);return{kind:`Vertex`,point:t,structuralHash:m4(p4(`Vertex`),t),freeParams:t.freeParams}}function D4(e){return{kind:`Empty`,output:e,structuralHash:k2(p4(`Empty`),e),freeParams:f4}}function O4(){return D4(`Solid`)}function k4(){return D4(`Face`)}function A4(){return D4(`Wire`)}function j4(e,t,n,r){return g4(m4(m4(p4(e),t),n),r)}function M4(e,t,n){return{kind:`Fuse`,a:e,b:t,tolerance:n,structuralHash:j4(`Fuse`,e,t,n),freeParams:_4(e,t)}}function N4(e,t,n){return{kind:`Cut`,a:e,b:t,tolerance:n,structuralHash:j4(`Cut`,e,t,n),freeParams:_4(e,t)}}function P4(e,t,n){return{kind:`Intersect`,a:e,b:t,tolerance:n,structuralHash:j4(`Intersect`,e,t,n),freeParams:_4(e,t)}}function F4(e,t){let n=F2(p4(`FuseAll`),e.length);for(let t of e)n=m4(n,t);return n=g4(n,t),{kind:`FuseAll`,shapes:e,tolerance:t,structuralHash:n,freeParams:_4(...e)}}function I4(e,t,n){let r=m4(p4(`CutAll`),e);r=F2(r,t.length);for(let e of t)r=m4(r,e);return r=g4(r,n),{kind:`CutAll`,base:e,tools:t,tolerance:n,structuralHash:r,freeParams:_4(e,...t)}}function L4(e){return e===void 0?void 0:Q2(e)}function R4(e,t){let n=Q2(t);return{kind:`Translate`,target:e,vector:n,structuralHash:m4(m4(p4(`Translate`),e),n),freeParams:_4(e,n)}}function z4(e,t,n){let r=X2(t),i=L4(n?.axis),a=L4(n?.at),o=m4(m4(p4(`Rotate`),e),r);return o=h4(o,i),o=h4(o,a),{kind:`Rotate`,target:e,angle:r,axis:i,at:a,structuralHash:o,freeParams:_4(e,r,i,a)}}function B4(e,t,n){let r=X2(t),i=L4(n?.center),a=m4(m4(p4(`Scale`),e),r);return a=h4(a,i),{kind:`Scale`,target:e,factor:r,center:i,structuralHash:a,freeParams:_4(e,r,i)}}function V4(e,t){let n=L4(t?.normal),r=L4(t?.at),i=m4(p4(`Mirror`),e);return i=h4(i,n),i=h4(i,r),{kind:`Mirror`,target:e,normal:n,at:r,structuralHash:i,freeParams:_4(e,n,r)}}function H4(e){let t=F2(p4(`Compound`),e.length);for(let n of e)t=m4(t,n);return{kind:`Compound`,children:e,structuralHash:t,freeParams:_4(...e)}}function U4(e,t,n=!1){let r=t.map(e=>e.map(e=>[...e])),i=F2(I2(m4(p4(`Instance`),e),n),r.length);for(let e of r)for(let t of e.flat())i=N2(i,t);return{kind:`Instance`,source:e,placements:r,fuse:n,structuralHash:i,freeParams:_4(e)}}function W4(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 W4(e.a);case`FuseAll`:return e.shapes[0]?W4(e.shapes[0]):`Solid`;case`CutAll`:return W4(e.base);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return W4(e.target);case`Compound`:return`Compound`;case`Instance`:return e.fuse?`Solid`:`Compound`}}function G4(e,t){let n=l4(e.x,t.env,`Box.x`);if(!n.ok)return n;let r=l4(e.y,t.env,`Box.y`);if(!r.ok)return r;let i=l4(e.z,t.env,`Box.z`);return i.ok?O($N(n.value,r.value,i.value)):i}function K4(e,t){let n=l4(e.radius,t.env,`Sphere.radius`);return n.ok?O(tP(n.value)):n}function q4(e,t){let n=l4(e.radius,t.env,`Cylinder.radius`);if(!n.ok)return n;let r=l4(e.height,t.env,`Cylinder.height`);return r.ok?O(eP(n.value,r.value)):r}function J4(e,t){let n=l4(e.radius1,t.env,`Cone.radius1`);if(!n.ok)return n;let r=l4(e.radius2,t.env,`Cone.radius2`);if(!r.ok)return r;let i=l4(e.height,t.env,`Cone.height`);return i.ok?O(nP(n.value,r.value,i.value)):i}function Y4(e,t){let n=l4(e.majorRadius,t.env,`Torus.majorRadius`);if(!n.ok)return n;let r=l4(e.minorRadius,t.env,`Torus.minorRadius`);return r.ok?O(rP(n.value,r.value)):r}function X4(e,t){let n=[];for(let r of e.points){let e=u4(r,t.env,`Polygon.point`);if(!e.ok)return e;n.push(e.value)}return yP(n)}function Z4(e,t){let n=l4(e.radius,t.env,`Circle.radius`);return n.ok?O(oP(n.value)):n}function Q4(e,t){let n=u4(e.from,t.env,`Line.from`);if(!n.ok)return n;let r=u4(e.to,t.env,`Line.to`);return r.ok?O(aP(n.value,r.value)):r}function $4(e,t){let n=u4(e.point,t.env,`Vertex.point`);return n.ok?O(bP(n.value)):n}function e3(e){return k(I(N.NULL_SHAPE_INPUT,`${e}: empty result has no kernel representation`))}function t3(e,t,n){let r=e.evalNode(t);return r.ok?kE(r.value)?O(r.value):k(ho(N.CSG_NOT_3D,`${n}: operand did not produce a 3D shape`)):r}function n3(e,t){return{unsafe:!0,fuzzyValue:e.tolerance??t.tolerance}}function r3(e,t){if(e.a.kind===`Empty`)return t.evalNode(e.b);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=t3(t,e.a,`Fuse.a`);if(!n.ok)return n;let r=t3(t,e.b,`Fuse.b`);return r.ok?kA(n.value,r.value,n3(e,t)):r}function i3(e,t){if(e.a.kind===`Empty`)return e3(`Cut`);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=t3(t,e.a,`Cut.a`);if(!n.ok)return n;let r=t3(t,e.b,`Cut.b`);return r.ok?AA(n.value,r.value,n3(e,t)):r}function a3(e,t){if(e.a.kind===`Empty`||e.b.kind===`Empty`)return e3(`Intersect`);let n=t3(t,e.a,`Intersect.a`);if(!n.ok)return n;let r=t3(t,e.b,`Intersect.b`);return r.ok?jA(n.value,r.value,n3(e,t)):r}function o3(e,t,n){let r=[];for(let i of t){let t=t3(e,i,n);if(!t.ok)return t;r.push(t.value)}return O(r)}function s3(e,t){let n=e.shapes.filter(e=>e.kind!==`Empty`);if(n.length===0)return e3(`FuseAll`);if(n.length===1&&n[0])return t.evalNode(n[0]);let r=o3(t,n,`FuseAll.operand`);return r.ok?NA(r.value,n3(e,t)):r}function c3(e,t){if(e.base.kind===`Empty`)return e3(`CutAll`);let n=e.tools.filter(e=>e.kind!==`Empty`);if(n.length===0)return t.evalNode(e.base);let r=t3(t,e.base,`CutAll.base`);if(!r.ok)return r;let i=o3(t,n,`CutAll.tool`);return i.ok?PA(r.value,i.value,n3(e,t)):i}function l3(e){return k(I(N.NULL_SHAPE_INPUT,`${e}: cannot transform an Empty node`))}function u3(e,t,n,r){return e?u4(e,t,n):O(r)}function d3(e,t){let n=U(),{handle:r,dispose:i}=n.composeTransform(t),a;try{a=jE(n.locate(e.wrapped,r))}finally{i()}return YO(e)&&$O(e,a),a}function f3(e,t){if(e.target.kind===`Empty`)return l3(`Translate`);let n=u4(e.vector,t.env,`Translate.vector`);if(!n.ok)return n;let r=t.evalNode(e.target);return r.ok?O(d3(r.value,[{type:`translate`,x:n.value[0],y:n.value[1],z:n.value[2]}])):r}function p3(e,t){if(e.target.kind===`Empty`)return l3(`Rotate`);let n=l4(e.angle,t.env,`Rotate.angle`);if(!n.ok)return n;let r=u3(e.axis,t.env,`Rotate.axis`,[0,0,1]);if(!r.ok)return r;let i=u3(e.at,t.env,`Rotate.at`,[0,0,0]);if(!i.ok)return i;let a=t.evalNode(e.target);return a.ok?O(d3(a.value,[{type:`rotate`,angle:n.value,axis:r.value,center:i.value}])):a}function m3(e,t){if(e.target.kind===`Empty`)return l3(`Scale`);let n=l4(e.factor,t.env,`Scale.factor`);if(!n.ok)return n;let r=u3(e.center,t.env,`Scale.center`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(rk(i.value,n.value,r.value)):i}function h3(e,t){if(e.target.kind===`Empty`)return l3(`Mirror`);let n=u3(e.normal,t.env,`Mirror.normal`,[1,0,0]);if(!n.ok)return n;let r=u3(e.at,t.env,`Mirror.at`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(nk(i.value,n.value,r.value)):i}function g3(e,t){let n=e.children.filter(e=>e.kind!==`Empty`);if(n.length===0)return k(I(N.NULL_SHAPE_INPUT,`Compound: cannot materialize a compound with zero non-empty children`));let r=[];for(let e of n){let n=t.evalNode(e);if(!n.ok)return n;r.push(n.value)}return O(xP(r))}function _3(){return k(I(N.NULL_SHAPE_INPUT,`Empty: cannot materialize an Empty node directly — only valid as boolean/transform operand`))}function v3(e,t){let n=t.evalNode(e.source);return n.ok?u$(s$(n.value,e.placements),{fuse:e.fuse}):n}function y3(e,t){switch(e.kind){case`Box`:return G4(e,t);case`Sphere`:return K4(e,t);case`Cylinder`:return q4(e,t);case`Cone`:return J4(e,t);case`Torus`:return Y4(e,t);case`Polygon`:return X4(e,t);case`Circle`:return Z4(e,t);case`Line`:return Q4(e,t);case`Vertex`:return $4(e,t);case`Empty`:return _3();case`Fuse`:return r3(e,t);case`Cut`:return i3(e,t);case`Intersect`:return a3(e,t);case`FuseAll`:return s3(e,t);case`CutAll`:return c3(e,t);case`Translate`:return f3(e,t);case`Rotate`:return p3(e,t);case`Scale`:return m3(e,t);case`Mirror`:return h3(e,t);case`Compound`:return g3(e,t);case`Instance`:return v3(e,t)}}function b3(e,t){if(typeof t==`number`)return N2(I2(e,!1),t);let n=I2(e,!0);n=F2(n,t.length);for(let e of t)n=N2(n,e);return n}function x3(e,t){if(t.size===0)return T2();let n=d4(e,t),r=Object.keys(n).sort(),i=T2();for(let e of r){i=k2(i,e);let t=n[e];t!==void 0&&(i=b3(i,t))}return i}function S3(e,t,n,r){let i=x3(t,e.freeParams),a=r===void 0?`d`:N2(T2(),r).toString(16);return`${L2(e.structuralHash)}:${n}:${L2(i)}:${a}`}var C3=[1,0,0,0];function w3(e,t){let n=l4(e.angle,t,`evaluateMesh.peelRigid`);if(!n.ok)return null;let r=e.axis?u4(e.axis,t,`evaluateMesh.peelRigid`):O([0,0,1]);if(!r.ok)return null;let i=e.at?u4(e.at,t,`evaluateMesh.peelRigid`):O([0,0,0]);return i.ok?{angle:n.value,axis:r.value,center:i.value}:null}function T3(e,t){let n=e,r=C3,i=[0,0,0];for(;;)if(n.kind===`Translate`){let e=u4(n.vector,t,`evaluateMesh.peelRigid`);if(!e.ok)break;let a=WP(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=w3(n,t);if(!e)break;let a=GP(e.axis,e.angle*Math.PI/180),o=qP(r,a),s=WP(r,e.center),c=WP(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 E3(e){return e[0]===1&&e[1]===0&&e[2]===0&&e[3]===0}function D3(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 O3(e,t,n){let[r,i,a]=n,o=E3(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;D3(c,s,l,u,d,f,r,i,a);let p=e.normals,m=new Float32Array(p.length);return D3(m,p,l,u,d,f,0,0,0),{...e,vertices:c,normals:m}}function k3(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 A3=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??_T()??`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 vT(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=To(),a=n.tolerance??i.tolerance,o=n.angularTolerance??i.angularTolerance,s=`${S3(e,t,this.kernelId,this.defaultTolerance)}|${Pk(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}=T3(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=ZE(c.value).map(mk),u=this.evaluate(e,t);if(!u.ok)return u;let d=ZE(u.value).map(mk),f=O3(r.value,a,o),p=k3(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=vT(this.kernelId,()=>Wk(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=S3(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=y3(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 j3(e,t){try{var n=OT();let r=t(n.u(new A3(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 M3(e){return{csgVersion:1,root:R3(e)}}function N3(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:N3(e.a),b:N3(e.b)};case`UnaryOp`:return{kind:`UnaryOp`,op:e.op,arg:N3(e.arg)};case`Component`:return{kind:`Component`,vec:N3(e.vec),index:e.index};case`BuildVec`:return{kind:`BuildVec`,dim:e.dim,components:e.components.map(N3)}}}function P3(e){switch(e.kind){case`Box`:return{kind:`Box`,x:N3(e.x),y:N3(e.y),z:N3(e.z)};case`Sphere`:return{kind:`Sphere`,radius:N3(e.radius)};case`Cylinder`:return{kind:`Cylinder`,radius:N3(e.radius),height:N3(e.height)};case`Cone`:return{kind:`Cone`,radius1:N3(e.radius1),radius2:N3(e.radius2),height:N3(e.height)};case`Torus`:return{kind:`Torus`,majorRadius:N3(e.majorRadius),minorRadius:N3(e.minorRadius)};case`Polygon`:return{kind:`Polygon`,points:e.points.map(N3)};case`Circle`:return{kind:`Circle`,radius:N3(e.radius)};case`Line`:return{kind:`Line`,from:N3(e.from),to:N3(e.to)};case`Vertex`:return{kind:`Vertex`,point:N3(e.point)};case`Empty`:return{kind:`Empty`,output:e.output};default:return}}function F3(e){switch(e.kind){case`Fuse`:case`Cut`:case`Intersect`:return{kind:e.kind,a:R3(e.a),b:R3(e.b),tolerance:e.tolerance};case`FuseAll`:return{kind:`FuseAll`,shapes:e.shapes.map(R3),tolerance:e.tolerance};case`CutAll`:return{kind:`CutAll`,base:R3(e.base),tools:e.tools.map(R3),tolerance:e.tolerance};default:return}}function I3(e){return e?N3(e):void 0}function L3(e){switch(e.kind){case`Translate`:return{kind:`Translate`,target:R3(e.target),vector:N3(e.vector)};case`Rotate`:return{kind:`Rotate`,target:R3(e.target),angle:N3(e.angle),axis:I3(e.axis),at:I3(e.at)};case`Scale`:return{kind:`Scale`,target:R3(e.target),factor:N3(e.factor),center:I3(e.center)};case`Mirror`:return{kind:`Mirror`,target:R3(e.target),normal:I3(e.normal),at:I3(e.at)};default:return}}function R3(e){return e.kind===`Compound`?{kind:`Compound`,children:e.children.map(R3)}:e.kind===`Instance`?{kind:`Instance`,source:R3(e.source),placements:e.placements,fuse:e.fuse}:P3(e)??F3(e)??L3(e)}function z3(e){return k(F(N.NULL_SHAPE_INPUT,`csg.fromJSON: ${e}`))}function B3(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function V3(e){return typeof e==`number`&&Number.isFinite(e)}function H3(e){return typeof e==`string`}function U3(e,t){if(!Array.isArray(e)||e.length!==3)return z3(`${t}: expected Vec3 array`);let[n,r,i]=e;return!V3(n)||!V3(r)||!V3(i)?z3(`${t}: Vec3 contains non-number`):O([n,r,i])}function W3(e,t){if(!Array.isArray(e)||e.length!==2)return z3(`${t}: expected Vec2 array`);let[n,r]=e;return!V3(n)||!V3(r)?z3(`${t}: Vec2 contains non-number`):O([n,r])}function G3(e){if(!B3(e))return z3(`input is not an object`);let t=e.csgVersion;if(t!==1)return z3(`unsupported csgVersion ${String(t)} (expected 1)`);let n=e.root;return $3(n)}function K3(e){if(!B3(e))return z3(`expression: not an object`);let t=e.kind;switch(t){case`NumLit`:return V3(e.value)?O(B2(e.value)):z3(`NumLit.value`);case`Vec3Lit`:{let t=U3(e.value,`Vec3Lit.value`);return t.ok?O(V2(t.value)):t}case`Vec2Lit`:{let t=W3(e.value,`Vec2Lit.value`);return t.ok?O(H2(t.value)):t}case`Param`:return H3(e.name)?O(U2(e.name)):z3(`Param.name`);case`BinOp`:return q3(e);case`UnaryOp`:return J3(e);case`Component`:return Y3(e);case`BuildVec`:return X3(e);default:return z3(`unknown expression kind: ${String(t)}`)}}function q3(e){let t=e.op;if(t!==`+`&&t!==`-`&&t!==`*`&&t!==`/`)return z3(`BinOp.op: ${String(t)}`);let n=K3(e.a);if(!n.ok)return n;let r=K3(e.b);return r.ok?O(W2(t,n.value,r.value)):r}function J3(e){let t=e.op;if(!H3(t)||![`neg`,`sin`,`cos`,`sqrt`,`abs`].includes(t))return z3(`UnaryOp.op: ${String(t)}`);let n=K3(e.arg);return n.ok?O(G2(t,n.value)):n}function Y3(e){let t=e.index;if(t!==0&&t!==1&&t!==2)return z3(`Component.index: ${String(t)}`);let n=K3(e.vec);return n.ok?O(K2(n.value,t)):n}function X3(e){let t=e.dim;if(t!==2&&t!==3)return z3(`BuildVec.dim: ${String(t)}`);let n=e.components;if(!Array.isArray(n))return z3(`BuildVec.components: not array`);if(n.length!==t)return z3(`BuildVec.components: expected ${t} components, got ${n.length}`);let r=[];for(let e of n){let t=K3(e);if(!t.ok)return t;r.push(t.value)}return O(q2(t,r))}function Z3(e,t){if(!Array.isArray(e))return z3(`${t}: not array`);let n=[];for(let t of e){let e=$3(t);if(!e.ok)return e;n.push(e.value)}return O(n)}function Q3(e){let t=e.tolerance;return t==null?O(void 0):V3(t)?O(t):z3(`tolerance: not a finite number`)}function $3(e){if(!B3(e))return z3(`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 t6(t,e);case`Fuse`:case`Cut`:case`Intersect`:return l6(t,e);case`FuseAll`:case`CutAll`:return u6(t,e);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return d6(t,e);case`Compound`:return _6(e);case`Instance`:return y6(e);default:return z3(`unknown node kind: ${String(t)}`)}}function e6(e,t,n){let r=K3(e[t]);return r.ok?O(n(r.value)):r}function t6(e,t){switch(e){case`Box`:return n6(t);case`Sphere`:return e6(t,`radius`,y4);case`Cylinder`:return r6(t);case`Cone`:return i6(t);case`Torus`:return a6(t);case`Polygon`:return o6(t);case`Circle`:return e6(t,`radius`,w4);case`Line`:return s6(t);case`Vertex`:return e6(t,`point`,E4);case`Empty`:return c6(t)}return z3(`unhandled primitive: ${e}`)}function n6(e){let t=K3(e.x);if(!t.ok)return t;let n=K3(e.y);if(!n.ok)return n;let r=K3(e.z);return r.ok?O(v4(t.value,n.value,r.value)):r}function r6(e){let t=K3(e.radius);if(!t.ok)return t;let n=K3(e.height);return n.ok?O(b4(t.value,n.value)):n}function i6(e){let t=K3(e.radius1);if(!t.ok)return t;let n=K3(e.radius2);if(!n.ok)return n;let r=K3(e.height);return r.ok?O(x4(t.value,n.value,r.value)):r}function a6(e){let t=K3(e.majorRadius);if(!t.ok)return t;let n=K3(e.minorRadius);return n.ok?O(S4(t.value,n.value)):n}function o6(e){let t=e.points;if(!Array.isArray(t))return z3(`Polygon.points: not array`);let n=[];for(let e of t){let t=K3(e);if(!t.ok)return t;n.push(t.value)}return O(C4(n))}function s6(e){let t=K3(e.from);if(!t.ok)return t;let n=K3(e.to);return n.ok?O(T4(t.value,n.value)):n}function c6(e){let t=e.output;switch(t){case`Solid`:return O(O4());case`Face`:return O(k4());case`Wire`:return O(A4());default:return z3(`Empty.output: ${String(t)}`)}}function l6(e,t){let n=$3(t.a);if(!n.ok)return n;let r=$3(t.b);if(!r.ok)return r;let i=Q3(t);if(!i.ok)return i;switch(e){case`Fuse`:return O(M4(n.value,r.value,i.value));case`Cut`:return O(N4(n.value,r.value,i.value));case`Intersect`:return O(P4(n.value,r.value,i.value))}}function u6(e,t){let n=Q3(t);if(!n.ok)return n;if(e===`FuseAll`){let e=Z3(t.shapes,`FuseAll.shapes`);return e.ok?O(F4(e.value,n.value)):e}let r=$3(t.base);if(!r.ok)return r;let i=Z3(t.tools,`CutAll.tools`);return i.ok?O(I4(r.value,i.value,n.value)):i}function d6(e,t){let n=$3(t.target);if(!n.ok)return n;switch(e){case`Translate`:return f6(t,n.value);case`Rotate`:return m6(t,n.value);case`Scale`:return h6(t,n.value);case`Mirror`:return g6(t,n.value)}}function f6(e,t){let n=K3(e.vector);return n.ok?O(R4(t,n.value)):n}function p6(e,t){if(e[t]===void 0)return O(void 0);let n=K3(e[t]);return n.ok?O(n.value):n}function m6(e,t){let n=K3(e.angle);if(!n.ok)return n;let r=p6(e,`axis`);if(!r.ok)return r;let i=p6(e,`at`);return i.ok?O(z4(t,n.value,{axis:r.value,at:i.value})):i}function h6(e,t){let n=K3(e.factor);if(!n.ok)return n;let r=p6(e,`center`);return r.ok?O(B4(t,n.value,{center:r.value})):r}function g6(e,t){let n=p6(e,`normal`);if(!n.ok)return n;let r=p6(e,`at`);return r.ok?O(V4(t,{normal:n.value,at:r.value})):r}function _6(e){let t=Z3(e.children,`Compound.children`);return t.ok?O(H4(t.value)):t}function v6(e){return Array.isArray(e)&&e.length===4&&e.every(e=>Array.isArray(e)&&e.length===4&&e.every(V3))}function y6(e){let t=$3(e.source);if(!t.ok)return t;let n=e.placements;return!Array.isArray(n)||!n.every(v6)?z3(`Instance.placements must be an array of 4x4 number matrices`):O(U4(t.value,n,e.fuse===!0))}function b6(e){return C6(e)}function x6(e){switch(e.kind){case`NumLit`:case`Vec3Lit`:case`Vec2Lit`:case`Param`:return e;case`BinOp`:{let t=x6(e.a),n=x6(e.b);if(t.kind===`NumLit`&&n.kind===`NumLit`)switch(e.op){case`+`:return B2(t.value+n.value);case`-`:return B2(t.value-n.value);case`*`:return B2(t.value*n.value);case`/`:return B2(t.value/n.value)}return t!==e.a||n!==e.b?W2(e.op,t,n):e}case`UnaryOp`:{let t=x6(e.arg);if(t.kind===`NumLit`){let n=t.value;switch(e.op){case`neg`:return B2(-n);case`sin`:return B2(Math.sin(n));case`cos`:return B2(Math.cos(n));case`sqrt`:return B2(Math.sqrt(n));case`abs`:return B2(Math.abs(n))}}return t===e.arg?e:G2(e.op,t)}case`Component`:{let t=x6(e.vec);return t.kind===`Vec3Lit`||t.kind===`Vec2Lit`&&(e.index===0||e.index===1)?B2(t.value[e.index]):t===e.vec?e:K2(t,e.index)}case`BuildVec`:{let t=e.components.map(x6);return S6(e.dim,t)||(t.some((t,n)=>t!==e.components[n])?q2(e.dim,t):e)}}}function S6(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?H2([n[0],n[1]]):V2([n[0],n[1],n[2]])}function C6(e){switch(e.kind){case`Box`:return v4(x6(e.x),x6(e.y),x6(e.z));case`Sphere`:return y4(x6(e.radius));case`Cylinder`:return b4(x6(e.radius),x6(e.height));case`Cone`:return x4(x6(e.radius1),x6(e.radius2),x6(e.height));case`Torus`:return S4(x6(e.majorRadius),x6(e.minorRadius));case`Polygon`:return C4(e.points.map(x6));case`Circle`:return w4(x6(e.radius));case`Line`:return T4(x6(e.from),x6(e.to));case`Vertex`:return E4(x6(e.point));case`Empty`:return e;case`Fuse`:return w6(e.a,e.b,e.tolerance);case`Cut`:return T6(e.a,e.b,e.tolerance);case`Intersect`:return E6(e.a,e.b,e.tolerance);case`FuseAll`:return D6(e.shapes,e.tolerance);case`CutAll`:return O6(e.base,e.tools,e.tolerance);case`Translate`:return k6(e.target,e.vector);case`Rotate`:return z4(C6(e.target),x6(e.angle),{axis:e.axis?x6(e.axis):void 0,at:e.at?x6(e.at):void 0});case`Scale`:return B4(C6(e.target),x6(e.factor),{center:e.center?x6(e.center):void 0});case`Mirror`:return V4(C6(e.target),{normal:e.normal?x6(e.normal):void 0,at:e.at?x6(e.at):void 0});case`Compound`:return H4(e.children.map(C6).filter(e=>e.kind!==`Empty`));case`Instance`:return U4(C6(e.source),e.placements,e.fuse)}}function w6(e,t,n){let r=C6(e),i=C6(t);return r.kind===`Empty`?i:i.kind===`Empty`?r:M4(r,i,n)}function T6(e,t,n){let r=C6(e),i=C6(t);return i.kind===`Empty`||r.kind===`Empty`?r:N4(r,i,n)}function E6(e,t,n){let r=C6(e),i=C6(t);return r.kind===`Empty`?r:i.kind===`Empty`?i:P4(r,i,n)}function D6(e,t){let n=e.map(C6).filter(e=>e.kind!==`Empty`);return n.length===0?O4():n.length===1?n[0]:F4(n,t)}function O6(e,t,n){let r=C6(e);if(r.kind===`Empty`)return r;let i=t.map(C6).filter(e=>e.kind!==`Empty`);return i.length===0?r:I4(r,i,n)}function k6(e,t){let n=C6(e),r=x6(t);if(r.kind!==`Vec3Lit`)return R4(n,r);let[i,a,o]=r.value;if(i===0&&a===0&&o===0)return n;if(n.kind===`Translate`){let e=x6(n.vector);if(e.kind===`Vec3Lit`)return R4(n.target,[e.value[0]+i,e.value[1]+a,e.value[2]+o])}return R4(n,r)}function A6(e,t,n){return j6(e,t,n)}function j6(e,t,n){return t(e)?n:M6(e,t,n)}function M6(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 M4(j6(e.a,t,n),j6(e.b,t,n),e.tolerance);case`Cut`:return N4(j6(e.a,t,n),j6(e.b,t,n),e.tolerance);case`Intersect`:return P4(j6(e.a,t,n),j6(e.b,t,n),e.tolerance);case`FuseAll`:return F4(e.shapes.map(e=>j6(e,t,n)),e.tolerance);case`CutAll`:return I4(j6(e.base,t,n),e.tools.map(e=>j6(e,t,n)),e.tolerance);case`Translate`:return R4(j6(e.target,t,n),e.vector);case`Rotate`:return z4(j6(e.target,t,n),e.angle,{axis:e.axis,at:e.at});case`Scale`:return B4(j6(e.target,t,n),e.factor,{center:e.center});case`Mirror`:return V4(j6(e.target,t,n),{normal:e.normal,at:e.at});case`Compound`:return H4(e.children.map(e=>j6(e,t,n)));case`Instance`:return U4(j6(e.source,t,n),e.placements,e.fuse)}}function N6(e,t){t(e);for(let n of P6(e))N6(n,t)}function P6(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 F6(e){let t=0;return N6(e,()=>{t++}),t}var I6=bX({CSG_VERSION:()=>1,Evaluator:()=>A3,add:()=>J2,asScalarExpr:()=>X2,asVec2Expr:()=>$2,asVec3Expr:()=>Q2,binOp:()=>W2,box:()=>v4,buildVec:()=>q2,circle:()=>w4,component:()=>K2,compound:()=>H4,cone:()=>x4,cut:()=>N4,cutAll:()=>I4,cylinder:()=>b4,emptyFace:()=>k4,emptySolid:()=>O4,emptyWire:()=>A4,foldExpr:()=>x6,forEachNode:()=>N6,fromJSON:()=>G3,fuse:()=>M4,fuseAll:()=>F4,instance:()=>U4,intersect:()=>P4,line:()=>T4,mirror:()=>V4,mul:()=>Y2,nodeCount:()=>F6,numLit:()=>B2,optimize:()=>b6,outputKindOf:()=>W4,param:()=>U2,polygon:()=>C4,replaceNode:()=>A6,rotate:()=>z4,scale:()=>B4,sphere:()=>y4,toJSON:()=>M3,torus:()=>S4,translate:()=>R4,unaryOp:()=>G2,vec2Lit:()=>H2,vec3Lit:()=>V2,vertex:()=>E4,withEvaluator:()=>j3});export{tR as BaseSketcher2d,nR as BlueprintSketcher,co as BrepBugError,N as BrepErrorCode,a0 as BrepWrapperError,ky as BrepkitAdapter,jK as CompoundSketch,i as DEFAULT_CAPABILITIES,gD as DEG2RAD,BT as DisposalScope,r as EXACT_BREP_CAPABILITIES,uq as FaceSketcher,G as HASH_CODE_MAX,Ra as OK,La as OcctWasmAdapter,_D as RAD2DEG,qK as Sketch,lq as Sketcher,JK as Sketches,NP as addChild,TP as addHoles,uF as addJoint,V$ as addMate,GF as addStep,YM as adjacentFaces,qa as all,Ha as andThen,CX as applyGlue,y1 as applyMatrix,Mk as approximateCurve,XT as as2D,YT as as3D,JD as asTopo,oN as assignRoles,eM as autoHeal,fP as bezier,cY as blueprintToDXF,GA as booleanPipeline,m2 as booleans,n0 as boss,$N as box,dP as bsplineApprox,M as bug,oq as cameraFromPlane,aq as cameraLookAt,QM as captureHint,eO as cast,jE as castShape,ME as castShape3D,F1 as chamfer,lj as chamferDistAngleShape,Mj as chamferWithEvolution,W$ as checkAllInterferences,Cj as checkBoolean,U$ as checkInterference,oP as circle,AP as circularPattern,hO as classifyPointOnFace,Hk as clearMeshCache,v1 as clone,aE as closedWire,io as collect,zP as collectShapes,GO as colorFaces,WO as colorShape,uM as complexExtrude,lk as composeTransforms,xP as compound,WK as compoundSketchExtrude,HK as compoundSketchFace,KK as compoundSketchLoft,GK as compoundSketchRevolve,I as computationError,JQ as computeStraightSkeleton,nP as cone,b2 as construction,OQ as convexHull,sR as cornerFinder,RP as countNodes,DP as createAssembly,MP as createAssemblyNode,SJ as createBlueprint,iq as createCamera,xE as createCompound,CJ as createCompoundBlueprint,zN as createDerivedFaceRef,PM as createDistanceQuery,hE as createEdge,SN as createEdgeRef,_E as createFace,RT as createHandle,WF as createHistory,zT as createKernelHandle,Uk as createMeshCache,VD as createNamedPlane,fX as createOperationRegistry,zD as createPlane,sN as createRef,QF as createRegistry,vE as createShell,yE as createSolid,iX as createTaskQueue,mE as createVertex,AN as createVertexRef,gE as createWire,dX as createWorkerClient,_X as createWorkerHandler,vX as createWorkerPool,I6 as csg,wo as currentQuality,mJ as curve2dBoundingBox,xJ as curve2dDistanceFrom,hJ as curve2dFirstPoint,bJ as curve2dIsOnCurve,gJ as curve2dLastPoint,vJ as curve2dParameter,_J as curve2dSplitAt,yJ as curve2dTangentAt,Tk as curveAxis,xk as curveEndPoint,Ek as curveIsClosed,Dk as curveIsPeriodic,wk as curveLength,Ok as curvePeriod,Sk as curvePointAt,bk as curveStartPoint,Ck as curveTangentAt,C1 as cut,qR as cut2D,T1 as cutAll,mj as cutAllBisect,IR as cutBlueprints,kj as cutWithEvolution,eP as cylinder,rF as cylindricalJoint,ZM as defaultScorer,oX as dequeueTask,W1 as describe,Vq as deserializeDrawing,aI as deserializeHistory,nO as deserializeShape,QD as downcast,z1 as draft,Uq as draw,Jq as drawCircle,Yq as drawEllipse,nJ as drawFaceOutline,$q as drawParametricFunction,Qq as drawPointsInterpolation,Xq as drawPolysides,tJ as drawProjection,Gq as drawRectangle,Wq as drawRoundedRectangle,Kq as drawSingleCircle,qq as drawSingleEllipse,Zq as drawText,cJ as drawingChamfer,aJ as drawingCut,sJ as drawingFillet,iJ as drawingFuse,oJ as drawingIntersect,rJ as drawingToSketchOnPlane,e0 as drill,jI as edgeFinder,GM as edgesOfFace,sP as ellipse,uP as ellipseArc,iP as ellipsoid,aX as enqueueTask,k as err,OP as exportAssemblySTEP,sY as exportDXF,JJ as exportGlb,qJ as exportGltf,Zk as exportIGES,LJ as exportOBJ,Yk as exportSTEP,GY as exportSTEPConfigured,Xk as exportSTL,DY as exportThreeMF,zF as exportURDF,Y1 as extrude,vM as extrudeAll,gP as face,mO as faceAxis,pO as faceCenter,PI as faceFinder,aO as faceGeomType,oO as faceOrientation,UM as facesOfEdge,WM as facesOfVertex,gZ as fieldBoolean,bZ as fieldContour,_Z as fieldOffset,yZ as fieldReinit,vZ as fieldShell,SA as fill,_P as filledFace,P1 as fillet,jj as filletWithEvolution,NO as findFacesByTag,IP as findNode,qF as findStep,rM as fixSelfIntersection,tM as fixShape,Ua as flatMap,Xa as flatten,sO as flipFaceOrientation,Ak as flipOrientation,ZY as fontMetrics,mF as forwardKinematics,K1 as fromBREP,hQ as fromKernelDir,mQ as fromKernelPnt,pQ as fromKernelVec,Qa as fromNullable,S1 as fuse,GR as fuse2D,w1 as fuseAll,vj as fuseAllBisect,FR as fuseBlueprints,Oj as fuseWithEvolution,k0 as gearGeometry,FX as getActiveVoxelId,uD as getBounds,wJ as getBounds2D,nD as getCompSolids,yk as getCurveType,MT as getDisposalStats,XE as getEdges,qO as getFaceColor,bO as getFaceOrigins,PO as getFaceTags,ZE as getFaces,ZK as getFont,mk as getHashCode,JF as getHistoryShape,U as getKernel,yT as getKernelCapabilities,CT as getKernelTier,uj as getNurbsCurveData,dj as getNurbsSurfaceData,kk as getOrientation,TJ as getOrientation2D,No as getPerformanceStats,KO as getShapeColor,eE as getShapeKind,tD as getShells,LI as getSingleFace,eD as getSolids,iO as getSurfaceType,IO as getTagMetadata,$E as getVertices,PX as getVoxel,QE as getWires,jP as gridPattern,hM as guidedSweep,B1 as heal,Zj as healFace,Xj as healSolid,Qj as healWire,cP as helix,DQ as hull,Y$ as importDXF,f1 as importGLB,JY as importIGES,$$ as importOBJ,KY as importSTEP,qY as importSTL,WY as importSVG,UY as importSVGPathD,d1 as importThreeMF,UF as importURDF,DT as init,mT as initFromManifold,TT as initFromOC,IX as initVoxel,vO as innerWires,s$ as instance,l$ as instanceCount,c$ as instanceGrid,f$ as instancedMesh,jk as interpolateCurve,E1 as intersect,JR as intersect2D,LR as intersectBlueprints,Aj as intersectWithEvolution,YE as invalidateShapeCache,OF as inverseKinematics,v2 as io,vo as ioError,JT as is2D,qT as is3D,tX as isBatchRequest,TX as isChamferRadius,tE as isClosedWire,tO as isCompSolid,OE as isCompound,HN as isDerivedFaceRef,eX as isDisposeRequest,CE as isEdge,UN as isEdgeRef,J1 as isEmpty,_k as isEqualShape,A as isErr,rX as isErrorResponse,TE as isFace,GN as isFaceRef,EX as isFilletRadius,QY as isInitRequest,EJ as isInside2D,o$ as isInstanced,KN as isLineageRef,KT as isLive,rE as isManifoldShell,wX as isNumber,za as isOk,$Y as isOperationRequest,nE as isOrientedFace,lE as isPlanarFace,uE as isPlanarWire,tq as isProjectionPlane,cX as isQueueEmpty,gk as isSameShape,AE as isShape1D,kE as isShape3D,EE as isShell,DE as isSolid,nX as isSuccessResponse,q1 as isValid,iE as isValidSolid,SE as isVertex,WN as isVertexRef,wE as isWire,lD as iterCompSolids,rD as iterEdges,iD as iterFaces,cD as iterShells,sD as iterSolids,XD as iterTopo,oD as iterVertices,aD as iterWires,AF as jointTrajectory,lF as jointTransform,NF as jointsFromDH,BE as kernelCall,VE as kernelCallRaw,HE as kernelCallScoped,P as kernelError,sQ as latticeInfill,cQ as latticeInfillShape,aP as line,kP as linearPattern,XK as loadFont,x1 as locate,Z1 as loft,bM as loftAll,bq as makeBaseBox,Q0 as makeExternalGear,$0 as makeInternalGear,UD as makePlane,t2 as makePlanetaryGear,rq as makeProjectedEdges,sE as manifoldShell,Ba as map,Za as mapBoth,Va as mapErr,ro as match,u$ as materialize,AM as measureArea,FM as measureCurvatureAt,IM as measureCurvatureAtMid,MM as measureDistance,NM as measureDistanceProps,jM as measureLength,OM as measureLinearProps,DM as measureSurfaceProps,kM as measureVolume,EM as measureVolumeProps,_2 as measurement,hF as mechanismDOF,H1 as mesh,U1 as meshEdges,nA as meshLODs,iA as meshLODsProgressive,Qk as meshMultiLOD,MQ as minkowski,g1 as mirror,jJ as mirror2D,fJ as mirrorDrawing,r0 as mirrorJoin,h2 as modifiers,rI as modifyStep,_o as moduleInitError,mM as multiSectionSweep,fO as normalAt,L1 as offset,CP as offsetFace,QX as offsetMesh,tZ as offsetShape,Nk as offsetWire2D,O as ok,Wa as or,Ga as orElse,GL as organiseBlueprints,oE as orientedFace,gO as outerWire,x2 as patterns,sX as pendingCount,so as pipeline,KD as pivotPlane,dE as planarFace,iF as planarJoint,fE as planarWire,q0 as planetPlacements,t0 as pocket,lO as pointOnSurface,VX as pointsInside,yP as polygon,NQ as polyhedron,gq as polysideInnerRadius,cR as polysidesBlueprint,Pj as positionOnCurve,ET as prewarm,p2 as primitives,nF as prismaticJoint,sq as projectEdges,dO as projectPointOnFace,y2 as query,yo as queryError,i0 as rectangularPattern,pX as registerHandler,hT as registerKernel,ST as registerKernelTier,$F as registerOperation,ZF as registerShape,NX as registerVoxel,lX as rejectAll,PP as removeChild,_O as removeHolesFromFace,WX as repairMesh,nI as replayFrom,tI as replayHistory,NT as resetDisposalStats,Po as resetPerformanceStats,ik as resize,$ as resolve,p1 as resolve3D,BN as resolveDerivedFaceRef,xD as resolveDirection,CN as resolveEdgeRef,JN as resolveLineageRef,HD as resolvePlane,pN as resolveRef,XN as resolveRefIn,QN as resolveRefParams,jN as resolveVertexRef,pJ as reverseCurve,tF as revoluteJoint,X1 as revolve,n$ as roof,h1 as rotate,kJ as rotate2D,uJ as rotateDrawing,lR as roundedRectangleBlueprint,_1 as scale,AJ as scale2D,dJ as scaleDrawing,IZ as sdfBox,BZ as sdfCapsule,zZ as sdfCone,RZ as sdfCylinder,QZ as sdfFieldAxialRamp,tQ as sdfFieldClamp,ZZ as sdfFieldConst,eQ as sdfFieldFromSdf,$Z as sdfFieldRadialRamp,KZ as sdfLattice,HZ as sdfPlane,LZ as sdfRoundedBox,FZ as sdfSphere,qZ as sdfStrutLattice,WZ as sdfSweep,VZ as sdfTorus,D1 as section,O1 as sectionToFace,iI as serializeHistory,sF as setJointValue,oF as setJointValues,yO as setShapeOrigin,FO as setTagMetadata,wP as sewShells,C0 as shape,KX as shapeToMeshInput,ZD as shapeType,XM as sharedEdges,I1 as shell,$X as shellMesh,nZ as shellShape,Nj as shellWithEvolution,V1 as simplify,dq as sketchCircle,fq as sketchEllipse,RK as sketchExtrude,FK as sketchFace,_q as sketchFaceOffset,yq as sketchHelix,BK as sketchLoft,PJ as sketchOnFace2D,NJ as sketchOnPlane2D,vq as sketchParametricFunction,hq as sketchPolysides,pq as sketchRectangle,LK as sketchRevolve,mq as sketchRoundedRectangle,zK as sketchSweep,YY as sketchText,IK as sketchWires,go as sketcherStateError,A1 as slice,SP as solid,nM as solidFromShell,H$ as solveAssembly,tP as sphere,aF as sphericalJoint,k1 as split,YF as stepCount,XF as stepsFrom,MJ as stretch2D,vP as subFace,lM as supportExtrude,uT as supportsConstraintSketch,lT as supportsProjection,SQ as surfaceFromGrid,TQ as surfaceFromImage,cM as sweep,MO as tagFaces,pP as tangentArc,Ja as tap,Ya as tapErr,$K as textBlueprints,XY as textMetrics,R1 as thicken,oI as thread,lP as threePointArc,G1 as toBREP,ij as toBufferGeometryData,aj as toGroupedBufferGeometryData,uQ as toKernelVec,sj as toLODGeometryData,cj as toLODGeometryLevels,oj as toLineGeometryData,DJ as toSVGPathD,yD as toVec2,vD as toVec3,rP as torus,lQ as tpmsLattice,b1 as transformCopy,g2 as transforms,m1 as translate,OJ as translate2D,lJ as translateDrawing,GD as translatePlane,ao as tryCatch,oo as tryCatchAsync,dM as twistExtrude,ho as typeCastError,KF as undoLast,bo as unsupportedError,j as unwrap,no as unwrapErr,eo as unwrapOr,to as unwrapOrElse,FP as updateNode,lN as updateRoles,cO as uvBounds,uO as uvCoordinates,cE as validSolid,P0 as validatePlanetary,F as validationError,Jj as variableFillet,SD as vecAdd,PD as vecAngle,DD as vecCross,AD as vecDistance,ED as vecDot,MD as vecEquals,ND as vecIsZero,OD as vecLength,kD as vecLengthSq,TD as vecNegate,jD as vecNormalize,FD as vecProjectToPlane,RD as vecRepr,ID as vecRotate,wD as vecScale,CD as vecSub,bP as vertex,kX as vertexFinder,hD as vertexPosition,JM as verticesOfEdge,KM as verticesOfFace,eZ as voxelBoolean,hZ as voxelBooleanField,SZ as voxelBooleanFieldShapes,rZ as voxelBooleanShapes,mZ as voxelField,xZ as voxelFieldFromShape,LP as walkAssembly,BX as windingNumbers,mP as wire,II as wireFinder,hP as wireLoop,qM as wiresOfFace,vT as withKernel,vQ as withKernelDir,_Q as withKernelPnt,gQ as withKernelVec,bT as withQuality,VT as withScope,WT as withScopeResult,GT as withScopeResultAsync,wT as withTier,Ka as zipResults};
59
+ </Relationships>`),c(`3D/3dmodel.model`,s)])}function NY(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 PY(e){return[e[0],-e[1]]}function FY(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(nL(PY([t.cx,t.cy]),PY([a,o]))),t.cx=a,t.cy=o,i+=2}}function IY(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(nL(PY([t.cx,t.cy]),PY([a,o]))),t.cx=a,t.cy=o,i+=2}}function LY(e,t,n,r){for(let i of e){let e=n?t.cx+i:i;r.push(nL(PY([t.cx,t.cy]),PY([e,t.cy]))),t.cx=e}}function RY(e,t,n,r){for(let i of e){let e=n?t.cy+i:i;r.push(nL(PY([t.cx,t.cy]),PY([t.cx,e]))),t.cy=e}}function zY(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(cL(PY([t.cx,t.cy]),[PY([s,c]),PY([l,u])],PY([d,f]))),t.prevControlX=l,t.prevControlY=u,t.cx=d,t.cy=f,i+=6}}function BY(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(cL(PY([t.cx,t.cy]),[PY([c,l]),PY([u,d])],PY([f,p]))),t.prevControlX=u,t.prevControlY=d,t.cx=f,t.cy=p,t.lastCmd=`S`,i+=4}}function VY(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(cL(PY([t.cx,t.cy]),[PY([s,c])],PY([l,u]))),t.prevControlX=s,t.prevControlY=c,t.cx=l,t.cy=u,i+=4}}function HY(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(cL(PY([t.cx,t.cy]),[PY([c,l])],PY([u,d]))),t.prevControlX=c,t.prevControlY=l,t.cx=u,t.cy=d,t.lastCmd=`T`,i+=2}}function UY(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[rL(PY([e,t]),PY(c),PY([e,s])),rL(PY([e,s]),PY(l),PY([e,t]))]}catch{return[]}}function WY(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[rL(PY([e,t]),PY([b,x]),PY([n,r]))]}catch{return[nL(PY([e,t]),PY([n,r]))]}}function GY(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(nL(PY([t.cx,t.cy]),PY([d,f])));else{let e=d-t.cx,n=f-t.cy;Math.sqrt(e*e+n*n)<1e-10?r.push(...UY(t.cx,t.cy,s,c,u)):r.push(...WY(t.cx,t.cy,d,f,s,c,l,u))}t.cx=d,t.cy=f,i+=7}}function KY(e,t){(Math.abs(e.cx-e.sx)>1e-10||Math.abs(e.cy-e.sy)>1e-10)&&t.push(nL(PY([e.cx,e.cy]),PY([e.sx,e.sy]))),e.cx=e.sx,e.cy=e.sy}function qY(e){let t=NY(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`:FY(i,r,t,n);break;case`L`:IY(i,r,t,n);break;case`H`:LY(i,r,t,n);break;case`V`:RY(i,r,t,n);break;case`C`:zY(i,r,t,n);break;case`S`:BY(i,r,t,n);break;case`Q`:VY(i,r,t,n);break;case`T`:HY(i,r,t,n);break;case`A`:GY(i,r,t,n);break;case`Z`:KY(r,n);break}a!==`S`&&a!==`T`&&(r.lastCmd=a)}return n}function JY(e){try{let t=qY(e);return t.length===0?k(vo(`SVG_EMPTY_PATH`,`SVG path produced no curves`)):O(new EL(t))}catch(e){return k(vo(`SVG_PARSE_FAILED`,`Failed to parse SVG path: ${e instanceof Error?e.message:String(e)}`))}}function YY(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=JY(l);u.ok&&n.push(u.value)}return n.length===0?k(vo(`SVG_NO_PATHS`,`No <path> elements found in SVG`)):O(n)}catch(e){return k(vo(`SVG_IMPORT_FAILED`,`Failed to import SVG: ${e instanceof Error?e.message:String(e)}`))}}function XY(e,t){try{let n=U(),r=e.map(e=>({shape:e.shape.wrapped,name:e.name,color:e.color?[...e.color]:void 0}));return O(n.exportSTEPConfigured(r,t))}catch(e){return k(vo(N.STEP_EXPORT_CONFIGURED_FAILED,`Configured STEP export failed`,e))}}async function ZY(e){try{let t=await e.arrayBuffer(),n=U().importSTEP(t);return n.length===0?k(vo(`STEP_IMPORT_FAILED`,`STEP file contains no valid geometry`)):O(ME(n[0]))}catch(e){return k(vo(`STEP_IMPORT_FAILED`,`Failed to load STEP file`,e))}}async function QY(e){try{let t=await e.arrayBuffer(),n=U().importSTL(t);return n.IsNull()?k(vo(`STL_IMPORT_FAILED`,`Failed to create solid from STL mesh`)):O(ME(n))}catch(e){return k(vo(`STL_IMPORT_FAILED`,`Failed to load STL file`,e))}}async function $Y(e){try{let t=await e.arrayBuffer(),n=U().importIGES(t);return n.length===0?k(vo(`IGES_IMPORT_FAILED`,`IGES file contains no valid geometry`)):O(ME(n[0]))}catch(e){return k(vo(`IGES_IMPORT_FAILED`,`Failed to load IGES file`,e))}}function eX(e,t,n={}){let r=iq(e,t);return new $K((typeof n.plane==`string`||n.plane===void 0?r.sketchOnPlane(n.plane,n.origin):r.sketchOnPlane(n.plane)).map(e=>Array.isArray(e)?new IK(e.map(LK)):LK(e)))}function tX(e,t){let n=t?.fontSize??1,r=nq(t?.fontFamily);if(!r)return k(F(N.NO_FONT_LOADED,`No font loaded. Call loadFont() first.`,void 0,void 0,`Load a font with loadFont() before calling textMetrics()`));let i=r.getAdvanceWidth(e,n),a=n/r.unitsPerEm,o=r.ascender*a,s=r.descender*a;return O({width:i,height:o-s,ascender:o,descender:s})}function nX(e){let t=e?.fontSize??1,n=nq(e?.fontFamily);if(!n)return k(F(N.NO_FONT_LOADED,`No font loaded. Call loadFont() first.`,void 0,void 0,`Load a font with loadFont() before calling fontMetrics()`));let r=t/n.unitsPerEm,i=n.ascender*r,a=n.descender*r,o=(n.tables?.os2?.sTypoLineGap??0)*r;return O({ascender:i,descender:a,unitsPerEm:n.unitsPerEm,lineHeight:i-a+o})}function rX(e){return e.type===`init`}function iX(e){return e.type===`operation`}function aX(e){return e.type===`dispose`}function oX(e){return e.type===`batch`}function sX(e){return e.success}function cX(e){return!e.success}function lX(){return{pending:new Map}}function uX(e,t){let n=new Map(e.pending);return n.set(t.id,t),{pending:n}}function dX(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 fX(e){return e.pending.size}function pX(e){return e.pending.size===0}function mX(e,t){for(let n of e.pending.values())n.reject(t);return{pending:new Map}}function hX(e,t){let n=t.data,r=e.get(n.id);if(r)if(e.delete(n.id),sX(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 gX(e){let{worker:t,wasmUrl:n}=e,r=new Map,i=!1;function a(){return crypto.randomUUID()}function o(e){hX(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 _X(){return{operations:new Map}}function vX(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function yX(e){return e instanceof Error?e.message:String(e)}function bX(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:yX(e)}}}function xX(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 SX(e,t){let n=globalThis;n.onmessage=async r=>{let i=r.data;if(rX(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:yX(e)};n.postMessage(t)}return}if(iX(i)){let t=bX(e,i.operation,i.shapesBrep,i.parameters);n.postMessage(xX(i.id,t));return}if(oX(i)){let t=i.operations.map(t=>bX(e,t.operation,t.shapesBrep,t.params)),r={id:i.id,success:!0,resultData:t};n.postMessage(r);return}if(aX(i)){let e={id:i.id,success:!0};n.postMessage(e),n.close?.()}}}function CX(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:gX({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 wX=Object.defineProperty,TX=(e,t)=>{let n={};for(var r in e)wX(n,r,{get:e[r],enumerable:!0});return t||wX(n,Symbol.toStringTag,{value:`Module`}),n},EX=1,DX=2;function OX(e,t){t===`commonFace`&&e.SetGlue(EX),t===`sameFace`&&e.SetGlue(DX)}function kX(e){return typeof e==`number`}function AX(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 jX(e){return typeof e==`number`?!0:Array.isArray(e)&&e.length===2?e.every(kX):!1}function MX(e,t){let n=n=>{let r=e.findAll(n);if(r.length===0)return[];let i=0,a=MD(_D(cA(r)),t);for(let e=1;e<r.length;e++){let n=MD(_D(sA(r,e)),t);n<a&&(a=n,i=e)}return[sA(r,i)]},r=e=>{let t=n(e);return t.length===0?k(yo(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found 0 element(s)`)):O(cA(t))};return{...e,findAll:n,findUnique:r}}function NX(e){return AI(`vertex`,e,NX,(t,n)=>({nearestTo:t=>MX(NX(e),t),atPosition:(e,t=1e-4)=>n(n=>MD(_D(n),e)<t),withinBox:(e,t)=>n(n=>{let r=_D(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=_D(n);return Math.abs(MD(i,t)-e)<r})}))}function PX(){return NX([])}var FX=new Map,IX=null,LX=null;function RX(e,t){FX.set(e,t),IX||=e,e===IX&&(LX=t)}function zX(e){if(!e&&LX)return LX;let t=e??IX;if(!t)throw Error(`brepjs voxel engine not initialized. Call initVoxel() (or registerVoxel()) before using voxel operations.`);let n=FX.get(t);if(!n)throw Error(`brepjs: voxel engine '${t}' is not registered.`);return n}function BX(){return IX}function VX(e,t=`voxel`){RX(t,e),IX=t,LX=e}function HX(e){if(e.vertices.length%3!=0)return F(`VOXEL_INVALID_MESH`,`mesh.vertices length must be a multiple of 3 (flat xyz).`);if(e.triangles.length%3!=0)return F(`VOXEL_INVALID_MESH`,`mesh.triangles length must be a multiple of 3.`);let t=e.vertices.length/3;for(let n=0;n<e.triangles.length;n++){let r=e.triangles[n];if(r===void 0||r>=t)return F(`VOXEL_INVALID_TRIANGLE_INDEX`,`triangle index ${r} at position ${n} is out of range for ${t} vertices.`)}return null}function UX(e,t){return HX(e)||(t.length%3==0?null:F(`VOXEL_INVALID_QUERIES`,`queries length must be a multiple of 3 (flat xyz).`))}function WX(e){try{return O(zX(e))}catch(e){return k(_o(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function GX(e,t,n){let r=UX(e,t);if(r)return k(r);let i=WX(n);return A(i)?i:O(i.value.winding_numbers(e.vertices,e.triangles,t))}function KX(e,t,n){let r=UX(e,t);if(r)return k(r);let i=WX(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 qX=48,JX=2;function YX(e,t,n){let r=HX(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`repairMesh requires a non-empty triangle mesh.`));let i=t?.resolution??qX,a=t?.padding??JX;if(!Number.isInteger(i)||i<1)return k(F(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`));if(!Number.isInteger(a)||a<1)return k(F(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`));let o=WX(n);if(A(o))return o;try{try{var s=OT();let t=s.u(o.value.repair_mesh(e.vertices,e.triangles,i,a)),n=t.positions.length/3;return O({vertices:t.positions,normals:t.normals,triangles:t.indices,uvs:new Float32Array(n*2),faceGroups:[{start:0,count:t.indices.length/3,faceHash:0}]})}catch(e){s.e=e}finally{s.d()}}catch(e){return k(I(`VOXEL_REPAIR_FAILED`,e instanceof Error?e.message:`voxel repair failed (grid too large?).`,e))}}var XX=.001;function ZX(e,t=XX){try{let n=Kk(e,{tolerance:t});return n.vertices.length===0||n.triangles.length===0?k(I(`VOXEL_SHAPE_MESH_EMPTY`,`shape tessellated to an empty triangle mesh.`)):O({vertices:n.vertices,triangles:n.triangles})}catch(e){return k(I(`VOXEL_SHAPE_MESH_FAILED`,e instanceof Error?e.message:`failed to mesh shape for voxel op.`,e))}}var QX=48,$X=2,eZ={union:0,intersection:1,difference:2};function tZ(e){let t=e?.resolution??QX,n=e?.padding??$X;return!Number.isInteger(t)||t<1?k(F(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(F(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function nZ(e){if(e.positions.length===0||e.indices.length===0)return k(I(`VOXEL_DEGENERATE_RESULT`,`the voxel operation produced an empty mesh (over-shrunk offset or disjoint operands?).`));let t=e.positions.length/3;return O({vertices:e.positions,normals:e.normals,triangles:e.indices,uvs:new Float32Array(t*2),faceGroups:[{start:0,count:e.indices.length/3,faceHash:0}]})}function rZ(e,t,n,r){let i=HX(e);if(i)return k(i);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`offsetMesh requires a non-empty triangle mesh.`));if(!Number.isFinite(t))return k(F(`VOXEL_INVALID_DISTANCE`,`distance must be a finite number.`));let a=tZ(n);if(A(a))return a;let o=WX(r);if(A(o))return o;try{try{var s=OT();return nZ(s.u(o.value.offset_mesh(e.vertices,e.triangles,t,a.value.resolution,a.value.padding)))}catch(e){s.e=e}finally{s.d()}}catch(e){return k(I(`VOXEL_OFFSET_FAILED`,e instanceof Error?e.message:`voxel offset failed (grid too large?).`,e))}}function iZ(e,t,n,r){let i=HX(e);if(i)return k(i);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`shellMesh requires a non-empty triangle mesh.`));if(!Number.isFinite(t)||t<=0)return k(F(`VOXEL_INVALID_THICKNESS`,`thickness must be a finite number > 0.`));let a=tZ(n);if(A(a))return a;let o=WX(r);if(A(o))return o;try{try{var s=OT();return nZ(s.u(o.value.shell_mesh(e.vertices,e.triangles,t,a.value.resolution,a.value.padding)))}catch(e){s.e=e}finally{s.d()}}catch(e){return k(I(`VOXEL_SHELL_FAILED`,e instanceof Error?e.message:`voxel shell failed (grid too large?).`,e))}}function aZ(e,t,n,r,i){let a=HX(e);if(a)return k(a);let o=HX(t);if(o)return k(o);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBoolean requires a non-empty mesh for operand A.`));if(t.vertices.length===0||t.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBoolean requires a non-empty mesh for operand B.`));let s=eZ[n],c=tZ(r);if(A(c))return c;let l=WX(i);if(A(l))return l;try{try{var u=OT();return nZ(u.u(l.value.voxel_boolean(e.vertices,e.triangles,t.vertices,t.triangles,s,c.value.resolution,c.value.padding)))}catch(e){u.e=e}finally{u.d()}}catch(e){return k(I(`VOXEL_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel boolean failed (grid too large?).`,e))}}function oZ(e,t,n,r){let i=ZX(e);return A(i)?i:rZ(i.value,t,n,r)}function sZ(e,t,n,r){let i=ZX(e);return A(i)?i:iZ(i.value,t,n,r)}function cZ(e,t,n,r,i){let a=ZX(e);if(A(a))return a;let o=ZX(t);return A(o)?o:aZ(a.value,o.value,n,r,i)}var lZ=48,uZ=2,dZ={union:0,intersection:1,difference:2};function fZ(e){let t=e?.resolution??lZ,n=e?.padding??uZ;return!Number.isInteger(t)||t<1?k(F(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(F(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function pZ(e){try{var t=OT();let n=e.contour(),{positions:r,normals:i,indices:a}=t.u({value:n,[Symbol.dispose](){n.free()}}).value;if(r.length===0||a.length===0)return k(I(`VOXEL_DEGENERATE_RESULT`,`the voxel field contoured to an empty mesh (over-shrunk offset or disjoint operands?).`));let o=r.length/3;return O({vertices:r,normals:i,triangles:a,uvs:new Float32Array(o*2),faceGroups:[{start:0,count:a.length/3,faceHash:0}]})}catch(e){t.e=e}finally{t.d()}}function mZ(e){return{raw:e,delete(){e.free()}}}function hZ(e){return gZ(e)}function gZ(e){let t=BT(mZ(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,dZ[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=pZ(this.value);if(A(e))throw Error(e.error.message);return e.value}};return n}function _Z(e){return!e.disposed}function vZ(){return k(F(`VOXEL_FIELD_DISPOSED`,`the voxel field handle has been disposed.`))}function yZ(e,t,n){let r=HX(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelField requires a non-empty triangle mesh.`));let i=fZ(t);if(A(i))return i;let a=WX(n);if(A(a))return a;try{return O(gZ(new a.value.VoxelField(e.vertices,e.triangles,i.value.resolution,i.value.padding)))}catch(e){return k(I(`VOXEL_FIELD_VOXELIZE_FAILED`,e instanceof Error?e.message:`voxel field voxelization failed (grid too large or non-dense?).`,e))}}function bZ(e,t,n,r,i){let a=HX(e);if(a)return k(a);let o=HX(t);if(o)return k(o);if(e.vertices.length===0||e.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBooleanField requires a non-empty mesh for operand A.`));if(t.vertices.length===0||t.triangles.length===0)return k(F(`VOXEL_EMPTY_MESH`,`voxelBooleanField requires a non-empty mesh for operand B.`));let s=fZ(r);if(A(s))return s;let c=WX(i);if(A(c))return c;try{return O(gZ(c.value.VoxelField.boolean_of(e.vertices,e.triangles,t.vertices,t.triangles,dZ[n],s.value.resolution,s.value.padding)))}catch(e){return k(I(`VOXEL_FIELD_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel field boolean failed (grid too large or non-dense?).`,e))}}function xZ(e,t,n){if(!_Z(e)||!_Z(t))return vZ();try{return e.value.boolean(t.value,dZ[n]),O(e)}catch(e){return k(I(`VOXEL_FIELD_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel field boolean failed (dim mismatch?).`,e))}}function SZ(e,t){if(!_Z(e))return vZ();if(!Number.isFinite(t))return k(F(`VOXEL_INVALID_DISTANCE`,`distance must be a finite number.`));try{return e.value.offset(t),O(e)}catch(e){return k(I(`VOXEL_FIELD_OFFSET_FAILED`,e instanceof Error?e.message:`voxel field offset failed.`,e))}}function CZ(e,t){if(!_Z(e))return vZ();if(!Number.isFinite(t)||t<=0)return k(F(`VOXEL_INVALID_THICKNESS`,`thickness must be a finite number > 0.`));try{return e.value.shell(t),O(e)}catch(e){return k(I(`VOXEL_FIELD_SHELL_FAILED`,e instanceof Error?e.message:`voxel field shell failed.`,e))}}function wZ(e){if(!_Z(e))return vZ();try{return e.value.reinit(),O(e)}catch(e){return k(I(`VOXEL_FIELD_REINIT_FAILED`,e instanceof Error?e.message:`voxel field reinit failed.`,e))}}function TZ(e){if(!_Z(e))return vZ();try{return pZ(e.value)}catch(e){return k(I(`VOXEL_FIELD_CONTOUR_FAILED`,e instanceof Error?e.message:`voxel field contour failed.`,e))}}function EZ(e,t,n){let r=ZX(e);return A(r)?r:yZ(r.value,t,n)}function DZ(e,t,n,r,i){let a=ZX(e);if(A(a))return a;let o=ZX(t);return A(o)?o:bZ(a.value,o.value,n,r,i)}var OZ=48,kZ=2;function AZ(e){try{return O(zX(e))}catch(e){return k(_o(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function jZ(e){let t=e?.resolution??OZ,n=e?.padding??kZ;return!Number.isInteger(t)||t<1?k(F(`SDF_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(F(`SDF_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function MZ(e){return{raw:e,delete(){e.free()}}}var NZ={offsetField(e){return PZ(this.value.offset_field(e.value))},roundField(e){return PZ(this.value.round_field(e.value))},shellField(e){return PZ(this.value.shell_field(e.value))},smoothUnionField(e,t){return PZ(this.value.smooth_union_field(e.value,t.value))}};function PZ(e){let t=BT(MZ(e));return{get value(){return t.value.raw},get disposed(){return t.disposed},[Symbol.dispose](){t[Symbol.dispose]()},union(e){return PZ(this.value.union(e.value))},intersection(e){return PZ(this.value.intersection(e.value))},difference(e){return PZ(this.value.difference(e.value))},smoothUnion(e,t){return PZ(this.value.smooth_union(e.value,t))},smoothIntersection(e,t){return PZ(this.value.smooth_intersection(e.value,t))},smoothDifference(e,t){return PZ(this.value.smooth_difference(e.value,t))},offset(e){return PZ(this.value.offset(e))},round(e){return PZ(this.value.round(e))},shell(e){return PZ(this.value.shell(e))},onion(e){return PZ(this.value.onion(e))},...NZ,translate(e,t,n){return PZ(this.value.translate(e,t,n))},rotate(e,t,n,r){return PZ(this.value.rotate(e,t,n,r))},scale(e){return PZ(this.value.scale(e))},rasterize(e){return FZ(this.value,e)},rasterizeIn(e,t){return IZ(this.value,e,t)}}}function FZ(e,t){let n=jZ(t);if(A(n))return n;try{return O(hZ(e.rasterize(n.value.resolution,n.value.padding)))}catch(e){return LZ(e)}}function IZ(e,t,n){let r=jZ(n);if(A(r))return r;let i=RZ(t);if(i)return k(i);try{return O(hZ(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 LZ(e)}}function LZ(e){return k(I(`SDF_RASTERIZE_FAILED`,e instanceof Error?e.message:`SDF rasterization failed (grid too large?).`,e))}function RZ(e){if(![...e.min,...e.max].every(e=>Number.isFinite(e)))return F(`SDF_INVALID_BOUNDS`,`bounds must be finite numbers.`);for(let t=0;t<3;t++)if(e.max[t]<=e.min[t])return F(`SDF_INVALID_BOUNDS`,`bounds max must exceed min on every axis.`);return null}function zZ(e,t){let n=AZ(t);if(A(n))return n;try{return O(PZ(e(n.value)))}catch(e){return k(I(`SDF_BUILD_FAILED`,e instanceof Error?e.message:`SDF primitive construction failed.`,e))}}function BZ(e,t){return zZ(t=>t.Sdf.sphere(e),t)}function VZ(e,t,n,r){return zZ(r=>r.Sdf.box_(e,t,n),r)}function HZ(e,t,n,r,i){return zZ(i=>i.Sdf.rounded_box(e,t,n,r),i)}function UZ(e,t,n){return zZ(n=>n.Sdf.cylinder(e,t),n)}function WZ(e,t,n){return zZ(n=>n.Sdf.cone(e,t),n)}function GZ(e,t,n,r){return zZ(r=>r.Sdf.capsule(e[0],e[1],e[2],t[0],t[1],t[2],n),r)}function KZ(e,t,n){return zZ(n=>n.Sdf.torus(e,t),n)}function qZ(e,t,n){return zZ(n=>n.Sdf.plane(e[0],e[1],e[2],t),n)}function JZ(e){if(e.length<2)return k(F(`SDF_INVALID_SPINE`,`sweep spine needs at least 2 points.`));let t=new Float64Array(e.length*3);for(let n=0;n<e.length;n++){let r=e[n];if(!r.every(e=>Number.isFinite(e)))return k(F(`SDF_INVALID_SPINE`,`sweep spine coordinates must be finite.`));t[n*3]=r[0],t[n*3+1]=r[1],t[n*3+2]=r[2]}return O(t)}function YZ(e,t,n,r){let i=JZ(e);if(A(i))return i;let a=n?.closed??!1;return zZ(e=>e.Sdf.sweep(i.value,t.value,a),r)}var XZ={gyroid:0,schwarzP:1,diamond:2};function ZZ(e,t,n,r){let i=XZ[e];return i===void 0?k(F(`SDF_INVALID_LATTICE_KIND`,`unknown lattice kind: ${e}`)):zZ(e=>e.Sdf.lattice(i,t.value,n.value),r)}function QZ(e,t,n){return zZ(n=>n.Sdf.strut_lattice(e,t.value),n)}function $Z(e){return{raw:e,delete(){e.free()}}}function eQ(e){let t=BT($Z(e));return{get value(){return t.value.raw},get disposed(){return t.disposed},[Symbol.dispose](){t[Symbol.dispose]()}}}function tQ(e,t){let n=AZ(t);if(A(n))return n;try{return O(eQ(e(n.value)))}catch(e){return k(I(`SDF_FIELD_BUILD_FAILED`,e instanceof Error?e.message:`scalar field construction failed.`,e))}}function nQ(e,t){return tQ(t=>t.ScalarField.constant(e),t)}function rQ(e,t,n,r,i,a){return tQ(a=>a.ScalarField.axial_ramp(e,t,n,r,i),a)}function iQ(e,t,n,r,i,a,o){return tQ(o=>o.ScalarField.radial_ramp(e[0],e[1],e[2],t,n,r,i,a),o)}function aQ(e,t,n,r){return tQ(r=>r.ScalarField.from_sdf(e.value,t,n),r)}function oQ(e,t,n,r){return tQ(r=>r.ScalarField.clamp(e.value,t,n),r)}var sQ={gyroid:0,schwarzP:1,diamond:2},cQ=48,lQ=2;function uQ(e){let t=sQ[e.type];if(t===void 0)return k(F(`LATTICE_INVALID_TYPE`,`lattice type must be one of gyroid, schwarzP, diamond (got '${e.type}').`));if(!(e.period>0))return k(F(`LATTICE_INVALID_PERIOD`,`period must be > 0.`));if(!(e.thickness>0))return k(F(`LATTICE_INVALID_THICKNESS`,`thickness must be > 0.`));let n=e.resolution??cQ,r=e.padding??lQ;return!Number.isInteger(n)||n<1?k(F(`LATTICE_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(r)||r<1?k(F(`LATTICE_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({tag:t,period:e.period,thickness:e.thickness,resolution:n,padding:r})}function dQ(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 fQ(e,t,n){let r=HX(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(F(`LATTICE_EMPTY_MESH`,`latticeInfill requires a non-empty triangle mesh.`));let i=uQ(t);if(A(i))return i;let a=WX(n);if(A(a))return a;let{tag:o,period:s,thickness:c,resolution:l,padding:u}=i.value;try{try{var d=OT();return O(dQ(d.u(a.value.lattice_infill(e.vertices,e.triangles,l,u,o,s,c))))}catch(e){d.e=e}finally{d.d()}}catch(e){return k(I(`LATTICE_INFILL_FAILED`,e instanceof Error?e.message:`lattice infill failed (grid too large?).`,e))}}function pQ(e,t,n){let r=ZX(e);return A(r)?r:fQ(r.value,t,n)}function mQ(e,t,n){for(let t=0;t<3;t++){let n=e.min[t],r=e.max[t];if(n===void 0||r===void 0||!(n<r))return k(F(`LATTICE_INVALID_BOUNDS`,`bounds.min must be strictly less than bounds.max on every axis (axis ${t}).`))}let r=uQ(t);if(A(r))return r;let i=WX(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=OT();return O(dQ(g.u(i.value.tpms_box(u,d,f,p,m,h,c,l,a,o,s))))}catch(e){g.e=e}finally{g.d()}}catch(e){return k(I(`TPMS_LATTICE_FAILED`,e instanceof Error?e.message:`tpms lattice failed (grid too large?).`,e))}}function hQ(e){return U().createVector3d(e[0],e[1],e[2])}function gQ(e){return U().createPoint3d(e[0],e[1],e[2])}function _Q(e){return U().createDirection3d(e[0],e[1],e[2])}function vQ(e){return[e.X(),e.Y(),e.Z()]}function yQ(e){return[e.X(),e.Y(),e.Z()]}function bQ(e){return[e.X(),e.Y(),e.Z()]}function xQ(e,t){let n=hQ(e);try{return t(n)}finally{n.delete()}}function SQ(e,t){let n=gQ(e);try{return t(n)}finally{n.delete()}}function CQ(e,t){let n=_Q(e);try{return t(n)}finally{n.delete()}}var wQ=.299,TQ=.587,EQ=.114;function DQ(e,t={}){if(e.length<2)return k(F(N.SURFACE_GRID_TOO_SMALL,`surfaceFromGrid: need at least 2 rows, got ${e.length}`));let n=e.length,r=e[0]?.length??0;if(r<2)return k(F(N.SURFACE_GRID_TOO_SMALL,`surfaceFromGrid: need at least 2 columns, got ${r}`));for(let t=0;t<n;t++){let n=e[t];if(!n||n.length!==r)return k(F(N.SURFACE_GRID_JAGGED,`surfaceFromGrid: row ${t} has ${n?.length??0} columns, expected ${r}`))}let{width:i=r-1,depth:a=n-1,scaleZ:o=1}=t,s=i/(r-1),c=a/(n-1);try{return OQ(e,n,r,s,c,o)}catch{}try{return kQ(e,n,r,s,c,o)}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.SURFACE_FAILED,`surfaceFromGrid failed: ${t}`,e))}}function OQ(e,t,n,r,i,a){let o=[];for(let s=0;s<t;s++)for(let t=0;t<n;t++){let n=e[s],c=(n?n[t]??0:0)*a;o.push([t*r,s*i,c])}let s=W(U().bsplineSurface(o,t,n));return EE(s)?O(s):(IE(s),k(P(N.SURFACE_FAILED,`B-spline surface did not produce a face`)))}function kQ(e,t,n,r,i,a){let o=[];for(let s=0;s<t;s++)for(let t=0;t<n;t++){let n=e[s],c=(n?n[t]??0:0)*a;o.push([t*r,s*i,c])}let s=W(U().triangulatedSurface(o,t,n));return EE(s)||DE(s)?O(s):(IE(s),k(P(N.SURFACE_FAILED,`surfaceFromGrid: unexpected shape type from sewing`)))}async function AQ(e,t={}){let n=t.channel??`luminance`,r=Math.max(1,Math.round(t.downsample??1));if(typeof createImageBitmap!=`function`)return k(vo(N.SURFACE_FAILED,`surfaceFromImage requires createImageBitmap (not available in this environment)`));let i;try{i=await createImageBitmap(e)}catch(e){return k(vo(N.SURFACE_FAILED,`surfaceFromImage: failed to decode image — ${e instanceof Error?e.message:String(e)}`))}let a=i.width,o=i.height;if(a<2||o<2)return i.close(),k(F(N.SURFACE_GRID_TOO_SMALL,`surfaceFromImage: image too small (${a}x${o}), need at least 2x2`));if(typeof OffscreenCanvas!=`function`)return i.close(),k(vo(N.SURFACE_FAILED,`surfaceFromImage requires OffscreenCanvas (not available in this environment)`));let s=new OffscreenCanvas(a,o).getContext(`2d`);if(!s)return i.close(),k(vo(N.SURFACE_FAILED,`surfaceFromImage: could not get 2D canvas context`));s.drawImage(i,0,0),i.close();let c=s.getImageData(0,0,a,o).data,l=[];for(let e=0;e<o;e+=r){let t=[];for(let i=0;i<a;i+=r){let r=(e*a+i)*4,o=c[r]??0,s=c[r+1]??0,l=c[r+2]??0,u;switch(n){case`r`:u=o/255;break;case`g`:u=s/255;break;case`b`:u=l/255;break;default:u=(wQ*o+TQ*s+EQ*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),DQ(l,u)}function jQ(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function MQ(e,t={}){if(e.length===0)return k(F(N.HULL_EMPTY_INPUT,`hull: at least one shape is required`,void 0,void 0,`Provide one or more shapes to compute a convex hull`));for(let[t,n]of e.entries()){let e=jQ(n,`hull: shapes[${t}]`);if(A(e))return e}let n=t.tolerance??.1;try{let t=U(),r=e.map(e=>e.wrapped),i=W(t.hull(r,n));return OE(i)?O(i):(IE(i),k(P(N.HULL_NOT_3D,`Hull result is not a solid; input may be degenerate`)))}catch(e){let t=e instanceof Error?e.message:String(e);return t.includes(`coplanar`)||t.includes(`fewer than`)||t.includes(`degenerate`)?k(P(N.HULL_DEGENERATE,`Hull degenerate: ${t}`,e)):k(P(N.HULL_FAILED,`Hull operation failed: ${t}`,e))}}function NQ(e){if(e.length<4)return k(F(N.HULL_EMPTY_INPUT,`convexHull: at least 4 points required, got ${e.length}`,void 0,void 0,`Provide 4 or more non-coplanar 3D points`));try{let t=U(),n=e.map(e=>({x:e[0],y:e[1],z:e[2]})),r=W(t.hullFromPoints(n,.1));return OE(r)?O(r):(IE(r),k(P(N.HULL_NOT_3D,`convexHull result is not a solid; points may be coplanar`)))}catch(e){let t=e instanceof Error?e.message:String(e);return t.includes(`coplanar`)||t.includes(`fewer than`)||t.includes(`degenerate`)?k(P(N.HULL_DEGENERATE,`convexHull degenerate: ${t}`,e)):k(P(N.HULL_FAILED,`convexHull failed: ${t}`,e))}}function PQ(e){let n=$E(e);if(n.length!==1)return null;let r=t(n,0);if(mD(r)!==`sphere`)return null;let i=U().area(r.wrapped);return Math.sqrt(i/(4*Math.PI))}function FQ(e,t,n){try{let r=W(U().offset(e.wrapped,t,n));return AE(r)?O(r):(IE(r),k(ho(N.MINKOWSKI_NOT_3D,`Minkowski sphere offset did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.MINKOWSKI_FAILED,`Minkowski sphere offset failed: ${t}`,e,{operation:`minkowski`,fastPath:`sphere`}))}}function IQ(e,t,n){let r=U();try{let i=tD(e),a=tD(t);if(i.length===0||a.length===0)return k(P(N.MINKOWSKI_FAILED,`Minkowski sum: one or both shapes have no vertices`,void 0,{operation:`minkowski`}));let o=[];for(let e of i){let[t,n,i]=r.vertexPosition(e.wrapped);for(let e of a){let[a,s,c]=r.vertexPosition(e.wrapped);o.push({x:t+a,y:n+s,z:i+c})}}let s=W(r.hullFromPoints(o,n));return AE(s)?O(s):(IE(s),k(ho(N.MINKOWSKI_NOT_3D,`Minkowski hull did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.MINKOWSKI_FAILED,`Minkowski general path failed: ${t}`,e,{operation:`minkowski`}))}}function LQ(e,t,n={}){let{tolerance:r=1e-6}=n;if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`minkowski: shape is a null shape`));if(U().isNull(t.wrapped))return k(F(N.MINKOWSKI_NULL_TOOL,`minkowski: tool is a null shape`));if(!AE(e)||!AE(t))return k(F(N.MINKOWSKI_NOT_3D,`minkowski: both shape and tool must be 3D`));let i=PQ(t);return i===null?IQ(e,t,r):FQ(e,i,r)}function RQ(e,t,n={}){let{tolerance:r=1e-6}=n;if(e.length<4)return k(F(N.POLYHEDRON_INSUFFICIENT_POINTS,`polyhedron: need at least 4 points, got ${e.length}`));if(t.length<4)return k(F(N.POLYHEDRON_INSUFFICIENT_FACES,`polyhedron: need at least 4 faces, got ${t.length}`));let i=[];for(let[n,r]of t.entries()){for(let t of r)if(t<0||t>=e.length)return k(F(N.POLYHEDRON_INVALID_INDEX,`polyhedron: face ${n} has out-of-range index ${t} (${e.length} points)`));if(r.length<3)continue;let t=r[0];for(let e=1;e<r.length-1;e++)i.push([t,r[e],r[e+1]])}try{let t=U(),n=e.map(([e,t,n])=>({x:e,y:t,z:n})),a=W(t.buildSolidFromFaces(n,i,r));return OE(a)?O(a):(IE(a),k(P(N.POLYHEDRON_FAILED,`Polyhedron did not produce a solid`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.POLYHEDRON_FAILED,`Polyhedron failed: ${t}`,e))}}var zQ=1e-10;function BQ(e,t,n,r){return e*r-t*n}function VQ(e,t,n,r){return e*n+t*r}function HQ(e,t){return Math.sqrt(e*e+t*t)}function UQ(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 WQ(e){let t=0;for(let n=0;n<e.length;n++){let r=UQ(e,n),i=UQ(e,n+1);t+=r.x*i.y-i.x*r.y}return t<0?[...e].reverse():e}function GQ(e,t){let n=UQ(e,t-1),r=UQ(e,t),i=UQ(e,t+1),a=r.x-n.x,o=r.y-n.y,s=HQ(a,o),c=i.x-r.x,l=i.y-r.y,u=HQ(c,l);if(s<zQ||u<zQ)return{dx:0,dy:0};let d=-o/s,f=a/s,p=-l/u,m=c/u,h=d+p,g=f+m,_=HQ(h,g);if(_<zQ)return{dx:d,dy:f};h/=_,g/=_;let v=VQ(h,g,d,f),y=Math.abs(v)>zQ?1/v:1;return{dx:h*y,dy:g*y}}function KQ(e){return!e.prev||!e.next?!1:BQ(e.x-e.prev.x,e.y-e.prev.y,e.next.x-e.x,e.next.y-e.y)<-1e-10}function qQ(e){let t=e.map((t,n)=>{let r=GQ(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 JQ(e,t){let n=e;for(let e=0;e<t&&n;e++)n.active=!1,n=n.next}function YQ(e){let t=1,n=e.next;for(;n!==e&&(t++,n=n.next,!(t>1e4)););return t}function XQ(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)<zQ&&Math.abs(r)<zQ)return null;let o;if(o=Math.abs(n)>Math.abs(r)?i/n:a/r,o<zQ)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)>zQ){let e=c/s;if(Math.abs(o-e)>1e-4*Math.max(1,Math.abs(o)))return null}return o}function ZQ(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=HQ(r,i);if(a<zQ)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)<zQ)return null;let f=-c/d;if(f<zQ)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=HQ(y,b);if(x<zQ)return f;let S=VQ(p-h,m-g,y,b)/(x*x);return S<-.01||S>1.01?null:f}function QQ(e){let t=[];for(let n of e){if(!n.active||!n.next)continue;let e=XQ(n,n.next);if(e!==null&&e>zQ){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(KQ(n)){let e=n.next.next,r=0;for(;e!==n.prev&&e!==n&&r<1e3;){let i=ZQ(n,e,e.next);if(i!==null&&i>zQ){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 $Q(e){if(e.length<3)return O({nodes:[],faces:[]});try{return O(e$(e))}catch(e){return k(I(N.STRAIGHT_SKELETON_FAILED,e instanceof Error?e.message:String(e),e))}}function e$(e){let t=WQ(e),n=t.length,r=[],i=Array.from({length:n},()=>[]),a=qQ(t),o=0,s=n*n*2;for(;o<s;){o++;let e=a.find(e=>e.active);if(!e)break;let t=YQ(e);if(t<=3){if(t===3){let t=e,n=t.next,a=n.next,o=XQ(t,n),s=o!==null&&o>zQ?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 JQ(e,t);continue}let n=a.filter(e=>e.active),s=QQ(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=GQ(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=GQ(f(e),0);e.bx=p.dx,e.by=p.dy;let m=GQ(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=[UQ(t,e),UQ(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&&HQ(n.x-i.x,n.y-i.y)>zQ&&(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 t$(e){let t=QE(e).map(e=>{let t=Sk(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 n$(e){let t=[];for(let n=1;n<e-1;n++)t.push([0,n,n+1]);return t}function r$(e,t,n,r,i,a){return(n-e)*(a-t)-(r-t)*(i-e)}function i$(e,t,n,r,i,a,o,s){let c=r$(n,r,i,a,e,t),l=r$(i,a,o,s,e,t),u=r$(o,s,n,r,e,t);return!((c<0||l<0||u<0)&&(c>0||l>0||u>0))}function a$(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||r$(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$(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 o$(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=n$(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 s$(e,t){let n=(t?.angle??45)*vD,r=Math.tan(n);try{let t=t$(e);if(t.length<3)return k(P(N.ROOF_FAILED,`Wire must have at least 3 edges for roof generation`));let n=$Q(t);if(!n.ok)return n;let i=n.value;if(i.faces.length===0)return k(P(N.ROOF_FAILED,`Straight skeleton computation produced no faces`));let a=U(),o=o$(i,r,a);for(let[e,n,r]of a$(t)){let i=t[e],s=t[n],c=t[r];if(!i||!s||!c)continue;let l=[i.x,i.y,0],u=[s.x,s.y,0],d=[c.x,c.y,0],f=a.buildTriFace(l,d,u);f!==null&&o.push(f)}if(o.length===0)return k(P(N.ROOF_FAILED,`No valid triangular faces could be built`));try{let e=a.sewAndSolidify(o,1e-6),t=a.fixShape(e);return t!==e&&a.dispose(e),O(bE(t))}catch(e){try{let t=bE(a.sew(o,1e-6));return aE(t)?O(t):k(P(N.ROOF_FAILED,`Sew fallback produced invalid solid`,e))}catch(e){return k(P(N.ROOF_FAILED,`Failed to sew roof faces`,e))}}finally{for(let e of o)a.dispose(e)}}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.ROOF_FAILED,`Roof generation failed: ${t}`,e))}}function c$(e){return[[1,0,0,e[0]],[0,1,0,e[1]],[0,0,1,e[2]],[0,0,0,1]]}function l$(e){let t=e[0];return t!==void 0&&typeof t[0]==`number`}function u$(e,t,n){return{__instanced:!0,source:e,placements:t,grid:n,[Symbol.dispose](){e[Symbol.dispose]()}}}function d$(e){return typeof e==`object`&&!!e&&e.__instanced===!0}function f$(e,t){return u$(e,l$(t)?t.map(c$):t.map(e=>e.map(e=>[...e])))}function p$(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(c$([e*i,t*a,0]));return u$(e,o,{cols:n,rows:r,pitchX:i,pitchY:a})}function m$(e){return e.placements.length}function h$(e,t={}){let{source:n,placements:r,grid:i}=e;return r.length===0?k(F(`INSTANCE_EMPTY`,`materialize: instance has no placements`)):t.fuse?AE(n)?i?IP(n,[1,0,0],[0,1,0],i.cols,i.rows,i.pitchX,i.pitchY):g$(n,r,!0):k(F(`MATERIALIZE_NOT_3D`,`materialize({fuse:true}) requires a 3D source shape`)):g$(n,r,!1)}function g$(e,t,n){let r=[];for(let n of t){let t=uk(e,n);if(!t.ok){for(let e of r)e[Symbol.dispose]();return t}r.push(t.value)}let i=n?FA(r,{unsafe:!0}):O(ij(r));for(let e of r)(!i.ok||e!==i.value)&&e[Symbol.dispose]();return i}function _$(e,t){return{geometry:Kk(e.source,t),instances:e.placements}}var v$={coincident:3,concentric:4,distance:1,angle:1},y$=[1,0,0,0];function b$(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function x$(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function S$(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function C$(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 w$(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function T$(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function E$(e){return T$(C$(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function D$(e,t){let n=b$(YP(t.rotation,e.origin),t.position);return{type:e.type,origin:n,...e.normal?{normal:YP(t.rotation,e.normal)}:{},...e.direction?{direction:YP(t.rotation,e.direction)}:{}}}function O$(e,t,n){let r=e.normal??[0,0,1];return{position:w$(r,S$(r,x$(e.origin,t.origin))+n),rotation:y$}}function k$(e,t){let n=e.direction??[0,0,1],r=ZP(t.direction??[0,0,1],n),i=YP(r,t.origin);return{position:x$(e.origin,i),rotation:r}}function A$(e,t,n){let r=T$(e.normal??[0,0,1]),i=T$(t.normal??[0,0,1]),a=Math.acos(Math.max(-1,Math.min(1,S$(i,r)))),o=C$(i,r);return{position:[0,0,0],rotation:XP(Math.hypot(o[0],o[1],o[2])<1e-9?E$(i):o,a-n)}}function j$(e,t,n){let r=x$(t,e),i=Math.hypot(r[0],r[1],r[2]);return{position:x$(b$(e,w$(i<1e-9?[1,0,0]:w$(r,1/i),n)),t),rotation:y$}}function M$(e,t,n,r){let i=T$(e);return{position:w$(i,S$(i,x$(t,n))-r),rotation:y$}}function N$(e,t,n){let r=T$(e.direction??[0,0,1]),i=b$(e.origin,w$(r,S$(r,x$(t,e.origin))));if(n===0)return{position:x$(i,t),rotation:y$};let a=x$(t,i),o=Math.hypot(a[0],a[1],a[2]);return{position:x$(b$(i,w$(o<1e-9?E$(r):w$(a,1/o),n)),t),rotation:y$}}function P$(e,t,n){let r=T$(t.direction??[0,0,1]),i=x$(t.origin,e),a=x$(i,w$(r,S$(r,i))),o=Math.hypot(a[0],a[1],a[2]);return n===0?{position:w$(a,-1),rotation:y$}:{position:x$(w$(o<1e-9?E$(r):w$(a,1/o),n),a),rotation:y$}}function F$(e,t,n){let r=T$(e.direction??[0,0,1]),i=ZP(T$(t.direction??[0,0,1]),r),a=x$(YP(i,t.origin),e.origin),o=x$(a,w$(r,S$(r,a))),s=Math.hypot(o[0],o[1],o[2]);return{position:x$(w$(s<1e-9?E$(r):w$(o,1/s),n),o),rotation:i}}var I$=new Set([`plane-plane`,`plane-point`,`point-plane`,`point-point`,`axis-axis`,`axis-point`,`point-axis`]),L$={angle:`plane`,concentric:`axis`},R$=new Set([`coincident`,`distance`,`angle`,`concentric`]);function z$(e,t,n){let r=L$[e];return r?t===r&&n===r:I$.has(`${t}-${n}`)}function B$(e,t,n){switch(`${e.type}-${t.type}`){case`plane-plane`:case`plane-point`:return O$(e,t,n);case`point-plane`:return M$(t.normal??[0,0,1],e.origin,t.origin,n);case`point-point`:return j$(e.origin,t.origin,n);case`axis-axis`:return n===0?k$(e,t):F$(e,t,n);case`axis-point`:return N$(e,t.origin,n);case`point-axis`:return P$(e.origin,t,n);default:return null}}function V$(e,t,n){switch(e.type){case`concentric`:return k$(t,n);case`angle`:return A$(t,n,(e.value??0)*Math.PI/180);default:{let r=B$(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 H$(e,t){let n=new Map;for(let t of e)n.set(t,{position:[0,0,0],rotation:y$});let r=[],i=t.filter(e=>R$.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(!z$(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:y$},l=D$(r.entity,a);n.set(i.node,V$(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+(v$[t]??v$[t.split(`(`)[0]??``]??0),0),converged:r.length===0,unsupported:r}}function U$(e){if(e.face){let t=gO(e.face);return t?{type:`axis`,origin:t.origin,direction:t.direction}:{type:`plane`,origin:hO(e.face),normal:mO(e.face)}}if(e.edge){if(xk(e.edge)===`LINE`)return{type:`axis`,origin:Sk(e.edge),direction:Tk(e.edge)};let t=Dk(e.edge);return t?{type:`axis`,origin:t.origin,direction:t.direction}:null}return e.point?{type:`point`,origin:e.point}:null}function W$(e,t){let n=U$(e),r=U$(t);return!n||!r?k(F(N.ASSEMBLY_MATE_INVALID,`solveAssembly: could not extract geometry from mate entities`)):O({entityA:{node:e.node,entity:n},entityB:{node:t.node,entity:r}})}function G$(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=W$(e.entityA,e.entityB);return t.ok?O({type:`coincident`,...t.value}):t}case`distance`:{let t=W$(e.entityA,e.entityB);return t.ok?O({type:`distance`,...t.value,value:e.distance}):t}case`angle`:{let t=W$(e.entityA,e.entityB);return t.ok?O({type:`angle`,...t.value,value:e.angle}):t}case`concentric`:{let t=W$(e.axisA,e.axisB);return t.ok?O({type:`concentric`,...t.value}):t}}}function K$(e,t){let n=e.mates??[];return{...e,mates:[...n,t]}}function q$(e){let t=e.mates;if(!t||t.length===0)return k(F(N.ASSEMBLY_MATE_INVALID,`solveAssembly: no mates defined`));try{let n=[];HP(e,e=>{n.push(e.name)});let r=[];for(let e of t){let t=G$(e);if(!t.ok)return t;r.push(t.value)}let i=H$(n,r);if(!i.converged){let e=i.unsupported.length>0?`Unsupported constraint types: ${i.unsupported.join(`, `)} (${i.dof} DOF unresolved)`:`Assembly constraint solver did not converge`;return k(P(N.ASSEMBLY_NOT_CONVERGED,e))}return O({transforms:i.transforms,dof:i.dof,converged:i.converged})}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.ASSEMBLY_SOLVE_FAILED,`Assembly solve failed: ${t}`,e))}}function J$(e,t,n=1e-6){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`checkInterference: first shape is a null shape`));if(U().isNull(t.wrapped))return k(F(N.NULL_SHAPE_INPUT,`checkInterference: second shape is a null shape`));let r=U().distance(e.wrapped,t.wrapped);return O({hasInterference:r.value<=n,minDistance:r.value,pointOnShape1:r.point1,pointOnShape2:r.point2})}function Y$(e,n=1e-6){let r=[],i=e.map(e=>fD(e));return e.forEach((a,o)=>{for(let s=o+1;s<e.length;s++){if(X$(t(i,o),t(i,s),n))continue;let c=j(J$(a,t(e,s),n));c.hasInterference&&r.push({i:o,j:s,result:c})}}),r}function X$(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 Z$(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 Q$(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 $$(e){let{type:t,data:n}=e,r=U();if(t===`LINE`)return r.makeLineEdge([Q$(n,10),Q$(n,20),Q$(n,30)],[Q$(n,11),Q$(n,21),Q$(n,31)]);if(t===`CIRCLE`)return r.makeCircleEdge([Q$(n,10),Q$(n,20),Q$(n,30)],[0,0,1],Q$(n,40));if(t===`ARC`){let e=Q$(n,50)*Math.PI/180,t=Q$(n,51)*Math.PI/180;return r.makeCircleArc([Q$(n,10),Q$(n,20),Q$(n,30)],[0,0,1],Q$(n,40),e,t)}}async function e1(e,t){let n;try{n=await e.text()}catch(e){return k(vo(N.DXF_IMPORT_FAILED,`Failed to read DXF blob`,e))}let r=Z$(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=$$(e);t!==void 0&&a.push(t)}return a.length===0?O([]):O([_E(U().makeWire(a))])}catch(e){return k(vo(N.DXF_IMPORT_FAILED,`Failed to convert DXF entities to geometry`,e))}finally{for(let e of a)e.delete()}}function t1(e,t,n=1e-6){let r=U(),i=[];for(let[t,n,a]of e){let e=r.buildTriFace(t,n,a);e!==null&&i.push(e)}if(i.length===0)return k(vo(t,`No valid triangular faces could be built`));try{return O(ME(r.sewAndSolidify(i,n)))}catch{try{return O(ME(r.sew(i,n)))}catch(e){return k(vo(t,`Failed to sew triangular faces`,e))}}}function n1(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 r1(e){return e.split(/\s+/).slice(1).map(e=>parseInt(e.split(`/`)[0]??``,10)).filter(e=>!isNaN(e))}async function i1(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=n1(t);e&&n.push(e)}else if(t.startsWith(`f `)){let e=r1(t);e.length>=3&&r.push(e)}}if(n.length===0||r.length===0)return k(vo(N.OBJ_IMPORT_FAILED,`OBJ file contains no valid geometry`));try{return a1(n,r)}catch(e){let t=e instanceof Error?e.message:String(e);return k(vo(N.OBJ_IMPORT_FAILED,`OBJ import failed: ${t}`,e))}}function a1(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 t1(n,N.OBJ_IMPORT_FAILED)}function o1(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 s1(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95}function c1(e){let t={},n=0;for(;n<e.length;){let r=e.indexOf(`="`,n);if(r<0)break;let i=r;for(;i>0&&s1(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 l1(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 u1(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 d1(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 f1(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=c1(e.slice(r,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of l1(a,`color`)){let t=c1(e).color;t!==void 0&&l.push(d1(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=c1(e.slice(n,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of l1(a,`base`)){let t=c1(e).displaycolor;t===void 0?l.push([0,0,0,1]):l.push(d1(t))}t.set(c,l)}return t}function p1(e){let t=[],n=[],r=[],i=f1(e);for(let n of l1(e,`vertex`)){let e=c1(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=u1(e,`object`);if(s!==null){let e=s.indexOf(`>`);if(e>=0){let t=c1(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 l1(e,`triangle`)){let e=c1(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 m1(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 h1(e){let t=U(),n=e.vertices.map(([e,t,n])=>({x:e,y:t,z:n})),r=e.triangles;try{return O(ME(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 t1(t,N.THREEMF_IMPORT_FAILED)}}async function g1(e){try{let t=await e.arrayBuffer(),n=o1(new Uint8Array(t),`3D/3dmodel.model`);if(!n)return k(vo(N.THREEMF_IMPORT_FAILED,`3MF archive does not contain 3D/3dmodel.model (or uses unsupported compression)`));let r=p1(new TextDecoder().decode(n));if(r.vertices.length===0||r.triangles.length===0)return k(vo(N.THREEMF_IMPORT_FAILED,`3MF model contains no valid geometry`));let i=h1(r);if(i.ok){let e=m1(r.triangleColors);e!==null&&KO(i.value,e)}return i}catch(e){let t=e instanceof Error?e.message:String(e);return k(vo(N.THREEMF_IMPORT_FAILED,`3MF import failed: ${t}`,e))}}async function _1(e){try{let t=await e.arrayBuffer();return O(ME(U().importGLB(t)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(vo(N.GLB_IMPORT_FAILED,`Failed to import GLB: ${t}`,e))}}function $(e){return`__wrapped`in e?e.val:e}function v1(e){return $(e)}function y1(e,t){return nk($(e),t)}function b1(e,t,n){let r=n?.at;return rk($(e),t,r,n?.axis)}function x1(e,t){let n=t?.at;return ik($(e),t?.normal??[1,0,0],n)}function S1(e,t,n){return ak($(e),t,n?.center)}function C1(e){return mk($(e))}function w1(e,t){return uk($(e),t)}function T1(e,t){return pk($(e),t)}function E1(e,t){return fk($(e),t)}function D1(e,t,n){return jA($(e),$(t),{...n,unsafe:!0})}function O1(e,t,n){return MA($(e),$(t),{...n,unsafe:!0})}function k1(e,t){return FA(e.map(e=>$(e)),{...t,unsafe:!0})}function A1(e,t,n){return IA($(e),t.map(e=>$(e)),{...n,unsafe:!0})}function j1(e,t,n){return NA($(e),$(t),{...n,unsafe:!0})}function M1(e,t,n){return RA($(e),t,n)}function N1(e,t,n){return WA($(e),t,n)}function P1(e,t){return GA($(e),t)}function F1(e,t,n){return KA($(e),t,n)}function I1(e,t){if(e!==void 0)return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(II()).findAll(t)}function L1(e,t){return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(zI()).findAll(t)}function R1(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 z1(e,t,n){let r=$(e),i,a;return n===void 0?(i=void 0,a=t):(i=I1(t,r),a=n),Wj(r,i,a)}function B1(e,t,n){let r=$(e),i,a;n===void 0?(i=void 0,a=t):(i=I1(t,r),a=n);let o=R1(a);return o.mode===`distAngle`?dj(r,[...i??QE(r)],o.distance,o.angle):Gj(r,i,o.distance)}function V1(e,t,n,r){let i=$(e);return Kj(i,L1(t,i),n,r?.tolerance)}function H1(e,t,n){return qj($(e),t,n?.tolerance)}function U1(e,t){return Hj($(e),t)}function W1(e,t,n){let r=$(e);return Yj(r,L1(t,r),n.pullDirection,n.neutralPlane,n.angle)}function G1(e){return tM($(e))}function K1(e){return bk($(e))}function q1(e,t){return Kk($(e),t)}function J1(e,t){return qk($(e),t)}function Y1(e){return gD($(e))}function X1(e){return hk($(e))}function Z1(e){return iO(e)}function Q1(e){return Zj($(e))}function $1(e){return _k($(e))}function e0(e,t){return vM($(e),typeof t==`number`?[0,0,t]:t)}function t0(e,t){let n=t?.at??[0,0,0];return yM($(e),n,t?.axis??[0,0,1],t?.angle??2*Math.PI)}function n0(e,t){return xM(e.map(e=>$(e)),t)}function r0(e,n){if(n===void 0){let t=$E(e);if(t.length===0)return k(F(N.COMPOUND_NO_FACES,`compoundOps: shape has no faces`));let n=cA(t),r=hO(n)[2];for(let e=1;e<t.length;e++){let i=sA(t,e),a=hO(i)[2];a>r&&(n=i,r=a)}return O(n)}if(typeof n==`function`){let r=n(zI()).findAll(e);return r.length===0?k(yo(N.COMPOUND_FACE_NOT_FOUND,`compoundOps: face finder matched no faces`)):O(t(r,0))}return O(n)}function i0(e){return`sketchOnPlane`in e&&typeof e.sketchOnPlane==`function`?{wire:e.sketchOnPlane(`XY`).wire,owned:!0}:{wire:e,owned:!1}}function a0(e,t){let n=$(e),{at:r,radius:i,axis:a}=t,o=a??[0,0,1];if(i<=0)return k(F(`DRILL_INVALID_RADIUS`,`Drill radius must be positive`));if(FD(o))return k(F(`DRILL_ZERO_AXIS`,`Drill axis cannot be zero`));let s=ND(o),c=r.length===2?[r[0],r[1],0]:[r[0],r[1],r[2]],l;if(t.depth!==void 0)l=ZA(i,t.depth,c,s);else{let e=fD(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=ZA(i,a-r,[c[0]+s[0]*r,c[1]+s[1]*r,c[2]+s[2]*r],s)}try{return MA(n,l,{unsafe:!0})}finally{l[Symbol.dispose]()}}function o0(e,t){try{var n=OT();let r=$(e),{profile:i,depth:a}=t;if(a<=0)return k(F(`POCKET_INVALID_DEPTH`,`Pocket depth must be positive`));let o=r0(r,t.face);if(A(o))return o;let s=o.value,c=mO(s),l=hO(s),u=n.u(new VT),{wire:d,owned:f}=i0(i);f&&u.register(d);let p=CA(d);if(A(p))return p;u.register(p.value);let m=vM(u.register(nk(p.value,l)),ED(ND(c),-a));return A(m)?m:(u.register(m.value),MA(r,m.value,{unsafe:!0}))}catch(e){n.e=e}finally{n.d()}}function s0(e,t){try{var n=OT();let r=$(e),{profile:i,height:a}=t;if(a<=0)return k(F(`BOSS_INVALID_HEIGHT`,`Boss height must be positive`));let o=r0(r,t.face);if(A(o))return o;let s=o.value,c=mO(s),l=hO(s),u=n.u(new VT),{wire:d,owned:f}=i0(i);f&&u.register(d);let p=CA(d);if(A(p))return p;u.register(p.value);let m=vM(u.register(nk(p.value,l)),ED(ND(c),a));return A(m)?m:(u.register(m.value),jA(r,m.value,{unsafe:!0}))}catch(e){n.e=e}finally{n.d()}}function c0(e,t){try{var n=OT();let r=$(e),i=t?.normal??[1,0,0],a=t?.at;return FD(i)?k(F(`MIRROR_ZERO_NORMAL`,`Mirror plane normal cannot be zero`)):jA(r,n.u(ik(r,i,a)),{unsafe:!0})}catch(e){n.e=e}finally{n.d()}}function l0(e,t){let n=$(e),{xDir:r,xCount:i,xSpacing:a,yDir:o,yCount:s,ySpacing:c}=t;if(i<1||s<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern counts must be at least 1`));if(FD(r))return k(F(`PATTERN_ZERO_DIRECTION`,`X direction cannot be zero`));if(FD(o))return k(F(`PATTERN_ZERO_DIRECTION`,`Y direction cannot be zero`));if(i===1&&s===1)return O(n);let l=ND(r),u=ND(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=nk(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 FA(d,{unsafe:!0})}finally{for(let e of f)e[Symbol.dispose]()}}var u0=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 d0(e){if(A(e))throw new u0(e.error);return e.value}function f0(e){return e}function p0(e){return e}function m0(e){return e}function h0(e){return e}function g0(e){return{val:e,__wrapped:!0,translate:t=>E0(y1(e,t)),rotate:(t,n)=>E0(b1(e,t,n)),mirror:t=>E0(x1(e,t)),scale:(t,n)=>E0(S1(e,t,n)),applyMatrix:t=>E0(d0(w1(e,t))),moveX:t=>E0(y1(e,[t,0,0])),moveY:t=>E0(y1(e,[0,t,0])),moveZ:t=>E0(y1(e,[0,0,t])),rotateX:t=>E0(b1(e,t,{axis:[1,0,0]})),rotateY:t=>E0(b1(e,t,{axis:[0,1,0]})),rotateZ:t=>E0(b1(e,t,{axis:[0,0,1]})),bounds:()=>fD(e),describe:()=>Y1(e),clone:()=>E0(d0(C1(e))),mesh:t=>q1(e,t),meshEdges:t=>J1(e,t),isValid:()=>Q1(e),isEmpty:()=>$1(e),heal:()=>E0(d0(G1(e))),simplify:()=>E0(d0(K1(e))),toBREP:()=>d0(X1(e)),apply:t=>E0(t(e)),applyResult:t=>E0(d0(t(e))),done:()=>e}}function _0(e){return{fuse:(t,n)=>D0(d0(D1(e,$(t),{...n,unsafe:!0}))),cut:(t,n)=>D0(d0(O1(e,$(t),{...n,unsafe:!0}))),intersect:(t,n)=>D0(d0(j1(e,$(t),{...n,unsafe:!0}))),fuseAll:(t,n)=>D0(h0(d0(FA([e,...t.map($)],{...n,unsafe:!0})))),cutAll:(t,n)=>D0(h0(d0(IA(e,t,{...n,unsafe:!0})))),section:(t,n)=>E0(d0(M1(e,t,n))),split:t=>E0(d0(P1(e,t))),slice:(t,n)=>d0(F1(e,t,n))}}function v0(e){return{fillet(...t){return t.length===1?D0(h0(d0(z1(f0(e),t[0])))):D0(h0(d0(z1(f0(e),t[0],t[1]))))},chamfer(...t){return t.length===1?D0(h0(d0(B1(f0(e),t[0])))):D0(h0(d0(B1(f0(e),t[0],t[1]))))},shell:(t,n,r)=>D0(h0(d0(V1(f0(e),t,n,r)))),offset:(t,n)=>D0(h0(d0(H1(f0(e),t,n)))),draft:(t,n)=>D0(h0(d0(W1(f0(e),t,n))))}}function y0(e){return{drill:t=>D0(d0(a0(e,t))),pocket:t=>D0(d0(o0(e,t))),boss:t=>D0(d0(s0(e,t))),mirrorJoin:t=>D0(d0(c0(e,t))),rectangularPattern:t=>D0(d0(l0(e,t)))}}function b0(e){return{volume:()=>d0(jM(e)),area:()=>d0(MM(e)),volumeProps:()=>d0(OM(e)),surfaceProps:()=>d0(kM(e))}}function x0(e){return{edges:()=>QE(e),faces:()=>$E(e),wires:()=>eD(e),vertices:()=>tD(e)}}function S0(e){return{linearPattern:(t,n,r)=>D0(h0(d0(PP(e,t,n,r)))),circularPattern:(t,n,r)=>D0(h0(d0(FP(e,t,n,r))))}}function C0(e){return{...g0(e),..._0(e),...v0(e),...y0(e),...b0(e),...x0(e),...S0(e)}}function w0(e){return{...g0(e),length:()=>Ek(e),startPoint:()=>Sk(e),endPoint:()=>Ck(e),pointAt:t=>wk(e,t),tangentAt:t=>Tk(e,t),isClosed:()=>Ok(e),sweep(t,n){if(!TE(e))throw Error(`sweep requires a Wire`);let r=d0(uM(m0(e),$(t),n));return D0(Array.isArray(r)?r[0]:r)}}}function T0(e){return{...g0(e),area:()=>d0(MM(e)),normalAt:t=>mO(e,t),center:()=>hO(e),surfaceType:()=>d0(oO(e)),outerWire:()=>vO(e),innerWires:()=>bO(e),extrude:t=>D0(d0(e0(p0(e),t))),revolve:t=>D0(d0(t0(p0(e),t)))}}function E0(e){return AE(e)?C0(e):EE(e)?T0(e):wE(e)||TE(e)?w0(e):g0(e)}function D0(e){return C0(e)}function O0(e){if(e&&typeof e==`object`&&`face`in e&&typeof e.face==`function`&&`_defaultOrigin`in e)return T0(e.face());if(e&&typeof e==`object`&&`wrapped`in e)return EE(e)?T0(e):AE(e)?C0(e):wE(e)||TE(e)?w0(e):g0(e);throw Error(`shape() requires a Sketch or branded shape type`)}var k0=.25,A0=e=>Math.tan(e)-e;function j0(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 M0(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(j0(e,s*t,n,i))}return a}function N0(e){return Math.max(16,Math.round(8*Math.sqrt(e)))}function P0(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 F0(e,t,n){if(t===0)return O(e);let r=A0(e)+2*t*Math.tan(e)/n,i,a;if(r>A0(e)?(i=e,a=Math.PI/2-1e-6):(i=1e-4,a=e),r>A0(a)||r<A0(i))return k(F(`GEAR_PA_OUT_OF_RANGE`,`working pressure angle out of range — target inv(αw)=${r.toFixed(4)} not in [${A0(i).toFixed(4)}, ${A0(a).toFixed(4)}]`,void 0,{target:r,invLo:A0(i),invHi:A0(a)}));for(let e=0;e<50;e++){let e=.5*(i+a);A0(e)<r?i=e:a=e}return O(.5*(i+a))}function I0(e,t,n,r,i){return F0(e,t+n,r+i)}function L0(e,t,n,r,i){return F0(e,n-t,i-r)}function R0(e,t,n,r,i){return(e+t)*n*Math.cos(r)/(2*Math.cos(i))}function z0(e,t,n,r){if(!Number.isInteger(e)||!Number.isInteger(t)||!Number.isInteger(n))return k(F(`GEAR_NON_INTEGER_TEETH`,`tooth counts and planet count must be integers`));if(e<4||t<4||n<2)return k(F(`GEAR_TEETH_TOO_FEW`,`zs ≥ 4, zp ≥ 4, N ≥ 2 required`));if((2*e+2*t)%n!=0)return k(F(`GEAR_ASSEMBLY`,`(2·zs + 2·zp) must be divisible by N — got ${2*e+2*t} mod ${n} = ${(2*e+2*t)%n}`));let i=t+2+2*r,a=(e+t)*Math.sin(Math.PI/n);return a<=i?k(F(`GEAR_PLANET_COLLISION`,`planet tips would collide: (zs+zp)·sin(π/N) = ${a.toFixed(3)} ≤ planet tip = ${i.toFixed(3)}`)):O(void 0)}function B0(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 V0(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 H0(e,t){return 1-e*Math.sin(t)*Math.sin(t)/2}function U0(e,t,n){return Math.max(0,H0(e,t)-n)}function W0(e){return e<8?.2:.485-2.88/e}function G0(e,t,n,r){let i=e*1e3,a=W0(r);return a<=0||n<=0||t<=0?1/0:2*i/(r*t*t*n*a)}function K0(e,t,n=!1){let r=(1.4+6.5/e)*(20/(t*180/Math.PI))**.15;return n?r*.85:r}function q0(e,t,n,r,i,a=!1){return G0(e,t,n,r)*K0(r,i,a)}function J0(e){return e/2}function Y0(e,t){return e+2*t}function X0(e){return e%2==0?Math.PI/e:0}function Z0(e,t,n){return e*(1+t/n)+X0(n)}function Q0(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=z0(n,r,i,s);if(A(c))return c;let l=I0(a,o,s,n,r);if(A(l))return l;let u=R0(n,r,t,a,l.value),d=[];for(let e=0;e<i;e++){let t=e*2*Math.PI/i,a=Z0(t,n,r);d.push({rotationDeg:a*180/Math.PI,position:[u*Math.cos(t),u*Math.sin(t),0]})}return O(d)}function $0(e,t,n,r,i){let a=t*e.toothPitch,o=(t+1)%n*e.toothPitch,s=A0(e.alphaPitch),c=a-e.halfToothAngle-s,l=a+e.halfToothAngle+s,u=M0(e.rb,e.alphaTip,c,r,1),d=M0(e.rb,e.alphaTip,l,r,-1).reverse(),f=cA(u),p=lA(u),m=cA(d),h=lA(d),g=[],_=e=>{i.register(e),g.push(e)},v=e.isInternal?e.rb<e.rRoot:e.rb>e.rRoot;v&&_(fA([e.rRoot*Math.cos(c),e.rRoot*Math.sin(c),0],f));let y=e.rPitch*1e-5,b=yA(u,{tolerance:y});if(A(b))return b;_(b.value),_(gA(p,[e.rTip*Math.cos(a),e.rTip*Math.sin(a),0],m));let x=yA(d,{tolerance:y});if(A(x))return x;_(x.value),v&&_(fA(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),_(gA(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 e2(e){return n2(e,!1)}function t2(e){return n2(e,!0)}function n2(e,t){try{var n=OT();let{teeth:r,moduleSize:i,pressureAngle:a,shift:o,clearance:s,flankThinning:c,samples:l=N0(i)}=e;if(r<4)return k(F(`GEAR_TEETH_TOO_FEW`,`gear needs ≥ 4 teeth, got ${r}`));if(i<=0)return k(F(`GEAR_MODULE_NONPOSITIVE`,`module must be > 0, got ${i}`));let u=P0(r,i,a,o,s,c,t),d=n.u(new VT),f=[];for(let e=0;e<r;e++){let t=$0(u,e,r,l,d);if(A(t))return t;f.push(...t.value)}let p=SA(f);return A(p)?p:O(p.value)}catch(e){n.e=e}finally{n.d()}}function r2(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=k0,flankThinning:s=0,bore:c=0,samples:l}=e;if(r<=0)return k(F(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));if(l!==void 0&&(!Number.isInteger(l)||l<1))return k(F(`GEAR_SAMPLES_INVALID`,`samples must be a positive integer; got ${String(l)}`));let u=i*Math.PI/180,d=P0(t,n,u,a,o,s,!1);if(c>0&&c>=2*d.rRoot)return k(F(`GEAR_BORE_TOO_LARGE`,`bore diameter ${c.toFixed(2)} ≥ root diameter ${(2*d.rRoot).toFixed(2)} — would erase the gear teeth`));let f=e2({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(f))return f;let p=a2(t,u,a);return u2(f.value,r,c,d,p)}function i2(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=k0,flankThinning:s=0,ringWallThickness:c=2*e.moduleSize,samples:l}=e;if(r<=0)return k(F(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));if(c<=0)return k(F(`GEAR_WALL_NONPOSITIVE`,`ringWallThickness must be > 0`));if(l!==void 0&&(!Number.isInteger(l)||l<1))return k(F(`GEAR_SAMPLES_INVALID`,`samples must be a positive integer; got ${String(l)}`));let u=i*Math.PI/180,d=t2({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(d))return d;let f=P0(t,n,u,a,o,s,!0),p=l2(f.rPitch+c);return A(p)?p:f2(p.value,d.value,r,f,[])}function a2(e,t,n){let r=U0(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 o2(e){let t=c2(e);if(A(t))return t;let n=t.value,r=s2(n);if(A(r))return r;let{sun:i,planet:a,ring:o}=r.value,s=g2(n,i,a,o),c=m2(a.solid,n);a.solid.delete();let l=h2(o.solid,n.zr),u=_2(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 s2(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=r2({...n,teeth:e.sunTeeth,shift:e.sunShift,bore:e.sunBore});if(A(r))return r;let i=r2({...n,teeth:e.planetTeeth,shift:e.planetShift,bore:e.planetBore});if(A(i))return r.value.solid.delete(),i;let a=i2({...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 c2(e){let t=e.moduleSize??3,n=e.sunTeeth??15,r=e.planetTeeth??12,i=e.numPlanets??3,a=e.pressureAngleDeg??20,o=a*Math.PI/180,s=e.sunShift??0,c=e.planetShift??0,l=e.ringShift??0;if(e.thickness<=0)return k(F(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));let u=z0(n,r,i,c);if(A(u))return u;let d=Y0(n,r),f=I0(o,s,c,n,r);if(A(f))return f;let p=L0(o,c,l,r,d);if(A(p))return p;let m=R0(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:J0(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 l2(e){try{var t=OT();let n=SA([t.u(new VT).register(pA(e,[0,0,0],[0,0,1]))]);return A(n)?n:O(n.value)}catch(e){t.e=e}finally{t.d()}}function u2(e,t,n,r,i){try{var a=OT();let o=a.u(new VT);o.register(e);let s=CA(e);if(A(s))return s;o.register(s.value);let c=vM(s.value,[0,0,t]);if(A(c))return c;if(n<=0)return O(p2(c.value,r,i));let l=a.u(new VT);l.register(c.value);let u=d2(n/2);if(A(u))return u;l.register(u.value);let d=vM(u.value,[0,0,t+1]);if(A(d))return d;l.register(d.value);let f=l.register(nk(d.value,[0,0,-.5])),p=MA(c.value,f);return A(p)?p:O(p2(p.value,r,i))}catch(e){a.e=e}finally{a.d()}}function d2(e){let t=l2(e);return A(t)?t:CA(t.value)}function f2(e,t,n,r,i){let a=CA(e,[t]);if(A(a))return a;let o=vM(a.value,[0,0,n]);return A(o)?o:O(p2(o.value,r,i))}function p2(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 m2(e,t){let n=[];try{for(let r=0;r<t.numPlanets;r++){let i=r*2*Math.PI/t.numPlanets,a=rk(e,Z0(i,t.sunTeeth,t.planetTeeth)*180/Math.PI);try{let e=[t.centerDistance*Math.cos(i),t.centerDistance*Math.sin(i),0];n.push(nk(a,e))}finally{a.delete()}}return n}catch(e){for(let e of n)e.delete();throw e}}function h2(e,t){let n=X0(t);if(n===0)return e;let r=rk(e,n*180/Math.PI);return e.delete(),r}function g2(e,t,n,r){let i={crSunPlanet:B0(t.tipDiameter/2,t.baseDiameter/2,n.tipDiameter/2,n.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_sp),crPlanetRing:V0(n.tipDiameter/2,n.baseDiameter/2,r.tipDiameter/2,r.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_pr),undercutSun:U0(e.sunTeeth,e.alpha,e.sunShift),undercutPlanet:U0(e.planetTeeth,e.alpha,e.planetShift)};if(e.appliedTorque!==void 0){let t=e.appliedTorque;i.lewisStress={sun:q0(t,e.moduleSize,e.thickness,e.sunTeeth,e.alpha),planet:q0(t*e.planetTeeth/e.sunTeeth,e.moduleSize,e.thickness,e.planetTeeth,e.alpha),ring:q0(t*e.zr/e.sunTeeth,e.moduleSize,e.thickness,e.zr,e.alpha,!0)},i.stressConcentrationFactor={sun:K0(e.sunTeeth,e.alpha),planet:K0(e.planetTeeth,e.alpha),ring:K0(e.zr,e.alpha,!0)}}return i}function _2(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 v2=TX({addHoles:()=>AP,bezier:()=>_P,box:()=>iP,bsplineApprox:()=>gP,circle:()=>dP,compound:()=>EP,cone:()=>sP,cylinder:()=>aP,ellipse:()=>fP,ellipseArc:()=>hP,ellipsoid:()=>lP,face:()=>xP,fill:()=>wA,filledFace:()=>SP,helix:()=>pP,line:()=>uP,offsetFace:()=>OP,polygon:()=>wP,polyhedron:()=>RQ,sewShells:()=>kP,solid:()=>DP,sphere:()=>oP,subFace:()=>CP,tangentArc:()=>vP,threePointArc:()=>mP,torus:()=>cP,vertex:()=>TP,wire:()=>yP,wireLoop:()=>bP}),y2=TX({checkBoolean:()=>Tj,convexHull:()=>NQ,cut:()=>O1,cutAll:()=>IA,cutAllBisect:()=>gj,fuse:()=>D1,fuseAll:()=>FA,fuseAllBisect:()=>bj,hull:()=>MQ,intersect:()=>j1,minkowski:()=>LQ,section:()=>M1,sectionToFace:()=>N1,slice:()=>F1,split:()=>P1}),b2=TX({chamfer:()=>B1,draft:()=>W1,fillet:()=>z1,heal:()=>G1,offset:()=>H1,shell:()=>V1,simplify:()=>K1,thicken:()=>U1,variableFillet:()=>Xj}),x2=TX({applyMatrix:()=>w1,clone:()=>C1,composeTransforms:()=>dk,mirror:()=>x1,rotate:()=>b1,scale:()=>S1,transformCopy:()=>T1,translate:()=>y1}),S2=TX({checkAllInterferences:()=>Y$,checkInterference:()=>J$,createDistanceQuery:()=>IM,measureArea:()=>MM,measureCurvatureAt:()=>LM,measureCurvatureAtMid:()=>RM,measureDistance:()=>PM,measureDistanceProps:()=>FM,measureLength:()=>NM,measureLinearProps:()=>AM,measureSurfaceProps:()=>kM,measureVolume:()=>jM,measureVolumeProps:()=>OM}),C2=TX({blueprintToDXF:()=>pY,exportAssemblySTEP:()=>NP,exportDXF:()=>fY,exportGlb:()=>$J,exportGltf:()=>QJ,exportIGES:()=>$k,exportOBJ:()=>HJ,exportSTEP:()=>Zk,exportSTEPConfigured:()=>XY,exportSTL:()=>Qk,exportThreeMF:()=>MY,importDXF:()=>e1,importGLB:()=>_1,importIGES:()=>$Y,importOBJ:()=>i1,importSTEP:()=>ZY,importSTL:()=>QY,importSVG:()=>YY,importSVGPathD:()=>JY,importThreeMF:()=>g1}),w2=TX({cornerFinder:()=>fR,edgeFinder:()=>II,faceFinder:()=>zI,getSingleFace:()=>HI,vertexFinder:()=>PX,wireFinder:()=>VI}),T2=TX({complexExtrude:()=>fM,extrude:()=>e0,guidedSweep:()=>_M,loft:()=>n0,multiSectionSweep:()=>gM,revolve:()=>t0,roof:()=>s$,supportExtrude:()=>dM,surfaceFromGrid:()=>DQ,surfaceFromImage:()=>AQ,sweep:()=>uM,twistExtrude:()=>pM}),E2=TX({circularPattern:()=>FP,linearPattern:()=>PP}),D2=14695981039346656037n,O2=1099511628211n,k2=18446744073709551615n;function A2(){return D2}function j2(e,t){return(e^BigInt(t&255))*O2&k2}function M2(e,t){let n=e;for(let e=0;e<t.length;e++)n=j2(n,t[e]??0);return n}var N2=new TextEncoder;function P2(e,t){return M2(e,N2.encode(t))}var F2=new ArrayBuffer(8),I2=new DataView(F2),L2=new Uint8Array(F2);function R2(e,t){return I2.setFloat64(0,Object.is(t,-0)?0:t),M2(e,L2)}function z2(e,t){let n=e,r=t&k2;for(let e=0;e<8;e++)n=j2(n,Number(r&255n)),r>>=8n;return n}function B2(e,t){let n=e,r=t|0;for(let e=0;e<4;e++)n=j2(n,r&255),r>>>=8;return n}function V2(e,t){return j2(e,+!!t)}function H2(e){return(e&k2).toString(16).padStart(16,`0`)}var U2=new Set;function W2(e){return P2(A2(),e)}function G2(e){return{kind:`NumLit`,value:e,structuralHash:R2(W2(`NumLit`),e),freeParams:U2}}function K2(e){let t=W2(`Vec3Lit`);for(let n of e)t=R2(t,n);return{kind:`Vec3Lit`,value:e,structuralHash:t,freeParams:U2}}function q2(e){let t=W2(`Vec2Lit`);for(let n of e)t=R2(t,n);return{kind:`Vec2Lit`,value:e,structuralHash:t,freeParams:U2}}function J2(e){return{kind:`Param`,name:e,structuralHash:P2(W2(`Param`),e),freeParams:new Set([e])}}function Y2(e,t,n){let r=P2(W2(`BinOp`),e);return r=z2(r,t.structuralHash),r=z2(r,n.structuralHash),{kind:`BinOp`,op:e,a:t,b:n,structuralHash:r,freeParams:a4(t.freeParams,n.freeParams)}}function X2(e,t){let n=P2(W2(`UnaryOp`),e);return n=z2(n,t.structuralHash),{kind:`UnaryOp`,op:e,arg:t,structuralHash:n,freeParams:t.freeParams}}function Z2(e,t){let n=B2(W2(`Component`),t);return n=z2(n,e.structuralHash),{kind:`Component`,vec:e,index:t,structuralHash:n,freeParams:e.freeParams}}function Q2(e,t){let n=B2(W2(`BuildVec`),e),r=new Set;for(let e of t){n=z2(n,e.structuralHash);for(let t of e.freeParams)r.add(t)}return{kind:`BuildVec`,dim:e,components:t,structuralHash:n,freeParams:r}}var $2=(e,t)=>Y2(`+`,e,t),e4=(e,t)=>Y2(`*`,e,t);function t4(e){return typeof e==`number`?G2(e):e}function n4(e,t){if(!Array.isArray(e))return e;let n=e;return n.every(e=>typeof e==`number`)?t===3?K2([n[0],n[1],n[2]]):q2([n[0],n[1]]):Q2(t,n.map(t4))}function r4(e){return n4(e,3)}function i4(e){return n4(e,2)}function a4(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 o4(e){return typeof e==`number`}function s4(e,t){return o4(e)?O(e):k(F(N.NULL_SHAPE_INPUT,`${t}: expected number, got ${Array.isArray(e)?`vector(${e.length})`:typeof e}`))}function c4(e,t,n){return Array.isArray(e)&&e.length===t?O(e):k(F(N.NULL_SHAPE_INPUT,`${n}: expected Vec${t}, got ${o4(e)?`number`:`vector(${e.length})`}`))}function l4(e,t){switch(e.kind){case`NumLit`:return O(e.value);case`Vec3Lit`:return O(e.value);case`Vec2Lit`:return O(e.value);case`Param`:{let n=t[e.name];return n===void 0?k(F(N.NULL_SHAPE_INPUT,`unbound param: ${e.name}`)):O(n)}case`BinOp`:return u4(e,t);case`UnaryOp`:return d4(e,t);case`Component`:return f4(e,t);case`BuildVec`:return p4(e,t)}}function u4(e,t){let n=l4(e.a,t);if(!n.ok)return n;let r=l4(e.b,t);if(!r.ok)return r;let i=s4(n.value,`BinOp(${e.op}).a`);if(!i.ok)return i;let a=s4(r.value,`BinOp(${e.op}).b`);if(!a.ok)return a;switch(e.op){case`+`:return O(i.value+a.value);case`-`:return O(i.value-a.value);case`*`:return O(i.value*a.value);case`/`:return a.value===0?k(F(N.NULL_SHAPE_INPUT,`BinOp(/): division by zero`)):O(i.value/a.value)}}function d4(e,t){let n=l4(e.arg,t);if(!n.ok)return n;let r=s4(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 f4(e,t){let n=l4(e.vec,t);if(!n.ok)return n;if(o4(n.value))return k(F(N.NULL_SHAPE_INPUT,`Component: cannot index a scalar`));let r=n.value,i=r[e.index];return i===void 0?k(F(N.NULL_SHAPE_INPUT,`Component: index ${e.index} out of range for Vec${r.length}`)):O(i)}function p4(e,t){if(e.components.length!==e.dim)return k(F(N.NULL_SHAPE_INPUT,`BuildVec(${e.dim}): expected ${e.dim} components, got ${e.components.length}`));let n=[];for(let r of e.components){let e=l4(r,t);if(!e.ok)return e;let i=s4(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 m4(e,t,n){let r=l4(e,t);return r.ok?s4(r.value,n):r}function h4(e,t,n){let r=l4(e,t);if(!r.ok)return r;let i=c4(r.value,3,n);if(!i.ok)return i;let[a,o,s]=i.value;return O([a,o,s])}function g4(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 _4=new Set;function v4(e){return P2(A2(),e)}function y4(e,t){return z2(e,t.structuralHash)}function b4(e,t){return t===void 0?V2(e,!1):y4(V2(e,!0),t)}function x4(e,t){return t===void 0?V2(e,!1):R2(V2(e,!0),t)}function S4(...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?_4:t}function C4(e,t,n){let r=t4(e),i=t4(t),a=t4(n),o=v4(`Box`);return o=y4(y4(y4(o,r),i),a),{kind:`Box`,x:r,y:i,z:a,structuralHash:o,freeParams:S4(r,i,a)}}function w4(e){let t=t4(e);return{kind:`Sphere`,radius:t,structuralHash:y4(v4(`Sphere`),t),freeParams:t.freeParams}}function T4(e,t){let n=t4(e),r=t4(t);return{kind:`Cylinder`,radius:n,height:r,structuralHash:y4(y4(v4(`Cylinder`),n),r),freeParams:S4(n,r)}}function E4(e,t,n){let r=t4(e),i=t4(t),a=t4(n),o=v4(`Cone`);return o=y4(y4(y4(o,r),i),a),{kind:`Cone`,radius1:r,radius2:i,height:a,structuralHash:o,freeParams:S4(r,i,a)}}function D4(e,t){let n=t4(e),r=t4(t);return{kind:`Torus`,majorRadius:n,minorRadius:r,structuralHash:y4(y4(v4(`Torus`),n),r),freeParams:S4(n,r)}}function O4(e){let t=e.map(r4),n=B2(v4(`Polygon`),t.length);for(let e of t)n=y4(n,e);return{kind:`Polygon`,points:t,structuralHash:n,freeParams:S4(...t)}}function k4(e){let t=t4(e);return{kind:`Circle`,radius:t,structuralHash:y4(v4(`Circle`),t),freeParams:t.freeParams}}function A4(e,t){let n=r4(e),r=r4(t);return{kind:`Line`,from:n,to:r,structuralHash:y4(y4(v4(`Line`),n),r),freeParams:S4(n,r)}}function j4(e){let t=r4(e);return{kind:`Vertex`,point:t,structuralHash:y4(v4(`Vertex`),t),freeParams:t.freeParams}}function M4(e){return{kind:`Empty`,output:e,structuralHash:P2(v4(`Empty`),e),freeParams:_4}}function N4(){return M4(`Solid`)}function P4(){return M4(`Face`)}function F4(){return M4(`Wire`)}function I4(e,t,n,r){return x4(y4(y4(v4(e),t),n),r)}function L4(e,t,n){return{kind:`Fuse`,a:e,b:t,tolerance:n,structuralHash:I4(`Fuse`,e,t,n),freeParams:S4(e,t)}}function R4(e,t,n){return{kind:`Cut`,a:e,b:t,tolerance:n,structuralHash:I4(`Cut`,e,t,n),freeParams:S4(e,t)}}function z4(e,t,n){return{kind:`Intersect`,a:e,b:t,tolerance:n,structuralHash:I4(`Intersect`,e,t,n),freeParams:S4(e,t)}}function B4(e,t){let n=B2(v4(`FuseAll`),e.length);for(let t of e)n=y4(n,t);return n=x4(n,t),{kind:`FuseAll`,shapes:e,tolerance:t,structuralHash:n,freeParams:S4(...e)}}function V4(e,t,n){let r=y4(v4(`CutAll`),e);r=B2(r,t.length);for(let e of t)r=y4(r,e);return r=x4(r,n),{kind:`CutAll`,base:e,tools:t,tolerance:n,structuralHash:r,freeParams:S4(e,...t)}}function H4(e){return e===void 0?void 0:r4(e)}function U4(e,t){let n=r4(t);return{kind:`Translate`,target:e,vector:n,structuralHash:y4(y4(v4(`Translate`),e),n),freeParams:S4(e,n)}}function W4(e,t,n){let r=t4(t),i=H4(n?.axis),a=H4(n?.at),o=y4(y4(v4(`Rotate`),e),r);return o=b4(o,i),o=b4(o,a),{kind:`Rotate`,target:e,angle:r,axis:i,at:a,structuralHash:o,freeParams:S4(e,r,i,a)}}function G4(e,t,n){let r=t4(t),i=H4(n?.center),a=y4(y4(v4(`Scale`),e),r);return a=b4(a,i),{kind:`Scale`,target:e,factor:r,center:i,structuralHash:a,freeParams:S4(e,r,i)}}function K4(e,t){let n=H4(t?.normal),r=H4(t?.at),i=y4(v4(`Mirror`),e);return i=b4(i,n),i=b4(i,r),{kind:`Mirror`,target:e,normal:n,at:r,structuralHash:i,freeParams:S4(e,n,r)}}function q4(e){let t=B2(v4(`Compound`),e.length);for(let n of e)t=y4(t,n);return{kind:`Compound`,children:e,structuralHash:t,freeParams:S4(...e)}}function J4(e,t,n=!1){let r=t.map(e=>e.map(e=>[...e])),i=B2(V2(y4(v4(`Instance`),e),n),r.length);for(let e of r)for(let t of e.flat())i=R2(i,t);return{kind:`Instance`,source:e,placements:r,fuse:n,structuralHash:i,freeParams:S4(e)}}function Y4(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 Y4(e.a);case`FuseAll`:return e.shapes[0]?Y4(e.shapes[0]):`Solid`;case`CutAll`:return Y4(e.base);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return Y4(e.target);case`Compound`:return`Compound`;case`Instance`:return e.fuse?`Solid`:`Compound`}}function X4(e,t){let n=m4(e.x,t.env,`Box.x`);if(!n.ok)return n;let r=m4(e.y,t.env,`Box.y`);if(!r.ok)return r;let i=m4(e.z,t.env,`Box.z`);return i.ok?O(iP(n.value,r.value,i.value)):i}function Z4(e,t){let n=m4(e.radius,t.env,`Sphere.radius`);return n.ok?O(oP(n.value)):n}function Q4(e,t){let n=m4(e.radius,t.env,`Cylinder.radius`);if(!n.ok)return n;let r=m4(e.height,t.env,`Cylinder.height`);return r.ok?O(aP(n.value,r.value)):r}function $4(e,t){let n=m4(e.radius1,t.env,`Cone.radius1`);if(!n.ok)return n;let r=m4(e.radius2,t.env,`Cone.radius2`);if(!r.ok)return r;let i=m4(e.height,t.env,`Cone.height`);return i.ok?O(sP(n.value,r.value,i.value)):i}function e3(e,t){let n=m4(e.majorRadius,t.env,`Torus.majorRadius`);if(!n.ok)return n;let r=m4(e.minorRadius,t.env,`Torus.minorRadius`);return r.ok?O(cP(n.value,r.value)):r}function t3(e,t){let n=[];for(let r of e.points){let e=h4(r,t.env,`Polygon.point`);if(!e.ok)return e;n.push(e.value)}return wP(n)}function n3(e,t){let n=m4(e.radius,t.env,`Circle.radius`);return n.ok?O(dP(n.value)):n}function r3(e,t){let n=h4(e.from,t.env,`Line.from`);if(!n.ok)return n;let r=h4(e.to,t.env,`Line.to`);return r.ok?O(uP(n.value,r.value)):r}function i3(e,t){let n=h4(e.point,t.env,`Vertex.point`);return n.ok?O(TP(n.value)):n}function a3(e){return k(I(N.NULL_SHAPE_INPUT,`${e}: empty result has no kernel representation`))}function o3(e,t,n){let r=e.evalNode(t);return r.ok?AE(r.value)?O(r.value):k(ho(N.CSG_NOT_3D,`${n}: operand did not produce a 3D shape`)):r}function s3(e,t){return{unsafe:!0,fuzzyValue:e.tolerance??t.tolerance}}function c3(e,t){if(e.a.kind===`Empty`)return t.evalNode(e.b);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=o3(t,e.a,`Fuse.a`);if(!n.ok)return n;let r=o3(t,e.b,`Fuse.b`);return r.ok?jA(n.value,r.value,s3(e,t)):r}function l3(e,t){if(e.a.kind===`Empty`)return a3(`Cut`);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=o3(t,e.a,`Cut.a`);if(!n.ok)return n;let r=o3(t,e.b,`Cut.b`);return r.ok?MA(n.value,r.value,s3(e,t)):r}function u3(e,t){if(e.a.kind===`Empty`||e.b.kind===`Empty`)return a3(`Intersect`);let n=o3(t,e.a,`Intersect.a`);if(!n.ok)return n;let r=o3(t,e.b,`Intersect.b`);return r.ok?NA(n.value,r.value,s3(e,t)):r}function d3(e,t,n){let r=[];for(let i of t){let t=o3(e,i,n);if(!t.ok)return t;r.push(t.value)}return O(r)}function f3(e,t){let n=e.shapes.filter(e=>e.kind!==`Empty`);if(n.length===0)return a3(`FuseAll`);if(n.length===1&&n[0])return t.evalNode(n[0]);let r=d3(t,n,`FuseAll.operand`);return r.ok?FA(r.value,s3(e,t)):r}function p3(e,t){if(e.base.kind===`Empty`)return a3(`CutAll`);let n=e.tools.filter(e=>e.kind!==`Empty`);if(n.length===0)return t.evalNode(e.base);let r=o3(t,e.base,`CutAll.base`);if(!r.ok)return r;let i=d3(t,n,`CutAll.tool`);return i.ok?IA(r.value,i.value,s3(e,t)):i}function m3(e){return k(I(N.NULL_SHAPE_INPUT,`${e}: cannot transform an Empty node`))}function h3(e,t,n,r){return e?h4(e,t,n):O(r)}function g3(e,t){let n=U(),{handle:r,dispose:i}=n.composeTransform(t),a;try{a=ME(n.locate(e.wrapped,r))}finally{i()}return ZO(e)&&tk(e,a),a}function _3(e,t){if(e.target.kind===`Empty`)return m3(`Translate`);let n=h4(e.vector,t.env,`Translate.vector`);if(!n.ok)return n;let r=t.evalNode(e.target);return r.ok?O(g3(r.value,[{type:`translate`,x:n.value[0],y:n.value[1],z:n.value[2]}])):r}function v3(e,t){if(e.target.kind===`Empty`)return m3(`Rotate`);let n=m4(e.angle,t.env,`Rotate.angle`);if(!n.ok)return n;let r=h3(e.axis,t.env,`Rotate.axis`,[0,0,1]);if(!r.ok)return r;let i=h3(e.at,t.env,`Rotate.at`,[0,0,0]);if(!i.ok)return i;let a=t.evalNode(e.target);return a.ok?O(g3(a.value,[{type:`rotate`,angle:n.value,axis:r.value,center:i.value}])):a}function y3(e,t){if(e.target.kind===`Empty`)return m3(`Scale`);let n=m4(e.factor,t.env,`Scale.factor`);if(!n.ok)return n;let r=h3(e.center,t.env,`Scale.center`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(ak(i.value,n.value,r.value)):i}function b3(e,t){if(e.target.kind===`Empty`)return m3(`Mirror`);let n=h3(e.normal,t.env,`Mirror.normal`,[1,0,0]);if(!n.ok)return n;let r=h3(e.at,t.env,`Mirror.at`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(ik(i.value,n.value,r.value)):i}function x3(e,t){let n=e.children.filter(e=>e.kind!==`Empty`);if(n.length===0)return k(I(N.NULL_SHAPE_INPUT,`Compound: cannot materialize a compound with zero non-empty children`));let r=[];for(let e of n){let n=t.evalNode(e);if(!n.ok)return n;r.push(n.value)}return O(EP(r))}function S3(){return k(I(N.NULL_SHAPE_INPUT,`Empty: cannot materialize an Empty node directly — only valid as boolean/transform operand`))}function C3(e,t){let n=t.evalNode(e.source);return n.ok?h$(f$(n.value,e.placements),{fuse:e.fuse}):n}function w3(e,t){switch(e.kind){case`Box`:return X4(e,t);case`Sphere`:return Z4(e,t);case`Cylinder`:return Q4(e,t);case`Cone`:return $4(e,t);case`Torus`:return e3(e,t);case`Polygon`:return t3(e,t);case`Circle`:return n3(e,t);case`Line`:return r3(e,t);case`Vertex`:return i3(e,t);case`Empty`:return S3();case`Fuse`:return c3(e,t);case`Cut`:return l3(e,t);case`Intersect`:return u3(e,t);case`FuseAll`:return f3(e,t);case`CutAll`:return p3(e,t);case`Translate`:return _3(e,t);case`Rotate`:return v3(e,t);case`Scale`:return y3(e,t);case`Mirror`:return b3(e,t);case`Compound`:return x3(e,t);case`Instance`:return C3(e,t)}}function T3(e,t){if(typeof t==`number`)return R2(V2(e,!1),t);let n=V2(e,!0);n=B2(n,t.length);for(let e of t)n=R2(n,e);return n}function E3(e,t){if(t.size===0)return A2();let n=g4(e,t),r=Object.keys(n).sort(),i=A2();for(let e of r){i=P2(i,e);let t=n[e];t!==void 0&&(i=T3(i,t))}return i}function D3(e,t,n,r){let i=E3(t,e.freeParams),a=r===void 0?`d`:R2(A2(),r).toString(16);return`${H2(e.structuralHash)}:${n}:${H2(i)}:${a}`}var O3=[1,0,0,0];function k3(e,t){let n=m4(e.angle,t,`evaluateMesh.peelRigid`);if(!n.ok)return null;let r=e.axis?h4(e.axis,t,`evaluateMesh.peelRigid`):O([0,0,1]);if(!r.ok)return null;let i=e.at?h4(e.at,t,`evaluateMesh.peelRigid`):O([0,0,0]);return i.ok?{angle:n.value,axis:r.value,center:i.value}:null}function A3(e,t){let n=e,r=O3,i=[0,0,0];for(;;)if(n.kind===`Translate`){let e=h4(n.vector,t,`evaluateMesh.peelRigid`);if(!e.ok)break;let a=YP(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=k3(n,t);if(!e)break;let a=XP(e.axis,e.angle*Math.PI/180),o=QP(r,a),s=YP(r,e.center),c=YP(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 j3(e){return e[0]===1&&e[1]===0&&e[2]===0&&e[3]===0}function M3(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 N3(e,t,n){let[r,i,a]=n,o=j3(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;M3(c,s,l,u,d,f,r,i,a);let p=e.normals,m=new Float32Array(p.length);return M3(m,p,l,u,d,f,0,0,0),{...e,vertices:c,normals:m}}function P3(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 F3=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??_T()??`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 vT(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=To(),a=n.tolerance??i.tolerance,o=n.angularTolerance??i.angularTolerance,s=`${D3(e,t,this.kernelId,this.defaultTolerance)}|${Ik(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}=A3(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=$E(c.value).map(gk),u=this.evaluate(e,t);if(!u.ok)return u;let d=$E(u.value).map(gk),f=N3(r.value,a,o),p=P3(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=vT(this.kernelId,()=>Kk(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=D3(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=w3(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 I3(e,t){try{var n=OT();let r=t(n.u(new F3(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 L3(e){return{csgVersion:1,root:U3(e)}}function R3(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:R3(e.a),b:R3(e.b)};case`UnaryOp`:return{kind:`UnaryOp`,op:e.op,arg:R3(e.arg)};case`Component`:return{kind:`Component`,vec:R3(e.vec),index:e.index};case`BuildVec`:return{kind:`BuildVec`,dim:e.dim,components:e.components.map(R3)}}}function z3(e){switch(e.kind){case`Box`:return{kind:`Box`,x:R3(e.x),y:R3(e.y),z:R3(e.z)};case`Sphere`:return{kind:`Sphere`,radius:R3(e.radius)};case`Cylinder`:return{kind:`Cylinder`,radius:R3(e.radius),height:R3(e.height)};case`Cone`:return{kind:`Cone`,radius1:R3(e.radius1),radius2:R3(e.radius2),height:R3(e.height)};case`Torus`:return{kind:`Torus`,majorRadius:R3(e.majorRadius),minorRadius:R3(e.minorRadius)};case`Polygon`:return{kind:`Polygon`,points:e.points.map(R3)};case`Circle`:return{kind:`Circle`,radius:R3(e.radius)};case`Line`:return{kind:`Line`,from:R3(e.from),to:R3(e.to)};case`Vertex`:return{kind:`Vertex`,point:R3(e.point)};case`Empty`:return{kind:`Empty`,output:e.output};default:return}}function B3(e){switch(e.kind){case`Fuse`:case`Cut`:case`Intersect`:return{kind:e.kind,a:U3(e.a),b:U3(e.b),tolerance:e.tolerance};case`FuseAll`:return{kind:`FuseAll`,shapes:e.shapes.map(U3),tolerance:e.tolerance};case`CutAll`:return{kind:`CutAll`,base:U3(e.base),tools:e.tools.map(U3),tolerance:e.tolerance};default:return}}function V3(e){return e?R3(e):void 0}function H3(e){switch(e.kind){case`Translate`:return{kind:`Translate`,target:U3(e.target),vector:R3(e.vector)};case`Rotate`:return{kind:`Rotate`,target:U3(e.target),angle:R3(e.angle),axis:V3(e.axis),at:V3(e.at)};case`Scale`:return{kind:`Scale`,target:U3(e.target),factor:R3(e.factor),center:V3(e.center)};case`Mirror`:return{kind:`Mirror`,target:U3(e.target),normal:V3(e.normal),at:V3(e.at)};default:return}}function U3(e){return e.kind===`Compound`?{kind:`Compound`,children:e.children.map(U3)}:e.kind===`Instance`?{kind:`Instance`,source:U3(e.source),placements:e.placements,fuse:e.fuse}:z3(e)??B3(e)??H3(e)}function W3(e){return k(F(N.NULL_SHAPE_INPUT,`csg.fromJSON: ${e}`))}function G3(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function K3(e){return typeof e==`number`&&Number.isFinite(e)}function q3(e){return typeof e==`string`}function J3(e,t){if(!Array.isArray(e)||e.length!==3)return W3(`${t}: expected Vec3 array`);let[n,r,i]=e;return!K3(n)||!K3(r)||!K3(i)?W3(`${t}: Vec3 contains non-number`):O([n,r,i])}function Y3(e,t){if(!Array.isArray(e)||e.length!==2)return W3(`${t}: expected Vec2 array`);let[n,r]=e;return!K3(n)||!K3(r)?W3(`${t}: Vec2 contains non-number`):O([n,r])}function X3(e){if(!G3(e))return W3(`input is not an object`);let t=e.csgVersion;if(t!==1)return W3(`unsupported csgVersion ${String(t)} (expected 1)`);let n=e.root;return i6(n)}function Z3(e){if(!G3(e))return W3(`expression: not an object`);let t=e.kind;switch(t){case`NumLit`:return K3(e.value)?O(G2(e.value)):W3(`NumLit.value`);case`Vec3Lit`:{let t=J3(e.value,`Vec3Lit.value`);return t.ok?O(K2(t.value)):t}case`Vec2Lit`:{let t=Y3(e.value,`Vec2Lit.value`);return t.ok?O(q2(t.value)):t}case`Param`:return q3(e.name)?O(J2(e.name)):W3(`Param.name`);case`BinOp`:return Q3(e);case`UnaryOp`:return $3(e);case`Component`:return e6(e);case`BuildVec`:return t6(e);default:return W3(`unknown expression kind: ${String(t)}`)}}function Q3(e){let t=e.op;if(t!==`+`&&t!==`-`&&t!==`*`&&t!==`/`)return W3(`BinOp.op: ${String(t)}`);let n=Z3(e.a);if(!n.ok)return n;let r=Z3(e.b);return r.ok?O(Y2(t,n.value,r.value)):r}function $3(e){let t=e.op;if(!q3(t)||![`neg`,`sin`,`cos`,`sqrt`,`abs`].includes(t))return W3(`UnaryOp.op: ${String(t)}`);let n=Z3(e.arg);return n.ok?O(X2(t,n.value)):n}function e6(e){let t=e.index;if(t!==0&&t!==1&&t!==2)return W3(`Component.index: ${String(t)}`);let n=Z3(e.vec);return n.ok?O(Z2(n.value,t)):n}function t6(e){let t=e.dim;if(t!==2&&t!==3)return W3(`BuildVec.dim: ${String(t)}`);let n=e.components;if(!Array.isArray(n))return W3(`BuildVec.components: not array`);if(n.length!==t)return W3(`BuildVec.components: expected ${t} components, got ${n.length}`);let r=[];for(let e of n){let t=Z3(e);if(!t.ok)return t;r.push(t.value)}return O(Q2(t,r))}function n6(e,t){if(!Array.isArray(e))return W3(`${t}: not array`);let n=[];for(let t of e){let e=i6(t);if(!e.ok)return e;n.push(e.value)}return O(n)}function r6(e){let t=e.tolerance;return t==null?O(void 0):K3(t)?O(t):W3(`tolerance: not a finite number`)}function i6(e){if(!G3(e))return W3(`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 o6(t,e);case`Fuse`:case`Cut`:case`Intersect`:return m6(t,e);case`FuseAll`:case`CutAll`:return h6(t,e);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return g6(t,e);case`Compound`:return S6(e);case`Instance`:return w6(e);default:return W3(`unknown node kind: ${String(t)}`)}}function a6(e,t,n){let r=Z3(e[t]);return r.ok?O(n(r.value)):r}function o6(e,t){switch(e){case`Box`:return s6(t);case`Sphere`:return a6(t,`radius`,w4);case`Cylinder`:return c6(t);case`Cone`:return l6(t);case`Torus`:return u6(t);case`Polygon`:return d6(t);case`Circle`:return a6(t,`radius`,k4);case`Line`:return f6(t);case`Vertex`:return a6(t,`point`,j4);case`Empty`:return p6(t)}return W3(`unhandled primitive: ${e}`)}function s6(e){let t=Z3(e.x);if(!t.ok)return t;let n=Z3(e.y);if(!n.ok)return n;let r=Z3(e.z);return r.ok?O(C4(t.value,n.value,r.value)):r}function c6(e){let t=Z3(e.radius);if(!t.ok)return t;let n=Z3(e.height);return n.ok?O(T4(t.value,n.value)):n}function l6(e){let t=Z3(e.radius1);if(!t.ok)return t;let n=Z3(e.radius2);if(!n.ok)return n;let r=Z3(e.height);return r.ok?O(E4(t.value,n.value,r.value)):r}function u6(e){let t=Z3(e.majorRadius);if(!t.ok)return t;let n=Z3(e.minorRadius);return n.ok?O(D4(t.value,n.value)):n}function d6(e){let t=e.points;if(!Array.isArray(t))return W3(`Polygon.points: not array`);let n=[];for(let e of t){let t=Z3(e);if(!t.ok)return t;n.push(t.value)}return O(O4(n))}function f6(e){let t=Z3(e.from);if(!t.ok)return t;let n=Z3(e.to);return n.ok?O(A4(t.value,n.value)):n}function p6(e){let t=e.output;switch(t){case`Solid`:return O(N4());case`Face`:return O(P4());case`Wire`:return O(F4());default:return W3(`Empty.output: ${String(t)}`)}}function m6(e,t){let n=i6(t.a);if(!n.ok)return n;let r=i6(t.b);if(!r.ok)return r;let i=r6(t);if(!i.ok)return i;switch(e){case`Fuse`:return O(L4(n.value,r.value,i.value));case`Cut`:return O(R4(n.value,r.value,i.value));case`Intersect`:return O(z4(n.value,r.value,i.value))}}function h6(e,t){let n=r6(t);if(!n.ok)return n;if(e===`FuseAll`){let e=n6(t.shapes,`FuseAll.shapes`);return e.ok?O(B4(e.value,n.value)):e}let r=i6(t.base);if(!r.ok)return r;let i=n6(t.tools,`CutAll.tools`);return i.ok?O(V4(r.value,i.value,n.value)):i}function g6(e,t){let n=i6(t.target);if(!n.ok)return n;switch(e){case`Translate`:return _6(t,n.value);case`Rotate`:return y6(t,n.value);case`Scale`:return b6(t,n.value);case`Mirror`:return x6(t,n.value)}}function _6(e,t){let n=Z3(e.vector);return n.ok?O(U4(t,n.value)):n}function v6(e,t){if(e[t]===void 0)return O(void 0);let n=Z3(e[t]);return n.ok?O(n.value):n}function y6(e,t){let n=Z3(e.angle);if(!n.ok)return n;let r=v6(e,`axis`);if(!r.ok)return r;let i=v6(e,`at`);return i.ok?O(W4(t,n.value,{axis:r.value,at:i.value})):i}function b6(e,t){let n=Z3(e.factor);if(!n.ok)return n;let r=v6(e,`center`);return r.ok?O(G4(t,n.value,{center:r.value})):r}function x6(e,t){let n=v6(e,`normal`);if(!n.ok)return n;let r=v6(e,`at`);return r.ok?O(K4(t,{normal:n.value,at:r.value})):r}function S6(e){let t=n6(e.children,`Compound.children`);return t.ok?O(q4(t.value)):t}function C6(e){return Array.isArray(e)&&e.length===4&&e.every(e=>Array.isArray(e)&&e.length===4&&e.every(K3))}function w6(e){let t=i6(e.source);if(!t.ok)return t;let n=e.placements;return!Array.isArray(n)||!n.every(C6)?W3(`Instance.placements must be an array of 4x4 number matrices`):O(J4(t.value,n,e.fuse===!0))}function T6(e){return O6(e)}function E6(e){switch(e.kind){case`NumLit`:case`Vec3Lit`:case`Vec2Lit`:case`Param`:return e;case`BinOp`:{let t=E6(e.a),n=E6(e.b);if(t.kind===`NumLit`&&n.kind===`NumLit`)switch(e.op){case`+`:return G2(t.value+n.value);case`-`:return G2(t.value-n.value);case`*`:return G2(t.value*n.value);case`/`:return G2(t.value/n.value)}return t!==e.a||n!==e.b?Y2(e.op,t,n):e}case`UnaryOp`:{let t=E6(e.arg);if(t.kind===`NumLit`){let n=t.value;switch(e.op){case`neg`:return G2(-n);case`sin`:return G2(Math.sin(n));case`cos`:return G2(Math.cos(n));case`sqrt`:return G2(Math.sqrt(n));case`abs`:return G2(Math.abs(n))}}return t===e.arg?e:X2(e.op,t)}case`Component`:{let t=E6(e.vec);return t.kind===`Vec3Lit`||t.kind===`Vec2Lit`&&(e.index===0||e.index===1)?G2(t.value[e.index]):t===e.vec?e:Z2(t,e.index)}case`BuildVec`:{let t=e.components.map(E6);return D6(e.dim,t)||(t.some((t,n)=>t!==e.components[n])?Q2(e.dim,t):e)}}}function D6(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?q2([n[0],n[1]]):K2([n[0],n[1],n[2]])}function O6(e){switch(e.kind){case`Box`:return C4(E6(e.x),E6(e.y),E6(e.z));case`Sphere`:return w4(E6(e.radius));case`Cylinder`:return T4(E6(e.radius),E6(e.height));case`Cone`:return E4(E6(e.radius1),E6(e.radius2),E6(e.height));case`Torus`:return D4(E6(e.majorRadius),E6(e.minorRadius));case`Polygon`:return O4(e.points.map(E6));case`Circle`:return k4(E6(e.radius));case`Line`:return A4(E6(e.from),E6(e.to));case`Vertex`:return j4(E6(e.point));case`Empty`:return e;case`Fuse`:return k6(e.a,e.b,e.tolerance);case`Cut`:return A6(e.a,e.b,e.tolerance);case`Intersect`:return j6(e.a,e.b,e.tolerance);case`FuseAll`:return M6(e.shapes,e.tolerance);case`CutAll`:return N6(e.base,e.tools,e.tolerance);case`Translate`:return P6(e.target,e.vector);case`Rotate`:return W4(O6(e.target),E6(e.angle),{axis:e.axis?E6(e.axis):void 0,at:e.at?E6(e.at):void 0});case`Scale`:return G4(O6(e.target),E6(e.factor),{center:e.center?E6(e.center):void 0});case`Mirror`:return K4(O6(e.target),{normal:e.normal?E6(e.normal):void 0,at:e.at?E6(e.at):void 0});case`Compound`:return q4(e.children.map(O6).filter(e=>e.kind!==`Empty`));case`Instance`:return J4(O6(e.source),e.placements,e.fuse)}}function k6(e,t,n){let r=O6(e),i=O6(t);return r.kind===`Empty`?i:i.kind===`Empty`?r:L4(r,i,n)}function A6(e,t,n){let r=O6(e),i=O6(t);return i.kind===`Empty`||r.kind===`Empty`?r:R4(r,i,n)}function j6(e,t,n){let r=O6(e),i=O6(t);return r.kind===`Empty`?r:i.kind===`Empty`?i:z4(r,i,n)}function M6(e,t){let n=e.map(O6).filter(e=>e.kind!==`Empty`);return n.length===0?N4():n.length===1?n[0]:B4(n,t)}function N6(e,t,n){let r=O6(e);if(r.kind===`Empty`)return r;let i=t.map(O6).filter(e=>e.kind!==`Empty`);return i.length===0?r:V4(r,i,n)}function P6(e,t){let n=O6(e),r=E6(t);if(r.kind!==`Vec3Lit`)return U4(n,r);let[i,a,o]=r.value;if(i===0&&a===0&&o===0)return n;if(n.kind===`Translate`){let e=E6(n.vector);if(e.kind===`Vec3Lit`)return U4(n.target,[e.value[0]+i,e.value[1]+a,e.value[2]+o])}return U4(n,r)}function F6(e,t,n){return I6(e,t,n)}function I6(e,t,n){return t(e)?n:L6(e,t,n)}function L6(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 L4(I6(e.a,t,n),I6(e.b,t,n),e.tolerance);case`Cut`:return R4(I6(e.a,t,n),I6(e.b,t,n),e.tolerance);case`Intersect`:return z4(I6(e.a,t,n),I6(e.b,t,n),e.tolerance);case`FuseAll`:return B4(e.shapes.map(e=>I6(e,t,n)),e.tolerance);case`CutAll`:return V4(I6(e.base,t,n),e.tools.map(e=>I6(e,t,n)),e.tolerance);case`Translate`:return U4(I6(e.target,t,n),e.vector);case`Rotate`:return W4(I6(e.target,t,n),e.angle,{axis:e.axis,at:e.at});case`Scale`:return G4(I6(e.target,t,n),e.factor,{center:e.center});case`Mirror`:return K4(I6(e.target,t,n),{normal:e.normal,at:e.at});case`Compound`:return q4(e.children.map(e=>I6(e,t,n)));case`Instance`:return J4(I6(e.source,t,n),e.placements,e.fuse)}}function R6(e,t){t(e);for(let n of z6(e))R6(n,t)}function z6(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 B6(e){let t=0;return R6(e,()=>{t++}),t}var V6=TX({CSG_VERSION:()=>1,Evaluator:()=>F3,add:()=>$2,asScalarExpr:()=>t4,asVec2Expr:()=>i4,asVec3Expr:()=>r4,binOp:()=>Y2,box:()=>C4,buildVec:()=>Q2,circle:()=>k4,component:()=>Z2,compound:()=>q4,cone:()=>E4,cut:()=>R4,cutAll:()=>V4,cylinder:()=>T4,emptyFace:()=>P4,emptySolid:()=>N4,emptyWire:()=>F4,foldExpr:()=>E6,forEachNode:()=>R6,fromJSON:()=>X3,fuse:()=>L4,fuseAll:()=>B4,instance:()=>J4,intersect:()=>z4,line:()=>A4,mirror:()=>K4,mul:()=>e4,nodeCount:()=>B6,numLit:()=>G2,optimize:()=>T6,outputKindOf:()=>Y4,param:()=>J2,polygon:()=>O4,replaceNode:()=>F6,rotate:()=>W4,scale:()=>G4,sphere:()=>w4,toJSON:()=>L3,torus:()=>D4,translate:()=>U4,unaryOp:()=>X2,vec2Lit:()=>q2,vec3Lit:()=>K2,vertex:()=>j4,withEvaluator:()=>I3});export{oR as BaseSketcher2d,sR as BlueprintSketcher,co as BrepBugError,N as BrepErrorCode,u0 as BrepWrapperError,ky as BrepkitAdapter,IK as CompoundSketch,i as DEFAULT_CAPABILITIES,vD as DEG2RAD,VT as DisposalScope,r as EXACT_BREP_CAPABILITIES,hq as FaceSketcher,G as HASH_CODE_MAX,Ra as OK,La as OcctWasmAdapter,yD as RAD2DEG,QK as Sketch,mq as Sketcher,$K as Sketches,RP as addChild,AP as addHoles,hF as addJoint,K$ as addMate,XF as addStep,ZM as adjacentFaces,qa as all,Ha as andThen,OX as applyGlue,w1 as applyMatrix,Pk as approximateCurve,ZT as as2D,XT as as3D,XD as asTopo,dN as assignRoles,nM as autoHeal,_P as bezier,pY as blueprintToDXF,qA as booleanPipeline,y2 as booleans,s0 as boss,iP as box,gP as bsplineApprox,M as bug,dq as cameraFromPlane,uq as cameraLookAt,rN as captureHint,nO as cast,ME as castShape,NE as castShape3D,B1 as chamfer,dj as chamferDistAngleShape,Pj as chamferWithEvolution,Y$ as checkAllInterferences,Tj as checkBoolean,J$ as checkInterference,dP as circle,FP as circularPattern,_O as classifyPointOnFace,Wk as clearMeshCache,C1 as clone,oE as closedWire,io as collect,WP as collectShapes,qO as colorFaces,KO as colorShape,fM as complexExtrude,dk as composeTransforms,EP as compound,YK as compoundSketchExtrude,qK as compoundSketchFace,ZK as compoundSketchLoft,XK as compoundSketchRevolve,I as computationError,$Q as computeStraightSkeleton,sP as cone,T2 as construction,NQ as convexHull,fR as cornerFinder,UP as countNodes,MP as createAssembly,LP as createAssemblyNode,DJ as createBlueprint,lq as createCamera,SE as createCompound,OJ as createCompoundBlueprint,WN as createDerivedFaceRef,IM as createDistanceQuery,gE as createEdge,DN as createEdgeRef,vE as createFace,RT as createHandle,YF as createHistory,BT as createKernelHandle,Gk as createMeshCache,UD as createNamedPlane,_X as createOperationRegistry,VD as createPlane,fN as createRef,rI as createRegistry,yE as createShell,bE as createSolid,lX as createTaskQueue,hE as createVertex,FN as createVertexRef,_E as createWire,gX as createWorkerClient,SX as createWorkerHandler,CX as createWorkerPool,V6 as csg,wo as currentQuality,yJ as curve2dBoundingBox,EJ as curve2dDistanceFrom,bJ as curve2dFirstPoint,TJ as curve2dIsOnCurve,xJ as curve2dLastPoint,CJ as curve2dParameter,SJ as curve2dSplitAt,wJ as curve2dTangentAt,Dk as curveAxis,Ck as curveEndPoint,Ok as curveIsClosed,kk as curveIsPeriodic,Ek as curveLength,Ak as curvePeriod,wk as curvePointAt,Sk as curveStartPoint,Tk as curveTangentAt,O1 as cut,QR as cut2D,A1 as cutAll,gj as cutAllBisect,VR as cutBlueprints,jj as cutWithEvolution,aP as cylinder,cF as cylindricalJoint,nN as defaultScorer,dX as dequeueTask,Y1 as describe,Kq as deserializeDrawing,uI as deserializeHistory,iO as deserializeShape,eO as downcast,W1 as draft,Jq as draw,$q as drawCircle,eJ as drawEllipse,sJ as drawFaceOutline,iJ as drawParametricFunction,rJ as drawPointsInterpolation,tJ as drawPolysides,oJ as drawProjection,Xq as drawRectangle,Yq as drawRoundedRectangle,Zq as drawSingleCircle,Qq as drawSingleEllipse,nJ as drawText,pJ as drawingChamfer,uJ as drawingCut,fJ as drawingFillet,lJ as drawingFuse,dJ as drawingIntersect,cJ as drawingToSketchOnPlane,a0 as drill,II as edgeFinder,qM as edgesOfFace,fP as ellipse,hP as ellipseArc,lP as ellipsoid,uX as enqueueTask,k as err,NP as exportAssemblySTEP,fY as exportDXF,$J as exportGlb,QJ as exportGltf,$k as exportIGES,HJ as exportOBJ,Zk as exportSTEP,XY as exportSTEPConfigured,Qk as exportSTL,MY as exportThreeMF,WF as exportURDF,e0 as extrude,bM as extrudeAll,xP as face,gO as faceAxis,hO as faceCenter,zI as faceFinder,sO as faceGeomType,cO as faceOrientation,GM as facesOfEdge,KM as facesOfVertex,xZ as fieldBoolean,TZ as fieldContour,SZ as fieldOffset,wZ as fieldReinit,CZ as fieldShell,wA as fill,SP as filledFace,z1 as fillet,Nj as filletWithEvolution,FO as findFacesByTag,VP as findNode,QF as findStep,aM as fixSelfIntersection,rM as fixShape,Ua as flatMap,Xa as flatten,lO as flipFaceOrientation,Mk as flipOrientation,nX as fontMetrics,yF as forwardKinematics,Z1 as fromBREP,bQ as fromKernelDir,yQ as fromKernelPnt,vQ as fromKernelVec,Qa as fromNullable,D1 as fuse,XR as fuse2D,k1 as fuseAll,bj as fuseAllBisect,BR as fuseBlueprints,Aj as fuseWithEvolution,P0 as gearGeometry,BX as getActiveVoxelId,fD as getBounds,kJ as getBounds2D,iD as getCompSolids,xk as getCurveType,MT as getDisposalStats,QE as getEdges,YO as getFaceColor,SO as getFaceOrigins,IO as getFaceTags,$E as getFaces,nq as getFont,gk as getHashCode,$F as getHistoryShape,U as getKernel,yT as getKernelCapabilities,CT as getKernelTier,fj as getNurbsCurveData,pj as getNurbsSurfaceData,jk as getOrientation,AJ as getOrientation2D,No as getPerformanceStats,JO as getShapeColor,tE as getShapeKind,rD as getShells,HI as getSingleFace,nD as getSolids,oO as getSurfaceType,RO as getTagMetadata,tD as getVertices,zX as getVoxel,eD as getWires,IP as gridPattern,_M as guidedSweep,G1 as heal,$j as healFace,Qj as healSolid,eM as healWire,pP as helix,MQ as hull,e1 as importDXF,_1 as importGLB,$Y as importIGES,i1 as importOBJ,ZY as importSTEP,QY as importSTL,YY as importSVG,JY as importSVGPathD,g1 as importThreeMF,JF as importURDF,DT as init,mT as initFromManifold,TT as initFromOC,VX as initVoxel,bO as innerWires,f$ as instance,m$ as instanceCount,p$ as instanceGrid,_$ as instancedMesh,Nk as interpolateCurve,j1 as intersect,$R as intersect2D,HR as intersectBlueprints,Mj as intersectWithEvolution,ZE as invalidateShapeCache,NF as inverseKinematics,C2 as io,vo as ioError,YT as is2D,JT as is3D,oX as isBatchRequest,AX as isChamferRadius,nE as isClosedWire,rO as isCompSolid,kE as isCompound,qN as isDerivedFaceRef,aX as isDisposeRequest,wE as isEdge,JN as isEdgeRef,$1 as isEmpty,yk as isEqualShape,A as isErr,cX as isErrorResponse,EE as isFace,XN as isFaceRef,jX as isFilletRadius,rX as isInitRequest,jJ as isInside2D,d$ as isInstanced,ZN as isLineageRef,qT as isLive,iE as isManifoldShell,kX as isNumber,za as isOk,iX as isOperationRequest,rE as isOrientedFace,uE as isPlanarFace,dE as isPlanarWire,oq as isProjectionPlane,pX as isQueueEmpty,vk as isSameShape,jE as isShape1D,AE as isShape3D,DE as isShell,OE as isSolid,sX as isSuccessResponse,Q1 as isValid,aE as isValidSolid,CE as isVertex,YN as isVertexRef,TE as isWire,dD as iterCompSolids,aD as iterEdges,oD as iterFaces,uD as iterShells,lD as iterSolids,QD as iterTopo,cD as iterVertices,sD as iterWires,FF as jointTrajectory,mF as jointTransform,RF as jointsFromDH,HE as kernelCall,UE as kernelCallRaw,WE as kernelCallScoped,P as kernelError,fQ as latticeInfill,pQ as latticeInfillShape,uP as line,PP as linearPattern,tq as loadFont,E1 as locate,n0 as loft,SM as loftAll,Tq as makeBaseBox,r2 as makeExternalGear,i2 as makeInternalGear,GD as makePlane,o2 as makePlanetaryGear,cq as makeProjectedEdges,cE as manifoldShell,Ba as map,Za as mapBoth,Va as mapErr,ro as match,h$ as materialize,MM as measureArea,LM as measureCurvatureAt,RM as measureCurvatureAtMid,PM as measureDistance,FM as measureDistanceProps,NM as measureLength,AM as measureLinearProps,kM as measureSurfaceProps,jM as measureVolume,OM as measureVolumeProps,S2 as measurement,bF as mechanismDOF,q1 as mesh,J1 as meshEdges,iA as meshLODs,oA as meshLODsProgressive,eA as meshMultiLOD,LQ as minkowski,x1 as mirror,IJ as mirror2D,_J as mirrorDrawing,c0 as mirrorJoin,b2 as modifiers,cI as modifyStep,_o as moduleInitError,gM as multiSectionSweep,mO as normalAt,H1 as offset,OP as offsetFace,rZ as offsetMesh,oZ as offsetShape,Fk as offsetWire2D,O as ok,Wa as or,Ga as orElse,XL as organiseBlueprints,sE as orientedFace,vO as outerWire,E2 as patterns,fX as pendingCount,so as pipeline,JD as pivotPlane,fE as planarFace,lF as planarJoint,pE as planarWire,Q0 as planetPlacements,o0 as pocket,dO as pointOnSurface,KX as pointsInside,wP as polygon,RQ as polyhedron,xq as polysideInnerRadius,pR as polysidesBlueprint,Ij as positionOnCurve,ET as prewarm,v2 as primitives,sF as prismaticJoint,fq as projectEdges,pO as projectPointOnFace,w2 as query,yo as queryError,l0 as rectangularPattern,vX as registerHandler,hT as registerKernel,ST as registerKernelTier,iI as registerOperation,nI as registerShape,RX as registerVoxel,mX as rejectAll,zP as removeChild,yO as removeHolesFromFace,YX as repairMesh,sI as replayFrom,oI as replayHistory,NT as resetDisposalStats,Po as resetPerformanceStats,ok as resize,$ as resolve,v1 as resolve3D,GN as resolveDerivedFaceRef,CD as resolveDirection,ON as resolveEdgeRef,$N as resolveLineageRef,WD as resolvePlane,vN as resolveRef,tP as resolveRefIn,rP as resolveRefParams,IN as resolveVertexRef,vJ as reverseCurve,oF as revoluteJoint,t0 as revolve,s$ as roof,b1 as rotate,PJ as rotate2D,hJ as rotateDrawing,mR as roundedRectangleBlueprint,S1 as scale,FJ as scale2D,gJ as scaleDrawing,VZ as sdfBox,GZ as sdfCapsule,WZ as sdfCone,UZ as sdfCylinder,rQ as sdfFieldAxialRamp,oQ as sdfFieldClamp,nQ as sdfFieldConst,aQ as sdfFieldFromSdf,iQ as sdfFieldRadialRamp,ZZ as sdfLattice,qZ as sdfPlane,HZ as sdfRoundedBox,BZ as sdfSphere,QZ as sdfStrutLattice,YZ as sdfSweep,KZ as sdfTorus,M1 as section,N1 as sectionToFace,lI as serializeHistory,fF as setJointValue,dF as setJointValues,xO as setShapeOrigin,LO as setTagMetadata,kP as sewShells,O0 as shape,ZX as shapeToMeshInput,$D as shapeType,eN as sharedEdges,V1 as shell,iZ as shellMesh,sZ as shellShape,Fj as shellWithEvolution,K1 as simplify,gq as sketchCircle,_q as sketchEllipse,UK as sketchExtrude,BK as sketchFace,Sq as sketchFaceOffset,wq as sketchHelix,GK as sketchLoft,zJ as sketchOnFace2D,RJ as sketchOnPlane2D,Cq as sketchParametricFunction,bq as sketchPolysides,vq as sketchRectangle,HK as sketchRevolve,yq as sketchRoundedRectangle,WK as sketchSweep,eX as sketchText,VK as sketchWires,go as sketcherStateError,F1 as slice,DP as solid,iM as solidFromShell,q$ as solveAssembly,oP as sphere,uF as sphericalJoint,P1 as split,eI as stepCount,tI as stepsFrom,LJ as stretch2D,CP as subFace,dM as supportExtrude,uT as supportsConstraintSketch,lT as supportsProjection,DQ as surfaceFromGrid,AQ as surfaceFromImage,uM as sweep,PO as tagFaces,vP as tangentArc,Ja as tap,Ya as tapErr,iq as textBlueprints,tX as textMetrics,U1 as thicken,dI as thread,mP as threePointArc,X1 as toBREP,oj as toBufferGeometryData,sj as toGroupedBufferGeometryData,hQ as toKernelVec,lj as toLODGeometryData,uj as toLODGeometryLevels,cj as toLineGeometryData,MJ as toSVGPathD,xD as toVec2,bD as toVec3,cP as torus,mQ as tpmsLattice,T1 as transformCopy,x2 as transforms,y1 as translate,NJ as translate2D,mJ as translateDrawing,qD as translatePlane,ao as tryCatch,oo as tryCatchAsync,pM as twistExtrude,ho as typeCastError,ZF as undoLast,bo as unsupportedError,j as unwrap,no as unwrapErr,eo as unwrapOr,to as unwrapOrElse,BP as updateNode,mN as updateRoles,uO as uvBounds,fO as uvCoordinates,lE as validSolid,z0 as validatePlanetary,F as validationError,Xj as variableFillet,wD as vecAdd,ID as vecAngle,kD as vecCross,MD as vecDistance,OD as vecDot,PD as vecEquals,FD as vecIsZero,AD as vecLength,jD as vecLengthSq,DD as vecNegate,ND as vecNormalize,LD as vecProjectToPlane,BD as vecRepr,RD as vecRotate,ED as vecScale,TD as vecSub,TP as vertex,PX as vertexFinder,_D as vertexPosition,XM as verticesOfEdge,JM as verticesOfFace,aZ as voxelBoolean,bZ as voxelBooleanField,DZ as voxelBooleanFieldShapes,cZ as voxelBooleanShapes,yZ as voxelField,EZ as voxelFieldFromShape,HP as walkAssembly,GX as windingNumbers,yP as wire,VI as wireFinder,bP as wireLoop,YM as wiresOfFace,vT as withKernel,CQ as withKernelDir,SQ as withKernelPnt,xQ as withKernelVec,bT as withQuality,HT as withScope,GT as withScopeResult,KT as withScopeResultAsync,wT as withTier,Ka as zipResults};