brepjs-cad 0.94.0 → 0.96.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +84 -0
- package/package.json +1 -1
- package/viewer/dist/assets/{brepjs-By5zhkbr.js → brepjs-42d18nEr.js} +16 -16
- package/viewer/dist/assets/{index-CdmuHLtd.js → index-CAqC8r21.js} +1 -1
- package/viewer/dist/assets/{kernelWorker-24XPVxhk.js → kernelWorker-BDC3iPOp.js} +1 -1
- package/viewer/dist/index.html +1 -1
|
@@ -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 lw(e,{vertProperties:Float32Array.from(r),triVerts:Uint32Array.from(i)})}function dw(e,t){let n=new Uint8Array(t),r=new TextDecoder().decode(n.subarray(0,Math.min(n.length,80))).trimStart().toLowerCase().startsWith(`solid`)&&mw(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=pw(i);return lw(e,{vertProperties:Float32Array.from(a.vertices),triVerts:Uint32Array.from(a.indices)})}var fw=1e6;function pw(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*fw)},${Math.round(o*fw)},${Math.round(s*fw)}`,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 mw(e){return e.length<84?!0:84+new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(80,!0)*50!==e.length}var hw=1e-6;function gw(e,t){let n=V(t);if(n.replayable)return sC(n,e)}function _w(e,t){let n=ew(t),r=Math.floor(n.triVerts.length/3),i=[];for(let t=0;t<r;t++){let[r,a,o]=iw(n,t),s=e.buildTriFace(rw(n,r),rw(n,a),rw(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,hw)}function vw(e){let t=Ky(`B-rep export`),n=gw(t,e);return n===void 0?(console.warn(`manifold: exact B-rep unavailable (non-replayable op-graph); exporting faceted approximation`),{occt:t,brep:_w(t,e)}):{occt:t,brep:n}}function yw(e,t,n,r){let i=t.mesh(n,{tolerance:.01,angularTolerance:.5});return lw(e,{vertProperties:Float32Array.from(i.vertices),triVerts:Uint32Array.from(i.triangles)},r)}var bw=1179937895,xw=2,Sw=1313821514,Cw=5130562,ww=5126,Tw=5125,Ew=5123,Dw=5121,Ow=34962,kw=34963,Aw=4;function jw(e){return e+3&-4}function Mw(e){let t=ew(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=jw(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:Aw}]}],accessors:[{bufferView:0,componentType:ww,count:r,type:`VEC3`,min:[o,s,c],max:[l,u,d]},{bufferView:1,componentType:Tw,count:i,type:`SCALAR`}],bufferViews:[{buffer:0,byteOffset:0,byteLength:p,target:Ow},{buffer:0,byteOffset:m,byteLength:f.byteLength,target:kw}],buffers:[{byteLength:h}]},_=new TextEncoder().encode(JSON.stringify(g)),v=jw(_.length),y=jw(h),b=20+v+8+y,x=new ArrayBuffer(b),S=new DataView(x),C=new Uint8Array(x);S.setUint32(0,bw,!0),S.setUint32(4,xw,!0),S.setUint32(8,b,!0);let w=12;S.setUint32(w,v,!0),S.setUint32(w+4,Sw,!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,Cw,!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 Nw(e,t){let n=new DataView(t);if(n.getUint32(0,!0)!==bw)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===Sw?i=JSON.parse(new TextDecoder().decode(s)):r===Cw&&(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===Tw?4:e.componentType===Ew?2:+(e.componentType===Dw);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 lw(e,{vertProperties:p,triVerts:m},`importGLB`)}function Pw(e){return{exportSTL:(e,t)=>ow(e,t),exportOBJ:e=>sw(e),exportPLY:e=>cw(e),importSTL:t=>dw(e,typeof t==`string`?new TextEncoder().encode(t).buffer:t),importOBJ:t=>uw(e,t),exportSTEP:e=>Ky(`exportSTEP`).exportSTEP(e.map(e=>vw(e).brep)),exportIGES:e=>Ky(`exportIGES`).exportIGES(e.map(e=>vw(e).brep)),toBREP:e=>{let{occt:t,brep:n}=vw(e);return t.toBREP(n)},exportSTEPAssembly:(e,t)=>{let n=Ky(`exportSTEPAssembly`),r=e.map(e=>{let t={shape:vw(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=Ky(`createXCAFDocument`),n=e.map(e=>{let t={shape:vw(e.shape).brep,name:e.name};return e.color===void 0?t:{...t,color:e.color}});return t.createXCAFDocument(n)},writeXCAFToSTEP:(e,t)=>Ky(`writeXCAFToSTEP`).writeXCAFToSTEP(e,t),exportSTEPConfigured:(e,t)=>{let n=Ky(`exportSTEPConfigured`),r=e.map(e=>{let t={shape:vw(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=Ky(`importSTEP`);return n.importSTEP(t).map(t=>yw(e,n,t,`importSTEP`))},importIGES:t=>{let n=Ky(`importIGES`);return n.importIGES(t).map(t=>yw(e,n,t,`importIGES`))},fromBREP:t=>{let n=Ky(`fromBREP`);return yw(e,n,n.fromBREP(t),`fromBREP`)},exportGLB:e=>Mw(e),importGLB:t=>Nw(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 Fw(e){return B(e).getMesh()}function Iw(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 Lw(e,t){let n=e;if(n&&n.__manifoldSub&&n.occt){let e=Gy();if(!e)throw new c(`manifold: sub-shape geometry query requires a registered occt kernel`);return t(n.occt,e)}let r=Uy(e);if(!r)throw Error(`manifold: exact geometry query requires a manifold shape handle`);let i=Gy();if(!i)throw new c(`manifold: exact geometry query unsupported on manifold kernel; no B-rep kernel registered`);if(!r.node.replayable)throw Error(`manifold: exact geometry query unsupported; shape originates from a non-replayable op (raw mesh import or mesh boolean)`);let a=qy.get(r.node);return a===void 0&&(a=sC(r.node,i),qy.set(r.node,a)),t(a,i)}function Rw(e){let t=Uy(e);if(!t)return;let n=t.node;return n.op===`profileEdge`?n.params?.curve:void 0}function zw(e){return{curveType:e=>{let t=Rw(e);return t?Nb(t):HC(e)?e.curveType:Lw(e,(e,t)=>t.curveType(e))},curveParameters:e=>{let t=Rw(e);if(t){let e=Pb(t);return[e.first,e.last]}return HC(e)?[0,e.length]:Lw(e,(e,t)=>t.curveParameters(e))},curvePointAtParam:(e,t)=>{let n=Rw(e);return n?Fb(n,t):HC(e)?UC(e,t):Lw(e,(e,n)=>n.curvePointAtParam(e,t))},curveTangent:(e,t)=>{let n=Rw(e);return n?{point:Fb(n,t),tangent:Ib(n,t)}:HC(e)?{point:UC(e,t),tangent:WC(e,t)}:Lw(e,(e,n)=>n.curveTangent(e,t))},curveIsClosed:e=>{let t=Rw(e);return t?Rb(t):Lw(e,(e,t)=>t.curveIsClosed(e))},curveIsPeriodic:e=>{let t=Rw(e);return t?zb(t):Lw(e,(e,t)=>t.curveIsPeriodic(e))},curvePeriod:e=>{let t=Rw(e);return t?Bb(t):Lw(e,(e,t)=>t.curvePeriod(e))},interpolatePoints:(e,t)=>Ky(`interpolatePoints`).interpolatePoints(e,t),approximatePoints:(e,t)=>Ky(`approximatePoints`).approximatePoints(e,t),curveDegreeElevate:(e,t)=>Lw(e,(e,n)=>n.curveDegreeElevate(e,t)),curveKnotInsert:(e,t,n)=>Lw(e,(e,r)=>r.curveKnotInsert(e,t,n)),curveKnotRemove:(e,t,n)=>Lw(e,(e,r)=>r.curveKnotRemove(e,t,n)),curveSplit:(e,t)=>Lw(e,(e,n)=>n.curveSplit(e,t)),createCurveAdaptor:e=>Lw(e,(e,t)=>t.createCurveAdaptor(e)),getBezierPenultimatePole:e=>Lw(e,(e,t)=>t.getBezierPenultimatePole(e)),getNurbsCurveData:e=>Lw(e,(e,t)=>t.getNurbsCurveData?.(e)??null),vertexPosition:e=>VC(e)?e.point:Uy(e)?Iw(Fw(e),0):Lw(e,(e,t)=>t.vertexPosition(e)),surfaceType:e=>{if(MC(e))return`plane`;let t=Uy(e);return t&&t.node.op===`profileFace`?`plane`:Lw(e,(e,t)=>t.surfaceType(e))},uvBounds:e=>MC(e)?{uMin:0,uMax:1,vMin:0,vMax:1}:Lw(e,(e,t)=>t.uvBounds(e)),outerWire:e=>Lw(e,(e,t)=>t.outerWire(e)),surfaceNormal:(e,t,n)=>MC(e)?e.normal:Lw(e,(e,r)=>r.surfaceNormal(e,t,n)),pointOnSurface:(e,t,n)=>Lw(e,(e,r)=>r.pointOnSurface(e,t,n)),uvFromPoint:(e,t)=>Lw(e,(e,n)=>n.uvFromPoint(e,t)),projectPointOnFace:(e,t)=>Lw(e,(e,n)=>n.projectPointOnFace(e,t)),classifyPointOnFace:(e,t,n,r)=>Lw(e,(e,i)=>i.classifyPointOnFace(e,t,n,r)),classifyPointRobust:(e,t,n)=>Lw(e,(e,r)=>r.classifyPointRobust(e,t,n)),classifyPointWinding:(e,t,n)=>Lw(e,(e,r)=>r.classifyPointWinding(e,t,n)),approximateSurfaceLspia:(e,t,n,r,i,a,o,s,c)=>Ky(`approximateSurfaceLspia`).approximateSurfaceLspia(e,t,n,r,i,a,o,s,c),untrimFace:(e,t,n)=>Lw(e,(e,r)=>r.untrimFace(e,t,n)),getSurfaceCylinderData:e=>Lw(e,(e,t)=>t.getSurfaceCylinderData(e)),getSurfaceAxis:e=>Lw(e,(e,t)=>t.getSurfaceAxis(e)),reverseSurfaceU:e=>Ky(`reverseSurfaceU`).reverseSurfaceU(e),detectSmallFeatures:(e,t,n)=>Lw(e,(e,r)=>r.detectSmallFeatures(e,t,n)),recognizeFeatures:(e,t)=>Lw(e,(e,n)=>n.recognizeFeatures(e,t)),projectEdges:(e,t,n,r)=>Lw(e,(e,i)=>i.projectEdges(e,t,n,r)),getNurbsSurfaceData:e=>Lw(e,(e,t)=>t.getNurbsSurfaceData?.(e)??null)}}var Bw={hasErrors:!1,hasWarnings:!1,messages:[]};function Vw(){return{modified:new Map,generated:new Map,deleted:new Set}}function Hw(e){return{shape:e,evolution:Vw()}}function Uw(e){return{shape:e,evolution:Vw(),diagnostics:Bw}}function Ww(e){let t=Eb(e),n=ib(e),r=jS(e);return{translateWithHistory:(e,n,r,i)=>Hw(t.translate(e,n,r,i)),rotateWithHistory:(e,n,r,i,a,o)=>Hw(t.rotate(e,n,a,o)),mirrorWithHistory:(e,n,r)=>Hw(t.mirror(e,n,r)),scaleWithHistory:(e,n,r)=>Hw(t.scale(e,n,r)),generalTransformWithHistory:(e,n,r,i)=>Hw(t.generalTransform(e,n,r,i)),fuseWithHistory:(e,t,r,i,a)=>Uw(n.fuse(e,t,a)),cutWithHistory:(e,t,r,i,a)=>Uw(n.cut(e,t,a)),intersectWithHistory:(e,t,r,i,a)=>Uw(n.intersect(e,t,a)),filletWithHistory:(e,t,n)=>Hw(r.fillet(e,t,n)),chamferWithHistory:(e,t,n)=>Hw(r.chamfer(e,t,n)),shellWithHistory:(e,t,n,i,a,o)=>Hw(r.shell(e,t,n,o)),thickenWithHistory:(e,t)=>Hw(r.thicken(e,t)),offsetWithHistory:(e,t,n,i,a)=>Hw(r.offset(e,t,a)),draftWithHistory:(e,t,n,i,a)=>Hw(r.draft(e,t,n,i,a)),applyComposedTransformWithHistory:(e,n)=>Hw(t.transform(e,n))}}function Gw(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 Kw(e){return{isValid:e=>Gw(e),isValidStrict:e=>Gw(e),healSolid:e=>Gw(e)?e:null,healFace:e=>e,healWire:e=>e,mergeCoincidentVertices:()=>0,removeDegenerateEdges:()=>0,fixFaceOrientations:()=>0,fixShape:e=>e,fixSelfIntersection:e=>e}}var qw=.004;function Jw(e){return!!e&&typeof e==`object`&&e.__nativeC2d===!0}function Yw(e,t){return{__nativeC2d:!0,k:`line`,p1:e,p2:t}}function Xw(e,t,n,r,i){return{__nativeC2d:!0,k:`conic`,c:e,u:t,v:n,a0:r,a1:i}}function Zw(e,[t,n]){return[e.a*t+e.b*n+e.tx,e.c*t+e.d*n+e.ty]}function Qw(e,[t,n]){return[e.a*t+e.b*n,e.c*t+e.d*n]}function $w(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 eT(e,t){return e.k===`line`?Yw(Zw(t,e.p1),Zw(t,e.p2)):e.k===`bezier`?{__nativeC2d:!0,k:`bezier`,pts:e.pts.map(e=>Zw(t,e))}:Xw(Zw(t,e.c),Qw(t,e.u),Qw(t,e.v),e.a0,e.a1)}function tT(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 nT(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 rT(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 tT(r,t)}function iT(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<=qw)return Math.max(2,Math.ceil(t/(2*Math.PI)*8));let a=2*Math.acos(Math.max(-1,1-qw/i));return Math.max(2,Math.ceil(t/a))}function aT(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(tT(e.pts,n/24));return t}let t=e.a1-e.a0,n=iT(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 oT(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 Yw(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-_),Xw(f,[p,0],[0,p],h,_)}function sT(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(!Jw(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=nT(n,n.a0),i=nT(n,(n.a0+n.a1)/2),a=nT(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(aT(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)=>Yw([e,t],[n,r]),makeCircle2d:(e,t,n,r=!0)=>Xw([e,t],[n,0],r?[0,n]:[0,-n],0,2*Math.PI),makeArc2dThreePoints:(e,t,n,r,i,a)=>oT([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 Yw([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),Xw([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 Xw([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 Xw([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`?tT(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:tT(n.pts,t),tangent:rT(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 Xw(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 Yw([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=$w(e,t);Object.assign(e,n)},transformCurve2dGeneral:(e,t)=>eT(i(e),t),translateCurve2d:(e,t,n)=>eT(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 eT(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)=>eT(i(e),{a:t,b:0,c:0,d:t,tx:n-t*n,ty:r-t*r}),mirrorCurve2dAtPoint:(e,t,n)=>eT(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 eT(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 eT(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(Jw(t))r=aT(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=aT(i(e)).map(([e,n])=>[t[0]+l*e+f*n,t[1]+u*e+p*n,t[2]+d*e+m*n]);return z(n,R(`profileEdge`,{pts:h},[]))},makeBSpline2d:(e,t)=>a(`makeBSpline2d`).makeBSpline2d(e,t),offsetCurve2d:(e,t)=>a(`offsetCurve2d`).offsetCurve2d(o(e),t),intersectCurves2d:(e,t,n)=>a(`intersectCurves2d`).intersectCurves2d(o(e),o(t),n),projectPointOnCurve2d:(e,t,n)=>a(`projectPointOnCurve2d`).projectPointOnCurve2d(o(e),t,n),distanceBetweenCurves2d:(e,t,n,r,i,s)=>a(`distanceBetweenCurves2d`).distanceBetweenCurves2d(o(e),o(t),n,r,i,s),approximateCurve2dAsBSpline:(e,t,n,r)=>a(`approximateCurve2dAsBSpline`).approximateCurve2dAsBSpline(o(e),t,n,r),decomposeBSpline2dToBeziers:e=>a(`decomposeBSpline2dToBeziers`).decomposeBSpline2dToBeziers(o(e)),serializeCurve2d:e=>a(`serializeCurve2d`).serializeCurve2d(o(e)),deserializeCurve2d:e=>a(`deserializeCurve2d`).deserializeCurve2d(e),splitCurve2d:(e,t)=>a(`splitCurve2d`).splitCurve2d(o(e),t),getCurve2dEllipseData:e=>a(`getCurve2dEllipseData`).getCurve2dEllipseData(o(e)),getCurve2dBezierPoles:e=>a(`getCurve2dBezierPoles`).getCurve2dBezierPoles(o(e)),getCurve2dBezierDegree:e=>a(`getCurve2dBezierDegree`).getCurve2dBezierDegree(o(e)),getCurve2dBSplineData:e=>a(`getCurve2dBSplineData`).getCurve2dBSplineData(o(e)),buildEdgeOnSurface:(e,t)=>a(`buildEdgeOnSurface`).buildEdgeOnSurface(o(e),t),extractSurfaceFromFace:e=>a(`extractSurfaceFromFace`).extractSurfaceFromFace(e),extractCurve2dFromEdge:(e,t)=>a(`extractCurve2dFromEdge`).extractCurve2dFromEdge(e,t),buildCurves3d:e=>{a(`buildCurves3d`).buildCurves3d(e)},fixWireOnFace:(e,t,n)=>a(`fixWireOnFace`).fixWireOnFace(e,t,n),fillSurface:(e,t)=>a(`fillSurface`).fillSurface(e,t)};for(let e of[`evaluateCurve2d`,`evaluateCurve2dD1`,`getCurve2dBounds`,`getCurve2dType`,`reverseCurve2d`,`copyCurve2d`,`trimCurve2d`,`transformCurve2dGeneral`,`translateCurve2d`,`rotateCurve2d`,`scaleCurve2d`,`mirrorCurve2dAtPoint`,`mirrorCurve2dAcrossAxis`,`affinityTransform2d`,`getCurve2dCircleData`,`liftCurve2dToPlane`]){let t=s[e];t&&(s[e]=((n,...i)=>Jw(n)?t(n,...i):r(e,n,...i)))}return s}var cT=`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 lT(e){let t=Gy();if(!t)throw Error(`manifold: ${e} unsupported on manifold kernel; no B-rep kernel registered`);return t}function uT(e){let t={};for(let e of cT)t[e]=(...t)=>lT(e)[e](...t);let n=sT(e,()=>Gy());return Object.assign(t,n),t}function dT(e){return{sketchNew:()=>zy(`sketchNew`),sketchAddPoint:()=>zy(`sketchAddPoint`),sketchAddArc:()=>zy(`sketchAddArc`),sketchAddConstraint:()=>zy(`sketchAddConstraint`),sketchSolve:()=>zy(`sketchSolve`),sketchDof:()=>zy(`sketchDof`)}}function fT(e){return{projectEdges:()=>zy(`projectEdges`)}}function pT(e){return{dispose(e){let t=Uy(e);if(t){let e=qy.get(t.node);e!==void 0&&(Gy()?.dispose(e),qy.delete(t.node))}(e?.manifold)?.delete?.()},executeBatch:()=>zy(`executeBatch`),checkpoint:()=>zy(`checkpoint`),checkpointCount:()=>0,restoreCheckpoint:()=>zy(`restoreCheckpoint`),discardCheckpoint:()=>zy(`discardCheckpoint`)}}var mT={draft:30,standard:10,fine:3},hT=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?.(mT[e])}constructor(e){this.oc=e,Object.assign(this,$y(e),ib(e),Eb(e),Nx(e),aS(e),jS(e),zS(e),kC(e),$C(e),Pw(e),zw(e),Ww(e),Kw(e),uT(e),dT(e),fT(e),pT(e))}};function gT(e){return import(e)}function _T(e){return`projectEdges`in e}function vT(e){return`sketchNew`in e&&`sketchDof`in e}var yT=new Map,bT=null,xT=null;function ST(e){CT(`manifold`,new hT(e))}function CT(e,t){yT.set(e,t),bT||=e,e===bT&&(xT=t)}function H(e){if(!e&&xT)return xT;let t=e??bT;if(!t)throw Error(`brepjs kernel not initialized. Call initFromOC() or registerKernel() before using the library.`);let n=yT.get(t);if(!n)throw Error(`brepjs: kernel '${t}' is not registered.`);return n}function wT(e){let t=H(e);if(!Io(t))throw Error(`brepjs: current kernel does not support 2D operations.`);return t}function TT(){return bT}function ET(e,t){let n=bT;bT=e,xT=yT.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{bT=n,xT=n?yT.get(n)??null:null}}function DT(e){return H(e).capabilities}function OT(e,t){let n=No();try{Fo(e),H().setQuality?.(e);let n=t();if(n instanceof Promise)throw Error(`withQuality() callback returned a Promise. Async code must read currentQuality()/getKernel() directly.`);return n}finally{Fo(n),H().setQuality?.(n)}}var kT=new Map;function AT(e,t){kT.set(e,t)}function jT(e){return kT.get(e)}function MT(e,t){let n=kT.get(e);if(!n)throw Error(`withTier: no tier registered for "${e}". Call registerKernelTier("${e}", { kernel, quality }) first.`);return ET(n.kernel,()=>OT(n.quality,t))}function NT(e){Qo(),fl(),Go(),Hc(),Uc(),il(),al();let t=new Jf(e);CT(`occt`,t),bT=`occt`,xT=t}function PT(){let e=H(),t=e.makeBox(1,1,1);try{e.dispose(t)}catch{}}async function FT(){if(bT)return bT;try{let{OcctKernel:e}=await gT(`occt-wasm`),t=await e.init();return CT(`occt-wasm`,Ka.fromKernel(t)),`occt-wasm`}catch{}try{return NT(await(await gT(`brepjs-opencascade`)).default()),`occt`}catch{}try{let e=await gT(`brepkit-wasm`);return typeof e.default==`function`&&await e.default(),CT(`brepkit`,new Ry(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 IT(){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 LT=Symbol;LT.dispose??=Symbol.for(`Symbol.dispose`),LT.asyncDispose??=Symbol.for(`Symbol.asyncDispose`);var RT=globalThis;RT.FinalizationRegistry||=(console.warn(`brepjs: FinalizationRegistry unavailable — garbage collection will not work`),class{register(e,t,n){}unregister(e){return!1}});var zT={liveHandles:0,peakHandles:0,gcCollected:0,scopeEnters:0,scopeExits:0};function BT(){return{...zT}}function VT(){zT.liveHandles=0,zT.peakHandles=0,zT.gcCollected=0,zT.scopeEnters=0,zT.scopeExits=0}function HT(){zT.liveHandles++,zT.liveHandles>zT.peakHandles&&(zT.peakHandles=zT.liveHandles)}function UT(){zT.liveHandles--}function WT(){zT.gcCollected++,zT.liveHandles--}var GT=new FinalizationRegistry(e=>{WT();try{e.delete()}catch{}});function KT(e){let t=H(),n=!1,r,i=()=>{if(r){for(let e of r)try{e()}catch{}r=void 0}},a=()=>{if(!n){n=!0,UT(),GT.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 HT(),GT.register(o,{delete:()=>{t.dispose(e)}},o),o}function qT(e){let t=()=>{};return{get wrapped(){return e},get disposed(){return!1},[Symbol.dispose]:t,delete:t,onDispose:t}}function JT(e){let t=H(),n;try{n=t.checkpoint()}catch(t){if(!l(t))throw t;return e()}let r;try{r=e()}catch(e){try{t.restoreCheckpoint(n)}catch{}throw e}return t.restoreCheckpoint(n),r}function YT(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,UT(),GT.unregister(n);try{e.delete()}catch{}}}};return HT(),GT.register(n,e,n),n}var XT=class{handles=[];constructor(){zT.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](){zT.scopeExits++;for(let e=this.handles.length-1;e>=0;e--)this.handles[e]?.();this.handles.length=0}};function ZT(e){try{var t=IT();return e(t.u(new XT))}catch(e){t.e=e}finally{t.d()}}function QT(e,t){GT.register(e,t,t)}function $T(e){GT.unregister(e)}function eE(e){try{var t=IT();return e(t.u(new XT))}catch(e){t.e=e}finally{t.d()}}async function tE(e){try{var t=IT();return await e(t.u(new XT))}catch(e){t.e=e}finally{t.d()}}function nE(e){return!e.disposed}function rE(e){return e.__is2D!==!0}function iE(e){return e.__is2D===!0}function aE(e){if(!rE(e))throw Error(`Expected 3D shape, got 2D`);return e}function oE(e){if(!iE(e))throw Error(`Expected 2D shape, got 3D`);return e}var sE=new WeakMap;function cE(e,t){sE.set(e,t)}function lE(e,t){let n=sE.get(t);if(n!==void 0)return n;let r=e.shapeType(t);return sE.set(t,r),r}function uE(e){return lE(H(),e.wrapped)}function dE(e){return H().curveIsClosed(e.wrapped)}function fE(e){return H().isValid(e.wrapped)}function pE(e){let t=H();if(!t.isValid(e.wrapped))return!1;let n=t.isValidStrict?.bind(t)??t.isValid.bind(t);try{let r=t.solidFromShell(e.wrapped),i=n(r);try{t.dispose(r)}catch{}return i}catch{return!1}}function mE(e){return H().isValid(e.wrapped)}function hE(e){return dE(e)?O(e):k(`Wire is not closed: start and end points do not coincide`)}function gE(e){return fE(e)?O(e):k(`Face orientation is inconsistent or face is invalid`)}function _E(e){return pE(e)?O(e):k(`Shell is not manifold: has free edges or is invalid`)}function vE(e){return mE(e)?O(e):k(`Solid failed BRepCheck validation`)}function yE(e){return H().surfaceType(e.wrapped)===`plane`}function bE(e){let t=H(),n=n=>{try{let r=t.makeFace(e.wrapped,n),i=t.surfaceType(r);try{t.dispose(r)}catch{}return i===`plane`}catch{return!1}};return n(!0)?!0:n(!1)}function xE(e){return yE(e)?O(e):k(`Face is not planar: underlying surface is not a geometric plane`)}function SE(e){return bE(e)?O(e):k(`Wire is not planar: edges do not lie in a common plane`)}function CE(e,t){return t===`2D`&&(e.__is2D=!0),e}function wE(e,t){return CE(KT(e),t)}function TE(e,t){return CE(KT(e),t)}function EE(e,t){return CE(KT(e),t)}function DE(e,t){return CE(KT(e),t)}function OE(e){return CE(KT(e))}function kE(e){return CE(KT(e))}function AE(e){return CE(KT(e))}function jE(e,t){return CE(KT(e),t)}function ME(e){return uE(e)===`vertex`}function NE(e){return uE(e)===`edge`}function PE(e){return uE(e)===`wire`}function FE(e){return uE(e)===`face`}function IE(e){return uE(e)===`shell`}function LE(e){return uE(e)===`solid`}function RE(e){return uE(e)===`compound`}function zE(e){let t=uE(e);return t===`shell`||t===`solid`||t===`compsolid`?!0:t===`compound`?rE(e):!1}function BE(e){let t=uE(e);return t===`edge`||t===`wire`}function VE(e,t){let n=H(),r=lE(n,e),i=n.downcast(e,r);return r===`vertex`?wE(i,t):r===`edge`?TE(i,t):r===`wire`?EE(i,t):r===`face`?DE(i,t):r===`shell`?OE(i):r===`solid`?kE(i):r===`compsolid`?AE(i):jE(i,t)}function HE(e){return VE(e)}function UE(e,t){let n=e.id,r=t.wrapped.id;(n!==void 0&&r!==void 0?n===r:t.wrapped===e)||H().dispose(e)}function U(e,t){let n=VE(e,t);return UE(e,n),n}function WE(e,t){let n=e.wrapped;if(e[Symbol.dispose](),n!==t){let e=H();e.dispose(n),e.dispose(t)}}function W(e){H().dispose(e.wrapped),e[Symbol.dispose]()}function GE(e,t,n){cE(e,t);let r=H().downcast(e,t);return t===`vertex`?wE(r,n):t===`edge`?TE(r,n):t===`wire`?EE(r,n):t===`face`?DE(r,n):t===`shell`?OE(r):t===`solid`?kE(r):t===`compsolid`?AE(r):jE(r,n)}function KE(e,t,n){let r=GE(e,t,n);return UE(e,r),r}function qE(e,t,n){return cE(e,t),CE(qT(e),n)}var G=2147483647,JE=Math.PI/180,YE=180/Math.PI;function XE(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)=>XE(`KERNEL_OPERATION`,e,t,n,r),VALIDATION:(e,t,n,r)=>XE(`VALIDATION`,e,t,n,r),TYPE_CAST:(e,t,n,r)=>XE(`TYPE_CAST`,e,t,n,r),SKETCHER_STATE:(e,t,n,r)=>XE(`SKETCHER_STATE`,e,t,n,r),MODULE_INIT:(e,t,n,r)=>XE(`MODULE_INIT`,e,t,n,r),COMPUTATION:(e,t,n,r)=>XE(`COMPUTATION`,e,t,n,r),IO:(e,t,n,r)=>XE(`IO`,e,t,n,r),QUERY:(e,t,n,r)=>XE(`QUERY`,e,t,n,r),UNSUPPORTED:(e,t,n,r)=>XE(`UNSUPPORTED`,e,t,n,r)};function QE(e,t,n,r=`KERNEL_OPERATION`){try{return O(U(e()))}catch(e){let i=e instanceof Error?e.message:String(e),a=r===`KERNEL_OPERATION`?xo(i):i,o=bo(t);return k(ZE[r](t,`${n}: ${a}`,e,o))}}function $E(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`?xo(i):i,o=bo(t);return k(ZE[r](t,`${n}: ${a}`,e,o))}}function eD(e,t,n,r=`KERNEL_OPERATION`){try{var i=IT();let a=i.u(new XT);return QE(()=>e(a),t,n,r)}catch(e){i.e=e}finally{i.d()}}function tD(e,t){let n=H().iterShapes(e,t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=KE(n[e],t);return r}function nD(e,t){let n=H();if(n.subShapeCount)return n.subShapeCount(e.wrapped,t);let r=n.iterShapes(e.wrapped,t);for(let e of r)n.dispose(e);return r.length}function rD(e,t){let n=H();if(n.subShapeHashes)return n.subShapeHashes(e.wrapped,t,G);let r=new Set;for(let i of n.iterShapes(e.wrapped,t))r.add(n.hashCode(i,G)),n.dispose(i);return[...r]}var iD=new WeakMap;function aD(e){let t=iD.get(e);if(!t)return;iD.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 oD=new WeakSet;function sD(e){let t=e.wrapped,n=iD.get(t);return n||(n={},iD.set(t,n)),oD.has(e)||(oD.add(e),e.onDispose(()=>{aD(t)})),n}function cD(e){return iD.get(e.wrapped)}function lD(e){aD(e.wrapped)}function uD(e){let t=sD(e);if(t.edges)return t.edges;let n=tD(e.wrapped,`edge`);return t.edges=n,n}function dD(e){let t=sD(e);if(t.faces)return t.faces;let n=tD(e.wrapped,`face`);return t.faces=n,n}function fD(e){let t=sD(e);if(t.wires)return t.wires;let n=tD(e.wrapped,`wire`);return t.wires=n,n}function pD(e){let t=sD(e);if(t.vertices)return t.vertices;let n=tD(e.wrapped,`vertex`);return t.vertices=n,n}function mD(e){let t=sD(e);if(t.solids)return t.solids;let n=tD(e.wrapped,`solid`);return t.solids=n,n}function hD(e){let t=sD(e);if(t.shells)return t.shells;let n=tD(e.wrapped,`shell`);return t.shells=n,n}function gD(e){let t=sD(e);if(t.compSolids)return t.compSolids;let n=tD(e.wrapped,`compsolid`);return t.compSolids=n,n}function*_D(e){for(let t of H().iterShapes(e.wrapped,`edge`))yield KE(t,`edge`)}function*vD(e){for(let t of H().iterShapes(e.wrapped,`face`))yield KE(t,`face`)}function*yD(e){for(let t of H().iterShapes(e.wrapped,`wire`))yield KE(t,`wire`)}function*bD(e){for(let t of H().iterShapes(e.wrapped,`vertex`))yield KE(t,`vertex`)}function*xD(e){for(let t of H().iterShapes(e.wrapped,`solid`))yield KE(t,`solid`)}function*SD(e){for(let t of H().iterShapes(e.wrapped,`shell`))yield KE(t,`shell`)}function*CD(e){for(let t of H().iterShapes(e.wrapped,`compsolid`))yield KE(t,`compsolid`)}function wD(e){let t=sD(e);if(t.bounds)return t.bounds;let{min:n,max:r}=H().boundingBox(e.wrapped),i={xMin:n[0],xMax:r[0],yMin:n[1],yMax:r[1],zMin:n[2],zMax:r[2]};return t.bounds=i,i}function TD(e){return lE(H(),e.wrapped)}function ED(e){let t=sD(e);if(t.surfaceType!==void 0)return t.surfaceType;let n=H().surfaceType(e.wrapped);return t.surfaceType=n,n}function DD(e){let t=sD(e);if(t.isValid!==void 0)return t.isValid;let n=H().isValid(e.wrapped);return t.isValid=n,n}function OD(e){return{kind:TD(e),faceCount:nD(e,`face`),edgeCount:nD(e,`edge`),wireCount:nD(e,`wire`),vertexCount:nD(e,`vertex`),valid:DD(e),bounds:wD(e)}}function kD(e){return H().vertexPosition(e.wrapped)}function AD(e){return e.length===2?[e[0],e[1],0]:[e[0],e[1],e[2]]}function jD(e){return[e[0],e[1]]}var MD={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function ND(e){if(typeof e==`string`){let t=MD[e];if(!t)throw Error(`Unknown direction: ${e}`);return t}return e}function PD(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function FD(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function ID(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function LD(e){return[-e[0],-e[1],-e[2]]}function RD(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function zD(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 BD(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function VD(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function HD(e,t){return BD(FD(e,t))}function UD(e){let t=BD(e);return t<1e-10?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function WD(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 GD(e,t=1e-10){return VD(e)<t*t}function KD(e,t){let n=RD(e,t),r=BD(e),i=BD(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 qD(e,t,n){let r=FD(e,t),i=VD(n);return i<1e-20?e:FD(e,ID(n,RD(r,n)/i))}function JD(e,t,n){let r=UD(t),i=Math.cos(n),a=Math.sin(n),o=RD(e,r),s=zD(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 YD=e=>Math.round(e*1e3)/1e3;function XD(e){return`x: ${YD(e[0])}, y: ${YD(e[1])}, z: ${YD(e[2])}`}function ZD(e,t=null,n=[0,0,1]){let r=UD(n);if(GD(r))throw Error(`Plane normal must be non-zero`);let i;if(t)i=UD(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?UD([l,u,d]):[1,0,0]}if(GD(i))throw Error(`Plane xDir must be non-zero`);let a=UD(zD(r,i));return{origin:e,xDir:i,yDir:a,zDir:r}}var QD={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 $D(e,t=[0,0,0]){let n=QD[e];if(!n)return k(P(`UNKNOWN_PLANE`,`Could not find plane ${e}`));let r;return r=typeof t==`number`?ID(n.normal,t):AD(t),O(ZD(r,n.xDir,n.normal))}function eO(e,t){return typeof e==`string`?$D(e,t):O(e)}function tO(e,t){return e&&typeof e!=`string`?{...e}:j(eO(e??`XY`,t))}function nO(e,t){let[n,r]=t;return PD(PD(e.origin,ID(e.xDir,n)),ID(e.yDir,r))}function rO(e,t){return{...e,origin:PD(e.origin,t)}}function iO(e,t,n=[1,0,0]){let r=t*JE,i=JD(e.zDir,n,r),a=JD(e.xDir,n,r),o=UD(zD(i,a));return{origin:e.origin,xDir:a,yDir:o,zDir:i}}var aO={compound:0,solidCompound:1,solid:2,shell:3,face:4,wire:5,edge:6,vertex:7,shape:8},oO=e=>aO[e],sO={vertex:`vertex`,edge:`edge`,wire:`wire`,face:`face`,shell:`shell`,solid:`solid`,solidCompound:`compsolid`,compound:`compound`,shape:`compound`},cO=function*(e,t){let n=H().iterShapes(e,sO[t]);for(let e of n)yield e},lO=e=>H().isNull(e)?k(Co(`NULL_SHAPE`,`This shape has no type, it is null`)):O(e.ShapeType());function uO(e){if(H().isNull(e))return k(Co(`NULL_SHAPE`,`This shape has no type, it is null`));try{return O(H().downcast(e))}catch(e){return k(Co(`NO_WRAPPER`,`Could not find a wrapper for this shape type`,e))}}function dO(e){if(H().isNull(e))return k(Co(`NULL_SHAPE`,`Cannot copy a null shape`));try{return O(H().copyShape(e))}catch(e){return k(Co(`NO_WRAPPER`,`Could not copy this shape`,e))}}function fO(e){return H().isNull(e)?k(Co(`NULL_SHAPE`,`Cannot cast a null shape`)):O(VE(e))}function pO(e){return H().shapeType(e.wrapped)===`compsolid`}function mO(e){return fO(H().fromBREP(e))}var hO={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 gO(e){return O(hO[ED(e)])}function _O(e){return j(gO(e))}function vO(e){return H().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function yO(e){return VE(H().reverseShape(e.wrapped))}function bO(e){return H().uvBounds(e.wrapped)}function xO(e,t,n){let r=bO(e),i=t*(r.uMax-r.uMin)+r.uMin,a=n*(r.vMax-r.vMin)+r.vMin;return H().pointOnSurface(e.wrapped,i,a)}function SO(e,t){let n=AD(t);return H().uvFromPoint(e.wrapped,n)||[0,0]}function CO(e,t){let n=AD(t);try{let t=n,r=H().uvFromPoint(e.wrapped,t);if(!r)return k(Co(`PROJECTION_FAILED`,`No projection found on the face`));let i=H().projectPointOnFace(e.wrapped,t),a=n[0]-i[0],o=n[1]-i[1],s=n[2]-i[2];return O({uv:r,point:i,distance:Math.sqrt(a*a+o*o+s*s)})}catch(e){return k(Co(`PROJECTION_FAILED`,`Point projection failed: ${e instanceof Error?e.message:String(e)}`))}}function wO(e,t){let n,r;if(t)[n,r]=SO(e,t);else{let t=bO(e);n=.5*(t.uMin+t.uMax),r=.5*(t.vMin+t.vMax)}return H().surfaceNormal(e.wrapped,n,r)}function TO(e){return H().surfaceCenterOfMass(e.wrapped)}function EO(e){return H().getSurfaceAxis(e.wrapped)}function DO(e,t,n=1e-6){let[r,i]=SO(e,t);return H().classifyPointOnFace(e.wrapped,r,i,n)}function OO(e){return VE(H().outerWire(e.wrapped))}function kO(e){return VE(H().removeHolesFromFace(e.wrapped))}function AO(e){let t=OO(e);return Array.from(cO(e.wrapped,`wire`)).map(e=>VE(j(uO(e)))).filter(e=>!H().isSame(e.wrapped,t.wrapped))}function jO(e,t){let n=sD(e),r=new Map;for(let n of rD(e,`face`))r.set(n,t);n.faceOrigins=r}function MO(e){return cD(e)?.faceOrigins}function NO(e,t,n){let r=new Map;for(let e of t){let t=MO(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=sD(n);e.faceOrigins=i}}var PO=100,FO=.985,IO=.1;function LO(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>PO)continue;let u=r-l/PO;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)<FO)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>IO)continue;let u=Math.max(0,i*i+a*a+c*c-l*l);u<o&&(o=u,s=n.origin)}return s}function RO(e,t){let n=new Map;for(let t of e){let e=MO(t);if(e)for(let[t,r]of e)n.set(t,r)}if(n.size===0)return;let r=H(),i=new Map,a=dD(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=MO(n);if(e)for(let i of dD(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=LO(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=sD(t);e.faceOrigins=i}}var zO=new WeakMap,BO=new WeakMap;function VO(e){return zO.has(e.wrapped)}function HO(e){let t=zO.get(e.wrapped);return t||(t=new Map,zO.set(e.wrapped,t)),t}function UO(e){let t=BO.get(e.wrapped);return t||(t=new Map,BO.set(e.wrapped,t)),t}function WO(e,t,n){let r=Array.isArray(t)?t:dD(e).filter(t),i=HO(e),a=i.get(n)??new Set;for(let e of r)a.add(H().hashCode(e.wrapped,G));return i.set(n,a),e}function GO(e,t){let n=zO.get(e.wrapped);if(!n)return[];let r=n.get(t);if(!r||r.size===0)return[];let i=[];for(let t of dD(e)){let e=H().hashCode(t.wrapped,G);r.has(e)&&i.push(t)}return i}function KO(e){let t=new Map,n=zO.get(e.wrapped);if(!n)return t;let r=dD(e),i=new Map;for(let e of r)i.set(H().hashCode(e.wrapped,G),e);for(let[e,r]of n){let n=[];for(let e of r){let t=i.get(e);t&&n.push(t)}n.length>0&&t.set(e,n)}return t}function qO(e,t,n){return UO(e).set(t,n),e}function JO(e,t){return BO.get(e.wrapped)?.get(t)}function YO(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function XO(e,t,n){let r=HO(n);for(let i of t){let t=zO.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)YO(r,t,e)}let o=BO.get(i.wrapped);if(o){let e=UO(n);for(let[t,n]of o)e.has(t)||e.set(t,n)}}}var ZO=new WeakMap,QO=new WeakMap;function $O(e){return ZO.has(e.wrapped)||QO.has(e.wrapped)}function ek(e){let t=QO.get(e.wrapped);return t||(t=new Map,QO.set(e.wrapped,t)),t}function tk(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 nk(e,t){return ZO.set(e.wrapped,tk(t)),e}function rk(e,t,n){let r=tk(n),i=ek(e);for(let e of t)i.set(H().hashCode(e.wrapped,G),r);return e}function ik(e){return ZO.get(e.wrapped)}function ak(e,t){let n=QO.get(e.wrapped);if(n)return n.get(H().hashCode(t.wrapped,G))}function ok(e,t,n){for(let e of t){let t=ZO.get(e.wrapped);if(t){ZO.set(n.wrapped,t);break}}let r=ek(n);for(let n of t){let t=QO.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 sk(e){return MO(e)!==void 0||VO(e)||$O(e)}function ck(e){if(!e.some(sk))return[];let t=[];for(let n of e)t.push(...rD(n,`face`));return t}function lk(e,t,n){NO(e,t,n),XO(e,t,n),ok(e,t,n)}function uk(e,t){RO(e,t)}function dk(e,t){let n=H(),r=[...n.iterShapes(e.wrapped,`face`)],i=[...n.iterShapes(t.wrapped,`face`)];if(r.length!==i.length)return;let a=new Map;for(let e=0;e<r.length;e++){let t=r[e],o=i[e];t===void 0||o===void 0||a.set(n.hashCode(t,G),[n.hashCode(o,G)])}for(let e of r)n.dispose(e);for(let e of i)n.dispose(e);lk({modified:a,generated:new Map,deleted:new Set},[e],t)}function fk(e,t){let n=ck([e]),{shape:r,evolution:i}=H().translateWithHistory(e.wrapped,t[0],t[1],t[2],n,G),a=U(r);return lk(i,[e],a),a}function pk(e,t,n=[0,0,0],r=[0,0,1]){let i=ck([e]),{shape:a,evolution:o}=H().rotateWithHistory(e.wrapped,t*JE,i,G,r,n),s=U(a);return lk(o,[e],s),s}function mk(e,t=[0,1,0],n=[0,0,0]){let r=ck([e]),{shape:i,evolution:a}=H().mirrorWithHistory(e.wrapped,n,t,r,G),o=U(i);return lk(a,[e],o),o}function hk(e,t,n=[0,0,0]){let r=ck([e]),{shape:i,evolution:a}=H().scaleWithHistory(e.wrapped,n,t,r,G),o=U(i);return lk(a,[e],o),o}function gk(e,t,n){let r=H().boundingBox(e.wrapped),i=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]],a=n?.auto===!0;function o(e,t,n){return e!==void 0&&t>1e-12?e/t:e===void 0&&a?n:1}let s=1;a&&(t[0]!==void 0&&i[0]>1e-12?s=t[0]/i[0]:t[1]!==void 0&&i[1]>1e-12?s=t[1]/i[1]:t[2]!==void 0&&i[2]>1e-12&&(s=t[2]/i[2]));let c=[o(t[0],i[0],s),o(t[1],i[1],s),o(t[2],i[2],s)];return Math.abs(c[0]-c[1])<1e-6&&Math.abs(c[1]-c[2])<1e-6?O(hk(e,c[0])):k(P(M.VALIDATION_FAILED,`resize: non-uniform scaling is not supported (WASM build lacks BRepBuilderAPI_GTransform).`,void 0,void 0,`Use auto: true to scale proportionally, or set all three dimensions to achieve uniform scaling.`))}function _k(e){if(`linear`in e)return O({linear:e.linear,translation:e.translation});let[t,n,r,i]=e,a=1e-10;return Math.abs(i[0])>a||Math.abs(i[1])>a||Math.abs(i[2])>a||Math.abs(i[3]-1)>a?k(P(M.VALIDATION_FAILED,`applyMatrix: invalid bottom row [${String(i[0])}, ${String(i[1])}, ${String(i[2])}, ${String(i[3])}]. Must be [0, 0, 0, 1] for an affine transform.`)):O({linear:[t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]],translation:[t[3],n[3],r[3]]})}function vk(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 yk(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 bk(e,t){let n=_k(t);if(!n.ok)return n;let{linear:r,translation:i}=n.value,a=vk(r);if(Math.abs(a)<1e-12)return k(P(M.VALIDATION_FAILED,`applyMatrix: singular matrix (determinant ≈ 0). Cannot apply a non-invertible transform.`));if(yk(r)){let t=ck([e]),{shape:n,evolution:a}=H().generalTransformWithHistory(e.wrapped,r,i,!0,t,G),o=U(n);return lk(a,[e],o),O(o)}let o=U(H().generalTransformNonOrthogonal(e.wrapped,r,i));return uk([e],o),O(o)}function xk(e){let t=e.map(e=>e.type===`translate`?{type:`translate`,x:e.v[0],y:e.v[1],z:e.v[2]}:{type:`rotate`,angle:e.angle,axis:e.axis,center:e.center}),{handle:n,dispose:r}=H().composeTransform(t);return{trsf:n,cleanup:r}}function Sk(e,t){let{trsf:n,cleanup:r}=xk(`type`in t?[t]:t),i;try{i=U(H().locate(e.wrapped,n))}finally{r()}return sk(e)&&dk(e,i),i}function Ck(e,t){let n=ck([e]),{shape:r,evolution:i}=H().applyComposedTransformWithHistory(e.wrapped,t.trsf,n,G),a=U(r);return lk(i,[e],a),a}function wk(e){return QE(()=>H().copyShape(e.wrapped),M.CLONE_FAILED,`Failed to clone shape`)}function Tk(e){return $E(()=>H().toBREP(e.wrapped),M.TO_BREP_FAILED,`Failed to serialize shape to BREP`)}function Ek(e){return H().hashCode(e.wrapped,G)}function Dk(e){return H().isNull(e.wrapped)}function Ok(e,t){return H().isSame(e.wrapped,t.wrapped)}function kk(e,t){return H().isEqual(e.wrapped,t.wrapped)}function Ak(e){return QE(()=>H().simplify(e.wrapped),M.SIMPLIFY_FAILED,`Failed to simplify shape`)}function jk(e){return H().curveType(e.wrapped)}function Mk(e){let[t]=H().curveParameters(e.wrapped);return H().curvePointAtParam(e.wrapped,t)}function Nk(e){let[,t]=H().curveParameters(e.wrapped);return H().curvePointAtParam(e.wrapped,t)}function Pk(e,t=.5){let[n,r]=H().curveParameters(e.wrapped),i=n+(r-n)*t;return H().curvePointAtParam(e.wrapped,i)}function Fk(e,t=.5){let[n,r]=H().curveParameters(e.wrapped),i=n+(r-n)*t;return H().curveTangent(e.wrapped,i).tangent}function Ik(e){return H().length(e.wrapped)}function Lk(e){if(jk(e)!==`CIRCLE`)return null;let t=Pk(e,0),n=Pk(e,1/3),r=Pk(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 Rk(e){return H().curveIsClosed(e.wrapped)}function zk(e){return H().curveIsPeriodic(e.wrapped)}function Bk(e){return H().curvePeriod(e.wrapped)}function Vk(e){return H().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function Hk(e){return U(H().reverseShape(e.wrapped))}function Uk(e,t={}){if(e.length<2)return k(Co(`INTERPOLATE_MIN_POINTS`,`Interpolation requires at least 2 points`));try{let n=U(H().interpolatePoints(e,t));return NE(n)?O(n):(W(n),k(Co(`INTERPOLATE_NOT_EDGE`,`Interpolation did not produce an edge`)))}catch(e){return k(Co(`INTERPOLATE_FAILED`,`Interpolation failed: ${e instanceof Error?e.message:String(e)}`))}}function Wk(e,t={}){if(e.length<2)return k(Co(`APPROXIMATE_MIN_POINTS`,`Approximation requires at least 2 points`));try{let n=U(H().approximatePoints(e,t));return NE(n)?O(n):(W(n),k(Co(`APPROXIMATE_NOT_EDGE`,`Approximation did not produce an edge`)))}catch(e){return k(Co(`APPROXIMATE_FAILED`,`Approximation failed: ${e instanceof Error?e.message:String(e)}`))}}function Gk(e,t,n=`arc`){let r=U(H().offsetWire2D(e.wrapped,t,{arc:`arc`,intersection:`intersection`,tangent:`tangent`,chamfer:`intersection`}[n]));return PE(r)?O(r):(W(r),k(Co(`OFFSET_NOT_WIRE`,`Offset did not produce a Wire`)))}function Kk(e,t,n,r=!1){return`${e}:${t}:${n}:${r}`}function qk(e,t){return`edge:${e}:${t}`}var Jk=new WeakMap,Yk=new WeakMap;function Xk(e,t){let n=Jk.get(e);if(n)return n.get(t)}function Zk(e,t,n){let r=Jk.get(e);r||(r=new Map,Jk.set(e,r)),r.set(t,n)}function Qk(e,t){let n=Yk.get(e);if(n)return n.get(t)}function $k(e,t,n){let r=Yk.get(e);r||(r=new Map,Yk.set(e,r)),r.set(t,n)}function eA(){Jk=new WeakMap,Yk=new WeakMap}function tA(){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 nA(e,t={}){let n=Po(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,skipNormals:a=!1,includeUVs:o=!1,cache:s=!0,signal:c}=t;c?.throwIfAborted();let l=Kk(r,i,a,o);if(s){let t=Xk(e.wrapped,l);if(t)return t}let u=H().mesh(e.wrapped,{tolerance:r,angularTolerance:i,skipNormals:a,includeUVs:o,...c?{signal:c}:{}}),d=MO(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 rA(e,t={}){let n=Po(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,cache:a=!0}=t,o=qk(r,i);if(a){let t=Qk(e.wrapped,o);if(t)return t}let s=H().meshEdges(e.wrapped,r,i),c={lines:s.lines,edgeGroups:s.edgeGroups.map(e=>({start:e.start,count:e.count,edgeId:e.edgeHash}))};return a&&$k(e.wrapped,o,c),c}function iA(e,t){return e instanceof Error&&e.message.startsWith(`${t} export failed`)?Do(`${t}_EXPORT_FAILED`,`Failed to write ${t} file`,e):e instanceof WebAssembly.RuntimeError?Do(`${t}_EXPORT_CRASHED`,`${t} export crashed the kernel (${e.message}); the shape likely contains geometry the ${t} writer cannot serialize`,e):Do(`${t}_FILE_READ_ERROR`,`Failed to read exported ${t} file`,e)}function aA(e){let t;try{t=mD(e)}catch{return``}if(t.length<=1)return``;let n=[];return t.forEach((e,t)=>{try{wD(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 oA(e,t){try{return wD(e),null}catch(n){if(n instanceof TypeError)throw n;return Do(`${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${aA(e)}`,n)}}function sA(e){let t=oA(e,`STEP`);if(t)return k(t);try{let t=H().exportSTEP([e.wrapped]);return O(new Blob([t],{type:`application/STEP`}))}catch(e){return k(iA(e,`STEP`))}}function cA(e,t={}){let n=Po(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,binary:a=!1}=t,o=oA(e,`STL`);if(o)return k(o);try{H().hasTriangulation(e.wrapped)||H().meshShape(e.wrapped,r,i);let t=H().exportSTL(e.wrapped,a,r,i);return O(new Blob([t],{type:`application/sla`}))}catch(e){return k(iA(e,`STL`))}}function lA(e){try{let t=H().exportIGES([e.wrapped]);return O(new Blob([t],{type:`application/iges`}))}catch(e){return k(Do(`IGES_EXPORT_FAILED`,`Failed to write IGES file`,e))}}function uA(e,t){let n=t?.coarseTolerance??.5,r=t?.fineTolerance??.05,i=t?.angularTolerance??.5;return{coarse:nA(e,{tolerance:n,angularTolerance:i}),fine:nA(e,{tolerance:r,angularTolerance:i*.2})}}function dA(e){let t=wD(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 fA(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)*dA(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 pA(e,t,n){return Math.min(e/t*n,1)}function mA(e,t={}){let n=t.angularTolerance??Po().angularTolerance,r=t.cache??!0,i=fA(e,t),a=Math.min(...i);return i.map(i=>{let o=pA(i,a,n);return{tolerance:i,angularTolerance:o,mesh:nA(e,{tolerance:i,angularTolerance:o,cache:r,...t.signal?{signal:t.signal}:{}})}})}function hA(){return new Promise(e=>{setTimeout(e,0)})}async function gA(e,t={}){let n=t.angularTolerance??Po().angularTolerance,r=t.cache??!0,i=t.meshLevel??((e,n,i)=>nA(e,{tolerance:n,angularTolerance:i,cache:r,...t.signal?{signal:t.signal}:{}})),a=fA(e,t),o=Math.min(...a),s=[];for(let[r,c]of a.entries()){if(t.signal?.aborted)break;let l=pA(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 hA()}return s}function _A(e,t,n){if(t<0||t>=e.length)throw Error(n??`Index ${t} out of bounds (length ${e.length})`);return e[t]}function vA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[0]}function yA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[e.length-1]}function bA(e){return Array.from(Array(e).keys())}function xA(e){return bA(Math.min(...e.map(e=>e.length))).map(t=>e.map(e=>e[t]))}function SA(e,t){return TE(H().makeLineEdge([...e],[...t]))}function CA(e,t=[0,0,0],n=[0,0,1]){return TE(H().makeCircleEdge([...t],[...n],e))}function wA(e,t,n=[0,0,0],r=[0,0,1],i){return t>e?k(P(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(TE(H().makeEllipseEdge([...n],[...r],e,t,i?[...i]:void 0)))}function TA(e,t,n,r=[0,0,0],i=[0,0,1],a=!1){return EE(H().makeHelixWire(e,t,n,[...r],[...i],a))}function EA(e,t,n){return TE(H().makeArcEdge([...e],[...t],[...n]))}function DA(e,t,n,r,i=[0,0,0],a=[0,0,1],o){return t>e?k(P(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(TE(H().makeEllipseArc([...i],[...a],e,t,n,r,o?[...o]:void 0)))}function OA(e,{tolerance:t=.001,smoothing:n=null,degMax:r=6,degMin:i=1}={}){try{let a=e.map(e=>[...e]);return O(TE(H().approximatePoints(a,{tolerance:t,degMin:i,degMax:r,smoothing:n})))}catch(e){return k(N(`BSPLINE_FAILED`,`B-spline approximation failed`,e))}}function kA(e,{periodic:t=!1,tolerance:n=1e-7}={}){try{let r=e.map(e=>[...e]);return O(TE(H().interpolatePoints(r,{periodic:t,tolerance:n})))}catch(e){return k(N(`BSPLINE_INTERP_FAILED`,`B-spline interpolation failed`,e))}}function AA(e){if(e.length<2)return k(P(`BEZIER_MIN_POINTS`,`Need at least 2 points for a Bezier curve, got ${e.length}`,void 0,{pointCount:e.length}));let t=e.map(e=>[...e]);return O(TE(H().makeBezierEdge(t)))}function jA(e,t,n){return TE(H().makeTangentArc([...e],[...t],[...n]))}function MA(e){try{return O(EE(H().makeWireFromMixed(e.map(e=>e.wrapped))))}catch(e){return k(N(`WIRE_BUILD_FAILED`,`Failed to build the wire: ${e instanceof Error?e.message:`unknown error`}`))}}function NA(e,t){try{let n=H().makeFace(e.wrapped,!0);if(t&&t.length>0){let e=LA(DE(n),t);return yE(e)?O(e):k(P(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}let r=DE(n);return yE(r)?O(r):k(P(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}catch(e){return k(N(`FACE_BUILD_FAILED`,`Failed to build the face. Your wire might be non planar.`,e))}}function PA(e){return NA(OO(e))}function FA(e,t){return DE(H().makeFaceOnSurface(e.wrapped,t.wrapped))}function IA(e){try{return Za(fO(H().makeNonPlanarFace(e.wrapped)),e=>FE(e)?O(e):k(N(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`)))}catch(e){return k(N(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`,e))}}function LA(e,t){return DE(H().addHolesInFace(e.wrapped,t.map(e=>e.wrapped)))}function RA(e){try{var t=IT();if(e.length<3)return k(P(`POLYGON_MIN_POINTS`,`You need at least 3 points to make a polygon`));let n=[...e.slice(1),e[0]],r=t.u(new XT);return Za(MA(xA([e,n]).map(([e,t])=>r.register(SA(e,t)))),e=>NA(r.register(e)))}catch(e){t.e=e}finally{t.d()}}function zA(e,t){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function BA(e,t,n,r,i){let a=VE(e);if(!zE(a)){let o=uE(a).toUpperCase();return UE(e,a),W(a),k(Co(t,`${n}. Got ${o} instead.`,void 0,i?{diagnostics:i}:void 0,r))}return UE(e,a),O(a)}function VA(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=zA(e,`fuse: first operand`);if(A(c))return c;let l=zA(t,`fuse: second operand`);if(A(l))return l;if(!s)return BA(H().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);let u=ck([e,t]),{shape:d,evolution:f,diagnostics:p}=H().fuseWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(H().isNull(d))return H().dispose(d),console.warn(`brepjs: fuse history path produced null result; retrying without evolution tracking.`,p),BA(H().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);console.warn(`brepjs: fuse reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=BA(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&&lk(f,[e,t],m.value),m}function HA(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;let c=zA(e,`cut: base`);if(A(c))return c;let l=zA(t,`cut: tool`);if(A(l))return l;if(!s)return BA(H().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);let u=ck([e,t]),{shape:d,evolution:f,diagnostics:p}=H().cutWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(H().isNull(d))return H().dispose(d),console.warn(`brepjs: cut history path produced null result; retrying without evolution tracking.`,p),BA(H().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);console.warn(`brepjs: cut reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=BA(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&&lk(f,[e,t],m.value),m}function UA(e,t,{simplify:n=!1,signal:r,fuzzyValue:i,unsafe:a,trackEvolution:o=!0}={}){if(r?.aborted)throw r.reason;let s=zA(e,`intersect: first operand`);if(A(s))return s;let c=zA(t,`intersect: second operand`);if(A(c))return c;if(!o)return BA(H().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);let l=ck([e,t]),{shape:u,evolution:d,diagnostics:f}=H().intersectWithHistory(e.wrapped,t.wrapped,l,G,{simplify:n,fuzzyValue:i});if(f.hasErrors){if(H().isNull(u))return H().dispose(u),console.warn(`brepjs: intersect history path produced null result; retrying without evolution tracking.`,f),BA(H().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);console.warn(`brepjs: intersect reported OCCT warnings/errors but produced a shape. Continuing with result.`,f)}let p=BA(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&&lk(d,[e,t],p.value),p}function WA(e,t,n,r,i,a,o,s,c){if(s?.aborted)throw s.reason;let l=n-t;if(l===1)return O({shape:_A(e,t),owned:!1});if(l===2){let n=VA(_A(e,t),_A(e,t+1),{optimisation:r,simplify:a?i:!1,trackEvolution:o,fuzzyValue:c,unsafe:!0,...s?{signal:s}:{}});return A(n)?n:O({shape:n.value,owned:!0})}let u=t+Math.ceil(l/2),d=WA(e,t,u,r,i,!1,o,s,c);if(A(d))return d;let f=WA(e,u,n,r,i,!1,o,s,c);if(A(f))return d.value.owned&&W(d.value.shape),f;let p=VA(d.value.shape,f.value.shape,{optimisation:r,simplify:i,trackEvolution:o,fuzzyValue:c,unsafe:!0,...s?{signal:s}:{}});return d.value.owned&&W(d.value.shape),f.value.owned&&W(f.value.shape),A(p)?p:O({shape:p.value,owned:!0})}function GA(e,{optimisation:t=`none`,simplify:n=!1,strategy:r=`native`,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;if(e.length===0)return k(P(`FUSE_ALL_EMPTY`,`fuseAll requires at least one shape`));if(e.length===1)return O(vA(e));for(let t=0;t<e.length;t++){let n=zA(_A(e,t),`fuseAll: shape at index ${t}`);if(A(n))return n}if(r===`native`){let o=BA(H().fuseAll(e.map(e=>e.wrapped),{optimisation:t,simplify:n,strategy:r,fuzzyValue:a,...i?{signal:i}:{}}),`FUSE_ALL_NOT_3D`,`fuseAll did not produce a 3D shape`);return o.ok&&s&&uk(e,o.value),o}let c=WA(e,0,e.length,t,n,!0,s,i,a);return A(c)?c:O(c.value.shape)}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;if(t.length===0)return O(e);let c=zA(e,`cutAll: base`);if(A(c))return c;for(let e=0;e<t.length;e++){let n=zA(_A(t,e),`cutAll: tool at index ${e}`);if(A(n))return n}let l=[e,...t],u=BA(H().cutAll(e.wrapped,t.map(e=>e.wrapped),{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_ALL_NOT_3D`,`cutAll did not produce a 3D shape`);return u.ok&&s&&uk(l,u.value),u}function qA(e,t){let n=H(),r=ID(e.xDir,t),i=ID(e.yDir,t),a=ID(e.xDir,-t),o=ID(e.yDir,-t),s=e.origin,c=[...PD(PD(s,a),o)],l=[...PD(PD(s,r),o)],u=[...PD(PD(s,r),i)],d=[...PD(PD(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 JA(e,t,{approximation:n=!0,planeSize:r=1e4}={}){if(H().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`section: shape is a null shape`));let i=qA(typeof t==`string`?j(eO(t)):t,r);try{return O(U(H().section(e.wrapped,i,n)))}catch(e){let n=e instanceof Error?e.message:String(e),r=typeof t==`string`?t:`custom`;return k(N(`SECTION_FAILED`,`Section with ${r} plane failed: ${n}`,e,{operation:`section`,plane:r},`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`))}finally{H().dispose(i)}}function YA(e){let t=H(),n=new Map,r=new Map;for(let i of e){let e=pD(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 XA(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=XA(i,t,n);for(;o;)e===0?r.push(o.edge):r.unshift(o.edge),i=o.nextTip,o=XA(i,t,n)}return r}function QA(e){let t=H(),n=YA(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(U(n))}catch{}}return i}function $A(e){let t=H(),n=0,r=-1;for(let i=0;i<e.length;i++){let a=e[i];if(!a)continue;let o=t.boundingBox(a.wrapped),s=o.max[0]-o.min[0],c=o.max[1]-o.min[1],l=o.max[2]-o.min[2],u=s*s+c*c+l*l;u>r&&(r=u,n=i)}return n}function ej(e,t,n={}){let r=JA(e,t,n);if(!r.ok)return r;let i=fD(r.value);if(i.length===0){let e=uD(r.value);if(e.length===0)return k(N(`SECTION_FAILED`,`sectionToFace: section produced no geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));i.push(...QA(e))}if(i.length===0)return k(N(`SECTION_FAILED`,`sectionToFace: section produced no usable geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));let a=$A(i),o=_A(i,a),s=i.filter((e,t)=>t!==a);return NA(o,s.length>0?s:void 0)}function tj(e,t){if(t.length===0)return O(e);if(H().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`split: shape is a null shape`));for(let e=0;e<t.length;e++)if(H().isNull(_A(t,e).wrapped))return k(P(M.NULL_SHAPE_INPUT,`splitShape: tool at index ${e} is a null shape`));try{return O(U(H().split(e.wrapped,t.map(e=>e.wrapped))))}catch(e){let n=e instanceof Error?e.message:String(e);return k(N(`SPLIT_FAILED`,`Split operation failed on ${t.length} tool(s): ${n}`,e,{operation:`split`,toolCount:t.length},`The splitting tools may not intersect the shape. Ensure tools cross through the shape's interior.`))}}function nj(e,t,n={}){let r=[];for(let i of t){let t=JA(e,i,n);if(A(t))return t;r.push(t.value)}return O(r)}function rj(e,t,n){if(t.length===0)return O(e);let r=n?.optimisation===`commonFace`?1:n?.optimisation===`sameFace`?2:0,i=H(),a=t.map(e=>({op:e.op,tool:e.tool.wrapped}));try{let o=i.booleanPipeline?.(e.wrapped,a,{glueMode:r});if(o===void 0)return ij(e,t,n);if(o===null)return k(N(`BOOLEAN_PIPELINE_FAILED`,`Boolean pipeline returned null shape`));let s=U(o);return zE(s)?O(s):(W(s),k(Co(`BOOLEAN_PIPELINE_NOT_3D`,`Pipeline result is not a 3D shape`)))}catch(e){return k(N(`BOOLEAN_PIPELINE_FAILED`,e instanceof Error?e.message:String(e)))}}function ij(e,t,n){let r=e,i={...n?.optimisation?{optimisation:n.optimisation}:{},unsafe:!0};for(let e of t){let t=e.op===`fuse`?VA(r,e.tool,i):e.op===`cut`?HA(r,e.tool,i):UA(r,e.tool,i);if(A(t))return t;r=j(t)}return O(r)}function aj(e){return U(H().sew(e.map(e=>e.wrapped)))}function oj(e,t=!1){let n=aj(e);return!t&&!IE(n)?k(Co(`WELD_NOT_SHELL`,`Could not make a shell from faces and shells`)):O(n)}function sj(e,t,n=[0,0,0],r=[0,0,1]){return kE(H().makeCylinder(e,t,[...n],[...r]))}function cj(e){return kE(H().makeSphere(e))}function lj(e,t,n,r=[0,0,0],i=[0,0,1]){return kE(H().makeCone(e,t,n,[...r],[...i]))}function uj(e,t,n=[0,0,0],r=[0,0,1]){return kE(H().makeTorus(e,t,[...n],[...r]))}function dj(e,t,n){return kE(H().makeEllipsoid(e,t,n))}function fj(e){return wE(H().makeVertex(e[0],e[1],e[2]))}function pj(e,t,n=1e-6){return Za(uO(H().offset(e.wrapped,t,n)),e=>Za(fO(e),e=>zE(e)?O(e):k(Co(`OFFSET_NOT_3D`,`Could not offset to a 3d shape`))))}function mj(e){return jE(H().makeCompound(e.map(e=>e.wrapped)))}function hj(e){try{var t=IT();let n=t.u(aj(e)),r=U(H().solidFromShell(n.wrapped));return LE(r)?O(r):(W(r),k(Co(`SOLID_BUILD_FAILED`,`Could not make a solid of faces and shells`)))}catch(e){t.e=e}finally{t.d()}}function gj(e){return{position:e.vertices,normal:e.normals,index:e.triangles}}function _j(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 vj(e){return{position:e.lines}}function yj(e,t){return{coarse:gj(e.coarse),fine:gj(e.fine),coarseDistance:t?.coarse??50,fineDistance:t?.fine??0}}function bj(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:gj(e.mesh),distance:r?.[t]??(i-t)*n}))}function xj(e,t,n,r){if(t.length===0)return k(P(`CHAMFER_ANGLE_NO_EDGES`,`chamferDistAngle requires at least one edge`,void 0,{edgeCount:0}));if(n<=0)return k(P(`CHAMFER_ANGLE_BAD_DISTANCE`,`distance must be positive, got ${n}`,void 0,{distance:n}));if(r<=0||r>=90)return k(P(`CHAMFER_ANGLE_BAD_ANGLE`,`angleDeg must be in range (0, 90), got ${r}`,void 0,{angleDeg:r}));let i;try{let a=H(),o=t.map(e=>e.wrapped);i=a.chamferDistAngle(e.wrapped,o,n,r)}catch(e){return k(N(`CHAMFER_ANGLE_FAILED`,`chamferDistAngle kernel call failed: ${e instanceof Error?e.message:String(e)}`,e,{distance:n,angleDeg:r,edgeCount:t.length}))}let a=uO(i);if(A(a))return H().dispose(i),a;let o=U(a.value);return UE(i,o),zE(o)?O(o):(W(o),k(Co(`CHAMFER_ANGLE_NOT_3D`,`chamferDistAngle did not produce a 3D shape`)))}function Sj(e){let t=H();return t.getNurbsCurveData?t.getNurbsCurveData(e.wrapped):null}function Cj(e){let t=H();return t.getNurbsSurfaceData?t.getNurbsSurfaceData(e.wrapped):null}var wj={cut:HA,cutAll:KA,fuse:VA,fuseAll:GA};function Tj(e){return{totalInputs:e.totalInputs,batchAttempts:e.batchAttempts,batchSucceeded:e.batchSucceeded,singletonFallbacks:e.singletonFallbacks,failedInputs:[...e.failedInputs].sort((e,t)=>e-t)}}function Ej(e,t,n={}){return Dj(wj,e,t,n)}function Dj(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=Oj(e,t,n,0,r,i);return A(a)?a:O({shape:a.value,telemetry:Tj(i)})}function Oj(e,t,n,r,i,a){if(n.length===0)return O(t);if(n.length===1)return kj(e,t,n,r,i,a);a.batchAttempts++;let o=Pj(()=>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=Oj(e,t,n.slice(0,s),r,i,a);return c.ok?Oj(e,c.value,n.slice(s),r+s,i,a):c}function kj(e,t,n,r,i,a){a.singletonFallbacks++;let o=vA(n),s=Pj(()=>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 Aj(e,t={}){return jj(wj,e,t)}function jj(e,t,n={}){if(n.signal?.aborted)throw n.signal.reason;if(t.length===0)return k(P(M.FUSE_ALL_EMPTY,`fuseAllBisect requires at least one shape`));let r={totalInputs:t.length,batchAttempts:0,batchSucceeded:0,singletonFallbacks:0,failedInputs:new Set},i=Mj(e,t,0,n,r);return A(i)?i:O({shape:i.value,telemetry:Tj(r)})}function Mj(e,t,n,r,i){if(t.length===1)return O(vA(t));i.batchAttempts++;let a=Pj(()=>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 Nj(e,Mj(e,t.slice(0,o),n,r,i),Mj(e,t.slice(o),n+o,r,i),t,n,o,r,i)}function Nj(e,t,n,r,i,a,o,s){if(t.ok&&n.ok){s.singletonFallbacks++;let c=Pj(()=>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 Pj(e){try{return e()}catch{return null}}function Fj(e,t,n){return H().checkBoolean(e.wrapped,t.wrapped,n)}function Ij(e,t){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Lj(e,t){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Rj(e,t,n,r){let i=VE(e);if(!zE(i)){let a=uE(i).toUpperCase();return UE(e,i),W(i),k(Co(t,`${n}. Got ${a} instead.`,void 0,void 0,r))}return UE(e,i),O(i)}function zj(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(H().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>r.get(H().hashCode(e,2147483647))??1}}function Bj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Ij(e,`fuseWithEvolution: first operand`);if(A(o))return o;let s=Ij(t,`fuseWithEvolution: second operand`);if(A(s))return s;let c=ck([e,t]),{shape:l,evolution:u}=H().fuseWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Rj(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?(lk(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function Vj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Ij(e,`cutWithEvolution: base`);if(A(o))return o;let s=Ij(t,`cutWithEvolution: tool`);if(A(s))return s;let c=ck([e,t]),{shape:l,evolution:u}=H().cutWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Rj(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?(lk(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function Hj(e,t,{simplify:n=!1,signal:r,fuzzyValue:i}={}){if(r?.aborted)throw r.reason;let a=Ij(e,`intersectWithEvolution: first operand`);if(A(a))return a;let o=Ij(t,`intersectWithEvolution: second operand`);if(A(o))return o;let s=ck([e,t]),{shape:c,evolution:l}=H().intersectWithHistory(e.wrapped,t.wrapped,s,G,{simplify:n,fuzzyValue:i}),u=Rj(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?(lk(l,[e,t],u.value),O({shape:u.value,evolution:l})):u}function Uj(e,t,n){let r=Lj(e,`filletWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(P(`INVALID_FILLET_RADIUS`,`Fillet radius must be positive`,void 0,void 0,`Provide a positive radius value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(P(`INVALID_FILLET_RADIUS`,`Fillet radii must both be positive`,void 0,void 0,`Both radius values must be greater than 0`));let i=t??uD(e);if(i.length===0)return k(P(M.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));try{let t,r;if(typeof n==`function`){let e=zj(i,n);if(!e)return k(P(M.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=ck([e]),{shape:o,evolution:s}=H().filletWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=U(o);return zE(c)?(lk(s,[e],c),O({shape:c,evolution:s})):(W(c),k(N(M.FILLET_NOT_3D,`Fillet result is not a 3D shape`)))}catch(e){return k(N(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:i.length,radius:n}))}}function Wj(e,t,n){let r=Lj(e,`chamferWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(P(`INVALID_CHAMFER_DISTANCE`,`Chamfer distance must be positive`,void 0,void 0,`Provide a positive distance value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(P(`INVALID_CHAMFER_DISTANCE`,`Chamfer distances must both be positive`,void 0,void 0,`Both distance values must be greater than 0`));let i=t??uD(e);if(i.length===0)return k(P(M.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=zj(i,n);if(!e)return k(P(M.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=ck([e]),{shape:o,evolution:s}=H().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=U(o);return zE(c)?(lk(s,[e],c),O({shape:c,evolution:s})):(W(c),k(N(M.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)))}catch(e){return k(N(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:i.length,distance:n}))}}function Gj(e,t,n,r=.001){let i=Lj(e,`shellWithEvolution: shape`);if(A(i))return i;if(n<=0)return k(P(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(P(`NO_FACES`,`At least one face must be specified for shell`));try{let i=ck([e]),{shape:a,evolution:o}=H().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,i,G,r),s=U(a);return zE(s)?(lk(o,[e],s),O({shape:s,evolution:o})):(W(s),k(N(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}catch(e){return k(N(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function Kj(e,t,n){try{let r=U(H().positionOnCurve(e.wrapped,t.wrapped,n));return zE(r)?O(r):(W(r),k(N(M.POSITION_ON_CURVE_FAILED,`positionOnCurve did not produce a 3D shape`)))}catch(e){return k(N(M.POSITION_ON_CURVE_FAILED,`Failed to position shape on curve at param ${n}`,e))}}function qj(e,t){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Jj(e,t){if(typeof e==`number`&&e<=0)return k(P(t.code,t.scalar,void 0,void 0,t.scalarHint));if(Array.isArray(e)&&(e[0]<=0||e[1]<=0))return k(P(t.code,t.pair,void 0,void 0,t.pairHint))}function Yj(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(H().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>{let t=r.get(H().hashCode(e,G));if(t===void 0)throw Error(`fillet/chamfer: edge hash not found — possible hash collision`);return t}}}function Xj(e,t,n,r,i){let a=U(t);return zE(a)?(lk(e,n,a),O(a)):(W(a),k(N(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(H().hashCode(i.wrapped,G),e))}return{filteredFaces:n,kernelAngle:e=>{let t=r.get(H().hashCode(e,G));if(t===void 0)throw Error(`draft: face hash not found — possible hash collision`);return t}}}function Qj(e,t){let n=qj(e,`thicken: shape`);if(A(n))return n;try{let n=ck([e]),{shape:r,evolution:i}=H().thickenWithHistory(e.wrapped,t,n,G),a=U(r);return lk(i,[e],a),O(a)}catch(e){return k(N(`THICKEN_FAILED`,`Thicken operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function $j(e,t,n){let r=qj(e,`fillet: shape`);if(A(r))return r;let i=Jj(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??uD(e);if(a.length===0)return k(P(M.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));if(typeof n==`function`){let e=Yj(a,n);return e?O({filteredEdges:e.edges,kernelRadius:e.kernelParam,selectedCount:a.length}):k(P(M.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`))}return O({filteredEdges:[...a],kernelRadius:n,selectedCount:a.length})}function eM(e,t,n,{trackEvolution:r=!0}={}){let i=$j(e,t,n);if(A(i))return i;let{filteredEdges:a,kernelRadius:o,selectedCount:s}=i.value;try{let t=a.map(e=>e.wrapped);if(!r){let n=U(H().fillet(e.wrapped,t,o));return zE(n)?O(n):(W(n),k(N(M.FILLET_NOT_3D,`Fillet result is not a 3D shape`)))}let n=ck([e]),{shape:i,evolution:s}=H().filletWithHistory(e.wrapped,t,o,n,G);return Xj(s,i,[e],M.FILLET_NOT_3D,`Fillet result is not a 3D shape`)}catch(e){return k(N(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:s,radius:n}))}}function tM(e,t,n){let r=qj(e,`chamfer: shape`);if(A(r))return r;let i=Jj(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??uD(e);if(a.length===0)return k(P(M.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=Yj(a,n);if(!e)return k(P(M.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...a],r=n;let i=ck([e]),{shape:o,evolution:s}=H().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,i,G);return Xj(s,o,[e],M.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)}catch(e){return k(N(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:a.length,distance:n}))}}function nM(e,t,n,r=.001,{trackEvolution:i=!0}={}){let a=qj(e,`shell: shape`);if(A(a))return a;if(n<=0)return k(P(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(P(`NO_FACES`,`At least one face must be specified for shell`));try{if(!i){let i=U(H().shell(e.wrapped,t.map(e=>e.wrapped),n,r));return zE(i)?O(i):(W(i),k(N(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}let a=ck([e]),{shape:o,evolution:s}=H().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,a,G,r),c=U(o);return zE(c)?(lk(s,[e],c),O(c)):(W(c),k(N(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}catch(e){return k(N(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function rM(e,t,n=1e-6){let r=qj(e,`offset: shape`);if(A(r))return r;if(Math.abs(t)<1e-10)return k(P(`ZERO_OFFSET`,`Offset distance cannot be zero`));try{let r=ck([e]),{shape:i,evolution:a}=H().offsetWithHistory(e.wrapped,t,r,G,n),o=U(i);return zE(o)?(lk(a,[e],o),O(o)):(W(o),k(N(`OFFSET_RESULT_NOT_3D`,`Offset result is not a 3D shape`)))}catch(e){return k(N(`OFFSET_FAILED`,`Offset operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function iM(e,t,n){let r=qj(e,`draft: shape`);if(A(r))return r;if(typeof n==`number`){if(Math.abs(n)<1e-10)return k(P(M.DRAFT_INVALID_ANGLE,`Draft angle cannot be zero`,void 0,void 0,`Provide a non-zero angle in degrees`));if(Math.abs(n)>=90)return k(P(M.DRAFT_INVALID_ANGLE,`Draft angle must be between -90 and 90 degrees (exclusive)`,void 0,void 0,`Typical draft angles are 1-5 degrees for injection molding`))}if(t.length===0)return k(P(M.DRAFT_NO_FACES,`No faces specified for draft`,void 0,void 0,`Select at least one face to apply the draft angle to`))}function aM(e,t,n,r,i){let a=iM(e,t,i);if(a)return a;try{let{filteredFaces:a,kernelAngle:o}=Zj(t,i);if(a.length===0)return k(P(M.DRAFT_NO_FACES,`No faces with valid draft angle`,void 0,void 0,`Check that the angle callback returns non-zero values between -90 and 90 degrees`));let s=ck([e]),{shape:c,evolution:l}=H().draftWithHistory(e.wrapped,a.map(e=>e.wrapped),[n[0],n[1],n[2]],[r[0],r[1],r[2]],o,s,G);return Xj(l,c,[e],M.DRAFT_NOT_3D,`Draft result is not a 3D shape`)}catch(e){let n=e instanceof Error?e.message:String(e);return k(N(M.DRAFT_FAILED,`Draft operation failed: ${n}`,e,{operation:`draft`,faceCount:t.length,angle:i}))}}function oM(e,t,n){if(n.length===0)return k(P(M.VARIABLE_FILLET_FAILED,`radii must contain at least one radius spec`));for(let e of n)if(e.radius<=0)return k(P(M.VARIABLE_FILLET_FAILED,`All radius values must be positive`));let r=H();try{let i=JSON.stringify({edge:r.hashCode(t.wrapped,G),radii:n.map(e=>({param:e.param,radius:e.radius}))}),a=U(r.filletVariable(e.wrapped,i));return zE(a)?LE(a)?O(a):(W(a),k(N(M.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a solid`))):(W(a),k(N(M.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a 3D shape`)))}catch(e){return k(N(M.VARIABLE_FILLET_FAILED,`Variable-radius fillet failed`,e))}}function sM(e){return DD(e)}function cM(e){if(!LE(e))return k(P(`NOT_A_SOLID`,`Input shape is not a solid`));let t=sM(e);try{let n=H().healSolid(e.wrapped);if(!n)return t?O(e):k(N(M.HEAL_NO_EFFECT,`Solid healing had no effect — shape is still invalid`));let r=U(n);return LE(r)?(lD(r),sM(r)?O(r):(W(r),k(N(`HEAL_SOLID_INCOMPLETE`,`Healed result is still invalid after ShapeFix_Solid`)))):(W(r),k(N(`HEAL_RESULT_NOT_SOLID`,`Healed result is not a solid`)))}catch(e){return k(N(`HEAL_SOLID_FAILED`,`Solid healing failed`,e))}}function lM(e){if(!FE(e))return k(P(`NOT_A_FACE`,`Input shape is not a face`));try{let t=U(H().healFace(e.wrapped));return FE(t)?O(t):(W(t),k(N(`HEAL_RESULT_NOT_FACE`,`Healed result is not a face`)))}catch(e){return k(N(`HEAL_FACE_FAILED`,`Face healing failed`,e))}}function uM(e,t){if(!PE(e))return k(P(`NOT_A_WIRE`,`Input shape is not a wire`));try{let n=U(H().healWire(e.wrapped,t?.wrapped));return PE(n)?O(n):(W(n),k(N(`HEAL_RESULT_NOT_WIRE`,`Healed result is not a wire`)))}catch(e){return k(N(`HEAL_WIRE_FAILED`,`Wire healing failed`,e))}}function dM(e){return LE(e)?cM(e):FE(e)?lM(e):PE(e)?uM(e):O(e)}function fM(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(sM(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=fD(e).length,u=dD(e).length,d=e,f=!1,p=t=>{let n=d;d=t,n!==e&&n.wrapped!==t.wrapped&&W(n)};if(o!==void 0)try{p(U(H().sew([d.wrapped],o))),s.push(`Applied sewing with tolerance ${o}`),c.push({name:`sew`,attempted:!0,succeeded:!0,detail:`tolerance=${o}`})}catch(e){let t=e instanceof Error?e.message:String(e);s.push(`Sewing failed: ${t}`),c.push({name:`sew`,attempted:!0,succeeded:!1,detail:t})}if(a&&n){let e=fD(d),t=0;for(let n of e)try{H().fixSelfIntersection(n.wrapped),t++}catch{}s.push(`Self-intersection fix: ${t}/${e.length} wires`),c.push({name:`fixSelfIntersection`,attempted:!0,succeeded:t>0,detail:`${t}/${e.length} wires fixed`})}if(LE(d)&&i||FE(d)&&r||PE(d)&&n){let t=dM(d);Ja(t)?(p(t.value),LE(e)?(f=!0,s.push(`Applied ShapeFix_Solid`),c.push({name:`healSolid`,attempted:!0,succeeded:!0})):FE(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=fD(d).length,h=dD(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=sM(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 pM(e){try{return O(U(H().fixShape(e.wrapped)))}catch(e){return k(N(M.FIX_SHAPE_FAILED,`ShapeFix_Shape failed`,e))}}function mM(e){try{let t=U(H().solidFromShell(e.wrapped));return LE(t)?sM(t)?O(t):(W(t),k(N(M.SOLID_FROM_SHELL_FAILED,`solidFromShell produced an invalid solid`))):(W(t),k(N(M.SOLID_FROM_SHELL_FAILED,`solidFromShell did not produce a solid`)))}catch(e){return k(N(M.SOLID_FROM_SHELL_FAILED,`Failed to create solid from shell`,e))}}function hM(e){try{let t=U(H().fixSelfIntersection(e.wrapped));return PE(t)?O(t):(W(t),k(N(M.FIX_SELF_INTERSECTION_FAILED,`Result is not a wire`)))}catch(e){return k(N(M.FIX_SELF_INTERSECTION_FAILED,`Failed to fix wire self-intersection`,e))}}function gM(e,{profile:t,endFactor:n=1}){return e<1e-10?k(P(`INVALID_EXTRUSION_LENGTH`,`Extrusion length too small (< 1e-10)`)):t!==`s-curve`&&t!==`linear`?k(P(`UNSUPPORTED_PROFILE`,`Unsupported extrusion profile: ${String(t)}`)):O(H().buildExtrusionLaw(t,e,n).Trim(0,e,1e-6))}function _M(e,t){let n=H(),r=n.makeLineEdge([...e],[...t]),i=n.makeWire([r]);return n.dispose(r),U(i)}function vM(e,t,n,r,i,a=!1){return U(H().makeHelixWire(e,t,n,[...r],[...i],a))}function yM(e){let t=U(e.shape),n=U(e.firstShape),r=U(e.lastShape),i=()=>{W(t),W(n),W(r)};return zE(t)?PE(n)?PE(r)?O([t,n,r]):(i(),k(Co(`SWEEP_END_NOT_WIRE`,`Sweep did not produce an end Wire`))):(i(),k(Co(`SWEEP_START_NOT_WIRE`,`Sweep did not produce a start Wire`))):(i(),k(Co(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function bM(e,t,n={},r=!1){if(n.mode===`simple`&&!r){let n=U(H().simplePipe(e.wrapped,t.wrapped));return zE(n)?O(n):(W(n),k(Co(`SWEEP_NOT_3D`,`Simple pipe did not produce a 3D shape`)))}let{frenet:i=!1,auxiliarySpine:a,law:o=null,transitionMode:s=`right`,withContact:c,support:l,forceProfileSpineOthogonality:u,tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h}=n,g=H(),_=s===`round`?!0:!!u,v=g.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:s,contact:!!c,correction:_,frenet:i,shellMode:r,...a?.wrapped?{auxiliary:a.wrapped}:{},...o===null?{}:{law:o},...l===null?{}:{support:l},tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h});if(r&&typeof v==`object`&&`firstShape`in v)return yM(v);let y=U(v);return zE(y)?O(y):(W(y),k(Co(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function xM(e,t,n,r){return bM(e,_M(t,PD(t,n)),{support:r})}function SM(e,t,n,r,i=!1){try{var a=IT();let o=BD(n);if(o<1e-10)return k(P(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let s=PD(t,n),c=a.u(_M(t,s)),l=null;if(r){let e=gM(o,r);if(A(e))return e;l=e.value}return bM(e,c,{law:l},i)}catch(e){a.e=e}finally{a.d()}}function CM(e,t,n,r,i,a=!1){try{var o=IT();if(Math.abs(t)<1e-10)return k(P(`ZERO_TWIST_ANGLE`,`Twist angle cannot be zero`));let s=BD(r);if(s<1e-10)return k(P(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let c=PD(n,r),l=o.u(_M(n,c)),u=t<0,d=360/Math.abs(t)*s,f=o.u(vM(d,s,1,n,r,u)),p=null;if(i){let e=gM(s,i);if(A(e))return e;p=e.value}return bM(e,l,{auxiliarySpine:f,law:p},a)}catch(e){o.e=e}finally{o.d()}}function wM(e){let t=e.map(e=>e.location);for(let e=0;e<t.length;e++){let n=t[e];if(n!==void 0&&(n<0||n>1))return P(M.MULTI_SWEEP_FAILED,`Section ${e} location ${n} is out of range [0, 1]`)}let n=t.filter(e=>e!==void 0);for(let e=1;e<n.length;e++)if((n[e]??0)<=(n[e-1]??0))return P(M.MULTI_SWEEP_FAILED,`Section locations must be strictly increasing`)}function TM(e,t,n){let[r,i]=n.curveParameters(t.wrapped),a=i-r,o=Array(e.length);for(let t=0;t<e.length;t++){let n=e[t]?.location;o[t]=n===void 0?NaN:r+n*a}let s=-1,c=r;for(let t=0;t<=e.length;t++){let n=t===e.length;if(!n&&!Number.isNaN(o[t]??NaN)||n){let e=n?i:o[t]??i,a=t-s-1;for(let t=1;t<=a;t++)o[s+t]=c+t/(a+1)*(e-c);n||(s=t,c=o[t]??r)}}for(let e=1;e<o.length;e++)if((o[e]??0)<=(o[e-1]??0))return k(P(M.MULTI_SWEEP_FAILED,`Computed section parameters are not strictly increasing at index ${e} (${o[e-1]?.toFixed(4)} >= ${o[e]?.toFixed(4)})`));return O(o)}function EM(e,t,n){if(e.length<2)return k(P(M.MULTI_SWEEP_INSUFFICIENT_SECTIONS,`Multi-section sweep requires at least 2 sections, got ${e.length}`));let{solid:r=!0,ruled:i=!1,tolerance:a=1e-6}=n??{},o=wM(e);if(o)return k(o);try{let n=H(),o=TM(e,t,n);if(A(o))return o;let s=o.value,c=[],l=[];try{for(let r=0;r<e.length;r++){let i=s[r],a=e[r];if(i===void 0||a===void 0)continue;let o=n.positionOnCurve(a.wire.wrapped,t.wrapped,i);c.push(o),l.push(n.downcast(o,`wire`))}let o=U(n.loftAdvanced(l,{solid:r,ruled:i,tolerance:a}));return zE(o)?O(o):(W(o),k(Co(`MULTI_SWEEP_NOT_3D`,`Multi-section sweep did not produce a 3D shape`)))}finally{for(let e of l)n.dispose(e);for(let e of c)n.dispose(e)}}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.MULTI_SWEEP_FAILED,`Multi-section sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function DM(e,t,n,r={}){let{transition:i=`transformed`,solid:a=!0,tolerance:o}=r;try{let r=H(),s=!a,c=n.length>0?n[0]?.wrapped:void 0,l=r.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:i,...c?{auxiliary:c}:{},shellMode:s,...o===void 0?{}:{tolerance:o,boundTolerance:o}}),u=U(typeof l==`object`&&`shape`in l?l.shape:l);return zE(u)?O(u):(W(u),k(Co(`GUIDED_SWEEP_NOT_3D`,`Guided sweep did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.GUIDED_SWEEP_FAILED,`Guided sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function OM(e,t){if(H().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`extrude: face is a null shape`));if(BD(t)<1e-10)return k(P(`EXTRUDE_ZERO_VECTOR`,`extrude: extrusion vector has zero length`));try{let n=H(),r=BD(t),i=UD(t),a=n.extrude(e.wrapped,[...i],r),o=kE(n.downcast(a,`solid`));return UE(a,o),O(o)}catch(e){return k(N(`EXTRUDE_FAILED`,`Extrusion operation failed`,e,{operation:`extrude`,vectorLength:BD(t)}))}}function kM(e,t=[0,0,0],n=[0,0,1],r=2*Math.PI){if(H().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`revolve: face is a null shape`));try{let i=U(H().revolveVec(e.wrapped,[...t],[...n],r));return zE(i)?O(i):(W(i),k(Co(`REVOLUTION_NOT_3D`,`Revolution did not produce a 3D shape`)))}catch(e){return k(N(`REVOLVE_FAILED`,`Revolution operation failed`,e,{operation:`revolve`,angle:r}))}}function AM(e){if(e.length===0)return O([]);let t=H(),n=[];for(let t=0;t<e.length;t++){let r=e[t];if(!r)continue;let i=typeof r.height==`number`?[0,0,r.height]:r.height,a=BD(i);if(a<1e-10)return k(P(`EXTRUDE_ALL_ZERO_VECTOR`,`extrudeAll: entry ${t} has zero-length extrusion vector`));let o=[...UD(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=kE(t.downcast(e,`solid`));return UE(e,n),n}))}catch(e){return k(N(`EXTRUDE_ALL_FAILED`,`Batch extrusion operation failed`,e))}}function jM(e,{ruled:t=!0,startPoint:n,endPoint:r,tolerance:i=1e-6}={},a=!1){if(e.length===0&&!n&&!r)return k(P(`LOFT_EMPTY`,`Loft requires at least one wire or start/end point`));let o=H(),s=n?o.makeVertex(...AD(n)):void 0,c=r?o.makeVertex(...AD(r)):void 0;try{let n=U(o.loftAdvanced(e.map(e=>e.wrapped),{solid:!a,ruled:t,tolerance:i,...s?{startVertex:s}:{},...c?{endVertex:c}:{}}));return zE(n)?O(n):(W(n),k(Co(`LOFT_NOT_3D`,`Loft did not produce a 3D shape`)))}catch(e){return k(N(`LOFT_FAILED`,`Loft operation failed`,e,void 0,`Common causes: wire profiles with different edge counts, self-intersecting result, or profiles too far apart. Ensure profiles are compatible and ordered.`))}}function MM(e){if(e.length===0)return O([]);let t=H(),n=[],r=e.map(e=>{let r=e.startPoint?t.makeVertex(...AD(e.startPoint)):void 0,i=e.endPoint?t.makeVertex(...AD(e.endPoint)):void 0;return r&&n.push(r),i&&n.push(i),{wires:e.wires.map(e=>e.wrapped),solid:!0,ruled:e.ruled??!0,tolerance:e.tolerance??1e-6,startVertex:r,endVertex:i}});try{let e=t.loftBatch?.(r)??r.map(e=>t.loftAdvanced(e.wires,{solid:e.solid,ruled:e.ruled,tolerance:e.tolerance,startVertex:e.startVertex,endVertex:e.endVertex})),n=[];for(let t of e){let e=U(t);if(!zE(e))return W(e),k(Co(`LOFT_ALL_NOT_3D`,`Batch loft entry did not produce a 3D shape`));n.push(e)}return O(n)}catch(e){return k(N(`LOFT_ALL_FAILED`,`Batch loft operation failed`,e))}finally{for(let e of n)t.dispose(e)}}var NM=new WeakMap;function PM(e,t){return NM.get(e)?.get(t)}function FM(e,t,n){let r=NM.get(e);r||(r=new Map,NM.set(e,r)),r.set(t,n)}function IM(e){return H().isNull(e.wrapped)}function LM(e){return k(P(M.NULL_SHAPE_INPUT,`${e}: shape is a null shape`))}function RM(e){let t=PM(e.wrapped,`volume`);if(t)return O(t);if(IM(e))return LM(`measureVolumeProps`);let n=H(),r=n.shapeType(e.wrapped);if(r!==`solid`&&r!==`compsolid`&&r!==`compound`){let t={mass:0,volume:0,centerOfMass:[0,0,0]};return FM(e.wrapped,`volume`,t),O(t)}let i=n.volume(e.wrapped),a=$E(()=>n.centerOfMass(e.wrapped),M.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!a.ok)return a;let o={mass:i,volume:i,centerOfMass:a.value};return FM(e.wrapped,`volume`,o),O(o)}function zM(e){let t=PM(e.wrapped,`surface`);if(t)return O(t);if(IM(e))return LM(`measureSurfaceProps`);let n=H(),r=n.area(e.wrapped),i=$E(()=>n.centerOfMass(e.wrapped),M.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!i.ok)return i;let a={mass:r,area:r,centerOfMass:i.value};return FM(e.wrapped,`surface`,a),O(a)}function BM(e){let t=PM(e.wrapped,`linear`);if(t)return O(t);if(IM(e))return LM(`measureLinearProps`);let n=H(),r=n.length(e.wrapped),i={mass:r,length:r,centerOfMass:n.linearCenterOfMass(e.wrapped)};return FM(e.wrapped,`linear`,i),O(i)}function VM(e){let t=RM(e);return t.ok?O(t.value.mass):t}function HM(e){let t=zM(e);return t.ok?O(t.value.mass):t}function UM(e){let t=BM(e);return t.ok?O(t.value.mass):t}function WM(e,t){return IM(e)||IM(t)?LM(`measureDistance`):O(H().distance(e.wrapped,t.wrapped).value)}function GM(e,t){if(IM(e)||IM(t))return LM(`measureDistanceProps`);let n=H().distance(e.wrapped,t.wrapped);return O({distance:n.value,point1:n.point1,point2:n.point2})}function KM(e){if(IM(e))return LM(`createDistanceQuery`);let t=H().createDistanceQuery(e.wrapped);return O({distanceTo(e){return IM(e)?LM(`createDistanceQuery.distanceTo`):O(t.distanceTo(e.wrapped).value)},dispose(){t.dispose()}})}function qM(e,t,n){if(IM(e))return LM(`measureCurvatureAt`);let r=H().surfaceCurvature(e.wrapped,t,n);return O({mean:r.mean,gaussian:r.gaussian,maxCurvature:r.max,minCurvature:r.min,maxDirection:r.maxDirection,minDirection:r.minDirection})}function JM(e){if(IM(e))return LM(`measureCurvatureAtMid`);let t=bO(e),n=(t.uMin+t.uMax)/2,r=(t.vMin+t.vMax)/2,i=H().surfaceCurvature(e.wrapped,n,r);return O({mean:i.mean,gaussian:i.gaussian,maxCurvature:i.max,minCurvature:i.min,maxDirection:i.maxDirection,minDirection:i.minDirection})}function YM(e,t){return e.map(e=>qE(e,t))}function XM(e,t){let n=H(),r=n.iterShapes(e,t),i=[],a=new Map;for(let e of r){let r=n.hashCode(e,G),o=a.get(r);if(o?.some(t=>n.isSame(t,e))){n.dispose(e);continue}let s=KE(e,t);i.push(s),o?o.push(s.wrapped):a.set(r,[s.wrapped])}return i}function ZM(e){let t=H(),n=new Map;for(let r of e){let e=t.hashCode(r.wrapped,G),i=n.get(e);i?i.push(r):n.set(e,[r])}return n}function QM(e,t,n){let r=H();return e.get(n)?.find(e=>r.isSame(e.wrapped,t))}function $M(e){let t=sD(e);if(t.edgeToFaces)return t.edgeToFaces;let n=H(),r=dD(e),i=ZM(uD(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=QM(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 eN(e){let t=sD(e);if(t.vertexToFaces)return t.vertexToFaces;let n=H(),r=dD(e),i=ZM(pD(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=QM(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 tN(e,t){let n=H(),r=$M(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 YM(o,`face`)}function nN(e,t){let n=H(),r=eN(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 YM(o,`face`)}function rN(e){return XM(e.wrapped,`edge`)}function iN(e){return XM(e.wrapped,`vertex`)}function aN(e){return XM(e.wrapped,`wire`)}function oN(e){return XM(e.wrapped,`vertex`)}function sN(e,t){let n=H(),r=$M(e),i=XM(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 YM(a,`face`)}var cN=new Map;function lN(e,t){let n=H(),r=TT()??``;if(cN.get(r)!==!1){let i;try{i=n.sharedEdges(e.wrapped,t.wrapped);let a=i.map(e=>KE(e,`edge`));return cN.set(r,!0),a}catch(e){if(i)for(let e of i)n.dispose(e);if(!l(e))throw e;cN.set(r,!1)}}return uN(e,t)}function uN(e,t){let n=H(),r=n.iterShapes(e.wrapped,`edge`),i=n.iterShapes(t.wrapped,`edge`),a=new Map;for(let e of i){let t=n.hashCode(e,G),r=a.get(t);r||(r=[],a.set(t,r)),r.push(e)}let o=[];for(let e of r)a.get(n.hashCode(e,2147483647))?.some(t=>n.isSame(e,t))?o.push(KE(e,`edge`)):n.dispose(e);for(let e of i)n.dispose(e);return o}var dN=new Map;function fN(e,t){let n=H(),r=TT()??``;if(dN.get(r)!==!1)try{let i=n.adjacentFaces(e.wrapped,t.wrapped);dN.set(r,!0);try{return i.map(e=>n.hashCode(e,G))}finally{for(let e of i)n.dispose(e)}}catch(e){if(!l(e))throw e;dN.set(r,!1)}return sN(e,t).map(e=>n.hashCode(e.wrapped,G))}function pN(e,t){let n=0,r=_O(t);if(e.surfaceType!==void 0)if(r===e.surfaceType)n+=1;else return-1/0;if(e.normal!==void 0){let r=wO(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=TO(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=HM(t);if(r.ok&&r.value>0){let t=Math.abs(Math.log(e.area/r.value));t>1&&(n-=t)}}return n}function mN(e){let t=_O(e),n=wO(e),r=TO(e),i=HM(e);return{entityType:`face`,surfaceType:t,normal:n,centroid:r,area:i.ok?i.value:void 0}}var hN=.9;function gN(e){if(e[2]>hN)return`box:top`;if(e[2]<-.9)return`box:bottom`;if(e[1]>hN)return`box:back`;if(e[1]<-.9)return`box:front`;if(e[0]>hN)return`box:right`;if(e[0]<-.9)return`box:left`}function _N(e,t){if(_O(t)!==`PLANE`)return;let n=wO(t)[2];if(n>hN)return`${e}:top`;if(n<-.9)return`${e}:bottom`}function vN(e){return _O(e)===`CYLINDRE`?`cylinder:lateral`:_N(`cylinder`,e)}function yN(e){return _O(e)===`CONE`?`cone:lateral`:_N(`cone`,e)}function bN(e){return _O(e)===`SPHERE`?`sphere:surface`:void 0}var xN={box:e=>gN(wO(e)),cylinder:vN,cone:yN,sphere:bN};function SN(e,t){let n=new Map,r=xN[t],i=H(),a=0;for(let o of i.iterShapes(e.wrapped,`face`)){let e=GE(o,`face`);try{let i=r?.(e),o=i!==void 0&&!n.has(i)?i:`${t}:face_${a}`;n.set(o,[Ek(e)]),a++}finally{WE(e,o)}}return n}function CN(e,t,n){return{origin:e,role:t,hint:mN(n)}}function wN(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 TN(e,t,n){let r=e.get(t);if(!r)return e;let i=new Map;for(let[e,t]of r){let r=wN(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 EN=.1,DN=.5;function ON(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<EN&&o.length>1?{kind:`ambiguous`,candidates:o.filter(([,e])=>e>=r-EN).map(([e])=>e)}:{kind:`match`,face:i}:{kind:`none`}}function kN(e,t,n,r){let i=dD(n),a=r??pN,o=t.get(e.origin)?.get(e.role);if(o!==void 0&&o.length>0){let t=i.filter(e=>o.includes(Ek(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=ON(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=ON(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 AN(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 jN(e){if(e.length===0)return;let t=0,n=0,r=0;for(let i of e){let e=kD(i);t+=e[0],n+=e[1],r+=e[2]}let i=e.length;return[t/i,n/i,r/i]}function MN(e,t,n){let r=n.get(t);if(!r)return;let i=Ek(e);for(let[e,t]of r)if(t.includes(i))return e}function NN(e,t,n,r){let i=r.get(t)?.get(n);return i===void 0||i.length===0?[]:dD(e).filter(e=>i.includes(Ek(e)))}function PN(e){let t=UM(e);return{entityType:`edge`,length:t.ok?t.value:void 0,midpoint:jN(oN(e))}}function FN(e){let t=new Set,n=[];for(let r of e){let e=Ek(r);t.has(e)||(t.add(e),n.push(r))}return n}var IN=1e-6;function LN(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=UM(a);n.ok&&(e+=Math.abs(n.value-t.length))}if(t.midpoint!==void 0){let n=jN(oN(a));n!==void 0&&(e+=AN(t.midpoint,n))}e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<IN))return n}function RN(e,t,n,r){let[i,a]=tN(n,t);if(i===void 0||a===void 0)return;let o=MN(i,e,r),s=MN(a,e,r);if(!(o===void 0||s===void 0))return{origin:e,faceRoles:[o,s],hint:PN(t)}}function zN(e,t,n){let[r,i]=e.faceRoles,a=NN(n,e.origin,r,t),o=NN(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(...lN(e,t));let c=FN(s);if(c.length===1){let[e]=c;if(e!==void 0)return{edge:e,confidence:`exact`}}if(c.length>1){let t=LN(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 BN=3,VN=1e-6;function HN(e,t){let n=new Set;for(let r of e)for(let e of iN(r)){let r=Ek(e);n.add(r),t.has(r)||t.set(r,e)}return n}function UN(e,t){let n=new Set;for(let r of e)t.has(r)&&n.add(r);return n}function WN(e){let t=new Map,n;for(let r of e){let e=HN(r,t);n=n===void 0?e:UN(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 GN(e,t){if(t.position===void 0)return;let n,r=1/0,i=1/0;for(let a of e){let e=AN(kD(a),t.position);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<VN))return n}function KN(e,t,n,r){let i=nN(n,t);if(i.length<BN)return;let a=new Set;for(let t of i){let n=MN(t,e,r);n!==void 0&&a.add(n)}if(!(a.size<BN))return{origin:e,faceRoles:[...a].sort(),hint:{entityType:`vertex`,position:kD(t)}}}function qN(e,t,n){let r=[];for(let i of e.faceRoles){let a=NN(n,e.origin,i,t);if(a.length===0)return{ref:e,reason:`not-found`};r.push(a)}let i=WN(r);if(i.length===1){let[e]=i;if(e!==void 0)return{vertex:e,confidence:`exact`}}if(i.length>1){let t=GN(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 JN=.99,YN=.1,XN=1e-6;function ZN(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function QN(e,t){return dD(e).filter(e=>ZN(wO(e),t)>JN)}function $N(e,t,n){let r=new Set([...t,...n].map(Ek)),i=new Set;for(let n of t)for(let t of fN(e,n))i.add(t);let a=[],o=new Set;for(let t of n)for(let n of fN(e,t))r.has(n)||o.has(n)||!i.has(n)||(o.add(n),a.push(n));if(a.length===0)return[];let s=new Map(dD(e).map(e=>[Ek(e),e]));return a.map(e=>s.get(e)).filter(e=>e!==void 0)}function eP(e,t){let n,r=1/0,i=1/0;for(let a of e){let e=AN(TO(a),t);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<XN))return n}function tP(e,t,n,r,i){let[a,o]=tN(r,n);if(a===void 0||o===void 0)return;let s=MN(a,e,i),c=MN(o,e,i);if(!(s===void 0||c===void 0))return{origin:e,op:t,betweenRoles:[s,c],hint:{entityType:`derived-face`,normalA:wO(a),normalB:wO(o),edgeMidpoint:jN(oN(n))}}}function nP(e,t,n){let r=NN(n,e.origin,e.betweenRoles[0],t);r.length===0&&(r=QN(n,e.hint.normalA));let i=NN(n,e.origin,e.betweenRoles[1],t);if(i.length===0&&(i=QN(n,e.hint.normalB)),r.length===0||i.length===0)return{ref:e,reason:`not-found`};let a=$N(n,r,i).filter(t=>ZN(wO(t),e.hint.normalA)>YN&&ZN(wO(t),e.hint.normalB)>YN);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&&eP(a,e.hint.edgeMidpoint);return t?{face:t,confidence:`geometric-fallback`}:{ref:e,reason:`ambiguous`,candidates:a}}return{ref:e,reason:`not-found`}}function rP(e){return typeof e==`object`&&!!e&&`origin`in e}function iP(e){return rP(e)&&`betweenRoles`in e&&`op`in e}function aP(e){return rP(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length===2}function oP(e){return rP(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length>=3}function sP(e){return rP(e)&&typeof e.role==`string`}function cP(e){return sP(e)||aP(e)||oP(e)||iP(e)}function lP(e,t){return t===void 0?{ok:!1,reason:e}:{ok:!1,reason:e,candidates:t}}function uP(e,t,n){if(iP(e)){let r=nP(e,t,n);return`face`in r?{ok:!0,entity:r.face}:lP(r.reason,r.candidates)}if(aP(e)){let r=zN(e,t,n);return`edge`in r?{ok:!0,entity:r.edge}:lP(r.reason,r.candidates)}if(oP(e)){let r=qN(e,t,n);return`vertex`in r?{ok:!0,entity:r.vertex}:lP(r.reason,r.candidates)}let r=kN(e,t,n);return`face`in r?{ok:!0,entity:r.face}:lP(r.reason,r.candidates)}function dP(e,t,n){let r=n.get(e.origin);if(r!==void 0)return r;let i=new Map([[e.origin,SN(t,e.origin)]]);return n.set(e.origin,i),i}function fP(e,t){return uP(e,dP(e,t,new Map),t)}function pP(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 mP(e,t){let n=new Map,r=e=>{if(cP(e)){let r=uP(e,dP(e,t,n),t);return r.ok?r.entity:e}if(Array.isArray(e))return e.map(r);if(pP(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 hP(e,t,n,r){let i=kE(H().makeBox(e,t,n)),a=r?.at??(r?.centered?[0,0,0]:void 0);if(a)try{var o=IT();return fk(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 gP(e,t,n){let r=n?.at??[0,0,0],i=n?.axis??[0,0,1],a=sj(e,t,r,i);if(n?.centered)try{var o=IT();let e=[-i[0]*t*.5,-i[1]*t*.5,-i[2]*t*.5];return fk(o.u(a),e)}catch(e){o.e=e}finally{o.d()}return a}function _P(e,t){let n=cj(e);if(t?.at)try{var r=IT();return fk(r.u(n),t.at)}catch(e){r.e=e}finally{r.d()}return n}function vP(e,t,n,r){let i=r?.at??[0,0,0],a=r?.axis??[0,0,1],o=lj(e,t,n,i,a);if(r?.centered)try{var s=IT();let e=[-a[0]*n*.5,-a[1]*n*.5,-a[2]*n*.5];return fk(s.u(o),e)}catch(e){s.e=e}finally{s.d()}return o}function yP(e,t,n){return uj(e,t,n?.at??[0,0,0],n?.axis??[0,0,1])}function bP(e,t,n,r){let i=dj(e,t,n);if(r?.at)try{var a=IT();return fk(a.u(i),r.at)}catch(e){a.e=e}finally{a.d()}return i}function xP(e,t){return SA(e,t)}function SP(e,t){let n=t?.axis??[0,0,1];return CA(e,t?.at??[0,0,0],n)}function CP(e,t,n){let r=n?.axis??[0,0,1];return wA(e,t,n?.at??[0,0,0],r,n?.xDir)}function wP(e,t,n,r){return TA(e,t,n,r?.at??[0,0,0],r?.axis??[0,0,1],r?.lefthand??!1)}function TP(e,t,n){return EA(e,t,n)}function EP(e,t,n,r,i){let a=i?.axis??[0,0,1];return DA(e,t,n*JE,r*JE,i?.at??[0,0,0],a,i?.xDir)}function DP(e,t){return OA(e,t)}function OP(e){return AA(e)}function kP(e,t,n){return jA(e,t,n)}function AP(e){return MA(e)}function jP(e){return Za(MA(e),e=>dE(e)?O(e):k(P(`WIRE_NOT_CLOSED`,`Assembled wire is not closed: start and end points do not coincide`)))}function MP(e,t){return NA(e,t)}function NP(e){return IA(e)}function PP(e,t){return FA(e,t)}function FP(e){return RA(e)}function IP(e){return fj(e)}function LP(e){return mj(e)}function RP(e){return hj(e)}function zP(e,t,n){return pj(e,t,n)}function BP(e,t){return oj(e,t)}function VP(e,t){return LA(e,t)}function HP(){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 UP(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??HP(),color:[a,o,s,c]}});return YT(H().createXCAFDocument(t))}function WP(e=[],{unit:t,modelUnit:n}={}){let r=e=>{let t=e;return t.indexOf(`#`)===0&&(t=t.slice(1)),t.length===3&&(t=t.replace(/([0-9a-f])/gi,`$1$1`)),[parseInt(t.substring(0,2),16),parseInt(t.substring(2,4),16),parseInt(t.substring(4,6),16)]},i=H(),a=e.map(({shape:e,name:t,color:n,alpha:i})=>{let[a,o,s]=r(n??`#f00`);return{shape:e.wrapped,name:t??HP(),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(Do(`STEP_EXPORT_FAILED`,`Failed to write STEP file`))}finally{o.delete()}}function GP(e,t,n,r,i){if(n<1)return k(P(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(GD(t))return k(P(`PATTERN_ZERO_DIRECTION`,`Pattern direction cannot be zero`));let a=UD(t),o=H().linearPattern(e.wrapped,[...a],r,n).map(e=>U(e));try{return GA(o,{optimisation:`sameFace`,...i,unsafe:!0})}finally{for(let e of o)e[Symbol.dispose]()}}function KP(e,t,n,r=360,i=[0,0,0],a){if(n<1)return k(P(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(GD(t))return k(P(`PATTERN_ZERO_AXIS`,`Pattern axis cannot be zero`));let o=r/n,s=H().circularPattern(e.wrapped,[...i],[...t],o,n).map(e=>U(e));try{return GA(s,{optimisation:`sameFace`,...a,unsafe:!0})}finally{for(let e of s)e[Symbol.dispose]()}}function qP(e,t,n,r,i,a,o,s){if(r<1||i<1)return k(P(`PATTERN_INVALID_COUNT`,`Grid pattern counts must be at least 1`));if(r===1&&i===1)return O(e);if(GD(t))return k(P(`PATTERN_ZERO_DIRECTION`,`Grid directionX cannot be zero`));if(GD(n))return k(P(`PATTERN_ZERO_DIRECTION`,`Grid directionY cannot be zero`));let c=H(),l=UD(t),u=UD(n);if(typeof c.gridPattern==`function`)return O(U(c.gridPattern(e.wrapped,[...l],[...u],a,o,r,i)));let d=GP(e,t,r,a,s);if(!d.ok)return d;let f=d.value,p=GP(f,n,i,o,s),m=p.ok&&p.value===f;return f!==e&&!m&&f[Symbol.dispose](),p}function JP(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 YP(e,t){return{...e,children:[...e.children,t]}}function XP(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 ZP(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 QP(e,t){if(e.name===t)return e;for(let n of e.children){let e=QP(n,t);if(e)return e}}function $P(e,t,n=0){t(e,n);for(let r of e.children)$P(r,t,n+1)}function eF(e){let t=1;for(let n of e.children)t+=eF(n);return t}function tF(e){let t=[];return $P(e,e=>{e.shape&&t.push(e.shape)}),t}function nF(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function rF(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 iF(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function aF(e){return iF(rF(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function oF(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 sF(e,t){let n=t/2,r=Math.sin(n),i=iF(e);return[Math.cos(n),i[0]*r,i[1]*r,i[2]*r]}function cF(e,t){let n=iF(e),r=iF(t),i=nF(n,r);if(i>=.999999999)return[1,0,0,0];if(i<=-.999999999)return sF(aF(n),Math.PI);let a=rF(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 lF(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 uF=Math.PI/180;function dF(e,t,n){return Math.min(n,Math.max(t,e))}function fF(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function pF(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 mF(e){return fF(pF(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function hF(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:fF(t),min:s,max:c,value:dF(n.value??0,s,c)}}function gF(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:fF(r.direction)},min:a.min,max:a.max,value:a.value,dofs:i}}function _F(e,t,n,r={}){return gF(`revolute`,e,t,n,[hF(`rotation`,n.direction,r,-180,180)])}function vF(e,t,n,r={}){return gF(`prismatic`,e,t,n,[hF(`translation`,n.direction,r,0,100)])}function yF(e,t,n,r={}){return gF(`cylindrical`,e,t,n,[hF(`rotation`,n.direction,r.rotation??{},-180,180),hF(`translation`,n.direction,r.translation??{},0,100)])}function bF(e,t,n,r={}){let i=fF(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?mF(i):fF(n)}else a=mF(i);let o=fF(pF(i,a));return gF(`planar`,e,t,{origin:n.origin,direction:i},[hF(`translation`,a,r.u??{},-100,100),hF(`translation`,o,r.v??{},-100,100),hF(`rotation`,i,r.rotation??{},-180,180)])}function xF(e,t,n,r={}){return gF(`spherical`,e,t,{origin:n,direction:[0,0,1]},[hF(`rotation`,[1,0,0],r.x??{},-180,180),hF(`rotation`,[0,1,0],r.y??{},-180,180),hF(`rotation`,[0,0,1],r.z??{},-180,180)])}function SF(e,t){let n=e.dofs.map((e,n)=>{let r=t[n];return r===void 0?e:{...e,value:dF(r,e.min,e.max)}}),r=n[0];return r?{...e,dofs:n,value:r.value}:{...e,dofs:n}}function CF(e,t){return SF(e,[t])}function wF(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=sF(t.axis,n*uF),i=oF(r,e);return{position:[e[0]-i[0],e[1]-i[1],e[2]-i[2]],rotation:r}}function TF(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=OF(a,wF(i,o,dF(s,o.min,o.max)))}return a}function EF(e,t){let n=e.joints??[];return{...e,joints:[...n,t]}}var DF={position:[0,0,0],rotation:[1,0,0,0]};function OF(e,t){let n=oF(e.rotation,t.position);return{position:[e.position[0]+n[0],e.position[1]+n[1],e.position[2]+n[2]],rotation:lF(e.rotation,t.rotation)}}function kF(e){let t=[];return $P(e,e=>{e.joints&&t.push(...e.joints)}),t}function AF(e,t={}){let n=[],r=new Set;$P(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?OF(TF(n,i),n.offset):TF(n,i);a.set(n.child,OF(r,c))}}for(let e of o)a.has(e.child)||a.set(e.child,DF);return a}function jF(e){return kF(e).reduce((e,t)=>e+t.dofs.length,0)}var MF={position:[0,0,0],rotation:[1,0,0,0]};function NF(e,t){let n=oF(e.rotation,t);return[n[0]+e.position[0],n[1]+e.position[1],n[2]+e.position[2]]}function PF(e){return[e[0],-e[1],-e[2],-e[3]]}function FF(e,t){let[n,r,i,a]=lF(t,PF(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 IF(e,t){let n=[];$P(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 LF(e,t){return e[t]??0}function RF(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]=LF(e,a*n+t);i[a*r+n]=LF(t,a)}for(let e=0;e<n;e++){let t=e;for(let a=e+1;a<n;a++)Math.abs(LF(i,a*r+e))>Math.abs(LF(i,t*r+e))&&(t=a);if(Math.abs(LF(i,t*r+e))<1e-12)return null;if(t!==e)for(let n=e;n<r;n++){let a=LF(i,e*r+n);i[e*r+n]=LF(i,t*r+n),i[t*r+n]=a}let a=LF(i,e*r+e);for(let t=e;t<r;t++)i[e*r+t]=LF(i,e*r+t)/a;for(let t=0;t<n;t++){if(t===e)continue;let n=LF(i,t*r+e);if(n!==0)for(let a=e;a<r;a++)i[t*r+a]=LF(i,t*r+a)-n*LF(i,e*r+a)}}let a=new Float64Array(n);for(let e=0;e<n;e++)a[e]=LF(i,e*r+n);return a}function zF(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 BF(e,t){let n={},r=0;for(let i of e){let e=[];for(let n=0;n<i.count;n++)e.push(LF(t,r++));n[i.child]=e}return n}function VF(e,t,n,r,i){let a=NF(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=FF(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+=LF(e,t)**2;return Math.sqrt(o)}function HF(e,t,n,r,i,a,o,s,c,l){let u=NF(o,s);for(let d=0;d<n;d++){let f=LF(t,d),p=f+c>LF(a,d)&&f-c>=LF(i,d)?-c:c;t[d]=f+p;let m=l(t);t[d]=f;let h=NF(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=FF(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 UF(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+=LF(e,t*n+r)*LF(e,i*n+r);a[t*r+i]=s+(t===i?o:0)}let s=RF(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+=LF(e,a*n+t)*LF(s,a);c[t]=i}return c}function WF(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}=zF(IF(e,t),r.seed),p=u.length,m=n=>AF(e,BF(l,n)).get(t)??MF,h=new Float64Array(c),g=new Float64Array(c*p),_=m(u),v=VF(h,_,n,s,c),y=0;for(;y<i&&p>0&&v>a;y++){HF(g,u,p,c,d,f,_,s,1e-6,m);let e=UF(g,h,p,c,o);if(!e)break;for(let t=0;t<p;t++){let n=LF(u,t)+LF(e,t);u[t]=Math.min(LF(f,t),Math.max(LF(d,t),n))}_=m(u),v=VF(h,_,n,s,c)}return{values:BF(l,u),converged:v<=a,iterations:y,error:v}}function GF(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 KF(e,t,n,r){let i=[];$P(e,e=>{e.joints&&i.push(...e.joints)});let a=i.map(e=>({child:e.child,a:GF(e,t[e.child]),b:GF(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:AF(e,r)})}return s}var qF=Math.PI/180;function JF(e,t,n,r){let i=e*qF,a=r*qF,o=lF(sF([0,0,1],i),sF([1,0,0],a));return{position:[n*Math.cos(i),n*Math.sin(i),t],rotation:o}}function YF(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=JF(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`?vF(i,a,s,c):_F(i,a,s,c),offset:o}})}var XF=Math.PI/180,ZF=180/Math.PI;function QF(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function $F(e){return String(e===0?0:e)}function eI(e){return`${$F(e[0])} ${$F(e[1])} ${$F(e[2])}`}function tI(e,t={}){let n=t.name??`robot`,r=t.effort??0,i=t.velocity??0,a=t.meshes??{},o=[],s=[];$P(e,e=>{o.push(e.name),e.joints&&s.push(...e.joints)});for(let e of s){if(e.type!==`revolute`&&e.type!==`prismatic`)return k(P(M.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' is '${e.type}'; URDF supports only revolute and prismatic joints`));if(e.offset)return k(P(M.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' carries a fixed offset (e.g. a DH link) that URDF cannot represent as a single joint`))}let c=[`<?xml version="1.0"?>`,`<robot name="${QF(n)}">`];for(let e of o){let t=a[e];t?c.push(` <link name="${QF(e)}">`,` <visual><geometry><mesh filename="${QF(t)}"/></geometry></visual>`,` </link>`):c.push(` <link name="${QF(e)}"/>`)}for(let e of s){let t=e.type===`revolute`,n=t?e.min*XF:e.min,a=t?e.max*XF:e.max,o=e.type===`prismatic`?[0,0,0]:e.axis.origin;c.push(` <joint name="${QF(`${e.parent}_to_${e.child}`)}" type="${e.type}">`,` <parent link="${QF(e.parent)}"/>`,` <child link="${QF(e.child)}"/>`,` <origin xyz="${eI(o)}" rpy="0 0 0"/>`,` <axis xyz="${eI(e.axis.direction)}"/>`,` <limit lower="${$F(n)}" upper="${$F(a)}" effort="${$F(r)}" velocity="${$F(i)}"/>`,` </joint>`)}return c.push(`</robot>`,``),O(c.join(`
|
|
16
|
-
`))}function nI(e,t){return RegExp(`\\b${t}\\s*=\\s*"([^"]*)"`).exec(e)?.[1]}function rI(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 iI(e,t){return oF(lF(lF(sF([0,0,1],t[2]),sF([0,1,0],t[1])),sF([1,0,0],t[0])),e)}function aI(e){let t=/<robot\b([^>]*)>/.exec(e);if(!t)return k(P(M.VALIDATION_FAILED,`importURDF: no <robot> element found`));let n=nI(t[1]??``,`name`)??`robot`,r=[],i=/<link\b([^>]*?)(?:\/>|>)/g;for(let t=i.exec(e);t;t=i.exec(e)){let e=nI(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=nI(e,`type`)??`fixed`;if(r===`fixed`||r===`floating`||r===`planar`)continue;let i=/<parent\b([^>]*?)\/?>/.exec(n),o=/<child\b([^>]*?)\/?>/.exec(n),s=nI(i?.[1]??``,`link`),c=nI(o?.[1]??``,`link`);if(!s||!c)return k(P(M.VALIDATION_FAILED,`importURDF: joint missing parent/child link (${nI(e,`name`)??`unnamed`})`));let l=/<origin\b([^>]*?)\/?>/.exec(n),u=/<axis\b([^>]*?)\/?>/.exec(n),d=/<limit\b([^>]*?)\/?>/.exec(n),f=rI(nI(l?.[1]??``,`xyz`),[0,0,0]),p=rI(nI(l?.[1]??``,`rpy`),[0,0,0]),m=iI(rI(nI(u?.[1]??``,`xyz`),[1,0,0]),p),h=Number(nI(d?.[1]??``,`lower`)??NaN),g=Number(nI(d?.[1]??``,`upper`)??NaN);if(r===`prismatic`){let e=Number.isFinite(h)&&Number.isFinite(g)?{min:h,max:g}:{};a.push(vF(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*ZF,max:g*ZF};a.push(_F(s,c,{origin:f,direction:m},e))}else return k(P(M.VALIDATION_FAILED,`importURDF: joint '${nI(e,`name`)??`unnamed`}' has unrecognized type '${r}'`))}return O({name:n,links:r,joints:a})}function oI(){return{steps:[],shapes:new Map}}function sI(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 cI(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 lI(e,t){return e.steps.find(e=>e.id===t)}function uI(e,t){return e.shapes.get(t)}function dI(e){return e.steps.length}function fI(e,t){let n=e.steps.findIndex(e=>e.id===t);return n===-1?[]:e.steps.slice(n)}function pI(e,t,n){let r=new Map(e.shapes);return r.set(t,n),{...e,shapes:r}}function mI(){return{operations:new Map}}function hI(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function gI(e,t){let[n,r]=t;return n!==void 0&&r===void 0&&zE(n)?mP(e,n):{...e}}function _I(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=pI(r,t,i));for(let n of e.steps){let e=t.operations.get(n.type);if(!e)return k(Eo(`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(Eo(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${n.id}`));i.push(t)}try{let t=e(i,gI(n.parameters,i));r=sI(r,{id:n.id,type:n.type,parameters:n.parameters,inputIds:n.inputIds,outputId:n.outputId},t)}catch(e){return k(Eo(`REPLAY_STEP_FAILED`,`Step ${n.id} (${n.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(r)}function vI(e,t,n){let r=e.steps.findIndex(e=>e.id===t);if(r===-1)return k(Eo(`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(Eo(`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(Eo(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${r.id}`));o.push(t)}try{let e=i(o,gI(r.parameters,o));a=sI(a,{id:r.id,type:r.type,parameters:r.parameters,inputIds:r.inputIds,outputId:r.outputId},e)}catch(e){return k(Eo(`REPLAY_STEP_FAILED`,`Step ${r.id} (${r.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(a)}function yI(e,t,n,r){return e.steps.findIndex(e=>e.id===t)===-1?k(Eo(`MODIFY_STEP_NOT_FOUND`,`Step not found: ${t}`)):vI({steps:e.steps.map(e=>e.id===t?{...e,parameters:n}:e),shapes:e.shapes},t,r)}function bI(e){let t={};for(let[n,r]of e.shapes){let e=Tk(r);if(!e.ok)return k(Eo(`SERIALIZE_SHAPE_FAILED`,`Failed to serialize shape "${n}": ${e.error.message}`));t[n]=e.value}return O({steps:e.steps,shapes:t})}function xI(e){let t=new Map;for(let[n,r]of Object.entries(e.shapes))try{let e=mO(r);if(!e.ok)return k(Eo(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e.error.message}`));t.set(n,e.value)}catch(e){return k(Eo(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e instanceof Error?e.message:String(e)}`))}return O({steps:e.steps,shapes:t})}function SI(e){try{var t=IT();let{radius:n,pitch:r,height:i,depth:a=.6*r,toothHalfWidth:o=.42*r,crest:s=0,sectionsPerTurn:c=20,lefthand:l=!1,inward:u=!1}=e;if(!(n>0))return k(P(`THREAD_INVALID_RADIUS`,`radius must be > 0`));if(!(r>0))return k(P(`THREAD_INVALID_PITCH`,`pitch must be > 0`));if(!(i>0))return k(P(`THREAD_INVALID_HEIGHT`,`height must be > 0`));if(!(a>0))return k(P(`THREAD_INVALID_DEPTH`,`depth must be > 0`));if(s<0||s>=o)return k(P(`THREAD_INVALID_CREST`,`crest must be >= 0 and < toothHalfWidth`));if(c<3)return k(P(`THREAD_TOO_FEW_SECTIONS`,`sectionsPerTurn must be >= 3`));let d=i/r,f=Math.max(2,Math.round(d*c)),p=l?-1:1,m=u?-a:a,h=u?.3:-.3,g=o,_=t.u(new XT),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=AP(f.map((e,t)=>_.register(xP(e,f[(t+1)%f.length]))));if(!Ja(y))return y;v.push(_.register(y.value))}return jM(v,{ruled:!0})}catch(e){t.e=e}finally{t.d()}}var CI=1e-9,wI=1e-8,TI=1e-6,EI=([e,t],[n,r],i=TI)=>Math.abs(e-n)<=i&&Math.abs(t-r)<=i,DI=([e,t],[n,r])=>[e+n,t+r],OI=([e,t],[n,r])=>[e-n,t-r],kI=([e,t],n)=>[e*n,t*n],AI=([e,t],[n,r]=[0,0])=>Math.sqrt((e-n)**2+(t-r)**2),jI=([e,t],[n,r]=[0,0])=>(e-n)**2+(t-r)**2;function MI([e,t],[n,r]){return e*r-t*n}var NI=([e,t],[n,r]=[0,0])=>Math.atan2(r*e-t*n,e*n+t*r),PI=([e,t],[n,r]=[0,0])=>Math.atan2(r-t,n-e),FI=(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 II([e,t]){let n=Math.sqrt(e*e+t*t);return n<1e-12?[0,0]:[e/n,t/n]}var LI=(e,t)=>[Math.cos(t)*e,Math.sin(t)*e],RI=([e,t])=>[Math.sqrt(e*e+t*t),Math.atan2(t,e)],zI=([e,t])=>{let n=II([e,t]);return n[0]===0&&n[1]===0&&i(`normalize2d`,`Cannot normalize zero-length vector`),n};function BI(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(Oo(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found ${r===0?0:`2+`} element(s)`))}function VI(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 uD(t);case`face`:return dD(t);case`wire`:return fD(t);case`vertex`:return pD(t)}}let s=e=>{let n=o(e);return t.length===0?n.slice():n.filter(a)},c=()=>VI(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=Ek(n),r=t.get(e);r?r.push(n):t.set(e,[n])}return i(e=>{let n=t.get(Ek(e));return!!n&&n.some(t=>Ok(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=>BI(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 HI={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function UI(e){return typeof e==`string`?HI[e]??[0,0,1]:e}function WI(e,t,n){let r=H(),i=r.makeVertex(t[0],t[1],t[2]);return t=>{let a=r.distance(i,t.wrapped).value;return Math.abs(a-e)<n}}function GI(e,t){let n=UD(UI(e));return e=>{let r=H(),[i,a]=r.curveParameters(e.wrapped),o=(i+a)/2,{tangent:s}=r.curveTangent(e.wrapped,o),c=UD(s),l=Math.acos(Math.min(1,Math.abs(RD(c,n))));return Math.abs(l-JE*t)<1e-6}}function KI(e){return VI(`edge`,e,KI,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(GI(e,t)),ofLength:(e,t=.001)=>n(n=>Math.abs(Ik(n)-e)<t),ofCurveType:e=>n(t=>jk(t)===e),parallelTo:(t=`Z`)=>KI(e).inDirection(t,0),atDistance:(e,t=[0,0,0])=>n(WI(e,t,1e-6))}))}function qI(){return KI([])}function JI(e,t){let n=UD(UI(e));return e=>{let r=wO(e),i=Math.acos(Math.min(1,Math.abs(RD(UD(r),n))));return Math.abs(i-JE*t)<1e-6}}function YI(e){return VI(`face`,e,YI,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(JI(e,t)),parallelTo:(t=`Z`)=>YI(e).inDirection(t,0),ofSurfaceType:e=>n(t=>{let n=gO(t);return Ja(n)&&n.value===e}),ofArea:(e,t=.001)=>n(n=>{let r=HM(n);return Ja(r)&&Math.abs(r.value-e)<t}),atDistance:(e,t=[0,0,0])=>n(WI(e,t,1e-6))}))}function XI(){return YI([])}function ZI(e){return VI(`wire`,e,ZI,(e,t)=>({isClosed:()=>t(e=>Rk(e)),isOpen:()=>t(e=>!Rk(e)),ofEdgeCount:e=>t(t=>uD(t).length===e)}))}function QI(){return ZI([])}function $I(e,t){return typeof e==`object`&&`_topoKind`in e?e.findUnique(t):typeof e!=`function`&&FE(e)?O(e):e(XI()).findUnique(t)}function eL(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`}function tL(e,t){let n=10**t,r=t<0?e:.01/n+e;return Math.round(r*n)/n}function nL(e){return Math.round(e*100)/100}function rL(e){return Math.round(e*1e5)/1e5}var iL=([e,t])=>`(${nL(e)},${nL(t)})`,aL=(e,t=1e-9)=>{let n=e;return Math.abs(e)<t&&(n=0),n.toFixed(-Math.log10(t))},oL=(e,t=1e-9)=>Array.from(new Map(e.map(([e,n])=>[`[${aL(e,t)},${aL(n,t)}]`,[e,n]])).values()),sL=class{_wrapped;_deleted=!1;constructor(e){this._wrapped=e??wT().createBoundingBox2d(),QT(this,this._wrapped)}get wrapped(){if(this._deleted)throw Error(`This object has been deleted`);return this._wrapped}delete(){this._deleted||(this._deleted=!0,$T(this._wrapped),typeof this._wrapped.delete==`function`&&this._wrapped.delete())}[Symbol.dispose](){this.delete()}get repr(){let[e,t]=this.bounds;return`${iL(e)} - ${iL(t)}`}get bounds(){let{xMin:e,yMin:t,xMax:n,yMax:r}=wT().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){wT().mergeBBox2d(this.wrapped,e.wrapped)}isOut(e){return wT().isBBox2dOut(this.wrapped,e.wrapped)}containsPoint(e){return!wT().isBBox2dOutPoint(this.wrapped,e[0],e[1])}};function cL(e){return new lL(H().deserializeCurve2d(e))}var lL=class e{_wrapped;_deleted=!1;_boundingBox;_firstPoint=null;_lastPoint=null;_firstParameter=null;_lastParameter=null;constructor(e){this._wrapped=H().wrapCurve2dHandle(e),this._boundingBox=null,typeof this._wrapped.delete==`function`&&QT(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`&&($T(this._wrapped),this._wrapped.delete()))}[Symbol.dispose](){this.delete()}get boundingBox(){if(this._boundingBox)return this._boundingBox;let e=H(),t=e.createBoundingBox2d();return e.addCurveToBBox2d(t,this.wrapped,1e-6),this._boundingBox=new sL(t),this._boundingBox}get repr(){return`${this.geomType} ${iL(this.firstPoint)} - ${iL(this.lastPoint)}`}serialize(){return H().serializeCurve2d(this.wrapped)}value(e){return H().evaluateCurve2d(this.wrapped,e)}get firstPoint(){return this._firstPoint===null&&(this._firstPoint=this.value(this.firstParameter)),this._firstPoint}get lastPoint(){return this._lastPoint===null&&(this._lastPoint=this.value(this.lastParameter)),this._lastPoint}get firstParameter(){return this._firstParameter===null&&(this._firstParameter=H().getCurve2dBounds(this.wrapped).first),this._firstParameter}get lastParameter(){return this._lastParameter===null&&(this._lastParameter=H().getCurve2dBounds(this.wrapped).last),this._lastParameter}get geomType(){return H().getCurve2dType(this.wrapped)}clone(){let t=new e(H().copyCurve2d(this.wrapped));return t._firstPoint=this._firstPoint,t._lastPoint=this._lastPoint,t._firstParameter=this._firstParameter,t._lastParameter=this._lastParameter,t}reverse(){H().reverseCurve2d(this.wrapped);let e=this._firstPoint;this._firstPoint=this._lastPoint,this._lastPoint=e;let t=this._firstParameter;this._firstParameter=this._lastParameter,this._lastParameter=t}distanceFromPoint(e){let t=H().projectPointOnCurve2d(this.wrapped,e[0],e[1]),n=t?t.distance:1/0;return Math.min(n,AI(e,this.firstPoint),AI(e,this.lastPoint))}distanceFromCurve(e){let t;try{t=H().distanceBetweenCurves2d(this.wrapped,e.wrapped,this.firstParameter,this.lastParameter,e.firstParameter,e.lastParameter)}catch{t=1/0}return Math.min(t,this.distanceFromPoint(e.firstPoint),this.distanceFromPoint(e.lastPoint),e.distanceFromPoint(this.firstPoint),e.distanceFromPoint(this.lastPoint))}distanceFrom(e){return eL(e)?this.distanceFromPoint(e):this.distanceFromCurve(e)}isOnCurve(e){return this.distanceFromPoint(e)<1e-9}parameter(e,t=1e-9){let n,r,i=!1;try{let t=H().projectPointOnCurve2d(this.wrapped,e[0],e[1]);t?(n=t.distance,r=t.param):i=!0}catch{i=!0}return i?EI(e,this.firstPoint,t)?O(this.firstParameter):EI(e,this.lastPoint,t)?O(this.lastParameter):k(Eo(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n===void 0||r===void 0?k(Eo(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n>t?k(Eo(`POINT_NOT_ON_CURVE`,`Point ${iL(e)} not on curve ${this.repr}, ${n.toFixed(9)}`)):O(r)}tangentAt(e){let t;if(Array.isArray(e))t=j(this.parameter(e));else{let n=H().getCurve2dBounds(this.wrapped);t=(n.last-n.first)*e+n.first}return H().evaluateCurve2dD1(this.wrapped,t).tangent}splitAt(n,r=1e-9){let i=n.map(e=>eL(e)?j(this.parameter(e,r)):e);i=Array.from(new Map(i.map(e=>[tL(e,-Math.log10(r)),e])).values()).sort((e,t)=>e-t);let a=this.firstParameter,o=this.lastParameter;return a>o&&i.reverse(),Math.abs(t(i,0)-a)<r*100&&(i=i.slice(1)),!i.length||(Math.abs(t(i,i.length-1)-o)<r*100&&(i=i.slice(0,-1)),!i.length)?[this]:H().splitCurve2d(this.wrapped,i).map(t=>new e(t))}},uL=(e,t=1e-4,n=`C0`,r=200)=>new lL(wT().approximateCurve2dAsBSpline(e.wrapped,t,n,r)),dL=e=>(e.geomType!==`BSPLINE_CURVE`&&i(`BSplineToBezier`,`You can only convert a Bspline`),wT().decomposeBSpline2dToBeziers(e.wrapped).map(e=>new lL(e)));function fL(e,t={tolerance:1e-4,continuity:`C0`,maxSegments:300}){let n=wT();return e.flatMap(e=>{let r=e.geomType;if(r===`ELLIPSE`||r===`CIRCLE`&&EI(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 fL(dL(r===`BSPLINE_CURVE`?e:uL(e,t.tolerance,t.continuity,t.maxSegments)),t)})}var pL=(e,t)=>{let n=new lL(H().makeLine2d(e[0],e[1],t[0],t[1]));return EI(n.firstPoint,e)||n.reverse(),n},mL=(e,t,n)=>{let r=new lL(H().makeArc2dThreePoints(e[0],e[1],t[0],t[1],n[0],n[1]));if(!EI(r.firstPoint,e)){let e=H().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new lL(e)}return r},hL=(e,t,n)=>{let r=new lL(H().makeArc2dTangent(e[0],e[1],t[0],t[1],n[0],n[1]));if(!EI(r.firstPoint,e)){let e=H().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new lL(e)}return r},gL=(e,t=[0,0])=>new lL(H().makeCircle2d(t[0],t[1],e,!0)),_L=(e,t,n=[1,0],r=[0,0],i=!0)=>new lL(H().makeEllipse2d(r[0],r[1],e,t,n[0],n[1],i)),vL=(e,t,n,r,i=[0,0],a,o=!0)=>new lL(H().makeEllipseArc2d(i[0],i[1],e,t,n,r,a[0],a[1],o)),yL=(e,t,n)=>{let r=[[e[0],e[1]],...t.map(e=>[e[0],e[1]]),[n[0],n[1]]];return new lL(H().makeBezier2d(r))};function bL(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 lL(H().makeBSpline2d(a,{tolerance:t,smoothing:n,degMax:r,degMin:i,continuity:`C2`})))}catch(e){return k(Eo(`BSPLINE_2D_FAILED`,`B-spline approximation failed`,e))}}var xL=(e,t,n,r=!1)=>{let i=kI(DI(e,t),.5),a=AI(n,e)*(r?-1:1);return mL(e,DI(kI(zI(OI(i,n)),a),n),t)},SL=(e,n)=>{let r=wT(),a=e.geomType,[o,s]=n,c=`${rL(o)} ${rL(s)}`;if(a===`LINE`)return`L ${c}`;if(a===`BEZIER_CURVE`){let n=r.getCurve2dBezierPoles(e.wrapped);n||i(`adaptedCurveToPathElem`,`Expected Bezier poles`);let a=n.length-1;if(a===1)return`L ${c}`;if(a===2){let[e,r]=t(n,1);return`Q ${nL(e)} ${nL(r)} ${c}`}if(a===3){let[e,r]=t(n,1),[i,a]=t(n,2);return`C ${nL(e)} ${nL(r)} ${nL(i)} ${nL(a)} ${c}`}}if(a===`CIRCLE`){let t=r.getCurve2dCircleData(e.wrapped);t||i(`adaptedCurveToPathElem`,`Expected circle data`);let{radius:n,isDirect:a}=t,l=r.getCurve2dBounds(e.wrapped),u=(l.last-l.first)*YE,d=u===360?`${rL(o)} ${rL(s+1e-4)}`:c;return`A ${n} ${n} 0 ${Math.abs(u)>180?`1`:`0`} ${a?`1`:`0`} ${d}`}if(a===`ELLIPSE`){let t=r.getCurve2dEllipseData(e.wrapped);t||i(`adaptedCurveToPathElem`,`Expected ellipse data`);let{majorRadius:n,minorRadius:a,xAxisAngle:l,isDirect:u}=t,d=r.getCurve2dBounds(e.wrapped),f=(d.last-d.first)*YE,p=f===360?`${rL(o)} ${rL(s+1e-4)}`:c,m=180-l*YE;return`A ${rL(n)} ${rL(a)} ${rL(m)} ${Math.abs(f)>180?`1`:`0`} ${u?`1`:`0`} ${p}`}i(`adaptedCurveToPathElem`,`Unsupported curve type: ${a}`)},CL=e=>{let t=H(),n=t.createBoundingBox2d();return e.forEach(e=>{t.addCurveToBBox2d(n,e.wrapped,1e-6)}),new sL(n)};function wL(e,t){let n=H();return e.map(e=>TE(n.liftCurve2dToPlane(e.wrapped,[...t.origin],[...t.zDir],[...t.xDir])))}var TL=(e,t)=>{let n=H();return e.map(e=>TE(n.buildEdgeOnSurface(e.wrapped,t)))},EL=(e,t)=>{let n=H();return e.map(e=>t?new lL(n.transformCurve2dGeneral(e.wrapped,t)):e.clone())},DL=(e,t,n=[0,0])=>H().createAffinityGTrsf2d(n[0],n[1],-t[1],t[0],e),OL=e=>H().createTranslationGTrsf2d(e[0],e[1]),kL=(e,t=[0,0],n=`center`)=>n===`center`?H().createMirrorGTrsf2d(e[0],e[1],`point`):H().createMirrorGTrsf2d(0,0,`axis`,t[0],t[1],e[0],e[1]),AL=(e,t=[0,0])=>H().createRotationGTrsf2d(e,t[0],t[1]),jL=(e,t=[0,0])=>H().createScaleGTrsf2d(e,t[0],t[1]);function ML(e,t,n=`original`){let r=H(),i=r.extractSurfaceFromFace(t.wrapped),a=bO(t),o=null;if(n===`original`&&_O(t)!==`PLANE`){if(_O(t)!==`CYLINDRE`)return k(P(`UNSUPPORTED_FACE_TYPE`,`Only planar and cylindrical faces can be unwrapped for sketching`));let e=r.getSurfaceCylinderData(i);if(!e)return k(P(`UNSUPPORTED_FACE_TYPE`,`Could not extract cylinder data from face surface`));e.isDirect||(i=r.reverseSurfaceU(i)),o=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=TL(EL(e,o),i);return o&&o.delete(),O(s)}function NL(e,t){let n=H(),r=new lL(n.extractCurve2dFromEdge(e.wrapped,t.wrapped));return Vk(e)===`backward`&&n.reverseCurve2d(r.wrapped),r}var PL=(e,t=1)=>`${e.bounds[0][0]-t} ${-e.bounds[1][1]-t} ${e.width+2*t} ${e.height+2*t}`,FL=(e,t,n=1)=>`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${PL(t,n)}" fill="none" stroke="black" stroke-width="0.6%" vector-effect="non-scaling-stroke">
|
|
15
|
+
npm install brepkit-wasm`)}function IT(){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 LT=Symbol;LT.dispose??=Symbol.for(`Symbol.dispose`),LT.asyncDispose??=Symbol.for(`Symbol.asyncDispose`);var RT=globalThis;RT.FinalizationRegistry||=(console.warn(`brepjs: FinalizationRegistry unavailable — garbage collection will not work`),class{register(e,t,n){}unregister(e){return!1}});var zT={liveHandles:0,peakHandles:0,gcCollected:0,scopeEnters:0,scopeExits:0};function BT(){return{...zT}}function VT(){zT.liveHandles=0,zT.peakHandles=0,zT.gcCollected=0,zT.scopeEnters=0,zT.scopeExits=0}function HT(){zT.liveHandles++,zT.liveHandles>zT.peakHandles&&(zT.peakHandles=zT.liveHandles)}function UT(){zT.liveHandles--}function WT(){zT.gcCollected++,zT.liveHandles--}var GT=new FinalizationRegistry(e=>{WT();try{e.delete()}catch{}});function KT(e){let t=H(),n=!1,r,i=()=>{if(r){for(let e of r)try{e()}catch{}r=void 0}},a=()=>{if(!n){n=!0,UT(),GT.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 HT(),GT.register(o,{delete:()=>{t.dispose(e)}},o),o}function qT(e){let t=()=>{};return{get wrapped(){return e},get disposed(){return!1},[Symbol.dispose]:t,delete:t,onDispose:t}}function JT(e){let t=H(),n;try{n=t.checkpoint()}catch(t){if(!l(t))throw t;return e()}let r;try{r=e()}catch(e){try{t.restoreCheckpoint(n)}catch{}throw e}return t.restoreCheckpoint(n),r}function YT(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,UT(),GT.unregister(n);try{e.delete()}catch{}}}};return HT(),GT.register(n,e,n),n}var XT=class{handles=[];constructor(){zT.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](){zT.scopeExits++;for(let e=this.handles.length-1;e>=0;e--)this.handles[e]?.();this.handles.length=0}};function ZT(e){try{var t=IT();return e(t.u(new XT))}catch(e){t.e=e}finally{t.d()}}function QT(e,t){GT.register(e,t,t)}function $T(e){GT.unregister(e)}function eE(e){try{var t=IT();return e(t.u(new XT))}catch(e){t.e=e}finally{t.d()}}async function tE(e){try{var t=IT();return await e(t.u(new XT))}catch(e){t.e=e}finally{t.d()}}function nE(e){return!e.disposed}function rE(e){return e.__is2D!==!0}function iE(e){return e.__is2D===!0}function aE(e){if(!rE(e))throw Error(`Expected 3D shape, got 2D`);return e}function oE(e){if(!iE(e))throw Error(`Expected 2D shape, got 3D`);return e}var sE=new WeakMap;function cE(e,t){sE.set(e,t)}function lE(e,t){let n=sE.get(t);if(n!==void 0)return n;let r=e.shapeType(t);return sE.set(t,r),r}function uE(e){return lE(H(),e.wrapped)}function dE(e){return H().curveIsClosed(e.wrapped)}function fE(e){return H().isValid(e.wrapped)}function pE(e){let t=H();if(!t.isValid(e.wrapped))return!1;let n=t.isValidStrict?.bind(t)??t.isValid.bind(t);try{let r=t.solidFromShell(e.wrapped),i=n(r);try{t.dispose(r)}catch{}return i}catch{return!1}}function mE(e){return H().isValid(e.wrapped)}function hE(e){return dE(e)?O(e):k(`Wire is not closed: start and end points do not coincide`)}function gE(e){return fE(e)?O(e):k(`Face orientation is inconsistent or face is invalid`)}function _E(e){return pE(e)?O(e):k(`Shell is not manifold: has free edges or is invalid`)}function vE(e){return mE(e)?O(e):k(`Solid failed BRepCheck validation`)}function yE(e){return H().surfaceType(e.wrapped)===`plane`}function bE(e){let t=H(),n=n=>{try{let r=t.makeFace(e.wrapped,n),i=t.surfaceType(r);try{t.dispose(r)}catch{}return i===`plane`}catch{return!1}};return n(!0)?!0:n(!1)}function xE(e){return yE(e)?O(e):k(`Face is not planar: underlying surface is not a geometric plane`)}function SE(e){return bE(e)?O(e):k(`Wire is not planar: edges do not lie in a common plane`)}function CE(e,t){return t===`2D`&&(e.__is2D=!0),e}function wE(e,t){return CE(KT(e),t)}function TE(e,t){return CE(KT(e),t)}function EE(e,t){return CE(KT(e),t)}function DE(e,t){return CE(KT(e),t)}function OE(e){return CE(KT(e))}function kE(e){return CE(KT(e))}function AE(e){return CE(KT(e))}function jE(e,t){return CE(KT(e),t)}function ME(e){return uE(e)===`vertex`}function NE(e){return uE(e)===`edge`}function PE(e){return uE(e)===`wire`}function FE(e){return uE(e)===`face`}function IE(e){return uE(e)===`shell`}function LE(e){return uE(e)===`solid`}function RE(e){return uE(e)===`compound`}function zE(e){let t=uE(e);return t===`shell`||t===`solid`||t===`compsolid`?!0:t===`compound`?rE(e):!1}function BE(e){let t=uE(e);return t===`edge`||t===`wire`}function VE(e,t){let n=H(),r=lE(n,e),i=n.downcast(e,r);return r===`vertex`?wE(i,t):r===`edge`?TE(i,t):r===`wire`?EE(i,t):r===`face`?DE(i,t):r===`shell`?OE(i):r===`solid`?kE(i):r===`compsolid`?AE(i):jE(i,t)}function HE(e){return VE(e)}function UE(e,t){let n=e.id,r=t.wrapped.id;(n!==void 0&&r!==void 0?n===r:t.wrapped===e)||H().dispose(e)}function U(e,t){let n=VE(e,t);return UE(e,n),n}function WE(e,t){let n=e.wrapped;if(e[Symbol.dispose](),n!==t){let e=H();e.dispose(n),e.dispose(t)}}function W(e){H().dispose(e.wrapped),e[Symbol.dispose]()}function GE(e,t,n){cE(e,t);let r=H().downcast(e,t);return t===`vertex`?wE(r,n):t===`edge`?TE(r,n):t===`wire`?EE(r,n):t===`face`?DE(r,n):t===`shell`?OE(r):t===`solid`?kE(r):t===`compsolid`?AE(r):jE(r,n)}function KE(e,t,n){let r=GE(e,t,n);return UE(e,r),r}function qE(e,t,n){return cE(e,t),CE(qT(e),n)}var G=2147483647,JE=Math.PI/180,YE=180/Math.PI;function XE(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)=>XE(`KERNEL_OPERATION`,e,t,n,r),VALIDATION:(e,t,n,r)=>XE(`VALIDATION`,e,t,n,r),TYPE_CAST:(e,t,n,r)=>XE(`TYPE_CAST`,e,t,n,r),SKETCHER_STATE:(e,t,n,r)=>XE(`SKETCHER_STATE`,e,t,n,r),MODULE_INIT:(e,t,n,r)=>XE(`MODULE_INIT`,e,t,n,r),COMPUTATION:(e,t,n,r)=>XE(`COMPUTATION`,e,t,n,r),IO:(e,t,n,r)=>XE(`IO`,e,t,n,r),QUERY:(e,t,n,r)=>XE(`QUERY`,e,t,n,r),UNSUPPORTED:(e,t,n,r)=>XE(`UNSUPPORTED`,e,t,n,r)};function QE(e,t,n,r=`KERNEL_OPERATION`){try{return O(U(e()))}catch(e){let i=e instanceof Error?e.message:String(e),a=r===`KERNEL_OPERATION`?xo(i):i,o=bo(t);return k(ZE[r](t,`${n}: ${a}`,e,o))}}function $E(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`?xo(i):i,o=bo(t);return k(ZE[r](t,`${n}: ${a}`,e,o))}}function eD(e,t,n,r=`KERNEL_OPERATION`){try{var i=IT();let a=i.u(new XT);return QE(()=>e(a),t,n,r)}catch(e){i.e=e}finally{i.d()}}function tD(e,t){let n=H().iterShapes(e,t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=KE(n[e],t);return r}function nD(e,t){let n=H();if(n.subShapeCount)return n.subShapeCount(e.wrapped,t);let r=n.iterShapes(e.wrapped,t);for(let e of r)n.dispose(e);return r.length}function rD(e,t){let n=H();if(n.subShapeHashes)return n.subShapeHashes(e.wrapped,t,G);let r=new Set;for(let i of n.iterShapes(e.wrapped,t))r.add(n.hashCode(i,G)),n.dispose(i);return[...r]}var iD=new WeakMap;function aD(e){let t=iD.get(e);if(!t)return;iD.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 oD=new WeakSet;function sD(e){let t=e.wrapped,n=iD.get(t);return n||(n={},iD.set(t,n)),oD.has(e)||(oD.add(e),e.onDispose(()=>{aD(t)})),n}function cD(e){return iD.get(e.wrapped)}function lD(e){aD(e.wrapped)}function uD(e){let t=sD(e);if(t.edges)return t.edges;let n=tD(e.wrapped,`edge`);return t.edges=n,n}function dD(e){let t=sD(e);if(t.faces)return t.faces;let n=tD(e.wrapped,`face`);return t.faces=n,n}function fD(e){let t=sD(e);if(t.wires)return t.wires;let n=tD(e.wrapped,`wire`);return t.wires=n,n}function pD(e){let t=sD(e);if(t.vertices)return t.vertices;let n=tD(e.wrapped,`vertex`);return t.vertices=n,n}function mD(e){let t=sD(e);if(t.solids)return t.solids;let n=tD(e.wrapped,`solid`);return t.solids=n,n}function hD(e){let t=sD(e);if(t.shells)return t.shells;let n=tD(e.wrapped,`shell`);return t.shells=n,n}function gD(e){let t=sD(e);if(t.compSolids)return t.compSolids;let n=tD(e.wrapped,`compsolid`);return t.compSolids=n,n}function*_D(e){for(let t of H().iterShapes(e.wrapped,`edge`))yield KE(t,`edge`)}function*vD(e){for(let t of H().iterShapes(e.wrapped,`face`))yield KE(t,`face`)}function*yD(e){for(let t of H().iterShapes(e.wrapped,`wire`))yield KE(t,`wire`)}function*bD(e){for(let t of H().iterShapes(e.wrapped,`vertex`))yield KE(t,`vertex`)}function*xD(e){for(let t of H().iterShapes(e.wrapped,`solid`))yield KE(t,`solid`)}function*SD(e){for(let t of H().iterShapes(e.wrapped,`shell`))yield KE(t,`shell`)}function*CD(e){for(let t of H().iterShapes(e.wrapped,`compsolid`))yield KE(t,`compsolid`)}function wD(e){let t=sD(e);if(t.bounds)return t.bounds;let{min:n,max:r}=H().boundingBox(e.wrapped),i={xMin:n[0],xMax:r[0],yMin:n[1],yMax:r[1],zMin:n[2],zMax:r[2]};return t.bounds=i,i}function TD(e){return lE(H(),e.wrapped)}function ED(e){let t=sD(e);if(t.surfaceType!==void 0)return t.surfaceType;let n=H().surfaceType(e.wrapped);return t.surfaceType=n,n}function DD(e){let t=sD(e);if(t.isValid!==void 0)return t.isValid;let n=H().isValid(e.wrapped);return t.isValid=n,n}function OD(e){return{kind:TD(e),faceCount:nD(e,`face`),edgeCount:nD(e,`edge`),wireCount:nD(e,`wire`),vertexCount:nD(e,`vertex`),valid:DD(e),bounds:wD(e)}}function kD(e){return H().vertexPosition(e.wrapped)}function AD(e){return e.length===2?[e[0],e[1],0]:[e[0],e[1],e[2]]}function jD(e){return[e[0],e[1]]}var MD={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function ND(e){if(typeof e==`string`){let t=MD[e];if(!t)throw Error(`Unknown direction: ${e}`);return t}return e}function PD(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function FD(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function ID(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function LD(e){return[-e[0],-e[1],-e[2]]}function RD(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function zD(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 BD(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function VD(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function HD(e,t){return BD(FD(e,t))}function UD(e){let t=BD(e);return t<1e-10?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function WD(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 GD(e,t=1e-10){return VD(e)<t*t}function KD(e,t){let n=RD(e,t),r=BD(e),i=BD(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 qD(e,t,n){let r=FD(e,t),i=VD(n);return i<1e-20?e:FD(e,ID(n,RD(r,n)/i))}function JD(e,t,n){let r=UD(t),i=Math.cos(n),a=Math.sin(n),o=RD(e,r),s=zD(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 YD=e=>Math.round(e*1e3)/1e3;function XD(e){return`x: ${YD(e[0])}, y: ${YD(e[1])}, z: ${YD(e[2])}`}function ZD(e,t=null,n=[0,0,1]){let r=UD(n);if(GD(r))throw Error(`Plane normal must be non-zero`);let i;if(t)i=UD(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?UD([l,u,d]):[1,0,0]}if(GD(i))throw Error(`Plane xDir must be non-zero`);let a=UD(zD(r,i));return{origin:e,xDir:i,yDir:a,zDir:r}}var QD={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 $D(e,t=[0,0,0]){let n=QD[e];if(!n)return k(P(`UNKNOWN_PLANE`,`Could not find plane ${e}`));let r;return r=typeof t==`number`?ID(n.normal,t):AD(t),O(ZD(r,n.xDir,n.normal))}function eO(e,t){return typeof e==`string`?$D(e,t):O(e)}function tO(e,t){return e&&typeof e!=`string`?{...e}:j(eO(e??`XY`,t))}function nO(e,t){let[n,r]=t;return PD(PD(e.origin,ID(e.xDir,n)),ID(e.yDir,r))}function rO(e,t){return{...e,origin:PD(e.origin,t)}}function iO(e,t,n=[1,0,0]){let r=t*JE,i=JD(e.zDir,n,r),a=JD(e.xDir,n,r),o=UD(zD(i,a));return{origin:e.origin,xDir:a,yDir:o,zDir:i}}var aO={compound:0,solidCompound:1,solid:2,shell:3,face:4,wire:5,edge:6,vertex:7,shape:8},oO=e=>aO[e],sO={vertex:`vertex`,edge:`edge`,wire:`wire`,face:`face`,shell:`shell`,solid:`solid`,solidCompound:`compsolid`,compound:`compound`,shape:`compound`},cO=function*(e,t){let n=H().iterShapes(e,sO[t]);for(let e of n)yield e},lO=e=>H().isNull(e)?k(Co(`NULL_SHAPE`,`This shape has no type, it is null`)):O(e.ShapeType());function uO(e){if(H().isNull(e))return k(Co(`NULL_SHAPE`,`This shape has no type, it is null`));try{return O(H().downcast(e))}catch(e){return k(Co(`NO_WRAPPER`,`Could not find a wrapper for this shape type`,e))}}function dO(e){if(H().isNull(e))return k(Co(`NULL_SHAPE`,`Cannot copy a null shape`));try{return O(H().copyShape(e))}catch(e){return k(Co(`NO_WRAPPER`,`Could not copy this shape`,e))}}function fO(e){return H().isNull(e)?k(Co(`NULL_SHAPE`,`Cannot cast a null shape`)):O(VE(e))}function pO(e){return H().shapeType(e.wrapped)===`compsolid`}function mO(e){return fO(H().fromBREP(e))}var hO={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 gO(e){return O(hO[ED(e)])}function _O(e){return j(gO(e))}function vO(e){return H().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function yO(e){return VE(H().reverseShape(e.wrapped))}function bO(e){return H().uvBounds(e.wrapped)}function xO(e,t,n){let r=bO(e),i=t*(r.uMax-r.uMin)+r.uMin,a=n*(r.vMax-r.vMin)+r.vMin;return H().pointOnSurface(e.wrapped,i,a)}function SO(e,t){let n=AD(t);return H().uvFromPoint(e.wrapped,n)||[0,0]}function CO(e,t){let n=AD(t);try{let t=n,r=H().uvFromPoint(e.wrapped,t);if(!r)return k(Co(`PROJECTION_FAILED`,`No projection found on the face`));let i=H().projectPointOnFace(e.wrapped,t),a=n[0]-i[0],o=n[1]-i[1],s=n[2]-i[2];return O({uv:r,point:i,distance:Math.sqrt(a*a+o*o+s*s)})}catch(e){return k(Co(`PROJECTION_FAILED`,`Point projection failed: ${e instanceof Error?e.message:String(e)}`))}}function wO(e,t){let n,r;if(t)[n,r]=SO(e,t);else{let t=bO(e);n=.5*(t.uMin+t.uMax),r=.5*(t.vMin+t.vMax)}return H().surfaceNormal(e.wrapped,n,r)}function TO(e){return H().surfaceCenterOfMass(e.wrapped)}function EO(e){return H().getSurfaceAxis(e.wrapped)}function DO(e,t,n=1e-6){let[r,i]=SO(e,t);return H().classifyPointOnFace(e.wrapped,r,i,n)}function OO(e){return VE(H().outerWire(e.wrapped))}function kO(e){return VE(H().removeHolesFromFace(e.wrapped))}function AO(e){let t=OO(e);return Array.from(cO(e.wrapped,`wire`)).map(e=>VE(j(uO(e)))).filter(e=>!H().isSame(e.wrapped,t.wrapped))}function jO(e,t){let n=sD(e),r=new Map;for(let n of rD(e,`face`))r.set(n,t);n.faceOrigins=r}function MO(e){return cD(e)?.faceOrigins}function NO(e,t,n){let r=new Map;for(let e of t){let t=MO(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=sD(n);e.faceOrigins=i}}var PO=100,FO=.985,IO=.1;function LO(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>PO)continue;let u=r-l/PO;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)<FO)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>IO)continue;let u=Math.max(0,i*i+a*a+c*c-l*l);u<o&&(o=u,s=n.origin)}return s}function RO(e,t){let n=new Map;for(let t of e){let e=MO(t);if(e)for(let[t,r]of e)n.set(t,r)}if(n.size===0)return;let r=H(),i=new Map,a=dD(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=MO(n);if(e)for(let i of dD(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=LO(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=sD(t);e.faceOrigins=i}}var zO=new WeakMap,BO=new WeakMap;function VO(e){return zO.has(e.wrapped)}function HO(e){let t=zO.get(e.wrapped);return t||(t=new Map,zO.set(e.wrapped,t)),t}function UO(e){let t=BO.get(e.wrapped);return t||(t=new Map,BO.set(e.wrapped,t)),t}function WO(e,t,n){let r=Array.isArray(t)?t:dD(e).filter(t),i=HO(e),a=i.get(n)??new Set;for(let e of r)a.add(H().hashCode(e.wrapped,G));return i.set(n,a),e}function GO(e,t){let n=zO.get(e.wrapped);if(!n)return[];let r=n.get(t);if(!r||r.size===0)return[];let i=[];for(let t of dD(e)){let e=H().hashCode(t.wrapped,G);r.has(e)&&i.push(t)}return i}function KO(e){let t=new Map,n=zO.get(e.wrapped);if(!n)return t;let r=dD(e),i=new Map;for(let e of r)i.set(H().hashCode(e.wrapped,G),e);for(let[e,r]of n){let n=[];for(let e of r){let t=i.get(e);t&&n.push(t)}n.length>0&&t.set(e,n)}return t}function qO(e,t,n){return UO(e).set(t,n),e}function JO(e,t){return BO.get(e.wrapped)?.get(t)}function YO(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function XO(e,t,n){let r=HO(n);for(let i of t){let t=zO.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)YO(r,t,e)}let o=BO.get(i.wrapped);if(o){let e=UO(n);for(let[t,n]of o)e.has(t)||e.set(t,n)}}}var ZO=new WeakMap,QO=new WeakMap;function $O(e){return ZO.has(e.wrapped)||QO.has(e.wrapped)}function ek(e){let t=QO.get(e.wrapped);return t||(t=new Map,QO.set(e.wrapped,t)),t}function tk(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 nk(e,t){return ZO.set(e.wrapped,tk(t)),e}function rk(e,t,n){let r=tk(n),i=ek(e);for(let e of t)i.set(H().hashCode(e.wrapped,G),r);return e}function ik(e){return ZO.get(e.wrapped)}function ak(e,t){let n=QO.get(e.wrapped);if(n)return n.get(H().hashCode(t.wrapped,G))}function ok(e,t,n){for(let e of t){let t=ZO.get(e.wrapped);if(t){ZO.set(n.wrapped,t);break}}let r=ek(n);for(let n of t){let t=QO.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 sk(e){return MO(e)!==void 0||VO(e)||$O(e)}function ck(e){if(!e.some(sk))return[];let t=[];for(let n of e)t.push(...rD(n,`face`));return t}function lk(e,t,n){NO(e,t,n),XO(e,t,n),ok(e,t,n)}function uk(e,t){RO(e,t)}function dk(e,t){let n=H(),r=[...n.iterShapes(e.wrapped,`face`)],i=[...n.iterShapes(t.wrapped,`face`)];if(r.length!==i.length)return;let a=new Map;for(let e=0;e<r.length;e++){let t=r[e],o=i[e];t===void 0||o===void 0||a.set(n.hashCode(t,G),[n.hashCode(o,G)])}for(let e of r)n.dispose(e);for(let e of i)n.dispose(e);lk({modified:a,generated:new Map,deleted:new Set},[e],t)}function fk(e,t){let n=ck([e]),{shape:r,evolution:i}=H().translateWithHistory(e.wrapped,t[0],t[1],t[2],n,G),a=U(r);return lk(i,[e],a),a}function pk(e,t,n=[0,0,0],r=[0,0,1]){let i=ck([e]),{shape:a,evolution:o}=H().rotateWithHistory(e.wrapped,t*JE,i,G,r,n),s=U(a);return lk(o,[e],s),s}function mk(e,t=[0,1,0],n=[0,0,0]){let r=ck([e]),{shape:i,evolution:a}=H().mirrorWithHistory(e.wrapped,n,t,r,G),o=U(i);return lk(a,[e],o),o}function hk(e,t,n=[0,0,0]){let r=ck([e]),{shape:i,evolution:a}=H().scaleWithHistory(e.wrapped,n,t,r,G),o=U(i);return lk(a,[e],o),o}function gk(e,t,n){let r=H().boundingBox(e.wrapped),i=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]],a=n?.auto===!0;function o(e,t,n){return e!==void 0&&t>1e-12?e/t:e===void 0&&a?n:1}let s=1;a&&(t[0]!==void 0&&i[0]>1e-12?s=t[0]/i[0]:t[1]!==void 0&&i[1]>1e-12?s=t[1]/i[1]:t[2]!==void 0&&i[2]>1e-12&&(s=t[2]/i[2]));let c=[o(t[0],i[0],s),o(t[1],i[1],s),o(t[2],i[2],s)];return Math.abs(c[0]-c[1])<1e-6&&Math.abs(c[1]-c[2])<1e-6?O(hk(e,c[0])):k(P(M.VALIDATION_FAILED,`resize: non-uniform scaling is not supported (WASM build lacks BRepBuilderAPI_GTransform).`,void 0,void 0,`Use auto: true to scale proportionally, or set all three dimensions to achieve uniform scaling.`))}function _k(e){if(`linear`in e)return O({linear:e.linear,translation:e.translation});let[t,n,r,i]=e,a=1e-10;return Math.abs(i[0])>a||Math.abs(i[1])>a||Math.abs(i[2])>a||Math.abs(i[3]-1)>a?k(P(M.VALIDATION_FAILED,`applyMatrix: invalid bottom row [${String(i[0])}, ${String(i[1])}, ${String(i[2])}, ${String(i[3])}]. Must be [0, 0, 0, 1] for an affine transform.`)):O({linear:[t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]],translation:[t[3],n[3],r[3]]})}function vk(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 yk(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 bk(e,t){let n=_k(t);if(!n.ok)return n;let{linear:r,translation:i}=n.value,a=vk(r);if(Math.abs(a)<1e-12)return k(P(M.VALIDATION_FAILED,`applyMatrix: singular matrix (determinant ≈ 0). Cannot apply a non-invertible transform.`));if(yk(r)){let t=ck([e]),{shape:n,evolution:a}=H().generalTransformWithHistory(e.wrapped,r,i,!0,t,G),o=U(n);return lk(a,[e],o),O(o)}let o=U(H().generalTransformNonOrthogonal(e.wrapped,r,i));return uk([e],o),O(o)}function xk(e){let t=e.map(e=>e.type===`translate`?{type:`translate`,x:e.v[0],y:e.v[1],z:e.v[2]}:{type:`rotate`,angle:e.angle,axis:e.axis,center:e.center}),{handle:n,dispose:r}=H().composeTransform(t);return{trsf:n,cleanup:r}}function Sk(e,t){let{trsf:n,cleanup:r}=xk(`type`in t?[t]:t),i;try{i=U(H().locate(e.wrapped,n))}finally{r()}return sk(e)&&dk(e,i),i}function Ck(e,t){let n=ck([e]),{shape:r,evolution:i}=H().applyComposedTransformWithHistory(e.wrapped,t.trsf,n,G),a=U(r);return lk(i,[e],a),a}function wk(e){return QE(()=>H().copyShape(e.wrapped),M.CLONE_FAILED,`Failed to clone shape`)}function Tk(e){return $E(()=>H().toBREP(e.wrapped),M.TO_BREP_FAILED,`Failed to serialize shape to BREP`)}function Ek(e){return H().hashCode(e.wrapped,G)}function Dk(e){return H().isNull(e.wrapped)}function Ok(e,t){return H().isSame(e.wrapped,t.wrapped)}function kk(e,t){return H().isEqual(e.wrapped,t.wrapped)}function Ak(e){return QE(()=>H().simplify(e.wrapped),M.SIMPLIFY_FAILED,`Failed to simplify shape`)}function jk(e){return H().curveType(e.wrapped)}function Mk(e){let[t]=H().curveParameters(e.wrapped);return H().curvePointAtParam(e.wrapped,t)}function Nk(e){let[,t]=H().curveParameters(e.wrapped);return H().curvePointAtParam(e.wrapped,t)}function Pk(e,t=.5){let[n,r]=H().curveParameters(e.wrapped),i=n+(r-n)*t;return H().curvePointAtParam(e.wrapped,i)}function Fk(e,t=.5){let[n,r]=H().curveParameters(e.wrapped),i=n+(r-n)*t;return H().curveTangent(e.wrapped,i).tangent}function Ik(e){return H().length(e.wrapped)}function Lk(e){if(jk(e)!==`CIRCLE`)return null;let t=Pk(e,0),n=Pk(e,1/3),r=Pk(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 Rk(e){return H().curveIsClosed(e.wrapped)}function zk(e){return H().curveIsPeriodic(e.wrapped)}function Bk(e){return H().curvePeriod(e.wrapped)}function Vk(e){return H().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function Hk(e){return U(H().reverseShape(e.wrapped))}function Uk(e,t={}){if(e.length<2)return k(Co(`INTERPOLATE_MIN_POINTS`,`Interpolation requires at least 2 points`));try{let n=U(H().interpolatePoints(e,t));return NE(n)?O(n):(W(n),k(Co(`INTERPOLATE_NOT_EDGE`,`Interpolation did not produce an edge`)))}catch(e){return k(Co(`INTERPOLATE_FAILED`,`Interpolation failed: ${e instanceof Error?e.message:String(e)}`))}}function Wk(e,t={}){if(e.length<2)return k(Co(`APPROXIMATE_MIN_POINTS`,`Approximation requires at least 2 points`));try{let n=U(H().approximatePoints(e,t));return NE(n)?O(n):(W(n),k(Co(`APPROXIMATE_NOT_EDGE`,`Approximation did not produce an edge`)))}catch(e){return k(Co(`APPROXIMATE_FAILED`,`Approximation failed: ${e instanceof Error?e.message:String(e)}`))}}function Gk(e,t,n=`arc`){let r=U(H().offsetWire2D(e.wrapped,t,{arc:`arc`,intersection:`intersection`,tangent:`tangent`,chamfer:`intersection`}[n]));return PE(r)?O(r):(W(r),k(Co(`OFFSET_NOT_WIRE`,`Offset did not produce a Wire`)))}function Kk(e,t,n,r=!1){return`${e}:${t}:${n}:${r}`}function qk(e,t){return`edge:${e}:${t}`}var Jk=new WeakMap,Yk=new WeakMap;function Xk(e,t){let n=Jk.get(e);if(n)return n.get(t)}function Zk(e,t,n){let r=Jk.get(e);r||(r=new Map,Jk.set(e,r)),r.set(t,n)}function Qk(e,t){let n=Yk.get(e);if(n)return n.get(t)}function $k(e,t,n){let r=Yk.get(e);r||(r=new Map,Yk.set(e,r)),r.set(t,n)}function eA(){Jk=new WeakMap,Yk=new WeakMap}function tA(){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 nA(e,t={}){let n=Po(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,skipNormals:a=!1,includeUVs:o=!1,cache:s=!0,signal:c}=t;c?.throwIfAborted();let l=Kk(r,i,a,o);if(s){let t=Xk(e.wrapped,l);if(t)return t}let u=H().mesh(e.wrapped,{tolerance:r,angularTolerance:i,skipNormals:a,includeUVs:o,...c?{signal:c}:{}}),d=MO(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 rA(e,t={}){let n=Po(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,cache:a=!0}=t,o=qk(r,i);if(a){let t=Qk(e.wrapped,o);if(t)return t}let s=H().meshEdges(e.wrapped,r,i),c={lines:s.lines,edgeGroups:s.edgeGroups.map(e=>({start:e.start,count:e.count,edgeId:e.edgeHash}))};return a&&$k(e.wrapped,o,c),c}function iA(e,t){return e instanceof Error&&e.message.startsWith(`${t} export failed`)?Do(`${t}_EXPORT_FAILED`,`Failed to write ${t} file`,e):e instanceof WebAssembly.RuntimeError?Do(`${t}_EXPORT_CRASHED`,`${t} export crashed the kernel (${e.message}); the shape likely contains geometry the ${t} writer cannot serialize`,e):Do(`${t}_FILE_READ_ERROR`,`Failed to read exported ${t} file`,e)}function aA(e){let t;try{t=mD(e)}catch{return``}if(t.length<=1)return``;let n=[];return t.forEach((e,t)=>{try{wD(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 oA(e,t){try{return wD(e),null}catch(n){if(n instanceof TypeError)throw n;return Do(`${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${aA(e)}`,n)}}function sA(e){let t=oA(e,`STEP`);if(t)return k(t);try{let t=H().exportSTEP([e.wrapped]);return O(new Blob([t],{type:`application/STEP`}))}catch(e){return k(iA(e,`STEP`))}}function cA(e,t={}){let n=Po(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,binary:a=!1}=t,o=oA(e,`STL`);if(o)return k(o);try{H().hasTriangulation(e.wrapped)||H().meshShape(e.wrapped,r,i);let t=H().exportSTL(e.wrapped,a,r,i);return O(new Blob([t],{type:`application/sla`}))}catch(e){return k(iA(e,`STL`))}}function lA(e){try{let t=H().exportIGES([e.wrapped]);return O(new Blob([t],{type:`application/iges`}))}catch(e){return k(Do(`IGES_EXPORT_FAILED`,`Failed to write IGES file`,e))}}function uA(e,t){let n=t?.coarseTolerance??.5,r=t?.fineTolerance??.05,i=t?.angularTolerance??.5;return{coarse:nA(e,{tolerance:n,angularTolerance:i}),fine:nA(e,{tolerance:r,angularTolerance:i*.2})}}function dA(e){let t=wD(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 fA(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)*dA(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 pA(e,t,n){return Math.min(e/t*n,1)}function mA(e,t={}){let n=t.angularTolerance??Po().angularTolerance,r=t.cache??!0,i=fA(e,t),a=Math.min(...i);return i.map(i=>{let o=pA(i,a,n);return{tolerance:i,angularTolerance:o,mesh:nA(e,{tolerance:i,angularTolerance:o,cache:r,...t.signal?{signal:t.signal}:{}})}})}function hA(){return new Promise(e=>{setTimeout(e,0)})}async function gA(e,t={}){let n=t.angularTolerance??Po().angularTolerance,r=t.cache??!0,i=t.meshLevel??((e,n,i)=>nA(e,{tolerance:n,angularTolerance:i,cache:r,...t.signal?{signal:t.signal}:{}})),a=fA(e,t),o=Math.min(...a),s=[];for(let[r,c]of a.entries()){if(t.signal?.aborted)break;let l=pA(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 hA()}return s}function _A(e,t,n){if(t<0||t>=e.length)throw Error(n??`Index ${t} out of bounds (length ${e.length})`);return e[t]}function vA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[0]}function yA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[e.length-1]}function bA(e){return Array.from(Array(e).keys())}function xA(e){return bA(Math.min(...e.map(e=>e.length))).map(t=>e.map(e=>e[t]))}function SA(e,t){return TE(H().makeLineEdge([...e],[...t]))}function CA(e,t=[0,0,0],n=[0,0,1]){return TE(H().makeCircleEdge([...t],[...n],e))}function wA(e,t,n=[0,0,0],r=[0,0,1],i){return t>e?k(P(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(TE(H().makeEllipseEdge([...n],[...r],e,t,i?[...i]:void 0)))}function TA(e,t,n,r=[0,0,0],i=[0,0,1],a=!1){return EE(H().makeHelixWire(e,t,n,[...r],[...i],a))}function EA(e,t,n){return TE(H().makeArcEdge([...e],[...t],[...n]))}function DA(e,t,n,r,i=[0,0,0],a=[0,0,1],o){return t>e?k(P(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(TE(H().makeEllipseArc([...i],[...a],e,t,n,r,o?[...o]:void 0)))}function OA(e,{tolerance:t=.001,smoothing:n=null,degMax:r=6,degMin:i=1}={}){try{let a=e.map(e=>[...e]);return O(TE(H().approximatePoints(a,{tolerance:t,degMin:i,degMax:r,smoothing:n})))}catch(e){return k(N(`BSPLINE_FAILED`,`B-spline approximation failed`,e))}}function kA(e,{periodic:t=!1,tolerance:n=1e-7}={}){try{let r=e.map(e=>[...e]);return O(TE(H().interpolatePoints(r,{periodic:t,tolerance:n})))}catch(e){return k(N(`BSPLINE_INTERP_FAILED`,`B-spline interpolation failed`,e))}}function AA(e){if(e.length<2)return k(P(`BEZIER_MIN_POINTS`,`Need at least 2 points for a Bezier curve, got ${e.length}`,void 0,{pointCount:e.length}));let t=e.map(e=>[...e]);return O(TE(H().makeBezierEdge(t)))}function jA(e,t,n){return TE(H().makeTangentArc([...e],[...t],[...n]))}function MA(e){try{return O(EE(H().makeWireFromMixed(e.map(e=>e.wrapped))))}catch(e){return k(N(`WIRE_BUILD_FAILED`,`Failed to build the wire: ${e instanceof Error?e.message:`unknown error`}`))}}function NA(e,t){try{let n=H().makeFace(e.wrapped,!0);if(t&&t.length>0){let e=LA(DE(n),t);return yE(e)?O(e):k(P(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}let r=DE(n);return yE(r)?O(r):k(P(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}catch(e){return k(N(`FACE_BUILD_FAILED`,`Failed to build the face. Your wire might be non planar.`,e))}}function PA(e){return NA(OO(e))}function FA(e,t){return DE(H().makeFaceOnSurface(e.wrapped,t.wrapped))}function IA(e){try{return Za(fO(H().makeNonPlanarFace(e.wrapped)),e=>FE(e)?O(e):k(N(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`)))}catch(e){return k(N(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`,e))}}function LA(e,t){return DE(H().addHolesInFace(e.wrapped,t.map(e=>e.wrapped)))}function RA(e){try{var t=IT();if(e.length<3)return k(P(`POLYGON_MIN_POINTS`,`You need at least 3 points to make a polygon`));let n=[...e.slice(1),e[0]],r=t.u(new XT);return Za(MA(xA([e,n]).map(([e,t])=>r.register(SA(e,t)))),e=>NA(r.register(e)))}catch(e){t.e=e}finally{t.d()}}function zA(e,t){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function BA(e,t,n,r,i){let a=VE(e);if(!zE(a)){let o=uE(a).toUpperCase();return UE(e,a),W(a),k(Co(t,`${n}. Got ${o} instead.`,void 0,i?{diagnostics:i}:void 0,r))}return UE(e,a),O(a)}function VA(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=zA(e,`fuse: first operand`);if(A(c))return c;let l=zA(t,`fuse: second operand`);if(A(l))return l;if(!s)return BA(H().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);let u=ck([e,t]),{shape:d,evolution:f,diagnostics:p}=H().fuseWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(H().isNull(d))return H().dispose(d),console.warn(`brepjs: fuse history path produced null result; retrying without evolution tracking.`,p),BA(H().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);console.warn(`brepjs: fuse reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=BA(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&&lk(f,[e,t],m.value),m}function HA(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;let c=zA(e,`cut: base`);if(A(c))return c;let l=zA(t,`cut: tool`);if(A(l))return l;if(!s)return BA(H().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);let u=ck([e,t]),{shape:d,evolution:f,diagnostics:p}=H().cutWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(H().isNull(d))return H().dispose(d),console.warn(`brepjs: cut history path produced null result; retrying without evolution tracking.`,p),BA(H().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);console.warn(`brepjs: cut reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=BA(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&&lk(f,[e,t],m.value),m}function UA(e,t,{simplify:n=!1,signal:r,fuzzyValue:i,unsafe:a,trackEvolution:o=!0}={}){if(r?.aborted)throw r.reason;let s=zA(e,`intersect: first operand`);if(A(s))return s;let c=zA(t,`intersect: second operand`);if(A(c))return c;if(!o)return BA(H().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);let l=ck([e,t]),{shape:u,evolution:d,diagnostics:f}=H().intersectWithHistory(e.wrapped,t.wrapped,l,G,{simplify:n,fuzzyValue:i});if(f.hasErrors){if(H().isNull(u))return H().dispose(u),console.warn(`brepjs: intersect history path produced null result; retrying without evolution tracking.`,f),BA(H().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);console.warn(`brepjs: intersect reported OCCT warnings/errors but produced a shape. Continuing with result.`,f)}let p=BA(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&&lk(d,[e,t],p.value),p}function WA(e,t,n,r,i,a,o,s,c){if(s?.aborted)throw s.reason;let l=n-t;if(l===1)return O({shape:_A(e,t),owned:!1});if(l===2){let n=VA(_A(e,t),_A(e,t+1),{optimisation:r,simplify:a?i:!1,trackEvolution:o,fuzzyValue:c,unsafe:!0,...s?{signal:s}:{}});return A(n)?n:O({shape:n.value,owned:!0})}let u=t+Math.ceil(l/2),d=WA(e,t,u,r,i,!1,o,s,c);if(A(d))return d;let f=WA(e,u,n,r,i,!1,o,s,c);if(A(f))return d.value.owned&&W(d.value.shape),f;let p=VA(d.value.shape,f.value.shape,{optimisation:r,simplify:i,trackEvolution:o,fuzzyValue:c,unsafe:!0,...s?{signal:s}:{}});return d.value.owned&&W(d.value.shape),f.value.owned&&W(f.value.shape),A(p)?p:O({shape:p.value,owned:!0})}function GA(e,{optimisation:t=`none`,simplify:n=!1,strategy:r=`native`,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;if(e.length===0)return k(P(`FUSE_ALL_EMPTY`,`fuseAll requires at least one shape`));if(e.length===1)return O(vA(e));for(let t=0;t<e.length;t++){let n=zA(_A(e,t),`fuseAll: shape at index ${t}`);if(A(n))return n}if(r===`native`){let o=BA(H().fuseAll(e.map(e=>e.wrapped),{optimisation:t,simplify:n,strategy:r,fuzzyValue:a,...i?{signal:i}:{}}),`FUSE_ALL_NOT_3D`,`fuseAll did not produce a 3D shape`);return o.ok&&s&&uk(e,o.value),o}let c=WA(e,0,e.length,t,n,!0,s,i,a);return A(c)?c:O(c.value.shape)}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;if(t.length===0)return O(e);let c=zA(e,`cutAll: base`);if(A(c))return c;for(let e=0;e<t.length;e++){let n=zA(_A(t,e),`cutAll: tool at index ${e}`);if(A(n))return n}let l=[e,...t],u=BA(H().cutAll(e.wrapped,t.map(e=>e.wrapped),{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_ALL_NOT_3D`,`cutAll did not produce a 3D shape`);return u.ok&&s&&uk(l,u.value),u}function qA(e,t,n){if(n!==void 0)return{size:n,center:t.origin};let{min:r,max:i}=H().boundingBox(e.wrapped),a=[(r[0]+i[0])/2,(r[1]+i[1])/2,(r[2]+i[2])/2],o=RD(FD(a,t.origin),t.zDir),s=FD(a,ID(t.zDir,o)),c=Math.hypot(i[0]-r[0],i[1]-r[1],i[2]-r[2]);return{size:Math.max(c,1),center:s}}function JA(e,t,n){let r=H(),i=ID(e.xDir,t),a=ID(e.yDir,t),o=ID(e.xDir,-t),s=ID(e.yDir,-t),c=n,l=[...PD(PD(c,o),s)],u=[...PD(PD(c,i),s)],d=[...PD(PD(c,i),a)],f=[...PD(PD(c,o),a)],p=[r.makeLineEdge(l,u),r.makeLineEdge(u,d),r.makeLineEdge(d,f),r.makeLineEdge(f,l)],m=r.makeWire(p),h=r.makeFace(m,!0);for(let e of p)r.dispose(e);return r.dispose(m),h}function YA(e,t,{approximation:n=!0,planeSize:r}={}){if(H().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`section: shape is a null shape`));let i=typeof t==`string`?j(eO(t)):t,{size:a,center:o}=qA(e,i,r),s=JA(i,a,o);try{return O(U(H().section(e.wrapped,s,n)))}catch(e){let n=e instanceof Error?e.message:String(e),r=typeof t==`string`?t:`custom`;return k(N(`SECTION_FAILED`,`Section with ${r} plane failed: ${n}`,e,{operation:`section`,plane:r},`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`))}finally{H().dispose(s)}}function XA(e){let t=H(),n=new Map,r=new Map;for(let i of e){let e=pD(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 ZA(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 QA(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=ZA(i,t,n);for(;o;)e===0?r.push(o.edge):r.unshift(o.edge),i=o.nextTip,o=ZA(i,t,n)}return r}function $A(e){let t=H(),n=XA(e),r=new Set,i=[];for(let a of e){if(r.has(a))continue;let e=QA(a,n,r);try{let n=t.makeWire(e.map(e=>e.wrapped));i.push(U(n))}catch{}}return i}function ej(e){let t=H(),n=0,r=-1;for(let i=0;i<e.length;i++){let a=e[i];if(!a)continue;let o=t.boundingBox(a.wrapped),s=o.max[0]-o.min[0],c=o.max[1]-o.min[1],l=o.max[2]-o.min[2],u=s*s+c*c+l*l;u>r&&(r=u,n=i)}return n}function tj(e,t,n={}){let r=YA(e,t,n);if(!r.ok)return r;let i=fD(r.value);if(i.length===0){let e=uD(r.value);if(e.length===0)return k(N(`SECTION_FAILED`,`sectionToFace: section produced no geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));i.push(...$A(e))}if(i.length===0)return k(N(`SECTION_FAILED`,`sectionToFace: section produced no usable geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));let a=ej(i),o=_A(i,a),s=i.filter((e,t)=>t!==a);return NA(o,s.length>0?s:void 0)}function nj(e,t){if(t.length===0)return O(e);if(H().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`split: shape is a null shape`));for(let e=0;e<t.length;e++)if(H().isNull(_A(t,e).wrapped))return k(P(M.NULL_SHAPE_INPUT,`splitShape: tool at index ${e} is a null shape`));try{return O(U(H().split(e.wrapped,t.map(e=>e.wrapped))))}catch(e){let n=e instanceof Error?e.message:String(e);return k(N(`SPLIT_FAILED`,`Split operation failed on ${t.length} tool(s): ${n}`,e,{operation:`split`,toolCount:t.length},`The splitting tools may not intersect the shape. Ensure tools cross through the shape's interior.`))}}function rj(e,t,n={}){let r=[];for(let i of t){let t=YA(e,i,n);if(A(t))return t;r.push(t.value)}return O(r)}function ij(e,t,n){if(t.length===0)return O(e);let r=n?.optimisation===`commonFace`?1:n?.optimisation===`sameFace`?2:0,i=H(),a=t.map(e=>({op:e.op,tool:e.tool.wrapped}));try{let o=i.booleanPipeline?.(e.wrapped,a,{glueMode:r});if(o===void 0)return aj(e,t,n);if(o===null)return k(N(`BOOLEAN_PIPELINE_FAILED`,`Boolean pipeline returned null shape`));let s=U(o);return zE(s)?O(s):(W(s),k(Co(`BOOLEAN_PIPELINE_NOT_3D`,`Pipeline result is not a 3D shape`)))}catch(e){return k(N(`BOOLEAN_PIPELINE_FAILED`,e instanceof Error?e.message:String(e)))}}function aj(e,t,n){let r=e,i={...n?.optimisation?{optimisation:n.optimisation}:{},unsafe:!0};for(let e of t){let t=e.op===`fuse`?VA(r,e.tool,i):e.op===`cut`?HA(r,e.tool,i):UA(r,e.tool,i);if(A(t))return t;r=j(t)}return O(r)}function oj(e){return U(H().sew(e.map(e=>e.wrapped)))}function sj(e,t=!1){let n=oj(e);return!t&&!IE(n)?k(Co(`WELD_NOT_SHELL`,`Could not make a shell from faces and shells`)):O(n)}function cj(e,t,n=[0,0,0],r=[0,0,1]){return kE(H().makeCylinder(e,t,[...n],[...r]))}function lj(e){return kE(H().makeSphere(e))}function uj(e,t,n,r=[0,0,0],i=[0,0,1]){return kE(H().makeCone(e,t,n,[...r],[...i]))}function dj(e,t,n=[0,0,0],r=[0,0,1]){return kE(H().makeTorus(e,t,[...n],[...r]))}function fj(e,t,n){return kE(H().makeEllipsoid(e,t,n))}function pj(e){return wE(H().makeVertex(e[0],e[1],e[2]))}function mj(e,t,n=1e-6){return Za(uO(H().offset(e.wrapped,t,n)),e=>Za(fO(e),e=>zE(e)?O(e):k(Co(`OFFSET_NOT_3D`,`Could not offset to a 3d shape`))))}function hj(e){return jE(H().makeCompound(e.map(e=>e.wrapped)))}function gj(e){try{var t=IT();let n=t.u(oj(e)),r=U(H().solidFromShell(n.wrapped));return LE(r)?O(r):(W(r),k(Co(`SOLID_BUILD_FAILED`,`Could not make a solid of faces and shells`)))}catch(e){t.e=e}finally{t.d()}}function _j(e){return{position:e.vertices,normal:e.normals,index:e.triangles}}function vj(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 yj(e){return{position:e.lines}}function bj(e,t){return{coarse:_j(e.coarse),fine:_j(e.fine),coarseDistance:t?.coarse??50,fineDistance:t?.fine??0}}function xj(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:_j(e.mesh),distance:r?.[t]??(i-t)*n}))}function Sj(e,t,n,r){if(t.length===0)return k(P(`CHAMFER_ANGLE_NO_EDGES`,`chamferDistAngle requires at least one edge`,void 0,{edgeCount:0}));if(n<=0)return k(P(`CHAMFER_ANGLE_BAD_DISTANCE`,`distance must be positive, got ${n}`,void 0,{distance:n}));if(r<=0||r>=90)return k(P(`CHAMFER_ANGLE_BAD_ANGLE`,`angleDeg must be in range (0, 90), got ${r}`,void 0,{angleDeg:r}));let i;try{let a=H(),o=t.map(e=>e.wrapped);i=a.chamferDistAngle(e.wrapped,o,n,r)}catch(e){return k(N(`CHAMFER_ANGLE_FAILED`,`chamferDistAngle kernel call failed: ${e instanceof Error?e.message:String(e)}`,e,{distance:n,angleDeg:r,edgeCount:t.length}))}let a=uO(i);if(A(a))return H().dispose(i),a;let o=U(a.value);return UE(i,o),zE(o)?O(o):(W(o),k(Co(`CHAMFER_ANGLE_NOT_3D`,`chamferDistAngle did not produce a 3D shape`)))}function Cj(e){let t=H();return t.getNurbsCurveData?t.getNurbsCurveData(e.wrapped):null}function wj(e){let t=H();return t.getNurbsSurfaceData?t.getNurbsSurfaceData(e.wrapped):null}var Tj={cut:HA,cutAll:KA,fuse:VA,fuseAll:GA};function Ej(e){return{totalInputs:e.totalInputs,batchAttempts:e.batchAttempts,batchSucceeded:e.batchSucceeded,singletonFallbacks:e.singletonFallbacks,failedInputs:[...e.failedInputs].sort((e,t)=>e-t)}}function Dj(e,t,n={}){return Oj(Tj,e,t,n)}function Oj(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=kj(e,t,n,0,r,i);return A(a)?a:O({shape:a.value,telemetry:Ej(i)})}function kj(e,t,n,r,i,a){if(n.length===0)return O(t);if(n.length===1)return Aj(e,t,n,r,i,a);a.batchAttempts++;let o=Fj(()=>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=kj(e,t,n.slice(0,s),r,i,a);return c.ok?kj(e,c.value,n.slice(s),r+s,i,a):c}function Aj(e,t,n,r,i,a){a.singletonFallbacks++;let o=vA(n),s=Fj(()=>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 jj(e,t={}){return Mj(Tj,e,t)}function Mj(e,t,n={}){if(n.signal?.aborted)throw n.signal.reason;if(t.length===0)return k(P(M.FUSE_ALL_EMPTY,`fuseAllBisect requires at least one shape`));let r={totalInputs:t.length,batchAttempts:0,batchSucceeded:0,singletonFallbacks:0,failedInputs:new Set},i=Nj(e,t,0,n,r);return A(i)?i:O({shape:i.value,telemetry:Ej(r)})}function Nj(e,t,n,r,i){if(t.length===1)return O(vA(t));i.batchAttempts++;let a=Fj(()=>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 Pj(e,Nj(e,t.slice(0,o),n,r,i),Nj(e,t.slice(o),n+o,r,i),t,n,o,r,i)}function Pj(e,t,n,r,i,a,o,s){if(t.ok&&n.ok){s.singletonFallbacks++;let c=Fj(()=>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 Fj(e){try{return e()}catch{return null}}function Ij(e,t,n){return H().checkBoolean(e.wrapped,t.wrapped,n)}function Lj(e,t){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Rj(e,t){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function zj(e,t,n,r){let i=VE(e);if(!zE(i)){let a=uE(i).toUpperCase();return UE(e,i),W(i),k(Co(t,`${n}. Got ${a} instead.`,void 0,void 0,r))}return UE(e,i),O(i)}function Bj(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(H().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>r.get(H().hashCode(e,2147483647))??1}}function Vj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Lj(e,`fuseWithEvolution: first operand`);if(A(o))return o;let s=Lj(t,`fuseWithEvolution: second operand`);if(A(s))return s;let c=ck([e,t]),{shape:l,evolution:u}=H().fuseWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=zj(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?(lk(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function Hj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Lj(e,`cutWithEvolution: base`);if(A(o))return o;let s=Lj(t,`cutWithEvolution: tool`);if(A(s))return s;let c=ck([e,t]),{shape:l,evolution:u}=H().cutWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=zj(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?(lk(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function Uj(e,t,{simplify:n=!1,signal:r,fuzzyValue:i}={}){if(r?.aborted)throw r.reason;let a=Lj(e,`intersectWithEvolution: first operand`);if(A(a))return a;let o=Lj(t,`intersectWithEvolution: second operand`);if(A(o))return o;let s=ck([e,t]),{shape:c,evolution:l}=H().intersectWithHistory(e.wrapped,t.wrapped,s,G,{simplify:n,fuzzyValue:i}),u=zj(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?(lk(l,[e,t],u.value),O({shape:u.value,evolution:l})):u}function Wj(e,t,n){let r=Rj(e,`filletWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(P(`INVALID_FILLET_RADIUS`,`Fillet radius must be positive`,void 0,void 0,`Provide a positive radius value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(P(`INVALID_FILLET_RADIUS`,`Fillet radii must both be positive`,void 0,void 0,`Both radius values must be greater than 0`));let i=t??uD(e);if(i.length===0)return k(P(M.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));try{let t,r;if(typeof n==`function`){let e=Bj(i,n);if(!e)return k(P(M.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=ck([e]),{shape:o,evolution:s}=H().filletWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=U(o);return zE(c)?(lk(s,[e],c),O({shape:c,evolution:s})):(W(c),k(N(M.FILLET_NOT_3D,`Fillet result is not a 3D shape`)))}catch(e){return k(N(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:i.length,radius:n}))}}function Gj(e,t,n){let r=Rj(e,`chamferWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(P(`INVALID_CHAMFER_DISTANCE`,`Chamfer distance must be positive`,void 0,void 0,`Provide a positive distance value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(P(`INVALID_CHAMFER_DISTANCE`,`Chamfer distances must both be positive`,void 0,void 0,`Both distance values must be greater than 0`));let i=t??uD(e);if(i.length===0)return k(P(M.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=Bj(i,n);if(!e)return k(P(M.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=ck([e]),{shape:o,evolution:s}=H().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=U(o);return zE(c)?(lk(s,[e],c),O({shape:c,evolution:s})):(W(c),k(N(M.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)))}catch(e){return k(N(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:i.length,distance:n}))}}function Kj(e,t,n,r=.001){let i=Rj(e,`shellWithEvolution: shape`);if(A(i))return i;if(n<=0)return k(P(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(P(`NO_FACES`,`At least one face must be specified for shell`));try{let i=ck([e]),{shape:a,evolution:o}=H().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,i,G,r),s=U(a);return zE(s)?(lk(o,[e],s),O({shape:s,evolution:o})):(W(s),k(N(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}catch(e){return k(N(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function qj(e,t,n){try{let r=U(H().positionOnCurve(e.wrapped,t.wrapped,n));return zE(r)?O(r):(W(r),k(N(M.POSITION_ON_CURVE_FAILED,`positionOnCurve did not produce a 3D shape`)))}catch(e){return k(N(M.POSITION_ON_CURVE_FAILED,`Failed to position shape on curve at param ${n}`,e))}}function Jj(e,t){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Yj(e,t){if(typeof e==`number`&&e<=0)return k(P(t.code,t.scalar,void 0,void 0,t.scalarHint));if(Array.isArray(e)&&(e[0]<=0||e[1]<=0))return k(P(t.code,t.pair,void 0,void 0,t.pairHint))}function Xj(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(H().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>{let t=r.get(H().hashCode(e,G));if(t===void 0)throw Error(`fillet/chamfer: edge hash not found — possible hash collision`);return t}}}function Zj(e,t,n,r,i){let a=U(t);return zE(a)?(lk(e,n,a),O(a)):(W(a),k(N(r,i)))}function Qj(e,t){if(typeof t!=`function`)return{filteredFaces:[...e],kernelAngle:t};let n=[],r=new Map;for(let i of e){let e=t(i);e===null||e===0||Math.abs(e)>=90||(n.push(i),r.set(H().hashCode(i.wrapped,G),e))}return{filteredFaces:n,kernelAngle:e=>{let t=r.get(H().hashCode(e,G));if(t===void 0)throw Error(`draft: face hash not found — possible hash collision`);return t}}}function $j(e,t){let n=Jj(e,`thicken: shape`);if(A(n))return n;try{let n=ck([e]),{shape:r,evolution:i}=H().thickenWithHistory(e.wrapped,t,n,G),a=U(r);return lk(i,[e],a),O(a)}catch(e){return k(N(`THICKEN_FAILED`,`Thicken operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function eM(e,t,n){let r=Jj(e,`fillet: shape`);if(A(r))return r;let i=Yj(n,{code:`INVALID_FILLET_RADIUS`,scalar:`Fillet radius must be positive`,pair:`Fillet radii must both be positive`,scalarHint:`Provide a positive radius value greater than 0`,pairHint:`Both radius values must be greater than 0`});if(i)return i;let a=t??uD(e);if(a.length===0)return k(P(M.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));if(typeof n==`function`){let e=Xj(a,n);return e?O({filteredEdges:e.edges,kernelRadius:e.kernelParam,selectedCount:a.length}):k(P(M.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`))}return O({filteredEdges:[...a],kernelRadius:n,selectedCount:a.length})}function tM(e,t,n,{trackEvolution:r=!0}={}){let i=eM(e,t,n);if(A(i))return i;let{filteredEdges:a,kernelRadius:o,selectedCount:s}=i.value;try{let t=a.map(e=>e.wrapped);if(!r){let n=U(H().fillet(e.wrapped,t,o));return zE(n)?O(n):(W(n),k(N(M.FILLET_NOT_3D,`Fillet result is not a 3D shape`)))}let n=ck([e]),{shape:i,evolution:s}=H().filletWithHistory(e.wrapped,t,o,n,G);return Zj(s,i,[e],M.FILLET_NOT_3D,`Fillet result is not a 3D shape`)}catch(e){return k(N(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:s,radius:n}))}}function nM(e,t,n){let r=Jj(e,`chamfer: shape`);if(A(r))return r;let i=Yj(n,{code:`INVALID_CHAMFER_DISTANCE`,scalar:`Chamfer distance must be positive`,pair:`Chamfer distances must both be positive`,scalarHint:`Provide a positive distance value greater than 0`,pairHint:`Both distance values must be greater than 0`});if(i)return i;let a=t??uD(e);if(a.length===0)return k(P(M.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=Xj(a,n);if(!e)return k(P(M.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...a],r=n;let i=ck([e]),{shape:o,evolution:s}=H().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,i,G);return Zj(s,o,[e],M.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)}catch(e){return k(N(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:a.length,distance:n}))}}function rM(e,t,n,r=.001,{trackEvolution:i=!0}={}){let a=Jj(e,`shell: shape`);if(A(a))return a;if(n<=0)return k(P(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(P(`NO_FACES`,`At least one face must be specified for shell`));try{if(!i){let i=U(H().shell(e.wrapped,t.map(e=>e.wrapped),n,r));return zE(i)?O(i):(W(i),k(N(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}let a=ck([e]),{shape:o,evolution:s}=H().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,a,G,r),c=U(o);return zE(c)?(lk(s,[e],c),O(c)):(W(c),k(N(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}catch(e){return k(N(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function iM(e,t,n=1e-6){let r=Jj(e,`offset: shape`);if(A(r))return r;if(Math.abs(t)<1e-10)return k(P(`ZERO_OFFSET`,`Offset distance cannot be zero`));try{let r=ck([e]),{shape:i,evolution:a}=H().offsetWithHistory(e.wrapped,t,r,G,n),o=U(i);return zE(o)?(lk(a,[e],o),O(o)):(W(o),k(N(`OFFSET_RESULT_NOT_3D`,`Offset result is not a 3D shape`)))}catch(e){return k(N(`OFFSET_FAILED`,`Offset operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function aM(e,t,n){let r=Jj(e,`draft: shape`);if(A(r))return r;if(typeof n==`number`){if(Math.abs(n)<1e-10)return k(P(M.DRAFT_INVALID_ANGLE,`Draft angle cannot be zero`,void 0,void 0,`Provide a non-zero angle in degrees`));if(Math.abs(n)>=90)return k(P(M.DRAFT_INVALID_ANGLE,`Draft angle must be between -90 and 90 degrees (exclusive)`,void 0,void 0,`Typical draft angles are 1-5 degrees for injection molding`))}if(t.length===0)return k(P(M.DRAFT_NO_FACES,`No faces specified for draft`,void 0,void 0,`Select at least one face to apply the draft angle to`))}function oM(e,t,n,r,i){let a=aM(e,t,i);if(a)return a;try{let{filteredFaces:a,kernelAngle:o}=Qj(t,i);if(a.length===0)return k(P(M.DRAFT_NO_FACES,`No faces with valid draft angle`,void 0,void 0,`Check that the angle callback returns non-zero values between -90 and 90 degrees`));let s=ck([e]),{shape:c,evolution:l}=H().draftWithHistory(e.wrapped,a.map(e=>e.wrapped),[n[0],n[1],n[2]],[r[0],r[1],r[2]],o,s,G);return Zj(l,c,[e],M.DRAFT_NOT_3D,`Draft result is not a 3D shape`)}catch(e){let n=e instanceof Error?e.message:String(e);return k(N(M.DRAFT_FAILED,`Draft operation failed: ${n}`,e,{operation:`draft`,faceCount:t.length,angle:i}))}}function sM(e,t,n){if(n.length===0)return k(P(M.VARIABLE_FILLET_FAILED,`radii must contain at least one radius spec`));for(let e of n)if(e.radius<=0)return k(P(M.VARIABLE_FILLET_FAILED,`All radius values must be positive`));let r=H();try{let i=JSON.stringify({edge:r.hashCode(t.wrapped,G),radii:n.map(e=>({param:e.param,radius:e.radius}))}),a=U(r.filletVariable(e.wrapped,i));return zE(a)?LE(a)?O(a):(W(a),k(N(M.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a solid`))):(W(a),k(N(M.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a 3D shape`)))}catch(e){return k(N(M.VARIABLE_FILLET_FAILED,`Variable-radius fillet failed`,e))}}function cM(e){return DD(e)}function lM(e){if(!LE(e))return k(P(`NOT_A_SOLID`,`Input shape is not a solid`));let t=cM(e);try{let n=H().healSolid(e.wrapped);if(!n)return t?O(e):k(N(M.HEAL_NO_EFFECT,`Solid healing had no effect — shape is still invalid`));let r=U(n);return LE(r)?(lD(r),cM(r)?O(r):(W(r),k(N(`HEAL_SOLID_INCOMPLETE`,`Healed result is still invalid after ShapeFix_Solid`)))):(W(r),k(N(`HEAL_RESULT_NOT_SOLID`,`Healed result is not a solid`)))}catch(e){return k(N(`HEAL_SOLID_FAILED`,`Solid healing failed`,e))}}function uM(e){if(!FE(e))return k(P(`NOT_A_FACE`,`Input shape is not a face`));try{let t=U(H().healFace(e.wrapped));return FE(t)?O(t):(W(t),k(N(`HEAL_RESULT_NOT_FACE`,`Healed result is not a face`)))}catch(e){return k(N(`HEAL_FACE_FAILED`,`Face healing failed`,e))}}function dM(e,t){if(!PE(e))return k(P(`NOT_A_WIRE`,`Input shape is not a wire`));try{let n=U(H().healWire(e.wrapped,t?.wrapped));return PE(n)?O(n):(W(n),k(N(`HEAL_RESULT_NOT_WIRE`,`Healed result is not a wire`)))}catch(e){return k(N(`HEAL_WIRE_FAILED`,`Wire healing failed`,e))}}function fM(e){return LE(e)?lM(e):FE(e)?uM(e):PE(e)?dM(e):O(e)}function pM(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(cM(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=fD(e).length,u=dD(e).length,d=e,f=!1,p=t=>{let n=d;d=t,n!==e&&n.wrapped!==t.wrapped&&W(n)};if(o!==void 0)try{p(U(H().sew([d.wrapped],o))),s.push(`Applied sewing with tolerance ${o}`),c.push({name:`sew`,attempted:!0,succeeded:!0,detail:`tolerance=${o}`})}catch(e){let t=e instanceof Error?e.message:String(e);s.push(`Sewing failed: ${t}`),c.push({name:`sew`,attempted:!0,succeeded:!1,detail:t})}if(a&&n){let e=fD(d),t=0;for(let n of e)try{H().fixSelfIntersection(n.wrapped),t++}catch{}s.push(`Self-intersection fix: ${t}/${e.length} wires`),c.push({name:`fixSelfIntersection`,attempted:!0,succeeded:t>0,detail:`${t}/${e.length} wires fixed`})}if(LE(d)&&i||FE(d)&&r||PE(d)&&n){let t=fM(d);Ja(t)?(p(t.value),LE(e)?(f=!0,s.push(`Applied ShapeFix_Solid`),c.push({name:`healSolid`,attempted:!0,succeeded:!0})):FE(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=fD(d).length,h=dD(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=cM(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 mM(e){try{return O(U(H().fixShape(e.wrapped)))}catch(e){return k(N(M.FIX_SHAPE_FAILED,`ShapeFix_Shape failed`,e))}}function hM(e){try{let t=U(H().solidFromShell(e.wrapped));return LE(t)?cM(t)?O(t):(W(t),k(N(M.SOLID_FROM_SHELL_FAILED,`solidFromShell produced an invalid solid`))):(W(t),k(N(M.SOLID_FROM_SHELL_FAILED,`solidFromShell did not produce a solid`)))}catch(e){return k(N(M.SOLID_FROM_SHELL_FAILED,`Failed to create solid from shell`,e))}}function gM(e){try{let t=U(H().fixSelfIntersection(e.wrapped));return PE(t)?O(t):(W(t),k(N(M.FIX_SELF_INTERSECTION_FAILED,`Result is not a wire`)))}catch(e){return k(N(M.FIX_SELF_INTERSECTION_FAILED,`Failed to fix wire self-intersection`,e))}}function _M(e,{profile:t,endFactor:n=1}){return e<1e-10?k(P(`INVALID_EXTRUSION_LENGTH`,`Extrusion length too small (< 1e-10)`)):t!==`s-curve`&&t!==`linear`?k(P(`UNSUPPORTED_PROFILE`,`Unsupported extrusion profile: ${String(t)}`)):O(H().buildExtrusionLaw(t,e,n).Trim(0,e,1e-6))}function vM(e,t){let n=H(),r=n.makeLineEdge([...e],[...t]),i=n.makeWire([r]);return n.dispose(r),U(i)}function yM(e,t,n,r,i,a=!1){return U(H().makeHelixWire(e,t,n,[...r],[...i],a))}function bM(e){let t=U(e.shape),n=U(e.firstShape),r=U(e.lastShape),i=()=>{W(t),W(n),W(r)};return zE(t)?PE(n)?PE(r)?O([t,n,r]):(i(),k(Co(`SWEEP_END_NOT_WIRE`,`Sweep did not produce an end Wire`))):(i(),k(Co(`SWEEP_START_NOT_WIRE`,`Sweep did not produce a start Wire`))):(i(),k(Co(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function xM(e,t,n={},r=!1){if(n.mode===`simple`&&!r){let n=U(H().simplePipe(e.wrapped,t.wrapped));return zE(n)?O(n):(W(n),k(Co(`SWEEP_NOT_3D`,`Simple pipe did not produce a 3D shape`)))}let{frenet:i=!1,auxiliarySpine:a,law:o=null,transitionMode:s=`right`,withContact:c,support:l,forceProfileSpineOthogonality:u,tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h}=n,g=H(),_=s===`round`?!0:!!u,v=g.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:s,contact:!!c,correction:_,frenet:i,shellMode:r,...a?.wrapped?{auxiliary:a.wrapped}:{},...o===null?{}:{law:o},...l===null?{}:{support:l},tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h});if(r&&typeof v==`object`&&`firstShape`in v)return bM(v);let y=U(v);return zE(y)?O(y):(W(y),k(Co(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function SM(e,t,n,r){return xM(e,vM(t,PD(t,n)),{support:r})}function CM(e,t,n,r,i=!1){try{var a=IT();let o=BD(n);if(o<1e-10)return k(P(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let s=PD(t,n),c=a.u(vM(t,s)),l=null;if(r){let e=_M(o,r);if(A(e))return e;l=e.value}return xM(e,c,{law:l},i)}catch(e){a.e=e}finally{a.d()}}function wM(e,t,n,r,i,a=!1){try{var o=IT();if(Math.abs(t)<1e-10)return k(P(`ZERO_TWIST_ANGLE`,`Twist angle cannot be zero`));let s=BD(r);if(s<1e-10)return k(P(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let c=PD(n,r),l=o.u(vM(n,c)),u=t<0,d=360/Math.abs(t)*s,f=o.u(yM(d,s,1,n,r,u)),p=null;if(i){let e=_M(s,i);if(A(e))return e;p=e.value}return xM(e,l,{auxiliarySpine:f,law:p},a)}catch(e){o.e=e}finally{o.d()}}function TM(e){let t=e.map(e=>e.location);for(let e=0;e<t.length;e++){let n=t[e];if(n!==void 0&&(n<0||n>1))return P(M.MULTI_SWEEP_FAILED,`Section ${e} location ${n} is out of range [0, 1]`)}let n=t.filter(e=>e!==void 0);for(let e=1;e<n.length;e++)if((n[e]??0)<=(n[e-1]??0))return P(M.MULTI_SWEEP_FAILED,`Section locations must be strictly increasing`)}function EM(e,t,n){let[r,i]=n.curveParameters(t.wrapped),a=i-r,o=Array(e.length);for(let t=0;t<e.length;t++){let n=e[t]?.location;o[t]=n===void 0?NaN:r+n*a}let s=-1,c=r;for(let t=0;t<=e.length;t++){let n=t===e.length;if(!n&&!Number.isNaN(o[t]??NaN)||n){let e=n?i:o[t]??i,a=t-s-1;for(let t=1;t<=a;t++)o[s+t]=c+t/(a+1)*(e-c);n||(s=t,c=o[t]??r)}}for(let e=1;e<o.length;e++)if((o[e]??0)<=(o[e-1]??0))return k(P(M.MULTI_SWEEP_FAILED,`Computed section parameters are not strictly increasing at index ${e} (${o[e-1]?.toFixed(4)} >= ${o[e]?.toFixed(4)})`));return O(o)}function DM(e,t,n){if(e.length<2)return k(P(M.MULTI_SWEEP_INSUFFICIENT_SECTIONS,`Multi-section sweep requires at least 2 sections, got ${e.length}`));let{solid:r=!0,ruled:i=!1,tolerance:a=1e-6}=n??{},o=TM(e);if(o)return k(o);try{let n=H(),o=EM(e,t,n);if(A(o))return o;let s=o.value,c=[],l=[];try{for(let r=0;r<e.length;r++){let i=s[r],a=e[r];if(i===void 0||a===void 0)continue;let o=n.positionOnCurve(a.wire.wrapped,t.wrapped,i);c.push(o),l.push(n.downcast(o,`wire`))}let o=U(n.loftAdvanced(l,{solid:r,ruled:i,tolerance:a}));return zE(o)?O(o):(W(o),k(Co(`MULTI_SWEEP_NOT_3D`,`Multi-section sweep did not produce a 3D shape`)))}finally{for(let e of l)n.dispose(e);for(let e of c)n.dispose(e)}}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.MULTI_SWEEP_FAILED,`Multi-section sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function OM(e,t,n,r={}){let{transition:i=`transformed`,solid:a=!0,tolerance:o}=r;try{let r=H(),s=!a,c=n.length>0?n[0]?.wrapped:void 0,l=r.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:i,...c?{auxiliary:c}:{},shellMode:s,...o===void 0?{}:{tolerance:o,boundTolerance:o}}),u=U(typeof l==`object`&&`shape`in l?l.shape:l);return zE(u)?O(u):(W(u),k(Co(`GUIDED_SWEEP_NOT_3D`,`Guided sweep did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.GUIDED_SWEEP_FAILED,`Guided sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function kM(e,t){if(H().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`extrude: face is a null shape`));if(BD(t)<1e-10)return k(P(`EXTRUDE_ZERO_VECTOR`,`extrude: extrusion vector has zero length`));try{let n=H(),r=BD(t),i=UD(t),a=n.extrude(e.wrapped,[...i],r),o=kE(n.downcast(a,`solid`));return UE(a,o),O(o)}catch(e){return k(N(`EXTRUDE_FAILED`,`Extrusion operation failed`,e,{operation:`extrude`,vectorLength:BD(t)}))}}function AM(e,t=[0,0,0],n=[0,0,1],r=2*Math.PI){if(H().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`revolve: face is a null shape`));try{let i=U(H().revolveVec(e.wrapped,[...t],[...n],r));return zE(i)?O(i):(W(i),k(Co(`REVOLUTION_NOT_3D`,`Revolution did not produce a 3D shape`)))}catch(e){return k(N(`REVOLVE_FAILED`,`Revolution operation failed`,e,{operation:`revolve`,angle:r}))}}function jM(e){if(e.length===0)return O([]);let t=H(),n=[];for(let t=0;t<e.length;t++){let r=e[t];if(!r)continue;let i=typeof r.height==`number`?[0,0,r.height]:r.height,a=BD(i);if(a<1e-10)return k(P(`EXTRUDE_ALL_ZERO_VECTOR`,`extrudeAll: entry ${t} has zero-length extrusion vector`));let o=[...UD(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=kE(t.downcast(e,`solid`));return UE(e,n),n}))}catch(e){return k(N(`EXTRUDE_ALL_FAILED`,`Batch extrusion operation failed`,e))}}function MM(e,{ruled:t=!0,startPoint:n,endPoint:r,tolerance:i=1e-6}={},a=!1){if(e.length===0&&!n&&!r)return k(P(`LOFT_EMPTY`,`Loft requires at least one wire or start/end point`));let o=H(),s=n?o.makeVertex(...AD(n)):void 0,c=r?o.makeVertex(...AD(r)):void 0;try{let n=U(o.loftAdvanced(e.map(e=>e.wrapped),{solid:!a,ruled:t,tolerance:i,...s?{startVertex:s}:{},...c?{endVertex:c}:{}}));return zE(n)?O(n):(W(n),k(Co(`LOFT_NOT_3D`,`Loft did not produce a 3D shape`)))}catch(e){return k(N(`LOFT_FAILED`,`Loft operation failed`,e,void 0,`Common causes: wire profiles with different edge counts, self-intersecting result, or profiles too far apart. Ensure profiles are compatible and ordered.`))}}function NM(e){if(e.length===0)return O([]);let t=H(),n=[],r=e.map(e=>{let r=e.startPoint?t.makeVertex(...AD(e.startPoint)):void 0,i=e.endPoint?t.makeVertex(...AD(e.endPoint)):void 0;return r&&n.push(r),i&&n.push(i),{wires:e.wires.map(e=>e.wrapped),solid:!0,ruled:e.ruled??!0,tolerance:e.tolerance??1e-6,startVertex:r,endVertex:i}});try{let e=t.loftBatch?.(r)??r.map(e=>t.loftAdvanced(e.wires,{solid:e.solid,ruled:e.ruled,tolerance:e.tolerance,startVertex:e.startVertex,endVertex:e.endVertex})),n=[];for(let t of e){let e=U(t);if(!zE(e))return W(e),k(Co(`LOFT_ALL_NOT_3D`,`Batch loft entry did not produce a 3D shape`));n.push(e)}return O(n)}catch(e){return k(N(`LOFT_ALL_FAILED`,`Batch loft operation failed`,e))}finally{for(let e of n)t.dispose(e)}}var PM=new WeakMap;function FM(e,t){return PM.get(e)?.get(t)}function IM(e,t,n){let r=PM.get(e);r||(r=new Map,PM.set(e,r)),r.set(t,n)}function LM(e){return H().isNull(e.wrapped)}function RM(e){return k(P(M.NULL_SHAPE_INPUT,`${e}: shape is a null shape`))}function zM(e){let t=FM(e.wrapped,`volume`);if(t)return O(t);if(LM(e))return RM(`measureVolumeProps`);let n=H(),r=n.shapeType(e.wrapped);if(r!==`solid`&&r!==`compsolid`&&r!==`compound`){let t={mass:0,volume:0,centerOfMass:[0,0,0]};return IM(e.wrapped,`volume`,t),O(t)}let i=n.volume(e.wrapped),a=$E(()=>n.centerOfMass(e.wrapped),M.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!a.ok)return a;let o={mass:i,volume:i,centerOfMass:a.value};return IM(e.wrapped,`volume`,o),O(o)}function BM(e){let t=FM(e.wrapped,`surface`);if(t)return O(t);if(LM(e))return RM(`measureSurfaceProps`);let n=H(),r=n.area(e.wrapped),i=$E(()=>n.centerOfMass(e.wrapped),M.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!i.ok)return i;let a={mass:r,area:r,centerOfMass:i.value};return IM(e.wrapped,`surface`,a),O(a)}function VM(e){let t=FM(e.wrapped,`linear`);if(t)return O(t);if(LM(e))return RM(`measureLinearProps`);let n=H(),r=n.length(e.wrapped),i={mass:r,length:r,centerOfMass:n.linearCenterOfMass(e.wrapped)};return IM(e.wrapped,`linear`,i),O(i)}function HM(e){let t=zM(e);return t.ok?O(t.value.mass):t}function UM(e){let t=BM(e);return t.ok?O(t.value.mass):t}function WM(e){let t=VM(e);return t.ok?O(t.value.mass):t}function GM(e,t){return LM(e)||LM(t)?RM(`measureDistance`):O(H().distance(e.wrapped,t.wrapped).value)}function KM(e,t){if(LM(e)||LM(t))return RM(`measureDistanceProps`);let n=H().distance(e.wrapped,t.wrapped);return O({distance:n.value,point1:n.point1,point2:n.point2})}function qM(e){if(LM(e))return RM(`createDistanceQuery`);let t=H().createDistanceQuery(e.wrapped);return O({distanceTo(e){return LM(e)?RM(`createDistanceQuery.distanceTo`):O(t.distanceTo(e.wrapped).value)},dispose(){t.dispose()}})}function JM(e,t,n){if(LM(e))return RM(`measureCurvatureAt`);let r=H().surfaceCurvature(e.wrapped,t,n);return O({mean:r.mean,gaussian:r.gaussian,maxCurvature:r.max,minCurvature:r.min,maxDirection:r.maxDirection,minDirection:r.minDirection})}function YM(e){if(LM(e))return RM(`measureCurvatureAtMid`);let t=bO(e),n=(t.uMin+t.uMax)/2,r=(t.vMin+t.vMax)/2,i=H().surfaceCurvature(e.wrapped,n,r);return O({mean:i.mean,gaussian:i.gaussian,maxCurvature:i.max,minCurvature:i.min,maxDirection:i.maxDirection,minDirection:i.minDirection})}function XM(e,t){return e.map(e=>qE(e,t))}function ZM(e,t){let n=H(),r=n.iterShapes(e,t),i=[],a=new Map;for(let e of r){let r=n.hashCode(e,G),o=a.get(r);if(o?.some(t=>n.isSame(t,e))){n.dispose(e);continue}let s=KE(e,t);i.push(s),o?o.push(s.wrapped):a.set(r,[s.wrapped])}return i}function QM(e){let t=H(),n=new Map;for(let r of e){let e=t.hashCode(r.wrapped,G),i=n.get(e);i?i.push(r):n.set(e,[r])}return n}function $M(e,t,n){let r=H();return e.get(n)?.find(e=>r.isSame(e.wrapped,t))}function eN(e){let t=sD(e);if(t.edgeToFaces)return t.edgeToFaces;let n=H(),r=dD(e),i=QM(uD(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=$M(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 tN(e){let t=sD(e);if(t.vertexToFaces)return t.vertexToFaces;let n=H(),r=dD(e),i=QM(pD(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=$M(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 nN(e,t){let n=H(),r=eN(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 XM(o,`face`)}function rN(e,t){let n=H(),r=tN(e),i=n.hashCode(t.wrapped,G),a=r.get(i)??[],o=[],s=new Map;for(let e of a){if(!n.isSame(e.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 XM(o,`face`)}function iN(e){return ZM(e.wrapped,`edge`)}function aN(e){return ZM(e.wrapped,`vertex`)}function oN(e){return ZM(e.wrapped,`wire`)}function sN(e){return ZM(e.wrapped,`vertex`)}function cN(e,t){let n=H(),r=eN(e),i=ZM(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 XM(a,`face`)}var lN=new Map;function uN(e,t){let n=H(),r=TT()??``;if(lN.get(r)!==!1){let i;try{i=n.sharedEdges(e.wrapped,t.wrapped);let a=i.map(e=>KE(e,`edge`));return lN.set(r,!0),a}catch(e){if(i)for(let e of i)n.dispose(e);if(!l(e))throw e;lN.set(r,!1)}}return dN(e,t)}function dN(e,t){let n=H(),r=n.iterShapes(e.wrapped,`edge`),i=n.iterShapes(t.wrapped,`edge`),a=new Map;for(let e of i){let t=n.hashCode(e,G),r=a.get(t);r||(r=[],a.set(t,r)),r.push(e)}let o=[];for(let e of r)a.get(n.hashCode(e,2147483647))?.some(t=>n.isSame(e,t))?o.push(KE(e,`edge`)):n.dispose(e);for(let e of i)n.dispose(e);return o}var fN=new Map;function pN(e,t){let n=H(),r=TT()??``;if(fN.get(r)!==!1)try{let i=n.adjacentFaces(e.wrapped,t.wrapped);fN.set(r,!0);try{return i.map(e=>n.hashCode(e,G))}finally{for(let e of i)n.dispose(e)}}catch(e){if(!l(e))throw e;fN.set(r,!1)}return cN(e,t).map(e=>n.hashCode(e.wrapped,G))}function mN(e,t){let n=0,r=_O(t);if(e.surfaceType!==void 0)if(r===e.surfaceType)n+=1;else return-1/0;if(e.normal!==void 0){let r=wO(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=TO(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=UM(t);if(r.ok&&r.value>0){let t=Math.abs(Math.log(e.area/r.value));t>1&&(n-=t)}}return n}function hN(e){let t=_O(e),n=wO(e),r=TO(e),i=UM(e);return{entityType:`face`,surfaceType:t,normal:n,centroid:r,area:i.ok?i.value:void 0}}var gN=.9;function _N(e){if(e[2]>gN)return`box:top`;if(e[2]<-.9)return`box:bottom`;if(e[1]>gN)return`box:back`;if(e[1]<-.9)return`box:front`;if(e[0]>gN)return`box:right`;if(e[0]<-.9)return`box:left`}function vN(e,t){if(_O(t)!==`PLANE`)return;let n=wO(t)[2];if(n>gN)return`${e}:top`;if(n<-.9)return`${e}:bottom`}function yN(e){return _O(e)===`CYLINDRE`?`cylinder:lateral`:vN(`cylinder`,e)}function bN(e){return _O(e)===`CONE`?`cone:lateral`:vN(`cone`,e)}function xN(e){return _O(e)===`SPHERE`?`sphere:surface`:void 0}var SN={box:e=>_N(wO(e)),cylinder:yN,cone:bN,sphere:xN};function CN(e,t){let n=new Map,r=SN[t],i=H(),a=0;for(let o of i.iterShapes(e.wrapped,`face`)){let e=GE(o,`face`);try{let i=r?.(e),o=i!==void 0&&!n.has(i)?i:`${t}:face_${a}`;n.set(o,[Ek(e)]),a++}finally{WE(e,o)}}return n}function wN(e,t,n){return{origin:e,role:t,hint:hN(n)}}function TN(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 EN(e,t,n){let r=e.get(t);if(!r)return e;let i=new Map;for(let[e,t]of r){let r=TN(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 DN=.1,ON=.5;function kN(e,t,n){let r=-1/0,i,a=-1/0,o=[];for(let s of t){let t=n(e,s);t>ON&&o.push([s,t]),t>r?(a=r,r=t,i=s):t>a&&(a=t)}return i!==void 0&&r>ON?r-a<DN&&o.length>1?{kind:`ambiguous`,candidates:o.filter(([,e])=>e>=r-DN).map(([e])=>e)}:{kind:`match`,face:i}:{kind:`none`}}function AN(e,t,n,r){let i=dD(n),a=r??mN,o=t.get(e.origin)?.get(e.role);if(o!==void 0&&o.length>0){let t=i.filter(e=>o.includes(Ek(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=kN(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=kN(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 jN(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 MN(e){if(e.length===0)return;let t=0,n=0,r=0;for(let i of e){let e=kD(i);t+=e[0],n+=e[1],r+=e[2]}let i=e.length;return[t/i,n/i,r/i]}function NN(e,t,n){let r=n.get(t);if(!r)return;let i=Ek(e);for(let[e,t]of r)if(t.includes(i))return e}function PN(e,t,n,r){let i=r.get(t)?.get(n);return i===void 0||i.length===0?[]:dD(e).filter(e=>i.includes(Ek(e)))}function FN(e){let t=WM(e);return{entityType:`edge`,length:t.ok?t.value:void 0,midpoint:MN(sN(e))}}function IN(e){let t=new Set,n=[];for(let r of e){let e=Ek(r);t.has(e)||(t.add(e),n.push(r))}return n}var LN=1e-6;function RN(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=WM(a);n.ok&&(e+=Math.abs(n.value-t.length))}if(t.midpoint!==void 0){let n=MN(sN(a));n!==void 0&&(e+=jN(t.midpoint,n))}e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<LN))return n}function zN(e,t,n,r){let[i,a]=nN(n,t);if(i===void 0||a===void 0)return;let o=NN(i,e,r),s=NN(a,e,r);if(!(o===void 0||s===void 0))return{origin:e,faceRoles:[o,s],hint:FN(t)}}function BN(e,t,n){let[r,i]=e.faceRoles,a=PN(n,e.origin,r,t),o=PN(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(...uN(e,t));let c=IN(s);if(c.length===1){let[e]=c;if(e!==void 0)return{edge:e,confidence:`exact`}}if(c.length>1){let t=RN(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 VN=3,HN=1e-6;function UN(e,t){let n=new Set;for(let r of e)for(let e of aN(r)){let r=Ek(e);n.add(r),t.has(r)||t.set(r,e)}return n}function WN(e,t){let n=new Set;for(let r of e)t.has(r)&&n.add(r);return n}function GN(e){let t=new Map,n;for(let r of e){let e=UN(r,t);n=n===void 0?e:WN(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=jN(kD(a),t.position);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<HN))return n}function qN(e,t,n,r){let i=rN(n,t);if(i.length<VN)return;let a=new Set;for(let t of i){let n=NN(t,e,r);n!==void 0&&a.add(n)}if(!(a.size<VN))return{origin:e,faceRoles:[...a].sort(),hint:{entityType:`vertex`,position:kD(t)}}}function JN(e,t,n){let r=[];for(let i of e.faceRoles){let a=PN(n,e.origin,i,t);if(a.length===0)return{ref:e,reason:`not-found`};r.push(a)}let i=GN(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 YN=.99,XN=.1,ZN=1e-6;function QN(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function $N(e,t){return dD(e).filter(e=>QN(wO(e),t)>YN)}function eP(e,t,n){let r=new Set([...t,...n].map(Ek)),i=new Set;for(let n of t)for(let t of pN(e,n))i.add(t);let a=[],o=new Set;for(let t of n)for(let n of pN(e,t))r.has(n)||o.has(n)||!i.has(n)||(o.add(n),a.push(n));if(a.length===0)return[];let s=new Map(dD(e).map(e=>[Ek(e),e]));return a.map(e=>s.get(e)).filter(e=>e!==void 0)}function tP(e,t){let n,r=1/0,i=1/0;for(let a of e){let e=jN(TO(a),t);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<ZN))return n}function nP(e,t,n,r,i){let[a,o]=nN(r,n);if(a===void 0||o===void 0)return;let s=NN(a,e,i),c=NN(o,e,i);if(!(s===void 0||c===void 0))return{origin:e,op:t,betweenRoles:[s,c],hint:{entityType:`derived-face`,normalA:wO(a),normalB:wO(o),edgeMidpoint:MN(sN(n))}}}function rP(e,t,n){let r=PN(n,e.origin,e.betweenRoles[0],t);r.length===0&&(r=$N(n,e.hint.normalA));let i=PN(n,e.origin,e.betweenRoles[1],t);if(i.length===0&&(i=$N(n,e.hint.normalB)),r.length===0||i.length===0)return{ref:e,reason:`not-found`};let a=eP(n,r,i).filter(t=>QN(wO(t),e.hint.normalA)>XN&&QN(wO(t),e.hint.normalB)>XN);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&&tP(a,e.hint.edgeMidpoint);return t?{face:t,confidence:`geometric-fallback`}:{ref:e,reason:`ambiguous`,candidates:a}}return{ref:e,reason:`not-found`}}function iP(e){return typeof e==`object`&&!!e&&`origin`in e}function aP(e){return iP(e)&&`betweenRoles`in e&&`op`in e}function oP(e){return iP(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length===2}function sP(e){return iP(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length>=3}function cP(e){return iP(e)&&typeof e.role==`string`}function lP(e){return cP(e)||oP(e)||sP(e)||aP(e)}function uP(e,t){return t===void 0?{ok:!1,reason:e}:{ok:!1,reason:e,candidates:t}}function dP(e,t,n){if(aP(e)){let r=rP(e,t,n);return`face`in r?{ok:!0,entity:r.face}:uP(r.reason,r.candidates)}if(oP(e)){let r=BN(e,t,n);return`edge`in r?{ok:!0,entity:r.edge}:uP(r.reason,r.candidates)}if(sP(e)){let r=JN(e,t,n);return`vertex`in r?{ok:!0,entity:r.vertex}:uP(r.reason,r.candidates)}let r=AN(e,t,n);return`face`in r?{ok:!0,entity:r.face}:uP(r.reason,r.candidates)}function fP(e,t,n){let r=n.get(e.origin);if(r!==void 0)return r;let i=new Map([[e.origin,CN(t,e.origin)]]);return n.set(e.origin,i),i}function pP(e,t){return dP(e,fP(e,t,new Map),t)}function mP(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 hP(e,t){let n=new Map,r=e=>{if(lP(e)){let r=dP(e,fP(e,t,n),t);return r.ok?r.entity:e}if(Array.isArray(e))return e.map(r);if(mP(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 gP(e,t,n,r){let i=kE(H().makeBox(e,t,n)),a=r?.at??(r?.centered?[0,0,0]:void 0);if(a)try{var o=IT();return fk(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 _P(e,t,n){let r=n?.at??[0,0,0],i=n?.axis??[0,0,1],a=cj(e,t,r,i);if(n?.centered)try{var o=IT();let e=[-i[0]*t*.5,-i[1]*t*.5,-i[2]*t*.5];return fk(o.u(a),e)}catch(e){o.e=e}finally{o.d()}return a}function vP(e,t){let n=lj(e);if(t?.at)try{var r=IT();return fk(r.u(n),t.at)}catch(e){r.e=e}finally{r.d()}return n}function yP(e,t,n,r){let i=r?.at??[0,0,0],a=r?.axis??[0,0,1],o=uj(e,t,n,i,a);if(r?.centered)try{var s=IT();let e=[-a[0]*n*.5,-a[1]*n*.5,-a[2]*n*.5];return fk(s.u(o),e)}catch(e){s.e=e}finally{s.d()}return o}function bP(e,t,n){return dj(e,t,n?.at??[0,0,0],n?.axis??[0,0,1])}function xP(e,t,n,r){let i=fj(e,t,n);if(r?.at)try{var a=IT();return fk(a.u(i),r.at)}catch(e){a.e=e}finally{a.d()}return i}function SP(e,t){return SA(e,t)}function CP(e,t){let n=t?.axis??[0,0,1];return CA(e,t?.at??[0,0,0],n)}function wP(e,t,n){let r=n?.axis??[0,0,1];return wA(e,t,n?.at??[0,0,0],r,n?.xDir)}function TP(e,t,n,r){return TA(e,t,n,r?.at??[0,0,0],r?.axis??[0,0,1],r?.lefthand??!1)}function EP(e,t,n){return EA(e,t,n)}function DP(e,t,n,r,i){let a=i?.axis??[0,0,1];return DA(e,t,n*JE,r*JE,i?.at??[0,0,0],a,i?.xDir)}function OP(e,t){return OA(e,t)}function kP(e){return AA(e)}function AP(e,t,n){return jA(e,t,n)}function jP(e){return MA(e)}function MP(e){return Za(MA(e),e=>dE(e)?O(e):k(P(`WIRE_NOT_CLOSED`,`Assembled wire is not closed: start and end points do not coincide`)))}function NP(e,t){return NA(e,t)}function PP(e){return IA(e)}function FP(e,t){return FA(e,t)}function IP(e){return RA(e)}function LP(e){return pj(e)}function RP(e){return hj(e)}function zP(e){return gj(e)}function BP(e,t,n){return mj(e,t,n)}function VP(e,t){return sj(e,t)}function HP(e,t){return LA(e,t)}function UP(){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 WP(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??UP(),color:[a,o,s,c]}});return YT(H().createXCAFDocument(t))}function GP(e=[],{unit:t,modelUnit:n}={}){let r=e=>{let t=e;return t.indexOf(`#`)===0&&(t=t.slice(1)),t.length===3&&(t=t.replace(/([0-9a-f])/gi,`$1$1`)),[parseInt(t.substring(0,2),16),parseInt(t.substring(2,4),16),parseInt(t.substring(4,6),16)]},i=H(),a=e.map(({shape:e,name:t,color:n,alpha:i})=>{let[a,o,s]=r(n??`#f00`);return{shape:e.wrapped,name:t??UP(),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(Do(`STEP_EXPORT_FAILED`,`Failed to write STEP file`))}finally{o.delete()}}function KP(e,t,n,r,i){if(n<1)return k(P(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(GD(t))return k(P(`PATTERN_ZERO_DIRECTION`,`Pattern direction cannot be zero`));let a=UD(t),o=H().linearPattern(e.wrapped,[...a],r,n).map(e=>U(e));try{return GA(o,{optimisation:`sameFace`,...i,unsafe:!0})}finally{for(let e of o)e[Symbol.dispose]()}}function qP(e,t,n,r=360,i=[0,0,0],a){if(n<1)return k(P(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(GD(t))return k(P(`PATTERN_ZERO_AXIS`,`Pattern axis cannot be zero`));let o=r/n,s=H().circularPattern(e.wrapped,[...i],[...t],o,n).map(e=>U(e));try{return GA(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(P(`PATTERN_INVALID_COUNT`,`Grid pattern counts must be at least 1`));if(r===1&&i===1)return O(e);if(GD(t))return k(P(`PATTERN_ZERO_DIRECTION`,`Grid directionX cannot be zero`));if(GD(n))return k(P(`PATTERN_ZERO_DIRECTION`,`Grid directionY cannot be zero`));let c=H(),l=UD(t),u=UD(n);if(typeof c.gridPattern==`function`)return O(U(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 YP(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 XP(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 QP(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 $P(e,t){if(e.name===t)return e;for(let n of e.children){let e=$P(n,t);if(e)return e}}function eF(e,t,n=0){t(e,n);for(let r of e.children)eF(r,t,n+1)}function tF(e){let t=1;for(let n of e.children)t+=tF(n);return t}function nF(e){let t=[];return eF(e,e=>{e.shape&&t.push(e.shape)}),t}function rF(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function iF(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 aF(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function oF(e){return aF(iF(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function sF(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 cF(e,t){let n=t/2,r=Math.sin(n),i=aF(e);return[Math.cos(n),i[0]*r,i[1]*r,i[2]*r]}function lF(e,t){let n=aF(e),r=aF(t),i=rF(n,r);if(i>=.999999999)return[1,0,0,0];if(i<=-.999999999)return cF(oF(n),Math.PI);let a=iF(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 uF(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 dF=Math.PI/180;function fF(e,t,n){return Math.min(n,Math.max(t,e))}function pF(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function mF(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 hF(e){return pF(mF(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function gF(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:pF(t),min:s,max:c,value:fF(n.value??0,s,c)}}function _F(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:pF(r.direction)},min:a.min,max:a.max,value:a.value,dofs:i}}function vF(e,t,n,r={}){return _F(`revolute`,e,t,n,[gF(`rotation`,n.direction,r,-180,180)])}function yF(e,t,n,r={}){return _F(`prismatic`,e,t,n,[gF(`translation`,n.direction,r,0,100)])}function bF(e,t,n,r={}){return _F(`cylindrical`,e,t,n,[gF(`rotation`,n.direction,r.rotation??{},-180,180),gF(`translation`,n.direction,r.translation??{},0,100)])}function xF(e,t,n,r={}){let i=pF(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?hF(i):pF(n)}else a=hF(i);let o=pF(mF(i,a));return _F(`planar`,e,t,{origin:n.origin,direction:i},[gF(`translation`,a,r.u??{},-100,100),gF(`translation`,o,r.v??{},-100,100),gF(`rotation`,i,r.rotation??{},-180,180)])}function SF(e,t,n,r={}){return _F(`spherical`,e,t,{origin:n,direction:[0,0,1]},[gF(`rotation`,[1,0,0],r.x??{},-180,180),gF(`rotation`,[0,1,0],r.y??{},-180,180),gF(`rotation`,[0,0,1],r.z??{},-180,180)])}function CF(e,t){let n=e.dofs.map((e,n)=>{let r=t[n];return r===void 0?e:{...e,value:fF(r,e.min,e.max)}}),r=n[0];return r?{...e,dofs:n,value:r.value}:{...e,dofs:n}}function wF(e,t){return CF(e,[t])}function TF(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=cF(t.axis,n*dF),i=sF(r,e);return{position:[e[0]-i[0],e[1]-i[1],e[2]-i[2]],rotation:r}}function EF(e,t=e.value){let n=Array.isArray(t)?t:void 0,r=n?void 0:t,i=e.axis.origin,a=OF;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=kF(a,TF(i,o,fF(s,o.min,o.max)))}return a}function DF(e,t){let n=e.joints??[];return{...e,joints:[...n,t]}}var OF={position:[0,0,0],rotation:[1,0,0,0]};function kF(e,t){let n=sF(e.rotation,t.position);return{position:[e.position[0]+n[0],e.position[1]+n[1],e.position[2]+n[2]],rotation:uF(e.rotation,t.rotation)}}function AF(e){let t=[];return eF(e,e=>{e.joints&&t.push(...e.joints)}),t}function jF(e,t={}){let n=[],r=new Set;eF(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,OF);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?kF(EF(n,i),n.offset):EF(n,i);a.set(n.child,kF(r,c))}}for(let e of o)a.has(e.child)||a.set(e.child,OF);return a}function MF(e){return AF(e).reduce((e,t)=>e+t.dofs.length,0)}var NF={position:[0,0,0],rotation:[1,0,0,0]};function PF(e,t){let n=sF(e.rotation,t);return[n[0]+e.position[0],n[1]+e.position[1],n[2]+e.position[2]]}function FF(e){return[e[0],-e[1],-e[2],-e[3]]}function IF(e,t){let[n,r,i,a]=uF(t,FF(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 LF(e,t){let n=[];eF(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 RF(e,t){return e[t]??0}function zF(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]=RF(e,a*n+t);i[a*r+n]=RF(t,a)}for(let e=0;e<n;e++){let t=e;for(let a=e+1;a<n;a++)Math.abs(RF(i,a*r+e))>Math.abs(RF(i,t*r+e))&&(t=a);if(Math.abs(RF(i,t*r+e))<1e-12)return null;if(t!==e)for(let n=e;n<r;n++){let a=RF(i,e*r+n);i[e*r+n]=RF(i,t*r+n),i[t*r+n]=a}let a=RF(i,e*r+e);for(let t=e;t<r;t++)i[e*r+t]=RF(i,e*r+t)/a;for(let t=0;t<n;t++){if(t===e)continue;let n=RF(i,t*r+e);if(n!==0)for(let a=e;a<r;a++)i[t*r+a]=RF(i,t*r+a)-n*RF(i,e*r+a)}}let a=new Float64Array(n);for(let e=0;e<n;e++)a[e]=RF(i,e*r+n);return a}function BF(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 VF(e,t){let n={},r=0;for(let i of e){let e=[];for(let n=0;n<i.count;n++)e.push(RF(t,r++));n[i.child]=e}return n}function HF(e,t,n,r,i){let a=PF(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=IF(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+=RF(e,t)**2;return Math.sqrt(o)}function UF(e,t,n,r,i,a,o,s,c,l){let u=PF(o,s);for(let d=0;d<n;d++){let f=RF(t,d),p=f+c>RF(a,d)&&f-c>=RF(i,d)?-c:c;t[d]=f+p;let m=l(t);t[d]=f;let h=PF(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=IF(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 WF(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+=RF(e,t*n+r)*RF(e,i*n+r);a[t*r+i]=s+(t===i?o:0)}let s=zF(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+=RF(e,a*n+t)*RF(s,a);c[t]=i}return c}function GF(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}=BF(LF(e,t),r.seed),p=u.length,m=n=>jF(e,VF(l,n)).get(t)??NF,h=new Float64Array(c),g=new Float64Array(c*p),_=m(u),v=HF(h,_,n,s,c),y=0;for(;y<i&&p>0&&v>a;y++){UF(g,u,p,c,d,f,_,s,1e-6,m);let e=WF(g,h,p,c,o);if(!e)break;for(let t=0;t<p;t++){let n=RF(u,t)+RF(e,t);u[t]=Math.min(RF(f,t),Math.max(RF(d,t),n))}_=m(u),v=HF(h,_,n,s,c)}return{values:VF(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 qF(e,t,n,r){let i=[];eF(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:jF(e,r)})}return s}var JF=Math.PI/180;function YF(e,t,n,r){let i=e*JF,a=r*JF,o=uF(cF([0,0,1],i),cF([1,0,0],a));return{position:[n*Math.cos(i),n*Math.sin(i),t],rotation:o}}function XF(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=YF(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`?yF(i,a,s,c):vF(i,a,s,c),offset:o}})}var ZF=Math.PI/180,QF=180/Math.PI;function $F(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function eI(e){return String(e===0?0:e)}function tI(e){return`${eI(e[0])} ${eI(e[1])} ${eI(e[2])}`}function nI(e,t={}){let n=t.name??`robot`,r=t.effort??0,i=t.velocity??0,a=t.meshes??{},o=[],s=[];eF(e,e=>{o.push(e.name),e.joints&&s.push(...e.joints)});for(let e of s){if(e.type!==`revolute`&&e.type!==`prismatic`)return k(P(M.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' is '${e.type}'; URDF supports only revolute and prismatic joints`));if(e.offset)return k(P(M.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' carries a fixed offset (e.g. a DH link) that URDF cannot represent as a single joint`))}let c=[`<?xml version="1.0"?>`,`<robot name="${$F(n)}">`];for(let e of o){let t=a[e];t?c.push(` <link name="${$F(e)}">`,` <visual><geometry><mesh filename="${$F(t)}"/></geometry></visual>`,` </link>`):c.push(` <link name="${$F(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="${$F(`${e.parent}_to_${e.child}`)}" type="${e.type}">`,` <parent link="${$F(e.parent)}"/>`,` <child link="${$F(e.child)}"/>`,` <origin xyz="${tI(o)}" rpy="0 0 0"/>`,` <axis xyz="${tI(e.axis.direction)}"/>`,` <limit lower="${eI(n)}" upper="${eI(a)}" effort="${eI(r)}" velocity="${eI(i)}"/>`,` </joint>`)}return c.push(`</robot>`,``),O(c.join(`
|
|
16
|
+
`))}function rI(e,t){return RegExp(`\\b${t}\\s*=\\s*"([^"]*)"`).exec(e)?.[1]}function iI(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 aI(e,t){return sF(uF(uF(cF([0,0,1],t[2]),cF([0,1,0],t[1])),cF([1,0,0],t[0])),e)}function oI(e){let t=/<robot\b([^>]*)>/.exec(e);if(!t)return k(P(M.VALIDATION_FAILED,`importURDF: no <robot> element found`));let n=rI(t[1]??``,`name`)??`robot`,r=[],i=/<link\b([^>]*?)(?:\/>|>)/g;for(let t=i.exec(e);t;t=i.exec(e)){let e=rI(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=rI(e,`type`)??`fixed`;if(r===`fixed`||r===`floating`||r===`planar`)continue;let i=/<parent\b([^>]*?)\/?>/.exec(n),o=/<child\b([^>]*?)\/?>/.exec(n),s=rI(i?.[1]??``,`link`),c=rI(o?.[1]??``,`link`);if(!s||!c)return k(P(M.VALIDATION_FAILED,`importURDF: joint missing parent/child link (${rI(e,`name`)??`unnamed`})`));let l=/<origin\b([^>]*?)\/?>/.exec(n),u=/<axis\b([^>]*?)\/?>/.exec(n),d=/<limit\b([^>]*?)\/?>/.exec(n),f=iI(rI(l?.[1]??``,`xyz`),[0,0,0]),p=iI(rI(l?.[1]??``,`rpy`),[0,0,0]),m=aI(iI(rI(u?.[1]??``,`xyz`),[1,0,0]),p),h=Number(rI(d?.[1]??``,`lower`)??NaN),g=Number(rI(d?.[1]??``,`upper`)??NaN);if(r===`prismatic`){let e=Number.isFinite(h)&&Number.isFinite(g)?{min:h,max:g}:{};a.push(yF(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*QF,max:g*QF};a.push(vF(s,c,{origin:f,direction:m},e))}else return k(P(M.VALIDATION_FAILED,`importURDF: joint '${rI(e,`name`)??`unnamed`}' has unrecognized type '${r}'`))}return O({name:n,links:r,joints:a})}function sI(){return{steps:[],shapes:new Map}}function cI(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 lI(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 uI(e,t){return e.steps.find(e=>e.id===t)}function dI(e,t){return e.shapes.get(t)}function fI(e){return e.steps.length}function pI(e,t){let n=e.steps.findIndex(e=>e.id===t);return n===-1?[]:e.steps.slice(n)}function mI(e,t,n){let r=new Map(e.shapes);return r.set(t,n),{...e,shapes:r}}function hI(){return{operations:new Map}}function gI(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function _I(e,t){let[n,r]=t;return n!==void 0&&r===void 0&&zE(n)?hP(e,n):{...e}}function vI(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=mI(r,t,i));for(let n of e.steps){let e=t.operations.get(n.type);if(!e)return k(Eo(`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(Eo(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${n.id}`));i.push(t)}try{let t=e(i,_I(n.parameters,i));r=cI(r,{id:n.id,type:n.type,parameters:n.parameters,inputIds:n.inputIds,outputId:n.outputId},t)}catch(e){return k(Eo(`REPLAY_STEP_FAILED`,`Step ${n.id} (${n.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(r)}function yI(e,t,n){let r=e.steps.findIndex(e=>e.id===t);if(r===-1)return k(Eo(`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(Eo(`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(Eo(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${r.id}`));o.push(t)}try{let e=i(o,_I(r.parameters,o));a=cI(a,{id:r.id,type:r.type,parameters:r.parameters,inputIds:r.inputIds,outputId:r.outputId},e)}catch(e){return k(Eo(`REPLAY_STEP_FAILED`,`Step ${r.id} (${r.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(a)}function bI(e,t,n,r){return e.steps.findIndex(e=>e.id===t)===-1?k(Eo(`MODIFY_STEP_NOT_FOUND`,`Step not found: ${t}`)):yI({steps:e.steps.map(e=>e.id===t?{...e,parameters:n}:e),shapes:e.shapes},t,r)}function xI(e){let t={};for(let[n,r]of e.shapes){let e=Tk(r);if(!e.ok)return k(Eo(`SERIALIZE_SHAPE_FAILED`,`Failed to serialize shape "${n}": ${e.error.message}`));t[n]=e.value}return O({steps:e.steps,shapes:t})}function SI(e){let t=new Map;for(let[n,r]of Object.entries(e.shapes))try{let e=mO(r);if(!e.ok)return k(Eo(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e.error.message}`));t.set(n,e.value)}catch(e){return k(Eo(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e instanceof Error?e.message:String(e)}`))}return O({steps:e.steps,shapes:t})}function CI(e){try{var t=IT();let{radius:n,pitch:r,height:i,depth:a=.6*r,toothHalfWidth:o=.42*r,crest:s=0,sectionsPerTurn:c=20,lefthand:l=!1,inward:u=!1}=e;if(!(n>0))return k(P(`THREAD_INVALID_RADIUS`,`radius must be > 0`));if(!(r>0))return k(P(`THREAD_INVALID_PITCH`,`pitch must be > 0`));if(!(i>0))return k(P(`THREAD_INVALID_HEIGHT`,`height must be > 0`));if(!(a>0))return k(P(`THREAD_INVALID_DEPTH`,`depth must be > 0`));if(s<0||s>=o)return k(P(`THREAD_INVALID_CREST`,`crest must be >= 0 and < toothHalfWidth`));if(c<3)return k(P(`THREAD_TOO_FEW_SECTIONS`,`sectionsPerTurn must be >= 3`));let d=i/r,f=Math.max(2,Math.round(d*c)),p=l?-1:1,m=u?-a:a,h=u?.3:-.3,g=o,_=t.u(new XT),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=jP(f.map((e,t)=>_.register(SP(e,f[(t+1)%f.length]))));if(!Ja(y))return y;v.push(_.register(y.value))}return MM(v,{ruled:!0})}catch(e){t.e=e}finally{t.d()}}var wI=1e-9,TI=1e-8,EI=1e-6,DI=([e,t],[n,r],i=EI)=>Math.abs(e-n)<=i&&Math.abs(t-r)<=i,OI=([e,t],[n,r])=>[e+n,t+r],kI=([e,t],[n,r])=>[e-n,t-r],AI=([e,t],n)=>[e*n,t*n],jI=([e,t],[n,r]=[0,0])=>Math.sqrt((e-n)**2+(t-r)**2),MI=([e,t],[n,r]=[0,0])=>(e-n)**2+(t-r)**2;function NI([e,t],[n,r]){return e*r-t*n}var PI=([e,t],[n,r]=[0,0])=>Math.atan2(r*e-t*n,e*n+t*r),FI=([e,t],[n,r]=[0,0])=>Math.atan2(r-t,n-e),II=(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 LI([e,t]){let n=Math.sqrt(e*e+t*t);return n<1e-12?[0,0]:[e/n,t/n]}var RI=(e,t)=>[Math.cos(t)*e,Math.sin(t)*e],zI=([e,t])=>[Math.sqrt(e*e+t*t),Math.atan2(t,e)],BI=([e,t])=>{let n=LI([e,t]);return n[0]===0&&n[1]===0&&i(`normalize2d`,`Cannot normalize zero-length vector`),n};function VI(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(Oo(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found ${r===0?0:`2+`} element(s)`))}function HI(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 uD(t);case`face`:return dD(t);case`wire`:return fD(t);case`vertex`:return pD(t)}}let s=e=>{let n=o(e);return t.length===0?n.slice():n.filter(a)},c=()=>HI(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=Ek(n),r=t.get(e);r?r.push(n):t.set(e,[n])}return i(e=>{let n=t.get(Ek(e));return!!n&&n.some(t=>Ok(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=>VI(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 UI={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function WI(e){return typeof e==`string`?UI[e]??[0,0,1]:e}function GI(e,t,n){let r=H(),i=r.makeVertex(t[0],t[1],t[2]);return t=>{let a=r.distance(i,t.wrapped).value;return Math.abs(a-e)<n}}function KI(e,t){let n=UD(WI(e));return e=>{let r=H(),[i,a]=r.curveParameters(e.wrapped),o=(i+a)/2,{tangent:s}=r.curveTangent(e.wrapped,o),c=UD(s),l=Math.acos(Math.min(1,Math.abs(RD(c,n))));return Math.abs(l-JE*t)<1e-6}}function qI(e){return HI(`edge`,e,qI,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(KI(e,t)),ofLength:(e,t=.001)=>n(n=>Math.abs(Ik(n)-e)<t),ofCurveType:e=>n(t=>jk(t)===e),parallelTo:(t=`Z`)=>qI(e).inDirection(t,0),atDistance:(e,t=[0,0,0])=>n(GI(e,t,1e-6))}))}function JI(){return qI([])}function YI(e,t){let n=UD(WI(e));return e=>{let r=wO(e),i=Math.acos(Math.min(1,Math.abs(RD(UD(r),n))));return Math.abs(i-JE*t)<1e-6}}function XI(e){return HI(`face`,e,XI,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(YI(e,t)),parallelTo:(t=`Z`)=>XI(e).inDirection(t,0),ofSurfaceType:e=>n(t=>{let n=gO(t);return Ja(n)&&n.value===e}),ofArea:(e,t=.001)=>n(n=>{let r=UM(n);return Ja(r)&&Math.abs(r.value-e)<t}),atDistance:(e,t=[0,0,0])=>n(GI(e,t,1e-6))}))}function ZI(){return XI([])}function QI(e){return HI(`wire`,e,QI,(e,t)=>({isClosed:()=>t(e=>Rk(e)),isOpen:()=>t(e=>!Rk(e)),ofEdgeCount:e=>t(t=>uD(t).length===e)}))}function $I(){return QI([])}function eL(e,t){return typeof e==`object`&&`_topoKind`in e?e.findUnique(t):typeof e!=`function`&&FE(e)?O(e):e(ZI()).findUnique(t)}function tL(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`}function nL(e,t){let n=10**t,r=t<0?e:.01/n+e;return Math.round(r*n)/n}function rL(e){return Math.round(e*100)/100}function iL(e){return Math.round(e*1e5)/1e5}var aL=([e,t])=>`(${rL(e)},${rL(t)})`,oL=(e,t=1e-9)=>{let n=e;return Math.abs(e)<t&&(n=0),n.toFixed(-Math.log10(t))},sL=(e,t=1e-9)=>Array.from(new Map(e.map(([e,n])=>[`[${oL(e,t)},${oL(n,t)}]`,[e,n]])).values()),cL=class{_wrapped;_deleted=!1;constructor(e){this._wrapped=e??wT().createBoundingBox2d(),QT(this,this._wrapped)}get wrapped(){if(this._deleted)throw Error(`This object has been deleted`);return this._wrapped}delete(){this._deleted||(this._deleted=!0,$T(this._wrapped),typeof this._wrapped.delete==`function`&&this._wrapped.delete())}[Symbol.dispose](){this.delete()}get repr(){let[e,t]=this.bounds;return`${aL(e)} - ${aL(t)}`}get bounds(){let{xMin:e,yMin:t,xMax:n,yMax:r}=wT().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){wT().mergeBBox2d(this.wrapped,e.wrapped)}isOut(e){return wT().isBBox2dOut(this.wrapped,e.wrapped)}containsPoint(e){return!wT().isBBox2dOutPoint(this.wrapped,e[0],e[1])}};function lL(e){return new uL(H().deserializeCurve2d(e))}var uL=class e{_wrapped;_deleted=!1;_boundingBox;_firstPoint=null;_lastPoint=null;_firstParameter=null;_lastParameter=null;constructor(e){this._wrapped=H().wrapCurve2dHandle(e),this._boundingBox=null,typeof this._wrapped.delete==`function`&&QT(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`&&($T(this._wrapped),this._wrapped.delete()))}[Symbol.dispose](){this.delete()}get boundingBox(){if(this._boundingBox)return this._boundingBox;let e=H(),t=e.createBoundingBox2d();return e.addCurveToBBox2d(t,this.wrapped,1e-6),this._boundingBox=new cL(t),this._boundingBox}get repr(){return`${this.geomType} ${aL(this.firstPoint)} - ${aL(this.lastPoint)}`}serialize(){return H().serializeCurve2d(this.wrapped)}value(e){return H().evaluateCurve2d(this.wrapped,e)}get firstPoint(){return this._firstPoint===null&&(this._firstPoint=this.value(this.firstParameter)),this._firstPoint}get lastPoint(){return this._lastPoint===null&&(this._lastPoint=this.value(this.lastParameter)),this._lastPoint}get firstParameter(){return this._firstParameter===null&&(this._firstParameter=H().getCurve2dBounds(this.wrapped).first),this._firstParameter}get lastParameter(){return this._lastParameter===null&&(this._lastParameter=H().getCurve2dBounds(this.wrapped).last),this._lastParameter}get geomType(){return H().getCurve2dType(this.wrapped)}clone(){let t=new e(H().copyCurve2d(this.wrapped));return t._firstPoint=this._firstPoint,t._lastPoint=this._lastPoint,t._firstParameter=this._firstParameter,t._lastParameter=this._lastParameter,t}reverse(){H().reverseCurve2d(this.wrapped);let e=this._firstPoint;this._firstPoint=this._lastPoint,this._lastPoint=e;let t=this._firstParameter;this._firstParameter=this._lastParameter,this._lastParameter=t}distanceFromPoint(e){let t=H().projectPointOnCurve2d(this.wrapped,e[0],e[1]),n=t?t.distance:1/0;return Math.min(n,jI(e,this.firstPoint),jI(e,this.lastPoint))}distanceFromCurve(e){let t;try{t=H().distanceBetweenCurves2d(this.wrapped,e.wrapped,this.firstParameter,this.lastParameter,e.firstParameter,e.lastParameter)}catch{t=1/0}return Math.min(t,this.distanceFromPoint(e.firstPoint),this.distanceFromPoint(e.lastPoint),e.distanceFromPoint(this.firstPoint),e.distanceFromPoint(this.lastPoint))}distanceFrom(e){return tL(e)?this.distanceFromPoint(e):this.distanceFromCurve(e)}isOnCurve(e){return this.distanceFromPoint(e)<1e-9}parameter(e,t=1e-9){let n,r,i=!1;try{let t=H().projectPointOnCurve2d(this.wrapped,e[0],e[1]);t?(n=t.distance,r=t.param):i=!0}catch{i=!0}return i?DI(e,this.firstPoint,t)?O(this.firstParameter):DI(e,this.lastPoint,t)?O(this.lastParameter):k(Eo(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n===void 0||r===void 0?k(Eo(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n>t?k(Eo(`POINT_NOT_ON_CURVE`,`Point ${aL(e)} not on curve ${this.repr}, ${n.toFixed(9)}`)):O(r)}tangentAt(e){let t;if(Array.isArray(e))t=j(this.parameter(e));else{let n=H().getCurve2dBounds(this.wrapped);t=(n.last-n.first)*e+n.first}return H().evaluateCurve2dD1(this.wrapped,t).tangent}splitAt(n,r=1e-9){let i=n.map(e=>tL(e)?j(this.parameter(e,r)):e);i=Array.from(new Map(i.map(e=>[nL(e,-Math.log10(r)),e])).values()).sort((e,t)=>e-t);let a=this.firstParameter,o=this.lastParameter;return a>o&&i.reverse(),Math.abs(t(i,0)-a)<r*100&&(i=i.slice(1)),!i.length||(Math.abs(t(i,i.length-1)-o)<r*100&&(i=i.slice(0,-1)),!i.length)?[this]:H().splitCurve2d(this.wrapped,i).map(t=>new e(t))}},dL=(e,t=1e-4,n=`C0`,r=200)=>new uL(wT().approximateCurve2dAsBSpline(e.wrapped,t,n,r)),fL=e=>(e.geomType!==`BSPLINE_CURVE`&&i(`BSplineToBezier`,`You can only convert a Bspline`),wT().decomposeBSpline2dToBeziers(e.wrapped).map(e=>new uL(e)));function pL(e,t={tolerance:1e-4,continuity:`C0`,maxSegments:300}){let n=wT();return e.flatMap(e=>{let r=e.geomType;if(r===`ELLIPSE`||r===`CIRCLE`&&DI(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 pL(fL(r===`BSPLINE_CURVE`?e:dL(e,t.tolerance,t.continuity,t.maxSegments)),t)})}var mL=(e,t)=>{let n=new uL(H().makeLine2d(e[0],e[1],t[0],t[1]));return DI(n.firstPoint,e)||n.reverse(),n},hL=(e,t,n)=>{let r=new uL(H().makeArc2dThreePoints(e[0],e[1],t[0],t[1],n[0],n[1]));if(!DI(r.firstPoint,e)){let e=H().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new uL(e)}return r},gL=(e,t,n)=>{let r=new uL(H().makeArc2dTangent(e[0],e[1],t[0],t[1],n[0],n[1]));if(!DI(r.firstPoint,e)){let e=H().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new uL(e)}return r},_L=(e,t=[0,0])=>new uL(H().makeCircle2d(t[0],t[1],e,!0)),vL=(e,t,n=[1,0],r=[0,0],i=!0)=>new uL(H().makeEllipse2d(r[0],r[1],e,t,n[0],n[1],i)),yL=(e,t,n,r,i=[0,0],a,o=!0)=>new uL(H().makeEllipseArc2d(i[0],i[1],e,t,n,r,a[0],a[1],o)),bL=(e,t,n)=>{let r=[[e[0],e[1]],...t.map(e=>[e[0],e[1]]),[n[0],n[1]]];return new uL(H().makeBezier2d(r))};function xL(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 uL(H().makeBSpline2d(a,{tolerance:t,smoothing:n,degMax:r,degMin:i,continuity:`C2`})))}catch(e){return k(Eo(`BSPLINE_2D_FAILED`,`B-spline approximation failed`,e))}}var SL=(e,t,n,r=!1)=>{let i=AI(OI(e,t),.5),a=jI(n,e)*(r?-1:1);return hL(e,OI(AI(BI(kI(i,n)),a),n),t)},CL=(e,n)=>{let r=wT(),a=e.geomType,[o,s]=n,c=`${iL(o)} ${iL(s)}`;if(a===`LINE`)return`L ${c}`;if(a===`BEZIER_CURVE`){let n=r.getCurve2dBezierPoles(e.wrapped);n||i(`adaptedCurveToPathElem`,`Expected Bezier poles`);let a=n.length-1;if(a===1)return`L ${c}`;if(a===2){let[e,r]=t(n,1);return`Q ${rL(e)} ${rL(r)} ${c}`}if(a===3){let[e,r]=t(n,1),[i,a]=t(n,2);return`C ${rL(e)} ${rL(r)} ${rL(i)} ${rL(a)} ${c}`}}if(a===`CIRCLE`){let t=r.getCurve2dCircleData(e.wrapped);t||i(`adaptedCurveToPathElem`,`Expected circle data`);let{radius:n,isDirect:a}=t,l=r.getCurve2dBounds(e.wrapped),u=(l.last-l.first)*YE,d=u===360?`${iL(o)} ${iL(s+1e-4)}`:c;return`A ${n} ${n} 0 ${Math.abs(u)>180?`1`:`0`} ${a?`1`:`0`} ${d}`}if(a===`ELLIPSE`){let t=r.getCurve2dEllipseData(e.wrapped);t||i(`adaptedCurveToPathElem`,`Expected ellipse data`);let{majorRadius:n,minorRadius:a,xAxisAngle:l,isDirect:u}=t,d=r.getCurve2dBounds(e.wrapped),f=(d.last-d.first)*YE,p=f===360?`${iL(o)} ${iL(s+1e-4)}`:c,m=180-l*YE;return`A ${iL(n)} ${iL(a)} ${iL(m)} ${Math.abs(f)>180?`1`:`0`} ${u?`1`:`0`} ${p}`}i(`adaptedCurveToPathElem`,`Unsupported curve type: ${a}`)},wL=e=>{let t=H(),n=t.createBoundingBox2d();return e.forEach(e=>{t.addCurveToBBox2d(n,e.wrapped,1e-6)}),new cL(n)};function TL(e,t){let n=H();return e.map(e=>TE(n.liftCurve2dToPlane(e.wrapped,[...t.origin],[...t.zDir],[...t.xDir])))}var EL=(e,t)=>{let n=H();return e.map(e=>TE(n.buildEdgeOnSurface(e.wrapped,t)))},DL=(e,t)=>{let n=H();return e.map(e=>t?new uL(n.transformCurve2dGeneral(e.wrapped,t)):e.clone())},OL=(e,t,n=[0,0])=>H().createAffinityGTrsf2d(n[0],n[1],-t[1],t[0],e),kL=e=>H().createTranslationGTrsf2d(e[0],e[1]),AL=(e,t=[0,0],n=`center`)=>n===`center`?H().createMirrorGTrsf2d(e[0],e[1],`point`):H().createMirrorGTrsf2d(0,0,`axis`,t[0],t[1],e[0],e[1]),jL=(e,t=[0,0])=>H().createRotationGTrsf2d(e,t[0],t[1]),ML=(e,t=[0,0])=>H().createScaleGTrsf2d(e,t[0],t[1]);function NL(e,t,n=`original`){let r=H(),i=r.extractSurfaceFromFace(t.wrapped),a=bO(t),o=null;if(n===`original`&&_O(t)!==`PLANE`){if(_O(t)!==`CYLINDRE`)return k(P(`UNSUPPORTED_FACE_TYPE`,`Only planar and cylindrical faces can be unwrapped for sketching`));let e=r.getSurfaceCylinderData(i);if(!e)return k(P(`UNSUPPORTED_FACE_TYPE`,`Could not extract cylinder data from face surface`));e.isDirect||(i=r.reverseSurfaceU(i)),o=OL(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=EL(DL(e,o),i);return o&&o.delete(),O(s)}function PL(e,t){let n=H(),r=new uL(n.extractCurve2dFromEdge(e.wrapped,t.wrapped));return Vk(e)===`backward`&&n.reverseCurve2d(r.wrapped),r}var FL=(e,t=1)=>`${e.bounds[0][0]-t} ${-e.bounds[1][1]-t} ${e.width+2*t} ${e.height+2*t}`,IL=(e,t,n=1)=>`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${FL(t,n)}" fill="none" stroke="black" stroke-width="0.6%" vector-effect="non-scaling-stroke">
|
|
17
17
|
${e}
|
|
18
|
-
</svg>`;function
|
|
19
|
-
`)}get boundingBox(){return this._boundingBox||=CL(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=_A(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=EL(this.curves,DL(t,n,r));return new e(i)}scale(t,n){let r=n||this.boundingBox.center,i=EL(this.curves,jL(t,r));return new e(i)}rotate(t,n){let r=EL(this.curves,AL(t*JE,n));return new e(r)}translate(t,n=0){let r=eL(t)?t:[t,n],i=EL(this.curves,OL(r));return new e(i)}mirror(t,n=[0,0],r=`center`){let i=EL(this.curves,kL(t,n,r));return new e(i)}sketchOnPlane(e,t){let n=e&&typeof e!=`string`?{...e}:tO(e,t),r=wL(this.curves,n),i=IL(r);for(let e of r)e[Symbol.dispose]();return{wire:i,defaultOrigin:n.origin,defaultDirection:n.zDir}}sketchOnFace(e,t){let n=H(),r=j(ML(this.curves,e,t)),i=IL(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:EE(a),baseFace:e}}subFace(e,t){let n=AD(t||[...TO(e)]);return j(NA(this.translate(SO(e,n)).sketchOnFace(e,`original`).wire))}punchHole(e,t,{height:n=null,origin:r=null,draftAngle:i=0}={}){let a=j($I(t,e)),o=this.subFace(a,r);return j(fO(H().draftPrism(e.wrapped,o.wrapped,a.wrapped,n,i,!1)))}toSVGPathD(){let e=this.clone().mirror([1,0],[0,0],`plane`),t=fL(e.curves).flatMap(e=>SL(e,e.lastPoint)),[n,r]=vA(e.curves).firstPoint;return`M ${rL(n)} ${rL(r)} ${t.join(` `)}${e.isClosed()?` Z`:``}`}toSVGPath(){return`<path d="${this.toSVGPathD()}" />`}toSVGViewBox(e=1){return PL(this.boundingBox,e)}toSVGPaths(){return[this.toSVGPathD()]}toSVG(e=1){return FL(this.toSVGPath(),this.boundingBox,e)}get firstPoint(){return vA(this.curves).firstPoint}get lastPoint(){return yA(this.curves).lastPoint}isInside(e){if(!this.boundingBox.containsPoint(e))return!1;let t=H(),n=pL(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=>EI(t,e,1e-9))||(r.push(e),i++);for(let e of a.segments)e.delete()}),!!(i%2)}finally{n.delete()}}isClosed(){return EI(this.firstPoint,this.lastPoint)}intersects(e){if(this.boundingBox.isOut(e.boundingBox))return!1;let t=H();for(let n of this.curves)for(let r of e.curves){if(n.boundingBox.isOut(r.boundingBox))continue;let e=t.intersectCurves2d(n.wrapped,r.wrapped,1e-9);if(e.points.length||e.segments.length)return!0}return!1}},RL=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)}},zL=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],BL=3,VL=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!==BL)throw Error(`Got v${a} data when expected v${BL}.`);let o=zL[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=zL.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,(BL<<4)+c]),new Uint16Array(n,2,1)[0]=t,new Uint32Array(n,4,1)[0]=e}this._queue=new RL}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]=GL(d*((t+s)/2-n)|0,f*((o+c)/2-r)|0)}UL(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,HL(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 HL(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 UL(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;WL(e,t,n,d,f)}o.push(i,f,f+1,r)}}function WL(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 GL(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 KL=(e,t,n=1e-9)=>{if(e.boundingBox.isOut(t.boundingBox))return O({intersections:[],commonSegments:[],commonSegmentsPoints:[]});let r=wT(),i,a;try{let o=r.intersectCurves2d(e.wrapped,t.wrapped,n);i=o.points,a=o.segments.map(e=>new lL(e))}catch(e){return k(Eo(`INTERSECTION_FAILED`,`Intersections failed between curves`,e))}let o=a.filter(e=>EI(e.firstPoint,e.lastPoint,n)).map(e=>e.firstPoint);o.length&&(i.push(...o),a=a.filter(e=>!EI(e.firstPoint,e.lastPoint,n)));let s=a.flatMap(e=>[e.firstPoint,e.lastPoint]);return O({intersections:i,commonSegments:a,commonSegmentsPoints:s})},qL=(e,t=1e-9)=>{let n=wT(),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(Eo(`SELF_INTERSECTION_FAILED`,`Self intersection failed`,e))}return O(r)},JL=(e,n,r)=>{let i=zI(OI(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)}},YL=(e,t)=>{let n=e.geomType,r=wT();if(n===`CIRCLE`){let n=r.getCurve2dCircleData(e.wrapped);if(!n)return pL(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]=zI(OI(e,t));return DI(e,[c*n,c*r])};return{collapsed:!0,firstPoint:n(e.firstPoint),lastPoint:n(e.lastPoint)}}let u=new lL(r.makeCircle2d(i,a,l,s)),d;try{d=r.trimCurve2d(u.wrapped,e.firstParameter,e.lastParameter)}finally{u.delete()}return new lL(d)}if(n===`LINE`){let{firstPoint:n,lastPoint:r}=JL(e.firstPoint,e.lastPoint,t);return pL(n,r)}let i=new lL(r.offsetCurve2d(e.wrapped,t)),a=uL(i);if(i.delete(),j(qL(a)).length){let e=a.firstPoint,t=a.lastPoint;return a.delete(),{collapsed:!0,firstPoint:e,lastPoint:t}}return a};function XL(e,n,r){let i=MI(e.tangentAt(1),n.tangentAt(0));if(Math.abs(i)<1e-10)return null;let a=Math.abs(r)*(i>0?-1:1),o=YL(e,a),s=YL(n,a);if(!(o instanceof lL)||!(s instanceof lL))return null;let c=KL(o,s,1e-9);if(!Ja(c))return null;let l=c.value.intersections.at(-1);if(!eL(l))return null;let u=l,d=(e,t)=>{let[n,r]=t.tangentAt(u),i=zI([-r,n]),o=DI(u,kI(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 ZL(e,t,n){let r=XL(e,t,n);if(!r)return[e,t];let{first:i,second:a,center:o}=r;return[i,xL(i.lastPoint,a.firstPoint,o),a]}function QL(e,t,n){let r=XL(e,t,n);if(!r)return[e,t];let{first:i,second:a}=r;return[i,pL(i.lastPoint,a.firstPoint),a]}function $L(e,n,r){let i=MI(zI(e.tangentAt(1)),zI(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=YL(e,s),l=YL(n,s);if(!(c instanceof lL)||!(l instanceof lL))return[e,n];let u=KL(c,l,1e-9);if(!Ja(u))return[e,n];let d=u.value.intersections.at(-1);if(!eL(d))return[e,n];let f=gL(r,d),p=j(KL(e,f)).intersections[0],m=j(KL(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[_,mL(_.lastPoint,e.lastPoint,v.firstPoint),v]}catch{return[e,n]}}var eR=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
|
|
21
|
-
`),this.boundingBox,e)}},
|
|
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 vA(this.blueprints).punchHole(e,t,n)}toSVGViewBox(e=1){return PL(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 FL(this.toSVGGroup(),this.boundingBox,e)}},nR=e=>{if(e.length===0)return[];if(e.length===1)return[[Ao(e,0,`groupByBoundingBoxOverlap`)]];let t=new VL(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(Ao(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(Ao(e,n,`groupByBoundingBoxOverlap`)),t.length&&t.forEach(e=>{i[e]=a})}),r},rR=e=>e.map((t,n)=>{let r=Ao(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))}}),iR=(e,t)=>e.flatMap(({blueprint:e})=>oR(t.filter(({blueprint:t,isIn:n})=>t===e||n.indexOf(e)!==-1))),aR=(e,t)=>[t.filter(({isIn:e})=>e.length<=1),...oR(rR(e.map(({blueprint:e})=>e)))],oR=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?iR(t,e):aR(n,e)},sR=e=>new eR(nR(e).map(rR).flatMap(oR).map(e=>e.length===1?Ao(e,0,`organiseBlueprints`).blueprint:(e.sort((e,t)=>e.isIn.length-t.isIn.length),new tR(e.map(({blueprint:e})=>e))))),cR=e=>e===`symmetric`||typeof e==`number`||Array.isArray(e)&&e.length===2,lR=e=>{let t;t=e?cR(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`?LI(1,n*JE):n;let s;return s=typeof a==`number`?LI(1,a*JE):a,{endTangent:o,startFactor:r,endFactor:i,startTangent:s}};function uR(e,t,n){return e<t?{majorRadius:t,minorRadius:e,rotationAngle:n+90}:{majorRadius:e,minorRadius:t,rotationAngle:n}}function dR(e,t,n,r,i,a,o,s){let c=i*JE,l=e=>AI(s(e)),u=l(LI(n,c)),d=l(LI(r,c+Math.PI/2)),f=zI(s(FI([1,0],c))),[,p]=RI(f),{cx:m,cy:h,startAngle:g,endAngle:_,clockwise:v,rx:y,ry:b}=mR(e,t,u,d,p,a,o),x=vL(y,b,v?g:_,v?_:g,[m,h],f);return v||x.reverse(),x}function fR(e,t,n,r,i){let a=Math.PI*2,o=pR(1,0,e,t),s=pR(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 pR(e,t,n,r){let a=e*n+t*r,o=Math.sqrt((e*e+t*t)*(n*n+r*r));o<1e-12&&i(`radianAngle`,`Cannot compute angle between zero-length vectors`);let s=Math.acos(Math.max(-1,Math.min(1,a/o)));return e*r-t*n<0&&(s=-s),s}function mR([e,t],[n,r],a,o,s,c,l){a<0&&(a=-a),o<0&&(o=-o),(a<1e-10||o<1e-10)&&i(`convertSvgEllipseParams`,`rx and ry cannot be 0`);let u=Math.sin(s),d=Math.cos(s),f=(e-n)/2,p=(t-r)/2,m=(e+n)/2,h=(t+r)/2,g=d*f+u*p,_=d*p-u*f,v=g*g/(a*a)+_*_/(o*o);v>1&&(a*=Math.sqrt(v),o*=Math.sqrt(v));let y=a*o,b=a*_,x=o*g,S=b*b+x*x;S||i(`convertSvgEllipseParams`,`Start point cannot be same as end point`);let C=Math.sqrt(Math.abs((y*y-S)/S));c===l&&(C=-C);let w=C*b/o,ee=-C*x/a,te=d*w-u*ee+m,ne=u*w+d*ee+h,re=(g-w)/a,ie=(g+w)/a,{startAngle:ae,deltaAngle:oe,endAngle:se}=fR(re,(_-ee)/o,ie,(_+ee)/o,l);return{cx:te,cy:ne,startAngle:ae,deltaAngle:oe,endAngle:se,clockwise:l,rx:a,ry:o}}var hR={chamfer:QL,dogbone:$L,fillet:ZL};function gR(e,t){if(typeof e==`function`)return e;let n=hR[t];return(t,r)=>n(t,r,e)}var _R=class{pointer;firstPoint;pendingCurves;_nextCorner;constructor(e=[0,0]){this.pointer=e,this.firstPoint=e,this._nextCorner=null,this.pendingCurves=[]}_convertToUV([e,t]){return[e,t]}_convertFromUV([e,t]){return[e,t]}_lastCurve(){let e=this.pendingCurves.length;return e===0?null:this.pendingCurves[e-1]}_requireLastCurve(e,t){let n=this._lastCurve();return n||i(e,`You need a previous curve to ${t}`),n}_resolveRelative(e,t){return[this.pointer[0]+e,this.pointer[1]+t]}_saveCurveAndAdvance(e,t){return this.saveCurve(e),this.pointer=t,this}get penPosition(){return this.pointer}get penAngle(){let e=this._lastCurve();if(!e)return 0;let[t,n]=e.tangentAt(1);return Math.atan2(n,t)*YE}movePointerTo(e){return this.pendingCurves.length&&i(`Sketcher2d.movePointerTo`,`You can only move the pointer if there is no curve defined`),this.pointer=e,this.firstPoint=e,this}saveCurve(e){if(!this._nextCorner){this.pendingCurves.push(e);return}let t=this.pendingCurves.pop();t||i(`Sketcher2d.saveCurve`,`No previous curve available for custom corner`),this.pendingCurves.push(...this._nextCorner(t,e)),this._nextCorner=null}lineTo(e){let t=pL(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(LI(e,t*JE))}polarLine(e,t){let[n,r]=LI(e,t*JE);return this.line(n,r)}tangentLine(e){let t=this._requireLastCurve(`Sketcher2d.tangentLine`,`sketch a tangent line`),n=zI(this._convertFromUV(t.tangentAt(1)));return this.line(n[0]*e,n[1]*e)}threePointsArcTo(e,t){let n=mL(this._convertToUV(this.pointer),this._convertToUV(t),this._convertToUV(e));return this._saveCurveAndAdvance(n,e)}threePointsArc(e,t,n,r){let[i,a]=this.pointer;return this.threePointsArcTo([i+e,a+t],[i+n,a+r])}sagittaArcTo(e,t){let[n,r]=this.pointer,[a,o]=e,s=(n+a)/2,c=(r+o)/2,l=-(o-r),u=a-n,d=Math.sqrt(l**2+u**2);d<1e-12&&i(`sagittaArcTo`,`Start and end points cannot be identical`);let f=[s+l/d*t,c+u/d*t],p=mL(this._convertToUV(this.pointer),this._convertToUV(f),this._convertToUV(e));return this._saveCurveAndAdvance(p,e)}sagittaArc(e,t,n){return this.sagittaArcTo(this._resolveRelative(e,t),n)}vSagittaArc(e,t){return this.sagittaArc(0,e,t)}hSagittaArc(e,t){return this.sagittaArc(e,0,t)}bulgeArcTo(e,t){if(!t)return this.lineTo(e);let n=AI(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=hL(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}=uR(t,n,r),l=dR(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=PI(e,this.pointer),i=AI(e,this.pointer);return this.ellipseTo(e,i/2,t,r*YE,!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=yL(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}=lR(t),o=this._lastCurve(),s=AI(this.pointer,e)*.25,c;c=r||(o?this._convertFromUV(o.tangentAt(1)):[1,0]),c=zI(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=zI(u);let d=[e[0]-u[0]*a*s,e[1]-u[1]*a*s];return this.cubicBezierCurveTo(e,l,d)}smoothSpline(e,t,n){return this.smoothSplineTo(this._resolveRelative(e,t),n)}customCorner(e,t=`fillet`){return this.pendingCurves.length||i(`Sketcher2d.customCorner`,`You need a curve defined to fillet the angle`),this._nextCorner=gR(e,t),this}_customCornerLastWithFirst(e,t=`fillet`){if(!e)return;let n=this.pendingCurves.pop(),r=this.pendingCurves.shift();(!n||!r)&&i(`Sketcher2d._customCornerLastWithFirst`,`Not enough curves to close and fillet`),this.pendingCurves.push(...gR(e,t)(n,r))}_closeSketch(){EI(this.pointer,this.firstPoint)||this.lineTo(this.firstPoint)}_closeWithMirror(){EI(this.pointer,this.firstPoint)&&i(`Sketcher2d._closeWithMirror`,`Cannot close with a mirror when the sketch is already closed`);let e=[this.pointer[0]-this.firstPoint[0],this.pointer[1]-this.firstPoint[1]],t=this._convertToUV(this.pointer),n=this._convertToUV(e),r=this.pendingCurves.map(e=>new lL(H().mirrorCurve2dAcrossAxis(e.wrapped,t[0],t[1],n[0],n[1])));r.reverse();for(let e of r)e.reverse();this.pendingCurves.push(...r),this.pointer=this.firstPoint}},vR=class extends _R{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new LL(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()}},yR=2*Math.PI;function bR(e){let t=e%yR,n=t<0?t+yR:t;return n<Math.PI?n:n===Math.PI?0:Math.abs(n-yR)}function xR(e){return e.curves.map((t,n)=>({firstCurve:t,secondCurve:_A(e.curves,(n+1)%e.curves.length),point:t.lastPoint}))}function SR(e){let t=t=>SR([...e,t]),n=t=>e.every(e=>e(t));return{shouldKeep:n,when:e=>t(e),inList:e=>t(t=>e.some(e=>EI(e,t.point))),atDistance:(e,n=[0,0])=>t(t=>Math.abs(AI(n,t.point)-e)<1e-9),atPoint:e=>t(t=>EI(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(bR(NI(n,r))-bR(JE*e))<1e-9}),not:e=>{let n=e(SR([]));return t(e=>!n.shouldKeep(e))},either:e=>{let n=e.map(e=>e(SR([])));return t(e=>n.some(t=>t.shouldKeep(e)))},find:e=>xR(e).filter(n)}}function CR(){return SR([])}var wR=(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=yA(r),a=new vR().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()},TR=(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 vR([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()},ER=(e,t)=>EI(e,t,CI);function DR(e){return`${e[0].toFixed(9)},${e[1].toFixed(9)}`}function OR(e,t){let n=DR(e),r=DR(t);return n<r?`${n}|${r}`:`${r}|${n}`}function kR(e){let t=e[0];return t===void 0&&i(`startOfSegment`,`empty segment`),t.firstPoint}function AR(e){let t=e[e.length-1];return t===void 0&&i(`endOfSegment`,`empty segment`),t.lastPoint}function jR(e){return[...e].reverse().map(e=>{let t=e.clone();return t.reverse(),t})}function MR(e){return[...e].reverse().map(jR)}function NR(e){let t=(e.lastParameter+e.firstParameter)/2;return e.value(t)}function PR(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&&ER(t,i.firstPoint))return r}for(let n=0;n<e.length;n++){let r=e[n];if(r!==void 0&&ER(t,r.firstPoint))return n}return-1}function FR(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 IR(e,t){return t<=0?e:e.slice(t).concat(e.slice(0,t))}function LR(e,t){return IR(e,PR(e,t))}function RR(e,t){let n=DR(t.firstPoint),r=DR(t.lastPoint),a=e=>ER(t.firstPoint,e.firstPoint)&&ER(t.lastPoint,e.lastPoint),o=e=>ER(t.lastPoint,e.firstPoint)&&ER(t.firstPoint,e.lastPoint);function s(e,t,n,r){let i=FR(e,t,n,r);return i===-1?null:IR(e,i)}let c=s(e,n,r,a);if(c!==null)return c;let l=s(e,r,n,o);if(l!==null)return l;let u=jR(e),d=s(u,n,r,a);if(d!==null)return d;let f=s(u,r,n,o);if(f!==null)return f;i(`rotateToStartAtSegment`,`failed to rotate to segment start`)}function*zR(e,t,n){let r=new Set(t.map(DR)),i=new Set(n.map(e=>OR(e.firstPoint,e.lastPoint))),a=e=>r.has(DR(e))?!0:t.some(t=>ER(t,e)),o=(e,t)=>i.has(OR(e,t))?!0:n.some(n=>ER(n.firstPoint,e)&&ER(n.lastPoint,t)||ER(n.firstPoint,t)&&ER(n.lastPoint,e)),s=[];for(let t of e){if(ER(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 BR(e,t,n){return e.filter(e=>{let r=t.filter(t=>ER(t.firstPoint,e)||ER(t.lastPoint,e)),i=r.length%2?r.filter(t=>!(ER(t.firstPoint,e)&&ER(t.lastPoint,e))):r;if(i.length===0||i.length%2)return!1;let a=i.map(e=>n.isInside(NR(e)));return!(a.every(Boolean)||a.every(e=>!e))})}function VR(e,n){let r=[],i=[],a=e.curves.map(()=>[]),o=n.curves.map(()=>[]),s=new VL(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(KL(e,t(n.curves,s),CI/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:oL(r,CI),allCommonSegments:i,firstCurvePoints:a,secondCurvePoints:o}}function HR(e,t){return xA([e,t]).flatMap(([e,t])=>t.length===0?[e]:e.splitAt(t,CI/100))}function UR(e,t,n){return e.some(([e,r])=>e===void 0||r===void 0?!1:ER(e,t)&&ER(r,n)||ER(e,n)&&ER(r,t))}function WR(e,t){let{allIntersections:n,allCommonSegments:r,firstCurvePoints:i,secondCurvePoints:a}=VR(e,t);if(n.length<=1)return null;let o=HR(e.curves,i),s=HR(t.curves,a),c=r.map(e=>[e.firstPoint,e.lastPoint]),l=BR(BR(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=LR(o,e),s=LR(s,e)}else{let e=r[0];if(e===void 0)return null;o=RR(o,e),s=RR(s,e)}let u=Array.from(zR(o,l,r)),d=Array.from(zR(s,l,r)),f=u[0],p=d[0];if(f!==void 0&&p!==void 0){let e=!ER(AR(p),AR(f)),t=r.length>0&&p.length!==1;(e||t)&&(d=MR(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}UR(c,kR(t),AR(t))?h.push([t,`same`]):h.push([t,n])}return h}function GR(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`||!ER(a,n.firstPoint))break;let r=OI(a,i.firstPoint),s=OI(n.lastPoint,n.firstPoint);if(Math.abs(MI(r,s))>1e-9)break;a=n.lastPoint,o++}o>r+1?n.push(pL(i.firstPoint,a)):n.push(i),r=o}return n}function KR(e){let t=e.map(e=>e.firstPoint),n=e.map(e=>e.lastPoint),r=xA([t,n.slice(-1).concat(n.slice(0,-1))]).map(([e,t],n)=>e===void 0||t===void 0||ER(e,t)?null:n).filter(e=>e!==null);if(r.length===0)return[e];let i=xA([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 qR(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 JR(e,t,n,r,i,a,o){let s=[],c=0,l=e[0];if(l!==void 0){let t=NR(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=NR(u),r=n.isInside(e);if(i.secondInside===`keep`&&r||i.secondInside===`remove`&&!r){let e=t;c===1&&(e=jR(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 YR(e,t,n){let r=WR(e,t);if(r===null)return XR(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=qR(r,i,a);return i=e.segmentsIn,a=e.lastWasSame,e.curves}let s=JR(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=KR(GR(o)).filter(e=>e.length>0).map(e=>new LL(e));if(c.length===0)return null;if(c.length===1){let e=c[0];return e===void 0?null:e}return sR(c)}function XR(e,t){let n=e.curves[0],r=t.curves[0];return{identical:!1,firstCurveInSecond:n!==void 0&&t.isInside(NR(n)),secondCurveInFirst:r!==void 0&&e.isInside(NR(r))}}function ZR(e,t){let n=YR(e,t,{firstInside:`remove`,secondInside:`remove`});return n===null||n instanceof LL||n instanceof eR?n:n.identical?e.clone():n.firstCurveInSecond?t.clone():n.secondCurveInFirst?e.clone():new eR([e,t])}function QR(e,t){let n=YR(e,t,{firstInside:`remove`,secondInside:`keep`});return n===null||n instanceof LL||n instanceof eR?n:n.identical||n.firstCurveInSecond?null:n.secondCurveInFirst?new eR([new tR([e,t])]):e.clone()}function $R(e,t){let n=YR(e,t,{firstInside:`keep`,secondInside:`keep`});return n===null||n instanceof LL||n instanceof eR?n:n.identical||n.firstCurveInSecond?e.clone():n.secondCurveInFirst?t.clone():null}var ez=(e,t)=>{if(e instanceof LL&&t instanceof LL){let n=[];return e.curves.forEach(e=>{t.curves.forEach(t=>{let{intersections:r,commonSegmentsPoints:i}=j(KL(e,t));n.push(...r),n.push(...i)})}),n=oL(n),n.length>1}if(e instanceof tR||e instanceof eR)return e.blueprints.some(e=>ez(e,t));if(t instanceof tR||t instanceof eR)return t.blueprints.some(t=>ez(e,t));i(`genericIntersects`,`Unhandled shape combination in genericIntersects`)},tz=(e,t)=>{if(e instanceof tR){if(t instanceof LL)return iz(t,e);if(t instanceof tR)return oz(e,t)}if(t instanceof tR){if(e instanceof LL)return iz(e,t);if(e instanceof tR)return oz(e,t)}if(e instanceof LL&&t instanceof LL)return ZR(e,t);i(`genericFuse`,`Unhandled shape combination in genericFuse`)},nz=e=>{let t=new Map,n=[];return e.forEach((r,a)=>{let o;t.has(a)?o=t.get(a):(o={current:r,fusedWith:new Set([a])},n.push(o)),e.slice(a+1).forEach((e,n)=>{let r=o.current,s=a+n+1;if(o.fusedWith.has(s))return;let c=e,l=!1;if(t.has(s)&&(c=t.get(s).current,l=!0),r.boundingBox.isOut(c.boundingBox)||!ez(r,c))return;let u;if(r instanceof eR||c instanceof eR){let e=sz(r,c);e===null&&i(`fuseIntersectingBlueprints`,`fuse2D returned null for non-null inputs`),u=e}else u=tz(r,c);if(!(u instanceof LL||u instanceof tR)){if(u instanceof eR&&u.blueprints.length===2)return;u instanceof eR&&u.blueprints.length===1?u=Ao(u.blueprints,0,`fuseIntersectingBlueprints`):u instanceof eR||i(`fuseIntersectingBlueprints`,`Fuse produced unexpected non-blueprint result`)}o.fusedWith.add(s),o.current=u,l||t.set(s,o)})}),sR(n.map(({current:e})=>e).flatMap(e=>rz(e)))},rz=e=>e instanceof LL?[e]:e instanceof tR?e.blueprints:e instanceof eR?e.blueprints.flatMap(e=>rz(e)):[],iz=(e,t)=>{let n=ZR(e,Ao(t.blueprints,0,`fuseBlueprintWithCompound`)),r=t.blueprints.slice(1).map(t=>QR(t,e));return sR([...rz(n),...r.flatMap(e=>rz(e))])};function az(e,t){let n=[];for(let r of e)for(let e of t)n.push([r,e]);return n}var oz=(e,t)=>{let n=Ao(e.blueprints,0,`fuseCompoundWithCompound`),r=Ao(t.blueprints,0,`fuseCompoundWithCompound`),i=ZR(n,r),a=t.blueprints.slice(1).map(e=>QR(e,n)),o=e.blueprints.slice(1).map(e=>QR(e,r)),s=az(e.blueprints.slice(1),t.blueprints.slice(1)).flatMap(([e,t])=>rz($R(e,t)));return sR([...rz(i),...a.flatMap(e=>rz(e)),...o.flatMap(e=>rz(e)),...s])},sz=(e,t)=>{if(e===null)return t?.clone()??null;if(t===null)return e.clone();if(!(e instanceof eR)&&t instanceof eR)return nz([e,...t.blueprints]);if(!(t instanceof eR)&&e instanceof eR)return nz([t,...e.blueprints]);if(e instanceof eR&&t instanceof eR){let n=sz(Ao(e.blueprints,0,`fuse2D`),t);return e.blueprints.slice(1).forEach(e=>{n=sz(e,n)}),n}if(e instanceof tR){if(t instanceof eR)return sz(t,e);if(t instanceof LL)return iz(t,e);if(t instanceof tR)return oz(e,t)}if(t instanceof tR){if(e instanceof eR)return sz(e,t);if(e instanceof LL)return iz(e,t);if(e instanceof tR)return oz(e,t)}return e instanceof LL&&t instanceof LL?ZR(e,t):null},cz=e=>{let t=e.flatMap(e=>e===null?[]:e instanceof eR?e.blueprints:e);return t.length===1?Ao(t,0,`mergeNonIntersecting`):new eR(t)},lz=(e,t)=>{if(e===null)return null;if(t===null)return e.clone();if(e instanceof eR)return cz(e.blueprints.map(e=>lz(e,t)));if(e instanceof tR){let n=Ao(e.blueprints,0,`cut2D`);if(t instanceof LL&&!t.intersects(n))return n.isInside(t.firstPoint)?sR([n,...rz(sz(t,new eR(e.blueprints.slice(1))))]):e.clone();{let r=lz(n,t);return e.blueprints.slice(1).forEach(e=>{r=lz(r,e)}),r}}if(t instanceof eR){let n=e;for(let e of t.blueprints)n=lz(n,e);return n}if(t instanceof tR){let n=QR(e,Ao(t.blueprints,0,`cut2D`));return t.blueprints.slice(1).forEach(t=>{n=sz(n,$R(t,e))}),n}return QR(e,t)};function uz(e,t){if(e===null||t===null)return null;if(e instanceof LL&&t instanceof LL)return $R(e,t);if(e instanceof eR)return cz(e.blueprints.map(e=>uz(e,t)));if(e instanceof tR){let n=Ao(e.blueprints,0,`intersect2D`),r=e.blueprints.slice(1);if(r.length===0)return uz(n,t);let i=uz(n,t);for(let e of r)i=lz(i,e);return i}if(t instanceof eR)return cz(t.blueprints.map(t=>uz(e,t)));if(t instanceof tR){let n=Ao(t.blueprints,0,`intersect2D`),r=t.blueprints.slice(1);if(r.length===0)return uz(n,e);let i=uz(n,e);for(let e of r)i=lz(i,e);return i}i(`intersect2D`,`Unhandled Shape2D combination`)}var dz=e(((e,t)=>{t.exports={}}));
|
|
18
|
+
</svg>`;function LL(e){let t=e.map(e=>e.wrapped);return EE(H().makeWire(t))}var RL=class e{curves;_boundingBox;_orientation;_guessedOrientation;constructor(e){e.length===0&&i(`Blueprint`,`requires at least one curve — use createBlueprint() for Result-based validation`),this.curves=e,this._boundingBox=null,this._orientation=null,this._guessedOrientation=null}delete(){this.curves.forEach(e=>{e.delete()}),this._boundingBox&&this._boundingBox.delete()}[Symbol.dispose](){this.delete()}clone(){return new e(this.curves.map(e=>e.clone()))}get repr(){return[`Blueprint`,...this.curves.map(e=>e.repr)].join(`
|
|
19
|
+
`)}get boundingBox(){return this._boundingBox||=wL(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=_A(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=DL(this.curves,OL(t,n,r));return new e(i)}scale(t,n){let r=n||this.boundingBox.center,i=DL(this.curves,ML(t,r));return new e(i)}rotate(t,n){let r=DL(this.curves,jL(t*JE,n));return new e(r)}translate(t,n=0){let r=tL(t)?t:[t,n],i=DL(this.curves,kL(r));return new e(i)}mirror(t,n=[0,0],r=`center`){let i=DL(this.curves,AL(t,n,r));return new e(i)}sketchOnPlane(e,t){let n=e&&typeof e!=`string`?{...e}:tO(e,t),r=TL(this.curves,n),i=LL(r);for(let e of r)e[Symbol.dispose]();return{wire:i,defaultOrigin:n.origin,defaultDirection:n.zDir}}sketchOnFace(e,t){let n=H(),r=j(NL(this.curves,e,t)),i=LL(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:EE(a),baseFace:e}}subFace(e,t){let n=AD(t||[...TO(e)]);return j(NA(this.translate(SO(e,n)).sketchOnFace(e,`original`).wire))}punchHole(e,t,{height:n=null,origin:r=null,draftAngle:i=0}={}){let a=j(eL(t,e)),o=this.subFace(a,r);return j(fO(H().draftPrism(e.wrapped,o.wrapped,a.wrapped,n,i,!1)))}toSVGPathD(){let e=this.clone().mirror([1,0],[0,0],`plane`),t=pL(e.curves).flatMap(e=>CL(e,e.lastPoint)),[n,r]=vA(e.curves).firstPoint;return`M ${iL(n)} ${iL(r)} ${t.join(` `)}${e.isClosed()?` Z`:``}`}toSVGPath(){return`<path d="${this.toSVGPathD()}" />`}toSVGViewBox(e=1){return FL(this.boundingBox,e)}toSVGPaths(){return[this.toSVGPathD()]}toSVG(e=1){return IL(this.toSVGPath(),this.boundingBox,e)}get firstPoint(){return vA(this.curves).firstPoint}get lastPoint(){return yA(this.curves).lastPoint}isInside(e){if(!this.boundingBox.containsPoint(e))return!1;let t=H(),n=mL(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=>DI(t,e,1e-9))||(r.push(e),i++);for(let e of a.segments)e.delete()}),!!(i%2)}finally{n.delete()}}isClosed(){return DI(this.firstPoint,this.lastPoint)}intersects(e){if(this.boundingBox.isOut(e.boundingBox))return!1;let t=H();for(let n of this.curves)for(let r of e.curves){if(n.boundingBox.isOut(r.boundingBox))continue;let e=t.intersectCurves2d(n.wrapped,r.wrapped,1e-9);if(e.points.length||e.segments.length)return!0}return!1}},zL=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)}},BL=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],VL=3,HL=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!==VL)throw Error(`Got v${a} data when expected v${VL}.`);let o=BL[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=BL.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,(VL<<4)+c]),new Uint16Array(n,2,1)[0]=t,new Uint32Array(n,4,1)[0]=e}this._queue=new zL}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)}WL(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,UL(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 UL(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 WL(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;GL(e,t,n,d,f)}o.push(i,f,f+1,r)}}function GL(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 qL=(e,t,n=1e-9)=>{if(e.boundingBox.isOut(t.boundingBox))return O({intersections:[],commonSegments:[],commonSegmentsPoints:[]});let r=wT(),i,a;try{let o=r.intersectCurves2d(e.wrapped,t.wrapped,n);i=o.points,a=o.segments.map(e=>new uL(e))}catch(e){return k(Eo(`INTERSECTION_FAILED`,`Intersections failed between curves`,e))}let o=a.filter(e=>DI(e.firstPoint,e.lastPoint,n)).map(e=>e.firstPoint);o.length&&(i.push(...o),a=a.filter(e=>!DI(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=wT(),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(Eo(`SELF_INTERSECTION_FAILED`,`Self intersection failed`,e))}return O(r)},YL=(e,n,r)=>{let i=BI(kI(n,e)),a=[i[1],-i[0]],o=[t(a,0)*r,t(a,1)*r];return{firstPoint:OI(e,o),lastPoint:OI(n,o)}},XL=(e,t)=>{let n=e.geomType,r=wT();if(n===`CIRCLE`){let n=r.getCurve2dCircleData(e.wrapped);if(!n)return mL(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]=BI(kI(e,t));return OI(e,[c*n,c*r])};return{collapsed:!0,firstPoint:n(e.firstPoint),lastPoint:n(e.lastPoint)}}let u=new uL(r.makeCircle2d(i,a,l,s)),d;try{d=r.trimCurve2d(u.wrapped,e.firstParameter,e.lastParameter)}finally{u.delete()}return new uL(d)}if(n===`LINE`){let{firstPoint:n,lastPoint:r}=YL(e.firstPoint,e.lastPoint,t);return mL(n,r)}let i=new uL(r.offsetCurve2d(e.wrapped,t)),a=dL(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 ZL(e,n,r){let i=NI(e.tangentAt(1),n.tangentAt(0));if(Math.abs(i)<1e-10)return null;let a=Math.abs(r)*(i>0?-1:1),o=XL(e,a),s=XL(n,a);if(!(o instanceof uL)||!(s instanceof uL))return null;let c=qL(o,s,1e-9);if(!Ja(c))return null;let l=c.value.intersections.at(-1);if(!tL(l))return null;let u=l,d=(e,t)=>{let[n,r]=t.tangentAt(u),i=BI([-r,n]),o=OI(u,AI(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 QL(e,t,n){let r=ZL(e,t,n);if(!r)return[e,t];let{first:i,second:a,center:o}=r;return[i,SL(i.lastPoint,a.firstPoint,o),a]}function $L(e,t,n){let r=ZL(e,t,n);if(!r)return[e,t];let{first:i,second:a}=r;return[i,mL(i.lastPoint,a.firstPoint),a]}function eR(e,n,r){let i=NI(BI(e.tangentAt(1)),BI(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=XL(e,s),l=XL(n,s);if(!(c instanceof uL)||!(l instanceof uL))return[e,n];let u=qL(c,l,1e-9);if(!Ja(u))return[e,n];let d=u.value.intersections.at(-1);if(!tL(d))return[e,n];let f=_L(r,d),p=j(qL(e,f)).intersections[0],m=j(qL(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[_,hL(_.lastPoint,e.lastPoint,v.firstPoint),v]}catch{return[e,n]}}var tR=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 cL;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 FL(this.boundingBox,e)}toSVGPaths(){return this.blueprints.map(e=>e.toSVGPaths())}toSVG(e=1){return IL(this.blueprints.map(e=>e instanceof RL?e.toSVGPath():e.toSVGGroup()).join(`
|
|
21
|
+
`),this.boundingBox,e)}},nR=class e{blueprints;_boundingBox;constructor(e){e.length===0&&i(`CompoundBlueprint`,`requires at least one blueprint (the outer boundary) — use createCompoundBlueprint() for Result-based validation`),this.blueprints=e,this._boundingBox=null}clone(){return new e(this.blueprints.map(e=>e.clone()))}get boundingBox(){if(!this._boundingBox){let e=new cL;this.blueprints.forEach(t=>{e.add(t.boundingBox)}),this._boundingBox=e}return this._boundingBox}get repr(){return[`Compound Blueprints`,`-- Outline`,vA(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 vA(this.blueprints).punchHole(e,t,n)}toSVGViewBox(e=1){return FL(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 IL(this.toSVGGroup(),this.boundingBox,e)}},rR=e=>{if(e.length===0)return[];if(e.length===1)return[[Ao(e,0,`groupByBoundingBoxOverlap`)]];let t=new HL(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(Ao(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(Ao(e,n,`groupByBoundingBoxOverlap`)),t.length&&t.forEach(e=>{i[e]=a})}),r},iR=e=>e.map((t,n)=>{let r=Ao(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))}}),aR=(e,t)=>e.flatMap(({blueprint:e})=>sR(t.filter(({blueprint:t,isIn:n})=>t===e||n.indexOf(e)!==-1))),oR=(e,t)=>[t.filter(({isIn:e})=>e.length<=1),...sR(iR(e.map(({blueprint:e})=>e)))],sR=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?aR(t,e):oR(n,e)},cR=e=>new tR(rR(e).map(iR).flatMap(sR).map(e=>e.length===1?Ao(e,0,`organiseBlueprints`).blueprint:(e.sort((e,t)=>e.isIn.length-t.isIn.length),new nR(e.map(({blueprint:e})=>e))))),lR=e=>e===`symmetric`||typeof e==`number`||Array.isArray(e)&&e.length===2,uR=e=>{let t;t=e?lR(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`?RI(1,n*JE):n;let s;return s=typeof a==`number`?RI(1,a*JE):a,{endTangent:o,startFactor:r,endFactor:i,startTangent:s}};function dR(e,t,n){return e<t?{majorRadius:t,minorRadius:e,rotationAngle:n+90}:{majorRadius:e,minorRadius:t,rotationAngle:n}}function fR(e,t,n,r,i,a,o,s){let c=i*JE,l=e=>jI(s(e)),u=l(RI(n,c)),d=l(RI(r,c+Math.PI/2)),f=BI(s(II([1,0],c))),[,p]=zI(f),{cx:m,cy:h,startAngle:g,endAngle:_,clockwise:v,rx:y,ry:b}=hR(e,t,u,d,p,a,o),x=yL(y,b,v?g:_,v?_:g,[m,h],f);return v||x.reverse(),x}function pR(e,t,n,r,i){let a=Math.PI*2,o=mR(1,0,e,t),s=mR(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 mR(e,t,n,r){let a=e*n+t*r,o=Math.sqrt((e*e+t*t)*(n*n+r*r));o<1e-12&&i(`radianAngle`,`Cannot compute angle between zero-length vectors`);let s=Math.acos(Math.max(-1,Math.min(1,a/o)));return e*r-t*n<0&&(s=-s),s}function hR([e,t],[n,r],a,o,s,c,l){a<0&&(a=-a),o<0&&(o=-o),(a<1e-10||o<1e-10)&&i(`convertSvgEllipseParams`,`rx and ry cannot be 0`);let u=Math.sin(s),d=Math.cos(s),f=(e-n)/2,p=(t-r)/2,m=(e+n)/2,h=(t+r)/2,g=d*f+u*p,_=d*p-u*f,v=g*g/(a*a)+_*_/(o*o);v>1&&(a*=Math.sqrt(v),o*=Math.sqrt(v));let y=a*o,b=a*_,x=o*g,S=b*b+x*x;S||i(`convertSvgEllipseParams`,`Start point cannot be same as end point`);let C=Math.sqrt(Math.abs((y*y-S)/S));c===l&&(C=-C);let w=C*b/o,ee=-C*x/a,te=d*w-u*ee+m,ne=u*w+d*ee+h,re=(g-w)/a,ie=(g+w)/a,{startAngle:ae,deltaAngle:oe,endAngle:se}=pR(re,(_-ee)/o,ie,(_+ee)/o,l);return{cx:te,cy:ne,startAngle:ae,deltaAngle:oe,endAngle:se,clockwise:l,rx:a,ry:o}}var gR={chamfer:$L,dogbone:eR,fillet:QL};function _R(e,t){if(typeof e==`function`)return e;let n=gR[t];return(t,r)=>n(t,r,e)}var vR=class{pointer;firstPoint;pendingCurves;_nextCorner;constructor(e=[0,0]){this.pointer=e,this.firstPoint=e,this._nextCorner=null,this.pendingCurves=[]}_convertToUV([e,t]){return[e,t]}_convertFromUV([e,t]){return[e,t]}_lastCurve(){let e=this.pendingCurves.length;return e===0?null:this.pendingCurves[e-1]}_requireLastCurve(e,t){let n=this._lastCurve();return n||i(e,`You need a previous curve to ${t}`),n}_resolveRelative(e,t){return[this.pointer[0]+e,this.pointer[1]+t]}_saveCurveAndAdvance(e,t){return this.saveCurve(e),this.pointer=t,this}get penPosition(){return this.pointer}get penAngle(){let e=this._lastCurve();if(!e)return 0;let[t,n]=e.tangentAt(1);return Math.atan2(n,t)*YE}movePointerTo(e){return this.pendingCurves.length&&i(`Sketcher2d.movePointerTo`,`You can only move the pointer if there is no curve defined`),this.pointer=e,this.firstPoint=e,this}saveCurve(e){if(!this._nextCorner){this.pendingCurves.push(e);return}let t=this.pendingCurves.pop();t||i(`Sketcher2d.saveCurve`,`No previous curve available for custom corner`),this.pendingCurves.push(...this._nextCorner(t,e)),this._nextCorner=null}lineTo(e){let t=mL(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(RI(e,t*JE))}polarLine(e,t){let[n,r]=RI(e,t*JE);return this.line(n,r)}tangentLine(e){let t=this._requireLastCurve(`Sketcher2d.tangentLine`,`sketch a tangent line`),n=BI(this._convertFromUV(t.tangentAt(1)));return this.line(n[0]*e,n[1]*e)}threePointsArcTo(e,t){let n=hL(this._convertToUV(this.pointer),this._convertToUV(t),this._convertToUV(e));return this._saveCurveAndAdvance(n,e)}threePointsArc(e,t,n,r){let[i,a]=this.pointer;return this.threePointsArcTo([i+e,a+t],[i+n,a+r])}sagittaArcTo(e,t){let[n,r]=this.pointer,[a,o]=e,s=(n+a)/2,c=(r+o)/2,l=-(o-r),u=a-n,d=Math.sqrt(l**2+u**2);d<1e-12&&i(`sagittaArcTo`,`Start and end points cannot be identical`);let f=[s+l/d*t,c+u/d*t],p=hL(this._convertToUV(this.pointer),this._convertToUV(f),this._convertToUV(e));return this._saveCurveAndAdvance(p,e)}sagittaArc(e,t,n){return this.sagittaArcTo(this._resolveRelative(e,t),n)}vSagittaArc(e,t){return this.sagittaArc(0,e,t)}hSagittaArc(e,t){return this.sagittaArc(e,0,t)}bulgeArcTo(e,t){if(!t)return this.lineTo(e);let n=jI(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=gL(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}=dR(t,n,r),l=fR(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=FI(e,this.pointer),i=jI(e,this.pointer);return this.ellipseTo(e,i/2,t,r*YE,!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=bL(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}=uR(t),o=this._lastCurve(),s=jI(this.pointer,e)*.25,c;c=r||(o?this._convertFromUV(o.tangentAt(1)):[1,0]),c=BI(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=BI(u);let d=[e[0]-u[0]*a*s,e[1]-u[1]*a*s];return this.cubicBezierCurveTo(e,l,d)}smoothSpline(e,t,n){return this.smoothSplineTo(this._resolveRelative(e,t),n)}customCorner(e,t=`fillet`){return this.pendingCurves.length||i(`Sketcher2d.customCorner`,`You need a curve defined to fillet the angle`),this._nextCorner=_R(e,t),this}_customCornerLastWithFirst(e,t=`fillet`){if(!e)return;let n=this.pendingCurves.pop(),r=this.pendingCurves.shift();(!n||!r)&&i(`Sketcher2d._customCornerLastWithFirst`,`Not enough curves to close and fillet`),this.pendingCurves.push(..._R(e,t)(n,r))}_closeSketch(){DI(this.pointer,this.firstPoint)||this.lineTo(this.firstPoint)}_closeWithMirror(){DI(this.pointer,this.firstPoint)&&i(`Sketcher2d._closeWithMirror`,`Cannot close with a mirror when the sketch is already closed`);let e=[this.pointer[0]-this.firstPoint[0],this.pointer[1]-this.firstPoint[1]],t=this._convertToUV(this.pointer),n=this._convertToUV(e),r=this.pendingCurves.map(e=>new uL(H().mirrorCurve2dAcrossAxis(e.wrapped,t[0],t[1],n[0],n[1])));r.reverse();for(let e of r)e.reverse();this.pendingCurves.push(...r),this.pointer=this.firstPoint}},yR=class extends vR{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new RL(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()}},bR=2*Math.PI;function xR(e){let t=e%bR,n=t<0?t+bR:t;return n<Math.PI?n:n===Math.PI?0:Math.abs(n-bR)}function SR(e){return e.curves.map((t,n)=>({firstCurve:t,secondCurve:_A(e.curves,(n+1)%e.curves.length),point:t.lastPoint}))}function CR(e){let t=t=>CR([...e,t]),n=t=>e.every(e=>e(t));return{shouldKeep:n,when:e=>t(e),inList:e=>t(t=>e.some(e=>DI(e,t.point))),atDistance:(e,n=[0,0])=>t(t=>Math.abs(jI(n,t.point)-e)<1e-9),atPoint:e=>t(t=>DI(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(xR(PI(n,r))-xR(JE*e))<1e-9}),not:e=>{let n=e(CR([]));return t(e=>!n.shouldKeep(e))},either:e=>{let n=e.map(e=>e(CR([])));return t(e=>n.some(t=>t.shouldKeep(e)))},find:e=>SR(e).filter(n)}}function wR(){return CR([])}var TR=(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=yA(r),a=new yR().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()},ER=(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 yR([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()},DR=(e,t)=>DI(e,t,wI);function OR(e){return`${e[0].toFixed(9)},${e[1].toFixed(9)}`}function kR(e,t){let n=OR(e),r=OR(t);return n<r?`${n}|${r}`:`${r}|${n}`}function AR(e){let t=e[0];return t===void 0&&i(`startOfSegment`,`empty segment`),t.firstPoint}function jR(e){let t=e[e.length-1];return t===void 0&&i(`endOfSegment`,`empty segment`),t.lastPoint}function MR(e){return[...e].reverse().map(e=>{let t=e.clone();return t.reverse(),t})}function NR(e){return[...e].reverse().map(MR)}function PR(e){let t=(e.lastParameter+e.firstParameter)/2;return e.value(t)}function FR(e,t){let n=OR(t);for(let r=0;r<e.length;r++){let i=e[r];if(i!==void 0&&OR(i.firstPoint)===n&&DR(t,i.firstPoint))return r}for(let n=0;n<e.length;n++){let r=e[n];if(r!==void 0&&DR(t,r.firstPoint))return n}return-1}function IR(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i];if(a!==void 0&&OR(a.firstPoint)===t&&OR(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 LR(e,t){return t<=0?e:e.slice(t).concat(e.slice(0,t))}function RR(e,t){return LR(e,FR(e,t))}function zR(e,t){let n=OR(t.firstPoint),r=OR(t.lastPoint),a=e=>DR(t.firstPoint,e.firstPoint)&&DR(t.lastPoint,e.lastPoint),o=e=>DR(t.lastPoint,e.firstPoint)&&DR(t.firstPoint,e.lastPoint);function s(e,t,n,r){let i=IR(e,t,n,r);return i===-1?null:LR(e,i)}let c=s(e,n,r,a);if(c!==null)return c;let l=s(e,r,n,o);if(l!==null)return l;let u=MR(e),d=s(u,n,r,a);if(d!==null)return d;let f=s(u,r,n,o);if(f!==null)return f;i(`rotateToStartAtSegment`,`failed to rotate to segment start`)}function*BR(e,t,n){let r=new Set(t.map(OR)),i=new Set(n.map(e=>kR(e.firstPoint,e.lastPoint))),a=e=>r.has(OR(e))?!0:t.some(t=>DR(t,e)),o=(e,t)=>i.has(kR(e,t))?!0:n.some(n=>DR(n.firstPoint,e)&&DR(n.lastPoint,t)||DR(n.firstPoint,t)&&DR(n.lastPoint,e)),s=[];for(let t of e){if(DR(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 VR(e,t,n){return e.filter(e=>{let r=t.filter(t=>DR(t.firstPoint,e)||DR(t.lastPoint,e)),i=r.length%2?r.filter(t=>!(DR(t.firstPoint,e)&&DR(t.lastPoint,e))):r;if(i.length===0||i.length%2)return!1;let a=i.map(e=>n.isInside(PR(e)));return!(a.every(Boolean)||a.every(e=>!e))})}function HR(e,n){let r=[],i=[],a=e.curves.map(()=>[]),o=n.curves.map(()=>[]),s=new HL(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(qL(e,t(n.curves,s),wI/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:sL(r,wI),allCommonSegments:i,firstCurvePoints:a,secondCurvePoints:o}}function UR(e,t){return xA([e,t]).flatMap(([e,t])=>t.length===0?[e]:e.splitAt(t,wI/100))}function WR(e,t,n){return e.some(([e,r])=>e===void 0||r===void 0?!1:DR(e,t)&&DR(r,n)||DR(e,n)&&DR(r,t))}function GR(e,t){let{allIntersections:n,allCommonSegments:r,firstCurvePoints:i,secondCurvePoints:a}=HR(e,t);if(n.length<=1)return null;let o=UR(e.curves,i),s=UR(t.curves,a),c=r.map(e=>[e.firstPoint,e.lastPoint]),l=VR(VR(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=RR(o,e),s=RR(s,e)}else{let e=r[0];if(e===void 0)return null;o=zR(o,e),s=zR(s,e)}let u=Array.from(BR(o,l,r)),d=Array.from(BR(s,l,r)),f=u[0],p=d[0];if(f!==void 0&&p!==void 0){let e=!DR(jR(p),jR(f)),t=r.length>0&&p.length!==1;(e||t)&&(d=NR(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}WR(c,AR(t),jR(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`||!DR(a,n.firstPoint))break;let r=kI(a,i.firstPoint),s=kI(n.lastPoint,n.firstPoint);if(Math.abs(NI(r,s))>1e-9)break;a=n.lastPoint,o++}o>r+1?n.push(mL(i.firstPoint,a)):n.push(i),r=o}return n}function qR(e){let t=e.map(e=>e.firstPoint),n=e.map(e=>e.lastPoint),r=xA([t,n.slice(-1).concat(n.slice(0,-1))]).map(([e,t],n)=>e===void 0||t===void 0||DR(e,t)?null:n).filter(e=>e!==null);if(r.length===0)return[e];let i=xA([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 YR(e,t,n,r,i,a,o){let s=[],c=0,l=e[0];if(l!==void 0){let t=PR(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=PR(u),r=n.isInside(e);if(i.secondInside===`keep`&&r||i.secondInside===`remove`&&!r){let e=t;c===1&&(e=MR(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 XR(e,t,n){let r=GR(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=JR(r,i,a);return i=e.segmentsIn,a=e.lastWasSame,e.curves}let s=YR(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=qR(KR(o)).filter(e=>e.length>0).map(e=>new RL(e));if(c.length===0)return null;if(c.length===1){let e=c[0];return e===void 0?null:e}return cR(c)}function ZR(e,t){let n=e.curves[0],r=t.curves[0];return{identical:!1,firstCurveInSecond:n!==void 0&&t.isInside(PR(n)),secondCurveInFirst:r!==void 0&&e.isInside(PR(r))}}function QR(e,t){let n=XR(e,t,{firstInside:`remove`,secondInside:`remove`});return n===null||n instanceof RL||n instanceof tR?n:n.identical?e.clone():n.firstCurveInSecond?t.clone():n.secondCurveInFirst?e.clone():new tR([e,t])}function $R(e,t){let n=XR(e,t,{firstInside:`remove`,secondInside:`keep`});return n===null||n instanceof RL||n instanceof tR?n:n.identical||n.firstCurveInSecond?null:n.secondCurveInFirst?new tR([new nR([e,t])]):e.clone()}function ez(e,t){let n=XR(e,t,{firstInside:`keep`,secondInside:`keep`});return n===null||n instanceof RL||n instanceof tR?n:n.identical||n.firstCurveInSecond?e.clone():n.secondCurveInFirst?t.clone():null}var tz=(e,t)=>{if(e instanceof RL&&t instanceof RL){let n=[];return e.curves.forEach(e=>{t.curves.forEach(t=>{let{intersections:r,commonSegmentsPoints:i}=j(qL(e,t));n.push(...r),n.push(...i)})}),n=sL(n),n.length>1}if(e instanceof nR||e instanceof tR)return e.blueprints.some(e=>tz(e,t));if(t instanceof nR||t instanceof tR)return t.blueprints.some(t=>tz(e,t));i(`genericIntersects`,`Unhandled shape combination in genericIntersects`)},nz=(e,t)=>{if(e instanceof nR){if(t instanceof RL)return az(t,e);if(t instanceof nR)return sz(e,t)}if(t instanceof nR){if(e instanceof RL)return az(e,t);if(e instanceof nR)return sz(e,t)}if(e instanceof RL&&t instanceof RL)return QR(e,t);i(`genericFuse`,`Unhandled shape combination in genericFuse`)},rz=e=>{let t=new Map,n=[];return e.forEach((r,a)=>{let o;t.has(a)?o=t.get(a):(o={current:r,fusedWith:new Set([a])},n.push(o)),e.slice(a+1).forEach((e,n)=>{let r=o.current,s=a+n+1;if(o.fusedWith.has(s))return;let c=e,l=!1;if(t.has(s)&&(c=t.get(s).current,l=!0),r.boundingBox.isOut(c.boundingBox)||!tz(r,c))return;let u;if(r instanceof tR||c instanceof tR){let e=cz(r,c);e===null&&i(`fuseIntersectingBlueprints`,`fuse2D returned null for non-null inputs`),u=e}else u=nz(r,c);if(!(u instanceof RL||u instanceof nR)){if(u instanceof tR&&u.blueprints.length===2)return;u instanceof tR&&u.blueprints.length===1?u=Ao(u.blueprints,0,`fuseIntersectingBlueprints`):u instanceof tR||i(`fuseIntersectingBlueprints`,`Fuse produced unexpected non-blueprint result`)}o.fusedWith.add(s),o.current=u,l||t.set(s,o)})}),cR(n.map(({current:e})=>e).flatMap(e=>iz(e)))},iz=e=>e instanceof RL?[e]:e instanceof nR?e.blueprints:e instanceof tR?e.blueprints.flatMap(e=>iz(e)):[],az=(e,t)=>{let n=QR(e,Ao(t.blueprints,0,`fuseBlueprintWithCompound`)),r=t.blueprints.slice(1).map(t=>$R(t,e));return cR([...iz(n),...r.flatMap(e=>iz(e))])};function oz(e,t){let n=[];for(let r of e)for(let e of t)n.push([r,e]);return n}var sz=(e,t)=>{let n=Ao(e.blueprints,0,`fuseCompoundWithCompound`),r=Ao(t.blueprints,0,`fuseCompoundWithCompound`),i=QR(n,r),a=t.blueprints.slice(1).map(e=>$R(e,n)),o=e.blueprints.slice(1).map(e=>$R(e,r)),s=oz(e.blueprints.slice(1),t.blueprints.slice(1)).flatMap(([e,t])=>iz(ez(e,t)));return cR([...iz(i),...a.flatMap(e=>iz(e)),...o.flatMap(e=>iz(e)),...s])},cz=(e,t)=>{if(e===null)return t?.clone()??null;if(t===null)return e.clone();if(!(e instanceof tR)&&t instanceof tR)return rz([e,...t.blueprints]);if(!(t instanceof tR)&&e instanceof tR)return rz([t,...e.blueprints]);if(e instanceof tR&&t instanceof tR){let n=cz(Ao(e.blueprints,0,`fuse2D`),t);return e.blueprints.slice(1).forEach(e=>{n=cz(e,n)}),n}if(e instanceof nR){if(t instanceof tR)return cz(t,e);if(t instanceof RL)return az(t,e);if(t instanceof nR)return sz(e,t)}if(t instanceof nR){if(e instanceof tR)return cz(e,t);if(e instanceof RL)return az(e,t);if(e instanceof nR)return sz(e,t)}return e instanceof RL&&t instanceof RL?QR(e,t):null},lz=e=>{let t=e.flatMap(e=>e===null?[]:e instanceof tR?e.blueprints:e);return t.length===1?Ao(t,0,`mergeNonIntersecting`):new tR(t)},uz=(e,t)=>{if(e===null)return null;if(t===null)return e.clone();if(e instanceof tR)return lz(e.blueprints.map(e=>uz(e,t)));if(e instanceof nR){let n=Ao(e.blueprints,0,`cut2D`);if(t instanceof RL&&!t.intersects(n))return n.isInside(t.firstPoint)?cR([n,...iz(cz(t,new tR(e.blueprints.slice(1))))]):e.clone();{let r=uz(n,t);return e.blueprints.slice(1).forEach(e=>{r=uz(r,e)}),r}}if(t instanceof tR){let n=e;for(let e of t.blueprints)n=uz(n,e);return n}if(t instanceof nR){let n=$R(e,Ao(t.blueprints,0,`cut2D`));return t.blueprints.slice(1).forEach(t=>{n=cz(n,ez(t,e))}),n}return $R(e,t)};function dz(e,t){if(e===null||t===null)return null;if(e instanceof RL&&t instanceof RL)return ez(e,t);if(e instanceof tR)return lz(e.blueprints.map(e=>dz(e,t)));if(e instanceof nR){let n=Ao(e.blueprints,0,`intersect2D`),r=e.blueprints.slice(1);if(r.length===0)return dz(n,t);let i=dz(n,t);for(let e of r)i=uz(i,e);return i}if(t instanceof tR)return lz(t.blueprints.map(t=>dz(e,t)));if(t instanceof nR){let n=Ao(t.blueprints,0,`intersect2D`),r=t.blueprints.slice(1);if(r.length===0)return dz(n,e);let i=dz(n,e);for(let e of r)i=uz(i,e);return i}i(`intersect2D`,`Unhandled Shape2D combination`)}var fz=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 fz=0,pz=-3;function mz(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function hz(e,t){this.source=e,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=t,this.destLen=0,this.ltree=new mz,this.dtree=new mz}var gz=new mz,_z=new mz,vz=new Uint8Array(30),yz=new Uint16Array(30),bz=new Uint8Array(30),xz=new Uint16Array(30),Sz=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Cz=new mz,wz=new Uint8Array(320);function Tz(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 Ez(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 Oz(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 kz(e){e.bitcount--||(e.tag=e.source[e.sourceIndex++],e.bitcount=7);var t=e.tag&1;return e.tag>>>=1,t}function Az(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 jz(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 Mz(e,t,n){var r=Az(e,5,257),i=Az(e,5,1),a=Az(e,4,4),o,s,c;for(o=0;o<19;++o)wz[o]=0;for(o=0;o<a;++o){var l=Az(e,3,0);wz[Sz[o]]=l}for(Oz(Cz,wz,0,19),s=0;s<r+i;){var u=jz(e,Cz);switch(u){case 16:var d=wz[s-1];for(c=Az(e,2,3);c;--c)wz[s++]=d;break;case 17:for(c=Az(e,3,3);c;--c)wz[s++]=0;break;case 18:for(c=Az(e,7,11);c;--c)wz[s++]=0;break;default:wz[s++]=u;break}}Oz(t,wz,0,r),Oz(n,wz,r,i)}function Nz(e,t,n){for(;;){var r=jz(e,t);if(r===256)return fz;if(r<256)e.dest[e.destLen++]=r;else{var i,a,o,s;for(r-=257,i=Az(e,vz[r],yz[r]),a=jz(e,n),o=e.destLen-Az(e,bz[a],xz[a]),s=o;s<o+i;++s)e.dest[e.destLen++]=e.dest[s]}}}function Pz(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 pz;for(e.sourceIndex+=4,r=t;r;--r)e.dest[e.destLen++]=e.source[e.sourceIndex++];return e.bitcount=0,fz}function Fz(e,t){var n=new hz(e,t),r,i,a;do{switch(r=kz(n),i=Az(n,2,0),i){case 0:a=Pz(n);break;case 1:a=Nz(n,gz,_z);break;case 2:Mz(n,n.ltree,n.dtree),a=Nz(n,n.ltree,n.dtree);break;default:a=pz}if(a!==fz)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}Ez(gz,_z),Tz(vz,yz,4,3),Tz(bz,xz,2,1),vz[28]=0,yz[28]=258;var Iz=Fz;function Lz(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 Rz(){this.x1=NaN,this.y1=NaN,this.x2=NaN,this.y2=NaN}Rz.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)},Rz.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))},Rz.prototype.addX=function(e){this.addPoint(e,null)},Rz.prototype.addY=function(e){this.addPoint(null,e)},Rz.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(Lz(c[f],l[f],u[f],d[f],g)),f===1&&this.addY(Lz(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(Lz(c[f],l[f],u[f],d[f],v)),f===1&&this.addY(Lz(c[f],l[f],u[f],d[f],v)));var y=(-p-Math.sqrt(_))/(2*m);0<y&&y<1&&(f===0&&this.addX(Lz(c[f],l[f],u[f],d[f],y)),f===1&&this.addY(Lz(c[f],l[f],u[f],d[f],y)))}}},Rz.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 zz(){this.commands=[],this.fill=`black`,this.stroke=null,this.strokeWidth=1}zz.prototype.moveTo=function(e,t){this.commands.push({type:`M`,x:e,y:t})},zz.prototype.lineTo=function(e,t){this.commands.push({type:`L`,x:e,y:t})},zz.prototype.curveTo=zz.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})},zz.prototype.quadTo=zz.prototype.quadraticCurveTo=function(e,t,n,r){this.commands.push({type:`Q`,x1:e,y1:t,x:n,y:r})},zz.prototype.close=zz.prototype.closePath=function(){this.commands.push({type:`Z`})},zz.prototype.extend=function(e){if(e.commands)e=e.commands;else if(e instanceof Rz){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)},zz.prototype.getBoundingBox=function(){for(var e=new Rz,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},zz.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())},zz.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},zz.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},zz.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 Bz(e){throw Error(e)}function Vz(e,t){e||Bz(t)}var K={fail:Bz,argument:Vz,assert:Vz},Hz=32768,Uz=2147483648,Wz={},q={},J={};function Gz(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=Gz(1),q.CHAR=function(e){return[e.charCodeAt(0)]},J.CHAR=Gz(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=Gz(2),q.SHORT=function(e){return e>=Hz&&(e=-(2*Hz-e)),[e>>8&255,e&255]},J.SHORT=Gz(2),q.UINT24=function(e){return[e>>16&255,e>>8&255,e&255]},J.UINT24=Gz(3),q.ULONG=function(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]},J.ULONG=Gz(4),q.LONG=function(e){return e>=Uz&&(e=-(2*Uz-e)),[e>>24&255,e>>16&255,e>>8&255,e&255]},J.LONG=Gz(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=Gz(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=Gz(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=Gz(3),q.NUMBER32=function(e){return[29,e>>24&255,e>>16&255,e>>8&255,e&255]},J.NUMBER32=Gz(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,Wz.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)},Wz.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 Kz={"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ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ`};Wz.MACSTRING=function(e,t,n,r){var i=Kz[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 qz=typeof WeakMap==`function`&&new WeakMap,Jz,Yz=function(e){if(!Jz)for(var t in Jz={},Kz)Jz[t]=new String(t);var n=Jz[e];if(n!==void 0){if(qz){var r=qz.get(n);if(r!==void 0)return r}var i=Kz[e];if(i!==void 0){for(var a={},o=0;o<i.length;o++)a[i.charCodeAt(o)]=o+128;return qz&&qz.set(n,a),a}}};q.MACSTRING=function(e,t){var n=Yz(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 Xz(e){return e>=-128&&e<=127}function Zz(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 Qz(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(!Xz(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 $z(e,t,n){for(var r=0,i=e.length,a=t;a<i&&r<64;){var o=e[a];if(o===0||Xz(o)&&a+1<i&&Xz(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?Zz(e,t,n):r>=-128&&r<=127?Qz(e,t,n):$z(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 eB=typeof WeakMap==`function`&&new WeakMap;q.CHARSTRING=function(e){if(eB){var t=eB.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 eB&&eB.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 tB(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)}}tB.prototype.encode=function(){return q.TABLE(this)},tB.prototype.sizeOf=function(){return J.TABLE(this)};function nB(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 rB(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 iB(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 aB(e){e.format===1?tB.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:1}].concat(nB(`glyph`,e.glyphs))):e.format===2?tB.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:2}].concat(iB(`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.`)}aB.prototype=Object.create(tB.prototype),aB.prototype.constructor=aB;function oB(e){tB.call(this,`scriptListTable`,iB(`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 tB(`scriptTable`,[{name:`defaultLangSys`,type:`TABLE`,value:new tB(`defaultLangSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:r.reqFeatureIndex}].concat(nB(`featureIndex`,r.featureIndexes)))}].concat(iB(`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 tB(`langSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:n.reqFeatureIndex}].concat(nB(`featureIndex`,n.featureIndexes)))}]})))}]}))}oB.prototype=Object.create(tB.prototype),oB.prototype.constructor=oB;function sB(e){tB.call(this,`featureListTable`,iB(`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 tB(`featureTable`,[{name:`featureParams`,type:`USHORT`,value:n.featureParams}].concat(nB(`lookupListIndex`,n.lookupListIndexes)))}]}))}sB.prototype=Object.create(tB.prototype),sB.prototype.constructor=sB;function cB(e,t){tB.call(this,`lookupListTable`,rB(`lookup`,e,function(e){var n=t[e.lookupType];return K.assert(!!n,`Unable to write GSUB lookup type `+e.lookupType+` tables.`),new tB(`lookupTable`,[{name:`lookupType`,type:`USHORT`,value:e.lookupType},{name:`lookupFlag`,type:`USHORT`,value:e.lookupFlag}].concat(rB(`subtable`,e.subtables,n)))}))}cB.prototype=Object.create(tB.prototype),cB.prototype.constructor=cB;var Y={Table:tB,Record:tB,Coverage:aB,ScriptList:oB,FeatureList:sB,LookupList:cB,ushortList:nB,tableList:rB,recordList:iB};function lB(e,t){return e.getUint8(t)}function uB(e,t){return e.getUint16(t,!1)}function dB(e,t){return e.getInt16(t,!1)}function fB(e,t){return e.getUint32(t,!1)}function pB(e,t){return e.getInt16(t,!1)+e.getUint16(t+2,!1)/65535}function mB(e,t){for(var n=``,r=t;r<t+4;r+=1)n+=String.fromCharCode(e.getInt8(r));return n}function hB(e,t,n){for(var r=0,i=0;i<n;i+=1)r<<=8,r+=e.getUint8(t+i);return r}function gB(e,t,n){for(var r=[],i=t;i<n;i+=1)r.push(e.getUint8(i));return r}function _B(e){for(var t=``,n=0;n<e.length;n+=1)t+=String.fromCharCode(e[n]);return t}var vB={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=fB(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,e},X.prototype.parseOffset32=X.prototype.parseULong,X.prototype.parseFixed=function(){var e=pB(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=fB(this.data,this.offset+this.relativeOffset+4);return e-=2082844800,this.relativeOffset+=8,e},X.prototype.parseVersion=function(e){var t=uB(this.data,this.offset+this.relativeOffset),n=uB(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+=vB[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 yB={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(yB),langSysRecords:X.recordList({tag:X.tag,langSys:X.pointer(yB)})})}))||[]},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:lB,getCard8:lB,getUShort:uB,getCard16:uB,getShort:dB,getULong:fB,getFixed:pB,getTag:mB,getOffset:hB,getBytes:gB,bytesToString:_B,Parser:X};function bB(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 xB(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 SB(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)bB(n,s);else if(n.format===4)xB(n,s,e,t,r);else throw Error(`Only format 4 and 12 cmap tables are supported (found format `+n.format+`).`);return n}function CB(e,t,n){e.segments.push({end:t,start:t,delta:-(t-n),offset:0,glyphIndex:n})}function wB(e){e.segments.push({end:65535,start:65535,delta:1,offset:0})}function TB(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)CB(i,a.unicodes[o],n);i.segments=i.segments.sort(function(e,t){return e.start-t.start})}wB(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 EB={parse:SB,make:TB},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(`,`),OB=`................................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(`.`),kB=`................................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(`.`),AB=`.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 jB(e){this.font=e}jB.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 MB(e){this.cmap=e}MB.prototype.charToGlyphIndex=function(e){return this.cmap.glyphIndexMap[e.codePointAt(0)]||0};function NB(e,t){this.encoding=e,this.charset=t}NB.prototype.charToGlyphIndex=function(e){var t=e.codePointAt(0),n=this.encoding[t];return this.charset.indexOf(n)};function PB(e){switch(e.version){case 1:this.names=AB.slice();break;case 2:this.names=Array(e.numberOfGlyphs);for(var t=0;t<e.numberOfGlyphs;t++)e.glyphNameIndex[t]<AB.length?this.names[t]=AB[e.glyphNameIndex[t]]:this.names[t]=e.names[e.glyphNameIndex[t]-AB.length];break;case 2.5:this.names=Array(e.numberOfGlyphs);for(var n=0;n<e.numberOfGlyphs;n++)this.names[n]=AB[n+e.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}PB.prototype.nameToGlyphIndex=function(e){return this.names.indexOf(e)},PB.prototype.glyphIndexToName=function(e){return this.names[e]};function FB(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 IB(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 LB(e,t){t.lowMemory?IB(e):FB(e)}function RB(e,t,n,r,i){e.beginPath(),e.moveTo(t,n),e.lineTo(r,i),e.stroke()}var zB={line:RB};function BB(e,t){var n=t||new zz;return{configurable:!0,get:function(){return typeof n==`function`&&(n=n()),n},set:function(e){n=e}}}function VB(e){this.bindConstructorValues(e)}VB.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",BB(this,e.path))},VB.prototype.addUnicode=function(e){this.unicodes.length===0&&(this.unicode=e),this.unicodes.push(e)},VB.prototype.getBoundingBox=function(){return this.path.getBoundingBox()},VB.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 zz,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},VB.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},VB.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},VB.prototype.draw=function(e,t,n,r,i){this.getPath(t,n,r,i).draw(e)},VB.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)},VB.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`,zB.line(e,t,-1e4,t,1e4),zB.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`,zB.line(e,t+a*i,-1e4,t+a*i,1e4),zB.line(e,t+s*i,-1e4,t+s*i,1e4),zB.line(e,-1e4,n+-o*i,1e4,n+-o*i),zB.line(e,-1e4,n+-c*i,1e4,n+-c*i),e.strokeStyle=`green`,zB.line(e,t+l*i,-1e4,t+l*i,1e4)};function HB(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 UB(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}UB.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]},UB.prototype.push=function(e,t){this.glyphs[e]=t,this.length++};function WB(e,t){return new VB({index:t,font:e})}function GB(e,t,n,r,i,a){return function(){var o=new VB({index:t,font:e});return o.path=function(){n(o,r,i);var t=a(e.glyphs,o);return t.unitsPerEm=e.unitsPerEm,t},HB(o,`xMin`,`_xMin`),HB(o,`xMax`,`_xMax`),HB(o,`yMin`,`_yMin`),HB(o,`yMax`,`_yMax`),o}}function KB(e,t,n,r){return function(){var i=new VB({index:t,font:e});return i.path=function(){var t=n(e,i,r);return t.unitsPerEm=e.unitsPerEm,t},i}}var qB={GlyphSet:UB,glyphLoader:WB,ttfGlyphLoader:GB,cffGlyphLoader:KB};function JB(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(!JB(e[n],t[n]))return!1;return!0}else return!1}function YB(e){return e.length<1240?107:e.length<33900?1131:32768}function XB(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 ZB(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 QB(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 $B(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 eV(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 $B(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 tV(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 nV(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(eV(r,o))}return tV(i)}function rV(e,t){return t=t<=390?DB[t]:e[t-391],t}function iV(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=rV(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=rV(n,i)),r[o.name]=i}return r}function aV(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 oV=[{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`}],sV=[{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 cV(e,t){return iV(nV(e,0,e.byteLength),oV,t)}function lV(e,t,n,r){return iV(nV(e,t,n),sV,r)}function uV(e,t,n,r){for(var i=[],a=0;a<n.length;a+=1){var o=cV(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=lV(e,c+t,s,r);o._defaultWidthX=l.defaultWidthX,o._nominalWidthX=l.nominalWidthX,l.subrs!==0&&(o._subrs=XB(e,c+l.subrs+t).objects,o._subrsBias=YB(o._subrs)),o._privateDict=l}i.push(o)}return i}function dV(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(rV(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(rV(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(rV(r,i)),i+=1}else throw Error(`Unknown charset format `+c);return s}function fV(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 NB(i,n)}function pV(e,t,n){var r,i,a,o,s=new zz,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 mV(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 hV(e,t,n,r){n.tables.cff={};var i=XB(e,XB(e,aV(e,t).endOffset,Z.bytesToString).endOffset),a=XB(e,i.endOffset,Z.bytesToString);n.gsubrs=XB(e,a.endOffset).objects,n.gsubrsBias=YB(n.gsubrs);var o=uV(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=uV(e,t,XB(e,c).objects,a.objects);s._fdArray=u,l+=t,s._fdSelect=mV(e,l,n.numGlyphs,u.length)}var d=t+s.private[1],f=lV(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=XB(e,d+f.subrs).objects,n.subrsBias=YB(n.subrs));var p;r.lowMemory?(p=ZB(e,t+s.charStrings),n.nGlyphs=p.offsets.length):(p=XB(e,t+s.charStrings),n.nGlyphs=p.objects.length);var m=dV(e,t+s.charset,n.nGlyphs,a.objects);if(s.encoding===0?n.cffEncoding=new NB(OB,m):s.encoding===1?n.cffEncoding=new NB(kB,m):n.cffEncoding=fV(e,t+s.encoding,m),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new qB.GlyphSet(n),r.lowMemory)n._push=function(r){var i=QB(r,p.offsets,e,t+s.charStrings);n.glyphs.push(r,qB.cffGlyphLoader(n,r,pV,i))};else for(var h=0;h<n.nGlyphs;h+=1){var g=p.objects[h];n.glyphs.push(h,qB.cffGlyphLoader(n,h,pV,g))}}function gV(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 _V(){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 vV(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 yV(e,t,n){for(var r={},i=0;i<e.length;i+=1){var a=e[i],o=t[a.name];o!==void 0&&!JB(o,a.value)&&(a.type===`SID`&&(o=gV(o,n)),r[a.op]={name:a.name,type:a.type,value:o})}return r}function bV(e,t){var n=new Y.Record(`Top DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=yV(oV,e,t),n}function xV(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 SV(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 CV(){return new Y.Record(`Global Subr INDEX`,[{name:`subrs`,type:`INDEX`,value:[]}])}function wV(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=gV(i,t);n.fields.push({name:`glyph_`+r,type:`SID`,value:a})}return n}function TV(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 EV(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=TV(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=yV(sV,e,t),n}function OV(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=_V(),n.nameIndex=vV([t.postScriptName]);var u=bV(i,l);return n.topDictIndex=xV(u),n.globalSubrIndex=CV(),n.charsets=wV(o,l),n.charStringsIndex=EV(e),n.privateDict=DV(a,l),n.stringIndex=SV(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=bV(i,l),n.topDictIndex=xV(u),n}var kV={parse:hV,make:OV};function AV(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 jV(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 MV={parse:AV,make:jV};function NV(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 PV(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 FV={parse:NV,make:PV};function IV(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 LV(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 RV(e,t,n,r,i,a,o){o.lowMemory?LV(e,t,n,r,i):IV(t,n,r,i,a)}function zV(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 BV={parse:RV,make:zV};function VV(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 HV(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 UV={make:VV,parse:HV};function WV(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 GV(e){return new Y.Table(`maxp`,[{name:`version`,type:`FIXED`,value:20480},{name:`numGlyphs`,type:`USHORT`,value:e}])}var KV={parse:WV,make:GV},qV=[`copyright`,`fontFamily`,`fontSubfamily`,`uniqueID`,`fullName`,`version`,`postScriptName`,`trademark`,`manufacturer`,`designer`,`description`,`manufacturerURL`,`designerURL`,`license`,`licenseURL`,`reserved`,`preferredFamily`,`preferredSubfamily`,`compatibleFullName`,`sampleText`,`postScriptFindFontName`,`wwsFamily`,`wwsSubfamily`],JV={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`},YV={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},XV={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 ZV(e,t,n){switch(e){case 0:if(t===65535)return`und`;if(n)return n[t];break;case 1:return JV[t];case 3:return XV[t]}}var QV=`utf-16`,$V={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`},eH={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 tH(e,t,n){switch(e){case 0:return QV;case 1:return eH[n]||$V[t];case 3:if(t===1||t===10)return QV;break}}function nH(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=qV[f]||f,m=i.parseUShort(),h=i.parseUShort(),g=ZV(l,d,n),_=tH(l,u,d);if(_!==void 0&&g!==void 0){var v=void 0;if(v=_===QV?Wz.UTF16(e,s+h,m):Wz.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 rH(e){var t={};for(var n in e)t[e[n]]=parseInt(n);return t}function iH(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 aH(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 oH(e,t){var n=aH(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 sH(e,t){var n,r=[],i={},a=rH(qV);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=rH(JV),l=rH(XV),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=YV[_],y=tH(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=oH(b,d);u.push(iH(g,v,_,n,b.length,x));var S=l[m];if(S!==void 0){var C=q.UTF16(h),w=oH(C,d);u.push(iH(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 cH={parse:nH,make:sH},lH=[{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 uH(e){for(var t=0;t<lH.length;t+=1){var n=lH[t];if(e>=n.begin&&e<n.end)return t}return-1}function dH(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 fH(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 pH={parse:dH,make:fH,unicodeRanges:lH,getUnicodeRange:uH};function mH(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=AB.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]>=AB.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 hH(){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 gH={parse:mH,make:hH},_H=Array(9);_H[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.`)},_H[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()}},_H[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()}},_H[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 vH={sequenceIndex:X.uShort,lookupListIndex:X.uShort};_H[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,vH)}})};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,vH)}})};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,vH)}}K.assert(!1,`0x`+e.toString(16)+`: lookup type 5 format must be 1, 2 or 3.`)},_H[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(vH)}})};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(vH)}})};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(vH)};K.assert(!1,`0x`+e.toString(16)+`: lookup type 6 format must be 1, 2 or 3.`)},_H[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:_H[t].call(n)}},_H[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 yH(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(_H)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(_H),variations:n.parseFeatureVariationsList()}}var bH=Array(9);bH[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)))},bH[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))})))},bH[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))})))},bH[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)))}))})))},bH[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 xH(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,bH)}])}var SH={parse:yH,make:xH};function CH(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]=Wz.UTF8(e,t+c,l)}return a}function wH(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 TH={parse:CH,make:wH};function EH(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 OH(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 kH(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**EH(t.numTables);t.searchRange=16*n,t.entrySelector=EH(n),t.rangeShift=t.numTables*16-t.searchRange;for(var r=[],i=[],a=t.sizeOf()+OH().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=OH(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 AH(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 jH(e){for(var t=0,n=0;n<e.length;n+=1)t+=e[n];return t/e.length}function MH(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 _=pH.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:jH(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=MV.make({flags:3,unitsPerEm:e.unitsPerEm,xMin:y.xMin,yMin:y.yMin,xMax:y.xMax,yMax:y.yMax,lowestRecPPEM:3,createdTimestamp:e.createdTimestamp}),x=FV.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=KV.make(e.glyphs.length),C=pH.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:AH(e,`xyvw`,{yMax:Math.round(y.ascender/2)}).yMax,sCapHeight:AH(e,`HIKLEFJMNTZBDPRAGOQSUVWXY`,y).yMax,usDefaultChar:e.hasChar(` `)?32:0,usBreakChar:e.hasChar(` `)?32:0},e.tables.os2)),w=BV.make(e.glyphs),ee=EB.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=cH.make(ae,se),le=se.length>0?UV.make(se):void 0,ue=gH.make(),de=kV.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?TH.make(e.metas):void 0,pe=[b,x,S,C,ce,ee,ue,de,w];le&&pe.push(le),e.tables.gsub&&pe.push(SH.make(e.tables.gsub)),fe&&pe.push(fe);for(var me=kH(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 NH={make:kH,fontToTable:MH,computeCheckSum:DH};function PH(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 FH(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 IH(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 LH(e,t){this.font=e,this.tableName=t}LH.prototype={searchTag:PH,binSearch:FH,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=PH(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=PH(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=IH(e.ranges,t);return n?n.classId:0}},getCoverageIndex:function(e,t){switch(e.format){case 1:var n=FH(e.glyphs,t);return n>=0?n:-1;case 2:var r=IH(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 RH(e){LH.call(this,e,`gpos`)}RH.prototype=LH.prototype,RH.prototype.init=function(){var e=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(e)},RH.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},RH.prototype.getKerningTables=function(e,t){if(this.font.tables.gpos)return this.getLookupTables(e,t,`kern`,2)};function zH(e){LH.call(this,e,`gsub`)}function BH(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 VH(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}zH.prototype=LH.prototype,zH.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:`DFLT`,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}},zH.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},zH.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},zH.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},zH.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},zH.prototype.addSingle=function(e,t,n,r){var i=this.getLookupTables(n,r,e,1,!0)[0],a=VH(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},zH.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=VH(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},zH.prototype.addAlternate=function(e,t,n,r){var i=this.getLookupTables(n,r,e,3,!0)[0],a=VH(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},zH.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(BH(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])},zH.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)}},zH.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 HH(){return typeof window<`u`}function UH(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 WH(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 GH(e,t){if(!e)throw t}function KH(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 qH(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=KH(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=KH(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 JH(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 YH(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 XH(e){var t=new zz;if(!e)return t;for(var n=YH(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 ZH(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=JH(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=JH([s],c)[0],c.dx=o.x-s.x,c.dy=o.y-s.y,a=JH(i.points,c)}t.points=t.points.concat(a)}}return XH(t.points)}function QH(e,t,n,r){for(var i=new qB.GlyphSet(r),a=0;a<n.length-1;a+=1){var o=n[a];o===n[a+1]?i.push(a,qB.glyphLoader(r,a)):i.push(a,qB.ttfGlyphLoader(r,a,qH,e,t+o,ZH))}return i}function $H(e,t,n,r){var i=new qB.GlyphSet(r);return r._push=function(a){var o=n[a];o===n[a+1]?i.push(a,qB.glyphLoader(r,a)):i.push(a,qB.ttfGlyphLoader(r,a,qH,e,t+o,ZH))},i}function eU(e,t,n,r,i){return i.lowMemory?$H(e,t,n,r):QH(e,t,n,r)}var tU={getPath:XH,parse:eU},nU,rU,iU,aU;function oU(e){this.font=e,this.getCommands=function(e){return tU.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function sU(e){return e}function cU(e){return Math.sign(e)*Math.round(Math.abs(e))}function lU(e){return Math.sign(e)*Math.round(Math.abs(e*2))/2}function uU(e){return Math.sign(e)*(Math.round(Math.abs(e)+.5)-.5)}function dU(e){return Math.sign(e)*Math.ceil(Math.abs(e))}function fU(e){return Math.sign(e)*Math.floor(Math.abs(e))}var pU=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},mU={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){mU.setRelative(e,e,(c+l)/2,r,!0);return}mU.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}},hU={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){hU.setRelative(e,e,(c+l)/2,r,!0);return}hU.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(mU),Object.freeze(hU);function gU(e,t){this.x=e,this.y=t,this.axis=void 0,this.slope=t/e,this.normalSlope=-e/t,Object.freeze(this)}gU.prototype.distance=function(e,t,n,r){return this.x*mU.distance(e,t,n,r)+this.y*hU.distance(e,t,n,r)},gU.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)},gU.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},gU.prototype.touch=function(e){e.xTouched=!0,e.yTouched=!0};function _U(e,t){var n=Math.sqrt(e*e+t*t);return e/=n,t/=n,e===1&&t===0?mU:e===0&&t===1?hU:new gU(e,t)}function vU(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)}vU.prototype.nextTouched=function(e){for(var t=this.nextPointOnContour;!e.touched(t)&&t!==this;)t=t.nextPointOnContour;return t},vU.prototype.prevTouched=function(e){for(var t=this.prevPointOnContour;!e.touched(t)&&t!==this;)t=t.prevPointOnContour;return t};var yU=Object.freeze(new vU(0,0)),bU={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function xU(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=mU,this.round=cU}}oU.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){xU.prototype=bU,i=this._fpgmState=new xU(`fpgm`,n.tables.fpgm),i.funcs=[],i.font=n,exports.DEBUG&&(console.log(`---EXEC FPGM---`),i.step=-1);try{rU(i)}catch(e){console.log(`Hinting error in FPGM:`+e),this._errorState=3;return}}xU.prototype=i,r=this._prepState=new xU(`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{rU(r)}catch(e){this._errorState<2&&console.log(`Hinting error in PREP:`+e),this._errorState=2}}if(!(this._errorState>1))try{return iU(e,r)}catch(e){this._errorState<1&&(console.log(`Hinting error:`+e),console.log(`Note: further hinting errors are silenced`)),this._errorState=1;return}}},iU=function(e,t){var n=t.ppem/t.font.unitsPerEm,r=n,i=e.components,a,o,s;if(xU.prototype=t,!i)s=new xU(`glyf`,e.instructions),exports.DEBUG&&(console.log(`---EXEC GLYPH---`),s.step=-1),aU(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 xU(`glyf`,d.instructions),exports.DEBUG&&(console.log(`---EXEC COMP `+l+`---`),s.step=-1),aU(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 xU(`glyf`,e.instructions),s.gZone=s.z0=s.z1=s.z2=o,s.contours=a,o.push(new vU(0,0),new vU(Math.round(e.advanceWidth*n),0)),exports.DEBUG&&(console.log(`---EXEC COMPOSITE---`),s.step=-1),rU(s),o.length-=2)}return o},aU=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 vU(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 vU(0,0),new vU(Math.round(e.advanceWidth*n),0)),rU(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)}}},rU=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=nU[t[e.ip]],!r)throw Error(`unknown instruction: 0x`+Number(t[e.ip]).toString(16));r(e)}}};function SU(e){for(var t=e.tZone=Array(e.gZone.length),n=0;n<t.length;n++)t[n]=new vU(0,0)}function CU(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 wU(e,t){exports.DEBUG&&console.log(t.step,`SVTCA[`+e.axis+`]`),t.fv=t.pv=t.dpv=e}function TU(e,t){exports.DEBUG&&console.log(t.step,`SPVTCA[`+e.axis+`]`),t.pv=t.dpv=e}function EU(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=_U(s,c)}function OU(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=_U(s,c)}function kU(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.pv=e.dpv=_U(r,n)}function AU(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.fv=_U(r,n)}function jU(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 MU(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 NU(e){e.fv=e.pv,exports.DEBUG&&console.log(e.step,`SFVTPV[]`)}function PU(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 FU(e){e.rp0=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP0[]`,e.rp0)}function IU(e){e.rp1=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP1[]`,e.rp1)}function LU(e){e.rp2=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP2[]`,e.rp2)}function RU(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP0[]`,t),e.zp0=t,t){case 0:e.tZone||SU(e),e.z0=e.tZone;break;case 1:e.z0=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function zU(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP1[]`,t),e.zp1=t,t){case 0:e.tZone||SU(e),e.z1=e.tZone;break;case 1:e.z1=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function BU(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP2[]`,t),e.zp2=t,t){case 0:e.tZone||SU(e),e.z2=e.tZone;break;case 1:e.z2=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function VU(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||SU(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 HU(e){e.loop=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SLOOP[]`,e.loop)}function UU(e){exports.DEBUG&&console.log(e.step,`RTG[]`),e.round=cU}function WU(e){exports.DEBUG&&console.log(e.step,`RTHG[]`),e.round=uU}function GU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SMD[]`,t),e.minDis=t/64}function KU(e){exports.DEBUG&&console.log(e.step,`ELSE[]`),CU(e,!1)}function qU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`JMPR[]`,t),e.ip+=t-1}function JU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCVTCI[]`,t),e.cvCutIn=t/64}function YU(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DUP[]`),t.push(t[t.length-1])}function XU(e){exports.DEBUG&&console.log(e.step,`POP[]`),e.stack.pop()}function ZU(e){exports.DEBUG&&console.log(e.step,`CLEAR[]`),e.stack.length=0}function QU(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 $U(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DEPTH[]`),t.push(t.length)}function eW(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++)rU(e),exports.DEBUG&&console.log(++e.step,o+1<r?`next loopcall`:`done loopcall`,o);e.ip=i,e.prog=a}function tW(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],rU(e),e.ip=n,e.prog=r,exports.DEBUG&&console.log(++e.step,`returning from`,t)}function nW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CINDEX[]`,n),t.push(t[t.length-n])}function rW(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 iW(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 aW(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,yU);e&&(o=t.round(o)),i.setRelative(r,yU,o,a),i.touch(r),t.rp0=t.rp1=n}function oW(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 sW(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 cW(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 lW(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 uW(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 dW(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 fW(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 pW(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 mW(e){exports.DEBUG&&console.log(e.step,`RTDG[]`),e.round=lU}function hW(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,yU);e&&(Math.abs(l-c)<t.cvCutIn&&(l=c),l=t.round(l)),o.setRelative(a,yU,l,s),t.zp0===0&&(a.xo=a.x,a.yo=a.y),o.touch(a),t.rp0=t.rp1=i}function gW(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 _W(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 vW(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 yW(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 bW(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 xW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`RCVT`,n),t.push(e.cvt[n]*64)}function SW(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,yU,e,!1)*64)}function CW(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 wW(e){exports.DEBUG&&console.log(e.step,`MPPEM[]`),e.stack.push(e.ppem)}function TW(e){exports.DEBUG&&console.log(e.step,`FLIPON[]`),e.autoFlip=!0}function EW(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 OW(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 kW(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 AW(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 jW(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 MW(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 NW(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 PW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`IF[]`,t),t||(CU(e,!0),exports.DEBUG&&console.log(e.step,`EIF[]`))}function FW(e){exports.DEBUG&&console.log(e.step,`EIF[]`)}function IW(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 LW(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 RW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NOT[]`,n),t.push(+!n)}function zW(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 BW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDB[]`,t),e.deltaBase=t}function VW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDS[]`,t),e.deltaShift=.5**t}function HW(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 UW(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 WW(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 GW(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 KW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`ABS[]`,n),t.push(Math.abs(n))}function qW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NEG[]`,n),t.push(-n)}function JW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`FLOOR[]`,n),t.push(Math.floor(n/64)*64)}function YW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CEILING[]`,n),t.push(Math.ceil(n/64)*64)}function XW(e,t){var n=t.stack,r=n.pop();exports.DEBUG&&console.log(t.step,`ROUND[]`),n.push(t.round(r/64)*64)}function ZW(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 QW(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 $W(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SROUND[]`,t),e.round=pU;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 eG(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`S45ROUND[]`,t),e.round=pU;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 tG(e){exports.DEBUG&&console.log(e.step,`ROFF[]`),e.round=sU}function nG(e){exports.DEBUG&&console.log(e.step,`RUTG[]`),e.round=dU}function rG(e){exports.DEBUG&&console.log(e.step,`RDTG[]`),e.round=fU}function iG(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANCTRL[]`,t)}function aG(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=_U(s,c)}function oG(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 sG(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 cG(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 lG(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 uG(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANTYPE[]`,t)}function dG(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 fG(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 pG(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)}nU=[wU.bind(void 0,hU),wU.bind(void 0,mU),TU.bind(void 0,hU),TU.bind(void 0,mU),EU.bind(void 0,hU),EU.bind(void 0,mU),DU.bind(void 0,0),DU.bind(void 0,1),OU.bind(void 0,0),OU.bind(void 0,1),kU,AU,jU,MU,NU,PU,FU,IU,LU,RU,zU,BU,VU,HU,UU,WU,GU,KU,qU,JU,void 0,void 0,YU,XU,ZU,QU,$U,nW,rW,void 0,void 0,void 0,eW,tW,iW,void 0,aW.bind(void 0,0),aW.bind(void 0,1),oW.bind(void 0,hU),oW.bind(void 0,mU),sW.bind(void 0,0),sW.bind(void 0,1),cW.bind(void 0,0),cW.bind(void 0,1),lW.bind(void 0,0),lW.bind(void 0,1),uW,dW,fW.bind(void 0,0),fW.bind(void 0,1),pW,mW,hW.bind(void 0,0),hW.bind(void 0,1),gW,_W,vW,yW,bW,xW,SW.bind(void 0,0),SW.bind(void 0,1),void 0,CW.bind(void 0,0),CW.bind(void 0,1),wW,void 0,TW,void 0,void 0,EW,DW,OW,kW,AW,jW,MW,NW,PW,FW,IW,LW,RW,zW.bind(void 0,1),BW,VW,HW,UW,WW,GW,KW,qW,JW,YW,XW.bind(void 0,0),XW.bind(void 0,1),XW.bind(void 0,2),XW.bind(void 0,3),void 0,void 0,void 0,void 0,ZW,zW.bind(void 0,2),zW.bind(void 0,3),QW.bind(void 0,1),QW.bind(void 0,2),QW.bind(void 0,3),$W,eG,void 0,void 0,tG,void 0,nG,rG,XU,XU,void 0,void 0,void 0,void 0,void 0,iG,aG.bind(void 0,0),aG.bind(void 0,1),oG,void 0,sG,cG,lG,uG,dG,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,fG.bind(void 0,1),fG.bind(void 0,2),fG.bind(void 0,3),fG.bind(void 0,4),fG.bind(void 0,5),fG.bind(void 0,6),fG.bind(void 0,7),fG.bind(void 0,8),pG.bind(void 0,1),pG.bind(void 0,2),pG.bind(void 0,3),pG.bind(void 0,4),pG.bind(void 0,5),pG.bind(void 0,6),pG.bind(void 0,7),pG.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 mG(e){this.char=e,this.state={},this.activeState=null}function hG(e,t,n){this.contextName=n,this.startIndex=e,this.endOffset=t}function gG(e,t,n){this.contextName=e,this.openRange=null,this.ranges=[],this.checkStart=t,this.checkEnd=n}function _G(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 vG(e){this.eventId=e,this.subscribers=[]}function yG(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 vG(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 bG(e){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],yG.call(this,e)}mG.prototype.setState=function(e,t){return this.state[e]=t,this.activeState={key:e,value:this.state[e]},this.activeState},mG.prototype.getState=function(e){return this.state[e]||null},bG.prototype.inboundIndex=function(e){return e>=0&&e<this.tokens.length},bG.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)})])},bG.prototype.replaceRange=function(e,t,n,r){t=t===null?this.tokens.length:t;var i=n.every(function(e){return e instanceof mG});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.`}},bG.prototype.replaceToken=function(e,t,n){if(!isNaN(e)&&this.inboundIndex(e)&&t instanceof mG){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.`}},bG.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},bG.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.`}},bG.prototype.insertToken=function(e,t,n){return e.every(function(e){return e instanceof mG})?(this.tokens.splice.apply(this.tokens,[t,0].concat(e)),n||this.dispatch(`insertToken`,[e,t]),e):{FAIL:`insertToken: invalid token(s).`}},bG.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)},vG.prototype.subscribe=function(e){return typeof e==`function`?this.subscribers.push(e)-1:{FAIL:`invalid '`+this.eventId+`' event handler`}},vG.prototype.unsubscribe=function(e){this.subscribers.splice(e,1)},_G.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)},_G.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}},bG.prototype.rangeToText=function(e){if(e instanceof hG)return this.getRangeTokens(e).map(function(e){return e.char}).join(``)},bG.prototype.getText=function(){return this.tokens.map(function(e){return e.char}).join(``)},bG.prototype.getContext=function(e){return this.registeredContexts[e]||null},bG.prototype.on=function(e,t){var n=this.events[e];return n?n.subscribe(t):null},bG.prototype.dispatch=function(e,t){var n=this,r=this.events[e];r instanceof vG&&r.subscribers.forEach(function(e){e.apply(n,t||[])})},bG.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 gG(e,t,n);return this.registeredContexts[e]=r,this.contextCheckers.push(r),r},bG.prototype.getRangeTokens=function(e){var t=e.startIndex+e.endOffset;return[].concat(this.tokens.slice(e.startIndex,t))},bG.prototype.getContextRanges=function(e){var t=this.getContext(e);return t?t.ranges:{FAIL:`context checker '`+e+`' is not registered.`}},bG.prototype.resetContextsRanges=function(){var e=this.registeredContexts;for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];n.ranges=[]}},bG.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 _G(e,t);this.runContextCheck(n)}this.dispatch(`updateContextsRanges`,[this.registeredContexts])},bG.prototype.setEndOffset=function(e,t){var n=this.getContext(t).openRange.startIndex,r=new hG(n,e,t),i=this.getContext(t).ranges;return r.rangeId=t+`.`+i.length,i.push(r),this.getContext(t).openRange=null,r},bG.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 hG(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])}})},bG.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 _G(t,n);this.dispatch(`next`,[i]),this.runContextCheck(i);var a=new mG(r);this.tokens.push(a),this.dispatch(`newToken`,[a,i])}return this.dispatch(`end`,[this.tokens]),this.tokens};function xG(e){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(e)}function SG(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 CG(e){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(e)}function wG(e){return/[A-z]/.test(e)}function TG(e){return/\s/.test(e)}function EG(e){this.font=e,this.features={}}function DG(e){this.id=e.id,this.tag=e.tag,this.substitution=e.substitution}function OG(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 kG(e,t){return OG(e,t.coverage)===-1?null:e+t.deltaGlyphId}function AG(e,t){var n=OG(e,t.coverage);return n===-1?null:t.substitute[n]}function jG(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=OG(a,i);o!==-1&&n.push(o)}return n.length===e.length?n:-1}function MG(e,t){var n=t.inputCoverage.length+t.lookaheadCoverage.length+t.backtrackCoverage.length;if(e.context.length<n)return[];var r=jG(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&&CG(a[0].char);)a.shift();var o=new _G(a,0),s=jG(t.lookaheadCoverage,o),c=[].concat(e.backtrack);for(c.reverse();c.length&&CG(c[0].char);)c.shift();if(c.length<t.backtrackCoverage.length)return[];var l=new _G(c,0),u=jG(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 NG(e,t){var n=e.current,r=OG(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 PG(e,t){var n=OG(e,t.coverage);return n===-1?null:t.sequences[n]}EG.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[]},EG.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()},EG.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},EG.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},EG.prototype.getSubstitutionType=function(e,t){return e.lookupType.toString()+t.substFormat.toString()},EG.prototype.getLookupMethod=function(e,t){var n=this;switch(this.getSubstitutionType(e,t)){case`11`:return function(e){return kG.apply(n,[e,t])};case`12`:return function(e){return AG.apply(n,[e,t])};case`63`:return function(e){return MG.apply(n,[e,t])};case`41`:return function(e){return NG.apply(n,[e,t])};case`21`:return function(e){return PG.apply(n,[e,t])};default:throw Error(`lookupType: `+e.lookupType+` - substFormat: `+t.substFormat+` is not yet supported`)}},EG.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 _G(a,n),!(Array.isArray(p)&&!p.length)&&(p=null)}return a.length?a:null},EG.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},EG.prototype.getLookupSubtables=function(e){return e.subtables||null},EG.prototype.getLookupByIndex=function(e){return this.font.tables.gsub.lookups[e]||null},EG.prototype.getFeatureLookups=function(e){return e.lookupListIndexes.map(this.getLookupByIndex.bind(this))},EG.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 FG(e){var t=e.current,n=e.get(-1);return n===null&&xG(t)||!xG(n)&&xG(t)}function IG(e){var t=e.get(1);return t===null||!xG(t)}var LG={startCheck:FG,endCheck:IG};function RG(e){var t=e.current,n=e.get(-1);return(xG(t)||CG(t))&&!xG(n)}function zG(e){var t=e.get(1);switch(!0){case t===null:return!0;case!xG(t)&&!CG(t):var n=TG(t);if(!n)return!0;if(n){var r=!1;if(r=e.lookahead.some(function(e){return xG(e)||CG(e)}),!r)return!0}break;default:return!1}}var BG={startCheck:RG,endCheck:zG};function VG(e,t,n){t[n].setState(e.tag,e.substitution)}function HG(e,t,n){t[n].setState(e.tag,e.substitution)}function UG(e,t,n){e.substitution.forEach(function(r,i){t[n+i].setState(e.tag,r)})}function WG(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 GG={11:VG,12:HG,63:UG,41:WG};function KG(e,t,n){e instanceof DG&&GG[e.id]&&GG[e.id](e,t,n)}function qG(e){for(var t=[].concat(e.backtrack),n=t.length-1;n>=0;n--){var r=t[n],i=SG(r),a=CG(r);if(!i&&!a)return!0;if(i)return!1}return!1}function JG(e){if(SG(e.current))return!1;for(var t=0;t<e.lookahead.length;t++){var n=e.lookahead[t];if(!CG(n))return!0}return!1}function YG(e){var t=this,n=`arab`,r=this.featuresTags[n],i=this.tokenizer.getRangeTokens(e);if(i.length!==1){var a=new _G(i.map(function(e){return e.getState(`glyphIndex`)}),0),o=new _G(i.map(function(e){return e.char}),0);i.forEach(function(e,s){if(!CG(e.char)){a.setCurrentIndex(s),o.setCurrentIndex(s);var c=0;qG(o)&&(c|=1),JG(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&&(KG(e,i,t),a.context[t]=e.substitution)})}}})}}function XG(e,t){return new _G(e.map(function(e){return e.activeState.value}),t||0)}function ZG(e){var t=this,n=`arab`,r=this.tokenizer.getRangeTokens(e),i=XG(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 KG(e,r,a)}),i=XG(r))})}function QG(e){var t=e.current,n=e.get(-1);return n===null&&wG(t)||!wG(n)&&wG(t)}function $G(e){var t=e.get(1);return t===null||!wG(t)}var eK={startCheck:QG,endCheck:$G};function tK(e,t){return new _G(e.map(function(e){return e.activeState.value}),t||0)}function nK(e){var t=this,n=`latn`,r=this.tokenizer.getRangeTokens(e),i=tK(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 KG(e,r,a)}),i=tK(r))})}function rK(e){this.baseDir=e||`ltr`,this.tokenizer=new bG,this.featuresTags={}}rK.prototype.setText=function(e){this.text=e},rK.prototype.contextChecks={latinWordCheck:eK,arabicWordCheck:LG,arabicSentenceCheck:BG};function iK(e){var t=this.contextChecks[e+`Check`];return this.tokenizer.registerContextChecker(e,t.startCheck,t.endCheck)}function aK(){return iK.call(this,`latinWord`),iK.call(this,`arabicWord`),iK.call(this,`arabicSentence`),this.tokenizer.tokenize(this.text)}function oK(){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())})}rK.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},rK.prototype.applyFeatures=function(e,t){if(!e)throw Error(`No valid font was provided to apply features`);this.query||=new EG(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)}},rK.prototype.registerModifier=function(e,t,n){this.tokenizer.registerModifier(e,t,n)};function sK(){if(this.tokenizer.registeredModifiers.indexOf(`glyphIndex`)===-1)throw Error(`glyphIndex modifier is required to apply arabic presentation features.`)}function cK(){var e=this;this.featuresTags.hasOwnProperty(`arab`)&&(sK.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){YG.call(e,t)}))}function lK(){var e=this,t=`arab`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`rlig`)!==-1&&(sK.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){ZG.call(e,t)}))}function uK(){var e=this,t=`latn`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`liga`)!==-1&&(sK.call(this),this.tokenizer.getContextRanges(`latinWord`).forEach(function(t){nK.call(e,t)}))}rK.prototype.checkContextReady=function(e){return!!this.tokenizer.getContext(e)},rK.prototype.applyFeaturesToContexts=function(){this.checkContextReady(`arabicWord`)&&(cK.call(this),lK.call(this)),this.checkContextReady(`latinWord`)&&uK.call(this),this.checkContextReady(`arabicSentence`)&&oK.call(this)},rK.prototype.processText=function(e){(!this.text||this.text!==e)&&(this.setText(e),aK.call(this),this.applyFeaturesToContexts())},rK.prototype.getBidiText=function(e){return this.processText(e),this.tokenizer.getText()},rK.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 dK(e){e||={},e.tables=e.tables||{},e.empty||(GH(e.familyName,`When creating a new Font object, familyName is required.`),GH(e.styleName,`When creating a new Font object, styleName is required.`),GH(e.unitsPerEm,`When creating a new Font object, unitsPerEm is required.`),GH(e.ascender,`When creating a new Font object, ascender is required.`),GH(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 qB.GlyphSet(this,e.glyphs||[]),this.encoding=new jB(this),this.position=new RH(this),this.substitution=new zH(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 oU(this)}})}dK.prototype.hasChar=function(e){return this.encoding.charToGlyphIndex(e)!==null},dK.prototype.charToGlyphIndex=function(e){return this.encoding.charToGlyphIndex(e)},dK.prototype.charToGlyph=function(e){var t=this.charToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},dK.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})},dK.prototype.stringToGlyphs=function(e,t){var n=this,r=new rK;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},dK.prototype.nameToGlyphIndex=function(e){return this.glyphNames.nameToGlyphIndex(e)},dK.prototype.nameToGlyph=function(e){var t=this.nameToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},dK.prototype.glyphIndexToName=function(e){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(e):``},dK.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},dK.prototype.defaultRenderOptions={kerning:!0,features:[{script:`arab`,tags:[`init`,`medi`,`fina`,`rlig`]},{script:`latn`,tags:[`liga`,`rlig`]}]},dK.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},dK.prototype.getPath=function(e,t,n,r,i){var a=new zz;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},dK.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},dK.prototype.getAdvanceWidth=function(e,t,n){return this.forEachGlyph(e,0,0,t,n,function(){})},dK.prototype.draw=function(e,t,n,r,i,a){this.getPath(t,n,r,i,a).draw(e)},dK.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)})},dK.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)})},dK.prototype.getEnglishName=function(e){var t=this.names[e];if(t)return t.en},dK.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},dK.prototype.toTables=function(){return NH.fontToTable(this)},dK.prototype.toBuffer=function(){return console.warn(`Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.`),this.toArrayBuffer()},dK.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},dK.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(HH())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=dz(),l=WH(r);c.writeFileSync(e,l)}},dK.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512},dK.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},dK.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function fK(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 pK(e,t,n){var r=fK(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 mK(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 hK(e,t,n,r){for(var i=fK(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 gK(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 _K(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(pK(r,e.axes[r],t));for(var i=0;i<e.instances.length;i++)n.fields=n.fields.concat(hK(i,e.instances[i],e.axes,t));return n}function vK(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(mK(e,t+a+d*s,n));for(var f=[],p=t+a+o*s,m=0;m<c;m++)f.push(gK(e,p+m*l,u,n));return{axes:u,instances:f}}var yK={make:_K,parse:vK},bK=function(){return{coverage:this.parsePointer(X.coverage),attachPoints:this.parseList(X.pointer(X.uShortList))}},xK=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()}},SK=function(){return this.parseList(X.pointer(xK))},CK=function(){return{coverage:this.parsePointer(X.coverage),ligGlyphs:this.parseList(X.pointer(SK))}},wK=function(){return this.parseUShort(),this.parseList(X.pointer(X.coverage))};function TK(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(bK),ligCaretList:n.parsePointer(CK),markAttachClassDef:n.parsePointer(X.classDef)};return r>=1.2&&(i.markGlyphSets=n.parsePointer(wK)),i}var EK={parse:TK},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 OK(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 kK=Array(10);function AK(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,kK)}])}var jK={parse:OK,make:AK};function MK(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 NK(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 PK(e,t){var n=new Z.Parser(e,t),r=n.parseUShort();if(r===0)return MK(n);if(r===1)return NK(n);throw Error(`Unsupported kern table version (`+r+`).`)}var FK={parse:PK};function IK(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 LK={parse:IK};function RK(e,t){dz().readFile(e,function(e,n){if(e)return t(e.message);t(null,UH(n))})}function zK(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 BK(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 VK(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 HK(e,t){if(t.compression===`WOFF`){var n=new Uint8Array(e.buffer,t.offset+2,t.compressedLength-2),r=new Uint8Array(t.length);if(Iz(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 UK(e,t){t??={};var n,r,i=new dK({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=BK(a,o);else if(c===`OTTO`)i.outlinesFormat=`cff`,o=Z.getUShort(a,4),s=BK(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=VK(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=HK(a,C),i.tables.cmap=EB.parse(w.data,w.offset),i.encoding=new MB(i.tables.cmap);break;case`cvt `:w=HK(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=HK(a,C),x=new Z.Parser(w.data,w.offset),i.tables.fpgm=x.parseByteList(C.length);break;case`head`:w=HK(a,C),i.tables.head=MV.parse(w.data,w.offset),i.unitsPerEm=i.tables.head.unitsPerEm,n=i.tables.head.indexToLocFormat;break;case`hhea`:w=HK(a,C),i.tables.hhea=FV.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=HK(a,C),r=UV.parse(w.data,w.offset);break;case`maxp`:w=HK(a,C),i.tables.maxp=KV.parse(w.data,w.offset),i.numGlyphs=i.tables.maxp.numGlyphs;break;case`name`:y=C;break;case`OS/2`:w=HK(a,C),i.tables.os2=pH.parse(w.data,w.offset);break;case`post`:w=HK(a,C),i.tables.post=gH.parse(w.data,w.offset),i.glyphNames=new PB(i.tables.post);break;case`prep`:w=HK(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=HK(a,y);if(i.tables.name=cH.parse(ee.data,ee.offset,r),i.names=i.tables.name,f&&v){var te=n===0,ne=HK(a,v),re=LK.parse(ne.data,ne.offset,i.numGlyphs,te),ie=HK(a,f);i.glyphs=tU.parse(ie.data,ie.offset,re,i,t)}else if(u){var ae=HK(a,u);kV.parse(ae.data,ae.offset,i,t)}else throw Error(`Font doesn't contain TrueType or CFF outlines.`);var oe=HK(a,g);if(BV.parse(i,oe.data,oe.offset,i.numberOfHMetrics,i.numGlyphs,i.glyphs,t),LB(i,t),_){var se=HK(a,_);i.kerningPairs=FK.parse(se.data,se.offset)}else i.kerningPairs={};if(p){var ce=HK(a,p);i.tables.gdef=EK.parse(ce.data,ce.offset)}if(m){var le=HK(a,m);i.tables.gpos=jK.parse(le.data,le.offset),i.position.init()}if(h){var ue=HK(a,h);i.tables.gsub=SH.parse(ue.data,ue.offset)}if(d){var de=HK(a,d);i.tables.fvar=yK.parse(de.data,de.offset,i.names)}if(b){var fe=HK(a,b);i.tables.meta=TH.parse(fe.data,fe.offset),i.metas=i.tables.meta}return i}function WK(e,t,n){n??={};var r=typeof window>`u`&&!n.isUrl?RK:zK;return new Promise(function(i,a){r(e,function(e,r){if(e){if(t)return t(e);a(e)}var o;try{o=UK(r,n)}catch(e){if(t)return t(e,null);a(e)}if(t)return t(null,o);i(o)})})}function GK(e,t){return UK(UH(dz().readFileSync(e)),t)}var KK=Object.freeze({__proto__:null,Font:dK,Glyph:VB,Path:zz,BoundingBox:Rz,_parse:Z,parse:UK,load:WK,loadSync:GK}),qK=class e{sketches;constructor(e){e.length===0&&i(`CompoundSketch`,`Cannot create CompoundSketch with an empty array of sketches`),this.sketches=e}delete(){this.sketches.forEach(e=>{e.delete()})}get outerSketch(){return vA(this.sketches)}get innerSketches(){return this.sketches.slice(1)}get wires(){return aq(this)}face(){return iq(this)}extrude(e,t={}){return oq(this,e,t)}revolve(e,t={}){return sq(this,e,t)}loftWith(t,n={}){return Array.isArray(t)||!(t instanceof e)?i(`CompoundSketch.loftWith`,`A compound (face-with-holes) sketch can only loft to another compound sketch with the same number of sub-sketches.`):cq(this,t,n)}sweepSketch(){return i(`CompoundSketch.sweepSketch`,`Sweeping a compound (face-with-holes) profile is not supported — sweep its outer Sketch instead.`)}};function JK(e){let t={};e.defaultOrigin&&(t.defaultOrigin=e.defaultOrigin),e.defaultDirection&&(t.defaultDirection=e.defaultDirection);let n=new lq(e.wire,t);return e.baseFace&&(n.baseFace=e.baseFace),n}function YK(e){return new qK(e.map(JK))}function XK(e){if(e instanceof lq)return e;let t=e.sketches;if(Array.isArray(t)){let[e,...n]=t;if(e instanceof lq){for(let e of n)e.delete();return e}}i(`asSketch`,`Expected a single-wire profile to loft or sweep.`)}function ZK(e){let t;return t=e.baseFace?FA(e.baseFace,e.wire):j(NA(e.wire)),t}function QK(e){return EE(j(dO(e.wire.wrapped)))}function $K(e,t,{origin:n}={}){let r=j(NA(e.wire)),i=j(kM(r,n?AD(n):e.defaultOrigin,t?AD(t):[0,0,1]));return r[Symbol.dispose](),e.delete(),i}function eq(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=ID(UD(n?AD(n):e.defaultDirection),t),s=a?AD(a):e.defaultOrigin;if(r&&!i){let t=j(SM(e.wire,[...s],[...o],r));return e.delete(),t}if(i){let t=j(CM(e.wire,i,[...s],[...o],r));return e.delete(),t}let c=j(NA(e.wire)),l=j(OM(c,[...o]));return c[Symbol.dispose](),e.delete(),l}function tq(e,t,n={}){let r=Mk(e.wire),i=UD(ID(Fk(e.wire,1e-9),-1)),a=e.defaultDirection,o=ID(zD(i,a),-1),s=XK(t(ZD([...r],[...o],[...i]),[...r])),c={forceProfileSpineOthogonality:!0,...n};e.baseFace&&(c.support=e.baseFace.wrapped);let l=j(bM(s.wire,e.wire,c));return e.delete(),l}function nq(e,t,n={},r=!1){let i=[e,...(Array.isArray(t)?t:[t]).map(XK)],a=j(jM(i.map(e=>e.wire),n,r));return i.forEach(e=>{e.delete()}),a}var rq=(e,t)=>{let n=j(t(vA(e))),r=e.slice(1).map(e=>j(t(e)));if(r.length===0)return n;try{return j(KA(n,r,{unsafe:!0}))}finally{n.delete();for(let e of r)e.delete()}};function iq(e){let t=e.outerSketch.face(),n=LA(t,e.innerSketches.map(e=>e.wire));return t[Symbol.dispose](),n}function aq(e){return mj(e.sketches.map(e=>e.wire))}function oq(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=ID(UD(n?AD(n):e.outerSketch.defaultDirection),t);if(r&&!i)return rq(e.sketches,t=>SM(t.wire,a?AD(a):e.outerSketch.defaultOrigin,o,r));if(i)return rq(e.sketches,t=>CM(t.wire,i,a?AD(a):e.outerSketch.defaultOrigin,o,r));let s=iq(e),c=j(OM(s,o));return s[Symbol.dispose](),c}function sq(e,t,{origin:n}={}){let r=n?AD(n):e.outerSketch.defaultOrigin,i=t?AD(t):[0,0,1],a=iq(e),o=j(kM(a,r,i));return a[Symbol.dispose](),o}function cq(e,t,n={}){e.sketches.length!==t.sketches.length&&i(`CompoundSketch.loftWith`,`You need to loft with another compound with the same number of sketches`);let r=e.sketches.map((e,r)=>{let i=_A(t.sketches,r),a={};return n.ruled!==void 0&&(a.ruled=n.ruled),e.clone().loftWith(i.clone(),a,!0)}),a=iq(e),o=DE(j(dO(a.wrapped)));a[Symbol.dispose](),r.push(o,iq(t));let s=j(hj(r));for(let e of r)e[Symbol.dispose]();return s}var lq=class e{wire;_defaultOrigin;_defaultDirection;_baseFace;constructor(e,{defaultOrigin:t=[0,0,0],defaultDirection:n=[0,0,1]}={}){this.wire=e,this._defaultOrigin=AD(t),this._defaultDirection=AD(n),this.baseFace=null}get baseFace(){return this._baseFace}set baseFace(e){this._baseFace&&this._baseFace[Symbol.dispose](),this._baseFace=e&&DE(j(dO(e.wrapped)))}delete(){this.wire[Symbol.dispose](),this.baseFace&&this.baseFace[Symbol.dispose]()}clone(){let t=EE(j(dO(this.wire.wrapped))),n=new e(t,{defaultOrigin:this.defaultOrigin,defaultDirection:this.defaultDirection});return this.baseFace&&(n.baseFace=DE(j(dO(this.baseFace.wrapped)))),n}get defaultOrigin(){return this._defaultOrigin}set defaultOrigin(e){this._defaultOrigin=AD(e)}get defaultDirection(){return this._defaultDirection}set defaultDirection(e){this._defaultDirection=AD(e)}face(){return ZK(this)}wires(){return QK(this)}faces(){return this.face()}revolve(e,t={}){return $K(this,e,t)}extrude(e,t={}){return eq(this,e,t)}sweepSketch(e,t={}){return tq(this,e,t)}loftWith(e,t={},n=!1){return nq(this,e,t,n)}},uq=class{sketches;constructor(e){this.sketches=e}soleSketch(e){this.sketches.length!==1&&i(`Sketches.${e}`,`Multiple profiles — ${e} each sub-sketch individually.`);let t=vA(this.sketches);return t instanceof lq||i(`Sketches.${e}`,`${e} is only supported on single-wire profiles.`),t}face(){return this.sketches.length!==1&&i(`Sketches.face`,`Multiple profiles — use faces() to combine them.`),vA(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 mj(this.sketches.flatMap(e=>e instanceof lq?[e.wire]:e.sketches.map(e=>e.wire)))}faces(){return mj(this.sketches.map(e=>e.face()))}extrude(e,t={}){return mj(this.sketches.map(n=>n.extrude(e,t)))}revolve(e,t){return mj(this.sketches.map(n=>n.revolve(e,t)))}},dq={};async function fq(e,t=`default`,n=!1){if(!n&&dq[t])return O(dq[t]);let r;if(typeof e==`string`){let t;try{t=await fetch(e)}catch(t){return k(Do(M.FONT_FETCH_FAILED,`Failed to fetch font from ${e}: ${t instanceof Error?t.message:String(t)}`,t))}if(!t.ok)return k(Do(M.FONT_FETCH_FAILED,`Failed to fetch font from ${e}: HTTP ${t.status} ${t.statusText}`));r=await t.arrayBuffer()}else r=e;let i;try{i=KK.parse(r)}catch(e){return k(Do(M.FONT_PARSE_FAILED,`Failed to parse font data: ${e instanceof Error?e.message:String(e)}`,e))}let a=i;return dq[t]=a,dq.default||=a,O(a)}var pq=(e=`default`)=>dq[e],mq=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 vR,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 hq(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:a=`default`}={}){let o=pq(a);o||=pq(),o||i(`text`,`No fonts loaded. Call loadFont() before using text functions.`);let s=o.getPath(e,-t,-n,r);return sR(Array.from(mq(s.commands))).mirror([0,0])}var gq={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 _q(e){return typeof e==`string`&&e in gq}var vq=e=>{try{var t=IT();return e.IsNull()?[]:uD(t.u(U(e))).map(e=>j(wk(e)))}catch(e){t.e=e}finally{t.d()}};function yq(e,t,n=!0){let r=H().projectEdges(e.wrapped,[...t.position],[...t.direction],[...t.xAxis]),i=[...vq(r.visible.sharp),...vq(r.visible.smooth),...vq(r.visible.outline)],a=[...vq(r.hidden.sharp),...vq(r.hidden.smooth),...vq(r.hidden.outline)],o;if(n)o=a;else{for(let e of a)e[Symbol.dispose]();o=[]}return{visible:i,hidden:o}}function bq(e=[0,0,0],t=[0,0,1],n){if(BD(t)<1e-12)return k(P(`CAMERA_ZERO_DIRECTION`,`Camera direction cannot be a zero-length vector`));let r;if(n)r=UD(n);else{let e=zD([0,0,1],t);BD(e)<1e-12&&(e=zD([0,1,0],t)),BD(e)<1e-12&&(e=zD([1,0,0],t)),r=UD(e)}let i=UD(zD(t,r));return O({position:e,direction:UD(t),xAxis:r,yAxis:i})}function xq(e,t){let n=UD(FD(e.position,t));return bq(e.position,n)}function Sq(e){let t=gq[e];return bq([0,0,0],t.dir,t.xAxis)}function Cq(e,t,n=!0){return yq(e,t,n)}var wq=(e,n=1e-7)=>{if(e.length===0)return[];let r=new VL(e.length);e.forEach(e=>{let[t,i]=e.firstPoint;r.add(t-n,i-n,t+n,i+n)}),r.finish();let a=[],o=new Set;return e.forEach((s,c)=>{if(o.has(c))return;let l=[s],u=c;o.add(c);let d=e.length;for(;;){d--<0&&i(`stitchCurves`,`Infinite loop detected`);let[s,c]=t(l,l.length-1).lastPoint,f=r.search(s-n,c-n,s+n,c+n),p=t=>Math.abs((u-t)%e.length),m=f.filter(e=>!o.has(e)).map(n=>[t(e,n),n,p(n)]).sort(([,,e],[,,t])=>e-t);if(m.length===0){a.push(l);break}let[h,g]=t(m,0);l.push(h),o.add(g),u=g}}),a},Tq=class extends _R{plane;constructor(e,t){super(),this.plane=e&&typeof e!=`string`?{...e}:j(eO(e??`XY`,t))}delete(){this.pendingCurves=[]}sagittaArcTo(e,t){return super.sagittaArcTo(e,-t)}buildWire(){try{var e=IT();this.pendingCurves.length||i(`Sketcher.buildWire`,`No lines to convert into a wire`);let t=e.u(new XT);return j(MA(wL(this.pendingCurves,this.plane).map(e=>t.register(e))))}catch(t){e.e=t}finally{e.d()}}done(){return new lq(this.buildWire(),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}close(){return this._closeSketch(),this.done()}closeWithMirror(){EI(this.pointer,this.firstPoint)&&i(`Sketcher.closeWithMirror`,`Cannot close with a mirror when the sketch is already closed`);let e=this.buildWire(),t=nO(this.plane,this.pointer),n=zD(UD(FD(t,nO(this.plane,this.firstPoint))),this.plane.zDir),r=j(uO(e.wrapped));return new lq(j(MA([e,EE(j(uO(H().mirror(r,AD(t),AD(n)))))])),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}closeWithCustomCorner(e,t=`fillet`){return this._closeSketch(),this._customCornerLastWithFirst(e,t),this.done()}},Eq=class extends _R{face;_bounds;constructor(e,t=[0,0]){super(t),this.face=DE(j(dO(e.wrapped))),this._bounds=bO(e)}_convertToUV([e,t]){let{uMin:n,uMax:r,vMin:i,vMax:a}=this._bounds;return[n+e*(r-n),i+t*(a-i)]}_convertFromUV([e,t]){let{uMin:n,uMax:r,vMin:i,vMax:a}=this._bounds;return[(e-n)/(r-n),(t-i)/(a-i)]}_adaptSurface(){return H().extractSurfaceFromFace(this.face.wrapped)}buildWire(){let e=H(),t=this._adaptSurface(),n=j(MA(this.pendingCurves.map(n=>TE(e.buildEdgeOnSurface(n.wrapped,t)))));return e.buildCurves3d(n.wrapped),n}done(){try{var e=IT();let t=e.u(new XT),n=this.buildWire(),r=new lq(n);if(Rk(n)){let e=t.register(r.clone().face()),n=xO(e,.5,.5),i=ID(wO(e),-1);r.defaultOrigin=[n[0],n[1],n[2]],r.defaultDirection=[i[0],i[1],i[2]]}else{let e=Mk(n),t=wO(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=IT();let r=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(eO(t.plane??`XY`,t.origin));return new lq(j(MA([n.u(new XT).register(CA(e,r.origin,r.zDir))])),{defaultOrigin:[...r.origin],defaultDirection:[...r.zDir]})}catch(e){n.e=e}finally{n.d()}},Oq=(e=1,t=2,n={})=>{try{var r=IT();let i=n.plane&&typeof n.plane!=`string`?{...n.plane}:j(eO(n.plane??`XY`,n.origin)),a=i.xDir,o=e,s=t;return t>e&&(a=JD(a,i.zDir,90*JE),o=t,s=e),new lq(j(MA([r.u(new XT).register(j(wA(o,s,i.origin,i.zDir,a)))])),{defaultOrigin:[...i.origin],defaultDirection:[...i.zDir]})}catch(e){r.e=e}finally{r.d()}},kq=(e,t,n={})=>(n.plane&&typeof n.plane!=`string`?new Tq(n.plane):new Tq(n.plane,n.origin)).movePointerTo([-e/2,-t/2]).hLine(e).vLine(t).hLine(-e).vLine(-t).done(),Aq=(e,t,n=0,r={})=>{let i=TR(e,t,n).sketchOnPlane(r.plane,r.origin),a={};return i.defaultOrigin&&(a.defaultOrigin=i.defaultOrigin),i.defaultDirection&&(a.defaultDirection=i.defaultDirection),new lq(i.wire,a)},jq=(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 Tq(r.plane):new Tq(r.plane,r.origin),o=yA(i),s=a.movePointerTo([_A(o,0),_A(o,1)]);return n?i.forEach(e=>s.sagittaArcTo([_A(e,0),_A(e,1)],n)):i.forEach(e=>s.lineTo([_A(e,0),_A(e,1)])),s.done()},Mq=(e,t,n=0)=>{let r=Math.PI/t,i=Math.cos(r)*e;return n>=0?i:i+n},Nq=(e,t)=>{let n=[...TO(e)],r=[...wO(e)];return new lq(j(Gk(OO(e),t)),{defaultOrigin:n,defaultDirection:r})},Pq=(e,t={},{pointsCount:n=400,start:r=0,stop:i=1}={},a={})=>{try{var o=IT();let s=o.u(new XT),c=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(eO(t.plane??`XY`,t.origin)),l=(i-r)/n,u=[...Array(n+1).keys()].map(t=>{let n=e(r+t*l);return nO(c,n)});return new lq(j(MA([s.register(j(OA(u,a)))])),{defaultOrigin:[...c.origin],defaultDirection:[...c.zDir]})}catch(e){o.e=e}finally{o.d()}},Fq=(e,t,n,r=[0,0,0],i=[0,0,1],a=!1)=>new lq(j(MA([TA(e,t,n,AD(r),AD(i),a)]))),Iq=(e,t,n)=>new Tq().movePointerTo([-e/2,t/2]).hLine(e).vLine(-t).hLine(-e).close().extrude(n),Lq=(e,t)=>EI(e,t,wI*100),Rq=(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 zq(e,t,n,r,i){let a=xL(t,n,r.original.lastPoint);e(r),e(a)}function Bq(e,t,n,r,i){let a=pL(t,n);e(r),e(a)}function Vq(e,t,n,r,i){let a=Rq(r.offset instanceof lL?OI(t,r.offset.tangentAt(1)):r.offset.firstPoint,t,n,i.offset instanceof lL?DI(n,i.offset.tangentAt(0)):i.offset.lastPoint);if(!a){let i=pL(t,n);e(r),e(i);return}let o=jI([(t[0]+n[0])/2,(t[1]+n[1])/2],a),s=jI(t,n);if(s<1e-18||o>16*s){let i=pL(t,n);e(r),e(i);return}let c=pL(t,a),l=pL(a,n);e(r),e(c),e(l)}var Hq={round:zq,bevel:Bq,miter:Vq};function Uq(e,t,n){let r=n.length===1?Ao(n,0,`rawOffsets`):Wq(n,e.original.lastPoint),a=Ao(e.offset.splitAt([r],wI),0,`rawOffsets`),o=t.offset.splitAt([r],wI).at(-1);return o||i(`offset.rawOffsets`,`Split produced no trailing curve segment`),{splitPrevious:{offset:a,original:e.original},splitCurrent:{offset:o,original:t.original}}}function Wq(e,t){let n=Ao(e,0,`selectClosestIntersection`),r=jI(n,t);for(let i=1;i<e.length;i++){let a=Ao(e,i,`selectClosestIntersection`),o=jI(a,t);o<r&&(r=o,n=a)}return n}function Gq(e){let t=new Map,n=(e,n)=>{let r=t.get(e)||[];t.set(e,[...r,...n])},r=new VL(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=Ao(e,r,`offsetBlueprint`),{intersections:o,commonSegmentsPoints:s}=j(KL(t,a,wI)),c=[...o,...s].filter(e=>{let n=Lq(e,t.firstPoint)||Lq(e,t.lastPoint),r=Lq(e,a.firstPoint)||Lq(e,a.lastPoint);return!(n&&r)});c.length&&(n(i,c),n(r,c))}}),t}function Kq(e,t,n={}){let r=e.orientation===`clockwise`?-t:t,a=e.curves.map(e=>({offset:YL(e,r),original:e})),o=[],s=null,c=a.at(-1);if(!c)return[];function l(e){if(e instanceof lL){o.push(e);return}s?e.offset instanceof lL?o.push(e.offset):Lq(e.offset.firstPoint,e.offset.lastPoint)||o.push(pL(e.offset.firstPoint,e.offset.lastPoint)):s=e}let u=function*(){for(let e of a.slice(0,-1))yield e;s||i(`offset.rawOffsets`,`No saved curve after iterating offset segments`),yield s};for(let e of u()){let t=c.offset.lastPoint,r=e.offset.firstPoint;if(Lq(t,r)){l(c),c=e;continue}let i=[];if(c.offset instanceof lL&&e.offset instanceof lL){let{intersections:t,commonSegmentsPoints:n}=j(KL(c.offset,e.offset,wI/100));i=[...t,...n]}if(i.length>0){let{splitPrevious:t,splitCurrent:n}=Uq(c,e,i);l(t),c=n;continue}let a=Hq[n.lineJoinType??`round`];a(l,t,r,c,e),c=e}return l(c),o}function qq(e,n,r={}){let i=Kq(e,n,r);if(i.length<2)return null;let a=Gq(i);if(!a.size){let t=new LL(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,wI*100)}),s=new VL(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-wI)});if(!l.length)return null;let u=wq(l).filter(e=>e.length>1).map(e=>new LL(e)).filter(e=>e.isClosed());return u.length?u.length===1?Ao(u,0,`offsetBlueprint`):new eR(u):null}var Jq=e=>{let t=Ao(e,0,`fuseAll`);for(let n=1;n<e.length;n++)t=sz(t,Ao(e,n,`fuseAll`));return t};function Yq(e,t,n={}){if(e instanceof LL)return qq(e,t,n);if(e instanceof eR)return Jq(e.blueprints.map(e=>Yq(e,t,n)));if(e instanceof tR){let r=Jq(e.blueprints.slice(1).map(e=>Yq(e,-t,n)));return lz(Yq(Ao(e.blueprints,0,`offset`),t,n),r)}return null}function Xq(e,t){return e instanceof LL?new LL(fL(e.curves,t)):e instanceof tR?new tR(e.blueprints.map(e=>Xq(e,t))):e instanceof eR?new eR(e.blueprints.map(e=>Xq(e,t))):e}function Zq(e,t,n,r){let a=()=>!0;r&&(a=r.shouldKeep.bind(r));let o=[vA(t.curves)],s=(t,r)=>{a({firstCurve:t,secondCurve:r,point:t.lastPoint})?o.push(...e(t,r,n)):o.push(t,r)};t.curves.slice(1).forEach(e=>{let t=o.pop();t||i(`customCorners.modifyCorners`,`Unexpected empty curve stack during filleting`),s(t,e)});let c=o.at(-1);if(c||i(`customCorners.modifyCorners`,`Unexpected empty curve list during corner modification`),EI(vA(o).firstPoint,c.lastPoint)&&o.length>1){let e=o.pop(),t=o.shift();(!e||!t)&&i(`customCorners.modifyCorners`,`Unexpected empty curve stack during close-and-fillet`),s(e,t)}return new LL(o)}function Qq(e,t,n,r){return t instanceof LL?Zq(e,t,n,r):t instanceof tR?new tR(t.blueprints.map(t=>Zq(e,t,n,r))):t instanceof eR?new eR(t.blueprints.map(t=>Qq(e,t,n,r)).filter(e=>e!==null)):null}function $q(e,t,n){return Qq(ZL,e,t,n)}function eJ(e,t,n){return Qq(QL,e,t,n)}function tJ(e,t){return e instanceof LL?JK(t):e instanceof tR?YK(t):new uq(t.map(e=>Array.isArray(e)?YK(e):JK(e)))}var nJ=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 tR)return{type:`CompoundBlueprint`,blueprints:t.blueprints.map(e)};if(t instanceof eR)return{type:`Blueprints`,blueprints:t.blueprints.map(e)};if(t instanceof LL)return{type:`Blueprint`,curves:t.curves.map(e=>e.serialize())};i(`Drawing.serialize`,`Unknown shape type for serialization`)}return JSON.stringify(e(this.innerShape))}get boundingBox(){return this.innerShape?this.innerShape.boundingBox:new sL}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(lz(this.innerShape,t.innerShape))}fuse(t){return new e(sz(this.innerShape,t.innerShape))}intersect(t){return new e(uz(this.innerShape,t.innerShape))}fillet(t,n){let r=n&&n(CR());return new e($q(this.innerShape,t,r))}chamfer(t,n){let r=n&&n(CR());return new e(eJ(this.innerShape,t,r))}sketchOnPlane(e,t){this.innerShape||i(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnPlane(e,t);return tJ(this.innerShape,n)}sketchOnFace(e,t){this.innerShape||i(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnFace(e,t);return tJ(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(Yq(this.innerShape,t,n))}approximate(t,n={}){return t!==`svg`&&i(`Drawing.approximate`,`Only 'svg' is supported for now`),new e(Xq(this.innerShape,n))}get blueprint(){if(!(this.innerShape instanceof LL)){if(this.innerShape instanceof eR&&this.innerShape.blueprints.length===1&&this.innerShape.blueprints[0]instanceof LL)return this.innerShape.blueprints[0];i(`Drawing.blueprint`,`This drawing is not a blueprint`)}return this.innerShape}};function rJ(e){function t(e){if(e.type===`CompoundBlueprint`)return new tR(e.blueprints.map(t));if(e.type===`Blueprints`)return new eR(e.blueprints.map(t));if(e.type===`Blueprint`)return new LL(e.curves.map(e=>cL(e)));i(`Drawing.deserialize`,`Unknown shape type for deserialization`)}return new nJ(t(JSON.parse(e)))}var iJ=class extends _R{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new nJ(new LL(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 aJ(e){let t=new iJ;return e&&t.movePointerTo(e),t}function oJ(e,t,n=0){return new nJ(TR(e,t,n))}var sJ=oJ;function cJ(e){return new nJ(new LL([gL(e)]))}function lJ(e,t){let[n,r]=[e,t].sort((e,t)=>e-t);return new nJ(new LL([_L(r,n,r===e?[1,0]:[0,1])]))}function uJ(e){return aJ().movePointerTo([-e,0]).sagittaArc(2*e,0,e).sagittaArc(-2*e,0,e).close()}function dJ(e,t){return aJ().movePointerTo([-e,0]).halfEllipse(2*e,0,t).halfEllipse(-2*e,0,t).close()}function fJ(e,t,n=0){return new nJ(wR(e,t,n))}function pJ(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:i=`default`}={}){return new nJ(hq(e,{startX:t,startY:n,fontSize:r,fontFamily:i}))}var mJ=(e,t={},n={})=>{e.length<2&&i(`drawPointsInterpolation`,`Need at least 2 points for interpolation, got ${e.length}`);let r=[j(bL(e,t))],a=e[0],o=e[e.length-1];return n.closeShape&&a&&o&&!EI(a,o)&&r.push(pL(o,a)),new nJ(new LL(r))},hJ=(e,{pointsCount:t=400,start:n=0,stop:r=1,closeShape:i=!1}={},a={})=>{let o=(r-n)/t;return mJ([...Array(t+1).keys()].map(t=>e(n+t*o)),a,{closeShape:i})},gJ=e=>{try{var t=IT();let n=t.u(new XT),r=sJ(1e3,1e3).sketchOnPlane();n.register(r.wire);let i=n.register(j(NA(r.wire))),a=wq(e.map(e=>NL(e,i))).map(e=>new LL(e));return a.length===0?new nJ:a.length===1?new nJ(a[0]):new nJ(new eR(a))}catch(e){t.e=e}finally{t.d()}};function _J(e,t=`front`){let n;n=typeof t==`string`?j(Sq(t)):t;let{visible:r,hidden:i}=Cq(e,n);try{return{visible:gJ(r),hidden:gJ(i)}}finally{for(let e of r)e[Symbol.dispose]();for(let e of i)e[Symbol.dispose]()}}function vJ(e){try{var t=IT();let n=t.u(new XT),r=n.register(DE(j(dO(e.wrapped)))),i=wq(uD(n.register(OO(r))).map(t=>NL(t,e))).map(e=>new LL(e));return i.length===0?new nJ:i.length===1?new nJ(i[0]):new nJ(new eR(i))}catch(e){t.e=e}finally{t.d()}}function yJ(e,t,n){return n===void 0?e.sketchOnPlane(t):e.sketchOnPlane(t,n)}function bJ(e,t){return e.fuse(t)}function xJ(e,t){return e.cut(t)}function SJ(e,t){return e.intersect(t)}function CJ(e,t,n){return e.fillet(t,n)}function wJ(e,t,n){return e.chamfer(t,n)}function TJ(e,t,n=0){return typeof t==`number`?e.translate(t,n):e.translate(t)}function EJ(e,t,n){return e.rotate(t,n)}function DJ(e,t,n){return e.scale(t,n)}function OJ(e,t,n,r){return e.mirror(t,n,r)}function kJ(e){let t=e.clone();return t.reverse(),t}function AJ(e){return e.boundingBox}function jJ(e){return e.firstPoint}function MJ(e){return e.lastPoint}function NJ(e,t,n){return e.splitAt(t,n)}function PJ(e,t,n){return e.parameter(t,n)}function FJ(e,t){return e.tangentAt(t)}function IJ(e,t){return e.isOnCurve(t)}function LJ(e,t){return e.distanceFrom(t)}function RJ(e){return e.length===0?k(P(M.BLUEPRINT_EMPTY_CURVES,`createBlueprint: at least one curve is required`)):O(new LL(e))}function zJ(e){return e.length===0?k(P(M.COMPOUND_BLUEPRINT_EMPTY,`createCompoundBlueprint: at least one blueprint (outer boundary) is required`)):O(new tR(e))}function BJ(e){return e.boundingBox}function VJ(e){return e.orientation}function HJ(e,t){return e.isInside(t)}function UJ(e){return e.toSVGPathD()}function WJ(e,t,n){return e.translate(t,n)}function GJ(e,t,n){return e.rotate(t,n)}function KJ(e,t,n){return e.scale(t,n)}function qJ(e,t,n,r){return e.mirror(t,n,r)}function JJ(e,t,n,r){return e.stretch(t,n,r)}function YJ(e,t,n){return e.sketchOnPlane(t,n)}function XJ(e,t,n){return e.sketchOnFace(t,n)}function ZJ(e,t){return n(e,t*3)}function QJ(e,t){return n(e,t)}function $J(e){let t=[`# brepjs OBJ export`],n=e.vertices.length/3;for(let r=0;r<n;r++){let[n,i,a]=ZJ(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]=ZJ(e.normals,n);t.push(`vn ${r} ${i} ${a}`)}let i=n=>{let[r,i,a]=QJ(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 pz=0,mz=-3;function hz(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function gz(e,t){this.source=e,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=t,this.destLen=0,this.ltree=new hz,this.dtree=new hz}var _z=new hz,vz=new hz,yz=new Uint8Array(30),bz=new Uint16Array(30),xz=new Uint8Array(30),Sz=new Uint16Array(30),Cz=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),wz=new hz,Tz=new Uint8Array(320);function Ez(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 Dz(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 Oz=new Uint16Array(16);function kz(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)Oz[i]=a,a+=e.table[i];for(i=0;i<r;++i)t[n+i]&&(e.trans[Oz[t[n+i]]++]=i)}function Az(e){e.bitcount--||(e.tag=e.source[e.sourceIndex++],e.bitcount=7);var t=e.tag&1;return e.tag>>>=1,t}function jz(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 Mz(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 Nz(e,t,n){var r=jz(e,5,257),i=jz(e,5,1),a=jz(e,4,4),o,s,c;for(o=0;o<19;++o)Tz[o]=0;for(o=0;o<a;++o){var l=jz(e,3,0);Tz[Cz[o]]=l}for(kz(wz,Tz,0,19),s=0;s<r+i;){var u=Mz(e,wz);switch(u){case 16:var d=Tz[s-1];for(c=jz(e,2,3);c;--c)Tz[s++]=d;break;case 17:for(c=jz(e,3,3);c;--c)Tz[s++]=0;break;case 18:for(c=jz(e,7,11);c;--c)Tz[s++]=0;break;default:Tz[s++]=u;break}}kz(t,Tz,0,r),kz(n,Tz,r,i)}function Pz(e,t,n){for(;;){var r=Mz(e,t);if(r===256)return pz;if(r<256)e.dest[e.destLen++]=r;else{var i,a,o,s;for(r-=257,i=jz(e,yz[r],bz[r]),a=Mz(e,n),o=e.destLen-jz(e,xz[a],Sz[a]),s=o;s<o+i;++s)e.dest[e.destLen++]=e.dest[s]}}}function Fz(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 mz;for(e.sourceIndex+=4,r=t;r;--r)e.dest[e.destLen++]=e.source[e.sourceIndex++];return e.bitcount=0,pz}function Iz(e,t){var n=new gz(e,t),r,i,a;do{switch(r=Az(n),i=jz(n,2,0),i){case 0:a=Fz(n);break;case 1:a=Pz(n,_z,vz);break;case 2:Nz(n,n.ltree,n.dtree),a=Pz(n,n.ltree,n.dtree);break;default:a=mz}if(a!==pz)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}Dz(_z,vz),Ez(yz,bz,4,3),Ez(xz,Sz,2,1),yz[28]=0,bz[28]=258;var Lz=Iz;function Rz(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 zz(){this.x1=NaN,this.y1=NaN,this.x2=NaN,this.y2=NaN}zz.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)},zz.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))},zz.prototype.addX=function(e){this.addPoint(e,null)},zz.prototype.addY=function(e){this.addPoint(null,e)},zz.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(Rz(c[f],l[f],u[f],d[f],g)),f===1&&this.addY(Rz(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(Rz(c[f],l[f],u[f],d[f],v)),f===1&&this.addY(Rz(c[f],l[f],u[f],d[f],v)));var y=(-p-Math.sqrt(_))/(2*m);0<y&&y<1&&(f===0&&this.addX(Rz(c[f],l[f],u[f],d[f],y)),f===1&&this.addY(Rz(c[f],l[f],u[f],d[f],y)))}}},zz.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 Bz(){this.commands=[],this.fill=`black`,this.stroke=null,this.strokeWidth=1}Bz.prototype.moveTo=function(e,t){this.commands.push({type:`M`,x:e,y:t})},Bz.prototype.lineTo=function(e,t){this.commands.push({type:`L`,x:e,y:t})},Bz.prototype.curveTo=Bz.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})},Bz.prototype.quadTo=Bz.prototype.quadraticCurveTo=function(e,t,n,r){this.commands.push({type:`Q`,x1:e,y1:t,x:n,y:r})},Bz.prototype.close=Bz.prototype.closePath=function(){this.commands.push({type:`Z`})},Bz.prototype.extend=function(e){if(e.commands)e=e.commands;else if(e instanceof zz){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)},Bz.prototype.getBoundingBox=function(){for(var e=new zz,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},Bz.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())},Bz.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},Bz.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},Bz.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 Vz(e){throw Error(e)}function Hz(e,t){e||Vz(t)}var K={fail:Vz,argument:Hz,assert:Hz},Uz=32768,Wz=2147483648,Gz={},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>=Uz&&(e=-(2*Uz-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>=Wz&&(e=-(2*Wz-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,Gz.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)},Gz.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 qz={"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ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ`};Gz.MACSTRING=function(e,t,n,r){var i=qz[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,Yz,Xz=function(e){if(!Yz)for(var t in Yz={},qz)Yz[t]=new String(t);var n=Yz[e];if(n!==void 0){if(Jz){var r=Jz.get(n);if(r!==void 0)return r}var i=qz[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=Xz(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 Qz(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 $z(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 eB(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?Qz(e,t,n):r>=-128&&r<=127?$z(e,t,n):eB(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 tB=typeof WeakMap==`function`&&new WeakMap;q.CHARSTRING=function(e){if(tB){var t=tB.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 tB&&tB.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 nB(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)}}nB.prototype.encode=function(){return q.TABLE(this)},nB.prototype.sizeOf=function(){return J.TABLE(this)};function rB(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 iB(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 aB(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 oB(e){e.format===1?nB.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:1}].concat(rB(`glyph`,e.glyphs))):e.format===2?nB.call(this,`coverageTable`,[{name:`coverageFormat`,type:`USHORT`,value:2}].concat(aB(`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.`)}oB.prototype=Object.create(nB.prototype),oB.prototype.constructor=oB;function sB(e){nB.call(this,`scriptListTable`,aB(`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 nB(`scriptTable`,[{name:`defaultLangSys`,type:`TABLE`,value:new nB(`defaultLangSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:r.reqFeatureIndex}].concat(rB(`featureIndex`,r.featureIndexes)))}].concat(aB(`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 nB(`langSys`,[{name:`lookupOrder`,type:`USHORT`,value:0},{name:`reqFeatureIndex`,type:`USHORT`,value:n.reqFeatureIndex}].concat(rB(`featureIndex`,n.featureIndexes)))}]})))}]}))}sB.prototype=Object.create(nB.prototype),sB.prototype.constructor=sB;function cB(e){nB.call(this,`featureListTable`,aB(`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 nB(`featureTable`,[{name:`featureParams`,type:`USHORT`,value:n.featureParams}].concat(rB(`lookupListIndex`,n.lookupListIndexes)))}]}))}cB.prototype=Object.create(nB.prototype),cB.prototype.constructor=cB;function lB(e,t){nB.call(this,`lookupListTable`,iB(`lookup`,e,function(e){var n=t[e.lookupType];return K.assert(!!n,`Unable to write GSUB lookup type `+e.lookupType+` tables.`),new nB(`lookupTable`,[{name:`lookupType`,type:`USHORT`,value:e.lookupType},{name:`lookupFlag`,type:`USHORT`,value:e.lookupFlag}].concat(iB(`subtable`,e.subtables,n)))}))}lB.prototype=Object.create(nB.prototype),lB.prototype.constructor=lB;var Y={Table:nB,Record:nB,Coverage:oB,ScriptList:sB,FeatureList:cB,LookupList:lB,ushortList:rB,tableList:iB,recordList:aB};function uB(e,t){return e.getUint8(t)}function dB(e,t){return e.getUint16(t,!1)}function fB(e,t){return e.getInt16(t,!1)}function pB(e,t){return e.getUint32(t,!1)}function mB(e,t){return e.getInt16(t,!1)+e.getUint16(t+2,!1)/65535}function hB(e,t){for(var n=``,r=t;r<t+4;r+=1)n+=String.fromCharCode(e.getInt8(r));return n}function gB(e,t,n){for(var r=0,i=0;i<n;i+=1)r<<=8,r+=e.getUint8(t+i);return r}function _B(e,t,n){for(var r=[],i=t;i<n;i+=1)r.push(e.getUint8(i));return r}function vB(e){for(var t=``,n=0;n<e.length;n+=1)t+=String.fromCharCode(e[n]);return t}var yB={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=pB(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,e},X.prototype.parseOffset32=X.prototype.parseULong,X.prototype.parseFixed=function(){var e=mB(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=pB(this.data,this.offset+this.relativeOffset+4);return e-=2082844800,this.relativeOffset+=8,e},X.prototype.parseVersion=function(e){var t=dB(this.data,this.offset+this.relativeOffset),n=dB(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+=yB[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 bB={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(bB),langSysRecords:X.recordList({tag:X.tag,langSys:X.pointer(bB)})})}))||[]},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:uB,getCard8:uB,getUShort:dB,getCard16:dB,getShort:fB,getULong:pB,getFixed:mB,getTag:hB,getOffset:gB,getBytes:_B,bytesToString:vB,Parser:X};function xB(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 SB(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 CB(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)xB(n,s);else if(n.format===4)SB(n,s,e,t,r);else throw Error(`Only format 4 and 12 cmap tables are supported (found format `+n.format+`).`);return n}function wB(e,t,n){e.segments.push({end:t,start:t,delta:-(t-n),offset:0,glyphIndex:n})}function TB(e){e.segments.push({end:65535,start:65535,delta:1,offset:0})}function EB(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)wB(i,a.unicodes[o],n);i.segments=i.segments.sort(function(e,t){return e.start-t.start})}TB(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 DB={parse:CB,make:EB},OB=`.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(`,`),kB=`................................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(`.`),AB=`................................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(`.`),jB=`.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 MB(e){this.font=e}MB.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 NB(e){this.cmap=e}NB.prototype.charToGlyphIndex=function(e){return this.cmap.glyphIndexMap[e.codePointAt(0)]||0};function PB(e,t){this.encoding=e,this.charset=t}PB.prototype.charToGlyphIndex=function(e){var t=e.codePointAt(0),n=this.encoding[t];return this.charset.indexOf(n)};function FB(e){switch(e.version){case 1:this.names=jB.slice();break;case 2:this.names=Array(e.numberOfGlyphs);for(var t=0;t<e.numberOfGlyphs;t++)e.glyphNameIndex[t]<jB.length?this.names[t]=jB[e.glyphNameIndex[t]]:this.names[t]=e.names[e.glyphNameIndex[t]-jB.length];break;case 2.5:this.names=Array(e.numberOfGlyphs);for(var n=0;n<e.numberOfGlyphs;n++)this.names[n]=jB[n+e.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}FB.prototype.nameToGlyphIndex=function(e){return this.names.indexOf(e)},FB.prototype.glyphIndexToName=function(e){return this.names[e]};function IB(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 LB(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 RB(e,t){t.lowMemory?LB(e):IB(e)}function zB(e,t,n,r,i){e.beginPath(),e.moveTo(t,n),e.lineTo(r,i),e.stroke()}var BB={line:zB};function VB(e,t){var n=t||new Bz;return{configurable:!0,get:function(){return typeof n==`function`&&(n=n()),n},set:function(e){n=e}}}function HB(e){this.bindConstructorValues(e)}HB.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",VB(this,e.path))},HB.prototype.addUnicode=function(e){this.unicodes.length===0&&(this.unicode=e),this.unicodes.push(e)},HB.prototype.getBoundingBox=function(){return this.path.getBoundingBox()},HB.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 Bz,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},HB.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},HB.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},HB.prototype.draw=function(e,t,n,r,i){this.getPath(t,n,r,i).draw(e)},HB.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)},HB.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`,BB.line(e,t,-1e4,t,1e4),BB.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`,BB.line(e,t+a*i,-1e4,t+a*i,1e4),BB.line(e,t+s*i,-1e4,t+s*i,1e4),BB.line(e,-1e4,n+-o*i,1e4,n+-o*i),BB.line(e,-1e4,n+-c*i,1e4,n+-c*i),e.strokeStyle=`green`,BB.line(e,t+l*i,-1e4,t+l*i,1e4)};function UB(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 WB(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}WB.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]},WB.prototype.push=function(e,t){this.glyphs[e]=t,this.length++};function GB(e,t){return new HB({index:t,font:e})}function KB(e,t,n,r,i,a){return function(){var o=new HB({index:t,font:e});return o.path=function(){n(o,r,i);var t=a(e.glyphs,o);return t.unitsPerEm=e.unitsPerEm,t},UB(o,`xMin`,`_xMin`),UB(o,`xMax`,`_xMax`),UB(o,`yMin`,`_yMin`),UB(o,`yMax`,`_yMax`),o}}function qB(e,t,n,r){return function(){var i=new HB({index:t,font:e});return i.path=function(){var t=n(e,i,r);return t.unitsPerEm=e.unitsPerEm,t},i}}var JB={GlyphSet:WB,glyphLoader:GB,ttfGlyphLoader:KB,cffGlyphLoader:qB};function YB(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(!YB(e[n],t[n]))return!1;return!0}else return!1}function XB(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 QB(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 $B(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 eV(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 tV(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 eV(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 nV(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 rV(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(tV(r,o))}return nV(i)}function iV(e,t){return t=t<=390?OB[t]:e[t-391],t}function aV(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=iV(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=iV(n,i)),r[o.name]=i}return r}function oV(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 sV=[{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`}],cV=[{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 lV(e,t){return aV(rV(e,0,e.byteLength),sV,t)}function uV(e,t,n,r){return aV(rV(e,t,n),cV,r)}function dV(e,t,n,r){for(var i=[],a=0;a<n.length;a+=1){var o=lV(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=uV(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=XB(o._subrs)),o._privateDict=l}i.push(o)}return i}function fV(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(iV(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(iV(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(iV(r,i)),i+=1}else throw Error(`Unknown charset format `+c);return s}function pV(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 PB(i,n)}function mV(e,t,n){var r,i,a,o,s=new Bz,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 hV(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 gV(e,t,n,r){n.tables.cff={};var i=ZB(e,ZB(e,oV(e,t).endOffset,Z.bytesToString).endOffset),a=ZB(e,i.endOffset,Z.bytesToString);n.gsubrs=ZB(e,a.endOffset).objects,n.gsubrsBias=XB(n.gsubrs);var o=dV(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=dV(e,t,ZB(e,c).objects,a.objects);s._fdArray=u,l+=t,s._fdSelect=hV(e,l,n.numGlyphs,u.length)}var d=t+s.private[1],f=uV(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=XB(n.subrs));var p;r.lowMemory?(p=QB(e,t+s.charStrings),n.nGlyphs=p.offsets.length):(p=ZB(e,t+s.charStrings),n.nGlyphs=p.objects.length);var m=fV(e,t+s.charset,n.nGlyphs,a.objects);if(s.encoding===0?n.cffEncoding=new PB(kB,m):s.encoding===1?n.cffEncoding=new PB(AB,m):n.cffEncoding=pV(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=$B(r,p.offsets,e,t+s.charStrings);n.glyphs.push(r,JB.cffGlyphLoader(n,r,mV,i))};else for(var h=0;h<n.nGlyphs;h+=1){var g=p.objects[h];n.glyphs.push(h,JB.cffGlyphLoader(n,h,mV,g))}}function _V(e,t){var n,r=OB.indexOf(e);return r>=0&&(n=r),r=t.indexOf(e),r>=0?n=r+OB.length:(n=OB.length+t.length,t.push(e)),n}function vV(){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 yV(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 bV(e,t,n){for(var r={},i=0;i<e.length;i+=1){var a=e[i],o=t[a.name];o!==void 0&&!YB(o,a.value)&&(a.type===`SID`&&(o=_V(o,n)),r[a.op]={name:a.name,type:a.type,value:o})}return r}function xV(e,t){var n=new Y.Record(`Top DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=bV(sV,e,t),n}function SV(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 CV(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 wV(){return new Y.Record(`Global Subr INDEX`,[{name:`subrs`,type:`INDEX`,value:[]}])}function TV(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=_V(i,t);n.fields.push({name:`glyph_`+r,type:`SID`,value:a})}return n}function EV(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 DV(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=EV(r);t.charStrings.push({name:r.name,type:`CHARSTRING`,value:i})}return t}function OV(e,t){var n=new Y.Record(`Private DICT`,[{name:`dict`,type:`DICT`,value:{}}]);return n.dict=bV(cV,e,t),n}function kV(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=vV(),n.nameIndex=yV([t.postScriptName]);var u=xV(i,l);return n.topDictIndex=SV(u),n.globalSubrIndex=wV(),n.charsets=TV(o,l),n.charStringsIndex=DV(e),n.privateDict=OV(a,l),n.stringIndex=CV(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=xV(i,l),n.topDictIndex=SV(u),n}var AV={parse:gV,make:kV};function jV(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 MV(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 NV={parse:jV,make:MV};function PV(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 FV(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 IV={parse:PV,make:FV};function LV(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 RV(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 zV(e,t,n,r,i,a,o){o.lowMemory?RV(e,t,n,r,i):LV(t,n,r,i,a)}function BV(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 VV={parse:zV,make:BV};function HV(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 UV(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 WV={make:HV,parse:UV};function GV(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 qV={parse:GV,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`],YV={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`},XV={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 QV(e,t,n){switch(e){case 0:if(t===65535)return`und`;if(n)return n[t];break;case 1:return YV[t];case 3:return ZV[t]}}var $V=`utf-16`,eH={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`},tH={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 nH(e,t,n){switch(e){case 0:return $V;case 1:return tH[n]||eH[t];case 3:if(t===1||t===10)return $V;break}}function rH(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=QV(l,d,n),_=nH(l,u,d);if(_!==void 0&&g!==void 0){var v=void 0;if(v=_===$V?Gz.UTF16(e,s+h,m):Gz.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 iH(e){var t={};for(var n in e)t[e[n]]=parseInt(n);return t}function aH(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 oH(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 sH(e,t){var n=oH(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 cH(e,t){var n,r=[],i={},a=iH(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=iH(YV),l=iH(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=XV[_],y=nH(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=sH(b,d);u.push(aH(g,v,_,n,b.length,x));var S=l[m];if(S!==void 0){var C=q.UTF16(h),w=sH(C,d);u.push(aH(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 lH={parse:rH,make:cH},uH=[{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 dH(e){for(var t=0;t<uH.length;t+=1){var n=uH[t];if(e>=n.begin&&e<n.end)return t}return-1}function fH(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 pH(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 mH={parse:fH,make:pH,unicodeRanges:uH,getUnicodeRange:dH};function hH(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=jB.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]>=jB.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 gH(){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 _H={parse:hH,make:gH},vH=Array(9);vH[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.`)},vH[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()}},vH[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()}},vH[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 yH={sequenceIndex:X.uShort,lookupListIndex:X.uShort};vH[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,yH)}})};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,yH)}})};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,yH)}}K.assert(!1,`0x`+e.toString(16)+`: lookup type 5 format must be 1, 2 or 3.`)},vH[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(yH)}})};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(yH)}})};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(yH)};K.assert(!1,`0x`+e.toString(16)+`: lookup type 6 format must be 1, 2 or 3.`)},vH[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:vH[t].call(n)}},vH[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 bH(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(vH)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(vH),variations:n.parseFeatureVariationsList()}}var xH=Array(9);xH[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)))},xH[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))})))},xH[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))})))},xH[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)))}))})))},xH[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 SH(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,xH)}])}var CH={parse:bH,make:SH};function wH(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]=Gz.UTF8(e,t+c,l)}return a}function TH(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 EH={parse:wH,make:TH};function DH(e){return Math.log(e)/Math.log(2)|0}function OH(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 kH(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 AH(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**DH(t.numTables);t.searchRange=16*n,t.entrySelector=DH(n),t.rangeShift=t.numTables*16-t.searchRange;for(var r=[],i=[],a=t.sizeOf()+kH().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=kH(s.tableName,OH(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 jH(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 MH(e){for(var t=0,n=0;n<e.length;n+=1)t+=e[n];return t/e.length}function NH(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 _=mH.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:MH(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=NV.make({flags:3,unitsPerEm:e.unitsPerEm,xMin:y.xMin,yMin:y.yMin,xMax:y.xMax,yMax:y.yMax,lowestRecPPEM:3,createdTimestamp:e.createdTimestamp}),x=IV.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=qV.make(e.glyphs.length),C=mH.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:jH(e,`xyvw`,{yMax:Math.round(y.ascender/2)}).yMax,sCapHeight:jH(e,`HIKLEFJMNTZBDPRAGOQSUVWXY`,y).yMax,usDefaultChar:e.hasChar(` `)?32:0,usBreakChar:e.hasChar(` `)?32:0},e.tables.os2)),w=VV.make(e.glyphs),ee=DB.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=lH.make(ae,se),le=se.length>0?WV.make(se):void 0,ue=_H.make(),de=AV.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?EH.make(e.metas):void 0,pe=[b,x,S,C,ce,ee,ue,de,w];le&&pe.push(le),e.tables.gsub&&pe.push(CH.make(e.tables.gsub)),fe&&pe.push(fe);for(var me=AH(pe),he=OH(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 PH={make:AH,fontToTable:NH,computeCheckSum:OH};function FH(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 IH(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 LH(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 RH(e,t){this.font=e,this.tableName=t}RH.prototype={searchTag:FH,binSearch:IH,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=FH(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=FH(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=LH(e.ranges,t);return n?n.classId:0}},getCoverageIndex:function(e,t){switch(e.format){case 1:var n=IH(e.glyphs,t);return n>=0?n:-1;case 2:var r=LH(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 zH(e){RH.call(this,e,`gpos`)}zH.prototype=RH.prototype,zH.prototype.init=function(){var e=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(e)},zH.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},zH.prototype.getKerningTables=function(e,t){if(this.font.tables.gpos)return this.getLookupTables(e,t,`kern`,2)};function BH(e){RH.call(this,e,`gsub`)}function VH(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 HH(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}BH.prototype=RH.prototype,BH.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:`DFLT`,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}},BH.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},BH.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},BH.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},BH.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},BH.prototype.addSingle=function(e,t,n,r){var i=this.getLookupTables(n,r,e,1,!0)[0],a=HH(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},BH.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=HH(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},BH.prototype.addAlternate=function(e,t,n,r){var i=this.getLookupTables(n,r,e,3,!0)[0],a=HH(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},BH.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(VH(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])},BH.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)}},BH.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 UH(){return typeof window<`u`}function WH(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 GH(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 qH(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=qH(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=qH(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 YH(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 XH(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 Bz;if(!e)return t;for(var n=XH(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 QH(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=YH(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=YH([s],c)[0],c.dx=o.x-s.x,c.dy=o.y-s.y,a=YH(i.points,c)}t.points=t.points.concat(a)}}return ZH(t.points)}function $H(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,QH))}return i}function eU(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,QH))},i}function tU(e,t,n,r,i){return i.lowMemory?eU(e,t,n,r):$H(e,t,n,r)}var nU={getPath:ZH,parse:tU},rU,iU,aU,oU;function sU(e){this.font=e,this.getCommands=function(e){return nU.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function cU(e){return e}function lU(e){return Math.sign(e)*Math.round(Math.abs(e))}function uU(e){return Math.sign(e)*Math.round(Math.abs(e*2))/2}function dU(e){return Math.sign(e)*(Math.round(Math.abs(e)+.5)-.5)}function fU(e){return Math.sign(e)*Math.ceil(Math.abs(e))}function pU(e){return Math.sign(e)*Math.floor(Math.abs(e))}var mU=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},hU={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){hU.setRelative(e,e,(c+l)/2,r,!0);return}hU.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}},gU={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){gU.setRelative(e,e,(c+l)/2,r,!0);return}gU.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(hU),Object.freeze(gU);function _U(e,t){this.x=e,this.y=t,this.axis=void 0,this.slope=t/e,this.normalSlope=-e/t,Object.freeze(this)}_U.prototype.distance=function(e,t,n,r){return this.x*hU.distance(e,t,n,r)+this.y*gU.distance(e,t,n,r)},_U.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)},_U.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},_U.prototype.touch=function(e){e.xTouched=!0,e.yTouched=!0};function vU(e,t){var n=Math.sqrt(e*e+t*t);return e/=n,t/=n,e===1&&t===0?hU:e===0&&t===1?gU:new _U(e,t)}function yU(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)}yU.prototype.nextTouched=function(e){for(var t=this.nextPointOnContour;!e.touched(t)&&t!==this;)t=t.nextPointOnContour;return t},yU.prototype.prevTouched=function(e){for(var t=this.prevPointOnContour;!e.touched(t)&&t!==this;)t=t.prevPointOnContour;return t};var bU=Object.freeze(new yU(0,0)),xU={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function SU(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=hU,this.round=lU}}sU.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){SU.prototype=xU,i=this._fpgmState=new SU(`fpgm`,n.tables.fpgm),i.funcs=[],i.font=n,exports.DEBUG&&(console.log(`---EXEC FPGM---`),i.step=-1);try{iU(i)}catch(e){console.log(`Hinting error in FPGM:`+e),this._errorState=3;return}}SU.prototype=i,r=this._prepState=new SU(`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{iU(r)}catch(e){this._errorState<2&&console.log(`Hinting error in PREP:`+e),this._errorState=2}}if(!(this._errorState>1))try{return aU(e,r)}catch(e){this._errorState<1&&(console.log(`Hinting error:`+e),console.log(`Note: further hinting errors are silenced`)),this._errorState=1;return}}},aU=function(e,t){var n=t.ppem/t.font.unitsPerEm,r=n,i=e.components,a,o,s;if(SU.prototype=t,!i)s=new SU(`glyf`,e.instructions),exports.DEBUG&&(console.log(`---EXEC GLYPH---`),s.step=-1),oU(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 SU(`glyf`,d.instructions),exports.DEBUG&&(console.log(`---EXEC COMP `+l+`---`),s.step=-1),oU(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 SU(`glyf`,e.instructions),s.gZone=s.z0=s.z1=s.z2=o,s.contours=a,o.push(new yU(0,0),new yU(Math.round(e.advanceWidth*n),0)),exports.DEBUG&&(console.log(`---EXEC COMPOSITE---`),s.step=-1),iU(s),o.length-=2)}return o},oU=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 yU(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 yU(0,0),new yU(Math.round(e.advanceWidth*n),0)),iU(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)}}},iU=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=rU[t[e.ip]],!r)throw Error(`unknown instruction: 0x`+Number(t[e.ip]).toString(16));r(e)}}};function CU(e){for(var t=e.tZone=Array(e.gZone.length),n=0;n<t.length;n++)t[n]=new yU(0,0)}function wU(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 TU(e,t){exports.DEBUG&&console.log(t.step,`SVTCA[`+e.axis+`]`),t.fv=t.pv=t.dpv=e}function EU(e,t){exports.DEBUG&&console.log(t.step,`SPVTCA[`+e.axis+`]`),t.pv=t.dpv=e}function DU(e,t){exports.DEBUG&&console.log(t.step,`SFVTCA[`+e.axis+`]`),t.fv=e}function OU(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=vU(s,c)}function kU(e,t){var n=t.stack,r=n.pop(),i=n.pop(),a=t.z2[r],o=t.z1[i];exports.DEBUG&&console.log(`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=vU(s,c)}function AU(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.pv=e.dpv=vU(r,n)}function jU(e){var t=e.stack,n=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,`SPVFS[]`,n,r),e.fv=vU(r,n)}function MU(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 NU(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 PU(e){e.fv=e.pv,exports.DEBUG&&console.log(e.step,`SFVTPV[]`)}function FU(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 IU(e){e.rp0=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP0[]`,e.rp0)}function LU(e){e.rp1=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP1[]`,e.rp1)}function RU(e){e.rp2=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SRP2[]`,e.rp2)}function zU(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP0[]`,t),e.zp0=t,t){case 0:e.tZone||CU(e),e.z0=e.tZone;break;case 1:e.z0=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function BU(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP1[]`,t),e.zp1=t,t){case 0:e.tZone||CU(e),e.z1=e.tZone;break;case 1:e.z1=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function VU(e){var t=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,`SZP2[]`,t),e.zp2=t,t){case 0:e.tZone||CU(e),e.z2=e.tZone;break;case 1:e.z2=e.gZone;break;default:throw Error(`Invalid zone pointer`)}}function HU(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||CU(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 UU(e){e.loop=e.stack.pop(),exports.DEBUG&&console.log(e.step,`SLOOP[]`,e.loop)}function WU(e){exports.DEBUG&&console.log(e.step,`RTG[]`),e.round=lU}function GU(e){exports.DEBUG&&console.log(e.step,`RTHG[]`),e.round=dU}function KU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SMD[]`,t),e.minDis=t/64}function qU(e){exports.DEBUG&&console.log(e.step,`ELSE[]`),wU(e,!1)}function JU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`JMPR[]`,t),e.ip+=t-1}function YU(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCVTCI[]`,t),e.cvCutIn=t/64}function XU(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 QU(e){exports.DEBUG&&console.log(e.step,`CLEAR[]`),e.stack.length=0}function $U(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 eW(e){var t=e.stack;exports.DEBUG&&console.log(e.step,`DEPTH[]`),t.push(t.length)}function tW(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++)iU(e),exports.DEBUG&&console.log(++e.step,o+1<r?`next loopcall`:`done loopcall`,o);e.ip=i,e.prog=a}function nW(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],iU(e),e.ip=n,e.prog=r,exports.DEBUG&&console.log(++e.step,`returning from`,t)}function rW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`CINDEX[]`,n),t.push(t[t.length-n])}function iW(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 aW(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 oW(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,bU);e&&(o=t.round(o)),i.setRelative(r,bU,o,a),i.touch(r),t.rp0=t.rp1=n}function sW(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 cW(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 lW(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 uW(e,t){var n=t.stack,r=e?t.rp1:t.rp2,i=(e?t.z0:t.z1)[r],a=t.fv,o=t.pv,s=n.pop();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 dW(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 fW(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 pW(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 mW(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 hW(e){exports.DEBUG&&console.log(e.step,`RTDG[]`),e.round=uU}function gW(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,bU);e&&(Math.abs(l-c)<t.cvCutIn&&(l=c),l=t.round(l)),o.setRelative(a,bU,l,s),t.zp0===0&&(a.xo=a.x,a.yo=a.y),o.touch(a),t.rp0=t.rp1=i}function _W(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 vW(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 yW(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 bW(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 xW(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 SW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`RCVT`,n),t.push(e.cvt[n]*64)}function CW(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,bU,e,!1)*64)}function wW(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 TW(e){exports.DEBUG&&console.log(e.step,`MPPEM[]`),e.stack.push(e.ppem)}function EW(e){exports.DEBUG&&console.log(e.step,`FLIPON[]`),e.autoFlip=!0}function DW(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 OW(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 kW(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 AW(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 jW(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 MW(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 NW(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 PW(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 FW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`IF[]`,t),t||(wU(e,!0),exports.DEBUG&&console.log(e.step,`EIF[]`))}function IW(e){exports.DEBUG&&console.log(e.step,`EIF[]`)}function LW(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 RW(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 zW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`NOT[]`,n),t.push(+!n)}function BW(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 VW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDB[]`,t),e.deltaBase=t}function HW(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SDS[]`,t),e.deltaShift=.5**t}function UW(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 WW(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 GW(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 qW(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 YW(e){var t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,`FLOOR[]`,n),t.push(Math.floor(n/64)*64)}function XW(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 QW(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 $W(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 eG(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SROUND[]`,t),e.round=mU;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 tG(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`S45ROUND[]`,t),e.round=mU;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 nG(e){exports.DEBUG&&console.log(e.step,`ROFF[]`),e.round=cU}function rG(e){exports.DEBUG&&console.log(e.step,`RUTG[]`),e.round=fU}function iG(e){exports.DEBUG&&console.log(e.step,`RDTG[]`),e.round=pU}function aG(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANCTRL[]`,t)}function oG(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=vU(s,c)}function sG(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 cG(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 lG(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 uG(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 dG(e){var t=e.stack.pop();exports.DEBUG&&console.log(e.step,`SCANTYPE[]`,t)}function fG(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 pG(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 mG(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)}rU=[TU.bind(void 0,gU),TU.bind(void 0,hU),EU.bind(void 0,gU),EU.bind(void 0,hU),DU.bind(void 0,gU),DU.bind(void 0,hU),OU.bind(void 0,0),OU.bind(void 0,1),kU.bind(void 0,0),kU.bind(void 0,1),AU,jU,MU,NU,PU,FU,IU,LU,RU,zU,BU,VU,HU,UU,WU,GU,KU,qU,JU,YU,void 0,void 0,XU,ZU,QU,$U,eW,rW,iW,void 0,void 0,void 0,tW,nW,aW,void 0,oW.bind(void 0,0),oW.bind(void 0,1),sW.bind(void 0,gU),sW.bind(void 0,hU),cW.bind(void 0,0),cW.bind(void 0,1),lW.bind(void 0,0),lW.bind(void 0,1),uW.bind(void 0,0),uW.bind(void 0,1),dW,fW,pW.bind(void 0,0),pW.bind(void 0,1),mW,hW,gW.bind(void 0,0),gW.bind(void 0,1),_W,vW,yW,bW,xW,SW,CW.bind(void 0,0),CW.bind(void 0,1),void 0,wW.bind(void 0,0),wW.bind(void 0,1),TW,void 0,EW,void 0,void 0,DW,OW,kW,AW,jW,MW,NW,PW,FW,IW,LW,RW,zW,BW.bind(void 0,1),VW,HW,UW,WW,GW,KW,qW,JW,YW,XW,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,QW,BW.bind(void 0,2),BW.bind(void 0,3),$W.bind(void 0,1),$W.bind(void 0,2),$W.bind(void 0,3),eG,tG,void 0,void 0,nG,void 0,rG,iG,ZU,ZU,void 0,void 0,void 0,void 0,void 0,aG,oG.bind(void 0,0),oG.bind(void 0,1),sG,void 0,cG,lG,uG,dG,fG,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,pG.bind(void 0,1),pG.bind(void 0,2),pG.bind(void 0,3),pG.bind(void 0,4),pG.bind(void 0,5),pG.bind(void 0,6),pG.bind(void 0,7),pG.bind(void 0,8),mG.bind(void 0,1),mG.bind(void 0,2),mG.bind(void 0,3),mG.bind(void 0,4),mG.bind(void 0,5),mG.bind(void 0,6),mG.bind(void 0,7),mG.bind(void 0,8),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 hG(e){this.char=e,this.state={},this.activeState=null}function gG(e,t,n){this.contextName=n,this.startIndex=e,this.endOffset=t}function _G(e,t,n){this.contextName=e,this.openRange=null,this.ranges=[],this.checkStart=t,this.checkEnd=n}function vG(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 yG(e){this.eventId=e,this.subscribers=[]}function bG(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 yG(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 xG(e){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],bG.call(this,e)}hG.prototype.setState=function(e,t){return this.state[e]=t,this.activeState={key:e,value:this.state[e]},this.activeState},hG.prototype.getState=function(e){return this.state[e]||null},xG.prototype.inboundIndex=function(e){return e>=0&&e<this.tokens.length},xG.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)})])},xG.prototype.replaceRange=function(e,t,n,r){t=t===null?this.tokens.length:t;var i=n.every(function(e){return e instanceof hG});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.`}},xG.prototype.replaceToken=function(e,t,n){if(!isNaN(e)&&this.inboundIndex(e)&&t instanceof hG){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.`}},xG.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},xG.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.`}},xG.prototype.insertToken=function(e,t,n){return e.every(function(e){return e instanceof hG})?(this.tokens.splice.apply(this.tokens,[t,0].concat(e)),n||this.dispatch(`insertToken`,[e,t]),e):{FAIL:`insertToken: invalid token(s).`}},xG.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)},yG.prototype.subscribe=function(e){return typeof e==`function`?this.subscribers.push(e)-1:{FAIL:`invalid '`+this.eventId+`' event handler`}},yG.prototype.unsubscribe=function(e){this.subscribers.splice(e,1)},vG.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)},vG.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}},xG.prototype.rangeToText=function(e){if(e instanceof gG)return this.getRangeTokens(e).map(function(e){return e.char}).join(``)},xG.prototype.getText=function(){return this.tokens.map(function(e){return e.char}).join(``)},xG.prototype.getContext=function(e){return this.registeredContexts[e]||null},xG.prototype.on=function(e,t){var n=this.events[e];return n?n.subscribe(t):null},xG.prototype.dispatch=function(e,t){var n=this,r=this.events[e];r instanceof yG&&r.subscribers.forEach(function(e){e.apply(n,t||[])})},xG.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 _G(e,t,n);return this.registeredContexts[e]=r,this.contextCheckers.push(r),r},xG.prototype.getRangeTokens=function(e){var t=e.startIndex+e.endOffset;return[].concat(this.tokens.slice(e.startIndex,t))},xG.prototype.getContextRanges=function(e){var t=this.getContext(e);return t?t.ranges:{FAIL:`context checker '`+e+`' is not registered.`}},xG.prototype.resetContextsRanges=function(){var e=this.registeredContexts;for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];n.ranges=[]}},xG.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 vG(e,t);this.runContextCheck(n)}this.dispatch(`updateContextsRanges`,[this.registeredContexts])},xG.prototype.setEndOffset=function(e,t){var n=this.getContext(t).openRange.startIndex,r=new gG(n,e,t),i=this.getContext(t).ranges;return r.rangeId=t+`.`+i.length,i.push(r),this.getContext(t).openRange=null,r},xG.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 gG(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])}})},xG.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 vG(t,n);this.dispatch(`next`,[i]),this.runContextCheck(i);var a=new hG(r);this.tokens.push(a),this.dispatch(`newToken`,[a,i])}return this.dispatch(`end`,[this.tokens]),this.tokens};function SG(e){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(e)}function CG(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 wG(e){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(e)}function TG(e){return/[A-z]/.test(e)}function EG(e){return/\s/.test(e)}function DG(e){this.font=e,this.features={}}function OG(e){this.id=e.id,this.tag=e.tag,this.substitution=e.substitution}function kG(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 AG(e,t){return kG(e,t.coverage)===-1?null:e+t.deltaGlyphId}function jG(e,t){var n=kG(e,t.coverage);return n===-1?null:t.substitute[n]}function MG(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=kG(a,i);o!==-1&&n.push(o)}return n.length===e.length?n:-1}function NG(e,t){var n=t.inputCoverage.length+t.lookaheadCoverage.length+t.backtrackCoverage.length;if(e.context.length<n)return[];var r=MG(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&&wG(a[0].char);)a.shift();var o=new vG(a,0),s=MG(t.lookaheadCoverage,o),c=[].concat(e.backtrack);for(c.reverse();c.length&&wG(c[0].char);)c.shift();if(c.length<t.backtrackCoverage.length)return[];var l=new vG(c,0),u=MG(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 PG(e,t){var n=e.current,r=kG(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 FG(e,t){var n=kG(e,t.coverage);return n===-1?null:t.sequences[n]}DG.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[]},DG.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()},DG.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},DG.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},DG.prototype.getSubstitutionType=function(e,t){return e.lookupType.toString()+t.substFormat.toString()},DG.prototype.getLookupMethod=function(e,t){var n=this;switch(this.getSubstitutionType(e,t)){case`11`:return function(e){return AG.apply(n,[e,t])};case`12`:return function(e){return jG.apply(n,[e,t])};case`63`:return function(e){return NG.apply(n,[e,t])};case`41`:return function(e){return PG.apply(n,[e,t])};case`21`:return function(e){return FG.apply(n,[e,t])};default:throw Error(`lookupType: `+e.lookupType+` - substFormat: `+t.substFormat+` is not yet supported`)}},DG.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 OG({id:11,tag:e.tag,substitution:p}));break;case`12`:p=f(t.current),p&&a.splice(n,1,new OG({id:12,tag:e.tag,substitution:p}));break;case`63`:p=f(t),Array.isArray(p)&&p.length&&a.splice(n,1,new OG({id:63,tag:e.tag,substitution:p}));break;case`41`:p=f(t),p&&a.splice(n,1,new OG({id:41,tag:e.tag,substitution:p}));break;case`21`:p=f(t.current),p&&a.splice(n,1,new OG({id:21,tag:e.tag,substitution:p}));break}t=new vG(a,n),!(Array.isArray(p)&&!p.length)&&(p=null)}return a.length?a:null},DG.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},DG.prototype.getLookupSubtables=function(e){return e.subtables||null},DG.prototype.getLookupByIndex=function(e){return this.font.tables.gsub.lookups[e]||null},DG.prototype.getFeatureLookups=function(e){return e.lookupListIndexes.map(this.getLookupByIndex.bind(this))},DG.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 IG(e){var t=e.current,n=e.get(-1);return n===null&&SG(t)||!SG(n)&&SG(t)}function LG(e){var t=e.get(1);return t===null||!SG(t)}var RG={startCheck:IG,endCheck:LG};function zG(e){var t=e.current,n=e.get(-1);return(SG(t)||wG(t))&&!SG(n)}function BG(e){var t=e.get(1);switch(!0){case t===null:return!0;case!SG(t)&&!wG(t):var n=EG(t);if(!n)return!0;if(n){var r=!1;if(r=e.lookahead.some(function(e){return SG(e)||wG(e)}),!r)return!0}break;default:return!1}}var VG={startCheck:zG,endCheck:BG};function HG(e,t,n){t[n].setState(e.tag,e.substitution)}function UG(e,t,n){t[n].setState(e.tag,e.substitution)}function WG(e,t,n){e.substitution.forEach(function(r,i){t[n+i].setState(e.tag,r)})}function GG(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:HG,12:UG,63:WG,41:GG};function qG(e,t,n){e instanceof OG&&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=CG(r),a=wG(r);if(!i&&!a)return!0;if(i)return!1}return!1}function YG(e){if(CG(e.current))return!1;for(var t=0;t<e.lookahead.length;t++){var n=e.lookahead[t];if(!wG(n))return!0}return!1}function XG(e){var t=this,n=`arab`,r=this.featuresTags[n],i=this.tokenizer.getRangeTokens(e);if(i.length!==1){var a=new vG(i.map(function(e){return e.getState(`glyphIndex`)}),0),o=new vG(i.map(function(e){return e.char}),0);i.forEach(function(e,s){if(!wG(e.char)){a.setCurrentIndex(s),o.setCurrentIndex(s);var c=0;JG(o)&&(c|=1),YG(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 OG&&(qG(e,i,t),a.context[t]=e.substitution)})}}})}}function ZG(e,t){return new vG(e.map(function(e){return e.activeState.value}),t||0)}function QG(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 qG(e,r,a)}),i=ZG(r))})}function $G(e){var t=e.current,n=e.get(-1);return n===null&&TG(t)||!TG(n)&&TG(t)}function eK(e){var t=e.get(1);return t===null||!TG(t)}var tK={startCheck:$G,endCheck:eK};function nK(e,t){return new vG(e.map(function(e){return e.activeState.value}),t||0)}function rK(e){var t=this,n=`latn`,r=this.tokenizer.getRangeTokens(e),i=nK(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 qG(e,r,a)}),i=nK(r))})}function iK(e){this.baseDir=e||`ltr`,this.tokenizer=new xG,this.featuresTags={}}iK.prototype.setText=function(e){this.text=e},iK.prototype.contextChecks={latinWordCheck:tK,arabicWordCheck:RG,arabicSentenceCheck:VG};function aK(e){var t=this.contextChecks[e+`Check`];return this.tokenizer.registerContextChecker(e,t.startCheck,t.endCheck)}function oK(){return aK.call(this,`latinWord`),aK.call(this,`arabicWord`),aK.call(this,`arabicSentence`),this.tokenizer.tokenize(this.text)}function sK(){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())})}iK.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},iK.prototype.applyFeatures=function(e,t){if(!e)throw Error(`No valid font was provided to apply features`);this.query||=new DG(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)}},iK.prototype.registerModifier=function(e,t,n){this.tokenizer.registerModifier(e,t,n)};function cK(){if(this.tokenizer.registeredModifiers.indexOf(`glyphIndex`)===-1)throw Error(`glyphIndex modifier is required to apply arabic presentation features.`)}function lK(){var e=this;this.featuresTags.hasOwnProperty(`arab`)&&(cK.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){XG.call(e,t)}))}function uK(){var e=this,t=`arab`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`rlig`)!==-1&&(cK.call(this),this.tokenizer.getContextRanges(`arabicWord`).forEach(function(t){QG.call(e,t)}))}function dK(){var e=this,t=`latn`;this.featuresTags.hasOwnProperty(t)&&this.featuresTags[t].indexOf(`liga`)!==-1&&(cK.call(this),this.tokenizer.getContextRanges(`latinWord`).forEach(function(t){rK.call(e,t)}))}iK.prototype.checkContextReady=function(e){return!!this.tokenizer.getContext(e)},iK.prototype.applyFeaturesToContexts=function(){this.checkContextReady(`arabicWord`)&&(lK.call(this),uK.call(this)),this.checkContextReady(`latinWord`)&&dK.call(this),this.checkContextReady(`arabicSentence`)&&sK.call(this)},iK.prototype.processText=function(e){(!this.text||this.text!==e)&&(this.setText(e),oK.call(this),this.applyFeaturesToContexts())},iK.prototype.getBidiText=function(e){return this.processText(e),this.tokenizer.getText()},iK.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 fK(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 MB(this),this.position=new zH(this),this.substitution=new BH(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 sU(this)}})}fK.prototype.hasChar=function(e){return this.encoding.charToGlyphIndex(e)!==null},fK.prototype.charToGlyphIndex=function(e){return this.encoding.charToGlyphIndex(e)},fK.prototype.charToGlyph=function(e){var t=this.charToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},fK.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})},fK.prototype.stringToGlyphs=function(e,t){var n=this,r=new iK;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},fK.prototype.nameToGlyphIndex=function(e){return this.glyphNames.nameToGlyphIndex(e)},fK.prototype.nameToGlyph=function(e){var t=this.nameToGlyphIndex(e),n=this.glyphs.get(t);return n||=this.glyphs.get(0),n},fK.prototype.glyphIndexToName=function(e){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(e):``},fK.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},fK.prototype.defaultRenderOptions={kerning:!0,features:[{script:`arab`,tags:[`init`,`medi`,`fina`,`rlig`]},{script:`latn`,tags:[`liga`,`rlig`]}]},fK.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},fK.prototype.getPath=function(e,t,n,r,i){var a=new Bz;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},fK.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},fK.prototype.getAdvanceWidth=function(e,t,n){return this.forEachGlyph(e,0,0,t,n,function(){})},fK.prototype.draw=function(e,t,n,r,i,a){this.getPath(t,n,r,i,a).draw(e)},fK.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)})},fK.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)})},fK.prototype.getEnglishName=function(e){var t=this.names[e];if(t)return t.en},fK.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},fK.prototype.toTables=function(){return PH.fontToTable(this)},fK.prototype.toBuffer=function(){return console.warn(`Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.`),this.toArrayBuffer()},fK.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},fK.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(UH())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=fz(),l=GH(r);c.writeFileSync(e,l)}},fK.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512},fK.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},fK.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function pK(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 mK(e,t,n){var r=pK(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 hK(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 gK(e,t,n,r){for(var i=pK(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 _K(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 vK(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(mK(r,e.axes[r],t));for(var i=0;i<e.instances.length;i++)n.fields=n.fields.concat(gK(i,e.instances[i],e.axes,t));return n}function yK(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(hK(e,t+a+d*s,n));for(var f=[],p=t+a+o*s,m=0;m<c;m++)f.push(_K(e,p+m*l,u,n));return{axes:u,instances:f}}var bK={make:vK,parse:yK},xK=function(){return{coverage:this.parsePointer(X.coverage),attachPoints:this.parseList(X.pointer(X.uShortList))}},SK=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()}},CK=function(){return this.parseList(X.pointer(SK))},wK=function(){return{coverage:this.parsePointer(X.coverage),ligGlyphs:this.parseList(X.pointer(CK))}},TK=function(){return this.parseUShort(),this.parseList(X.pointer(X.coverage))};function EK(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(xK),ligCaretList:n.parsePointer(wK),markAttachClassDef:n.parsePointer(X.classDef)};return r>=1.2&&(i.markGlyphSets=n.parsePointer(TK)),i}var DK={parse:EK},OK=Array(10);OK[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.`)},OK[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)}}))}}},OK[3]=function(){return{error:`GPOS Lookup 3 not supported`}},OK[4]=function(){return{error:`GPOS Lookup 4 not supported`}},OK[5]=function(){return{error:`GPOS Lookup 5 not supported`}},OK[6]=function(){return{error:`GPOS Lookup 6 not supported`}},OK[7]=function(){return{error:`GPOS Lookup 7 not supported`}},OK[8]=function(){return{error:`GPOS Lookup 8 not supported`}},OK[9]=function(){return{error:`GPOS Lookup 9 not supported`}};function kK(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(OK)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(OK),variations:n.parseFeatureVariationsList()}}var AK=Array(10);function jK(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,AK)}])}var MK={parse:kK,make:jK};function NK(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 PK(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 FK(e,t){var n=new Z.Parser(e,t),r=n.parseUShort();if(r===0)return NK(n);if(r===1)return PK(n);throw Error(`Unsupported kern table version (`+r+`).`)}var IK={parse:FK};function LK(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 RK={parse:LK};function zK(e,t){fz().readFile(e,function(e,n){if(e)return t(e.message);t(null,WH(n))})}function BK(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 VK(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 HK(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 UK(e,t){if(t.compression===`WOFF`){var n=new Uint8Array(e.buffer,t.offset+2,t.compressedLength-2),r=new Uint8Array(t.length);if(Lz(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 WK(e,t){t??={};var n,r,i=new fK({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=VK(a,o);else if(c===`OTTO`)i.outlinesFormat=`cff`,o=Z.getUShort(a,4),s=VK(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=HK(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=UK(a,C),i.tables.cmap=DB.parse(w.data,w.offset),i.encoding=new NB(i.tables.cmap);break;case`cvt `:w=UK(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=UK(a,C),x=new Z.Parser(w.data,w.offset),i.tables.fpgm=x.parseByteList(C.length);break;case`head`:w=UK(a,C),i.tables.head=NV.parse(w.data,w.offset),i.unitsPerEm=i.tables.head.unitsPerEm,n=i.tables.head.indexToLocFormat;break;case`hhea`:w=UK(a,C),i.tables.hhea=IV.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=UK(a,C),r=WV.parse(w.data,w.offset);break;case`maxp`:w=UK(a,C),i.tables.maxp=qV.parse(w.data,w.offset),i.numGlyphs=i.tables.maxp.numGlyphs;break;case`name`:y=C;break;case`OS/2`:w=UK(a,C),i.tables.os2=mH.parse(w.data,w.offset);break;case`post`:w=UK(a,C),i.tables.post=_H.parse(w.data,w.offset),i.glyphNames=new FB(i.tables.post);break;case`prep`:w=UK(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=UK(a,y);if(i.tables.name=lH.parse(ee.data,ee.offset,r),i.names=i.tables.name,f&&v){var te=n===0,ne=UK(a,v),re=RK.parse(ne.data,ne.offset,i.numGlyphs,te),ie=UK(a,f);i.glyphs=nU.parse(ie.data,ie.offset,re,i,t)}else if(u){var ae=UK(a,u);AV.parse(ae.data,ae.offset,i,t)}else throw Error(`Font doesn't contain TrueType or CFF outlines.`);var oe=UK(a,g);if(VV.parse(i,oe.data,oe.offset,i.numberOfHMetrics,i.numGlyphs,i.glyphs,t),RB(i,t),_){var se=UK(a,_);i.kerningPairs=IK.parse(se.data,se.offset)}else i.kerningPairs={};if(p){var ce=UK(a,p);i.tables.gdef=DK.parse(ce.data,ce.offset)}if(m){var le=UK(a,m);i.tables.gpos=MK.parse(le.data,le.offset),i.position.init()}if(h){var ue=UK(a,h);i.tables.gsub=CH.parse(ue.data,ue.offset)}if(d){var de=UK(a,d);i.tables.fvar=bK.parse(de.data,de.offset,i.names)}if(b){var fe=UK(a,b);i.tables.meta=EH.parse(fe.data,fe.offset),i.metas=i.tables.meta}return i}function GK(e,t,n){n??={};var r=typeof window>`u`&&!n.isUrl?zK:BK;return new Promise(function(i,a){r(e,function(e,r){if(e){if(t)return t(e);a(e)}var o;try{o=WK(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 WK(WH(fz().readFileSync(e)),t)}var qK=Object.freeze({__proto__:null,Font:fK,Glyph:HB,Path:Bz,BoundingBox:zz,_parse:Z,parse:WK,load:GK,loadSync:KK}),JK=class e{sketches;constructor(e){e.length===0&&i(`CompoundSketch`,`Cannot create CompoundSketch with an empty array of sketches`),this.sketches=e}delete(){this.sketches.forEach(e=>{e.delete()})}get outerSketch(){return vA(this.sketches)}get innerSketches(){return this.sketches.slice(1)}get wires(){return oq(this)}face(){return aq(this)}extrude(e,t={}){return sq(this,e,t)}revolve(e,t={}){return cq(this,e,t)}loftWith(t,n={}){return Array.isArray(t)||!(t instanceof e)?i(`CompoundSketch.loftWith`,`A compound (face-with-holes) sketch can only loft to another compound sketch with the same number of sub-sketches.`):lq(this,t,n)}sweepSketch(){return i(`CompoundSketch.sweepSketch`,`Sweeping a compound (face-with-holes) profile is not supported — sweep its outer Sketch instead.`)}};function YK(e){let t={};e.defaultOrigin&&(t.defaultOrigin=e.defaultOrigin),e.defaultDirection&&(t.defaultDirection=e.defaultDirection);let n=new uq(e.wire,t);return e.baseFace&&(n.baseFace=e.baseFace),n}function XK(e){return new JK(e.map(YK))}function ZK(e){if(e instanceof uq)return e;let t=e.sketches;if(Array.isArray(t)){let[e,...n]=t;if(e instanceof uq){for(let e of n)e.delete();return e}}i(`asSketch`,`Expected a single-wire profile to loft or sweep.`)}function QK(e){let t;return t=e.baseFace?FA(e.baseFace,e.wire):j(NA(e.wire)),t}function $K(e){return EE(j(dO(e.wire.wrapped)))}function eq(e,t,{origin:n}={}){let r=j(NA(e.wire)),i=j(AM(r,n?AD(n):e.defaultOrigin,t?AD(t):[0,0,1]));return r[Symbol.dispose](),e.delete(),i}function tq(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=ID(UD(n?AD(n):e.defaultDirection),t),s=a?AD(a):e.defaultOrigin;if(r&&!i){let t=j(CM(e.wire,[...s],[...o],r));return e.delete(),t}if(i){let t=j(wM(e.wire,i,[...s],[...o],r));return e.delete(),t}let c=j(NA(e.wire)),l=j(kM(c,[...o]));return c[Symbol.dispose](),e.delete(),l}function nq(e,t,n={}){let r=Mk(e.wire),i=UD(ID(Fk(e.wire,1e-9),-1)),a=e.defaultDirection,o=ID(zD(i,a),-1),s=ZK(t(ZD([...r],[...o],[...i]),[...r])),c={forceProfileSpineOthogonality:!0,...n};e.baseFace&&(c.support=e.baseFace.wrapped);let l=j(xM(s.wire,e.wire,c));return e.delete(),l}function rq(e,t,n={},r=!1){let i=[e,...(Array.isArray(t)?t:[t]).map(ZK)],a=j(MM(i.map(e=>e.wire),n,r));return i.forEach(e=>{e.delete()}),a}var iq=(e,t)=>{let n=j(t(vA(e))),r=e.slice(1).map(e=>j(t(e)));if(r.length===0)return n;try{return j(KA(n,r,{unsafe:!0}))}finally{n.delete();for(let e of r)e.delete()}};function aq(e){let t=e.outerSketch.face(),n=LA(t,e.innerSketches.map(e=>e.wire));return t[Symbol.dispose](),n}function oq(e){return hj(e.sketches.map(e=>e.wire))}function sq(e,t,{extrusionDirection:n,extrusionProfile:r,twistAngle:i,origin:a}={}){let o=ID(UD(n?AD(n):e.outerSketch.defaultDirection),t);if(r&&!i)return iq(e.sketches,t=>CM(t.wire,a?AD(a):e.outerSketch.defaultOrigin,o,r));if(i)return iq(e.sketches,t=>wM(t.wire,i,a?AD(a):e.outerSketch.defaultOrigin,o,r));let s=aq(e),c=j(kM(s,o));return s[Symbol.dispose](),c}function cq(e,t,{origin:n}={}){let r=n?AD(n):e.outerSketch.defaultOrigin,i=t?AD(t):[0,0,1],a=aq(e),o=j(AM(a,r,i));return a[Symbol.dispose](),o}function lq(e,t,n={}){e.sketches.length!==t.sketches.length&&i(`CompoundSketch.loftWith`,`You need to loft with another compound with the same number of sketches`);let r=e.sketches.map((e,r)=>{let i=_A(t.sketches,r),a={};return n.ruled!==void 0&&(a.ruled=n.ruled),e.clone().loftWith(i.clone(),a,!0)}),a=aq(e),o=DE(j(dO(a.wrapped)));a[Symbol.dispose](),r.push(o,aq(t));let s=j(gj(r));for(let e of r)e[Symbol.dispose]();return s}var uq=class e{wire;_defaultOrigin;_defaultDirection;_baseFace;constructor(e,{defaultOrigin:t=[0,0,0],defaultDirection:n=[0,0,1]}={}){this.wire=e,this._defaultOrigin=AD(t),this._defaultDirection=AD(n),this.baseFace=null}get baseFace(){return this._baseFace}set baseFace(e){this._baseFace&&this._baseFace[Symbol.dispose](),this._baseFace=e&&DE(j(dO(e.wrapped)))}delete(){this.wire[Symbol.dispose](),this.baseFace&&this.baseFace[Symbol.dispose]()}clone(){let t=EE(j(dO(this.wire.wrapped))),n=new e(t,{defaultOrigin:this.defaultOrigin,defaultDirection:this.defaultDirection});return this.baseFace&&(n.baseFace=DE(j(dO(this.baseFace.wrapped)))),n}get defaultOrigin(){return this._defaultOrigin}set defaultOrigin(e){this._defaultOrigin=AD(e)}get defaultDirection(){return this._defaultDirection}set defaultDirection(e){this._defaultDirection=AD(e)}face(){return QK(this)}wires(){return $K(this)}faces(){return this.face()}revolve(e,t={}){return eq(this,e,t)}extrude(e,t={}){return tq(this,e,t)}sweepSketch(e,t={}){return nq(this,e,t)}loftWith(e,t={},n=!1){return rq(this,e,t,n)}},dq=class{sketches;constructor(e){this.sketches=e}soleSketch(e){this.sketches.length!==1&&i(`Sketches.${e}`,`Multiple profiles — ${e} each sub-sketch individually.`);let t=vA(this.sketches);return t instanceof uq||i(`Sketches.${e}`,`${e} is only supported on single-wire profiles.`),t}face(){return this.sketches.length!==1&&i(`Sketches.face`,`Multiple profiles — use faces() to combine them.`),vA(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 hj(this.sketches.flatMap(e=>e instanceof uq?[e.wire]:e.sketches.map(e=>e.wire)))}faces(){return hj(this.sketches.map(e=>e.face()))}extrude(e,t={}){return hj(this.sketches.map(n=>n.extrude(e,t)))}revolve(e,t){return hj(this.sketches.map(n=>n.revolve(e,t)))}},fq={};async function pq(e,t=`default`,n=!1){if(!n&&fq[t])return O(fq[t]);let r;if(typeof e==`string`){let t;try{t=await fetch(e)}catch(t){return k(Do(M.FONT_FETCH_FAILED,`Failed to fetch font from ${e}: ${t instanceof Error?t.message:String(t)}`,t))}if(!t.ok)return k(Do(M.FONT_FETCH_FAILED,`Failed to fetch font from ${e}: HTTP ${t.status} ${t.statusText}`));r=await t.arrayBuffer()}else r=e;let i;try{i=qK.parse(r)}catch(e){return k(Do(M.FONT_PARSE_FAILED,`Failed to parse font data: ${e instanceof Error?e.message:String(e)}`,e))}let a=i;return fq[t]=a,fq.default||=a,O(a)}var mq=(e=`default`)=>fq[e],hq=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 yR,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 gq(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:a=`default`}={}){let o=mq(a);o||=mq(),o||i(`text`,`No fonts loaded. Call loadFont() before using text functions.`);let s=o.getPath(e,-t,-n,r);return cR(Array.from(hq(s.commands))).mirror([0,0])}var _q={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 vq(e){return typeof e==`string`&&e in _q}var yq=e=>{try{var t=IT();return e.IsNull()?[]:uD(t.u(U(e))).map(e=>j(wk(e)))}catch(e){t.e=e}finally{t.d()}};function bq(e,t,n=!0){let r=H().projectEdges(e.wrapped,[...t.position],[...t.direction],[...t.xAxis]),i=[...yq(r.visible.sharp),...yq(r.visible.smooth),...yq(r.visible.outline)],a=[...yq(r.hidden.sharp),...yq(r.hidden.smooth),...yq(r.hidden.outline)],o;if(n)o=a;else{for(let e of a)e[Symbol.dispose]();o=[]}return{visible:i,hidden:o}}function xq(e=[0,0,0],t=[0,0,1],n){if(BD(t)<1e-12)return k(P(`CAMERA_ZERO_DIRECTION`,`Camera direction cannot be a zero-length vector`));let r;if(n)r=UD(n);else{let e=zD([0,0,1],t);BD(e)<1e-12&&(e=zD([0,1,0],t)),BD(e)<1e-12&&(e=zD([1,0,0],t)),r=UD(e)}let i=UD(zD(t,r));return O({position:e,direction:UD(t),xAxis:r,yAxis:i})}function Sq(e,t){let n=UD(FD(e.position,t));return xq(e.position,n)}function Cq(e){let t=_q[e];return xq([0,0,0],t.dir,t.xAxis)}function wq(e,t,n=!0){return bq(e,t,n)}var Tq=(e,n=1e-7)=>{if(e.length===0)return[];let r=new HL(e.length);e.forEach(e=>{let[t,i]=e.firstPoint;r.add(t-n,i-n,t+n,i+n)}),r.finish();let a=[],o=new Set;return e.forEach((s,c)=>{if(o.has(c))return;let l=[s],u=c;o.add(c);let d=e.length;for(;;){d--<0&&i(`stitchCurves`,`Infinite loop detected`);let[s,c]=t(l,l.length-1).lastPoint,f=r.search(s-n,c-n,s+n,c+n),p=t=>Math.abs((u-t)%e.length),m=f.filter(e=>!o.has(e)).map(n=>[t(e,n),n,p(n)]).sort(([,,e],[,,t])=>e-t);if(m.length===0){a.push(l);break}let[h,g]=t(m,0);l.push(h),o.add(g),u=g}}),a},Eq=class extends vR{plane;constructor(e,t){super(),this.plane=e&&typeof e!=`string`?{...e}:j(eO(e??`XY`,t))}delete(){this.pendingCurves=[]}sagittaArcTo(e,t){return super.sagittaArcTo(e,-t)}buildWire(){try{var e=IT();this.pendingCurves.length||i(`Sketcher.buildWire`,`No lines to convert into a wire`);let t=e.u(new XT);return j(MA(TL(this.pendingCurves,this.plane).map(e=>t.register(e))))}catch(t){e.e=t}finally{e.d()}}done(){return new uq(this.buildWire(),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}close(){return this._closeSketch(),this.done()}closeWithMirror(){DI(this.pointer,this.firstPoint)&&i(`Sketcher.closeWithMirror`,`Cannot close with a mirror when the sketch is already closed`);let e=this.buildWire(),t=nO(this.plane,this.pointer),n=zD(UD(FD(t,nO(this.plane,this.firstPoint))),this.plane.zDir),r=j(uO(e.wrapped));return new uq(j(MA([e,EE(j(uO(H().mirror(r,AD(t),AD(n)))))])),{defaultOrigin:this.plane.origin,defaultDirection:this.plane.zDir})}closeWithCustomCorner(e,t=`fillet`){return this._closeSketch(),this._customCornerLastWithFirst(e,t),this.done()}},Dq=class extends vR{face;_bounds;constructor(e,t=[0,0]){super(t),this.face=DE(j(dO(e.wrapped))),this._bounds=bO(e)}_convertToUV([e,t]){let{uMin:n,uMax:r,vMin:i,vMax:a}=this._bounds;return[n+e*(r-n),i+t*(a-i)]}_convertFromUV([e,t]){let{uMin:n,uMax:r,vMin:i,vMax:a}=this._bounds;return[(e-n)/(r-n),(t-i)/(a-i)]}_adaptSurface(){return H().extractSurfaceFromFace(this.face.wrapped)}buildWire(){let e=H(),t=this._adaptSurface(),n=j(MA(this.pendingCurves.map(n=>TE(e.buildEdgeOnSurface(n.wrapped,t)))));return e.buildCurves3d(n.wrapped),n}done(){try{var e=IT();let t=e.u(new XT),n=this.buildWire(),r=new uq(n);if(Rk(n)){let e=t.register(r.clone().face()),n=xO(e,.5,.5),i=ID(wO(e),-1);r.defaultOrigin=[n[0],n[1],n[2]],r.defaultDirection=[i[0],i[1],i[2]]}else{let e=Mk(n),t=wO(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()}},Oq=(e,t={})=>{try{var n=IT();let r=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(eO(t.plane??`XY`,t.origin));return new uq(j(MA([n.u(new XT).register(CA(e,r.origin,r.zDir))])),{defaultOrigin:[...r.origin],defaultDirection:[...r.zDir]})}catch(e){n.e=e}finally{n.d()}},kq=(e=1,t=2,n={})=>{try{var r=IT();let i=n.plane&&typeof n.plane!=`string`?{...n.plane}:j(eO(n.plane??`XY`,n.origin)),a=i.xDir,o=e,s=t;return t>e&&(a=JD(a,i.zDir,90*JE),o=t,s=e),new uq(j(MA([r.u(new XT).register(j(wA(o,s,i.origin,i.zDir,a)))])),{defaultOrigin:[...i.origin],defaultDirection:[...i.zDir]})}catch(e){r.e=e}finally{r.d()}},Aq=(e,t,n={})=>(n.plane&&typeof n.plane!=`string`?new Eq(n.plane):new Eq(n.plane,n.origin)).movePointerTo([-e/2,-t/2]).hLine(e).vLine(t).hLine(-e).vLine(-t).done(),jq=(e,t,n=0,r={})=>{let i=ER(e,t,n).sketchOnPlane(r.plane,r.origin),a={};return i.defaultOrigin&&(a.defaultOrigin=i.defaultOrigin),i.defaultDirection&&(a.defaultDirection=i.defaultDirection),new uq(i.wire,a)},Mq=(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 Eq(r.plane):new Eq(r.plane,r.origin),o=yA(i),s=a.movePointerTo([_A(o,0),_A(o,1)]);return n?i.forEach(e=>s.sagittaArcTo([_A(e,0),_A(e,1)],n)):i.forEach(e=>s.lineTo([_A(e,0),_A(e,1)])),s.done()},Nq=(e,t,n=0)=>{let r=Math.PI/t,i=Math.cos(r)*e;return n>=0?i:i+n},Pq=(e,t)=>{let n=[...TO(e)],r=[...wO(e)];return new uq(j(Gk(OO(e),t)),{defaultOrigin:n,defaultDirection:r})},Fq=(e,t={},{pointsCount:n=400,start:r=0,stop:i=1}={},a={})=>{try{var o=IT();let s=o.u(new XT),c=t.plane&&typeof t.plane!=`string`?{...t.plane}:j(eO(t.plane??`XY`,t.origin)),l=(i-r)/n,u=[...Array(n+1).keys()].map(t=>{let n=e(r+t*l);return nO(c,n)});return new uq(j(MA([s.register(j(OA(u,a)))])),{defaultOrigin:[...c.origin],defaultDirection:[...c.zDir]})}catch(e){o.e=e}finally{o.d()}},Iq=(e,t,n,r=[0,0,0],i=[0,0,1],a=!1)=>new uq(j(MA([TA(e,t,n,AD(r),AD(i),a)]))),Lq=(e,t,n)=>new Eq().movePointerTo([-e/2,t/2]).hLine(e).vLine(-t).hLine(-e).close().extrude(n),Rq=(e,t)=>DI(e,t,TI*100),zq=(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 Bq(e,t,n,r,i){let a=SL(t,n,r.original.lastPoint);e(r),e(a)}function Vq(e,t,n,r,i){let a=mL(t,n);e(r),e(a)}function Hq(e,t,n,r,i){let a=zq(r.offset instanceof uL?kI(t,r.offset.tangentAt(1)):r.offset.firstPoint,t,n,i.offset instanceof uL?OI(n,i.offset.tangentAt(0)):i.offset.lastPoint);if(!a){let i=mL(t,n);e(r),e(i);return}let o=MI([(t[0]+n[0])/2,(t[1]+n[1])/2],a),s=MI(t,n);if(s<1e-18||o>16*s){let i=mL(t,n);e(r),e(i);return}let c=mL(t,a),l=mL(a,n);e(r),e(c),e(l)}var Uq={round:Bq,bevel:Vq,miter:Hq};function Wq(e,t,n){let r=n.length===1?Ao(n,0,`rawOffsets`):Gq(n,e.original.lastPoint),a=Ao(e.offset.splitAt([r],TI),0,`rawOffsets`),o=t.offset.splitAt([r],TI).at(-1);return o||i(`offset.rawOffsets`,`Split produced no trailing curve segment`),{splitPrevious:{offset:a,original:e.original},splitCurrent:{offset:o,original:t.original}}}function Gq(e,t){let n=Ao(e,0,`selectClosestIntersection`),r=MI(n,t);for(let i=1;i<e.length;i++){let a=Ao(e,i,`selectClosestIntersection`),o=MI(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 HL(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=Ao(e,r,`offsetBlueprint`),{intersections:o,commonSegmentsPoints:s}=j(qL(t,a,TI)),c=[...o,...s].filter(e=>{let n=Rq(e,t.firstPoint)||Rq(e,t.lastPoint),r=Rq(e,a.firstPoint)||Rq(e,a.lastPoint);return!(n&&r)});c.length&&(n(i,c),n(r,c))}}),t}function qq(e,t,n={}){let r=e.orientation===`clockwise`?-t:t,a=e.curves.map(e=>({offset:XL(e,r),original:e})),o=[],s=null,c=a.at(-1);if(!c)return[];function l(e){if(e instanceof uL){o.push(e);return}s?e.offset instanceof uL?o.push(e.offset):Rq(e.offset.firstPoint,e.offset.lastPoint)||o.push(mL(e.offset.firstPoint,e.offset.lastPoint)):s=e}let u=function*(){for(let e of a.slice(0,-1))yield e;s||i(`offset.rawOffsets`,`No saved curve after iterating offset segments`),yield s};for(let e of u()){let t=c.offset.lastPoint,r=e.offset.firstPoint;if(Rq(t,r)){l(c),c=e;continue}let i=[];if(c.offset instanceof uL&&e.offset instanceof uL){let{intersections:t,commonSegmentsPoints:n}=j(qL(c.offset,e.offset,TI/100));i=[...t,...n]}if(i.length>0){let{splitPrevious:t,splitCurrent:n}=Wq(c,e,i);l(t),c=n;continue}let a=Uq[n.lineJoinType??`round`];a(l,t,r,c,e),c=e}return l(c),o}function Jq(e,n,r={}){let i=qq(e,n,r);if(i.length<2)return null;let a=Kq(i);if(!a.size){let t=new RL(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,TI*100)}),s=new HL(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-TI)});if(!l.length)return null;let u=Tq(l).filter(e=>e.length>1).map(e=>new RL(e)).filter(e=>e.isClosed());return u.length?u.length===1?Ao(u,0,`offsetBlueprint`):new tR(u):null}var Yq=e=>{let t=Ao(e,0,`fuseAll`);for(let n=1;n<e.length;n++)t=cz(t,Ao(e,n,`fuseAll`));return t};function Xq(e,t,n={}){if(e instanceof RL)return Jq(e,t,n);if(e instanceof tR)return Yq(e.blueprints.map(e=>Xq(e,t,n)));if(e instanceof nR){let r=Yq(e.blueprints.slice(1).map(e=>Xq(e,-t,n)));return uz(Xq(Ao(e.blueprints,0,`offset`),t,n),r)}return null}function Zq(e,t){return e instanceof RL?new RL(pL(e.curves,t)):e instanceof nR?new nR(e.blueprints.map(e=>Zq(e,t))):e instanceof tR?new tR(e.blueprints.map(e=>Zq(e,t))):e}function Qq(e,t,n,r){let a=()=>!0;r&&(a=r.shouldKeep.bind(r));let o=[vA(t.curves)],s=(t,r)=>{a({firstCurve:t,secondCurve:r,point:t.lastPoint})?o.push(...e(t,r,n)):o.push(t,r)};t.curves.slice(1).forEach(e=>{let t=o.pop();t||i(`customCorners.modifyCorners`,`Unexpected empty curve stack during filleting`),s(t,e)});let c=o.at(-1);if(c||i(`customCorners.modifyCorners`,`Unexpected empty curve list during corner modification`),DI(vA(o).firstPoint,c.lastPoint)&&o.length>1){let e=o.pop(),t=o.shift();(!e||!t)&&i(`customCorners.modifyCorners`,`Unexpected empty curve stack during close-and-fillet`),s(e,t)}return new RL(o)}function $q(e,t,n,r){return t instanceof RL?Qq(e,t,n,r):t instanceof nR?new nR(t.blueprints.map(t=>Qq(e,t,n,r))):t instanceof tR?new tR(t.blueprints.map(t=>$q(e,t,n,r)).filter(e=>e!==null)):null}function eJ(e,t,n){return $q(QL,e,t,n)}function tJ(e,t,n){return $q($L,e,t,n)}function nJ(e,t){return e instanceof RL?YK(t):e instanceof nR?XK(t):new dq(t.map(e=>Array.isArray(e)?XK(e):YK(e)))}var rJ=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 nR)return{type:`CompoundBlueprint`,blueprints:t.blueprints.map(e)};if(t instanceof tR)return{type:`Blueprints`,blueprints:t.blueprints.map(e)};if(t instanceof RL)return{type:`Blueprint`,curves:t.curves.map(e=>e.serialize())};i(`Drawing.serialize`,`Unknown shape type for serialization`)}return JSON.stringify(e(this.innerShape))}get boundingBox(){return this.innerShape?this.innerShape.boundingBox:new cL}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(uz(this.innerShape,t.innerShape))}fuse(t){return new e(cz(this.innerShape,t.innerShape))}intersect(t){return new e(dz(this.innerShape,t.innerShape))}fillet(t,n){let r=n&&n(wR());return new e(eJ(this.innerShape,t,r))}chamfer(t,n){let r=n&&n(wR());return new e(tJ(this.innerShape,t,r))}sketchOnPlane(e,t){this.innerShape||i(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnPlane(e,t);return nJ(this.innerShape,n)}sketchOnFace(e,t){this.innerShape||i(`Drawing`,`Trying to sketch an empty drawing`);let n=this.innerShape.sketchOnFace(e,t);return nJ(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(Xq(this.innerShape,t,n))}approximate(t,n={}){return t!==`svg`&&i(`Drawing.approximate`,`Only 'svg' is supported for now`),new e(Zq(this.innerShape,n))}get blueprint(){if(!(this.innerShape instanceof RL)){if(this.innerShape instanceof tR&&this.innerShape.blueprints.length===1&&this.innerShape.blueprints[0]instanceof RL)return this.innerShape.blueprints[0];i(`Drawing.blueprint`,`This drawing is not a blueprint`)}return this.innerShape}};function iJ(e){function t(e){if(e.type===`CompoundBlueprint`)return new nR(e.blueprints.map(t));if(e.type===`Blueprints`)return new tR(e.blueprints.map(t));if(e.type===`Blueprint`)return new RL(e.curves.map(e=>lL(e)));i(`Drawing.deserialize`,`Unknown shape type for deserialization`)}return new rJ(t(JSON.parse(e)))}var aJ=class extends vR{constructor(e=[0,0]){super(),this.pointer=e,this.firstPoint=e,this.pendingCurves=[]}done(){return new rJ(new RL(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 oJ(e){let t=new aJ;return e&&t.movePointerTo(e),t}function sJ(e,t,n=0){return new rJ(ER(e,t,n))}var cJ=sJ;function lJ(e){return new rJ(new RL([_L(e)]))}function uJ(e,t){let[n,r]=[e,t].sort((e,t)=>e-t);return new rJ(new RL([vL(r,n,r===e?[1,0]:[0,1])]))}function dJ(e){return oJ().movePointerTo([-e,0]).sagittaArc(2*e,0,e).sagittaArc(-2*e,0,e).close()}function fJ(e,t){return oJ().movePointerTo([-e,0]).halfEllipse(2*e,0,t).halfEllipse(-2*e,0,t).close()}function pJ(e,t,n=0){return new rJ(TR(e,t,n))}function mJ(e,{startX:t=0,startY:n=0,fontSize:r=16,fontFamily:i=`default`}={}){return new rJ(gq(e,{startX:t,startY:n,fontSize:r,fontFamily:i}))}var hJ=(e,t={},n={})=>{e.length<2&&i(`drawPointsInterpolation`,`Need at least 2 points for interpolation, got ${e.length}`);let r=[j(xL(e,t))],a=e[0],o=e[e.length-1];return n.closeShape&&a&&o&&!DI(a,o)&&r.push(mL(o,a)),new rJ(new RL(r))},gJ=(e,{pointsCount:t=400,start:n=0,stop:r=1,closeShape:i=!1}={},a={})=>{let o=(r-n)/t;return hJ([...Array(t+1).keys()].map(t=>e(n+t*o)),a,{closeShape:i})},_J=e=>{try{var t=IT();let n=t.u(new XT),r=cJ(1e3,1e3).sketchOnPlane();n.register(r.wire);let i=n.register(j(NA(r.wire))),a=Tq(e.map(e=>PL(e,i))).map(e=>new RL(e));return a.length===0?new rJ:a.length===1?new rJ(a[0]):new rJ(new tR(a))}catch(e){t.e=e}finally{t.d()}};function vJ(e,t=`front`){let n;n=typeof t==`string`?j(Cq(t)):t;let{visible:r,hidden:i}=wq(e,n);try{return{visible:_J(r),hidden:_J(i)}}finally{for(let e of r)e[Symbol.dispose]();for(let e of i)e[Symbol.dispose]()}}function yJ(e){try{var t=IT();let n=t.u(new XT),r=n.register(DE(j(dO(e.wrapped)))),i=Tq(uD(n.register(OO(r))).map(t=>PL(t,e))).map(e=>new RL(e));return i.length===0?new rJ:i.length===1?new rJ(i[0]):new rJ(new tR(i))}catch(e){t.e=e}finally{t.d()}}function bJ(e,t,n){return n===void 0?e.sketchOnPlane(t):e.sketchOnPlane(t,n)}function xJ(e,t){return e.fuse(t)}function SJ(e,t){return e.cut(t)}function CJ(e,t){return e.intersect(t)}function wJ(e,t,n){return e.fillet(t,n)}function TJ(e,t,n){return e.chamfer(t,n)}function EJ(e,t,n=0){return typeof t==`number`?e.translate(t,n):e.translate(t)}function DJ(e,t,n){return e.rotate(t,n)}function OJ(e,t,n){return e.scale(t,n)}function kJ(e,t,n,r){return e.mirror(t,n,r)}function AJ(e){let t=e.clone();return t.reverse(),t}function jJ(e){return e.boundingBox}function MJ(e){return e.firstPoint}function NJ(e){return e.lastPoint}function PJ(e,t,n){return e.splitAt(t,n)}function FJ(e,t,n){return e.parameter(t,n)}function IJ(e,t){return e.tangentAt(t)}function LJ(e,t){return e.isOnCurve(t)}function RJ(e,t){return e.distanceFrom(t)}function zJ(e){return e.length===0?k(P(M.BLUEPRINT_EMPTY_CURVES,`createBlueprint: at least one curve is required`)):O(new RL(e))}function BJ(e){return e.length===0?k(P(M.COMPOUND_BLUEPRINT_EMPTY,`createCompoundBlueprint: at least one blueprint (outer boundary) is required`)):O(new nR(e))}function VJ(e){return e.boundingBox}function HJ(e){return e.orientation}function UJ(e,t){return e.isInside(t)}function WJ(e){return e.toSVGPathD()}function GJ(e,t,n){return e.translate(t,n)}function KJ(e,t,n){return e.rotate(t,n)}function qJ(e,t,n){return e.scale(t,n)}function JJ(e,t,n,r){return e.mirror(t,n,r)}function YJ(e,t,n,r){return e.stretch(t,n,r)}function XJ(e,t,n){return e.sketchOnPlane(t,n)}function ZJ(e,t,n){return e.sketchOnFace(t,n)}function QJ(e,t){return n(e,t*3)}function $J(e,t){return n(e,t)}function eY(e){let t=[`# brepjs OBJ export`],n=e.vertices.length/3;for(let r=0;r<n;r++){let[n,i,a]=QJ(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]=QJ(e.normals,n);t.push(`vn ${r} ${i} ${a}`)}let i=n=>{let[r,i,a]=$J(e.triangles,n);t.push(`f ${r+1}//${r+1} ${i+1}//${i+1} ${a+1}//${a+1}`)};if(e.faceGroups.length>0)for(let n of e.faceGroups){t.push(`g face_${n.faceId}`);let e=n.count/3;for(let t=0;t<e;t++)i(n.start+t*3)}else{let t=e.triangles.length/3;for(let e=0;e<t;e++)i(e*3)}return t.join(`
|
|
25
25
|
`)+`
|
|
26
|
-
`}var
|
|
26
|
+
`}var tY=5126,nY=5125,rY=34962,iY=34963,aY=[-Math.SQRT1_2,0,0,Math.SQRT1_2];function oY(e){return e===`Z`?[{mesh:0}]:[{name:`Z_up_to_Y_up`,rotation:aY,children:[1]},{mesh:0}]}function sY(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 cY(e){return e+3&-4}function lY(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 uY(e,t){let n=mY(e,`base64`,t);return JSON.stringify(n)}function dY(e,t){let{doc:n,binBuffer:r}=hY(e,t),i=JSON.stringify(n),a=new TextEncoder().encode(i),o=cY(a.length),s=new Uint8Array(o);s.set(a);for(let e=a.length;e<o;e++)s[e]=32;let c=cY(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 fY(e,t,n,r,i){return[{bufferView:0,componentType:nY,count:e.length,type:`SCALAR`},{bufferView:1,componentType:tY,count:t.length/3,type:`VEC3`,min:r,max:i},{bufferView:2,componentType:tY,count:n.length/3,type:`VEC3`}]}function pY(e,t,n){return[{buffer:0,byteOffset:0,byteLength:e,target:iY},{buffer:0,byteOffset:cY(e),byteLength:t,target:rY},{buffer:0,byteOffset:cY(e)+t,byteLength:n,target:rY}]}function mY(e,t,n){let{vertices:r,normals:i,triangles:a}=e,o=n?.materials;if(o&&o.size>0&&e.faceGroups.length>0)return xY(e,t,o,n.upAxis??`Y`);let s=a.byteLength,c=r.byteLength,l=i.byteLength,u=cY(s)+c+l,{min:d,max:f}=sY(r),p={asset:{version:`2.0`,generator:`brepjs`},scene:0,scenes:[{nodes:[0]}],nodes:oY(n?.upAxis??`Y`),meshes:[{primitives:[{attributes:{POSITION:1,NORMAL:2},indices:0}]}],accessors:fY(a,r,i,d,f),bufferViews:pY(s,c,l),buffers:[{byteLength:u}]};if(t===`base64`){let t=CY(e);p.buffers[0]={byteLength:u,uri:`data:application/octet-stream;base64,`+lY(t)}}return p}function hY(e,t){let n=t?.materials;if(n&&n.size>0&&e.faceGroups.length>0){let{doc:r,binBuffer:i}=SY(e,n,t.upAxis??`Y`);return{doc:r,binBuffer:i}}return{doc:mY(e,`glb`,t),binBuffer:CY(e)}}function gY(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=_A(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+=_A(o,e).count;let i=new Uint32Array(r),s=0;for(let e of n){let n=_A(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=cY(f+t)}let m=f;return{primitiveData:d,indexBufferInfos:p,verticesOffset:m,totalByteLength:m+r.byteLength+i.byteLength,uniqueMaterials:s}}function _Y(e,t,n,r){let{vertices:i,normals:a}=e,{min:o,max:s}=sY(i),c=r.length;r.push({buffer:0,byteOffset:t,byteLength:i.byteLength,target:rY});let l=n.length;n.push({bufferView:c,componentType:tY,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:rY});let d=n.length;return n.push({bufferView:u,componentType:tY,count:a.length/3,type:`VEC3`}),{verticesAccIdx:l,normalsAccIdx:d}}function vY(e,t,n,r,i,a){let o=[];for(let s=0;s<e.length;s++){let c=_A(e,s),l=_A(t,s),u=a.length;a.push({buffer:0,byteOffset:l.byteOffset,byteLength:l.byteLength,target:iY});let d=i.length;i.push({bufferView:u,componentType:nY,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 yY(e,t,n=`Y`){let{primitiveData:r,indexBufferInfos:i,verticesOffset:a,totalByteLength:o,uniqueMaterials:s}=t,c=[],l=[],{verticesAccIdx:u,normalsAccIdx:d}=_Y(e,a,c,l),f=vY(r,i,u,d,c,l);return{asset:{version:`2.0`,generator:`brepjs`},scene:0,scenes:[{nodes:[0]}],nodes:oY(n),meshes:[{primitives:f}],accessors:c,bufferViews:l,buffers:[{byteLength:o}],materials:s}}function bY(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=_A(i,e),n=_A(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 xY(e,t,n,r=`Y`){let i=gY(e,n),a=yY(e,i,r);if(t===`base64`){let t=bY(e,i);a.buffers[0]={byteLength:i.totalByteLength,uri:`data:application/octet-stream;base64,`+lY(t)}}return a}function SY(e,t,n=`Y`){let r=gY(e,t);return{doc:yY(e,r,n),binBuffer:bY(e,r)}}function CY(e){let{vertices:t,normals:n,triangles:r}=e,i=r.byteLength,a=t.byteLength,o=n.byteLength,s=cY(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),cY(i)),l.set(new Uint8Array(n.buffer,n.byteOffset,o),cY(i)+a),c}function wY(e,t){let n=t?.layer??`0`,r=[];r.push(`0`,`SECTION`,`2`,`HEADER`),r.push(`9`,`$ACADVER`,`1`,`AC1009`),r.push(`0`,`ENDSEC`);let i=new Set([n]);for(let t of e)t.layer&&i.add(t.layer);r.push(`0`,`SECTION`,`2`,`TABLES`),r.push(`0`,`TABLE`,`2`,`LAYER`,`70`,String(i.size));for(let e of i)r.push(`0`,`LAYER`,`2`,e,`70`,`0`,`62`,`7`,`6`,`CONTINUOUS`);r.push(`0`,`ENDTAB`),r.push(`0`,`ENDSEC`),r.push(`0`,`SECTION`,`2`,`ENTITIES`);for(let t of e){let e=t.layer??n;if(t.type===`LINE`)r.push(`0`,`LINE`,`8`,e,`10`,String(t.start[0]),`20`,String(t.start[1]),`30`,`0`,`11`,String(t.end[0]),`21`,String(t.end[1]),`31`,`0`);else{r.push(`0`,`LWPOLYLINE`,`8`,e,`90`,String(t.points.length),`70`,t.closed?`1`:`0`);for(let e of t.points)r.push(`10`,String(e[0]),`20`,String(e[1]))}}return r.push(`0`,`ENDSEC`),r.push(`0`,`EOF`),r.join(`
|
|
27
27
|
`)+`
|
|
28
|
-
`}function
|
|
29
|
-
`);n.push(` <colorgroup id="2">\n${t}\n </colorgroup>`)}if(t.length>0){let e=t.map(e=>{let t=e.displayColor===void 0?`#FFFFFFFF`:
|
|
30
|
-
`);n.push(` <basematerials id="3">\n${e}\n </basematerials>`)}return n}function
|
|
28
|
+
`}function TY(e,t){let n=t?.curveSegments??32,r=[],i=EY(e);for(let e of i)for(let t of e.curves)r.push(...DY(t,n));return wY(r,t)}function EY(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(...EY(n));return t}return[]}function DY(e,t){return e.geomType===`LINE`?[{type:`LINE`,start:e.firstPoint,end:e.lastPoint}]:[OY(e,t)]}function OY(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 kY=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;kY[e]=t}function AY(e){let t=4294967295;for(let n of e)t=(kY[(t^n)&255]??0)^t>>>8;return(t^4294967295)>>>0}function jY(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 MY(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 NY(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 PY(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=jY(s,c,l,e);for(let{offset:e,entry:t}of n)l=MY(s,c,l,e,t);return NY(s,l,e.length,r,i),o}function FY(e){return e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`)}function IY(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 LY(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 RY(e){let t=new Map,n=[];if(e!==void 0&&e.size>0)for(let r of e.values()){let e=IY(r);t.has(e)||(t.set(e,n.length),n.push(e))}return{colorIndexByHex:t,colorHexList:n}}function zY(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 BY(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=IY(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 VY(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 HY(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`:IY(e.displayColor);return` <base name="${FY(e.name)}" displaycolor="${t}" />`}).join(`
|
|
30
|
+
`);n.push(` <basematerials id="3">\n${e}\n </basematerials>`)}return n}function UY(e,t,n,r,i){let a=LY(e),{colorIndexByHex:o,colorHexList:s}=RY(r),{materialIndexByName:c,materialList:l}=zY(i),u=VY(e,BY(e,r,i,o,c)),d=HY(s,l);return`<?xml version="1.0" encoding="UTF-8"?>
|
|
31
31
|
<model unit="${n}" xmlns="http://schemas.microsoft.com/3dmanufacturing/core/2015/02"${l.length>0?`
|
|
32
32
|
xmlns:m="http://schemas.microsoft.com/3dmanufacturing/material/2015/02"`:``}>
|
|
33
33
|
<resources>${d.length>0?`
|
|
34
34
|
`+d.join(`
|
|
35
35
|
`):``}
|
|
36
|
-
<object id="1" name="${
|
|
36
|
+
<object id="1" name="${FY(t)}" type="model">
|
|
37
37
|
<mesh>
|
|
38
38
|
<vertices>
|
|
39
39
|
${a.join(`
|
|
@@ -49,12 +49,12 @@ ${u.join(`
|
|
|
49
49
|
<build>
|
|
50
50
|
<item objectid="1" />
|
|
51
51
|
</build>
|
|
52
|
-
</model>`}function
|
|
52
|
+
</model>`}function WY(e,t={}){let{name:n=`model`,unit:r=`millimeter`,colors:i,materials:a}=t,o=new TextEncoder,s=UY(e,n,r,i,a);function c(e,t){let n=o.encode(e),r=o.encode(t);return{name:n,data:r,crc:AY(r)}}return PY([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 WY(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 GY(e){return[e[0],-e[1]]}function KY(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(pL(GY([t.cx,t.cy]),GY([a,o]))),t.cx=a,t.cy=o,i+=2}}function qY(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(pL(GY([t.cx,t.cy]),GY([a,o]))),t.cx=a,t.cy=o,i+=2}}function JY(e,t,n,r){for(let i of e){let e=n?t.cx+i:i;r.push(pL(GY([t.cx,t.cy]),GY([e,t.cy]))),t.cx=e}}function YY(e,t,n,r){for(let i of e){let e=n?t.cy+i:i;r.push(pL(GY([t.cx,t.cy]),GY([t.cx,e]))),t.cy=e}}function XY(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(yL(GY([t.cx,t.cy]),[GY([s,c]),GY([l,u])],GY([d,f]))),t.prevControlX=l,t.prevControlY=u,t.cx=d,t.cy=f,i+=6}}function ZY(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(yL(GY([t.cx,t.cy]),[GY([c,l]),GY([u,d])],GY([f,p]))),t.prevControlX=u,t.prevControlY=d,t.cx=f,t.cy=p,t.lastCmd=`S`,i+=4}}function QY(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(yL(GY([t.cx,t.cy]),[GY([s,c])],GY([l,u]))),t.prevControlX=s,t.prevControlY=c,t.cx=l,t.cy=u,i+=4}}function $Y(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(yL(GY([t.cx,t.cy]),[GY([c,l])],GY([u,d]))),t.prevControlX=c,t.prevControlY=l,t.cx=u,t.cy=d,t.lastCmd=`T`,i+=2}}function eX(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[mL(GY([e,t]),GY(c),GY([e,s])),mL(GY([e,s]),GY(l),GY([e,t]))]}catch{return[]}}function tX(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[mL(GY([e,t]),GY([b,x]),GY([n,r]))]}catch{return[pL(GY([e,t]),GY([n,r]))]}}function nX(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(pL(GY([t.cx,t.cy]),GY([d,f])));else{let e=d-t.cx,n=f-t.cy;Math.sqrt(e*e+n*n)<1e-10?r.push(...eX(t.cx,t.cy,s,c,u)):r.push(...tX(t.cx,t.cy,d,f,s,c,l,u))}t.cx=d,t.cy=f,i+=7}}function rX(e,t){(Math.abs(e.cx-e.sx)>1e-10||Math.abs(e.cy-e.sy)>1e-10)&&t.push(pL(GY([e.cx,e.cy]),GY([e.sx,e.sy]))),e.cx=e.sx,e.cy=e.sy}function iX(e){let t=WY(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`:KY(i,r,t,n);break;case`L`:qY(i,r,t,n);break;case`H`:JY(i,r,t,n);break;case`V`:YY(i,r,t,n);break;case`C`:XY(i,r,t,n);break;case`S`:ZY(i,r,t,n);break;case`Q`:QY(i,r,t,n);break;case`T`:$Y(i,r,t,n);break;case`A`:nX(i,r,t,n);break;case`Z`:rX(r,n);break}a!==`S`&&a!==`T`&&(r.lastCmd=a)}return n}function aX(e){try{let t=iX(e);return t.length===0?k(Do(`SVG_EMPTY_PATH`,`SVG path produced no curves`)):O(new LL(t))}catch(e){return k(Do(`SVG_PARSE_FAILED`,`Failed to parse SVG path: ${e instanceof Error?e.message:String(e)}`))}}function oX(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=aX(l);u.ok&&n.push(u.value)}return n.length===0?k(Do(`SVG_NO_PATHS`,`No <path> elements found in SVG`)):O(n)}catch(e){return k(Do(`SVG_IMPORT_FAILED`,`Failed to import SVG: ${e instanceof Error?e.message:String(e)}`))}}function sX(e,t){try{let n=H(),r=e.map(e=>({shape:e.shape.wrapped,name:e.name,color:e.color?[...e.color]:void 0}));return O(n.exportSTEPConfigured(r,t))}catch(e){return k(Do(M.STEP_EXPORT_CONFIGURED_FAILED,`Configured STEP export failed`,e))}}async function cX(e){try{let t=await e.arrayBuffer(),n=H().importSTEP(t);if(n.length===0)return k(Do(`STEP_IMPORT_FAILED`,`STEP file contains no valid geometry`));for(let e=1;e<n.length;e++){let t=n[e];t&&H().dispose(t)}return O(U(n[0]))}catch(e){return k(Do(`STEP_IMPORT_FAILED`,`Failed to load STEP file`,e))}}async function lX(e){try{let t=await e.arrayBuffer(),n=H().importSTL(t);return n.IsNull()?k(Do(`STL_IMPORT_FAILED`,`Failed to create solid from STL mesh`)):O(U(n))}catch(e){return k(Do(`STL_IMPORT_FAILED`,`Failed to load STL file`,e))}}async function uX(e){try{let t=await e.arrayBuffer(),n=H().importIGES(t);if(n.length===0)return k(Do(`IGES_IMPORT_FAILED`,`IGES file contains no valid geometry`));for(let e=1;e<n.length;e++){let t=n[e];t&&H().dispose(t)}return O(U(n[0]))}catch(e){return k(Do(`IGES_IMPORT_FAILED`,`Failed to load IGES file`,e))}}function dX(e,t,n={}){let r=hq(e,t);return new uq((typeof n.plane==`string`||n.plane===void 0?r.sketchOnPlane(n.plane,n.origin):r.sketchOnPlane(n.plane)).map(e=>Array.isArray(e)?new qK(e.map(JK)):JK(e)))}function fX(e,t){let n=t?.fontSize??1,r=pq(t?.fontFamily);if(!r)return k(P(M.NO_FONT_LOADED,`No font loaded. Call loadFont() first.`,void 0,void 0,`Load a font with loadFont() before calling textMetrics()`));let i=r.getAdvanceWidth(e,n),a=n/r.unitsPerEm,o=r.ascender*a,s=r.descender*a;return O({width:i,height:o-s,ascender:o,descender:s})}function pX(e){let t=e?.fontSize??1,n=pq(e?.fontFamily);if(!n)return k(P(M.NO_FONT_LOADED,`No font loaded. Call loadFont() first.`,void 0,void 0,`Load a font with loadFont() before calling fontMetrics()`));let r=t/n.unitsPerEm,i=n.ascender*r,a=n.descender*r,o=(n.tables?.os2?.sTypoLineGap??0)*r;return O({ascender:i,descender:a,unitsPerEm:n.unitsPerEm,lineHeight:i-a+o})}function mX(e){return e.type===`init`}function hX(e){return e.type===`operation`}function gX(e){return e.type===`dispose`}function _X(e){return e.type===`batch`}function vX(e){return e.success}function yX(e){return!e.success}function bX(){return{pending:new Map}}function xX(e,t){let n=new Map(e.pending);return n.set(t.id,t),{pending:n}}function SX(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 CX(e){return e.pending.size}function wX(e){return e.pending.size===0}function TX(e,t){for(let n of e.pending.values())n.reject(t);return{pending:new Map}}function EX(e,t){let n=t.data,r=e.get(n.id);if(r)if(e.delete(n.id),vX(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){EX(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 OX(){return{operations:new Map}}function kX(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function AX(e){return e instanceof Error?e.message:String(e)}function jX(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:AX(e)}}}function MX(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 NX(e,t){let n=globalThis;n.onmessage=async r=>{let i=r.data;if(mX(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:AX(e)};n.postMessage(t)}return}if(hX(i)){let t=jX(e,i.operation,i.shapesBrep,i.parameters);n.postMessage(MX(i.id,t));return}if(_X(i)){let t=i.operations.map(t=>jX(e,t.operation,t.shapesBrep,t.params)),r={id:i.id,success:!0,resultData:t};n.postMessage(r);return}if(gX(i)){let e={id:i.id,success:!0};n.postMessage(e),n.close?.()}}}function PX(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 FX=Object.defineProperty,IX=(e,t)=>{let n={};for(var r in e)FX(n,r,{get:e[r],enumerable:!0});return t||FX(n,Symbol.toStringTag,{value:`Module`}),n},LX=1,RX=2;function zX(e,t){t===`commonFace`&&e.SetGlue(LX),t===`sameFace`&&e.SetGlue(RX)}function BX(e){return typeof e==`number`}function VX(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 HX(e){return typeof e==`number`?!0:Array.isArray(e)&&e.length===2?e.every(BX):!1}function UX(e,t){let n=n=>{let r=e.findAll(n);if(r.length===0)return[];let i=0,a=HD(kD(vA(r)),t);for(let e=1;e<r.length;e++){let n=HD(kD(_A(r,e)),t);n<a&&(a=n,i=e)}return[_A(r,i)]},r=e=>{let t=n(e);return t.length===0?k(Oo(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found 0 element(s)`)):O(vA(t))};return{...e,findAll:n,findUnique:r}}function WX(e){return VI(`vertex`,e,WX,(t,n)=>({nearestTo:t=>UX(WX(e),t),atPosition:(e,t=1e-4)=>n(n=>HD(kD(n),e)<t),withinBox:(e,t)=>n(n=>{let r=kD(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=kD(n);return Math.abs(HD(i,t)-e)<r})}))}function GX(){return WX([])}var KX=new Map,qX=null,JX=null;function YX(e,t){KX.set(e,t),qX||=e,e===qX&&(JX=t)}function XX(e){if(!e&&JX)return JX;let t=e??qX;if(!t)throw Error(`brepjs voxel engine not initialized. Call initVoxel() (or registerVoxel()) before using voxel operations.`);let n=KX.get(t);if(!n)throw Error(`brepjs: voxel engine '${t}' is not registered.`);return n}function ZX(){return qX}function QX(e,t=`voxel`){YX(t,e),qX=t,JX=e}function $X(e){if(e.vertices.length%3!=0)return P(`VOXEL_INVALID_MESH`,`mesh.vertices length must be a multiple of 3 (flat xyz).`);if(e.triangles.length%3!=0)return P(`VOXEL_INVALID_MESH`,`mesh.triangles length must be a multiple of 3.`);let t=e.vertices.length/3;for(let n=0;n<e.triangles.length;n++){let r=e.triangles[n];if(r===void 0||r>=t)return P(`VOXEL_INVALID_TRIANGLE_INDEX`,`triangle index ${r} at position ${n} is out of range for ${t} vertices.`)}return null}function eZ(e,t){return $X(e)||(t.length%3==0?null:P(`VOXEL_INVALID_QUERIES`,`queries length must be a multiple of 3 (flat xyz).`))}function tZ(e){try{return O(XX(e))}catch(e){return k(To(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function nZ(e,t,n){let r=eZ(e,t);if(r)return k(r);let i=tZ(n);return A(i)?i:O(i.value.winding_numbers(e.vertices,e.triangles,t))}function rZ(e,t,n){let r=eZ(e,t);if(r)return k(r);let i=tZ(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 iZ=48,aZ=2;function oZ(e,t,n){let r=$X(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`repairMesh requires a non-empty triangle mesh.`));let i=t?.resolution??iZ,a=t?.padding??aZ;if(!Number.isInteger(i)||i<1)return k(P(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`));if(!Number.isInteger(a)||a<1)return k(P(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`));let o=tZ(n);if(A(o))return o;try{try{var s=IT();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(Eo(`VOXEL_REPAIR_FAILED`,e instanceof Error?e.message:`voxel repair failed (grid too large?).`,e))}}var sZ=.001;function cZ(e,t=sZ){try{let n=nA(e,{tolerance:t});return n.vertices.length===0||n.triangles.length===0?k(Eo(`VOXEL_SHAPE_MESH_EMPTY`,`shape tessellated to an empty triangle mesh.`)):O({vertices:n.vertices,triangles:n.triangles})}catch(e){return k(Eo(`VOXEL_SHAPE_MESH_FAILED`,e instanceof Error?e.message:`failed to mesh shape for voxel op.`,e))}}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(P(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(P(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function pZ(e){if(e.positions.length===0||e.indices.length===0)return k(Eo(`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 mZ(e,t,n,r){let i=$X(e);if(i)return k(i);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`offsetMesh requires a non-empty triangle mesh.`));if(!Number.isFinite(t))return k(P(`VOXEL_INVALID_DISTANCE`,`distance must be a finite number.`));let a=fZ(n);if(A(a))return a;let o=tZ(r);if(A(o))return o;try{try{var s=IT();return pZ(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(Eo(`VOXEL_OFFSET_FAILED`,e instanceof Error?e.message:`voxel offset failed (grid too large?).`,e))}}function hZ(e,t,n,r){let i=$X(e);if(i)return k(i);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`shellMesh requires a non-empty triangle mesh.`));if(!Number.isFinite(t)||t<=0)return k(P(`VOXEL_INVALID_THICKNESS`,`thickness must be a finite number > 0.`));let a=fZ(n);if(A(a))return a;let o=tZ(r);if(A(o))return o;try{try{var s=IT();return pZ(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(Eo(`VOXEL_SHELL_FAILED`,e instanceof Error?e.message:`voxel shell failed (grid too large?).`,e))}}function gZ(e,t,n,r,i){let a=$X(e);if(a)return k(a);let o=$X(t);if(o)return k(o);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`voxelBoolean requires a non-empty mesh for operand A.`));if(t.vertices.length===0||t.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`voxelBoolean requires a non-empty mesh for operand B.`));let s=dZ[n],c=fZ(r);if(A(c))return c;let l=tZ(i);if(A(l))return l;try{try{var u=IT();return pZ(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(Eo(`VOXEL_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel boolean failed (grid too large?).`,e))}}function _Z(e,t,n,r){let i=cZ(e);return A(i)?i:mZ(i.value,t,n,r)}function vZ(e,t,n,r){let i=cZ(e);return A(i)?i:hZ(i.value,t,n,r)}function yZ(e,t,n,r,i){let a=cZ(e);if(A(a))return a;let o=cZ(t);return A(o)?o:gZ(a.value,o.value,n,r,i)}var bZ=48,xZ=2,SZ={union:0,intersection:1,difference:2};function CZ(e){let t=e?.resolution??bZ,n=e?.padding??xZ;return!Number.isInteger(t)||t<1?k(P(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(P(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function wZ(e){try{var t=IT();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(Eo(`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 TZ(e){return{raw:e,delete(){e.free()}}}function EZ(e){return DZ(e)}function DZ(e){let t=YT(TZ(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,SZ[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=wZ(this.value);if(A(e))throw Error(e.error.message);return e.value}};return n}function OZ(e){return!e.disposed}function kZ(){return k(P(`VOXEL_FIELD_DISPOSED`,`the voxel field handle has been disposed.`))}function AZ(e,t,n){let r=$X(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`voxelField requires a non-empty triangle mesh.`));let i=CZ(t);if(A(i))return i;let a=tZ(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(Eo(`VOXEL_FIELD_VOXELIZE_FAILED`,e instanceof Error?e.message:`voxel field voxelization failed (grid too large or non-dense?).`,e))}}function jZ(e,t,n,r,i){let a=$X(e);if(a)return k(a);let o=$X(t);if(o)return k(o);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`voxelBooleanField requires a non-empty mesh for operand A.`));if(t.vertices.length===0||t.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`voxelBooleanField requires a non-empty mesh for operand B.`));let s=CZ(r);if(A(s))return s;let c=tZ(i);if(A(c))return c;try{return O(DZ(c.value.VoxelField.boolean_of(e.vertices,e.triangles,t.vertices,t.triangles,SZ[n],s.value.resolution,s.value.padding)))}catch(e){return k(Eo(`VOXEL_FIELD_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel field boolean failed (grid too large or non-dense?).`,e))}}function MZ(e,t,n){if(!OZ(e)||!OZ(t))return kZ();try{return e.value.boolean(t.value,SZ[n]),O(e)}catch(e){return k(Eo(`VOXEL_FIELD_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel field boolean failed (dim mismatch?).`,e))}}function NZ(e,t){if(!OZ(e))return kZ();if(!Number.isFinite(t))return k(P(`VOXEL_INVALID_DISTANCE`,`distance must be a finite number.`));try{return e.value.offset(t),O(e)}catch(e){return k(Eo(`VOXEL_FIELD_OFFSET_FAILED`,e instanceof Error?e.message:`voxel field offset failed.`,e))}}function PZ(e,t){if(!OZ(e))return kZ();if(!Number.isFinite(t)||t<=0)return k(P(`VOXEL_INVALID_THICKNESS`,`thickness must be a finite number > 0.`));try{return e.value.shell(t),O(e)}catch(e){return k(Eo(`VOXEL_FIELD_SHELL_FAILED`,e instanceof Error?e.message:`voxel field shell failed.`,e))}}function FZ(e){if(!OZ(e))return kZ();try{return e.value.reinit(),O(e)}catch(e){return k(Eo(`VOXEL_FIELD_REINIT_FAILED`,e instanceof Error?e.message:`voxel field reinit failed.`,e))}}function IZ(e){if(!OZ(e))return kZ();try{return wZ(e.value)}catch(e){return k(Eo(`VOXEL_FIELD_CONTOUR_FAILED`,e instanceof Error?e.message:`voxel field contour failed.`,e))}}function LZ(e,t,n){let r=cZ(e);return A(r)?r:AZ(r.value,t,n)}function RZ(e,t,n,r,i){let a=cZ(e);if(A(a))return a;let o=cZ(t);return A(o)?o:jZ(a.value,o.value,n,r,i)}var zZ=48,BZ=2;function VZ(e){try{return O(XX(e))}catch(e){return k(To(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function HZ(e){let t=e?.resolution??zZ,n=e?.padding??BZ;return!Number.isInteger(t)||t<1?k(P(`SDF_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(P(`SDF_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function UZ(e){return{raw:e,delete(){e.free()}}}var WZ={offsetField(e){return GZ(this.value.offset_field(e.value))},roundField(e){return GZ(this.value.round_field(e.value))},shellField(e){return GZ(this.value.shell_field(e.value))},smoothUnionField(e,t){return GZ(this.value.smooth_union_field(e.value,t.value))}};function GZ(e){let t=YT(UZ(e));return{get value(){return t.value.raw},get disposed(){return t.disposed},[Symbol.dispose](){t[Symbol.dispose]()},union(e){return GZ(this.value.union(e.value))},intersection(e){return GZ(this.value.intersection(e.value))},difference(e){return GZ(this.value.difference(e.value))},smoothUnion(e,t){return GZ(this.value.smooth_union(e.value,t))},smoothIntersection(e,t){return GZ(this.value.smooth_intersection(e.value,t))},smoothDifference(e,t){return GZ(this.value.smooth_difference(e.value,t))},offset(e){return GZ(this.value.offset(e))},round(e){return GZ(this.value.round(e))},shell(e){return GZ(this.value.shell(e))},onion(e){return GZ(this.value.onion(e))},...WZ,translate(e,t,n){return GZ(this.value.translate(e,t,n))},rotate(e,t,n,r){return GZ(this.value.rotate(e,t,n,r))},scale(e){return GZ(this.value.scale(e))},rasterize(e){return KZ(this.value,e)},rasterizeIn(e,t){return qZ(this.value,e,t)}}}function KZ(e,t){let n=HZ(t);if(A(n))return n;try{return O(EZ(e.rasterize(n.value.resolution,n.value.padding)))}catch(e){return JZ(e)}}function qZ(e,t,n){let r=HZ(n);if(A(r))return r;let i=YZ(t);if(i)return k(i);try{return O(EZ(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 JZ(e)}}function JZ(e){return k(Eo(`SDF_RASTERIZE_FAILED`,e instanceof Error?e.message:`SDF rasterization failed (grid too large?).`,e))}function YZ(e){if(![...e.min,...e.max].every(e=>Number.isFinite(e)))return P(`SDF_INVALID_BOUNDS`,`bounds must be finite numbers.`);for(let t=0;t<3;t++)if(e.max[t]<=e.min[t])return P(`SDF_INVALID_BOUNDS`,`bounds max must exceed min on every axis.`);return null}function XZ(e,t){let n=VZ(t);if(A(n))return n;try{return O(GZ(e(n.value)))}catch(e){return k(Eo(`SDF_BUILD_FAILED`,e instanceof Error?e.message:`SDF primitive construction failed.`,e))}}function ZZ(e,t){return XZ(t=>t.Sdf.sphere(e),t)}function QZ(e,t,n,r){return XZ(r=>r.Sdf.box_(e,t,n),r)}function $Z(e,t,n,r,i){return XZ(i=>i.Sdf.rounded_box(e,t,n,r),i)}function eQ(e,t,n){return XZ(n=>n.Sdf.cylinder(e,t),n)}function tQ(e,t,n){return XZ(n=>n.Sdf.cone(e,t),n)}function nQ(e,t,n,r){return XZ(r=>r.Sdf.capsule(e[0],e[1],e[2],t[0],t[1],t[2],n),r)}function rQ(e,t,n){return XZ(n=>n.Sdf.torus(e,t),n)}function iQ(e,t,n){return XZ(n=>n.Sdf.plane(e[0],e[1],e[2],t),n)}function aQ(e){if(e.length<2)return k(P(`SDF_INVALID_SPINE`,`sweep spine needs at least 2 points.`));let t=new Float64Array(e.length*3);for(let n=0;n<e.length;n++){let r=e[n];if(!r.every(e=>Number.isFinite(e)))return k(P(`SDF_INVALID_SPINE`,`sweep spine coordinates must be finite.`));t[n*3]=r[0],t[n*3+1]=r[1],t[n*3+2]=r[2]}return O(t)}function oQ(e,t,n,r){let i=aQ(e);if(A(i))return i;let a=n?.closed??!1;return XZ(e=>e.Sdf.sweep(i.value,t.value,a),r)}var sQ={gyroid:0,schwarzP:1,diamond:2};function cQ(e,t,n,r){let i=sQ[e];return i===void 0?k(P(`SDF_INVALID_LATTICE_KIND`,`unknown lattice kind: ${e}`)):XZ(e=>e.Sdf.lattice(i,t.value,n.value),r)}function lQ(e,t,n){return XZ(n=>n.Sdf.strut_lattice(e,t.value),n)}function uQ(e){return{raw:e,delete(){e.free()}}}function dQ(e){let t=YT(uQ(e));return{get value(){return t.value.raw},get disposed(){return t.disposed},[Symbol.dispose](){t[Symbol.dispose]()}}}function fQ(e,t){let n=VZ(t);if(A(n))return n;try{return O(dQ(e(n.value)))}catch(e){return k(Eo(`SDF_FIELD_BUILD_FAILED`,e instanceof Error?e.message:`scalar field construction failed.`,e))}}function pQ(e,t){return fQ(t=>t.ScalarField.constant(e),t)}function mQ(e,t,n,r,i,a){return fQ(a=>a.ScalarField.axial_ramp(e,t,n,r,i),a)}function hQ(e,t,n,r,i,a,o){return fQ(o=>o.ScalarField.radial_ramp(e[0],e[1],e[2],t,n,r,i,a),o)}function gQ(e,t,n,r){return fQ(r=>r.ScalarField.from_sdf(e.value,t,n),r)}function _Q(e,t,n,r){return fQ(r=>r.ScalarField.clamp(e.value,t,n),r)}var vQ={gyroid:0,schwarzP:1,diamond:2},yQ=48,bQ=2;function xQ(e){let t=vQ[e.type];if(t===void 0)return k(P(`LATTICE_INVALID_TYPE`,`lattice type must be one of gyroid, schwarzP, diamond (got '${e.type}').`));if(!(e.period>0))return k(P(`LATTICE_INVALID_PERIOD`,`period must be > 0.`));if(!(e.thickness>0))return k(P(`LATTICE_INVALID_THICKNESS`,`thickness must be > 0.`));let n=e.resolution??yQ,r=e.padding??bQ;return!Number.isInteger(n)||n<1?k(P(`LATTICE_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(r)||r<1?k(P(`LATTICE_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({tag:t,period:e.period,thickness:e.thickness,resolution:n,padding:r})}function SQ(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 CQ(e,t,n){let r=$X(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(P(`LATTICE_EMPTY_MESH`,`latticeInfill requires a non-empty triangle mesh.`));let i=xQ(t);if(A(i))return i;let a=tZ(n);if(A(a))return a;let{tag:o,period:s,thickness:c,resolution:l,padding:u}=i.value;try{try{var d=IT();return O(SQ(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(Eo(`LATTICE_INFILL_FAILED`,e instanceof Error?e.message:`lattice infill failed (grid too large?).`,e))}}function wQ(e,t,n){let r=cZ(e);return A(r)?r:CQ(r.value,t,n)}function TQ(e,t,n){for(let t=0;t<3;t++){let n=e.min[t],r=e.max[t];if(n===void 0||r===void 0||!(n<r))return k(P(`LATTICE_INVALID_BOUNDS`,`bounds.min must be strictly less than bounds.max on every axis (axis ${t}).`))}let r=xQ(t);if(A(r))return r;let i=tZ(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=IT();return O(SQ(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(Eo(`TPMS_LATTICE_FAILED`,e instanceof Error?e.message:`tpms lattice failed (grid too large?).`,e))}}function EQ(e){return H().createVector3d(e[0],e[1],e[2])}function DQ(e){return H().createPoint3d(e[0],e[1],e[2])}function OQ(e){return H().createDirection3d(e[0],e[1],e[2])}function kQ(e){return[e.X(),e.Y(),e.Z()]}function AQ(e){return[e.X(),e.Y(),e.Z()]}function jQ(e){return[e.X(),e.Y(),e.Z()]}function MQ(e,t){let n=EQ(e);try{return t(n)}finally{n.delete()}}function NQ(e,t){let n=DQ(e);try{return t(n)}finally{n.delete()}}function PQ(e,t){let n=OQ(e);try{return t(n)}finally{n.delete()}}var FQ=.299,IQ=.587,LQ=.114;function RQ(e,t={}){if(e.length<2)return k(P(M.SURFACE_GRID_TOO_SMALL,`surfaceFromGrid: need at least 2 rows, got ${e.length}`));let n=e.length,r=e[0]?.length??0;if(r<2)return k(P(M.SURFACE_GRID_TOO_SMALL,`surfaceFromGrid: need at least 2 columns, got ${r}`));for(let t=0;t<n;t++){let n=e[t];if(!n||n.length!==r)return k(P(M.SURFACE_GRID_JAGGED,`surfaceFromGrid: row ${t} has ${n?.length??0} columns, expected ${r}`))}let{width:i=r-1,depth:a=n-1,scaleZ:o=1}=t,s=i/(r-1),c=a/(n-1);try{return zQ(e,n,r,s,c,o)}catch{}try{return BQ(e,n,r,s,c,o)}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.SURFACE_FAILED,`surfaceFromGrid failed: ${t}`,e))}}function zQ(e,t,n,r,i,a){let o=[];for(let s=0;s<t;s++)for(let t=0;t<n;t++){let n=e[s],c=(n?n[t]??0:0)*a;o.push([t*r,s*i,c])}let s=U(H().bsplineSurface(o,t,n));return FE(s)?O(s):(W(s),k(N(M.SURFACE_FAILED,`B-spline surface did not produce a face`)))}function BQ(e,t,n,r,i,a){let o=[];for(let s=0;s<t;s++)for(let t=0;t<n;t++){let n=e[s],c=(n?n[t]??0:0)*a;o.push([t*r,s*i,c])}let s=U(H().triangulatedSurface(o,t,n));return FE(s)||IE(s)?O(s):(W(s),k(N(M.SURFACE_FAILED,`surfaceFromGrid: unexpected shape type from sewing`)))}async function VQ(e,t={}){let n=t.channel??`luminance`,r=Math.max(1,Math.round(t.downsample??1));if(typeof createImageBitmap!=`function`)return k(Do(M.SURFACE_FAILED,`surfaceFromImage requires createImageBitmap (not available in this environment)`));let i;try{i=await createImageBitmap(e)}catch(e){return k(Do(M.SURFACE_FAILED,`surfaceFromImage: failed to decode image — ${e instanceof Error?e.message:String(e)}`))}let a=i.width,o=i.height;if(a<2||o<2)return i.close(),k(P(M.SURFACE_GRID_TOO_SMALL,`surfaceFromImage: image too small (${a}x${o}), need at least 2x2`));if(typeof OffscreenCanvas!=`function`)return i.close(),k(Do(M.SURFACE_FAILED,`surfaceFromImage requires OffscreenCanvas (not available in this environment)`));let s=new OffscreenCanvas(a,o).getContext(`2d`);if(!s)return i.close(),k(Do(M.SURFACE_FAILED,`surfaceFromImage: could not get 2D canvas context`));s.drawImage(i,0,0),i.close();let c=s.getImageData(0,0,a,o).data,l=[];for(let e=0;e<o;e+=r){let t=[];for(let i=0;i<a;i+=r){let r=(e*a+i)*4,o=c[r]??0,s=c[r+1]??0,l=c[r+2]??0,u;switch(n){case`r`:u=o/255;break;case`g`:u=s/255;break;case`b`:u=l/255;break;default:u=(FQ*o+IQ*s+LQ*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),RQ(l,u)}function HQ(e,t){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function UQ(e,t={}){if(e.length===0)return k(P(M.HULL_EMPTY_INPUT,`hull: at least one shape is required`,void 0,void 0,`Provide one or more shapes to compute a convex hull`));for(let[t,n]of e.entries()){let e=HQ(n,`hull: shapes[${t}]`);if(A(e))return e}let n=t.tolerance??.1;try{let t=H(),r=e.map(e=>e.wrapped),i=U(t.hull(r,n));return LE(i)?O(i):(W(i),k(N(M.HULL_NOT_3D,`Hull result is not a solid; input may be degenerate`)))}catch(e){let t=e instanceof Error?e.message:String(e);return t.includes(`coplanar`)||t.includes(`fewer than`)||t.includes(`degenerate`)?k(N(M.HULL_DEGENERATE,`Hull degenerate: ${t}`,e)):k(N(M.HULL_FAILED,`Hull operation failed: ${t}`,e))}}function WQ(e){if(e.length<4)return k(P(M.HULL_EMPTY_INPUT,`convexHull: at least 4 points required, got ${e.length}`,void 0,void 0,`Provide 4 or more non-coplanar 3D points`));try{let t=H(),n=e.map(e=>({x:e[0],y:e[1],z:e[2]})),r=U(t.hullFromPoints(n,.1));return LE(r)?O(r):(W(r),k(N(M.HULL_NOT_3D,`convexHull result is not a solid; points may be coplanar`)))}catch(e){let t=e instanceof Error?e.message:String(e);return t.includes(`coplanar`)||t.includes(`fewer than`)||t.includes(`degenerate`)?k(N(M.HULL_DEGENERATE,`convexHull degenerate: ${t}`,e)):k(N(M.HULL_FAILED,`convexHull failed: ${t}`,e))}}function GQ(e){let n=dD(e);if(n.length!==1)return null;let r=t(n,0);if(ED(r)!==`sphere`)return null;let i=H().area(r.wrapped);return Math.sqrt(i/(4*Math.PI))}function KQ(e,t,n){try{let r=U(H().offset(e.wrapped,t,n));return zE(r)?O(r):(W(r),k(Co(M.MINKOWSKI_NOT_3D,`Minkowski sphere offset did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.MINKOWSKI_FAILED,`Minkowski sphere offset failed: ${t}`,e,{operation:`minkowski`,fastPath:`sphere`}))}}function qQ(e,t,n){let r=H();try{let i=pD(e),a=pD(t);if(i.length===0||a.length===0)return k(N(M.MINKOWSKI_FAILED,`Minkowski sum: one or both shapes have no vertices`,void 0,{operation:`minkowski`}));let o=[];for(let e of i){let[t,n,i]=r.vertexPosition(e.wrapped);for(let e of a){let[a,s,c]=r.vertexPosition(e.wrapped);o.push({x:t+a,y:n+s,z:i+c})}}let s=U(r.hullFromPoints(o,n));return zE(s)?O(s):(W(s),k(Co(M.MINKOWSKI_NOT_3D,`Minkowski hull did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.MINKOWSKI_FAILED,`Minkowski general path failed: ${t}`,e,{operation:`minkowski`}))}}function JQ(e,t,n={}){let{tolerance:r=1e-6}=n;if(H().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`minkowski: shape is a null shape`));if(H().isNull(t.wrapped))return k(P(M.MINKOWSKI_NULL_TOOL,`minkowski: tool is a null shape`));if(!zE(e)||!zE(t))return k(P(M.MINKOWSKI_NOT_3D,`minkowski: both shape and tool must be 3D`));let i=GQ(t);return i===null?qQ(e,t,r):KQ(e,i,r)}function YQ(e,t,n={}){let{tolerance:r=1e-6}=n;if(e.length<4)return k(P(M.POLYHEDRON_INSUFFICIENT_POINTS,`polyhedron: need at least 4 points, got ${e.length}`));if(t.length<4)return k(P(M.POLYHEDRON_INSUFFICIENT_FACES,`polyhedron: need at least 4 faces, got ${t.length}`));let i=[];for(let[n,r]of t.entries()){for(let t of r)if(t<0||t>=e.length)return k(P(M.POLYHEDRON_INVALID_INDEX,`polyhedron: face ${n} has out-of-range index ${t} (${e.length} points)`));if(r.length<3)continue;let t=r[0];for(let e=1;e<r.length-1;e++)i.push([t,r[e],r[e+1]])}try{let t=H(),n=e.map(([e,t,n])=>({x:e,y:t,z:n})),a=U(t.buildSolidFromFaces(n,i,r));return LE(a)?O(a):(W(a),k(N(M.POLYHEDRON_FAILED,`Polyhedron did not produce a solid`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.POLYHEDRON_FAILED,`Polyhedron failed: ${t}`,e))}}var XQ=1e-10;function ZQ(e,t,n,r){return e*r-t*n}function QQ(e,t,n,r){return e*n+t*r}function $Q(e,t){return Math.sqrt(e*e+t*t)}function e$(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 t$(e){let t=0;for(let n=0;n<e.length;n++){let r=e$(e,n),i=e$(e,n+1);t+=r.x*i.y-i.x*r.y}return t<0?[...e].reverse():e}function n$(e,t){let n=e$(e,t-1),r=e$(e,t),i=e$(e,t+1),a=r.x-n.x,o=r.y-n.y,s=$Q(a,o),c=i.x-r.x,l=i.y-r.y,u=$Q(c,l);if(s<XQ||u<XQ)return{dx:0,dy:0};let d=-o/s,f=a/s,p=-l/u,m=c/u,h=d+p,g=f+m,_=$Q(h,g);if(_<XQ)return{dx:d,dy:f};h/=_,g/=_;let v=QQ(h,g,d,f),y=Math.abs(v)>XQ?1/v:1;return{dx:h*y,dy:g*y}}function r$(e){return!e.prev||!e.next?!1:ZQ(e.x-e.prev.x,e.y-e.prev.y,e.next.x-e.x,e.next.y-e.y)<-1e-10}function i$(e){let t=e.map((t,n)=>{let r=n$(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 a$(e,t){let n=e;for(let e=0;e<t&&n;e++)n.active=!1,n=n.next}function o$(e){let t=1,n=e.next;for(;n!==e&&(t++,n=n.next,!(t>1e4)););return t}function s$(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)<XQ&&Math.abs(r)<XQ)return null;let o;if(o=Math.abs(n)>Math.abs(r)?i/n:a/r,o<XQ)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)>XQ){let e=c/s;if(Math.abs(o-e)>1e-4*Math.max(1,Math.abs(o)))return null}return o}function c$(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=$Q(r,i);if(a<XQ)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)<XQ)return null;let f=-c/d;if(f<XQ)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=$Q(y,b);if(x<XQ)return f;let S=QQ(p-h,m-g,y,b)/(x*x);return S<-.01||S>1.01?null:f}function l$(e){let t=[];for(let n of e){if(!n.active||!n.next)continue;let e=s$(n,n.next);if(e!==null&&e>XQ){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(r$(n)){let e=n.next.next,r=0;for(;e!==n.prev&&e!==n&&r<1e3;){let i=c$(n,e,e.next);if(i!==null&&i>XQ){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 u$(e){if(e.length<3)return O({nodes:[],faces:[]});try{return O(d$(e))}catch(e){return k(Eo(M.STRAIGHT_SKELETON_FAILED,e instanceof Error?e.message:String(e),e))}}function d$(e){let t=t$(e),n=t.length,r=[],i=Array.from({length:n},()=>[]),a=i$(t),o=0,s=n*n*2;for(;o<s;){o++;let e=a.find(e=>e.active);if(!e)break;let t=o$(e);if(t<=3){if(t===3){let t=e,n=t.next,a=n.next,o=s$(t,n),s=o!==null&&o>XQ?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 a$(e,t);continue}let n=a.filter(e=>e.active),s=l$(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=n$(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=n$(f(e),0);e.bx=p.dx,e.by=p.dy;let m=n$(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=[e$(t,e),e$(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&&$Q(n.x-i.x,n.y-i.y)>XQ&&(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 f$(e){let t=uD(e).map(e=>{let t=Mk(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 p$(e){let t=[];for(let n=1;n<e-1;n++)t.push([0,n,n+1]);return t}function m$(e,t,n,r,i,a){return(n-e)*(a-t)-(r-t)*(i-e)}function h$(e,t,n,r,i,a,o,s){let c=m$(n,r,i,a,e,t),l=m$(i,a,o,s,e,t),u=m$(o,s,n,r,e,t);return!((c<0||l<0||u<0)&&(c>0||l>0||u>0))}function g$(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||m$(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&&h$(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 _$(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=p$(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 v$(e,t){let n=(t?.angle??45)*JE,r=Math.tan(n);try{let t=f$(e);if(t.length<3)return k(N(M.ROOF_FAILED,`Wire must have at least 3 edges for roof generation`));let n=u$(t);if(!n.ok)return n;let i=n.value;if(i.faces.length===0)return k(N(M.ROOF_FAILED,`Straight skeleton computation produced no faces`));let a=H(),o=_$(i,r,a);for(let[e,n,r]of g$(t)){let i=t[e],s=t[n],c=t[r];if(!i||!s||!c)continue;let l=[i.x,i.y,0],u=[s.x,s.y,0],d=[c.x,c.y,0],f=a.buildTriFace(l,d,u);f!==null&&o.push(f)}if(o.length===0)return k(N(M.ROOF_FAILED,`No valid triangular faces could be built`));try{let e=a.sewAndSolidify(o,1e-6),t=a.fixShape(e);return t!==e&&a.dispose(e),O(kE(t))}catch(e){try{let t=kE(a.sew(o,1e-6));return mE(t)?O(t):k(N(M.ROOF_FAILED,`Sew fallback produced invalid solid`,e))}catch(e){return k(N(M.ROOF_FAILED,`Failed to sew roof faces`,e))}}finally{for(let e of o)a.dispose(e)}}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.ROOF_FAILED,`Roof generation failed: ${t}`,e))}}function y$(e){return[[1,0,0,e[0]],[0,1,0,e[1]],[0,0,1,e[2]],[0,0,0,1]]}function b$(e){let t=e[0];return t!==void 0&&typeof t[0]==`number`}function x$(e,t,n){return{__instanced:!0,source:e,placements:t,grid:n,[Symbol.dispose](){e[Symbol.dispose]()}}}function S$(e){return typeof e==`object`&&!!e&&e.__instanced===!0}function C$(e,t){return x$(e,b$(t)?t.map(y$):t.map(e=>e.map(e=>[...e])))}function w$(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(y$([e*i,t*a,0]));return x$(e,o,{cols:n,rows:r,pitchX:i,pitchY:a})}function T$(e){return e.placements.length}function E$(e,t={}){let{source:n,placements:r,grid:i}=e;return r.length===0?k(P(`INSTANCE_EMPTY`,`materialize: instance has no placements`)):t.fuse?zE(n)?i?qP(n,[1,0,0],[0,1,0],i.cols,i.rows,i.pitchX,i.pitchY):D$(n,r,!0):k(P(`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=bk(e,n);if(!t.ok){for(let e of r)e[Symbol.dispose]();return t}r.push(t.value)}let i=n?GA(r,{unsafe:!0}):O(mj(r));for(let e of r)(!i.ok||e!==i.value)&&e[Symbol.dispose]();return i}function O$(e,t){return{geometry:nA(e.source,t),instances:e.placements}}var k$={coincident:3,concentric:4,distance:1,angle:1},A$=[1,0,0,0];function j$(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function M$(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function N$(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function P$(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 F$(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function I$(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function L$(e){return I$(P$(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function R$(e,t){let n=j$(oF(t.rotation,e.origin),t.position);return{type:e.type,origin:n,...e.normal?{normal:oF(t.rotation,e.normal)}:{},...e.direction?{direction:oF(t.rotation,e.direction)}:{}}}function z$(e,t,n){let r=e.normal??[0,0,1];return{position:F$(r,N$(r,M$(e.origin,t.origin))+n),rotation:A$}}function B$(e,t){let n=e.direction??[0,0,1],r=cF(t.direction??[0,0,1],n),i=oF(r,t.origin);return{position:M$(e.origin,i),rotation:r}}function V$(e,t,n){let r=I$(e.normal??[0,0,1]),i=I$(t.normal??[0,0,1]),a=Math.acos(Math.max(-1,Math.min(1,N$(i,r)))),o=P$(i,r);return{position:[0,0,0],rotation:sF(Math.hypot(o[0],o[1],o[2])<1e-9?L$(i):o,a-n)}}function H$(e,t,n){let r=M$(t,e),i=Math.hypot(r[0],r[1],r[2]);return{position:M$(j$(e,F$(i<1e-9?[1,0,0]:F$(r,1/i),n)),t),rotation:A$}}function U$(e,t,n,r){let i=I$(e);return{position:F$(i,N$(i,M$(t,n))-r),rotation:A$}}function W$(e,t,n){let r=I$(e.direction??[0,0,1]),i=j$(e.origin,F$(r,N$(r,M$(t,e.origin))));if(n===0)return{position:M$(i,t),rotation:A$};let a=M$(t,i),o=Math.hypot(a[0],a[1],a[2]);return{position:M$(j$(i,F$(o<1e-9?L$(r):F$(a,1/o),n)),t),rotation:A$}}function G$(e,t,n){let r=I$(t.direction??[0,0,1]),i=M$(t.origin,e),a=M$(i,F$(r,N$(r,i))),o=Math.hypot(a[0],a[1],a[2]);return n===0?{position:F$(a,-1),rotation:A$}:{position:M$(F$(o<1e-9?L$(r):F$(a,1/o),n),a),rotation:A$}}function K$(e,t,n){let r=I$(e.direction??[0,0,1]),i=cF(I$(t.direction??[0,0,1]),r),a=M$(oF(i,t.origin),e.origin),o=M$(a,F$(r,N$(r,a))),s=Math.hypot(o[0],o[1],o[2]);return{position:M$(F$(s<1e-9?L$(r):F$(o,1/s),n),o),rotation:i}}var q$=new Set([`plane-plane`,`plane-point`,`point-plane`,`point-point`,`axis-axis`,`axis-point`,`point-axis`]),J$={angle:`plane`,concentric:`axis`},Y$=new Set([`coincident`,`distance`,`angle`,`concentric`]);function X$(e,t,n){let r=J$[e];return r?t===r&&n===r:q$.has(`${t}-${n}`)}function Z$(e,t,n){switch(`${e.type}-${t.type}`){case`plane-plane`:case`plane-point`:return z$(e,t,n);case`point-plane`:return U$(t.normal??[0,0,1],e.origin,t.origin,n);case`point-point`:return H$(e.origin,t.origin,n);case`axis-axis`:return n===0?B$(e,t):K$(e,t,n);case`axis-point`:return W$(e,t.origin,n);case`point-axis`:return G$(e.origin,t,n);default:return null}}function Q$(e,t,n){switch(e.type){case`concentric`:return B$(t,n);case`angle`:return V$(t,n,(e.value??0)*Math.PI/180);default:{let r=Z$(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 $$(e,t){let n=new Map;for(let t of e)n.set(t,{position:[0,0,0],rotation:A$});let r=[],i=t.filter(e=>Y$.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(!X$(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:A$},l=R$(r.entity,a);n.set(i.node,Q$(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+(k$[t]??k$[t.split(`(`)[0]??``]??0),0),converged:r.length===0,unsupported:r}}function e1(e){if(e.face){let t=EO(e.face);return t?{type:`axis`,origin:t.origin,direction:t.direction}:{type:`plane`,origin:TO(e.face),normal:wO(e.face)}}if(e.edge){if(jk(e.edge)===`LINE`)return{type:`axis`,origin:Mk(e.edge),direction:Fk(e.edge)};let t=Lk(e.edge);return t?{type:`axis`,origin:t.origin,direction:t.direction}:null}return e.point?{type:`point`,origin:e.point}:null}function t1(e,t){let n=e1(e),r=e1(t);return!n||!r?k(P(M.ASSEMBLY_MATE_INVALID,`solveAssembly: could not extract geometry from mate entities`)):O({entityA:{node:e.node,entity:n},entityB:{node:t.node,entity:r}})}function n1(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=t1(e.entityA,e.entityB);return t.ok?O({type:`coincident`,...t.value}):t}case`distance`:{let t=t1(e.entityA,e.entityB);return t.ok?O({type:`distance`,...t.value,value:e.distance}):t}case`angle`:{let t=t1(e.entityA,e.entityB);return t.ok?O({type:`angle`,...t.value,value:e.angle}):t}case`concentric`:{let t=t1(e.axisA,e.axisB);return t.ok?O({type:`concentric`,...t.value}):t}}}function r1(e,t){let n=e.mates??[];return{...e,mates:[...n,t]}}function i1(e){let t=e.mates;if(!t||t.length===0)return k(P(M.ASSEMBLY_MATE_INVALID,`solveAssembly: no mates defined`));try{let n=[];$P(e,e=>{n.push(e.name)});let r=[];for(let e of t){let t=n1(e);if(!t.ok)return t;r.push(t.value)}let i=$$(n,r);if(!i.converged){let e=i.unsupported.length>0?`Unsupported constraint types: ${i.unsupported.join(`, `)} (${i.dof} DOF unresolved)`:`Assembly constraint solver did not converge`;return k(N(M.ASSEMBLY_NOT_CONVERGED,e))}return O({transforms:i.transforms,dof:i.dof,converged:i.converged})}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.ASSEMBLY_SOLVE_FAILED,`Assembly solve failed: ${t}`,e))}}function a1(e,t,n=1e-6){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`checkInterference: first shape is a null shape`)):H().isNull(t.wrapped)?k(P(M.NULL_SHAPE_INPUT,`checkInterference: second shape is a null shape`)):JT(()=>{let r=H().distance(e.wrapped,t.wrapped);return O({hasInterference:r.value<=n,minDistance:r.value,pointOnShape1:r.point1,pointOnShape2:r.point2})})}function o1(e,n=1e-6){let r=[],i=e.map(e=>wD(e));return e.forEach((a,o)=>{for(let s=o+1;s<e.length;s++){if(s1(t(i,o),t(i,s),n))continue;let c=j(a1(a,t(e,s),n));c.hasInterference&&r.push({i:o,j:s,result:c})}}),r}function s1(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 c1(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 l1(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 u1(e){let{type:t,data:n}=e,r=H();if(t===`LINE`)return r.makeLineEdge([l1(n,10),l1(n,20),l1(n,30)],[l1(n,11),l1(n,21),l1(n,31)]);if(t===`CIRCLE`)return r.makeCircleEdge([l1(n,10),l1(n,20),l1(n,30)],[0,0,1],l1(n,40));if(t===`ARC`){let e=l1(n,50)*Math.PI/180,t=l1(n,51)*Math.PI/180;return r.makeCircleArc([l1(n,10),l1(n,20),l1(n,30)],[0,0,1],l1(n,40),e,t)}}async function d1(e,t){let n;try{n=await e.text()}catch(e){return k(Do(M.DXF_IMPORT_FAILED,`Failed to read DXF blob`,e))}let r=c1(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=u1(e);t!==void 0&&a.push(t)}return a.length===0?O([]):O([EE(H().makeWire(a))])}catch(e){return k(Do(M.DXF_IMPORT_FAILED,`Failed to convert DXF entities to geometry`,e))}finally{for(let e of a)e.delete()}}function f1(e,t,n=1e-6){let r=H(),i=[];for(let[t,n,a]of e){let e=r.buildTriFace(t,n,a);e!==null&&i.push(e)}if(i.length===0)return k(Do(t,`No valid triangular faces could be built`));try{let e=U(r.sewAndSolidify(i,n));for(let e of i)r.dispose(e);return O(e)}catch{try{return O(VE(r.sew(i,n)))}catch(e){return k(Do(t,`Failed to sew triangular faces`,e))}}}function p1(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 m1(e){return e.split(/\s+/).slice(1).map(e=>parseInt(e.split(`/`)[0]??``,10)).filter(e=>!isNaN(e))}async function h1(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=p1(t);e&&n.push(e)}else if(t.startsWith(`f `)){let e=m1(t);e.length>=3&&r.push(e)}}if(n.length===0||r.length===0)return k(Do(M.OBJ_IMPORT_FAILED,`OBJ file contains no valid geometry`));try{return g1(n,r)}catch(e){let t=e instanceof Error?e.message:String(e);return k(Do(M.OBJ_IMPORT_FAILED,`OBJ import failed: ${t}`,e))}}function g1(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 f1(n,M.OBJ_IMPORT_FAILED)}function _1(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 v1(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95}function y1(e){let t={},n=0;for(;n<e.length;){let r=e.indexOf(`="`,n);if(r<0)break;let i=r;for(;i>0&&v1(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 b1(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 x1(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 S1(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 C1(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=y1(e.slice(r,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of b1(a,`color`)){let t=y1(e).color;t!==void 0&&l.push(S1(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=y1(e.slice(n,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of b1(a,`base`)){let t=y1(e).displaycolor;t===void 0?l.push([0,0,0,1]):l.push(S1(t))}t.set(c,l)}return t}function w1(e){let t=[],n=[],r=[],i=C1(e);for(let n of b1(e,`vertex`)){let e=y1(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=x1(e,`object`);if(s!==null){let e=s.indexOf(`>`);if(e>=0){let t=y1(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 b1(e,`triangle`)){let e=y1(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 T1(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 E1(e){let t=H(),n=e.vertices.map(([e,t,n])=>({x:e,y:t,z:n})),r=e.triangles;try{return O(U(t.buildSolidFromFaces(n,r,1e-6)))}catch{let t=[];for(let[n,r,i]of e.triangles){let a=e.vertices[n],o=e.vertices[r],s=e.vertices[i];!a||!o||!s||t.push([a,o,s])}return f1(t,M.THREEMF_IMPORT_FAILED)}}async function D1(e){try{let t=await e.arrayBuffer(),n=_1(new Uint8Array(t),`3D/3dmodel.model`);if(!n)return k(Do(M.THREEMF_IMPORT_FAILED,`3MF archive does not contain 3D/3dmodel.model (or uses unsupported compression)`));let r=w1(new TextDecoder().decode(n));if(r.vertices.length===0||r.triangles.length===0)return k(Do(M.THREEMF_IMPORT_FAILED,`3MF model contains no valid geometry`));let i=E1(r);if(i.ok){let e=T1(r.triangleColors);e!==null&&nk(i.value,e)}return i}catch(e){let t=e instanceof Error?e.message:String(e);return k(Do(M.THREEMF_IMPORT_FAILED,`3MF import failed: ${t}`,e))}}async function O1(e){try{let t=await e.arrayBuffer();return O(U(H().importGLB(t)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(Do(M.GLB_IMPORT_FAILED,`Failed to import GLB: ${t}`,e))}}function $(e){return`__wrapped`in e?e.val:e}function k1(e){return $(e)}function A1(e,t){return fk($(e),t)}function j1(e,t,n){let r=n?.at;return pk($(e),t,r,n?.axis)}function M1(e,t){let n=t?.at;return mk($(e),t?.normal??[1,0,0],n)}function N1(e,t,n){return hk($(e),t,n?.center)}function P1(e){return wk($(e))}function F1(e,t){return bk($(e),t)}function I1(e,t){return Ck($(e),t)}function L1(e,t){return Sk($(e),t)}function R1(e,t,n){return VA($(e),$(t),{...n,unsafe:!0})}function z1(e,t,n){return HA($(e),$(t),{...n,unsafe:!0})}function B1(e,t){return GA(e.map(e=>$(e)),{...t,unsafe:!0})}function V1(e,t,n){return KA($(e),t.map(e=>$(e)),{...n,unsafe:!0})}function H1(e,t,n){return UA($(e),$(t),{...n,unsafe:!0})}function U1(e,t,n){return JA($(e),t,n)}function W1(e,t,n){return ej($(e),t,n)}function G1(e,t){return tj($(e),t)}function K1(e,t,n){return nj($(e),t,n)}function q1(e,t){if(e!==void 0)return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(qI()).findAll(t)}function J1(e,t){return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(XI()).findAll(t)}function Y1(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 X1(e,t,n){let r=$(e),i,a;return n===void 0?(i=void 0,a=t):(i=q1(t,r),a=n),eM(r,i,a)}function Z1(e,t,n){let r=$(e),i,a;n===void 0?(i=void 0,a=t):(i=q1(t,r),a=n);let o=Y1(a);return o.mode===`distAngle`?xj(r,[...i??uD(r)],o.distance,o.angle):tM(r,i,o.distance)}function Q1(e,t,n,r){let i=$(e);return nM(i,J1(t,i),n,r?.tolerance)}function $1(e,t,n){return rM($(e),t,n?.tolerance)}function e0(e,t){return Qj($(e),t)}function t0(e,t,n){let r=$(e);return aM(r,J1(t,r),n.pullDirection,n.neutralPlane,n.angle)}function n0(e){return dM($(e))}function r0(e){return Ak($(e))}function i0(e,t){return nA($(e),t)}function a0(e,t){return rA($(e),t)}function o0(e){return OD($(e))}function s0(e){return Tk($(e))}function c0(e){return mO(e)}function l0(e){return sM($(e))}function u0(e){return Dk($(e))}function d0(e,t){return OM($(e),typeof t==`number`?[0,0,t]:t)}function f0(e,t){let n=t?.at??[0,0,0];return kM($(e),n,t?.axis??[0,0,1],t?.angle??2*Math.PI)}function p0(e,t){return jM(e.map(e=>$(e)),t)}function m0(e,n){if(n===void 0){let t=dD(e);if(t.length===0)return k(P(M.COMPOUND_NO_FACES,`compoundOps: shape has no faces`));let n=vA(t),r=TO(n)[2];for(let e=1;e<t.length;e++){let i=_A(t,e),a=TO(i)[2];a>r&&(n=i,r=a)}return O(n)}if(typeof n==`function`){let r=n(XI()).findAll(e);return r.length===0?k(Oo(M.COMPOUND_FACE_NOT_FOUND,`compoundOps: face finder matched no faces`)):O(t(r,0))}return O(n)}function h0(e){return`sketchOnPlane`in e&&typeof e.sketchOnPlane==`function`?{wire:e.sketchOnPlane(`XY`).wire,owned:!0}:{wire:e,owned:!1}}function g0(e,t){let n=$(e),{at:r,radius:i,axis:a}=t,o=a??[0,0,1];if(i<=0)return k(P(`DRILL_INVALID_RADIUS`,`Drill radius must be positive`));if(GD(o))return k(P(`DRILL_ZERO_AXIS`,`Drill axis cannot be zero`));let s=UD(o),c=r.length===2?[r[0],r[1],0]:[r[0],r[1],r[2]],l;if(t.depth!==void 0)l=sj(i,t.depth,c,s);else{let e=wD(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=sj(i,a-r,[c[0]+s[0]*r,c[1]+s[1]*r,c[2]+s[2]*r],s)}try{return HA(n,l,{unsafe:!0})}finally{l[Symbol.dispose]()}}function _0(e,t){try{var n=IT();let r=$(e),{profile:i,depth:a}=t;if(a<=0)return k(P(`POCKET_INVALID_DEPTH`,`Pocket depth must be positive`));let o=m0(r,t.face);if(A(o))return o;let s=o.value,c=wO(s),l=TO(s),u=n.u(new XT),{wire:d,owned:f}=h0(i);f&&u.register(d);let p=NA(d);if(A(p))return p;u.register(p.value);let m=OM(u.register(fk(p.value,l)),ID(UD(c),-a));return A(m)?m:(u.register(m.value),HA(r,m.value,{unsafe:!0}))}catch(e){n.e=e}finally{n.d()}}function v0(e,t){try{var n=IT();let r=$(e),{profile:i,height:a}=t;if(a<=0)return k(P(`BOSS_INVALID_HEIGHT`,`Boss height must be positive`));let o=m0(r,t.face);if(A(o))return o;let s=o.value,c=wO(s),l=TO(s),u=n.u(new XT),{wire:d,owned:f}=h0(i);f&&u.register(d);let p=NA(d);if(A(p))return p;u.register(p.value);let m=OM(u.register(fk(p.value,l)),ID(UD(c),a));return A(m)?m:(u.register(m.value),VA(r,m.value,{unsafe:!0}))}catch(e){n.e=e}finally{n.d()}}function y0(e,t){try{var n=IT();let r=$(e),i=t?.normal??[1,0,0],a=t?.at;return GD(i)?k(P(`MIRROR_ZERO_NORMAL`,`Mirror plane normal cannot be zero`)):VA(r,n.u(mk(r,i,a)),{unsafe:!0})}catch(e){n.e=e}finally{n.d()}}function b0(e,t){let n=$(e),{xDir:r,xCount:i,xSpacing:a,yDir:o,yCount:s,ySpacing:c}=t;if(i<1||s<1)return k(P(`PATTERN_INVALID_COUNT`,`Pattern counts must be at least 1`));if(GD(r))return k(P(`PATTERN_ZERO_DIRECTION`,`X direction cannot be zero`));if(GD(o))return k(P(`PATTERN_ZERO_DIRECTION`,`Y direction cannot be zero`));if(i===1&&s===1)return O(n);let l=UD(r),u=UD(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=fk(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 GA(d,{unsafe:!0})}finally{for(let e of f)e[Symbol.dispose]()}}var x0=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 S0(e){if(A(e))throw new x0(e.error);return e.value}function C0(e){return e}function w0(e){return e}function T0(e){return e}function E0(e){return e}function D0(e){return{val:e,__wrapped:!0,translate:t=>L0(A1(e,t)),rotate:(t,n)=>L0(j1(e,t,n)),mirror:t=>L0(M1(e,t)),scale:(t,n)=>L0(N1(e,t,n)),applyMatrix:t=>L0(S0(F1(e,t))),moveX:t=>L0(A1(e,[t,0,0])),moveY:t=>L0(A1(e,[0,t,0])),moveZ:t=>L0(A1(e,[0,0,t])),rotateX:t=>L0(j1(e,t,{axis:[1,0,0]})),rotateY:t=>L0(j1(e,t,{axis:[0,1,0]})),rotateZ:t=>L0(j1(e,t,{axis:[0,0,1]})),bounds:()=>wD(e),describe:()=>o0(e),clone:()=>L0(S0(P1(e))),mesh:t=>i0(e,t),meshEdges:t=>a0(e,t),isValid:()=>l0(e),isEmpty:()=>u0(e),heal:()=>L0(S0(n0(e))),simplify:()=>L0(S0(r0(e))),toBREP:()=>S0(s0(e)),apply:t=>L0(t(e)),applyResult:t=>L0(S0(t(e))),done:()=>e}}function O0(e){return{fuse:(t,n)=>R0(S0(R1(e,$(t),{...n,unsafe:!0}))),cut:(t,n)=>R0(S0(z1(e,$(t),{...n,unsafe:!0}))),intersect:(t,n)=>R0(S0(H1(e,$(t),{...n,unsafe:!0}))),fuseAll:(t,n)=>R0(E0(S0(GA([e,...t.map($)],{...n,unsafe:!0})))),cutAll:(t,n)=>R0(E0(S0(KA(e,t,{...n,unsafe:!0})))),section:(t,n)=>L0(S0(U1(e,t,n))),split:t=>L0(S0(G1(e,t))),slice:(t,n)=>S0(K1(e,t,n))}}function k0(e){return{fillet(...t){return t.length===1?R0(E0(S0(X1(C0(e),t[0])))):R0(E0(S0(X1(C0(e),t[0],t[1]))))},chamfer(...t){return t.length===1?R0(E0(S0(Z1(C0(e),t[0])))):R0(E0(S0(Z1(C0(e),t[0],t[1]))))},shell:(t,n,r)=>R0(E0(S0(Q1(C0(e),t,n,r)))),offset:(t,n)=>R0(E0(S0($1(C0(e),t,n)))),draft:(t,n)=>R0(E0(S0(t0(C0(e),t,n))))}}function A0(e){return{drill:t=>R0(S0(g0(e,t))),pocket:t=>R0(S0(_0(e,t))),boss:t=>R0(S0(v0(e,t))),mirrorJoin:t=>R0(S0(y0(e,t))),rectangularPattern:t=>R0(S0(b0(e,t)))}}function j0(e){return{volume:()=>S0(VM(e)),area:()=>S0(HM(e)),volumeProps:()=>S0(RM(e)),surfaceProps:()=>S0(zM(e))}}function M0(e){return{edges:()=>uD(e),faces:()=>dD(e),wires:()=>fD(e),vertices:()=>pD(e)}}function N0(e){return{linearPattern:(t,n,r)=>R0(E0(S0(GP(e,t,n,r)))),circularPattern:(t,n,r)=>R0(E0(S0(KP(e,t,n,r))))}}function P0(e){return{...D0(e),...O0(e),...k0(e),...A0(e),...j0(e),...M0(e),...N0(e)}}function F0(e){return{...D0(e),length:()=>Ik(e),startPoint:()=>Mk(e),endPoint:()=>Nk(e),pointAt:t=>Pk(e,t),tangentAt:t=>Fk(e,t),isClosed:()=>Rk(e),sweep(t,n){if(!PE(e))throw Error(`sweep requires a Wire`);let r=S0(bM(T0(e),$(t),n));return R0(Array.isArray(r)?r[0]:r)}}}function I0(e){return{...D0(e),area:()=>S0(HM(e)),normalAt:t=>wO(e,t),center:()=>TO(e),surfaceType:()=>S0(gO(e)),outerWire:()=>OO(e),innerWires:()=>AO(e),extrude:t=>R0(S0(d0(w0(e),t))),revolve:t=>R0(S0(f0(w0(e),t)))}}function L0(e){return zE(e)?P0(e):FE(e)?I0(e):NE(e)||PE(e)?F0(e):D0(e)}function R0(e){return P0(e)}function z0(e){if(e&&typeof e==`object`&&`face`in e&&typeof e.face==`function`&&`_defaultOrigin`in e)return I0(e.face());if(e&&typeof e==`object`&&`wrapped`in e)return FE(e)?I0(e):zE(e)?P0(e):NE(e)||PE(e)?F0(e):D0(e);throw Error(`shape() requires a Sketch or branded shape type`)}var B0=.25,V0=e=>Math.tan(e)-e;function H0(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 U0(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(H0(e,s*t,n,i))}return a}function W0(e){return Math.max(16,Math.round(8*Math.sqrt(e)))}function G0(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 K0(e,t,n){if(t===0)return O(e);let r=V0(e)+2*t*Math.tan(e)/n,i,a;if(r>V0(e)?(i=e,a=Math.PI/2-1e-6):(i=1e-4,a=e),r>V0(a)||r<V0(i))return k(P(`GEAR_PA_OUT_OF_RANGE`,`working pressure angle out of range — target inv(αw)=${r.toFixed(4)} not in [${V0(i).toFixed(4)}, ${V0(a).toFixed(4)}]`,void 0,{target:r,invLo:V0(i),invHi:V0(a)}));for(let e=0;e<50;e++){let e=.5*(i+a);V0(e)<r?i=e:a=e}return O(.5*(i+a))}function q0(e,t,n,r,i){return K0(e,t+n,r+i)}function J0(e,t,n,r,i){return K0(e,n-t,i-r)}function Y0(e,t,n,r,i){return(e+t)*n*Math.cos(r)/(2*Math.cos(i))}function X0(e,t,n,r){if(!Number.isInteger(e)||!Number.isInteger(t)||!Number.isInteger(n))return k(P(`GEAR_NON_INTEGER_TEETH`,`tooth counts and planet count must be integers`));if(e<4||t<4||n<2)return k(P(`GEAR_TEETH_TOO_FEW`,`zs ≥ 4, zp ≥ 4, N ≥ 2 required`));if((2*e+2*t)%n!=0)return k(P(`GEAR_ASSEMBLY`,`(2·zs + 2·zp) must be divisible by N — got ${2*e+2*t} mod ${n} = ${(2*e+2*t)%n}`));let i=t+2+2*r,a=(e+t)*Math.sin(Math.PI/n);return a<=i?k(P(`GEAR_PLANET_COLLISION`,`planet tips would collide: (zs+zp)·sin(π/N) = ${a.toFixed(3)} ≤ planet tip = ${i.toFixed(3)}`)):O(void 0)}function Z0(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 Q0(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 $0(e,t){return 1-e*Math.sin(t)*Math.sin(t)/2}function e2(e,t,n){return Math.max(0,$0(e,t)-n)}function t2(e){return e<8?.2:.485-2.88/e}function n2(e,t,n,r){let i=e*1e3,a=t2(r);return a<=0||n<=0||t<=0?1/0:2*i/(r*t*t*n*a)}function r2(e,t,n=!1){let r=(1.4+6.5/e)*(20/(t*180/Math.PI))**.15;return n?r*.85:r}function i2(e,t,n,r,i,a=!1){return n2(e,t,n,r)*r2(r,i,a)}function a2(e){return e/2}function o2(e,t){return e+2*t}function s2(e){return e%2==0?Math.PI/e:0}function c2(e,t,n){return e*(1+t/n)+s2(n)}function l2(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=X0(n,r,i,s);if(A(c))return c;let l=q0(a,o,s,n,r);if(A(l))return l;let u=Y0(n,r,t,a,l.value),d=[];for(let e=0;e<i;e++){let t=e*2*Math.PI/i,a=c2(t,n,r);d.push({rotationDeg:a*180/Math.PI,position:[u*Math.cos(t),u*Math.sin(t),0]})}return O(d)}function u2(e,t,n,r,i){let a=t*e.toothPitch,o=(t+1)%n*e.toothPitch,s=V0(e.alphaPitch),c=a-e.halfToothAngle-s,l=a+e.halfToothAngle+s,u=U0(e.rb,e.alphaTip,c,r,1),d=U0(e.rb,e.alphaTip,l,r,-1).reverse(),f=vA(u),p=yA(u),m=vA(d),h=yA(d),g=[],_=e=>{i.register(e),g.push(e)},v=e.isInternal?e.rb<e.rRoot:e.rb>e.rRoot;v&&_(SA([e.rRoot*Math.cos(c),e.rRoot*Math.sin(c),0],f));let y=e.rPitch*1e-5,b=kA(u,{tolerance:y});if(A(b))return b;_(b.value),_(EA(p,[e.rTip*Math.cos(a),e.rTip*Math.sin(a),0],m));let x=kA(d,{tolerance:y});if(A(x))return x;_(x.value),v&&_(SA(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),_(EA(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 d2(e){return p2(e,!1)}function f2(e){return p2(e,!0)}function p2(e,t){try{var n=IT();let{teeth:r,moduleSize:i,pressureAngle:a,shift:o,clearance:s,flankThinning:c,samples:l=W0(i)}=e;if(r<4)return k(P(`GEAR_TEETH_TOO_FEW`,`gear needs ≥ 4 teeth, got ${r}`));if(i<=0)return k(P(`GEAR_MODULE_NONPOSITIVE`,`module must be > 0, got ${i}`));let u=G0(r,i,a,o,s,c,t),d=n.u(new XT),f=[];for(let e=0;e<r;e++){let t=u2(u,e,r,l,d);if(A(t))return t;f.push(...t.value)}let p=MA(f);return A(p)?p:O(p.value)}catch(e){n.e=e}finally{n.d()}}function m2(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=B0,flankThinning:s=0,bore:c=0,samples:l}=e;if(r<=0)return k(P(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));if(l!==void 0&&(!Number.isInteger(l)||l<1))return k(P(`GEAR_SAMPLES_INVALID`,`samples must be a positive integer; got ${String(l)}`));let u=i*Math.PI/180,d=G0(t,n,u,a,o,s,!1);if(c>0&&c>=2*d.rRoot)return k(P(`GEAR_BORE_TOO_LARGE`,`bore diameter ${c.toFixed(2)} ≥ root diameter ${(2*d.rRoot).toFixed(2)} — would erase the gear teeth`));let f=d2({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(f))return f;let p=g2(t,u,a);return x2(f.value,r,c,d,p)}function h2(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=B0,flankThinning:s=0,ringWallThickness:c=2*e.moduleSize,samples:l}=e;if(r<=0)return k(P(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));if(c<=0)return k(P(`GEAR_WALL_NONPOSITIVE`,`ringWallThickness must be > 0`));if(l!==void 0&&(!Number.isInteger(l)||l<1))return k(P(`GEAR_SAMPLES_INVALID`,`samples must be a positive integer; got ${String(l)}`));let u=i*Math.PI/180,d=f2({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(d))return d;let f=G0(t,n,u,a,o,s,!0),p=b2(f.rPitch+c);return A(p)?p:C2(p.value,d.value,r,f,[])}function g2(e,t,n){let r=e2(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 _2(e){let t=y2(e);if(A(t))return t;let n=t.value,r=v2(n);if(A(r))return r;let{sun:i,planet:a,ring:o}=r.value,s=D2(n,i,a,o),c=T2(a.solid,n);a.solid.delete();let l=E2(o.solid,n.zr),u=O2(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 v2(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=m2({...n,teeth:e.sunTeeth,shift:e.sunShift,bore:e.sunBore});if(A(r))return r;let i=m2({...n,teeth:e.planetTeeth,shift:e.planetShift,bore:e.planetBore});if(A(i))return r.value.solid.delete(),i;let a=h2({...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 y2(e){let t=e.moduleSize??3,n=e.sunTeeth??15,r=e.planetTeeth??12,i=e.numPlanets??3,a=e.pressureAngleDeg??20,o=a*Math.PI/180,s=e.sunShift??0,c=e.planetShift??0,l=e.ringShift??0;if(e.thickness<=0)return k(P(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));let u=X0(n,r,i,c);if(A(u))return u;let d=o2(n,r),f=q0(o,s,c,n,r);if(A(f))return f;let p=J0(o,c,l,r,d);if(A(p))return p;let m=Y0(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:a2(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 b2(e){try{var t=IT();let n=MA([t.u(new XT).register(CA(e,[0,0,0],[0,0,1]))]);return A(n)?n:O(n.value)}catch(e){t.e=e}finally{t.d()}}function x2(e,t,n,r,i){try{var a=IT();let o=a.u(new XT);o.register(e);let s=NA(e);if(A(s))return s;o.register(s.value);let c=OM(s.value,[0,0,t]);if(A(c))return c;if(n<=0)return O(w2(c.value,r,i));let l=a.u(new XT);l.register(c.value);let u=S2(n/2);if(A(u))return u;l.register(u.value);let d=OM(u.value,[0,0,t+1]);if(A(d))return d;l.register(d.value);let f=l.register(fk(d.value,[0,0,-.5])),p=HA(c.value,f);return A(p)?p:O(w2(p.value,r,i))}catch(e){a.e=e}finally{a.d()}}function S2(e){let t=b2(e);return A(t)?t:NA(t.value)}function C2(e,t,n,r,i){let a=NA(e,[t]);if(A(a))return a;let o=OM(a.value,[0,0,n]);return A(o)?o:O(w2(o.value,r,i))}function w2(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 T2(e,t){let n=[];try{for(let r=0;r<t.numPlanets;r++){let i=r*2*Math.PI/t.numPlanets,a=pk(e,c2(i,t.sunTeeth,t.planetTeeth)*180/Math.PI);try{let e=[t.centerDistance*Math.cos(i),t.centerDistance*Math.sin(i),0];n.push(fk(a,e))}finally{a.delete()}}return n}catch(e){for(let e of n)e.delete();throw e}}function E2(e,t){let n=s2(t);if(n===0)return e;let r=pk(e,n*180/Math.PI);return e.delete(),r}function D2(e,t,n,r){let i={crSunPlanet:Z0(t.tipDiameter/2,t.baseDiameter/2,n.tipDiameter/2,n.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_sp),crPlanetRing:Q0(n.tipDiameter/2,n.baseDiameter/2,r.tipDiameter/2,r.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_pr),undercutSun:e2(e.sunTeeth,e.alpha,e.sunShift),undercutPlanet:e2(e.planetTeeth,e.alpha,e.planetShift)};if(e.appliedTorque!==void 0){let t=e.appliedTorque;i.lewisStress={sun:i2(t,e.moduleSize,e.thickness,e.sunTeeth,e.alpha),planet:i2(t*e.planetTeeth/e.sunTeeth,e.moduleSize,e.thickness,e.planetTeeth,e.alpha),ring:i2(t*e.zr/e.sunTeeth,e.moduleSize,e.thickness,e.zr,e.alpha,!0)},i.stressConcentrationFactor={sun:r2(e.sunTeeth,e.alpha),planet:r2(e.planetTeeth,e.alpha),ring:r2(e.zr,e.alpha,!0)}}return i}function O2(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 k2=IX({addHoles:()=>VP,bezier:()=>OP,box:()=>hP,bsplineApprox:()=>DP,circle:()=>SP,compound:()=>LP,cone:()=>vP,cylinder:()=>gP,ellipse:()=>CP,ellipseArc:()=>EP,ellipsoid:()=>bP,face:()=>MP,fill:()=>PA,filledFace:()=>NP,helix:()=>wP,line:()=>xP,offsetFace:()=>zP,polygon:()=>FP,polyhedron:()=>YQ,sewShells:()=>BP,solid:()=>RP,sphere:()=>_P,subFace:()=>PP,tangentArc:()=>kP,threePointArc:()=>TP,torus:()=>yP,vertex:()=>IP,wire:()=>AP,wireLoop:()=>jP}),A2=IX({checkBoolean:()=>Fj,convexHull:()=>WQ,cut:()=>z1,cutAll:()=>KA,cutAllBisect:()=>Ej,fuse:()=>R1,fuseAll:()=>GA,fuseAllBisect:()=>Aj,hull:()=>UQ,intersect:()=>H1,minkowski:()=>JQ,section:()=>U1,sectionToFace:()=>W1,slice:()=>K1,split:()=>G1}),j2=IX({chamfer:()=>Z1,draft:()=>t0,fillet:()=>X1,heal:()=>n0,offset:()=>$1,shell:()=>Q1,simplify:()=>r0,thicken:()=>e0,variableFillet:()=>oM}),M2=IX({applyMatrix:()=>F1,clone:()=>P1,composeTransforms:()=>xk,mirror:()=>M1,rotate:()=>j1,scale:()=>N1,transformCopy:()=>I1,translate:()=>A1}),N2=IX({checkAllInterferences:()=>o1,checkInterference:()=>a1,createDistanceQuery:()=>KM,measureArea:()=>HM,measureCurvatureAt:()=>qM,measureCurvatureAtMid:()=>JM,measureDistance:()=>WM,measureDistanceProps:()=>GM,measureLength:()=>UM,measureLinearProps:()=>BM,measureSurfaceProps:()=>zM,measureVolume:()=>VM,measureVolumeProps:()=>RM}),P2=IX({blueprintToDXF:()=>wY,exportAssemblySTEP:()=>WP,exportDXF:()=>CY,exportGlb:()=>uY,exportGltf:()=>lY,exportIGES:()=>lA,exportOBJ:()=>$J,exportSTEP:()=>sA,exportSTEPConfigured:()=>sX,exportSTL:()=>cA,exportThreeMF:()=>UY,importDXF:()=>d1,importGLB:()=>O1,importIGES:()=>uX,importOBJ:()=>h1,importSTEP:()=>cX,importSTL:()=>lX,importSVG:()=>oX,importSVGPathD:()=>aX,importThreeMF:()=>D1}),F2=IX({cornerFinder:()=>CR,edgeFinder:()=>qI,faceFinder:()=>XI,getSingleFace:()=>$I,vertexFinder:()=>GX,wireFinder:()=>QI}),I2=IX({complexExtrude:()=>SM,extrude:()=>d0,guidedSweep:()=>DM,loft:()=>p0,multiSectionSweep:()=>EM,revolve:()=>f0,roof:()=>v$,supportExtrude:()=>xM,surfaceFromGrid:()=>RQ,surfaceFromImage:()=>VQ,sweep:()=>bM,twistExtrude:()=>CM}),L2=IX({circularPattern:()=>KP,linearPattern:()=>GP}),R2=14695981039346656037n,z2=1099511628211n,B2=18446744073709551615n;function V2(){return R2}function H2(e,t){return(e^BigInt(t&255))*z2&B2}function U2(e,t){let n=e;for(let e=0;e<t.length;e++)n=H2(n,t[e]??0);return n}var W2=new TextEncoder;function G2(e,t){return U2(e,W2.encode(t))}var K2=new ArrayBuffer(8),q2=new DataView(K2),J2=new Uint8Array(K2);function Y2(e,t){return q2.setFloat64(0,Object.is(t,-0)?0:t),U2(e,J2)}function X2(e,t){let n=e,r=t&B2;for(let e=0;e<8;e++)n=H2(n,Number(r&255n)),r>>=8n;return n}function Z2(e,t){let n=e,r=t|0;for(let e=0;e<4;e++)n=H2(n,r&255),r>>>=8;return n}function Q2(e,t){return H2(e,+!!t)}function $2(e){return(e&B2).toString(16).padStart(16,`0`)}var e4=new Set;function t4(e){return G2(V2(),e)}function n4(e){return{kind:`NumLit`,value:e,structuralHash:Y2(t4(`NumLit`),e),freeParams:e4}}function r4(e){let t=t4(`Vec3Lit`);for(let n of e)t=Y2(t,n);return{kind:`Vec3Lit`,value:e,structuralHash:t,freeParams:e4}}function i4(e){let t=t4(`Vec2Lit`);for(let n of e)t=Y2(t,n);return{kind:`Vec2Lit`,value:e,structuralHash:t,freeParams:e4}}function a4(e){return{kind:`Param`,name:e,structuralHash:G2(t4(`Param`),e),freeParams:new Set([e])}}function o4(e,t,n){let r=G2(t4(`BinOp`),e);return r=X2(r,t.structuralHash),r=X2(r,n.structuralHash),{kind:`BinOp`,op:e,a:t,b:n,structuralHash:r,freeParams:g4(t.freeParams,n.freeParams)}}function s4(e,t){let n=G2(t4(`UnaryOp`),e);return n=X2(n,t.structuralHash),{kind:`UnaryOp`,op:e,arg:t,structuralHash:n,freeParams:t.freeParams}}function c4(e,t){let n=Z2(t4(`Component`),t);return n=X2(n,e.structuralHash),{kind:`Component`,vec:e,index:t,structuralHash:n,freeParams:e.freeParams}}function l4(e,t){let n=Z2(t4(`BuildVec`),e),r=new Set;for(let e of t){n=X2(n,e.structuralHash);for(let t of e.freeParams)r.add(t)}return{kind:`BuildVec`,dim:e,components:t,structuralHash:n,freeParams:r}}var u4=(e,t)=>o4(`+`,e,t),d4=(e,t)=>o4(`*`,e,t);function f4(e){return typeof e==`number`?n4(e):e}function p4(e,t){if(!Array.isArray(e))return e;let n=e;return n.every(e=>typeof e==`number`)?t===3?r4([n[0],n[1],n[2]]):i4([n[0],n[1]]):l4(t,n.map(f4))}function m4(e){return p4(e,3)}function h4(e){return p4(e,2)}function g4(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 _4(e){return typeof e==`number`}function v4(e,t){return _4(e)?O(e):k(P(M.NULL_SHAPE_INPUT,`${t}: expected number, got ${Array.isArray(e)?`vector(${e.length})`:typeof e}`))}function y4(e,t,n){return Array.isArray(e)&&e.length===t?O(e):k(P(M.NULL_SHAPE_INPUT,`${n}: expected Vec${t}, got ${_4(e)?`number`:`vector(${e.length})`}`))}function b4(e,t){switch(e.kind){case`NumLit`:return O(e.value);case`Vec3Lit`:return O(e.value);case`Vec2Lit`:return O(e.value);case`Param`:{let n=t[e.name];return n===void 0?k(P(M.NULL_SHAPE_INPUT,`unbound param: ${e.name}`)):O(n)}case`BinOp`:return x4(e,t);case`UnaryOp`:return S4(e,t);case`Component`:return C4(e,t);case`BuildVec`:return w4(e,t)}}function x4(e,t){let n=b4(e.a,t);if(!n.ok)return n;let r=b4(e.b,t);if(!r.ok)return r;let i=v4(n.value,`BinOp(${e.op}).a`);if(!i.ok)return i;let a=v4(r.value,`BinOp(${e.op}).b`);if(!a.ok)return a;switch(e.op){case`+`:return O(i.value+a.value);case`-`:return O(i.value-a.value);case`*`:return O(i.value*a.value);case`/`:return a.value===0?k(P(M.NULL_SHAPE_INPUT,`BinOp(/): division by zero`)):O(i.value/a.value)}}function S4(e,t){let n=b4(e.arg,t);if(!n.ok)return n;let r=v4(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 C4(e,t){let n=b4(e.vec,t);if(!n.ok)return n;if(_4(n.value))return k(P(M.NULL_SHAPE_INPUT,`Component: cannot index a scalar`));let r=n.value,i=r[e.index];return i===void 0?k(P(M.NULL_SHAPE_INPUT,`Component: index ${e.index} out of range for Vec${r.length}`)):O(i)}function w4(e,t){if(e.components.length!==e.dim)return k(P(M.NULL_SHAPE_INPUT,`BuildVec(${e.dim}): expected ${e.dim} components, got ${e.components.length}`));let n=[];for(let r of e.components){let e=b4(r,t);if(!e.ok)return e;let i=v4(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 T4(e,t,n){let r=b4(e,t);return r.ok?v4(r.value,n):r}function E4(e,t,n){let r=b4(e,t);if(!r.ok)return r;let i=y4(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 O4=new Set;function k4(e){return G2(V2(),e)}function A4(e,t){return X2(e,t.structuralHash)}function j4(e,t){return t===void 0?Q2(e,!1):A4(Q2(e,!0),t)}function M4(e,t){return t===void 0?Q2(e,!1):Y2(Q2(e,!0),t)}function N4(...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?O4:t}function P4(e,t,n){let r=f4(e),i=f4(t),a=f4(n),o=k4(`Box`);return o=A4(A4(A4(o,r),i),a),{kind:`Box`,x:r,y:i,z:a,structuralHash:o,freeParams:N4(r,i,a)}}function F4(e){let t=f4(e);return{kind:`Sphere`,radius:t,structuralHash:A4(k4(`Sphere`),t),freeParams:t.freeParams}}function I4(e,t){let n=f4(e),r=f4(t);return{kind:`Cylinder`,radius:n,height:r,structuralHash:A4(A4(k4(`Cylinder`),n),r),freeParams:N4(n,r)}}function L4(e,t,n){let r=f4(e),i=f4(t),a=f4(n),o=k4(`Cone`);return o=A4(A4(A4(o,r),i),a),{kind:`Cone`,radius1:r,radius2:i,height:a,structuralHash:o,freeParams:N4(r,i,a)}}function R4(e,t){let n=f4(e),r=f4(t);return{kind:`Torus`,majorRadius:n,minorRadius:r,structuralHash:A4(A4(k4(`Torus`),n),r),freeParams:N4(n,r)}}function z4(e){let t=e.map(m4),n=Z2(k4(`Polygon`),t.length);for(let e of t)n=A4(n,e);return{kind:`Polygon`,points:t,structuralHash:n,freeParams:N4(...t)}}function B4(e){let t=f4(e);return{kind:`Circle`,radius:t,structuralHash:A4(k4(`Circle`),t),freeParams:t.freeParams}}function V4(e,t){let n=m4(e),r=m4(t);return{kind:`Line`,from:n,to:r,structuralHash:A4(A4(k4(`Line`),n),r),freeParams:N4(n,r)}}function H4(e){let t=m4(e);return{kind:`Vertex`,point:t,structuralHash:A4(k4(`Vertex`),t),freeParams:t.freeParams}}function U4(e){return{kind:`Empty`,output:e,structuralHash:G2(k4(`Empty`),e),freeParams:O4}}function W4(){return U4(`Solid`)}function G4(){return U4(`Face`)}function K4(){return U4(`Wire`)}function q4(e,t,n,r){return M4(A4(A4(k4(e),t),n),r)}function J4(e,t,n){return{kind:`Fuse`,a:e,b:t,tolerance:n,structuralHash:q4(`Fuse`,e,t,n),freeParams:N4(e,t)}}function Y4(e,t,n){return{kind:`Cut`,a:e,b:t,tolerance:n,structuralHash:q4(`Cut`,e,t,n),freeParams:N4(e,t)}}function X4(e,t,n){return{kind:`Intersect`,a:e,b:t,tolerance:n,structuralHash:q4(`Intersect`,e,t,n),freeParams:N4(e,t)}}function Z4(e,t){let n=Z2(k4(`FuseAll`),e.length);for(let t of e)n=A4(n,t);return n=M4(n,t),{kind:`FuseAll`,shapes:e,tolerance:t,structuralHash:n,freeParams:N4(...e)}}function Q4(e,t,n){let r=A4(k4(`CutAll`),e);r=Z2(r,t.length);for(let e of t)r=A4(r,e);return r=M4(r,n),{kind:`CutAll`,base:e,tools:t,tolerance:n,structuralHash:r,freeParams:N4(e,...t)}}function $4(e){return e===void 0?void 0:m4(e)}function e3(e,t){let n=m4(t);return{kind:`Translate`,target:e,vector:n,structuralHash:A4(A4(k4(`Translate`),e),n),freeParams:N4(e,n)}}function t3(e,t,n){let r=f4(t),i=$4(n?.axis),a=$4(n?.at),o=A4(A4(k4(`Rotate`),e),r);return o=j4(o,i),o=j4(o,a),{kind:`Rotate`,target:e,angle:r,axis:i,at:a,structuralHash:o,freeParams:N4(e,r,i,a)}}function n3(e,t,n){let r=f4(t),i=$4(n?.center),a=A4(A4(k4(`Scale`),e),r);return a=j4(a,i),{kind:`Scale`,target:e,factor:r,center:i,structuralHash:a,freeParams:N4(e,r,i)}}function r3(e,t){let n=$4(t?.normal),r=$4(t?.at),i=A4(k4(`Mirror`),e);return i=j4(i,n),i=j4(i,r),{kind:`Mirror`,target:e,normal:n,at:r,structuralHash:i,freeParams:N4(e,n,r)}}function i3(e){let t=Z2(k4(`Compound`),e.length);for(let n of e)t=A4(t,n);return{kind:`Compound`,children:e,structuralHash:t,freeParams:N4(...e)}}function a3(e,t,n=!1){let r=t.map(e=>e.map(e=>[...e])),i=Z2(Q2(A4(k4(`Instance`),e),n),r.length);for(let e of r)for(let t of e.flat())i=Y2(i,t);return{kind:`Instance`,source:e,placements:r,fuse:n,structuralHash:i,freeParams:N4(e)}}function o3(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 o3(e.a);case`FuseAll`:return e.shapes[0]?o3(e.shapes[0]):`Solid`;case`CutAll`:return o3(e.base);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return o3(e.target);case`Compound`:return`Compound`;case`Instance`:return e.fuse?`Solid`:`Compound`}}function s3(e,t){let n=T4(e.x,t.env,`Box.x`);if(!n.ok)return n;let r=T4(e.y,t.env,`Box.y`);if(!r.ok)return r;let i=T4(e.z,t.env,`Box.z`);return i.ok?O(hP(n.value,r.value,i.value)):i}function c3(e,t){let n=T4(e.radius,t.env,`Sphere.radius`);return n.ok?O(_P(n.value)):n}function l3(e,t){let n=T4(e.radius,t.env,`Cylinder.radius`);if(!n.ok)return n;let r=T4(e.height,t.env,`Cylinder.height`);return r.ok?O(gP(n.value,r.value)):r}function u3(e,t){let n=T4(e.radius1,t.env,`Cone.radius1`);if(!n.ok)return n;let r=T4(e.radius2,t.env,`Cone.radius2`);if(!r.ok)return r;let i=T4(e.height,t.env,`Cone.height`);return i.ok?O(vP(n.value,r.value,i.value)):i}function d3(e,t){let n=T4(e.majorRadius,t.env,`Torus.majorRadius`);if(!n.ok)return n;let r=T4(e.minorRadius,t.env,`Torus.minorRadius`);return r.ok?O(yP(n.value,r.value)):r}function f3(e,t){let n=[];for(let r of e.points){let e=E4(r,t.env,`Polygon.point`);if(!e.ok)return e;n.push(e.value)}return FP(n)}function p3(e,t){let n=T4(e.radius,t.env,`Circle.radius`);return n.ok?O(SP(n.value)):n}function m3(e,t){let n=E4(e.from,t.env,`Line.from`);if(!n.ok)return n;let r=E4(e.to,t.env,`Line.to`);return r.ok?O(xP(n.value,r.value)):r}function h3(e,t){let n=E4(e.point,t.env,`Vertex.point`);return n.ok?O(IP(n.value)):n}function g3(e){return k(Eo(M.NULL_SHAPE_INPUT,`${e}: empty result has no kernel representation`))}function _3(e,t,n){let r=e.evalNode(t);return r.ok?zE(r.value)?O(r.value):k(Co(M.CSG_NOT_3D,`${n}: operand did not produce a 3D shape`)):r}function v3(e,t){return{unsafe:!0,fuzzyValue:e.tolerance??t.tolerance}}function y3(e,t){if(e.a.kind===`Empty`)return t.evalNode(e.b);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=_3(t,e.a,`Fuse.a`);if(!n.ok)return n;let r=_3(t,e.b,`Fuse.b`);return r.ok?VA(n.value,r.value,v3(e,t)):r}function b3(e,t){if(e.a.kind===`Empty`)return g3(`Cut`);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=_3(t,e.a,`Cut.a`);if(!n.ok)return n;let r=_3(t,e.b,`Cut.b`);return r.ok?HA(n.value,r.value,v3(e,t)):r}function x3(e,t){if(e.a.kind===`Empty`||e.b.kind===`Empty`)return g3(`Intersect`);let n=_3(t,e.a,`Intersect.a`);if(!n.ok)return n;let r=_3(t,e.b,`Intersect.b`);return r.ok?UA(n.value,r.value,v3(e,t)):r}function S3(e,t,n){let r=[];for(let i of t){let t=_3(e,i,n);if(!t.ok)return t;r.push(t.value)}return O(r)}function C3(e,t){let n=e.shapes.filter(e=>e.kind!==`Empty`);if(n.length===0)return g3(`FuseAll`);if(n.length===1&&n[0])return t.evalNode(n[0]);let r=S3(t,n,`FuseAll.operand`);return r.ok?GA(r.value,v3(e,t)):r}function w3(e,t){if(e.base.kind===`Empty`)return g3(`CutAll`);let n=e.tools.filter(e=>e.kind!==`Empty`);if(n.length===0)return t.evalNode(e.base);let r=_3(t,e.base,`CutAll.base`);if(!r.ok)return r;let i=S3(t,n,`CutAll.tool`);return i.ok?KA(r.value,i.value,v3(e,t)):i}function T3(e){return k(Eo(M.NULL_SHAPE_INPUT,`${e}: cannot transform an Empty node`))}function E3(e,t,n,r){return e?E4(e,t,n):O(r)}function D3(e,t){let n=H(),{handle:r,dispose:i}=n.composeTransform(t),a;try{a=VE(n.locate(e.wrapped,r))}finally{i()}return sk(e)&&dk(e,a),a}function O3(e,t){if(e.target.kind===`Empty`)return T3(`Translate`);let n=E4(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 k3(e,t){if(e.target.kind===`Empty`)return T3(`Rotate`);let n=T4(e.angle,t.env,`Rotate.angle`);if(!n.ok)return n;let r=E3(e.axis,t.env,`Rotate.axis`,[0,0,1]);if(!r.ok)return r;let i=E3(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 A3(e,t){if(e.target.kind===`Empty`)return T3(`Scale`);let n=T4(e.factor,t.env,`Scale.factor`);if(!n.ok)return n;let r=E3(e.center,t.env,`Scale.center`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(hk(i.value,n.value,r.value)):i}function j3(e,t){if(e.target.kind===`Empty`)return T3(`Mirror`);let n=E3(e.normal,t.env,`Mirror.normal`,[1,0,0]);if(!n.ok)return n;let r=E3(e.at,t.env,`Mirror.at`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(mk(i.value,n.value,r.value)):i}function M3(e,t){let n=e.children.filter(e=>e.kind!==`Empty`);if(n.length===0)return k(Eo(M.NULL_SHAPE_INPUT,`Compound: cannot materialize a compound with zero non-empty children`));let r=[];for(let e of n){let n=t.evalNode(e);if(!n.ok)return n;r.push(n.value)}return O(LP(r))}function N3(){return k(Eo(M.NULL_SHAPE_INPUT,`Empty: cannot materialize an Empty node directly — only valid as boolean/transform operand`))}function P3(e,t){let n=t.evalNode(e.source);return n.ok?E$(C$(n.value,e.placements),{fuse:e.fuse}):n}function F3(e,t){switch(e.kind){case`Box`:return s3(e,t);case`Sphere`:return c3(e,t);case`Cylinder`:return l3(e,t);case`Cone`:return u3(e,t);case`Torus`:return d3(e,t);case`Polygon`:return f3(e,t);case`Circle`:return p3(e,t);case`Line`:return m3(e,t);case`Vertex`:return h3(e,t);case`Empty`:return N3();case`Fuse`:return y3(e,t);case`Cut`:return b3(e,t);case`Intersect`:return x3(e,t);case`FuseAll`:return C3(e,t);case`CutAll`:return w3(e,t);case`Translate`:return O3(e,t);case`Rotate`:return k3(e,t);case`Scale`:return A3(e,t);case`Mirror`:return j3(e,t);case`Compound`:return M3(e,t);case`Instance`:return P3(e,t)}}function I3(e,t){if(typeof t==`number`)return Y2(Q2(e,!1),t);let n=Q2(e,!0);n=Z2(n,t.length);for(let e of t)n=Y2(n,e);return n}function L3(e,t){if(t.size===0)return V2();let n=D4(e,t),r=Object.keys(n).sort(),i=V2();for(let e of r){i=G2(i,e);let t=n[e];t!==void 0&&(i=I3(i,t))}return i}function R3(e,t,n,r){let i=L3(t,e.freeParams),a=r===void 0?`d`:Y2(V2(),r).toString(16);return`${$2(e.structuralHash)}:${n}:${$2(i)}:${a}`}var z3=[1,0,0,0];function B3(e,t){let n=T4(e.angle,t,`evaluateMesh.peelRigid`);if(!n.ok)return null;let r=e.axis?E4(e.axis,t,`evaluateMesh.peelRigid`):O([0,0,1]);if(!r.ok)return null;let i=e.at?E4(e.at,t,`evaluateMesh.peelRigid`):O([0,0,0]);return i.ok?{angle:n.value,axis:r.value,center:i.value}:null}function V3(e,t){let n=e,r=z3,i=[0,0,0];for(;;)if(n.kind===`Translate`){let e=E4(n.vector,t,`evaluateMesh.peelRigid`);if(!e.ok)break;let a=oF(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=B3(n,t);if(!e)break;let a=sF(e.axis,e.angle*Math.PI/180),o=lF(r,a),s=oF(r,e.center),c=oF(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 H3(e){return e[0]===1&&e[1]===0&&e[2]===0&&e[3]===0}function U3(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 W3(e,t,n){let[r,i,a]=n,o=H3(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;U3(c,s,l,u,d,f,r,i,a);let p=e.normals,m=new Float32Array(p.length);return U3(m,p,l,u,d,f,0,0,0),{...e,vertices:c,normals:m}}function G3(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 K3=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??TT()??`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 ET(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=Po(),a=n.tolerance??i.tolerance,o=n.angularTolerance??i.angularTolerance,s=`${R3(e,t,this.kernelId,this.defaultTolerance)}|${Kk(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}=V3(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=dD(c.value).map(Ek),u=this.evaluate(e,t);if(!u.ok)return u;let d=dD(u.value).map(Ek),f=W3(r.value,a,o),p=G3(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=ET(this.kernelId,()=>nA(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=R3(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=F3(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 q3(e,t){try{var n=IT();let r=t(n.u(new K3(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 J3(e){return{csgVersion:1,root:e6(e)}}function Y3(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:Y3(e.a),b:Y3(e.b)};case`UnaryOp`:return{kind:`UnaryOp`,op:e.op,arg:Y3(e.arg)};case`Component`:return{kind:`Component`,vec:Y3(e.vec),index:e.index};case`BuildVec`:return{kind:`BuildVec`,dim:e.dim,components:e.components.map(Y3)}}}function X3(e){switch(e.kind){case`Box`:return{kind:`Box`,x:Y3(e.x),y:Y3(e.y),z:Y3(e.z)};case`Sphere`:return{kind:`Sphere`,radius:Y3(e.radius)};case`Cylinder`:return{kind:`Cylinder`,radius:Y3(e.radius),height:Y3(e.height)};case`Cone`:return{kind:`Cone`,radius1:Y3(e.radius1),radius2:Y3(e.radius2),height:Y3(e.height)};case`Torus`:return{kind:`Torus`,majorRadius:Y3(e.majorRadius),minorRadius:Y3(e.minorRadius)};case`Polygon`:return{kind:`Polygon`,points:e.points.map(Y3)};case`Circle`:return{kind:`Circle`,radius:Y3(e.radius)};case`Line`:return{kind:`Line`,from:Y3(e.from),to:Y3(e.to)};case`Vertex`:return{kind:`Vertex`,point:Y3(e.point)};case`Empty`:return{kind:`Empty`,output:e.output};default:return}}function Z3(e){switch(e.kind){case`Fuse`:case`Cut`:case`Intersect`:return{kind:e.kind,a:e6(e.a),b:e6(e.b),tolerance:e.tolerance};case`FuseAll`:return{kind:`FuseAll`,shapes:e.shapes.map(e6),tolerance:e.tolerance};case`CutAll`:return{kind:`CutAll`,base:e6(e.base),tools:e.tools.map(e6),tolerance:e.tolerance};default:return}}function Q3(e){return e?Y3(e):void 0}function $3(e){switch(e.kind){case`Translate`:return{kind:`Translate`,target:e6(e.target),vector:Y3(e.vector)};case`Rotate`:return{kind:`Rotate`,target:e6(e.target),angle:Y3(e.angle),axis:Q3(e.axis),at:Q3(e.at)};case`Scale`:return{kind:`Scale`,target:e6(e.target),factor:Y3(e.factor),center:Q3(e.center)};case`Mirror`:return{kind:`Mirror`,target:e6(e.target),normal:Q3(e.normal),at:Q3(e.at)};default:return}}function e6(e){return e.kind===`Compound`?{kind:`Compound`,children:e.children.map(e6)}:e.kind===`Instance`?{kind:`Instance`,source:e6(e.source),placements:e.placements,fuse:e.fuse}:X3(e)??Z3(e)??$3(e)}function t6(e){return k(P(M.NULL_SHAPE_INPUT,`csg.fromJSON: ${e}`))}function n6(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function r6(e){return typeof e==`number`&&Number.isFinite(e)}function i6(e){return typeof e==`string`}function a6(e,t){if(!Array.isArray(e)||e.length!==3)return t6(`${t}: expected Vec3 array`);let[n,r,i]=e;return!r6(n)||!r6(r)||!r6(i)?t6(`${t}: Vec3 contains non-number`):O([n,r,i])}function o6(e,t){if(!Array.isArray(e)||e.length!==2)return t6(`${t}: expected Vec2 array`);let[n,r]=e;return!r6(n)||!r6(r)?t6(`${t}: Vec2 contains non-number`):O([n,r])}function s6(e){if(!n6(e))return t6(`input is not an object`);let t=e.csgVersion;if(t!==1)return t6(`unsupported csgVersion ${String(t)} (expected 1)`);let n=e.root;return h6(n)}function c6(e){if(!n6(e))return t6(`expression: not an object`);let t=e.kind;switch(t){case`NumLit`:return r6(e.value)?O(n4(e.value)):t6(`NumLit.value`);case`Vec3Lit`:{let t=a6(e.value,`Vec3Lit.value`);return t.ok?O(r4(t.value)):t}case`Vec2Lit`:{let t=o6(e.value,`Vec2Lit.value`);return t.ok?O(i4(t.value)):t}case`Param`:return i6(e.name)?O(a4(e.name)):t6(`Param.name`);case`BinOp`:return l6(e);case`UnaryOp`:return u6(e);case`Component`:return d6(e);case`BuildVec`:return f6(e);default:return t6(`unknown expression kind: ${String(t)}`)}}function l6(e){let t=e.op;if(t!==`+`&&t!==`-`&&t!==`*`&&t!==`/`)return t6(`BinOp.op: ${String(t)}`);let n=c6(e.a);if(!n.ok)return n;let r=c6(e.b);return r.ok?O(o4(t,n.value,r.value)):r}function u6(e){let t=e.op;if(!i6(t)||![`neg`,`sin`,`cos`,`sqrt`,`abs`].includes(t))return t6(`UnaryOp.op: ${String(t)}`);let n=c6(e.arg);return n.ok?O(s4(t,n.value)):n}function d6(e){let t=e.index;if(t!==0&&t!==1&&t!==2)return t6(`Component.index: ${String(t)}`);let n=c6(e.vec);return n.ok?O(c4(n.value,t)):n}function f6(e){let t=e.dim;if(t!==2&&t!==3)return t6(`BuildVec.dim: ${String(t)}`);let n=e.components;if(!Array.isArray(n))return t6(`BuildVec.components: not array`);if(n.length!==t)return t6(`BuildVec.components: expected ${t} components, got ${n.length}`);let r=[];for(let e of n){let t=c6(e);if(!t.ok)return t;r.push(t.value)}return O(l4(t,r))}function p6(e,t){if(!Array.isArray(e))return t6(`${t}: not array`);let n=[];for(let t of e){let e=h6(t);if(!e.ok)return e;n.push(e.value)}return O(n)}function m6(e){let t=e.tolerance;return t==null?O(void 0):r6(t)?O(t):t6(`tolerance: not a finite number`)}function h6(e){if(!n6(e))return t6(`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 _6(t,e);case`Fuse`:case`Cut`:case`Intersect`:return T6(t,e);case`FuseAll`:case`CutAll`:return E6(t,e);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return D6(t,e);case`Compound`:return N6(e);case`Instance`:return F6(e);default:return t6(`unknown node kind: ${String(t)}`)}}function g6(e,t,n){let r=c6(e[t]);return r.ok?O(n(r.value)):r}function _6(e,t){switch(e){case`Box`:return v6(t);case`Sphere`:return g6(t,`radius`,F4);case`Cylinder`:return y6(t);case`Cone`:return b6(t);case`Torus`:return x6(t);case`Polygon`:return S6(t);case`Circle`:return g6(t,`radius`,B4);case`Line`:return C6(t);case`Vertex`:return g6(t,`point`,H4);case`Empty`:return w6(t)}return t6(`unhandled primitive: ${e}`)}function v6(e){let t=c6(e.x);if(!t.ok)return t;let n=c6(e.y);if(!n.ok)return n;let r=c6(e.z);return r.ok?O(P4(t.value,n.value,r.value)):r}function y6(e){let t=c6(e.radius);if(!t.ok)return t;let n=c6(e.height);return n.ok?O(I4(t.value,n.value)):n}function b6(e){let t=c6(e.radius1);if(!t.ok)return t;let n=c6(e.radius2);if(!n.ok)return n;let r=c6(e.height);return r.ok?O(L4(t.value,n.value,r.value)):r}function x6(e){let t=c6(e.majorRadius);if(!t.ok)return t;let n=c6(e.minorRadius);return n.ok?O(R4(t.value,n.value)):n}function S6(e){let t=e.points;if(!Array.isArray(t))return t6(`Polygon.points: not array`);let n=[];for(let e of t){let t=c6(e);if(!t.ok)return t;n.push(t.value)}return O(z4(n))}function C6(e){let t=c6(e.from);if(!t.ok)return t;let n=c6(e.to);return n.ok?O(V4(t.value,n.value)):n}function w6(e){let t=e.output;switch(t){case`Solid`:return O(W4());case`Face`:return O(G4());case`Wire`:return O(K4());default:return t6(`Empty.output: ${String(t)}`)}}function T6(e,t){let n=h6(t.a);if(!n.ok)return n;let r=h6(t.b);if(!r.ok)return r;let i=m6(t);if(!i.ok)return i;switch(e){case`Fuse`:return O(J4(n.value,r.value,i.value));case`Cut`:return O(Y4(n.value,r.value,i.value));case`Intersect`:return O(X4(n.value,r.value,i.value))}}function E6(e,t){let n=m6(t);if(!n.ok)return n;if(e===`FuseAll`){let e=p6(t.shapes,`FuseAll.shapes`);return e.ok?O(Z4(e.value,n.value)):e}let r=h6(t.base);if(!r.ok)return r;let i=p6(t.tools,`CutAll.tools`);return i.ok?O(Q4(r.value,i.value,n.value)):i}function D6(e,t){let n=h6(t.target);if(!n.ok)return n;switch(e){case`Translate`:return O6(t,n.value);case`Rotate`:return A6(t,n.value);case`Scale`:return j6(t,n.value);case`Mirror`:return M6(t,n.value)}}function O6(e,t){let n=c6(e.vector);return n.ok?O(e3(t,n.value)):n}function k6(e,t){if(e[t]===void 0)return O(void 0);let n=c6(e[t]);return n.ok?O(n.value):n}function A6(e,t){let n=c6(e.angle);if(!n.ok)return n;let r=k6(e,`axis`);if(!r.ok)return r;let i=k6(e,`at`);return i.ok?O(t3(t,n.value,{axis:r.value,at:i.value})):i}function j6(e,t){let n=c6(e.factor);if(!n.ok)return n;let r=k6(e,`center`);return r.ok?O(n3(t,n.value,{center:r.value})):r}function M6(e,t){let n=k6(e,`normal`);if(!n.ok)return n;let r=k6(e,`at`);return r.ok?O(r3(t,{normal:n.value,at:r.value})):r}function N6(e){let t=p6(e.children,`Compound.children`);return t.ok?O(i3(t.value)):t}function P6(e){return Array.isArray(e)&&e.length===4&&e.every(e=>Array.isArray(e)&&e.length===4&&e.every(r6))}function F6(e){let t=h6(e.source);if(!t.ok)return t;let n=e.placements;return!Array.isArray(n)||!n.every(P6)?t6(`Instance.placements must be an array of 4x4 number matrices`):O(a3(t.value,n,e.fuse===!0))}function I6(e){return z6(e)}function L6(e){switch(e.kind){case`NumLit`:case`Vec3Lit`:case`Vec2Lit`:case`Param`:return e;case`BinOp`:{let t=L6(e.a),n=L6(e.b);if(t.kind===`NumLit`&&n.kind===`NumLit`)switch(e.op){case`+`:return n4(t.value+n.value);case`-`:return n4(t.value-n.value);case`*`:return n4(t.value*n.value);case`/`:return n4(t.value/n.value)}return t!==e.a||n!==e.b?o4(e.op,t,n):e}case`UnaryOp`:{let t=L6(e.arg);if(t.kind===`NumLit`){let n=t.value;switch(e.op){case`neg`:return n4(-n);case`sin`:return n4(Math.sin(n));case`cos`:return n4(Math.cos(n));case`sqrt`:return n4(Math.sqrt(n));case`abs`:return n4(Math.abs(n))}}return t===e.arg?e:s4(e.op,t)}case`Component`:{let t=L6(e.vec);return t.kind===`Vec3Lit`||t.kind===`Vec2Lit`&&(e.index===0||e.index===1)?n4(t.value[e.index]):t===e.vec?e:c4(t,e.index)}case`BuildVec`:{let t=e.components.map(L6);return R6(e.dim,t)||(t.some((t,n)=>t!==e.components[n])?l4(e.dim,t):e)}}}function R6(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?i4([n[0],n[1]]):r4([n[0],n[1],n[2]])}function z6(e){switch(e.kind){case`Box`:return P4(L6(e.x),L6(e.y),L6(e.z));case`Sphere`:return F4(L6(e.radius));case`Cylinder`:return I4(L6(e.radius),L6(e.height));case`Cone`:return L4(L6(e.radius1),L6(e.radius2),L6(e.height));case`Torus`:return R4(L6(e.majorRadius),L6(e.minorRadius));case`Polygon`:return z4(e.points.map(L6));case`Circle`:return B4(L6(e.radius));case`Line`:return V4(L6(e.from),L6(e.to));case`Vertex`:return H4(L6(e.point));case`Empty`:return e;case`Fuse`:return B6(e.a,e.b,e.tolerance);case`Cut`:return V6(e.a,e.b,e.tolerance);case`Intersect`:return H6(e.a,e.b,e.tolerance);case`FuseAll`:return U6(e.shapes,e.tolerance);case`CutAll`:return W6(e.base,e.tools,e.tolerance);case`Translate`:return G6(e.target,e.vector);case`Rotate`:return t3(z6(e.target),L6(e.angle),{axis:e.axis?L6(e.axis):void 0,at:e.at?L6(e.at):void 0});case`Scale`:return n3(z6(e.target),L6(e.factor),{center:e.center?L6(e.center):void 0});case`Mirror`:return r3(z6(e.target),{normal:e.normal?L6(e.normal):void 0,at:e.at?L6(e.at):void 0});case`Compound`:return i3(e.children.map(z6).filter(e=>e.kind!==`Empty`));case`Instance`:return a3(z6(e.source),e.placements,e.fuse)}}function B6(e,t,n){let r=z6(e),i=z6(t);return r.kind===`Empty`?i:i.kind===`Empty`?r:J4(r,i,n)}function V6(e,t,n){let r=z6(e),i=z6(t);return i.kind===`Empty`||r.kind===`Empty`?r:Y4(r,i,n)}function H6(e,t,n){let r=z6(e),i=z6(t);return r.kind===`Empty`?r:i.kind===`Empty`?i:X4(r,i,n)}function U6(e,t){let n=e.map(z6).filter(e=>e.kind!==`Empty`);return n.length===0?W4():n.length===1?n[0]:Z4(n,t)}function W6(e,t,n){let r=z6(e);if(r.kind===`Empty`)return r;let i=t.map(z6).filter(e=>e.kind!==`Empty`);return i.length===0?r:Q4(r,i,n)}function G6(e,t){let n=z6(e),r=L6(t);if(r.kind!==`Vec3Lit`)return e3(n,r);let[i,a,o]=r.value;if(i===0&&a===0&&o===0)return n;if(n.kind===`Translate`){let e=L6(n.vector);if(e.kind===`Vec3Lit`)return e3(n.target,[e.value[0]+i,e.value[1]+a,e.value[2]+o])}return e3(n,r)}function K6(e,t,n){return q6(e,t,n)}function q6(e,t,n){return t(e)?n:J6(e,t,n)}function J6(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 J4(q6(e.a,t,n),q6(e.b,t,n),e.tolerance);case`Cut`:return Y4(q6(e.a,t,n),q6(e.b,t,n),e.tolerance);case`Intersect`:return X4(q6(e.a,t,n),q6(e.b,t,n),e.tolerance);case`FuseAll`:return Z4(e.shapes.map(e=>q6(e,t,n)),e.tolerance);case`CutAll`:return Q4(q6(e.base,t,n),e.tools.map(e=>q6(e,t,n)),e.tolerance);case`Translate`:return e3(q6(e.target,t,n),e.vector);case`Rotate`:return t3(q6(e.target,t,n),e.angle,{axis:e.axis,at:e.at});case`Scale`:return n3(q6(e.target,t,n),e.factor,{center:e.center});case`Mirror`:return r3(q6(e.target,t,n),{normal:e.normal,at:e.at});case`Compound`:return i3(e.children.map(e=>q6(e,t,n)));case`Instance`:return a3(q6(e.source,t,n),e.placements,e.fuse)}}function Y6(e,t){t(e);for(let n of X6(e))Y6(n,t)}function X6(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 Z6(e){let t=0;return Y6(e,()=>{t++}),t}var Q6=IX({CSG_VERSION:()=>1,Evaluator:()=>K3,add:()=>u4,asScalarExpr:()=>f4,asVec2Expr:()=>h4,asVec3Expr:()=>m4,binOp:()=>o4,box:()=>P4,buildVec:()=>l4,circle:()=>B4,component:()=>c4,compound:()=>i3,cone:()=>L4,cut:()=>Y4,cutAll:()=>Q4,cylinder:()=>I4,emptyFace:()=>G4,emptySolid:()=>W4,emptyWire:()=>K4,foldExpr:()=>L6,forEachNode:()=>Y6,fromJSON:()=>s6,fuse:()=>J4,fuseAll:()=>Z4,instance:()=>a3,intersect:()=>X4,line:()=>V4,mirror:()=>r3,mul:()=>d4,nodeCount:()=>Z6,numLit:()=>n4,optimize:()=>I6,outputKindOf:()=>o3,param:()=>a4,polygon:()=>z4,replaceNode:()=>K6,rotate:()=>t3,scale:()=>n3,sphere:()=>F4,toJSON:()=>J3,torus:()=>R4,translate:()=>e3,unaryOp:()=>s4,vec2Lit:()=>i4,vec3Lit:()=>r4,vertex:()=>H4,withEvaluator:()=>q3});export{_R as BaseSketcher2d,vR as BlueprintSketcher,r as BrepBugError,M as BrepErrorCode,x0 as BrepWrapperError,Ry as BrepkitAdapter,qK as CompoundSketch,o as DEFAULT_CAPABILITIES,JE as DEG2RAD,XT as DisposalScope,a as EXACT_BREP_CAPABILITIES,Eq as FaceSketcher,G as HASH_CODE_MAX,qa as OK,Ka as OcctWasmAdapter,YE as RAD2DEG,lq as Sketch,Tq as Sketcher,uq as Sketches,YP as addChild,VP as addHoles,EF as addJoint,r1 as addMate,sI as addStep,sN as adjacentFaces,no as all,Za as andThen,zX as applyGlue,F1 as applyMatrix,Wk as approximateCurve,oE as as2D,aE as as3D,oO as asTopo,SN as assignRoles,fM as autoHeal,OP as bezier,wY as blueprintToDXF,rj as booleanPipeline,A2 as booleans,v0 as boss,hP as box,DP as bsplineApprox,i as bug,Sq as cameraFromPlane,xq as cameraLookAt,mN as captureHint,fO as cast,VE as castShape,HE as castShape3D,Z1 as chamfer,xj as chamferDistAngleShape,Wj as chamferWithEvolution,o1 as checkAllInterferences,Fj as checkBoolean,a1 as checkInterference,SP as circle,KP as circularPattern,DO as classifyPointOnFace,eA as clearMeshCache,P1 as clone,hE as closedWire,mo as collect,tF as collectShapes,rk as colorFaces,nk as colorShape,SM as complexExtrude,xk as composeTransforms,LP as compound,oq as compoundSketchExtrude,iq as compoundSketchFace,cq as compoundSketchLoft,sq as compoundSketchRevolve,Eo as computationError,u$ as computeStraightSkeleton,vP as cone,I2 as construction,WQ as convexHull,CR as cornerFinder,eF as countNodes,UP as createAssembly,JP as createAssemblyNode,RJ as createBlueprint,bq as createCamera,jE as createCompound,zJ as createCompoundBlueprint,tP as createDerivedFaceRef,KM as createDistanceQuery,TE as createEdge,RN as createEdgeRef,DE as createFace,KT as createHandle,oI as createHistory,YT as createKernelHandle,tA as createMeshCache,$D as createNamedPlane,OX as createOperationRegistry,ZD as createPlane,CN as createRef,mI as createRegistry,OE as createShell,kE as createSolid,bX as createTaskQueue,wE as createVertex,KN as createVertexRef,EE as createWire,DX as createWorkerClient,NX as createWorkerHandler,PX as createWorkerPool,Q6 as csg,No as currentQuality,AJ as curve2dBoundingBox,LJ as curve2dDistanceFrom,jJ as curve2dFirstPoint,IJ as curve2dIsOnCurve,MJ as curve2dLastPoint,PJ as curve2dParameter,NJ as curve2dSplitAt,FJ as curve2dTangentAt,Lk as curveAxis,Nk as curveEndPoint,Rk as curveIsClosed,zk as curveIsPeriodic,Ik as curveLength,Bk as curvePeriod,Pk as curvePointAt,Mk as curveStartPoint,Fk as curveTangentAt,z1 as cut,lz as cut2D,V1 as cutAll,Ej as cutAllBisect,QR as cutBlueprints,Vj as cutWithEvolution,gP as cylinder,yF as cylindricalJoint,pN as defaultScorer,SX as dequeueTask,o0 as describe,rJ as deserializeDrawing,xI as deserializeHistory,mO as deserializeShape,uO as downcast,t0 as draft,aJ as draw,uJ as drawCircle,dJ as drawEllipse,vJ as drawFaceOutline,hJ as drawParametricFunction,mJ as drawPointsInterpolation,fJ as drawPolysides,_J as drawProjection,sJ as drawRectangle,oJ as drawRoundedRectangle,cJ as drawSingleCircle,lJ as drawSingleEllipse,pJ as drawText,wJ as drawingChamfer,xJ as drawingCut,CJ as drawingFillet,bJ as drawingFuse,SJ as drawingIntersect,yJ as drawingToSketchOnPlane,g0 as drill,qI as edgeFinder,rN as edgesOfFace,CP as ellipse,EP as ellipseArc,bP as ellipsoid,xX as enqueueTask,k as err,WP as exportAssemblySTEP,CY as exportDXF,uY as exportGlb,lY as exportGltf,lA as exportIGES,$J as exportOBJ,sA as exportSTEP,sX as exportSTEPConfigured,cA as exportSTL,UY as exportThreeMF,tI as exportURDF,d0 as extrude,AM as extrudeAll,MP as face,EO as faceAxis,TO as faceCenter,XI as faceFinder,_O as faceGeomType,vO as faceOrientation,tN as facesOfEdge,nN as facesOfVertex,MZ as fieldBoolean,IZ as fieldContour,NZ as fieldOffset,FZ as fieldReinit,PZ as fieldShell,PA as fill,NP as filledFace,X1 as fillet,Uj as filletWithEvolution,GO as findFacesByTag,QP as findNode,lI as findStep,hM as fixSelfIntersection,pM as fixShape,Qa as flatMap,ao as flatten,yO as flipFaceOrientation,Hk as flipOrientation,pX as fontMetrics,AF as forwardKinematics,c0 as fromBREP,jQ as fromKernelDir,AQ as fromKernelPnt,kQ as fromKernelVec,so as fromNullable,R1 as fuse,sz as fuse2D,B1 as fuseAll,Aj as fuseAllBisect,ZR as fuseBlueprints,Bj as fuseWithEvolution,G0 as gearGeometry,ZX as getActiveVoxelId,wD as getBounds,BJ as getBounds2D,gD as getCompSolids,jk as getCurveType,BT as getDisposalStats,uD as getEdges,ak as getFaceColor,MO as getFaceOrigins,KO as getFaceTags,dD as getFaces,pq as getFont,Ek as getHashCode,uI as getHistoryShape,H as getKernel,DT as getKernelCapabilities,jT as getKernelTier,Sj as getNurbsCurveData,Cj as getNurbsSurfaceData,Vk as getOrientation,VJ as getOrientation2D,Ho as getPerformanceStats,ik as getShapeColor,uE as getShapeKind,hD as getShells,$I as getSingleFace,mD as getSolids,gO as getSurfaceType,JO as getTagMetadata,pD as getVertices,XX as getVoxel,fD as getWires,qP as gridPattern,DM as guidedSweep,n0 as heal,lM as healFace,cM as healSolid,uM as healWire,wP as helix,UQ as hull,d1 as importDXF,O1 as importGLB,uX as importIGES,h1 as importOBJ,cX as importSTEP,lX as importSTL,oX as importSVG,aX as importSVGPathD,D1 as importThreeMF,aI as importURDF,FT as init,ST as initFromManifold,NT as initFromOC,QX as initVoxel,AO as innerWires,C$ as instance,T$ as instanceCount,w$ as instanceGrid,O$ as instancedMesh,Uk as interpolateCurve,H1 as intersect,uz as intersect2D,$R as intersectBlueprints,Hj as intersectWithEvolution,lD as invalidateShapeCache,WF as inverseKinematics,P2 as io,Do as ioError,iE as is2D,rE as is3D,_X as isBatchRequest,VX as isChamferRadius,dE as isClosedWire,pO as isCompSolid,RE as isCompound,iP as isDerivedFaceRef,gX as isDisposeRequest,NE as isEdge,aP as isEdgeRef,u0 as isEmpty,kk as isEqualShape,A as isErr,yX as isErrorResponse,FE as isFace,sP as isFaceRef,HX as isFilletRadius,mX as isInitRequest,HJ as isInside2D,S$ as isInstanced,cP as isLineageRef,nE as isLive,pE as isManifoldShell,BX as isNumber,Ja as isOk,hX as isOperationRequest,fE as isOrientedFace,yE as isPlanarFace,bE as isPlanarWire,_q as isProjectionPlane,wX as isQueueEmpty,Ok as isSameShape,BE as isShape1D,zE as isShape3D,IE as isShell,LE as isSolid,vX as isSuccessResponse,l0 as isValid,mE as isValidSolid,ME as isVertex,oP as isVertexRef,PE as isWire,CD as iterCompSolids,_D as iterEdges,vD as iterFaces,SD as iterShells,xD as iterSolids,cO as iterTopo,bD as iterVertices,yD as iterWires,KF as jointTrajectory,TF as jointTransform,YF as jointsFromDH,QE as kernelCall,$E as kernelCallRaw,eD as kernelCallScoped,N as kernelError,CQ as latticeInfill,wQ as latticeInfillShape,xP as line,GP as linearPattern,fq as loadFont,L1 as locate,p0 as loft,MM as loftAll,Iq as makeBaseBox,m2 as makeExternalGear,h2 as makeInternalGear,tO as makePlane,_2 as makePlanetaryGear,yq as makeProjectedEdges,_E as manifoldShell,Ya as map,oo as mapBoth,Xa as mapErr,po as match,E$ as materialize,HM as measureArea,qM as measureCurvatureAt,JM as measureCurvatureAtMid,WM as measureDistance,GM as measureDistanceProps,UM as measureLength,BM as measureLinearProps,zM as measureSurfaceProps,VM as measureVolume,RM as measureVolumeProps,N2 as measurement,jF as mechanismDOF,i0 as mesh,a0 as meshEdges,mA as meshLODs,gA as meshLODsProgressive,uA as meshMultiLOD,JQ as minkowski,M1 as mirror,qJ as mirror2D,OJ as mirrorDrawing,y0 as mirrorJoin,j2 as modifiers,yI as modifyStep,To as moduleInitError,EM as multiSectionSweep,wO as normalAt,$1 as offset,zP as offsetFace,mZ as offsetMesh,_Z as offsetShape,Gk as offsetWire2D,O as ok,$a as or,eo as orElse,sR as organiseBlueprints,gE as orientedFace,OO as outerWire,L2 as patterns,CX as pendingCount,_o as pipeline,iO as pivotPlane,xE as planarFace,bF as planarJoint,SE as planarWire,l2 as planetPlacements,_0 as pocket,xO as pointOnSurface,rZ as pointsInside,FP as polygon,YQ as polyhedron,Mq as polysideInnerRadius,wR as polysidesBlueprint,Kj as positionOnCurve,PT as prewarm,k2 as primitives,vF as prismaticJoint,Cq as projectEdges,CO as projectPointOnFace,F2 as query,Oo as queryError,b0 as rectangularPattern,kX as registerHandler,CT as registerKernel,AT as registerKernelTier,hI as registerOperation,pI as registerShape,YX as registerVoxel,TX as rejectAll,XP as removeChild,kO as removeHolesFromFace,oZ as repairMesh,vI as replayFrom,_I as replayHistory,VT as resetDisposalStats,Uo as resetPerformanceStats,gk as resize,$ as resolve,k1 as resolve3D,nP as resolveDerivedFaceRef,ND as resolveDirection,zN as resolveEdgeRef,uP as resolveLineageRef,eO as resolvePlane,kN as resolveRef,fP as resolveRefIn,mP as resolveRefParams,qN as resolveVertexRef,kJ as reverseCurve,_F as revoluteJoint,f0 as revolve,v$ as roof,j1 as rotate,GJ as rotate2D,EJ as rotateDrawing,TR as roundedRectangleBlueprint,N1 as scale,KJ as scale2D,DJ as scaleDrawing,QZ as sdfBox,nQ as sdfCapsule,tQ as sdfCone,eQ as sdfCylinder,mQ as sdfFieldAxialRamp,_Q as sdfFieldClamp,pQ as sdfFieldConst,gQ as sdfFieldFromSdf,hQ as sdfFieldRadialRamp,cQ as sdfLattice,iQ as sdfPlane,$Z as sdfRoundedBox,ZZ as sdfSphere,lQ as sdfStrutLattice,oQ as sdfSweep,rQ as sdfTorus,U1 as section,W1 as sectionToFace,bI as serializeHistory,CF as setJointValue,SF as setJointValues,jO as setShapeOrigin,qO as setTagMetadata,BP as sewShells,z0 as shape,cZ as shapeToMeshInput,lO as shapeType,lN as sharedEdges,Q1 as shell,hZ as shellMesh,vZ as shellShape,Gj as shellWithEvolution,r0 as simplify,Dq as sketchCircle,Oq as sketchEllipse,eq as sketchExtrude,ZK as sketchFace,Nq as sketchFaceOffset,Fq as sketchHelix,nq as sketchLoft,XJ as sketchOnFace2D,YJ as sketchOnPlane2D,Pq as sketchParametricFunction,jq as sketchPolysides,kq as sketchRectangle,$K as sketchRevolve,Aq as sketchRoundedRectangle,tq as sketchSweep,dX as sketchText,QK as sketchWires,wo as sketcherStateError,K1 as slice,RP as solid,mM as solidFromShell,i1 as solveAssembly,_P as sphere,xF as sphericalJoint,G1 as split,dI as stepCount,fI as stepsFrom,JJ as stretch2D,PP as subFace,xM as supportExtrude,vT as supportsConstraintSketch,_T as supportsProjection,RQ as surfaceFromGrid,VQ as surfaceFromImage,bM as sweep,WO as tagFaces,kP as tangentArc,ro as tap,io as tapErr,hq as textBlueprints,fX as textMetrics,e0 as thicken,SI as thread,TP as threePointArc,s0 as toBREP,gj as toBufferGeometryData,_j as toGroupedBufferGeometryData,EQ as toKernelVec,yj as toLODGeometryData,bj as toLODGeometryLevels,vj as toLineGeometryData,UJ as toSVGPathD,jD as toVec2,AD as toVec3,yP as torus,TQ as tpmsLattice,I1 as transformCopy,M2 as transforms,A1 as translate,WJ as translate2D,TJ as translateDrawing,rO as translatePlane,ho as tryCatch,go as tryCatchAsync,CM as twistExtrude,Co as typeCastError,cI as undoLast,ko as unsupportedError,j as unwrap,fo as unwrapErr,lo as unwrapOr,uo as unwrapOrElse,ZP as updateNode,TN as updateRoles,bO as uvBounds,SO as uvCoordinates,vE as validSolid,X0 as validatePlanetary,P as validationError,oM as variableFillet,PD as vecAdd,KD as vecAngle,zD as vecCross,HD as vecDistance,RD as vecDot,WD as vecEquals,GD as vecIsZero,BD as vecLength,VD as vecLengthSq,LD as vecNegate,UD as vecNormalize,qD as vecProjectToPlane,XD as vecRepr,JD as vecRotate,ID as vecScale,FD as vecSub,IP as vertex,GX as vertexFinder,kD as vertexPosition,oN as verticesOfEdge,iN as verticesOfFace,gZ as voxelBoolean,jZ as voxelBooleanField,RZ as voxelBooleanFieldShapes,yZ as voxelBooleanShapes,AZ as voxelField,LZ as voxelFieldFromShape,$P as walkAssembly,nZ as windingNumbers,AP as wire,QI as wireFinder,jP as wireLoop,aN as wiresOfFace,ET as withKernel,PQ as withKernelDir,NQ as withKernelPnt,MQ as withKernelVec,OT as withQuality,ZT as withScope,eE as withScopeResult,tE as withScopeResultAsync,MT as withTier,to as zipResults};
|
|
59
|
+
</Relationships>`),c(`3D/3dmodel.model`,s)])}function GY(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 qY(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(mL(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(mL(KY([t.cx,t.cy]),KY([a,o]))),t.cx=a,t.cy=o,i+=2}}function YY(e,t,n,r){for(let i of e){let e=n?t.cx+i:i;r.push(mL(KY([t.cx,t.cy]),KY([e,t.cy]))),t.cx=e}}function XY(e,t,n,r){for(let i of e){let e=n?t.cy+i:i;r.push(mL(KY([t.cx,t.cy]),KY([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(bL(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 QY(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(bL(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 $Y(e,t,n,r){let i=0;for(;i+3<e.length;){let a=n?t.cx:0,o=n?t.cy:0,s=a+(e[i]??0),c=o+(e[i+1]??0),l=a+(e[i+2]??0),u=o+(e[i+3]??0);r.push(bL(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 eX(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(bL(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 tX(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[hL(KY([e,t]),KY(c),KY([e,s])),hL(KY([e,s]),KY(l),KY([e,t]))]}catch{return[]}}function nX(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[hL(KY([e,t]),KY([b,x]),KY([n,r]))]}catch{return[mL(KY([e,t]),KY([n,r]))]}}function rX(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(mL(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(...tX(t.cx,t.cy,s,c,u)):r.push(...nX(t.cx,t.cy,d,f,s,c,l,u))}t.cx=d,t.cy=f,i+=7}}function iX(e,t){(Math.abs(e.cx-e.sx)>1e-10||Math.abs(e.cy-e.sy)>1e-10)&&t.push(mL(KY([e.cx,e.cy]),KY([e.sx,e.sy]))),e.cx=e.sx,e.cy=e.sy}function aX(e){let t=GY(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`:qY(i,r,t,n);break;case`L`:JY(i,r,t,n);break;case`H`:YY(i,r,t,n);break;case`V`:XY(i,r,t,n);break;case`C`:ZY(i,r,t,n);break;case`S`:QY(i,r,t,n);break;case`Q`:$Y(i,r,t,n);break;case`T`:eX(i,r,t,n);break;case`A`:rX(i,r,t,n);break;case`Z`:iX(r,n);break}a!==`S`&&a!==`T`&&(r.lastCmd=a)}return n}function oX(e){try{let t=aX(e);return t.length===0?k(Do(`SVG_EMPTY_PATH`,`SVG path produced no curves`)):O(new RL(t))}catch(e){return k(Do(`SVG_PARSE_FAILED`,`Failed to parse SVG path: ${e instanceof Error?e.message:String(e)}`))}}function sX(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=oX(l);u.ok&&n.push(u.value)}return n.length===0?k(Do(`SVG_NO_PATHS`,`No <path> elements found in SVG`)):O(n)}catch(e){return k(Do(`SVG_IMPORT_FAILED`,`Failed to import SVG: ${e instanceof Error?e.message:String(e)}`))}}function cX(e,t){try{let n=H(),r=e.map(e=>({shape:e.shape.wrapped,name:e.name,color:e.color?[...e.color]:void 0}));return O(n.exportSTEPConfigured(r,t))}catch(e){return k(Do(M.STEP_EXPORT_CONFIGURED_FAILED,`Configured STEP export failed`,e))}}async function lX(e){try{let t=await e.arrayBuffer(),n=H().importSTEP(t);if(n.length===0)return k(Do(`STEP_IMPORT_FAILED`,`STEP file contains no valid geometry`));for(let e=1;e<n.length;e++){let t=n[e];t&&H().dispose(t)}return O(U(n[0]))}catch(e){return k(Do(`STEP_IMPORT_FAILED`,`Failed to load STEP file`,e))}}async function uX(e){try{let t=await e.arrayBuffer(),n=H().importSTL(t);return n.IsNull()?k(Do(`STL_IMPORT_FAILED`,`Failed to create solid from STL mesh`)):O(U(n))}catch(e){return k(Do(`STL_IMPORT_FAILED`,`Failed to load STL file`,e))}}async function dX(e){try{let t=await e.arrayBuffer(),n=H().importIGES(t);if(n.length===0)return k(Do(`IGES_IMPORT_FAILED`,`IGES file contains no valid geometry`));for(let e=1;e<n.length;e++){let t=n[e];t&&H().dispose(t)}return O(U(n[0]))}catch(e){return k(Do(`IGES_IMPORT_FAILED`,`Failed to load IGES file`,e))}}function fX(e,t,n={}){let r=gq(e,t);return new dq((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(YK)):YK(e)))}function pX(e,t){let n=t?.fontSize??1,r=mq(t?.fontFamily);if(!r)return k(P(M.NO_FONT_LOADED,`No font loaded. Call loadFont() first.`,void 0,void 0,`Load a font with loadFont() before calling textMetrics()`));let i=r.getAdvanceWidth(e,n),a=n/r.unitsPerEm,o=r.ascender*a,s=r.descender*a;return O({width:i,height:o-s,ascender:o,descender:s})}function mX(e){let t=e?.fontSize??1,n=mq(e?.fontFamily);if(!n)return k(P(M.NO_FONT_LOADED,`No font loaded. Call loadFont() first.`,void 0,void 0,`Load a font with loadFont() before calling fontMetrics()`));let r=t/n.unitsPerEm,i=n.ascender*r,a=n.descender*r,o=(n.tables?.os2?.sTypoLineGap??0)*r;return O({ascender:i,descender:a,unitsPerEm:n.unitsPerEm,lineHeight:i-a+o})}function hX(e){return e.type===`init`}function gX(e){return e.type===`operation`}function _X(e){return e.type===`dispose`}function vX(e){return e.type===`batch`}function yX(e){return e.success}function bX(e){return!e.success}function xX(){return{pending:new Map}}function SX(e,t){let n=new Map(e.pending);return n.set(t.id,t),{pending:n}}function CX(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 wX(e){return e.pending.size}function TX(e){return e.pending.size===0}function EX(e,t){for(let n of e.pending.values())n.reject(t);return{pending:new Map}}function DX(e,t){let n=t.data,r=e.get(n.id);if(r)if(e.delete(n.id),yX(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 OX(e){let{worker:t,wasmUrl:n}=e,r=new Map,i=!1;function a(){return crypto.randomUUID()}function o(e){DX(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 kX(){return{operations:new Map}}function AX(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function jX(e){return e instanceof Error?e.message:String(e)}function MX(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:jX(e)}}}function NX(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 PX(e,t){let n=globalThis;n.onmessage=async r=>{let i=r.data;if(hX(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:jX(e)};n.postMessage(t)}return}if(gX(i)){let t=MX(e,i.operation,i.shapesBrep,i.parameters);n.postMessage(NX(i.id,t));return}if(vX(i)){let t=i.operations.map(t=>MX(e,t.operation,t.shapesBrep,t.params)),r={id:i.id,success:!0,resultData:t};n.postMessage(r);return}if(_X(i)){let e={id:i.id,success:!0};n.postMessage(e),n.close?.()}}}function FX(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:OX({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 IX=Object.defineProperty,LX=(e,t)=>{let n={};for(var r in e)IX(n,r,{get:e[r],enumerable:!0});return t||IX(n,Symbol.toStringTag,{value:`Module`}),n},RX=1,zX=2;function BX(e,t){t===`commonFace`&&e.SetGlue(RX),t===`sameFace`&&e.SetGlue(zX)}function VX(e){return typeof e==`number`}function HX(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 UX(e){return typeof e==`number`?!0:Array.isArray(e)&&e.length===2?e.every(VX):!1}function WX(e,t){let n=n=>{let r=e.findAll(n);if(r.length===0)return[];let i=0,a=HD(kD(vA(r)),t);for(let e=1;e<r.length;e++){let n=HD(kD(_A(r,e)),t);n<a&&(a=n,i=e)}return[_A(r,i)]},r=e=>{let t=n(e);return t.length===0?k(Oo(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found 0 element(s)`)):O(vA(t))};return{...e,findAll:n,findUnique:r}}function GX(e){return HI(`vertex`,e,GX,(t,n)=>({nearestTo:t=>WX(GX(e),t),atPosition:(e,t=1e-4)=>n(n=>HD(kD(n),e)<t),withinBox:(e,t)=>n(n=>{let r=kD(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=kD(n);return Math.abs(HD(i,t)-e)<r})}))}function KX(){return GX([])}var qX=new Map,JX=null,YX=null;function XX(e,t){qX.set(e,t),JX||=e,e===JX&&(YX=t)}function ZX(e){if(!e&&YX)return YX;let t=e??JX;if(!t)throw Error(`brepjs voxel engine not initialized. Call initVoxel() (or registerVoxel()) before using voxel operations.`);let n=qX.get(t);if(!n)throw Error(`brepjs: voxel engine '${t}' is not registered.`);return n}function QX(){return JX}function $X(e,t=`voxel`){XX(t,e),JX=t,YX=e}function eZ(e){if(e.vertices.length%3!=0)return P(`VOXEL_INVALID_MESH`,`mesh.vertices length must be a multiple of 3 (flat xyz).`);if(e.triangles.length%3!=0)return P(`VOXEL_INVALID_MESH`,`mesh.triangles length must be a multiple of 3.`);let t=e.vertices.length/3;for(let n=0;n<e.triangles.length;n++){let r=e.triangles[n];if(r===void 0||r>=t)return P(`VOXEL_INVALID_TRIANGLE_INDEX`,`triangle index ${r} at position ${n} is out of range for ${t} vertices.`)}return null}function tZ(e,t){return eZ(e)||(t.length%3==0?null:P(`VOXEL_INVALID_QUERIES`,`queries length must be a multiple of 3 (flat xyz).`))}function nZ(e){try{return O(ZX(e))}catch(e){return k(To(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function rZ(e,t,n){let r=tZ(e,t);if(r)return k(r);let i=nZ(n);return A(i)?i:O(i.value.winding_numbers(e.vertices,e.triangles,t))}function iZ(e,t,n){let r=tZ(e,t);if(r)return k(r);let i=nZ(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 aZ=48,oZ=2;function sZ(e,t,n){let r=eZ(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`repairMesh requires a non-empty triangle mesh.`));let i=t?.resolution??aZ,a=t?.padding??oZ;if(!Number.isInteger(i)||i<1)return k(P(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`));if(!Number.isInteger(a)||a<1)return k(P(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`));let o=nZ(n);if(A(o))return o;try{try{var s=IT();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(Eo(`VOXEL_REPAIR_FAILED`,e instanceof Error?e.message:`voxel repair failed (grid too large?).`,e))}}var cZ=.001;function lZ(e,t=cZ){try{let n=nA(e,{tolerance:t});return n.vertices.length===0||n.triangles.length===0?k(Eo(`VOXEL_SHAPE_MESH_EMPTY`,`shape tessellated to an empty triangle mesh.`)):O({vertices:n.vertices,triangles:n.triangles})}catch(e){return k(Eo(`VOXEL_SHAPE_MESH_FAILED`,e instanceof Error?e.message:`failed to mesh shape for voxel op.`,e))}}var uZ=48,dZ=2,fZ={union:0,intersection:1,difference:2};function pZ(e){let t=e?.resolution??uZ,n=e?.padding??dZ;return!Number.isInteger(t)||t<1?k(P(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(P(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function mZ(e){if(e.positions.length===0||e.indices.length===0)return k(Eo(`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 hZ(e,t,n,r){let i=eZ(e);if(i)return k(i);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`offsetMesh requires a non-empty triangle mesh.`));if(!Number.isFinite(t))return k(P(`VOXEL_INVALID_DISTANCE`,`distance must be a finite number.`));let a=pZ(n);if(A(a))return a;let o=nZ(r);if(A(o))return o;try{try{var s=IT();return mZ(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(Eo(`VOXEL_OFFSET_FAILED`,e instanceof Error?e.message:`voxel offset failed (grid too large?).`,e))}}function gZ(e,t,n,r){let i=eZ(e);if(i)return k(i);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`shellMesh requires a non-empty triangle mesh.`));if(!Number.isFinite(t)||t<=0)return k(P(`VOXEL_INVALID_THICKNESS`,`thickness must be a finite number > 0.`));let a=pZ(n);if(A(a))return a;let o=nZ(r);if(A(o))return o;try{try{var s=IT();return mZ(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(Eo(`VOXEL_SHELL_FAILED`,e instanceof Error?e.message:`voxel shell failed (grid too large?).`,e))}}function _Z(e,t,n,r,i){let a=eZ(e);if(a)return k(a);let o=eZ(t);if(o)return k(o);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`voxelBoolean requires a non-empty mesh for operand A.`));if(t.vertices.length===0||t.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`voxelBoolean requires a non-empty mesh for operand B.`));let s=fZ[n],c=pZ(r);if(A(c))return c;let l=nZ(i);if(A(l))return l;try{try{var u=IT();return mZ(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(Eo(`VOXEL_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel boolean failed (grid too large?).`,e))}}function vZ(e,t,n,r){let i=lZ(e);return A(i)?i:hZ(i.value,t,n,r)}function yZ(e,t,n,r){let i=lZ(e);return A(i)?i:gZ(i.value,t,n,r)}function bZ(e,t,n,r,i){let a=lZ(e);if(A(a))return a;let o=lZ(t);return A(o)?o:_Z(a.value,o.value,n,r,i)}var xZ=48,SZ=2,CZ={union:0,intersection:1,difference:2};function wZ(e){let t=e?.resolution??xZ,n=e?.padding??SZ;return!Number.isInteger(t)||t<1?k(P(`VOXEL_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(P(`VOXEL_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function TZ(e){try{var t=IT();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(Eo(`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 EZ(e){return{raw:e,delete(){e.free()}}}function DZ(e){return OZ(e)}function OZ(e){let t=YT(EZ(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,CZ[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=TZ(this.value);if(A(e))throw Error(e.error.message);return e.value}};return n}function kZ(e){return!e.disposed}function AZ(){return k(P(`VOXEL_FIELD_DISPOSED`,`the voxel field handle has been disposed.`))}function jZ(e,t,n){let r=eZ(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`voxelField requires a non-empty triangle mesh.`));let i=wZ(t);if(A(i))return i;let a=nZ(n);if(A(a))return a;try{return O(OZ(new a.value.VoxelField(e.vertices,e.triangles,i.value.resolution,i.value.padding)))}catch(e){return k(Eo(`VOXEL_FIELD_VOXELIZE_FAILED`,e instanceof Error?e.message:`voxel field voxelization failed (grid too large or non-dense?).`,e))}}function MZ(e,t,n,r,i){let a=eZ(e);if(a)return k(a);let o=eZ(t);if(o)return k(o);if(e.vertices.length===0||e.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`voxelBooleanField requires a non-empty mesh for operand A.`));if(t.vertices.length===0||t.triangles.length===0)return k(P(`VOXEL_EMPTY_MESH`,`voxelBooleanField requires a non-empty mesh for operand B.`));let s=wZ(r);if(A(s))return s;let c=nZ(i);if(A(c))return c;try{return O(OZ(c.value.VoxelField.boolean_of(e.vertices,e.triangles,t.vertices,t.triangles,CZ[n],s.value.resolution,s.value.padding)))}catch(e){return k(Eo(`VOXEL_FIELD_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel field boolean failed (grid too large or non-dense?).`,e))}}function NZ(e,t,n){if(!kZ(e)||!kZ(t))return AZ();try{return e.value.boolean(t.value,CZ[n]),O(e)}catch(e){return k(Eo(`VOXEL_FIELD_BOOLEAN_FAILED`,e instanceof Error?e.message:`voxel field boolean failed (dim mismatch?).`,e))}}function PZ(e,t){if(!kZ(e))return AZ();if(!Number.isFinite(t))return k(P(`VOXEL_INVALID_DISTANCE`,`distance must be a finite number.`));try{return e.value.offset(t),O(e)}catch(e){return k(Eo(`VOXEL_FIELD_OFFSET_FAILED`,e instanceof Error?e.message:`voxel field offset failed.`,e))}}function FZ(e,t){if(!kZ(e))return AZ();if(!Number.isFinite(t)||t<=0)return k(P(`VOXEL_INVALID_THICKNESS`,`thickness must be a finite number > 0.`));try{return e.value.shell(t),O(e)}catch(e){return k(Eo(`VOXEL_FIELD_SHELL_FAILED`,e instanceof Error?e.message:`voxel field shell failed.`,e))}}function IZ(e){if(!kZ(e))return AZ();try{return e.value.reinit(),O(e)}catch(e){return k(Eo(`VOXEL_FIELD_REINIT_FAILED`,e instanceof Error?e.message:`voxel field reinit failed.`,e))}}function LZ(e){if(!kZ(e))return AZ();try{return TZ(e.value)}catch(e){return k(Eo(`VOXEL_FIELD_CONTOUR_FAILED`,e instanceof Error?e.message:`voxel field contour failed.`,e))}}function RZ(e,t,n){let r=lZ(e);return A(r)?r:jZ(r.value,t,n)}function zZ(e,t,n,r,i){let a=lZ(e);if(A(a))return a;let o=lZ(t);return A(o)?o:MZ(a.value,o.value,n,r,i)}var BZ=48,VZ=2;function HZ(e){try{return O(ZX(e))}catch(e){return k(To(`VOXEL_NOT_INITIALIZED`,e instanceof Error?e.message:`voxel engine not initialized`,e))}}function UZ(e){let t=e?.resolution??BZ,n=e?.padding??VZ;return!Number.isInteger(t)||t<1?k(P(`SDF_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(n)||n<1?k(P(`SDF_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({resolution:t,padding:n})}function WZ(e){return{raw:e,delete(){e.free()}}}var GZ={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=YT(WZ(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))},...GZ,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 qZ(this.value,e)},rasterizeIn(e,t){return JZ(this.value,e,t)}}}function qZ(e,t){let n=UZ(t);if(A(n))return n;try{return O(DZ(e.rasterize(n.value.resolution,n.value.padding)))}catch(e){return YZ(e)}}function JZ(e,t,n){let r=UZ(n);if(A(r))return r;let i=XZ(t);if(i)return k(i);try{return O(DZ(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 YZ(e)}}function YZ(e){return k(Eo(`SDF_RASTERIZE_FAILED`,e instanceof Error?e.message:`SDF rasterization failed (grid too large?).`,e))}function XZ(e){if(![...e.min,...e.max].every(e=>Number.isFinite(e)))return P(`SDF_INVALID_BOUNDS`,`bounds must be finite numbers.`);for(let t=0;t<3;t++)if(e.max[t]<=e.min[t])return P(`SDF_INVALID_BOUNDS`,`bounds max must exceed min on every axis.`);return null}function ZZ(e,t){let n=HZ(t);if(A(n))return n;try{return O(KZ(e(n.value)))}catch(e){return k(Eo(`SDF_BUILD_FAILED`,e instanceof Error?e.message:`SDF primitive construction failed.`,e))}}function QZ(e,t){return ZZ(t=>t.Sdf.sphere(e),t)}function $Z(e,t,n,r){return ZZ(r=>r.Sdf.box_(e,t,n),r)}function eQ(e,t,n,r,i){return ZZ(i=>i.Sdf.rounded_box(e,t,n,r),i)}function tQ(e,t,n){return ZZ(n=>n.Sdf.cylinder(e,t),n)}function nQ(e,t,n){return ZZ(n=>n.Sdf.cone(e,t),n)}function rQ(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 iQ(e,t,n){return ZZ(n=>n.Sdf.torus(e,t),n)}function aQ(e,t,n){return ZZ(n=>n.Sdf.plane(e[0],e[1],e[2],t),n)}function oQ(e){if(e.length<2)return k(P(`SDF_INVALID_SPINE`,`sweep spine needs at least 2 points.`));let t=new Float64Array(e.length*3);for(let n=0;n<e.length;n++){let r=e[n];if(!r.every(e=>Number.isFinite(e)))return k(P(`SDF_INVALID_SPINE`,`sweep spine coordinates must be finite.`));t[n*3]=r[0],t[n*3+1]=r[1],t[n*3+2]=r[2]}return O(t)}function sQ(e,t,n,r){let i=oQ(e);if(A(i))return i;let a=n?.closed??!1;return ZZ(e=>e.Sdf.sweep(i.value,t.value,a),r)}var cQ={gyroid:0,schwarzP:1,diamond:2};function lQ(e,t,n,r){let i=cQ[e];return i===void 0?k(P(`SDF_INVALID_LATTICE_KIND`,`unknown lattice kind: ${e}`)):ZZ(e=>e.Sdf.lattice(i,t.value,n.value),r)}function uQ(e,t,n){return ZZ(n=>n.Sdf.strut_lattice(e,t.value),n)}function dQ(e){return{raw:e,delete(){e.free()}}}function fQ(e){let t=YT(dQ(e));return{get value(){return t.value.raw},get disposed(){return t.disposed},[Symbol.dispose](){t[Symbol.dispose]()}}}function pQ(e,t){let n=HZ(t);if(A(n))return n;try{return O(fQ(e(n.value)))}catch(e){return k(Eo(`SDF_FIELD_BUILD_FAILED`,e instanceof Error?e.message:`scalar field construction failed.`,e))}}function mQ(e,t){return pQ(t=>t.ScalarField.constant(e),t)}function hQ(e,t,n,r,i,a){return pQ(a=>a.ScalarField.axial_ramp(e,t,n,r,i),a)}function gQ(e,t,n,r,i,a,o){return pQ(o=>o.ScalarField.radial_ramp(e[0],e[1],e[2],t,n,r,i,a),o)}function _Q(e,t,n,r){return pQ(r=>r.ScalarField.from_sdf(e.value,t,n),r)}function vQ(e,t,n,r){return pQ(r=>r.ScalarField.clamp(e.value,t,n),r)}var yQ={gyroid:0,schwarzP:1,diamond:2},bQ=48,xQ=2;function SQ(e){let t=yQ[e.type];if(t===void 0)return k(P(`LATTICE_INVALID_TYPE`,`lattice type must be one of gyroid, schwarzP, diamond (got '${e.type}').`));if(!(e.period>0))return k(P(`LATTICE_INVALID_PERIOD`,`period must be > 0.`));if(!(e.thickness>0))return k(P(`LATTICE_INVALID_THICKNESS`,`thickness must be > 0.`));let n=e.resolution??bQ,r=e.padding??xQ;return!Number.isInteger(n)||n<1?k(P(`LATTICE_INVALID_RESOLUTION`,`resolution must be an integer >= 1.`)):!Number.isInteger(r)||r<1?k(P(`LATTICE_INVALID_PADDING`,`padding must be an integer >= 1.`)):O({tag:t,period:e.period,thickness:e.thickness,resolution:n,padding:r})}function CQ(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 wQ(e,t,n){let r=eZ(e);if(r)return k(r);if(e.vertices.length===0||e.triangles.length===0)return k(P(`LATTICE_EMPTY_MESH`,`latticeInfill requires a non-empty triangle mesh.`));let i=SQ(t);if(A(i))return i;let a=nZ(n);if(A(a))return a;let{tag:o,period:s,thickness:c,resolution:l,padding:u}=i.value;try{try{var d=IT();return O(CQ(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(Eo(`LATTICE_INFILL_FAILED`,e instanceof Error?e.message:`lattice infill failed (grid too large?).`,e))}}function TQ(e,t,n){let r=lZ(e);return A(r)?r:wQ(r.value,t,n)}function EQ(e,t,n){for(let t=0;t<3;t++){let n=e.min[t],r=e.max[t];if(n===void 0||r===void 0||!(n<r))return k(P(`LATTICE_INVALID_BOUNDS`,`bounds.min must be strictly less than bounds.max on every axis (axis ${t}).`))}let r=SQ(t);if(A(r))return r;let i=nZ(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=IT();return O(CQ(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(Eo(`TPMS_LATTICE_FAILED`,e instanceof Error?e.message:`tpms lattice failed (grid too large?).`,e))}}function DQ(e){return H().createVector3d(e[0],e[1],e[2])}function OQ(e){return H().createPoint3d(e[0],e[1],e[2])}function kQ(e){return H().createDirection3d(e[0],e[1],e[2])}function AQ(e){return[e.X(),e.Y(),e.Z()]}function jQ(e){return[e.X(),e.Y(),e.Z()]}function MQ(e){return[e.X(),e.Y(),e.Z()]}function NQ(e,t){let n=DQ(e);try{return t(n)}finally{n.delete()}}function PQ(e,t){let n=OQ(e);try{return t(n)}finally{n.delete()}}function FQ(e,t){let n=kQ(e);try{return t(n)}finally{n.delete()}}var IQ=.299,LQ=.587,RQ=.114;function zQ(e,t={}){if(e.length<2)return k(P(M.SURFACE_GRID_TOO_SMALL,`surfaceFromGrid: need at least 2 rows, got ${e.length}`));let n=e.length,r=e[0]?.length??0;if(r<2)return k(P(M.SURFACE_GRID_TOO_SMALL,`surfaceFromGrid: need at least 2 columns, got ${r}`));for(let t=0;t<n;t++){let n=e[t];if(!n||n.length!==r)return k(P(M.SURFACE_GRID_JAGGED,`surfaceFromGrid: row ${t} has ${n?.length??0} columns, expected ${r}`))}let{width:i=r-1,depth:a=n-1,scaleZ:o=1}=t,s=i/(r-1),c=a/(n-1);try{return BQ(e,n,r,s,c,o)}catch{}try{return VQ(e,n,r,s,c,o)}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.SURFACE_FAILED,`surfaceFromGrid failed: ${t}`,e))}}function BQ(e,t,n,r,i,a){let o=[];for(let s=0;s<t;s++)for(let t=0;t<n;t++){let n=e[s],c=(n?n[t]??0:0)*a;o.push([t*r,s*i,c])}let s=U(H().bsplineSurface(o,t,n));return FE(s)?O(s):(W(s),k(N(M.SURFACE_FAILED,`B-spline surface did not produce a face`)))}function VQ(e,t,n,r,i,a){let o=[];for(let s=0;s<t;s++)for(let t=0;t<n;t++){let n=e[s],c=(n?n[t]??0:0)*a;o.push([t*r,s*i,c])}let s=U(H().triangulatedSurface(o,t,n));return FE(s)||IE(s)?O(s):(W(s),k(N(M.SURFACE_FAILED,`surfaceFromGrid: unexpected shape type from sewing`)))}async function HQ(e,t={}){let n=t.channel??`luminance`,r=Math.max(1,Math.round(t.downsample??1));if(typeof createImageBitmap!=`function`)return k(Do(M.SURFACE_FAILED,`surfaceFromImage requires createImageBitmap (not available in this environment)`));let i;try{i=await createImageBitmap(e)}catch(e){return k(Do(M.SURFACE_FAILED,`surfaceFromImage: failed to decode image — ${e instanceof Error?e.message:String(e)}`))}let a=i.width,o=i.height;if(a<2||o<2)return i.close(),k(P(M.SURFACE_GRID_TOO_SMALL,`surfaceFromImage: image too small (${a}x${o}), need at least 2x2`));if(typeof OffscreenCanvas!=`function`)return i.close(),k(Do(M.SURFACE_FAILED,`surfaceFromImage requires OffscreenCanvas (not available in this environment)`));let s=new OffscreenCanvas(a,o).getContext(`2d`);if(!s)return i.close(),k(Do(M.SURFACE_FAILED,`surfaceFromImage: could not get 2D canvas context`));s.drawImage(i,0,0),i.close();let c=s.getImageData(0,0,a,o).data,l=[];for(let e=0;e<o;e+=r){let t=[];for(let i=0;i<a;i+=r){let r=(e*a+i)*4,o=c[r]??0,s=c[r+1]??0,l=c[r+2]??0,u;switch(n){case`r`:u=o/255;break;case`g`:u=s/255;break;case`b`:u=l/255;break;default:u=(IQ*o+LQ*s+RQ*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),zQ(l,u)}function UQ(e,t){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function WQ(e,t={}){if(e.length===0)return k(P(M.HULL_EMPTY_INPUT,`hull: at least one shape is required`,void 0,void 0,`Provide one or more shapes to compute a convex hull`));for(let[t,n]of e.entries()){let e=UQ(n,`hull: shapes[${t}]`);if(A(e))return e}let n=t.tolerance??.1;try{let t=H(),r=e.map(e=>e.wrapped),i=U(t.hull(r,n));return LE(i)?O(i):(W(i),k(N(M.HULL_NOT_3D,`Hull result is not a solid; input may be degenerate`)))}catch(e){let t=e instanceof Error?e.message:String(e);return t.includes(`coplanar`)||t.includes(`fewer than`)||t.includes(`degenerate`)?k(N(M.HULL_DEGENERATE,`Hull degenerate: ${t}`,e)):k(N(M.HULL_FAILED,`Hull operation failed: ${t}`,e))}}function GQ(e){if(e.length<4)return k(P(M.HULL_EMPTY_INPUT,`convexHull: at least 4 points required, got ${e.length}`,void 0,void 0,`Provide 4 or more non-coplanar 3D points`));try{let t=H(),n=e.map(e=>({x:e[0],y:e[1],z:e[2]})),r=U(t.hullFromPoints(n,.1));return LE(r)?O(r):(W(r),k(N(M.HULL_NOT_3D,`convexHull result is not a solid; points may be coplanar`)))}catch(e){let t=e instanceof Error?e.message:String(e);return t.includes(`coplanar`)||t.includes(`fewer than`)||t.includes(`degenerate`)?k(N(M.HULL_DEGENERATE,`convexHull degenerate: ${t}`,e)):k(N(M.HULL_FAILED,`convexHull failed: ${t}`,e))}}function KQ(e){let n=dD(e);if(n.length!==1)return null;let r=t(n,0);if(ED(r)!==`sphere`)return null;let i=H().area(r.wrapped);return Math.sqrt(i/(4*Math.PI))}function qQ(e,t,n){try{let r=U(H().offset(e.wrapped,t,n));return zE(r)?O(r):(W(r),k(Co(M.MINKOWSKI_NOT_3D,`Minkowski sphere offset did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.MINKOWSKI_FAILED,`Minkowski sphere offset failed: ${t}`,e,{operation:`minkowski`,fastPath:`sphere`}))}}function JQ(e,t,n){let r=H();try{let i=pD(e),a=pD(t);if(i.length===0||a.length===0)return k(N(M.MINKOWSKI_FAILED,`Minkowski sum: one or both shapes have no vertices`,void 0,{operation:`minkowski`}));let o=[];for(let e of i){let[t,n,i]=r.vertexPosition(e.wrapped);for(let e of a){let[a,s,c]=r.vertexPosition(e.wrapped);o.push({x:t+a,y:n+s,z:i+c})}}let s=U(r.hullFromPoints(o,n));return zE(s)?O(s):(W(s),k(Co(M.MINKOWSKI_NOT_3D,`Minkowski hull did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.MINKOWSKI_FAILED,`Minkowski general path failed: ${t}`,e,{operation:`minkowski`}))}}function YQ(e,t,n={}){let{tolerance:r=1e-6}=n;if(H().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`minkowski: shape is a null shape`));if(H().isNull(t.wrapped))return k(P(M.MINKOWSKI_NULL_TOOL,`minkowski: tool is a null shape`));if(!zE(e)||!zE(t))return k(P(M.MINKOWSKI_NOT_3D,`minkowski: both shape and tool must be 3D`));let i=KQ(t);return i===null?JQ(e,t,r):qQ(e,i,r)}function XQ(e,t,n={}){let{tolerance:r=1e-6}=n;if(e.length<4)return k(P(M.POLYHEDRON_INSUFFICIENT_POINTS,`polyhedron: need at least 4 points, got ${e.length}`));if(t.length<4)return k(P(M.POLYHEDRON_INSUFFICIENT_FACES,`polyhedron: need at least 4 faces, got ${t.length}`));let i=[];for(let[n,r]of t.entries()){for(let t of r)if(t<0||t>=e.length)return k(P(M.POLYHEDRON_INVALID_INDEX,`polyhedron: face ${n} has out-of-range index ${t} (${e.length} points)`));if(r.length<3)continue;let t=r[0];for(let e=1;e<r.length-1;e++)i.push([t,r[e],r[e+1]])}try{let t=H(),n=e.map(([e,t,n])=>({x:e,y:t,z:n})),a=U(t.buildSolidFromFaces(n,i,r));return LE(a)?O(a):(W(a),k(N(M.POLYHEDRON_FAILED,`Polyhedron did not produce a solid`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.POLYHEDRON_FAILED,`Polyhedron failed: ${t}`,e))}}var ZQ=1e-10;function QQ(e,t,n,r){return e*r-t*n}function $Q(e,t,n,r){return e*n+t*r}function e$(e,t){return Math.sqrt(e*e+t*t)}function t$(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 n$(e){let t=0;for(let n=0;n<e.length;n++){let r=t$(e,n),i=t$(e,n+1);t+=r.x*i.y-i.x*r.y}return t<0?[...e].reverse():e}function r$(e,t){let n=t$(e,t-1),r=t$(e,t),i=t$(e,t+1),a=r.x-n.x,o=r.y-n.y,s=e$(a,o),c=i.x-r.x,l=i.y-r.y,u=e$(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,_=e$(h,g);if(_<ZQ)return{dx:d,dy:f};h/=_,g/=_;let v=$Q(h,g,d,f),y=Math.abs(v)>ZQ?1/v:1;return{dx:h*y,dy:g*y}}function i$(e){return!e.prev||!e.next?!1:QQ(e.x-e.prev.x,e.y-e.prev.y,e.next.x-e.x,e.next.y-e.y)<-1e-10}function a$(e){let t=e.map((t,n)=>{let r=r$(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 o$(e,t){let n=e;for(let e=0;e<t&&n;e++)n.active=!1,n=n.next}function s$(e){let t=1,n=e.next;for(;n!==e&&(t++,n=n.next,!(t>1e4)););return t}function c$(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 l$(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=e$(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=e$(y,b);if(x<ZQ)return f;let S=$Q(p-h,m-g,y,b)/(x*x);return S<-.01||S>1.01?null:f}function u$(e){let t=[];for(let n of e){if(!n.active||!n.next)continue;let e=c$(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(i$(n)){let e=n.next.next,r=0;for(;e!==n.prev&&e!==n&&r<1e3;){let i=l$(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 d$(e){if(e.length<3)return O({nodes:[],faces:[]});try{return O(f$(e))}catch(e){return k(Eo(M.STRAIGHT_SKELETON_FAILED,e instanceof Error?e.message:String(e),e))}}function f$(e){let t=n$(e),n=t.length,r=[],i=Array.from({length:n},()=>[]),a=a$(t),o=0,s=n*n*2;for(;o<s;){o++;let e=a.find(e=>e.active);if(!e)break;let t=s$(e);if(t<=3){if(t===3){let t=e,n=t.next,a=n.next,o=c$(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 o$(e,t);continue}let n=a.filter(e=>e.active),s=u$(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=r$(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=r$(f(e),0);e.bx=p.dx,e.by=p.dy;let m=r$(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=[t$(t,e),t$(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&&e$(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 p$(e){let t=uD(e).map(e=>{let t=Mk(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 m$(e){let t=[];for(let n=1;n<e-1;n++)t.push([0,n,n+1]);return t}function h$(e,t,n,r,i,a){return(n-e)*(a-t)-(r-t)*(i-e)}function g$(e,t,n,r,i,a,o,s){let c=h$(n,r,i,a,e,t),l=h$(i,a,o,s,e,t),u=h$(o,s,n,r,e,t);return!((c<0||l<0||u<0)&&(c>0||l>0||u>0))}function _$(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||h$(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&&g$(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 v$(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=m$(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 y$(e,t){let n=(t?.angle??45)*JE,r=Math.tan(n);try{let t=p$(e);if(t.length<3)return k(N(M.ROOF_FAILED,`Wire must have at least 3 edges for roof generation`));let n=d$(t);if(!n.ok)return n;let i=n.value;if(i.faces.length===0)return k(N(M.ROOF_FAILED,`Straight skeleton computation produced no faces`));let a=H(),o=v$(i,r,a);for(let[e,n,r]of _$(t)){let i=t[e],s=t[n],c=t[r];if(!i||!s||!c)continue;let l=[i.x,i.y,0],u=[s.x,s.y,0],d=[c.x,c.y,0],f=a.buildTriFace(l,d,u);f!==null&&o.push(f)}if(o.length===0)return k(N(M.ROOF_FAILED,`No valid triangular faces could be built`));try{let e=a.sewAndSolidify(o,1e-6),t=a.fixShape(e);return t!==e&&a.dispose(e),O(kE(t))}catch(e){try{let t=kE(a.sew(o,1e-6));return mE(t)?O(t):k(N(M.ROOF_FAILED,`Sew fallback produced invalid solid`,e))}catch(e){return k(N(M.ROOF_FAILED,`Failed to sew roof faces`,e))}}finally{for(let e of o)a.dispose(e)}}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.ROOF_FAILED,`Roof generation failed: ${t}`,e))}}function b$(e){return[[1,0,0,e[0]],[0,1,0,e[1]],[0,0,1,e[2]],[0,0,0,1]]}function x$(e){let t=e[0];return t!==void 0&&typeof t[0]==`number`}function S$(e,t,n){return{__instanced:!0,source:e,placements:t,grid:n,[Symbol.dispose](){e[Symbol.dispose]()}}}function C$(e){return typeof e==`object`&&!!e&&e.__instanced===!0}function w$(e,t){return S$(e,x$(t)?t.map(b$):t.map(e=>e.map(e=>[...e])))}function T$(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(b$([e*i,t*a,0]));return S$(e,o,{cols:n,rows:r,pitchX:i,pitchY:a})}function E$(e){return e.placements.length}function D$(e,t={}){let{source:n,placements:r,grid:i}=e;return r.length===0?k(P(`INSTANCE_EMPTY`,`materialize: instance has no placements`)):t.fuse?zE(n)?i?JP(n,[1,0,0],[0,1,0],i.cols,i.rows,i.pitchX,i.pitchY):O$(n,r,!0):k(P(`MATERIALIZE_NOT_3D`,`materialize({fuse:true}) requires a 3D source shape`)):O$(n,r,!1)}function O$(e,t,n){let r=[];for(let n of t){let t=bk(e,n);if(!t.ok){for(let e of r)e[Symbol.dispose]();return t}r.push(t.value)}let i=n?GA(r,{unsafe:!0}):O(hj(r));for(let e of r)(!i.ok||e!==i.value)&&e[Symbol.dispose]();return i}function k$(e,t){return{geometry:nA(e.source,t),instances:e.placements}}var A$={coincident:3,concentric:4,distance:1,angle:1},j$=[1,0,0,0];function M$(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function N$(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function P$(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function F$(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function I$(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function L$(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function R$(e){return L$(F$(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function z$(e,t){let n=M$(sF(t.rotation,e.origin),t.position);return{type:e.type,origin:n,...e.normal?{normal:sF(t.rotation,e.normal)}:{},...e.direction?{direction:sF(t.rotation,e.direction)}:{}}}function B$(e,t,n){let r=e.normal??[0,0,1];return{position:I$(r,P$(r,N$(e.origin,t.origin))+n),rotation:j$}}function V$(e,t){let n=e.direction??[0,0,1],r=lF(t.direction??[0,0,1],n),i=sF(r,t.origin);return{position:N$(e.origin,i),rotation:r}}function H$(e,t,n){let r=L$(e.normal??[0,0,1]),i=L$(t.normal??[0,0,1]),a=Math.acos(Math.max(-1,Math.min(1,P$(i,r)))),o=F$(i,r);return{position:[0,0,0],rotation:cF(Math.hypot(o[0],o[1],o[2])<1e-9?R$(i):o,a-n)}}function U$(e,t,n){let r=N$(t,e),i=Math.hypot(r[0],r[1],r[2]);return{position:N$(M$(e,I$(i<1e-9?[1,0,0]:I$(r,1/i),n)),t),rotation:j$}}function W$(e,t,n,r){let i=L$(e);return{position:I$(i,P$(i,N$(t,n))-r),rotation:j$}}function G$(e,t,n){let r=L$(e.direction??[0,0,1]),i=M$(e.origin,I$(r,P$(r,N$(t,e.origin))));if(n===0)return{position:N$(i,t),rotation:j$};let a=N$(t,i),o=Math.hypot(a[0],a[1],a[2]);return{position:N$(M$(i,I$(o<1e-9?R$(r):I$(a,1/o),n)),t),rotation:j$}}function K$(e,t,n){let r=L$(t.direction??[0,0,1]),i=N$(t.origin,e),a=N$(i,I$(r,P$(r,i))),o=Math.hypot(a[0],a[1],a[2]);return n===0?{position:I$(a,-1),rotation:j$}:{position:N$(I$(o<1e-9?R$(r):I$(a,1/o),n),a),rotation:j$}}function q$(e,t,n){let r=L$(e.direction??[0,0,1]),i=lF(L$(t.direction??[0,0,1]),r),a=N$(sF(i,t.origin),e.origin),o=N$(a,I$(r,P$(r,a))),s=Math.hypot(o[0],o[1],o[2]);return{position:N$(I$(s<1e-9?R$(r):I$(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`]),Y$={angle:`plane`,concentric:`axis`},X$=new Set([`coincident`,`distance`,`angle`,`concentric`]);function Z$(e,t,n){let r=Y$[e];return r?t===r&&n===r:J$.has(`${t}-${n}`)}function Q$(e,t,n){switch(`${e.type}-${t.type}`){case`plane-plane`:case`plane-point`:return B$(e,t,n);case`point-plane`:return W$(t.normal??[0,0,1],e.origin,t.origin,n);case`point-point`:return U$(e.origin,t.origin,n);case`axis-axis`:return n===0?V$(e,t):q$(e,t,n);case`axis-point`:return G$(e,t.origin,n);case`point-axis`:return K$(e.origin,t,n);default:return null}}function $$(e,t,n){switch(e.type){case`concentric`:return V$(t,n);case`angle`:return H$(t,n,(e.value??0)*Math.PI/180);default:{let r=Q$(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 e1(e,t){let n=new Map;for(let t of e)n.set(t,{position:[0,0,0],rotation:j$});let r=[],i=t.filter(e=>X$.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:j$},l=z$(r.entity,a);n.set(i.node,$$(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+(A$[t]??A$[t.split(`(`)[0]??``]??0),0),converged:r.length===0,unsupported:r}}function t1(e){if(e.face){let t=EO(e.face);return t?{type:`axis`,origin:t.origin,direction:t.direction}:{type:`plane`,origin:TO(e.face),normal:wO(e.face)}}if(e.edge){if(jk(e.edge)===`LINE`)return{type:`axis`,origin:Mk(e.edge),direction:Fk(e.edge)};let t=Lk(e.edge);return t?{type:`axis`,origin:t.origin,direction:t.direction}:null}return e.point?{type:`point`,origin:e.point}:null}function n1(e,t){let n=t1(e),r=t1(t);return!n||!r?k(P(M.ASSEMBLY_MATE_INVALID,`solveAssembly: could not extract geometry from mate entities`)):O({entityA:{node:e.node,entity:n},entityB:{node:t.node,entity:r}})}function r1(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=n1(e.entityA,e.entityB);return t.ok?O({type:`coincident`,...t.value}):t}case`distance`:{let t=n1(e.entityA,e.entityB);return t.ok?O({type:`distance`,...t.value,value:e.distance}):t}case`angle`:{let t=n1(e.entityA,e.entityB);return t.ok?O({type:`angle`,...t.value,value:e.angle}):t}case`concentric`:{let t=n1(e.axisA,e.axisB);return t.ok?O({type:`concentric`,...t.value}):t}}}function i1(e,t){let n=e.mates??[];return{...e,mates:[...n,t]}}function a1(e){let t=e.mates;if(!t||t.length===0)return k(P(M.ASSEMBLY_MATE_INVALID,`solveAssembly: no mates defined`));try{let n=[];eF(e,e=>{n.push(e.name)});let r=[];for(let e of t){let t=r1(e);if(!t.ok)return t;r.push(t.value)}let i=e1(n,r);if(!i.converged){let e=i.unsupported.length>0?`Unsupported constraint types: ${i.unsupported.join(`, `)} (${i.dof} DOF unresolved)`:`Assembly constraint solver did not converge`;return k(N(M.ASSEMBLY_NOT_CONVERGED,e))}return O({transforms:i.transforms,dof:i.dof,converged:i.converged})}catch(e){let t=e instanceof Error?e.message:String(e);return k(N(M.ASSEMBLY_SOLVE_FAILED,`Assembly solve failed: ${t}`,e))}}function o1(e,t,n=1e-6){return H().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`checkInterference: first shape is a null shape`)):H().isNull(t.wrapped)?k(P(M.NULL_SHAPE_INPUT,`checkInterference: second shape is a null shape`)):JT(()=>{let r=H().distance(e.wrapped,t.wrapped);return O({hasInterference:r.value<=n,minDistance:r.value,pointOnShape1:r.point1,pointOnShape2:r.point2})})}function s1(e,n=1e-6){let r=[],i=e.map(e=>wD(e));return e.forEach((a,o)=>{for(let s=o+1;s<e.length;s++){if(c1(t(i,o),t(i,s),n))continue;let c=j(o1(a,t(e,s),n));c.hasInterference&&r.push({i:o,j:s,result:c})}}),r}function c1(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 l1(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 u1(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 d1(e){let{type:t,data:n}=e,r=H();if(t===`LINE`)return r.makeLineEdge([u1(n,10),u1(n,20),u1(n,30)],[u1(n,11),u1(n,21),u1(n,31)]);if(t===`CIRCLE`)return r.makeCircleEdge([u1(n,10),u1(n,20),u1(n,30)],[0,0,1],u1(n,40));if(t===`ARC`){let e=u1(n,50)*Math.PI/180,t=u1(n,51)*Math.PI/180;return r.makeCircleArc([u1(n,10),u1(n,20),u1(n,30)],[0,0,1],u1(n,40),e,t)}}async function f1(e,t){let n;try{n=await e.text()}catch(e){return k(Do(M.DXF_IMPORT_FAILED,`Failed to read DXF blob`,e))}let r=l1(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=d1(e);t!==void 0&&a.push(t)}return a.length===0?O([]):O([EE(H().makeWire(a))])}catch(e){return k(Do(M.DXF_IMPORT_FAILED,`Failed to convert DXF entities to geometry`,e))}finally{for(let e of a)e.delete()}}function p1(e,t,n=1e-6){let r=H(),i=[];for(let[t,n,a]of e){let e=r.buildTriFace(t,n,a);e!==null&&i.push(e)}if(i.length===0)return k(Do(t,`No valid triangular faces could be built`));try{let e=U(r.sewAndSolidify(i,n));for(let e of i)r.dispose(e);return O(e)}catch{try{return O(VE(r.sew(i,n)))}catch(e){return k(Do(t,`Failed to sew triangular faces`,e))}}}function m1(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 h1(e){return e.split(/\s+/).slice(1).map(e=>parseInt(e.split(`/`)[0]??``,10)).filter(e=>!isNaN(e))}async function g1(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=m1(t);e&&n.push(e)}else if(t.startsWith(`f `)){let e=h1(t);e.length>=3&&r.push(e)}}if(n.length===0||r.length===0)return k(Do(M.OBJ_IMPORT_FAILED,`OBJ file contains no valid geometry`));try{return _1(n,r)}catch(e){let t=e instanceof Error?e.message:String(e);return k(Do(M.OBJ_IMPORT_FAILED,`OBJ import failed: ${t}`,e))}}function _1(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 p1(n,M.OBJ_IMPORT_FAILED)}function v1(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 y1(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95}function b1(e){let t={},n=0;for(;n<e.length;){let r=e.indexOf(`="`,n);if(r<0)break;let i=r;for(;i>0&&y1(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 x1(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 S1(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 C1(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 w1(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=b1(e.slice(r,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of x1(a,`color`)){let t=b1(e).color;t!==void 0&&l.push(C1(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=b1(e.slice(n,o+1)).id;if(s===void 0)continue;let c=parseInt(s,10),l=[];for(let e of x1(a,`base`)){let t=b1(e).displaycolor;t===void 0?l.push([0,0,0,1]):l.push(C1(t))}t.set(c,l)}return t}function T1(e){let t=[],n=[],r=[],i=w1(e);for(let n of x1(e,`vertex`)){let e=b1(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=S1(e,`object`);if(s!==null){let e=s.indexOf(`>`);if(e>=0){let t=b1(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 x1(e,`triangle`)){let e=b1(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 E1(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 D1(e){let t=H(),n=e.vertices.map(([e,t,n])=>({x:e,y:t,z:n})),r=e.triangles;try{return O(U(t.buildSolidFromFaces(n,r,1e-6)))}catch{let t=[];for(let[n,r,i]of e.triangles){let a=e.vertices[n],o=e.vertices[r],s=e.vertices[i];!a||!o||!s||t.push([a,o,s])}return p1(t,M.THREEMF_IMPORT_FAILED)}}async function O1(e){try{let t=await e.arrayBuffer(),n=v1(new Uint8Array(t),`3D/3dmodel.model`);if(!n)return k(Do(M.THREEMF_IMPORT_FAILED,`3MF archive does not contain 3D/3dmodel.model (or uses unsupported compression)`));let r=T1(new TextDecoder().decode(n));if(r.vertices.length===0||r.triangles.length===0)return k(Do(M.THREEMF_IMPORT_FAILED,`3MF model contains no valid geometry`));let i=D1(r);if(i.ok){let e=E1(r.triangleColors);e!==null&&nk(i.value,e)}return i}catch(e){let t=e instanceof Error?e.message:String(e);return k(Do(M.THREEMF_IMPORT_FAILED,`3MF import failed: ${t}`,e))}}async function k1(e){try{let t=await e.arrayBuffer();return O(U(H().importGLB(t)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(Do(M.GLB_IMPORT_FAILED,`Failed to import GLB: ${t}`,e))}}function $(e){return`__wrapped`in e?e.val:e}function A1(e){return $(e)}function j1(e,t){return fk($(e),t)}function M1(e,t,n){let r=n?.at;return pk($(e),t,r,n?.axis)}function N1(e,t){let n=t?.at;return mk($(e),t?.normal??[1,0,0],n)}function P1(e,t,n){return hk($(e),t,n?.center)}function F1(e){return wk($(e))}function I1(e,t){return bk($(e),t)}function L1(e,t){return Ck($(e),t)}function R1(e,t){return Sk($(e),t)}function z1(e,t,n){return VA($(e),$(t),{...n,unsafe:!0})}function B1(e,t,n){return HA($(e),$(t),{...n,unsafe:!0})}function V1(e,t){return GA(e.map(e=>$(e)),{...t,unsafe:!0})}function H1(e,t,n){return KA($(e),t.map(e=>$(e)),{...n,unsafe:!0})}function U1(e,t,n){return UA($(e),$(t),{...n,unsafe:!0})}function W1(e,t,n){return YA($(e),t,n)}function G1(e,t,n){return tj($(e),t,n)}function K1(e,t){return nj($(e),t)}function q1(e,t,n){return rj($(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 Y1(e,t){return Array.isArray(e)?e:typeof e==`object`&&`findAll`in e?e.findAll(t):e(ZI()).findAll(t)}function X1(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=J1(t,r),a=n),tM(r,i,a)}function Q1(e,t,n){let r=$(e),i,a;n===void 0?(i=void 0,a=t):(i=J1(t,r),a=n);let o=X1(a);return o.mode===`distAngle`?Sj(r,[...i??uD(r)],o.distance,o.angle):nM(r,i,o.distance)}function $1(e,t,n,r){let i=$(e);return rM(i,Y1(t,i),n,r?.tolerance)}function e0(e,t,n){return iM($(e),t,n?.tolerance)}function t0(e,t){return $j($(e),t)}function n0(e,t,n){let r=$(e);return oM(r,Y1(t,r),n.pullDirection,n.neutralPlane,n.angle)}function r0(e){return fM($(e))}function i0(e){return Ak($(e))}function a0(e,t){return nA($(e),t)}function o0(e,t){return rA($(e),t)}function s0(e){return OD($(e))}function c0(e){return Tk($(e))}function l0(e){return mO(e)}function u0(e){return cM($(e))}function d0(e){return Dk($(e))}function f0(e,t){return kM($(e),typeof t==`number`?[0,0,t]:t)}function p0(e,t){let n=t?.at??[0,0,0];return AM($(e),n,t?.axis??[0,0,1],t?.angle??2*Math.PI)}function m0(e,t){return MM(e.map(e=>$(e)),t)}function h0(e,n){if(n===void 0){let t=dD(e);if(t.length===0)return k(P(M.COMPOUND_NO_FACES,`compoundOps: shape has no faces`));let n=vA(t),r=TO(n)[2];for(let e=1;e<t.length;e++){let i=_A(t,e),a=TO(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(Oo(M.COMPOUND_FACE_NOT_FOUND,`compoundOps: face finder matched no faces`)):O(t(r,0))}return O(n)}function g0(e){return`sketchOnPlane`in e&&typeof e.sketchOnPlane==`function`?{wire:e.sketchOnPlane(`XY`).wire,owned:!0}:{wire:e,owned:!1}}function _0(e,t){let n=$(e),{at:r,radius:i,axis:a}=t,o=a??[0,0,1];if(i<=0)return k(P(`DRILL_INVALID_RADIUS`,`Drill radius must be positive`));if(GD(o))return k(P(`DRILL_ZERO_AXIS`,`Drill axis cannot be zero`));let s=UD(o),c=r.length===2?[r[0],r[1],0]:[r[0],r[1],r[2]],l;if(t.depth!==void 0)l=cj(i,t.depth,c,s);else{let e=wD(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=cj(i,a-r,[c[0]+s[0]*r,c[1]+s[1]*r,c[2]+s[2]*r],s)}try{return HA(n,l,{unsafe:!0})}finally{l[Symbol.dispose]()}}function v0(e,t){try{var n=IT();let r=$(e),{profile:i,depth:a}=t;if(a<=0)return k(P(`POCKET_INVALID_DEPTH`,`Pocket depth must be positive`));let o=h0(r,t.face);if(A(o))return o;let s=o.value,c=wO(s),l=TO(s),u=n.u(new XT),{wire:d,owned:f}=g0(i);f&&u.register(d);let p=NA(d);if(A(p))return p;u.register(p.value);let m=kM(u.register(fk(p.value,l)),ID(UD(c),-a));return A(m)?m:(u.register(m.value),HA(r,m.value,{unsafe:!0}))}catch(e){n.e=e}finally{n.d()}}function y0(e,t){try{var n=IT();let r=$(e),{profile:i,height:a}=t;if(a<=0)return k(P(`BOSS_INVALID_HEIGHT`,`Boss height must be positive`));let o=h0(r,t.face);if(A(o))return o;let s=o.value,c=wO(s),l=TO(s),u=n.u(new XT),{wire:d,owned:f}=g0(i);f&&u.register(d);let p=NA(d);if(A(p))return p;u.register(p.value);let m=kM(u.register(fk(p.value,l)),ID(UD(c),a));return A(m)?m:(u.register(m.value),VA(r,m.value,{unsafe:!0}))}catch(e){n.e=e}finally{n.d()}}function b0(e,t){try{var n=IT();let r=$(e),i=t?.normal??[1,0,0],a=t?.at;return GD(i)?k(P(`MIRROR_ZERO_NORMAL`,`Mirror plane normal cannot be zero`)):VA(r,n.u(mk(r,i,a)),{unsafe:!0})}catch(e){n.e=e}finally{n.d()}}function x0(e,t){let n=$(e),{xDir:r,xCount:i,xSpacing:a,yDir:o,yCount:s,ySpacing:c}=t;if(i<1||s<1)return k(P(`PATTERN_INVALID_COUNT`,`Pattern counts must be at least 1`));if(GD(r))return k(P(`PATTERN_ZERO_DIRECTION`,`X direction cannot be zero`));if(GD(o))return k(P(`PATTERN_ZERO_DIRECTION`,`Y direction cannot be zero`));if(i===1&&s===1)return O(n);let l=UD(r),u=UD(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=fk(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 GA(d,{unsafe:!0})}finally{for(let e of f)e[Symbol.dispose]()}}var S0=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 C0(e){if(A(e))throw new S0(e.error);return e.value}function w0(e){return e}function T0(e){return e}function E0(e){return e}function D0(e){return e}function O0(e){return{val:e,__wrapped:!0,translate:t=>R0(j1(e,t)),rotate:(t,n)=>R0(M1(e,t,n)),mirror:t=>R0(N1(e,t)),scale:(t,n)=>R0(P1(e,t,n)),applyMatrix:t=>R0(C0(I1(e,t))),moveX:t=>R0(j1(e,[t,0,0])),moveY:t=>R0(j1(e,[0,t,0])),moveZ:t=>R0(j1(e,[0,0,t])),rotateX:t=>R0(M1(e,t,{axis:[1,0,0]})),rotateY:t=>R0(M1(e,t,{axis:[0,1,0]})),rotateZ:t=>R0(M1(e,t,{axis:[0,0,1]})),bounds:()=>wD(e),describe:()=>s0(e),clone:()=>R0(C0(F1(e))),mesh:t=>a0(e,t),meshEdges:t=>o0(e,t),isValid:()=>u0(e),isEmpty:()=>d0(e),heal:()=>R0(C0(r0(e))),simplify:()=>R0(C0(i0(e))),toBREP:()=>C0(c0(e)),apply:t=>R0(t(e)),applyResult:t=>R0(C0(t(e))),done:()=>e}}function k0(e){return{fuse:(t,n)=>z0(C0(z1(e,$(t),{...n,unsafe:!0}))),cut:(t,n)=>z0(C0(B1(e,$(t),{...n,unsafe:!0}))),intersect:(t,n)=>z0(C0(U1(e,$(t),{...n,unsafe:!0}))),fuseAll:(t,n)=>z0(D0(C0(GA([e,...t.map($)],{...n,unsafe:!0})))),cutAll:(t,n)=>z0(D0(C0(KA(e,t,{...n,unsafe:!0})))),section:(t,n)=>R0(C0(W1(e,t,n))),split:t=>R0(C0(K1(e,t))),slice:(t,n)=>C0(q1(e,t,n))}}function A0(e){return{fillet(...t){return t.length===1?z0(D0(C0(Z1(w0(e),t[0])))):z0(D0(C0(Z1(w0(e),t[0],t[1]))))},chamfer(...t){return t.length===1?z0(D0(C0(Q1(w0(e),t[0])))):z0(D0(C0(Q1(w0(e),t[0],t[1]))))},shell:(t,n,r)=>z0(D0(C0($1(w0(e),t,n,r)))),offset:(t,n)=>z0(D0(C0(e0(w0(e),t,n)))),draft:(t,n)=>z0(D0(C0(n0(w0(e),t,n))))}}function j0(e){return{drill:t=>z0(C0(_0(e,t))),pocket:t=>z0(C0(v0(e,t))),boss:t=>z0(C0(y0(e,t))),mirrorJoin:t=>z0(C0(b0(e,t))),rectangularPattern:t=>z0(C0(x0(e,t)))}}function M0(e){return{volume:()=>C0(HM(e)),area:()=>C0(UM(e)),volumeProps:()=>C0(zM(e)),surfaceProps:()=>C0(BM(e))}}function N0(e){return{edges:()=>uD(e),faces:()=>dD(e),wires:()=>fD(e),vertices:()=>pD(e)}}function P0(e){return{linearPattern:(t,n,r)=>z0(D0(C0(KP(e,t,n,r)))),circularPattern:(t,n,r)=>z0(D0(C0(qP(e,t,n,r))))}}function F0(e){return{...O0(e),...k0(e),...A0(e),...j0(e),...M0(e),...N0(e),...P0(e)}}function I0(e){return{...O0(e),length:()=>Ik(e),startPoint:()=>Mk(e),endPoint:()=>Nk(e),pointAt:t=>Pk(e,t),tangentAt:t=>Fk(e,t),isClosed:()=>Rk(e),sweep(t,n){if(!PE(e))throw Error(`sweep requires a Wire`);let r=C0(xM(E0(e),$(t),n));return z0(Array.isArray(r)?r[0]:r)}}}function L0(e){return{...O0(e),area:()=>C0(UM(e)),normalAt:t=>wO(e,t),center:()=>TO(e),surfaceType:()=>C0(gO(e)),outerWire:()=>OO(e),innerWires:()=>AO(e),extrude:t=>z0(C0(f0(T0(e),t))),revolve:t=>z0(C0(p0(T0(e),t)))}}function R0(e){return zE(e)?F0(e):FE(e)?L0(e):NE(e)||PE(e)?I0(e):O0(e)}function z0(e){return F0(e)}function B0(e){if(e&&typeof e==`object`&&`face`in e&&typeof e.face==`function`&&`_defaultOrigin`in e)return L0(e.face());if(e&&typeof e==`object`&&`wrapped`in e)return FE(e)?L0(e):zE(e)?F0(e):NE(e)||PE(e)?I0(e):O0(e);throw Error(`shape() requires a Sketch or branded shape type`)}var V0=.25,H0=e=>Math.tan(e)-e;function U0(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 W0(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(U0(e,s*t,n,i))}return a}function G0(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 q0(e,t,n){if(t===0)return O(e);let r=H0(e)+2*t*Math.tan(e)/n,i,a;if(r>H0(e)?(i=e,a=Math.PI/2-1e-6):(i=1e-4,a=e),r>H0(a)||r<H0(i))return k(P(`GEAR_PA_OUT_OF_RANGE`,`working pressure angle out of range — target inv(αw)=${r.toFixed(4)} not in [${H0(i).toFixed(4)}, ${H0(a).toFixed(4)}]`,void 0,{target:r,invLo:H0(i),invHi:H0(a)}));for(let e=0;e<50;e++){let e=.5*(i+a);H0(e)<r?i=e:a=e}return O(.5*(i+a))}function J0(e,t,n,r,i){return q0(e,t+n,r+i)}function Y0(e,t,n,r,i){return q0(e,n-t,i-r)}function X0(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(P(`GEAR_NON_INTEGER_TEETH`,`tooth counts and planet count must be integers`));if(e<4||t<4||n<2)return k(P(`GEAR_TEETH_TOO_FEW`,`zs ≥ 4, zp ≥ 4, N ≥ 2 required`));if((2*e+2*t)%n!=0)return k(P(`GEAR_ASSEMBLY`,`(2·zs + 2·zp) must be divisible by N — got ${2*e+2*t} mod ${n} = ${(2*e+2*t)%n}`));let i=t+2+2*r,a=(e+t)*Math.sin(Math.PI/n);return a<=i?k(P(`GEAR_PLANET_COLLISION`,`planet tips would collide: (zs+zp)·sin(π/N) = ${a.toFixed(3)} ≤ planet tip = ${i.toFixed(3)}`)):O(void 0)}function Q0(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 $0(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 e2(e,t){return 1-e*Math.sin(t)*Math.sin(t)/2}function t2(e,t,n){return Math.max(0,e2(e,t)-n)}function n2(e){return e<8?.2:.485-2.88/e}function r2(e,t,n,r){let i=e*1e3,a=n2(r);return a<=0||n<=0||t<=0?1/0:2*i/(r*t*t*n*a)}function i2(e,t,n=!1){let r=(1.4+6.5/e)*(20/(t*180/Math.PI))**.15;return n?r*.85:r}function a2(e,t,n,r,i,a=!1){return r2(e,t,n,r)*i2(r,i,a)}function o2(e){return e/2}function s2(e,t){return e+2*t}function c2(e){return e%2==0?Math.PI/e:0}function l2(e,t,n){return e*(1+t/n)+c2(n)}function u2(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=J0(a,o,s,n,r);if(A(l))return l;let u=X0(n,r,t,a,l.value),d=[];for(let e=0;e<i;e++){let t=e*2*Math.PI/i,a=l2(t,n,r);d.push({rotationDeg:a*180/Math.PI,position:[u*Math.cos(t),u*Math.sin(t),0]})}return O(d)}function d2(e,t,n,r,i){let a=t*e.toothPitch,o=(t+1)%n*e.toothPitch,s=H0(e.alphaPitch),c=a-e.halfToothAngle-s,l=a+e.halfToothAngle+s,u=W0(e.rb,e.alphaTip,c,r,1),d=W0(e.rb,e.alphaTip,l,r,-1).reverse(),f=vA(u),p=yA(u),m=vA(d),h=yA(d),g=[],_=e=>{i.register(e),g.push(e)},v=e.isInternal?e.rb<e.rRoot:e.rb>e.rRoot;v&&_(SA([e.rRoot*Math.cos(c),e.rRoot*Math.sin(c),0],f));let y=e.rPitch*1e-5,b=kA(u,{tolerance:y});if(A(b))return b;_(b.value),_(EA(p,[e.rTip*Math.cos(a),e.rTip*Math.sin(a),0],m));let x=kA(d,{tolerance:y});if(A(x))return x;_(x.value),v&&_(SA(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),_(EA(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 f2(e){return m2(e,!1)}function p2(e){return m2(e,!0)}function m2(e,t){try{var n=IT();let{teeth:r,moduleSize:i,pressureAngle:a,shift:o,clearance:s,flankThinning:c,samples:l=G0(i)}=e;if(r<4)return k(P(`GEAR_TEETH_TOO_FEW`,`gear needs ≥ 4 teeth, got ${r}`));if(i<=0)return k(P(`GEAR_MODULE_NONPOSITIVE`,`module must be > 0, got ${i}`));let u=K0(r,i,a,o,s,c,t),d=n.u(new XT),f=[];for(let e=0;e<r;e++){let t=d2(u,e,r,l,d);if(A(t))return t;f.push(...t.value)}let p=MA(f);return A(p)?p:O(p.value)}catch(e){n.e=e}finally{n.d()}}function h2(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=V0,flankThinning:s=0,bore:c=0,samples:l}=e;if(r<=0)return k(P(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));if(l!==void 0&&(!Number.isInteger(l)||l<1))return k(P(`GEAR_SAMPLES_INVALID`,`samples must be a positive integer; got ${String(l)}`));let u=i*Math.PI/180,d=K0(t,n,u,a,o,s,!1);if(c>0&&c>=2*d.rRoot)return k(P(`GEAR_BORE_TOO_LARGE`,`bore diameter ${c.toFixed(2)} ≥ root diameter ${(2*d.rRoot).toFixed(2)} — would erase the gear teeth`));let f=f2({teeth:t,moduleSize:n,pressureAngle:u,shift:a,clearance:o,flankThinning:s,...l===void 0?{}:{samples:l}});if(A(f))return f;let p=_2(t,u,a);return S2(f.value,r,c,d,p)}function g2(e){let{teeth:t,moduleSize:n,thickness:r,pressureAngleDeg:i=20,shift:a=0,clearance:o=V0,flankThinning:s=0,ringWallThickness:c=2*e.moduleSize,samples:l}=e;if(r<=0)return k(P(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));if(c<=0)return k(P(`GEAR_WALL_NONPOSITIVE`,`ringWallThickness must be > 0`));if(l!==void 0&&(!Number.isInteger(l)||l<1))return k(P(`GEAR_SAMPLES_INVALID`,`samples must be a positive integer; got ${String(l)}`));let u=i*Math.PI/180,d=p2({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=x2(f.rPitch+c);return A(p)?p:w2(p.value,d.value,r,f,[])}function _2(e,t,n){let r=t2(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 v2(e){let t=b2(e);if(A(t))return t;let n=t.value,r=y2(n);if(A(r))return r;let{sun:i,planet:a,ring:o}=r.value,s=O2(n,i,a,o),c=E2(a.solid,n);a.solid.delete();let l=D2(o.solid,n.zr),u=k2(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 y2(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=h2({...n,teeth:e.sunTeeth,shift:e.sunShift,bore:e.sunBore});if(A(r))return r;let i=h2({...n,teeth:e.planetTeeth,shift:e.planetShift,bore:e.planetBore});if(A(i))return r.value.solid.delete(),i;let a=g2({...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 b2(e){let t=e.moduleSize??3,n=e.sunTeeth??15,r=e.planetTeeth??12,i=e.numPlanets??3,a=e.pressureAngleDeg??20,o=a*Math.PI/180,s=e.sunShift??0,c=e.planetShift??0,l=e.ringShift??0;if(e.thickness<=0)return k(P(`GEAR_THICKNESS_NONPOSITIVE`,`thickness must be > 0`));let u=Z0(n,r,i,c);if(A(u))return u;let d=s2(n,r),f=J0(o,s,c,n,r);if(A(f))return f;let p=Y0(o,c,l,r,d);if(A(p))return p;let m=X0(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:o2(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 x2(e){try{var t=IT();let n=MA([t.u(new XT).register(CA(e,[0,0,0],[0,0,1]))]);return A(n)?n:O(n.value)}catch(e){t.e=e}finally{t.d()}}function S2(e,t,n,r,i){try{var a=IT();let o=a.u(new XT);o.register(e);let s=NA(e);if(A(s))return s;o.register(s.value);let c=kM(s.value,[0,0,t]);if(A(c))return c;if(n<=0)return O(T2(c.value,r,i));let l=a.u(new XT);l.register(c.value);let u=C2(n/2);if(A(u))return u;l.register(u.value);let d=kM(u.value,[0,0,t+1]);if(A(d))return d;l.register(d.value);let f=l.register(fk(d.value,[0,0,-.5])),p=HA(c.value,f);return A(p)?p:O(T2(p.value,r,i))}catch(e){a.e=e}finally{a.d()}}function C2(e){let t=x2(e);return A(t)?t:NA(t.value)}function w2(e,t,n,r,i){let a=NA(e,[t]);if(A(a))return a;let o=kM(a.value,[0,0,n]);return A(o)?o:O(T2(o.value,r,i))}function T2(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 E2(e,t){let n=[];try{for(let r=0;r<t.numPlanets;r++){let i=r*2*Math.PI/t.numPlanets,a=pk(e,l2(i,t.sunTeeth,t.planetTeeth)*180/Math.PI);try{let e=[t.centerDistance*Math.cos(i),t.centerDistance*Math.sin(i),0];n.push(fk(a,e))}finally{a.delete()}}return n}catch(e){for(let e of n)e.delete();throw e}}function D2(e,t){let n=c2(t);if(n===0)return e;let r=pk(e,n*180/Math.PI);return e.delete(),r}function O2(e,t,n,r){let i={crSunPlanet:Q0(t.tipDiameter/2,t.baseDiameter/2,n.tipDiameter/2,n.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_sp),crPlanetRing:$0(n.tipDiameter/2,n.baseDiameter/2,r.tipDiameter/2,r.baseDiameter/2,e.centerDistance,e.moduleSize,e.alpha,e.alphaW_pr),undercutSun:t2(e.sunTeeth,e.alpha,e.sunShift),undercutPlanet:t2(e.planetTeeth,e.alpha,e.planetShift)};if(e.appliedTorque!==void 0){let t=e.appliedTorque;i.lewisStress={sun:a2(t,e.moduleSize,e.thickness,e.sunTeeth,e.alpha),planet:a2(t*e.planetTeeth/e.sunTeeth,e.moduleSize,e.thickness,e.planetTeeth,e.alpha),ring:a2(t*e.zr/e.sunTeeth,e.moduleSize,e.thickness,e.zr,e.alpha,!0)},i.stressConcentrationFactor={sun:i2(e.sunTeeth,e.alpha),planet:i2(e.planetTeeth,e.alpha),ring:i2(e.zr,e.alpha,!0)}}return i}function k2(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 A2=LX({addHoles:()=>HP,bezier:()=>kP,box:()=>gP,bsplineApprox:()=>OP,circle:()=>CP,compound:()=>RP,cone:()=>yP,cylinder:()=>_P,ellipse:()=>wP,ellipseArc:()=>DP,ellipsoid:()=>xP,face:()=>NP,fill:()=>PA,filledFace:()=>PP,helix:()=>TP,line:()=>SP,offsetFace:()=>BP,polygon:()=>IP,polyhedron:()=>XQ,sewShells:()=>VP,solid:()=>zP,sphere:()=>vP,subFace:()=>FP,tangentArc:()=>AP,threePointArc:()=>EP,torus:()=>bP,vertex:()=>LP,wire:()=>jP,wireLoop:()=>MP}),j2=LX({checkBoolean:()=>Ij,convexHull:()=>GQ,cut:()=>B1,cutAll:()=>KA,cutAllBisect:()=>Dj,fuse:()=>z1,fuseAll:()=>GA,fuseAllBisect:()=>jj,hull:()=>WQ,intersect:()=>U1,minkowski:()=>YQ,section:()=>W1,sectionToFace:()=>G1,slice:()=>q1,split:()=>K1}),M2=LX({chamfer:()=>Q1,draft:()=>n0,fillet:()=>Z1,heal:()=>r0,offset:()=>e0,shell:()=>$1,simplify:()=>i0,thicken:()=>t0,variableFillet:()=>sM}),N2=LX({applyMatrix:()=>I1,clone:()=>F1,composeTransforms:()=>xk,mirror:()=>N1,rotate:()=>M1,scale:()=>P1,transformCopy:()=>L1,translate:()=>j1}),P2=LX({checkAllInterferences:()=>s1,checkInterference:()=>o1,createDistanceQuery:()=>qM,measureArea:()=>UM,measureCurvatureAt:()=>JM,measureCurvatureAtMid:()=>YM,measureDistance:()=>GM,measureDistanceProps:()=>KM,measureLength:()=>WM,measureLinearProps:()=>VM,measureSurfaceProps:()=>BM,measureVolume:()=>HM,measureVolumeProps:()=>zM}),F2=LX({blueprintToDXF:()=>TY,exportAssemblySTEP:()=>GP,exportDXF:()=>wY,exportGlb:()=>dY,exportGltf:()=>uY,exportIGES:()=>lA,exportOBJ:()=>eY,exportSTEP:()=>sA,exportSTEPConfigured:()=>cX,exportSTL:()=>cA,exportThreeMF:()=>WY,importDXF:()=>f1,importGLB:()=>k1,importIGES:()=>dX,importOBJ:()=>g1,importSTEP:()=>lX,importSTL:()=>uX,importSVG:()=>sX,importSVGPathD:()=>oX,importThreeMF:()=>O1}),I2=LX({cornerFinder:()=>wR,edgeFinder:()=>JI,faceFinder:()=>ZI,getSingleFace:()=>eL,vertexFinder:()=>KX,wireFinder:()=>$I}),L2=LX({complexExtrude:()=>CM,extrude:()=>f0,guidedSweep:()=>OM,loft:()=>m0,multiSectionSweep:()=>DM,revolve:()=>p0,roof:()=>y$,supportExtrude:()=>SM,surfaceFromGrid:()=>zQ,surfaceFromImage:()=>HQ,sweep:()=>xM,twistExtrude:()=>wM}),R2=LX({circularPattern:()=>qP,linearPattern:()=>KP}),z2=14695981039346656037n,B2=1099511628211n,V2=18446744073709551615n;function H2(){return z2}function U2(e,t){return(e^BigInt(t&255))*B2&V2}function W2(e,t){let n=e;for(let e=0;e<t.length;e++)n=U2(n,t[e]??0);return n}var G2=new TextEncoder;function K2(e,t){return W2(e,G2.encode(t))}var q2=new ArrayBuffer(8),J2=new DataView(q2),Y2=new Uint8Array(q2);function X2(e,t){return J2.setFloat64(0,Object.is(t,-0)?0:t),W2(e,Y2)}function Z2(e,t){let n=e,r=t&V2;for(let e=0;e<8;e++)n=U2(n,Number(r&255n)),r>>=8n;return n}function Q2(e,t){let n=e,r=t|0;for(let e=0;e<4;e++)n=U2(n,r&255),r>>>=8;return n}function $2(e,t){return U2(e,+!!t)}function e4(e){return(e&V2).toString(16).padStart(16,`0`)}var t4=new Set;function n4(e){return K2(H2(),e)}function r4(e){return{kind:`NumLit`,value:e,structuralHash:X2(n4(`NumLit`),e),freeParams:t4}}function i4(e){let t=n4(`Vec3Lit`);for(let n of e)t=X2(t,n);return{kind:`Vec3Lit`,value:e,structuralHash:t,freeParams:t4}}function a4(e){let t=n4(`Vec2Lit`);for(let n of e)t=X2(t,n);return{kind:`Vec2Lit`,value:e,structuralHash:t,freeParams:t4}}function o4(e){return{kind:`Param`,name:e,structuralHash:K2(n4(`Param`),e),freeParams:new Set([e])}}function s4(e,t,n){let r=K2(n4(`BinOp`),e);return r=Z2(r,t.structuralHash),r=Z2(r,n.structuralHash),{kind:`BinOp`,op:e,a:t,b:n,structuralHash:r,freeParams:_4(t.freeParams,n.freeParams)}}function c4(e,t){let n=K2(n4(`UnaryOp`),e);return n=Z2(n,t.structuralHash),{kind:`UnaryOp`,op:e,arg:t,structuralHash:n,freeParams:t.freeParams}}function l4(e,t){let n=Q2(n4(`Component`),t);return n=Z2(n,e.structuralHash),{kind:`Component`,vec:e,index:t,structuralHash:n,freeParams:e.freeParams}}function u4(e,t){let n=Q2(n4(`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 d4=(e,t)=>s4(`+`,e,t),f4=(e,t)=>s4(`*`,e,t);function p4(e){return typeof e==`number`?r4(e):e}function m4(e,t){if(!Array.isArray(e))return e;let n=e;return n.every(e=>typeof e==`number`)?t===3?i4([n[0],n[1],n[2]]):a4([n[0],n[1]]):u4(t,n.map(p4))}function h4(e){return m4(e,3)}function g4(e){return m4(e,2)}function _4(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 v4(e){return typeof e==`number`}function y4(e,t){return v4(e)?O(e):k(P(M.NULL_SHAPE_INPUT,`${t}: expected number, got ${Array.isArray(e)?`vector(${e.length})`:typeof e}`))}function b4(e,t,n){return Array.isArray(e)&&e.length===t?O(e):k(P(M.NULL_SHAPE_INPUT,`${n}: expected Vec${t}, got ${v4(e)?`number`:`vector(${e.length})`}`))}function x4(e,t){switch(e.kind){case`NumLit`:return O(e.value);case`Vec3Lit`:return O(e.value);case`Vec2Lit`:return O(e.value);case`Param`:{let n=t[e.name];return n===void 0?k(P(M.NULL_SHAPE_INPUT,`unbound param: ${e.name}`)):O(n)}case`BinOp`:return S4(e,t);case`UnaryOp`:return C4(e,t);case`Component`:return w4(e,t);case`BuildVec`:return T4(e,t)}}function S4(e,t){let n=x4(e.a,t);if(!n.ok)return n;let r=x4(e.b,t);if(!r.ok)return r;let i=y4(n.value,`BinOp(${e.op}).a`);if(!i.ok)return i;let a=y4(r.value,`BinOp(${e.op}).b`);if(!a.ok)return a;switch(e.op){case`+`:return O(i.value+a.value);case`-`:return O(i.value-a.value);case`*`:return O(i.value*a.value);case`/`:return a.value===0?k(P(M.NULL_SHAPE_INPUT,`BinOp(/): division by zero`)):O(i.value/a.value)}}function C4(e,t){let n=x4(e.arg,t);if(!n.ok)return n;let r=y4(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 w4(e,t){let n=x4(e.vec,t);if(!n.ok)return n;if(v4(n.value))return k(P(M.NULL_SHAPE_INPUT,`Component: cannot index a scalar`));let r=n.value,i=r[e.index];return i===void 0?k(P(M.NULL_SHAPE_INPUT,`Component: index ${e.index} out of range for Vec${r.length}`)):O(i)}function T4(e,t){if(e.components.length!==e.dim)return k(P(M.NULL_SHAPE_INPUT,`BuildVec(${e.dim}): expected ${e.dim} components, got ${e.components.length}`));let n=[];for(let r of e.components){let e=x4(r,t);if(!e.ok)return e;let i=y4(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 E4(e,t,n){let r=x4(e,t);return r.ok?y4(r.value,n):r}function D4(e,t,n){let r=x4(e,t);if(!r.ok)return r;let i=b4(r.value,3,n);if(!i.ok)return i;let[a,o,s]=i.value;return O([a,o,s])}function O4(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 k4=new Set;function A4(e){return K2(H2(),e)}function j4(e,t){return Z2(e,t.structuralHash)}function M4(e,t){return t===void 0?$2(e,!1):j4($2(e,!0),t)}function N4(e,t){return t===void 0?$2(e,!1):X2($2(e,!0),t)}function P4(...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?k4:t}function F4(e,t,n){let r=p4(e),i=p4(t),a=p4(n),o=A4(`Box`);return o=j4(j4(j4(o,r),i),a),{kind:`Box`,x:r,y:i,z:a,structuralHash:o,freeParams:P4(r,i,a)}}function I4(e){let t=p4(e);return{kind:`Sphere`,radius:t,structuralHash:j4(A4(`Sphere`),t),freeParams:t.freeParams}}function L4(e,t){let n=p4(e),r=p4(t);return{kind:`Cylinder`,radius:n,height:r,structuralHash:j4(j4(A4(`Cylinder`),n),r),freeParams:P4(n,r)}}function R4(e,t,n){let r=p4(e),i=p4(t),a=p4(n),o=A4(`Cone`);return o=j4(j4(j4(o,r),i),a),{kind:`Cone`,radius1:r,radius2:i,height:a,structuralHash:o,freeParams:P4(r,i,a)}}function z4(e,t){let n=p4(e),r=p4(t);return{kind:`Torus`,majorRadius:n,minorRadius:r,structuralHash:j4(j4(A4(`Torus`),n),r),freeParams:P4(n,r)}}function B4(e){let t=e.map(h4),n=Q2(A4(`Polygon`),t.length);for(let e of t)n=j4(n,e);return{kind:`Polygon`,points:t,structuralHash:n,freeParams:P4(...t)}}function V4(e){let t=p4(e);return{kind:`Circle`,radius:t,structuralHash:j4(A4(`Circle`),t),freeParams:t.freeParams}}function H4(e,t){let n=h4(e),r=h4(t);return{kind:`Line`,from:n,to:r,structuralHash:j4(j4(A4(`Line`),n),r),freeParams:P4(n,r)}}function U4(e){let t=h4(e);return{kind:`Vertex`,point:t,structuralHash:j4(A4(`Vertex`),t),freeParams:t.freeParams}}function W4(e){return{kind:`Empty`,output:e,structuralHash:K2(A4(`Empty`),e),freeParams:k4}}function G4(){return W4(`Solid`)}function K4(){return W4(`Face`)}function q4(){return W4(`Wire`)}function J4(e,t,n,r){return N4(j4(j4(A4(e),t),n),r)}function Y4(e,t,n){return{kind:`Fuse`,a:e,b:t,tolerance:n,structuralHash:J4(`Fuse`,e,t,n),freeParams:P4(e,t)}}function X4(e,t,n){return{kind:`Cut`,a:e,b:t,tolerance:n,structuralHash:J4(`Cut`,e,t,n),freeParams:P4(e,t)}}function Z4(e,t,n){return{kind:`Intersect`,a:e,b:t,tolerance:n,structuralHash:J4(`Intersect`,e,t,n),freeParams:P4(e,t)}}function Q4(e,t){let n=Q2(A4(`FuseAll`),e.length);for(let t of e)n=j4(n,t);return n=N4(n,t),{kind:`FuseAll`,shapes:e,tolerance:t,structuralHash:n,freeParams:P4(...e)}}function $4(e,t,n){let r=j4(A4(`CutAll`),e);r=Q2(r,t.length);for(let e of t)r=j4(r,e);return r=N4(r,n),{kind:`CutAll`,base:e,tools:t,tolerance:n,structuralHash:r,freeParams:P4(e,...t)}}function e3(e){return e===void 0?void 0:h4(e)}function t3(e,t){let n=h4(t);return{kind:`Translate`,target:e,vector:n,structuralHash:j4(j4(A4(`Translate`),e),n),freeParams:P4(e,n)}}function n3(e,t,n){let r=p4(t),i=e3(n?.axis),a=e3(n?.at),o=j4(j4(A4(`Rotate`),e),r);return o=M4(o,i),o=M4(o,a),{kind:`Rotate`,target:e,angle:r,axis:i,at:a,structuralHash:o,freeParams:P4(e,r,i,a)}}function r3(e,t,n){let r=p4(t),i=e3(n?.center),a=j4(j4(A4(`Scale`),e),r);return a=M4(a,i),{kind:`Scale`,target:e,factor:r,center:i,structuralHash:a,freeParams:P4(e,r,i)}}function i3(e,t){let n=e3(t?.normal),r=e3(t?.at),i=j4(A4(`Mirror`),e);return i=M4(i,n),i=M4(i,r),{kind:`Mirror`,target:e,normal:n,at:r,structuralHash:i,freeParams:P4(e,n,r)}}function a3(e){let t=Q2(A4(`Compound`),e.length);for(let n of e)t=j4(t,n);return{kind:`Compound`,children:e,structuralHash:t,freeParams:P4(...e)}}function o3(e,t,n=!1){let r=t.map(e=>e.map(e=>[...e])),i=Q2($2(j4(A4(`Instance`),e),n),r.length);for(let e of r)for(let t of e.flat())i=X2(i,t);return{kind:`Instance`,source:e,placements:r,fuse:n,structuralHash:i,freeParams:P4(e)}}function s3(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 s3(e.a);case`FuseAll`:return e.shapes[0]?s3(e.shapes[0]):`Solid`;case`CutAll`:return s3(e.base);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return s3(e.target);case`Compound`:return`Compound`;case`Instance`:return e.fuse?`Solid`:`Compound`}}function c3(e,t){let n=E4(e.x,t.env,`Box.x`);if(!n.ok)return n;let r=E4(e.y,t.env,`Box.y`);if(!r.ok)return r;let i=E4(e.z,t.env,`Box.z`);return i.ok?O(gP(n.value,r.value,i.value)):i}function l3(e,t){let n=E4(e.radius,t.env,`Sphere.radius`);return n.ok?O(vP(n.value)):n}function u3(e,t){let n=E4(e.radius,t.env,`Cylinder.radius`);if(!n.ok)return n;let r=E4(e.height,t.env,`Cylinder.height`);return r.ok?O(_P(n.value,r.value)):r}function d3(e,t){let n=E4(e.radius1,t.env,`Cone.radius1`);if(!n.ok)return n;let r=E4(e.radius2,t.env,`Cone.radius2`);if(!r.ok)return r;let i=E4(e.height,t.env,`Cone.height`);return i.ok?O(yP(n.value,r.value,i.value)):i}function f3(e,t){let n=E4(e.majorRadius,t.env,`Torus.majorRadius`);if(!n.ok)return n;let r=E4(e.minorRadius,t.env,`Torus.minorRadius`);return r.ok?O(bP(n.value,r.value)):r}function p3(e,t){let n=[];for(let r of e.points){let e=D4(r,t.env,`Polygon.point`);if(!e.ok)return e;n.push(e.value)}return IP(n)}function m3(e,t){let n=E4(e.radius,t.env,`Circle.radius`);return n.ok?O(CP(n.value)):n}function h3(e,t){let n=D4(e.from,t.env,`Line.from`);if(!n.ok)return n;let r=D4(e.to,t.env,`Line.to`);return r.ok?O(SP(n.value,r.value)):r}function g3(e,t){let n=D4(e.point,t.env,`Vertex.point`);return n.ok?O(LP(n.value)):n}function _3(e){return k(Eo(M.NULL_SHAPE_INPUT,`${e}: empty result has no kernel representation`))}function v3(e,t,n){let r=e.evalNode(t);return r.ok?zE(r.value)?O(r.value):k(Co(M.CSG_NOT_3D,`${n}: operand did not produce a 3D shape`)):r}function y3(e,t){return{unsafe:!0,fuzzyValue:e.tolerance??t.tolerance}}function b3(e,t){if(e.a.kind===`Empty`)return t.evalNode(e.b);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=v3(t,e.a,`Fuse.a`);if(!n.ok)return n;let r=v3(t,e.b,`Fuse.b`);return r.ok?VA(n.value,r.value,y3(e,t)):r}function x3(e,t){if(e.a.kind===`Empty`)return _3(`Cut`);if(e.b.kind===`Empty`)return t.evalNode(e.a);let n=v3(t,e.a,`Cut.a`);if(!n.ok)return n;let r=v3(t,e.b,`Cut.b`);return r.ok?HA(n.value,r.value,y3(e,t)):r}function S3(e,t){if(e.a.kind===`Empty`||e.b.kind===`Empty`)return _3(`Intersect`);let n=v3(t,e.a,`Intersect.a`);if(!n.ok)return n;let r=v3(t,e.b,`Intersect.b`);return r.ok?UA(n.value,r.value,y3(e,t)):r}function C3(e,t,n){let r=[];for(let i of t){let t=v3(e,i,n);if(!t.ok)return t;r.push(t.value)}return O(r)}function w3(e,t){let n=e.shapes.filter(e=>e.kind!==`Empty`);if(n.length===0)return _3(`FuseAll`);if(n.length===1&&n[0])return t.evalNode(n[0]);let r=C3(t,n,`FuseAll.operand`);return r.ok?GA(r.value,y3(e,t)):r}function T3(e,t){if(e.base.kind===`Empty`)return _3(`CutAll`);let n=e.tools.filter(e=>e.kind!==`Empty`);if(n.length===0)return t.evalNode(e.base);let r=v3(t,e.base,`CutAll.base`);if(!r.ok)return r;let i=C3(t,n,`CutAll.tool`);return i.ok?KA(r.value,i.value,y3(e,t)):i}function E3(e){return k(Eo(M.NULL_SHAPE_INPUT,`${e}: cannot transform an Empty node`))}function D3(e,t,n,r){return e?D4(e,t,n):O(r)}function O3(e,t){let n=H(),{handle:r,dispose:i}=n.composeTransform(t),a;try{a=VE(n.locate(e.wrapped,r))}finally{i()}return sk(e)&&dk(e,a),a}function k3(e,t){if(e.target.kind===`Empty`)return E3(`Translate`);let n=D4(e.vector,t.env,`Translate.vector`);if(!n.ok)return n;let r=t.evalNode(e.target);return r.ok?O(O3(r.value,[{type:`translate`,x:n.value[0],y:n.value[1],z:n.value[2]}])):r}function A3(e,t){if(e.target.kind===`Empty`)return E3(`Rotate`);let n=E4(e.angle,t.env,`Rotate.angle`);if(!n.ok)return n;let r=D3(e.axis,t.env,`Rotate.axis`,[0,0,1]);if(!r.ok)return r;let i=D3(e.at,t.env,`Rotate.at`,[0,0,0]);if(!i.ok)return i;let a=t.evalNode(e.target);return a.ok?O(O3(a.value,[{type:`rotate`,angle:n.value,axis:r.value,center:i.value}])):a}function j3(e,t){if(e.target.kind===`Empty`)return E3(`Scale`);let n=E4(e.factor,t.env,`Scale.factor`);if(!n.ok)return n;let r=D3(e.center,t.env,`Scale.center`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(hk(i.value,n.value,r.value)):i}function M3(e,t){if(e.target.kind===`Empty`)return E3(`Mirror`);let n=D3(e.normal,t.env,`Mirror.normal`,[1,0,0]);if(!n.ok)return n;let r=D3(e.at,t.env,`Mirror.at`,[0,0,0]);if(!r.ok)return r;let i=t.evalNode(e.target);return i.ok?O(mk(i.value,n.value,r.value)):i}function N3(e,t){let n=e.children.filter(e=>e.kind!==`Empty`);if(n.length===0)return k(Eo(M.NULL_SHAPE_INPUT,`Compound: cannot materialize a compound with zero non-empty children`));let r=[];for(let e of n){let n=t.evalNode(e);if(!n.ok)return n;r.push(n.value)}return O(RP(r))}function P3(){return k(Eo(M.NULL_SHAPE_INPUT,`Empty: cannot materialize an Empty node directly — only valid as boolean/transform operand`))}function F3(e,t){let n=t.evalNode(e.source);return n.ok?D$(w$(n.value,e.placements),{fuse:e.fuse}):n}function I3(e,t){switch(e.kind){case`Box`:return c3(e,t);case`Sphere`:return l3(e,t);case`Cylinder`:return u3(e,t);case`Cone`:return d3(e,t);case`Torus`:return f3(e,t);case`Polygon`:return p3(e,t);case`Circle`:return m3(e,t);case`Line`:return h3(e,t);case`Vertex`:return g3(e,t);case`Empty`:return P3();case`Fuse`:return b3(e,t);case`Cut`:return x3(e,t);case`Intersect`:return S3(e,t);case`FuseAll`:return w3(e,t);case`CutAll`:return T3(e,t);case`Translate`:return k3(e,t);case`Rotate`:return A3(e,t);case`Scale`:return j3(e,t);case`Mirror`:return M3(e,t);case`Compound`:return N3(e,t);case`Instance`:return F3(e,t)}}function L3(e,t){if(typeof t==`number`)return X2($2(e,!1),t);let n=$2(e,!0);n=Q2(n,t.length);for(let e of t)n=X2(n,e);return n}function R3(e,t){if(t.size===0)return H2();let n=O4(e,t),r=Object.keys(n).sort(),i=H2();for(let e of r){i=K2(i,e);let t=n[e];t!==void 0&&(i=L3(i,t))}return i}function z3(e,t,n,r){let i=R3(t,e.freeParams),a=r===void 0?`d`:X2(H2(),r).toString(16);return`${e4(e.structuralHash)}:${n}:${e4(i)}:${a}`}var B3=[1,0,0,0];function V3(e,t){let n=E4(e.angle,t,`evaluateMesh.peelRigid`);if(!n.ok)return null;let r=e.axis?D4(e.axis,t,`evaluateMesh.peelRigid`):O([0,0,1]);if(!r.ok)return null;let i=e.at?D4(e.at,t,`evaluateMesh.peelRigid`):O([0,0,0]);return i.ok?{angle:n.value,axis:r.value,center:i.value}:null}function H3(e,t){let n=e,r=B3,i=[0,0,0];for(;;)if(n.kind===`Translate`){let e=D4(n.vector,t,`evaluateMesh.peelRigid`);if(!e.ok)break;let a=sF(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=V3(n,t);if(!e)break;let a=cF(e.axis,e.angle*Math.PI/180),o=uF(r,a),s=sF(r,e.center),c=sF(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 U3(e){return e[0]===1&&e[1]===0&&e[2]===0&&e[3]===0}function W3(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 G3(e,t,n){let[r,i,a]=n,o=U3(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;W3(c,s,l,u,d,f,r,i,a);let p=e.normals,m=new Float32Array(p.length);return W3(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 q3=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??TT()??`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 ET(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=Po(),a=n.tolerance??i.tolerance,o=n.angularTolerance??i.angularTolerance,s=`${z3(e,t,this.kernelId,this.defaultTolerance)}|${Kk(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}=H3(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=dD(c.value).map(Ek),u=this.evaluate(e,t);if(!u.ok)return u;let d=dD(u.value).map(Ek),f=G3(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=ET(this.kernelId,()=>nA(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=z3(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=I3(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=IT();let r=t(n.u(new q3(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 Y3(e){return{csgVersion:1,root:t6(e)}}function X3(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:X3(e.a),b:X3(e.b)};case`UnaryOp`:return{kind:`UnaryOp`,op:e.op,arg:X3(e.arg)};case`Component`:return{kind:`Component`,vec:X3(e.vec),index:e.index};case`BuildVec`:return{kind:`BuildVec`,dim:e.dim,components:e.components.map(X3)}}}function Z3(e){switch(e.kind){case`Box`:return{kind:`Box`,x:X3(e.x),y:X3(e.y),z:X3(e.z)};case`Sphere`:return{kind:`Sphere`,radius:X3(e.radius)};case`Cylinder`:return{kind:`Cylinder`,radius:X3(e.radius),height:X3(e.height)};case`Cone`:return{kind:`Cone`,radius1:X3(e.radius1),radius2:X3(e.radius2),height:X3(e.height)};case`Torus`:return{kind:`Torus`,majorRadius:X3(e.majorRadius),minorRadius:X3(e.minorRadius)};case`Polygon`:return{kind:`Polygon`,points:e.points.map(X3)};case`Circle`:return{kind:`Circle`,radius:X3(e.radius)};case`Line`:return{kind:`Line`,from:X3(e.from),to:X3(e.to)};case`Vertex`:return{kind:`Vertex`,point:X3(e.point)};case`Empty`:return{kind:`Empty`,output:e.output};default:return}}function Q3(e){switch(e.kind){case`Fuse`:case`Cut`:case`Intersect`:return{kind:e.kind,a:t6(e.a),b:t6(e.b),tolerance:e.tolerance};case`FuseAll`:return{kind:`FuseAll`,shapes:e.shapes.map(t6),tolerance:e.tolerance};case`CutAll`:return{kind:`CutAll`,base:t6(e.base),tools:e.tools.map(t6),tolerance:e.tolerance};default:return}}function $3(e){return e?X3(e):void 0}function e6(e){switch(e.kind){case`Translate`:return{kind:`Translate`,target:t6(e.target),vector:X3(e.vector)};case`Rotate`:return{kind:`Rotate`,target:t6(e.target),angle:X3(e.angle),axis:$3(e.axis),at:$3(e.at)};case`Scale`:return{kind:`Scale`,target:t6(e.target),factor:X3(e.factor),center:$3(e.center)};case`Mirror`:return{kind:`Mirror`,target:t6(e.target),normal:$3(e.normal),at:$3(e.at)};default:return}}function t6(e){return e.kind===`Compound`?{kind:`Compound`,children:e.children.map(t6)}:e.kind===`Instance`?{kind:`Instance`,source:t6(e.source),placements:e.placements,fuse:e.fuse}:Z3(e)??Q3(e)??e6(e)}function n6(e){return k(P(M.NULL_SHAPE_INPUT,`csg.fromJSON: ${e}`))}function r6(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function i6(e){return typeof e==`number`&&Number.isFinite(e)}function a6(e){return typeof e==`string`}function o6(e,t){if(!Array.isArray(e)||e.length!==3)return n6(`${t}: expected Vec3 array`);let[n,r,i]=e;return!i6(n)||!i6(r)||!i6(i)?n6(`${t}: Vec3 contains non-number`):O([n,r,i])}function s6(e,t){if(!Array.isArray(e)||e.length!==2)return n6(`${t}: expected Vec2 array`);let[n,r]=e;return!i6(n)||!i6(r)?n6(`${t}: Vec2 contains non-number`):O([n,r])}function c6(e){if(!r6(e))return n6(`input is not an object`);let t=e.csgVersion;if(t!==1)return n6(`unsupported csgVersion ${String(t)} (expected 1)`);let n=e.root;return g6(n)}function l6(e){if(!r6(e))return n6(`expression: not an object`);let t=e.kind;switch(t){case`NumLit`:return i6(e.value)?O(r4(e.value)):n6(`NumLit.value`);case`Vec3Lit`:{let t=o6(e.value,`Vec3Lit.value`);return t.ok?O(i4(t.value)):t}case`Vec2Lit`:{let t=s6(e.value,`Vec2Lit.value`);return t.ok?O(a4(t.value)):t}case`Param`:return a6(e.name)?O(o4(e.name)):n6(`Param.name`);case`BinOp`:return u6(e);case`UnaryOp`:return d6(e);case`Component`:return f6(e);case`BuildVec`:return p6(e);default:return n6(`unknown expression kind: ${String(t)}`)}}function u6(e){let t=e.op;if(t!==`+`&&t!==`-`&&t!==`*`&&t!==`/`)return n6(`BinOp.op: ${String(t)}`);let n=l6(e.a);if(!n.ok)return n;let r=l6(e.b);return r.ok?O(s4(t,n.value,r.value)):r}function d6(e){let t=e.op;if(!a6(t)||![`neg`,`sin`,`cos`,`sqrt`,`abs`].includes(t))return n6(`UnaryOp.op: ${String(t)}`);let n=l6(e.arg);return n.ok?O(c4(t,n.value)):n}function f6(e){let t=e.index;if(t!==0&&t!==1&&t!==2)return n6(`Component.index: ${String(t)}`);let n=l6(e.vec);return n.ok?O(l4(n.value,t)):n}function p6(e){let t=e.dim;if(t!==2&&t!==3)return n6(`BuildVec.dim: ${String(t)}`);let n=e.components;if(!Array.isArray(n))return n6(`BuildVec.components: not array`);if(n.length!==t)return n6(`BuildVec.components: expected ${t} components, got ${n.length}`);let r=[];for(let e of n){let t=l6(e);if(!t.ok)return t;r.push(t.value)}return O(u4(t,r))}function m6(e,t){if(!Array.isArray(e))return n6(`${t}: not array`);let n=[];for(let t of e){let e=g6(t);if(!e.ok)return e;n.push(e.value)}return O(n)}function h6(e){let t=e.tolerance;return t==null?O(void 0):i6(t)?O(t):n6(`tolerance: not a finite number`)}function g6(e){if(!r6(e))return n6(`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 v6(t,e);case`Fuse`:case`Cut`:case`Intersect`:return E6(t,e);case`FuseAll`:case`CutAll`:return D6(t,e);case`Translate`:case`Rotate`:case`Scale`:case`Mirror`:return O6(t,e);case`Compound`:return P6(e);case`Instance`:return I6(e);default:return n6(`unknown node kind: ${String(t)}`)}}function _6(e,t,n){let r=l6(e[t]);return r.ok?O(n(r.value)):r}function v6(e,t){switch(e){case`Box`:return y6(t);case`Sphere`:return _6(t,`radius`,I4);case`Cylinder`:return b6(t);case`Cone`:return x6(t);case`Torus`:return S6(t);case`Polygon`:return C6(t);case`Circle`:return _6(t,`radius`,V4);case`Line`:return w6(t);case`Vertex`:return _6(t,`point`,U4);case`Empty`:return T6(t)}return n6(`unhandled primitive: ${e}`)}function y6(e){let t=l6(e.x);if(!t.ok)return t;let n=l6(e.y);if(!n.ok)return n;let r=l6(e.z);return r.ok?O(F4(t.value,n.value,r.value)):r}function b6(e){let t=l6(e.radius);if(!t.ok)return t;let n=l6(e.height);return n.ok?O(L4(t.value,n.value)):n}function x6(e){let t=l6(e.radius1);if(!t.ok)return t;let n=l6(e.radius2);if(!n.ok)return n;let r=l6(e.height);return r.ok?O(R4(t.value,n.value,r.value)):r}function S6(e){let t=l6(e.majorRadius);if(!t.ok)return t;let n=l6(e.minorRadius);return n.ok?O(z4(t.value,n.value)):n}function C6(e){let t=e.points;if(!Array.isArray(t))return n6(`Polygon.points: not array`);let n=[];for(let e of t){let t=l6(e);if(!t.ok)return t;n.push(t.value)}return O(B4(n))}function w6(e){let t=l6(e.from);if(!t.ok)return t;let n=l6(e.to);return n.ok?O(H4(t.value,n.value)):n}function T6(e){let t=e.output;switch(t){case`Solid`:return O(G4());case`Face`:return O(K4());case`Wire`:return O(q4());default:return n6(`Empty.output: ${String(t)}`)}}function E6(e,t){let n=g6(t.a);if(!n.ok)return n;let r=g6(t.b);if(!r.ok)return r;let i=h6(t);if(!i.ok)return i;switch(e){case`Fuse`:return O(Y4(n.value,r.value,i.value));case`Cut`:return O(X4(n.value,r.value,i.value));case`Intersect`:return O(Z4(n.value,r.value,i.value))}}function D6(e,t){let n=h6(t);if(!n.ok)return n;if(e===`FuseAll`){let e=m6(t.shapes,`FuseAll.shapes`);return e.ok?O(Q4(e.value,n.value)):e}let r=g6(t.base);if(!r.ok)return r;let i=m6(t.tools,`CutAll.tools`);return i.ok?O($4(r.value,i.value,n.value)):i}function O6(e,t){let n=g6(t.target);if(!n.ok)return n;switch(e){case`Translate`:return k6(t,n.value);case`Rotate`:return j6(t,n.value);case`Scale`:return M6(t,n.value);case`Mirror`:return N6(t,n.value)}}function k6(e,t){let n=l6(e.vector);return n.ok?O(t3(t,n.value)):n}function A6(e,t){if(e[t]===void 0)return O(void 0);let n=l6(e[t]);return n.ok?O(n.value):n}function j6(e,t){let n=l6(e.angle);if(!n.ok)return n;let r=A6(e,`axis`);if(!r.ok)return r;let i=A6(e,`at`);return i.ok?O(n3(t,n.value,{axis:r.value,at:i.value})):i}function M6(e,t){let n=l6(e.factor);if(!n.ok)return n;let r=A6(e,`center`);return r.ok?O(r3(t,n.value,{center:r.value})):r}function N6(e,t){let n=A6(e,`normal`);if(!n.ok)return n;let r=A6(e,`at`);return r.ok?O(i3(t,{normal:n.value,at:r.value})):r}function P6(e){let t=m6(e.children,`Compound.children`);return t.ok?O(a3(t.value)):t}function F6(e){return Array.isArray(e)&&e.length===4&&e.every(e=>Array.isArray(e)&&e.length===4&&e.every(i6))}function I6(e){let t=g6(e.source);if(!t.ok)return t;let n=e.placements;return!Array.isArray(n)||!n.every(F6)?n6(`Instance.placements must be an array of 4x4 number matrices`):O(o3(t.value,n,e.fuse===!0))}function L6(e){return B6(e)}function R6(e){switch(e.kind){case`NumLit`:case`Vec3Lit`:case`Vec2Lit`:case`Param`:return e;case`BinOp`:{let t=R6(e.a),n=R6(e.b);if(t.kind===`NumLit`&&n.kind===`NumLit`)switch(e.op){case`+`:return r4(t.value+n.value);case`-`:return r4(t.value-n.value);case`*`:return r4(t.value*n.value);case`/`:return r4(t.value/n.value)}return t!==e.a||n!==e.b?s4(e.op,t,n):e}case`UnaryOp`:{let t=R6(e.arg);if(t.kind===`NumLit`){let n=t.value;switch(e.op){case`neg`:return r4(-n);case`sin`:return r4(Math.sin(n));case`cos`:return r4(Math.cos(n));case`sqrt`:return r4(Math.sqrt(n));case`abs`:return r4(Math.abs(n))}}return t===e.arg?e:c4(e.op,t)}case`Component`:{let t=R6(e.vec);return t.kind===`Vec3Lit`||t.kind===`Vec2Lit`&&(e.index===0||e.index===1)?r4(t.value[e.index]):t===e.vec?e:l4(t,e.index)}case`BuildVec`:{let t=e.components.map(R6);return z6(e.dim,t)||(t.some((t,n)=>t!==e.components[n])?u4(e.dim,t):e)}}}function z6(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?a4([n[0],n[1]]):i4([n[0],n[1],n[2]])}function B6(e){switch(e.kind){case`Box`:return F4(R6(e.x),R6(e.y),R6(e.z));case`Sphere`:return I4(R6(e.radius));case`Cylinder`:return L4(R6(e.radius),R6(e.height));case`Cone`:return R4(R6(e.radius1),R6(e.radius2),R6(e.height));case`Torus`:return z4(R6(e.majorRadius),R6(e.minorRadius));case`Polygon`:return B4(e.points.map(R6));case`Circle`:return V4(R6(e.radius));case`Line`:return H4(R6(e.from),R6(e.to));case`Vertex`:return U4(R6(e.point));case`Empty`:return e;case`Fuse`:return V6(e.a,e.b,e.tolerance);case`Cut`:return H6(e.a,e.b,e.tolerance);case`Intersect`:return U6(e.a,e.b,e.tolerance);case`FuseAll`:return W6(e.shapes,e.tolerance);case`CutAll`:return G6(e.base,e.tools,e.tolerance);case`Translate`:return K6(e.target,e.vector);case`Rotate`:return n3(B6(e.target),R6(e.angle),{axis:e.axis?R6(e.axis):void 0,at:e.at?R6(e.at):void 0});case`Scale`:return r3(B6(e.target),R6(e.factor),{center:e.center?R6(e.center):void 0});case`Mirror`:return i3(B6(e.target),{normal:e.normal?R6(e.normal):void 0,at:e.at?R6(e.at):void 0});case`Compound`:return a3(e.children.map(B6).filter(e=>e.kind!==`Empty`));case`Instance`:return o3(B6(e.source),e.placements,e.fuse)}}function V6(e,t,n){let r=B6(e),i=B6(t);return r.kind===`Empty`?i:i.kind===`Empty`?r:Y4(r,i,n)}function H6(e,t,n){let r=B6(e),i=B6(t);return i.kind===`Empty`||r.kind===`Empty`?r:X4(r,i,n)}function U6(e,t,n){let r=B6(e),i=B6(t);return r.kind===`Empty`?r:i.kind===`Empty`?i:Z4(r,i,n)}function W6(e,t){let n=e.map(B6).filter(e=>e.kind!==`Empty`);return n.length===0?G4():n.length===1?n[0]:Q4(n,t)}function G6(e,t,n){let r=B6(e);if(r.kind===`Empty`)return r;let i=t.map(B6).filter(e=>e.kind!==`Empty`);return i.length===0?r:$4(r,i,n)}function K6(e,t){let n=B6(e),r=R6(t);if(r.kind!==`Vec3Lit`)return t3(n,r);let[i,a,o]=r.value;if(i===0&&a===0&&o===0)return n;if(n.kind===`Translate`){let e=R6(n.vector);if(e.kind===`Vec3Lit`)return t3(n.target,[e.value[0]+i,e.value[1]+a,e.value[2]+o])}return t3(n,r)}function q6(e,t,n){return J6(e,t,n)}function J6(e,t,n){return t(e)?n:Y6(e,t,n)}function Y6(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 Y4(J6(e.a,t,n),J6(e.b,t,n),e.tolerance);case`Cut`:return X4(J6(e.a,t,n),J6(e.b,t,n),e.tolerance);case`Intersect`:return Z4(J6(e.a,t,n),J6(e.b,t,n),e.tolerance);case`FuseAll`:return Q4(e.shapes.map(e=>J6(e,t,n)),e.tolerance);case`CutAll`:return $4(J6(e.base,t,n),e.tools.map(e=>J6(e,t,n)),e.tolerance);case`Translate`:return t3(J6(e.target,t,n),e.vector);case`Rotate`:return n3(J6(e.target,t,n),e.angle,{axis:e.axis,at:e.at});case`Scale`:return r3(J6(e.target,t,n),e.factor,{center:e.center});case`Mirror`:return i3(J6(e.target,t,n),{normal:e.normal,at:e.at});case`Compound`:return a3(e.children.map(e=>J6(e,t,n)));case`Instance`:return o3(J6(e.source,t,n),e.placements,e.fuse)}}function X6(e,t){t(e);for(let n of Z6(e))X6(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 Q6(e){let t=0;return X6(e,()=>{t++}),t}var $6=LX({CSG_VERSION:()=>1,Evaluator:()=>q3,add:()=>d4,asScalarExpr:()=>p4,asVec2Expr:()=>g4,asVec3Expr:()=>h4,binOp:()=>s4,box:()=>F4,buildVec:()=>u4,circle:()=>V4,component:()=>l4,compound:()=>a3,cone:()=>R4,cut:()=>X4,cutAll:()=>$4,cylinder:()=>L4,emptyFace:()=>K4,emptySolid:()=>G4,emptyWire:()=>q4,foldExpr:()=>R6,forEachNode:()=>X6,fromJSON:()=>c6,fuse:()=>Y4,fuseAll:()=>Q4,instance:()=>o3,intersect:()=>Z4,line:()=>H4,mirror:()=>i3,mul:()=>f4,nodeCount:()=>Q6,numLit:()=>r4,optimize:()=>L6,outputKindOf:()=>s3,param:()=>o4,polygon:()=>B4,replaceNode:()=>q6,rotate:()=>n3,scale:()=>r3,sphere:()=>I4,toJSON:()=>Y3,torus:()=>z4,translate:()=>t3,unaryOp:()=>c4,vec2Lit:()=>a4,vec3Lit:()=>i4,vertex:()=>U4,withEvaluator:()=>J3});export{vR as BaseSketcher2d,yR as BlueprintSketcher,r as BrepBugError,M as BrepErrorCode,S0 as BrepWrapperError,Ry as BrepkitAdapter,JK as CompoundSketch,o as DEFAULT_CAPABILITIES,JE as DEG2RAD,XT as DisposalScope,a as EXACT_BREP_CAPABILITIES,Dq as FaceSketcher,G as HASH_CODE_MAX,qa as OK,Ka as OcctWasmAdapter,YE as RAD2DEG,uq as Sketch,Eq as Sketcher,dq as Sketches,XP as addChild,HP as addHoles,DF as addJoint,i1 as addMate,cI as addStep,cN as adjacentFaces,no as all,Za as andThen,BX as applyGlue,I1 as applyMatrix,Wk as approximateCurve,oE as as2D,aE as as3D,oO as asTopo,CN as assignRoles,pM as autoHeal,kP as bezier,TY as blueprintToDXF,ij as booleanPipeline,j2 as booleans,y0 as boss,gP as box,OP as bsplineApprox,i as bug,Cq as cameraFromPlane,Sq as cameraLookAt,hN as captureHint,fO as cast,VE as castShape,HE as castShape3D,Q1 as chamfer,Sj as chamferDistAngleShape,Gj as chamferWithEvolution,s1 as checkAllInterferences,Ij as checkBoolean,o1 as checkInterference,CP as circle,qP as circularPattern,DO as classifyPointOnFace,eA as clearMeshCache,F1 as clone,hE as closedWire,mo as collect,nF as collectShapes,rk as colorFaces,nk as colorShape,CM as complexExtrude,xk as composeTransforms,RP as compound,sq as compoundSketchExtrude,aq as compoundSketchFace,lq as compoundSketchLoft,cq as compoundSketchRevolve,Eo as computationError,d$ as computeStraightSkeleton,yP as cone,L2 as construction,GQ as convexHull,wR as cornerFinder,tF as countNodes,WP as createAssembly,YP as createAssemblyNode,zJ as createBlueprint,xq as createCamera,jE as createCompound,BJ as createCompoundBlueprint,nP as createDerivedFaceRef,qM as createDistanceQuery,TE as createEdge,zN as createEdgeRef,DE as createFace,KT as createHandle,sI as createHistory,YT as createKernelHandle,tA as createMeshCache,$D as createNamedPlane,kX as createOperationRegistry,ZD as createPlane,wN as createRef,hI as createRegistry,OE as createShell,kE as createSolid,xX as createTaskQueue,wE as createVertex,qN as createVertexRef,EE as createWire,OX as createWorkerClient,PX as createWorkerHandler,FX as createWorkerPool,$6 as csg,No as currentQuality,jJ as curve2dBoundingBox,RJ as curve2dDistanceFrom,MJ as curve2dFirstPoint,LJ as curve2dIsOnCurve,NJ as curve2dLastPoint,FJ as curve2dParameter,PJ as curve2dSplitAt,IJ as curve2dTangentAt,Lk as curveAxis,Nk as curveEndPoint,Rk as curveIsClosed,zk as curveIsPeriodic,Ik as curveLength,Bk as curvePeriod,Pk as curvePointAt,Mk as curveStartPoint,Fk as curveTangentAt,B1 as cut,uz as cut2D,H1 as cutAll,Dj as cutAllBisect,$R as cutBlueprints,Hj as cutWithEvolution,_P as cylinder,bF as cylindricalJoint,mN as defaultScorer,CX as dequeueTask,s0 as describe,iJ as deserializeDrawing,SI as deserializeHistory,mO as deserializeShape,uO as downcast,n0 as draft,oJ as draw,dJ as drawCircle,fJ as drawEllipse,yJ as drawFaceOutline,gJ as drawParametricFunction,hJ as drawPointsInterpolation,pJ as drawPolysides,vJ as drawProjection,cJ as drawRectangle,sJ as drawRoundedRectangle,lJ as drawSingleCircle,uJ as drawSingleEllipse,mJ as drawText,TJ as drawingChamfer,SJ as drawingCut,wJ as drawingFillet,xJ as drawingFuse,CJ as drawingIntersect,bJ as drawingToSketchOnPlane,_0 as drill,JI as edgeFinder,iN as edgesOfFace,wP as ellipse,DP as ellipseArc,xP as ellipsoid,SX as enqueueTask,k as err,GP as exportAssemblySTEP,wY as exportDXF,dY as exportGlb,uY as exportGltf,lA as exportIGES,eY as exportOBJ,sA as exportSTEP,cX as exportSTEPConfigured,cA as exportSTL,WY as exportThreeMF,nI as exportURDF,f0 as extrude,jM as extrudeAll,NP as face,EO as faceAxis,TO as faceCenter,ZI as faceFinder,_O as faceGeomType,vO as faceOrientation,nN as facesOfEdge,rN as facesOfVertex,NZ as fieldBoolean,LZ as fieldContour,PZ as fieldOffset,IZ as fieldReinit,FZ as fieldShell,PA as fill,PP as filledFace,Z1 as fillet,Wj as filletWithEvolution,GO as findFacesByTag,$P as findNode,uI as findStep,gM as fixSelfIntersection,mM as fixShape,Qa as flatMap,ao as flatten,yO as flipFaceOrientation,Hk as flipOrientation,mX as fontMetrics,jF as forwardKinematics,l0 as fromBREP,MQ as fromKernelDir,jQ as fromKernelPnt,AQ as fromKernelVec,so as fromNullable,z1 as fuse,cz as fuse2D,V1 as fuseAll,jj as fuseAllBisect,QR as fuseBlueprints,Vj as fuseWithEvolution,K0 as gearGeometry,QX as getActiveVoxelId,wD as getBounds,VJ as getBounds2D,gD as getCompSolids,jk as getCurveType,BT as getDisposalStats,uD as getEdges,ak as getFaceColor,MO as getFaceOrigins,KO as getFaceTags,dD as getFaces,mq as getFont,Ek as getHashCode,dI as getHistoryShape,H as getKernel,DT as getKernelCapabilities,jT as getKernelTier,Cj as getNurbsCurveData,wj as getNurbsSurfaceData,Vk as getOrientation,HJ as getOrientation2D,Ho as getPerformanceStats,ik as getShapeColor,uE as getShapeKind,hD as getShells,eL as getSingleFace,mD as getSolids,gO as getSurfaceType,JO as getTagMetadata,pD as getVertices,ZX as getVoxel,fD as getWires,JP as gridPattern,OM as guidedSweep,r0 as heal,uM as healFace,lM as healSolid,dM as healWire,TP as helix,WQ as hull,f1 as importDXF,k1 as importGLB,dX as importIGES,g1 as importOBJ,lX as importSTEP,uX as importSTL,sX as importSVG,oX as importSVGPathD,O1 as importThreeMF,oI as importURDF,FT as init,ST as initFromManifold,NT as initFromOC,$X as initVoxel,AO as innerWires,w$ as instance,E$ as instanceCount,T$ as instanceGrid,k$ as instancedMesh,Uk as interpolateCurve,U1 as intersect,dz as intersect2D,ez as intersectBlueprints,Uj as intersectWithEvolution,lD as invalidateShapeCache,GF as inverseKinematics,F2 as io,Do as ioError,iE as is2D,rE as is3D,vX as isBatchRequest,HX as isChamferRadius,dE as isClosedWire,pO as isCompSolid,RE as isCompound,aP as isDerivedFaceRef,_X as isDisposeRequest,NE as isEdge,oP as isEdgeRef,d0 as isEmpty,kk as isEqualShape,A as isErr,bX as isErrorResponse,FE as isFace,cP as isFaceRef,UX as isFilletRadius,hX as isInitRequest,UJ as isInside2D,C$ as isInstanced,lP as isLineageRef,nE as isLive,pE as isManifoldShell,VX as isNumber,Ja as isOk,gX as isOperationRequest,fE as isOrientedFace,yE as isPlanarFace,bE as isPlanarWire,vq as isProjectionPlane,TX as isQueueEmpty,Ok as isSameShape,BE as isShape1D,zE as isShape3D,IE as isShell,LE as isSolid,yX as isSuccessResponse,u0 as isValid,mE as isValidSolid,ME as isVertex,sP as isVertexRef,PE as isWire,CD as iterCompSolids,_D as iterEdges,vD as iterFaces,SD as iterShells,xD as iterSolids,cO as iterTopo,bD as iterVertices,yD as iterWires,qF as jointTrajectory,EF as jointTransform,XF as jointsFromDH,QE as kernelCall,$E as kernelCallRaw,eD as kernelCallScoped,N as kernelError,wQ as latticeInfill,TQ as latticeInfillShape,SP as line,KP as linearPattern,pq as loadFont,R1 as locate,m0 as loft,NM as loftAll,Lq as makeBaseBox,h2 as makeExternalGear,g2 as makeInternalGear,tO as makePlane,v2 as makePlanetaryGear,bq as makeProjectedEdges,_E as manifoldShell,Ya as map,oo as mapBoth,Xa as mapErr,po as match,D$ as materialize,UM as measureArea,JM as measureCurvatureAt,YM as measureCurvatureAtMid,GM as measureDistance,KM as measureDistanceProps,WM as measureLength,VM as measureLinearProps,BM as measureSurfaceProps,HM as measureVolume,zM as measureVolumeProps,P2 as measurement,MF as mechanismDOF,a0 as mesh,o0 as meshEdges,mA as meshLODs,gA as meshLODsProgressive,uA as meshMultiLOD,YQ as minkowski,N1 as mirror,JJ as mirror2D,kJ as mirrorDrawing,b0 as mirrorJoin,M2 as modifiers,bI as modifyStep,To as moduleInitError,DM as multiSectionSweep,wO as normalAt,e0 as offset,BP as offsetFace,hZ as offsetMesh,vZ as offsetShape,Gk as offsetWire2D,O as ok,$a as or,eo as orElse,cR as organiseBlueprints,gE as orientedFace,OO as outerWire,R2 as patterns,wX as pendingCount,_o as pipeline,iO as pivotPlane,xE as planarFace,xF as planarJoint,SE as planarWire,u2 as planetPlacements,v0 as pocket,xO as pointOnSurface,iZ as pointsInside,IP as polygon,XQ as polyhedron,Nq as polysideInnerRadius,TR as polysidesBlueprint,qj as positionOnCurve,PT as prewarm,A2 as primitives,yF as prismaticJoint,wq as projectEdges,CO as projectPointOnFace,I2 as query,Oo as queryError,x0 as rectangularPattern,AX as registerHandler,CT as registerKernel,AT as registerKernelTier,gI as registerOperation,mI as registerShape,XX as registerVoxel,EX as rejectAll,ZP as removeChild,kO as removeHolesFromFace,sZ as repairMesh,yI as replayFrom,vI as replayHistory,VT as resetDisposalStats,Uo as resetPerformanceStats,gk as resize,$ as resolve,A1 as resolve3D,rP as resolveDerivedFaceRef,ND as resolveDirection,BN as resolveEdgeRef,dP as resolveLineageRef,eO as resolvePlane,AN as resolveRef,pP as resolveRefIn,hP as resolveRefParams,JN as resolveVertexRef,AJ as reverseCurve,vF as revoluteJoint,p0 as revolve,y$ as roof,M1 as rotate,KJ as rotate2D,DJ as rotateDrawing,ER as roundedRectangleBlueprint,P1 as scale,qJ as scale2D,OJ as scaleDrawing,$Z as sdfBox,rQ as sdfCapsule,nQ as sdfCone,tQ as sdfCylinder,hQ as sdfFieldAxialRamp,vQ as sdfFieldClamp,mQ as sdfFieldConst,_Q as sdfFieldFromSdf,gQ as sdfFieldRadialRamp,lQ as sdfLattice,aQ as sdfPlane,eQ as sdfRoundedBox,QZ as sdfSphere,uQ as sdfStrutLattice,sQ as sdfSweep,iQ as sdfTorus,W1 as section,G1 as sectionToFace,xI as serializeHistory,wF as setJointValue,CF as setJointValues,jO as setShapeOrigin,qO as setTagMetadata,VP as sewShells,B0 as shape,lZ as shapeToMeshInput,lO as shapeType,uN as sharedEdges,$1 as shell,gZ as shellMesh,yZ as shellShape,Kj as shellWithEvolution,i0 as simplify,Oq as sketchCircle,kq as sketchEllipse,tq as sketchExtrude,QK as sketchFace,Pq as sketchFaceOffset,Iq as sketchHelix,rq as sketchLoft,ZJ as sketchOnFace2D,XJ as sketchOnPlane2D,Fq as sketchParametricFunction,Mq as sketchPolysides,Aq as sketchRectangle,eq as sketchRevolve,jq as sketchRoundedRectangle,nq as sketchSweep,fX as sketchText,$K as sketchWires,wo as sketcherStateError,q1 as slice,zP as solid,hM as solidFromShell,a1 as solveAssembly,vP as sphere,SF as sphericalJoint,K1 as split,fI as stepCount,pI as stepsFrom,YJ as stretch2D,FP as subFace,SM as supportExtrude,vT as supportsConstraintSketch,_T as supportsProjection,zQ as surfaceFromGrid,HQ as surfaceFromImage,xM as sweep,WO as tagFaces,AP as tangentArc,ro as tap,io as tapErr,gq as textBlueprints,pX as textMetrics,t0 as thicken,CI as thread,EP as threePointArc,c0 as toBREP,_j as toBufferGeometryData,vj as toGroupedBufferGeometryData,DQ as toKernelVec,bj as toLODGeometryData,xj as toLODGeometryLevels,yj as toLineGeometryData,WJ as toSVGPathD,jD as toVec2,AD as toVec3,bP as torus,EQ as tpmsLattice,L1 as transformCopy,N2 as transforms,j1 as translate,GJ as translate2D,EJ as translateDrawing,rO as translatePlane,ho as tryCatch,go as tryCatchAsync,wM as twistExtrude,Co as typeCastError,lI as undoLast,ko as unsupportedError,j as unwrap,fo as unwrapErr,lo as unwrapOr,uo as unwrapOrElse,QP as updateNode,EN as updateRoles,bO as uvBounds,SO as uvCoordinates,vE as validSolid,Z0 as validatePlanetary,P as validationError,sM as variableFillet,PD as vecAdd,KD as vecAngle,zD as vecCross,HD as vecDistance,RD as vecDot,WD as vecEquals,GD as vecIsZero,BD as vecLength,VD as vecLengthSq,LD as vecNegate,UD as vecNormalize,qD as vecProjectToPlane,XD as vecRepr,JD as vecRotate,ID as vecScale,FD as vecSub,LP as vertex,KX as vertexFinder,kD as vertexPosition,sN as verticesOfEdge,aN as verticesOfFace,_Z as voxelBoolean,MZ as voxelBooleanField,zZ as voxelBooleanFieldShapes,bZ as voxelBooleanShapes,jZ as voxelField,RZ as voxelFieldFromShape,eF as walkAssembly,rZ as windingNumbers,jP as wire,$I as wireFinder,MP as wireLoop,oN as wiresOfFace,ET as withKernel,FQ as withKernelDir,PQ as withKernelPnt,NQ as withKernelVec,OT as withQuality,ZT as withScope,eE as withScopeResult,tE as withScopeResultAsync,MT as withTier,to as zipResults};
|