forgecad 0.1.0 → 0.1.1

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.
@@ -1,4 +1,4 @@
1
- var ASt=Object.defineProperty;var NSt=(l,o,f)=>o in l?ASt(l,o,{enumerable:!0,configurable:!0,writable:!0,value:f}):l[o]=f;var tu=(l,o,f)=>NSt(l,typeof o!="symbol"?o+"":o,f);function a2e(l,o){return[l[0]-o[0],l[1]-o[1],l[2]-o[2]]}function nq(l,o){return[l[0]*o,l[1]*o,l[2]*o]}function o2e(l,o){return l[0]*o[0]+l[1]*o[1]+l[2]*o[2]}function ISt(l,o){return[l[1]*o[2]-l[2]*o[1],l[2]*o[0]-l[0]*o[2],l[0]*o[1]-l[1]*o[0]]}function Rte(l){return Math.hypot(l[0],l[1],l[2])}function ZBe(l,o){const f=o2e(l,o);return{axial:f,radial:a2e(l,nq(o,f))}}function jte(l,o,f){const g=Rte(l),T=Rte(o);if(g<1e-10||T<1e-10)return 0;const P=nq(l,1/g),O=nq(o,1/T),z=o2e(f,ISt(P,O)),H=o2e(P,O);return Math.atan2(z,H)*180/Math.PI}function FSt(l,o,f){const g=jte(l,o,f),T=jte(l,nq(o,-1),f);return Math.abs(g)<=Math.abs(T)?g:T}function VJe(l,o,f,g,T={}){const P=T.mode??"plane",O=X2e(l),z=a2e(f,o),H=a2e(g,o),re=ZBe(z,O),te=ZBe(H,O),W=Rte(re.radial),Ee=Rte(te.radial);if(W<1e-10){if(P==="line"&&Ee>=1e-10)throw new Error("rotateAroundTo(...): moving point lies on the rotation axis, so line alignment is impossible");return 0}if(P==="plane"){if(Ee<1e-10)throw new Error("rotateAroundTo(...): target point lies on the rotation axis, so the target plane is undefined");return jte(re.radial,te.radial,O)}if(Ee<1e-10)throw new Error("rotateAroundTo(...): target line lies on the rotation axis, but the moving point does not");const se=1e-8*Math.max(1,Math.abs(re.axial),Math.abs(te.axial)),me=1e-8*Math.max(1,W,Ee);if(Math.abs(te.axial)<se){if(Math.abs(re.axial)>se)throw new Error("rotateAroundTo(...): target line stays on the pivot plane, but the moving point has axial offset");return FSt(re.radial,te.radial,O)}const Xe=re.axial/te.axial,it=Math.abs(Xe)*Ee;if(Math.abs(W-it)>me)throw new Error("rotateAroundTo(...): moving point cannot reach the target line while preserving radius around the axis");const at=Xe>=0?te.radial:nq(te.radial,-1);return jte(re.radial,at,O)}function OSt(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function MSt(l){return l instanceof Ea?l.toArray():l}function LSt(l,o){const f=new Array(16).fill(0);for(let g=0;g<4;g++)for(let T=0;T<4;T++){let P=0;for(let O=0;O<4;O++)P+=l[O*4+T]*o[g*4+O];f[g*4+T]=P}return f}function X2e(l){const o=Math.sqrt(l[0]*l[0]+l[1]*l[1]+l[2]*l[2]);if(o<1e-10)throw new Error("Axis must be non-zero");return[l[0]/o,l[1]/o,l[2]/o]}function KBe(l,o,f){const g=o[0],T=o[1],P=o[2];return[l[0]*g+l[4]*T+l[8]*P+l[12]*f,l[1]*g+l[5]*T+l[9]*P+l[13]*f,l[2]*g+l[6]*T+l[10]*P+l[14]*f]}function RSt(l){const o=new Array(16),f=l[0],g=l[1],T=l[2],P=l[3],O=l[4],z=l[5],H=l[6],re=l[7],te=l[8],W=l[9],Ee=l[10],se=l[11],me=l[12],Xe=l[13],it=l[14],at=l[15],It=f*z-g*O,tn=f*H-T*O,At=f*re-P*O,mt=g*H-T*z,ht=g*re-P*z,xn=T*re-P*H,Pn=te*Xe-W*me,$r=te*it-Ee*me,zn=te*at-se*me,ii=W*it-Ee*Xe,Gr=W*at-se*Xe,mn=Ee*at-se*it,$s=It*mn-tn*Gr+At*ii+mt*zn-ht*$r+xn*Pn;if(Math.abs($s)<1e-10)throw new Error("Transform matrix is not invertible");const is=1/$s;return o[0]=(z*mn-H*Gr+re*ii)*is,o[1]=(T*Gr-g*mn-P*ii)*is,o[2]=(Xe*xn-it*ht+at*mt)*is,o[3]=(Ee*ht-W*xn-se*mt)*is,o[4]=(H*zn-O*mn-re*$r)*is,o[5]=(f*mn-T*zn+P*$r)*is,o[6]=(it*At-me*xn-at*tn)*is,o[7]=(te*xn-Ee*At+se*tn)*is,o[8]=(O*Gr-z*zn+re*Pn)*is,o[9]=(g*zn-f*Gr-P*Pn)*is,o[10]=(me*ht-Xe*At+at*It)*is,o[11]=(W*At-te*ht-se*It)*is,o[12]=(z*$r-O*ii-H*Pn)*is,o[13]=(f*ii-g*$r+T*Pn)*is,o[14]=(Xe*tn-me*mt-it*It)*is,o[15]=(te*mt-W*tn+Ee*It)*is,o}class Ea{constructor(o){tu(this,"m");this.m=o}static identity(){return new Ea(OSt())}static from(o){return o instanceof Ea?o:new Ea(o)}static translation(o,f,g){return new Ea([1,0,0,0,0,1,0,0,0,0,1,0,o,f,g,1])}static scale(o){const f=typeof o=="number"?o:o[0],g=typeof o=="number"?o:o[1],T=typeof o=="number"?o:o[2];return new Ea([f,0,0,0,0,g,0,0,0,0,T,0,0,0,0,1])}static rotationAxis(o,f,g=[0,0,0]){const[T,P,O]=X2e(o),z=f*Math.PI/180,H=Math.cos(z),re=Math.sin(z),te=H+T*T*(1-H),W=T*P*(1-H)-O*re,Ee=T*O*(1-H)+P*re,se=P*T*(1-H)+O*re,me=H+P*P*(1-H),Xe=P*O*(1-H)-T*re,it=O*T*(1-H)-P*re,at=O*P*(1-H)+T*re,It=H+O*O*(1-H),[tn,At,mt]=g,ht=tn-(te*tn+W*At+Ee*mt),xn=At-(se*tn+me*At+Xe*mt),Pn=mt-(it*tn+at*At+It*mt);return new Ea([te,se,it,0,W,me,at,0,Ee,Xe,It,0,ht,xn,Pn,1])}static rotateAroundTo(o,f,g,T,P={}){const O=VJe(o,f,g,T,P);return Ea.rotationAxis(o,O,f)}mul(o){const f=MSt(o);return new Ea(LSt(f,this.m))}translate(o,f,g){return this.mul(Ea.translation(o,f,g))}rotateAxis(o,f,g=[0,0,0]){return this.mul(Ea.rotationAxis(o,f,g))}scale(o){return this.mul(Ea.scale(o))}inverse(){return new Ea(RSt(this.m))}point(o){return KBe(this.m,o,1)}vector(o){return KBe(this.m,o,0)}toArray(){return[...this.m]}}function td(l){return X2e(l)}function UJe(...l){let o=Ea.identity();for(const f of l)o=o.mul(f);return o}const jSt={live:{id:"live",label:"Live (fast)",description:"Prioritizes responsiveness for interactive editing.",curves:{splineSamplesScale:.55,sweepPathSamplesScale:.6,levelSetEdgeLengthScale:1.75,boundsPaddingScale:1},smoothing:{refineStepsScale:.5,refineLengthScale:1.8,refineToleranceScale:1.8}},default:{id:"default",label:"Default",description:"Balanced quality and speed.",curves:{splineSamplesScale:1,sweepPathSamplesScale:1,levelSetEdgeLengthScale:1,boundsPaddingScale:1},smoothing:{refineStepsScale:1,refineLengthScale:1,refineToleranceScale:1}},high:{id:"high",label:"High",description:"Finer tessellation for final exports.",curves:{splineSamplesScale:1.35,sweepPathSamplesScale:1.35,levelSetEdgeLengthScale:.8,boundsPaddingScale:1},smoothing:{refineStepsScale:1.25,refineLengthScale:.8,refineToleranceScale:.8}}};let Bte=["default"];function Y2e(l){return l==="live"||l==="default"||l==="high"?l:"default"}function BSt(){return Bte[Bte.length-1]??"default"}function pI(l){const o=Y2e(BSt());return jSt[o]}function zSt(l,o){const f=Y2e(l);Bte.push(f);try{return o()}finally{Bte.pop()}}function $Je(l,o,f){const g=Math.round(l*o);return Math.max(f,g)}function HJe(l,o,f){return Math.max(f,l*o)}function JSt(l){const o=Math.max(3,Math.floor(l)),f=pI().curves.splineSamplesScale;return $Je(o,f,3)}function qSt(l){const o=Math.max(4,Math.floor(l)),f=pI().curves.sweepPathSamplesScale;return $Je(o,f,4)}function GJe(l){const o=Math.max(.01,l),f=pI().curves.levelSetEdgeLengthScale;return HJe(o,f,.01)}function XJe(l){const o=Math.max(.01,l),f=pI().curves.boundsPaddingScale;return HJe(o,f,.01)}function WSt(l){const o=Math.max(0,Math.floor(l)),f=pI().smoothing.refineStepsScale;return Math.max(0,Math.round(o*f))}function VSt(l){const o=Math.max(1e-6,l),f=pI().smoothing.refineLengthScale;return Math.max(1e-6,o*f)}function USt(l){const o=Math.max(1e-6,l),f=pI().smoothing.refineToleranceScale;return Math.max(1e-6,o*f)}const YJe=["center","front","back","left","right","top","bottom","front-left","front-right","back-left","back-right","top-front","top-back","top-left","top-right","bottom-front","bottom-back","bottom-left","bottom-right","top-front-left","top-front-right","top-back-left","top-back-right","bottom-front-left","bottom-front-right","bottom-back-left","bottom-back-right"],Ste=new Set(YJe),$St={center:"center",left:"x",right:"x",front:"y",back:"y",top:"z",bottom:"z"};function QJe(l){return Ste.has(l)}function cne(l){if(Ste.has(l))return l;const o=l.split("-").filter(Boolean);if(o.length===0)return null;if(o.length===1)return Ste.has(o[0])?o[0]:null;const f=new Map;for(const T of o){const P=$St[T];if(!P||P==="center")return null;const O=f.get(P);if(O&&O!==T)return null;f.set(P,T)}const g=[f.get("z"),f.get("y"),f.get("x")].filter(T=>T!=null).join("-");return Ste.has(g)?g:null}function t4(l,o,f){const g=cne(f);if(!g)throw new Error(`Unknown anchor "${f}". Valid anchors: ${YJe.join(", ")}`);const T=(l[0]+o[0])/2,P=(l[1]+o[1])/2,O=(l[2]+o[2])/2;switch(g){case"center":return[T,P,O];case"front":return[T,l[1],O];case"back":return[T,o[1],O];case"left":return[l[0],P,O];case"right":return[o[0],P,O];case"top":return[T,P,o[2]];case"bottom":return[T,P,l[2]];case"front-left":return[l[0],l[1],O];case"front-right":return[o[0],l[1],O];case"back-left":return[l[0],o[1],O];case"back-right":return[o[0],o[1],O];case"top-front":return[T,l[1],o[2]];case"top-back":return[T,o[1],o[2]];case"top-left":return[l[0],P,o[2]];case"top-right":return[o[0],P,o[2]];case"bottom-front":return[T,l[1],l[2]];case"bottom-back":return[T,o[1],l[2]];case"bottom-left":return[l[0],P,l[2]];case"bottom-right":return[o[0],P,l[2]];case"top-front-left":return[l[0],l[1],o[2]];case"top-front-right":return[o[0],l[1],o[2]];case"top-back-left":return[l[0],o[1],o[2]];case"top-back-right":return[o[0],o[1],o[2]];case"bottom-front-left":return[l[0],l[1],l[2]];case"bottom-front-right":return[o[0],l[1],l[2]];case"bottom-back-left":return[l[0],o[1],l[2]];case"bottom-back-right":return[o[0],o[1],l[2]];default:throw new Error(`Unhandled anchor normalization for "${g}"`)}}const zte=["points","edges","surfaces","objects"];function Z_(l,o){if(!Array.isArray(l)||l.length<3)throw new Error(`${o} must be a [x, y, z] tuple`);const f=Number(l[0]),g=Number(l[1]),T=Number(l[2]);if(!Number.isFinite(f)||!Number.isFinite(g)||!Number.isFinite(T))throw new Error(`${o} must contain finite numbers`);return[f,g,T]}function HSt(l,o){return[(l[0]+o[0])/2,(l[1]+o[1])/2,(l[2]+o[2])/2]}function ZJe(l){const o=Math.hypot(l[0],l[1],l[2]);return o<1e-10?[0,0,1]:[l[0]/o,l[1]/o,l[2]/o]}function GSt(l){return!!l&&typeof l=="object"&&"min"in l&&"max"in l}function XSt(l,o){if(GSt(l))return{min:Z_(l.min,`${o}.min`),max:Z_(l.max,`${o}.max`)};if(typeof l=="object"&&l!=null){if("boundingBox"in l&&typeof l.boundingBox=="function"){const f=l.boundingBox();return{min:Z_(f.min,`${o}.min`),max:Z_(f.max,`${o}.max`)}}if("_bbox"in l&&typeof l._bbox=="function"){const f=l._bbox();return{min:Z_(f.min,`${o}.min`),max:Z_(f.max,`${o}.max`)}}}throw new Error(`${o} must be a bounds object or a shape/group with a bounding box`)}function YSt(l,o){const f=Ea.from(o),[g,T,P]=l.min,[O,z,H]=l.max,re=[[g,T,P],[g,T,H],[g,z,P],[g,z,H],[O,T,P],[O,T,H],[O,z,P],[O,z,H]],te=[1/0,1/0,1/0],W=[-1/0,-1/0,-1/0];for(const Ee of re){const se=f.point(Ee);te[0]=Math.min(te[0],se[0]),te[1]=Math.min(te[1],se[1]),te[2]=Math.min(te[2],se[2]),W[0]=Math.max(W[0],se[0]),W[1]=Math.max(W[1],se[1]),W[2]=Math.max(W[2],se[2])}return{min:te,max:W}}function sM(){return{points:{},edges:{},surfaces:{},objects:{}}}function KJe(l){const o=sM();for(const[f,g]of Object.entries(l.points))o.points[f]=Z_(g,`points.${f}`);for(const[f,g]of Object.entries(l.edges))o.edges[f]={start:Z_(g.start,`edges.${f}.start`),end:Z_(g.end,`edges.${f}.end`)};for(const[f,g]of Object.entries(l.surfaces))o.surfaces[f]={center:Z_(g.center,`surfaces.${f}.center`),normal:Z_(g.normal,`surfaces.${f}.normal`)};for(const[f,g]of Object.entries(l.objects))o.objects[f]={min:Z_(g.min,`objects.${f}.min`),max:Z_(g.max,`objects.${f}.max`)};return o}function QSt(l={}){const o=sM();for(const[f,g]of Object.entries(l.points??{}))o.points[f]=Z_(g,`points.${f}`);for(const[f,g]of Object.entries(l.edges??{}))o.edges[f]={start:Z_(g.start,`edges.${f}.start`),end:Z_(g.end,`edges.${f}.end`)};for(const[f,g]of Object.entries(l.surfaces??{}))o.surfaces[f]={center:Z_(g.center,`surfaces.${f}.center`),normal:ZJe(Z_(g.normal,`surfaces.${f}.normal`))};for(const[f,g]of Object.entries(l.objects??{}))o.objects[f]=XSt(g,`objects.${f}`);return o}function eqe(...l){const o=sM();for(const f of l){for(const[g,T]of Object.entries(f.points))o.points[g]=Z_(T,`points.${g}`);for(const[g,T]of Object.entries(f.edges))o.edges[g]={start:Z_(T.start,`edges.${g}.start`),end:Z_(T.end,`edges.${g}.end`)};for(const[g,T]of Object.entries(f.surfaces))o.surfaces[g]={center:Z_(T.center,`surfaces.${g}.center`),normal:Z_(T.normal,`surfaces.${g}.normal`)};for(const[g,T]of Object.entries(f.objects))o.objects[g]={min:Z_(T.min,`objects.${g}.min`),max:Z_(T.max,`objects.${g}.max`)}}return o}function ZSt(l){return zte.some(o=>Object.keys(l[o]).length>0)}function eze(l,o){return eqe(l,QSt(o))}function KSt(l,o){const f=Ea.from(o),g=sM();for(const[T,P]of Object.entries(l.points))g.points[T]=f.point(P);for(const[T,P]of Object.entries(l.edges))g.edges[T]={start:f.point(P.start),end:f.point(P.end)};for(const[T,P]of Object.entries(l.surfaces))g.surfaces[T]={center:f.point(P.center),normal:ZJe(f.vector(P.normal))};for(const[T,P]of Object.entries(l.objects))g.objects[T]=YSt(P,o);return g}function qee(l,o){throw new Error(`Placement reference "${l}" ${o}`)}function tze(l,o,f,g,T){switch(o){case"points":{const P=l.points[f];return P?(g!=null&&qee(T,"does not support selectors"),Z_(P,`points.${f}`)):null}case"edges":{const P=l.edges[f];if(!P)return null;if(g==null||g==="midpoint"||g==="center")return HSt(P.start,P.end);if(g==="start")return Z_(P.start,`edges.${f}.start`);if(g==="end")return Z_(P.end,`edges.${f}.end`);qee(T,"supports only .start, .end, or .midpoint")}case"surfaces":{const P=l.surfaces[f];return P?(g!=null&&g!=="center"&&qee(T,"supports only .center"),Z_(P.center,`surfaces.${f}.center`)):null}case"objects":{const P=l.objects[f];if(!P)return null;const z=cne(g??"center");return z||qee(T,`supports only Anchor3D selectors (${["center","top","bottom","left","right","front","back"].join(", ")} ...)`),t4(P.min,P.max,z)}default:return null}}function eTt(l,o){const f=o.trim();if(!f)return null;const g=f.split(".");if(g.length>=2&&zte.includes(g[0])){const P=g[0],O=g[1],z=g.length>2?g.slice(2).join("."):void 0;return tze(l,P,O,z,f)}const T=zte.map(P=>({kind:P,point:tze(l,P,f,void 0,f)})).filter(P=>P.point!=null);if(T.length===0)return null;if(T.length>1)throw new Error(`Placement reference "${f}" is ambiguous. Use one of: ${T.map(P=>`${P.kind}.${f}`).join(", ")}`);return T[0].point}function tqe(l,o){return o?Object.keys(l[o]).sort():zte.flatMap(f=>Object.keys(l[f]).sort().map(g=>`${f}.${g}`))}function Sp(l){if(l)return{id:l.id,operation:l.operation}}function Pb(l,o){return l==null||o==null?l==null&&o==null:l.id===o.id&&l.operation===o.operation}function iu(l){if(l)switch(l.kind){case"canonical-face":return{kind:"canonical-face",face:l.face,owner:Sp(l.owner)};case"tracked-face":return{kind:"tracked-face",faceName:l.faceName,owner:Sp(l.owner)};case"face-ref":return{kind:"face-ref",faceName:l.faceName,owner:Sp(l.owner)};case"propagated-face":return{kind:"propagated-face",rewriteId:l.rewriteId,outcome:l.outcome,source:iu(l.source),owner:Sp(l.owner)};case"created-face":return{kind:"created-face",rewriteId:l.rewriteId,operation:l.operation,slot:l.slot,owner:Sp(l.owner)}}}function wl(l){if(l)switch(l.kind){case"tracked-edge":return{kind:"tracked-edge",edgeName:l.edgeName,selector:l.selector,owner:Sp(l.owner)};case"edge-ref":return{kind:"edge-ref",edgeName:l.edgeName,selector:l.selector,owner:Sp(l.owner)};case"propagated-edge":return{kind:"propagated-edge",rewriteId:l.rewriteId,outcome:l.outcome,source:wl(l.source),selector:l.selector,owner:Sp(l.owner)};case"created-edge":return{kind:"created-edge",rewriteId:l.rewriteId,operation:l.operation,slot:l.slot,selector:l.selector,owner:Sp(l.owner)}}}function uC(l){if(l)return{rewriteId:l.rewriteId,operation:l.operation,owner:Sp(l.owner),preservedFaces:l.preservedFaces.map(o=>({query:iu(o.query),status:o.status,note:o.note})),preservedEdges:l.preservedEdges.map(o=>({query:wl(o.query),status:o.status,note:o.note})),createdFaces:l.createdFaces.map(o=>({query:iu(o.query),note:o.note})),createdEdges:l.createdEdges.map(o=>({query:wl(o.query),note:o.note})),diagnostics:l.diagnostics.map(o=>({code:o.code,category:o.category,queryKind:o.queryKind,message:o.message,source:o.queryKind==="face"?iu(o.source):wl(o.source),query:o.queryKind==="face"?iu(o.query):wl(o.query)})),descendants:(l.descendants??[]).map(o=>{switch(o.queryKind){case"face":return{queryKind:"face",kind:o.kind,query:iu(o.query),source:iu(o.source),note:o.note};case"edge":return{queryKind:"edge",kind:o.kind,query:wl(o.query),source:wl(o.source),note:o.note};case"vertex":return{queryKind:"vertex",kind:o.kind,note:o.note}}})}}function sT(l,o){if(l==null||o==null)return l==null&&o==null;if(l.kind!==o.kind)return!1;switch(l.kind){case"canonical-face":return o.kind==="canonical-face"&&l.face===o.face&&Pb(l.owner,o.owner);case"tracked-face":return o.kind==="tracked-face"&&l.faceName===o.faceName&&Pb(l.owner,o.owner);case"face-ref":return o.kind==="face-ref"&&l.faceName===o.faceName&&Pb(l.owner,o.owner);case"propagated-face":return o.kind==="propagated-face"&&l.rewriteId===o.rewriteId&&l.outcome===o.outcome&&sT(l.source,o.source)&&Pb(l.owner,o.owner);case"created-face":return o.kind==="created-face"&&l.rewriteId===o.rewriteId&&l.operation===o.operation&&l.slot===o.slot&&Pb(l.owner,o.owner)}}function gC(l,o){if(l==null||o==null)return l==null&&o==null;if(l.kind!==o.kind)return!1;switch(l.kind){case"tracked-edge":return o.kind==="tracked-edge"&&l.edgeName===o.edgeName&&l.selector===o.selector&&Pb(l.owner,o.owner);case"edge-ref":return o.kind==="edge-ref"&&l.edgeName===o.edgeName&&l.selector===o.selector&&Pb(l.owner,o.owner);case"propagated-edge":return o.kind==="propagated-edge"&&l.rewriteId===o.rewriteId&&l.outcome===o.outcome&&l.selector===o.selector&&gC(l.source,o.source)&&Pb(l.owner,o.owner);case"created-edge":return o.kind==="created-edge"&&l.rewriteId===o.rewriteId&&l.operation===o.operation&&l.slot===o.slot&&l.selector===o.selector&&Pb(l.owner,o.owner)}}function rq(l){if(!l)return"none";const o=l.owner?` @${l.owner.operation}:${l.owner.id}`:"";switch(l.kind){case"canonical-face":return`canonical-face(${l.face})${o}`;case"tracked-face":return`tracked-face(${l.faceName})${o}`;case"face-ref":return`face-ref(${l.faceName??"unnamed"})${o}`;case"propagated-face":return`propagated-face(${l.outcome} <- ${rq(l.source)})${o}`;case"created-face":return`created-face(${l.operation}:${l.slot})${o}`}}function iq(l){if(!l)return"none";const o=l.owner?` @${l.owner.operation}:${l.owner.id}`:"",f=`#${l.selector}`;switch(l.kind){case"tracked-edge":return`tracked-edge(${l.edgeName}${f})${o}`;case"edge-ref":return`edge-ref(${l.edgeName??"unnamed"}${f})${o}`;case"propagated-edge":return`propagated-edge(${l.outcome} <- ${iq(l.source)}${f})${o}`;case"created-edge":return`created-edge(${l.operation}:${l.slot}${f})${o}`}}function tTt(l){return iu(l)}function c2e(l){return{origin:[l.origin[0],l.origin[1],l.origin[2]],u:[l.u[0],l.u[1],l.u[2]],v:[l.v[0],l.v[1],l.v[2]],normal:[l.normal[0],l.normal[1],l.normal[2]],source:tTt(l.source)}}function i6(l){return l?{workplane:c2e(l.workplane),u:l.u,v:l.v,protrude:l.protrude,selfAnchor:l.selfAnchor}:null}function nTt(l){return[...l]}function rT(l){return l?{matrix:nTt(l.matrix),placement:i6(l.placement)}:null}function Jte(l){if(l)return[l[0],l[1]]}function nze(l){if(l)return{kind:l.kind,edgeName:l.edgeName,start:[l.start[0],l.start[1],l.start[2]],end:[l.end[0],l.end[1],l.end[2]],midpoint:[l.midpoint[0],l.midpoint[1],l.midpoint[2]]}}const dq=["top","right","bottom","left"],VO=1e-9;function Wee(l){return Number.isFinite(l)&&l>0}function rze(l){return Number.isFinite(l)&&l>=0}function l2e(l){return[l[0],l[1],l[2]]}function ize(l){return l?l2e(l):void 0}function qte(l){return l?{panel:{width:l.panel.width,height:l.panel.height},thickness:l.thickness,bendRadius:l.bendRadius,bendAllowance:{kind:l.bendAllowance.kind,kFactor:l.bendAllowance.kFactor},cornerRelief:{kind:l.cornerRelief.kind,size:l.cornerRelief.size},flanges:l.flanges.map(o=>({edge:o.edge,length:o.length,angleDeg:o.angleDeg}))}:null}function Tte(l){return`sheetMetal().flange("${l}", ...)`}function rTt(l){return Math.abs(l)<=VO?0:l}function Wte(l){if(!Wee(l.panel.width)||!Wee(l.panel.height))return"sheetMetal() requires a positive finite panel width and height.";if(!Wee(l.thickness))return"sheetMetal() requires a positive finite sheet thickness.";if(!rze(l.bendRadius))return"sheetMetal() requires a finite non-negative bendRadius.";if(l.bendRadius<=VO)return"sheetMetal() v1 requires a positive bendRadius so the bend region stays explicit instead of collapsing into a sharp fold.";if(l.bendAllowance.kind!=="k-factor")return`sheetMetal() does not support bend allowance model "${l.bendAllowance.kind}" yet.`;if(!Number.isFinite(l.bendAllowance.kFactor)||l.bendAllowance.kFactor<=0||l.bendAllowance.kFactor>=1)return"sheetMetal() k-factor must be a finite value between 0 and 1.";if(l.cornerRelief.kind!=="rect")return`sheetMetal() does not support corner relief "${l.cornerRelief.kind}" yet.`;if(!rze(l.cornerRelief.size))return"sheetMetal() corner relief size must be a finite non-negative value.";const o=new Set;for(const f of l.flanges){if(!dq.includes(f.edge))return`sheetMetal() does not recognize flange edge "${String(f.edge)}".`;if(o.has(f.edge))return`${Tte(f.edge)} can only be declared once.`;if(o.add(f.edge),!Wee(f.length))return`${Tte(f.edge)} requires a positive finite length.`;if(!Number.isFinite(f.angleDeg)||Math.abs(rTt(f.angleDeg)-90)>1e-6)return`${Tte(f.edge)} v1 only supports 90 degree flanges.`}return null}function iTt(l){return new Map(l.flanges.map(o=>[o.edge,o]))}function sTt(l){switch(l){case"top":return{start:"left",end:"right"};case"right":return{start:"bottom",end:"top"};case"bottom":return{start:"left",end:"right"};case"left":return{start:"bottom",end:"top"}}}function eM(l){const o=Wte(l);if(o)throw new Error(o);const f=iTt(l),g=Math.PI/2*(l.bendRadius+l.bendAllowance.kFactor*l.thickness),T=new Map;for(const P of dq){const O=f.get(P);if(!O)continue;const z=sTt(P),H=f.has(z.start)?l.cornerRelief.size:0,re=f.has(z.end)?l.cornerRelief.size:0,W=(P==="top"||P==="bottom"?l.panel.width:l.panel.height)-H-re;if(!(W>VO))throw new Error(`${Tte(P)} loses all usable span after applying the defended rectangular corner relief size ${l.cornerRelief.size}.`);T.set(P,{edge:P,length:O.length,angleDeg:O.angleDeg,bendAllowance:g,trimStart:H,trimEnd:re,span:W,centerAlongEdge:(H-re)/2})}return{panelWidth:l.panel.width,panelHeight:l.panel.height,thickness:l.thickness,bendRadius:l.bendRadius,kFactor:l.bendAllowance.kFactor,bendAllowance:g,reliefSize:l.cornerRelief.size,flanges:T}}function aTt(l){const o=["panel"],f=eM(l);for(const g of dq)f.flanges.has(g)&&o.push(`bend-${g}`,`flange-${g}`);return o}function oTt(l){return aTt(l).filter(o=>o==="panel"||o.startsWith("flange-"))}function cTt(l){return l==="panel"||l==="flange-top"||l==="flange-right"||l==="flange-bottom"||l==="flange-left"}function lTt(l,o,f,g){return{workplane:{origin:[l[0],l[1],l[2]],u:[o[0],o[1],o[2]],v:[f[0],f[1],f[2]],normal:[g[0],g[1],g[2]],source:{kind:"face-ref",faceName:"sheet-metal-placement"}},u:0,v:0,protrude:0,selfAnchor:"center"}}function uTt(l,o,f,g){return Math.abs(o)<=VO&&Math.abs(f)<=VO&&Math.abs(g)<=VO?m_(l):G1(m_(l),{kind:"translate",x:o,y:f,z:g})}function Vee(l,o,f,g,T){const P=lTt(o,f,g,T),O=[f[0],f[1],f[2],0,g[0],g[1],g[2],0,T[0],T[1],T[2],0,o[0],o[1],o[2],1];return G1(m_(l),{kind:"workplanePlacement",matrix:O,placement:P})}function mx(l,o,f,g=0,T=0,P=0){return uTt({kind:"box",x:l,y:o,z:f,center:!0},g,T,P)}function _Tt(l,o){const f=l+o,g=Db({kind:"circle",radius:f,transforms:[]},{kind:"translate",x:0,y:l}),T=Db({kind:"circle",radius:l,transforms:[]},{kind:"translate",x:0,y:l}),P=iT("difference",[g,T]),O=Db({kind:"rect",width:f,height:f,center:!1,transforms:[]},{kind:"translate",x:0,y:-o});return iT("intersection",[P,O])}function fTt(l){return{kind:"box",x:l.panelWidth,y:l.panelHeight,z:l.thickness,center:!0}}function pTt(l,o){const f=l.thickness,g=l.bendRadius,T=o.length;switch(o.edge){case"top":return mx(o.span,f,T,o.centerAlongEdge,l.panelHeight/2+g+f/2,-f/2-g-T/2);case"bottom":return mx(o.span,f,T,o.centerAlongEdge,-l.panelHeight/2-g-f/2,-f/2-g-T/2);case"right":return mx(f,o.span,T,l.panelWidth/2+g+f/2,o.centerAlongEdge,-f/2-g-T/2);case"left":return mx(f,o.span,T,-l.panelWidth/2-g-f/2,o.centerAlongEdge,-f/2-g-T/2)}}function dTt(l,o){const f=_Tt(l.bendRadius,l.thickness);if(!f)return null;const g={kind:"extrude",profile:f,height:o.span,center:!1};switch(o.edge){case"top":return Vee(g,[-l.panelWidth/2+o.trimStart,l.panelHeight/2,-l.thickness/2],[0,1,0],[0,0,-1],[1,0,0]);case"bottom":return Vee(g,[-l.panelWidth/2+o.trimStart,-l.panelHeight/2,-l.thickness/2],[0,-1,0],[0,0,-1],[1,0,0]);case"right":return Vee(g,[l.panelWidth/2,-l.panelHeight/2+o.trimStart,-l.thickness/2],[1,0,0],[0,0,-1],[0,1,0]);case"left":return Vee(g,[-l.panelWidth/2,-l.panelHeight/2+o.trimStart,-l.thickness/2],[-1,0,0],[0,0,-1],[0,1,0])}}function mTt(l,o){const f=l.thickness,g=o.bendAllowance;switch(o.edge){case"top":return mx(o.span,g,f,o.centerAlongEdge,l.panelHeight/2+g/2,0);case"bottom":return mx(o.span,g,f,o.centerAlongEdge,-l.panelHeight/2-g/2,0);case"right":return mx(g,o.span,f,l.panelWidth/2+g/2,o.centerAlongEdge,0);case"left":return mx(g,o.span,f,-l.panelWidth/2-g/2,o.centerAlongEdge,0)}}function hTt(l,o){const f=l.thickness,g=o.bendAllowance,T=o.length;switch(o.edge){case"top":return mx(o.span,T,f,o.centerAlongEdge,l.panelHeight/2+g+T/2,0);case"bottom":return mx(o.span,T,f,o.centerAlongEdge,-l.panelHeight/2-g-T/2,0);case"right":return mx(T,o.span,f,l.panelWidth/2+g+T/2,o.centerAlongEdge,0);case"left":return mx(T,o.span,f,-l.panelWidth/2-g-T/2,o.centerAlongEdge,0)}}function gTt(l,o){const f=eM(l),g=[fTt(f)];for(const T of dq){const P=f.flanges.get(T);if(P){if(o==="folded"){const O=dTt(f,P);O&&g.push(O),g.push(pTt(f,P));continue}g.push(mTt(f,P)),g.push(hTt(f,P))}}return g.length===1?g[0]:Ry("union",g)}function Wg(l,o,f,g,T,P,O="face",z=[l],H=g){return{name:l,center:l2e(o),normal:l2e(f),planar:g,uAxis:ize(T),vAxis:ize(P),semantic:O,memberNames:[...z],coplanar:H}}function yTt(l,o){const f=l.thickness,g=l.bendRadius,P=(g+f/2)/Math.sqrt(2);switch(o.edge){case"top":return Wg("bend-top",[o.centerAlongEdge,l.panelHeight/2+P,-l.thickness/2-g+P],[0,1/Math.sqrt(2),1/Math.sqrt(2)],!1,void 0,void 0,"set",["bend-top-inner","bend-top-outer"],!1);case"bottom":return Wg("bend-bottom",[o.centerAlongEdge,-l.panelHeight/2-P,-l.thickness/2-g+P],[0,-1/Math.sqrt(2),1/Math.sqrt(2)],!1,void 0,void 0,"set",["bend-bottom-inner","bend-bottom-outer"],!1);case"right":return Wg("bend-right",[l.panelWidth/2+P,o.centerAlongEdge,-l.thickness/2-g+P],[1/Math.sqrt(2),0,1/Math.sqrt(2)],!1,void 0,void 0,"set",["bend-right-inner","bend-right-outer"],!1);case"left":return Wg("bend-left",[-l.panelWidth/2-P,o.centerAlongEdge,-l.thickness/2-g+P],[-1/Math.sqrt(2),0,1/Math.sqrt(2)],!1,void 0,void 0,"set",["bend-left-inner","bend-left-outer"],!1)}}function vTt(l,o){const f=eM(l),g=[Wg("panel",[0,0,f.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0])];for(const T of dq){const P=f.flanges.get(T);if(P){if(o==="folded"){switch(g.push(yTt(f,P)),T){case"top":g.push(Wg("flange-top",[P.centerAlongEdge,f.panelHeight/2+f.bendRadius+f.thickness,-f.thickness/2-f.bendRadius-P.length/2],[0,1,0],!0,[1,0,0],[0,0,-1]));break;case"bottom":g.push(Wg("flange-bottom",[P.centerAlongEdge,-f.panelHeight/2-f.bendRadius-f.thickness,-f.thickness/2-f.bendRadius-P.length/2],[0,-1,0],!0,[1,0,0],[0,0,1]));break;case"right":g.push(Wg("flange-right",[f.panelWidth/2+f.bendRadius+f.thickness,P.centerAlongEdge,-f.thickness/2-f.bendRadius-P.length/2],[1,0,0],!0,[0,1,0],[0,0,1]));break;case"left":g.push(Wg("flange-left",[-f.panelWidth/2-f.bendRadius-f.thickness,P.centerAlongEdge,-f.thickness/2-f.bendRadius-P.length/2],[-1,0,0],!0,[0,-1,0],[0,0,1]));break}continue}switch(T){case"top":g.push(Wg("bend-top",[P.centerAlongEdge,f.panelHeight/2+P.bendAllowance/2,f.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0])),g.push(Wg("flange-top",[P.centerAlongEdge,f.panelHeight/2+P.bendAllowance+P.length/2,f.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0]));break;case"bottom":g.push(Wg("bend-bottom",[P.centerAlongEdge,-f.panelHeight/2-P.bendAllowance/2,f.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0])),g.push(Wg("flange-bottom",[P.centerAlongEdge,-f.panelHeight/2-P.bendAllowance-P.length/2,f.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0]));break;case"right":g.push(Wg("bend-right",[f.panelWidth/2+P.bendAllowance/2,P.centerAlongEdge,f.thickness/2],[0,0,1],!0,[0,1,0],[-1,0,0])),g.push(Wg("flange-right",[f.panelWidth/2+P.bendAllowance+P.length/2,P.centerAlongEdge,f.thickness/2],[0,0,1],!0,[0,1,0],[-1,0,0]));break;case"left":g.push(Wg("bend-left",[-f.panelWidth/2-P.bendAllowance/2,P.centerAlongEdge,f.thickness/2],[0,0,1],!0,[0,-1,0],[1,0,0])),g.push(Wg("flange-left",[-f.panelWidth/2-P.bendAllowance-P.length/2,P.centerAlongEdge,f.thickness/2],[0,0,1],!0,[0,-1,0],[1,0,0]));break}}}return g}function XE(l){switch(l.kind){case"translate":return{kind:"translate",x:l.x,y:l.y};case"rotate":return{kind:"rotate",degrees:l.degrees};case"scale":return{kind:"scale",x:l.x,y:l.y};case"mirror":return{kind:"mirror",normalX:l.normalX,normalY:l.normalY}}}function R_(l){return Object.is(l,-0)?0:l}function Q2e(l){return l.map(o=>R_(o))}function Uee(l){return[R_(l[0]),R_(l[1]),R_(l[2])]}function sq(l){return rT({matrix:Q2e(l.matrix),placement:i6(l.placement)})}function lne(l){return Sp(l)}function bTt(l){return{radius:R_(l.radius),depth:R_(l.depth)}}function xTt(l){return{radius:R_(l.radius),angleDeg:R_(l.angleDeg),depth:R_(l.depth)}}function STt(l){return{designation:l.designation,pitch:l.pitch==null?void 0:R_(l.pitch),class:l.class,handedness:l.handedness,depth:l.depth==null?void 0:R_(l.depth),modeled:l.modeled}}function TTt(l){return{radius:R_(l.radius),counterbore:l.counterbore?bTt(l.counterbore):void 0,countersink:l.countersink?xTt(l.countersink):void 0,thread:l.thread?STt(l.thread):void 0}}function Cbe(l){switch(l.kind){case"through":case"blind":return{kind:l.kind,depth:R_(l.depth)};case"upToFace":return{kind:"upToFace",depth:R_(l.depth),face:iu(l.face)}}}function sze(l){return l.kind==="two-sided"?{kind:"two-sided",forward:Cbe(l.forward),reverse:Cbe(l.reverse)}:Cbe(l)}function kTt(l){return{scale:[R_(l.scale[0]),R_(l.scale[1])]}}function Rm(l){return l.kind==="two-sided"?l.forward:l}function Ab(l){return l.kind==="two-sided"?l.reverse:void 0}function mq(l){var g;const o=Rm(l).depth,f=((g=Ab(l))==null?void 0:g.depth)??0;return o+f}let u2e=0;function CTt(l){return l.replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()||"shape"}function une(l){return u2e+=1,{id:`shape-query-${CTt(l)}-${u2e}`,operation:l}}function wTt(){u2e=0}function ETt(l){const[o,f,g]=l,T=Math.hypot(o,f,g);if(T<1e-12)return Ea.identity().toArray();const P=o/T,O=f/T,z=g/T,H=1-2*P*P,re=-2*P*O,te=-2*P*z,W=-2*O*P,Ee=1-2*O*O,se=-2*O*z,me=-2*z*P,Xe=-2*z*O,it=1-2*z*z;return[H,W,me,0,re,Ee,Xe,0,te,se,it,0,0,0,0,1]}function PTt(l){switch(l.kind){case"translate":return Ea.translation(l.x,l.y,l.z).toArray();case"rotate":return Ea.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg).toArray();case"scale":return Ea.scale([l.x,l.y,l.z]).toArray();case"rotateAround":return Ea.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]).toArray();case"mirror":return ETt([l.normalX,l.normalY,l.normalZ])}}function DTt(l,o){const f=PTt(o),g=Ea.from(f),T=sq(l);return{matrix:Q2e(Ea.from(T.matrix).mul(f).toArray()),placement:{...T.placement,workplane:{...T.placement.workplane,origin:Uee(g.point(T.placement.workplane.origin)),u:Uee(g.vector(T.placement.workplane.u)),v:Uee(g.vector(T.placement.workplane.v)),normal:Uee(g.vector(T.placement.workplane.normal))}}}}function kte(l){switch(l.kind){case"translate":return{kind:"translate",x:l.x,y:l.y,z:l.z};case"rotate":return{kind:"rotate",xDeg:l.xDeg,yDeg:l.yDeg,zDeg:l.zDeg};case"scale":return{kind:"scale",x:l.x,y:l.y,z:l.z};case"rotateAround":return{kind:"rotateAround",axisX:l.axisX,axisY:l.axisY,axisZ:l.axisZ,degrees:l.degrees,pivotX:l.pivotX,pivotY:l.pivotY,pivotZ:l.pivotZ};case"mirror":return{kind:"mirror",normalX:l.normalX,normalY:l.normalY,normalZ:l.normalZ};case"workplanePlacement":return{kind:"workplanePlacement",matrix:Q2e(l.matrix),placement:i6(l.placement)}}}function nqe(l){return{kind:l.kind,points:l.points.map(([o,f,g])=>[o,f,g])}}function Fd(l){if(!l)return null;switch(l.kind){case"rect":return{kind:"rect",width:l.width,height:l.height,center:l.center,transforms:l.transforms.map(XE)};case"roundedRect":return{kind:"roundedRect",width:l.width,height:l.height,radius:l.radius,center:l.center,transforms:l.transforms.map(XE)};case"circle":return{kind:"circle",radius:l.radius,segments:l.segments,transforms:l.transforms.map(XE)};case"polygon":return{kind:"polygon",points:l.points.map(([o,f])=>[o,f]),transforms:l.transforms.map(XE)};case"boolean":return{kind:"boolean",op:l.op,profiles:l.profiles.map(o=>Fd(o)),transforms:l.transforms.map(XE)};case"offset":return{kind:"offset",base:Fd(l.base),delta:l.delta,join:l.join,transforms:l.transforms.map(XE)};case"hull":return{kind:"hull",profiles:l.profiles.map(o=>Fd(o)),transforms:l.transforms.map(XE)};case"project":return{kind:"project",sourceShape:m_(l.sourceShape),plane:{origin:[l.plane.origin[0],l.plane.origin[1],l.plane.origin[2]],u:[l.plane.u[0],l.plane.u[1],l.plane.u[2]],v:[l.plane.v[0],l.plane.v[1],l.plane.v[2]],normal:[l.plane.normal[0],l.plane.normal[1],l.plane.normal[2]]},sourcePlacement:l.sourcePlacement?i6(l.sourcePlacement):void 0,replayProfile:l.replayProfile?Fd(l.replayProfile):void 0,replayReason:l.replayReason,transforms:l.transforms.map(XE)}}}function m_(l){if(!l)return null;switch(l.kind){case"box":return{kind:"box",x:l.x,y:l.y,z:l.z,center:l.center};case"cylinder":return{kind:"cylinder",height:l.height,radius:l.radius,radiusTop:l.radiusTop,segments:l.segments,center:l.center};case"sphere":return{kind:"sphere",radius:l.radius,segments:l.segments};case"extrude":return{kind:"extrude",profile:Fd(l.profile),height:l.height,center:l.center,scaleTop:l.scaleTop?[l.scaleTop[0],l.scaleTop[1]]:void 0};case"sheetMetal":return{kind:"sheetMetal",model:qte(l.model),output:l.output};case"shell":return{kind:"shell",base:m_(l.base),thickness:l.thickness,openFaces:[...l.openFaces],queryPropagation:uC(l.queryPropagation)};case"hole":return{kind:"hole",base:m_(l.base),placement:sq(l.placement),hole:TTt(l.hole),extent:sze(l.extent),queryPropagation:uC(l.queryPropagation)};case"cut":return{kind:"cut",base:m_(l.base),placement:sq(l.placement),profile:Fd(l.profile),extent:sze(l.extent),taper:l.taper?kTt(l.taper):void 0,queryPropagation:uC(l.queryPropagation)};case"revolve":return{kind:"revolve",profile:Fd(l.profile),degrees:l.degrees,segments:l.segments};case"loft":return{kind:"loft",profiles:l.profiles.map(o=>Fd(o)),heights:l.heights.map(o=>o),edgeLength:l.edgeLength,boundsPadding:l.boundsPadding};case"sweep":return{kind:"sweep",profile:Fd(l.profile),path:nqe(l.path),edgeLength:l.edgeLength,boundsPadding:l.boundsPadding,up:[l.up[0],l.up[1],l.up[2]]};case"boolean":return{kind:"boolean",op:l.op,shapes:l.shapes.map(o=>m_(o)),queryPropagation:uC(l.queryPropagation)};case"transform":return{kind:"transform",base:m_(l.base),steps:l.steps.map(kte)};case"queryOwner":return{kind:"queryOwner",owner:lne(l.owner),base:m_(l.base)};case"hull":return{kind:"hull",shapes:l.shapes.map(o=>m_(o)),points:l.points.map(([o,f,g])=>[o,f,g]),queryPropagation:uC(l.queryPropagation)};case"trimByPlane":return{kind:"trimByPlane",base:m_(l.base),normalX:l.normalX,normalY:l.normalY,normalZ:l.normalZ,originOffset:l.originOffset,queryPropagation:uC(l.queryPropagation)};case"fillet":return{kind:"fillet",base:m_(l.base),edge:wl(l.edge),radius:l.radius,quadrant:Jte(l.quadrant),segments:l.segments,resolvedEdge:nze(l.resolvedEdge),queryPropagation:uC(l.queryPropagation)};case"chamfer":return{kind:"chamfer",base:m_(l.base),edge:wl(l.edge),size:l.size,quadrant:Jte(l.quadrant),resolvedEdge:nze(l.resolvedEdge),queryPropagation:uC(l.queryPropagation)}}}function Db(l,o){if(!l)return null;const f=Fd(l);return f.transforms.push(XE(o)),f}function G1(l,o){return l?l.kind==="transform"?{kind:"transform",base:m_(l.base),steps:[...l.steps.map(kte),kte(o)]}:{kind:"transform",base:m_(l),steps:[kte(o)]}:null}function ATt(l,o){let f=m_(l);for(const g of o)f=G1(f,g);return f}function hq(l,o){return l?{kind:"queryOwner",owner:lne(o),base:m_(l)}:null}function s6(l,o){return l?hq(l,une(o)):null}function Ry(l,o){return o.some(f=>f==null)?null:{kind:"boolean",op:l,shapes:o.map(f=>m_(f))}}function _ne(l){if(!l)return null;switch(l.kind){case"queryOwner":return lne(l.owner);case"transform":case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":return _ne(l.base);case"box":case"cylinder":case"sphere":case"extrude":case"sheetMetal":case"revolve":case"loft":case"sweep":case"boolean":case"hull":return null}}function NTt(l){const o=[],f=new Set;function g(T){if(T)switch(T.kind){case"queryOwner":f.has(T.owner.id)||(f.add(T.owner.id),o.push(lne(T.owner))),g(T.base);return;case"transform":case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":g(T.base);return;case"boolean":for(const P of T.shapes)g(P);return;case"hull":for(const P of T.shapes)g(P);return;case"box":case"cylinder":case"sphere":case"extrude":case"sheetMetal":case"revolve":case"loft":case"sweep":return}}return g(l),o}function UJ(l){if(!l)return null;switch(l.kind){case"queryOwner":return UJ(l.base);case"transform":{let o=UJ(l.base);for(const f of l.steps){if(f.kind==="workplanePlacement"){o=sq({matrix:f.matrix,placement:f.placement});continue}o&&(o=DTt(o,f))}return o}case"shell":case"fillet":case"chamfer":return UJ(l.base);case"hole":case"cut":return sq(l.placement);case"trimByPlane":return UJ(l.base);case"box":case"cylinder":case"sphere":case"extrude":case"sheetMetal":case"loft":case"sweep":case"boolean":case"hull":case"revolve":return null}}function iT(l,o){return o.some(f=>f==null)?null:{kind:"boolean",op:l,profiles:o.map(f=>Fd(f)),transforms:[]}}function rqe(l,o,f){return l?{kind:"offset",base:Fd(l),delta:o,join:f,transforms:[]}:null}function iqe(l){return l.some(o=>o==null)?null:{kind:"hull",profiles:l.map(o=>Fd(o)),transforms:[]}}function sqe(l,o=[]){return l.some(f=>f==null)?null:{kind:"hull",shapes:l.map(f=>m_(f)),points:o.map(([f,g,T])=>[f,g,T])}}function wbe(l,o,f){return l?{kind:"trimByPlane",base:m_(l),normalX:R_(o[0]),normalY:R_(o[1]),normalZ:R_(o[2]),originOffset:R_(f)}:null}function ITt(l,o,f,g,T){return!l||!o||!Number.isFinite(f)||!(f>0)||!Number.isFinite(T)||T<2?null:{kind:"fillet",base:m_(l),edge:wl(o),radius:R_(f),quadrant:Jte(g),segments:Math.max(2,Math.round(T))}}function FTt(l,o,f,g){return!l||!o||!Number.isFinite(f)||!(f>0)?null:{kind:"chamfer",base:m_(l),edge:wl(o),size:R_(f),quadrant:Jte(g)}}function OTt(l,o,f){return l.some(g=>g==null)?null:{kind:"loft",profiles:l.map(g=>Fd(g)),heights:o.map(g=>R_(g)),edgeLength:R_(f.edgeLength),boundsPadding:R_(f.boundsPadding)}}function MTt(l,o,f){return l?{kind:"sweep",profile:Fd(l),path:nqe(o),edgeLength:R_(f.edgeLength),boundsPadding:R_(f.boundsPadding),up:[R_(f.up[0]),R_(f.up[1]),R_(f.up[2])]}:null}function Vte(l){var o;if(l===null)return"null";if(l===void 0)return"undefined";if(Array.isArray(l))return`Array(${l.length})`;if(typeof l=="object"){const f=(o=l.constructor)==null?void 0:o.name;return f&&f!=="Object"?f:"object"}return typeof l=="string"?`"${l}"`:typeof l}function aqe({apiName:l,inputs:o,minCount:f,itemName:g,usage:T,coerce:P}){const O=[];for(const z of o)Array.isArray(z)?O.push(...z):O.push(z);if(O.length<f){const z=f===1?g:`${g}s`;throw new Error(`${l} requires at least ${f} ${z}. ${T}`)}return O.map((z,H)=>{try{return P(z)}catch(re){const te=re instanceof Error?re.message:String(re);throw new Error(`${l} argument ${H+1}: ${te}`)}})}function dI(l,o){return{rewriteId:o.id,operation:l,owner:Sp(o),preservedFaces:[],preservedEdges:[],createdFaces:[],createdEdges:[],diagnostics:[],descendants:[]}}function lm(l,o,f,g,T,P){return{code:l,category:o,queryKind:f,message:g,source:f==="face"?iu(T):wl(T),query:f==="face"?iu(P):wl(P)}}function Y1(l,o,f){return{kind:"propagated-face",rewriteId:o.id,outcome:f,source:iu(l),owner:Sp(o)}}function fne(l,o,f){return{kind:"created-face",rewriteId:l.id,operation:o,slot:f,owner:Sp(l)}}function tM(l,o,f){return{kind:"propagated-edge",rewriteId:o.id,outcome:f,source:wl(l),selector:l.selector,owner:Sp(o)}}function oqe(l,o,f,g="edge"){return{kind:"created-edge",rewriteId:l.id,operation:o,slot:f,selector:g,owner:Sp(l)}}function Q1(l,o,f={}){return{queryKind:"face",kind:l,query:iu(o),source:iu(f.source),note:f.note}}function aq(l,o,f={}){return{queryKind:"edge",kind:l,query:wl(o),source:wl(f.source),note:f.note}}function Sh(l,o){l.descendants.push(o)}function pC(){return{faces:new Map,blockedNames:new Map,supportedQueries:[],blockedQueries:[]}}function Lm(l){return[l[0],l[1],l[2]]}function cI(l){return{...l,normal:Lm(l.normal),center:Lm(l.center),query:iu(l.query),uAxis:l.uAxis?Lm(l.uAxis):void 0,vAxis:l.vAxis?Lm(l.vAxis):void 0,descendant:l.descendant?LTt(l.descendant):void 0}}function LTt(l){return{kind:l.kind,semantic:l.semantic,memberCount:l.memberCount,memberNames:[...l.memberNames],coplanar:l.coplanar}}function pne(l,o,f){return{kind:l==="face"&&o.length===1?"single":"face-set",semantic:l,memberCount:o.length,memberNames:[...o],coplanar:f}}function RTt(l){if(l.length<=1)return!0;const o=l[0];if(o.planar===!1||!o.uAxis||!o.vAxis)return!1;const f=td(o.normal),g=f[0]*o.center[0]+f[1]*o.center[1]+f[2]*o.center[2];for(const T of l.slice(1)){if(T.planar===!1||!T.uAxis||!T.vAxis)return!1;const P=td(T.normal),O=Math.abs(f[0]*P[0]+f[1]*P[1]+f[2]*P[2]);if(Math.abs(O-1)>1e-6)return!1;const z=f[0]*T.center[0]+f[1]*T.center[1]+f[2]*T.center[2];if(Math.abs(z-g)>1e-6)return!1}return!0}function jTt(l,o,f,g){return{...l,descendant:pne(o,f,g)}}function BTt(l,o,f,g){const T=o.map(te=>cI(te)),P=T[0],O=RTt(T),z=T.reduce((te,W)=>[te[0]+W.center[0],te[1]+W.center[1],te[2]+W.center[2]],[0,0,0]),H=Math.max(T.length,1),re={...P,name:l,center:[z[0]/H,z[1]/H,z[2]/H],query:iu(f),planar:O?P.planar:!1,uAxis:O?P.uAxis:void 0,vAxis:O?P.vAxis:void 0};return jTt(re,g,T.map(te=>te.name),O)}function Cte(l){return{faces:new Map(Array.from(l.faces.entries(),([o,f])=>[o,cI(f)])),blockedNames:new Map(l.blockedNames),supportedQueries:l.supportedQueries.map(o=>iu(o)),blockedQueries:l.blockedQueries.map(o=>({query:iu(o.query),reason:o.reason}))}}function cqe(l,o){return o?l.some(f=>sT(f,o)):!1}function zTt(l,o){return o?l.some(f=>sT(f.query,o)):!1}function n4(l,o){!o||cqe(l.supportedQueries,o)||l.supportedQueries.push(iu(o))}function wte(l,o,f){!o||zTt(l.blockedQueries,o)||l.blockedQueries.push({query:iu(o),reason:f})}function JTt(l,o){o&&(l.supportedQueries=l.supportedQueries.filter(f=>!sT(f,o)))}function Zu(l,o){const f=cI(o);f.descendant||(f.descendant=pne("face",[f.name],f.planar!==!1)),l.faces.set(f.name,f),n4(l,o.query)}function Ebe(l,o,f,g){const T=l.faces.get(o);T&&(T.query=iu(f),l.faces.set(o,T),n4(l,f),n4(l,g))}function $ee(l,o,f,g,T){const P=l.faces.get(o);P&&(P.query=iu(f),P.descendant=pne(g,[o],P.planar!==!1),l.faces.set(o,P),n4(l,f),n4(l,T))}function aze(l,o,f){const g=l.faces.get(o);g&&(JTt(l,g.query),wte(l,g.query,f),l.faces.delete(o)),l.blockedNames.set(o,f)}function qTt(l,o,f){l.faces.has(o)&&l.faces.delete(o),l.blockedNames.set(o,f)}function WTt(l,o){const f=Ea.from(o);return{...l,center:f.point(l.center),normal:td(f.vector(l.normal)),query:iu(l.query),uAxis:l.uAxis?td(f.vector(l.uAxis)):void 0,vAxis:l.vAxis?td(f.vector(l.vAxis)):void 0}}function VTt(l,o){const f=Cte(l);return f.faces=new Map(Array.from(f.faces.entries(),([g,T])=>[g,WTt(T,o)])),f}function UTt(l){switch(l.kind){case"translate":return Ea.translation(l.x,l.y,l.z).toArray();case"rotate":return Ea.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg).toArray();case"scale":return Ea.scale([l.x,l.y,l.z]).toArray();case"rotateAround":return Ea.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]).toArray();case"mirror":return lqe([l.normalX,l.normalY,l.normalZ]);case"workplanePlacement":return[...l.matrix]}}function lqe(l){const o=Math.hypot(l[0],l[1],l[2]);if(o<1e-12)return Ea.identity().toArray();const f=l[0]/o,g=l[1]/o,T=l[2]/o;return[1-2*f*f,-2*f*g,-2*f*T,0,-2*g*f,1-2*g*g,-2*g*T,0,-2*T*f,-2*T*g,1-2*T*T,0,0,0,0,1]}function Ute(l){let o=Ea.identity();for(const f of l)switch(f.kind){case"translate":o=o.translate(f.x,f.y,0);break;case"rotate":o=o.rotateAxis([0,0,1],f.degrees);break;case"scale":o=o.scale([f.x,f.y,1]);break;case"mirror":o=o.mul(lqe([f.normalX,f.normalY,0]));break}return o.toArray()}function _C(l,o,f){const g=Ea.from(l).point([o,f,0]);return[g[0],g[1]]}function Z2e(l,o){return[(l[0]+o[0])/2,(l[1]+o[1])/2]}function $Tt(l){if(l.length===0)return[0,0,0];const o=l.reduce((f,g)=>[f[0]+g[0],f[1]+g[1],f[2]+g[2]],[0,0,0]);return[o[0]/l.length,o[1]/l.length,o[2]/l.length]}function OJ(l,o){return[l[0]*o[0],l[1]*o[1]]}function MJ(l,o,f,g,T,P,O=0){return[l[0]+o[0]*g+f[0]*T+((P==null?void 0:P[0])??0)*O,l[1]+o[1]*g+f[1]*T+((P==null?void 0:P[1])??0)*O,l[2]+o[2]*g+f[2]*T+((P==null?void 0:P[2])??0)*O]}function HTt(l){const o=Math.hypot(l[0],l[1]);return o<1e-12?[1,0]:[l[0]/o,l[1]/o]}function _2e(l,o){return[l[1]*o[2]-l[2]*o[1],l[2]*o[0]-l[0]*o[2],l[0]*o[1]-l[1]*o[0]]}function GTt(l){const o=td(l),f=Math.abs(o[2])<.9?[0,0,1]:[0,1,0],g=td(_2e(f,o)),T=td(_2e(o,g));return{u:g,v:T}}function ZD(l,o,f,g,T){const P=HTt([f[0]-o[0],f[1]-o[1]]),O=[P[1],-P[0]],z=Z2e(o,f);return{name:l,normal:[O[0],O[1],0],center:[z[0],z[1],g],planar:!0,uAxis:[P[0],P[1],0],vAxis:[0,0,1],query:iu(T)}}function xh(l,o){if(o)return{kind:"tracked-face",faceName:l,owner:o}}function XTt(l,o){const f=pC(),g=l.center?-l.x/2:0,T=l.center?-l.y/2:0,P=g+l.x,O=T+l.y,z=l.center?-l.z/2:0,H=z+l.z,re=[g,T],te=[P,T],W=[P,O],Ee=[g,O],se=xh("top",o),me=xh("bottom",o);return Zu(f,{name:"top",normal:[0,0,1],center:[(g+P)/2,(T+O)/2,H],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0],query:se}),Zu(f,{name:"bottom",normal:[0,0,-1],center:[(g+P)/2,(T+O)/2,z],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0],query:me}),Zu(f,{...ZD("side-bottom",re,te,(H+z)/2,xh("side-bottom",o))}),Zu(f,{...ZD("side-right",te,W,(H+z)/2,xh("side-right",o))}),Zu(f,{...ZD("side-top",W,Ee,(H+z)/2,xh("side-top",o))}),Zu(f,{...ZD("side-left",Ee,re,(H+z)/2,xh("side-left",o))}),f}function YTt(l,o){const f=pC(),g=l.center?-l.height/2:0,T=g+l.height,P=l.radiusTop??l.radius,O=(Math.abs(l.radius)+Math.abs(P))/2;return Zu(f,{name:"top",normal:[0,0,1],center:[0,0,T],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0],query:xh("top",o)}),Zu(f,{name:"bottom",normal:[0,0,-1],center:[0,0,g],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0],query:xh("bottom",o)}),Zu(f,{name:"side",normal:[1,0,0],center:[O,0,(T+g)/2],planar:!1,query:xh("side",o)}),f}function QTt(l,o,f,g){const T=Ute(l.transforms),P=l.center?-l.width/2:0,O=l.center?-l.height/2:0,z=P+l.width,H=O+l.height,re=_C(T,P,O),te=_C(T,z,O),W=_C(T,z,H),Ee=_C(T,P,H),se=Z2e(re,W),me=f?-o/2:0,Xe=me+o,it=td([te[0]-re[0],te[1]-re[1],0]),at=td([Ee[0]-re[0],Ee[1]-re[1],0]),It=pC();return Zu(It,{name:"top",normal:[0,0,1],center:[se[0],se[1],Xe],planar:!0,uAxis:it,vAxis:at,query:xh("top",g)}),Zu(It,{name:"bottom",normal:[0,0,-1],center:[se[0],se[1],me],planar:!0,uAxis:it,vAxis:[-at[0],-at[1],-at[2]],query:xh("bottom",g)}),Zu(It,ZD("side-bottom",re,te,(Xe+me)/2,xh("side-bottom",g))),Zu(It,ZD("side-right",te,W,(Xe+me)/2,xh("side-right",g))),Zu(It,ZD("side-top",W,Ee,(Xe+me)/2,xh("side-top",g))),Zu(It,ZD("side-left",Ee,re,(Xe+me)/2,xh("side-left",g))),It}function ZTt(l,o,f,g){const T=pC(),P=Ute(l.transforms),O=Ea.from(P).point([0,0,0]),z=Ea.from(P).point([l.radius,0,0]),H=td([z[0]-O[0],z[1]-O[1],0]),re=td(Ea.from(P).vector([1,0,0])),te=td(Ea.from(P).vector([0,1,0])),W=f?-o/2:0,Ee=W+o;return Zu(T,{name:"top",normal:[0,0,1],center:[O[0],O[1],Ee],planar:!0,uAxis:re,vAxis:te,query:xh("top",g)}),Zu(T,{name:"bottom",normal:[0,0,-1],center:[O[0],O[1],W],planar:!0,uAxis:re,vAxis:[-te[0],-te[1],-te[2]],query:xh("bottom",g)}),Zu(T,{name:"side",normal:H,center:[z[0],z[1],(Ee+W)/2],planar:!1,query:xh("side",g)}),T}function KTt(l,o){switch(l.profile.kind){case"rect":case"roundedRect":return QTt(l.profile,l.height,l.center,o);case"circle":return ZTt(l.profile,l.height,l.center,o);default:return pC()}}function ux(l,o){var f;return(f=l==null?void 0:l.createdFaces.find(g=>g.query.slot===o))==null?void 0:f.query}function Pbe(l,o){if(o)return l==null?void 0:l.descendants.find(f=>f.queryKind==="face"&&sT(f.query,o))}function LJ(l,o){var f;if(o)return(f=l==null?void 0:l.preservedFaces.find(g=>sT(g.query.source,o)))==null?void 0:f.query}function ekt(l){return`inner-${l}`}function uqe(l,o){const f=px(l),g=[];for(const T of f.faces.keys())T==="top"&&o.includes("top")||T==="bottom"&&o.includes("bottom")||g.push(ekt(T));return g}function tkt(l,o){var g;const f=["wall"];return l.counterbore&&f.push("counterbore-wall","counterbore-floor"),l.countersink&&f.push("countersink-wall"),Rm(o).kind==="blind"&&f.push("floor"),((g=Ab(o))==null?void 0:g.kind)==="blind"&&f.push("cap"),f}function _qe(l,o,f){var T;const g=(()=>{switch(l.kind){case"circle":return["wall"];case"rect":case"roundedRect":return["wall-bottom","wall-right","wall-top","wall-left"];default:return[]}})();return Rm(o).kind==="blind"&&g.push("floor"),((T=Ab(o))==null?void 0:T.kind)==="blind"&&g.push("cap"),g}function nkt(l,o){const f=["entry-rim","forward-end-rim"];return Ab(o)&&f.push("reverse-end-rim"),(l.counterbore||l.countersink)&&f.push("head-transition-rim"),f}function rkt(l,o,f){if(_qe(l,o).length===0)return[];const g=["entry-rim","forward-end-rim"];return Ab(o)&&g.push("reverse-end-rim"),g}function UO(l,o){if(!o)return[];const f=new Set(l.faces.keys()),g=(()=>{switch(o.kind){case"tracked-face":return[o.faceName];case"face-ref":return o.faceName?[o.faceName]:[];case"canonical-face":switch(o.face){case"front":return f.has("side-bottom")?["side-bottom"]:f.has("side")?["side"]:[];case"back":return f.has("side-top")?["side-top"]:f.has("side")?["side"]:[];case"left":return f.has("side-left")?["side-left"]:f.has("side")?["side"]:[];case"right":return f.has("side-right")?["side-right"]:f.has("side")?["side"]:[];case"top":return f.has("top")?["top"]:[];case"bottom":return f.has("bottom")?["bottom"]:[]}case"created-face":return[o.slot];case"propagated-face":return UO(l,o.source)}})();return g.filter((T,P)=>f.has(T)&&g.indexOf(T)===P)}function ikt(l,o){switch(l){case"top":return o.has("bottom")?["bottom"]:[];case"bottom":return o.has("top")?["top"]:[];case"side-bottom":return o.has("side-top")?["side-top"]:[];case"side-top":return o.has("side-bottom")?["side-bottom"]:[];case"side-left":return o.has("side-right")?["side-right"]:[];case"side-right":return o.has("side-left")?["side-left"]:[];case"side":return o.has("side")?["side"]:[];default:return[]}}function oze(l,o){switch(o){case"host":return`This selected host face is rewritten by the ${l} result and is not a defended named face target.`;case"through-exit":return`This opposite face is pierced by the through-${l} and is not a defended named face target.`;case"up-to-face-target":return`This selected up-to-face termination face is rewritten by the ${l} result and is not a defended named face target.`}}function cze(l){switch(l){case"host":return 3;case"up-to-face-target":return 2;case"through-exit":return 1}}function skt(l){var o,f;return((o=l.counterbore)==null?void 0:o.depth)??((f=l.countersink)==null?void 0:f.depth)??0}function akt(l,o){var T;const f=((T=Ab(o))==null?void 0:T.depth)??0;if(f>0)return(Rm(o).depth-f)/2;const g=skt(l);return g+Math.max(Rm(o).depth-g,0)/2}function okt(l){var f;const o=((f=Ab(l))==null?void 0:f.depth)??0;return(Rm(l).depth-o)/2}function $te(l,o,f){if(!l)return[];const g=px(l),T=new Set(g.faces.keys()),P=new Map,O=(te,W)=>{const Ee=P.get(te);(!Ee||cze(W)>cze(Ee))&&P.set(te,W)},z=UO(g,o),H=Rm(f);for(const te of z)if(O(te,"host"),H.kind==="through")for(const W of ikt(te,T))O(W,"through-exit");if(H.kind==="upToFace")for(const te of UO(g,H.face))O(te,"up-to-face-target");const re=Ab(f);if((re==null?void 0:re.kind)==="upToFace")for(const te of UO(g,re.face))O(te,"up-to-face-target");return Array.from(P.entries()).map(([te,W])=>({name:te,reason:W})).sort((te,W)=>te.name.localeCompare(W.name))}function Hee(l,o){var f;return o?Pb((f=l.query)==null?void 0:f.owner,o):!0}function fqe(l,o,f,g){switch(g.kind){case"tracked-face":return o===g.faceName&&Hee(f,g.owner);case"face-ref":return(g.faceName==null||o===g.faceName)&&Hee(f,g.owner);case"canonical-face":return UO(l,g).includes(o)&&Hee(f,g.owner);case"created-face":return o===g.slot&&Hee(f,g.owner);case"propagated-face":return sT(f.query,g)||fqe(l,o,f,g.source)}}function ckt(l,o){if(!o)return[];const f=new Set,g=[];for(const[T,P]of l.faces.entries())f.has(T)||fqe(l,T,P,o)&&(f.add(T),g.push({name:T,face:cI(P)}));return g}function lkt(l,o){return l.flatMap(f=>ckt(f,o))}function ukt(l){if(l.length===0)return null;const o=[...new Set(l.map(f=>f.name))];return o.length===1?o[0]:null}function _kt(l,o){return l??o}function fkt(l,o){const f=l.get(o.name);if(f){f.push(o);return}l.set(o.name,[o])}function pkt(l,o,f){for(const[g,T]of o.entries()){const P=T.length===1?T[0].query:{kind:"face-ref",faceName:g,owner:Sp(f)},O=T.some(H=>H.semantic==="region")?"region":T.length>1?"set":T[0].semantic,z=BTt(g,T.map(H=>H.face),P,O);Zu(l,z);for(const H of T){n4(l,H.query);for(const re of H.aliases)n4(l,re)}T.length>1&&n4(l,P)}}function f2e(l,o){var f,g,T;if(!l)return pC();switch(l.kind){case"queryOwner":return f2e(l.base,o??l.owner);case"transform":{let P=f2e(l.base,o);for(const O of l.steps)P=VTt(P,UTt(O));return P}case"box":return XTt(l,o);case"cylinder":return YTt(l,o);case"extrude":return KTt(l,o);case"sheetMetal":{const P=pC();for(const O of vTt(l.model,l.output))Zu(P,{name:O.name,normal:Lm(O.normal),center:Lm(O.center),planar:O.planar,uAxis:O.uAxis?Lm(O.uAxis):void 0,vAxis:O.vAxis?Lm(O.vAxis):void 0,query:xh(O.name,o),descendant:pne(O.semantic,O.memberNames,O.coplanar)});return P}case"shell":{const P=Cte(px(l.base));for(const[O,z]of P.faces.entries()){const H=LJ(l.queryPropagation,z.query);H&&Ebe(P,O,H,z.query)}for(const O of uqe(l.base,l.openFaces)){const z=O.slice(6),H=P.faces.get(z),re=ux(l.queryPropagation,O);!H||!re||Zu(P,{...cI(H),name:O,center:[H.center[0]-H.normal[0]*l.thickness,H.center[1]-H.normal[1]*l.thickness,H.center[2]-H.normal[2]*l.thickness],normal:[-H.normal[0],-H.normal[1],-H.normal[2]],uAxis:H.uAxis?Lm(H.uAxis):void 0,vAxis:H.vAxis?[-H.vAxis[0],-H.vAxis[1],-H.vAxis[2]]:void 0,query:re})}return P}case"hole":{const P=Cte(px(l.base));for(const[at,It]of P.faces.entries()){const tn=LJ(l.queryPropagation,It.query),At=Pbe(l.queryPropagation,tn);if(tn&&(At==null?void 0:At.kind)==="face-region"){$ee(P,at,tn,"region",It.query);continue}tn&&Ebe(P,at,tn,It.query)}for(const at of $te(l.base,l.placement.placement.workplane.source,l.extent)){const It=P.faces.get(at.name);if(((f=It==null?void 0:It.descendant)==null?void 0:f.semantic)==="region")continue;const tn=It?LJ(l.queryPropagation,It.query):void 0;if(It&&tn){$ee(P,at.name,tn,"region",It.query);continue}aze(P,at.name,oze("hole",at.reason))}const O=l.placement.placement.workplane,z=O.origin,H=[-O.normal[0],-O.normal[1],-O.normal[2]],re=Rm(l.extent),te=Ab(l.extent),W=ux(l.queryPropagation,"wall");if(W){const at=akt(l.hole,l.extent);Zu(P,{name:"wall",normal:[-O.u[0],-O.u[1],-O.u[2]],center:[z[0]+O.u[0]*l.hole.radius+H[0]*at,z[1]+O.u[1]*l.hole.radius+H[1]*at,z[2]+O.u[2]*l.hole.radius+H[2]*at],planar:!1,query:W})}const Ee=ux(l.queryPropagation,"counterbore-wall");Ee&&l.hole.counterbore&&Zu(P,{name:"counterbore-wall",normal:[-O.u[0],-O.u[1],-O.u[2]],center:[z[0]+O.u[0]*l.hole.counterbore.radius+H[0]*(l.hole.counterbore.depth/2),z[1]+O.u[1]*l.hole.counterbore.radius+H[1]*(l.hole.counterbore.depth/2),z[2]+O.u[2]*l.hole.counterbore.radius+H[2]*(l.hole.counterbore.depth/2)],planar:!1,query:Ee});const se=ux(l.queryPropagation,"counterbore-floor");se&&l.hole.counterbore&&Zu(P,{name:"counterbore-floor",normal:Lm(O.normal),center:[z[0]+H[0]*l.hole.counterbore.depth,z[1]+H[1]*l.hole.counterbore.depth,z[2]+H[2]*l.hole.counterbore.depth],planar:!0,uAxis:Lm(O.u),vAxis:Lm(O.v),query:se});const me=ux(l.queryPropagation,"countersink-wall");if(me&&l.hole.countersink){const at=l.hole.countersink.depth/2,It=(l.hole.radius+l.hole.countersink.radius)/2;Zu(P,{name:"countersink-wall",normal:[-O.u[0],-O.u[1],-O.u[2]],center:[z[0]+O.u[0]*It+H[0]*at,z[1]+O.u[1]*It+H[1]*at,z[2]+O.u[2]*It+H[2]*at],planar:!1,query:me})}const Xe=ux(l.queryPropagation,"floor");Xe&&Zu(P,{name:"floor",normal:Lm(O.normal),center:[z[0]+H[0]*re.depth,z[1]+H[1]*re.depth,z[2]+H[2]*re.depth],planar:!0,uAxis:Lm(O.u),vAxis:Lm(O.v),query:Xe});const it=ux(l.queryPropagation,"cap");return it&&(te==null?void 0:te.kind)==="blind"&&Zu(P,{name:"cap",normal:[-O.normal[0],-O.normal[1],-O.normal[2]],center:[z[0]-H[0]*te.depth,z[1]-H[1]*te.depth,z[2]-H[2]*te.depth],planar:!0,uAxis:Lm(O.u),vAxis:[-O.v[0],-O.v[1],-O.v[2]],query:it}),P}case"cut":{const P=Cte(px(l.base));for(const[Xe,it]of P.faces.entries()){const at=LJ(l.queryPropagation,it.query),It=Pbe(l.queryPropagation,at);if(at&&(It==null?void 0:It.kind)==="face-region"){$ee(P,Xe,at,"region",it.query);continue}at&&Ebe(P,Xe,at,it.query)}for(const Xe of $te(l.base,l.placement.placement.workplane.source,l.extent)){const it=P.faces.get(Xe.name);if(((g=it==null?void 0:it.descendant)==null?void 0:g.semantic)==="region")continue;const at=it?LJ(l.queryPropagation,it.query):void 0;if(it&&at){$ee(P,Xe.name,at,"region",it.query);continue}aze(P,Xe.name,oze("cut",Xe.reason))}const O=l.placement.placement,z=O.workplane.origin,H=[-O.workplane.normal[0],-O.workplane.normal[1],-O.workplane.normal[2]],re=Rm(l.extent),te=Ab(l.extent),W=(te==null?void 0:te.depth)??0,Ee=okt(l.extent);if(l.profile.kind==="circle"){const Xe=ux(l.queryPropagation,"wall");if(Xe){const it=l.profile.radius,at=l.taper?it*l.taper.scale[0]:it,It=(it+at)/2;Zu(P,{name:"wall",normal:[-O.workplane.u[0],-O.workplane.u[1],-O.workplane.u[2]],center:[z[0]+O.workplane.u[0]*It+H[0]*Ee,z[1]+O.workplane.u[1]*It+H[1]*Ee,z[2]+O.workplane.u[2]*It+H[2]*Ee],planar:!1,query:Xe})}}if(l.profile.kind==="rect"||l.profile.kind==="roundedRect"){const Xe=Ute(l.profile.transforms),it=l.profile.center?-l.profile.width/2:0,at=l.profile.center?-l.profile.height/2:0,It=it+l.profile.width,tn=at+l.profile.height,At=_C(Xe,it,at),mt=_C(Xe,It,at),ht=_C(Xe,It,tn),xn=_C(Xe,it,tn),Pn=((T=l.taper)==null?void 0:T.scale)??[1,1],$r=OJ(At,Pn),zn=OJ(mt,Pn),ii=OJ(ht,Pn),Gr=OJ(xn,Pn),mn=[{name:"wall-bottom",reverseStart:At,reverseEnd:mt,forwardStart:$r,forwardEnd:zn},{name:"wall-right",reverseStart:mt,reverseEnd:ht,forwardStart:zn,forwardEnd:ii},{name:"wall-top",reverseStart:ht,reverseEnd:xn,forwardStart:ii,forwardEnd:Gr},{name:"wall-left",reverseStart:xn,reverseEnd:At,forwardStart:Gr,forwardEnd:$r}];for(const $s of mn){const is=ux(l.queryPropagation,$s.name);if(!is)continue;const Wt=MJ(z,O.workplane.u,O.workplane.v,$s.reverseStart[0],$s.reverseStart[1],H,-W),Es=MJ(z,O.workplane.u,O.workplane.v,$s.reverseEnd[0],$s.reverseEnd[1],H,-W),Hs=MJ(z,O.workplane.u,O.workplane.v,$s.forwardStart[0],$s.forwardStart[1],H,re.depth),Ua=MJ(z,O.workplane.u,O.workplane.v,$s.forwardEnd[0],$s.forwardEnd[1],H,re.depth),Di=td([Es[0]-Wt[0],Es[1]-Wt[1],Es[2]-Wt[2]]),ko=td([Hs[0]-Wt[0],Hs[1]-Wt[1],Hs[2]-Wt[2]]),K_=td(_2e(Di,ko));Zu(P,{name:$s.name,normal:K_,center:$Tt([Wt,Es,Hs,Ua]),planar:!0,uAxis:Di,vAxis:ko,query:is})}}const se=ux(l.queryPropagation,"floor");if(se){const Xe=(()=>{if(l.profile.kind==="rect"||l.profile.kind==="roundedRect"){const it=Ute(l.profile.transforms),at=l.profile.center?-l.profile.width/2:0,It=l.profile.center?-l.profile.height/2:0,tn=at+l.profile.width,At=It+l.profile.height,mt=Z2e(_C(it,at,It),_C(it,tn,At)),ht=l.taper?OJ(mt,l.taper.scale):mt;return MJ(z,O.workplane.u,O.workplane.v,ht[0],ht[1],H,re.depth)}return[z[0]+H[0]*re.depth,z[1]+H[1]*re.depth,z[2]+H[2]*re.depth]})();Zu(P,{name:"floor",normal:Lm(O.workplane.normal),center:Xe,planar:!0,uAxis:Lm(O.workplane.u),vAxis:Lm(O.workplane.v),query:se})}const me=ux(l.queryPropagation,"cap");return me&&(te==null?void 0:te.kind)==="blind"&&Zu(P,{name:"cap",normal:[-O.workplane.normal[0],-O.workplane.normal[1],-O.workplane.normal[2]],center:[z[0]-H[0]*te.depth,z[1]-H[1]*te.depth,z[2]-H[2]*te.depth],planar:!0,uAxis:Lm(O.workplane.u),vAxis:[-O.workplane.v[0],-O.workplane.v[1],-O.workplane.v[2]],query:me}),P}case"sphere":case"revolve":case"loft":case"sweep":case"hull":case"fillet":case"chamfer":return pC();case"trimByPlane":{const P=pC(),O=ux(l.queryPropagation,"plane-cap");if(!O)return P;const z=px(l.base),H=Array.from(z.faces.values()).map(me=>me.center),re=H.length>0?H.reduce((me,Xe)=>[me[0]+Xe[0],me[1]+Xe[1],me[2]+Xe[2]],[0,0,0]).map(me=>me/H.length):[0,0,l.originOffset],te=td([l.normalX,l.normalY,l.normalZ]),W=re[0]*te[0]+re[1]*te[1]+re[2]*te[2]-l.originOffset,Ee=[re[0]-te[0]*W,re[1]-te[1]*W,re[2]-te[2]*W],se=GTt(te);return Zu(P,{name:"plane-cap",normal:te,center:Ee,planar:!0,uAxis:se.u,vAxis:se.v,query:O}),P}case"boolean":{const P=pC(),O=l.shapes.map(re=>px(re)),z=l.queryPropagation;if(!z)return P;const H=new Map;for(const re of z.preservedFaces){const te=iu(re.query),W=lkt(O,re.query.source),Ee=Pbe(z,te);if(re.status==="ambiguous"&&!Ee){const me=ukt(W),Xe=_kt(re.note,"This propagated boolean face lineage is ambiguous and is not part of the defended named-face subset.");for(const it of W)wte(P,it.face.query,Xe);me&&qTt(P,me,Xe),wte(P,re.query,Xe),wte(P,re.query.kind==="propagated-face"?re.query.source:void 0,Xe);continue}const se=(Ee==null?void 0:Ee.kind)==="face-region"?"region":(Ee==null?void 0:Ee.kind)==="face-set"?"set":"face";for(const me of W)fkt(H,{name:me.name,face:cI(me.face),query:te,semantic:se,aliases:[te,...re.query.kind==="propagated-face"?[re.query.source]:[],...me.face.query?[me.face.query]:[]].filter(Xe=>Xe!=null)})}return pkt(P,H,z.owner),P}}}function px(l){return f2e(l,_ne(l))}function dkt(l){return Array.from(px(l).faces.keys()).sort()}function mkt(l){const o=px(l);return Array.from(o.faces.entries()).filter(([,f])=>f.query!=null).map(([f,g])=>({name:f,query:iu(g.query)})).sort((f,g)=>f.name.localeCompare(g.name))}function lze(l,o){const g=px(l).faces.get(o);return g?cI(g):null}function uze(l,o){const f=px(l),g=f.blockedNames.get(o);if(g)return g;const T=Array.from(f.faces.keys()).sort();return`Face "${o}" is not available. Supported faces: ${T.join(", ")||"none"}`}function hkt(l,o){if(!o)return null;const f=px(l);if(cqe(f.supportedQueries,o))return null;const g=UO(f,o);if(g.some(P=>f.faces.has(P)))return null;for(const P of g){const O=f.blockedNames.get(P);if(O)return O}const T=f.blockedQueries.find(P=>sT(P.query,o));return T?T.reason:o.kind==="created-face"||o.kind==="propagated-face"?"This face query is not part of the target shape's defended face subset.":g.length===0&&f.faces.size===0&&f.blockedQueries.length===0||o.kind==="tracked-face"||o.kind==="canonical-face"||o.kind==="face-ref"?null:"This face query is not part of the target shape's defended face subset."}function gkt(l,o){return l?uqe(l,o).sort():[]}function ykt(l,o){return tkt(l,o)}function vkt(l,o,f){return _qe(l,o)}function bkt(l,o){return nkt(l,o)}function xkt(l,o,f){return rkt(l,o)}function dne(l){return mkt(l)}const Skt=["front","back","left","right","top","bottom"];function K2e(l){if(!l)return null;switch(l.kind){case"queryOwner":case"transform":return K2e(l.base);case"shell":case"hole":case"cut":case"boolean":case"hull":case"trimByPlane":case"fillet":case"chamfer":return uC(l.queryPropagation)??null;case"box":case"cylinder":case"sphere":case"extrude":case"sheetMetal":case"revolve":case"loft":case"sweep":return null}}function _ze(l,o){const f=l.find(g=>sT(g.source,o.source));if(!f){l.push({source:iu(o.source),status:o.status});return}o.status==="ambiguous"&&(f.status="ambiguous")}function fze(l,o){const f=l.find(g=>gC(g.source,o.source));if(!f){l.push({source:wl(o.source),status:o.status});return}o.status==="ambiguous"&&(f.status="ambiguous")}function Tkt(l){return l?Skt.map(o=>({source:{kind:"canonical-face",face:o,owner:Sp(l)},status:"supported"})):[]}function kkt(l){const o=K2e(l);if(!o)return Tkt(_ne(l));const f=[];for(const g of o.preservedFaces)_ze(f,{source:g.query,status:g.status});for(const g of o.createdFaces)_ze(f,{source:g.query,status:"supported"});return f}function Ckt(l){const o=K2e(l);if(!o)return[];const f=[];for(const g of o.preservedEdges)fze(f,{source:g.query,status:g.status});for(const g of o.createdEdges)fze(f,{source:g.query,status:"supported"});return f}function wkt(l){const o=[];for(const f of l){const g=o.find(T=>sT(T.source,f.source));if(g){g.count+=1,g.hasAmbiguousSource=g.hasAmbiguousSource||f.status==="ambiguous";continue}o.push({source:iu(f.source),count:1,hasAmbiguousSource:f.status==="ambiguous"})}return o}function Ekt(l){const o=[];for(const f of l){const g=o.find(T=>gC(T.source,f.source));if(g){g.count+=1,g.hasAmbiguousSource=g.hasAmbiguousSource||f.status==="ambiguous";continue}o.push({source:wl(f.source),count:1,hasAmbiguousSource:f.status==="ambiguous"})}return o}function exe(l,o){const f=o?l:l.slice(0,1);return wkt(f.flatMap(g=>kkt(g)))}function txe(l,o){const f=o?l:l.slice(0,1);return Ekt(f.flatMap(g=>Ckt(g)))}function nxe(l,o){const f=o==="union"?"Boolean union preserved owner lineage, but none of its operands exposed defended face queries in the supported subset.":o==="difference"?"Boolean difference can only propagate explicit base-operand face queries, and none were available in the supported subset.":"Boolean intersection needs explicit operand face queries to defend any surviving descendants, and none were available in the supported subset.";l.diagnostics.push(lm(`boolean-${o}-face-propagation-unsupported`,"unsupported","face",f))}function rxe(l,o){const f=o==="union"?"Boolean union preserved owner lineage, but none of its operands exposed defended edge queries in the supported subset.":o==="difference"?"Boolean difference can only propagate explicit base-operand edge queries, and none were available in the supported subset.":"Boolean intersection needs explicit operand edge queries to defend any surviving descendants, and none were available in the supported subset.";l.diagnostics.push(lm(`boolean-${o}-edge-propagation-unsupported`,"unsupported","edge",f))}function Pkt(l,o,f){const g=exe(f,!0);if(g.length===0){nxe(o,"union");return}for(const T of g){if(T.count===1&&!T.hasAmbiguousSource){const O=Y1(T.source,l,"preserved");o.preservedFaces.push({query:O,status:"supported"}),Sh(o,Q1("single",O,{source:T.source,note:"Boolean union keeps one defended single face descendant for this lineage."}));continue}const P=Y1(T.source,l,T.count>1?"merged":"preserved");o.preservedFaces.push({query:P,status:"ambiguous"}),T.count>1&&!T.hasAmbiguousSource&&Sh(o,Q1("face-set",P,{source:T.source,note:"Boolean union keeps a defended descendant face set for this merged lineage."})),o.diagnostics.push(lm(T.count>1?"boolean-union-face-merged-ambiguous":"boolean-union-face-inherited-ambiguity","ambiguous","face",T.count>1?`Boolean union cannot defend ${rq(T.source)} because ${T.count} operand descendants share that face lineage and may merge.`:`Boolean union inherits ${rq(T.source)} from an already-ambiguous rewrite result, so the post-union descendant remains ambiguous.`,T.source,P))}}function Dkt(l,o,f){const g=txe(f,!0);if(g.length===0){rxe(o,"union");return}for(const T of g){if(T.count===1&&!T.hasAmbiguousSource){const O=tM(T.source,l,"preserved");o.preservedEdges.push({query:O,status:"supported"}),Sh(o,aq("single",O,{source:T.source,note:"Boolean union keeps one defended single edge descendant for this lineage."}));continue}const P=tM(T.source,l,T.count>1?"merged":"preserved");o.preservedEdges.push({query:P,status:"ambiguous"}),o.diagnostics.push(lm(T.count>1?"boolean-union-edge-merged-ambiguous":"boolean-union-edge-inherited-ambiguity","ambiguous","edge",T.count>1?`Boolean union cannot defend ${iq(T.source)} because ${T.count} operand descendants share that edge lineage and may merge.`:`Boolean union inherits ${iq(T.source)} from an already-ambiguous rewrite result, so the post-union descendant remains ambiguous.`,T.source,P))}}function Akt(l,o,f){const g=exe(f,!1);if(g.length===0){nxe(o,"difference");return}for(const T of g){const P=Y1(T.source,l,"split");o.preservedFaces.push({query:P,status:"ambiguous"}),Sh(o,Q1("face-region",P,{source:T.source,note:"Boolean difference keeps a defended descendant region on the source surface."})),o.diagnostics.push(lm("boolean-difference-face-split-ambiguous","ambiguous","face",`Boolean difference can trace ${rq(T.source)} to the base operand, but subtractive cutters may split or erase its surviving descendants.`,T.source,P))}}function Nkt(l,o,f){const g=txe(f,!1);if(g.length===0){rxe(o,"difference");return}for(const T of g){const P=tM(T.source,l,"split");o.preservedEdges.push({query:P,status:"ambiguous"}),o.diagnostics.push(lm("boolean-difference-edge-split-ambiguous","ambiguous","edge",`Boolean difference can trace ${iq(T.source)} to the base operand, but subtractive cutters may split or erase its surviving descendants.`,T.source,P))}}function Ikt(l,o,f){const g=exe(f,!0);if(g.length===0){nxe(o,"intersection");return}for(const T of g){const P=Y1(T.source,l,"split");o.preservedFaces.push({query:P,status:"ambiguous"}),Sh(o,Q1("face-region",P,{source:T.source,note:"Boolean intersection keeps a defended descendant region on the source surface."})),o.diagnostics.push(lm("boolean-intersection-face-split-ambiguous","ambiguous","face",`Boolean intersection can trace ${rq(T.source)}, but the kept overlap is only a clipped descendant subset and cannot be defended as one stable face target.`,T.source,P))}}function Fkt(l,o,f){const g=txe(f,!0);if(g.length===0){rxe(o,"intersection");return}for(const T of g){const P=tM(T.source,l,"split");o.preservedEdges.push({query:P,status:"ambiguous"}),o.diagnostics.push(lm("boolean-intersection-edge-split-ambiguous","ambiguous","edge",`Boolean intersection can trace ${iq(T.source)}, but the kept overlap is only a clipped descendant subset and cannot be defended as one stable edge target.`,T.source,P))}}function YD(l,o,f){const g=dI(`boolean:${l}`,o);switch(l){case"union":return Pkt(o,g,f),Dkt(o,g,f),g;case"difference":return Akt(o,g,f),Nkt(o,g,f),g;case"intersection":return Ikt(o,g,f),Fkt(o,g,f),g}}function pqe(l,o){switch(o){case"host":return`The selected host face is rewritten by the ${l} result and is not a defended named target.`;case"through-exit":return`This opposite face is pierced by the through-${l} and is not a defended named target.`;case"up-to-face-target":return`The selected up-to-face termination face is rewritten by the ${l} result and is not a defended named target.`}}function Okt(l,o,f){switch(l){case"entry-rim":return"Hole results record the entry perimeter as a defended descendant edge chain on the host face.";case"forward-end-rim":{const g=Rm(f);return g.kind==="blind"?"Blind holes record the floor perimeter as a defended descendant edge chain.":g.kind==="upToFace"?"Hole upToFace results record the termination perimeter as a defended descendant edge chain.":"Through holes record the exit perimeter as a defended descendant edge chain."}case"reverse-end-rim":{const g=Ab(f);return(g==null?void 0:g.kind)==="blind"?"Reverse two-sided holes record the cap perimeter as a defended descendant edge chain.":"Reverse two-sided hole termination stays visible as a defended descendant edge chain."}case"head-transition-rim":return o.counterbore?"Counterbored holes record the shoulder transition as a defended descendant edge chain.":"Countersunk holes record the sink-to-shaft transition as a defended descendant edge chain.";default:return"This hole-created edge chain stays inspectable in the defended topology-rewrite subset."}}function Mkt(l,o){switch(l){case"entry-rim":return"Cut results record the sketched entry perimeter as a defended descendant edge chain on the host face.";case"forward-end-rim":{const f=Rm(o);return f.kind==="blind"?"Blind cutouts record the floor perimeter as a defended descendant edge chain.":f.kind==="upToFace"?"Cut upToFace results record the termination perimeter as a defended descendant edge chain.":"Through cutouts record the exit perimeter as a defended descendant edge chain."}case"reverse-end-rim":{const f=Ab(o);return(f==null?void 0:f.kind)==="blind"?"Reverse two-sided cutouts record the cap perimeter as a defended descendant edge chain.":"Reverse two-sided cut termination stays visible as a defended descendant edge chain."}default:return"This cut-created edge chain stays inspectable in the defended topology-rewrite subset."}}function dqe(l,o,f,g){const T=Rm(g);T.kind==="upToFace"&&l.diagnostics.push(lm(`${f}-up-to-face-target-split-ambiguous`,"ambiguous","face",`${f==="hole"?"Hole":"Cut"} upToFace intent records the selected termination face as an explicit split-face ambiguity instead of silently keeping it queryable.`,T.face,Y1(T.face,o,"split")));const P=Ab(g);(P==null?void 0:P.kind)==="upToFace"&&l.diagnostics.push(lm(`${f}-reverse-up-to-face-target-split-ambiguous`,"ambiguous","face",`${f==="hole"?"Hole":"Cut"} reverse upToFace intent records the selected reverse termination face as an explicit split-face ambiguity instead of silently keeping it queryable.`,P.face,Y1(P.face,o,"split")))}function Lkt(l,o,f){const g=dI("shell",l),T=dne(o),P=gkt(o,f);for(const O of T){const z=Y1(O.query,l,"preserved");g.preservedFaces.push({query:z,status:"supported",note:"The outer shell face survives as a defended preserved-face query on the shelled result."}),Sh(g,Q1("single",z,{source:O.query,note:"Shell keeps this face as one defended single descendant."}))}for(const O of P){const z=fne(l,"shell",O);g.createdFaces.push({query:z,note:"This shell-created inner face is part of the defended named-face subset."}),Sh(g,Q1("single",z,{note:"This shell-created face resolves to one defended descendant."}))}if(T.length===0&&P.length===0){const O=f.length>0?` Open faces: ${f.join(", ")}.`:"";g.diagnostics.push(lm("shell-face-propagation-unsupported","unsupported","face",`Shell exact lowering is supported here, but compiler-owned face propagation is not defended for this shell base.${O}`))}return g.diagnostics.push(lm("shell-edge-propagation-ambiguous","ambiguous","edge","Shell rewrites result edges, but durable edge-query propagation is not defended yet.")),g}function Rkt(l,o,f,g,T){const P=dI("hole",l),O=new Map($te(o,f.workplane.source,T).map(z=>[z.name,z.reason]));for(const z of dne(o)){const H=O.get(z.name);if(H){const te=Y1(z.query,l,"split");P.preservedFaces.push({query:te,status:"ambiguous",note:pqe("hole",H)}),Sh(P,Q1("face-region",te,{source:z.query,note:"This rewritten hole face remains a defended descendant region on the same source surface."}));continue}const re=Y1(z.query,l,"preserved");P.preservedFaces.push({query:re,status:"supported",note:"This face stays queryable through the hole rewrite."}),Sh(P,Q1("single",re,{source:z.query,note:"This hole descendant stays one defended face."}))}for(const z of ykt(g,T)){const H=fne(l,"hole",z);P.createdFaces.push({query:H,note:(()=>{switch(z){case"floor":return"Blind holes create a defended planar floor face.";case"counterbore-floor":return"Counterbored holes create a defended planar shoulder face.";case"counterbore-wall":return"Counterbored holes create a defended counterbore wall-face query.";case"countersink-wall":return"Countersunk holes create a defended countersink wall-face query.";default:return"Hole results create a defended wall-face query."}})()}),Sh(P,Q1("single",H,{note:"This hole-created face resolves to one defended descendant."}))}for(const z of bkt(g,T)){const H=oqe(l,"hole",z);P.createdEdges.push({query:H,note:Okt(z,g,T)}),Sh(P,aq("edge-chain",H,{note:"This hole-created edge query resolves to a defended descendant chain."}))}return P.diagnostics.push(lm("hole-source-face-split-ambiguous","ambiguous","face","Hole intent records which rewritten host/exit faces are ambiguous instead of silently accepting them.",f.workplane.source,Y1(f.workplane.source,l,"split"))),dqe(P,l,"hole",T),P}function jkt(l,o,f,g,T,P){const O=dI("cut",l),z=new Map($te(o,f.workplane.source,T).map(re=>[re.name,re.reason]));for(const re of dne(o)){const te=z.get(re.name);if(te){const Ee=Y1(re.query,l,"split");O.preservedFaces.push({query:Ee,status:"ambiguous",note:pqe("cut",te)}),Sh(O,Q1("face-region",Ee,{source:re.query,note:"This rewritten cut face remains a defended descendant region on the same source surface."}));continue}const W=Y1(re.query,l,"preserved");O.preservedFaces.push({query:W,status:"supported",note:"This face stays queryable through the cut rewrite."}),Sh(O,Q1("single",W,{source:re.query,note:"This cut descendant stays one defended face."}))}const H=vkt(g,T);for(const re of H){const te=fne(l,"cut",re);O.createdFaces.push({query:te,note:re==="floor"?"Blind cutouts create a defended planar floor face.":"This cut-created wall face is part of the defended named-face subset."}),Sh(O,Q1("single",te,{note:"This cut-created face resolves to one defended descendant."}))}for(const re of xkt(g,T)){const te=oqe(l,"cut",re);O.createdEdges.push({query:te,note:Mkt(re,T)}),Sh(O,aq("edge-chain",te,{note:"This cut-created edge query resolves to a defended descendant chain."}))}return O.diagnostics.push(lm("cut-source-face-split-ambiguous","ambiguous","face","Cut intent records which rewritten host/exit faces are ambiguous instead of silently accepting them.",f.workplane.source,Y1(f.workplane.source,l,"split"))),dqe(O,l,"cut",T),H.length===0&&O.diagnostics.push(lm("cut-created-face-subset-unsupported","unsupported","face","This cut profile does not fall inside the defended cut-created face subset yet.")),O}function mqe(l){const o=dI("hull",l);return o.diagnostics.push(lm("hull-face-propagation-unsupported","unsupported","face","Hull combines source solids through a full topology rewrite, so face-query propagation is not defended yet."),lm("hull-edge-propagation-unsupported","unsupported","edge","Hull combines source solids through a full topology rewrite, so edge-query propagation is not defended yet.")),o}function Dbe(l,o){const f=dI("trimByPlane",l);for(const T of dne(o)){const P=Y1(T.query,l,"split");f.preservedFaces.push({query:P,status:"ambiguous",note:"Trim keeps a clipped descendant region on the source surface instead of one untouched face."}),Sh(f,Q1("face-region",P,{source:T.query,note:"Trim keeps a defended descendant region on the source surface."}))}const g=fne(l,"trimByPlane","plane-cap");return f.createdFaces.push({query:g,note:"The kept side of the trim introduces one deterministic cap face on the trim plane."}),Sh(f,Q1("single",g,{note:"The trim plane cap resolves to one defended descendant face."})),f.diagnostics.push(lm("trim-by-plane-preserved-face-propagation-ambiguous","ambiguous","face","Trim-by-plane now exposes its created plane-cap face, but preserved non-cap face propagation is still ambiguous."),lm("trim-by-plane-edge-propagation-ambiguous","ambiguous","edge","Trim-by-plane boundary edge propagation is not defended yet.")),f}function Bkt(l,o,f,g=[]){const T=dI(l,o);for(const P of g){const O=tM(P,o,"preserved");T.preservedEdges.push({query:O,status:"supported",note:`${l} leaves this supported propagated vertical edge lineage unchanged in the defended post-rewrite subset.`}),Sh(T,aq("single",O,{source:P,note:`${l} keeps this edge as one defended single descendant.`}))}if(f){const P=tM(f,o,"merged");T.preservedEdges.push({query:P,status:"ambiguous",note:`${l} rewrites the selected edge into a blended descendant set rather than one defended edge target.`}),Sh(T,aq("edge-chain",P,{source:f,note:`${l} rewrites the selected edge into a defended descendant chain instead of one single edge target.`})),T.diagnostics.push(lm(`${l}-selected-edge-merged-ambiguous`,"ambiguous","edge",`${l} records that the selected edge is merged into rewritten descendants, but a durable post-rewrite edge target is not defended yet.`,f,P))}return T.diagnostics.push(lm(`${l}-created-face-propagation-unsupported`,"unsupported","face",`${l}-created face semantics are not part of the topology-rewrite kernel yet.`)),T}function zkt(l){return l.kind==="shell"||l.kind==="hole"||l.kind==="cut"||l.kind==="boolean"||l.kind==="hull"||l.kind==="trimByPlane"||l.kind==="fillet"||l.kind==="chamfer"}function Jkt(l,o){return{...l,queryPropagation:uC(o)}}function ixe(l,o){if(!l)return l;if(!zkt(l))throw new Error(`Cannot attach topology-rewrite propagation to non-rewrite plan kind "${l.kind}".`);return Jkt(l,o)}function hqe(l,o){return s6(l,o)}function qkt(l,o){return`pattern:${l}:${o}`}const sxe=Symbol.for("forgecad.shapeBackend");var qJe;qJe=sxe;const Om=class Om{constructor(o){tu(this,qJe,!0);this.manifold=o}clone(){return new Om(this.manifold)}translate(o,f,g){return new Om(this.manifold.translate(o,f,g))}rotate(o,f,g){return new Om(this.manifold.rotate(o,f,g))}transform(o){return new Om(this.manifold.transform(o))}scale(o){return new Om(this.manifold.scale(o))}mirror(o){return new Om(this.manifold.mirror(o))}smoothOut(o,f){return new Om(this.manifold.smoothOut(o,f))}refine(o){return new Om(this.manifold.refine(o))}refineToLength(o){return new Om(this.manifold.refineToLength(o))}refineToTolerance(o){return new Om(this.manifold.refineToTolerance(o))}warp(o){return new Om(this.manifold.warp(o))}split(o){const[f,g]=this.manifold.split(Gte(o,"ShapeBackend.split()"));return[new Om(f),new Om(g)]}splitByPlane(o,f){const[g,T]=this.manifold.splitByPlane(o,f);return[new Om(g),new Om(T)]}trimByPlane(o,f){return new Om(this.manifold.trimByPlane(o,f))}hull(){return new Om(this.manifold.hull())}simplify(o){return new Om(this.manifold.simplify(o))}boundingBox(){return this.manifold.boundingBox()}volume(){return this.manifold.volume()}surfaceArea(){return this.manifold.surfaceArea()}minGap(o,f){return this.manifold.minGap(Gte(o,"ShapeBackend.minGap()"),f)}isEmpty(){return this.manifold.isEmpty()}numTri(){return this.manifold.numTri()}getMesh(){return this.manifold.getMesh()}slice(o){return this.manifold.slice(o)}project(){return this.manifold.project()}requireManifold(){return this.manifold}};let Hte=Om;function Wkt(l){return!!(l&&typeof l=="object"&&l[sxe]===!0)}function gqe(l){return new Hte(l)}function Gte(l,o="requireManifoldShapeBackend()"){try{return l.requireManifold(o)}catch(f){const g=f instanceof Error?f.message:String(f);throw new Error(`${o} currently requires a Manifold-backed runtime shape. ${g}`)}}function Abe(l){switch(l.kind){case"through":case"blind":return{kind:l.kind,depth:l.depth};case"upToFace":return{kind:"upToFace",depth:l.depth,face:iu(l.face)}}}function yqe(l){return l.kind==="two-sided"?{kind:"two-sided",forward:Abe(l.forward),reverse:Abe(l.reverse)}:Abe(l)}function fx(l){return Number.isFinite(l)&&l>0}function vqe(l){return Math.max(.01,Math.min(.25,l*.01))}function $J(l,o){return G1(l,{kind:"translate",x:0,y:0,z:o})}function bqe(l,o){const f=G1(l,{kind:"workplanePlacement",matrix:o.matrix,placement:o.placement});return f?{ok:!0,plan:f}:{ok:!1,reason:"Hole/cut features could not apply the selected workplane placement."}}function Vkt(l,o,f,g){const T=Rm(f),P=mq(f);if(!fx(P))return{ok:!1,reason:"Hole/cut features require a positive finite depth."};const O=vqe(P),z=P+O*2,H=(()=>{switch(l.kind){case"cylinder":return{kind:"cylinder",height:z,radius:l.radius,center:!1};case"extrude":if(g&&(!fx(g.scale[0])||!fx(g.scale[1])))return null;const te=Fd(l.profile);if(!te)return null;const W=g?Db(te,{kind:"scale",x:g.scale[0],y:g.scale[1]}):te;return W?{kind:"extrude",profile:W,height:z,center:!1,scaleTop:g?[1/g.scale[0],1/g.scale[1]]:void 0}:null;default:return null}})();if(!H)return{ok:!1,reason:"Hole/cut feature lowerer expected an analytic cylinder or extruded profile cutter."};const re=$J(H,-(T.depth+O+o.placement.protrude));return re?bqe(re,o):{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."}}function Ukt(l,o,f){if(!fx(l.radius))return{ok:!1,reason:"Shape.hole() requires a positive finite diameter."};const g=Rm(f),T=mq(f);if(!fx(T))return{ok:!1,reason:"Hole/cut features require a positive finite depth."};const P=vqe(T),O=[],z=$J({kind:"cylinder",height:T+P*2,radius:l.radius,center:!1},-(g.depth+P+o.placement.protrude));if(!z)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};if(O.push(z),l.counterbore){if(!fx(l.counterbore.radius)||!fx(l.counterbore.depth))return{ok:!1,reason:"Shape.hole() counterbores require positive finite diameter and depth."};const re=$J({kind:"cylinder",height:l.counterbore.depth+P,radius:l.counterbore.radius,center:!1},-(l.counterbore.depth+o.placement.protrude));if(!re)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};O.push(re)}if(l.countersink){if(!fx(l.countersink.radius)||!fx(l.countersink.depth))return{ok:!1,reason:"Shape.hole() countersinks require positive finite diameter and depth."};const re=$J({kind:"cylinder",height:l.countersink.depth,radius:l.radius,radiusTop:l.countersink.radius,center:!1},-(l.countersink.depth+o.placement.protrude));if(!re)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};const te=$J({kind:"cylinder",height:P,radius:l.countersink.radius,center:!1},-o.placement.protrude);if(!te)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};O.push(re,te)}const H=O.length===1?O[0]:Ry("union",O);return H?bqe(H,o):{ok:!1,reason:"Hole/cut features could not combine the selected cutter components."}}function $kt(l,o,f,g){return!l||!o||!f||!fx(f.radius)||!fx(mq(g))?null:{kind:"hole",base:m_(l),placement:rT(o),hole:{radius:f.radius,counterbore:f.counterbore?{radius:f.counterbore.radius,depth:f.counterbore.depth}:void 0,countersink:f.countersink?{radius:f.countersink.radius,angleDeg:f.countersink.angleDeg,depth:f.countersink.depth}:void 0},extent:yqe(g)}}function Hkt(l,o,f,g,T){return!l||!o||!f||!fx(mq(g))?null:{kind:"cut",base:m_(l),placement:rT(o),profile:Fd(f),extent:yqe(g),taper:T?{scale:[T.scale[0],T.scale[1]]}:void 0}}function Gkt(l){const o=Ukt(l.hole,l.placement,l.extent);return o.ok?{ok:!0,plan:Ry("difference",[l.base,o.plan])}:o}function Xkt(l){const o=Vkt({kind:"extrude",profile:l.profile,height:mq(l.extent)},l.placement,l.extent,l.taper);return o.ok?{ok:!0,plan:Ry("difference",[l.base,o.plan])}:o}function xqe(l){const o=[];for(const f of l??[]){if(f!=="top"&&f!=="bottom")throw new Error(`Shape.shell() only supports "top" and "bottom" openings, got "${f}"`);o.includes(f)||o.push(f)}return o}function Ykt(l){return l.kind!=="scale"}function axe(l,o,f,g){const T=g.includes("top"),P=g.includes("bottom"),O=o?-l/2+(P?0:f):P?0:f,z=o?l/2-(T?0:f):l-(T?0:f),H=z-O;return H>0?{height:H,translateZ:o?(O+z)/2:O}:null}function Sqe(l,o){return Math.abs(o)<=1e-12?l:G1(l,{kind:"translate",x:0,y:0,z:o})}function Qkt(l,o,f,g){let T=l;return(Math.abs(o)>1e-12||Math.abs(f)>1e-12||Math.abs(g)>1e-12)&&(T=G1(T,{kind:"translate",x:o,y:f,z:g})),T}function Zkt(l,o,f){const g=l.x-2*o,T=l.y-2*o;if(!(g>0)||!(T>0))return{ok:!1,reason:"Shape.shell() thickness is too large for this box base."};const P=axe(l.z,l.center,o,f);if(!P)return{ok:!1,reason:"Shape.shell() thickness is too large for this box height and opening configuration."};const O=Qkt({kind:"box",x:g,y:T,z:P.height,center:l.center},l.center?0:o,l.center?0:o,P.translateZ);return{ok:!0,plan:Ry("difference",[l,O])}}function Kkt(l,o,f){const g=l.radius-o,T=l.radiusTop==null?void 0:l.radiusTop-o;if(!(g>0)||T!=null&&!(T>0))return{ok:!1,reason:"Shape.shell() thickness is too large for this cylinder or cone base."};const P=axe(l.height,l.center,o,f);if(!P)return{ok:!1,reason:"Shape.shell() thickness is too large for this cylinder height and opening configuration."};const O=Sqe({kind:"cylinder",height:P.height,radius:g,radiusTop:T,center:l.center},P.translateZ);return{ok:!0,plan:Ry("difference",[l,O])}}function eCt(l,o,f){if(l.scaleTop)return{ok:!1,reason:"Shape.shell() v1 does not support tapered extrudes (`scaleTop`) yet."};const g=rqe(l.profile,-o,"Round");if(!g)return{ok:!1,reason:"Shape.shell() could not offset the source profile for this extrude base."};const T=axe(l.height,l.center,o,f);if(!T)return{ok:!1,reason:"Shape.shell() thickness is too large for this extrude height and opening configuration."};const P=Sqe({kind:"extrude",profile:g,height:T.height,center:l.center},T.translateZ);return{ok:!0,plan:Ry("difference",[l,P])}}function p2e(l,o,f){switch(l.kind){case"queryOwner":{const g=p2e(l.base,o,f);return g.ok?{ok:!0,plan:hq(g.plan,l.owner)}:g}case"transform":{if(!l.steps.every(Ykt))return{ok:!1,reason:"Shape.shell() v1 supports only rigid transforms before shelling. Scale transforms are not supported yet."};const g=p2e(l.base,o,f);return g.ok?{ok:!0,plan:m_({kind:"transform",base:g.plan,steps:l.steps.map(T=>({...T}))})}:g}case"box":return Zkt(l,o,f);case"cylinder":return Kkt(l,o,f);case"extrude":return eCt(l,o,f);case"shell":return{ok:!1,reason:"Shape.shell() v1 does not support shelling an already-shelled result yet."};case"fillet":case"chamfer":return{ok:!1,reason:"Shape.shell() v1 does not support edge-finished bodies yet."};case"sphere":case"sheetMetal":case"hole":case"cut":case"revolve":case"loft":case"sweep":case"boolean":case"hull":case"trimByPlane":return{ok:!1,reason:"Shape.shell() v1 currently supports compile-covered box(), cylinder(), and straight extrude() bases with optional top/bottom openings."}}}function tCt(l,o,f=[]){if(!l||!Number.isFinite(o)||!(o>0))return null;const g={kind:"shell",base:m_(l),thickness:o,openFaces:xqe(f)};return Tqe(g).ok?g:null}function Tqe(l){return!Number.isFinite(l.thickness)||!(l.thickness>0)?{ok:!1,reason:"Shape.shell() requires a positive finite wall thickness."}:p2e(l.base,l.thickness,xqe(l.openFaces))}function nCt(l,o,f){return Math.max(o,Math.min(f,l))}function pze(l,o){return[l[0]-o[0],l[1]-o[1],l[2]-o[2]]}function rCt(l,o){return[l[0]*o,l[1]*o,l[2]*o]}function QJ(l,o){return l[0]*o[0]+l[1]*o[1]+l[2]*o[2]}function Nbe(l,o){return[l[1]*o[2]-l[2]*o[1],l[2]*o[0]-l[0]*o[2],l[0]*o[1]-l[1]*o[0]]}function oxe(l){return Math.sqrt(QJ(l,l))}function Gee(l){const o=oxe(l);return o<1e-9?[0,0,1]:[l[0]/o,l[1]/o,l[2]/o]}function iCt(l){let o=0;for(let f=0;f<l.length;f+=1){const[g,T]=l[f],[P,O]=l[(f+1)%l.length];o+=g*O-P*T}return o*.5}function sCt(l,o){let f=!1;const[g,T]=l;for(let P=0,O=o.length-1;P<o.length;O=P,P+=1){const[z,H]=o[P],[re,te]=o[O];H>T!=te>T&&g<(re-z)*(T-H)/(te-H+1e-20)+z&&(f=!f)}return f}function aCt(l,o,f){const g=f[0]-o[0],T=f[1]-o[1],P=l[0]-o[0],O=l[1]-o[1],z=g*g+T*T,H=z<1e-12?0:nCt((P*g+O*T)/z,0,1),re=o[0]+g*H,te=o[1]+T*H,W=l[0]-re,Ee=l[1]-te;return Math.sqrt(W*W+Ee*Ee)}function oCt(l,o){let f=1/0;for(let g=0;g<o.length;g+=1){const T=o[g],P=o[(g+1)%o.length];f=Math.min(f,aCt(l,T,P))}return sCt(l,o)?f:-f}function kqe(l){const o=l.filter(f=>Array.isArray(f)&&f.length>=3).map(f=>({pts:f.map(([g,T])=>[g,T]),area:iCt(f)}));return o.length===0?()=>-1:(f,g)=>{const T=[f,g];let P=-1/0;for(const O of o){const z=oCt(T,O.pts);P=O.area>=0?Math.max(P,z):Math.min(P,-z)}return P}}function cCt(l,o){let f=Gee(o);Math.abs(QJ(f,l))>.95&&(f=Math.abs(l[2])<.95?[0,0,1]:[0,1,0]);let g=Gee(Nbe(f,l));if(oxe(g)<1e-8){const P=Math.abs(l[0])<.9?[1,0,0]:[0,1,0];g=Gee(Nbe(P,l))}const T=Gee(Nbe(l,g));return{x:g,y:T}}function Cqe(l,o,f){if(l.length<2)throw new Error("loft requires at least two compileable profiles");if(l.length!==o.length)throw new Error("loft compile data requires heights.length === profiles.length");const g=l.map(Ee=>kqe(Ee)),T=o.map(Ee=>Ee);let P=1/0,O=1/0,z=-1/0,H=-1/0;for(const Ee of l)for(const se of Ee)for(const[me,Xe]of se)P=Math.min(P,me),O=Math.min(O,Xe),z=Math.max(z,me),H=Math.max(H,Xe);const re=T[0],te=T[T.length-1],W=f.boundsPadding;return{sdf:([Ee,se,me])=>{let Xe;if(me<=re)Xe=g[0](Ee,se);else if(me>=te)Xe=g[g.length-1](Ee,se);else{let at=0;for(;at+1<T.length&&me>T[at+1];)at+=1;const It=T[at],tn=T[at+1],At=(me-It)/(tn-It),mt=g[at](Ee,se),ht=g[at+1](Ee,se);Xe=mt*(1-At)+ht*At}const it=Math.min(me-re,te-me);return Math.min(Xe,it)},bounds:{min:[P-W,O-W,re-W],max:[z+W,H+W,te+W]},edgeLength:f.edgeLength}}function wqe(l,o,f){if(o.length<2)throw new Error("sweep requires a path with at least two points");const g=kqe(l),T=[];for(let se=0;se<o.length-1;se+=1){const me=o[se],Xe=o[se+1],it=pze(Xe,me),at=oxe(it);if(at<1e-6)continue;const It=rCt(it,1/at),tn=cCt(It,f.up);T.push({a:me,t:It,x:tn.x,y:tn.y,len:at})}if(T.length===0)throw new Error("sweep path has no non-zero segments");let P=0;for(const se of l)for(const[me,Xe]of se)P=Math.max(P,Math.abs(me),Math.abs(Xe));let O=1/0,z=1/0,H=1/0,re=-1/0,te=-1/0,W=-1/0;for(const[se,me,Xe]of o)O=Math.min(O,se),z=Math.min(z,me),H=Math.min(H,Xe),re=Math.max(re,se),te=Math.max(te,me),W=Math.max(W,Xe);const Ee=Math.max(f.boundsPadding,P);return{sdf:se=>{let me=-1/0;for(const Xe of T){const it=pze(se,Xe.a),at=QJ(it,Xe.t),It=QJ(it,Xe.x),tn=QJ(it,Xe.y),At=g(It,tn),mt=Math.min(at,Xe.len-at);me=Math.max(me,Math.min(At,mt))}return me},bounds:{min:[O-Ee,z-Ee,H-Ee],max:[re+Ee,te+Ee,W+Ee]},edgeLength:f.edgeLength}}function lCt(l,o){if(l.length<2)return l;if(o<=0)return[];const f=[0];for(let P=0;P<l.length;P++){const O=l[P],z=l[(P+1)%l.length],H=z[0]-O[0],re=z[1]-O[1],te=Math.sqrt(H*H+re*re);f.push(f[f.length-1]+te)}const g=f[f.length-1];if(g<1e-12)return Array.from({length:o},()=>[l[0][0],l[0][1]]);const T=[];for(let P=0;P<o;P++){const O=P/o*g;let z=0,H=f.length-1;for(;z<H;){const se=z+H>>1;f[se]<=O?z=se+1:H=se}const re=z-1,te=(O-f[re])/(f[re+1]-f[re]),W=l[re%l.length],Ee=l[(re+1)%l.length];T.push([W[0]+(Ee[0]-W[0])*te,W[1]+(Ee[1]-W[1])*te])}return T}function uCt(l,o,f){if(l.length<2)return null;const g=l[0].length;if(g===0)return null;for(let O=1;O<l.length;O++)if(l[O].length!==g)return null;const T=[];for(let O=0;O<g;O++){const z=fCt(l.map(H=>H[O]),o,f);if(z)T.push(z);else{for(const H of T)H.delete();return null}}if(T.length===0)return null;if(T.length===1)return T[0];const P=f.Manifold.union(T);for(const O of T)O.delete();return P}function _Ct(l){let o=0;for(let f=0;f<l.length;f++){const g=l[f],T=l[(f+1)%l.length];o+=g[0]*T[1]-T[0]*g[1]}return o*.5}function fCt(l,o,f){const g=l.map(Xe=>_Ct(Xe)<0?[...Xe].reverse():Xe);let T=0;for(const Xe of g)T=Math.max(T,Xe.length);const P=Math.max(T,24),O=g.map((Xe,it)=>{const at=lCt(Xe,P),It=o[it];return at.map(([tn,At])=>[tn,At,It])}),z=[],H=[];for(const Xe of O)for(const[it,at,It]of Xe)z.push(it,at,It);for(let Xe=0;Xe<O.length-1;Xe++){const it=Xe*P,at=(Xe+1)*P;for(let It=0;It<P;It++){const tn=(It+1)%P,At=it+It,mt=at+It,ht=at+tn,xn=it+tn;H.push(At,xn,ht),H.push(At,ht,mt)}}const re=O[0].map(([Xe,it])=>[Xe,it]),te=f.triangulate([re]);for(const Xe of te){const[it,at,It]=Array.isArray(Xe)?Xe:[Xe[0],Xe[1],Xe[2]];H.push(it,It,at)}const W=O[O.length-1].map(([Xe,it])=>[Xe,it]),Ee=f.triangulate([W]),se=(O.length-1)*P;for(const Xe of Ee){const[it,at,It]=Array.isArray(Xe)?Xe:[Xe[0],Xe[1],Xe[2]];H.push(se+it,se+at,se+It)}const me=new f.Mesh({numProp:3,vertProperties:new Float32Array(z),triVerts:new Uint32Array(H)});try{return new f.Manifold(me)}catch{return null}}const d2e=1e-8;function Eqe(l){return Math.hypot(l[0],l[1],l[2])}function Pqe(l){const o=Eqe(l);if(o<d2e)throw new Error("Plane normal must be non-zero");return[l[0]/o,l[1]/o,l[2]/o]}function pCt(l){if("origin"in l)return{origin:[l.origin[0],l.origin[1],l.origin[2]],normal:Pqe(l.normal)};const o=l.offset??0;return l.plane==="XY"?{origin:[0,0,o],normal:[0,0,1]}:l.plane==="XZ"?{origin:[0,o,0],normal:[0,1,0]}:{origin:[o,0,0],normal:[1,0,0]}}function Dqe(l){const o=Pqe(l),f=o[2];if(f>1-d2e)return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];let g,T;if(f<-1+d2e)g=[1,0,0],T=Math.PI;else{g=[o[1],-o[0],0];const At=Eqe(g);g=[g[0]/At,g[1]/At,g[2]/At],T=Math.acos(f)}const[P,O,z]=g,H=Math.cos(T),re=Math.sin(T),te=1-H,W=H+P*P*te,Ee=P*O*te-z*re,se=P*z*te+O*re,me=O*P*te+z*re,Xe=H+O*O*te,it=O*z*te-P*re,at=z*P*te-O*re,It=z*O*te+P*re,tn=H+z*z*te;return[W,me,at,0,Ee,Xe,It,0,se,it,tn,0,0,0,0,1]}function Aqe(l){const{origin:o,normal:f}=pCt(l),g=Ea.from(Dqe(f)).inverse();return{origin:o,u:g.vector([1,0,0]),v:g.vector([0,1,0]),normal:f}}function Nqe(l){const o=Dqe(l.normal);return Ea.translation(-l.origin[0],-l.origin[1],-l.origin[2]).mul(o).toArray()}const cxe=1e-8,Iqe=["vert-bl","vert-br","vert-tr","vert-tl"];function dCt(l,o){return[(l[0]+o[0])*.5,(l[1]+o[1])*.5,(l[2]+o[2])*.5]}function ZJ(l){const o=Math.hypot(l[0],l[1],l[2]);if(o<=cxe)throw new Error("Edge feature selection requires a non-zero direction vector");return[l[0]/o,l[1]/o,l[2]/o]}function mCt(l,o){return[l[0]-o[0],l[1]-o[1],l[2]-o[2]]}function Ap(l,o){return{ok:!1,issue:{code:l,reason:o}}}function gq(l,o){return{ok:!0,selection:l,query:wl(o)}}function hCt(l){return Iqe.includes(l)}function lxe(l){switch(l.kind){case"boolean":return`boolean ${l.op}`;case"trimByPlane":return"trimByPlane";default:return l.kind}}function Xee(l,o){return{base:l.base,steps:[...l.steps,o]}}function gCt(l){switch(l.kind){case"shell":return"Edge finishing does not yet defend durable edge queries through shell rewrites.";case"hole":return"Edge finishing does not yet defend durable edge queries through hole rewrites.";case"cut":return"Edge finishing does not yet defend durable edge queries through cut rewrites.";case"boolean":return`Edge finishing only accepts propagated edge queries that ${lxe(l)} already recorded as supported.`;case"hull":return"Edge finishing does not yet defend durable edge queries through hull rewrites.";case"trimByPlane":return"Edge finishing does not yet defend durable edge queries through trimByPlane rewrites.";case"fillet":case"chamfer":return`Edge finishing only accepts preserved propagated edge queries after earlier ${l.kind} rewrites.`}}function dze(l,o,f){var z;const g=((z=l.queryPropagation)==null?void 0:z.diagnostics.filter(H=>H.queryKind==="edge"))??[],T=g.find(H=>gC(H.source,o)&&(f==null||gC(H.query,f)));if(T!=null&&T.message)return T.message;const P=g.find(H=>gC(H.source,o));if(P!=null&&P.message)return P.message;const O=g.find(H=>H.source==null&&H.query==null);return(O==null?void 0:O.message)??null}function Fqe(l,o){var f;if(o)return(f=l.queryPropagation)==null?void 0:f.descendants.find(g=>g.queryKind==="edge"&&gC(g.query,o))}function yCt(l){switch(l.kind){case"translate":return Ea.translation(l.x,l.y,l.z);case"rotate":return Ea.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg);case"rotateAround":return Ea.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]);case"mirror":{const[o,f,g]=[l.normalX,l.normalY,l.normalZ],T=Math.hypot(o,f,g);if(T<=cxe)return Ea.identity();const P=o/T,O=f/T,z=g/T;return Ea.from([1-2*P*P,-2*O*P,-2*z*P,0,-2*P*O,1-2*O*O,-2*z*O,0,-2*P*z,-2*O*z,1-2*z*z,0,0,0,0,1])}case"workplanePlacement":return Ea.from(l.matrix);case"scale":return null}}function Oqe(l,o){let f=l;for(const g of o){const T=yCt(g);if(!T)return{issue:{code:"unsupported-edge-transform",reason:"Edge finishing currently supports only rigid transforms between the tracked source edge and the target body."}};f=f.mul(T)}return{transform:f}}function zO(l,o){var f,g;if(!l)return{issue:{code:"edge-owner-not-found",reason:"The selected tracked edge is not owned by this target shape or any preserved query ancestor."}};switch(l.kind){case"queryOwner":return Pb(l.owner,o)?{match:{base:l.base,steps:[]}}:zO(l.base,o);case"transform":{const T=zO(l.base,o);return T.match?{match:Xee(T.match,{kind:"transform",steps:l.steps})}:T}case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":{const T=zO(l.base,o);return T.match?{match:Xee(T.match,{kind:"rewrite",plan:l})}:T}case"boolean":{for(const T of l.shapes){const P=zO(T,o);if(P.match)return{match:Xee(P.match,{kind:"rewrite",plan:l})};if(((f=P.issue)==null?void 0:f.code)==="unsupported-edge-transform")return P}return{issue:{code:"edge-owner-not-found",reason:"The selected tracked edge is not owned by this target shape or any preserved query ancestor."}}}case"hull":{for(const T of l.shapes){const P=zO(T,o);if(P.match)return{match:Xee(P.match,{kind:"rewrite",plan:l})};if(((g=P.issue)==null?void 0:g.code)==="unsupported-edge-transform")return P}return{issue:{code:"edge-owner-not-found",reason:"The selected tracked edge is not owned by this target shape or any preserved query ancestor."}}}case"box":case"cylinder":case"sphere":case"extrude":case"sheetMetal":case"revolve":case"loft":case"sweep":return{issue:{code:"edge-owner-not-found",reason:"The selected tracked edge is not owned by this target shape or any preserved query ancestor."}}}}function Mqe(l,o){const f=Oqe(Ea.identity(),o);return f.transform?gq(Bqe(l.selection,f.transform),l.query):Ap(f.issue.code,f.issue.reason)}function vCt(l,o){switch(o.kind){case"tracked-edge":return bCt(l,o);case"propagated-edge":return xCt(l,o);case"created-edge":return Ap("unsupported-edge-query-kind","Edge finishing does not yet support created-edge queries from topology rewrites.");case"edge-ref":return Ap("unsupported-edge-query-kind","Edge finishing v1 supports tracked/propagated compiler-owned edge queries only, not direct edge refs.")}}function bCt(l,o){const f=m2e(l,o.edgeName);return f.ok?gq(f.selection,o):f}function Lqe(l,o){switch(l.kind){case"fillet":case"chamfer":case"shell":case"hole":case"cut":case"trimByPlane":return lI(l.base,o);case"boolean":case"hull":{let f=null;for(const g of l.shapes){const T=lI(g,o);if(T.ok)return T;T.issue.code!=="edge-owner-not-found"&&T.issue.code!=="edge-query-propagation-mismatch"&&(f??(f=T.issue))}return f?Ap(f.code,f.reason):Ap("edge-query-propagation-mismatch","The selected propagated edge query does not match the target shape's recorded rewrite propagation contract.")}}}function Rqe(l,o){var g;const f=(g=l.queryPropagation)==null?void 0:g.preservedEdges.find(T=>gC(T.query.source,o.query));return f?f.status!=="supported"||f.query.outcome!=="preserved"?Ap("edge-query-ambiguous-after-rewrite",dze(l,o.query,f.query)??f.note??`The selected edge query is recorded as ${f.status} after ${lxe(l)} and does not resolve to one defended edge target.`):gq(o.selection,f.query):Ap("edge-query-unsupported-after-rewrite",dze(l,o.query)??gCt(l))}function xCt(l,o){if(l.kind==="box"||l.kind==="cylinder"||l.kind==="sphere"||l.kind==="extrude"||l.kind==="sheetMetal"||l.kind==="revolve"||l.kind==="loft"||l.kind==="sweep"||l.kind==="transform"||l.kind==="queryOwner")return Ap("edge-query-propagation-mismatch","The selected propagated edge query does not point at a topology-rewrite result on this target shape.");const f=l.queryPropagation;if(!f||f.rewriteId!==o.rewriteId)return Ap("edge-query-propagation-mismatch","The selected propagated edge query does not match the target shape's recorded rewrite propagation contract.");if(!f.preservedEdges.find(O=>gC(O.query,o)))return Ap("edge-query-propagation-mismatch",`The selected propagated edge query is not part of the recorded ${lxe(l)} propagation subset for this target shape.`);const T=Lqe(l,o.source);if(!T.ok)return T;const P=Rqe(l,{selection:T.selection,query:T.query});return P.ok?gC(P.query,o)?P:Ap("edge-query-propagation-mismatch","The selected propagated edge query does not match the target shape's recorded rewrite propagation contract."):P}function SCt(l,o){let f=gq(l.selection,l.query);for(const g of o){if(!f.ok)return f;f=g.kind==="transform"?Mqe({selection:f.selection,query:f.query},g.steps):Rqe(g.plan,{selection:f.selection,query:f.query})}return f}function jqe(l){if(!l)return null;switch(l.kind){case"tracked-edge":return l.selector!=="edge"||!l.owner||!hCt(l.edgeName)?null:{owner:Sp(l.owner),edgeName:l.edgeName};case"propagated-edge":return jqe(l.source);case"created-edge":case"edge-ref":return null}}function TCt(l,o){const f=l.center?-l.x/2:0,g=l.center?-l.y/2:0,T=l.center?-l.z/2:0,P=f+l.x,O=g+l.y,z=T+l.z,H=(()=>{switch(o){case"vert-bl":return{point:[f,g,T],quadrant:[1,-1]};case"vert-br":return{point:[P,g,T],quadrant:[-1,-1]};case"vert-tr":return{point:[P,O,T],quadrant:[-1,1]};case"vert-tl":return{point:[f,O,T],quadrant:[1,1]};default:return null}})();return H?{ok:!0,selection:{kind:"line-segment",edgeName:o,start:[H.point[0],H.point[1],T],end:[H.point[0],H.point[1],z],midpoint:[H.point[0],H.point[1],(T+z)*.5],axis:[0,0,1],basisX:[1,0,0],basisY:[0,-1,0],quadrant:H.quadrant}}:Ap("unsupported-edge-name",`Edge finishing v1 currently supports only tracked vertical rectangle/box edges (${["vert-bl","vert-br","vert-tr","vert-tl"].join(", ")}).`)}function kCt(l){if(l.length!==4)return!1;const o=l.map((re,te)=>{const W=l[(te+1)%l.length];return[W[0]-re[0],W[1]-re[1]]}),f=o.map(([re,te])=>Math.hypot(re,te));if(f.some(re=>re<=cxe))return!1;const g=o[0][0]*o[1][0]+o[0][1]*o[1][1],T=o[1][0]*o[2][0]+o[1][1]*o[2][1],P=o[2][0]*o[3][0]+o[2][1]*o[3][1],O=o[3][0]*o[0][0]+o[3][1]*o[0][1],z=o[0][0]*o[2][1]-o[0][1]*o[2][0],H=o[1][0]*o[3][1]-o[1][1]*o[3][0];return Math.abs(g)<=1e-6*Math.max(1,f[0]*f[1])&&Math.abs(T)<=1e-6*Math.max(1,f[1]*f[2])&&Math.abs(P)<=1e-6*Math.max(1,f[2]*f[3])&&Math.abs(O)<=1e-6*Math.max(1,f[3]*f[0])&&Math.abs(z)<=1e-6*Math.max(1,f[0]*f[2])&&Math.abs(H)<=1e-6*Math.max(1,f[1]*f[3])}function CCt(l,o){if(l.scaleTop)return Ap("unsupported-edge-base","Edge finishing v1 does not support tapered extrudes (`scaleTop`) yet.");if(l.center)return Ap("unsupported-edge-base","Edge finishing v1 currently supports tracked rectangle extrusions in their normal upward form; centered sketch extrudes are not tracked in the supported subset.");if(l.profile.kind!=="polygon"||!kCt(l.profile.points))return Ap("unsupported-edge-profile","Edge finishing v1 currently supports tracked rectangle extrusions only; generic sketch extrudes are outside the supported subset.");const f=(()=>{switch(o){case"vert-bl":return 0;case"vert-br":return 1;case"vert-tr":return 2;case"vert-tl":return 3;default:return-1}})();if(f<0)return Ap("unsupported-edge-name",`Edge finishing v1 currently supports only tracked vertical rectangle/box edges (${["vert-bl","vert-br","vert-tr","vert-tl"].join(", ")}).`);const g=l.profile.points,[T,P,O,z]=g,H=ZJ([P[0]-T[0],P[1]-T[1],0]),re=ZJ([z[0]-T[0],z[1]-T[1],0]),te=g[f],W=f===0?[1,-1]:f===1?[-1,-1]:f===2?[-1,1]:[1,1];return{ok:!0,selection:{kind:"line-segment",edgeName:o,start:[te[0],te[1],0],end:[te[0],te[1],l.height],midpoint:[te[0],te[1],l.height*.5],axis:[0,0,1],basisX:[H[0],H[1],H[2]],basisY:[-re[0],-re[1],-re[2]],quadrant:W}}}function Bqe(l,o){const f=o.point(l.start),g=o.point(l.end),T=ZJ(o.vector(l.basisX)),P=ZJ(o.vector(l.basisY)),O=ZJ(mCt(g,f));return{kind:"line-segment",edgeName:l.edgeName,start:f,end:g,midpoint:dCt(f,g),axis:O,basisX:T,basisY:P,quadrant:[l.quadrant[0],l.quadrant[1]]}}function m2e(l,o){switch(l.kind){case"transform":{const f=m2e(l.base,o);if(!f.ok)return f;const g=Oqe(Ea.identity(),l.steps);return g.transform?{ok:!0,selection:Bqe(f.selection,g.transform)}:Ap(g.issue.code,g.issue.reason)}case"box":return TCt(l,o);case"extrude":return CCt(l,o);case"queryOwner":return m2e(l.base,o);case"fillet":case"chamfer":case"shell":case"hole":case"cut":case"boolean":case"cylinder":case"sphere":case"sheetMetal":case"revolve":case"loft":case"sweep":case"hull":case"trimByPlane":return Ap("unsupported-edge-base","Edge finishing v1 currently supports tracked vertical edges from compile-covered box() bodies and rectangle extrusions before topology-changing edits.")}}function lI(l,o){const f=PCt(l,o);return f.kind==="single"?gq(f.selection,f.query):f.kind==="edge-chain"?Ap("edge-query-ambiguous-after-rewrite",f.note??"The selected edge resolves to a defended descendant chain, not one single edge target."):f.query==null&&o==null?Ap("missing-edge-query",f.reason):f.query==null&&(o!=null&&o.selector)&&o.selector!=="edge"||f.reason.includes("selector")?Ap("unsupported-edge-selector",f.reason):f.reason.includes("owner")?Ap("edge-owner-not-found",f.reason):Ap("edge-query-unsupported-after-rewrite",f.reason)}function wCt(l,o){if(l.kind==="box"||l.kind==="cylinder"||l.kind==="sphere"||l.kind==="extrude"||l.kind==="sheetMetal"||l.kind==="revolve"||l.kind==="loft"||l.kind==="sweep"||l.kind==="transform"||l.kind==="queryOwner")return{kind:"unsupported",query:wl(o),reason:"The selected propagated edge query does not point at a topology-rewrite result on this target shape."};const f=Fqe(l,o);if(!f||f.kind!=="edge-chain")return{kind:"unsupported",query:wl(o),reason:"This target shape does not record a defended descendant edge chain for the selected query."};const g=Lqe(l,o.source);return g.ok?{kind:"edge-chain",semantic:"chain",query:wl(o),selection:g.selection,note:f.note}:{kind:"unsupported",query:wl(o),reason:g.issue.reason,note:f.note}}function ECt(l,o){if(l.kind==="box"||l.kind==="cylinder"||l.kind==="sphere"||l.kind==="extrude"||l.kind==="sheetMetal"||l.kind==="revolve"||l.kind==="loft"||l.kind==="sweep"||l.kind==="transform"||l.kind==="queryOwner")return{kind:"unsupported",query:wl(o),reason:"The selected created-edge query does not point at a topology-rewrite result on this target shape."};const f=Fqe(l,o);return!f||f.kind!=="edge-chain"?{kind:"unsupported",query:wl(o),reason:"This target shape does not record a defended descendant edge chain for the selected created-edge query."}:{kind:"edge-chain",semantic:"chain",query:wl(o),note:f.note}}function PCt(l,o){var T;if(!o)return{kind:"unsupported",reason:"Edge finishing currently requires a tracked edge query from a compile-covered target body."};if(o.selector!=="edge")return{kind:"unsupported",query:wl(o),reason:"Edge finishing v1 currently supports whole-edge selections only; use shape.edge(name), not .start/.end/.midpoint selectors."};if(o.kind==="edge-ref")return{kind:"unsupported",query:wl(o),reason:"Edge finishing v1 supports compiler-owned tracked-edge, propagated-edge, and inspectable created-edge queries only, not direct edge refs."};if(!o.owner)return{kind:"unsupported",query:wl(o),reason:"Edge finishing currently requires a tracked edge query with a compiler-owned parent body owner."};const f=zO(l,o.owner);if(!f.match)return{kind:"unsupported",query:wl(o),reason:((T=f.issue)==null?void 0:T.reason)??"The selected tracked edge is not owned by this target shape or any preserved query ancestor."};if(o.kind==="created-edge"){const P=ECt(f.match.base,o);if(P.kind==="unsupported")return P;for(const O of f.match.steps)if(O.kind==="rewrite")return{kind:"unsupported",query:wl(o),reason:"Later topology rewrites do not yet preserve this defended created-edge chain as a new downstream chain contract.",note:P.note};return P}const g=vCt(f.match.base,o);if(g.ok){const P=SCt({selection:g.selection,query:g.query},f.match.steps);return P.ok?{kind:"single",semantic:"edge",query:P.query,selection:P.selection}:{kind:"unsupported",query:wl(o),reason:P.issue.reason}}if(o.kind==="propagated-edge"){const P=wCt(f.match.base,o);if(P.kind!=="unsupported"){let O=P;for(const z of f.match.steps){if(z.kind==="transform"){if(!O.selection)continue;const H=Mqe({selection:O.selection,query:O.query},z.steps);if(!H.ok)return{kind:"unsupported",query:wl(o),reason:H.issue.reason,note:O.note};O={...O,selection:H.selection,query:H.query};continue}return{kind:"unsupported",query:wl(o),reason:"Later topology rewrites do not yet preserve this defended edge chain as a new downstream chain contract.",note:O.note}}return O}}return{kind:"unsupported",query:wl(o),reason:g.issue.reason}}function zqe(l,o){if(!l)return[];const f=jqe(o);if(!f)return[];const g=[];for(const T of Iqe){if(T===f.edgeName)continue;const P={kind:"tracked-edge",edgeName:T,selector:"edge",owner:Sp(f.owner)},O=lI(l,P);O.ok&&g.push(O.query)}return g}const Xte=.01;function Jqe(l,o=0){const f=[l.start[0]+l.axis[0]*o,l.start[1]+l.axis[1]*o,l.start[2]+l.axis[2]*o];return[l.basisX[0],l.basisX[1],l.basisX[2],0,l.basisY[0],l.basisY[1],l.basisY[2],0,l.axis[0],l.axis[1],l.axis[2],0,f[0],f[1],f[2],1]}function qqe(l){const o=l.end[0]-l.start[0],f=l.end[1]-l.start[1],g=l.end[2]-l.start[2];return Math.hypot(o,f,g)}function DCt(l,o,f,g,T){const P=qqe(o);if(!(P>1e-6))return l;const[O,z]=o.quadrant,H=P+Xte*2,re=Jqe(o,-Xte),te=T.CrossSection.square([f,f],!1).translate(O>0?0:-f,z>0?0:-f).extrude(H,0,0,void 0,!1).transform(re),W=T.CrossSection.circle(f,Math.max(3,g)).extrude(H,0,0,void 0,!1).transform(re);return T.Manifold.union([T.Manifold.difference([l,te]),W])}function ACt(l,o,f,g){const T=qqe(o);if(!(T>1e-6))return l;const[P,O]=o.quadrant,z=T+Xte*2,H=Jqe(o,-Xte),te=new g.CrossSection([[[0,0],[P*f,0],[0,O*f]]]).extrude(z,0,0,void 0,!1).transform(H);return g.Manifold.difference([l,te])}function NCt(l,o){switch(o.kind){case"translate":return l.translate(o.x,o.y);case"rotate":return l.rotate(o.degrees);case"scale":return l.scale([o.x,o.y]);case"mirror":return l.mirror([o.normalX,o.normalY])}}function fC(l,o){let f=l;for(const g of o)f=NCt(f,g);return f}function ICt(l,o){const f=l.profiles.map(T=>s4(T,o));if(f.length===0)throw new Error(`Cannot lower empty profile boolean (${l.op})`);if(f.length===1)return fC(f[0],l.transforms);const g=(()=>{switch(l.op){case"union":return o.CrossSection.union(f);case"difference":return o.CrossSection.difference(f);case"intersection":return o.CrossSection.intersection(f)}})();return fC(g,l.transforms)}function FCt(l,o){const f=l.profiles.map(g=>s4(g,o));if(f.length===0)throw new Error("Cannot lower empty profile hull");return f.length===1?fC(f[0],l.transforms):fC(o.CrossSection.hull(f),l.transforms)}function s4(l,o){switch(l.kind){case"rect":return fC(o.CrossSection.square([l.width,l.height],l.center),l.transforms);case"roundedRect":{const f=Math.min(l.radius,l.width/2,l.height/2),g=o.CrossSection.square([l.width-2*f,l.height-2*f],!0).translate(l.center?0:l.width/2,l.center?0:l.height/2).offset(f,"Round");return fC(g,l.transforms)}case"circle":return fC(o.CrossSection.circle(l.radius,l.segments??0),l.transforms);case"polygon":return fC(new o.CrossSection([l.points]),l.transforms);case"boolean":return ICt(l,o);case"offset":return fC(s4(l.base,o).offset(l.delta,l.join),l.transforms);case"hull":return FCt(l,o);case"project":{const f=wb(l.sourceShape,o).transform(Nqe(l.plane)).project();return fC(f,l.transforms)}}}function OCt(l,o){switch(o.kind){case"translate":return l.translate(o.x,o.y,o.z);case"rotate":return l.rotate(o.xDeg,o.yDeg,o.zDeg);case"scale":return l.scale([o.x,o.y,o.z]);case"rotateAround":return l.transform(Ea.rotationAxis([o.axisX,o.axisY,o.axisZ],o.degrees,[o.pivotX,o.pivotY,o.pivotZ]).toArray());case"mirror":return l.mirror([o.normalX,o.normalY,o.normalZ]);case"workplanePlacement":return l.transform(o.matrix)}}function MCt(l,o){let f=l;for(const g of o)f=OCt(f,g);return f}function LCt(l,o){const f=l.shapes.map(g=>wb(g,o));if(f.length===0)throw new Error(`Cannot lower empty shape boolean (${l.op})`);if(f.length===1)return f[0];switch(l.op){case"union":return o.Manifold.union(f);case"difference":return o.Manifold.difference(f);case"intersection":return o.Manifold.intersection(f)}}function RCt(l,o){const g=[...l.shapes.map(T=>wb(T,o)),...l.points.map(([T,P,O])=>[T,P,O])];if(g.length===0)throw new Error("Cannot lower empty shape hull");return o.Manifold.hull(g)}function jCt(l,o){return wb(l.base,o).trimByPlane([l.normalX,l.normalY,l.normalZ],l.originOffset)}function BCt(l,o){const f=l.profiles.map(P=>s4(P,o).toPolygons());if(f.length>=2&&f.every(P=>P.length===1)){const P=uCt(f,l.heights,o);if(P)return P}const T=Cqe(f,l.heights,{edgeLength:l.edgeLength,boundsPadding:l.boundsPadding});return o.Manifold.levelSet(T.sdf,T.bounds,T.edgeLength,0)}function zCt(l,o){const f=wqe(s4(l.profile,o).toPolygons(),l.path.points.map(([g,T,P])=>[g,T,P]),{edgeLength:l.edgeLength,boundsPadding:l.boundsPadding,up:[l.up[0],l.up[1],l.up[2]]});return o.Manifold.levelSet(f.sdf,f.bounds,f.edgeLength,0)}function JCt(l,o){const f=lI(l.base,l.edge);if(!f.ok)throw new Error(f.issue.reason);if(f.selection.quadrant[0]!==l.quadrant[0]||f.selection.quadrant[1]!==l.quadrant[1])throw new Error(`filletEdge() currently supports ${f.selection.edgeName} only with quadrant [${f.selection.quadrant[0]}, ${f.selection.quadrant[1]}].`);return DCt(wb(l.base,o),f.selection,l.radius,l.segments,o)}function qCt(l,o){const f=lI(l.base,l.edge);if(!f.ok)throw new Error(f.issue.reason);if(f.selection.quadrant[0]!==l.quadrant[0]||f.selection.quadrant[1]!==l.quadrant[1])throw new Error(`chamferEdge() currently supports ${f.selection.edgeName} only with quadrant [${f.selection.quadrant[0]}, ${f.selection.quadrant[1]}].`);return ACt(wb(l.base,o),f.selection,l.size,o)}function wb(l,o){switch(l.kind){case"box":return o.Manifold.cube([l.x,l.y,l.z],l.center);case"cylinder":return o.Manifold.cylinder(l.height,l.radius,l.radiusTop??-1,l.segments??0,l.center);case"sphere":return o.Manifold.sphere(l.radius,l.segments??0);case"extrude":return s4(l.profile,o).extrude(l.height,0,0,l.scaleTop,l.center);case"sheetMetal":return wb(gTt(l.model,l.output),o);case"shell":{const f=Tqe(l);if(!f.ok)throw new Error(f.reason);return wb(f.plan,o)}case"hole":{const f=Gkt(l);if(!f.ok)throw new Error(f.reason);return wb(f.plan,o)}case"cut":{const f=Xkt(l);if(!f.ok)throw new Error(f.reason);return wb(f.plan,o)}case"revolve":return s4(l.profile,o).revolve(l.segments??0,l.degrees);case"loft":return BCt(l,o);case"sweep":return zCt(l,o);case"boolean":return LCt(l,o);case"transform":return MCt(wb(l.base,o),l.steps);case"queryOwner":return wb(l.base,o);case"fillet":return JCt(l,o);case"chamfer":return qCt(l,o);case"hull":return RCt(l,o);case"trimByPlane":return jCt(l,o)}}function WCt(l,o){return gqe(wb(l,o))}function Wqe(l){switch(l.kind){case"translate":return{kind:"translate",description:`Translate by [${l.x}, ${l.y}, ${l.z}]`,details:{x:l.x,y:l.y,z:l.z}};case"rotate":return{kind:"rotate",description:`Rotate by [${l.xDeg}°, ${l.yDeg}°, ${l.zDeg}°]`,details:{xDeg:l.xDeg,yDeg:l.yDeg,zDeg:l.zDeg}};case"scale":return{kind:"scale",description:`Scale by [${l.x}, ${l.y}, ${l.z}]`,details:{x:l.x,y:l.y,z:l.z}};case"mirror":return{kind:"mirror",description:`Mirror across plane with normal [${l.normalX}, ${l.normalY}, ${l.normalZ}]`,details:{normalX:l.normalX,normalY:l.normalY,normalZ:l.normalZ}};case"rotateAround":return{kind:"rotateAround",description:`Rotate ${l.degrees}° around axis [${l.axisX}, ${l.axisY}, ${l.axisZ}] at pivot [${l.pivotX}, ${l.pivotY}, ${l.pivotZ}]`,details:{axisX:l.axisX,axisY:l.axisY,axisZ:l.axisZ,degrees:l.degrees,pivotX:l.pivotX,pivotY:l.pivotY,pivotZ:l.pivotZ}};case"workplanePlacement":return{kind:"workplanePlacement",description:"Place on workplane",details:{matrix:l.matrix,placement:l.placement}}}}function HJ(l){if(!l)return[];const o=[];switch(l.kind){case"transform":o.push(...HJ(l.base)),o.push(...l.steps.map(Wqe));break;case"queryOwner":o.push(...HJ(l.base));break;case"boolean":l.shapes.length>0&&o.push(...HJ(l.shapes[0]));break;case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":o.push(...HJ(l.base));break}return o}function h2e(l){if(!l)return{operation:"unknown"};switch(l.kind){case"queryOwner":return{operation:l.owner.operation,owner:l.owner};case"transform":return h2e(l.base);case"boolean":return{operation:`${l.op} (${l.shapes.length} operands)`};case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":return h2e(l.base);default:return{operation:l.kind}}}function Ibe(l){switch(l.kind){case"rect":return`${l.width}×${l.height} rect`;case"roundedRect":return`${l.width}×${l.height} rounded rect`;case"circle":return`r=${l.radius} circle`;case"polygon":return`polygon (${l.points.length} pts)`;case"boolean":return`${l.op} profile`;case"offset":return"offset profile";case"hull":return"hull profile";case"project":return"projected profile"}}function cC(l,o){switch(l.kind){case"queryOwner":cC(l.base,o);return;case"transform":cC(l.base,o);for(const f of l.steps){const g=Wqe(f),T=f.kind==="translate"?"Move":f.kind==="rotate"?"Rotate":f.kind==="rotateAround"?"Rotate Around":f.kind==="scale"?"Scale":f.kind==="mirror"?"Mirror":"Place on Workplane";o.push({kind:f.kind,label:T,summary:g.description,category:"transform"})}return;case"shell":cC(l.base,o),o.push({kind:"shell",label:"Shell",summary:`t = ${l.thickness}`,category:"modifier"});return;case"hole":cC(l.base,o),o.push({kind:"hole",label:"Hole",summary:`r = ${l.hole.radius}`,category:"modifier"});return;case"cut":cC(l.base,o),o.push({kind:"cut",label:"Cut",summary:Ibe(l.profile),category:"modifier"});return;case"fillet":cC(l.base,o),o.push({kind:"fillet",label:"Fillet",summary:`r = ${l.radius}`,category:"modifier"});return;case"chamfer":cC(l.base,o),o.push({kind:"chamfer",label:"Chamfer",summary:`size = ${l.size}`,category:"modifier"});return;case"trimByPlane":cC(l.base,o),o.push({kind:"trimByPlane",label:"Trim by Plane",summary:`normal [${l.normalX}, ${l.normalY}, ${l.normalZ}]`,category:"modifier"});return;case"boolean":l.shapes.length>0&&cC(l.shapes[0],o),o.push({kind:"boolean",label:l.op==="union"?"Union":l.op==="difference"?"Difference":"Intersection",summary:`${l.shapes.length} operand${l.shapes.length!==1?"s":""}`,category:"boolean"});return;case"hull":o.push({kind:"hull",label:"Hull",summary:`${l.shapes.length} shapes`,category:"boolean"});return;case"extrude":o.push({kind:"extrude",label:"Extrude",summary:`${Ibe(l.profile)}, h = ${l.height}`,category:"sketch"});return;case"revolve":o.push({kind:"revolve",label:"Revolve",summary:`${l.degrees}°`,category:"sketch"});return;case"loft":o.push({kind:"loft",label:"Loft",summary:`${l.profiles.length} sections`,category:"sketch"});return;case"sweep":o.push({kind:"sweep",label:"Sweep",summary:Ibe(l.profile),category:"sketch"});return;case"box":o.push({kind:"box",label:"Box",summary:`${l.x} × ${l.y} × ${l.z}`,category:"primitive"});return;case"cylinder":o.push({kind:"cylinder",label:"Cylinder",summary:l.radiusTop!==void 0&&l.radiusTop!==l.radius?`r = ${l.radius}→${l.radiusTop}, h = ${l.height}`:`r = ${l.radius}, h = ${l.height}`,category:"primitive"});return;case"sphere":o.push({kind:"sphere",label:"Sphere",summary:`r = ${l.radius}`,category:"primitive"});return;case"sheetMetal":o.push({kind:"sheetMetal",label:"Sheet Metal",summary:"",category:"primitive"});return;default:{const f=l.kind;o.push({kind:f,label:f,summary:"",category:"primitive"});return}}}function VCt(l){if(!l)return[];const o=[];return cC(l,o),o}function UCt(l,o){const f=HJ(l),g=h2e(l),T=VCt(l);return{faceName:o.name,origin:g,transformations:f,query:o.query,timeline:T}}let YE=null;async function $Ct(){if(YE)return YE;const l=(await import("./manifold-B85M7kop.js")).default;return YE=await l(),YE.setup(),YE.setMinCircularAngle(2),YE.setMinCircularEdgeLength(.5),YE}function nd(){if(!YE)throw new Error("Kernel not initialized — call initKernel() first");return YE}function uxe(l){if(l instanceof na)return l;if(l&&typeof l=="object"&&typeof l.toShape=="function"){const o=l.toShape();if(o instanceof na)return o;throw new Error(`expected toShape() to return a Shape, got ${Vte(o)}`)}throw new Error(`expected a Shape or TrackedShape-compatible value, got ${Vte(l)}`)}const g2e=new WeakMap,Vqe=new WeakMap,Uqe=new WeakMap,y2e=new WeakMap,$qe=new WeakMap;let mze=0;const ZN={backend:"manifold",representation:"mesh-solid",fidelity:"unknown",topology:"none",sources:["unknown"]};function _xe(l){const o=[],f=new Set;for(const g of l)f.has(g)||(f.add(g),o.push(g));return o}function Hqe(l){return{backend:l.backend,representation:l.representation,fidelity:l.fidelity,topology:l.topology,sources:[...l.sources]}}function yq(l={}){return{backend:l.backend??ZN.backend,representation:l.representation??ZN.representation,fidelity:l.fidelity??ZN.fidelity,topology:l.topology??ZN.topology,sources:_xe(l.sources?[...l.sources]:[...ZN.sources])}}function O_(l,o){return Vqe.set(l,Hqe(o)),l}function HCt(l,o){const f=Wkt(o)?o:gqe(o);return $qe.set(l,f),l}function nu(l,o){return Uqe.set(l,m_(o)),l}function vq(l,o){return ZSt(o)?y2e.set(l,KJe(o)):y2e.delete(l),l}function Xf(l){return Hqe(Vqe.get(l)??ZN)}function d_(l){const o=$qe.get(l);if(!o)throw new Error("Runtime backend missing on Shape");return o}function ju(l){return m_(Uqe.get(l)??null)}function n6(l){return KJe(y2e.get(l)??sM())}function Yee(l,o){const f=[...new Set(l)];return f.length===1?f[0]:o}function oC(l,o,f={}){return yq({backend:f.backend??l.backend,representation:f.representation??l.representation,fidelity:f.fidelity??l.fidelity,topology:f.topology??l.topology,sources:_xe([o,...l.sources,...f.sources??[]])})}function KD(l,o,f={}){return yq({backend:f.backend??Yee(l.map(g=>g.backend),"hybrid"),representation:f.representation??Yee(l.map(g=>g.representation),"mixed"),fidelity:f.fidelity??Yee(l.map(g=>g.fidelity),"mixed"),topology:f.topology??Yee(l.map(g=>g.topology),"none"),sources:_xe([o,...l.flatMap(g=>g.sources),...f.sources??[]])})}function Gqe(){return mze+=1,`shape-dim-${mze}`}function GCt(l,o=!1){return{id:o?Gqe():l.id,from:[l.from[0],l.from[1],l.from[2]],to:[l.to[0],l.to[1],l.to[2]],offset:l.offset,autoOffset:l.autoOffset,label:l.label,color:l.color,components:l.components?[...l.components]:void 0,currentComponent:l.currentComponent}}function bq(l,o=!1){return l.map(f=>GCt(f,o))}function nM(l,o){return o.length===0?g2e.delete(l):g2e.set(l,o),l}function xq(l){return g2e.get(l)??[]}function hze(l,o){const f=o[0],g=o[1],T=o[2];return[l[0]*f+l[4]*g+l[8]*T+l[12],l[1]*f+l[5]*g+l[9]*T+l[13],l[2]*f+l[6]*g+l[10]*T+l[14]]}function XCt(l,o){return l.map(f=>({id:Gqe(),from:hze(o,f.from),to:hze(o,f.to),offset:f.offset,autoOffset:f.autoOffset,label:f.label,color:f.color,components:f.components?[...f.components]:void 0,currentComponent:f.currentComponent}))}function YCt(l,o,f){return Ea.identity().rotateAxis([1,0,0],l).rotateAxis([0,1,0],o).rotateAxis([0,0,1],f).toArray()}function QCt(l,o,f){const[g,T,P]=f,O=o*Math.PI/180,z=Math.cos(O),H=Math.sin(O),re=Math.sqrt(l[0]**2+l[1]**2+l[2]**2)||1,te=l[0]/re,W=l[1]/re,Ee=l[2]/re,se=z+te*te*(1-z),me=te*W*(1-z)-Ee*H,Xe=te*Ee*(1-z)+W*H,it=W*te*(1-z)+Ee*H,at=z+W*W*(1-z),It=W*Ee*(1-z)-te*H,tn=Ee*te*(1-z)-W*H,At=Ee*W*(1-z)+te*H,mt=z+Ee*Ee*(1-z),ht=g-(se*g+me*T+Xe*P),xn=T-(it*g+at*T+It*P),Pn=P-(tn*g+At*T+mt*P);return[se,it,tn,0,me,at,At,0,Xe,It,mt,0,ht,xn,Pn,1]}function ZCt(l){const[o,f,g]=l,T=Math.hypot(o,f,g);if(T<1e-12)return Ea.identity().toArray();const P=o/T,O=f/T,z=g/T,H=1-2*P*P,re=-2*P*O,te=-2*P*z,W=-2*O*P,Ee=1-2*O*O,se=-2*O*z,me=-2*z*P,Xe=-2*z*O,it=1-2*z*z;return[H,W,me,0,re,Ee,Xe,0,te,se,it,0,0,0,0,1]}function KCt(l){const o=typeof l=="number"?[l,l,l]:l;return!Number.isFinite(o[0])||!Number.isFinite(o[1])||!Number.isFinite(o[2])||Math.abs(o[0])<1e-12||Math.abs(o[1])<1e-12||Math.abs(o[2])<1e-12?null:[o[0],o[1],o[2]]}function Qee(l,o){return l[0]*o[0]+l[1]*o[1]+l[2]*o[2]}function ewt(l,o){return[l[1]*o[2]-l[2]*o[1],l[2]*o[0]-l[0]*o[2],l[0]*o[1]-l[1]*o[0]]}function Ete(l){return Math.hypot(l[0],l[1],l[2])}function gze(l){const o=Ete(l);return o<1e-12?[1,0,0]:[l[0]/o,l[1]/o,l[2]/o]}function twt(l){if(Math.abs(l[3])>1e-6||Math.abs(l[7])>1e-6||Math.abs(l[11])>1e-6||Math.abs(l[15]-1)>1e-6)return null;const f=[l[0],l[1],l[2]],g=[l[4],l[5],l[6]],T=[l[8],l[9],l[10]],P=Ete(f),O=Ete(g),z=Ete(T);if(Math.abs(P-1)>1e-6||Math.abs(O-1)>1e-6||Math.abs(z-1)>1e-6||Math.abs(Qee(f,g))>1e-6||Math.abs(Qee(f,T))>1e-6||Math.abs(Qee(g,T))>1e-6)return null;const H=Qee(f,ewt(g,T));if(Math.abs(H-1)>1e-6)return null;const re=l[0],te=l[4],W=l[8],Ee=l[1],se=l[5],me=l[9],Xe=l[2],it=l[6],at=l[10],It=l[12],tn=l[13],At=l[14],mt=[],ht=re+se+at,xn=Math.max(-1,Math.min(1,(ht-1)/2)),Pn=Math.acos(xn),$r=Pn*180/Math.PI;if($r>1e-6){let zn;if(Math.PI-Pn<1e-5){const ii=Math.max(0,(re+1)/2),Gr=Math.max(0,(se+1)/2),mn=Math.max(0,(at+1)/2),$s=(te+Ee)/4,is=(W+Xe)/4,Wt=(me+it)/4;if(ii>=Gr&&ii>=mn){const Es=Math.sqrt(ii);zn=[Es,Es>1e-6?$s/Es:0,Es>1e-6?is/Es:0]}else if(Gr>=mn){const Es=Math.sqrt(Gr);zn=[Es>1e-6?$s/Es:0,Es,Es>1e-6?Wt/Es:0]}else{const Es=Math.sqrt(mn);zn=[Es>1e-6?is/Es:0,Es>1e-6?Wt/Es:0,Es]}}else zn=gze([it-me,W-Xe,Ee-te]);zn=gze(zn),mt.push({kind:"rotateAround",axisX:zn[0],axisY:zn[1],axisZ:zn[2],degrees:$r,pivotX:0,pivotY:0,pivotZ:0})}return(Math.abs(It)>1e-6||Math.abs(tn)>1e-6||Math.abs(At)>1e-6)&&mt.push({kind:"translate",x:It,y:tn,z:At}),mt}function $N(l,o){return nM(o,bq(xq(l),!0)),O_(o,Xf(l)),vq(o,n6(l)),nu(o,ju(l))}function DO(l,o,f){const g=xq(l);return g.length===0?nM(o,[]):nM(o,XCt(g,f)),O_(o,Xf(l)),vq(o,KSt(n6(l),f)),nu(o,ju(l))}function oq(l,o){const f=l.flatMap(P=>xq(P));nM(o,bq(f,!0));const g=l.length>0?Xf(l[0]):ZN;O_(o,g),vq(o,eqe(...l.map(P=>n6(P))));const T=l.length>0?ju(l[0]):null;return nu(o,T)}function W1(l,o){return nM(o,bq(xq(l),!0)),O_(o,Xf(l)),vq(o,n6(l)),nu(o,ju(l))}function yze(l,o){return Array.isArray(o)?[o[0],o[1],o[2]]:l.referencePoint(o)}function Yte(l,o,f={}){const g=f.regenerateIds??!0;return nM(l,bq(o,g))}function fxe(l){return bq(xq(l),!1)}function mne(l,o,f={}){const g=f.merge??!0?eze(n6(l),o):eze(sM(),o);return vq(l,g)}function Xqe(l){return n6(l)}function Yqe(l){return Xf(l)}function hne(l,o){const f=Xf(l);return O_(l,yq({backend:o.backend??f.backend,representation:o.representation??f.representation,fidelity:o.fidelity??f.fidelity,topology:o.topology??f.topology,sources:o.sources??f.sources}))}function c4(l){return ju(l)}function gne(l,o){return nu(l,o)}function Qte(l){return _ne(ju(l))}function Qqe(l){return NTt(ju(l))}function nwt(l){return UJ(ju(l))}function M_(l,o,f){return gne(new na(WCt(l,nd()),o,f),l)}function U1(l,o,f){if(!l)return null;const g=une(o);return hq(ixe(l,f(g)),g)}class na{constructor(o,f,g){tu(this,"colorHex");this.colorHex=f,HCt(this,o),O_(this,yq(g)),nu(this,null)}setColor(o){return $N(this,new na(d_(this).clone(),o))}color(o){return this.setColor(o)}clone(){return $N(this,new na(d_(this).clone(),this.colorHex))}duplicate(){return this.clone()}geometryInfo(){return Xf(this)}withReferences(o){return mne(this.clone(),o,{merge:!0})}referenceNames(o){return tqe(n6(this),o)}referencePoint(o){return Zqe(this,o)}face(o){const f=ju(this),g=lze(f,o);if(g)return g;throw new Error(uze(f,o))}faceNames(){return dkt(ju(this))}faceHistory(o){const f=ju(this),g=lze(f,o);if(!g)throw new Error(uze(f,o));return UCt(f,g)}placeReference(o,f,g){const T=this.referencePoint(o);let P=f[0]-T[0],O=f[1]-T[1],z=f[2]-T[2];return g&&(P+=g[0],O+=g[1],z+=g[2]),this.translate(P,O,z)}translate(o,f,g){const T=G1(ju(this),{kind:"translate",x:o,y:f,z:g});return nu(DO(this,T?M_(T,this.colorHex):new na(d_(this).translate(o,f,g),this.colorHex),Ea.translation(o,f,g).toArray()),T)}moveTo(o,f,g){const T=this.boundingBox();return this.translate(o-T.min[0],f-T.min[1],g-T.min[2])}moveToLocal(o,f,g,T){const O=("toShape"in o?o.toShape():o).boundingBox();return this.moveTo(O.min[0]+f,O.min[1]+g,O.min[2]+T)}rotate(o,f,g){const T=G1(ju(this),{kind:"rotate",xDeg:o,yDeg:f,zDeg:g});return nu(DO(this,T?M_(T,this.colorHex):new na(d_(this).rotate(o,f,g),this.colorHex),YCt(o,f,g)),T)}transform(o){const f=o instanceof Ea?o.toArray():o,g=(()=>{const T=twt(f);return T==null?null:T.length===0?ju(this):ATt(ju(this),T)})();return nu(DO(this,g?M_(g,this.colorHex):new na(d_(this).transform(f),this.colorHex),f),g)}scale(o){const f=KCt(o),g=f?G1(ju(this),{kind:"scale",x:f[0],y:f[1],z:f[2]}):null;return nu(DO(this,g?M_(g,this.colorHex):new na(d_(this).scale(o),this.colorHex),Ea.scale(o).toArray()),g)}mirror(o){const f=G1(ju(this),{kind:"mirror",normalX:o[0],normalY:o[1],normalZ:o[2]}),g=hqe(f,"mirror");return nu(DO(this,g?M_(g,this.colorHex):new na(d_(this).mirror(o),this.colorHex),ZCt(o)),g)}pointAlong(o){const[f,g,T]=o,P=Math.sqrt(f*f+g*g+T*T)||1,O=f/P,z=g/P,H=T/P,re=-z,te=O,W=0,Ee=Math.sqrt(re*re+te*te+W*W),se=H;if(Ee<1e-10)return se>0?this:this.rotate(180,0,0);const me=Math.atan2(Ee,se)*180/Math.PI,Xe=re/Ee,it=te/Ee,at=W/Ee;return this.rotateAround([Xe,it,at],me)}rotateAround(o,f,g=[0,0,0]){const T=Math.sqrt(o[0]**2+o[1]**2+o[2]**2)||1,P=[o[0]/T,o[1]/T,o[2]/T],O=QCt(P,f,g),z=G1(ju(this),{kind:"rotateAround",axisX:P[0],axisY:P[1],axisZ:P[2],degrees:f,pivotX:g[0],pivotY:g[1],pivotZ:g[2]});return nu(DO(this,z?M_(z,this.colorHex):new na(d_(this).transform(O),this.colorHex),O),z)}rotateAroundTo(o,f,g,T,P={}){const O=yze(this,g),z=yze(this,T),H=VJe(o,f,O,z,P);return this.rotateAround(o,H,f)}smoothOut(o=60,f=0){return nu(O_($N(this,new na(d_(this).smoothOut(o,f),this.colorHex)),oC(Xf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}refine(o){const f=WSt(o);return f<=0?this.clone():nu(O_($N(this,new na(d_(this).refine(f),this.colorHex)),oC(Xf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}refineToLength(o){const f=VSt(o);return nu(O_($N(this,new na(d_(this).refineToLength(f),this.colorHex)),oC(Xf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}refineToTolerance(o){const f=USt(o);return nu(O_($N(this,new na(d_(this).refineToTolerance(f),this.colorHex)),oC(Xf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}warp(o){return nu(O_($N(this,new na(d_(this).warp(o),this.colorHex)),oC(Xf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}static _unwrap(o){return uxe(o)}add(...o){const f=[this,...$O("Shape.add()",o,1,"Use shape.add(other1, other2) or shape.add([other1, other2]).")],g=f.map(P=>ju(P)),T=U1(Ry("union",g),"boolean:union",P=>YD("union",P,g));return nu(O_(oq(f,T?M_(T,this.colorHex):new na(nd().Manifold.union(HO("Shape.add()",f)),this.colorHex)),KD(f.map(P=>Xf(P)),"boolean",{topology:"none"})),T)}subtract(...o){const f=[this,...$O("Shape.subtract()",o,1,"Use shape.subtract(other1, other2) or shape.subtract([other1, other2]).")],g=f.map(P=>ju(P)),T=U1(Ry("difference",g),"boolean:difference",P=>YD("difference",P,g));return nu(O_(W1(this,T?M_(T,this.colorHex):new na(nd().Manifold.difference(HO("Shape.subtract()",f)),this.colorHex)),KD(f.map(P=>Xf(P)),"boolean",{topology:"none"})),T)}intersect(...o){const f=[this,...$O("Shape.intersect()",o,1,"Use shape.intersect(other1, other2) or shape.intersect([other1, other2]).")],g=f.map(P=>ju(P)),T=U1(Ry("intersection",g),"boolean:intersection",P=>YD("intersection",P,g));return nu(O_(oq(f,T?M_(T,this.colorHex):new na(nd().Manifold.intersection(HO("Shape.intersect()",f)),this.colorHex)),KD(f.map(P=>Xf(P)),"boolean",{topology:"none"})),T)}split(o){const f=na._unwrap(o),g=[ju(this),ju(f)],T=U1(Ry("intersection",g),"split:inside",te=>YD("intersection",te,g)),P=[ju(this),ju(f)],O=U1(Ry("difference",P),"split:outside",te=>YD("difference",te,P)),z=KD([Xf(this),Xf(f)],"boolean",{topology:"none"});if(T&&O)return[nu(O_(W1(this,M_(T,this.colorHex)),z),T),nu(O_(W1(this,M_(O,this.colorHex)),z),O)];const[H,re]=d_(this).split(d_(f));return[nu(O_(W1(this,new na(H,this.colorHex)),z),null),nu(O_(W1(this,new na(re,this.colorHex)),z),null)]}splitByPlane(o,f=0){const g=oC(Xf(this),"boolean",{topology:"none"}),T=ju(this),P=U1(wbe(T,o,f),"splitByPlane:positive",re=>Dbe(re,T)),O=U1(wbe(T,[-o[0],-o[1],-o[2]],-f),"splitByPlane:opposite",re=>Dbe(re,T));if(P&&O)return[nu(O_(W1(this,M_(P,this.colorHex)),g),P),nu(O_(W1(this,M_(O,this.colorHex)),g),O)];const[z,H]=d_(this).splitByPlane(o,f);return[nu(O_(W1(this,new na(z,this.colorHex)),g),null),nu(O_(W1(this,new na(H,this.colorHex)),g),null)]}trimByPlane(o,f=0){const g=ju(this),T=U1(wbe(g,o,f),"trimByPlane",P=>Dbe(P,g));return nu(O_(W1(this,T?M_(T,this.colorHex):new na(d_(this).trimByPlane(o,f),this.colorHex)),oC(Xf(this),"boolean",{topology:"none"})),T)}shell(o,f={}){const g=ju(this),T=U1(tCt(g,o,f.openFaces),"shell",P=>Lkt(P,g,f.openFaces??[]));if(!T)throw new Error("Shape.shell() currently supports compile-covered box(), cylinder(), and straight extrude() solids with optional top/bottom openings and rigid transforms.");return nu(O_(W1(this,M_(T,this.colorHex)),oC(Xf(this),"shell",{topology:"none"})),T)}hull(){const o=U1(sqe([ju(this)]),"hull",f=>mqe(f));return nu(O_(W1(this,o?M_(o,this.colorHex):new na(d_(this).hull(),this.colorHex)),oC(Xf(this),"hull",{topology:"none"})),o)}simplify(o){return nu(O_(W1(this,new na(d_(this).simplify(o),this.colorHex)),oC(Xf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}boundingBox(){return d_(this).boundingBox()}volume(){return d_(this).volume()}surfaceArea(){return d_(this).surfaceArea()}minGap(o,f){const g="toShape"in o?o.toShape():o;return d_(this).minGap(d_(g),f)}isEmpty(){return d_(this).isEmpty()}numTri(){return d_(this).numTri()}getMesh(){return d_(this).getMesh()}slice(o=0){return d_(this).slice(o)}project(){return d_(this).project()}attachTo(o,f,g="center",T){const P=rwt(o,f),O=this.referencePoint(g);let z=P[0]-O[0],H=P[1]-O[1],re=P[2]-O[2];return T&&(z+=T[0],H+=T[1],re+=T[2]),this.translate(z,H,re)}onFace(o,f,g={}){const T=g.u??0,P=g.v??0,O=g.protrude??0,z={front:"back",back:"front",left:"right",right:"left",top:"bottom",bottom:"top"},H={front:(W,Ee,se)=>[W,-se,Ee],back:(W,Ee,se)=>[W,se,Ee],left:(W,Ee,se)=>[-se,W,Ee],right:(W,Ee,se)=>[se,W,Ee],top:(W,Ee,se)=>[W,Ee,se],bottom:(W,Ee,se)=>[W,Ee,-se]},re=z[f],te=H[f](T,P,O);return this.attachTo(o,f,re,te)}}function vze(l,o){const g=(typeof l.toShape=="function"?l.toShape():l).boundingBox();return t4(g.min,g.max,o)}function Zqe(l,o){if(QJe(o))return vze(l,o);const f=eTt(n6(l),o);if(f)return f;const g=cne(o);if(g)return vze(l,g);throw new Error(`Unknown placement reference "${o}". Available: ${tqe(n6(l)).join(", ")||"none"}`)}function rwt(l,o){if(l instanceof na)return Zqe(l,o);if("referencePoint"in l&&typeof l.referencePoint=="function")return l.referencePoint(o);const f=cne(o);if(!f)throw new Error(`ShapeGroup targets only support built-in anchors, got "${o}"`);if(!("_bbox"in l)||typeof l._bbox!="function")throw new Error("ShapeGroup anchor target is missing _bbox()");const g=l._bbox();return t4(g.min,g.max,f)}function eT(l,o,f,g=!1){return M_(s6({kind:"box",x:l,y:o,z:f,center:g},"primitive:box"),void 0,{fidelity:"kernel-native",sources:["primitive"]})}function Th(l,o,f,g,T=!1){return M_(s6({kind:"cylinder",height:l,radius:o,radiusTop:f!=null&&f>=0?f:void 0,segments:g!=null&&g>0?g:void 0,center:T},"primitive:cylinder"),void 0,{fidelity:"kernel-native",sources:["primitive"]})}function iwt(l,o){return M_(s6({kind:"sphere",radius:l,segments:o!=null&&o>0?o:void 0},"primitive:sphere"),void 0,{fidelity:"kernel-native",sources:["primitive"]})}function $O(l,o,f,g){return aqe({apiName:l,inputs:o,minCount:f,itemName:"shape",usage:g,coerce:T=>uxe(T)})}function swt(l,o,f){if(Array.isArray(l)&&l.length===3&&l.every(g=>typeof g=="number"&&Number.isFinite(g)))return l;throw new Error(`${o} argument ${f}: expected a [x, y, z] point, got ${Vte(l)}`)}function HO(l,o){return o.map((f,g)=>Gte(d_(f),`${l} operand ${g+1}`))}function K1(...l){const o=$O("union()",l,1,"Use union(shape1, shape2) or union([shape1, shape2]).");if(o.length===0)throw new Error("union requires at least one shape");if(o.length===1)return o[0];const f=o.map(T=>ju(T)),g=U1(Ry("union",f),"boolean:union",T=>YD("union",T,f));return nu(O_(oq(o,g?M_(g,o[0].colorHex):new na(nd().Manifold.union(HO("union()",o)),o[0].colorHex)),KD(o.map(T=>Xf(T)),"boolean",{topology:"none"})),g)}function awt(...l){const o=$O("difference()",l,2,"Use difference(base, cutter1, cutter2) or difference([base, cutter1, cutter2]).");if(o.length<2)throw new Error("difference requires at least two shapes");const f=o.map(T=>ju(T)),g=U1(Ry("difference",f),"boolean:difference",T=>YD("difference",T,f));return nu(O_(W1(o[0],g?M_(g,o[0].colorHex):new na(nd().Manifold.difference(HO("difference()",o)),o[0].colorHex)),KD(o.map(T=>Xf(T)),"boolean",{topology:"none"})),g)}function owt(...l){const o=$O("intersection()",l,2,"Use intersection(shape1, shape2) or intersection([shape1, shape2]).");if(o.length<2)throw new Error("intersection requires at least two shapes");const f=o.map(T=>ju(T)),g=U1(Ry("intersection",f),"boolean:intersection",T=>YD("intersection",T,f));return nu(O_(oq(o,g?M_(g,o[0].colorHex):new na(nd().Manifold.intersection(HO("intersection()",o)),o[0].colorHex)),KD(o.map(T=>Xf(T)),"boolean",{topology:"none"})),g)}function cwt(...l){var O,z;const o=[],f=[],g=l.map((H,re)=>{if(H instanceof na||H&&typeof H=="object"&&typeof H.toShape=="function"){const W=uxe(H);return o.push(W),Gte(d_(W),`hull3d() shape ${o.length}`)}const te=swt(H,"hull3d()",re+1);return f.push(te),te}),T=U1(sqe(o.map(H=>ju(H)),f),"hull",H=>mqe(H)),P=T?M_(T,(O=o[0])==null?void 0:O.colorHex):new na(nd().Manifold.hull(g),(z=o[0])==null?void 0:z.colorHex);return nu(O_(oq(o,P),o.length>0?KD(o.map(H=>Xf(H)),"hull",{topology:"none"}):yq({fidelity:"kernel-native",sources:["hull"]})),T)}function pxe(l,o,f,g=0){return new na(nd().Manifold.levelSet(l,{min:o.min,max:o.max},f,g),void 0,{fidelity:"sampled",sources:["level-set"]})}const Kqe=new WeakMap,eWe=new WeakMap,tWe=new WeakMap;function Pte(l,o){return Kqe.set(l,Fd(o)),l}function nWe(l){return l?[...l]:null}function KJ(l,o){return eWe.set(l,nWe(o)),l}function eq(l,o){return tWe.set(l,i6(o)),l}class Eo{constructor(o,f){tu(this,"colorHex");this.cross=o,this.colorHex=f,Pte(this,null),KJ(this,null),eq(this,null)}color(o){return eq(KJ(Pte(new Eo(this.cross,o),um(this)),a4(this)),r6(this))}clone(){return eq(KJ(Pte(new Eo(this.cross,this.colorHex),um(this)),a4(this)),r6(this))}duplicate(){return this.clone()}area(){return this.cross.area()}bounds(){return this.cross.bounds()}isEmpty(){return this.cross.isEmpty()}numVert(){return this.cross.numVert()}toPolygons(){return this.cross.toPolygons()}translate(o,f){throw new Error("Not implemented")}rotate(o){throw new Error("Not implemented")}rotateAround(o,f){throw new Error("Not implemented")}scale(o){throw new Error("Not implemented")}mirror(o){throw new Error("Not implemented")}add(...o){throw new Error("Not implemented")}subtract(...o){throw new Error("Not implemented")}intersect(...o){throw new Error("Not implemented")}offset(o,f="Round"){return hx(this,new Eo(this.cross.offset(o,f),this.colorHex))}hull(){return hx(this,new Eo(this.cross.hull(),this.colorHex))}simplify(o=1e-6){return hx(this,new Eo(this.cross.simplify(o),this.colorHex))}warp(o){return hx(this,new Eo(this.cross.warp(o),this.colorHex))}extrude(o,f){throw new Error("Not implemented")}revolve(o,f){throw new Error("Not implemented")}attachTo(o,f,g,T){throw new Error("Not implemented")}onFace(o,f,g){throw new Error("Not implemented")}}function um(l){return Fd(Kqe.get(l)??null)}function By(l,o){return Pte(l,o)}function $g(l,o){return By(new Eo(s4(l,nd()),o),l)}function a4(l){return nWe(eWe.get(l)??null)}function l4(l,o){return KJ(l,o)}function r6(l){return i6(tWe.get(l)??null)}function u4(l,o){return eq(l,o)}function hx(l,o){return eq(KJ(o,a4(l)),r6(l))}function lwt(l,o,f=1e-8){if(l==null||o==null)return l==null&&o==null;for(let g=0;g<16;g+=1)if(Math.abs(l[g]-o[g])>f)return!1;return!0}function uwt(l,o,f=1e-8){if(l==null||o==null)return l==null&&o==null;if(!sT(l.source,o.source))return!1;const g=[[l.origin,o.origin],[l.u,o.u],[l.v,o.v],[l.normal,o.normal]];for(const[T,P]of g)for(let O=0;O<T.length;O+=1)if(Math.abs(T[O]-P[O])>f)return!1;return!0}function _wt(l,o,f=1e-8){return l==null||o==null?l==null&&o==null:uwt(l.workplane,o.workplane,f)&&Math.abs(l.u-o.u)<=f&&Math.abs(l.v-o.v)<=f&&Math.abs(l.protrude-o.protrude)<=f&&l.selfAnchor===o.selfAnchor}function mI(l){if(l.length===0)return null;const o=a4(l[0]);for(let f=1;f<l.length;f+=1)if(!lwt(o,a4(l[f])))return null;return o}function hI(l){if(l.length===0)return null;const o=r6(l[0]);for(let f=1;f<l.length;f+=1)if(!_wt(o,r6(l[f])))return null;return o}function fwt(l){const o=l.map(g=>Array.isArray(g)?[g[0],g[1]]:[g.x,g.y]);let f=0;for(let g=0;g<o.length;g++){const[T,P]=o[g],[O,z]=o[(g+1)%o.length];f+=(O-T)*(z+P)}return f>0&&o.reverse(),o.map(([g,T])=>[g,T])}function KS(l,o,f=!1){return $g({kind:"rect",width:l,height:o,center:f,transforms:[]})}function Nb(l,o){return $g({kind:"circle",radius:l,segments:o!=null&&o>0?o:void 0,transforms:[]})}function Zte(l,o,f,g=!1){const T=Math.min(f,l/2,o/2);return $g({kind:"roundedRect",width:l,height:o,radius:T,center:g,transforms:[]})}function Md(l){const o=fwt(l);return $g({kind:"polygon",points:o,transforms:[]})}function pwt(l,o){const f=[];for(let g=0;g<l;g++){const T=2*Math.PI*g/l-Math.PI/2;f.push([o*Math.cos(T),o*Math.sin(T)])}return Md(f)}function dwt(l,o,f=64){const g=[];for(let T=0;T<f;T++){const P=2*Math.PI*T/f;g.push([l*Math.cos(P),o*Math.sin(P)])}return Md(g)}function mwt(l,o){const f=o/2,g=KS(l-o,o,!0),T=Nb(f).translate(-(l-o)/2,0),P=Nb(f).translate((l-o)/2,0);return g.add(T).add(P)}function hwt(l,o,f){const g=[];for(let T=0;T<l*2;T++){const P=Math.PI*T/l-Math.PI/2,O=T%2===0?o:f;g.push([O*Math.cos(P),O*Math.sin(P)])}return Md(g)}function uI(l,o,f=0){const g=Db(um(l),{kind:"translate",x:o,y:f});return hx(l,g?$g(g,l.colorHex):By(new Eo(l.cross.translate(o,f),l.colorHex),null))}function dx(l,o){const f=Db(um(l),{kind:"rotate",degrees:o});return hx(l,f?$g(f,l.colorHex):By(new Eo(l.cross.rotate(o),l.colorHex),null))}function gwt(l,o,f){return uI(dx(uI(l,-f[0],-f[1]),o),f[0],f[1])}function ywt(l,o){const f=typeof o=="number"?[o,o]:o,g=Db(um(l),{kind:"scale",x:f[0],y:f[1]});return hx(l,g?$g(g,l.colorHex):By(new Eo(l.cross.scale(o),l.colorHex),null))}function vwt(l,o){const f=Db(um(l),{kind:"mirror",normalX:o[0],normalY:o[1]});return hx(l,f?$g(f,l.colorHex):By(new Eo(l.cross.mirror(o),l.colorHex),null))}Eo.prototype.translate=function(l,o=0){return uI(this,l,o)};Eo.prototype.rotate=function(l){return dx(this,l)};Eo.prototype.rotateAround=function(l,o){return gwt(this,l,o)};Eo.prototype.scale=function(l){return ywt(this,l)};Eo.prototype.mirror=function(l){return vwt(this,l)};function V1(l,o,f){return{name:l,start:o,end:f,query:{kind:"tracked-edge",edgeName:l,selector:"edge"}}}class po{constructor(o,f,g,T){this.shape=o,this.topology=f,this.baseHeight=g,this.extrudeUp=T,mne(this.shape,Swt(this.topology),{merge:!0})}face(o){var T;const f=this.topology.faces.get(o);if(!f){const P=[...this.topology.faces.keys()].join(", ");throw new Error(`Face "${o}" not found. Available: ${P}`)}const g=Qte(this.shape);return{...f,normal:[f.normal[0],f.normal[1],f.normal[2]],center:[f.center[0],f.center[1],f.center[2]],query:iu({kind:"tracked-face",faceName:o,owner:Sp(g??((T=f.query)==null?void 0:T.owner))}),uAxis:f.uAxis?[f.uAxis[0],f.uAxis[1],f.uAxis[2]]:void 0,vAxis:f.vAxis?[f.vAxis[0],f.vAxis[1],f.vAxis[2]]:void 0}}edge(o){var T;const f=this.topology.edges.get(o);if(!f){const P=[...this.topology.edges.keys()].join(", ");throw new Error(`Edge "${o}" not found. Available: ${P}`)}const g=Qte(this.shape);return{...f,start:[f.start[0],f.start[1],f.start[2]],end:[f.end[0],f.end[1],f.end[2]],query:wl({kind:"tracked-edge",edgeName:o,selector:"edge",owner:Sp(g??((T=f.query)==null?void 0:T.owner))})}}faceNames(){return[...this.topology.faces.keys()]}edgeNames(){return[...this.topology.edges.keys()]}clone(){return new po(this.shape.clone(),Fbe(this.topology),this.baseHeight,this.extrudeUp)}duplicate(){return this.clone()}geometryInfo(){const o=this.shape.geometryInfo(),f=this.topology.faces.size>0||this.topology.edges.size>0;return{...o,topology:f?"synthetic":o.topology}}withReferences(o){return new po(this.shape.withReferences(o),Fbe(this.topology),this.baseHeight,this.extrudeUp)}referenceNames(o){return this.shape.referenceNames(o)}referencePoint(o){return this.shape.referencePoint(o)}placeReference(o,f,g){return new po(this.shape.placeReference(o,f,g),Fbe(this.topology),this.baseHeight,this.extrudeUp)}translate(o,f,g){const T=bwt(this.topology,o,f,g);return new po(this.shape.translate(o,f,g),T,this.baseHeight,this.extrudeUp)}moveTo(o,f,g){const T=this.shape.boundingBox();return this.translate(o-T.min[0],f-T.min[1],g-T.min[2])}moveToLocal(o,f,g,T){const O=(o instanceof po?o.toShape():o).boundingBox();return this.moveTo(O.min[0]+f,O.min[1]+g,O.min[2]+T)}moveBy(o,f,g){return this.translate(o,f,g)}rotateAroundEdge(o,f){const g=this.edge(o),[T,P,O]=g.start,z=g.end[0]-T,H=g.end[1]-P,re=g.end[2]-O,te=Math.sqrt(z*z+H*H+re*re)||1,W=z/te,Ee=H/te,se=re/te,me=f*Math.PI/180,Xe=Math.cos(me),it=Math.sin(me),at=1-Xe,It=at*W*W+Xe,tn=at*W*Ee-it*se,At=at*W*se+it*Ee,mt=at*W*Ee+it*se,ht=at*Ee*Ee+Xe,xn=at*Ee*se-it*W,Pn=at*W*se-it*Ee,$r=at*Ee*se+it*W,zn=at*se*se+Xe,ii=-It*T-tn*P-At*O+T,Gr=-mt*T-ht*P-xn*O+P,mn=-Pn*T-$r*P-zn*O+O,$s=[It,mt,Pn,0,tn,ht,$r,0,At,xn,zn,0,ii,Gr,mn,1],is=this.shape.transform($s);return new po(is,{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}rotate(o,f,g){return new po(this.shape.rotate(o,f,g),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}transform(o){return new po(this.shape.transform(o),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}pointAlong(o){return new po(this.shape.pointAlong(o),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}rotateAround(o,f,g=[0,0,0]){return new po(this.shape.rotateAround(o,f,g),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}rotateAroundTo(o,f,g,T,P={}){return new po(this.shape.rotateAroundTo(o,f,g,T,P),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}scale(o){return new po(this.shape.scale(o),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}mirror(o){return new po(this.shape.mirror(o),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}color(o){return new po(this.shape.color(o),this.topology,this.baseHeight,this.extrudeUp)}toShape(){return this.shape}attachTo(o,f,g="center",T){let P;if(typeof o._bbox=="function"&&!(o instanceof po)&&!(o instanceof na)){if(f.includes("."))throw new Error(`ShapeGroup targets only support built-in anchors, got "${f}"`);const te=o._bbox();P=t4(te.min,te.max,f)}else P=(o instanceof po,o).referencePoint(f);const O=this.referencePoint(g);let z=P[0]-O[0],H=P[1]-O[1],re=P[2]-O[2];return T&&(z+=T[0],H+=T[1],re+=T[2]),this.translate(z,H,re)}onFace(o,f,g={}){const T=g.u??0,P=g.v??0,O=g.protrude??0,z={front:"back",back:"front",left:"right",right:"left",top:"bottom",bottom:"top"},H={front:(re,te,W)=>[re,-W,te],back:(re,te,W)=>[re,W,te],left:(re,te,W)=>[-W,re,te],right:(re,te,W)=>[W,re,te],top:(re,te,W)=>[re,te,W],bottom:(re,te,W)=>[re,te,-W]};return this.attachTo(o,f,z[f],H[f](T,P,O))}subtract(...o){return this.shape.subtract(...o)}add(...o){return this.shape.add(...o)}intersect(...o){return this.shape.intersect(...o)}shell(o,f={}){return this.shape.shell(o,f)}boundingBox(){return this.shape.boundingBox()}get volume(){return this.shape.volume()}}function bwt(l,o,f,g){const T=new Map;for(const[O,z]of l.faces)T.set(O,{...z,center:[z.center[0]+o,z.center[1]+f,z.center[2]+g],query:iu(z.query),uAxis:z.uAxis?[z.uAxis[0],z.uAxis[1],z.uAxis[2]]:void 0,vAxis:z.vAxis?[z.vAxis[0],z.vAxis[1],z.vAxis[2]]:void 0});const P=new Map;for(const[O,z]of l.edges)P.set(O,{...z,start:[z.start[0]+o,z.start[1]+f,z.start[2]+g],end:[z.end[0]+o,z.end[1]+f,z.end[2]+g],query:wl(z.query)});return{faces:T,edges:P}}function Fbe(l){const o=new Map;for(const[g,T]of l.faces)o.set(g,{...T,normal:[T.normal[0],T.normal[1],T.normal[2]],center:[T.center[0],T.center[1],T.center[2]],query:iu(T.query),uAxis:T.uAxis?[T.uAxis[0],T.uAxis[1],T.uAxis[2]]:void 0,vAxis:T.vAxis?[T.vAxis[0],T.vAxis[1],T.vAxis[2]]:void 0});const f=new Map;for(const[g,T]of l.edges)f.set(g,{...T,start:[T.start[0],T.start[1],T.start[2]],end:[T.end[0],T.end[1],T.end[2]],query:wl(T.query)});return{faces:o,edges:f}}function xwt(l,o){const f=Ea.from(o),g=new Map;for(const[P,O]of l.faces)g.set(P,{...O,normal:td(f.vector(O.normal)),center:f.point(O.center),query:iu(O.query),uAxis:O.uAxis?td(f.vector(O.uAxis)):void 0,vAxis:O.vAxis?td(f.vector(O.vAxis)):void 0});const T=new Map;for(const[P,O]of l.edges)T.set(P,{...O,start:f.point(O.start),end:f.point(O.end),query:wl(O.query)});return{faces:g,edges:T}}function Swt(l){const o={};for(const[g,T]of l.faces)o[g]={center:[T.center[0],T.center[1],T.center[2]],normal:[T.normal[0],T.normal[1],T.normal[2]]};const f={};for(const[g,T]of l.edges)f[g]={start:[T.start[0],T.start[1],T.start[2]],end:[T.end[0],T.end[1],T.end[2]]};return{surfaces:o,edges:f}}function rWe(l,o,f=!0,g=0){const T=new Map,P=new Map,[O,z,H,re]=l.vertices,te=g,W=g+(f?o:-o),Ee=Math.max(te,W),se=Math.min(te,W),me=l.center.x,Xe=l.center.y,it=td([z.x-O.x,z.y-O.y,0]),at=td([re.x-O.x,re.y-O.y,0]);T.set("top",{name:"top",normal:[0,0,1],center:[me,Xe,Ee],planar:!0,uAxis:it,vAxis:at}),T.set("bottom",{name:"bottom",normal:[0,0,-1],center:[me,Xe,se],planar:!0,uAxis:it,vAxis:[-at[0],-at[1],-at[2]]});const It=[["bottom",O,z],["right",z,H],["top",H,re],["left",re,O]];for(const[tn,At,mt]of It){const ht=At.midpointTo(mt),xn=mt.x-At.x,Pn=mt.y-At.y,$r=Math.sqrt(xn*xn+Pn*Pn)||1,zn=Pn/$r,ii=-xn/$r,Gr=[xn/$r,Pn/$r,0];T.set(`side-${tn}`,{name:`side-${tn}`,normal:[zn,ii,0],center:[ht.x,ht.y,(Ee+se)/2],planar:!0,uAxis:Gr,vAxis:[0,0,1]})}return P.set("bottom-bottom",V1("bottom-bottom",[O.x,O.y,se],[z.x,z.y,se])),P.set("bottom-right",V1("bottom-right",[z.x,z.y,se],[H.x,H.y,se])),P.set("bottom-top",V1("bottom-top",[H.x,H.y,se],[re.x,re.y,se])),P.set("bottom-left",V1("bottom-left",[re.x,re.y,se],[O.x,O.y,se])),P.set("top-bottom",V1("top-bottom",[O.x,O.y,Ee],[z.x,z.y,Ee])),P.set("top-right",V1("top-right",[z.x,z.y,Ee],[H.x,H.y,Ee])),P.set("top-top",V1("top-top",[H.x,H.y,Ee],[re.x,re.y,Ee])),P.set("top-left",V1("top-left",[re.x,re.y,Ee],[O.x,O.y,Ee])),P.set("vert-bl",V1("vert-bl",[O.x,O.y,se],[O.x,O.y,Ee])),P.set("vert-br",V1("vert-br",[z.x,z.y,se],[z.x,z.y,Ee])),P.set("vert-tr",V1("vert-tr",[H.x,H.y,se],[H.x,H.y,Ee])),P.set("vert-tl",V1("vert-tl",[re.x,re.y,se],[re.x,re.y,Ee])),{faces:T,edges:P}}function iWe(l,o,f=!1){const g=new Map,T=new Map,P=l.center.x,O=l.center.y,z=f?-o/2:0,H=f?o/2:o,re=Math.min(z,H),te=Math.max(z,H),W=l.radiusTop??l.radius,Ee=(Math.abs(l.radius)+Math.abs(W))/2;return g.set("top",{name:"top",normal:[0,0,1],center:[P,O,te],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0]}),g.set("bottom",{name:"bottom",normal:[0,0,-1],center:[P,O,re],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0]}),g.set("side",{name:"side",normal:[1,0,0],center:[P+Ee,O,(te+re)/2],planar:!1}),T.set("top-rim",V1("top-rim",[P+W,O,te],[P,O+W,te])),T.set("bottom-rim",V1("bottom-rim",[P+l.radius,O,re],[P,O+l.radius,re])),{faces:g,edges:T}}function Twt(l,o){const f=l.bounds(),[g,T]=f.min,[P,O]=f.max,z=(g+P)/2,H=(T+O)/2;switch(o){case"center":return[z,H];case"top-left":return[g,O];case"top-right":return[P,O];case"bottom-left":return[g,T];case"bottom-right":return[P,T];case"top":return[z,O];case"bottom":return[z,T];case"left":return[g,H];case"right":return[P,H]}}function kwt(l,o){if(typeof l._bbox=="function"){const T=l._bbox();return t4(T.min,T.max,o)}const f=l;return("toShape"in f?f.toShape():f).referencePoint(o)}function Cwt(l){if(typeof l._bbox=="function")return;const o=l,f="toShape"in o?o.toShape():o;return Sp(Qte(f)??void 0)}function bze(l){return l==="front"||l==="back"||l==="left"||l==="right"||l==="top"||l==="bottom"}function xze(l){if(!l||typeof l!="object")return!1;const o=l;return typeof o.name=="string"&&Array.isArray(o.normal)&&Array.isArray(o.center)}function wwt(l){switch(l){case"front":return{u:[1,0,0],v:[0,0,1],normal:[0,-1,0]};case"back":return{u:[-1,0,0],v:[0,0,1],normal:[0,1,0]};case"left":return{u:[0,-1,0],v:[0,0,1],normal:[-1,0,0]};case"right":return{u:[0,1,0],v:[0,0,1],normal:[1,0,0]};case"bottom":return{u:[1,0,0],v:[0,-1,0],normal:[0,0,-1]};case"top":default:return{u:[1,0,0],v:[0,1,0],normal:[0,0,1]}}}function Zee(l){if(l.planar===!1||!l.uAxis||!l.vAxis)throw new Error(`Face "${l.name}" is not planar and cannot host a sketch.`);const o=(()=>{var g;if(l.query&&l.query.kind!=="tracked-face"&&l.query.kind!=="canonical-face")return iu(l.query);const f=Sp((g=l.query)==null?void 0:g.owner);return{kind:"face-ref",faceName:l.name,owner:f}})();return{origin:[l.center[0],l.center[1],l.center[2]],u:[l.uAxis[0],l.uAxis[1],l.uAxis[2]],v:[l.vAxis[0],l.vAxis[1],l.vAxis[2]],normal:[l.normal[0],l.normal[1],l.normal[2]],source:o}}function Ewt(l,o){var T;const f=l.topology.faces.get(o);if(!f)return null;const g=Qte(l.toShape())??((T=f.query)==null?void 0:T.owner);return{...f,normal:[f.normal[0],f.normal[1],f.normal[2]],center:[f.center[0],f.center[1],f.center[2]],query:iu({kind:"tracked-face",faceName:o,owner:Sp(g??void 0)}),uAxis:f.uAxis?[f.uAxis[0],f.uAxis[1],f.uAxis[2]]:void 0,vAxis:f.vAxis?[f.vAxis[0],f.vAxis[1],f.vAxis[2]]:void 0}}function Pwt(l){return l.faceNames().filter(o=>{const f=l.topology.faces.get(o);return!!f&&f.planar!==!1&&!!f.uAxis&&!!f.vAxis})}function Dwt(l,o){const f=l instanceof Error?l.message:String(l);return f===`Face "${o}" is not available. Supported faces: none`||f.startsWith(`Face "${o}" is not available. Supported faces: `)}function rM(l,o){if(xze(l))return Zee(l);if(o==null)throw new Error("Sketch.onFace(parent, face, opts) requires a face name or FaceRef.");if(xze(o))return Zee(o);if(typeof o!="string")throw new Error("Sketch.onFace() requires a face name or FaceRef.");if(l instanceof po){const f=Ewt(l,o);if(f)return{...Zee(f),source:iu(f.query)??{kind:"tracked-face",faceName:o}}}if(l instanceof na&&c4(l))try{return Zee(l.face(o))}catch(f){if(!bze(o)||!Dwt(f,o))throw f}if(bze(o)){const f=wwt(o);return{origin:kwt(l,o),u:f.u,v:f.v,normal:f.normal,source:{kind:"canonical-face",face:o,owner:Cwt(l)}}}if(l instanceof po){const f=Pwt(l).join(", ")||"none";throw new Error(`Face "${o}" not found or is not planar. Available planar faces: ${f}`)}throw new Error(`Named face "${o}" requires a TrackedShape parent or a FaceRef target.`)}function Awt(l,o,f,g){return[l[0],l[1],l[2],0,o[0],o[1],o[2],0,f[0],f[1],f[2],0,g[0],g[1],g[2],1]}function Nwt(l,o){const[f,g]=Twt(l,o.selfAnchor),T=[o.workplane.origin[0]+o.workplane.u[0]*o.u+o.workplane.v[0]*o.v+o.workplane.normal[0]*o.protrude,o.workplane.origin[1]+o.workplane.u[1]*o.u+o.workplane.v[1]*o.v+o.workplane.normal[1]*o.protrude,o.workplane.origin[2]+o.workplane.u[2]*o.u+o.workplane.v[2]*o.v+o.workplane.normal[2]*o.protrude],P=Awt(o.workplane.u,o.workplane.v,o.workplane.normal,T);return Ea.translation(-f,-g,0).mul(P).toArray()}function Iwt(l){if(!l||typeof l!="object")return!1;const o=l;return typeof o.name=="string"&&Array.isArray(o.normal)&&Array.isArray(o.center)}function Fwt(l,o,f,g={}){const T=Iwt(o);if(T&&typeof f=="string")throw new Error("Sketch.onFace(faceRef, opts) accepts options as the second argument, not a face name.");const P=T?rM(o):rM(o,f),O=(T?f:g)??{},z={workplane:P,u:O.u??0,v:O.v??0,protrude:O.protrude??0,selfAnchor:O.selfAnchor??"center"};return u4(l4(l.clone(),Nwt(l,z)),z)}Eo.prototype.onFace=function(l,o,f={}){return Fwt(this,l,o,f)};function gI(l,o,f,g){return aqe({apiName:l,inputs:o,minCount:f,itemName:"sketch",usage:g,coerce:T=>{if(T instanceof Eo)return T;throw new Error(`expected a Sketch, got ${Vte(T)}`)}})}function Owt(l,...o){const f=[l,...gI("Sketch.add()",o,1,"Use sketch.add(other1, other2) or sketch.add([other1, other2]).")],g=iT("union",f.map(T=>um(T)));return u4(l4(g?$g(g,l.colorHex):By(new Eo(nd().CrossSection.union(f.map(T=>T.cross)),l.colorHex),null),mI(f)),hI(f))}function Mwt(l,...o){const f=[l,...gI("Sketch.subtract()",o,1,"Use sketch.subtract(other1, other2) or sketch.subtract([other1, other2]).")],g=iT("difference",f.map(T=>um(T)));return u4(l4(g?$g(g,l.colorHex):By(new Eo(nd().CrossSection.difference(f.map(T=>T.cross)),l.colorHex),null),mI(f)),hI(f))}function Lwt(l,...o){const f=[l,...gI("Sketch.intersect()",o,1,"Use sketch.intersect(other1, other2) or sketch.intersect([other1, other2]).")],g=iT("intersection",f.map(T=>um(T)));return u4(l4(g?$g(g,l.colorHex):By(new Eo(nd().CrossSection.intersection(f.map(T=>T.cross)),l.colorHex),null),mI(f)),hI(f))}function Ug(...l){const o=gI("union2d()",l,1,"Use union2d(sketch1, sketch2) or union2d([sketch1, sketch2]).");if(o.length===0)throw new Error("union2d requires at least one sketch");if(o.length===1)return o[0];const f=iT("union",o.map(g=>um(g)));return u4(l4(f?$g(f,o[0].colorHex):By(new Eo(nd().CrossSection.union(o.map(g=>g.cross)),o[0].colorHex),null),mI(o)),hI(o))}function Z1(...l){const o=gI("difference2d()",l,2,"Use difference2d(base, cutter1, cutter2) or difference2d([base, cutter1, cutter2]).");if(o.length<2)throw new Error("difference2d requires at least two sketches");const f=iT("difference",o.map(g=>um(g)));return u4(l4(f?$g(f,o[0].colorHex):By(new Eo(nd().CrossSection.difference(o.map(g=>g.cross)),o[0].colorHex),null),mI(o)),hI(o))}function Rwt(...l){const o=gI("intersection2d()",l,2,"Use intersection2d(sketch1, sketch2) or intersection2d([sketch1, sketch2]).");if(o.length<2)throw new Error("intersection2d requires at least two sketches");const f=iT("intersection",o.map(g=>um(g)));return u4(l4(f?$g(f,o[0].colorHex):By(new Eo(nd().CrossSection.intersection(o.map(g=>g.cross)),o[0].colorHex),null),mI(o)),hI(o))}function jwt(...l){const o=gI("hull2d()",l,1,"Use hull2d(sketch1, sketch2) or hull2d([sketch1, sketch2]).");if(o.length===0)throw new Error("hull2d requires at least one sketch");const f=iqe(o.map(g=>um(g)));return u4(l4(f?$g(f,o[0].colorHex):By(new Eo(nd().CrossSection.hull(o.map(g=>g.cross)),o[0].colorHex),null),mI(o)),hI(o))}Eo.prototype.add=function(...l){return Owt(this,...l)};Eo.prototype.subtract=function(...l){return Mwt(this,...l)};Eo.prototype.intersect=function(...l){return Lwt(this,...l)};function Bwt(l,o,f="Round"){const g=f==="Round"?rqe(um(l),o,"Round"):null;return hx(l,g?$g(g,l.colorHex):By(new Eo(l.cross.offset(o,f),l.colorHex),null))}function zwt(l){const o=iqe([um(l)]);return hx(l,o?$g(o,l.colorHex):By(new Eo(l.cross.hull(),l.colorHex),null))}function Jwt(l,o=1e-6){return hx(l,new Eo(l.cross.simplify(o),l.colorHex))}function qwt(l,o){return hx(l,new Eo(l.cross.warp(o),l.colorHex))}Eo.prototype.offset=function(l,o="Round"){return Bwt(this,l,o)};Eo.prototype.hull=function(){return zwt(this)};Eo.prototype.simplify=function(l=1e-6){return Jwt(this,l)};Eo.prototype.warp=function(l){return qwt(this,l)};function Wwt(l,o,f){const g=new Map,T=new Map,P=l.bounds(),O=(P.min[0]+P.max[0])/2,z=(P.min[1]+P.max[1])/2,H=f?-o/2:0,re=f?o/2:o;return g.set("top",{name:"top",normal:[0,0,1],center:[O,z,re],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0]}),g.set("bottom",{name:"bottom",normal:[0,0,-1],center:[O,z,H],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0]}),g.set("side",{name:"side",normal:[1,0,0],center:[P.max[0],z,(re+H)/2],planar:!1}),{faces:g,edges:T}}function aT(l,o,f){const g=typeof(f==null?void 0:f.scaleTop)=="number"?[f.scaleTop,f.scaleTop]:f==null?void 0:f.scaleTop,T=((f==null?void 0:f.twist)==null||f.twist===0)&&((f==null?void 0:f.divisions)==null||f.divisions===0)?(()=>{const Ee=um(l);return Ee?{kind:"extrude",profile:Ee,height:o,center:(f==null?void 0:f.center)??!1,scaleTop:g}:null})():null,P=a4(l),O=r6(l),z=T&&P&&O?G1(T,{kind:"workplanePlacement",matrix:P,placement:O}):T,H=s6(z,"extrude"),re=H?M_(H,l.colorHex,{fidelity:"kernel-native",sources:["extrude"]}):gne(new na(l.cross.extrude(o,(f==null?void 0:f.divisions)??0,(f==null?void 0:f.twist)??0,g,(f==null?void 0:f.center)??!1),l.colorHex,{fidelity:"kernel-native",sources:["extrude"]}),null),te=Wwt(l,o,(f==null?void 0:f.center)??!1);if(!P)return new po(re,te,0,!0);const W=xwt(te,P);return H&&O?new po(re,W,0,!0):new po(re.transform(P),W,0,!0)}function Vwt(l,o=360,f){const g=(()=>{const re=um(l);return re?{kind:"revolve",profile:re,degrees:o,segments:f!=null&&f>0?f:void 0}:null})(),T=a4(l),P=r6(l),O=g&&T&&P?G1(g,{kind:"workplanePlacement",matrix:T,placement:P}):g,z=s6(O,"revolve"),H=z?M_(z,l.colorHex,{fidelity:"kernel-native",sources:["revolve"]}):gne(new na(l.cross.revolve(f??0,o),l.colorHex,{fidelity:"kernel-native",sources:["revolve"]}),null);return!T||z&&P?H:H.transform(T)}Eo.prototype.extrude=function(l,o){return aT(this,l,o)};Eo.prototype.revolve=function(l=360,o){return Vwt(this,l,o)};class sWe{constructor(){tu(this,"points",[]);tu(this,"x",0);tu(this,"y",0)}moveTo(o,f){return this.x=o,this.y=f,this.points.push([o,f]),this}lineTo(o,f){return this.x=o,this.y=f,this.points.push([o,f]),this}lineH(o){return this.lineTo(this.x+o,this.y)}lineV(o){return this.lineTo(this.x,this.y+o)}lineAngled(o,f){const g=f*Math.PI/180;return this.lineTo(this.x+o*Math.cos(g),this.y+o*Math.sin(g))}close(){if(this.points.length<3)throw new Error("Path needs at least 3 points");const o=this.points;let f=0;for(let g=0;g<o.length;g++){const[T,P]=o[g],[O,z]=o[(g+1)%o.length];f+=(O-T)*(z+P)}return f>0&&o.reverse(),Md(o)}stroke(o,f="Square"){if(this.points.length<2)throw new Error("Stroke needs at least 2 points");const g=o/2,T=this.points,P=T.length,O=[];for(let Ee=0;Ee<P-1;Ee++){const se=T[Ee+1][0]-T[Ee][0],me=T[Ee+1][1]-T[Ee][1],Xe=Math.sqrt(se*se+me*me);O.push([-me/Xe,se/Xe])}const z=[],H=[];for(let Ee=0;Ee<P;Ee++){const[se,me]=T[Ee];if(Ee===0||Ee===P-1){const Xe=O[Ee===0?0:P-2];z.push([se+Xe[0]*g,me+Xe[1]*g]),H.push([se-Xe[0]*g,me-Xe[1]*g])}else{const Xe=O[Ee-1],it=O[Ee];let at=Xe[0]+it[0],It=Xe[1]+it[1],tn=Math.sqrt(at*at+It*It);tn<1e-9&&(at=Xe[0],It=Xe[1],tn=1),at/=tn,It/=tn;const At=g/(at*Xe[0]+It*Xe[1]);z.push([se+at*At,me+It*At]),H.push([se-at*At,me-It*At])}}const re=[...z,...H.reverse()];let te=0;for(let Ee=0;Ee<re.length;Ee++){const[se,me]=re[Ee],[Xe,it]=re[(Ee+1)%re.length];te+=(Xe-se)*(it+me)}te>0&&re.reverse();let W=Md(re);return f==="Round"&&(W=W.offset(-g/2,"Round").offset(g/2,"Round")),W}}function Uwt(){return new sWe}function dxe(l,o,f="Square"){const g=new sWe;g.moveTo(l[0][0],l[0][1]);for(let T=1;T<l.length;T++)g.lineTo(l[T][0],l[T][1]);return g.stroke(o,f)}function Sze(l,o){const f=l.bounds(),[g,T]=f.min,[P,O]=f.max,z=(g+P)/2,H=(T+O)/2;switch(o){case"center":return[z,H];case"top-left":return[g,O];case"top-right":return[P,O];case"bottom-left":return[g,T];case"bottom-right":return[P,T];case"top":return[z,O];case"bottom":return[z,T];case"left":return[g,H];case"right":return[P,H]}}function $wt(l,o,f,g="center",T){const P=Sze(o,f),O=Sze(l,g);let z=P[0]-O[0],H=P[1]-O[1];return T&&(z+=T[0],H+=T[1]),l.translate(z,H)}Eo.prototype.attachTo=function(l,o,f="center",g){return $wt(this,l,o,f,g)};const Kte=.001,aWe=l=>l*Math.PI/180,YN=(l,o)=>{const f=o.x-l.x,g=o.y-l.y;return Math.sqrt(f*f+g*g)},H1=(l,o)=>[(l.x+o.x)/2,(l.y+o.y)/2],Tze=(l,o)=>{const f=YN(l,o)||1;return[(o.x-l.x)/f,(o.y-l.y)/f]},kze=(l,o)=>Math.atan2(o.y-l.y,o.x-l.x),Hwt=l=>{let o=l;for(;o>Math.PI;)o-=Math.PI*2;for(;o<-Math.PI;)o+=Math.PI*2;return o},oWe=(l,o,f)=>{const g=f.x-o.x,T=f.y-o.y,P=g*g+T*T;if(P<1e-9)return[o.x,o.y];const O=((l.x-o.x)*g+(l.y-o.y)*T)/P;return[o.x+O*g,o.y+O*T]},Cze=(l,o,f)=>{const g=oWe(l,o,f);return[2*g[0]-l.x,2*g[1]-l.y]},cWe=l=>({points:l.points.map(o=>({...o})),lines:l.lines.map(o=>({...o})),circles:l.circles.map(o=>({...o})),loops:l.loops.map(o=>o.type==="poly"?{type:"poly",points:[...o.points]}:{type:"circle",circle:o.circle}),constraints:l.constraints.map(o=>({...o})),rejectedConstraints:l.rejectedConstraints.map(o=>({...o}))}),Gwt=l=>{switch(l){case"coincident":return"COINC";case"horizontal":return"H";case"vertical":return"V";case"parallel":return"PAR";case"perpendicular":return"PERP";case"tangent":return"TAN";case"equal":return"EQ";case"symmetric":return"SYM";case"concentric":return"CONC";case"collinear":return"COLL";case"fixed":return"FIX";case"distance":return"DIST";case"length":return"LEN";case"angle":return"ANG";case"radius":return"R";case"diameter":return"DIA";case"hDistance":return"HD";case"vDistance":return"VD";default:return"C"}},Xwt=l=>l==="distance"||l==="length"||l==="angle"||l==="radius"||l==="diameter"||l==="hDistance"||l==="vDistance",Ywt=l=>{if(l.type==="distance"||l.type==="length"||l.type==="angle"||l.type==="radius"||l.type==="diameter"||l.type==="hDistance"||l.type==="vDistance")return l.value},Qwt=(l,o)=>{l.type==="distance"&&(l.value=o),l.type==="length"&&(l.value=o),l.type==="angle"&&(l.value=o),l.type==="radius"&&(l.value=o),l.type==="diameter"&&(l.value=o),l.type==="hDistance"&&(l.value=o),l.type==="vDistance"&&(l.value=o)},wze=(l,o)=>{const f=new Map(l.points.map(O=>[O.id,O])),g=new Map(l.lines.map(O=>[O.id,O])),T=new Map(l.circles.map(O=>[O.id,O])),P=[];return l.constraints.forEach(O=>{let z=[0,0];if(O.type==="coincident"||O.type==="distance"||O.type==="hDistance"||O.type==="vDistance"){const H=f.get(O.a),re=f.get(O.b);H&&re&&(z=H1(H,re))}else if(O.type==="horizontal"||O.type==="vertical"||O.type==="length"){const H=g.get(O.line);if(H){const re=f.get(H.a),te=f.get(H.b);re&&te&&(z=H1(re,te))}}else if(O.type==="parallel"||O.type==="perpendicular"||O.type==="equal"||O.type==="angle"){const H=g.get(O.a),re=g.get(O.b);if(H&&re){const te=f.get(H.a),W=f.get(H.b),Ee=f.get(re.a),se=f.get(re.b);if(te&&W&&Ee&&se){const me=H1(te,W),Xe=H1(Ee,se);z=[(me[0]+Xe[0])/2,(me[1]+Xe[1])/2]}}}else if(O.type==="radius"||O.type==="diameter"){const H=T.get(O.circle);if(H){const re=f.get(H.center);re&&(z=[re.x+H.radius,re.y])}}else if(O.type==="concentric"){const H=T.get(O.a),re=T.get(O.b);if(H&&re){const te=f.get(H.center),W=f.get(re.center);te&&W&&(z=H1(te,W))}}else if(O.type==="collinear"){const H=f.get(O.point);H&&(z=[H.x,H.y])}else if(O.type==="fixed"){const H=f.get(O.point);H&&(z=[H.x,H.y])}else if(O.type==="symmetric"){const H=f.get(O.a),re=f.get(O.b);H&&re&&(z=H1(H,re))}else if(O.type==="tangent"){if(O.line&&O.circle){const H=g.get(O.line),re=T.get(O.circle);if(H&&re){const te=f.get(H.a),W=f.get(H.b);te&&W&&(z=H1(te,W))}}else if(O.a&&O.b){const H=T.get(O.a),re=T.get(O.b);if(H&&re){const te=f.get(H.center),W=f.get(re.center);te&&W&&(z=H1(te,W))}}}P.push({id:O.id,type:O.type,label:Gwt(O.type),position:z,value:Ywt(O),isDimension:Xwt(O.type),isConflicting:o.has(O.id)})}),P},Zwt=l=>{const o=[];if(l.loops.forEach(f=>{if(f.type==="poly"){const g=f.points.map(T=>{const P=l.points.find(O=>O.id===T);if(!P)throw new Error(`Missing point ${T}`);return[P.x,P.y]});g.length>=3&&o.push(Md(g))}else if(f.type==="circle"){const g=l.circles.find(O=>O.id===f.circle);if(!g)throw new Error(`Missing circle ${f.circle}`);const T=l.points.find(O=>O.id===g.center);if(!T)throw new Error(`Missing center ${g.center}`);const P=new Eo(nd().CrossSection.circle(g.radius,g.segments));o.push(P.translate(T.x,T.y))}}),o.length===0)throw new Error("Constrained sketch needs at least one closed loop");return Ug(...o)},Kwt=l=>{const o=new Map(l.points.map(T=>[T.id,T])),f=l.lines.filter(T=>T.construction).map(T=>{const P=o.get(T.a),O=o.get(T.b);return!P||!O?null:{a:[P.x,P.y],b:[O.x,O.y]}}).filter(T=>T!==null),g=l.circles.filter(T=>T.construction).map(T=>{const P=o.get(T.center);return P?{center:[P.x,P.y],radius:T.radius}:null}).filter(T=>T!==null);return{lines:f,circles:g}},eEt=(l,o)=>{l.fixed=!0,l.x=o.x,l.y=o.y},lWe=(l,o)=>{const f=o.iterations??40,g=o.tolerance??Kte,T=new Map(l.points.map(re=>[re.id,re])),P=new Map(l.lines.map(re=>[re.id,re])),O=new Map(l.circles.map(re=>[re.id,re]));l.constraints.forEach(re=>{if(re.type==="fixed"){const te=T.get(re.point);te&&eEt(te,re)}});const z=(re,te,W)=>re.fixed?!1:(re.x+=te,re.y+=W,!0);let H=0;for(let re=0;re<f&&(H=0,l.constraints.forEach(te=>{let W=0;if(te.type==="coincident"){const Ee=T.get(te.a),se=T.get(te.b);if(!Ee||!se)return;const me=se.x-Ee.x,Xe=se.y-Ee.y;if(W=Math.sqrt(me*me+Xe*Xe),W<=g||Ee.fixed&&se.fixed)return;if(Ee.fixed){se.x=Ee.x,se.y=Ee.y;return}if(se.fixed){Ee.x=se.x,Ee.y=se.y;return}const it=(Ee.x+se.x)/2,at=(Ee.y+se.y)/2;Ee.x=it,Ee.y=at,se.x=it,se.y=at}if(te.type==="horizontal"){const Ee=P.get(te.line);if(!Ee)return;const se=T.get(Ee.a),me=T.get(Ee.b);if(!se||!me||(W=Math.abs(me.y-se.y),W<=g)||se.fixed&&me.fixed)return;const Xe=(se.y+me.y)/2;se.fixed||(se.y=Xe),me.fixed||(me.y=Xe)}if(te.type==="vertical"){const Ee=P.get(te.line);if(!Ee)return;const se=T.get(Ee.a),me=T.get(Ee.b);if(!se||!me||(W=Math.abs(me.x-se.x),W<=g)||se.fixed&&me.fixed)return;const Xe=(se.x+me.x)/2;se.fixed||(se.x=Xe),me.fixed||(me.x=Xe)}if(te.type==="parallel"||te.type==="perpendicular"||te.type==="angle"){const Ee=P.get(te.a),se=P.get(te.b);if(!Ee||!se)return;const me=T.get(Ee.a),Xe=T.get(Ee.b),it=T.get(se.a),at=T.get(se.b);if(!me||!Xe||!it||!at)return;const It=kze(me,Xe),tn=te.type==="parallel"?It:te.type==="perpendicular"?It+Math.PI/2:It+aWe(te.value),At=kze(it,at),mt=Hwt(At-tn);if(W=Math.abs(mt),W<=g||it.fixed&&at.fixed)return;const ht=YN(it,at)||1,xn=[Math.cos(tn),Math.sin(tn)];if(it.fixed)at.x=it.x+xn[0]*ht,at.y=it.y+xn[1]*ht;else if(at.fixed)it.x=at.x-xn[0]*ht,it.y=at.y-xn[1]*ht;else{const Pn=H1(it,at);it.x=Pn[0]-xn[0]*ht/2,it.y=Pn[1]-xn[1]*ht/2,at.x=Pn[0]+xn[0]*ht/2,at.y=Pn[1]+xn[1]*ht/2}}if(te.type==="equal"){const Ee=P.get(te.a),se=P.get(te.b);if(!Ee||!se)return;const me=T.get(Ee.a),Xe=T.get(Ee.b),it=T.get(se.a),at=T.get(se.b);if(!me||!Xe||!it||!at)return;const It=YN(me,Xe),tn=YN(it,at)||1;if(W=Math.abs(tn-It),W<=g||it.fixed&&at.fixed)return;const At=Tze(it,at);if(it.fixed)at.x=it.x+At[0]*It,at.y=it.y+At[1]*It;else if(at.fixed)it.x=at.x-At[0]*It,it.y=at.y-At[1]*It;else{const mt=H1(it,at);it.x=mt[0]-At[0]*It/2,it.y=mt[1]-At[1]*It/2,at.x=mt[0]+At[0]*It/2,at.y=mt[1]+At[1]*It/2}}if(te.type==="distance"){const Ee=T.get(te.a),se=T.get(te.b);if(!Ee||!se)return;const me=YN(Ee,se)||1;if(W=Math.abs(me-te.value),W<=g)return;const Xe=[(se.x-Ee.x)/me,(se.y-Ee.y)/me];if(Ee.fixed&&se.fixed)return;if(Ee.fixed)se.x=Ee.x+Xe[0]*te.value,se.y=Ee.y+Xe[1]*te.value;else if(se.fixed)Ee.x=se.x-Xe[0]*te.value,Ee.y=se.y-Xe[1]*te.value;else{const it=H1(Ee,se);Ee.x=it[0]-Xe[0]*te.value/2,Ee.y=it[1]-Xe[1]*te.value/2,se.x=it[0]+Xe[0]*te.value/2,se.y=it[1]+Xe[1]*te.value/2}}if(te.type==="length"){const Ee=P.get(te.line);if(!Ee)return;const se=T.get(Ee.a),me=T.get(Ee.b);if(!se||!me)return;const Xe=YN(se,me)||1;if(W=Math.abs(Xe-te.value),W<=g)return;const it=Tze(se,me);if(se.fixed&&me.fixed)return;if(se.fixed)me.x=se.x+it[0]*te.value,me.y=se.y+it[1]*te.value;else if(me.fixed)se.x=me.x-it[0]*te.value,se.y=me.y-it[1]*te.value;else{const at=H1(se,me);se.x=at[0]-it[0]*te.value/2,se.y=at[1]-it[1]*te.value/2,me.x=at[0]+it[0]*te.value/2,me.y=at[1]+it[1]*te.value/2}}if(te.type==="radius"||te.type==="diameter"){const Ee=O.get(te.circle);if(!Ee)return;const se=te.type==="radius"?te.value:te.value/2;if(W=Math.abs(Ee.radius-se),W<=g)return;Ee.fixedRadius||(Ee.radius=se)}if(te.type==="hDistance"){const Ee=T.get(te.a),se=T.get(te.b);if(!Ee||!se||(W=Math.abs(se.x-Ee.x-te.value),W<=g)||Ee.fixed&&se.fixed)return;if(Ee.fixed)se.x=Ee.x+te.value;else if(se.fixed)Ee.x=se.x-te.value;else{const me=(Ee.x+se.x)/2;Ee.x=me-te.value/2,se.x=me+te.value/2}}if(te.type==="vDistance"){const Ee=T.get(te.a),se=T.get(te.b);if(!Ee||!se||(W=Math.abs(se.y-Ee.y-te.value),W<=g)||Ee.fixed&&se.fixed)return;if(Ee.fixed)se.y=Ee.y+te.value;else if(se.fixed)Ee.y=se.y-te.value;else{const me=(Ee.y+se.y)/2;Ee.y=me-te.value/2,se.y=me+te.value/2}}if(te.type==="concentric"){const Ee=O.get(te.a),se=O.get(te.b);if(!Ee||!se)return;const me=T.get(Ee.center),Xe=T.get(se.center);if(!me||!Xe)return;const it=Xe.x-me.x,at=Xe.y-me.y;if(W=Math.sqrt(it*it+at*at),W<=g||me.fixed&&Xe.fixed)return;if(me.fixed)Xe.x=me.x,Xe.y=me.y;else if(Xe.fixed)me.x=Xe.x,me.y=Xe.y;else{const It=H1(me,Xe);me.x=It[0],me.y=It[1],Xe.x=It[0],Xe.y=It[1]}}if(te.type==="collinear"){const Ee=T.get(te.point),se=P.get(te.line);if(!Ee||!se)return;const me=T.get(se.a),Xe=T.get(se.b);if(!me||!Xe)return;const it=oWe(Ee,me,Xe);if(W=Math.sqrt((Ee.x-it[0])**2+(Ee.y-it[1])**2),W<=g)return;if(!Ee.fixed)Ee.x=it[0],Ee.y=it[1];else{const at=it[0]-Ee.x,It=it[1]-Ee.y;me.fixed||z(me,-at,-It),Xe.fixed||z(Xe,-at,-It)}}if(te.type==="symmetric"){const Ee=T.get(te.a),se=T.get(te.b),me=P.get(te.axis);if(!Ee||!se||!me)return;const Xe=T.get(me.a),it=T.get(me.b);if(!Xe||!it)return;const at=Cze(Ee,Xe,it),It=Cze(se,Xe,it);if(W=Math.sqrt((se.x-at[0])**2+(se.y-at[1])**2),W<=g||Ee.fixed&&se.fixed)return;Ee.fixed?(se.x=at[0],se.y=at[1]):se.fixed?(Ee.x=It[0],Ee.y=It[1]):(se.x=at[0],se.y=at[1])}if(te.type==="tangent"){if(te.line&&te.circle){const Ee=P.get(te.line),se=O.get(te.circle);if(!Ee||!se)return;const me=T.get(Ee.a),Xe=T.get(Ee.b),it=T.get(se.center);if(!me||!Xe||!it)return;const at=Xe.x-me.x,It=Xe.y-me.y,tn=Math.sqrt(at*at+It*It)||1,At=-It/tn,mt=at/tn,ht=(it.x-me.x)*At+(it.y-me.y)*mt;if(W=Math.abs(Math.abs(ht)-se.radius),W<=g)return;const xn=ht>0?ht-se.radius:ht+se.radius;!me.fixed||!Xe.fixed?(me.fixed||(me.x+=At*-xn,me.y+=mt*-xn),Xe.fixed||(Xe.x+=At*-xn,Xe.y+=mt*-xn)):it.fixed||(it.x+=At*-xn,it.y+=mt*-xn)}else if(te.a&&te.b){const Ee=O.get(te.a),se=O.get(te.b);if(!Ee||!se)return;const me=T.get(Ee.center),Xe=T.get(se.center);if(!me||!Xe)return;const it=Ee.radius+se.radius,at=YN(me,Xe)||1;if(W=Math.abs(at-it),W<=g)return;const It=[(Xe.x-me.x)/at,(Xe.y-me.y)/at];if(me.fixed&&Xe.fixed)return;if(me.fixed)Xe.x=me.x+It[0]*it,Xe.y=me.y+It[1]*it;else if(Xe.fixed)me.x=Xe.x-It[0]*it,me.y=Xe.y-It[1]*it;else{const tn=H1(me,Xe);me.x=tn[0]-It[0]*it/2,me.y=tn[1]-It[1]*it/2,Xe.x=tn[0]+It[0]*it/2,Xe.y=tn[1]+It[1]*it/2}}}H=Math.max(H,W)}),!(H<=g));re+=1);return{maxError:H}},tEt=(l,o,f)=>{if(o>f*5)return"over";const g=new Map;return l.points.forEach(P=>g.set(P.id,0)),l.constraints.forEach(P=>{if(P.type==="fixed"){const O=g.get(P.point)??0;g.set(P.point,O+2);return}if(P.type==="coincident"||P.type==="distance"||P.type==="hDistance"||P.type==="vDistance"){g.set(P.a,(g.get(P.a)??0)+1),g.set(P.b,(g.get(P.b)??0)+1);return}if(P.type==="collinear"){g.set(P.point,(g.get(P.point)??0)+1);return}if(P.type==="symmetric"){g.set(P.a,(g.get(P.a)??0)+1),g.set(P.b,(g.get(P.b)??0)+1);return}if(P.type==="horizontal"||P.type==="vertical"||P.type==="length"){const O=l.lines.find(z=>z.id===P.line);O&&(g.set(O.a,(g.get(O.a)??0)+1),g.set(O.b,(g.get(O.b)??0)+1));return}if(P.type==="parallel"||P.type==="perpendicular"||P.type==="equal"||P.type==="angle"){const O=l.lines.find(H=>H.id===P.a),z=l.lines.find(H=>H.id===P.b);O&&(g.set(O.a,(g.get(O.a)??0)+1),g.set(O.b,(g.get(O.b)??0)+1)),z&&(g.set(z.a,(g.get(z.a)??0)+1),g.set(z.b,(g.get(z.b)??0)+1));return}}),l.points.some(P=>!P.fixed&&(g.get(P.id)??0)<2)?"under":"fully"};class v2e extends Eo{constructor(o,f,g){super(o),this.constraintMeta=f,this.definition=g}withUpdatedConstraint(o,f){const g=cWe(this.definition),T=g.constraints.find(P=>P.id===o);return T?(Qwt(T,f),uWe(g)):this}}class nEt{constructor(){tu(this,"points",[]);tu(this,"lines",[]);tu(this,"circles",[]);tu(this,"constraints",[]);tu(this,"loops",[]);tu(this,"rejectedConstraints",[]);tu(this,"cursor",null);tu(this,"loopStart",null);tu(this,"nextId",1)}point(o,f,g=!1){const T=`pt-${this.nextId++}`;return this.points.push({id:T,x:o,y:f,fixed:g}),T}pointAt(o){const f=this.points[o];if(!f)throw new Error(`Point index ${o} out of range`);return f.id}line(o,f,g=!1){const T=`ln-${this.nextId++}`;return this.lines.push({id:T,a:o,b:f,construction:g}),T}lineAt(o){const f=this.lines[o];if(!f)throw new Error(`Line index ${o} out of range`);return f.id}circle(o,f,g=!1,T=48){const P=`c-${this.nextId++}`;return this.circles.push({id:P,center:o,radius:f,construction:g,fixedRadius:!1,segments:T}),g||this.loops.push({type:"circle",circle:P}),P}circleAt(o){const f=this.circles[o];if(!f)throw new Error(`Circle index ${o} out of range`);return f.id}moveTo(o,f){const g=this.point(o,f);return this.cursor=g,this.loopStart=g,this.loops.push({type:"poly",points:[g]}),this}lineTo(o,f){if(!this.cursor)return this.moveTo(o,f);const g=this.point(o,f);this.line(this.cursor,g);const T=this.loops[this.loops.length-1];return T&&T.type==="poly"&&T.points.push(g),this.cursor=g,this}lineH(o){const f=this.getPoint(this.cursor);return f?this.lineTo(f.x+o,f.y):this}lineV(o){const f=this.getPoint(this.cursor);return f?this.lineTo(f.x,f.y+o):this}lineAngled(o,f){const g=this.getPoint(this.cursor);if(!g)return this;const T=aWe(f);return this.lineTo(g.x+Math.cos(T)*o,g.y+Math.sin(T)*o)}close(){return!this.cursor||!this.loopStart||this.cursor===this.loopStart?this:(this.line(this.cursor,this.loopStart),this.cursor=this.loopStart,this)}addLoopCircle(o,f,g=48){return this.circle(o,f,!1,g),this}constrain(o){const f=`cst-${this.nextId++}`,g={...o,id:f},T=this.buildDefinition(g),{maxError:P}=lWe(T,{iterations:30,tolerance:Kte});if(P>Kte*5)return this.rejectedConstraints.push(g),this;if(g.type==="fixed"){const O=this.points.find(z=>z.id===g.point);O&&(O.fixed=!0,O.x=g.x,O.y=g.y)}return this.constraints.push(g),this}solve(o={}){return uWe(this.buildDefinition(),o)}buildDefinition(o){return{points:this.points.map(f=>({...f})),lines:this.lines.map(f=>({...f})),circles:this.circles.map(f=>({...f})),loops:this.loops.map(f=>f.type==="poly"?{type:"poly",points:[...f.points]}:{type:"circle",circle:f.circle}),constraints:o?[...this.constraints,o]:[...this.constraints],rejectedConstraints:[...this.rejectedConstraints]}}getPoint(o){return o?this.points.find(f=>f.id===o)??null:null}importPoint(o,f=!1){return this.point(o.x,o.y,f)}importLine(o,f=!1){const g=this.importPoint(o.start,f),T=this.importPoint(o.end,f);return this.line(g,T)}importRectangle(o,f=!1){const[g,T,P,O]=o.vertices.map(z=>this.importPoint(z,f));return{bottom:this.line(g,T),right:this.line(T,P),top:this.line(P,O),left:this.line(O,g),points:[g,T,P,O]}}}function rEt(){return new nEt}const uWe=(l,o={})=>{const f=cWe(l),g=o.tolerance??Kte,{maxError:T}=lWe(f,o),P=tEt(f,T,g),O=new Set(P==="over"?f.constraints.map(W=>W.id):[]),z=wze(f,O),H=wze({...f,constraints:f.rejectedConstraints},new Set(f.rejectedConstraints.map(W=>W.id))),re=Zwt(f),te=Kwt(f);return new v2e(re.cross,{status:P,maxError:T,constraints:z,rejected:H,construction:te},f)};class Q_{constructor(o,f){this.x=o,this.y=f}distanceTo(o){const f=o.x-this.x,g=o.y-this.y;return Math.sqrt(f*f+g*g)}midpointTo(o){return new Q_((this.x+o.x)/2,(this.y+o.y)/2)}translate(o,f){return new Q_(this.x+o,this.y+f)}toTuple(){return[this.x,this.y]}}function iEt(l,o){return new Q_(l,o)}class Eb{constructor(o,f){this.start=o,this.end=f}get length(){return this.start.distanceTo(this.end)}get midpoint(){return this.start.midpointTo(this.end)}get angle(){return Math.atan2(this.end.y-this.start.y,this.end.x-this.start.x)*(180/Math.PI)}get direction(){const o=this.length||1;return[(this.end.x-this.start.x)/o,(this.end.y-this.start.y)/o]}parallel(o){const[f,g]=this.direction,T=-g*o,P=f*o;return new Eb(this.start.translate(T,P),this.end.translate(T,P))}intersect(o){const f=this.start.x,g=this.start.y,T=this.end.x,P=this.end.y,O=o.start.x,z=o.start.y,H=o.end.x,re=o.end.y,te=(f-T)*(z-re)-(g-P)*(O-H);if(Math.abs(te)<1e-12)return null;const W=((f-O)*(z-re)-(g-z)*(O-H))/te;return new Q_(f+W*(T-f),g+W*(P-g))}intersectSegment(o){const f=this.start.x,g=this.start.y,T=this.end.x,P=this.end.y,O=o.start.x,z=o.start.y,H=o.end.x,re=o.end.y,te=(f-T)*(z-re)-(g-P)*(O-H);if(Math.abs(te)<1e-12)return null;const W=((f-O)*(z-re)-(g-z)*(O-H))/te,Ee=-((f-T)*(g-z)-(g-P)*(f-O))/te;return W<-1e-12||W>1+1e-12||Ee<-1e-12||Ee>1+1e-12?null:new Q_(f+W*(T-f),g+W*(P-g))}static fromCoordinates(o,f,g,T){return new Eb(new Q_(o,f),new Q_(g,T))}static fromPointAndAngle(o,f,g){const T=f*(Math.PI/180);return new Eb(o,new Q_(o.x+Math.cos(T)*g,o.y+Math.sin(T)*g))}static fromPointAndDirection(o,f,g){const T=Math.sqrt(f[0]*f[0]+f[1]*f[1])||1;return new Eb(o,new Q_(o.x+f[0]/T*g,o.y+f[1]/T*g))}}function sEt(l,o,f,g){return Eb.fromCoordinates(l,o,f,g)}class GO{constructor(o,f){this.center=o,this.radius=f}get diameter(){return this.radius*2}get circumference(){return 2*Math.PI*this.radius}get area(){return Math.PI*this.radius*this.radius}pointAtAngle(o){const f=o*Math.PI/180;return new Q_(this.center.x+Math.cos(f)*this.radius,this.center.y+Math.sin(f)*this.radius)}translate(o,f){return new GO(this.center.translate(o,f),this.radius)}toSketch(o){const g=nd().CrossSection.circle(this.radius,o??0).translate([this.center.x,this.center.y]);return new Eo(g)}extrude(o,f){const g=this.toSketch(f),T=aT(g,o),P=iWe(this,o);return new po(T.shape,P,o,!0)}static fromCenterAndRadius(o,f){return new GO(o,f)}static fromDiameter(o,f){return new GO(o,f/2)}}function aEt(l,o,f){return new GO(new Q_(l,o),f)}class dC{constructor(o){tu(this,"vertices");this.vertices=o}get width(){return this.vertices[0].distanceTo(this.vertices[1])}get height(){return this.vertices[1].distanceTo(this.vertices[2])}get center(){return this.vertices[0].midpointTo(this.vertices[2])}side(o){const[f,g,T,P]=this.vertices;switch(o){case"bottom":return new Eb(f,g);case"right":return new Eb(g,T);case"top":return new Eb(T,P);case"left":return new Eb(P,f)}}sideAt(o){const f=["bottom","right","top","left"];return this.side(f[o%4])}vertex(o){const[f,g,T,P]=this.vertices;switch(o){case"bottom-left":return f;case"bottom-right":return g;case"top-right":return T;case"top-left":return P}}diagonals(){const[o,f,g,T]=this.vertices;return[new Eb(o,g),new Eb(f,T)]}toSketch(){return Md(this.vertices.map(o=>o.toTuple()))}translate(o,f){return new dC(this.vertices.map(g=>g.translate(o,f)))}static fromDimensions(o,f,g,T){return new dC([new Q_(o,f),new Q_(o+g,f),new Q_(o+g,f+T),new Q_(o,f+T)])}static fromCenterAndDimensions(o,f,g){const T=f/2,P=g/2;return new dC([new Q_(o.x-T,o.y-P),new Q_(o.x+T,o.y-P),new Q_(o.x+T,o.y+P),new Q_(o.x-T,o.y+P)])}static from2Corners(o,f){const g=Math.min(o.x,f.x),T=Math.max(o.x,f.x),P=Math.min(o.y,f.y),O=Math.max(o.y,f.y);return new dC([new Q_(g,P),new Q_(T,P),new Q_(T,O),new Q_(g,O)])}static from3Points(o,f,g){const T=f.x-o.x,P=f.y-o.y,O=Math.sqrt(T*T+P*P)||1,z=T/O,re=-(P/O),te=z,W=(g.x-o.x)*re+(g.y-o.y)*te;return new dC([o,f,new Q_(f.x+re*W,f.y+te*W),new Q_(o.x+re*W,o.y+te*W)])}extrude(o,f=!0){const g=this.toSketch(),T=Math.abs(o),P=aT(g,T),O=f?P.shape:P.shape.translate(0,0,-T),z=rWe(this,T,f);return new po(O,z,T,f)}}function oEt(l,o,f,g){return dC.fromDimensions(l,o,f,g)}function cEt(l){return l}function lEt(l){return l*(180/Math.PI)}function HS(l,o){return typeof o=="string"?o:l.importLine(o)}function RJ(l,o){return typeof o=="string"?o:l.importPoint(o)}const uEt={makeParallel(l,o,f){return l.constrain({type:"parallel",a:HS(l,o),b:HS(l,f)})},enforceAngle(l,o,f,g){return l.constrain({type:"angle",a:HS(l,o),b:HS(l,f),value:g})},horizontal(l,o){return l.constrain({type:"horizontal",line:HS(l,o)})},vertical(l,o){return l.constrain({type:"vertical",line:HS(l,o)})},equalLength(l,o,f){return l.constrain({type:"equal",a:HS(l,o),b:HS(l,f)})},distance(l,o,f,g){return l.constrain({type:"distance",a:RJ(l,o),b:RJ(l,f),value:g})},fix(l,o,f,g){return l.constrain({type:"fixed",point:RJ(l,o),x:f,y:g})},coincident(l,o,f){return l.constrain({type:"coincident",a:RJ(l,o),b:RJ(l,f)})},perpendicular(l,o,f){return l.constrain({type:"perpendicular",a:HS(l,o),b:HS(l,f)})},length(l,o,f){return l.constrain({type:"length",line:HS(l,o),value:f})}},mxe=l=>l instanceof po?l.toShape():l;function _We(l,o,f){return gne(l,hqe(c4(l),qkt(o,f)))}function _Et(l,o,f,g,T=0){const P=mxe(l),O=[];for(let z=0;z<o;z++){const H=z===0?P.clone():P.translate(f*z,g*z,T*z);O.push(_We(H,"linear",z))}return K1(...O)}function fEt(l,o,f=0,g=0){const T=mxe(l),P=360/o,O=[];for(let z=0;z<o;z++){const H=z===0?T.clone():T.translate(-f,-g,0).rotate(0,0,P*z).translate(f,g,0);O.push(_We(H,"circular",z))}return K1(...O)}function pEt(l,o){const f=mxe(l);return K1(f,f.mirror(o))}function fWe(l){return l instanceof po?l.toShape():l}function pWe(l,o){const f=l??[-1,-1],g=Math.sign(f[0]),T=Math.sign(f[1]);if(g!==1&&g!==-1||T!==1&&T!==-1)throw new Error(`${o} requires quadrant signs of either 1 or -1.`);return[g,T]}function dEt(l,o){return o?Qqe(l).some(f=>Pb(f,o)):!0}function dWe(l,o,f){var g;if(!dEt(l,(g=o.query)==null?void 0:g.owner))throw new Error(`${f} requires an edge query owned by the target shape or one of its preserved query ancestors.`)}function mWe(l,o,f,g){if(!l)return null;const T=une(o);return hq(ixe(l,Bkt(o,T,f,g.filter(P=>P!=null))),T)}function hWe(l,o,f){if(!o)throw new Error(`Could not record compiler intent for ${f} on this target shape.`);const g=Yqe(l),T=M_(o,l.colorHex,{backend:g.backend,representation:g.representation,fidelity:g.fidelity,topology:"none",sources:[f,...g.sources]});return Yte(T,fxe(l)),mne(T,Xqe(l),{merge:!1}),hne(T,{backend:g.backend,representation:g.representation,fidelity:g.fidelity,topology:"none",sources:[f,...g.sources]}),T}function mEt(l,o,f,g=[-1,-1],T=16){if(!Number.isFinite(f)||!(f>0))throw new Error("filletEdge() requires a positive finite radius.");if(!Number.isFinite(T)||T<2)throw new Error("filletEdge() requires at least 2 segments.");const P=fWe(l);dWe(P,o,"filletEdge()");const O=c4(P);if(!O)throw new Error("filletEdge() currently requires a compile-covered target shape.");const z=pWe(g,"filletEdge()"),H=lI(O,o.query);if(!H.ok)throw new Error(`filletEdge(): ${H.issue.reason}`);const re=zqe(O,o.query);if(H.selection.quadrant[0]!==z[0]||H.selection.quadrant[1]!==z[1])throw new Error(`filletEdge() currently supports ${H.selection.edgeName} only with quadrant [${H.selection.quadrant[0]}, ${H.selection.quadrant[1]}].`);const te=mWe(ITt(O,H.query,f,z,Math.round(T)),"fillet",H.query,re);return hWe(P,te,"fillet")}function hEt(l,o,f,g=[-1,-1]){if(!Number.isFinite(f)||!(f>0))throw new Error("chamferEdge() requires a positive finite size.");const T=fWe(l);dWe(T,o,"chamferEdge()");const P=c4(T);if(!P)throw new Error("chamferEdge() currently requires a compile-covered target shape.");const O=pWe(g,"chamferEdge()"),z=lI(P,o.query);if(!z.ok)throw new Error(`chamferEdge(): ${z.issue.reason}`);const H=zqe(P,o.query);if(z.selection.quadrant[0]!==O[0]||z.selection.quadrant[1]!==O[1])throw new Error(`chamferEdge() currently supports ${z.selection.edgeName} only with quadrant [${z.selection.quadrant[0]}, ${z.selection.quadrant[1]}].`);const re=mWe(FTt(P,z.query,f,O),"chamfer",z.query,H);return hWe(T,re,"chamfer")}const QD=1e-8;function gEt(l){return Array.isArray(l)?[l[0],l[1]]:[l.x,l.y]}function b2e(l,o){const f=o[0]-l[0],g=o[1]-l[1];return Math.hypot(f,g)}function Obe(l,o){const f=Math.hypot(l,o);if(f<=QD)throw new Error("filletCorners requires non-degenerate edges");return[l/f,o/f]}function yEt(l,o,f){return Math.max(o,Math.min(f,l))}function vEt(l){let o=0;for(let f=0;f<l.length;f+=1){const[g,T]=l[f],[P,O]=l[(f+1)%l.length];o+=g*O-P*T}return o/2}function bEt(l){return Math.max(3,Math.ceil(Math.abs(l)/(Math.PI/15)))}function Eze(l,o,f=1e-6){return Math.abs(l[0]-o[0])<=f&&Math.abs(l[1]-o[1])<=f}function xEt(l,o,f){const g=l.length;if(!Number.isInteger(o.index)||o.index<0||o.index>=g)throw new Error(`filletCorners corner index ${o.index} is out of range for ${g} points`);if(!(o.radius>0))throw new Error(`filletCorners corner ${o.index} must have a positive radius`);const T=l[(o.index-1+g)%g],P=l[o.index],O=l[(o.index+1)%g],z=b2e(T,P),H=b2e(P,O),[re,te]=Obe(P[0]-T[0],P[1]-T[1]),[W,Ee]=Obe(O[0]-P[0],O[1]-P[1]);if((re*Ee-te*W)*f<=QD)throw new Error(`filletCorners corner ${o.index} is concave or collinear; only convex corners are supported`);const me=[-re,-te],Xe=[W,Ee],it=Math.acos(yEt(me[0]*Xe[0]+me[1]*Xe[1],-1,1));if(it<=QD||it>=Math.PI-QD)throw new Error(`filletCorners corner ${o.index} has an unsupported angle`);const at=o.radius/Math.tan(it/2);if(at>=z-QD||at>=H-QD){const zn=Math.min(z,H)*Math.tan(it/2);throw new Error(`filletCorners radius ${o.radius} is too large for corner ${o.index}; max is ${zn.toFixed(3)}`)}const It=[P[0]-re*at,P[1]-te*at],tn=[P[0]+W*at,P[1]+Ee*at],[At,mt]=Obe(me[0]+Xe[0],me[1]+Xe[1]),ht=o.radius/Math.sin(it/2),xn=[P[0]+At*ht,P[1]+mt*ht],Pn=o.segments==null?bEt(it):Math.round(o.segments),$r=Math.max(2,Pn);return{radius:o.radius,tangentDistance:at,segments:$r,start:It,end:tn,center:xn,startAngle:Math.atan2(It[1]-xn[1],It[0]-xn[0]),sweep:f*it}}function SEt(l,o){var H,re;if(l.length<3)throw new Error("filletCorners requires at least 3 points");if(o.length===0)return Md(l);const f=l.map(gEt),g=vEt(f);if(Math.abs(g)<=QD)throw new Error("filletCorners requires a non-degenerate polygon");const T=Math.sign(g),P=new Map;for(const te of o){if(P.has(te.index))throw new Error(`filletCorners corner ${te.index} is specified more than once`);P.set(te.index,xEt(f,te,T))}for(let te=0;te<f.length;te+=1){const W=(te+1)%f.length,Ee=b2e(f[te],f[W]),se=((H=P.get(te))==null?void 0:H.tangentDistance)??0,me=((re=P.get(W))==null?void 0:re.tangentDistance)??0;if(se+me>=Ee-QD)throw new Error(`filletCorners adjacent fillets overlap on edge ${te} -> ${W}; reduce one of the radii`)}const O=[],z=te=>{(O.length===0||!Eze(O[O.length-1],te))&&O.push(te)};for(let te=0;te<f.length;te+=1){const W=P.get(te);if(W==null){z(f[te]);continue}z(W.start);for(let Ee=1;Ee<W.segments;Ee+=1){const se=W.startAngle+W.sweep*Ee/W.segments;z([W.center[0]+Math.cos(se)*W.radius,W.center[1]+Math.sin(se)*W.radius])}z(W.end)}return O.length>=2&&Eze(O[0],O[O.length-1])&&O.pop(),Md(O)}function ene(l,o){return[l[0]-o[0],l[1]-o[1],l[2]-o[2]]}function Pze(l,o){return[l[0]+o[0],l[1]+o[1],l[2]+o[2]]}function x2e(l,o){return[l[0]*o,l[1]*o,l[2]*o]}function QE(l,o){return l[0]*o[0]+l[1]*o[1]+l[2]*o[2]}function TEt(l,o){return[l[1]*o[2]-l[2]*o[1],l[2]*o[0]-l[0]*o[2],l[0]*o[1]-l[1]*o[0]]}function hxe(l){return Math.sqrt(QE(l,l))}function S2e(l){const o=hxe(l)||1;return[l[0]/o,l[1]/o,l[2]/o]}function Dze(l,o){return[(l[0]+o[0])/2,(l[1]+o[1])/2,(l[2]+o[2])/2]}function Aze(l){if(l instanceof dC){const[o,f,g,T]=l.vertices;return{corners:[[o.x,o.y,0],[f.x,f.y,0],[g.x,g.y,0],[T.x,T.y,0]]}}return l}function Nze(l,o){const[f,g,T,P]=l.corners;return[{name:`${o}-bottom`,start:f,end:g},{name:`${o}-right`,start:g,end:T},{name:`${o}-top`,start:T,end:P},{name:`${o}-left`,start:P,end:f}]}function tne(l){return S2e(ene(l.end,l.start))}function kEt(l,o,f){const g=tne(l),T=tne(o);if(!(Math.abs(QE(g,T))>.999))throw new Error("Inner edges are not parallel");const O=QE(l.start,g),z=QE(l.end,g),H=QE(o.start,g),re=QE(o.end,g),te=Math.min(O,z),W=Math.max(O,z),Ee=Math.min(H,re),se=Math.max(H,re),me=Math.max(te,Ee),it=Math.min(W,se)-me;if(it<1e-6)throw new Error("Inner edges do not overlap along their direction");const at=Pze(l.start,x2e(g,me-O)),It=Pze(o.start,x2e(g,me-H)),tn=ene(It,at),At=QE(tn,g),mt=[tn[0]-g[0]*At,tn[1]-g[1]*At,tn[2]-g[2]*At],ht=hxe(mt);if(ht<1e-6)throw new Error("Edges are coincident — no arc to build");const xn=S2e(mt),Pn=S2e(TEt(g,xn)),$r=ht/2,zn=[ht/2,0],ii=[];for(let Hs=0;Hs<=f;Hs++){const Ua=Math.PI*Hs/f,Di=zn[0]-$r*Math.cos(Ua),ko=$r*Math.sin(Ua);ii.push([Di,ko])}const Gr=Math.max(.5,ht*.02),mn=[];for(let Hs=f;Hs>=0;Hs--){const Ua=Math.PI*Hs/f,Di=$r-Gr,ko=zn[0]-Di*Math.cos(Ua),K_=Di*Math.sin(Ua);mn.push([ko,K_])}const $s=Md([...ii,...mn]),is=aT($s,it).toShape(),Wt=at,Es=[xn[0],xn[1],xn[2],0,Pn[0],Pn[1],Pn[2],0,g[0],g[1],g[2],0,Wt[0],Wt[1],Wt[2],1];return is.transform(Es)}function CEt(l,o,f=12){const g=Aze(l),T=Aze(o),P=Nze(g,"a"),O=Nze(T,"b");let z=null;for(const H of P){const re=tne(H);for(const te of O){const W=tne(te);if(Math.abs(QE(re,W))<.999)continue;const Ee=Dze(H.start,H.end),se=Dze(te.start,te.end),me=ene(se,Ee),Xe=QE(me,re),it=ene(me,x2e(re,Xe)),at=hxe(it);at<1e-6||(!z||at<z.dist)&&(z={edgeA:H,edgeB:te,dist:at})}}if(!z)throw new Error("No parallel inner edges found between the two rectangles");return kEt(z.edgeA,z.edgeB,f)}let nI=[],T2e=0;function wEt(){nI=[],T2e=0}function k2e(){return nI}function EEt(l){const o=Math.max(0,Math.min(l,nI.length)),f=nI.slice(o);return nI=nI.slice(0,o),f}function Ize(l){return l instanceof Q_?[l.x,l.y,0]:l.length===2?[l[0],l[1],0]:[l[0],l[1],l[2]]}function gWe(l,o,f){T2e++;const g=(()=>{if(typeof(f==null?void 0:f.component)=="string"){const T=f.component.trim();return T?[T]:void 0}if(Array.isArray(f==null?void 0:f.component)){const T=Array.from(new Set(f.component.map(P=>typeof P=="string"?P.trim():"").filter(Boolean)));return T.length>0?T:void 0}})();nI.push({id:`dim-${T2e}`,from:Ize(l),to:Ize(o),offset:(f==null?void 0:f.offset)??10,autoOffset:(f==null?void 0:f.offset)===void 0,label:f==null?void 0:f.label,color:f==null?void 0:f.color,components:g,currentComponent:!!(f!=null&&f.currentComponent)})}function PEt(l,o){gWe([l.start.x,l.start.y],[l.end.x,l.end.y],o)}function GJ(l,o,f){return Math.max(o,Math.min(f,l))}function DEt(l,o){return[l[0]+o[0],l[1]+o[1],l[2]+o[2]]}function C2e(l,o){return[l[0]-o[0],l[1]-o[1],l[2]-o[2]]}function Fze(l,o){return[l[0]*o,l[1]*o,l[2]*o]}function AEt(l,o){return l[0]*o[0]+l[1]*o[1]+l[2]*o[2]}function gxe(l){return Math.sqrt(AEt(l,l))}function NEt(l){const o=gxe(l);return o<1e-9?[0,0,1]:[l[0]/o,l[1]/o,l[2]/o]}function Oze(l,o,f,g,T,P){const O=T*T,z=O*T,H=(1-P)*.5,re=(f[0]-l[0])*H,te=(f[1]-l[1])*H,W=(g[0]-o[0])*H,Ee=(g[1]-o[1])*H,se=2*z-3*O+1,me=z-2*O+T,Xe=-2*z+3*O,it=z-O;return[se*o[0]+me*re+Xe*f[0]+it*W,se*o[1]+me*te+Xe*f[1]+it*Ee]}function Mze(l,o,f,g,T,P){const O=T*T,z=O*T,H=(1-P)*.5,re=[(f[0]-l[0])*H,(f[1]-l[1])*H,(f[2]-l[2])*H],te=[(g[0]-o[0])*H,(g[1]-o[1])*H,(g[2]-o[2])*H],W=2*z-3*O+1,Ee=z-2*O+T,se=-2*z+3*O,me=z-O;return[W*o[0]+Ee*re[0]+se*f[0]+me*te[0],W*o[1]+Ee*re[1]+se*f[1]+me*te[1],W*o[2]+Ee*re[2]+se*f[2]+me*te[2]]}function IEt(l,o,f,g){if(l.length<2)throw new Error("spline2d requires at least 2 points");const T=l.length,P=[],O=o?T:T-1;for(let z=0;z<O;z++){const H=l[(z-1+T)%T],re=l[z%T],te=l[(z+1)%T],W=l[(z+2)%T];if(!o){const Ee=z===0?re:H,se=z===T-2?te:W;for(let me=0;me<f;me++){const Xe=me/f;P.push(Oze(Ee,re,te,se,Xe,g))}continue}for(let Ee=0;Ee<f;Ee++){const se=Ee/f;P.push(Oze(H,re,te,W,se,g))}}return o||P.push(l[T-1]),P}function FEt(l,o,f,g){if(l.length<2)throw new Error("spline3d requires at least 2 points");const T=l.length,P=[],O=o?T:T-1;for(let z=0;z<O;z++){const H=l[(z-1+T)%T],re=l[z%T],te=l[(z+1)%T],W=l[(z+2)%T];if(!o){const Ee=z===0?re:H,se=z===T-2?te:W;for(let me=0;me<f;me++){const Xe=me/f;P.push(Mze(Ee,re,te,se,Xe,g))}continue}for(let Ee=0;Ee<f;Ee++){const se=Ee/f;P.push(Mze(H,re,te,W,se,g))}}return o||P.push(l[T-1]),P}class yWe{constructor(o,f={}){tu(this,"points");tu(this,"closed");tu(this,"tension");if(o.length<2)throw new Error("Curve3D needs at least 2 points");this.points=o.map(g=>[g[0],g[1],g[2]]),this.closed=f.closed??!1,this.tension=GJ(f.tension??.5,0,1)}sampleBySegment(o=16){const f=Math.max(3,Math.floor(o));return FEt(this.points,this.closed,f,this.tension)}sample(o=64){const f=Math.max(2,Math.floor(o)),g=Math.max(3,Math.ceil(f/Math.max(1,this.points.length-(this.closed?0:1)))),T=this.sampleBySegment(g);if(T.length<=f)return T;const P=[];for(let O=0;O<f;O++){const z=Math.round(O/(f-1)*(T.length-1));P.push(T[z])}return P}pointAt(o){const f=this.sample(200),T=GJ(o,0,1)*(f.length-1),P=Math.floor(T),O=Math.min(f.length-1,P+1),z=T-P;return DEt(Fze(f[P],1-z),Fze(f[O],z))}tangentAt(o){const g=this.pointAt(GJ(o-.001,0,1)),T=this.pointAt(GJ(o+.001,0,1));return NEt(C2e(T,g))}length(o=200){const f=this.sample(o);let g=0;for(let T=1;T<f.length;T++)g+=gxe(C2e(f[T],f[T-1]));return g}}function OEt(l,o={}){const f=o.closed??!0,g=GJ(o.tension??.5,0,1),T=JSt(o.samplesPerSegment??16),P=IEt(l,f,T,g);if(f)return Md(P);if(o.strokeWidth==null||o.strokeWidth<=0)throw new Error("spline2d: open spline requires options.strokeWidth > 0 to create a solid Sketch");return dxe(P,o.strokeWidth,o.join??"Round")}function MEt(l,o={}){return new yWe(l,o)}function LEt(l,o,f={}){var tn;if(l.length<2)throw new Error("loft requires at least two profiles");if(l.length!==o.length)throw new Error("loft requires heights.length === profiles.length");const g=l.map((At,mt)=>({profile:At,z:o[mt]})).sort((At,mt)=>At.z-mt.z);for(let At=1;At<g.length;At++)if(Math.abs(g[At].z-g[At-1].z)<1e-8)throw new Error("loft requires strictly increasing, unique heights");const T=g.map(At=>At.z);let P=1/0,O=1/0,z=-1/0,H=-1/0;for(const At of g){const mt=At.profile.bounds();P=Math.min(P,mt.min[0]),O=Math.min(O,mt.min[1]),z=Math.max(z,mt.max[0]),H=Math.max(H,mt.max[1])}const re=T[0],te=T[T.length-1],W=Math.max(z-P,H-O,te-re,1),Ee=f.edgeLength??Math.max(.35,W/90),se=GJe(Ee),me=f.boundsPadding??Math.max(se*3,W*.06,1.5),Xe=XJe(me),it=OTt(g.map(At=>um(At.profile)),T,{edgeLength:se,boundsPadding:Xe}),at=s6(it,"loft");if(at)return M_(at,(tn=g[0])==null?void 0:tn.profile.colorHex,{fidelity:"sampled",sources:["loft","level-set"]});const It=Cqe(g.map(At=>At.profile.toPolygons()),T,{edgeLength:se,boundsPadding:Xe});return hne(pxe(It.sdf,It.bounds,It.edgeLength),{fidelity:"sampled",sources:["loft","level-set"]})}function REt(l,o,f={}){const g=Math.max(4,f.samples??48),T=qSt(g),P=Array.isArray(o)?o:o.sample(T);if(P.length<2)throw new Error("sweep requires a path with at least two points");const O=f.up??[0,0,1],z=l.bounds(),H=Math.max(Math.abs(z.min[0]),Math.abs(z.max[0]),Math.abs(z.min[1]),Math.abs(z.max[1]));let re=1/0,te=1/0,W=1/0,Ee=-1/0,se=-1/0,me=-1/0;for(const Pn of P)re=Math.min(re,Pn[0]),te=Math.min(te,Pn[1]),W=Math.min(W,Pn[2]),Ee=Math.max(Ee,Pn[0]),se=Math.max(se,Pn[1]),me=Math.max(me,Pn[2]);let Xe=0;for(let Pn=1;Pn<P.length;Pn++)Xe+=gxe(C2e(P[Pn],P[Pn-1]));const it=Math.max(Ee-re,se-te,me-W,Xe,1),at=f.edgeLength??Math.max(.3,it/110),It=GJe(at),tn=f.boundsPadding??Math.max(H+It*2,it*.04,2),At=XJe(tn),mt=MTt(um(l),{kind:"polyline",points:P.map(([Pn,$r,zn])=>[Pn,$r,zn])},{edgeLength:It,boundsPadding:At,up:O}),ht=s6(mt,"sweep");if(ht)return M_(ht,l.colorHex,{fidelity:"sampled",sources:["sweep","level-set"]});const xn=wqe(l.toPolygons(),P.map(([Pn,$r,zn])=>[Pn,$r,zn]),{edgeLength:It,boundsPadding:At,up:O});return hne(pxe(xn.sdf,xn.bounds,xn.edgeLength),{fidelity:"sampled",sources:["sweep","level-set"]})}const vWe=1e-7,ku=1e-9,jEt={fill:"black",stroke:"none",strokeWidth:1,fillRule:"nonzero",strokeJoin:"miter",display:"inline",visibility:"visible",opacity:1,fillOpacity:1,strokeOpacity:1},BEt={px:1,pt:96/72,pc:16,in:96,cm:96/2.54,mm:96/25.4,q:96/101.6};function _I(l,o,f){return Math.max(o,Math.min(f,l))}function qD(l){return l*l}function iI(l,o){return Math.hypot(l[0]-o[0],l[1]-o[1])}function yxe(l){let o=0;for(let f=0;f<l.length;f+=1){const[g,T]=l[f],[P,O]=l[(f+1)%l.length];o+=g*O-P*T}return o*.5}function zEt(l){if(l.length===0)return[0,0];let o=0,f=0;for(const[g,T]of l)o+=g,f+=T;return[o/l.length,f/l.length]}function bWe(l){let o=0,f=0,g=0;for(let P=0;P<l.length;P+=1){const[O,z]=l[P],[H,re]=l[(P+1)%l.length],te=O*re-H*z;g+=te,o+=(O+H)*te,f+=(z+re)*te}if(Math.abs(g)<ku)return zEt(l);const T=1/(3*g);return[o*T,f*T]}function xWe(l,o){const[f,g]=l;let T=!1;for(let P=0,O=o.length-1;P<o.length;O=P++){const[z,H]=o[P],[re,te]=o[O];H>g!=te>g&&f<(re-z)*(g-H)/(te-H||1e-20)+z&&(T=!T)}return T}function qO(){return[1,0,0,1,0,0]}function sI(l,o){const[f,g,T,P,O,z]=l,[H,re,te,W,Ee,se]=o;return[f*H+T*re,g*H+P*re,f*te+T*W,g*te+P*W,f*Ee+T*se+O,g*Ee+P*se+z]}function JEt(l,o){const[f,g,T,P,O,z]=l,[H,re]=o;return[f*H+T*re+O,g*H+P*re+z]}function Dte(l,o){return[1,0,0,1,l,o]}function w2e(l,o){return[l,0,0,o,0,0]}function Lze(l){const o=l*Math.PI/180,f=Math.cos(o),g=Math.sin(o);return[f,g,-g,f,0,0]}function qEt(l){const o=l*Math.PI/180;return[1,0,Math.tan(o),1,0,0]}function WEt(l){const o=l*Math.PI/180;return[1,Math.tan(o),0,1,0,0]}function Mm(l,o=NaN){if(typeof l!="string")return o;const f=l.trim();if(!f)return o;const g=f.match(/^([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)([a-z%]*)$/i);if(!g)return o;const T=Number(g[1]);if(!Number.isFinite(T))return o;const P=g[2].toLowerCase();return P===""||P==="px"?T:P==="%"?o:T*(BEt[P]??1)}function vxe(l){if(!l)return[];const o=[],f=/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g;let g;for(;(g=f.exec(l))!==null;){const T=Number(g[0]);Number.isFinite(T)&&o.push(T)}return o}function VEt(l){return l.replace(/&(#x?[0-9a-fA-F]+|amp|lt|gt|quot|apos);/g,(o,f)=>{switch(f){case"amp":return"&";case"lt":return"<";case"gt":return">";case"quot":return'"';case"apos":return"'";default:if(f.startsWith("#x")||f.startsWith("#X")){const g=Number.parseInt(f.slice(2),16);return Number.isFinite(g)?String.fromCodePoint(g):""}if(f.startsWith("#")){const g=Number.parseInt(f.slice(1),10);return Number.isFinite(g)?String.fromCodePoint(g):""}return""}})}function UEt(l){const o={},f=/([:@A-Za-z_][\w:.-]*)\s*=\s*("([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/g;let g;for(;(g=f.exec(l))!==null;){const T=g[1],P=g[3]??g[4]??g[5]??"";o[T]=VEt(P)}return o}function $Et(l){const o={};return l&&l.split(";").forEach(f=>{const g=f.indexOf(":");if(g<0)return;const T=f.slice(0,g).trim().toLowerCase(),P=f.slice(g+1).trim();T&&(o[T]=P)}),o}function HEt(l,o){return l?l.trim().toLowerCase()==="evenodd"?"evenodd":"nonzero":o}function GEt(l,o){if(!l)return o;const f=l.trim().toLowerCase();return f==="round"||f==="bevel"?f:"miter"}function Mbe(l,o){const f=Mm(l,NaN);return Number.isFinite(f)?_I(f,0,1):o}function Kee(l,o){if(typeof l!="string")return o;const f=l.trim().toLowerCase();return f||o}function XEt(l,o){const f={...l},g=$Et(o.style),T=O=>g[O]??o[O];f.fill=Kee(T("fill"),f.fill),f.stroke=Kee(T("stroke"),f.stroke);const P=Mm(T("stroke-width"),NaN);return Number.isFinite(P)&&P>=0&&(f.strokeWidth=P),f.fillRule=HEt(T("fill-rule"),f.fillRule),f.strokeJoin=GEt(T("stroke-linejoin"),f.strokeJoin),f.display=Kee(T("display"),f.display),f.visibility=Kee(T("visibility"),f.visibility),f.opacity=Mbe(T("opacity"),f.opacity),f.fillOpacity=Mbe(T("fill-opacity"),f.fillOpacity),f.strokeOpacity=Mbe(T("stroke-opacity"),f.strokeOpacity),f}function YEt(l){if(!l)return qO();const o=l.trim();if(!o)return qO();const f=/([a-zA-Z]+)\s*\(([^)]*)\)/g;let g,T=qO();for(;(g=f.exec(o))!==null;){const P=g[1].toLowerCase(),O=vxe(g[2]);let z=qO();P==="matrix"&&O.length>=6?z=[O[0],O[1],O[2],O[3],O[4],O[5]]:P==="translate"&&O.length>=1?z=Dte(O[0],O.length>=2?O[1]:0):P==="scale"&&O.length>=1?z=w2e(O[0],O.length>=2?O[1]:O[0]):P==="rotate"&&O.length>=1?O.length>=3?z=sI(Dte(O[1],O[2]),sI(Lze(O[0]),Dte(-O[1],-O[2]))):z=Lze(O[0]):P==="skewx"&&O.length>=1?z=qEt(O[0]):P==="skewy"&&O.length>=1&&(z=WEt(O[0])),T=sI(z,T)}return T}function Vg(l,o){if(l.length===0){l.push([o[0],o[1]]);return}const f=l[l.length-1];iI(f,o)>vWe&&l.push([o[0],o[1]])}function yI(l){return l.length<=1?l:iI(l[0],l[l.length-1])<=vWe?l.slice(0,-1):l}function Rze(l,o,f,g,T){const P=iI(l,o)+iI(o,f)+iI(f,g),O=_I(Math.ceil(P/Math.max(T,1e-4)),4,512),z=[];for(let H=1;H<=O;H+=1){const re=H/O,te=1-re,W=te*te*te*l[0]+3*te*te*re*o[0]+3*te*re*re*f[0]+re*re*re*g[0],Ee=te*te*te*l[1]+3*te*te*re*o[1]+3*te*re*re*f[1]+re*re*re*g[1];z.push([W,Ee])}return z}function jze(l,o,f,g){const T=iI(l,o)+iI(o,f),P=_I(Math.ceil(T/Math.max(g,1e-4)),4,512),O=[];for(let z=1;z<=P;z+=1){const H=z/P,re=1-H,te=re*re*l[0]+2*re*H*o[0]+H*H*f[0],W=re*re*l[1]+2*re*H*o[1]+H*H*f[1];O.push([te,W])}return O}function Bze(l,o,f,g){const T=l*f+o*g,P=l*g-o*f;return Math.atan2(P,T)}function QEt(l,o,f,g,T,P,O,z,H,re,te){let W=Math.abs(f),Ee=Math.abs(g);if(W<ku||Ee<ku)return[[z,H]];const se=T*Math.PI/180,me=Math.cos(se),Xe=Math.sin(se),it=(l-z)/2,at=(o-H)/2,It=me*it+Xe*at,tn=-Xe*it+me*at,At=qD(It)/qD(W)+qD(tn)/qD(Ee);if(At>1){const xi=Math.sqrt(At);W*=xi,Ee*=xi}const mt=qD(W),ht=qD(Ee),xn=qD(It),Pn=qD(tn);let $r=mt*ht-mt*Pn-ht*xn,zn=mt*Pn+ht*xn;zn<ku&&(zn=ku),$r=Math.max(0,$r);const ii=(P===O?-1:1)*Math.sqrt($r/zn),Gr=ii*(W*tn/Ee),mn=ii*(-(Ee*It)/W),$s=me*Gr-Xe*mn+(l+z)/2,is=Xe*Gr+me*mn+(o+H)/2,Wt=(It-Gr)/W,Es=(tn-mn)/Ee,Hs=(-It-Gr)/W,Ua=(-tn-mn)/Ee;let Di=Bze(1,0,Wt,Es),ko=Bze(Wt,Es,Hs,Ua);!O&&ko>0&&(ko-=Math.PI*2),O&&ko<0&&(ko+=Math.PI*2);const K_=Math.max(W,Ee),Cu=Math.max(te,Math.ceil(Math.abs(ko)*K_/Math.max(re,1e-4))),El=[];for(let xi=1;xi<=Cu;xi+=1){const yf=xi/Cu,j0=Di+ko*yf,Bm=Math.cos(j0),a6=Math.sin(j0),B0=me*W*Bm-Xe*Ee*a6+$s,zy=Xe*W*Bm+me*Ee*a6+is;El.push([B0,zy])}return El}function ZEt(l,o){return l.map(f=>{const g=[];for(const T of f.points)Vg(g,JEt(o,T));return{points:g,closed:f.closed}})}function KEt(l,o,f){const g=l.match(/[AaCcHhLlMmQqSsTtVvZz]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[],T=[];let P=0,O="",z=0,H=0,re=0,te=0,W=null,Ee=null,se=null;const me=at=>{if(!W)return;const It=yI(W.points);It.length>=2&&T.push({points:It,closed:at}),W=null},Xe=()=>{W||(W={points:[[z,H]],closed:!1})},it=()=>{if(P>=g.length)return null;const at=g[P];if(/^[AaCcHhLlMmQqSsTtVvZz]$/.test(at))return null;P+=1;const It=Number(at);return Number.isFinite(It)?It:null};for(;P<g.length;){if(/^[AaCcHhLlMmQqSsTtVvZz]$/.test(g[P]))O=g[P],P+=1;else if(!O){P+=1;continue}switch(O){case"M":case"m":{let at=!0;for(;;){const It=it(),tn=it();if(It==null||tn==null)break;const At=O==="m"?z+It:It,mt=O==="m"?H+tn:tn;at?(me(!1),W={points:[[At,mt]],closed:!1},z=At,H=mt,re=At,te=mt,at=!1):(Xe(),Vg(W.points,[At,mt]),z=At,H=mt)}Ee=null,se=null;break}case"L":case"l":{for(;;){const at=it(),It=it();if(at==null||It==null)break;const tn=O==="l"?z+at:at,At=O==="l"?H+It:It;Xe(),Vg(W.points,[tn,At]),z=tn,H=At}Ee=null,se=null;break}case"H":case"h":{for(;;){const at=it();if(at==null)break;const It=O==="h"?z+at:at;Xe(),Vg(W.points,[It,H]),z=It}Ee=null,se=null;break}case"V":case"v":{for(;;){const at=it();if(at==null)break;const It=O==="v"?H+at:at;Xe(),Vg(W.points,[z,It]),H=It}Ee=null,se=null;break}case"C":case"c":{for(;;){const at=it(),It=it(),tn=it(),At=it(),mt=it(),ht=it();if(at==null||It==null||tn==null||At==null||mt==null||ht==null)break;const xn=[z,H],Pn=[O==="c"?z+at:at,O==="c"?H+It:It],$r=[O==="c"?z+tn:tn,O==="c"?H+At:At],zn=[O==="c"?z+mt:mt,O==="c"?H+ht:ht];Xe(),Rze(xn,Pn,$r,zn,o).forEach(ii=>Vg(W.points,ii)),z=zn[0],H=zn[1],Ee=$r,se=null}break}case"S":case"s":{for(;;){const at=it(),It=it(),tn=it(),At=it();if(at==null||It==null||tn==null||At==null)break;const mt=[z,H],ht=Ee?[2*z-Ee[0],2*H-Ee[1]]:[z,H],xn=[O==="s"?z+at:at,O==="s"?H+It:It],Pn=[O==="s"?z+tn:tn,O==="s"?H+At:At];Xe(),Rze(mt,ht,xn,Pn,o).forEach($r=>Vg(W.points,$r)),z=Pn[0],H=Pn[1],Ee=xn,se=null}break}case"Q":case"q":{for(;;){const at=it(),It=it(),tn=it(),At=it();if(at==null||It==null||tn==null||At==null)break;const mt=[z,H],ht=[O==="q"?z+at:at,O==="q"?H+It:It],xn=[O==="q"?z+tn:tn,O==="q"?H+At:At];Xe(),jze(mt,ht,xn,o).forEach(Pn=>Vg(W.points,Pn)),z=xn[0],H=xn[1],se=ht,Ee=null}break}case"T":case"t":{for(;;){const at=it(),It=it();if(at==null||It==null)break;const tn=[z,H],At=se?[2*z-se[0],2*H-se[1]]:[z,H],mt=[O==="t"?z+at:at,O==="t"?H+It:It];Xe(),jze(tn,At,mt,o).forEach(ht=>Vg(W.points,ht)),z=mt[0],H=mt[1],se=At,Ee=null}break}case"A":case"a":{for(;;){const at=it(),It=it(),tn=it(),At=it(),mt=it(),ht=it(),xn=it();if(at==null||It==null||tn==null||At==null||mt==null||ht==null||xn==null)break;const Pn=O==="a"?z+ht:ht,$r=O==="a"?H+xn:xn;Xe(),QEt(z,H,at,It,tn,Math.abs(At)>=.5,Math.abs(mt)>=.5,Pn,$r,o,f).forEach(zn=>Vg(W.points,zn)),z=Pn,H=$r,Ee=null,se=null}break}case"Z":case"z":{W&&Vg(W.points,[re,te]),me(!0),z=re,H=te,Ee=null,se=null;break}default:{Ee=null,se=null;break}}}return me(!1),T}function zze(l,o,f,g,T){if(!(f>ku)||!(g>ku))return[];const P=2*Math.PI*Math.max(f,g),O=_I(Math.ceil(P/Math.max(T,1e-4)),16,720),z=[];for(let H=0;H<O;H+=1){const re=2*Math.PI*H/O;z.push([l+f*Math.cos(re),o+g*Math.sin(re)])}return[{points:z,closed:!0}]}function ete(l,o,f,g,T,P,O,z){const H=Math.abs(O-P),re=_I(Math.ceil(H*Math.max(g,T)/Math.max(z,1e-4)),2,180);for(let te=1;te<=re;te+=1){const W=P+H*te/re*Math.sign(O-P);Vg(l,[o+g*Math.cos(W),f+T*Math.sin(W)])}}function e6t(l,o,f,g,T,P,O){const z=f,H=g;if(!(z>ku)||!(H>ku))return[];const re=_I(T,0,z/2),te=_I(P,0,H/2);if(re<ku||te<ku)return[{points:[[l,o],[l+z,o],[l+z,o+H],[l,o+H]],closed:!0}];const W=[];return Vg(W,[l+re,o]),Vg(W,[l+z-re,o]),ete(W,l+z-re,o+te,re,te,-Math.PI/2,0,O),Vg(W,[l+z,o+H-te]),ete(W,l+z-re,o+H-te,re,te,0,Math.PI/2,O),Vg(W,[l+re,o+H]),ete(W,l+re,o+H-te,re,te,Math.PI/2,Math.PI,O),Vg(W,[l,o+te]),ete(W,l+re,o+te,re,te,Math.PI,3*Math.PI/2,O),[{points:yI(W),closed:!0}]}function Jze(l){const o=vxe(l),f=[];for(let g=0;g+1<o.length;g+=2)f.push([o[g],o[g+1]]);return yI(f)}function t6t(l,o,f,g){const T=l.toLowerCase();if(T==="path"){const P=o.d??"";return P.trim()?KEt(P,f,g):[]}if(T==="rect"){const P=Mm(o.x,0),O=Mm(o.y,0),z=Mm(o.width,NaN),H=Mm(o.height,NaN);if(!(z>ku)||!(H>ku))return[];let re=Mm(o.rx,NaN),te=Mm(o.ry,NaN);return!Number.isFinite(re)&&Number.isFinite(te)&&(re=te),!Number.isFinite(te)&&Number.isFinite(re)&&(te=re),Number.isFinite(re)||(re=0),Number.isFinite(te)||(te=0),e6t(P,O,z,H,re,te,f)}if(T==="circle"){const P=Mm(o.cx,0),O=Mm(o.cy,0),z=Mm(o.r,NaN);return z>ku?zze(P,O,z,z,f):[]}if(T==="ellipse"){const P=Mm(o.cx,0),O=Mm(o.cy,0),z=Mm(o.rx,NaN),H=Mm(o.ry,NaN);return!(z>ku)||!(H>ku)?[]:zze(P,O,z,H,f)}if(T==="line"){const P=Mm(o.x1,0),O=Mm(o.y1,0),z=Mm(o.x2,0),H=Mm(o.y2,0);return[{points:[[P,O],[z,H]],closed:!1}]}if(T==="polyline"){const P=Jze(o.points);return P.length<2?[]:[{points:P,closed:!1}]}if(T==="polygon"){const P=Jze(o.points);return P.length<3?[]:[{points:P,closed:!0}]}return[]}function n6t(l){const o=[];for(const f of l){const g=yI(f.points);f.closed?g.length>=3&&Math.abs(yxe(g))>ku&&o.push({points:g,closed:!0}):g.length>=2&&o.push({points:g,closed:!1})}return o}function r6t(l){return l.fill!=="none"&&l.fill!=="transparent"&&l.opacity>ku&&l.fillOpacity>ku}function i6t(l){return l.stroke!=="none"&&l.stroke!=="transparent"&&l.strokeWidth>ku&&l.opacity>ku&&l.strokeOpacity>ku}function s6t(l){const o=[];for(const f of l){if(!f.closed)continue;const g=yI(f.points);if(g.length<3)continue;const T=yxe(g),P=Math.abs(T);P<=ku||o.push({points:g,area:T,absArea:P,sample:bWe(g)})}return o}function a6t(l,o){const f=s6t(l);if(f.length===0)return null;const g=[],T=[];if(o==="evenodd"){const O=[...f].sort((z,H)=>z.absArea-H.absArea);for(const z of O){let H=0;for(const te of f)te!==z&&(te.absArea<=z.absArea+ku||xWe(z.sample,te.points)&&(H+=1));const re=Md(z.points);H%2===0?g.push(re):T.push(re)}}else{const z=[...f].sort((H,re)=>re.absArea-H.absArea)[0].area>=0?1:-1;for(const H of f){const re=Md(H.points);(H.area>=0?1:-1)===z?g.push(re):T.push(re)}}g.length===0&&g.push(Md(f[0].points));let P=g.length===1?g[0]:Ug(...g);return T.length>0&&(P=Z1(P,...T)),P.isEmpty()?null:P}function o6t(l){return l==="round"?"Round":"Square"}function c6t(l,o,f){const g=Md(l),T=g.offset(o/2,f),P=g.offset(-o/2,f);if(P.isEmpty())return T.isEmpty()?null:T;const O=Z1(T,P);return O.isEmpty()?null:O}function l6t(l,o,f){if(!(o>ku))return null;const g=o6t(f),T=[];for(const P of l){const O=yI(P.points);if(P.closed){if(O.length<3)continue;const z=c6t(O,o,g);z&&!z.isEmpty()&&T.push(z)}else{if(O.length<2)continue;const z=dxe(O,o,g);z.isEmpty()||T.push(z)}}return T.length===0?null:T.length===1?T[0]:Ug(...T)}function u6t(l){const f=l.toPolygons().map(z=>z.map(([H,re])=>[H,re])).map(z=>yI(z)).filter(z=>z.length>=3).map(z=>{const H=yxe(z);return{points:z,area:H,absArea:Math.abs(H),sample:bWe(z)}}).filter(z=>z.absArea>ku);if(f.length===0)return[];const g=f.filter(z=>z.area>0),T=f.filter(z=>z.area<0);if(g.length===0){const z=Md(f[0].points);return z.isEmpty()?[]:[{sketch:z,area:z.area()}]}const P=g.map(z=>({outer:z,holes:[]}));for(const z of T){const H=P.filter(re=>xWe(z.sample,re.outer.points)).sort((re,te)=>re.outer.absArea-te.outer.absArea);H.length>0&&H[0].holes.push(z)}const O=[];for(const z of P){let H=Md(z.outer.points);if(z.holes.length>0){const re=z.holes.map(te=>Md(te.points));H=Z1(H,...re)}H.isEmpty()||O.push({area:Math.abs(H.area()),sketch:H})}return O.sort((z,H)=>H.area-z.area),O}function _6t(l,o){const f=u6t(l);if(f.length===0)return l;const g=f[0].area,T=Math.max(o.minRegionArea,g*o.minRegionAreaRatio);let P=f.filter(O=>O.area+ku>=T);if(P.length===0&&(P=[f[0]]),o.regionSelection==="largest"&&(P=[P[0]]),Number.isFinite(o.maxRegions)){const O=Math.max(1,Math.floor(o.maxRegions));P=P.slice(0,O)}return P.length===1?P[0].sketch:Ug(...P.map(O=>O.sketch))}function f6t(l,o){const f=Number.isFinite(o.maxWidth),g=Number.isFinite(o.maxHeight);if(!f&&!g)return l;const T=l.bounds(),P=T.min,O=T.max,z=Math.max(0,(O[0]??0)-(P[0]??0)),H=Math.max(0,(O[1]??0)-(P[1]??0));let re=Number.POSITIVE_INFINITY;return f&&z>ku&&(re=Math.min(re,o.maxWidth/z)),g&&H>ku&&(re=Math.min(re,o.maxHeight/H)),!Number.isFinite(re)||re<=0||re>=1-ku?l:l.scale(re)}function p6t(l,o){if(!o.centerOnOrigin)return l;const f=l.bounds(),g=f.min,T=f.max,P=((g[0]??0)+(T[0]??0))*.5,O=((g[1]??0)+(T[1]??0))*.5;return Math.abs(P)<=ku&&Math.abs(O)<=ku?l:l.translate(-P,-O)}function d6t(l,o){let f=qO();if(o.invertY){const g=vxe(l.viewBox),T=Mm(l.height,NaN),P=g.length>=4?g[1]+g[3]:Number.isFinite(T)?T:0;f=sI(Dte(0,P),w2e(1,-1))}return Math.abs(o.scale-1)>ku&&(f=sI(w2e(o.scale,o.scale),f)),f}const m6t=new Set(["path","rect","circle","ellipse","line","polyline","polygon"]);function h6t(l,o){const f=[],g=[{tag:"__root__",ctx:{transform:qO(),style:{...jEt},hidden:!1,inDefs:!1}}];let T=!1;const P=/<!--[\s\S]*?-->|<\?[\s\S]*?\?>|<!DOCTYPE[\s\S]*?>|<!\[CDATA\[[\s\S]*?\]\]>|<\/?[^>]+>/gi;let O;for(;(O=P.exec(l))!==null;){const z=O[0];if(z.startsWith("<!--")||z.startsWith("<?")||z.startsWith("<!"))continue;if(z.startsWith("</")){const ht=z.slice(2,-1).trim().toLowerCase();for(;g.length>1;){const xn=g.pop();if(!xn||xn.tag===ht)break}continue}const re=z.endsWith("/>"),te=z.slice(1,z.length-(re?2:1)).trim();if(!te)continue;const W=te.search(/\s/),Ee=(W<0?te:te.slice(0,W)).toLowerCase(),se=W<0?"":te.slice(W+1),me=UEt(se),Xe=g[g.length-1].ctx,it=XEt(Xe.style,me),at=YEt(me.transform);let It=sI(Xe.transform,at);!T&&Ee==="svg"&&(T=!0,It=sI(d6t(me,o),It));const tn=Xe.hidden||it.display==="none"||it.visibility==="hidden"||it.opacity<=ku,At=Xe.inDefs||Ee==="defs"||Ee==="symbol"||Ee==="clipPath"||Ee==="mask"||Ee==="pattern",mt={transform:It,style:it,hidden:tn,inDefs:At};if(!mt.hidden&&!mt.inDefs&&m6t.has(Ee)){const ht=t6t(Ee,me,o.flattenTolerance,o.arcSegments),xn=n6t(ZEt(ht,mt.transform));xn.length>0&&f.push({subpaths:xn,style:{...mt.style}})}re||g.push({tag:Ee,ctx:mt})}return f}function g6t(l={}){const o=l.include??"auto",f=l.regionSelection??"all",g=Number.isFinite(l.flattenTolerance)?Math.max(.01,l.flattenTolerance):.35,T=Number.isFinite(l.arcSegments)?Math.max(2,Math.floor(l.arcSegments)):12,P=Number.isFinite(l.maxRegions)?Math.max(1,Math.floor(l.maxRegions)):Number.POSITIVE_INFINITY,O=Number.isFinite(l.minRegionArea)?Math.max(0,l.minRegionArea):0,z=Number.isFinite(l.minRegionAreaRatio)?Math.max(0,l.minRegionAreaRatio):0,H=Number.isFinite(l.scale)?Math.max(1e-6,l.scale):1,re=Number.isFinite(l.maxWidth)?Math.max(1e-6,l.maxWidth):Number.POSITIVE_INFINITY,te=Number.isFinite(l.maxHeight)?Math.max(1e-6,l.maxHeight):Number.POSITIVE_INFINITY,W=l.centerOnOrigin??!1,Ee=Number.isFinite(l.simplify)?Math.max(0,l.simplify):0,se=l.invertY??!0;return{include:o,regionSelection:f,maxRegions:P,minRegionArea:O,minRegionAreaRatio:z,flattenTolerance:g,arcSegments:T,scale:H,maxWidth:re,maxHeight:te,centerOnOrigin:W,simplify:Ee,invertY:se}}function y6t(l={}){const o=(f,g,T=!0)=>{if(f!=null){if(typeof f!="number"||!Number.isFinite(f))throw new Error(`SVG import option "${g}" must be a finite number`);if(!T&&f<=0)throw new Error(`SVG import option "${g}" must be > 0`)}};if(l.include!=null&&!["auto","fill","stroke","fill-and-stroke"].includes(l.include))throw new Error('SVG import option "include" must be one of: auto, fill, stroke, fill-and-stroke');if(l.regionSelection!=null&&!["all","largest"].includes(l.regionSelection))throw new Error('SVG import option "regionSelection" must be one of: all, largest');if(o(l.maxRegions,"maxRegions"),o(l.minRegionArea,"minRegionArea"),o(l.minRegionAreaRatio,"minRegionAreaRatio"),o(l.flattenTolerance,"flattenTolerance",!1),o(l.arcSegments,"arcSegments",!1),o(l.scale,"scale",!1),o(l.maxWidth,"maxWidth",!1),o(l.maxHeight,"maxHeight",!1),o(l.simplify,"simplify"),l.centerOnOrigin!=null&&typeof l.centerOnOrigin!="boolean")throw new Error('SVG import option "centerOnOrigin" must be a boolean');if(l.invertY!=null&&typeof l.invertY!="boolean")throw new Error('SVG import option "invertY" must be a boolean')}function v6t(l,o,f){return f==="fill"?l:f==="stroke"?o:f==="fill-and-stroke"?[...l,...o]:l.length>0?l:o}function qze(l,o={}){if(typeof l!="string"||l.trim().length===0)throw new Error("SVG import requires non-empty SVG content");if(!/<svg[\s>]/i.test(l))throw new Error("SVG import expects content containing an <svg> root element");y6t(o);const f=g6t(o),g=h6t(l,f);if(g.length===0)throw new Error("SVG import produced no supported shape geometry");const T=[],P=[];for(const H of g){if(r6t(H.style)){const re=a6t(H.subpaths,H.style.fillRule);re&&!re.isEmpty()&&T.push(re)}if(i6t(H.style)){const re=l6t(H.subpaths,H.style.strokeWidth,H.style.strokeJoin);re&&!re.isEmpty()&&P.push(re)}}const O=v6t(T,P,f.include);if(O.length===0)throw new Error("SVG import found no fill/stroke geometry after style filtering");let z=O.length===1?O[0]:Ug(...O);if(z=_6t(z,f),z=f6t(z,f),f.simplify>0&&(z=z.simplify(f.simplify)),z.isEmpty())throw new Error("SVG import generated an empty sketch");return z=p6t(z,f),z}const E2e=1e-6;function HN(l,o){return l[0]*o[0]+l[1]*o[1]+l[2]*o[2]}function b6t(l,o){return[l[0]-o[0],l[1]-o[1],l[2]-o[2]]}function Wze(l,o){return Math.hypot(l,o)}function Ate(l){const o=Math.hypot(l[0],l[1],l[2]);return o<1e-12?[0,0,1]:[l[0]/o,l[1]/o,l[2]/o]}function WD(l,o,f=E2e){return Math.abs(l-o)<=f}function Vze(l,o,f,g){return{kind:"project",sourceShape:m_(l),plane:{origin:[o.origin[0],o.origin[1],o.origin[2]],u:[o.u[0],o.u[1],o.u[2]],v:[o.v[0],o.v[1],o.v[2]],normal:[o.normal[0],o.normal[1],o.normal[2]]},sourcePlacement:f?i6(f):void 0,replayReason:g,transforms:[]}}const x6t={matrix:Ea.identity().toArray(),placement:{workplane:{origin:[0,0,0],u:[1,0,0],v:[0,1,0],normal:[0,0,1],source:{kind:"face-ref"}},u:0,v:0,protrude:0,selfAnchor:"center"}};function tte(l){return{profile:Fd(l.profile),placement:rT(l.placement)}}function bxe(l){return{origin:[l.placement.workplane.origin[0],l.placement.workplane.origin[1],l.placement.workplane.origin[2]],u:Ate([l.placement.workplane.u[0],l.placement.workplane.u[1],l.placement.workplane.u[2]]),v:Ate([l.placement.workplane.v[0],l.placement.workplane.v[1],l.placement.workplane.v[2]]),normal:Ate([l.placement.workplane.normal[0],l.placement.workplane.normal[1],l.placement.workplane.normal[2]])}}function S6t(l){const o=Math.hypot(l[0],l[1],l[2]);if(o<1e-12)return Ea.identity().toArray();const f=l[0]/o,g=l[1]/o,T=l[2]/o;return[1-2*f*f,-2*f*g,-2*f*T,0,-2*g*f,1-2*g*g,-2*g*T,0,-2*T*f,-2*T*g,1-2*T*T,0,0,0,0,1]}function T6t(l){switch(l.kind){case"translate":return Ea.translation(l.x,l.y,l.z).toArray();case"rotate":return Ea.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg).toArray();case"scale":return Ea.scale([l.x,l.y,l.z]).toArray();case"rotateAround":return Ea.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]).toArray();case"mirror":return S6t([l.normalX,l.normalY,l.normalZ])}}function k6t(l,o){const f=T6t(o),g=Ea.from(f),T=rT(l);return{matrix:Ea.from(T.matrix).mul(f).toArray(),placement:{...T.placement,workplane:{...T.placement.workplane,origin:g.point(T.placement.workplane.origin),u:g.vector(T.placement.workplane.u),v:g.vector(T.placement.workplane.v),normal:g.vector(T.placement.workplane.normal)}}}}function yne(l,o,f){const g=Ea.from(o.matrix),T=g.point([0,0,0]),P=g.vector([1,0,0]),O=g.vector([0,1,0]),z=g.vector([0,0,1]),H=Math.abs(HN(Ate(z),f.normal));if(!WD(H,1,1e-5))return{reason:"projection replay currently requires the target plane to stay parallel to the source workplane."};const re=HN(P,f.u),te=HN(O,f.u),W=HN(P,f.v),Ee=HN(O,f.v),se=Wze(re,W),me=Wze(te,Ee);if(se<E2e||me<E2e)return{reason:"projection replay requires a non-degenerate in-plane basis."};const Xe=re*te+W*Ee;if(Math.abs(Xe)>1e-5*Math.max(1,se*me))return{reason:"projection replay does not support in-plane shear from downstream 3D transforms yet."};const it=re/se,at=te/me,It=W/se,tn=Ee/me,At=it*tn-at*It;if(!WD(Math.abs(At),1,1e-5))return{reason:"projection replay requires a rigid or mirrored in-plane basis."};let mt=Fd(l);if((!WD(se,1)||!WD(me,1))&&(mt=Db(mt,{kind:"scale",x:se,y:me})),At<0){mt=Db(mt,{kind:"mirror",normalX:1,normalY:0});const $r=Math.atan2(-It,-it)*180/Math.PI;WD($r,0)||(mt=Db(mt,{kind:"rotate",degrees:$r}))}else{const $r=Math.atan2(It,it)*180/Math.PI;WD($r,0)||(mt=Db(mt,{kind:"rotate",degrees:$r}))}const ht=b6t(T,f.origin),xn=HN(ht,f.u),Pn=HN(ht,f.v);return(!WD(xn,0)||!WD(Pn,0))&&(mt=Db(mt,{kind:"translate",x:xn,y:Pn})),{profile:mt}}function C6t(l,o,f){return yne(l,o,f)}function SWe(l){return{kind:"circle",radius:l,transforms:[]}}function w6t(l){var o,f;return Math.max(l.hole.radius,((o=l.hole.counterbore)==null?void 0:o.radius)??0,((f=l.hole.countersink)==null?void 0:f.radius)??0)}function Lbe(l){return{profile:Fd(l),placement:rT(x6t)}}function E6t(l,o){const f=yne(l.profile,l.placement,bxe(o));return f.profile?{ok:!0,context:{profile:f.profile,placement:rT(o)}}:{ok:!1,reason:f.reason??"projection replay could not map a compatible source plane."}}function P6t(l,o){const f=yne(SWe(w6t(o)),o.placement,bxe(l.placement));if(!f.profile)return{ok:!1,reason:`projection replay can only absorb hole rewrites when the hole axis stays parallel to the projected source basis. ${f.reason??""}`.trim()};const g=iT("difference",[l.profile,f.profile]);return g?{ok:!0,context:{profile:g,placement:rT(l.placement)}}:{ok:!1,reason:"projection replay could not subtract the hole silhouette from the projected source profile."}}function D6t(l,o){const f=yne(o.profile,o.placement,bxe(l.placement));if(!f.profile)return{ok:!1,reason:`projection replay can only absorb cut rewrites when the cut workplane stays parallel to the projected source basis. ${f.reason??""}`.trim()};const g=iT("difference",[l.profile,f.profile]);return g?{ok:!0,context:{profile:g,placement:rT(l.placement)}}:{ok:!1,reason:"projection replay could not subtract the cut silhouette from the projected source profile."}}function QN(l){if(!l)return{ok:!1,reason:"projection replay currently requires compiler-owned source intent."};switch(l.kind){case"queryOwner":return QN(l.base);case"transform":{const o=QN(l.base);if(!o.ok)return o;let f=tte(o.context);for(const g of l.steps){if(g.kind==="workplanePlacement"){f.placement=rT({matrix:g.matrix,placement:g.placement});continue}f.placement=k6t(f.placement,g)}return{ok:!0,context:f}}case"extrude":return l.scaleTop?{ok:!1,reason:"projection replay currently supports straight extrusions without tapered tops."}:{ok:!0,context:Lbe(l.profile)};case"box":return{ok:!0,context:Lbe({kind:"rect",width:l.x,height:l.y,center:l.center,transforms:[]})};case"cylinder":return{ok:!0,context:Lbe(SWe(Math.max(Math.abs(l.radius),Math.abs(l.radiusTop??l.radius))))};case"shell":{const o=QN(l.base);return o.ok?{ok:!0,context:tte(o.context)}:o}case"hole":{const o=QN(l.base);return o.ok?l.extent.kind==="two-sided"&&Rm(l.extent).kind==="through"?{ok:!1,reason:"projection replay currently supports one-sided through holes only; reverse two-sided spans can change silhouette coverage outside the defended subset."}:Rm(l.extent).kind!=="through"?{ok:!0,context:tte(o.context)}:P6t(o.context,l):o}case"cut":{const o=QN(l.base);return o.ok?l.extent.kind==="two-sided"&&Rm(l.extent).kind==="through"?{ok:!1,reason:"projection replay currently supports one-sided through cuts only; reverse two-sided spans can change silhouette coverage outside the defended subset."}:l.taper||Rm(l.extent).kind!=="through"?l.taper&&Rm(l.extent).kind==="through"?{ok:!1,reason:"projection replay currently supports straight through cuts without tapered side walls."}:{ok:!0,context:tte(o.context)}:D6t(o.context,l):o}case"boolean":{if(l.op!=="union")return{ok:!1,reason:`projection replay currently supports boolean union sources only; boolean ${l.op} can change shadow coverage along the projection normal.`};const o=[];for(let P=0;P<l.shapes.length;P+=1){const O=QN(l.shapes[P]);if(!O.ok)return{ok:!1,reason:`projection replay could not derive a compatible union operand at index ${P}: ${O.reason}`};o.push(O.context)}if(o.length===0)return{ok:!1,reason:"projection replay cannot derive an empty boolean union source."};const f=rT(o[0].placement),g=[];for(let P=0;P<o.length;P+=1){const O=E6t(o[P],f);if(!O.ok)return{ok:!1,reason:`projection replay could not align union operand ${P} to a shared projection basis: ${O.reason}`};g.push(O.context.profile)}const T=iT("union",g);return T?{ok:!0,context:{profile:T,placement:f}}:{ok:!1,reason:"projection replay could not combine the projected union operands into one 2D profile."}}case"sphere":return{ok:!1,reason:"projection replay currently needs a defended planar source basis and does not derive one from spheres yet."};case"sheetMetal":return{ok:!1,reason:"projection replay currently does not derive a defended planar projection basis from sheet-metal semantic bodies yet."};case"revolve":return{ok:!1,reason:"projection replay currently supports projection-driven descendants from extrude/box/cylinder rewrite flows, not revolves."};case"loft":case"sweep":return{ok:!1,reason:`projection replay currently does not reduce ${l.kind} sources to one defended planar projection basis.`};case"hull":return{ok:!1,reason:"projection replay currently does not reduce hull sources to one defended planar projection basis."};case"trimByPlane":return{ok:!1,reason:"projection replay currently does not defend trim-by-plane sources because the kept silhouette depends on the trim half-space."};case"fillet":case"chamfer":return{ok:!1,reason:`projection replay currently does not absorb ${l.kind} silhouette changes into the exact subset.`}}}function A6t(l,o){var O;const f=c4(l);if(!f)return null;const g=Aqe(o),T=QN(f);if(!T.ok)return Vze(f,g,(O=nwt(l))==null?void 0:O.placement,T.reason);const P=C6t(T.context.profile,T.context.placement,g);return P.profile?{kind:"project",sourceShape:m_(f),plane:{origin:[g.origin[0],g.origin[1],g.origin[2]],u:[g.u[0],g.u[1],g.u[2]],v:[g.v[0],g.v[1],g.v[2]],normal:[g.normal[0],g.normal[1],g.normal[2]]},sourcePlacement:i6(T.context.placement.placement),replayProfile:P.profile,transforms:[]}:Vze(f,g,T.context.placement.placement,P.reason??"projection replay could not derive a supported 2D profile.")}function TWe(l,o){const f=Aqe(o),g=Nqe(f);return l.transform(g)}function N6t(l,o){const f=TWe(l,o);return new Eo(f.slice(0))}function I6t(l,o){const f=TWe(l,o),g=new Eo(f.project()),T=A6t(l,o);return T?By(g,T):g}function xxe(l){if(!l||typeof l!="object")return!1;const o=l;return typeof o.name=="string"&&Array.isArray(o.normal)&&Array.isArray(o.center)}function ZE(l){return Number.isFinite(l)&&l>0}function P2e(l,o){return l[0]*o[0]+l[1]*o[1]+l[2]*o[2]}function nne(l){const o=Math.hypot(l[0],l[1],l[2]);if(o<1e-12)throw new Error("Hole/cut feature direction could not be normalized.");return[l[0]/o,l[1]/o,l[2]/o]}function F6t(l){const{workplane:o,u:f,v:g,protrude:T}=l,P=[o.origin[0]+o.u[0]*f+o.v[0]*g+o.normal[0]*T,o.origin[1]+o.u[1]*f+o.v[1]*g+o.normal[1]*T,o.origin[2]+o.u[2]*f+o.v[2]*g+o.normal[2]*T];return[o.u[0],o.u[1],o.u[2],0,o.v[0],o.v[1],o.v[2],0,o.normal[0],o.normal[1],o.normal[2],0,P[0],P[1],P[2],1]}function O6t(l,o){return o?Qqe(l).some(f=>Pb(f,o)):!0}function Sxe(l,o,f){if(!O6t(l,o))throw new Error(`${f} requires a face/workplane owned by the target shape or one of its preserved query ancestors.`)}function Txe(l,o,f){const g=hkt(c4(l),f);if(g)throw new Error(`${o} ${g}`)}function M6t(l){const o=l.boundingBox(),[f,g,T]=o.min,[P,O,z]=o.max;return[[f,g,T],[f,g,z],[f,O,T],[f,O,z],[P,g,T],[P,g,z],[P,O,T],[P,O,z]]}function L6t(l,o,f){const g=nne(f);let T=0;for(const re of M6t(l)){const te=[re[0]-o[0],re[1]-o[1],re[2]-o[2]];T=Math.max(T,P2e(te,g))}if(T>1e-6)return T;const P=l.boundingBox(),O=P.max[0]-P.min[0],z=P.max[1]-P.min[1],H=P.max[2]-P.min[2];return Math.max(Math.hypot(O,z,H),1)}function R6t(l,o){return xxe(o)?o:l.face(o)}function j6t(l,o,f,g,T={requireDefendedQuery:!0}){const P=xxe(f)?rM(f):rM(l,f);return Sxe(o,P.source.owner,g),T.requireDefendedQuery&&Txe(o,g,P.source),{face:R6t(l,f),query:P.source}}function B6t(l,o,f,g){if(f.planar===!1||!f.uAxis||!f.vAxis)throw new Error(`${g} upToFace currently requires a planar termination face.`);const T=nne(o),P=nne(f.normal);if(Math.abs(Math.abs(P2e(T,P))-1)>1e-6)throw new Error(`${g} upToFace currently requires a termination face parallel to the feature direction.`);const O=[f.center[0]-l[0],f.center[1]-l[1],f.center[2]-l[2]],z=P2e(O,T);if(!(z>1e-6))throw new Error(`${g} upToFace requires the termination face to lie in the feature direction.`);return z}function jJ(l,o,f,g,T,P,O,z={allowThrough:!0}){if(+(T.depth!=null)+ +(T.upToFace!=null)+ +(T.through===!0)!==1)throw new Error(`${P} ${O} extent must specify exactly one of through, depth, or upToFace.`);if(T.through){if(!z.allowThrough)throw new Error(`${P} reverse two-sided extents do not support through termination yet.`);return{kind:"through",depth:L6t(o,f,g)}}if(T.upToFace!=null){const re=j6t(l,o,T.upToFace,P,{requireDefendedQuery:!1});return{kind:"upToFace",depth:B6t(f,g,re.face,P),face:re.query}}if(!ZE(T.depth))throw new Error(`${P} ${O} extent requires a positive finite blind depth.`);return{kind:"blind",depth:T.depth}}function kWe(l,o,f,g,T,P){if(T.extent){if(T.depth!=null||T.upToFace!=null)throw new Error(`${P} accepts either top-level depth/upToFace or extent.forward/extent.reverse, not both.`);if(!T.extent.forward)throw new Error(`${P} extent.forward is required when using structured feature extents.`);const O=jJ(l,o,f,[-g[0],-g[1],-g[2]],T.extent.forward,P,"forward");if(!T.extent.reverse)return O;const z=jJ(l,o,f,nne(g),T.extent.reverse,P,"reverse",{allowThrough:!1});if(z.kind==="through")throw new Error(`${P} reverse two-sided extents do not support through termination yet.`);return{kind:"two-sided",forward:O,reverse:z}}if(T.depth!=null&&T.upToFace!=null)throw new Error(`${P} accepts either depth or upToFace, not both.`);return T.upToFace!=null?jJ(l,o,f,[-g[0],-g[1],-g[2]],{upToFace:T.upToFace},P,"forward"):T.depth==null?jJ(l,o,f,[-g[0],-g[1],-g[2]],{through:!0},P,"forward"):jJ(l,o,f,[-g[0],-g[1],-g[2]],{depth:T.depth},P,"forward")}function z6t(l){var f,g;const o={radius:l.diameter/2};if(l.counterbore&&l.countersink)throw new Error("Shape.hole() currently supports either counterbore or countersink, not both at once.");if(l.counterbore){if(!ZE(l.counterbore.diameter)||l.counterbore.diameter<=l.diameter)throw new Error("Shape.hole() counterbore diameter must be greater than the hole diameter.");if(!ZE(l.counterbore.depth))throw new Error("Shape.hole() counterbore depth must be a positive finite value.");o.counterbore={radius:l.counterbore.diameter/2,depth:l.counterbore.depth}}if(l.countersink){if(!ZE(l.countersink.diameter)||l.countersink.diameter<=l.diameter)throw new Error("Shape.hole() countersink diameter must be greater than the hole diameter.");const T=l.countersink.angleDeg??90;if(!Number.isFinite(T)||T<=0||T>=180)throw new Error("Shape.hole() countersink angleDeg must be between 0 and 180 degrees.");const P=T*Math.PI/360,O=Math.tan(P);if(!(O>1e-9))throw new Error("Shape.hole() countersink angleDeg is too small to form a defended taper.");o.countersink={radius:l.countersink.diameter/2,angleDeg:T,depth:(l.countersink.diameter-l.diameter)/2/O}}if(l.thread){const T=(f=l.thread.designation)==null?void 0:f.trim(),P=(g=l.thread.class)==null?void 0:g.trim();if(T==="")throw new Error("Shape.hole() thread.designation must be a non-empty string when provided.");if(P==="")throw new Error("Shape.hole() thread.class must be a non-empty string when provided.");if(l.thread.pitch!=null&&!ZE(l.thread.pitch))throw new Error("Shape.hole() thread.pitch must be a positive finite value when provided.");if(l.thread.depth!=null&&!ZE(l.thread.depth))throw new Error("Shape.hole() thread.depth must be a positive finite value when provided.");if(l.thread.modeled===!0)throw new Error("Shape.hole() does not model helical threads yet; pass thread metadata with modeled omitted/false for deferred thread intent.");if(T==null&&P==null&&l.thread.pitch==null&&l.thread.depth==null&&l.thread.handedness==null&&l.thread.modeled==null)throw new Error("Shape.hole() thread metadata requires at least one designation, pitch, class, handedness, or depth value.");o.thread={designation:T,pitch:l.thread.pitch,class:P,handedness:l.thread.handedness,depth:l.thread.depth,modeled:!1}}return o}function J6t(l,o){var T,P,O;if((l.counterbore||l.countersink)&&o.kind==="two-sided")throw new Error("Shape.hole() does not yet combine reverse two-sided extents with counterbore or countersink heads.");const f=Rm(o),g=((T=l.counterbore)==null?void 0:T.depth)??((P=l.countersink)==null?void 0:P.depth)??0;if(g>0&&g>=f.depth-1e-6)throw l.counterbore?new Error("Shape.hole() counterbore depth must leave some straight hole depth below the bore."):new Error("Shape.hole() countersink diameter/angle must leave some straight hole depth below the sink.");if(((O=l.thread)==null?void 0:O.depth)!=null&&l.thread.depth>f.depth+1e-6)throw new Error("Shape.hole() thread.depth cannot exceed the primary forward hole depth.")}function q6t(l,o,f){if(o.taperScale==null)return;if(f.kind==="two-sided")throw new Error("Shape.cutout() does not yet combine taperScale with reverse two-sided extents.");if(!l)throw new Error("Shape.cutout() requires a compile-covered sketch profile before taperScale can be validated.");if(l.kind!=="circle"&&l.kind!=="rect"&&l.kind!=="roundedRect")throw new Error("Shape.cutout() taperScale currently supports circle, rect, and roundedRect sketch profiles only.");const g=Array.isArray(o.taperScale)?o.taperScale:[o.taperScale,o.taperScale];if(g.length!==2||!ZE(g[0])||!ZE(g[1]))throw new Error("Shape.cutout() taperScale must be a positive finite number or [x, y] pair.");if(l.kind==="circle"&&Math.abs(g[0]-g[1])>1e-6)throw new Error("Shape.cutout() circular tapered cuts currently require a uniform taperScale.");return{scale:[g[0],g[1]]}}function CWe(l,o,f){if(!l)return null;const g=une(o);return hq(ixe(l,f(g)),g)}function wWe(l,o){if(!o)throw new Error("Hole/cut feature could not record compiler intent for this target.");const f=Yqe(l),g=M_(o,l.colorHex,{backend:f.backend,representation:f.representation,fidelity:f.fidelity,topology:"none",sources:["boolean",...f.sources]});return Yte(g,fxe(l)),mne(g,Xqe(l),{merge:!1}),hne(g,{backend:f.backend,representation:f.representation,fidelity:f.fidelity,topology:"none",sources:["boolean",...f.sources]}),g}function W6t(l,o,f,g){const T=xxe(f)?rM(f):rM(l,f);return Sxe(o,T.source.owner,"Shape.hole()"),Txe(o,"Shape.hole()",T.source),{placement:{placement:{workplane:c2e(T),u:g.u??0,v:g.v??0,protrude:0,selfAnchor:"center"},matrix:F6t({workplane:c2e(T),u:g.u??0,v:g.v??0,protrude:0})},extent:kWe(l,o,T.origin,T.normal,{depth:g.depth,upToFace:g.upToFace,extent:g.extent},"Shape.hole()")}}function EWe(l,o,f,g){if(!ZE(g.diameter))throw new Error("Shape.hole() requires a positive finite diameter.");const T=c4(l);if(!T)throw new Error("Shape.hole() currently requires a compile-covered target shape.");const{placement:P,extent:O}=W6t(o,l,f,g),z=z6t(g);J6t(z,O);const H=CWe($kt(T,P,z,O),"hole",re=>Rkt(re,T,P.placement,z,O));return wWe(l,H)}function PWe(l,o,f={}){const g=c4(l);if(!g)throw new Error("Shape.cutout() currently requires a compile-covered target shape.");const T=um(o);if(!T)throw new Error("Shape.cutout() requires a compile-covered sketch profile.");const P=r6(o),O=a4(o);if(!P||!O)throw new Error("Shape.cutout() requires a sketch placed with Sketch.onFace(...).");Sxe(l,P.workplane.source.owner,"Shape.cutout()"),Txe(l,"Shape.cutout()",P.workplane.source);const z=kWe(l,l,P.workplane.origin,P.workplane.normal,{depth:f.depth,upToFace:f.upToFace,extent:f.extent},"Shape.cutout()"),H=q6t(T,f,z),re=CWe(Hkt(g,{matrix:O,placement:i6(P)},T,z,H),"cut",te=>jkt(te,g,P,T,z));return wWe(l,re)}na.prototype.hole=function(o,f){return EWe(this,this,o,f)};na.prototype.cutout=function(o,f={}){return PWe(this,o,f)};po.prototype.hole=function(o,f){return EWe(this.toShape(),this,o,f)};po.prototype.cutout=function(o,f={}){return PWe(this.toShape(),o,f)};const V6t={fidelity:"kernel-native",topology:"synthetic",sources:["sheet-metal"]};function U6t(l){var f,g;const o=l.bendRadius+l.thickness;return{kind:((f=l.cornerRelief)==null?void 0:f.kind)??"rect",size:((g=l.cornerRelief)==null?void 0:g.size)??o}}function $6t(l){return{panel:{width:l.panel.width,height:l.panel.height},thickness:l.thickness,bendRadius:l.bendRadius,bendAllowance:{kind:"k-factor",kFactor:l.bendAllowance.kFactor},cornerRelief:U6t(l),flanges:[]}}function H6t(l){return l==="panel"?"panel":`"${l}"`}function G6t(l){return{region:l.region,sketch:l.sketch.clone(),u:l.u,v:l.v,selfAnchor:l.selfAnchor}}function X6t(l){if(r6(l)!=null)throw new Error("SheetMetalPart.cutout() expects an unplaced 2D sketch. Pass the profile before calling onFace(...).");if(!um(l))throw new Error("SheetMetalPart.cutout() requires a compile-covered sketch profile.")}function Y6t(l,o){const f=s6({kind:"sheetMetal",model:qte(l),output:o},`sheet-metal:${o}`);if(!f)throw new Error("sheetMetal() could not build the compiler-owned base plan.");return M_(f,void 0,V6t)}function Q6t(l,o){const f=new Set(oTt(l));if(!f.has(o)&&o!=="panel")throw new Error(`SheetMetalPart.cutout() cannot target ${H6t(o)} because that flange has not been added. Supported planar regions: ${Array.from(f).join(", ")}`)}class cq{constructor(o,f=[]){tu(this,"model");tu(this,"cutouts");this.model=qte(o),this.cutouts=f.map(G6t)}flange(o,f){const g=qte(this.model);if(g.flanges.find(O=>O.edge===o))throw new Error(`${o} flange is already defined on this SheetMetalPart.`);g.flanges.push({edge:o,length:f.length,angleDeg:f.angleDeg??90});const P=Wte(g);if(P)throw new Error(P);return eM(g),new cq(g,this.cutouts)}cutout(o,f,g={}){if(!cTt(o))throw new Error(`SheetMetalPart.cutout() does not support region "${String(o)}".`);return Q6t(this.model,o),X6t(f),new cq(this.model,[...this.cutouts,{region:o,sketch:f.clone(),u:g.u??0,v:g.v??0,selfAnchor:g.selfAnchor??"center"}])}regionNames(){return["panel",...Array.from(new Set(this.model.flanges.flatMap(o=>[`bend-${o.edge}`,`flange-${o.edge}`])))]}folded(){return this.buildOutput("folded")}flatPattern(){return this.buildOutput("flat")}buildOutput(o){const f=Wte(this.model);if(f)throw new Error(f);eM(this.model);let g=Y6t(this.model,o);for(const T of this.cutouts){const P=T.sketch.onFace(g,T.region,{u:T.u,v:T.v,selfAnchor:T.selfAnchor});g=g.cutout(P)}return g}}function Z6t(l){const o=$6t(l),f=Wte(o);if(f)throw new Error(f);return eM(o),new cq(o)}let vne=[],lq={},fI=[];function K6t(){vne=[],fI=[]}function ePt(l){lq=l}function Uze(){return vne}function tPt(l,o){fI.push(l);try{return o()}finally{fI.pop()}}function DWe(l,o){return Object.prototype.hasOwnProperty.call(l,o)}function AWe(l,o,f={}){const g=fI[fI.length-1],T=g!=null&&g.namePrefix?`${g.namePrefix} / ${l}`:l,P=g==null?void 0:g.localOverrides,O=!!(P&&DWe(P,l)),z=(O?P[l]:void 0)??lq[T]??lq[l]??o,H=f.integer??!1,re=H?Math.round(z):z,te=f.min??0,W=f.max??o*4,Ee=f.step??(H||W-te>100?1:.1);if(!O){const se=H?Math.round(o):o;vne.push({name:T,value:re,defaultValue:se,min:te,max:W,step:Ee,unit:f.unit,integer:H,reverse:f.reverse})}return re}function nPt(l,o){const f=fI[fI.length-1],g=f!=null&&f.namePrefix?`${f.namePrefix} / ${l}`:l,T=f==null?void 0:f.localOverrides,P=!!(T&&DWe(T,l)),O=o?1:0,H=((P?T[l]:void 0)??lq[g]??lq[l]??O)>=.5?1:0;return P||vne.push({name:g,value:H,defaultValue:O,min:0,max:1,step:1,boolean:!0}),H===1}function rPt(l,o,f,g={}){const T=g.axis??[0,0,1],P=g.min??0,O=g.max??360,z=g.default??0,H=AWe(l,z,{min:P,max:O,unit:g.unit??"°",reverse:g.reverse});return o.rotateAround(T,H,f)}function kxe(l){if(typeof l!="string")return;const o=l.trim();return o.length>0?o:void 0}function iPt(l){return!!l&&typeof l=="object"&&typeof l.name=="string"}function sPt(l){const o=kxe(l.name);if(!o)throw new Error("group(...) named items require a non-empty name");const f=l.shape!==void 0,g=l.sketch!==void 0,T=Array.isArray(l.group);if(Number(f)+Number(g)+Number(T)!==1)throw new Error(`group(...) named item "${o}" must provide exactly one of shape, sketch, or group`);if(f){if(!(l.shape instanceof na)&&!(l.shape instanceof po)&&!(l.shape instanceof lu))throw new Error(`group(...) named item "${o}" shape must be a Shape, TrackedShape, or ShapeGroup`);return l.shape}if(g){if(!(l.sketch instanceof Eo))throw new Error(`group(...) named item "${o}" sketch must be a Sketch`);return l.sketch}return Cxe(...l.group)}function aPt(l){const o=[],f=[];return l.forEach(g=>{if(iPt(g)){o.push(sPt(g)),f.push(kxe(g.name));return}o.push(g),f.push(void 0)}),{children:o,childNames:f}}class lu{constructor(o,f){tu(this,"children");tu(this,"childNames");if(f&&f.length!==o.length)throw new Error("ShapeGroup childNames must match children length");this.children=[...o],this.childNames=this.children.map((g,T)=>kxe(f==null?void 0:f[T]))}childName(o){return this.childNames[o]}mapChildren(o){return new lu(this.children.map(o),this.childNames)}clone(){return this.mapChildren(o=>(o instanceof lu||o instanceof po||o instanceof na,o.clone()))}duplicate(){return this.clone()}translate(o,f,g){return this.mapChildren(T=>T instanceof lu||T instanceof po||T instanceof na?T.translate(o,f,g):T.translate(o,f))}_bbox(){let o=[1/0,1/0,1/0],f=[-1/0,-1/0,-1/0];for(const g of this.children){if(g instanceof lu){const O=g._bbox();for(let z=0;z<3;z++)O.min[z]<o[z]&&(o[z]=O.min[z]),O.max[z]>f[z]&&(f[z]=O.max[z]);continue}const T=g instanceof po?g.toShape():g instanceof na?g:null;if(!T)continue;const P=T.boundingBox();for(let O=0;O<3;O++)P.min[O]<o[O]&&(o[O]=P.min[O]),P.max[O]>f[O]&&(f[O]=P.max[O])}return{min:o,max:f}}boundingBox(){const o=this._bbox();return{min:o.min,max:o.max}}resolveRotatePoint(o){if(Array.isArray(o))return[o[0],o[1],o[2]];const f=this._bbox();return t4(f.min,f.max,o)}moveTo(o,f,g){const T=this._bbox();return this.translate(o-T.min[0],f-T.min[1],g-T.min[2])}moveToLocal(o,f,g,T){let P;return o instanceof lu?P=o._bbox():P={min:(o instanceof po?o.toShape():o).boundingBox().min},this.moveTo(P.min[0]+f,P.min[1]+g,P.min[2]+T)}attachTo(o,f,g="center",T){const P=o instanceof lu?o._bbox():(()=>{const se=(o instanceof po?o.toShape():o).boundingBox();return{min:se.min,max:se.max}})(),O=this._bbox(),z=o instanceof lu||QJe(f)?t4(P.min,P.max,f):(o instanceof po,o.referencePoint(f)),H=t4(O.min,O.max,g);let re=z[0]-H[0],te=z[1]-H[1],W=z[2]-H[2];return T&&(re+=T[0],te+=T[1],W+=T[2]),this.translate(re,te,W)}onFace(o,f,g={}){const T=g.u??0,P=g.v??0,O=g.protrude??0,z={front:"back",back:"front",left:"right",right:"left",top:"bottom",bottom:"top"},H={front:(re,te,W)=>[re,-W,te],back:(re,te,W)=>[re,W,te],left:(re,te,W)=>[-W,re,te],right:(re,te,W)=>[W,re,te],top:(re,te,W)=>[re,te,W],bottom:(re,te,W)=>[re,te,-W]};return this.attachTo(o,f,z[f],H[f](T,P,O))}rotate(o,f,g){return this.mapChildren(T=>T instanceof lu||T instanceof po||T instanceof na?T.rotate(o,f,g):T.rotate(o))}rotateAround(o,f,g=[0,0,0]){return this.transform(Ea.rotationAxis(o,f,g))}rotateAroundTo(o,f,g,T,P={}){return this.transform(Ea.rotateAroundTo(o,f,this.resolveRotatePoint(g),this.resolveRotatePoint(T),P))}pointAlong(o){const[f,g,T]=o,P=Math.sqrt(f*f+g*g+T*T)||1,O=f/P,z=g/P,H=T/P,re=-z,te=O,W=0,Ee=Math.sqrt(re*re+te*te+W*W),se=H;if(Ee<1e-10)return se>0?this:this.rotate(180,0,0);const me=Math.atan2(Ee,se)*180/Math.PI,Xe=[re/Ee,te/Ee,W/Ee];return this.rotateAround(Xe,me)}transform(o){return new lu(this.children.map(f=>{if(f instanceof lu||f instanceof po||f instanceof na)return f.transform(o);throw new Error("ShapeGroup.transform only supports 3D children (Shape/TrackedShape/ShapeGroup). For Sketch children, use 2D transforms (translate/rotate/scale/mirror).")}),this.childNames)}scale(o){return this.mapChildren(f=>f instanceof lu||f instanceof po||f instanceof na?f.scale(o):f.scale(typeof o=="number"?o:[o[0],o[1]]))}mirror(o){return this.mapChildren(f=>f instanceof lu||f instanceof po||f instanceof na?f.mirror(o):f.mirror([o[0],o[1]]))}color(o){return this.mapChildren(f=>(f instanceof lu||f instanceof po||f instanceof na,f.color(o)))}}function Cxe(...l){const o=aPt(l);return new lu(o.children,o.childNames)}function NWe(l){const o=["part","qty","material","process","tolerance","notes"],f=T=>`"${T.replace(/"/g,'""')}"`,g=[o.join(",")];for(const T of l)g.push([f(T.part),String(T.qty),f(T.material??""),f(T.process??""),f(T.tolerance??""),f(T.notes??"")].join(","));return g.join(`
1
+ var ASt=Object.defineProperty;var NSt=(l,o,f)=>o in l?ASt(l,o,{enumerable:!0,configurable:!0,writable:!0,value:f}):l[o]=f;var tu=(l,o,f)=>NSt(l,typeof o!="symbol"?o+"":o,f);function a2e(l,o){return[l[0]-o[0],l[1]-o[1],l[2]-o[2]]}function nq(l,o){return[l[0]*o,l[1]*o,l[2]*o]}function o2e(l,o){return l[0]*o[0]+l[1]*o[1]+l[2]*o[2]}function ISt(l,o){return[l[1]*o[2]-l[2]*o[1],l[2]*o[0]-l[0]*o[2],l[0]*o[1]-l[1]*o[0]]}function Rte(l){return Math.hypot(l[0],l[1],l[2])}function ZBe(l,o){const f=o2e(l,o);return{axial:f,radial:a2e(l,nq(o,f))}}function jte(l,o,f){const g=Rte(l),T=Rte(o);if(g<1e-10||T<1e-10)return 0;const P=nq(l,1/g),O=nq(o,1/T),z=o2e(f,ISt(P,O)),H=o2e(P,O);return Math.atan2(z,H)*180/Math.PI}function FSt(l,o,f){const g=jte(l,o,f),T=jte(l,nq(o,-1),f);return Math.abs(g)<=Math.abs(T)?g:T}function VJe(l,o,f,g,T={}){const P=T.mode??"plane",O=X2e(l),z=a2e(f,o),H=a2e(g,o),re=ZBe(z,O),te=ZBe(H,O),W=Rte(re.radial),Ee=Rte(te.radial);if(W<1e-10){if(P==="line"&&Ee>=1e-10)throw new Error("rotateAroundTo(...): moving point lies on the rotation axis, so line alignment is impossible");return 0}if(P==="plane"){if(Ee<1e-10)throw new Error("rotateAroundTo(...): target point lies on the rotation axis, so the target plane is undefined");return jte(re.radial,te.radial,O)}if(Ee<1e-10)throw new Error("rotateAroundTo(...): target line lies on the rotation axis, but the moving point does not");const se=1e-8*Math.max(1,Math.abs(re.axial),Math.abs(te.axial)),me=1e-8*Math.max(1,W,Ee);if(Math.abs(te.axial)<se){if(Math.abs(re.axial)>se)throw new Error("rotateAroundTo(...): target line stays on the pivot plane, but the moving point has axial offset");return FSt(re.radial,te.radial,O)}const Xe=re.axial/te.axial,it=Math.abs(Xe)*Ee;if(Math.abs(W-it)>me)throw new Error("rotateAroundTo(...): moving point cannot reach the target line while preserving radius around the axis");const at=Xe>=0?te.radial:nq(te.radial,-1);return jte(re.radial,at,O)}function OSt(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function MSt(l){return l instanceof Ea?l.toArray():l}function LSt(l,o){const f=new Array(16).fill(0);for(let g=0;g<4;g++)for(let T=0;T<4;T++){let P=0;for(let O=0;O<4;O++)P+=l[O*4+T]*o[g*4+O];f[g*4+T]=P}return f}function X2e(l){const o=Math.sqrt(l[0]*l[0]+l[1]*l[1]+l[2]*l[2]);if(o<1e-10)throw new Error("Axis must be non-zero");return[l[0]/o,l[1]/o,l[2]/o]}function KBe(l,o,f){const g=o[0],T=o[1],P=o[2];return[l[0]*g+l[4]*T+l[8]*P+l[12]*f,l[1]*g+l[5]*T+l[9]*P+l[13]*f,l[2]*g+l[6]*T+l[10]*P+l[14]*f]}function RSt(l){const o=new Array(16),f=l[0],g=l[1],T=l[2],P=l[3],O=l[4],z=l[5],H=l[6],re=l[7],te=l[8],W=l[9],Ee=l[10],se=l[11],me=l[12],Xe=l[13],it=l[14],at=l[15],It=f*z-g*O,tn=f*H-T*O,At=f*re-P*O,mt=g*H-T*z,ht=g*re-P*z,xn=T*re-P*H,Pn=te*Xe-W*me,$r=te*it-Ee*me,zn=te*at-se*me,ii=W*it-Ee*Xe,Gr=W*at-se*Xe,mn=Ee*at-se*it,$s=It*mn-tn*Gr+At*ii+mt*zn-ht*$r+xn*Pn;if(Math.abs($s)<1e-10)throw new Error("Transform matrix is not invertible");const is=1/$s;return o[0]=(z*mn-H*Gr+re*ii)*is,o[1]=(T*Gr-g*mn-P*ii)*is,o[2]=(Xe*xn-it*ht+at*mt)*is,o[3]=(Ee*ht-W*xn-se*mt)*is,o[4]=(H*zn-O*mn-re*$r)*is,o[5]=(f*mn-T*zn+P*$r)*is,o[6]=(it*At-me*xn-at*tn)*is,o[7]=(te*xn-Ee*At+se*tn)*is,o[8]=(O*Gr-z*zn+re*Pn)*is,o[9]=(g*zn-f*Gr-P*Pn)*is,o[10]=(me*ht-Xe*At+at*It)*is,o[11]=(W*At-te*ht-se*It)*is,o[12]=(z*$r-O*ii-H*Pn)*is,o[13]=(f*ii-g*$r+T*Pn)*is,o[14]=(Xe*tn-me*mt-it*It)*is,o[15]=(te*mt-W*tn+Ee*It)*is,o}class Ea{constructor(o){tu(this,"m");this.m=o}static identity(){return new Ea(OSt())}static from(o){return o instanceof Ea?o:new Ea(o)}static translation(o,f,g){return new Ea([1,0,0,0,0,1,0,0,0,0,1,0,o,f,g,1])}static scale(o){const f=typeof o=="number"?o:o[0],g=typeof o=="number"?o:o[1],T=typeof o=="number"?o:o[2];return new Ea([f,0,0,0,0,g,0,0,0,0,T,0,0,0,0,1])}static rotationAxis(o,f,g=[0,0,0]){const[T,P,O]=X2e(o),z=f*Math.PI/180,H=Math.cos(z),re=Math.sin(z),te=H+T*T*(1-H),W=T*P*(1-H)-O*re,Ee=T*O*(1-H)+P*re,se=P*T*(1-H)+O*re,me=H+P*P*(1-H),Xe=P*O*(1-H)-T*re,it=O*T*(1-H)-P*re,at=O*P*(1-H)+T*re,It=H+O*O*(1-H),[tn,At,mt]=g,ht=tn-(te*tn+W*At+Ee*mt),xn=At-(se*tn+me*At+Xe*mt),Pn=mt-(it*tn+at*At+It*mt);return new Ea([te,se,it,0,W,me,at,0,Ee,Xe,It,0,ht,xn,Pn,1])}static rotateAroundTo(o,f,g,T,P={}){const O=VJe(o,f,g,T,P);return Ea.rotationAxis(o,O,f)}mul(o){const f=MSt(o);return new Ea(LSt(f,this.m))}translate(o,f,g){return this.mul(Ea.translation(o,f,g))}rotateAxis(o,f,g=[0,0,0]){return this.mul(Ea.rotationAxis(o,f,g))}scale(o){return this.mul(Ea.scale(o))}inverse(){return new Ea(RSt(this.m))}point(o){return KBe(this.m,o,1)}vector(o){return KBe(this.m,o,0)}toArray(){return[...this.m]}}function td(l){return X2e(l)}function UJe(...l){let o=Ea.identity();for(const f of l)o=o.mul(f);return o}const jSt={live:{id:"live",label:"Live (fast)",description:"Prioritizes responsiveness for interactive editing.",curves:{splineSamplesScale:.55,sweepPathSamplesScale:.6,levelSetEdgeLengthScale:1.75,boundsPaddingScale:1},smoothing:{refineStepsScale:.5,refineLengthScale:1.8,refineToleranceScale:1.8}},default:{id:"default",label:"Default",description:"Balanced quality and speed.",curves:{splineSamplesScale:1,sweepPathSamplesScale:1,levelSetEdgeLengthScale:1,boundsPaddingScale:1},smoothing:{refineStepsScale:1,refineLengthScale:1,refineToleranceScale:1}},high:{id:"high",label:"High",description:"Finer tessellation for final exports.",curves:{splineSamplesScale:1.35,sweepPathSamplesScale:1.35,levelSetEdgeLengthScale:.8,boundsPaddingScale:1},smoothing:{refineStepsScale:1.25,refineLengthScale:.8,refineToleranceScale:.8}}};let Bte=["default"];function Y2e(l){return l==="live"||l==="default"||l==="high"?l:"default"}function BSt(){return Bte[Bte.length-1]??"default"}function pI(l){const o=Y2e(BSt());return jSt[o]}function zSt(l,o){const f=Y2e(l);Bte.push(f);try{return o()}finally{Bte.pop()}}function $Je(l,o,f){const g=Math.round(l*o);return Math.max(f,g)}function HJe(l,o,f){return Math.max(f,l*o)}function JSt(l){const o=Math.max(3,Math.floor(l)),f=pI().curves.splineSamplesScale;return $Je(o,f,3)}function qSt(l){const o=Math.max(4,Math.floor(l)),f=pI().curves.sweepPathSamplesScale;return $Je(o,f,4)}function GJe(l){const o=Math.max(.01,l),f=pI().curves.levelSetEdgeLengthScale;return HJe(o,f,.01)}function XJe(l){const o=Math.max(.01,l),f=pI().curves.boundsPaddingScale;return HJe(o,f,.01)}function WSt(l){const o=Math.max(0,Math.floor(l)),f=pI().smoothing.refineStepsScale;return Math.max(0,Math.round(o*f))}function VSt(l){const o=Math.max(1e-6,l),f=pI().smoothing.refineLengthScale;return Math.max(1e-6,o*f)}function USt(l){const o=Math.max(1e-6,l),f=pI().smoothing.refineToleranceScale;return Math.max(1e-6,o*f)}const YJe=["center","front","back","left","right","top","bottom","front-left","front-right","back-left","back-right","top-front","top-back","top-left","top-right","bottom-front","bottom-back","bottom-left","bottom-right","top-front-left","top-front-right","top-back-left","top-back-right","bottom-front-left","bottom-front-right","bottom-back-left","bottom-back-right"],Ste=new Set(YJe),$St={center:"center",left:"x",right:"x",front:"y",back:"y",top:"z",bottom:"z"};function QJe(l){return Ste.has(l)}function cne(l){if(Ste.has(l))return l;const o=l.split("-").filter(Boolean);if(o.length===0)return null;if(o.length===1)return Ste.has(o[0])?o[0]:null;const f=new Map;for(const T of o){const P=$St[T];if(!P||P==="center")return null;const O=f.get(P);if(O&&O!==T)return null;f.set(P,T)}const g=[f.get("z"),f.get("y"),f.get("x")].filter(T=>T!=null).join("-");return Ste.has(g)?g:null}function t4(l,o,f){const g=cne(f);if(!g)throw new Error(`Unknown anchor "${f}". Valid anchors: ${YJe.join(", ")}`);const T=(l[0]+o[0])/2,P=(l[1]+o[1])/2,O=(l[2]+o[2])/2;switch(g){case"center":return[T,P,O];case"front":return[T,l[1],O];case"back":return[T,o[1],O];case"left":return[l[0],P,O];case"right":return[o[0],P,O];case"top":return[T,P,o[2]];case"bottom":return[T,P,l[2]];case"front-left":return[l[0],l[1],O];case"front-right":return[o[0],l[1],O];case"back-left":return[l[0],o[1],O];case"back-right":return[o[0],o[1],O];case"top-front":return[T,l[1],o[2]];case"top-back":return[T,o[1],o[2]];case"top-left":return[l[0],P,o[2]];case"top-right":return[o[0],P,o[2]];case"bottom-front":return[T,l[1],l[2]];case"bottom-back":return[T,o[1],l[2]];case"bottom-left":return[l[0],P,l[2]];case"bottom-right":return[o[0],P,l[2]];case"top-front-left":return[l[0],l[1],o[2]];case"top-front-right":return[o[0],l[1],o[2]];case"top-back-left":return[l[0],o[1],o[2]];case"top-back-right":return[o[0],o[1],o[2]];case"bottom-front-left":return[l[0],l[1],l[2]];case"bottom-front-right":return[o[0],l[1],l[2]];case"bottom-back-left":return[l[0],o[1],l[2]];case"bottom-back-right":return[o[0],o[1],l[2]];default:throw new Error(`Unhandled anchor normalization for "${g}"`)}}const zte=["points","edges","surfaces","objects"];function Z_(l,o){if(!Array.isArray(l)||l.length<3)throw new Error(`${o} must be a [x, y, z] tuple`);const f=Number(l[0]),g=Number(l[1]),T=Number(l[2]);if(!Number.isFinite(f)||!Number.isFinite(g)||!Number.isFinite(T))throw new Error(`${o} must contain finite numbers`);return[f,g,T]}function HSt(l,o){return[(l[0]+o[0])/2,(l[1]+o[1])/2,(l[2]+o[2])/2]}function ZJe(l){const o=Math.hypot(l[0],l[1],l[2]);return o<1e-10?[0,0,1]:[l[0]/o,l[1]/o,l[2]/o]}function GSt(l){return!!l&&typeof l=="object"&&"min"in l&&"max"in l}function XSt(l,o){if(GSt(l))return{min:Z_(l.min,`${o}.min`),max:Z_(l.max,`${o}.max`)};if(typeof l=="object"&&l!=null){if("boundingBox"in l&&typeof l.boundingBox=="function"){const f=l.boundingBox();return{min:Z_(f.min,`${o}.min`),max:Z_(f.max,`${o}.max`)}}if("_bbox"in l&&typeof l._bbox=="function"){const f=l._bbox();return{min:Z_(f.min,`${o}.min`),max:Z_(f.max,`${o}.max`)}}}throw new Error(`${o} must be a bounds object or a shape/group with a bounding box`)}function YSt(l,o){const f=Ea.from(o),[g,T,P]=l.min,[O,z,H]=l.max,re=[[g,T,P],[g,T,H],[g,z,P],[g,z,H],[O,T,P],[O,T,H],[O,z,P],[O,z,H]],te=[1/0,1/0,1/0],W=[-1/0,-1/0,-1/0];for(const Ee of re){const se=f.point(Ee);te[0]=Math.min(te[0],se[0]),te[1]=Math.min(te[1],se[1]),te[2]=Math.min(te[2],se[2]),W[0]=Math.max(W[0],se[0]),W[1]=Math.max(W[1],se[1]),W[2]=Math.max(W[2],se[2])}return{min:te,max:W}}function sM(){return{points:{},edges:{},surfaces:{},objects:{}}}function KJe(l){const o=sM();for(const[f,g]of Object.entries(l.points))o.points[f]=Z_(g,`points.${f}`);for(const[f,g]of Object.entries(l.edges))o.edges[f]={start:Z_(g.start,`edges.${f}.start`),end:Z_(g.end,`edges.${f}.end`)};for(const[f,g]of Object.entries(l.surfaces))o.surfaces[f]={center:Z_(g.center,`surfaces.${f}.center`),normal:Z_(g.normal,`surfaces.${f}.normal`)};for(const[f,g]of Object.entries(l.objects))o.objects[f]={min:Z_(g.min,`objects.${f}.min`),max:Z_(g.max,`objects.${f}.max`)};return o}function QSt(l={}){const o=sM();for(const[f,g]of Object.entries(l.points??{}))o.points[f]=Z_(g,`points.${f}`);for(const[f,g]of Object.entries(l.edges??{}))o.edges[f]={start:Z_(g.start,`edges.${f}.start`),end:Z_(g.end,`edges.${f}.end`)};for(const[f,g]of Object.entries(l.surfaces??{}))o.surfaces[f]={center:Z_(g.center,`surfaces.${f}.center`),normal:ZJe(Z_(g.normal,`surfaces.${f}.normal`))};for(const[f,g]of Object.entries(l.objects??{}))o.objects[f]=XSt(g,`objects.${f}`);return o}function eqe(...l){const o=sM();for(const f of l){for(const[g,T]of Object.entries(f.points))o.points[g]=Z_(T,`points.${g}`);for(const[g,T]of Object.entries(f.edges))o.edges[g]={start:Z_(T.start,`edges.${g}.start`),end:Z_(T.end,`edges.${g}.end`)};for(const[g,T]of Object.entries(f.surfaces))o.surfaces[g]={center:Z_(T.center,`surfaces.${g}.center`),normal:Z_(T.normal,`surfaces.${g}.normal`)};for(const[g,T]of Object.entries(f.objects))o.objects[g]={min:Z_(T.min,`objects.${g}.min`),max:Z_(T.max,`objects.${g}.max`)}}return o}function ZSt(l){return zte.some(o=>Object.keys(l[o]).length>0)}function eze(l,o){return eqe(l,QSt(o))}function KSt(l,o){const f=Ea.from(o),g=sM();for(const[T,P]of Object.entries(l.points))g.points[T]=f.point(P);for(const[T,P]of Object.entries(l.edges))g.edges[T]={start:f.point(P.start),end:f.point(P.end)};for(const[T,P]of Object.entries(l.surfaces))g.surfaces[T]={center:f.point(P.center),normal:ZJe(f.vector(P.normal))};for(const[T,P]of Object.entries(l.objects))g.objects[T]=YSt(P,o);return g}function qee(l,o){throw new Error(`Placement reference "${l}" ${o}`)}function tze(l,o,f,g,T){switch(o){case"points":{const P=l.points[f];return P?(g!=null&&qee(T,"does not support selectors"),Z_(P,`points.${f}`)):null}case"edges":{const P=l.edges[f];if(!P)return null;if(g==null||g==="midpoint"||g==="center")return HSt(P.start,P.end);if(g==="start")return Z_(P.start,`edges.${f}.start`);if(g==="end")return Z_(P.end,`edges.${f}.end`);qee(T,"supports only .start, .end, or .midpoint")}case"surfaces":{const P=l.surfaces[f];return P?(g!=null&&g!=="center"&&qee(T,"supports only .center"),Z_(P.center,`surfaces.${f}.center`)):null}case"objects":{const P=l.objects[f];if(!P)return null;const z=cne(g??"center");return z||qee(T,`supports only Anchor3D selectors (${["center","top","bottom","left","right","front","back"].join(", ")} ...)`),t4(P.min,P.max,z)}default:return null}}function eTt(l,o){const f=o.trim();if(!f)return null;const g=f.split(".");if(g.length>=2&&zte.includes(g[0])){const P=g[0],O=g[1],z=g.length>2?g.slice(2).join("."):void 0;return tze(l,P,O,z,f)}const T=zte.map(P=>({kind:P,point:tze(l,P,f,void 0,f)})).filter(P=>P.point!=null);if(T.length===0)return null;if(T.length>1)throw new Error(`Placement reference "${f}" is ambiguous. Use one of: ${T.map(P=>`${P.kind}.${f}`).join(", ")}`);return T[0].point}function tqe(l,o){return o?Object.keys(l[o]).sort():zte.flatMap(f=>Object.keys(l[f]).sort().map(g=>`${f}.${g}`))}function Sp(l){if(l)return{id:l.id,operation:l.operation}}function Pb(l,o){return l==null||o==null?l==null&&o==null:l.id===o.id&&l.operation===o.operation}function iu(l){if(l)switch(l.kind){case"canonical-face":return{kind:"canonical-face",face:l.face,owner:Sp(l.owner)};case"tracked-face":return{kind:"tracked-face",faceName:l.faceName,owner:Sp(l.owner)};case"face-ref":return{kind:"face-ref",faceName:l.faceName,owner:Sp(l.owner)};case"propagated-face":return{kind:"propagated-face",rewriteId:l.rewriteId,outcome:l.outcome,source:iu(l.source),owner:Sp(l.owner)};case"created-face":return{kind:"created-face",rewriteId:l.rewriteId,operation:l.operation,slot:l.slot,owner:Sp(l.owner)}}}function wl(l){if(l)switch(l.kind){case"tracked-edge":return{kind:"tracked-edge",edgeName:l.edgeName,selector:l.selector,owner:Sp(l.owner)};case"edge-ref":return{kind:"edge-ref",edgeName:l.edgeName,selector:l.selector,owner:Sp(l.owner)};case"propagated-edge":return{kind:"propagated-edge",rewriteId:l.rewriteId,outcome:l.outcome,source:wl(l.source),selector:l.selector,owner:Sp(l.owner)};case"created-edge":return{kind:"created-edge",rewriteId:l.rewriteId,operation:l.operation,slot:l.slot,selector:l.selector,owner:Sp(l.owner)}}}function uC(l){if(l)return{rewriteId:l.rewriteId,operation:l.operation,owner:Sp(l.owner),preservedFaces:l.preservedFaces.map(o=>({query:iu(o.query),status:o.status,note:o.note})),preservedEdges:l.preservedEdges.map(o=>({query:wl(o.query),status:o.status,note:o.note})),createdFaces:l.createdFaces.map(o=>({query:iu(o.query),note:o.note})),createdEdges:l.createdEdges.map(o=>({query:wl(o.query),note:o.note})),diagnostics:l.diagnostics.map(o=>({code:o.code,category:o.category,queryKind:o.queryKind,message:o.message,source:o.queryKind==="face"?iu(o.source):wl(o.source),query:o.queryKind==="face"?iu(o.query):wl(o.query)})),descendants:(l.descendants??[]).map(o=>{switch(o.queryKind){case"face":return{queryKind:"face",kind:o.kind,query:iu(o.query),source:iu(o.source),note:o.note};case"edge":return{queryKind:"edge",kind:o.kind,query:wl(o.query),source:wl(o.source),note:o.note};case"vertex":return{queryKind:"vertex",kind:o.kind,note:o.note}}})}}function sT(l,o){if(l==null||o==null)return l==null&&o==null;if(l.kind!==o.kind)return!1;switch(l.kind){case"canonical-face":return o.kind==="canonical-face"&&l.face===o.face&&Pb(l.owner,o.owner);case"tracked-face":return o.kind==="tracked-face"&&l.faceName===o.faceName&&Pb(l.owner,o.owner);case"face-ref":return o.kind==="face-ref"&&l.faceName===o.faceName&&Pb(l.owner,o.owner);case"propagated-face":return o.kind==="propagated-face"&&l.rewriteId===o.rewriteId&&l.outcome===o.outcome&&sT(l.source,o.source)&&Pb(l.owner,o.owner);case"created-face":return o.kind==="created-face"&&l.rewriteId===o.rewriteId&&l.operation===o.operation&&l.slot===o.slot&&Pb(l.owner,o.owner)}}function gC(l,o){if(l==null||o==null)return l==null&&o==null;if(l.kind!==o.kind)return!1;switch(l.kind){case"tracked-edge":return o.kind==="tracked-edge"&&l.edgeName===o.edgeName&&l.selector===o.selector&&Pb(l.owner,o.owner);case"edge-ref":return o.kind==="edge-ref"&&l.edgeName===o.edgeName&&l.selector===o.selector&&Pb(l.owner,o.owner);case"propagated-edge":return o.kind==="propagated-edge"&&l.rewriteId===o.rewriteId&&l.outcome===o.outcome&&l.selector===o.selector&&gC(l.source,o.source)&&Pb(l.owner,o.owner);case"created-edge":return o.kind==="created-edge"&&l.rewriteId===o.rewriteId&&l.operation===o.operation&&l.slot===o.slot&&l.selector===o.selector&&Pb(l.owner,o.owner)}}function rq(l){if(!l)return"none";const o=l.owner?` @${l.owner.operation}:${l.owner.id}`:"";switch(l.kind){case"canonical-face":return`canonical-face(${l.face})${o}`;case"tracked-face":return`tracked-face(${l.faceName})${o}`;case"face-ref":return`face-ref(${l.faceName??"unnamed"})${o}`;case"propagated-face":return`propagated-face(${l.outcome} <- ${rq(l.source)})${o}`;case"created-face":return`created-face(${l.operation}:${l.slot})${o}`}}function iq(l){if(!l)return"none";const o=l.owner?` @${l.owner.operation}:${l.owner.id}`:"",f=`#${l.selector}`;switch(l.kind){case"tracked-edge":return`tracked-edge(${l.edgeName}${f})${o}`;case"edge-ref":return`edge-ref(${l.edgeName??"unnamed"}${f})${o}`;case"propagated-edge":return`propagated-edge(${l.outcome} <- ${iq(l.source)}${f})${o}`;case"created-edge":return`created-edge(${l.operation}:${l.slot}${f})${o}`}}function tTt(l){return iu(l)}function c2e(l){return{origin:[l.origin[0],l.origin[1],l.origin[2]],u:[l.u[0],l.u[1],l.u[2]],v:[l.v[0],l.v[1],l.v[2]],normal:[l.normal[0],l.normal[1],l.normal[2]],source:tTt(l.source)}}function i6(l){return l?{workplane:c2e(l.workplane),u:l.u,v:l.v,protrude:l.protrude,selfAnchor:l.selfAnchor}:null}function nTt(l){return[...l]}function rT(l){return l?{matrix:nTt(l.matrix),placement:i6(l.placement)}:null}function Jte(l){if(l)return[l[0],l[1]]}function nze(l){if(l)return{kind:l.kind,edgeName:l.edgeName,start:[l.start[0],l.start[1],l.start[2]],end:[l.end[0],l.end[1],l.end[2]],midpoint:[l.midpoint[0],l.midpoint[1],l.midpoint[2]]}}const dq=["top","right","bottom","left"],VO=1e-9;function Wee(l){return Number.isFinite(l)&&l>0}function rze(l){return Number.isFinite(l)&&l>=0}function l2e(l){return[l[0],l[1],l[2]]}function ize(l){return l?l2e(l):void 0}function qte(l){return l?{panel:{width:l.panel.width,height:l.panel.height},thickness:l.thickness,bendRadius:l.bendRadius,bendAllowance:{kind:l.bendAllowance.kind,kFactor:l.bendAllowance.kFactor},cornerRelief:{kind:l.cornerRelief.kind,size:l.cornerRelief.size},flanges:l.flanges.map(o=>({edge:o.edge,length:o.length,angleDeg:o.angleDeg}))}:null}function Tte(l){return`sheetMetal().flange("${l}", ...)`}function rTt(l){return Math.abs(l)<=VO?0:l}function Wte(l){if(!Wee(l.panel.width)||!Wee(l.panel.height))return"sheetMetal() requires a positive finite panel width and height.";if(!Wee(l.thickness))return"sheetMetal() requires a positive finite sheet thickness.";if(!rze(l.bendRadius))return"sheetMetal() requires a finite non-negative bendRadius.";if(l.bendRadius<=VO)return"sheetMetal() v1 requires a positive bendRadius so the bend region stays explicit instead of collapsing into a sharp fold.";if(l.bendAllowance.kind!=="k-factor")return`sheetMetal() does not support bend allowance model "${l.bendAllowance.kind}" yet.`;if(!Number.isFinite(l.bendAllowance.kFactor)||l.bendAllowance.kFactor<=0||l.bendAllowance.kFactor>=1)return"sheetMetal() k-factor must be a finite value between 0 and 1.";if(l.cornerRelief.kind!=="rect")return`sheetMetal() does not support corner relief "${l.cornerRelief.kind}" yet.`;if(!rze(l.cornerRelief.size))return"sheetMetal() corner relief size must be a finite non-negative value.";const o=new Set;for(const f of l.flanges){if(!dq.includes(f.edge))return`sheetMetal() does not recognize flange edge "${String(f.edge)}".`;if(o.has(f.edge))return`${Tte(f.edge)} can only be declared once.`;if(o.add(f.edge),!Wee(f.length))return`${Tte(f.edge)} requires a positive finite length.`;if(!Number.isFinite(f.angleDeg)||Math.abs(rTt(f.angleDeg)-90)>1e-6)return`${Tte(f.edge)} v1 only supports 90 degree flanges.`}return null}function iTt(l){return new Map(l.flanges.map(o=>[o.edge,o]))}function sTt(l){switch(l){case"top":return{start:"left",end:"right"};case"right":return{start:"bottom",end:"top"};case"bottom":return{start:"left",end:"right"};case"left":return{start:"bottom",end:"top"}}}function eM(l){const o=Wte(l);if(o)throw new Error(o);const f=iTt(l),g=Math.PI/2*(l.bendRadius+l.bendAllowance.kFactor*l.thickness),T=new Map;for(const P of dq){const O=f.get(P);if(!O)continue;const z=sTt(P),H=f.has(z.start)?l.cornerRelief.size:0,re=f.has(z.end)?l.cornerRelief.size:0,W=(P==="top"||P==="bottom"?l.panel.width:l.panel.height)-H-re;if(!(W>VO))throw new Error(`${Tte(P)} loses all usable span after applying the defended rectangular corner relief size ${l.cornerRelief.size}.`);T.set(P,{edge:P,length:O.length,angleDeg:O.angleDeg,bendAllowance:g,trimStart:H,trimEnd:re,span:W,centerAlongEdge:(H-re)/2})}return{panelWidth:l.panel.width,panelHeight:l.panel.height,thickness:l.thickness,bendRadius:l.bendRadius,kFactor:l.bendAllowance.kFactor,bendAllowance:g,reliefSize:l.cornerRelief.size,flanges:T}}function aTt(l){const o=["panel"],f=eM(l);for(const g of dq)f.flanges.has(g)&&o.push(`bend-${g}`,`flange-${g}`);return o}function oTt(l){return aTt(l).filter(o=>o==="panel"||o.startsWith("flange-"))}function cTt(l){return l==="panel"||l==="flange-top"||l==="flange-right"||l==="flange-bottom"||l==="flange-left"}function lTt(l,o,f,g){return{workplane:{origin:[l[0],l[1],l[2]],u:[o[0],o[1],o[2]],v:[f[0],f[1],f[2]],normal:[g[0],g[1],g[2]],source:{kind:"face-ref",faceName:"sheet-metal-placement"}},u:0,v:0,protrude:0,selfAnchor:"center"}}function uTt(l,o,f,g){return Math.abs(o)<=VO&&Math.abs(f)<=VO&&Math.abs(g)<=VO?m_(l):G1(m_(l),{kind:"translate",x:o,y:f,z:g})}function Vee(l,o,f,g,T){const P=lTt(o,f,g,T),O=[f[0],f[1],f[2],0,g[0],g[1],g[2],0,T[0],T[1],T[2],0,o[0],o[1],o[2],1];return G1(m_(l),{kind:"workplanePlacement",matrix:O,placement:P})}function mx(l,o,f,g=0,T=0,P=0){return uTt({kind:"box",x:l,y:o,z:f,center:!0},g,T,P)}function _Tt(l,o){const f=l+o,g=Db({kind:"circle",radius:f,transforms:[]},{kind:"translate",x:0,y:l}),T=Db({kind:"circle",radius:l,transforms:[]},{kind:"translate",x:0,y:l}),P=iT("difference",[g,T]),O=Db({kind:"rect",width:f,height:f,center:!1,transforms:[]},{kind:"translate",x:0,y:-o});return iT("intersection",[P,O])}function fTt(l){return{kind:"box",x:l.panelWidth,y:l.panelHeight,z:l.thickness,center:!0}}function pTt(l,o){const f=l.thickness,g=l.bendRadius,T=o.length;switch(o.edge){case"top":return mx(o.span,f,T,o.centerAlongEdge,l.panelHeight/2+g+f/2,-f/2-g-T/2);case"bottom":return mx(o.span,f,T,o.centerAlongEdge,-l.panelHeight/2-g-f/2,-f/2-g-T/2);case"right":return mx(f,o.span,T,l.panelWidth/2+g+f/2,o.centerAlongEdge,-f/2-g-T/2);case"left":return mx(f,o.span,T,-l.panelWidth/2-g-f/2,o.centerAlongEdge,-f/2-g-T/2)}}function dTt(l,o){const f=_Tt(l.bendRadius,l.thickness);if(!f)return null;const g={kind:"extrude",profile:f,height:o.span,center:!1};switch(o.edge){case"top":return Vee(g,[-l.panelWidth/2+o.trimStart,l.panelHeight/2,-l.thickness/2],[0,1,0],[0,0,-1],[1,0,0]);case"bottom":return Vee(g,[-l.panelWidth/2+o.trimStart,-l.panelHeight/2,-l.thickness/2],[0,-1,0],[0,0,-1],[1,0,0]);case"right":return Vee(g,[l.panelWidth/2,-l.panelHeight/2+o.trimStart,-l.thickness/2],[1,0,0],[0,0,-1],[0,1,0]);case"left":return Vee(g,[-l.panelWidth/2,-l.panelHeight/2+o.trimStart,-l.thickness/2],[-1,0,0],[0,0,-1],[0,1,0])}}function mTt(l,o){const f=l.thickness,g=o.bendAllowance;switch(o.edge){case"top":return mx(o.span,g,f,o.centerAlongEdge,l.panelHeight/2+g/2,0);case"bottom":return mx(o.span,g,f,o.centerAlongEdge,-l.panelHeight/2-g/2,0);case"right":return mx(g,o.span,f,l.panelWidth/2+g/2,o.centerAlongEdge,0);case"left":return mx(g,o.span,f,-l.panelWidth/2-g/2,o.centerAlongEdge,0)}}function hTt(l,o){const f=l.thickness,g=o.bendAllowance,T=o.length;switch(o.edge){case"top":return mx(o.span,T,f,o.centerAlongEdge,l.panelHeight/2+g+T/2,0);case"bottom":return mx(o.span,T,f,o.centerAlongEdge,-l.panelHeight/2-g-T/2,0);case"right":return mx(T,o.span,f,l.panelWidth/2+g+T/2,o.centerAlongEdge,0);case"left":return mx(T,o.span,f,-l.panelWidth/2-g-T/2,o.centerAlongEdge,0)}}function gTt(l,o){const f=eM(l),g=[fTt(f)];for(const T of dq){const P=f.flanges.get(T);if(P){if(o==="folded"){const O=dTt(f,P);O&&g.push(O),g.push(pTt(f,P));continue}g.push(mTt(f,P)),g.push(hTt(f,P))}}return g.length===1?g[0]:Ry("union",g)}function Wg(l,o,f,g,T,P,O="face",z=[l],H=g){return{name:l,center:l2e(o),normal:l2e(f),planar:g,uAxis:ize(T),vAxis:ize(P),semantic:O,memberNames:[...z],coplanar:H}}function yTt(l,o){const f=l.thickness,g=l.bendRadius,P=(g+f/2)/Math.sqrt(2);switch(o.edge){case"top":return Wg("bend-top",[o.centerAlongEdge,l.panelHeight/2+P,-l.thickness/2-g+P],[0,1/Math.sqrt(2),1/Math.sqrt(2)],!1,void 0,void 0,"set",["bend-top-inner","bend-top-outer"],!1);case"bottom":return Wg("bend-bottom",[o.centerAlongEdge,-l.panelHeight/2-P,-l.thickness/2-g+P],[0,-1/Math.sqrt(2),1/Math.sqrt(2)],!1,void 0,void 0,"set",["bend-bottom-inner","bend-bottom-outer"],!1);case"right":return Wg("bend-right",[l.panelWidth/2+P,o.centerAlongEdge,-l.thickness/2-g+P],[1/Math.sqrt(2),0,1/Math.sqrt(2)],!1,void 0,void 0,"set",["bend-right-inner","bend-right-outer"],!1);case"left":return Wg("bend-left",[-l.panelWidth/2-P,o.centerAlongEdge,-l.thickness/2-g+P],[-1/Math.sqrt(2),0,1/Math.sqrt(2)],!1,void 0,void 0,"set",["bend-left-inner","bend-left-outer"],!1)}}function vTt(l,o){const f=eM(l),g=[Wg("panel",[0,0,f.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0])];for(const T of dq){const P=f.flanges.get(T);if(P){if(o==="folded"){switch(g.push(yTt(f,P)),T){case"top":g.push(Wg("flange-top",[P.centerAlongEdge,f.panelHeight/2+f.bendRadius+f.thickness,-f.thickness/2-f.bendRadius-P.length/2],[0,1,0],!0,[1,0,0],[0,0,-1]));break;case"bottom":g.push(Wg("flange-bottom",[P.centerAlongEdge,-f.panelHeight/2-f.bendRadius-f.thickness,-f.thickness/2-f.bendRadius-P.length/2],[0,-1,0],!0,[1,0,0],[0,0,1]));break;case"right":g.push(Wg("flange-right",[f.panelWidth/2+f.bendRadius+f.thickness,P.centerAlongEdge,-f.thickness/2-f.bendRadius-P.length/2],[1,0,0],!0,[0,1,0],[0,0,1]));break;case"left":g.push(Wg("flange-left",[-f.panelWidth/2-f.bendRadius-f.thickness,P.centerAlongEdge,-f.thickness/2-f.bendRadius-P.length/2],[-1,0,0],!0,[0,-1,0],[0,0,1]));break}continue}switch(T){case"top":g.push(Wg("bend-top",[P.centerAlongEdge,f.panelHeight/2+P.bendAllowance/2,f.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0])),g.push(Wg("flange-top",[P.centerAlongEdge,f.panelHeight/2+P.bendAllowance+P.length/2,f.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0]));break;case"bottom":g.push(Wg("bend-bottom",[P.centerAlongEdge,-f.panelHeight/2-P.bendAllowance/2,f.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0])),g.push(Wg("flange-bottom",[P.centerAlongEdge,-f.panelHeight/2-P.bendAllowance-P.length/2,f.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0]));break;case"right":g.push(Wg("bend-right",[f.panelWidth/2+P.bendAllowance/2,P.centerAlongEdge,f.thickness/2],[0,0,1],!0,[0,1,0],[-1,0,0])),g.push(Wg("flange-right",[f.panelWidth/2+P.bendAllowance+P.length/2,P.centerAlongEdge,f.thickness/2],[0,0,1],!0,[0,1,0],[-1,0,0]));break;case"left":g.push(Wg("bend-left",[-f.panelWidth/2-P.bendAllowance/2,P.centerAlongEdge,f.thickness/2],[0,0,1],!0,[0,-1,0],[1,0,0])),g.push(Wg("flange-left",[-f.panelWidth/2-P.bendAllowance-P.length/2,P.centerAlongEdge,f.thickness/2],[0,0,1],!0,[0,-1,0],[1,0,0]));break}}}return g}function XE(l){switch(l.kind){case"translate":return{kind:"translate",x:l.x,y:l.y};case"rotate":return{kind:"rotate",degrees:l.degrees};case"scale":return{kind:"scale",x:l.x,y:l.y};case"mirror":return{kind:"mirror",normalX:l.normalX,normalY:l.normalY}}}function R_(l){return Object.is(l,-0)?0:l}function Q2e(l){return l.map(o=>R_(o))}function Uee(l){return[R_(l[0]),R_(l[1]),R_(l[2])]}function sq(l){return rT({matrix:Q2e(l.matrix),placement:i6(l.placement)})}function lne(l){return Sp(l)}function bTt(l){return{radius:R_(l.radius),depth:R_(l.depth)}}function xTt(l){return{radius:R_(l.radius),angleDeg:R_(l.angleDeg),depth:R_(l.depth)}}function STt(l){return{designation:l.designation,pitch:l.pitch==null?void 0:R_(l.pitch),class:l.class,handedness:l.handedness,depth:l.depth==null?void 0:R_(l.depth),modeled:l.modeled}}function TTt(l){return{radius:R_(l.radius),counterbore:l.counterbore?bTt(l.counterbore):void 0,countersink:l.countersink?xTt(l.countersink):void 0,thread:l.thread?STt(l.thread):void 0}}function Cbe(l){switch(l.kind){case"through":case"blind":return{kind:l.kind,depth:R_(l.depth)};case"upToFace":return{kind:"upToFace",depth:R_(l.depth),face:iu(l.face)}}}function sze(l){return l.kind==="two-sided"?{kind:"two-sided",forward:Cbe(l.forward),reverse:Cbe(l.reverse)}:Cbe(l)}function kTt(l){return{scale:[R_(l.scale[0]),R_(l.scale[1])]}}function Rm(l){return l.kind==="two-sided"?l.forward:l}function Ab(l){return l.kind==="two-sided"?l.reverse:void 0}function mq(l){var g;const o=Rm(l).depth,f=((g=Ab(l))==null?void 0:g.depth)??0;return o+f}let u2e=0;function CTt(l){return l.replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()||"shape"}function une(l){return u2e+=1,{id:`shape-query-${CTt(l)}-${u2e}`,operation:l}}function wTt(){u2e=0}function ETt(l){const[o,f,g]=l,T=Math.hypot(o,f,g);if(T<1e-12)return Ea.identity().toArray();const P=o/T,O=f/T,z=g/T,H=1-2*P*P,re=-2*P*O,te=-2*P*z,W=-2*O*P,Ee=1-2*O*O,se=-2*O*z,me=-2*z*P,Xe=-2*z*O,it=1-2*z*z;return[H,W,me,0,re,Ee,Xe,0,te,se,it,0,0,0,0,1]}function PTt(l){switch(l.kind){case"translate":return Ea.translation(l.x,l.y,l.z).toArray();case"rotate":return Ea.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg).toArray();case"scale":return Ea.scale([l.x,l.y,l.z]).toArray();case"rotateAround":return Ea.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]).toArray();case"mirror":return ETt([l.normalX,l.normalY,l.normalZ])}}function DTt(l,o){const f=PTt(o),g=Ea.from(f),T=sq(l);return{matrix:Q2e(Ea.from(T.matrix).mul(f).toArray()),placement:{...T.placement,workplane:{...T.placement.workplane,origin:Uee(g.point(T.placement.workplane.origin)),u:Uee(g.vector(T.placement.workplane.u)),v:Uee(g.vector(T.placement.workplane.v)),normal:Uee(g.vector(T.placement.workplane.normal))}}}}function kte(l){switch(l.kind){case"translate":return{kind:"translate",x:l.x,y:l.y,z:l.z};case"rotate":return{kind:"rotate",xDeg:l.xDeg,yDeg:l.yDeg,zDeg:l.zDeg};case"scale":return{kind:"scale",x:l.x,y:l.y,z:l.z};case"rotateAround":return{kind:"rotateAround",axisX:l.axisX,axisY:l.axisY,axisZ:l.axisZ,degrees:l.degrees,pivotX:l.pivotX,pivotY:l.pivotY,pivotZ:l.pivotZ};case"mirror":return{kind:"mirror",normalX:l.normalX,normalY:l.normalY,normalZ:l.normalZ};case"workplanePlacement":return{kind:"workplanePlacement",matrix:Q2e(l.matrix),placement:i6(l.placement)}}}function nqe(l){return{kind:l.kind,points:l.points.map(([o,f,g])=>[o,f,g])}}function Fd(l){if(!l)return null;switch(l.kind){case"rect":return{kind:"rect",width:l.width,height:l.height,center:l.center,transforms:l.transforms.map(XE)};case"roundedRect":return{kind:"roundedRect",width:l.width,height:l.height,radius:l.radius,center:l.center,transforms:l.transforms.map(XE)};case"circle":return{kind:"circle",radius:l.radius,segments:l.segments,transforms:l.transforms.map(XE)};case"polygon":return{kind:"polygon",points:l.points.map(([o,f])=>[o,f]),transforms:l.transforms.map(XE)};case"boolean":return{kind:"boolean",op:l.op,profiles:l.profiles.map(o=>Fd(o)),transforms:l.transforms.map(XE)};case"offset":return{kind:"offset",base:Fd(l.base),delta:l.delta,join:l.join,transforms:l.transforms.map(XE)};case"hull":return{kind:"hull",profiles:l.profiles.map(o=>Fd(o)),transforms:l.transforms.map(XE)};case"project":return{kind:"project",sourceShape:m_(l.sourceShape),plane:{origin:[l.plane.origin[0],l.plane.origin[1],l.plane.origin[2]],u:[l.plane.u[0],l.plane.u[1],l.plane.u[2]],v:[l.plane.v[0],l.plane.v[1],l.plane.v[2]],normal:[l.plane.normal[0],l.plane.normal[1],l.plane.normal[2]]},sourcePlacement:l.sourcePlacement?i6(l.sourcePlacement):void 0,replayProfile:l.replayProfile?Fd(l.replayProfile):void 0,replayReason:l.replayReason,transforms:l.transforms.map(XE)}}}function m_(l){if(!l)return null;switch(l.kind){case"box":return{kind:"box",x:l.x,y:l.y,z:l.z,center:l.center};case"cylinder":return{kind:"cylinder",height:l.height,radius:l.radius,radiusTop:l.radiusTop,segments:l.segments,center:l.center};case"sphere":return{kind:"sphere",radius:l.radius,segments:l.segments};case"extrude":return{kind:"extrude",profile:Fd(l.profile),height:l.height,center:l.center,scaleTop:l.scaleTop?[l.scaleTop[0],l.scaleTop[1]]:void 0};case"sheetMetal":return{kind:"sheetMetal",model:qte(l.model),output:l.output};case"shell":return{kind:"shell",base:m_(l.base),thickness:l.thickness,openFaces:[...l.openFaces],queryPropagation:uC(l.queryPropagation)};case"hole":return{kind:"hole",base:m_(l.base),placement:sq(l.placement),hole:TTt(l.hole),extent:sze(l.extent),queryPropagation:uC(l.queryPropagation)};case"cut":return{kind:"cut",base:m_(l.base),placement:sq(l.placement),profile:Fd(l.profile),extent:sze(l.extent),taper:l.taper?kTt(l.taper):void 0,queryPropagation:uC(l.queryPropagation)};case"revolve":return{kind:"revolve",profile:Fd(l.profile),degrees:l.degrees,segments:l.segments};case"loft":return{kind:"loft",profiles:l.profiles.map(o=>Fd(o)),heights:l.heights.map(o=>o),edgeLength:l.edgeLength,boundsPadding:l.boundsPadding};case"sweep":return{kind:"sweep",profile:Fd(l.profile),path:nqe(l.path),edgeLength:l.edgeLength,boundsPadding:l.boundsPadding,up:[l.up[0],l.up[1],l.up[2]]};case"boolean":return{kind:"boolean",op:l.op,shapes:l.shapes.map(o=>m_(o)),queryPropagation:uC(l.queryPropagation)};case"transform":return{kind:"transform",base:m_(l.base),steps:l.steps.map(kte)};case"queryOwner":return{kind:"queryOwner",owner:lne(l.owner),base:m_(l.base)};case"hull":return{kind:"hull",shapes:l.shapes.map(o=>m_(o)),points:l.points.map(([o,f,g])=>[o,f,g]),queryPropagation:uC(l.queryPropagation)};case"trimByPlane":return{kind:"trimByPlane",base:m_(l.base),normalX:l.normalX,normalY:l.normalY,normalZ:l.normalZ,originOffset:l.originOffset,queryPropagation:uC(l.queryPropagation)};case"fillet":return{kind:"fillet",base:m_(l.base),edge:wl(l.edge),radius:l.radius,quadrant:Jte(l.quadrant),segments:l.segments,resolvedEdge:nze(l.resolvedEdge),queryPropagation:uC(l.queryPropagation)};case"chamfer":return{kind:"chamfer",base:m_(l.base),edge:wl(l.edge),size:l.size,quadrant:Jte(l.quadrant),resolvedEdge:nze(l.resolvedEdge),queryPropagation:uC(l.queryPropagation)}}}function Db(l,o){if(!l)return null;const f=Fd(l);return f.transforms.push(XE(o)),f}function G1(l,o){return l?l.kind==="transform"?{kind:"transform",base:m_(l.base),steps:[...l.steps.map(kte),kte(o)]}:{kind:"transform",base:m_(l),steps:[kte(o)]}:null}function ATt(l,o){let f=m_(l);for(const g of o)f=G1(f,g);return f}function hq(l,o){return l?{kind:"queryOwner",owner:lne(o),base:m_(l)}:null}function s6(l,o){return l?hq(l,une(o)):null}function Ry(l,o){return o.some(f=>f==null)?null:{kind:"boolean",op:l,shapes:o.map(f=>m_(f))}}function _ne(l){if(!l)return null;switch(l.kind){case"queryOwner":return lne(l.owner);case"transform":case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":return _ne(l.base);case"box":case"cylinder":case"sphere":case"extrude":case"sheetMetal":case"revolve":case"loft":case"sweep":case"boolean":case"hull":return null}}function NTt(l){const o=[],f=new Set;function g(T){if(T)switch(T.kind){case"queryOwner":f.has(T.owner.id)||(f.add(T.owner.id),o.push(lne(T.owner))),g(T.base);return;case"transform":case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":g(T.base);return;case"boolean":for(const P of T.shapes)g(P);return;case"hull":for(const P of T.shapes)g(P);return;case"box":case"cylinder":case"sphere":case"extrude":case"sheetMetal":case"revolve":case"loft":case"sweep":return}}return g(l),o}function UJ(l){if(!l)return null;switch(l.kind){case"queryOwner":return UJ(l.base);case"transform":{let o=UJ(l.base);for(const f of l.steps){if(f.kind==="workplanePlacement"){o=sq({matrix:f.matrix,placement:f.placement});continue}o&&(o=DTt(o,f))}return o}case"shell":case"fillet":case"chamfer":return UJ(l.base);case"hole":case"cut":return sq(l.placement);case"trimByPlane":return UJ(l.base);case"box":case"cylinder":case"sphere":case"extrude":case"sheetMetal":case"loft":case"sweep":case"boolean":case"hull":case"revolve":return null}}function iT(l,o){return o.some(f=>f==null)?null:{kind:"boolean",op:l,profiles:o.map(f=>Fd(f)),transforms:[]}}function rqe(l,o,f){return l?{kind:"offset",base:Fd(l),delta:o,join:f,transforms:[]}:null}function iqe(l){return l.some(o=>o==null)?null:{kind:"hull",profiles:l.map(o=>Fd(o)),transforms:[]}}function sqe(l,o=[]){return l.some(f=>f==null)?null:{kind:"hull",shapes:l.map(f=>m_(f)),points:o.map(([f,g,T])=>[f,g,T])}}function wbe(l,o,f){return l?{kind:"trimByPlane",base:m_(l),normalX:R_(o[0]),normalY:R_(o[1]),normalZ:R_(o[2]),originOffset:R_(f)}:null}function ITt(l,o,f,g,T){return!l||!o||!Number.isFinite(f)||!(f>0)||!Number.isFinite(T)||T<2?null:{kind:"fillet",base:m_(l),edge:wl(o),radius:R_(f),quadrant:Jte(g),segments:Math.max(2,Math.round(T))}}function FTt(l,o,f,g){return!l||!o||!Number.isFinite(f)||!(f>0)?null:{kind:"chamfer",base:m_(l),edge:wl(o),size:R_(f),quadrant:Jte(g)}}function OTt(l,o,f){return l.some(g=>g==null)?null:{kind:"loft",profiles:l.map(g=>Fd(g)),heights:o.map(g=>R_(g)),edgeLength:R_(f.edgeLength),boundsPadding:R_(f.boundsPadding)}}function MTt(l,o,f){return l?{kind:"sweep",profile:Fd(l),path:nqe(o),edgeLength:R_(f.edgeLength),boundsPadding:R_(f.boundsPadding),up:[R_(f.up[0]),R_(f.up[1]),R_(f.up[2])]}:null}function Vte(l){var o;if(l===null)return"null";if(l===void 0)return"undefined";if(Array.isArray(l))return`Array(${l.length})`;if(typeof l=="object"){const f=(o=l.constructor)==null?void 0:o.name;return f&&f!=="Object"?f:"object"}return typeof l=="string"?`"${l}"`:typeof l}function aqe({apiName:l,inputs:o,minCount:f,itemName:g,usage:T,coerce:P}){const O=[];for(const z of o)Array.isArray(z)?O.push(...z):O.push(z);if(O.length<f){const z=f===1?g:`${g}s`;throw new Error(`${l} requires at least ${f} ${z}. ${T}`)}return O.map((z,H)=>{try{return P(z)}catch(re){const te=re instanceof Error?re.message:String(re);throw new Error(`${l} argument ${H+1}: ${te}`)}})}function dI(l,o){return{rewriteId:o.id,operation:l,owner:Sp(o),preservedFaces:[],preservedEdges:[],createdFaces:[],createdEdges:[],diagnostics:[],descendants:[]}}function lm(l,o,f,g,T,P){return{code:l,category:o,queryKind:f,message:g,source:f==="face"?iu(T):wl(T),query:f==="face"?iu(P):wl(P)}}function Y1(l,o,f){return{kind:"propagated-face",rewriteId:o.id,outcome:f,source:iu(l),owner:Sp(o)}}function fne(l,o,f){return{kind:"created-face",rewriteId:l.id,operation:o,slot:f,owner:Sp(l)}}function tM(l,o,f){return{kind:"propagated-edge",rewriteId:o.id,outcome:f,source:wl(l),selector:l.selector,owner:Sp(o)}}function oqe(l,o,f,g="edge"){return{kind:"created-edge",rewriteId:l.id,operation:o,slot:f,selector:g,owner:Sp(l)}}function Q1(l,o,f={}){return{queryKind:"face",kind:l,query:iu(o),source:iu(f.source),note:f.note}}function aq(l,o,f={}){return{queryKind:"edge",kind:l,query:wl(o),source:wl(f.source),note:f.note}}function Sh(l,o){l.descendants.push(o)}function pC(){return{faces:new Map,blockedNames:new Map,supportedQueries:[],blockedQueries:[]}}function Lm(l){return[l[0],l[1],l[2]]}function cI(l){return{...l,normal:Lm(l.normal),center:Lm(l.center),query:iu(l.query),uAxis:l.uAxis?Lm(l.uAxis):void 0,vAxis:l.vAxis?Lm(l.vAxis):void 0,descendant:l.descendant?LTt(l.descendant):void 0}}function LTt(l){return{kind:l.kind,semantic:l.semantic,memberCount:l.memberCount,memberNames:[...l.memberNames],coplanar:l.coplanar}}function pne(l,o,f){return{kind:l==="face"&&o.length===1?"single":"face-set",semantic:l,memberCount:o.length,memberNames:[...o],coplanar:f}}function RTt(l){if(l.length<=1)return!0;const o=l[0];if(o.planar===!1||!o.uAxis||!o.vAxis)return!1;const f=td(o.normal),g=f[0]*o.center[0]+f[1]*o.center[1]+f[2]*o.center[2];for(const T of l.slice(1)){if(T.planar===!1||!T.uAxis||!T.vAxis)return!1;const P=td(T.normal),O=Math.abs(f[0]*P[0]+f[1]*P[1]+f[2]*P[2]);if(Math.abs(O-1)>1e-6)return!1;const z=f[0]*T.center[0]+f[1]*T.center[1]+f[2]*T.center[2];if(Math.abs(z-g)>1e-6)return!1}return!0}function jTt(l,o,f,g){return{...l,descendant:pne(o,f,g)}}function BTt(l,o,f,g){const T=o.map(te=>cI(te)),P=T[0],O=RTt(T),z=T.reduce((te,W)=>[te[0]+W.center[0],te[1]+W.center[1],te[2]+W.center[2]],[0,0,0]),H=Math.max(T.length,1),re={...P,name:l,center:[z[0]/H,z[1]/H,z[2]/H],query:iu(f),planar:O?P.planar:!1,uAxis:O?P.uAxis:void 0,vAxis:O?P.vAxis:void 0};return jTt(re,g,T.map(te=>te.name),O)}function Cte(l){return{faces:new Map(Array.from(l.faces.entries(),([o,f])=>[o,cI(f)])),blockedNames:new Map(l.blockedNames),supportedQueries:l.supportedQueries.map(o=>iu(o)),blockedQueries:l.blockedQueries.map(o=>({query:iu(o.query),reason:o.reason}))}}function cqe(l,o){return o?l.some(f=>sT(f,o)):!1}function zTt(l,o){return o?l.some(f=>sT(f.query,o)):!1}function n4(l,o){!o||cqe(l.supportedQueries,o)||l.supportedQueries.push(iu(o))}function wte(l,o,f){!o||zTt(l.blockedQueries,o)||l.blockedQueries.push({query:iu(o),reason:f})}function JTt(l,o){o&&(l.supportedQueries=l.supportedQueries.filter(f=>!sT(f,o)))}function Zu(l,o){const f=cI(o);f.descendant||(f.descendant=pne("face",[f.name],f.planar!==!1)),l.faces.set(f.name,f),n4(l,o.query)}function Ebe(l,o,f,g){const T=l.faces.get(o);T&&(T.query=iu(f),l.faces.set(o,T),n4(l,f),n4(l,g))}function $ee(l,o,f,g,T){const P=l.faces.get(o);P&&(P.query=iu(f),P.descendant=pne(g,[o],P.planar!==!1),l.faces.set(o,P),n4(l,f),n4(l,T))}function aze(l,o,f){const g=l.faces.get(o);g&&(JTt(l,g.query),wte(l,g.query,f),l.faces.delete(o)),l.blockedNames.set(o,f)}function qTt(l,o,f){l.faces.has(o)&&l.faces.delete(o),l.blockedNames.set(o,f)}function WTt(l,o){const f=Ea.from(o);return{...l,center:f.point(l.center),normal:td(f.vector(l.normal)),query:iu(l.query),uAxis:l.uAxis?td(f.vector(l.uAxis)):void 0,vAxis:l.vAxis?td(f.vector(l.vAxis)):void 0}}function VTt(l,o){const f=Cte(l);return f.faces=new Map(Array.from(f.faces.entries(),([g,T])=>[g,WTt(T,o)])),f}function UTt(l){switch(l.kind){case"translate":return Ea.translation(l.x,l.y,l.z).toArray();case"rotate":return Ea.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg).toArray();case"scale":return Ea.scale([l.x,l.y,l.z]).toArray();case"rotateAround":return Ea.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]).toArray();case"mirror":return lqe([l.normalX,l.normalY,l.normalZ]);case"workplanePlacement":return[...l.matrix]}}function lqe(l){const o=Math.hypot(l[0],l[1],l[2]);if(o<1e-12)return Ea.identity().toArray();const f=l[0]/o,g=l[1]/o,T=l[2]/o;return[1-2*f*f,-2*f*g,-2*f*T,0,-2*g*f,1-2*g*g,-2*g*T,0,-2*T*f,-2*T*g,1-2*T*T,0,0,0,0,1]}function Ute(l){let o=Ea.identity();for(const f of l)switch(f.kind){case"translate":o=o.translate(f.x,f.y,0);break;case"rotate":o=o.rotateAxis([0,0,1],f.degrees);break;case"scale":o=o.scale([f.x,f.y,1]);break;case"mirror":o=o.mul(lqe([f.normalX,f.normalY,0]));break}return o.toArray()}function _C(l,o,f){const g=Ea.from(l).point([o,f,0]);return[g[0],g[1]]}function Z2e(l,o){return[(l[0]+o[0])/2,(l[1]+o[1])/2]}function $Tt(l){if(l.length===0)return[0,0,0];const o=l.reduce((f,g)=>[f[0]+g[0],f[1]+g[1],f[2]+g[2]],[0,0,0]);return[o[0]/l.length,o[1]/l.length,o[2]/l.length]}function OJ(l,o){return[l[0]*o[0],l[1]*o[1]]}function MJ(l,o,f,g,T,P,O=0){return[l[0]+o[0]*g+f[0]*T+((P==null?void 0:P[0])??0)*O,l[1]+o[1]*g+f[1]*T+((P==null?void 0:P[1])??0)*O,l[2]+o[2]*g+f[2]*T+((P==null?void 0:P[2])??0)*O]}function HTt(l){const o=Math.hypot(l[0],l[1]);return o<1e-12?[1,0]:[l[0]/o,l[1]/o]}function _2e(l,o){return[l[1]*o[2]-l[2]*o[1],l[2]*o[0]-l[0]*o[2],l[0]*o[1]-l[1]*o[0]]}function GTt(l){const o=td(l),f=Math.abs(o[2])<.9?[0,0,1]:[0,1,0],g=td(_2e(f,o)),T=td(_2e(o,g));return{u:g,v:T}}function ZD(l,o,f,g,T){const P=HTt([f[0]-o[0],f[1]-o[1]]),O=[P[1],-P[0]],z=Z2e(o,f);return{name:l,normal:[O[0],O[1],0],center:[z[0],z[1],g],planar:!0,uAxis:[P[0],P[1],0],vAxis:[0,0,1],query:iu(T)}}function xh(l,o){if(o)return{kind:"tracked-face",faceName:l,owner:o}}function XTt(l,o){const f=pC(),g=l.center?-l.x/2:0,T=l.center?-l.y/2:0,P=g+l.x,O=T+l.y,z=l.center?-l.z/2:0,H=z+l.z,re=[g,T],te=[P,T],W=[P,O],Ee=[g,O],se=xh("top",o),me=xh("bottom",o);return Zu(f,{name:"top",normal:[0,0,1],center:[(g+P)/2,(T+O)/2,H],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0],query:se}),Zu(f,{name:"bottom",normal:[0,0,-1],center:[(g+P)/2,(T+O)/2,z],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0],query:me}),Zu(f,{...ZD("side-bottom",re,te,(H+z)/2,xh("side-bottom",o))}),Zu(f,{...ZD("side-right",te,W,(H+z)/2,xh("side-right",o))}),Zu(f,{...ZD("side-top",W,Ee,(H+z)/2,xh("side-top",o))}),Zu(f,{...ZD("side-left",Ee,re,(H+z)/2,xh("side-left",o))}),f}function YTt(l,o){const f=pC(),g=l.center?-l.height/2:0,T=g+l.height,P=l.radiusTop??l.radius,O=(Math.abs(l.radius)+Math.abs(P))/2;return Zu(f,{name:"top",normal:[0,0,1],center:[0,0,T],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0],query:xh("top",o)}),Zu(f,{name:"bottom",normal:[0,0,-1],center:[0,0,g],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0],query:xh("bottom",o)}),Zu(f,{name:"side",normal:[1,0,0],center:[O,0,(T+g)/2],planar:!1,query:xh("side",o)}),f}function QTt(l,o,f,g){const T=Ute(l.transforms),P=l.center?-l.width/2:0,O=l.center?-l.height/2:0,z=P+l.width,H=O+l.height,re=_C(T,P,O),te=_C(T,z,O),W=_C(T,z,H),Ee=_C(T,P,H),se=Z2e(re,W),me=f?-o/2:0,Xe=me+o,it=td([te[0]-re[0],te[1]-re[1],0]),at=td([Ee[0]-re[0],Ee[1]-re[1],0]),It=pC();return Zu(It,{name:"top",normal:[0,0,1],center:[se[0],se[1],Xe],planar:!0,uAxis:it,vAxis:at,query:xh("top",g)}),Zu(It,{name:"bottom",normal:[0,0,-1],center:[se[0],se[1],me],planar:!0,uAxis:it,vAxis:[-at[0],-at[1],-at[2]],query:xh("bottom",g)}),Zu(It,ZD("side-bottom",re,te,(Xe+me)/2,xh("side-bottom",g))),Zu(It,ZD("side-right",te,W,(Xe+me)/2,xh("side-right",g))),Zu(It,ZD("side-top",W,Ee,(Xe+me)/2,xh("side-top",g))),Zu(It,ZD("side-left",Ee,re,(Xe+me)/2,xh("side-left",g))),It}function ZTt(l,o,f,g){const T=pC(),P=Ute(l.transforms),O=Ea.from(P).point([0,0,0]),z=Ea.from(P).point([l.radius,0,0]),H=td([z[0]-O[0],z[1]-O[1],0]),re=td(Ea.from(P).vector([1,0,0])),te=td(Ea.from(P).vector([0,1,0])),W=f?-o/2:0,Ee=W+o;return Zu(T,{name:"top",normal:[0,0,1],center:[O[0],O[1],Ee],planar:!0,uAxis:re,vAxis:te,query:xh("top",g)}),Zu(T,{name:"bottom",normal:[0,0,-1],center:[O[0],O[1],W],planar:!0,uAxis:re,vAxis:[-te[0],-te[1],-te[2]],query:xh("bottom",g)}),Zu(T,{name:"side",normal:H,center:[z[0],z[1],(Ee+W)/2],planar:!1,query:xh("side",g)}),T}function KTt(l,o){switch(l.profile.kind){case"rect":case"roundedRect":return QTt(l.profile,l.height,l.center,o);case"circle":return ZTt(l.profile,l.height,l.center,o);default:return pC()}}function ux(l,o){var f;return(f=l==null?void 0:l.createdFaces.find(g=>g.query.slot===o))==null?void 0:f.query}function Pbe(l,o){if(o)return l==null?void 0:l.descendants.find(f=>f.queryKind==="face"&&sT(f.query,o))}function LJ(l,o){var f;if(o)return(f=l==null?void 0:l.preservedFaces.find(g=>sT(g.query.source,o)))==null?void 0:f.query}function ekt(l){return`inner-${l}`}function uqe(l,o){const f=px(l),g=[];for(const T of f.faces.keys())T==="top"&&o.includes("top")||T==="bottom"&&o.includes("bottom")||g.push(ekt(T));return g}function tkt(l,o){var g;const f=["wall"];return l.counterbore&&f.push("counterbore-wall","counterbore-floor"),l.countersink&&f.push("countersink-wall"),Rm(o).kind==="blind"&&f.push("floor"),((g=Ab(o))==null?void 0:g.kind)==="blind"&&f.push("cap"),f}function _qe(l,o,f){var T;const g=(()=>{switch(l.kind){case"circle":return["wall"];case"rect":case"roundedRect":return["wall-bottom","wall-right","wall-top","wall-left"];default:return[]}})();return Rm(o).kind==="blind"&&g.push("floor"),((T=Ab(o))==null?void 0:T.kind)==="blind"&&g.push("cap"),g}function nkt(l,o){const f=["entry-rim","forward-end-rim"];return Ab(o)&&f.push("reverse-end-rim"),(l.counterbore||l.countersink)&&f.push("head-transition-rim"),f}function rkt(l,o,f){if(_qe(l,o).length===0)return[];const g=["entry-rim","forward-end-rim"];return Ab(o)&&g.push("reverse-end-rim"),g}function UO(l,o){if(!o)return[];const f=new Set(l.faces.keys()),g=(()=>{switch(o.kind){case"tracked-face":return[o.faceName];case"face-ref":return o.faceName?[o.faceName]:[];case"canonical-face":switch(o.face){case"front":return f.has("side-bottom")?["side-bottom"]:f.has("side")?["side"]:[];case"back":return f.has("side-top")?["side-top"]:f.has("side")?["side"]:[];case"left":return f.has("side-left")?["side-left"]:f.has("side")?["side"]:[];case"right":return f.has("side-right")?["side-right"]:f.has("side")?["side"]:[];case"top":return f.has("top")?["top"]:[];case"bottom":return f.has("bottom")?["bottom"]:[]}case"created-face":return[o.slot];case"propagated-face":return UO(l,o.source)}})();return g.filter((T,P)=>f.has(T)&&g.indexOf(T)===P)}function ikt(l,o){switch(l){case"top":return o.has("bottom")?["bottom"]:[];case"bottom":return o.has("top")?["top"]:[];case"side-bottom":return o.has("side-top")?["side-top"]:[];case"side-top":return o.has("side-bottom")?["side-bottom"]:[];case"side-left":return o.has("side-right")?["side-right"]:[];case"side-right":return o.has("side-left")?["side-left"]:[];case"side":return o.has("side")?["side"]:[];default:return[]}}function oze(l,o){switch(o){case"host":return`This selected host face is rewritten by the ${l} result and is not a defended named face target.`;case"through-exit":return`This opposite face is pierced by the through-${l} and is not a defended named face target.`;case"up-to-face-target":return`This selected up-to-face termination face is rewritten by the ${l} result and is not a defended named face target.`}}function cze(l){switch(l){case"host":return 3;case"up-to-face-target":return 2;case"through-exit":return 1}}function skt(l){var o,f;return((o=l.counterbore)==null?void 0:o.depth)??((f=l.countersink)==null?void 0:f.depth)??0}function akt(l,o){var T;const f=((T=Ab(o))==null?void 0:T.depth)??0;if(f>0)return(Rm(o).depth-f)/2;const g=skt(l);return g+Math.max(Rm(o).depth-g,0)/2}function okt(l){var f;const o=((f=Ab(l))==null?void 0:f.depth)??0;return(Rm(l).depth-o)/2}function $te(l,o,f){if(!l)return[];const g=px(l),T=new Set(g.faces.keys()),P=new Map,O=(te,W)=>{const Ee=P.get(te);(!Ee||cze(W)>cze(Ee))&&P.set(te,W)},z=UO(g,o),H=Rm(f);for(const te of z)if(O(te,"host"),H.kind==="through")for(const W of ikt(te,T))O(W,"through-exit");if(H.kind==="upToFace")for(const te of UO(g,H.face))O(te,"up-to-face-target");const re=Ab(f);if((re==null?void 0:re.kind)==="upToFace")for(const te of UO(g,re.face))O(te,"up-to-face-target");return Array.from(P.entries()).map(([te,W])=>({name:te,reason:W})).sort((te,W)=>te.name.localeCompare(W.name))}function Hee(l,o){var f;return o?Pb((f=l.query)==null?void 0:f.owner,o):!0}function fqe(l,o,f,g){switch(g.kind){case"tracked-face":return o===g.faceName&&Hee(f,g.owner);case"face-ref":return(g.faceName==null||o===g.faceName)&&Hee(f,g.owner);case"canonical-face":return UO(l,g).includes(o)&&Hee(f,g.owner);case"created-face":return o===g.slot&&Hee(f,g.owner);case"propagated-face":return sT(f.query,g)||fqe(l,o,f,g.source)}}function ckt(l,o){if(!o)return[];const f=new Set,g=[];for(const[T,P]of l.faces.entries())f.has(T)||fqe(l,T,P,o)&&(f.add(T),g.push({name:T,face:cI(P)}));return g}function lkt(l,o){return l.flatMap(f=>ckt(f,o))}function ukt(l){if(l.length===0)return null;const o=[...new Set(l.map(f=>f.name))];return o.length===1?o[0]:null}function _kt(l,o){return l??o}function fkt(l,o){const f=l.get(o.name);if(f){f.push(o);return}l.set(o.name,[o])}function pkt(l,o,f){for(const[g,T]of o.entries()){const P=T.length===1?T[0].query:{kind:"face-ref",faceName:g,owner:Sp(f)},O=T.some(H=>H.semantic==="region")?"region":T.length>1?"set":T[0].semantic,z=BTt(g,T.map(H=>H.face),P,O);Zu(l,z);for(const H of T){n4(l,H.query);for(const re of H.aliases)n4(l,re)}T.length>1&&n4(l,P)}}function f2e(l,o){var f,g,T;if(!l)return pC();switch(l.kind){case"queryOwner":return f2e(l.base,o??l.owner);case"transform":{let P=f2e(l.base,o);for(const O of l.steps)P=VTt(P,UTt(O));return P}case"box":return XTt(l,o);case"cylinder":return YTt(l,o);case"extrude":return KTt(l,o);case"sheetMetal":{const P=pC();for(const O of vTt(l.model,l.output))Zu(P,{name:O.name,normal:Lm(O.normal),center:Lm(O.center),planar:O.planar,uAxis:O.uAxis?Lm(O.uAxis):void 0,vAxis:O.vAxis?Lm(O.vAxis):void 0,query:xh(O.name,o),descendant:pne(O.semantic,O.memberNames,O.coplanar)});return P}case"shell":{const P=Cte(px(l.base));for(const[O,z]of P.faces.entries()){const H=LJ(l.queryPropagation,z.query);H&&Ebe(P,O,H,z.query)}for(const O of uqe(l.base,l.openFaces)){const z=O.slice(6),H=P.faces.get(z),re=ux(l.queryPropagation,O);!H||!re||Zu(P,{...cI(H),name:O,center:[H.center[0]-H.normal[0]*l.thickness,H.center[1]-H.normal[1]*l.thickness,H.center[2]-H.normal[2]*l.thickness],normal:[-H.normal[0],-H.normal[1],-H.normal[2]],uAxis:H.uAxis?Lm(H.uAxis):void 0,vAxis:H.vAxis?[-H.vAxis[0],-H.vAxis[1],-H.vAxis[2]]:void 0,query:re})}return P}case"hole":{const P=Cte(px(l.base));for(const[at,It]of P.faces.entries()){const tn=LJ(l.queryPropagation,It.query),At=Pbe(l.queryPropagation,tn);if(tn&&(At==null?void 0:At.kind)==="face-region"){$ee(P,at,tn,"region",It.query);continue}tn&&Ebe(P,at,tn,It.query)}for(const at of $te(l.base,l.placement.placement.workplane.source,l.extent)){const It=P.faces.get(at.name);if(((f=It==null?void 0:It.descendant)==null?void 0:f.semantic)==="region")continue;const tn=It?LJ(l.queryPropagation,It.query):void 0;if(It&&tn){$ee(P,at.name,tn,"region",It.query);continue}aze(P,at.name,oze("hole",at.reason))}const O=l.placement.placement.workplane,z=O.origin,H=[-O.normal[0],-O.normal[1],-O.normal[2]],re=Rm(l.extent),te=Ab(l.extent),W=ux(l.queryPropagation,"wall");if(W){const at=akt(l.hole,l.extent);Zu(P,{name:"wall",normal:[-O.u[0],-O.u[1],-O.u[2]],center:[z[0]+O.u[0]*l.hole.radius+H[0]*at,z[1]+O.u[1]*l.hole.radius+H[1]*at,z[2]+O.u[2]*l.hole.radius+H[2]*at],planar:!1,query:W})}const Ee=ux(l.queryPropagation,"counterbore-wall");Ee&&l.hole.counterbore&&Zu(P,{name:"counterbore-wall",normal:[-O.u[0],-O.u[1],-O.u[2]],center:[z[0]+O.u[0]*l.hole.counterbore.radius+H[0]*(l.hole.counterbore.depth/2),z[1]+O.u[1]*l.hole.counterbore.radius+H[1]*(l.hole.counterbore.depth/2),z[2]+O.u[2]*l.hole.counterbore.radius+H[2]*(l.hole.counterbore.depth/2)],planar:!1,query:Ee});const se=ux(l.queryPropagation,"counterbore-floor");se&&l.hole.counterbore&&Zu(P,{name:"counterbore-floor",normal:Lm(O.normal),center:[z[0]+H[0]*l.hole.counterbore.depth,z[1]+H[1]*l.hole.counterbore.depth,z[2]+H[2]*l.hole.counterbore.depth],planar:!0,uAxis:Lm(O.u),vAxis:Lm(O.v),query:se});const me=ux(l.queryPropagation,"countersink-wall");if(me&&l.hole.countersink){const at=l.hole.countersink.depth/2,It=(l.hole.radius+l.hole.countersink.radius)/2;Zu(P,{name:"countersink-wall",normal:[-O.u[0],-O.u[1],-O.u[2]],center:[z[0]+O.u[0]*It+H[0]*at,z[1]+O.u[1]*It+H[1]*at,z[2]+O.u[2]*It+H[2]*at],planar:!1,query:me})}const Xe=ux(l.queryPropagation,"floor");Xe&&Zu(P,{name:"floor",normal:Lm(O.normal),center:[z[0]+H[0]*re.depth,z[1]+H[1]*re.depth,z[2]+H[2]*re.depth],planar:!0,uAxis:Lm(O.u),vAxis:Lm(O.v),query:Xe});const it=ux(l.queryPropagation,"cap");return it&&(te==null?void 0:te.kind)==="blind"&&Zu(P,{name:"cap",normal:[-O.normal[0],-O.normal[1],-O.normal[2]],center:[z[0]-H[0]*te.depth,z[1]-H[1]*te.depth,z[2]-H[2]*te.depth],planar:!0,uAxis:Lm(O.u),vAxis:[-O.v[0],-O.v[1],-O.v[2]],query:it}),P}case"cut":{const P=Cte(px(l.base));for(const[Xe,it]of P.faces.entries()){const at=LJ(l.queryPropagation,it.query),It=Pbe(l.queryPropagation,at);if(at&&(It==null?void 0:It.kind)==="face-region"){$ee(P,Xe,at,"region",it.query);continue}at&&Ebe(P,Xe,at,it.query)}for(const Xe of $te(l.base,l.placement.placement.workplane.source,l.extent)){const it=P.faces.get(Xe.name);if(((g=it==null?void 0:it.descendant)==null?void 0:g.semantic)==="region")continue;const at=it?LJ(l.queryPropagation,it.query):void 0;if(it&&at){$ee(P,Xe.name,at,"region",it.query);continue}aze(P,Xe.name,oze("cut",Xe.reason))}const O=l.placement.placement,z=O.workplane.origin,H=[-O.workplane.normal[0],-O.workplane.normal[1],-O.workplane.normal[2]],re=Rm(l.extent),te=Ab(l.extent),W=(te==null?void 0:te.depth)??0,Ee=okt(l.extent);if(l.profile.kind==="circle"){const Xe=ux(l.queryPropagation,"wall");if(Xe){const it=l.profile.radius,at=l.taper?it*l.taper.scale[0]:it,It=(it+at)/2;Zu(P,{name:"wall",normal:[-O.workplane.u[0],-O.workplane.u[1],-O.workplane.u[2]],center:[z[0]+O.workplane.u[0]*It+H[0]*Ee,z[1]+O.workplane.u[1]*It+H[1]*Ee,z[2]+O.workplane.u[2]*It+H[2]*Ee],planar:!1,query:Xe})}}if(l.profile.kind==="rect"||l.profile.kind==="roundedRect"){const Xe=Ute(l.profile.transforms),it=l.profile.center?-l.profile.width/2:0,at=l.profile.center?-l.profile.height/2:0,It=it+l.profile.width,tn=at+l.profile.height,At=_C(Xe,it,at),mt=_C(Xe,It,at),ht=_C(Xe,It,tn),xn=_C(Xe,it,tn),Pn=((T=l.taper)==null?void 0:T.scale)??[1,1],$r=OJ(At,Pn),zn=OJ(mt,Pn),ii=OJ(ht,Pn),Gr=OJ(xn,Pn),mn=[{name:"wall-bottom",reverseStart:At,reverseEnd:mt,forwardStart:$r,forwardEnd:zn},{name:"wall-right",reverseStart:mt,reverseEnd:ht,forwardStart:zn,forwardEnd:ii},{name:"wall-top",reverseStart:ht,reverseEnd:xn,forwardStart:ii,forwardEnd:Gr},{name:"wall-left",reverseStart:xn,reverseEnd:At,forwardStart:Gr,forwardEnd:$r}];for(const $s of mn){const is=ux(l.queryPropagation,$s.name);if(!is)continue;const Wt=MJ(z,O.workplane.u,O.workplane.v,$s.reverseStart[0],$s.reverseStart[1],H,-W),Es=MJ(z,O.workplane.u,O.workplane.v,$s.reverseEnd[0],$s.reverseEnd[1],H,-W),Hs=MJ(z,O.workplane.u,O.workplane.v,$s.forwardStart[0],$s.forwardStart[1],H,re.depth),Ua=MJ(z,O.workplane.u,O.workplane.v,$s.forwardEnd[0],$s.forwardEnd[1],H,re.depth),Di=td([Es[0]-Wt[0],Es[1]-Wt[1],Es[2]-Wt[2]]),ko=td([Hs[0]-Wt[0],Hs[1]-Wt[1],Hs[2]-Wt[2]]),K_=td(_2e(Di,ko));Zu(P,{name:$s.name,normal:K_,center:$Tt([Wt,Es,Hs,Ua]),planar:!0,uAxis:Di,vAxis:ko,query:is})}}const se=ux(l.queryPropagation,"floor");if(se){const Xe=(()=>{if(l.profile.kind==="rect"||l.profile.kind==="roundedRect"){const it=Ute(l.profile.transforms),at=l.profile.center?-l.profile.width/2:0,It=l.profile.center?-l.profile.height/2:0,tn=at+l.profile.width,At=It+l.profile.height,mt=Z2e(_C(it,at,It),_C(it,tn,At)),ht=l.taper?OJ(mt,l.taper.scale):mt;return MJ(z,O.workplane.u,O.workplane.v,ht[0],ht[1],H,re.depth)}return[z[0]+H[0]*re.depth,z[1]+H[1]*re.depth,z[2]+H[2]*re.depth]})();Zu(P,{name:"floor",normal:Lm(O.workplane.normal),center:Xe,planar:!0,uAxis:Lm(O.workplane.u),vAxis:Lm(O.workplane.v),query:se})}const me=ux(l.queryPropagation,"cap");return me&&(te==null?void 0:te.kind)==="blind"&&Zu(P,{name:"cap",normal:[-O.workplane.normal[0],-O.workplane.normal[1],-O.workplane.normal[2]],center:[z[0]-H[0]*te.depth,z[1]-H[1]*te.depth,z[2]-H[2]*te.depth],planar:!0,uAxis:Lm(O.workplane.u),vAxis:[-O.workplane.v[0],-O.workplane.v[1],-O.workplane.v[2]],query:me}),P}case"sphere":case"revolve":case"loft":case"sweep":case"hull":case"fillet":case"chamfer":return pC();case"trimByPlane":{const P=pC(),O=ux(l.queryPropagation,"plane-cap");if(!O)return P;const z=px(l.base),H=Array.from(z.faces.values()).map(me=>me.center),re=H.length>0?H.reduce((me,Xe)=>[me[0]+Xe[0],me[1]+Xe[1],me[2]+Xe[2]],[0,0,0]).map(me=>me/H.length):[0,0,l.originOffset],te=td([l.normalX,l.normalY,l.normalZ]),W=re[0]*te[0]+re[1]*te[1]+re[2]*te[2]-l.originOffset,Ee=[re[0]-te[0]*W,re[1]-te[1]*W,re[2]-te[2]*W],se=GTt(te);return Zu(P,{name:"plane-cap",normal:te,center:Ee,planar:!0,uAxis:se.u,vAxis:se.v,query:O}),P}case"boolean":{const P=pC(),O=l.shapes.map(re=>px(re)),z=l.queryPropagation;if(!z)return P;const H=new Map;for(const re of z.preservedFaces){const te=iu(re.query),W=lkt(O,re.query.source),Ee=Pbe(z,te);if(re.status==="ambiguous"&&!Ee){const me=ukt(W),Xe=_kt(re.note,"This propagated boolean face lineage is ambiguous and is not part of the defended named-face subset.");for(const it of W)wte(P,it.face.query,Xe);me&&qTt(P,me,Xe),wte(P,re.query,Xe),wte(P,re.query.kind==="propagated-face"?re.query.source:void 0,Xe);continue}const se=(Ee==null?void 0:Ee.kind)==="face-region"?"region":(Ee==null?void 0:Ee.kind)==="face-set"?"set":"face";for(const me of W)fkt(H,{name:me.name,face:cI(me.face),query:te,semantic:se,aliases:[te,...re.query.kind==="propagated-face"?[re.query.source]:[],...me.face.query?[me.face.query]:[]].filter(Xe=>Xe!=null)})}return pkt(P,H,z.owner),P}}}function px(l){return f2e(l,_ne(l))}function dkt(l){return Array.from(px(l).faces.keys()).sort()}function mkt(l){const o=px(l);return Array.from(o.faces.entries()).filter(([,f])=>f.query!=null).map(([f,g])=>({name:f,query:iu(g.query)})).sort((f,g)=>f.name.localeCompare(g.name))}function lze(l,o){const g=px(l).faces.get(o);return g?cI(g):null}function uze(l,o){const f=px(l),g=f.blockedNames.get(o);if(g)return g;const T=Array.from(f.faces.keys()).sort();return`Face "${o}" is not available. Supported faces: ${T.join(", ")||"none"}`}function hkt(l,o){if(!o)return null;const f=px(l);if(cqe(f.supportedQueries,o))return null;const g=UO(f,o);if(g.some(P=>f.faces.has(P)))return null;for(const P of g){const O=f.blockedNames.get(P);if(O)return O}const T=f.blockedQueries.find(P=>sT(P.query,o));return T?T.reason:o.kind==="created-face"||o.kind==="propagated-face"?"This face query is not part of the target shape's defended face subset.":g.length===0&&f.faces.size===0&&f.blockedQueries.length===0||o.kind==="tracked-face"||o.kind==="canonical-face"||o.kind==="face-ref"?null:"This face query is not part of the target shape's defended face subset."}function gkt(l,o){return l?uqe(l,o).sort():[]}function ykt(l,o){return tkt(l,o)}function vkt(l,o,f){return _qe(l,o)}function bkt(l,o){return nkt(l,o)}function xkt(l,o,f){return rkt(l,o)}function dne(l){return mkt(l)}const Skt=["front","back","left","right","top","bottom"];function K2e(l){if(!l)return null;switch(l.kind){case"queryOwner":case"transform":return K2e(l.base);case"shell":case"hole":case"cut":case"boolean":case"hull":case"trimByPlane":case"fillet":case"chamfer":return uC(l.queryPropagation)??null;case"box":case"cylinder":case"sphere":case"extrude":case"sheetMetal":case"revolve":case"loft":case"sweep":return null}}function _ze(l,o){const f=l.find(g=>sT(g.source,o.source));if(!f){l.push({source:iu(o.source),status:o.status});return}o.status==="ambiguous"&&(f.status="ambiguous")}function fze(l,o){const f=l.find(g=>gC(g.source,o.source));if(!f){l.push({source:wl(o.source),status:o.status});return}o.status==="ambiguous"&&(f.status="ambiguous")}function Tkt(l){return l?Skt.map(o=>({source:{kind:"canonical-face",face:o,owner:Sp(l)},status:"supported"})):[]}function kkt(l){const o=K2e(l);if(!o)return Tkt(_ne(l));const f=[];for(const g of o.preservedFaces)_ze(f,{source:g.query,status:g.status});for(const g of o.createdFaces)_ze(f,{source:g.query,status:"supported"});return f}function Ckt(l){const o=K2e(l);if(!o)return[];const f=[];for(const g of o.preservedEdges)fze(f,{source:g.query,status:g.status});for(const g of o.createdEdges)fze(f,{source:g.query,status:"supported"});return f}function wkt(l){const o=[];for(const f of l){const g=o.find(T=>sT(T.source,f.source));if(g){g.count+=1,g.hasAmbiguousSource=g.hasAmbiguousSource||f.status==="ambiguous";continue}o.push({source:iu(f.source),count:1,hasAmbiguousSource:f.status==="ambiguous"})}return o}function Ekt(l){const o=[];for(const f of l){const g=o.find(T=>gC(T.source,f.source));if(g){g.count+=1,g.hasAmbiguousSource=g.hasAmbiguousSource||f.status==="ambiguous";continue}o.push({source:wl(f.source),count:1,hasAmbiguousSource:f.status==="ambiguous"})}return o}function exe(l,o){const f=o?l:l.slice(0,1);return wkt(f.flatMap(g=>kkt(g)))}function txe(l,o){const f=o?l:l.slice(0,1);return Ekt(f.flatMap(g=>Ckt(g)))}function nxe(l,o){const f=o==="union"?"Boolean union preserved owner lineage, but none of its operands exposed defended face queries in the supported subset.":o==="difference"?"Boolean difference can only propagate explicit base-operand face queries, and none were available in the supported subset.":"Boolean intersection needs explicit operand face queries to defend any surviving descendants, and none were available in the supported subset.";l.diagnostics.push(lm(`boolean-${o}-face-propagation-unsupported`,"unsupported","face",f))}function rxe(l,o){const f=o==="union"?"Boolean union preserved owner lineage, but none of its operands exposed defended edge queries in the supported subset.":o==="difference"?"Boolean difference can only propagate explicit base-operand edge queries, and none were available in the supported subset.":"Boolean intersection needs explicit operand edge queries to defend any surviving descendants, and none were available in the supported subset.";l.diagnostics.push(lm(`boolean-${o}-edge-propagation-unsupported`,"unsupported","edge",f))}function Pkt(l,o,f){const g=exe(f,!0);if(g.length===0){nxe(o,"union");return}for(const T of g){if(T.count===1&&!T.hasAmbiguousSource){const O=Y1(T.source,l,"preserved");o.preservedFaces.push({query:O,status:"supported"}),Sh(o,Q1("single",O,{source:T.source,note:"Boolean union keeps one defended single face descendant for this lineage."}));continue}const P=Y1(T.source,l,T.count>1?"merged":"preserved");o.preservedFaces.push({query:P,status:"ambiguous"}),T.count>1&&!T.hasAmbiguousSource&&Sh(o,Q1("face-set",P,{source:T.source,note:"Boolean union keeps a defended descendant face set for this merged lineage."})),o.diagnostics.push(lm(T.count>1?"boolean-union-face-merged-ambiguous":"boolean-union-face-inherited-ambiguity","ambiguous","face",T.count>1?`Boolean union cannot defend ${rq(T.source)} because ${T.count} operand descendants share that face lineage and may merge.`:`Boolean union inherits ${rq(T.source)} from an already-ambiguous rewrite result, so the post-union descendant remains ambiguous.`,T.source,P))}}function Dkt(l,o,f){const g=txe(f,!0);if(g.length===0){rxe(o,"union");return}for(const T of g){if(T.count===1&&!T.hasAmbiguousSource){const O=tM(T.source,l,"preserved");o.preservedEdges.push({query:O,status:"supported"}),Sh(o,aq("single",O,{source:T.source,note:"Boolean union keeps one defended single edge descendant for this lineage."}));continue}const P=tM(T.source,l,T.count>1?"merged":"preserved");o.preservedEdges.push({query:P,status:"ambiguous"}),o.diagnostics.push(lm(T.count>1?"boolean-union-edge-merged-ambiguous":"boolean-union-edge-inherited-ambiguity","ambiguous","edge",T.count>1?`Boolean union cannot defend ${iq(T.source)} because ${T.count} operand descendants share that edge lineage and may merge.`:`Boolean union inherits ${iq(T.source)} from an already-ambiguous rewrite result, so the post-union descendant remains ambiguous.`,T.source,P))}}function Akt(l,o,f){const g=exe(f,!1);if(g.length===0){nxe(o,"difference");return}for(const T of g){const P=Y1(T.source,l,"split");o.preservedFaces.push({query:P,status:"ambiguous"}),Sh(o,Q1("face-region",P,{source:T.source,note:"Boolean difference keeps a defended descendant region on the source surface."})),o.diagnostics.push(lm("boolean-difference-face-split-ambiguous","ambiguous","face",`Boolean difference can trace ${rq(T.source)} to the base operand, but subtractive cutters may split or erase its surviving descendants.`,T.source,P))}}function Nkt(l,o,f){const g=txe(f,!1);if(g.length===0){rxe(o,"difference");return}for(const T of g){const P=tM(T.source,l,"split");o.preservedEdges.push({query:P,status:"ambiguous"}),o.diagnostics.push(lm("boolean-difference-edge-split-ambiguous","ambiguous","edge",`Boolean difference can trace ${iq(T.source)} to the base operand, but subtractive cutters may split or erase its surviving descendants.`,T.source,P))}}function Ikt(l,o,f){const g=exe(f,!0);if(g.length===0){nxe(o,"intersection");return}for(const T of g){const P=Y1(T.source,l,"split");o.preservedFaces.push({query:P,status:"ambiguous"}),Sh(o,Q1("face-region",P,{source:T.source,note:"Boolean intersection keeps a defended descendant region on the source surface."})),o.diagnostics.push(lm("boolean-intersection-face-split-ambiguous","ambiguous","face",`Boolean intersection can trace ${rq(T.source)}, but the kept overlap is only a clipped descendant subset and cannot be defended as one stable face target.`,T.source,P))}}function Fkt(l,o,f){const g=txe(f,!0);if(g.length===0){rxe(o,"intersection");return}for(const T of g){const P=tM(T.source,l,"split");o.preservedEdges.push({query:P,status:"ambiguous"}),o.diagnostics.push(lm("boolean-intersection-edge-split-ambiguous","ambiguous","edge",`Boolean intersection can trace ${iq(T.source)}, but the kept overlap is only a clipped descendant subset and cannot be defended as one stable edge target.`,T.source,P))}}function YD(l,o,f){const g=dI(`boolean:${l}`,o);switch(l){case"union":return Pkt(o,g,f),Dkt(o,g,f),g;case"difference":return Akt(o,g,f),Nkt(o,g,f),g;case"intersection":return Ikt(o,g,f),Fkt(o,g,f),g}}function pqe(l,o){switch(o){case"host":return`The selected host face is rewritten by the ${l} result and is not a defended named target.`;case"through-exit":return`This opposite face is pierced by the through-${l} and is not a defended named target.`;case"up-to-face-target":return`The selected up-to-face termination face is rewritten by the ${l} result and is not a defended named target.`}}function Okt(l,o,f){switch(l){case"entry-rim":return"Hole results record the entry perimeter as a defended descendant edge chain on the host face.";case"forward-end-rim":{const g=Rm(f);return g.kind==="blind"?"Blind holes record the floor perimeter as a defended descendant edge chain.":g.kind==="upToFace"?"Hole upToFace results record the termination perimeter as a defended descendant edge chain.":"Through holes record the exit perimeter as a defended descendant edge chain."}case"reverse-end-rim":{const g=Ab(f);return(g==null?void 0:g.kind)==="blind"?"Reverse two-sided holes record the cap perimeter as a defended descendant edge chain.":"Reverse two-sided hole termination stays visible as a defended descendant edge chain."}case"head-transition-rim":return o.counterbore?"Counterbored holes record the shoulder transition as a defended descendant edge chain.":"Countersunk holes record the sink-to-shaft transition as a defended descendant edge chain.";default:return"This hole-created edge chain stays inspectable in the defended topology-rewrite subset."}}function Mkt(l,o){switch(l){case"entry-rim":return"Cut results record the sketched entry perimeter as a defended descendant edge chain on the host face.";case"forward-end-rim":{const f=Rm(o);return f.kind==="blind"?"Blind cutouts record the floor perimeter as a defended descendant edge chain.":f.kind==="upToFace"?"Cut upToFace results record the termination perimeter as a defended descendant edge chain.":"Through cutouts record the exit perimeter as a defended descendant edge chain."}case"reverse-end-rim":{const f=Ab(o);return(f==null?void 0:f.kind)==="blind"?"Reverse two-sided cutouts record the cap perimeter as a defended descendant edge chain.":"Reverse two-sided cut termination stays visible as a defended descendant edge chain."}default:return"This cut-created edge chain stays inspectable in the defended topology-rewrite subset."}}function dqe(l,o,f,g){const T=Rm(g);T.kind==="upToFace"&&l.diagnostics.push(lm(`${f}-up-to-face-target-split-ambiguous`,"ambiguous","face",`${f==="hole"?"Hole":"Cut"} upToFace intent records the selected termination face as an explicit split-face ambiguity instead of silently keeping it queryable.`,T.face,Y1(T.face,o,"split")));const P=Ab(g);(P==null?void 0:P.kind)==="upToFace"&&l.diagnostics.push(lm(`${f}-reverse-up-to-face-target-split-ambiguous`,"ambiguous","face",`${f==="hole"?"Hole":"Cut"} reverse upToFace intent records the selected reverse termination face as an explicit split-face ambiguity instead of silently keeping it queryable.`,P.face,Y1(P.face,o,"split")))}function Lkt(l,o,f){const g=dI("shell",l),T=dne(o),P=gkt(o,f);for(const O of T){const z=Y1(O.query,l,"preserved");g.preservedFaces.push({query:z,status:"supported",note:"The outer shell face survives as a defended preserved-face query on the shelled result."}),Sh(g,Q1("single",z,{source:O.query,note:"Shell keeps this face as one defended single descendant."}))}for(const O of P){const z=fne(l,"shell",O);g.createdFaces.push({query:z,note:"This shell-created inner face is part of the defended named-face subset."}),Sh(g,Q1("single",z,{note:"This shell-created face resolves to one defended descendant."}))}if(T.length===0&&P.length===0){const O=f.length>0?` Open faces: ${f.join(", ")}.`:"";g.diagnostics.push(lm("shell-face-propagation-unsupported","unsupported","face",`Shell exact lowering is supported here, but compiler-owned face propagation is not defended for this shell base.${O}`))}return g.diagnostics.push(lm("shell-edge-propagation-ambiguous","ambiguous","edge","Shell rewrites result edges, but durable edge-query propagation is not defended yet.")),g}function Rkt(l,o,f,g,T){const P=dI("hole",l),O=new Map($te(o,f.workplane.source,T).map(z=>[z.name,z.reason]));for(const z of dne(o)){const H=O.get(z.name);if(H){const te=Y1(z.query,l,"split");P.preservedFaces.push({query:te,status:"ambiguous",note:pqe("hole",H)}),Sh(P,Q1("face-region",te,{source:z.query,note:"This rewritten hole face remains a defended descendant region on the same source surface."}));continue}const re=Y1(z.query,l,"preserved");P.preservedFaces.push({query:re,status:"supported",note:"This face stays queryable through the hole rewrite."}),Sh(P,Q1("single",re,{source:z.query,note:"This hole descendant stays one defended face."}))}for(const z of ykt(g,T)){const H=fne(l,"hole",z);P.createdFaces.push({query:H,note:(()=>{switch(z){case"floor":return"Blind holes create a defended planar floor face.";case"counterbore-floor":return"Counterbored holes create a defended planar shoulder face.";case"counterbore-wall":return"Counterbored holes create a defended counterbore wall-face query.";case"countersink-wall":return"Countersunk holes create a defended countersink wall-face query.";default:return"Hole results create a defended wall-face query."}})()}),Sh(P,Q1("single",H,{note:"This hole-created face resolves to one defended descendant."}))}for(const z of bkt(g,T)){const H=oqe(l,"hole",z);P.createdEdges.push({query:H,note:Okt(z,g,T)}),Sh(P,aq("edge-chain",H,{note:"This hole-created edge query resolves to a defended descendant chain."}))}return P.diagnostics.push(lm("hole-source-face-split-ambiguous","ambiguous","face","Hole intent records which rewritten host/exit faces are ambiguous instead of silently accepting them.",f.workplane.source,Y1(f.workplane.source,l,"split"))),dqe(P,l,"hole",T),P}function jkt(l,o,f,g,T,P){const O=dI("cut",l),z=new Map($te(o,f.workplane.source,T).map(re=>[re.name,re.reason]));for(const re of dne(o)){const te=z.get(re.name);if(te){const Ee=Y1(re.query,l,"split");O.preservedFaces.push({query:Ee,status:"ambiguous",note:pqe("cut",te)}),Sh(O,Q1("face-region",Ee,{source:re.query,note:"This rewritten cut face remains a defended descendant region on the same source surface."}));continue}const W=Y1(re.query,l,"preserved");O.preservedFaces.push({query:W,status:"supported",note:"This face stays queryable through the cut rewrite."}),Sh(O,Q1("single",W,{source:re.query,note:"This cut descendant stays one defended face."}))}const H=vkt(g,T);for(const re of H){const te=fne(l,"cut",re);O.createdFaces.push({query:te,note:re==="floor"?"Blind cutouts create a defended planar floor face.":"This cut-created wall face is part of the defended named-face subset."}),Sh(O,Q1("single",te,{note:"This cut-created face resolves to one defended descendant."}))}for(const re of xkt(g,T)){const te=oqe(l,"cut",re);O.createdEdges.push({query:te,note:Mkt(re,T)}),Sh(O,aq("edge-chain",te,{note:"This cut-created edge query resolves to a defended descendant chain."}))}return O.diagnostics.push(lm("cut-source-face-split-ambiguous","ambiguous","face","Cut intent records which rewritten host/exit faces are ambiguous instead of silently accepting them.",f.workplane.source,Y1(f.workplane.source,l,"split"))),dqe(O,l,"cut",T),H.length===0&&O.diagnostics.push(lm("cut-created-face-subset-unsupported","unsupported","face","This cut profile does not fall inside the defended cut-created face subset yet.")),O}function mqe(l){const o=dI("hull",l);return o.diagnostics.push(lm("hull-face-propagation-unsupported","unsupported","face","Hull combines source solids through a full topology rewrite, so face-query propagation is not defended yet."),lm("hull-edge-propagation-unsupported","unsupported","edge","Hull combines source solids through a full topology rewrite, so edge-query propagation is not defended yet.")),o}function Dbe(l,o){const f=dI("trimByPlane",l);for(const T of dne(o)){const P=Y1(T.query,l,"split");f.preservedFaces.push({query:P,status:"ambiguous",note:"Trim keeps a clipped descendant region on the source surface instead of one untouched face."}),Sh(f,Q1("face-region",P,{source:T.query,note:"Trim keeps a defended descendant region on the source surface."}))}const g=fne(l,"trimByPlane","plane-cap");return f.createdFaces.push({query:g,note:"The kept side of the trim introduces one deterministic cap face on the trim plane."}),Sh(f,Q1("single",g,{note:"The trim plane cap resolves to one defended descendant face."})),f.diagnostics.push(lm("trim-by-plane-preserved-face-propagation-ambiguous","ambiguous","face","Trim-by-plane now exposes its created plane-cap face, but preserved non-cap face propagation is still ambiguous."),lm("trim-by-plane-edge-propagation-ambiguous","ambiguous","edge","Trim-by-plane boundary edge propagation is not defended yet.")),f}function Bkt(l,o,f,g=[]){const T=dI(l,o);for(const P of g){const O=tM(P,o,"preserved");T.preservedEdges.push({query:O,status:"supported",note:`${l} leaves this supported propagated vertical edge lineage unchanged in the defended post-rewrite subset.`}),Sh(T,aq("single",O,{source:P,note:`${l} keeps this edge as one defended single descendant.`}))}if(f){const P=tM(f,o,"merged");T.preservedEdges.push({query:P,status:"ambiguous",note:`${l} rewrites the selected edge into a blended descendant set rather than one defended edge target.`}),Sh(T,aq("edge-chain",P,{source:f,note:`${l} rewrites the selected edge into a defended descendant chain instead of one single edge target.`})),T.diagnostics.push(lm(`${l}-selected-edge-merged-ambiguous`,"ambiguous","edge",`${l} records that the selected edge is merged into rewritten descendants, but a durable post-rewrite edge target is not defended yet.`,f,P))}return T.diagnostics.push(lm(`${l}-created-face-propagation-unsupported`,"unsupported","face",`${l}-created face semantics are not part of the topology-rewrite kernel yet.`)),T}function zkt(l){return l.kind==="shell"||l.kind==="hole"||l.kind==="cut"||l.kind==="boolean"||l.kind==="hull"||l.kind==="trimByPlane"||l.kind==="fillet"||l.kind==="chamfer"}function Jkt(l,o){return{...l,queryPropagation:uC(o)}}function ixe(l,o){if(!l)return l;if(!zkt(l))throw new Error(`Cannot attach topology-rewrite propagation to non-rewrite plan kind "${l.kind}".`);return Jkt(l,o)}function hqe(l,o){return s6(l,o)}function qkt(l,o){return`pattern:${l}:${o}`}const sxe=Symbol.for("forgecad.shapeBackend");var qJe;qJe=sxe;const Om=class Om{constructor(o){tu(this,qJe,!0);this.manifold=o}clone(){return new Om(this.manifold)}translate(o,f,g){return new Om(this.manifold.translate(o,f,g))}rotate(o,f,g){return new Om(this.manifold.rotate(o,f,g))}transform(o){return new Om(this.manifold.transform(o))}scale(o){return new Om(this.manifold.scale(o))}mirror(o){return new Om(this.manifold.mirror(o))}smoothOut(o,f){return new Om(this.manifold.smoothOut(o,f))}refine(o){return new Om(this.manifold.refine(o))}refineToLength(o){return new Om(this.manifold.refineToLength(o))}refineToTolerance(o){return new Om(this.manifold.refineToTolerance(o))}warp(o){return new Om(this.manifold.warp(o))}split(o){const[f,g]=this.manifold.split(Gte(o,"ShapeBackend.split()"));return[new Om(f),new Om(g)]}splitByPlane(o,f){const[g,T]=this.manifold.splitByPlane(o,f);return[new Om(g),new Om(T)]}trimByPlane(o,f){return new Om(this.manifold.trimByPlane(o,f))}hull(){return new Om(this.manifold.hull())}simplify(o){return new Om(this.manifold.simplify(o))}boundingBox(){return this.manifold.boundingBox()}volume(){return this.manifold.volume()}surfaceArea(){return this.manifold.surfaceArea()}minGap(o,f){return this.manifold.minGap(Gte(o,"ShapeBackend.minGap()"),f)}isEmpty(){return this.manifold.isEmpty()}numTri(){return this.manifold.numTri()}getMesh(){return this.manifold.getMesh()}slice(o){return this.manifold.slice(o)}project(){return this.manifold.project()}requireManifold(){return this.manifold}};let Hte=Om;function Wkt(l){return!!(l&&typeof l=="object"&&l[sxe]===!0)}function gqe(l){return new Hte(l)}function Gte(l,o="requireManifoldShapeBackend()"){try{return l.requireManifold(o)}catch(f){const g=f instanceof Error?f.message:String(f);throw new Error(`${o} currently requires a Manifold-backed runtime shape. ${g}`)}}function Abe(l){switch(l.kind){case"through":case"blind":return{kind:l.kind,depth:l.depth};case"upToFace":return{kind:"upToFace",depth:l.depth,face:iu(l.face)}}}function yqe(l){return l.kind==="two-sided"?{kind:"two-sided",forward:Abe(l.forward),reverse:Abe(l.reverse)}:Abe(l)}function fx(l){return Number.isFinite(l)&&l>0}function vqe(l){return Math.max(.01,Math.min(.25,l*.01))}function $J(l,o){return G1(l,{kind:"translate",x:0,y:0,z:o})}function bqe(l,o){const f=G1(l,{kind:"workplanePlacement",matrix:o.matrix,placement:o.placement});return f?{ok:!0,plan:f}:{ok:!1,reason:"Hole/cut features could not apply the selected workplane placement."}}function Vkt(l,o,f,g){const T=Rm(f),P=mq(f);if(!fx(P))return{ok:!1,reason:"Hole/cut features require a positive finite depth."};const O=vqe(P),z=P+O*2,H=(()=>{switch(l.kind){case"cylinder":return{kind:"cylinder",height:z,radius:l.radius,center:!1};case"extrude":if(g&&(!fx(g.scale[0])||!fx(g.scale[1])))return null;const te=Fd(l.profile);if(!te)return null;const W=g?Db(te,{kind:"scale",x:g.scale[0],y:g.scale[1]}):te;return W?{kind:"extrude",profile:W,height:z,center:!1,scaleTop:g?[1/g.scale[0],1/g.scale[1]]:void 0}:null;default:return null}})();if(!H)return{ok:!1,reason:"Hole/cut feature lowerer expected an analytic cylinder or extruded profile cutter."};const re=$J(H,-(T.depth+O+o.placement.protrude));return re?bqe(re,o):{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."}}function Ukt(l,o,f){if(!fx(l.radius))return{ok:!1,reason:"Shape.hole() requires a positive finite diameter."};const g=Rm(f),T=mq(f);if(!fx(T))return{ok:!1,reason:"Hole/cut features require a positive finite depth."};const P=vqe(T),O=[],z=$J({kind:"cylinder",height:T+P*2,radius:l.radius,center:!1},-(g.depth+P+o.placement.protrude));if(!z)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};if(O.push(z),l.counterbore){if(!fx(l.counterbore.radius)||!fx(l.counterbore.depth))return{ok:!1,reason:"Shape.hole() counterbores require positive finite diameter and depth."};const re=$J({kind:"cylinder",height:l.counterbore.depth+P,radius:l.counterbore.radius,center:!1},-(l.counterbore.depth+o.placement.protrude));if(!re)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};O.push(re)}if(l.countersink){if(!fx(l.countersink.radius)||!fx(l.countersink.depth))return{ok:!1,reason:"Shape.hole() countersinks require positive finite diameter and depth."};const re=$J({kind:"cylinder",height:l.countersink.depth,radius:l.radius,radiusTop:l.countersink.radius,center:!1},-(l.countersink.depth+o.placement.protrude));if(!re)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};const te=$J({kind:"cylinder",height:P,radius:l.countersink.radius,center:!1},-o.placement.protrude);if(!te)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};O.push(re,te)}const H=O.length===1?O[0]:Ry("union",O);return H?bqe(H,o):{ok:!1,reason:"Hole/cut features could not combine the selected cutter components."}}function $kt(l,o,f,g){return!l||!o||!f||!fx(f.radius)||!fx(mq(g))?null:{kind:"hole",base:m_(l),placement:rT(o),hole:{radius:f.radius,counterbore:f.counterbore?{radius:f.counterbore.radius,depth:f.counterbore.depth}:void 0,countersink:f.countersink?{radius:f.countersink.radius,angleDeg:f.countersink.angleDeg,depth:f.countersink.depth}:void 0},extent:yqe(g)}}function Hkt(l,o,f,g,T){return!l||!o||!f||!fx(mq(g))?null:{kind:"cut",base:m_(l),placement:rT(o),profile:Fd(f),extent:yqe(g),taper:T?{scale:[T.scale[0],T.scale[1]]}:void 0}}function Gkt(l){const o=Ukt(l.hole,l.placement,l.extent);return o.ok?{ok:!0,plan:Ry("difference",[l.base,o.plan])}:o}function Xkt(l){const o=Vkt({kind:"extrude",profile:l.profile,height:mq(l.extent)},l.placement,l.extent,l.taper);return o.ok?{ok:!0,plan:Ry("difference",[l.base,o.plan])}:o}function xqe(l){const o=[];for(const f of l??[]){if(f!=="top"&&f!=="bottom")throw new Error(`Shape.shell() only supports "top" and "bottom" openings, got "${f}"`);o.includes(f)||o.push(f)}return o}function Ykt(l){return l.kind!=="scale"}function axe(l,o,f,g){const T=g.includes("top"),P=g.includes("bottom"),O=o?-l/2+(P?0:f):P?0:f,z=o?l/2-(T?0:f):l-(T?0:f),H=z-O;return H>0?{height:H,translateZ:o?(O+z)/2:O}:null}function Sqe(l,o){return Math.abs(o)<=1e-12?l:G1(l,{kind:"translate",x:0,y:0,z:o})}function Qkt(l,o,f,g){let T=l;return(Math.abs(o)>1e-12||Math.abs(f)>1e-12||Math.abs(g)>1e-12)&&(T=G1(T,{kind:"translate",x:o,y:f,z:g})),T}function Zkt(l,o,f){const g=l.x-2*o,T=l.y-2*o;if(!(g>0)||!(T>0))return{ok:!1,reason:"Shape.shell() thickness is too large for this box base."};const P=axe(l.z,l.center,o,f);if(!P)return{ok:!1,reason:"Shape.shell() thickness is too large for this box height and opening configuration."};const O=Qkt({kind:"box",x:g,y:T,z:P.height,center:l.center},l.center?0:o,l.center?0:o,P.translateZ);return{ok:!0,plan:Ry("difference",[l,O])}}function Kkt(l,o,f){const g=l.radius-o,T=l.radiusTop==null?void 0:l.radiusTop-o;if(!(g>0)||T!=null&&!(T>0))return{ok:!1,reason:"Shape.shell() thickness is too large for this cylinder or cone base."};const P=axe(l.height,l.center,o,f);if(!P)return{ok:!1,reason:"Shape.shell() thickness is too large for this cylinder height and opening configuration."};const O=Sqe({kind:"cylinder",height:P.height,radius:g,radiusTop:T,center:l.center},P.translateZ);return{ok:!0,plan:Ry("difference",[l,O])}}function eCt(l,o,f){if(l.scaleTop)return{ok:!1,reason:"Shape.shell() v1 does not support tapered extrudes (`scaleTop`) yet."};const g=rqe(l.profile,-o,"Round");if(!g)return{ok:!1,reason:"Shape.shell() could not offset the source profile for this extrude base."};const T=axe(l.height,l.center,o,f);if(!T)return{ok:!1,reason:"Shape.shell() thickness is too large for this extrude height and opening configuration."};const P=Sqe({kind:"extrude",profile:g,height:T.height,center:l.center},T.translateZ);return{ok:!0,plan:Ry("difference",[l,P])}}function p2e(l,o,f){switch(l.kind){case"queryOwner":{const g=p2e(l.base,o,f);return g.ok?{ok:!0,plan:hq(g.plan,l.owner)}:g}case"transform":{if(!l.steps.every(Ykt))return{ok:!1,reason:"Shape.shell() v1 supports only rigid transforms before shelling. Scale transforms are not supported yet."};const g=p2e(l.base,o,f);return g.ok?{ok:!0,plan:m_({kind:"transform",base:g.plan,steps:l.steps.map(T=>({...T}))})}:g}case"box":return Zkt(l,o,f);case"cylinder":return Kkt(l,o,f);case"extrude":return eCt(l,o,f);case"shell":return{ok:!1,reason:"Shape.shell() v1 does not support shelling an already-shelled result yet."};case"fillet":case"chamfer":return{ok:!1,reason:"Shape.shell() v1 does not support edge-finished bodies yet."};case"sphere":case"sheetMetal":case"hole":case"cut":case"revolve":case"loft":case"sweep":case"boolean":case"hull":case"trimByPlane":return{ok:!1,reason:"Shape.shell() v1 currently supports compile-covered box(), cylinder(), and straight extrude() bases with optional top/bottom openings."}}}function tCt(l,o,f=[]){if(!l||!Number.isFinite(o)||!(o>0))return null;const g={kind:"shell",base:m_(l),thickness:o,openFaces:xqe(f)};return Tqe(g).ok?g:null}function Tqe(l){return!Number.isFinite(l.thickness)||!(l.thickness>0)?{ok:!1,reason:"Shape.shell() requires a positive finite wall thickness."}:p2e(l.base,l.thickness,xqe(l.openFaces))}function nCt(l,o,f){return Math.max(o,Math.min(f,l))}function pze(l,o){return[l[0]-o[0],l[1]-o[1],l[2]-o[2]]}function rCt(l,o){return[l[0]*o,l[1]*o,l[2]*o]}function QJ(l,o){return l[0]*o[0]+l[1]*o[1]+l[2]*o[2]}function Nbe(l,o){return[l[1]*o[2]-l[2]*o[1],l[2]*o[0]-l[0]*o[2],l[0]*o[1]-l[1]*o[0]]}function oxe(l){return Math.sqrt(QJ(l,l))}function Gee(l){const o=oxe(l);return o<1e-9?[0,0,1]:[l[0]/o,l[1]/o,l[2]/o]}function iCt(l){let o=0;for(let f=0;f<l.length;f+=1){const[g,T]=l[f],[P,O]=l[(f+1)%l.length];o+=g*O-P*T}return o*.5}function sCt(l,o){let f=!1;const[g,T]=l;for(let P=0,O=o.length-1;P<o.length;O=P,P+=1){const[z,H]=o[P],[re,te]=o[O];H>T!=te>T&&g<(re-z)*(T-H)/(te-H+1e-20)+z&&(f=!f)}return f}function aCt(l,o,f){const g=f[0]-o[0],T=f[1]-o[1],P=l[0]-o[0],O=l[1]-o[1],z=g*g+T*T,H=z<1e-12?0:nCt((P*g+O*T)/z,0,1),re=o[0]+g*H,te=o[1]+T*H,W=l[0]-re,Ee=l[1]-te;return Math.sqrt(W*W+Ee*Ee)}function oCt(l,o){let f=1/0;for(let g=0;g<o.length;g+=1){const T=o[g],P=o[(g+1)%o.length];f=Math.min(f,aCt(l,T,P))}return sCt(l,o)?f:-f}function kqe(l){const o=l.filter(f=>Array.isArray(f)&&f.length>=3).map(f=>({pts:f.map(([g,T])=>[g,T]),area:iCt(f)}));return o.length===0?()=>-1:(f,g)=>{const T=[f,g];let P=-1/0;for(const O of o){const z=oCt(T,O.pts);P=O.area>=0?Math.max(P,z):Math.min(P,-z)}return P}}function cCt(l,o){let f=Gee(o);Math.abs(QJ(f,l))>.95&&(f=Math.abs(l[2])<.95?[0,0,1]:[0,1,0]);let g=Gee(Nbe(f,l));if(oxe(g)<1e-8){const P=Math.abs(l[0])<.9?[1,0,0]:[0,1,0];g=Gee(Nbe(P,l))}const T=Gee(Nbe(l,g));return{x:g,y:T}}function Cqe(l,o,f){if(l.length<2)throw new Error("loft requires at least two compileable profiles");if(l.length!==o.length)throw new Error("loft compile data requires heights.length === profiles.length");const g=l.map(Ee=>kqe(Ee)),T=o.map(Ee=>Ee);let P=1/0,O=1/0,z=-1/0,H=-1/0;for(const Ee of l)for(const se of Ee)for(const[me,Xe]of se)P=Math.min(P,me),O=Math.min(O,Xe),z=Math.max(z,me),H=Math.max(H,Xe);const re=T[0],te=T[T.length-1],W=f.boundsPadding;return{sdf:([Ee,se,me])=>{let Xe;if(me<=re)Xe=g[0](Ee,se);else if(me>=te)Xe=g[g.length-1](Ee,se);else{let at=0;for(;at+1<T.length&&me>T[at+1];)at+=1;const It=T[at],tn=T[at+1],At=(me-It)/(tn-It),mt=g[at](Ee,se),ht=g[at+1](Ee,se);Xe=mt*(1-At)+ht*At}const it=Math.min(me-re,te-me);return Math.min(Xe,it)},bounds:{min:[P-W,O-W,re-W],max:[z+W,H+W,te+W]},edgeLength:f.edgeLength}}function wqe(l,o,f){if(o.length<2)throw new Error("sweep requires a path with at least two points");const g=kqe(l),T=[];for(let se=0;se<o.length-1;se+=1){const me=o[se],Xe=o[se+1],it=pze(Xe,me),at=oxe(it);if(at<1e-6)continue;const It=rCt(it,1/at),tn=cCt(It,f.up);T.push({a:me,t:It,x:tn.x,y:tn.y,len:at})}if(T.length===0)throw new Error("sweep path has no non-zero segments");let P=0;for(const se of l)for(const[me,Xe]of se)P=Math.max(P,Math.abs(me),Math.abs(Xe));let O=1/0,z=1/0,H=1/0,re=-1/0,te=-1/0,W=-1/0;for(const[se,me,Xe]of o)O=Math.min(O,se),z=Math.min(z,me),H=Math.min(H,Xe),re=Math.max(re,se),te=Math.max(te,me),W=Math.max(W,Xe);const Ee=Math.max(f.boundsPadding,P);return{sdf:se=>{let me=-1/0;for(const Xe of T){const it=pze(se,Xe.a),at=QJ(it,Xe.t),It=QJ(it,Xe.x),tn=QJ(it,Xe.y),At=g(It,tn),mt=Math.min(at,Xe.len-at);me=Math.max(me,Math.min(At,mt))}return me},bounds:{min:[O-Ee,z-Ee,H-Ee],max:[re+Ee,te+Ee,W+Ee]},edgeLength:f.edgeLength}}function lCt(l,o){if(l.length<2)return l;if(o<=0)return[];const f=[0];for(let P=0;P<l.length;P++){const O=l[P],z=l[(P+1)%l.length],H=z[0]-O[0],re=z[1]-O[1],te=Math.sqrt(H*H+re*re);f.push(f[f.length-1]+te)}const g=f[f.length-1];if(g<1e-12)return Array.from({length:o},()=>[l[0][0],l[0][1]]);const T=[];for(let P=0;P<o;P++){const O=P/o*g;let z=0,H=f.length-1;for(;z<H;){const se=z+H>>1;f[se]<=O?z=se+1:H=se}const re=z-1,te=(O-f[re])/(f[re+1]-f[re]),W=l[re%l.length],Ee=l[(re+1)%l.length];T.push([W[0]+(Ee[0]-W[0])*te,W[1]+(Ee[1]-W[1])*te])}return T}function uCt(l,o,f){if(l.length<2)return null;const g=l[0].length;if(g===0)return null;for(let O=1;O<l.length;O++)if(l[O].length!==g)return null;const T=[];for(let O=0;O<g;O++){const z=fCt(l.map(H=>H[O]),o,f);if(z)T.push(z);else{for(const H of T)H.delete();return null}}if(T.length===0)return null;if(T.length===1)return T[0];const P=f.Manifold.union(T);for(const O of T)O.delete();return P}function _Ct(l){let o=0;for(let f=0;f<l.length;f++){const g=l[f],T=l[(f+1)%l.length];o+=g[0]*T[1]-T[0]*g[1]}return o*.5}function fCt(l,o,f){const g=l.map(Xe=>_Ct(Xe)<0?[...Xe].reverse():Xe);let T=0;for(const Xe of g)T=Math.max(T,Xe.length);const P=Math.max(T,24),O=g.map((Xe,it)=>{const at=lCt(Xe,P),It=o[it];return at.map(([tn,At])=>[tn,At,It])}),z=[],H=[];for(const Xe of O)for(const[it,at,It]of Xe)z.push(it,at,It);for(let Xe=0;Xe<O.length-1;Xe++){const it=Xe*P,at=(Xe+1)*P;for(let It=0;It<P;It++){const tn=(It+1)%P,At=it+It,mt=at+It,ht=at+tn,xn=it+tn;H.push(At,xn,ht),H.push(At,ht,mt)}}const re=O[0].map(([Xe,it])=>[Xe,it]),te=f.triangulate([re]);for(const Xe of te){const[it,at,It]=Array.isArray(Xe)?Xe:[Xe[0],Xe[1],Xe[2]];H.push(it,It,at)}const W=O[O.length-1].map(([Xe,it])=>[Xe,it]),Ee=f.triangulate([W]),se=(O.length-1)*P;for(const Xe of Ee){const[it,at,It]=Array.isArray(Xe)?Xe:[Xe[0],Xe[1],Xe[2]];H.push(se+it,se+at,se+It)}const me=new f.Mesh({numProp:3,vertProperties:new Float32Array(z),triVerts:new Uint32Array(H)});try{return new f.Manifold(me)}catch{return null}}const d2e=1e-8;function Eqe(l){return Math.hypot(l[0],l[1],l[2])}function Pqe(l){const o=Eqe(l);if(o<d2e)throw new Error("Plane normal must be non-zero");return[l[0]/o,l[1]/o,l[2]/o]}function pCt(l){if("origin"in l)return{origin:[l.origin[0],l.origin[1],l.origin[2]],normal:Pqe(l.normal)};const o=l.offset??0;return l.plane==="XY"?{origin:[0,0,o],normal:[0,0,1]}:l.plane==="XZ"?{origin:[0,o,0],normal:[0,1,0]}:{origin:[o,0,0],normal:[1,0,0]}}function Dqe(l){const o=Pqe(l),f=o[2];if(f>1-d2e)return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];let g,T;if(f<-1+d2e)g=[1,0,0],T=Math.PI;else{g=[o[1],-o[0],0];const At=Eqe(g);g=[g[0]/At,g[1]/At,g[2]/At],T=Math.acos(f)}const[P,O,z]=g,H=Math.cos(T),re=Math.sin(T),te=1-H,W=H+P*P*te,Ee=P*O*te-z*re,se=P*z*te+O*re,me=O*P*te+z*re,Xe=H+O*O*te,it=O*z*te-P*re,at=z*P*te-O*re,It=z*O*te+P*re,tn=H+z*z*te;return[W,me,at,0,Ee,Xe,It,0,se,it,tn,0,0,0,0,1]}function Aqe(l){const{origin:o,normal:f}=pCt(l),g=Ea.from(Dqe(f)).inverse();return{origin:o,u:g.vector([1,0,0]),v:g.vector([0,1,0]),normal:f}}function Nqe(l){const o=Dqe(l.normal);return Ea.translation(-l.origin[0],-l.origin[1],-l.origin[2]).mul(o).toArray()}const cxe=1e-8,Iqe=["vert-bl","vert-br","vert-tr","vert-tl"];function dCt(l,o){return[(l[0]+o[0])*.5,(l[1]+o[1])*.5,(l[2]+o[2])*.5]}function ZJ(l){const o=Math.hypot(l[0],l[1],l[2]);if(o<=cxe)throw new Error("Edge feature selection requires a non-zero direction vector");return[l[0]/o,l[1]/o,l[2]/o]}function mCt(l,o){return[l[0]-o[0],l[1]-o[1],l[2]-o[2]]}function Ap(l,o){return{ok:!1,issue:{code:l,reason:o}}}function gq(l,o){return{ok:!0,selection:l,query:wl(o)}}function hCt(l){return Iqe.includes(l)}function lxe(l){switch(l.kind){case"boolean":return`boolean ${l.op}`;case"trimByPlane":return"trimByPlane";default:return l.kind}}function Xee(l,o){return{base:l.base,steps:[...l.steps,o]}}function gCt(l){switch(l.kind){case"shell":return"Edge finishing does not yet defend durable edge queries through shell rewrites.";case"hole":return"Edge finishing does not yet defend durable edge queries through hole rewrites.";case"cut":return"Edge finishing does not yet defend durable edge queries through cut rewrites.";case"boolean":return`Edge finishing only accepts propagated edge queries that ${lxe(l)} already recorded as supported.`;case"hull":return"Edge finishing does not yet defend durable edge queries through hull rewrites.";case"trimByPlane":return"Edge finishing does not yet defend durable edge queries through trimByPlane rewrites.";case"fillet":case"chamfer":return`Edge finishing only accepts preserved propagated edge queries after earlier ${l.kind} rewrites.`}}function dze(l,o,f){var z;const g=((z=l.queryPropagation)==null?void 0:z.diagnostics.filter(H=>H.queryKind==="edge"))??[],T=g.find(H=>gC(H.source,o)&&(f==null||gC(H.query,f)));if(T!=null&&T.message)return T.message;const P=g.find(H=>gC(H.source,o));if(P!=null&&P.message)return P.message;const O=g.find(H=>H.source==null&&H.query==null);return(O==null?void 0:O.message)??null}function Fqe(l,o){var f;if(o)return(f=l.queryPropagation)==null?void 0:f.descendants.find(g=>g.queryKind==="edge"&&gC(g.query,o))}function yCt(l){switch(l.kind){case"translate":return Ea.translation(l.x,l.y,l.z);case"rotate":return Ea.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg);case"rotateAround":return Ea.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]);case"mirror":{const[o,f,g]=[l.normalX,l.normalY,l.normalZ],T=Math.hypot(o,f,g);if(T<=cxe)return Ea.identity();const P=o/T,O=f/T,z=g/T;return Ea.from([1-2*P*P,-2*O*P,-2*z*P,0,-2*P*O,1-2*O*O,-2*z*O,0,-2*P*z,-2*O*z,1-2*z*z,0,0,0,0,1])}case"workplanePlacement":return Ea.from(l.matrix);case"scale":return null}}function Oqe(l,o){let f=l;for(const g of o){const T=yCt(g);if(!T)return{issue:{code:"unsupported-edge-transform",reason:"Edge finishing currently supports only rigid transforms between the tracked source edge and the target body."}};f=f.mul(T)}return{transform:f}}function zO(l,o){var f,g;if(!l)return{issue:{code:"edge-owner-not-found",reason:"The selected tracked edge is not owned by this target shape or any preserved query ancestor."}};switch(l.kind){case"queryOwner":return Pb(l.owner,o)?{match:{base:l.base,steps:[]}}:zO(l.base,o);case"transform":{const T=zO(l.base,o);return T.match?{match:Xee(T.match,{kind:"transform",steps:l.steps})}:T}case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":{const T=zO(l.base,o);return T.match?{match:Xee(T.match,{kind:"rewrite",plan:l})}:T}case"boolean":{for(const T of l.shapes){const P=zO(T,o);if(P.match)return{match:Xee(P.match,{kind:"rewrite",plan:l})};if(((f=P.issue)==null?void 0:f.code)==="unsupported-edge-transform")return P}return{issue:{code:"edge-owner-not-found",reason:"The selected tracked edge is not owned by this target shape or any preserved query ancestor."}}}case"hull":{for(const T of l.shapes){const P=zO(T,o);if(P.match)return{match:Xee(P.match,{kind:"rewrite",plan:l})};if(((g=P.issue)==null?void 0:g.code)==="unsupported-edge-transform")return P}return{issue:{code:"edge-owner-not-found",reason:"The selected tracked edge is not owned by this target shape or any preserved query ancestor."}}}case"box":case"cylinder":case"sphere":case"extrude":case"sheetMetal":case"revolve":case"loft":case"sweep":return{issue:{code:"edge-owner-not-found",reason:"The selected tracked edge is not owned by this target shape or any preserved query ancestor."}}}}function Mqe(l,o){const f=Oqe(Ea.identity(),o);return f.transform?gq(Bqe(l.selection,f.transform),l.query):Ap(f.issue.code,f.issue.reason)}function vCt(l,o){switch(o.kind){case"tracked-edge":return bCt(l,o);case"propagated-edge":return xCt(l,o);case"created-edge":return Ap("unsupported-edge-query-kind","Edge finishing does not yet support created-edge queries from topology rewrites.");case"edge-ref":return Ap("unsupported-edge-query-kind","Edge finishing v1 supports tracked/propagated compiler-owned edge queries only, not direct edge refs.")}}function bCt(l,o){const f=m2e(l,o.edgeName);return f.ok?gq(f.selection,o):f}function Lqe(l,o){switch(l.kind){case"fillet":case"chamfer":case"shell":case"hole":case"cut":case"trimByPlane":return lI(l.base,o);case"boolean":case"hull":{let f=null;for(const g of l.shapes){const T=lI(g,o);if(T.ok)return T;T.issue.code!=="edge-owner-not-found"&&T.issue.code!=="edge-query-propagation-mismatch"&&(f??(f=T.issue))}return f?Ap(f.code,f.reason):Ap("edge-query-propagation-mismatch","The selected propagated edge query does not match the target shape's recorded rewrite propagation contract.")}}}function Rqe(l,o){var g;const f=(g=l.queryPropagation)==null?void 0:g.preservedEdges.find(T=>gC(T.query.source,o.query));return f?f.status!=="supported"||f.query.outcome!=="preserved"?Ap("edge-query-ambiguous-after-rewrite",dze(l,o.query,f.query)??f.note??`The selected edge query is recorded as ${f.status} after ${lxe(l)} and does not resolve to one defended edge target.`):gq(o.selection,f.query):Ap("edge-query-unsupported-after-rewrite",dze(l,o.query)??gCt(l))}function xCt(l,o){if(l.kind==="box"||l.kind==="cylinder"||l.kind==="sphere"||l.kind==="extrude"||l.kind==="sheetMetal"||l.kind==="revolve"||l.kind==="loft"||l.kind==="sweep"||l.kind==="transform"||l.kind==="queryOwner")return Ap("edge-query-propagation-mismatch","The selected propagated edge query does not point at a topology-rewrite result on this target shape.");const f=l.queryPropagation;if(!f||f.rewriteId!==o.rewriteId)return Ap("edge-query-propagation-mismatch","The selected propagated edge query does not match the target shape's recorded rewrite propagation contract.");if(!f.preservedEdges.find(O=>gC(O.query,o)))return Ap("edge-query-propagation-mismatch",`The selected propagated edge query is not part of the recorded ${lxe(l)} propagation subset for this target shape.`);const T=Lqe(l,o.source);if(!T.ok)return T;const P=Rqe(l,{selection:T.selection,query:T.query});return P.ok?gC(P.query,o)?P:Ap("edge-query-propagation-mismatch","The selected propagated edge query does not match the target shape's recorded rewrite propagation contract."):P}function SCt(l,o){let f=gq(l.selection,l.query);for(const g of o){if(!f.ok)return f;f=g.kind==="transform"?Mqe({selection:f.selection,query:f.query},g.steps):Rqe(g.plan,{selection:f.selection,query:f.query})}return f}function jqe(l){if(!l)return null;switch(l.kind){case"tracked-edge":return l.selector!=="edge"||!l.owner||!hCt(l.edgeName)?null:{owner:Sp(l.owner),edgeName:l.edgeName};case"propagated-edge":return jqe(l.source);case"created-edge":case"edge-ref":return null}}function TCt(l,o){const f=l.center?-l.x/2:0,g=l.center?-l.y/2:0,T=l.center?-l.z/2:0,P=f+l.x,O=g+l.y,z=T+l.z,H=(()=>{switch(o){case"vert-bl":return{point:[f,g,T],quadrant:[1,-1]};case"vert-br":return{point:[P,g,T],quadrant:[-1,-1]};case"vert-tr":return{point:[P,O,T],quadrant:[-1,1]};case"vert-tl":return{point:[f,O,T],quadrant:[1,1]};default:return null}})();return H?{ok:!0,selection:{kind:"line-segment",edgeName:o,start:[H.point[0],H.point[1],T],end:[H.point[0],H.point[1],z],midpoint:[H.point[0],H.point[1],(T+z)*.5],axis:[0,0,1],basisX:[1,0,0],basisY:[0,-1,0],quadrant:H.quadrant}}:Ap("unsupported-edge-name",`Edge finishing v1 currently supports only tracked vertical rectangle/box edges (${["vert-bl","vert-br","vert-tr","vert-tl"].join(", ")}).`)}function kCt(l){if(l.length!==4)return!1;const o=l.map((re,te)=>{const W=l[(te+1)%l.length];return[W[0]-re[0],W[1]-re[1]]}),f=o.map(([re,te])=>Math.hypot(re,te));if(f.some(re=>re<=cxe))return!1;const g=o[0][0]*o[1][0]+o[0][1]*o[1][1],T=o[1][0]*o[2][0]+o[1][1]*o[2][1],P=o[2][0]*o[3][0]+o[2][1]*o[3][1],O=o[3][0]*o[0][0]+o[3][1]*o[0][1],z=o[0][0]*o[2][1]-o[0][1]*o[2][0],H=o[1][0]*o[3][1]-o[1][1]*o[3][0];return Math.abs(g)<=1e-6*Math.max(1,f[0]*f[1])&&Math.abs(T)<=1e-6*Math.max(1,f[1]*f[2])&&Math.abs(P)<=1e-6*Math.max(1,f[2]*f[3])&&Math.abs(O)<=1e-6*Math.max(1,f[3]*f[0])&&Math.abs(z)<=1e-6*Math.max(1,f[0]*f[2])&&Math.abs(H)<=1e-6*Math.max(1,f[1]*f[3])}function CCt(l,o){if(l.scaleTop)return Ap("unsupported-edge-base","Edge finishing v1 does not support tapered extrudes (`scaleTop`) yet.");if(l.center)return Ap("unsupported-edge-base","Edge finishing v1 currently supports tracked rectangle extrusions in their normal upward form; centered sketch extrudes are not tracked in the supported subset.");if(l.profile.kind!=="polygon"||!kCt(l.profile.points))return Ap("unsupported-edge-profile","Edge finishing v1 currently supports tracked rectangle extrusions only; generic sketch extrudes are outside the supported subset.");const f=(()=>{switch(o){case"vert-bl":return 0;case"vert-br":return 1;case"vert-tr":return 2;case"vert-tl":return 3;default:return-1}})();if(f<0)return Ap("unsupported-edge-name",`Edge finishing v1 currently supports only tracked vertical rectangle/box edges (${["vert-bl","vert-br","vert-tr","vert-tl"].join(", ")}).`);const g=l.profile.points,[T,P,O,z]=g,H=ZJ([P[0]-T[0],P[1]-T[1],0]),re=ZJ([z[0]-T[0],z[1]-T[1],0]),te=g[f],W=f===0?[1,-1]:f===1?[-1,-1]:f===2?[-1,1]:[1,1];return{ok:!0,selection:{kind:"line-segment",edgeName:o,start:[te[0],te[1],0],end:[te[0],te[1],l.height],midpoint:[te[0],te[1],l.height*.5],axis:[0,0,1],basisX:[H[0],H[1],H[2]],basisY:[-re[0],-re[1],-re[2]],quadrant:W}}}function Bqe(l,o){const f=o.point(l.start),g=o.point(l.end),T=ZJ(o.vector(l.basisX)),P=ZJ(o.vector(l.basisY)),O=ZJ(mCt(g,f));return{kind:"line-segment",edgeName:l.edgeName,start:f,end:g,midpoint:dCt(f,g),axis:O,basisX:T,basisY:P,quadrant:[l.quadrant[0],l.quadrant[1]]}}function m2e(l,o){switch(l.kind){case"transform":{const f=m2e(l.base,o);if(!f.ok)return f;const g=Oqe(Ea.identity(),l.steps);return g.transform?{ok:!0,selection:Bqe(f.selection,g.transform)}:Ap(g.issue.code,g.issue.reason)}case"box":return TCt(l,o);case"extrude":return CCt(l,o);case"queryOwner":return m2e(l.base,o);case"fillet":case"chamfer":case"shell":case"hole":case"cut":case"boolean":case"cylinder":case"sphere":case"sheetMetal":case"revolve":case"loft":case"sweep":case"hull":case"trimByPlane":return Ap("unsupported-edge-base","Edge finishing v1 currently supports tracked vertical edges from compile-covered box() bodies and rectangle extrusions before topology-changing edits.")}}function lI(l,o){const f=PCt(l,o);return f.kind==="single"?gq(f.selection,f.query):f.kind==="edge-chain"?Ap("edge-query-ambiguous-after-rewrite",f.note??"The selected edge resolves to a defended descendant chain, not one single edge target."):f.query==null&&o==null?Ap("missing-edge-query",f.reason):f.query==null&&(o!=null&&o.selector)&&o.selector!=="edge"||f.reason.includes("selector")?Ap("unsupported-edge-selector",f.reason):f.reason.includes("owner")?Ap("edge-owner-not-found",f.reason):Ap("edge-query-unsupported-after-rewrite",f.reason)}function wCt(l,o){if(l.kind==="box"||l.kind==="cylinder"||l.kind==="sphere"||l.kind==="extrude"||l.kind==="sheetMetal"||l.kind==="revolve"||l.kind==="loft"||l.kind==="sweep"||l.kind==="transform"||l.kind==="queryOwner")return{kind:"unsupported",query:wl(o),reason:"The selected propagated edge query does not point at a topology-rewrite result on this target shape."};const f=Fqe(l,o);if(!f||f.kind!=="edge-chain")return{kind:"unsupported",query:wl(o),reason:"This target shape does not record a defended descendant edge chain for the selected query."};const g=Lqe(l,o.source);return g.ok?{kind:"edge-chain",semantic:"chain",query:wl(o),selection:g.selection,note:f.note}:{kind:"unsupported",query:wl(o),reason:g.issue.reason,note:f.note}}function ECt(l,o){if(l.kind==="box"||l.kind==="cylinder"||l.kind==="sphere"||l.kind==="extrude"||l.kind==="sheetMetal"||l.kind==="revolve"||l.kind==="loft"||l.kind==="sweep"||l.kind==="transform"||l.kind==="queryOwner")return{kind:"unsupported",query:wl(o),reason:"The selected created-edge query does not point at a topology-rewrite result on this target shape."};const f=Fqe(l,o);return!f||f.kind!=="edge-chain"?{kind:"unsupported",query:wl(o),reason:"This target shape does not record a defended descendant edge chain for the selected created-edge query."}:{kind:"edge-chain",semantic:"chain",query:wl(o),note:f.note}}function PCt(l,o){var T;if(!o)return{kind:"unsupported",reason:"Edge finishing currently requires a tracked edge query from a compile-covered target body."};if(o.selector!=="edge")return{kind:"unsupported",query:wl(o),reason:"Edge finishing v1 currently supports whole-edge selections only; use shape.edge(name), not .start/.end/.midpoint selectors."};if(o.kind==="edge-ref")return{kind:"unsupported",query:wl(o),reason:"Edge finishing v1 supports compiler-owned tracked-edge, propagated-edge, and inspectable created-edge queries only, not direct edge refs."};if(!o.owner)return{kind:"unsupported",query:wl(o),reason:"Edge finishing currently requires a tracked edge query with a compiler-owned parent body owner."};const f=zO(l,o.owner);if(!f.match)return{kind:"unsupported",query:wl(o),reason:((T=f.issue)==null?void 0:T.reason)??"The selected tracked edge is not owned by this target shape or any preserved query ancestor."};if(o.kind==="created-edge"){const P=ECt(f.match.base,o);if(P.kind==="unsupported")return P;for(const O of f.match.steps)if(O.kind==="rewrite")return{kind:"unsupported",query:wl(o),reason:"Later topology rewrites do not yet preserve this defended created-edge chain as a new downstream chain contract.",note:P.note};return P}const g=vCt(f.match.base,o);if(g.ok){const P=SCt({selection:g.selection,query:g.query},f.match.steps);return P.ok?{kind:"single",semantic:"edge",query:P.query,selection:P.selection}:{kind:"unsupported",query:wl(o),reason:P.issue.reason}}if(o.kind==="propagated-edge"){const P=wCt(f.match.base,o);if(P.kind!=="unsupported"){let O=P;for(const z of f.match.steps){if(z.kind==="transform"){if(!O.selection)continue;const H=Mqe({selection:O.selection,query:O.query},z.steps);if(!H.ok)return{kind:"unsupported",query:wl(o),reason:H.issue.reason,note:O.note};O={...O,selection:H.selection,query:H.query};continue}return{kind:"unsupported",query:wl(o),reason:"Later topology rewrites do not yet preserve this defended edge chain as a new downstream chain contract.",note:O.note}}return O}}return{kind:"unsupported",query:wl(o),reason:g.issue.reason}}function zqe(l,o){if(!l)return[];const f=jqe(o);if(!f)return[];const g=[];for(const T of Iqe){if(T===f.edgeName)continue;const P={kind:"tracked-edge",edgeName:T,selector:"edge",owner:Sp(f.owner)},O=lI(l,P);O.ok&&g.push(O.query)}return g}const Xte=.01;function Jqe(l,o=0){const f=[l.start[0]+l.axis[0]*o,l.start[1]+l.axis[1]*o,l.start[2]+l.axis[2]*o];return[l.basisX[0],l.basisX[1],l.basisX[2],0,l.basisY[0],l.basisY[1],l.basisY[2],0,l.axis[0],l.axis[1],l.axis[2],0,f[0],f[1],f[2],1]}function qqe(l){const o=l.end[0]-l.start[0],f=l.end[1]-l.start[1],g=l.end[2]-l.start[2];return Math.hypot(o,f,g)}function DCt(l,o,f,g,T){const P=qqe(o);if(!(P>1e-6))return l;const[O,z]=o.quadrant,H=P+Xte*2,re=Jqe(o,-Xte),te=T.CrossSection.square([f,f],!1).translate(O>0?0:-f,z>0?0:-f).extrude(H,0,0,void 0,!1).transform(re),W=T.CrossSection.circle(f,Math.max(3,g)).extrude(H,0,0,void 0,!1).transform(re);return T.Manifold.union([T.Manifold.difference([l,te]),W])}function ACt(l,o,f,g){const T=qqe(o);if(!(T>1e-6))return l;const[P,O]=o.quadrant,z=T+Xte*2,H=Jqe(o,-Xte),te=new g.CrossSection([[[0,0],[P*f,0],[0,O*f]]]).extrude(z,0,0,void 0,!1).transform(H);return g.Manifold.difference([l,te])}function NCt(l,o){switch(o.kind){case"translate":return l.translate(o.x,o.y);case"rotate":return l.rotate(o.degrees);case"scale":return l.scale([o.x,o.y]);case"mirror":return l.mirror([o.normalX,o.normalY])}}function fC(l,o){let f=l;for(const g of o)f=NCt(f,g);return f}function ICt(l,o){const f=l.profiles.map(T=>s4(T,o));if(f.length===0)throw new Error(`Cannot lower empty profile boolean (${l.op})`);if(f.length===1)return fC(f[0],l.transforms);const g=(()=>{switch(l.op){case"union":return o.CrossSection.union(f);case"difference":return o.CrossSection.difference(f);case"intersection":return o.CrossSection.intersection(f)}})();return fC(g,l.transforms)}function FCt(l,o){const f=l.profiles.map(g=>s4(g,o));if(f.length===0)throw new Error("Cannot lower empty profile hull");return f.length===1?fC(f[0],l.transforms):fC(o.CrossSection.hull(f),l.transforms)}function s4(l,o){switch(l.kind){case"rect":return fC(o.CrossSection.square([l.width,l.height],l.center),l.transforms);case"roundedRect":{const f=Math.min(l.radius,l.width/2,l.height/2),g=o.CrossSection.square([l.width-2*f,l.height-2*f],!0).translate(l.center?0:l.width/2,l.center?0:l.height/2).offset(f,"Round");return fC(g,l.transforms)}case"circle":return fC(o.CrossSection.circle(l.radius,l.segments??0),l.transforms);case"polygon":return fC(new o.CrossSection([l.points]),l.transforms);case"boolean":return ICt(l,o);case"offset":return fC(s4(l.base,o).offset(l.delta,l.join),l.transforms);case"hull":return FCt(l,o);case"project":{const f=wb(l.sourceShape,o).transform(Nqe(l.plane)).project();return fC(f,l.transforms)}}}function OCt(l,o){switch(o.kind){case"translate":return l.translate(o.x,o.y,o.z);case"rotate":return l.rotate(o.xDeg,o.yDeg,o.zDeg);case"scale":return l.scale([o.x,o.y,o.z]);case"rotateAround":return l.transform(Ea.rotationAxis([o.axisX,o.axisY,o.axisZ],o.degrees,[o.pivotX,o.pivotY,o.pivotZ]).toArray());case"mirror":return l.mirror([o.normalX,o.normalY,o.normalZ]);case"workplanePlacement":return l.transform(o.matrix)}}function MCt(l,o){let f=l;for(const g of o)f=OCt(f,g);return f}function LCt(l,o){const f=l.shapes.map(g=>wb(g,o));if(f.length===0)throw new Error(`Cannot lower empty shape boolean (${l.op})`);if(f.length===1)return f[0];switch(l.op){case"union":return o.Manifold.union(f);case"difference":return o.Manifold.difference(f);case"intersection":return o.Manifold.intersection(f)}}function RCt(l,o){const g=[...l.shapes.map(T=>wb(T,o)),...l.points.map(([T,P,O])=>[T,P,O])];if(g.length===0)throw new Error("Cannot lower empty shape hull");return o.Manifold.hull(g)}function jCt(l,o){return wb(l.base,o).trimByPlane([l.normalX,l.normalY,l.normalZ],l.originOffset)}function BCt(l,o){const f=l.profiles.map(P=>s4(P,o).toPolygons());if(f.length>=2&&f.every(P=>P.length===1)){const P=uCt(f,l.heights,o);if(P)return P}const T=Cqe(f,l.heights,{edgeLength:l.edgeLength,boundsPadding:l.boundsPadding});return o.Manifold.levelSet(T.sdf,T.bounds,T.edgeLength,0)}function zCt(l,o){const f=wqe(s4(l.profile,o).toPolygons(),l.path.points.map(([g,T,P])=>[g,T,P]),{edgeLength:l.edgeLength,boundsPadding:l.boundsPadding,up:[l.up[0],l.up[1],l.up[2]]});return o.Manifold.levelSet(f.sdf,f.bounds,f.edgeLength,0)}function JCt(l,o){const f=lI(l.base,l.edge);if(!f.ok)throw new Error(f.issue.reason);if(f.selection.quadrant[0]!==l.quadrant[0]||f.selection.quadrant[1]!==l.quadrant[1])throw new Error(`filletEdge() currently supports ${f.selection.edgeName} only with quadrant [${f.selection.quadrant[0]}, ${f.selection.quadrant[1]}].`);return DCt(wb(l.base,o),f.selection,l.radius,l.segments,o)}function qCt(l,o){const f=lI(l.base,l.edge);if(!f.ok)throw new Error(f.issue.reason);if(f.selection.quadrant[0]!==l.quadrant[0]||f.selection.quadrant[1]!==l.quadrant[1])throw new Error(`chamferEdge() currently supports ${f.selection.edgeName} only with quadrant [${f.selection.quadrant[0]}, ${f.selection.quadrant[1]}].`);return ACt(wb(l.base,o),f.selection,l.size,o)}function wb(l,o){switch(l.kind){case"box":return o.Manifold.cube([l.x,l.y,l.z],l.center);case"cylinder":return o.Manifold.cylinder(l.height,l.radius,l.radiusTop??-1,l.segments??0,l.center);case"sphere":return o.Manifold.sphere(l.radius,l.segments??0);case"extrude":return s4(l.profile,o).extrude(l.height,0,0,l.scaleTop,l.center);case"sheetMetal":return wb(gTt(l.model,l.output),o);case"shell":{const f=Tqe(l);if(!f.ok)throw new Error(f.reason);return wb(f.plan,o)}case"hole":{const f=Gkt(l);if(!f.ok)throw new Error(f.reason);return wb(f.plan,o)}case"cut":{const f=Xkt(l);if(!f.ok)throw new Error(f.reason);return wb(f.plan,o)}case"revolve":return s4(l.profile,o).revolve(l.segments??0,l.degrees);case"loft":return BCt(l,o);case"sweep":return zCt(l,o);case"boolean":return LCt(l,o);case"transform":return MCt(wb(l.base,o),l.steps);case"queryOwner":return wb(l.base,o);case"fillet":return JCt(l,o);case"chamfer":return qCt(l,o);case"hull":return RCt(l,o);case"trimByPlane":return jCt(l,o)}}function WCt(l,o){return gqe(wb(l,o))}function Wqe(l){switch(l.kind){case"translate":return{kind:"translate",description:`Translate by [${l.x}, ${l.y}, ${l.z}]`,details:{x:l.x,y:l.y,z:l.z}};case"rotate":return{kind:"rotate",description:`Rotate by [${l.xDeg}°, ${l.yDeg}°, ${l.zDeg}°]`,details:{xDeg:l.xDeg,yDeg:l.yDeg,zDeg:l.zDeg}};case"scale":return{kind:"scale",description:`Scale by [${l.x}, ${l.y}, ${l.z}]`,details:{x:l.x,y:l.y,z:l.z}};case"mirror":return{kind:"mirror",description:`Mirror across plane with normal [${l.normalX}, ${l.normalY}, ${l.normalZ}]`,details:{normalX:l.normalX,normalY:l.normalY,normalZ:l.normalZ}};case"rotateAround":return{kind:"rotateAround",description:`Rotate ${l.degrees}° around axis [${l.axisX}, ${l.axisY}, ${l.axisZ}] at pivot [${l.pivotX}, ${l.pivotY}, ${l.pivotZ}]`,details:{axisX:l.axisX,axisY:l.axisY,axisZ:l.axisZ,degrees:l.degrees,pivotX:l.pivotX,pivotY:l.pivotY,pivotZ:l.pivotZ}};case"workplanePlacement":return{kind:"workplanePlacement",description:"Place on workplane",details:{matrix:l.matrix,placement:l.placement}}}}function HJ(l){if(!l)return[];const o=[];switch(l.kind){case"transform":o.push(...HJ(l.base)),o.push(...l.steps.map(Wqe));break;case"queryOwner":o.push(...HJ(l.base));break;case"boolean":l.shapes.length>0&&o.push(...HJ(l.shapes[0]));break;case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":o.push(...HJ(l.base));break}return o}function h2e(l){if(!l)return{operation:"unknown"};switch(l.kind){case"queryOwner":return{operation:l.owner.operation,owner:l.owner};case"transform":return h2e(l.base);case"boolean":return{operation:`${l.op} (${l.shapes.length} operands)`};case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":return h2e(l.base);default:return{operation:l.kind}}}function Ibe(l){switch(l.kind){case"rect":return`${l.width}×${l.height} rect`;case"roundedRect":return`${l.width}×${l.height} rounded rect`;case"circle":return`r=${l.radius} circle`;case"polygon":return`polygon (${l.points.length} pts)`;case"boolean":return`${l.op} profile`;case"offset":return"offset profile";case"hull":return"hull profile";case"project":return"projected profile"}}function cC(l,o){switch(l.kind){case"queryOwner":cC(l.base,o);return;case"transform":cC(l.base,o);for(const f of l.steps){const g=Wqe(f),T=f.kind==="translate"?"Move":f.kind==="rotate"?"Rotate":f.kind==="rotateAround"?"Rotate Around":f.kind==="scale"?"Scale":f.kind==="mirror"?"Mirror":"Place on Workplane";o.push({kind:f.kind,label:T,summary:g.description,category:"transform"})}return;case"shell":cC(l.base,o),o.push({kind:"shell",label:"Shell",summary:`t = ${l.thickness}`,category:"modifier"});return;case"hole":cC(l.base,o),o.push({kind:"hole",label:"Hole",summary:`r = ${l.hole.radius}`,category:"modifier"});return;case"cut":cC(l.base,o),o.push({kind:"cut",label:"Cut",summary:Ibe(l.profile),category:"modifier"});return;case"fillet":cC(l.base,o),o.push({kind:"fillet",label:"Fillet",summary:`r = ${l.radius}`,category:"modifier"});return;case"chamfer":cC(l.base,o),o.push({kind:"chamfer",label:"Chamfer",summary:`size = ${l.size}`,category:"modifier"});return;case"trimByPlane":cC(l.base,o),o.push({kind:"trimByPlane",label:"Trim by Plane",summary:`normal [${l.normalX}, ${l.normalY}, ${l.normalZ}]`,category:"modifier"});return;case"boolean":l.shapes.length>0&&cC(l.shapes[0],o),o.push({kind:"boolean",label:l.op==="union"?"Union":l.op==="difference"?"Difference":"Intersection",summary:`${l.shapes.length} operand${l.shapes.length!==1?"s":""}`,category:"boolean"});return;case"hull":o.push({kind:"hull",label:"Hull",summary:`${l.shapes.length} shapes`,category:"boolean"});return;case"extrude":o.push({kind:"extrude",label:"Extrude",summary:`${Ibe(l.profile)}, h = ${l.height}`,category:"sketch"});return;case"revolve":o.push({kind:"revolve",label:"Revolve",summary:`${l.degrees}°`,category:"sketch"});return;case"loft":o.push({kind:"loft",label:"Loft",summary:`${l.profiles.length} sections`,category:"sketch"});return;case"sweep":o.push({kind:"sweep",label:"Sweep",summary:Ibe(l.profile),category:"sketch"});return;case"box":o.push({kind:"box",label:"Box",summary:`${l.x} × ${l.y} × ${l.z}`,category:"primitive"});return;case"cylinder":o.push({kind:"cylinder",label:"Cylinder",summary:l.radiusTop!==void 0&&l.radiusTop!==l.radius?`r = ${l.radius}→${l.radiusTop}, h = ${l.height}`:`r = ${l.radius}, h = ${l.height}`,category:"primitive"});return;case"sphere":o.push({kind:"sphere",label:"Sphere",summary:`r = ${l.radius}`,category:"primitive"});return;case"sheetMetal":o.push({kind:"sheetMetal",label:"Sheet Metal",summary:"",category:"primitive"});return;default:{const f=l.kind;o.push({kind:f,label:f,summary:"",category:"primitive"});return}}}function VCt(l){if(!l)return[];const o=[];return cC(l,o),o}function UCt(l,o){const f=HJ(l),g=h2e(l),T=VCt(l);return{faceName:o.name,origin:g,transformations:f,query:o.query,timeline:T}}let YE=null;async function $Ct(){if(YE)return YE;const l=(await import("./manifold-cL7A7HeM.js")).default;return YE=await l(),YE.setup(),YE.setMinCircularAngle(2),YE.setMinCircularEdgeLength(.5),YE}function nd(){if(!YE)throw new Error("Kernel not initialized — call initKernel() first");return YE}function uxe(l){if(l instanceof na)return l;if(l&&typeof l=="object"&&typeof l.toShape=="function"){const o=l.toShape();if(o instanceof na)return o;throw new Error(`expected toShape() to return a Shape, got ${Vte(o)}`)}throw new Error(`expected a Shape or TrackedShape-compatible value, got ${Vte(l)}`)}const g2e=new WeakMap,Vqe=new WeakMap,Uqe=new WeakMap,y2e=new WeakMap,$qe=new WeakMap;let mze=0;const ZN={backend:"manifold",representation:"mesh-solid",fidelity:"unknown",topology:"none",sources:["unknown"]};function _xe(l){const o=[],f=new Set;for(const g of l)f.has(g)||(f.add(g),o.push(g));return o}function Hqe(l){return{backend:l.backend,representation:l.representation,fidelity:l.fidelity,topology:l.topology,sources:[...l.sources]}}function yq(l={}){return{backend:l.backend??ZN.backend,representation:l.representation??ZN.representation,fidelity:l.fidelity??ZN.fidelity,topology:l.topology??ZN.topology,sources:_xe(l.sources?[...l.sources]:[...ZN.sources])}}function O_(l,o){return Vqe.set(l,Hqe(o)),l}function HCt(l,o){const f=Wkt(o)?o:gqe(o);return $qe.set(l,f),l}function nu(l,o){return Uqe.set(l,m_(o)),l}function vq(l,o){return ZSt(o)?y2e.set(l,KJe(o)):y2e.delete(l),l}function Xf(l){return Hqe(Vqe.get(l)??ZN)}function d_(l){const o=$qe.get(l);if(!o)throw new Error("Runtime backend missing on Shape");return o}function ju(l){return m_(Uqe.get(l)??null)}function n6(l){return KJe(y2e.get(l)??sM())}function Yee(l,o){const f=[...new Set(l)];return f.length===1?f[0]:o}function oC(l,o,f={}){return yq({backend:f.backend??l.backend,representation:f.representation??l.representation,fidelity:f.fidelity??l.fidelity,topology:f.topology??l.topology,sources:_xe([o,...l.sources,...f.sources??[]])})}function KD(l,o,f={}){return yq({backend:f.backend??Yee(l.map(g=>g.backend),"hybrid"),representation:f.representation??Yee(l.map(g=>g.representation),"mixed"),fidelity:f.fidelity??Yee(l.map(g=>g.fidelity),"mixed"),topology:f.topology??Yee(l.map(g=>g.topology),"none"),sources:_xe([o,...l.flatMap(g=>g.sources),...f.sources??[]])})}function Gqe(){return mze+=1,`shape-dim-${mze}`}function GCt(l,o=!1){return{id:o?Gqe():l.id,from:[l.from[0],l.from[1],l.from[2]],to:[l.to[0],l.to[1],l.to[2]],offset:l.offset,autoOffset:l.autoOffset,label:l.label,color:l.color,components:l.components?[...l.components]:void 0,currentComponent:l.currentComponent}}function bq(l,o=!1){return l.map(f=>GCt(f,o))}function nM(l,o){return o.length===0?g2e.delete(l):g2e.set(l,o),l}function xq(l){return g2e.get(l)??[]}function hze(l,o){const f=o[0],g=o[1],T=o[2];return[l[0]*f+l[4]*g+l[8]*T+l[12],l[1]*f+l[5]*g+l[9]*T+l[13],l[2]*f+l[6]*g+l[10]*T+l[14]]}function XCt(l,o){return l.map(f=>({id:Gqe(),from:hze(o,f.from),to:hze(o,f.to),offset:f.offset,autoOffset:f.autoOffset,label:f.label,color:f.color,components:f.components?[...f.components]:void 0,currentComponent:f.currentComponent}))}function YCt(l,o,f){return Ea.identity().rotateAxis([1,0,0],l).rotateAxis([0,1,0],o).rotateAxis([0,0,1],f).toArray()}function QCt(l,o,f){const[g,T,P]=f,O=o*Math.PI/180,z=Math.cos(O),H=Math.sin(O),re=Math.sqrt(l[0]**2+l[1]**2+l[2]**2)||1,te=l[0]/re,W=l[1]/re,Ee=l[2]/re,se=z+te*te*(1-z),me=te*W*(1-z)-Ee*H,Xe=te*Ee*(1-z)+W*H,it=W*te*(1-z)+Ee*H,at=z+W*W*(1-z),It=W*Ee*(1-z)-te*H,tn=Ee*te*(1-z)-W*H,At=Ee*W*(1-z)+te*H,mt=z+Ee*Ee*(1-z),ht=g-(se*g+me*T+Xe*P),xn=T-(it*g+at*T+It*P),Pn=P-(tn*g+At*T+mt*P);return[se,it,tn,0,me,at,At,0,Xe,It,mt,0,ht,xn,Pn,1]}function ZCt(l){const[o,f,g]=l,T=Math.hypot(o,f,g);if(T<1e-12)return Ea.identity().toArray();const P=o/T,O=f/T,z=g/T,H=1-2*P*P,re=-2*P*O,te=-2*P*z,W=-2*O*P,Ee=1-2*O*O,se=-2*O*z,me=-2*z*P,Xe=-2*z*O,it=1-2*z*z;return[H,W,me,0,re,Ee,Xe,0,te,se,it,0,0,0,0,1]}function KCt(l){const o=typeof l=="number"?[l,l,l]:l;return!Number.isFinite(o[0])||!Number.isFinite(o[1])||!Number.isFinite(o[2])||Math.abs(o[0])<1e-12||Math.abs(o[1])<1e-12||Math.abs(o[2])<1e-12?null:[o[0],o[1],o[2]]}function Qee(l,o){return l[0]*o[0]+l[1]*o[1]+l[2]*o[2]}function ewt(l,o){return[l[1]*o[2]-l[2]*o[1],l[2]*o[0]-l[0]*o[2],l[0]*o[1]-l[1]*o[0]]}function Ete(l){return Math.hypot(l[0],l[1],l[2])}function gze(l){const o=Ete(l);return o<1e-12?[1,0,0]:[l[0]/o,l[1]/o,l[2]/o]}function twt(l){if(Math.abs(l[3])>1e-6||Math.abs(l[7])>1e-6||Math.abs(l[11])>1e-6||Math.abs(l[15]-1)>1e-6)return null;const f=[l[0],l[1],l[2]],g=[l[4],l[5],l[6]],T=[l[8],l[9],l[10]],P=Ete(f),O=Ete(g),z=Ete(T);if(Math.abs(P-1)>1e-6||Math.abs(O-1)>1e-6||Math.abs(z-1)>1e-6||Math.abs(Qee(f,g))>1e-6||Math.abs(Qee(f,T))>1e-6||Math.abs(Qee(g,T))>1e-6)return null;const H=Qee(f,ewt(g,T));if(Math.abs(H-1)>1e-6)return null;const re=l[0],te=l[4],W=l[8],Ee=l[1],se=l[5],me=l[9],Xe=l[2],it=l[6],at=l[10],It=l[12],tn=l[13],At=l[14],mt=[],ht=re+se+at,xn=Math.max(-1,Math.min(1,(ht-1)/2)),Pn=Math.acos(xn),$r=Pn*180/Math.PI;if($r>1e-6){let zn;if(Math.PI-Pn<1e-5){const ii=Math.max(0,(re+1)/2),Gr=Math.max(0,(se+1)/2),mn=Math.max(0,(at+1)/2),$s=(te+Ee)/4,is=(W+Xe)/4,Wt=(me+it)/4;if(ii>=Gr&&ii>=mn){const Es=Math.sqrt(ii);zn=[Es,Es>1e-6?$s/Es:0,Es>1e-6?is/Es:0]}else if(Gr>=mn){const Es=Math.sqrt(Gr);zn=[Es>1e-6?$s/Es:0,Es,Es>1e-6?Wt/Es:0]}else{const Es=Math.sqrt(mn);zn=[Es>1e-6?is/Es:0,Es>1e-6?Wt/Es:0,Es]}}else zn=gze([it-me,W-Xe,Ee-te]);zn=gze(zn),mt.push({kind:"rotateAround",axisX:zn[0],axisY:zn[1],axisZ:zn[2],degrees:$r,pivotX:0,pivotY:0,pivotZ:0})}return(Math.abs(It)>1e-6||Math.abs(tn)>1e-6||Math.abs(At)>1e-6)&&mt.push({kind:"translate",x:It,y:tn,z:At}),mt}function $N(l,o){return nM(o,bq(xq(l),!0)),O_(o,Xf(l)),vq(o,n6(l)),nu(o,ju(l))}function DO(l,o,f){const g=xq(l);return g.length===0?nM(o,[]):nM(o,XCt(g,f)),O_(o,Xf(l)),vq(o,KSt(n6(l),f)),nu(o,ju(l))}function oq(l,o){const f=l.flatMap(P=>xq(P));nM(o,bq(f,!0));const g=l.length>0?Xf(l[0]):ZN;O_(o,g),vq(o,eqe(...l.map(P=>n6(P))));const T=l.length>0?ju(l[0]):null;return nu(o,T)}function W1(l,o){return nM(o,bq(xq(l),!0)),O_(o,Xf(l)),vq(o,n6(l)),nu(o,ju(l))}function yze(l,o){return Array.isArray(o)?[o[0],o[1],o[2]]:l.referencePoint(o)}function Yte(l,o,f={}){const g=f.regenerateIds??!0;return nM(l,bq(o,g))}function fxe(l){return bq(xq(l),!1)}function mne(l,o,f={}){const g=f.merge??!0?eze(n6(l),o):eze(sM(),o);return vq(l,g)}function Xqe(l){return n6(l)}function Yqe(l){return Xf(l)}function hne(l,o){const f=Xf(l);return O_(l,yq({backend:o.backend??f.backend,representation:o.representation??f.representation,fidelity:o.fidelity??f.fidelity,topology:o.topology??f.topology,sources:o.sources??f.sources}))}function c4(l){return ju(l)}function gne(l,o){return nu(l,o)}function Qte(l){return _ne(ju(l))}function Qqe(l){return NTt(ju(l))}function nwt(l){return UJ(ju(l))}function M_(l,o,f){return gne(new na(WCt(l,nd()),o,f),l)}function U1(l,o,f){if(!l)return null;const g=une(o);return hq(ixe(l,f(g)),g)}class na{constructor(o,f,g){tu(this,"colorHex");this.colorHex=f,HCt(this,o),O_(this,yq(g)),nu(this,null)}setColor(o){return $N(this,new na(d_(this).clone(),o))}color(o){return this.setColor(o)}clone(){return $N(this,new na(d_(this).clone(),this.colorHex))}duplicate(){return this.clone()}geometryInfo(){return Xf(this)}withReferences(o){return mne(this.clone(),o,{merge:!0})}referenceNames(o){return tqe(n6(this),o)}referencePoint(o){return Zqe(this,o)}face(o){const f=ju(this),g=lze(f,o);if(g)return g;throw new Error(uze(f,o))}faceNames(){return dkt(ju(this))}faceHistory(o){const f=ju(this),g=lze(f,o);if(!g)throw new Error(uze(f,o));return UCt(f,g)}placeReference(o,f,g){const T=this.referencePoint(o);let P=f[0]-T[0],O=f[1]-T[1],z=f[2]-T[2];return g&&(P+=g[0],O+=g[1],z+=g[2]),this.translate(P,O,z)}translate(o,f,g){const T=G1(ju(this),{kind:"translate",x:o,y:f,z:g});return nu(DO(this,T?M_(T,this.colorHex):new na(d_(this).translate(o,f,g),this.colorHex),Ea.translation(o,f,g).toArray()),T)}moveTo(o,f,g){const T=this.boundingBox();return this.translate(o-T.min[0],f-T.min[1],g-T.min[2])}moveToLocal(o,f,g,T){const O=("toShape"in o?o.toShape():o).boundingBox();return this.moveTo(O.min[0]+f,O.min[1]+g,O.min[2]+T)}rotate(o,f,g){const T=G1(ju(this),{kind:"rotate",xDeg:o,yDeg:f,zDeg:g});return nu(DO(this,T?M_(T,this.colorHex):new na(d_(this).rotate(o,f,g),this.colorHex),YCt(o,f,g)),T)}transform(o){const f=o instanceof Ea?o.toArray():o,g=(()=>{const T=twt(f);return T==null?null:T.length===0?ju(this):ATt(ju(this),T)})();return nu(DO(this,g?M_(g,this.colorHex):new na(d_(this).transform(f),this.colorHex),f),g)}scale(o){const f=KCt(o),g=f?G1(ju(this),{kind:"scale",x:f[0],y:f[1],z:f[2]}):null;return nu(DO(this,g?M_(g,this.colorHex):new na(d_(this).scale(o),this.colorHex),Ea.scale(o).toArray()),g)}mirror(o){const f=G1(ju(this),{kind:"mirror",normalX:o[0],normalY:o[1],normalZ:o[2]}),g=hqe(f,"mirror");return nu(DO(this,g?M_(g,this.colorHex):new na(d_(this).mirror(o),this.colorHex),ZCt(o)),g)}pointAlong(o){const[f,g,T]=o,P=Math.sqrt(f*f+g*g+T*T)||1,O=f/P,z=g/P,H=T/P,re=-z,te=O,W=0,Ee=Math.sqrt(re*re+te*te+W*W),se=H;if(Ee<1e-10)return se>0?this:this.rotate(180,0,0);const me=Math.atan2(Ee,se)*180/Math.PI,Xe=re/Ee,it=te/Ee,at=W/Ee;return this.rotateAround([Xe,it,at],me)}rotateAround(o,f,g=[0,0,0]){const T=Math.sqrt(o[0]**2+o[1]**2+o[2]**2)||1,P=[o[0]/T,o[1]/T,o[2]/T],O=QCt(P,f,g),z=G1(ju(this),{kind:"rotateAround",axisX:P[0],axisY:P[1],axisZ:P[2],degrees:f,pivotX:g[0],pivotY:g[1],pivotZ:g[2]});return nu(DO(this,z?M_(z,this.colorHex):new na(d_(this).transform(O),this.colorHex),O),z)}rotateAroundTo(o,f,g,T,P={}){const O=yze(this,g),z=yze(this,T),H=VJe(o,f,O,z,P);return this.rotateAround(o,H,f)}smoothOut(o=60,f=0){return nu(O_($N(this,new na(d_(this).smoothOut(o,f),this.colorHex)),oC(Xf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}refine(o){const f=WSt(o);return f<=0?this.clone():nu(O_($N(this,new na(d_(this).refine(f),this.colorHex)),oC(Xf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}refineToLength(o){const f=VSt(o);return nu(O_($N(this,new na(d_(this).refineToLength(f),this.colorHex)),oC(Xf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}refineToTolerance(o){const f=USt(o);return nu(O_($N(this,new na(d_(this).refineToTolerance(f),this.colorHex)),oC(Xf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}warp(o){return nu(O_($N(this,new na(d_(this).warp(o),this.colorHex)),oC(Xf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}static _unwrap(o){return uxe(o)}add(...o){const f=[this,...$O("Shape.add()",o,1,"Use shape.add(other1, other2) or shape.add([other1, other2]).")],g=f.map(P=>ju(P)),T=U1(Ry("union",g),"boolean:union",P=>YD("union",P,g));return nu(O_(oq(f,T?M_(T,this.colorHex):new na(nd().Manifold.union(HO("Shape.add()",f)),this.colorHex)),KD(f.map(P=>Xf(P)),"boolean",{topology:"none"})),T)}subtract(...o){const f=[this,...$O("Shape.subtract()",o,1,"Use shape.subtract(other1, other2) or shape.subtract([other1, other2]).")],g=f.map(P=>ju(P)),T=U1(Ry("difference",g),"boolean:difference",P=>YD("difference",P,g));return nu(O_(W1(this,T?M_(T,this.colorHex):new na(nd().Manifold.difference(HO("Shape.subtract()",f)),this.colorHex)),KD(f.map(P=>Xf(P)),"boolean",{topology:"none"})),T)}intersect(...o){const f=[this,...$O("Shape.intersect()",o,1,"Use shape.intersect(other1, other2) or shape.intersect([other1, other2]).")],g=f.map(P=>ju(P)),T=U1(Ry("intersection",g),"boolean:intersection",P=>YD("intersection",P,g));return nu(O_(oq(f,T?M_(T,this.colorHex):new na(nd().Manifold.intersection(HO("Shape.intersect()",f)),this.colorHex)),KD(f.map(P=>Xf(P)),"boolean",{topology:"none"})),T)}split(o){const f=na._unwrap(o),g=[ju(this),ju(f)],T=U1(Ry("intersection",g),"split:inside",te=>YD("intersection",te,g)),P=[ju(this),ju(f)],O=U1(Ry("difference",P),"split:outside",te=>YD("difference",te,P)),z=KD([Xf(this),Xf(f)],"boolean",{topology:"none"});if(T&&O)return[nu(O_(W1(this,M_(T,this.colorHex)),z),T),nu(O_(W1(this,M_(O,this.colorHex)),z),O)];const[H,re]=d_(this).split(d_(f));return[nu(O_(W1(this,new na(H,this.colorHex)),z),null),nu(O_(W1(this,new na(re,this.colorHex)),z),null)]}splitByPlane(o,f=0){const g=oC(Xf(this),"boolean",{topology:"none"}),T=ju(this),P=U1(wbe(T,o,f),"splitByPlane:positive",re=>Dbe(re,T)),O=U1(wbe(T,[-o[0],-o[1],-o[2]],-f),"splitByPlane:opposite",re=>Dbe(re,T));if(P&&O)return[nu(O_(W1(this,M_(P,this.colorHex)),g),P),nu(O_(W1(this,M_(O,this.colorHex)),g),O)];const[z,H]=d_(this).splitByPlane(o,f);return[nu(O_(W1(this,new na(z,this.colorHex)),g),null),nu(O_(W1(this,new na(H,this.colorHex)),g),null)]}trimByPlane(o,f=0){const g=ju(this),T=U1(wbe(g,o,f),"trimByPlane",P=>Dbe(P,g));return nu(O_(W1(this,T?M_(T,this.colorHex):new na(d_(this).trimByPlane(o,f),this.colorHex)),oC(Xf(this),"boolean",{topology:"none"})),T)}shell(o,f={}){const g=ju(this),T=U1(tCt(g,o,f.openFaces),"shell",P=>Lkt(P,g,f.openFaces??[]));if(!T)throw new Error("Shape.shell() currently supports compile-covered box(), cylinder(), and straight extrude() solids with optional top/bottom openings and rigid transforms.");return nu(O_(W1(this,M_(T,this.colorHex)),oC(Xf(this),"shell",{topology:"none"})),T)}hull(){const o=U1(sqe([ju(this)]),"hull",f=>mqe(f));return nu(O_(W1(this,o?M_(o,this.colorHex):new na(d_(this).hull(),this.colorHex)),oC(Xf(this),"hull",{topology:"none"})),o)}simplify(o){return nu(O_(W1(this,new na(d_(this).simplify(o),this.colorHex)),oC(Xf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}boundingBox(){return d_(this).boundingBox()}volume(){return d_(this).volume()}surfaceArea(){return d_(this).surfaceArea()}minGap(o,f){const g="toShape"in o?o.toShape():o;return d_(this).minGap(d_(g),f)}isEmpty(){return d_(this).isEmpty()}numTri(){return d_(this).numTri()}getMesh(){return d_(this).getMesh()}slice(o=0){return d_(this).slice(o)}project(){return d_(this).project()}attachTo(o,f,g="center",T){const P=rwt(o,f),O=this.referencePoint(g);let z=P[0]-O[0],H=P[1]-O[1],re=P[2]-O[2];return T&&(z+=T[0],H+=T[1],re+=T[2]),this.translate(z,H,re)}onFace(o,f,g={}){const T=g.u??0,P=g.v??0,O=g.protrude??0,z={front:"back",back:"front",left:"right",right:"left",top:"bottom",bottom:"top"},H={front:(W,Ee,se)=>[W,-se,Ee],back:(W,Ee,se)=>[W,se,Ee],left:(W,Ee,se)=>[-se,W,Ee],right:(W,Ee,se)=>[se,W,Ee],top:(W,Ee,se)=>[W,Ee,se],bottom:(W,Ee,se)=>[W,Ee,-se]},re=z[f],te=H[f](T,P,O);return this.attachTo(o,f,re,te)}}function vze(l,o){const g=(typeof l.toShape=="function"?l.toShape():l).boundingBox();return t4(g.min,g.max,o)}function Zqe(l,o){if(QJe(o))return vze(l,o);const f=eTt(n6(l),o);if(f)return f;const g=cne(o);if(g)return vze(l,g);throw new Error(`Unknown placement reference "${o}". Available: ${tqe(n6(l)).join(", ")||"none"}`)}function rwt(l,o){if(l instanceof na)return Zqe(l,o);if("referencePoint"in l&&typeof l.referencePoint=="function")return l.referencePoint(o);const f=cne(o);if(!f)throw new Error(`ShapeGroup targets only support built-in anchors, got "${o}"`);if(!("_bbox"in l)||typeof l._bbox!="function")throw new Error("ShapeGroup anchor target is missing _bbox()");const g=l._bbox();return t4(g.min,g.max,f)}function eT(l,o,f,g=!1){return M_(s6({kind:"box",x:l,y:o,z:f,center:g},"primitive:box"),void 0,{fidelity:"kernel-native",sources:["primitive"]})}function Th(l,o,f,g,T=!1){return M_(s6({kind:"cylinder",height:l,radius:o,radiusTop:f!=null&&f>=0?f:void 0,segments:g!=null&&g>0?g:void 0,center:T},"primitive:cylinder"),void 0,{fidelity:"kernel-native",sources:["primitive"]})}function iwt(l,o){return M_(s6({kind:"sphere",radius:l,segments:o!=null&&o>0?o:void 0},"primitive:sphere"),void 0,{fidelity:"kernel-native",sources:["primitive"]})}function $O(l,o,f,g){return aqe({apiName:l,inputs:o,minCount:f,itemName:"shape",usage:g,coerce:T=>uxe(T)})}function swt(l,o,f){if(Array.isArray(l)&&l.length===3&&l.every(g=>typeof g=="number"&&Number.isFinite(g)))return l;throw new Error(`${o} argument ${f}: expected a [x, y, z] point, got ${Vte(l)}`)}function HO(l,o){return o.map((f,g)=>Gte(d_(f),`${l} operand ${g+1}`))}function K1(...l){const o=$O("union()",l,1,"Use union(shape1, shape2) or union([shape1, shape2]).");if(o.length===0)throw new Error("union requires at least one shape");if(o.length===1)return o[0];const f=o.map(T=>ju(T)),g=U1(Ry("union",f),"boolean:union",T=>YD("union",T,f));return nu(O_(oq(o,g?M_(g,o[0].colorHex):new na(nd().Manifold.union(HO("union()",o)),o[0].colorHex)),KD(o.map(T=>Xf(T)),"boolean",{topology:"none"})),g)}function awt(...l){const o=$O("difference()",l,2,"Use difference(base, cutter1, cutter2) or difference([base, cutter1, cutter2]).");if(o.length<2)throw new Error("difference requires at least two shapes");const f=o.map(T=>ju(T)),g=U1(Ry("difference",f),"boolean:difference",T=>YD("difference",T,f));return nu(O_(W1(o[0],g?M_(g,o[0].colorHex):new na(nd().Manifold.difference(HO("difference()",o)),o[0].colorHex)),KD(o.map(T=>Xf(T)),"boolean",{topology:"none"})),g)}function owt(...l){const o=$O("intersection()",l,2,"Use intersection(shape1, shape2) or intersection([shape1, shape2]).");if(o.length<2)throw new Error("intersection requires at least two shapes");const f=o.map(T=>ju(T)),g=U1(Ry("intersection",f),"boolean:intersection",T=>YD("intersection",T,f));return nu(O_(oq(o,g?M_(g,o[0].colorHex):new na(nd().Manifold.intersection(HO("intersection()",o)),o[0].colorHex)),KD(o.map(T=>Xf(T)),"boolean",{topology:"none"})),g)}function cwt(...l){var O,z;const o=[],f=[],g=l.map((H,re)=>{if(H instanceof na||H&&typeof H=="object"&&typeof H.toShape=="function"){const W=uxe(H);return o.push(W),Gte(d_(W),`hull3d() shape ${o.length}`)}const te=swt(H,"hull3d()",re+1);return f.push(te),te}),T=U1(sqe(o.map(H=>ju(H)),f),"hull",H=>mqe(H)),P=T?M_(T,(O=o[0])==null?void 0:O.colorHex):new na(nd().Manifold.hull(g),(z=o[0])==null?void 0:z.colorHex);return nu(O_(oq(o,P),o.length>0?KD(o.map(H=>Xf(H)),"hull",{topology:"none"}):yq({fidelity:"kernel-native",sources:["hull"]})),T)}function pxe(l,o,f,g=0){return new na(nd().Manifold.levelSet(l,{min:o.min,max:o.max},f,g),void 0,{fidelity:"sampled",sources:["level-set"]})}const Kqe=new WeakMap,eWe=new WeakMap,tWe=new WeakMap;function Pte(l,o){return Kqe.set(l,Fd(o)),l}function nWe(l){return l?[...l]:null}function KJ(l,o){return eWe.set(l,nWe(o)),l}function eq(l,o){return tWe.set(l,i6(o)),l}class Eo{constructor(o,f){tu(this,"colorHex");this.cross=o,this.colorHex=f,Pte(this,null),KJ(this,null),eq(this,null)}color(o){return eq(KJ(Pte(new Eo(this.cross,o),um(this)),a4(this)),r6(this))}clone(){return eq(KJ(Pte(new Eo(this.cross,this.colorHex),um(this)),a4(this)),r6(this))}duplicate(){return this.clone()}area(){return this.cross.area()}bounds(){return this.cross.bounds()}isEmpty(){return this.cross.isEmpty()}numVert(){return this.cross.numVert()}toPolygons(){return this.cross.toPolygons()}translate(o,f){throw new Error("Not implemented")}rotate(o){throw new Error("Not implemented")}rotateAround(o,f){throw new Error("Not implemented")}scale(o){throw new Error("Not implemented")}mirror(o){throw new Error("Not implemented")}add(...o){throw new Error("Not implemented")}subtract(...o){throw new Error("Not implemented")}intersect(...o){throw new Error("Not implemented")}offset(o,f="Round"){return hx(this,new Eo(this.cross.offset(o,f),this.colorHex))}hull(){return hx(this,new Eo(this.cross.hull(),this.colorHex))}simplify(o=1e-6){return hx(this,new Eo(this.cross.simplify(o),this.colorHex))}warp(o){return hx(this,new Eo(this.cross.warp(o),this.colorHex))}extrude(o,f){throw new Error("Not implemented")}revolve(o,f){throw new Error("Not implemented")}attachTo(o,f,g,T){throw new Error("Not implemented")}onFace(o,f,g){throw new Error("Not implemented")}}function um(l){return Fd(Kqe.get(l)??null)}function By(l,o){return Pte(l,o)}function $g(l,o){return By(new Eo(s4(l,nd()),o),l)}function a4(l){return nWe(eWe.get(l)??null)}function l4(l,o){return KJ(l,o)}function r6(l){return i6(tWe.get(l)??null)}function u4(l,o){return eq(l,o)}function hx(l,o){return eq(KJ(o,a4(l)),r6(l))}function lwt(l,o,f=1e-8){if(l==null||o==null)return l==null&&o==null;for(let g=0;g<16;g+=1)if(Math.abs(l[g]-o[g])>f)return!1;return!0}function uwt(l,o,f=1e-8){if(l==null||o==null)return l==null&&o==null;if(!sT(l.source,o.source))return!1;const g=[[l.origin,o.origin],[l.u,o.u],[l.v,o.v],[l.normal,o.normal]];for(const[T,P]of g)for(let O=0;O<T.length;O+=1)if(Math.abs(T[O]-P[O])>f)return!1;return!0}function _wt(l,o,f=1e-8){return l==null||o==null?l==null&&o==null:uwt(l.workplane,o.workplane,f)&&Math.abs(l.u-o.u)<=f&&Math.abs(l.v-o.v)<=f&&Math.abs(l.protrude-o.protrude)<=f&&l.selfAnchor===o.selfAnchor}function mI(l){if(l.length===0)return null;const o=a4(l[0]);for(let f=1;f<l.length;f+=1)if(!lwt(o,a4(l[f])))return null;return o}function hI(l){if(l.length===0)return null;const o=r6(l[0]);for(let f=1;f<l.length;f+=1)if(!_wt(o,r6(l[f])))return null;return o}function fwt(l){const o=l.map(g=>Array.isArray(g)?[g[0],g[1]]:[g.x,g.y]);let f=0;for(let g=0;g<o.length;g++){const[T,P]=o[g],[O,z]=o[(g+1)%o.length];f+=(O-T)*(z+P)}return f>0&&o.reverse(),o.map(([g,T])=>[g,T])}function KS(l,o,f=!1){return $g({kind:"rect",width:l,height:o,center:f,transforms:[]})}function Nb(l,o){return $g({kind:"circle",radius:l,segments:o!=null&&o>0?o:void 0,transforms:[]})}function Zte(l,o,f,g=!1){const T=Math.min(f,l/2,o/2);return $g({kind:"roundedRect",width:l,height:o,radius:T,center:g,transforms:[]})}function Md(l){const o=fwt(l);return $g({kind:"polygon",points:o,transforms:[]})}function pwt(l,o){const f=[];for(let g=0;g<l;g++){const T=2*Math.PI*g/l-Math.PI/2;f.push([o*Math.cos(T),o*Math.sin(T)])}return Md(f)}function dwt(l,o,f=64){const g=[];for(let T=0;T<f;T++){const P=2*Math.PI*T/f;g.push([l*Math.cos(P),o*Math.sin(P)])}return Md(g)}function mwt(l,o){const f=o/2,g=KS(l-o,o,!0),T=Nb(f).translate(-(l-o)/2,0),P=Nb(f).translate((l-o)/2,0);return g.add(T).add(P)}function hwt(l,o,f){const g=[];for(let T=0;T<l*2;T++){const P=Math.PI*T/l-Math.PI/2,O=T%2===0?o:f;g.push([O*Math.cos(P),O*Math.sin(P)])}return Md(g)}function uI(l,o,f=0){const g=Db(um(l),{kind:"translate",x:o,y:f});return hx(l,g?$g(g,l.colorHex):By(new Eo(l.cross.translate(o,f),l.colorHex),null))}function dx(l,o){const f=Db(um(l),{kind:"rotate",degrees:o});return hx(l,f?$g(f,l.colorHex):By(new Eo(l.cross.rotate(o),l.colorHex),null))}function gwt(l,o,f){return uI(dx(uI(l,-f[0],-f[1]),o),f[0],f[1])}function ywt(l,o){const f=typeof o=="number"?[o,o]:o,g=Db(um(l),{kind:"scale",x:f[0],y:f[1]});return hx(l,g?$g(g,l.colorHex):By(new Eo(l.cross.scale(o),l.colorHex),null))}function vwt(l,o){const f=Db(um(l),{kind:"mirror",normalX:o[0],normalY:o[1]});return hx(l,f?$g(f,l.colorHex):By(new Eo(l.cross.mirror(o),l.colorHex),null))}Eo.prototype.translate=function(l,o=0){return uI(this,l,o)};Eo.prototype.rotate=function(l){return dx(this,l)};Eo.prototype.rotateAround=function(l,o){return gwt(this,l,o)};Eo.prototype.scale=function(l){return ywt(this,l)};Eo.prototype.mirror=function(l){return vwt(this,l)};function V1(l,o,f){return{name:l,start:o,end:f,query:{kind:"tracked-edge",edgeName:l,selector:"edge"}}}class po{constructor(o,f,g,T){this.shape=o,this.topology=f,this.baseHeight=g,this.extrudeUp=T,mne(this.shape,Swt(this.topology),{merge:!0})}face(o){var T;const f=this.topology.faces.get(o);if(!f){const P=[...this.topology.faces.keys()].join(", ");throw new Error(`Face "${o}" not found. Available: ${P}`)}const g=Qte(this.shape);return{...f,normal:[f.normal[0],f.normal[1],f.normal[2]],center:[f.center[0],f.center[1],f.center[2]],query:iu({kind:"tracked-face",faceName:o,owner:Sp(g??((T=f.query)==null?void 0:T.owner))}),uAxis:f.uAxis?[f.uAxis[0],f.uAxis[1],f.uAxis[2]]:void 0,vAxis:f.vAxis?[f.vAxis[0],f.vAxis[1],f.vAxis[2]]:void 0}}edge(o){var T;const f=this.topology.edges.get(o);if(!f){const P=[...this.topology.edges.keys()].join(", ");throw new Error(`Edge "${o}" not found. Available: ${P}`)}const g=Qte(this.shape);return{...f,start:[f.start[0],f.start[1],f.start[2]],end:[f.end[0],f.end[1],f.end[2]],query:wl({kind:"tracked-edge",edgeName:o,selector:"edge",owner:Sp(g??((T=f.query)==null?void 0:T.owner))})}}faceNames(){return[...this.topology.faces.keys()]}edgeNames(){return[...this.topology.edges.keys()]}clone(){return new po(this.shape.clone(),Fbe(this.topology),this.baseHeight,this.extrudeUp)}duplicate(){return this.clone()}geometryInfo(){const o=this.shape.geometryInfo(),f=this.topology.faces.size>0||this.topology.edges.size>0;return{...o,topology:f?"synthetic":o.topology}}withReferences(o){return new po(this.shape.withReferences(o),Fbe(this.topology),this.baseHeight,this.extrudeUp)}referenceNames(o){return this.shape.referenceNames(o)}referencePoint(o){return this.shape.referencePoint(o)}placeReference(o,f,g){return new po(this.shape.placeReference(o,f,g),Fbe(this.topology),this.baseHeight,this.extrudeUp)}translate(o,f,g){const T=bwt(this.topology,o,f,g);return new po(this.shape.translate(o,f,g),T,this.baseHeight,this.extrudeUp)}moveTo(o,f,g){const T=this.shape.boundingBox();return this.translate(o-T.min[0],f-T.min[1],g-T.min[2])}moveToLocal(o,f,g,T){const O=(o instanceof po?o.toShape():o).boundingBox();return this.moveTo(O.min[0]+f,O.min[1]+g,O.min[2]+T)}moveBy(o,f,g){return this.translate(o,f,g)}rotateAroundEdge(o,f){const g=this.edge(o),[T,P,O]=g.start,z=g.end[0]-T,H=g.end[1]-P,re=g.end[2]-O,te=Math.sqrt(z*z+H*H+re*re)||1,W=z/te,Ee=H/te,se=re/te,me=f*Math.PI/180,Xe=Math.cos(me),it=Math.sin(me),at=1-Xe,It=at*W*W+Xe,tn=at*W*Ee-it*se,At=at*W*se+it*Ee,mt=at*W*Ee+it*se,ht=at*Ee*Ee+Xe,xn=at*Ee*se-it*W,Pn=at*W*se-it*Ee,$r=at*Ee*se+it*W,zn=at*se*se+Xe,ii=-It*T-tn*P-At*O+T,Gr=-mt*T-ht*P-xn*O+P,mn=-Pn*T-$r*P-zn*O+O,$s=[It,mt,Pn,0,tn,ht,$r,0,At,xn,zn,0,ii,Gr,mn,1],is=this.shape.transform($s);return new po(is,{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}rotate(o,f,g){return new po(this.shape.rotate(o,f,g),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}transform(o){return new po(this.shape.transform(o),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}pointAlong(o){return new po(this.shape.pointAlong(o),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}rotateAround(o,f,g=[0,0,0]){return new po(this.shape.rotateAround(o,f,g),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}rotateAroundTo(o,f,g,T,P={}){return new po(this.shape.rotateAroundTo(o,f,g,T,P),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}scale(o){return new po(this.shape.scale(o),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}mirror(o){return new po(this.shape.mirror(o),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}color(o){return new po(this.shape.color(o),this.topology,this.baseHeight,this.extrudeUp)}toShape(){return this.shape}attachTo(o,f,g="center",T){let P;if(typeof o._bbox=="function"&&!(o instanceof po)&&!(o instanceof na)){if(f.includes("."))throw new Error(`ShapeGroup targets only support built-in anchors, got "${f}"`);const te=o._bbox();P=t4(te.min,te.max,f)}else P=(o instanceof po,o).referencePoint(f);const O=this.referencePoint(g);let z=P[0]-O[0],H=P[1]-O[1],re=P[2]-O[2];return T&&(z+=T[0],H+=T[1],re+=T[2]),this.translate(z,H,re)}onFace(o,f,g={}){const T=g.u??0,P=g.v??0,O=g.protrude??0,z={front:"back",back:"front",left:"right",right:"left",top:"bottom",bottom:"top"},H={front:(re,te,W)=>[re,-W,te],back:(re,te,W)=>[re,W,te],left:(re,te,W)=>[-W,re,te],right:(re,te,W)=>[W,re,te],top:(re,te,W)=>[re,te,W],bottom:(re,te,W)=>[re,te,-W]};return this.attachTo(o,f,z[f],H[f](T,P,O))}subtract(...o){return this.shape.subtract(...o)}add(...o){return this.shape.add(...o)}intersect(...o){return this.shape.intersect(...o)}shell(o,f={}){return this.shape.shell(o,f)}boundingBox(){return this.shape.boundingBox()}get volume(){return this.shape.volume()}}function bwt(l,o,f,g){const T=new Map;for(const[O,z]of l.faces)T.set(O,{...z,center:[z.center[0]+o,z.center[1]+f,z.center[2]+g],query:iu(z.query),uAxis:z.uAxis?[z.uAxis[0],z.uAxis[1],z.uAxis[2]]:void 0,vAxis:z.vAxis?[z.vAxis[0],z.vAxis[1],z.vAxis[2]]:void 0});const P=new Map;for(const[O,z]of l.edges)P.set(O,{...z,start:[z.start[0]+o,z.start[1]+f,z.start[2]+g],end:[z.end[0]+o,z.end[1]+f,z.end[2]+g],query:wl(z.query)});return{faces:T,edges:P}}function Fbe(l){const o=new Map;for(const[g,T]of l.faces)o.set(g,{...T,normal:[T.normal[0],T.normal[1],T.normal[2]],center:[T.center[0],T.center[1],T.center[2]],query:iu(T.query),uAxis:T.uAxis?[T.uAxis[0],T.uAxis[1],T.uAxis[2]]:void 0,vAxis:T.vAxis?[T.vAxis[0],T.vAxis[1],T.vAxis[2]]:void 0});const f=new Map;for(const[g,T]of l.edges)f.set(g,{...T,start:[T.start[0],T.start[1],T.start[2]],end:[T.end[0],T.end[1],T.end[2]],query:wl(T.query)});return{faces:o,edges:f}}function xwt(l,o){const f=Ea.from(o),g=new Map;for(const[P,O]of l.faces)g.set(P,{...O,normal:td(f.vector(O.normal)),center:f.point(O.center),query:iu(O.query),uAxis:O.uAxis?td(f.vector(O.uAxis)):void 0,vAxis:O.vAxis?td(f.vector(O.vAxis)):void 0});const T=new Map;for(const[P,O]of l.edges)T.set(P,{...O,start:f.point(O.start),end:f.point(O.end),query:wl(O.query)});return{faces:g,edges:T}}function Swt(l){const o={};for(const[g,T]of l.faces)o[g]={center:[T.center[0],T.center[1],T.center[2]],normal:[T.normal[0],T.normal[1],T.normal[2]]};const f={};for(const[g,T]of l.edges)f[g]={start:[T.start[0],T.start[1],T.start[2]],end:[T.end[0],T.end[1],T.end[2]]};return{surfaces:o,edges:f}}function rWe(l,o,f=!0,g=0){const T=new Map,P=new Map,[O,z,H,re]=l.vertices,te=g,W=g+(f?o:-o),Ee=Math.max(te,W),se=Math.min(te,W),me=l.center.x,Xe=l.center.y,it=td([z.x-O.x,z.y-O.y,0]),at=td([re.x-O.x,re.y-O.y,0]);T.set("top",{name:"top",normal:[0,0,1],center:[me,Xe,Ee],planar:!0,uAxis:it,vAxis:at}),T.set("bottom",{name:"bottom",normal:[0,0,-1],center:[me,Xe,se],planar:!0,uAxis:it,vAxis:[-at[0],-at[1],-at[2]]});const It=[["bottom",O,z],["right",z,H],["top",H,re],["left",re,O]];for(const[tn,At,mt]of It){const ht=At.midpointTo(mt),xn=mt.x-At.x,Pn=mt.y-At.y,$r=Math.sqrt(xn*xn+Pn*Pn)||1,zn=Pn/$r,ii=-xn/$r,Gr=[xn/$r,Pn/$r,0];T.set(`side-${tn}`,{name:`side-${tn}`,normal:[zn,ii,0],center:[ht.x,ht.y,(Ee+se)/2],planar:!0,uAxis:Gr,vAxis:[0,0,1]})}return P.set("bottom-bottom",V1("bottom-bottom",[O.x,O.y,se],[z.x,z.y,se])),P.set("bottom-right",V1("bottom-right",[z.x,z.y,se],[H.x,H.y,se])),P.set("bottom-top",V1("bottom-top",[H.x,H.y,se],[re.x,re.y,se])),P.set("bottom-left",V1("bottom-left",[re.x,re.y,se],[O.x,O.y,se])),P.set("top-bottom",V1("top-bottom",[O.x,O.y,Ee],[z.x,z.y,Ee])),P.set("top-right",V1("top-right",[z.x,z.y,Ee],[H.x,H.y,Ee])),P.set("top-top",V1("top-top",[H.x,H.y,Ee],[re.x,re.y,Ee])),P.set("top-left",V1("top-left",[re.x,re.y,Ee],[O.x,O.y,Ee])),P.set("vert-bl",V1("vert-bl",[O.x,O.y,se],[O.x,O.y,Ee])),P.set("vert-br",V1("vert-br",[z.x,z.y,se],[z.x,z.y,Ee])),P.set("vert-tr",V1("vert-tr",[H.x,H.y,se],[H.x,H.y,Ee])),P.set("vert-tl",V1("vert-tl",[re.x,re.y,se],[re.x,re.y,Ee])),{faces:T,edges:P}}function iWe(l,o,f=!1){const g=new Map,T=new Map,P=l.center.x,O=l.center.y,z=f?-o/2:0,H=f?o/2:o,re=Math.min(z,H),te=Math.max(z,H),W=l.radiusTop??l.radius,Ee=(Math.abs(l.radius)+Math.abs(W))/2;return g.set("top",{name:"top",normal:[0,0,1],center:[P,O,te],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0]}),g.set("bottom",{name:"bottom",normal:[0,0,-1],center:[P,O,re],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0]}),g.set("side",{name:"side",normal:[1,0,0],center:[P+Ee,O,(te+re)/2],planar:!1}),T.set("top-rim",V1("top-rim",[P+W,O,te],[P,O+W,te])),T.set("bottom-rim",V1("bottom-rim",[P+l.radius,O,re],[P,O+l.radius,re])),{faces:g,edges:T}}function Twt(l,o){const f=l.bounds(),[g,T]=f.min,[P,O]=f.max,z=(g+P)/2,H=(T+O)/2;switch(o){case"center":return[z,H];case"top-left":return[g,O];case"top-right":return[P,O];case"bottom-left":return[g,T];case"bottom-right":return[P,T];case"top":return[z,O];case"bottom":return[z,T];case"left":return[g,H];case"right":return[P,H]}}function kwt(l,o){if(typeof l._bbox=="function"){const T=l._bbox();return t4(T.min,T.max,o)}const f=l;return("toShape"in f?f.toShape():f).referencePoint(o)}function Cwt(l){if(typeof l._bbox=="function")return;const o=l,f="toShape"in o?o.toShape():o;return Sp(Qte(f)??void 0)}function bze(l){return l==="front"||l==="back"||l==="left"||l==="right"||l==="top"||l==="bottom"}function xze(l){if(!l||typeof l!="object")return!1;const o=l;return typeof o.name=="string"&&Array.isArray(o.normal)&&Array.isArray(o.center)}function wwt(l){switch(l){case"front":return{u:[1,0,0],v:[0,0,1],normal:[0,-1,0]};case"back":return{u:[-1,0,0],v:[0,0,1],normal:[0,1,0]};case"left":return{u:[0,-1,0],v:[0,0,1],normal:[-1,0,0]};case"right":return{u:[0,1,0],v:[0,0,1],normal:[1,0,0]};case"bottom":return{u:[1,0,0],v:[0,-1,0],normal:[0,0,-1]};case"top":default:return{u:[1,0,0],v:[0,1,0],normal:[0,0,1]}}}function Zee(l){if(l.planar===!1||!l.uAxis||!l.vAxis)throw new Error(`Face "${l.name}" is not planar and cannot host a sketch.`);const o=(()=>{var g;if(l.query&&l.query.kind!=="tracked-face"&&l.query.kind!=="canonical-face")return iu(l.query);const f=Sp((g=l.query)==null?void 0:g.owner);return{kind:"face-ref",faceName:l.name,owner:f}})();return{origin:[l.center[0],l.center[1],l.center[2]],u:[l.uAxis[0],l.uAxis[1],l.uAxis[2]],v:[l.vAxis[0],l.vAxis[1],l.vAxis[2]],normal:[l.normal[0],l.normal[1],l.normal[2]],source:o}}function Ewt(l,o){var T;const f=l.topology.faces.get(o);if(!f)return null;const g=Qte(l.toShape())??((T=f.query)==null?void 0:T.owner);return{...f,normal:[f.normal[0],f.normal[1],f.normal[2]],center:[f.center[0],f.center[1],f.center[2]],query:iu({kind:"tracked-face",faceName:o,owner:Sp(g??void 0)}),uAxis:f.uAxis?[f.uAxis[0],f.uAxis[1],f.uAxis[2]]:void 0,vAxis:f.vAxis?[f.vAxis[0],f.vAxis[1],f.vAxis[2]]:void 0}}function Pwt(l){return l.faceNames().filter(o=>{const f=l.topology.faces.get(o);return!!f&&f.planar!==!1&&!!f.uAxis&&!!f.vAxis})}function Dwt(l,o){const f=l instanceof Error?l.message:String(l);return f===`Face "${o}" is not available. Supported faces: none`||f.startsWith(`Face "${o}" is not available. Supported faces: `)}function rM(l,o){if(xze(l))return Zee(l);if(o==null)throw new Error("Sketch.onFace(parent, face, opts) requires a face name or FaceRef.");if(xze(o))return Zee(o);if(typeof o!="string")throw new Error("Sketch.onFace() requires a face name or FaceRef.");if(l instanceof po){const f=Ewt(l,o);if(f)return{...Zee(f),source:iu(f.query)??{kind:"tracked-face",faceName:o}}}if(l instanceof na&&c4(l))try{return Zee(l.face(o))}catch(f){if(!bze(o)||!Dwt(f,o))throw f}if(bze(o)){const f=wwt(o);return{origin:kwt(l,o),u:f.u,v:f.v,normal:f.normal,source:{kind:"canonical-face",face:o,owner:Cwt(l)}}}if(l instanceof po){const f=Pwt(l).join(", ")||"none";throw new Error(`Face "${o}" not found or is not planar. Available planar faces: ${f}`)}throw new Error(`Named face "${o}" requires a TrackedShape parent or a FaceRef target.`)}function Awt(l,o,f,g){return[l[0],l[1],l[2],0,o[0],o[1],o[2],0,f[0],f[1],f[2],0,g[0],g[1],g[2],1]}function Nwt(l,o){const[f,g]=Twt(l,o.selfAnchor),T=[o.workplane.origin[0]+o.workplane.u[0]*o.u+o.workplane.v[0]*o.v+o.workplane.normal[0]*o.protrude,o.workplane.origin[1]+o.workplane.u[1]*o.u+o.workplane.v[1]*o.v+o.workplane.normal[1]*o.protrude,o.workplane.origin[2]+o.workplane.u[2]*o.u+o.workplane.v[2]*o.v+o.workplane.normal[2]*o.protrude],P=Awt(o.workplane.u,o.workplane.v,o.workplane.normal,T);return Ea.translation(-f,-g,0).mul(P).toArray()}function Iwt(l){if(!l||typeof l!="object")return!1;const o=l;return typeof o.name=="string"&&Array.isArray(o.normal)&&Array.isArray(o.center)}function Fwt(l,o,f,g={}){const T=Iwt(o);if(T&&typeof f=="string")throw new Error("Sketch.onFace(faceRef, opts) accepts options as the second argument, not a face name.");const P=T?rM(o):rM(o,f),O=(T?f:g)??{},z={workplane:P,u:O.u??0,v:O.v??0,protrude:O.protrude??0,selfAnchor:O.selfAnchor??"center"};return u4(l4(l.clone(),Nwt(l,z)),z)}Eo.prototype.onFace=function(l,o,f={}){return Fwt(this,l,o,f)};function gI(l,o,f,g){return aqe({apiName:l,inputs:o,minCount:f,itemName:"sketch",usage:g,coerce:T=>{if(T instanceof Eo)return T;throw new Error(`expected a Sketch, got ${Vte(T)}`)}})}function Owt(l,...o){const f=[l,...gI("Sketch.add()",o,1,"Use sketch.add(other1, other2) or sketch.add([other1, other2]).")],g=iT("union",f.map(T=>um(T)));return u4(l4(g?$g(g,l.colorHex):By(new Eo(nd().CrossSection.union(f.map(T=>T.cross)),l.colorHex),null),mI(f)),hI(f))}function Mwt(l,...o){const f=[l,...gI("Sketch.subtract()",o,1,"Use sketch.subtract(other1, other2) or sketch.subtract([other1, other2]).")],g=iT("difference",f.map(T=>um(T)));return u4(l4(g?$g(g,l.colorHex):By(new Eo(nd().CrossSection.difference(f.map(T=>T.cross)),l.colorHex),null),mI(f)),hI(f))}function Lwt(l,...o){const f=[l,...gI("Sketch.intersect()",o,1,"Use sketch.intersect(other1, other2) or sketch.intersect([other1, other2]).")],g=iT("intersection",f.map(T=>um(T)));return u4(l4(g?$g(g,l.colorHex):By(new Eo(nd().CrossSection.intersection(f.map(T=>T.cross)),l.colorHex),null),mI(f)),hI(f))}function Ug(...l){const o=gI("union2d()",l,1,"Use union2d(sketch1, sketch2) or union2d([sketch1, sketch2]).");if(o.length===0)throw new Error("union2d requires at least one sketch");if(o.length===1)return o[0];const f=iT("union",o.map(g=>um(g)));return u4(l4(f?$g(f,o[0].colorHex):By(new Eo(nd().CrossSection.union(o.map(g=>g.cross)),o[0].colorHex),null),mI(o)),hI(o))}function Z1(...l){const o=gI("difference2d()",l,2,"Use difference2d(base, cutter1, cutter2) or difference2d([base, cutter1, cutter2]).");if(o.length<2)throw new Error("difference2d requires at least two sketches");const f=iT("difference",o.map(g=>um(g)));return u4(l4(f?$g(f,o[0].colorHex):By(new Eo(nd().CrossSection.difference(o.map(g=>g.cross)),o[0].colorHex),null),mI(o)),hI(o))}function Rwt(...l){const o=gI("intersection2d()",l,2,"Use intersection2d(sketch1, sketch2) or intersection2d([sketch1, sketch2]).");if(o.length<2)throw new Error("intersection2d requires at least two sketches");const f=iT("intersection",o.map(g=>um(g)));return u4(l4(f?$g(f,o[0].colorHex):By(new Eo(nd().CrossSection.intersection(o.map(g=>g.cross)),o[0].colorHex),null),mI(o)),hI(o))}function jwt(...l){const o=gI("hull2d()",l,1,"Use hull2d(sketch1, sketch2) or hull2d([sketch1, sketch2]).");if(o.length===0)throw new Error("hull2d requires at least one sketch");const f=iqe(o.map(g=>um(g)));return u4(l4(f?$g(f,o[0].colorHex):By(new Eo(nd().CrossSection.hull(o.map(g=>g.cross)),o[0].colorHex),null),mI(o)),hI(o))}Eo.prototype.add=function(...l){return Owt(this,...l)};Eo.prototype.subtract=function(...l){return Mwt(this,...l)};Eo.prototype.intersect=function(...l){return Lwt(this,...l)};function Bwt(l,o,f="Round"){const g=f==="Round"?rqe(um(l),o,"Round"):null;return hx(l,g?$g(g,l.colorHex):By(new Eo(l.cross.offset(o,f),l.colorHex),null))}function zwt(l){const o=iqe([um(l)]);return hx(l,o?$g(o,l.colorHex):By(new Eo(l.cross.hull(),l.colorHex),null))}function Jwt(l,o=1e-6){return hx(l,new Eo(l.cross.simplify(o),l.colorHex))}function qwt(l,o){return hx(l,new Eo(l.cross.warp(o),l.colorHex))}Eo.prototype.offset=function(l,o="Round"){return Bwt(this,l,o)};Eo.prototype.hull=function(){return zwt(this)};Eo.prototype.simplify=function(l=1e-6){return Jwt(this,l)};Eo.prototype.warp=function(l){return qwt(this,l)};function Wwt(l,o,f){const g=new Map,T=new Map,P=l.bounds(),O=(P.min[0]+P.max[0])/2,z=(P.min[1]+P.max[1])/2,H=f?-o/2:0,re=f?o/2:o;return g.set("top",{name:"top",normal:[0,0,1],center:[O,z,re],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0]}),g.set("bottom",{name:"bottom",normal:[0,0,-1],center:[O,z,H],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0]}),g.set("side",{name:"side",normal:[1,0,0],center:[P.max[0],z,(re+H)/2],planar:!1}),{faces:g,edges:T}}function aT(l,o,f){const g=typeof(f==null?void 0:f.scaleTop)=="number"?[f.scaleTop,f.scaleTop]:f==null?void 0:f.scaleTop,T=((f==null?void 0:f.twist)==null||f.twist===0)&&((f==null?void 0:f.divisions)==null||f.divisions===0)?(()=>{const Ee=um(l);return Ee?{kind:"extrude",profile:Ee,height:o,center:(f==null?void 0:f.center)??!1,scaleTop:g}:null})():null,P=a4(l),O=r6(l),z=T&&P&&O?G1(T,{kind:"workplanePlacement",matrix:P,placement:O}):T,H=s6(z,"extrude"),re=H?M_(H,l.colorHex,{fidelity:"kernel-native",sources:["extrude"]}):gne(new na(l.cross.extrude(o,(f==null?void 0:f.divisions)??0,(f==null?void 0:f.twist)??0,g,(f==null?void 0:f.center)??!1),l.colorHex,{fidelity:"kernel-native",sources:["extrude"]}),null),te=Wwt(l,o,(f==null?void 0:f.center)??!1);if(!P)return new po(re,te,0,!0);const W=xwt(te,P);return H&&O?new po(re,W,0,!0):new po(re.transform(P),W,0,!0)}function Vwt(l,o=360,f){const g=(()=>{const re=um(l);return re?{kind:"revolve",profile:re,degrees:o,segments:f!=null&&f>0?f:void 0}:null})(),T=a4(l),P=r6(l),O=g&&T&&P?G1(g,{kind:"workplanePlacement",matrix:T,placement:P}):g,z=s6(O,"revolve"),H=z?M_(z,l.colorHex,{fidelity:"kernel-native",sources:["revolve"]}):gne(new na(l.cross.revolve(f??0,o),l.colorHex,{fidelity:"kernel-native",sources:["revolve"]}),null);return!T||z&&P?H:H.transform(T)}Eo.prototype.extrude=function(l,o){return aT(this,l,o)};Eo.prototype.revolve=function(l=360,o){return Vwt(this,l,o)};class sWe{constructor(){tu(this,"points",[]);tu(this,"x",0);tu(this,"y",0)}moveTo(o,f){return this.x=o,this.y=f,this.points.push([o,f]),this}lineTo(o,f){return this.x=o,this.y=f,this.points.push([o,f]),this}lineH(o){return this.lineTo(this.x+o,this.y)}lineV(o){return this.lineTo(this.x,this.y+o)}lineAngled(o,f){const g=f*Math.PI/180;return this.lineTo(this.x+o*Math.cos(g),this.y+o*Math.sin(g))}close(){if(this.points.length<3)throw new Error("Path needs at least 3 points");const o=this.points;let f=0;for(let g=0;g<o.length;g++){const[T,P]=o[g],[O,z]=o[(g+1)%o.length];f+=(O-T)*(z+P)}return f>0&&o.reverse(),Md(o)}stroke(o,f="Square"){if(this.points.length<2)throw new Error("Stroke needs at least 2 points");const g=o/2,T=this.points,P=T.length,O=[];for(let Ee=0;Ee<P-1;Ee++){const se=T[Ee+1][0]-T[Ee][0],me=T[Ee+1][1]-T[Ee][1],Xe=Math.sqrt(se*se+me*me);O.push([-me/Xe,se/Xe])}const z=[],H=[];for(let Ee=0;Ee<P;Ee++){const[se,me]=T[Ee];if(Ee===0||Ee===P-1){const Xe=O[Ee===0?0:P-2];z.push([se+Xe[0]*g,me+Xe[1]*g]),H.push([se-Xe[0]*g,me-Xe[1]*g])}else{const Xe=O[Ee-1],it=O[Ee];let at=Xe[0]+it[0],It=Xe[1]+it[1],tn=Math.sqrt(at*at+It*It);tn<1e-9&&(at=Xe[0],It=Xe[1],tn=1),at/=tn,It/=tn;const At=g/(at*Xe[0]+It*Xe[1]);z.push([se+at*At,me+It*At]),H.push([se-at*At,me-It*At])}}const re=[...z,...H.reverse()];let te=0;for(let Ee=0;Ee<re.length;Ee++){const[se,me]=re[Ee],[Xe,it]=re[(Ee+1)%re.length];te+=(Xe-se)*(it+me)}te>0&&re.reverse();let W=Md(re);return f==="Round"&&(W=W.offset(-g/2,"Round").offset(g/2,"Round")),W}}function Uwt(){return new sWe}function dxe(l,o,f="Square"){const g=new sWe;g.moveTo(l[0][0],l[0][1]);for(let T=1;T<l.length;T++)g.lineTo(l[T][0],l[T][1]);return g.stroke(o,f)}function Sze(l,o){const f=l.bounds(),[g,T]=f.min,[P,O]=f.max,z=(g+P)/2,H=(T+O)/2;switch(o){case"center":return[z,H];case"top-left":return[g,O];case"top-right":return[P,O];case"bottom-left":return[g,T];case"bottom-right":return[P,T];case"top":return[z,O];case"bottom":return[z,T];case"left":return[g,H];case"right":return[P,H]}}function $wt(l,o,f,g="center",T){const P=Sze(o,f),O=Sze(l,g);let z=P[0]-O[0],H=P[1]-O[1];return T&&(z+=T[0],H+=T[1]),l.translate(z,H)}Eo.prototype.attachTo=function(l,o,f="center",g){return $wt(this,l,o,f,g)};const Kte=.001,aWe=l=>l*Math.PI/180,YN=(l,o)=>{const f=o.x-l.x,g=o.y-l.y;return Math.sqrt(f*f+g*g)},H1=(l,o)=>[(l.x+o.x)/2,(l.y+o.y)/2],Tze=(l,o)=>{const f=YN(l,o)||1;return[(o.x-l.x)/f,(o.y-l.y)/f]},kze=(l,o)=>Math.atan2(o.y-l.y,o.x-l.x),Hwt=l=>{let o=l;for(;o>Math.PI;)o-=Math.PI*2;for(;o<-Math.PI;)o+=Math.PI*2;return o},oWe=(l,o,f)=>{const g=f.x-o.x,T=f.y-o.y,P=g*g+T*T;if(P<1e-9)return[o.x,o.y];const O=((l.x-o.x)*g+(l.y-o.y)*T)/P;return[o.x+O*g,o.y+O*T]},Cze=(l,o,f)=>{const g=oWe(l,o,f);return[2*g[0]-l.x,2*g[1]-l.y]},cWe=l=>({points:l.points.map(o=>({...o})),lines:l.lines.map(o=>({...o})),circles:l.circles.map(o=>({...o})),loops:l.loops.map(o=>o.type==="poly"?{type:"poly",points:[...o.points]}:{type:"circle",circle:o.circle}),constraints:l.constraints.map(o=>({...o})),rejectedConstraints:l.rejectedConstraints.map(o=>({...o}))}),Gwt=l=>{switch(l){case"coincident":return"COINC";case"horizontal":return"H";case"vertical":return"V";case"parallel":return"PAR";case"perpendicular":return"PERP";case"tangent":return"TAN";case"equal":return"EQ";case"symmetric":return"SYM";case"concentric":return"CONC";case"collinear":return"COLL";case"fixed":return"FIX";case"distance":return"DIST";case"length":return"LEN";case"angle":return"ANG";case"radius":return"R";case"diameter":return"DIA";case"hDistance":return"HD";case"vDistance":return"VD";default:return"C"}},Xwt=l=>l==="distance"||l==="length"||l==="angle"||l==="radius"||l==="diameter"||l==="hDistance"||l==="vDistance",Ywt=l=>{if(l.type==="distance"||l.type==="length"||l.type==="angle"||l.type==="radius"||l.type==="diameter"||l.type==="hDistance"||l.type==="vDistance")return l.value},Qwt=(l,o)=>{l.type==="distance"&&(l.value=o),l.type==="length"&&(l.value=o),l.type==="angle"&&(l.value=o),l.type==="radius"&&(l.value=o),l.type==="diameter"&&(l.value=o),l.type==="hDistance"&&(l.value=o),l.type==="vDistance"&&(l.value=o)},wze=(l,o)=>{const f=new Map(l.points.map(O=>[O.id,O])),g=new Map(l.lines.map(O=>[O.id,O])),T=new Map(l.circles.map(O=>[O.id,O])),P=[];return l.constraints.forEach(O=>{let z=[0,0];if(O.type==="coincident"||O.type==="distance"||O.type==="hDistance"||O.type==="vDistance"){const H=f.get(O.a),re=f.get(O.b);H&&re&&(z=H1(H,re))}else if(O.type==="horizontal"||O.type==="vertical"||O.type==="length"){const H=g.get(O.line);if(H){const re=f.get(H.a),te=f.get(H.b);re&&te&&(z=H1(re,te))}}else if(O.type==="parallel"||O.type==="perpendicular"||O.type==="equal"||O.type==="angle"){const H=g.get(O.a),re=g.get(O.b);if(H&&re){const te=f.get(H.a),W=f.get(H.b),Ee=f.get(re.a),se=f.get(re.b);if(te&&W&&Ee&&se){const me=H1(te,W),Xe=H1(Ee,se);z=[(me[0]+Xe[0])/2,(me[1]+Xe[1])/2]}}}else if(O.type==="radius"||O.type==="diameter"){const H=T.get(O.circle);if(H){const re=f.get(H.center);re&&(z=[re.x+H.radius,re.y])}}else if(O.type==="concentric"){const H=T.get(O.a),re=T.get(O.b);if(H&&re){const te=f.get(H.center),W=f.get(re.center);te&&W&&(z=H1(te,W))}}else if(O.type==="collinear"){const H=f.get(O.point);H&&(z=[H.x,H.y])}else if(O.type==="fixed"){const H=f.get(O.point);H&&(z=[H.x,H.y])}else if(O.type==="symmetric"){const H=f.get(O.a),re=f.get(O.b);H&&re&&(z=H1(H,re))}else if(O.type==="tangent"){if(O.line&&O.circle){const H=g.get(O.line),re=T.get(O.circle);if(H&&re){const te=f.get(H.a),W=f.get(H.b);te&&W&&(z=H1(te,W))}}else if(O.a&&O.b){const H=T.get(O.a),re=T.get(O.b);if(H&&re){const te=f.get(H.center),W=f.get(re.center);te&&W&&(z=H1(te,W))}}}P.push({id:O.id,type:O.type,label:Gwt(O.type),position:z,value:Ywt(O),isDimension:Xwt(O.type),isConflicting:o.has(O.id)})}),P},Zwt=l=>{const o=[];if(l.loops.forEach(f=>{if(f.type==="poly"){const g=f.points.map(T=>{const P=l.points.find(O=>O.id===T);if(!P)throw new Error(`Missing point ${T}`);return[P.x,P.y]});g.length>=3&&o.push(Md(g))}else if(f.type==="circle"){const g=l.circles.find(O=>O.id===f.circle);if(!g)throw new Error(`Missing circle ${f.circle}`);const T=l.points.find(O=>O.id===g.center);if(!T)throw new Error(`Missing center ${g.center}`);const P=new Eo(nd().CrossSection.circle(g.radius,g.segments));o.push(P.translate(T.x,T.y))}}),o.length===0)throw new Error("Constrained sketch needs at least one closed loop");return Ug(...o)},Kwt=l=>{const o=new Map(l.points.map(T=>[T.id,T])),f=l.lines.filter(T=>T.construction).map(T=>{const P=o.get(T.a),O=o.get(T.b);return!P||!O?null:{a:[P.x,P.y],b:[O.x,O.y]}}).filter(T=>T!==null),g=l.circles.filter(T=>T.construction).map(T=>{const P=o.get(T.center);return P?{center:[P.x,P.y],radius:T.radius}:null}).filter(T=>T!==null);return{lines:f,circles:g}},eEt=(l,o)=>{l.fixed=!0,l.x=o.x,l.y=o.y},lWe=(l,o)=>{const f=o.iterations??40,g=o.tolerance??Kte,T=new Map(l.points.map(re=>[re.id,re])),P=new Map(l.lines.map(re=>[re.id,re])),O=new Map(l.circles.map(re=>[re.id,re]));l.constraints.forEach(re=>{if(re.type==="fixed"){const te=T.get(re.point);te&&eEt(te,re)}});const z=(re,te,W)=>re.fixed?!1:(re.x+=te,re.y+=W,!0);let H=0;for(let re=0;re<f&&(H=0,l.constraints.forEach(te=>{let W=0;if(te.type==="coincident"){const Ee=T.get(te.a),se=T.get(te.b);if(!Ee||!se)return;const me=se.x-Ee.x,Xe=se.y-Ee.y;if(W=Math.sqrt(me*me+Xe*Xe),W<=g||Ee.fixed&&se.fixed)return;if(Ee.fixed){se.x=Ee.x,se.y=Ee.y;return}if(se.fixed){Ee.x=se.x,Ee.y=se.y;return}const it=(Ee.x+se.x)/2,at=(Ee.y+se.y)/2;Ee.x=it,Ee.y=at,se.x=it,se.y=at}if(te.type==="horizontal"){const Ee=P.get(te.line);if(!Ee)return;const se=T.get(Ee.a),me=T.get(Ee.b);if(!se||!me||(W=Math.abs(me.y-se.y),W<=g)||se.fixed&&me.fixed)return;const Xe=(se.y+me.y)/2;se.fixed||(se.y=Xe),me.fixed||(me.y=Xe)}if(te.type==="vertical"){const Ee=P.get(te.line);if(!Ee)return;const se=T.get(Ee.a),me=T.get(Ee.b);if(!se||!me||(W=Math.abs(me.x-se.x),W<=g)||se.fixed&&me.fixed)return;const Xe=(se.x+me.x)/2;se.fixed||(se.x=Xe),me.fixed||(me.x=Xe)}if(te.type==="parallel"||te.type==="perpendicular"||te.type==="angle"){const Ee=P.get(te.a),se=P.get(te.b);if(!Ee||!se)return;const me=T.get(Ee.a),Xe=T.get(Ee.b),it=T.get(se.a),at=T.get(se.b);if(!me||!Xe||!it||!at)return;const It=kze(me,Xe),tn=te.type==="parallel"?It:te.type==="perpendicular"?It+Math.PI/2:It+aWe(te.value),At=kze(it,at),mt=Hwt(At-tn);if(W=Math.abs(mt),W<=g||it.fixed&&at.fixed)return;const ht=YN(it,at)||1,xn=[Math.cos(tn),Math.sin(tn)];if(it.fixed)at.x=it.x+xn[0]*ht,at.y=it.y+xn[1]*ht;else if(at.fixed)it.x=at.x-xn[0]*ht,it.y=at.y-xn[1]*ht;else{const Pn=H1(it,at);it.x=Pn[0]-xn[0]*ht/2,it.y=Pn[1]-xn[1]*ht/2,at.x=Pn[0]+xn[0]*ht/2,at.y=Pn[1]+xn[1]*ht/2}}if(te.type==="equal"){const Ee=P.get(te.a),se=P.get(te.b);if(!Ee||!se)return;const me=T.get(Ee.a),Xe=T.get(Ee.b),it=T.get(se.a),at=T.get(se.b);if(!me||!Xe||!it||!at)return;const It=YN(me,Xe),tn=YN(it,at)||1;if(W=Math.abs(tn-It),W<=g||it.fixed&&at.fixed)return;const At=Tze(it,at);if(it.fixed)at.x=it.x+At[0]*It,at.y=it.y+At[1]*It;else if(at.fixed)it.x=at.x-At[0]*It,it.y=at.y-At[1]*It;else{const mt=H1(it,at);it.x=mt[0]-At[0]*It/2,it.y=mt[1]-At[1]*It/2,at.x=mt[0]+At[0]*It/2,at.y=mt[1]+At[1]*It/2}}if(te.type==="distance"){const Ee=T.get(te.a),se=T.get(te.b);if(!Ee||!se)return;const me=YN(Ee,se)||1;if(W=Math.abs(me-te.value),W<=g)return;const Xe=[(se.x-Ee.x)/me,(se.y-Ee.y)/me];if(Ee.fixed&&se.fixed)return;if(Ee.fixed)se.x=Ee.x+Xe[0]*te.value,se.y=Ee.y+Xe[1]*te.value;else if(se.fixed)Ee.x=se.x-Xe[0]*te.value,Ee.y=se.y-Xe[1]*te.value;else{const it=H1(Ee,se);Ee.x=it[0]-Xe[0]*te.value/2,Ee.y=it[1]-Xe[1]*te.value/2,se.x=it[0]+Xe[0]*te.value/2,se.y=it[1]+Xe[1]*te.value/2}}if(te.type==="length"){const Ee=P.get(te.line);if(!Ee)return;const se=T.get(Ee.a),me=T.get(Ee.b);if(!se||!me)return;const Xe=YN(se,me)||1;if(W=Math.abs(Xe-te.value),W<=g)return;const it=Tze(se,me);if(se.fixed&&me.fixed)return;if(se.fixed)me.x=se.x+it[0]*te.value,me.y=se.y+it[1]*te.value;else if(me.fixed)se.x=me.x-it[0]*te.value,se.y=me.y-it[1]*te.value;else{const at=H1(se,me);se.x=at[0]-it[0]*te.value/2,se.y=at[1]-it[1]*te.value/2,me.x=at[0]+it[0]*te.value/2,me.y=at[1]+it[1]*te.value/2}}if(te.type==="radius"||te.type==="diameter"){const Ee=O.get(te.circle);if(!Ee)return;const se=te.type==="radius"?te.value:te.value/2;if(W=Math.abs(Ee.radius-se),W<=g)return;Ee.fixedRadius||(Ee.radius=se)}if(te.type==="hDistance"){const Ee=T.get(te.a),se=T.get(te.b);if(!Ee||!se||(W=Math.abs(se.x-Ee.x-te.value),W<=g)||Ee.fixed&&se.fixed)return;if(Ee.fixed)se.x=Ee.x+te.value;else if(se.fixed)Ee.x=se.x-te.value;else{const me=(Ee.x+se.x)/2;Ee.x=me-te.value/2,se.x=me+te.value/2}}if(te.type==="vDistance"){const Ee=T.get(te.a),se=T.get(te.b);if(!Ee||!se||(W=Math.abs(se.y-Ee.y-te.value),W<=g)||Ee.fixed&&se.fixed)return;if(Ee.fixed)se.y=Ee.y+te.value;else if(se.fixed)Ee.y=se.y-te.value;else{const me=(Ee.y+se.y)/2;Ee.y=me-te.value/2,se.y=me+te.value/2}}if(te.type==="concentric"){const Ee=O.get(te.a),se=O.get(te.b);if(!Ee||!se)return;const me=T.get(Ee.center),Xe=T.get(se.center);if(!me||!Xe)return;const it=Xe.x-me.x,at=Xe.y-me.y;if(W=Math.sqrt(it*it+at*at),W<=g||me.fixed&&Xe.fixed)return;if(me.fixed)Xe.x=me.x,Xe.y=me.y;else if(Xe.fixed)me.x=Xe.x,me.y=Xe.y;else{const It=H1(me,Xe);me.x=It[0],me.y=It[1],Xe.x=It[0],Xe.y=It[1]}}if(te.type==="collinear"){const Ee=T.get(te.point),se=P.get(te.line);if(!Ee||!se)return;const me=T.get(se.a),Xe=T.get(se.b);if(!me||!Xe)return;const it=oWe(Ee,me,Xe);if(W=Math.sqrt((Ee.x-it[0])**2+(Ee.y-it[1])**2),W<=g)return;if(!Ee.fixed)Ee.x=it[0],Ee.y=it[1];else{const at=it[0]-Ee.x,It=it[1]-Ee.y;me.fixed||z(me,-at,-It),Xe.fixed||z(Xe,-at,-It)}}if(te.type==="symmetric"){const Ee=T.get(te.a),se=T.get(te.b),me=P.get(te.axis);if(!Ee||!se||!me)return;const Xe=T.get(me.a),it=T.get(me.b);if(!Xe||!it)return;const at=Cze(Ee,Xe,it),It=Cze(se,Xe,it);if(W=Math.sqrt((se.x-at[0])**2+(se.y-at[1])**2),W<=g||Ee.fixed&&se.fixed)return;Ee.fixed?(se.x=at[0],se.y=at[1]):se.fixed?(Ee.x=It[0],Ee.y=It[1]):(se.x=at[0],se.y=at[1])}if(te.type==="tangent"){if(te.line&&te.circle){const Ee=P.get(te.line),se=O.get(te.circle);if(!Ee||!se)return;const me=T.get(Ee.a),Xe=T.get(Ee.b),it=T.get(se.center);if(!me||!Xe||!it)return;const at=Xe.x-me.x,It=Xe.y-me.y,tn=Math.sqrt(at*at+It*It)||1,At=-It/tn,mt=at/tn,ht=(it.x-me.x)*At+(it.y-me.y)*mt;if(W=Math.abs(Math.abs(ht)-se.radius),W<=g)return;const xn=ht>0?ht-se.radius:ht+se.radius;!me.fixed||!Xe.fixed?(me.fixed||(me.x+=At*-xn,me.y+=mt*-xn),Xe.fixed||(Xe.x+=At*-xn,Xe.y+=mt*-xn)):it.fixed||(it.x+=At*-xn,it.y+=mt*-xn)}else if(te.a&&te.b){const Ee=O.get(te.a),se=O.get(te.b);if(!Ee||!se)return;const me=T.get(Ee.center),Xe=T.get(se.center);if(!me||!Xe)return;const it=Ee.radius+se.radius,at=YN(me,Xe)||1;if(W=Math.abs(at-it),W<=g)return;const It=[(Xe.x-me.x)/at,(Xe.y-me.y)/at];if(me.fixed&&Xe.fixed)return;if(me.fixed)Xe.x=me.x+It[0]*it,Xe.y=me.y+It[1]*it;else if(Xe.fixed)me.x=Xe.x-It[0]*it,me.y=Xe.y-It[1]*it;else{const tn=H1(me,Xe);me.x=tn[0]-It[0]*it/2,me.y=tn[1]-It[1]*it/2,Xe.x=tn[0]+It[0]*it/2,Xe.y=tn[1]+It[1]*it/2}}}H=Math.max(H,W)}),!(H<=g));re+=1);return{maxError:H}},tEt=(l,o,f)=>{if(o>f*5)return"over";const g=new Map;return l.points.forEach(P=>g.set(P.id,0)),l.constraints.forEach(P=>{if(P.type==="fixed"){const O=g.get(P.point)??0;g.set(P.point,O+2);return}if(P.type==="coincident"||P.type==="distance"||P.type==="hDistance"||P.type==="vDistance"){g.set(P.a,(g.get(P.a)??0)+1),g.set(P.b,(g.get(P.b)??0)+1);return}if(P.type==="collinear"){g.set(P.point,(g.get(P.point)??0)+1);return}if(P.type==="symmetric"){g.set(P.a,(g.get(P.a)??0)+1),g.set(P.b,(g.get(P.b)??0)+1);return}if(P.type==="horizontal"||P.type==="vertical"||P.type==="length"){const O=l.lines.find(z=>z.id===P.line);O&&(g.set(O.a,(g.get(O.a)??0)+1),g.set(O.b,(g.get(O.b)??0)+1));return}if(P.type==="parallel"||P.type==="perpendicular"||P.type==="equal"||P.type==="angle"){const O=l.lines.find(H=>H.id===P.a),z=l.lines.find(H=>H.id===P.b);O&&(g.set(O.a,(g.get(O.a)??0)+1),g.set(O.b,(g.get(O.b)??0)+1)),z&&(g.set(z.a,(g.get(z.a)??0)+1),g.set(z.b,(g.get(z.b)??0)+1));return}}),l.points.some(P=>!P.fixed&&(g.get(P.id)??0)<2)?"under":"fully"};class v2e extends Eo{constructor(o,f,g){super(o),this.constraintMeta=f,this.definition=g}withUpdatedConstraint(o,f){const g=cWe(this.definition),T=g.constraints.find(P=>P.id===o);return T?(Qwt(T,f),uWe(g)):this}}class nEt{constructor(){tu(this,"points",[]);tu(this,"lines",[]);tu(this,"circles",[]);tu(this,"constraints",[]);tu(this,"loops",[]);tu(this,"rejectedConstraints",[]);tu(this,"cursor",null);tu(this,"loopStart",null);tu(this,"nextId",1)}point(o,f,g=!1){const T=`pt-${this.nextId++}`;return this.points.push({id:T,x:o,y:f,fixed:g}),T}pointAt(o){const f=this.points[o];if(!f)throw new Error(`Point index ${o} out of range`);return f.id}line(o,f,g=!1){const T=`ln-${this.nextId++}`;return this.lines.push({id:T,a:o,b:f,construction:g}),T}lineAt(o){const f=this.lines[o];if(!f)throw new Error(`Line index ${o} out of range`);return f.id}circle(o,f,g=!1,T=48){const P=`c-${this.nextId++}`;return this.circles.push({id:P,center:o,radius:f,construction:g,fixedRadius:!1,segments:T}),g||this.loops.push({type:"circle",circle:P}),P}circleAt(o){const f=this.circles[o];if(!f)throw new Error(`Circle index ${o} out of range`);return f.id}moveTo(o,f){const g=this.point(o,f);return this.cursor=g,this.loopStart=g,this.loops.push({type:"poly",points:[g]}),this}lineTo(o,f){if(!this.cursor)return this.moveTo(o,f);const g=this.point(o,f);this.line(this.cursor,g);const T=this.loops[this.loops.length-1];return T&&T.type==="poly"&&T.points.push(g),this.cursor=g,this}lineH(o){const f=this.getPoint(this.cursor);return f?this.lineTo(f.x+o,f.y):this}lineV(o){const f=this.getPoint(this.cursor);return f?this.lineTo(f.x,f.y+o):this}lineAngled(o,f){const g=this.getPoint(this.cursor);if(!g)return this;const T=aWe(f);return this.lineTo(g.x+Math.cos(T)*o,g.y+Math.sin(T)*o)}close(){return!this.cursor||!this.loopStart||this.cursor===this.loopStart?this:(this.line(this.cursor,this.loopStart),this.cursor=this.loopStart,this)}addLoopCircle(o,f,g=48){return this.circle(o,f,!1,g),this}constrain(o){const f=`cst-${this.nextId++}`,g={...o,id:f},T=this.buildDefinition(g),{maxError:P}=lWe(T,{iterations:30,tolerance:Kte});if(P>Kte*5)return this.rejectedConstraints.push(g),this;if(g.type==="fixed"){const O=this.points.find(z=>z.id===g.point);O&&(O.fixed=!0,O.x=g.x,O.y=g.y)}return this.constraints.push(g),this}solve(o={}){return uWe(this.buildDefinition(),o)}buildDefinition(o){return{points:this.points.map(f=>({...f})),lines:this.lines.map(f=>({...f})),circles:this.circles.map(f=>({...f})),loops:this.loops.map(f=>f.type==="poly"?{type:"poly",points:[...f.points]}:{type:"circle",circle:f.circle}),constraints:o?[...this.constraints,o]:[...this.constraints],rejectedConstraints:[...this.rejectedConstraints]}}getPoint(o){return o?this.points.find(f=>f.id===o)??null:null}importPoint(o,f=!1){return this.point(o.x,o.y,f)}importLine(o,f=!1){const g=this.importPoint(o.start,f),T=this.importPoint(o.end,f);return this.line(g,T)}importRectangle(o,f=!1){const[g,T,P,O]=o.vertices.map(z=>this.importPoint(z,f));return{bottom:this.line(g,T),right:this.line(T,P),top:this.line(P,O),left:this.line(O,g),points:[g,T,P,O]}}}function rEt(){return new nEt}const uWe=(l,o={})=>{const f=cWe(l),g=o.tolerance??Kte,{maxError:T}=lWe(f,o),P=tEt(f,T,g),O=new Set(P==="over"?f.constraints.map(W=>W.id):[]),z=wze(f,O),H=wze({...f,constraints:f.rejectedConstraints},new Set(f.rejectedConstraints.map(W=>W.id))),re=Zwt(f),te=Kwt(f);return new v2e(re.cross,{status:P,maxError:T,constraints:z,rejected:H,construction:te},f)};class Q_{constructor(o,f){this.x=o,this.y=f}distanceTo(o){const f=o.x-this.x,g=o.y-this.y;return Math.sqrt(f*f+g*g)}midpointTo(o){return new Q_((this.x+o.x)/2,(this.y+o.y)/2)}translate(o,f){return new Q_(this.x+o,this.y+f)}toTuple(){return[this.x,this.y]}}function iEt(l,o){return new Q_(l,o)}class Eb{constructor(o,f){this.start=o,this.end=f}get length(){return this.start.distanceTo(this.end)}get midpoint(){return this.start.midpointTo(this.end)}get angle(){return Math.atan2(this.end.y-this.start.y,this.end.x-this.start.x)*(180/Math.PI)}get direction(){const o=this.length||1;return[(this.end.x-this.start.x)/o,(this.end.y-this.start.y)/o]}parallel(o){const[f,g]=this.direction,T=-g*o,P=f*o;return new Eb(this.start.translate(T,P),this.end.translate(T,P))}intersect(o){const f=this.start.x,g=this.start.y,T=this.end.x,P=this.end.y,O=o.start.x,z=o.start.y,H=o.end.x,re=o.end.y,te=(f-T)*(z-re)-(g-P)*(O-H);if(Math.abs(te)<1e-12)return null;const W=((f-O)*(z-re)-(g-z)*(O-H))/te;return new Q_(f+W*(T-f),g+W*(P-g))}intersectSegment(o){const f=this.start.x,g=this.start.y,T=this.end.x,P=this.end.y,O=o.start.x,z=o.start.y,H=o.end.x,re=o.end.y,te=(f-T)*(z-re)-(g-P)*(O-H);if(Math.abs(te)<1e-12)return null;const W=((f-O)*(z-re)-(g-z)*(O-H))/te,Ee=-((f-T)*(g-z)-(g-P)*(f-O))/te;return W<-1e-12||W>1+1e-12||Ee<-1e-12||Ee>1+1e-12?null:new Q_(f+W*(T-f),g+W*(P-g))}static fromCoordinates(o,f,g,T){return new Eb(new Q_(o,f),new Q_(g,T))}static fromPointAndAngle(o,f,g){const T=f*(Math.PI/180);return new Eb(o,new Q_(o.x+Math.cos(T)*g,o.y+Math.sin(T)*g))}static fromPointAndDirection(o,f,g){const T=Math.sqrt(f[0]*f[0]+f[1]*f[1])||1;return new Eb(o,new Q_(o.x+f[0]/T*g,o.y+f[1]/T*g))}}function sEt(l,o,f,g){return Eb.fromCoordinates(l,o,f,g)}class GO{constructor(o,f){this.center=o,this.radius=f}get diameter(){return this.radius*2}get circumference(){return 2*Math.PI*this.radius}get area(){return Math.PI*this.radius*this.radius}pointAtAngle(o){const f=o*Math.PI/180;return new Q_(this.center.x+Math.cos(f)*this.radius,this.center.y+Math.sin(f)*this.radius)}translate(o,f){return new GO(this.center.translate(o,f),this.radius)}toSketch(o){const g=nd().CrossSection.circle(this.radius,o??0).translate([this.center.x,this.center.y]);return new Eo(g)}extrude(o,f){const g=this.toSketch(f),T=aT(g,o),P=iWe(this,o);return new po(T.shape,P,o,!0)}static fromCenterAndRadius(o,f){return new GO(o,f)}static fromDiameter(o,f){return new GO(o,f/2)}}function aEt(l,o,f){return new GO(new Q_(l,o),f)}class dC{constructor(o){tu(this,"vertices");this.vertices=o}get width(){return this.vertices[0].distanceTo(this.vertices[1])}get height(){return this.vertices[1].distanceTo(this.vertices[2])}get center(){return this.vertices[0].midpointTo(this.vertices[2])}side(o){const[f,g,T,P]=this.vertices;switch(o){case"bottom":return new Eb(f,g);case"right":return new Eb(g,T);case"top":return new Eb(T,P);case"left":return new Eb(P,f)}}sideAt(o){const f=["bottom","right","top","left"];return this.side(f[o%4])}vertex(o){const[f,g,T,P]=this.vertices;switch(o){case"bottom-left":return f;case"bottom-right":return g;case"top-right":return T;case"top-left":return P}}diagonals(){const[o,f,g,T]=this.vertices;return[new Eb(o,g),new Eb(f,T)]}toSketch(){return Md(this.vertices.map(o=>o.toTuple()))}translate(o,f){return new dC(this.vertices.map(g=>g.translate(o,f)))}static fromDimensions(o,f,g,T){return new dC([new Q_(o,f),new Q_(o+g,f),new Q_(o+g,f+T),new Q_(o,f+T)])}static fromCenterAndDimensions(o,f,g){const T=f/2,P=g/2;return new dC([new Q_(o.x-T,o.y-P),new Q_(o.x+T,o.y-P),new Q_(o.x+T,o.y+P),new Q_(o.x-T,o.y+P)])}static from2Corners(o,f){const g=Math.min(o.x,f.x),T=Math.max(o.x,f.x),P=Math.min(o.y,f.y),O=Math.max(o.y,f.y);return new dC([new Q_(g,P),new Q_(T,P),new Q_(T,O),new Q_(g,O)])}static from3Points(o,f,g){const T=f.x-o.x,P=f.y-o.y,O=Math.sqrt(T*T+P*P)||1,z=T/O,re=-(P/O),te=z,W=(g.x-o.x)*re+(g.y-o.y)*te;return new dC([o,f,new Q_(f.x+re*W,f.y+te*W),new Q_(o.x+re*W,o.y+te*W)])}extrude(o,f=!0){const g=this.toSketch(),T=Math.abs(o),P=aT(g,T),O=f?P.shape:P.shape.translate(0,0,-T),z=rWe(this,T,f);return new po(O,z,T,f)}}function oEt(l,o,f,g){return dC.fromDimensions(l,o,f,g)}function cEt(l){return l}function lEt(l){return l*(180/Math.PI)}function HS(l,o){return typeof o=="string"?o:l.importLine(o)}function RJ(l,o){return typeof o=="string"?o:l.importPoint(o)}const uEt={makeParallel(l,o,f){return l.constrain({type:"parallel",a:HS(l,o),b:HS(l,f)})},enforceAngle(l,o,f,g){return l.constrain({type:"angle",a:HS(l,o),b:HS(l,f),value:g})},horizontal(l,o){return l.constrain({type:"horizontal",line:HS(l,o)})},vertical(l,o){return l.constrain({type:"vertical",line:HS(l,o)})},equalLength(l,o,f){return l.constrain({type:"equal",a:HS(l,o),b:HS(l,f)})},distance(l,o,f,g){return l.constrain({type:"distance",a:RJ(l,o),b:RJ(l,f),value:g})},fix(l,o,f,g){return l.constrain({type:"fixed",point:RJ(l,o),x:f,y:g})},coincident(l,o,f){return l.constrain({type:"coincident",a:RJ(l,o),b:RJ(l,f)})},perpendicular(l,o,f){return l.constrain({type:"perpendicular",a:HS(l,o),b:HS(l,f)})},length(l,o,f){return l.constrain({type:"length",line:HS(l,o),value:f})}},mxe=l=>l instanceof po?l.toShape():l;function _We(l,o,f){return gne(l,hqe(c4(l),qkt(o,f)))}function _Et(l,o,f,g,T=0){const P=mxe(l),O=[];for(let z=0;z<o;z++){const H=z===0?P.clone():P.translate(f*z,g*z,T*z);O.push(_We(H,"linear",z))}return K1(...O)}function fEt(l,o,f=0,g=0){const T=mxe(l),P=360/o,O=[];for(let z=0;z<o;z++){const H=z===0?T.clone():T.translate(-f,-g,0).rotate(0,0,P*z).translate(f,g,0);O.push(_We(H,"circular",z))}return K1(...O)}function pEt(l,o){const f=mxe(l);return K1(f,f.mirror(o))}function fWe(l){return l instanceof po?l.toShape():l}function pWe(l,o){const f=l??[-1,-1],g=Math.sign(f[0]),T=Math.sign(f[1]);if(g!==1&&g!==-1||T!==1&&T!==-1)throw new Error(`${o} requires quadrant signs of either 1 or -1.`);return[g,T]}function dEt(l,o){return o?Qqe(l).some(f=>Pb(f,o)):!0}function dWe(l,o,f){var g;if(!dEt(l,(g=o.query)==null?void 0:g.owner))throw new Error(`${f} requires an edge query owned by the target shape or one of its preserved query ancestors.`)}function mWe(l,o,f,g){if(!l)return null;const T=une(o);return hq(ixe(l,Bkt(o,T,f,g.filter(P=>P!=null))),T)}function hWe(l,o,f){if(!o)throw new Error(`Could not record compiler intent for ${f} on this target shape.`);const g=Yqe(l),T=M_(o,l.colorHex,{backend:g.backend,representation:g.representation,fidelity:g.fidelity,topology:"none",sources:[f,...g.sources]});return Yte(T,fxe(l)),mne(T,Xqe(l),{merge:!1}),hne(T,{backend:g.backend,representation:g.representation,fidelity:g.fidelity,topology:"none",sources:[f,...g.sources]}),T}function mEt(l,o,f,g=[-1,-1],T=16){if(!Number.isFinite(f)||!(f>0))throw new Error("filletEdge() requires a positive finite radius.");if(!Number.isFinite(T)||T<2)throw new Error("filletEdge() requires at least 2 segments.");const P=fWe(l);dWe(P,o,"filletEdge()");const O=c4(P);if(!O)throw new Error("filletEdge() currently requires a compile-covered target shape.");const z=pWe(g,"filletEdge()"),H=lI(O,o.query);if(!H.ok)throw new Error(`filletEdge(): ${H.issue.reason}`);const re=zqe(O,o.query);if(H.selection.quadrant[0]!==z[0]||H.selection.quadrant[1]!==z[1])throw new Error(`filletEdge() currently supports ${H.selection.edgeName} only with quadrant [${H.selection.quadrant[0]}, ${H.selection.quadrant[1]}].`);const te=mWe(ITt(O,H.query,f,z,Math.round(T)),"fillet",H.query,re);return hWe(P,te,"fillet")}function hEt(l,o,f,g=[-1,-1]){if(!Number.isFinite(f)||!(f>0))throw new Error("chamferEdge() requires a positive finite size.");const T=fWe(l);dWe(T,o,"chamferEdge()");const P=c4(T);if(!P)throw new Error("chamferEdge() currently requires a compile-covered target shape.");const O=pWe(g,"chamferEdge()"),z=lI(P,o.query);if(!z.ok)throw new Error(`chamferEdge(): ${z.issue.reason}`);const H=zqe(P,o.query);if(z.selection.quadrant[0]!==O[0]||z.selection.quadrant[1]!==O[1])throw new Error(`chamferEdge() currently supports ${z.selection.edgeName} only with quadrant [${z.selection.quadrant[0]}, ${z.selection.quadrant[1]}].`);const re=mWe(FTt(P,z.query,f,O),"chamfer",z.query,H);return hWe(T,re,"chamfer")}const QD=1e-8;function gEt(l){return Array.isArray(l)?[l[0],l[1]]:[l.x,l.y]}function b2e(l,o){const f=o[0]-l[0],g=o[1]-l[1];return Math.hypot(f,g)}function Obe(l,o){const f=Math.hypot(l,o);if(f<=QD)throw new Error("filletCorners requires non-degenerate edges");return[l/f,o/f]}function yEt(l,o,f){return Math.max(o,Math.min(f,l))}function vEt(l){let o=0;for(let f=0;f<l.length;f+=1){const[g,T]=l[f],[P,O]=l[(f+1)%l.length];o+=g*O-P*T}return o/2}function bEt(l){return Math.max(3,Math.ceil(Math.abs(l)/(Math.PI/15)))}function Eze(l,o,f=1e-6){return Math.abs(l[0]-o[0])<=f&&Math.abs(l[1]-o[1])<=f}function xEt(l,o,f){const g=l.length;if(!Number.isInteger(o.index)||o.index<0||o.index>=g)throw new Error(`filletCorners corner index ${o.index} is out of range for ${g} points`);if(!(o.radius>0))throw new Error(`filletCorners corner ${o.index} must have a positive radius`);const T=l[(o.index-1+g)%g],P=l[o.index],O=l[(o.index+1)%g],z=b2e(T,P),H=b2e(P,O),[re,te]=Obe(P[0]-T[0],P[1]-T[1]),[W,Ee]=Obe(O[0]-P[0],O[1]-P[1]);if((re*Ee-te*W)*f<=QD)throw new Error(`filletCorners corner ${o.index} is concave or collinear; only convex corners are supported`);const me=[-re,-te],Xe=[W,Ee],it=Math.acos(yEt(me[0]*Xe[0]+me[1]*Xe[1],-1,1));if(it<=QD||it>=Math.PI-QD)throw new Error(`filletCorners corner ${o.index} has an unsupported angle`);const at=o.radius/Math.tan(it/2);if(at>=z-QD||at>=H-QD){const zn=Math.min(z,H)*Math.tan(it/2);throw new Error(`filletCorners radius ${o.radius} is too large for corner ${o.index}; max is ${zn.toFixed(3)}`)}const It=[P[0]-re*at,P[1]-te*at],tn=[P[0]+W*at,P[1]+Ee*at],[At,mt]=Obe(me[0]+Xe[0],me[1]+Xe[1]),ht=o.radius/Math.sin(it/2),xn=[P[0]+At*ht,P[1]+mt*ht],Pn=o.segments==null?bEt(it):Math.round(o.segments),$r=Math.max(2,Pn);return{radius:o.radius,tangentDistance:at,segments:$r,start:It,end:tn,center:xn,startAngle:Math.atan2(It[1]-xn[1],It[0]-xn[0]),sweep:f*it}}function SEt(l,o){var H,re;if(l.length<3)throw new Error("filletCorners requires at least 3 points");if(o.length===0)return Md(l);const f=l.map(gEt),g=vEt(f);if(Math.abs(g)<=QD)throw new Error("filletCorners requires a non-degenerate polygon");const T=Math.sign(g),P=new Map;for(const te of o){if(P.has(te.index))throw new Error(`filletCorners corner ${te.index} is specified more than once`);P.set(te.index,xEt(f,te,T))}for(let te=0;te<f.length;te+=1){const W=(te+1)%f.length,Ee=b2e(f[te],f[W]),se=((H=P.get(te))==null?void 0:H.tangentDistance)??0,me=((re=P.get(W))==null?void 0:re.tangentDistance)??0;if(se+me>=Ee-QD)throw new Error(`filletCorners adjacent fillets overlap on edge ${te} -> ${W}; reduce one of the radii`)}const O=[],z=te=>{(O.length===0||!Eze(O[O.length-1],te))&&O.push(te)};for(let te=0;te<f.length;te+=1){const W=P.get(te);if(W==null){z(f[te]);continue}z(W.start);for(let Ee=1;Ee<W.segments;Ee+=1){const se=W.startAngle+W.sweep*Ee/W.segments;z([W.center[0]+Math.cos(se)*W.radius,W.center[1]+Math.sin(se)*W.radius])}z(W.end)}return O.length>=2&&Eze(O[0],O[O.length-1])&&O.pop(),Md(O)}function ene(l,o){return[l[0]-o[0],l[1]-o[1],l[2]-o[2]]}function Pze(l,o){return[l[0]+o[0],l[1]+o[1],l[2]+o[2]]}function x2e(l,o){return[l[0]*o,l[1]*o,l[2]*o]}function QE(l,o){return l[0]*o[0]+l[1]*o[1]+l[2]*o[2]}function TEt(l,o){return[l[1]*o[2]-l[2]*o[1],l[2]*o[0]-l[0]*o[2],l[0]*o[1]-l[1]*o[0]]}function hxe(l){return Math.sqrt(QE(l,l))}function S2e(l){const o=hxe(l)||1;return[l[0]/o,l[1]/o,l[2]/o]}function Dze(l,o){return[(l[0]+o[0])/2,(l[1]+o[1])/2,(l[2]+o[2])/2]}function Aze(l){if(l instanceof dC){const[o,f,g,T]=l.vertices;return{corners:[[o.x,o.y,0],[f.x,f.y,0],[g.x,g.y,0],[T.x,T.y,0]]}}return l}function Nze(l,o){const[f,g,T,P]=l.corners;return[{name:`${o}-bottom`,start:f,end:g},{name:`${o}-right`,start:g,end:T},{name:`${o}-top`,start:T,end:P},{name:`${o}-left`,start:P,end:f}]}function tne(l){return S2e(ene(l.end,l.start))}function kEt(l,o,f){const g=tne(l),T=tne(o);if(!(Math.abs(QE(g,T))>.999))throw new Error("Inner edges are not parallel");const O=QE(l.start,g),z=QE(l.end,g),H=QE(o.start,g),re=QE(o.end,g),te=Math.min(O,z),W=Math.max(O,z),Ee=Math.min(H,re),se=Math.max(H,re),me=Math.max(te,Ee),it=Math.min(W,se)-me;if(it<1e-6)throw new Error("Inner edges do not overlap along their direction");const at=Pze(l.start,x2e(g,me-O)),It=Pze(o.start,x2e(g,me-H)),tn=ene(It,at),At=QE(tn,g),mt=[tn[0]-g[0]*At,tn[1]-g[1]*At,tn[2]-g[2]*At],ht=hxe(mt);if(ht<1e-6)throw new Error("Edges are coincident — no arc to build");const xn=S2e(mt),Pn=S2e(TEt(g,xn)),$r=ht/2,zn=[ht/2,0],ii=[];for(let Hs=0;Hs<=f;Hs++){const Ua=Math.PI*Hs/f,Di=zn[0]-$r*Math.cos(Ua),ko=$r*Math.sin(Ua);ii.push([Di,ko])}const Gr=Math.max(.5,ht*.02),mn=[];for(let Hs=f;Hs>=0;Hs--){const Ua=Math.PI*Hs/f,Di=$r-Gr,ko=zn[0]-Di*Math.cos(Ua),K_=Di*Math.sin(Ua);mn.push([ko,K_])}const $s=Md([...ii,...mn]),is=aT($s,it).toShape(),Wt=at,Es=[xn[0],xn[1],xn[2],0,Pn[0],Pn[1],Pn[2],0,g[0],g[1],g[2],0,Wt[0],Wt[1],Wt[2],1];return is.transform(Es)}function CEt(l,o,f=12){const g=Aze(l),T=Aze(o),P=Nze(g,"a"),O=Nze(T,"b");let z=null;for(const H of P){const re=tne(H);for(const te of O){const W=tne(te);if(Math.abs(QE(re,W))<.999)continue;const Ee=Dze(H.start,H.end),se=Dze(te.start,te.end),me=ene(se,Ee),Xe=QE(me,re),it=ene(me,x2e(re,Xe)),at=hxe(it);at<1e-6||(!z||at<z.dist)&&(z={edgeA:H,edgeB:te,dist:at})}}if(!z)throw new Error("No parallel inner edges found between the two rectangles");return kEt(z.edgeA,z.edgeB,f)}let nI=[],T2e=0;function wEt(){nI=[],T2e=0}function k2e(){return nI}function EEt(l){const o=Math.max(0,Math.min(l,nI.length)),f=nI.slice(o);return nI=nI.slice(0,o),f}function Ize(l){return l instanceof Q_?[l.x,l.y,0]:l.length===2?[l[0],l[1],0]:[l[0],l[1],l[2]]}function gWe(l,o,f){T2e++;const g=(()=>{if(typeof(f==null?void 0:f.component)=="string"){const T=f.component.trim();return T?[T]:void 0}if(Array.isArray(f==null?void 0:f.component)){const T=Array.from(new Set(f.component.map(P=>typeof P=="string"?P.trim():"").filter(Boolean)));return T.length>0?T:void 0}})();nI.push({id:`dim-${T2e}`,from:Ize(l),to:Ize(o),offset:(f==null?void 0:f.offset)??10,autoOffset:(f==null?void 0:f.offset)===void 0,label:f==null?void 0:f.label,color:f==null?void 0:f.color,components:g,currentComponent:!!(f!=null&&f.currentComponent)})}function PEt(l,o){gWe([l.start.x,l.start.y],[l.end.x,l.end.y],o)}function GJ(l,o,f){return Math.max(o,Math.min(f,l))}function DEt(l,o){return[l[0]+o[0],l[1]+o[1],l[2]+o[2]]}function C2e(l,o){return[l[0]-o[0],l[1]-o[1],l[2]-o[2]]}function Fze(l,o){return[l[0]*o,l[1]*o,l[2]*o]}function AEt(l,o){return l[0]*o[0]+l[1]*o[1]+l[2]*o[2]}function gxe(l){return Math.sqrt(AEt(l,l))}function NEt(l){const o=gxe(l);return o<1e-9?[0,0,1]:[l[0]/o,l[1]/o,l[2]/o]}function Oze(l,o,f,g,T,P){const O=T*T,z=O*T,H=(1-P)*.5,re=(f[0]-l[0])*H,te=(f[1]-l[1])*H,W=(g[0]-o[0])*H,Ee=(g[1]-o[1])*H,se=2*z-3*O+1,me=z-2*O+T,Xe=-2*z+3*O,it=z-O;return[se*o[0]+me*re+Xe*f[0]+it*W,se*o[1]+me*te+Xe*f[1]+it*Ee]}function Mze(l,o,f,g,T,P){const O=T*T,z=O*T,H=(1-P)*.5,re=[(f[0]-l[0])*H,(f[1]-l[1])*H,(f[2]-l[2])*H],te=[(g[0]-o[0])*H,(g[1]-o[1])*H,(g[2]-o[2])*H],W=2*z-3*O+1,Ee=z-2*O+T,se=-2*z+3*O,me=z-O;return[W*o[0]+Ee*re[0]+se*f[0]+me*te[0],W*o[1]+Ee*re[1]+se*f[1]+me*te[1],W*o[2]+Ee*re[2]+se*f[2]+me*te[2]]}function IEt(l,o,f,g){if(l.length<2)throw new Error("spline2d requires at least 2 points");const T=l.length,P=[],O=o?T:T-1;for(let z=0;z<O;z++){const H=l[(z-1+T)%T],re=l[z%T],te=l[(z+1)%T],W=l[(z+2)%T];if(!o){const Ee=z===0?re:H,se=z===T-2?te:W;for(let me=0;me<f;me++){const Xe=me/f;P.push(Oze(Ee,re,te,se,Xe,g))}continue}for(let Ee=0;Ee<f;Ee++){const se=Ee/f;P.push(Oze(H,re,te,W,se,g))}}return o||P.push(l[T-1]),P}function FEt(l,o,f,g){if(l.length<2)throw new Error("spline3d requires at least 2 points");const T=l.length,P=[],O=o?T:T-1;for(let z=0;z<O;z++){const H=l[(z-1+T)%T],re=l[z%T],te=l[(z+1)%T],W=l[(z+2)%T];if(!o){const Ee=z===0?re:H,se=z===T-2?te:W;for(let me=0;me<f;me++){const Xe=me/f;P.push(Mze(Ee,re,te,se,Xe,g))}continue}for(let Ee=0;Ee<f;Ee++){const se=Ee/f;P.push(Mze(H,re,te,W,se,g))}}return o||P.push(l[T-1]),P}class yWe{constructor(o,f={}){tu(this,"points");tu(this,"closed");tu(this,"tension");if(o.length<2)throw new Error("Curve3D needs at least 2 points");this.points=o.map(g=>[g[0],g[1],g[2]]),this.closed=f.closed??!1,this.tension=GJ(f.tension??.5,0,1)}sampleBySegment(o=16){const f=Math.max(3,Math.floor(o));return FEt(this.points,this.closed,f,this.tension)}sample(o=64){const f=Math.max(2,Math.floor(o)),g=Math.max(3,Math.ceil(f/Math.max(1,this.points.length-(this.closed?0:1)))),T=this.sampleBySegment(g);if(T.length<=f)return T;const P=[];for(let O=0;O<f;O++){const z=Math.round(O/(f-1)*(T.length-1));P.push(T[z])}return P}pointAt(o){const f=this.sample(200),T=GJ(o,0,1)*(f.length-1),P=Math.floor(T),O=Math.min(f.length-1,P+1),z=T-P;return DEt(Fze(f[P],1-z),Fze(f[O],z))}tangentAt(o){const g=this.pointAt(GJ(o-.001,0,1)),T=this.pointAt(GJ(o+.001,0,1));return NEt(C2e(T,g))}length(o=200){const f=this.sample(o);let g=0;for(let T=1;T<f.length;T++)g+=gxe(C2e(f[T],f[T-1]));return g}}function OEt(l,o={}){const f=o.closed??!0,g=GJ(o.tension??.5,0,1),T=JSt(o.samplesPerSegment??16),P=IEt(l,f,T,g);if(f)return Md(P);if(o.strokeWidth==null||o.strokeWidth<=0)throw new Error("spline2d: open spline requires options.strokeWidth > 0 to create a solid Sketch");return dxe(P,o.strokeWidth,o.join??"Round")}function MEt(l,o={}){return new yWe(l,o)}function LEt(l,o,f={}){var tn;if(l.length<2)throw new Error("loft requires at least two profiles");if(l.length!==o.length)throw new Error("loft requires heights.length === profiles.length");const g=l.map((At,mt)=>({profile:At,z:o[mt]})).sort((At,mt)=>At.z-mt.z);for(let At=1;At<g.length;At++)if(Math.abs(g[At].z-g[At-1].z)<1e-8)throw new Error("loft requires strictly increasing, unique heights");const T=g.map(At=>At.z);let P=1/0,O=1/0,z=-1/0,H=-1/0;for(const At of g){const mt=At.profile.bounds();P=Math.min(P,mt.min[0]),O=Math.min(O,mt.min[1]),z=Math.max(z,mt.max[0]),H=Math.max(H,mt.max[1])}const re=T[0],te=T[T.length-1],W=Math.max(z-P,H-O,te-re,1),Ee=f.edgeLength??Math.max(.35,W/90),se=GJe(Ee),me=f.boundsPadding??Math.max(se*3,W*.06,1.5),Xe=XJe(me),it=OTt(g.map(At=>um(At.profile)),T,{edgeLength:se,boundsPadding:Xe}),at=s6(it,"loft");if(at)return M_(at,(tn=g[0])==null?void 0:tn.profile.colorHex,{fidelity:"sampled",sources:["loft","level-set"]});const It=Cqe(g.map(At=>At.profile.toPolygons()),T,{edgeLength:se,boundsPadding:Xe});return hne(pxe(It.sdf,It.bounds,It.edgeLength),{fidelity:"sampled",sources:["loft","level-set"]})}function REt(l,o,f={}){const g=Math.max(4,f.samples??48),T=qSt(g),P=Array.isArray(o)?o:o.sample(T);if(P.length<2)throw new Error("sweep requires a path with at least two points");const O=f.up??[0,0,1],z=l.bounds(),H=Math.max(Math.abs(z.min[0]),Math.abs(z.max[0]),Math.abs(z.min[1]),Math.abs(z.max[1]));let re=1/0,te=1/0,W=1/0,Ee=-1/0,se=-1/0,me=-1/0;for(const Pn of P)re=Math.min(re,Pn[0]),te=Math.min(te,Pn[1]),W=Math.min(W,Pn[2]),Ee=Math.max(Ee,Pn[0]),se=Math.max(se,Pn[1]),me=Math.max(me,Pn[2]);let Xe=0;for(let Pn=1;Pn<P.length;Pn++)Xe+=gxe(C2e(P[Pn],P[Pn-1]));const it=Math.max(Ee-re,se-te,me-W,Xe,1),at=f.edgeLength??Math.max(.3,it/110),It=GJe(at),tn=f.boundsPadding??Math.max(H+It*2,it*.04,2),At=XJe(tn),mt=MTt(um(l),{kind:"polyline",points:P.map(([Pn,$r,zn])=>[Pn,$r,zn])},{edgeLength:It,boundsPadding:At,up:O}),ht=s6(mt,"sweep");if(ht)return M_(ht,l.colorHex,{fidelity:"sampled",sources:["sweep","level-set"]});const xn=wqe(l.toPolygons(),P.map(([Pn,$r,zn])=>[Pn,$r,zn]),{edgeLength:It,boundsPadding:At,up:O});return hne(pxe(xn.sdf,xn.bounds,xn.edgeLength),{fidelity:"sampled",sources:["sweep","level-set"]})}const vWe=1e-7,ku=1e-9,jEt={fill:"black",stroke:"none",strokeWidth:1,fillRule:"nonzero",strokeJoin:"miter",display:"inline",visibility:"visible",opacity:1,fillOpacity:1,strokeOpacity:1},BEt={px:1,pt:96/72,pc:16,in:96,cm:96/2.54,mm:96/25.4,q:96/101.6};function _I(l,o,f){return Math.max(o,Math.min(f,l))}function qD(l){return l*l}function iI(l,o){return Math.hypot(l[0]-o[0],l[1]-o[1])}function yxe(l){let o=0;for(let f=0;f<l.length;f+=1){const[g,T]=l[f],[P,O]=l[(f+1)%l.length];o+=g*O-P*T}return o*.5}function zEt(l){if(l.length===0)return[0,0];let o=0,f=0;for(const[g,T]of l)o+=g,f+=T;return[o/l.length,f/l.length]}function bWe(l){let o=0,f=0,g=0;for(let P=0;P<l.length;P+=1){const[O,z]=l[P],[H,re]=l[(P+1)%l.length],te=O*re-H*z;g+=te,o+=(O+H)*te,f+=(z+re)*te}if(Math.abs(g)<ku)return zEt(l);const T=1/(3*g);return[o*T,f*T]}function xWe(l,o){const[f,g]=l;let T=!1;for(let P=0,O=o.length-1;P<o.length;O=P++){const[z,H]=o[P],[re,te]=o[O];H>g!=te>g&&f<(re-z)*(g-H)/(te-H||1e-20)+z&&(T=!T)}return T}function qO(){return[1,0,0,1,0,0]}function sI(l,o){const[f,g,T,P,O,z]=l,[H,re,te,W,Ee,se]=o;return[f*H+T*re,g*H+P*re,f*te+T*W,g*te+P*W,f*Ee+T*se+O,g*Ee+P*se+z]}function JEt(l,o){const[f,g,T,P,O,z]=l,[H,re]=o;return[f*H+T*re+O,g*H+P*re+z]}function Dte(l,o){return[1,0,0,1,l,o]}function w2e(l,o){return[l,0,0,o,0,0]}function Lze(l){const o=l*Math.PI/180,f=Math.cos(o),g=Math.sin(o);return[f,g,-g,f,0,0]}function qEt(l){const o=l*Math.PI/180;return[1,0,Math.tan(o),1,0,0]}function WEt(l){const o=l*Math.PI/180;return[1,Math.tan(o),0,1,0,0]}function Mm(l,o=NaN){if(typeof l!="string")return o;const f=l.trim();if(!f)return o;const g=f.match(/^([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)([a-z%]*)$/i);if(!g)return o;const T=Number(g[1]);if(!Number.isFinite(T))return o;const P=g[2].toLowerCase();return P===""||P==="px"?T:P==="%"?o:T*(BEt[P]??1)}function vxe(l){if(!l)return[];const o=[],f=/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g;let g;for(;(g=f.exec(l))!==null;){const T=Number(g[0]);Number.isFinite(T)&&o.push(T)}return o}function VEt(l){return l.replace(/&(#x?[0-9a-fA-F]+|amp|lt|gt|quot|apos);/g,(o,f)=>{switch(f){case"amp":return"&";case"lt":return"<";case"gt":return">";case"quot":return'"';case"apos":return"'";default:if(f.startsWith("#x")||f.startsWith("#X")){const g=Number.parseInt(f.slice(2),16);return Number.isFinite(g)?String.fromCodePoint(g):""}if(f.startsWith("#")){const g=Number.parseInt(f.slice(1),10);return Number.isFinite(g)?String.fromCodePoint(g):""}return""}})}function UEt(l){const o={},f=/([:@A-Za-z_][\w:.-]*)\s*=\s*("([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/g;let g;for(;(g=f.exec(l))!==null;){const T=g[1],P=g[3]??g[4]??g[5]??"";o[T]=VEt(P)}return o}function $Et(l){const o={};return l&&l.split(";").forEach(f=>{const g=f.indexOf(":");if(g<0)return;const T=f.slice(0,g).trim().toLowerCase(),P=f.slice(g+1).trim();T&&(o[T]=P)}),o}function HEt(l,o){return l?l.trim().toLowerCase()==="evenodd"?"evenodd":"nonzero":o}function GEt(l,o){if(!l)return o;const f=l.trim().toLowerCase();return f==="round"||f==="bevel"?f:"miter"}function Mbe(l,o){const f=Mm(l,NaN);return Number.isFinite(f)?_I(f,0,1):o}function Kee(l,o){if(typeof l!="string")return o;const f=l.trim().toLowerCase();return f||o}function XEt(l,o){const f={...l},g=$Et(o.style),T=O=>g[O]??o[O];f.fill=Kee(T("fill"),f.fill),f.stroke=Kee(T("stroke"),f.stroke);const P=Mm(T("stroke-width"),NaN);return Number.isFinite(P)&&P>=0&&(f.strokeWidth=P),f.fillRule=HEt(T("fill-rule"),f.fillRule),f.strokeJoin=GEt(T("stroke-linejoin"),f.strokeJoin),f.display=Kee(T("display"),f.display),f.visibility=Kee(T("visibility"),f.visibility),f.opacity=Mbe(T("opacity"),f.opacity),f.fillOpacity=Mbe(T("fill-opacity"),f.fillOpacity),f.strokeOpacity=Mbe(T("stroke-opacity"),f.strokeOpacity),f}function YEt(l){if(!l)return qO();const o=l.trim();if(!o)return qO();const f=/([a-zA-Z]+)\s*\(([^)]*)\)/g;let g,T=qO();for(;(g=f.exec(o))!==null;){const P=g[1].toLowerCase(),O=vxe(g[2]);let z=qO();P==="matrix"&&O.length>=6?z=[O[0],O[1],O[2],O[3],O[4],O[5]]:P==="translate"&&O.length>=1?z=Dte(O[0],O.length>=2?O[1]:0):P==="scale"&&O.length>=1?z=w2e(O[0],O.length>=2?O[1]:O[0]):P==="rotate"&&O.length>=1?O.length>=3?z=sI(Dte(O[1],O[2]),sI(Lze(O[0]),Dte(-O[1],-O[2]))):z=Lze(O[0]):P==="skewx"&&O.length>=1?z=qEt(O[0]):P==="skewy"&&O.length>=1&&(z=WEt(O[0])),T=sI(z,T)}return T}function Vg(l,o){if(l.length===0){l.push([o[0],o[1]]);return}const f=l[l.length-1];iI(f,o)>vWe&&l.push([o[0],o[1]])}function yI(l){return l.length<=1?l:iI(l[0],l[l.length-1])<=vWe?l.slice(0,-1):l}function Rze(l,o,f,g,T){const P=iI(l,o)+iI(o,f)+iI(f,g),O=_I(Math.ceil(P/Math.max(T,1e-4)),4,512),z=[];for(let H=1;H<=O;H+=1){const re=H/O,te=1-re,W=te*te*te*l[0]+3*te*te*re*o[0]+3*te*re*re*f[0]+re*re*re*g[0],Ee=te*te*te*l[1]+3*te*te*re*o[1]+3*te*re*re*f[1]+re*re*re*g[1];z.push([W,Ee])}return z}function jze(l,o,f,g){const T=iI(l,o)+iI(o,f),P=_I(Math.ceil(T/Math.max(g,1e-4)),4,512),O=[];for(let z=1;z<=P;z+=1){const H=z/P,re=1-H,te=re*re*l[0]+2*re*H*o[0]+H*H*f[0],W=re*re*l[1]+2*re*H*o[1]+H*H*f[1];O.push([te,W])}return O}function Bze(l,o,f,g){const T=l*f+o*g,P=l*g-o*f;return Math.atan2(P,T)}function QEt(l,o,f,g,T,P,O,z,H,re,te){let W=Math.abs(f),Ee=Math.abs(g);if(W<ku||Ee<ku)return[[z,H]];const se=T*Math.PI/180,me=Math.cos(se),Xe=Math.sin(se),it=(l-z)/2,at=(o-H)/2,It=me*it+Xe*at,tn=-Xe*it+me*at,At=qD(It)/qD(W)+qD(tn)/qD(Ee);if(At>1){const xi=Math.sqrt(At);W*=xi,Ee*=xi}const mt=qD(W),ht=qD(Ee),xn=qD(It),Pn=qD(tn);let $r=mt*ht-mt*Pn-ht*xn,zn=mt*Pn+ht*xn;zn<ku&&(zn=ku),$r=Math.max(0,$r);const ii=(P===O?-1:1)*Math.sqrt($r/zn),Gr=ii*(W*tn/Ee),mn=ii*(-(Ee*It)/W),$s=me*Gr-Xe*mn+(l+z)/2,is=Xe*Gr+me*mn+(o+H)/2,Wt=(It-Gr)/W,Es=(tn-mn)/Ee,Hs=(-It-Gr)/W,Ua=(-tn-mn)/Ee;let Di=Bze(1,0,Wt,Es),ko=Bze(Wt,Es,Hs,Ua);!O&&ko>0&&(ko-=Math.PI*2),O&&ko<0&&(ko+=Math.PI*2);const K_=Math.max(W,Ee),Cu=Math.max(te,Math.ceil(Math.abs(ko)*K_/Math.max(re,1e-4))),El=[];for(let xi=1;xi<=Cu;xi+=1){const yf=xi/Cu,j0=Di+ko*yf,Bm=Math.cos(j0),a6=Math.sin(j0),B0=me*W*Bm-Xe*Ee*a6+$s,zy=Xe*W*Bm+me*Ee*a6+is;El.push([B0,zy])}return El}function ZEt(l,o){return l.map(f=>{const g=[];for(const T of f.points)Vg(g,JEt(o,T));return{points:g,closed:f.closed}})}function KEt(l,o,f){const g=l.match(/[AaCcHhLlMmQqSsTtVvZz]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[],T=[];let P=0,O="",z=0,H=0,re=0,te=0,W=null,Ee=null,se=null;const me=at=>{if(!W)return;const It=yI(W.points);It.length>=2&&T.push({points:It,closed:at}),W=null},Xe=()=>{W||(W={points:[[z,H]],closed:!1})},it=()=>{if(P>=g.length)return null;const at=g[P];if(/^[AaCcHhLlMmQqSsTtVvZz]$/.test(at))return null;P+=1;const It=Number(at);return Number.isFinite(It)?It:null};for(;P<g.length;){if(/^[AaCcHhLlMmQqSsTtVvZz]$/.test(g[P]))O=g[P],P+=1;else if(!O){P+=1;continue}switch(O){case"M":case"m":{let at=!0;for(;;){const It=it(),tn=it();if(It==null||tn==null)break;const At=O==="m"?z+It:It,mt=O==="m"?H+tn:tn;at?(me(!1),W={points:[[At,mt]],closed:!1},z=At,H=mt,re=At,te=mt,at=!1):(Xe(),Vg(W.points,[At,mt]),z=At,H=mt)}Ee=null,se=null;break}case"L":case"l":{for(;;){const at=it(),It=it();if(at==null||It==null)break;const tn=O==="l"?z+at:at,At=O==="l"?H+It:It;Xe(),Vg(W.points,[tn,At]),z=tn,H=At}Ee=null,se=null;break}case"H":case"h":{for(;;){const at=it();if(at==null)break;const It=O==="h"?z+at:at;Xe(),Vg(W.points,[It,H]),z=It}Ee=null,se=null;break}case"V":case"v":{for(;;){const at=it();if(at==null)break;const It=O==="v"?H+at:at;Xe(),Vg(W.points,[z,It]),H=It}Ee=null,se=null;break}case"C":case"c":{for(;;){const at=it(),It=it(),tn=it(),At=it(),mt=it(),ht=it();if(at==null||It==null||tn==null||At==null||mt==null||ht==null)break;const xn=[z,H],Pn=[O==="c"?z+at:at,O==="c"?H+It:It],$r=[O==="c"?z+tn:tn,O==="c"?H+At:At],zn=[O==="c"?z+mt:mt,O==="c"?H+ht:ht];Xe(),Rze(xn,Pn,$r,zn,o).forEach(ii=>Vg(W.points,ii)),z=zn[0],H=zn[1],Ee=$r,se=null}break}case"S":case"s":{for(;;){const at=it(),It=it(),tn=it(),At=it();if(at==null||It==null||tn==null||At==null)break;const mt=[z,H],ht=Ee?[2*z-Ee[0],2*H-Ee[1]]:[z,H],xn=[O==="s"?z+at:at,O==="s"?H+It:It],Pn=[O==="s"?z+tn:tn,O==="s"?H+At:At];Xe(),Rze(mt,ht,xn,Pn,o).forEach($r=>Vg(W.points,$r)),z=Pn[0],H=Pn[1],Ee=xn,se=null}break}case"Q":case"q":{for(;;){const at=it(),It=it(),tn=it(),At=it();if(at==null||It==null||tn==null||At==null)break;const mt=[z,H],ht=[O==="q"?z+at:at,O==="q"?H+It:It],xn=[O==="q"?z+tn:tn,O==="q"?H+At:At];Xe(),jze(mt,ht,xn,o).forEach(Pn=>Vg(W.points,Pn)),z=xn[0],H=xn[1],se=ht,Ee=null}break}case"T":case"t":{for(;;){const at=it(),It=it();if(at==null||It==null)break;const tn=[z,H],At=se?[2*z-se[0],2*H-se[1]]:[z,H],mt=[O==="t"?z+at:at,O==="t"?H+It:It];Xe(),jze(tn,At,mt,o).forEach(ht=>Vg(W.points,ht)),z=mt[0],H=mt[1],se=At,Ee=null}break}case"A":case"a":{for(;;){const at=it(),It=it(),tn=it(),At=it(),mt=it(),ht=it(),xn=it();if(at==null||It==null||tn==null||At==null||mt==null||ht==null||xn==null)break;const Pn=O==="a"?z+ht:ht,$r=O==="a"?H+xn:xn;Xe(),QEt(z,H,at,It,tn,Math.abs(At)>=.5,Math.abs(mt)>=.5,Pn,$r,o,f).forEach(zn=>Vg(W.points,zn)),z=Pn,H=$r,Ee=null,se=null}break}case"Z":case"z":{W&&Vg(W.points,[re,te]),me(!0),z=re,H=te,Ee=null,se=null;break}default:{Ee=null,se=null;break}}}return me(!1),T}function zze(l,o,f,g,T){if(!(f>ku)||!(g>ku))return[];const P=2*Math.PI*Math.max(f,g),O=_I(Math.ceil(P/Math.max(T,1e-4)),16,720),z=[];for(let H=0;H<O;H+=1){const re=2*Math.PI*H/O;z.push([l+f*Math.cos(re),o+g*Math.sin(re)])}return[{points:z,closed:!0}]}function ete(l,o,f,g,T,P,O,z){const H=Math.abs(O-P),re=_I(Math.ceil(H*Math.max(g,T)/Math.max(z,1e-4)),2,180);for(let te=1;te<=re;te+=1){const W=P+H*te/re*Math.sign(O-P);Vg(l,[o+g*Math.cos(W),f+T*Math.sin(W)])}}function e6t(l,o,f,g,T,P,O){const z=f,H=g;if(!(z>ku)||!(H>ku))return[];const re=_I(T,0,z/2),te=_I(P,0,H/2);if(re<ku||te<ku)return[{points:[[l,o],[l+z,o],[l+z,o+H],[l,o+H]],closed:!0}];const W=[];return Vg(W,[l+re,o]),Vg(W,[l+z-re,o]),ete(W,l+z-re,o+te,re,te,-Math.PI/2,0,O),Vg(W,[l+z,o+H-te]),ete(W,l+z-re,o+H-te,re,te,0,Math.PI/2,O),Vg(W,[l+re,o+H]),ete(W,l+re,o+H-te,re,te,Math.PI/2,Math.PI,O),Vg(W,[l,o+te]),ete(W,l+re,o+te,re,te,Math.PI,3*Math.PI/2,O),[{points:yI(W),closed:!0}]}function Jze(l){const o=vxe(l),f=[];for(let g=0;g+1<o.length;g+=2)f.push([o[g],o[g+1]]);return yI(f)}function t6t(l,o,f,g){const T=l.toLowerCase();if(T==="path"){const P=o.d??"";return P.trim()?KEt(P,f,g):[]}if(T==="rect"){const P=Mm(o.x,0),O=Mm(o.y,0),z=Mm(o.width,NaN),H=Mm(o.height,NaN);if(!(z>ku)||!(H>ku))return[];let re=Mm(o.rx,NaN),te=Mm(o.ry,NaN);return!Number.isFinite(re)&&Number.isFinite(te)&&(re=te),!Number.isFinite(te)&&Number.isFinite(re)&&(te=re),Number.isFinite(re)||(re=0),Number.isFinite(te)||(te=0),e6t(P,O,z,H,re,te,f)}if(T==="circle"){const P=Mm(o.cx,0),O=Mm(o.cy,0),z=Mm(o.r,NaN);return z>ku?zze(P,O,z,z,f):[]}if(T==="ellipse"){const P=Mm(o.cx,0),O=Mm(o.cy,0),z=Mm(o.rx,NaN),H=Mm(o.ry,NaN);return!(z>ku)||!(H>ku)?[]:zze(P,O,z,H,f)}if(T==="line"){const P=Mm(o.x1,0),O=Mm(o.y1,0),z=Mm(o.x2,0),H=Mm(o.y2,0);return[{points:[[P,O],[z,H]],closed:!1}]}if(T==="polyline"){const P=Jze(o.points);return P.length<2?[]:[{points:P,closed:!1}]}if(T==="polygon"){const P=Jze(o.points);return P.length<3?[]:[{points:P,closed:!0}]}return[]}function n6t(l){const o=[];for(const f of l){const g=yI(f.points);f.closed?g.length>=3&&Math.abs(yxe(g))>ku&&o.push({points:g,closed:!0}):g.length>=2&&o.push({points:g,closed:!1})}return o}function r6t(l){return l.fill!=="none"&&l.fill!=="transparent"&&l.opacity>ku&&l.fillOpacity>ku}function i6t(l){return l.stroke!=="none"&&l.stroke!=="transparent"&&l.strokeWidth>ku&&l.opacity>ku&&l.strokeOpacity>ku}function s6t(l){const o=[];for(const f of l){if(!f.closed)continue;const g=yI(f.points);if(g.length<3)continue;const T=yxe(g),P=Math.abs(T);P<=ku||o.push({points:g,area:T,absArea:P,sample:bWe(g)})}return o}function a6t(l,o){const f=s6t(l);if(f.length===0)return null;const g=[],T=[];if(o==="evenodd"){const O=[...f].sort((z,H)=>z.absArea-H.absArea);for(const z of O){let H=0;for(const te of f)te!==z&&(te.absArea<=z.absArea+ku||xWe(z.sample,te.points)&&(H+=1));const re=Md(z.points);H%2===0?g.push(re):T.push(re)}}else{const z=[...f].sort((H,re)=>re.absArea-H.absArea)[0].area>=0?1:-1;for(const H of f){const re=Md(H.points);(H.area>=0?1:-1)===z?g.push(re):T.push(re)}}g.length===0&&g.push(Md(f[0].points));let P=g.length===1?g[0]:Ug(...g);return T.length>0&&(P=Z1(P,...T)),P.isEmpty()?null:P}function o6t(l){return l==="round"?"Round":"Square"}function c6t(l,o,f){const g=Md(l),T=g.offset(o/2,f),P=g.offset(-o/2,f);if(P.isEmpty())return T.isEmpty()?null:T;const O=Z1(T,P);return O.isEmpty()?null:O}function l6t(l,o,f){if(!(o>ku))return null;const g=o6t(f),T=[];for(const P of l){const O=yI(P.points);if(P.closed){if(O.length<3)continue;const z=c6t(O,o,g);z&&!z.isEmpty()&&T.push(z)}else{if(O.length<2)continue;const z=dxe(O,o,g);z.isEmpty()||T.push(z)}}return T.length===0?null:T.length===1?T[0]:Ug(...T)}function u6t(l){const f=l.toPolygons().map(z=>z.map(([H,re])=>[H,re])).map(z=>yI(z)).filter(z=>z.length>=3).map(z=>{const H=yxe(z);return{points:z,area:H,absArea:Math.abs(H),sample:bWe(z)}}).filter(z=>z.absArea>ku);if(f.length===0)return[];const g=f.filter(z=>z.area>0),T=f.filter(z=>z.area<0);if(g.length===0){const z=Md(f[0].points);return z.isEmpty()?[]:[{sketch:z,area:z.area()}]}const P=g.map(z=>({outer:z,holes:[]}));for(const z of T){const H=P.filter(re=>xWe(z.sample,re.outer.points)).sort((re,te)=>re.outer.absArea-te.outer.absArea);H.length>0&&H[0].holes.push(z)}const O=[];for(const z of P){let H=Md(z.outer.points);if(z.holes.length>0){const re=z.holes.map(te=>Md(te.points));H=Z1(H,...re)}H.isEmpty()||O.push({area:Math.abs(H.area()),sketch:H})}return O.sort((z,H)=>H.area-z.area),O}function _6t(l,o){const f=u6t(l);if(f.length===0)return l;const g=f[0].area,T=Math.max(o.minRegionArea,g*o.minRegionAreaRatio);let P=f.filter(O=>O.area+ku>=T);if(P.length===0&&(P=[f[0]]),o.regionSelection==="largest"&&(P=[P[0]]),Number.isFinite(o.maxRegions)){const O=Math.max(1,Math.floor(o.maxRegions));P=P.slice(0,O)}return P.length===1?P[0].sketch:Ug(...P.map(O=>O.sketch))}function f6t(l,o){const f=Number.isFinite(o.maxWidth),g=Number.isFinite(o.maxHeight);if(!f&&!g)return l;const T=l.bounds(),P=T.min,O=T.max,z=Math.max(0,(O[0]??0)-(P[0]??0)),H=Math.max(0,(O[1]??0)-(P[1]??0));let re=Number.POSITIVE_INFINITY;return f&&z>ku&&(re=Math.min(re,o.maxWidth/z)),g&&H>ku&&(re=Math.min(re,o.maxHeight/H)),!Number.isFinite(re)||re<=0||re>=1-ku?l:l.scale(re)}function p6t(l,o){if(!o.centerOnOrigin)return l;const f=l.bounds(),g=f.min,T=f.max,P=((g[0]??0)+(T[0]??0))*.5,O=((g[1]??0)+(T[1]??0))*.5;return Math.abs(P)<=ku&&Math.abs(O)<=ku?l:l.translate(-P,-O)}function d6t(l,o){let f=qO();if(o.invertY){const g=vxe(l.viewBox),T=Mm(l.height,NaN),P=g.length>=4?g[1]+g[3]:Number.isFinite(T)?T:0;f=sI(Dte(0,P),w2e(1,-1))}return Math.abs(o.scale-1)>ku&&(f=sI(w2e(o.scale,o.scale),f)),f}const m6t=new Set(["path","rect","circle","ellipse","line","polyline","polygon"]);function h6t(l,o){const f=[],g=[{tag:"__root__",ctx:{transform:qO(),style:{...jEt},hidden:!1,inDefs:!1}}];let T=!1;const P=/<!--[\s\S]*?-->|<\?[\s\S]*?\?>|<!DOCTYPE[\s\S]*?>|<!\[CDATA\[[\s\S]*?\]\]>|<\/?[^>]+>/gi;let O;for(;(O=P.exec(l))!==null;){const z=O[0];if(z.startsWith("<!--")||z.startsWith("<?")||z.startsWith("<!"))continue;if(z.startsWith("</")){const ht=z.slice(2,-1).trim().toLowerCase();for(;g.length>1;){const xn=g.pop();if(!xn||xn.tag===ht)break}continue}const re=z.endsWith("/>"),te=z.slice(1,z.length-(re?2:1)).trim();if(!te)continue;const W=te.search(/\s/),Ee=(W<0?te:te.slice(0,W)).toLowerCase(),se=W<0?"":te.slice(W+1),me=UEt(se),Xe=g[g.length-1].ctx,it=XEt(Xe.style,me),at=YEt(me.transform);let It=sI(Xe.transform,at);!T&&Ee==="svg"&&(T=!0,It=sI(d6t(me,o),It));const tn=Xe.hidden||it.display==="none"||it.visibility==="hidden"||it.opacity<=ku,At=Xe.inDefs||Ee==="defs"||Ee==="symbol"||Ee==="clipPath"||Ee==="mask"||Ee==="pattern",mt={transform:It,style:it,hidden:tn,inDefs:At};if(!mt.hidden&&!mt.inDefs&&m6t.has(Ee)){const ht=t6t(Ee,me,o.flattenTolerance,o.arcSegments),xn=n6t(ZEt(ht,mt.transform));xn.length>0&&f.push({subpaths:xn,style:{...mt.style}})}re||g.push({tag:Ee,ctx:mt})}return f}function g6t(l={}){const o=l.include??"auto",f=l.regionSelection??"all",g=Number.isFinite(l.flattenTolerance)?Math.max(.01,l.flattenTolerance):.35,T=Number.isFinite(l.arcSegments)?Math.max(2,Math.floor(l.arcSegments)):12,P=Number.isFinite(l.maxRegions)?Math.max(1,Math.floor(l.maxRegions)):Number.POSITIVE_INFINITY,O=Number.isFinite(l.minRegionArea)?Math.max(0,l.minRegionArea):0,z=Number.isFinite(l.minRegionAreaRatio)?Math.max(0,l.minRegionAreaRatio):0,H=Number.isFinite(l.scale)?Math.max(1e-6,l.scale):1,re=Number.isFinite(l.maxWidth)?Math.max(1e-6,l.maxWidth):Number.POSITIVE_INFINITY,te=Number.isFinite(l.maxHeight)?Math.max(1e-6,l.maxHeight):Number.POSITIVE_INFINITY,W=l.centerOnOrigin??!1,Ee=Number.isFinite(l.simplify)?Math.max(0,l.simplify):0,se=l.invertY??!0;return{include:o,regionSelection:f,maxRegions:P,minRegionArea:O,minRegionAreaRatio:z,flattenTolerance:g,arcSegments:T,scale:H,maxWidth:re,maxHeight:te,centerOnOrigin:W,simplify:Ee,invertY:se}}function y6t(l={}){const o=(f,g,T=!0)=>{if(f!=null){if(typeof f!="number"||!Number.isFinite(f))throw new Error(`SVG import option "${g}" must be a finite number`);if(!T&&f<=0)throw new Error(`SVG import option "${g}" must be > 0`)}};if(l.include!=null&&!["auto","fill","stroke","fill-and-stroke"].includes(l.include))throw new Error('SVG import option "include" must be one of: auto, fill, stroke, fill-and-stroke');if(l.regionSelection!=null&&!["all","largest"].includes(l.regionSelection))throw new Error('SVG import option "regionSelection" must be one of: all, largest');if(o(l.maxRegions,"maxRegions"),o(l.minRegionArea,"minRegionArea"),o(l.minRegionAreaRatio,"minRegionAreaRatio"),o(l.flattenTolerance,"flattenTolerance",!1),o(l.arcSegments,"arcSegments",!1),o(l.scale,"scale",!1),o(l.maxWidth,"maxWidth",!1),o(l.maxHeight,"maxHeight",!1),o(l.simplify,"simplify"),l.centerOnOrigin!=null&&typeof l.centerOnOrigin!="boolean")throw new Error('SVG import option "centerOnOrigin" must be a boolean');if(l.invertY!=null&&typeof l.invertY!="boolean")throw new Error('SVG import option "invertY" must be a boolean')}function v6t(l,o,f){return f==="fill"?l:f==="stroke"?o:f==="fill-and-stroke"?[...l,...o]:l.length>0?l:o}function qze(l,o={}){if(typeof l!="string"||l.trim().length===0)throw new Error("SVG import requires non-empty SVG content");if(!/<svg[\s>]/i.test(l))throw new Error("SVG import expects content containing an <svg> root element");y6t(o);const f=g6t(o),g=h6t(l,f);if(g.length===0)throw new Error("SVG import produced no supported shape geometry");const T=[],P=[];for(const H of g){if(r6t(H.style)){const re=a6t(H.subpaths,H.style.fillRule);re&&!re.isEmpty()&&T.push(re)}if(i6t(H.style)){const re=l6t(H.subpaths,H.style.strokeWidth,H.style.strokeJoin);re&&!re.isEmpty()&&P.push(re)}}const O=v6t(T,P,f.include);if(O.length===0)throw new Error("SVG import found no fill/stroke geometry after style filtering");let z=O.length===1?O[0]:Ug(...O);if(z=_6t(z,f),z=f6t(z,f),f.simplify>0&&(z=z.simplify(f.simplify)),z.isEmpty())throw new Error("SVG import generated an empty sketch");return z=p6t(z,f),z}const E2e=1e-6;function HN(l,o){return l[0]*o[0]+l[1]*o[1]+l[2]*o[2]}function b6t(l,o){return[l[0]-o[0],l[1]-o[1],l[2]-o[2]]}function Wze(l,o){return Math.hypot(l,o)}function Ate(l){const o=Math.hypot(l[0],l[1],l[2]);return o<1e-12?[0,0,1]:[l[0]/o,l[1]/o,l[2]/o]}function WD(l,o,f=E2e){return Math.abs(l-o)<=f}function Vze(l,o,f,g){return{kind:"project",sourceShape:m_(l),plane:{origin:[o.origin[0],o.origin[1],o.origin[2]],u:[o.u[0],o.u[1],o.u[2]],v:[o.v[0],o.v[1],o.v[2]],normal:[o.normal[0],o.normal[1],o.normal[2]]},sourcePlacement:f?i6(f):void 0,replayReason:g,transforms:[]}}const x6t={matrix:Ea.identity().toArray(),placement:{workplane:{origin:[0,0,0],u:[1,0,0],v:[0,1,0],normal:[0,0,1],source:{kind:"face-ref"}},u:0,v:0,protrude:0,selfAnchor:"center"}};function tte(l){return{profile:Fd(l.profile),placement:rT(l.placement)}}function bxe(l){return{origin:[l.placement.workplane.origin[0],l.placement.workplane.origin[1],l.placement.workplane.origin[2]],u:Ate([l.placement.workplane.u[0],l.placement.workplane.u[1],l.placement.workplane.u[2]]),v:Ate([l.placement.workplane.v[0],l.placement.workplane.v[1],l.placement.workplane.v[2]]),normal:Ate([l.placement.workplane.normal[0],l.placement.workplane.normal[1],l.placement.workplane.normal[2]])}}function S6t(l){const o=Math.hypot(l[0],l[1],l[2]);if(o<1e-12)return Ea.identity().toArray();const f=l[0]/o,g=l[1]/o,T=l[2]/o;return[1-2*f*f,-2*f*g,-2*f*T,0,-2*g*f,1-2*g*g,-2*g*T,0,-2*T*f,-2*T*g,1-2*T*T,0,0,0,0,1]}function T6t(l){switch(l.kind){case"translate":return Ea.translation(l.x,l.y,l.z).toArray();case"rotate":return Ea.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg).toArray();case"scale":return Ea.scale([l.x,l.y,l.z]).toArray();case"rotateAround":return Ea.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]).toArray();case"mirror":return S6t([l.normalX,l.normalY,l.normalZ])}}function k6t(l,o){const f=T6t(o),g=Ea.from(f),T=rT(l);return{matrix:Ea.from(T.matrix).mul(f).toArray(),placement:{...T.placement,workplane:{...T.placement.workplane,origin:g.point(T.placement.workplane.origin),u:g.vector(T.placement.workplane.u),v:g.vector(T.placement.workplane.v),normal:g.vector(T.placement.workplane.normal)}}}}function yne(l,o,f){const g=Ea.from(o.matrix),T=g.point([0,0,0]),P=g.vector([1,0,0]),O=g.vector([0,1,0]),z=g.vector([0,0,1]),H=Math.abs(HN(Ate(z),f.normal));if(!WD(H,1,1e-5))return{reason:"projection replay currently requires the target plane to stay parallel to the source workplane."};const re=HN(P,f.u),te=HN(O,f.u),W=HN(P,f.v),Ee=HN(O,f.v),se=Wze(re,W),me=Wze(te,Ee);if(se<E2e||me<E2e)return{reason:"projection replay requires a non-degenerate in-plane basis."};const Xe=re*te+W*Ee;if(Math.abs(Xe)>1e-5*Math.max(1,se*me))return{reason:"projection replay does not support in-plane shear from downstream 3D transforms yet."};const it=re/se,at=te/me,It=W/se,tn=Ee/me,At=it*tn-at*It;if(!WD(Math.abs(At),1,1e-5))return{reason:"projection replay requires a rigid or mirrored in-plane basis."};let mt=Fd(l);if((!WD(se,1)||!WD(me,1))&&(mt=Db(mt,{kind:"scale",x:se,y:me})),At<0){mt=Db(mt,{kind:"mirror",normalX:1,normalY:0});const $r=Math.atan2(-It,-it)*180/Math.PI;WD($r,0)||(mt=Db(mt,{kind:"rotate",degrees:$r}))}else{const $r=Math.atan2(It,it)*180/Math.PI;WD($r,0)||(mt=Db(mt,{kind:"rotate",degrees:$r}))}const ht=b6t(T,f.origin),xn=HN(ht,f.u),Pn=HN(ht,f.v);return(!WD(xn,0)||!WD(Pn,0))&&(mt=Db(mt,{kind:"translate",x:xn,y:Pn})),{profile:mt}}function C6t(l,o,f){return yne(l,o,f)}function SWe(l){return{kind:"circle",radius:l,transforms:[]}}function w6t(l){var o,f;return Math.max(l.hole.radius,((o=l.hole.counterbore)==null?void 0:o.radius)??0,((f=l.hole.countersink)==null?void 0:f.radius)??0)}function Lbe(l){return{profile:Fd(l),placement:rT(x6t)}}function E6t(l,o){const f=yne(l.profile,l.placement,bxe(o));return f.profile?{ok:!0,context:{profile:f.profile,placement:rT(o)}}:{ok:!1,reason:f.reason??"projection replay could not map a compatible source plane."}}function P6t(l,o){const f=yne(SWe(w6t(o)),o.placement,bxe(l.placement));if(!f.profile)return{ok:!1,reason:`projection replay can only absorb hole rewrites when the hole axis stays parallel to the projected source basis. ${f.reason??""}`.trim()};const g=iT("difference",[l.profile,f.profile]);return g?{ok:!0,context:{profile:g,placement:rT(l.placement)}}:{ok:!1,reason:"projection replay could not subtract the hole silhouette from the projected source profile."}}function D6t(l,o){const f=yne(o.profile,o.placement,bxe(l.placement));if(!f.profile)return{ok:!1,reason:`projection replay can only absorb cut rewrites when the cut workplane stays parallel to the projected source basis. ${f.reason??""}`.trim()};const g=iT("difference",[l.profile,f.profile]);return g?{ok:!0,context:{profile:g,placement:rT(l.placement)}}:{ok:!1,reason:"projection replay could not subtract the cut silhouette from the projected source profile."}}function QN(l){if(!l)return{ok:!1,reason:"projection replay currently requires compiler-owned source intent."};switch(l.kind){case"queryOwner":return QN(l.base);case"transform":{const o=QN(l.base);if(!o.ok)return o;let f=tte(o.context);for(const g of l.steps){if(g.kind==="workplanePlacement"){f.placement=rT({matrix:g.matrix,placement:g.placement});continue}f.placement=k6t(f.placement,g)}return{ok:!0,context:f}}case"extrude":return l.scaleTop?{ok:!1,reason:"projection replay currently supports straight extrusions without tapered tops."}:{ok:!0,context:Lbe(l.profile)};case"box":return{ok:!0,context:Lbe({kind:"rect",width:l.x,height:l.y,center:l.center,transforms:[]})};case"cylinder":return{ok:!0,context:Lbe(SWe(Math.max(Math.abs(l.radius),Math.abs(l.radiusTop??l.radius))))};case"shell":{const o=QN(l.base);return o.ok?{ok:!0,context:tte(o.context)}:o}case"hole":{const o=QN(l.base);return o.ok?l.extent.kind==="two-sided"&&Rm(l.extent).kind==="through"?{ok:!1,reason:"projection replay currently supports one-sided through holes only; reverse two-sided spans can change silhouette coverage outside the defended subset."}:Rm(l.extent).kind!=="through"?{ok:!0,context:tte(o.context)}:P6t(o.context,l):o}case"cut":{const o=QN(l.base);return o.ok?l.extent.kind==="two-sided"&&Rm(l.extent).kind==="through"?{ok:!1,reason:"projection replay currently supports one-sided through cuts only; reverse two-sided spans can change silhouette coverage outside the defended subset."}:l.taper||Rm(l.extent).kind!=="through"?l.taper&&Rm(l.extent).kind==="through"?{ok:!1,reason:"projection replay currently supports straight through cuts without tapered side walls."}:{ok:!0,context:tte(o.context)}:D6t(o.context,l):o}case"boolean":{if(l.op!=="union")return{ok:!1,reason:`projection replay currently supports boolean union sources only; boolean ${l.op} can change shadow coverage along the projection normal.`};const o=[];for(let P=0;P<l.shapes.length;P+=1){const O=QN(l.shapes[P]);if(!O.ok)return{ok:!1,reason:`projection replay could not derive a compatible union operand at index ${P}: ${O.reason}`};o.push(O.context)}if(o.length===0)return{ok:!1,reason:"projection replay cannot derive an empty boolean union source."};const f=rT(o[0].placement),g=[];for(let P=0;P<o.length;P+=1){const O=E6t(o[P],f);if(!O.ok)return{ok:!1,reason:`projection replay could not align union operand ${P} to a shared projection basis: ${O.reason}`};g.push(O.context.profile)}const T=iT("union",g);return T?{ok:!0,context:{profile:T,placement:f}}:{ok:!1,reason:"projection replay could not combine the projected union operands into one 2D profile."}}case"sphere":return{ok:!1,reason:"projection replay currently needs a defended planar source basis and does not derive one from spheres yet."};case"sheetMetal":return{ok:!1,reason:"projection replay currently does not derive a defended planar projection basis from sheet-metal semantic bodies yet."};case"revolve":return{ok:!1,reason:"projection replay currently supports projection-driven descendants from extrude/box/cylinder rewrite flows, not revolves."};case"loft":case"sweep":return{ok:!1,reason:`projection replay currently does not reduce ${l.kind} sources to one defended planar projection basis.`};case"hull":return{ok:!1,reason:"projection replay currently does not reduce hull sources to one defended planar projection basis."};case"trimByPlane":return{ok:!1,reason:"projection replay currently does not defend trim-by-plane sources because the kept silhouette depends on the trim half-space."};case"fillet":case"chamfer":return{ok:!1,reason:`projection replay currently does not absorb ${l.kind} silhouette changes into the exact subset.`}}}function A6t(l,o){var O;const f=c4(l);if(!f)return null;const g=Aqe(o),T=QN(f);if(!T.ok)return Vze(f,g,(O=nwt(l))==null?void 0:O.placement,T.reason);const P=C6t(T.context.profile,T.context.placement,g);return P.profile?{kind:"project",sourceShape:m_(f),plane:{origin:[g.origin[0],g.origin[1],g.origin[2]],u:[g.u[0],g.u[1],g.u[2]],v:[g.v[0],g.v[1],g.v[2]],normal:[g.normal[0],g.normal[1],g.normal[2]]},sourcePlacement:i6(T.context.placement.placement),replayProfile:P.profile,transforms:[]}:Vze(f,g,T.context.placement.placement,P.reason??"projection replay could not derive a supported 2D profile.")}function TWe(l,o){const f=Aqe(o),g=Nqe(f);return l.transform(g)}function N6t(l,o){const f=TWe(l,o);return new Eo(f.slice(0))}function I6t(l,o){const f=TWe(l,o),g=new Eo(f.project()),T=A6t(l,o);return T?By(g,T):g}function xxe(l){if(!l||typeof l!="object")return!1;const o=l;return typeof o.name=="string"&&Array.isArray(o.normal)&&Array.isArray(o.center)}function ZE(l){return Number.isFinite(l)&&l>0}function P2e(l,o){return l[0]*o[0]+l[1]*o[1]+l[2]*o[2]}function nne(l){const o=Math.hypot(l[0],l[1],l[2]);if(o<1e-12)throw new Error("Hole/cut feature direction could not be normalized.");return[l[0]/o,l[1]/o,l[2]/o]}function F6t(l){const{workplane:o,u:f,v:g,protrude:T}=l,P=[o.origin[0]+o.u[0]*f+o.v[0]*g+o.normal[0]*T,o.origin[1]+o.u[1]*f+o.v[1]*g+o.normal[1]*T,o.origin[2]+o.u[2]*f+o.v[2]*g+o.normal[2]*T];return[o.u[0],o.u[1],o.u[2],0,o.v[0],o.v[1],o.v[2],0,o.normal[0],o.normal[1],o.normal[2],0,P[0],P[1],P[2],1]}function O6t(l,o){return o?Qqe(l).some(f=>Pb(f,o)):!0}function Sxe(l,o,f){if(!O6t(l,o))throw new Error(`${f} requires a face/workplane owned by the target shape or one of its preserved query ancestors.`)}function Txe(l,o,f){const g=hkt(c4(l),f);if(g)throw new Error(`${o} ${g}`)}function M6t(l){const o=l.boundingBox(),[f,g,T]=o.min,[P,O,z]=o.max;return[[f,g,T],[f,g,z],[f,O,T],[f,O,z],[P,g,T],[P,g,z],[P,O,T],[P,O,z]]}function L6t(l,o,f){const g=nne(f);let T=0;for(const re of M6t(l)){const te=[re[0]-o[0],re[1]-o[1],re[2]-o[2]];T=Math.max(T,P2e(te,g))}if(T>1e-6)return T;const P=l.boundingBox(),O=P.max[0]-P.min[0],z=P.max[1]-P.min[1],H=P.max[2]-P.min[2];return Math.max(Math.hypot(O,z,H),1)}function R6t(l,o){return xxe(o)?o:l.face(o)}function j6t(l,o,f,g,T={requireDefendedQuery:!0}){const P=xxe(f)?rM(f):rM(l,f);return Sxe(o,P.source.owner,g),T.requireDefendedQuery&&Txe(o,g,P.source),{face:R6t(l,f),query:P.source}}function B6t(l,o,f,g){if(f.planar===!1||!f.uAxis||!f.vAxis)throw new Error(`${g} upToFace currently requires a planar termination face.`);const T=nne(o),P=nne(f.normal);if(Math.abs(Math.abs(P2e(T,P))-1)>1e-6)throw new Error(`${g} upToFace currently requires a termination face parallel to the feature direction.`);const O=[f.center[0]-l[0],f.center[1]-l[1],f.center[2]-l[2]],z=P2e(O,T);if(!(z>1e-6))throw new Error(`${g} upToFace requires the termination face to lie in the feature direction.`);return z}function jJ(l,o,f,g,T,P,O,z={allowThrough:!0}){if(+(T.depth!=null)+ +(T.upToFace!=null)+ +(T.through===!0)!==1)throw new Error(`${P} ${O} extent must specify exactly one of through, depth, or upToFace.`);if(T.through){if(!z.allowThrough)throw new Error(`${P} reverse two-sided extents do not support through termination yet.`);return{kind:"through",depth:L6t(o,f,g)}}if(T.upToFace!=null){const re=j6t(l,o,T.upToFace,P,{requireDefendedQuery:!1});return{kind:"upToFace",depth:B6t(f,g,re.face,P),face:re.query}}if(!ZE(T.depth))throw new Error(`${P} ${O} extent requires a positive finite blind depth.`);return{kind:"blind",depth:T.depth}}function kWe(l,o,f,g,T,P){if(T.extent){if(T.depth!=null||T.upToFace!=null)throw new Error(`${P} accepts either top-level depth/upToFace or extent.forward/extent.reverse, not both.`);if(!T.extent.forward)throw new Error(`${P} extent.forward is required when using structured feature extents.`);const O=jJ(l,o,f,[-g[0],-g[1],-g[2]],T.extent.forward,P,"forward");if(!T.extent.reverse)return O;const z=jJ(l,o,f,nne(g),T.extent.reverse,P,"reverse",{allowThrough:!1});if(z.kind==="through")throw new Error(`${P} reverse two-sided extents do not support through termination yet.`);return{kind:"two-sided",forward:O,reverse:z}}if(T.depth!=null&&T.upToFace!=null)throw new Error(`${P} accepts either depth or upToFace, not both.`);return T.upToFace!=null?jJ(l,o,f,[-g[0],-g[1],-g[2]],{upToFace:T.upToFace},P,"forward"):T.depth==null?jJ(l,o,f,[-g[0],-g[1],-g[2]],{through:!0},P,"forward"):jJ(l,o,f,[-g[0],-g[1],-g[2]],{depth:T.depth},P,"forward")}function z6t(l){var f,g;const o={radius:l.diameter/2};if(l.counterbore&&l.countersink)throw new Error("Shape.hole() currently supports either counterbore or countersink, not both at once.");if(l.counterbore){if(!ZE(l.counterbore.diameter)||l.counterbore.diameter<=l.diameter)throw new Error("Shape.hole() counterbore diameter must be greater than the hole diameter.");if(!ZE(l.counterbore.depth))throw new Error("Shape.hole() counterbore depth must be a positive finite value.");o.counterbore={radius:l.counterbore.diameter/2,depth:l.counterbore.depth}}if(l.countersink){if(!ZE(l.countersink.diameter)||l.countersink.diameter<=l.diameter)throw new Error("Shape.hole() countersink diameter must be greater than the hole diameter.");const T=l.countersink.angleDeg??90;if(!Number.isFinite(T)||T<=0||T>=180)throw new Error("Shape.hole() countersink angleDeg must be between 0 and 180 degrees.");const P=T*Math.PI/360,O=Math.tan(P);if(!(O>1e-9))throw new Error("Shape.hole() countersink angleDeg is too small to form a defended taper.");o.countersink={radius:l.countersink.diameter/2,angleDeg:T,depth:(l.countersink.diameter-l.diameter)/2/O}}if(l.thread){const T=(f=l.thread.designation)==null?void 0:f.trim(),P=(g=l.thread.class)==null?void 0:g.trim();if(T==="")throw new Error("Shape.hole() thread.designation must be a non-empty string when provided.");if(P==="")throw new Error("Shape.hole() thread.class must be a non-empty string when provided.");if(l.thread.pitch!=null&&!ZE(l.thread.pitch))throw new Error("Shape.hole() thread.pitch must be a positive finite value when provided.");if(l.thread.depth!=null&&!ZE(l.thread.depth))throw new Error("Shape.hole() thread.depth must be a positive finite value when provided.");if(l.thread.modeled===!0)throw new Error("Shape.hole() does not model helical threads yet; pass thread metadata with modeled omitted/false for deferred thread intent.");if(T==null&&P==null&&l.thread.pitch==null&&l.thread.depth==null&&l.thread.handedness==null&&l.thread.modeled==null)throw new Error("Shape.hole() thread metadata requires at least one designation, pitch, class, handedness, or depth value.");o.thread={designation:T,pitch:l.thread.pitch,class:P,handedness:l.thread.handedness,depth:l.thread.depth,modeled:!1}}return o}function J6t(l,o){var T,P,O;if((l.counterbore||l.countersink)&&o.kind==="two-sided")throw new Error("Shape.hole() does not yet combine reverse two-sided extents with counterbore or countersink heads.");const f=Rm(o),g=((T=l.counterbore)==null?void 0:T.depth)??((P=l.countersink)==null?void 0:P.depth)??0;if(g>0&&g>=f.depth-1e-6)throw l.counterbore?new Error("Shape.hole() counterbore depth must leave some straight hole depth below the bore."):new Error("Shape.hole() countersink diameter/angle must leave some straight hole depth below the sink.");if(((O=l.thread)==null?void 0:O.depth)!=null&&l.thread.depth>f.depth+1e-6)throw new Error("Shape.hole() thread.depth cannot exceed the primary forward hole depth.")}function q6t(l,o,f){if(o.taperScale==null)return;if(f.kind==="two-sided")throw new Error("Shape.cutout() does not yet combine taperScale with reverse two-sided extents.");if(!l)throw new Error("Shape.cutout() requires a compile-covered sketch profile before taperScale can be validated.");if(l.kind!=="circle"&&l.kind!=="rect"&&l.kind!=="roundedRect")throw new Error("Shape.cutout() taperScale currently supports circle, rect, and roundedRect sketch profiles only.");const g=Array.isArray(o.taperScale)?o.taperScale:[o.taperScale,o.taperScale];if(g.length!==2||!ZE(g[0])||!ZE(g[1]))throw new Error("Shape.cutout() taperScale must be a positive finite number or [x, y] pair.");if(l.kind==="circle"&&Math.abs(g[0]-g[1])>1e-6)throw new Error("Shape.cutout() circular tapered cuts currently require a uniform taperScale.");return{scale:[g[0],g[1]]}}function CWe(l,o,f){if(!l)return null;const g=une(o);return hq(ixe(l,f(g)),g)}function wWe(l,o){if(!o)throw new Error("Hole/cut feature could not record compiler intent for this target.");const f=Yqe(l),g=M_(o,l.colorHex,{backend:f.backend,representation:f.representation,fidelity:f.fidelity,topology:"none",sources:["boolean",...f.sources]});return Yte(g,fxe(l)),mne(g,Xqe(l),{merge:!1}),hne(g,{backend:f.backend,representation:f.representation,fidelity:f.fidelity,topology:"none",sources:["boolean",...f.sources]}),g}function W6t(l,o,f,g){const T=xxe(f)?rM(f):rM(l,f);return Sxe(o,T.source.owner,"Shape.hole()"),Txe(o,"Shape.hole()",T.source),{placement:{placement:{workplane:c2e(T),u:g.u??0,v:g.v??0,protrude:0,selfAnchor:"center"},matrix:F6t({workplane:c2e(T),u:g.u??0,v:g.v??0,protrude:0})},extent:kWe(l,o,T.origin,T.normal,{depth:g.depth,upToFace:g.upToFace,extent:g.extent},"Shape.hole()")}}function EWe(l,o,f,g){if(!ZE(g.diameter))throw new Error("Shape.hole() requires a positive finite diameter.");const T=c4(l);if(!T)throw new Error("Shape.hole() currently requires a compile-covered target shape.");const{placement:P,extent:O}=W6t(o,l,f,g),z=z6t(g);J6t(z,O);const H=CWe($kt(T,P,z,O),"hole",re=>Rkt(re,T,P.placement,z,O));return wWe(l,H)}function PWe(l,o,f={}){const g=c4(l);if(!g)throw new Error("Shape.cutout() currently requires a compile-covered target shape.");const T=um(o);if(!T)throw new Error("Shape.cutout() requires a compile-covered sketch profile.");const P=r6(o),O=a4(o);if(!P||!O)throw new Error("Shape.cutout() requires a sketch placed with Sketch.onFace(...).");Sxe(l,P.workplane.source.owner,"Shape.cutout()"),Txe(l,"Shape.cutout()",P.workplane.source);const z=kWe(l,l,P.workplane.origin,P.workplane.normal,{depth:f.depth,upToFace:f.upToFace,extent:f.extent},"Shape.cutout()"),H=q6t(T,f,z),re=CWe(Hkt(g,{matrix:O,placement:i6(P)},T,z,H),"cut",te=>jkt(te,g,P,T,z));return wWe(l,re)}na.prototype.hole=function(o,f){return EWe(this,this,o,f)};na.prototype.cutout=function(o,f={}){return PWe(this,o,f)};po.prototype.hole=function(o,f){return EWe(this.toShape(),this,o,f)};po.prototype.cutout=function(o,f={}){return PWe(this.toShape(),o,f)};const V6t={fidelity:"kernel-native",topology:"synthetic",sources:["sheet-metal"]};function U6t(l){var f,g;const o=l.bendRadius+l.thickness;return{kind:((f=l.cornerRelief)==null?void 0:f.kind)??"rect",size:((g=l.cornerRelief)==null?void 0:g.size)??o}}function $6t(l){return{panel:{width:l.panel.width,height:l.panel.height},thickness:l.thickness,bendRadius:l.bendRadius,bendAllowance:{kind:"k-factor",kFactor:l.bendAllowance.kFactor},cornerRelief:U6t(l),flanges:[]}}function H6t(l){return l==="panel"?"panel":`"${l}"`}function G6t(l){return{region:l.region,sketch:l.sketch.clone(),u:l.u,v:l.v,selfAnchor:l.selfAnchor}}function X6t(l){if(r6(l)!=null)throw new Error("SheetMetalPart.cutout() expects an unplaced 2D sketch. Pass the profile before calling onFace(...).");if(!um(l))throw new Error("SheetMetalPart.cutout() requires a compile-covered sketch profile.")}function Y6t(l,o){const f=s6({kind:"sheetMetal",model:qte(l),output:o},`sheet-metal:${o}`);if(!f)throw new Error("sheetMetal() could not build the compiler-owned base plan.");return M_(f,void 0,V6t)}function Q6t(l,o){const f=new Set(oTt(l));if(!f.has(o)&&o!=="panel")throw new Error(`SheetMetalPart.cutout() cannot target ${H6t(o)} because that flange has not been added. Supported planar regions: ${Array.from(f).join(", ")}`)}class cq{constructor(o,f=[]){tu(this,"model");tu(this,"cutouts");this.model=qte(o),this.cutouts=f.map(G6t)}flange(o,f){const g=qte(this.model);if(g.flanges.find(O=>O.edge===o))throw new Error(`${o} flange is already defined on this SheetMetalPart.`);g.flanges.push({edge:o,length:f.length,angleDeg:f.angleDeg??90});const P=Wte(g);if(P)throw new Error(P);return eM(g),new cq(g,this.cutouts)}cutout(o,f,g={}){if(!cTt(o))throw new Error(`SheetMetalPart.cutout() does not support region "${String(o)}".`);return Q6t(this.model,o),X6t(f),new cq(this.model,[...this.cutouts,{region:o,sketch:f.clone(),u:g.u??0,v:g.v??0,selfAnchor:g.selfAnchor??"center"}])}regionNames(){return["panel",...Array.from(new Set(this.model.flanges.flatMap(o=>[`bend-${o.edge}`,`flange-${o.edge}`])))]}folded(){return this.buildOutput("folded")}flatPattern(){return this.buildOutput("flat")}buildOutput(o){const f=Wte(this.model);if(f)throw new Error(f);eM(this.model);let g=Y6t(this.model,o);for(const T of this.cutouts){const P=T.sketch.onFace(g,T.region,{u:T.u,v:T.v,selfAnchor:T.selfAnchor});g=g.cutout(P)}return g}}function Z6t(l){const o=$6t(l),f=Wte(o);if(f)throw new Error(f);return eM(o),new cq(o)}let vne=[],lq={},fI=[];function K6t(){vne=[],fI=[]}function ePt(l){lq=l}function Uze(){return vne}function tPt(l,o){fI.push(l);try{return o()}finally{fI.pop()}}function DWe(l,o){return Object.prototype.hasOwnProperty.call(l,o)}function AWe(l,o,f={}){const g=fI[fI.length-1],T=g!=null&&g.namePrefix?`${g.namePrefix} / ${l}`:l,P=g==null?void 0:g.localOverrides,O=!!(P&&DWe(P,l)),z=(O?P[l]:void 0)??lq[T]??lq[l]??o,H=f.integer??!1,re=H?Math.round(z):z,te=f.min??0,W=f.max??o*4,Ee=f.step??(H||W-te>100?1:.1);if(!O){const se=H?Math.round(o):o;vne.push({name:T,value:re,defaultValue:se,min:te,max:W,step:Ee,unit:f.unit,integer:H,reverse:f.reverse})}return re}function nPt(l,o){const f=fI[fI.length-1],g=f!=null&&f.namePrefix?`${f.namePrefix} / ${l}`:l,T=f==null?void 0:f.localOverrides,P=!!(T&&DWe(T,l)),O=o?1:0,H=((P?T[l]:void 0)??lq[g]??lq[l]??O)>=.5?1:0;return P||vne.push({name:g,value:H,defaultValue:O,min:0,max:1,step:1,boolean:!0}),H===1}function rPt(l,o,f,g={}){const T=g.axis??[0,0,1],P=g.min??0,O=g.max??360,z=g.default??0,H=AWe(l,z,{min:P,max:O,unit:g.unit??"°",reverse:g.reverse});return o.rotateAround(T,H,f)}function kxe(l){if(typeof l!="string")return;const o=l.trim();return o.length>0?o:void 0}function iPt(l){return!!l&&typeof l=="object"&&typeof l.name=="string"}function sPt(l){const o=kxe(l.name);if(!o)throw new Error("group(...) named items require a non-empty name");const f=l.shape!==void 0,g=l.sketch!==void 0,T=Array.isArray(l.group);if(Number(f)+Number(g)+Number(T)!==1)throw new Error(`group(...) named item "${o}" must provide exactly one of shape, sketch, or group`);if(f){if(!(l.shape instanceof na)&&!(l.shape instanceof po)&&!(l.shape instanceof lu))throw new Error(`group(...) named item "${o}" shape must be a Shape, TrackedShape, or ShapeGroup`);return l.shape}if(g){if(!(l.sketch instanceof Eo))throw new Error(`group(...) named item "${o}" sketch must be a Sketch`);return l.sketch}return Cxe(...l.group)}function aPt(l){const o=[],f=[];return l.forEach(g=>{if(iPt(g)){o.push(sPt(g)),f.push(kxe(g.name));return}o.push(g),f.push(void 0)}),{children:o,childNames:f}}class lu{constructor(o,f){tu(this,"children");tu(this,"childNames");if(f&&f.length!==o.length)throw new Error("ShapeGroup childNames must match children length");this.children=[...o],this.childNames=this.children.map((g,T)=>kxe(f==null?void 0:f[T]))}childName(o){return this.childNames[o]}mapChildren(o){return new lu(this.children.map(o),this.childNames)}clone(){return this.mapChildren(o=>(o instanceof lu||o instanceof po||o instanceof na,o.clone()))}duplicate(){return this.clone()}translate(o,f,g){return this.mapChildren(T=>T instanceof lu||T instanceof po||T instanceof na?T.translate(o,f,g):T.translate(o,f))}_bbox(){let o=[1/0,1/0,1/0],f=[-1/0,-1/0,-1/0];for(const g of this.children){if(g instanceof lu){const O=g._bbox();for(let z=0;z<3;z++)O.min[z]<o[z]&&(o[z]=O.min[z]),O.max[z]>f[z]&&(f[z]=O.max[z]);continue}const T=g instanceof po?g.toShape():g instanceof na?g:null;if(!T)continue;const P=T.boundingBox();for(let O=0;O<3;O++)P.min[O]<o[O]&&(o[O]=P.min[O]),P.max[O]>f[O]&&(f[O]=P.max[O])}return{min:o,max:f}}boundingBox(){const o=this._bbox();return{min:o.min,max:o.max}}resolveRotatePoint(o){if(Array.isArray(o))return[o[0],o[1],o[2]];const f=this._bbox();return t4(f.min,f.max,o)}moveTo(o,f,g){const T=this._bbox();return this.translate(o-T.min[0],f-T.min[1],g-T.min[2])}moveToLocal(o,f,g,T){let P;return o instanceof lu?P=o._bbox():P={min:(o instanceof po?o.toShape():o).boundingBox().min},this.moveTo(P.min[0]+f,P.min[1]+g,P.min[2]+T)}attachTo(o,f,g="center",T){const P=o instanceof lu?o._bbox():(()=>{const se=(o instanceof po?o.toShape():o).boundingBox();return{min:se.min,max:se.max}})(),O=this._bbox(),z=o instanceof lu||QJe(f)?t4(P.min,P.max,f):(o instanceof po,o.referencePoint(f)),H=t4(O.min,O.max,g);let re=z[0]-H[0],te=z[1]-H[1],W=z[2]-H[2];return T&&(re+=T[0],te+=T[1],W+=T[2]),this.translate(re,te,W)}onFace(o,f,g={}){const T=g.u??0,P=g.v??0,O=g.protrude??0,z={front:"back",back:"front",left:"right",right:"left",top:"bottom",bottom:"top"},H={front:(re,te,W)=>[re,-W,te],back:(re,te,W)=>[re,W,te],left:(re,te,W)=>[-W,re,te],right:(re,te,W)=>[W,re,te],top:(re,te,W)=>[re,te,W],bottom:(re,te,W)=>[re,te,-W]};return this.attachTo(o,f,z[f],H[f](T,P,O))}rotate(o,f,g){return this.mapChildren(T=>T instanceof lu||T instanceof po||T instanceof na?T.rotate(o,f,g):T.rotate(o))}rotateAround(o,f,g=[0,0,0]){return this.transform(Ea.rotationAxis(o,f,g))}rotateAroundTo(o,f,g,T,P={}){return this.transform(Ea.rotateAroundTo(o,f,this.resolveRotatePoint(g),this.resolveRotatePoint(T),P))}pointAlong(o){const[f,g,T]=o,P=Math.sqrt(f*f+g*g+T*T)||1,O=f/P,z=g/P,H=T/P,re=-z,te=O,W=0,Ee=Math.sqrt(re*re+te*te+W*W),se=H;if(Ee<1e-10)return se>0?this:this.rotate(180,0,0);const me=Math.atan2(Ee,se)*180/Math.PI,Xe=[re/Ee,te/Ee,W/Ee];return this.rotateAround(Xe,me)}transform(o){return new lu(this.children.map(f=>{if(f instanceof lu||f instanceof po||f instanceof na)return f.transform(o);throw new Error("ShapeGroup.transform only supports 3D children (Shape/TrackedShape/ShapeGroup). For Sketch children, use 2D transforms (translate/rotate/scale/mirror).")}),this.childNames)}scale(o){return this.mapChildren(f=>f instanceof lu||f instanceof po||f instanceof na?f.scale(o):f.scale(typeof o=="number"?o:[o[0],o[1]]))}mirror(o){return this.mapChildren(f=>f instanceof lu||f instanceof po||f instanceof na?f.mirror(o):f.mirror([o[0],o[1]]))}color(o){return this.mapChildren(f=>(f instanceof lu||f instanceof po||f instanceof na,f.color(o)))}}function Cxe(...l){const o=aPt(l);return new lu(o.children,o.childNames)}function NWe(l){const o=["part","qty","material","process","tolerance","notes"],f=T=>`"${T.replace(/"/g,'""')}"`,g=[o.join(",")];for(const T of l)g.push([f(T.part),String(T.qty),f(T.material??""),f(T.process??""),f(T.tolerance??""),f(T.notes??"")].join(","));return g.join(`
2
2
  `)}function oPt(l,o){return l instanceof po||l instanceof na,l.transform(o)}function IWe(l){if(l instanceof po)return[l.toShape()];if(l instanceof na)return[l];const o=[];for(const f of l.children)f instanceof lu?o.push(...IWe(f)):f instanceof po?o.push(f.toShape()):f instanceof na&&o.push(f);return o}function nte(l){const o=IWe(l);return o.length===0?null:o.length===1?o[0]:K1(...o)}function cPt(l,o){if(l.type==="fixed")return Ea.identity();if(l.type==="revolute")return Ea.identity().rotateAxis(l.axis,o);const f=l.axis[0]*o,g=l.axis[1]*o,T=l.axis[2]*o;return Ea.identity().translate(f,g,T)}function lPt(l,o){let f=Number.isFinite(o)?o:l.defaultValue;return l.min!=null&&(f=Math.max(l.min,f)),l.max!=null&&(f=Math.min(l.max,f)),{value:f,wasClamped:f!==o}}class FWe{constructor(o,f,g,T,P){this.name=o,this.parts=f,this.transforms=g,this.jointValues=T,this.solveWarnings=P}warnings(){return[...this.solveWarnings]}getJointState(){return{...this.jointValues}}getTransform(o){const f=this.transforms.get(o);if(!f)throw new Error(`Unknown part "${o}"`);return f}getPart(o){const f=this.parts.get(o);if(!f)throw new Error(`Unknown part "${o}"`);return oPt(f.part,this.getTransform(o))}toScene(){const o=(g,T,P)=>{g.children.forEach((O,z)=>{const H=g.childName(z),re=H?`${T}.${H}`:`${T}.${z+1}`;if(O instanceof lu){o(O,re,P);return}if(O instanceof po){P.push({name:re,shape:O.toShape()});return}O instanceof na&&P.push({name:re,shape:O})})},f=[];for(const[g,T]of this.parts){const P=this.getPart(g);if(P instanceof lu){const O=[];o(P,g,O),f.push({name:g,group:O,metadata:T.metadata})}else P instanceof po?f.push({name:g,shape:P.toShape(),metadata:T.metadata}):f.push({name:g,shape:P,metadata:T.metadata})}return f}bom(){var f,g,T,P,O;const o=[];for(const z of this.parts.values())o.push({part:z.name,qty:Math.max(1,Math.round(((f=z.metadata)==null?void 0:f.qty)??1)),material:(g=z.metadata)==null?void 0:g.material,process:(T=z.metadata)==null?void 0:T.process,tolerance:(P=z.metadata)==null?void 0:P.tolerance,notes:(O=z.metadata)==null?void 0:O.notes,metadata:z.metadata?{...z.metadata}:void 0});return o}bomCsv(){return NWe(this.bom())}collisionReport(o={}){const f=(o.parts??[...this.parts.keys()]).filter(O=>this.parts.has(O)),g=o.minOverlapVolume??.1,T=new Set((o.ignorePairs??[]).map(([O,z])=>[O,z].sort().join("|"))),P=[];for(let O=0;O<f.length;O++)for(let z=O+1;z<f.length;z++){const H=f[O],re=f[z];if(T.has([H,re].sort().join("|")))continue;const te=nte(this.getPart(H)),W=nte(this.getPart(re));if(!(!te||!W))try{const Ee=te.intersect(W);if(Ee.isEmpty())continue;const se=Ee.volume();se>g&&P.push({partA:H,partB:re,overlapVolume:se})}catch{}}return P}minClearance(o,f,g=10){const T=nte(this.getPart(o)),P=nte(this.getPart(f));if(!T||!P)throw new Error(`Cannot compute clearance between "${o}" and "${f}"`);try{const O=T.intersect(P);if(!O.isEmpty()&&O.volume()>0)return 0}catch{}return T.minGap(P,g)}}class OWe{constructor(o="Assembly"){tu(this,"parts",new Map);tu(this,"joints",new Map);tu(this,"jointCouplings",new Map);this.name=o}addFrame(o,f={}){return this.addPart(o,Cxe(),f)}addPart(o,f,g={}){if(this.parts.has(o))throw new Error(`Part "${o}" already exists`);return this.parts.set(o,{name:o,part:f,base:g.transform?Ea.from(g.transform):Ea.identity(),metadata:g.metadata?{...g.metadata}:void 0}),this}addJoint(o,f,g,T,P={}){if(this.joints.has(o))throw new Error(`Joint "${o}" already exists`);if(!this.parts.has(g))throw new Error(`Unknown parent part "${g}"`);if(!this.parts.has(T))throw new Error(`Unknown child part "${T}"`);if(g===T)throw new Error(`Joint "${o}" cannot connect a part to itself`);const O=td(P.axis??[0,0,1]);return this.joints.set(o,{name:o,type:f,parent:g,child:T,frame:P.frame?Ea.from(P.frame):Ea.identity(),axis:O,min:P.min,max:P.max,defaultValue:P.default??0,unit:P.unit,effort:P.effort,velocity:P.velocity,damping:P.damping,friction:P.friction}),this}addRevolute(o,f,g,T={}){return this.addJoint(o,"revolute",f,g,T)}addPrismatic(o,f,g,T={}){return this.addJoint(o,"prismatic",f,g,T)}addFixed(o,f,g,T={}){return this.addJoint(o,"fixed",f,g,T)}addJointCoupling(o,f){const g=this.joints.get(o);if(!g)throw new Error(`Unknown joint "${o}"`);if(g.type==="fixed")throw new Error(`Joint "${o}" is fixed and cannot be coupled`);if(!f||typeof f!="object")throw new Error("addJointCoupling(...) expects an options object");if(!Array.isArray(f.terms)||f.terms.length===0)throw new Error(`Joint coupling "${o}" requires a non-empty terms array`);if(f.offset!==void 0&&!Number.isFinite(f.offset))throw new Error(`Joint coupling "${o}" offset must be finite`);const T=new Set,P=f.terms.map((O,z)=>{if(!O||typeof O!="object")throw new Error(`Joint coupling "${o}" term[${z}] must be an object`);const H=typeof O.joint=="string"?O.joint.trim():"";if(!H)throw new Error(`Joint coupling "${o}" term[${z}] joint is required`);if(!this.joints.has(H))throw new Error(`Joint coupling "${o}" references unknown joint "${H}"`);if(H===o)throw new Error(`Joint coupling "${o}" cannot reference itself`);if(T.has(H))throw new Error(`Joint coupling "${o}" has duplicate source joint "${H}"`);T.add(H);const re=O.ratio??1;if(!Number.isFinite(re))throw new Error(`Joint coupling "${o}" term[${z}] ratio must be finite`);return{joint:H,ratio:re}});return this.jointCouplings.set(o,{joint:o,terms:P,offset:f.offset??0}),this.assertJointCouplingsAcyclic(),this}addGearCoupling(o,f,g={}){if(!g||typeof g!="object")throw new Error("addGearCoupling(...) expects an options object");const T=this.joints.get(o);if(!T)throw new Error(`Unknown joint "${o}"`);if(T.type!=="revolute")throw new Error(`addGearCoupling(...) expects driven joint "${o}" to be revolute`);const P=this.joints.get(f);if(!P)throw new Error(`Unknown joint "${f}"`);if(P.type!=="revolute")throw new Error(`addGearCoupling(...) expects driver joint "${f}" to be revolute`);if(g.offset!==void 0&&!Number.isFinite(g.offset))throw new Error(`Gear coupling "${o}" offset must be finite`);const O=g.ratio!==void 0,z=g.pair!==void 0,H=g.driverTeeth!==void 0||g.drivenTeeth!==void 0;if(Number(O)+Number(z)+Number(H)!==1)throw new Error(`Gear coupling "${o}" must provide exactly one ratio source: ratio, pair, or driverTeeth/drivenTeeth`);if(g.mesh!==void 0&&!H)throw new Error(`Gear coupling "${o}" mesh may only be set when using driverTeeth/drivenTeeth`);let te;if(O)te=g.ratio;else if(z){const W=g.pair;if(!W||typeof W!="object")throw new Error(`Gear coupling "${o}" pair must be an object with jointRatio`);te=W.jointRatio}else{if(!Number.isFinite(g.driverTeeth)||!Number.isFinite(g.drivenTeeth))throw new Error(`Gear coupling "${o}" driverTeeth/drivenTeeth must be finite`);if(g.driverTeeth<=0||g.drivenTeeth<=0)throw new Error(`Gear coupling "${o}" driverTeeth/drivenTeeth must be > 0`);te=((g.mesh??"external")==="internal"?1:-1)*(g.driverTeeth/g.drivenTeeth)}if(!Number.isFinite(te)||te===0)throw new Error(`Gear coupling "${o}" resolved ratio must be finite and non-zero`);return this.addJointCoupling(o,{terms:[{joint:f,ratio:te}],offset:g.offset})}assertJointCouplingsAcyclic(){const o=new Set,f=new Set,g=T=>{if(f.has(T))return;if(o.has(T))throw new Error(`Joint coupling cycle detected at "${T}"`);o.add(T);const P=this.jointCouplings.get(T);P&&P.terms.forEach(O=>g(O.joint)),o.delete(T),f.add(T)};this.jointCouplings.forEach((T,P)=>g(P))}solve(o={}){const f=new Map,g=new Map,T=[];for(const se of this.joints.values()){if(f.has(se.child))throw new Error(`Part "${se.child}" has multiple parent joints`);f.set(se.child,se.name);const me=g.get(se.parent)??[];me.push(se),g.set(se.parent,me)}const P=[...this.parts.keys()].filter(se=>!f.has(se));if(P.length===0&&this.parts.size>0)throw new Error("Assembly has no root part (cyclic joint graph)");const O=new Map,z=new Set,H=new Set,re={},te=new Set,W=se=>{const me=re[se];if(me!==void 0)return me;if(te.has(se))throw new Error(`Joint coupling cycle detected at "${se}"`);const Xe=this.joints.get(se);if(!Xe)throw new Error(`Unknown joint "${se}"`);te.add(se);let it=o[se]??Xe.defaultValue;const at=this.jointCouplings.get(se);at&&(it=at.offset,at.terms.forEach(At=>{it+=At.ratio*W(At.joint)}),o[se]!==void 0&&T.push(`Joint "${se}" state override ignored because it is coupled`));const{value:It,wasClamped:tn}=lPt(Xe,it);return re[se]=It,tn&&T.push(`Joint "${se}" clamped from ${it} to ${It}${Xe.unit??""}`),te.delete(se),It},Ee=(se,me)=>{if(z.has(se))throw new Error(`Cycle detected at part "${se}"`);z.add(se),O.set(se,me),H.add(se);const Xe=g.get(se)??[];for(const it of Xe){const at=W(it.name),It=this.parts.get(it.child),tn=UJe(It.base,cPt(it,at),it.frame,me);Ee(it.child,tn)}z.delete(se)};for(const se of P){const me=this.parts.get(se);Ee(se,me.base)}if(H.size!==this.parts.size){const se=[...this.parts.keys()].filter(me=>!H.has(me));throw new Error(`Assembly graph unresolved for parts: ${se.join(", ")}`)}return new FWe(this.name,this.parts,O,re,T)}sweepJoint(o,f,g,T,P={},O={}){if(!this.joints.has(o))throw new Error(`Unknown joint "${o}"`);if(this.jointCouplings.has(o))throw new Error(`Cannot sweep coupled joint "${o}". Sweep one of its source joints instead.`);const z=Math.max(1,Math.floor(T)),H=[];for(let re=0;re<=z;re++){const te=z===0?0:re/z,W=f+(g-f)*te,Ee=this.solve({...P,[o]:W});H.push({value:W,collisions:Ee.collisionReport(O),warnings:Ee.warnings()})}return H}describe(){return{name:this.name,parts:[...this.parts.values()].map(o=>({name:o.name,part:o.part,base:o.base,metadata:o.metadata?{...o.metadata}:void 0})),joints:[...this.joints.values()].map(o=>({name:o.name,type:o.type,parent:o.parent,child:o.child,frame:o.frame,axis:[...o.axis],min:o.min,max:o.max,defaultValue:o.defaultValue,unit:o.unit,effort:o.effort,velocity:o.velocity,damping:o.damping,friction:o.friction})),jointCouplings:[...this.jointCouplings.values()].map(o=>({joint:o.joint,terms:o.terms.map(f=>({joint:f.joint,ratio:f.ratio})),offset:o.offset}))}}}function uPt(l){return new OWe(l)}let rne=null;function _Pt(l){return l?Object.fromEntries(Object.entries(l).map(([o,f])=>[o,{...f}])):{}}function fPt(l){return l?Object.fromEntries(Object.entries(l).map(([o,f])=>[o,{...f}])):{}}function pPt(l){if(l)return{...l,leftJoints:[...l.leftJoints],rightJoints:[...l.rightJoints]}}function dPt(l){if(l)return{...l,joints:l.joints?[...l.joints]:void 0}}function mPt(l){return l?{...l,spawnPose:l.spawnPose?[...l.spawnPose]:void 0,keyboardTeleop:l.keyboardTeleop?{...l.keyboardTeleop}:void 0}:null}function GS(l,o){if(l!==void 0&&!Number.isFinite(l))throw new Error(`${o} must be finite`)}function hPt(l){return new Map(l.joints.map(o=>[o.name,o]))}function gPt(){rne=null}function $ze(){return rne}function yPt(l){var re,te,W,Ee;if(!l||typeof l!="object")throw new Error("robotExport(...) expects an options object");if(!l.assembly||typeof l.assembly.describe!="function")throw new Error("robotExport(...) requires an assembly");const o=l.assembly.describe(),f=new Set(o.parts.map(se=>se.name)),g=hPt(o),T=_Pt(l.links);for(const[se,me]of Object.entries(T)){if(!f.has(se))throw new Error(`robotExport(...) unknown link "${se}"`);GS(me.massKg,`robotExport link "${se}" massKg`),GS(me.densityKgM3,`robotExport link "${se}" densityKgM3`)}const P=fPt(l.joints);for(const[se,me]of Object.entries(P)){if(!g.has(se))throw new Error(`robotExport(...) unknown joint "${se}"`);GS(me.effort,`robotExport joint "${se}" effort`),GS(me.velocity,`robotExport joint "${se}" velocity`),GS(me.damping,`robotExport joint "${se}" damping`),GS(me.friction,`robotExport joint "${se}" friction`)}const O=pPt((re=l.plugins)==null?void 0:re.diffDrive);if(O){if(O.leftJoints.length===0||O.rightJoints.length===0)throw new Error("robotExport(...) diffDrive requires at least one left joint and one right joint");if(GS(O.wheelSeparationMm,"robotExport(...) diffDrive wheelSeparationMm"),GS(O.wheelRadiusMm,"robotExport(...) diffDrive wheelRadiusMm"),O.wheelSeparationMm<=0||O.wheelRadiusMm<=0)throw new Error("robotExport(...) diffDrive wheel separation and radius must be > 0");[...O.leftJoints,...O.rightJoints].forEach(se=>{const me=g.get(se);if(!me)throw new Error(`robotExport(...) diffDrive references unknown joint "${se}"`);if(me.type!=="revolute")throw new Error(`robotExport(...) diffDrive joint "${se}" must be revolute`)})}const z=dPt((te=l.plugins)==null?void 0:te.jointStatePublisher);z!=null&&z.joints&&z.joints.forEach(se=>{if(!g.has(se))throw new Error(`robotExport(...) jointStatePublisher references unknown joint "${se}"`)});const H=mPt(l.world);return H!=null&&H.spawnPose&&H.spawnPose.forEach((se,me)=>GS(se,`robotExport(...) world spawnPose[${me}]`)),GS((W=H==null?void 0:H.keyboardTeleop)==null?void 0:W.linearStep,"robotExport(...) world keyboardTeleop.linearStep"),GS((Ee=H==null?void 0:H.keyboardTeleop)==null?void 0:Ee.angularStep,"robotExport(...) world keyboardTeleop.angularStep"),rne={modelName:(l.modelName??o.name??"ForgeCAD Robot").trim()||"ForgeCAD Robot",assembly:o,state:{...l.state??{}},static:l.static??!1,selfCollide:l.selfCollide??!1,allowAutoDisable:l.allowAutoDisable??!0,links:T,joints:P,plugins:{diffDrive:O,jointStatePublisher:z},world:H},rne}var Hze=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function vPt(l){if(Object.prototype.hasOwnProperty.call(l,"__esModule"))return l;var o=l.default;if(typeof o=="function"){var f=function g(){return this instanceof g?Reflect.construct(o,arguments,this.constructor):o.apply(this,arguments)};f.prototype=o.prototype}else f={};return Object.defineProperty(f,"__esModule",{value:!0}),Object.keys(l).forEach(function(g){var T=Object.getOwnPropertyDescriptor(l,g);Object.defineProperty(f,g,T.get?T:{enumerable:!0,get:function(){return l[g]}})}),f}function Gze(l){throw new Error('Could not dynamically require "'+l+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Rbe={exports:{}},bPt={},xPt=Object.freeze({__proto__:null,default:bPt}),VD=vPt(xPt),Xze;function SPt(){return Xze||(Xze=1,(function(l){var o={};/*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use