brepjs-cad 0.85.0 → 0.87.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 CHANGED
@@ -1,5 +1,79 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.87.0](https://github.com/andymai/brepjs/compare/brepjs-cad-v0.86.0...brepjs-cad-v0.87.0) (2026-07-17)
4
+
5
+
6
+ ### Features
7
+
8
+ * **brepjs-cad:** add airfoils.md feature recipe (swept fans/props/impellers) ([#1566](https://github.com/andymai/brepjs/issues/1566)) ([8c786db](https://github.com/andymai/brepjs/commit/8c786db69ead59edcdc9d0f8525e43324552e4db))
9
+ * **brepjs-cad:** aimed section cut for the design judge (Phase 3) ([#1543](https://github.com/andymai/brepjs/issues/1543)) ([40e5acd](https://github.com/andymai/brepjs/commit/40e5acd54318d768dc5a620403d17d43e358e698))
10
+ * **brepjs-cad:** decomposed, cross-checked design-judge rubric (Phase 1.5) ([#1539](https://github.com/andymai/brepjs/issues/1539)) ([8059b6d](https://github.com/andymai/brepjs/commit/8059b6d701ae5980e6bb11f51695aa102fe2bb43))
11
+ * **brepjs-cad:** deterministic body/interference metrics for the design judge (Phase 1) ([#1531](https://github.com/andymai/brepjs/issues/1531)) ([d296b54](https://github.com/andymai/brepjs/commit/d296b545f2d7084b861683d61b626ace4747a371))
12
+ * **brepjs-cad:** grade judge quality against a reference exemplar ([#1731](https://github.com/andymai/brepjs/issues/1731)) ([9d4aaeb](https://github.com/andymai/brepjs/commit/9d4aaeb8e4830c6be78668854730367194b6a9e5))
13
+ * **brepjs-cad:** kernel-anchored Set-of-Marks for the design judge ([#1545](https://github.com/andymai/brepjs/issues/1545)) ([2b6f5b4](https://github.com/andymai/brepjs/commit/2b6f5b436f2a73c96747cc71f83afc8715765cd0))
14
+ * **brepjs-cad:** reliable internal-bore detection for the design judge (keystone) ([#1542](https://github.com/andymai/brepjs/issues/1542)) ([0d780c3](https://github.com/andymai/brepjs/commit/0d780c3b73c2551dab2f04a6ff31bf9ec8cae2ab))
15
+ * **brepjs-cad:** surface fragmentation in verify --check (the [#1](https://github.com/andymai/brepjs/issues/1) design defect) ([#1560](https://github.com/andymai/brepjs/issues/1560)) ([45a4f6e](https://github.com/andymai/brepjs/commit/45a4f6e268331b7816cd9957fbdab4c0893b2000))
16
+ * **brepjs-cad:** xray internal-reveal shot for the design judge (Phase 2a) ([#1540](https://github.com/andymai/brepjs/issues/1540)) ([eca5bc9](https://github.com/andymai/brepjs/commit/eca5bc9ad20fc7947132d647952245cfe466a7f4))
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * **brepjs-cad:** add a triangular-gusset recipe to the implement skill (bracket/enclosure eval) ([#1571](https://github.com/andymai/brepjs/issues/1571)) ([346d042](https://github.com/andymai/brepjs/commit/346d0423fefa3bd163f4075f69bf96d478543bf5))
22
+ * **brepjs-cad:** add the "realize the designed object" bar to the implement skill ([#1563](https://github.com/andymai/brepjs/issues/1563)) ([e150357](https://github.com/andymai/brepjs/commit/e1503570aaf271ebef1e39d48be9c70a5ffe8f03))
23
+ * **brepjs-cad:** bore detector misses full-cylinder through-holes ([#1551](https://github.com/andymai/brepjs/issues/1551)) ([#1586](https://github.com/andymai/brepjs/issues/1586)) ([b6d61eb](https://github.com/andymai/brepjs/commit/b6d61eb6d88e2e4a3aa1c55b78dc2e76315ebc02))
24
+ * **brepjs-cad:** close gear-teeth edge cases found by /eval-skill (ring, worm tip relief, GT2) ([#1548](https://github.com/andymai/brepjs/issues/1548)) ([4bd0494](https://github.com/andymai/brepjs/commit/4bd049401f3affcc3f38e3a31bb9520653a3e89c))
25
+ * **brepjs-cad:** code + hint the degenerate-edge (duplicate-vertex) verify failure ([#1550](https://github.com/andymai/brepjs/issues/1550)) ([502dffc](https://github.com/andymai/brepjs/commit/502dffc4a2ae495ae5c98b0c7966721abe0d5f48))
26
+ * **brepjs-cad:** correct spur-gear example flanks + add root fillet ([#1528](https://github.com/andymai/brepjs/issues/1528)) ([6971c6b](https://github.com/andymai/brepjs/commit/6971c6befa1fea36a8c2f3ee89c4aa20946020c7))
27
+ * **brepjs-cad:** exploded-joint legibility + disjoint-compound caveat (basics eval) ([#1565](https://github.com/andymai/brepjs/issues/1565)) ([9d06121](https://github.com/andymai/brepjs/commit/9d0612111a595e57fcfca6fd191ed9169fc2c062))
28
+ * **brepjs-cad:** handle brepjs/playground refs + summarize body relations in the digest ([#1547](https://github.com/andymai/brepjs/issues/1547)) ([b0acef0](https://github.com/andymai/brepjs/commit/b0acef0ad80cdd61f0d2683f1e6d0ece0cae028e))
29
+ * **brepjs-cad:** heal 6 implement-skill findings from the full-flywheel re-run ([#1568](https://github.com/andymai/brepjs/issues/1568)) ([f63bf3d](https://github.com/andymai/brepjs/commit/f63bf3d5a0aa638d06e11dd7e2c27e84dbf74746))
30
+ * **brepjs-cad:** heal implement + polish skills from clean-room eval ([#1526](https://github.com/andymai/brepjs/issues/1526)) ([0645e16](https://github.com/andymai/brepjs/commit/0645e163e1d8759c95406d0f9526d0aa3b5dd480))
31
+ * **brepjs-cad:** heal implement skill — deep-stack bounds extremes aren't datums ([#1529](https://github.com/andymai/brepjs/issues/1529)) ([5ed366f](https://github.com/andymai/brepjs/commit/5ed366f266b3e6e50ae4b54d5779aa05453e894a))
32
+ * **brepjs-cad:** heal implement skill from the eval flywheel (3 findings) ([#1552](https://github.com/andymai/brepjs/issues/1552)) ([51def82](https://github.com/andymai/brepjs/commit/51def82db4e0600e85f45e4dd828cc9caee58d15))
33
+ * **brepjs-cad:** heal implement skill from the full-corpus eval flywheel (4 findings) ([#1554](https://github.com/andymai/brepjs/issues/1554)) ([3cfc28e](https://github.com/andymai/brepjs/commit/3cfc28ed8b82c46330f1d75f1e98c13fd4d65a06))
34
+ * **brepjs-cad:** make blind-judge reference adaptation render multi-body parts at scale ([#1530](https://github.com/andymai/brepjs/issues/1530)) ([18d4523](https://github.com/andymai/brepjs/commit/18d4523c85e1b22496bb5c0b8fb382a1146429c6))
35
+ * **brepjs-cad:** polish skill — bosses on shells must fuse, or they float (eval finding) ([#1553](https://github.com/andymai/brepjs/issues/1553)) ([07cbf93](https://github.com/andymai/brepjs/commit/07cbf93e47fbf880df53bc2a1cee05bf0d17e2d5))
36
+ * **brepjs-cad:** teach worm-wheel and rack tooth recipes; fix gear-build contradiction ([#1544](https://github.com/andymai/brepjs/issues/1544)) ([b0da85f](https://github.com/andymai/brepjs/commit/b0da85f218d463e0f1ef0ca8760cec54b4814b02))
37
+ * **core:** bump occt-wasm to 3.7.0 with borrowed adjacency handles ([#1821](https://github.com/andymai/brepjs/issues/1821)) ([4b76974](https://github.com/andymai/brepjs/commit/4b76974833f2d9900740fffcec2dd589de952ff9))
38
+ * **release:** unbreak Vercel — repin brepjs-cad to brepjs >=18.0.0 ([#1711](https://github.com/andymai/brepjs/issues/1711)) ([78c780a](https://github.com/andymai/brepjs/commit/78c780a3ab2fcc78f26b32029df72795582e145c))
39
+
40
+ ## [0.86.0](https://github.com/andymai/brepjs/compare/brepjs-cad-v0.85.1...brepjs-cad-v0.86.0) (2026-07-17)
41
+
42
+
43
+ ### Features
44
+
45
+ * **brepjs-cad:** add airfoils.md feature recipe (swept fans/props/impellers) ([#1566](https://github.com/andymai/brepjs/issues/1566)) ([8c786db](https://github.com/andymai/brepjs/commit/8c786db69ead59edcdc9d0f8525e43324552e4db))
46
+ * **brepjs-cad:** aimed section cut for the design judge (Phase 3) ([#1543](https://github.com/andymai/brepjs/issues/1543)) ([40e5acd](https://github.com/andymai/brepjs/commit/40e5acd54318d768dc5a620403d17d43e358e698))
47
+ * **brepjs-cad:** decomposed, cross-checked design-judge rubric (Phase 1.5) ([#1539](https://github.com/andymai/brepjs/issues/1539)) ([8059b6d](https://github.com/andymai/brepjs/commit/8059b6d701ae5980e6bb11f51695aa102fe2bb43))
48
+ * **brepjs-cad:** deterministic body/interference metrics for the design judge (Phase 1) ([#1531](https://github.com/andymai/brepjs/issues/1531)) ([d296b54](https://github.com/andymai/brepjs/commit/d296b545f2d7084b861683d61b626ace4747a371))
49
+ * **brepjs-cad:** grade judge quality against a reference exemplar ([#1731](https://github.com/andymai/brepjs/issues/1731)) ([9d4aaeb](https://github.com/andymai/brepjs/commit/9d4aaeb8e4830c6be78668854730367194b6a9e5))
50
+ * **brepjs-cad:** kernel-anchored Set-of-Marks for the design judge ([#1545](https://github.com/andymai/brepjs/issues/1545)) ([2b6f5b4](https://github.com/andymai/brepjs/commit/2b6f5b436f2a73c96747cc71f83afc8715765cd0))
51
+ * **brepjs-cad:** reliable internal-bore detection for the design judge (keystone) ([#1542](https://github.com/andymai/brepjs/issues/1542)) ([0d780c3](https://github.com/andymai/brepjs/commit/0d780c3b73c2551dab2f04a6ff31bf9ec8cae2ab))
52
+ * **brepjs-cad:** surface fragmentation in verify --check (the [#1](https://github.com/andymai/brepjs/issues/1) design defect) ([#1560](https://github.com/andymai/brepjs/issues/1560)) ([45a4f6e](https://github.com/andymai/brepjs/commit/45a4f6e268331b7816cd9957fbdab4c0893b2000))
53
+ * **brepjs-cad:** xray internal-reveal shot for the design judge (Phase 2a) ([#1540](https://github.com/andymai/brepjs/issues/1540)) ([eca5bc9](https://github.com/andymai/brepjs/commit/eca5bc9ad20fc7947132d647952245cfe466a7f4))
54
+
55
+
56
+ ### Bug Fixes
57
+
58
+ * **brepjs-cad:** add a triangular-gusset recipe to the implement skill (bracket/enclosure eval) ([#1571](https://github.com/andymai/brepjs/issues/1571)) ([346d042](https://github.com/andymai/brepjs/commit/346d0423fefa3bd163f4075f69bf96d478543bf5))
59
+ * **brepjs-cad:** add the "realize the designed object" bar to the implement skill ([#1563](https://github.com/andymai/brepjs/issues/1563)) ([e150357](https://github.com/andymai/brepjs/commit/e1503570aaf271ebef1e39d48be9c70a5ffe8f03))
60
+ * **brepjs-cad:** bore detector misses full-cylinder through-holes ([#1551](https://github.com/andymai/brepjs/issues/1551)) ([#1586](https://github.com/andymai/brepjs/issues/1586)) ([b6d61eb](https://github.com/andymai/brepjs/commit/b6d61eb6d88e2e4a3aa1c55b78dc2e76315ebc02))
61
+ * **brepjs-cad:** close gear-teeth edge cases found by /eval-skill (ring, worm tip relief, GT2) ([#1548](https://github.com/andymai/brepjs/issues/1548)) ([4bd0494](https://github.com/andymai/brepjs/commit/4bd049401f3affcc3f38e3a31bb9520653a3e89c))
62
+ * **brepjs-cad:** code + hint the degenerate-edge (duplicate-vertex) verify failure ([#1550](https://github.com/andymai/brepjs/issues/1550)) ([502dffc](https://github.com/andymai/brepjs/commit/502dffc4a2ae495ae5c98b0c7966721abe0d5f48))
63
+ * **brepjs-cad:** correct spur-gear example flanks + add root fillet ([#1528](https://github.com/andymai/brepjs/issues/1528)) ([6971c6b](https://github.com/andymai/brepjs/commit/6971c6befa1fea36a8c2f3ee89c4aa20946020c7))
64
+ * **brepjs-cad:** exploded-joint legibility + disjoint-compound caveat (basics eval) ([#1565](https://github.com/andymai/brepjs/issues/1565)) ([9d06121](https://github.com/andymai/brepjs/commit/9d0612111a595e57fcfca6fd191ed9169fc2c062))
65
+ * **brepjs-cad:** handle brepjs/playground refs + summarize body relations in the digest ([#1547](https://github.com/andymai/brepjs/issues/1547)) ([b0acef0](https://github.com/andymai/brepjs/commit/b0acef0ad80cdd61f0d2683f1e6d0ece0cae028e))
66
+ * **brepjs-cad:** heal 6 implement-skill findings from the full-flywheel re-run ([#1568](https://github.com/andymai/brepjs/issues/1568)) ([f63bf3d](https://github.com/andymai/brepjs/commit/f63bf3d5a0aa638d06e11dd7e2c27e84dbf74746))
67
+ * **brepjs-cad:** heal implement + polish skills from clean-room eval ([#1526](https://github.com/andymai/brepjs/issues/1526)) ([0645e16](https://github.com/andymai/brepjs/commit/0645e163e1d8759c95406d0f9526d0aa3b5dd480))
68
+ * **brepjs-cad:** heal implement skill — deep-stack bounds extremes aren't datums ([#1529](https://github.com/andymai/brepjs/issues/1529)) ([5ed366f](https://github.com/andymai/brepjs/commit/5ed366f266b3e6e50ae4b54d5779aa05453e894a))
69
+ * **brepjs-cad:** heal implement skill from the eval flywheel (3 findings) ([#1552](https://github.com/andymai/brepjs/issues/1552)) ([51def82](https://github.com/andymai/brepjs/commit/51def82db4e0600e85f45e4dd828cc9caee58d15))
70
+ * **brepjs-cad:** heal implement skill from the full-corpus eval flywheel (4 findings) ([#1554](https://github.com/andymai/brepjs/issues/1554)) ([3cfc28e](https://github.com/andymai/brepjs/commit/3cfc28ed8b82c46330f1d75f1e98c13fd4d65a06))
71
+ * **brepjs-cad:** make blind-judge reference adaptation render multi-body parts at scale ([#1530](https://github.com/andymai/brepjs/issues/1530)) ([18d4523](https://github.com/andymai/brepjs/commit/18d4523c85e1b22496bb5c0b8fb382a1146429c6))
72
+ * **brepjs-cad:** polish skill — bosses on shells must fuse, or they float (eval finding) ([#1553](https://github.com/andymai/brepjs/issues/1553)) ([07cbf93](https://github.com/andymai/brepjs/commit/07cbf93e47fbf880df53bc2a1cee05bf0d17e2d5))
73
+ * **brepjs-cad:** teach worm-wheel and rack tooth recipes; fix gear-build contradiction ([#1544](https://github.com/andymai/brepjs/issues/1544)) ([b0da85f](https://github.com/andymai/brepjs/commit/b0da85f218d463e0f1ef0ca8760cec54b4814b02))
74
+ * **core:** bump occt-wasm to 3.7.0 with borrowed adjacency handles ([#1821](https://github.com/andymai/brepjs/issues/1821)) ([4b76974](https://github.com/andymai/brepjs/commit/4b76974833f2d9900740fffcec2dd589de952ff9))
75
+ * **release:** unbreak Vercel — repin brepjs-cad to brepjs >=18.0.0 ([#1711](https://github.com/andymai/brepjs/issues/1711)) ([78c780a](https://github.com/andymai/brepjs/commit/78c780a3ab2fcc78f26b32029df72795582e145c))
76
+
3
77
  ## [0.85.0](https://github.com/andymai/brepjs/compare/brepjs-cad-v0.84.0...brepjs-cad-v0.85.0) (2026-07-17)
4
78
 
5
79
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brepjs-cad",
3
- "version": "0.85.0",
3
+ "version": "0.87.0",
4
4
  "description": "Brainstorm → design → author → verify → polish pipeline for parametric brepjs CAD, with the brep CLI",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -12,7 +12,7 @@ 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 ow(e,{vertProperties:Float32Array.from(r),triVerts:Uint32Array.from(i)})}function cw(e,t){let n=new Uint8Array(t),r=new TextDecoder().decode(n.subarray(0,Math.min(n.length,80))).trimStart().toLowerCase().startsWith(`solid`)&&dw(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=uw(i);return ow(e,{vertProperties:Float32Array.from(a.vertices),triVerts:Uint32Array.from(a.indices)})}var lw=1e6;function uw(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*lw)},${Math.round(o*lw)},${Math.round(s*lw)}`,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 dw(e){return e.length<84?!0:84+new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(80,!0)*50!==e.length}var fw=1e-6;function pw(e,t){let n=H(t);if(n.replayable)return iC(n,e)}function mw(e,t){let n=ZC(t),r=Math.floor(n.triVerts.length/3),i=[];for(let t=0;t<r;t++){let[r,a,o]=tw(n,t),s=e.buildTriFace(ew(n,r),ew(n,a),ew(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,fw)}function hw(e){let t=Hy(`B-rep export`),n=pw(t,e);return n===void 0?(console.warn(`manifold: exact B-rep unavailable (non-replayable op-graph); exporting faceted approximation`),{occt:t,brep:mw(t,e)}):{occt:t,brep:n}}function gw(e,t,n,r){let i=t.mesh(n,{tolerance:.01,angularTolerance:.5});return ow(e,{vertProperties:Float32Array.from(i.vertices),triVerts:Uint32Array.from(i.triangles)},r)}var _w=1179937895,vw=2,yw=1313821514,bw=5130562,xw=5126,Sw=5125,Cw=5123,ww=5121,Tw=34962,Ew=34963,Dw=4;function Ow(e){return e+3&-4}function kw(e){let t=ZC(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=Ow(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:Dw}]}],accessors:[{bufferView:0,componentType:xw,count:r,type:`VEC3`,min:[o,s,c],max:[l,u,d]},{bufferView:1,componentType:Sw,count:i,type:`SCALAR`}],bufferViews:[{buffer:0,byteOffset:0,byteLength:p,target:Tw},{buffer:0,byteOffset:m,byteLength:f.byteLength,target:Ew}],buffers:[{byteLength:h}]},_=new TextEncoder().encode(JSON.stringify(g)),v=Ow(_.length),y=Ow(h),b=20+v+8+y,x=new ArrayBuffer(b),S=new DataView(x),C=new Uint8Array(x);S.setUint32(0,_w,!0),S.setUint32(4,vw,!0),S.setUint32(8,b,!0);let w=12;S.setUint32(w,v,!0),S.setUint32(w+4,yw,!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,bw,!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 Aw(e,t){let n=new DataView(t);if(n.getUint32(0,!0)!==_w)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===yw?i=JSON.parse(new TextDecoder().decode(s)):r===bw&&(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===Sw?4:e.componentType===Cw?2:+(e.componentType===ww);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 ow(e,{vertProperties:p,triVerts:m},`importGLB`)}function jw(e){return{exportSTL:(e,t)=>rw(e,t),exportOBJ:e=>iw(e),exportPLY:e=>aw(e),importSTL:t=>cw(e,typeof t==`string`?new TextEncoder().encode(t).buffer:t),importOBJ:t=>sw(e,t),exportSTEP:e=>Hy(`exportSTEP`).exportSTEP(e.map(e=>hw(e).brep)),exportIGES:e=>Hy(`exportIGES`).exportIGES(e.map(e=>hw(e).brep)),toBREP:e=>{let{occt:t,brep:n}=hw(e);return t.toBREP(n)},exportSTEPAssembly:(e,t)=>{let n=Hy(`exportSTEPAssembly`),r=e.map(e=>{let t={shape:hw(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=Hy(`createXCAFDocument`),n=e.map(e=>{let t={shape:hw(e.shape).brep,name:e.name};return e.color===void 0?t:{...t,color:e.color}});return t.createXCAFDocument(n)},writeXCAFToSTEP:(e,t)=>Hy(`writeXCAFToSTEP`).writeXCAFToSTEP(e,t),exportSTEPConfigured:(e,t)=>{let n=Hy(`exportSTEPConfigured`),r=e.map(e=>{let t={shape:hw(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=Hy(`importSTEP`);return n.importSTEP(t).map(t=>gw(e,n,t,`importSTEP`))},importIGES:t=>{let n=Hy(`importIGES`);return n.importIGES(t).map(t=>gw(e,n,t,`importIGES`))},fromBREP:t=>{let n=Hy(`fromBREP`);return gw(e,n,n.fromBREP(t),`fromBREP`)},exportGLB:e=>kw(e),importGLB:t=>Aw(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 Mw(e){return V(e).getMesh()}function Nw(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 Pw(e,t){let n=e;if(n&&n.__manifoldSub&&n.occt){let e=Vy();if(!e)throw new c(`manifold: sub-shape geometry query requires a registered occt kernel`);return t(n.occt,e)}let r=zy(e);if(!r)throw Error(`manifold: exact geometry query requires a manifold shape handle`);let i=Vy();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=Uy.get(r.node);return a===void 0&&(a=iC(r.node,i),Uy.set(r.node,a)),t(a,i)}function Fw(e){let t=zy(e);if(!t)return;let n=t.node;return n.op===`profileEdge`?n.params?.curve:void 0}function Iw(e){return{curveType:e=>{let t=Fw(e);return t?kb(t):zC(e)?e.curveType:Pw(e,(e,t)=>t.curveType(e))},curveParameters:e=>{let t=Fw(e);if(t){let e=Ab(t);return[e.first,e.last]}return zC(e)?[0,e.length]:Pw(e,(e,t)=>t.curveParameters(e))},curvePointAtParam:(e,t)=>{let n=Fw(e);return n?jb(n,t):zC(e)?BC(e,t):Pw(e,(e,n)=>n.curvePointAtParam(e,t))},curveTangent:(e,t)=>{let n=Fw(e);return n?{point:jb(n,t),tangent:Mb(n,t)}:zC(e)?{point:BC(e,t),tangent:VC(e,t)}:Pw(e,(e,n)=>n.curveTangent(e,t))},curveIsClosed:e=>{let t=Fw(e);return t?Pb(t):Pw(e,(e,t)=>t.curveIsClosed(e))},curveIsPeriodic:e=>{let t=Fw(e);return t?Fb(t):Pw(e,(e,t)=>t.curveIsPeriodic(e))},curvePeriod:e=>{let t=Fw(e);return t?Ib(t):Pw(e,(e,t)=>t.curvePeriod(e))},interpolatePoints:(e,t)=>Hy(`interpolatePoints`).interpolatePoints(e,t),approximatePoints:(e,t)=>Hy(`approximatePoints`).approximatePoints(e,t),curveDegreeElevate:(e,t)=>Pw(e,(e,n)=>n.curveDegreeElevate(e,t)),curveKnotInsert:(e,t,n)=>Pw(e,(e,r)=>r.curveKnotInsert(e,t,n)),curveKnotRemove:(e,t,n)=>Pw(e,(e,r)=>r.curveKnotRemove(e,t,n)),curveSplit:(e,t)=>Pw(e,(e,n)=>n.curveSplit(e,t)),createCurveAdaptor:e=>Pw(e,(e,t)=>t.createCurveAdaptor(e)),getBezierPenultimatePole:e=>Pw(e,(e,t)=>t.getBezierPenultimatePole(e)),getNurbsCurveData:e=>Pw(e,(e,t)=>t.getNurbsCurveData?.(e)??null),vertexPosition:e=>RC(e)?e.point:zy(e)?Nw(Mw(e),0):Pw(e,(e,t)=>t.vertexPosition(e)),surfaceType:e=>{if(kC(e))return`plane`;let t=zy(e);return t&&t.node.op===`profileFace`?`plane`:Pw(e,(e,t)=>t.surfaceType(e))},uvBounds:e=>kC(e)?{uMin:0,uMax:1,vMin:0,vMax:1}:Pw(e,(e,t)=>t.uvBounds(e)),outerWire:e=>Pw(e,(e,t)=>t.outerWire(e)),surfaceNormal:(e,t,n)=>kC(e)?e.normal:Pw(e,(e,r)=>r.surfaceNormal(e,t,n)),pointOnSurface:(e,t,n)=>Pw(e,(e,r)=>r.pointOnSurface(e,t,n)),uvFromPoint:(e,t)=>Pw(e,(e,n)=>n.uvFromPoint(e,t)),projectPointOnFace:(e,t)=>Pw(e,(e,n)=>n.projectPointOnFace(e,t)),classifyPointOnFace:(e,t,n,r)=>Pw(e,(e,i)=>i.classifyPointOnFace(e,t,n,r)),classifyPointRobust:(e,t,n)=>Pw(e,(e,r)=>r.classifyPointRobust(e,t,n)),classifyPointWinding:(e,t,n)=>Pw(e,(e,r)=>r.classifyPointWinding(e,t,n)),approximateSurfaceLspia:(e,t,n,r,i,a,o,s,c)=>Hy(`approximateSurfaceLspia`).approximateSurfaceLspia(e,t,n,r,i,a,o,s,c),untrimFace:(e,t,n)=>Pw(e,(e,r)=>r.untrimFace(e,t,n)),getSurfaceCylinderData:e=>Pw(e,(e,t)=>t.getSurfaceCylinderData(e)),getSurfaceAxis:e=>Pw(e,(e,t)=>t.getSurfaceAxis(e)),reverseSurfaceU:e=>Hy(`reverseSurfaceU`).reverseSurfaceU(e),detectSmallFeatures:(e,t,n)=>Pw(e,(e,r)=>r.detectSmallFeatures(e,t,n)),recognizeFeatures:(e,t)=>Pw(e,(e,n)=>n.recognizeFeatures(e,t)),projectEdges:(e,t,n,r)=>Pw(e,(e,i)=>i.projectEdges(e,t,n,r)),getNurbsSurfaceData:e=>Pw(e,(e,t)=>t.getNurbsSurfaceData?.(e)??null)}}var Lw={hasErrors:!1,hasWarnings:!1,messages:[]};function Rw(){return{modified:new Map,generated:new Map,deleted:new Set}}function zw(e){return{shape:e,evolution:Rw()}}function Bw(e){return{shape:e,evolution:Rw(),diagnostics:Lw}}function Vw(e){let t=Sb(e),n=eb(e),r=OS(e);return{translateWithHistory:(e,n,r,i)=>zw(t.translate(e,n,r,i)),rotateWithHistory:(e,n,r,i,a,o)=>zw(t.rotate(e,n,a,o)),mirrorWithHistory:(e,n,r)=>zw(t.mirror(e,n,r)),scaleWithHistory:(e,n,r)=>zw(t.scale(e,n,r)),generalTransformWithHistory:(e,n,r,i)=>zw(t.generalTransform(e,n,r,i)),fuseWithHistory:(e,t,r,i,a)=>Bw(n.fuse(e,t,a)),cutWithHistory:(e,t,r,i,a)=>Bw(n.cut(e,t,a)),intersectWithHistory:(e,t,r,i,a)=>Bw(n.intersect(e,t,a)),filletWithHistory:(e,t,n)=>zw(r.fillet(e,t,n)),chamferWithHistory:(e,t,n)=>zw(r.chamfer(e,t,n)),shellWithHistory:(e,t,n,i,a,o)=>zw(r.shell(e,t,n,o)),thickenWithHistory:(e,t)=>zw(r.thicken(e,t)),offsetWithHistory:(e,t,n,i,a)=>zw(r.offset(e,t,a)),draftWithHistory:(e,t,n,i,a)=>zw(r.draft(e,t,n,i,a)),applyComposedTransformWithHistory:(e,n)=>zw(t.transform(e,n))}}function Hw(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 Uw(e){return{isValid:e=>Hw(e),isValidStrict:e=>Hw(e),healSolid:e=>Hw(e)?e:null,healFace:e=>e,healWire:e=>e,mergeCoincidentVertices:()=>0,removeDegenerateEdges:()=>0,fixFaceOrientations:()=>0,fixShape:e=>e,fixSelfIntersection:e=>e}}var Ww=.004;function Gw(e){return!!e&&typeof e==`object`&&e.__nativeC2d===!0}function Kw(e,t){return{__nativeC2d:!0,k:`line`,p1:e,p2:t}}function qw(e,t,n,r,i){return{__nativeC2d:!0,k:`conic`,c:e,u:t,v:n,a0:r,a1:i}}function Jw(e,[t,n]){return[e.a*t+e.b*n+e.tx,e.c*t+e.d*n+e.ty]}function Yw(e,[t,n]){return[e.a*t+e.b*n,e.c*t+e.d*n]}function Xw(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 Zw(e,t){return e.k===`line`?Kw(Jw(t,e.p1),Jw(t,e.p2)):e.k===`bezier`?{__nativeC2d:!0,k:`bezier`,pts:e.pts.map(e=>Jw(t,e))}:qw(Jw(t,e.c),Yw(t,e.u),Yw(t,e.v),e.a0,e.a1)}function Qw(e,t){let n=e.map(e=>[e[0],e[1]]);for(let e=1;e<n.length;e++)for(let r=0;r<n.length-e;r++){let e=n[r]??[0,0],i=n[r+1]??[0,0];n[r]=[e[0]*(1-t)+i[0]*t,e[1]*(1-t)+i[1]*t]}return n[0]??[0,0]}function $w(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 eT(e,t){let n=e.length-1;if(n<1)return[0,0];let r=[];for(let t=0;t<n;t++){let i=e[t]??[0,0],a=e[t+1]??[0,0];r.push([n*(a[0]-i[0]),n*(a[1]-i[1])])}return Qw(r,t)}function tT(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<=Ww)return Math.max(2,Math.ceil(t/(2*Math.PI)*8));let a=2*Math.acos(Math.max(-1,1-Ww/i));return Math.max(2,Math.ceil(t/a))}function nT(e){if(e.k===`line`)return[e.p1,e.p2];if(e.k===`bezier`){let t=[];for(let n=0;n<=24;n++)t.push(Qw(e.pts,n/24));return t}let t=e.a1-e.a0,n=tT(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 rT(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 Kw(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-_),qw(f,[p,0],[0,p],h,_)}function iT(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(!Gw(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=$w(n,n.a0),i=$w(n,(n.a0+n.a1)/2),a=$w(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(nT(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)=>Kw([e,t],[n,r]),makeCircle2d:(e,t,n,r=!0)=>qw([e,t],[n,0],r?[0,n]:[0,-n],0,2*Math.PI),makeArc2dThreePoints:(e,t,n,r,i,a)=>rT([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 Kw([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),qw([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 qw([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 qw([e,t],[u,d],[f,p],i,a)},makeBezier2d:e=>({__nativeC2d:!0,k:`bezier`,pts:e.map(e=>[e[0],e[1]])}),evaluateCurve2d:(e,t)=>{let n=i(e);if(n.k===`line`){let e=n.p2[0]-n.p1[0],r=n.p2[1]-n.p1[1],i=Math.hypot(e,r)||1;return[n.p1[0]+e*t/i,n.p1[1]+r*t/i]}return n.k===`bezier`?Qw(n.pts,t):[n.c[0]+n.u[0]*Math.cos(t)+n.v[0]*Math.sin(t),n.c[1]+n.u[1]*Math.cos(t)+n.v[1]*Math.sin(t)]},evaluateCurve2dD1:(e,t)=>{let n=i(e);if(n.k===`line`){let e=n.p2[0]-n.p1[0],r=n.p2[1]-n.p1[1],i=Math.hypot(e,r)||1;return{point:[n.p1[0]+e*t/i,n.p1[1]+r*t/i],tangent:[e/i,r/i]}}if(n.k===`bezier`)return{point:Qw(n.pts,t),tangent:eT(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 qw(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 Kw([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=Xw(e,t);Object.assign(e,n)},transformCurve2dGeneral:(e,t)=>Zw(i(e),t),translateCurve2d:(e,t,n)=>Zw(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 Zw(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)=>Zw(i(e),{a:t,b:0,c:0,d:t,tx:n-t*n,ty:r-t*r}),mirrorCurve2dAtPoint:(e,t,n)=>Zw(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 Zw(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 Zw(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(Gw(t))r=nT(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=nT(i(e)).map(([e,n])=>[t[0]+l*e+f*n,t[1]+u*e+p*n,t[2]+d*e+m*n]);return B(n,z(`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)=>Gw(n)?t(n,...i):r(e,n,...i)))}return s}var aT=`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 oT(e){let t=Vy();if(!t)throw Error(`manifold: ${e} unsupported on manifold kernel; no B-rep kernel registered`);return t}function sT(e){let t={};for(let e of aT)t[e]=(...t)=>oT(e)[e](...t);let n=iT(e,()=>Vy());return Object.assign(t,n),t}function cT(e){return{sketchNew:()=>Iy(`sketchNew`),sketchAddPoint:()=>Iy(`sketchAddPoint`),sketchAddArc:()=>Iy(`sketchAddArc`),sketchAddConstraint:()=>Iy(`sketchAddConstraint`),sketchSolve:()=>Iy(`sketchSolve`),sketchDof:()=>Iy(`sketchDof`)}}function lT(e){return{projectEdges:()=>Iy(`projectEdges`)}}function uT(e){return{dispose(e){let t=zy(e);if(t){let e=Uy.get(t.node);e!==void 0&&(Vy()?.dispose(e),Uy.delete(t.node))}(e?.manifold)?.delete?.()},executeBatch:()=>Iy(`executeBatch`),checkpoint:()=>Iy(`checkpoint`),checkpointCount:()=>0,restoreCheckpoint:()=>Iy(`restoreCheckpoint`),discardCheckpoint:()=>Iy(`discardCheckpoint`)}}var dT={draft:30,standard:10,fine:3},fT=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?.(dT[e])}constructor(e){this.oc=e,Object.assign(this,Yy(e),eb(e),Sb(e),kx(e),tS(e),OS(e),IS(e),EC(e),XC(e),jw(e),Iw(e),Vw(e),Uw(e),sT(e),cT(e),lT(e),uT(e))}};function pT(e){return import(e)}function mT(e){return`projectEdges`in e}function hT(e){return`sketchNew`in e&&`sketchDof`in e}var gT=new Map,_T=null,vT=null;function yT(e){bT(`manifold`,new fT(e))}function bT(e,t){gT.set(e,t),_T||=e,e===_T&&(vT=t)}function U(e){if(!e&&vT)return vT;let t=e??_T;if(!t)throw Error(`brepjs kernel not initialized. Call initFromOC() or registerKernel() before using the library.`);let n=gT.get(t);if(!n)throw Error(`brepjs: kernel '${t}' is not registered.`);return n}function xT(e){let t=U(e);if(!No(t))throw Error(`brepjs: current kernel does not support 2D operations.`);return t}function ST(){return _T}function CT(e,t){let n=_T;_T=e,vT=gT.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{_T=n,vT=n?gT.get(n)??null:null}}function wT(e){return U(e).capabilities}function TT(e,t){let n=Ao();try{Mo(e),U().setQuality?.(e);let n=t();if(n instanceof Promise)throw Error(`withQuality() callback returned a Promise. Async code must read currentQuality()/getKernel() directly.`);return n}finally{Mo(n),U().setQuality?.(n)}}var ET=new Map;function DT(e,t){ET.set(e,t)}function OT(e){return ET.get(e)}function kT(e,t){let n=ET.get(e);if(!n)throw Error(`withTier: no tier registered for "${e}". Call registerKernelTier("${e}", { kernel, quality }) first.`);return CT(n.kernel,()=>TT(n.quality,t))}function AT(e){Yo(),ll(),Ho(),zc(),Bc(),tl(),nl();let t=new Gf(e);bT(`occt`,t),_T=`occt`,vT=t}function jT(){let e=U(),t=e.makeBox(1,1,1);try{e.dispose(t)}catch{}}async function MT(){if(_T)return _T;try{let{OcctKernel:e}=await pT(`occt-wasm`),t=await e.init();return bT(`occt-wasm`,Wa.fromKernel(t)),`occt-wasm`}catch{}try{return AT(await(await pT(`brepjs-opencascade`)).default()),`occt`}catch{}try{let e=await pT(`brepkit-wasm`);return typeof e.default==`function`&&await e.default(),bT(`brepkit`,new Fy(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 NT(){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 PT=Symbol;PT.dispose??=Symbol.for(`Symbol.dispose`),PT.asyncDispose??=Symbol.for(`Symbol.asyncDispose`);var FT=globalThis;FT.FinalizationRegistry||=(console.warn(`brepjs: FinalizationRegistry unavailable — garbage collection will not work`),class{register(e,t,n){}unregister(e){return!1}});var IT={liveHandles:0,peakHandles:0,gcCollected:0,scopeEnters:0,scopeExits:0};function LT(){return{...IT}}function RT(){IT.liveHandles=0,IT.peakHandles=0,IT.gcCollected=0,IT.scopeEnters=0,IT.scopeExits=0}function zT(){IT.liveHandles++,IT.liveHandles>IT.peakHandles&&(IT.peakHandles=IT.liveHandles)}function BT(){IT.liveHandles--}function VT(){IT.gcCollected++,IT.liveHandles--}var HT=new FinalizationRegistry(e=>{VT();try{e.delete()}catch{}});function UT(e){let t=U(),n=!1,r,i=()=>{if(r){for(let e of r)try{e()}catch{}r=void 0}},a=()=>{if(!n){n=!0,BT(),HT.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 zT(),HT.register(o,{delete:()=>{t.dispose(e)}},o),o}function WT(e){let t=()=>{};return{get wrapped(){return e},get disposed(){return!1},[Symbol.dispose]:t,delete:t,onDispose:t}}function GT(e){let t=U(),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 KT(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,BT(),HT.unregister(n);try{e.delete()}catch{}}}};return zT(),HT.register(n,e,n),n}var qT=class{handles=[];constructor(){IT.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](){IT.scopeExits++;for(let e=this.handles.length-1;e>=0;e--)this.handles[e]?.();this.handles.length=0}};function JT(e){try{var t=NT();return e(t.u(new qT))}catch(e){t.e=e}finally{t.d()}}function YT(e,t){HT.register(e,t,t)}function XT(e){HT.unregister(e)}function ZT(e){try{var t=NT();return e(t.u(new qT))}catch(e){t.e=e}finally{t.d()}}async function QT(e){try{var t=NT();return await e(t.u(new qT))}catch(e){t.e=e}finally{t.d()}}function $T(e){return!e.disposed}function eE(e){return e.__is2D!==!0}function tE(e){return e.__is2D===!0}function nE(e){if(!eE(e))throw Error(`Expected 3D shape, got 2D`);return e}function rE(e){if(!tE(e))throw Error(`Expected 2D shape, got 3D`);return e}var iE=new WeakMap;function aE(e,t){iE.set(e,t)}function oE(e,t){let n=iE.get(t);if(n!==void 0)return n;let r=e.shapeType(t);return iE.set(t,r),r}function sE(e){return oE(U(),e.wrapped)}function cE(e){return U().curveIsClosed(e.wrapped)}function lE(e){return U().isValid(e.wrapped)}function uE(e){let t=U();if(!t.isValid(e.wrapped))return!1;let n=t.isValidStrict?.bind(t)??t.isValid.bind(t);try{let r=t.solidFromShell(e.wrapped),i=n(r);try{t.dispose(r)}catch{}return i}catch{return!1}}function dE(e){return U().isValid(e.wrapped)}function fE(e){return cE(e)?O(e):k(`Wire is not closed: start and end points do not coincide`)}function pE(e){return lE(e)?O(e):k(`Face orientation is inconsistent or face is invalid`)}function mE(e){return uE(e)?O(e):k(`Shell is not manifold: has free edges or is invalid`)}function hE(e){return dE(e)?O(e):k(`Solid failed BRepCheck validation`)}function gE(e){return U().surfaceType(e.wrapped)===`plane`}function _E(e){let t=U(),n=n=>{try{let r=t.makeFace(e.wrapped,n),i=t.surfaceType(r);try{t.dispose(r)}catch{}return i===`plane`}catch{return!1}};return n(!0)?!0:n(!1)}function vE(e){return gE(e)?O(e):k(`Face is not planar: underlying surface is not a geometric plane`)}function yE(e){return _E(e)?O(e):k(`Wire is not planar: edges do not lie in a common plane`)}function bE(e,t){return t===`2D`&&(e.__is2D=!0),e}function xE(e,t){return bE(UT(e),t)}function SE(e,t){return bE(UT(e),t)}function CE(e,t){return bE(UT(e),t)}function wE(e,t){return bE(UT(e),t)}function TE(e){return bE(UT(e))}function EE(e){return bE(UT(e))}function DE(e){return bE(UT(e))}function OE(e,t){return bE(UT(e),t)}function kE(e){return sE(e)===`vertex`}function AE(e){return sE(e)===`edge`}function jE(e){return sE(e)===`wire`}function ME(e){return sE(e)===`face`}function NE(e){return sE(e)===`shell`}function PE(e){return sE(e)===`solid`}function FE(e){return sE(e)===`compound`}function IE(e){let t=sE(e);return t===`shell`||t===`solid`||t===`compsolid`?!0:t===`compound`?eE(e):!1}function LE(e){let t=sE(e);return t===`edge`||t===`wire`}function RE(e,t){let n=U(),r=oE(n,e),i=n.downcast(e,r);return r===`vertex`?xE(i,t):r===`edge`?SE(i,t):r===`wire`?CE(i,t):r===`face`?wE(i,t):r===`shell`?TE(i):r===`solid`?EE(i):r===`compsolid`?DE(i):OE(i,t)}function zE(e){return RE(e)}function BE(e,t){let n=e.id,r=t.wrapped.id;(n!==void 0&&r!==void 0?n===r:t.wrapped===e)||U().dispose(e)}function W(e,t){let n=RE(e,t);return BE(e,n),n}function VE(e,t){let n=e.wrapped;if(e[Symbol.dispose](),n!==t){let e=U();e.dispose(n),e.dispose(t)}}function HE(e){U().dispose(e.wrapped),e[Symbol.dispose]()}function UE(e,t,n){aE(e,t);let r=U().downcast(e,t);return t===`vertex`?xE(r,n):t===`edge`?SE(r,n):t===`wire`?CE(r,n):t===`face`?wE(r,n):t===`shell`?TE(r):t===`solid`?EE(r):t===`compsolid`?DE(r):OE(r,n)}function WE(e,t,n){let r=UE(e,t,n);return BE(e,r),r}function GE(e,t,n){return aE(e,t),bE(WT(e),n)}var G=2147483647,KE=Math.PI/180,qE=180/Math.PI;function JE(e,t,n,r,i){let a={kind:e,code:t,message:n,cause:r};return i?{...a,suggestion:i}:a}var YE={KERNEL_OPERATION:(e,t,n,r)=>JE(`KERNEL_OPERATION`,e,t,n,r),VALIDATION:(e,t,n,r)=>JE(`VALIDATION`,e,t,n,r),TYPE_CAST:(e,t,n,r)=>JE(`TYPE_CAST`,e,t,n,r),SKETCHER_STATE:(e,t,n,r)=>JE(`SKETCHER_STATE`,e,t,n,r),MODULE_INIT:(e,t,n,r)=>JE(`MODULE_INIT`,e,t,n,r),COMPUTATION:(e,t,n,r)=>JE(`COMPUTATION`,e,t,n,r),IO:(e,t,n,r)=>JE(`IO`,e,t,n,r),QUERY:(e,t,n,r)=>JE(`QUERY`,e,t,n,r),UNSUPPORTED:(e,t,n,r)=>JE(`UNSUPPORTED`,e,t,n,r)};function XE(e,t,n,r=`KERNEL_OPERATION`){try{return O(W(e()))}catch(e){let i=e instanceof Error?e.message:String(e),a=r===`KERNEL_OPERATION`?yo(i):i,o=vo(t);return k(YE[r](t,`${n}: ${a}`,e,o))}}function ZE(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`?yo(i):i,o=vo(t);return k(YE[r](t,`${n}: ${a}`,e,o))}}function QE(e,t,n,r=`KERNEL_OPERATION`){try{var i=NT();let a=i.u(new qT);return XE(()=>e(a),t,n,r)}catch(e){i.e=e}finally{i.d()}}function $E(e,t){let n=U().iterShapes(e,t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=WE(n[e],t);return r}function eD(e,t){let n=U();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 tD(e,t){let n=U();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 nD=new WeakMap;function rD(e){let t=nD.get(e);if(!t)return;nD.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 iD=new WeakSet;function aD(e){let t=e.wrapped,n=nD.get(t);return n||(n={},nD.set(t,n)),iD.has(e)||(iD.add(e),e.onDispose(()=>{rD(t)})),n}function oD(e){return nD.get(e.wrapped)}function sD(e){rD(e.wrapped)}function cD(e){let t=aD(e);if(t.edges)return t.edges;let n=$E(e.wrapped,`edge`);return t.edges=n,n}function lD(e){let t=aD(e);if(t.faces)return t.faces;let n=$E(e.wrapped,`face`);return t.faces=n,n}function uD(e){let t=aD(e);if(t.wires)return t.wires;let n=$E(e.wrapped,`wire`);return t.wires=n,n}function dD(e){let t=aD(e);if(t.vertices)return t.vertices;let n=$E(e.wrapped,`vertex`);return t.vertices=n,n}function fD(e){let t=aD(e);if(t.solids)return t.solids;let n=$E(e.wrapped,`solid`);return t.solids=n,n}function pD(e){let t=aD(e);if(t.shells)return t.shells;let n=$E(e.wrapped,`shell`);return t.shells=n,n}function mD(e){let t=aD(e);if(t.compSolids)return t.compSolids;let n=$E(e.wrapped,`compsolid`);return t.compSolids=n,n}function*hD(e){for(let t of U().iterShapes(e.wrapped,`edge`))yield WE(t,`edge`)}function*gD(e){for(let t of U().iterShapes(e.wrapped,`face`))yield WE(t,`face`)}function*_D(e){for(let t of U().iterShapes(e.wrapped,`wire`))yield WE(t,`wire`)}function*vD(e){for(let t of U().iterShapes(e.wrapped,`vertex`))yield WE(t,`vertex`)}function*yD(e){for(let t of U().iterShapes(e.wrapped,`solid`))yield WE(t,`solid`)}function*bD(e){for(let t of U().iterShapes(e.wrapped,`shell`))yield WE(t,`shell`)}function*xD(e){for(let t of U().iterShapes(e.wrapped,`compsolid`))yield WE(t,`compsolid`)}function SD(e){let t=aD(e);if(t.bounds)return t.bounds;let{min:n,max:r}=U().boundingBox(e.wrapped),i={xMin:n[0],xMax:r[0],yMin:n[1],yMax:r[1],zMin:n[2],zMax:r[2]};return t.bounds=i,i}function CD(e){return oE(U(),e.wrapped)}function wD(e){let t=aD(e);if(t.surfaceType!==void 0)return t.surfaceType;let n=U().surfaceType(e.wrapped);return t.surfaceType=n,n}function TD(e){let t=aD(e);if(t.isValid!==void 0)return t.isValid;let n=U().isValid(e.wrapped);return t.isValid=n,n}function ED(e){return{kind:CD(e),faceCount:eD(e,`face`),edgeCount:eD(e,`edge`),wireCount:eD(e,`wire`),vertexCount:eD(e,`vertex`),valid:TD(e),bounds:SD(e)}}function DD(e){return U().vertexPosition(e.wrapped)}function OD(e){return e.length===2?[e[0],e[1],0]:[e[0],e[1],e[2]]}function kD(e){return[e[0],e[1]]}var AD={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function jD(e){if(typeof e==`string`){let t=AD[e];if(!t)throw Error(`Unknown direction: ${e}`);return t}return e}function MD(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function ND(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function PD(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function FD(e){return[-e[0],-e[1],-e[2]]}function ID(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function LD(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 RD(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function zD(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function BD(e,t){return RD(ND(e,t))}function VD(e){let t=RD(e);return t<1e-10?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function HD(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 UD(e,t=1e-10){return zD(e)<t*t}function WD(e,t){let n=ID(e,t),r=RD(e),i=RD(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 GD(e,t,n){let r=ND(e,t),i=zD(n);return i<1e-20?e:ND(e,PD(n,ID(r,n)/i))}function KD(e,t,n){let r=VD(t),i=Math.cos(n),a=Math.sin(n),o=ID(e,r),s=LD(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 qD=e=>Math.round(e*1e3)/1e3;function JD(e){return`x: ${qD(e[0])}, y: ${qD(e[1])}, z: ${qD(e[2])}`}function YD(e,t=null,n=[0,0,1]){let r=VD(n);if(UD(r))throw Error(`Plane normal must be non-zero`);let i;if(t)i=VD(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?VD([l,u,d]):[1,0,0]}if(UD(i))throw Error(`Plane xDir must be non-zero`);let a=VD(LD(r,i));return{origin:e,xDir:i,yDir:a,zDir:r}}var XD={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 ZD(e,t=[0,0,0]){let n=XD[e];if(!n)return k(P(`UNKNOWN_PLANE`,`Could not find plane ${e}`));let r;return r=typeof t==`number`?PD(n.normal,t):OD(t),O(YD(r,n.xDir,n.normal))}function QD(e,t){return typeof e==`string`?ZD(e,t):O(e)}function $D(e,t){return e&&typeof e!=`string`?{...e}:j(QD(e??`XY`,t))}function eO(e,t){let[n,r]=t;return MD(MD(e.origin,PD(e.xDir,n)),PD(e.yDir,r))}function tO(e,t){return{...e,origin:MD(e.origin,t)}}function nO(e,t,n=[1,0,0]){let r=t*KE,i=KD(e.zDir,n,r),a=KD(e.xDir,n,r),o=VD(LD(i,a));return{origin:e.origin,xDir:a,yDir:o,zDir:i}}var rO={compound:0,solidCompound:1,solid:2,shell:3,face:4,wire:5,edge:6,vertex:7,shape:8},iO=e=>rO[e],aO={vertex:`vertex`,edge:`edge`,wire:`wire`,face:`face`,shell:`shell`,solid:`solid`,solidCompound:`compsolid`,compound:`compound`,shape:`compound`},oO=function*(e,t){let n=U().iterShapes(e,aO[t]);for(let e of n)yield e},sO=e=>U().isNull(e)?k(xo(`NULL_SHAPE`,`This shape has no type, it is null`)):O(e.ShapeType());function cO(e){if(U().isNull(e))return k(xo(`NULL_SHAPE`,`This shape has no type, it is null`));try{return O(U().downcast(e))}catch(e){return k(xo(`NO_WRAPPER`,`Could not find a wrapper for this shape type`,e))}}function lO(e){if(U().isNull(e))return k(xo(`NULL_SHAPE`,`Cannot copy a null shape`));try{return O(U().copyShape(e))}catch(e){return k(xo(`NO_WRAPPER`,`Could not copy this shape`,e))}}function uO(e){return U().isNull(e)?k(xo(`NULL_SHAPE`,`Cannot cast a null shape`)):O(RE(e))}function dO(e){return U().shapeType(e.wrapped)===`compsolid`}function fO(e){return uO(U().fromBREP(e))}var pO={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 mO(e){return O(pO[wD(e)])}function hO(e){return j(mO(e))}function gO(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function _O(e){return RE(U().reverseShape(e.wrapped))}function vO(e){return U().uvBounds(e.wrapped)}function yO(e,t,n){let r=vO(e),i=t*(r.uMax-r.uMin)+r.uMin,a=n*(r.vMax-r.vMin)+r.vMin;return U().pointOnSurface(e.wrapped,i,a)}function bO(e,t){let n=OD(t);return U().uvFromPoint(e.wrapped,n)||[0,0]}function xO(e,t){let n=OD(t);try{let t=n,r=U().uvFromPoint(e.wrapped,t);if(!r)return k(xo(`PROJECTION_FAILED`,`No projection found on the face`));let i=U().projectPointOnFace(e.wrapped,t),a=n[0]-i[0],o=n[1]-i[1],s=n[2]-i[2];return O({uv:r,point:i,distance:Math.sqrt(a*a+o*o+s*s)})}catch(e){return k(xo(`PROJECTION_FAILED`,`Point projection failed: ${e instanceof Error?e.message:String(e)}`))}}function SO(e,t){let n,r;if(t)[n,r]=bO(e,t);else{let t=vO(e);n=.5*(t.uMin+t.uMax),r=.5*(t.vMin+t.vMax)}return U().surfaceNormal(e.wrapped,n,r)}function CO(e){return U().surfaceCenterOfMass(e.wrapped)}function wO(e){return U().getSurfaceAxis(e.wrapped)}function TO(e,t,n=1e-6){let[r,i]=bO(e,t);return U().classifyPointOnFace(e.wrapped,r,i,n)}function EO(e){return RE(U().outerWire(e.wrapped))}function DO(e){return RE(U().removeHolesFromFace(e.wrapped))}function OO(e){let t=EO(e);return Array.from(oO(e.wrapped,`wire`)).map(e=>RE(j(cO(e)))).filter(e=>!U().isSame(e.wrapped,t.wrapped))}function kO(e,t){let n=aD(e),r=new Map;for(let n of tD(e,`face`))r.set(n,t);n.faceOrigins=r}function AO(e){return oD(e)?.faceOrigins}function jO(e,t,n){let r=new Map;for(let e of t){let t=AO(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=aD(n);e.faceOrigins=i}}var MO=100,NO=.985,PO=.1;function FO(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>MO)continue;let u=r-l/MO;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)<NO)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>PO)continue;let u=Math.max(0,i*i+a*a+c*c-l*l);u<o&&(o=u,s=n.origin)}return s}function IO(e,t){let n=new Map;for(let t of e){let e=AO(t);if(e)for(let[t,r]of e)n.set(t,r)}if(n.size===0)return;let r=U(),i=new Map,a=lD(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=AO(n);if(e)for(let i of lD(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=FO(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=aD(t);e.faceOrigins=i}}var LO=new WeakMap,RO=new WeakMap;function zO(e){return LO.has(e.wrapped)}function BO(e){let t=LO.get(e.wrapped);return t||(t=new Map,LO.set(e.wrapped,t)),t}function VO(e){let t=RO.get(e.wrapped);return t||(t=new Map,RO.set(e.wrapped,t)),t}function HO(e,t,n){let r=Array.isArray(t)?t:lD(e).filter(t),i=BO(e),a=i.get(n)??new Set;for(let e of r)a.add(U().hashCode(e.wrapped,G));return i.set(n,a),e}function UO(e,t){let n=LO.get(e.wrapped);if(!n)return[];let r=n.get(t);if(!r||r.size===0)return[];let i=[];for(let t of lD(e)){let e=U().hashCode(t.wrapped,G);r.has(e)&&i.push(t)}return i}function WO(e){let t=new Map,n=LO.get(e.wrapped);if(!n)return t;let r=lD(e),i=new Map;for(let e of r)i.set(U().hashCode(e.wrapped,G),e);for(let[e,r]of n){let n=[];for(let e of r){let t=i.get(e);t&&n.push(t)}n.length>0&&t.set(e,n)}return t}function GO(e,t,n){return VO(e).set(t,n),e}function KO(e,t){return RO.get(e.wrapped)?.get(t)}function qO(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function JO(e,t,n){let r=BO(n);for(let i of t){let t=LO.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)qO(r,t,e)}let o=RO.get(i.wrapped);if(o){let e=VO(n);for(let[t,n]of o)e.has(t)||e.set(t,n)}}}var YO=new WeakMap,XO=new WeakMap;function ZO(e){return YO.has(e.wrapped)||XO.has(e.wrapped)}function QO(e){let t=XO.get(e.wrapped);return t||(t=new Map,XO.set(e.wrapped,t)),t}function $O(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 ek(e,t){return YO.set(e.wrapped,$O(t)),e}function tk(e,t,n){let r=$O(n),i=QO(e);for(let e of t)i.set(U().hashCode(e.wrapped,G),r);return e}function nk(e){return YO.get(e.wrapped)}function rk(e,t){let n=XO.get(e.wrapped);if(n)return n.get(U().hashCode(t.wrapped,G))}function ik(e,t,n){for(let e of t){let t=YO.get(e.wrapped);if(t){YO.set(n.wrapped,t);break}}let r=QO(n);for(let n of t){let t=XO.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 ak(e){return AO(e)!==void 0||zO(e)||ZO(e)}function ok(e){if(!e.some(ak))return[];let t=U(),n=[];for(let r of e){let e=t.iterShapes(r.wrapped,`face`);for(let r of e)n.push(t.hashCode(r,G)),t.dispose(r)}return n}function sk(e,t,n){jO(e,t,n),JO(e,t,n),ik(e,t,n)}function ck(e,t){IO(e,t)}function lk(e,t){let n=U(),r=[...n.iterShapes(e.wrapped,`face`)],i=[...n.iterShapes(t.wrapped,`face`)];if(r.length!==i.length)return;let a=new Map;for(let e=0;e<r.length;e++){let t=r[e],o=i[e];t===void 0||o===void 0||a.set(n.hashCode(t,G),[n.hashCode(o,G)])}for(let e of r)n.dispose(e);for(let e of i)n.dispose(e);sk({modified:a,generated:new Map,deleted:new Set},[e],t)}function uk(e,t){let n=ok([e]),{shape:r,evolution:i}=U().translateWithHistory(e.wrapped,t[0],t[1],t[2],n,G),a=W(r);return sk(i,[e],a),a}function dk(e,t,n=[0,0,0],r=[0,0,1]){let i=ok([e]),{shape:a,evolution:o}=U().rotateWithHistory(e.wrapped,t*KE,i,G,r,n),s=W(a);return sk(o,[e],s),s}function fk(e,t=[0,1,0],n=[0,0,0]){let r=ok([e]),{shape:i,evolution:a}=U().mirrorWithHistory(e.wrapped,n,t,r,G),o=W(i);return sk(a,[e],o),o}function pk(e,t,n=[0,0,0]){let r=ok([e]),{shape:i,evolution:a}=U().scaleWithHistory(e.wrapped,n,t,r,G),o=W(i);return sk(a,[e],o),o}function mk(e,t,n){let r=U().boundingBox(e.wrapped),i=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]],a=n?.auto===!0;function o(e,t,n){return e!==void 0&&t>1e-12?e/t:e===void 0&&a?n:1}let s=1;a&&(t[0]!==void 0&&i[0]>1e-12?s=t[0]/i[0]:t[1]!==void 0&&i[1]>1e-12?s=t[1]/i[1]:t[2]!==void 0&&i[2]>1e-12&&(s=t[2]/i[2]));let c=[o(t[0],i[0],s),o(t[1],i[1],s),o(t[2],i[2],s)];return Math.abs(c[0]-c[1])<1e-6&&Math.abs(c[1]-c[2])<1e-6?O(pk(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 hk(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 gk(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 _k(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 vk(e,t){let n=hk(t);if(!n.ok)return n;let{linear:r,translation:i}=n.value,a=gk(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(_k(r)){let t=ok([e]),{shape:n,evolution:a}=U().generalTransformWithHistory(e.wrapped,r,i,!0,t,G),o=W(n);return sk(a,[e],o),O(o)}let o=W(U().generalTransformNonOrthogonal(e.wrapped,r,i));return ck([e],o),O(o)}function yk(e){let t=e.map(e=>e.type===`translate`?{type:`translate`,x:e.v[0],y:e.v[1],z:e.v[2]}:{type:`rotate`,angle:e.angle,axis:e.axis,center:e.center}),{handle:n,dispose:r}=U().composeTransform(t);return{trsf:n,cleanup:r}}function bk(e,t){let{trsf:n,cleanup:r}=yk(`type`in t?[t]:t),i;try{i=W(U().locate(e.wrapped,n))}finally{r()}return ak(e)&&lk(e,i),i}function xk(e,t){let n=ok([e]),{shape:r,evolution:i}=U().applyComposedTransformWithHistory(e.wrapped,t.trsf,n,G),a=W(r);return sk(i,[e],a),a}function Sk(e){return XE(()=>U().copyShape(e.wrapped),M.CLONE_FAILED,`Failed to clone shape`)}function Ck(e){return ZE(()=>U().toBREP(e.wrapped),M.TO_BREP_FAILED,`Failed to serialize shape to BREP`)}function wk(e){return U().hashCode(e.wrapped,G)}function Tk(e){return U().isNull(e.wrapped)}function Ek(e,t){return U().isSame(e.wrapped,t.wrapped)}function Dk(e,t){return U().isEqual(e.wrapped,t.wrapped)}function Ok(e){return XE(()=>U().simplify(e.wrapped),M.SIMPLIFY_FAILED,`Failed to simplify shape`)}function kk(e){return U().curveType(e.wrapped)}function Ak(e){let[t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function jk(e){let[,t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function Mk(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curvePointAtParam(e.wrapped,i)}function Nk(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curveTangent(e.wrapped,i).tangent}function Pk(e){return U().length(e.wrapped)}function Fk(e){if(kk(e)!==`CIRCLE`)return null;let t=Mk(e,0),n=Mk(e,1/3),r=Mk(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 Ik(e){return U().curveIsClosed(e.wrapped)}function Lk(e){return U().curveIsPeriodic(e.wrapped)}function Rk(e){return U().curvePeriod(e.wrapped)}function zk(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function Bk(e){return W(U().reverseShape(e.wrapped))}function Vk(e,t={}){if(e.length<2)return k(xo(`INTERPOLATE_MIN_POINTS`,`Interpolation requires at least 2 points`));try{let n=W(U().interpolatePoints(e,t));return AE(n)?O(n):(HE(n),k(xo(`INTERPOLATE_NOT_EDGE`,`Interpolation did not produce an edge`)))}catch(e){return k(xo(`INTERPOLATE_FAILED`,`Interpolation failed: ${e instanceof Error?e.message:String(e)}`))}}function Hk(e,t={}){if(e.length<2)return k(xo(`APPROXIMATE_MIN_POINTS`,`Approximation requires at least 2 points`));try{let n=W(U().approximatePoints(e,t));return AE(n)?O(n):(HE(n),k(xo(`APPROXIMATE_NOT_EDGE`,`Approximation did not produce an edge`)))}catch(e){return k(xo(`APPROXIMATE_FAILED`,`Approximation failed: ${e instanceof Error?e.message:String(e)}`))}}function Uk(e,t,n=`arc`){let r=W(U().offsetWire2D(e.wrapped,t,{arc:`arc`,intersection:`intersection`,tangent:`tangent`,chamfer:`intersection`}[n]));return jE(r)?O(r):(HE(r),k(xo(`OFFSET_NOT_WIRE`,`Offset did not produce a Wire`)))}function Wk(e,t,n,r=!1){return`${e}:${t}:${n}:${r}`}function Gk(e,t){return`edge:${e}:${t}`}var Kk=new WeakMap,qk=new WeakMap;function Jk(e,t){let n=Kk.get(e);if(n)return n.get(t)}function Yk(e,t,n){let r=Kk.get(e);r||(r=new Map,Kk.set(e,r)),r.set(t,n)}function Xk(e,t){let n=qk.get(e);if(n)return n.get(t)}function Zk(e,t,n){let r=qk.get(e);r||(r=new Map,qk.set(e,r)),r.set(t,n)}function Qk(){Kk=new WeakMap,qk=new WeakMap}function $k(){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 eA(e,t={}){let n=jo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,skipNormals:a=!1,includeUVs:o=!1,cache:s=!0,signal:c}=t;c?.throwIfAborted();let l=Wk(r,i,a,o);if(s){let t=Jk(e.wrapped,l);if(t)return t}let u=U().mesh(e.wrapped,{tolerance:r,angularTolerance:i,skipNormals:a,includeUVs:o,...c?{signal:c}:{}}),d=AO(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&&Yk(e.wrapped,l,f),f}function tA(e,t={}){let n=jo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,cache:a=!0}=t,o=Gk(r,i);if(a){let t=Xk(e.wrapped,o);if(t)return t}let s=U().meshEdges(e.wrapped,r,i),c={lines:s.lines,edgeGroups:s.edgeGroups.map(e=>({start:e.start,count:e.count,edgeId:e.edgeHash}))};return a&&Zk(e.wrapped,o,c),c}function nA(e,t){return e instanceof Error&&e.message.startsWith(`${t} export failed`)?wo(`${t}_EXPORT_FAILED`,`Failed to write ${t} file`,e):e instanceof WebAssembly.RuntimeError?wo(`${t}_EXPORT_CRASHED`,`${t} export crashed the kernel (${e.message}); the shape likely contains geometry the ${t} writer cannot serialize`,e):wo(`${t}_FILE_READ_ERROR`,`Failed to read exported ${t} file`,e)}function rA(e){let t;try{t=fD(e)}catch{return``}if(t.length<=1)return``;let n=[];return t.forEach((e,t)=>{try{SD(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 iA(e,t){try{return SD(e),null}catch(n){if(n instanceof TypeError)throw n;return wo(`${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${rA(e)}`,n)}}function aA(e){let t=iA(e,`STEP`);if(t)return k(t);try{let t=U().exportSTEP([e.wrapped]);return O(new Blob([t],{type:`application/STEP`}))}catch(e){return k(nA(e,`STEP`))}}function oA(e,t={}){let n=jo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,binary:a=!1}=t,o=iA(e,`STL`);if(o)return k(o);try{U().hasTriangulation(e.wrapped)||U().meshShape(e.wrapped,r,i);let t=U().exportSTL(e.wrapped,a,r,i);return O(new Blob([t],{type:`application/sla`}))}catch(e){return k(nA(e,`STL`))}}function sA(e){try{let t=U().exportIGES([e.wrapped]);return O(new Blob([t],{type:`application/iges`}))}catch(e){return k(wo(`IGES_EXPORT_FAILED`,`Failed to write IGES file`,e))}}function cA(e,t){let n=t?.coarseTolerance??.5,r=t?.fineTolerance??.05,i=t?.angularTolerance??.5;return{coarse:eA(e,{tolerance:n,angularTolerance:i}),fine:eA(e,{tolerance:r,angularTolerance:i*.2})}}function lA(e){let t=SD(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 uA(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)*lA(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 dA(e,t,n){return Math.min(e/t*n,1)}function fA(e,t={}){let n=t.angularTolerance??jo().angularTolerance,r=t.cache??!0,i=uA(e,t),a=Math.min(...i);return i.map(i=>{let o=dA(i,a,n);return{tolerance:i,angularTolerance:o,mesh:eA(e,{tolerance:i,angularTolerance:o,cache:r,...t.signal?{signal:t.signal}:{}})}})}function pA(){return new Promise(e=>{setTimeout(e,0)})}async function mA(e,t={}){let n=t.angularTolerance??jo().angularTolerance,r=t.cache??!0,i=t.meshLevel??((e,n,i)=>eA(e,{tolerance:n,angularTolerance:i,cache:r,...t.signal?{signal:t.signal}:{}})),a=uA(e,t),o=Math.min(...a),s=[];for(let[r,c]of a.entries()){if(t.signal?.aborted)break;let l=dA(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 pA()}return s}function hA(e,t,n){if(t<0||t>=e.length)throw Error(n??`Index ${t} out of bounds (length ${e.length})`);return e[t]}function gA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[0]}function _A(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[e.length-1]}function vA(e){return Array.from(Array(e).keys())}function yA(e){return vA(Math.min(...e.map(e=>e.length))).map(t=>e.map(e=>e[t]))}function bA(e,t){return SE(U().makeLineEdge([...e],[...t]))}function xA(e,t=[0,0,0],n=[0,0,1]){return SE(U().makeCircleEdge([...t],[...n],e))}function SA(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(SE(U().makeEllipseEdge([...n],[...r],e,t,i?[...i]:void 0)))}function CA(e,t,n,r=[0,0,0],i=[0,0,1],a=!1){return CE(U().makeHelixWire(e,t,n,[...r],[...i],a))}function wA(e,t,n){return SE(U().makeArcEdge([...e],[...t],[...n]))}function TA(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(SE(U().makeEllipseArc([...i],[...a],e,t,n,r,o?[...o]:void 0)))}function EA(e,{tolerance:t=.001,smoothing:n=null,degMax:r=6,degMin:i=1}={}){try{let a=e.map(e=>[...e]);return O(SE(U().approximatePoints(a,{tolerance:t,degMin:i,degMax:r,smoothing:n})))}catch(e){return k(N(`BSPLINE_FAILED`,`B-spline approximation failed`,e))}}function DA(e,{periodic:t=!1,tolerance:n=1e-7}={}){try{let r=e.map(e=>[...e]);return O(SE(U().interpolatePoints(r,{periodic:t,tolerance:n})))}catch(e){return k(N(`BSPLINE_INTERP_FAILED`,`B-spline interpolation failed`,e))}}function OA(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(SE(U().makeBezierEdge(t)))}function kA(e,t,n){return SE(U().makeTangentArc([...e],[...t],[...n]))}function AA(e){try{return O(CE(U().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 jA(e,t){try{let n=U().makeFace(e.wrapped,!0);if(t&&t.length>0){let e=FA(wE(n),t);return gE(e)?O(e):k(P(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}let r=wE(n);return gE(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 MA(e){return jA(EO(e))}function NA(e,t){return wE(U().makeFaceOnSurface(e.wrapped,t.wrapped))}function PA(e){try{return Ya(uO(U().makeNonPlanarFace(e.wrapped)),e=>ME(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 FA(e,t){return wE(U().addHolesInFace(e.wrapped,t.map(e=>e.wrapped)))}function IA(e){try{var t=NT();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 qT);return Ya(AA(yA([e,n]).map(([e,t])=>r.register(bA(e,t)))),e=>jA(r.register(e)))}catch(e){t.e=e}finally{t.d()}}function LA(e,t){return U().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function RA(e,t,n,r,i){let a=RE(e);if(!IE(a)){let o=sE(a).toUpperCase();return BE(e,a),HE(a),k(xo(t,`${n}. Got ${o} instead.`,void 0,i?{diagnostics:i}:void 0,r))}return BE(e,a),O(a)}function zA(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=LA(e,`fuse: first operand`);if(A(c))return c;let l=LA(t,`fuse: second operand`);if(A(l))return l;if(!s)return RA(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);let u=ok([e,t]),{shape:d,evolution:f,diagnostics:p}=U().fuseWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(U().isNull(d))return U().dispose(d),console.warn(`brepjs: fuse history path produced null result; retrying without evolution tracking.`,p),RA(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);console.warn(`brepjs: fuse reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=RA(d,`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`,`Common causes: overlapping coplanar faces, zero-thickness geometry, or non-manifold input. Try autoHeal() on inputs first.`,p);return m.ok&&sk(f,[e,t],m.value),m}function BA(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=LA(e,`cut: base`);if(A(c))return c;let l=LA(t,`cut: tool`);if(A(l))return l;if(!s)return RA(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);let u=ok([e,t]),{shape:d,evolution:f,diagnostics:p}=U().cutWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(U().isNull(d))return U().dispose(d),console.warn(`brepjs: cut history path produced null result; retrying without evolution tracking.`,p),RA(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);console.warn(`brepjs: cut reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=RA(d,`CUT_NOT_3D`,`Cut did not produce a 3D shape`,`Common causes: tool does not fully intersect the base, or produces a zero-thickness sliver. Ensure the tool extends through the shape.`,p);return m.ok&&sk(f,[e,t],m.value),m}function VA(e,t,{simplify:n=!1,signal:r,fuzzyValue:i,unsafe:a,trackEvolution:o=!0}={}){if(r?.aborted)throw r.reason;let s=LA(e,`intersect: first operand`);if(A(s))return s;let c=LA(t,`intersect: second operand`);if(A(c))return c;if(!o)return RA(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);let l=ok([e,t]),{shape:u,evolution:d,diagnostics:f}=U().intersectWithHistory(e.wrapped,t.wrapped,l,G,{simplify:n,fuzzyValue:i});if(f.hasErrors){if(U().isNull(u))return U().dispose(u),console.warn(`brepjs: intersect history path produced null result; retrying without evolution tracking.`,f),RA(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);console.warn(`brepjs: intersect reported OCCT warnings/errors but produced a shape. Continuing with result.`,f)}let p=RA(u,`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`,`Shapes may not overlap. Verify they share a common volume before intersecting.`,f);return p.ok&&sk(d,[e,t],p.value),p}function HA(e,t,n,r,i,a,o,s){if(o?.aborted)throw o.reason;let c=n-t;if(c===1)return O(hA(e,t));if(c===2)return zA(hA(e,t),hA(e,t+1),{optimisation:r,simplify:!1,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}});let l=t+Math.ceil(c/2),u=HA(e,t,l,r,i,a,o,s);if(A(u))return u;let d=HA(e,l,n,r,i,a,o,s);return A(d)?d:zA(u.value,d.value,{optimisation:r,simplify:i,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}})}function UA(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(gA(e));for(let t=0;t<e.length;t++){let n=LA(hA(e,t),`fuseAll: shape at index ${t}`);if(A(n))return n}if(r===`native`){let o=RA(U().fuseAll(e.map(e=>e.wrapped),{optimisation:t,simplify:n,strategy:r,fuzzyValue:a,...i?{signal:i}:{}}),`FUSE_ALL_NOT_3D`,`fuseAll did not produce a 3D shape`);return o.ok&&s&&ck(e,o.value),o}return HA(e,0,e.length,t,n,s,i,a)}function WA(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=LA(e,`cutAll: base`);if(A(c))return c;for(let e=0;e<t.length;e++){let n=LA(hA(t,e),`cutAll: tool at index ${e}`);if(A(n))return n}let l=[e,...t],u=RA(U().cutAll(e.wrapped,t.map(e=>e.wrapped),{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_ALL_NOT_3D`,`cutAll did not produce a 3D shape`);return u.ok&&s&&ck(l,u.value),u}function GA(e,t){let n=U(),r=PD(e.xDir,t),i=PD(e.yDir,t),a=PD(e.xDir,-t),o=PD(e.yDir,-t),s=e.origin,c=[...MD(MD(s,a),o)],l=[...MD(MD(s,r),o)],u=[...MD(MD(s,r),i)],d=[...MD(MD(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 KA(e,t,{approximation:n=!0,planeSize:r=1e4}={}){if(U().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`section: shape is a null shape`));let i=GA(typeof t==`string`?j(QD(t)):t,r);try{return O(W(U().section(e.wrapped,i,n)))}catch(e){let n=e instanceof Error?e.message:String(e),r=typeof t==`string`?t:`custom`;return k(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{U().dispose(i)}}function qA(e){let t=U(),n=new Map,r=new Map;for(let i of e){let e=dD(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 JA(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 YA(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=JA(i,t,n);for(;o;)e===0?r.push(o.edge):r.unshift(o.edge),i=o.nextTip,o=JA(i,t,n)}return r}function XA(e){let t=U(),n=qA(e),r=new Set,i=[];for(let a of e){if(r.has(a))continue;let e=YA(a,n,r);try{let n=t.makeWire(e.map(e=>e.wrapped));i.push(W(n))}catch{}}return i}function ZA(e){let t=U(),n=0,r=-1;for(let i=0;i<e.length;i++){let a=e[i];if(!a)continue;let o=t.boundingBox(a.wrapped),s=o.max[0]-o.min[0],c=o.max[1]-o.min[1],l=o.max[2]-o.min[2],u=s*s+c*c+l*l;u>r&&(r=u,n=i)}return n}function QA(e,t,n={}){let r=KA(e,t,n);if(!r.ok)return r;let i=uD(r.value);if(i.length===0){let e=cD(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(...XA(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=ZA(i),o=hA(i,a),s=i.filter((e,t)=>t!==a);return jA(o,s.length>0?s:void 0)}function $A(e,t){if(t.length===0)return O(e);if(U().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(U().isNull(hA(t,e).wrapped))return k(P(M.NULL_SHAPE_INPUT,`splitShape: tool at index ${e} is a null shape`));try{return O(W(U().split(e.wrapped,t.map(e=>e.wrapped))))}catch(e){let n=e instanceof Error?e.message:String(e);return k(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 ej(e,t,n={}){let r=[];for(let i of t){let t=KA(e,i,n);if(A(t))return t;r.push(t.value)}return O(r)}function tj(e,t,n){if(t.length===0)return O(e);let r=n?.optimisation===`commonFace`?1:n?.optimisation===`sameFace`?2:0,i=U(),a=t.map(e=>({op:e.op,tool:e.tool.wrapped}));try{let o=i.booleanPipeline?.(e.wrapped,a,{glueMode:r});if(o===void 0)return nj(e,t,n);if(o===null)return k(N(`BOOLEAN_PIPELINE_FAILED`,`Boolean pipeline returned null shape`));let s=W(o);return IE(s)?O(s):(HE(s),k(xo(`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 nj(e,t,n){let r=e,i={...n?.optimisation?{optimisation:n.optimisation}:{},unsafe:!0};for(let e of t){let t=e.op===`fuse`?zA(r,e.tool,i):e.op===`cut`?BA(r,e.tool,i):VA(r,e.tool,i);if(A(t))return t;r=j(t)}return O(r)}function rj(e){return W(U().sew(e.map(e=>e.wrapped)))}function ij(e,t=!1){let n=rj(e);return!t&&!NE(n)?k(xo(`WELD_NOT_SHELL`,`Could not make a shell from faces and shells`)):O(n)}function aj(e,t,n=[0,0,0],r=[0,0,1]){return EE(U().makeCylinder(e,t,[...n],[...r]))}function oj(e){return EE(U().makeSphere(e))}function sj(e,t,n,r=[0,0,0],i=[0,0,1]){return EE(U().makeCone(e,t,n,[...r],[...i]))}function cj(e,t,n=[0,0,0],r=[0,0,1]){return EE(U().makeTorus(e,t,[...n],[...r]))}function lj(e,t,n){return EE(U().makeEllipsoid(e,t,n))}function uj(e){return xE(U().makeVertex(e[0],e[1],e[2]))}function dj(e,t,n=1e-6){return Ya(cO(U().offset(e.wrapped,t,n)),e=>Ya(uO(e),e=>IE(e)?O(e):k(xo(`OFFSET_NOT_3D`,`Could not offset to a 3d shape`))))}function fj(e){return OE(U().makeCompound(e.map(e=>e.wrapped)))}function pj(e){try{var t=NT();let n=t.u(rj(e)),r=W(U().solidFromShell(n.wrapped));return PE(r)?O(r):(HE(r),k(xo(`SOLID_BUILD_FAILED`,`Could not make a solid of faces and shells`)))}catch(e){t.e=e}finally{t.d()}}function mj(e){return{position:e.vertices,normal:e.normals,index:e.triangles}}function hj(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 gj(e){return{position:e.lines}}function _j(e,t){return{coarse:mj(e.coarse),fine:mj(e.fine),coarseDistance:t?.coarse??50,fineDistance:t?.fine??0}}function vj(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:mj(e.mesh),distance:r?.[t]??(i-t)*n}))}function yj(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=U(),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=cO(i);if(A(a))return U().dispose(i),a;let o=W(a.value);return BE(i,o),IE(o)?O(o):(HE(o),k(xo(`CHAMFER_ANGLE_NOT_3D`,`chamferDistAngle did not produce a 3D shape`)))}function bj(e){let t=U();return t.getNurbsCurveData?t.getNurbsCurveData(e.wrapped):null}function xj(e){let t=U();return t.getNurbsSurfaceData?t.getNurbsSurfaceData(e.wrapped):null}var Sj={cut:BA,cutAll:WA,fuse:zA,fuseAll:UA};function Cj(e){return{totalInputs:e.totalInputs,batchAttempts:e.batchAttempts,batchSucceeded:e.batchSucceeded,singletonFallbacks:e.singletonFallbacks,failedInputs:[...e.failedInputs].sort((e,t)=>e-t)}}function wj(e,t,n={}){return Tj(Sj,e,t,n)}function Tj(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=Ej(e,t,n,0,r,i);return A(a)?a:O({shape:a.value,telemetry:Cj(i)})}function Ej(e,t,n,r,i,a){if(n.length===0)return O(t);if(n.length===1)return Dj(e,t,n,r,i,a);a.batchAttempts++;let o=Mj(()=>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=Ej(e,t,n.slice(0,s),r,i,a);return c.ok?Ej(e,c.value,n.slice(s),r+s,i,a):c}function Dj(e,t,n,r,i,a){a.singletonFallbacks++;let o=gA(n),s=Mj(()=>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 Oj(e,t={}){return kj(Sj,e,t)}function kj(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=Aj(e,t,0,n,r);return A(i)?i:O({shape:i.value,telemetry:Cj(r)})}function Aj(e,t,n,r,i){if(t.length===1)return O(gA(t));i.batchAttempts++;let a=Mj(()=>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 jj(e,Aj(e,t.slice(0,o),n,r,i),Aj(e,t.slice(o),n+o,r,i),t,n,o,r,i)}function jj(e,t,n,r,i,a,o,s){if(t.ok&&n.ok){s.singletonFallbacks++;let c=Mj(()=>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 Mj(e){try{return e()}catch{return null}}function Nj(e,t,n){return U().checkBoolean(e.wrapped,t.wrapped,n)}function Pj(e,t){return U().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Fj(e,t){return U().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Ij(e,t,n,r){let i=RE(e);if(!IE(i)){let a=sE(i).toUpperCase();return BE(e,i),HE(i),k(xo(t,`${n}. Got ${a} instead.`,void 0,void 0,r))}return BE(e,i),O(i)}function Lj(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>r.get(U().hashCode(e,2147483647))??1}}function Rj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Pj(e,`fuseWithEvolution: first operand`);if(A(o))return o;let s=Pj(t,`fuseWithEvolution: second operand`);if(A(s))return s;let c=ok([e,t]),{shape:l,evolution:u}=U().fuseWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Ij(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?(sk(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function zj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Pj(e,`cutWithEvolution: base`);if(A(o))return o;let s=Pj(t,`cutWithEvolution: tool`);if(A(s))return s;let c=ok([e,t]),{shape:l,evolution:u}=U().cutWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Ij(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?(sk(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function Bj(e,t,{simplify:n=!1,signal:r,fuzzyValue:i}={}){if(r?.aborted)throw r.reason;let a=Pj(e,`intersectWithEvolution: first operand`);if(A(a))return a;let o=Pj(t,`intersectWithEvolution: second operand`);if(A(o))return o;let s=ok([e,t]),{shape:c,evolution:l}=U().intersectWithHistory(e.wrapped,t.wrapped,s,G,{simplify:n,fuzzyValue:i}),u=Ij(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?(sk(l,[e,t],u.value),O({shape:u.value,evolution:l})):u}function Vj(e,t,n){let r=Fj(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??cD(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=Lj(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=ok([e]),{shape:o,evolution:s}=U().filletWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return IE(c)?(sk(s,[e],c),O({shape:c,evolution:s})):(HE(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 Hj(e,t,n){let r=Fj(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??cD(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=Lj(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=ok([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return IE(c)?(sk(s,[e],c),O({shape:c,evolution:s})):(HE(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 Uj(e,t,n,r=.001){let i=Fj(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=ok([e]),{shape:a,evolution:o}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,i,G,r),s=W(a);return IE(s)?(sk(o,[e],s),O({shape:s,evolution:o})):(HE(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 Wj(e,t,n){try{let r=W(U().positionOnCurve(e.wrapped,t.wrapped,n));return IE(r)?O(r):(HE(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 Gj(e,t){return U().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Kj(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 qj(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>{let t=r.get(U().hashCode(e,G));if(t===void 0)throw Error(`fillet/chamfer: edge hash not found — possible hash collision`);return t}}}function Jj(e,t,n,r,i){let a=W(t);return IE(a)?(sk(e,n,a),O(a)):(HE(a),k(N(r,i)))}function Yj(e,t){if(typeof t!=`function`)return{filteredFaces:[...e],kernelAngle:t};let n=[],r=new Map;for(let i of e){let e=t(i);e===null||e===0||Math.abs(e)>=90||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return{filteredFaces:n,kernelAngle:e=>{let t=r.get(U().hashCode(e,G));if(t===void 0)throw Error(`draft: face hash not found — possible hash collision`);return t}}}function Xj(e,t){let n=Gj(e,`thicken: shape`);if(A(n))return n;try{let n=ok([e]),{shape:r,evolution:i}=U().thickenWithHistory(e.wrapped,t,n,G),a=W(r);return sk(i,[e],a),O(a)}catch(e){return k(N(`THICKEN_FAILED`,`Thicken operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function Zj(e,t,n){let r=Gj(e,`fillet: shape`);if(A(r))return r;let i=Kj(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??cD(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=qj(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 Qj(e,t,n,{trackEvolution:r=!0}={}){let i=Zj(e,t,n);if(A(i))return i;let{filteredEdges:a,kernelRadius:o,selectedCount:s}=i.value;try{let t=a.map(e=>e.wrapped);if(!r){let n=W(U().fillet(e.wrapped,t,o));return IE(n)?O(n):k(N(M.FILLET_NOT_3D,`Fillet result is not a 3D shape`))}let n=ok([e]),{shape:i,evolution:s}=U().filletWithHistory(e.wrapped,t,o,n,G);return Jj(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 $j(e,t,n){let r=Gj(e,`chamfer: shape`);if(A(r))return r;let i=Kj(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??cD(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=qj(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=ok([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,i,G);return Jj(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 eM(e,t,n,r=.001,{trackEvolution:i=!0}={}){let a=Gj(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=W(U().shell(e.wrapped,t.map(e=>e.wrapped),n,r));return IE(i)?O(i):k(N(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}let a=ok([e]),{shape:o,evolution:s}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,a,G,r),c=W(o);return IE(c)?(sk(s,[e],c),O(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 tM(e,t,n=1e-6){let r=Gj(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=ok([e]),{shape:i,evolution:a}=U().offsetWithHistory(e.wrapped,t,r,G,n),o=W(i);return IE(o)?(sk(a,[e],o),O(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 nM(e,t,n){let r=Gj(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 rM(e,t,n,r,i){let a=nM(e,t,i);if(a)return a;try{let{filteredFaces:a,kernelAngle:o}=Yj(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=ok([e]),{shape:c,evolution:l}=U().draftWithHistory(e.wrapped,a.map(e=>e.wrapped),[n[0],n[1],n[2]],[r[0],r[1],r[2]],o,s,G);return Jj(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 iM(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=U();try{let i=JSON.stringify({edge:r.hashCode(t.wrapped,G),radii:n.map(e=>({param:e.param,radius:e.radius}))}),a=W(r.filletVariable(e.wrapped,i));return IE(a)?PE(a)?O(a):(HE(a),k(N(M.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a solid`))):(HE(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 aM(e){return TD(e)}function oM(e){if(!PE(e))return k(P(`NOT_A_SOLID`,`Input shape is not a solid`));let t=aM(e);try{let n=U().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=W(n);return PE(r)?(sD(r),aM(r)?O(r):(HE(r),k(N(`HEAL_SOLID_INCOMPLETE`,`Healed result is still invalid after ShapeFix_Solid`)))):(HE(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 sM(e){if(!ME(e))return k(P(`NOT_A_FACE`,`Input shape is not a face`));try{let t=W(U().healFace(e.wrapped));return ME(t)?O(t):(HE(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 cM(e,t){if(!jE(e))return k(P(`NOT_A_WIRE`,`Input shape is not a wire`));try{let n=W(U().healWire(e.wrapped,t?.wrapped));return jE(n)?O(n):(HE(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 lM(e){return PE(e)?oM(e):ME(e)?sM(e):jE(e)?cM(e):O(e)}function uM(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(aM(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=uD(e).length,u=lD(e).length,d=e,f=!1,p=t=>{let n=d;d=t,n!==e&&n.wrapped!==t.wrapped&&HE(n)};if(o!==void 0)try{p(W(U().sew([d.wrapped],o))),s.push(`Applied sewing with tolerance ${o}`),c.push({name:`sew`,attempted:!0,succeeded:!0,detail:`tolerance=${o}`})}catch(e){let t=e instanceof Error?e.message:String(e);s.push(`Sewing failed: ${t}`),c.push({name:`sew`,attempted:!0,succeeded:!1,detail:t})}if(a&&n){let e=uD(d),t=0;for(let n of e)try{U().fixSelfIntersection(n.wrapped),t++}catch{}s.push(`Self-intersection fix: ${t}/${e.length} wires`),c.push({name:`fixSelfIntersection`,attempted:!0,succeeded:t>0,detail:`${t}/${e.length} wires fixed`})}if(PE(d)&&i||ME(d)&&r||jE(d)&&n){let t=lM(d);Ka(t)?(p(t.value),PE(e)?(f=!0,s.push(`Applied ShapeFix_Solid`),c.push({name:`healSolid`,attempted:!0,succeeded:!0})):ME(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=uD(d).length,h=lD(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=aM(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 dM(e){try{return O(W(U().fixShape(e.wrapped)))}catch(e){return k(N(M.FIX_SHAPE_FAILED,`ShapeFix_Shape failed`,e))}}function fM(e){try{let t=W(U().solidFromShell(e.wrapped));return PE(t)?aM(t)?O(t):(HE(t),k(N(M.SOLID_FROM_SHELL_FAILED,`solidFromShell produced an invalid solid`))):(HE(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 pM(e){try{let t=W(U().fixSelfIntersection(e.wrapped));return jE(t)?O(t):(HE(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 mM(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(U().buildExtrusionLaw(t,e,n).Trim(0,e,1e-6))}function hM(e,t){let n=U(),r=n.makeLineEdge([...e],[...t]),i=n.makeWire([r]);return n.dispose(r),W(i)}function gM(e,t,n,r,i,a=!1){return W(U().makeHelixWire(e,t,n,[...r],[...i],a))}function _M(e){let t=W(e.shape),n=W(e.firstShape),r=W(e.lastShape),i=()=>{HE(t),HE(n),HE(r)};return IE(t)?jE(n)?jE(r)?O([t,n,r]):(i(),k(xo(`SWEEP_END_NOT_WIRE`,`Sweep did not produce an end Wire`))):(i(),k(xo(`SWEEP_START_NOT_WIRE`,`Sweep did not produce a start Wire`))):(i(),k(xo(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function vM(e,t,n={},r=!1){if(n.mode===`simple`&&!r){let n=W(U().simplePipe(e.wrapped,t.wrapped));return IE(n)?O(n):(HE(n),k(xo(`SWEEP_NOT_3D`,`Simple pipe did not produce a 3D shape`)))}let{frenet:i=!1,auxiliarySpine:a,law:o=null,transitionMode:s=`right`,withContact:c,support:l,forceProfileSpineOthogonality:u,tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h}=n,g=U(),_=s===`round`?!0:!!u,v=g.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:s,contact:!!c,correction:_,frenet:i,shellMode:r,...a?.wrapped?{auxiliary:a.wrapped}:{},...o===null?{}:{law:o},...l===null?{}:{support:l},tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h});if(r&&typeof v==`object`&&`firstShape`in v)return _M(v);let y=W(v);return IE(y)?O(y):(HE(y),k(xo(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function yM(e,t,n,r){return vM(e,hM(t,MD(t,n)),{support:r})}function bM(e,t,n,r,i=!1){try{var a=NT();let o=RD(n);if(o<1e-10)return k(P(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let s=MD(t,n),c=a.u(hM(t,s)),l=null;if(r){let e=mM(o,r);if(A(e))return e;l=e.value}return vM(e,c,{law:l},i)}catch(e){a.e=e}finally{a.d()}}function xM(e,t,n,r,i,a=!1){try{var o=NT();if(Math.abs(t)<1e-10)return k(P(`ZERO_TWIST_ANGLE`,`Twist angle cannot be zero`));let s=RD(r);if(s<1e-10)return k(P(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let c=MD(n,r),l=o.u(hM(n,c)),u=t<0,d=360/Math.abs(t)*s,f=o.u(gM(d,s,1,n,r,u)),p=null;if(i){let e=mM(s,i);if(A(e))return e;p=e.value}return vM(e,l,{auxiliarySpine:f,law:p},a)}catch(e){o.e=e}finally{o.d()}}function SM(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 CM(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 wM(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=SM(e);if(o)return k(o);try{let n=U(),o=CM(e,t,n);if(A(o))return o;let s=o.value,c=[],l=[];try{for(let r=0;r<e.length;r++){let i=s[r],a=e[r];if(i===void 0||a===void 0)continue;let o=n.positionOnCurve(a.wire.wrapped,t.wrapped,i);c.push(o),l.push(n.downcast(o,`wire`))}let o=W(n.loftAdvanced(l,{solid:r,ruled:i,tolerance:a}));return IE(o)?O(o):(HE(o),k(xo(`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 TM(e,t,n,r={}){let{transition:i=`transformed`,solid:a=!0,tolerance:o}=r;try{let r=U(),s=!a,c=n.length>0?n[0]?.wrapped:void 0,l=r.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:i,...c?{auxiliary:c}:{},shellMode:s,...o===void 0?{}:{tolerance:o,boundTolerance:o}}),u=W(typeof l==`object`&&`shape`in l?l.shape:l);return IE(u)?O(u):(HE(u),k(xo(`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 EM(e,t){if(U().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`extrude: face is a null shape`));if(RD(t)<1e-10)return k(P(`EXTRUDE_ZERO_VECTOR`,`extrude: extrusion vector has zero length`));try{let n=U(),r=RD(t),i=VD(t),a=n.extrude(e.wrapped,[...i],r),o=EE(n.downcast(a,`solid`));return BE(a,o),O(o)}catch(e){return k(N(`EXTRUDE_FAILED`,`Extrusion operation failed`,e,{operation:`extrude`,vectorLength:RD(t)}))}}function DM(e,t=[0,0,0],n=[0,0,1],r=2*Math.PI){if(U().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`revolve: face is a null shape`));try{let i=W(U().revolveVec(e.wrapped,[...t],[...n],r));return IE(i)?O(i):(HE(i),k(xo(`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 OM(e){if(e.length===0)return O([]);let t=U(),n=[];for(let t=0;t<e.length;t++){let r=e[t];if(!r)continue;let i=typeof r.height==`number`?[0,0,r.height]:r.height,a=RD(i);if(a<1e-10)return k(P(`EXTRUDE_ALL_ZERO_VECTOR`,`extrudeAll: entry ${t} has zero-length extrusion vector`));let o=[...VD(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=EE(t.downcast(e,`solid`));return BE(e,n),n}))}catch(e){return k(N(`EXTRUDE_ALL_FAILED`,`Batch extrusion operation failed`,e))}}function kM(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=U(),s=n?o.makeVertex(...OD(n)):void 0,c=r?o.makeVertex(...OD(r)):void 0;try{let n=W(o.loftAdvanced(e.map(e=>e.wrapped),{solid:!a,ruled:t,tolerance:i,...s?{startVertex:s}:{},...c?{endVertex:c}:{}}));return IE(n)?O(n):(HE(n),k(xo(`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 AM(e){if(e.length===0)return O([]);let t=U(),n=[],r=e.map(e=>{let r=e.startPoint?t.makeVertex(...OD(e.startPoint)):void 0,i=e.endPoint?t.makeVertex(...OD(e.endPoint)):void 0;return r&&n.push(r),i&&n.push(i),{wires:e.wires.map(e=>e.wrapped),solid:!0,ruled:e.ruled??!0,tolerance:e.tolerance??1e-6,startVertex:r,endVertex:i}});try{let e=t.loftBatch?.(r)??r.map(e=>t.loftAdvanced(e.wires,{solid:e.solid,ruled:e.ruled,tolerance:e.tolerance,startVertex:e.startVertex,endVertex:e.endVertex})),n=[];for(let t of e){let e=W(t);if(!IE(e))return HE(e),k(xo(`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 jM=new WeakMap;function MM(e,t){return jM.get(e)?.get(t)}function NM(e,t,n){let r=jM.get(e);r||(r=new Map,jM.set(e,r)),r.set(t,n)}function PM(e){return U().isNull(e.wrapped)}function FM(e){return k(P(M.NULL_SHAPE_INPUT,`${e}: shape is a null shape`))}function IM(e){let t=MM(e.wrapped,`volume`);if(t)return O(t);if(PM(e))return FM(`measureVolumeProps`);let n=U(),r=n.shapeType(e.wrapped);if(r!==`solid`&&r!==`compsolid`&&r!==`compound`){let t={mass:0,volume:0,centerOfMass:[0,0,0]};return NM(e.wrapped,`volume`,t),O(t)}let i=n.volume(e.wrapped),a=ZE(()=>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 NM(e.wrapped,`volume`,o),O(o)}function LM(e){let t=MM(e.wrapped,`surface`);if(t)return O(t);if(PM(e))return FM(`measureSurfaceProps`);let n=U(),r=n.area(e.wrapped),i=ZE(()=>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 NM(e.wrapped,`surface`,a),O(a)}function RM(e){let t=MM(e.wrapped,`linear`);if(t)return O(t);if(PM(e))return FM(`measureLinearProps`);let n=U(),r=n.length(e.wrapped),i={mass:r,length:r,centerOfMass:n.linearCenterOfMass(e.wrapped)};return NM(e.wrapped,`linear`,i),O(i)}function zM(e){let t=IM(e);return t.ok?O(t.value.mass):t}function BM(e){let t=LM(e);return t.ok?O(t.value.mass):t}function VM(e){let t=RM(e);return t.ok?O(t.value.mass):t}function HM(e,t){return PM(e)||PM(t)?FM(`measureDistance`):O(U().distance(e.wrapped,t.wrapped).value)}function UM(e,t){if(PM(e)||PM(t))return FM(`measureDistanceProps`);let n=U().distance(e.wrapped,t.wrapped);return O({distance:n.value,point1:n.point1,point2:n.point2})}function WM(e){if(PM(e))return FM(`createDistanceQuery`);let t=U().createDistanceQuery(e.wrapped);return O({distanceTo(e){return PM(e)?FM(`createDistanceQuery.distanceTo`):O(t.distanceTo(e.wrapped).value)},dispose(){t.dispose()}})}function GM(e,t,n){if(PM(e))return FM(`measureCurvatureAt`);let r=U().surfaceCurvature(e.wrapped,t,n);return O({mean:r.mean,gaussian:r.gaussian,maxCurvature:r.max,minCurvature:r.min,maxDirection:r.maxDirection,minDirection:r.minDirection})}function KM(e){if(PM(e))return FM(`measureCurvatureAtMid`);let t=vO(e),n=(t.uMin+t.uMax)/2,r=(t.vMin+t.vMax)/2,i=U().surfaceCurvature(e.wrapped,n,r);return O({mean:i.mean,gaussian:i.gaussian,maxCurvature:i.max,minCurvature:i.min,maxDirection:i.maxDirection,minDirection:i.minDirection})}function qM(e,t){return e.map(e=>GE(e,t))}function JM(e,t){let n=U(),r=n.iterShapes(e,t),i=[],a=new Map;for(let e of r){let r=n.hashCode(e,G),o=a.get(r);if(o?.some(t=>n.isSame(t,e))){n.dispose(e);continue}let s=WE(e,t);i.push(s),o?o.push(s.wrapped):a.set(r,[s.wrapped])}return i}function YM(e){let t=U(),n=new Map;for(let r of e){let e=t.hashCode(r.wrapped,G),i=n.get(e);i?i.push(r):n.set(e,[r])}return n}function XM(e,t,n){let r=U();return e.get(n)?.find(e=>r.isSame(e.wrapped,t))}function ZM(e){let t=aD(e);if(t.edgeToFaces)return t.edgeToFaces;let n=U(),r=lD(e),i=YM(cD(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=XM(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 QM(e){let t=aD(e);if(t.vertexToFaces)return t.vertexToFaces;let n=U(),r=lD(e),i=YM(dD(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=XM(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 $M(e,t){let n=U(),r=ZM(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 qM(o,`face`)}function eN(e,t){let n=U(),r=QM(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 qM(o,`face`)}function tN(e){return JM(e.wrapped,`edge`)}function nN(e){return JM(e.wrapped,`vertex`)}function rN(e){return JM(e.wrapped,`wire`)}function iN(e){return JM(e.wrapped,`vertex`)}function aN(e,t){let n=U(),r=ZM(e),i=JM(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 qM(a,`face`)}var oN=new Map;function sN(e,t){let n=U(),r=ST()??``;if(oN.get(r)!==!1){let i;try{i=n.sharedEdges(e.wrapped,t.wrapped);let a=i.map(e=>WE(e,`edge`));return oN.set(r,!0),a}catch(e){if(i)for(let e of i)n.dispose(e);if(!l(e))throw e;oN.set(r,!1)}}return cN(e,t)}function cN(e,t){let n=U(),r=n.iterShapes(e.wrapped,`edge`),i=n.iterShapes(t.wrapped,`edge`),a=new Map;for(let e of i){let t=n.hashCode(e,G),r=a.get(t);r||(r=[],a.set(t,r)),r.push(e)}let o=[];for(let e of r)a.get(n.hashCode(e,2147483647))?.some(t=>n.isSame(e,t))?o.push(WE(e,`edge`)):n.dispose(e);for(let e of i)n.dispose(e);return o}var lN=new Map;function uN(e,t){let n=U(),r=ST()??``;if(lN.get(r)!==!1)try{let i=n.adjacentFaces(e.wrapped,t.wrapped);lN.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;lN.set(r,!1)}return aN(e,t).map(e=>n.hashCode(e.wrapped,G))}function dN(e,t){let n=0,r=hO(t);if(e.surfaceType!==void 0)if(r===e.surfaceType)n+=1;else return-1/0;if(e.normal!==void 0){let r=SO(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=CO(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=BM(t);if(r.ok&&r.value>0){let t=Math.abs(Math.log(e.area/r.value));t>1&&(n-=t)}}return n}function fN(e){let t=hO(e),n=SO(e),r=CO(e),i=BM(e);return{entityType:`face`,surfaceType:t,normal:n,centroid:r,area:i.ok?i.value:void 0}}var pN=.9;function mN(e){if(e[2]>pN)return`box:top`;if(e[2]<-.9)return`box:bottom`;if(e[1]>pN)return`box:back`;if(e[1]<-.9)return`box:front`;if(e[0]>pN)return`box:right`;if(e[0]<-.9)return`box:left`}function hN(e,t){if(hO(t)!==`PLANE`)return;let n=SO(t)[2];if(n>pN)return`${e}:top`;if(n<-.9)return`${e}:bottom`}function gN(e){return hO(e)===`CYLINDRE`?`cylinder:lateral`:hN(`cylinder`,e)}function _N(e){return hO(e)===`CONE`?`cone:lateral`:hN(`cone`,e)}function vN(e){return hO(e)===`SPHERE`?`sphere:surface`:void 0}var yN={box:e=>mN(SO(e)),cylinder:gN,cone:_N,sphere:vN};function bN(e,t){let n=new Map,r=yN[t],i=U(),a=0;for(let o of i.iterShapes(e.wrapped,`face`)){let e=UE(o,`face`);try{let i=r?.(e),o=i!==void 0&&!n.has(i)?i:`${t}:face_${a}`;n.set(o,[wk(e)]),a++}finally{VE(e,o)}}return n}function xN(e,t,n){return{origin:e,role:t,hint:fN(n)}}function SN(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 CN(e,t,n){let r=e.get(t);if(!r)return e;let i=new Map;for(let[e,t]of r){let r=SN(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 wN=.1,TN=.5;function EN(e,t,n){let r=-1/0,i,a=-1/0,o=[];for(let s of t){let t=n(e,s);t>TN&&o.push([s,t]),t>r?(a=r,r=t,i=s):t>a&&(a=t)}return i!==void 0&&r>TN?r-a<wN&&o.length>1?{kind:`ambiguous`,candidates:o.filter(([,e])=>e>=r-wN).map(([e])=>e)}:{kind:`match`,face:i}:{kind:`none`}}function DN(e,t,n,r){let i=lD(n),a=r??dN,o=t.get(e.origin)?.get(e.role);if(o!==void 0&&o.length>0){let t=i.filter(e=>o.includes(wk(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=EN(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=EN(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 ON(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 kN(e){if(e.length===0)return;let t=0,n=0,r=0;for(let i of e){let e=DD(i);t+=e[0],n+=e[1],r+=e[2]}let i=e.length;return[t/i,n/i,r/i]}function AN(e,t,n){let r=n.get(t);if(!r)return;let i=wk(e);for(let[e,t]of r)if(t.includes(i))return e}function jN(e,t,n,r){let i=r.get(t)?.get(n);return i===void 0||i.length===0?[]:lD(e).filter(e=>i.includes(wk(e)))}function MN(e){let t=VM(e);return{entityType:`edge`,length:t.ok?t.value:void 0,midpoint:kN(iN(e))}}function NN(e){let t=new Set,n=[];for(let r of e){let e=wk(r);t.has(e)||(t.add(e),n.push(r))}return n}var PN=1e-6;function FN(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=VM(a);n.ok&&(e+=Math.abs(n.value-t.length))}if(t.midpoint!==void 0){let n=kN(iN(a));n!==void 0&&(e+=ON(t.midpoint,n))}e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<PN))return n}function IN(e,t,n,r){let[i,a]=$M(n,t);if(i===void 0||a===void 0)return;let o=AN(i,e,r),s=AN(a,e,r);if(!(o===void 0||s===void 0))return{origin:e,faceRoles:[o,s],hint:MN(t)}}function LN(e,t,n){let[r,i]=e.faceRoles,a=jN(n,e.origin,r,t),o=jN(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(...sN(e,t));let c=NN(s);if(c.length===1){let[e]=c;if(e!==void 0)return{edge:e,confidence:`exact`}}if(c.length>1){let t=FN(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 RN=3,zN=1e-6;function BN(e,t){let n=new Set;for(let r of e)for(let e of nN(r)){let r=wk(e);n.add(r),t.has(r)||t.set(r,e)}return n}function VN(e,t){let n=new Set;for(let r of e)t.has(r)&&n.add(r);return n}function HN(e){let t=new Map,n;for(let r of e){let e=BN(r,t);n=n===void 0?e:VN(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 UN(e,t){if(t.position===void 0)return;let n,r=1/0,i=1/0;for(let a of e){let e=ON(DD(a),t.position);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<zN))return n}function WN(e,t,n,r){let i=eN(n,t);if(i.length<RN)return;let a=new Set;for(let t of i){let n=AN(t,e,r);n!==void 0&&a.add(n)}if(!(a.size<RN))return{origin:e,faceRoles:[...a].sort(),hint:{entityType:`vertex`,position:DD(t)}}}function GN(e,t,n){let r=[];for(let i of e.faceRoles){let a=jN(n,e.origin,i,t);if(a.length===0)return{ref:e,reason:`not-found`};r.push(a)}let i=HN(r);if(i.length===1){let[e]=i;if(e!==void 0)return{vertex:e,confidence:`exact`}}if(i.length>1){let t=UN(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 KN=.99,qN=.1,JN=1e-6;function YN(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function XN(e,t){return lD(e).filter(e=>YN(SO(e),t)>KN)}function ZN(e,t,n){let r=new Set([...t,...n].map(wk)),i=new Set;for(let n of t)for(let t of uN(e,n))i.add(t);let a=[],o=new Set;for(let t of n)for(let n of uN(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(lD(e).map(e=>[wk(e),e]));return a.map(e=>s.get(e)).filter(e=>e!==void 0)}function QN(e,t){let n,r=1/0,i=1/0;for(let a of e){let e=ON(CO(a),t);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<JN))return n}function $N(e,t,n,r,i){let[a,o]=$M(r,n);if(a===void 0||o===void 0)return;let s=AN(a,e,i),c=AN(o,e,i);if(!(s===void 0||c===void 0))return{origin:e,op:t,betweenRoles:[s,c],hint:{entityType:`derived-face`,normalA:SO(a),normalB:SO(o),edgeMidpoint:kN(iN(n))}}}function eP(e,t,n){let r=jN(n,e.origin,e.betweenRoles[0],t);r.length===0&&(r=XN(n,e.hint.normalA));let i=jN(n,e.origin,e.betweenRoles[1],t);if(i.length===0&&(i=XN(n,e.hint.normalB)),r.length===0||i.length===0)return{ref:e,reason:`not-found`};let a=ZN(n,r,i).filter(t=>YN(SO(t),e.hint.normalA)>qN&&YN(SO(t),e.hint.normalB)>qN);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&&QN(a,e.hint.edgeMidpoint);return t?{face:t,confidence:`geometric-fallback`}:{ref:e,reason:`ambiguous`,candidates:a}}return{ref:e,reason:`not-found`}}function tP(e){return typeof e==`object`&&!!e&&`origin`in e}function nP(e){return tP(e)&&`betweenRoles`in e&&`op`in e}function rP(e){return tP(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length===2}function iP(e){return tP(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length>=3}function aP(e){return tP(e)&&typeof e.role==`string`}function oP(e){return aP(e)||rP(e)||iP(e)||nP(e)}function sP(e,t){return t===void 0?{ok:!1,reason:e}:{ok:!1,reason:e,candidates:t}}function cP(e,t,n){if(nP(e)){let r=eP(e,t,n);return`face`in r?{ok:!0,entity:r.face}:sP(r.reason,r.candidates)}if(rP(e)){let r=LN(e,t,n);return`edge`in r?{ok:!0,entity:r.edge}:sP(r.reason,r.candidates)}if(iP(e)){let r=GN(e,t,n);return`vertex`in r?{ok:!0,entity:r.vertex}:sP(r.reason,r.candidates)}let r=DN(e,t,n);return`face`in r?{ok:!0,entity:r.face}:sP(r.reason,r.candidates)}function lP(e,t,n){let r=n.get(e.origin);if(r!==void 0)return r;let i=new Map([[e.origin,bN(t,e.origin)]]);return n.set(e.origin,i),i}function uP(e,t){return cP(e,lP(e,t,new Map),t)}function dP(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 fP(e,t){let n=new Map,r=e=>{if(oP(e)){let r=cP(e,lP(e,t,n),t);return r.ok?r.entity:e}if(Array.isArray(e))return e.map(r);if(dP(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 pP(e,t,n,r){let i=EE(U().makeBox(e,t,n)),a=r?.at??(r?.centered?[0,0,0]:void 0);if(a)try{var o=NT();return uk(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 mP(e,t,n){let r=n?.at??[0,0,0],i=n?.axis??[0,0,1],a=aj(e,t,r,i);if(n?.centered)try{var o=NT();let e=[-i[0]*t*.5,-i[1]*t*.5,-i[2]*t*.5];return uk(o.u(a),e)}catch(e){o.e=e}finally{o.d()}return a}function hP(e,t){let n=oj(e);if(t?.at)try{var r=NT();return uk(r.u(n),t.at)}catch(e){r.e=e}finally{r.d()}return n}function gP(e,t,n,r){let i=r?.at??[0,0,0],a=r?.axis??[0,0,1],o=sj(e,t,n,i,a);if(r?.centered)try{var s=NT();let e=[-a[0]*n*.5,-a[1]*n*.5,-a[2]*n*.5];return uk(s.u(o),e)}catch(e){s.e=e}finally{s.d()}return o}function _P(e,t,n){return cj(e,t,n?.at??[0,0,0],n?.axis??[0,0,1])}function vP(e,t,n,r){let i=lj(e,t,n);if(r?.at)try{var a=NT();return uk(a.u(i),r.at)}catch(e){a.e=e}finally{a.d()}return i}function yP(e,t){return bA(e,t)}function bP(e,t){let n=t?.axis??[0,0,1];return xA(e,t?.at??[0,0,0],n)}function xP(e,t,n){let r=n?.axis??[0,0,1];return SA(e,t,n?.at??[0,0,0],r,n?.xDir)}function SP(e,t,n,r){return CA(e,t,n,r?.at??[0,0,0],r?.axis??[0,0,1],r?.lefthand??!1)}function CP(e,t,n){return wA(e,t,n)}function wP(e,t,n,r,i){let a=i?.axis??[0,0,1];return TA(e,t,n*KE,r*KE,i?.at??[0,0,0],a,i?.xDir)}function TP(e,t){return EA(e,t)}function EP(e){return OA(e)}function DP(e,t,n){return kA(e,t,n)}function OP(e){return AA(e)}function kP(e){return Ya(AA(e),e=>cE(e)?O(e):k(P(`WIRE_NOT_CLOSED`,`Assembled wire is not closed: start and end points do not coincide`)))}function AP(e,t){return jA(e,t)}function jP(e){return PA(e)}function MP(e,t){return NA(e,t)}function NP(e){return IA(e)}function PP(e){return uj(e)}function FP(e){return fj(e)}function IP(e){return pj(e)}function LP(e,t,n){return dj(e,t,n)}function RP(e,t){return ij(e,t)}function zP(e,t){return FA(e,t)}function BP(){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 VP(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??BP(),color:[a,o,s,c]}});return KT(U().createXCAFDocument(t))}function HP(e=[],{unit:t,modelUnit:n}={}){let r=e=>{let t=e;return t.indexOf(`#`)===0&&(t=t.slice(1)),t.length===3&&(t=t.replace(/([0-9a-f])/gi,`$1$1`)),[parseInt(t.substring(0,2),16),parseInt(t.substring(2,4),16),parseInt(t.substring(4,6),16)]},i=U(),a=e.map(({shape:e,name:t,color:n,alpha:i})=>{let[a,o,s]=r(n??`#f00`);return{shape:e.wrapped,name:t??BP(),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(wo(`STEP_EXPORT_FAILED`,`Failed to write STEP file`))}finally{o.delete()}}function UP(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(UD(t))return k(P(`PATTERN_ZERO_DIRECTION`,`Pattern direction cannot be zero`));let a=VD(t),o=U().linearPattern(e.wrapped,[...a],r,n).map(e=>W(e));try{return UA(o,{optimisation:`sameFace`,...i,unsafe:!0})}finally{for(let e of o)e[Symbol.dispose]()}}function WP(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(UD(t))return k(P(`PATTERN_ZERO_AXIS`,`Pattern axis cannot be zero`));let o=r/n,s=U().circularPattern(e.wrapped,[...i],[...t],o,n).map(e=>W(e));try{return UA(s,{optimisation:`sameFace`,...a,unsafe:!0})}finally{for(let e of s)e[Symbol.dispose]()}}function GP(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(UD(t))return k(P(`PATTERN_ZERO_DIRECTION`,`Grid directionX cannot be zero`));if(UD(n))return k(P(`PATTERN_ZERO_DIRECTION`,`Grid directionY cannot be zero`));let c=U(),l=VD(t),u=VD(n);if(typeof c.gridPattern==`function`)return O(W(c.gridPattern(e.wrapped,[...l],[...u],a,o,r,i)));let d=UP(e,t,r,a,s);if(!d.ok)return d;let f=d.value,p=UP(f,n,i,o,s),m=p.ok&&p.value===f;return f!==e&&!m&&f[Symbol.dispose](),p}function KP(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 qP(e,t){return{...e,children:[...e.children,t]}}function JP(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 YP(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 XP(e,t){if(e.name===t)return e;for(let n of e.children){let e=XP(n,t);if(e)return e}}function ZP(e,t,n=0){t(e,n);for(let r of e.children)ZP(r,t,n+1)}function QP(e){let t=1;for(let n of e.children)t+=QP(n);return t}function $P(e){let t=[];return ZP(e,e=>{e.shape&&t.push(e.shape)}),t}function eF(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function tF(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 nF(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function rF(e){return nF(tF(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function iF(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 aF(e,t){let n=t/2,r=Math.sin(n),i=nF(e);return[Math.cos(n),i[0]*r,i[1]*r,i[2]*r]}function oF(e,t){let n=nF(e),r=nF(t),i=eF(n,r);if(i>=.999999999)return[1,0,0,0];if(i<=-.999999999)return aF(rF(n),Math.PI);let a=tF(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 sF(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 cF=Math.PI/180;function lF(e,t,n){return Math.min(n,Math.max(t,e))}function uF(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function dF(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 fF(e){return uF(dF(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function pF(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:uF(t),min:s,max:c,value:lF(n.value??0,s,c)}}function mF(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:uF(r.direction)},min:a.min,max:a.max,value:a.value,dofs:i}}function hF(e,t,n,r={}){return mF(`revolute`,e,t,n,[pF(`rotation`,n.direction,r,-180,180)])}function gF(e,t,n,r={}){return mF(`prismatic`,e,t,n,[pF(`translation`,n.direction,r,0,100)])}function _F(e,t,n,r={}){return mF(`cylindrical`,e,t,n,[pF(`rotation`,n.direction,r.rotation??{},-180,180),pF(`translation`,n.direction,r.translation??{},0,100)])}function vF(e,t,n,r={}){let i=uF(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?fF(i):uF(n)}else a=fF(i);let o=uF(dF(i,a));return mF(`planar`,e,t,{origin:n.origin,direction:i},[pF(`translation`,a,r.u??{},-100,100),pF(`translation`,o,r.v??{},-100,100),pF(`rotation`,i,r.rotation??{},-180,180)])}function yF(e,t,n,r={}){return mF(`spherical`,e,t,{origin:n,direction:[0,0,1]},[pF(`rotation`,[1,0,0],r.x??{},-180,180),pF(`rotation`,[0,1,0],r.y??{},-180,180),pF(`rotation`,[0,0,1],r.z??{},-180,180)])}function bF(e,t){let n=e.dofs.map((e,n)=>{let r=t[n];return r===void 0?e:{...e,value:lF(r,e.min,e.max)}}),r=n[0];return r?{...e,dofs:n,value:r.value}:{...e,dofs:n}}function xF(e,t){return bF(e,[t])}function SF(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=aF(t.axis,n*cF),i=iF(r,e);return{position:[e[0]-i[0],e[1]-i[1],e[2]-i[2]],rotation:r}}function CF(e,t=e.value){let n=Array.isArray(t)?t:void 0,r=n?void 0:t,i=e.axis.origin,a=TF;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=EF(a,SF(i,o,lF(s,o.min,o.max)))}return a}function wF(e,t){let n=e.joints??[];return{...e,joints:[...n,t]}}var TF={position:[0,0,0],rotation:[1,0,0,0]};function EF(e,t){let n=iF(e.rotation,t.position);return{position:[e.position[0]+n[0],e.position[1]+n[1],e.position[2]+n[2]],rotation:sF(e.rotation,t.rotation)}}function DF(e){let t=[];return ZP(e,e=>{e.joints&&t.push(...e.joints)}),t}function OF(e,t={}){let n=[],r=new Set;ZP(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,TF);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?EF(CF(n,i),n.offset):CF(n,i);a.set(n.child,EF(r,c))}}for(let e of o)a.has(e.child)||a.set(e.child,TF);return a}function kF(e){return DF(e).reduce((e,t)=>e+t.dofs.length,0)}var AF={position:[0,0,0],rotation:[1,0,0,0]};function jF(e,t){let n=iF(e.rotation,t);return[n[0]+e.position[0],n[1]+e.position[1],n[2]+e.position[2]]}function MF(e){return[e[0],-e[1],-e[2],-e[3]]}function NF(e,t){let[n,r,i,a]=sF(t,MF(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 PF(e,t){let n=[];ZP(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 FF(e,t){return e[t]??0}function IF(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]=FF(e,a*n+t);i[a*r+n]=FF(t,a)}for(let e=0;e<n;e++){let t=e;for(let a=e+1;a<n;a++)Math.abs(FF(i,a*r+e))>Math.abs(FF(i,t*r+e))&&(t=a);if(Math.abs(FF(i,t*r+e))<1e-12)return null;if(t!==e)for(let n=e;n<r;n++){let a=FF(i,e*r+n);i[e*r+n]=FF(i,t*r+n),i[t*r+n]=a}let a=FF(i,e*r+e);for(let t=e;t<r;t++)i[e*r+t]=FF(i,e*r+t)/a;for(let t=0;t<n;t++){if(t===e)continue;let n=FF(i,t*r+e);if(n!==0)for(let a=e;a<r;a++)i[t*r+a]=FF(i,t*r+a)-n*FF(i,e*r+a)}}let a=new Float64Array(n);for(let e=0;e<n;e++)a[e]=FF(i,e*r+n);return a}function LF(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 RF(e,t){let n={},r=0;for(let i of e){let e=[];for(let n=0;n<i.count;n++)e.push(FF(t,r++));n[i.child]=e}return n}function zF(e,t,n,r,i){let a=jF(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=NF(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+=FF(e,t)**2;return Math.sqrt(o)}function BF(e,t,n,r,i,a,o,s,c,l){let u=jF(o,s);for(let d=0;d<n;d++){let f=FF(t,d),p=f+c>FF(a,d)&&f-c>=FF(i,d)?-c:c;t[d]=f+p;let m=l(t);t[d]=f;let h=jF(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=NF(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 VF(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+=FF(e,t*n+r)*FF(e,i*n+r);a[t*r+i]=s+(t===i?o:0)}let s=IF(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+=FF(e,a*n+t)*FF(s,a);c[t]=i}return c}function HF(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}=LF(PF(e,t),r.seed),p=u.length,m=n=>OF(e,RF(l,n)).get(t)??AF,h=new Float64Array(c),g=new Float64Array(c*p),_=m(u),v=zF(h,_,n,s,c),y=0;for(;y<i&&p>0&&v>a;y++){BF(g,u,p,c,d,f,_,s,1e-6,m);let e=VF(g,h,p,c,o);if(!e)break;for(let t=0;t<p;t++){let n=FF(u,t)+FF(e,t);u[t]=Math.min(FF(f,t),Math.max(FF(d,t),n))}_=m(u),v=zF(h,_,n,s,c)}return{values:RF(l,u),converged:v<=a,iterations:y,error:v}}function UF(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 WF(e,t,n,r){let i=[];ZP(e,e=>{e.joints&&i.push(...e.joints)});let a=i.map(e=>({child:e.child,a:UF(e,t[e.child]),b:UF(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:OF(e,r)})}return s}var GF=Math.PI/180;function KF(e,t,n,r){let i=e*GF,a=r*GF,o=sF(aF([0,0,1],i),aF([1,0,0],a));return{position:[n*Math.cos(i),n*Math.sin(i),t],rotation:o}}function qF(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=KF(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`?gF(i,a,s,c):hF(i,a,s,c),offset:o}})}var JF=Math.PI/180,YF=180/Math.PI;function XF(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function ZF(e){return String(e===0?0:e)}function QF(e){return`${ZF(e[0])} ${ZF(e[1])} ${ZF(e[2])}`}function $F(e,t={}){let n=t.name??`robot`,r=t.effort??0,i=t.velocity??0,a=t.meshes??{},o=[],s=[];ZP(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="${XF(n)}">`];for(let e of o){let t=a[e];t?c.push(` <link name="${XF(e)}">`,` <visual><geometry><mesh filename="${XF(t)}"/></geometry></visual>`,` </link>`):c.push(` <link name="${XF(e)}"/>`)}for(let e of s){let t=e.type===`revolute`,n=t?e.min*JF:e.min,a=t?e.max*JF:e.max,o=e.type===`prismatic`?[0,0,0]:e.axis.origin;c.push(` <joint name="${XF(`${e.parent}_to_${e.child}`)}" type="${e.type}">`,` <parent link="${XF(e.parent)}"/>`,` <child link="${XF(e.child)}"/>`,` <origin xyz="${QF(o)}" rpy="0 0 0"/>`,` <axis xyz="${QF(e.axis.direction)}"/>`,` <limit lower="${ZF(n)}" upper="${ZF(a)}" effort="${ZF(r)}" velocity="${ZF(i)}"/>`,` </joint>`)}return c.push(`</robot>`,``),O(c.join(`
15
+ npm install brepkit-wasm`)}function NT(){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 PT=Symbol;PT.dispose??=Symbol.for(`Symbol.dispose`),PT.asyncDispose??=Symbol.for(`Symbol.asyncDispose`);var FT=globalThis;FT.FinalizationRegistry||=(console.warn(`brepjs: FinalizationRegistry unavailable — garbage collection will not work`),class{register(e,t,n){}unregister(e){return!1}});var IT={liveHandles:0,peakHandles:0,gcCollected:0,scopeEnters:0,scopeExits:0};function LT(){return{...IT}}function RT(){IT.liveHandles=0,IT.peakHandles=0,IT.gcCollected=0,IT.scopeEnters=0,IT.scopeExits=0}function zT(){IT.liveHandles++,IT.liveHandles>IT.peakHandles&&(IT.peakHandles=IT.liveHandles)}function BT(){IT.liveHandles--}function VT(){IT.gcCollected++,IT.liveHandles--}var HT=new FinalizationRegistry(e=>{VT();try{e.delete()}catch{}});function UT(e){let t=U(),n=!1,r,i=()=>{if(r){for(let e of r)try{e()}catch{}r=void 0}},a=()=>{if(!n){n=!0,BT(),HT.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 zT(),HT.register(o,{delete:()=>{t.dispose(e)}},o),o}function WT(e){let t=()=>{};return{get wrapped(){return e},get disposed(){return!1},[Symbol.dispose]:t,delete:t,onDispose:t}}function GT(e){let t=U(),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 KT(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,BT(),HT.unregister(n);try{e.delete()}catch{}}}};return zT(),HT.register(n,e,n),n}var qT=class{handles=[];constructor(){IT.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](){IT.scopeExits++;for(let e=this.handles.length-1;e>=0;e--)this.handles[e]?.();this.handles.length=0}};function JT(e){try{var t=NT();return e(t.u(new qT))}catch(e){t.e=e}finally{t.d()}}function YT(e,t){HT.register(e,t,t)}function XT(e){HT.unregister(e)}function ZT(e){try{var t=NT();return e(t.u(new qT))}catch(e){t.e=e}finally{t.d()}}async function QT(e){try{var t=NT();return await e(t.u(new qT))}catch(e){t.e=e}finally{t.d()}}function $T(e){return!e.disposed}function eE(e){return e.__is2D!==!0}function tE(e){return e.__is2D===!0}function nE(e){if(!eE(e))throw Error(`Expected 3D shape, got 2D`);return e}function rE(e){if(!tE(e))throw Error(`Expected 2D shape, got 3D`);return e}var iE=new WeakMap;function aE(e,t){iE.set(e,t)}function oE(e,t){let n=iE.get(t);if(n!==void 0)return n;let r=e.shapeType(t);return iE.set(t,r),r}function sE(e){return oE(U(),e.wrapped)}function cE(e){return U().curveIsClosed(e.wrapped)}function lE(e){return U().isValid(e.wrapped)}function uE(e){let t=U();if(!t.isValid(e.wrapped))return!1;let n=t.isValidStrict?.bind(t)??t.isValid.bind(t);try{let r=t.solidFromShell(e.wrapped),i=n(r);try{t.dispose(r)}catch{}return i}catch{return!1}}function dE(e){return U().isValid(e.wrapped)}function fE(e){return cE(e)?O(e):k(`Wire is not closed: start and end points do not coincide`)}function pE(e){return lE(e)?O(e):k(`Face orientation is inconsistent or face is invalid`)}function mE(e){return uE(e)?O(e):k(`Shell is not manifold: has free edges or is invalid`)}function hE(e){return dE(e)?O(e):k(`Solid failed BRepCheck validation`)}function gE(e){return U().surfaceType(e.wrapped)===`plane`}function _E(e){let t=U(),n=n=>{try{let r=t.makeFace(e.wrapped,n),i=t.surfaceType(r);try{t.dispose(r)}catch{}return i===`plane`}catch{return!1}};return n(!0)?!0:n(!1)}function vE(e){return gE(e)?O(e):k(`Face is not planar: underlying surface is not a geometric plane`)}function yE(e){return _E(e)?O(e):k(`Wire is not planar: edges do not lie in a common plane`)}function bE(e,t){return t===`2D`&&(e.__is2D=!0),e}function xE(e,t){return bE(UT(e),t)}function SE(e,t){return bE(UT(e),t)}function CE(e,t){return bE(UT(e),t)}function wE(e,t){return bE(UT(e),t)}function TE(e){return bE(UT(e))}function EE(e){return bE(UT(e))}function DE(e){return bE(UT(e))}function OE(e,t){return bE(UT(e),t)}function kE(e){return sE(e)===`vertex`}function AE(e){return sE(e)===`edge`}function jE(e){return sE(e)===`wire`}function ME(e){return sE(e)===`face`}function NE(e){return sE(e)===`shell`}function PE(e){return sE(e)===`solid`}function FE(e){return sE(e)===`compound`}function IE(e){let t=sE(e);return t===`shell`||t===`solid`||t===`compsolid`?!0:t===`compound`?eE(e):!1}function LE(e){let t=sE(e);return t===`edge`||t===`wire`}function RE(e,t){let n=U(),r=oE(n,e),i=n.downcast(e,r);return r===`vertex`?xE(i,t):r===`edge`?SE(i,t):r===`wire`?CE(i,t):r===`face`?wE(i,t):r===`shell`?TE(i):r===`solid`?EE(i):r===`compsolid`?DE(i):OE(i,t)}function zE(e){return RE(e)}function BE(e,t){let n=e.id,r=t.wrapped.id;(n!==void 0&&r!==void 0?n===r:t.wrapped===e)||U().dispose(e)}function W(e,t){let n=RE(e,t);return BE(e,n),n}function VE(e,t){let n=e.wrapped;if(e[Symbol.dispose](),n!==t){let e=U();e.dispose(n),e.dispose(t)}}function HE(e){U().dispose(e.wrapped),e[Symbol.dispose]()}function UE(e,t,n){aE(e,t);let r=U().downcast(e,t);return t===`vertex`?xE(r,n):t===`edge`?SE(r,n):t===`wire`?CE(r,n):t===`face`?wE(r,n):t===`shell`?TE(r):t===`solid`?EE(r):t===`compsolid`?DE(r):OE(r,n)}function WE(e,t,n){let r=UE(e,t,n);return BE(e,r),r}function GE(e,t,n){return aE(e,t),bE(WT(e),n)}var G=2147483647,KE=Math.PI/180,qE=180/Math.PI;function JE(e,t,n,r,i){let a={kind:e,code:t,message:n,cause:r};return i?{...a,suggestion:i}:a}var YE={KERNEL_OPERATION:(e,t,n,r)=>JE(`KERNEL_OPERATION`,e,t,n,r),VALIDATION:(e,t,n,r)=>JE(`VALIDATION`,e,t,n,r),TYPE_CAST:(e,t,n,r)=>JE(`TYPE_CAST`,e,t,n,r),SKETCHER_STATE:(e,t,n,r)=>JE(`SKETCHER_STATE`,e,t,n,r),MODULE_INIT:(e,t,n,r)=>JE(`MODULE_INIT`,e,t,n,r),COMPUTATION:(e,t,n,r)=>JE(`COMPUTATION`,e,t,n,r),IO:(e,t,n,r)=>JE(`IO`,e,t,n,r),QUERY:(e,t,n,r)=>JE(`QUERY`,e,t,n,r),UNSUPPORTED:(e,t,n,r)=>JE(`UNSUPPORTED`,e,t,n,r)};function XE(e,t,n,r=`KERNEL_OPERATION`){try{return O(W(e()))}catch(e){let i=e instanceof Error?e.message:String(e),a=r===`KERNEL_OPERATION`?yo(i):i,o=vo(t);return k(YE[r](t,`${n}: ${a}`,e,o))}}function ZE(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`?yo(i):i,o=vo(t);return k(YE[r](t,`${n}: ${a}`,e,o))}}function QE(e,t,n,r=`KERNEL_OPERATION`){try{var i=NT();let a=i.u(new qT);return XE(()=>e(a),t,n,r)}catch(e){i.e=e}finally{i.d()}}function $E(e,t){let n=U().iterShapes(e,t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=WE(n[e],t);return r}function eD(e,t){let n=U();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 tD(e,t){let n=U();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 nD=new WeakMap;function rD(e){let t=nD.get(e);if(!t)return;nD.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 iD=new WeakSet;function aD(e){let t=e.wrapped,n=nD.get(t);return n||(n={},nD.set(t,n)),iD.has(e)||(iD.add(e),e.onDispose(()=>{rD(t)})),n}function oD(e){return nD.get(e.wrapped)}function sD(e){rD(e.wrapped)}function cD(e){let t=aD(e);if(t.edges)return t.edges;let n=$E(e.wrapped,`edge`);return t.edges=n,n}function lD(e){let t=aD(e);if(t.faces)return t.faces;let n=$E(e.wrapped,`face`);return t.faces=n,n}function uD(e){let t=aD(e);if(t.wires)return t.wires;let n=$E(e.wrapped,`wire`);return t.wires=n,n}function dD(e){let t=aD(e);if(t.vertices)return t.vertices;let n=$E(e.wrapped,`vertex`);return t.vertices=n,n}function fD(e){let t=aD(e);if(t.solids)return t.solids;let n=$E(e.wrapped,`solid`);return t.solids=n,n}function pD(e){let t=aD(e);if(t.shells)return t.shells;let n=$E(e.wrapped,`shell`);return t.shells=n,n}function mD(e){let t=aD(e);if(t.compSolids)return t.compSolids;let n=$E(e.wrapped,`compsolid`);return t.compSolids=n,n}function*hD(e){for(let t of U().iterShapes(e.wrapped,`edge`))yield WE(t,`edge`)}function*gD(e){for(let t of U().iterShapes(e.wrapped,`face`))yield WE(t,`face`)}function*_D(e){for(let t of U().iterShapes(e.wrapped,`wire`))yield WE(t,`wire`)}function*vD(e){for(let t of U().iterShapes(e.wrapped,`vertex`))yield WE(t,`vertex`)}function*yD(e){for(let t of U().iterShapes(e.wrapped,`solid`))yield WE(t,`solid`)}function*bD(e){for(let t of U().iterShapes(e.wrapped,`shell`))yield WE(t,`shell`)}function*xD(e){for(let t of U().iterShapes(e.wrapped,`compsolid`))yield WE(t,`compsolid`)}function SD(e){let t=aD(e);if(t.bounds)return t.bounds;let{min:n,max:r}=U().boundingBox(e.wrapped),i={xMin:n[0],xMax:r[0],yMin:n[1],yMax:r[1],zMin:n[2],zMax:r[2]};return t.bounds=i,i}function CD(e){return oE(U(),e.wrapped)}function wD(e){let t=aD(e);if(t.surfaceType!==void 0)return t.surfaceType;let n=U().surfaceType(e.wrapped);return t.surfaceType=n,n}function TD(e){let t=aD(e);if(t.isValid!==void 0)return t.isValid;let n=U().isValid(e.wrapped);return t.isValid=n,n}function ED(e){return{kind:CD(e),faceCount:eD(e,`face`),edgeCount:eD(e,`edge`),wireCount:eD(e,`wire`),vertexCount:eD(e,`vertex`),valid:TD(e),bounds:SD(e)}}function DD(e){return U().vertexPosition(e.wrapped)}function OD(e){return e.length===2?[e[0],e[1],0]:[e[0],e[1],e[2]]}function kD(e){return[e[0],e[1]]}var AD={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function jD(e){if(typeof e==`string`){let t=AD[e];if(!t)throw Error(`Unknown direction: ${e}`);return t}return e}function MD(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function ND(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function PD(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function FD(e){return[-e[0],-e[1],-e[2]]}function ID(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function LD(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 RD(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function zD(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function BD(e,t){return RD(ND(e,t))}function VD(e){let t=RD(e);return t<1e-10?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function HD(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 UD(e,t=1e-10){return zD(e)<t*t}function WD(e,t){let n=ID(e,t),r=RD(e),i=RD(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 GD(e,t,n){let r=ND(e,t),i=zD(n);return i<1e-20?e:ND(e,PD(n,ID(r,n)/i))}function KD(e,t,n){let r=VD(t),i=Math.cos(n),a=Math.sin(n),o=ID(e,r),s=LD(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 qD=e=>Math.round(e*1e3)/1e3;function JD(e){return`x: ${qD(e[0])}, y: ${qD(e[1])}, z: ${qD(e[2])}`}function YD(e,t=null,n=[0,0,1]){let r=VD(n);if(UD(r))throw Error(`Plane normal must be non-zero`);let i;if(t)i=VD(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?VD([l,u,d]):[1,0,0]}if(UD(i))throw Error(`Plane xDir must be non-zero`);let a=VD(LD(r,i));return{origin:e,xDir:i,yDir:a,zDir:r}}var XD={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 ZD(e,t=[0,0,0]){let n=XD[e];if(!n)return k(P(`UNKNOWN_PLANE`,`Could not find plane ${e}`));let r;return r=typeof t==`number`?PD(n.normal,t):OD(t),O(YD(r,n.xDir,n.normal))}function QD(e,t){return typeof e==`string`?ZD(e,t):O(e)}function $D(e,t){return e&&typeof e!=`string`?{...e}:j(QD(e??`XY`,t))}function eO(e,t){let[n,r]=t;return MD(MD(e.origin,PD(e.xDir,n)),PD(e.yDir,r))}function tO(e,t){return{...e,origin:MD(e.origin,t)}}function nO(e,t,n=[1,0,0]){let r=t*KE,i=KD(e.zDir,n,r),a=KD(e.xDir,n,r),o=VD(LD(i,a));return{origin:e.origin,xDir:a,yDir:o,zDir:i}}var rO={compound:0,solidCompound:1,solid:2,shell:3,face:4,wire:5,edge:6,vertex:7,shape:8},iO=e=>rO[e],aO={vertex:`vertex`,edge:`edge`,wire:`wire`,face:`face`,shell:`shell`,solid:`solid`,solidCompound:`compsolid`,compound:`compound`,shape:`compound`},oO=function*(e,t){let n=U().iterShapes(e,aO[t]);for(let e of n)yield e},sO=e=>U().isNull(e)?k(xo(`NULL_SHAPE`,`This shape has no type, it is null`)):O(e.ShapeType());function cO(e){if(U().isNull(e))return k(xo(`NULL_SHAPE`,`This shape has no type, it is null`));try{return O(U().downcast(e))}catch(e){return k(xo(`NO_WRAPPER`,`Could not find a wrapper for this shape type`,e))}}function lO(e){if(U().isNull(e))return k(xo(`NULL_SHAPE`,`Cannot copy a null shape`));try{return O(U().copyShape(e))}catch(e){return k(xo(`NO_WRAPPER`,`Could not copy this shape`,e))}}function uO(e){return U().isNull(e)?k(xo(`NULL_SHAPE`,`Cannot cast a null shape`)):O(RE(e))}function dO(e){return U().shapeType(e.wrapped)===`compsolid`}function fO(e){return uO(U().fromBREP(e))}var pO={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 mO(e){return O(pO[wD(e)])}function hO(e){return j(mO(e))}function gO(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function _O(e){return RE(U().reverseShape(e.wrapped))}function vO(e){return U().uvBounds(e.wrapped)}function yO(e,t,n){let r=vO(e),i=t*(r.uMax-r.uMin)+r.uMin,a=n*(r.vMax-r.vMin)+r.vMin;return U().pointOnSurface(e.wrapped,i,a)}function bO(e,t){let n=OD(t);return U().uvFromPoint(e.wrapped,n)||[0,0]}function xO(e,t){let n=OD(t);try{let t=n,r=U().uvFromPoint(e.wrapped,t);if(!r)return k(xo(`PROJECTION_FAILED`,`No projection found on the face`));let i=U().projectPointOnFace(e.wrapped,t),a=n[0]-i[0],o=n[1]-i[1],s=n[2]-i[2];return O({uv:r,point:i,distance:Math.sqrt(a*a+o*o+s*s)})}catch(e){return k(xo(`PROJECTION_FAILED`,`Point projection failed: ${e instanceof Error?e.message:String(e)}`))}}function SO(e,t){let n,r;if(t)[n,r]=bO(e,t);else{let t=vO(e);n=.5*(t.uMin+t.uMax),r=.5*(t.vMin+t.vMax)}return U().surfaceNormal(e.wrapped,n,r)}function CO(e){return U().surfaceCenterOfMass(e.wrapped)}function wO(e){return U().getSurfaceAxis(e.wrapped)}function TO(e,t,n=1e-6){let[r,i]=bO(e,t);return U().classifyPointOnFace(e.wrapped,r,i,n)}function EO(e){return RE(U().outerWire(e.wrapped))}function DO(e){return RE(U().removeHolesFromFace(e.wrapped))}function OO(e){let t=EO(e);return Array.from(oO(e.wrapped,`wire`)).map(e=>RE(j(cO(e)))).filter(e=>!U().isSame(e.wrapped,t.wrapped))}function kO(e,t){let n=aD(e),r=new Map;for(let n of tD(e,`face`))r.set(n,t);n.faceOrigins=r}function AO(e){return oD(e)?.faceOrigins}function jO(e,t,n){let r=new Map;for(let e of t){let t=AO(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=aD(n);e.faceOrigins=i}}var MO=100,NO=.985,PO=.1;function FO(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>MO)continue;let u=r-l/MO;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)<NO)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>PO)continue;let u=Math.max(0,i*i+a*a+c*c-l*l);u<o&&(o=u,s=n.origin)}return s}function IO(e,t){let n=new Map;for(let t of e){let e=AO(t);if(e)for(let[t,r]of e)n.set(t,r)}if(n.size===0)return;let r=U(),i=new Map,a=lD(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=AO(n);if(e)for(let i of lD(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=FO(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=aD(t);e.faceOrigins=i}}var LO=new WeakMap,RO=new WeakMap;function zO(e){return LO.has(e.wrapped)}function BO(e){let t=LO.get(e.wrapped);return t||(t=new Map,LO.set(e.wrapped,t)),t}function VO(e){let t=RO.get(e.wrapped);return t||(t=new Map,RO.set(e.wrapped,t)),t}function HO(e,t,n){let r=Array.isArray(t)?t:lD(e).filter(t),i=BO(e),a=i.get(n)??new Set;for(let e of r)a.add(U().hashCode(e.wrapped,G));return i.set(n,a),e}function UO(e,t){let n=LO.get(e.wrapped);if(!n)return[];let r=n.get(t);if(!r||r.size===0)return[];let i=[];for(let t of lD(e)){let e=U().hashCode(t.wrapped,G);r.has(e)&&i.push(t)}return i}function WO(e){let t=new Map,n=LO.get(e.wrapped);if(!n)return t;let r=lD(e),i=new Map;for(let e of r)i.set(U().hashCode(e.wrapped,G),e);for(let[e,r]of n){let n=[];for(let e of r){let t=i.get(e);t&&n.push(t)}n.length>0&&t.set(e,n)}return t}function GO(e,t,n){return VO(e).set(t,n),e}function KO(e,t){return RO.get(e.wrapped)?.get(t)}function qO(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function JO(e,t,n){let r=BO(n);for(let i of t){let t=LO.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)qO(r,t,e)}let o=RO.get(i.wrapped);if(o){let e=VO(n);for(let[t,n]of o)e.has(t)||e.set(t,n)}}}var YO=new WeakMap,XO=new WeakMap;function ZO(e){return YO.has(e.wrapped)||XO.has(e.wrapped)}function QO(e){let t=XO.get(e.wrapped);return t||(t=new Map,XO.set(e.wrapped,t)),t}function $O(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 ek(e,t){return YO.set(e.wrapped,$O(t)),e}function tk(e,t,n){let r=$O(n),i=QO(e);for(let e of t)i.set(U().hashCode(e.wrapped,G),r);return e}function nk(e){return YO.get(e.wrapped)}function rk(e,t){let n=XO.get(e.wrapped);if(n)return n.get(U().hashCode(t.wrapped,G))}function ik(e,t,n){for(let e of t){let t=YO.get(e.wrapped);if(t){YO.set(n.wrapped,t);break}}let r=QO(n);for(let n of t){let t=XO.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 ak(e){return AO(e)!==void 0||zO(e)||ZO(e)}function ok(e){if(!e.some(ak))return[];let t=[];for(let n of e)t.push(...tD(n,`face`));return t}function sk(e,t,n){jO(e,t,n),JO(e,t,n),ik(e,t,n)}function ck(e,t){IO(e,t)}function lk(e,t){let n=U(),r=[...n.iterShapes(e.wrapped,`face`)],i=[...n.iterShapes(t.wrapped,`face`)];if(r.length!==i.length)return;let a=new Map;for(let e=0;e<r.length;e++){let t=r[e],o=i[e];t===void 0||o===void 0||a.set(n.hashCode(t,G),[n.hashCode(o,G)])}for(let e of r)n.dispose(e);for(let e of i)n.dispose(e);sk({modified:a,generated:new Map,deleted:new Set},[e],t)}function uk(e,t){let n=ok([e]),{shape:r,evolution:i}=U().translateWithHistory(e.wrapped,t[0],t[1],t[2],n,G),a=W(r);return sk(i,[e],a),a}function dk(e,t,n=[0,0,0],r=[0,0,1]){let i=ok([e]),{shape:a,evolution:o}=U().rotateWithHistory(e.wrapped,t*KE,i,G,r,n),s=W(a);return sk(o,[e],s),s}function fk(e,t=[0,1,0],n=[0,0,0]){let r=ok([e]),{shape:i,evolution:a}=U().mirrorWithHistory(e.wrapped,n,t,r,G),o=W(i);return sk(a,[e],o),o}function pk(e,t,n=[0,0,0]){let r=ok([e]),{shape:i,evolution:a}=U().scaleWithHistory(e.wrapped,n,t,r,G),o=W(i);return sk(a,[e],o),o}function mk(e,t,n){let r=U().boundingBox(e.wrapped),i=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]],a=n?.auto===!0;function o(e,t,n){return e!==void 0&&t>1e-12?e/t:e===void 0&&a?n:1}let s=1;a&&(t[0]!==void 0&&i[0]>1e-12?s=t[0]/i[0]:t[1]!==void 0&&i[1]>1e-12?s=t[1]/i[1]:t[2]!==void 0&&i[2]>1e-12&&(s=t[2]/i[2]));let c=[o(t[0],i[0],s),o(t[1],i[1],s),o(t[2],i[2],s)];return Math.abs(c[0]-c[1])<1e-6&&Math.abs(c[1]-c[2])<1e-6?O(pk(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 hk(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 gk(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 _k(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 vk(e,t){let n=hk(t);if(!n.ok)return n;let{linear:r,translation:i}=n.value,a=gk(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(_k(r)){let t=ok([e]),{shape:n,evolution:a}=U().generalTransformWithHistory(e.wrapped,r,i,!0,t,G),o=W(n);return sk(a,[e],o),O(o)}let o=W(U().generalTransformNonOrthogonal(e.wrapped,r,i));return ck([e],o),O(o)}function yk(e){let t=e.map(e=>e.type===`translate`?{type:`translate`,x:e.v[0],y:e.v[1],z:e.v[2]}:{type:`rotate`,angle:e.angle,axis:e.axis,center:e.center}),{handle:n,dispose:r}=U().composeTransform(t);return{trsf:n,cleanup:r}}function bk(e,t){let{trsf:n,cleanup:r}=yk(`type`in t?[t]:t),i;try{i=W(U().locate(e.wrapped,n))}finally{r()}return ak(e)&&lk(e,i),i}function xk(e,t){let n=ok([e]),{shape:r,evolution:i}=U().applyComposedTransformWithHistory(e.wrapped,t.trsf,n,G),a=W(r);return sk(i,[e],a),a}function Sk(e){return XE(()=>U().copyShape(e.wrapped),M.CLONE_FAILED,`Failed to clone shape`)}function Ck(e){return ZE(()=>U().toBREP(e.wrapped),M.TO_BREP_FAILED,`Failed to serialize shape to BREP`)}function wk(e){return U().hashCode(e.wrapped,G)}function Tk(e){return U().isNull(e.wrapped)}function Ek(e,t){return U().isSame(e.wrapped,t.wrapped)}function Dk(e,t){return U().isEqual(e.wrapped,t.wrapped)}function Ok(e){return XE(()=>U().simplify(e.wrapped),M.SIMPLIFY_FAILED,`Failed to simplify shape`)}function kk(e){return U().curveType(e.wrapped)}function Ak(e){let[t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function jk(e){let[,t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function Mk(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curvePointAtParam(e.wrapped,i)}function Nk(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curveTangent(e.wrapped,i).tangent}function Pk(e){return U().length(e.wrapped)}function Fk(e){if(kk(e)!==`CIRCLE`)return null;let t=Mk(e,0),n=Mk(e,1/3),r=Mk(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 Ik(e){return U().curveIsClosed(e.wrapped)}function Lk(e){return U().curveIsPeriodic(e.wrapped)}function Rk(e){return U().curvePeriod(e.wrapped)}function zk(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function Bk(e){return W(U().reverseShape(e.wrapped))}function Vk(e,t={}){if(e.length<2)return k(xo(`INTERPOLATE_MIN_POINTS`,`Interpolation requires at least 2 points`));try{let n=W(U().interpolatePoints(e,t));return AE(n)?O(n):(HE(n),k(xo(`INTERPOLATE_NOT_EDGE`,`Interpolation did not produce an edge`)))}catch(e){return k(xo(`INTERPOLATE_FAILED`,`Interpolation failed: ${e instanceof Error?e.message:String(e)}`))}}function Hk(e,t={}){if(e.length<2)return k(xo(`APPROXIMATE_MIN_POINTS`,`Approximation requires at least 2 points`));try{let n=W(U().approximatePoints(e,t));return AE(n)?O(n):(HE(n),k(xo(`APPROXIMATE_NOT_EDGE`,`Approximation did not produce an edge`)))}catch(e){return k(xo(`APPROXIMATE_FAILED`,`Approximation failed: ${e instanceof Error?e.message:String(e)}`))}}function Uk(e,t,n=`arc`){let r=W(U().offsetWire2D(e.wrapped,t,{arc:`arc`,intersection:`intersection`,tangent:`tangent`,chamfer:`intersection`}[n]));return jE(r)?O(r):(HE(r),k(xo(`OFFSET_NOT_WIRE`,`Offset did not produce a Wire`)))}function Wk(e,t,n,r=!1){return`${e}:${t}:${n}:${r}`}function Gk(e,t){return`edge:${e}:${t}`}var Kk=new WeakMap,qk=new WeakMap;function Jk(e,t){let n=Kk.get(e);if(n)return n.get(t)}function Yk(e,t,n){let r=Kk.get(e);r||(r=new Map,Kk.set(e,r)),r.set(t,n)}function Xk(e,t){let n=qk.get(e);if(n)return n.get(t)}function Zk(e,t,n){let r=qk.get(e);r||(r=new Map,qk.set(e,r)),r.set(t,n)}function Qk(){Kk=new WeakMap,qk=new WeakMap}function $k(){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 eA(e,t={}){let n=jo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,skipNormals:a=!1,includeUVs:o=!1,cache:s=!0,signal:c}=t;c?.throwIfAborted();let l=Wk(r,i,a,o);if(s){let t=Jk(e.wrapped,l);if(t)return t}let u=U().mesh(e.wrapped,{tolerance:r,angularTolerance:i,skipNormals:a,includeUVs:o,...c?{signal:c}:{}}),d=AO(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&&Yk(e.wrapped,l,f),f}function tA(e,t={}){let n=jo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,cache:a=!0}=t,o=Gk(r,i);if(a){let t=Xk(e.wrapped,o);if(t)return t}let s=U().meshEdges(e.wrapped,r,i),c={lines:s.lines,edgeGroups:s.edgeGroups.map(e=>({start:e.start,count:e.count,edgeId:e.edgeHash}))};return a&&Zk(e.wrapped,o,c),c}function nA(e,t){return e instanceof Error&&e.message.startsWith(`${t} export failed`)?wo(`${t}_EXPORT_FAILED`,`Failed to write ${t} file`,e):e instanceof WebAssembly.RuntimeError?wo(`${t}_EXPORT_CRASHED`,`${t} export crashed the kernel (${e.message}); the shape likely contains geometry the ${t} writer cannot serialize`,e):wo(`${t}_FILE_READ_ERROR`,`Failed to read exported ${t} file`,e)}function rA(e){let t;try{t=fD(e)}catch{return``}if(t.length<=1)return``;let n=[];return t.forEach((e,t)=>{try{SD(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 iA(e,t){try{return SD(e),null}catch(n){if(n instanceof TypeError)throw n;return wo(`${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${rA(e)}`,n)}}function aA(e){let t=iA(e,`STEP`);if(t)return k(t);try{let t=U().exportSTEP([e.wrapped]);return O(new Blob([t],{type:`application/STEP`}))}catch(e){return k(nA(e,`STEP`))}}function oA(e,t={}){let n=jo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,binary:a=!1}=t,o=iA(e,`STL`);if(o)return k(o);try{U().hasTriangulation(e.wrapped)||U().meshShape(e.wrapped,r,i);let t=U().exportSTL(e.wrapped,a,r,i);return O(new Blob([t],{type:`application/sla`}))}catch(e){return k(nA(e,`STL`))}}function sA(e){try{let t=U().exportIGES([e.wrapped]);return O(new Blob([t],{type:`application/iges`}))}catch(e){return k(wo(`IGES_EXPORT_FAILED`,`Failed to write IGES file`,e))}}function cA(e,t){let n=t?.coarseTolerance??.5,r=t?.fineTolerance??.05,i=t?.angularTolerance??.5;return{coarse:eA(e,{tolerance:n,angularTolerance:i}),fine:eA(e,{tolerance:r,angularTolerance:i*.2})}}function lA(e){let t=SD(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 uA(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)*lA(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 dA(e,t,n){return Math.min(e/t*n,1)}function fA(e,t={}){let n=t.angularTolerance??jo().angularTolerance,r=t.cache??!0,i=uA(e,t),a=Math.min(...i);return i.map(i=>{let o=dA(i,a,n);return{tolerance:i,angularTolerance:o,mesh:eA(e,{tolerance:i,angularTolerance:o,cache:r,...t.signal?{signal:t.signal}:{}})}})}function pA(){return new Promise(e=>{setTimeout(e,0)})}async function mA(e,t={}){let n=t.angularTolerance??jo().angularTolerance,r=t.cache??!0,i=t.meshLevel??((e,n,i)=>eA(e,{tolerance:n,angularTolerance:i,cache:r,...t.signal?{signal:t.signal}:{}})),a=uA(e,t),o=Math.min(...a),s=[];for(let[r,c]of a.entries()){if(t.signal?.aborted)break;let l=dA(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 pA()}return s}function hA(e,t,n){if(t<0||t>=e.length)throw Error(n??`Index ${t} out of bounds (length ${e.length})`);return e[t]}function gA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[0]}function _A(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[e.length-1]}function vA(e){return Array.from(Array(e).keys())}function yA(e){return vA(Math.min(...e.map(e=>e.length))).map(t=>e.map(e=>e[t]))}function bA(e,t){return SE(U().makeLineEdge([...e],[...t]))}function xA(e,t=[0,0,0],n=[0,0,1]){return SE(U().makeCircleEdge([...t],[...n],e))}function SA(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(SE(U().makeEllipseEdge([...n],[...r],e,t,i?[...i]:void 0)))}function CA(e,t,n,r=[0,0,0],i=[0,0,1],a=!1){return CE(U().makeHelixWire(e,t,n,[...r],[...i],a))}function wA(e,t,n){return SE(U().makeArcEdge([...e],[...t],[...n]))}function TA(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(SE(U().makeEllipseArc([...i],[...a],e,t,n,r,o?[...o]:void 0)))}function EA(e,{tolerance:t=.001,smoothing:n=null,degMax:r=6,degMin:i=1}={}){try{let a=e.map(e=>[...e]);return O(SE(U().approximatePoints(a,{tolerance:t,degMin:i,degMax:r,smoothing:n})))}catch(e){return k(N(`BSPLINE_FAILED`,`B-spline approximation failed`,e))}}function DA(e,{periodic:t=!1,tolerance:n=1e-7}={}){try{let r=e.map(e=>[...e]);return O(SE(U().interpolatePoints(r,{periodic:t,tolerance:n})))}catch(e){return k(N(`BSPLINE_INTERP_FAILED`,`B-spline interpolation failed`,e))}}function OA(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(SE(U().makeBezierEdge(t)))}function kA(e,t,n){return SE(U().makeTangentArc([...e],[...t],[...n]))}function AA(e){try{return O(CE(U().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 jA(e,t){try{let n=U().makeFace(e.wrapped,!0);if(t&&t.length>0){let e=FA(wE(n),t);return gE(e)?O(e):k(P(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}let r=wE(n);return gE(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 MA(e){return jA(EO(e))}function NA(e,t){return wE(U().makeFaceOnSurface(e.wrapped,t.wrapped))}function PA(e){try{return Ya(uO(U().makeNonPlanarFace(e.wrapped)),e=>ME(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 FA(e,t){return wE(U().addHolesInFace(e.wrapped,t.map(e=>e.wrapped)))}function IA(e){try{var t=NT();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 qT);return Ya(AA(yA([e,n]).map(([e,t])=>r.register(bA(e,t)))),e=>jA(r.register(e)))}catch(e){t.e=e}finally{t.d()}}function LA(e,t){return U().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function RA(e,t,n,r,i){let a=RE(e);if(!IE(a)){let o=sE(a).toUpperCase();return BE(e,a),HE(a),k(xo(t,`${n}. Got ${o} instead.`,void 0,i?{diagnostics:i}:void 0,r))}return BE(e,a),O(a)}function zA(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=LA(e,`fuse: first operand`);if(A(c))return c;let l=LA(t,`fuse: second operand`);if(A(l))return l;if(!s)return RA(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);let u=ok([e,t]),{shape:d,evolution:f,diagnostics:p}=U().fuseWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(U().isNull(d))return U().dispose(d),console.warn(`brepjs: fuse history path produced null result; retrying without evolution tracking.`,p),RA(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);console.warn(`brepjs: fuse reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=RA(d,`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`,`Common causes: overlapping coplanar faces, zero-thickness geometry, or non-manifold input. Try autoHeal() on inputs first.`,p);return m.ok&&sk(f,[e,t],m.value),m}function BA(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=LA(e,`cut: base`);if(A(c))return c;let l=LA(t,`cut: tool`);if(A(l))return l;if(!s)return RA(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);let u=ok([e,t]),{shape:d,evolution:f,diagnostics:p}=U().cutWithHistory(e.wrapped,t.wrapped,u,G,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(U().isNull(d))return U().dispose(d),console.warn(`brepjs: cut history path produced null result; retrying without evolution tracking.`,p),RA(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);console.warn(`brepjs: cut reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=RA(d,`CUT_NOT_3D`,`Cut did not produce a 3D shape`,`Common causes: tool does not fully intersect the base, or produces a zero-thickness sliver. Ensure the tool extends through the shape.`,p);return m.ok&&sk(f,[e,t],m.value),m}function VA(e,t,{simplify:n=!1,signal:r,fuzzyValue:i,unsafe:a,trackEvolution:o=!0}={}){if(r?.aborted)throw r.reason;let s=LA(e,`intersect: first operand`);if(A(s))return s;let c=LA(t,`intersect: second operand`);if(A(c))return c;if(!o)return RA(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);let l=ok([e,t]),{shape:u,evolution:d,diagnostics:f}=U().intersectWithHistory(e.wrapped,t.wrapped,l,G,{simplify:n,fuzzyValue:i});if(f.hasErrors){if(U().isNull(u))return U().dispose(u),console.warn(`brepjs: intersect history path produced null result; retrying without evolution tracking.`,f),RA(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);console.warn(`brepjs: intersect reported OCCT warnings/errors but produced a shape. Continuing with result.`,f)}let p=RA(u,`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`,`Shapes may not overlap. Verify they share a common volume before intersecting.`,f);return p.ok&&sk(d,[e,t],p.value),p}function HA(e,t,n,r,i,a,o,s){if(o?.aborted)throw o.reason;let c=n-t;if(c===1)return O(hA(e,t));if(c===2)return zA(hA(e,t),hA(e,t+1),{optimisation:r,simplify:!1,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}});let l=t+Math.ceil(c/2),u=HA(e,t,l,r,i,a,o,s);if(A(u))return u;let d=HA(e,l,n,r,i,a,o,s);return A(d)?d:zA(u.value,d.value,{optimisation:r,simplify:i,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}})}function UA(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(gA(e));for(let t=0;t<e.length;t++){let n=LA(hA(e,t),`fuseAll: shape at index ${t}`);if(A(n))return n}if(r===`native`){let o=RA(U().fuseAll(e.map(e=>e.wrapped),{optimisation:t,simplify:n,strategy:r,fuzzyValue:a,...i?{signal:i}:{}}),`FUSE_ALL_NOT_3D`,`fuseAll did not produce a 3D shape`);return o.ok&&s&&ck(e,o.value),o}return HA(e,0,e.length,t,n,s,i,a)}function WA(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=LA(e,`cutAll: base`);if(A(c))return c;for(let e=0;e<t.length;e++){let n=LA(hA(t,e),`cutAll: tool at index ${e}`);if(A(n))return n}let l=[e,...t],u=RA(U().cutAll(e.wrapped,t.map(e=>e.wrapped),{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_ALL_NOT_3D`,`cutAll did not produce a 3D shape`);return u.ok&&s&&ck(l,u.value),u}function GA(e,t){let n=U(),r=PD(e.xDir,t),i=PD(e.yDir,t),a=PD(e.xDir,-t),o=PD(e.yDir,-t),s=e.origin,c=[...MD(MD(s,a),o)],l=[...MD(MD(s,r),o)],u=[...MD(MD(s,r),i)],d=[...MD(MD(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 KA(e,t,{approximation:n=!0,planeSize:r=1e4}={}){if(U().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`section: shape is a null shape`));let i=GA(typeof t==`string`?j(QD(t)):t,r);try{return O(W(U().section(e.wrapped,i,n)))}catch(e){let n=e instanceof Error?e.message:String(e),r=typeof t==`string`?t:`custom`;return k(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{U().dispose(i)}}function qA(e){let t=U(),n=new Map,r=new Map;for(let i of e){let e=dD(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 JA(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 YA(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=JA(i,t,n);for(;o;)e===0?r.push(o.edge):r.unshift(o.edge),i=o.nextTip,o=JA(i,t,n)}return r}function XA(e){let t=U(),n=qA(e),r=new Set,i=[];for(let a of e){if(r.has(a))continue;let e=YA(a,n,r);try{let n=t.makeWire(e.map(e=>e.wrapped));i.push(W(n))}catch{}}return i}function ZA(e){let t=U(),n=0,r=-1;for(let i=0;i<e.length;i++){let a=e[i];if(!a)continue;let o=t.boundingBox(a.wrapped),s=o.max[0]-o.min[0],c=o.max[1]-o.min[1],l=o.max[2]-o.min[2],u=s*s+c*c+l*l;u>r&&(r=u,n=i)}return n}function QA(e,t,n={}){let r=KA(e,t,n);if(!r.ok)return r;let i=uD(r.value);if(i.length===0){let e=cD(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(...XA(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=ZA(i),o=hA(i,a),s=i.filter((e,t)=>t!==a);return jA(o,s.length>0?s:void 0)}function $A(e,t){if(t.length===0)return O(e);if(U().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(U().isNull(hA(t,e).wrapped))return k(P(M.NULL_SHAPE_INPUT,`splitShape: tool at index ${e} is a null shape`));try{return O(W(U().split(e.wrapped,t.map(e=>e.wrapped))))}catch(e){let n=e instanceof Error?e.message:String(e);return k(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 ej(e,t,n={}){let r=[];for(let i of t){let t=KA(e,i,n);if(A(t))return t;r.push(t.value)}return O(r)}function tj(e,t,n){if(t.length===0)return O(e);let r=n?.optimisation===`commonFace`?1:n?.optimisation===`sameFace`?2:0,i=U(),a=t.map(e=>({op:e.op,tool:e.tool.wrapped}));try{let o=i.booleanPipeline?.(e.wrapped,a,{glueMode:r});if(o===void 0)return nj(e,t,n);if(o===null)return k(N(`BOOLEAN_PIPELINE_FAILED`,`Boolean pipeline returned null shape`));let s=W(o);return IE(s)?O(s):(HE(s),k(xo(`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 nj(e,t,n){let r=e,i={...n?.optimisation?{optimisation:n.optimisation}:{},unsafe:!0};for(let e of t){let t=e.op===`fuse`?zA(r,e.tool,i):e.op===`cut`?BA(r,e.tool,i):VA(r,e.tool,i);if(A(t))return t;r=j(t)}return O(r)}function rj(e){return W(U().sew(e.map(e=>e.wrapped)))}function ij(e,t=!1){let n=rj(e);return!t&&!NE(n)?k(xo(`WELD_NOT_SHELL`,`Could not make a shell from faces and shells`)):O(n)}function aj(e,t,n=[0,0,0],r=[0,0,1]){return EE(U().makeCylinder(e,t,[...n],[...r]))}function oj(e){return EE(U().makeSphere(e))}function sj(e,t,n,r=[0,0,0],i=[0,0,1]){return EE(U().makeCone(e,t,n,[...r],[...i]))}function cj(e,t,n=[0,0,0],r=[0,0,1]){return EE(U().makeTorus(e,t,[...n],[...r]))}function lj(e,t,n){return EE(U().makeEllipsoid(e,t,n))}function uj(e){return xE(U().makeVertex(e[0],e[1],e[2]))}function dj(e,t,n=1e-6){return Ya(cO(U().offset(e.wrapped,t,n)),e=>Ya(uO(e),e=>IE(e)?O(e):k(xo(`OFFSET_NOT_3D`,`Could not offset to a 3d shape`))))}function fj(e){return OE(U().makeCompound(e.map(e=>e.wrapped)))}function pj(e){try{var t=NT();let n=t.u(rj(e)),r=W(U().solidFromShell(n.wrapped));return PE(r)?O(r):(HE(r),k(xo(`SOLID_BUILD_FAILED`,`Could not make a solid of faces and shells`)))}catch(e){t.e=e}finally{t.d()}}function mj(e){return{position:e.vertices,normal:e.normals,index:e.triangles}}function hj(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 gj(e){return{position:e.lines}}function _j(e,t){return{coarse:mj(e.coarse),fine:mj(e.fine),coarseDistance:t?.coarse??50,fineDistance:t?.fine??0}}function vj(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:mj(e.mesh),distance:r?.[t]??(i-t)*n}))}function yj(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=U(),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=cO(i);if(A(a))return U().dispose(i),a;let o=W(a.value);return BE(i,o),IE(o)?O(o):(HE(o),k(xo(`CHAMFER_ANGLE_NOT_3D`,`chamferDistAngle did not produce a 3D shape`)))}function bj(e){let t=U();return t.getNurbsCurveData?t.getNurbsCurveData(e.wrapped):null}function xj(e){let t=U();return t.getNurbsSurfaceData?t.getNurbsSurfaceData(e.wrapped):null}var Sj={cut:BA,cutAll:WA,fuse:zA,fuseAll:UA};function Cj(e){return{totalInputs:e.totalInputs,batchAttempts:e.batchAttempts,batchSucceeded:e.batchSucceeded,singletonFallbacks:e.singletonFallbacks,failedInputs:[...e.failedInputs].sort((e,t)=>e-t)}}function wj(e,t,n={}){return Tj(Sj,e,t,n)}function Tj(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=Ej(e,t,n,0,r,i);return A(a)?a:O({shape:a.value,telemetry:Cj(i)})}function Ej(e,t,n,r,i,a){if(n.length===0)return O(t);if(n.length===1)return Dj(e,t,n,r,i,a);a.batchAttempts++;let o=Mj(()=>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=Ej(e,t,n.slice(0,s),r,i,a);return c.ok?Ej(e,c.value,n.slice(s),r+s,i,a):c}function Dj(e,t,n,r,i,a){a.singletonFallbacks++;let o=gA(n),s=Mj(()=>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 Oj(e,t={}){return kj(Sj,e,t)}function kj(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=Aj(e,t,0,n,r);return A(i)?i:O({shape:i.value,telemetry:Cj(r)})}function Aj(e,t,n,r,i){if(t.length===1)return O(gA(t));i.batchAttempts++;let a=Mj(()=>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 jj(e,Aj(e,t.slice(0,o),n,r,i),Aj(e,t.slice(o),n+o,r,i),t,n,o,r,i)}function jj(e,t,n,r,i,a,o,s){if(t.ok&&n.ok){s.singletonFallbacks++;let c=Mj(()=>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 Mj(e){try{return e()}catch{return null}}function Nj(e,t,n){return U().checkBoolean(e.wrapped,t.wrapped,n)}function Pj(e,t){return U().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Fj(e,t){return U().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Ij(e,t,n,r){let i=RE(e);if(!IE(i)){let a=sE(i).toUpperCase();return BE(e,i),HE(i),k(xo(t,`${n}. Got ${a} instead.`,void 0,void 0,r))}return BE(e,i),O(i)}function Lj(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>r.get(U().hashCode(e,2147483647))??1}}function Rj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Pj(e,`fuseWithEvolution: first operand`);if(A(o))return o;let s=Pj(t,`fuseWithEvolution: second operand`);if(A(s))return s;let c=ok([e,t]),{shape:l,evolution:u}=U().fuseWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Ij(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?(sk(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function zj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Pj(e,`cutWithEvolution: base`);if(A(o))return o;let s=Pj(t,`cutWithEvolution: tool`);if(A(s))return s;let c=ok([e,t]),{shape:l,evolution:u}=U().cutWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Ij(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?(sk(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function Bj(e,t,{simplify:n=!1,signal:r,fuzzyValue:i}={}){if(r?.aborted)throw r.reason;let a=Pj(e,`intersectWithEvolution: first operand`);if(A(a))return a;let o=Pj(t,`intersectWithEvolution: second operand`);if(A(o))return o;let s=ok([e,t]),{shape:c,evolution:l}=U().intersectWithHistory(e.wrapped,t.wrapped,s,G,{simplify:n,fuzzyValue:i}),u=Ij(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?(sk(l,[e,t],u.value),O({shape:u.value,evolution:l})):u}function Vj(e,t,n){let r=Fj(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??cD(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=Lj(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=ok([e]),{shape:o,evolution:s}=U().filletWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return IE(c)?(sk(s,[e],c),O({shape:c,evolution:s})):(HE(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 Hj(e,t,n){let r=Fj(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??cD(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=Lj(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=ok([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return IE(c)?(sk(s,[e],c),O({shape:c,evolution:s})):(HE(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 Uj(e,t,n,r=.001){let i=Fj(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=ok([e]),{shape:a,evolution:o}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,i,G,r),s=W(a);return IE(s)?(sk(o,[e],s),O({shape:s,evolution:o})):(HE(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 Wj(e,t,n){try{let r=W(U().positionOnCurve(e.wrapped,t.wrapped,n));return IE(r)?O(r):(HE(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 Gj(e,t){return U().isNull(e.wrapped)?k(P(M.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Kj(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 qj(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>{let t=r.get(U().hashCode(e,G));if(t===void 0)throw Error(`fillet/chamfer: edge hash not found — possible hash collision`);return t}}}function Jj(e,t,n,r,i){let a=W(t);return IE(a)?(sk(e,n,a),O(a)):(HE(a),k(N(r,i)))}function Yj(e,t){if(typeof t!=`function`)return{filteredFaces:[...e],kernelAngle:t};let n=[],r=new Map;for(let i of e){let e=t(i);e===null||e===0||Math.abs(e)>=90||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return{filteredFaces:n,kernelAngle:e=>{let t=r.get(U().hashCode(e,G));if(t===void 0)throw Error(`draft: face hash not found — possible hash collision`);return t}}}function Xj(e,t){let n=Gj(e,`thicken: shape`);if(A(n))return n;try{let n=ok([e]),{shape:r,evolution:i}=U().thickenWithHistory(e.wrapped,t,n,G),a=W(r);return sk(i,[e],a),O(a)}catch(e){return k(N(`THICKEN_FAILED`,`Thicken operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function Zj(e,t,n){let r=Gj(e,`fillet: shape`);if(A(r))return r;let i=Kj(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??cD(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=qj(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 Qj(e,t,n,{trackEvolution:r=!0}={}){let i=Zj(e,t,n);if(A(i))return i;let{filteredEdges:a,kernelRadius:o,selectedCount:s}=i.value;try{let t=a.map(e=>e.wrapped);if(!r){let n=W(U().fillet(e.wrapped,t,o));return IE(n)?O(n):k(N(M.FILLET_NOT_3D,`Fillet result is not a 3D shape`))}let n=ok([e]),{shape:i,evolution:s}=U().filletWithHistory(e.wrapped,t,o,n,G);return Jj(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 $j(e,t,n){let r=Gj(e,`chamfer: shape`);if(A(r))return r;let i=Kj(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??cD(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=qj(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=ok([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,i,G);return Jj(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 eM(e,t,n,r=.001,{trackEvolution:i=!0}={}){let a=Gj(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=W(U().shell(e.wrapped,t.map(e=>e.wrapped),n,r));return IE(i)?O(i):k(N(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}let a=ok([e]),{shape:o,evolution:s}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,a,G,r),c=W(o);return IE(c)?(sk(s,[e],c),O(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 tM(e,t,n=1e-6){let r=Gj(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=ok([e]),{shape:i,evolution:a}=U().offsetWithHistory(e.wrapped,t,r,G,n),o=W(i);return IE(o)?(sk(a,[e],o),O(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 nM(e,t,n){let r=Gj(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 rM(e,t,n,r,i){let a=nM(e,t,i);if(a)return a;try{let{filteredFaces:a,kernelAngle:o}=Yj(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=ok([e]),{shape:c,evolution:l}=U().draftWithHistory(e.wrapped,a.map(e=>e.wrapped),[n[0],n[1],n[2]],[r[0],r[1],r[2]],o,s,G);return Jj(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 iM(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=U();try{let i=JSON.stringify({edge:r.hashCode(t.wrapped,G),radii:n.map(e=>({param:e.param,radius:e.radius}))}),a=W(r.filletVariable(e.wrapped,i));return IE(a)?PE(a)?O(a):(HE(a),k(N(M.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a solid`))):(HE(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 aM(e){return TD(e)}function oM(e){if(!PE(e))return k(P(`NOT_A_SOLID`,`Input shape is not a solid`));let t=aM(e);try{let n=U().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=W(n);return PE(r)?(sD(r),aM(r)?O(r):(HE(r),k(N(`HEAL_SOLID_INCOMPLETE`,`Healed result is still invalid after ShapeFix_Solid`)))):(HE(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 sM(e){if(!ME(e))return k(P(`NOT_A_FACE`,`Input shape is not a face`));try{let t=W(U().healFace(e.wrapped));return ME(t)?O(t):(HE(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 cM(e,t){if(!jE(e))return k(P(`NOT_A_WIRE`,`Input shape is not a wire`));try{let n=W(U().healWire(e.wrapped,t?.wrapped));return jE(n)?O(n):(HE(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 lM(e){return PE(e)?oM(e):ME(e)?sM(e):jE(e)?cM(e):O(e)}function uM(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(aM(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=uD(e).length,u=lD(e).length,d=e,f=!1,p=t=>{let n=d;d=t,n!==e&&n.wrapped!==t.wrapped&&HE(n)};if(o!==void 0)try{p(W(U().sew([d.wrapped],o))),s.push(`Applied sewing with tolerance ${o}`),c.push({name:`sew`,attempted:!0,succeeded:!0,detail:`tolerance=${o}`})}catch(e){let t=e instanceof Error?e.message:String(e);s.push(`Sewing failed: ${t}`),c.push({name:`sew`,attempted:!0,succeeded:!1,detail:t})}if(a&&n){let e=uD(d),t=0;for(let n of e)try{U().fixSelfIntersection(n.wrapped),t++}catch{}s.push(`Self-intersection fix: ${t}/${e.length} wires`),c.push({name:`fixSelfIntersection`,attempted:!0,succeeded:t>0,detail:`${t}/${e.length} wires fixed`})}if(PE(d)&&i||ME(d)&&r||jE(d)&&n){let t=lM(d);Ka(t)?(p(t.value),PE(e)?(f=!0,s.push(`Applied ShapeFix_Solid`),c.push({name:`healSolid`,attempted:!0,succeeded:!0})):ME(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=uD(d).length,h=lD(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=aM(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 dM(e){try{return O(W(U().fixShape(e.wrapped)))}catch(e){return k(N(M.FIX_SHAPE_FAILED,`ShapeFix_Shape failed`,e))}}function fM(e){try{let t=W(U().solidFromShell(e.wrapped));return PE(t)?aM(t)?O(t):(HE(t),k(N(M.SOLID_FROM_SHELL_FAILED,`solidFromShell produced an invalid solid`))):(HE(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 pM(e){try{let t=W(U().fixSelfIntersection(e.wrapped));return jE(t)?O(t):(HE(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 mM(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(U().buildExtrusionLaw(t,e,n).Trim(0,e,1e-6))}function hM(e,t){let n=U(),r=n.makeLineEdge([...e],[...t]),i=n.makeWire([r]);return n.dispose(r),W(i)}function gM(e,t,n,r,i,a=!1){return W(U().makeHelixWire(e,t,n,[...r],[...i],a))}function _M(e){let t=W(e.shape),n=W(e.firstShape),r=W(e.lastShape),i=()=>{HE(t),HE(n),HE(r)};return IE(t)?jE(n)?jE(r)?O([t,n,r]):(i(),k(xo(`SWEEP_END_NOT_WIRE`,`Sweep did not produce an end Wire`))):(i(),k(xo(`SWEEP_START_NOT_WIRE`,`Sweep did not produce a start Wire`))):(i(),k(xo(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function vM(e,t,n={},r=!1){if(n.mode===`simple`&&!r){let n=W(U().simplePipe(e.wrapped,t.wrapped));return IE(n)?O(n):(HE(n),k(xo(`SWEEP_NOT_3D`,`Simple pipe did not produce a 3D shape`)))}let{frenet:i=!1,auxiliarySpine:a,law:o=null,transitionMode:s=`right`,withContact:c,support:l,forceProfileSpineOthogonality:u,tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h}=n,g=U(),_=s===`round`?!0:!!u,v=g.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:s,contact:!!c,correction:_,frenet:i,shellMode:r,...a?.wrapped?{auxiliary:a.wrapped}:{},...o===null?{}:{law:o},...l===null?{}:{support:l},tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h});if(r&&typeof v==`object`&&`firstShape`in v)return _M(v);let y=W(v);return IE(y)?O(y):(HE(y),k(xo(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function yM(e,t,n,r){return vM(e,hM(t,MD(t,n)),{support:r})}function bM(e,t,n,r,i=!1){try{var a=NT();let o=RD(n);if(o<1e-10)return k(P(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let s=MD(t,n),c=a.u(hM(t,s)),l=null;if(r){let e=mM(o,r);if(A(e))return e;l=e.value}return vM(e,c,{law:l},i)}catch(e){a.e=e}finally{a.d()}}function xM(e,t,n,r,i,a=!1){try{var o=NT();if(Math.abs(t)<1e-10)return k(P(`ZERO_TWIST_ANGLE`,`Twist angle cannot be zero`));let s=RD(r);if(s<1e-10)return k(P(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let c=MD(n,r),l=o.u(hM(n,c)),u=t<0,d=360/Math.abs(t)*s,f=o.u(gM(d,s,1,n,r,u)),p=null;if(i){let e=mM(s,i);if(A(e))return e;p=e.value}return vM(e,l,{auxiliarySpine:f,law:p},a)}catch(e){o.e=e}finally{o.d()}}function SM(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 CM(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 wM(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=SM(e);if(o)return k(o);try{let n=U(),o=CM(e,t,n);if(A(o))return o;let s=o.value,c=[],l=[];try{for(let r=0;r<e.length;r++){let i=s[r],a=e[r];if(i===void 0||a===void 0)continue;let o=n.positionOnCurve(a.wire.wrapped,t.wrapped,i);c.push(o),l.push(n.downcast(o,`wire`))}let o=W(n.loftAdvanced(l,{solid:r,ruled:i,tolerance:a}));return IE(o)?O(o):(HE(o),k(xo(`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 TM(e,t,n,r={}){let{transition:i=`transformed`,solid:a=!0,tolerance:o}=r;try{let r=U(),s=!a,c=n.length>0?n[0]?.wrapped:void 0,l=r.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:i,...c?{auxiliary:c}:{},shellMode:s,...o===void 0?{}:{tolerance:o,boundTolerance:o}}),u=W(typeof l==`object`&&`shape`in l?l.shape:l);return IE(u)?O(u):(HE(u),k(xo(`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 EM(e,t){if(U().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`extrude: face is a null shape`));if(RD(t)<1e-10)return k(P(`EXTRUDE_ZERO_VECTOR`,`extrude: extrusion vector has zero length`));try{let n=U(),r=RD(t),i=VD(t),a=n.extrude(e.wrapped,[...i],r),o=EE(n.downcast(a,`solid`));return BE(a,o),O(o)}catch(e){return k(N(`EXTRUDE_FAILED`,`Extrusion operation failed`,e,{operation:`extrude`,vectorLength:RD(t)}))}}function DM(e,t=[0,0,0],n=[0,0,1],r=2*Math.PI){if(U().isNull(e.wrapped))return k(P(M.NULL_SHAPE_INPUT,`revolve: face is a null shape`));try{let i=W(U().revolveVec(e.wrapped,[...t],[...n],r));return IE(i)?O(i):(HE(i),k(xo(`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 OM(e){if(e.length===0)return O([]);let t=U(),n=[];for(let t=0;t<e.length;t++){let r=e[t];if(!r)continue;let i=typeof r.height==`number`?[0,0,r.height]:r.height,a=RD(i);if(a<1e-10)return k(P(`EXTRUDE_ALL_ZERO_VECTOR`,`extrudeAll: entry ${t} has zero-length extrusion vector`));let o=[...VD(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=EE(t.downcast(e,`solid`));return BE(e,n),n}))}catch(e){return k(N(`EXTRUDE_ALL_FAILED`,`Batch extrusion operation failed`,e))}}function kM(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=U(),s=n?o.makeVertex(...OD(n)):void 0,c=r?o.makeVertex(...OD(r)):void 0;try{let n=W(o.loftAdvanced(e.map(e=>e.wrapped),{solid:!a,ruled:t,tolerance:i,...s?{startVertex:s}:{},...c?{endVertex:c}:{}}));return IE(n)?O(n):(HE(n),k(xo(`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 AM(e){if(e.length===0)return O([]);let t=U(),n=[],r=e.map(e=>{let r=e.startPoint?t.makeVertex(...OD(e.startPoint)):void 0,i=e.endPoint?t.makeVertex(...OD(e.endPoint)):void 0;return r&&n.push(r),i&&n.push(i),{wires:e.wires.map(e=>e.wrapped),solid:!0,ruled:e.ruled??!0,tolerance:e.tolerance??1e-6,startVertex:r,endVertex:i}});try{let e=t.loftBatch?.(r)??r.map(e=>t.loftAdvanced(e.wires,{solid:e.solid,ruled:e.ruled,tolerance:e.tolerance,startVertex:e.startVertex,endVertex:e.endVertex})),n=[];for(let t of e){let e=W(t);if(!IE(e))return HE(e),k(xo(`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 jM=new WeakMap;function MM(e,t){return jM.get(e)?.get(t)}function NM(e,t,n){let r=jM.get(e);r||(r=new Map,jM.set(e,r)),r.set(t,n)}function PM(e){return U().isNull(e.wrapped)}function FM(e){return k(P(M.NULL_SHAPE_INPUT,`${e}: shape is a null shape`))}function IM(e){let t=MM(e.wrapped,`volume`);if(t)return O(t);if(PM(e))return FM(`measureVolumeProps`);let n=U(),r=n.shapeType(e.wrapped);if(r!==`solid`&&r!==`compsolid`&&r!==`compound`){let t={mass:0,volume:0,centerOfMass:[0,0,0]};return NM(e.wrapped,`volume`,t),O(t)}let i=n.volume(e.wrapped),a=ZE(()=>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 NM(e.wrapped,`volume`,o),O(o)}function LM(e){let t=MM(e.wrapped,`surface`);if(t)return O(t);if(PM(e))return FM(`measureSurfaceProps`);let n=U(),r=n.area(e.wrapped),i=ZE(()=>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 NM(e.wrapped,`surface`,a),O(a)}function RM(e){let t=MM(e.wrapped,`linear`);if(t)return O(t);if(PM(e))return FM(`measureLinearProps`);let n=U(),r=n.length(e.wrapped),i={mass:r,length:r,centerOfMass:n.linearCenterOfMass(e.wrapped)};return NM(e.wrapped,`linear`,i),O(i)}function zM(e){let t=IM(e);return t.ok?O(t.value.mass):t}function BM(e){let t=LM(e);return t.ok?O(t.value.mass):t}function VM(e){let t=RM(e);return t.ok?O(t.value.mass):t}function HM(e,t){return PM(e)||PM(t)?FM(`measureDistance`):O(U().distance(e.wrapped,t.wrapped).value)}function UM(e,t){if(PM(e)||PM(t))return FM(`measureDistanceProps`);let n=U().distance(e.wrapped,t.wrapped);return O({distance:n.value,point1:n.point1,point2:n.point2})}function WM(e){if(PM(e))return FM(`createDistanceQuery`);let t=U().createDistanceQuery(e.wrapped);return O({distanceTo(e){return PM(e)?FM(`createDistanceQuery.distanceTo`):O(t.distanceTo(e.wrapped).value)},dispose(){t.dispose()}})}function GM(e,t,n){if(PM(e))return FM(`measureCurvatureAt`);let r=U().surfaceCurvature(e.wrapped,t,n);return O({mean:r.mean,gaussian:r.gaussian,maxCurvature:r.max,minCurvature:r.min,maxDirection:r.maxDirection,minDirection:r.minDirection})}function KM(e){if(PM(e))return FM(`measureCurvatureAtMid`);let t=vO(e),n=(t.uMin+t.uMax)/2,r=(t.vMin+t.vMax)/2,i=U().surfaceCurvature(e.wrapped,n,r);return O({mean:i.mean,gaussian:i.gaussian,maxCurvature:i.max,minCurvature:i.min,maxDirection:i.maxDirection,minDirection:i.minDirection})}function qM(e,t){return e.map(e=>GE(e,t))}function JM(e,t){let n=U(),r=n.iterShapes(e,t),i=[],a=new Map;for(let e of r){let r=n.hashCode(e,G),o=a.get(r);if(o?.some(t=>n.isSame(t,e))){n.dispose(e);continue}let s=WE(e,t);i.push(s),o?o.push(s.wrapped):a.set(r,[s.wrapped])}return i}function YM(e){let t=U(),n=new Map;for(let r of e){let e=t.hashCode(r.wrapped,G),i=n.get(e);i?i.push(r):n.set(e,[r])}return n}function XM(e,t,n){let r=U();return e.get(n)?.find(e=>r.isSame(e.wrapped,t))}function ZM(e){let t=aD(e);if(t.edgeToFaces)return t.edgeToFaces;let n=U(),r=lD(e),i=YM(cD(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=XM(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 QM(e){let t=aD(e);if(t.vertexToFaces)return t.vertexToFaces;let n=U(),r=lD(e),i=YM(dD(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=XM(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 $M(e,t){let n=U(),r=ZM(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 qM(o,`face`)}function eN(e,t){let n=U(),r=QM(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 qM(o,`face`)}function tN(e){return JM(e.wrapped,`edge`)}function nN(e){return JM(e.wrapped,`vertex`)}function rN(e){return JM(e.wrapped,`wire`)}function iN(e){return JM(e.wrapped,`vertex`)}function aN(e,t){let n=U(),r=ZM(e),i=JM(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 qM(a,`face`)}var oN=new Map;function sN(e,t){let n=U(),r=ST()??``;if(oN.get(r)!==!1){let i;try{i=n.sharedEdges(e.wrapped,t.wrapped);let a=i.map(e=>WE(e,`edge`));return oN.set(r,!0),a}catch(e){if(i)for(let e of i)n.dispose(e);if(!l(e))throw e;oN.set(r,!1)}}return cN(e,t)}function cN(e,t){let n=U(),r=n.iterShapes(e.wrapped,`edge`),i=n.iterShapes(t.wrapped,`edge`),a=new Map;for(let e of i){let t=n.hashCode(e,G),r=a.get(t);r||(r=[],a.set(t,r)),r.push(e)}let o=[];for(let e of r)a.get(n.hashCode(e,2147483647))?.some(t=>n.isSame(e,t))?o.push(WE(e,`edge`)):n.dispose(e);for(let e of i)n.dispose(e);return o}var lN=new Map;function uN(e,t){let n=U(),r=ST()??``;if(lN.get(r)!==!1)try{let i=n.adjacentFaces(e.wrapped,t.wrapped);lN.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;lN.set(r,!1)}return aN(e,t).map(e=>n.hashCode(e.wrapped,G))}function dN(e,t){let n=0,r=hO(t);if(e.surfaceType!==void 0)if(r===e.surfaceType)n+=1;else return-1/0;if(e.normal!==void 0){let r=SO(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=CO(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=BM(t);if(r.ok&&r.value>0){let t=Math.abs(Math.log(e.area/r.value));t>1&&(n-=t)}}return n}function fN(e){let t=hO(e),n=SO(e),r=CO(e),i=BM(e);return{entityType:`face`,surfaceType:t,normal:n,centroid:r,area:i.ok?i.value:void 0}}var pN=.9;function mN(e){if(e[2]>pN)return`box:top`;if(e[2]<-.9)return`box:bottom`;if(e[1]>pN)return`box:back`;if(e[1]<-.9)return`box:front`;if(e[0]>pN)return`box:right`;if(e[0]<-.9)return`box:left`}function hN(e,t){if(hO(t)!==`PLANE`)return;let n=SO(t)[2];if(n>pN)return`${e}:top`;if(n<-.9)return`${e}:bottom`}function gN(e){return hO(e)===`CYLINDRE`?`cylinder:lateral`:hN(`cylinder`,e)}function _N(e){return hO(e)===`CONE`?`cone:lateral`:hN(`cone`,e)}function vN(e){return hO(e)===`SPHERE`?`sphere:surface`:void 0}var yN={box:e=>mN(SO(e)),cylinder:gN,cone:_N,sphere:vN};function bN(e,t){let n=new Map,r=yN[t],i=U(),a=0;for(let o of i.iterShapes(e.wrapped,`face`)){let e=UE(o,`face`);try{let i=r?.(e),o=i!==void 0&&!n.has(i)?i:`${t}:face_${a}`;n.set(o,[wk(e)]),a++}finally{VE(e,o)}}return n}function xN(e,t,n){return{origin:e,role:t,hint:fN(n)}}function SN(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 CN(e,t,n){let r=e.get(t);if(!r)return e;let i=new Map;for(let[e,t]of r){let r=SN(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 wN=.1,TN=.5;function EN(e,t,n){let r=-1/0,i,a=-1/0,o=[];for(let s of t){let t=n(e,s);t>TN&&o.push([s,t]),t>r?(a=r,r=t,i=s):t>a&&(a=t)}return i!==void 0&&r>TN?r-a<wN&&o.length>1?{kind:`ambiguous`,candidates:o.filter(([,e])=>e>=r-wN).map(([e])=>e)}:{kind:`match`,face:i}:{kind:`none`}}function DN(e,t,n,r){let i=lD(n),a=r??dN,o=t.get(e.origin)?.get(e.role);if(o!==void 0&&o.length>0){let t=i.filter(e=>o.includes(wk(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=EN(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=EN(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 ON(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 kN(e){if(e.length===0)return;let t=0,n=0,r=0;for(let i of e){let e=DD(i);t+=e[0],n+=e[1],r+=e[2]}let i=e.length;return[t/i,n/i,r/i]}function AN(e,t,n){let r=n.get(t);if(!r)return;let i=wk(e);for(let[e,t]of r)if(t.includes(i))return e}function jN(e,t,n,r){let i=r.get(t)?.get(n);return i===void 0||i.length===0?[]:lD(e).filter(e=>i.includes(wk(e)))}function MN(e){let t=VM(e);return{entityType:`edge`,length:t.ok?t.value:void 0,midpoint:kN(iN(e))}}function NN(e){let t=new Set,n=[];for(let r of e){let e=wk(r);t.has(e)||(t.add(e),n.push(r))}return n}var PN=1e-6;function FN(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=VM(a);n.ok&&(e+=Math.abs(n.value-t.length))}if(t.midpoint!==void 0){let n=kN(iN(a));n!==void 0&&(e+=ON(t.midpoint,n))}e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<PN))return n}function IN(e,t,n,r){let[i,a]=$M(n,t);if(i===void 0||a===void 0)return;let o=AN(i,e,r),s=AN(a,e,r);if(!(o===void 0||s===void 0))return{origin:e,faceRoles:[o,s],hint:MN(t)}}function LN(e,t,n){let[r,i]=e.faceRoles,a=jN(n,e.origin,r,t),o=jN(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(...sN(e,t));let c=NN(s);if(c.length===1){let[e]=c;if(e!==void 0)return{edge:e,confidence:`exact`}}if(c.length>1){let t=FN(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 RN=3,zN=1e-6;function BN(e,t){let n=new Set;for(let r of e)for(let e of nN(r)){let r=wk(e);n.add(r),t.has(r)||t.set(r,e)}return n}function VN(e,t){let n=new Set;for(let r of e)t.has(r)&&n.add(r);return n}function HN(e){let t=new Map,n;for(let r of e){let e=BN(r,t);n=n===void 0?e:VN(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 UN(e,t){if(t.position===void 0)return;let n,r=1/0,i=1/0;for(let a of e){let e=ON(DD(a),t.position);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<zN))return n}function WN(e,t,n,r){let i=eN(n,t);if(i.length<RN)return;let a=new Set;for(let t of i){let n=AN(t,e,r);n!==void 0&&a.add(n)}if(!(a.size<RN))return{origin:e,faceRoles:[...a].sort(),hint:{entityType:`vertex`,position:DD(t)}}}function GN(e,t,n){let r=[];for(let i of e.faceRoles){let a=jN(n,e.origin,i,t);if(a.length===0)return{ref:e,reason:`not-found`};r.push(a)}let i=HN(r);if(i.length===1){let[e]=i;if(e!==void 0)return{vertex:e,confidence:`exact`}}if(i.length>1){let t=UN(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 KN=.99,qN=.1,JN=1e-6;function YN(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function XN(e,t){return lD(e).filter(e=>YN(SO(e),t)>KN)}function ZN(e,t,n){let r=new Set([...t,...n].map(wk)),i=new Set;for(let n of t)for(let t of uN(e,n))i.add(t);let a=[],o=new Set;for(let t of n)for(let n of uN(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(lD(e).map(e=>[wk(e),e]));return a.map(e=>s.get(e)).filter(e=>e!==void 0)}function QN(e,t){let n,r=1/0,i=1/0;for(let a of e){let e=ON(CO(a),t);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<JN))return n}function $N(e,t,n,r,i){let[a,o]=$M(r,n);if(a===void 0||o===void 0)return;let s=AN(a,e,i),c=AN(o,e,i);if(!(s===void 0||c===void 0))return{origin:e,op:t,betweenRoles:[s,c],hint:{entityType:`derived-face`,normalA:SO(a),normalB:SO(o),edgeMidpoint:kN(iN(n))}}}function eP(e,t,n){let r=jN(n,e.origin,e.betweenRoles[0],t);r.length===0&&(r=XN(n,e.hint.normalA));let i=jN(n,e.origin,e.betweenRoles[1],t);if(i.length===0&&(i=XN(n,e.hint.normalB)),r.length===0||i.length===0)return{ref:e,reason:`not-found`};let a=ZN(n,r,i).filter(t=>YN(SO(t),e.hint.normalA)>qN&&YN(SO(t),e.hint.normalB)>qN);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&&QN(a,e.hint.edgeMidpoint);return t?{face:t,confidence:`geometric-fallback`}:{ref:e,reason:`ambiguous`,candidates:a}}return{ref:e,reason:`not-found`}}function tP(e){return typeof e==`object`&&!!e&&`origin`in e}function nP(e){return tP(e)&&`betweenRoles`in e&&`op`in e}function rP(e){return tP(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length===2}function iP(e){return tP(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length>=3}function aP(e){return tP(e)&&typeof e.role==`string`}function oP(e){return aP(e)||rP(e)||iP(e)||nP(e)}function sP(e,t){return t===void 0?{ok:!1,reason:e}:{ok:!1,reason:e,candidates:t}}function cP(e,t,n){if(nP(e)){let r=eP(e,t,n);return`face`in r?{ok:!0,entity:r.face}:sP(r.reason,r.candidates)}if(rP(e)){let r=LN(e,t,n);return`edge`in r?{ok:!0,entity:r.edge}:sP(r.reason,r.candidates)}if(iP(e)){let r=GN(e,t,n);return`vertex`in r?{ok:!0,entity:r.vertex}:sP(r.reason,r.candidates)}let r=DN(e,t,n);return`face`in r?{ok:!0,entity:r.face}:sP(r.reason,r.candidates)}function lP(e,t,n){let r=n.get(e.origin);if(r!==void 0)return r;let i=new Map([[e.origin,bN(t,e.origin)]]);return n.set(e.origin,i),i}function uP(e,t){return cP(e,lP(e,t,new Map),t)}function dP(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 fP(e,t){let n=new Map,r=e=>{if(oP(e)){let r=cP(e,lP(e,t,n),t);return r.ok?r.entity:e}if(Array.isArray(e))return e.map(r);if(dP(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 pP(e,t,n,r){let i=EE(U().makeBox(e,t,n)),a=r?.at??(r?.centered?[0,0,0]:void 0);if(a)try{var o=NT();return uk(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 mP(e,t,n){let r=n?.at??[0,0,0],i=n?.axis??[0,0,1],a=aj(e,t,r,i);if(n?.centered)try{var o=NT();let e=[-i[0]*t*.5,-i[1]*t*.5,-i[2]*t*.5];return uk(o.u(a),e)}catch(e){o.e=e}finally{o.d()}return a}function hP(e,t){let n=oj(e);if(t?.at)try{var r=NT();return uk(r.u(n),t.at)}catch(e){r.e=e}finally{r.d()}return n}function gP(e,t,n,r){let i=r?.at??[0,0,0],a=r?.axis??[0,0,1],o=sj(e,t,n,i,a);if(r?.centered)try{var s=NT();let e=[-a[0]*n*.5,-a[1]*n*.5,-a[2]*n*.5];return uk(s.u(o),e)}catch(e){s.e=e}finally{s.d()}return o}function _P(e,t,n){return cj(e,t,n?.at??[0,0,0],n?.axis??[0,0,1])}function vP(e,t,n,r){let i=lj(e,t,n);if(r?.at)try{var a=NT();return uk(a.u(i),r.at)}catch(e){a.e=e}finally{a.d()}return i}function yP(e,t){return bA(e,t)}function bP(e,t){let n=t?.axis??[0,0,1];return xA(e,t?.at??[0,0,0],n)}function xP(e,t,n){let r=n?.axis??[0,0,1];return SA(e,t,n?.at??[0,0,0],r,n?.xDir)}function SP(e,t,n,r){return CA(e,t,n,r?.at??[0,0,0],r?.axis??[0,0,1],r?.lefthand??!1)}function CP(e,t,n){return wA(e,t,n)}function wP(e,t,n,r,i){let a=i?.axis??[0,0,1];return TA(e,t,n*KE,r*KE,i?.at??[0,0,0],a,i?.xDir)}function TP(e,t){return EA(e,t)}function EP(e){return OA(e)}function DP(e,t,n){return kA(e,t,n)}function OP(e){return AA(e)}function kP(e){return Ya(AA(e),e=>cE(e)?O(e):k(P(`WIRE_NOT_CLOSED`,`Assembled wire is not closed: start and end points do not coincide`)))}function AP(e,t){return jA(e,t)}function jP(e){return PA(e)}function MP(e,t){return NA(e,t)}function NP(e){return IA(e)}function PP(e){return uj(e)}function FP(e){return fj(e)}function IP(e){return pj(e)}function LP(e,t,n){return dj(e,t,n)}function RP(e,t){return ij(e,t)}function zP(e,t){return FA(e,t)}function BP(){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 VP(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??BP(),color:[a,o,s,c]}});return KT(U().createXCAFDocument(t))}function HP(e=[],{unit:t,modelUnit:n}={}){let r=e=>{let t=e;return t.indexOf(`#`)===0&&(t=t.slice(1)),t.length===3&&(t=t.replace(/([0-9a-f])/gi,`$1$1`)),[parseInt(t.substring(0,2),16),parseInt(t.substring(2,4),16),parseInt(t.substring(4,6),16)]},i=U(),a=e.map(({shape:e,name:t,color:n,alpha:i})=>{let[a,o,s]=r(n??`#f00`);return{shape:e.wrapped,name:t??BP(),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(wo(`STEP_EXPORT_FAILED`,`Failed to write STEP file`))}finally{o.delete()}}function UP(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(UD(t))return k(P(`PATTERN_ZERO_DIRECTION`,`Pattern direction cannot be zero`));let a=VD(t),o=U().linearPattern(e.wrapped,[...a],r,n).map(e=>W(e));try{return UA(o,{optimisation:`sameFace`,...i,unsafe:!0})}finally{for(let e of o)e[Symbol.dispose]()}}function WP(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(UD(t))return k(P(`PATTERN_ZERO_AXIS`,`Pattern axis cannot be zero`));let o=r/n,s=U().circularPattern(e.wrapped,[...i],[...t],o,n).map(e=>W(e));try{return UA(s,{optimisation:`sameFace`,...a,unsafe:!0})}finally{for(let e of s)e[Symbol.dispose]()}}function GP(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(UD(t))return k(P(`PATTERN_ZERO_DIRECTION`,`Grid directionX cannot be zero`));if(UD(n))return k(P(`PATTERN_ZERO_DIRECTION`,`Grid directionY cannot be zero`));let c=U(),l=VD(t),u=VD(n);if(typeof c.gridPattern==`function`)return O(W(c.gridPattern(e.wrapped,[...l],[...u],a,o,r,i)));let d=UP(e,t,r,a,s);if(!d.ok)return d;let f=d.value,p=UP(f,n,i,o,s),m=p.ok&&p.value===f;return f!==e&&!m&&f[Symbol.dispose](),p}function KP(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 qP(e,t){return{...e,children:[...e.children,t]}}function JP(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 YP(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 XP(e,t){if(e.name===t)return e;for(let n of e.children){let e=XP(n,t);if(e)return e}}function ZP(e,t,n=0){t(e,n);for(let r of e.children)ZP(r,t,n+1)}function QP(e){let t=1;for(let n of e.children)t+=QP(n);return t}function $P(e){let t=[];return ZP(e,e=>{e.shape&&t.push(e.shape)}),t}function eF(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function tF(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 nF(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function rF(e){return nF(tF(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function iF(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 aF(e,t){let n=t/2,r=Math.sin(n),i=nF(e);return[Math.cos(n),i[0]*r,i[1]*r,i[2]*r]}function oF(e,t){let n=nF(e),r=nF(t),i=eF(n,r);if(i>=.999999999)return[1,0,0,0];if(i<=-.999999999)return aF(rF(n),Math.PI);let a=tF(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 sF(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 cF=Math.PI/180;function lF(e,t,n){return Math.min(n,Math.max(t,e))}function uF(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function dF(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 fF(e){return uF(dF(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function pF(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:uF(t),min:s,max:c,value:lF(n.value??0,s,c)}}function mF(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:uF(r.direction)},min:a.min,max:a.max,value:a.value,dofs:i}}function hF(e,t,n,r={}){return mF(`revolute`,e,t,n,[pF(`rotation`,n.direction,r,-180,180)])}function gF(e,t,n,r={}){return mF(`prismatic`,e,t,n,[pF(`translation`,n.direction,r,0,100)])}function _F(e,t,n,r={}){return mF(`cylindrical`,e,t,n,[pF(`rotation`,n.direction,r.rotation??{},-180,180),pF(`translation`,n.direction,r.translation??{},0,100)])}function vF(e,t,n,r={}){let i=uF(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?fF(i):uF(n)}else a=fF(i);let o=uF(dF(i,a));return mF(`planar`,e,t,{origin:n.origin,direction:i},[pF(`translation`,a,r.u??{},-100,100),pF(`translation`,o,r.v??{},-100,100),pF(`rotation`,i,r.rotation??{},-180,180)])}function yF(e,t,n,r={}){return mF(`spherical`,e,t,{origin:n,direction:[0,0,1]},[pF(`rotation`,[1,0,0],r.x??{},-180,180),pF(`rotation`,[0,1,0],r.y??{},-180,180),pF(`rotation`,[0,0,1],r.z??{},-180,180)])}function bF(e,t){let n=e.dofs.map((e,n)=>{let r=t[n];return r===void 0?e:{...e,value:lF(r,e.min,e.max)}}),r=n[0];return r?{...e,dofs:n,value:r.value}:{...e,dofs:n}}function xF(e,t){return bF(e,[t])}function SF(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=aF(t.axis,n*cF),i=iF(r,e);return{position:[e[0]-i[0],e[1]-i[1],e[2]-i[2]],rotation:r}}function CF(e,t=e.value){let n=Array.isArray(t)?t:void 0,r=n?void 0:t,i=e.axis.origin,a=TF;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=EF(a,SF(i,o,lF(s,o.min,o.max)))}return a}function wF(e,t){let n=e.joints??[];return{...e,joints:[...n,t]}}var TF={position:[0,0,0],rotation:[1,0,0,0]};function EF(e,t){let n=iF(e.rotation,t.position);return{position:[e.position[0]+n[0],e.position[1]+n[1],e.position[2]+n[2]],rotation:sF(e.rotation,t.rotation)}}function DF(e){let t=[];return ZP(e,e=>{e.joints&&t.push(...e.joints)}),t}function OF(e,t={}){let n=[],r=new Set;ZP(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,TF);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?EF(CF(n,i),n.offset):CF(n,i);a.set(n.child,EF(r,c))}}for(let e of o)a.has(e.child)||a.set(e.child,TF);return a}function kF(e){return DF(e).reduce((e,t)=>e+t.dofs.length,0)}var AF={position:[0,0,0],rotation:[1,0,0,0]};function jF(e,t){let n=iF(e.rotation,t);return[n[0]+e.position[0],n[1]+e.position[1],n[2]+e.position[2]]}function MF(e){return[e[0],-e[1],-e[2],-e[3]]}function NF(e,t){let[n,r,i,a]=sF(t,MF(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 PF(e,t){let n=[];ZP(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 FF(e,t){return e[t]??0}function IF(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]=FF(e,a*n+t);i[a*r+n]=FF(t,a)}for(let e=0;e<n;e++){let t=e;for(let a=e+1;a<n;a++)Math.abs(FF(i,a*r+e))>Math.abs(FF(i,t*r+e))&&(t=a);if(Math.abs(FF(i,t*r+e))<1e-12)return null;if(t!==e)for(let n=e;n<r;n++){let a=FF(i,e*r+n);i[e*r+n]=FF(i,t*r+n),i[t*r+n]=a}let a=FF(i,e*r+e);for(let t=e;t<r;t++)i[e*r+t]=FF(i,e*r+t)/a;for(let t=0;t<n;t++){if(t===e)continue;let n=FF(i,t*r+e);if(n!==0)for(let a=e;a<r;a++)i[t*r+a]=FF(i,t*r+a)-n*FF(i,e*r+a)}}let a=new Float64Array(n);for(let e=0;e<n;e++)a[e]=FF(i,e*r+n);return a}function LF(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 RF(e,t){let n={},r=0;for(let i of e){let e=[];for(let n=0;n<i.count;n++)e.push(FF(t,r++));n[i.child]=e}return n}function zF(e,t,n,r,i){let a=jF(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=NF(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+=FF(e,t)**2;return Math.sqrt(o)}function BF(e,t,n,r,i,a,o,s,c,l){let u=jF(o,s);for(let d=0;d<n;d++){let f=FF(t,d),p=f+c>FF(a,d)&&f-c>=FF(i,d)?-c:c;t[d]=f+p;let m=l(t);t[d]=f;let h=jF(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=NF(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 VF(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+=FF(e,t*n+r)*FF(e,i*n+r);a[t*r+i]=s+(t===i?o:0)}let s=IF(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+=FF(e,a*n+t)*FF(s,a);c[t]=i}return c}function HF(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}=LF(PF(e,t),r.seed),p=u.length,m=n=>OF(e,RF(l,n)).get(t)??AF,h=new Float64Array(c),g=new Float64Array(c*p),_=m(u),v=zF(h,_,n,s,c),y=0;for(;y<i&&p>0&&v>a;y++){BF(g,u,p,c,d,f,_,s,1e-6,m);let e=VF(g,h,p,c,o);if(!e)break;for(let t=0;t<p;t++){let n=FF(u,t)+FF(e,t);u[t]=Math.min(FF(f,t),Math.max(FF(d,t),n))}_=m(u),v=zF(h,_,n,s,c)}return{values:RF(l,u),converged:v<=a,iterations:y,error:v}}function UF(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 WF(e,t,n,r){let i=[];ZP(e,e=>{e.joints&&i.push(...e.joints)});let a=i.map(e=>({child:e.child,a:UF(e,t[e.child]),b:UF(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:OF(e,r)})}return s}var GF=Math.PI/180;function KF(e,t,n,r){let i=e*GF,a=r*GF,o=sF(aF([0,0,1],i),aF([1,0,0],a));return{position:[n*Math.cos(i),n*Math.sin(i),t],rotation:o}}function qF(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=KF(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`?gF(i,a,s,c):hF(i,a,s,c),offset:o}})}var JF=Math.PI/180,YF=180/Math.PI;function XF(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function ZF(e){return String(e===0?0:e)}function QF(e){return`${ZF(e[0])} ${ZF(e[1])} ${ZF(e[2])}`}function $F(e,t={}){let n=t.name??`robot`,r=t.effort??0,i=t.velocity??0,a=t.meshes??{},o=[],s=[];ZP(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="${XF(n)}">`];for(let e of o){let t=a[e];t?c.push(` <link name="${XF(e)}">`,` <visual><geometry><mesh filename="${XF(t)}"/></geometry></visual>`,` </link>`):c.push(` <link name="${XF(e)}"/>`)}for(let e of s){let t=e.type===`revolute`,n=t?e.min*JF:e.min,a=t?e.max*JF:e.max,o=e.type===`prismatic`?[0,0,0]:e.axis.origin;c.push(` <joint name="${XF(`${e.parent}_to_${e.child}`)}" type="${e.type}">`,` <parent link="${XF(e.parent)}"/>`,` <child link="${XF(e.child)}"/>`,` <origin xyz="${QF(o)}" rpy="0 0 0"/>`,` <axis xyz="${QF(e.axis.direction)}"/>`,` <limit lower="${ZF(n)}" upper="${ZF(a)}" effort="${ZF(r)}" velocity="${ZF(i)}"/>`,` </joint>`)}return c.push(`</robot>`,``),O(c.join(`
16
16
  `))}function eI(e,t){return RegExp(`\\b${t}\\s*=\\s*"([^"]*)"`).exec(e)?.[1]}function tI(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 nI(e,t){return iF(sF(sF(aF([0,0,1],t[2]),aF([0,1,0],t[1])),aF([1,0,0],t[0])),e)}function rI(e){let t=/<robot\b([^>]*)>/.exec(e);if(!t)return k(P(M.VALIDATION_FAILED,`importURDF: no <robot> element found`));let n=eI(t[1]??``,`name`)??`robot`,r=[],i=/<link\b([^>]*?)(?:\/>|>)/g;for(let t=i.exec(e);t;t=i.exec(e)){let e=eI(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=eI(e,`type`)??`fixed`;if(r===`fixed`||r===`floating`||r===`planar`)continue;let i=/<parent\b([^>]*?)\/?>/.exec(n),o=/<child\b([^>]*?)\/?>/.exec(n),s=eI(i?.[1]??``,`link`),c=eI(o?.[1]??``,`link`);if(!s||!c)return k(P(M.VALIDATION_FAILED,`importURDF: joint missing parent/child link (${eI(e,`name`)??`unnamed`})`));let l=/<origin\b([^>]*?)\/?>/.exec(n),u=/<axis\b([^>]*?)\/?>/.exec(n),d=/<limit\b([^>]*?)\/?>/.exec(n),f=tI(eI(l?.[1]??``,`xyz`),[0,0,0]),p=tI(eI(l?.[1]??``,`rpy`),[0,0,0]),m=nI(tI(eI(u?.[1]??``,`xyz`),[1,0,0]),p),h=Number(eI(d?.[1]??``,`lower`)??NaN),g=Number(eI(d?.[1]??``,`upper`)??NaN);if(r===`prismatic`){let e=Number.isFinite(h)&&Number.isFinite(g)?{min:h,max:g}:{};a.push(gF(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*YF,max:g*YF};a.push(hF(s,c,{origin:f,direction:m},e))}else return k(P(M.VALIDATION_FAILED,`importURDF: joint '${eI(e,`name`)??`unnamed`}' has unrecognized type '${r}'`))}return O({name:n,links:r,joints:a})}function iI(){return{steps:[],shapes:new Map}}function aI(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 oI(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 sI(e,t){return e.steps.find(e=>e.id===t)}function cI(e,t){return e.shapes.get(t)}function lI(e){return e.steps.length}function uI(e,t){let n=e.steps.findIndex(e=>e.id===t);return n===-1?[]:e.steps.slice(n)}function dI(e,t,n){let r=new Map(e.shapes);return r.set(t,n),{...e,shapes:r}}function fI(){return{operations:new Map}}function pI(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function mI(e,t){let[n,r]=t;return n!==void 0&&r===void 0&&IE(n)?fP(e,n):{...e}}function hI(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=dI(r,t,i));for(let n of e.steps){let e=t.operations.get(n.type);if(!e)return k(F(`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(F(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${n.id}`));i.push(t)}try{let t=e(i,mI(n.parameters,i));r=aI(r,{id:n.id,type:n.type,parameters:n.parameters,inputIds:n.inputIds,outputId:n.outputId},t)}catch(e){return k(F(`REPLAY_STEP_FAILED`,`Step ${n.id} (${n.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(r)}function gI(e,t,n){let r=e.steps.findIndex(e=>e.id===t);if(r===-1)return k(F(`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(F(`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(F(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${r.id}`));o.push(t)}try{let e=i(o,mI(r.parameters,o));a=aI(a,{id:r.id,type:r.type,parameters:r.parameters,inputIds:r.inputIds,outputId:r.outputId},e)}catch(e){return k(F(`REPLAY_STEP_FAILED`,`Step ${r.id} (${r.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(a)}function _I(e,t,n,r){return e.steps.findIndex(e=>e.id===t)===-1?k(F(`MODIFY_STEP_NOT_FOUND`,`Step not found: ${t}`)):gI({steps:e.steps.map(e=>e.id===t?{...e,parameters:n}:e),shapes:e.shapes},t,r)}function vI(e){let t={};for(let[n,r]of e.shapes){let e=Ck(r);if(!e.ok)return k(F(`SERIALIZE_SHAPE_FAILED`,`Failed to serialize shape "${n}": ${e.error.message}`));t[n]=e.value}return O({steps:e.steps,shapes:t})}function yI(e){let t=new Map;for(let[n,r]of Object.entries(e.shapes))try{let e=fO(r);if(!e.ok)return k(F(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e.error.message}`));t.set(n,e.value)}catch(e){return k(F(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e instanceof Error?e.message:String(e)}`))}return O({steps:e.steps,shapes:t})}function bI(e){try{var t=NT();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 qT),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=OP(f.map((e,t)=>_.register(yP(e,f[(t+1)%f.length]))));if(!Ka(y))return y;v.push(_.register(y.value))}return kM(v,{ruled:!0})}catch(e){t.e=e}finally{t.d()}}var xI=1e-9,SI=1e-8,CI=1e-6,wI=([e,t],[n,r],i=CI)=>Math.abs(e-n)<=i&&Math.abs(t-r)<=i,TI=([e,t],[n,r])=>[e+n,t+r],EI=([e,t],[n,r])=>[e-n,t-r],DI=([e,t],n)=>[e*n,t*n],OI=([e,t],[n,r]=[0,0])=>Math.sqrt((e-n)**2+(t-r)**2),kI=([e,t],[n,r]=[0,0])=>(e-n)**2+(t-r)**2;function AI([e,t],[n,r]){return e*r-t*n}var jI=([e,t],[n,r]=[0,0])=>Math.atan2(r*e-t*n,e*n+t*r),MI=([e,t],[n,r]=[0,0])=>Math.atan2(r-t,n-e),NI=(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 PI([e,t]){let n=Math.sqrt(e*e+t*t);return n<1e-12?[0,0]:[e/n,t/n]}var FI=(e,t)=>[Math.cos(t)*e,Math.sin(t)*e],II=([e,t])=>[Math.sqrt(e*e+t*t),Math.atan2(t,e)],LI=([e,t])=>{let n=PI([e,t]);return n[0]===0&&n[1]===0&&i(`normalize2d`,`Cannot normalize zero-length vector`),n};function RI(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(To(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found ${r===0?0:`2+`} element(s)`))}function zI(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 cD(t);case`face`:return lD(t);case`wire`:return uD(t);case`vertex`:return dD(t)}}let s=e=>{let n=o(e);return t.length===0?n.slice():n.filter(a)},c=()=>zI(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=wk(n),r=t.get(e);r?r.push(n):t.set(e,[n])}return i(e=>{let n=t.get(wk(e));return!!n&&n.some(t=>Ek(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=>RI(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 BI={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function VI(e){return typeof e==`string`?BI[e]??[0,0,1]:e}function HI(e,t,n){let r=U(),i=r.makeVertex(t[0],t[1],t[2]);return t=>{let a=r.distance(i,t.wrapped).value;return Math.abs(a-e)<n}}function UI(e,t){let n=VD(VI(e));return e=>{let r=U(),[i,a]=r.curveParameters(e.wrapped),o=(i+a)/2,{tangent:s}=r.curveTangent(e.wrapped,o),c=VD(s),l=Math.acos(Math.min(1,Math.abs(ID(c,n))));return Math.abs(l-KE*t)<1e-6}}function WI(e){return zI(`edge`,e,WI,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(UI(e,t)),ofLength:(e,t=.001)=>n(n=>Math.abs(Pk(n)-e)<t),ofCurveType:e=>n(t=>kk(t)===e),parallelTo:(t=`Z`)=>WI(e).inDirection(t,0),atDistance:(e,t=[0,0,0])=>n(HI(e,t,1e-6))}))}function GI(){return WI([])}function KI(e,t){let n=VD(VI(e));return e=>{let r=SO(e),i=Math.acos(Math.min(1,Math.abs(ID(VD(r),n))));return Math.abs(i-KE*t)<1e-6}}function qI(e){return zI(`face`,e,qI,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(KI(e,t)),parallelTo:(t=`Z`)=>qI(e).inDirection(t,0),ofSurfaceType:e=>n(t=>{let n=mO(t);return Ka(n)&&n.value===e}),ofArea:(e,t=.001)=>n(n=>{let r=BM(n);return Ka(r)&&Math.abs(r.value-e)<t}),atDistance:(e,t=[0,0,0])=>n(HI(e,t,1e-6))}))}function JI(){return qI([])}function YI(e){return zI(`wire`,e,YI,(e,t)=>({isClosed:()=>t(e=>Ik(e)),isOpen:()=>t(e=>!Ik(e)),ofEdgeCount:e=>t(t=>cD(t).length===e)}))}function XI(){return YI([])}function ZI(e,t){return typeof e==`object`&&`_topoKind`in e?e.findUnique(t):typeof e!=`function`&&ME(e)?O(e):e(JI()).findUnique(t)}function QI(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`}function $I(e,t){let n=10**t,r=t<0?e:.01/n+e;return Math.round(r*n)/n}function eL(e){return Math.round(e*100)/100}function tL(e){return Math.round(e*1e5)/1e5}var nL=([e,t])=>`(${eL(e)},${eL(t)})`,rL=(e,t=1e-9)=>{let n=e;return Math.abs(e)<t&&(n=0),n.toFixed(-Math.log10(t))},iL=(e,t=1e-9)=>Array.from(new Map(e.map(([e,n])=>[`[${rL(e,t)},${rL(n,t)}]`,[e,n]])).values()),aL=class{_wrapped;_deleted=!1;constructor(e){this._wrapped=e??xT().createBoundingBox2d(),YT(this,this._wrapped)}get wrapped(){if(this._deleted)throw Error(`This object has been deleted`);return this._wrapped}delete(){this._deleted||(this._deleted=!0,XT(this._wrapped),typeof this._wrapped.delete==`function`&&this._wrapped.delete())}[Symbol.dispose](){this.delete()}get repr(){let[e,t]=this.bounds;return`${nL(e)} - ${nL(t)}`}get bounds(){let{xMin:e,yMin:t,xMax:n,yMax:r}=xT().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){xT().mergeBBox2d(this.wrapped,e.wrapped)}isOut(e){return xT().isBBox2dOut(this.wrapped,e.wrapped)}containsPoint(e){return!xT().isBBox2dOutPoint(this.wrapped,e[0],e[1])}};function oL(e){return new sL(U().deserializeCurve2d(e))}var sL=class e{_wrapped;_deleted=!1;_boundingBox;_firstPoint=null;_lastPoint=null;_firstParameter=null;_lastParameter=null;constructor(e){this._wrapped=U().wrapCurve2dHandle(e),this._boundingBox=null,typeof this._wrapped.delete==`function`&&YT(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`&&(XT(this._wrapped),this._wrapped.delete()))}[Symbol.dispose](){this.delete()}get boundingBox(){if(this._boundingBox)return this._boundingBox;let e=U(),t=e.createBoundingBox2d();return e.addCurveToBBox2d(t,this.wrapped,1e-6),this._boundingBox=new aL(t),this._boundingBox}get repr(){return`${this.geomType} ${nL(this.firstPoint)} - ${nL(this.lastPoint)}`}serialize(){return U().serializeCurve2d(this.wrapped)}value(e){return U().evaluateCurve2d(this.wrapped,e)}get firstPoint(){return this._firstPoint===null&&(this._firstPoint=this.value(this.firstParameter)),this._firstPoint}get lastPoint(){return this._lastPoint===null&&(this._lastPoint=this.value(this.lastParameter)),this._lastPoint}get firstParameter(){return this._firstParameter===null&&(this._firstParameter=U().getCurve2dBounds(this.wrapped).first),this._firstParameter}get lastParameter(){return this._lastParameter===null&&(this._lastParameter=U().getCurve2dBounds(this.wrapped).last),this._lastParameter}get geomType(){return U().getCurve2dType(this.wrapped)}clone(){let t=new e(U().copyCurve2d(this.wrapped));return t._firstPoint=this._firstPoint,t._lastPoint=this._lastPoint,t._firstParameter=this._firstParameter,t._lastParameter=this._lastParameter,t}reverse(){U().reverseCurve2d(this.wrapped);let e=this._firstPoint;this._firstPoint=this._lastPoint,this._lastPoint=e;let t=this._firstParameter;this._firstParameter=this._lastParameter,this._lastParameter=t}distanceFromPoint(e){let t=U().projectPointOnCurve2d(this.wrapped,e[0],e[1]),n=t?t.distance:1/0;return Math.min(n,OI(e,this.firstPoint),OI(e,this.lastPoint))}distanceFromCurve(e){let t;try{t=U().distanceBetweenCurves2d(this.wrapped,e.wrapped,this.firstParameter,this.lastParameter,e.firstParameter,e.lastParameter)}catch{t=1/0}return Math.min(t,this.distanceFromPoint(e.firstPoint),this.distanceFromPoint(e.lastPoint),e.distanceFromPoint(this.firstPoint),e.distanceFromPoint(this.lastPoint))}distanceFrom(e){return QI(e)?this.distanceFromPoint(e):this.distanceFromCurve(e)}isOnCurve(e){return this.distanceFromPoint(e)<1e-9}parameter(e,t=1e-9){let n,r,i=!1;try{let t=U().projectPointOnCurve2d(this.wrapped,e[0],e[1]);t?(n=t.distance,r=t.param):i=!0}catch{i=!0}return i?wI(e,this.firstPoint,t)?O(this.firstParameter):wI(e,this.lastPoint,t)?O(this.lastParameter):k(F(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n===void 0||r===void 0?k(F(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n>t?k(F(`POINT_NOT_ON_CURVE`,`Point ${nL(e)} not on curve ${this.repr}, ${n.toFixed(9)}`)):O(r)}tangentAt(e){let t;if(Array.isArray(e))t=j(this.parameter(e));else{let n=U().getCurve2dBounds(this.wrapped);t=(n.last-n.first)*e+n.first}return U().evaluateCurve2dD1(this.wrapped,t).tangent}splitAt(n,r=1e-9){let i=n.map(e=>QI(e)?j(this.parameter(e,r)):e);i=Array.from(new Map(i.map(e=>[$I(e,-Math.log10(r)),e])).values()).sort((e,t)=>e-t);let a=this.firstParameter,o=this.lastParameter;return a>o&&i.reverse(),Math.abs(t(i,0)-a)<r*100&&(i=i.slice(1)),!i.length||(Math.abs(t(i,i.length-1)-o)<r*100&&(i=i.slice(0,-1)),!i.length)?[this]:U().splitCurve2d(this.wrapped,i).map(t=>new e(t))}},cL=(e,t=1e-4,n=`C0`,r=200)=>new sL(xT().approximateCurve2dAsBSpline(e.wrapped,t,n,r)),lL=e=>(e.geomType!==`BSPLINE_CURVE`&&i(`BSplineToBezier`,`You can only convert a Bspline`),xT().decomposeBSpline2dToBeziers(e.wrapped).map(e=>new sL(e)));function uL(e,t={tolerance:1e-4,continuity:`C0`,maxSegments:300}){let n=xT();return e.flatMap(e=>{let r=e.geomType;if(r===`ELLIPSE`||r===`CIRCLE`&&wI(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 uL(lL(r===`BSPLINE_CURVE`?e:cL(e,t.tolerance,t.continuity,t.maxSegments)),t)})}var dL=(e,t)=>{let n=new sL(U().makeLine2d(e[0],e[1],t[0],t[1]));return wI(n.firstPoint,e)||n.reverse(),n},fL=(e,t,n)=>{let r=new sL(U().makeArc2dThreePoints(e[0],e[1],t[0],t[1],n[0],n[1]));if(!wI(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new sL(e)}return r},pL=(e,t,n)=>{let r=new sL(U().makeArc2dTangent(e[0],e[1],t[0],t[1],n[0],n[1]));if(!wI(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new sL(e)}return r},mL=(e,t=[0,0])=>new sL(U().makeCircle2d(t[0],t[1],e,!0)),hL=(e,t,n=[1,0],r=[0,0],i=!0)=>new sL(U().makeEllipse2d(r[0],r[1],e,t,n[0],n[1],i)),gL=(e,t,n,r,i=[0,0],a,o=!0)=>new sL(U().makeEllipseArc2d(i[0],i[1],e,t,n,r,a[0],a[1],o)),_L=(e,t,n)=>{let r=[[e[0],e[1]],...t.map(e=>[e[0],e[1]]),[n[0],n[1]]];return new sL(U().makeBezier2d(r))};function vL(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 sL(U().makeBSpline2d(a,{tolerance:t,smoothing:n,degMax:r,degMin:i,continuity:`C2`})))}catch(e){return k(F(`BSPLINE_2D_FAILED`,`B-spline approximation failed`,e))}}var yL=(e,t,n,r=!1)=>{let i=DI(TI(e,t),.5),a=OI(n,e)*(r?-1:1);return fL(e,TI(DI(LI(EI(i,n)),a),n),t)},bL=(e,n)=>{let r=xT(),a=e.geomType,[o,s]=n,c=`${tL(o)} ${tL(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 ${eL(e)} ${eL(r)} ${c}`}if(a===3){let[e,r]=t(n,1),[i,a]=t(n,2);return`C ${eL(e)} ${eL(r)} ${eL(i)} ${eL(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)*qE,d=u===360?`${tL(o)} ${tL(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)*qE,p=f===360?`${tL(o)} ${tL(s+1e-4)}`:c,m=180-l*qE;return`A ${tL(n)} ${tL(a)} ${tL(m)} ${Math.abs(f)>180?`1`:`0`} ${u?`1`:`0`} ${p}`}i(`adaptedCurveToPathElem`,`Unsupported curve type: ${a}`)},xL=e=>{let t=U(),n=t.createBoundingBox2d();return e.forEach(e=>{t.addCurveToBBox2d(n,e.wrapped,1e-6)}),new aL(n)};function SL(e,t){let n=U();return e.map(e=>SE(n.liftCurve2dToPlane(e.wrapped,[...t.origin],[...t.zDir],[...t.xDir])))}var CL=(e,t)=>{let n=U();return e.map(e=>SE(n.buildEdgeOnSurface(e.wrapped,t)))},wL=(e,t)=>{let n=U();return e.map(e=>t?new sL(n.transformCurve2dGeneral(e.wrapped,t)):e.clone())},TL=(e,t,n=[0,0])=>U().createAffinityGTrsf2d(n[0],n[1],-t[1],t[0],e),EL=e=>U().createTranslationGTrsf2d(e[0],e[1]),DL=(e,t=[0,0],n=`center`)=>n===`center`?U().createMirrorGTrsf2d(e[0],e[1],`point`):U().createMirrorGTrsf2d(0,0,`axis`,t[0],t[1],e[0],e[1]),OL=(e,t=[0,0])=>U().createRotationGTrsf2d(e,t[0],t[1]),kL=(e,t=[0,0])=>U().createScaleGTrsf2d(e,t[0],t[1]);function AL(e,t,n=`original`){let r=U(),i=r.extractSurfaceFromFace(t.wrapped),a=vO(t),o=null;if(n===`original`&&hO(t)!==`PLANE`){if(hO(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=TL(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=CL(wL(e,o),i);return o&&o.delete(),O(s)}function jL(e,t){let n=U(),r=new sL(n.extractCurve2dFromEdge(e.wrapped,t.wrapped));return zk(e)===`backward`&&n.reverseCurve2d(r.wrapped),r}var ML=(e,t=1)=>`${e.bounds[0][0]-t} ${-e.bounds[1][1]-t} ${e.width+2*t} ${e.height+2*t}`,NL=(e,t,n=1)=>`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${ML(t,n)}" fill="none" stroke="black" stroke-width="0.6%" vector-effect="non-scaling-stroke">
17
17
  ${e}
18
18
  </svg>`;function PL(e){let t=e.map(e=>e.wrapped);return CE(U().makeWire(t))}var FL=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(`
@@ -4205,4 +4205,4 @@ No matching component was found for:
4205
4205
 
4206
4206
  gl_FragColor = vec4(lineColor, alpha);
4207
4207
  }
4208
- `;function ib({cellSize:e=10,lineColor:t=`#888898`,lineOpacity:n=.1,fadeStart:r=50,fadeEnd:i=200}){let a=(0,v.useRef)(null),o=i*2.5;return(0,v.useEffect)(()=>()=>{a.current?.dispose()},[]),(0,$.jsxs)(`mesh`,{rotation:[-Math.PI/2,0,0],position:[0,-.01,0],children:[(0,$.jsx)(`planeGeometry`,{args:[o,o]}),(0,$.jsx)(`shaderMaterial`,{ref:a,vertexShader:nb,fragmentShader:rb,uniforms:{cellSize:{value:e},lineColor:{value:new q(t)},lineOpacity:{value:n},fadeStart:{value:r},fadeEnd:{value:i}},transparent:!0,depthWrite:!1,side:2,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1})]})}function ab(){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`hemisphereLight`,{args:[`#ffffff`,`#1a1a2e`,.65]}),(0,$.jsx)(`directionalLight`,{position:[-50,60,80],intensity:.85,color:`#fff8f0`}),(0,$.jsx)(`directionalLight`,{position:[40,-40,30],intensity:.15,color:`#e0e8ff`})]})}function ob({autoRotate:e=!1,target:t,gridVisible:n=!0,gridProps:r,controlsProps:i,controlsRef:a,onControlsStart:o}){let s={...a?{ref:a}:{},...t?{target:t}:{},...o?{onStart:o}:{}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ab,{}),(0,$.jsx)(tb,{}),(0,$.jsx)(Ay,{makeDefault:!0,autoRotate:e,autoRotateSpeed:1.5,...s,...i}),n&&(0,$.jsx)(ib,{...r})]})}var sb={iso:new G(.6,.5,.6),front:new G(0,.3,1),top:new G(0,1,-.01),right:new G(1,.3,0)};function cb({data:e,view:t,fitSignal:n,projection:r,onFirstFrame:i}){let a=k_(e=>e.camera),o=k_(e=>e.invalidate),s=(0,v.useRef)(!1),c=(0,v.useRef)(i);c.current=i;let{center:l,radius:u}=(0,v.useMemo)(()=>{let t=jy(e);t.computeBoundingSphere();let n=t.boundingSphere??new zi(new G,1),r={center:n.center.clone(),radius:n.radius||1};return t.dispose(),r},[e]);return(0,v.useEffect)(()=>{let e=sb[t].clone().normalize();a.position.copy(l).addScaledVector(e,u*3),a.near=u/100,a.far=u*100;let n=a;if(n.isOrthographicCamera){let e=Math.min(n.right-n.left,n.top-n.bottom);e>0&&u>0&&(n.zoom=e/(u*2.4))}a.lookAt(l),a.updateProjectionMatrix(),o(),s.current||(s.current=!0,c.current?.())},[a,o,l,u,t,n,r]),null}function lb(){let e=k_(e=>e.camera);return(0,$.jsx)(ky,{makeDefault:!0,position:(0,v.useRef)([e.position.x,e.position.y,e.position.z]).current,zoom:20,near:.1,far:2e3})}function ub(){let e=k_(e=>e.gl);return(0,v.useEffect)(()=>(e.localClippingEnabled=!0,()=>{e.localClippingEnabled=!1}),[e]),null}function db({data:e,view:t=`iso`,fitSignal:n,autoRotate:r=!1,gridVisible:i=!0,projection:a=`perspective`,onFirstFrame:o,onError:s,errorFallback:c,children:l}){return(0,$.jsx)(By,{onError:s,fallback:c,children:(0,$.jsxs)(Qv,{frameloop:r?`always`:`demand`,gl:{preserveDrawingBuffer:!0},children:[(0,$.jsx)(ub,{}),a===`orthographic`&&(0,$.jsx)(lb,{}),(0,$.jsx)(ob,{autoRotate:r,gridVisible:i}),(0,$.jsx)(cb,{data:e,view:t,fitSignal:n,projection:a,onFirstFrame:o}),l]})})}var fb=[`iso`,`front`,`top`,`right`],pb={solid:`Solid`,wireframe:`Wire`,xray:`X-ray`},mb={iso:`Iso`,front:`Front`,top:`Top`,right:`Right`};function hb({viewMode:e,onViewModeChange:t,showEdges:n,onToggleEdges:r,showGrid:i,onToggleGrid:a,autoRotate:o,onToggleAutoRotate:s,projection:c,onToggleProjection:l,activeView:u,onView:d,onFit:f,onScreenshot:p,touch:m=!1,className:h}){return(0,$.jsxs)(`div`,{className:h,style:h?void 0:{...vb,gap:m?8:6},children:[(f||p)&&(0,$.jsxs)(gb,{touch:m,children:[f&&(0,$.jsx)(_b,{label:`Fit`,onClick:f,touch:m}),p&&(0,$.jsx)(_b,{label:`Snap`,onClick:p,touch:m})]}),e&&t&&(0,$.jsx)(gb,{touch:m,children:Object.keys(pb).map(n=>(0,$.jsx)(_b,{label:pb[n],active:e===n,touch:m,onClick:()=>{t(n)}},n))}),(r||a||s||l)&&(0,$.jsxs)(gb,{touch:m,children:[r&&(0,$.jsx)(_b,{label:`Edges`,active:n,onClick:r,touch:m}),a&&(0,$.jsx)(_b,{label:`Grid`,active:i,onClick:a,touch:m}),s&&(0,$.jsx)(_b,{label:`Spin`,active:o,onClick:s,touch:m}),l&&(0,$.jsx)(_b,{label:c===`orthographic`?`Ortho`:`Persp`,active:c===`orthographic`,touch:m,onClick:l})]}),d&&(0,$.jsx)(gb,{touch:m,children:fb.map(e=>(0,$.jsx)(_b,{label:mb[e],active:u===e,touch:m,onClick:()=>{d(e)}},e))})]})}function gb({children:e,touch:t}){return(0,$.jsx)(`div`,{style:t?Sb:yb,children:e})}function _b({label:e,active:t,onClick:n,touch:r}){return(0,$.jsx)(`button`,{type:`button`,onClick:n,"aria-pressed":t,style:{...r?Cb:bb,...t?xb:null},children:e})}var vb={position:`absolute`,top:12,right:12,zIndex:10,display:`flex`,flexDirection:`column`,gap:6,pointerEvents:`none`,fontFamily:`ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif`},yb={display:`flex`,flexDirection:`column`,gap:4,padding:4,borderRadius:8,background:`rgba(26, 29, 33, 0.7)`,backdropFilter:`blur(6px)`,border:`1px solid rgba(255, 255, 255, 0.08)`},bb={cursor:`pointer`,pointerEvents:`auto`,padding:`4px 10px`,borderRadius:5,fontSize:12,fontWeight:500,lineHeight:1.2,color:`#9aa3ad`,background:`rgba(255, 255, 255, 0.04)`,border:`1px solid transparent`,transition:`color 120ms, background 120ms`},xb={color:`#6ee7d7`,background:`rgba(45, 212, 191, 0.16)`,borderColor:`rgba(45, 212, 191, 0.3)`},Sb={...yb,gap:6,padding:6},Cb={...bb,padding:`9px 14px`,fontSize:13,borderRadius:6};function wb({dims:e,volume:t,area:n,triangles:r,valid:i,unit:a,className:o}){let s=a?` ${a}`:``,c=[];return e&&c.push((0,$.jsx)(Tb,{label:`Size`,value:`${Eb(e[0])} × ${Eb(e[1])} × ${Eb(e[2])}${s}`},`size`)),t!==void 0&&c.push((0,$.jsx)(Tb,{label:`Volume`,value:`${Eb(t)}${a?` ${a}³`:``}`},`vol`)),n!==void 0&&c.push((0,$.jsx)(Tb,{label:`Area`,value:`${Eb(n)}${a?` ${a}²`:``}`},`area`)),r!==void 0&&c.push((0,$.jsx)(Tb,{label:`Triangles`,value:r.toLocaleString()},`tris`)),i!==void 0&&c.push((0,$.jsx)(Tb,{label:`Validity`,value:i?`valid`:`invalid`,valueColor:i?`#6ee7d7`:`#f0a0a0`},`valid`)),c.length===0?null:(0,$.jsx)(`div`,{className:o,style:o?void 0:Db,children:c})}function Tb({label:e,value:t,valueColor:n}){return(0,$.jsxs)(`div`,{style:Ob,children:[(0,$.jsx)(`span`,{style:kb,children:e}),(0,$.jsx)(`span`,{style:{...Ab,...n?{color:n}:null},children:t})]})}function Eb(e){return Number.isFinite(e)?Number.isInteger(e)?e.toLocaleString():Number(e.toFixed(2)).toLocaleString():`—`}var Db={position:`absolute`,left:12,bottom:12,zIndex:10,display:`flex`,flexDirection:`column`,gap:2,padding:`8px 10px`,borderRadius:8,minWidth:150,background:`rgba(26, 29, 33, 0.7)`,backdropFilter:`blur(6px)`,border:`1px solid rgba(255, 255, 255, 0.08)`,fontFamily:`ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif`},Ob={display:`flex`,justifyContent:`space-between`,gap:16,fontSize:12,lineHeight:1.5},kb={color:`#7b8591`},Ab={color:`#c8cdd3`,fontVariantNumeric:`tabular-nums`},jb={PLANE:`Planar`,CYLINDER:`Cylindrical`,CONE:`Conical`,SPHERE:`Spherical`,TORUS:`Toroidal`,BEZIER_SURFACE:`Bézier`,BSPLINE_SURFACE:`B-spline`,REVOLUTION_SURFACE:`Revolved`,EXTRUSION_SURFACE:`Extruded`,OFFSET_SURFACE:`Offset`,OTHER_SURFACE:`Surface`};function Mb(e){return jb[e]??`Surface`}function Nb(e){return Number.isFinite(e)?Number.isInteger(e)?e.toLocaleString():Number(e.toFixed(2)).toLocaleString():`—`}function Pb({face:e,onClear:t,unit:n,className:r}){if(!e)return null;let[i,a,o]=e.normal;return(0,$.jsxs)(`div`,{className:r,style:r?void 0:Ib,children:[(0,$.jsxs)(`div`,{style:Lb,children:[(0,$.jsxs)(`span`,{style:Rb,children:[Mb(e.surfaceType),` face`]}),t&&(0,$.jsx)(`button`,{type:`button`,onClick:t,"aria-label":`Clear selection`,style:zb,children:`✕`})]}),(0,$.jsx)(Fb,{label:`Area`,value:`${Nb(e.area)}${n?` ${n}²`:``}`}),(0,$.jsx)(Fb,{label:`Normal`,value:`${Nb(i)}, ${Nb(a)}, ${Nb(o)}`})]})}function Fb({label:e,value:t}){return(0,$.jsxs)(`div`,{style:Bb,children:[(0,$.jsx)(`span`,{style:Vb,children:e}),(0,$.jsx)(`span`,{style:Hb,children:t})]})}var Ib={position:`absolute`,left:12,top:12,zIndex:10,display:`flex`,flexDirection:`column`,gap:2,padding:`8px 10px`,borderRadius:8,minWidth:170,background:`rgba(26, 29, 33, 0.7)`,backdropFilter:`blur(6px)`,border:`1px solid rgba(74, 206, 204, 0.3)`,fontFamily:`ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif`},Lb={display:`flex`,justifyContent:`space-between`,alignItems:`center`,gap:12,marginBottom:2},Rb={color:`#6ee7d7`,fontSize:12,fontWeight:600},zb={cursor:`pointer`,border:`none`,background:`transparent`,color:`#7b8591`,fontSize:12,lineHeight:1,padding:0},Bb={display:`flex`,justifyContent:`space-between`,gap:16,fontSize:12,lineHeight:1.5},Vb={color:`#7b8591`},Hb={color:`#c8cdd3`,fontVariantNumeric:`tabular-nums`},Ub=[`x`,`y`,`z`];function Wb({enabled:e,onToggle:t,axis:n,onAxisChange:r,position:i,min:a,max:o,onPositionChange:s,flip:c,onToggleFlip:l,className:u}){return(0,$.jsxs)(`div`,{className:u,style:u?void 0:Kb,children:[(0,$.jsx)(Gb,{label:`Section`,active:e,onClick:t}),e&&(0,$.jsxs)($.Fragment,{children:[Ub.map(e=>(0,$.jsx)(Gb,{label:e.toUpperCase(),active:n===e,onClick:()=>{r(e)}},e)),(0,$.jsx)(`input`,{type:`range`,min:a,max:o,step:(o-a)/200||.01,value:i,disabled:a===o,onChange:e=>{s(Number(e.target.value))},"aria-label":`Section position`,style:{...Yb,...a===o?{opacity:.4}:null}}),(0,$.jsx)(Gb,{label:`Flip`,active:c,onClick:l})]})]})}function Gb({label:e,active:t,onClick:n}){return(0,$.jsx)(`button`,{type:`button`,onClick:n,"aria-pressed":t,style:{...qb,...t?Jb:null},children:e})}var Kb={position:`absolute`,bottom:12,left:`50%`,transform:`translateX(-50%)`,zIndex:10,display:`flex`,alignItems:`center`,gap:4,padding:4,borderRadius:8,background:`rgba(26, 29, 33, 0.7)`,backdropFilter:`blur(6px)`,border:`1px solid rgba(255, 255, 255, 0.08)`,fontFamily:`ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif`},qb={cursor:`pointer`,padding:`4px 10px`,borderRadius:5,fontSize:12,fontWeight:500,lineHeight:1.2,color:`#9aa3ad`,background:`rgba(255, 255, 255, 0.04)`,border:`1px solid transparent`},Jb={color:`#6ee7d7`,background:`rgba(45, 212, 191, 0.16)`,borderColor:`rgba(45, 212, 191, 0.3)`},Yb={width:160,accentColor:`#4ACECC`,margin:`0 4px`};function Xb(e){let t=new URLSearchParams(e),n=t.get(`file`);return n?{dir:t.get(`dir`),file:n}:null}function Zb(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function Qb({inspect:e=!1}={}){let[t,n]=(0,v.useState)({status:`idle`});return(0,v.useEffect)(()=>{let t=Xb(window.location.search);if(!t){n({status:`error`,error:`missing ?file= parameter`});return}if(!t.dir){n({status:`error`,error:`missing ?dir= parameter`});return}n({status:`loading`});let r=new Worker(new URL(``+new URL(`kernelWorker-hsU6yKs9.js`,import.meta.url).href,``+import.meta.url),{type:`module`}),i=!1;r.addEventListener(`message`,e=>{i||(e.data.type===`loaded`?n({status:`ready`,data:e.data.meshData,measurements:e.data.measurements}):n({status:`error`,error:e.data.error}))});let a=`/__model/${t.file.split(`/`).map(encodeURIComponent).join(`/`)}?dir=${encodeURIComponent(t.dir)}`;return fetch(a).then(e=>{if(!e.ok)throw Error(`fetch ${t.file}: ${e.status}`);return e.arrayBuffer()}).then(n=>{let i={type:`load`,bytes:n,ext:Zb(t.file),inspect:e};r.postMessage(i,[n])}).catch(e=>{i||n({status:`error`,error:e instanceof Error?e.message:String(e)})}),()=>{i=!0,r.terminate()}},[e]),t}var $b=[`iso`,`front`,`top`,`right`],ex=new Set;function tx(e){return $b.includes(e)}function nx(e){return ex.add(e),()=>ex.delete(e)}function rx(e){for(let t of ex)t(e)}function ix(){globalThis.__ready=!0}function ax(){let e=globalThis;e.__ready=!1,e.__renderView=e=>{tx(e)&&rx({view:e})},e.__setScene=e=>{e&&tx(e.view)&&rx(e)}}function ox({marks:e}){return(0,$.jsx)($.Fragment,{children:e.map((e,t)=>(0,$.jsx)(my,{position:[e.pos[0],e.pos[1],e.pos[2]],center:!0,children:(0,$.jsx)(`div`,{style:{background:`#ffcc00`,color:`#000`,font:`700 13px monospace`,padding:`1px 5px`,borderRadius:4,border:`1px solid #000`,whiteSpace:`nowrap`,pointerEvents:`none`},children:e.label})},`${e.label}-${t}`))})}var sx=new URLSearchParams(window.location.search),cx=sx.get(`ui`)!==`0`,lx=sx.get(`dims`)===`1`;function ux(){let e=document.querySelector(`canvas`);if(!e)return;let t=e.toDataURL(`image/png`),n=document.createElement(`a`);n.href=t,n.download=`brepjs-view.png`,n.click()}function dx(){let e=Qb({inspect:cx}),[t,n]=(0,v.useState)(`iso`),[r,i]=(0,v.useState)(`solid`),[a,o]=(0,v.useState)(!0),[s,c]=(0,v.useState)(!0),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(`perspective`),[p,m]=(0,v.useState)(0),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(null),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(`x`),[w,T]=(0,v.useState)(0),[E,D]=(0,v.useState)(!1),[O,k]=(0,v.useState)([]),A=(0,v.useCallback)(()=>{m(e=>e+1)},[]),ee=(0,v.useCallback)(e=>{g(e)},[]),j=(0,v.useCallback)(e=>{y(e?e.faceId:null)},[]),M=(0,v.useMemo)(()=>e.status===`ready`?My(e.data):null,[e]);(0,v.useEffect)(()=>nx(e=>{if(n(e.view),i(e.viewMode??`solid`),e.section&&M){let t=e.section.axis===`x`?0:e.section.axis===`y`?1:2;C(e.section.axis),T(M.min[t]+e.section.frac*(M.max[t]-M.min[t])),x(!0)}else x(!1);k(e.marks??[])}),[M]);let te=S===`x`?0:S===`y`?1:2,N=M?M.min[te]:0,P=M?M.max[te]:1,F=(0,v.useCallback)(e=>{if(!M)return 0;let t=e===`x`?0:e===`y`?1:2;return(M.min[t]+M.max[t])/2},[M]),ne=(0,v.useCallback)(()=>{x(e=>(e||T(F(S)),!e))},[F,S]),re=(0,v.useCallback)(e=>{C(e),T(F(e))},[F]),ie=(0,v.useMemo)(()=>b&&M?[Py(S,w,E)]:void 0,[b,M,S,w,E]);return e.status===`error`?(0,$.jsxs)(`div`,{style:{color:`#e88`,padding:16,fontFamily:`monospace`},children:[`error: `,e.error]}):e.status===`ready`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(db,{data:e.data,view:t,fitSignal:p,autoRotate:l,gridVisible:s,projection:d,onFirstFrame:ix,children:[(0,$.jsx)(zy,{data:e.data,viewMode:r,...ie?{clippingPlanes:ie}:{},...cx?{onFacePick:ee,onFaceHover:j}:{}}),a&&r!==`wireframe`&&e.data.edges.length>0&&(0,$.jsx)(Uy,{edges:e.data.edges,...ie?{clippingPlanes:ie}:{}}),cx&&(0,$.jsx)(Zy,{data:e.data,selectedFaceIds:h?[h.faceId]:[],hoverFaceId:_}),O.length>0&&(0,$.jsx)(ox,{marks:O})]}),cx&&(0,$.jsx)(Pb,{face:h,onClear:()=>{g(null)}}),cx&&(0,$.jsx)(Wb,{enabled:b,onToggle:ne,axis:S,onAxisChange:re,position:w,min:N,max:P,onPositionChange:T,flip:E,onToggleFlip:()=>{D(e=>!e)}}),cx&&(0,$.jsx)(wb,{dims:Ny(e.data),volume:e.measurements.volume,area:e.measurements.area,triangles:e.data.index.length/3,valid:e.measurements.valid}),!cx&&lx&&(0,$.jsx)(wb,{dims:Ny(e.data)}),cx&&(0,$.jsx)(hb,{viewMode:r,onViewModeChange:i,showEdges:a,onToggleEdges:()=>{o(e=>!e)},showGrid:s,onToggleGrid:()=>{c(e=>!e)},autoRotate:l,onToggleAutoRotate:()=>{u(e=>!e)},projection:d,onToggleProjection:()=>{f(e=>e===`perspective`?`orthographic`:`perspective`)},activeView:t,onView:n,onFit:A,onScreenshot:ux})]}):(0,$.jsx)(`div`,{style:{color:`#9aa`,padding:16,fontFamily:`monospace`},children:`loading model…`})}ax();var fx=document.getElementById(`root`);fx&&(0,y.createRoot)(fx).render((0,$.jsx)(v.StrictMode,{children:(0,$.jsx)(dx,{})}));
4208
+ `;function ib({cellSize:e=10,lineColor:t=`#888898`,lineOpacity:n=.1,fadeStart:r=50,fadeEnd:i=200}){let a=(0,v.useRef)(null),o=i*2.5;return(0,v.useEffect)(()=>()=>{a.current?.dispose()},[]),(0,$.jsxs)(`mesh`,{rotation:[-Math.PI/2,0,0],position:[0,-.01,0],children:[(0,$.jsx)(`planeGeometry`,{args:[o,o]}),(0,$.jsx)(`shaderMaterial`,{ref:a,vertexShader:nb,fragmentShader:rb,uniforms:{cellSize:{value:e},lineColor:{value:new q(t)},lineOpacity:{value:n},fadeStart:{value:r},fadeEnd:{value:i}},transparent:!0,depthWrite:!1,side:2,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1})]})}function ab(){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`hemisphereLight`,{args:[`#ffffff`,`#1a1a2e`,.65]}),(0,$.jsx)(`directionalLight`,{position:[-50,60,80],intensity:.85,color:`#fff8f0`}),(0,$.jsx)(`directionalLight`,{position:[40,-40,30],intensity:.15,color:`#e0e8ff`})]})}function ob({autoRotate:e=!1,target:t,gridVisible:n=!0,gridProps:r,controlsProps:i,controlsRef:a,onControlsStart:o}){let s={...a?{ref:a}:{},...t?{target:t}:{},...o?{onStart:o}:{}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ab,{}),(0,$.jsx)(tb,{}),(0,$.jsx)(Ay,{makeDefault:!0,autoRotate:e,autoRotateSpeed:1.5,...s,...i}),n&&(0,$.jsx)(ib,{...r})]})}var sb={iso:new G(.6,.5,.6),front:new G(0,.3,1),top:new G(0,1,-.01),right:new G(1,.3,0)};function cb({data:e,view:t,fitSignal:n,projection:r,onFirstFrame:i}){let a=k_(e=>e.camera),o=k_(e=>e.invalidate),s=(0,v.useRef)(!1),c=(0,v.useRef)(i);c.current=i;let{center:l,radius:u}=(0,v.useMemo)(()=>{let t=jy(e);t.computeBoundingSphere();let n=t.boundingSphere??new zi(new G,1),r={center:n.center.clone(),radius:n.radius||1};return t.dispose(),r},[e]);return(0,v.useEffect)(()=>{let e=sb[t].clone().normalize();a.position.copy(l).addScaledVector(e,u*3),a.near=u/100,a.far=u*100;let n=a;if(n.isOrthographicCamera){let e=Math.min(n.right-n.left,n.top-n.bottom);e>0&&u>0&&(n.zoom=e/(u*2.4))}a.lookAt(l),a.updateProjectionMatrix(),o(),s.current||(s.current=!0,c.current?.())},[a,o,l,u,t,n,r]),null}function lb(){let e=k_(e=>e.camera);return(0,$.jsx)(ky,{makeDefault:!0,position:(0,v.useRef)([e.position.x,e.position.y,e.position.z]).current,zoom:20,near:.1,far:2e3})}function ub(){let e=k_(e=>e.gl);return(0,v.useEffect)(()=>(e.localClippingEnabled=!0,()=>{e.localClippingEnabled=!1}),[e]),null}function db({data:e,view:t=`iso`,fitSignal:n,autoRotate:r=!1,gridVisible:i=!0,projection:a=`perspective`,onFirstFrame:o,onError:s,errorFallback:c,children:l}){return(0,$.jsx)(By,{onError:s,fallback:c,children:(0,$.jsxs)(Qv,{frameloop:r?`always`:`demand`,gl:{preserveDrawingBuffer:!0},children:[(0,$.jsx)(ub,{}),a===`orthographic`&&(0,$.jsx)(lb,{}),(0,$.jsx)(ob,{autoRotate:r,gridVisible:i}),(0,$.jsx)(cb,{data:e,view:t,fitSignal:n,projection:a,onFirstFrame:o}),l]})})}var fb=[`iso`,`front`,`top`,`right`],pb={solid:`Solid`,wireframe:`Wire`,xray:`X-ray`},mb={iso:`Iso`,front:`Front`,top:`Top`,right:`Right`};function hb({viewMode:e,onViewModeChange:t,showEdges:n,onToggleEdges:r,showGrid:i,onToggleGrid:a,autoRotate:o,onToggleAutoRotate:s,projection:c,onToggleProjection:l,activeView:u,onView:d,onFit:f,onScreenshot:p,touch:m=!1,className:h}){return(0,$.jsxs)(`div`,{className:h,style:h?void 0:{...vb,gap:m?8:6},children:[(f||p)&&(0,$.jsxs)(gb,{touch:m,children:[f&&(0,$.jsx)(_b,{label:`Fit`,onClick:f,touch:m}),p&&(0,$.jsx)(_b,{label:`Snap`,onClick:p,touch:m})]}),e&&t&&(0,$.jsx)(gb,{touch:m,children:Object.keys(pb).map(n=>(0,$.jsx)(_b,{label:pb[n],active:e===n,touch:m,onClick:()=>{t(n)}},n))}),(r||a||s||l)&&(0,$.jsxs)(gb,{touch:m,children:[r&&(0,$.jsx)(_b,{label:`Edges`,active:n,onClick:r,touch:m}),a&&(0,$.jsx)(_b,{label:`Grid`,active:i,onClick:a,touch:m}),s&&(0,$.jsx)(_b,{label:`Spin`,active:o,onClick:s,touch:m}),l&&(0,$.jsx)(_b,{label:c===`orthographic`?`Ortho`:`Persp`,active:c===`orthographic`,touch:m,onClick:l})]}),d&&(0,$.jsx)(gb,{touch:m,children:fb.map(e=>(0,$.jsx)(_b,{label:mb[e],active:u===e,touch:m,onClick:()=>{d(e)}},e))})]})}function gb({children:e,touch:t}){return(0,$.jsx)(`div`,{style:t?Sb:yb,children:e})}function _b({label:e,active:t,onClick:n,touch:r}){return(0,$.jsx)(`button`,{type:`button`,onClick:n,"aria-pressed":t,style:{...r?Cb:bb,...t?xb:null},children:e})}var vb={position:`absolute`,top:12,right:12,zIndex:10,display:`flex`,flexDirection:`column`,gap:6,pointerEvents:`none`,fontFamily:`ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif`},yb={display:`flex`,flexDirection:`column`,gap:4,padding:4,borderRadius:8,background:`rgba(26, 29, 33, 0.7)`,backdropFilter:`blur(6px)`,border:`1px solid rgba(255, 255, 255, 0.08)`},bb={cursor:`pointer`,pointerEvents:`auto`,padding:`4px 10px`,borderRadius:5,fontSize:12,fontWeight:500,lineHeight:1.2,color:`#9aa3ad`,background:`rgba(255, 255, 255, 0.04)`,border:`1px solid transparent`,transition:`color 120ms, background 120ms`},xb={color:`#6ee7d7`,background:`rgba(45, 212, 191, 0.16)`,borderColor:`rgba(45, 212, 191, 0.3)`},Sb={...yb,gap:6,padding:6},Cb={...bb,padding:`9px 14px`,fontSize:13,borderRadius:6};function wb({dims:e,volume:t,area:n,triangles:r,valid:i,unit:a,className:o}){let s=a?` ${a}`:``,c=[];return e&&c.push((0,$.jsx)(Tb,{label:`Size`,value:`${Eb(e[0])} × ${Eb(e[1])} × ${Eb(e[2])}${s}`},`size`)),t!==void 0&&c.push((0,$.jsx)(Tb,{label:`Volume`,value:`${Eb(t)}${a?` ${a}³`:``}`},`vol`)),n!==void 0&&c.push((0,$.jsx)(Tb,{label:`Area`,value:`${Eb(n)}${a?` ${a}²`:``}`},`area`)),r!==void 0&&c.push((0,$.jsx)(Tb,{label:`Triangles`,value:r.toLocaleString()},`tris`)),i!==void 0&&c.push((0,$.jsx)(Tb,{label:`Validity`,value:i?`valid`:`invalid`,valueColor:i?`#6ee7d7`:`#f0a0a0`},`valid`)),c.length===0?null:(0,$.jsx)(`div`,{className:o,style:o?void 0:Db,children:c})}function Tb({label:e,value:t,valueColor:n}){return(0,$.jsxs)(`div`,{style:Ob,children:[(0,$.jsx)(`span`,{style:kb,children:e}),(0,$.jsx)(`span`,{style:{...Ab,...n?{color:n}:null},children:t})]})}function Eb(e){return Number.isFinite(e)?Number.isInteger(e)?e.toLocaleString():Number(e.toFixed(2)).toLocaleString():`—`}var Db={position:`absolute`,left:12,bottom:12,zIndex:10,display:`flex`,flexDirection:`column`,gap:2,padding:`8px 10px`,borderRadius:8,minWidth:150,background:`rgba(26, 29, 33, 0.7)`,backdropFilter:`blur(6px)`,border:`1px solid rgba(255, 255, 255, 0.08)`,fontFamily:`ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif`},Ob={display:`flex`,justifyContent:`space-between`,gap:16,fontSize:12,lineHeight:1.5},kb={color:`#7b8591`},Ab={color:`#c8cdd3`,fontVariantNumeric:`tabular-nums`},jb={PLANE:`Planar`,CYLINDER:`Cylindrical`,CONE:`Conical`,SPHERE:`Spherical`,TORUS:`Toroidal`,BEZIER_SURFACE:`Bézier`,BSPLINE_SURFACE:`B-spline`,REVOLUTION_SURFACE:`Revolved`,EXTRUSION_SURFACE:`Extruded`,OFFSET_SURFACE:`Offset`,OTHER_SURFACE:`Surface`};function Mb(e){return jb[e]??`Surface`}function Nb(e){return Number.isFinite(e)?Number.isInteger(e)?e.toLocaleString():Number(e.toFixed(2)).toLocaleString():`—`}function Pb({face:e,onClear:t,unit:n,className:r}){if(!e)return null;let[i,a,o]=e.normal;return(0,$.jsxs)(`div`,{className:r,style:r?void 0:Ib,children:[(0,$.jsxs)(`div`,{style:Lb,children:[(0,$.jsxs)(`span`,{style:Rb,children:[Mb(e.surfaceType),` face`]}),t&&(0,$.jsx)(`button`,{type:`button`,onClick:t,"aria-label":`Clear selection`,style:zb,children:`✕`})]}),(0,$.jsx)(Fb,{label:`Area`,value:`${Nb(e.area)}${n?` ${n}²`:``}`}),(0,$.jsx)(Fb,{label:`Normal`,value:`${Nb(i)}, ${Nb(a)}, ${Nb(o)}`})]})}function Fb({label:e,value:t}){return(0,$.jsxs)(`div`,{style:Bb,children:[(0,$.jsx)(`span`,{style:Vb,children:e}),(0,$.jsx)(`span`,{style:Hb,children:t})]})}var Ib={position:`absolute`,left:12,top:12,zIndex:10,display:`flex`,flexDirection:`column`,gap:2,padding:`8px 10px`,borderRadius:8,minWidth:170,background:`rgba(26, 29, 33, 0.7)`,backdropFilter:`blur(6px)`,border:`1px solid rgba(74, 206, 204, 0.3)`,fontFamily:`ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif`},Lb={display:`flex`,justifyContent:`space-between`,alignItems:`center`,gap:12,marginBottom:2},Rb={color:`#6ee7d7`,fontSize:12,fontWeight:600},zb={cursor:`pointer`,border:`none`,background:`transparent`,color:`#7b8591`,fontSize:12,lineHeight:1,padding:0},Bb={display:`flex`,justifyContent:`space-between`,gap:16,fontSize:12,lineHeight:1.5},Vb={color:`#7b8591`},Hb={color:`#c8cdd3`,fontVariantNumeric:`tabular-nums`},Ub=[`x`,`y`,`z`];function Wb({enabled:e,onToggle:t,axis:n,onAxisChange:r,position:i,min:a,max:o,onPositionChange:s,flip:c,onToggleFlip:l,className:u}){return(0,$.jsxs)(`div`,{className:u,style:u?void 0:Kb,children:[(0,$.jsx)(Gb,{label:`Section`,active:e,onClick:t}),e&&(0,$.jsxs)($.Fragment,{children:[Ub.map(e=>(0,$.jsx)(Gb,{label:e.toUpperCase(),active:n===e,onClick:()=>{r(e)}},e)),(0,$.jsx)(`input`,{type:`range`,min:a,max:o,step:(o-a)/200||.01,value:i,disabled:a===o,onChange:e=>{s(Number(e.target.value))},"aria-label":`Section position`,style:{...Yb,...a===o?{opacity:.4}:null}}),(0,$.jsx)(Gb,{label:`Flip`,active:c,onClick:l})]})]})}function Gb({label:e,active:t,onClick:n}){return(0,$.jsx)(`button`,{type:`button`,onClick:n,"aria-pressed":t,style:{...qb,...t?Jb:null},children:e})}var Kb={position:`absolute`,bottom:12,left:`50%`,transform:`translateX(-50%)`,zIndex:10,display:`flex`,alignItems:`center`,gap:4,padding:4,borderRadius:8,background:`rgba(26, 29, 33, 0.7)`,backdropFilter:`blur(6px)`,border:`1px solid rgba(255, 255, 255, 0.08)`,fontFamily:`ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif`},qb={cursor:`pointer`,padding:`4px 10px`,borderRadius:5,fontSize:12,fontWeight:500,lineHeight:1.2,color:`#9aa3ad`,background:`rgba(255, 255, 255, 0.04)`,border:`1px solid transparent`},Jb={color:`#6ee7d7`,background:`rgba(45, 212, 191, 0.16)`,borderColor:`rgba(45, 212, 191, 0.3)`},Yb={width:160,accentColor:`#4ACECC`,margin:`0 4px`};function Xb(e){let t=new URLSearchParams(e),n=t.get(`file`);return n?{dir:t.get(`dir`),file:n}:null}function Zb(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function Qb({inspect:e=!1}={}){let[t,n]=(0,v.useState)({status:`idle`});return(0,v.useEffect)(()=>{let t=Xb(window.location.search);if(!t){n({status:`error`,error:`missing ?file= parameter`});return}if(!t.dir){n({status:`error`,error:`missing ?dir= parameter`});return}n({status:`loading`});let r=new Worker(new URL(``+new URL(`kernelWorker-B0NAVVTL.js`,import.meta.url).href,``+import.meta.url),{type:`module`}),i=!1;r.addEventListener(`message`,e=>{i||(e.data.type===`loaded`?n({status:`ready`,data:e.data.meshData,measurements:e.data.measurements}):n({status:`error`,error:e.data.error}))});let a=`/__model/${t.file.split(`/`).map(encodeURIComponent).join(`/`)}?dir=${encodeURIComponent(t.dir)}`;return fetch(a).then(e=>{if(!e.ok)throw Error(`fetch ${t.file}: ${e.status}`);return e.arrayBuffer()}).then(n=>{let i={type:`load`,bytes:n,ext:Zb(t.file),inspect:e};r.postMessage(i,[n])}).catch(e=>{i||n({status:`error`,error:e instanceof Error?e.message:String(e)})}),()=>{i=!0,r.terminate()}},[e]),t}var $b=[`iso`,`front`,`top`,`right`],ex=new Set;function tx(e){return $b.includes(e)}function nx(e){return ex.add(e),()=>ex.delete(e)}function rx(e){for(let t of ex)t(e)}function ix(){globalThis.__ready=!0}function ax(){let e=globalThis;e.__ready=!1,e.__renderView=e=>{tx(e)&&rx({view:e})},e.__setScene=e=>{e&&tx(e.view)&&rx(e)}}function ox({marks:e}){return(0,$.jsx)($.Fragment,{children:e.map((e,t)=>(0,$.jsx)(my,{position:[e.pos[0],e.pos[1],e.pos[2]],center:!0,children:(0,$.jsx)(`div`,{style:{background:`#ffcc00`,color:`#000`,font:`700 13px monospace`,padding:`1px 5px`,borderRadius:4,border:`1px solid #000`,whiteSpace:`nowrap`,pointerEvents:`none`},children:e.label})},`${e.label}-${t}`))})}var sx=new URLSearchParams(window.location.search),cx=sx.get(`ui`)!==`0`,lx=sx.get(`dims`)===`1`;function ux(){let e=document.querySelector(`canvas`);if(!e)return;let t=e.toDataURL(`image/png`),n=document.createElement(`a`);n.href=t,n.download=`brepjs-view.png`,n.click()}function dx(){let e=Qb({inspect:cx}),[t,n]=(0,v.useState)(`iso`),[r,i]=(0,v.useState)(`solid`),[a,o]=(0,v.useState)(!0),[s,c]=(0,v.useState)(!0),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(`perspective`),[p,m]=(0,v.useState)(0),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(null),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(`x`),[w,T]=(0,v.useState)(0),[E,D]=(0,v.useState)(!1),[O,k]=(0,v.useState)([]),A=(0,v.useCallback)(()=>{m(e=>e+1)},[]),ee=(0,v.useCallback)(e=>{g(e)},[]),j=(0,v.useCallback)(e=>{y(e?e.faceId:null)},[]),M=(0,v.useMemo)(()=>e.status===`ready`?My(e.data):null,[e]);(0,v.useEffect)(()=>nx(e=>{if(n(e.view),i(e.viewMode??`solid`),e.section&&M){let t=e.section.axis===`x`?0:e.section.axis===`y`?1:2;C(e.section.axis),T(M.min[t]+e.section.frac*(M.max[t]-M.min[t])),x(!0)}else x(!1);k(e.marks??[])}),[M]);let te=S===`x`?0:S===`y`?1:2,N=M?M.min[te]:0,P=M?M.max[te]:1,F=(0,v.useCallback)(e=>{if(!M)return 0;let t=e===`x`?0:e===`y`?1:2;return(M.min[t]+M.max[t])/2},[M]),ne=(0,v.useCallback)(()=>{x(e=>(e||T(F(S)),!e))},[F,S]),re=(0,v.useCallback)(e=>{C(e),T(F(e))},[F]),ie=(0,v.useMemo)(()=>b&&M?[Py(S,w,E)]:void 0,[b,M,S,w,E]);return e.status===`error`?(0,$.jsxs)(`div`,{style:{color:`#e88`,padding:16,fontFamily:`monospace`},children:[`error: `,e.error]}):e.status===`ready`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(db,{data:e.data,view:t,fitSignal:p,autoRotate:l,gridVisible:s,projection:d,onFirstFrame:ix,children:[(0,$.jsx)(zy,{data:e.data,viewMode:r,...ie?{clippingPlanes:ie}:{},...cx?{onFacePick:ee,onFaceHover:j}:{}}),a&&r!==`wireframe`&&e.data.edges.length>0&&(0,$.jsx)(Uy,{edges:e.data.edges,...ie?{clippingPlanes:ie}:{}}),cx&&(0,$.jsx)(Zy,{data:e.data,selectedFaceIds:h?[h.faceId]:[],hoverFaceId:_}),O.length>0&&(0,$.jsx)(ox,{marks:O})]}),cx&&(0,$.jsx)(Pb,{face:h,onClear:()=>{g(null)}}),cx&&(0,$.jsx)(Wb,{enabled:b,onToggle:ne,axis:S,onAxisChange:re,position:w,min:N,max:P,onPositionChange:T,flip:E,onToggleFlip:()=>{D(e=>!e)}}),cx&&(0,$.jsx)(wb,{dims:Ny(e.data),volume:e.measurements.volume,area:e.measurements.area,triangles:e.data.index.length/3,valid:e.measurements.valid}),!cx&&lx&&(0,$.jsx)(wb,{dims:Ny(e.data)}),cx&&(0,$.jsx)(hb,{viewMode:r,onViewModeChange:i,showEdges:a,onToggleEdges:()=>{o(e=>!e)},showGrid:s,onToggleGrid:()=>{c(e=>!e)},autoRotate:l,onToggleAutoRotate:()=>{u(e=>!e)},projection:d,onToggleProjection:()=>{f(e=>e===`perspective`?`orthographic`:`perspective`)},activeView:t,onView:n,onFit:A,onScreenshot:ux})]}):(0,$.jsx)(`div`,{style:{color:`#9aa`,padding:16,fontFamily:`monospace`},children:`loading model…`})}ax();var fx=document.getElementById(`root`);fx&&(0,y.createRoot)(fx).render((0,$.jsx)(v.StrictMode,{children:(0,$.jsx)(dx,{})}));
@@ -1 +1 @@
1
- function e(e,t,n={}){let r={position:e.vertices,normal:e.normals,index:e.triangles,edges:t,faceGroups:e.faceGroups.map(e=>({start:e.start,count:e.count,faceId:e.faceId}))};return n.color&&(r.color=n.color),r}function t(e,t){let r={valid:n(()=>e.isValid(t))??!1},i=n(()=>e.measureVolume(t));i&&e.isOk(i)&&typeof i.value==`number`&&i.value>0&&(r.volume=i.value);let a=n(()=>e.measureArea(t));return a&&e.isOk(a)&&typeof a.value==`number`&&a.value>0&&(r.area=a.value),r}function n(e){try{return e()}catch{return}}function r(e,t){switch(t.replace(/^\./,``).toLowerCase()){case`step`:case`stp`:return e.importSTEP;case`stl`:return e.importSTL;case`iges`:case`igs`:return e.importIGES;case`3mf`:return e.importThreeMF;case`glb`:case`gltf`:return e.importGLB;case`obj`:return e.importOBJ;default:throw Error(`unsupported file extension: ${t}`)}}function i(e,t){let n;try{n=e.getFaces(t)}catch(e){return console.warn(`[brepjs-cad] getFaces threw; faces unselectable`,e),[]}let r=[];for(let t of n)try{let n=e.getSurfaceType(t),i=e.isOk(n)&&n.value?n.value:`OTHER_SURFACE`,a=e.measureArea(t),o=e.isOk(a)&&typeof a.value==`number`?a.value:NaN;r.push({faceId:e.getHashCode(t),surfaceType:i,area:o,normal:e.normalAt(t)})}catch(e){console.warn(`[brepjs-cad] face metadata threw; skipping face`,e)}return r}async function a(n,a,o,s=!1){let c=await r(n,o)(a);if(!n.isOk(c)){let e=c.error;throw Error(`import failed: ${typeof e==`string`?e:JSON.stringify(e)}`)}let l=c.value,u=e(n.mesh(l),n.meshEdges(l).lines);return s&&(u.faceInfos=i(n,l)),{meshData:u,measurements:t(n,l)}}function o(e,t){t?self.postMessage(e,t):self.postMessage(e)}let s=null;function c(){return s||=l().catch(e=>{throw s=null,e}),s}async function l(){let e=new URL(`./`,self.location.origin).href,t=await fetch(`${e}wasm/occt-wasm.js`);if(!t.ok)throw Error(`failed to load occt-wasm.js: ${t.status}`);let n=URL.createObjectURL(new Blob([await t.text()],{type:`application/javascript`})),r=await import(n);URL.revokeObjectURL(n);let i=await r.default({locateFile:t=>t.endsWith(`.wasm`)?`${e}wasm/occt-wasm.wasm`:t}),a=await import(`./brepjs-nhz44i-z.js`),o=new i.OcctKernel;return a.registerKernel(`occt-wasm`,new a.OcctWasmAdapter(i,o)),a}function u(e){return[e.position.buffer,e.normal.buffer,e.index.buffer,e.edges.buffer]}async function d(e){try{let{meshData:t,measurements:n}=await a(await c(),new Blob([e.bytes]),e.ext,e.inspect??!1);o({type:`loaded`,meshData:t,measurements:n},u(t))}catch(e){o({type:`error`,error:e instanceof Error?e.message:String(e)})}}self.addEventListener(`message`,e=>{e.data.type===`load`&&d(e.data)});
1
+ function e(e,t,n={}){let r={position:e.vertices,normal:e.normals,index:e.triangles,edges:t,faceGroups:e.faceGroups.map(e=>({start:e.start,count:e.count,faceId:e.faceId}))};return n.color&&(r.color=n.color),r}function t(e,t){let r={valid:n(()=>e.isValid(t))??!1},i=n(()=>e.measureVolume(t));i&&e.isOk(i)&&typeof i.value==`number`&&i.value>0&&(r.volume=i.value);let a=n(()=>e.measureArea(t));return a&&e.isOk(a)&&typeof a.value==`number`&&a.value>0&&(r.area=a.value),r}function n(e){try{return e()}catch{return}}function r(e,t){switch(t.replace(/^\./,``).toLowerCase()){case`step`:case`stp`:return e.importSTEP;case`stl`:return e.importSTL;case`iges`:case`igs`:return e.importIGES;case`3mf`:return e.importThreeMF;case`glb`:case`gltf`:return e.importGLB;case`obj`:return e.importOBJ;default:throw Error(`unsupported file extension: ${t}`)}}function i(e,t){let n;try{n=e.getFaces(t)}catch(e){return console.warn(`[brepjs-cad] getFaces threw; faces unselectable`,e),[]}let r=[];for(let t of n)try{let n=e.getSurfaceType(t),i=e.isOk(n)&&n.value?n.value:`OTHER_SURFACE`,a=e.measureArea(t),o=e.isOk(a)&&typeof a.value==`number`?a.value:NaN;r.push({faceId:e.getHashCode(t),surfaceType:i,area:o,normal:e.normalAt(t)})}catch(e){console.warn(`[brepjs-cad] face metadata threw; skipping face`,e)}return r}async function a(n,a,o,s=!1){let c=await r(n,o)(a);if(!n.isOk(c)){let e=c.error;throw Error(`import failed: ${typeof e==`string`?e:JSON.stringify(e)}`)}let l=c.value,u=e(n.mesh(l),n.meshEdges(l).lines);return s&&(u.faceInfos=i(n,l)),{meshData:u,measurements:t(n,l)}}function o(e,t){t?self.postMessage(e,t):self.postMessage(e)}let s=null;function c(){return s||=l().catch(e=>{throw s=null,e}),s}async function l(){let e=new URL(`./`,self.location.origin).href,t=await fetch(`${e}wasm/occt-wasm.js`);if(!t.ok)throw Error(`failed to load occt-wasm.js: ${t.status}`);let n=URL.createObjectURL(new Blob([await t.text()],{type:`application/javascript`})),r=await import(n);URL.revokeObjectURL(n);let i=await r.default({locateFile:t=>t.endsWith(`.wasm`)?`${e}wasm/occt-wasm.wasm`:t}),a=await import(`./brepjs-u_PqaluH.js`),o=new i.OcctKernel;return a.registerKernel(`occt-wasm`,new a.OcctWasmAdapter(i,o)),a}function u(e){return[e.position.buffer,e.normal.buffer,e.index.buffer,e.edges.buffer]}async function d(e){try{let{meshData:t,measurements:n}=await a(await c(),new Blob([e.bytes]),e.ext,e.inspect??!1);o({type:`loaded`,meshData:t,measurements:n},u(t))}catch(e){o({type:`error`,error:e instanceof Error?e.message:String(e)})}}self.addEventListener(`message`,e=>{e.data.type===`load`&&d(e.data)});
@@ -14,7 +14,7 @@
14
14
  background: #1a1d21;
15
15
  }
16
16
  </style>
17
- <script type="module" crossorigin src="./assets/index-Da3FWE25.js"></script>
17
+ <script type="module" crossorigin src="./assets/index-f5md-zbM.js"></script>
18
18
  </head>
19
19
  <body>
20
20
  <div id="root"></div>