ignitefuse 0.1.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/LICENSE +202 -0
- package/README.md +37 -0
- package/THIRD_PARTY_NOTICES.md +37 -0
- package/dist/index.js +9954 -0
- package/dist/index.js.map +7 -0
- package/package.json +51 -0
- package/skills/ignitefuse/SKILL.md +75 -0
- package/skills/ignitefuse/references/full-api-and-architecture.md +93 -0
- package/skills/ignitefuse-dev/SKILL.md +22 -0
- package/skills/ignitefuse-dev/references/implementation-map.md +18 -0
- package/skills/ignitefuse-dev/references/task-recipes.md +32 -0
- package/skills/ignitefuse-make-toolpath/SKILL.md +48 -0
- package/skills/ignitefuse-make-toolpath/references/api-shape.md +211 -0
- package/skills/ignitefuse-make-toolpath/references/direct-open-case-solid-bottom.md +193 -0
- package/skills/ignitefuse-make-toolpath/references/direct-region-fill.md +34 -0
- package/skills/ignitefuse-make-toolpath/references/function-implementation.md +137 -0
- package/skills/ignitefuse-make-toolpath/references/stl-standard-fdm.md +50 -0
- package/skills/ignitefuse-params/SKILL.md +24 -0
- package/skills/ignitefuse-params/references/param-patterns.md +153 -0
- package/skills/ignitefuse-printer-scene/SKILL.md +26 -0
- package/skills/ignitefuse-printer-scene/references/canonical-printer-scene.md +110 -0
- package/skills/ignitefuse-studio-mcp/SKILL.md +29 -0
- package/skills/ignitefuse-studio-mcp/references/mcp-tools.md +205 -0
- package/web/_app/env.js +1 -0
- package/web/_app/immutable/assets/0.7gMbBLNl.css +1 -0
- package/web/_app/immutable/assets/2.DUefECe3.css +1 -0
- package/web/_app/immutable/chunks/BLxuUouR.js +1 -0
- package/web/_app/immutable/chunks/BYlkGUYK.js +2 -0
- package/web/_app/immutable/chunks/ByZS5AaA.js +1 -0
- package/web/_app/immutable/chunks/C8-ejoe7.js +1 -0
- package/web/_app/immutable/chunks/CH8BOpuN.js +1 -0
- package/web/_app/immutable/chunks/Crm9Js9u.js +1 -0
- package/web/_app/immutable/chunks/D2Rdy9P1.js +1 -0
- package/web/_app/immutable/chunks/DwxNakxI.js +1 -0
- package/web/_app/immutable/entry/app.CUixVVde.js +2 -0
- package/web/_app/immutable/entry/start.DLVy4bB7.js +1 -0
- package/web/_app/immutable/nodes/0.Dgd1b1QE.js +1 -0
- package/web/_app/immutable/nodes/1.D_VGAzop.js +1 -0
- package/web/_app/immutable/nodes/2.CajHQkWG.js +5344 -0
- package/web/_app/immutable/workers/assets/clipper2z-bvMLVKp3.wasm +0 -0
- package/web/_app/immutable/workers/fuseRuntime.worker-DXbd4CFC.js +22 -0
- package/web/_app/immutable/workers/layerToolpath.worker-5A0bN0Cv.js +15 -0
- package/web/_app/immutable/workers/sectionConnect.worker-D4w8efrj.js +1 -0
- package/web/_app/version.json +1 -0
- package/web/favicon.png +0 -0
- package/web/icon.png +0 -0
- package/web/index.html +43 -0
- package/web/logo.png +0 -0
|
Binary file
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
(function(){"use strict";function Ns(e,t){return t.forEach(function(n){n&&typeof n!="string"&&!Array.isArray(n)&&Object.keys(n).forEach(function(r){if(r!=="default"&&!(r in e)){var i=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(e,r,i.get?i:{enumerable:!0,get:function(){return n[r]}})}})}),Object.freeze(e)}const Ds=e=>e.replaceAll(`\r
|
|
2
|
+
`,`
|
|
3
|
+
`).replace(/\n+$/,"").split(`
|
|
4
|
+
`),bt=e=>Array.isArray(e)?e:Ds(e),Ws=e=>{for(let t=e.length-1;t>=0;t-=1)if(e[t].trim())return t;return e.length},gn=e=>{const t=bt(e),n=r=>gn(r);return{append:r=>n([...t,...bt(r)]),insertBeforeEnd:r=>{const i=Ws(t);return n([...t.slice(0,i),...bt(r),...t.slice(i)])},mapLines:r=>{const i=t.flatMap((s,a)=>{const o=r(s,a,t);return o===null?[]:typeof o>"u"?[s]:Array.isArray(o)?o:[o]});return n(i)},prepend:r=>n([...bt(r),...t]),replace:(r,i)=>n(t.map(s=>s.replace(r,i))),toLines:()=>[...t],toString:()=>`${t.join(`
|
|
5
|
+
`)}
|
|
6
|
+
`}},yn=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],ve=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],vt=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],ue=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Fe=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],xr=e=>Math.sqrt(ue(e,e)),xe=e=>{const t=xr(e);return t===0?[0,0,0]:vt(e,1/t)},xt={origin:[0,0,0],xAxis:[1,0,0],yAxis:[0,1,0],zAxis:[0,0,1]},Ke=(e,t)=>Array.isArray(e)?[Number.isFinite(Number(e[0]))?Number(e[0]):t[0],Number.isFinite(Number(e[1]))?Number(e[1]):t[1],Number.isFinite(Number(e[2]))?Number(e[2]):t[2]]:t,Os=e=>({bounds:e==null?void 0:e.bounds,origin:Ke(e==null?void 0:e.origin,xt.origin),xAxis:Ke(e==null?void 0:e.xAxis,xt.xAxis),yAxis:Ke(e==null?void 0:e.yAxis,xt.yAxis),zAxis:Ke(e==null?void 0:e.zAxis,xt.zAxis)}),Bs=e=>{const[[t,n,r],[i,s,a],[o,d,u]]=[[e.xAxis[0],e.yAxis[0],e.zAxis[0]],[e.xAxis[1],e.yAxis[1],e.zAxis[1]],[e.xAxis[2],e.yAxis[2],e.zAxis[2]]],p=t*(s*u-a*d)-n*(i*u-a*o)+r*(i*d-s*o);if(Math.abs(p)<1e-12)throw new Error("printer.machineFrame axes must form an invertible basis.");const m=1/p;return[[(s*u-a*d)*m,(r*d-n*u)*m,(n*a-r*s)*m],[(a*o-i*u)*m,(t*u-r*o)*m,(r*i-t*a)*m],[(i*d-s*o)*m,(n*o-t*d)*m,(t*s-n*i)*m]]},Gs=(e,t)=>{const n=[e.x,e.y,e.z],r=ve(n,t.origin),i=Bs(t);return{...e,x:i[0][0]*r[0]+i[0][1]*r[1]+i[0][2]*r[2],y:i[1][0]*r[0]+i[1][1]*r[1]+i[1][2]*r[2],z:i[2][0]*r[0]+i[2][1]*r[1]+i[2][2]*r[2]}},$r=(e,t)=>Gs(e,Os(t)),js=e=>Math.abs(ue(e,[0,0,1]))>.95?[1,0,0]:xe(Fe([0,0,1],e)),Hs=e=>{const t=xe(e.normal),n=xe(e.xAxis??js(t)),r=xe(e.yAxis??Fe(t,n));return{origin:Ke(e.origin,[0,0,0]),normal:t,xAxis:n,yAxis:r}},_r=e=>({origin:[0,0,e],normal:[0,0,1],xAxis:[1,0,0],yAxis:[0,1,0]}),wr=e=>ue(e.origin,e.normal),Us=(e,t)=>{const n=yn(yn(t.origin,vt(t.xAxis,e.x)),yn(vt(t.yAxis,e.y),vt(t.normal,e.z)));return{...e,x:n[0],y:n[1],z:n[2]}},Vs=(e,t)=>({...e,points:e.points.map(n=>Us(n,t))});var Ys={type:"abs",diameter:1.75,flowRatio:1,nozzleTemp:245,bedTemp:100,cooling:{maxFanSpeed:80,recommendedFanSpeed:0}},Xs={type:"asa",diameter:1.75,flowRatio:1,nozzleTemp:250,bedTemp:100,cooling:{maxFanSpeed:80,recommendedFanSpeed:0}},Ks={type:"petg",diameter:1.75,flowRatio:1,nozzleTemp:235,bedTemp:75,cooling:{bridgeFanSpeed:255,maxFanSpeed:180,recommendedFanSpeed:90}},Zs={type:"pla",diameter:1.75,flowRatio:1,nozzleTemp:210,bedTemp:60,cooling:{bridgeFanSpeed:255,maxFanSpeed:255,recommendedFanSpeed:180}},qs={type:"tpu",diameter:1.75,flowRatio:1,nozzleTemp:225,bedTemp:45,cooling:{bridgeFanSpeed:200,maxFanSpeed:180,recommendedFanSpeed:120}},Js={id:"base-fdm",name:"Generic FDM Base",buildArea:{x:[0,220],y:[0,220],z:[0,250]},machineFrame:{origin:[0,0,0],xAxis:[1,0,0],yAxis:[0,1,0],zAxis:[0,0,1],bounds:{x:[0,220],y:[0,220],z:[0,250]}},capabilities:{heatedBed:!0,partCoolingFan:!0},filament:1.75,layerHeight:.2,nozzle:.4},Qs={id:"base-bambu-fdm",inherits:"base-fdm",name:"Bambu Lab FDM Base",capabilities:{auxiliaryFan:!0,bedProbe:!0,supportsM73:!0},gcodeFlavor:"bambu",gcodeStyle:"bambu",gcodeScripts:{layerChange:[{line:"M73 L[layer_num+1]",when:{capability:"supportsM73"}},{line:"M991 S0 P[layer_num] ;notify layer change",when:{capability:"supportsM73"}}],machinePause:["M400 U1"]}},eo={id:"base-klipper-fdm",inherits:"base-fdm",name:"Klipper FDM Base",capabilities:{supportsExcludeObject:!0},gcodeFlavor:"klipper",gcodeStyle:"orca",gcodeScripts:{machineStart:[";===== Klipper start (IgniteFuse) =====","G90 ; absolute coordinates","M83 ; relative extrusion",{line:"M140 S[bed_temperature_initial_layer_single] ; set bed temperature",when:{capability:"heatedBed"}},"M104 S[nozzle_temperature_initial_layer] ; set nozzle temperature","G28 ; home all axes",{line:"M190 S[bed_temperature_initial_layer_single] ; wait for bed temperature",when:{capability:"heatedBed"}},"M109 S[nozzle_temperature_initial_layer] ; wait for nozzle temperature","G92 E0 ; reset extrusion"],beforeLayerChange:[";BEFORE_LAYER_CHANGE",";[layer_z]","G92 E0"],layerChange:[";AFTER_LAYER_CHANGE",";[layer_z]"],machineEnd:[";===== Klipper end (IgniteFuse) =====","M400 ; wait for moves","G92 E0","G1 E-0.8 F1800 ; retract",{line:"M107 ; fan off",when:{capability:"partCoolingFan"}},"M104 S0 ; hotend off",{line:"M140 S0 ; bed off",when:{capability:"heatedBed"}},"G91 ; relative positioning","G0 Z10 F1200 ; lift","G90 ; absolute positioning","M84 ; motors off"],machinePause:["PAUSE"]}},to={id:"base-marlin-fdm",inherits:"base-fdm",name:"Marlin FDM Base",gcodeFlavor:"marlin",gcodeStyle:"orca"},no={id:"base-prusa-fdm",inherits:"base-marlin-fdm",name:"Prusa FDM Base",capabilities:{bedProbe:!0,supportsM486:!0},gcodeStyle:"prusa"},ro={id:"bambu-a1-mini",inherits:"base-bambu-fdm",name:"Bambu Lab A1 mini",buildArea:{x:[0,180],y:[0,180],z:[0,180]},machineFrame:{origin:[0,0,0],xAxis:[1,0,0],yAxis:[0,1,0],zAxis:[0,0,1],bounds:{x:[0,180],y:[0,180],z:[0,180]}},gcodeScripts:{machineStart:[";===== machine: Bambu Lab A1 mini (IgniteFuse) =====","M1002 gcode_claim_action : 2","M1002 set_filament_type:[filament_type]","M104 S170 ; preheat nozzle",{line:"M140 S[bed_temperature_initial_layer_single] ; set bed temperature",when:{capability:"heatedBed"}},"G392 S0 ; turn off clog detect during preparation","M17","M400 S1","G90","M83","M220 S100 ; reset feedrate","M221 S100 ; reset flowrate",{line:"M73.2 R1.0 ; reset remaining time multiplier",when:{capability:"supportsM73"}},"G28 ; home all axes",{line:"M190 S[bed_temperature_initial_layer_single] ; wait for bed temperature",when:{capability:"heatedBed"}},"M109 S[nozzle_temperature_initial_layer] ; wait for nozzle temperature","M1002 gcode_claim_action : 1",{line:"G29 A1 X[first_layer_print_min_x] Y[first_layer_print_min_y] I[first_layer_print_size_x] J[first_layer_print_size_y] ; bed leveling",when:{capability:"bedProbe"}},"M400","M1002 gcode_claim_action : 0","M1007 S1","G92 E0","G1 X-13.5 Y0 Z10 F10000 ; move to purge side","G1 E1.2 F500","G1 X18 Y1 Z0.3 F18000","G1 X80 E8 F900 ; purge line","G92 E0"],machineEnd:[";===== Bambu A1 mini end (IgniteFuse) =====","G392 S0 ; turn off clog detect","M400 ; wait for buffer to clear","G92 E0","G1 E-0.8 F1800 ; retract","G1 Z{max_layer_z + 0.5} F900 ; lift","G1 X0 Y180 F18000 ; move to safe pos",{line:"M140 S0 ; turn off bed",when:{capability:"heatedBed"}},{line:"M106 S0 ; turn off fan",when:{capability:"partCoolingFan"}},{line:"M106 P2 S0 ; turn off remote part cooling fan",when:{capability:"auxiliaryFan"}},{line:"M106 P3 S0 ; turn off chamber cooling fan",when:{capability:"auxiliaryFan"}},"M104 S0 ; turn off hotend","M400",{line:"M73.2 R1.0 ; reset remaining time multiplier",when:{capability:"supportsM73"}},"M1002 set_gcode_claim_speed_level : 0","M18 X Y Z"]}},io={id:"bambu-a1",inherits:"base-bambu-fdm",name:"Bambu Lab A1",buildArea:{x:[0,256],y:[0,256],z:[0,256]},machineFrame:{origin:[0,0,0],xAxis:[1,0,0],yAxis:[0,1,0],zAxis:[0,0,1],bounds:{x:[0,256],y:[0,256],z:[0,256]}},gcodeScripts:{machineStart:[";===== machine: Bambu Lab A1 (IgniteFuse) =====","M1002 gcode_claim_action : 2","M1002 set_filament_type:[filament_type]","M104 S170 ; preheat nozzle",{line:"M140 S[bed_temperature_initial_layer_single] ; set bed temperature",when:{capability:"heatedBed"}},"G392 S0 ; turn off clog detect during preparation","M17","M400 S1","G90","M83","M220 S100 ; reset feedrate","M221 S100 ; reset flowrate",{line:"M73.2 R1.0 ; reset remaining time multiplier",when:{capability:"supportsM73"}},"G28 ; home all axes",{line:"M190 S[bed_temperature_initial_layer_single] ; wait for bed temperature",when:{capability:"heatedBed"}},"M109 S[nozzle_temperature_initial_layer] ; wait for nozzle temperature","M1002 gcode_claim_action : 1",{line:"G29 A1 X[first_layer_print_min_x] Y[first_layer_print_min_y] I[first_layer_print_size_x] J[first_layer_print_size_y] ; bed leveling",when:{capability:"bedProbe"}},"M400","M1002 gcode_claim_action : 0","M1007 S1","G92 E0","G1 X-13.5 Y0 Z10 F10000 ; move to purge side","G1 E1.2 F500","G1 X18 Y1 Z0.3 F18000","G1 X120 E12 F900 ; purge line","G92 E0"],machineEnd:[";===== Bambu A1 end (IgniteFuse) =====","G392 S0 ; turn off clog detect","M400 ; wait for buffer to clear","G92 E0","G1 E-0.8 F1800 ; retract","G1 Z{max_layer_z + 0.5} F900 ; lift","G1 X0 Y220 F18000 ; move to safe pos",{line:"M140 S0 ; turn off bed",when:{capability:"heatedBed"}},{line:"M106 S0 ; turn off fan",when:{capability:"partCoolingFan"}},{line:"M106 P2 S0 ; turn off remote part cooling fan",when:{capability:"auxiliaryFan"}},{line:"M106 P3 S0 ; turn off chamber cooling fan",when:{capability:"auxiliaryFan"}},"M104 S0 ; turn off hotend","M400",{line:"M73.2 R1.0 ; reset remaining time multiplier",when:{capability:"supportsM73"}},"M1002 set_gcode_claim_speed_level : 0","M18 X Y Z"]}},so={id:"bambu-p1s",inherits:"base-bambu-fdm",name:"Bambu Lab P1S",buildArea:{x:[0,256],y:[0,256],z:[0,256]},machineFrame:{origin:[0,0,0],xAxis:[1,0,0],yAxis:[0,1,0],zAxis:[0,0,1],bounds:{x:[0,256],y:[0,256],z:[0,256]}},capabilities:{heatedChamber:!1},gcodeScripts:{machineStart:[";===== machine: Bambu Lab P1S (IgniteFuse) =====","M1002 gcode_claim_action : 2","M104 S170 ; preheat nozzle",{line:"M140 S[bed_temperature_initial_layer_single] ; set bed temperature",when:{capability:"heatedBed"}},"M17","G90","M83","M220 S100 ; reset feedrate","M221 S100 ; reset flowrate",{line:"M73.2 R1.0 ; reset remaining time multiplier",when:{capability:"supportsM73"}},{line:"M190 S[bed_temperature_initial_layer_single] ; wait for bed temperature",when:{capability:"heatedBed"}},"M104 S[nozzle_temperature_initial_layer] ; set nozzle temperature","G28 ; home all axes",{line:"G29 A X[first_layer_print_min_x] Y[first_layer_print_min_y] I[first_layer_print_size_x] J[first_layer_print_size_y] ; bed leveling",when:{capability:"bedProbe"}},"M109 S[nozzle_temperature_initial_layer] ; wait for nozzle temperature","M400","M1002 gcode_claim_action : 0","G92 E0","G1 X18 Y1 Z0.3 F18000","G1 X220 E15 F900 ; purge line","G92 E0"],machineEnd:[";===== Bambu P1S end (IgniteFuse) =====","M400 ; wait for buffer to clear","G92 E0","G1 E-0.8 F1800 ; retract","G1 Z{max_layer_z + 0.5} F900 ; lift","G1 X65 Y245 F12000 ; move to safe pos",{line:"M140 S0 ; turn off bed",when:{capability:"heatedBed"}},{line:"M106 S0 ; turn off fan",when:{capability:"partCoolingFan"}},{line:"M106 P2 S0 ; turn off auxiliary fan",when:{capability:"auxiliaryFan"}},{line:"M106 P3 S0 ; turn off chamber fan",when:{capability:"auxiliaryFan"}},"M104 S0 ; turn off hotend","M400",{line:"M73.2 R1.0 ; reset remaining time multiplier",when:{capability:"supportsM73"}},"M1002 set_gcode_claim_speed_level : 0"]}},oo={id:"bambu-x1c",inherits:"base-bambu-fdm",name:"Bambu Lab X1 Carbon",buildArea:{x:[0,256],y:[0,256],z:[0,256]},machineFrame:{origin:[0,0,0],xAxis:[1,0,0],yAxis:[0,1,0],zAxis:[0,0,1],bounds:{x:[0,256],y:[0,256],z:[0,256]}},capabilities:{chamberLight:!0,heatedChamber:!0},gcodeScripts:{machineStart:[";===== machine: Bambu Lab X1 Carbon (IgniteFuse) =====","M1002 gcode_claim_action : 2","M104 S170 ; preheat nozzle",{line:"M140 S[bed_temperature_initial_layer_single] ; set bed temperature",when:{capability:"heatedBed"}},"M17","G90","M83","M220 S100 ; reset feedrate","M221 S100 ; reset flowrate",{line:"M73.2 R1.0 ; reset remaining time multiplier",when:{capability:"supportsM73"}},{line:"M190 S[bed_temperature_initial_layer_single] ; wait for bed temperature",when:{capability:"heatedBed"}},"M104 S[nozzle_temperature_initial_layer] ; set nozzle temperature","G28 ; home all axes",{line:"G29 A X[first_layer_print_min_x] Y[first_layer_print_min_y] I[first_layer_print_size_x] J[first_layer_print_size_y] ; bed leveling",when:{capability:"bedProbe"}},"M109 S[nozzle_temperature_initial_layer] ; wait for nozzle temperature","M400","M1002 gcode_claim_action : 0","G92 E0","G1 X18 Y1 Z0.3 F18000","G1 X220 E15 F900 ; purge line","G92 E0"],machineEnd:[";===== Bambu X1 Carbon end (IgniteFuse) =====","M400 ; wait for buffer to clear","G92 E0","G1 E-0.8 F1800 ; retract","G1 Z{max_layer_z + 0.5} F900 ; lift","G1 X65 Y245 F12000 ; move to safe pos",{line:"M140 S0 ; turn off bed",when:{capability:"heatedBed"}},{line:"M106 S0 ; turn off fan",when:{capability:"partCoolingFan"}},{line:"M106 P2 S0 ; turn off auxiliary fan",when:{capability:"auxiliaryFan"}},{line:"M106 P3 S0 ; turn off chamber fan",when:{capability:"auxiliaryFan"}},"M104 S0 ; turn off hotend","M400",{line:"M960 S5 P0 ; turn off logo lamp",when:{capability:"chamberLight"}},{line:"M73.2 R1.0 ; reset remaining time multiplier",when:{capability:"supportsM73"}},"M1002 set_gcode_claim_speed_level : 0"]}},ao={id:"generic-klipper",inherits:"base-klipper-fdm",name:"Generic Klipper FDM 220"},co={id:"generic-marlin",inherits:"base-marlin-fdm",name:"Generic Marlin FDM 220"},lo={id:"prusa-mk4",inherits:"base-prusa-fdm",name:"Prusa MK4",buildArea:{x:[0,220],y:[0,220],z:[0,250]},machineFrame:{origin:[0,0,0],xAxis:[1,0,0],yAxis:[0,1,0],zAxis:[0,0,1]},capabilities:{bedProbe:!0,supportsM486:!0}};const bn={heatedBed:!0,partCoolingFan:!0},Mr={"base-fdm":Js,"base-bambu-fdm":Qs,"base-klipper-fdm":eo,"base-marlin-fdm":to,"base-prusa-fdm":no,"generic-marlin":co,"generic-klipper":ao,"bambu-a1-mini":ro,"bambu-a1":io,"bambu-p1s":so,"bambu-x1c":oo,"prusa-mk4":lo},uo=["generic-marlin","generic-klipper","bambu-a1-mini","bambu-a1","bambu-p1s","bambu-x1c","prusa-mk4"],Pr={abs:Ys,asa:Xs,petg:Ks,pla:Zs,tpu:qs},fo=(e,t)=>{const{inherits:n,...r}=e,{inherits:i,...s}=t,a={...r,...s,capabilities:{...e.capabilities,...t.capabilities},defaults:{...e.defaults,...t.defaults},gcodeScripts:{...e.gcodeScripts,...t.gcodeScripts},machineFrame:t.machineFrame??e.machineFrame};return(e.process||t.process)&&(a.process={...e.process,...t.process}),a},vn=(e,t=[])=>{const n=Mr[e]??Mr["generic-marlin"];if(!n)throw new Error(`Unknown printer preset: ${e}`);if(t.includes(e))throw new Error(`Circular printer preset inheritance: ${[...t,e].join(" -> ")}`);const r=n.inherits?vn(n.inherits,[...t,e]):{};return fo(r,n)},ho=e=>{const t=[];e.buildArea||t.push("buildArea is missing."),e.machineFrame||t.push("machineFrame is missing."),(!Number.isFinite(e.nozzle)||e.nozzle<=0)&&t.push("nozzle must be positive."),(!Number.isFinite(e.filament)||e.filament<=0)&&t.push("filament must be positive."),(!Number.isFinite(e.layerHeight)||e.layerHeight<=0)&&t.push("layerHeight must be positive.");const n=e.machineFrame;if(n){const r=n.xAxis[0]*(n.yAxis[1]*n.zAxis[2]-n.yAxis[2]*n.zAxis[1])-n.yAxis[0]*(n.xAxis[1]*n.zAxis[2]-n.xAxis[2]*n.zAxis[1])+n.zAxis[0]*(n.xAxis[1]*n.yAxis[2]-n.xAxis[2]*n.yAxis[1]);(!Number.isFinite(r)||Math.abs(r)<1e-9)&&t.push("machineFrame basis must be invertible.")}return t},Cr=e=>{const t=vn(e),n=ho(t);if(n.length>0)throw new Error(`Invalid printer preset ${e}: ${n.join(" ")}`);return t},xn=Cr("generic-marlin");Object.fromEntries(uo.map(e=>[e,Cr(e)]));const Ir=(e,t={})=>{const n=vn(e);return{...n,...t,capabilities:{...bn,...n.capabilities,...t.capabilities},defaults:{...n.defaults,...t.defaults},gcodeScripts:{...n.gcodeScripts,...t.gcodeScripts},machineFrame:t.machineFrame??n.machineFrame}},Sr=(e,t={})=>{var n;return{...Pr[e]??{diameter:1.75,flowRatio:1,type:e},...t,cooling:{...((n=Pr[e])==null?void 0:n.cooling)??{},...t.cooling}}},$n=["x","y","z"],Ze={x:0,y:0,z:0},po=new Set(["outerWall","innerWall","infill","solidInfill","top","bottom","support"]),U=e=>e.toFixed(3).replace(/\.?0+$/,""),mo=e=>String(Math.max(0,Math.min(255,Math.round(e)))),ee=e=>typeof e=="number"&&Number.isFinite(e),go=(e,t)=>{var n;return t??e.machineFrame??((n=e.coordinates)==null?void 0:n.machineFrame)},yo=e=>$n.some(t=>Math.abs(e[t])>1e-9),bo=(e,t)=>({...e,x:e.x+t.x,y:e.y+t.y,z:e.z+t.z}),_n=(e,t,n)=>bo($r(e,t),n),Er=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Ar=e=>{const t=Math.hypot(e[0],e[1],e[2]);return t<1e-12?[0,0,1]:[e[0]/t,e[1]/t,e[2]/t]},zr=e=>{const t=Ar(e.normal);return n=>Math.abs(Er([n.x-e.origin[0],n.y-e.origin[1],n.z-e.origin[2]],t))},vo=e=>{const t=Math.min(e.z[0],e.z[1]);return n=>Math.abs(n.z-t)},xo=e=>{const t=Ar([-e[0],-e[1],-e[2]]);return n=>Er([n.x,n.y,n.z],t)},$o=e=>{var n,r,i;const t=(n=e.process)==null?void 0:n.contact;if(t&&t!=="bed")return zr(t);if(e.buildArea)return vo(e.buildArea);if((t==="bed"||t===void 0)&&((r=e.bed)!=null&&r.frame))return zr(e.bed.frame);if((i=e.process)!=null&&i.gravity)return xo(e.process.gravity)},fe=(e,t)=>t(e),Fr=(e,t)=>e.points.reduce((n,r)=>Math.min(n,fe(r,t)),Number.POSITIVE_INFINITY),_o=(e,t)=>{if(e.points.length<2)return e;let n=0,r=Number.POSITIVE_INFINITY;for(let s=0;s<e.points.length;s+=1){const a=fe(e.points[s],t);a<r&&(n=s,r=a)}const i=[...e.points.slice(n),...e.points.slice(0,n)];if(i.length>2){const s=fe(i[1],t);if(fe(i[i.length-1],t)<s)return{...e,points:[i[0],...i.slice(1).reverse()]}}return{...e,points:i}},wo=(e,t)=>{if(e.points.length<2)return e;const n=fe(e.points[0],t);return fe(e.points[e.points.length-1],t)<n?{...e,points:[...e.points].reverse()}:e},Mo=(e,t)=>{const n=[];for(let r=0;r+1<e.points.length;r+=2){const i=e.points[r],s=e.points[r+1];n.push(fe(s,t)<fe(i,t)?[s,i]:[i,s])}return n.sort((r,i)=>{const s=Math.min(fe(r[0],t),fe(r[1],t)),a=Math.min(fe(i[0],t),fe(i[1],t));return s-a}),{...e,points:n.flatMap(([r,i])=>[r,i])}},Po=(e,t)=>e.primitive==="segments"?Mo(e,t):e.closed?_o(e,t):wo(e,t),Co=(e,t)=>{if(!t)return e;const n=e.filter(i=>i.role!=="travel");return(n.length>0?n:e).map((i,s)=>({index:s,path:Po(i,t),score:Fr(i,t)})).sort((i,s)=>i.score-s.score||i.index-s.index).map(i=>i.path)},Tr=()=>({x:{max:Number.NEGATIVE_INFINITY,min:Number.POSITIVE_INFINITY},y:{max:Number.NEGATIVE_INFINITY,min:Number.POSITIVE_INFINITY},z:{max:Number.NEGATIVE_INFINITY,min:Number.POSITIVE_INFINITY}}),kr=(e,t)=>{for(const n of $n)e[n].min=Math.min(e[n].min,t[n]),e[n].max=Math.max(e[n].max,t[n])},Lr=e=>$n.every(t=>Number.isFinite(e[t].min)&&Number.isFinite(e[t].max)),Io=(e,t)=>{const n=Tr(),r=e.layers.flatMap(i=>i.paths.flatMap(s=>s.points));for(const i of r)kr(n,$r(i,t));return Lr(n)?n:void 0},wn=(e,t)=>typeof t=="number"?t-e.min:t==="min"?-e.min:t==="center"?-((e.min+e.max)/2):t==="max"?-e.max:0,So=(e,t,n)=>{if(!n)return Ze;const r=Io(e,t);return r?{x:wn(r.x,n.x??"none"),y:wn(r.y,n.y??"none"),z:wn(r.z,n.z??"none")}:Ze},Eo=(e,t)=>{var i;const n=typeof t=="string"?Ir(t):t,r=e.printer??xn;return{...xn,...r,...n,capabilities:{...bn,...r.capabilities,...n==null?void 0:n.capabilities},defaults:{...r.defaults,...n==null?void 0:n.defaults},gcodeScripts:{...r.gcodeScripts,...n==null?void 0:n.gcodeScripts},machineFrame:(n==null?void 0:n.machineFrame)??r.machineFrame??((i=r.coordinates)==null?void 0:i.machineFrame)??xn.machineFrame}},Ao=(e,t)=>{var r,i,s,a;const n=typeof t=="string"?Sr(t):t??{};return{...n,bedTemp:n.bedTemp??((r=e.defaults)==null?void 0:r.bedTemp),chamberTemp:n.chamberTemp??((i=e.defaults)==null?void 0:i.chamberTemp),diameter:n.diameter??((s=e.defaults)==null?void 0:s.filamentDiameter)??e.filament??1.75,flowRatio:n.flowRatio??1,nozzleTemp:n.nozzleTemp??((a=e.defaults)==null?void 0:a.nozzleTemp)}},zo=(e,t)=>{var i,s,a,o;const n=(t==null?void 0:t.flavor)??e.gcodeFlavor??"marlin",r=(t==null?void 0:t.style)??e.gcodeStyle??(n==="bambu"?"bambu":"orca");return{flavor:n,style:r,metadata:{objectLabels:((i=t==null?void 0:t.metadata)==null?void 0:i.objectLabels)??!1,printStats:((s=t==null?void 0:t.metadata)==null?void 0:s.printStats)??!0,slicerComments:((a=t==null?void 0:t.metadata)==null?void 0:a.slicerComments)??!0,thumbnails:((o=t==null?void 0:t.metadata)==null?void 0:o.thumbnails)??!1}}},Fo=(e,t,n)=>{var r,i,s,a;return{...n,acceleration:n==null?void 0:n.acceleration,cooling:{enabled:((r=e.capabilities)==null?void 0:r.partCoolingFan)!==!1,fanSpeed:((i=t.cooling)==null?void 0:i.recommendedFanSpeed)??180,maxFanSpeed:((s=t.cooling)==null?void 0:s.maxFanSpeed)??255,offLayers:1,rampLayers:0,...n==null?void 0:n.cooling},retraction:{enabled:!1,length:.8,speed:2100,zHop:0,...n==null?void 0:n.retraction},speed:{mode:"preserveGraph",travel:((a=e.defaults)==null?void 0:a.travelSpeed)??7200,...n==null?void 0:n.speed}}},To=(e,t)=>{const n=Eo(e,t.printer),r=Ao(n,t.filament);return{capabilities:{...bn,...n.capabilities},filament:r,output:zo(n,t.output),print:Fo(n,r,t.print),printer:n,scripts:{...n.gcodeScripts,...t.scripts}}},Rr={bottom:"Bottom solid infill",infill:"Sparse infill",innerWall:"Inner wall",outerWall:"Outer wall",solidInfill:"Internal solid infill",support:"Support",top:"Top solid infill",travel:"Travel"},ko={bottom:"Bottom surface",infill:"Sparse infill",innerWall:"Inner wall",outerWall:"Outer wall",solidInfill:"Internal solid infill",support:"Support",top:"Top surface",travel:"Travel"},Lo=(e,t)=>t==="plain"?"":`; ${e}`,Ro=(e,t)=>t==="plain"?"":t==="orca"||t==="bambu"?`; FEATURE: ${ko[e]}`:t==="prusa"?`;TYPE:${Rr[e]}`:`; ${e} path`,$t=e=>e.map(t=>U(t)).join(","),No=(e,t,n,r,i)=>{var u,p,m,g;const s=t.output.style;if(s==="plain")return[];const a=i?Math.abs(e.z-i.z):((p=(u=e.paths[0])==null?void 0:u.extrusion)==null?void 0:p.height)??e.z,o=`;IF_LAYER_PLANE O${$t(e.plane.origin)} N${$t(e.plane.normal)} X${$t(e.plane.xAxis)} Y${$t(e.plane.yAxis)}`,d=U(a||((g=(m=e.paths[0])==null?void 0:m.extrusion)==null?void 0:g.height)||0);if(s==="orca"||s==="bambu"){const C=["; CHANGE_LAYER",`; Z_HEIGHT: ${U(e.z)}`,`; LAYER_HEIGHT: ${d}`,o,`; layer num/total_layer_count: ${n}/${r}`,"; update layer progress"];return s==="bambu"&&t.output.flavor==="bambu"&&Pn(t.scripts.layerChange,t.capabilities)===0&&t.capabilities.supportsM73&&(C.push(`M73 L${n}`),C.push(`M991 S0 P${n-1} ;notify layer change`)),C}return s==="prusa"?[";LAYER_CHANGE",`;LAYER:${e.index}`,`;Z:${U(e.z)}`,`;HEIGHT:${d}`,o]:[`; Layer ${e.index} Z${U(e.z)}`,`;LAYER:${e.index}`,o]},Nr=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y,e.z-t.z),Do=e=>Math.PI*(e/2)**2,qe=e=>e.role!=="travel"&&!!e.extrusion&&po.has(e.role),Wo=(e,t,n,r)=>!(e.roles&&!e.roles.includes(n.role)||e.objectId&&e.objectId!==n.objectId||typeof e.layerIndex=="number"&&t.index!==e.layerIndex||Array.isArray(e.layerIndex)&&(t.index<e.layerIndex[0]||t.index>e.layerIndex[1])||e.z&&(t.z<e.z[0]||t.z>e.z[1])||typeof e.contactDistance=="number"&&(!r||Fr(n,r)>e.contactDistance)),Oo=(e,t,n,r)=>{const i=n.print.speed;let s=i.mode==="override"?i.default??t.speed:t.speed;t.role==="travel"&&ee(i.travel)&&(s=i.travel),t.role!=="travel"&&e.index===0&&ee(i.firstLayer)&&(s=i.firstLayer),(t.role==="bottom"||t.role==="solidInfill")&&e.index===0&&ee(i.bottom)&&(s=i.bottom),t.role==="top"&&ee(i.top)&&(s=i.top);const a=i[t.role];ee(a)&&(s=a);for(const o of i.rules??[])Wo(o,e,t,r)&&(s=o.speed);return Math.max(1,s||i.default||1200)},Bo=(e,t,n)=>{const r=n.print.acceleration;if(r)return e.index===0&&ee(r.firstLayer)?r.firstLayer:t.role==="travel"&&ee(r.travel)?r.travel:r[t.role]??r.default},Dr=(e,t)=>{const n=Object.entries(t??{}).filter(r=>r[1]!==void 0).map(([r,i])=>`${r}=${i}`);return[e,...n].join(" ")},Go=["bed_temperature","bed_temperature_initial_layer","bed_temperature_initial_layer_single","filament_diameter","filament_type","first_layer_bed_temperature","first_layer_print_max_x","first_layer_print_max_y","first_layer_print_min_x","first_layer_print_min_y","first_layer_print_size_x","first_layer_print_size_y","first_layer_temperature","layer_height","layer_num","layer_z","machine_name","max_layer_z","nozzle_diameter","nozzle_temperature","nozzle_temperature_initial_layer","print_max_x","print_max_y","print_max_z","print_min_x","print_min_y","print_min_z","print_size_x","print_size_y","print_size_z","printer_name","temperature","total_layer_count"],Wr=new Set(Go),jo=e=>e?Array.isArray(e)?e:e.split(/\r?\n/):[],Ho=e=>typeof e=="string"?e:e.line,_t=(e,t)=>!!e[t],Uo=(e,t)=>{if(typeof e=="string"||!e.when)return!0;const{allCapabilities:n,anyCapabilities:r,capability:i,notCapability:s}=e.when;return!(i&&!_t(t,i)||s&&_t(t,s)||n!=null&&n.some(a=>!_t(t,a))||r&&r.length>0&&!r.some(a=>_t(t,a)))},Mn=(e,t)=>jo(e).filter(n=>Uo(n,t)).map(Ho),Or=(e,t,n=Ze)=>{const r=Tr();for(const i of e)if(qe(i))for(const s of i.points)kr(r,_n(s,t,n));return Lr(r)?r:void 0},Vo=(e,t,n=Ze)=>Or(e.layers.flatMap(r=>r.paths),t,n),Yo=(e,t,n=Ze)=>{const r=e.layers.find(i=>i.paths.some(s=>qe(s)));return r?Or(r.paths,t,n):void 0},Je=(e,t)=>e?Math.max(0,e[t].max-e[t].min):0,Qe=(e,t)=>e?e[t].min:0,et=(e,t)=>e?e[t].max:0,Xo=e=>{var m,g,C,E;const{graph:t,layer:n,layerHeight:r,layerOrdinal:i,profiles:s}=e,a=i?i-1:(n==null?void 0:n.index)??0,o=s.filament.bedTemp??((m=s.printer.defaults)==null?void 0:m.bedTemp)??0,d=s.filament.nozzleTemp??((g=s.printer.defaults)==null?void 0:g.nozzleTemp)??0,u=Vo(t,e.machineFrame,e.alignOffset),p=Yo(t,e.machineFrame,e.alignOffset);return{bed_temperature:o,bed_temperature_initial_layer:o,bed_temperature_initial_layer_single:o,first_layer_bed_temperature:o,first_layer_print_max_x:et(p,"x"),first_layer_print_max_y:et(p,"y"),first_layer_print_min_x:Qe(p,"x"),first_layer_print_min_y:Qe(p,"y"),first_layer_print_size_x:Je(p,"x"),first_layer_print_size_y:Je(p,"y"),first_layer_temperature:d,filament_diameter:s.filament.diameter,filament_type:s.filament.type??"UNKNOWN",layer_height:r??((E=(C=n==null?void 0:n.paths[0])==null?void 0:C.extrusion)==null?void 0:E.height)??s.printer.layerHeight,layer_num:a,layer_z:(n==null?void 0:n.z)??0,machine_name:s.printer.name??"unknown",max_layer_z:jr(t),nozzle_diameter:s.printer.nozzle,nozzle_temperature:d,nozzle_temperature_initial_layer:d,print_max_x:et(u,"x"),print_max_y:et(u,"y"),print_max_z:et(u,"z"),print_min_x:Qe(u,"x"),print_min_y:Qe(u,"y"),print_min_z:Qe(u,"z"),print_size_x:Je(u,"x"),print_size_y:Je(u,"y"),print_size_z:Je(u,"z"),printer_name:s.printer.name??"unknown",temperature:d,total_layer_count:t.layers.length}},Ko=(e,t)=>{const n=e.trim();if(n in t)return String(t[n]);const r=n.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*([+-])\s*(-?\d+(?:\.\d+)?)$/);if(r){const i=t[r[1]];if(typeof i=="number"){const s=Number(r[3]);return U(r[2]==="+"?i+s:i-s)}}},Zo=e=>{const t=e.trim();if(Wr.has(t))return!0;const n=t.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*([+-])\s*(-?\d+(?:\.\d+)?)$/);return!!(n&&Wr.has(n[1]))},qo=e=>{const t=e.trim();return/^(if|elsif|elif|else|endif)\b/i.test(t)?"conditional":Zo(t)?"supported":"unsupported"},Jo=(e,t)=>{const n=new Map;for(const[r,i]of Object.entries(e))for(const s of Mn(i,t))for(const a of s.matchAll(/\[([^\]]+)\]|\{([^{}]+)\}/g)){const o=a[1]??a[2]??"",d=qo(o);if(d==="conditional"){const u=`gcodeScripts.${r} uses unsupported conditional template "${o.trim()}".`;n.set(u,{level:"warning",message:u})}else if(d==="unsupported"){const u=`gcodeScripts.${r} uses unsupported template placeholder "${o.trim()}".`;n.set(u,{level:"warning",message:u})}}return[...n.values()]},Qo=(e,t)=>{const n=Xo(t);return e.replace(/\[([^\]]+)\]|\{([^{}]+)\}/g,(r,i,s)=>Ko(i??s??"",n)??r)},wt=(e,t)=>Mn(e,t.profiles.capabilities).map(n=>Qo(n,t)),Pn=(e,t)=>Mn(e,t).filter(n=>n.trim().length>0).length,ea=(e,t)=>{const n=[],{capabilities:r,filament:i,output:s}=e;return s.flavor!=="klipper"&&n.push("G21 ; millimeters"),n.push("G90 ; absolute coordinates"),n.push("M82 ; absolute extrusion"),r.heatedBed&&ee(i.bedTemp)&&n.push(`M140 S${U(i.bedTemp)} ; set bed temperature`),ee(i.nozzleTemp)&&n.push(`M104 S${U(i.nozzleTemp)} ; set nozzle temperature`),n.push("G28 ; home all axes"),r.heatedBed&&ee(i.bedTemp)&&n.push(`M190 S${U(i.bedTemp)} ; wait for bed temperature`),ee(i.nozzleTemp)&&n.push(`M109 S${U(i.nozzleTemp)} ; wait for nozzle temperature`),n.push("G92 E0 ; reset extrusion"),t.purgeLine&&(n.push("G0 X5 Y5 Z0.28 F7200 ; purge start"),n.push("G1 X5 Y80 E6 F900 ; purge line"),n.push("G92 E0 ; reset extrusion after purge"),n.push(`G0 Z${U(.28+.2)} F7200 ; lift after purge`)),n},ta=(e,t,n)=>{const r=t??{};return r.mode==="custom"?r.lines??[]:r.mode==="macro"?[Dr(r.startMacro??"START_PRINT",r.params)]:Pn(e.scripts.machineStart,e.capabilities)>0?wt(e.scripts.machineStart,n):ea(e,{...r})},na=e=>{const t=[];return e.capabilities.partCoolingFan!==!1&&t.push("M107 ; fan off"),t.push("M104 S0 ; hotend off"),e.capabilities.heatedBed&&t.push("M140 S0 ; bed off"),t.push("G91 ; relative positioning"),t.push("G0 Z10 F1200 ; lift"),t.push("G90 ; absolute positioning"),t.push("M2 ; end"),t},ra=(e,t,n)=>{const r=t??{};return r.mode==="custom"?r.lines??[]:r.mode==="macro"?[Dr(r.endMacro??"END_PRINT",r.params)]:Pn(e.scripts.machineEnd,e.capabilities)>0?wt(e.scripts.machineEnd,n):na(e)},ia=e=>{if(!e)return 1;const[t,n,r]=e.xAxis,[i,s,a]=e.yAxis,[o,d,u]=e.zAxis;return t*(s*u-a*d)-i*(n*u-r*d)+o*(n*a-r*s)},sa=(e,t,n)=>{var i;const r=[];Math.abs(ia(n))<1e-9&&r.push({level:"warning",message:"machineFrame basis is not invertible."}),e.layers.length===0&&r.push({level:"warning",message:"ToolpathGraph has no layers."}),e.layers.some(s=>s.paths.some(a=>qe(a)))||r.push({level:"warning",message:"ToolpathGraph has no extrusion paths."}),(!ee(t.filament.diameter)||t.filament.diameter<=0)&&r.push({level:"warning",message:"filament diameter must be positive."}),ee(t.filament.nozzleTemp)||r.push({level:"warning",message:"nozzle temperature is not set."}),t.capabilities.heatedBed&&!ee(t.filament.bedTemp)&&r.push({level:"warning",message:"bed temperature is not set for a heated-bed printer."});for(const s of e.layers)for(const a of s.paths){a.points.length<2&&r.push({level:"warning",message:`path ${a.id} has fewer than two points.`}),(!ee(a.speed)||a.speed<=0)&&r.push({level:"warning",message:`path ${a.id} has invalid speed.`});for(const o of a.points)if(!ee(o.x)||!ee(o.y)||!ee(o.z)){r.push({level:"warning",message:`path ${a.id} contains non-finite coordinates.`});break}}return t.output.metadata.objectLabels&&!((i=e.objects)!=null&&i.length)&&r.push({level:"warning",message:"objectLabels requested but ToolpathGraph has no object metadata."}),r.push(...Jo(t.scripts,t.capabilities)),[...new Map(r.map(s=>[`${s.level}:${s.message}`,s])).values()]},oa=(e,t,n)=>({command:r=>{r.trim()&&e.push(r)},comment:r=>{const i=Lo(r,t.output.style);i&&e.push(i)},fan:(r,i)=>{if(t.capabilities.partCoolingFan===!1)return;const s=Math.max(0,Math.min(255,r));n.currentFan!==Math.round(s)&&(n.currentFan=Math.round(s),e.push(s<=0?`M107${i?` ; ${i}`:""}`:`M106 S${mo(s)}${i?` ; ${i}`:""}`))},resetExtrusion:r=>{n.extrusion.e=0,e.push(`G92 E0${r?` ; ${r}`:""}`)},setAcceleration:(r,i)=>{!ee(r)||r<=0||n.currentAcceleration===r||(n.currentAcceleration=r,e.push(`M204 S${U(r)}${i?` ; ${i}`:""}`))}}),Cn=(e,t,n)=>({emit:e,graph:t,profiles:n}),aa=(e,t,n)=>{const r=n.print.cooling;if(!r.enabled||n.capabilities.partCoolingFan===!1)return;const i=r.offLayers??0,s=r.minLayer??i,a=r.minHeight??Number.NEGATIVE_INFINITY;if(e.index<i||e.index<s||e.z<a){t.fan(0,"part cooling off");return}const o=Math.min(r.fanSpeed??0,r.maxFanSpeed??255),d=r.rampLayers??0;if(d>0&&e.index<s+d){const u=e.index-s+1;t.fan(o*u/d,"part cooling ramp");return}t.fan(o,"part cooling")},Mt=(e,t,n,r)=>{const i=_n(e,n,r);return`G0 X${U(i.x)} Y${U(i.y)} Z${U(i.z)} F${U(t)}`},ca=(e,t,n,r,i,s,a,o)=>{var g,C;const d=_n(t,a,o),u=((g=n.extrusion)==null?void 0:g.width)??i.printer.nozzle*1.1,p=((C=n.extrusion)==null?void 0:C.height)??i.printer.layerHeight,m=Nr(e,t)*u*p*i.filament.flowRatio;return s.e+=m/Do(i.filament.diameter),`G1 X${U(d.x)} Y${U(d.y)} Z${U(d.z)} E${U(s.e)} F${U(r)}`},In=(e,t,n,r)=>{const i=t.print.retraction;!i.enabled||!i.length||n.extrusion.retracted===r||(n.extrusion.e+=r?-i.length:i.length,n.extrusion.retracted=r,e.push(`G1 E${U(n.extrusion.e)} F${U(i.speed??2100)} ; ${r?"retract":"unretract"}`))},la=(e,t,n,r,i,s,a)=>{const o=e.points[0];if(!o)return;const d=i.currentPosition?Nr(i.currentPosition,o):0,u=qe(e);d>1e-6&&u&&In(n,r,i,!0);const p=r.print.retraction.enabled?r.print.retraction.zHop??0:0;i.currentPosition&&p>0&&d>1e-6&&u&&n.push(Mt({...i.currentPosition,z:i.currentPosition.z+p},r.print.speed.travel??t,s,a)),n.push(Mt(o,e.role==="travel"?t:r.print.speed.travel??t,s,a)),p>0&&d>1e-6&&u&&n.push(Mt(o,r.print.speed.travel??t,s,a)),u&&In(n,r,i,!1),i.currentPosition=o},da=(e,t,n,r,i,s,a)=>{if(e.points.length===0)return;la(e,t,n,r,i,s,a);const o=e.closed?[...e.points.slice(1),e.points[0]]:e.points.slice(1);for(const d of o){const u=i.currentPosition??e.points[0];qe(e)?n.push(ca(u,d,e,t,r,i.extrusion,s,a)):n.push(Mt(d,t,s,a)),i.currentPosition=d}},Br=e=>e.output.metadata.objectLabels?e.output.flavor==="klipper"&&e.capabilities.supportsExcludeObject!==!1?"klipper":e.capabilities.supportsM486?"m486":e.output.style==="orca"||e.output.style==="bambu"||e.output.style==="prusa"?"comment":"none":"none",ua=(e,t)=>{var r;return Br(t)!=="klipper"||!((r=e.objects)!=null&&r.length)?[]:e.objects.map(i=>{var o;const s=i.center?`${U(i.center[0])},${U(i.center[1])}`:"0,0",a=(o=i.polygon)!=null&&o.length?` POLYGON=[${i.polygon.map(d=>`[${U(d[0])},${U(d[1])}]`).join(",")}]`:"";return`EXCLUDE_OBJECT_DEFINE NAME=${i.id} CENTER=${s}${a}`})},fa=(e,t)=>{var n;return Math.max(0,((n=e.objects)==null?void 0:n.findIndex(r=>r.id===t))??0)},Gr=(e,t,n,r,i,s,a,o)=>{var m,g,C,E;if(!r.output.metadata.objectLabels||i.currentObjectId===t)return;const d=Br(r),u=i.currentObjectId?(m=n.objects)==null?void 0:m.find(_=>_.id===i.currentObjectId):void 0;if(i.currentObjectId&&((g=o==null?void 0:o.onObjectEnd)==null||g.call(o,{...Cn(s,n,r),layer:a,object:u,objectId:i.currentObjectId}),d==="klipper"?e.push(`EXCLUDE_OBJECT_END NAME=${i.currentObjectId}`):d==="m486"?e.push("M486 S-1"):d==="comment"&&e.push(`;OBJECT_END:${i.currentObjectId}`)),i.currentObjectId=t,!t)return;const p=(C=n.objects)==null?void 0:C.find(_=>_.id===t);d==="klipper"?e.push(`EXCLUDE_OBJECT_START NAME=${t}`):d==="m486"?e.push(`M486 S${fa(n,t)}`):d==="comment"&&e.push(`;OBJECT:${(p==null?void 0:p.name)??t}`),(E=o==null?void 0:o.onObjectStart)==null||E.call(o,{...Cn(s,n,r),layer:a,object:p,objectId:t})},jr=e=>e.layers.reduce((t,n)=>Math.max(t,n.z),0),ha=(e,t)=>{if(t.output.style==="plain")return[];if(t.output.style==="bambu"){const r=["; HEADER_BLOCK_START","; IgniteFuse",`; total layer number: ${e.layers.length}`,`; filament_diameter: ${U(t.filament.diameter)}`,`; nozzle_diameter: ${U(t.printer.nozzle)}`,`; max_z_height: ${U(jr(e))}`];return t.output.metadata.printStats&&r.push(`; path_count: ${e.stats.pathCount}`),r.push("; HEADER_BLOCK_END"),r.push("; EXECUTABLE_BLOCK_START"),r}const n=["; generated by IgniteFuse",`; printer: ${t.printer.name??"unknown"}`,`; flavor: ${t.output.flavor}`,`; filament_diameter: ${U(t.filament.diameter)}`,`; nozzle_diameter: ${U(t.printer.nozzle)}`];return t.output.metadata.printStats&&(n.push(`; layer_count: ${e.layers.length}`),n.push(`; path_count: ${e.stats.pathCount}`)),n},Hr=e=>e==="orca"||e==="bambu"?"; FEATURE: Custom":e==="prusa"?";TYPE:Custom":e==="ignitefuse"?"; custom gcode":"",pa=(e,t)=>e.output.style!=="bambu"||(t==null?void 0:t.mode)==="custom"?[]:["; MACHINE_START_GCODE_END"],ma=e=>e.output.style==="bambu"?["; EXECUTABLE_BLOCK_END"]:[],ga=(e,t={})=>{var C,E,_,v,z,M,P,A,R,G,D,k,B,Y,j,X,re,ce,he,le;const n=To(e,t),r=go(n.printer,t.machineFrame),i=So(e,r,t.align),s=(t.pathOrder??(n.printer.process?"contact":"graph"))==="contact"?$o(n.printer):void 0,a={extrusion:{e:0,retracted:!1}},o=[],d=oa(o,n,a),u=Cn(d,e,n),p={alignOffset:i,graph:e,machineFrame:r,profiles:n};(E=(C=t.hooks)==null?void 0:C.onJobStart)==null||E.call(C,u),o.push(...ha(e,n));const m=sa(e,n,r);for(const Q of m)(_=t.onDiagnostic)==null||_.call(t,Q),t.diagnosticComments&&o.push(`; ${Q.level.toUpperCase()}: ${Q.message}`);o.push(...ua(e,n)),o.push(Hr(n.output.style)),o.push(...ta(n,t.start,p)),o.push(...pa(n,t.start)),yo(i)&&o.push(`; IgniteFuse: alignOffset X${U(i.x)} Y${U(i.y)} Z${U(i.z)}`),(z=(v=t.hooks)==null?void 0:v.onAfterStart)==null||z.call(v,u);for(let Q=0;Q<e.layers.length;Q+=1){const J=e.layers[Q],te=e.layers[Q-1],_e=te?Math.abs(J.z-te.z):((P=(M=J.paths[0])==null?void 0:M.extrusion)==null?void 0:P.height)??J.z,we={alignOffset:i,graph:e,layer:J,layerHeight:_e,layerOrdinal:Q+1,machineFrame:r,profiles:n};o.push(...wt(n.scripts.beforeLayerChange,we)),o.push(...No(J,n,Q+1,e.layers.length,te)),o.push(...wt(n.scripts.layerChange,we)),aa(J,d,n),(R=(A=t.hooks)==null?void 0:A.onLayerStart)==null||R.call(A,{...u,layer:J});let $;for(const x of Co(J.paths,s)){if(Gr(o,x.objectId,e,n,a,d,J,t.hooks),$!==x.role){const W=Ro(x.role,n.output.style);W&&o.push(W),$=x.role}const y=Oo(J,x,n,s),L=Bo(J,x,n);L&&d.setAcceleration(L,`${Rr[x.role]} acceleration`),(D=(G=t.hooks)==null?void 0:G.onPathStart)==null||D.call(G,{...u,layer:J,path:x}),da(x,y,o,n,a,r,i),(B=(k=t.hooks)==null?void 0:k.onPathEnd)==null||B.call(k,{...u,layer:J,path:x})}(j=(Y=t.hooks)==null?void 0:Y.onLayerEnd)==null||j.call(Y,{...u,layer:J})}Gr(o,void 0,e,n,a,d,e.layers[e.layers.length-1],t.hooks),In(o,n,a,!1),(re=(X=t.hooks)==null?void 0:X.onBeforeEnd)==null||re.call(X,u);const g=t.end??(((ce=t.start)==null?void 0:ce.mode)==="macro"&&t.start.endMacro?{endMacro:t.start.endMacro,mode:"macro",params:t.start.params}:void 0);return o.push(Hr(n.output.style)),o.push(...ra(n,g,p)),o.push(...ma(n)),(le=(he=t.hooks)==null?void 0:he.onJobEnd)==null||le.call(he,u),`${o.filter(Q=>Q.length>0).join(`
|
|
7
|
+
`)}
|
|
8
|
+
`};function ya(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Sn={exports:{}},Ur;function ba(){return Ur||(Ur=1,(function(e,t){var n=(()=>{var i;var r=typeof document<"u"?(i=document.currentScript)==null?void 0:i.src:void 0;return(function(s={}){var a,o=s,d,u,p=new Promise((l,c)=>{d=l,u=c}),m=Object.assign({},o),g="";function C(l){return o.locateFile?o.locateFile(l,g):g+l}var E;typeof document<"u"&&document.currentScript&&(g=document.currentScript.src),r&&(g=r),g.startsWith("blob:")?g="":g=g.substr(0,g.replace(/[?#].*/,"").lastIndexOf("/")+1),E=l=>fetch(l,{credentials:"same-origin"}).then(c=>c.ok?c.arrayBuffer():Promise.reject(new Error(c.status+" : "+c.url))),o.print||console.log.bind(console);var _=o.printErr||console.error.bind(console);Object.assign(o,m),m=null,o.arguments&&o.arguments,o.thisProgram&&o.thisProgram;var v=o.wasmBinary,z,M=!1,P,A,R,G,D,k,B,Y,j,X;function re(){var l=z.buffer;o.HEAP8=P=new Int8Array(l),o.HEAP16=R=new Int16Array(l),o.HEAPU8=A=new Uint8Array(l),o.HEAPU16=G=new Uint16Array(l),o.HEAP32=D=new Int32Array(l),o.HEAPU32=k=new Uint32Array(l),o.HEAPF32=B=new Float32Array(l),o.HEAPF64=X=new Float64Array(l),o.HEAP64=Y=new BigInt64Array(l),o.HEAPU64=j=new BigUint64Array(l)}var ce=[],he=[],le=[];function Q(){if(o.preRun)for(typeof o.preRun=="function"&&(o.preRun=[o.preRun]);o.preRun.length;)_e(o.preRun.shift());dr(ce)}function J(){dr(he)}function te(){if(o.postRun)for(typeof o.postRun=="function"&&(o.postRun=[o.postRun]);o.postRun.length;)$(o.postRun.shift());dr(le)}function _e(l){ce.unshift(l)}function we(l){he.unshift(l)}function $(l){le.unshift(l)}var x=0,y=null;function L(l){var c;x++,(c=o.monitorRunDependencies)==null||c.call(o,x)}function W(l){var f;if(x--,(f=o.monitorRunDependencies)==null||f.call(o,x),x==0&&y){var c=y;y=null,c()}}function V(l){var f;(f=o.onAbort)==null||f.call(o,l),l="Aborted("+l+")",_(l),M=!0,l+=". Build with -sASSERTIONS for more info.";var c=new WebAssembly.RuntimeError(l);throw u(c),c}var K="data:application/octet-stream;base64,",me=l=>l.startsWith(K);function Ue(){var l="clipper2z.wasm";return me(l)?l:C(l)}var lr;function cs(l){if(l==lr&&v)return new Uint8Array(v);throw"both async and sync fetching of the wasm failed"}function uu(l){return v?Promise.resolve().then(()=>cs(l)):E(l).then(c=>new Uint8Array(c),()=>cs(l))}function ls(l,c,f){return uu(l).then(h=>WebAssembly.instantiate(h,c)).then(f,h=>{_(`failed to asynchronously prepare wasm: ${h}`),V(h)})}function fu(l,c,f,h){return!l&&typeof WebAssembly.instantiateStreaming=="function"&&!me(c)&&typeof fetch=="function"?fetch(c,{credentials:"same-origin"}).then(b=>{var I=WebAssembly.instantiateStreaming(b,f);return I.then(h,function(S){return _(`wasm streaming compile failed: ${S}`),_("falling back to ArrayBuffer instantiation"),ls(c,f,h)})}):ls(c,f,h)}function hu(){return{a:Mf}}function pu(){function l(h,b){return ze=h.exports,z=ze.t,re(),xs=ze.w,we(ze.u),W(),ze}L();function c(h){l(h.instance)}var f=hu();if(o.instantiateWasm)try{return o.instantiateWasm(f,l)}catch(h){_(`Module.instantiateWasm callback failed with error: ${h}`),u(h)}return lr??(lr=Ue()),fu(v,lr,f,c).catch(u),{}}var dr=l=>{for(;l.length>0;)l.shift()(o)};o.noExitRuntime;class mu{constructor(c){this.excPtr=c,this.ptr=c-24}set_type(c){k[this.ptr+4>>2]=c}get_type(){return k[this.ptr+4>>2]}set_destructor(c){k[this.ptr+8>>2]=c}get_destructor(){return k[this.ptr+8>>2]}set_caught(c){c=c?1:0,P[this.ptr+12]=c}get_caught(){return P[this.ptr+12]!=0}set_rethrown(c){c=c?1:0,P[this.ptr+13]=c}get_rethrown(){return P[this.ptr+13]!=0}init(c,f){this.set_adjusted_ptr(0),this.set_type(c),this.set_destructor(f)}set_adjusted_ptr(c){k[this.ptr+16>>2]=c}get_adjusted_ptr(){return k[this.ptr+16>>2]}}var ds=0,gu=(l,c,f)=>{var h=new mu(l);throw h.init(c,f),ds=l,ds},yu=()=>V(""),on=l=>{if(l===null)return"null";var c=typeof l;return c==="object"||c==="array"||c==="function"?l.toString():""+l},bu=()=>{for(var l=new Array(256),c=0;c<256;++c)l[c]=String.fromCharCode(c);us=l},us,ie=l=>{for(var c="",f=l;A[f];)c+=us[A[f++]];return c},Ve={},Re={},an={},Ye,H=l=>{throw new Ye(l)},fs,cn=l=>{throw new fs(l)},Ee=(l,c,f)=>{l.forEach(w=>an[w]=c);function h(w){var F=f(w);F.length!==l.length&&cn("Mismatched type converter count");for(var T=0;T<l.length;++T)ge(l[T],F[T])}var b=new Array(c.length),I=[],S=0;c.forEach((w,F)=>{Re.hasOwnProperty(w)?b[F]=Re[w]:(I.push(w),Ve.hasOwnProperty(w)||(Ve[w]=[]),Ve[w].push(()=>{b[F]=Re[w],++S,S===I.length&&h(b)}))}),I.length===0&&h(b)};function vu(l,c,f={}){var h=c.name;if(l||H(`type "${h}" must have a positive integer typeid pointer`),Re.hasOwnProperty(l)){if(f.ignoreDuplicateRegistrations)return;H(`Cannot register type '${h}' twice`)}if(Re[l]=c,delete an[l],Ve.hasOwnProperty(l)){var b=Ve[l];delete Ve[l],b.forEach(I=>I())}}function ge(l,c,f={}){return vu(l,c,f)}var hs=(l,c,f)=>{switch(c){case 1:return f?h=>P[h]:h=>A[h];case 2:return f?h=>R[h>>1]:h=>G[h>>1];case 4:return f?h=>D[h>>2]:h=>k[h>>2];case 8:return f?h=>Y[h>>3]:h=>j[h>>3];default:throw new TypeError(`invalid integer width (${c}): ${l}`)}},xu=(l,c,f,h,b)=>{c=ie(c);var I=c.indexOf("u")!=-1;ge(l,{name:c,fromWireType:S=>S,toWireType:function(S,w){if(typeof w!="bigint"&&typeof w!="number")throw new TypeError(`Cannot convert "${on(w)}" to ${this.name}`);return typeof w=="number"&&(w=BigInt(w)),w},argPackAdvance:be,readValueFromPointer:hs(c,f,!I),destructorFunction:null})},be=8,$u=(l,c,f,h)=>{c=ie(c),ge(l,{name:c,fromWireType:function(b){return!!b},toWireType:function(b,I){return I?f:h},argPackAdvance:be,readValueFromPointer:function(b){return this.fromWireType(A[b])},destructorFunction:null})},_u=l=>({count:l.count,deleteScheduled:l.deleteScheduled,preservePointerOnDelete:l.preservePointerOnDelete,ptr:l.ptr,ptrType:l.ptrType,smartPtr:l.smartPtr,smartPtrType:l.smartPtrType}),ur=l=>{function c(f){return f.$$.ptrType.registeredClass.name}H(c(l)+" instance already deleted")},fr=!1,ps=l=>{},wu=l=>{l.smartPtr?l.smartPtrType.rawDestructor(l.smartPtr):l.ptrType.registeredClass.rawDestructor(l.ptr)},ms=l=>{l.count.value-=1;var c=l.count.value===0;c&&wu(l)},gs=(l,c,f)=>{if(c===f)return l;if(f.baseClass===void 0)return null;var h=gs(l,c,f.baseClass);return h===null?null:f.downcast(h)},ys={},Mu={},Pu=(l,c)=>{for(c===void 0&&H("ptr should not be undefined");l.baseClass;)c=l.upcast(c),l=l.baseClass;return c},Cu=(l,c)=>(c=Pu(l,c),Mu[c]),ln=(l,c)=>{(!c.ptrType||!c.ptr)&&cn("makeClassHandle requires ptr and ptrType");var f=!!c.smartPtrType,h=!!c.smartPtr;return f!==h&&cn("Both smartPtrType and smartPtr must be specified"),c.count={value:1},mt(Object.create(l,{$$:{value:c,writable:!0}}))};function Iu(l){var c=this.getPointee(l);if(!c)return this.destructor(l),null;var f=Cu(this.registeredClass,c);if(f!==void 0){if(f.$$.count.value===0)return f.$$.ptr=c,f.$$.smartPtr=l,f.clone();var h=f.clone();return this.destructor(l),h}function b(){return this.isSmartPointer?ln(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:c,smartPtrType:this,smartPtr:l}):ln(this.registeredClass.instancePrototype,{ptrType:this,ptr:l})}var I=this.registeredClass.getActualType(c),S=ys[I];if(!S)return b.call(this);var w;this.isConst?w=S.constPointerType:w=S.pointerType;var F=gs(c,this.registeredClass,w.registeredClass);return F===null?b.call(this):this.isSmartPointer?ln(w.registeredClass.instancePrototype,{ptrType:w,ptr:F,smartPtrType:this,smartPtr:l}):ln(w.registeredClass.instancePrototype,{ptrType:w,ptr:F})}var mt=l=>typeof FinalizationRegistry>"u"?(mt=c=>c,l):(fr=new FinalizationRegistry(c=>{ms(c.$$)}),mt=c=>{var f=c.$$,h=!!f.smartPtr;if(h){var b={$$:f};fr.register(c,b,c)}return c},ps=c=>fr.unregister(c),mt(l)),Su=()=>{Object.assign(dn.prototype,{isAliasOf(l){if(!(this instanceof dn)||!(l instanceof dn))return!1;var c=this.$$.ptrType.registeredClass,f=this.$$.ptr;l.$$=l.$$;for(var h=l.$$.ptrType.registeredClass,b=l.$$.ptr;c.baseClass;)f=c.upcast(f),c=c.baseClass;for(;h.baseClass;)b=h.upcast(b),h=h.baseClass;return c===h&&f===b},clone(){if(this.$$.ptr||ur(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var l=mt(Object.create(Object.getPrototypeOf(this),{$$:{value:_u(this.$$)}}));return l.$$.count.value+=1,l.$$.deleteScheduled=!1,l},delete(){this.$$.ptr||ur(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&H("Object already scheduled for deletion"),ps(this),ms(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)},isDeleted(){return!this.$$.ptr},deleteLater(){return this.$$.ptr||ur(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&H("Object already scheduled for deletion"),this.$$.deleteScheduled=!0,this}})};function dn(){}var gt=(l,c)=>Object.defineProperty(c,"name",{value:l}),bs=(l,c,f)=>{if(l[c].overloadTable===void 0){var h=l[c];l[c]=function(...b){return l[c].overloadTable.hasOwnProperty(b.length)||H(`Function '${f}' called with an invalid number of arguments (${b.length}) - expects one of (${l[c].overloadTable})!`),l[c].overloadTable[b.length].apply(this,b)},l[c].overloadTable=[],l[c].overloadTable[h.argCount]=h}},hr=(l,c,f)=>{o.hasOwnProperty(l)?((f===void 0||o[l].overloadTable!==void 0&&o[l].overloadTable[f]!==void 0)&&H(`Cannot register public name '${l}' twice`),bs(o,l,l),o[l].overloadTable.hasOwnProperty(f)&&H(`Cannot register multiple overloads of a function with the same number of arguments (${f})!`),o[l].overloadTable[f]=c):(o[l]=c,o[l].argCount=f)},Eu=48,Au=57,zu=l=>{l=l.replace(/[^a-zA-Z0-9_]/g,"$");var c=l.charCodeAt(0);return c>=Eu&&c<=Au?`_${l}`:l};function Fu(l,c,f,h,b,I,S,w){this.name=l,this.constructor=c,this.instancePrototype=f,this.rawDestructor=h,this.baseClass=b,this.getActualType=I,this.upcast=S,this.downcast=w,this.pureVirtualFunctions=[]}var un=(l,c,f)=>{for(;c!==f;)c.upcast||H(`Expected null or instance of ${f.name}, got an instance of ${c.name}`),l=c.upcast(l),c=c.baseClass;return l};function Tu(l,c){if(c===null)return this.isReference&&H(`null is not a valid ${this.name}`),0;c.$$||H(`Cannot pass "${on(c)}" as a ${this.name}`),c.$$.ptr||H(`Cannot pass deleted object as a pointer of type ${this.name}`);var f=c.$$.ptrType.registeredClass,h=un(c.$$.ptr,f,this.registeredClass);return h}function ku(l,c){var f;if(c===null)return this.isReference&&H(`null is not a valid ${this.name}`),this.isSmartPointer?(f=this.rawConstructor(),l!==null&&l.push(this.rawDestructor,f),f):0;(!c||!c.$$)&&H(`Cannot pass "${on(c)}" as a ${this.name}`),c.$$.ptr||H(`Cannot pass deleted object as a pointer of type ${this.name}`),!this.isConst&&c.$$.ptrType.isConst&&H(`Cannot convert argument of type ${c.$$.smartPtrType?c.$$.smartPtrType.name:c.$$.ptrType.name} to parameter type ${this.name}`);var h=c.$$.ptrType.registeredClass;if(f=un(c.$$.ptr,h,this.registeredClass),this.isSmartPointer)switch(c.$$.smartPtr===void 0&&H("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:c.$$.smartPtrType===this?f=c.$$.smartPtr:H(`Cannot convert argument of type ${c.$$.smartPtrType?c.$$.smartPtrType.name:c.$$.ptrType.name} to parameter type ${this.name}`);break;case 1:f=c.$$.smartPtr;break;case 2:if(c.$$.smartPtrType===this)f=c.$$.smartPtr;else{var b=c.clone();f=this.rawShare(f,yr.toHandle(()=>b.delete())),l!==null&&l.push(this.rawDestructor,f)}break;default:H("Unsupporting sharing policy")}return f}function Lu(l,c){if(c===null)return this.isReference&&H(`null is not a valid ${this.name}`),0;c.$$||H(`Cannot pass "${on(c)}" as a ${this.name}`),c.$$.ptr||H(`Cannot pass deleted object as a pointer of type ${this.name}`),c.$$.ptrType.isConst&&H(`Cannot convert argument of type ${c.$$.ptrType.name} to parameter type ${this.name}`);var f=c.$$.ptrType.registeredClass,h=un(c.$$.ptr,f,this.registeredClass);return h}function fn(l){return this.fromWireType(k[l>>2])}var Ru=()=>{Object.assign(hn.prototype,{getPointee(l){return this.rawGetPointee&&(l=this.rawGetPointee(l)),l},destructor(l){var c;(c=this.rawDestructor)==null||c.call(this,l)},argPackAdvance:be,readValueFromPointer:fn,fromWireType:Iu})};function hn(l,c,f,h,b,I,S,w,F,T,N){this.name=l,this.registeredClass=c,this.isReference=f,this.isConst=h,this.isSmartPointer=b,this.pointeeType=I,this.sharingPolicy=S,this.rawGetPointee=w,this.rawConstructor=F,this.rawShare=T,this.rawDestructor=N,!b&&c.baseClass===void 0?h?(this.toWireType=Tu,this.destructorFunction=null):(this.toWireType=Lu,this.destructorFunction=null):this.toWireType=ku}var vs=(l,c,f)=>{o.hasOwnProperty(l)||cn("Replacing nonexistent public symbol"),o[l].overloadTable!==void 0&&f!==void 0?o[l].overloadTable[f]=c:(o[l]=c,o[l].argCount=f)},pn=[],xs,Nu=l=>{var c=pn[l];return c||(l>=pn.length&&(pn.length=l+1),pn[l]=c=xs.get(l)),c},Me=(l,c)=>{l=ie(l);function f(){return Nu(c)}var h=f();return typeof h!="function"&&H(`unknown function pointer with signature ${l}: ${c}`),h},Du=(l,c)=>{var f=gt(c,function(h){this.name=c,this.message=h;var b=new Error(h).stack;b!==void 0&&(this.stack=this.toString()+`
|
|
9
|
+
`+b.replace(/^Error(:[^\n]*)?\n/,""))});return f.prototype=Object.create(l.prototype),f.prototype.constructor=f,f.prototype.toString=function(){return this.message===void 0?this.name:`${this.name}: ${this.message}`},f},$s,_s=l=>{var c=Es(l),f=ie(c);return Pe(c),f},Xe=(l,c)=>{var f=[],h={};function b(I){if(!h[I]&&!Re[I]){if(an[I]){an[I].forEach(b);return}f.push(I),h[I]=!0}}throw c.forEach(b),new $s(`${l}: `+f.map(_s).join([", "]))},Wu=(l,c,f,h,b,I,S,w,F,T,N,O,Z)=>{N=ie(N),I=Me(b,I),w&&(w=Me(S,w)),T&&(T=Me(F,T)),Z=Me(O,Z);var se=zu(N);hr(se,function(){Xe(`Cannot construct ${N} due to unbound types`,[h])}),Ee([l,c,f],h?[h]:[],ne=>{var Ls;ne=ne[0];var ye,Ne;h?(ye=ne.registeredClass,Ne=ye.instancePrototype):Ne=dn.prototype;var pe=gt(N,function(...vr){if(Object.getPrototypeOf(this)!==yt)throw new Ye("Use 'new' to construct "+N);if(de.constructor_body===void 0)throw new Ye(N+" has no accessible constructor");var Rs=de.constructor_body[vr.length];if(Rs===void 0)throw new Ye(`Tried to invoke ctor of ${N} with invalid number of parameters (${vr.length}) - expected (${Object.keys(de.constructor_body).toString()}) parameters instead!`);return Rs.apply(this,vr)}),yt=Object.create(Ne,{constructor:{value:pe}});pe.prototype=yt;var de=new Fu(N,pe,yt,Z,ye,I,w,T);de.baseClass&&((Ls=de.baseClass).__derivedClasses??(Ls.__derivedClasses=[]),de.baseClass.__derivedClasses.push(de));var zf=new hn(N,de,!0,!1,!1),Ts=new hn(N+"*",de,!1,!1,!1),ks=new hn(N+" const*",de,!1,!0,!1);return ys[l]={pointerType:Ts,constPointerType:ks},vs(se,pe),[zf,Ts,ks]})},pr=(l,c)=>{for(var f=[],h=0;h<l;h++)f.push(k[c+h*4>>2]);return f},ws=l=>{for(;l.length;){var c=l.pop(),f=l.pop();f(c)}};function Ms(l){for(var c=1;c<l.length;++c)if(l[c]!==null&&l[c].destructorFunction===void 0)return!0;return!1}function Ou(l,c){if(!(l instanceof Function))throw new TypeError(`new_ called with constructor type ${typeof l} which is not a function`);var f=gt(l.name||"unknownFunctionName",function(){});f.prototype=l.prototype;var h=new f,b=l.apply(h,c);return b instanceof Object?b:h}function Bu(l,c,f,h){var b=Ms(l),I=l.length-2,S=[],w=["fn"];c&&w.push("thisWired");for(var F=0;F<I;++F)S.push(`arg${F}`),w.push(`arg${F}Wired`);S=S.join(","),w=w.join(",");var T=`return function (${S}) {
|
|
10
|
+
`;b&&(T+=`var destructors = [];
|
|
11
|
+
`);var N=b?"destructors":"null",O=["humanName","throwBindingError","invoker","fn","runDestructors","retType","classParam"];c&&(T+=`var thisWired = classParam['toWireType'](${N}, this);
|
|
12
|
+
`);for(var F=0;F<I;++F)T+=`var arg${F}Wired = argType${F}['toWireType'](${N}, arg${F});
|
|
13
|
+
`,O.push(`argType${F}`);if(T+=(f||h?"var rv = ":"")+`invoker(${w});
|
|
14
|
+
`,b)T+=`runDestructors(destructors);
|
|
15
|
+
`;else for(var F=c?1:2;F<l.length;++F){var Z=F===1?"thisWired":"arg"+(F-2)+"Wired";l[F].destructorFunction!==null&&(T+=`${Z}_dtor(${Z});
|
|
16
|
+
`,O.push(`${Z}_dtor`))}return f&&(T+=`var ret = retType['fromWireType'](rv);
|
|
17
|
+
return ret;
|
|
18
|
+
`),T+=`}
|
|
19
|
+
`,[O,T]}function mr(l,c,f,h,b,I){var S=c.length;S<2&&H("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var w=c[1]!==null&&f!==null,F=Ms(c),T=c[0].name!=="void",N=[l,H,h,b,ws,c[0],c[1]],O=0;O<S-2;++O)N.push(c[O+2]);if(!F)for(var O=w?1:2;O<c.length;++O)c[O].destructorFunction!==null&&N.push(c[O].destructorFunction);let[Z,se]=Bu(c,w,T,I);Z.push(se);var ne=Ou(Function,Z)(...N);return gt(l,ne)}var Gu=(l,c,f,h,b,I)=>{var S=pr(c,f);b=Me(h,b),Ee([],[l],w=>{w=w[0];var F=`constructor ${w.name}`;if(w.registeredClass.constructor_body===void 0&&(w.registeredClass.constructor_body=[]),w.registeredClass.constructor_body[c-1]!==void 0)throw new Ye(`Cannot register multiple constructors with identical number of parameters (${c-1}) for class '${w.name}'! Overload resolution is currently only performed using the parameter count, not actual type info!`);return w.registeredClass.constructor_body[c-1]=()=>{Xe(`Cannot construct ${w.name} due to unbound types`,S)},Ee([],S,T=>(T.splice(1,0,null),w.registeredClass.constructor_body[c-1]=mr(F,T,null,b,I),[])),[]})},Ps=l=>{l=l.trim();const c=l.indexOf("(");return c!==-1?l.substr(0,c):l},ju=(l,c,f,h,b,I,S,w,F,T)=>{var N=pr(f,h);c=ie(c),c=Ps(c),I=Me(b,I),Ee([],[l],O=>{O=O[0];var Z=`${O.name}.${c}`;c.startsWith("@@")&&(c=Symbol[c.substring(2)]),w&&O.registeredClass.pureVirtualFunctions.push(c);function se(){Xe(`Cannot call ${Z} due to unbound types`,N)}var ne=O.registeredClass.instancePrototype,ye=ne[c];return ye===void 0||ye.overloadTable===void 0&&ye.className!==O.name&&ye.argCount===f-2?(se.argCount=f-2,se.className=O.name,ne[c]=se):(bs(ne,c,Z),ne[c].overloadTable[f-2]=se),Ee([],N,Ne=>{var pe=mr(Z,Ne,O,I,S,F);return ne[c].overloadTable===void 0?(pe.argCount=f-2,ne[c]=pe):ne[c].overloadTable[f-2]=pe,[]}),[]})},Cs=(l,c,f)=>(l instanceof Object||H(`${f} with invalid "this": ${l}`),l instanceof c.registeredClass.constructor||H(`${f} incompatible with "this" of type ${l.constructor.name}`),l.$$.ptr||H(`cannot call emscripten binding method ${f} on deleted object`),un(l.$$.ptr,l.$$.ptrType.registeredClass,c.registeredClass)),Hu=(l,c,f,h,b,I,S,w,F,T)=>{c=ie(c),b=Me(h,b),Ee([],[l],N=>{N=N[0];var O=`${N.name}.${c}`,Z={get(){Xe(`Cannot access ${O} due to unbound types`,[f,S])},enumerable:!0,configurable:!0};return F?Z.set=()=>Xe(`Cannot access ${O} due to unbound types`,[f,S]):Z.set=se=>H(O+" is a read-only property"),Object.defineProperty(N.registeredClass.instancePrototype,c,Z),Ee([],F?[f,S]:[f],se=>{var ne=se[0],ye={get(){var pe=Cs(this,N,O+" getter");return ne.fromWireType(b(I,pe))},enumerable:!0};if(F){F=Me(w,F);var Ne=se[1];ye.set=function(pe){var yt=Cs(this,N,O+" setter"),de=[];F(T,yt,Ne.toWireType(de,pe)),ws(de)}}return Object.defineProperty(N.registeredClass.instancePrototype,c,ye),[]}),[]})},gr=[],Ae=[],Uu=l=>{l>9&&--Ae[l+1]===0&&(Ae[l]=void 0,gr.push(l))},Vu=()=>Ae.length/2-5-gr.length,Yu=()=>{Ae.push(0,1,void 0,1,null,1,!0,1,!1,1),o.count_emval_handles=Vu},yr={toValue:l=>(l||H("Cannot use deleted val. handle = "+l),Ae[l]),toHandle:l=>{switch(l){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:{const c=gr.pop()||Ae.length;return Ae[c]=l,Ae[c+1]=1,c}}}},Xu={name:"emscripten::val",fromWireType:l=>{var c=yr.toValue(l);return Uu(l),c},toWireType:(l,c)=>yr.toHandle(c),argPackAdvance:be,readValueFromPointer:fn,destructorFunction:null},Ku=l=>ge(l,Xu),Zu=(l,c,f)=>{switch(c){case 1:return f?function(h){return this.fromWireType(P[h])}:function(h){return this.fromWireType(A[h])};case 2:return f?function(h){return this.fromWireType(R[h>>1])}:function(h){return this.fromWireType(G[h>>1])};case 4:return f?function(h){return this.fromWireType(D[h>>2])}:function(h){return this.fromWireType(k[h>>2])};default:throw new TypeError(`invalid integer width (${c}): ${l}`)}},qu=(l,c,f,h)=>{c=ie(c);function b(){}b.values={},ge(l,{name:c,constructor:b,fromWireType:function(I){return this.constructor.values[I]},toWireType:(I,S)=>S.value,argPackAdvance:be,readValueFromPointer:Zu(c,f,h),destructorFunction:null}),hr(c,b)},Ju=(l,c)=>{var f=Re[l];return f===void 0&&H(`${c} has unknown type ${_s(l)}`),f},Qu=(l,c,f)=>{var h=Ju(l,"enum");c=ie(c);var b=h.constructor,I=Object.create(h.constructor.prototype,{value:{value:f},constructor:{value:gt(`${h.name}_${c}`,function(){})}});b.values[f]=I,b[c]=I},ef=(l,c)=>{switch(c){case 4:return function(f){return this.fromWireType(B[f>>2])};case 8:return function(f){return this.fromWireType(X[f>>3])};default:throw new TypeError(`invalid float width (${c}): ${l}`)}},tf=(l,c,f)=>{c=ie(c),ge(l,{name:c,fromWireType:h=>h,toWireType:(h,b)=>b,argPackAdvance:be,readValueFromPointer:ef(c,f),destructorFunction:null})},nf=(l,c,f,h,b,I,S,w)=>{var F=pr(c,f);l=ie(l),l=Ps(l),b=Me(h,b),hr(l,function(){Xe(`Cannot call ${l} due to unbound types`,F)},c-1),Ee([],F,T=>{var N=[T[0],null].concat(T.slice(1));return vs(l,mr(l,N,null,b,I,S),c-1),[]})},rf=(l,c,f,h,b)=>{c=ie(c);var I=N=>N;if(h===0){var S=32-8*f;I=N=>N<<S>>>S}var w=c.includes("unsigned"),F=(N,O)=>{},T;w?T=function(N,O){return F(O,this.name),O>>>0}:T=function(N,O){return F(O,this.name),O},ge(l,{name:c,fromWireType:I,toWireType:T,argPackAdvance:be,readValueFromPointer:hs(c,f,h!==0),destructorFunction:null})},sf=(l,c,f)=>{var h=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array],b=h[c];function I(S){var w=k[S>>2],F=k[S+4>>2];return new b(P.buffer,F,w)}f=ie(f),ge(l,{name:f,fromWireType:I,argPackAdvance:be,readValueFromPointer:I},{ignoreDuplicateRegistrations:!0})},of=(l,c,f,h)=>{if(!(h>0))return 0;for(var b=f,I=f+h-1,S=0;S<l.length;++S){var w=l.charCodeAt(S);if(w>=55296&&w<=57343){var F=l.charCodeAt(++S);w=65536+((w&1023)<<10)|F&1023}if(w<=127){if(f>=I)break;c[f++]=w}else if(w<=2047){if(f+1>=I)break;c[f++]=192|w>>6,c[f++]=128|w&63}else if(w<=65535){if(f+2>=I)break;c[f++]=224|w>>12,c[f++]=128|w>>6&63,c[f++]=128|w&63}else{if(f+3>=I)break;c[f++]=240|w>>18,c[f++]=128|w>>12&63,c[f++]=128|w>>6&63,c[f++]=128|w&63}}return c[f]=0,f-b},af=(l,c,f)=>of(l,A,c,f),cf=l=>{for(var c=0,f=0;f<l.length;++f){var h=l.charCodeAt(f);h<=127?c++:h<=2047?c+=2:h>=55296&&h<=57343?(c+=4,++f):c+=3}return c},Is=typeof TextDecoder<"u"?new TextDecoder:void 0,lf=(l,c=0,f=NaN)=>{for(var h=c+f,b=c;l[b]&&!(b>=h);)++b;if(b-c>16&&l.buffer&&Is)return Is.decode(l.subarray(c,b));for(var I="";c<b;){var S=l[c++];if(!(S&128)){I+=String.fromCharCode(S);continue}var w=l[c++]&63;if((S&224)==192){I+=String.fromCharCode((S&31)<<6|w);continue}var F=l[c++]&63;if((S&240)==224?S=(S&15)<<12|w<<6|F:S=(S&7)<<18|w<<12|F<<6|l[c++]&63,S<65536)I+=String.fromCharCode(S);else{var T=S-65536;I+=String.fromCharCode(55296|T>>10,56320|T&1023)}}return I},df=(l,c)=>l?lf(A,l,c):"",uf=(l,c)=>{c=ie(c);var f=c==="std::string";ge(l,{name:c,fromWireType(h){var b=k[h>>2],I=h+4,S;if(f)for(var w=I,F=0;F<=b;++F){var T=I+F;if(F==b||A[T]==0){var N=T-w,O=df(w,N);S===void 0?S=O:(S+="\0",S+=O),w=T+1}}else{for(var Z=new Array(b),F=0;F<b;++F)Z[F]=String.fromCharCode(A[I+F]);S=Z.join("")}return Pe(h),S},toWireType(h,b){b instanceof ArrayBuffer&&(b=new Uint8Array(b));var I,S=typeof b=="string";S||b instanceof Uint8Array||b instanceof Uint8ClampedArray||b instanceof Int8Array||H("Cannot pass non-string to std::string"),f&&S?I=cf(b):I=b.length;var w=br(4+I+1),F=w+4;if(k[w>>2]=I,f&&S)af(b,F,I+1);else if(S)for(var T=0;T<I;++T){var N=b.charCodeAt(T);N>255&&(Pe(F),H("String has UTF-16 code units that do not fit in 8 bits")),A[F+T]=N}else for(var T=0;T<I;++T)A[F+T]=b[T];return h!==null&&h.push(Pe,w),w},argPackAdvance:be,readValueFromPointer:fn,destructorFunction(h){Pe(h)}})},Ss=typeof TextDecoder<"u"?new TextDecoder("utf-16le"):void 0,ff=(l,c)=>{for(var f=l,h=f>>1,b=h+c/2;!(h>=b)&&G[h];)++h;if(f=h<<1,f-l>32&&Ss)return Ss.decode(A.subarray(l,f));for(var I="",S=0;!(S>=c/2);++S){var w=R[l+S*2>>1];if(w==0)break;I+=String.fromCharCode(w)}return I},hf=(l,c,f)=>{if(f??(f=2147483647),f<2)return 0;f-=2;for(var h=c,b=f<l.length*2?f/2:l.length,I=0;I<b;++I){var S=l.charCodeAt(I);R[c>>1]=S,c+=2}return R[c>>1]=0,c-h},pf=l=>l.length*2,mf=(l,c)=>{for(var f=0,h="";!(f>=c/4);){var b=D[l+f*4>>2];if(b==0)break;if(++f,b>=65536){var I=b-65536;h+=String.fromCharCode(55296|I>>10,56320|I&1023)}else h+=String.fromCharCode(b)}return h},gf=(l,c,f)=>{if(f??(f=2147483647),f<4)return 0;for(var h=c,b=h+f-4,I=0;I<l.length;++I){var S=l.charCodeAt(I);if(S>=55296&&S<=57343){var w=l.charCodeAt(++I);S=65536+((S&1023)<<10)|w&1023}if(D[c>>2]=S,c+=4,c+4>b)break}return D[c>>2]=0,c-h},yf=l=>{for(var c=0,f=0;f<l.length;++f){var h=l.charCodeAt(f);h>=55296&&h<=57343&&++f,c+=4}return c},bf=(l,c,f)=>{f=ie(f);var h,b,I,S;c===2?(h=ff,b=hf,S=pf,I=w=>G[w>>1]):c===4&&(h=mf,b=gf,S=yf,I=w=>k[w>>2]),ge(l,{name:f,fromWireType:w=>{for(var F=k[w>>2],T,N=w+4,O=0;O<=F;++O){var Z=w+4+O*c;if(O==F||I(Z)==0){var se=Z-N,ne=h(N,se);T===void 0?T=ne:(T+="\0",T+=ne),N=Z+c}}return Pe(w),T},toWireType:(w,F)=>{typeof F!="string"&&H(`Cannot pass non-string to C++ string type ${f}`);var T=S(F),N=br(4+T+c);return k[N>>2]=T/c,b(F,N+4,T+c),w!==null&&w.push(Pe,N),N},argPackAdvance:be,readValueFromPointer:fn,destructorFunction(w){Pe(w)}})},vf=(l,c)=>{c=ie(c),ge(l,{isVoid:!0,name:c,argPackAdvance:0,fromWireType:()=>{},toWireType:(f,h)=>{}})},xf=()=>2147483648,$f=(l,c)=>Math.ceil(l/c)*c,_f=l=>{var c=z.buffer,f=(l-c.byteLength+65535)/65536|0;try{return z.grow(f),re(),1}catch{}},wf=l=>{var c=A.length;l>>>=0;var f=xf();if(l>f)return!1;for(var h=1;h<=4;h*=2){var b=c*(1+.2/h);b=Math.min(b,l+100663296);var I=Math.min(f,$f(Math.max(l,b),65536)),S=_f(I);if(S)return!0}return!1};bu(),Ye=o.BindingError=class extends Error{constructor(c){super(c),this.name="BindingError"}},fs=o.InternalError=class extends Error{constructor(c){super(c),this.name="InternalError"}},Su(),Ru(),$s=o.UnboundTypeError=Du(Error,"UnboundTypeError"),Yu();var Mf={i:gu,q:yu,n:xu,o:$u,g:Wu,f:Gu,a:ju,e:Hu,s:Ku,j:qu,c:Qu,m:tf,b:nf,h:rf,d:sf,l:uf,k:bf,p:vf,r:wf},ze=pu(),Es=l=>(Es=ze.v)(l),br=l=>(br=ze.x)(l),Pe=l=>(Pe=ze.y)(l),mn;y=function l(){mn||As(),mn||(y=l)};function As(){if(x>0||(Q(),x>0))return;function l(){var c;mn||(mn=!0,o.calledRun=!0,!M&&(J(),d(o),(c=o.onRuntimeInitialized)==null||c.call(o),te()))}o.setStatus?(o.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>o.setStatus(""),1),l()},1)):l()}if(o.preInit)for(typeof o.preInit=="function"&&(o.preInit=[o.preInit]);o.preInit.length>0;)o.preInit.pop()();As();function Pf(l){if(l.length%2!=0)throw"MakePath64: intArray.length must be even";var c=l.map(function(h){return typeof h!="bigint"?BigInt(h):h});let f=new o.Path64;for(let h=0;h<c.length;h+=2){let b=new o.Point64(c[h],c[h+1],BigInt(0));f.push_back(b)}return f}o.MakePath64=Pf;function Cf(l){if(l.length%3!=0)throw"MakePathZ64: intArray.length must be multiple of 3";var c=l.map(function(h){return typeof h!="bigint"?BigInt(h):h});let f=new o.Path64;for(let h=0;h<c.length;h+=3){let b=new o.Point64(c[h],c[h+1],c[h+2]);f.push_back(b)}return f}o.MakePathZ64=Cf;function If(l){if(l.length%2!=0)throw"MakePathD: intArray.length must be even";let c=new o.PathD;for(let f=0;f<l.length;f+=2){let h=new o.PointD(l[f],l[f+1],0);c.push_back(h)}return c}o.MakePathD=If;function Sf(l){if(l.length%3!=0)throw"MakePathZD: intArray.length must be multiple of 3";let c=new o.PathD;for(let f=0;f<l.length;f+=3){let h=new o.PointD(l[f],l[f+1],l[f+2]);c.push_back(h)}return c}o.MakePathZD=Sf;function zs(l){let c=new o.Path64;for(let f=0;f<l.size();f++){const h=l.get(f),b=typeof h.x!="bigint"?BigInt(Math.round(h.x)):h.x,I=typeof h.y!="bigint"?BigInt(Math.round(h.y)):h.y,S=typeof h.z!="bigint"?BigInt(Math.round(h.z)):h.z;let w=new o.Point64(b,I,S);c.push_back(w)}return c}o.PathDToPath64=zs;function Fs(l){let c=new o.PathD;for(let f=0;f<l.size();f++){const h=l.get(f);let b=new o.PointD(Number(h.x),Number(h.y),Number(h.z));c.push_back(b)}return c}o.Path64ToPathD=Fs;function Ef(l){let c=new o.PathsD;for(let f=0;f<l.size();f++){const h=l.get(f);let b=Fs(h);c.push_back(b)}return c}o.Paths64ToPathsD=Ef;function Af(l){let c=new o.Paths64;for(let f=0;f<l.size();f++){const h=l.get(f);let b=zs(h);c.push_back(b)}return c}return o.PathsDToPaths64=Af,a=p,a})})();e.exports=n})(Sn)),Sn.exports}var Vr=ba(),va=ya(Vr),xa=Ns({__proto__:null,default:va},[Vr]),$a=""+new URL("assets/clipper2z-bvMLVKp3.wasm",self.location.href).href;const En=1e6,_a=(e=>{if(typeof e=="function")return e;if(e&&typeof e=="object"){const t=e;if(typeof t.default=="function")return t.default;if(typeof t.Clipper2ZFactory=="function")return t.Clipper2ZFactory;const n=t.default;if(n&&typeof n=="object"){const r=n;if(typeof r.default=="function")return r.default}}throw new Error("Clipper2-WASM factory could not be resolved.")})(xa);let De,Yr;const wa=async()=>De||(Yr??(Yr=_a({locateFile:e=>e.endsWith(".wasm")?$a:e})),De=await Yr,De),Pt=()=>{if(!De)throw new Error("Clipper2 kernel is not initialized. Call initClipperKernel() before using geometry kernel operations.");return De},Xr=e=>BigInt(Math.round(e*En)),Kr=e=>Number(e)/En,Ma=(e,t)=>{const n=new e.Path64;for(const r of t){const i=new e.Point64(Xr(r[0]),Xr(r[1]),0n);n.push_back(i),i.delete()}return n},We=(e,t)=>{const n=new e.Paths64,r=[];for(const i of t){const s=Ma(e,i);n.push_back(s),r.push(s)}return{paths:n,release:()=>{for(const i of r)i.delete();n.delete()}}},Zr=e=>{const t=[];for(let n=0;n<e.size();n+=1){const r=e.get(n);t.push([Kr(r.x),Kr(r.y)]),r.delete()}return t},An=e=>{const t=[];for(let n=0;n<e.size();n+=1){const r=e.get(n);t.push(Zr(r)),r.delete()}return t},qr=1e-5,Jr=(e,t)=>{const n=t[0]-e[0],r=t[1]-e[1];return n*n+r*r},ae=e=>{let t=0;for(let n=0;n<e.length;n+=1){const r=e[n],i=e[(n+1)%e.length];t+=r[0]*i[1]-i[0]*r[1]}return t/2},Oe=e=>{let t=1/0,n=1/0,r=-1/0,i=-1/0;for(const s of e)t=Math.min(t,s[0]),n=Math.min(n,s[1]),r=Math.max(r,s[0]),i=Math.max(i,s[1]);return Number.isFinite(t)?{min:[t,n],max:[r,i]}:{min:[0,0],max:[0,0]}},Pa=(e,t,n)=>{const r=t[0]-e[0],i=t[1]-e[1],s=n[0]-t[0],a=n[1]-t[1];return r*a-i*s},Qr=(e,t)=>{const n=t*t,r=[];for(const i of e){const s=r[r.length-1];(!s||Jr(s,i)>n)&&r.push(i)}return r.length>1&&Jr(r[0],r[r.length-1])<=n&&r.pop(),r},Ct=(e,t=qr)=>Qr(e,t),Ca=(e,t)=>{if(e.length<3)return[...e];const n=[];for(let r=0;r<e.length;r+=1){const i=e[(r-1+e.length)%e.length],s=e[r],a=e[(r+1)%e.length];Math.abs(Pa(i,s,a))>t&&n.push(s)}return n.length>=3?n:[...e]},Ia=(e,t=qr)=>{const n=Qr(e,t);return Ca(n,t)},It=(e,t,n)=>(t[0]-e[0])*(n[1]-e[1])-(t[1]-e[1])*(n[0]-e[0]),St=(e,t,n,r)=>Math.min(e[0],n[0])-r<=t[0]&&t[0]<=Math.max(e[0],n[0])+r&&Math.min(e[1],n[1])-r<=t[1]&&t[1]<=Math.max(e[1],n[1])+r,ei=(e,t,n,r,i=1e-9)=>{const s=It(e,t,n),a=It(e,t,r),o=It(n,r,e),d=It(n,r,t);return Math.abs(s)<=i&&St(e,n,t,i)||Math.abs(a)<=i&&St(e,r,t,i)||Math.abs(o)<=i&&St(n,e,r,i)||Math.abs(d)<=i&&St(n,t,r,i)?!0:s>0!=a>0&&o>0!=d>0},Sa=(e,t,n)=>e===t||Math.abs(e-t)===1||e===0&&t===n-1||t===0&&e===n-1,ti=(e,t=1e-9)=>{const n=[];for(let r=0;r<e.length;r+=1){const i=e[r],s=e[(r+1)%e.length];for(let a=r+1;a<e.length;a+=1){if(Sa(r,a,e.length))continue;const o=e[a],d=e[(a+1)%e.length];ei(i,s,o,d,t)&&n.push([r,a])}}return n},zn=1e-6,Fn=1e-5,Ea=1.5,Aa=0,za=(e,t,n)=>{const r=t[0]-e[0],i=t[1]-e[1];return r*r+i*i<=n*n},Fa=(e,t)=>{const n=ae(e);return t&&n<0||!t&&n>0?[...e].reverse():e},Ta=(e,t)=>{const n=Ct(e,t);return n.length>1&&za(n[0],n[n.length-1],t)&&n.pop(),n},ni=(e,t,n)=>e.map(r=>Ta(r,n)).filter(r=>r.length>=3&&Math.abs(ae(r))>t),ka=(e,t,n)=>{const r=[];for(let i=0;i<e.size();i+=1){const s=e.get(i);r.push(Zr(s)),s.delete()}return ni(r,t,n)},ri=(e,t,n)=>{const r=Pt(),i=n.areaEpsilon??zn,s=n.distanceEpsilon??Fn,a=n.miterLimit??Ea,o=We(r,e);let d;try{const u=Math.round(t*En);d=r.InflatePaths64(o.paths,u,r.JoinType.Miter,r.EndType.Polygon,a,Aa);const p=ka(d,i,s);return p.length===0?{ok:!1,reason:"offset region collapsed after Clipper2 cleanup",warnings:[]}:{ok:!0,rings:p,warnings:[]}}finally{d==null||d.delete(),o.release()}},Tn=(e,t,n={})=>{const r=n.distanceEpsilon??Fn,i=n.areaEpsilon??zn,s=n.side??"inward",a=Math.abs(t),o=Ct(e,r);if(o.length<3)return{ok:!1,reason:"source ring collapsed below 3 points",warnings:[]};const d=ae(o);if(Math.abs(d)<=i)return{ok:!1,reason:"source ring collapsed to near-zero area",warnings:[]};const u=ti(o,r);if(u.length>0)return{ok:!1,reason:`source ring has ${u.length} self intersections`,warnings:[]};if(a<=r)return{ok:!0,rings:[o],warnings:[]};const p=d>=0?1:-1,m=(s==="inward"?-p:p)*a;return ri([o],m,n)},Et=(e,t,n={})=>{const r=n.distanceEpsilon??Fn,i=n.areaEpsilon??zn,s=Math.abs(t);if(s<=r){const o=ni(e.map(d=>[...d.points]),i,r);return o.length>0?{ok:!0,rings:o,warnings:[]}:{ok:!1,reason:"region collapsed below 3 points",warnings:[]}}const a=e.flatMap(o=>{if(o.role==="invalid"||o.role==="open")return[];const d=Ct(o.points,r);if(d.length<3||Math.abs(ae(d))<=i)return[];const u=o.role!=="hole";return[Fa(d,u)]});return a.length===0?{ok:!1,reason:"region has no valid rings",warnings:[]}:ri(a,-s,n)},ii=(e,t,n={})=>{const r=Tn(e,t,n);return r.ok===!1?{ok:!1,reason:r.reason,warnings:r.warnings}:r.rings.length>1?{ok:!1,reason:`offset produced ${r.rings.length} rings; use offsetClosedRing2MultiResult`,warnings:r.warnings}:{ok:!0,points:r.rings[0],warnings:r.warnings}},si=(e,t,n={})=>{const r=ii(e,t,n);return r.ok?r.points:null},La=1e-6,Ra=1e-5,At=(e,t)=>{let n=!1;for(let r=0,i=t.length-1;r<t.length;i=r,r+=1){const s=t[r],a=t[i];s[1]>e[1]!=a[1]>e[1]&&e[0]<(a[0]-s[0])*(e[1]-s[1])/(a[1]-s[1])+s[0]&&(n=!n)}return n},Na=e=>e[0]??null,Da=(e,t)=>t[0]>=e.min[0]&&t[0]<=e.max[0]&&t[1]>=e.min[1]&&t[1]<=e.max[1],Wa=(e,t)=>t.min[0]>=e.min[0]&&t.max[0]<=e.max[0]&&t.min[1]>=e.min[1]&&t.max[1]<=e.max[1],Oa=e=>e%2===1?"hole":e===0?"outer":"island",Ba=(e,t)=>{const n=t%2===0,i=ae(e)>=0;return n===i?e:[...e].reverse()},oi=(e,t={})=>{var o;const n=t.areaEpsilon??La,r=t.distanceEpsilon??Ra,i=e.map((d,u)=>{const p=Ia(d,r),m=ae(p);return{area:m,bounds:Oe(p),childIds:[],depth:0,id:`contour-${u}`,points:p,role:p.length<3||Math.abs(m)<=n?"invalid":"outer",sourceIndex:u,winding:m>=0?"ccw":"cw"}}),s=i.filter(d=>d.role!=="invalid");for(const d of s){const u=Na(d.points);if(!u)continue;const p=s.filter(g=>g.sourceIndex!==d.sourceIndex&&Math.abs(g.area)>Math.abs(d.area)&&Wa(g.bounds,d.bounds)&&Da(g.bounds,u)&&At(u,g.points)).sort((g,C)=>Math.abs(g.area)-Math.abs(C.area)),m=p[0];d.parentId=m==null?void 0:m.id,d.depth=p.length}for(const d of s)d.role=Oa(d.depth),d.points=Ba(d.points,d.depth),d.area=ae(d.points),d.winding=d.area>=0?"ccw":"cw",d.bounds=Oe(d.points);const a=new Map(s.map(d=>[d.id,d]));for(const d of s)d.parentId&&((o=a.get(d.parentId))==null||o.childIds.push(d.id));return i},Ga=1e-7,ja=1e-9,kn=(e,t,n)=>[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n],ai=(e,t)=>Math.hypot(t[0]-e[0],t[1]-e[1]),zt=(e,t)=>{const n=e.end[0]-e.start[0],r=e.end[1]-e.start[1],i=n*n+r*r;return i<=0?0:((t[0]-e.start[0])*n+(t[1]-e.start[1])*r)/i},Ha=(e,t,n)=>{const r=zt(e,t),i=zt(e,n);return r<=i?{start:t,end:n}:{start:n,end:t}},Ua=(e,t)=>{const n=e.end[0]-e.start[0],r=e.end[1]-e.start[1],i=n*n+r*r;if(i<=0)return Number.POSITIVE_INFINITY;const s=n*(t[1]-e.start[1])-r*(t[0]-e.start[0]);return s*s/i},Va=(e,t)=>{const n=t.length>1?kn(t[0],t[t.length-1],.5):t[0];let r=0,i=Number.POSITIVE_INFINITY;for(let s=0;s<e.length;s+=1){const a=e[s],o=zt(a,n),d=o<0?o*o:o>1?(o-1)*(o-1):0,u=Ua(a,n)+d;u<i&&(r=s,i=u)}return r},Ya=(e,t)=>{const n=e[0],r=n.end[0]-n.start[0],i=n.end[1]-n.start[1],s=Math.hypot(r,i);if(s<=t)return;const a=[r/s,i/s],o=[-a[1],a[0]];for(const d of e){const u=d.end[0]-d.start[0],p=d.end[1]-d.start[1],m=Math.hypot(u,p);if(m<=t)return;const g=u/m*a[1]-p/m*a[0];if(Math.abs(g)>ja)return}return(d,u)=>{const m=(u[0]-d[0])*a[0]+(u[1]-d[1])*a[1]>=0?{start:d,end:u}:{start:u,end:d},g=kn(m.start,m.end,.5);return{...m,orderOffset:g[0]*o[0]+g[1]*o[1],orderT:m.start[0]*a[0]+m.start[1]*a[1]}}},Xa=(e,t)=>{const n=Ya(e,t);return n||((r,i,s)=>{const a=Va(e,s),o=e[a],d=Ha(o,r,i);return{...d,orderOffset:a,orderT:zt(o,d.start)}})},Ft=(e,t,n,r={})=>{const i=r.epsilon??Ga,s=r.minLength??i,a=e.filter(v=>ai(v.start,v.end)>=s),o=t.filter(v=>v.length>=3);if(a.length===0||o.length===0)return[];const d=Pt(),u=We(d,a.map(v=>[v.start,v.end])),p=We(d,o),m=new d.Clipper64,g=new d.Paths64,C=new d.Paths64,E=[],_=Xa(a,i);try{m.AddOpenSubject(u.paths),m.AddClip(p.paths),m.ExecutePath(d.ClipType.Intersection,d.FillRule.EvenOdd,g,C);for(const v of An(C))if(!(v.length<2))for(let z=1;z<v.length;z+=1){const M=v[z-1],P=v[z];if(ai(M,P)<s)continue;const A=_(M,P,v),R=kn(A.start,A.end,.5);n(R)&&E.push(A)}}finally{g.delete(),C.delete(),m.delete(),p.release(),u.release()}return E.sort((v,z)=>v.orderOffset-z.orderOffset||v.orderT-z.orderT).map(({orderOffset:v,orderT:z,...M})=>M)},Ka=(e,t,n,r={})=>Ft([e],t,n,r),Ln=[[0,0],[20,0],[20,10],[0,10]],ci=[[6,3],[14,3],[14,7],[6,7]],Za=[[0,0],[16,0],[16,5],[9,5],[9,10],[0,10]],li=[[0,0],[10,10],[0,10],[10,0]],qa=[[0,0],[12,0],[12,3],[7,3],[7,10],[5,10],[5,3],[0,3]],Ce=(e,t)=>e?[]:[{level:"error",message:t}],Ja=()=>{const e=[],t=oi([Ln,ci]);e.push(...Ce(t.filter(d=>d.role==="outer").length===1,"Expected one outer contour.")),e.push(...Ce(t.filter(d=>d.role==="hole").length===1,"Expected one hole contour."));const r=Ka({start:[-1,5],end:[21,5]},[Ln,ci],d=>t.filter(u=>u.role!=="invalid"&&u.points.length>=3&&At(d,u.points)).length%2===1);e.push(...Ce(r.length===2,"Expected scan line through holed rectangle to produce two fill segments."));const i=si(Ln,1,{side:"inward"});e.push(...Ce(!!(i&&i.length===4),"Expected rectangle inset to produce a valid ring."));const s=si(Za,.5,{side:"inward"});e.push(...Ce(!!(s&&s.length>=4),"Expected concave inset to produce a valid ring."));const a=Tn(qa,1.2,{side:"inward"});e.push(...Ce(a.ok&&a.rings.length===1,"Expected T-junction inset to remove collapsed stem.")),e.push(...Ce(ti(li).length===1,"Expected bowtie fixture to report one self intersection."));const o=ii(li,.5,{side:"inward"});return e.push(...Ce(!o.ok,"Expected self-intersecting source ring to be rejected.")),e},Qa=()=>({min:[1/0,1/0,1/0],max:[-1/0,-1/0,-1/0]}),Rn=(e,t)=>({min:[Math.min(e.min[0],t[0]),Math.min(e.min[1],t[1]),Math.min(e.min[2],t[2])],max:[Math.max(e.max[0],t[0]),Math.max(e.max[1],t[1]),Math.max(e.max[2],t[2])]}),Nn=e=>{let t=Qa();for(const n of e)t=Rn(Rn(Rn(t,n.a),n.b),n.c);return e.length===0?{min:[0,0,0],max:[0,0,0]}:t},ec=new TextDecoder,Tt=(e,t)=>[e.getFloat32(t,!0),e.getFloat32(t+4,!0),e.getFloat32(t+8,!0)],tc=e=>e.byteLength<84?!1:84+new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(80,!0)*50===e.byteLength,nc=e=>{const t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(80,!0),r=[];for(let i=0;i<n;i+=1){const s=84+i*50;r.push({normal:Tt(t,s),a:Tt(t,s+12),b:Tt(t,s+24),c:Tt(t,s+36)})}return r},rc=e=>{const t=ec.decode(e),n=/vertex\s+([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)\s+([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)\s+([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)/gi,r=[],i=[];let s;for(;s=n.exec(t);)r.push([Number(s[1]),Number(s[2]),Number(s[3])]);for(let a=0;a+2<r.length;a+=3)i.push({a:r[a],b:r[a+1],c:r[a+2]});return i},ic=(e,t)=>{const n=tc(e)?nc(e):rc(e);return{id:t??"stl",sourcePath:t,triangles:n,bounds:Nn(n)}},Dn=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],Wn=(e,t)=>{let n=e[0]*t.scale[0],r=e[1]*t.scale[1],i=e[2]*t.scale[2];const[s,a,o]=t.rotation;if(s!==0){const d=Math.cos(s),u=Math.sin(s),p=r*d-i*u,m=r*u+i*d;r=p,i=m}if(a!==0){const d=Math.cos(a),u=Math.sin(a),p=n*d+i*u,m=-n*u+i*d;n=p,i=m}if(o!==0){const d=Math.cos(o),u=Math.sin(o),p=n*d-r*u,m=n*u+r*d;n=p,r=m}return[n+t.position[0],r+t.position[1],i+t.position[2]]},sc=(e,t)=>{const n=e.triangles.map(r=>({...r,a:Dn(r.a,t),b:Dn(r.b,t),c:Dn(r.c,t)}));return{...e,triangles:n,bounds:Nn(n)}},oc=(e,t)=>{const n=e.triangles.map(r=>({a:Wn(r.a,t),b:Wn(r.b,t),c:Wn(r.c,t)}));return{...e,triangles:n,bounds:Nn(n)}},ac=(e,t)=>[e.frame.origin[0]+e.frame.xAxis[0]*t[0]+e.frame.yAxis[0]*t[1],e.frame.origin[1]+e.frame.xAxis[1]*t[0]+e.frame.yAxis[1]*t[1],e.frame.origin[2]+e.frame.xAxis[2]*t[0]+e.frame.yAxis[2]*t[1]],kt=(e,t)=>oi(t.map(r=>r.points2)).map((r,i)=>{const s=t[r.sourceIndex]??t[i],a=s.points2.length>=3?s.points2:r.points,o=s.points3.length===a.length?s.points3:a.map(u=>ac(e,u)),d=ae(a);return{...s,area:d,bounds:Oe(a),childIds:r.childIds,closed:r.role!=="open",depth:r.depth,id:`curve-${i}`,parentId:r.parentId,points2:a,points3:o,role:r.role,winding:d>=0?"ccw":"cw"}}),On=.049,Bn=1e-4,cc=1e-6,lc=1e-7,Te=e=>typeof e.id=="number",Gn=(e,t)=>{const n=t[0]-e[0],r=t[1]-e[1];return Math.sqrt(n*n+r*r)},tt=(e,t,n)=>Gn(e,t)<=n,di=(e,t)=>`${Math.round(e[0]/t)},${Math.round(e[1]/t)}`,ui=e=>{let t=0;for(let n=0;n<e.length;n+=1){const r=e[n],i=e[(n+1)%e.length];t+=r[0]*i[1]-i[0]*r[1]}return t/2},dc=(e,t)=>{if(e.length<4)return!1;for(let n=0;n<e.length;n+=1){const r=e[n],i=e[(n+1)%e.length];for(let s=n+1;s<e.length;s+=1){if(s===n||s===n+1||n===0&&s===e.length-1)continue;const o=e[s],d=e[(s+1)%e.length];if(ei(r,i,o,d,t))return!0}}return!1},uc=(e,t)=>e.points2.length<2?!1:tt(e.points2[0],e.points2[e.points2.length-1],t),Lt=(e,t=Bn)=>{if(e.points2.length<2)return e;const n=e.points2[0],r=e.points2[e.points2.length-1];return tt(n,r,t)?{...e,points2:e.points2.slice(0,-1),points3:e.points3.slice(0,-1)}:e},fi=(e,t)=>{if(!uc(e,t))return{rejected:!1,short:!1};const n={...e,end:e.start,points2:[...e.points2.slice(0,-1),e.points2[0]],points3:[...e.points3.slice(0,-1),e.points3[0]]},r=Lt(n,t);return r.points2.length<3?{rejected:!1,short:!0}:{chain:r,rejected:!1,short:!1}},jn=(e,t,n={})=>{const r=Lt(e,t);return!(r.points2.length<3||Math.abs(ui(r.points2))<=cc||!n.allowSelfIntersection&&dc(r.points2,lc))},fc=(e,t)=>{var r;const n=Te(e)?e.endpointKeys:(r=e.source)==null?void 0:r.endpointKeys;return n||[`p:${di(e.points2[0],t)}`,`p:${di(e.points2[1],t)}`]},hc=e=>{var t;return Te(e)?e.endpointRefs:(t=e.source)==null?void 0:t.endpointRefs},pc=e=>{var t;return Te(e)?e.triangleIndex:(t=e.source)==null?void 0:t.triangleIndex},hi=(e,t,n,r)=>{const i=r==null?void 0:r[t],s=Te(e)?t===0?e.edgeAId:e.edgeBId:i==null?void 0:i.edgeIndex,a=Te(e)?t===0?e.aId:e.bId:i==null?void 0:i.vertexIndex;return{edgeId:s,key:n[t],point2:e.points2[t],point3:e.points3[t],pointId:a,ref:i}},mc=e=>{const t=e.start.key,n=e.end.key;return t<n?`${t}:${n}`:`${n}:${t}`},gc=(e,t)=>{const n=[],r=new Set;let i=0,s=0;for(const a of e){if(a.points2.length<2||a.points3.length<2)continue;if(tt(a.points2[0],a.points2[1],t)){s+=1;continue}const o=fc(a,t),d=hc(a),u={end:hi(a,1,o,d),id:n.length,noSeed:Te(a)?a.noSeed??!1:!1,skip:Te(a)?a.skip??!1:!1,start:hi(a,0,o,d),triangleIndex:pc(a)},p=mc(u);if(r.has(p)){i+=1;continue}r.add(p),n.push(u)}return{duplicateCount:i,lines:n,zeroLengthCount:s}},nt=e=>{const t=[];return typeof e.edgeId=="number"&&t.push(`e:${e.edgeId}`),typeof e.pointId=="number"&&t.push(`v:${e.pointId}`),t.push(e.key),[...new Set(t)]},ke=(e,t)=>nt(e).some(n=>nt(t).includes(n)),yc=(e,t)=>{if(!e||!t)return!1;if(typeof e.edgeIndex=="number"&&typeof t.edgeIndex=="number"&&e.edgeIndex===t.edgeIndex)return!0;const n=new Set;typeof e.edgeIndex=="number"&&n.add(e.edgeIndex);for(const r of e.incidentEdgeIndices??[])n.add(r);return typeof t.edgeIndex=="number"&&n.has(t.edgeIndex)?!0:(t.incidentEdgeIndices??[]).some(r=>n.has(r))},pi=(e,t,n,r)=>{const i=t[0]-e[0],s=t[1]-e[1],a=r[0]-n[0],o=r[1]-n[1],d=Math.sqrt(i*i+s*s),u=Math.sqrt(a*a+o*o);return d<=Number.EPSILON||u<=Number.EPSILON?1:(i*a+s*o)/(d*u)},bc=(e,t)=>t===0?e.start:e.end,vc=(e,t)=>t===0?e.end:e.start,Hn=(e,t)=>({enter:bc(e,t),exit:vc(e,t),line:e}),xc=e=>{const t=new Map,n=(r,i,s)=>{const a=i*2+s,o=t.get(r);o?o.push(a):t.set(r,[a])};for(const r of e)if(!r.skip){for(const i of nt(r.start))n(i,r.id,0);for(const i of nt(r.end))n(i,r.id,1)}return t},$c=(e,t,n,r)=>{const i=new Map;for(const s of nt(n))for(const a of t.get(s)??[]){const o=Math.floor(a/2),d=a%2;r.has(o)||i.set(a,Hn(e[o],d))}return[...i.values()]},_c=(e,t)=>{if(t.length<=1)return t[0];const n=t.map(o=>{const d=yc(e.exit.ref,o.enter.ref)?100:0,u=e.line.triangleIndex!==o.line.triangleIndex?10:0,p=pi(e.enter.point2,e.exit.point2,o.enter.point2,o.exit.point2),m=o.line.noSeed?.01:0;return{candidate:o,score:d+u+p-m}}).sort((o,d)=>d.score-o.score),r=n[0],i=n[1];if(!r)return;const s=r.score>=50,a=r.score>=10.75&&(!i||r.score-i.score>=.05);if(!(!s&&!a))return r.candidate},mi=(e,t,n,r,i)=>{const s=[n.enter.point2,n.exit.point2],a=[n.enter.point3,n.exit.point3],o=[n.line.id],d=new Set([n.line.id]);let u=n,p=!1,m=!1,g=!1;const C=Math.max(e.length+1,1);for(let E=0;E<C;E+=1){if((ke(u.exit,n.enter)||tt(u.exit.point2,n.enter.point2,i))&&o.length>1){p=!0;break}const _=$c(e,t,u.exit,r).filter(P=>!d.has(P.line.id)),v=ke(u.exit,n.enter)||tt(u.exit.point2,n.enter.point2,i)?n:void 0,z=v?[..._,v]:_,M=_c(u,z);if(!M){g=z.length>1;break}if(M.line.id===n.line.id){p=!0;break}if(d.has(M.line.id)){m=!0;break}d.add(M.line.id),o.push(M.line.id),s.push(M.exit.point2),a.push(M.exit.point3),u=M}return{ambiguous:g,chain:{end:u.exit,lineIds:o,points2:s,points3:a,start:n.enter},closed:p,selfTouch:m}},Rt=e=>({end:e.start,lineIds:[...e.lineIds].reverse(),points2:[...e.points2].reverse(),points3:[...e.points3].reverse(),start:e.end}),rt=(e,t)=>({end:t.end,lineIds:[...e.lineIds,...t.lineIds],points2:[...e.points2,...t.points2.slice(1)],points3:[...e.points3,...t.points3.slice(1)],start:e.start}),wc=(e,t)=>e.points2.length<2||t.points2.length<2?1:pi(e.points2[e.points2.length-2],e.points2[e.points2.length-1],t.points2[0],t.points2[1]),Mc=(e,t)=>{if(ke(e.end,t.start))return rt(e,t);if(ke(e.end,t.end))return rt(e,Rt(t));if(ke(e.start,t.end))return rt(t,e);if(ke(e.start,t.start))return rt(Rt(e),t)},Pc=(e,t,n)=>{const r=[],i=Rt(e),s=Rt(t),a=-.35,o=(d,u)=>{const p=Gn(d.end.point2,u.start.point2);if(p>n)return;const m=wc(d,u);m<a||r.push({chain:rt(d,{...u,start:d.end,points2:[d.end.point2,...u.points2.slice(1)],points3:[d.end.point3,...u.points3.slice(1)]}),directionScore:m,distance:p})};return o(e,t),o(e,s),o(i,t),o(i,s),r},Cc=(e,t,n)=>Pc(e,t,n).sort((i,s)=>{const a=i.distance-s.distance;return Math.abs(a)>1e-9?a:s.directionScore-i.directionScore})[0],Ic=(e,t)=>{const n=[...e],r=[];let i=0,s=0,a=0,o=0,d=0,u=0,p=0,m=0,g=0,C=!0;for(;C;){C=!1;let E;for(let v=0;v<n.length;v+=1){const z=[];for(let M=v+1;M<n.length;M+=1){const P=Mc(n[v],n[M]);P&&z.push({bIndex:M,chain:P})}if(z.length===1){E={aIndex:v,bIndex:z[0].bIndex,chain:z[0].chain};break}z.length>1&&(i+=z.length)}if(E){n.splice(E.bIndex,1),n.splice(E.aIndex,1,E.chain),a+=1,C=!0;continue}let _;for(let v=0;v<n.length;v+=1){const z=[];for(let M=v+1;M<n.length;M+=1){const P=Cc(n[v],n[M],t);P&&(u+=1,z.push({bIndex:M,candidate:P}))}if(z.length>0){z.sort((R,G)=>{const D=R.candidate.distance-G.candidate.distance;return Math.abs(D)>1e-9?D:G.candidate.directionScore-R.candidate.directionScore});const M=z[0],P=z[1];if(!(!P||M.candidate.distance<=t*.25||P.candidate.distance-M.candidate.distance>=Math.max(1e-6,t*.1))){d+=z.length;continue}_={aIndex:v,bIndex:M.bIndex,chain:M.candidate.chain};break}}_&&(n.splice(_.bIndex,1),n.splice(_.aIndex,1,_.chain),p+=1,C=!0)}for(let E=n.length-1;E>=0;E-=1){const _=n[E],v=fi(_,t);if(v.short){g+=1,s+=1,n.splice(E,1);continue}v.rejected&&(m+=1),(v.chain||ke(_.start,_.end)&&jn(_,t))&&(r.push(v.chain??Lt(_,t)),n.splice(E,1),o+=v.chain?1:0)}return{ambiguousEndpointCount:i,closedChains:r,discardedShortNearClosedChainCount:s,exactMergedChainCount:a,gapClosedChainCount:o,nearMergeAmbiguousCount:d,nearMergeCandidateCount:u,nearMergedChainCount:p,openChains:n,rejectedClosedChainCount:m,shortNearClosedChainCount:g}},Sc=e=>Gn(e.points2[0],e.points2[e.points2.length-1]),Ec=e=>{if(e.length===0)return{max:0,min:0};const t=e.map(Sc);return{max:Math.max(...t),min:Math.min(...t)}},Ac=(e,t,n)=>{const r=gc(e,t),i=r.lines,s=xc(i),a=new Set,o=[],d=[];let u=0,p=0,m=0,g=0;const C=[...i.filter(v=>!v.skip&&!v.noSeed),...i.filter(v=>!v.skip&&v.noSeed)];for(const v of C){if(a.has(v.id))continue;const z=mi(i,s,Hn(v,0),a,n),M=mi(i,s,Hn(v,1),a,n),P=[z,M].find(R=>R.closed&&!R.selfTouch&&jn(R.chain,n))??[z,M].filter(R=>!R.selfTouch).sort((R,G)=>G.chain.lineIds.length-R.chain.lineIds.length)[0]??z;for(const R of P.chain.lineIds)a.add(R);P.ambiguous&&(u+=1),P.selfTouch&&(g+=1);const A=fi(P.chain,n);A.short&&(m+=1),A.rejected&&(u+=1),!P.selfTouch&&(A.chain||P.closed&&jn(P.chain,n))?o.push(A.chain??Lt(P.chain,n)):P.chain.points2.length>=2&&d.push(P.chain)}const E=Ic(d,n),_=Ec(E.openChains);return{ambiguousEndpointCount:u+E.ambiguousEndpointCount,closedChains:[...o,...E.closedChains],discardedShortNearClosedChainCount:p+E.discardedShortNearClosedChainCount,duplicateCount:r.duplicateCount,exactMergedChainCount:E.exactMergedChainCount,gapClosedChainCount:E.gapClosedChainCount,nearMergeAmbiguousCount:E.nearMergeAmbiguousCount,nearMergeCandidateCount:E.nearMergeCandidateCount,nearMergedChainCount:E.nearMergedChainCount,openGapMax:_.max,openGapMin:_.min,openChains:E.openChains,pairedLineCount:a.size,rejectedClosedChainCount:E.rejectedClosedChainCount,selfTouchCount:g,shortNearClosedChainCount:m+E.shortNearClosedChainCount,zeroLengthCount:r.zeroLengthCount}},Nt=(e,t={})=>{const r=(e.intersectionLines&&e.intersectionLines.length>0?e.intersectionLines:e.openCurves).filter(P=>P.points2.length>=2&&P.points3.length>=2),i=Math.max(Bn,t.closingRadius??On),s=Ac(r,Bn,i),a=t.emitOpenCurves??t.diagnostics!=="none",o=s.closedChains.map((P,A)=>{const R=ui(P.points2);return{area:R,closed:!0,id:`curve-${A}`,points2:P.points2,points3:P.points3,role:"unknown",winding:R>=0?"ccw":"cw"}}),d=a?s.openChains.map((P,A)=>({closed:!1,id:`open-${A}`,points2:P.points2,points3:P.points3,role:"open"})):[],u=kt(e,o),p=u.filter(P=>P.role==="outer").length,m=u.filter(P=>P.role==="hole").length,g=u.filter(P=>P.role==="island").length,C=u.filter(P=>P.role==="invalid").length,E=t.diagnostics==="none"?[]:[...e.diagnostics,...s.zeroLengthCount>0||s.duplicateCount>0?[{level:"info",message:`${s.zeroLengthCount} zero-length section segments and ${s.duplicateCount} duplicate section segments were removed before make_loops.`}]:[],...s.ambiguousEndpointCount>0||s.selfTouchCount>0?[{level:s.ambiguousEndpointCount>0?"warning":"info",message:`${s.ambiguousEndpointCount} section endpoints remained ambiguous and ${s.selfTouchCount} self-touching loop candidates were left open by make_loops.`}]:[],{level:"info",message:`${s.pairedLineCount} section lines were consumed by make_loops.`},...s.openChains.length>0?[{level:"info",message:`make_loops repair: ${s.gapClosedChainCount} gap-closed, ${s.exactMergedChainCount} exact-merged, ${s.nearMergedChainCount}/${s.nearMergeCandidateCount} near-merged, ${s.nearMergeAmbiguousCount} near candidates ambiguous, ${s.shortNearClosedChainCount} short near-closed chains, ${s.rejectedClosedChainCount} closed candidates rejected; open gap range ${s.openGapMin.toFixed(6)}-${s.openGapMax.toFixed(6)} mm with closing ${i.toFixed(6)} mm.`}]:[],...s.discardedShortNearClosedChainCount>0?[{level:"info",message:`${s.discardedShortNearClosedChainCount} short near-closed non-contour fragments were discarded after make_loops.`}]:[],{level:u.length>0&&C===0?"info":"warning",message:`${p} outer curves, ${m} hole curves, ${g} island curves, ${C} invalid curves, and ${d.length} open curves connected from ${r.length} section segments.`}],{intersectionLines:_,rawCurves:v,openCurves:z,...M}=e;return{...M,curves:u,diagnostics:E,openCurves:d}},Un=1e-9,zc=e=>Math.abs(ue(e,[0,0,1]))>.95?[1,0,0]:xe(Fe([0,0,1],e)),gi=(e,t)=>{if(!Number.isFinite(e))throw new Error(`Plane stack ${t} must be a finite number.`);return e},Fc=(e,t,n)=>{const r=typeof e=="function"?e(t,n):e;if(!Number.isFinite(r)||r<=0)throw new Error("Plane stack pitch must return a positive finite number.");return r},Vn=({includeMax:e=!1,includeMin:t=!1,max:n,min:r,pitch:i})=>{const s=gi(r,"min"),a=gi(n,"max");if(a<s)return[];const o=[];let d=0,u=s;for(t&&o.push(s);u<a-Un&&(u+=Fc(i,u,d),!(u>a+Un));)o.push(u),d+=1;if(e){const p=o[o.length-1];(p===void 0||Math.abs(p-a)>Un)&&o.push(a)}return o},Tc=(e,t,n)=>[e[0]+t[0]*n,e[1]+t[1]*n,e[2]+t[2]*n],kc=({normalAt:e,pointAt:t,xAxis:n,xAxisAt:r},i,s)=>({distance:i,kind:"plane",origin:t(i,s),normal:e(i,s),xAxis:(r==null?void 0:r(i,s))??n}),Yn=e=>Vn(e).map((t,n)=>kc(e,t,n)),Lc={z:e=>({distance:e,kind:"plane",origin:[0,0,e],normal:[0,0,1],xAxis:[1,0,0]}),fromPointNormal:(e,t,n={})=>({kind:"plane",distance:0,origin:e,normal:t,xAxis:n.xAxis}),fromNormal:({origin:e,normal:t,xAxis:n})=>({kind:"plane",distance:0,origin:e,normal:t,xAxis:n}),stack:({origin:e,normal:t,xAxis:n,...r})=>{const i=xe(t),s=ue(i,i)>0?i:[0,0,1];return Vn(r).map(a=>({kind:"plane",distance:a,origin:Tc(e,s,a),normal:s,xAxis:n}))},zStack:e=>Vn(e).map(t=>({kind:"plane",distance:t,origin:[0,0,t],normal:[0,0,1],xAxis:[1,0,0]})),rail:Yn},yi=e=>{const t=xe(e.normal),n=xe(e.xAxis??zc(t)),r=xe(Fe(t,n));return{origin:e.origin,normal:t,xAxis:n,yAxis:r}},bi=(e,t)=>At(e,t),Rc=(e,t,n)=>{const r=n[0]-t[0],i=n[1]-t[1],s=r*r+i*i,a=s===0?0:Math.max(0,Math.min(1,((e[0]-t[0])*r+(e[1]-t[1])*i)/s)),o=t[0]+r*a,d=t[1]+i*a,u=e[0]-o,p=e[1]-d;return Math.sqrt(u*u+p*p)},Xn=(e,t)=>{let n=1/0;for(const r of t.curves)if(!(r.role==="invalid"||r.points2.length<2))for(let i=0;i<r.points2.length;i+=1){const s=r.points2[i],a=r.points2[(i+1)%r.points2.length];n=Math.min(n,Rc(e,s,a))}return n},Nc=(e,t,n=0)=>t.curves.filter(s=>s.role!=="invalid"&&s.points2.length>=3&&bi(e,s.points2)).length%2===1&&(n<=0||Xn(e,t)>=n),vi=(e,t,n={})=>{const r=[],i=Et(e.curves.map(d=>({points:d.points2,role:d.role})),t,n);for(const d of i.warnings)r.push({level:"info",message:`Offset region: ${d}.`});i.ok||r.push({level:"warning",message:`Offset region discarded: ${i.reason}.`});const a=(i.ok?i.rings:[]).map((d,u)=>{const p=e.curves.find(m=>bi(d[0],m.points2));return{id:`offset-region-${u}`,points2:d,points3:[],closed:!0,role:(p==null?void 0:p.role)??"unknown"}}),o=kt(e,a);return{...e,curves:o,diagnostics:[...e.diagnostics,...r,{level:o.length>0?"info":"warning",message:`Inset region by ${t.toFixed(3)} mm: ${o.length} region curves remain from ${e.curves.length} source curves.`}]}},Be=(e,t)=>{const n=t??(s=>Nc(s,e)),r=!t;return{contains:n,inset:s=>{if(s<=0)return Be(e,t);if(r){const a=vi(e,s),o=e.curves.filter(u=>u.role!=="invalid"&&u.points2.length>=3).length,d=a.curves.filter(u=>u.role!=="invalid"&&u.points2.length>=3).length;return d>0||o===0?Be(a):Be({...e,diagnostics:[...a.diagnostics,{level:"warning",message:`Inset region fallback used source contours because ${d}/${o} offset curves remained.`}]},u=>n(u)&&Xn(u,e)>=s)}return Be(e,a=>n(a)&&Xn(a,e)>=s)},section:e,subtract:s=>Be(e,a=>n(a)&&!s.contains(a))}},xi=new WeakMap,$i=new WeakMap,Dc=(e,t)=>[Math.round(e[0]/t),Math.round(e[1]/t),Math.round(e[2]/t)],_i=(e,t,n)=>`${e},${t},${n}`,Wc=(e,t)=>{const n=t[0]-e[0],r=t[1]-e[1],i=t[2]-e[2];return n*n+r*r+i*i},Oc=(e,t,n)=>xr(Fe(ve(t,e),ve(n,e)))/2,wi=e=>[...e].sort((t,n)=>t-n).join(":"),Bc=(e,t)=>e<t?`${e}:${t}`:`${t}:${e}`,Gc=(e,t)=>e<t?[e,t]:[t,e],jc=(e,t)=>{const n=[],r=new Map,i=t*t,s=new Map,a=[],o=new Set;let d=0,u=0;const p=M=>{const[P,A,R]=Dc(M,t);for(let B=-1;B<=1;B+=1)for(let Y=-1;Y<=1;Y+=1)for(let j=-1;j<=1;j+=1){const X=r.get(_i(P+B,A+Y,R+j));if(X){for(const re of X)if(Wc(n[re],M)<=i)return re}}const G=n.length;n.push(M);const D=_i(P,A,R),k=r.get(D);return k?k.push(G):r.set(D,[G]),G},m=(M,P,A)=>{const R=Bc(M,P),G=s.get(R);if(typeof G=="number")return a[G].triangleIds.push(A),G;const D=a.length;return a.push({id:D,key:R,kind:"boundary",triangleIds:[A],vertexIds:Gc(M,P)}),s.set(R,D),D},g=e.triangles.map((M,P)=>{const A=[p(M.a),p(M.b),p(M.c)],R=o.has(wi(A)),G=A[0]===A[1]||A[1]===A[2]||A[2]===A[0]||Oc(M.a,M.b,M.c)<=t*t;R?u+=1:o.add(wi(A)),G&&(d+=1);const D=G?"degenerate":R?"duplicate":void 0,k=D?[-1,-1,-1]:[m(A[0],A[1],P),m(A[1],A[2],P),m(A[2],A[0],P)];return{duplicate:R,edgeIds:k,skipReason:D,sourceIndex:P,vertexIds:A}});let C=0,E=0,_=0;for(const M of a)M.triangleIds.length===1?(M.kind="boundary",C+=1):M.triangleIds.length===2?(M.kind="manifold",E+=1):(M.kind="non-manifold",_+=1);const v=Array.from({length:n.length},()=>[]),z=Array.from({length:n.length},()=>[]);for(const M of g)if(!M.skipReason){for(const P of M.vertexIds)v[P].push(M.sourceIndex);for(const P of M.edgeIds){const A=a[P];for(const R of A.vertexIds){const G=z[R];G.includes(P)||G.push(P)}}}return{diagnostics:{boundaryEdgeCount:C,degenerateTriangleCount:d,duplicateTriangleCount:u,manifoldEdgeCount:E,nonManifoldEdgeCount:_,originalTriangleCount:e.triangles.length,sharedVertexCount:n.length},edges:a,triangles:g,vertexEdgeIds:z,vertexTriangleIds:v,vertices:n}},Mi=(e,t)=>{const n=t.toPrecision(12),r=xi.get(e),i=r==null?void 0:r.get(n);if(i)return i;const s=jc(e,t);return r?r.set(n,s):xi.set(e,new Map([[n,s]])),s},Pi=(e,t,n,r)=>{const i=`${t.map(d=>d.toPrecision(12)).join(",")}:${n.map(d=>d.toPrecision(12)).join(",")}:${r.toPrecision(12)}`,s=$i.get(e),a=s==null?void 0:s.get(i);if(a)return a;const o=[];for(const d of e.triangles){if(d.skipReason)continue;const u=d.vertexIds.map(g=>ue(ve(e.vertices[g],t),n)),p=Math.min(...u),m=Math.max(...u);p<=r&&m>=-r&&o.push(d.sourceIndex)}return s?s.set(i,o):$i.set(e,new Map([[i,o]])),o},Hc=(e,t)=>{let n=0,r=e.length;for(;n<r;){const i=Math.floor((n+r)/2);e[i]<t?n=i+1:r=i}return n},Uc=(e,t)=>{let n=0,r=e.length;for(;n<r;){const i=Math.floor((n+r)/2);e[i]<=t?n=i+1:r=i}return n},Vc=(e,t,n,r)=>{const i=n.map((o,d)=>({index:d,offset:o})).sort((o,d)=>o.offset-d.offset),s=i.map(o=>o.offset),a=Array.from({length:n.length},()=>[]);if(s.length===0)return a;for(const o of e.triangles){if(o.skipReason)continue;const d=o.vertexIds.map(C=>ue(e.vertices[C],t)),u=Math.min(...d),p=Math.max(...d),m=Hc(s,u-r),g=Uc(s,p+r);for(let C=m;C<g;C+=1)a[i[C].index].push(o.sourceIndex)}return a},Ci=1e-6,Ii=1e-5,it=1e-9,Yc=(e,t,n)=>[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n],Si=()=>({min:[1/0,1/0],max:[-1/0,-1/0]}),Dt=(e,t)=>({min:[Math.min(e.min[0],t[0]),Math.min(e.min[1],t[1])],max:[Math.max(e.max[0],t[0]),Math.max(e.max[1],t[1])]}),Xc=(e,t)=>{const n=ve(e,t.origin);return[ue(n,t.xAxis),ue(n,t.yAxis)]},Kc=(e,t,n)=>Math.abs(e[0]-t[0])<n&&Math.abs(e[1]-t[1])<n&&Math.abs(e[2]-t[2])<n,Zc=e=>e.filter((t,n)=>e.findIndex(r=>r.key===t.key)===n),qc=(e,t,n)=>{const r=Fe(ve(e.b,e.a),ve(e.c,e.a)),i=Fe(t,r),s=ve(n[1].point,n[0].point);return ue(s,i)<0?[n[1],n[0]]:n},Ei=e=>({edgeIndex:e.edgeId,incidentEdgeIndices:e.incidentEdgeIds,key:e.key,kind:e.refKind,localVertexIndex:e.localVertexIndex,vertexIndex:e.vertexId}),Ai=(e,t)=>t==="cross"&&e.refKind==="edge"&&typeof e.edgeId=="number"?{edgeId:e.edgeId,pointId:e.vertexId}:{edgeId:void 0,pointId:e.vertexId},Jc=(e,t)=>e>t?1:e<-t?-1:0,Qc=(e,t,n=1e-9)=>Math.abs(e[0]-t[0])<=n&&Math.abs(e[1]-t[1])<=n&&Math.abs(e[2]-t[2])<=n,Kn=[[0,1],[1,2],[2,0]],el=e=>e===0?[0,2]:e===1?[0,1]:[1,2],st=(e,t,n,r)=>({edgeId:r,incidentEdgeIds:el(n).map(i=>t.edgeIds[i]),key:`v:${t.vertexIds[n]}`,localVertexIndex:n,point:e.vertices[t.vertexIds[n]],refKind:"vertex",vertexId:t.vertexIds[n]}),tl=(e,t,n,r)=>{const i=t.edgeIds[n];return{edgeId:i,key:`e:${i}`,point:r,refKind:"edge"}},zi=(e,t,n,r)=>st(e,t,n,t.edgeIds[r]),Fi=(e,t)=>{var n;return!((n=e.triangles[t])!=null&&n.skipReason)},Zn=(e,t,n)=>{const r=e.vertexIds.findIndex(i=>i!==t[0]&&i!==t[1]);return r>=0?n[r]:0},nl=(e,t,n,r,i)=>{const s=e.edges[t],a=s.triangleIds.filter(p=>Fi(e,p));if(a.filter(p=>i.has(p)).length>0)return!1;const d=new Set;for(const p of a){const m=r.get(p);if(!m)continue;const g=Zn(e.triangles[p],s.vertexIds,m);g!==0&&d.add(g)}const u=a.filter(p=>!i.has(p));if(d.has(1)&&d.has(-1)){const p=u.find(m=>{const g=r.get(m);return g?Zn(e.triangles[m],s.vertexIds,g)>0:!1});return n===(p??Math.min(...u))}return!1},rl=(e,t,n,r)=>{const i=e.edges[t],s=i.triangleIds.filter(d=>Fi(e,d));return s.filter(d=>r.has(d)).length>=2?!1:i.kind==="boundary"?!0:s.filter(d=>!r.has(d)).map(d=>{const u=n.get(d);return u?Zn(e.triangles[d],i.vertexIds,u):0}).filter(d=>d!==0).length>0},il=(e,t,n,r)=>{const i=[];for(let s=0;s<3;s+=1){const a=t.edgeIds[s];if(!rl(e,a,n,r))continue;const[o,d]=Kn[s];i.push({kind:"coplanarBoundary",points:[st(e,t,o,a),st(e,t,d,a)]})}return i.filter(s=>s.points[0].key!==s.points[1].key)},sl=(e,t,n,r,i,s,a)=>{const o=[e.a,e.b,e.c],d=r.get(n.sourceIndex),u=i.get(n.sourceIndex),p=[];if(!u||!d)return[];if(s.has(n.sourceIndex))return il(t,n,i,s);const m=[];for(let v=0;v<3;v+=1){const[z,M]=Kn[v];if(u[z]!==0||u[M]!==0)continue;const P=n.edgeIds[v];nl(t,P,n.sourceIndex,i,s)&&m.push({kind:"onPlaneEdge",points:[st(t,n,z,P),st(t,n,M,P)]})}if(m.length>0)return m;for(let v=0;v<3;v+=1){const[z,M]=Kn[v],P=u[z],A=u[M],R=P===0,G=A===0;if(!(R&&G)){if(R){p.push({...zi(t,n,z,v),side:A});continue}if(G){p.push({...zi(t,n,M,v),side:P});continue}if(P<0&&A>0||P>0&&A<0){const D=o[z],k=o[M],B=d[z],Y=d[M],j=B/(B-Y);p.push({...tl(t,n,v,Yc(D,k,j)),side:0})}}}const g=Zc(p);if(g.length<2)return[];if(g.length===2)return[{kind:"cross",points:[g[0],g[1]]}];const C=g.filter(v=>typeof v.vertexId!="number"),E=g.filter(v=>typeof v.vertexId=="number");if(C.length===2)return[{kind:"cross",points:[C[0],C[1]]}];const _=C.length===1?E.find(v=>{const z=E.find(M=>M!==v&&M.side===-v.side);return v.side!==0&&z}):void 0;return C.length===1&&_?[{kind:"cross",points:[_,C[0]]}]:[]},ol=(e,t)=>{const n=t[0]-e[0],r=t[1]-e[1];return n*n+r*r},Ti=(e,t)=>`${Math.floor(e[0]/t)},${Math.floor(e[1]/t)}`,al=(e,t,n,r)=>{if(e.endpointIndex===0){e.line.endpointKeys=[t,e.line.endpointKeys[1]],e.line.points2=[n,e.line.points2[1]],e.line.points3=[r,e.line.points3[1]];return}e.line.endpointKeys=[e.line.endpointKeys[0],t],e.line.points2=[e.line.points2[0],n],e.line.points3=[e.line.points3[0],r]},cl=(e,t)=>{if(e.length===0||t<=0)return{ambiguousEndpointCount:0,snappedEndpointCount:0,snapGroupCount:0};const n=[];for(const _ of e)n.push({endpointIndex:0,index:n.length,line:_,point2:_.points2[0],point3:_.points3[0]},{endpointIndex:1,index:n.length+1,line:_,point2:_.points2[1],point3:_.points3[1]});const r=Math.max(t,it),i=t*t,s=new Map,a=n.map((_,v)=>v),o=n.map(()=>0),d=new Map;let u=0;const p=_=>{let v=_;for(;a[v]!==v;)v=a[v];for(;a[_]!==_;){const z=a[_];a[_]=v,_=z}return v},m=(_,v)=>{const z=p(_),M=p(v);if(z!==M){if(o[z]<o[M]){a[z]=M;return}if(o[z]>o[M]){a[M]=z;return}a[M]=z,o[z]+=1}};for(const _ of n){const[v,z]=Ti(_.point2,r).split(",").map(Number);for(let A=-1;A<=1;A+=1)for(let R=-1;R<=1;R+=1){const G=s.get(`${v+A},${z+R}`);if(G)for(const D of G){const k=n[D];if(k.line.id===_.line.id)continue;const B=ol(_.point2,k.point2);if(B>i)continue;const Y=d.get(_.index);!Y||B<Y.distanceSquared-it?d.set(_.index,{ambiguous:!1,distanceSquared:B,index:k.index}):Math.abs(B-Y.distanceSquared)<=it&&Y.index!==k.index&&d.set(_.index,{...Y,ambiguous:!0});const j=d.get(k.index);!j||B<j.distanceSquared-it?d.set(k.index,{ambiguous:!1,distanceSquared:B,index:_.index}):Math.abs(B-j.distanceSquared)<=it&&j.index!==_.index&&d.set(k.index,{...j,ambiguous:!0})}}const M=Ti(_.point2,r),P=s.get(M);P?P.push(_.index):s.set(M,[_.index])}for(const[_,v]of d){if(v.ambiguous){u+=1;continue}const z=d.get(v.index);!z||z.ambiguous||z.index!==_||m(_,v.index)}const g=new Map;for(const _ of n){const v=p(_.index),z=g.get(v);z?z.push(_):g.set(v,[_])}let C=0,E=0;for(const _ of g.values()){if(_.length<2)continue;const v=[_.reduce((P,A)=>P+A.point2[0],0)/_.length,_.reduce((P,A)=>P+A.point2[1],0)/_.length],z=[_.reduce((P,A)=>P+A.point3[0],0)/_.length,_.reduce((P,A)=>P+A.point3[1],0)/_.length,_.reduce((P,A)=>P+A.point3[2],0)/_.length],M=`snap:${C}`;for(const P of _)al(P,M,v,z),E+=1;C+=1}return{ambiguousEndpointCount:u,snappedEndpointCount:E,snapGroupCount:C}},ll=e=>e.length===0?{min:[0,0],max:[0,0]}:e.reduce((t,n)=>Dt(Dt(t,n.points2[0]),n.points2[1]),Si()),qn=(e,t,n,r,i,s,a,o,d)=>{const u=[],p=[],m=new Map,g=new Map,C=new Map,E=D=>{const k=g.get(D);if(k)return k;const B=e.triangles[D],j=[B.a,B.b,B.c].map(X=>ue(ve(X,n.origin),r.normal));return g.set(D,j),j},_=D=>{const k=C.get(D);if(k)return k;const B=E(D).map(Y=>Jc(Y,s));return C.set(D,B),B},v=new Set;let z=0,M=0,P=0,A=Si(),R={ambiguousEndpointCount:0,snappedEndpointCount:0,snapGroupCount:0};for(const D of i){const k=t.triangles[D];k.skipReason||_(k.sourceIndex).every(B=>B===0)&&v.add(k.sourceIndex)}const G=D=>{const k=m.get(D.key);if(k)return k;const B={point2:Xc(D.point,r),point3:D.point};return m.set(D.key,B),B};for(const D of i){const k=e.triangles[D],B=t.triangles[D];if(B.skipReason){P+=1;continue}const Y=sl(k,t,B,g,C,v);v.has(D)?z+=Y.length:Y.some(j=>j.kind==="onPlaneEdge")&&(M+=Y.length);for(const j of Y){const[X,re]=qc(k,r.normal,j.points),ce=G(X),he=G(re);if(Kc(ce.point3,he.point3,s))continue;const le=[ce.point2,he.point2],Q=[ce.point3,he.point3],J=[X.key,re.key],te=[Ei(X),Ei(re)],_e=Ai(X,j.kind),we=Ai(re,j.kind);A=Dt(Dt(A,le[0]),le[1]),p.push({aId:_e.pointId,bId:we.pointId,edgeAId:_e.edgeId,edgeBId:we.edgeId,edgeType:j.kind,id:p.length,points2:le,points3:Q,endpointKeys:J,endpointRefs:te,edgeIndex:X.edgeId??re.edgeId,intersector:"plane",kind:j.kind,noSeed:j.kind!=="cross",skip:!1,triangleEdgeIndices:B.edgeIds,triangleIndex:D,triangleVertexIndices:B.vertexIds}),o&&u.push({id:`segment-${u.length}`,points2:le,points3:Q,closed:!1,role:"unknown",source:{edgeIndex:X.edgeId??re.edgeId,endpointKeys:J,endpointRefs:te,intersector:"plane",kind:j.kind,triangleEdgeIndices:B.edgeIds,triangleIndex:D,triangleVertexIndices:B.vertexIds}})}}return o?p.length===0&&(A={min:[0,0],max:[0,0]}):(R=cl(p,a),A=ll(p)),{id:`${e.id}:plane:${n.origin.join(",")}:${n.normal.join(",")}`,spec:n,frame:r,curves:[],intersectionLines:p,openCurves:u,rawCurves:o?u:void 0,bounds:A,diagnostics:d?[{level:p.length>0?"info":"warning",message:`${p.length} section segments generated from ${t.diagnostics.sharedVertexCount} shared mesh vertices.`},{level:t.diagnostics.nonManifoldEdgeCount>0||t.diagnostics.boundaryEdgeCount>0?"warning":"info",message:`${t.diagnostics.manifoldEdgeCount} manifold edges, ${t.diagnostics.boundaryEdgeCount} boundary edges, and ${t.diagnostics.nonManifoldEdgeCount} non-manifold edges classified.`},...P>0?[{level:"info",message:`${t.diagnostics.degenerateTriangleCount} degenerate triangles and ${t.diagnostics.duplicateTriangleCount} duplicate triangles skipped by mesh topology normalization.`}]:[],...v.size>0||z>0||M>0?[{level:"info",message:`${v.size} coplanar triangles produced ${z} boundary segments; ${M} on-plane vertex/edge segments emitted.`}]:[],...R.snapGroupCount>0||R.ambiguousEndpointCount>0?[{level:"info",message:`${R.snappedEndpointCount} section endpoints snapped into ${R.snapGroupCount} groups; ${R.ambiguousEndpointCount} ambiguous snap candidates ignored.`}]:[]]:[]}},ki=(e,t,n,r,i,s)=>({kind:"plane",intersect:a=>{const o=yi(a),d=Pi(t,o.origin,o.normal,n);return qn(e,t,a,o,d,n,r,i,s)},intersectStack:a=>{if(a.length===0)return[];const o=a.map(yi),d=o[0].normal;if(!o.every(g=>Qc(g.normal,d)))return a.map((g,C)=>{const E=Pi(t,o[C].origin,o[C].normal,n);return qn(e,t,g,o[C],E,n,r,i,s)});const p=o.map(g=>ue(g.origin,d)),m=Vc(t,d,p,n);return a.map((g,C)=>qn(e,t,g,o[C],m[C],n,r,i,s))}}),dl=(e,t,n={})=>{const r=n.intersectionEpsilon??Ci,i=n.topologyEpsilon??Ii,s=Mi(e,Math.max(r,i)),a=n.connect===!1?0:n.closingRadius??On;return ki(e,s,r,a,n.connect===!1,n.diagnostics!=="none").intersect(t)},Wt=(e,t,n={})=>{if(t.length===0)return[];const r=n.intersectionEpsilon??Ci,i=n.topologyEpsilon??Ii,s=Mi(e,Math.max(r,i)),a=n.connect===!1?0:n.closingRadius??On;return ki(e,s,r,a,n.connect===!1,n.diagnostics!=="none").intersectStack(t)},ul=(e,t,n={})=>{if(t.kind==="plane")return dl(e,t,n);throw new Error(`Section intersector is not implemented for ${t.kind} sections yet.`)},Li=(e,t)=>{const n=t.x-e.x,r=t.y-e.y,i=t.z-e.z;return Math.sqrt(n*n+r*r+i*i)},fl=e=>{let t=0;for(let n=1;n<e.points.length;n+=1)t+=Li(e.points[n-1],e.points[n]);return e.closed&&e.points.length>2&&(t+=Li(e.points[e.points.length-1],e.points[0])),t},hl=e=>{var s;let t=0,n=0,r=0,i=0;for(const a of e.layers)for(const o of a.paths){i+=1;const d=fl(o);o.role==="travel"?t+=d:(n+=d,r+=d*(((s=o.extrusion)==null?void 0:s.flow)??.045))}return{layerCount:e.layers.length,pathCount:i,travelDistanceMm:t,extrusionDistanceMm:n,estimatedExtrusionMm:r}},pl=1e-6,ml=1e-5,ot=(e,t={})=>{const n=t.areaEpsilon??pl,r=t.distanceEpsilon??ml;return e.flatMap(i=>{const s=Ct(i,r);return s.length<3||Math.abs(ae(s))<=n?[]:[s]})},at=(e,t,n,r={})=>{const i=ot(e,r),s=ot(t,r);if(i.length===0)return[];if(s.length===0&&n==="difference"||s.length===0&&n==="union")return i;if(s.length===0)return[];const a=Pt(),o=We(a,i),d=We(a,s);let u;try{const p=n==="difference"?a.ClipType.Difference:n==="intersection"?a.ClipType.Intersection:n==="union"?a.ClipType.Union:a.ClipType.Xor;return u=a.BooleanOp64(p,a.FillRule.NonZero,o.paths,d.paths),ot(An(u),r)}finally{u==null||u.delete(),d.release(),o.release()}},Ri=(e,t={})=>{const n=ot(e,t);if(n.length===0)return[];const r=Pt(),i=We(r,n);let s;try{return s=r.UnionSelf64(i.paths,r.FillRule.NonZero),ot(An(s),t)}finally{s==null||s.delete(),i.release()}},Jn=(e,t)=>[e.frame.origin[0]+e.frame.xAxis[0]*t[0]+e.frame.yAxis[0]*t[1],e.frame.origin[1]+e.frame.xAxis[1]*t[0]+e.frame.yAxis[1]*t[1],e.frame.origin[2]+e.frame.xAxis[2]*t[0]+e.frame.yAxis[2]*t[1]],Ot=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Ni=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],ct=(e,t,n=1e-8)=>Math.abs(e-t)<=n,Di=(e,t,n=1e-8)=>ct(e[0],t[0],n)&&ct(e[1],t[1],n)&&ct(e[2],t[2],n),gl=(e,t)=>{if(!Di(e.frame.xAxis,t.frame.xAxis)||!Di(e.frame.yAxis,t.frame.yAxis))return!1;const n=Ni(t.frame.origin,e.frame.origin);return ct(Ot(n,e.frame.xAxis),0)&&ct(Ot(n,e.frame.yAxis),0)},Wi=(e,t)=>{const n=Ni(t,e.frame.origin);return[Ot(n,e.frame.xAxis),Ot(n,e.frame.yAxis)]},yl=e=>e.curves.flatMap(t=>t.role==="invalid"||t.role==="open"||t.points2.length<3?[]:[t.points2]),Qn=e=>e.curves.flatMap(t=>t.role==="invalid"||t.role==="open"||t.points2.length<3?[]:[{points:t.points2,role:t.role}]),bl=(e,t)=>Qn(Oi(e,t,"role-source")),Oi=(e,t,n)=>{const r=t.map((a,o)=>({id:`${e.id}-${n}-${o}`,points2:[...a],points3:a.map(d=>Jn(e,d)),closed:!0,role:"unknown"})),i=kt(e,r).map(a=>Gi(e,a)),s=i.flatMap(a=>a.points2);return{...e,id:`${e.id}-${n}`,curves:i,openCurves:[],rawCurves:void 0,intersectionLines:void 0,bounds:s.length>0?Oe(s):{min:[0,0],max:[0,0]}}},Bi=e=>Oe(e.flatMap(t=>[...t])),Bt=(e,t)=>({bounds:e.bounds,diagnostics:e.diagnostics,frame:e.frame,id:`${e.id}-${t}`,rings:yl(e),source:e}),vl=(e,t,n={})=>{const r={origin:[0,0,e],xAxis:[1,0,0],yAxis:[0,1,0],normal:[0,0,1]},i=t.map((d,u)=>({id:`${n.id??"path-region"}-${u}`,points2:[...d],points3:d.map(([p,m])=>[p,m,e]),closed:!0,role:"unknown"})),s={id:n.id??`path-region-${e.toFixed(3)}`,spec:{kind:"plane",origin:r.origin,normal:r.normal,xAxis:r.xAxis},frame:r,curves:[],openCurves:[],bounds:Bi(t),diagnostics:[]},a=kt(s,i).map(d=>Gi(s,d)),o=a.flatMap(d=>d.points2);return{...s,curves:a,bounds:o.length>0?Oe(o):s.bounds}},Gt=(e,t)=>{const n=[...e];if(n.length<3)return n;const r=!t,i=ae(n)>=0;return r===i?n:n.reverse()},Gi=(e,t)=>{if(t.role==="invalid"||t.role==="open"||t.points2.length<3)return t;const n=t.role!=="hole",r=ae(t.points2)>=0,i=n===r?[...t.points2]:[...t.points2].reverse();return{...t,area:ae(i),points2:i,points3:i.map(s=>Jn(e,s)),winding:ae(i)>=0?"ccw":"cw"}},$e=(e,t={})=>{const n=[];let r;const i=()=>{r=void 0},s=()=>(r??(r=Bt(vl(e,n,t),"region")),r),a={get bounds(){return s().bounds},get frame(){return s().frame},get id(){return s().id},get rings(){return s().rings},get source(){return s().source},circle:(o,d,u={})=>{const p=Math.max(8,Math.round(u.segments??64)),m=Array.from({length:p},(g,C)=>{const E=C/p*Math.PI*2;return[o[0]+Math.cos(E)*d,o[1]+Math.sin(E)*d]});return n.push(Gt(m,u.hole)),i(),a},fill:o=>Le(s(),o),hole:o=>(n.push(Gt(o,!0)),i(),a),inset:o=>{const d=s();if(o<=0)return d;const u=Et(Qn(d.source),o);return lt(d,u.ok?u.rings:[],`inset-${o.toFixed(3)}`,u.warnings.map(p=>({level:"info",message:`Offset region: ${p}.`})))},polygon:(o,d={})=>(n.push(Gt(o,d.hole)),i(),a),ring:(o,d={})=>(n.push(Gt(o,d.hole)),i(),a),toRegion:s,toSection:()=>s().source};return a},lt=(e,t,n,r=[])=>{const i="source"in e?e.source:e,s=t.map(a=>[...a]);return{bounds:Bi(s),diagnostics:r,frame:e.frame,id:`${e.id}-${n}`,rings:s,source:i}},dt=(e,t)=>({...Oi(e.source,e.rings,`${e.id}-${t}`),diagnostics:[...e.source.diagnostics,...e.diagnostics]}),jt=e=>{let t;return()=>(t??(t=e()),t)},xl=(e,t)=>{const n=jt(()=>dt(e.bottom,"section")),r=jt(()=>dt(e.sparse,"section")),i=jt(()=>dt(e.top,"section")),s=jt(()=>dt(t,"section"));return{get bottom(){return n()},get inset(){return s()},get sparse(){return r()},get top(){return i()}}},$l=(e,t)=>gl(e.source,t.source)?t.rings:t.rings.map(n=>n.map(r=>Wi(e.source,Jn(t.source,r)))),er=(e,t)=>{const n=Math.cos(t),r=Math.sin(t);return[e[0]*n-e[1]*r,e[0]*r+e[1]*n]},ji=(e,t)=>er(e,-t),_l=(e,t)=>{let n=1/0,r=1/0,i=-1/0,s=-1/0;for(const a of e)for(const o of a){const d=er(o,t);n=Math.min(n,d[0]),r=Math.min(r,d[1]),i=Math.max(i,d[0]),s=Math.max(s,d[1])}return Number.isFinite(n)?{min:[n,r],max:[i,s]}:{min:[0,0],max:[0,0]}},Ht=(e,t)=>{const n=Math.max(0,Math.min(1,e));return n<=0?1/0:n>=1?t:Math.max(t,t/n)},wl=(e,t,n,r,i=0)=>{const s=t-e,a=(e+t)/2;if(r!==void 0&&Number.isFinite(r)){const p=Math.floor((e-r-i)/n),m=Math.ceil((t-r-i)/n);return Array.from({length:Math.max(1,m-p+1)},(g,C)=>r+i+(p+C)*n)}if(s<=0)return[a];const o=Math.max(1,Math.ceil(s/n)),d=(o-1)*n,u=a-d/2;return Array.from({length:o},(p,m)=>u+m*n)},Ml=(e,t)=>{const n=(t==null?void 0:t.anchor)??"build",r=t==null?void 0:t.origin;if(n==="section")return[typeof(r==null?void 0:r[0])=="number"?r[0]:0,typeof(r==null?void 0:r[1])=="number"?r[1]:0];const i=[typeof(r==null?void 0:r[0])=="number"?r[0]:0,typeof(r==null?void 0:r[1])=="number"?r[1]:0,typeof(r==null?void 0:r[2])=="number"?r[2]:0];return Wi(e,i)},Pl=(e,t,n)=>{if((t==null?void 0:t.anchor)!=="regionCenter")return er(Ml(e,t),n)[1]},Ge=(e,t)=>Math.hypot(t[0]-e[0],t[1]-e[1]),Cl=(e,t,n=1e-7)=>Ge(e,t)<=n,Hi=e=>Ge(e.start,e.end),Il=(e,t,n)=>{const r=n[0]-t[0],i=n[1]-t[1],s=r*r+i*i,a=s<=0?0:Math.max(0,Math.min(1,((e[0]-t[0])*r+(e[1]-t[1])*i)/s)),o=[t[0]+r*a,t[1]+i*a];return Ge(e,o)},Sl=(e,t,n=1e-5)=>{for(const r of t)if(!(r.length<2)){for(let i=0;i<r.length;i+=1)if(Il(e,r[i],r[(i+1)%r.length])<=n)return!0}return!1},El=(e,t)=>Sl(e,t)?!0:t.filter(n=>n.length>=3&&At(e,n)).length%2===1,Al=(e,t,n)=>{for(let r=1;r<10;r+=1){const i=r/10,s=[e[0]+(t[0]-e[0])*i,e[1]+(t[1]-e[1])*i];if(!El(s,n))return!1}return!0},zl=(e,t,n)=>{const r={start:e,end:t},i=Hi(r);return i<=1e-7?!0:Ft([r],n,()=>!0,{minLength:1e-6}).reduce((a,o)=>a+Hi(o),0)>=i-1e-5||Al(e,t,n)},Ui=new WeakMap,Vi=new WeakMap,Fl=e=>e.toFixed(6),je=(e,t)=>{let n=Ui.get(e);n||(n=new Map,Ui.set(e,n));const r=Fl(t),i=n.get(r);if(i)return i;if(t<=0){const u=Bt(e,"fill-region");return n.set(r,u),u}const s=[],a=Et(Qn(e),t);for(const u of a.warnings)s.push({level:"info",message:`Offset region: ${u}.`});a.ok||s.push({level:"warning",message:`Offset region discarded: ${a.reason}.`});const o=a.ok?a.rings:[],d=lt(e,o,"fill-inset",[...s,{level:o.length>0?"info":"warning",message:`Inset region by ${t.toFixed(3)} mm: ${o.length} region curves remain from ${e.curves.length} source curves.`}]);return n.set(r,d),d},Yi=(e,t,n,r,i,s)=>{const a=Math.max(1,Math.round(i));let o=null;for(let d=1;d<=a;d+=1){const u=e[t+r*d];if(!u)return[];const p=je(u,s),m=$l(n,p);if(m.length===0)return[];if(o=o===null?Ri(m):at(o,m,"intersection"),o.length===0)return[]}return o??[]},Tl=(e,t,n,r,i)=>{const s=n.rings,a=Yi(e,t,n,-1,r,i),o=Yi(e,t,n,1,r,i),d=at(s,a,"difference"),u=at(s,o,"difference"),p=at(u,d,"difference"),m=Ri([...d,...p]),g=at(s,m,"difference");return{bottom:lt(n,d,"bottom-region"),sparse:lt(n,g,"sparse-region"),top:lt(n,p,"top-region")}},Ut=(e,t,n,r,i)=>{let s=Vi.get(n);s||(s=new Map,Vi.set(n,s));const a=`${t}:${Math.max(1,Math.round(r))}`,o=s.get(a);if(o)return o;const d=Tl(e,t,n,r,i);return s.set(a,d),d},kl=(e,t,n)=>Dl(e,t,Ll(e,t,n)),Ll=(e,t,n)=>tr(e,t,n),tr=(e,t,n)=>{var m;const r=t.spacing??Ht(t.density??.18,t.lineWidth);if(!Number.isFinite(r)||r<=0)return[];const i=(t.angle??0)*Math.PI/180,s=_l(n.rings,i),a=s.min[0]-t.lineWidth,o=s.max[0]+t.lineWidth,d=n.rings,u=Pl(e,t.field,i);return wl(s.min[1],s.max[1],r,u,((m=t.field)==null?void 0:m.phase)??0).map(g=>({start:ji([a,g],i),end:ji([o,g],i)})).flatMap((g,C)=>Ft([g],d,()=>!0,{minLength:Math.max(t.lineWidth*.25,.001)}).map(E=>({...E,scanIndex:C})))},Rl=e=>e.lineWidth*e.layerHeight*(e.role&&e.role!=="infill"?.42:.35),Nl=e=>e.role&&e.role!=="infill"?2600:3200,nr=(e,t,n,r,i,s=!1)=>({id:`${t.idPrefix??`layer-${t.layerIndex}-${t.role??"infill"}${i?`-${i}`:""}`}-${r}`,role:t.role??"infill",order:s?r:void 0,layerIndex:t.layerIndex,z:e.frame.origin[2],closed:!1,points:n.map(([a,o])=>({x:a,y:o,z:0})),extrusion:{width:t.lineWidth,height:t.layerHeight,flow:Rl(t)},speed:Nl(t)}),Dl=(e,t,n,r)=>n.map((i,s)=>nr(e,t,[i.start,i.end],s,r)),Xi=e=>{const t=e*Math.PI/180;return[Math.cos(t),Math.sin(t)]},Vt=(e,t)=>e[0]*t[0]+e[1]*t[1],Wl=(e,t)=>{const n=Xi(t),r=e.map(s=>{const a=Vt(s.start,n);return{endT:Vt(s.end,n),scanIndex:s.scanIndex,segment:s,startT:a}}).sort((s,a)=>s.scanIndex-a.scanIndex||Math.min(s.startT,s.endT)-Math.min(a.startT,a.endT)),i=[];for(const s of r){const a=i[i.length-1];a&&a[0].scanIndex===s.scanIndex?a.push(s):i.push([s])}return i.map(s=>[...s].sort((a,o)=>Math.min(a.startT,a.endT)-Math.min(o.startT,o.endT)))},Ol=(e,t)=>t?{start:e.end,end:e.start}:{start:e.start,end:e.end},Ki=(e,t)=>{const n=Xi(t),r=[];let i;for(const s of Wl(e,t)){const a=[...s];for(;a.length>0;){let o=0,d=!1,u=Number.POSITIVE_INFINITY;for(let g=0;g<a.length;g+=1){const{segment:C}=a[g],E=i?[{distance:Ge(i,C.start),startAtEnd:!1},{distance:Ge(i,C.end),startAtEnd:!0}]:[{distance:Vt(C.start,n),startAtEnd:!1},{distance:Vt(C.end,n),startAtEnd:!0}],_=E[0].distance<=E[1].distance?E[0]:E[1];_.distance<u&&(u=_.distance,o=g,d=_.startAtEnd)}const[p]=a.splice(o,1),m=Ol(p.segment,d);r.push(m),i=m.end}}return r},Bl=(e,t,n)=>Ki(tr(e,t,n),t.angle??0).map((r,i)=>nr(e,t,[r.start,r.end],i,"monotonic-line",!0)),Zi=(e,t,n)=>{const r=t.spacing??Ht(t.density??.18,t.lineWidth),i=(Number.isFinite(r)?r:t.lineWidth)*2.5+t.lineWidth,s=Ki(tr(e,t,n),t.angle??0),a=[];let o=[];const d=()=>{o.length>=2&&a.push(nr(e,t,o,a.length,"monotonic",!0)),o=[]};for(const u of s){if(o.length===0){o=[u.start,u.end];continue}const p=o[o.length-1];Ge(p,u.start)<=i&&zl(p,u.start,n.rings)?(Cl(p,u.start)||o.push(u.start),o.push(u.end)):(d(),o=[u.start,u.end])}return d(),a},Gl=(e,t,n)=>{const r=t.spacing??Ht(t.density??.18,t.lineWidth);if(!Number.isFinite(r)||r<=0)return[];const i=[];let s=n.rings,a=0;const o=1e3;for(;s.length>0&&a<o;){for(const u of s)u.length<3||i.push({id:`${t.idPrefix??`layer-${t.layerIndex}-${t.role??"infill"}-concentric`}-${a}-${i.length}`,role:t.role??"infill",layerIndex:t.layerIndex,z:e.frame.origin[2],closed:!0,points:u.map(([p,m])=>({x:p,y:m,z:0})),extrusion:{width:t.lineWidth,height:t.layerHeight,flow:t.lineWidth*t.layerHeight*(t.role&&t.role!=="infill"?.42:.35)},speed:t.role&&t.role!=="infill"?2600:3200});const d=Et(bl(e,s),r);s=d.ok?d.rings:[],a+=1}return i},Ie=(e,t,n)=>{const r=t.pattern??(t.role==="bottom"?"monotonic":t.role==="solidInfill"||t.role==="top"?"monotonicLine":"rectilinear");if(r==="concentric")return Gl(e,t,n);if(r==="monotonic")return Zi(e,t,n);if(r==="monotonicLine")return Bl(e,t,n);const i=t.angle??(r==="rectilinear"?45:0);if(r==="rectilinear")return Zi(e,{...t,angle:i+(t.layerIndex%2===0?0:90)},n);const s=r==="grid"?[0,90]:r==="triangles"?[0,60,120]:[0],a=t.spacing??Ht(t.density??.18,t.lineWidth);return!Number.isFinite(a)||a<=0?[]:s.flatMap((o,d)=>kl(e,{...t,angle:i+o,idPrefix:`${t.idPrefix??`layer-${t.layerIndex}-${t.role??"infill"}-${r}`}-${d}`,spacing:a},n))},jl=e=>typeof e=="object"&&e!==null&&"toRegion"in e&&typeof e.toRegion=="function",Hl=e=>typeof e=="object"&&e!==null&&"rings"in e&&"source"in e&&"frame"in e,qi=e=>jl(e)?e.toRegion():Hl(e)?e:"section"in e?Bt(e.section,"fill-region"):Bt(e,"fill-region"),Le=(e,t)=>{const n=qi(e);return Ie(n.source,{angle:t.angle,density:t.density??1,field:t.field,layerHeight:t.layerHeight??.2,layerIndex:t.layerIndex??0,lineWidth:t.lineWidth??.44,pattern:t.pattern,role:t.role??"infill",spacing:t.spacing},n)},ut=(e,t)=>{if(t)for(const n of e.diagnostics)t(n.message,n.level)},Ul=(e,t)=>{const n=je(e,t.margin??0);return ut(n,t.onDiagnostic),Ie(e,t,n)},Yt=(e,t,n)=>{const r=e.map((i,s)=>dt(qi(i),`region-layer-${s}`));return Ji(r,t,n)},Vl=(e,t,n)=>{const r=e[t];if(!r)return[];const i=n.solidLayers??3,s=n.margin??0,a=je(r,s);ut(a,n.onDiagnostic);const o=Ut(e,t,a,i,s);return Ie(r,n,o.sparse)},Ji=(e,t,n)=>{const r=e[t];if(!r)throw new Error(`fillLayer layerIndex is out of range: ${t}`);const i=n.solidLayers??3,s=n.layerIndex??t,a=n.margin??0,o=je(r,a);ut(o,n.onDiagnostic);const d=Ut(e,t,o,i,a),u=Ie(r,{angle:n.bottomAngle??45,field:n.field,layerHeight:n.layerHeight,layerIndex:s,lineWidth:n.lineWidth,margin:n.margin,role:"bottom",spacing:n.lineWidth,pattern:n.bottomPattern??n.pattern},d.bottom),p=Ie(r,{angle:n.topAngle??-45,field:n.field,layerHeight:n.layerHeight,layerIndex:s,lineWidth:n.lineWidth,margin:n.margin,role:"top",spacing:n.lineWidth,pattern:n.topPattern??n.pattern},d.top),m=Ie(r,{angle:n.sparseAngle,density:n.density??.18,field:n.field,layerHeight:n.layerHeight,layerIndex:s,lineWidth:n.lineWidth,margin:n.margin,role:"infill",pattern:n.sparsePattern??n.pattern,spacing:n.sparseSpacing},d.sparse);return{bottom:u,get paths(){return[...u,...p,...m]},regions:xl(d,o),sparse:m,top:p}},Yl=(e,t,n)=>{const r=e[t];if(!r)return[];const i=n.solidLayers??3,s=n.margin??0,a=je(r,s);ut(a,n.onDiagnostic);const o=Ut(e,t,a,i,s);return Ie(r,{angle:n.angle??45,field:n.field,layerHeight:n.layerHeight,layerIndex:n.layerIndex??t,lineWidth:n.lineWidth,margin:n.margin,pattern:n.pattern,role:"bottom",spacing:n.lineWidth},o.bottom)},Xl=(e,t,n)=>{const r=e[t];if(!r)return[];const i=n.solidLayers??3,s=n.margin??0,a=je(r,s);ut(a,n.onDiagnostic);const o=Ut(e,t,a,i,s);return Ie(r,{angle:n.angle??-45,field:n.field,layerHeight:n.layerHeight,layerIndex:n.layerIndex??t,lineWidth:n.lineWidth,margin:n.margin,pattern:n.pattern,role:"top",spacing:n.lineWidth},o.top)},Kl=["outerWall","innerWall","bottom","top","solidInfill","infill","support"],Qi=e=>Array.isArray(e)?e.flatMap(t=>Qi(t)):[e],Xt=e=>e.points[0],Zl=e=>e.closed?e.points[0]:e.points[e.points.length-1],Kt=(e,t)=>{const n=t.x-e.x,r=t.y-e.y,i=t.z-e.z;return n*n+r*r+i*i},ql=(e,t)=>{const n=new Set(e.map(i=>i.role)),r=t.filter(i=>n.has(i));for(const i of e)r.includes(i.role)||r.push(i.role);return r},Jl=(e,t)=>{if(!t)return e.shift();let n=0,r=Number.POSITIVE_INFINITY;for(let i=0;i<e.length;i+=1){const s=Xt(e[i]);if(!s)continue;const a=Kt(t,s);a<r&&(r=a,n=i)}return e.splice(n,1)[0]},Ql=e=>e.some(t=>Number.isFinite(t.order)),ed=e=>({...e,points:[...e.points].reverse()}),td=(e,t)=>{const n=[...e].sort((a,o)=>{const d=Number.isFinite(a.order)?a.order:Number.POSITIVE_INFINITY,u=Number.isFinite(o.order)?o.order:Number.POSITIVE_INFINITY;return d-u});if(!t||n.length===0)return n;const r=n.map(ed).reverse(),i=Xt(n[0]),s=Xt(r[0]);return!i||!s?n:Kt(t,s)<Kt(t,i)?r:n},es=(e,t,n,r,i,s)=>{const a=Xt(t);let o=r;return i&&n&&a&&Kt(n,a)>0&&(e.push(nd(n,a,o,s)),o+=1),e.push(t),{currentPoint:Zl(t),travelIndex:o}},nd=(e,t,n,r)=>({id:`layer-0-travel-${n}`,role:"travel",layerIndex:0,z:e.z,closed:!1,points:[{...e},{...t}],speed:r}),Zt=(e,t={})=>{const n=Qi(e).filter(u=>u.points.length>0),r=t.roleOrder??Kl,i=t.travel??!0,s=t.travelSpeed??7200,a=[];let o,d=0;for(const u of ql(n,r)){const p=n.filter(g=>g.role===u);if(Ql(p)){for(const g of td(p,o)){const C=es(a,g,o,d,i,s);o=C.currentPoint,d=C.travelIndex}continue}for(;p.length>0;){const g=Jl(p,o);if(!g)break;const C=es(a,g,o,d,i,s);o=C.currentPoint,d=C.travelIndex}}return a},Se=[[0,0],[20,0],[20,10],[0,10]],qt=[[6,3],[14,3],[14,7],[6,7]],ts=[...qt].reverse(),oe=(e,t)=>e?[]:[{level:"error",message:t}],rd=e=>e.x>6.001&&e.x<13.999&&e.y>3.001&&e.y<6.999,id=e=>{if(e.points.length<2)return!1;const t=e.closed?e.points.length:e.points.length-1;for(let n=0;n<t;n+=1){const r=e.points[n],i=e.points[(n+1)%e.points.length];for(let s=1;s<10;s+=1){const a=s/10,o={x:r.x+(i.x-r.x)*a,y:r.y+(i.y-r.y)*a};if(rd(o))return!0}}return!1},sd=(e,t)=>e.filter(n=>n.points.length>=2&&n.points.every(r=>Math.abs(r.y-t)<1e-6)).length,ft=(e,t)=>{const n=[],r=["lines","rectilinear","monotonicLine","monotonic","grid","triangles","concentric"];for(const i of r){const s=Le(t(),{field:{anchor:"build",origin:[0,0,0]},layerHeight:.2,lineWidth:.4,pattern:i,spacing:1});n.push(...oe(s.length>0,`${e}: expected ${i} fill paths.`)),n.push(...oe(!s.some(id),`${e}: expected ${i} fill to avoid the hole.`)),i==="lines"&&n.push(...oe(sd(s,5)===2,`${e}: expected line fill through the hole to split into two segments.`))}return n},od=()=>{var d,u;const e=$e(0).polygon(Se),t=Le(e,{layerHeight:.2,lineWidth:.4,pattern:"monotonic",role:"bottom",spacing:1}),n=Le(e,{layerHeight:.2,lineWidth:.4,pattern:"monotonicLine",role:"bottom",spacing:1}),r=Zt([n],{roleOrder:["bottom"],travel:!1}),i=Zt([t],{roleOrder:["bottom"],travel:!1}),s=n[n.length-1],a=s==null?void 0:s.points[s.points.length-1],o=a?Zt([{id:"seed-inner-wall",role:"innerWall",layerIndex:0,z:0,closed:!1,points:[{x:-100,y:-100,z:0},{...a}],speed:1200},n],{roleOrder:["innerWall","bottom"],travel:!1}).filter(p=>p.role==="bottom"):[];return[...oe(t.length===1,"Monotonic bottom fill should connect a simple solid region into one stroke."),...oe(t.every((p,m)=>{var g;return((g=i[m])==null?void 0:g.id)===p.id}),"Monotonic bottom fill planning should preserve scanline path order."),...oe(t.length!==1||t[0].points.length<4||Math.abs(t[0].points[1].x-t[0].points[2].x)<1e-6,"Monotonic bottom fill should snake through adjacent scan lines instead of restarting from the opposite side."),...oe(n.length>t.length,"Monotonic line fill should keep scan lines as separate strokes."),...oe(n.every((p,m)=>{var g;return((g=r[m])==null?void 0:g.id)===p.id}),"Monotonic line fill planning should preserve corner-to-corner scanline order."),...oe(((d=o[0])==null?void 0:d.id)===((u=n[n.length-1])==null?void 0:u.id),"Monotonic line fill planning should be reversible to start from the nearest corner.")]},ad=()=>{const e=$e(0).polygon(Se),t=Le(e,{angle:45,layerHeight:.2,layerIndex:0,lineWidth:.4,pattern:"rectilinear",role:"infill",spacing:1}),n=Le(e,{angle:45,layerHeight:.2,layerIndex:1,lineWidth:.4,pattern:"rectilinear",role:"infill",spacing:1}),r=s=>{const a=s.points[0],o=s.points[1];return Math.atan2(o.y-a.y,o.x-a.x)},i=t.length>0&&n.length>0;return[...oe(i,"Rectilinear fill should generate paths on adjacent layers."),...oe(!i||Math.abs(Math.sin(r(t[0])-r(n[0])))>.9,"Rectilinear fill should rotate 90 degrees across adjacent layers.")]},cd=()=>[...ft("Direct path .hole() is winding-independent",()=>$e(0).polygon(Se).hole(qt)),...ft("Direct path reversed .hole() is winding-independent",()=>$e(0).polygon(Se).hole(ts)),...ft("Direct path { hole: true } is winding-independent",()=>$e(0).polygon(Se).polygon(qt,{hole:!0})),...ft("Direct path reversed { hole: true } is winding-independent",()=>$e(0).polygon(Se).polygon(ts,{hole:!0})),...ft("Direct path nested rings classify implicit holes",()=>$e(0).polygon(Se).polygon(qt)),...od(),...ad(),...(()=>{const e=Array.from({length:7},(i,s)=>$e(s*.2).polygon(Se)),t=Yt(e,0,{layerHeight:.2,lineWidth:.4,solidLayers:2}),n=Yt(e,3,{density:.2,layerHeight:.2,lineWidth:.4,solidLayers:2}),r=Yt(e,6,{layerHeight:.2,lineWidth:.4,solidLayers:2});return[...oe(t.bottom.length>0&&t.top.length===0,"Direct path region layer fill should classify bottom solid layers."),...oe(n.sparse.length>0&&n.bottom.length===0&&n.top.length===0,"Direct path region layer fill should classify sparse infill layers."),...oe(r.top.length>0&&r.bottom.length===0,"Direct path region layer fill should classify top solid layers.")]})()],ns=e=>Array.isArray(e)?e.flatMap(t=>ns(t)):[e],rr=(e,t=e.points)=>({...e,points:t.map(n=>({...n}))}),rs=(e,t)=>{const n=t.x-e.x,r=t.y-e.y,i=t.z-e.z;return Math.sqrt(n*n+r*r+i*i)},ld=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n,z:e.z+(t.z-e.z)*n}),dd=e=>{const t=e.closed?[...e.points,e.points[0]]:e.points,n=[];for(let r=1;r<t.length;r+=1)n.push([t[r-1],t[r]]);return n},ud=(e,t)=>{const n=e[Math.max(0,t-1)]??e[t],r=e[Math.min(e.length-1,t+1)]??e[t],i=r.x-n.x,s=r.y-n.y,a=Math.hypot(i,s)||1;return{x:i/a,y:s/a}},fd=(e,t)=>{const n=ud(e,t);return{x:-n.y,y:n.x}},ir=(e,t)=>{let n=0;const r=e.points.map((i,s,a)=>{s>0&&(n+=rs(a[s-1],i));const o=fd(a,s),d=t(n,s);return{...i,x:i.x+o.x*d,y:i.y+o.y*d}});return rr(e,r)},hd=e=>{let t=e>>>0;return()=>(t=1664525*t+1013904223>>>0,t/4294967295)},pd=({spacing:e})=>{const t=Math.max(.001,e);return n=>{if(n.points.length<2)return rr(n);const r=[];for(const[i,s]of dd(n)){const a=rs(i,s),o=Math.max(1,Math.ceil(a/t));r.length===0&&r.push({...i});for(let d=1;d<=o;d+=1){const u=d/o;r.push(ld(i,s,u))}}return n.closed&&r.pop(),rr(n,r)}},md=({amplitude:e,wavelength:t})=>{const n=Math.max(.001,t);return r=>ir(r,i=>e*Math.sin(i/n*Math.PI*2))},gd=({amplitude:e,wavelength:t})=>{const n=Math.max(.001,t);return r=>ir(r,i=>{const s=i/n%1,a=s<.5?s*4-1:3-s*4;return e*a})},yd=({amplitude:e,frequency:t=1,seed:n=1})=>{const r=hd(n);return i=>{const s=i.points.map(()=>(r()*2-1)*e);return ir(i,(a,o)=>{const d=Math.sin(a*t);return s[o]*d})}},is=(e,t)=>{const n=Array.isArray(t)?t:[t];return ns(e).map(r=>n.reduce((i,s)=>s(i),r))},bd=new Set(["outerWall","innerWall","infill","solidInfill","top","bottom","support"]),vd={bottom:2400,infill:3200,innerWall:2200,outerWall:1800,solidInfill:2600,support:2600,top:2400,travel:5e3},ss=e=>"section"in e&&"contains"in e,xd=e=>"toRegion"in e&&typeof e.toRegion=="function",$d=e=>"rings"in e,_d=e=>{const t=xd(e)?e.toRegion():e;return $d(t)?t.rings.map(r=>[...r]):(ss(t)?t.section:t).curves.flatMap(r=>r.role==="invalid"||r.role==="open"||r.points2.length<3?[]:[r.points2])},ht=(e,t)=>"x"in e?{x:Number(e.x),y:Number(e.y),z:Number(e.z??t)}:{x:Number(e[0]),y:Number(e[1]),z:Number(e[2]??t)},wd=e=>{const t=e.closed?[...e.points,e.points[0]]:e.points,n=[];for(let r=1;r<t.length;r+=1){const i=t[r-1],s=t[r];n.push({start:[i.x,i.y],end:[s.x,s.y]})}return n},Md=e=>bd.has(e),Pd=(e,t,n)=>{const r=e==="outerWall"||e==="innerWall"?.45:.35;return t*n*r},Cd=(e,t={})=>{const n=t.layerIndex??0,r=t.layerHeight??.2,i=t.lineWidth??.44,s=[];let a=0;const o=(u,p,m={})=>{const g=m.width??i,C=m.height??r,E=m.extrude??Md(u);return{id:m.id??`custom-${n}-${a++}`,role:u,primitive:m.primitive,layerIndex:n,z:e,closed:m.closed??!1,points:p,extrusion:E?{width:g,height:C,flow:m.flow??Pd(u,g,C)}:void 0,speed:m.speed??t.speed??vd[u]}},d={get paths(){return s},circle:(u,p,m,g={})=>{const C=Math.max(8,Math.round(g.segments??64)),E=ht(p,e),_=Array.from({length:C},(v,z)=>{const M=z/C*Math.PI*2;return{x:E.x+Math.cos(M)*m,y:E.y+Math.sin(M)*m,z:E.z}});return s.push(o(u,_,{...g,closed:!0})),d},clip:(u,p={})=>{const m=_d(u),g=ss(u)?u.contains:()=>!0;if(m.length===0)return s.splice(0,s.length),d;const C=s.flatMap(E=>Ft(wd(E),m,()=>!0,{minLength:p.minLength}).filter(v=>g([(v.start[0]+v.end[0])/2,(v.start[1]+v.end[1])/2])).map((v,z)=>{var M,P,A;return o(p.role??E.role,[{x:v.start[0],y:v.start[1],z:E.z},{x:v.end[0],y:v.end[1],z:E.z}],{closed:!1,extrude:!!E.extrusion,flow:(M=E.extrusion)==null?void 0:M.flow,height:(P=E.extrusion)==null?void 0:P.height,id:`${E.id}-clip-${z}`,primitive:"segments",speed:E.speed,width:(A=E.extrusion)==null?void 0:A.width})}));return s.splice(0,s.length,...C),d},line:(u,p,m,g={})=>(s.push(o(u,[ht(p,e),ht(m,e)],g)),d),modify:u=>(s.splice(0,s.length,...is(s,u)),d),offset:(u,p={})=>{const m=s.flatMap(g=>{if(!g.closed||g.points.length<3)return[g];const C=Tn(g.points.map(E=>[E.x,E.y]),Math.abs(u),{...p,side:p.side??(u>=0?"outward":"inward")});return C.ok?C.rings.map((E,_)=>{var v,z,M;return o(g.role,E.map(([P,A])=>({x:P,y:A,z:g.z})),{closed:!0,extrude:!!g.extrusion,flow:(v=g.extrusion)==null?void 0:v.flow,height:(z=g.extrusion)==null?void 0:z.height,id:`${g.id}-offset-${_}`,speed:g.speed,width:(M=g.extrusion)==null?void 0:M.width})}):[]});return s.splice(0,s.length,...m),d},polyline:(u,p,m={})=>(s.push(o(u,p.map(g=>ht(g,e)),m)),d),polygon:(u,p,m={})=>(s.push(o(u,p.map(g=>ht(g,e)),{...m,closed:!0})),d)};return d},Id=(e,t)=>{var s;const n=Math.max(1,Math.round(t.count??1)),r=[];let i=e;for(let a=0;a<n;a+=1){const o=a===0?t.lineWidth/2:t.lineWidth,d=vi(i,o,{miterLimit:t.miterLimit});for(const u of d.diagnostics)u.level!=="info"&&((s=t.onDiagnostic)==null||s.call(t,`Perimeter wall ${a+1}: ${u.message}`,u.level));for(const u of d.curves.filter(p=>p.role!=="invalid")){const p=(u.role==="outer"||u.role==="island")&&u.points2.length>=3;r.push({id:`layer-${t.layerIndex}-perimeter-${a}-${r.length}`,role:p&&a===0?"outerWall":"innerWall",layerIndex:t.layerIndex,z:e.frame.origin[2],closed:!0,points:u.points2.map(([m,g])=>({x:m,y:g,z:0})),extrusion:{width:t.lineWidth,height:t.layerHeight,flow:t.lineWidth*t.layerHeight*.45},speed:a===0?1800:2200})}i=d}return r},Sd=8,Ed=()=>new Worker(new URL(""+new URL("layerToolpath.worker-5A0bN0Cv.js",self.location.href).href,self.location.href),{type:"module"}),Ad=(e,t={})=>{if(t.workerPool===!1||e<2||typeof Worker>"u")return 0;const n=typeof navigator>"u"?4:navigator.hardwareConcurrency||4,r=typeof t.workerPool=="number"?t.workerPool:n-1;return Math.min(e,Sd,Math.max(1,Math.floor(r)))},zd=(e,t)=>{const n=Array.from({length:t},()=>[]);for(let r=0;r<e;r+=1)n[r%t].push(r);return n},Fd=(e,t)=>{const n=[],r=Math.ceil(e/t);for(let i=0;i<e;i+=r){const s=Math.min(e,i+r),a=[];for(let o=i;o<s;o+=1)a.push(o);n.push(a)}return n},Td=e=>{if(!(typeof e.sectionWindow!="number"||!Number.isFinite(e.sectionWindow)))return Math.max(0,Math.ceil(e.sectionWindow))},kd=(e,t,n)=>{if(typeof n!="number"||t.length===0)return e;const r=Math.min(...t),i=Math.max(...t),s=Math.max(0,r-n),a=Math.min(e.length-1,i+n),o=new Array(e.length);for(let d=s;d<=a;d+=1)o[d]=e[d];return o},sr=e=>e?Array.isArray(e)?e.flatMap(t=>sr(t)):[e]:[],Ld=(e,t,n)=>e&&typeof e=="object"&&!Array.isArray(e)&&"paths"in e?{distance:typeof e.distance=="number"?e.distance:n.distance,layerIndex:typeof e.layerIndex=="number"?e.layerIndex:t,paths:sr(e.paths),plane:e.plane??n.plane,z:typeof e.z=="number"?e.z:n.z}:{distance:n.distance,layerIndex:t,paths:sr(e),plane:n.plane,z:n.z},Rd=e=>e.spec.kind==="plane"&&typeof e.spec.distance=="number"?e.spec.distance:wr(e.frame),Nd=async(e,t,n)=>{const r=[];for(const i of t){const s=e[i];if(!s)continue;const a=s.frame.origin[2],o=Rd(s),d=await n({distance:o,layerIndex:i,plane:s.frame,section:s,sections:e,z:a});r.push(Ld(d,i,{distance:o,plane:s.frame,z:a}))}return r},Dd=(e,t,n,r,i)=>new Promise((s,a)=>{const o=Ed();o.onmessage=({data:d})=>{if(o.terminate(),d.id===i){if(d.error){a(new Error(d.error));return}s(d.layers??[])}},o.onerror=d=>{o.terminate(),a(new Error(d.message||"Layer worker failed."))},o.postMessage({callbackSource:r,context:n,id:i,layerIndices:t,sections:e})}),or=async(e,t)=>Nd(e,e.map((n,r)=>r),t),Wd=async(e,t,n,r={})=>{const i=Ad(e.length,r);if(i<=1)return or(e,n);const s=Td(r),a=(typeof s=="number"?Fd(e.length,i):zd(e.length,i)).filter(u=>u.length>0),o=n.toString();return(await Promise.all(a.map((u,p)=>Dd(kd(e,u,s),u,t,o,p+1)))).flat().sort((u,p)=>u.layerIndex-p.layerIndex)},Od=8,Bd=()=>new Worker(new URL(""+new URL("sectionConnect.worker-D4w8efrj.js",self.location.href).href,self.location.href),{type:"module"}),Gd=(e,t)=>{if(t.workerPool===!1||e<2||typeof Worker>"u")return 0;const n=typeof navigator>"u"?4:navigator.hardwareConcurrency||4,r=typeof t.workerPool=="number"?t.workerPool:n-1;return Math.min(e,Od,Math.max(1,Math.floor(r)))},jd=(e,t)=>{const n=Array.from({length:t},()=>[]);for(let r=0;r<e.length;r+=1)n[r%t].push(e[r]);return n},Hd=(e,t,n)=>new Promise((r,i)=>{const s=Bd();s.onmessage=({data:a})=>{if(s.terminate(),a.id===n){if(a.error){i(new Error(a.error));return}r(a.sections??[])}},s.onerror=a=>{s.terminate(),i(new Error(a.message||"Section worker failed."))},s.postMessage({id:n,options:{...t,workerPool:!1},sections:e})}),Ud=(e,t)=>e.map(n=>Nt(n,{...t})),Vd=async(e,t={})=>{const n=Gd(e.length,t);if(n<=1)return Ud(e,t);const r=jd(e,n),i=await Promise.all(r.map((a,o)=>Hd(a,t,o+1))),s=[];for(let a=0;a<i.length;a+=1){const o=i[a];for(let d=0;d<o.length;d+=1)s[a+d*n]=o[d]}return s.filter(Boolean)},Jt=([e,t,n])=>Object.assign([e,t,n],{x:e,y:t,z:n}),Yd=e=>{const t=Jt(e.bounds.min),n=Jt(e.bounds.max),r=Jt([(t.x+n.x)/2,(t.y+n.y)/2,(t.z+n.z)/2]),i=Jt([n.x-t.x,n.y-t.y,n.z-t.z]);return{min:t,max:n,center:r,size:i}},Xd=e=>e.replace(/^\.\//,"").replaceAll("\\","/"),Qt=e=>{const t=e.trim().replace(/^[^A-Za-z_$]+/,"").replace(/[^A-Za-z0-9_$]+(.)/g,(n,r)=>r.toUpperCase()).replace(/[^A-Za-z0-9_$]/g,"");return t?t[0].toLowerCase()+t.slice(1):e},en=(e={})=>({description:typeof e.description=="string"&&e.description.trim()?e.description:void 0,group:typeof e.group=="string"&&e.group.trim()?e.group:void 0}),tn=e=>({mesh:e,bounds:()=>Yd(e),translate:t=>tn(sc(e,as(t)))}),os=(e={})=>{var t;return{bed:e.bed,buildArea:e.buildArea,capabilities:e.capabilities,coordinates:e.coordinates,defaults:e.defaults,filament:e.filament??1.75,gcodeFlavor:e.gcodeFlavor,layerHeight:e.layerHeight??.2,machineFrame:e.machineFrame??((t=e.coordinates)==null?void 0:t.machineFrame),name:e.name,nozzle:e.nozzle??.4,process:e.process,travel:e.travel}},ar=(e,t)=>Array.isArray(e)?[Number(e[0]??t[0]),Number(e[1]??t[1]),Number(e[2]??t[2])]:t,cr=(e={})=>{const t=ar(e.position,[Number(e.x??0),Number(e.y??0),Number(e.z??0)]),n=ar(e.rotation,[Number(e.rotateX??0),Number(e.rotateY??0),Number(e.rotateZ??0)]),r=Array.isArray(e.scale)?ar(e.scale,[1,1,1]):[Number(e.scale??1),Number(e.scale??1),Number(e.scale??1)];return{name:typeof e.name=="string"?e.name:void 0,position:t,rotation:n,scale:r}},as=e=>{const t=e;return Array.isArray(e)?[Number(e[0]??0),Number(e[1]??0),Number(e[2]??0)]:[t.x??0,t.y??0,t.z??0]},Kd=e=>({bounds:{min:e.bounds.min,max:e.bounds.max},positions:e.triangles.flatMap(t=>[...t.a,...t.b,...t.c])}),Zd=(e,t)=>{const n=e;if(n.kind==="model"){const r=cr(n.placement);return{id:n.id,kind:"model",path:n.path,placement:r,preview:t&&typeof n.previewMesh=="function"?Kd(n.previewMesh().mesh):void 0}}return n.kind==="paths"?{kind:"paths",name:n.name}:e},qd=(e,t)=>({printer:e.printer,items:(e.items??[]).map(n=>Zd(n,t))}),nn=e=>Array.isArray(e)?e.flatMap(t=>nn(t)):[e],Jd=(e,t,n,r)=>({...e,id:e.id.replace(/^layer-\d+/,`layer-${t}`),layerIndex:t,z:n,points:e.points.map(i=>({...i,z:n})),extrusion:e.extrusion?{...e.extrusion,height:e.extrusion.height||r.layerHeight}:void 0}),Qd=(e,t,n,r,i)=>({...Vs(e,n),id:e.id.replace(/^layer-\d+/,`layer-${t}`),layerIndex:t,z:r,extrusion:e.extrusion?{...e.extrusion,height:e.extrusion.height||i.layerHeight}:void 0}),eu=e=>{const t=[];return{addLayer:(r,i)=>{if(typeof r=="number"){const p=t.length,m=r,g=nn(i??[]).map(C=>Jd(C,p,m,e));t.push({distance:m,index:p,paths:g,plane:_r(m),z:m});return}const s=r.layerIndex??t.length,a=Hs(r.plane??_r(r.z??0)),o=r.distance??wr(a),d=r.z??a.origin[2],u=nn(r.paths).map(p=>Qd(p,s,a,d,e));t.push({distance:o,index:s,paths:u,plane:a,z:d})},toGraph:()=>{const r={units:"mm",printer:e,layers:t};return{...r,stats:hl(r)}}}},tu=(e,t={})=>{const n=t.layerIndex??0,r=t.z??e.frame.origin[2],i=t.speed??1200,s=(u,p)=>typeof t.role=="function"?t.role(u,p):t.role?t.role:u==="hole"?"innerWall":"outerWall",a=([u,p])=>({x:u,y:p,z:0}),o=e.curves.filter(u=>u.role!=="invalid"&&u.points2.length>=3).map((u,p)=>({id:`section-${n}-curve-${p}`,role:s(u.role,p),layerIndex:n,z:r,closed:!0,points:u.points2.map(a),speed:i}));if(!t.includeOpen)return o;const d=e.openCurves.filter(u=>u.points2.length>=2).map((u,p)=>({id:`section-${n}-open-${p}`,role:t.openRole??"travel",layerIndex:n,z:r,closed:!1,points:u.points2.map(a),speed:i}));return[...o,...d]},rn=(e,t,n)=>e[t]??n,nu=e=>{const t=e;return typeof t.bounds=="function"&&typeof t.translate=="function"&&typeof t.mesh=="object"},ru=e=>{const t=e;return t.kind==="model"&&typeof t.mesh=="function"},pt=e=>ru(e)?e.mesh():nu(e)?e:tn(e),iu=Object.getPrototypeOf(async function(){}).constructor,su=async({files:e,mode:t="toolpath",onProgress:n,source:r,values:i})=>{const s=[],a=[];let o,d,u,p,m,g,C=0,E=0;const _=($,x)=>{n==null||n({label:$,percent:Math.max(0,Math.min(99,x)),stage:t})};_("Initializing geometry kernel",16),await wa(),_("Validating geometry kernel",18);const v=Ja();for(const $ of v)s.push({level:$.level,message:`Geometry kernel validation: ${$.message}`});const z=cd();for(const $ of z)s.push({level:$.level,message:`Toolpath validation: ${$.message}`});const M=$=>"toGraph"in $?$.toGraph():$,P=$=>{s.push({level:$.level,message:`G-code export: ${$.message}`})},A=($,x)=>{const y=x==null?void 0:x.onDiagnostic;return ga(M($),{...x,onDiagnostic:L=>{P(L),y==null||y(L)}})},R=new Map,G=$=>{const x=Xd($);let L=(x.includes("/")?[x]:[`models/${x}`,x]).find(Ue=>e.has(Ue))??x,W=e.get(L);if(!W&&e.size===1){const Ue=[...e.entries()][0];L=Ue[0],W=Ue[1],s.push({level:"warning",message:`${$} was not found. Using the only imported STL instead: ${L}.`})}if(!W)throw new Error(`STL not found in project: ${$}`);const V=R.get(L);if(V)return V;const K=ic(W,L);s.push({level:"info",message:`Parsed ${K.triangles.length} STL triangles from ${L}.`});const me=tn(K);return R.set(L,me),me},D=($,x={})=>{const y={bounds:()=>y.mesh().bounds(),id:typeof x.id=="string"?x.id:void 0,kind:"model",path:$,placement:x,mesh:()=>tn(oc(G($).mesh,cr(y.placement))),place:L=>(y.placement={...y.placement,...L},typeof L.id=="string"&&(y.id=L.id),y),previewMesh:()=>G($),translate:L=>{const W=cr(y.placement),V=as(L);return D($,{...y.placement,position:[W.position[0]+V[0],W.position[1]+V[1],W.position[2]+V[2]]})}};return y},k=($,x)=>{const y=x??200;y<=0||s.length>=y||s.push($)},B=$=>s.length>=($??200),Y=$=>$.diagnostics??"warnings",j=($,x={})=>{const y=Y(x);if(y==="none")return;const L=x.maxDiagnostics;if(B(L))return;if(y==="all"){for(const K of $.diagnostics)if(k(K,L),B(L))return}else for(const K of $.diagnostics)if(K.level!=="info"&&(k(K,L),B(L)))return;const W=$.curves.filter(K=>K.role==="invalid").length;($.curves.length===0||W>0||$.openCurves.length>0)&&(C<20?k({level:"warning",message:`Slice at z=${$.frame.origin[2].toFixed(3)} generated ${$.curves.length} closed curves, ${$.openCurves.length} open curves, and ${W} invalid curves.`},L):C===20&&k({level:"warning",message:"Additional broken slice diagnostics were suppressed."},L),C+=1)},X=($,x="warning")=>{E<30?s.push({level:x,message:$}):E===30&&s.push({level:"warning",message:"Additional toolpath generation diagnostics were suppressed."}),E+=1},re=$=>{const x=$.layers.filter(L=>L.paths.every(W=>W.role==="travel"||!W.extrusion));if(x.length===0)return;const y=x.slice(0,8).map(L=>`#${L.index}@z=${L.z.toFixed(3)}`).join(", ");s.push({level:"warning",message:`${x.length} layers have no extrusion paths: ${y}${x.length>8?", ...":""}.`})},ce=async($,x={})=>{try{return _(`Connecting ${$.length} slice sections`,56),await Vd($,x)}catch(y){return k({level:"warning",message:`Section worker pool failed; falling back to synchronous connection: ${y instanceof Error?y.message:String(y)}`},x.maxDiagnostics),$.map(L=>Nt(L,{...x}))}},le={Param:{number:($,x,y={})=>{const L=Qt($),W=Number(rn(i,L,x));return a.push({id:L,label:$,kind:"number",...en(y),value:W,min:typeof y.min=="number"?y.min:Math.min(0,x),max:typeof y.max=="number"?y.max:Math.max(1,x*2),step:typeof y.step=="number"?y.step:void 0,unit:typeof y.unit=="string"?y.unit:void 0}),W},boolean:($,x,y={})=>{const L=Qt($),W=!!rn(i,L,x);return a.push({id:L,label:$,kind:"boolean",...en(y),value:W}),W},select:($,x,y,L={})=>{const W=Qt($),V=String(rn(i,W,y)),K=x.includes(V)?V:y;return a.push({id:W,label:$,kind:"select",...en(L),value:K,options:x}),K},text:($,x,y={})=>{const L=Qt($),W=String(rn(i,L,x));return a.push({id:L,label:$,kind:"text",...en(y),value:W}),W}},Plane:Lc,railPlanes:Yn,filament:Sr,model:D,preset:Ir,printer:($={})=>os($),scenePath:($,x)=>({kind:"paths",name:$,paths:()=>nn(x())}),exportScene:$=>(d=qd($,t==="scene"),d),exportToolpath:$=>typeof $=="function"?(u=$,$):(o=M($),o),exportGcode:($,x)=>(o=M($),s.push({level:"warning",message:"exportGcode(graph) is deprecated. Use exportToolpath(graph) and onExportGcode(makeGcode)."}),p=t==="gcode"?A(o,x):void 0,p??""),editGcode:gn,generateGcode:A,onExportGcode:$=>{if(typeof $!="function")throw new Error("onExportGcode expects a function.");m=$},modifyPaths:is,mapLayers:($,x)=>or($,x),noise:yd,parallelLayers:async($,x,y,L={})=>{const W=typeof x=="function"?{}:x,V=typeof x=="function"?x:y,K=typeof x=="function"?y:L;if(typeof V!="function")throw new Error("parallelLayers expects a callback. Use parallelLayers(sections, context, callback, options).");try{return _(`Generating ${$.length} toolpath layers`,70),await Wd($,W,V,K??{})}catch(me){return s.push({level:"warning",message:`Layer worker pool failed; falling back to synchronous layer generation: ${me instanceof Error?me.message:String(me)}`}),or($,V)}},pathLayer:Cd,pathRegion:$e,planLayerPaths:Zt,resample:pd,sine:md,zigzag:gd,lineInfill:($,x={})=>Ul($,{angle:x.angle,layerIndex:0,density:x.density??.18,field:x.field,lineWidth:x.lineWidth??.44,layerHeight:x.layerHeight??.2,margin:x.margin,onDiagnostic:X,pattern:x.pattern,spacing:x.spacing}),fillRegion:($,x={})=>Le($,{angle:x.angle,density:x.density,field:x.field,layerHeight:x.layerHeight??.2,layerIndex:x.layerIndex??0,lineWidth:x.lineWidth??.44,pattern:x.pattern,role:x.role,spacing:x.spacing}),fillLayer:($,x,y={})=>Ji($,x,{bottomAngle:y.bottomAngle,bottomPattern:y.bottomPattern,density:y.density??.18,field:y.field,layerHeight:y.layerHeight??.2,layerIndex:x,lineWidth:y.lineWidth??.44,margin:y.margin,onDiagnostic:X,pattern:y.pattern,solidLayers:y.solidLayers,sparseAngle:y.sparseAngle,sparsePattern:y.sparsePattern,sparseSpacing:y.sparseSpacing,topAngle:y.topAngle,topPattern:y.topPattern}),fillRegionLayer:($,x,y={})=>Yt($,x,{bottomAngle:y.bottomAngle,bottomPattern:y.bottomPattern,density:y.density??.18,field:y.field,layerHeight:y.layerHeight??.2,layerIndex:x,lineWidth:y.lineWidth??.44,margin:y.margin,onDiagnostic:X,pattern:y.pattern,solidLayers:y.solidLayers,sparseAngle:y.sparseAngle,sparsePattern:y.sparsePattern,sparseSpacing:y.sparseSpacing,topAngle:y.topAngle,topPattern:y.topPattern}),loadSTL:G,perimeters:($,x={})=>Id($,{count:x.count,layerIndex:0,lineWidth:x.lineWidth??.44,layerHeight:x.layerHeight??.2,miterLimit:x.miterLimit,onDiagnostic:X}),region:$=>Be($),rawSegments:$=>$.rawCurves??[],sectionPaths:tu,slice:($,x,y={})=>{const L=pt($).mesh;_("Slicing section",42);const W=ul(L,x,y),V=y.connect===!1?W:Nt(W,y);return j(V,y),V},sliceStack:($,x,y={})=>{const L=pt($).mesh;_(`Slicing ${x.length} planes`,42);const W=Wt(L,x,y);_(`Generated ${W.length} raw sections`,52);const V=y.connect===!1?W:W.map(K=>Nt(K,y));for(const K of V)j(K,y);return V},sliceStackAsync:async($,x,y={})=>{const L=pt($).mesh;_(`Slicing ${x.length} planes`,42);const W=Wt(L,x,y);_(`Generated ${W.length} raw sections`,52);const V=y.connect===!1?W:await ce(W,y);for(const K of V)j(K,y);return V},sliceStackParallel:async($,x,y={})=>{const L=pt($).mesh;_(`Slicing ${x.length} planes`,42);const W=Wt(L,x,y);_(`Generated ${W.length} raw sections`,52);const V=y.connect===!1?W:await ce(W,y);for(const K of V)j(K,y);return V},sliceAlong:async($,x,y={})=>{const L=Yn(x),W=pt($).mesh;_(`Slicing ${L.length} rail planes`,42);const V=Wt(W,L,y);_(`Generated ${V.length} raw rail sections`,52);const K=y.connect===!1?V:await ce(V,y);for(const me of K)j(me,y);return K},sparseInfill:($,x,y={})=>Vl($,x,{angle:y.angle,density:y.density??.18,field:y.field,layerHeight:y.layerHeight??.2,layerIndex:0,lineWidth:y.lineWidth??.44,margin:y.margin,onDiagnostic:X,pattern:y.pattern,solidLayers:y.solidLayers,spacing:y.spacing}),bottomSolidFill:($,x,y={})=>Yl($,x,{angle:y.angle,field:y.field,layerHeight:y.layerHeight??.2,layerIndex:0,lineWidth:y.lineWidth??.44,margin:y.margin,onDiagnostic:X,pattern:y.pattern,solidLayers:y.solidLayers}),topSolidFill:($,x,y={})=>Xl($,x,{angle:y.angle,field:y.field,layerHeight:y.layerHeight??.2,layerIndex:0,lineWidth:y.lineWidth??.44,margin:y.margin,onDiagnostic:X,pattern:y.pattern,solidLayers:y.solidLayers}),toolpath:($={})=>{var y;const x={...$.printer??$,layerHeight:$.layerHeight??((y=$.printer)==null?void 0:y.layerHeight)};return g=eu(os(x)),g}},Q={document:void 0,fetch:void 0,globalThis:void 0,localStorage:void 0,sessionStorage:void 0,window:void 0},J=new iu(...Object.keys(le),...Object.keys(Q),`"use strict";
|
|
20
|
+
${r}
|
|
21
|
+
//# sourceURL=main.fuse.js`);_("Evaluating .fuse.js declarations",24),await J(...Object.values(le),...Object.values(Q)),_(t==="scene"?"Preparing scene":"Declarations evaluated",t==="scene"?84:32),t!=="scene"&&!o&&u&&(_("Executing toolpath callback",36),o=M(await u()),_("Toolpath graph generated",86));const te=o??(g==null?void 0:g.toGraph());if(t!=="scene"&&!te)throw new Error("The .fuse.js program did not create or export a toolpath graph.");te&&re(te);let _e;t==="gcode"&&te&&(_("Generating G-code",90),_e=p??(m==null?void 0:m({editGcode:gn,generateGcode:A,graph:te}))??A(te));const we=te?`generated ${te.layers.length} layers`:`generated scene metadata with ${(d==null?void 0:d.items.length)??0} items`;return{diagnostics:[...s,{level:"info",message:`Executed .fuse.js in ${t} stage and ${we} from ${r.split(`
|
|
22
|
+
`).length} lines.`}],graph:te,gcode:_e,hasGcodeExport:!!m,hasToolpathExport:!!(o||u||g),params:a,scene:d,stage:t}},q=(e,t=0)=>{const n=Number(e);return Number.isFinite(n)?n:t},ou=e=>({x:q(e.x),y:q(e.y),z:q(e.z),e:typeof e.e=="number"?q(e.e):void 0}),sn=e=>[q(e[0]),q(e[1]),q(e[2])],au=e=>({id:String(e.id),role:e.role,order:typeof e.order=="number"?q(e.order):void 0,layerIndex:q(e.layerIndex),z:q(e.z),closed:!!e.closed,points:e.points.map(ou),primitive:e.primitive,sourceLine:typeof e.sourceLine=="number"?q(e.sourceLine):void 0,speed:q(e.speed),extrusion:e.extrusion?{flow:q(e.extrusion.flow),height:q(e.extrusion.height),width:q(e.extrusion.width)}:void 0}),cu=e=>{var t,n,r,i;return{distance:q(e.distance,e.z),index:q(e.index),plane:{origin:sn(((t=e.plane)==null?void 0:t.origin)??[0,0,e.z]),normal:sn(((n=e.plane)==null?void 0:n.normal)??[0,0,1]),xAxis:sn(((r=e.plane)==null?void 0:r.xAxis)??[1,0,0]),yAxis:sn(((i=e.plane)==null?void 0:i.yAxis)??[0,1,0])},z:q(e.z),paths:e.paths.map(au)}},He=e=>{if(e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(He);if(typeof e=="object")return Object.fromEntries(Object.entries(e).map(([t,n])=>[t,He(n)]).filter(([t,n])=>n!==void 0))},lu=e=>({units:"mm",printer:He(e.printer),layers:e.layers.map(cu),stats:{estimatedExtrusionMm:q(e.stats.estimatedExtrusionMm),extrusionDistanceMm:q(e.stats.extrusionDistanceMm),layerCount:q(e.stats.layerCount),pathCount:q(e.stats.pathCount),travelDistanceMm:q(e.stats.travelDistanceMm)}}),du=e=>({diagnostics:e.diagnostics.map(t=>({level:t.level,message:String(t.message)})),gcode:e.gcode,graph:e.graph?lu(e.graph):void 0,hasGcodeExport:!!e.hasGcodeExport,hasToolpathExport:!!e.hasToolpathExport,params:e.params.map(t=>He(t)),scene:e.scene?{items:e.scene.items.map(He),printer:He(e.scene.printer)}:void 0,stage:e.stage});self.onmessage=async({data:e})=>{const t=n=>{self.postMessage({id:e.id,progress:n})};try{t({label:"Starting runtime worker",percent:14,stage:e.mode});const n=await su({files:new Map(e.files),mode:e.mode,onProgress:t,source:e.source,values:e.values});t({label:"Preparing preview data",percent:94,stage:e.mode});const r=du(n);self.postMessage({id:e.id,result:r})}catch(n){self.postMessage({error:n instanceof Error?n.message:String(n),id:e.id})}}})();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
(function(){"use strict";function Zr(e,t){return t.forEach(function(r){r&&typeof r!="string"&&!Array.isArray(r)&&Object.keys(r).forEach(function(i){if(i!=="default"&&!(i in e)){var c=Object.getOwnPropertyDescriptor(r,i);Object.defineProperty(e,i,c.get?c:{enumerable:!0,get:function(){return r[i]}})}})}),Object.freeze(e)}function qr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Xe={exports:{}},xt;function Xr(){return xt||(xt=1,(function(e,t){var r=(()=>{var c;var i=typeof document<"u"?(c=document.currentScript)==null?void 0:c.src:void 0;return(function(l={}){var f,o=l,d,h,y=new Promise((s,n)=>{d=s,h=n}),P=Object.assign({},o),$="";function A(s){return o.locateFile?o.locateFile(s,$):$+s}var T;typeof document<"u"&&document.currentScript&&($=document.currentScript.src),i&&($=i),$.startsWith("blob:")?$="":$=$.substr(0,$.replace(/[?#].*/,"").lastIndexOf("/")+1),T=s=>fetch(s,{credentials:"same-origin"}).then(n=>n.ok?n.arrayBuffer():Promise.reject(new Error(n.status+" : "+n.url))),o.print||console.log.bind(console);var W=o.printErr||console.error.bind(console);Object.assign(o,P),P=null,o.arguments&&o.arguments,o.thisProgram&&o.thisProgram;var C=o.wasmBinary,R,D=!1,k,E,X,ye,ae,M,ar,cr,lr,ur;function fr(){var s=R.buffer;o.HEAP8=k=new Int8Array(s),o.HEAP16=X=new Int16Array(s),o.HEAPU8=E=new Uint8Array(s),o.HEAPU16=ye=new Uint16Array(s),o.HEAP32=ae=new Int32Array(s),o.HEAPU32=M=new Uint32Array(s),o.HEAPF32=ar=new Float32Array(s),o.HEAPF64=ur=new Float64Array(s),o.HEAP64=cr=new BigInt64Array(s),o.HEAPU64=lr=new BigUint64Array(s)}var dr=[],hr=[],gr=[];function Gs(){if(o.preRun)for(typeof o.preRun=="function"&&(o.preRun=[o.preRun]);o.preRun.length;)ei(o.preRun.shift());ht(dr)}function Js(){ht(hr)}function Qs(){if(o.postRun)for(typeof o.postRun=="function"&&(o.postRun=[o.postRun]);o.postRun.length;)ri(o.postRun.shift());ht(gr)}function ei(s){dr.unshift(s)}function ti(s){hr.unshift(s)}function ri(s){gr.unshift(s)}var J=0,Pe=null;function ni(s){var n;J++,(n=o.monitorRunDependencies)==null||n.call(o,J)}function si(s){var a;if(J--,(a=o.monitorRunDependencies)==null||a.call(o,J),J==0&&Pe){var n=Pe;Pe=null,n()}}function pr(s){var a;(a=o.onAbort)==null||a.call(o,s),s="Aborted("+s+")",W(s),D=!0,s+=". Build with -sASSERTIONS for more info.";var n=new WebAssembly.RuntimeError(s);throw h(n),n}var ii="data:application/octet-stream;base64,",mr=s=>s.startsWith(ii);function oi(){var s="clipper2z.wasm";return mr(s)?s:A(s)}var dt;function vr(s){if(s==dt&&C)return new Uint8Array(C);throw"both async and sync fetching of the wasm failed"}function ai(s){return C?Promise.resolve().then(()=>vr(s)):T(s).then(n=>new Uint8Array(n),()=>vr(s))}function yr(s,n,a){return ai(s).then(u=>WebAssembly.instantiate(u,n)).then(a,u=>{W(`failed to asynchronously prepare wasm: ${u}`),pr(u)})}function ci(s,n,a,u){return!s&&typeof WebAssembly.instantiateStreaming=="function"&&!mr(n)&&typeof fetch=="function"?fetch(n,{credentials:"same-origin"}).then(g=>{var m=WebAssembly.instantiateStreaming(g,a);return m.then(u,function(v){return W(`wasm streaming compile failed: ${v}`),W("falling back to ArrayBuffer instantiation"),yr(n,a,u)})}):yr(n,a,u)}function li(){return{a:bo}}function ui(){function s(u,g){return G=u.exports,R=G.t,fr(),Sr=G.w,ti(G.u),si(),G}ni();function n(u){s(u.instance)}var a=li();if(o.instantiateWasm)try{return o.instantiateWasm(a,s)}catch(u){W(`Module.instantiateWasm callback failed with error: ${u}`),h(u)}return dt??(dt=oi()),ci(C,dt,a,n).catch(h),{}}var ht=s=>{for(;s.length>0;)s.shift()(o)};o.noExitRuntime;class fi{constructor(n){this.excPtr=n,this.ptr=n-24}set_type(n){M[this.ptr+4>>2]=n}get_type(){return M[this.ptr+4>>2]}set_destructor(n){M[this.ptr+8>>2]=n}get_destructor(){return M[this.ptr+8>>2]}set_caught(n){n=n?1:0,k[this.ptr+12]=n}get_caught(){return k[this.ptr+12]!=0}set_rethrown(n){n=n?1:0,k[this.ptr+13]=n}get_rethrown(){return k[this.ptr+13]!=0}init(n,a){this.set_adjusted_ptr(0),this.set_type(n),this.set_destructor(a)}set_adjusted_ptr(n){M[this.ptr+16>>2]=n}get_adjusted_ptr(){return M[this.ptr+16>>2]}}var Pr=0,di=(s,n,a)=>{var u=new fi(s);throw u.init(n,a),Pr=s,Pr},hi=()=>pr(""),Oe=s=>{if(s===null)return"null";var n=typeof s;return n==="object"||n==="array"||n==="function"?s.toString():""+s},gi=()=>{for(var s=new Array(256),n=0;n<256;++n)s[n]=String.fromCharCode(n);br=s},br,L=s=>{for(var n="",a=s;E[a];)n+=br[E[a++]];return n},ce={},Q={},He={},le,I=s=>{throw new le(s)},$r,ze=s=>{throw new $r(s)},Y=(s,n,a)=>{s.forEach(p=>He[p]=n);function u(p){var b=a(p);b.length!==s.length&&ze("Mismatched type converter count");for(var w=0;w<s.length;++w)U(s[w],b[w])}var g=new Array(n.length),m=[],v=0;n.forEach((p,b)=>{Q.hasOwnProperty(p)?g[b]=Q[p]:(m.push(p),ce.hasOwnProperty(p)||(ce[p]=[]),ce[p].push(()=>{g[b]=Q[p],++v,v===m.length&&u(g)}))}),m.length===0&&u(g)};function pi(s,n,a={}){var u=n.name;if(s||I(`type "${u}" must have a positive integer typeid pointer`),Q.hasOwnProperty(s)){if(a.ignoreDuplicateRegistrations)return;I(`Cannot register type '${u}' twice`)}if(Q[s]=n,delete He[s],ce.hasOwnProperty(s)){var g=ce[s];delete ce[s],g.forEach(m=>m())}}function U(s,n,a={}){return pi(s,n,a)}var wr=(s,n,a)=>{switch(n){case 1:return a?u=>k[u]:u=>E[u];case 2:return a?u=>X[u>>1]:u=>ye[u>>1];case 4:return a?u=>ae[u>>2]:u=>M[u>>2];case 8:return a?u=>cr[u>>3]:u=>lr[u>>3];default:throw new TypeError(`invalid integer width (${n}): ${s}`)}},mi=(s,n,a,u,g)=>{n=L(n);var m=n.indexOf("u")!=-1;U(s,{name:n,fromWireType:v=>v,toWireType:function(v,p){if(typeof p!="bigint"&&typeof p!="number")throw new TypeError(`Cannot convert "${Oe(p)}" to ${this.name}`);return typeof p=="number"&&(p=BigInt(p)),p},argPackAdvance:B,readValueFromPointer:wr(n,a,!m),destructorFunction:null})},B=8,vi=(s,n,a,u)=>{n=L(n),U(s,{name:n,fromWireType:function(g){return!!g},toWireType:function(g,m){return m?a:u},argPackAdvance:B,readValueFromPointer:function(g){return this.fromWireType(E[g])},destructorFunction:null})},yi=s=>({count:s.count,deleteScheduled:s.deleteScheduled,preservePointerOnDelete:s.preservePointerOnDelete,ptr:s.ptr,ptrType:s.ptrType,smartPtr:s.smartPtr,smartPtrType:s.smartPtrType}),gt=s=>{function n(a){return a.$$.ptrType.registeredClass.name}I(n(s)+" instance already deleted")},pt=!1,xr=s=>{},Pi=s=>{s.smartPtr?s.smartPtrType.rawDestructor(s.smartPtr):s.ptrType.registeredClass.rawDestructor(s.ptr)},_r=s=>{s.count.value-=1;var n=s.count.value===0;n&&Pi(s)},Tr=(s,n,a)=>{if(n===a)return s;if(a.baseClass===void 0)return null;var u=Tr(s,n,a.baseClass);return u===null?null:a.downcast(u)},Cr={},bi={},$i=(s,n)=>{for(n===void 0&&I("ptr should not be undefined");s.baseClass;)n=s.upcast(n),s=s.baseClass;return n},wi=(s,n)=>(n=$i(s,n),bi[n]),je=(s,n)=>{(!n.ptrType||!n.ptr)&&ze("makeClassHandle requires ptr and ptrType");var a=!!n.smartPtrType,u=!!n.smartPtr;return a!==u&&ze("Both smartPtrType and smartPtr must be specified"),n.count={value:1},be(Object.create(s,{$$:{value:n,writable:!0}}))};function xi(s){var n=this.getPointee(s);if(!n)return this.destructor(s),null;var a=wi(this.registeredClass,n);if(a!==void 0){if(a.$$.count.value===0)return a.$$.ptr=n,a.$$.smartPtr=s,a.clone();var u=a.clone();return this.destructor(s),u}function g(){return this.isSmartPointer?je(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:n,smartPtrType:this,smartPtr:s}):je(this.registeredClass.instancePrototype,{ptrType:this,ptr:s})}var m=this.registeredClass.getActualType(n),v=Cr[m];if(!v)return g.call(this);var p;this.isConst?p=v.constPointerType:p=v.pointerType;var b=Tr(n,this.registeredClass,p.registeredClass);return b===null?g.call(this):this.isSmartPointer?je(p.registeredClass.instancePrototype,{ptrType:p,ptr:b,smartPtrType:this,smartPtr:s}):je(p.registeredClass.instancePrototype,{ptrType:p,ptr:b})}var be=s=>typeof FinalizationRegistry>"u"?(be=n=>n,s):(pt=new FinalizationRegistry(n=>{_r(n.$$)}),be=n=>{var a=n.$$,u=!!a.smartPtr;if(u){var g={$$:a};pt.register(n,g,n)}return n},xr=n=>pt.unregister(n),be(s)),_i=()=>{Object.assign(Ue.prototype,{isAliasOf(s){if(!(this instanceof Ue)||!(s instanceof Ue))return!1;var n=this.$$.ptrType.registeredClass,a=this.$$.ptr;s.$$=s.$$;for(var u=s.$$.ptrType.registeredClass,g=s.$$.ptr;n.baseClass;)a=n.upcast(a),n=n.baseClass;for(;u.baseClass;)g=u.upcast(g),u=u.baseClass;return n===u&&a===g},clone(){if(this.$$.ptr||gt(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var s=be(Object.create(Object.getPrototypeOf(this),{$$:{value:yi(this.$$)}}));return s.$$.count.value+=1,s.$$.deleteScheduled=!1,s},delete(){this.$$.ptr||gt(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&I("Object already scheduled for deletion"),xr(this),_r(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)},isDeleted(){return!this.$$.ptr},deleteLater(){return this.$$.ptr||gt(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&I("Object already scheduled for deletion"),this.$$.deleteScheduled=!0,this}})};function Ue(){}var $e=(s,n)=>Object.defineProperty(n,"name",{value:s}),Ir=(s,n,a)=>{if(s[n].overloadTable===void 0){var u=s[n];s[n]=function(...g){return s[n].overloadTable.hasOwnProperty(g.length)||I(`Function '${a}' called with an invalid number of arguments (${g.length}) - expects one of (${s[n].overloadTable})!`),s[n].overloadTable[g.length].apply(this,g)},s[n].overloadTable=[],s[n].overloadTable[u.argCount]=u}},mt=(s,n,a)=>{o.hasOwnProperty(s)?((a===void 0||o[s].overloadTable!==void 0&&o[s].overloadTable[a]!==void 0)&&I(`Cannot register public name '${s}' twice`),Ir(o,s,s),o[s].overloadTable.hasOwnProperty(a)&&I(`Cannot register multiple overloads of a function with the same number of arguments (${a})!`),o[s].overloadTable[a]=n):(o[s]=n,o[s].argCount=a)},Ti=48,Ci=57,Ii=s=>{s=s.replace(/[^a-zA-Z0-9_]/g,"$");var n=s.charCodeAt(0);return n>=Ti&&n<=Ci?`_${s}`:s};function Ai(s,n,a,u,g,m,v,p){this.name=s,this.constructor=n,this.instancePrototype=a,this.rawDestructor=u,this.baseClass=g,this.getActualType=m,this.upcast=v,this.downcast=p,this.pureVirtualFunctions=[]}var Ne=(s,n,a)=>{for(;n!==a;)n.upcast||I(`Expected null or instance of ${a.name}, got an instance of ${n.name}`),s=n.upcast(s),n=n.baseClass;return s};function Si(s,n){if(n===null)return this.isReference&&I(`null is not a valid ${this.name}`),0;n.$$||I(`Cannot pass "${Oe(n)}" as a ${this.name}`),n.$$.ptr||I(`Cannot pass deleted object as a pointer of type ${this.name}`);var a=n.$$.ptrType.registeredClass,u=Ne(n.$$.ptr,a,this.registeredClass);return u}function Ei(s,n){var a;if(n===null)return this.isReference&&I(`null is not a valid ${this.name}`),this.isSmartPointer?(a=this.rawConstructor(),s!==null&&s.push(this.rawDestructor,a),a):0;(!n||!n.$$)&&I(`Cannot pass "${Oe(n)}" as a ${this.name}`),n.$$.ptr||I(`Cannot pass deleted object as a pointer of type ${this.name}`),!this.isConst&&n.$$.ptrType.isConst&&I(`Cannot convert argument of type ${n.$$.smartPtrType?n.$$.smartPtrType.name:n.$$.ptrType.name} to parameter type ${this.name}`);var u=n.$$.ptrType.registeredClass;if(a=Ne(n.$$.ptr,u,this.registeredClass),this.isSmartPointer)switch(n.$$.smartPtr===void 0&&I("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:n.$$.smartPtrType===this?a=n.$$.smartPtr:I(`Cannot convert argument of type ${n.$$.smartPtrType?n.$$.smartPtrType.name:n.$$.ptrType.name} to parameter type ${this.name}`);break;case 1:a=n.$$.smartPtr;break;case 2:if(n.$$.smartPtrType===this)a=n.$$.smartPtr;else{var g=n.clone();a=this.rawShare(a,bt.toHandle(()=>g.delete())),s!==null&&s.push(this.rawDestructor,a)}break;default:I("Unsupporting sharing policy")}return a}function Ri(s,n){if(n===null)return this.isReference&&I(`null is not a valid ${this.name}`),0;n.$$||I(`Cannot pass "${Oe(n)}" as a ${this.name}`),n.$$.ptr||I(`Cannot pass deleted object as a pointer of type ${this.name}`),n.$$.ptrType.isConst&&I(`Cannot convert argument of type ${n.$$.ptrType.name} to parameter type ${this.name}`);var a=n.$$.ptrType.registeredClass,u=Ne(n.$$.ptr,a,this.registeredClass);return u}function Be(s){return this.fromWireType(M[s>>2])}var Mi=()=>{Object.assign(Ve.prototype,{getPointee(s){return this.rawGetPointee&&(s=this.rawGetPointee(s)),s},destructor(s){var n;(n=this.rawDestructor)==null||n.call(this,s)},argPackAdvance:B,readValueFromPointer:Be,fromWireType:xi})};function Ve(s,n,a,u,g,m,v,p,b,w,x){this.name=s,this.registeredClass=n,this.isReference=a,this.isConst=u,this.isSmartPointer=g,this.pointeeType=m,this.sharingPolicy=v,this.rawGetPointee=p,this.rawConstructor=b,this.rawShare=w,this.rawDestructor=x,!g&&n.baseClass===void 0?u?(this.toWireType=Si,this.destructorFunction=null):(this.toWireType=Ri,this.destructorFunction=null):this.toWireType=Ei}var Ar=(s,n,a)=>{o.hasOwnProperty(s)||ze("Replacing nonexistent public symbol"),o[s].overloadTable!==void 0&&a!==void 0?o[s].overloadTable[a]=n:(o[s]=n,o[s].argCount=a)},Ze=[],Sr,Fi=s=>{var n=Ze[s];return n||(s>=Ze.length&&(Ze.length=s+1),Ze[s]=n=Sr.get(s)),n},V=(s,n)=>{s=L(s);function a(){return Fi(n)}var u=a();return typeof u!="function"&&I(`unknown function pointer with signature ${s}: ${n}`),u},Wi=(s,n)=>{var a=$e(n,function(u){this.name=n,this.message=u;var g=new Error(u).stack;g!==void 0&&(this.stack=this.toString()+`
|
|
2
|
+
`+g.replace(/^Error(:[^\n]*)?\n/,""))});return a.prototype=Object.create(s.prototype),a.prototype.constructor=a,a.prototype.toString=function(){return this.message===void 0?this.name:`${this.name}: ${this.message}`},a},Er,Rr=s=>{var n=Or(s),a=L(n);return Z(n),a},ue=(s,n)=>{var a=[],u={};function g(m){if(!u[m]&&!Q[m]){if(He[m]){He[m].forEach(g);return}a.push(m),u[m]=!0}}throw n.forEach(g),new Er(`${s}: `+a.map(Rr).join([", "]))},Di=(s,n,a,u,g,m,v,p,b,w,x,_,S)=>{x=L(x),m=V(g,m),p&&(p=V(v,p)),w&&(w=V(b,w)),S=V(_,S);var O=Ii(x);mt(O,function(){ue(`Cannot construct ${x} due to unbound types`,[u])}),Y([s,n,a],u?[u]:[],F=>{var Br;F=F[0];var N,ee;u?(N=F.registeredClass,ee=N.instancePrototype):ee=Ue.prototype;var j=$e(x,function(...wt){if(Object.getPrototypeOf(this)!==we)throw new le("Use 'new' to construct "+x);if(z.constructor_body===void 0)throw new le(x+" has no accessible constructor");var Vr=z.constructor_body[wt.length];if(Vr===void 0)throw new le(`Tried to invoke ctor of ${x} with invalid number of parameters (${wt.length}) - expected (${Object.keys(z.constructor_body).toString()}) parameters instead!`);return Vr.apply(this,wt)}),we=Object.create(ee,{constructor:{value:j}});j.prototype=we;var z=new Ai(x,j,we,S,N,m,p,w);z.baseClass&&((Br=z.baseClass).__derivedClasses??(Br.__derivedClasses=[]),z.baseClass.__derivedClasses.push(z));var Io=new Ve(x,z,!0,!1,!1),Ur=new Ve(x+"*",z,!1,!1,!1),Nr=new Ve(x+" const*",z,!1,!0,!1);return Cr[s]={pointerType:Ur,constPointerType:Nr},Ar(O,j),[Io,Ur,Nr]})},vt=(s,n)=>{for(var a=[],u=0;u<s;u++)a.push(M[n+u*4>>2]);return a},Mr=s=>{for(;s.length;){var n=s.pop(),a=s.pop();a(n)}};function Fr(s){for(var n=1;n<s.length;++n)if(s[n]!==null&&s[n].destructorFunction===void 0)return!0;return!1}function ki(s,n){if(!(s instanceof Function))throw new TypeError(`new_ called with constructor type ${typeof s} which is not a function`);var a=$e(s.name||"unknownFunctionName",function(){});a.prototype=s.prototype;var u=new a,g=s.apply(u,n);return g instanceof Object?g:u}function Li(s,n,a,u){var g=Fr(s),m=s.length-2,v=[],p=["fn"];n&&p.push("thisWired");for(var b=0;b<m;++b)v.push(`arg${b}`),p.push(`arg${b}Wired`);v=v.join(","),p=p.join(",");var w=`return function (${v}) {
|
|
3
|
+
`;g&&(w+=`var destructors = [];
|
|
4
|
+
`);var x=g?"destructors":"null",_=["humanName","throwBindingError","invoker","fn","runDestructors","retType","classParam"];n&&(w+=`var thisWired = classParam['toWireType'](${x}, this);
|
|
5
|
+
`);for(var b=0;b<m;++b)w+=`var arg${b}Wired = argType${b}['toWireType'](${x}, arg${b});
|
|
6
|
+
`,_.push(`argType${b}`);if(w+=(a||u?"var rv = ":"")+`invoker(${p});
|
|
7
|
+
`,g)w+=`runDestructors(destructors);
|
|
8
|
+
`;else for(var b=n?1:2;b<s.length;++b){var S=b===1?"thisWired":"arg"+(b-2)+"Wired";s[b].destructorFunction!==null&&(w+=`${S}_dtor(${S});
|
|
9
|
+
`,_.push(`${S}_dtor`))}return a&&(w+=`var ret = retType['fromWireType'](rv);
|
|
10
|
+
return ret;
|
|
11
|
+
`),w+=`}
|
|
12
|
+
`,[_,w]}function yt(s,n,a,u,g,m){var v=n.length;v<2&&I("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var p=n[1]!==null&&a!==null,b=Fr(n),w=n[0].name!=="void",x=[s,I,u,g,Mr,n[0],n[1]],_=0;_<v-2;++_)x.push(n[_+2]);if(!b)for(var _=p?1:2;_<n.length;++_)n[_].destructorFunction!==null&&x.push(n[_].destructorFunction);let[S,O]=Li(n,p,w,m);S.push(O);var F=ki(Function,S)(...x);return $e(s,F)}var Oi=(s,n,a,u,g,m)=>{var v=vt(n,a);g=V(u,g),Y([],[s],p=>{p=p[0];var b=`constructor ${p.name}`;if(p.registeredClass.constructor_body===void 0&&(p.registeredClass.constructor_body=[]),p.registeredClass.constructor_body[n-1]!==void 0)throw new le(`Cannot register multiple constructors with identical number of parameters (${n-1}) for class '${p.name}'! Overload resolution is currently only performed using the parameter count, not actual type info!`);return p.registeredClass.constructor_body[n-1]=()=>{ue(`Cannot construct ${p.name} due to unbound types`,v)},Y([],v,w=>(w.splice(1,0,null),p.registeredClass.constructor_body[n-1]=yt(b,w,null,g,m),[])),[]})},Wr=s=>{s=s.trim();const n=s.indexOf("(");return n!==-1?s.substr(0,n):s},Hi=(s,n,a,u,g,m,v,p,b,w)=>{var x=vt(a,u);n=L(n),n=Wr(n),m=V(g,m),Y([],[s],_=>{_=_[0];var S=`${_.name}.${n}`;n.startsWith("@@")&&(n=Symbol[n.substring(2)]),p&&_.registeredClass.pureVirtualFunctions.push(n);function O(){ue(`Cannot call ${S} due to unbound types`,x)}var F=_.registeredClass.instancePrototype,N=F[n];return N===void 0||N.overloadTable===void 0&&N.className!==_.name&&N.argCount===a-2?(O.argCount=a-2,O.className=_.name,F[n]=O):(Ir(F,n,S),F[n].overloadTable[a-2]=O),Y([],x,ee=>{var j=yt(S,ee,_,m,v,b);return F[n].overloadTable===void 0?(j.argCount=a-2,F[n]=j):F[n].overloadTable[a-2]=j,[]}),[]})},Dr=(s,n,a)=>(s instanceof Object||I(`${a} with invalid "this": ${s}`),s instanceof n.registeredClass.constructor||I(`${a} incompatible with "this" of type ${s.constructor.name}`),s.$$.ptr||I(`cannot call emscripten binding method ${a} on deleted object`),Ne(s.$$.ptr,s.$$.ptrType.registeredClass,n.registeredClass)),zi=(s,n,a,u,g,m,v,p,b,w)=>{n=L(n),g=V(u,g),Y([],[s],x=>{x=x[0];var _=`${x.name}.${n}`,S={get(){ue(`Cannot access ${_} due to unbound types`,[a,v])},enumerable:!0,configurable:!0};return b?S.set=()=>ue(`Cannot access ${_} due to unbound types`,[a,v]):S.set=O=>I(_+" is a read-only property"),Object.defineProperty(x.registeredClass.instancePrototype,n,S),Y([],b?[a,v]:[a],O=>{var F=O[0],N={get(){var j=Dr(this,x,_+" getter");return F.fromWireType(g(m,j))},enumerable:!0};if(b){b=V(p,b);var ee=O[1];N.set=function(j){var we=Dr(this,x,_+" setter"),z=[];b(w,we,ee.toWireType(z,j)),Mr(z)}}return Object.defineProperty(x.registeredClass.instancePrototype,n,N),[]}),[]})},Pt=[],K=[],ji=s=>{s>9&&--K[s+1]===0&&(K[s]=void 0,Pt.push(s))},Ui=()=>K.length/2-5-Pt.length,Ni=()=>{K.push(0,1,void 0,1,null,1,!0,1,!1,1),o.count_emval_handles=Ui},bt={toValue:s=>(s||I("Cannot use deleted val. handle = "+s),K[s]),toHandle:s=>{switch(s){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:{const n=Pt.pop()||K.length;return K[n]=s,K[n+1]=1,n}}}},Bi={name:"emscripten::val",fromWireType:s=>{var n=bt.toValue(s);return ji(s),n},toWireType:(s,n)=>bt.toHandle(n),argPackAdvance:B,readValueFromPointer:Be,destructorFunction:null},Vi=s=>U(s,Bi),Zi=(s,n,a)=>{switch(n){case 1:return a?function(u){return this.fromWireType(k[u])}:function(u){return this.fromWireType(E[u])};case 2:return a?function(u){return this.fromWireType(X[u>>1])}:function(u){return this.fromWireType(ye[u>>1])};case 4:return a?function(u){return this.fromWireType(ae[u>>2])}:function(u){return this.fromWireType(M[u>>2])};default:throw new TypeError(`invalid integer width (${n}): ${s}`)}},qi=(s,n,a,u)=>{n=L(n);function g(){}g.values={},U(s,{name:n,constructor:g,fromWireType:function(m){return this.constructor.values[m]},toWireType:(m,v)=>v.value,argPackAdvance:B,readValueFromPointer:Zi(n,a,u),destructorFunction:null}),mt(n,g)},Xi=(s,n)=>{var a=Q[s];return a===void 0&&I(`${n} has unknown type ${Rr(s)}`),a},Yi=(s,n,a)=>{var u=Xi(s,"enum");n=L(n);var g=u.constructor,m=Object.create(u.constructor.prototype,{value:{value:a},constructor:{value:$e(`${u.name}_${n}`,function(){})}});g.values[a]=m,g[n]=m},Ki=(s,n)=>{switch(n){case 4:return function(a){return this.fromWireType(ar[a>>2])};case 8:return function(a){return this.fromWireType(ur[a>>3])};default:throw new TypeError(`invalid float width (${n}): ${s}`)}},Gi=(s,n,a)=>{n=L(n),U(s,{name:n,fromWireType:u=>u,toWireType:(u,g)=>g,argPackAdvance:B,readValueFromPointer:Ki(n,a),destructorFunction:null})},Ji=(s,n,a,u,g,m,v,p)=>{var b=vt(n,a);s=L(s),s=Wr(s),g=V(u,g),mt(s,function(){ue(`Cannot call ${s} due to unbound types`,b)},n-1),Y([],b,w=>{var x=[w[0],null].concat(w.slice(1));return Ar(s,yt(s,x,null,g,m,v),n-1),[]})},Qi=(s,n,a,u,g)=>{n=L(n);var m=x=>x;if(u===0){var v=32-8*a;m=x=>x<<v>>>v}var p=n.includes("unsigned"),b=(x,_)=>{},w;p?w=function(x,_){return b(_,this.name),_>>>0}:w=function(x,_){return b(_,this.name),_},U(s,{name:n,fromWireType:m,toWireType:w,argPackAdvance:B,readValueFromPointer:wr(n,a,u!==0),destructorFunction:null})},eo=(s,n,a)=>{var u=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array],g=u[n];function m(v){var p=M[v>>2],b=M[v+4>>2];return new g(k.buffer,b,p)}a=L(a),U(s,{name:a,fromWireType:m,argPackAdvance:B,readValueFromPointer:m},{ignoreDuplicateRegistrations:!0})},to=(s,n,a,u)=>{if(!(u>0))return 0;for(var g=a,m=a+u-1,v=0;v<s.length;++v){var p=s.charCodeAt(v);if(p>=55296&&p<=57343){var b=s.charCodeAt(++v);p=65536+((p&1023)<<10)|b&1023}if(p<=127){if(a>=m)break;n[a++]=p}else if(p<=2047){if(a+1>=m)break;n[a++]=192|p>>6,n[a++]=128|p&63}else if(p<=65535){if(a+2>=m)break;n[a++]=224|p>>12,n[a++]=128|p>>6&63,n[a++]=128|p&63}else{if(a+3>=m)break;n[a++]=240|p>>18,n[a++]=128|p>>12&63,n[a++]=128|p>>6&63,n[a++]=128|p&63}}return n[a]=0,a-g},ro=(s,n,a)=>to(s,E,n,a),no=s=>{for(var n=0,a=0;a<s.length;++a){var u=s.charCodeAt(a);u<=127?n++:u<=2047?n+=2:u>=55296&&u<=57343?(n+=4,++a):n+=3}return n},kr=typeof TextDecoder<"u"?new TextDecoder:void 0,so=(s,n=0,a=NaN)=>{for(var u=n+a,g=n;s[g]&&!(g>=u);)++g;if(g-n>16&&s.buffer&&kr)return kr.decode(s.subarray(n,g));for(var m="";n<g;){var v=s[n++];if(!(v&128)){m+=String.fromCharCode(v);continue}var p=s[n++]&63;if((v&224)==192){m+=String.fromCharCode((v&31)<<6|p);continue}var b=s[n++]&63;if((v&240)==224?v=(v&15)<<12|p<<6|b:v=(v&7)<<18|p<<12|b<<6|s[n++]&63,v<65536)m+=String.fromCharCode(v);else{var w=v-65536;m+=String.fromCharCode(55296|w>>10,56320|w&1023)}}return m},io=(s,n)=>s?so(E,s,n):"",oo=(s,n)=>{n=L(n);var a=n==="std::string";U(s,{name:n,fromWireType(u){var g=M[u>>2],m=u+4,v;if(a)for(var p=m,b=0;b<=g;++b){var w=m+b;if(b==g||E[w]==0){var x=w-p,_=io(p,x);v===void 0?v=_:(v+="\0",v+=_),p=w+1}}else{for(var S=new Array(g),b=0;b<g;++b)S[b]=String.fromCharCode(E[m+b]);v=S.join("")}return Z(u),v},toWireType(u,g){g instanceof ArrayBuffer&&(g=new Uint8Array(g));var m,v=typeof g=="string";v||g instanceof Uint8Array||g instanceof Uint8ClampedArray||g instanceof Int8Array||I("Cannot pass non-string to std::string"),a&&v?m=no(g):m=g.length;var p=$t(4+m+1),b=p+4;if(M[p>>2]=m,a&&v)ro(g,b,m+1);else if(v)for(var w=0;w<m;++w){var x=g.charCodeAt(w);x>255&&(Z(b),I("String has UTF-16 code units that do not fit in 8 bits")),E[b+w]=x}else for(var w=0;w<m;++w)E[b+w]=g[w];return u!==null&&u.push(Z,p),p},argPackAdvance:B,readValueFromPointer:Be,destructorFunction(u){Z(u)}})},Lr=typeof TextDecoder<"u"?new TextDecoder("utf-16le"):void 0,ao=(s,n)=>{for(var a=s,u=a>>1,g=u+n/2;!(u>=g)&&ye[u];)++u;if(a=u<<1,a-s>32&&Lr)return Lr.decode(E.subarray(s,a));for(var m="",v=0;!(v>=n/2);++v){var p=X[s+v*2>>1];if(p==0)break;m+=String.fromCharCode(p)}return m},co=(s,n,a)=>{if(a??(a=2147483647),a<2)return 0;a-=2;for(var u=n,g=a<s.length*2?a/2:s.length,m=0;m<g;++m){var v=s.charCodeAt(m);X[n>>1]=v,n+=2}return X[n>>1]=0,n-u},lo=s=>s.length*2,uo=(s,n)=>{for(var a=0,u="";!(a>=n/4);){var g=ae[s+a*4>>2];if(g==0)break;if(++a,g>=65536){var m=g-65536;u+=String.fromCharCode(55296|m>>10,56320|m&1023)}else u+=String.fromCharCode(g)}return u},fo=(s,n,a)=>{if(a??(a=2147483647),a<4)return 0;for(var u=n,g=u+a-4,m=0;m<s.length;++m){var v=s.charCodeAt(m);if(v>=55296&&v<=57343){var p=s.charCodeAt(++m);v=65536+((v&1023)<<10)|p&1023}if(ae[n>>2]=v,n+=4,n+4>g)break}return ae[n>>2]=0,n-u},ho=s=>{for(var n=0,a=0;a<s.length;++a){var u=s.charCodeAt(a);u>=55296&&u<=57343&&++a,n+=4}return n},go=(s,n,a)=>{a=L(a);var u,g,m,v;n===2?(u=ao,g=co,v=lo,m=p=>ye[p>>1]):n===4&&(u=uo,g=fo,v=ho,m=p=>M[p>>2]),U(s,{name:a,fromWireType:p=>{for(var b=M[p>>2],w,x=p+4,_=0;_<=b;++_){var S=p+4+_*n;if(_==b||m(S)==0){var O=S-x,F=u(x,O);w===void 0?w=F:(w+="\0",w+=F),x=S+n}}return Z(p),w},toWireType:(p,b)=>{typeof b!="string"&&I(`Cannot pass non-string to C++ string type ${a}`);var w=v(b),x=$t(4+w+n);return M[x>>2]=w/n,g(b,x+4,w+n),p!==null&&p.push(Z,x),x},argPackAdvance:B,readValueFromPointer:Be,destructorFunction(p){Z(p)}})},po=(s,n)=>{n=L(n),U(s,{isVoid:!0,name:n,argPackAdvance:0,fromWireType:()=>{},toWireType:(a,u)=>{}})},mo=()=>2147483648,vo=(s,n)=>Math.ceil(s/n)*n,yo=s=>{var n=R.buffer,a=(s-n.byteLength+65535)/65536|0;try{return R.grow(a),fr(),1}catch{}},Po=s=>{var n=E.length;s>>>=0;var a=mo();if(s>a)return!1;for(var u=1;u<=4;u*=2){var g=n*(1+.2/u);g=Math.min(g,s+100663296);var m=Math.min(a,vo(Math.max(s,g),65536)),v=yo(m);if(v)return!0}return!1};gi(),le=o.BindingError=class extends Error{constructor(n){super(n),this.name="BindingError"}},$r=o.InternalError=class extends Error{constructor(n){super(n),this.name="InternalError"}},_i(),Mi(),Er=o.UnboundTypeError=Wi(Error,"UnboundTypeError"),Ni();var bo={i:di,q:hi,n:mi,o:vi,g:Di,f:Oi,a:Hi,e:zi,s:Vi,j:qi,c:Yi,m:Gi,b:Ji,h:Qi,d:eo,l:oo,k:go,p:po,r:Po},G=ui(),Or=s=>(Or=G.v)(s),$t=s=>($t=G.x)(s),Z=s=>(Z=G.y)(s),qe;Pe=function s(){qe||Hr(),qe||(Pe=s)};function Hr(){if(J>0||(Gs(),J>0))return;function s(){var n;qe||(qe=!0,o.calledRun=!0,!D&&(Js(),d(o),(n=o.onRuntimeInitialized)==null||n.call(o),Qs()))}o.setStatus?(o.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>o.setStatus(""),1),s()},1)):s()}if(o.preInit)for(typeof o.preInit=="function"&&(o.preInit=[o.preInit]);o.preInit.length>0;)o.preInit.pop()();Hr();function $o(s){if(s.length%2!=0)throw"MakePath64: intArray.length must be even";var n=s.map(function(u){return typeof u!="bigint"?BigInt(u):u});let a=new o.Path64;for(let u=0;u<n.length;u+=2){let g=new o.Point64(n[u],n[u+1],BigInt(0));a.push_back(g)}return a}o.MakePath64=$o;function wo(s){if(s.length%3!=0)throw"MakePathZ64: intArray.length must be multiple of 3";var n=s.map(function(u){return typeof u!="bigint"?BigInt(u):u});let a=new o.Path64;for(let u=0;u<n.length;u+=3){let g=new o.Point64(n[u],n[u+1],n[u+2]);a.push_back(g)}return a}o.MakePathZ64=wo;function xo(s){if(s.length%2!=0)throw"MakePathD: intArray.length must be even";let n=new o.PathD;for(let a=0;a<s.length;a+=2){let u=new o.PointD(s[a],s[a+1],0);n.push_back(u)}return n}o.MakePathD=xo;function _o(s){if(s.length%3!=0)throw"MakePathZD: intArray.length must be multiple of 3";let n=new o.PathD;for(let a=0;a<s.length;a+=3){let u=new o.PointD(s[a],s[a+1],s[a+2]);n.push_back(u)}return n}o.MakePathZD=_o;function zr(s){let n=new o.Path64;for(let a=0;a<s.size();a++){const u=s.get(a),g=typeof u.x!="bigint"?BigInt(Math.round(u.x)):u.x,m=typeof u.y!="bigint"?BigInt(Math.round(u.y)):u.y,v=typeof u.z!="bigint"?BigInt(Math.round(u.z)):u.z;let p=new o.Point64(g,m,v);n.push_back(p)}return n}o.PathDToPath64=zr;function jr(s){let n=new o.PathD;for(let a=0;a<s.size();a++){const u=s.get(a);let g=new o.PointD(Number(u.x),Number(u.y),Number(u.z));n.push_back(g)}return n}o.Path64ToPathD=jr;function To(s){let n=new o.PathsD;for(let a=0;a<s.size();a++){const u=s.get(a);let g=jr(u);n.push_back(g)}return n}o.Paths64ToPathsD=To;function Co(s){let n=new o.Paths64;for(let a=0;a<s.size();a++){const u=s.get(a);let g=zr(u);n.push_back(g)}return n}return o.PathsDToPaths64=Co,f=y,f})})();e.exports=r})(Xe)),Xe.exports}var _t=Xr(),Yr=qr(_t),Kr=Zr({__proto__:null,default:Yr},[_t]),Gr=""+new URL("assets/clipper2z-bvMLVKp3.wasm",self.location.href).href;const Ye=1e6,Jr=(e=>{if(typeof e=="function")return e;if(e&&typeof e=="object"){const t=e;if(typeof t.default=="function")return t.default;if(typeof t.Clipper2ZFactory=="function")return t.Clipper2ZFactory;const r=t.default;if(r&&typeof r=="object"){const i=r;if(typeof i.default=="function")return i.default}}throw new Error("Clipper2-WASM factory could not be resolved.")})(Kr);let te,Tt;const Qr=async()=>te||(Tt??(Tt=Jr({locateFile:e=>e.endsWith(".wasm")?Gr:e})),te=await Tt,te),xe=()=>{if(!te)throw new Error("Clipper2 kernel is not initialized. Call initClipperKernel() before using geometry kernel operations.");return te},Ct=e=>BigInt(Math.round(e*Ye)),It=e=>Number(e)/Ye,en=(e,t)=>{const r=new e.Path64;for(const i of t){const c=new e.Point64(Ct(i[0]),Ct(i[1]),0n);r.push_back(c),c.delete()}return r},re=(e,t)=>{const r=new e.Paths64,i=[];for(const c of t){const l=en(e,c);r.push_back(l),i.push(l)}return{paths:r,release:()=>{for(const c of i)c.delete();r.delete()}}},At=e=>{const t=[];for(let r=0;r<e.size();r+=1){const i=e.get(r);t.push([It(i.x),It(i.y)]),i.delete()}return t},Ke=e=>{const t=[];for(let r=0;r<e.size();r+=1){const i=e.get(r);t.push(At(i)),i.delete()}return t},St=1e-5,Et=(e,t)=>{const r=t[0]-e[0],i=t[1]-e[1];return r*r+i*i},H=e=>{let t=0;for(let r=0;r<e.length;r+=1){const i=e[r],c=e[(r+1)%e.length];t+=i[0]*c[1]-c[0]*i[1]}return t/2},ne=e=>{let t=1/0,r=1/0,i=-1/0,c=-1/0;for(const l of e)t=Math.min(t,l[0]),r=Math.min(r,l[1]),i=Math.max(i,l[0]),c=Math.max(c,l[1]);return Number.isFinite(t)?{min:[t,r],max:[i,c]}:{min:[0,0],max:[0,0]}},tn=(e,t,r)=>{const i=t[0]-e[0],c=t[1]-e[1],l=r[0]-t[0],f=r[1]-t[1];return i*f-c*l},Rt=(e,t)=>{const r=t*t,i=[];for(const c of e){const l=i[i.length-1];(!l||Et(l,c)>r)&&i.push(c)}return i.length>1&&Et(i[0],i[i.length-1])<=r&&i.pop(),i},_e=(e,t=St)=>Rt(e,t),rn=(e,t)=>{if(e.length<3)return[...e];const r=[];for(let i=0;i<e.length;i+=1){const c=e[(i-1+e.length)%e.length],l=e[i],f=e[(i+1)%e.length];Math.abs(tn(c,l,f))>t&&r.push(l)}return r.length>=3?r:[...e]},nn=(e,t=St)=>{const r=Rt(e,t);return rn(r,t)},Te=(e,t,r)=>(t[0]-e[0])*(r[1]-e[1])-(t[1]-e[1])*(r[0]-e[0]),Ce=(e,t,r,i)=>Math.min(e[0],r[0])-i<=t[0]&&t[0]<=Math.max(e[0],r[0])+i&&Math.min(e[1],r[1])-i<=t[1]&&t[1]<=Math.max(e[1],r[1])+i,sn=(e,t,r,i,c=1e-9)=>{const l=Te(e,t,r),f=Te(e,t,i),o=Te(r,i,e),d=Te(r,i,t);return Math.abs(l)<=c&&Ce(e,r,t,c)||Math.abs(f)<=c&&Ce(e,i,t,c)||Math.abs(o)<=c&&Ce(r,e,i,c)||Math.abs(d)<=c&&Ce(r,t,i,c)?!0:l>0!=f>0&&o>0!=d>0},on=(e,t,r)=>e===t||Math.abs(e-t)===1||e===0&&t===r-1||t===0&&e===r-1,an=(e,t=1e-9)=>{const r=[];for(let i=0;i<e.length;i+=1){const c=e[i],l=e[(i+1)%e.length];for(let f=i+1;f<e.length;f+=1){if(on(i,f,e.length))continue;const o=e[f],d=e[(f+1)%e.length];sn(c,l,o,d,t)&&r.push([i,f])}}return r},Ge=1e-6,Je=1e-5,cn=1.5,ln=0,un=(e,t,r)=>{const i=t[0]-e[0],c=t[1]-e[1];return i*i+c*c<=r*r},fn=(e,t)=>{const r=H(e);return t&&r<0||!t&&r>0?[...e].reverse():e},dn=(e,t)=>{const r=_e(e,t);return r.length>1&&un(r[0],r[r.length-1],t)&&r.pop(),r},Mt=(e,t,r)=>e.map(i=>dn(i,r)).filter(i=>i.length>=3&&Math.abs(H(i))>t),hn=(e,t,r)=>{const i=[];for(let c=0;c<e.size();c+=1){const l=e.get(c);i.push(At(l)),l.delete()}return Mt(i,t,r)},Ft=(e,t,r)=>{const i=xe(),c=r.areaEpsilon??Ge,l=r.distanceEpsilon??Je,f=r.miterLimit??cn,o=re(i,e);let d;try{const h=Math.round(t*Ye);d=i.InflatePaths64(o.paths,h,i.JoinType.Miter,i.EndType.Polygon,f,ln);const y=hn(d,c,l);return y.length===0?{ok:!1,reason:"offset region collapsed after Clipper2 cleanup",warnings:[]}:{ok:!0,rings:y,warnings:[]}}finally{d==null||d.delete(),o.release()}},gn=(e,t,r={})=>{const i=r.distanceEpsilon??Je,c=r.areaEpsilon??Ge,l=r.side??"inward",f=Math.abs(t),o=_e(e,i);if(o.length<3)return{ok:!1,reason:"source ring collapsed below 3 points",warnings:[]};const d=H(o);if(Math.abs(d)<=c)return{ok:!1,reason:"source ring collapsed to near-zero area",warnings:[]};const h=an(o,i);if(h.length>0)return{ok:!1,reason:`source ring has ${h.length} self intersections`,warnings:[]};if(f<=i)return{ok:!0,rings:[o],warnings:[]};const y=d>=0?1:-1,P=(l==="inward"?-y:y)*f;return Ft([o],P,r)},Ie=(e,t,r={})=>{const i=r.distanceEpsilon??Je,c=r.areaEpsilon??Ge,l=Math.abs(t);if(l<=i){const o=Mt(e.map(d=>[...d.points]),c,i);return o.length>0?{ok:!0,rings:o,warnings:[]}:{ok:!1,reason:"region collapsed below 3 points",warnings:[]}}const f=e.flatMap(o=>{if(o.role==="invalid"||o.role==="open")return[];const d=_e(o.points,i);if(d.length<3||Math.abs(H(d))<=c)return[];const h=o.role!=="hole";return[fn(d,h)]});return f.length===0?{ok:!1,reason:"region has no valid rings",warnings:[]}:Ft(f,-l,r)},pn=1e-6,mn=1e-5,Qe=(e,t)=>{let r=!1;for(let i=0,c=t.length-1;i<t.length;c=i,i+=1){const l=t[i],f=t[c];l[1]>e[1]!=f[1]>e[1]&&e[0]<(f[0]-l[0])*(e[1]-l[1])/(f[1]-l[1])+l[0]&&(r=!r)}return r},vn=e=>e[0]??null,yn=(e,t)=>t[0]>=e.min[0]&&t[0]<=e.max[0]&&t[1]>=e.min[1]&&t[1]<=e.max[1],Pn=(e,t)=>t.min[0]>=e.min[0]&&t.max[0]<=e.max[0]&&t.min[1]>=e.min[1]&&t.max[1]<=e.max[1],bn=e=>e%2===1?"hole":e===0?"outer":"island",$n=(e,t)=>{const r=t%2===0,c=H(e)>=0;return r===c?e:[...e].reverse()},wn=(e,t={})=>{var o;const r=t.areaEpsilon??pn,i=t.distanceEpsilon??mn,c=e.map((d,h)=>{const y=nn(d,i),P=H(y);return{area:P,bounds:ne(y),childIds:[],depth:0,id:`contour-${h}`,points:y,role:y.length<3||Math.abs(P)<=r?"invalid":"outer",sourceIndex:h,winding:P>=0?"ccw":"cw"}}),l=c.filter(d=>d.role!=="invalid");for(const d of l){const h=vn(d.points);if(!h)continue;const y=l.filter($=>$.sourceIndex!==d.sourceIndex&&Math.abs($.area)>Math.abs(d.area)&&Pn($.bounds,d.bounds)&&yn($.bounds,h)&&Qe(h,$.points)).sort(($,A)=>Math.abs($.area)-Math.abs(A.area)),P=y[0];d.parentId=P==null?void 0:P.id,d.depth=y.length}for(const d of l)d.role=bn(d.depth),d.points=$n(d.points,d.depth),d.area=H(d.points),d.winding=d.area>=0?"ccw":"cw",d.bounds=ne(d.points);const f=new Map(l.map(d=>[d.id,d]));for(const d of l)d.parentId&&((o=f.get(d.parentId))==null||o.childIds.push(d.id));return c},xn=(e,t)=>[e.frame.origin[0]+e.frame.xAxis[0]*t[0]+e.frame.yAxis[0]*t[1],e.frame.origin[1]+e.frame.xAxis[1]*t[0]+e.frame.yAxis[1]*t[1],e.frame.origin[2]+e.frame.xAxis[2]*t[0]+e.frame.yAxis[2]*t[1]],et=(e,t)=>wn(t.map(i=>i.points2)).map((i,c)=>{const l=t[i.sourceIndex]??t[c],f=l.points2.length>=3?l.points2:i.points,o=l.points3.length===f.length?l.points3:f.map(h=>xn(e,h)),d=H(f);return{...l,area:d,bounds:ne(f),childIds:i.childIds,closed:i.role!=="open",depth:i.depth,id:`curve-${c}`,parentId:i.parentId,points2:f,points3:o,role:i.role,winding:d>=0?"ccw":"cw"}}),Wt=(e,t)=>Qe(e,t),_n=(e,t,r)=>{const i=r[0]-t[0],c=r[1]-t[1],l=i*i+c*c,f=l===0?0:Math.max(0,Math.min(1,((e[0]-t[0])*i+(e[1]-t[1])*c)/l)),o=t[0]+i*f,d=t[1]+c*f,h=e[0]-o,y=e[1]-d;return Math.sqrt(h*h+y*y)},tt=(e,t)=>{let r=1/0;for(const i of t.curves)if(!(i.role==="invalid"||i.points2.length<2))for(let c=0;c<i.points2.length;c+=1){const l=i.points2[c],f=i.points2[(c+1)%i.points2.length];r=Math.min(r,_n(e,l,f))}return r},Tn=(e,t,r=0)=>t.curves.filter(l=>l.role!=="invalid"&&l.points2.length>=3&&Wt(e,l.points2)).length%2===1&&(r<=0||tt(e,t)>=r),Dt=(e,t,r={})=>{const i=[],c=Ie(e.curves.map(d=>({points:d.points2,role:d.role})),t,r);for(const d of c.warnings)i.push({level:"info",message:`Offset region: ${d}.`});c.ok||i.push({level:"warning",message:`Offset region discarded: ${c.reason}.`});const f=(c.ok?c.rings:[]).map((d,h)=>{const y=e.curves.find(P=>Wt(d[0],P.points2));return{id:`offset-region-${h}`,points2:d,points3:[],closed:!0,role:(y==null?void 0:y.role)??"unknown"}}),o=et(e,f);return{...e,curves:o,diagnostics:[...e.diagnostics,...i,{level:o.length>0?"info":"warning",message:`Inset region by ${t.toFixed(3)} mm: ${o.length} region curves remain from ${e.curves.length} source curves.`}]}},se=(e,t)=>{const r=t??(l=>Tn(l,e)),i=!t;return{contains:r,inset:l=>{if(l<=0)return se(e,t);if(i){const f=Dt(e,l),o=e.curves.filter(h=>h.role!=="invalid"&&h.points2.length>=3).length,d=f.curves.filter(h=>h.role!=="invalid"&&h.points2.length>=3).length;return d>0||o===0?se(f):se({...e,diagnostics:[...f.diagnostics,{level:"warning",message:`Inset region fallback used source contours because ${d}/${o} offset curves remained.`}]},h=>r(h)&&tt(h,e)>=l)}return se(e,f=>r(f)&&tt(f,e)>=l)},section:e,subtract:l=>se(e,f=>r(f)&&!l.contains(f))}},Cn=1e-6,In=1e-5,fe=(e,t={})=>{const r=t.areaEpsilon??Cn,i=t.distanceEpsilon??In;return e.flatMap(c=>{const l=_e(c,i);return l.length<3||Math.abs(H(l))<=r?[]:[l]})},de=(e,t,r,i={})=>{const c=fe(e,i),l=fe(t,i);if(c.length===0)return[];if(l.length===0&&r==="difference"||l.length===0&&r==="union")return c;if(l.length===0)return[];const f=xe(),o=re(f,c),d=re(f,l);let h;try{const y=r==="difference"?f.ClipType.Difference:r==="intersection"?f.ClipType.Intersection:r==="union"?f.ClipType.Union:f.ClipType.Xor;return h=f.BooleanOp64(y,f.FillRule.NonZero,o.paths,d.paths),fe(Ke(h),i)}finally{h==null||h.delete(),d.release(),o.release()}},kt=(e,t={})=>{const r=fe(e,t);if(r.length===0)return[];const i=xe(),c=re(i,r);let l;try{return l=i.UnionSelf64(c.paths,i.FillRule.NonZero),fe(Ke(l),t)}finally{l==null||l.delete(),c.release()}},An=1e-7,Sn=1e-9,rt=(e,t,r)=>[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r],Lt=(e,t)=>Math.hypot(t[0]-e[0],t[1]-e[1]),Ae=(e,t)=>{const r=e.end[0]-e.start[0],i=e.end[1]-e.start[1],c=r*r+i*i;return c<=0?0:((t[0]-e.start[0])*r+(t[1]-e.start[1])*i)/c},En=(e,t,r)=>{const i=Ae(e,t),c=Ae(e,r);return i<=c?{start:t,end:r}:{start:r,end:t}},Rn=(e,t)=>{const r=e.end[0]-e.start[0],i=e.end[1]-e.start[1],c=r*r+i*i;if(c<=0)return Number.POSITIVE_INFINITY;const l=r*(t[1]-e.start[1])-i*(t[0]-e.start[0]);return l*l/c},Mn=(e,t)=>{const r=t.length>1?rt(t[0],t[t.length-1],.5):t[0];let i=0,c=Number.POSITIVE_INFINITY;for(let l=0;l<e.length;l+=1){const f=e[l],o=Ae(f,r),d=o<0?o*o:o>1?(o-1)*(o-1):0,h=Rn(f,r)+d;h<c&&(i=l,c=h)}return i},Fn=(e,t)=>{const r=e[0],i=r.end[0]-r.start[0],c=r.end[1]-r.start[1],l=Math.hypot(i,c);if(l<=t)return;const f=[i/l,c/l],o=[-f[1],f[0]];for(const d of e){const h=d.end[0]-d.start[0],y=d.end[1]-d.start[1],P=Math.hypot(h,y);if(P<=t)return;const $=h/P*f[1]-y/P*f[0];if(Math.abs($)>Sn)return}return(d,h)=>{const P=(h[0]-d[0])*f[0]+(h[1]-d[1])*f[1]>=0?{start:d,end:h}:{start:h,end:d},$=rt(P.start,P.end,.5);return{...P,orderOffset:$[0]*o[0]+$[1]*o[1],orderT:P.start[0]*f[0]+P.start[1]*f[1]}}},Wn=(e,t)=>{const r=Fn(e,t);return r||((i,c,l)=>{const f=Mn(e,l),o=e[f],d=En(o,i,c);return{...d,orderOffset:f,orderT:Ae(o,d.start)}})},nt=(e,t,r,i={})=>{const c=i.epsilon??An,l=i.minLength??c,f=e.filter(C=>Lt(C.start,C.end)>=l),o=t.filter(C=>C.length>=3);if(f.length===0||o.length===0)return[];const d=xe(),h=re(d,f.map(C=>[C.start,C.end])),y=re(d,o),P=new d.Clipper64,$=new d.Paths64,A=new d.Paths64,T=[],W=Wn(f,c);try{P.AddOpenSubject(h.paths),P.AddClip(y.paths),P.ExecutePath(d.ClipType.Intersection,d.FillRule.EvenOdd,$,A);for(const C of Ke(A))if(!(C.length<2))for(let R=1;R<C.length;R+=1){const D=C[R-1],k=C[R];if(Lt(D,k)<l)continue;const E=W(D,k,C),X=rt(E.start,E.end,.5);r(X)&&T.push(E)}}finally{$.delete(),A.delete(),P.delete(),y.release(),h.release()}return T.sort((C,R)=>C.orderOffset-R.orderOffset||C.orderT-R.orderT).map(({orderOffset:C,orderT:R,...D})=>D)},st=(e,t)=>[e.frame.origin[0]+e.frame.xAxis[0]*t[0]+e.frame.yAxis[0]*t[1],e.frame.origin[1]+e.frame.xAxis[1]*t[0]+e.frame.yAxis[1]*t[1],e.frame.origin[2]+e.frame.xAxis[2]*t[0]+e.frame.yAxis[2]*t[1]],Se=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Ot=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],he=(e,t,r=1e-8)=>Math.abs(e-t)<=r,Ht=(e,t,r=1e-8)=>he(e[0],t[0],r)&&he(e[1],t[1],r)&&he(e[2],t[2],r),Dn=(e,t)=>{if(!Ht(e.frame.xAxis,t.frame.xAxis)||!Ht(e.frame.yAxis,t.frame.yAxis))return!1;const r=Ot(t.frame.origin,e.frame.origin);return he(Se(r,e.frame.xAxis),0)&&he(Se(r,e.frame.yAxis),0)},zt=(e,t)=>{const r=Ot(t,e.frame.origin);return[Se(r,e.frame.xAxis),Se(r,e.frame.yAxis)]},kn=e=>e.curves.flatMap(t=>t.role==="invalid"||t.role==="open"||t.points2.length<3?[]:[t.points2]),it=e=>e.curves.flatMap(t=>t.role==="invalid"||t.role==="open"||t.points2.length<3?[]:[{points:t.points2,role:t.role}]),Ln=(e,t)=>it(jt(e,t,"role-source")),jt=(e,t,r)=>{const i=t.map((f,o)=>({id:`${e.id}-${r}-${o}`,points2:[...f],points3:f.map(d=>st(e,d)),closed:!0,role:"unknown"})),c=et(e,i).map(f=>Nt(e,f)),l=c.flatMap(f=>f.points2);return{...e,id:`${e.id}-${r}`,curves:c,openCurves:[],rawCurves:void 0,intersectionLines:void 0,bounds:l.length>0?ne(l):{min:[0,0],max:[0,0]}}},Ut=e=>ne(e.flatMap(t=>[...t])),Ee=(e,t)=>({bounds:e.bounds,diagnostics:e.diagnostics,frame:e.frame,id:`${e.id}-${t}`,rings:kn(e),source:e}),On=(e,t,r={})=>{const i={origin:[0,0,e],xAxis:[1,0,0],yAxis:[0,1,0],normal:[0,0,1]},c=t.map((d,h)=>({id:`${r.id??"path-region"}-${h}`,points2:[...d],points3:d.map(([y,P])=>[y,P,e]),closed:!0,role:"unknown"})),l={id:r.id??`path-region-${e.toFixed(3)}`,spec:{kind:"plane",origin:i.origin,normal:i.normal,xAxis:i.xAxis},frame:i,curves:[],openCurves:[],bounds:Ut(t),diagnostics:[]},f=et(l,c).map(d=>Nt(l,d)),o=f.flatMap(d=>d.points2);return{...l,curves:f,bounds:o.length>0?ne(o):l.bounds}},Re=(e,t)=>{const r=[...e];if(r.length<3)return r;const i=!t,c=H(r)>=0;return i===c?r:r.reverse()},Nt=(e,t)=>{if(t.role==="invalid"||t.role==="open"||t.points2.length<3)return t;const r=t.role!=="hole",i=H(t.points2)>=0,c=r===i?[...t.points2]:[...t.points2].reverse();return{...t,area:H(c),points2:c,points3:c.map(l=>st(e,l)),winding:H(c)>=0?"ccw":"cw"}},Hn=(e,t={})=>{const r=[];let i;const c=()=>{i=void 0},l=()=>(i??(i=Ee(On(e,r,t),"region")),i),f={get bounds(){return l().bounds},get frame(){return l().frame},get id(){return l().id},get rings(){return l().rings},get source(){return l().source},circle:(o,d,h={})=>{const y=Math.max(8,Math.round(h.segments??64)),P=Array.from({length:y},($,A)=>{const T=A/y*Math.PI*2;return[o[0]+Math.cos(T)*d,o[1]+Math.sin(T)*d]});return r.push(Re(P,h.hole)),c(),f},fill:o=>Qt(l(),o),hole:o=>(r.push(Re(o,!0)),c(),f),inset:o=>{const d=l();if(o<=0)return d;const h=Ie(it(d.source),o);return ge(d,h.ok?h.rings:[],`inset-${o.toFixed(3)}`,h.warnings.map(y=>({level:"info",message:`Offset region: ${y}.`})))},polygon:(o,d={})=>(r.push(Re(o,d.hole)),c(),f),ring:(o,d={})=>(r.push(Re(o,d.hole)),c(),f),toRegion:l,toSection:()=>l().source};return f},ge=(e,t,r,i=[])=>{const c="source"in e?e.source:e,l=t.map(f=>[...f]);return{bounds:Ut(l),diagnostics:i,frame:e.frame,id:`${e.id}-${r}`,rings:l,source:c}},pe=(e,t)=>({...jt(e.source,e.rings,`${e.id}-${t}`),diagnostics:[...e.source.diagnostics,...e.diagnostics]}),Me=e=>{let t;return()=>(t??(t=e()),t)},zn=(e,t)=>{const r=Me(()=>pe(e.bottom,"section")),i=Me(()=>pe(e.sparse,"section")),c=Me(()=>pe(e.top,"section")),l=Me(()=>pe(t,"section"));return{get bottom(){return r()},get inset(){return l()},get sparse(){return i()},get top(){return c()}}},jn=(e,t)=>Dn(e.source,t.source)?t.rings:t.rings.map(r=>r.map(i=>zt(e.source,st(t.source,i)))),ot=(e,t)=>{const r=Math.cos(t),i=Math.sin(t);return[e[0]*r-e[1]*i,e[0]*i+e[1]*r]},Bt=(e,t)=>ot(e,-t),Un=(e,t)=>{let r=1/0,i=1/0,c=-1/0,l=-1/0;for(const f of e)for(const o of f){const d=ot(o,t);r=Math.min(r,d[0]),i=Math.min(i,d[1]),c=Math.max(c,d[0]),l=Math.max(l,d[1])}return Number.isFinite(r)?{min:[r,i],max:[c,l]}:{min:[0,0],max:[0,0]}},Fe=(e,t)=>{const r=Math.max(0,Math.min(1,e));return r<=0?1/0:r>=1?t:Math.max(t,t/r)},Nn=(e,t,r,i,c=0)=>{const l=t-e,f=(e+t)/2;if(i!==void 0&&Number.isFinite(i)){const y=Math.floor((e-i-c)/r),P=Math.ceil((t-i-c)/r);return Array.from({length:Math.max(1,P-y+1)},($,A)=>i+c+(y+A)*r)}if(l<=0)return[f];const o=Math.max(1,Math.ceil(l/r)),d=(o-1)*r,h=f-d/2;return Array.from({length:o},(y,P)=>h+P*r)},Bn=(e,t)=>{const r=(t==null?void 0:t.anchor)??"build",i=t==null?void 0:t.origin;if(r==="section")return[typeof(i==null?void 0:i[0])=="number"?i[0]:0,typeof(i==null?void 0:i[1])=="number"?i[1]:0];const c=[typeof(i==null?void 0:i[0])=="number"?i[0]:0,typeof(i==null?void 0:i[1])=="number"?i[1]:0,typeof(i==null?void 0:i[2])=="number"?i[2]:0];return zt(e,c)},Vn=(e,t,r)=>{if((t==null?void 0:t.anchor)!=="regionCenter")return ot(Bn(e,t),r)[1]},ie=(e,t)=>Math.hypot(t[0]-e[0],t[1]-e[1]),Zn=(e,t,r=1e-7)=>ie(e,t)<=r,Vt=e=>ie(e.start,e.end),qn=(e,t,r)=>{const i=r[0]-t[0],c=r[1]-t[1],l=i*i+c*c,f=l<=0?0:Math.max(0,Math.min(1,((e[0]-t[0])*i+(e[1]-t[1])*c)/l)),o=[t[0]+i*f,t[1]+c*f];return ie(e,o)},Xn=(e,t,r=1e-5)=>{for(const i of t)if(!(i.length<2)){for(let c=0;c<i.length;c+=1)if(qn(e,i[c],i[(c+1)%i.length])<=r)return!0}return!1},Yn=(e,t)=>Xn(e,t)?!0:t.filter(r=>r.length>=3&&Qe(e,r)).length%2===1,Kn=(e,t,r)=>{for(let i=1;i<10;i+=1){const c=i/10,l=[e[0]+(t[0]-e[0])*c,e[1]+(t[1]-e[1])*c];if(!Yn(l,r))return!1}return!0},Gn=(e,t,r)=>{const i={start:e,end:t},c=Vt(i);return c<=1e-7?!0:nt([i],r,()=>!0,{minLength:1e-6}).reduce((f,o)=>f+Vt(o),0)>=c-1e-5||Kn(e,t,r)},Zt=new WeakMap,qt=new WeakMap,Jn=e=>e.toFixed(6),oe=(e,t)=>{let r=Zt.get(e);r||(r=new Map,Zt.set(e,r));const i=Jn(t),c=r.get(i);if(c)return c;if(t<=0){const h=Ee(e,"fill-region");return r.set(i,h),h}const l=[],f=Ie(it(e),t);for(const h of f.warnings)l.push({level:"info",message:`Offset region: ${h}.`});f.ok||l.push({level:"warning",message:`Offset region discarded: ${f.reason}.`});const o=f.ok?f.rings:[],d=ge(e,o,"fill-inset",[...l,{level:o.length>0?"info":"warning",message:`Inset region by ${t.toFixed(3)} mm: ${o.length} region curves remain from ${e.curves.length} source curves.`}]);return r.set(i,d),d},Xt=(e,t,r,i,c,l)=>{const f=Math.max(1,Math.round(c));let o=null;for(let d=1;d<=f;d+=1){const h=e[t+i*d];if(!h)return[];const y=oe(h,l),P=jn(r,y);if(P.length===0)return[];if(o=o===null?kt(P):de(o,P,"intersection"),o.length===0)return[]}return o??[]},Qn=(e,t,r,i,c)=>{const l=r.rings,f=Xt(e,t,r,-1,i,c),o=Xt(e,t,r,1,i,c),d=de(l,f,"difference"),h=de(l,o,"difference"),y=de(h,d,"difference"),P=kt([...d,...y]),$=de(l,P,"difference");return{bottom:ge(r,d,"bottom-region"),sparse:ge(r,$,"sparse-region"),top:ge(r,y,"top-region")}},We=(e,t,r,i,c)=>{let l=qt.get(r);l||(l=new Map,qt.set(r,l));const f=`${t}:${Math.max(1,Math.round(i))}`,o=l.get(f);if(o)return o;const d=Qn(e,t,r,i,c);return l.set(f,d),d},es=(e,t,r)=>ss(e,t,ts(e,t,r)),ts=(e,t,r)=>at(e,t,r),at=(e,t,r)=>{var P;const i=t.spacing??Fe(t.density??.18,t.lineWidth);if(!Number.isFinite(i)||i<=0)return[];const c=(t.angle??0)*Math.PI/180,l=Un(r.rings,c),f=l.min[0]-t.lineWidth,o=l.max[0]+t.lineWidth,d=r.rings,h=Vn(e,t.field,c);return Nn(l.min[1],l.max[1],i,h,((P=t.field)==null?void 0:P.phase)??0).map($=>({start:Bt([f,$],c),end:Bt([o,$],c)})).flatMap(($,A)=>nt([$],d,()=>!0,{minLength:Math.max(t.lineWidth*.25,.001)}).map(T=>({...T,scanIndex:A})))},rs=e=>e.lineWidth*e.layerHeight*(e.role&&e.role!=="infill"?.42:.35),ns=e=>e.role&&e.role!=="infill"?2600:3200,ct=(e,t,r,i,c,l=!1)=>({id:`${t.idPrefix??`layer-${t.layerIndex}-${t.role??"infill"}${c?`-${c}`:""}`}-${i}`,role:t.role??"infill",order:l?i:void 0,layerIndex:t.layerIndex,z:e.frame.origin[2],closed:!1,points:r.map(([f,o])=>({x:f,y:o,z:0})),extrusion:{width:t.lineWidth,height:t.layerHeight,flow:rs(t)},speed:ns(t)}),ss=(e,t,r,i)=>r.map((c,l)=>ct(e,t,[c.start,c.end],l,i)),Yt=e=>{const t=e*Math.PI/180;return[Math.cos(t),Math.sin(t)]},De=(e,t)=>e[0]*t[0]+e[1]*t[1],is=(e,t)=>{const r=Yt(t),i=e.map(l=>{const f=De(l.start,r);return{endT:De(l.end,r),scanIndex:l.scanIndex,segment:l,startT:f}}).sort((l,f)=>l.scanIndex-f.scanIndex||Math.min(l.startT,l.endT)-Math.min(f.startT,f.endT)),c=[];for(const l of i){const f=c[c.length-1];f&&f[0].scanIndex===l.scanIndex?f.push(l):c.push([l])}return c.map(l=>[...l].sort((f,o)=>Math.min(f.startT,f.endT)-Math.min(o.startT,o.endT)))},os=(e,t)=>t?{start:e.end,end:e.start}:{start:e.start,end:e.end},Kt=(e,t)=>{const r=Yt(t),i=[];let c;for(const l of is(e,t)){const f=[...l];for(;f.length>0;){let o=0,d=!1,h=Number.POSITIVE_INFINITY;for(let $=0;$<f.length;$+=1){const{segment:A}=f[$],T=c?[{distance:ie(c,A.start),startAtEnd:!1},{distance:ie(c,A.end),startAtEnd:!0}]:[{distance:De(A.start,r),startAtEnd:!1},{distance:De(A.end,r),startAtEnd:!0}],W=T[0].distance<=T[1].distance?T[0]:T[1];W.distance<h&&(h=W.distance,o=$,d=W.startAtEnd)}const[y]=f.splice(o,1),P=os(y.segment,d);i.push(P),c=P.end}}return i},as=(e,t,r)=>Kt(at(e,t,r),t.angle??0).map((i,c)=>ct(e,t,[i.start,i.end],c,"monotonic-line",!0)),Gt=(e,t,r)=>{const i=t.spacing??Fe(t.density??.18,t.lineWidth),c=(Number.isFinite(i)?i:t.lineWidth)*2.5+t.lineWidth,l=Kt(at(e,t,r),t.angle??0),f=[];let o=[];const d=()=>{o.length>=2&&f.push(ct(e,t,o,f.length,"monotonic",!0)),o=[]};for(const h of l){if(o.length===0){o=[h.start,h.end];continue}const y=o[o.length-1];ie(y,h.start)<=c&&Gn(y,h.start,r.rings)?(Zn(y,h.start)||o.push(h.start),o.push(h.end)):(d(),o=[h.start,h.end])}return d(),f},cs=(e,t,r)=>{const i=t.spacing??Fe(t.density??.18,t.lineWidth);if(!Number.isFinite(i)||i<=0)return[];const c=[];let l=r.rings,f=0;const o=1e3;for(;l.length>0&&f<o;){for(const h of l)h.length<3||c.push({id:`${t.idPrefix??`layer-${t.layerIndex}-${t.role??"infill"}-concentric`}-${f}-${c.length}`,role:t.role??"infill",layerIndex:t.layerIndex,z:e.frame.origin[2],closed:!0,points:h.map(([y,P])=>({x:y,y:P,z:0})),extrusion:{width:t.lineWidth,height:t.layerHeight,flow:t.lineWidth*t.layerHeight*(t.role&&t.role!=="infill"?.42:.35)},speed:t.role&&t.role!=="infill"?2600:3200});const d=Ie(Ln(e,l),i);l=d.ok?d.rings:[],f+=1}return c},q=(e,t,r)=>{const i=t.pattern??(t.role==="bottom"?"monotonic":t.role==="solidInfill"||t.role==="top"?"monotonicLine":"rectilinear");if(i==="concentric")return cs(e,t,r);if(i==="monotonic")return Gt(e,t,r);if(i==="monotonicLine")return as(e,t,r);const c=t.angle??(i==="rectilinear"?45:0);if(i==="rectilinear")return Gt(e,{...t,angle:c+(t.layerIndex%2===0?0:90)},r);const l=i==="grid"?[0,90]:i==="triangles"?[0,60,120]:[0],f=t.spacing??Fe(t.density??.18,t.lineWidth);return!Number.isFinite(f)||f<=0?[]:l.flatMap((o,d)=>es(e,{...t,angle:c+o,idPrefix:`${t.idPrefix??`layer-${t.layerIndex}-${t.role??"infill"}-${i}`}-${d}`,spacing:f},r))},ls=e=>typeof e=="object"&&e!==null&&"toRegion"in e&&typeof e.toRegion=="function",us=e=>typeof e=="object"&&e!==null&&"rings"in e&&"source"in e&&"frame"in e,Jt=e=>ls(e)?e.toRegion():us(e)?e:"section"in e?Ee(e.section,"fill-region"):Ee(e,"fill-region"),Qt=(e,t)=>{const r=Jt(e);return q(r.source,{angle:t.angle,density:t.density??1,field:t.field,layerHeight:t.layerHeight??.2,layerIndex:t.layerIndex??0,lineWidth:t.lineWidth??.44,pattern:t.pattern,role:t.role??"infill",spacing:t.spacing},r)},me=(e,t)=>{if(t)for(const r of e.diagnostics)t(r.message,r.level)},fs=(e,t)=>{const r=oe(e,t.margin??0);return me(r,t.onDiagnostic),q(e,t,r)},ds=(e,t,r)=>{const i=e.map((c,l)=>pe(Jt(c),`region-layer-${l}`));return er(i,t,r)},hs=(e,t,r)=>{const i=e[t];if(!i)return[];const c=r.solidLayers??3,l=r.margin??0,f=oe(i,l);me(f,r.onDiagnostic);const o=We(e,t,f,c,l);return q(i,r,o.sparse)},er=(e,t,r)=>{const i=e[t];if(!i)throw new Error(`fillLayer layerIndex is out of range: ${t}`);const c=r.solidLayers??3,l=r.layerIndex??t,f=r.margin??0,o=oe(i,f);me(o,r.onDiagnostic);const d=We(e,t,o,c,f),h=q(i,{angle:r.bottomAngle??45,field:r.field,layerHeight:r.layerHeight,layerIndex:l,lineWidth:r.lineWidth,margin:r.margin,role:"bottom",spacing:r.lineWidth,pattern:r.bottomPattern??r.pattern},d.bottom),y=q(i,{angle:r.topAngle??-45,field:r.field,layerHeight:r.layerHeight,layerIndex:l,lineWidth:r.lineWidth,margin:r.margin,role:"top",spacing:r.lineWidth,pattern:r.topPattern??r.pattern},d.top),P=q(i,{angle:r.sparseAngle,density:r.density??.18,field:r.field,layerHeight:r.layerHeight,layerIndex:l,lineWidth:r.lineWidth,margin:r.margin,role:"infill",pattern:r.sparsePattern??r.pattern,spacing:r.sparseSpacing},d.sparse);return{bottom:h,get paths(){return[...h,...y,...P]},regions:zn(d,o),sparse:P,top:y}},gs=(e,t,r)=>{const i=e[t];if(!i)return[];const c=r.solidLayers??3,l=r.margin??0,f=oe(i,l);me(f,r.onDiagnostic);const o=We(e,t,f,c,l);return q(i,{angle:r.angle??45,field:r.field,layerHeight:r.layerHeight,layerIndex:r.layerIndex??t,lineWidth:r.lineWidth,margin:r.margin,pattern:r.pattern,role:"bottom",spacing:r.lineWidth},o.bottom)},ps=(e,t,r)=>{const i=e[t];if(!i)return[];const c=r.solidLayers??3,l=r.margin??0,f=oe(i,l);me(f,r.onDiagnostic);const o=We(e,t,f,c,l);return q(i,{angle:r.angle??-45,field:r.field,layerHeight:r.layerHeight,layerIndex:r.layerIndex??t,lineWidth:r.lineWidth,margin:r.margin,pattern:r.pattern,role:"top",spacing:r.lineWidth},o.top)},tr=e=>Array.isArray(e)?e.flatMap(t=>tr(t)):[e],lt=(e,t=e.points)=>({...e,points:t.map(r=>({...r}))}),rr=(e,t)=>{const r=t.x-e.x,i=t.y-e.y,c=t.z-e.z;return Math.sqrt(r*r+i*i+c*c)},ms=(e,t,r)=>({x:e.x+(t.x-e.x)*r,y:e.y+(t.y-e.y)*r,z:e.z+(t.z-e.z)*r}),vs=e=>{const t=e.closed?[...e.points,e.points[0]]:e.points,r=[];for(let i=1;i<t.length;i+=1)r.push([t[i-1],t[i]]);return r},ys=(e,t)=>{const r=e[Math.max(0,t-1)]??e[t],i=e[Math.min(e.length-1,t+1)]??e[t],c=i.x-r.x,l=i.y-r.y,f=Math.hypot(c,l)||1;return{x:c/f,y:l/f}},Ps=(e,t)=>{const r=ys(e,t);return{x:-r.y,y:r.x}},ut=(e,t)=>{let r=0;const i=e.points.map((c,l,f)=>{l>0&&(r+=rr(f[l-1],c));const o=Ps(f,l),d=t(r,l);return{...c,x:c.x+o.x*d,y:c.y+o.y*d}});return lt(e,i)},bs=e=>{let t=e>>>0;return()=>(t=1664525*t+1013904223>>>0,t/4294967295)},$s=({spacing:e})=>{const t=Math.max(.001,e);return r=>{if(r.points.length<2)return lt(r);const i=[];for(const[c,l]of vs(r)){const f=rr(c,l),o=Math.max(1,Math.ceil(f/t));i.length===0&&i.push({...c});for(let d=1;d<=o;d+=1){const h=d/o;i.push(ms(c,l,h))}}return r.closed&&i.pop(),lt(r,i)}},ws=({amplitude:e,wavelength:t})=>{const r=Math.max(.001,t);return i=>ut(i,c=>e*Math.sin(c/r*Math.PI*2))},xs=({amplitude:e,wavelength:t})=>{const r=Math.max(.001,t);return i=>ut(i,c=>{const l=c/r%1,f=l<.5?l*4-1:3-l*4;return e*f})},_s=({amplitude:e,frequency:t=1,seed:r=1})=>{const i=bs(r);return c=>{const l=c.points.map(()=>(i()*2-1)*e);return ut(c,(f,o)=>{const d=Math.sin(f*t);return l[o]*d})}},nr=(e,t)=>{const r=Array.isArray(t)?t:[t];return tr(e).map(i=>r.reduce((c,l)=>l(c),i))},Ts=new Set(["outerWall","innerWall","infill","solidInfill","top","bottom","support"]),Cs={bottom:2400,infill:3200,innerWall:2200,outerWall:1800,solidInfill:2600,support:2600,top:2400,travel:5e3},sr=e=>"section"in e&&"contains"in e,Is=e=>"toRegion"in e&&typeof e.toRegion=="function",As=e=>"rings"in e,Ss=e=>{const t=Is(e)?e.toRegion():e;return As(t)?t.rings.map(i=>[...i]):(sr(t)?t.section:t).curves.flatMap(i=>i.role==="invalid"||i.role==="open"||i.points2.length<3?[]:[i.points2])},ve=(e,t)=>"x"in e?{x:Number(e.x),y:Number(e.y),z:Number(e.z??t)}:{x:Number(e[0]),y:Number(e[1]),z:Number(e[2]??t)},Es=e=>{const t=e.closed?[...e.points,e.points[0]]:e.points,r=[];for(let i=1;i<t.length;i+=1){const c=t[i-1],l=t[i];r.push({start:[c.x,c.y],end:[l.x,l.y]})}return r},Rs=e=>Ts.has(e),Ms=(e,t,r)=>{const i=e==="outerWall"||e==="innerWall"?.45:.35;return t*r*i},Fs=(e,t={})=>{const r=t.layerIndex??0,i=t.layerHeight??.2,c=t.lineWidth??.44,l=[];let f=0;const o=(h,y,P={})=>{const $=P.width??c,A=P.height??i,T=P.extrude??Rs(h);return{id:P.id??`custom-${r}-${f++}`,role:h,primitive:P.primitive,layerIndex:r,z:e,closed:P.closed??!1,points:y,extrusion:T?{width:$,height:A,flow:P.flow??Ms(h,$,A)}:void 0,speed:P.speed??t.speed??Cs[h]}},d={get paths(){return l},circle:(h,y,P,$={})=>{const A=Math.max(8,Math.round($.segments??64)),T=ve(y,e),W=Array.from({length:A},(C,R)=>{const D=R/A*Math.PI*2;return{x:T.x+Math.cos(D)*P,y:T.y+Math.sin(D)*P,z:T.z}});return l.push(o(h,W,{...$,closed:!0})),d},clip:(h,y={})=>{const P=Ss(h),$=sr(h)?h.contains:()=>!0;if(P.length===0)return l.splice(0,l.length),d;const A=l.flatMap(T=>nt(Es(T),P,()=>!0,{minLength:y.minLength}).filter(C=>$([(C.start[0]+C.end[0])/2,(C.start[1]+C.end[1])/2])).map((C,R)=>{var D,k,E;return o(y.role??T.role,[{x:C.start[0],y:C.start[1],z:T.z},{x:C.end[0],y:C.end[1],z:T.z}],{closed:!1,extrude:!!T.extrusion,flow:(D=T.extrusion)==null?void 0:D.flow,height:(k=T.extrusion)==null?void 0:k.height,id:`${T.id}-clip-${R}`,primitive:"segments",speed:T.speed,width:(E=T.extrusion)==null?void 0:E.width})}));return l.splice(0,l.length,...A),d},line:(h,y,P,$={})=>(l.push(o(h,[ve(y,e),ve(P,e)],$)),d),modify:h=>(l.splice(0,l.length,...nr(l,h)),d),offset:(h,y={})=>{const P=l.flatMap($=>{if(!$.closed||$.points.length<3)return[$];const A=gn($.points.map(T=>[T.x,T.y]),Math.abs(h),{...y,side:y.side??(h>=0?"outward":"inward")});return A.ok?A.rings.map((T,W)=>{var C,R,D;return o($.role,T.map(([k,E])=>({x:k,y:E,z:$.z})),{closed:!0,extrude:!!$.extrusion,flow:(C=$.extrusion)==null?void 0:C.flow,height:(R=$.extrusion)==null?void 0:R.height,id:`${$.id}-offset-${W}`,speed:$.speed,width:(D=$.extrusion)==null?void 0:D.width})}):[]});return l.splice(0,l.length,...P),d},polyline:(h,y,P={})=>(l.push(o(h,y.map($=>ve($,e)),P)),d),polygon:(h,y,P={})=>(l.push(o(h,y.map($=>ve($,e)),{...P,closed:!0})),d)};return d},Ws=(e,t)=>{var l;const r=Math.max(1,Math.round(t.count??1)),i=[];let c=e;for(let f=0;f<r;f+=1){const o=f===0?t.lineWidth/2:t.lineWidth,d=Dt(c,o,{miterLimit:t.miterLimit});for(const h of d.diagnostics)h.level!=="info"&&((l=t.onDiagnostic)==null||l.call(t,`Perimeter wall ${f+1}: ${h.message}`,h.level));for(const h of d.curves.filter(y=>y.role!=="invalid")){const y=(h.role==="outer"||h.role==="island")&&h.points2.length>=3;i.push({id:`layer-${t.layerIndex}-perimeter-${f}-${i.length}`,role:y&&f===0?"outerWall":"innerWall",layerIndex:t.layerIndex,z:e.frame.origin[2],closed:!0,points:h.points2.map(([P,$])=>({x:P,y:$,z:0})),extrusion:{width:t.lineWidth,height:t.layerHeight,flow:t.lineWidth*t.layerHeight*.45},speed:f===0?1800:2200})}c=d}return i},Ds=["outerWall","innerWall","bottom","top","solidInfill","infill","support"],ir=e=>Array.isArray(e)?e.flatMap(t=>ir(t)):[e],ke=e=>e.points[0],ks=e=>e.closed?e.points[0]:e.points[e.points.length-1],Le=(e,t)=>{const r=t.x-e.x,i=t.y-e.y,c=t.z-e.z;return r*r+i*i+c*c},Ls=(e,t)=>{const r=new Set(e.map(c=>c.role)),i=t.filter(c=>r.has(c));for(const c of e)i.includes(c.role)||i.push(c.role);return i},Os=(e,t)=>{if(!t)return e.shift();let r=0,i=Number.POSITIVE_INFINITY;for(let c=0;c<e.length;c+=1){const l=ke(e[c]);if(!l)continue;const f=Le(t,l);f<i&&(i=f,r=c)}return e.splice(r,1)[0]},Hs=e=>e.some(t=>Number.isFinite(t.order)),zs=e=>({...e,points:[...e.points].reverse()}),js=(e,t)=>{const r=[...e].sort((f,o)=>{const d=Number.isFinite(f.order)?f.order:Number.POSITIVE_INFINITY,h=Number.isFinite(o.order)?o.order:Number.POSITIVE_INFINITY;return d-h});if(!t||r.length===0)return r;const i=r.map(zs).reverse(),c=ke(r[0]),l=ke(i[0]);return!c||!l?r:Le(t,l)<Le(t,c)?i:r},or=(e,t,r,i,c,l)=>{const f=ke(t);let o=i;return c&&r&&f&&Le(r,f)>0&&(e.push(Us(r,f,o,l)),o+=1),e.push(t),{currentPoint:ks(t),travelIndex:o}},Us=(e,t,r,i)=>({id:`layer-0-travel-${r}`,role:"travel",layerIndex:0,z:e.z,closed:!1,points:[{...e},{...t}],speed:i}),Ns=(e,t={})=>{const r=ir(e).filter(h=>h.points.length>0),i=t.roleOrder??Ds,c=t.travel??!0,l=t.travelSpeed??7200,f=[];let o,d=0;for(const h of Ls(r,i)){const y=r.filter($=>$.role===h);if(Hs(y)){for(const $ of js(y,o)){const A=or(f,$,o,d,c,l);o=A.currentPoint,d=A.travelIndex}continue}for(;y.length>0;){const $=Os(y,o);if(!$)break;const A=or(f,$,o,d,c,l);o=A.currentPoint,d=A.travelIndex}}return f},Bs=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Vs=e=>Bs(e.origin,e.normal),Zs=Object.getPrototypeOf(async function(){}).constructor,qs=e=>/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e),ft=e=>e?Array.isArray(e)?e.flatMap(t=>ft(t)):[e]:[],Xs=(e,t,r)=>e&&typeof e=="object"&&!Array.isArray(e)&&"paths"in e?{distance:typeof e.distance=="number"?e.distance:r.distance,layerIndex:typeof e.layerIndex=="number"?e.layerIndex:t,paths:ft(e.paths??[]),plane:e.plane??r.plane,z:typeof e.z=="number"?e.z:r.z}:{distance:r.distance,layerIndex:t,paths:ft(e),plane:r.plane,z:r.z},Ys=e=>e.spec.kind==="plane"&&typeof e.spec.distance=="number"?e.spec.distance:Vs(e.frame),Ks=()=>({bottomSolidFill:(e,t,r={})=>gs(e,t,{angle:r.angle,field:r.field,layerHeight:r.layerHeight??.2,layerIndex:t,lineWidth:r.lineWidth??.44,margin:r.margin,pattern:r.pattern,solidLayers:r.solidLayers}),lineInfill:(e,t={})=>fs(e,{angle:t.angle,density:t.density??.18,field:t.field,layerHeight:t.layerHeight??.2,layerIndex:t.layerIndex??0,lineWidth:t.lineWidth??.44,margin:t.margin,pattern:t.pattern,spacing:t.spacing}),fillLayer:(e,t,r={})=>er(e,t,{bottomAngle:r.bottomAngle,bottomPattern:r.bottomPattern,density:r.density??.18,field:r.field,layerHeight:r.layerHeight??.2,layerIndex:t,lineWidth:r.lineWidth??.44,margin:r.margin,pattern:r.pattern,solidLayers:r.solidLayers,sparseAngle:r.sparseAngle,sparsePattern:r.sparsePattern,sparseSpacing:r.sparseSpacing,topAngle:r.topAngle,topPattern:r.topPattern}),fillRegionLayer:(e,t,r={})=>ds(e,t,{bottomAngle:r.bottomAngle,bottomPattern:r.bottomPattern,density:r.density??.18,field:r.field,layerHeight:r.layerHeight??.2,layerIndex:t,lineWidth:r.lineWidth??.44,margin:r.margin,pattern:r.pattern,solidLayers:r.solidLayers,sparseAngle:r.sparseAngle,sparsePattern:r.sparsePattern,sparseSpacing:r.sparseSpacing,topAngle:r.topAngle,topPattern:r.topPattern}),modifyPaths:nr,noise:_s,pathLayer:Fs,pathRegion:Hn,perimeters:(e,t={})=>Ws(e,{count:t.count,layerHeight:t.layerHeight??.2,layerIndex:0,lineWidth:t.lineWidth??.44,miterLimit:t.miterLimit}),planLayerPaths:Ns,fillRegion:(e,t={})=>Qt(e,{angle:t.angle,density:t.density,field:t.field,layerHeight:t.layerHeight??.2,layerIndex:t.layerIndex??0,lineWidth:t.lineWidth??.44,pattern:t.pattern,role:t.role,spacing:t.spacing}),region:e=>se(e),resample:$s,sine:ws,sparseInfill:(e,t,r={})=>hs(e,t,{angle:r.angle,density:r.density??.18,field:r.field,layerHeight:r.layerHeight??.2,layerIndex:t,lineWidth:r.lineWidth??.44,margin:r.margin,pattern:r.pattern,solidLayers:r.solidLayers,spacing:r.spacing}),topSolidFill:(e,t,r={})=>ps(e,t,{angle:r.angle,field:r.field,layerHeight:r.layerHeight??.2,layerIndex:t,lineWidth:r.lineWidth??.44,margin:r.margin,pattern:r.pattern,solidLayers:r.solidLayers}),zigzag:xs});self.onmessage=async({data:e})=>{try{await Qr();const t=Ks(),r=Object.entries(e.context).filter(([l])=>qs(l)),i=new Zs(...Object.keys(t),"context",...r.map(([l])=>l),"__layer",`"use strict";
|
|
13
|
+
const callback = (${e.callbackSource});
|
|
14
|
+
return await callback(__layer);
|
|
15
|
+
//# sourceURL=parallel-layer.fuse.js`),c=[];for(const l of e.layerIndices){const f=e.sections[l];if(!f)continue;const o=f.frame.origin[2],d=Ys(f),h={distance:d,layerIndex:l,plane:f.frame,section:f,sections:e.sections,z:o},y=await i(...Object.values(t),e.context,...r.map(([P,$])=>$),h);c.push(Xs(y,l,{distance:d,plane:f.frame,z:o}))}self.postMessage({id:e.id,layers:c})}catch(t){self.postMessage({id:e.id,error:t instanceof Error?t.message:String(t)})}}})();
|