brepjs-cad 0.61.0 → 0.63.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,77 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.63.0](https://github.com/andymai/brepjs/compare/brepjs-cad-v0.62.0...brepjs-cad-v0.63.0) (2026-07-13)
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
+ * **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))
38
+
39
+ ## [0.62.0](https://github.com/andymai/brepjs/compare/brepjs-cad-v0.61.1...brepjs-cad-v0.62.0) (2026-07-13)
40
+
41
+
42
+ ### Features
43
+
44
+ * **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))
45
+ * **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))
46
+ * **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))
47
+ * **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))
48
+ * **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))
49
+ * **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))
50
+ * **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))
51
+ * **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))
52
+ * **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))
53
+
54
+
55
+ ### Bug Fixes
56
+
57
+ * **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))
58
+ * **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))
59
+ * **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))
60
+ * **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))
61
+ * **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))
62
+ * **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))
63
+ * **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))
64
+ * **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))
65
+ * **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))
66
+ * **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))
67
+ * **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))
68
+ * **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))
69
+ * **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))
70
+ * **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))
71
+ * **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))
72
+ * **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))
73
+ * **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))
74
+
3
75
  ## [0.61.0](https://github.com/andymai/brepjs/compare/brepjs-cad-v0.60.0...brepjs-cad-v0.61.0) (2026-07-13)
4
76
 
5
77
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brepjs-cad",
3
- "version": "0.61.0",
3
+ "version": "0.63.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 ew(e,{vertProperties:Float32Array.from(r),triVerts:Uint32Array.from(i)})}function nw(e,t){let n=new Uint8Array(t),r=new TextDecoder().decode(n.subarray(0,Math.min(n.length,80))).trimStart().toLowerCase().startsWith(`solid`)&&aw(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=iw(i);return ew(e,{vertProperties:Float32Array.from(a.vertices),triVerts:Uint32Array.from(a.indices)})}var rw=1e6;function iw(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*rw)},${Math.round(o*rw)},${Math.round(s*rw)}`,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 aw(e){return e.length<84?!0:84+new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(80,!0)*50!==e.length}var ow=1e-6;function sw(e,t){let n=H(t);if(n.replayable)return QS(n,e)}function cw(e,t){let n=GC(t),r=Math.floor(n.triVerts.length/3),i=[];for(let t=0;t<r;t++){let[r,a,o]=YC(n,t),s=e.buildTriFace(JC(n,r),JC(n,a),JC(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,ow)}function lw(e){let t=Iy(`B-rep export`),n=sw(t,e);return n===void 0?(console.warn(`manifold: exact B-rep unavailable (non-replayable op-graph); exporting faceted approximation`),{occt:t,brep:cw(t,e)}):{occt:t,brep:n}}function uw(e,t,n,r){let i=t.mesh(n,{tolerance:.01,angularTolerance:.5});return ew(e,{vertProperties:Float32Array.from(i.vertices),triVerts:Uint32Array.from(i.triangles)},r)}var dw=1179937895,fw=2,pw=1313821514,mw=5130562,hw=5126,gw=5125,_w=5123,vw=5121,yw=34962,bw=34963,xw=4;function Sw(e){return e+3&-4}function Cw(e){let t=GC(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=Sw(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:xw}]}],accessors:[{bufferView:0,componentType:hw,count:r,type:`VEC3`,min:[o,s,c],max:[l,u,d]},{bufferView:1,componentType:gw,count:i,type:`SCALAR`}],bufferViews:[{buffer:0,byteOffset:0,byteLength:p,target:yw},{buffer:0,byteOffset:m,byteLength:f.byteLength,target:bw}],buffers:[{byteLength:h}]},_=new TextEncoder().encode(JSON.stringify(g)),v=Sw(_.length),y=Sw(h),b=20+v+8+y,x=new ArrayBuffer(b),S=new DataView(x),C=new Uint8Array(x);S.setUint32(0,dw,!0),S.setUint32(4,fw,!0),S.setUint32(8,b,!0);let w=12;S.setUint32(w,v,!0),S.setUint32(w+4,pw,!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,mw,!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 ww(e,t){let n=new DataView(t);if(n.getUint32(0,!0)!==dw)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===pw?i=JSON.parse(new TextDecoder().decode(s)):r===mw&&(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===gw?4:e.componentType===_w?2:+(e.componentType===vw);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 ew(e,{vertProperties:p,triVerts:m},`importGLB`)}function Tw(e){return{exportSTL:(e,t)=>ZC(e,t),exportOBJ:e=>QC(e),exportPLY:e=>$C(e),importSTL:t=>nw(e,typeof t==`string`?new TextEncoder().encode(t).buffer:t),importOBJ:t=>tw(e,t),exportSTEP:e=>Iy(`exportSTEP`).exportSTEP(e.map(e=>lw(e).brep)),exportIGES:e=>Iy(`exportIGES`).exportIGES(e.map(e=>lw(e).brep)),toBREP:e=>{let{occt:t,brep:n}=lw(e);return t.toBREP(n)},exportSTEPAssembly:(e,t)=>{let n=Iy(`exportSTEPAssembly`),r=e.map(e=>{let t={shape:lw(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=Iy(`createXCAFDocument`),n=e.map(e=>{let t={shape:lw(e.shape).brep,name:e.name};return e.color===void 0?t:{...t,color:e.color}});return t.createXCAFDocument(n)},writeXCAFToSTEP:(e,t)=>Iy(`writeXCAFToSTEP`).writeXCAFToSTEP(e,t),exportSTEPConfigured:(e,t)=>{let n=Iy(`exportSTEPConfigured`),r=e.map(e=>{let t={shape:lw(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=Iy(`importSTEP`);return n.importSTEP(t).map(t=>uw(e,n,t,`importSTEP`))},importIGES:t=>{let n=Iy(`importIGES`);return n.importIGES(t).map(t=>uw(e,n,t,`importIGES`))},fromBREP:t=>{let n=Iy(`fromBREP`);return uw(e,n,n.fromBREP(t),`fromBREP`)},exportGLB:e=>Cw(e),importGLB:t=>ww(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 Ew(e){return V(e).getMesh()}function Dw(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 Ow(e,t){let n=e;if(n&&n.__manifoldSub&&n.occt){let e=Fy();if(!e)throw Error(`manifold: sub-shape geometry query requires a registered occt kernel`);return t(n.occt,e)}let r=Ny(e);if(!r)throw Error(`manifold: exact geometry query requires a manifold shape handle`);let i=Fy();if(!i)throw Error(`manifold: exact geometry query unsupported on manifold kernel; no B-rep kernel registered`);if(!r.node.replayable)throw Error(`manifold: exact geometry query unsupported; shape originates from a non-replayable op (raw mesh import or mesh boolean)`);let a=Ly.get(r.node);return a===void 0&&(a=QS(r.node,i),Ly.set(r.node,a)),t(a,i)}function kw(e){let t=Ny(e);if(!t)return;let n=t.node;return n.op===`profileEdge`?n.params?.curve:void 0}function Aw(e){return{curveType:e=>{let t=kw(e);return t?Cb(t):NC(e)?e.curveType:Ow(e,(e,t)=>t.curveType(e))},curveParameters:e=>{let t=kw(e);if(t){let e=wb(t);return[e.first,e.last]}return NC(e)?[0,e.length]:Ow(e,(e,t)=>t.curveParameters(e))},curvePointAtParam:(e,t)=>{let n=kw(e);return n?Tb(n,t):NC(e)?PC(e,t):Ow(e,(e,n)=>n.curvePointAtParam(e,t))},curveTangent:(e,t)=>{let n=kw(e);return n?{point:Tb(n,t),tangent:Eb(n,t)}:NC(e)?{point:PC(e,t),tangent:FC(e,t)}:Ow(e,(e,n)=>n.curveTangent(e,t))},curveIsClosed:e=>{let t=kw(e);return t?Ob(t):Ow(e,(e,t)=>t.curveIsClosed(e))},curveIsPeriodic:e=>{let t=kw(e);return t?kb(t):Ow(e,(e,t)=>t.curveIsPeriodic(e))},curvePeriod:e=>{let t=kw(e);return t?Ab(t):Ow(e,(e,t)=>t.curvePeriod(e))},interpolatePoints:(e,t)=>Iy(`interpolatePoints`).interpolatePoints(e,t),approximatePoints:(e,t)=>Iy(`approximatePoints`).approximatePoints(e,t),curveDegreeElevate:(e,t)=>Ow(e,(e,n)=>n.curveDegreeElevate(e,t)),curveKnotInsert:(e,t,n)=>Ow(e,(e,r)=>r.curveKnotInsert(e,t,n)),curveKnotRemove:(e,t,n)=>Ow(e,(e,r)=>r.curveKnotRemove(e,t,n)),curveSplit:(e,t)=>Ow(e,(e,n)=>n.curveSplit(e,t)),createCurveAdaptor:e=>Ow(e,(e,t)=>t.createCurveAdaptor(e)),getBezierPenultimatePole:e=>Ow(e,(e,t)=>t.getBezierPenultimatePole(e)),getNurbsCurveData:e=>Ow(e,(e,t)=>t.getNurbsCurveData?.(e)??null),vertexPosition:e=>MC(e)?e.point:Ny(e)?Dw(Ew(e),0):Ow(e,(e,t)=>t.vertexPosition(e)),surfaceType:e=>{if(CC(e))return`plane`;let t=Ny(e);return t&&t.node.op===`profileFace`?`plane`:Ow(e,(e,t)=>t.surfaceType(e))},uvBounds:e=>CC(e)?{uMin:0,uMax:1,vMin:0,vMax:1}:Ow(e,(e,t)=>t.uvBounds(e)),outerWire:e=>Ow(e,(e,t)=>t.outerWire(e)),surfaceNormal:(e,t,n)=>CC(e)?e.normal:Ow(e,(e,r)=>r.surfaceNormal(e,t,n)),pointOnSurface:(e,t,n)=>Ow(e,(e,r)=>r.pointOnSurface(e,t,n)),uvFromPoint:(e,t)=>Ow(e,(e,n)=>n.uvFromPoint(e,t)),projectPointOnFace:(e,t)=>Ow(e,(e,n)=>n.projectPointOnFace(e,t)),classifyPointOnFace:(e,t,n,r)=>Ow(e,(e,i)=>i.classifyPointOnFace(e,t,n,r)),classifyPointRobust:(e,t,n)=>Ow(e,(e,r)=>r.classifyPointRobust(e,t,n)),classifyPointWinding:(e,t,n)=>Ow(e,(e,r)=>r.classifyPointWinding(e,t,n)),approximateSurfaceLspia:(e,t,n,r,i,a,o,s,c)=>Iy(`approximateSurfaceLspia`).approximateSurfaceLspia(e,t,n,r,i,a,o,s,c),untrimFace:(e,t,n)=>Ow(e,(e,r)=>r.untrimFace(e,t,n)),getSurfaceCylinderData:e=>Ow(e,(e,t)=>t.getSurfaceCylinderData(e)),getSurfaceAxis:e=>Ow(e,(e,t)=>t.getSurfaceAxis(e)),reverseSurfaceU:e=>Iy(`reverseSurfaceU`).reverseSurfaceU(e),detectSmallFeatures:(e,t,n)=>Ow(e,(e,r)=>r.detectSmallFeatures(e,t,n)),recognizeFeatures:(e,t)=>Ow(e,(e,n)=>n.recognizeFeatures(e,t)),projectEdges:(e,t,n,r)=>Ow(e,(e,i)=>i.projectEdges(e,t,n,r)),getNurbsSurfaceData:e=>Ow(e,(e,t)=>t.getNurbsSurfaceData?.(e)??null)}}var jw={hasErrors:!1,hasWarnings:!1,messages:[]};function Mw(){return{modified:new Map,generated:new Map,deleted:new Set}}function Nw(e){return{shape:e,evolution:Mw()}}function Pw(e){return{shape:e,evolution:Mw(),diagnostics:jw}}function Fw(e){let t=gb(e),n=Jy(e),r=SS(e);return{translateWithHistory:(e,n,r,i)=>Nw(t.translate(e,n,r,i)),rotateWithHistory:(e,n,r,i,a,o)=>Nw(t.rotate(e,n,a,o)),mirrorWithHistory:(e,n,r)=>Nw(t.mirror(e,n,r)),scaleWithHistory:(e,n,r)=>Nw(t.scale(e,n,r)),generalTransformWithHistory:(e,n,r,i)=>Nw(t.generalTransform(e,n,r,i)),fuseWithHistory:(e,t,r,i,a)=>Pw(n.fuse(e,t,a)),cutWithHistory:(e,t,r,i,a)=>Pw(n.cut(e,t,a)),intersectWithHistory:(e,t,r,i,a)=>Pw(n.intersect(e,t,a)),filletWithHistory:(e,t,n)=>Nw(r.fillet(e,t,n)),chamferWithHistory:(e,t,n)=>Nw(r.chamfer(e,t,n)),shellWithHistory:(e,t,n,i,a,o)=>Nw(r.shell(e,t,n,o)),thickenWithHistory:(e,t)=>Nw(r.thicken(e,t)),offsetWithHistory:(e,t,n,i,a)=>Nw(r.offset(e,t,a)),draftWithHistory:(e,t,n,i,a)=>Nw(r.draft(e,t,n,i,a)),applyComposedTransformWithHistory:(e,n)=>Nw(t.transform(e,n))}}function Iw(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 Lw(e){return{isValid:e=>Iw(e),isValidStrict:e=>Iw(e),healSolid:e=>Iw(e)?e:null,healFace:e=>e,healWire:e=>e,mergeCoincidentVertices:()=>0,removeDegenerateEdges:()=>0,fixFaceOrientations:()=>0,fixShape:e=>e,fixSelfIntersection:e=>e}}var Rw=.004;function zw(e){return!!e&&typeof e==`object`&&e.__nativeC2d===!0}function Bw(e,t){return{__nativeC2d:!0,k:`line`,p1:e,p2:t}}function Vw(e,t,n,r,i){return{__nativeC2d:!0,k:`conic`,c:e,u:t,v:n,a0:r,a1:i}}function Hw(e,[t,n]){return[e.a*t+e.b*n+e.tx,e.c*t+e.d*n+e.ty]}function Uw(e,[t,n]){return[e.a*t+e.b*n,e.c*t+e.d*n]}function Ww(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 Gw(e,t){return e.k===`line`?Bw(Hw(t,e.p1),Hw(t,e.p2)):e.k===`bezier`?{__nativeC2d:!0,k:`bezier`,pts:e.pts.map(e=>Hw(t,e))}:Vw(Hw(t,e.c),Uw(t,e.u),Uw(t,e.v),e.a0,e.a1)}function Kw(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 qw(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 Jw(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 Kw(r,t)}function Yw(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<=Rw)return Math.max(2,Math.ceil(t/(2*Math.PI)*8));let a=2*Math.acos(Math.max(-1,1-Rw/i));return Math.max(2,Math.ceil(t/a))}function Xw(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(Kw(e.pts,n/24));return t}let t=e.a1-e.a0,n=Yw(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 Zw(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 Bw(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-_),Vw(f,[p,0],[0,p],h,_)}function Qw(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(!zw(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=qw(n,n.a0),i=qw(n,(n.a0+n.a1)/2),a=qw(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(Xw(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)=>Bw([e,t],[n,r]),makeCircle2d:(e,t,n,r=!0)=>Vw([e,t],[n,0],r?[0,n]:[0,-n],0,2*Math.PI),makeArc2dThreePoints:(e,t,n,r,i,a)=>Zw([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 Bw([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),Vw([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 Vw([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 Vw([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`?Kw(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:Kw(n.pts,t),tangent:Jw(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 Vw(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 Bw([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=Ww(e,t);Object.assign(e,n)},transformCurve2dGeneral:(e,t)=>Gw(i(e),t),translateCurve2d:(e,t,n)=>Gw(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 Gw(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)=>Gw(i(e),{a:t,b:0,c:0,d:t,tx:n-t*n,ty:r-t*r}),mirrorCurve2dAtPoint:(e,t,n)=>Gw(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 Gw(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 Gw(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(zw(t))r=Xw(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=Xw(i(e)).map(([e,n])=>[t[0]+l*e+f*n,t[1]+u*e+p*n,t[2]+d*e+m*n]);return My(n,B(`profileEdge`,{pts:h},[]))},makeBSpline2d:(e,t)=>a(`makeBSpline2d`).makeBSpline2d(e,t),offsetCurve2d:(e,t)=>a(`offsetCurve2d`).offsetCurve2d(o(e),t),intersectCurves2d:(e,t,n)=>a(`intersectCurves2d`).intersectCurves2d(o(e),o(t),n),projectPointOnCurve2d:(e,t,n)=>a(`projectPointOnCurve2d`).projectPointOnCurve2d(o(e),t,n),distanceBetweenCurves2d:(e,t,n,r,i,s)=>a(`distanceBetweenCurves2d`).distanceBetweenCurves2d(o(e),o(t),n,r,i,s),approximateCurve2dAsBSpline:(e,t,n,r)=>a(`approximateCurve2dAsBSpline`).approximateCurve2dAsBSpline(o(e),t,n,r),decomposeBSpline2dToBeziers:e=>a(`decomposeBSpline2dToBeziers`).decomposeBSpline2dToBeziers(o(e)),serializeCurve2d:e=>a(`serializeCurve2d`).serializeCurve2d(o(e)),deserializeCurve2d:e=>a(`deserializeCurve2d`).deserializeCurve2d(e),splitCurve2d:(e,t)=>a(`splitCurve2d`).splitCurve2d(o(e),t),getCurve2dEllipseData:e=>a(`getCurve2dEllipseData`).getCurve2dEllipseData(o(e)),getCurve2dBezierPoles:e=>a(`getCurve2dBezierPoles`).getCurve2dBezierPoles(o(e)),getCurve2dBezierDegree:e=>a(`getCurve2dBezierDegree`).getCurve2dBezierDegree(o(e)),getCurve2dBSplineData:e=>a(`getCurve2dBSplineData`).getCurve2dBSplineData(o(e)),buildEdgeOnSurface:(e,t)=>a(`buildEdgeOnSurface`).buildEdgeOnSurface(o(e),t),extractSurfaceFromFace:e=>a(`extractSurfaceFromFace`).extractSurfaceFromFace(e),extractCurve2dFromEdge:(e,t)=>a(`extractCurve2dFromEdge`).extractCurve2dFromEdge(e,t),buildCurves3d:e=>{a(`buildCurves3d`).buildCurves3d(e)},fixWireOnFace:(e,t,n)=>a(`fixWireOnFace`).fixWireOnFace(e,t,n),fillSurface:(e,t)=>a(`fillSurface`).fillSurface(e,t)};for(let e of[`evaluateCurve2d`,`evaluateCurve2dD1`,`getCurve2dBounds`,`getCurve2dType`,`reverseCurve2d`,`copyCurve2d`,`trimCurve2d`,`transformCurve2dGeneral`,`translateCurve2d`,`rotateCurve2d`,`scaleCurve2d`,`mirrorCurve2dAtPoint`,`mirrorCurve2dAcrossAxis`,`affinityTransform2d`,`getCurve2dCircleData`,`liftCurve2dToPlane`]){let t=s[e];t&&(s[e]=((n,...i)=>zw(n)?t(n,...i):r(e,n,...i)))}return s}var $w=`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 eT(e){let t=Fy();if(!t)throw Error(`manifold: ${e} unsupported on manifold kernel; no B-rep kernel registered`);return t}function tT(e){let t={};for(let e of $w)t[e]=(...t)=>eT(e)[e](...t);let n=Qw(e,()=>Fy());return Object.assign(t,n),t}function nT(e){return{sketchNew:()=>ky(`sketchNew`),sketchAddPoint:()=>ky(`sketchAddPoint`),sketchAddArc:()=>ky(`sketchAddArc`),sketchAddConstraint:()=>ky(`sketchAddConstraint`),sketchSolve:()=>ky(`sketchSolve`),sketchDof:()=>ky(`sketchDof`)}}function rT(e){return{projectEdges:()=>ky(`projectEdges`)}}function iT(e){return{dispose(e){let t=Ny(e);if(t){let e=Ly.get(t.node);e!==void 0&&(Fy()?.dispose(e),Ly.delete(t.node))}(e?.manifold)?.delete?.()},executeBatch:()=>ky(`executeBatch`),checkpoint:()=>ky(`checkpoint`),checkpointCount:()=>0,restoreCheckpoint:()=>ky(`restoreCheckpoint`),discardCheckpoint:()=>ky(`discardCheckpoint`)}}var aT={draft:30,standard:10,fine:3},oT=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?.(aT[e])}constructor(e){this.oc=e,Object.assign(this,Uy(e),Jy(e),gb(e),Cx(e),Yx(e),SS(e),AS(e),bC(e),WC(e),Tw(e),Aw(e),Fw(e),Lw(e),tT(e),nT(e),rT(e),iT(e))}};function sT(e){return import(e)}function cT(e){return`projectEdges`in e}function lT(e){return`sketchNew`in e&&`sketchDof`in e}var uT=new Map,dT=null,fT=null;function pT(e){mT(`manifold`,new oT(e))}function mT(e,t){uT.set(e,t),dT||=e,e===dT&&(fT=t)}function U(e){if(!e&&fT)return fT;let t=e??dT;if(!t)throw Error(`brepjs kernel not initialized. Call initFromOC() or registerKernel() before using the library.`);let n=uT.get(t);if(!n)throw Error(`brepjs: kernel '${t}' is not registered.`);return n}function hT(e){let t=U(e);if(!Eo(t))throw Error(`brepjs: current kernel does not support 2D operations.`);return t}function gT(){return dT}function _T(e,t){let n=dT;dT=e,fT=uT.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{dT=n,fT=n?uT.get(n)??null:null}}function vT(e){return U(e).capabilities}function yT(e,t){let n=Co();try{To(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{To(n),U().setQuality?.(n)}}var bT=new Map;function xT(e,t){bT.set(e,t)}function ST(e){return bT.get(e)}function CT(e,t){let n=bT.get(e);if(!n)throw Error(`withTier: no tier registered for "${e}". Call registerKernelTier("${e}", { kernel, quality }) first.`);return _T(n.kernel,()=>yT(n.quality,t))}function wT(e){Ho(),nl(),Fo(),Mc(),Nc(),Jc(),Yc();let t=new Rf(e);mT(`occt`,t),dT=`occt`,fT=t}function TT(){let e=U(),t=e.makeBox(1,1,1);try{e.dispose(t)}catch{}}async function ET(){if(dT)return dT;try{let{OcctKernel:e}=await sT(`occt-wasm`),t=await e.init();return mT(`occt-wasm`,Ia.fromKernel(t)),`occt-wasm`}catch{}try{return wT(await(await sT(`brepjs-opencascade`)).default()),`occt`}catch{}try{let e=await sT(`brepkit-wasm`);return typeof e.default==`function`&&await e.default(),mT(`brepkit`,new Oy(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 DT(){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 OT=Symbol;OT.dispose??=Symbol.for(`Symbol.dispose`),OT.asyncDispose??=Symbol.for(`Symbol.asyncDispose`);var kT=globalThis;kT.FinalizationRegistry||=(console.warn(`brepjs: FinalizationRegistry unavailable — garbage collection will not work`),class{register(e,t,n){}unregister(e){return!1}});var AT={liveHandles:0,peakHandles:0,gcCollected:0,scopeEnters:0,scopeExits:0};function jT(){return{...AT}}function MT(){AT.liveHandles=0,AT.peakHandles=0,AT.gcCollected=0,AT.scopeEnters=0,AT.scopeExits=0}function NT(){AT.liveHandles++,AT.liveHandles>AT.peakHandles&&(AT.peakHandles=AT.liveHandles)}function PT(){AT.liveHandles--}function FT(){AT.gcCollected++,AT.liveHandles--}var IT=new FinalizationRegistry(e=>{FT();try{e.delete()}catch{}});function LT(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,PT(),IT.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 NT(),IT.register(o,{delete:()=>{t.dispose(e)}},o),o}function RT(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,PT(),IT.unregister(n);try{e.delete()}catch{}}}};return NT(),IT.register(n,e,n),n}var zT=class{handles=[];constructor(){AT.scopeEnters++}register(e){return this.handles.push(()=>{try{e.delete()}catch{}}),e}track(e){return this.handles.push(()=>{try{e[Symbol.dispose]()}catch{}}),e}[Symbol.dispose](){AT.scopeExits++;for(let e=this.handles.length-1;e>=0;e--)this.handles[e]?.();this.handles.length=0}};function BT(e){try{var t=DT();return e(t.u(new zT))}catch(e){t.e=e}finally{t.d()}}function VT(e,t){IT.register(e,t,t)}function HT(e){IT.unregister(e)}function UT(e){try{var t=DT();return e(t.u(new zT))}catch(e){t.e=e}finally{t.d()}}async function WT(e){try{var t=DT();return await e(t.u(new zT))}catch(e){t.e=e}finally{t.d()}}function GT(e){return!e.disposed}function KT(e){return e.__is2D!==!0}function qT(e){return e.__is2D===!0}function JT(e){if(!KT(e))throw Error(`Expected 3D shape, got 2D`);return e}function YT(e){if(!qT(e))throw Error(`Expected 2D shape, got 3D`);return e}var XT=new WeakMap;function ZT(e,t){XT.set(e,t)}function QT(e,t){let n=XT.get(t);if(n!==void 0)return n;let r=e.shapeType(t);return XT.set(t,r),r}function $T(e){return QT(U(),e.wrapped)}function eE(e){return U().curveIsClosed(e.wrapped)}function tE(e){return U().isValid(e.wrapped)}function nE(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 rE(e){return U().isValid(e.wrapped)}function iE(e){return eE(e)?O(e):k(`Wire is not closed: start and end points do not coincide`)}function aE(e){return tE(e)?O(e):k(`Face orientation is inconsistent or face is invalid`)}function oE(e){return nE(e)?O(e):k(`Shell is not manifold: has free edges or is invalid`)}function sE(e){return rE(e)?O(e):k(`Solid failed BRepCheck validation`)}function cE(e){return U().surfaceType(e.wrapped)===`plane`}function lE(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 uE(e){return cE(e)?O(e):k(`Face is not planar: underlying surface is not a geometric plane`)}function dE(e){return lE(e)?O(e):k(`Wire is not planar: edges do not lie in a common plane`)}function fE(e,t){return t===`2D`&&(e.__is2D=!0),e}function pE(e,t){return fE(LT(e),t)}function mE(e,t){return fE(LT(e),t)}function hE(e,t){return fE(LT(e),t)}function gE(e,t){return fE(LT(e),t)}function _E(e){return fE(LT(e))}function vE(e){return fE(LT(e))}function yE(e){return fE(LT(e))}function bE(e,t){return fE(LT(e),t)}function xE(e){return $T(e)===`vertex`}function SE(e){return $T(e)===`edge`}function CE(e){return $T(e)===`wire`}function wE(e){return $T(e)===`face`}function TE(e){return $T(e)===`shell`}function EE(e){return $T(e)===`solid`}function DE(e){return $T(e)===`compound`}function OE(e){let t=$T(e);return t===`shell`||t===`solid`||t===`compsolid`?!0:t===`compound`?KT(e):!1}function kE(e){let t=$T(e);return t===`edge`||t===`wire`}function AE(e,t){let n=U(),r=QT(n,e),i=n.downcast(e,r);return r===`vertex`?pE(i,t):r===`edge`?mE(i,t):r===`wire`?hE(i,t):r===`face`?gE(i,t):r===`shell`?_E(i):r===`solid`?vE(i):r===`compsolid`?yE(i):bE(i,t)}function jE(e){return AE(e)}function ME(e,t){t.wrapped!==e&&U().dispose(e)}function W(e,t){let n=AE(e,t);return ME(e,n),n}function NE(e,t){let n=e.wrapped;if(e[Symbol.dispose](),n!==t){let e=U();e.dispose(n),e.dispose(t)}}function PE(e){U().dispose(e.wrapped),e[Symbol.dispose]()}function FE(e,t,n){ZT(e,t);let r=U().downcast(e,t);return t===`vertex`?pE(r,n):t===`edge`?mE(r,n):t===`wire`?hE(r,n):t===`face`?gE(r,n):t===`shell`?_E(r):t===`solid`?vE(r):t===`compsolid`?yE(r):bE(r,n)}function IE(e,t,n){let r=FE(e,t,n);return ME(e,r),r}function LE(e,t,n,r,i){let a={kind:e,code:t,message:n,cause:r};return i?{...a,suggestion:i}:a}var RE={KERNEL_OPERATION:(e,t,n,r)=>LE(`KERNEL_OPERATION`,e,t,n,r),VALIDATION:(e,t,n,r)=>LE(`VALIDATION`,e,t,n,r),TYPE_CAST:(e,t,n,r)=>LE(`TYPE_CAST`,e,t,n,r),SKETCHER_STATE:(e,t,n,r)=>LE(`SKETCHER_STATE`,e,t,n,r),MODULE_INIT:(e,t,n,r)=>LE(`MODULE_INIT`,e,t,n,r),COMPUTATION:(e,t,n,r)=>LE(`COMPUTATION`,e,t,n,r),IO:(e,t,n,r)=>LE(`IO`,e,t,n,r),QUERY:(e,t,n,r)=>LE(`QUERY`,e,t,n,r),UNSUPPORTED:(e,t,n,r)=>LE(`UNSUPPORTED`,e,t,n,r)};function zE(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`?fo(i):i,o=uo(t);return k(RE[r](t,`${n}: ${a}`,e,o))}}function BE(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`?fo(i):i,o=uo(t);return k(RE[r](t,`${n}: ${a}`,e,o))}}function VE(e,t,n,r=`KERNEL_OPERATION`){try{var i=DT();let a=i.u(new zT);return zE(()=>e(a),t,n,r)}catch(e){i.e=e}finally{i.d()}}function HE(e,t){let n=U().iterShapes(e,t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=IE(n[e],t);return r}var UE=new WeakMap;function WE(e){let t=UE.get(e);if(!t)return;UE.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 GE=new WeakSet;function KE(e){let t=e.wrapped,n=UE.get(t);return n||(n={},UE.set(t,n)),GE.has(e)||(GE.add(e),e.onDispose(()=>{WE(t)})),n}function qE(e){return UE.get(e.wrapped)}function JE(e){WE(e.wrapped)}function YE(e){let t=KE(e);if(t.edges)return t.edges;let n=HE(e.wrapped,`edge`);return t.edges=n,n}function XE(e){let t=KE(e);if(t.faces)return t.faces;let n=HE(e.wrapped,`face`);return t.faces=n,n}function ZE(e){let t=KE(e);if(t.wires)return t.wires;let n=HE(e.wrapped,`wire`);return t.wires=n,n}function QE(e){let t=KE(e);if(t.vertices)return t.vertices;let n=HE(e.wrapped,`vertex`);return t.vertices=n,n}function $E(e){let t=KE(e);if(t.solids)return t.solids;let n=HE(e.wrapped,`solid`);return t.solids=n,n}function eD(e){let t=KE(e);if(t.shells)return t.shells;let n=HE(e.wrapped,`shell`);return t.shells=n,n}function tD(e){let t=KE(e);if(t.compSolids)return t.compSolids;let n=HE(e.wrapped,`compsolid`);return t.compSolids=n,n}function*nD(e){for(let t of U().iterShapes(e.wrapped,`edge`))yield IE(t,`edge`)}function*rD(e){for(let t of U().iterShapes(e.wrapped,`face`))yield IE(t,`face`)}function*iD(e){for(let t of U().iterShapes(e.wrapped,`wire`))yield IE(t,`wire`)}function*aD(e){for(let t of U().iterShapes(e.wrapped,`vertex`))yield IE(t,`vertex`)}function*oD(e){for(let t of U().iterShapes(e.wrapped,`solid`))yield IE(t,`solid`)}function*sD(e){for(let t of U().iterShapes(e.wrapped,`shell`))yield IE(t,`shell`)}function*cD(e){for(let t of U().iterShapes(e.wrapped,`compsolid`))yield IE(t,`compsolid`)}function lD(e){let t=KE(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 uD(e){return QT(U(),e.wrapped)}function dD(e){let t=KE(e);if(t.surfaceType!==void 0)return t.surfaceType;let n=U().surfaceType(e.wrapped);return t.surfaceType=n,n}function fD(e){let t=KE(e);if(t.isValid!==void 0)return t.isValid;let n=U().isValid(e.wrapped);return t.isValid=n,n}function pD(e){return{kind:uD(e),faceCount:XE(e).length,edgeCount:YE(e).length,wireCount:ZE(e).length,vertexCount:QE(e).length,valid:fD(e),bounds:lD(e)}}function mD(e){return U().vertexPosition(e.wrapped)}var G=2147483647,hD=Math.PI/180,gD=180/Math.PI;function _D(e){return e.length===2?[e[0],e[1],0]:[e[0],e[1],e[2]]}function vD(e){return[e[0],e[1]]}var yD={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function bD(e){if(typeof e==`string`){let t=yD[e];if(!t)throw Error(`Unknown direction: ${e}`);return t}return e}function xD(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function SD(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function CD(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function wD(e){return[-e[0],-e[1],-e[2]]}function TD(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function ED(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 DD(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function OD(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function kD(e,t){return DD(SD(e,t))}function AD(e){let t=DD(e);return t<1e-10?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function jD(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 MD(e,t=1e-10){return OD(e)<t*t}function ND(e,t){let n=TD(e,t),r=DD(e),i=DD(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 PD(e,t,n){let r=SD(e,t),i=OD(n);return i<1e-20?e:SD(e,CD(n,TD(r,n)/i))}function FD(e,t,n){let r=AD(t),i=Math.cos(n),a=Math.sin(n),o=TD(e,r),s=ED(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 ID=e=>Math.round(e*1e3)/1e3;function LD(e){return`x: ${ID(e[0])}, y: ${ID(e[1])}, z: ${ID(e[2])}`}function RD(e,t=null,n=[0,0,1]){let r=AD(n);if(MD(r))throw Error(`Plane normal must be non-zero`);let i;if(t)i=AD(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?AD([l,u,d]):[1,0,0]}if(MD(i))throw Error(`Plane xDir must be non-zero`);let a=AD(ED(r,i));return{origin:e,xDir:i,yDir:a,zDir:r}}var zD={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 BD(e,t=[0,0,0]){let n=zD[e];if(!n)return k(F(`UNKNOWN_PLANE`,`Could not find plane ${e}`));let r;return r=typeof t==`number`?CD(n.normal,t):_D(t),O(RD(r,n.xDir,n.normal))}function VD(e,t){return typeof e==`string`?BD(e,t):O(e)}function HD(e,t){return e&&typeof e!=`string`?{...e}:j(VD(e??`XY`,t))}function UD(e,t){let[n,r]=t;return xD(xD(e.origin,CD(e.xDir,n)),CD(e.yDir,r))}function WD(e,t){return{...e,origin:xD(e.origin,t)}}function GD(e,t,n=[1,0,0]){let r=t*hD,i=FD(e.zDir,n,r),a=FD(e.xDir,n,r),o=AD(ED(i,a));return{origin:e.origin,xDir:a,yDir:o,zDir:i}}var KD={compound:0,solidCompound:1,solid:2,shell:3,face:4,wire:5,edge:6,vertex:7,shape:8},qD=e=>KD[e],JD={vertex:`vertex`,edge:`edge`,wire:`wire`,face:`face`,shell:`shell`,solid:`solid`,solidCompound:`compsolid`,compound:`compound`,shape:`compound`},YD=function*(e,t){let n=U().iterShapes(e,JD[t]);for(let e of n)yield e},XD=e=>U().isNull(e)?k(mo(`NULL_SHAPE`,`This shape has no type, it is null`)):O(e.ShapeType());function ZD(e){if(U().isNull(e))return k(mo(`NULL_SHAPE`,`This shape has no type, it is null`));try{return O(U().downcast(e))}catch(e){return k(mo(`NO_WRAPPER`,`Could not find a wrapper for this shape type`,e))}}function QD(e){if(U().isNull(e))return k(mo(`NULL_SHAPE`,`Cannot copy a null shape`));try{return O(U().copyShape(e))}catch(e){return k(mo(`NO_WRAPPER`,`Could not copy this shape`,e))}}function $D(e){return U().isNull(e)?k(mo(`NULL_SHAPE`,`Cannot cast a null shape`)):O(AE(e))}function eO(e){return U().shapeType(e.wrapped)===`compsolid`}function tO(e){return $D(U().fromBREP(e))}var nO={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 rO(e){return O(nO[dD(e)])}function iO(e){return j(rO(e))}function aO(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function oO(e){return AE(U().reverseShape(e.wrapped))}function sO(e){return U().uvBounds(e.wrapped)}function cO(e,t,n){let r=sO(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 lO(e,t){let n=_D(t);return U().uvFromPoint(e.wrapped,n)||[0,0]}function uO(e,t){let n=_D(t);try{let t=n,r=U().uvFromPoint(e.wrapped,t);if(!r)return k(mo(`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(mo(`PROJECTION_FAILED`,`Point projection failed: ${e instanceof Error?e.message:String(e)}`))}}function dO(e,t){let n,r;if(t)[n,r]=lO(e,t);else{let t=sO(e);n=.5*(t.uMin+t.uMax),r=.5*(t.vMin+t.vMax)}return U().surfaceNormal(e.wrapped,n,r)}function fO(e){return U().surfaceCenterOfMass(e.wrapped)}function pO(e){return U().getSurfaceAxis(e.wrapped)}function mO(e,t,n=1e-6){let[r,i]=lO(e,t);return U().classifyPointOnFace(e.wrapped,r,i,n)}function hO(e){return AE(U().outerWire(e.wrapped))}function gO(e){return AE(U().removeHolesFromFace(e.wrapped))}function _O(e){let t=hO(e);return Array.from(YD(e.wrapped,`wire`)).map(e=>AE(j(ZD(e)))).filter(e=>!U().isSame(e.wrapped,t.wrapped))}function vO(e,t){let n=KE(e),r=U(),i=new Map;for(let n of r.iterShapes(e.wrapped,`face`))i.set(r.hashCode(n,G),t),r.dispose(n);n.faceOrigins=i}function yO(e){return qE(e)?.faceOrigins}function bO(e,t,n){let r=new Map;for(let e of t){let t=yO(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=KE(n);e.faceOrigins=i}}var xO=100,SO=.985,CO=.1;function wO(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>xO)continue;let u=r-l/xO;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)<SO)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>CO)continue;let u=Math.max(0,i*i+a*a+c*c-l*l);u<o&&(o=u,s=n.origin)}return s}function TO(e,t){let n=new Map;for(let t of e){let e=yO(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=XE(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=yO(n);if(e)for(let i of XE(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=wO(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=KE(t);e.faceOrigins=i}}var EO=new WeakMap,DO=new WeakMap;function OO(e){return EO.has(e.wrapped)}function kO(e){let t=EO.get(e.wrapped);return t||(t=new Map,EO.set(e.wrapped,t)),t}function AO(e){let t=DO.get(e.wrapped);return t||(t=new Map,DO.set(e.wrapped,t)),t}function jO(e,t,n){let r=Array.isArray(t)?t:XE(e).filter(t),i=kO(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 MO(e,t){let n=EO.get(e.wrapped);if(!n)return[];let r=n.get(t);if(!r||r.size===0)return[];let i=[];for(let t of XE(e)){let e=U().hashCode(t.wrapped,G);r.has(e)&&i.push(t)}return i}function NO(e){let t=new Map,n=EO.get(e.wrapped);if(!n)return t;let r=XE(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 PO(e,t,n){return AO(e).set(t,n),e}function FO(e,t){return DO.get(e.wrapped)?.get(t)}function IO(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function LO(e,t,n){let r=kO(n);for(let i of t){let t=EO.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)IO(r,t,e)}let o=DO.get(i.wrapped);if(o){let e=AO(n);for(let[t,n]of o)e.has(t)||e.set(t,n)}}}var RO=new WeakMap,zO=new WeakMap;function BO(e){return RO.has(e.wrapped)||zO.has(e.wrapped)}function VO(e){let t=zO.get(e.wrapped);return t||(t=new Map,zO.set(e.wrapped,t)),t}function HO(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 UO(e,t){return RO.set(e.wrapped,HO(t)),e}function WO(e,t,n){let r=HO(n),i=VO(e);for(let e of t)i.set(U().hashCode(e.wrapped,G),r);return e}function GO(e){return RO.get(e.wrapped)}function KO(e,t){let n=zO.get(e.wrapped);if(n)return n.get(U().hashCode(t.wrapped,G))}function qO(e,t,n){for(let e of t){let t=RO.get(e.wrapped);if(t){RO.set(n.wrapped,t);break}}let r=VO(n);for(let n of t){let t=zO.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 JO(e){return yO(e)!==void 0||OO(e)||BO(e)}function YO(e){if(!e.some(JO))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 XO(e,t,n){bO(e,t,n),LO(e,t,n),qO(e,t,n)}function ZO(e,t){TO(e,t)}function QO(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);XO({modified:a,generated:new Map,deleted:new Set},[e],t)}function $O(e,t){let n=YO([e]),{shape:r,evolution:i}=U().translateWithHistory(e.wrapped,t[0],t[1],t[2],n,G),a=W(r);return XO(i,[e],a),a}function ek(e,t,n=[0,0,0],r=[0,0,1]){let i=YO([e]),{shape:a,evolution:o}=U().rotateWithHistory(e.wrapped,t*hD,i,G,r,n),s=W(a);return XO(o,[e],s),s}function tk(e,t=[0,1,0],n=[0,0,0]){let r=YO([e]),{shape:i,evolution:a}=U().mirrorWithHistory(e.wrapped,n,t,r,G),o=W(i);return XO(a,[e],o),o}function nk(e,t,n=[0,0,0]){let r=YO([e]),{shape:i,evolution:a}=U().scaleWithHistory(e.wrapped,n,t,r,G),o=W(i);return XO(a,[e],o),o}function rk(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(nk(e,c[0])):k(F(N.VALIDATION_FAILED,`resize: non-uniform scaling is not supported (WASM build lacks BRepBuilderAPI_GTransform).`,void 0,void 0,`Use auto: true to scale proportionally, or set all three dimensions to achieve uniform scaling.`))}function ik(e){if(`linear`in e)return O({linear:e.linear,translation:e.translation});let[t,n,r,i]=e,a=1e-10;return Math.abs(i[0])>a||Math.abs(i[1])>a||Math.abs(i[2])>a||Math.abs(i[3]-1)>a?k(F(N.VALIDATION_FAILED,`applyMatrix: invalid bottom row [${String(i[0])}, ${String(i[1])}, ${String(i[2])}, ${String(i[3])}]. Must be [0, 0, 0, 1] for an affine transform.`)):O({linear:[t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]],translation:[t[3],n[3],r[3]]})}function ak(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 ok(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 sk(e,t){let n=ik(t);if(!n.ok)return n;let{linear:r,translation:i}=n.value,a=ak(r);if(Math.abs(a)<1e-12)return k(F(N.VALIDATION_FAILED,`applyMatrix: singular matrix (determinant ≈ 0). Cannot apply a non-invertible transform.`));if(ok(r)){let t=YO([e]),{shape:n,evolution:a}=U().generalTransformWithHistory(e.wrapped,r,i,!0,t,G),o=W(n);return XO(a,[e],o),O(o)}let o=W(U().generalTransformNonOrthogonal(e.wrapped,r,i));return ZO([e],o),O(o)}function ck(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 lk(e,t){let{trsf:n,cleanup:r}=ck(`type`in t?[t]:t),i;try{i=W(U().locate(e.wrapped,n))}finally{r()}return JO(e)&&QO(e,i),i}function uk(e,t){let n=YO([e]),{shape:r,evolution:i}=U().applyComposedTransformWithHistory(e.wrapped,t.trsf,n,G),a=W(r);return XO(i,[e],a),a}function dk(e){return zE(()=>U().copyShape(e.wrapped),N.CLONE_FAILED,`Failed to clone shape`)}function fk(e){return BE(()=>U().toBREP(e.wrapped),N.TO_BREP_FAILED,`Failed to serialize shape to BREP`)}function pk(e){return U().hashCode(e.wrapped,G)}function mk(e){return U().isNull(e.wrapped)}function hk(e,t){return U().isSame(e.wrapped,t.wrapped)}function gk(e,t){return U().isEqual(e.wrapped,t.wrapped)}function _k(e){return zE(()=>U().simplify(e.wrapped),N.SIMPLIFY_FAILED,`Failed to simplify shape`)}function vk(e){return U().curveType(e.wrapped)}function yk(e){let[t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function bk(e){let[,t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function xk(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curvePointAtParam(e.wrapped,i)}function Sk(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curveTangent(e.wrapped,i).tangent}function Ck(e){return U().length(e.wrapped)}function wk(e){if(vk(e)!==`CIRCLE`)return null;let t=xk(e,0),n=xk(e,1/3),r=xk(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 Tk(e){return U().curveIsClosed(e.wrapped)}function Ek(e){return U().curveIsPeriodic(e.wrapped)}function Dk(e){return U().curvePeriod(e.wrapped)}function Ok(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function kk(e){return W(U().reverseShape(e.wrapped))}function Ak(e,t={}){if(e.length<2)return k(mo(`INTERPOLATE_MIN_POINTS`,`Interpolation requires at least 2 points`));try{let n=W(U().interpolatePoints(e,t));return SE(n)?O(n):(PE(n),k(mo(`INTERPOLATE_NOT_EDGE`,`Interpolation did not produce an edge`)))}catch(e){return k(mo(`INTERPOLATE_FAILED`,`Interpolation failed: ${e instanceof Error?e.message:String(e)}`))}}function jk(e,t={}){if(e.length<2)return k(mo(`APPROXIMATE_MIN_POINTS`,`Approximation requires at least 2 points`));try{let n=W(U().approximatePoints(e,t));return SE(n)?O(n):(PE(n),k(mo(`APPROXIMATE_NOT_EDGE`,`Approximation did not produce an edge`)))}catch(e){return k(mo(`APPROXIMATE_FAILED`,`Approximation failed: ${e instanceof Error?e.message:String(e)}`))}}function Mk(e,t,n=`arc`){let r=W(U().offsetWire2D(e.wrapped,t,{arc:`arc`,intersection:`intersection`,tangent:`tangent`,chamfer:`intersection`}[n]));return CE(r)?O(r):(PE(r),k(mo(`OFFSET_NOT_WIRE`,`Offset did not produce a Wire`)))}function Nk(e,t,n,r=!1){return`${e}:${t}:${n}:${r}`}function Pk(e,t){return`edge:${e}:${t}`}var Fk=new WeakMap,Ik=new WeakMap;function Lk(e,t){let n=Fk.get(e);if(n)return n.get(t)}function Rk(e,t,n){let r=Fk.get(e);r||(r=new Map,Fk.set(e,r)),r.set(t,n)}function zk(e,t){let n=Ik.get(e);if(n)return n.get(t)}function Bk(e,t,n){let r=Ik.get(e);r||(r=new Map,Ik.set(e,r)),r.set(t,n)}function Vk(){Fk=new WeakMap,Ik=new WeakMap}function Hk(){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 Uk(e,t={}){let n=wo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,skipNormals:a=!1,includeUVs:o=!1,cache:s=!0,signal:c}=t;c?.throwIfAborted();let l=Nk(r,i,a,o);if(s){let t=Lk(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=yO(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&&Rk(e.wrapped,l,f),f}function Wk(e,t={}){let n=wo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,cache:a=!0}=t,o=Pk(r,i);if(a){let t=zk(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&&Bk(e.wrapped,o,c),c}function Gk(e,t){return e instanceof Error&&e.message.startsWith(`${t} export failed`)?_o(`${t}_EXPORT_FAILED`,`Failed to write ${t} file`,e):e instanceof WebAssembly.RuntimeError?_o(`${t}_EXPORT_CRASHED`,`${t} export crashed the kernel (${e.message}); the shape likely contains geometry the ${t} writer cannot serialize`,e):_o(`${t}_FILE_READ_ERROR`,`Failed to read exported ${t} file`,e)}function Kk(e){let t;try{t=$E(e)}catch{return``}if(t.length<=1)return``;let n=[];return t.forEach((e,t)=>{try{lD(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 qk(e,t){try{return lD(e),null}catch(n){if(n instanceof TypeError)throw n;return _o(`${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${Kk(e)}`,n)}}function Jk(e){let t=qk(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(Gk(e,`STEP`))}}function Yk(e,t={}){let n=wo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,binary:a=!1}=t,o=qk(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(Gk(e,`STL`))}}function Xk(e){try{let t=U().exportIGES([e.wrapped]);return O(new Blob([t],{type:`application/iges`}))}catch(e){return k(_o(`IGES_EXPORT_FAILED`,`Failed to write IGES file`,e))}}function Zk(e,t){let n=t?.coarseTolerance??.5,r=t?.fineTolerance??.05,i=t?.angularTolerance??.5;return{coarse:Uk(e,{tolerance:n,angularTolerance:i}),fine:Uk(e,{tolerance:r,angularTolerance:i*.2})}}function Qk(e){let t=lD(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 $k(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)*Qk(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 eA(e,t,n){return Math.min(e/t*n,1)}function tA(e,t={}){let n=t.angularTolerance??wo().angularTolerance,r=t.cache??!0,i=$k(e,t),a=Math.min(...i);return i.map(i=>{let o=eA(i,a,n);return{tolerance:i,angularTolerance:o,mesh:Uk(e,{tolerance:i,angularTolerance:o,cache:r,...t.signal?{signal:t.signal}:{}})}})}function nA(){return new Promise(e=>{setTimeout(e,0)})}async function rA(e,t={}){let n=t.angularTolerance??wo().angularTolerance,r=t.cache??!0,i=t.meshLevel??((e,n,i)=>Uk(e,{tolerance:n,angularTolerance:i,cache:r,...t.signal?{signal:t.signal}:{}})),a=$k(e,t),o=Math.min(...a),s=[];for(let[r,c]of a.entries()){if(t.signal?.aborted)break;let l=eA(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 nA()}return s}function iA(e,t,n){if(t<0||t>=e.length)throw Error(n??`Index ${t} out of bounds (length ${e.length})`);return e[t]}function aA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[0]}function oA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[e.length-1]}function sA(e){return Array.from(Array(e).keys())}function cA(e){return sA(Math.min(...e.map(e=>e.length))).map(t=>e.map(e=>e[t]))}function lA(e,t){return mE(U().makeLineEdge([...e],[...t]))}function uA(e,t=[0,0,0],n=[0,0,1]){return mE(U().makeCircleEdge([...t],[...n],e))}function dA(e,t,n=[0,0,0],r=[0,0,1],i){return t>e?k(F(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(mE(U().makeEllipseEdge([...n],[...r],e,t,i?[...i]:void 0)))}function fA(e,t,n,r=[0,0,0],i=[0,0,1],a=!1){return hE(U().makeHelixWire(e,t,n,[...r],[...i],a))}function pA(e,t,n){return mE(U().makeArcEdge([...e],[...t],[...n]))}function mA(e,t,n,r,i=[0,0,0],a=[0,0,1],o){return t>e?k(F(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(mE(U().makeEllipseArc([...i],[...a],e,t,n,r,o?[...o]:void 0)))}function hA(e,{tolerance:t=.001,smoothing:n=null,degMax:r=6,degMin:i=1}={}){try{let a=e.map(e=>[...e]);return O(mE(U().approximatePoints(a,{tolerance:t,degMin:i,degMax:r,smoothing:n})))}catch(e){return k(P(`BSPLINE_FAILED`,`B-spline approximation failed`,e))}}function gA(e,{periodic:t=!1,tolerance:n=1e-7}={}){try{let r=e.map(e=>[...e]);return O(mE(U().interpolatePoints(r,{periodic:t,tolerance:n})))}catch(e){return k(P(`BSPLINE_INTERP_FAILED`,`B-spline interpolation failed`,e))}}function _A(e){if(e.length<2)return k(F(`BEZIER_MIN_POINTS`,`Need at least 2 points for a Bezier curve, got ${e.length}`,void 0,{pointCount:e.length}));let t=e.map(e=>[...e]);return O(mE(U().makeBezierEdge(t)))}function vA(e,t,n){return mE(U().makeTangentArc([...e],[...t],[...n]))}function yA(e){try{return O(hE(U().makeWireFromMixed(e.map(e=>e.wrapped))))}catch(e){return k(P(`WIRE_BUILD_FAILED`,`Failed to build the wire: ${e instanceof Error?e.message:`unknown error`}`))}}function bA(e,t){try{let n=U().makeFace(e.wrapped,!0);if(t&&t.length>0){let e=wA(gE(n),t);return cE(e)?O(e):k(F(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}let r=gE(n);return cE(r)?O(r):k(F(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}catch(e){return k(P(`FACE_BUILD_FAILED`,`Failed to build the face. Your wire might be non planar.`,e))}}function xA(e){return bA(hO(e))}function SA(e,t){return gE(U().makeFaceOnSurface(e.wrapped,t.wrapped))}function CA(e){try{return Va($D(U().makeNonPlanarFace(e.wrapped)),e=>wE(e)?O(e):k(P(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`)))}catch(e){return k(P(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`,e))}}function wA(e,t){return gE(U().addHolesInFace(e.wrapped,t.map(e=>e.wrapped)))}function TA(e){return e.length<3?k(F(`POLYGON_MIN_POINTS`,`You need at least 3 points to make a polygon`)):Va(yA(cA([e,[...e.slice(1),e[0]]]).map(([e,t])=>lA(e,t))),e=>bA(e))}function EA(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function DA(e,t,n,r,i){let a=AE(e);if(!OE(a)){let o=$T(a).toUpperCase();return ME(e,a),PE(a),k(mo(t,`${n}. Got ${o} instead.`,void 0,i?{diagnostics:i}:void 0,r))}return ME(e,a),O(a)}function OA(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=EA(e,`fuse: first operand`);if(A(c))return c;let l=EA(t,`fuse: second operand`);if(A(l))return l;if(!s)return DA(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);let u=YO([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),DA(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=DA(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&&XO(f,[e,t],m.value),m}function kA(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;let c=EA(e,`cut: base`);if(A(c))return c;let l=EA(t,`cut: tool`);if(A(l))return l;if(!s)return DA(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);let u=YO([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),DA(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=DA(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&&XO(f,[e,t],m.value),m}function AA(e,t,{simplify:n=!1,signal:r,fuzzyValue:i,unsafe:a,trackEvolution:o=!0}={}){if(r?.aborted)throw r.reason;let s=EA(e,`intersect: first operand`);if(A(s))return s;let c=EA(t,`intersect: second operand`);if(A(c))return c;if(!o)return DA(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);let l=YO([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),DA(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=DA(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&&XO(d,[e,t],p.value),p}function jA(e,t,n,r,i,a,o,s){if(o?.aborted)throw o.reason;let c=n-t;if(c===1)return O(iA(e,t));if(c===2)return OA(iA(e,t),iA(e,t+1),{optimisation:r,simplify:!1,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}});let l=t+Math.ceil(c/2),u=jA(e,t,l,r,i,a,o,s);if(A(u))return u;let d=jA(e,l,n,r,i,a,o,s);return A(d)?d:OA(u.value,d.value,{optimisation:r,simplify:i,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}})}function MA(e,{optimisation:t=`none`,simplify:n=!1,strategy:r=`native`,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;if(e.length===0)return k(F(`FUSE_ALL_EMPTY`,`fuseAll requires at least one shape`));if(e.length===1)return O(aA(e));for(let t=0;t<e.length;t++){let n=EA(iA(e,t),`fuseAll: shape at index ${t}`);if(A(n))return n}if(r===`native`){let o=DA(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&&ZO(e,o.value),o}return jA(e,0,e.length,t,n,s,i,a)}function NA(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=EA(e,`cutAll: base`);if(A(c))return c;for(let e=0;e<t.length;e++){let n=EA(iA(t,e),`cutAll: tool at index ${e}`);if(A(n))return n}let l=[e,...t],u=DA(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&&ZO(l,u.value),u}function PA(e,t){let n=U(),r=CD(e.xDir,t),i=CD(e.yDir,t),a=CD(e.xDir,-t),o=CD(e.yDir,-t),s=e.origin,c=[...xD(xD(s,a),o)],l=[...xD(xD(s,r),o)],u=[...xD(xD(s,r),i)],d=[...xD(xD(s,a),i)],f=[n.makeLineEdge(c,l),n.makeLineEdge(l,u),n.makeLineEdge(u,d),n.makeLineEdge(d,c)],p=n.makeWire(f),m=n.makeFace(p,!0);for(let e of f)e.delete();return p.delete(),m}function FA(e,t,{approximation:n=!0,planeSize:r=1e4}={}){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`section: shape is a null shape`));let i=PA(typeof t==`string`?j(VD(t)):t,r);try{return O(W(U().section(e.wrapped,i,n)))}catch(e){let n=e instanceof Error?e.message:String(e),r=typeof t==`string`?t:`custom`;return k(P(`SECTION_FAILED`,`Section with ${r} plane failed: ${n}`,e,{operation:`section`,plane:r},`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`))}finally{i.delete()}}function IA(e){let t=U(),n=new Map,r=new Map;for(let i of e){let e=QE(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 LA(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 RA(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=LA(i,t,n);for(;o;)e===0?r.push(o.edge):r.unshift(o.edge),i=o.nextTip,o=LA(i,t,n)}return r}function zA(e){let t=U(),n=IA(e),r=new Set,i=[];for(let a of e){if(r.has(a))continue;let e=RA(a,n,r);try{let n=t.makeWire(e.map(e=>e.wrapped));i.push(W(n))}catch{}}return i}function BA(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 VA(e,t,n={}){let r=FA(e,t,n);if(!r.ok)return r;let i=ZE(r.value);if(i.length===0){let e=YE(r.value);if(e.length===0)return k(P(`SECTION_FAILED`,`sectionToFace: section produced no geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));i.push(...zA(e))}if(i.length===0)return k(P(`SECTION_FAILED`,`sectionToFace: section produced no usable geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));let a=BA(i),o=iA(i,a),s=i.filter((e,t)=>t!==a);return bA(o,s.length>0?s:void 0)}function HA(e,t){if(t.length===0)return O(e);if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`split: shape is a null shape`));for(let e=0;e<t.length;e++)if(U().isNull(iA(t,e).wrapped))return k(F(N.NULL_SHAPE_INPUT,`splitShape: tool at index ${e} is a null shape`));try{return O(W(U().split(e.wrapped,t.map(e=>e.wrapped))))}catch(e){let n=e instanceof Error?e.message:String(e);return k(P(`SPLIT_FAILED`,`Split operation failed on ${t.length} tool(s): ${n}`,e,{operation:`split`,toolCount:t.length},`The splitting tools may not intersect the shape. Ensure tools cross through the shape's interior.`))}}function UA(e,t,n={}){let r=[];for(let i of t){let t=FA(e,i,n);if(A(t))return t;r.push(t.value)}return O(r)}function WA(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 GA(e,t,n);if(o===null)return k(P(`BOOLEAN_PIPELINE_FAILED`,`Boolean pipeline returned null shape`));let s=W(o);return OE(s)?O(s):(PE(s),k(mo(`BOOLEAN_PIPELINE_NOT_3D`,`Pipeline result is not a 3D shape`)))}catch(e){return k(P(`BOOLEAN_PIPELINE_FAILED`,e instanceof Error?e.message:String(e)))}}function GA(e,t,n){let r=e,i={...n?.optimisation?{optimisation:n.optimisation}:{},unsafe:!0};for(let e of t){let t=e.op===`fuse`?OA(r,e.tool,i):e.op===`cut`?kA(r,e.tool,i):AA(r,e.tool,i);if(A(t))return t;r=j(t)}return O(r)}function KA(e){return j($D(j(ZD(U().sew(e.map(e=>e.wrapped))))))}function qA(e,t=!1){let n=KA(e);return!t&&!TE(n)?k(mo(`WELD_NOT_SHELL`,`Could not make a shell from faces and shells`)):O(n)}function JA(e,t,n=[0,0,0],r=[0,0,1]){return vE(U().makeCylinder(e,t,[...n],[...r]))}function YA(e){return vE(U().makeSphere(e))}function XA(e,t,n,r=[0,0,0],i=[0,0,1]){return vE(U().makeCone(e,t,n,[...r],[...i]))}function ZA(e,t,n=[0,0,0],r=[0,0,1]){return vE(U().makeTorus(e,t,[...n],[...r]))}function QA(e,t,n){return vE(U().makeEllipsoid(e,t,n))}function $A(e){return pE(U().makeVertex(e[0],e[1],e[2]))}function ej(e,t,n=1e-6){return Va(ZD(U().offset(e.wrapped,t,n)),e=>Va($D(e),e=>OE(e)?O(e):k(mo(`OFFSET_NOT_3D`,`Could not offset to a 3d shape`))))}function tj(e){return bE(U().makeCompound(e.map(e=>e.wrapped)))}function nj(e){let t=KA(e);return Va($D(U().solidFromShell(t.wrapped)),e=>EE(e)?O(e):k(mo(`SOLID_BUILD_FAILED`,`Could not make a solid of faces and shells`)))}function rj(e){return{position:e.vertices,normal:e.normals,index:e.triangles}}function ij(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 aj(e){return{position:e.lines}}function oj(e,t){return{coarse:rj(e.coarse),fine:rj(e.fine),coarseDistance:t?.coarse??50,fineDistance:t?.fine??0}}function sj(e,t){let n=t?.step??50,r=t?.distances;if(r&&r.length!==e.length)throw Error(`toLODGeometryLevels: distances must have one entry per level (got ${r.length} for ${e.length} levels)`);let i=e.length-1;return e.map((e,t)=>({geometry:rj(e.mesh),distance:r?.[t]??(i-t)*n}))}function cj(e,t,n,r){if(t.length===0)return k(F(`CHAMFER_ANGLE_NO_EDGES`,`chamferDistAngle requires at least one edge`,void 0,{edgeCount:0}));if(n<=0)return k(F(`CHAMFER_ANGLE_BAD_DISTANCE`,`distance must be positive, got ${n}`,void 0,{distance:n}));if(r<=0||r>=90)return k(F(`CHAMFER_ANGLE_BAD_ANGLE`,`angleDeg must be in range (0, 90), got ${r}`,void 0,{angleDeg:r}));let i;try{let a=U(),o=t.map(e=>e.wrapped);i=a.chamferDistAngle(e.wrapped,o,n,r)}catch(e){return k(P(`CHAMFER_ANGLE_FAILED`,`chamferDistAngle kernel call failed: ${e instanceof Error?e.message:String(e)}`,e,{distance:n,angleDeg:r,edgeCount:t.length}))}let a=ZD(i);if(A(a))return U().dispose(i),a;let o=W(a.value);return ME(i,o),OE(o)?O(o):(PE(o),k(mo(`CHAMFER_ANGLE_NOT_3D`,`chamferDistAngle did not produce a 3D shape`)))}function lj(e){let t=U();return t.getNurbsCurveData?t.getNurbsCurveData(e.wrapped):null}function uj(e){let t=U();return t.getNurbsSurfaceData?t.getNurbsSurfaceData(e.wrapped):null}var dj={cut:kA,cutAll:NA,fuse:OA,fuseAll:MA};function fj(e){return{totalInputs:e.totalInputs,batchAttempts:e.batchAttempts,batchSucceeded:e.batchSucceeded,singletonFallbacks:e.singletonFallbacks,failedInputs:[...e.failedInputs].sort((e,t)=>e-t)}}function pj(e,t,n={}){return mj(dj,e,t,n)}function mj(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=hj(e,t,n,0,r,i);return A(a)?a:O({shape:a.value,telemetry:fj(i)})}function hj(e,t,n,r,i,a){if(n.length===0)return O(t);if(n.length===1)return gj(e,t,n,r,i,a);a.batchAttempts++;let o=xj(()=>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=hj(e,t,n.slice(0,s),r,i,a);return c.ok?hj(e,c.value,n.slice(s),r+s,i,a):c}function gj(e,t,n,r,i,a){a.singletonFallbacks++;let o=aA(n),s=xj(()=>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 _j(e,t={}){return vj(dj,e,t)}function vj(e,t,n={}){if(n.signal?.aborted)throw n.signal.reason;if(t.length===0)return k(F(N.FUSE_ALL_EMPTY,`fuseAllBisect requires at least one shape`));let r={totalInputs:t.length,batchAttempts:0,batchSucceeded:0,singletonFallbacks:0,failedInputs:new Set},i=yj(e,t,0,n,r);return A(i)?i:O({shape:i.value,telemetry:fj(r)})}function yj(e,t,n,r,i){if(t.length===1)return O(aA(t));i.batchAttempts++;let a=xj(()=>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 bj(e,yj(e,t.slice(0,o),n,r,i),yj(e,t.slice(o),n+o,r,i),t,n,o,r,i)}function bj(e,t,n,r,i,a,o,s){if(t.ok&&n.ok){s.singletonFallbacks++;let c=xj(()=>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 xj(e){try{return e()}catch{return null}}function Sj(e,t,n){return U().checkBoolean(e.wrapped,t.wrapped,n)}function Cj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function wj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Tj(e,t,n,r){let i=AE(e);if(!OE(i)){let a=$T(i).toUpperCase();return ME(e,i),PE(i),k(mo(t,`${n}. Got ${a} instead.`,void 0,void 0,r))}return ME(e,i),O(i)}function Ej(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>r.get(U().hashCode(e,2147483647))??1}}function Dj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Cj(e,`fuseWithEvolution: first operand`);if(A(o))return o;let s=Cj(t,`fuseWithEvolution: second operand`);if(A(s))return s;let c=YO([e,t]),{shape:l,evolution:u}=U().fuseWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Tj(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?(XO(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function Oj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Cj(e,`cutWithEvolution: base`);if(A(o))return o;let s=Cj(t,`cutWithEvolution: tool`);if(A(s))return s;let c=YO([e,t]),{shape:l,evolution:u}=U().cutWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Tj(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?(XO(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function kj(e,t,{simplify:n=!1,signal:r,fuzzyValue:i}={}){if(r?.aborted)throw r.reason;let a=Cj(e,`intersectWithEvolution: first operand`);if(A(a))return a;let o=Cj(t,`intersectWithEvolution: second operand`);if(A(o))return o;let s=YO([e,t]),{shape:c,evolution:l}=U().intersectWithHistory(e.wrapped,t.wrapped,s,G,{simplify:n,fuzzyValue:i}),u=Tj(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?(XO(l,[e,t],u.value),O({shape:u.value,evolution:l})):u}function Aj(e,t,n){let r=wj(e,`filletWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(F(`INVALID_FILLET_RADIUS`,`Fillet radius must be positive`,void 0,void 0,`Provide a positive radius value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(F(`INVALID_FILLET_RADIUS`,`Fillet radii must both be positive`,void 0,void 0,`Both radius values must be greater than 0`));let i=t??YE(e);if(i.length===0)return k(F(N.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));try{let t,r;if(typeof n==`function`){let e=Ej(i,n);if(!e)return k(F(N.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=YO([e]),{shape:o,evolution:s}=U().filletWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return OE(c)?(XO(s,[e],c),O({shape:c,evolution:s})):(PE(c),k(P(N.FILLET_NOT_3D,`Fillet result is not a 3D shape`)))}catch(e){return k(P(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:i.length,radius:n}))}}function jj(e,t,n){let r=wj(e,`chamferWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(F(`INVALID_CHAMFER_DISTANCE`,`Chamfer distance must be positive`,void 0,void 0,`Provide a positive distance value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(F(`INVALID_CHAMFER_DISTANCE`,`Chamfer distances must both be positive`,void 0,void 0,`Both distance values must be greater than 0`));let i=t??YE(e);if(i.length===0)return k(F(N.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=Ej(i,n);if(!e)return k(F(N.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=YO([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return OE(c)?(XO(s,[e],c),O({shape:c,evolution:s})):(PE(c),k(P(N.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)))}catch(e){return k(P(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:i.length,distance:n}))}}function Mj(e,t,n,r=.001){let i=wj(e,`shellWithEvolution: shape`);if(A(i))return i;if(n<=0)return k(F(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(F(`NO_FACES`,`At least one face must be specified for shell`));try{let i=YO([e]),{shape:a,evolution:o}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,i,G,r),s=W(a);return OE(s)?(XO(o,[e],s),O({shape:s,evolution:o})):(PE(s),k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}catch(e){return k(P(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function Nj(e,t,n){try{let r=W(U().positionOnCurve(e.wrapped,t.wrapped,n));return OE(r)?O(r):(PE(r),k(P(N.POSITION_ON_CURVE_FAILED,`positionOnCurve did not produce a 3D shape`)))}catch(e){return k(P(N.POSITION_ON_CURVE_FAILED,`Failed to position shape on curve at param ${n}`,e))}}function Pj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Fj(e,t){if(typeof e==`number`&&e<=0)return k(F(t.code,t.scalar,void 0,void 0,t.scalarHint));if(Array.isArray(e)&&(e[0]<=0||e[1]<=0))return k(F(t.code,t.pair,void 0,void 0,t.pairHint))}function Ij(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 Lj(e,t,n,r,i){let a=W(t);return OE(a)?(XO(e,n,a),O(a)):(PE(a),k(P(r,i)))}function Rj(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 zj(e,t){let n=Pj(e,`thicken: shape`);if(A(n))return n;try{let n=YO([e]),{shape:r,evolution:i}=U().thickenWithHistory(e.wrapped,t,n,G),a=W(r);return XO(i,[e],a),O(a)}catch(e){return k(P(`THICKEN_FAILED`,`Thicken operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function Bj(e,t,n){let r=Pj(e,`fillet: shape`);if(A(r))return r;let i=Fj(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??YE(e);if(a.length===0)return k(F(N.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));if(typeof n==`function`){let e=Ij(a,n);return e?O({filteredEdges:e.edges,kernelRadius:e.kernelParam,selectedCount:a.length}):k(F(N.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`))}return O({filteredEdges:[...a],kernelRadius:n,selectedCount:a.length})}function Vj(e,t,n,{trackEvolution:r=!0}={}){let i=Bj(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 OE(n)?O(n):k(P(N.FILLET_NOT_3D,`Fillet result is not a 3D shape`))}let n=YO([e]),{shape:i,evolution:s}=U().filletWithHistory(e.wrapped,t,o,n,G);return Lj(s,i,[e],N.FILLET_NOT_3D,`Fillet result is not a 3D shape`)}catch(e){return k(P(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:s,radius:n}))}}function Hj(e,t,n){let r=Pj(e,`chamfer: shape`);if(A(r))return r;let i=Fj(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??YE(e);if(a.length===0)return k(F(N.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=Ij(a,n);if(!e)return k(F(N.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...a],r=n;let i=YO([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,i,G);return Lj(s,o,[e],N.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)}catch(e){return k(P(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:a.length,distance:n}))}}function Uj(e,t,n,r=.001,{trackEvolution:i=!0}={}){let a=Pj(e,`shell: shape`);if(A(a))return a;if(n<=0)return k(F(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(F(`NO_FACES`,`At least one face must be specified for shell`));try{if(!i){let i=W(U().shell(e.wrapped,t.map(e=>e.wrapped),n,r));return OE(i)?O(i):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}let a=YO([e]),{shape:o,evolution:s}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,a,G,r),c=W(o);return OE(c)?(XO(s,[e],c),O(c)):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}catch(e){return k(P(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function Wj(e,t,n=1e-6){let r=Pj(e,`offset: shape`);if(A(r))return r;if(Math.abs(t)<1e-10)return k(F(`ZERO_OFFSET`,`Offset distance cannot be zero`));try{let r=YO([e]),{shape:i,evolution:a}=U().offsetWithHistory(e.wrapped,t,r,G,n),o=W(i);return OE(o)?(XO(a,[e],o),O(o)):k(P(`OFFSET_RESULT_NOT_3D`,`Offset result is not a 3D shape`))}catch(e){return k(P(`OFFSET_FAILED`,`Offset operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function Gj(e,t,n){let r=Pj(e,`draft: shape`);if(A(r))return r;if(typeof n==`number`){if(Math.abs(n)<1e-10)return k(F(N.DRAFT_INVALID_ANGLE,`Draft angle cannot be zero`,void 0,void 0,`Provide a non-zero angle in degrees`));if(Math.abs(n)>=90)return k(F(N.DRAFT_INVALID_ANGLE,`Draft angle must be between -90 and 90 degrees (exclusive)`,void 0,void 0,`Typical draft angles are 1-5 degrees for injection molding`))}if(t.length===0)return k(F(N.DRAFT_NO_FACES,`No faces specified for draft`,void 0,void 0,`Select at least one face to apply the draft angle to`))}function Kj(e,t,n,r,i){let a=Gj(e,t,i);if(a)return a;try{let{filteredFaces:a,kernelAngle:o}=Rj(t,i);if(a.length===0)return k(F(N.DRAFT_NO_FACES,`No faces with valid draft angle`,void 0,void 0,`Check that the angle callback returns non-zero values between -90 and 90 degrees`));let s=YO([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 Lj(l,c,[e],N.DRAFT_NOT_3D,`Draft result is not a 3D shape`)}catch(e){let n=e instanceof Error?e.message:String(e);return k(P(N.DRAFT_FAILED,`Draft operation failed: ${n}`,e,{operation:`draft`,faceCount:t.length,angle:i}))}}function qj(e,t,n){if(n.length===0)return k(F(N.VARIABLE_FILLET_FAILED,`radii must contain at least one radius spec`));for(let e of n)if(e.radius<=0)return k(F(N.VARIABLE_FILLET_FAILED,`All radius values must be positive`));let r=U();try{let i=JSON.stringify({edge:r.hashCode(t.wrapped,G),radii:n.map(e=>({param:e.param,radius:e.radius}))}),a=W(r.filletVariable(e.wrapped,i));return OE(a)?EE(a)?O(a):(PE(a),k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a solid`))):(PE(a),k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a 3D shape`)))}catch(e){return k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet failed`,e))}}function Jj(e){return fD(e)}function Yj(e){if(!EE(e))return k(F(`NOT_A_SOLID`,`Input shape is not a solid`));let t=Jj(e);try{let n=U().healSolid(e.wrapped);if(!n)return t?O(e):k(P(N.HEAL_NO_EFFECT,`Solid healing had no effect — shape is still invalid`));let r=AE(n);return EE(r)?(JE(r),Jj(r)?O(r):k(P(`HEAL_SOLID_INCOMPLETE`,`Healed result is still invalid after ShapeFix_Solid`))):k(P(`HEAL_RESULT_NOT_SOLID`,`Healed result is not a solid`))}catch(e){return k(P(`HEAL_SOLID_FAILED`,`Solid healing failed`,e))}}function Xj(e){if(!wE(e))return k(F(`NOT_A_FACE`,`Input shape is not a face`));try{let t=AE(U().healFace(e.wrapped));return wE(t)?O(t):k(P(`HEAL_RESULT_NOT_FACE`,`Healed result is not a face`))}catch(e){return k(P(`HEAL_FACE_FAILED`,`Face healing failed`,e))}}function Zj(e,t){if(!CE(e))return k(F(`NOT_A_WIRE`,`Input shape is not a wire`));try{let n=AE(U().healWire(e.wrapped,t?.wrapped));return CE(n)?O(n):k(P(`HEAL_RESULT_NOT_WIRE`,`Healed result is not a wire`))}catch(e){return k(P(`HEAL_WIRE_FAILED`,`Wire healing failed`,e))}}function Qj(e){return EE(e)?Yj(e):wE(e)?Xj(e):CE(e)?Zj(e):O(e)}function $j(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(Jj(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=ZE(e).length,u=XE(e).length,d=e,f=!1;if(o!==void 0)try{d=AE(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=ZE(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(EE(d)&&i||wE(d)&&r||CE(d)&&n){let t=Qj(d);Ra(t)?(d=t.value,EE(e)?(f=!0,s.push(`Applied ShapeFix_Solid`),c.push({name:`healSolid`,attempted:!0,succeeded:!0})):wE(e)?(s.push(`Applied ShapeFix_Face`),c.push({name:`healFace`,attempted:!0,succeeded:!0})):(s.push(`Applied ShapeFix_Wire`),c.push({name:`healWire`,attempted:!0,succeeded:!0}))):(s.push(`Shape-level healing failed`),c.push({name:`healShape`,attempted:!0,succeeded:!1}))}else c.push({name:`healShape`,attempted:!1,succeeded:!1,detail:`skipped by options`});let p=ZE(d).length,m=XE(d).length,h=Math.abs(p-l),g=Math.abs(m-u);h>0&&s.push(`Wire count changed by ${h}`),g>0&&s.push(`Face count changed by ${g}`);let _=Jj(d);return s.push(_?`Final validation: valid`:`Final validation: still invalid`),c.push({name:`finalValidation`,attempted:!0,succeeded:_}),O({shape:d,report:{isValid:_,alreadyValid:!1,wiresHealed:h,facesHealed:g,solidHealed:f,steps:s,diagnostics:c}})}function eM(e){try{return O(AE(U().fixShape(e.wrapped)))}catch(e){return k(P(N.FIX_SHAPE_FAILED,`ShapeFix_Shape failed`,e))}}function tM(e){try{let t=AE(U().solidFromShell(e.wrapped));return EE(t)?Jj(t)?O(t):k(P(N.SOLID_FROM_SHELL_FAILED,`solidFromShell produced an invalid solid`)):k(P(N.SOLID_FROM_SHELL_FAILED,`solidFromShell did not produce a solid`))}catch(e){return k(P(N.SOLID_FROM_SHELL_FAILED,`Failed to create solid from shell`,e))}}function nM(e){try{let t=AE(U().fixSelfIntersection(e.wrapped));return CE(t)?O(t):k(P(N.FIX_SELF_INTERSECTION_FAILED,`Result is not a wire`))}catch(e){return k(P(N.FIX_SELF_INTERSECTION_FAILED,`Failed to fix wire self-intersection`,e))}}function rM(e,{profile:t,endFactor:n=1}){return e<1e-10?k(F(`INVALID_EXTRUSION_LENGTH`,`Extrusion length too small (< 1e-10)`)):t!==`s-curve`&&t!==`linear`?k(F(`UNSUPPORTED_PROFILE`,`Unsupported extrusion profile: ${String(t)}`)):O(U().buildExtrusionLaw(t,e,n).Trim(0,e,1e-6))}function iM(e,t){let n=U(),r=n.makeLineEdge([...e],[...t]);return W(n.makeWire([r]))}function aM(e,t,n,r,i,a=!1){return W(U().makeHelixWire(e,t,n,[...r],[...i],a))}function oM(e){let t=W(e.shape),n=W(e.firstShape),r=W(e.lastShape),i=()=>{PE(t),PE(n),PE(r)};return OE(t)?CE(n)?CE(r)?O([t,n,r]):(i(),k(mo(`SWEEP_END_NOT_WIRE`,`Sweep did not produce an end Wire`))):(i(),k(mo(`SWEEP_START_NOT_WIRE`,`Sweep did not produce a start Wire`))):(i(),k(mo(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function sM(e,t,n={},r=!1){if(n.mode===`simple`&&!r){let n=W(U().simplePipe(e.wrapped,t.wrapped));return OE(n)?O(n):(PE(n),k(mo(`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 oM(v);let y=W(v);return OE(y)?O(y):(PE(y),k(mo(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function cM(e,t,n,r){return sM(e,iM(t,xD(t,n)),{support:r})}function lM(e,t,n,r,i=!1){let a=DD(n);if(a<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let o=iM(t,xD(t,n)),s=null;if(r){let e=rM(a,r);if(A(e))return e;s=e.value}return sM(e,o,{law:s},i)}function uM(e,t,n,r,i,a=!1){if(Math.abs(t)<1e-10)return k(F(`ZERO_TWIST_ANGLE`,`Twist angle cannot be zero`));let o=DD(r);if(o<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let s=iM(n,xD(n,r)),c=t<0,l=aM(360/Math.abs(t)*o,o,1,n,r,c),u=null;if(i){let e=rM(o,i);if(A(e))return e;u=e.value}return sM(e,s,{auxiliarySpine:l,law:u},a)}function dM(e){let t=e.map(e=>e.location);for(let e=0;e<t.length;e++){let n=t[e];if(n!==void 0&&(n<0||n>1))return F(N.MULTI_SWEEP_FAILED,`Section ${e} location ${n} is out of range [0, 1]`)}let n=t.filter(e=>e!==void 0);for(let e=1;e<n.length;e++)if((n[e]??0)<=(n[e-1]??0))return F(N.MULTI_SWEEP_FAILED,`Section locations must be strictly increasing`)}function fM(e,t,n){let[r,i]=n.curveParameters(t.wrapped),a=i-r,o=Array(e.length);for(let t=0;t<e.length;t++){let n=e[t]?.location;o[t]=n===void 0?NaN:r+n*a}let s=-1,c=r;for(let t=0;t<=e.length;t++){let n=t===e.length;if(!n&&!Number.isNaN(o[t]??NaN)||n){let e=n?i:o[t]??i,a=t-s-1;for(let t=1;t<=a;t++)o[s+t]=c+t/(a+1)*(e-c);n||(s=t,c=o[t]??r)}}for(let e=1;e<o.length;e++)if((o[e]??0)<=(o[e-1]??0))return k(F(N.MULTI_SWEEP_FAILED,`Computed section parameters are not strictly increasing at index ${e} (${o[e-1]?.toFixed(4)} >= ${o[e]?.toFixed(4)})`));return O(o)}function pM(e,t,n){if(e.length<2)return k(F(N.MULTI_SWEEP_INSUFFICIENT_SECTIONS,`Multi-section sweep requires at least 2 sections, got ${e.length}`));let{solid:r=!0,ruled:i=!1,tolerance:a=1e-6}=n??{},o=dM(e);if(o)return k(o);try{let n=U(),o=fM(e,t,n);if(A(o))return o;let s=o.value,c=[];for(let r=0;r<e.length;r++){let i=s[r],a=e[r];if(i===void 0||a===void 0)continue;let o=n.positionOnCurve(a.wire.wrapped,t.wrapped,i);c.push(n.downcast(o,`wire`))}let l=W(n.loftAdvanced(c,{solid:r,ruled:i,tolerance:a}));return OE(l)?O(l):(PE(l),k(mo(`MULTI_SWEEP_NOT_3D`,`Multi-section sweep did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.MULTI_SWEEP_FAILED,`Multi-section sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function mM(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 OE(u)?O(u):(PE(u),k(mo(`GUIDED_SWEEP_NOT_3D`,`Guided sweep did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.GUIDED_SWEEP_FAILED,`Guided sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function hM(e,t){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`extrude: face is a null shape`));if(DD(t)<1e-10)return k(F(`EXTRUDE_ZERO_VECTOR`,`extrude: extrusion vector has zero length`));try{let n=U(),r=DD(t),i=AD(t),a=n.extrude(e.wrapped,[...i],r),o=vE(n.downcast(a,`solid`));return ME(a,o),O(o)}catch(e){return k(P(`EXTRUDE_FAILED`,`Extrusion operation failed`,e,{operation:`extrude`,vectorLength:DD(t)}))}}function gM(e,t=[0,0,0],n=[0,0,1],r=2*Math.PI){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`revolve: face is a null shape`));try{let i=W(U().revolveVec(e.wrapped,[...t],[...n],r));return OE(i)?O(i):(PE(i),k(mo(`REVOLUTION_NOT_3D`,`Revolution did not produce a 3D shape`)))}catch(e){return k(P(`REVOLVE_FAILED`,`Revolution operation failed`,e,{operation:`revolve`,angle:r}))}}function _M(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=DD(i);if(a<1e-10)return k(F(`EXTRUDE_ALL_ZERO_VECTOR`,`extrudeAll: entry ${t} has zero-length extrusion vector`));let o=[...AD(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=vE(t.downcast(e,`solid`));return ME(e,n),n}))}catch(e){return k(P(`EXTRUDE_ALL_FAILED`,`Batch extrusion operation failed`,e))}}function vM(e,{ruled:t=!0,startPoint:n,endPoint:r,tolerance:i=1e-6}={},a=!1){if(e.length===0&&!n&&!r)return k(F(`LOFT_EMPTY`,`Loft requires at least one wire or start/end point`));let o=U(),s=n?o.makeVertex(..._D(n)):void 0,c=r?o.makeVertex(..._D(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 OE(n)?O(n):(PE(n),k(mo(`LOFT_NOT_3D`,`Loft did not produce a 3D shape`)))}catch(e){return k(P(`LOFT_FAILED`,`Loft operation failed`,e,void 0,`Common causes: wire profiles with different edge counts, self-intersecting result, or profiles too far apart. Ensure profiles are compatible and ordered.`))}}function yM(e){if(e.length===0)return O([]);let t=U(),n=[],r=e.map(e=>{let r=e.startPoint?t.makeVertex(..._D(e.startPoint)):void 0,i=e.endPoint?t.makeVertex(..._D(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(!OE(e))return PE(e),k(mo(`LOFT_ALL_NOT_3D`,`Batch loft entry did not produce a 3D shape`));n.push(e)}return O(n)}catch(e){return k(P(`LOFT_ALL_FAILED`,`Batch loft operation failed`,e))}finally{for(let e of n)t.dispose(e)}}var bM=new WeakMap;function xM(e,t){return bM.get(e)?.get(t)}function SM(e,t,n){let r=bM.get(e);r||(r=new Map,bM.set(e,r)),r.set(t,n)}function CM(e){return U().isNull(e.wrapped)}function wM(e){return k(F(N.NULL_SHAPE_INPUT,`${e}: shape is a null shape`))}function TM(e){let t=xM(e.wrapped,`volume`);if(t)return O(t);if(CM(e))return wM(`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 SM(e.wrapped,`volume`,t),O(t)}let i=n.volume(e.wrapped),a=BE(()=>n.centerOfMass(e.wrapped),N.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!a.ok)return a;let o={mass:i,volume:i,centerOfMass:a.value};return SM(e.wrapped,`volume`,o),O(o)}function EM(e){let t=xM(e.wrapped,`surface`);if(t)return O(t);if(CM(e))return wM(`measureSurfaceProps`);let n=U(),r=n.area(e.wrapped),i=BE(()=>n.centerOfMass(e.wrapped),N.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!i.ok)return i;let a={mass:r,area:r,centerOfMass:i.value};return SM(e.wrapped,`surface`,a),O(a)}function DM(e){let t=xM(e.wrapped,`linear`);if(t)return O(t);if(CM(e))return wM(`measureLinearProps`);let n=U(),r=n.length(e.wrapped),i={mass:r,length:r,centerOfMass:n.linearCenterOfMass(e.wrapped)};return SM(e.wrapped,`linear`,i),O(i)}function OM(e){let t=TM(e);return t.ok?O(t.value.mass):t}function kM(e){let t=EM(e);return t.ok?O(t.value.mass):t}function AM(e){let t=DM(e);return t.ok?O(t.value.mass):t}function jM(e,t){return CM(e)||CM(t)?wM(`measureDistance`):O(U().distance(e.wrapped,t.wrapped).value)}function MM(e,t){if(CM(e)||CM(t))return wM(`measureDistanceProps`);let n=U().distance(e.wrapped,t.wrapped);return O({distance:n.value,point1:n.point1,point2:n.point2})}function NM(e){if(CM(e))return wM(`createDistanceQuery`);let t=U().createDistanceQuery(e.wrapped);return O({distanceTo(e){return CM(e)?wM(`createDistanceQuery.distanceTo`):O(t.distanceTo(e.wrapped).value)},dispose(){t.dispose()}})}function PM(e,t,n){if(CM(e))return wM(`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 FM(e){if(CM(e))return wM(`measureCurvatureAtMid`);let t=sO(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 IM(e,t){return e.map(e=>FE(e,t))}function LM(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=IE(e,t);i.push(s),o?o.push(s.wrapped):a.set(r,[s.wrapped])}return i}function RM(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 zM(e,t,n){let r=U();return e.get(n)?.find(e=>r.isSame(e.wrapped,t))}function BM(e){let t=KE(e);if(t.edgeToFaces)return t.edgeToFaces;let n=U(),r=XE(e),i=RM(YE(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=zM(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 VM(e){let t=KE(e);if(t.vertexToFaces)return t.vertexToFaces;let n=U(),r=XE(e),i=RM(QE(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=zM(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 HM(e,t){let n=U(),r=BM(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 IM(o,`face`)}function UM(e,t){let n=U(),r=VM(e),i=n.hashCode(t.wrapped,G),a=r.get(i)??[],o=[],s=new Map;for(let e of a){if(!n.isSame(e.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 IM(o,`face`)}function WM(e){return LM(e.wrapped,`edge`)}function GM(e){return LM(e.wrapped,`vertex`)}function KM(e){return LM(e.wrapped,`wire`)}function qM(e){return LM(e.wrapped,`vertex`)}function JM(e,t){let n=U(),r=BM(e),i=LM(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 IM(a,`face`)}function YM(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(IE(e,`edge`)):n.dispose(e);for(let e of i)n.dispose(e);return o}function XM(e,t){let n=0,r=iO(t);if(e.surfaceType!==void 0)if(r===e.surfaceType)n+=1;else return-1/0;if(e.normal!==void 0){let r=dO(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=fO(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=kM(t);if(r.ok&&r.value>0){let t=Math.abs(Math.log(e.area/r.value));t>1&&(n-=t)}}return n}function ZM(e){let t=iO(e),n=dO(e),r=fO(e),i=kM(e);return{entityType:`face`,surfaceType:t,normal:n,centroid:r,area:i.ok?i.value:void 0}}var QM=.9;function $M(e){if(e[2]>QM)return`box:top`;if(e[2]<-.9)return`box:bottom`;if(e[1]>QM)return`box:back`;if(e[1]<-.9)return`box:front`;if(e[0]>QM)return`box:right`;if(e[0]<-.9)return`box:left`}function eN(e,t){if(iO(t)!==`PLANE`)return;let n=dO(t)[2];if(n>QM)return`${e}:top`;if(n<-.9)return`${e}:bottom`}function tN(e){return iO(e)===`CYLINDRE`?`cylinder:lateral`:eN(`cylinder`,e)}function nN(e){return iO(e)===`CONE`?`cone:lateral`:eN(`cone`,e)}function rN(e){return iO(e)===`SPHERE`?`sphere:surface`:void 0}var iN={box:e=>$M(dO(e)),cylinder:tN,cone:nN,sphere:rN};function aN(e,t){let n=new Map,r=iN[t],i=U(),a=0;for(let o of i.iterShapes(e.wrapped,`face`)){let e=FE(o,`face`);try{let i=r?.(e),o=i!==void 0&&!n.has(i)?i:`${t}:face_${a}`;n.set(o,[pk(e)]),a++}finally{NE(e,o)}}return n}function oN(e,t,n){return{origin:e,role:t,hint:ZM(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 lN=.1,uN=.5;function dN(e,t,n){let r=-1/0,i,a=-1/0,o=[];for(let s of t){let t=n(e,s);t>uN&&o.push([s,t]),t>r?(a=r,r=t,i=s):t>a&&(a=t)}return i!==void 0&&r>uN?r-a<lN&&o.length>1?{kind:`ambiguous`,candidates:o.filter(([,e])=>e>=r-lN).map(([e])=>e)}:{kind:`match`,face:i}:{kind:`none`}}function fN(e,t,n,r){let i=XE(n),a=r??XM,o=t.get(e.origin)?.get(e.role);if(o!==void 0&&o.length>0){let t=i.filter(e=>o.includes(pk(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=dN(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=dN(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 pN(e,t){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(n*n+r*r+i*i)}function mN(e){if(e.length===0)return;let t=0,n=0,r=0;for(let i of e){let e=mD(i);t+=e[0],n+=e[1],r+=e[2]}let i=e.length;return[t/i,n/i,r/i]}function hN(e,t,n){let r=n.get(t);if(!r)return;let i=pk(e);for(let[e,t]of r)if(t.includes(i))return e}function gN(e,t,n,r){let i=r.get(t)?.get(n);return i===void 0||i.length===0?[]:XE(e).filter(e=>i.includes(pk(e)))}function _N(e){let t=AM(e);return{entityType:`edge`,length:t.ok?t.value:void 0,midpoint:mN(qM(e))}}function vN(e){let t=new Set,n=[];for(let r of e){let e=pk(r);t.has(e)||(t.add(e),n.push(r))}return n}var yN=1e-6;function bN(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=AM(a);n.ok&&(e+=Math.abs(n.value-t.length))}if(t.midpoint!==void 0){let n=mN(qM(a));n!==void 0&&(e+=pN(t.midpoint,n))}e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<yN))return n}function xN(e,t,n,r){let[i,a]=HM(n,t);if(i===void 0||a===void 0)return;let o=hN(i,e,r),s=hN(a,e,r);if(!(o===void 0||s===void 0))return{origin:e,faceRoles:[o,s],hint:_N(t)}}function SN(e,t,n){let[r,i]=e.faceRoles,a=gN(n,e.origin,r,t),o=gN(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(...YM(e,t));let c=vN(s);if(c.length===1){let[e]=c;if(e!==void 0)return{edge:e,confidence:`exact`}}if(c.length>1){let t=bN(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 CN=3,wN=1e-6;function TN(e,t){let n=new Set;for(let r of e)for(let e of GM(r)){let r=pk(e);n.add(r),t.has(r)||t.set(r,e)}return n}function EN(e,t){let n=new Set;for(let r of e)t.has(r)&&n.add(r);return n}function DN(e){let t=new Map,n;for(let r of e){let e=TN(r,t);n=n===void 0?e:EN(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 ON(e,t){if(t.position===void 0)return;let n,r=1/0,i=1/0;for(let a of e){let e=pN(mD(a),t.position);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<wN))return n}function kN(e,t,n,r){let i=UM(n,t);if(i.length<CN)return;let a=new Set;for(let t of i){let n=hN(t,e,r);n!==void 0&&a.add(n)}if(!(a.size<CN))return{origin:e,faceRoles:[...a].sort(),hint:{entityType:`vertex`,position:mD(t)}}}function AN(e,t,n){let r=[];for(let i of e.faceRoles){let a=gN(n,e.origin,i,t);if(a.length===0)return{ref:e,reason:`not-found`};r.push(a)}let i=DN(r);if(i.length===1){let[e]=i;if(e!==void 0)return{vertex:e,confidence:`exact`}}if(i.length>1){let t=ON(i,e.hint);return t===void 0?{ref:e,reason:`ambiguous`,candidates:i}:{vertex:t,confidence:`geometric-fallback`}}return{ref:e,reason:`not-found`}}var jN=.99,MN=.1,NN=1e-6;function PN(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function FN(e,t){return XE(e).filter(e=>PN(dO(e),t)>jN)}function IN(e,t,n){let r=new Set([...t,...n].map(pk)),i=new Set;for(let n of t)for(let t of JM(e,n))i.add(pk(t));let a=[],o=new Set;for(let t of n)for(let n of JM(e,t)){let e=pk(n);r.has(e)||o.has(e)||!i.has(e)||(o.add(e),a.push(n))}return a}function LN(e,t){let n,r=1/0,i=1/0;for(let a of e){let e=pN(fO(a),t);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<NN))return n}function RN(e,t,n,r,i){let[a,o]=HM(r,n);if(a===void 0||o===void 0)return;let s=hN(a,e,i),c=hN(o,e,i);if(!(s===void 0||c===void 0))return{origin:e,op:t,betweenRoles:[s,c],hint:{entityType:`derived-face`,normalA:dO(a),normalB:dO(o),edgeMidpoint:mN(qM(n))}}}function zN(e,t,n){let r=gN(n,e.origin,e.betweenRoles[0],t);r.length===0&&(r=FN(n,e.hint.normalA));let i=gN(n,e.origin,e.betweenRoles[1],t);if(i.length===0&&(i=FN(n,e.hint.normalB)),r.length===0||i.length===0)return{ref:e,reason:`not-found`};let a=IN(n,r,i).filter(t=>PN(dO(t),e.hint.normalA)>MN&&PN(dO(t),e.hint.normalB)>MN);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&&LN(a,e.hint.edgeMidpoint);return t?{face:t,confidence:`geometric-fallback`}:{ref:e,reason:`ambiguous`,candidates:a}}return{ref:e,reason:`not-found`}}function BN(e){return typeof e==`object`&&!!e&&`origin`in e}function VN(e){return BN(e)&&`betweenRoles`in e&&`op`in e}function HN(e){return BN(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length===2}function UN(e){return BN(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length>=3}function WN(e){return BN(e)&&typeof e.role==`string`}function GN(e){return WN(e)||HN(e)||UN(e)||VN(e)}function KN(e,t){return t===void 0?{ok:!1,reason:e}:{ok:!1,reason:e,candidates:t}}function qN(e,t,n){if(VN(e)){let r=zN(e,t,n);return`face`in r?{ok:!0,entity:r.face}:KN(r.reason,r.candidates)}if(HN(e)){let r=SN(e,t,n);return`edge`in r?{ok:!0,entity:r.edge}:KN(r.reason,r.candidates)}if(UN(e)){let r=AN(e,t,n);return`vertex`in r?{ok:!0,entity:r.vertex}:KN(r.reason,r.candidates)}let r=fN(e,t,n);return`face`in r?{ok:!0,entity:r.face}:KN(r.reason,r.candidates)}function JN(e,t,n){let r=n.get(e.origin);if(r!==void 0)return r;let i=new Map([[e.origin,aN(t,e.origin)]]);return n.set(e.origin,i),i}function YN(e,t){return qN(e,JN(e,t,new Map),t)}function XN(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 ZN(e,t){let n=new Map,r=e=>{if(GN(e)){let r=qN(e,JN(e,t,n),t);return r.ok?r.entity:e}if(Array.isArray(e))return e.map(r);if(XN(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 QN(e,t,n,r){let i=vE(U().makeBox(e,t,n)),a=r?.at??(r?.centered?[0,0,0]:void 0);return a?$O(i,[a[0]-e/2,a[1]-t/2,a[2]-n/2]):i}function $N(e,t,n){let r=n?.at??[0,0,0],i=n?.axis??[0,0,1],a=JA(e,t,r,i);if(n?.centered){let e=[-i[0]*t*.5,-i[1]*t*.5,-i[2]*t*.5];a=$O(a,e)}return a}function eP(e,t){let n=YA(e);return t?.at&&(n=$O(n,t.at)),n}function tP(e,t,n,r){let i=r?.at??[0,0,0],a=r?.axis??[0,0,1],o=XA(e,t,n,i,a);if(r?.centered){let e=[-a[0]*n*.5,-a[1]*n*.5,-a[2]*n*.5];o=$O(o,e)}return o}function nP(e,t,n){return ZA(e,t,n?.at??[0,0,0],n?.axis??[0,0,1])}function rP(e,t,n,r){let i=QA(e,t,n);return r?.at&&(i=$O(i,r.at)),i}function iP(e,t){return lA(e,t)}function aP(e,t){let n=t?.axis??[0,0,1];return uA(e,t?.at??[0,0,0],n)}function oP(e,t,n){let r=n?.axis??[0,0,1];return dA(e,t,n?.at??[0,0,0],r,n?.xDir)}function sP(e,t,n,r){return fA(e,t,n,r?.at??[0,0,0],r?.axis??[0,0,1],r?.lefthand??!1)}function cP(e,t,n){return pA(e,t,n)}function lP(e,t,n,r,i){let a=i?.axis??[0,0,1];return mA(e,t,n*hD,r*hD,i?.at??[0,0,0],a,i?.xDir)}function uP(e,t){return hA(e,t)}function dP(e){return _A(e)}function fP(e,t,n){return vA(e,t,n)}function pP(e){return yA(e)}function mP(e){return Va(yA(e),e=>eE(e)?O(e):k(F(`WIRE_NOT_CLOSED`,`Assembled wire is not closed: start and end points do not coincide`)))}function hP(e,t){return bA(e,t)}function gP(e){return CA(e)}function _P(e,t){return SA(e,t)}function vP(e){return TA(e)}function yP(e){return $A(e)}function bP(e){return tj(e)}function xP(e){return nj(e)}function SP(e,t,n){return ej(e,t,n)}function CP(e,t){return qA(e,t)}function wP(e,t){return wA(e,t)}function TP(){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 EP(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??TP(),color:[a,o,s,c]}});return RT(U().createXCAFDocument(t))}function DP(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??TP(),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(_o(`STEP_EXPORT_FAILED`,`Failed to write STEP file`))}finally{o.delete()}}function OP(e,t,n,r,i){if(n<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(MD(t))return k(F(`PATTERN_ZERO_DIRECTION`,`Pattern direction cannot be zero`));let a=AD(t);return MA(U().linearPattern(e.wrapped,[...a],r,n).map(e=>W(e)),{optimisation:`sameFace`,...i,unsafe:!0})}function kP(e,t,n,r=360,i=[0,0,0],a){if(n<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(MD(t))return k(F(`PATTERN_ZERO_AXIS`,`Pattern axis cannot be zero`));let o=r/n;return MA(U().circularPattern(e.wrapped,[...i],[...t],o,n).map(e=>W(e)),{optimisation:`sameFace`,...a,unsafe:!0})}function AP(e,t,n,r,i,a,o,s){if(r<1||i<1)return k(F(`PATTERN_INVALID_COUNT`,`Grid pattern counts must be at least 1`));if(r===1&&i===1)return O(e);if(MD(t))return k(F(`PATTERN_ZERO_DIRECTION`,`Grid directionX cannot be zero`));if(MD(n))return k(F(`PATTERN_ZERO_DIRECTION`,`Grid directionY cannot be zero`));let c=U(),l=AD(t),u=AD(n);if(typeof c.gridPattern==`function`)return O(W(c.gridPattern(e.wrapped,[...l],[...u],a,o,r,i)));let d=OP(e,t,r,a,s);return d.ok?OP(d.value,n,i,o,s):d}function jP(e,t={}){return{name:e,children:[],...t.shape===void 0?{}:{shape:t.shape},...t.translate===void 0?{}:{translate:t.translate},...t.rotate===void 0?{}:{rotate:t.rotate},...t.metadata===void 0?{}:{metadata:t.metadata}}}function MP(e,t){return{...e,children:[...e.children,t]}}function NP(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 PP(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 FP(e,t){if(e.name===t)return e;for(let n of e.children){let e=FP(n,t);if(e)return e}}function IP(e,t,n=0){t(e,n);for(let r of e.children)IP(r,t,n+1)}function LP(e){let t=1;for(let n of e.children)t+=LP(n);return t}function RP(e){let t=[];return IP(e,e=>{e.shape&&t.push(e.shape)}),t}function zP(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function BP(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 VP(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function HP(e){return VP(BP(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function UP(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 WP(e,t){let n=t/2,r=Math.sin(n),i=VP(e);return[Math.cos(n),i[0]*r,i[1]*r,i[2]*r]}function GP(e,t){let n=VP(e),r=VP(t),i=zP(n,r);if(i>=.999999999)return[1,0,0,0];if(i<=-.999999999)return WP(HP(n),Math.PI);let a=BP(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 KP(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 qP=Math.PI/180;function JP(e,t,n){return Math.min(n,Math.max(t,e))}function YP(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function XP(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 ZP(e){return YP(XP(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function QP(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:YP(t),min:s,max:c,value:JP(n.value??0,s,c)}}function $P(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:YP(r.direction)},min:a.min,max:a.max,value:a.value,dofs:i}}function eF(e,t,n,r={}){return $P(`revolute`,e,t,n,[QP(`rotation`,n.direction,r,-180,180)])}function tF(e,t,n,r={}){return $P(`prismatic`,e,t,n,[QP(`translation`,n.direction,r,0,100)])}function nF(e,t,n,r={}){return $P(`cylindrical`,e,t,n,[QP(`rotation`,n.direction,r.rotation??{},-180,180),QP(`translation`,n.direction,r.translation??{},0,100)])}function rF(e,t,n,r={}){let i=YP(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?ZP(i):YP(n)}else a=ZP(i);let o=YP(XP(i,a));return $P(`planar`,e,t,{origin:n.origin,direction:i},[QP(`translation`,a,r.u??{},-100,100),QP(`translation`,o,r.v??{},-100,100),QP(`rotation`,i,r.rotation??{},-180,180)])}function iF(e,t,n,r={}){return $P(`spherical`,e,t,{origin:n,direction:[0,0,1]},[QP(`rotation`,[1,0,0],r.x??{},-180,180),QP(`rotation`,[0,1,0],r.y??{},-180,180),QP(`rotation`,[0,0,1],r.z??{},-180,180)])}function aF(e,t){let n=e.dofs.map((e,n)=>{let r=t[n];return r===void 0?e:{...e,value:JP(r,e.min,e.max)}}),r=n[0];return r?{...e,dofs:n,value:r.value}:{...e,dofs:n}}function oF(e,t){return aF(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=WP(t.axis,n*qP),i=UP(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=uF;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=dF(a,sF(i,o,JP(s,o.min,o.max)))}return a}function lF(e,t){let n=e.joints??[];return{...e,joints:[...n,t]}}var uF={position:[0,0,0],rotation:[1,0,0,0]};function dF(e,t){let n=UP(e.rotation,t.position);return{position:[e.position[0]+n[0],e.position[1]+n[1],e.position[2]+n[2]],rotation:KP(e.rotation,t.rotation)}}function fF(e){let t=[];return IP(e,e=>{e.joints&&t.push(...e.joints)}),t}function pF(e,t={}){let n=[],r=new Set;IP(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,uF);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?dF(cF(n,i),n.offset):cF(n,i);a.set(n.child,dF(r,c))}}for(let e of o)a.has(e.child)||a.set(e.child,uF);return a}function mF(e){return fF(e).reduce((e,t)=>e+t.dofs.length,0)}var hF={position:[0,0,0],rotation:[1,0,0,0]};function gF(e,t){let n=UP(e.rotation,t);return[n[0]+e.position[0],n[1]+e.position[1],n[2]+e.position[2]]}function _F(e){return[e[0],-e[1],-e[2],-e[3]]}function vF(e,t){let[n,r,i,a]=KP(t,_F(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 yF(e,t){let n=[];IP(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 bF(e,t){return e[t]??0}function xF(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]=bF(e,a*n+t);i[a*r+n]=bF(t,a)}for(let e=0;e<n;e++){let t=e;for(let a=e+1;a<n;a++)Math.abs(bF(i,a*r+e))>Math.abs(bF(i,t*r+e))&&(t=a);if(Math.abs(bF(i,t*r+e))<1e-12)return null;if(t!==e)for(let n=e;n<r;n++){let a=bF(i,e*r+n);i[e*r+n]=bF(i,t*r+n),i[t*r+n]=a}let a=bF(i,e*r+e);for(let t=e;t<r;t++)i[e*r+t]=bF(i,e*r+t)/a;for(let t=0;t<n;t++){if(t===e)continue;let n=bF(i,t*r+e);if(n!==0)for(let a=e;a<r;a++)i[t*r+a]=bF(i,t*r+a)-n*bF(i,e*r+a)}}let a=new Float64Array(n);for(let e=0;e<n;e++)a[e]=bF(i,e*r+n);return a}function SF(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 CF(e,t){let n={},r=0;for(let i of e){let e=[];for(let n=0;n<i.count;n++)e.push(bF(t,r++));n[i.child]=e}return n}function wF(e,t,n,r,i){let a=gF(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=vF(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+=bF(e,t)**2;return Math.sqrt(o)}function TF(e,t,n,r,i,a,o,s,c,l){let u=gF(o,s);for(let d=0;d<n;d++){let f=bF(t,d),p=f+c>bF(a,d)&&f-c>=bF(i,d)?-c:c;t[d]=f+p;let m=l(t);t[d]=f;let h=gF(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=vF(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 EF(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+=bF(e,t*n+r)*bF(e,i*n+r);a[t*r+i]=s+(t===i?o:0)}let s=xF(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+=bF(e,a*n+t)*bF(s,a);c[t]=i}return c}function DF(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}=SF(yF(e,t),r.seed),p=u.length,m=n=>pF(e,CF(l,n)).get(t)??hF,h=new Float64Array(c),g=new Float64Array(c*p),_=m(u),v=wF(h,_,n,s,c),y=0;for(;y<i&&p>0&&v>a;y++){TF(g,u,p,c,d,f,_,s,1e-6,m);let e=EF(g,h,p,c,o);if(!e)break;for(let t=0;t<p;t++){let n=bF(u,t)+bF(e,t);u[t]=Math.min(bF(f,t),Math.max(bF(d,t),n))}_=m(u),v=wF(h,_,n,s,c)}return{values:CF(l,u),converged:v<=a,iterations:y,error:v}}function OF(e,t){return e.dofs.map((e,n)=>{let r=(Array.isArray(t)?t[n]:n===0?t:void 0)??e.value;return Math.min(e.max,Math.max(e.min,r))})}function kF(e,t,n,r){let i=[];IP(e,e=>{e.joints&&i.push(...e.joints)});let a=i.map(e=>({child:e.child,a:OF(e,t[e.child]),b:OF(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:pF(e,r)})}return s}var AF=Math.PI/180;function jF(e,t,n,r){let i=e*AF,a=r*AF,o=KP(WP([0,0,1],i),WP([1,0,0],a));return{position:[n*Math.cos(i),n*Math.sin(i),t],rotation:o}}function MF(e,t={}){let n=t.base??`base`,r=e.map((e,t)=>e.name??`link${t+1}`);return e.map((e,t)=>{let i=t===0?n:r[t-1]??`link${t}`,a=r[t]??`link${t+1}`,o=jF(e.theta,e.d,e.a,e.alpha),s={origin:[0,0,0],direction:[0,0,1]},c={...e.min===void 0?{}:{min:e.min},...e.max===void 0?{}:{max:e.max},...e.value===void 0?{}:{value:e.value}};return{...e.type===`prismatic`?tF(i,a,s,c):eF(i,a,s,c),offset:o}})}var NF=Math.PI/180,PF=180/Math.PI;function FF(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function IF(e){return String(e===0?0:e)}function LF(e){return`${IF(e[0])} ${IF(e[1])} ${IF(e[2])}`}function RF(e,t={}){let n=t.name??`robot`,r=t.effort??0,i=t.velocity??0,a=t.meshes??{},o=[],s=[];IP(e,e=>{o.push(e.name),e.joints&&s.push(...e.joints)});for(let e of s){if(e.type!==`revolute`&&e.type!==`prismatic`)return k(F(N.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' is '${e.type}'; URDF supports only revolute and prismatic joints`));if(e.offset)return k(F(N.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' carries a fixed offset (e.g. a DH link) that URDF cannot represent as a single joint`))}let c=[`<?xml version="1.0"?>`,`<robot name="${FF(n)}">`];for(let e of o){let t=a[e];t?c.push(` <link name="${FF(e)}">`,` <visual><geometry><mesh filename="${FF(t)}"/></geometry></visual>`,` </link>`):c.push(` <link name="${FF(e)}"/>`)}for(let e of s){let t=e.type===`revolute`,n=t?e.min*NF:e.min,a=t?e.max*NF:e.max,o=e.type===`prismatic`?[0,0,0]:e.axis.origin;c.push(` <joint name="${FF(`${e.parent}_to_${e.child}`)}" type="${e.type}">`,` <parent link="${FF(e.parent)}"/>`,` <child link="${FF(e.child)}"/>`,` <origin xyz="${LF(o)}" rpy="0 0 0"/>`,` <axis xyz="${LF(e.axis.direction)}"/>`,` <limit lower="${IF(n)}" upper="${IF(a)}" effort="${IF(r)}" velocity="${IF(i)}"/>`,` </joint>`)}return c.push(`</robot>`,``),O(c.join(`
15
+ npm install brepkit-wasm`)}function DT(){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 OT=Symbol;OT.dispose??=Symbol.for(`Symbol.dispose`),OT.asyncDispose??=Symbol.for(`Symbol.asyncDispose`);var kT=globalThis;kT.FinalizationRegistry||=(console.warn(`brepjs: FinalizationRegistry unavailable — garbage collection will not work`),class{register(e,t,n){}unregister(e){return!1}});var AT={liveHandles:0,peakHandles:0,gcCollected:0,scopeEnters:0,scopeExits:0};function jT(){return{...AT}}function MT(){AT.liveHandles=0,AT.peakHandles=0,AT.gcCollected=0,AT.scopeEnters=0,AT.scopeExits=0}function NT(){AT.liveHandles++,AT.liveHandles>AT.peakHandles&&(AT.peakHandles=AT.liveHandles)}function PT(){AT.liveHandles--}function FT(){AT.gcCollected++,AT.liveHandles--}var IT=new FinalizationRegistry(e=>{FT();try{e.delete()}catch{}});function LT(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,PT(),IT.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 NT(),IT.register(o,{delete:()=>{t.dispose(e)}},o),o}function RT(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,PT(),IT.unregister(n);try{e.delete()}catch{}}}};return NT(),IT.register(n,e,n),n}var zT=class{handles=[];constructor(){AT.scopeEnters++}register(e){return this.handles.push(()=>{try{e.delete()}catch{}}),e}track(e){return this.handles.push(()=>{try{e[Symbol.dispose]()}catch{}}),e}[Symbol.dispose](){AT.scopeExits++;for(let e=this.handles.length-1;e>=0;e--)this.handles[e]?.();this.handles.length=0}};function BT(e){try{var t=DT();return e(t.u(new zT))}catch(e){t.e=e}finally{t.d()}}function VT(e,t){IT.register(e,t,t)}function HT(e){IT.unregister(e)}function UT(e){try{var t=DT();return e(t.u(new zT))}catch(e){t.e=e}finally{t.d()}}async function WT(e){try{var t=DT();return await e(t.u(new zT))}catch(e){t.e=e}finally{t.d()}}function GT(e){return!e.disposed}function KT(e){return e.__is2D!==!0}function qT(e){return e.__is2D===!0}function JT(e){if(!KT(e))throw Error(`Expected 3D shape, got 2D`);return e}function YT(e){if(!qT(e))throw Error(`Expected 2D shape, got 3D`);return e}var XT=new WeakMap;function ZT(e,t){XT.set(e,t)}function QT(e,t){let n=XT.get(t);if(n!==void 0)return n;let r=e.shapeType(t);return XT.set(t,r),r}function $T(e){return QT(U(),e.wrapped)}function eE(e){return U().curveIsClosed(e.wrapped)}function tE(e){return U().isValid(e.wrapped)}function nE(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 rE(e){return U().isValid(e.wrapped)}function iE(e){return eE(e)?O(e):k(`Wire is not closed: start and end points do not coincide`)}function aE(e){return tE(e)?O(e):k(`Face orientation is inconsistent or face is invalid`)}function oE(e){return nE(e)?O(e):k(`Shell is not manifold: has free edges or is invalid`)}function sE(e){return rE(e)?O(e):k(`Solid failed BRepCheck validation`)}function cE(e){return U().surfaceType(e.wrapped)===`plane`}function lE(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 uE(e){return cE(e)?O(e):k(`Face is not planar: underlying surface is not a geometric plane`)}function dE(e){return lE(e)?O(e):k(`Wire is not planar: edges do not lie in a common plane`)}function fE(e,t){return t===`2D`&&(e.__is2D=!0),e}function pE(e,t){return fE(LT(e),t)}function mE(e,t){return fE(LT(e),t)}function hE(e,t){return fE(LT(e),t)}function gE(e,t){return fE(LT(e),t)}function _E(e){return fE(LT(e))}function vE(e){return fE(LT(e))}function yE(e){return fE(LT(e))}function bE(e,t){return fE(LT(e),t)}function xE(e){return $T(e)===`vertex`}function SE(e){return $T(e)===`edge`}function CE(e){return $T(e)===`wire`}function wE(e){return $T(e)===`face`}function TE(e){return $T(e)===`shell`}function EE(e){return $T(e)===`solid`}function DE(e){return $T(e)===`compound`}function OE(e){let t=$T(e);return t===`shell`||t===`solid`||t===`compsolid`?!0:t===`compound`?KT(e):!1}function kE(e){let t=$T(e);return t===`edge`||t===`wire`}function AE(e,t){let n=U(),r=QT(n,e),i=n.downcast(e,r);return r===`vertex`?pE(i,t):r===`edge`?mE(i,t):r===`wire`?hE(i,t):r===`face`?gE(i,t):r===`shell`?_E(i):r===`solid`?vE(i):r===`compsolid`?yE(i):bE(i,t)}function jE(e){return AE(e)}function ME(e,t){t.wrapped!==e&&U().dispose(e)}function W(e,t){let n=AE(e,t);return ME(e,n),n}function NE(e,t){let n=e.wrapped;if(e[Symbol.dispose](),n!==t){let e=U();e.dispose(n),e.dispose(t)}}function PE(e){U().dispose(e.wrapped),e[Symbol.dispose]()}function FE(e,t,n){ZT(e,t);let r=U().downcast(e,t);return t===`vertex`?pE(r,n):t===`edge`?mE(r,n):t===`wire`?hE(r,n):t===`face`?gE(r,n):t===`shell`?_E(r):t===`solid`?vE(r):t===`compsolid`?yE(r):bE(r,n)}function IE(e,t,n){let r=FE(e,t,n);return ME(e,r),r}function LE(e,t,n,r,i){let a={kind:e,code:t,message:n,cause:r};return i?{...a,suggestion:i}:a}var RE={KERNEL_OPERATION:(e,t,n,r)=>LE(`KERNEL_OPERATION`,e,t,n,r),VALIDATION:(e,t,n,r)=>LE(`VALIDATION`,e,t,n,r),TYPE_CAST:(e,t,n,r)=>LE(`TYPE_CAST`,e,t,n,r),SKETCHER_STATE:(e,t,n,r)=>LE(`SKETCHER_STATE`,e,t,n,r),MODULE_INIT:(e,t,n,r)=>LE(`MODULE_INIT`,e,t,n,r),COMPUTATION:(e,t,n,r)=>LE(`COMPUTATION`,e,t,n,r),IO:(e,t,n,r)=>LE(`IO`,e,t,n,r),QUERY:(e,t,n,r)=>LE(`QUERY`,e,t,n,r),UNSUPPORTED:(e,t,n,r)=>LE(`UNSUPPORTED`,e,t,n,r)};function zE(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`?fo(i):i,o=uo(t);return k(RE[r](t,`${n}: ${a}`,e,o))}}function BE(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`?fo(i):i,o=uo(t);return k(RE[r](t,`${n}: ${a}`,e,o))}}function VE(e,t,n,r=`KERNEL_OPERATION`){try{var i=DT();let a=i.u(new zT);return zE(()=>e(a),t,n,r)}catch(e){i.e=e}finally{i.d()}}function HE(e,t){let n=U().iterShapes(e,t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=IE(n[e],t);return r}var UE=new WeakMap;function WE(e){let t=UE.get(e);if(!t)return;UE.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 GE=new WeakSet;function KE(e){let t=e.wrapped,n=UE.get(t);return n||(n={},UE.set(t,n)),GE.has(e)||(GE.add(e),e.onDispose(()=>{WE(t)})),n}function qE(e){return UE.get(e.wrapped)}function JE(e){WE(e.wrapped)}function YE(e){let t=KE(e);if(t.edges)return t.edges;let n=HE(e.wrapped,`edge`);return t.edges=n,n}function XE(e){let t=KE(e);if(t.faces)return t.faces;let n=HE(e.wrapped,`face`);return t.faces=n,n}function ZE(e){let t=KE(e);if(t.wires)return t.wires;let n=HE(e.wrapped,`wire`);return t.wires=n,n}function QE(e){let t=KE(e);if(t.vertices)return t.vertices;let n=HE(e.wrapped,`vertex`);return t.vertices=n,n}function $E(e){let t=KE(e);if(t.solids)return t.solids;let n=HE(e.wrapped,`solid`);return t.solids=n,n}function eD(e){let t=KE(e);if(t.shells)return t.shells;let n=HE(e.wrapped,`shell`);return t.shells=n,n}function tD(e){let t=KE(e);if(t.compSolids)return t.compSolids;let n=HE(e.wrapped,`compsolid`);return t.compSolids=n,n}function*nD(e){for(let t of U().iterShapes(e.wrapped,`edge`))yield IE(t,`edge`)}function*rD(e){for(let t of U().iterShapes(e.wrapped,`face`))yield IE(t,`face`)}function*iD(e){for(let t of U().iterShapes(e.wrapped,`wire`))yield IE(t,`wire`)}function*aD(e){for(let t of U().iterShapes(e.wrapped,`vertex`))yield IE(t,`vertex`)}function*oD(e){for(let t of U().iterShapes(e.wrapped,`solid`))yield IE(t,`solid`)}function*sD(e){for(let t of U().iterShapes(e.wrapped,`shell`))yield IE(t,`shell`)}function*cD(e){for(let t of U().iterShapes(e.wrapped,`compsolid`))yield IE(t,`compsolid`)}function lD(e){let t=KE(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 uD(e){return QT(U(),e.wrapped)}function dD(e){let t=KE(e);if(t.surfaceType!==void 0)return t.surfaceType;let n=U().surfaceType(e.wrapped);return t.surfaceType=n,n}function fD(e){let t=KE(e);if(t.isValid!==void 0)return t.isValid;let n=U().isValid(e.wrapped);return t.isValid=n,n}function pD(e){return{kind:uD(e),faceCount:XE(e).length,edgeCount:YE(e).length,wireCount:ZE(e).length,vertexCount:QE(e).length,valid:fD(e),bounds:lD(e)}}function mD(e){return U().vertexPosition(e.wrapped)}var G=2147483647,hD=Math.PI/180,gD=180/Math.PI;function _D(e){return e.length===2?[e[0],e[1],0]:[e[0],e[1],e[2]]}function vD(e){return[e[0],e[1]]}var yD={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function bD(e){if(typeof e==`string`){let t=yD[e];if(!t)throw Error(`Unknown direction: ${e}`);return t}return e}function xD(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function SD(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function CD(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function wD(e){return[-e[0],-e[1],-e[2]]}function TD(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function ED(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 DD(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function OD(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function kD(e,t){return DD(SD(e,t))}function AD(e){let t=DD(e);return t<1e-10?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function jD(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 MD(e,t=1e-10){return OD(e)<t*t}function ND(e,t){let n=TD(e,t),r=DD(e),i=DD(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 PD(e,t,n){let r=SD(e,t),i=OD(n);return i<1e-20?e:SD(e,CD(n,TD(r,n)/i))}function FD(e,t,n){let r=AD(t),i=Math.cos(n),a=Math.sin(n),o=TD(e,r),s=ED(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 ID=e=>Math.round(e*1e3)/1e3;function LD(e){return`x: ${ID(e[0])}, y: ${ID(e[1])}, z: ${ID(e[2])}`}function RD(e,t=null,n=[0,0,1]){let r=AD(n);if(MD(r))throw Error(`Plane normal must be non-zero`);let i;if(t)i=AD(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?AD([l,u,d]):[1,0,0]}if(MD(i))throw Error(`Plane xDir must be non-zero`);let a=AD(ED(r,i));return{origin:e,xDir:i,yDir:a,zDir:r}}var zD={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 BD(e,t=[0,0,0]){let n=zD[e];if(!n)return k(F(`UNKNOWN_PLANE`,`Could not find plane ${e}`));let r;return r=typeof t==`number`?CD(n.normal,t):_D(t),O(RD(r,n.xDir,n.normal))}function VD(e,t){return typeof e==`string`?BD(e,t):O(e)}function HD(e,t){return e&&typeof e!=`string`?{...e}:j(VD(e??`XY`,t))}function UD(e,t){let[n,r]=t;return xD(xD(e.origin,CD(e.xDir,n)),CD(e.yDir,r))}function WD(e,t){return{...e,origin:xD(e.origin,t)}}function GD(e,t,n=[1,0,0]){let r=t*hD,i=FD(e.zDir,n,r),a=FD(e.xDir,n,r),o=AD(ED(i,a));return{origin:e.origin,xDir:a,yDir:o,zDir:i}}var KD={compound:0,solidCompound:1,solid:2,shell:3,face:4,wire:5,edge:6,vertex:7,shape:8},qD=e=>KD[e],JD={vertex:`vertex`,edge:`edge`,wire:`wire`,face:`face`,shell:`shell`,solid:`solid`,solidCompound:`compsolid`,compound:`compound`,shape:`compound`},YD=function*(e,t){let n=U().iterShapes(e,JD[t]);for(let e of n)yield e},XD=e=>U().isNull(e)?k(mo(`NULL_SHAPE`,`This shape has no type, it is null`)):O(e.ShapeType());function ZD(e){if(U().isNull(e))return k(mo(`NULL_SHAPE`,`This shape has no type, it is null`));try{return O(U().downcast(e))}catch(e){return k(mo(`NO_WRAPPER`,`Could not find a wrapper for this shape type`,e))}}function QD(e){if(U().isNull(e))return k(mo(`NULL_SHAPE`,`Cannot copy a null shape`));try{return O(U().copyShape(e))}catch(e){return k(mo(`NO_WRAPPER`,`Could not copy this shape`,e))}}function $D(e){return U().isNull(e)?k(mo(`NULL_SHAPE`,`Cannot cast a null shape`)):O(AE(e))}function eO(e){return U().shapeType(e.wrapped)===`compsolid`}function tO(e){return $D(U().fromBREP(e))}var nO={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 rO(e){return O(nO[dD(e)])}function iO(e){return j(rO(e))}function aO(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function oO(e){return AE(U().reverseShape(e.wrapped))}function sO(e){return U().uvBounds(e.wrapped)}function cO(e,t,n){let r=sO(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 lO(e,t){let n=_D(t);return U().uvFromPoint(e.wrapped,n)||[0,0]}function uO(e,t){let n=_D(t);try{let t=n,r=U().uvFromPoint(e.wrapped,t);if(!r)return k(mo(`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(mo(`PROJECTION_FAILED`,`Point projection failed: ${e instanceof Error?e.message:String(e)}`))}}function dO(e,t){let n,r;if(t)[n,r]=lO(e,t);else{let t=sO(e);n=.5*(t.uMin+t.uMax),r=.5*(t.vMin+t.vMax)}return U().surfaceNormal(e.wrapped,n,r)}function fO(e){return U().surfaceCenterOfMass(e.wrapped)}function pO(e){return U().getSurfaceAxis(e.wrapped)}function mO(e,t,n=1e-6){let[r,i]=lO(e,t);return U().classifyPointOnFace(e.wrapped,r,i,n)}function hO(e){return AE(U().outerWire(e.wrapped))}function gO(e){return AE(U().removeHolesFromFace(e.wrapped))}function _O(e){let t=hO(e);return Array.from(YD(e.wrapped,`wire`)).map(e=>AE(j(ZD(e)))).filter(e=>!U().isSame(e.wrapped,t.wrapped))}function vO(e,t){let n=KE(e),r=U(),i=new Map;for(let n of r.iterShapes(e.wrapped,`face`))i.set(r.hashCode(n,G),t),r.dispose(n);n.faceOrigins=i}function yO(e){return qE(e)?.faceOrigins}function bO(e,t,n){let r=new Map;for(let e of t){let t=yO(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=KE(n);e.faceOrigins=i}}var xO=100,SO=.985,CO=.1;function wO(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>xO)continue;let u=r-l/xO;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)<SO)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>CO)continue;let u=Math.max(0,i*i+a*a+c*c-l*l);u<o&&(o=u,s=n.origin)}return s}function TO(e,t){let n=new Map;for(let t of e){let e=yO(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=XE(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=yO(n);if(e)for(let i of XE(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=wO(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=KE(t);e.faceOrigins=i}}var EO=new WeakMap,DO=new WeakMap;function OO(e){return EO.has(e.wrapped)}function kO(e){let t=EO.get(e.wrapped);return t||(t=new Map,EO.set(e.wrapped,t)),t}function AO(e){let t=DO.get(e.wrapped);return t||(t=new Map,DO.set(e.wrapped,t)),t}function jO(e,t,n){let r=Array.isArray(t)?t:XE(e).filter(t),i=kO(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 MO(e,t){let n=EO.get(e.wrapped);if(!n)return[];let r=n.get(t);if(!r||r.size===0)return[];let i=[];for(let t of XE(e)){let e=U().hashCode(t.wrapped,G);r.has(e)&&i.push(t)}return i}function NO(e){let t=new Map,n=EO.get(e.wrapped);if(!n)return t;let r=XE(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 PO(e,t,n){return AO(e).set(t,n),e}function FO(e,t){return DO.get(e.wrapped)?.get(t)}function IO(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function LO(e,t,n){let r=kO(n);for(let i of t){let t=EO.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)IO(r,t,e)}let o=DO.get(i.wrapped);if(o){let e=AO(n);for(let[t,n]of o)e.has(t)||e.set(t,n)}}}var RO=new WeakMap,zO=new WeakMap;function BO(e){return RO.has(e.wrapped)||zO.has(e.wrapped)}function VO(e){let t=zO.get(e.wrapped);return t||(t=new Map,zO.set(e.wrapped,t)),t}function HO(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 UO(e,t){return RO.set(e.wrapped,HO(t)),e}function WO(e,t,n){let r=HO(n),i=VO(e);for(let e of t)i.set(U().hashCode(e.wrapped,G),r);return e}function GO(e){return RO.get(e.wrapped)}function KO(e,t){let n=zO.get(e.wrapped);if(n)return n.get(U().hashCode(t.wrapped,G))}function qO(e,t,n){for(let e of t){let t=RO.get(e.wrapped);if(t){RO.set(n.wrapped,t);break}}let r=VO(n);for(let n of t){let t=zO.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 JO(e){return yO(e)!==void 0||OO(e)||BO(e)}function YO(e){if(!e.some(JO))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 XO(e,t,n){bO(e,t,n),LO(e,t,n),qO(e,t,n)}function ZO(e,t){TO(e,t)}function QO(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);XO({modified:a,generated:new Map,deleted:new Set},[e],t)}function $O(e,t){let n=YO([e]),{shape:r,evolution:i}=U().translateWithHistory(e.wrapped,t[0],t[1],t[2],n,G),a=W(r);return XO(i,[e],a),a}function ek(e,t,n=[0,0,0],r=[0,0,1]){let i=YO([e]),{shape:a,evolution:o}=U().rotateWithHistory(e.wrapped,t*hD,i,G,r,n),s=W(a);return XO(o,[e],s),s}function tk(e,t=[0,1,0],n=[0,0,0]){let r=YO([e]),{shape:i,evolution:a}=U().mirrorWithHistory(e.wrapped,n,t,r,G),o=W(i);return XO(a,[e],o),o}function nk(e,t,n=[0,0,0]){let r=YO([e]),{shape:i,evolution:a}=U().scaleWithHistory(e.wrapped,n,t,r,G),o=W(i);return XO(a,[e],o),o}function rk(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(nk(e,c[0])):k(F(N.VALIDATION_FAILED,`resize: non-uniform scaling is not supported (WASM build lacks BRepBuilderAPI_GTransform).`,void 0,void 0,`Use auto: true to scale proportionally, or set all three dimensions to achieve uniform scaling.`))}function ik(e){if(`linear`in e)return O({linear:e.linear,translation:e.translation});let[t,n,r,i]=e,a=1e-10;return Math.abs(i[0])>a||Math.abs(i[1])>a||Math.abs(i[2])>a||Math.abs(i[3]-1)>a?k(F(N.VALIDATION_FAILED,`applyMatrix: invalid bottom row [${String(i[0])}, ${String(i[1])}, ${String(i[2])}, ${String(i[3])}]. Must be [0, 0, 0, 1] for an affine transform.`)):O({linear:[t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]],translation:[t[3],n[3],r[3]]})}function ak(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 ok(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 sk(e,t){let n=ik(t);if(!n.ok)return n;let{linear:r,translation:i}=n.value,a=ak(r);if(Math.abs(a)<1e-12)return k(F(N.VALIDATION_FAILED,`applyMatrix: singular matrix (determinant ≈ 0). Cannot apply a non-invertible transform.`));if(ok(r)){let t=YO([e]),{shape:n,evolution:a}=U().generalTransformWithHistory(e.wrapped,r,i,!0,t,G),o=W(n);return XO(a,[e],o),O(o)}let o=W(U().generalTransformNonOrthogonal(e.wrapped,r,i));return ZO([e],o),O(o)}function ck(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 lk(e,t){let{trsf:n,cleanup:r}=ck(`type`in t?[t]:t),i;try{i=W(U().locate(e.wrapped,n))}finally{r()}return JO(e)&&QO(e,i),i}function uk(e,t){let n=YO([e]),{shape:r,evolution:i}=U().applyComposedTransformWithHistory(e.wrapped,t.trsf,n,G),a=W(r);return XO(i,[e],a),a}function dk(e){return zE(()=>U().copyShape(e.wrapped),N.CLONE_FAILED,`Failed to clone shape`)}function fk(e){return BE(()=>U().toBREP(e.wrapped),N.TO_BREP_FAILED,`Failed to serialize shape to BREP`)}function pk(e){return U().hashCode(e.wrapped,G)}function mk(e){return U().isNull(e.wrapped)}function hk(e,t){return U().isSame(e.wrapped,t.wrapped)}function gk(e,t){return U().isEqual(e.wrapped,t.wrapped)}function _k(e){return zE(()=>U().simplify(e.wrapped),N.SIMPLIFY_FAILED,`Failed to simplify shape`)}function vk(e){return U().curveType(e.wrapped)}function yk(e){let[t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function bk(e){let[,t]=U().curveParameters(e.wrapped);return U().curvePointAtParam(e.wrapped,t)}function xk(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curvePointAtParam(e.wrapped,i)}function Sk(e,t=.5){let[n,r]=U().curveParameters(e.wrapped),i=n+(r-n)*t;return U().curveTangent(e.wrapped,i).tangent}function Ck(e){return U().length(e.wrapped)}function wk(e){if(vk(e)!==`CIRCLE`)return null;let t=xk(e,0),n=xk(e,1/3),r=xk(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 Tk(e){return U().curveIsClosed(e.wrapped)}function Ek(e){return U().curveIsPeriodic(e.wrapped)}function Dk(e){return U().curvePeriod(e.wrapped)}function Ok(e){return U().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function kk(e){return W(U().reverseShape(e.wrapped))}function Ak(e,t={}){if(e.length<2)return k(mo(`INTERPOLATE_MIN_POINTS`,`Interpolation requires at least 2 points`));try{let n=W(U().interpolatePoints(e,t));return SE(n)?O(n):(PE(n),k(mo(`INTERPOLATE_NOT_EDGE`,`Interpolation did not produce an edge`)))}catch(e){return k(mo(`INTERPOLATE_FAILED`,`Interpolation failed: ${e instanceof Error?e.message:String(e)}`))}}function jk(e,t={}){if(e.length<2)return k(mo(`APPROXIMATE_MIN_POINTS`,`Approximation requires at least 2 points`));try{let n=W(U().approximatePoints(e,t));return SE(n)?O(n):(PE(n),k(mo(`APPROXIMATE_NOT_EDGE`,`Approximation did not produce an edge`)))}catch(e){return k(mo(`APPROXIMATE_FAILED`,`Approximation failed: ${e instanceof Error?e.message:String(e)}`))}}function Mk(e,t,n=`arc`){let r=W(U().offsetWire2D(e.wrapped,t,{arc:`arc`,intersection:`intersection`,tangent:`tangent`,chamfer:`intersection`}[n]));return CE(r)?O(r):(PE(r),k(mo(`OFFSET_NOT_WIRE`,`Offset did not produce a Wire`)))}function Nk(e,t,n,r=!1){return`${e}:${t}:${n}:${r}`}function Pk(e,t){return`edge:${e}:${t}`}var Fk=new WeakMap,Ik=new WeakMap;function Lk(e,t){let n=Fk.get(e);if(n)return n.get(t)}function Rk(e,t,n){let r=Fk.get(e);r||(r=new Map,Fk.set(e,r)),r.set(t,n)}function zk(e,t){let n=Ik.get(e);if(n)return n.get(t)}function Bk(e,t,n){let r=Ik.get(e);r||(r=new Map,Ik.set(e,r)),r.set(t,n)}function Vk(){Fk=new WeakMap,Ik=new WeakMap}function Hk(){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 Uk(e,t={}){let n=wo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,skipNormals:a=!1,includeUVs:o=!1,cache:s=!0,signal:c}=t;c?.throwIfAborted();let l=Nk(r,i,a,o);if(s){let t=Lk(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=yO(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&&Rk(e.wrapped,l,f),f}function Wk(e,t={}){let n=wo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,cache:a=!0}=t,o=Pk(r,i);if(a){let t=zk(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&&Bk(e.wrapped,o,c),c}function Gk(e,t){return e instanceof Error&&e.message.startsWith(`${t} export failed`)?_o(`${t}_EXPORT_FAILED`,`Failed to write ${t} file`,e):e instanceof WebAssembly.RuntimeError?_o(`${t}_EXPORT_CRASHED`,`${t} export crashed the kernel (${e.message}); the shape likely contains geometry the ${t} writer cannot serialize`,e):_o(`${t}_FILE_READ_ERROR`,`Failed to read exported ${t} file`,e)}function Kk(e){let t;try{t=$E(e)}catch{return``}if(t.length<=1)return``;let n=[];return t.forEach((e,t)=>{try{lD(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 qk(e,t){try{return lD(e),null}catch(n){if(n instanceof TypeError)throw n;return _o(`${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${Kk(e)}`,n)}}function Jk(e){let t=qk(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(Gk(e,`STEP`))}}function Yk(e,t={}){let n=wo(),{tolerance:r=n.tolerance,angularTolerance:i=n.angularTolerance,binary:a=!1}=t,o=qk(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(Gk(e,`STL`))}}function Xk(e){try{let t=U().exportIGES([e.wrapped]);return O(new Blob([t],{type:`application/iges`}))}catch(e){return k(_o(`IGES_EXPORT_FAILED`,`Failed to write IGES file`,e))}}function Zk(e,t){let n=t?.coarseTolerance??.5,r=t?.fineTolerance??.05,i=t?.angularTolerance??.5;return{coarse:Uk(e,{tolerance:n,angularTolerance:i}),fine:Uk(e,{tolerance:r,angularTolerance:i*.2})}}function Qk(e){let t=lD(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 $k(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)*Qk(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 eA(e,t,n){return Math.min(e/t*n,1)}function tA(e,t={}){let n=t.angularTolerance??wo().angularTolerance,r=t.cache??!0,i=$k(e,t),a=Math.min(...i);return i.map(i=>{let o=eA(i,a,n);return{tolerance:i,angularTolerance:o,mesh:Uk(e,{tolerance:i,angularTolerance:o,cache:r,...t.signal?{signal:t.signal}:{}})}})}function nA(){return new Promise(e=>{setTimeout(e,0)})}async function rA(e,t={}){let n=t.angularTolerance??wo().angularTolerance,r=t.cache??!0,i=t.meshLevel??((e,n,i)=>Uk(e,{tolerance:n,angularTolerance:i,cache:r,...t.signal?{signal:t.signal}:{}})),a=$k(e,t),o=Math.min(...a),s=[];for(let[r,c]of a.entries()){if(t.signal?.aborted)break;let l=eA(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 nA()}return s}function iA(e,t,n){if(t<0||t>=e.length)throw Error(n??`Index ${t} out of bounds (length ${e.length})`);return e[t]}function aA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[0]}function oA(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[e.length-1]}function sA(e){return Array.from(Array(e).keys())}function cA(e){return sA(Math.min(...e.map(e=>e.length))).map(t=>e.map(e=>e[t]))}function lA(e,t){return mE(U().makeLineEdge([...e],[...t]))}function uA(e,t=[0,0,0],n=[0,0,1]){return mE(U().makeCircleEdge([...t],[...n],e))}function dA(e,t,n=[0,0,0],r=[0,0,1],i){return t>e?k(F(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(mE(U().makeEllipseEdge([...n],[...r],e,t,i?[...i]:void 0)))}function fA(e,t,n,r=[0,0,0],i=[0,0,1],a=!1){return hE(U().makeHelixWire(e,t,n,[...r],[...i],a))}function pA(e,t,n){return mE(U().makeArcEdge([...e],[...t],[...n]))}function mA(e,t,n,r,i=[0,0,0],a=[0,0,1],o){return t>e?k(F(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):O(mE(U().makeEllipseArc([...i],[...a],e,t,n,r,o?[...o]:void 0)))}function hA(e,{tolerance:t=.001,smoothing:n=null,degMax:r=6,degMin:i=1}={}){try{let a=e.map(e=>[...e]);return O(mE(U().approximatePoints(a,{tolerance:t,degMin:i,degMax:r,smoothing:n})))}catch(e){return k(P(`BSPLINE_FAILED`,`B-spline approximation failed`,e))}}function gA(e,{periodic:t=!1,tolerance:n=1e-7}={}){try{let r=e.map(e=>[...e]);return O(mE(U().interpolatePoints(r,{periodic:t,tolerance:n})))}catch(e){return k(P(`BSPLINE_INTERP_FAILED`,`B-spline interpolation failed`,e))}}function _A(e){if(e.length<2)return k(F(`BEZIER_MIN_POINTS`,`Need at least 2 points for a Bezier curve, got ${e.length}`,void 0,{pointCount:e.length}));let t=e.map(e=>[...e]);return O(mE(U().makeBezierEdge(t)))}function vA(e,t,n){return mE(U().makeTangentArc([...e],[...t],[...n]))}function yA(e){try{return O(hE(U().makeWireFromMixed(e.map(e=>e.wrapped))))}catch(e){return k(P(`WIRE_BUILD_FAILED`,`Failed to build the wire: ${e instanceof Error?e.message:`unknown error`}`))}}function bA(e,t){try{let n=U().makeFace(e.wrapped,!0);if(t&&t.length>0){let e=wA(gE(n),t);return cE(e)?O(e):k(F(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}let r=gE(n);return cE(r)?O(r):k(F(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}catch(e){return k(P(`FACE_BUILD_FAILED`,`Failed to build the face. Your wire might be non planar.`,e))}}function xA(e){return bA(hO(e))}function SA(e,t){return gE(U().makeFaceOnSurface(e.wrapped,t.wrapped))}function CA(e){try{return Va($D(U().makeNonPlanarFace(e.wrapped)),e=>wE(e)?O(e):k(P(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`)))}catch(e){return k(P(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`,e))}}function wA(e,t){return gE(U().addHolesInFace(e.wrapped,t.map(e=>e.wrapped)))}function TA(e){return e.length<3?k(F(`POLYGON_MIN_POINTS`,`You need at least 3 points to make a polygon`)):Va(yA(cA([e,[...e.slice(1),e[0]]]).map(([e,t])=>lA(e,t))),e=>bA(e))}function EA(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function DA(e,t,n,r,i){let a=AE(e);if(!OE(a)){let o=$T(a).toUpperCase();return ME(e,a),PE(a),k(mo(t,`${n}. Got ${o} instead.`,void 0,i?{diagnostics:i}:void 0,r))}return ME(e,a),O(a)}function OA(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=EA(e,`fuse: first operand`);if(A(c))return c;let l=EA(t,`fuse: second operand`);if(A(l))return l;if(!s)return DA(U().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);let u=YO([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),DA(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=DA(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&&XO(f,[e,t],m.value),m}function kA(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;let c=EA(e,`cut: base`);if(A(c))return c;let l=EA(t,`cut: tool`);if(A(l))return l;if(!s)return DA(U().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);let u=YO([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),DA(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=DA(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&&XO(f,[e,t],m.value),m}function AA(e,t,{simplify:n=!1,signal:r,fuzzyValue:i,unsafe:a,trackEvolution:o=!0}={}){if(r?.aborted)throw r.reason;let s=EA(e,`intersect: first operand`);if(A(s))return s;let c=EA(t,`intersect: second operand`);if(A(c))return c;if(!o)return DA(U().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);let l=YO([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),DA(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=DA(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&&XO(d,[e,t],p.value),p}function jA(e,t,n,r,i,a,o,s){if(o?.aborted)throw o.reason;let c=n-t;if(c===1)return O(iA(e,t));if(c===2)return OA(iA(e,t),iA(e,t+1),{optimisation:r,simplify:!1,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}});let l=t+Math.ceil(c/2),u=jA(e,t,l,r,i,a,o,s);if(A(u))return u;let d=jA(e,l,n,r,i,a,o,s);return A(d)?d:OA(u.value,d.value,{optimisation:r,simplify:i,trackEvolution:a,fuzzyValue:s,unsafe:!0,...o?{signal:o}:{}})}function MA(e,{optimisation:t=`none`,simplify:n=!1,strategy:r=`native`,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;if(e.length===0)return k(F(`FUSE_ALL_EMPTY`,`fuseAll requires at least one shape`));if(e.length===1)return O(aA(e));for(let t=0;t<e.length;t++){let n=EA(iA(e,t),`fuseAll: shape at index ${t}`);if(A(n))return n}if(r===`native`){let o=DA(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&&ZO(e,o.value),o}return jA(e,0,e.length,t,n,s,i,a)}function NA(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=EA(e,`cutAll: base`);if(A(c))return c;for(let e=0;e<t.length;e++){let n=EA(iA(t,e),`cutAll: tool at index ${e}`);if(A(n))return n}let l=[e,...t],u=DA(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&&ZO(l,u.value),u}function PA(e,t){let n=U(),r=CD(e.xDir,t),i=CD(e.yDir,t),a=CD(e.xDir,-t),o=CD(e.yDir,-t),s=e.origin,c=[...xD(xD(s,a),o)],l=[...xD(xD(s,r),o)],u=[...xD(xD(s,r),i)],d=[...xD(xD(s,a),i)],f=[n.makeLineEdge(c,l),n.makeLineEdge(l,u),n.makeLineEdge(u,d),n.makeLineEdge(d,c)],p=n.makeWire(f),m=n.makeFace(p,!0);for(let e of f)e.delete();return p.delete(),m}function FA(e,t,{approximation:n=!0,planeSize:r=1e4}={}){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`section: shape is a null shape`));let i=PA(typeof t==`string`?j(VD(t)):t,r);try{return O(W(U().section(e.wrapped,i,n)))}catch(e){let n=e instanceof Error?e.message:String(e),r=typeof t==`string`?t:`custom`;return k(P(`SECTION_FAILED`,`Section with ${r} plane failed: ${n}`,e,{operation:`section`,plane:r},`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`))}finally{i.delete()}}function IA(e){let t=U(),n=new Map,r=new Map;for(let i of e){let e=QE(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 LA(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 RA(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=LA(i,t,n);for(;o;)e===0?r.push(o.edge):r.unshift(o.edge),i=o.nextTip,o=LA(i,t,n)}return r}function zA(e){let t=U(),n=IA(e),r=new Set,i=[];for(let a of e){if(r.has(a))continue;let e=RA(a,n,r);try{let n=t.makeWire(e.map(e=>e.wrapped));i.push(W(n))}catch{}}return i}function BA(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 VA(e,t,n={}){let r=FA(e,t,n);if(!r.ok)return r;let i=ZE(r.value);if(i.length===0){let e=YE(r.value);if(e.length===0)return k(P(`SECTION_FAILED`,`sectionToFace: section produced no geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));i.push(...zA(e))}if(i.length===0)return k(P(`SECTION_FAILED`,`sectionToFace: section produced no usable geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));let a=BA(i),o=iA(i,a),s=i.filter((e,t)=>t!==a);return bA(o,s.length>0?s:void 0)}function HA(e,t){if(t.length===0)return O(e);if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`split: shape is a null shape`));for(let e=0;e<t.length;e++)if(U().isNull(iA(t,e).wrapped))return k(F(N.NULL_SHAPE_INPUT,`splitShape: tool at index ${e} is a null shape`));try{return O(W(U().split(e.wrapped,t.map(e=>e.wrapped))))}catch(e){let n=e instanceof Error?e.message:String(e);return k(P(`SPLIT_FAILED`,`Split operation failed on ${t.length} tool(s): ${n}`,e,{operation:`split`,toolCount:t.length},`The splitting tools may not intersect the shape. Ensure tools cross through the shape's interior.`))}}function UA(e,t,n={}){let r=[];for(let i of t){let t=FA(e,i,n);if(A(t))return t;r.push(t.value)}return O(r)}function WA(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 GA(e,t,n);if(o===null)return k(P(`BOOLEAN_PIPELINE_FAILED`,`Boolean pipeline returned null shape`));let s=W(o);return OE(s)?O(s):(PE(s),k(mo(`BOOLEAN_PIPELINE_NOT_3D`,`Pipeline result is not a 3D shape`)))}catch(e){return k(P(`BOOLEAN_PIPELINE_FAILED`,e instanceof Error?e.message:String(e)))}}function GA(e,t,n){let r=e,i={...n?.optimisation?{optimisation:n.optimisation}:{},unsafe:!0};for(let e of t){let t=e.op===`fuse`?OA(r,e.tool,i):e.op===`cut`?kA(r,e.tool,i):AA(r,e.tool,i);if(A(t))return t;r=j(t)}return O(r)}function KA(e){return j($D(j(ZD(U().sew(e.map(e=>e.wrapped))))))}function qA(e,t=!1){let n=KA(e);return!t&&!TE(n)?k(mo(`WELD_NOT_SHELL`,`Could not make a shell from faces and shells`)):O(n)}function JA(e,t,n=[0,0,0],r=[0,0,1]){return vE(U().makeCylinder(e,t,[...n],[...r]))}function YA(e){return vE(U().makeSphere(e))}function XA(e,t,n,r=[0,0,0],i=[0,0,1]){return vE(U().makeCone(e,t,n,[...r],[...i]))}function ZA(e,t,n=[0,0,0],r=[0,0,1]){return vE(U().makeTorus(e,t,[...n],[...r]))}function QA(e,t,n){return vE(U().makeEllipsoid(e,t,n))}function $A(e){return pE(U().makeVertex(e[0],e[1],e[2]))}function ej(e,t,n=1e-6){return Va(ZD(U().offset(e.wrapped,t,n)),e=>Va($D(e),e=>OE(e)?O(e):k(mo(`OFFSET_NOT_3D`,`Could not offset to a 3d shape`))))}function tj(e){return bE(U().makeCompound(e.map(e=>e.wrapped)))}function nj(e){let t=KA(e);return Va($D(U().solidFromShell(t.wrapped)),e=>EE(e)?O(e):k(mo(`SOLID_BUILD_FAILED`,`Could not make a solid of faces and shells`)))}function rj(e){return{position:e.vertices,normal:e.normals,index:e.triangles}}function ij(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 aj(e){return{position:e.lines}}function oj(e,t){return{coarse:rj(e.coarse),fine:rj(e.fine),coarseDistance:t?.coarse??50,fineDistance:t?.fine??0}}function sj(e,t){let n=t?.step??50,r=t?.distances;if(r&&r.length!==e.length)throw Error(`toLODGeometryLevels: distances must have one entry per level (got ${r.length} for ${e.length} levels)`);let i=e.length-1;return e.map((e,t)=>({geometry:rj(e.mesh),distance:r?.[t]??(i-t)*n}))}function cj(e,t,n,r){if(t.length===0)return k(F(`CHAMFER_ANGLE_NO_EDGES`,`chamferDistAngle requires at least one edge`,void 0,{edgeCount:0}));if(n<=0)return k(F(`CHAMFER_ANGLE_BAD_DISTANCE`,`distance must be positive, got ${n}`,void 0,{distance:n}));if(r<=0||r>=90)return k(F(`CHAMFER_ANGLE_BAD_ANGLE`,`angleDeg must be in range (0, 90), got ${r}`,void 0,{angleDeg:r}));let i;try{let a=U(),o=t.map(e=>e.wrapped);i=a.chamferDistAngle(e.wrapped,o,n,r)}catch(e){return k(P(`CHAMFER_ANGLE_FAILED`,`chamferDistAngle kernel call failed: ${e instanceof Error?e.message:String(e)}`,e,{distance:n,angleDeg:r,edgeCount:t.length}))}let a=ZD(i);if(A(a))return U().dispose(i),a;let o=W(a.value);return ME(i,o),OE(o)?O(o):(PE(o),k(mo(`CHAMFER_ANGLE_NOT_3D`,`chamferDistAngle did not produce a 3D shape`)))}function lj(e){let t=U();return t.getNurbsCurveData?t.getNurbsCurveData(e.wrapped):null}function uj(e){let t=U();return t.getNurbsSurfaceData?t.getNurbsSurfaceData(e.wrapped):null}var dj={cut:kA,cutAll:NA,fuse:OA,fuseAll:MA};function fj(e){return{totalInputs:e.totalInputs,batchAttempts:e.batchAttempts,batchSucceeded:e.batchSucceeded,singletonFallbacks:e.singletonFallbacks,failedInputs:[...e.failedInputs].sort((e,t)=>e-t)}}function pj(e,t,n={}){return mj(dj,e,t,n)}function mj(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=hj(e,t,n,0,r,i);return A(a)?a:O({shape:a.value,telemetry:fj(i)})}function hj(e,t,n,r,i,a){if(n.length===0)return O(t);if(n.length===1)return gj(e,t,n,r,i,a);a.batchAttempts++;let o=xj(()=>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=hj(e,t,n.slice(0,s),r,i,a);return c.ok?hj(e,c.value,n.slice(s),r+s,i,a):c}function gj(e,t,n,r,i,a){a.singletonFallbacks++;let o=aA(n),s=xj(()=>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 _j(e,t={}){return vj(dj,e,t)}function vj(e,t,n={}){if(n.signal?.aborted)throw n.signal.reason;if(t.length===0)return k(F(N.FUSE_ALL_EMPTY,`fuseAllBisect requires at least one shape`));let r={totalInputs:t.length,batchAttempts:0,batchSucceeded:0,singletonFallbacks:0,failedInputs:new Set},i=yj(e,t,0,n,r);return A(i)?i:O({shape:i.value,telemetry:fj(r)})}function yj(e,t,n,r,i){if(t.length===1)return O(aA(t));i.batchAttempts++;let a=xj(()=>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 bj(e,yj(e,t.slice(0,o),n,r,i),yj(e,t.slice(o),n+o,r,i),t,n,o,r,i)}function bj(e,t,n,r,i,a,o,s){if(t.ok&&n.ok){s.singletonFallbacks++;let c=xj(()=>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 xj(e){try{return e()}catch{return null}}function Sj(e,t,n){return U().checkBoolean(e.wrapped,t.wrapped,n)}function Cj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function wj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Tj(e,t,n,r){let i=AE(e);if(!OE(i)){let a=$T(i).toUpperCase();return ME(e,i),PE(i),k(mo(t,`${n}. Got ${a} instead.`,void 0,void 0,r))}return ME(e,i),O(i)}function Ej(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(U().hashCode(i.wrapped,G),e))}return n.length===0?null:{edges:n,kernelParam:e=>r.get(U().hashCode(e,2147483647))??1}}function Dj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Cj(e,`fuseWithEvolution: first operand`);if(A(o))return o;let s=Cj(t,`fuseWithEvolution: second operand`);if(A(s))return s;let c=YO([e,t]),{shape:l,evolution:u}=U().fuseWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Tj(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?(XO(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function Oj(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=Cj(e,`cutWithEvolution: base`);if(A(o))return o;let s=Cj(t,`cutWithEvolution: tool`);if(A(s))return s;let c=YO([e,t]),{shape:l,evolution:u}=U().cutWithHistory(e.wrapped,t.wrapped,c,G,{optimisation:n,simplify:r,fuzzyValue:a}),d=Tj(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?(XO(u,[e,t],d.value),O({shape:d.value,evolution:u})):d}function kj(e,t,{simplify:n=!1,signal:r,fuzzyValue:i}={}){if(r?.aborted)throw r.reason;let a=Cj(e,`intersectWithEvolution: first operand`);if(A(a))return a;let o=Cj(t,`intersectWithEvolution: second operand`);if(A(o))return o;let s=YO([e,t]),{shape:c,evolution:l}=U().intersectWithHistory(e.wrapped,t.wrapped,s,G,{simplify:n,fuzzyValue:i}),u=Tj(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?(XO(l,[e,t],u.value),O({shape:u.value,evolution:l})):u}function Aj(e,t,n){let r=wj(e,`filletWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(F(`INVALID_FILLET_RADIUS`,`Fillet radius must be positive`,void 0,void 0,`Provide a positive radius value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(F(`INVALID_FILLET_RADIUS`,`Fillet radii must both be positive`,void 0,void 0,`Both radius values must be greater than 0`));let i=t??YE(e);if(i.length===0)return k(F(N.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));try{let t,r;if(typeof n==`function`){let e=Ej(i,n);if(!e)return k(F(N.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=YO([e]),{shape:o,evolution:s}=U().filletWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return OE(c)?(XO(s,[e],c),O({shape:c,evolution:s})):(PE(c),k(P(N.FILLET_NOT_3D,`Fillet result is not a 3D shape`)))}catch(e){return k(P(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:i.length,radius:n}))}}function jj(e,t,n){let r=wj(e,`chamferWithEvolution: shape`);if(A(r))return r;if(typeof n==`number`&&n<=0)return k(F(`INVALID_CHAMFER_DISTANCE`,`Chamfer distance must be positive`,void 0,void 0,`Provide a positive distance value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return k(F(`INVALID_CHAMFER_DISTANCE`,`Chamfer distances must both be positive`,void 0,void 0,`Both distance values must be greater than 0`));let i=t??YE(e);if(i.length===0)return k(F(N.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=Ej(i,n);if(!e)return k(F(N.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=YO([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,G),c=W(o);return OE(c)?(XO(s,[e],c),O({shape:c,evolution:s})):(PE(c),k(P(N.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)))}catch(e){return k(P(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:i.length,distance:n}))}}function Mj(e,t,n,r=.001){let i=wj(e,`shellWithEvolution: shape`);if(A(i))return i;if(n<=0)return k(F(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(F(`NO_FACES`,`At least one face must be specified for shell`));try{let i=YO([e]),{shape:a,evolution:o}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,i,G,r),s=W(a);return OE(s)?(XO(o,[e],s),O({shape:s,evolution:o})):(PE(s),k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}catch(e){return k(P(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function Nj(e,t,n){try{let r=W(U().positionOnCurve(e.wrapped,t.wrapped,n));return OE(r)?O(r):(PE(r),k(P(N.POSITION_ON_CURVE_FAILED,`positionOnCurve did not produce a 3D shape`)))}catch(e){return k(P(N.POSITION_ON_CURVE_FAILED,`Failed to position shape on curve at param ${n}`,e))}}function Pj(e,t){return U().isNull(e.wrapped)?k(F(N.NULL_SHAPE_INPUT,`${t} is a null shape`)):O(void 0)}function Fj(e,t){if(typeof e==`number`&&e<=0)return k(F(t.code,t.scalar,void 0,void 0,t.scalarHint));if(Array.isArray(e)&&(e[0]<=0||e[1]<=0))return k(F(t.code,t.pair,void 0,void 0,t.pairHint))}function Ij(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 Lj(e,t,n,r,i){let a=W(t);return OE(a)?(XO(e,n,a),O(a)):(PE(a),k(P(r,i)))}function Rj(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 zj(e,t){let n=Pj(e,`thicken: shape`);if(A(n))return n;try{let n=YO([e]),{shape:r,evolution:i}=U().thickenWithHistory(e.wrapped,t,n,G),a=W(r);return XO(i,[e],a),O(a)}catch(e){return k(P(`THICKEN_FAILED`,`Thicken operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function Bj(e,t,n){let r=Pj(e,`fillet: shape`);if(A(r))return r;let i=Fj(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??YE(e);if(a.length===0)return k(F(N.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));if(typeof n==`function`){let e=Ij(a,n);return e?O({filteredEdges:e.edges,kernelRadius:e.kernelParam,selectedCount:a.length}):k(F(N.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`))}return O({filteredEdges:[...a],kernelRadius:n,selectedCount:a.length})}function Vj(e,t,n,{trackEvolution:r=!0}={}){let i=Bj(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 OE(n)?O(n):k(P(N.FILLET_NOT_3D,`Fillet result is not a 3D shape`))}let n=YO([e]),{shape:i,evolution:s}=U().filletWithHistory(e.wrapped,t,o,n,G);return Lj(s,i,[e],N.FILLET_NOT_3D,`Fillet result is not a 3D shape`)}catch(e){return k(P(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:s,radius:n}))}}function Hj(e,t,n){let r=Pj(e,`chamfer: shape`);if(A(r))return r;let i=Fj(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??YE(e);if(a.length===0)return k(F(N.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=Ij(a,n);if(!e)return k(F(N.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...a],r=n;let i=YO([e]),{shape:o,evolution:s}=U().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,i,G);return Lj(s,o,[e],N.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)}catch(e){return k(P(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:a.length,distance:n}))}}function Uj(e,t,n,r=.001,{trackEvolution:i=!0}={}){let a=Pj(e,`shell: shape`);if(A(a))return a;if(n<=0)return k(F(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return k(F(`NO_FACES`,`At least one face must be specified for shell`));try{if(!i){let i=W(U().shell(e.wrapped,t.map(e=>e.wrapped),n,r));return OE(i)?O(i):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}let a=YO([e]),{shape:o,evolution:s}=U().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,a,G,r),c=W(o);return OE(c)?(XO(s,[e],c),O(c)):k(P(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`))}catch(e){return k(P(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function Wj(e,t,n=1e-6){let r=Pj(e,`offset: shape`);if(A(r))return r;if(Math.abs(t)<1e-10)return k(F(`ZERO_OFFSET`,`Offset distance cannot be zero`));try{let r=YO([e]),{shape:i,evolution:a}=U().offsetWithHistory(e.wrapped,t,r,G,n),o=W(i);return OE(o)?(XO(a,[e],o),O(o)):k(P(`OFFSET_RESULT_NOT_3D`,`Offset result is not a 3D shape`))}catch(e){return k(P(`OFFSET_FAILED`,`Offset operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function Gj(e,t,n){let r=Pj(e,`draft: shape`);if(A(r))return r;if(typeof n==`number`){if(Math.abs(n)<1e-10)return k(F(N.DRAFT_INVALID_ANGLE,`Draft angle cannot be zero`,void 0,void 0,`Provide a non-zero angle in degrees`));if(Math.abs(n)>=90)return k(F(N.DRAFT_INVALID_ANGLE,`Draft angle must be between -90 and 90 degrees (exclusive)`,void 0,void 0,`Typical draft angles are 1-5 degrees for injection molding`))}if(t.length===0)return k(F(N.DRAFT_NO_FACES,`No faces specified for draft`,void 0,void 0,`Select at least one face to apply the draft angle to`))}function Kj(e,t,n,r,i){let a=Gj(e,t,i);if(a)return a;try{let{filteredFaces:a,kernelAngle:o}=Rj(t,i);if(a.length===0)return k(F(N.DRAFT_NO_FACES,`No faces with valid draft angle`,void 0,void 0,`Check that the angle callback returns non-zero values between -90 and 90 degrees`));let s=YO([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 Lj(l,c,[e],N.DRAFT_NOT_3D,`Draft result is not a 3D shape`)}catch(e){let n=e instanceof Error?e.message:String(e);return k(P(N.DRAFT_FAILED,`Draft operation failed: ${n}`,e,{operation:`draft`,faceCount:t.length,angle:i}))}}function qj(e,t,n){if(n.length===0)return k(F(N.VARIABLE_FILLET_FAILED,`radii must contain at least one radius spec`));for(let e of n)if(e.radius<=0)return k(F(N.VARIABLE_FILLET_FAILED,`All radius values must be positive`));let r=U();try{let i=JSON.stringify({edge:r.hashCode(t.wrapped,G),radii:n.map(e=>({param:e.param,radius:e.radius}))}),a=W(r.filletVariable(e.wrapped,i));return OE(a)?EE(a)?O(a):(PE(a),k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a solid`))):(PE(a),k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a 3D shape`)))}catch(e){return k(P(N.VARIABLE_FILLET_FAILED,`Variable-radius fillet failed`,e))}}function Jj(e){return fD(e)}function Yj(e){if(!EE(e))return k(F(`NOT_A_SOLID`,`Input shape is not a solid`));let t=Jj(e);try{let n=U().healSolid(e.wrapped);if(!n)return t?O(e):k(P(N.HEAL_NO_EFFECT,`Solid healing had no effect — shape is still invalid`));let r=W(n);return EE(r)?(JE(r),Jj(r)?O(r):(PE(r),k(P(`HEAL_SOLID_INCOMPLETE`,`Healed result is still invalid after ShapeFix_Solid`)))):(PE(r),k(P(`HEAL_RESULT_NOT_SOLID`,`Healed result is not a solid`)))}catch(e){return k(P(`HEAL_SOLID_FAILED`,`Solid healing failed`,e))}}function Xj(e){if(!wE(e))return k(F(`NOT_A_FACE`,`Input shape is not a face`));try{let t=W(U().healFace(e.wrapped));return wE(t)?O(t):(PE(t),k(P(`HEAL_RESULT_NOT_FACE`,`Healed result is not a face`)))}catch(e){return k(P(`HEAL_FACE_FAILED`,`Face healing failed`,e))}}function Zj(e,t){if(!CE(e))return k(F(`NOT_A_WIRE`,`Input shape is not a wire`));try{let n=W(U().healWire(e.wrapped,t?.wrapped));return CE(n)?O(n):(PE(n),k(P(`HEAL_RESULT_NOT_WIRE`,`Healed result is not a wire`)))}catch(e){return k(P(`HEAL_WIRE_FAILED`,`Wire healing failed`,e))}}function Qj(e){return EE(e)?Yj(e):wE(e)?Xj(e):CE(e)?Zj(e):O(e)}function $j(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(Jj(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=ZE(e).length,u=XE(e).length,d=e,f=!1,p=t=>{let n=d;d=t,n!==e&&n.wrapped!==t.wrapped&&PE(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=ZE(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(EE(d)&&i||wE(d)&&r||CE(d)&&n){let t=Qj(d);Ra(t)?(p(t.value),EE(e)?(f=!0,s.push(`Applied ShapeFix_Solid`),c.push({name:`healSolid`,attempted:!0,succeeded:!0})):wE(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=ZE(d).length,h=XE(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=Jj(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 eM(e){try{return O(W(U().fixShape(e.wrapped)))}catch(e){return k(P(N.FIX_SHAPE_FAILED,`ShapeFix_Shape failed`,e))}}function tM(e){try{let t=W(U().solidFromShell(e.wrapped));return EE(t)?Jj(t)?O(t):(PE(t),k(P(N.SOLID_FROM_SHELL_FAILED,`solidFromShell produced an invalid solid`))):(PE(t),k(P(N.SOLID_FROM_SHELL_FAILED,`solidFromShell did not produce a solid`)))}catch(e){return k(P(N.SOLID_FROM_SHELL_FAILED,`Failed to create solid from shell`,e))}}function nM(e){try{let t=W(U().fixSelfIntersection(e.wrapped));return CE(t)?O(t):(PE(t),k(P(N.FIX_SELF_INTERSECTION_FAILED,`Result is not a wire`)))}catch(e){return k(P(N.FIX_SELF_INTERSECTION_FAILED,`Failed to fix wire self-intersection`,e))}}function rM(e,{profile:t,endFactor:n=1}){return e<1e-10?k(F(`INVALID_EXTRUSION_LENGTH`,`Extrusion length too small (< 1e-10)`)):t!==`s-curve`&&t!==`linear`?k(F(`UNSUPPORTED_PROFILE`,`Unsupported extrusion profile: ${String(t)}`)):O(U().buildExtrusionLaw(t,e,n).Trim(0,e,1e-6))}function iM(e,t){let n=U(),r=n.makeLineEdge([...e],[...t]);return W(n.makeWire([r]))}function aM(e,t,n,r,i,a=!1){return W(U().makeHelixWire(e,t,n,[...r],[...i],a))}function oM(e){let t=W(e.shape),n=W(e.firstShape),r=W(e.lastShape),i=()=>{PE(t),PE(n),PE(r)};return OE(t)?CE(n)?CE(r)?O([t,n,r]):(i(),k(mo(`SWEEP_END_NOT_WIRE`,`Sweep did not produce an end Wire`))):(i(),k(mo(`SWEEP_START_NOT_WIRE`,`Sweep did not produce a start Wire`))):(i(),k(mo(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function sM(e,t,n={},r=!1){if(n.mode===`simple`&&!r){let n=W(U().simplePipe(e.wrapped,t.wrapped));return OE(n)?O(n):(PE(n),k(mo(`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 oM(v);let y=W(v);return OE(y)?O(y):(PE(y),k(mo(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function cM(e,t,n,r){return sM(e,iM(t,xD(t,n)),{support:r})}function lM(e,t,n,r,i=!1){let a=DD(n);if(a<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let o=iM(t,xD(t,n)),s=null;if(r){let e=rM(a,r);if(A(e))return e;s=e.value}return sM(e,o,{law:s},i)}function uM(e,t,n,r,i,a=!1){if(Math.abs(t)<1e-10)return k(F(`ZERO_TWIST_ANGLE`,`Twist angle cannot be zero`));let o=DD(r);if(o<1e-10)return k(F(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let s=iM(n,xD(n,r)),c=t<0,l=aM(360/Math.abs(t)*o,o,1,n,r,c),u=null;if(i){let e=rM(o,i);if(A(e))return e;u=e.value}return sM(e,s,{auxiliarySpine:l,law:u},a)}function dM(e){let t=e.map(e=>e.location);for(let e=0;e<t.length;e++){let n=t[e];if(n!==void 0&&(n<0||n>1))return F(N.MULTI_SWEEP_FAILED,`Section ${e} location ${n} is out of range [0, 1]`)}let n=t.filter(e=>e!==void 0);for(let e=1;e<n.length;e++)if((n[e]??0)<=(n[e-1]??0))return F(N.MULTI_SWEEP_FAILED,`Section locations must be strictly increasing`)}function fM(e,t,n){let[r,i]=n.curveParameters(t.wrapped),a=i-r,o=Array(e.length);for(let t=0;t<e.length;t++){let n=e[t]?.location;o[t]=n===void 0?NaN:r+n*a}let s=-1,c=r;for(let t=0;t<=e.length;t++){let n=t===e.length;if(!n&&!Number.isNaN(o[t]??NaN)||n){let e=n?i:o[t]??i,a=t-s-1;for(let t=1;t<=a;t++)o[s+t]=c+t/(a+1)*(e-c);n||(s=t,c=o[t]??r)}}for(let e=1;e<o.length;e++)if((o[e]??0)<=(o[e-1]??0))return k(F(N.MULTI_SWEEP_FAILED,`Computed section parameters are not strictly increasing at index ${e} (${o[e-1]?.toFixed(4)} >= ${o[e]?.toFixed(4)})`));return O(o)}function pM(e,t,n){if(e.length<2)return k(F(N.MULTI_SWEEP_INSUFFICIENT_SECTIONS,`Multi-section sweep requires at least 2 sections, got ${e.length}`));let{solid:r=!0,ruled:i=!1,tolerance:a=1e-6}=n??{},o=dM(e);if(o)return k(o);try{let n=U(),o=fM(e,t,n);if(A(o))return o;let s=o.value,c=[];for(let r=0;r<e.length;r++){let i=s[r],a=e[r];if(i===void 0||a===void 0)continue;let o=n.positionOnCurve(a.wire.wrapped,t.wrapped,i);c.push(n.downcast(o,`wire`))}let l=W(n.loftAdvanced(c,{solid:r,ruled:i,tolerance:a}));return OE(l)?O(l):(PE(l),k(mo(`MULTI_SWEEP_NOT_3D`,`Multi-section sweep did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.MULTI_SWEEP_FAILED,`Multi-section sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function mM(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 OE(u)?O(u):(PE(u),k(mo(`GUIDED_SWEEP_NOT_3D`,`Guided sweep did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return k(P(N.GUIDED_SWEEP_FAILED,`Guided sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function hM(e,t){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`extrude: face is a null shape`));if(DD(t)<1e-10)return k(F(`EXTRUDE_ZERO_VECTOR`,`extrude: extrusion vector has zero length`));try{let n=U(),r=DD(t),i=AD(t),a=n.extrude(e.wrapped,[...i],r),o=vE(n.downcast(a,`solid`));return ME(a,o),O(o)}catch(e){return k(P(`EXTRUDE_FAILED`,`Extrusion operation failed`,e,{operation:`extrude`,vectorLength:DD(t)}))}}function gM(e,t=[0,0,0],n=[0,0,1],r=2*Math.PI){if(U().isNull(e.wrapped))return k(F(N.NULL_SHAPE_INPUT,`revolve: face is a null shape`));try{let i=W(U().revolveVec(e.wrapped,[...t],[...n],r));return OE(i)?O(i):(PE(i),k(mo(`REVOLUTION_NOT_3D`,`Revolution did not produce a 3D shape`)))}catch(e){return k(P(`REVOLVE_FAILED`,`Revolution operation failed`,e,{operation:`revolve`,angle:r}))}}function _M(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=DD(i);if(a<1e-10)return k(F(`EXTRUDE_ALL_ZERO_VECTOR`,`extrudeAll: entry ${t} has zero-length extrusion vector`));let o=[...AD(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=vE(t.downcast(e,`solid`));return ME(e,n),n}))}catch(e){return k(P(`EXTRUDE_ALL_FAILED`,`Batch extrusion operation failed`,e))}}function vM(e,{ruled:t=!0,startPoint:n,endPoint:r,tolerance:i=1e-6}={},a=!1){if(e.length===0&&!n&&!r)return k(F(`LOFT_EMPTY`,`Loft requires at least one wire or start/end point`));let o=U(),s=n?o.makeVertex(..._D(n)):void 0,c=r?o.makeVertex(..._D(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 OE(n)?O(n):(PE(n),k(mo(`LOFT_NOT_3D`,`Loft did not produce a 3D shape`)))}catch(e){return k(P(`LOFT_FAILED`,`Loft operation failed`,e,void 0,`Common causes: wire profiles with different edge counts, self-intersecting result, or profiles too far apart. Ensure profiles are compatible and ordered.`))}}function yM(e){if(e.length===0)return O([]);let t=U(),n=[],r=e.map(e=>{let r=e.startPoint?t.makeVertex(..._D(e.startPoint)):void 0,i=e.endPoint?t.makeVertex(..._D(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(!OE(e))return PE(e),k(mo(`LOFT_ALL_NOT_3D`,`Batch loft entry did not produce a 3D shape`));n.push(e)}return O(n)}catch(e){return k(P(`LOFT_ALL_FAILED`,`Batch loft operation failed`,e))}finally{for(let e of n)t.dispose(e)}}var bM=new WeakMap;function xM(e,t){return bM.get(e)?.get(t)}function SM(e,t,n){let r=bM.get(e);r||(r=new Map,bM.set(e,r)),r.set(t,n)}function CM(e){return U().isNull(e.wrapped)}function wM(e){return k(F(N.NULL_SHAPE_INPUT,`${e}: shape is a null shape`))}function TM(e){let t=xM(e.wrapped,`volume`);if(t)return O(t);if(CM(e))return wM(`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 SM(e.wrapped,`volume`,t),O(t)}let i=n.volume(e.wrapped),a=BE(()=>n.centerOfMass(e.wrapped),N.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!a.ok)return a;let o={mass:i,volume:i,centerOfMass:a.value};return SM(e.wrapped,`volume`,o),O(o)}function EM(e){let t=xM(e.wrapped,`surface`);if(t)return O(t);if(CM(e))return wM(`measureSurfaceProps`);let n=U(),r=n.area(e.wrapped),i=BE(()=>n.centerOfMass(e.wrapped),N.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!i.ok)return i;let a={mass:r,area:r,centerOfMass:i.value};return SM(e.wrapped,`surface`,a),O(a)}function DM(e){let t=xM(e.wrapped,`linear`);if(t)return O(t);if(CM(e))return wM(`measureLinearProps`);let n=U(),r=n.length(e.wrapped),i={mass:r,length:r,centerOfMass:n.linearCenterOfMass(e.wrapped)};return SM(e.wrapped,`linear`,i),O(i)}function OM(e){let t=TM(e);return t.ok?O(t.value.mass):t}function kM(e){let t=EM(e);return t.ok?O(t.value.mass):t}function AM(e){let t=DM(e);return t.ok?O(t.value.mass):t}function jM(e,t){return CM(e)||CM(t)?wM(`measureDistance`):O(U().distance(e.wrapped,t.wrapped).value)}function MM(e,t){if(CM(e)||CM(t))return wM(`measureDistanceProps`);let n=U().distance(e.wrapped,t.wrapped);return O({distance:n.value,point1:n.point1,point2:n.point2})}function NM(e){if(CM(e))return wM(`createDistanceQuery`);let t=U().createDistanceQuery(e.wrapped);return O({distanceTo(e){return CM(e)?wM(`createDistanceQuery.distanceTo`):O(t.distanceTo(e.wrapped).value)},dispose(){t.dispose()}})}function PM(e,t,n){if(CM(e))return wM(`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 FM(e){if(CM(e))return wM(`measureCurvatureAtMid`);let t=sO(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 IM(e,t){return e.map(e=>FE(e,t))}function LM(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=IE(e,t);i.push(s),o?o.push(s.wrapped):a.set(r,[s.wrapped])}return i}function RM(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 zM(e,t,n){let r=U();return e.get(n)?.find(e=>r.isSame(e.wrapped,t))}function BM(e){let t=KE(e);if(t.edgeToFaces)return t.edgeToFaces;let n=U(),r=XE(e),i=RM(YE(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=zM(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 VM(e){let t=KE(e);if(t.vertexToFaces)return t.vertexToFaces;let n=U(),r=XE(e),i=RM(QE(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=zM(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 HM(e,t){let n=U(),r=BM(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 IM(o,`face`)}function UM(e,t){let n=U(),r=VM(e),i=n.hashCode(t.wrapped,G),a=r.get(i)??[],o=[],s=new Map;for(let e of a){if(!n.isSame(e.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 IM(o,`face`)}function WM(e){return LM(e.wrapped,`edge`)}function GM(e){return LM(e.wrapped,`vertex`)}function KM(e){return LM(e.wrapped,`wire`)}function qM(e){return LM(e.wrapped,`vertex`)}function JM(e,t){let n=U(),r=BM(e),i=LM(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 IM(a,`face`)}function YM(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(IE(e,`edge`)):n.dispose(e);for(let e of i)n.dispose(e);return o}function XM(e,t){let n=0,r=iO(t);if(e.surfaceType!==void 0)if(r===e.surfaceType)n+=1;else return-1/0;if(e.normal!==void 0){let r=dO(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=fO(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=kM(t);if(r.ok&&r.value>0){let t=Math.abs(Math.log(e.area/r.value));t>1&&(n-=t)}}return n}function ZM(e){let t=iO(e),n=dO(e),r=fO(e),i=kM(e);return{entityType:`face`,surfaceType:t,normal:n,centroid:r,area:i.ok?i.value:void 0}}var QM=.9;function $M(e){if(e[2]>QM)return`box:top`;if(e[2]<-.9)return`box:bottom`;if(e[1]>QM)return`box:back`;if(e[1]<-.9)return`box:front`;if(e[0]>QM)return`box:right`;if(e[0]<-.9)return`box:left`}function eN(e,t){if(iO(t)!==`PLANE`)return;let n=dO(t)[2];if(n>QM)return`${e}:top`;if(n<-.9)return`${e}:bottom`}function tN(e){return iO(e)===`CYLINDRE`?`cylinder:lateral`:eN(`cylinder`,e)}function nN(e){return iO(e)===`CONE`?`cone:lateral`:eN(`cone`,e)}function rN(e){return iO(e)===`SPHERE`?`sphere:surface`:void 0}var iN={box:e=>$M(dO(e)),cylinder:tN,cone:nN,sphere:rN};function aN(e,t){let n=new Map,r=iN[t],i=U(),a=0;for(let o of i.iterShapes(e.wrapped,`face`)){let e=FE(o,`face`);try{let i=r?.(e),o=i!==void 0&&!n.has(i)?i:`${t}:face_${a}`;n.set(o,[pk(e)]),a++}finally{NE(e,o)}}return n}function oN(e,t,n){return{origin:e,role:t,hint:ZM(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 lN=.1,uN=.5;function dN(e,t,n){let r=-1/0,i,a=-1/0,o=[];for(let s of t){let t=n(e,s);t>uN&&o.push([s,t]),t>r?(a=r,r=t,i=s):t>a&&(a=t)}return i!==void 0&&r>uN?r-a<lN&&o.length>1?{kind:`ambiguous`,candidates:o.filter(([,e])=>e>=r-lN).map(([e])=>e)}:{kind:`match`,face:i}:{kind:`none`}}function fN(e,t,n,r){let i=XE(n),a=r??XM,o=t.get(e.origin)?.get(e.role);if(o!==void 0&&o.length>0){let t=i.filter(e=>o.includes(pk(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=dN(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=dN(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 pN(e,t){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(n*n+r*r+i*i)}function mN(e){if(e.length===0)return;let t=0,n=0,r=0;for(let i of e){let e=mD(i);t+=e[0],n+=e[1],r+=e[2]}let i=e.length;return[t/i,n/i,r/i]}function hN(e,t,n){let r=n.get(t);if(!r)return;let i=pk(e);for(let[e,t]of r)if(t.includes(i))return e}function gN(e,t,n,r){let i=r.get(t)?.get(n);return i===void 0||i.length===0?[]:XE(e).filter(e=>i.includes(pk(e)))}function _N(e){let t=AM(e);return{entityType:`edge`,length:t.ok?t.value:void 0,midpoint:mN(qM(e))}}function vN(e){let t=new Set,n=[];for(let r of e){let e=pk(r);t.has(e)||(t.add(e),n.push(r))}return n}var yN=1e-6;function bN(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=AM(a);n.ok&&(e+=Math.abs(n.value-t.length))}if(t.midpoint!==void 0){let n=mN(qM(a));n!==void 0&&(e+=pN(t.midpoint,n))}e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<yN))return n}function xN(e,t,n,r){let[i,a]=HM(n,t);if(i===void 0||a===void 0)return;let o=hN(i,e,r),s=hN(a,e,r);if(!(o===void 0||s===void 0))return{origin:e,faceRoles:[o,s],hint:_N(t)}}function SN(e,t,n){let[r,i]=e.faceRoles,a=gN(n,e.origin,r,t),o=gN(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(...YM(e,t));let c=vN(s);if(c.length===1){let[e]=c;if(e!==void 0)return{edge:e,confidence:`exact`}}if(c.length>1){let t=bN(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 CN=3,wN=1e-6;function TN(e,t){let n=new Set;for(let r of e)for(let e of GM(r)){let r=pk(e);n.add(r),t.has(r)||t.set(r,e)}return n}function EN(e,t){let n=new Set;for(let r of e)t.has(r)&&n.add(r);return n}function DN(e){let t=new Map,n;for(let r of e){let e=TN(r,t);n=n===void 0?e:EN(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 ON(e,t){if(t.position===void 0)return;let n,r=1/0,i=1/0;for(let a of e){let e=pN(mD(a),t.position);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<wN))return n}function kN(e,t,n,r){let i=UM(n,t);if(i.length<CN)return;let a=new Set;for(let t of i){let n=hN(t,e,r);n!==void 0&&a.add(n)}if(!(a.size<CN))return{origin:e,faceRoles:[...a].sort(),hint:{entityType:`vertex`,position:mD(t)}}}function AN(e,t,n){let r=[];for(let i of e.faceRoles){let a=gN(n,e.origin,i,t);if(a.length===0)return{ref:e,reason:`not-found`};r.push(a)}let i=DN(r);if(i.length===1){let[e]=i;if(e!==void 0)return{vertex:e,confidence:`exact`}}if(i.length>1){let t=ON(i,e.hint);return t===void 0?{ref:e,reason:`ambiguous`,candidates:i}:{vertex:t,confidence:`geometric-fallback`}}return{ref:e,reason:`not-found`}}var jN=.99,MN=.1,NN=1e-6;function PN(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function FN(e,t){return XE(e).filter(e=>PN(dO(e),t)>jN)}function IN(e,t,n){let r=new Set([...t,...n].map(pk)),i=new Set;for(let n of t)for(let t of JM(e,n))i.add(pk(t));let a=[],o=new Set;for(let t of n)for(let n of JM(e,t)){let e=pk(n);r.has(e)||o.has(e)||!i.has(e)||(o.add(e),a.push(n))}return a}function LN(e,t){let n,r=1/0,i=1/0;for(let a of e){let e=pN(fO(a),t);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<NN))return n}function RN(e,t,n,r,i){let[a,o]=HM(r,n);if(a===void 0||o===void 0)return;let s=hN(a,e,i),c=hN(o,e,i);if(!(s===void 0||c===void 0))return{origin:e,op:t,betweenRoles:[s,c],hint:{entityType:`derived-face`,normalA:dO(a),normalB:dO(o),edgeMidpoint:mN(qM(n))}}}function zN(e,t,n){let r=gN(n,e.origin,e.betweenRoles[0],t);r.length===0&&(r=FN(n,e.hint.normalA));let i=gN(n,e.origin,e.betweenRoles[1],t);if(i.length===0&&(i=FN(n,e.hint.normalB)),r.length===0||i.length===0)return{ref:e,reason:`not-found`};let a=IN(n,r,i).filter(t=>PN(dO(t),e.hint.normalA)>MN&&PN(dO(t),e.hint.normalB)>MN);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&&LN(a,e.hint.edgeMidpoint);return t?{face:t,confidence:`geometric-fallback`}:{ref:e,reason:`ambiguous`,candidates:a}}return{ref:e,reason:`not-found`}}function BN(e){return typeof e==`object`&&!!e&&`origin`in e}function VN(e){return BN(e)&&`betweenRoles`in e&&`op`in e}function HN(e){return BN(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length===2}function UN(e){return BN(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length>=3}function WN(e){return BN(e)&&typeof e.role==`string`}function GN(e){return WN(e)||HN(e)||UN(e)||VN(e)}function KN(e,t){return t===void 0?{ok:!1,reason:e}:{ok:!1,reason:e,candidates:t}}function qN(e,t,n){if(VN(e)){let r=zN(e,t,n);return`face`in r?{ok:!0,entity:r.face}:KN(r.reason,r.candidates)}if(HN(e)){let r=SN(e,t,n);return`edge`in r?{ok:!0,entity:r.edge}:KN(r.reason,r.candidates)}if(UN(e)){let r=AN(e,t,n);return`vertex`in r?{ok:!0,entity:r.vertex}:KN(r.reason,r.candidates)}let r=fN(e,t,n);return`face`in r?{ok:!0,entity:r.face}:KN(r.reason,r.candidates)}function JN(e,t,n){let r=n.get(e.origin);if(r!==void 0)return r;let i=new Map([[e.origin,aN(t,e.origin)]]);return n.set(e.origin,i),i}function YN(e,t){return qN(e,JN(e,t,new Map),t)}function XN(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 ZN(e,t){let n=new Map,r=e=>{if(GN(e)){let r=qN(e,JN(e,t,n),t);return r.ok?r.entity:e}if(Array.isArray(e))return e.map(r);if(XN(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 QN(e,t,n,r){let i=vE(U().makeBox(e,t,n)),a=r?.at??(r?.centered?[0,0,0]:void 0);return a?$O(i,[a[0]-e/2,a[1]-t/2,a[2]-n/2]):i}function $N(e,t,n){let r=n?.at??[0,0,0],i=n?.axis??[0,0,1],a=JA(e,t,r,i);if(n?.centered){let e=[-i[0]*t*.5,-i[1]*t*.5,-i[2]*t*.5];a=$O(a,e)}return a}function eP(e,t){let n=YA(e);return t?.at&&(n=$O(n,t.at)),n}function tP(e,t,n,r){let i=r?.at??[0,0,0],a=r?.axis??[0,0,1],o=XA(e,t,n,i,a);if(r?.centered){let e=[-a[0]*n*.5,-a[1]*n*.5,-a[2]*n*.5];o=$O(o,e)}return o}function nP(e,t,n){return ZA(e,t,n?.at??[0,0,0],n?.axis??[0,0,1])}function rP(e,t,n,r){let i=QA(e,t,n);return r?.at&&(i=$O(i,r.at)),i}function iP(e,t){return lA(e,t)}function aP(e,t){let n=t?.axis??[0,0,1];return uA(e,t?.at??[0,0,0],n)}function oP(e,t,n){let r=n?.axis??[0,0,1];return dA(e,t,n?.at??[0,0,0],r,n?.xDir)}function sP(e,t,n,r){return fA(e,t,n,r?.at??[0,0,0],r?.axis??[0,0,1],r?.lefthand??!1)}function cP(e,t,n){return pA(e,t,n)}function lP(e,t,n,r,i){let a=i?.axis??[0,0,1];return mA(e,t,n*hD,r*hD,i?.at??[0,0,0],a,i?.xDir)}function uP(e,t){return hA(e,t)}function dP(e){return _A(e)}function fP(e,t,n){return vA(e,t,n)}function pP(e){return yA(e)}function mP(e){return Va(yA(e),e=>eE(e)?O(e):k(F(`WIRE_NOT_CLOSED`,`Assembled wire is not closed: start and end points do not coincide`)))}function hP(e,t){return bA(e,t)}function gP(e){return CA(e)}function _P(e,t){return SA(e,t)}function vP(e){return TA(e)}function yP(e){return $A(e)}function bP(e){return tj(e)}function xP(e){return nj(e)}function SP(e,t,n){return ej(e,t,n)}function CP(e,t){return qA(e,t)}function wP(e,t){return wA(e,t)}function TP(){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 EP(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??TP(),color:[a,o,s,c]}});return RT(U().createXCAFDocument(t))}function DP(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??TP(),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(_o(`STEP_EXPORT_FAILED`,`Failed to write STEP file`))}finally{o.delete()}}function OP(e,t,n,r,i){if(n<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(MD(t))return k(F(`PATTERN_ZERO_DIRECTION`,`Pattern direction cannot be zero`));let a=AD(t);return MA(U().linearPattern(e.wrapped,[...a],r,n).map(e=>W(e)),{optimisation:`sameFace`,...i,unsafe:!0})}function kP(e,t,n,r=360,i=[0,0,0],a){if(n<1)return k(F(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return O(e);if(MD(t))return k(F(`PATTERN_ZERO_AXIS`,`Pattern axis cannot be zero`));let o=r/n;return MA(U().circularPattern(e.wrapped,[...i],[...t],o,n).map(e=>W(e)),{optimisation:`sameFace`,...a,unsafe:!0})}function AP(e,t,n,r,i,a,o,s){if(r<1||i<1)return k(F(`PATTERN_INVALID_COUNT`,`Grid pattern counts must be at least 1`));if(r===1&&i===1)return O(e);if(MD(t))return k(F(`PATTERN_ZERO_DIRECTION`,`Grid directionX cannot be zero`));if(MD(n))return k(F(`PATTERN_ZERO_DIRECTION`,`Grid directionY cannot be zero`));let c=U(),l=AD(t),u=AD(n);if(typeof c.gridPattern==`function`)return O(W(c.gridPattern(e.wrapped,[...l],[...u],a,o,r,i)));let d=OP(e,t,r,a,s);return d.ok?OP(d.value,n,i,o,s):d}function jP(e,t={}){return{name:e,children:[],...t.shape===void 0?{}:{shape:t.shape},...t.translate===void 0?{}:{translate:t.translate},...t.rotate===void 0?{}:{rotate:t.rotate},...t.metadata===void 0?{}:{metadata:t.metadata}}}function MP(e,t){return{...e,children:[...e.children,t]}}function NP(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 PP(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 FP(e,t){if(e.name===t)return e;for(let n of e.children){let e=FP(n,t);if(e)return e}}function IP(e,t,n=0){t(e,n);for(let r of e.children)IP(r,t,n+1)}function LP(e){let t=1;for(let n of e.children)t+=LP(n);return t}function RP(e){let t=[];return IP(e,e=>{e.shape&&t.push(e.shape)}),t}function zP(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function BP(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 VP(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function HP(e){return VP(BP(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function UP(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 WP(e,t){let n=t/2,r=Math.sin(n),i=VP(e);return[Math.cos(n),i[0]*r,i[1]*r,i[2]*r]}function GP(e,t){let n=VP(e),r=VP(t),i=zP(n,r);if(i>=.999999999)return[1,0,0,0];if(i<=-.999999999)return WP(HP(n),Math.PI);let a=BP(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 KP(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 qP=Math.PI/180;function JP(e,t,n){return Math.min(n,Math.max(t,e))}function YP(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function XP(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 ZP(e){return YP(XP(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function QP(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:YP(t),min:s,max:c,value:JP(n.value??0,s,c)}}function $P(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:YP(r.direction)},min:a.min,max:a.max,value:a.value,dofs:i}}function eF(e,t,n,r={}){return $P(`revolute`,e,t,n,[QP(`rotation`,n.direction,r,-180,180)])}function tF(e,t,n,r={}){return $P(`prismatic`,e,t,n,[QP(`translation`,n.direction,r,0,100)])}function nF(e,t,n,r={}){return $P(`cylindrical`,e,t,n,[QP(`rotation`,n.direction,r.rotation??{},-180,180),QP(`translation`,n.direction,r.translation??{},0,100)])}function rF(e,t,n,r={}){let i=YP(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?ZP(i):YP(n)}else a=ZP(i);let o=YP(XP(i,a));return $P(`planar`,e,t,{origin:n.origin,direction:i},[QP(`translation`,a,r.u??{},-100,100),QP(`translation`,o,r.v??{},-100,100),QP(`rotation`,i,r.rotation??{},-180,180)])}function iF(e,t,n,r={}){return $P(`spherical`,e,t,{origin:n,direction:[0,0,1]},[QP(`rotation`,[1,0,0],r.x??{},-180,180),QP(`rotation`,[0,1,0],r.y??{},-180,180),QP(`rotation`,[0,0,1],r.z??{},-180,180)])}function aF(e,t){let n=e.dofs.map((e,n)=>{let r=t[n];return r===void 0?e:{...e,value:JP(r,e.min,e.max)}}),r=n[0];return r?{...e,dofs:n,value:r.value}:{...e,dofs:n}}function oF(e,t){return aF(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=WP(t.axis,n*qP),i=UP(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=uF;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=dF(a,sF(i,o,JP(s,o.min,o.max)))}return a}function lF(e,t){let n=e.joints??[];return{...e,joints:[...n,t]}}var uF={position:[0,0,0],rotation:[1,0,0,0]};function dF(e,t){let n=UP(e.rotation,t.position);return{position:[e.position[0]+n[0],e.position[1]+n[1],e.position[2]+n[2]],rotation:KP(e.rotation,t.rotation)}}function fF(e){let t=[];return IP(e,e=>{e.joints&&t.push(...e.joints)}),t}function pF(e,t={}){let n=[],r=new Set;IP(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,uF);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?dF(cF(n,i),n.offset):cF(n,i);a.set(n.child,dF(r,c))}}for(let e of o)a.has(e.child)||a.set(e.child,uF);return a}function mF(e){return fF(e).reduce((e,t)=>e+t.dofs.length,0)}var hF={position:[0,0,0],rotation:[1,0,0,0]};function gF(e,t){let n=UP(e.rotation,t);return[n[0]+e.position[0],n[1]+e.position[1],n[2]+e.position[2]]}function _F(e){return[e[0],-e[1],-e[2],-e[3]]}function vF(e,t){let[n,r,i,a]=KP(t,_F(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 yF(e,t){let n=[];IP(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 bF(e,t){return e[t]??0}function xF(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]=bF(e,a*n+t);i[a*r+n]=bF(t,a)}for(let e=0;e<n;e++){let t=e;for(let a=e+1;a<n;a++)Math.abs(bF(i,a*r+e))>Math.abs(bF(i,t*r+e))&&(t=a);if(Math.abs(bF(i,t*r+e))<1e-12)return null;if(t!==e)for(let n=e;n<r;n++){let a=bF(i,e*r+n);i[e*r+n]=bF(i,t*r+n),i[t*r+n]=a}let a=bF(i,e*r+e);for(let t=e;t<r;t++)i[e*r+t]=bF(i,e*r+t)/a;for(let t=0;t<n;t++){if(t===e)continue;let n=bF(i,t*r+e);if(n!==0)for(let a=e;a<r;a++)i[t*r+a]=bF(i,t*r+a)-n*bF(i,e*r+a)}}let a=new Float64Array(n);for(let e=0;e<n;e++)a[e]=bF(i,e*r+n);return a}function SF(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 CF(e,t){let n={},r=0;for(let i of e){let e=[];for(let n=0;n<i.count;n++)e.push(bF(t,r++));n[i.child]=e}return n}function wF(e,t,n,r,i){let a=gF(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=vF(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+=bF(e,t)**2;return Math.sqrt(o)}function TF(e,t,n,r,i,a,o,s,c,l){let u=gF(o,s);for(let d=0;d<n;d++){let f=bF(t,d),p=f+c>bF(a,d)&&f-c>=bF(i,d)?-c:c;t[d]=f+p;let m=l(t);t[d]=f;let h=gF(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=vF(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 EF(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+=bF(e,t*n+r)*bF(e,i*n+r);a[t*r+i]=s+(t===i?o:0)}let s=xF(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+=bF(e,a*n+t)*bF(s,a);c[t]=i}return c}function DF(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}=SF(yF(e,t),r.seed),p=u.length,m=n=>pF(e,CF(l,n)).get(t)??hF,h=new Float64Array(c),g=new Float64Array(c*p),_=m(u),v=wF(h,_,n,s,c),y=0;for(;y<i&&p>0&&v>a;y++){TF(g,u,p,c,d,f,_,s,1e-6,m);let e=EF(g,h,p,c,o);if(!e)break;for(let t=0;t<p;t++){let n=bF(u,t)+bF(e,t);u[t]=Math.min(bF(f,t),Math.max(bF(d,t),n))}_=m(u),v=wF(h,_,n,s,c)}return{values:CF(l,u),converged:v<=a,iterations:y,error:v}}function OF(e,t){return e.dofs.map((e,n)=>{let r=(Array.isArray(t)?t[n]:n===0?t:void 0)??e.value;return Math.min(e.max,Math.max(e.min,r))})}function kF(e,t,n,r){let i=[];IP(e,e=>{e.joints&&i.push(...e.joints)});let a=i.map(e=>({child:e.child,a:OF(e,t[e.child]),b:OF(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:pF(e,r)})}return s}var AF=Math.PI/180;function jF(e,t,n,r){let i=e*AF,a=r*AF,o=KP(WP([0,0,1],i),WP([1,0,0],a));return{position:[n*Math.cos(i),n*Math.sin(i),t],rotation:o}}function MF(e,t={}){let n=t.base??`base`,r=e.map((e,t)=>e.name??`link${t+1}`);return e.map((e,t)=>{let i=t===0?n:r[t-1]??`link${t}`,a=r[t]??`link${t+1}`,o=jF(e.theta,e.d,e.a,e.alpha),s={origin:[0,0,0],direction:[0,0,1]},c={...e.min===void 0?{}:{min:e.min},...e.max===void 0?{}:{max:e.max},...e.value===void 0?{}:{value:e.value}};return{...e.type===`prismatic`?tF(i,a,s,c):eF(i,a,s,c),offset:o}})}var NF=Math.PI/180,PF=180/Math.PI;function FF(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function IF(e){return String(e===0?0:e)}function LF(e){return`${IF(e[0])} ${IF(e[1])} ${IF(e[2])}`}function RF(e,t={}){let n=t.name??`robot`,r=t.effort??0,i=t.velocity??0,a=t.meshes??{},o=[],s=[];IP(e,e=>{o.push(e.name),e.joints&&s.push(...e.joints)});for(let e of s){if(e.type!==`revolute`&&e.type!==`prismatic`)return k(F(N.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' is '${e.type}'; URDF supports only revolute and prismatic joints`));if(e.offset)return k(F(N.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' carries a fixed offset (e.g. a DH link) that URDF cannot represent as a single joint`))}let c=[`<?xml version="1.0"?>`,`<robot name="${FF(n)}">`];for(let e of o){let t=a[e];t?c.push(` <link name="${FF(e)}">`,` <visual><geometry><mesh filename="${FF(t)}"/></geometry></visual>`,` </link>`):c.push(` <link name="${FF(e)}"/>`)}for(let e of s){let t=e.type===`revolute`,n=t?e.min*NF:e.min,a=t?e.max*NF:e.max,o=e.type===`prismatic`?[0,0,0]:e.axis.origin;c.push(` <joint name="${FF(`${e.parent}_to_${e.child}`)}" type="${e.type}">`,` <parent link="${FF(e.parent)}"/>`,` <child link="${FF(e.child)}"/>`,` <origin xyz="${LF(o)}" rpy="0 0 0"/>`,` <axis xyz="${LF(e.axis.direction)}"/>`,` <limit lower="${IF(n)}" upper="${IF(a)}" effort="${IF(r)}" velocity="${IF(i)}"/>`,` </joint>`)}return c.push(`</robot>`,``),O(c.join(`
16
16
  `))}function zF(e,t){return RegExp(`\\b${t}\\s*=\\s*"([^"]*)"`).exec(e)?.[1]}function BF(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 VF(e,t){return UP(KP(KP(WP([0,0,1],t[2]),WP([0,1,0],t[1])),WP([1,0,0],t[0])),e)}function HF(e){let t=/<robot\b([^>]*)>/.exec(e);if(!t)return k(F(N.VALIDATION_FAILED,`importURDF: no <robot> element found`));let n=zF(t[1]??``,`name`)??`robot`,r=[],i=/<link\b([^>]*?)(?:\/>|>)/g;for(let t=i.exec(e);t;t=i.exec(e)){let e=zF(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=zF(e,`type`)??`fixed`;if(r===`fixed`||r===`floating`||r===`planar`)continue;let i=/<parent\b([^>]*?)\/?>/.exec(n),o=/<child\b([^>]*?)\/?>/.exec(n),s=zF(i?.[1]??``,`link`),c=zF(o?.[1]??``,`link`);if(!s||!c)return k(F(N.VALIDATION_FAILED,`importURDF: joint missing parent/child link (${zF(e,`name`)??`unnamed`})`));let l=/<origin\b([^>]*?)\/?>/.exec(n),u=/<axis\b([^>]*?)\/?>/.exec(n),d=/<limit\b([^>]*?)\/?>/.exec(n),f=BF(zF(l?.[1]??``,`xyz`),[0,0,0]),p=BF(zF(l?.[1]??``,`rpy`),[0,0,0]),m=VF(BF(zF(u?.[1]??``,`xyz`),[1,0,0]),p),h=Number(zF(d?.[1]??``,`lower`)??NaN),g=Number(zF(d?.[1]??``,`upper`)??NaN);if(r===`prismatic`){let e=Number.isFinite(h)&&Number.isFinite(g)?{min:h,max:g}:{};a.push(tF(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*PF,max:g*PF};a.push(eF(s,c,{origin:f,direction:m},e))}else return k(F(N.VALIDATION_FAILED,`importURDF: joint '${zF(e,`name`)??`unnamed`}' has unrecognized type '${r}'`))}return O({name:n,links:r,joints:a})}function UF(){return{steps:[],shapes:new Map}}function WF(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 GF(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 KF(e,t){return e.steps.find(e=>e.id===t)}function qF(e,t){return e.shapes.get(t)}function JF(e){return e.steps.length}function YF(e,t){let n=e.steps.findIndex(e=>e.id===t);return n===-1?[]:e.steps.slice(n)}function XF(e,t,n){let r=new Map(e.shapes);return r.set(t,n),{...e,shapes:r}}function ZF(){return{operations:new Map}}function QF(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function $F(e,t){let[n,r]=t;return n!==void 0&&r===void 0&&OE(n)?ZN(e,n):{...e}}function eI(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=XF(r,t,i));for(let n of e.steps){let e=t.operations.get(n.type);if(!e)return k(I(`REPLAY_UNKNOWN_OP`,`Unknown operation type: ${n.type}`));let i=[];for(let e of n.inputIds){let t=r.shapes.get(e);if(!t)return k(I(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${n.id}`));i.push(t)}try{let t=e(i,$F(n.parameters,i));r=WF(r,{id:n.id,type:n.type,parameters:n.parameters,inputIds:n.inputIds,outputId:n.outputId},t)}catch(e){return k(I(`REPLAY_STEP_FAILED`,`Step ${n.id} (${n.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(r)}function tI(e,t,n){let r=e.steps.findIndex(e=>e.id===t);if(r===-1)return k(I(`REPLAY_STEP_NOT_FOUND`,`Step not found: ${t}`));let i=new Map(e.shapes);for(let t=r;t<e.steps.length;t++){let n=e.steps[t];n&&i.delete(n.outputId)}let a={steps:e.steps.slice(0,r),shapes:i};for(let t=r;t<e.steps.length;t++){let r=e.steps[t];if(!r)continue;let i=n.operations.get(r.type);if(!i)return k(I(`REPLAY_UNKNOWN_OP`,`Unknown operation type: ${r.type}`));let o=[];for(let e of r.inputIds){let t=a.shapes.get(e);if(!t)return k(I(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${r.id}`));o.push(t)}try{let e=i(o,$F(r.parameters,o));a=WF(a,{id:r.id,type:r.type,parameters:r.parameters,inputIds:r.inputIds,outputId:r.outputId},e)}catch(e){return k(I(`REPLAY_STEP_FAILED`,`Step ${r.id} (${r.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return O(a)}function nI(e,t,n,r){return e.steps.findIndex(e=>e.id===t)===-1?k(I(`MODIFY_STEP_NOT_FOUND`,`Step not found: ${t}`)):tI({steps:e.steps.map(e=>e.id===t?{...e,parameters:n}:e),shapes:e.shapes},t,r)}function rI(e){let t={};for(let[n,r]of e.shapes){let e=fk(r);if(!e.ok)return k(I(`SERIALIZE_SHAPE_FAILED`,`Failed to serialize shape "${n}": ${e.error.message}`));t[n]=e.value}return O({steps:e.steps,shapes:t})}function iI(e){let t=new Map;for(let[n,r]of Object.entries(e.shapes))try{let e=tO(r);if(!e.ok)return k(I(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e.error.message}`));t.set(n,e.value)}catch(e){return k(I(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e instanceof Error?e.message:String(e)}`))}return O({steps:e.steps,shapes:t})}function aI(e){try{var t=DT();let{radius:n,pitch:r,height:i,depth:a=.6*r,toothHalfWidth:o=.42*r,crest:s=0,sectionsPerTurn:c=20,lefthand:l=!1,inward:u=!1}=e;if(!(n>0))return k(F(`THREAD_INVALID_RADIUS`,`radius must be > 0`));if(!(r>0))return k(F(`THREAD_INVALID_PITCH`,`pitch must be > 0`));if(!(i>0))return k(F(`THREAD_INVALID_HEIGHT`,`height must be > 0`));if(!(a>0))return k(F(`THREAD_INVALID_DEPTH`,`depth must be > 0`));if(s<0||s>=o)return k(F(`THREAD_INVALID_CREST`,`crest must be >= 0 and < toothHalfWidth`));if(c<3)return k(F(`THREAD_TOO_FEW_SECTIONS`,`sectionsPerTurn must be >= 3`));let d=i/r,f=Math.max(2,Math.round(d*c)),p=l?-1:1,m=u?-a:a,h=u?.3:-.3,g=o,_=t.u(new zT),v=[];for(let e=0;e<=f;e++){let t=p*e*2*Math.PI/c,i=r*Math.abs(t)/(2*Math.PI),a=n*Math.cos(t),o=n*Math.sin(t),l=Math.cos(t),u=Math.sin(t),d=(e,t)=>[a+e*l,o+e*u,i+t],f=s>0?[d(h,-g),d(m,-s),d(m,s),d(h,g)]:[d(h,-g),d(m,0),d(h,g)],y=pP(f.map((e,t)=>_.register(iP(e,f[(t+1)%f.length]))));if(!Ra(y))return y;v.push(_.register(y.value))}return vM(v,{ruled:!0})}catch(e){t.e=e}finally{t.d()}}var oI=1e-9,sI=1e-8,cI=1e-6,lI=([e,t],[n,r],i=cI)=>Math.abs(e-n)<=i&&Math.abs(t-r)<=i,uI=([e,t],[n,r])=>[e+n,t+r],dI=([e,t],[n,r])=>[e-n,t-r],fI=([e,t],n)=>[e*n,t*n],pI=([e,t],[n,r]=[0,0])=>Math.sqrt((e-n)**2+(t-r)**2),mI=([e,t],[n,r]=[0,0])=>(e-n)**2+(t-r)**2;function hI([e,t],[n,r]){return e*r-t*n}var gI=([e,t],[n,r]=[0,0])=>Math.atan2(r*e-t*n,e*n+t*r),_I=([e,t],[n,r]=[0,0])=>Math.atan2(r-t,n-e),vI=(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 yI([e,t]){let n=Math.sqrt(e*e+t*t);return n<1e-12?[0,0]:[e/n,t/n]}var bI=(e,t)=>[Math.cos(t)*e,Math.sin(t)*e],xI=([e,t])=>[Math.sqrt(e*e+t*t),Math.atan2(t,e)],SI=([e,t])=>{let n=yI([e,t]);return n[0]===0&&n[1]===0&&M(`normalize2d`,`Cannot normalize zero-length vector`),n};function CI(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(vo(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found ${r===0?0:`2+`} element(s)`))}function wI(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 YE(t);case`face`:return XE(t);case`wire`:return ZE(t);case`vertex`:return QE(t)}}let s=e=>{let n=o(e);return t.length===0?n.slice():n.filter(a)},c=()=>wI(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=pk(n),r=t.get(e);r?r.push(n):t.set(e,[n])}return i(e=>{let n=t.get(pk(e));return!!n&&n.some(t=>hk(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=>CI(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 TI={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function EI(e){return typeof e==`string`?TI[e]??[0,0,1]:e}function DI(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 OI(e,t){let n=AD(EI(e));return e=>{let r=U(),[i,a]=r.curveParameters(e.wrapped),o=(i+a)/2,{tangent:s}=r.curveTangent(e.wrapped,o),c=AD(s),l=Math.acos(Math.min(1,Math.abs(TD(c,n))));return Math.abs(l-hD*t)<1e-6}}function kI(e){return wI(`edge`,e,kI,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(OI(e,t)),ofLength:(e,t=.001)=>n(n=>Math.abs(Ck(n)-e)<t),ofCurveType:e=>n(t=>vk(t)===e),parallelTo:(t=`Z`)=>kI(e).inDirection(t,0),atDistance:(e,t=[0,0,0])=>n(DI(e,t,1e-6))}))}function AI(){return kI([])}function jI(e,t){let n=AD(EI(e));return e=>{let r=dO(e),i=Math.acos(Math.min(1,Math.abs(TD(AD(r),n))));return Math.abs(i-hD*t)<1e-6}}function MI(e){return wI(`face`,e,MI,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(jI(e,t)),parallelTo:(t=`Z`)=>MI(e).inDirection(t,0),ofSurfaceType:e=>n(t=>{let n=rO(t);return Ra(n)&&n.value===e}),ofArea:(e,t=.001)=>n(n=>{let r=kM(n);return Ra(r)&&Math.abs(r.value-e)<t}),atDistance:(e,t=[0,0,0])=>n(DI(e,t,1e-6))}))}function NI(){return MI([])}function PI(e){return wI(`wire`,e,PI,(e,t)=>({isClosed:()=>t(e=>Tk(e)),isOpen:()=>t(e=>!Tk(e)),ofEdgeCount:e=>t(t=>YE(t).length===e)}))}function FI(){return PI([])}function II(e,t){return typeof e==`object`&&`_topoKind`in e?e.findUnique(t):typeof e!=`function`&&wE(e)?O(e):e(NI()).findUnique(t)}function LI(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`}function RI(e,t){let n=10**t,r=t<0?e:.01/n+e;return Math.round(r*n)/n}function zI(e){return Math.round(e*100)/100}function BI(e){return Math.round(e*1e5)/1e5}var VI=([e,t])=>`(${zI(e)},${zI(t)})`,HI=(e,t=1e-9)=>{let n=e;return Math.abs(e)<t&&(n=0),n.toFixed(-Math.log10(t))},UI=(e,t=1e-9)=>Array.from(new Map(e.map(([e,n])=>[`[${HI(e,t)},${HI(n,t)}]`,[e,n]])).values()),WI=class{_wrapped;_deleted=!1;constructor(e){this._wrapped=e??hT().createBoundingBox2d(),VT(this,this._wrapped)}get wrapped(){if(this._deleted)throw Error(`This object has been deleted`);return this._wrapped}delete(){this._deleted||(this._deleted=!0,HT(this._wrapped),typeof this._wrapped.delete==`function`&&this._wrapped.delete())}[Symbol.dispose](){this.delete()}get repr(){let[e,t]=this.bounds;return`${VI(e)} - ${VI(t)}`}get bounds(){let{xMin:e,yMin:t,xMax:n,yMax:r}=hT().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){hT().mergeBBox2d(this.wrapped,e.wrapped)}isOut(e){return hT().isBBox2dOut(this.wrapped,e.wrapped)}containsPoint(e){return!hT().isBBox2dOutPoint(this.wrapped,e[0],e[1])}};function GI(e){return new KI(U().deserializeCurve2d(e))}var KI=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`&&VT(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`&&(HT(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 WI(t),this._boundingBox}get repr(){return`${this.geomType} ${VI(this.firstPoint)} - ${VI(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,pI(e,this.firstPoint),pI(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 LI(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?lI(e,this.firstPoint,t)?O(this.firstParameter):lI(e,this.lastPoint,t)?O(this.lastParameter):k(I(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n===void 0||r===void 0?k(I(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n>t?k(I(`POINT_NOT_ON_CURVE`,`Point ${VI(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=>LI(e)?j(this.parameter(e,r)):e);i=Array.from(new Map(i.map(e=>[RI(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))}},qI=(e,t=1e-4,n=`C0`,r=200)=>new KI(hT().approximateCurve2dAsBSpline(e.wrapped,t,n,r)),JI=e=>(e.geomType!==`BSPLINE_CURVE`&&M(`BSplineToBezier`,`You can only convert a Bspline`),hT().decomposeBSpline2dToBeziers(e.wrapped).map(e=>new KI(e)));function YI(e,t={tolerance:1e-4,continuity:`C0`,maxSegments:300}){let n=hT();return e.flatMap(e=>{let r=e.geomType;if(r===`ELLIPSE`||r===`CIRCLE`&&lI(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 YI(JI(r===`BSPLINE_CURVE`?e:qI(e,t.tolerance,t.continuity,t.maxSegments)),t)})}var XI=(e,t)=>{let n=new KI(U().makeLine2d(e[0],e[1],t[0],t[1]));return lI(n.firstPoint,e)||n.reverse(),n},ZI=(e,t,n)=>{let r=new KI(U().makeArc2dThreePoints(e[0],e[1],t[0],t[1],n[0],n[1]));if(!lI(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new KI(e)}return r},QI=(e,t,n)=>{let r=new KI(U().makeArc2dTangent(e[0],e[1],t[0],t[1],n[0],n[1]));if(!lI(r.firstPoint,e)){let e=U().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new KI(e)}return r},$I=(e,t=[0,0])=>new KI(U().makeCircle2d(t[0],t[1],e,!0)),eL=(e,t,n=[1,0],r=[0,0],i=!0)=>new KI(U().makeEllipse2d(r[0],r[1],e,t,n[0],n[1],i)),tL=(e,t,n,r,i=[0,0],a,o=!0)=>new KI(U().makeEllipseArc2d(i[0],i[1],e,t,n,r,a[0],a[1],o)),nL=(e,t,n)=>{let r=[[e[0],e[1]],...t.map(e=>[e[0],e[1]]),[n[0],n[1]]];return new KI(U().makeBezier2d(r))};function rL(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 KI(U().makeBSpline2d(a,{tolerance:t,smoothing:n,degMax:r,degMin:i,continuity:`C2`})))}catch(e){return k(I(`BSPLINE_2D_FAILED`,`B-spline approximation failed`,e))}}var iL=(e,t,n,r=!1)=>{let i=fI(uI(e,t),.5),a=pI(n,e)*(r?-1:1);return ZI(e,uI(fI(SI(dI(i,n)),a),n),t)},aL=(e,n)=>{let r=hT(),i=e.geomType,[a,o]=n,s=`${BI(a)} ${BI(o)}`;if(i===`LINE`)return`L ${s}`;if(i===`BEZIER_CURVE`){let n=r.getCurve2dBezierPoles(e.wrapped);n||M(`adaptedCurveToPathElem`,`Expected Bezier poles`);let i=n.length-1;if(i===1)return`L ${s}`;if(i===2){let[e,r]=t(n,1);return`Q ${zI(e)} ${zI(r)} ${s}`}if(i===3){let[e,r]=t(n,1),[i,a]=t(n,2);return`C ${zI(e)} ${zI(r)} ${zI(i)} ${zI(a)} ${s}`}}if(i===`CIRCLE`){let t=r.getCurve2dCircleData(e.wrapped);t||M(`adaptedCurveToPathElem`,`Expected circle data`);let{radius:n,isDirect:i}=t,c=r.getCurve2dBounds(e.wrapped),l=(c.last-c.first)*gD,u=l===360?`${BI(a)} ${BI(o+1e-4)}`:s;return`A ${n} ${n} 0 ${Math.abs(l)>180?`1`:`0`} ${i?`1`:`0`} ${u}`}if(i===`ELLIPSE`){let t=r.getCurve2dEllipseData(e.wrapped);t||M(`adaptedCurveToPathElem`,`Expected ellipse data`);let{majorRadius:n,minorRadius:i,xAxisAngle:c,isDirect:l}=t,u=r.getCurve2dBounds(e.wrapped),d=(u.last-u.first)*gD,f=d===360?`${BI(a)} ${BI(o+1e-4)}`:s,p=180-c*gD;return`A ${BI(n)} ${BI(i)} ${BI(p)} ${Math.abs(d)>180?`1`:`0`} ${l?`1`:`0`} ${f}`}M(`adaptedCurveToPathElem`,`Unsupported curve type: ${i}`)},oL=e=>{let t=U(),n=t.createBoundingBox2d();return e.forEach(e=>{t.addCurveToBBox2d(n,e.wrapped,1e-6)}),new WI(n)};function sL(e,t){let n=U();return e.map(e=>mE(n.liftCurve2dToPlane(e.wrapped,[...t.origin],[...t.zDir],[...t.xDir])))}var cL=(e,t)=>{let n=U();return e.map(e=>mE(n.buildEdgeOnSurface(e.wrapped,t)))},lL=(e,t)=>{let n=U();return e.map(e=>t?new KI(n.transformCurve2dGeneral(e.wrapped,t)):e.clone())},uL=(e,t,n=[0,0])=>U().createAffinityGTrsf2d(n[0],n[1],-t[1],t[0],e),dL=e=>U().createTranslationGTrsf2d(e[0],e[1]),fL=(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]),pL=(e,t=[0,0])=>U().createRotationGTrsf2d(e,t[0],t[1]),mL=(e,t=[0,0])=>U().createScaleGTrsf2d(e,t[0],t[1]);function hL(e,t,n=`original`){let r=U(),i=r.extractSurfaceFromFace(t.wrapped),a=sO(t),o=null;if(n===`original`&&iO(t)!==`PLANE`){if(iO(t)!==`CYLINDRE`)return k(F(`UNSUPPORTED_FACE_TYPE`,`Only planar and cylindrical faces can be unwrapped for sketching`));let e=r.getSurfaceCylinderData(i);if(!e)return k(F(`UNSUPPORTED_FACE_TYPE`,`Could not extract cylinder data from face surface`));e.isDirect||(i=r.reverseSurfaceU(i)),o=uL(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(lL(e,o),i);return o&&o.delete(),O(s)}function gL(e,t){let n=U(),r=new KI(n.extractCurve2dFromEdge(e.wrapped,t.wrapped));return Ok(e)===`backward`&&n.reverseCurve2d(r.wrapped),r}var _L=(e,t=1)=>`${e.bounds[0][0]-t} ${-e.bounds[1][1]-t} ${e.width+2*t} ${e.height+2*t}`,vL=(e,t,n=1)=>`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${_L(t,n)}" fill="none" stroke="black" stroke-width="0.6%" vector-effect="non-scaling-stroke">
17
17
  ${e}
18
18
  </svg>`;function yL(e){let t=e.map(e=>e.wrapped);return hE(U().makeWire(t))}var bL=class e{curves;_boundingBox;_orientation;_guessedOrientation;constructor(e){e.length===0&&M(`Blueprint`,`requires at least one curve — use createBlueprint() for Result-based validation`),this.curves=e,this._boundingBox=null,this._orientation=null,this._guessedOrientation=null}delete(){this.curves.forEach(e=>{e.delete()}),this._boundingBox&&this._boundingBox.delete()}[Symbol.dispose](){this.delete()}clone(){return new e(this.curves.map(e=>e.clone()))}get repr(){return[`Blueprint`,...this.curves.map(e=>e.repr)].join(`
@@ -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-t8RmNVaE.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-BaSSAtuF.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-CGFB9Tln.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-BF3kqfwN.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-DAoc0zrS.js"></script>
17
+ <script type="module" crossorigin src="./assets/index-Dc6MY1LX.js"></script>
18
18
  </head>
19
19
  <body>
20
20
  <div id="root"></div>