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 Vbt=Object.defineProperty;var Ubt=(l,_,g)=>_ in l?Vbt(l,_,{enumerable:!0,configurable:!0,writable:!0,value:g}):l[_]=g;var of=(l,_,g)=>Ubt(l,typeof _!="symbol"?_+"":_,g);function fve(l,_){return[l[0]-_[0],l[1]-_[1],l[2]-_[2]]}function qJ(l,_){return[l[0]*_,l[1]*_,l[2]*_]}function pve(l,_){return l[0]*_[0]+l[1]*_[1]+l[2]*_[2]}function $bt(l,_){return[l[1]*_[2]-l[2]*_[1],l[2]*_[0]-l[0]*_[2],l[0]*_[1]-l[1]*_[0]]}function aee(l){return Math.hypot(l[0],l[1],l[2])}function GRe(l,_){const g=pve(l,_);return{axial:g,radial:fve(l,qJ(_,g))}}function oee(l,_,g){const S=aee(l),D=aee(_);if(S<1e-10||D<1e-10)return 0;const F=qJ(l,1/S),z=qJ(_,1/D),ee=pve(g,$bt(F,z)),pe=pve(F,z);return Math.atan2(ee,pe)*180/Math.PI}function Hbt(l,_,g){const S=oee(l,_,g),D=oee(l,qJ(_,-1),g);return Math.abs(S)<=Math.abs(D)?S:D}function fBe(l,_,g,S,D={}){const F=D.mode??"plane",z=Hve(l),ee=fve(g,_),pe=fve(S,_),we=GRe(ee,z),De=GRe(pe,z),te=aee(we.radial),nt=aee(De.radial);if(te<1e-10){if(F==="line"&&nt>=1e-10)throw new Error("rotateAroundTo(...): moving point lies on the rotation axis, so line alignment is impossible");return 0}if(F==="plane"){if(nt<1e-10)throw new Error("rotateAroundTo(...): target point lies on the rotation axis, so the target plane is undefined");return oee(we.radial,De.radial,z)}if(nt<1e-10)throw new Error("rotateAroundTo(...): target line lies on the rotation axis, but the moving point does not");const Te=1e-8*Math.max(1,Math.abs(we.axial),Math.abs(De.axial)),Me=1e-8*Math.max(1,te,nt);if(Math.abs(De.axial)<Te){if(Math.abs(we.axial)>Te)throw new Error("rotateAroundTo(...): target line stays on the pivot plane, but the moving point has axial offset");return Hbt(we.radial,De.radial,z)}const bt=we.axial/De.axial,vt=Math.abs(bt)*nt;if(Math.abs(te-vt)>Me)throw new Error("rotateAroundTo(...): moving point cannot reach the target line while preserving radius around the axis");const Bt=bt>=0?De.radial:qJ(De.radial,-1);return oee(we.radial,Bt,z)}function Gbt(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function Xbt(l){return l instanceof Sa?l.toArray():l}function Qbt(l,_){const g=new Array(16).fill(0);for(let S=0;S<4;S++)for(let D=0;D<4;D++){let F=0;for(let z=0;z<4;z++)F+=l[z*4+D]*_[S*4+z];g[S*4+D]=F}return g}function Hve(l){const _=Math.sqrt(l[0]*l[0]+l[1]*l[1]+l[2]*l[2]);if(_<1e-10)throw new Error("Axis must be non-zero");return[l[0]/_,l[1]/_,l[2]/_]}function XRe(l,_,g){const S=_[0],D=_[1],F=_[2];return[l[0]*S+l[4]*D+l[8]*F+l[12]*g,l[1]*S+l[5]*D+l[9]*F+l[13]*g,l[2]*S+l[6]*D+l[10]*F+l[14]*g]}function Ybt(l){const _=new Array(16),g=l[0],S=l[1],D=l[2],F=l[3],z=l[4],ee=l[5],pe=l[6],we=l[7],De=l[8],te=l[9],nt=l[10],Te=l[11],Me=l[12],bt=l[13],vt=l[14],Bt=l[15],fr=g*ee-S*z,hn=g*pe-D*z,vr=g*we-F*z,Xt=S*pe-D*ee,Wt=S*we-F*ee,Hn=D*we-F*pe,zn=De*bt-te*Me,Fs=De*vt-nt*Me,Jn=De*Bt-Te*Me,oc=te*vt-nt*bt,ro=te*Bt-Te*bt,Br=nt*Bt-Te*vt,pc=fr*Br-hn*ro+vr*oc+Xt*Jn-Wt*Fs+Hn*zn;if(Math.abs(pc)<1e-10)throw new Error("Transform matrix is not invertible");const eo=1/pc;return _[0]=(ee*Br-pe*ro+we*oc)*eo,_[1]=(D*ro-S*Br-F*oc)*eo,_[2]=(bt*Hn-vt*Wt+Bt*Xt)*eo,_[3]=(nt*Wt-te*Hn-Te*Xt)*eo,_[4]=(pe*Jn-z*Br-we*Fs)*eo,_[5]=(g*Br-D*Jn+F*Fs)*eo,_[6]=(vt*vr-Me*Hn-Bt*hn)*eo,_[7]=(De*Hn-nt*vr+Te*hn)*eo,_[8]=(z*ro-ee*Jn+we*zn)*eo,_[9]=(S*Jn-g*ro-F*zn)*eo,_[10]=(Me*Wt-bt*vr+Bt*fr)*eo,_[11]=(te*vr-De*Wt-Te*fr)*eo,_[12]=(ee*Fs-z*oc-pe*zn)*eo,_[13]=(g*oc-S*Fs+D*zn)*eo,_[14]=(bt*hn-Me*Xt-vt*fr)*eo,_[15]=(De*Xt-te*hn+nt*fr)*eo,_}class Sa{constructor(_){of(this,"m");this.m=_}static identity(){return new Sa(Gbt())}static from(_){return _ instanceof Sa?_:new Sa(_)}static translation(_,g,S){return new Sa([1,0,0,0,0,1,0,0,0,0,1,0,_,g,S,1])}static scale(_){const g=typeof _=="number"?_:_[0],S=typeof _=="number"?_:_[1],D=typeof _=="number"?_:_[2];return new Sa([g,0,0,0,0,S,0,0,0,0,D,0,0,0,0,1])}static rotationAxis(_,g,S=[0,0,0]){const[D,F,z]=Hve(_),ee=g*Math.PI/180,pe=Math.cos(ee),we=Math.sin(ee),De=pe+D*D*(1-pe),te=D*F*(1-pe)-z*we,nt=D*z*(1-pe)+F*we,Te=F*D*(1-pe)+z*we,Me=pe+F*F*(1-pe),bt=F*z*(1-pe)-D*we,vt=z*D*(1-pe)-F*we,Bt=z*F*(1-pe)+D*we,fr=pe+z*z*(1-pe),[hn,vr,Xt]=S,Wt=hn-(De*hn+te*vr+nt*Xt),Hn=vr-(Te*hn+Me*vr+bt*Xt),zn=Xt-(vt*hn+Bt*vr+fr*Xt);return new Sa([De,Te,vt,0,te,Me,Bt,0,nt,bt,fr,0,Wt,Hn,zn,1])}static rotateAroundTo(_,g,S,D,F={}){const z=fBe(_,g,S,D,F);return Sa.rotationAxis(_,z,g)}mul(_){const g=Xbt(_);return new Sa(Qbt(g,this.m))}translate(_,g,S){return this.mul(Sa.translation(_,g,S))}rotateAxis(_,g,S=[0,0,0]){return this.mul(Sa.rotationAxis(_,g,S))}scale(_){return this.mul(Sa.scale(_))}inverse(){return new Sa(Ybt(this.m))}point(_){return XRe(this.m,_,1)}vector(_){return XRe(this.m,_,0)}toArray(){return[...this.m]}}function $p(l){return Hve(l)}function pBe(...l){let _=Sa.identity();for(const g of l)_=_.mul(g);return _}const Zbt={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 cee=["default"];function Gve(l){return l==="live"||l==="default"||l==="high"?l:"default"}function Kbt(){return cee[cee.length-1]??"default"}function mN(l){const _=Gve(Kbt());return Zbt[_]}function e2t(l,_){const g=Gve(l);cee.push(g);try{return _()}finally{cee.pop()}}function dBe(l,_,g){const S=Math.round(l*_);return Math.max(g,S)}function mBe(l,_,g){return Math.max(g,l*_)}function t2t(l){const _=Math.max(3,Math.floor(l)),g=mN().curves.splineSamplesScale;return dBe(_,g,3)}function r2t(l){const _=Math.max(4,Math.floor(l)),g=mN().curves.sweepPathSamplesScale;return dBe(_,g,4)}function gBe(l){const _=Math.max(.01,l),g=mN().curves.levelSetEdgeLengthScale;return mBe(_,g,.01)}function hBe(l){const _=Math.max(.01,l),g=mN().curves.boundsPaddingScale;return mBe(_,g,.01)}function n2t(l){const _=Math.max(0,Math.floor(l)),g=mN().smoothing.refineStepsScale;return Math.max(0,Math.round(_*g))}function i2t(l){const _=Math.max(1e-6,l),g=mN().smoothing.refineLengthScale;return Math.max(1e-6,_*g)}function s2t(l){const _=Math.max(1e-6,l),g=mN().smoothing.refineToleranceScale;return Math.max(1e-6,_*g)}const yBe=["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"],$K=new Set(yBe),a2t={center:"center",left:"x",right:"x",front:"y",back:"y",top:"z",bottom:"z"};function vBe(l){return $K.has(l)}function Pee(l){if($K.has(l))return l;const _=l.split("-").filter(Boolean);if(_.length===0)return null;if(_.length===1)return $K.has(_[0])?_[0]:null;const g=new Map;for(const D of _){const F=a2t[D];if(!F||F==="center")return null;const z=g.get(F);if(z&&z!==D)return null;g.set(F,D)}const S=[g.get("z"),g.get("y"),g.get("x")].filter(D=>D!=null).join("-");return $K.has(S)?S:null}function pP(l,_,g){const S=Pee(g);if(!S)throw new Error(`Unknown anchor "${g}". Valid anchors: ${yBe.join(", ")}`);const D=(l[0]+_[0])/2,F=(l[1]+_[1])/2,z=(l[2]+_[2])/2;switch(S){case"center":return[D,F,z];case"front":return[D,l[1],z];case"back":return[D,_[1],z];case"left":return[l[0],F,z];case"right":return[_[0],F,z];case"top":return[D,F,_[2]];case"bottom":return[D,F,l[2]];case"front-left":return[l[0],l[1],z];case"front-right":return[_[0],l[1],z];case"back-left":return[l[0],_[1],z];case"back-right":return[_[0],_[1],z];case"top-front":return[D,l[1],_[2]];case"top-back":return[D,_[1],_[2]];case"top-left":return[l[0],F,_[2]];case"top-right":return[_[0],F,_[2]];case"bottom-front":return[D,l[1],l[2]];case"bottom-back":return[D,_[1],l[2]];case"bottom-left":return[l[0],F,l[2]];case"bottom-right":return[_[0],F,l[2]];case"top-front-left":return[l[0],l[1],_[2]];case"top-front-right":return[_[0],l[1],_[2]];case"top-back-left":return[l[0],_[1],_[2]];case"top-back-right":return[_[0],_[1],_[2]];case"bottom-front-left":return[l[0],l[1],l[2]];case"bottom-front-right":return[_[0],l[1],l[2]];case"bottom-back-left":return[l[0],_[1],l[2]];case"bottom-back-right":return[_[0],_[1],l[2]];default:throw new Error(`Unhandled anchor normalization for "${S}"`)}}const lee=["points","edges","surfaces","objects"];function z_(l,_){if(!Array.isArray(l)||l.length<3)throw new Error(`${_} must be a [x, y, z] tuple`);const g=Number(l[0]),S=Number(l[1]),D=Number(l[2]);if(!Number.isFinite(g)||!Number.isFinite(S)||!Number.isFinite(D))throw new Error(`${_} must contain finite numbers`);return[g,S,D]}function o2t(l,_){return[(l[0]+_[0])/2,(l[1]+_[1])/2,(l[2]+_[2])/2]}function bBe(l){const _=Math.hypot(l[0],l[1],l[2]);return _<1e-10?[0,0,1]:[l[0]/_,l[1]/_,l[2]/_]}function c2t(l){return!!l&&typeof l=="object"&&"min"in l&&"max"in l}function l2t(l,_){if(c2t(l))return{min:z_(l.min,`${_}.min`),max:z_(l.max,`${_}.max`)};if(typeof l=="object"&&l!=null){if("boundingBox"in l&&typeof l.boundingBox=="function"){const g=l.boundingBox();return{min:z_(g.min,`${_}.min`),max:z_(g.max,`${_}.max`)}}if("_bbox"in l&&typeof l._bbox=="function"){const g=l._bbox();return{min:z_(g.min,`${_}.min`),max:z_(g.max,`${_}.max`)}}}throw new Error(`${_} must be a bounds object or a shape/group with a bounding box`)}function u2t(l,_){const g=Sa.from(_),[S,D,F]=l.min,[z,ee,pe]=l.max,we=[[S,D,F],[S,D,pe],[S,ee,F],[S,ee,pe],[z,D,F],[z,D,pe],[z,ee,F],[z,ee,pe]],De=[1/0,1/0,1/0],te=[-1/0,-1/0,-1/0];for(const nt of we){const Te=g.point(nt);De[0]=Math.min(De[0],Te[0]),De[1]=Math.min(De[1],Te[1]),De[2]=Math.min(De[2],Te[2]),te[0]=Math.max(te[0],Te[0]),te[1]=Math.max(te[1],Te[1]),te[2]=Math.max(te[2],Te[2])}return{min:De,max:te}}function YF(){return{points:{},edges:{},surfaces:{},objects:{}}}function xBe(l){const _=YF();for(const[g,S]of Object.entries(l.points))_.points[g]=z_(S,`points.${g}`);for(const[g,S]of Object.entries(l.edges))_.edges[g]={start:z_(S.start,`edges.${g}.start`),end:z_(S.end,`edges.${g}.end`)};for(const[g,S]of Object.entries(l.surfaces))_.surfaces[g]={center:z_(S.center,`surfaces.${g}.center`),normal:z_(S.normal,`surfaces.${g}.normal`)};for(const[g,S]of Object.entries(l.objects))_.objects[g]={min:z_(S.min,`objects.${g}.min`),max:z_(S.max,`objects.${g}.max`)};return _}function _2t(l={}){const _=YF();for(const[g,S]of Object.entries(l.points??{}))_.points[g]=z_(S,`points.${g}`);for(const[g,S]of Object.entries(l.edges??{}))_.edges[g]={start:z_(S.start,`edges.${g}.start`),end:z_(S.end,`edges.${g}.end`)};for(const[g,S]of Object.entries(l.surfaces??{}))_.surfaces[g]={center:z_(S.center,`surfaces.${g}.center`),normal:bBe(z_(S.normal,`surfaces.${g}.normal`))};for(const[g,S]of Object.entries(l.objects??{}))_.objects[g]=l2t(S,`objects.${g}`);return _}function SBe(...l){const _=YF();for(const g of l){for(const[S,D]of Object.entries(g.points))_.points[S]=z_(D,`points.${S}`);for(const[S,D]of Object.entries(g.edges))_.edges[S]={start:z_(D.start,`edges.${S}.start`),end:z_(D.end,`edges.${S}.end`)};for(const[S,D]of Object.entries(g.surfaces))_.surfaces[S]={center:z_(D.center,`surfaces.${S}.center`),normal:z_(D.normal,`surfaces.${S}.normal`)};for(const[S,D]of Object.entries(g.objects))_.objects[S]={min:z_(D.min,`objects.${S}.min`),max:z_(D.max,`objects.${S}.max`)}}return _}function f2t(l){return lee.some(_=>Object.keys(l[_]).length>0)}function QRe(l,_){return SBe(l,_2t(_))}function p2t(l,_){const g=Sa.from(_),S=YF();for(const[D,F]of Object.entries(l.points))S.points[D]=g.point(F);for(const[D,F]of Object.entries(l.edges))S.edges[D]={start:g.point(F.start),end:g.point(F.end)};for(const[D,F]of Object.entries(l.surfaces))S.surfaces[D]={center:g.point(F.center),normal:bBe(g.vector(F.normal))};for(const[D,F]of Object.entries(l.objects))S.objects[D]=u2t(F,_);return S}function wK(l,_){throw new Error(`Placement reference "${l}" ${_}`)}function YRe(l,_,g,S,D){switch(_){case"points":{const F=l.points[g];return F?(S!=null&&wK(D,"does not support selectors"),z_(F,`points.${g}`)):null}case"edges":{const F=l.edges[g];if(!F)return null;if(S==null||S==="midpoint"||S==="center")return o2t(F.start,F.end);if(S==="start")return z_(F.start,`edges.${g}.start`);if(S==="end")return z_(F.end,`edges.${g}.end`);wK(D,"supports only .start, .end, or .midpoint")}case"surfaces":{const F=l.surfaces[g];return F?(S!=null&&S!=="center"&&wK(D,"supports only .center"),z_(F.center,`surfaces.${g}.center`)):null}case"objects":{const F=l.objects[g];if(!F)return null;const ee=Pee(S??"center");return ee||wK(D,`supports only Anchor3D selectors (${["center","top","bottom","left","right","front","back"].join(", ")} ...)`),pP(F.min,F.max,ee)}default:return null}}function d2t(l,_){const g=_.trim();if(!g)return null;const S=g.split(".");if(S.length>=2&&lee.includes(S[0])){const F=S[0],z=S[1],ee=S.length>2?S.slice(2).join("."):void 0;return YRe(l,F,z,ee,g)}const D=lee.map(F=>({kind:F,point:YRe(l,F,g,void 0,g)})).filter(F=>F.point!=null);if(D.length===0)return null;if(D.length>1)throw new Error(`Placement reference "${g}" is ambiguous. Use one of: ${D.map(F=>`${F.kind}.${g}`).join(", ")}`);return D[0].point}function TBe(l,_){return _?Object.keys(l[_]).sort():lee.flatMap(g=>Object.keys(l[g]).sort().map(S=>`${g}.${S}`))}function fp(l){if(l)return{id:l.id,operation:l.operation}}function cb(l,_){return l==null||_==null?l==null&&_==null:l.id===_.id&&l.operation===_.operation}function Kl(l){if(l)switch(l.kind){case"canonical-face":return{kind:"canonical-face",face:l.face,owner:fp(l.owner)};case"tracked-face":return{kind:"tracked-face",faceName:l.faceName,owner:fp(l.owner)};case"face-ref":return{kind:"face-ref",faceName:l.faceName,owner:fp(l.owner)};case"propagated-face":return{kind:"propagated-face",rewriteId:l.rewriteId,outcome:l.outcome,source:Kl(l.source),owner:fp(l.owner)};case"created-face":return{kind:"created-face",rewriteId:l.rewriteId,operation:l.operation,slot:l.slot,owner:fp(l.owner)}}}function Tl(l){if(l)switch(l.kind){case"tracked-edge":return{kind:"tracked-edge",edgeName:l.edgeName,selector:l.selector,owner:fp(l.owner)};case"edge-ref":return{kind:"edge-ref",edgeName:l.edgeName,selector:l.selector,owner:fp(l.owner)};case"propagated-edge":return{kind:"propagated-edge",rewriteId:l.rewriteId,outcome:l.outcome,source:Tl(l.source),selector:l.selector,owner:fp(l.owner)};case"created-edge":return{kind:"created-edge",rewriteId:l.rewriteId,operation:l.operation,slot:l.slot,selector:l.selector,owner:fp(l.owner)}}}function Rk(l){if(l)return{rewriteId:l.rewriteId,operation:l.operation,owner:fp(l.owner),preservedFaces:l.preservedFaces.map(_=>({query:Kl(_.query),status:_.status,note:_.note})),preservedEdges:l.preservedEdges.map(_=>({query:Tl(_.query),status:_.status,note:_.note})),createdFaces:l.createdFaces.map(_=>({query:Kl(_.query),note:_.note})),createdEdges:l.createdEdges.map(_=>({query:Tl(_.query),note:_.note})),diagnostics:l.diagnostics.map(_=>({code:_.code,category:_.category,queryKind:_.queryKind,message:_.message,source:_.queryKind==="face"?Kl(_.source):Tl(_.source),query:_.queryKind==="face"?Kl(_.query):Tl(_.query)})),descendants:(l.descendants??[]).map(_=>{switch(_.queryKind){case"face":return{queryKind:"face",kind:_.kind,query:Kl(_.query),source:Kl(_.source),note:_.note};case"edge":return{queryKind:"edge",kind:_.kind,query:Tl(_.query),source:Tl(_.source),note:_.note};case"vertex":return{queryKind:"vertex",kind:_.kind,note:_.note}}})}}function IS(l,_){if(l==null||_==null)return l==null&&_==null;if(l.kind!==_.kind)return!1;switch(l.kind){case"canonical-face":return _.kind==="canonical-face"&&l.face===_.face&&cb(l.owner,_.owner);case"tracked-face":return _.kind==="tracked-face"&&l.faceName===_.faceName&&cb(l.owner,_.owner);case"face-ref":return _.kind==="face-ref"&&l.faceName===_.faceName&&cb(l.owner,_.owner);case"propagated-face":return _.kind==="propagated-face"&&l.rewriteId===_.rewriteId&&l.outcome===_.outcome&&IS(l.source,_.source)&&cb(l.owner,_.owner);case"created-face":return _.kind==="created-face"&&l.rewriteId===_.rewriteId&&l.operation===_.operation&&l.slot===_.slot&&cb(l.owner,_.owner)}}function qk(l,_){if(l==null||_==null)return l==null&&_==null;if(l.kind!==_.kind)return!1;switch(l.kind){case"tracked-edge":return _.kind==="tracked-edge"&&l.edgeName===_.edgeName&&l.selector===_.selector&&cb(l.owner,_.owner);case"edge-ref":return _.kind==="edge-ref"&&l.edgeName===_.edgeName&&l.selector===_.selector&&cb(l.owner,_.owner);case"propagated-edge":return _.kind==="propagated-edge"&&l.rewriteId===_.rewriteId&&l.outcome===_.outcome&&l.selector===_.selector&&qk(l.source,_.source)&&cb(l.owner,_.owner);case"created-edge":return _.kind==="created-edge"&&l.rewriteId===_.rewriteId&&l.operation===_.operation&&l.slot===_.slot&&l.selector===_.selector&&cb(l.owner,_.owner)}}function WJ(l){if(!l)return"none";const _=l.owner?` @${l.owner.operation}:${l.owner.id}`:"";switch(l.kind){case"canonical-face":return`canonical-face(${l.face})${_}`;case"tracked-face":return`tracked-face(${l.faceName})${_}`;case"face-ref":return`face-ref(${l.faceName??"unnamed"})${_}`;case"propagated-face":return`propagated-face(${l.outcome} <- ${WJ(l.source)})${_}`;case"created-face":return`created-face(${l.operation}:${l.slot})${_}`}}function VJ(l){if(!l)return"none";const _=l.owner?` @${l.owner.operation}:${l.owner.id}`:"",g=`#${l.selector}`;switch(l.kind){case"tracked-edge":return`tracked-edge(${l.edgeName}${g})${_}`;case"edge-ref":return`edge-ref(${l.edgeName??"unnamed"}${g})${_}`;case"propagated-edge":return`propagated-edge(${l.outcome} <- ${VJ(l.source)}${g})${_}`;case"created-edge":return`created-edge(${l.operation}:${l.slot}${g})${_}`}}function m2t(l){return Kl(l)}function dve(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:m2t(l.source)}}function TE(l){return l?{workplane:dve(l.workplane),u:l.u,v:l.v,protrude:l.protrude,selfAnchor:l.selfAnchor}:null}function g2t(l){return[...l]}function AS(l){return l?{matrix:g2t(l.matrix),placement:TE(l.placement)}:null}function uee(l){if(l)return[l[0],l[1]]}function ZRe(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 YJ=["top","right","bottom","left"],RF=1e-9;function EK(l){return Number.isFinite(l)&&l>0}function KRe(l){return Number.isFinite(l)&&l>=0}function mve(l){return[l[0],l[1],l[2]]}function eje(l){return l?mve(l):void 0}function _ee(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(_=>({edge:_.edge,length:_.length,angleDeg:_.angleDeg}))}:null}function HK(l){return`sheetMetal().flange("${l}", ...)`}function h2t(l){return Math.abs(l)<=RF?0:l}function fee(l){if(!EK(l.panel.width)||!EK(l.panel.height))return"sheetMetal() requires a positive finite panel width and height.";if(!EK(l.thickness))return"sheetMetal() requires a positive finite sheet thickness.";if(!KRe(l.bendRadius))return"sheetMetal() requires a finite non-negative bendRadius.";if(l.bendRadius<=RF)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(!KRe(l.cornerRelief.size))return"sheetMetal() corner relief size must be a finite non-negative value.";const _=new Set;for(const g of l.flanges){if(!YJ.includes(g.edge))return`sheetMetal() does not recognize flange edge "${String(g.edge)}".`;if(_.has(g.edge))return`${HK(g.edge)} can only be declared once.`;if(_.add(g.edge),!EK(g.length))return`${HK(g.edge)} requires a positive finite length.`;if(!Number.isFinite(g.angleDeg)||Math.abs(h2t(g.angleDeg)-90)>1e-6)return`${HK(g.edge)} v1 only supports 90 degree flanges.`}return null}function y2t(l){return new Map(l.flanges.map(_=>[_.edge,_]))}function v2t(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 HF(l){const _=fee(l);if(_)throw new Error(_);const g=y2t(l),S=Math.PI/2*(l.bendRadius+l.bendAllowance.kFactor*l.thickness),D=new Map;for(const F of YJ){const z=g.get(F);if(!z)continue;const ee=v2t(F),pe=g.has(ee.start)?l.cornerRelief.size:0,we=g.has(ee.end)?l.cornerRelief.size:0,te=(F==="top"||F==="bottom"?l.panel.width:l.panel.height)-pe-we;if(!(te>RF))throw new Error(`${HK(F)} loses all usable span after applying the defended rectangular corner relief size ${l.cornerRelief.size}.`);D.set(F,{edge:F,length:z.length,angleDeg:z.angleDeg,bendAllowance:S,trimStart:pe,trimEnd:we,span:te,centerAlongEdge:(pe-we)/2})}return{panelWidth:l.panel.width,panelHeight:l.panel.height,thickness:l.thickness,bendRadius:l.bendRadius,kFactor:l.bendAllowance.kFactor,bendAllowance:S,reliefSize:l.cornerRelief.size,flanges:D}}function b2t(l){const _=["panel"],g=HF(l);for(const S of YJ)g.flanges.has(S)&&_.push(`bend-${S}`,`flange-${S}`);return _}function x2t(l){return b2t(l).filter(_=>_==="panel"||_.startsWith("flange-"))}function S2t(l){return l==="panel"||l==="flange-top"||l==="flange-right"||l==="flange-bottom"||l==="flange-left"}function T2t(l,_,g,S){return{workplane:{origin:[l[0],l[1],l[2]],u:[_[0],_[1],_[2]],v:[g[0],g[1],g[2]],normal:[S[0],S[1],S[2]],source:{kind:"face-ref",faceName:"sheet-metal-placement"}},u:0,v:0,protrude:0,selfAnchor:"center"}}function k2t(l,_,g,S){return Math.abs(_)<=RF&&Math.abs(g)<=RF&&Math.abs(S)<=RF?s_(l):E1(s_(l),{kind:"translate",x:_,y:g,z:S})}function DK(l,_,g,S,D){const F=T2t(_,g,S,D),z=[g[0],g[1],g[2],0,S[0],S[1],S[2],0,D[0],D[1],D[2],0,_[0],_[1],_[2],1];return E1(s_(l),{kind:"workplanePlacement",matrix:z,placement:F})}function G2(l,_,g,S=0,D=0,F=0){return k2t({kind:"box",x:l,y:_,z:g,center:!0},S,D,F)}function C2t(l,_){const g=l+_,S=lb({kind:"circle",radius:g,transforms:[]},{kind:"translate",x:0,y:l}),D=lb({kind:"circle",radius:l,transforms:[]},{kind:"translate",x:0,y:l}),F=NS("difference",[S,D]),z=lb({kind:"rect",width:g,height:g,center:!1,transforms:[]},{kind:"translate",x:0,y:-_});return NS("intersection",[F,z])}function w2t(l){return{kind:"box",x:l.panelWidth,y:l.panelHeight,z:l.thickness,center:!0}}function E2t(l,_){const g=l.thickness,S=l.bendRadius,D=_.length;switch(_.edge){case"top":return G2(_.span,g,D,_.centerAlongEdge,l.panelHeight/2+S+g/2,-g/2-S-D/2);case"bottom":return G2(_.span,g,D,_.centerAlongEdge,-l.panelHeight/2-S-g/2,-g/2-S-D/2);case"right":return G2(g,_.span,D,l.panelWidth/2+S+g/2,_.centerAlongEdge,-g/2-S-D/2);case"left":return G2(g,_.span,D,-l.panelWidth/2-S-g/2,_.centerAlongEdge,-g/2-S-D/2)}}function D2t(l,_){const g=C2t(l.bendRadius,l.thickness);if(!g)return null;const S={kind:"extrude",profile:g,height:_.span,center:!1};switch(_.edge){case"top":return DK(S,[-l.panelWidth/2+_.trimStart,l.panelHeight/2,-l.thickness/2],[0,1,0],[0,0,-1],[1,0,0]);case"bottom":return DK(S,[-l.panelWidth/2+_.trimStart,-l.panelHeight/2,-l.thickness/2],[0,-1,0],[0,0,-1],[1,0,0]);case"right":return DK(S,[l.panelWidth/2,-l.panelHeight/2+_.trimStart,-l.thickness/2],[1,0,0],[0,0,-1],[0,1,0]);case"left":return DK(S,[-l.panelWidth/2,-l.panelHeight/2+_.trimStart,-l.thickness/2],[-1,0,0],[0,0,-1],[0,1,0])}}function P2t(l,_){const g=l.thickness,S=_.bendAllowance;switch(_.edge){case"top":return G2(_.span,S,g,_.centerAlongEdge,l.panelHeight/2+S/2,0);case"bottom":return G2(_.span,S,g,_.centerAlongEdge,-l.panelHeight/2-S/2,0);case"right":return G2(S,_.span,g,l.panelWidth/2+S/2,_.centerAlongEdge,0);case"left":return G2(S,_.span,g,-l.panelWidth/2-S/2,_.centerAlongEdge,0)}}function A2t(l,_){const g=l.thickness,S=_.bendAllowance,D=_.length;switch(_.edge){case"top":return G2(_.span,D,g,_.centerAlongEdge,l.panelHeight/2+S+D/2,0);case"bottom":return G2(_.span,D,g,_.centerAlongEdge,-l.panelHeight/2-S-D/2,0);case"right":return G2(D,_.span,g,l.panelWidth/2+S+D/2,_.centerAlongEdge,0);case"left":return G2(D,_.span,g,-l.panelWidth/2-S-D/2,_.centerAlongEdge,0)}}function N2t(l,_){const g=HF(l),S=[w2t(g)];for(const D of YJ){const F=g.flanges.get(D);if(F){if(_==="folded"){const z=D2t(g,F);z&&S.push(z),S.push(E2t(g,F));continue}S.push(P2t(g,F)),S.push(A2t(g,F))}}return S.length===1?S[0]:Sy("union",S)}function Nh(l,_,g,S,D,F,z="face",ee=[l],pe=S){return{name:l,center:mve(_),normal:mve(g),planar:S,uAxis:eje(D),vAxis:eje(F),semantic:z,memberNames:[...ee],coplanar:pe}}function I2t(l,_){const g=l.thickness,S=l.bendRadius,F=(S+g/2)/Math.sqrt(2);switch(_.edge){case"top":return Nh("bend-top",[_.centerAlongEdge,l.panelHeight/2+F,-l.thickness/2-S+F],[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 Nh("bend-bottom",[_.centerAlongEdge,-l.panelHeight/2-F,-l.thickness/2-S+F],[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 Nh("bend-right",[l.panelWidth/2+F,_.centerAlongEdge,-l.thickness/2-S+F],[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 Nh("bend-left",[-l.panelWidth/2-F,_.centerAlongEdge,-l.thickness/2-S+F],[-1/Math.sqrt(2),0,1/Math.sqrt(2)],!1,void 0,void 0,"set",["bend-left-inner","bend-left-outer"],!1)}}function F2t(l,_){const g=HF(l),S=[Nh("panel",[0,0,g.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0])];for(const D of YJ){const F=g.flanges.get(D);if(F){if(_==="folded"){switch(S.push(I2t(g,F)),D){case"top":S.push(Nh("flange-top",[F.centerAlongEdge,g.panelHeight/2+g.bendRadius+g.thickness,-g.thickness/2-g.bendRadius-F.length/2],[0,1,0],!0,[1,0,0],[0,0,-1]));break;case"bottom":S.push(Nh("flange-bottom",[F.centerAlongEdge,-g.panelHeight/2-g.bendRadius-g.thickness,-g.thickness/2-g.bendRadius-F.length/2],[0,-1,0],!0,[1,0,0],[0,0,1]));break;case"right":S.push(Nh("flange-right",[g.panelWidth/2+g.bendRadius+g.thickness,F.centerAlongEdge,-g.thickness/2-g.bendRadius-F.length/2],[1,0,0],!0,[0,1,0],[0,0,1]));break;case"left":S.push(Nh("flange-left",[-g.panelWidth/2-g.bendRadius-g.thickness,F.centerAlongEdge,-g.thickness/2-g.bendRadius-F.length/2],[-1,0,0],!0,[0,-1,0],[0,0,1]));break}continue}switch(D){case"top":S.push(Nh("bend-top",[F.centerAlongEdge,g.panelHeight/2+F.bendAllowance/2,g.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0])),S.push(Nh("flange-top",[F.centerAlongEdge,g.panelHeight/2+F.bendAllowance+F.length/2,g.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0]));break;case"bottom":S.push(Nh("bend-bottom",[F.centerAlongEdge,-g.panelHeight/2-F.bendAllowance/2,g.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0])),S.push(Nh("flange-bottom",[F.centerAlongEdge,-g.panelHeight/2-F.bendAllowance-F.length/2,g.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0]));break;case"right":S.push(Nh("bend-right",[g.panelWidth/2+F.bendAllowance/2,F.centerAlongEdge,g.thickness/2],[0,0,1],!0,[0,1,0],[-1,0,0])),S.push(Nh("flange-right",[g.panelWidth/2+F.bendAllowance+F.length/2,F.centerAlongEdge,g.thickness/2],[0,0,1],!0,[0,1,0],[-1,0,0]));break;case"left":S.push(Nh("bend-left",[-g.panelWidth/2-F.bendAllowance/2,F.centerAlongEdge,g.thickness/2],[0,0,1],!0,[0,-1,0],[1,0,0])),S.push(Nh("flange-left",[-g.panelWidth/2-F.bendAllowance-F.length/2,F.centerAlongEdge,g.thickness/2],[0,0,1],!0,[0,-1,0],[1,0,0]));break}}}return S}function gE(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 C_(l){return Object.is(l,-0)?0:l}function Xve(l){return l.map(_=>C_(_))}function PK(l){return[C_(l[0]),C_(l[1]),C_(l[2])]}function UJ(l){return AS({matrix:Xve(l.matrix),placement:TE(l.placement)})}function Aee(l){return fp(l)}function O2t(l){return{radius:C_(l.radius),depth:C_(l.depth)}}function M2t(l){return{radius:C_(l.radius),angleDeg:C_(l.angleDeg),depth:C_(l.depth)}}function L2t(l){return{designation:l.designation,pitch:l.pitch==null?void 0:C_(l.pitch),class:l.class,handedness:l.handedness,depth:l.depth==null?void 0:C_(l.depth),modeled:l.modeled}}function R2t(l){return{radius:C_(l.radius),counterbore:l.counterbore?O2t(l.counterbore):void 0,countersink:l.countersink?M2t(l.countersink):void 0,thread:l.thread?L2t(l.thread):void 0}}function $1e(l){switch(l.kind){case"through":case"blind":return{kind:l.kind,depth:C_(l.depth)};case"upToFace":return{kind:"upToFace",depth:C_(l.depth),face:Kl(l.face)}}}function tje(l){return l.kind==="two-sided"?{kind:"two-sided",forward:$1e(l.forward),reverse:$1e(l.reverse)}:$1e(l)}function j2t(l){return{scale:[C_(l.scale[0]),C_(l.scale[1])]}}function wm(l){return l.kind==="two-sided"?l.forward:l}function ub(l){return l.kind==="two-sided"?l.reverse:void 0}function ZJ(l){var S;const _=wm(l).depth,g=((S=ub(l))==null?void 0:S.depth)??0;return _+g}let gve=0;function B2t(l){return l.replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()||"shape"}function Nee(l){return gve+=1,{id:`shape-query-${B2t(l)}-${gve}`,operation:l}}function J2t(){gve=0}function z2t(l){const[_,g,S]=l,D=Math.hypot(_,g,S);if(D<1e-12)return Sa.identity().toArray();const F=_/D,z=g/D,ee=S/D,pe=1-2*F*F,we=-2*F*z,De=-2*F*ee,te=-2*z*F,nt=1-2*z*z,Te=-2*z*ee,Me=-2*ee*F,bt=-2*ee*z,vt=1-2*ee*ee;return[pe,te,Me,0,we,nt,bt,0,De,Te,vt,0,0,0,0,1]}function q2t(l){switch(l.kind){case"translate":return Sa.translation(l.x,l.y,l.z).toArray();case"rotate":return Sa.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg).toArray();case"scale":return Sa.scale([l.x,l.y,l.z]).toArray();case"rotateAround":return Sa.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]).toArray();case"mirror":return z2t([l.normalX,l.normalY,l.normalZ])}}function W2t(l,_){const g=q2t(_),S=Sa.from(g),D=UJ(l);return{matrix:Xve(Sa.from(D.matrix).mul(g).toArray()),placement:{...D.placement,workplane:{...D.placement.workplane,origin:PK(S.point(D.placement.workplane.origin)),u:PK(S.vector(D.placement.workplane.u)),v:PK(S.vector(D.placement.workplane.v)),normal:PK(S.vector(D.placement.workplane.normal))}}}}function GK(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:Xve(l.matrix),placement:TE(l.placement)}}}function kBe(l){return{kind:l.kind,points:l.points.map(([_,g,S])=>[_,g,S])}}function Cd(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(gE)};case"roundedRect":return{kind:"roundedRect",width:l.width,height:l.height,radius:l.radius,center:l.center,transforms:l.transforms.map(gE)};case"circle":return{kind:"circle",radius:l.radius,segments:l.segments,transforms:l.transforms.map(gE)};case"polygon":return{kind:"polygon",points:l.points.map(([_,g])=>[_,g]),transforms:l.transforms.map(gE)};case"boolean":return{kind:"boolean",op:l.op,profiles:l.profiles.map(_=>Cd(_)),transforms:l.transforms.map(gE)};case"offset":return{kind:"offset",base:Cd(l.base),delta:l.delta,join:l.join,transforms:l.transforms.map(gE)};case"hull":return{kind:"hull",profiles:l.profiles.map(_=>Cd(_)),transforms:l.transforms.map(gE)};case"project":return{kind:"project",sourceShape:s_(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?TE(l.sourcePlacement):void 0,replayProfile:l.replayProfile?Cd(l.replayProfile):void 0,replayReason:l.replayReason,transforms:l.transforms.map(gE)}}}function s_(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:Cd(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:_ee(l.model),output:l.output};case"shell":return{kind:"shell",base:s_(l.base),thickness:l.thickness,openFaces:[...l.openFaces],queryPropagation:Rk(l.queryPropagation)};case"hole":return{kind:"hole",base:s_(l.base),placement:UJ(l.placement),hole:R2t(l.hole),extent:tje(l.extent),queryPropagation:Rk(l.queryPropagation)};case"cut":return{kind:"cut",base:s_(l.base),placement:UJ(l.placement),profile:Cd(l.profile),extent:tje(l.extent),taper:l.taper?j2t(l.taper):void 0,queryPropagation:Rk(l.queryPropagation)};case"revolve":return{kind:"revolve",profile:Cd(l.profile),degrees:l.degrees,segments:l.segments};case"loft":return{kind:"loft",profiles:l.profiles.map(_=>Cd(_)),heights:l.heights.map(_=>_),edgeLength:l.edgeLength,boundsPadding:l.boundsPadding};case"sweep":return{kind:"sweep",profile:Cd(l.profile),path:kBe(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(_=>s_(_)),queryPropagation:Rk(l.queryPropagation)};case"transform":return{kind:"transform",base:s_(l.base),steps:l.steps.map(GK)};case"queryOwner":return{kind:"queryOwner",owner:Aee(l.owner),base:s_(l.base)};case"hull":return{kind:"hull",shapes:l.shapes.map(_=>s_(_)),points:l.points.map(([_,g,S])=>[_,g,S]),queryPropagation:Rk(l.queryPropagation)};case"trimByPlane":return{kind:"trimByPlane",base:s_(l.base),normalX:l.normalX,normalY:l.normalY,normalZ:l.normalZ,originOffset:l.originOffset,queryPropagation:Rk(l.queryPropagation)};case"fillet":return{kind:"fillet",base:s_(l.base),edge:Tl(l.edge),radius:l.radius,quadrant:uee(l.quadrant),segments:l.segments,resolvedEdge:ZRe(l.resolvedEdge),queryPropagation:Rk(l.queryPropagation)};case"chamfer":return{kind:"chamfer",base:s_(l.base),edge:Tl(l.edge),size:l.size,quadrant:uee(l.quadrant),resolvedEdge:ZRe(l.resolvedEdge),queryPropagation:Rk(l.queryPropagation)}}}function lb(l,_){if(!l)return null;const g=Cd(l);return g.transforms.push(gE(_)),g}function E1(l,_){return l?l.kind==="transform"?{kind:"transform",base:s_(l.base),steps:[...l.steps.map(GK),GK(_)]}:{kind:"transform",base:s_(l),steps:[GK(_)]}:null}function V2t(l,_){let g=s_(l);for(const S of _)g=E1(g,S);return g}function KJ(l,_){return l?{kind:"queryOwner",owner:Aee(_),base:s_(l)}:null}function kE(l,_){return l?KJ(l,Nee(_)):null}function Sy(l,_){return _.some(g=>g==null)?null:{kind:"boolean",op:l,shapes:_.map(g=>s_(g))}}function Iee(l){if(!l)return null;switch(l.kind){case"queryOwner":return Aee(l.owner);case"transform":case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":return Iee(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 U2t(l){const _=[],g=new Set;function S(D){if(D)switch(D.kind){case"queryOwner":g.has(D.owner.id)||(g.add(D.owner.id),_.push(Aee(D.owner))),S(D.base);return;case"transform":case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":S(D.base);return;case"boolean":for(const F of D.shapes)S(F);return;case"hull":for(const F of D.shapes)S(F);return;case"box":case"cylinder":case"sphere":case"extrude":case"sheetMetal":case"revolve":case"loft":case"sweep":return}}return S(l),_}function NJ(l){if(!l)return null;switch(l.kind){case"queryOwner":return NJ(l.base);case"transform":{let _=NJ(l.base);for(const g of l.steps){if(g.kind==="workplanePlacement"){_=UJ({matrix:g.matrix,placement:g.placement});continue}_&&(_=W2t(_,g))}return _}case"shell":case"fillet":case"chamfer":return NJ(l.base);case"hole":case"cut":return UJ(l.placement);case"trimByPlane":return NJ(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 NS(l,_){return _.some(g=>g==null)?null:{kind:"boolean",op:l,profiles:_.map(g=>Cd(g)),transforms:[]}}function CBe(l,_,g){return l?{kind:"offset",base:Cd(l),delta:_,join:g,transforms:[]}:null}function wBe(l){return l.some(_=>_==null)?null:{kind:"hull",profiles:l.map(_=>Cd(_)),transforms:[]}}function EBe(l,_=[]){return l.some(g=>g==null)?null:{kind:"hull",shapes:l.map(g=>s_(g)),points:_.map(([g,S,D])=>[g,S,D])}}function H1e(l,_,g){return l?{kind:"trimByPlane",base:s_(l),normalX:C_(_[0]),normalY:C_(_[1]),normalZ:C_(_[2]),originOffset:C_(g)}:null}function $2t(l,_,g,S,D){return!l||!_||!Number.isFinite(g)||!(g>0)||!Number.isFinite(D)||D<2?null:{kind:"fillet",base:s_(l),edge:Tl(_),radius:C_(g),quadrant:uee(S),segments:Math.max(2,Math.round(D))}}function H2t(l,_,g,S){return!l||!_||!Number.isFinite(g)||!(g>0)?null:{kind:"chamfer",base:s_(l),edge:Tl(_),size:C_(g),quadrant:uee(S)}}function G2t(l,_,g){return l.some(S=>S==null)?null:{kind:"loft",profiles:l.map(S=>Cd(S)),heights:_.map(S=>C_(S)),edgeLength:C_(g.edgeLength),boundsPadding:C_(g.boundsPadding)}}function X2t(l,_,g){return l?{kind:"sweep",profile:Cd(l),path:kBe(_),edgeLength:C_(g.edgeLength),boundsPadding:C_(g.boundsPadding),up:[C_(g.up[0]),C_(g.up[1]),C_(g.up[2])]}:null}function pee(l){var _;if(l===null)return"null";if(l===void 0)return"undefined";if(Array.isArray(l))return`Array(${l.length})`;if(typeof l=="object"){const g=(_=l.constructor)==null?void 0:_.name;return g&&g!=="Object"?g:"object"}return typeof l=="string"?`"${l}"`:typeof l}function DBe({apiName:l,inputs:_,minCount:g,itemName:S,usage:D,coerce:F}){const z=[];for(const ee of _)Array.isArray(ee)?z.push(...ee):z.push(ee);if(z.length<g){const ee=g===1?S:`${S}s`;throw new Error(`${l} requires at least ${g} ${ee}. ${D}`)}return z.map((ee,pe)=>{try{return F(ee)}catch(we){const De=we instanceof Error?we.message:String(we);throw new Error(`${l} argument ${pe+1}: ${De}`)}})}function gN(l,_){return{rewriteId:_.id,operation:l,owner:fp(_),preservedFaces:[],preservedEdges:[],createdFaces:[],createdEdges:[],diagnostics:[],descendants:[]}}function em(l,_,g,S,D,F){return{code:l,category:_,queryKind:g,message:S,source:g==="face"?Kl(D):Tl(D),query:g==="face"?Kl(F):Tl(F)}}function P1(l,_,g){return{kind:"propagated-face",rewriteId:_.id,outcome:g,source:Kl(l),owner:fp(_)}}function Fee(l,_,g){return{kind:"created-face",rewriteId:l.id,operation:_,slot:g,owner:fp(l)}}function GF(l,_,g){return{kind:"propagated-edge",rewriteId:_.id,outcome:g,source:Tl(l),selector:l.selector,owner:fp(_)}}function PBe(l,_,g,S="edge"){return{kind:"created-edge",rewriteId:l.id,operation:_,slot:g,selector:S,owner:fp(l)}}function A1(l,_,g={}){return{queryKind:"face",kind:l,query:Kl(_),source:Kl(g.source),note:g.note}}function $J(l,_,g={}){return{queryKind:"edge",kind:l,query:Tl(_),source:Tl(g.source),note:g.note}}function cg(l,_){l.descendants.push(_)}function Jk(){return{faces:new Map,blockedNames:new Map,supportedQueries:[],blockedQueries:[]}}function km(l){return[l[0],l[1],l[2]]}function uN(l){return{...l,normal:km(l.normal),center:km(l.center),query:Kl(l.query),uAxis:l.uAxis?km(l.uAxis):void 0,vAxis:l.vAxis?km(l.vAxis):void 0,descendant:l.descendant?Q2t(l.descendant):void 0}}function Q2t(l){return{kind:l.kind,semantic:l.semantic,memberCount:l.memberCount,memberNames:[...l.memberNames],coplanar:l.coplanar}}function Oee(l,_,g){return{kind:l==="face"&&_.length===1?"single":"face-set",semantic:l,memberCount:_.length,memberNames:[..._],coplanar:g}}function Y2t(l){if(l.length<=1)return!0;const _=l[0];if(_.planar===!1||!_.uAxis||!_.vAxis)return!1;const g=$p(_.normal),S=g[0]*_.center[0]+g[1]*_.center[1]+g[2]*_.center[2];for(const D of l.slice(1)){if(D.planar===!1||!D.uAxis||!D.vAxis)return!1;const F=$p(D.normal),z=Math.abs(g[0]*F[0]+g[1]*F[1]+g[2]*F[2]);if(Math.abs(z-1)>1e-6)return!1;const ee=g[0]*D.center[0]+g[1]*D.center[1]+g[2]*D.center[2];if(Math.abs(ee-S)>1e-6)return!1}return!0}function Z2t(l,_,g,S){return{...l,descendant:Oee(_,g,S)}}function K2t(l,_,g,S){const D=_.map(De=>uN(De)),F=D[0],z=Y2t(D),ee=D.reduce((De,te)=>[De[0]+te.center[0],De[1]+te.center[1],De[2]+te.center[2]],[0,0,0]),pe=Math.max(D.length,1),we={...F,name:l,center:[ee[0]/pe,ee[1]/pe,ee[2]/pe],query:Kl(g),planar:z?F.planar:!1,uAxis:z?F.uAxis:void 0,vAxis:z?F.vAxis:void 0};return Z2t(we,S,D.map(De=>De.name),z)}function XK(l){return{faces:new Map(Array.from(l.faces.entries(),([_,g])=>[_,uN(g)])),blockedNames:new Map(l.blockedNames),supportedQueries:l.supportedQueries.map(_=>Kl(_)),blockedQueries:l.blockedQueries.map(_=>({query:Kl(_.query),reason:_.reason}))}}function ABe(l,_){return _?l.some(g=>IS(g,_)):!1}function ext(l,_){return _?l.some(g=>IS(g.query,_)):!1}function dP(l,_){!_||ABe(l.supportedQueries,_)||l.supportedQueries.push(Kl(_))}function QK(l,_,g){!_||ext(l.blockedQueries,_)||l.blockedQueries.push({query:Kl(_),reason:g})}function txt(l,_){_&&(l.supportedQueries=l.supportedQueries.filter(g=>!IS(g,_)))}function Wu(l,_){const g=uN(_);g.descendant||(g.descendant=Oee("face",[g.name],g.planar!==!1)),l.faces.set(g.name,g),dP(l,_.query)}function G1e(l,_,g,S){const D=l.faces.get(_);D&&(D.query=Kl(g),l.faces.set(_,D),dP(l,g),dP(l,S))}function AK(l,_,g,S,D){const F=l.faces.get(_);F&&(F.query=Kl(g),F.descendant=Oee(S,[_],F.planar!==!1),l.faces.set(_,F),dP(l,g),dP(l,D))}function rje(l,_,g){const S=l.faces.get(_);S&&(txt(l,S.query),QK(l,S.query,g),l.faces.delete(_)),l.blockedNames.set(_,g)}function rxt(l,_,g){l.faces.has(_)&&l.faces.delete(_),l.blockedNames.set(_,g)}function nxt(l,_){const g=Sa.from(_);return{...l,center:g.point(l.center),normal:$p(g.vector(l.normal)),query:Kl(l.query),uAxis:l.uAxis?$p(g.vector(l.uAxis)):void 0,vAxis:l.vAxis?$p(g.vector(l.vAxis)):void 0}}function ixt(l,_){const g=XK(l);return g.faces=new Map(Array.from(g.faces.entries(),([S,D])=>[S,nxt(D,_)])),g}function sxt(l){switch(l.kind){case"translate":return Sa.translation(l.x,l.y,l.z).toArray();case"rotate":return Sa.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg).toArray();case"scale":return Sa.scale([l.x,l.y,l.z]).toArray();case"rotateAround":return Sa.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]).toArray();case"mirror":return NBe([l.normalX,l.normalY,l.normalZ]);case"workplanePlacement":return[...l.matrix]}}function NBe(l){const _=Math.hypot(l[0],l[1],l[2]);if(_<1e-12)return Sa.identity().toArray();const g=l[0]/_,S=l[1]/_,D=l[2]/_;return[1-2*g*g,-2*g*S,-2*g*D,0,-2*S*g,1-2*S*S,-2*S*D,0,-2*D*g,-2*D*S,1-2*D*D,0,0,0,0,1]}function dee(l){let _=Sa.identity();for(const g of l)switch(g.kind){case"translate":_=_.translate(g.x,g.y,0);break;case"rotate":_=_.rotateAxis([0,0,1],g.degrees);break;case"scale":_=_.scale([g.x,g.y,1]);break;case"mirror":_=_.mul(NBe([g.normalX,g.normalY,0]));break}return _.toArray()}function jk(l,_,g){const S=Sa.from(l).point([_,g,0]);return[S[0],S[1]]}function Qve(l,_){return[(l[0]+_[0])/2,(l[1]+_[1])/2]}function axt(l){if(l.length===0)return[0,0,0];const _=l.reduce((g,S)=>[g[0]+S[0],g[1]+S[1],g[2]+S[2]],[0,0,0]);return[_[0]/l.length,_[1]/l.length,_[2]/l.length]}function CJ(l,_){return[l[0]*_[0],l[1]*_[1]]}function wJ(l,_,g,S,D,F,z=0){return[l[0]+_[0]*S+g[0]*D+((F==null?void 0:F[0])??0)*z,l[1]+_[1]*S+g[1]*D+((F==null?void 0:F[1])??0)*z,l[2]+_[2]*S+g[2]*D+((F==null?void 0:F[2])??0)*z]}function oxt(l){const _=Math.hypot(l[0],l[1]);return _<1e-12?[1,0]:[l[0]/_,l[1]/_]}function hve(l,_){return[l[1]*_[2]-l[2]*_[1],l[2]*_[0]-l[0]*_[2],l[0]*_[1]-l[1]*_[0]]}function cxt(l){const _=$p(l),g=Math.abs(_[2])<.9?[0,0,1]:[0,1,0],S=$p(hve(g,_)),D=$p(hve(_,S));return{u:S,v:D}}function _P(l,_,g,S,D){const F=oxt([g[0]-_[0],g[1]-_[1]]),z=[F[1],-F[0]],ee=Qve(_,g);return{name:l,normal:[z[0],z[1],0],center:[ee[0],ee[1],S],planar:!0,uAxis:[F[0],F[1],0],vAxis:[0,0,1],query:Kl(D)}}function og(l,_){if(_)return{kind:"tracked-face",faceName:l,owner:_}}function lxt(l,_){const g=Jk(),S=l.center?-l.x/2:0,D=l.center?-l.y/2:0,F=S+l.x,z=D+l.y,ee=l.center?-l.z/2:0,pe=ee+l.z,we=[S,D],De=[F,D],te=[F,z],nt=[S,z],Te=og("top",_),Me=og("bottom",_);return Wu(g,{name:"top",normal:[0,0,1],center:[(S+F)/2,(D+z)/2,pe],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0],query:Te}),Wu(g,{name:"bottom",normal:[0,0,-1],center:[(S+F)/2,(D+z)/2,ee],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0],query:Me}),Wu(g,{..._P("side-bottom",we,De,(pe+ee)/2,og("side-bottom",_))}),Wu(g,{..._P("side-right",De,te,(pe+ee)/2,og("side-right",_))}),Wu(g,{..._P("side-top",te,nt,(pe+ee)/2,og("side-top",_))}),Wu(g,{..._P("side-left",nt,we,(pe+ee)/2,og("side-left",_))}),g}function uxt(l,_){const g=Jk(),S=l.center?-l.height/2:0,D=S+l.height,F=l.radiusTop??l.radius,z=(Math.abs(l.radius)+Math.abs(F))/2;return Wu(g,{name:"top",normal:[0,0,1],center:[0,0,D],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0],query:og("top",_)}),Wu(g,{name:"bottom",normal:[0,0,-1],center:[0,0,S],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0],query:og("bottom",_)}),Wu(g,{name:"side",normal:[1,0,0],center:[z,0,(D+S)/2],planar:!1,query:og("side",_)}),g}function _xt(l,_,g,S){const D=dee(l.transforms),F=l.center?-l.width/2:0,z=l.center?-l.height/2:0,ee=F+l.width,pe=z+l.height,we=jk(D,F,z),De=jk(D,ee,z),te=jk(D,ee,pe),nt=jk(D,F,pe),Te=Qve(we,te),Me=g?-_/2:0,bt=Me+_,vt=$p([De[0]-we[0],De[1]-we[1],0]),Bt=$p([nt[0]-we[0],nt[1]-we[1],0]),fr=Jk();return Wu(fr,{name:"top",normal:[0,0,1],center:[Te[0],Te[1],bt],planar:!0,uAxis:vt,vAxis:Bt,query:og("top",S)}),Wu(fr,{name:"bottom",normal:[0,0,-1],center:[Te[0],Te[1],Me],planar:!0,uAxis:vt,vAxis:[-Bt[0],-Bt[1],-Bt[2]],query:og("bottom",S)}),Wu(fr,_P("side-bottom",we,De,(bt+Me)/2,og("side-bottom",S))),Wu(fr,_P("side-right",De,te,(bt+Me)/2,og("side-right",S))),Wu(fr,_P("side-top",te,nt,(bt+Me)/2,og("side-top",S))),Wu(fr,_P("side-left",nt,we,(bt+Me)/2,og("side-left",S))),fr}function fxt(l,_,g,S){const D=Jk(),F=dee(l.transforms),z=Sa.from(F).point([0,0,0]),ee=Sa.from(F).point([l.radius,0,0]),pe=$p([ee[0]-z[0],ee[1]-z[1],0]),we=$p(Sa.from(F).vector([1,0,0])),De=$p(Sa.from(F).vector([0,1,0])),te=g?-_/2:0,nt=te+_;return Wu(D,{name:"top",normal:[0,0,1],center:[z[0],z[1],nt],planar:!0,uAxis:we,vAxis:De,query:og("top",S)}),Wu(D,{name:"bottom",normal:[0,0,-1],center:[z[0],z[1],te],planar:!0,uAxis:we,vAxis:[-De[0],-De[1],-De[2]],query:og("bottom",S)}),Wu(D,{name:"side",normal:pe,center:[ee[0],ee[1],(nt+te)/2],planar:!1,query:og("side",S)}),D}function pxt(l,_){switch(l.profile.kind){case"rect":case"roundedRect":return _xt(l.profile,l.height,l.center,_);case"circle":return fxt(l.profile,l.height,l.center,_);default:return Jk()}}function V2(l,_){var g;return(g=l==null?void 0:l.createdFaces.find(S=>S.query.slot===_))==null?void 0:g.query}function X1e(l,_){if(_)return l==null?void 0:l.descendants.find(g=>g.queryKind==="face"&&IS(g.query,_))}function EJ(l,_){var g;if(_)return(g=l==null?void 0:l.preservedFaces.find(S=>IS(S.query.source,_)))==null?void 0:g.query}function dxt(l){return`inner-${l}`}function IBe(l,_){const g=$2(l),S=[];for(const D of g.faces.keys())D==="top"&&_.includes("top")||D==="bottom"&&_.includes("bottom")||S.push(dxt(D));return S}function mxt(l,_){var S;const g=["wall"];return l.counterbore&&g.push("counterbore-wall","counterbore-floor"),l.countersink&&g.push("countersink-wall"),wm(_).kind==="blind"&&g.push("floor"),((S=ub(_))==null?void 0:S.kind)==="blind"&&g.push("cap"),g}function FBe(l,_,g){var D;const S=(()=>{switch(l.kind){case"circle":return["wall"];case"rect":case"roundedRect":return["wall-bottom","wall-right","wall-top","wall-left"];default:return[]}})();return wm(_).kind==="blind"&&S.push("floor"),((D=ub(_))==null?void 0:D.kind)==="blind"&&S.push("cap"),S}function gxt(l,_){const g=["entry-rim","forward-end-rim"];return ub(_)&&g.push("reverse-end-rim"),(l.counterbore||l.countersink)&&g.push("head-transition-rim"),g}function hxt(l,_,g){if(FBe(l,_).length===0)return[];const S=["entry-rim","forward-end-rim"];return ub(_)&&S.push("reverse-end-rim"),S}function jF(l,_){if(!_)return[];const g=new Set(l.faces.keys()),S=(()=>{switch(_.kind){case"tracked-face":return[_.faceName];case"face-ref":return _.faceName?[_.faceName]:[];case"canonical-face":switch(_.face){case"front":return g.has("side-bottom")?["side-bottom"]:g.has("side")?["side"]:[];case"back":return g.has("side-top")?["side-top"]:g.has("side")?["side"]:[];case"left":return g.has("side-left")?["side-left"]:g.has("side")?["side"]:[];case"right":return g.has("side-right")?["side-right"]:g.has("side")?["side"]:[];case"top":return g.has("top")?["top"]:[];case"bottom":return g.has("bottom")?["bottom"]:[]}case"created-face":return[_.slot];case"propagated-face":return jF(l,_.source)}})();return S.filter((D,F)=>g.has(D)&&S.indexOf(D)===F)}function yxt(l,_){switch(l){case"top":return _.has("bottom")?["bottom"]:[];case"bottom":return _.has("top")?["top"]:[];case"side-bottom":return _.has("side-top")?["side-top"]:[];case"side-top":return _.has("side-bottom")?["side-bottom"]:[];case"side-left":return _.has("side-right")?["side-right"]:[];case"side-right":return _.has("side-left")?["side-left"]:[];case"side":return _.has("side")?["side"]:[];default:return[]}}function nje(l,_){switch(_){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 ije(l){switch(l){case"host":return 3;case"up-to-face-target":return 2;case"through-exit":return 1}}function vxt(l){var _,g;return((_=l.counterbore)==null?void 0:_.depth)??((g=l.countersink)==null?void 0:g.depth)??0}function bxt(l,_){var D;const g=((D=ub(_))==null?void 0:D.depth)??0;if(g>0)return(wm(_).depth-g)/2;const S=vxt(l);return S+Math.max(wm(_).depth-S,0)/2}function xxt(l){var g;const _=((g=ub(l))==null?void 0:g.depth)??0;return(wm(l).depth-_)/2}function mee(l,_,g){if(!l)return[];const S=$2(l),D=new Set(S.faces.keys()),F=new Map,z=(De,te)=>{const nt=F.get(De);(!nt||ije(te)>ije(nt))&&F.set(De,te)},ee=jF(S,_),pe=wm(g);for(const De of ee)if(z(De,"host"),pe.kind==="through")for(const te of yxt(De,D))z(te,"through-exit");if(pe.kind==="upToFace")for(const De of jF(S,pe.face))z(De,"up-to-face-target");const we=ub(g);if((we==null?void 0:we.kind)==="upToFace")for(const De of jF(S,we.face))z(De,"up-to-face-target");return Array.from(F.entries()).map(([De,te])=>({name:De,reason:te})).sort((De,te)=>De.name.localeCompare(te.name))}function NK(l,_){var g;return _?cb((g=l.query)==null?void 0:g.owner,_):!0}function OBe(l,_,g,S){switch(S.kind){case"tracked-face":return _===S.faceName&&NK(g,S.owner);case"face-ref":return(S.faceName==null||_===S.faceName)&&NK(g,S.owner);case"canonical-face":return jF(l,S).includes(_)&&NK(g,S.owner);case"created-face":return _===S.slot&&NK(g,S.owner);case"propagated-face":return IS(g.query,S)||OBe(l,_,g,S.source)}}function Sxt(l,_){if(!_)return[];const g=new Set,S=[];for(const[D,F]of l.faces.entries())g.has(D)||OBe(l,D,F,_)&&(g.add(D),S.push({name:D,face:uN(F)}));return S}function Txt(l,_){return l.flatMap(g=>Sxt(g,_))}function kxt(l){if(l.length===0)return null;const _=[...new Set(l.map(g=>g.name))];return _.length===1?_[0]:null}function Cxt(l,_){return l??_}function wxt(l,_){const g=l.get(_.name);if(g){g.push(_);return}l.set(_.name,[_])}function Ext(l,_,g){for(const[S,D]of _.entries()){const F=D.length===1?D[0].query:{kind:"face-ref",faceName:S,owner:fp(g)},z=D.some(pe=>pe.semantic==="region")?"region":D.length>1?"set":D[0].semantic,ee=K2t(S,D.map(pe=>pe.face),F,z);Wu(l,ee);for(const pe of D){dP(l,pe.query);for(const we of pe.aliases)dP(l,we)}D.length>1&&dP(l,F)}}function yve(l,_){var g,S,D;if(!l)return Jk();switch(l.kind){case"queryOwner":return yve(l.base,_??l.owner);case"transform":{let F=yve(l.base,_);for(const z of l.steps)F=ixt(F,sxt(z));return F}case"box":return lxt(l,_);case"cylinder":return uxt(l,_);case"extrude":return pxt(l,_);case"sheetMetal":{const F=Jk();for(const z of F2t(l.model,l.output))Wu(F,{name:z.name,normal:km(z.normal),center:km(z.center),planar:z.planar,uAxis:z.uAxis?km(z.uAxis):void 0,vAxis:z.vAxis?km(z.vAxis):void 0,query:og(z.name,_),descendant:Oee(z.semantic,z.memberNames,z.coplanar)});return F}case"shell":{const F=XK($2(l.base));for(const[z,ee]of F.faces.entries()){const pe=EJ(l.queryPropagation,ee.query);pe&&G1e(F,z,pe,ee.query)}for(const z of IBe(l.base,l.openFaces)){const ee=z.slice(6),pe=F.faces.get(ee),we=V2(l.queryPropagation,z);!pe||!we||Wu(F,{...uN(pe),name:z,center:[pe.center[0]-pe.normal[0]*l.thickness,pe.center[1]-pe.normal[1]*l.thickness,pe.center[2]-pe.normal[2]*l.thickness],normal:[-pe.normal[0],-pe.normal[1],-pe.normal[2]],uAxis:pe.uAxis?km(pe.uAxis):void 0,vAxis:pe.vAxis?[-pe.vAxis[0],-pe.vAxis[1],-pe.vAxis[2]]:void 0,query:we})}return F}case"hole":{const F=XK($2(l.base));for(const[Bt,fr]of F.faces.entries()){const hn=EJ(l.queryPropagation,fr.query),vr=X1e(l.queryPropagation,hn);if(hn&&(vr==null?void 0:vr.kind)==="face-region"){AK(F,Bt,hn,"region",fr.query);continue}hn&&G1e(F,Bt,hn,fr.query)}for(const Bt of mee(l.base,l.placement.placement.workplane.source,l.extent)){const fr=F.faces.get(Bt.name);if(((g=fr==null?void 0:fr.descendant)==null?void 0:g.semantic)==="region")continue;const hn=fr?EJ(l.queryPropagation,fr.query):void 0;if(fr&&hn){AK(F,Bt.name,hn,"region",fr.query);continue}rje(F,Bt.name,nje("hole",Bt.reason))}const z=l.placement.placement.workplane,ee=z.origin,pe=[-z.normal[0],-z.normal[1],-z.normal[2]],we=wm(l.extent),De=ub(l.extent),te=V2(l.queryPropagation,"wall");if(te){const Bt=bxt(l.hole,l.extent);Wu(F,{name:"wall",normal:[-z.u[0],-z.u[1],-z.u[2]],center:[ee[0]+z.u[0]*l.hole.radius+pe[0]*Bt,ee[1]+z.u[1]*l.hole.radius+pe[1]*Bt,ee[2]+z.u[2]*l.hole.radius+pe[2]*Bt],planar:!1,query:te})}const nt=V2(l.queryPropagation,"counterbore-wall");nt&&l.hole.counterbore&&Wu(F,{name:"counterbore-wall",normal:[-z.u[0],-z.u[1],-z.u[2]],center:[ee[0]+z.u[0]*l.hole.counterbore.radius+pe[0]*(l.hole.counterbore.depth/2),ee[1]+z.u[1]*l.hole.counterbore.radius+pe[1]*(l.hole.counterbore.depth/2),ee[2]+z.u[2]*l.hole.counterbore.radius+pe[2]*(l.hole.counterbore.depth/2)],planar:!1,query:nt});const Te=V2(l.queryPropagation,"counterbore-floor");Te&&l.hole.counterbore&&Wu(F,{name:"counterbore-floor",normal:km(z.normal),center:[ee[0]+pe[0]*l.hole.counterbore.depth,ee[1]+pe[1]*l.hole.counterbore.depth,ee[2]+pe[2]*l.hole.counterbore.depth],planar:!0,uAxis:km(z.u),vAxis:km(z.v),query:Te});const Me=V2(l.queryPropagation,"countersink-wall");if(Me&&l.hole.countersink){const Bt=l.hole.countersink.depth/2,fr=(l.hole.radius+l.hole.countersink.radius)/2;Wu(F,{name:"countersink-wall",normal:[-z.u[0],-z.u[1],-z.u[2]],center:[ee[0]+z.u[0]*fr+pe[0]*Bt,ee[1]+z.u[1]*fr+pe[1]*Bt,ee[2]+z.u[2]*fr+pe[2]*Bt],planar:!1,query:Me})}const bt=V2(l.queryPropagation,"floor");bt&&Wu(F,{name:"floor",normal:km(z.normal),center:[ee[0]+pe[0]*we.depth,ee[1]+pe[1]*we.depth,ee[2]+pe[2]*we.depth],planar:!0,uAxis:km(z.u),vAxis:km(z.v),query:bt});const vt=V2(l.queryPropagation,"cap");return vt&&(De==null?void 0:De.kind)==="blind"&&Wu(F,{name:"cap",normal:[-z.normal[0],-z.normal[1],-z.normal[2]],center:[ee[0]-pe[0]*De.depth,ee[1]-pe[1]*De.depth,ee[2]-pe[2]*De.depth],planar:!0,uAxis:km(z.u),vAxis:[-z.v[0],-z.v[1],-z.v[2]],query:vt}),F}case"cut":{const F=XK($2(l.base));for(const[bt,vt]of F.faces.entries()){const Bt=EJ(l.queryPropagation,vt.query),fr=X1e(l.queryPropagation,Bt);if(Bt&&(fr==null?void 0:fr.kind)==="face-region"){AK(F,bt,Bt,"region",vt.query);continue}Bt&&G1e(F,bt,Bt,vt.query)}for(const bt of mee(l.base,l.placement.placement.workplane.source,l.extent)){const vt=F.faces.get(bt.name);if(((S=vt==null?void 0:vt.descendant)==null?void 0:S.semantic)==="region")continue;const Bt=vt?EJ(l.queryPropagation,vt.query):void 0;if(vt&&Bt){AK(F,bt.name,Bt,"region",vt.query);continue}rje(F,bt.name,nje("cut",bt.reason))}const z=l.placement.placement,ee=z.workplane.origin,pe=[-z.workplane.normal[0],-z.workplane.normal[1],-z.workplane.normal[2]],we=wm(l.extent),De=ub(l.extent),te=(De==null?void 0:De.depth)??0,nt=xxt(l.extent);if(l.profile.kind==="circle"){const bt=V2(l.queryPropagation,"wall");if(bt){const vt=l.profile.radius,Bt=l.taper?vt*l.taper.scale[0]:vt,fr=(vt+Bt)/2;Wu(F,{name:"wall",normal:[-z.workplane.u[0],-z.workplane.u[1],-z.workplane.u[2]],center:[ee[0]+z.workplane.u[0]*fr+pe[0]*nt,ee[1]+z.workplane.u[1]*fr+pe[1]*nt,ee[2]+z.workplane.u[2]*fr+pe[2]*nt],planar:!1,query:bt})}}if(l.profile.kind==="rect"||l.profile.kind==="roundedRect"){const bt=dee(l.profile.transforms),vt=l.profile.center?-l.profile.width/2:0,Bt=l.profile.center?-l.profile.height/2:0,fr=vt+l.profile.width,hn=Bt+l.profile.height,vr=jk(bt,vt,Bt),Xt=jk(bt,fr,Bt),Wt=jk(bt,fr,hn),Hn=jk(bt,vt,hn),zn=((D=l.taper)==null?void 0:D.scale)??[1,1],Fs=CJ(vr,zn),Jn=CJ(Xt,zn),oc=CJ(Wt,zn),ro=CJ(Hn,zn),Br=[{name:"wall-bottom",reverseStart:vr,reverseEnd:Xt,forwardStart:Fs,forwardEnd:Jn},{name:"wall-right",reverseStart:Xt,reverseEnd:Wt,forwardStart:Jn,forwardEnd:oc},{name:"wall-top",reverseStart:Wt,reverseEnd:Hn,forwardStart:oc,forwardEnd:ro},{name:"wall-left",reverseStart:Hn,reverseEnd:vr,forwardStart:ro,forwardEnd:Fs}];for(const pc of Br){const eo=V2(l.queryPropagation,pc.name);if(!eo)continue;const Gt=wJ(ee,z.workplane.u,z.workplane.v,pc.reverseStart[0],pc.reverseStart[1],pe,-te),fa=wJ(ee,z.workplane.u,z.workplane.v,pc.reverseEnd[0],pc.reverseEnd[1],pe,-te),Es=wJ(ee,z.workplane.u,z.workplane.v,pc.forwardStart[0],pc.forwardStart[1],pe,we.depth),Ho=wJ(ee,z.workplane.u,z.workplane.v,pc.forwardEnd[0],pc.forwardEnd[1],pe,we.depth),qi=$p([fa[0]-Gt[0],fa[1]-Gt[1],fa[2]-Gt[2]]),Yc=$p([Es[0]-Gt[0],Es[1]-Gt[1],Es[2]-Gt[2]]),Hp=$p(hve(qi,Yc));Wu(F,{name:pc.name,normal:Hp,center:axt([Gt,fa,Es,Ho]),planar:!0,uAxis:qi,vAxis:Yc,query:eo})}}const Te=V2(l.queryPropagation,"floor");if(Te){const bt=(()=>{if(l.profile.kind==="rect"||l.profile.kind==="roundedRect"){const vt=dee(l.profile.transforms),Bt=l.profile.center?-l.profile.width/2:0,fr=l.profile.center?-l.profile.height/2:0,hn=Bt+l.profile.width,vr=fr+l.profile.height,Xt=Qve(jk(vt,Bt,fr),jk(vt,hn,vr)),Wt=l.taper?CJ(Xt,l.taper.scale):Xt;return wJ(ee,z.workplane.u,z.workplane.v,Wt[0],Wt[1],pe,we.depth)}return[ee[0]+pe[0]*we.depth,ee[1]+pe[1]*we.depth,ee[2]+pe[2]*we.depth]})();Wu(F,{name:"floor",normal:km(z.workplane.normal),center:bt,planar:!0,uAxis:km(z.workplane.u),vAxis:km(z.workplane.v),query:Te})}const Me=V2(l.queryPropagation,"cap");return Me&&(De==null?void 0:De.kind)==="blind"&&Wu(F,{name:"cap",normal:[-z.workplane.normal[0],-z.workplane.normal[1],-z.workplane.normal[2]],center:[ee[0]-pe[0]*De.depth,ee[1]-pe[1]*De.depth,ee[2]-pe[2]*De.depth],planar:!0,uAxis:km(z.workplane.u),vAxis:[-z.workplane.v[0],-z.workplane.v[1],-z.workplane.v[2]],query:Me}),F}case"sphere":case"revolve":case"loft":case"sweep":case"hull":case"fillet":case"chamfer":return Jk();case"trimByPlane":{const F=Jk(),z=V2(l.queryPropagation,"plane-cap");if(!z)return F;const ee=$2(l.base),pe=Array.from(ee.faces.values()).map(Me=>Me.center),we=pe.length>0?pe.reduce((Me,bt)=>[Me[0]+bt[0],Me[1]+bt[1],Me[2]+bt[2]],[0,0,0]).map(Me=>Me/pe.length):[0,0,l.originOffset],De=$p([l.normalX,l.normalY,l.normalZ]),te=we[0]*De[0]+we[1]*De[1]+we[2]*De[2]-l.originOffset,nt=[we[0]-De[0]*te,we[1]-De[1]*te,we[2]-De[2]*te],Te=cxt(De);return Wu(F,{name:"plane-cap",normal:De,center:nt,planar:!0,uAxis:Te.u,vAxis:Te.v,query:z}),F}case"boolean":{const F=Jk(),z=l.shapes.map(we=>$2(we)),ee=l.queryPropagation;if(!ee)return F;const pe=new Map;for(const we of ee.preservedFaces){const De=Kl(we.query),te=Txt(z,we.query.source),nt=X1e(ee,De);if(we.status==="ambiguous"&&!nt){const Me=kxt(te),bt=Cxt(we.note,"This propagated boolean face lineage is ambiguous and is not part of the defended named-face subset.");for(const vt of te)QK(F,vt.face.query,bt);Me&&rxt(F,Me,bt),QK(F,we.query,bt),QK(F,we.query.kind==="propagated-face"?we.query.source:void 0,bt);continue}const Te=(nt==null?void 0:nt.kind)==="face-region"?"region":(nt==null?void 0:nt.kind)==="face-set"?"set":"face";for(const Me of te)wxt(pe,{name:Me.name,face:uN(Me.face),query:De,semantic:Te,aliases:[De,...we.query.kind==="propagated-face"?[we.query.source]:[],...Me.face.query?[Me.face.query]:[]].filter(bt=>bt!=null)})}return Ext(F,pe,ee.owner),F}}}function $2(l){return yve(l,Iee(l))}function Dxt(l){return Array.from($2(l).faces.keys()).sort()}function Pxt(l){const _=$2(l);return Array.from(_.faces.entries()).filter(([,g])=>g.query!=null).map(([g,S])=>({name:g,query:Kl(S.query)})).sort((g,S)=>g.name.localeCompare(S.name))}function sje(l,_){const S=$2(l).faces.get(_);return S?uN(S):null}function aje(l,_){const g=$2(l),S=g.blockedNames.get(_);if(S)return S;const D=Array.from(g.faces.keys()).sort();return`Face "${_}" is not available. Supported faces: ${D.join(", ")||"none"}`}function Axt(l,_){if(!_)return null;const g=$2(l);if(ABe(g.supportedQueries,_))return null;const S=jF(g,_);if(S.some(F=>g.faces.has(F)))return null;for(const F of S){const z=g.blockedNames.get(F);if(z)return z}const D=g.blockedQueries.find(F=>IS(F.query,_));return D?D.reason:_.kind==="created-face"||_.kind==="propagated-face"?"This face query is not part of the target shape's defended face subset.":S.length===0&&g.faces.size===0&&g.blockedQueries.length===0||_.kind==="tracked-face"||_.kind==="canonical-face"||_.kind==="face-ref"?null:"This face query is not part of the target shape's defended face subset."}function Nxt(l,_){return l?IBe(l,_).sort():[]}function Ixt(l,_){return mxt(l,_)}function Fxt(l,_,g){return FBe(l,_)}function Oxt(l,_){return gxt(l,_)}function Mxt(l,_,g){return hxt(l,_)}function Mee(l){return Pxt(l)}const Lxt=["front","back","left","right","top","bottom"];function Yve(l){if(!l)return null;switch(l.kind){case"queryOwner":case"transform":return Yve(l.base);case"shell":case"hole":case"cut":case"boolean":case"hull":case"trimByPlane":case"fillet":case"chamfer":return Rk(l.queryPropagation)??null;case"box":case"cylinder":case"sphere":case"extrude":case"sheetMetal":case"revolve":case"loft":case"sweep":return null}}function oje(l,_){const g=l.find(S=>IS(S.source,_.source));if(!g){l.push({source:Kl(_.source),status:_.status});return}_.status==="ambiguous"&&(g.status="ambiguous")}function cje(l,_){const g=l.find(S=>qk(S.source,_.source));if(!g){l.push({source:Tl(_.source),status:_.status});return}_.status==="ambiguous"&&(g.status="ambiguous")}function Rxt(l){return l?Lxt.map(_=>({source:{kind:"canonical-face",face:_,owner:fp(l)},status:"supported"})):[]}function jxt(l){const _=Yve(l);if(!_)return Rxt(Iee(l));const g=[];for(const S of _.preservedFaces)oje(g,{source:S.query,status:S.status});for(const S of _.createdFaces)oje(g,{source:S.query,status:"supported"});return g}function Bxt(l){const _=Yve(l);if(!_)return[];const g=[];for(const S of _.preservedEdges)cje(g,{source:S.query,status:S.status});for(const S of _.createdEdges)cje(g,{source:S.query,status:"supported"});return g}function Jxt(l){const _=[];for(const g of l){const S=_.find(D=>IS(D.source,g.source));if(S){S.count+=1,S.hasAmbiguousSource=S.hasAmbiguousSource||g.status==="ambiguous";continue}_.push({source:Kl(g.source),count:1,hasAmbiguousSource:g.status==="ambiguous"})}return _}function zxt(l){const _=[];for(const g of l){const S=_.find(D=>qk(D.source,g.source));if(S){S.count+=1,S.hasAmbiguousSource=S.hasAmbiguousSource||g.status==="ambiguous";continue}_.push({source:Tl(g.source),count:1,hasAmbiguousSource:g.status==="ambiguous"})}return _}function Zve(l,_){const g=_?l:l.slice(0,1);return Jxt(g.flatMap(S=>jxt(S)))}function Kve(l,_){const g=_?l:l.slice(0,1);return zxt(g.flatMap(S=>Bxt(S)))}function ebe(l,_){const g=_==="union"?"Boolean union preserved owner lineage, but none of its operands exposed defended face queries in the supported subset.":_==="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(em(`boolean-${_}-face-propagation-unsupported`,"unsupported","face",g))}function tbe(l,_){const g=_==="union"?"Boolean union preserved owner lineage, but none of its operands exposed defended edge queries in the supported subset.":_==="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(em(`boolean-${_}-edge-propagation-unsupported`,"unsupported","edge",g))}function qxt(l,_,g){const S=Zve(g,!0);if(S.length===0){ebe(_,"union");return}for(const D of S){if(D.count===1&&!D.hasAmbiguousSource){const z=P1(D.source,l,"preserved");_.preservedFaces.push({query:z,status:"supported"}),cg(_,A1("single",z,{source:D.source,note:"Boolean union keeps one defended single face descendant for this lineage."}));continue}const F=P1(D.source,l,D.count>1?"merged":"preserved");_.preservedFaces.push({query:F,status:"ambiguous"}),D.count>1&&!D.hasAmbiguousSource&&cg(_,A1("face-set",F,{source:D.source,note:"Boolean union keeps a defended descendant face set for this merged lineage."})),_.diagnostics.push(em(D.count>1?"boolean-union-face-merged-ambiguous":"boolean-union-face-inherited-ambiguity","ambiguous","face",D.count>1?`Boolean union cannot defend ${WJ(D.source)} because ${D.count} operand descendants share that face lineage and may merge.`:`Boolean union inherits ${WJ(D.source)} from an already-ambiguous rewrite result, so the post-union descendant remains ambiguous.`,D.source,F))}}function Wxt(l,_,g){const S=Kve(g,!0);if(S.length===0){tbe(_,"union");return}for(const D of S){if(D.count===1&&!D.hasAmbiguousSource){const z=GF(D.source,l,"preserved");_.preservedEdges.push({query:z,status:"supported"}),cg(_,$J("single",z,{source:D.source,note:"Boolean union keeps one defended single edge descendant for this lineage."}));continue}const F=GF(D.source,l,D.count>1?"merged":"preserved");_.preservedEdges.push({query:F,status:"ambiguous"}),_.diagnostics.push(em(D.count>1?"boolean-union-edge-merged-ambiguous":"boolean-union-edge-inherited-ambiguity","ambiguous","edge",D.count>1?`Boolean union cannot defend ${VJ(D.source)} because ${D.count} operand descendants share that edge lineage and may merge.`:`Boolean union inherits ${VJ(D.source)} from an already-ambiguous rewrite result, so the post-union descendant remains ambiguous.`,D.source,F))}}function Vxt(l,_,g){const S=Zve(g,!1);if(S.length===0){ebe(_,"difference");return}for(const D of S){const F=P1(D.source,l,"split");_.preservedFaces.push({query:F,status:"ambiguous"}),cg(_,A1("face-region",F,{source:D.source,note:"Boolean difference keeps a defended descendant region on the source surface."})),_.diagnostics.push(em("boolean-difference-face-split-ambiguous","ambiguous","face",`Boolean difference can trace ${WJ(D.source)} to the base operand, but subtractive cutters may split or erase its surviving descendants.`,D.source,F))}}function Uxt(l,_,g){const S=Kve(g,!1);if(S.length===0){tbe(_,"difference");return}for(const D of S){const F=GF(D.source,l,"split");_.preservedEdges.push({query:F,status:"ambiguous"}),_.diagnostics.push(em("boolean-difference-edge-split-ambiguous","ambiguous","edge",`Boolean difference can trace ${VJ(D.source)} to the base operand, but subtractive cutters may split or erase its surviving descendants.`,D.source,F))}}function $xt(l,_,g){const S=Zve(g,!0);if(S.length===0){ebe(_,"intersection");return}for(const D of S){const F=P1(D.source,l,"split");_.preservedFaces.push({query:F,status:"ambiguous"}),cg(_,A1("face-region",F,{source:D.source,note:"Boolean intersection keeps a defended descendant region on the source surface."})),_.diagnostics.push(em("boolean-intersection-face-split-ambiguous","ambiguous","face",`Boolean intersection can trace ${WJ(D.source)}, but the kept overlap is only a clipped descendant subset and cannot be defended as one stable face target.`,D.source,F))}}function Hxt(l,_,g){const S=Kve(g,!0);if(S.length===0){tbe(_,"intersection");return}for(const D of S){const F=GF(D.source,l,"split");_.preservedEdges.push({query:F,status:"ambiguous"}),_.diagnostics.push(em("boolean-intersection-edge-split-ambiguous","ambiguous","edge",`Boolean intersection can trace ${VJ(D.source)}, but the kept overlap is only a clipped descendant subset and cannot be defended as one stable edge target.`,D.source,F))}}function lP(l,_,g){const S=gN(`boolean:${l}`,_);switch(l){case"union":return qxt(_,S,g),Wxt(_,S,g),S;case"difference":return Vxt(_,S,g),Uxt(_,S,g),S;case"intersection":return $xt(_,S,g),Hxt(_,S,g),S}}function MBe(l,_){switch(_){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 Gxt(l,_,g){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 S=wm(g);return S.kind==="blind"?"Blind holes record the floor perimeter as a defended descendant edge chain.":S.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 S=ub(g);return(S==null?void 0:S.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 _.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 Xxt(l,_){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 g=wm(_);return g.kind==="blind"?"Blind cutouts record the floor perimeter as a defended descendant edge chain.":g.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 g=ub(_);return(g==null?void 0:g.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 LBe(l,_,g,S){const D=wm(S);D.kind==="upToFace"&&l.diagnostics.push(em(`${g}-up-to-face-target-split-ambiguous`,"ambiguous","face",`${g==="hole"?"Hole":"Cut"} upToFace intent records the selected termination face as an explicit split-face ambiguity instead of silently keeping it queryable.`,D.face,P1(D.face,_,"split")));const F=ub(S);(F==null?void 0:F.kind)==="upToFace"&&l.diagnostics.push(em(`${g}-reverse-up-to-face-target-split-ambiguous`,"ambiguous","face",`${g==="hole"?"Hole":"Cut"} reverse upToFace intent records the selected reverse termination face as an explicit split-face ambiguity instead of silently keeping it queryable.`,F.face,P1(F.face,_,"split")))}function Qxt(l,_,g){const S=gN("shell",l),D=Mee(_),F=Nxt(_,g);for(const z of D){const ee=P1(z.query,l,"preserved");S.preservedFaces.push({query:ee,status:"supported",note:"The outer shell face survives as a defended preserved-face query on the shelled result."}),cg(S,A1("single",ee,{source:z.query,note:"Shell keeps this face as one defended single descendant."}))}for(const z of F){const ee=Fee(l,"shell",z);S.createdFaces.push({query:ee,note:"This shell-created inner face is part of the defended named-face subset."}),cg(S,A1("single",ee,{note:"This shell-created face resolves to one defended descendant."}))}if(D.length===0&&F.length===0){const z=g.length>0?` Open faces: ${g.join(", ")}.`:"";S.diagnostics.push(em("shell-face-propagation-unsupported","unsupported","face",`Shell exact lowering is supported here, but compiler-owned face propagation is not defended for this shell base.${z}`))}return S.diagnostics.push(em("shell-edge-propagation-ambiguous","ambiguous","edge","Shell rewrites result edges, but durable edge-query propagation is not defended yet.")),S}function Yxt(l,_,g,S,D){const F=gN("hole",l),z=new Map(mee(_,g.workplane.source,D).map(ee=>[ee.name,ee.reason]));for(const ee of Mee(_)){const pe=z.get(ee.name);if(pe){const De=P1(ee.query,l,"split");F.preservedFaces.push({query:De,status:"ambiguous",note:MBe("hole",pe)}),cg(F,A1("face-region",De,{source:ee.query,note:"This rewritten hole face remains a defended descendant region on the same source surface."}));continue}const we=P1(ee.query,l,"preserved");F.preservedFaces.push({query:we,status:"supported",note:"This face stays queryable through the hole rewrite."}),cg(F,A1("single",we,{source:ee.query,note:"This hole descendant stays one defended face."}))}for(const ee of Ixt(S,D)){const pe=Fee(l,"hole",ee);F.createdFaces.push({query:pe,note:(()=>{switch(ee){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."}})()}),cg(F,A1("single",pe,{note:"This hole-created face resolves to one defended descendant."}))}for(const ee of Oxt(S,D)){const pe=PBe(l,"hole",ee);F.createdEdges.push({query:pe,note:Gxt(ee,S,D)}),cg(F,$J("edge-chain",pe,{note:"This hole-created edge query resolves to a defended descendant chain."}))}return F.diagnostics.push(em("hole-source-face-split-ambiguous","ambiguous","face","Hole intent records which rewritten host/exit faces are ambiguous instead of silently accepting them.",g.workplane.source,P1(g.workplane.source,l,"split"))),LBe(F,l,"hole",D),F}function Zxt(l,_,g,S,D,F){const z=gN("cut",l),ee=new Map(mee(_,g.workplane.source,D).map(we=>[we.name,we.reason]));for(const we of Mee(_)){const De=ee.get(we.name);if(De){const nt=P1(we.query,l,"split");z.preservedFaces.push({query:nt,status:"ambiguous",note:MBe("cut",De)}),cg(z,A1("face-region",nt,{source:we.query,note:"This rewritten cut face remains a defended descendant region on the same source surface."}));continue}const te=P1(we.query,l,"preserved");z.preservedFaces.push({query:te,status:"supported",note:"This face stays queryable through the cut rewrite."}),cg(z,A1("single",te,{source:we.query,note:"This cut descendant stays one defended face."}))}const pe=Fxt(S,D);for(const we of pe){const De=Fee(l,"cut",we);z.createdFaces.push({query:De,note:we==="floor"?"Blind cutouts create a defended planar floor face.":"This cut-created wall face is part of the defended named-face subset."}),cg(z,A1("single",De,{note:"This cut-created face resolves to one defended descendant."}))}for(const we of Mxt(S,D)){const De=PBe(l,"cut",we);z.createdEdges.push({query:De,note:Xxt(we,D)}),cg(z,$J("edge-chain",De,{note:"This cut-created edge query resolves to a defended descendant chain."}))}return z.diagnostics.push(em("cut-source-face-split-ambiguous","ambiguous","face","Cut intent records which rewritten host/exit faces are ambiguous instead of silently accepting them.",g.workplane.source,P1(g.workplane.source,l,"split"))),LBe(z,l,"cut",D),pe.length===0&&z.diagnostics.push(em("cut-created-face-subset-unsupported","unsupported","face","This cut profile does not fall inside the defended cut-created face subset yet.")),z}function RBe(l){const _=gN("hull",l);return _.diagnostics.push(em("hull-face-propagation-unsupported","unsupported","face","Hull combines source solids through a full topology rewrite, so face-query propagation is not defended yet."),em("hull-edge-propagation-unsupported","unsupported","edge","Hull combines source solids through a full topology rewrite, so edge-query propagation is not defended yet.")),_}function Q1e(l,_){const g=gN("trimByPlane",l);for(const D of Mee(_)){const F=P1(D.query,l,"split");g.preservedFaces.push({query:F,status:"ambiguous",note:"Trim keeps a clipped descendant region on the source surface instead of one untouched face."}),cg(g,A1("face-region",F,{source:D.query,note:"Trim keeps a defended descendant region on the source surface."}))}const S=Fee(l,"trimByPlane","plane-cap");return g.createdFaces.push({query:S,note:"The kept side of the trim introduces one deterministic cap face on the trim plane."}),cg(g,A1("single",S,{note:"The trim plane cap resolves to one defended descendant face."})),g.diagnostics.push(em("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."),em("trim-by-plane-edge-propagation-ambiguous","ambiguous","edge","Trim-by-plane boundary edge propagation is not defended yet.")),g}function Kxt(l,_,g,S=[]){const D=gN(l,_);for(const F of S){const z=GF(F,_,"preserved");D.preservedEdges.push({query:z,status:"supported",note:`${l} leaves this supported propagated vertical edge lineage unchanged in the defended post-rewrite subset.`}),cg(D,$J("single",z,{source:F,note:`${l} keeps this edge as one defended single descendant.`}))}if(g){const F=GF(g,_,"merged");D.preservedEdges.push({query:F,status:"ambiguous",note:`${l} rewrites the selected edge into a blended descendant set rather than one defended edge target.`}),cg(D,$J("edge-chain",F,{source:g,note:`${l} rewrites the selected edge into a defended descendant chain instead of one single edge target.`})),D.diagnostics.push(em(`${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.`,g,F))}return D.diagnostics.push(em(`${l}-created-face-propagation-unsupported`,"unsupported","face",`${l}-created face semantics are not part of the topology-rewrite kernel yet.`)),D}function eSt(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 tSt(l,_){return{...l,queryPropagation:Rk(_)}}function rbe(l,_){if(!l)return l;if(!eSt(l))throw new Error(`Cannot attach topology-rewrite propagation to non-rewrite plan kind "${l.kind}".`);return tSt(l,_)}function jBe(l,_){return kE(l,_)}function rSt(l,_){return`pattern:${l}:${_}`}const BBe=Symbol.for("forgecad.shapeBackend");var _Be;_Be=BBe;const Sm=class Sm{constructor(_){of(this,_Be,!0);this.manifold=_}clone(){return new Sm(this.manifold)}translate(_,g,S){return new Sm(this.manifold.translate(_,g,S))}rotate(_,g,S){return new Sm(this.manifold.rotate(_,g,S))}transform(_){return new Sm(this.manifold.transform(_))}scale(_){return new Sm(this.manifold.scale(_))}mirror(_){return new Sm(this.manifold.mirror(_))}smoothOut(_,g){return new Sm(this.manifold.smoothOut(_,g))}refine(_){return new Sm(this.manifold.refine(_))}refineToLength(_){return new Sm(this.manifold.refineToLength(_))}refineToTolerance(_){return new Sm(this.manifold.refineToTolerance(_))}warp(_){return new Sm(this.manifold.warp(_))}split(_){const[g,S]=this.manifold.split(gee(_,"ShapeBackend.split()"));return[new Sm(g),new Sm(S)]}splitByPlane(_,g){const[S,D]=this.manifold.splitByPlane(_,g);return[new Sm(S),new Sm(D)]}trimByPlane(_,g){return new Sm(this.manifold.trimByPlane(_,g))}hull(){return new Sm(this.manifold.hull())}simplify(_){return new Sm(this.manifold.simplify(_))}boundingBox(){return this.manifold.boundingBox()}volume(){return this.manifold.volume()}surfaceArea(){return this.manifold.surfaceArea()}minGap(_,g){return this.manifold.minGap(gee(_,"ShapeBackend.minGap()"),g)}isEmpty(){return this.manifold.isEmpty()}numTri(){return this.manifold.numTri()}getMesh(){return this.manifold.getMesh()}slice(_){return this.manifold.slice(_)}project(){return this.manifold.project()}requireManifold(){return this.manifold}};let vve=Sm;function nSt(l){return!!(l&&typeof l=="object"&&l[BBe]===!0)}function JBe(l){return new vve(l)}function gee(l,_="requireManifoldShapeBackend()"){try{return l.requireManifold(_)}catch(g){const S=g instanceof Error?g.message:String(g);throw new Error(`${_} currently requires a Manifold-backed runtime shape. ${S}`)}}function Y1e(l){switch(l.kind){case"through":case"blind":return{kind:l.kind,depth:l.depth};case"upToFace":return{kind:"upToFace",depth:l.depth,face:Kl(l.face)}}}function zBe(l){return l.kind==="two-sided"?{kind:"two-sided",forward:Y1e(l.forward),reverse:Y1e(l.reverse)}:Y1e(l)}function U2(l){return Number.isFinite(l)&&l>0}function qBe(l){return Math.max(.01,Math.min(.25,l*.01))}function IJ(l,_){return E1(l,{kind:"translate",x:0,y:0,z:_})}function WBe(l,_){const g=E1(l,{kind:"workplanePlacement",matrix:_.matrix,placement:_.placement});return g?{ok:!0,plan:g}:{ok:!1,reason:"Hole/cut features could not apply the selected workplane placement."}}function iSt(l,_,g,S){const D=wm(g),F=ZJ(g);if(!U2(F))return{ok:!1,reason:"Hole/cut features require a positive finite depth."};const z=qBe(F),ee=F+z*2,pe=(()=>{switch(l.kind){case"cylinder":return{kind:"cylinder",height:ee,radius:l.radius,center:!1};case"extrude":if(S&&(!U2(S.scale[0])||!U2(S.scale[1])))return null;const De=Cd(l.profile);if(!De)return null;const te=S?lb(De,{kind:"scale",x:S.scale[0],y:S.scale[1]}):De;return te?{kind:"extrude",profile:te,height:ee,center:!1,scaleTop:S?[1/S.scale[0],1/S.scale[1]]:void 0}:null;default:return null}})();if(!pe)return{ok:!1,reason:"Hole/cut feature lowerer expected an analytic cylinder or extruded profile cutter."};const we=IJ(pe,-(D.depth+z+_.placement.protrude));return we?WBe(we,_):{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."}}function sSt(l,_,g){if(!U2(l.radius))return{ok:!1,reason:"Shape.hole() requires a positive finite diameter."};const S=wm(g),D=ZJ(g);if(!U2(D))return{ok:!1,reason:"Hole/cut features require a positive finite depth."};const F=qBe(D),z=[],ee=IJ({kind:"cylinder",height:D+F*2,radius:l.radius,center:!1},-(S.depth+F+_.placement.protrude));if(!ee)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};if(z.push(ee),l.counterbore){if(!U2(l.counterbore.radius)||!U2(l.counterbore.depth))return{ok:!1,reason:"Shape.hole() counterbores require positive finite diameter and depth."};const we=IJ({kind:"cylinder",height:l.counterbore.depth+F,radius:l.counterbore.radius,center:!1},-(l.counterbore.depth+_.placement.protrude));if(!we)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};z.push(we)}if(l.countersink){if(!U2(l.countersink.radius)||!U2(l.countersink.depth))return{ok:!1,reason:"Shape.hole() countersinks require positive finite diameter and depth."};const we=IJ({kind:"cylinder",height:l.countersink.depth,radius:l.radius,radiusTop:l.countersink.radius,center:!1},-(l.countersink.depth+_.placement.protrude));if(!we)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};const De=IJ({kind:"cylinder",height:F,radius:l.countersink.radius,center:!1},-_.placement.protrude);if(!De)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};z.push(we,De)}const pe=z.length===1?z[0]:Sy("union",z);return pe?WBe(pe,_):{ok:!1,reason:"Hole/cut features could not combine the selected cutter components."}}function aSt(l,_,g,S){return!l||!_||!g||!U2(g.radius)||!U2(ZJ(S))?null:{kind:"hole",base:s_(l),placement:AS(_),hole:{radius:g.radius,counterbore:g.counterbore?{radius:g.counterbore.radius,depth:g.counterbore.depth}:void 0,countersink:g.countersink?{radius:g.countersink.radius,angleDeg:g.countersink.angleDeg,depth:g.countersink.depth}:void 0},extent:zBe(S)}}function oSt(l,_,g,S,D){return!l||!_||!g||!U2(ZJ(S))?null:{kind:"cut",base:s_(l),placement:AS(_),profile:Cd(g),extent:zBe(S),taper:D?{scale:[D.scale[0],D.scale[1]]}:void 0}}function cSt(l){const _=sSt(l.hole,l.placement,l.extent);return _.ok?{ok:!0,plan:Sy("difference",[l.base,_.plan])}:_}function lSt(l){const _=iSt({kind:"extrude",profile:l.profile,height:ZJ(l.extent)},l.placement,l.extent,l.taper);return _.ok?{ok:!0,plan:Sy("difference",[l.base,_.plan])}:_}function VBe(l){const _=[];for(const g of l??[]){if(g!=="top"&&g!=="bottom")throw new Error(`Shape.shell() only supports "top" and "bottom" openings, got "${g}"`);_.includes(g)||_.push(g)}return _}function uSt(l){return l.kind!=="scale"}function nbe(l,_,g,S){const D=S.includes("top"),F=S.includes("bottom"),z=_?-l/2+(F?0:g):F?0:g,ee=_?l/2-(D?0:g):l-(D?0:g),pe=ee-z;return pe>0?{height:pe,translateZ:_?(z+ee)/2:z}:null}function UBe(l,_){return Math.abs(_)<=1e-12?l:E1(l,{kind:"translate",x:0,y:0,z:_})}function _St(l,_,g,S){let D=l;return(Math.abs(_)>1e-12||Math.abs(g)>1e-12||Math.abs(S)>1e-12)&&(D=E1(D,{kind:"translate",x:_,y:g,z:S})),D}function fSt(l,_,g){const S=l.x-2*_,D=l.y-2*_;if(!(S>0)||!(D>0))return{ok:!1,reason:"Shape.shell() thickness is too large for this box base."};const F=nbe(l.z,l.center,_,g);if(!F)return{ok:!1,reason:"Shape.shell() thickness is too large for this box height and opening configuration."};const z=_St({kind:"box",x:S,y:D,z:F.height,center:l.center},l.center?0:_,l.center?0:_,F.translateZ);return{ok:!0,plan:Sy("difference",[l,z])}}function pSt(l,_,g){const S=l.radius-_,D=l.radiusTop==null?void 0:l.radiusTop-_;if(!(S>0)||D!=null&&!(D>0))return{ok:!1,reason:"Shape.shell() thickness is too large for this cylinder or cone base."};const F=nbe(l.height,l.center,_,g);if(!F)return{ok:!1,reason:"Shape.shell() thickness is too large for this cylinder height and opening configuration."};const z=UBe({kind:"cylinder",height:F.height,radius:S,radiusTop:D,center:l.center},F.translateZ);return{ok:!0,plan:Sy("difference",[l,z])}}function dSt(l,_,g){if(l.scaleTop)return{ok:!1,reason:"Shape.shell() v1 does not support tapered extrudes (`scaleTop`) yet."};const S=CBe(l.profile,-_,"Round");if(!S)return{ok:!1,reason:"Shape.shell() could not offset the source profile for this extrude base."};const D=nbe(l.height,l.center,_,g);if(!D)return{ok:!1,reason:"Shape.shell() thickness is too large for this extrude height and opening configuration."};const F=UBe({kind:"extrude",profile:S,height:D.height,center:l.center},D.translateZ);return{ok:!0,plan:Sy("difference",[l,F])}}function bve(l,_,g){switch(l.kind){case"queryOwner":{const S=bve(l.base,_,g);return S.ok?{ok:!0,plan:KJ(S.plan,l.owner)}:S}case"transform":{if(!l.steps.every(uSt))return{ok:!1,reason:"Shape.shell() v1 supports only rigid transforms before shelling. Scale transforms are not supported yet."};const S=bve(l.base,_,g);return S.ok?{ok:!0,plan:s_({kind:"transform",base:S.plan,steps:l.steps.map(D=>({...D}))})}:S}case"box":return fSt(l,_,g);case"cylinder":return pSt(l,_,g);case"extrude":return dSt(l,_,g);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 mSt(l,_,g=[]){if(!l||!Number.isFinite(_)||!(_>0))return null;const S={kind:"shell",base:s_(l),thickness:_,openFaces:VBe(g)};return $Be(S).ok?S:null}function $Be(l){return!Number.isFinite(l.thickness)||!(l.thickness>0)?{ok:!1,reason:"Shape.shell() requires a positive finite wall thickness."}:bve(l.base,l.thickness,VBe(l.openFaces))}function gSt(l,_,g){return Math.max(_,Math.min(g,l))}function lje(l,_){return[l[0]-_[0],l[1]-_[1],l[2]-_[2]]}function hSt(l,_){return[l[0]*_,l[1]*_,l[2]*_]}function LJ(l,_){return l[0]*_[0]+l[1]*_[1]+l[2]*_[2]}function Z1e(l,_){return[l[1]*_[2]-l[2]*_[1],l[2]*_[0]-l[0]*_[2],l[0]*_[1]-l[1]*_[0]]}function ibe(l){return Math.sqrt(LJ(l,l))}function IK(l){const _=ibe(l);return _<1e-9?[0,0,1]:[l[0]/_,l[1]/_,l[2]/_]}function ySt(l){let _=0;for(let g=0;g<l.length;g+=1){const[S,D]=l[g],[F,z]=l[(g+1)%l.length];_+=S*z-F*D}return _*.5}function vSt(l,_){let g=!1;const[S,D]=l;for(let F=0,z=_.length-1;F<_.length;z=F,F+=1){const[ee,pe]=_[F],[we,De]=_[z];pe>D!=De>D&&S<(we-ee)*(D-pe)/(De-pe+1e-20)+ee&&(g=!g)}return g}function bSt(l,_,g){const S=g[0]-_[0],D=g[1]-_[1],F=l[0]-_[0],z=l[1]-_[1],ee=S*S+D*D,pe=ee<1e-12?0:gSt((F*S+z*D)/ee,0,1),we=_[0]+S*pe,De=_[1]+D*pe,te=l[0]-we,nt=l[1]-De;return Math.sqrt(te*te+nt*nt)}function xSt(l,_){let g=1/0;for(let S=0;S<_.length;S+=1){const D=_[S],F=_[(S+1)%_.length];g=Math.min(g,bSt(l,D,F))}return vSt(l,_)?g:-g}function HBe(l){const _=l.filter(g=>Array.isArray(g)&&g.length>=3).map(g=>({pts:g.map(([S,D])=>[S,D]),area:ySt(g)}));return _.length===0?()=>-1:(g,S)=>{const D=[g,S];let F=-1/0;for(const z of _){const ee=xSt(D,z.pts);F=z.area>=0?Math.max(F,ee):Math.min(F,-ee)}return F}}function SSt(l,_){let g=IK(_);Math.abs(LJ(g,l))>.95&&(g=Math.abs(l[2])<.95?[0,0,1]:[0,1,0]);let S=IK(Z1e(g,l));if(ibe(S)<1e-8){const F=Math.abs(l[0])<.9?[1,0,0]:[0,1,0];S=IK(Z1e(F,l))}const D=IK(Z1e(l,S));return{x:S,y:D}}function GBe(l,_,g){if(l.length<2)throw new Error("loft requires at least two compileable profiles");if(l.length!==_.length)throw new Error("loft compile data requires heights.length === profiles.length");const S=l.map(nt=>HBe(nt)),D=_.map(nt=>nt);let F=1/0,z=1/0,ee=-1/0,pe=-1/0;for(const nt of l)for(const Te of nt)for(const[Me,bt]of Te)F=Math.min(F,Me),z=Math.min(z,bt),ee=Math.max(ee,Me),pe=Math.max(pe,bt);const we=D[0],De=D[D.length-1],te=g.boundsPadding;return{sdf:([nt,Te,Me])=>{let bt;if(Me<=we)bt=S[0](nt,Te);else if(Me>=De)bt=S[S.length-1](nt,Te);else{let Bt=0;for(;Bt+1<D.length&&Me>D[Bt+1];)Bt+=1;const fr=D[Bt],hn=D[Bt+1],vr=(Me-fr)/(hn-fr),Xt=S[Bt](nt,Te),Wt=S[Bt+1](nt,Te);bt=Xt*(1-vr)+Wt*vr}const vt=Math.min(Me-we,De-Me);return Math.min(bt,vt)},bounds:{min:[F-te,z-te,we-te],max:[ee+te,pe+te,De+te]},edgeLength:g.edgeLength}}function XBe(l,_,g){if(_.length<2)throw new Error("sweep requires a path with at least two points");const S=HBe(l),D=[];for(let Te=0;Te<_.length-1;Te+=1){const Me=_[Te],bt=_[Te+1],vt=lje(bt,Me),Bt=ibe(vt);if(Bt<1e-6)continue;const fr=hSt(vt,1/Bt),hn=SSt(fr,g.up);D.push({a:Me,t:fr,x:hn.x,y:hn.y,len:Bt})}if(D.length===0)throw new Error("sweep path has no non-zero segments");let F=0;for(const Te of l)for(const[Me,bt]of Te)F=Math.max(F,Math.abs(Me),Math.abs(bt));let z=1/0,ee=1/0,pe=1/0,we=-1/0,De=-1/0,te=-1/0;for(const[Te,Me,bt]of _)z=Math.min(z,Te),ee=Math.min(ee,Me),pe=Math.min(pe,bt),we=Math.max(we,Te),De=Math.max(De,Me),te=Math.max(te,bt);const nt=Math.max(g.boundsPadding,F);return{sdf:Te=>{let Me=-1/0;for(const bt of D){const vt=lje(Te,bt.a),Bt=LJ(vt,bt.t),fr=LJ(vt,bt.x),hn=LJ(vt,bt.y),vr=S(fr,hn),Xt=Math.min(Bt,bt.len-Bt);Me=Math.max(Me,Math.min(vr,Xt))}return Me},bounds:{min:[z-nt,ee-nt,pe-nt],max:[we+nt,De+nt,te+nt]},edgeLength:g.edgeLength}}function TSt(l,_){if(l.length<2)return l;if(_<=0)return[];const g=[0];for(let F=0;F<l.length;F++){const z=l[F],ee=l[(F+1)%l.length],pe=ee[0]-z[0],we=ee[1]-z[1],De=Math.sqrt(pe*pe+we*we);g.push(g[g.length-1]+De)}const S=g[g.length-1];if(S<1e-12)return Array.from({length:_},()=>[l[0][0],l[0][1]]);const D=[];for(let F=0;F<_;F++){const z=F/_*S;let ee=0,pe=g.length-1;for(;ee<pe;){const Te=ee+pe>>1;g[Te]<=z?ee=Te+1:pe=Te}const we=ee-1,De=(z-g[we])/(g[we+1]-g[we]),te=l[we%l.length],nt=l[(we+1)%l.length];D.push([te[0]+(nt[0]-te[0])*De,te[1]+(nt[1]-te[1])*De])}return D}function kSt(l,_,g){if(l.length<2)return null;const S=l[0].length;if(S===0)return null;for(let z=1;z<l.length;z++)if(l[z].length!==S)return null;const D=[];for(let z=0;z<S;z++){const ee=wSt(l.map(pe=>pe[z]),_,g);if(ee)D.push(ee);else{for(const pe of D)pe.delete();return null}}if(D.length===0)return null;if(D.length===1)return D[0];const F=g.Manifold.union(D);for(const z of D)z.delete();return F}function CSt(l){let _=0;for(let g=0;g<l.length;g++){const S=l[g],D=l[(g+1)%l.length];_+=S[0]*D[1]-D[0]*S[1]}return _*.5}function wSt(l,_,g){const S=l.map(bt=>CSt(bt)<0?[...bt].reverse():bt);let D=0;for(const bt of S)D=Math.max(D,bt.length);const F=Math.max(D,24),z=S.map((bt,vt)=>{const Bt=TSt(bt,F),fr=_[vt];return Bt.map(([hn,vr])=>[hn,vr,fr])}),ee=[],pe=[];for(const bt of z)for(const[vt,Bt,fr]of bt)ee.push(vt,Bt,fr);for(let bt=0;bt<z.length-1;bt++){const vt=bt*F,Bt=(bt+1)*F;for(let fr=0;fr<F;fr++){const hn=(fr+1)%F,vr=vt+fr,Xt=Bt+fr,Wt=Bt+hn,Hn=vt+hn;pe.push(vr,Hn,Wt),pe.push(vr,Wt,Xt)}}const we=z[0].map(([bt,vt])=>[bt,vt]),De=g.triangulate([we]);for(const bt of De){const[vt,Bt,fr]=Array.isArray(bt)?bt:[bt[0],bt[1],bt[2]];pe.push(vt,fr,Bt)}const te=z[z.length-1].map(([bt,vt])=>[bt,vt]),nt=g.triangulate([te]),Te=(z.length-1)*F;for(const bt of nt){const[vt,Bt,fr]=Array.isArray(bt)?bt:[bt[0],bt[1],bt[2]];pe.push(Te+vt,Te+Bt,Te+fr)}const Me=new g.Mesh({numProp:3,vertProperties:new Float32Array(ee),triVerts:new Uint32Array(pe)});try{return new g.Manifold(Me)}catch{return null}}const xve=1e-8;function QBe(l){return Math.hypot(l[0],l[1],l[2])}function YBe(l){const _=QBe(l);if(_<xve)throw new Error("Plane normal must be non-zero");return[l[0]/_,l[1]/_,l[2]/_]}function ESt(l){if("origin"in l)return{origin:[l.origin[0],l.origin[1],l.origin[2]],normal:YBe(l.normal)};const _=l.offset??0;return l.plane==="XY"?{origin:[0,0,_],normal:[0,0,1]}:l.plane==="XZ"?{origin:[0,_,0],normal:[0,1,0]}:{origin:[_,0,0],normal:[1,0,0]}}function ZBe(l){const _=YBe(l),g=_[2];if(g>1-xve)return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];let S,D;if(g<-1+xve)S=[1,0,0],D=Math.PI;else{S=[_[1],-_[0],0];const vr=QBe(S);S=[S[0]/vr,S[1]/vr,S[2]/vr],D=Math.acos(g)}const[F,z,ee]=S,pe=Math.cos(D),we=Math.sin(D),De=1-pe,te=pe+F*F*De,nt=F*z*De-ee*we,Te=F*ee*De+z*we,Me=z*F*De+ee*we,bt=pe+z*z*De,vt=z*ee*De-F*we,Bt=ee*F*De-z*we,fr=ee*z*De+F*we,hn=pe+ee*ee*De;return[te,Me,Bt,0,nt,bt,fr,0,Te,vt,hn,0,0,0,0,1]}function KBe(l){const{origin:_,normal:g}=ESt(l),S=Sa.from(ZBe(g)).inverse();return{origin:_,u:S.vector([1,0,0]),v:S.vector([0,1,0]),normal:g}}function eJe(l){const _=ZBe(l.normal);return Sa.translation(-l.origin[0],-l.origin[1],-l.origin[2]).mul(_).toArray()}const sbe=1e-8,tJe=["vert-bl","vert-br","vert-tr","vert-tl"];function DSt(l,_){return[(l[0]+_[0])*.5,(l[1]+_[1])*.5,(l[2]+_[2])*.5]}function RJ(l){const _=Math.hypot(l[0],l[1],l[2]);if(_<=sbe)throw new Error("Edge feature selection requires a non-zero direction vector");return[l[0]/_,l[1]/_,l[2]/_]}function PSt(l,_){return[l[0]-_[0],l[1]-_[1],l[2]-_[2]]}function xp(l,_){return{ok:!1,issue:{code:l,reason:_}}}function ez(l,_){return{ok:!0,selection:l,query:Tl(_)}}function ASt(l){return tJe.includes(l)}function abe(l){switch(l.kind){case"boolean":return`boolean ${l.op}`;case"trimByPlane":return"trimByPlane";default:return l.kind}}function FK(l,_){return{base:l.base,steps:[...l.steps,_]}}function NSt(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 ${abe(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 uje(l,_,g){var ee;const S=((ee=l.queryPropagation)==null?void 0:ee.diagnostics.filter(pe=>pe.queryKind==="edge"))??[],D=S.find(pe=>qk(pe.source,_)&&(g==null||qk(pe.query,g)));if(D!=null&&D.message)return D.message;const F=S.find(pe=>qk(pe.source,_));if(F!=null&&F.message)return F.message;const z=S.find(pe=>pe.source==null&&pe.query==null);return(z==null?void 0:z.message)??null}function rJe(l,_){var g;if(_)return(g=l.queryPropagation)==null?void 0:g.descendants.find(S=>S.queryKind==="edge"&&qk(S.query,_))}function ISt(l){switch(l.kind){case"translate":return Sa.translation(l.x,l.y,l.z);case"rotate":return Sa.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg);case"rotateAround":return Sa.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]);case"mirror":{const[_,g,S]=[l.normalX,l.normalY,l.normalZ],D=Math.hypot(_,g,S);if(D<=sbe)return Sa.identity();const F=_/D,z=g/D,ee=S/D;return Sa.from([1-2*F*F,-2*z*F,-2*ee*F,0,-2*F*z,1-2*z*z,-2*ee*z,0,-2*F*ee,-2*z*ee,1-2*ee*ee,0,0,0,0,1])}case"workplanePlacement":return Sa.from(l.matrix);case"scale":return null}}function nJe(l,_){let g=l;for(const S of _){const D=ISt(S);if(!D)return{issue:{code:"unsupported-edge-transform",reason:"Edge finishing currently supports only rigid transforms between the tracked source edge and the target body."}};g=g.mul(D)}return{transform:g}}function FF(l,_){var g,S;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 cb(l.owner,_)?{match:{base:l.base,steps:[]}}:FF(l.base,_);case"transform":{const D=FF(l.base,_);return D.match?{match:FK(D.match,{kind:"transform",steps:l.steps})}:D}case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":{const D=FF(l.base,_);return D.match?{match:FK(D.match,{kind:"rewrite",plan:l})}:D}case"boolean":{for(const D of l.shapes){const F=FF(D,_);if(F.match)return{match:FK(F.match,{kind:"rewrite",plan:l})};if(((g=F.issue)==null?void 0:g.code)==="unsupported-edge-transform")return F}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 D of l.shapes){const F=FF(D,_);if(F.match)return{match:FK(F.match,{kind:"rewrite",plan:l})};if(((S=F.issue)==null?void 0:S.code)==="unsupported-edge-transform")return F}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 iJe(l,_){const g=nJe(Sa.identity(),_);return g.transform?ez(cJe(l.selection,g.transform),l.query):xp(g.issue.code,g.issue.reason)}function FSt(l,_){switch(_.kind){case"tracked-edge":return OSt(l,_);case"propagated-edge":return MSt(l,_);case"created-edge":return xp("unsupported-edge-query-kind","Edge finishing does not yet support created-edge queries from topology rewrites.");case"edge-ref":return xp("unsupported-edge-query-kind","Edge finishing v1 supports tracked/propagated compiler-owned edge queries only, not direct edge refs.")}}function OSt(l,_){const g=Sve(l,_.edgeName);return g.ok?ez(g.selection,_):g}function sJe(l,_){switch(l.kind){case"fillet":case"chamfer":case"shell":case"hole":case"cut":case"trimByPlane":return _N(l.base,_);case"boolean":case"hull":{let g=null;for(const S of l.shapes){const D=_N(S,_);if(D.ok)return D;D.issue.code!=="edge-owner-not-found"&&D.issue.code!=="edge-query-propagation-mismatch"&&(g??(g=D.issue))}return g?xp(g.code,g.reason):xp("edge-query-propagation-mismatch","The selected propagated edge query does not match the target shape's recorded rewrite propagation contract.")}}}function aJe(l,_){var S;const g=(S=l.queryPropagation)==null?void 0:S.preservedEdges.find(D=>qk(D.query.source,_.query));return g?g.status!=="supported"||g.query.outcome!=="preserved"?xp("edge-query-ambiguous-after-rewrite",uje(l,_.query,g.query)??g.note??`The selected edge query is recorded as ${g.status} after ${abe(l)} and does not resolve to one defended edge target.`):ez(_.selection,g.query):xp("edge-query-unsupported-after-rewrite",uje(l,_.query)??NSt(l))}function MSt(l,_){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 xp("edge-query-propagation-mismatch","The selected propagated edge query does not point at a topology-rewrite result on this target shape.");const g=l.queryPropagation;if(!g||g.rewriteId!==_.rewriteId)return xp("edge-query-propagation-mismatch","The selected propagated edge query does not match the target shape's recorded rewrite propagation contract.");if(!g.preservedEdges.find(z=>qk(z.query,_)))return xp("edge-query-propagation-mismatch",`The selected propagated edge query is not part of the recorded ${abe(l)} propagation subset for this target shape.`);const D=sJe(l,_.source);if(!D.ok)return D;const F=aJe(l,{selection:D.selection,query:D.query});return F.ok?qk(F.query,_)?F:xp("edge-query-propagation-mismatch","The selected propagated edge query does not match the target shape's recorded rewrite propagation contract."):F}function LSt(l,_){let g=ez(l.selection,l.query);for(const S of _){if(!g.ok)return g;g=S.kind==="transform"?iJe({selection:g.selection,query:g.query},S.steps):aJe(S.plan,{selection:g.selection,query:g.query})}return g}function oJe(l){if(!l)return null;switch(l.kind){case"tracked-edge":return l.selector!=="edge"||!l.owner||!ASt(l.edgeName)?null:{owner:fp(l.owner),edgeName:l.edgeName};case"propagated-edge":return oJe(l.source);case"created-edge":case"edge-ref":return null}}function RSt(l,_){const g=l.center?-l.x/2:0,S=l.center?-l.y/2:0,D=l.center?-l.z/2:0,F=g+l.x,z=S+l.y,ee=D+l.z,pe=(()=>{switch(_){case"vert-bl":return{point:[g,S,D],quadrant:[1,-1]};case"vert-br":return{point:[F,S,D],quadrant:[-1,-1]};case"vert-tr":return{point:[F,z,D],quadrant:[-1,1]};case"vert-tl":return{point:[g,z,D],quadrant:[1,1]};default:return null}})();return pe?{ok:!0,selection:{kind:"line-segment",edgeName:_,start:[pe.point[0],pe.point[1],D],end:[pe.point[0],pe.point[1],ee],midpoint:[pe.point[0],pe.point[1],(D+ee)*.5],axis:[0,0,1],basisX:[1,0,0],basisY:[0,-1,0],quadrant:pe.quadrant}}:xp("unsupported-edge-name",`Edge finishing v1 currently supports only tracked vertical rectangle/box edges (${["vert-bl","vert-br","vert-tr","vert-tl"].join(", ")}).`)}function jSt(l){if(l.length!==4)return!1;const _=l.map((we,De)=>{const te=l[(De+1)%l.length];return[te[0]-we[0],te[1]-we[1]]}),g=_.map(([we,De])=>Math.hypot(we,De));if(g.some(we=>we<=sbe))return!1;const S=_[0][0]*_[1][0]+_[0][1]*_[1][1],D=_[1][0]*_[2][0]+_[1][1]*_[2][1],F=_[2][0]*_[3][0]+_[2][1]*_[3][1],z=_[3][0]*_[0][0]+_[3][1]*_[0][1],ee=_[0][0]*_[2][1]-_[0][1]*_[2][0],pe=_[1][0]*_[3][1]-_[1][1]*_[3][0];return Math.abs(S)<=1e-6*Math.max(1,g[0]*g[1])&&Math.abs(D)<=1e-6*Math.max(1,g[1]*g[2])&&Math.abs(F)<=1e-6*Math.max(1,g[2]*g[3])&&Math.abs(z)<=1e-6*Math.max(1,g[3]*g[0])&&Math.abs(ee)<=1e-6*Math.max(1,g[0]*g[2])&&Math.abs(pe)<=1e-6*Math.max(1,g[1]*g[3])}function BSt(l,_){if(l.scaleTop)return xp("unsupported-edge-base","Edge finishing v1 does not support tapered extrudes (`scaleTop`) yet.");if(l.center)return xp("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"||!jSt(l.profile.points))return xp("unsupported-edge-profile","Edge finishing v1 currently supports tracked rectangle extrusions only; generic sketch extrudes are outside the supported subset.");const g=(()=>{switch(_){case"vert-bl":return 0;case"vert-br":return 1;case"vert-tr":return 2;case"vert-tl":return 3;default:return-1}})();if(g<0)return xp("unsupported-edge-name",`Edge finishing v1 currently supports only tracked vertical rectangle/box edges (${["vert-bl","vert-br","vert-tr","vert-tl"].join(", ")}).`);const S=l.profile.points,[D,F,z,ee]=S,pe=RJ([F[0]-D[0],F[1]-D[1],0]),we=RJ([ee[0]-D[0],ee[1]-D[1],0]),De=S[g],te=g===0?[1,-1]:g===1?[-1,-1]:g===2?[-1,1]:[1,1];return{ok:!0,selection:{kind:"line-segment",edgeName:_,start:[De[0],De[1],0],end:[De[0],De[1],l.height],midpoint:[De[0],De[1],l.height*.5],axis:[0,0,1],basisX:[pe[0],pe[1],pe[2]],basisY:[-we[0],-we[1],-we[2]],quadrant:te}}}function cJe(l,_){const g=_.point(l.start),S=_.point(l.end),D=RJ(_.vector(l.basisX)),F=RJ(_.vector(l.basisY)),z=RJ(PSt(S,g));return{kind:"line-segment",edgeName:l.edgeName,start:g,end:S,midpoint:DSt(g,S),axis:z,basisX:D,basisY:F,quadrant:[l.quadrant[0],l.quadrant[1]]}}function Sve(l,_){switch(l.kind){case"transform":{const g=Sve(l.base,_);if(!g.ok)return g;const S=nJe(Sa.identity(),l.steps);return S.transform?{ok:!0,selection:cJe(g.selection,S.transform)}:xp(S.issue.code,S.issue.reason)}case"box":return RSt(l,_);case"extrude":return BSt(l,_);case"queryOwner":return Sve(l.base,_);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 xp("unsupported-edge-base","Edge finishing v1 currently supports tracked vertical edges from compile-covered box() bodies and rectangle extrusions before topology-changing edits.")}}function _N(l,_){const g=qSt(l,_);return g.kind==="single"?ez(g.selection,g.query):g.kind==="edge-chain"?xp("edge-query-ambiguous-after-rewrite",g.note??"The selected edge resolves to a defended descendant chain, not one single edge target."):g.query==null&&_==null?xp("missing-edge-query",g.reason):g.query==null&&(_!=null&&_.selector)&&_.selector!=="edge"||g.reason.includes("selector")?xp("unsupported-edge-selector",g.reason):g.reason.includes("owner")?xp("edge-owner-not-found",g.reason):xp("edge-query-unsupported-after-rewrite",g.reason)}function JSt(l,_){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:Tl(_),reason:"The selected propagated edge query does not point at a topology-rewrite result on this target shape."};const g=rJe(l,_);if(!g||g.kind!=="edge-chain")return{kind:"unsupported",query:Tl(_),reason:"This target shape does not record a defended descendant edge chain for the selected query."};const S=sJe(l,_.source);return S.ok?{kind:"edge-chain",semantic:"chain",query:Tl(_),selection:S.selection,note:g.note}:{kind:"unsupported",query:Tl(_),reason:S.issue.reason,note:g.note}}function zSt(l,_){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:Tl(_),reason:"The selected created-edge query does not point at a topology-rewrite result on this target shape."};const g=rJe(l,_);return!g||g.kind!=="edge-chain"?{kind:"unsupported",query:Tl(_),reason:"This target shape does not record a defended descendant edge chain for the selected created-edge query."}:{kind:"edge-chain",semantic:"chain",query:Tl(_),note:g.note}}function qSt(l,_){var D;if(!_)return{kind:"unsupported",reason:"Edge finishing currently requires a tracked edge query from a compile-covered target body."};if(_.selector!=="edge")return{kind:"unsupported",query:Tl(_),reason:"Edge finishing v1 currently supports whole-edge selections only; use shape.edge(name), not .start/.end/.midpoint selectors."};if(_.kind==="edge-ref")return{kind:"unsupported",query:Tl(_),reason:"Edge finishing v1 supports compiler-owned tracked-edge, propagated-edge, and inspectable created-edge queries only, not direct edge refs."};if(!_.owner)return{kind:"unsupported",query:Tl(_),reason:"Edge finishing currently requires a tracked edge query with a compiler-owned parent body owner."};const g=FF(l,_.owner);if(!g.match)return{kind:"unsupported",query:Tl(_),reason:((D=g.issue)==null?void 0:D.reason)??"The selected tracked edge is not owned by this target shape or any preserved query ancestor."};if(_.kind==="created-edge"){const F=zSt(g.match.base,_);if(F.kind==="unsupported")return F;for(const z of g.match.steps)if(z.kind==="rewrite")return{kind:"unsupported",query:Tl(_),reason:"Later topology rewrites do not yet preserve this defended created-edge chain as a new downstream chain contract.",note:F.note};return F}const S=FSt(g.match.base,_);if(S.ok){const F=LSt({selection:S.selection,query:S.query},g.match.steps);return F.ok?{kind:"single",semantic:"edge",query:F.query,selection:F.selection}:{kind:"unsupported",query:Tl(_),reason:F.issue.reason}}if(_.kind==="propagated-edge"){const F=JSt(g.match.base,_);if(F.kind!=="unsupported"){let z=F;for(const ee of g.match.steps){if(ee.kind==="transform"){if(!z.selection)continue;const pe=iJe({selection:z.selection,query:z.query},ee.steps);if(!pe.ok)return{kind:"unsupported",query:Tl(_),reason:pe.issue.reason,note:z.note};z={...z,selection:pe.selection,query:pe.query};continue}return{kind:"unsupported",query:Tl(_),reason:"Later topology rewrites do not yet preserve this defended edge chain as a new downstream chain contract.",note:z.note}}return z}}return{kind:"unsupported",query:Tl(_),reason:S.issue.reason}}function lJe(l,_){if(!l)return[];const g=oJe(_);if(!g)return[];const S=[];for(const D of tJe){if(D===g.edgeName)continue;const F={kind:"tracked-edge",edgeName:D,selector:"edge",owner:fp(g.owner)},z=_N(l,F);z.ok&&S.push(z.query)}return S}const hee=.01;function uJe(l,_=0){const g=[l.start[0]+l.axis[0]*_,l.start[1]+l.axis[1]*_,l.start[2]+l.axis[2]*_];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,g[0],g[1],g[2],1]}function _Je(l){const _=l.end[0]-l.start[0],g=l.end[1]-l.start[1],S=l.end[2]-l.start[2];return Math.hypot(_,g,S)}function WSt(l,_,g,S,D){const F=_Je(_);if(!(F>1e-6))return l;const[z,ee]=_.quadrant,pe=F+hee*2,we=uJe(_,-hee),De=D.CrossSection.square([g,g],!1).translate(z>0?0:-g,ee>0?0:-g).extrude(pe,0,0,void 0,!1).transform(we),te=D.CrossSection.circle(g,Math.max(3,S)).extrude(pe,0,0,void 0,!1).transform(we);return D.Manifold.union([D.Manifold.difference([l,De]),te])}function VSt(l,_,g,S){const D=_Je(_);if(!(D>1e-6))return l;const[F,z]=_.quadrant,ee=D+hee*2,pe=uJe(_,-hee),De=new S.CrossSection([[[0,0],[F*g,0],[0,z*g]]]).extrude(ee,0,0,void 0,!1).transform(pe);return S.Manifold.difference([l,De])}function USt(l,_){switch(_.kind){case"translate":return l.translate(_.x,_.y);case"rotate":return l.rotate(_.degrees);case"scale":return l.scale([_.x,_.y]);case"mirror":return l.mirror([_.normalX,_.normalY])}}function Bk(l,_){let g=l;for(const S of _)g=USt(g,S);return g}function $St(l,_){const g=l.profiles.map(D=>mP(D,_));if(g.length===0)throw new Error(`Cannot lower empty profile boolean (${l.op})`);if(g.length===1)return Bk(g[0],l.transforms);const S=(()=>{switch(l.op){case"union":return _.CrossSection.union(g);case"difference":return _.CrossSection.difference(g);case"intersection":return _.CrossSection.intersection(g)}})();return Bk(S,l.transforms)}function HSt(l,_){const g=l.profiles.map(S=>mP(S,_));if(g.length===0)throw new Error("Cannot lower empty profile hull");return g.length===1?Bk(g[0],l.transforms):Bk(_.CrossSection.hull(g),l.transforms)}function mP(l,_){switch(l.kind){case"rect":return Bk(_.CrossSection.square([l.width,l.height],l.center),l.transforms);case"roundedRect":{const g=Math.min(l.radius,l.width/2,l.height/2),S=_.CrossSection.square([l.width-2*g,l.height-2*g],!0).translate(l.center?0:l.width/2,l.center?0:l.height/2).offset(g,"Round");return Bk(S,l.transforms)}case"circle":return Bk(_.CrossSection.circle(l.radius,l.segments??0),l.transforms);case"polygon":return Bk(new _.CrossSection([l.points]),l.transforms);case"boolean":return $St(l,_);case"offset":return Bk(mP(l.base,_).offset(l.delta,l.join),l.transforms);case"hull":return HSt(l,_);case"project":{const g=ab(l.sourceShape,_).transform(eJe(l.plane)).project();return Bk(g,l.transforms)}}}function GSt(l,_){switch(_.kind){case"translate":return l.translate(_.x,_.y,_.z);case"rotate":return l.rotate(_.xDeg,_.yDeg,_.zDeg);case"scale":return l.scale([_.x,_.y,_.z]);case"rotateAround":return l.transform(Sa.rotationAxis([_.axisX,_.axisY,_.axisZ],_.degrees,[_.pivotX,_.pivotY,_.pivotZ]).toArray());case"mirror":return l.mirror([_.normalX,_.normalY,_.normalZ]);case"workplanePlacement":return l.transform(_.matrix)}}function XSt(l,_){let g=l;for(const S of _)g=GSt(g,S);return g}function QSt(l,_){const g=l.shapes.map(S=>ab(S,_));if(g.length===0)throw new Error(`Cannot lower empty shape boolean (${l.op})`);if(g.length===1)return g[0];switch(l.op){case"union":return _.Manifold.union(g);case"difference":return _.Manifold.difference(g);case"intersection":return _.Manifold.intersection(g)}}function YSt(l,_){const S=[...l.shapes.map(D=>ab(D,_)),...l.points.map(([D,F,z])=>[D,F,z])];if(S.length===0)throw new Error("Cannot lower empty shape hull");return _.Manifold.hull(S)}function ZSt(l,_){return ab(l.base,_).trimByPlane([l.normalX,l.normalY,l.normalZ],l.originOffset)}function KSt(l,_){const g=l.profiles.map(F=>mP(F,_).toPolygons());if(g.length>=2&&g.every(F=>F.length===1)){const F=kSt(g,l.heights,_);if(F)return F}const D=GBe(g,l.heights,{edgeLength:l.edgeLength,boundsPadding:l.boundsPadding});return _.Manifold.levelSet(D.sdf,D.bounds,D.edgeLength,0)}function eTt(l,_){const g=XBe(mP(l.profile,_).toPolygons(),l.path.points.map(([S,D,F])=>[S,D,F]),{edgeLength:l.edgeLength,boundsPadding:l.boundsPadding,up:[l.up[0],l.up[1],l.up[2]]});return _.Manifold.levelSet(g.sdf,g.bounds,g.edgeLength,0)}function tTt(l,_){const g=_N(l.base,l.edge);if(!g.ok)throw new Error(g.issue.reason);if(g.selection.quadrant[0]!==l.quadrant[0]||g.selection.quadrant[1]!==l.quadrant[1])throw new Error(`filletEdge() currently supports ${g.selection.edgeName} only with quadrant [${g.selection.quadrant[0]}, ${g.selection.quadrant[1]}].`);return WSt(ab(l.base,_),g.selection,l.radius,l.segments,_)}function rTt(l,_){const g=_N(l.base,l.edge);if(!g.ok)throw new Error(g.issue.reason);if(g.selection.quadrant[0]!==l.quadrant[0]||g.selection.quadrant[1]!==l.quadrant[1])throw new Error(`chamferEdge() currently supports ${g.selection.edgeName} only with quadrant [${g.selection.quadrant[0]}, ${g.selection.quadrant[1]}].`);return VSt(ab(l.base,_),g.selection,l.size,_)}function ab(l,_){switch(l.kind){case"box":return _.Manifold.cube([l.x,l.y,l.z],l.center);case"cylinder":return _.Manifold.cylinder(l.height,l.radius,l.radiusTop??-1,l.segments??0,l.center);case"sphere":return _.Manifold.sphere(l.radius,l.segments??0);case"extrude":return mP(l.profile,_).extrude(l.height,0,0,l.scaleTop,l.center);case"sheetMetal":return ab(N2t(l.model,l.output),_);case"shell":{const g=$Be(l);if(!g.ok)throw new Error(g.reason);return ab(g.plan,_)}case"hole":{const g=cSt(l);if(!g.ok)throw new Error(g.reason);return ab(g.plan,_)}case"cut":{const g=lSt(l);if(!g.ok)throw new Error(g.reason);return ab(g.plan,_)}case"revolve":return mP(l.profile,_).revolve(l.segments??0,l.degrees);case"loft":return KSt(l,_);case"sweep":return eTt(l,_);case"boolean":return QSt(l,_);case"transform":return XSt(ab(l.base,_),l.steps);case"queryOwner":return ab(l.base,_);case"fillet":return tTt(l,_);case"chamfer":return rTt(l,_);case"hull":return YSt(l,_);case"trimByPlane":return ZSt(l,_)}}function nTt(l,_){return JBe(ab(l,_))}function fJe(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 FJ(l){if(!l)return[];const _=[];switch(l.kind){case"transform":_.push(...FJ(l.base)),_.push(...l.steps.map(fJe));break;case"queryOwner":_.push(...FJ(l.base));break;case"boolean":l.shapes.length>0&&_.push(...FJ(l.shapes[0]));break;case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":_.push(...FJ(l.base));break}return _}function Tve(l){if(!l)return{operation:"unknown"};switch(l.kind){case"queryOwner":return{operation:l.owner.operation,owner:l.owner};case"transform":return Tve(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 Tve(l.base);default:return{operation:l.kind}}}function K1e(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 Mk(l,_){switch(l.kind){case"queryOwner":Mk(l.base,_);return;case"transform":Mk(l.base,_);for(const g of l.steps){const S=fJe(g),D=g.kind==="translate"?"Move":g.kind==="rotate"?"Rotate":g.kind==="rotateAround"?"Rotate Around":g.kind==="scale"?"Scale":g.kind==="mirror"?"Mirror":"Place on Workplane";_.push({kind:g.kind,label:D,summary:S.description,category:"transform"})}return;case"shell":Mk(l.base,_),_.push({kind:"shell",label:"Shell",summary:`t = ${l.thickness}`,category:"modifier"});return;case"hole":Mk(l.base,_),_.push({kind:"hole",label:"Hole",summary:`r = ${l.hole.radius}`,category:"modifier"});return;case"cut":Mk(l.base,_),_.push({kind:"cut",label:"Cut",summary:K1e(l.profile),category:"modifier"});return;case"fillet":Mk(l.base,_),_.push({kind:"fillet",label:"Fillet",summary:`r = ${l.radius}`,category:"modifier"});return;case"chamfer":Mk(l.base,_),_.push({kind:"chamfer",label:"Chamfer",summary:`size = ${l.size}`,category:"modifier"});return;case"trimByPlane":Mk(l.base,_),_.push({kind:"trimByPlane",label:"Trim by Plane",summary:`normal [${l.normalX}, ${l.normalY}, ${l.normalZ}]`,category:"modifier"});return;case"boolean":l.shapes.length>0&&Mk(l.shapes[0],_),_.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":_.push({kind:"hull",label:"Hull",summary:`${l.shapes.length} shapes`,category:"boolean"});return;case"extrude":_.push({kind:"extrude",label:"Extrude",summary:`${K1e(l.profile)}, h = ${l.height}`,category:"sketch"});return;case"revolve":_.push({kind:"revolve",label:"Revolve",summary:`${l.degrees}°`,category:"sketch"});return;case"loft":_.push({kind:"loft",label:"Loft",summary:`${l.profiles.length} sections`,category:"sketch"});return;case"sweep":_.push({kind:"sweep",label:"Sweep",summary:K1e(l.profile),category:"sketch"});return;case"box":_.push({kind:"box",label:"Box",summary:`${l.x} × ${l.y} × ${l.z}`,category:"primitive"});return;case"cylinder":_.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":_.push({kind:"sphere",label:"Sphere",summary:`r = ${l.radius}`,category:"primitive"});return;case"sheetMetal":_.push({kind:"sheetMetal",label:"Sheet Metal",summary:"",category:"primitive"});return;default:{const g=l.kind;_.push({kind:g,label:g,summary:"",category:"primitive"});return}}}function iTt(l){if(!l)return[];const _=[];return Mk(l,_),_}function sTt(l,_){const g=FJ(l),S=Tve(l),D=iTt(l);return{faceName:_.name,origin:S,transformations:g,query:_.query,timeline:D}}let hE=null;async function aTt(){if(hE)return hE;const l=(await import("./manifold-65fIQlgQ.js")).default;return hE=await l(),hE.setup(),hE.setMinCircularAngle(2),hE.setMinCircularEdgeLength(.5),hE}function wd(){if(!hE)throw new Error("Kernel not initialized — call initKernel() first");return hE}function obe(l){if(l instanceof Ys)return l;if(l&&typeof l=="object"&&typeof l.toShape=="function"){const _=l.toShape();if(_ instanceof Ys)return _;throw new Error(`expected toShape() to return a Shape, got ${pee(_)}`)}throw new Error(`expected a Shape or TrackedShape-compatible value, got ${pee(l)}`)}const kve=new WeakMap,pJe=new WeakMap,dJe=new WeakMap,Cve=new WeakMap,mJe=new WeakMap;let _je=0;const iN={backend:"manifold",representation:"mesh-solid",fidelity:"unknown",topology:"none",sources:["unknown"]};function cbe(l){const _=[],g=new Set;for(const S of l)g.has(S)||(g.add(S),_.push(S));return _}function gJe(l){return{backend:l.backend,representation:l.representation,fidelity:l.fidelity,topology:l.topology,sources:[...l.sources]}}function tz(l={}){return{backend:l.backend??iN.backend,representation:l.representation??iN.representation,fidelity:l.fidelity??iN.fidelity,topology:l.topology??iN.topology,sources:cbe(l.sources?[...l.sources]:[...iN.sources])}}function T_(l,_){return pJe.set(l,gJe(_)),l}function oTt(l,_){const g=nSt(_)?_:JBe(_);return mJe.set(l,g),l}function Zl(l,_){return dJe.set(l,s_(_)),l}function rz(l,_){return f2t(_)?Cve.set(l,xBe(_)):Cve.delete(l),l}function jf(l){return gJe(pJe.get(l)??iN)}function i_(l){const _=mJe.get(l);if(!_)throw new Error("Runtime backend missing on Shape");return _}function Pu(l){return s_(dJe.get(l)??null)}function bE(l){return xBe(Cve.get(l)??YF())}function OK(l,_){const g=[...new Set(l)];return g.length===1?g[0]:_}function Ok(l,_,g={}){return tz({backend:g.backend??l.backend,representation:g.representation??l.representation,fidelity:g.fidelity??l.fidelity,topology:g.topology??l.topology,sources:cbe([_,...l.sources,...g.sources??[]])})}function fP(l,_,g={}){return tz({backend:g.backend??OK(l.map(S=>S.backend),"hybrid"),representation:g.representation??OK(l.map(S=>S.representation),"mixed"),fidelity:g.fidelity??OK(l.map(S=>S.fidelity),"mixed"),topology:g.topology??OK(l.map(S=>S.topology),"none"),sources:cbe([_,...l.flatMap(S=>S.sources),...g.sources??[]])})}function hJe(){return _je+=1,`shape-dim-${_je}`}function cTt(l,_=!1){return{id:_?hJe():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 nz(l,_=!1){return l.map(g=>cTt(g,_))}function XF(l,_){return _.length===0?kve.delete(l):kve.set(l,_),l}function iz(l){return kve.get(l)??[]}function fje(l,_){const g=_[0],S=_[1],D=_[2];return[l[0]*g+l[4]*S+l[8]*D+l[12],l[1]*g+l[5]*S+l[9]*D+l[13],l[2]*g+l[6]*S+l[10]*D+l[14]]}function lTt(l,_){return l.map(g=>({id:hJe(),from:fje(_,g.from),to:fje(_,g.to),offset:g.offset,autoOffset:g.autoOffset,label:g.label,color:g.color,components:g.components?[...g.components]:void 0,currentComponent:g.currentComponent}))}function uTt(l,_,g){return Sa.identity().rotateAxis([1,0,0],l).rotateAxis([0,1,0],_).rotateAxis([0,0,1],g).toArray()}function _Tt(l,_,g){const[S,D,F]=g,z=_*Math.PI/180,ee=Math.cos(z),pe=Math.sin(z),we=Math.sqrt(l[0]**2+l[1]**2+l[2]**2)||1,De=l[0]/we,te=l[1]/we,nt=l[2]/we,Te=ee+De*De*(1-ee),Me=De*te*(1-ee)-nt*pe,bt=De*nt*(1-ee)+te*pe,vt=te*De*(1-ee)+nt*pe,Bt=ee+te*te*(1-ee),fr=te*nt*(1-ee)-De*pe,hn=nt*De*(1-ee)-te*pe,vr=nt*te*(1-ee)+De*pe,Xt=ee+nt*nt*(1-ee),Wt=S-(Te*S+Me*D+bt*F),Hn=D-(vt*S+Bt*D+fr*F),zn=F-(hn*S+vr*D+Xt*F);return[Te,vt,hn,0,Me,Bt,vr,0,bt,fr,Xt,0,Wt,Hn,zn,1]}function fTt(l){const[_,g,S]=l,D=Math.hypot(_,g,S);if(D<1e-12)return Sa.identity().toArray();const F=_/D,z=g/D,ee=S/D,pe=1-2*F*F,we=-2*F*z,De=-2*F*ee,te=-2*z*F,nt=1-2*z*z,Te=-2*z*ee,Me=-2*ee*F,bt=-2*ee*z,vt=1-2*ee*ee;return[pe,te,Me,0,we,nt,bt,0,De,Te,vt,0,0,0,0,1]}function pTt(l){const _=typeof l=="number"?[l,l,l]:l;return!Number.isFinite(_[0])||!Number.isFinite(_[1])||!Number.isFinite(_[2])||Math.abs(_[0])<1e-12||Math.abs(_[1])<1e-12||Math.abs(_[2])<1e-12?null:[_[0],_[1],_[2]]}function MK(l,_){return l[0]*_[0]+l[1]*_[1]+l[2]*_[2]}function dTt(l,_){return[l[1]*_[2]-l[2]*_[1],l[2]*_[0]-l[0]*_[2],l[0]*_[1]-l[1]*_[0]]}function YK(l){return Math.hypot(l[0],l[1],l[2])}function pje(l){const _=YK(l);return _<1e-12?[1,0,0]:[l[0]/_,l[1]/_,l[2]/_]}function mTt(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 g=[l[0],l[1],l[2]],S=[l[4],l[5],l[6]],D=[l[8],l[9],l[10]],F=YK(g),z=YK(S),ee=YK(D);if(Math.abs(F-1)>1e-6||Math.abs(z-1)>1e-6||Math.abs(ee-1)>1e-6||Math.abs(MK(g,S))>1e-6||Math.abs(MK(g,D))>1e-6||Math.abs(MK(S,D))>1e-6)return null;const pe=MK(g,dTt(S,D));if(Math.abs(pe-1)>1e-6)return null;const we=l[0],De=l[4],te=l[8],nt=l[1],Te=l[5],Me=l[9],bt=l[2],vt=l[6],Bt=l[10],fr=l[12],hn=l[13],vr=l[14],Xt=[],Wt=we+Te+Bt,Hn=Math.max(-1,Math.min(1,(Wt-1)/2)),zn=Math.acos(Hn),Fs=zn*180/Math.PI;if(Fs>1e-6){let Jn;if(Math.PI-zn<1e-5){const oc=Math.max(0,(we+1)/2),ro=Math.max(0,(Te+1)/2),Br=Math.max(0,(Bt+1)/2),pc=(De+nt)/4,eo=(te+bt)/4,Gt=(Me+vt)/4;if(oc>=ro&&oc>=Br){const fa=Math.sqrt(oc);Jn=[fa,fa>1e-6?pc/fa:0,fa>1e-6?eo/fa:0]}else if(ro>=Br){const fa=Math.sqrt(ro);Jn=[fa>1e-6?pc/fa:0,fa,fa>1e-6?Gt/fa:0]}else{const fa=Math.sqrt(Br);Jn=[fa>1e-6?eo/fa:0,fa>1e-6?Gt/fa:0,fa]}}else Jn=pje([vt-Me,te-bt,nt-De]);Jn=pje(Jn),Xt.push({kind:"rotateAround",axisX:Jn[0],axisY:Jn[1],axisZ:Jn[2],degrees:Fs,pivotX:0,pivotY:0,pivotZ:0})}return(Math.abs(fr)>1e-6||Math.abs(hn)>1e-6||Math.abs(vr)>1e-6)&&Xt.push({kind:"translate",x:fr,y:hn,z:vr}),Xt}function eN(l,_){return XF(_,nz(iz(l),!0)),T_(_,jf(l)),rz(_,bE(l)),Zl(_,Pu(l))}function IF(l,_,g){const S=iz(l);return S.length===0?XF(_,[]):XF(_,lTt(S,g)),T_(_,jf(l)),rz(_,p2t(bE(l),g)),Zl(_,Pu(l))}function HJ(l,_){const g=l.flatMap(F=>iz(F));XF(_,nz(g,!0));const S=l.length>0?jf(l[0]):iN;T_(_,S),rz(_,SBe(...l.map(F=>bE(F))));const D=l.length>0?Pu(l[0]):null;return Zl(_,D)}function T1(l,_){return XF(_,nz(iz(l),!0)),T_(_,jf(l)),rz(_,bE(l)),Zl(_,Pu(l))}function dje(l,_){return Array.isArray(_)?[_[0],_[1],_[2]]:l.referencePoint(_)}function yee(l,_,g={}){const S=g.regenerateIds??!0;return XF(l,nz(_,S))}function lbe(l){return nz(iz(l),!1)}function Lee(l,_,g={}){const S=g.merge??!0?QRe(bE(l),_):QRe(YF(),_);return rz(l,S)}function yJe(l){return bE(l)}function vJe(l){return jf(l)}function Ree(l,_){const g=jf(l);return T_(l,tz({backend:_.backend??g.backend,representation:_.representation??g.representation,fidelity:_.fidelity??g.fidelity,topology:_.topology??g.topology,sources:_.sources??g.sources}))}function gP(l){return Pu(l)}function jee(l,_){return Zl(l,_)}function vee(l){return Iee(Pu(l))}function bJe(l){return U2t(Pu(l))}function gTt(l){return NJ(Pu(l))}function k_(l,_,g){return jee(new Ys(nTt(l,wd()),_,g),l)}function C1(l,_,g){if(!l)return null;const S=Nee(_);return KJ(rbe(l,g(S)),S)}class Ys{constructor(_,g,S){of(this,"colorHex");this.colorHex=g,oTt(this,_),T_(this,tz(S)),Zl(this,null)}setColor(_){return eN(this,new Ys(i_(this).clone(),_))}color(_){return this.setColor(_)}clone(){return eN(this,new Ys(i_(this).clone(),this.colorHex))}duplicate(){return this.clone()}geometryInfo(){return jf(this)}withReferences(_){return Lee(this.clone(),_,{merge:!0})}referenceNames(_){return TBe(bE(this),_)}referencePoint(_){return xJe(this,_)}face(_){const g=Pu(this),S=sje(g,_);if(S)return S;throw new Error(aje(g,_))}faceNames(){return Dxt(Pu(this))}faceHistory(_){const g=Pu(this),S=sje(g,_);if(!S)throw new Error(aje(g,_));return sTt(g,S)}placeReference(_,g,S){const D=this.referencePoint(_);let F=g[0]-D[0],z=g[1]-D[1],ee=g[2]-D[2];return S&&(F+=S[0],z+=S[1],ee+=S[2]),this.translate(F,z,ee)}translate(_,g,S){const D=E1(Pu(this),{kind:"translate",x:_,y:g,z:S});return Zl(IF(this,D?k_(D,this.colorHex):new Ys(i_(this).translate(_,g,S),this.colorHex),Sa.translation(_,g,S).toArray()),D)}moveTo(_,g,S){const D=this.boundingBox();return this.translate(_-D.min[0],g-D.min[1],S-D.min[2])}moveToLocal(_,g,S,D){const z=("toShape"in _?_.toShape():_).boundingBox();return this.moveTo(z.min[0]+g,z.min[1]+S,z.min[2]+D)}rotate(_,g,S){const D=E1(Pu(this),{kind:"rotate",xDeg:_,yDeg:g,zDeg:S});return Zl(IF(this,D?k_(D,this.colorHex):new Ys(i_(this).rotate(_,g,S),this.colorHex),uTt(_,g,S)),D)}transform(_){const g=_ instanceof Sa?_.toArray():_,S=(()=>{const D=mTt(g);return D==null?null:D.length===0?Pu(this):V2t(Pu(this),D)})();return Zl(IF(this,S?k_(S,this.colorHex):new Ys(i_(this).transform(g),this.colorHex),g),S)}scale(_){const g=pTt(_),S=g?E1(Pu(this),{kind:"scale",x:g[0],y:g[1],z:g[2]}):null;return Zl(IF(this,S?k_(S,this.colorHex):new Ys(i_(this).scale(_),this.colorHex),Sa.scale(_).toArray()),S)}mirror(_){const g=E1(Pu(this),{kind:"mirror",normalX:_[0],normalY:_[1],normalZ:_[2]}),S=jBe(g,"mirror");return Zl(IF(this,S?k_(S,this.colorHex):new Ys(i_(this).mirror(_),this.colorHex),fTt(_)),S)}pointAlong(_){const[g,S,D]=_,F=Math.sqrt(g*g+S*S+D*D)||1,z=g/F,ee=S/F,pe=D/F,we=-ee,De=z,te=0,nt=Math.sqrt(we*we+De*De+te*te),Te=pe;if(nt<1e-10)return Te>0?this:this.rotate(180,0,0);const Me=Math.atan2(nt,Te)*180/Math.PI,bt=we/nt,vt=De/nt,Bt=te/nt;return this.rotateAround([bt,vt,Bt],Me)}rotateAround(_,g,S=[0,0,0]){const D=Math.sqrt(_[0]**2+_[1]**2+_[2]**2)||1,F=[_[0]/D,_[1]/D,_[2]/D],z=_Tt(F,g,S),ee=E1(Pu(this),{kind:"rotateAround",axisX:F[0],axisY:F[1],axisZ:F[2],degrees:g,pivotX:S[0],pivotY:S[1],pivotZ:S[2]});return Zl(IF(this,ee?k_(ee,this.colorHex):new Ys(i_(this).transform(z),this.colorHex),z),ee)}rotateAroundTo(_,g,S,D,F={}){const z=dje(this,S),ee=dje(this,D),pe=fBe(_,g,z,ee,F);return this.rotateAround(_,pe,g)}smoothOut(_=60,g=0){return Zl(T_(eN(this,new Ys(i_(this).smoothOut(_,g),this.colorHex)),Ok(jf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}refine(_){const g=n2t(_);return g<=0?this.clone():Zl(T_(eN(this,new Ys(i_(this).refine(g),this.colorHex)),Ok(jf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}refineToLength(_){const g=i2t(_);return Zl(T_(eN(this,new Ys(i_(this).refineToLength(g),this.colorHex)),Ok(jf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}refineToTolerance(_){const g=s2t(_);return Zl(T_(eN(this,new Ys(i_(this).refineToTolerance(g),this.colorHex)),Ok(jf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}warp(_){return Zl(T_(eN(this,new Ys(i_(this).warp(_),this.colorHex)),Ok(jf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}static _unwrap(_){return obe(_)}add(..._){const g=[this,...BF("Shape.add()",_,1,"Use shape.add(other1, other2) or shape.add([other1, other2]).")],S=g.map(F=>Pu(F)),D=C1(Sy("union",S),"boolean:union",F=>lP("union",F,S));return Zl(T_(HJ(g,D?k_(D,this.colorHex):new Ys(wd().Manifold.union(JF("Shape.add()",g)),this.colorHex)),fP(g.map(F=>jf(F)),"boolean",{topology:"none"})),D)}subtract(..._){const g=[this,...BF("Shape.subtract()",_,1,"Use shape.subtract(other1, other2) or shape.subtract([other1, other2]).")],S=g.map(F=>Pu(F)),D=C1(Sy("difference",S),"boolean:difference",F=>lP("difference",F,S));return Zl(T_(T1(this,D?k_(D,this.colorHex):new Ys(wd().Manifold.difference(JF("Shape.subtract()",g)),this.colorHex)),fP(g.map(F=>jf(F)),"boolean",{topology:"none"})),D)}intersect(..._){const g=[this,...BF("Shape.intersect()",_,1,"Use shape.intersect(other1, other2) or shape.intersect([other1, other2]).")],S=g.map(F=>Pu(F)),D=C1(Sy("intersection",S),"boolean:intersection",F=>lP("intersection",F,S));return Zl(T_(HJ(g,D?k_(D,this.colorHex):new Ys(wd().Manifold.intersection(JF("Shape.intersect()",g)),this.colorHex)),fP(g.map(F=>jf(F)),"boolean",{topology:"none"})),D)}split(_){const g=Ys._unwrap(_),S=[Pu(this),Pu(g)],D=C1(Sy("intersection",S),"split:inside",De=>lP("intersection",De,S)),F=[Pu(this),Pu(g)],z=C1(Sy("difference",F),"split:outside",De=>lP("difference",De,F)),ee=fP([jf(this),jf(g)],"boolean",{topology:"none"});if(D&&z)return[Zl(T_(T1(this,k_(D,this.colorHex)),ee),D),Zl(T_(T1(this,k_(z,this.colorHex)),ee),z)];const[pe,we]=i_(this).split(i_(g));return[Zl(T_(T1(this,new Ys(pe,this.colorHex)),ee),null),Zl(T_(T1(this,new Ys(we,this.colorHex)),ee),null)]}splitByPlane(_,g=0){const S=Ok(jf(this),"boolean",{topology:"none"}),D=Pu(this),F=C1(H1e(D,_,g),"splitByPlane:positive",we=>Q1e(we,D)),z=C1(H1e(D,[-_[0],-_[1],-_[2]],-g),"splitByPlane:opposite",we=>Q1e(we,D));if(F&&z)return[Zl(T_(T1(this,k_(F,this.colorHex)),S),F),Zl(T_(T1(this,k_(z,this.colorHex)),S),z)];const[ee,pe]=i_(this).splitByPlane(_,g);return[Zl(T_(T1(this,new Ys(ee,this.colorHex)),S),null),Zl(T_(T1(this,new Ys(pe,this.colorHex)),S),null)]}trimByPlane(_,g=0){const S=Pu(this),D=C1(H1e(S,_,g),"trimByPlane",F=>Q1e(F,S));return Zl(T_(T1(this,D?k_(D,this.colorHex):new Ys(i_(this).trimByPlane(_,g),this.colorHex)),Ok(jf(this),"boolean",{topology:"none"})),D)}shell(_,g={}){const S=Pu(this),D=C1(mSt(S,_,g.openFaces),"shell",F=>Qxt(F,S,g.openFaces??[]));if(!D)throw new Error("Shape.shell() currently supports compile-covered box(), cylinder(), and straight extrude() solids with optional top/bottom openings and rigid transforms.");return Zl(T_(T1(this,k_(D,this.colorHex)),Ok(jf(this),"shell",{topology:"none"})),D)}hull(){const _=C1(EBe([Pu(this)]),"hull",g=>RBe(g));return Zl(T_(T1(this,_?k_(_,this.colorHex):new Ys(i_(this).hull(),this.colorHex)),Ok(jf(this),"hull",{topology:"none"})),_)}simplify(_){return Zl(T_(T1(this,new Ys(i_(this).simplify(_),this.colorHex)),Ok(jf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}boundingBox(){return i_(this).boundingBox()}volume(){return i_(this).volume()}surfaceArea(){return i_(this).surfaceArea()}minGap(_,g){const S="toShape"in _?_.toShape():_;return i_(this).minGap(i_(S),g)}isEmpty(){return i_(this).isEmpty()}numTri(){return i_(this).numTri()}getMesh(){return i_(this).getMesh()}slice(_=0){return i_(this).slice(_)}project(){return i_(this).project()}attachTo(_,g,S="center",D){const F=hTt(_,g),z=this.referencePoint(S);let ee=F[0]-z[0],pe=F[1]-z[1],we=F[2]-z[2];return D&&(ee+=D[0],pe+=D[1],we+=D[2]),this.translate(ee,pe,we)}onFace(_,g,S={}){const D=S.u??0,F=S.v??0,z=S.protrude??0,ee={front:"back",back:"front",left:"right",right:"left",top:"bottom",bottom:"top"},pe={front:(te,nt,Te)=>[te,-Te,nt],back:(te,nt,Te)=>[te,Te,nt],left:(te,nt,Te)=>[-Te,te,nt],right:(te,nt,Te)=>[Te,te,nt],top:(te,nt,Te)=>[te,nt,Te],bottom:(te,nt,Te)=>[te,nt,-Te]},we=ee[g],De=pe[g](D,F,z);return this.attachTo(_,g,we,De)}}function mje(l,_){const S=(typeof l.toShape=="function"?l.toShape():l).boundingBox();return pP(S.min,S.max,_)}function xJe(l,_){if(vBe(_))return mje(l,_);const g=d2t(bE(l),_);if(g)return g;const S=Pee(_);if(S)return mje(l,S);throw new Error(`Unknown placement reference "${_}". Available: ${TBe(bE(l)).join(", ")||"none"}`)}function hTt(l,_){if(l instanceof Ys)return xJe(l,_);if("referencePoint"in l&&typeof l.referencePoint=="function")return l.referencePoint(_);const g=Pee(_);if(!g)throw new Error(`ShapeGroup targets only support built-in anchors, got "${_}"`);if(!("_bbox"in l)||typeof l._bbox!="function")throw new Error("ShapeGroup anchor target is missing _bbox()");const S=l._bbox();return pP(S.min,S.max,g)}function DS(l,_,g,S=!1){return k_(kE({kind:"box",x:l,y:_,z:g,center:S},"primitive:box"),void 0,{fidelity:"kernel-native",sources:["primitive"]})}function lg(l,_,g,S,D=!1){return k_(kE({kind:"cylinder",height:l,radius:_,radiusTop:g!=null&&g>=0?g:void 0,segments:S!=null&&S>0?S:void 0,center:D},"primitive:cylinder"),void 0,{fidelity:"kernel-native",sources:["primitive"]})}function yTt(l,_){return k_(kE({kind:"sphere",radius:l,segments:_!=null&&_>0?_:void 0},"primitive:sphere"),void 0,{fidelity:"kernel-native",sources:["primitive"]})}function BF(l,_,g,S){return DBe({apiName:l,inputs:_,minCount:g,itemName:"shape",usage:S,coerce:D=>obe(D)})}function vTt(l,_,g){if(Array.isArray(l)&&l.length===3&&l.every(S=>typeof S=="number"&&Number.isFinite(S)))return l;throw new Error(`${_} argument ${g}: expected a [x, y, z] point, got ${pee(l)}`)}function JF(l,_){return _.map((g,S)=>gee(i_(g),`${l} operand ${S+1}`))}function I1(...l){const _=BF("union()",l,1,"Use union(shape1, shape2) or union([shape1, shape2]).");if(_.length===0)throw new Error("union requires at least one shape");if(_.length===1)return _[0];const g=_.map(D=>Pu(D)),S=C1(Sy("union",g),"boolean:union",D=>lP("union",D,g));return Zl(T_(HJ(_,S?k_(S,_[0].colorHex):new Ys(wd().Manifold.union(JF("union()",_)),_[0].colorHex)),fP(_.map(D=>jf(D)),"boolean",{topology:"none"})),S)}function bTt(...l){const _=BF("difference()",l,2,"Use difference(base, cutter1, cutter2) or difference([base, cutter1, cutter2]).");if(_.length<2)throw new Error("difference requires at least two shapes");const g=_.map(D=>Pu(D)),S=C1(Sy("difference",g),"boolean:difference",D=>lP("difference",D,g));return Zl(T_(T1(_[0],S?k_(S,_[0].colorHex):new Ys(wd().Manifold.difference(JF("difference()",_)),_[0].colorHex)),fP(_.map(D=>jf(D)),"boolean",{topology:"none"})),S)}function xTt(...l){const _=BF("intersection()",l,2,"Use intersection(shape1, shape2) or intersection([shape1, shape2]).");if(_.length<2)throw new Error("intersection requires at least two shapes");const g=_.map(D=>Pu(D)),S=C1(Sy("intersection",g),"boolean:intersection",D=>lP("intersection",D,g));return Zl(T_(HJ(_,S?k_(S,_[0].colorHex):new Ys(wd().Manifold.intersection(JF("intersection()",_)),_[0].colorHex)),fP(_.map(D=>jf(D)),"boolean",{topology:"none"})),S)}function STt(...l){var z,ee;const _=[],g=[],S=l.map((pe,we)=>{if(pe instanceof Ys||pe&&typeof pe=="object"&&typeof pe.toShape=="function"){const te=obe(pe);return _.push(te),gee(i_(te),`hull3d() shape ${_.length}`)}const De=vTt(pe,"hull3d()",we+1);return g.push(De),De}),D=C1(EBe(_.map(pe=>Pu(pe)),g),"hull",pe=>RBe(pe)),F=D?k_(D,(z=_[0])==null?void 0:z.colorHex):new Ys(wd().Manifold.hull(S),(ee=_[0])==null?void 0:ee.colorHex);return Zl(T_(HJ(_,F),_.length>0?fP(_.map(pe=>jf(pe)),"hull",{topology:"none"}):tz({fidelity:"kernel-native",sources:["hull"]})),D)}function ube(l,_,g,S=0){return new Ys(wd().Manifold.levelSet(l,{min:_.min,max:_.max},g,S),void 0,{fidelity:"sampled",sources:["level-set"]})}const SJe=new WeakMap,TJe=new WeakMap,kJe=new WeakMap;function ZK(l,_){return SJe.set(l,Cd(_)),l}function CJe(l){return l?[...l]:null}function jJ(l,_){return TJe.set(l,CJe(_)),l}function BJ(l,_){return kJe.set(l,TE(_)),l}class So{constructor(_,g){of(this,"colorHex");this.cross=_,this.colorHex=g,ZK(this,null),jJ(this,null),BJ(this,null)}color(_){return BJ(jJ(ZK(new So(this.cross,_),tm(this)),xE(this)),SE(this))}clone(){return BJ(jJ(ZK(new So(this.cross,this.colorHex),tm(this)),xE(this)),SE(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(_,g){throw new Error("Not implemented")}rotate(_){throw new Error("Not implemented")}rotateAround(_,g){throw new Error("Not implemented")}scale(_){throw new Error("Not implemented")}mirror(_){throw new Error("Not implemented")}add(..._){throw new Error("Not implemented")}subtract(..._){throw new Error("Not implemented")}intersect(..._){throw new Error("Not implemented")}offset(_,g="Round"){return X2(this,new So(this.cross.offset(_,g),this.colorHex))}hull(){return X2(this,new So(this.cross.hull(),this.colorHex))}simplify(_=1e-6){return X2(this,new So(this.cross.simplify(_),this.colorHex))}warp(_){return X2(this,new So(this.cross.warp(_),this.colorHex))}extrude(_,g){throw new Error("Not implemented")}revolve(_,g){throw new Error("Not implemented")}attachTo(_,g,S,D){throw new Error("Not implemented")}onFace(_,g,S){throw new Error("Not implemented")}}function tm(l){return Cd(SJe.get(l)??null)}function Ty(l,_){return ZK(l,_)}function Oh(l,_){return Ty(new So(mP(l,wd()),_),l)}function xE(l){return CJe(TJe.get(l)??null)}function hP(l,_){return jJ(l,_)}function SE(l){return TE(kJe.get(l)??null)}function yP(l,_){return BJ(l,_)}function X2(l,_){return BJ(jJ(_,xE(l)),SE(l))}function TTt(l,_,g=1e-8){if(l==null||_==null)return l==null&&_==null;for(let S=0;S<16;S+=1)if(Math.abs(l[S]-_[S])>g)return!1;return!0}function kTt(l,_,g=1e-8){if(l==null||_==null)return l==null&&_==null;if(!IS(l.source,_.source))return!1;const S=[[l.origin,_.origin],[l.u,_.u],[l.v,_.v],[l.normal,_.normal]];for(const[D,F]of S)for(let z=0;z<D.length;z+=1)if(Math.abs(D[z]-F[z])>g)return!1;return!0}function CTt(l,_,g=1e-8){return l==null||_==null?l==null&&_==null:kTt(l.workplane,_.workplane,g)&&Math.abs(l.u-_.u)<=g&&Math.abs(l.v-_.v)<=g&&Math.abs(l.protrude-_.protrude)<=g&&l.selfAnchor===_.selfAnchor}function hN(l){if(l.length===0)return null;const _=xE(l[0]);for(let g=1;g<l.length;g+=1)if(!TTt(_,xE(l[g])))return null;return _}function yN(l){if(l.length===0)return null;const _=SE(l[0]);for(let g=1;g<l.length;g+=1)if(!CTt(_,SE(l[g])))return null;return _}function wTt(l){const _=l.map(S=>Array.isArray(S)?[S[0],S[1]]:[S.x,S.y]);let g=0;for(let S=0;S<_.length;S++){const[D,F]=_[S],[z,ee]=_[(S+1)%_.length];g+=(z-D)*(ee+F)}return g>0&&_.reverse(),_.map(([S,D])=>[S,D])}function ES(l,_,g=!1){return Oh({kind:"rect",width:l,height:_,center:g,transforms:[]})}function _b(l,_){return Oh({kind:"circle",radius:l,segments:_!=null&&_>0?_:void 0,transforms:[]})}function bee(l,_,g,S=!1){const D=Math.min(g,l/2,_/2);return Oh({kind:"roundedRect",width:l,height:_,radius:D,center:S,transforms:[]})}function Ed(l){const _=wTt(l);return Oh({kind:"polygon",points:_,transforms:[]})}function ETt(l,_){const g=[];for(let S=0;S<l;S++){const D=2*Math.PI*S/l-Math.PI/2;g.push([_*Math.cos(D),_*Math.sin(D)])}return Ed(g)}function DTt(l,_,g=64){const S=[];for(let D=0;D<g;D++){const F=2*Math.PI*D/g;S.push([l*Math.cos(F),_*Math.sin(F)])}return Ed(S)}function PTt(l,_){const g=_/2,S=ES(l-_,_,!0),D=_b(g).translate(-(l-_)/2,0),F=_b(g).translate((l-_)/2,0);return S.add(D).add(F)}function ATt(l,_,g){const S=[];for(let D=0;D<l*2;D++){const F=Math.PI*D/l-Math.PI/2,z=D%2===0?_:g;S.push([z*Math.cos(F),z*Math.sin(F)])}return Ed(S)}function fN(l,_,g=0){const S=lb(tm(l),{kind:"translate",x:_,y:g});return X2(l,S?Oh(S,l.colorHex):Ty(new So(l.cross.translate(_,g),l.colorHex),null))}function H2(l,_){const g=lb(tm(l),{kind:"rotate",degrees:_});return X2(l,g?Oh(g,l.colorHex):Ty(new So(l.cross.rotate(_),l.colorHex),null))}function NTt(l,_,g){return fN(H2(fN(l,-g[0],-g[1]),_),g[0],g[1])}function ITt(l,_){const g=typeof _=="number"?[_,_]:_,S=lb(tm(l),{kind:"scale",x:g[0],y:g[1]});return X2(l,S?Oh(S,l.colorHex):Ty(new So(l.cross.scale(_),l.colorHex),null))}function FTt(l,_){const g=lb(tm(l),{kind:"mirror",normalX:_[0],normalY:_[1]});return X2(l,g?Oh(g,l.colorHex):Ty(new So(l.cross.mirror(_),l.colorHex),null))}So.prototype.translate=function(l,_=0){return fN(this,l,_)};So.prototype.rotate=function(l){return H2(this,l)};So.prototype.rotateAround=function(l,_){return NTt(this,l,_)};So.prototype.scale=function(l){return ITt(this,l)};So.prototype.mirror=function(l){return FTt(this,l)};function k1(l,_,g){return{name:l,start:_,end:g,query:{kind:"tracked-edge",edgeName:l,selector:"edge"}}}class lo{constructor(_,g,S,D){this.shape=_,this.topology=g,this.baseHeight=S,this.extrudeUp=D,Lee(this.shape,LTt(this.topology),{merge:!0})}face(_){var D;const g=this.topology.faces.get(_);if(!g){const F=[...this.topology.faces.keys()].join(", ");throw new Error(`Face "${_}" not found. Available: ${F}`)}const S=vee(this.shape);return{...g,normal:[g.normal[0],g.normal[1],g.normal[2]],center:[g.center[0],g.center[1],g.center[2]],query:Kl({kind:"tracked-face",faceName:_,owner:fp(S??((D=g.query)==null?void 0:D.owner))}),uAxis:g.uAxis?[g.uAxis[0],g.uAxis[1],g.uAxis[2]]:void 0,vAxis:g.vAxis?[g.vAxis[0],g.vAxis[1],g.vAxis[2]]:void 0}}edge(_){var D;const g=this.topology.edges.get(_);if(!g){const F=[...this.topology.edges.keys()].join(", ");throw new Error(`Edge "${_}" not found. Available: ${F}`)}const S=vee(this.shape);return{...g,start:[g.start[0],g.start[1],g.start[2]],end:[g.end[0],g.end[1],g.end[2]],query:Tl({kind:"tracked-edge",edgeName:_,selector:"edge",owner:fp(S??((D=g.query)==null?void 0:D.owner))})}}faceNames(){return[...this.topology.faces.keys()]}edgeNames(){return[...this.topology.edges.keys()]}clone(){return new lo(this.shape.clone(),eve(this.topology),this.baseHeight,this.extrudeUp)}duplicate(){return this.clone()}geometryInfo(){const _=this.shape.geometryInfo(),g=this.topology.faces.size>0||this.topology.edges.size>0;return{..._,topology:g?"synthetic":_.topology}}withReferences(_){return new lo(this.shape.withReferences(_),eve(this.topology),this.baseHeight,this.extrudeUp)}referenceNames(_){return this.shape.referenceNames(_)}referencePoint(_){return this.shape.referencePoint(_)}placeReference(_,g,S){return new lo(this.shape.placeReference(_,g,S),eve(this.topology),this.baseHeight,this.extrudeUp)}translate(_,g,S){const D=OTt(this.topology,_,g,S);return new lo(this.shape.translate(_,g,S),D,this.baseHeight,this.extrudeUp)}moveTo(_,g,S){const D=this.shape.boundingBox();return this.translate(_-D.min[0],g-D.min[1],S-D.min[2])}moveToLocal(_,g,S,D){const z=(_ instanceof lo?_.toShape():_).boundingBox();return this.moveTo(z.min[0]+g,z.min[1]+S,z.min[2]+D)}moveBy(_,g,S){return this.translate(_,g,S)}rotateAroundEdge(_,g){const S=this.edge(_),[D,F,z]=S.start,ee=S.end[0]-D,pe=S.end[1]-F,we=S.end[2]-z,De=Math.sqrt(ee*ee+pe*pe+we*we)||1,te=ee/De,nt=pe/De,Te=we/De,Me=g*Math.PI/180,bt=Math.cos(Me),vt=Math.sin(Me),Bt=1-bt,fr=Bt*te*te+bt,hn=Bt*te*nt-vt*Te,vr=Bt*te*Te+vt*nt,Xt=Bt*te*nt+vt*Te,Wt=Bt*nt*nt+bt,Hn=Bt*nt*Te-vt*te,zn=Bt*te*Te-vt*nt,Fs=Bt*nt*Te+vt*te,Jn=Bt*Te*Te+bt,oc=-fr*D-hn*F-vr*z+D,ro=-Xt*D-Wt*F-Hn*z+F,Br=-zn*D-Fs*F-Jn*z+z,pc=[fr,Xt,zn,0,hn,Wt,Fs,0,vr,Hn,Jn,0,oc,ro,Br,1],eo=this.shape.transform(pc);return new lo(eo,{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}rotate(_,g,S){return new lo(this.shape.rotate(_,g,S),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}transform(_){return new lo(this.shape.transform(_),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}pointAlong(_){return new lo(this.shape.pointAlong(_),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}rotateAround(_,g,S=[0,0,0]){return new lo(this.shape.rotateAround(_,g,S),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}rotateAroundTo(_,g,S,D,F={}){return new lo(this.shape.rotateAroundTo(_,g,S,D,F),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}scale(_){return new lo(this.shape.scale(_),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}mirror(_){return new lo(this.shape.mirror(_),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}color(_){return new lo(this.shape.color(_),this.topology,this.baseHeight,this.extrudeUp)}toShape(){return this.shape}attachTo(_,g,S="center",D){let F;if(typeof _._bbox=="function"&&!(_ instanceof lo)&&!(_ instanceof Ys)){if(g.includes("."))throw new Error(`ShapeGroup targets only support built-in anchors, got "${g}"`);const De=_._bbox();F=pP(De.min,De.max,g)}else F=(_ instanceof lo,_).referencePoint(g);const z=this.referencePoint(S);let ee=F[0]-z[0],pe=F[1]-z[1],we=F[2]-z[2];return D&&(ee+=D[0],pe+=D[1],we+=D[2]),this.translate(ee,pe,we)}onFace(_,g,S={}){const D=S.u??0,F=S.v??0,z=S.protrude??0,ee={front:"back",back:"front",left:"right",right:"left",top:"bottom",bottom:"top"},pe={front:(we,De,te)=>[we,-te,De],back:(we,De,te)=>[we,te,De],left:(we,De,te)=>[-te,we,De],right:(we,De,te)=>[te,we,De],top:(we,De,te)=>[we,De,te],bottom:(we,De,te)=>[we,De,-te]};return this.attachTo(_,g,ee[g],pe[g](D,F,z))}subtract(..._){return this.shape.subtract(..._)}add(..._){return this.shape.add(..._)}intersect(..._){return this.shape.intersect(..._)}shell(_,g={}){return this.shape.shell(_,g)}boundingBox(){return this.shape.boundingBox()}get volume(){return this.shape.volume()}}function OTt(l,_,g,S){const D=new Map;for(const[z,ee]of l.faces)D.set(z,{...ee,center:[ee.center[0]+_,ee.center[1]+g,ee.center[2]+S],query:Kl(ee.query),uAxis:ee.uAxis?[ee.uAxis[0],ee.uAxis[1],ee.uAxis[2]]:void 0,vAxis:ee.vAxis?[ee.vAxis[0],ee.vAxis[1],ee.vAxis[2]]:void 0});const F=new Map;for(const[z,ee]of l.edges)F.set(z,{...ee,start:[ee.start[0]+_,ee.start[1]+g,ee.start[2]+S],end:[ee.end[0]+_,ee.end[1]+g,ee.end[2]+S],query:Tl(ee.query)});return{faces:D,edges:F}}function eve(l){const _=new Map;for(const[S,D]of l.faces)_.set(S,{...D,normal:[D.normal[0],D.normal[1],D.normal[2]],center:[D.center[0],D.center[1],D.center[2]],query:Kl(D.query),uAxis:D.uAxis?[D.uAxis[0],D.uAxis[1],D.uAxis[2]]:void 0,vAxis:D.vAxis?[D.vAxis[0],D.vAxis[1],D.vAxis[2]]:void 0});const g=new Map;for(const[S,D]of l.edges)g.set(S,{...D,start:[D.start[0],D.start[1],D.start[2]],end:[D.end[0],D.end[1],D.end[2]],query:Tl(D.query)});return{faces:_,edges:g}}function MTt(l,_){const g=Sa.from(_),S=new Map;for(const[F,z]of l.faces)S.set(F,{...z,normal:$p(g.vector(z.normal)),center:g.point(z.center),query:Kl(z.query),uAxis:z.uAxis?$p(g.vector(z.uAxis)):void 0,vAxis:z.vAxis?$p(g.vector(z.vAxis)):void 0});const D=new Map;for(const[F,z]of l.edges)D.set(F,{...z,start:g.point(z.start),end:g.point(z.end),query:Tl(z.query)});return{faces:S,edges:D}}function LTt(l){const _={};for(const[S,D]of l.faces)_[S]={center:[D.center[0],D.center[1],D.center[2]],normal:[D.normal[0],D.normal[1],D.normal[2]]};const g={};for(const[S,D]of l.edges)g[S]={start:[D.start[0],D.start[1],D.start[2]],end:[D.end[0],D.end[1],D.end[2]]};return{surfaces:_,edges:g}}function wJe(l,_,g=!0,S=0){const D=new Map,F=new Map,[z,ee,pe,we]=l.vertices,De=S,te=S+(g?_:-_),nt=Math.max(De,te),Te=Math.min(De,te),Me=l.center.x,bt=l.center.y,vt=$p([ee.x-z.x,ee.y-z.y,0]),Bt=$p([we.x-z.x,we.y-z.y,0]);D.set("top",{name:"top",normal:[0,0,1],center:[Me,bt,nt],planar:!0,uAxis:vt,vAxis:Bt}),D.set("bottom",{name:"bottom",normal:[0,0,-1],center:[Me,bt,Te],planar:!0,uAxis:vt,vAxis:[-Bt[0],-Bt[1],-Bt[2]]});const fr=[["bottom",z,ee],["right",ee,pe],["top",pe,we],["left",we,z]];for(const[hn,vr,Xt]of fr){const Wt=vr.midpointTo(Xt),Hn=Xt.x-vr.x,zn=Xt.y-vr.y,Fs=Math.sqrt(Hn*Hn+zn*zn)||1,Jn=zn/Fs,oc=-Hn/Fs,ro=[Hn/Fs,zn/Fs,0];D.set(`side-${hn}`,{name:`side-${hn}`,normal:[Jn,oc,0],center:[Wt.x,Wt.y,(nt+Te)/2],planar:!0,uAxis:ro,vAxis:[0,0,1]})}return F.set("bottom-bottom",k1("bottom-bottom",[z.x,z.y,Te],[ee.x,ee.y,Te])),F.set("bottom-right",k1("bottom-right",[ee.x,ee.y,Te],[pe.x,pe.y,Te])),F.set("bottom-top",k1("bottom-top",[pe.x,pe.y,Te],[we.x,we.y,Te])),F.set("bottom-left",k1("bottom-left",[we.x,we.y,Te],[z.x,z.y,Te])),F.set("top-bottom",k1("top-bottom",[z.x,z.y,nt],[ee.x,ee.y,nt])),F.set("top-right",k1("top-right",[ee.x,ee.y,nt],[pe.x,pe.y,nt])),F.set("top-top",k1("top-top",[pe.x,pe.y,nt],[we.x,we.y,nt])),F.set("top-left",k1("top-left",[we.x,we.y,nt],[z.x,z.y,nt])),F.set("vert-bl",k1("vert-bl",[z.x,z.y,Te],[z.x,z.y,nt])),F.set("vert-br",k1("vert-br",[ee.x,ee.y,Te],[ee.x,ee.y,nt])),F.set("vert-tr",k1("vert-tr",[pe.x,pe.y,Te],[pe.x,pe.y,nt])),F.set("vert-tl",k1("vert-tl",[we.x,we.y,Te],[we.x,we.y,nt])),{faces:D,edges:F}}function EJe(l,_,g=!1){const S=new Map,D=new Map,F=l.center.x,z=l.center.y,ee=g?-_/2:0,pe=g?_/2:_,we=Math.min(ee,pe),De=Math.max(ee,pe),te=l.radiusTop??l.radius,nt=(Math.abs(l.radius)+Math.abs(te))/2;return S.set("top",{name:"top",normal:[0,0,1],center:[F,z,De],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0]}),S.set("bottom",{name:"bottom",normal:[0,0,-1],center:[F,z,we],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0]}),S.set("side",{name:"side",normal:[1,0,0],center:[F+nt,z,(De+we)/2],planar:!1}),D.set("top-rim",k1("top-rim",[F+te,z,De],[F,z+te,De])),D.set("bottom-rim",k1("bottom-rim",[F+l.radius,z,we],[F,z+l.radius,we])),{faces:S,edges:D}}function RTt(l,_){const g=l.bounds(),[S,D]=g.min,[F,z]=g.max,ee=(S+F)/2,pe=(D+z)/2;switch(_){case"center":return[ee,pe];case"top-left":return[S,z];case"top-right":return[F,z];case"bottom-left":return[S,D];case"bottom-right":return[F,D];case"top":return[ee,z];case"bottom":return[ee,D];case"left":return[S,pe];case"right":return[F,pe]}}function jTt(l,_){if(typeof l._bbox=="function"){const D=l._bbox();return pP(D.min,D.max,_)}const g=l;return("toShape"in g?g.toShape():g).referencePoint(_)}function BTt(l){if(typeof l._bbox=="function")return;const _=l,g="toShape"in _?_.toShape():_;return fp(vee(g)??void 0)}function gje(l){return l==="front"||l==="back"||l==="left"||l==="right"||l==="top"||l==="bottom"}function hje(l){if(!l||typeof l!="object")return!1;const _=l;return typeof _.name=="string"&&Array.isArray(_.normal)&&Array.isArray(_.center)}function JTt(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 LK(l){if(l.planar===!1||!l.uAxis||!l.vAxis)throw new Error(`Face "${l.name}" is not planar and cannot host a sketch.`);const _=(()=>{var S;if(l.query&&l.query.kind!=="tracked-face"&&l.query.kind!=="canonical-face")return Kl(l.query);const g=fp((S=l.query)==null?void 0:S.owner);return{kind:"face-ref",faceName:l.name,owner:g}})();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:_}}function zTt(l,_){var D;const g=l.topology.faces.get(_);if(!g)return null;const S=vee(l.toShape())??((D=g.query)==null?void 0:D.owner);return{...g,normal:[g.normal[0],g.normal[1],g.normal[2]],center:[g.center[0],g.center[1],g.center[2]],query:Kl({kind:"tracked-face",faceName:_,owner:fp(S??void 0)}),uAxis:g.uAxis?[g.uAxis[0],g.uAxis[1],g.uAxis[2]]:void 0,vAxis:g.vAxis?[g.vAxis[0],g.vAxis[1],g.vAxis[2]]:void 0}}function qTt(l){return l.faceNames().filter(_=>{const g=l.topology.faces.get(_);return!!g&&g.planar!==!1&&!!g.uAxis&&!!g.vAxis})}function WTt(l,_){const g=l instanceof Error?l.message:String(l);return g===`Face "${_}" is not available. Supported faces: none`||g.startsWith(`Face "${_}" is not available. Supported faces: `)}function QF(l,_){if(hje(l))return LK(l);if(_==null)throw new Error("Sketch.onFace(parent, face, opts) requires a face name or FaceRef.");if(hje(_))return LK(_);if(typeof _!="string")throw new Error("Sketch.onFace() requires a face name or FaceRef.");if(l instanceof lo){const g=zTt(l,_);if(g)return{...LK(g),source:Kl(g.query)??{kind:"tracked-face",faceName:_}}}if(l instanceof Ys&&gP(l))try{return LK(l.face(_))}catch(g){if(!gje(_)||!WTt(g,_))throw g}if(gje(_)){const g=JTt(_);return{origin:jTt(l,_),u:g.u,v:g.v,normal:g.normal,source:{kind:"canonical-face",face:_,owner:BTt(l)}}}if(l instanceof lo){const g=qTt(l).join(", ")||"none";throw new Error(`Face "${_}" not found or is not planar. Available planar faces: ${g}`)}throw new Error(`Named face "${_}" requires a TrackedShape parent or a FaceRef target.`)}function VTt(l,_,g,S){return[l[0],l[1],l[2],0,_[0],_[1],_[2],0,g[0],g[1],g[2],0,S[0],S[1],S[2],1]}function UTt(l,_){const[g,S]=RTt(l,_.selfAnchor),D=[_.workplane.origin[0]+_.workplane.u[0]*_.u+_.workplane.v[0]*_.v+_.workplane.normal[0]*_.protrude,_.workplane.origin[1]+_.workplane.u[1]*_.u+_.workplane.v[1]*_.v+_.workplane.normal[1]*_.protrude,_.workplane.origin[2]+_.workplane.u[2]*_.u+_.workplane.v[2]*_.v+_.workplane.normal[2]*_.protrude],F=VTt(_.workplane.u,_.workplane.v,_.workplane.normal,D);return Sa.translation(-g,-S,0).mul(F).toArray()}function $Tt(l){if(!l||typeof l!="object")return!1;const _=l;return typeof _.name=="string"&&Array.isArray(_.normal)&&Array.isArray(_.center)}function HTt(l,_,g,S={}){const D=$Tt(_);if(D&&typeof g=="string")throw new Error("Sketch.onFace(faceRef, opts) accepts options as the second argument, not a face name.");const F=D?QF(_):QF(_,g),z=(D?g:S)??{},ee={workplane:F,u:z.u??0,v:z.v??0,protrude:z.protrude??0,selfAnchor:z.selfAnchor??"center"};return yP(hP(l.clone(),UTt(l,ee)),ee)}So.prototype.onFace=function(l,_,g={}){return HTt(this,l,_,g)};function vN(l,_,g,S){return DBe({apiName:l,inputs:_,minCount:g,itemName:"sketch",usage:S,coerce:D=>{if(D instanceof So)return D;throw new Error(`expected a Sketch, got ${pee(D)}`)}})}function GTt(l,..._){const g=[l,...vN("Sketch.add()",_,1,"Use sketch.add(other1, other2) or sketch.add([other1, other2]).")],S=NS("union",g.map(D=>tm(D)));return yP(hP(S?Oh(S,l.colorHex):Ty(new So(wd().CrossSection.union(g.map(D=>D.cross)),l.colorHex),null),hN(g)),yN(g))}function XTt(l,..._){const g=[l,...vN("Sketch.subtract()",_,1,"Use sketch.subtract(other1, other2) or sketch.subtract([other1, other2]).")],S=NS("difference",g.map(D=>tm(D)));return yP(hP(S?Oh(S,l.colorHex):Ty(new So(wd().CrossSection.difference(g.map(D=>D.cross)),l.colorHex),null),hN(g)),yN(g))}function QTt(l,..._){const g=[l,...vN("Sketch.intersect()",_,1,"Use sketch.intersect(other1, other2) or sketch.intersect([other1, other2]).")],S=NS("intersection",g.map(D=>tm(D)));return yP(hP(S?Oh(S,l.colorHex):Ty(new So(wd().CrossSection.intersection(g.map(D=>D.cross)),l.colorHex),null),hN(g)),yN(g))}function Fh(...l){const _=vN("union2d()",l,1,"Use union2d(sketch1, sketch2) or union2d([sketch1, sketch2]).");if(_.length===0)throw new Error("union2d requires at least one sketch");if(_.length===1)return _[0];const g=NS("union",_.map(S=>tm(S)));return yP(hP(g?Oh(g,_[0].colorHex):Ty(new So(wd().CrossSection.union(_.map(S=>S.cross)),_[0].colorHex),null),hN(_)),yN(_))}function N1(...l){const _=vN("difference2d()",l,2,"Use difference2d(base, cutter1, cutter2) or difference2d([base, cutter1, cutter2]).");if(_.length<2)throw new Error("difference2d requires at least two sketches");const g=NS("difference",_.map(S=>tm(S)));return yP(hP(g?Oh(g,_[0].colorHex):Ty(new So(wd().CrossSection.difference(_.map(S=>S.cross)),_[0].colorHex),null),hN(_)),yN(_))}function YTt(...l){const _=vN("intersection2d()",l,2,"Use intersection2d(sketch1, sketch2) or intersection2d([sketch1, sketch2]).");if(_.length<2)throw new Error("intersection2d requires at least two sketches");const g=NS("intersection",_.map(S=>tm(S)));return yP(hP(g?Oh(g,_[0].colorHex):Ty(new So(wd().CrossSection.intersection(_.map(S=>S.cross)),_[0].colorHex),null),hN(_)),yN(_))}function ZTt(...l){const _=vN("hull2d()",l,1,"Use hull2d(sketch1, sketch2) or hull2d([sketch1, sketch2]).");if(_.length===0)throw new Error("hull2d requires at least one sketch");const g=wBe(_.map(S=>tm(S)));return yP(hP(g?Oh(g,_[0].colorHex):Ty(new So(wd().CrossSection.hull(_.map(S=>S.cross)),_[0].colorHex),null),hN(_)),yN(_))}So.prototype.add=function(...l){return GTt(this,...l)};So.prototype.subtract=function(...l){return XTt(this,...l)};So.prototype.intersect=function(...l){return QTt(this,...l)};function KTt(l,_,g="Round"){const S=g==="Round"?CBe(tm(l),_,"Round"):null;return X2(l,S?Oh(S,l.colorHex):Ty(new So(l.cross.offset(_,g),l.colorHex),null))}function ekt(l){const _=wBe([tm(l)]);return X2(l,_?Oh(_,l.colorHex):Ty(new So(l.cross.hull(),l.colorHex),null))}function tkt(l,_=1e-6){return X2(l,new So(l.cross.simplify(_),l.colorHex))}function rkt(l,_){return X2(l,new So(l.cross.warp(_),l.colorHex))}So.prototype.offset=function(l,_="Round"){return KTt(this,l,_)};So.prototype.hull=function(){return ekt(this)};So.prototype.simplify=function(l=1e-6){return tkt(this,l)};So.prototype.warp=function(l){return rkt(this,l)};function nkt(l,_,g){const S=new Map,D=new Map,F=l.bounds(),z=(F.min[0]+F.max[0])/2,ee=(F.min[1]+F.max[1])/2,pe=g?-_/2:0,we=g?_/2:_;return S.set("top",{name:"top",normal:[0,0,1],center:[z,ee,we],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0]}),S.set("bottom",{name:"bottom",normal:[0,0,-1],center:[z,ee,pe],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0]}),S.set("side",{name:"side",normal:[1,0,0],center:[F.max[0],ee,(we+pe)/2],planar:!1}),{faces:S,edges:D}}function FS(l,_,g){const S=typeof(g==null?void 0:g.scaleTop)=="number"?[g.scaleTop,g.scaleTop]:g==null?void 0:g.scaleTop,D=((g==null?void 0:g.twist)==null||g.twist===0)&&((g==null?void 0:g.divisions)==null||g.divisions===0)?(()=>{const nt=tm(l);return nt?{kind:"extrude",profile:nt,height:_,center:(g==null?void 0:g.center)??!1,scaleTop:S}:null})():null,F=xE(l),z=SE(l),ee=D&&F&&z?E1(D,{kind:"workplanePlacement",matrix:F,placement:z}):D,pe=kE(ee,"extrude"),we=pe?k_(pe,l.colorHex,{fidelity:"kernel-native",sources:["extrude"]}):jee(new Ys(l.cross.extrude(_,(g==null?void 0:g.divisions)??0,(g==null?void 0:g.twist)??0,S,(g==null?void 0:g.center)??!1),l.colorHex,{fidelity:"kernel-native",sources:["extrude"]}),null),De=nkt(l,_,(g==null?void 0:g.center)??!1);if(!F)return new lo(we,De,0,!0);const te=MTt(De,F);return pe&&z?new lo(we,te,0,!0):new lo(we.transform(F),te,0,!0)}function ikt(l,_=360,g){const S=(()=>{const we=tm(l);return we?{kind:"revolve",profile:we,degrees:_,segments:g!=null&&g>0?g:void 0}:null})(),D=xE(l),F=SE(l),z=S&&D&&F?E1(S,{kind:"workplanePlacement",matrix:D,placement:F}):S,ee=kE(z,"revolve"),pe=ee?k_(ee,l.colorHex,{fidelity:"kernel-native",sources:["revolve"]}):jee(new Ys(l.cross.revolve(g??0,_),l.colorHex,{fidelity:"kernel-native",sources:["revolve"]}),null);return!D||ee&&F?pe:pe.transform(D)}So.prototype.extrude=function(l,_){return FS(this,l,_)};So.prototype.revolve=function(l=360,_){return ikt(this,l,_)};class DJe{constructor(){of(this,"points",[]);of(this,"x",0);of(this,"y",0)}moveTo(_,g){return this.x=_,this.y=g,this.points.push([_,g]),this}lineTo(_,g){return this.x=_,this.y=g,this.points.push([_,g]),this}lineH(_){return this.lineTo(this.x+_,this.y)}lineV(_){return this.lineTo(this.x,this.y+_)}lineAngled(_,g){const S=g*Math.PI/180;return this.lineTo(this.x+_*Math.cos(S),this.y+_*Math.sin(S))}close(){if(this.points.length<3)throw new Error("Path needs at least 3 points");const _=this.points;let g=0;for(let S=0;S<_.length;S++){const[D,F]=_[S],[z,ee]=_[(S+1)%_.length];g+=(z-D)*(ee+F)}return g>0&&_.reverse(),Ed(_)}stroke(_,g="Square"){if(this.points.length<2)throw new Error("Stroke needs at least 2 points");const S=_/2,D=this.points,F=D.length,z=[];for(let nt=0;nt<F-1;nt++){const Te=D[nt+1][0]-D[nt][0],Me=D[nt+1][1]-D[nt][1],bt=Math.sqrt(Te*Te+Me*Me);z.push([-Me/bt,Te/bt])}const ee=[],pe=[];for(let nt=0;nt<F;nt++){const[Te,Me]=D[nt];if(nt===0||nt===F-1){const bt=z[nt===0?0:F-2];ee.push([Te+bt[0]*S,Me+bt[1]*S]),pe.push([Te-bt[0]*S,Me-bt[1]*S])}else{const bt=z[nt-1],vt=z[nt];let Bt=bt[0]+vt[0],fr=bt[1]+vt[1],hn=Math.sqrt(Bt*Bt+fr*fr);hn<1e-9&&(Bt=bt[0],fr=bt[1],hn=1),Bt/=hn,fr/=hn;const vr=S/(Bt*bt[0]+fr*bt[1]);ee.push([Te+Bt*vr,Me+fr*vr]),pe.push([Te-Bt*vr,Me-fr*vr])}}const we=[...ee,...pe.reverse()];let De=0;for(let nt=0;nt<we.length;nt++){const[Te,Me]=we[nt],[bt,vt]=we[(nt+1)%we.length];De+=(bt-Te)*(vt+Me)}De>0&&we.reverse();let te=Ed(we);return g==="Round"&&(te=te.offset(-S/2,"Round").offset(S/2,"Round")),te}}function skt(){return new DJe}function _be(l,_,g="Square"){const S=new DJe;S.moveTo(l[0][0],l[0][1]);for(let D=1;D<l.length;D++)S.lineTo(l[D][0],l[D][1]);return S.stroke(_,g)}function yje(l,_){const g=l.bounds(),[S,D]=g.min,[F,z]=g.max,ee=(S+F)/2,pe=(D+z)/2;switch(_){case"center":return[ee,pe];case"top-left":return[S,z];case"top-right":return[F,z];case"bottom-left":return[S,D];case"bottom-right":return[F,D];case"top":return[ee,z];case"bottom":return[ee,D];case"left":return[S,pe];case"right":return[F,pe]}}function akt(l,_,g,S="center",D){const F=yje(_,g),z=yje(l,S);let ee=F[0]-z[0],pe=F[1]-z[1];return D&&(ee+=D[0],pe+=D[1]),l.translate(ee,pe)}So.prototype.attachTo=function(l,_,g="center",S){return akt(this,l,_,g,S)};const xee=.001,PJe=l=>l*Math.PI/180,rN=(l,_)=>{const g=_.x-l.x,S=_.y-l.y;return Math.sqrt(g*g+S*S)},w1=(l,_)=>[(l.x+_.x)/2,(l.y+_.y)/2],vje=(l,_)=>{const g=rN(l,_)||1;return[(_.x-l.x)/g,(_.y-l.y)/g]},bje=(l,_)=>Math.atan2(_.y-l.y,_.x-l.x),okt=l=>{let _=l;for(;_>Math.PI;)_-=Math.PI*2;for(;_<-Math.PI;)_+=Math.PI*2;return _},AJe=(l,_,g)=>{const S=g.x-_.x,D=g.y-_.y,F=S*S+D*D;if(F<1e-9)return[_.x,_.y];const z=((l.x-_.x)*S+(l.y-_.y)*D)/F;return[_.x+z*S,_.y+z*D]},xje=(l,_,g)=>{const S=AJe(l,_,g);return[2*S[0]-l.x,2*S[1]-l.y]},NJe=l=>({points:l.points.map(_=>({..._})),lines:l.lines.map(_=>({..._})),circles:l.circles.map(_=>({..._})),loops:l.loops.map(_=>_.type==="poly"?{type:"poly",points:[..._.points]}:{type:"circle",circle:_.circle}),constraints:l.constraints.map(_=>({..._})),rejectedConstraints:l.rejectedConstraints.map(_=>({..._}))}),ckt=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"}},lkt=l=>l==="distance"||l==="length"||l==="angle"||l==="radius"||l==="diameter"||l==="hDistance"||l==="vDistance",ukt=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},_kt=(l,_)=>{l.type==="distance"&&(l.value=_),l.type==="length"&&(l.value=_),l.type==="angle"&&(l.value=_),l.type==="radius"&&(l.value=_),l.type==="diameter"&&(l.value=_),l.type==="hDistance"&&(l.value=_),l.type==="vDistance"&&(l.value=_)},Sje=(l,_)=>{const g=new Map(l.points.map(z=>[z.id,z])),S=new Map(l.lines.map(z=>[z.id,z])),D=new Map(l.circles.map(z=>[z.id,z])),F=[];return l.constraints.forEach(z=>{let ee=[0,0];if(z.type==="coincident"||z.type==="distance"||z.type==="hDistance"||z.type==="vDistance"){const pe=g.get(z.a),we=g.get(z.b);pe&&we&&(ee=w1(pe,we))}else if(z.type==="horizontal"||z.type==="vertical"||z.type==="length"){const pe=S.get(z.line);if(pe){const we=g.get(pe.a),De=g.get(pe.b);we&&De&&(ee=w1(we,De))}}else if(z.type==="parallel"||z.type==="perpendicular"||z.type==="equal"||z.type==="angle"){const pe=S.get(z.a),we=S.get(z.b);if(pe&&we){const De=g.get(pe.a),te=g.get(pe.b),nt=g.get(we.a),Te=g.get(we.b);if(De&&te&&nt&&Te){const Me=w1(De,te),bt=w1(nt,Te);ee=[(Me[0]+bt[0])/2,(Me[1]+bt[1])/2]}}}else if(z.type==="radius"||z.type==="diameter"){const pe=D.get(z.circle);if(pe){const we=g.get(pe.center);we&&(ee=[we.x+pe.radius,we.y])}}else if(z.type==="concentric"){const pe=D.get(z.a),we=D.get(z.b);if(pe&&we){const De=g.get(pe.center),te=g.get(we.center);De&&te&&(ee=w1(De,te))}}else if(z.type==="collinear"){const pe=g.get(z.point);pe&&(ee=[pe.x,pe.y])}else if(z.type==="fixed"){const pe=g.get(z.point);pe&&(ee=[pe.x,pe.y])}else if(z.type==="symmetric"){const pe=g.get(z.a),we=g.get(z.b);pe&&we&&(ee=w1(pe,we))}else if(z.type==="tangent"){if(z.line&&z.circle){const pe=S.get(z.line),we=D.get(z.circle);if(pe&&we){const De=g.get(pe.a),te=g.get(pe.b);De&&te&&(ee=w1(De,te))}}else if(z.a&&z.b){const pe=D.get(z.a),we=D.get(z.b);if(pe&&we){const De=g.get(pe.center),te=g.get(we.center);De&&te&&(ee=w1(De,te))}}}F.push({id:z.id,type:z.type,label:ckt(z.type),position:ee,value:ukt(z),isDimension:lkt(z.type),isConflicting:_.has(z.id)})}),F},fkt=l=>{const _=[];if(l.loops.forEach(g=>{if(g.type==="poly"){const S=g.points.map(D=>{const F=l.points.find(z=>z.id===D);if(!F)throw new Error(`Missing point ${D}`);return[F.x,F.y]});S.length>=3&&_.push(Ed(S))}else if(g.type==="circle"){const S=l.circles.find(z=>z.id===g.circle);if(!S)throw new Error(`Missing circle ${g.circle}`);const D=l.points.find(z=>z.id===S.center);if(!D)throw new Error(`Missing center ${S.center}`);const F=new So(wd().CrossSection.circle(S.radius,S.segments));_.push(F.translate(D.x,D.y))}}),_.length===0)throw new Error("Constrained sketch needs at least one closed loop");return Fh(..._)},pkt=l=>{const _=new Map(l.points.map(D=>[D.id,D])),g=l.lines.filter(D=>D.construction).map(D=>{const F=_.get(D.a),z=_.get(D.b);return!F||!z?null:{a:[F.x,F.y],b:[z.x,z.y]}}).filter(D=>D!==null),S=l.circles.filter(D=>D.construction).map(D=>{const F=_.get(D.center);return F?{center:[F.x,F.y],radius:D.radius}:null}).filter(D=>D!==null);return{lines:g,circles:S}},dkt=(l,_)=>{l.fixed=!0,l.x=_.x,l.y=_.y},IJe=(l,_)=>{const g=_.iterations??40,S=_.tolerance??xee,D=new Map(l.points.map(we=>[we.id,we])),F=new Map(l.lines.map(we=>[we.id,we])),z=new Map(l.circles.map(we=>[we.id,we]));l.constraints.forEach(we=>{if(we.type==="fixed"){const De=D.get(we.point);De&&dkt(De,we)}});const ee=(we,De,te)=>we.fixed?!1:(we.x+=De,we.y+=te,!0);let pe=0;for(let we=0;we<g&&(pe=0,l.constraints.forEach(De=>{let te=0;if(De.type==="coincident"){const nt=D.get(De.a),Te=D.get(De.b);if(!nt||!Te)return;const Me=Te.x-nt.x,bt=Te.y-nt.y;if(te=Math.sqrt(Me*Me+bt*bt),te<=S||nt.fixed&&Te.fixed)return;if(nt.fixed){Te.x=nt.x,Te.y=nt.y;return}if(Te.fixed){nt.x=Te.x,nt.y=Te.y;return}const vt=(nt.x+Te.x)/2,Bt=(nt.y+Te.y)/2;nt.x=vt,nt.y=Bt,Te.x=vt,Te.y=Bt}if(De.type==="horizontal"){const nt=F.get(De.line);if(!nt)return;const Te=D.get(nt.a),Me=D.get(nt.b);if(!Te||!Me||(te=Math.abs(Me.y-Te.y),te<=S)||Te.fixed&&Me.fixed)return;const bt=(Te.y+Me.y)/2;Te.fixed||(Te.y=bt),Me.fixed||(Me.y=bt)}if(De.type==="vertical"){const nt=F.get(De.line);if(!nt)return;const Te=D.get(nt.a),Me=D.get(nt.b);if(!Te||!Me||(te=Math.abs(Me.x-Te.x),te<=S)||Te.fixed&&Me.fixed)return;const bt=(Te.x+Me.x)/2;Te.fixed||(Te.x=bt),Me.fixed||(Me.x=bt)}if(De.type==="parallel"||De.type==="perpendicular"||De.type==="angle"){const nt=F.get(De.a),Te=F.get(De.b);if(!nt||!Te)return;const Me=D.get(nt.a),bt=D.get(nt.b),vt=D.get(Te.a),Bt=D.get(Te.b);if(!Me||!bt||!vt||!Bt)return;const fr=bje(Me,bt),hn=De.type==="parallel"?fr:De.type==="perpendicular"?fr+Math.PI/2:fr+PJe(De.value),vr=bje(vt,Bt),Xt=okt(vr-hn);if(te=Math.abs(Xt),te<=S||vt.fixed&&Bt.fixed)return;const Wt=rN(vt,Bt)||1,Hn=[Math.cos(hn),Math.sin(hn)];if(vt.fixed)Bt.x=vt.x+Hn[0]*Wt,Bt.y=vt.y+Hn[1]*Wt;else if(Bt.fixed)vt.x=Bt.x-Hn[0]*Wt,vt.y=Bt.y-Hn[1]*Wt;else{const zn=w1(vt,Bt);vt.x=zn[0]-Hn[0]*Wt/2,vt.y=zn[1]-Hn[1]*Wt/2,Bt.x=zn[0]+Hn[0]*Wt/2,Bt.y=zn[1]+Hn[1]*Wt/2}}if(De.type==="equal"){const nt=F.get(De.a),Te=F.get(De.b);if(!nt||!Te)return;const Me=D.get(nt.a),bt=D.get(nt.b),vt=D.get(Te.a),Bt=D.get(Te.b);if(!Me||!bt||!vt||!Bt)return;const fr=rN(Me,bt),hn=rN(vt,Bt)||1;if(te=Math.abs(hn-fr),te<=S||vt.fixed&&Bt.fixed)return;const vr=vje(vt,Bt);if(vt.fixed)Bt.x=vt.x+vr[0]*fr,Bt.y=vt.y+vr[1]*fr;else if(Bt.fixed)vt.x=Bt.x-vr[0]*fr,vt.y=Bt.y-vr[1]*fr;else{const Xt=w1(vt,Bt);vt.x=Xt[0]-vr[0]*fr/2,vt.y=Xt[1]-vr[1]*fr/2,Bt.x=Xt[0]+vr[0]*fr/2,Bt.y=Xt[1]+vr[1]*fr/2}}if(De.type==="distance"){const nt=D.get(De.a),Te=D.get(De.b);if(!nt||!Te)return;const Me=rN(nt,Te)||1;if(te=Math.abs(Me-De.value),te<=S)return;const bt=[(Te.x-nt.x)/Me,(Te.y-nt.y)/Me];if(nt.fixed&&Te.fixed)return;if(nt.fixed)Te.x=nt.x+bt[0]*De.value,Te.y=nt.y+bt[1]*De.value;else if(Te.fixed)nt.x=Te.x-bt[0]*De.value,nt.y=Te.y-bt[1]*De.value;else{const vt=w1(nt,Te);nt.x=vt[0]-bt[0]*De.value/2,nt.y=vt[1]-bt[1]*De.value/2,Te.x=vt[0]+bt[0]*De.value/2,Te.y=vt[1]+bt[1]*De.value/2}}if(De.type==="length"){const nt=F.get(De.line);if(!nt)return;const Te=D.get(nt.a),Me=D.get(nt.b);if(!Te||!Me)return;const bt=rN(Te,Me)||1;if(te=Math.abs(bt-De.value),te<=S)return;const vt=vje(Te,Me);if(Te.fixed&&Me.fixed)return;if(Te.fixed)Me.x=Te.x+vt[0]*De.value,Me.y=Te.y+vt[1]*De.value;else if(Me.fixed)Te.x=Me.x-vt[0]*De.value,Te.y=Me.y-vt[1]*De.value;else{const Bt=w1(Te,Me);Te.x=Bt[0]-vt[0]*De.value/2,Te.y=Bt[1]-vt[1]*De.value/2,Me.x=Bt[0]+vt[0]*De.value/2,Me.y=Bt[1]+vt[1]*De.value/2}}if(De.type==="radius"||De.type==="diameter"){const nt=z.get(De.circle);if(!nt)return;const Te=De.type==="radius"?De.value:De.value/2;if(te=Math.abs(nt.radius-Te),te<=S)return;nt.fixedRadius||(nt.radius=Te)}if(De.type==="hDistance"){const nt=D.get(De.a),Te=D.get(De.b);if(!nt||!Te||(te=Math.abs(Te.x-nt.x-De.value),te<=S)||nt.fixed&&Te.fixed)return;if(nt.fixed)Te.x=nt.x+De.value;else if(Te.fixed)nt.x=Te.x-De.value;else{const Me=(nt.x+Te.x)/2;nt.x=Me-De.value/2,Te.x=Me+De.value/2}}if(De.type==="vDistance"){const nt=D.get(De.a),Te=D.get(De.b);if(!nt||!Te||(te=Math.abs(Te.y-nt.y-De.value),te<=S)||nt.fixed&&Te.fixed)return;if(nt.fixed)Te.y=nt.y+De.value;else if(Te.fixed)nt.y=Te.y-De.value;else{const Me=(nt.y+Te.y)/2;nt.y=Me-De.value/2,Te.y=Me+De.value/2}}if(De.type==="concentric"){const nt=z.get(De.a),Te=z.get(De.b);if(!nt||!Te)return;const Me=D.get(nt.center),bt=D.get(Te.center);if(!Me||!bt)return;const vt=bt.x-Me.x,Bt=bt.y-Me.y;if(te=Math.sqrt(vt*vt+Bt*Bt),te<=S||Me.fixed&&bt.fixed)return;if(Me.fixed)bt.x=Me.x,bt.y=Me.y;else if(bt.fixed)Me.x=bt.x,Me.y=bt.y;else{const fr=w1(Me,bt);Me.x=fr[0],Me.y=fr[1],bt.x=fr[0],bt.y=fr[1]}}if(De.type==="collinear"){const nt=D.get(De.point),Te=F.get(De.line);if(!nt||!Te)return;const Me=D.get(Te.a),bt=D.get(Te.b);if(!Me||!bt)return;const vt=AJe(nt,Me,bt);if(te=Math.sqrt((nt.x-vt[0])**2+(nt.y-vt[1])**2),te<=S)return;if(!nt.fixed)nt.x=vt[0],nt.y=vt[1];else{const Bt=vt[0]-nt.x,fr=vt[1]-nt.y;Me.fixed||ee(Me,-Bt,-fr),bt.fixed||ee(bt,-Bt,-fr)}}if(De.type==="symmetric"){const nt=D.get(De.a),Te=D.get(De.b),Me=F.get(De.axis);if(!nt||!Te||!Me)return;const bt=D.get(Me.a),vt=D.get(Me.b);if(!bt||!vt)return;const Bt=xje(nt,bt,vt),fr=xje(Te,bt,vt);if(te=Math.sqrt((Te.x-Bt[0])**2+(Te.y-Bt[1])**2),te<=S||nt.fixed&&Te.fixed)return;nt.fixed?(Te.x=Bt[0],Te.y=Bt[1]):Te.fixed?(nt.x=fr[0],nt.y=fr[1]):(Te.x=Bt[0],Te.y=Bt[1])}if(De.type==="tangent"){if(De.line&&De.circle){const nt=F.get(De.line),Te=z.get(De.circle);if(!nt||!Te)return;const Me=D.get(nt.a),bt=D.get(nt.b),vt=D.get(Te.center);if(!Me||!bt||!vt)return;const Bt=bt.x-Me.x,fr=bt.y-Me.y,hn=Math.sqrt(Bt*Bt+fr*fr)||1,vr=-fr/hn,Xt=Bt/hn,Wt=(vt.x-Me.x)*vr+(vt.y-Me.y)*Xt;if(te=Math.abs(Math.abs(Wt)-Te.radius),te<=S)return;const Hn=Wt>0?Wt-Te.radius:Wt+Te.radius;!Me.fixed||!bt.fixed?(Me.fixed||(Me.x+=vr*-Hn,Me.y+=Xt*-Hn),bt.fixed||(bt.x+=vr*-Hn,bt.y+=Xt*-Hn)):vt.fixed||(vt.x+=vr*-Hn,vt.y+=Xt*-Hn)}else if(De.a&&De.b){const nt=z.get(De.a),Te=z.get(De.b);if(!nt||!Te)return;const Me=D.get(nt.center),bt=D.get(Te.center);if(!Me||!bt)return;const vt=nt.radius+Te.radius,Bt=rN(Me,bt)||1;if(te=Math.abs(Bt-vt),te<=S)return;const fr=[(bt.x-Me.x)/Bt,(bt.y-Me.y)/Bt];if(Me.fixed&&bt.fixed)return;if(Me.fixed)bt.x=Me.x+fr[0]*vt,bt.y=Me.y+fr[1]*vt;else if(bt.fixed)Me.x=bt.x-fr[0]*vt,Me.y=bt.y-fr[1]*vt;else{const hn=w1(Me,bt);Me.x=hn[0]-fr[0]*vt/2,Me.y=hn[1]-fr[1]*vt/2,bt.x=hn[0]+fr[0]*vt/2,bt.y=hn[1]+fr[1]*vt/2}}}pe=Math.max(pe,te)}),!(pe<=S));we+=1);return{maxError:pe}},mkt=(l,_,g)=>{if(_>g*5)return"over";const S=new Map;return l.points.forEach(F=>S.set(F.id,0)),l.constraints.forEach(F=>{if(F.type==="fixed"){const z=S.get(F.point)??0;S.set(F.point,z+2);return}if(F.type==="coincident"||F.type==="distance"||F.type==="hDistance"||F.type==="vDistance"){S.set(F.a,(S.get(F.a)??0)+1),S.set(F.b,(S.get(F.b)??0)+1);return}if(F.type==="collinear"){S.set(F.point,(S.get(F.point)??0)+1);return}if(F.type==="symmetric"){S.set(F.a,(S.get(F.a)??0)+1),S.set(F.b,(S.get(F.b)??0)+1);return}if(F.type==="horizontal"||F.type==="vertical"||F.type==="length"){const z=l.lines.find(ee=>ee.id===F.line);z&&(S.set(z.a,(S.get(z.a)??0)+1),S.set(z.b,(S.get(z.b)??0)+1));return}if(F.type==="parallel"||F.type==="perpendicular"||F.type==="equal"||F.type==="angle"){const z=l.lines.find(pe=>pe.id===F.a),ee=l.lines.find(pe=>pe.id===F.b);z&&(S.set(z.a,(S.get(z.a)??0)+1),S.set(z.b,(S.get(z.b)??0)+1)),ee&&(S.set(ee.a,(S.get(ee.a)??0)+1),S.set(ee.b,(S.get(ee.b)??0)+1));return}}),l.points.some(F=>!F.fixed&&(S.get(F.id)??0)<2)?"under":"fully"};class See extends So{constructor(_,g,S){super(_),this.constraintMeta=g,this.definition=S}withUpdatedConstraint(_,g){const S=NJe(this.definition),D=S.constraints.find(F=>F.id===_);return D?(_kt(D,g),FJe(S)):this}}const gkt=l=>l instanceof See;class hkt{constructor(){of(this,"points",[]);of(this,"lines",[]);of(this,"circles",[]);of(this,"constraints",[]);of(this,"loops",[]);of(this,"rejectedConstraints",[]);of(this,"cursor",null);of(this,"loopStart",null);of(this,"nextId",1)}point(_,g,S=!1){const D=`pt-${this.nextId++}`;return this.points.push({id:D,x:_,y:g,fixed:S}),D}pointAt(_){const g=this.points[_];if(!g)throw new Error(`Point index ${_} out of range`);return g.id}line(_,g,S=!1){const D=`ln-${this.nextId++}`;return this.lines.push({id:D,a:_,b:g,construction:S}),D}lineAt(_){const g=this.lines[_];if(!g)throw new Error(`Line index ${_} out of range`);return g.id}circle(_,g,S=!1,D=48){const F=`c-${this.nextId++}`;return this.circles.push({id:F,center:_,radius:g,construction:S,fixedRadius:!1,segments:D}),S||this.loops.push({type:"circle",circle:F}),F}circleAt(_){const g=this.circles[_];if(!g)throw new Error(`Circle index ${_} out of range`);return g.id}moveTo(_,g){const S=this.point(_,g);return this.cursor=S,this.loopStart=S,this.loops.push({type:"poly",points:[S]}),this}lineTo(_,g){if(!this.cursor)return this.moveTo(_,g);const S=this.point(_,g);this.line(this.cursor,S);const D=this.loops[this.loops.length-1];return D&&D.type==="poly"&&D.points.push(S),this.cursor=S,this}lineH(_){const g=this.getPoint(this.cursor);return g?this.lineTo(g.x+_,g.y):this}lineV(_){const g=this.getPoint(this.cursor);return g?this.lineTo(g.x,g.y+_):this}lineAngled(_,g){const S=this.getPoint(this.cursor);if(!S)return this;const D=PJe(g);return this.lineTo(S.x+Math.cos(D)*_,S.y+Math.sin(D)*_)}close(){return!this.cursor||!this.loopStart||this.cursor===this.loopStart?this:(this.line(this.cursor,this.loopStart),this.cursor=this.loopStart,this)}addLoopCircle(_,g,S=48){return this.circle(_,g,!1,S),this}constrain(_){const g=`cst-${this.nextId++}`,S={..._,id:g},D=this.buildDefinition(S),{maxError:F}=IJe(D,{iterations:30,tolerance:xee});if(F>xee*5)return this.rejectedConstraints.push(S),this;if(S.type==="fixed"){const z=this.points.find(ee=>ee.id===S.point);z&&(z.fixed=!0,z.x=S.x,z.y=S.y)}return this.constraints.push(S),this}solve(_={}){return FJe(this.buildDefinition(),_)}buildDefinition(_){return{points:this.points.map(g=>({...g})),lines:this.lines.map(g=>({...g})),circles:this.circles.map(g=>({...g})),loops:this.loops.map(g=>g.type==="poly"?{type:"poly",points:[...g.points]}:{type:"circle",circle:g.circle}),constraints:_?[...this.constraints,_]:[...this.constraints],rejectedConstraints:[...this.rejectedConstraints]}}getPoint(_){return _?this.points.find(g=>g.id===_)??null:null}importPoint(_,g=!1){return this.point(_.x,_.y,g)}importLine(_,g=!1){const S=this.importPoint(_.start,g),D=this.importPoint(_.end,g);return this.line(S,D)}importRectangle(_,g=!1){const[S,D,F,z]=_.vertices.map(ee=>this.importPoint(ee,g));return{bottom:this.line(S,D),right:this.line(D,F),top:this.line(F,z),left:this.line(z,S),points:[S,D,F,z]}}}function ykt(){return new hkt}const FJe=(l,_={})=>{const g=NJe(l),S=_.tolerance??xee,{maxError:D}=IJe(g,_),F=mkt(g,D,S),z=new Set(F==="over"?g.constraints.map(te=>te.id):[]),ee=Sje(g,z),pe=Sje({...g,constraints:g.rejectedConstraints},new Set(g.rejectedConstraints.map(te=>te.id))),we=fkt(g),De=pkt(g);return new See(we.cross,{status:F,maxError:D,constraints:ee,rejected:pe,construction:De},g)};class J_{constructor(_,g){this.x=_,this.y=g}distanceTo(_){const g=_.x-this.x,S=_.y-this.y;return Math.sqrt(g*g+S*S)}midpointTo(_){return new J_((this.x+_.x)/2,(this.y+_.y)/2)}translate(_,g){return new J_(this.x+_,this.y+g)}toTuple(){return[this.x,this.y]}}function vkt(l,_){return new J_(l,_)}class ob{constructor(_,g){this.start=_,this.end=g}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 _=this.length||1;return[(this.end.x-this.start.x)/_,(this.end.y-this.start.y)/_]}parallel(_){const[g,S]=this.direction,D=-S*_,F=g*_;return new ob(this.start.translate(D,F),this.end.translate(D,F))}intersect(_){const g=this.start.x,S=this.start.y,D=this.end.x,F=this.end.y,z=_.start.x,ee=_.start.y,pe=_.end.x,we=_.end.y,De=(g-D)*(ee-we)-(S-F)*(z-pe);if(Math.abs(De)<1e-12)return null;const te=((g-z)*(ee-we)-(S-ee)*(z-pe))/De;return new J_(g+te*(D-g),S+te*(F-S))}intersectSegment(_){const g=this.start.x,S=this.start.y,D=this.end.x,F=this.end.y,z=_.start.x,ee=_.start.y,pe=_.end.x,we=_.end.y,De=(g-D)*(ee-we)-(S-F)*(z-pe);if(Math.abs(De)<1e-12)return null;const te=((g-z)*(ee-we)-(S-ee)*(z-pe))/De,nt=-((g-D)*(S-ee)-(S-F)*(g-z))/De;return te<-1e-12||te>1+1e-12||nt<-1e-12||nt>1+1e-12?null:new J_(g+te*(D-g),S+te*(F-S))}static fromCoordinates(_,g,S,D){return new ob(new J_(_,g),new J_(S,D))}static fromPointAndAngle(_,g,S){const D=g*(Math.PI/180);return new ob(_,new J_(_.x+Math.cos(D)*S,_.y+Math.sin(D)*S))}static fromPointAndDirection(_,g,S){const D=Math.sqrt(g[0]*g[0]+g[1]*g[1])||1;return new ob(_,new J_(_.x+g[0]/D*S,_.y+g[1]/D*S))}}function bkt(l,_,g,S){return ob.fromCoordinates(l,_,g,S)}class zF{constructor(_,g){this.center=_,this.radius=g}get diameter(){return this.radius*2}get circumference(){return 2*Math.PI*this.radius}get area(){return Math.PI*this.radius*this.radius}pointAtAngle(_){const g=_*Math.PI/180;return new J_(this.center.x+Math.cos(g)*this.radius,this.center.y+Math.sin(g)*this.radius)}translate(_,g){return new zF(this.center.translate(_,g),this.radius)}toSketch(_){const S=wd().CrossSection.circle(this.radius,_??0).translate([this.center.x,this.center.y]);return new So(S)}extrude(_,g){const S=this.toSketch(g),D=FS(S,_),F=EJe(this,_);return new lo(D.shape,F,_,!0)}static fromCenterAndRadius(_,g){return new zF(_,g)}static fromDiameter(_,g){return new zF(_,g/2)}}function xkt(l,_,g){return new zF(new J_(l,_),g)}class zk{constructor(_){of(this,"vertices");this.vertices=_}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(_){const[g,S,D,F]=this.vertices;switch(_){case"bottom":return new ob(g,S);case"right":return new ob(S,D);case"top":return new ob(D,F);case"left":return new ob(F,g)}}sideAt(_){const g=["bottom","right","top","left"];return this.side(g[_%4])}vertex(_){const[g,S,D,F]=this.vertices;switch(_){case"bottom-left":return g;case"bottom-right":return S;case"top-right":return D;case"top-left":return F}}diagonals(){const[_,g,S,D]=this.vertices;return[new ob(_,S),new ob(g,D)]}toSketch(){return Ed(this.vertices.map(_=>_.toTuple()))}translate(_,g){return new zk(this.vertices.map(S=>S.translate(_,g)))}static fromDimensions(_,g,S,D){return new zk([new J_(_,g),new J_(_+S,g),new J_(_+S,g+D),new J_(_,g+D)])}static fromCenterAndDimensions(_,g,S){const D=g/2,F=S/2;return new zk([new J_(_.x-D,_.y-F),new J_(_.x+D,_.y-F),new J_(_.x+D,_.y+F),new J_(_.x-D,_.y+F)])}static from2Corners(_,g){const S=Math.min(_.x,g.x),D=Math.max(_.x,g.x),F=Math.min(_.y,g.y),z=Math.max(_.y,g.y);return new zk([new J_(S,F),new J_(D,F),new J_(D,z),new J_(S,z)])}static from3Points(_,g,S){const D=g.x-_.x,F=g.y-_.y,z=Math.sqrt(D*D+F*F)||1,ee=D/z,we=-(F/z),De=ee,te=(S.x-_.x)*we+(S.y-_.y)*De;return new zk([_,g,new J_(g.x+we*te,g.y+De*te),new J_(_.x+we*te,_.y+De*te)])}extrude(_,g=!0){const S=this.toSketch(),D=Math.abs(_),F=FS(S,D),z=g?F.shape:F.shape.translate(0,0,-D),ee=wJe(this,D,g);return new lo(z,ee,D,g)}}function Skt(l,_,g,S){return zk.fromDimensions(l,_,g,S)}function Tkt(l){return l}function kkt(l){return l*(180/Math.PI)}function kS(l,_){return typeof _=="string"?_:l.importLine(_)}function DJ(l,_){return typeof _=="string"?_:l.importPoint(_)}const Ckt={makeParallel(l,_,g){return l.constrain({type:"parallel",a:kS(l,_),b:kS(l,g)})},enforceAngle(l,_,g,S){return l.constrain({type:"angle",a:kS(l,_),b:kS(l,g),value:S})},horizontal(l,_){return l.constrain({type:"horizontal",line:kS(l,_)})},vertical(l,_){return l.constrain({type:"vertical",line:kS(l,_)})},equalLength(l,_,g){return l.constrain({type:"equal",a:kS(l,_),b:kS(l,g)})},distance(l,_,g,S){return l.constrain({type:"distance",a:DJ(l,_),b:DJ(l,g),value:S})},fix(l,_,g,S){return l.constrain({type:"fixed",point:DJ(l,_),x:g,y:S})},coincident(l,_,g){return l.constrain({type:"coincident",a:DJ(l,_),b:DJ(l,g)})},perpendicular(l,_,g){return l.constrain({type:"perpendicular",a:kS(l,_),b:kS(l,g)})},length(l,_,g){return l.constrain({type:"length",line:kS(l,_),value:g})}},fbe=l=>l instanceof lo?l.toShape():l;function OJe(l,_,g){return jee(l,jBe(gP(l),rSt(_,g)))}function wkt(l,_,g,S,D=0){const F=fbe(l),z=[];for(let ee=0;ee<_;ee++){const pe=ee===0?F.clone():F.translate(g*ee,S*ee,D*ee);z.push(OJe(pe,"linear",ee))}return I1(...z)}function Ekt(l,_,g=0,S=0){const D=fbe(l),F=360/_,z=[];for(let ee=0;ee<_;ee++){const pe=ee===0?D.clone():D.translate(-g,-S,0).rotate(0,0,F*ee).translate(g,S,0);z.push(OJe(pe,"circular",ee))}return I1(...z)}function Dkt(l,_){const g=fbe(l);return I1(g,g.mirror(_))}function MJe(l){return l instanceof lo?l.toShape():l}function LJe(l,_){const g=l??[-1,-1],S=Math.sign(g[0]),D=Math.sign(g[1]);if(S!==1&&S!==-1||D!==1&&D!==-1)throw new Error(`${_} requires quadrant signs of either 1 or -1.`);return[S,D]}function Pkt(l,_){return _?bJe(l).some(g=>cb(g,_)):!0}function RJe(l,_,g){var S;if(!Pkt(l,(S=_.query)==null?void 0:S.owner))throw new Error(`${g} requires an edge query owned by the target shape or one of its preserved query ancestors.`)}function jJe(l,_,g,S){if(!l)return null;const D=Nee(_);return KJ(rbe(l,Kxt(_,D,g,S.filter(F=>F!=null))),D)}function BJe(l,_,g){if(!_)throw new Error(`Could not record compiler intent for ${g} on this target shape.`);const S=vJe(l),D=k_(_,l.colorHex,{backend:S.backend,representation:S.representation,fidelity:S.fidelity,topology:"none",sources:[g,...S.sources]});return yee(D,lbe(l)),Lee(D,yJe(l),{merge:!1}),Ree(D,{backend:S.backend,representation:S.representation,fidelity:S.fidelity,topology:"none",sources:[g,...S.sources]}),D}function Akt(l,_,g,S=[-1,-1],D=16){if(!Number.isFinite(g)||!(g>0))throw new Error("filletEdge() requires a positive finite radius.");if(!Number.isFinite(D)||D<2)throw new Error("filletEdge() requires at least 2 segments.");const F=MJe(l);RJe(F,_,"filletEdge()");const z=gP(F);if(!z)throw new Error("filletEdge() currently requires a compile-covered target shape.");const ee=LJe(S,"filletEdge()"),pe=_N(z,_.query);if(!pe.ok)throw new Error(`filletEdge(): ${pe.issue.reason}`);const we=lJe(z,_.query);if(pe.selection.quadrant[0]!==ee[0]||pe.selection.quadrant[1]!==ee[1])throw new Error(`filletEdge() currently supports ${pe.selection.edgeName} only with quadrant [${pe.selection.quadrant[0]}, ${pe.selection.quadrant[1]}].`);const De=jJe($2t(z,pe.query,g,ee,Math.round(D)),"fillet",pe.query,we);return BJe(F,De,"fillet")}function Nkt(l,_,g,S=[-1,-1]){if(!Number.isFinite(g)||!(g>0))throw new Error("chamferEdge() requires a positive finite size.");const D=MJe(l);RJe(D,_,"chamferEdge()");const F=gP(D);if(!F)throw new Error("chamferEdge() currently requires a compile-covered target shape.");const z=LJe(S,"chamferEdge()"),ee=_N(F,_.query);if(!ee.ok)throw new Error(`chamferEdge(): ${ee.issue.reason}`);const pe=lJe(F,_.query);if(ee.selection.quadrant[0]!==z[0]||ee.selection.quadrant[1]!==z[1])throw new Error(`chamferEdge() currently supports ${ee.selection.edgeName} only with quadrant [${ee.selection.quadrant[0]}, ${ee.selection.quadrant[1]}].`);const we=jJe(H2t(F,ee.query,g,z),"chamfer",ee.query,pe);return BJe(D,we,"chamfer")}const uP=1e-8;function Ikt(l){return Array.isArray(l)?[l[0],l[1]]:[l.x,l.y]}function wve(l,_){const g=_[0]-l[0],S=_[1]-l[1];return Math.hypot(g,S)}function tve(l,_){const g=Math.hypot(l,_);if(g<=uP)throw new Error("filletCorners requires non-degenerate edges");return[l/g,_/g]}function Fkt(l,_,g){return Math.max(_,Math.min(g,l))}function Okt(l){let _=0;for(let g=0;g<l.length;g+=1){const[S,D]=l[g],[F,z]=l[(g+1)%l.length];_+=S*z-F*D}return _/2}function Mkt(l){return Math.max(3,Math.ceil(Math.abs(l)/(Math.PI/15)))}function Tje(l,_,g=1e-6){return Math.abs(l[0]-_[0])<=g&&Math.abs(l[1]-_[1])<=g}function Lkt(l,_,g){const S=l.length;if(!Number.isInteger(_.index)||_.index<0||_.index>=S)throw new Error(`filletCorners corner index ${_.index} is out of range for ${S} points`);if(!(_.radius>0))throw new Error(`filletCorners corner ${_.index} must have a positive radius`);const D=l[(_.index-1+S)%S],F=l[_.index],z=l[(_.index+1)%S],ee=wve(D,F),pe=wve(F,z),[we,De]=tve(F[0]-D[0],F[1]-D[1]),[te,nt]=tve(z[0]-F[0],z[1]-F[1]);if((we*nt-De*te)*g<=uP)throw new Error(`filletCorners corner ${_.index} is concave or collinear; only convex corners are supported`);const Me=[-we,-De],bt=[te,nt],vt=Math.acos(Fkt(Me[0]*bt[0]+Me[1]*bt[1],-1,1));if(vt<=uP||vt>=Math.PI-uP)throw new Error(`filletCorners corner ${_.index} has an unsupported angle`);const Bt=_.radius/Math.tan(vt/2);if(Bt>=ee-uP||Bt>=pe-uP){const Jn=Math.min(ee,pe)*Math.tan(vt/2);throw new Error(`filletCorners radius ${_.radius} is too large for corner ${_.index}; max is ${Jn.toFixed(3)}`)}const fr=[F[0]-we*Bt,F[1]-De*Bt],hn=[F[0]+te*Bt,F[1]+nt*Bt],[vr,Xt]=tve(Me[0]+bt[0],Me[1]+bt[1]),Wt=_.radius/Math.sin(vt/2),Hn=[F[0]+vr*Wt,F[1]+Xt*Wt],zn=_.segments==null?Mkt(vt):Math.round(_.segments),Fs=Math.max(2,zn);return{radius:_.radius,tangentDistance:Bt,segments:Fs,start:fr,end:hn,center:Hn,startAngle:Math.atan2(fr[1]-Hn[1],fr[0]-Hn[0]),sweep:g*vt}}function Rkt(l,_){var pe,we;if(l.length<3)throw new Error("filletCorners requires at least 3 points");if(_.length===0)return Ed(l);const g=l.map(Ikt),S=Okt(g);if(Math.abs(S)<=uP)throw new Error("filletCorners requires a non-degenerate polygon");const D=Math.sign(S),F=new Map;for(const De of _){if(F.has(De.index))throw new Error(`filletCorners corner ${De.index} is specified more than once`);F.set(De.index,Lkt(g,De,D))}for(let De=0;De<g.length;De+=1){const te=(De+1)%g.length,nt=wve(g[De],g[te]),Te=((pe=F.get(De))==null?void 0:pe.tangentDistance)??0,Me=((we=F.get(te))==null?void 0:we.tangentDistance)??0;if(Te+Me>=nt-uP)throw new Error(`filletCorners adjacent fillets overlap on edge ${De} -> ${te}; reduce one of the radii`)}const z=[],ee=De=>{(z.length===0||!Tje(z[z.length-1],De))&&z.push(De)};for(let De=0;De<g.length;De+=1){const te=F.get(De);if(te==null){ee(g[De]);continue}ee(te.start);for(let nt=1;nt<te.segments;nt+=1){const Te=te.startAngle+te.sweep*nt/te.segments;ee([te.center[0]+Math.cos(Te)*te.radius,te.center[1]+Math.sin(Te)*te.radius])}ee(te.end)}return z.length>=2&&Tje(z[0],z[z.length-1])&&z.pop(),Ed(z)}function Tee(l,_){return[l[0]-_[0],l[1]-_[1],l[2]-_[2]]}function kje(l,_){return[l[0]+_[0],l[1]+_[1],l[2]+_[2]]}function Eve(l,_){return[l[0]*_,l[1]*_,l[2]*_]}function yE(l,_){return l[0]*_[0]+l[1]*_[1]+l[2]*_[2]}function jkt(l,_){return[l[1]*_[2]-l[2]*_[1],l[2]*_[0]-l[0]*_[2],l[0]*_[1]-l[1]*_[0]]}function pbe(l){return Math.sqrt(yE(l,l))}function Dve(l){const _=pbe(l)||1;return[l[0]/_,l[1]/_,l[2]/_]}function Cje(l,_){return[(l[0]+_[0])/2,(l[1]+_[1])/2,(l[2]+_[2])/2]}function wje(l){if(l instanceof zk){const[_,g,S,D]=l.vertices;return{corners:[[_.x,_.y,0],[g.x,g.y,0],[S.x,S.y,0],[D.x,D.y,0]]}}return l}function Eje(l,_){const[g,S,D,F]=l.corners;return[{name:`${_}-bottom`,start:g,end:S},{name:`${_}-right`,start:S,end:D},{name:`${_}-top`,start:D,end:F},{name:`${_}-left`,start:F,end:g}]}function kee(l){return Dve(Tee(l.end,l.start))}function Bkt(l,_,g){const S=kee(l),D=kee(_);if(!(Math.abs(yE(S,D))>.999))throw new Error("Inner edges are not parallel");const z=yE(l.start,S),ee=yE(l.end,S),pe=yE(_.start,S),we=yE(_.end,S),De=Math.min(z,ee),te=Math.max(z,ee),nt=Math.min(pe,we),Te=Math.max(pe,we),Me=Math.max(De,nt),vt=Math.min(te,Te)-Me;if(vt<1e-6)throw new Error("Inner edges do not overlap along their direction");const Bt=kje(l.start,Eve(S,Me-z)),fr=kje(_.start,Eve(S,Me-pe)),hn=Tee(fr,Bt),vr=yE(hn,S),Xt=[hn[0]-S[0]*vr,hn[1]-S[1]*vr,hn[2]-S[2]*vr],Wt=pbe(Xt);if(Wt<1e-6)throw new Error("Edges are coincident — no arc to build");const Hn=Dve(Xt),zn=Dve(jkt(S,Hn)),Fs=Wt/2,Jn=[Wt/2,0],oc=[];for(let Es=0;Es<=g;Es++){const Ho=Math.PI*Es/g,qi=Jn[0]-Fs*Math.cos(Ho),Yc=Fs*Math.sin(Ho);oc.push([qi,Yc])}const ro=Math.max(.5,Wt*.02),Br=[];for(let Es=g;Es>=0;Es--){const Ho=Math.PI*Es/g,qi=Fs-ro,Yc=Jn[0]-qi*Math.cos(Ho),Hp=qi*Math.sin(Ho);Br.push([Yc,Hp])}const pc=Ed([...oc,...Br]),eo=FS(pc,vt).toShape(),Gt=Bt,fa=[Hn[0],Hn[1],Hn[2],0,zn[0],zn[1],zn[2],0,S[0],S[1],S[2],0,Gt[0],Gt[1],Gt[2],1];return eo.transform(fa)}function Jkt(l,_,g=12){const S=wje(l),D=wje(_),F=Eje(S,"a"),z=Eje(D,"b");let ee=null;for(const pe of F){const we=kee(pe);for(const De of z){const te=kee(De);if(Math.abs(yE(we,te))<.999)continue;const nt=Cje(pe.start,pe.end),Te=Cje(De.start,De.end),Me=Tee(Te,nt),bt=yE(Me,we),vt=Tee(Me,Eve(we,bt)),Bt=pbe(vt);Bt<1e-6||(!ee||Bt<ee.dist)&&(ee={edgeA:pe,edgeB:De,dist:Bt})}}if(!ee)throw new Error("No parallel inner edges found between the two rectangles");return Bkt(ee.edgeA,ee.edgeB,g)}let oN=[],Pve=0;function zkt(){oN=[],Pve=0}function Ave(){return oN}function qkt(l){const _=Math.max(0,Math.min(l,oN.length)),g=oN.slice(_);return oN=oN.slice(0,_),g}function Dje(l){return l instanceof J_?[l.x,l.y,0]:l.length===2?[l[0],l[1],0]:[l[0],l[1],l[2]]}function JJe(l,_,g){Pve++;const S=(()=>{if(typeof(g==null?void 0:g.component)=="string"){const D=g.component.trim();return D?[D]:void 0}if(Array.isArray(g==null?void 0:g.component)){const D=Array.from(new Set(g.component.map(F=>typeof F=="string"?F.trim():"").filter(Boolean)));return D.length>0?D:void 0}})();oN.push({id:`dim-${Pve}`,from:Dje(l),to:Dje(_),offset:(g==null?void 0:g.offset)??10,autoOffset:(g==null?void 0:g.offset)===void 0,label:g==null?void 0:g.label,color:g==null?void 0:g.color,components:S,currentComponent:!!(g!=null&&g.currentComponent)})}function Wkt(l,_){JJe([l.start.x,l.start.y],[l.end.x,l.end.y],_)}function OJ(l,_,g){return Math.max(_,Math.min(g,l))}function Vkt(l,_){return[l[0]+_[0],l[1]+_[1],l[2]+_[2]]}function Nve(l,_){return[l[0]-_[0],l[1]-_[1],l[2]-_[2]]}function Pje(l,_){return[l[0]*_,l[1]*_,l[2]*_]}function Ukt(l,_){return l[0]*_[0]+l[1]*_[1]+l[2]*_[2]}function dbe(l){return Math.sqrt(Ukt(l,l))}function $kt(l){const _=dbe(l);return _<1e-9?[0,0,1]:[l[0]/_,l[1]/_,l[2]/_]}function Aje(l,_,g,S,D,F){const z=D*D,ee=z*D,pe=(1-F)*.5,we=(g[0]-l[0])*pe,De=(g[1]-l[1])*pe,te=(S[0]-_[0])*pe,nt=(S[1]-_[1])*pe,Te=2*ee-3*z+1,Me=ee-2*z+D,bt=-2*ee+3*z,vt=ee-z;return[Te*_[0]+Me*we+bt*g[0]+vt*te,Te*_[1]+Me*De+bt*g[1]+vt*nt]}function Nje(l,_,g,S,D,F){const z=D*D,ee=z*D,pe=(1-F)*.5,we=[(g[0]-l[0])*pe,(g[1]-l[1])*pe,(g[2]-l[2])*pe],De=[(S[0]-_[0])*pe,(S[1]-_[1])*pe,(S[2]-_[2])*pe],te=2*ee-3*z+1,nt=ee-2*z+D,Te=-2*ee+3*z,Me=ee-z;return[te*_[0]+nt*we[0]+Te*g[0]+Me*De[0],te*_[1]+nt*we[1]+Te*g[1]+Me*De[1],te*_[2]+nt*we[2]+Te*g[2]+Me*De[2]]}function Hkt(l,_,g,S){if(l.length<2)throw new Error("spline2d requires at least 2 points");const D=l.length,F=[],z=_?D:D-1;for(let ee=0;ee<z;ee++){const pe=l[(ee-1+D)%D],we=l[ee%D],De=l[(ee+1)%D],te=l[(ee+2)%D];if(!_){const nt=ee===0?we:pe,Te=ee===D-2?De:te;for(let Me=0;Me<g;Me++){const bt=Me/g;F.push(Aje(nt,we,De,Te,bt,S))}continue}for(let nt=0;nt<g;nt++){const Te=nt/g;F.push(Aje(pe,we,De,te,Te,S))}}return _||F.push(l[D-1]),F}function Gkt(l,_,g,S){if(l.length<2)throw new Error("spline3d requires at least 2 points");const D=l.length,F=[],z=_?D:D-1;for(let ee=0;ee<z;ee++){const pe=l[(ee-1+D)%D],we=l[ee%D],De=l[(ee+1)%D],te=l[(ee+2)%D];if(!_){const nt=ee===0?we:pe,Te=ee===D-2?De:te;for(let Me=0;Me<g;Me++){const bt=Me/g;F.push(Nje(nt,we,De,Te,bt,S))}continue}for(let nt=0;nt<g;nt++){const Te=nt/g;F.push(Nje(pe,we,De,te,Te,S))}}return _||F.push(l[D-1]),F}class zJe{constructor(_,g={}){of(this,"points");of(this,"closed");of(this,"tension");if(_.length<2)throw new Error("Curve3D needs at least 2 points");this.points=_.map(S=>[S[0],S[1],S[2]]),this.closed=g.closed??!1,this.tension=OJ(g.tension??.5,0,1)}sampleBySegment(_=16){const g=Math.max(3,Math.floor(_));return Gkt(this.points,this.closed,g,this.tension)}sample(_=64){const g=Math.max(2,Math.floor(_)),S=Math.max(3,Math.ceil(g/Math.max(1,this.points.length-(this.closed?0:1)))),D=this.sampleBySegment(S);if(D.length<=g)return D;const F=[];for(let z=0;z<g;z++){const ee=Math.round(z/(g-1)*(D.length-1));F.push(D[ee])}return F}pointAt(_){const g=this.sample(200),D=OJ(_,0,1)*(g.length-1),F=Math.floor(D),z=Math.min(g.length-1,F+1),ee=D-F;return Vkt(Pje(g[F],1-ee),Pje(g[z],ee))}tangentAt(_){const S=this.pointAt(OJ(_-.001,0,1)),D=this.pointAt(OJ(_+.001,0,1));return $kt(Nve(D,S))}length(_=200){const g=this.sample(_);let S=0;for(let D=1;D<g.length;D++)S+=dbe(Nve(g[D],g[D-1]));return S}}function Xkt(l,_={}){const g=_.closed??!0,S=OJ(_.tension??.5,0,1),D=t2t(_.samplesPerSegment??16),F=Hkt(l,g,D,S);if(g)return Ed(F);if(_.strokeWidth==null||_.strokeWidth<=0)throw new Error("spline2d: open spline requires options.strokeWidth > 0 to create a solid Sketch");return _be(F,_.strokeWidth,_.join??"Round")}function Qkt(l,_={}){return new zJe(l,_)}function Ykt(l,_,g={}){var hn;if(l.length<2)throw new Error("loft requires at least two profiles");if(l.length!==_.length)throw new Error("loft requires heights.length === profiles.length");const S=l.map((vr,Xt)=>({profile:vr,z:_[Xt]})).sort((vr,Xt)=>vr.z-Xt.z);for(let vr=1;vr<S.length;vr++)if(Math.abs(S[vr].z-S[vr-1].z)<1e-8)throw new Error("loft requires strictly increasing, unique heights");const D=S.map(vr=>vr.z);let F=1/0,z=1/0,ee=-1/0,pe=-1/0;for(const vr of S){const Xt=vr.profile.bounds();F=Math.min(F,Xt.min[0]),z=Math.min(z,Xt.min[1]),ee=Math.max(ee,Xt.max[0]),pe=Math.max(pe,Xt.max[1])}const we=D[0],De=D[D.length-1],te=Math.max(ee-F,pe-z,De-we,1),nt=g.edgeLength??Math.max(.35,te/90),Te=gBe(nt),Me=g.boundsPadding??Math.max(Te*3,te*.06,1.5),bt=hBe(Me),vt=G2t(S.map(vr=>tm(vr.profile)),D,{edgeLength:Te,boundsPadding:bt}),Bt=kE(vt,"loft");if(Bt)return k_(Bt,(hn=S[0])==null?void 0:hn.profile.colorHex,{fidelity:"sampled",sources:["loft","level-set"]});const fr=GBe(S.map(vr=>vr.profile.toPolygons()),D,{edgeLength:Te,boundsPadding:bt});return Ree(ube(fr.sdf,fr.bounds,fr.edgeLength),{fidelity:"sampled",sources:["loft","level-set"]})}function Zkt(l,_,g={}){const S=Math.max(4,g.samples??48),D=r2t(S),F=Array.isArray(_)?_:_.sample(D);if(F.length<2)throw new Error("sweep requires a path with at least two points");const z=g.up??[0,0,1],ee=l.bounds(),pe=Math.max(Math.abs(ee.min[0]),Math.abs(ee.max[0]),Math.abs(ee.min[1]),Math.abs(ee.max[1]));let we=1/0,De=1/0,te=1/0,nt=-1/0,Te=-1/0,Me=-1/0;for(const zn of F)we=Math.min(we,zn[0]),De=Math.min(De,zn[1]),te=Math.min(te,zn[2]),nt=Math.max(nt,zn[0]),Te=Math.max(Te,zn[1]),Me=Math.max(Me,zn[2]);let bt=0;for(let zn=1;zn<F.length;zn++)bt+=dbe(Nve(F[zn],F[zn-1]));const vt=Math.max(nt-we,Te-De,Me-te,bt,1),Bt=g.edgeLength??Math.max(.3,vt/110),fr=gBe(Bt),hn=g.boundsPadding??Math.max(pe+fr*2,vt*.04,2),vr=hBe(hn),Xt=X2t(tm(l),{kind:"polyline",points:F.map(([zn,Fs,Jn])=>[zn,Fs,Jn])},{edgeLength:fr,boundsPadding:vr,up:z}),Wt=kE(Xt,"sweep");if(Wt)return k_(Wt,l.colorHex,{fidelity:"sampled",sources:["sweep","level-set"]});const Hn=XBe(l.toPolygons(),F.map(([zn,Fs,Jn])=>[zn,Fs,Jn]),{edgeLength:fr,boundsPadding:vr,up:z});return Ree(ube(Hn.sdf,Hn.bounds,Hn.edgeLength),{fidelity:"sampled",sources:["sweep","level-set"]})}const qJe=1e-7,gu=1e-9,Kkt={fill:"black",stroke:"none",strokeWidth:1,fillRule:"nonzero",strokeJoin:"miter",display:"inline",visibility:"visible",opacity:1,fillOpacity:1,strokeOpacity:1},eCt={px:1,pt:96/72,pc:16,in:96,cm:96/2.54,mm:96/25.4,q:96/101.6};function pN(l,_,g){return Math.max(_,Math.min(g,l))}function iP(l){return l*l}function cN(l,_){return Math.hypot(l[0]-_[0],l[1]-_[1])}function mbe(l){let _=0;for(let g=0;g<l.length;g+=1){const[S,D]=l[g],[F,z]=l[(g+1)%l.length];_+=S*z-F*D}return _*.5}function tCt(l){if(l.length===0)return[0,0];let _=0,g=0;for(const[S,D]of l)_+=S,g+=D;return[_/l.length,g/l.length]}function WJe(l){let _=0,g=0,S=0;for(let F=0;F<l.length;F+=1){const[z,ee]=l[F],[pe,we]=l[(F+1)%l.length],De=z*we-pe*ee;S+=De,_+=(z+pe)*De,g+=(ee+we)*De}if(Math.abs(S)<gu)return tCt(l);const D=1/(3*S);return[_*D,g*D]}function VJe(l,_){const[g,S]=l;let D=!1;for(let F=0,z=_.length-1;F<_.length;z=F++){const[ee,pe]=_[F],[we,De]=_[z];pe>S!=De>S&&g<(we-ee)*(S-pe)/(De-pe||1e-20)+ee&&(D=!D)}return D}function MF(){return[1,0,0,1,0,0]}function lN(l,_){const[g,S,D,F,z,ee]=l,[pe,we,De,te,nt,Te]=_;return[g*pe+D*we,S*pe+F*we,g*De+D*te,S*De+F*te,g*nt+D*Te+z,S*nt+F*Te+ee]}function rCt(l,_){const[g,S,D,F,z,ee]=l,[pe,we]=_;return[g*pe+D*we+z,S*pe+F*we+ee]}function KK(l,_){return[1,0,0,1,l,_]}function Ive(l,_){return[l,0,0,_,0,0]}function Ije(l){const _=l*Math.PI/180,g=Math.cos(_),S=Math.sin(_);return[g,S,-S,g,0,0]}function nCt(l){const _=l*Math.PI/180;return[1,0,Math.tan(_),1,0,0]}function iCt(l){const _=l*Math.PI/180;return[1,Math.tan(_),0,1,0,0]}function Tm(l,_=NaN){if(typeof l!="string")return _;const g=l.trim();if(!g)return _;const S=g.match(/^([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)([a-z%]*)$/i);if(!S)return _;const D=Number(S[1]);if(!Number.isFinite(D))return _;const F=S[2].toLowerCase();return F===""||F==="px"?D:F==="%"?_:D*(eCt[F]??1)}function gbe(l){if(!l)return[];const _=[],g=/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g;let S;for(;(S=g.exec(l))!==null;){const D=Number(S[0]);Number.isFinite(D)&&_.push(D)}return _}function sCt(l){return l.replace(/&(#x?[0-9a-fA-F]+|amp|lt|gt|quot|apos);/g,(_,g)=>{switch(g){case"amp":return"&";case"lt":return"<";case"gt":return">";case"quot":return'"';case"apos":return"'";default:if(g.startsWith("#x")||g.startsWith("#X")){const S=Number.parseInt(g.slice(2),16);return Number.isFinite(S)?String.fromCodePoint(S):""}if(g.startsWith("#")){const S=Number.parseInt(g.slice(1),10);return Number.isFinite(S)?String.fromCodePoint(S):""}return""}})}function aCt(l){const _={},g=/([:@A-Za-z_][\w:.-]*)\s*=\s*("([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/g;let S;for(;(S=g.exec(l))!==null;){const D=S[1],F=S[3]??S[4]??S[5]??"";_[D]=sCt(F)}return _}function oCt(l){const _={};return l&&l.split(";").forEach(g=>{const S=g.indexOf(":");if(S<0)return;const D=g.slice(0,S).trim().toLowerCase(),F=g.slice(S+1).trim();D&&(_[D]=F)}),_}function cCt(l,_){return l?l.trim().toLowerCase()==="evenodd"?"evenodd":"nonzero":_}function lCt(l,_){if(!l)return _;const g=l.trim().toLowerCase();return g==="round"||g==="bevel"?g:"miter"}function rve(l,_){const g=Tm(l,NaN);return Number.isFinite(g)?pN(g,0,1):_}function RK(l,_){if(typeof l!="string")return _;const g=l.trim().toLowerCase();return g||_}function uCt(l,_){const g={...l},S=oCt(_.style),D=z=>S[z]??_[z];g.fill=RK(D("fill"),g.fill),g.stroke=RK(D("stroke"),g.stroke);const F=Tm(D("stroke-width"),NaN);return Number.isFinite(F)&&F>=0&&(g.strokeWidth=F),g.fillRule=cCt(D("fill-rule"),g.fillRule),g.strokeJoin=lCt(D("stroke-linejoin"),g.strokeJoin),g.display=RK(D("display"),g.display),g.visibility=RK(D("visibility"),g.visibility),g.opacity=rve(D("opacity"),g.opacity),g.fillOpacity=rve(D("fill-opacity"),g.fillOpacity),g.strokeOpacity=rve(D("stroke-opacity"),g.strokeOpacity),g}function _Ct(l){if(!l)return MF();const _=l.trim();if(!_)return MF();const g=/([a-zA-Z]+)\s*\(([^)]*)\)/g;let S,D=MF();for(;(S=g.exec(_))!==null;){const F=S[1].toLowerCase(),z=gbe(S[2]);let ee=MF();F==="matrix"&&z.length>=6?ee=[z[0],z[1],z[2],z[3],z[4],z[5]]:F==="translate"&&z.length>=1?ee=KK(z[0],z.length>=2?z[1]:0):F==="scale"&&z.length>=1?ee=Ive(z[0],z.length>=2?z[1]:z[0]):F==="rotate"&&z.length>=1?z.length>=3?ee=lN(KK(z[1],z[2]),lN(Ije(z[0]),KK(-z[1],-z[2]))):ee=Ije(z[0]):F==="skewx"&&z.length>=1?ee=nCt(z[0]):F==="skewy"&&z.length>=1&&(ee=iCt(z[0])),D=lN(ee,D)}return D}function Ih(l,_){if(l.length===0){l.push([_[0],_[1]]);return}const g=l[l.length-1];cN(g,_)>qJe&&l.push([_[0],_[1]])}function bN(l){return l.length<=1?l:cN(l[0],l[l.length-1])<=qJe?l.slice(0,-1):l}function Fje(l,_,g,S,D){const F=cN(l,_)+cN(_,g)+cN(g,S),z=pN(Math.ceil(F/Math.max(D,1e-4)),4,512),ee=[];for(let pe=1;pe<=z;pe+=1){const we=pe/z,De=1-we,te=De*De*De*l[0]+3*De*De*we*_[0]+3*De*we*we*g[0]+we*we*we*S[0],nt=De*De*De*l[1]+3*De*De*we*_[1]+3*De*we*we*g[1]+we*we*we*S[1];ee.push([te,nt])}return ee}function Oje(l,_,g,S){const D=cN(l,_)+cN(_,g),F=pN(Math.ceil(D/Math.max(S,1e-4)),4,512),z=[];for(let ee=1;ee<=F;ee+=1){const pe=ee/F,we=1-pe,De=we*we*l[0]+2*we*pe*_[0]+pe*pe*g[0],te=we*we*l[1]+2*we*pe*_[1]+pe*pe*g[1];z.push([De,te])}return z}function Mje(l,_,g,S){const D=l*g+_*S,F=l*S-_*g;return Math.atan2(F,D)}function fCt(l,_,g,S,D,F,z,ee,pe,we,De){let te=Math.abs(g),nt=Math.abs(S);if(te<gu||nt<gu)return[[ee,pe]];const Te=D*Math.PI/180,Me=Math.cos(Te),bt=Math.sin(Te),vt=(l-ee)/2,Bt=(_-pe)/2,fr=Me*vt+bt*Bt,hn=-bt*vt+Me*Bt,vr=iP(fr)/iP(te)+iP(hn)/iP(nt);if(vr>1){const Ci=Math.sqrt(vr);te*=Ci,nt*=Ci}const Xt=iP(te),Wt=iP(nt),Hn=iP(fr),zn=iP(hn);let Fs=Xt*Wt-Xt*zn-Wt*Hn,Jn=Xt*zn+Wt*Hn;Jn<gu&&(Jn=gu),Fs=Math.max(0,Fs);const oc=(F===z?-1:1)*Math.sqrt(Fs/Jn),ro=oc*(te*hn/nt),Br=oc*(-(nt*fr)/te),pc=Me*ro-bt*Br+(l+ee)/2,eo=bt*ro+Me*Br+(_+pe)/2,Gt=(fr-ro)/te,fa=(hn-Br)/nt,Es=(-fr-ro)/te,Ho=(-hn-Br)/nt;let qi=Mje(1,0,Gt,fa),Yc=Mje(Gt,fa,Es,Ho);!z&&Yc>0&&(Yc-=Math.PI*2),z&&Yc<0&&(Yc+=Math.PI*2);const Hp=Math.max(te,nt),Gp=Math.max(De,Math.ceil(Math.abs(Yc)*Hp/Math.max(we,1e-4))),q_=[];for(let Ci=1;Ci<=Gp;Ci+=1){const Bf=Ci/Gp,F1=qi+Yc*Bf,Qg=Math.cos(F1),xN=Math.sin(F1),SN=Me*te*Qg-bt*nt*xN+pc,ZF=bt*te*Qg+Me*nt*xN+eo;q_.push([SN,ZF])}return q_}function pCt(l,_){return l.map(g=>{const S=[];for(const D of g.points)Ih(S,rCt(_,D));return{points:S,closed:g.closed}})}function dCt(l,_,g){const S=l.match(/[AaCcHhLlMmQqSsTtVvZz]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[],D=[];let F=0,z="",ee=0,pe=0,we=0,De=0,te=null,nt=null,Te=null;const Me=Bt=>{if(!te)return;const fr=bN(te.points);fr.length>=2&&D.push({points:fr,closed:Bt}),te=null},bt=()=>{te||(te={points:[[ee,pe]],closed:!1})},vt=()=>{if(F>=S.length)return null;const Bt=S[F];if(/^[AaCcHhLlMmQqSsTtVvZz]$/.test(Bt))return null;F+=1;const fr=Number(Bt);return Number.isFinite(fr)?fr:null};for(;F<S.length;){if(/^[AaCcHhLlMmQqSsTtVvZz]$/.test(S[F]))z=S[F],F+=1;else if(!z){F+=1;continue}switch(z){case"M":case"m":{let Bt=!0;for(;;){const fr=vt(),hn=vt();if(fr==null||hn==null)break;const vr=z==="m"?ee+fr:fr,Xt=z==="m"?pe+hn:hn;Bt?(Me(!1),te={points:[[vr,Xt]],closed:!1},ee=vr,pe=Xt,we=vr,De=Xt,Bt=!1):(bt(),Ih(te.points,[vr,Xt]),ee=vr,pe=Xt)}nt=null,Te=null;break}case"L":case"l":{for(;;){const Bt=vt(),fr=vt();if(Bt==null||fr==null)break;const hn=z==="l"?ee+Bt:Bt,vr=z==="l"?pe+fr:fr;bt(),Ih(te.points,[hn,vr]),ee=hn,pe=vr}nt=null,Te=null;break}case"H":case"h":{for(;;){const Bt=vt();if(Bt==null)break;const fr=z==="h"?ee+Bt:Bt;bt(),Ih(te.points,[fr,pe]),ee=fr}nt=null,Te=null;break}case"V":case"v":{for(;;){const Bt=vt();if(Bt==null)break;const fr=z==="v"?pe+Bt:Bt;bt(),Ih(te.points,[ee,fr]),pe=fr}nt=null,Te=null;break}case"C":case"c":{for(;;){const Bt=vt(),fr=vt(),hn=vt(),vr=vt(),Xt=vt(),Wt=vt();if(Bt==null||fr==null||hn==null||vr==null||Xt==null||Wt==null)break;const Hn=[ee,pe],zn=[z==="c"?ee+Bt:Bt,z==="c"?pe+fr:fr],Fs=[z==="c"?ee+hn:hn,z==="c"?pe+vr:vr],Jn=[z==="c"?ee+Xt:Xt,z==="c"?pe+Wt:Wt];bt(),Fje(Hn,zn,Fs,Jn,_).forEach(oc=>Ih(te.points,oc)),ee=Jn[0],pe=Jn[1],nt=Fs,Te=null}break}case"S":case"s":{for(;;){const Bt=vt(),fr=vt(),hn=vt(),vr=vt();if(Bt==null||fr==null||hn==null||vr==null)break;const Xt=[ee,pe],Wt=nt?[2*ee-nt[0],2*pe-nt[1]]:[ee,pe],Hn=[z==="s"?ee+Bt:Bt,z==="s"?pe+fr:fr],zn=[z==="s"?ee+hn:hn,z==="s"?pe+vr:vr];bt(),Fje(Xt,Wt,Hn,zn,_).forEach(Fs=>Ih(te.points,Fs)),ee=zn[0],pe=zn[1],nt=Hn,Te=null}break}case"Q":case"q":{for(;;){const Bt=vt(),fr=vt(),hn=vt(),vr=vt();if(Bt==null||fr==null||hn==null||vr==null)break;const Xt=[ee,pe],Wt=[z==="q"?ee+Bt:Bt,z==="q"?pe+fr:fr],Hn=[z==="q"?ee+hn:hn,z==="q"?pe+vr:vr];bt(),Oje(Xt,Wt,Hn,_).forEach(zn=>Ih(te.points,zn)),ee=Hn[0],pe=Hn[1],Te=Wt,nt=null}break}case"T":case"t":{for(;;){const Bt=vt(),fr=vt();if(Bt==null||fr==null)break;const hn=[ee,pe],vr=Te?[2*ee-Te[0],2*pe-Te[1]]:[ee,pe],Xt=[z==="t"?ee+Bt:Bt,z==="t"?pe+fr:fr];bt(),Oje(hn,vr,Xt,_).forEach(Wt=>Ih(te.points,Wt)),ee=Xt[0],pe=Xt[1],Te=vr,nt=null}break}case"A":case"a":{for(;;){const Bt=vt(),fr=vt(),hn=vt(),vr=vt(),Xt=vt(),Wt=vt(),Hn=vt();if(Bt==null||fr==null||hn==null||vr==null||Xt==null||Wt==null||Hn==null)break;const zn=z==="a"?ee+Wt:Wt,Fs=z==="a"?pe+Hn:Hn;bt(),fCt(ee,pe,Bt,fr,hn,Math.abs(vr)>=.5,Math.abs(Xt)>=.5,zn,Fs,_,g).forEach(Jn=>Ih(te.points,Jn)),ee=zn,pe=Fs,nt=null,Te=null}break}case"Z":case"z":{te&&Ih(te.points,[we,De]),Me(!0),ee=we,pe=De,nt=null,Te=null;break}default:{nt=null,Te=null;break}}}return Me(!1),D}function Lje(l,_,g,S,D){if(!(g>gu)||!(S>gu))return[];const F=2*Math.PI*Math.max(g,S),z=pN(Math.ceil(F/Math.max(D,1e-4)),16,720),ee=[];for(let pe=0;pe<z;pe+=1){const we=2*Math.PI*pe/z;ee.push([l+g*Math.cos(we),_+S*Math.sin(we)])}return[{points:ee,closed:!0}]}function jK(l,_,g,S,D,F,z,ee){const pe=Math.abs(z-F),we=pN(Math.ceil(pe*Math.max(S,D)/Math.max(ee,1e-4)),2,180);for(let De=1;De<=we;De+=1){const te=F+pe*De/we*Math.sign(z-F);Ih(l,[_+S*Math.cos(te),g+D*Math.sin(te)])}}function mCt(l,_,g,S,D,F,z){const ee=g,pe=S;if(!(ee>gu)||!(pe>gu))return[];const we=pN(D,0,ee/2),De=pN(F,0,pe/2);if(we<gu||De<gu)return[{points:[[l,_],[l+ee,_],[l+ee,_+pe],[l,_+pe]],closed:!0}];const te=[];return Ih(te,[l+we,_]),Ih(te,[l+ee-we,_]),jK(te,l+ee-we,_+De,we,De,-Math.PI/2,0,z),Ih(te,[l+ee,_+pe-De]),jK(te,l+ee-we,_+pe-De,we,De,0,Math.PI/2,z),Ih(te,[l+we,_+pe]),jK(te,l+we,_+pe-De,we,De,Math.PI/2,Math.PI,z),Ih(te,[l,_+De]),jK(te,l+we,_+De,we,De,Math.PI,3*Math.PI/2,z),[{points:bN(te),closed:!0}]}function Rje(l){const _=gbe(l),g=[];for(let S=0;S+1<_.length;S+=2)g.push([_[S],_[S+1]]);return bN(g)}function gCt(l,_,g,S){const D=l.toLowerCase();if(D==="path"){const F=_.d??"";return F.trim()?dCt(F,g,S):[]}if(D==="rect"){const F=Tm(_.x,0),z=Tm(_.y,0),ee=Tm(_.width,NaN),pe=Tm(_.height,NaN);if(!(ee>gu)||!(pe>gu))return[];let we=Tm(_.rx,NaN),De=Tm(_.ry,NaN);return!Number.isFinite(we)&&Number.isFinite(De)&&(we=De),!Number.isFinite(De)&&Number.isFinite(we)&&(De=we),Number.isFinite(we)||(we=0),Number.isFinite(De)||(De=0),mCt(F,z,ee,pe,we,De,g)}if(D==="circle"){const F=Tm(_.cx,0),z=Tm(_.cy,0),ee=Tm(_.r,NaN);return ee>gu?Lje(F,z,ee,ee,g):[]}if(D==="ellipse"){const F=Tm(_.cx,0),z=Tm(_.cy,0),ee=Tm(_.rx,NaN),pe=Tm(_.ry,NaN);return!(ee>gu)||!(pe>gu)?[]:Lje(F,z,ee,pe,g)}if(D==="line"){const F=Tm(_.x1,0),z=Tm(_.y1,0),ee=Tm(_.x2,0),pe=Tm(_.y2,0);return[{points:[[F,z],[ee,pe]],closed:!1}]}if(D==="polyline"){const F=Rje(_.points);return F.length<2?[]:[{points:F,closed:!1}]}if(D==="polygon"){const F=Rje(_.points);return F.length<3?[]:[{points:F,closed:!0}]}return[]}function hCt(l){const _=[];for(const g of l){const S=bN(g.points);g.closed?S.length>=3&&Math.abs(mbe(S))>gu&&_.push({points:S,closed:!0}):S.length>=2&&_.push({points:S,closed:!1})}return _}function yCt(l){return l.fill!=="none"&&l.fill!=="transparent"&&l.opacity>gu&&l.fillOpacity>gu}function vCt(l){return l.stroke!=="none"&&l.stroke!=="transparent"&&l.strokeWidth>gu&&l.opacity>gu&&l.strokeOpacity>gu}function bCt(l){const _=[];for(const g of l){if(!g.closed)continue;const S=bN(g.points);if(S.length<3)continue;const D=mbe(S),F=Math.abs(D);F<=gu||_.push({points:S,area:D,absArea:F,sample:WJe(S)})}return _}function xCt(l,_){const g=bCt(l);if(g.length===0)return null;const S=[],D=[];if(_==="evenodd"){const z=[...g].sort((ee,pe)=>ee.absArea-pe.absArea);for(const ee of z){let pe=0;for(const De of g)De!==ee&&(De.absArea<=ee.absArea+gu||VJe(ee.sample,De.points)&&(pe+=1));const we=Ed(ee.points);pe%2===0?S.push(we):D.push(we)}}else{const ee=[...g].sort((pe,we)=>we.absArea-pe.absArea)[0].area>=0?1:-1;for(const pe of g){const we=Ed(pe.points);(pe.area>=0?1:-1)===ee?S.push(we):D.push(we)}}S.length===0&&S.push(Ed(g[0].points));let F=S.length===1?S[0]:Fh(...S);return D.length>0&&(F=N1(F,...D)),F.isEmpty()?null:F}function SCt(l){return l==="round"?"Round":"Square"}function TCt(l,_,g){const S=Ed(l),D=S.offset(_/2,g),F=S.offset(-_/2,g);if(F.isEmpty())return D.isEmpty()?null:D;const z=N1(D,F);return z.isEmpty()?null:z}function kCt(l,_,g){if(!(_>gu))return null;const S=SCt(g),D=[];for(const F of l){const z=bN(F.points);if(F.closed){if(z.length<3)continue;const ee=TCt(z,_,S);ee&&!ee.isEmpty()&&D.push(ee)}else{if(z.length<2)continue;const ee=_be(z,_,S);ee.isEmpty()||D.push(ee)}}return D.length===0?null:D.length===1?D[0]:Fh(...D)}function CCt(l){const g=l.toPolygons().map(ee=>ee.map(([pe,we])=>[pe,we])).map(ee=>bN(ee)).filter(ee=>ee.length>=3).map(ee=>{const pe=mbe(ee);return{points:ee,area:pe,absArea:Math.abs(pe),sample:WJe(ee)}}).filter(ee=>ee.absArea>gu);if(g.length===0)return[];const S=g.filter(ee=>ee.area>0),D=g.filter(ee=>ee.area<0);if(S.length===0){const ee=Ed(g[0].points);return ee.isEmpty()?[]:[{sketch:ee,area:ee.area()}]}const F=S.map(ee=>({outer:ee,holes:[]}));for(const ee of D){const pe=F.filter(we=>VJe(ee.sample,we.outer.points)).sort((we,De)=>we.outer.absArea-De.outer.absArea);pe.length>0&&pe[0].holes.push(ee)}const z=[];for(const ee of F){let pe=Ed(ee.outer.points);if(ee.holes.length>0){const we=ee.holes.map(De=>Ed(De.points));pe=N1(pe,...we)}pe.isEmpty()||z.push({area:Math.abs(pe.area()),sketch:pe})}return z.sort((ee,pe)=>pe.area-ee.area),z}function wCt(l,_){const g=CCt(l);if(g.length===0)return l;const S=g[0].area,D=Math.max(_.minRegionArea,S*_.minRegionAreaRatio);let F=g.filter(z=>z.area+gu>=D);if(F.length===0&&(F=[g[0]]),_.regionSelection==="largest"&&(F=[F[0]]),Number.isFinite(_.maxRegions)){const z=Math.max(1,Math.floor(_.maxRegions));F=F.slice(0,z)}return F.length===1?F[0].sketch:Fh(...F.map(z=>z.sketch))}function ECt(l,_){const g=Number.isFinite(_.maxWidth),S=Number.isFinite(_.maxHeight);if(!g&&!S)return l;const D=l.bounds(),F=D.min,z=D.max,ee=Math.max(0,(z[0]??0)-(F[0]??0)),pe=Math.max(0,(z[1]??0)-(F[1]??0));let we=Number.POSITIVE_INFINITY;return g&&ee>gu&&(we=Math.min(we,_.maxWidth/ee)),S&&pe>gu&&(we=Math.min(we,_.maxHeight/pe)),!Number.isFinite(we)||we<=0||we>=1-gu?l:l.scale(we)}function DCt(l,_){if(!_.centerOnOrigin)return l;const g=l.bounds(),S=g.min,D=g.max,F=((S[0]??0)+(D[0]??0))*.5,z=((S[1]??0)+(D[1]??0))*.5;return Math.abs(F)<=gu&&Math.abs(z)<=gu?l:l.translate(-F,-z)}function PCt(l,_){let g=MF();if(_.invertY){const S=gbe(l.viewBox),D=Tm(l.height,NaN),F=S.length>=4?S[1]+S[3]:Number.isFinite(D)?D:0;g=lN(KK(0,F),Ive(1,-1))}return Math.abs(_.scale-1)>gu&&(g=lN(Ive(_.scale,_.scale),g)),g}const ACt=new Set(["path","rect","circle","ellipse","line","polyline","polygon"]);function NCt(l,_){const g=[],S=[{tag:"__root__",ctx:{transform:MF(),style:{...Kkt},hidden:!1,inDefs:!1}}];let D=!1;const F=/<!--[\s\S]*?-->|<\?[\s\S]*?\?>|<!DOCTYPE[\s\S]*?>|<!\[CDATA\[[\s\S]*?\]\]>|<\/?[^>]+>/gi;let z;for(;(z=F.exec(l))!==null;){const ee=z[0];if(ee.startsWith("<!--")||ee.startsWith("<?")||ee.startsWith("<!"))continue;if(ee.startsWith("</")){const Wt=ee.slice(2,-1).trim().toLowerCase();for(;S.length>1;){const Hn=S.pop();if(!Hn||Hn.tag===Wt)break}continue}const we=ee.endsWith("/>"),De=ee.slice(1,ee.length-(we?2:1)).trim();if(!De)continue;const te=De.search(/\s/),nt=(te<0?De:De.slice(0,te)).toLowerCase(),Te=te<0?"":De.slice(te+1),Me=aCt(Te),bt=S[S.length-1].ctx,vt=uCt(bt.style,Me),Bt=_Ct(Me.transform);let fr=lN(bt.transform,Bt);!D&&nt==="svg"&&(D=!0,fr=lN(PCt(Me,_),fr));const hn=bt.hidden||vt.display==="none"||vt.visibility==="hidden"||vt.opacity<=gu,vr=bt.inDefs||nt==="defs"||nt==="symbol"||nt==="clipPath"||nt==="mask"||nt==="pattern",Xt={transform:fr,style:vt,hidden:hn,inDefs:vr};if(!Xt.hidden&&!Xt.inDefs&&ACt.has(nt)){const Wt=gCt(nt,Me,_.flattenTolerance,_.arcSegments),Hn=hCt(pCt(Wt,Xt.transform));Hn.length>0&&g.push({subpaths:Hn,style:{...Xt.style}})}we||S.push({tag:nt,ctx:Xt})}return g}function ICt(l={}){const _=l.include??"auto",g=l.regionSelection??"all",S=Number.isFinite(l.flattenTolerance)?Math.max(.01,l.flattenTolerance):.35,D=Number.isFinite(l.arcSegments)?Math.max(2,Math.floor(l.arcSegments)):12,F=Number.isFinite(l.maxRegions)?Math.max(1,Math.floor(l.maxRegions)):Number.POSITIVE_INFINITY,z=Number.isFinite(l.minRegionArea)?Math.max(0,l.minRegionArea):0,ee=Number.isFinite(l.minRegionAreaRatio)?Math.max(0,l.minRegionAreaRatio):0,pe=Number.isFinite(l.scale)?Math.max(1e-6,l.scale):1,we=Number.isFinite(l.maxWidth)?Math.max(1e-6,l.maxWidth):Number.POSITIVE_INFINITY,De=Number.isFinite(l.maxHeight)?Math.max(1e-6,l.maxHeight):Number.POSITIVE_INFINITY,te=l.centerOnOrigin??!1,nt=Number.isFinite(l.simplify)?Math.max(0,l.simplify):0,Te=l.invertY??!0;return{include:_,regionSelection:g,maxRegions:F,minRegionArea:z,minRegionAreaRatio:ee,flattenTolerance:S,arcSegments:D,scale:pe,maxWidth:we,maxHeight:De,centerOnOrigin:te,simplify:nt,invertY:Te}}function FCt(l={}){const _=(g,S,D=!0)=>{if(g!=null){if(typeof g!="number"||!Number.isFinite(g))throw new Error(`SVG import option "${S}" must be a finite number`);if(!D&&g<=0)throw new Error(`SVG import option "${S}" 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(_(l.maxRegions,"maxRegions"),_(l.minRegionArea,"minRegionArea"),_(l.minRegionAreaRatio,"minRegionAreaRatio"),_(l.flattenTolerance,"flattenTolerance",!1),_(l.arcSegments,"arcSegments",!1),_(l.scale,"scale",!1),_(l.maxWidth,"maxWidth",!1),_(l.maxHeight,"maxHeight",!1),_(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 OCt(l,_,g){return g==="fill"?l:g==="stroke"?_:g==="fill-and-stroke"?[...l,..._]:l.length>0?l:_}function jje(l,_={}){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");FCt(_);const g=ICt(_),S=NCt(l,g);if(S.length===0)throw new Error("SVG import produced no supported shape geometry");const D=[],F=[];for(const pe of S){if(yCt(pe.style)){const we=xCt(pe.subpaths,pe.style.fillRule);we&&!we.isEmpty()&&D.push(we)}if(vCt(pe.style)){const we=kCt(pe.subpaths,pe.style.strokeWidth,pe.style.strokeJoin);we&&!we.isEmpty()&&F.push(we)}}const z=OCt(D,F,g.include);if(z.length===0)throw new Error("SVG import found no fill/stroke geometry after style filtering");let ee=z.length===1?z[0]:Fh(...z);if(ee=wCt(ee,g),ee=ECt(ee,g),g.simplify>0&&(ee=ee.simplify(g.simplify)),ee.isEmpty())throw new Error("SVG import generated an empty sketch");return ee=DCt(ee,g),ee}const Fve=1e-6;function tN(l,_){return l[0]*_[0]+l[1]*_[1]+l[2]*_[2]}function MCt(l,_){return[l[0]-_[0],l[1]-_[1],l[2]-_[2]]}function Bje(l,_){return Math.hypot(l,_)}function eee(l){const _=Math.hypot(l[0],l[1],l[2]);return _<1e-12?[0,0,1]:[l[0]/_,l[1]/_,l[2]/_]}function sP(l,_,g=Fve){return Math.abs(l-_)<=g}function Jje(l,_,g,S){return{kind:"project",sourceShape:s_(l),plane:{origin:[_.origin[0],_.origin[1],_.origin[2]],u:[_.u[0],_.u[1],_.u[2]],v:[_.v[0],_.v[1],_.v[2]],normal:[_.normal[0],_.normal[1],_.normal[2]]},sourcePlacement:g?TE(g):void 0,replayReason:S,transforms:[]}}const LCt={matrix:Sa.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 BK(l){return{profile:Cd(l.profile),placement:AS(l.placement)}}function hbe(l){return{origin:[l.placement.workplane.origin[0],l.placement.workplane.origin[1],l.placement.workplane.origin[2]],u:eee([l.placement.workplane.u[0],l.placement.workplane.u[1],l.placement.workplane.u[2]]),v:eee([l.placement.workplane.v[0],l.placement.workplane.v[1],l.placement.workplane.v[2]]),normal:eee([l.placement.workplane.normal[0],l.placement.workplane.normal[1],l.placement.workplane.normal[2]])}}function RCt(l){const _=Math.hypot(l[0],l[1],l[2]);if(_<1e-12)return Sa.identity().toArray();const g=l[0]/_,S=l[1]/_,D=l[2]/_;return[1-2*g*g,-2*g*S,-2*g*D,0,-2*S*g,1-2*S*S,-2*S*D,0,-2*D*g,-2*D*S,1-2*D*D,0,0,0,0,1]}function jCt(l){switch(l.kind){case"translate":return Sa.translation(l.x,l.y,l.z).toArray();case"rotate":return Sa.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg).toArray();case"scale":return Sa.scale([l.x,l.y,l.z]).toArray();case"rotateAround":return Sa.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]).toArray();case"mirror":return RCt([l.normalX,l.normalY,l.normalZ])}}function BCt(l,_){const g=jCt(_),S=Sa.from(g),D=AS(l);return{matrix:Sa.from(D.matrix).mul(g).toArray(),placement:{...D.placement,workplane:{...D.placement.workplane,origin:S.point(D.placement.workplane.origin),u:S.vector(D.placement.workplane.u),v:S.vector(D.placement.workplane.v),normal:S.vector(D.placement.workplane.normal)}}}}function Bee(l,_,g){const S=Sa.from(_.matrix),D=S.point([0,0,0]),F=S.vector([1,0,0]),z=S.vector([0,1,0]),ee=S.vector([0,0,1]),pe=Math.abs(tN(eee(ee),g.normal));if(!sP(pe,1,1e-5))return{reason:"projection replay currently requires the target plane to stay parallel to the source workplane."};const we=tN(F,g.u),De=tN(z,g.u),te=tN(F,g.v),nt=tN(z,g.v),Te=Bje(we,te),Me=Bje(De,nt);if(Te<Fve||Me<Fve)return{reason:"projection replay requires a non-degenerate in-plane basis."};const bt=we*De+te*nt;if(Math.abs(bt)>1e-5*Math.max(1,Te*Me))return{reason:"projection replay does not support in-plane shear from downstream 3D transforms yet."};const vt=we/Te,Bt=De/Me,fr=te/Te,hn=nt/Me,vr=vt*hn-Bt*fr;if(!sP(Math.abs(vr),1,1e-5))return{reason:"projection replay requires a rigid or mirrored in-plane basis."};let Xt=Cd(l);if((!sP(Te,1)||!sP(Me,1))&&(Xt=lb(Xt,{kind:"scale",x:Te,y:Me})),vr<0){Xt=lb(Xt,{kind:"mirror",normalX:1,normalY:0});const Fs=Math.atan2(-fr,-vt)*180/Math.PI;sP(Fs,0)||(Xt=lb(Xt,{kind:"rotate",degrees:Fs}))}else{const Fs=Math.atan2(fr,vt)*180/Math.PI;sP(Fs,0)||(Xt=lb(Xt,{kind:"rotate",degrees:Fs}))}const Wt=MCt(D,g.origin),Hn=tN(Wt,g.u),zn=tN(Wt,g.v);return(!sP(Hn,0)||!sP(zn,0))&&(Xt=lb(Xt,{kind:"translate",x:Hn,y:zn})),{profile:Xt}}function JCt(l,_,g){return Bee(l,_,g)}function UJe(l){return{kind:"circle",radius:l,transforms:[]}}function zCt(l){var _,g;return Math.max(l.hole.radius,((_=l.hole.counterbore)==null?void 0:_.radius)??0,((g=l.hole.countersink)==null?void 0:g.radius)??0)}function nve(l){return{profile:Cd(l),placement:AS(LCt)}}function qCt(l,_){const g=Bee(l.profile,l.placement,hbe(_));return g.profile?{ok:!0,context:{profile:g.profile,placement:AS(_)}}:{ok:!1,reason:g.reason??"projection replay could not map a compatible source plane."}}function WCt(l,_){const g=Bee(UJe(zCt(_)),_.placement,hbe(l.placement));if(!g.profile)return{ok:!1,reason:`projection replay can only absorb hole rewrites when the hole axis stays parallel to the projected source basis. ${g.reason??""}`.trim()};const S=NS("difference",[l.profile,g.profile]);return S?{ok:!0,context:{profile:S,placement:AS(l.placement)}}:{ok:!1,reason:"projection replay could not subtract the hole silhouette from the projected source profile."}}function VCt(l,_){const g=Bee(_.profile,_.placement,hbe(l.placement));if(!g.profile)return{ok:!1,reason:`projection replay can only absorb cut rewrites when the cut workplane stays parallel to the projected source basis. ${g.reason??""}`.trim()};const S=NS("difference",[l.profile,g.profile]);return S?{ok:!0,context:{profile:S,placement:AS(l.placement)}}:{ok:!1,reason:"projection replay could not subtract the cut silhouette from the projected source profile."}}function nN(l){if(!l)return{ok:!1,reason:"projection replay currently requires compiler-owned source intent."};switch(l.kind){case"queryOwner":return nN(l.base);case"transform":{const _=nN(l.base);if(!_.ok)return _;let g=BK(_.context);for(const S of l.steps){if(S.kind==="workplanePlacement"){g.placement=AS({matrix:S.matrix,placement:S.placement});continue}g.placement=BCt(g.placement,S)}return{ok:!0,context:g}}case"extrude":return l.scaleTop?{ok:!1,reason:"projection replay currently supports straight extrusions without tapered tops."}:{ok:!0,context:nve(l.profile)};case"box":return{ok:!0,context:nve({kind:"rect",width:l.x,height:l.y,center:l.center,transforms:[]})};case"cylinder":return{ok:!0,context:nve(UJe(Math.max(Math.abs(l.radius),Math.abs(l.radiusTop??l.radius))))};case"shell":{const _=nN(l.base);return _.ok?{ok:!0,context:BK(_.context)}:_}case"hole":{const _=nN(l.base);return _.ok?l.extent.kind==="two-sided"&&wm(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."}:wm(l.extent).kind!=="through"?{ok:!0,context:BK(_.context)}:WCt(_.context,l):_}case"cut":{const _=nN(l.base);return _.ok?l.extent.kind==="two-sided"&&wm(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||wm(l.extent).kind!=="through"?l.taper&&wm(l.extent).kind==="through"?{ok:!1,reason:"projection replay currently supports straight through cuts without tapered side walls."}:{ok:!0,context:BK(_.context)}:VCt(_.context,l):_}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 _=[];for(let F=0;F<l.shapes.length;F+=1){const z=nN(l.shapes[F]);if(!z.ok)return{ok:!1,reason:`projection replay could not derive a compatible union operand at index ${F}: ${z.reason}`};_.push(z.context)}if(_.length===0)return{ok:!1,reason:"projection replay cannot derive an empty boolean union source."};const g=AS(_[0].placement),S=[];for(let F=0;F<_.length;F+=1){const z=qCt(_[F],g);if(!z.ok)return{ok:!1,reason:`projection replay could not align union operand ${F} to a shared projection basis: ${z.reason}`};S.push(z.context.profile)}const D=NS("union",S);return D?{ok:!0,context:{profile:D,placement:g}}:{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 UCt(l,_){var z;const g=gP(l);if(!g)return null;const S=KBe(_),D=nN(g);if(!D.ok)return Jje(g,S,(z=gTt(l))==null?void 0:z.placement,D.reason);const F=JCt(D.context.profile,D.context.placement,S);return F.profile?{kind:"project",sourceShape:s_(g),plane:{origin:[S.origin[0],S.origin[1],S.origin[2]],u:[S.u[0],S.u[1],S.u[2]],v:[S.v[0],S.v[1],S.v[2]],normal:[S.normal[0],S.normal[1],S.normal[2]]},sourcePlacement:TE(D.context.placement.placement),replayProfile:F.profile,transforms:[]}:Jje(g,S,D.context.placement.placement,F.reason??"projection replay could not derive a supported 2D profile.")}function $Je(l,_){const g=KBe(_),S=eJe(g);return l.transform(S)}function $Ct(l,_){const g=$Je(l,_);return new So(g.slice(0))}function HCt(l,_){const g=$Je(l,_),S=new So(g.project()),D=UCt(l,_);return D?Ty(S,D):S}function ybe(l){if(!l||typeof l!="object")return!1;const _=l;return typeof _.name=="string"&&Array.isArray(_.normal)&&Array.isArray(_.center)}function vE(l){return Number.isFinite(l)&&l>0}function Ove(l,_){return l[0]*_[0]+l[1]*_[1]+l[2]*_[2]}function Cee(l){const _=Math.hypot(l[0],l[1],l[2]);if(_<1e-12)throw new Error("Hole/cut feature direction could not be normalized.");return[l[0]/_,l[1]/_,l[2]/_]}function GCt(l){const{workplane:_,u:g,v:S,protrude:D}=l,F=[_.origin[0]+_.u[0]*g+_.v[0]*S+_.normal[0]*D,_.origin[1]+_.u[1]*g+_.v[1]*S+_.normal[1]*D,_.origin[2]+_.u[2]*g+_.v[2]*S+_.normal[2]*D];return[_.u[0],_.u[1],_.u[2],0,_.v[0],_.v[1],_.v[2],0,_.normal[0],_.normal[1],_.normal[2],0,F[0],F[1],F[2],1]}function XCt(l,_){return _?bJe(l).some(g=>cb(g,_)):!0}function vbe(l,_,g){if(!XCt(l,_))throw new Error(`${g} requires a face/workplane owned by the target shape or one of its preserved query ancestors.`)}function bbe(l,_,g){const S=Axt(gP(l),g);if(S)throw new Error(`${_} ${S}`)}function QCt(l){const _=l.boundingBox(),[g,S,D]=_.min,[F,z,ee]=_.max;return[[g,S,D],[g,S,ee],[g,z,D],[g,z,ee],[F,S,D],[F,S,ee],[F,z,D],[F,z,ee]]}function YCt(l,_,g){const S=Cee(g);let D=0;for(const we of QCt(l)){const De=[we[0]-_[0],we[1]-_[1],we[2]-_[2]];D=Math.max(D,Ove(De,S))}if(D>1e-6)return D;const F=l.boundingBox(),z=F.max[0]-F.min[0],ee=F.max[1]-F.min[1],pe=F.max[2]-F.min[2];return Math.max(Math.hypot(z,ee,pe),1)}function ZCt(l,_){return ybe(_)?_:l.face(_)}function KCt(l,_,g,S,D={requireDefendedQuery:!0}){const F=ybe(g)?QF(g):QF(l,g);return vbe(_,F.source.owner,S),D.requireDefendedQuery&&bbe(_,S,F.source),{face:ZCt(l,g),query:F.source}}function ewt(l,_,g,S){if(g.planar===!1||!g.uAxis||!g.vAxis)throw new Error(`${S} upToFace currently requires a planar termination face.`);const D=Cee(_),F=Cee(g.normal);if(Math.abs(Math.abs(Ove(D,F))-1)>1e-6)throw new Error(`${S} upToFace currently requires a termination face parallel to the feature direction.`);const z=[g.center[0]-l[0],g.center[1]-l[1],g.center[2]-l[2]],ee=Ove(z,D);if(!(ee>1e-6))throw new Error(`${S} upToFace requires the termination face to lie in the feature direction.`);return ee}function PJ(l,_,g,S,D,F,z,ee={allowThrough:!0}){if(+(D.depth!=null)+ +(D.upToFace!=null)+ +(D.through===!0)!==1)throw new Error(`${F} ${z} extent must specify exactly one of through, depth, or upToFace.`);if(D.through){if(!ee.allowThrough)throw new Error(`${F} reverse two-sided extents do not support through termination yet.`);return{kind:"through",depth:YCt(_,g,S)}}if(D.upToFace!=null){const we=KCt(l,_,D.upToFace,F,{requireDefendedQuery:!1});return{kind:"upToFace",depth:ewt(g,S,we.face,F),face:we.query}}if(!vE(D.depth))throw new Error(`${F} ${z} extent requires a positive finite blind depth.`);return{kind:"blind",depth:D.depth}}function HJe(l,_,g,S,D,F){if(D.extent){if(D.depth!=null||D.upToFace!=null)throw new Error(`${F} accepts either top-level depth/upToFace or extent.forward/extent.reverse, not both.`);if(!D.extent.forward)throw new Error(`${F} extent.forward is required when using structured feature extents.`);const z=PJ(l,_,g,[-S[0],-S[1],-S[2]],D.extent.forward,F,"forward");if(!D.extent.reverse)return z;const ee=PJ(l,_,g,Cee(S),D.extent.reverse,F,"reverse",{allowThrough:!1});if(ee.kind==="through")throw new Error(`${F} reverse two-sided extents do not support through termination yet.`);return{kind:"two-sided",forward:z,reverse:ee}}if(D.depth!=null&&D.upToFace!=null)throw new Error(`${F} accepts either depth or upToFace, not both.`);return D.upToFace!=null?PJ(l,_,g,[-S[0],-S[1],-S[2]],{upToFace:D.upToFace},F,"forward"):D.depth==null?PJ(l,_,g,[-S[0],-S[1],-S[2]],{through:!0},F,"forward"):PJ(l,_,g,[-S[0],-S[1],-S[2]],{depth:D.depth},F,"forward")}function twt(l){var g,S;const _={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(!vE(l.counterbore.diameter)||l.counterbore.diameter<=l.diameter)throw new Error("Shape.hole() counterbore diameter must be greater than the hole diameter.");if(!vE(l.counterbore.depth))throw new Error("Shape.hole() counterbore depth must be a positive finite value.");_.counterbore={radius:l.counterbore.diameter/2,depth:l.counterbore.depth}}if(l.countersink){if(!vE(l.countersink.diameter)||l.countersink.diameter<=l.diameter)throw new Error("Shape.hole() countersink diameter must be greater than the hole diameter.");const D=l.countersink.angleDeg??90;if(!Number.isFinite(D)||D<=0||D>=180)throw new Error("Shape.hole() countersink angleDeg must be between 0 and 180 degrees.");const F=D*Math.PI/360,z=Math.tan(F);if(!(z>1e-9))throw new Error("Shape.hole() countersink angleDeg is too small to form a defended taper.");_.countersink={radius:l.countersink.diameter/2,angleDeg:D,depth:(l.countersink.diameter-l.diameter)/2/z}}if(l.thread){const D=(g=l.thread.designation)==null?void 0:g.trim(),F=(S=l.thread.class)==null?void 0:S.trim();if(D==="")throw new Error("Shape.hole() thread.designation must be a non-empty string when provided.");if(F==="")throw new Error("Shape.hole() thread.class must be a non-empty string when provided.");if(l.thread.pitch!=null&&!vE(l.thread.pitch))throw new Error("Shape.hole() thread.pitch must be a positive finite value when provided.");if(l.thread.depth!=null&&!vE(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(D==null&&F==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.");_.thread={designation:D,pitch:l.thread.pitch,class:F,handedness:l.thread.handedness,depth:l.thread.depth,modeled:!1}}return _}function rwt(l,_){var D,F,z;if((l.counterbore||l.countersink)&&_.kind==="two-sided")throw new Error("Shape.hole() does not yet combine reverse two-sided extents with counterbore or countersink heads.");const g=wm(_),S=((D=l.counterbore)==null?void 0:D.depth)??((F=l.countersink)==null?void 0:F.depth)??0;if(S>0&&S>=g.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(((z=l.thread)==null?void 0:z.depth)!=null&&l.thread.depth>g.depth+1e-6)throw new Error("Shape.hole() thread.depth cannot exceed the primary forward hole depth.")}function nwt(l,_,g){if(_.taperScale==null)return;if(g.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 S=Array.isArray(_.taperScale)?_.taperScale:[_.taperScale,_.taperScale];if(S.length!==2||!vE(S[0])||!vE(S[1]))throw new Error("Shape.cutout() taperScale must be a positive finite number or [x, y] pair.");if(l.kind==="circle"&&Math.abs(S[0]-S[1])>1e-6)throw new Error("Shape.cutout() circular tapered cuts currently require a uniform taperScale.");return{scale:[S[0],S[1]]}}function GJe(l,_,g){if(!l)return null;const S=Nee(_);return KJ(rbe(l,g(S)),S)}function XJe(l,_){if(!_)throw new Error("Hole/cut feature could not record compiler intent for this target.");const g=vJe(l),S=k_(_,l.colorHex,{backend:g.backend,representation:g.representation,fidelity:g.fidelity,topology:"none",sources:["boolean",...g.sources]});return yee(S,lbe(l)),Lee(S,yJe(l),{merge:!1}),Ree(S,{backend:g.backend,representation:g.representation,fidelity:g.fidelity,topology:"none",sources:["boolean",...g.sources]}),S}function iwt(l,_,g,S){const D=ybe(g)?QF(g):QF(l,g);return vbe(_,D.source.owner,"Shape.hole()"),bbe(_,"Shape.hole()",D.source),{placement:{placement:{workplane:dve(D),u:S.u??0,v:S.v??0,protrude:0,selfAnchor:"center"},matrix:GCt({workplane:dve(D),u:S.u??0,v:S.v??0,protrude:0})},extent:HJe(l,_,D.origin,D.normal,{depth:S.depth,upToFace:S.upToFace,extent:S.extent},"Shape.hole()")}}function QJe(l,_,g,S){if(!vE(S.diameter))throw new Error("Shape.hole() requires a positive finite diameter.");const D=gP(l);if(!D)throw new Error("Shape.hole() currently requires a compile-covered target shape.");const{placement:F,extent:z}=iwt(_,l,g,S),ee=twt(S);rwt(ee,z);const pe=GJe(aSt(D,F,ee,z),"hole",we=>Yxt(we,D,F.placement,ee,z));return XJe(l,pe)}function YJe(l,_,g={}){const S=gP(l);if(!S)throw new Error("Shape.cutout() currently requires a compile-covered target shape.");const D=tm(_);if(!D)throw new Error("Shape.cutout() requires a compile-covered sketch profile.");const F=SE(_),z=xE(_);if(!F||!z)throw new Error("Shape.cutout() requires a sketch placed with Sketch.onFace(...).");vbe(l,F.workplane.source.owner,"Shape.cutout()"),bbe(l,"Shape.cutout()",F.workplane.source);const ee=HJe(l,l,F.workplane.origin,F.workplane.normal,{depth:g.depth,upToFace:g.upToFace,extent:g.extent},"Shape.cutout()"),pe=nwt(D,g,ee),we=GJe(oSt(S,{matrix:z,placement:TE(F)},D,ee,pe),"cut",De=>Zxt(De,S,F,D,ee));return XJe(l,we)}Ys.prototype.hole=function(_,g){return QJe(this,this,_,g)};Ys.prototype.cutout=function(_,g={}){return YJe(this,_,g)};lo.prototype.hole=function(_,g){return QJe(this.toShape(),this,_,g)};lo.prototype.cutout=function(_,g={}){return YJe(this.toShape(),_,g)};const swt={fidelity:"kernel-native",topology:"synthetic",sources:["sheet-metal"]};function awt(l){var g,S;const _=l.bendRadius+l.thickness;return{kind:((g=l.cornerRelief)==null?void 0:g.kind)??"rect",size:((S=l.cornerRelief)==null?void 0:S.size)??_}}function owt(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:awt(l),flanges:[]}}function cwt(l){return l==="panel"?"panel":`"${l}"`}function lwt(l){return{region:l.region,sketch:l.sketch.clone(),u:l.u,v:l.v,selfAnchor:l.selfAnchor}}function uwt(l){if(SE(l)!=null)throw new Error("SheetMetalPart.cutout() expects an unplaced 2D sketch. Pass the profile before calling onFace(...).");if(!tm(l))throw new Error("SheetMetalPart.cutout() requires a compile-covered sketch profile.")}function _wt(l,_){const g=kE({kind:"sheetMetal",model:_ee(l),output:_},`sheet-metal:${_}`);if(!g)throw new Error("sheetMetal() could not build the compiler-owned base plan.");return k_(g,void 0,swt)}function fwt(l,_){const g=new Set(x2t(l));if(!g.has(_)&&_!=="panel")throw new Error(`SheetMetalPart.cutout() cannot target ${cwt(_)} because that flange has not been added. Supported planar regions: ${Array.from(g).join(", ")}`)}class GJ{constructor(_,g=[]){of(this,"model");of(this,"cutouts");this.model=_ee(_),this.cutouts=g.map(lwt)}flange(_,g){const S=_ee(this.model);if(S.flanges.find(z=>z.edge===_))throw new Error(`${_} flange is already defined on this SheetMetalPart.`);S.flanges.push({edge:_,length:g.length,angleDeg:g.angleDeg??90});const F=fee(S);if(F)throw new Error(F);return HF(S),new GJ(S,this.cutouts)}cutout(_,g,S={}){if(!S2t(_))throw new Error(`SheetMetalPart.cutout() does not support region "${String(_)}".`);return fwt(this.model,_),uwt(g),new GJ(this.model,[...this.cutouts,{region:_,sketch:g.clone(),u:S.u??0,v:S.v??0,selfAnchor:S.selfAnchor??"center"}])}regionNames(){return["panel",...Array.from(new Set(this.model.flanges.flatMap(_=>[`bend-${_.edge}`,`flange-${_.edge}`])))]}folded(){return this.buildOutput("folded")}flatPattern(){return this.buildOutput("flat")}buildOutput(_){const g=fee(this.model);if(g)throw new Error(g);HF(this.model);let S=_wt(this.model,_);for(const D of this.cutouts){const F=D.sketch.onFace(S,D.region,{u:D.u,v:D.v,selfAnchor:D.selfAnchor});S=S.cutout(F)}return S}}function pwt(l){const _=owt(l),g=fee(_);if(g)throw new Error(g);return HF(_),new GJ(_)}let Jee=[],XJ={},dN=[];function dwt(){Jee=[],dN=[]}function mwt(l){XJ=l}function zje(){return Jee}function gwt(l,_){dN.push(l);try{return _()}finally{dN.pop()}}function ZJe(l,_){return Object.prototype.hasOwnProperty.call(l,_)}function KJe(l,_,g={}){const S=dN[dN.length-1],D=S!=null&&S.namePrefix?`${S.namePrefix} / ${l}`:l,F=S==null?void 0:S.localOverrides,z=!!(F&&ZJe(F,l)),ee=(z?F[l]:void 0)??XJ[D]??XJ[l]??_,pe=g.integer??!1,we=pe?Math.round(ee):ee,De=g.min??0,te=g.max??_*4,nt=g.step??(pe||te-De>100?1:.1);if(!z){const Te=pe?Math.round(_):_;Jee.push({name:D,value:we,defaultValue:Te,min:De,max:te,step:nt,unit:g.unit,integer:pe,reverse:g.reverse})}return we}function hwt(l,_){const g=dN[dN.length-1],S=g!=null&&g.namePrefix?`${g.namePrefix} / ${l}`:l,D=g==null?void 0:g.localOverrides,F=!!(D&&ZJe(D,l)),z=_?1:0,pe=((F?D[l]:void 0)??XJ[S]??XJ[l]??z)>=.5?1:0;return F||Jee.push({name:S,value:pe,defaultValue:z,min:0,max:1,step:1,boolean:!0}),pe===1}function ywt(l,_,g,S={}){const D=S.axis??[0,0,1],F=S.min??0,z=S.max??360,ee=S.default??0,pe=KJe(l,ee,{min:F,max:z,unit:S.unit??"°",reverse:S.reverse});return _.rotateAround(D,pe,g)}function xbe(l){if(typeof l!="string")return;const _=l.trim();return _.length>0?_:void 0}function vwt(l){return!!l&&typeof l=="object"&&typeof l.name=="string"}function bwt(l){const _=xbe(l.name);if(!_)throw new Error("group(...) named items require a non-empty name");const g=l.shape!==void 0,S=l.sketch!==void 0,D=Array.isArray(l.group);if(Number(g)+Number(S)+Number(D)!==1)throw new Error(`group(...) named item "${_}" must provide exactly one of shape, sketch, or group`);if(g){if(!(l.shape instanceof Ys)&&!(l.shape instanceof lo)&&!(l.shape instanceof iu))throw new Error(`group(...) named item "${_}" shape must be a Shape, TrackedShape, or ShapeGroup`);return l.shape}if(S){if(!(l.sketch instanceof So))throw new Error(`group(...) named item "${_}" sketch must be a Sketch`);return l.sketch}return Sbe(...l.group)}function xwt(l){const _=[],g=[];return l.forEach(S=>{if(vwt(S)){_.push(bwt(S)),g.push(xbe(S.name));return}_.push(S),g.push(void 0)}),{children:_,childNames:g}}class iu{constructor(_,g){of(this,"children");of(this,"childNames");if(g&&g.length!==_.length)throw new Error("ShapeGroup childNames must match children length");this.children=[..._],this.childNames=this.children.map((S,D)=>xbe(g==null?void 0:g[D]))}childName(_){return this.childNames[_]}mapChildren(_){return new iu(this.children.map(_),this.childNames)}clone(){return this.mapChildren(_=>(_ instanceof iu||_ instanceof lo||_ instanceof Ys,_.clone()))}duplicate(){return this.clone()}translate(_,g,S){return this.mapChildren(D=>D instanceof iu||D instanceof lo||D instanceof Ys?D.translate(_,g,S):D.translate(_,g))}_bbox(){let _=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0];for(const S of this.children){if(S instanceof iu){const z=S._bbox();for(let ee=0;ee<3;ee++)z.min[ee]<_[ee]&&(_[ee]=z.min[ee]),z.max[ee]>g[ee]&&(g[ee]=z.max[ee]);continue}const D=S instanceof lo?S.toShape():S instanceof Ys?S:null;if(!D)continue;const F=D.boundingBox();for(let z=0;z<3;z++)F.min[z]<_[z]&&(_[z]=F.min[z]),F.max[z]>g[z]&&(g[z]=F.max[z])}return{min:_,max:g}}boundingBox(){const _=this._bbox();return{min:_.min,max:_.max}}resolveRotatePoint(_){if(Array.isArray(_))return[_[0],_[1],_[2]];const g=this._bbox();return pP(g.min,g.max,_)}moveTo(_,g,S){const D=this._bbox();return this.translate(_-D.min[0],g-D.min[1],S-D.min[2])}moveToLocal(_,g,S,D){let F;return _ instanceof iu?F=_._bbox():F={min:(_ instanceof lo?_.toShape():_).boundingBox().min},this.moveTo(F.min[0]+g,F.min[1]+S,F.min[2]+D)}attachTo(_,g,S="center",D){const F=_ instanceof iu?_._bbox():(()=>{const Te=(_ instanceof lo?_.toShape():_).boundingBox();return{min:Te.min,max:Te.max}})(),z=this._bbox(),ee=_ instanceof iu||vBe(g)?pP(F.min,F.max,g):(_ instanceof lo,_.referencePoint(g)),pe=pP(z.min,z.max,S);let we=ee[0]-pe[0],De=ee[1]-pe[1],te=ee[2]-pe[2];return D&&(we+=D[0],De+=D[1],te+=D[2]),this.translate(we,De,te)}onFace(_,g,S={}){const D=S.u??0,F=S.v??0,z=S.protrude??0,ee={front:"back",back:"front",left:"right",right:"left",top:"bottom",bottom:"top"},pe={front:(we,De,te)=>[we,-te,De],back:(we,De,te)=>[we,te,De],left:(we,De,te)=>[-te,we,De],right:(we,De,te)=>[te,we,De],top:(we,De,te)=>[we,De,te],bottom:(we,De,te)=>[we,De,-te]};return this.attachTo(_,g,ee[g],pe[g](D,F,z))}rotate(_,g,S){return this.mapChildren(D=>D instanceof iu||D instanceof lo||D instanceof Ys?D.rotate(_,g,S):D.rotate(_))}rotateAround(_,g,S=[0,0,0]){return this.transform(Sa.rotationAxis(_,g,S))}rotateAroundTo(_,g,S,D,F={}){return this.transform(Sa.rotateAroundTo(_,g,this.resolveRotatePoint(S),this.resolveRotatePoint(D),F))}pointAlong(_){const[g,S,D]=_,F=Math.sqrt(g*g+S*S+D*D)||1,z=g/F,ee=S/F,pe=D/F,we=-ee,De=z,te=0,nt=Math.sqrt(we*we+De*De+te*te),Te=pe;if(nt<1e-10)return Te>0?this:this.rotate(180,0,0);const Me=Math.atan2(nt,Te)*180/Math.PI,bt=[we/nt,De/nt,te/nt];return this.rotateAround(bt,Me)}transform(_){return new iu(this.children.map(g=>{if(g instanceof iu||g instanceof lo||g instanceof Ys)return g.transform(_);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(_){return this.mapChildren(g=>g instanceof iu||g instanceof lo||g instanceof Ys?g.scale(_):g.scale(typeof _=="number"?_:[_[0],_[1]]))}mirror(_){return this.mapChildren(g=>g instanceof iu||g instanceof lo||g instanceof Ys?g.mirror(_):g.mirror([_[0],_[1]]))}color(_){return this.mapChildren(g=>(g instanceof iu||g instanceof lo||g instanceof Ys,g.color(_)))}}function Sbe(...l){const _=xwt(l);return new iu(_.children,_.childNames)}function eze(l){const _=["part","qty","material","process","tolerance","notes"],g=D=>`"${D.replace(/"/g,'""')}"`,S=[_.join(",")];for(const D of l)S.push([g(D.part),String(D.qty),g(D.material??""),g(D.process??""),g(D.tolerance??""),g(D.notes??"")].join(","));return S.join(`
1
+ var Vbt=Object.defineProperty;var Ubt=(l,_,g)=>_ in l?Vbt(l,_,{enumerable:!0,configurable:!0,writable:!0,value:g}):l[_]=g;var of=(l,_,g)=>Ubt(l,typeof _!="symbol"?_+"":_,g);function fve(l,_){return[l[0]-_[0],l[1]-_[1],l[2]-_[2]]}function qJ(l,_){return[l[0]*_,l[1]*_,l[2]*_]}function pve(l,_){return l[0]*_[0]+l[1]*_[1]+l[2]*_[2]}function $bt(l,_){return[l[1]*_[2]-l[2]*_[1],l[2]*_[0]-l[0]*_[2],l[0]*_[1]-l[1]*_[0]]}function aee(l){return Math.hypot(l[0],l[1],l[2])}function GRe(l,_){const g=pve(l,_);return{axial:g,radial:fve(l,qJ(_,g))}}function oee(l,_,g){const S=aee(l),D=aee(_);if(S<1e-10||D<1e-10)return 0;const F=qJ(l,1/S),z=qJ(_,1/D),ee=pve(g,$bt(F,z)),pe=pve(F,z);return Math.atan2(ee,pe)*180/Math.PI}function Hbt(l,_,g){const S=oee(l,_,g),D=oee(l,qJ(_,-1),g);return Math.abs(S)<=Math.abs(D)?S:D}function fBe(l,_,g,S,D={}){const F=D.mode??"plane",z=Hve(l),ee=fve(g,_),pe=fve(S,_),we=GRe(ee,z),De=GRe(pe,z),te=aee(we.radial),nt=aee(De.radial);if(te<1e-10){if(F==="line"&&nt>=1e-10)throw new Error("rotateAroundTo(...): moving point lies on the rotation axis, so line alignment is impossible");return 0}if(F==="plane"){if(nt<1e-10)throw new Error("rotateAroundTo(...): target point lies on the rotation axis, so the target plane is undefined");return oee(we.radial,De.radial,z)}if(nt<1e-10)throw new Error("rotateAroundTo(...): target line lies on the rotation axis, but the moving point does not");const Te=1e-8*Math.max(1,Math.abs(we.axial),Math.abs(De.axial)),Me=1e-8*Math.max(1,te,nt);if(Math.abs(De.axial)<Te){if(Math.abs(we.axial)>Te)throw new Error("rotateAroundTo(...): target line stays on the pivot plane, but the moving point has axial offset");return Hbt(we.radial,De.radial,z)}const bt=we.axial/De.axial,vt=Math.abs(bt)*nt;if(Math.abs(te-vt)>Me)throw new Error("rotateAroundTo(...): moving point cannot reach the target line while preserving radius around the axis");const Bt=bt>=0?De.radial:qJ(De.radial,-1);return oee(we.radial,Bt,z)}function Gbt(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function Xbt(l){return l instanceof Sa?l.toArray():l}function Qbt(l,_){const g=new Array(16).fill(0);for(let S=0;S<4;S++)for(let D=0;D<4;D++){let F=0;for(let z=0;z<4;z++)F+=l[z*4+D]*_[S*4+z];g[S*4+D]=F}return g}function Hve(l){const _=Math.sqrt(l[0]*l[0]+l[1]*l[1]+l[2]*l[2]);if(_<1e-10)throw new Error("Axis must be non-zero");return[l[0]/_,l[1]/_,l[2]/_]}function XRe(l,_,g){const S=_[0],D=_[1],F=_[2];return[l[0]*S+l[4]*D+l[8]*F+l[12]*g,l[1]*S+l[5]*D+l[9]*F+l[13]*g,l[2]*S+l[6]*D+l[10]*F+l[14]*g]}function Ybt(l){const _=new Array(16),g=l[0],S=l[1],D=l[2],F=l[3],z=l[4],ee=l[5],pe=l[6],we=l[7],De=l[8],te=l[9],nt=l[10],Te=l[11],Me=l[12],bt=l[13],vt=l[14],Bt=l[15],fr=g*ee-S*z,hn=g*pe-D*z,vr=g*we-F*z,Xt=S*pe-D*ee,Wt=S*we-F*ee,Hn=D*we-F*pe,zn=De*bt-te*Me,Fs=De*vt-nt*Me,Jn=De*Bt-Te*Me,oc=te*vt-nt*bt,ro=te*Bt-Te*bt,Br=nt*Bt-Te*vt,pc=fr*Br-hn*ro+vr*oc+Xt*Jn-Wt*Fs+Hn*zn;if(Math.abs(pc)<1e-10)throw new Error("Transform matrix is not invertible");const eo=1/pc;return _[0]=(ee*Br-pe*ro+we*oc)*eo,_[1]=(D*ro-S*Br-F*oc)*eo,_[2]=(bt*Hn-vt*Wt+Bt*Xt)*eo,_[3]=(nt*Wt-te*Hn-Te*Xt)*eo,_[4]=(pe*Jn-z*Br-we*Fs)*eo,_[5]=(g*Br-D*Jn+F*Fs)*eo,_[6]=(vt*vr-Me*Hn-Bt*hn)*eo,_[7]=(De*Hn-nt*vr+Te*hn)*eo,_[8]=(z*ro-ee*Jn+we*zn)*eo,_[9]=(S*Jn-g*ro-F*zn)*eo,_[10]=(Me*Wt-bt*vr+Bt*fr)*eo,_[11]=(te*vr-De*Wt-Te*fr)*eo,_[12]=(ee*Fs-z*oc-pe*zn)*eo,_[13]=(g*oc-S*Fs+D*zn)*eo,_[14]=(bt*hn-Me*Xt-vt*fr)*eo,_[15]=(De*Xt-te*hn+nt*fr)*eo,_}class Sa{constructor(_){of(this,"m");this.m=_}static identity(){return new Sa(Gbt())}static from(_){return _ instanceof Sa?_:new Sa(_)}static translation(_,g,S){return new Sa([1,0,0,0,0,1,0,0,0,0,1,0,_,g,S,1])}static scale(_){const g=typeof _=="number"?_:_[0],S=typeof _=="number"?_:_[1],D=typeof _=="number"?_:_[2];return new Sa([g,0,0,0,0,S,0,0,0,0,D,0,0,0,0,1])}static rotationAxis(_,g,S=[0,0,0]){const[D,F,z]=Hve(_),ee=g*Math.PI/180,pe=Math.cos(ee),we=Math.sin(ee),De=pe+D*D*(1-pe),te=D*F*(1-pe)-z*we,nt=D*z*(1-pe)+F*we,Te=F*D*(1-pe)+z*we,Me=pe+F*F*(1-pe),bt=F*z*(1-pe)-D*we,vt=z*D*(1-pe)-F*we,Bt=z*F*(1-pe)+D*we,fr=pe+z*z*(1-pe),[hn,vr,Xt]=S,Wt=hn-(De*hn+te*vr+nt*Xt),Hn=vr-(Te*hn+Me*vr+bt*Xt),zn=Xt-(vt*hn+Bt*vr+fr*Xt);return new Sa([De,Te,vt,0,te,Me,Bt,0,nt,bt,fr,0,Wt,Hn,zn,1])}static rotateAroundTo(_,g,S,D,F={}){const z=fBe(_,g,S,D,F);return Sa.rotationAxis(_,z,g)}mul(_){const g=Xbt(_);return new Sa(Qbt(g,this.m))}translate(_,g,S){return this.mul(Sa.translation(_,g,S))}rotateAxis(_,g,S=[0,0,0]){return this.mul(Sa.rotationAxis(_,g,S))}scale(_){return this.mul(Sa.scale(_))}inverse(){return new Sa(Ybt(this.m))}point(_){return XRe(this.m,_,1)}vector(_){return XRe(this.m,_,0)}toArray(){return[...this.m]}}function $p(l){return Hve(l)}function pBe(...l){let _=Sa.identity();for(const g of l)_=_.mul(g);return _}const Zbt={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 cee=["default"];function Gve(l){return l==="live"||l==="default"||l==="high"?l:"default"}function Kbt(){return cee[cee.length-1]??"default"}function mN(l){const _=Gve(Kbt());return Zbt[_]}function e2t(l,_){const g=Gve(l);cee.push(g);try{return _()}finally{cee.pop()}}function dBe(l,_,g){const S=Math.round(l*_);return Math.max(g,S)}function mBe(l,_,g){return Math.max(g,l*_)}function t2t(l){const _=Math.max(3,Math.floor(l)),g=mN().curves.splineSamplesScale;return dBe(_,g,3)}function r2t(l){const _=Math.max(4,Math.floor(l)),g=mN().curves.sweepPathSamplesScale;return dBe(_,g,4)}function gBe(l){const _=Math.max(.01,l),g=mN().curves.levelSetEdgeLengthScale;return mBe(_,g,.01)}function hBe(l){const _=Math.max(.01,l),g=mN().curves.boundsPaddingScale;return mBe(_,g,.01)}function n2t(l){const _=Math.max(0,Math.floor(l)),g=mN().smoothing.refineStepsScale;return Math.max(0,Math.round(_*g))}function i2t(l){const _=Math.max(1e-6,l),g=mN().smoothing.refineLengthScale;return Math.max(1e-6,_*g)}function s2t(l){const _=Math.max(1e-6,l),g=mN().smoothing.refineToleranceScale;return Math.max(1e-6,_*g)}const yBe=["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"],$K=new Set(yBe),a2t={center:"center",left:"x",right:"x",front:"y",back:"y",top:"z",bottom:"z"};function vBe(l){return $K.has(l)}function Pee(l){if($K.has(l))return l;const _=l.split("-").filter(Boolean);if(_.length===0)return null;if(_.length===1)return $K.has(_[0])?_[0]:null;const g=new Map;for(const D of _){const F=a2t[D];if(!F||F==="center")return null;const z=g.get(F);if(z&&z!==D)return null;g.set(F,D)}const S=[g.get("z"),g.get("y"),g.get("x")].filter(D=>D!=null).join("-");return $K.has(S)?S:null}function pP(l,_,g){const S=Pee(g);if(!S)throw new Error(`Unknown anchor "${g}". Valid anchors: ${yBe.join(", ")}`);const D=(l[0]+_[0])/2,F=(l[1]+_[1])/2,z=(l[2]+_[2])/2;switch(S){case"center":return[D,F,z];case"front":return[D,l[1],z];case"back":return[D,_[1],z];case"left":return[l[0],F,z];case"right":return[_[0],F,z];case"top":return[D,F,_[2]];case"bottom":return[D,F,l[2]];case"front-left":return[l[0],l[1],z];case"front-right":return[_[0],l[1],z];case"back-left":return[l[0],_[1],z];case"back-right":return[_[0],_[1],z];case"top-front":return[D,l[1],_[2]];case"top-back":return[D,_[1],_[2]];case"top-left":return[l[0],F,_[2]];case"top-right":return[_[0],F,_[2]];case"bottom-front":return[D,l[1],l[2]];case"bottom-back":return[D,_[1],l[2]];case"bottom-left":return[l[0],F,l[2]];case"bottom-right":return[_[0],F,l[2]];case"top-front-left":return[l[0],l[1],_[2]];case"top-front-right":return[_[0],l[1],_[2]];case"top-back-left":return[l[0],_[1],_[2]];case"top-back-right":return[_[0],_[1],_[2]];case"bottom-front-left":return[l[0],l[1],l[2]];case"bottom-front-right":return[_[0],l[1],l[2]];case"bottom-back-left":return[l[0],_[1],l[2]];case"bottom-back-right":return[_[0],_[1],l[2]];default:throw new Error(`Unhandled anchor normalization for "${S}"`)}}const lee=["points","edges","surfaces","objects"];function z_(l,_){if(!Array.isArray(l)||l.length<3)throw new Error(`${_} must be a [x, y, z] tuple`);const g=Number(l[0]),S=Number(l[1]),D=Number(l[2]);if(!Number.isFinite(g)||!Number.isFinite(S)||!Number.isFinite(D))throw new Error(`${_} must contain finite numbers`);return[g,S,D]}function o2t(l,_){return[(l[0]+_[0])/2,(l[1]+_[1])/2,(l[2]+_[2])/2]}function bBe(l){const _=Math.hypot(l[0],l[1],l[2]);return _<1e-10?[0,0,1]:[l[0]/_,l[1]/_,l[2]/_]}function c2t(l){return!!l&&typeof l=="object"&&"min"in l&&"max"in l}function l2t(l,_){if(c2t(l))return{min:z_(l.min,`${_}.min`),max:z_(l.max,`${_}.max`)};if(typeof l=="object"&&l!=null){if("boundingBox"in l&&typeof l.boundingBox=="function"){const g=l.boundingBox();return{min:z_(g.min,`${_}.min`),max:z_(g.max,`${_}.max`)}}if("_bbox"in l&&typeof l._bbox=="function"){const g=l._bbox();return{min:z_(g.min,`${_}.min`),max:z_(g.max,`${_}.max`)}}}throw new Error(`${_} must be a bounds object or a shape/group with a bounding box`)}function u2t(l,_){const g=Sa.from(_),[S,D,F]=l.min,[z,ee,pe]=l.max,we=[[S,D,F],[S,D,pe],[S,ee,F],[S,ee,pe],[z,D,F],[z,D,pe],[z,ee,F],[z,ee,pe]],De=[1/0,1/0,1/0],te=[-1/0,-1/0,-1/0];for(const nt of we){const Te=g.point(nt);De[0]=Math.min(De[0],Te[0]),De[1]=Math.min(De[1],Te[1]),De[2]=Math.min(De[2],Te[2]),te[0]=Math.max(te[0],Te[0]),te[1]=Math.max(te[1],Te[1]),te[2]=Math.max(te[2],Te[2])}return{min:De,max:te}}function YF(){return{points:{},edges:{},surfaces:{},objects:{}}}function xBe(l){const _=YF();for(const[g,S]of Object.entries(l.points))_.points[g]=z_(S,`points.${g}`);for(const[g,S]of Object.entries(l.edges))_.edges[g]={start:z_(S.start,`edges.${g}.start`),end:z_(S.end,`edges.${g}.end`)};for(const[g,S]of Object.entries(l.surfaces))_.surfaces[g]={center:z_(S.center,`surfaces.${g}.center`),normal:z_(S.normal,`surfaces.${g}.normal`)};for(const[g,S]of Object.entries(l.objects))_.objects[g]={min:z_(S.min,`objects.${g}.min`),max:z_(S.max,`objects.${g}.max`)};return _}function _2t(l={}){const _=YF();for(const[g,S]of Object.entries(l.points??{}))_.points[g]=z_(S,`points.${g}`);for(const[g,S]of Object.entries(l.edges??{}))_.edges[g]={start:z_(S.start,`edges.${g}.start`),end:z_(S.end,`edges.${g}.end`)};for(const[g,S]of Object.entries(l.surfaces??{}))_.surfaces[g]={center:z_(S.center,`surfaces.${g}.center`),normal:bBe(z_(S.normal,`surfaces.${g}.normal`))};for(const[g,S]of Object.entries(l.objects??{}))_.objects[g]=l2t(S,`objects.${g}`);return _}function SBe(...l){const _=YF();for(const g of l){for(const[S,D]of Object.entries(g.points))_.points[S]=z_(D,`points.${S}`);for(const[S,D]of Object.entries(g.edges))_.edges[S]={start:z_(D.start,`edges.${S}.start`),end:z_(D.end,`edges.${S}.end`)};for(const[S,D]of Object.entries(g.surfaces))_.surfaces[S]={center:z_(D.center,`surfaces.${S}.center`),normal:z_(D.normal,`surfaces.${S}.normal`)};for(const[S,D]of Object.entries(g.objects))_.objects[S]={min:z_(D.min,`objects.${S}.min`),max:z_(D.max,`objects.${S}.max`)}}return _}function f2t(l){return lee.some(_=>Object.keys(l[_]).length>0)}function QRe(l,_){return SBe(l,_2t(_))}function p2t(l,_){const g=Sa.from(_),S=YF();for(const[D,F]of Object.entries(l.points))S.points[D]=g.point(F);for(const[D,F]of Object.entries(l.edges))S.edges[D]={start:g.point(F.start),end:g.point(F.end)};for(const[D,F]of Object.entries(l.surfaces))S.surfaces[D]={center:g.point(F.center),normal:bBe(g.vector(F.normal))};for(const[D,F]of Object.entries(l.objects))S.objects[D]=u2t(F,_);return S}function wK(l,_){throw new Error(`Placement reference "${l}" ${_}`)}function YRe(l,_,g,S,D){switch(_){case"points":{const F=l.points[g];return F?(S!=null&&wK(D,"does not support selectors"),z_(F,`points.${g}`)):null}case"edges":{const F=l.edges[g];if(!F)return null;if(S==null||S==="midpoint"||S==="center")return o2t(F.start,F.end);if(S==="start")return z_(F.start,`edges.${g}.start`);if(S==="end")return z_(F.end,`edges.${g}.end`);wK(D,"supports only .start, .end, or .midpoint")}case"surfaces":{const F=l.surfaces[g];return F?(S!=null&&S!=="center"&&wK(D,"supports only .center"),z_(F.center,`surfaces.${g}.center`)):null}case"objects":{const F=l.objects[g];if(!F)return null;const ee=Pee(S??"center");return ee||wK(D,`supports only Anchor3D selectors (${["center","top","bottom","left","right","front","back"].join(", ")} ...)`),pP(F.min,F.max,ee)}default:return null}}function d2t(l,_){const g=_.trim();if(!g)return null;const S=g.split(".");if(S.length>=2&&lee.includes(S[0])){const F=S[0],z=S[1],ee=S.length>2?S.slice(2).join("."):void 0;return YRe(l,F,z,ee,g)}const D=lee.map(F=>({kind:F,point:YRe(l,F,g,void 0,g)})).filter(F=>F.point!=null);if(D.length===0)return null;if(D.length>1)throw new Error(`Placement reference "${g}" is ambiguous. Use one of: ${D.map(F=>`${F.kind}.${g}`).join(", ")}`);return D[0].point}function TBe(l,_){return _?Object.keys(l[_]).sort():lee.flatMap(g=>Object.keys(l[g]).sort().map(S=>`${g}.${S}`))}function fp(l){if(l)return{id:l.id,operation:l.operation}}function cb(l,_){return l==null||_==null?l==null&&_==null:l.id===_.id&&l.operation===_.operation}function Kl(l){if(l)switch(l.kind){case"canonical-face":return{kind:"canonical-face",face:l.face,owner:fp(l.owner)};case"tracked-face":return{kind:"tracked-face",faceName:l.faceName,owner:fp(l.owner)};case"face-ref":return{kind:"face-ref",faceName:l.faceName,owner:fp(l.owner)};case"propagated-face":return{kind:"propagated-face",rewriteId:l.rewriteId,outcome:l.outcome,source:Kl(l.source),owner:fp(l.owner)};case"created-face":return{kind:"created-face",rewriteId:l.rewriteId,operation:l.operation,slot:l.slot,owner:fp(l.owner)}}}function Tl(l){if(l)switch(l.kind){case"tracked-edge":return{kind:"tracked-edge",edgeName:l.edgeName,selector:l.selector,owner:fp(l.owner)};case"edge-ref":return{kind:"edge-ref",edgeName:l.edgeName,selector:l.selector,owner:fp(l.owner)};case"propagated-edge":return{kind:"propagated-edge",rewriteId:l.rewriteId,outcome:l.outcome,source:Tl(l.source),selector:l.selector,owner:fp(l.owner)};case"created-edge":return{kind:"created-edge",rewriteId:l.rewriteId,operation:l.operation,slot:l.slot,selector:l.selector,owner:fp(l.owner)}}}function Rk(l){if(l)return{rewriteId:l.rewriteId,operation:l.operation,owner:fp(l.owner),preservedFaces:l.preservedFaces.map(_=>({query:Kl(_.query),status:_.status,note:_.note})),preservedEdges:l.preservedEdges.map(_=>({query:Tl(_.query),status:_.status,note:_.note})),createdFaces:l.createdFaces.map(_=>({query:Kl(_.query),note:_.note})),createdEdges:l.createdEdges.map(_=>({query:Tl(_.query),note:_.note})),diagnostics:l.diagnostics.map(_=>({code:_.code,category:_.category,queryKind:_.queryKind,message:_.message,source:_.queryKind==="face"?Kl(_.source):Tl(_.source),query:_.queryKind==="face"?Kl(_.query):Tl(_.query)})),descendants:(l.descendants??[]).map(_=>{switch(_.queryKind){case"face":return{queryKind:"face",kind:_.kind,query:Kl(_.query),source:Kl(_.source),note:_.note};case"edge":return{queryKind:"edge",kind:_.kind,query:Tl(_.query),source:Tl(_.source),note:_.note};case"vertex":return{queryKind:"vertex",kind:_.kind,note:_.note}}})}}function IS(l,_){if(l==null||_==null)return l==null&&_==null;if(l.kind!==_.kind)return!1;switch(l.kind){case"canonical-face":return _.kind==="canonical-face"&&l.face===_.face&&cb(l.owner,_.owner);case"tracked-face":return _.kind==="tracked-face"&&l.faceName===_.faceName&&cb(l.owner,_.owner);case"face-ref":return _.kind==="face-ref"&&l.faceName===_.faceName&&cb(l.owner,_.owner);case"propagated-face":return _.kind==="propagated-face"&&l.rewriteId===_.rewriteId&&l.outcome===_.outcome&&IS(l.source,_.source)&&cb(l.owner,_.owner);case"created-face":return _.kind==="created-face"&&l.rewriteId===_.rewriteId&&l.operation===_.operation&&l.slot===_.slot&&cb(l.owner,_.owner)}}function qk(l,_){if(l==null||_==null)return l==null&&_==null;if(l.kind!==_.kind)return!1;switch(l.kind){case"tracked-edge":return _.kind==="tracked-edge"&&l.edgeName===_.edgeName&&l.selector===_.selector&&cb(l.owner,_.owner);case"edge-ref":return _.kind==="edge-ref"&&l.edgeName===_.edgeName&&l.selector===_.selector&&cb(l.owner,_.owner);case"propagated-edge":return _.kind==="propagated-edge"&&l.rewriteId===_.rewriteId&&l.outcome===_.outcome&&l.selector===_.selector&&qk(l.source,_.source)&&cb(l.owner,_.owner);case"created-edge":return _.kind==="created-edge"&&l.rewriteId===_.rewriteId&&l.operation===_.operation&&l.slot===_.slot&&l.selector===_.selector&&cb(l.owner,_.owner)}}function WJ(l){if(!l)return"none";const _=l.owner?` @${l.owner.operation}:${l.owner.id}`:"";switch(l.kind){case"canonical-face":return`canonical-face(${l.face})${_}`;case"tracked-face":return`tracked-face(${l.faceName})${_}`;case"face-ref":return`face-ref(${l.faceName??"unnamed"})${_}`;case"propagated-face":return`propagated-face(${l.outcome} <- ${WJ(l.source)})${_}`;case"created-face":return`created-face(${l.operation}:${l.slot})${_}`}}function VJ(l){if(!l)return"none";const _=l.owner?` @${l.owner.operation}:${l.owner.id}`:"",g=`#${l.selector}`;switch(l.kind){case"tracked-edge":return`tracked-edge(${l.edgeName}${g})${_}`;case"edge-ref":return`edge-ref(${l.edgeName??"unnamed"}${g})${_}`;case"propagated-edge":return`propagated-edge(${l.outcome} <- ${VJ(l.source)}${g})${_}`;case"created-edge":return`created-edge(${l.operation}:${l.slot}${g})${_}`}}function m2t(l){return Kl(l)}function dve(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:m2t(l.source)}}function TE(l){return l?{workplane:dve(l.workplane),u:l.u,v:l.v,protrude:l.protrude,selfAnchor:l.selfAnchor}:null}function g2t(l){return[...l]}function AS(l){return l?{matrix:g2t(l.matrix),placement:TE(l.placement)}:null}function uee(l){if(l)return[l[0],l[1]]}function ZRe(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 YJ=["top","right","bottom","left"],RF=1e-9;function EK(l){return Number.isFinite(l)&&l>0}function KRe(l){return Number.isFinite(l)&&l>=0}function mve(l){return[l[0],l[1],l[2]]}function eje(l){return l?mve(l):void 0}function _ee(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(_=>({edge:_.edge,length:_.length,angleDeg:_.angleDeg}))}:null}function HK(l){return`sheetMetal().flange("${l}", ...)`}function h2t(l){return Math.abs(l)<=RF?0:l}function fee(l){if(!EK(l.panel.width)||!EK(l.panel.height))return"sheetMetal() requires a positive finite panel width and height.";if(!EK(l.thickness))return"sheetMetal() requires a positive finite sheet thickness.";if(!KRe(l.bendRadius))return"sheetMetal() requires a finite non-negative bendRadius.";if(l.bendRadius<=RF)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(!KRe(l.cornerRelief.size))return"sheetMetal() corner relief size must be a finite non-negative value.";const _=new Set;for(const g of l.flanges){if(!YJ.includes(g.edge))return`sheetMetal() does not recognize flange edge "${String(g.edge)}".`;if(_.has(g.edge))return`${HK(g.edge)} can only be declared once.`;if(_.add(g.edge),!EK(g.length))return`${HK(g.edge)} requires a positive finite length.`;if(!Number.isFinite(g.angleDeg)||Math.abs(h2t(g.angleDeg)-90)>1e-6)return`${HK(g.edge)} v1 only supports 90 degree flanges.`}return null}function y2t(l){return new Map(l.flanges.map(_=>[_.edge,_]))}function v2t(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 HF(l){const _=fee(l);if(_)throw new Error(_);const g=y2t(l),S=Math.PI/2*(l.bendRadius+l.bendAllowance.kFactor*l.thickness),D=new Map;for(const F of YJ){const z=g.get(F);if(!z)continue;const ee=v2t(F),pe=g.has(ee.start)?l.cornerRelief.size:0,we=g.has(ee.end)?l.cornerRelief.size:0,te=(F==="top"||F==="bottom"?l.panel.width:l.panel.height)-pe-we;if(!(te>RF))throw new Error(`${HK(F)} loses all usable span after applying the defended rectangular corner relief size ${l.cornerRelief.size}.`);D.set(F,{edge:F,length:z.length,angleDeg:z.angleDeg,bendAllowance:S,trimStart:pe,trimEnd:we,span:te,centerAlongEdge:(pe-we)/2})}return{panelWidth:l.panel.width,panelHeight:l.panel.height,thickness:l.thickness,bendRadius:l.bendRadius,kFactor:l.bendAllowance.kFactor,bendAllowance:S,reliefSize:l.cornerRelief.size,flanges:D}}function b2t(l){const _=["panel"],g=HF(l);for(const S of YJ)g.flanges.has(S)&&_.push(`bend-${S}`,`flange-${S}`);return _}function x2t(l){return b2t(l).filter(_=>_==="panel"||_.startsWith("flange-"))}function S2t(l){return l==="panel"||l==="flange-top"||l==="flange-right"||l==="flange-bottom"||l==="flange-left"}function T2t(l,_,g,S){return{workplane:{origin:[l[0],l[1],l[2]],u:[_[0],_[1],_[2]],v:[g[0],g[1],g[2]],normal:[S[0],S[1],S[2]],source:{kind:"face-ref",faceName:"sheet-metal-placement"}},u:0,v:0,protrude:0,selfAnchor:"center"}}function k2t(l,_,g,S){return Math.abs(_)<=RF&&Math.abs(g)<=RF&&Math.abs(S)<=RF?s_(l):E1(s_(l),{kind:"translate",x:_,y:g,z:S})}function DK(l,_,g,S,D){const F=T2t(_,g,S,D),z=[g[0],g[1],g[2],0,S[0],S[1],S[2],0,D[0],D[1],D[2],0,_[0],_[1],_[2],1];return E1(s_(l),{kind:"workplanePlacement",matrix:z,placement:F})}function G2(l,_,g,S=0,D=0,F=0){return k2t({kind:"box",x:l,y:_,z:g,center:!0},S,D,F)}function C2t(l,_){const g=l+_,S=lb({kind:"circle",radius:g,transforms:[]},{kind:"translate",x:0,y:l}),D=lb({kind:"circle",radius:l,transforms:[]},{kind:"translate",x:0,y:l}),F=NS("difference",[S,D]),z=lb({kind:"rect",width:g,height:g,center:!1,transforms:[]},{kind:"translate",x:0,y:-_});return NS("intersection",[F,z])}function w2t(l){return{kind:"box",x:l.panelWidth,y:l.panelHeight,z:l.thickness,center:!0}}function E2t(l,_){const g=l.thickness,S=l.bendRadius,D=_.length;switch(_.edge){case"top":return G2(_.span,g,D,_.centerAlongEdge,l.panelHeight/2+S+g/2,-g/2-S-D/2);case"bottom":return G2(_.span,g,D,_.centerAlongEdge,-l.panelHeight/2-S-g/2,-g/2-S-D/2);case"right":return G2(g,_.span,D,l.panelWidth/2+S+g/2,_.centerAlongEdge,-g/2-S-D/2);case"left":return G2(g,_.span,D,-l.panelWidth/2-S-g/2,_.centerAlongEdge,-g/2-S-D/2)}}function D2t(l,_){const g=C2t(l.bendRadius,l.thickness);if(!g)return null;const S={kind:"extrude",profile:g,height:_.span,center:!1};switch(_.edge){case"top":return DK(S,[-l.panelWidth/2+_.trimStart,l.panelHeight/2,-l.thickness/2],[0,1,0],[0,0,-1],[1,0,0]);case"bottom":return DK(S,[-l.panelWidth/2+_.trimStart,-l.panelHeight/2,-l.thickness/2],[0,-1,0],[0,0,-1],[1,0,0]);case"right":return DK(S,[l.panelWidth/2,-l.panelHeight/2+_.trimStart,-l.thickness/2],[1,0,0],[0,0,-1],[0,1,0]);case"left":return DK(S,[-l.panelWidth/2,-l.panelHeight/2+_.trimStart,-l.thickness/2],[-1,0,0],[0,0,-1],[0,1,0])}}function P2t(l,_){const g=l.thickness,S=_.bendAllowance;switch(_.edge){case"top":return G2(_.span,S,g,_.centerAlongEdge,l.panelHeight/2+S/2,0);case"bottom":return G2(_.span,S,g,_.centerAlongEdge,-l.panelHeight/2-S/2,0);case"right":return G2(S,_.span,g,l.panelWidth/2+S/2,_.centerAlongEdge,0);case"left":return G2(S,_.span,g,-l.panelWidth/2-S/2,_.centerAlongEdge,0)}}function A2t(l,_){const g=l.thickness,S=_.bendAllowance,D=_.length;switch(_.edge){case"top":return G2(_.span,D,g,_.centerAlongEdge,l.panelHeight/2+S+D/2,0);case"bottom":return G2(_.span,D,g,_.centerAlongEdge,-l.panelHeight/2-S-D/2,0);case"right":return G2(D,_.span,g,l.panelWidth/2+S+D/2,_.centerAlongEdge,0);case"left":return G2(D,_.span,g,-l.panelWidth/2-S-D/2,_.centerAlongEdge,0)}}function N2t(l,_){const g=HF(l),S=[w2t(g)];for(const D of YJ){const F=g.flanges.get(D);if(F){if(_==="folded"){const z=D2t(g,F);z&&S.push(z),S.push(E2t(g,F));continue}S.push(P2t(g,F)),S.push(A2t(g,F))}}return S.length===1?S[0]:Sy("union",S)}function Nh(l,_,g,S,D,F,z="face",ee=[l],pe=S){return{name:l,center:mve(_),normal:mve(g),planar:S,uAxis:eje(D),vAxis:eje(F),semantic:z,memberNames:[...ee],coplanar:pe}}function I2t(l,_){const g=l.thickness,S=l.bendRadius,F=(S+g/2)/Math.sqrt(2);switch(_.edge){case"top":return Nh("bend-top",[_.centerAlongEdge,l.panelHeight/2+F,-l.thickness/2-S+F],[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 Nh("bend-bottom",[_.centerAlongEdge,-l.panelHeight/2-F,-l.thickness/2-S+F],[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 Nh("bend-right",[l.panelWidth/2+F,_.centerAlongEdge,-l.thickness/2-S+F],[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 Nh("bend-left",[-l.panelWidth/2-F,_.centerAlongEdge,-l.thickness/2-S+F],[-1/Math.sqrt(2),0,1/Math.sqrt(2)],!1,void 0,void 0,"set",["bend-left-inner","bend-left-outer"],!1)}}function F2t(l,_){const g=HF(l),S=[Nh("panel",[0,0,g.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0])];for(const D of YJ){const F=g.flanges.get(D);if(F){if(_==="folded"){switch(S.push(I2t(g,F)),D){case"top":S.push(Nh("flange-top",[F.centerAlongEdge,g.panelHeight/2+g.bendRadius+g.thickness,-g.thickness/2-g.bendRadius-F.length/2],[0,1,0],!0,[1,0,0],[0,0,-1]));break;case"bottom":S.push(Nh("flange-bottom",[F.centerAlongEdge,-g.panelHeight/2-g.bendRadius-g.thickness,-g.thickness/2-g.bendRadius-F.length/2],[0,-1,0],!0,[1,0,0],[0,0,1]));break;case"right":S.push(Nh("flange-right",[g.panelWidth/2+g.bendRadius+g.thickness,F.centerAlongEdge,-g.thickness/2-g.bendRadius-F.length/2],[1,0,0],!0,[0,1,0],[0,0,1]));break;case"left":S.push(Nh("flange-left",[-g.panelWidth/2-g.bendRadius-g.thickness,F.centerAlongEdge,-g.thickness/2-g.bendRadius-F.length/2],[-1,0,0],!0,[0,-1,0],[0,0,1]));break}continue}switch(D){case"top":S.push(Nh("bend-top",[F.centerAlongEdge,g.panelHeight/2+F.bendAllowance/2,g.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0])),S.push(Nh("flange-top",[F.centerAlongEdge,g.panelHeight/2+F.bendAllowance+F.length/2,g.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0]));break;case"bottom":S.push(Nh("bend-bottom",[F.centerAlongEdge,-g.panelHeight/2-F.bendAllowance/2,g.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0])),S.push(Nh("flange-bottom",[F.centerAlongEdge,-g.panelHeight/2-F.bendAllowance-F.length/2,g.thickness/2],[0,0,1],!0,[1,0,0],[0,1,0]));break;case"right":S.push(Nh("bend-right",[g.panelWidth/2+F.bendAllowance/2,F.centerAlongEdge,g.thickness/2],[0,0,1],!0,[0,1,0],[-1,0,0])),S.push(Nh("flange-right",[g.panelWidth/2+F.bendAllowance+F.length/2,F.centerAlongEdge,g.thickness/2],[0,0,1],!0,[0,1,0],[-1,0,0]));break;case"left":S.push(Nh("bend-left",[-g.panelWidth/2-F.bendAllowance/2,F.centerAlongEdge,g.thickness/2],[0,0,1],!0,[0,-1,0],[1,0,0])),S.push(Nh("flange-left",[-g.panelWidth/2-F.bendAllowance-F.length/2,F.centerAlongEdge,g.thickness/2],[0,0,1],!0,[0,-1,0],[1,0,0]));break}}}return S}function gE(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 C_(l){return Object.is(l,-0)?0:l}function Xve(l){return l.map(_=>C_(_))}function PK(l){return[C_(l[0]),C_(l[1]),C_(l[2])]}function UJ(l){return AS({matrix:Xve(l.matrix),placement:TE(l.placement)})}function Aee(l){return fp(l)}function O2t(l){return{radius:C_(l.radius),depth:C_(l.depth)}}function M2t(l){return{radius:C_(l.radius),angleDeg:C_(l.angleDeg),depth:C_(l.depth)}}function L2t(l){return{designation:l.designation,pitch:l.pitch==null?void 0:C_(l.pitch),class:l.class,handedness:l.handedness,depth:l.depth==null?void 0:C_(l.depth),modeled:l.modeled}}function R2t(l){return{radius:C_(l.radius),counterbore:l.counterbore?O2t(l.counterbore):void 0,countersink:l.countersink?M2t(l.countersink):void 0,thread:l.thread?L2t(l.thread):void 0}}function $1e(l){switch(l.kind){case"through":case"blind":return{kind:l.kind,depth:C_(l.depth)};case"upToFace":return{kind:"upToFace",depth:C_(l.depth),face:Kl(l.face)}}}function tje(l){return l.kind==="two-sided"?{kind:"two-sided",forward:$1e(l.forward),reverse:$1e(l.reverse)}:$1e(l)}function j2t(l){return{scale:[C_(l.scale[0]),C_(l.scale[1])]}}function wm(l){return l.kind==="two-sided"?l.forward:l}function ub(l){return l.kind==="two-sided"?l.reverse:void 0}function ZJ(l){var S;const _=wm(l).depth,g=((S=ub(l))==null?void 0:S.depth)??0;return _+g}let gve=0;function B2t(l){return l.replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()||"shape"}function Nee(l){return gve+=1,{id:`shape-query-${B2t(l)}-${gve}`,operation:l}}function J2t(){gve=0}function z2t(l){const[_,g,S]=l,D=Math.hypot(_,g,S);if(D<1e-12)return Sa.identity().toArray();const F=_/D,z=g/D,ee=S/D,pe=1-2*F*F,we=-2*F*z,De=-2*F*ee,te=-2*z*F,nt=1-2*z*z,Te=-2*z*ee,Me=-2*ee*F,bt=-2*ee*z,vt=1-2*ee*ee;return[pe,te,Me,0,we,nt,bt,0,De,Te,vt,0,0,0,0,1]}function q2t(l){switch(l.kind){case"translate":return Sa.translation(l.x,l.y,l.z).toArray();case"rotate":return Sa.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg).toArray();case"scale":return Sa.scale([l.x,l.y,l.z]).toArray();case"rotateAround":return Sa.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]).toArray();case"mirror":return z2t([l.normalX,l.normalY,l.normalZ])}}function W2t(l,_){const g=q2t(_),S=Sa.from(g),D=UJ(l);return{matrix:Xve(Sa.from(D.matrix).mul(g).toArray()),placement:{...D.placement,workplane:{...D.placement.workplane,origin:PK(S.point(D.placement.workplane.origin)),u:PK(S.vector(D.placement.workplane.u)),v:PK(S.vector(D.placement.workplane.v)),normal:PK(S.vector(D.placement.workplane.normal))}}}}function GK(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:Xve(l.matrix),placement:TE(l.placement)}}}function kBe(l){return{kind:l.kind,points:l.points.map(([_,g,S])=>[_,g,S])}}function Cd(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(gE)};case"roundedRect":return{kind:"roundedRect",width:l.width,height:l.height,radius:l.radius,center:l.center,transforms:l.transforms.map(gE)};case"circle":return{kind:"circle",radius:l.radius,segments:l.segments,transforms:l.transforms.map(gE)};case"polygon":return{kind:"polygon",points:l.points.map(([_,g])=>[_,g]),transforms:l.transforms.map(gE)};case"boolean":return{kind:"boolean",op:l.op,profiles:l.profiles.map(_=>Cd(_)),transforms:l.transforms.map(gE)};case"offset":return{kind:"offset",base:Cd(l.base),delta:l.delta,join:l.join,transforms:l.transforms.map(gE)};case"hull":return{kind:"hull",profiles:l.profiles.map(_=>Cd(_)),transforms:l.transforms.map(gE)};case"project":return{kind:"project",sourceShape:s_(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?TE(l.sourcePlacement):void 0,replayProfile:l.replayProfile?Cd(l.replayProfile):void 0,replayReason:l.replayReason,transforms:l.transforms.map(gE)}}}function s_(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:Cd(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:_ee(l.model),output:l.output};case"shell":return{kind:"shell",base:s_(l.base),thickness:l.thickness,openFaces:[...l.openFaces],queryPropagation:Rk(l.queryPropagation)};case"hole":return{kind:"hole",base:s_(l.base),placement:UJ(l.placement),hole:R2t(l.hole),extent:tje(l.extent),queryPropagation:Rk(l.queryPropagation)};case"cut":return{kind:"cut",base:s_(l.base),placement:UJ(l.placement),profile:Cd(l.profile),extent:tje(l.extent),taper:l.taper?j2t(l.taper):void 0,queryPropagation:Rk(l.queryPropagation)};case"revolve":return{kind:"revolve",profile:Cd(l.profile),degrees:l.degrees,segments:l.segments};case"loft":return{kind:"loft",profiles:l.profiles.map(_=>Cd(_)),heights:l.heights.map(_=>_),edgeLength:l.edgeLength,boundsPadding:l.boundsPadding};case"sweep":return{kind:"sweep",profile:Cd(l.profile),path:kBe(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(_=>s_(_)),queryPropagation:Rk(l.queryPropagation)};case"transform":return{kind:"transform",base:s_(l.base),steps:l.steps.map(GK)};case"queryOwner":return{kind:"queryOwner",owner:Aee(l.owner),base:s_(l.base)};case"hull":return{kind:"hull",shapes:l.shapes.map(_=>s_(_)),points:l.points.map(([_,g,S])=>[_,g,S]),queryPropagation:Rk(l.queryPropagation)};case"trimByPlane":return{kind:"trimByPlane",base:s_(l.base),normalX:l.normalX,normalY:l.normalY,normalZ:l.normalZ,originOffset:l.originOffset,queryPropagation:Rk(l.queryPropagation)};case"fillet":return{kind:"fillet",base:s_(l.base),edge:Tl(l.edge),radius:l.radius,quadrant:uee(l.quadrant),segments:l.segments,resolvedEdge:ZRe(l.resolvedEdge),queryPropagation:Rk(l.queryPropagation)};case"chamfer":return{kind:"chamfer",base:s_(l.base),edge:Tl(l.edge),size:l.size,quadrant:uee(l.quadrant),resolvedEdge:ZRe(l.resolvedEdge),queryPropagation:Rk(l.queryPropagation)}}}function lb(l,_){if(!l)return null;const g=Cd(l);return g.transforms.push(gE(_)),g}function E1(l,_){return l?l.kind==="transform"?{kind:"transform",base:s_(l.base),steps:[...l.steps.map(GK),GK(_)]}:{kind:"transform",base:s_(l),steps:[GK(_)]}:null}function V2t(l,_){let g=s_(l);for(const S of _)g=E1(g,S);return g}function KJ(l,_){return l?{kind:"queryOwner",owner:Aee(_),base:s_(l)}:null}function kE(l,_){return l?KJ(l,Nee(_)):null}function Sy(l,_){return _.some(g=>g==null)?null:{kind:"boolean",op:l,shapes:_.map(g=>s_(g))}}function Iee(l){if(!l)return null;switch(l.kind){case"queryOwner":return Aee(l.owner);case"transform":case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":return Iee(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 U2t(l){const _=[],g=new Set;function S(D){if(D)switch(D.kind){case"queryOwner":g.has(D.owner.id)||(g.add(D.owner.id),_.push(Aee(D.owner))),S(D.base);return;case"transform":case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":S(D.base);return;case"boolean":for(const F of D.shapes)S(F);return;case"hull":for(const F of D.shapes)S(F);return;case"box":case"cylinder":case"sphere":case"extrude":case"sheetMetal":case"revolve":case"loft":case"sweep":return}}return S(l),_}function NJ(l){if(!l)return null;switch(l.kind){case"queryOwner":return NJ(l.base);case"transform":{let _=NJ(l.base);for(const g of l.steps){if(g.kind==="workplanePlacement"){_=UJ({matrix:g.matrix,placement:g.placement});continue}_&&(_=W2t(_,g))}return _}case"shell":case"fillet":case"chamfer":return NJ(l.base);case"hole":case"cut":return UJ(l.placement);case"trimByPlane":return NJ(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 NS(l,_){return _.some(g=>g==null)?null:{kind:"boolean",op:l,profiles:_.map(g=>Cd(g)),transforms:[]}}function CBe(l,_,g){return l?{kind:"offset",base:Cd(l),delta:_,join:g,transforms:[]}:null}function wBe(l){return l.some(_=>_==null)?null:{kind:"hull",profiles:l.map(_=>Cd(_)),transforms:[]}}function EBe(l,_=[]){return l.some(g=>g==null)?null:{kind:"hull",shapes:l.map(g=>s_(g)),points:_.map(([g,S,D])=>[g,S,D])}}function H1e(l,_,g){return l?{kind:"trimByPlane",base:s_(l),normalX:C_(_[0]),normalY:C_(_[1]),normalZ:C_(_[2]),originOffset:C_(g)}:null}function $2t(l,_,g,S,D){return!l||!_||!Number.isFinite(g)||!(g>0)||!Number.isFinite(D)||D<2?null:{kind:"fillet",base:s_(l),edge:Tl(_),radius:C_(g),quadrant:uee(S),segments:Math.max(2,Math.round(D))}}function H2t(l,_,g,S){return!l||!_||!Number.isFinite(g)||!(g>0)?null:{kind:"chamfer",base:s_(l),edge:Tl(_),size:C_(g),quadrant:uee(S)}}function G2t(l,_,g){return l.some(S=>S==null)?null:{kind:"loft",profiles:l.map(S=>Cd(S)),heights:_.map(S=>C_(S)),edgeLength:C_(g.edgeLength),boundsPadding:C_(g.boundsPadding)}}function X2t(l,_,g){return l?{kind:"sweep",profile:Cd(l),path:kBe(_),edgeLength:C_(g.edgeLength),boundsPadding:C_(g.boundsPadding),up:[C_(g.up[0]),C_(g.up[1]),C_(g.up[2])]}:null}function pee(l){var _;if(l===null)return"null";if(l===void 0)return"undefined";if(Array.isArray(l))return`Array(${l.length})`;if(typeof l=="object"){const g=(_=l.constructor)==null?void 0:_.name;return g&&g!=="Object"?g:"object"}return typeof l=="string"?`"${l}"`:typeof l}function DBe({apiName:l,inputs:_,minCount:g,itemName:S,usage:D,coerce:F}){const z=[];for(const ee of _)Array.isArray(ee)?z.push(...ee):z.push(ee);if(z.length<g){const ee=g===1?S:`${S}s`;throw new Error(`${l} requires at least ${g} ${ee}. ${D}`)}return z.map((ee,pe)=>{try{return F(ee)}catch(we){const De=we instanceof Error?we.message:String(we);throw new Error(`${l} argument ${pe+1}: ${De}`)}})}function gN(l,_){return{rewriteId:_.id,operation:l,owner:fp(_),preservedFaces:[],preservedEdges:[],createdFaces:[],createdEdges:[],diagnostics:[],descendants:[]}}function em(l,_,g,S,D,F){return{code:l,category:_,queryKind:g,message:S,source:g==="face"?Kl(D):Tl(D),query:g==="face"?Kl(F):Tl(F)}}function P1(l,_,g){return{kind:"propagated-face",rewriteId:_.id,outcome:g,source:Kl(l),owner:fp(_)}}function Fee(l,_,g){return{kind:"created-face",rewriteId:l.id,operation:_,slot:g,owner:fp(l)}}function GF(l,_,g){return{kind:"propagated-edge",rewriteId:_.id,outcome:g,source:Tl(l),selector:l.selector,owner:fp(_)}}function PBe(l,_,g,S="edge"){return{kind:"created-edge",rewriteId:l.id,operation:_,slot:g,selector:S,owner:fp(l)}}function A1(l,_,g={}){return{queryKind:"face",kind:l,query:Kl(_),source:Kl(g.source),note:g.note}}function $J(l,_,g={}){return{queryKind:"edge",kind:l,query:Tl(_),source:Tl(g.source),note:g.note}}function cg(l,_){l.descendants.push(_)}function Jk(){return{faces:new Map,blockedNames:new Map,supportedQueries:[],blockedQueries:[]}}function km(l){return[l[0],l[1],l[2]]}function uN(l){return{...l,normal:km(l.normal),center:km(l.center),query:Kl(l.query),uAxis:l.uAxis?km(l.uAxis):void 0,vAxis:l.vAxis?km(l.vAxis):void 0,descendant:l.descendant?Q2t(l.descendant):void 0}}function Q2t(l){return{kind:l.kind,semantic:l.semantic,memberCount:l.memberCount,memberNames:[...l.memberNames],coplanar:l.coplanar}}function Oee(l,_,g){return{kind:l==="face"&&_.length===1?"single":"face-set",semantic:l,memberCount:_.length,memberNames:[..._],coplanar:g}}function Y2t(l){if(l.length<=1)return!0;const _=l[0];if(_.planar===!1||!_.uAxis||!_.vAxis)return!1;const g=$p(_.normal),S=g[0]*_.center[0]+g[1]*_.center[1]+g[2]*_.center[2];for(const D of l.slice(1)){if(D.planar===!1||!D.uAxis||!D.vAxis)return!1;const F=$p(D.normal),z=Math.abs(g[0]*F[0]+g[1]*F[1]+g[2]*F[2]);if(Math.abs(z-1)>1e-6)return!1;const ee=g[0]*D.center[0]+g[1]*D.center[1]+g[2]*D.center[2];if(Math.abs(ee-S)>1e-6)return!1}return!0}function Z2t(l,_,g,S){return{...l,descendant:Oee(_,g,S)}}function K2t(l,_,g,S){const D=_.map(De=>uN(De)),F=D[0],z=Y2t(D),ee=D.reduce((De,te)=>[De[0]+te.center[0],De[1]+te.center[1],De[2]+te.center[2]],[0,0,0]),pe=Math.max(D.length,1),we={...F,name:l,center:[ee[0]/pe,ee[1]/pe,ee[2]/pe],query:Kl(g),planar:z?F.planar:!1,uAxis:z?F.uAxis:void 0,vAxis:z?F.vAxis:void 0};return Z2t(we,S,D.map(De=>De.name),z)}function XK(l){return{faces:new Map(Array.from(l.faces.entries(),([_,g])=>[_,uN(g)])),blockedNames:new Map(l.blockedNames),supportedQueries:l.supportedQueries.map(_=>Kl(_)),blockedQueries:l.blockedQueries.map(_=>({query:Kl(_.query),reason:_.reason}))}}function ABe(l,_){return _?l.some(g=>IS(g,_)):!1}function ext(l,_){return _?l.some(g=>IS(g.query,_)):!1}function dP(l,_){!_||ABe(l.supportedQueries,_)||l.supportedQueries.push(Kl(_))}function QK(l,_,g){!_||ext(l.blockedQueries,_)||l.blockedQueries.push({query:Kl(_),reason:g})}function txt(l,_){_&&(l.supportedQueries=l.supportedQueries.filter(g=>!IS(g,_)))}function Wu(l,_){const g=uN(_);g.descendant||(g.descendant=Oee("face",[g.name],g.planar!==!1)),l.faces.set(g.name,g),dP(l,_.query)}function G1e(l,_,g,S){const D=l.faces.get(_);D&&(D.query=Kl(g),l.faces.set(_,D),dP(l,g),dP(l,S))}function AK(l,_,g,S,D){const F=l.faces.get(_);F&&(F.query=Kl(g),F.descendant=Oee(S,[_],F.planar!==!1),l.faces.set(_,F),dP(l,g),dP(l,D))}function rje(l,_,g){const S=l.faces.get(_);S&&(txt(l,S.query),QK(l,S.query,g),l.faces.delete(_)),l.blockedNames.set(_,g)}function rxt(l,_,g){l.faces.has(_)&&l.faces.delete(_),l.blockedNames.set(_,g)}function nxt(l,_){const g=Sa.from(_);return{...l,center:g.point(l.center),normal:$p(g.vector(l.normal)),query:Kl(l.query),uAxis:l.uAxis?$p(g.vector(l.uAxis)):void 0,vAxis:l.vAxis?$p(g.vector(l.vAxis)):void 0}}function ixt(l,_){const g=XK(l);return g.faces=new Map(Array.from(g.faces.entries(),([S,D])=>[S,nxt(D,_)])),g}function sxt(l){switch(l.kind){case"translate":return Sa.translation(l.x,l.y,l.z).toArray();case"rotate":return Sa.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg).toArray();case"scale":return Sa.scale([l.x,l.y,l.z]).toArray();case"rotateAround":return Sa.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]).toArray();case"mirror":return NBe([l.normalX,l.normalY,l.normalZ]);case"workplanePlacement":return[...l.matrix]}}function NBe(l){const _=Math.hypot(l[0],l[1],l[2]);if(_<1e-12)return Sa.identity().toArray();const g=l[0]/_,S=l[1]/_,D=l[2]/_;return[1-2*g*g,-2*g*S,-2*g*D,0,-2*S*g,1-2*S*S,-2*S*D,0,-2*D*g,-2*D*S,1-2*D*D,0,0,0,0,1]}function dee(l){let _=Sa.identity();for(const g of l)switch(g.kind){case"translate":_=_.translate(g.x,g.y,0);break;case"rotate":_=_.rotateAxis([0,0,1],g.degrees);break;case"scale":_=_.scale([g.x,g.y,1]);break;case"mirror":_=_.mul(NBe([g.normalX,g.normalY,0]));break}return _.toArray()}function jk(l,_,g){const S=Sa.from(l).point([_,g,0]);return[S[0],S[1]]}function Qve(l,_){return[(l[0]+_[0])/2,(l[1]+_[1])/2]}function axt(l){if(l.length===0)return[0,0,0];const _=l.reduce((g,S)=>[g[0]+S[0],g[1]+S[1],g[2]+S[2]],[0,0,0]);return[_[0]/l.length,_[1]/l.length,_[2]/l.length]}function CJ(l,_){return[l[0]*_[0],l[1]*_[1]]}function wJ(l,_,g,S,D,F,z=0){return[l[0]+_[0]*S+g[0]*D+((F==null?void 0:F[0])??0)*z,l[1]+_[1]*S+g[1]*D+((F==null?void 0:F[1])??0)*z,l[2]+_[2]*S+g[2]*D+((F==null?void 0:F[2])??0)*z]}function oxt(l){const _=Math.hypot(l[0],l[1]);return _<1e-12?[1,0]:[l[0]/_,l[1]/_]}function hve(l,_){return[l[1]*_[2]-l[2]*_[1],l[2]*_[0]-l[0]*_[2],l[0]*_[1]-l[1]*_[0]]}function cxt(l){const _=$p(l),g=Math.abs(_[2])<.9?[0,0,1]:[0,1,0],S=$p(hve(g,_)),D=$p(hve(_,S));return{u:S,v:D}}function _P(l,_,g,S,D){const F=oxt([g[0]-_[0],g[1]-_[1]]),z=[F[1],-F[0]],ee=Qve(_,g);return{name:l,normal:[z[0],z[1],0],center:[ee[0],ee[1],S],planar:!0,uAxis:[F[0],F[1],0],vAxis:[0,0,1],query:Kl(D)}}function og(l,_){if(_)return{kind:"tracked-face",faceName:l,owner:_}}function lxt(l,_){const g=Jk(),S=l.center?-l.x/2:0,D=l.center?-l.y/2:0,F=S+l.x,z=D+l.y,ee=l.center?-l.z/2:0,pe=ee+l.z,we=[S,D],De=[F,D],te=[F,z],nt=[S,z],Te=og("top",_),Me=og("bottom",_);return Wu(g,{name:"top",normal:[0,0,1],center:[(S+F)/2,(D+z)/2,pe],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0],query:Te}),Wu(g,{name:"bottom",normal:[0,0,-1],center:[(S+F)/2,(D+z)/2,ee],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0],query:Me}),Wu(g,{..._P("side-bottom",we,De,(pe+ee)/2,og("side-bottom",_))}),Wu(g,{..._P("side-right",De,te,(pe+ee)/2,og("side-right",_))}),Wu(g,{..._P("side-top",te,nt,(pe+ee)/2,og("side-top",_))}),Wu(g,{..._P("side-left",nt,we,(pe+ee)/2,og("side-left",_))}),g}function uxt(l,_){const g=Jk(),S=l.center?-l.height/2:0,D=S+l.height,F=l.radiusTop??l.radius,z=(Math.abs(l.radius)+Math.abs(F))/2;return Wu(g,{name:"top",normal:[0,0,1],center:[0,0,D],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0],query:og("top",_)}),Wu(g,{name:"bottom",normal:[0,0,-1],center:[0,0,S],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0],query:og("bottom",_)}),Wu(g,{name:"side",normal:[1,0,0],center:[z,0,(D+S)/2],planar:!1,query:og("side",_)}),g}function _xt(l,_,g,S){const D=dee(l.transforms),F=l.center?-l.width/2:0,z=l.center?-l.height/2:0,ee=F+l.width,pe=z+l.height,we=jk(D,F,z),De=jk(D,ee,z),te=jk(D,ee,pe),nt=jk(D,F,pe),Te=Qve(we,te),Me=g?-_/2:0,bt=Me+_,vt=$p([De[0]-we[0],De[1]-we[1],0]),Bt=$p([nt[0]-we[0],nt[1]-we[1],0]),fr=Jk();return Wu(fr,{name:"top",normal:[0,0,1],center:[Te[0],Te[1],bt],planar:!0,uAxis:vt,vAxis:Bt,query:og("top",S)}),Wu(fr,{name:"bottom",normal:[0,0,-1],center:[Te[0],Te[1],Me],planar:!0,uAxis:vt,vAxis:[-Bt[0],-Bt[1],-Bt[2]],query:og("bottom",S)}),Wu(fr,_P("side-bottom",we,De,(bt+Me)/2,og("side-bottom",S))),Wu(fr,_P("side-right",De,te,(bt+Me)/2,og("side-right",S))),Wu(fr,_P("side-top",te,nt,(bt+Me)/2,og("side-top",S))),Wu(fr,_P("side-left",nt,we,(bt+Me)/2,og("side-left",S))),fr}function fxt(l,_,g,S){const D=Jk(),F=dee(l.transforms),z=Sa.from(F).point([0,0,0]),ee=Sa.from(F).point([l.radius,0,0]),pe=$p([ee[0]-z[0],ee[1]-z[1],0]),we=$p(Sa.from(F).vector([1,0,0])),De=$p(Sa.from(F).vector([0,1,0])),te=g?-_/2:0,nt=te+_;return Wu(D,{name:"top",normal:[0,0,1],center:[z[0],z[1],nt],planar:!0,uAxis:we,vAxis:De,query:og("top",S)}),Wu(D,{name:"bottom",normal:[0,0,-1],center:[z[0],z[1],te],planar:!0,uAxis:we,vAxis:[-De[0],-De[1],-De[2]],query:og("bottom",S)}),Wu(D,{name:"side",normal:pe,center:[ee[0],ee[1],(nt+te)/2],planar:!1,query:og("side",S)}),D}function pxt(l,_){switch(l.profile.kind){case"rect":case"roundedRect":return _xt(l.profile,l.height,l.center,_);case"circle":return fxt(l.profile,l.height,l.center,_);default:return Jk()}}function V2(l,_){var g;return(g=l==null?void 0:l.createdFaces.find(S=>S.query.slot===_))==null?void 0:g.query}function X1e(l,_){if(_)return l==null?void 0:l.descendants.find(g=>g.queryKind==="face"&&IS(g.query,_))}function EJ(l,_){var g;if(_)return(g=l==null?void 0:l.preservedFaces.find(S=>IS(S.query.source,_)))==null?void 0:g.query}function dxt(l){return`inner-${l}`}function IBe(l,_){const g=$2(l),S=[];for(const D of g.faces.keys())D==="top"&&_.includes("top")||D==="bottom"&&_.includes("bottom")||S.push(dxt(D));return S}function mxt(l,_){var S;const g=["wall"];return l.counterbore&&g.push("counterbore-wall","counterbore-floor"),l.countersink&&g.push("countersink-wall"),wm(_).kind==="blind"&&g.push("floor"),((S=ub(_))==null?void 0:S.kind)==="blind"&&g.push("cap"),g}function FBe(l,_,g){var D;const S=(()=>{switch(l.kind){case"circle":return["wall"];case"rect":case"roundedRect":return["wall-bottom","wall-right","wall-top","wall-left"];default:return[]}})();return wm(_).kind==="blind"&&S.push("floor"),((D=ub(_))==null?void 0:D.kind)==="blind"&&S.push("cap"),S}function gxt(l,_){const g=["entry-rim","forward-end-rim"];return ub(_)&&g.push("reverse-end-rim"),(l.counterbore||l.countersink)&&g.push("head-transition-rim"),g}function hxt(l,_,g){if(FBe(l,_).length===0)return[];const S=["entry-rim","forward-end-rim"];return ub(_)&&S.push("reverse-end-rim"),S}function jF(l,_){if(!_)return[];const g=new Set(l.faces.keys()),S=(()=>{switch(_.kind){case"tracked-face":return[_.faceName];case"face-ref":return _.faceName?[_.faceName]:[];case"canonical-face":switch(_.face){case"front":return g.has("side-bottom")?["side-bottom"]:g.has("side")?["side"]:[];case"back":return g.has("side-top")?["side-top"]:g.has("side")?["side"]:[];case"left":return g.has("side-left")?["side-left"]:g.has("side")?["side"]:[];case"right":return g.has("side-right")?["side-right"]:g.has("side")?["side"]:[];case"top":return g.has("top")?["top"]:[];case"bottom":return g.has("bottom")?["bottom"]:[]}case"created-face":return[_.slot];case"propagated-face":return jF(l,_.source)}})();return S.filter((D,F)=>g.has(D)&&S.indexOf(D)===F)}function yxt(l,_){switch(l){case"top":return _.has("bottom")?["bottom"]:[];case"bottom":return _.has("top")?["top"]:[];case"side-bottom":return _.has("side-top")?["side-top"]:[];case"side-top":return _.has("side-bottom")?["side-bottom"]:[];case"side-left":return _.has("side-right")?["side-right"]:[];case"side-right":return _.has("side-left")?["side-left"]:[];case"side":return _.has("side")?["side"]:[];default:return[]}}function nje(l,_){switch(_){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 ije(l){switch(l){case"host":return 3;case"up-to-face-target":return 2;case"through-exit":return 1}}function vxt(l){var _,g;return((_=l.counterbore)==null?void 0:_.depth)??((g=l.countersink)==null?void 0:g.depth)??0}function bxt(l,_){var D;const g=((D=ub(_))==null?void 0:D.depth)??0;if(g>0)return(wm(_).depth-g)/2;const S=vxt(l);return S+Math.max(wm(_).depth-S,0)/2}function xxt(l){var g;const _=((g=ub(l))==null?void 0:g.depth)??0;return(wm(l).depth-_)/2}function mee(l,_,g){if(!l)return[];const S=$2(l),D=new Set(S.faces.keys()),F=new Map,z=(De,te)=>{const nt=F.get(De);(!nt||ije(te)>ije(nt))&&F.set(De,te)},ee=jF(S,_),pe=wm(g);for(const De of ee)if(z(De,"host"),pe.kind==="through")for(const te of yxt(De,D))z(te,"through-exit");if(pe.kind==="upToFace")for(const De of jF(S,pe.face))z(De,"up-to-face-target");const we=ub(g);if((we==null?void 0:we.kind)==="upToFace")for(const De of jF(S,we.face))z(De,"up-to-face-target");return Array.from(F.entries()).map(([De,te])=>({name:De,reason:te})).sort((De,te)=>De.name.localeCompare(te.name))}function NK(l,_){var g;return _?cb((g=l.query)==null?void 0:g.owner,_):!0}function OBe(l,_,g,S){switch(S.kind){case"tracked-face":return _===S.faceName&&NK(g,S.owner);case"face-ref":return(S.faceName==null||_===S.faceName)&&NK(g,S.owner);case"canonical-face":return jF(l,S).includes(_)&&NK(g,S.owner);case"created-face":return _===S.slot&&NK(g,S.owner);case"propagated-face":return IS(g.query,S)||OBe(l,_,g,S.source)}}function Sxt(l,_){if(!_)return[];const g=new Set,S=[];for(const[D,F]of l.faces.entries())g.has(D)||OBe(l,D,F,_)&&(g.add(D),S.push({name:D,face:uN(F)}));return S}function Txt(l,_){return l.flatMap(g=>Sxt(g,_))}function kxt(l){if(l.length===0)return null;const _=[...new Set(l.map(g=>g.name))];return _.length===1?_[0]:null}function Cxt(l,_){return l??_}function wxt(l,_){const g=l.get(_.name);if(g){g.push(_);return}l.set(_.name,[_])}function Ext(l,_,g){for(const[S,D]of _.entries()){const F=D.length===1?D[0].query:{kind:"face-ref",faceName:S,owner:fp(g)},z=D.some(pe=>pe.semantic==="region")?"region":D.length>1?"set":D[0].semantic,ee=K2t(S,D.map(pe=>pe.face),F,z);Wu(l,ee);for(const pe of D){dP(l,pe.query);for(const we of pe.aliases)dP(l,we)}D.length>1&&dP(l,F)}}function yve(l,_){var g,S,D;if(!l)return Jk();switch(l.kind){case"queryOwner":return yve(l.base,_??l.owner);case"transform":{let F=yve(l.base,_);for(const z of l.steps)F=ixt(F,sxt(z));return F}case"box":return lxt(l,_);case"cylinder":return uxt(l,_);case"extrude":return pxt(l,_);case"sheetMetal":{const F=Jk();for(const z of F2t(l.model,l.output))Wu(F,{name:z.name,normal:km(z.normal),center:km(z.center),planar:z.planar,uAxis:z.uAxis?km(z.uAxis):void 0,vAxis:z.vAxis?km(z.vAxis):void 0,query:og(z.name,_),descendant:Oee(z.semantic,z.memberNames,z.coplanar)});return F}case"shell":{const F=XK($2(l.base));for(const[z,ee]of F.faces.entries()){const pe=EJ(l.queryPropagation,ee.query);pe&&G1e(F,z,pe,ee.query)}for(const z of IBe(l.base,l.openFaces)){const ee=z.slice(6),pe=F.faces.get(ee),we=V2(l.queryPropagation,z);!pe||!we||Wu(F,{...uN(pe),name:z,center:[pe.center[0]-pe.normal[0]*l.thickness,pe.center[1]-pe.normal[1]*l.thickness,pe.center[2]-pe.normal[2]*l.thickness],normal:[-pe.normal[0],-pe.normal[1],-pe.normal[2]],uAxis:pe.uAxis?km(pe.uAxis):void 0,vAxis:pe.vAxis?[-pe.vAxis[0],-pe.vAxis[1],-pe.vAxis[2]]:void 0,query:we})}return F}case"hole":{const F=XK($2(l.base));for(const[Bt,fr]of F.faces.entries()){const hn=EJ(l.queryPropagation,fr.query),vr=X1e(l.queryPropagation,hn);if(hn&&(vr==null?void 0:vr.kind)==="face-region"){AK(F,Bt,hn,"region",fr.query);continue}hn&&G1e(F,Bt,hn,fr.query)}for(const Bt of mee(l.base,l.placement.placement.workplane.source,l.extent)){const fr=F.faces.get(Bt.name);if(((g=fr==null?void 0:fr.descendant)==null?void 0:g.semantic)==="region")continue;const hn=fr?EJ(l.queryPropagation,fr.query):void 0;if(fr&&hn){AK(F,Bt.name,hn,"region",fr.query);continue}rje(F,Bt.name,nje("hole",Bt.reason))}const z=l.placement.placement.workplane,ee=z.origin,pe=[-z.normal[0],-z.normal[1],-z.normal[2]],we=wm(l.extent),De=ub(l.extent),te=V2(l.queryPropagation,"wall");if(te){const Bt=bxt(l.hole,l.extent);Wu(F,{name:"wall",normal:[-z.u[0],-z.u[1],-z.u[2]],center:[ee[0]+z.u[0]*l.hole.radius+pe[0]*Bt,ee[1]+z.u[1]*l.hole.radius+pe[1]*Bt,ee[2]+z.u[2]*l.hole.radius+pe[2]*Bt],planar:!1,query:te})}const nt=V2(l.queryPropagation,"counterbore-wall");nt&&l.hole.counterbore&&Wu(F,{name:"counterbore-wall",normal:[-z.u[0],-z.u[1],-z.u[2]],center:[ee[0]+z.u[0]*l.hole.counterbore.radius+pe[0]*(l.hole.counterbore.depth/2),ee[1]+z.u[1]*l.hole.counterbore.radius+pe[1]*(l.hole.counterbore.depth/2),ee[2]+z.u[2]*l.hole.counterbore.radius+pe[2]*(l.hole.counterbore.depth/2)],planar:!1,query:nt});const Te=V2(l.queryPropagation,"counterbore-floor");Te&&l.hole.counterbore&&Wu(F,{name:"counterbore-floor",normal:km(z.normal),center:[ee[0]+pe[0]*l.hole.counterbore.depth,ee[1]+pe[1]*l.hole.counterbore.depth,ee[2]+pe[2]*l.hole.counterbore.depth],planar:!0,uAxis:km(z.u),vAxis:km(z.v),query:Te});const Me=V2(l.queryPropagation,"countersink-wall");if(Me&&l.hole.countersink){const Bt=l.hole.countersink.depth/2,fr=(l.hole.radius+l.hole.countersink.radius)/2;Wu(F,{name:"countersink-wall",normal:[-z.u[0],-z.u[1],-z.u[2]],center:[ee[0]+z.u[0]*fr+pe[0]*Bt,ee[1]+z.u[1]*fr+pe[1]*Bt,ee[2]+z.u[2]*fr+pe[2]*Bt],planar:!1,query:Me})}const bt=V2(l.queryPropagation,"floor");bt&&Wu(F,{name:"floor",normal:km(z.normal),center:[ee[0]+pe[0]*we.depth,ee[1]+pe[1]*we.depth,ee[2]+pe[2]*we.depth],planar:!0,uAxis:km(z.u),vAxis:km(z.v),query:bt});const vt=V2(l.queryPropagation,"cap");return vt&&(De==null?void 0:De.kind)==="blind"&&Wu(F,{name:"cap",normal:[-z.normal[0],-z.normal[1],-z.normal[2]],center:[ee[0]-pe[0]*De.depth,ee[1]-pe[1]*De.depth,ee[2]-pe[2]*De.depth],planar:!0,uAxis:km(z.u),vAxis:[-z.v[0],-z.v[1],-z.v[2]],query:vt}),F}case"cut":{const F=XK($2(l.base));for(const[bt,vt]of F.faces.entries()){const Bt=EJ(l.queryPropagation,vt.query),fr=X1e(l.queryPropagation,Bt);if(Bt&&(fr==null?void 0:fr.kind)==="face-region"){AK(F,bt,Bt,"region",vt.query);continue}Bt&&G1e(F,bt,Bt,vt.query)}for(const bt of mee(l.base,l.placement.placement.workplane.source,l.extent)){const vt=F.faces.get(bt.name);if(((S=vt==null?void 0:vt.descendant)==null?void 0:S.semantic)==="region")continue;const Bt=vt?EJ(l.queryPropagation,vt.query):void 0;if(vt&&Bt){AK(F,bt.name,Bt,"region",vt.query);continue}rje(F,bt.name,nje("cut",bt.reason))}const z=l.placement.placement,ee=z.workplane.origin,pe=[-z.workplane.normal[0],-z.workplane.normal[1],-z.workplane.normal[2]],we=wm(l.extent),De=ub(l.extent),te=(De==null?void 0:De.depth)??0,nt=xxt(l.extent);if(l.profile.kind==="circle"){const bt=V2(l.queryPropagation,"wall");if(bt){const vt=l.profile.radius,Bt=l.taper?vt*l.taper.scale[0]:vt,fr=(vt+Bt)/2;Wu(F,{name:"wall",normal:[-z.workplane.u[0],-z.workplane.u[1],-z.workplane.u[2]],center:[ee[0]+z.workplane.u[0]*fr+pe[0]*nt,ee[1]+z.workplane.u[1]*fr+pe[1]*nt,ee[2]+z.workplane.u[2]*fr+pe[2]*nt],planar:!1,query:bt})}}if(l.profile.kind==="rect"||l.profile.kind==="roundedRect"){const bt=dee(l.profile.transforms),vt=l.profile.center?-l.profile.width/2:0,Bt=l.profile.center?-l.profile.height/2:0,fr=vt+l.profile.width,hn=Bt+l.profile.height,vr=jk(bt,vt,Bt),Xt=jk(bt,fr,Bt),Wt=jk(bt,fr,hn),Hn=jk(bt,vt,hn),zn=((D=l.taper)==null?void 0:D.scale)??[1,1],Fs=CJ(vr,zn),Jn=CJ(Xt,zn),oc=CJ(Wt,zn),ro=CJ(Hn,zn),Br=[{name:"wall-bottom",reverseStart:vr,reverseEnd:Xt,forwardStart:Fs,forwardEnd:Jn},{name:"wall-right",reverseStart:Xt,reverseEnd:Wt,forwardStart:Jn,forwardEnd:oc},{name:"wall-top",reverseStart:Wt,reverseEnd:Hn,forwardStart:oc,forwardEnd:ro},{name:"wall-left",reverseStart:Hn,reverseEnd:vr,forwardStart:ro,forwardEnd:Fs}];for(const pc of Br){const eo=V2(l.queryPropagation,pc.name);if(!eo)continue;const Gt=wJ(ee,z.workplane.u,z.workplane.v,pc.reverseStart[0],pc.reverseStart[1],pe,-te),fa=wJ(ee,z.workplane.u,z.workplane.v,pc.reverseEnd[0],pc.reverseEnd[1],pe,-te),Es=wJ(ee,z.workplane.u,z.workplane.v,pc.forwardStart[0],pc.forwardStart[1],pe,we.depth),Ho=wJ(ee,z.workplane.u,z.workplane.v,pc.forwardEnd[0],pc.forwardEnd[1],pe,we.depth),qi=$p([fa[0]-Gt[0],fa[1]-Gt[1],fa[2]-Gt[2]]),Yc=$p([Es[0]-Gt[0],Es[1]-Gt[1],Es[2]-Gt[2]]),Hp=$p(hve(qi,Yc));Wu(F,{name:pc.name,normal:Hp,center:axt([Gt,fa,Es,Ho]),planar:!0,uAxis:qi,vAxis:Yc,query:eo})}}const Te=V2(l.queryPropagation,"floor");if(Te){const bt=(()=>{if(l.profile.kind==="rect"||l.profile.kind==="roundedRect"){const vt=dee(l.profile.transforms),Bt=l.profile.center?-l.profile.width/2:0,fr=l.profile.center?-l.profile.height/2:0,hn=Bt+l.profile.width,vr=fr+l.profile.height,Xt=Qve(jk(vt,Bt,fr),jk(vt,hn,vr)),Wt=l.taper?CJ(Xt,l.taper.scale):Xt;return wJ(ee,z.workplane.u,z.workplane.v,Wt[0],Wt[1],pe,we.depth)}return[ee[0]+pe[0]*we.depth,ee[1]+pe[1]*we.depth,ee[2]+pe[2]*we.depth]})();Wu(F,{name:"floor",normal:km(z.workplane.normal),center:bt,planar:!0,uAxis:km(z.workplane.u),vAxis:km(z.workplane.v),query:Te})}const Me=V2(l.queryPropagation,"cap");return Me&&(De==null?void 0:De.kind)==="blind"&&Wu(F,{name:"cap",normal:[-z.workplane.normal[0],-z.workplane.normal[1],-z.workplane.normal[2]],center:[ee[0]-pe[0]*De.depth,ee[1]-pe[1]*De.depth,ee[2]-pe[2]*De.depth],planar:!0,uAxis:km(z.workplane.u),vAxis:[-z.workplane.v[0],-z.workplane.v[1],-z.workplane.v[2]],query:Me}),F}case"sphere":case"revolve":case"loft":case"sweep":case"hull":case"fillet":case"chamfer":return Jk();case"trimByPlane":{const F=Jk(),z=V2(l.queryPropagation,"plane-cap");if(!z)return F;const ee=$2(l.base),pe=Array.from(ee.faces.values()).map(Me=>Me.center),we=pe.length>0?pe.reduce((Me,bt)=>[Me[0]+bt[0],Me[1]+bt[1],Me[2]+bt[2]],[0,0,0]).map(Me=>Me/pe.length):[0,0,l.originOffset],De=$p([l.normalX,l.normalY,l.normalZ]),te=we[0]*De[0]+we[1]*De[1]+we[2]*De[2]-l.originOffset,nt=[we[0]-De[0]*te,we[1]-De[1]*te,we[2]-De[2]*te],Te=cxt(De);return Wu(F,{name:"plane-cap",normal:De,center:nt,planar:!0,uAxis:Te.u,vAxis:Te.v,query:z}),F}case"boolean":{const F=Jk(),z=l.shapes.map(we=>$2(we)),ee=l.queryPropagation;if(!ee)return F;const pe=new Map;for(const we of ee.preservedFaces){const De=Kl(we.query),te=Txt(z,we.query.source),nt=X1e(ee,De);if(we.status==="ambiguous"&&!nt){const Me=kxt(te),bt=Cxt(we.note,"This propagated boolean face lineage is ambiguous and is not part of the defended named-face subset.");for(const vt of te)QK(F,vt.face.query,bt);Me&&rxt(F,Me,bt),QK(F,we.query,bt),QK(F,we.query.kind==="propagated-face"?we.query.source:void 0,bt);continue}const Te=(nt==null?void 0:nt.kind)==="face-region"?"region":(nt==null?void 0:nt.kind)==="face-set"?"set":"face";for(const Me of te)wxt(pe,{name:Me.name,face:uN(Me.face),query:De,semantic:Te,aliases:[De,...we.query.kind==="propagated-face"?[we.query.source]:[],...Me.face.query?[Me.face.query]:[]].filter(bt=>bt!=null)})}return Ext(F,pe,ee.owner),F}}}function $2(l){return yve(l,Iee(l))}function Dxt(l){return Array.from($2(l).faces.keys()).sort()}function Pxt(l){const _=$2(l);return Array.from(_.faces.entries()).filter(([,g])=>g.query!=null).map(([g,S])=>({name:g,query:Kl(S.query)})).sort((g,S)=>g.name.localeCompare(S.name))}function sje(l,_){const S=$2(l).faces.get(_);return S?uN(S):null}function aje(l,_){const g=$2(l),S=g.blockedNames.get(_);if(S)return S;const D=Array.from(g.faces.keys()).sort();return`Face "${_}" is not available. Supported faces: ${D.join(", ")||"none"}`}function Axt(l,_){if(!_)return null;const g=$2(l);if(ABe(g.supportedQueries,_))return null;const S=jF(g,_);if(S.some(F=>g.faces.has(F)))return null;for(const F of S){const z=g.blockedNames.get(F);if(z)return z}const D=g.blockedQueries.find(F=>IS(F.query,_));return D?D.reason:_.kind==="created-face"||_.kind==="propagated-face"?"This face query is not part of the target shape's defended face subset.":S.length===0&&g.faces.size===0&&g.blockedQueries.length===0||_.kind==="tracked-face"||_.kind==="canonical-face"||_.kind==="face-ref"?null:"This face query is not part of the target shape's defended face subset."}function Nxt(l,_){return l?IBe(l,_).sort():[]}function Ixt(l,_){return mxt(l,_)}function Fxt(l,_,g){return FBe(l,_)}function Oxt(l,_){return gxt(l,_)}function Mxt(l,_,g){return hxt(l,_)}function Mee(l){return Pxt(l)}const Lxt=["front","back","left","right","top","bottom"];function Yve(l){if(!l)return null;switch(l.kind){case"queryOwner":case"transform":return Yve(l.base);case"shell":case"hole":case"cut":case"boolean":case"hull":case"trimByPlane":case"fillet":case"chamfer":return Rk(l.queryPropagation)??null;case"box":case"cylinder":case"sphere":case"extrude":case"sheetMetal":case"revolve":case"loft":case"sweep":return null}}function oje(l,_){const g=l.find(S=>IS(S.source,_.source));if(!g){l.push({source:Kl(_.source),status:_.status});return}_.status==="ambiguous"&&(g.status="ambiguous")}function cje(l,_){const g=l.find(S=>qk(S.source,_.source));if(!g){l.push({source:Tl(_.source),status:_.status});return}_.status==="ambiguous"&&(g.status="ambiguous")}function Rxt(l){return l?Lxt.map(_=>({source:{kind:"canonical-face",face:_,owner:fp(l)},status:"supported"})):[]}function jxt(l){const _=Yve(l);if(!_)return Rxt(Iee(l));const g=[];for(const S of _.preservedFaces)oje(g,{source:S.query,status:S.status});for(const S of _.createdFaces)oje(g,{source:S.query,status:"supported"});return g}function Bxt(l){const _=Yve(l);if(!_)return[];const g=[];for(const S of _.preservedEdges)cje(g,{source:S.query,status:S.status});for(const S of _.createdEdges)cje(g,{source:S.query,status:"supported"});return g}function Jxt(l){const _=[];for(const g of l){const S=_.find(D=>IS(D.source,g.source));if(S){S.count+=1,S.hasAmbiguousSource=S.hasAmbiguousSource||g.status==="ambiguous";continue}_.push({source:Kl(g.source),count:1,hasAmbiguousSource:g.status==="ambiguous"})}return _}function zxt(l){const _=[];for(const g of l){const S=_.find(D=>qk(D.source,g.source));if(S){S.count+=1,S.hasAmbiguousSource=S.hasAmbiguousSource||g.status==="ambiguous";continue}_.push({source:Tl(g.source),count:1,hasAmbiguousSource:g.status==="ambiguous"})}return _}function Zve(l,_){const g=_?l:l.slice(0,1);return Jxt(g.flatMap(S=>jxt(S)))}function Kve(l,_){const g=_?l:l.slice(0,1);return zxt(g.flatMap(S=>Bxt(S)))}function ebe(l,_){const g=_==="union"?"Boolean union preserved owner lineage, but none of its operands exposed defended face queries in the supported subset.":_==="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(em(`boolean-${_}-face-propagation-unsupported`,"unsupported","face",g))}function tbe(l,_){const g=_==="union"?"Boolean union preserved owner lineage, but none of its operands exposed defended edge queries in the supported subset.":_==="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(em(`boolean-${_}-edge-propagation-unsupported`,"unsupported","edge",g))}function qxt(l,_,g){const S=Zve(g,!0);if(S.length===0){ebe(_,"union");return}for(const D of S){if(D.count===1&&!D.hasAmbiguousSource){const z=P1(D.source,l,"preserved");_.preservedFaces.push({query:z,status:"supported"}),cg(_,A1("single",z,{source:D.source,note:"Boolean union keeps one defended single face descendant for this lineage."}));continue}const F=P1(D.source,l,D.count>1?"merged":"preserved");_.preservedFaces.push({query:F,status:"ambiguous"}),D.count>1&&!D.hasAmbiguousSource&&cg(_,A1("face-set",F,{source:D.source,note:"Boolean union keeps a defended descendant face set for this merged lineage."})),_.diagnostics.push(em(D.count>1?"boolean-union-face-merged-ambiguous":"boolean-union-face-inherited-ambiguity","ambiguous","face",D.count>1?`Boolean union cannot defend ${WJ(D.source)} because ${D.count} operand descendants share that face lineage and may merge.`:`Boolean union inherits ${WJ(D.source)} from an already-ambiguous rewrite result, so the post-union descendant remains ambiguous.`,D.source,F))}}function Wxt(l,_,g){const S=Kve(g,!0);if(S.length===0){tbe(_,"union");return}for(const D of S){if(D.count===1&&!D.hasAmbiguousSource){const z=GF(D.source,l,"preserved");_.preservedEdges.push({query:z,status:"supported"}),cg(_,$J("single",z,{source:D.source,note:"Boolean union keeps one defended single edge descendant for this lineage."}));continue}const F=GF(D.source,l,D.count>1?"merged":"preserved");_.preservedEdges.push({query:F,status:"ambiguous"}),_.diagnostics.push(em(D.count>1?"boolean-union-edge-merged-ambiguous":"boolean-union-edge-inherited-ambiguity","ambiguous","edge",D.count>1?`Boolean union cannot defend ${VJ(D.source)} because ${D.count} operand descendants share that edge lineage and may merge.`:`Boolean union inherits ${VJ(D.source)} from an already-ambiguous rewrite result, so the post-union descendant remains ambiguous.`,D.source,F))}}function Vxt(l,_,g){const S=Zve(g,!1);if(S.length===0){ebe(_,"difference");return}for(const D of S){const F=P1(D.source,l,"split");_.preservedFaces.push({query:F,status:"ambiguous"}),cg(_,A1("face-region",F,{source:D.source,note:"Boolean difference keeps a defended descendant region on the source surface."})),_.diagnostics.push(em("boolean-difference-face-split-ambiguous","ambiguous","face",`Boolean difference can trace ${WJ(D.source)} to the base operand, but subtractive cutters may split or erase its surviving descendants.`,D.source,F))}}function Uxt(l,_,g){const S=Kve(g,!1);if(S.length===0){tbe(_,"difference");return}for(const D of S){const F=GF(D.source,l,"split");_.preservedEdges.push({query:F,status:"ambiguous"}),_.diagnostics.push(em("boolean-difference-edge-split-ambiguous","ambiguous","edge",`Boolean difference can trace ${VJ(D.source)} to the base operand, but subtractive cutters may split or erase its surviving descendants.`,D.source,F))}}function $xt(l,_,g){const S=Zve(g,!0);if(S.length===0){ebe(_,"intersection");return}for(const D of S){const F=P1(D.source,l,"split");_.preservedFaces.push({query:F,status:"ambiguous"}),cg(_,A1("face-region",F,{source:D.source,note:"Boolean intersection keeps a defended descendant region on the source surface."})),_.diagnostics.push(em("boolean-intersection-face-split-ambiguous","ambiguous","face",`Boolean intersection can trace ${WJ(D.source)}, but the kept overlap is only a clipped descendant subset and cannot be defended as one stable face target.`,D.source,F))}}function Hxt(l,_,g){const S=Kve(g,!0);if(S.length===0){tbe(_,"intersection");return}for(const D of S){const F=GF(D.source,l,"split");_.preservedEdges.push({query:F,status:"ambiguous"}),_.diagnostics.push(em("boolean-intersection-edge-split-ambiguous","ambiguous","edge",`Boolean intersection can trace ${VJ(D.source)}, but the kept overlap is only a clipped descendant subset and cannot be defended as one stable edge target.`,D.source,F))}}function lP(l,_,g){const S=gN(`boolean:${l}`,_);switch(l){case"union":return qxt(_,S,g),Wxt(_,S,g),S;case"difference":return Vxt(_,S,g),Uxt(_,S,g),S;case"intersection":return $xt(_,S,g),Hxt(_,S,g),S}}function MBe(l,_){switch(_){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 Gxt(l,_,g){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 S=wm(g);return S.kind==="blind"?"Blind holes record the floor perimeter as a defended descendant edge chain.":S.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 S=ub(g);return(S==null?void 0:S.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 _.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 Xxt(l,_){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 g=wm(_);return g.kind==="blind"?"Blind cutouts record the floor perimeter as a defended descendant edge chain.":g.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 g=ub(_);return(g==null?void 0:g.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 LBe(l,_,g,S){const D=wm(S);D.kind==="upToFace"&&l.diagnostics.push(em(`${g}-up-to-face-target-split-ambiguous`,"ambiguous","face",`${g==="hole"?"Hole":"Cut"} upToFace intent records the selected termination face as an explicit split-face ambiguity instead of silently keeping it queryable.`,D.face,P1(D.face,_,"split")));const F=ub(S);(F==null?void 0:F.kind)==="upToFace"&&l.diagnostics.push(em(`${g}-reverse-up-to-face-target-split-ambiguous`,"ambiguous","face",`${g==="hole"?"Hole":"Cut"} reverse upToFace intent records the selected reverse termination face as an explicit split-face ambiguity instead of silently keeping it queryable.`,F.face,P1(F.face,_,"split")))}function Qxt(l,_,g){const S=gN("shell",l),D=Mee(_),F=Nxt(_,g);for(const z of D){const ee=P1(z.query,l,"preserved");S.preservedFaces.push({query:ee,status:"supported",note:"The outer shell face survives as a defended preserved-face query on the shelled result."}),cg(S,A1("single",ee,{source:z.query,note:"Shell keeps this face as one defended single descendant."}))}for(const z of F){const ee=Fee(l,"shell",z);S.createdFaces.push({query:ee,note:"This shell-created inner face is part of the defended named-face subset."}),cg(S,A1("single",ee,{note:"This shell-created face resolves to one defended descendant."}))}if(D.length===0&&F.length===0){const z=g.length>0?` Open faces: ${g.join(", ")}.`:"";S.diagnostics.push(em("shell-face-propagation-unsupported","unsupported","face",`Shell exact lowering is supported here, but compiler-owned face propagation is not defended for this shell base.${z}`))}return S.diagnostics.push(em("shell-edge-propagation-ambiguous","ambiguous","edge","Shell rewrites result edges, but durable edge-query propagation is not defended yet.")),S}function Yxt(l,_,g,S,D){const F=gN("hole",l),z=new Map(mee(_,g.workplane.source,D).map(ee=>[ee.name,ee.reason]));for(const ee of Mee(_)){const pe=z.get(ee.name);if(pe){const De=P1(ee.query,l,"split");F.preservedFaces.push({query:De,status:"ambiguous",note:MBe("hole",pe)}),cg(F,A1("face-region",De,{source:ee.query,note:"This rewritten hole face remains a defended descendant region on the same source surface."}));continue}const we=P1(ee.query,l,"preserved");F.preservedFaces.push({query:we,status:"supported",note:"This face stays queryable through the hole rewrite."}),cg(F,A1("single",we,{source:ee.query,note:"This hole descendant stays one defended face."}))}for(const ee of Ixt(S,D)){const pe=Fee(l,"hole",ee);F.createdFaces.push({query:pe,note:(()=>{switch(ee){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."}})()}),cg(F,A1("single",pe,{note:"This hole-created face resolves to one defended descendant."}))}for(const ee of Oxt(S,D)){const pe=PBe(l,"hole",ee);F.createdEdges.push({query:pe,note:Gxt(ee,S,D)}),cg(F,$J("edge-chain",pe,{note:"This hole-created edge query resolves to a defended descendant chain."}))}return F.diagnostics.push(em("hole-source-face-split-ambiguous","ambiguous","face","Hole intent records which rewritten host/exit faces are ambiguous instead of silently accepting them.",g.workplane.source,P1(g.workplane.source,l,"split"))),LBe(F,l,"hole",D),F}function Zxt(l,_,g,S,D,F){const z=gN("cut",l),ee=new Map(mee(_,g.workplane.source,D).map(we=>[we.name,we.reason]));for(const we of Mee(_)){const De=ee.get(we.name);if(De){const nt=P1(we.query,l,"split");z.preservedFaces.push({query:nt,status:"ambiguous",note:MBe("cut",De)}),cg(z,A1("face-region",nt,{source:we.query,note:"This rewritten cut face remains a defended descendant region on the same source surface."}));continue}const te=P1(we.query,l,"preserved");z.preservedFaces.push({query:te,status:"supported",note:"This face stays queryable through the cut rewrite."}),cg(z,A1("single",te,{source:we.query,note:"This cut descendant stays one defended face."}))}const pe=Fxt(S,D);for(const we of pe){const De=Fee(l,"cut",we);z.createdFaces.push({query:De,note:we==="floor"?"Blind cutouts create a defended planar floor face.":"This cut-created wall face is part of the defended named-face subset."}),cg(z,A1("single",De,{note:"This cut-created face resolves to one defended descendant."}))}for(const we of Mxt(S,D)){const De=PBe(l,"cut",we);z.createdEdges.push({query:De,note:Xxt(we,D)}),cg(z,$J("edge-chain",De,{note:"This cut-created edge query resolves to a defended descendant chain."}))}return z.diagnostics.push(em("cut-source-face-split-ambiguous","ambiguous","face","Cut intent records which rewritten host/exit faces are ambiguous instead of silently accepting them.",g.workplane.source,P1(g.workplane.source,l,"split"))),LBe(z,l,"cut",D),pe.length===0&&z.diagnostics.push(em("cut-created-face-subset-unsupported","unsupported","face","This cut profile does not fall inside the defended cut-created face subset yet.")),z}function RBe(l){const _=gN("hull",l);return _.diagnostics.push(em("hull-face-propagation-unsupported","unsupported","face","Hull combines source solids through a full topology rewrite, so face-query propagation is not defended yet."),em("hull-edge-propagation-unsupported","unsupported","edge","Hull combines source solids through a full topology rewrite, so edge-query propagation is not defended yet.")),_}function Q1e(l,_){const g=gN("trimByPlane",l);for(const D of Mee(_)){const F=P1(D.query,l,"split");g.preservedFaces.push({query:F,status:"ambiguous",note:"Trim keeps a clipped descendant region on the source surface instead of one untouched face."}),cg(g,A1("face-region",F,{source:D.query,note:"Trim keeps a defended descendant region on the source surface."}))}const S=Fee(l,"trimByPlane","plane-cap");return g.createdFaces.push({query:S,note:"The kept side of the trim introduces one deterministic cap face on the trim plane."}),cg(g,A1("single",S,{note:"The trim plane cap resolves to one defended descendant face."})),g.diagnostics.push(em("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."),em("trim-by-plane-edge-propagation-ambiguous","ambiguous","edge","Trim-by-plane boundary edge propagation is not defended yet.")),g}function Kxt(l,_,g,S=[]){const D=gN(l,_);for(const F of S){const z=GF(F,_,"preserved");D.preservedEdges.push({query:z,status:"supported",note:`${l} leaves this supported propagated vertical edge lineage unchanged in the defended post-rewrite subset.`}),cg(D,$J("single",z,{source:F,note:`${l} keeps this edge as one defended single descendant.`}))}if(g){const F=GF(g,_,"merged");D.preservedEdges.push({query:F,status:"ambiguous",note:`${l} rewrites the selected edge into a blended descendant set rather than one defended edge target.`}),cg(D,$J("edge-chain",F,{source:g,note:`${l} rewrites the selected edge into a defended descendant chain instead of one single edge target.`})),D.diagnostics.push(em(`${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.`,g,F))}return D.diagnostics.push(em(`${l}-created-face-propagation-unsupported`,"unsupported","face",`${l}-created face semantics are not part of the topology-rewrite kernel yet.`)),D}function eSt(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 tSt(l,_){return{...l,queryPropagation:Rk(_)}}function rbe(l,_){if(!l)return l;if(!eSt(l))throw new Error(`Cannot attach topology-rewrite propagation to non-rewrite plan kind "${l.kind}".`);return tSt(l,_)}function jBe(l,_){return kE(l,_)}function rSt(l,_){return`pattern:${l}:${_}`}const BBe=Symbol.for("forgecad.shapeBackend");var _Be;_Be=BBe;const Sm=class Sm{constructor(_){of(this,_Be,!0);this.manifold=_}clone(){return new Sm(this.manifold)}translate(_,g,S){return new Sm(this.manifold.translate(_,g,S))}rotate(_,g,S){return new Sm(this.manifold.rotate(_,g,S))}transform(_){return new Sm(this.manifold.transform(_))}scale(_){return new Sm(this.manifold.scale(_))}mirror(_){return new Sm(this.manifold.mirror(_))}smoothOut(_,g){return new Sm(this.manifold.smoothOut(_,g))}refine(_){return new Sm(this.manifold.refine(_))}refineToLength(_){return new Sm(this.manifold.refineToLength(_))}refineToTolerance(_){return new Sm(this.manifold.refineToTolerance(_))}warp(_){return new Sm(this.manifold.warp(_))}split(_){const[g,S]=this.manifold.split(gee(_,"ShapeBackend.split()"));return[new Sm(g),new Sm(S)]}splitByPlane(_,g){const[S,D]=this.manifold.splitByPlane(_,g);return[new Sm(S),new Sm(D)]}trimByPlane(_,g){return new Sm(this.manifold.trimByPlane(_,g))}hull(){return new Sm(this.manifold.hull())}simplify(_){return new Sm(this.manifold.simplify(_))}boundingBox(){return this.manifold.boundingBox()}volume(){return this.manifold.volume()}surfaceArea(){return this.manifold.surfaceArea()}minGap(_,g){return this.manifold.minGap(gee(_,"ShapeBackend.minGap()"),g)}isEmpty(){return this.manifold.isEmpty()}numTri(){return this.manifold.numTri()}getMesh(){return this.manifold.getMesh()}slice(_){return this.manifold.slice(_)}project(){return this.manifold.project()}requireManifold(){return this.manifold}};let vve=Sm;function nSt(l){return!!(l&&typeof l=="object"&&l[BBe]===!0)}function JBe(l){return new vve(l)}function gee(l,_="requireManifoldShapeBackend()"){try{return l.requireManifold(_)}catch(g){const S=g instanceof Error?g.message:String(g);throw new Error(`${_} currently requires a Manifold-backed runtime shape. ${S}`)}}function Y1e(l){switch(l.kind){case"through":case"blind":return{kind:l.kind,depth:l.depth};case"upToFace":return{kind:"upToFace",depth:l.depth,face:Kl(l.face)}}}function zBe(l){return l.kind==="two-sided"?{kind:"two-sided",forward:Y1e(l.forward),reverse:Y1e(l.reverse)}:Y1e(l)}function U2(l){return Number.isFinite(l)&&l>0}function qBe(l){return Math.max(.01,Math.min(.25,l*.01))}function IJ(l,_){return E1(l,{kind:"translate",x:0,y:0,z:_})}function WBe(l,_){const g=E1(l,{kind:"workplanePlacement",matrix:_.matrix,placement:_.placement});return g?{ok:!0,plan:g}:{ok:!1,reason:"Hole/cut features could not apply the selected workplane placement."}}function iSt(l,_,g,S){const D=wm(g),F=ZJ(g);if(!U2(F))return{ok:!1,reason:"Hole/cut features require a positive finite depth."};const z=qBe(F),ee=F+z*2,pe=(()=>{switch(l.kind){case"cylinder":return{kind:"cylinder",height:ee,radius:l.radius,center:!1};case"extrude":if(S&&(!U2(S.scale[0])||!U2(S.scale[1])))return null;const De=Cd(l.profile);if(!De)return null;const te=S?lb(De,{kind:"scale",x:S.scale[0],y:S.scale[1]}):De;return te?{kind:"extrude",profile:te,height:ee,center:!1,scaleTop:S?[1/S.scale[0],1/S.scale[1]]:void 0}:null;default:return null}})();if(!pe)return{ok:!1,reason:"Hole/cut feature lowerer expected an analytic cylinder or extruded profile cutter."};const we=IJ(pe,-(D.depth+z+_.placement.protrude));return we?WBe(we,_):{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."}}function sSt(l,_,g){if(!U2(l.radius))return{ok:!1,reason:"Shape.hole() requires a positive finite diameter."};const S=wm(g),D=ZJ(g);if(!U2(D))return{ok:!1,reason:"Hole/cut features require a positive finite depth."};const F=qBe(D),z=[],ee=IJ({kind:"cylinder",height:D+F*2,radius:l.radius,center:!1},-(S.depth+F+_.placement.protrude));if(!ee)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};if(z.push(ee),l.counterbore){if(!U2(l.counterbore.radius)||!U2(l.counterbore.depth))return{ok:!1,reason:"Shape.hole() counterbores require positive finite diameter and depth."};const we=IJ({kind:"cylinder",height:l.counterbore.depth+F,radius:l.counterbore.radius,center:!1},-(l.counterbore.depth+_.placement.protrude));if(!we)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};z.push(we)}if(l.countersink){if(!U2(l.countersink.radius)||!U2(l.countersink.depth))return{ok:!1,reason:"Shape.hole() countersinks require positive finite diameter and depth."};const we=IJ({kind:"cylinder",height:l.countersink.depth,radius:l.radius,radiusTop:l.countersink.radius,center:!1},-(l.countersink.depth+_.placement.protrude));if(!we)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};const De=IJ({kind:"cylinder",height:F,radius:l.countersink.radius,center:!1},-_.placement.protrude);if(!De)return{ok:!1,reason:"Hole/cut features could not translate the cutter into the selected workplane."};z.push(we,De)}const pe=z.length===1?z[0]:Sy("union",z);return pe?WBe(pe,_):{ok:!1,reason:"Hole/cut features could not combine the selected cutter components."}}function aSt(l,_,g,S){return!l||!_||!g||!U2(g.radius)||!U2(ZJ(S))?null:{kind:"hole",base:s_(l),placement:AS(_),hole:{radius:g.radius,counterbore:g.counterbore?{radius:g.counterbore.radius,depth:g.counterbore.depth}:void 0,countersink:g.countersink?{radius:g.countersink.radius,angleDeg:g.countersink.angleDeg,depth:g.countersink.depth}:void 0},extent:zBe(S)}}function oSt(l,_,g,S,D){return!l||!_||!g||!U2(ZJ(S))?null:{kind:"cut",base:s_(l),placement:AS(_),profile:Cd(g),extent:zBe(S),taper:D?{scale:[D.scale[0],D.scale[1]]}:void 0}}function cSt(l){const _=sSt(l.hole,l.placement,l.extent);return _.ok?{ok:!0,plan:Sy("difference",[l.base,_.plan])}:_}function lSt(l){const _=iSt({kind:"extrude",profile:l.profile,height:ZJ(l.extent)},l.placement,l.extent,l.taper);return _.ok?{ok:!0,plan:Sy("difference",[l.base,_.plan])}:_}function VBe(l){const _=[];for(const g of l??[]){if(g!=="top"&&g!=="bottom")throw new Error(`Shape.shell() only supports "top" and "bottom" openings, got "${g}"`);_.includes(g)||_.push(g)}return _}function uSt(l){return l.kind!=="scale"}function nbe(l,_,g,S){const D=S.includes("top"),F=S.includes("bottom"),z=_?-l/2+(F?0:g):F?0:g,ee=_?l/2-(D?0:g):l-(D?0:g),pe=ee-z;return pe>0?{height:pe,translateZ:_?(z+ee)/2:z}:null}function UBe(l,_){return Math.abs(_)<=1e-12?l:E1(l,{kind:"translate",x:0,y:0,z:_})}function _St(l,_,g,S){let D=l;return(Math.abs(_)>1e-12||Math.abs(g)>1e-12||Math.abs(S)>1e-12)&&(D=E1(D,{kind:"translate",x:_,y:g,z:S})),D}function fSt(l,_,g){const S=l.x-2*_,D=l.y-2*_;if(!(S>0)||!(D>0))return{ok:!1,reason:"Shape.shell() thickness is too large for this box base."};const F=nbe(l.z,l.center,_,g);if(!F)return{ok:!1,reason:"Shape.shell() thickness is too large for this box height and opening configuration."};const z=_St({kind:"box",x:S,y:D,z:F.height,center:l.center},l.center?0:_,l.center?0:_,F.translateZ);return{ok:!0,plan:Sy("difference",[l,z])}}function pSt(l,_,g){const S=l.radius-_,D=l.radiusTop==null?void 0:l.radiusTop-_;if(!(S>0)||D!=null&&!(D>0))return{ok:!1,reason:"Shape.shell() thickness is too large for this cylinder or cone base."};const F=nbe(l.height,l.center,_,g);if(!F)return{ok:!1,reason:"Shape.shell() thickness is too large for this cylinder height and opening configuration."};const z=UBe({kind:"cylinder",height:F.height,radius:S,radiusTop:D,center:l.center},F.translateZ);return{ok:!0,plan:Sy("difference",[l,z])}}function dSt(l,_,g){if(l.scaleTop)return{ok:!1,reason:"Shape.shell() v1 does not support tapered extrudes (`scaleTop`) yet."};const S=CBe(l.profile,-_,"Round");if(!S)return{ok:!1,reason:"Shape.shell() could not offset the source profile for this extrude base."};const D=nbe(l.height,l.center,_,g);if(!D)return{ok:!1,reason:"Shape.shell() thickness is too large for this extrude height and opening configuration."};const F=UBe({kind:"extrude",profile:S,height:D.height,center:l.center},D.translateZ);return{ok:!0,plan:Sy("difference",[l,F])}}function bve(l,_,g){switch(l.kind){case"queryOwner":{const S=bve(l.base,_,g);return S.ok?{ok:!0,plan:KJ(S.plan,l.owner)}:S}case"transform":{if(!l.steps.every(uSt))return{ok:!1,reason:"Shape.shell() v1 supports only rigid transforms before shelling. Scale transforms are not supported yet."};const S=bve(l.base,_,g);return S.ok?{ok:!0,plan:s_({kind:"transform",base:S.plan,steps:l.steps.map(D=>({...D}))})}:S}case"box":return fSt(l,_,g);case"cylinder":return pSt(l,_,g);case"extrude":return dSt(l,_,g);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 mSt(l,_,g=[]){if(!l||!Number.isFinite(_)||!(_>0))return null;const S={kind:"shell",base:s_(l),thickness:_,openFaces:VBe(g)};return $Be(S).ok?S:null}function $Be(l){return!Number.isFinite(l.thickness)||!(l.thickness>0)?{ok:!1,reason:"Shape.shell() requires a positive finite wall thickness."}:bve(l.base,l.thickness,VBe(l.openFaces))}function gSt(l,_,g){return Math.max(_,Math.min(g,l))}function lje(l,_){return[l[0]-_[0],l[1]-_[1],l[2]-_[2]]}function hSt(l,_){return[l[0]*_,l[1]*_,l[2]*_]}function LJ(l,_){return l[0]*_[0]+l[1]*_[1]+l[2]*_[2]}function Z1e(l,_){return[l[1]*_[2]-l[2]*_[1],l[2]*_[0]-l[0]*_[2],l[0]*_[1]-l[1]*_[0]]}function ibe(l){return Math.sqrt(LJ(l,l))}function IK(l){const _=ibe(l);return _<1e-9?[0,0,1]:[l[0]/_,l[1]/_,l[2]/_]}function ySt(l){let _=0;for(let g=0;g<l.length;g+=1){const[S,D]=l[g],[F,z]=l[(g+1)%l.length];_+=S*z-F*D}return _*.5}function vSt(l,_){let g=!1;const[S,D]=l;for(let F=0,z=_.length-1;F<_.length;z=F,F+=1){const[ee,pe]=_[F],[we,De]=_[z];pe>D!=De>D&&S<(we-ee)*(D-pe)/(De-pe+1e-20)+ee&&(g=!g)}return g}function bSt(l,_,g){const S=g[0]-_[0],D=g[1]-_[1],F=l[0]-_[0],z=l[1]-_[1],ee=S*S+D*D,pe=ee<1e-12?0:gSt((F*S+z*D)/ee,0,1),we=_[0]+S*pe,De=_[1]+D*pe,te=l[0]-we,nt=l[1]-De;return Math.sqrt(te*te+nt*nt)}function xSt(l,_){let g=1/0;for(let S=0;S<_.length;S+=1){const D=_[S],F=_[(S+1)%_.length];g=Math.min(g,bSt(l,D,F))}return vSt(l,_)?g:-g}function HBe(l){const _=l.filter(g=>Array.isArray(g)&&g.length>=3).map(g=>({pts:g.map(([S,D])=>[S,D]),area:ySt(g)}));return _.length===0?()=>-1:(g,S)=>{const D=[g,S];let F=-1/0;for(const z of _){const ee=xSt(D,z.pts);F=z.area>=0?Math.max(F,ee):Math.min(F,-ee)}return F}}function SSt(l,_){let g=IK(_);Math.abs(LJ(g,l))>.95&&(g=Math.abs(l[2])<.95?[0,0,1]:[0,1,0]);let S=IK(Z1e(g,l));if(ibe(S)<1e-8){const F=Math.abs(l[0])<.9?[1,0,0]:[0,1,0];S=IK(Z1e(F,l))}const D=IK(Z1e(l,S));return{x:S,y:D}}function GBe(l,_,g){if(l.length<2)throw new Error("loft requires at least two compileable profiles");if(l.length!==_.length)throw new Error("loft compile data requires heights.length === profiles.length");const S=l.map(nt=>HBe(nt)),D=_.map(nt=>nt);let F=1/0,z=1/0,ee=-1/0,pe=-1/0;for(const nt of l)for(const Te of nt)for(const[Me,bt]of Te)F=Math.min(F,Me),z=Math.min(z,bt),ee=Math.max(ee,Me),pe=Math.max(pe,bt);const we=D[0],De=D[D.length-1],te=g.boundsPadding;return{sdf:([nt,Te,Me])=>{let bt;if(Me<=we)bt=S[0](nt,Te);else if(Me>=De)bt=S[S.length-1](nt,Te);else{let Bt=0;for(;Bt+1<D.length&&Me>D[Bt+1];)Bt+=1;const fr=D[Bt],hn=D[Bt+1],vr=(Me-fr)/(hn-fr),Xt=S[Bt](nt,Te),Wt=S[Bt+1](nt,Te);bt=Xt*(1-vr)+Wt*vr}const vt=Math.min(Me-we,De-Me);return Math.min(bt,vt)},bounds:{min:[F-te,z-te,we-te],max:[ee+te,pe+te,De+te]},edgeLength:g.edgeLength}}function XBe(l,_,g){if(_.length<2)throw new Error("sweep requires a path with at least two points");const S=HBe(l),D=[];for(let Te=0;Te<_.length-1;Te+=1){const Me=_[Te],bt=_[Te+1],vt=lje(bt,Me),Bt=ibe(vt);if(Bt<1e-6)continue;const fr=hSt(vt,1/Bt),hn=SSt(fr,g.up);D.push({a:Me,t:fr,x:hn.x,y:hn.y,len:Bt})}if(D.length===0)throw new Error("sweep path has no non-zero segments");let F=0;for(const Te of l)for(const[Me,bt]of Te)F=Math.max(F,Math.abs(Me),Math.abs(bt));let z=1/0,ee=1/0,pe=1/0,we=-1/0,De=-1/0,te=-1/0;for(const[Te,Me,bt]of _)z=Math.min(z,Te),ee=Math.min(ee,Me),pe=Math.min(pe,bt),we=Math.max(we,Te),De=Math.max(De,Me),te=Math.max(te,bt);const nt=Math.max(g.boundsPadding,F);return{sdf:Te=>{let Me=-1/0;for(const bt of D){const vt=lje(Te,bt.a),Bt=LJ(vt,bt.t),fr=LJ(vt,bt.x),hn=LJ(vt,bt.y),vr=S(fr,hn),Xt=Math.min(Bt,bt.len-Bt);Me=Math.max(Me,Math.min(vr,Xt))}return Me},bounds:{min:[z-nt,ee-nt,pe-nt],max:[we+nt,De+nt,te+nt]},edgeLength:g.edgeLength}}function TSt(l,_){if(l.length<2)return l;if(_<=0)return[];const g=[0];for(let F=0;F<l.length;F++){const z=l[F],ee=l[(F+1)%l.length],pe=ee[0]-z[0],we=ee[1]-z[1],De=Math.sqrt(pe*pe+we*we);g.push(g[g.length-1]+De)}const S=g[g.length-1];if(S<1e-12)return Array.from({length:_},()=>[l[0][0],l[0][1]]);const D=[];for(let F=0;F<_;F++){const z=F/_*S;let ee=0,pe=g.length-1;for(;ee<pe;){const Te=ee+pe>>1;g[Te]<=z?ee=Te+1:pe=Te}const we=ee-1,De=(z-g[we])/(g[we+1]-g[we]),te=l[we%l.length],nt=l[(we+1)%l.length];D.push([te[0]+(nt[0]-te[0])*De,te[1]+(nt[1]-te[1])*De])}return D}function kSt(l,_,g){if(l.length<2)return null;const S=l[0].length;if(S===0)return null;for(let z=1;z<l.length;z++)if(l[z].length!==S)return null;const D=[];for(let z=0;z<S;z++){const ee=wSt(l.map(pe=>pe[z]),_,g);if(ee)D.push(ee);else{for(const pe of D)pe.delete();return null}}if(D.length===0)return null;if(D.length===1)return D[0];const F=g.Manifold.union(D);for(const z of D)z.delete();return F}function CSt(l){let _=0;for(let g=0;g<l.length;g++){const S=l[g],D=l[(g+1)%l.length];_+=S[0]*D[1]-D[0]*S[1]}return _*.5}function wSt(l,_,g){const S=l.map(bt=>CSt(bt)<0?[...bt].reverse():bt);let D=0;for(const bt of S)D=Math.max(D,bt.length);const F=Math.max(D,24),z=S.map((bt,vt)=>{const Bt=TSt(bt,F),fr=_[vt];return Bt.map(([hn,vr])=>[hn,vr,fr])}),ee=[],pe=[];for(const bt of z)for(const[vt,Bt,fr]of bt)ee.push(vt,Bt,fr);for(let bt=0;bt<z.length-1;bt++){const vt=bt*F,Bt=(bt+1)*F;for(let fr=0;fr<F;fr++){const hn=(fr+1)%F,vr=vt+fr,Xt=Bt+fr,Wt=Bt+hn,Hn=vt+hn;pe.push(vr,Hn,Wt),pe.push(vr,Wt,Xt)}}const we=z[0].map(([bt,vt])=>[bt,vt]),De=g.triangulate([we]);for(const bt of De){const[vt,Bt,fr]=Array.isArray(bt)?bt:[bt[0],bt[1],bt[2]];pe.push(vt,fr,Bt)}const te=z[z.length-1].map(([bt,vt])=>[bt,vt]),nt=g.triangulate([te]),Te=(z.length-1)*F;for(const bt of nt){const[vt,Bt,fr]=Array.isArray(bt)?bt:[bt[0],bt[1],bt[2]];pe.push(Te+vt,Te+Bt,Te+fr)}const Me=new g.Mesh({numProp:3,vertProperties:new Float32Array(ee),triVerts:new Uint32Array(pe)});try{return new g.Manifold(Me)}catch{return null}}const xve=1e-8;function QBe(l){return Math.hypot(l[0],l[1],l[2])}function YBe(l){const _=QBe(l);if(_<xve)throw new Error("Plane normal must be non-zero");return[l[0]/_,l[1]/_,l[2]/_]}function ESt(l){if("origin"in l)return{origin:[l.origin[0],l.origin[1],l.origin[2]],normal:YBe(l.normal)};const _=l.offset??0;return l.plane==="XY"?{origin:[0,0,_],normal:[0,0,1]}:l.plane==="XZ"?{origin:[0,_,0],normal:[0,1,0]}:{origin:[_,0,0],normal:[1,0,0]}}function ZBe(l){const _=YBe(l),g=_[2];if(g>1-xve)return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];let S,D;if(g<-1+xve)S=[1,0,0],D=Math.PI;else{S=[_[1],-_[0],0];const vr=QBe(S);S=[S[0]/vr,S[1]/vr,S[2]/vr],D=Math.acos(g)}const[F,z,ee]=S,pe=Math.cos(D),we=Math.sin(D),De=1-pe,te=pe+F*F*De,nt=F*z*De-ee*we,Te=F*ee*De+z*we,Me=z*F*De+ee*we,bt=pe+z*z*De,vt=z*ee*De-F*we,Bt=ee*F*De-z*we,fr=ee*z*De+F*we,hn=pe+ee*ee*De;return[te,Me,Bt,0,nt,bt,fr,0,Te,vt,hn,0,0,0,0,1]}function KBe(l){const{origin:_,normal:g}=ESt(l),S=Sa.from(ZBe(g)).inverse();return{origin:_,u:S.vector([1,0,0]),v:S.vector([0,1,0]),normal:g}}function eJe(l){const _=ZBe(l.normal);return Sa.translation(-l.origin[0],-l.origin[1],-l.origin[2]).mul(_).toArray()}const sbe=1e-8,tJe=["vert-bl","vert-br","vert-tr","vert-tl"];function DSt(l,_){return[(l[0]+_[0])*.5,(l[1]+_[1])*.5,(l[2]+_[2])*.5]}function RJ(l){const _=Math.hypot(l[0],l[1],l[2]);if(_<=sbe)throw new Error("Edge feature selection requires a non-zero direction vector");return[l[0]/_,l[1]/_,l[2]/_]}function PSt(l,_){return[l[0]-_[0],l[1]-_[1],l[2]-_[2]]}function xp(l,_){return{ok:!1,issue:{code:l,reason:_}}}function ez(l,_){return{ok:!0,selection:l,query:Tl(_)}}function ASt(l){return tJe.includes(l)}function abe(l){switch(l.kind){case"boolean":return`boolean ${l.op}`;case"trimByPlane":return"trimByPlane";default:return l.kind}}function FK(l,_){return{base:l.base,steps:[...l.steps,_]}}function NSt(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 ${abe(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 uje(l,_,g){var ee;const S=((ee=l.queryPropagation)==null?void 0:ee.diagnostics.filter(pe=>pe.queryKind==="edge"))??[],D=S.find(pe=>qk(pe.source,_)&&(g==null||qk(pe.query,g)));if(D!=null&&D.message)return D.message;const F=S.find(pe=>qk(pe.source,_));if(F!=null&&F.message)return F.message;const z=S.find(pe=>pe.source==null&&pe.query==null);return(z==null?void 0:z.message)??null}function rJe(l,_){var g;if(_)return(g=l.queryPropagation)==null?void 0:g.descendants.find(S=>S.queryKind==="edge"&&qk(S.query,_))}function ISt(l){switch(l.kind){case"translate":return Sa.translation(l.x,l.y,l.z);case"rotate":return Sa.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg);case"rotateAround":return Sa.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]);case"mirror":{const[_,g,S]=[l.normalX,l.normalY,l.normalZ],D=Math.hypot(_,g,S);if(D<=sbe)return Sa.identity();const F=_/D,z=g/D,ee=S/D;return Sa.from([1-2*F*F,-2*z*F,-2*ee*F,0,-2*F*z,1-2*z*z,-2*ee*z,0,-2*F*ee,-2*z*ee,1-2*ee*ee,0,0,0,0,1])}case"workplanePlacement":return Sa.from(l.matrix);case"scale":return null}}function nJe(l,_){let g=l;for(const S of _){const D=ISt(S);if(!D)return{issue:{code:"unsupported-edge-transform",reason:"Edge finishing currently supports only rigid transforms between the tracked source edge and the target body."}};g=g.mul(D)}return{transform:g}}function FF(l,_){var g,S;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 cb(l.owner,_)?{match:{base:l.base,steps:[]}}:FF(l.base,_);case"transform":{const D=FF(l.base,_);return D.match?{match:FK(D.match,{kind:"transform",steps:l.steps})}:D}case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":{const D=FF(l.base,_);return D.match?{match:FK(D.match,{kind:"rewrite",plan:l})}:D}case"boolean":{for(const D of l.shapes){const F=FF(D,_);if(F.match)return{match:FK(F.match,{kind:"rewrite",plan:l})};if(((g=F.issue)==null?void 0:g.code)==="unsupported-edge-transform")return F}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 D of l.shapes){const F=FF(D,_);if(F.match)return{match:FK(F.match,{kind:"rewrite",plan:l})};if(((S=F.issue)==null?void 0:S.code)==="unsupported-edge-transform")return F}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 iJe(l,_){const g=nJe(Sa.identity(),_);return g.transform?ez(cJe(l.selection,g.transform),l.query):xp(g.issue.code,g.issue.reason)}function FSt(l,_){switch(_.kind){case"tracked-edge":return OSt(l,_);case"propagated-edge":return MSt(l,_);case"created-edge":return xp("unsupported-edge-query-kind","Edge finishing does not yet support created-edge queries from topology rewrites.");case"edge-ref":return xp("unsupported-edge-query-kind","Edge finishing v1 supports tracked/propagated compiler-owned edge queries only, not direct edge refs.")}}function OSt(l,_){const g=Sve(l,_.edgeName);return g.ok?ez(g.selection,_):g}function sJe(l,_){switch(l.kind){case"fillet":case"chamfer":case"shell":case"hole":case"cut":case"trimByPlane":return _N(l.base,_);case"boolean":case"hull":{let g=null;for(const S of l.shapes){const D=_N(S,_);if(D.ok)return D;D.issue.code!=="edge-owner-not-found"&&D.issue.code!=="edge-query-propagation-mismatch"&&(g??(g=D.issue))}return g?xp(g.code,g.reason):xp("edge-query-propagation-mismatch","The selected propagated edge query does not match the target shape's recorded rewrite propagation contract.")}}}function aJe(l,_){var S;const g=(S=l.queryPropagation)==null?void 0:S.preservedEdges.find(D=>qk(D.query.source,_.query));return g?g.status!=="supported"||g.query.outcome!=="preserved"?xp("edge-query-ambiguous-after-rewrite",uje(l,_.query,g.query)??g.note??`The selected edge query is recorded as ${g.status} after ${abe(l)} and does not resolve to one defended edge target.`):ez(_.selection,g.query):xp("edge-query-unsupported-after-rewrite",uje(l,_.query)??NSt(l))}function MSt(l,_){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 xp("edge-query-propagation-mismatch","The selected propagated edge query does not point at a topology-rewrite result on this target shape.");const g=l.queryPropagation;if(!g||g.rewriteId!==_.rewriteId)return xp("edge-query-propagation-mismatch","The selected propagated edge query does not match the target shape's recorded rewrite propagation contract.");if(!g.preservedEdges.find(z=>qk(z.query,_)))return xp("edge-query-propagation-mismatch",`The selected propagated edge query is not part of the recorded ${abe(l)} propagation subset for this target shape.`);const D=sJe(l,_.source);if(!D.ok)return D;const F=aJe(l,{selection:D.selection,query:D.query});return F.ok?qk(F.query,_)?F:xp("edge-query-propagation-mismatch","The selected propagated edge query does not match the target shape's recorded rewrite propagation contract."):F}function LSt(l,_){let g=ez(l.selection,l.query);for(const S of _){if(!g.ok)return g;g=S.kind==="transform"?iJe({selection:g.selection,query:g.query},S.steps):aJe(S.plan,{selection:g.selection,query:g.query})}return g}function oJe(l){if(!l)return null;switch(l.kind){case"tracked-edge":return l.selector!=="edge"||!l.owner||!ASt(l.edgeName)?null:{owner:fp(l.owner),edgeName:l.edgeName};case"propagated-edge":return oJe(l.source);case"created-edge":case"edge-ref":return null}}function RSt(l,_){const g=l.center?-l.x/2:0,S=l.center?-l.y/2:0,D=l.center?-l.z/2:0,F=g+l.x,z=S+l.y,ee=D+l.z,pe=(()=>{switch(_){case"vert-bl":return{point:[g,S,D],quadrant:[1,-1]};case"vert-br":return{point:[F,S,D],quadrant:[-1,-1]};case"vert-tr":return{point:[F,z,D],quadrant:[-1,1]};case"vert-tl":return{point:[g,z,D],quadrant:[1,1]};default:return null}})();return pe?{ok:!0,selection:{kind:"line-segment",edgeName:_,start:[pe.point[0],pe.point[1],D],end:[pe.point[0],pe.point[1],ee],midpoint:[pe.point[0],pe.point[1],(D+ee)*.5],axis:[0,0,1],basisX:[1,0,0],basisY:[0,-1,0],quadrant:pe.quadrant}}:xp("unsupported-edge-name",`Edge finishing v1 currently supports only tracked vertical rectangle/box edges (${["vert-bl","vert-br","vert-tr","vert-tl"].join(", ")}).`)}function jSt(l){if(l.length!==4)return!1;const _=l.map((we,De)=>{const te=l[(De+1)%l.length];return[te[0]-we[0],te[1]-we[1]]}),g=_.map(([we,De])=>Math.hypot(we,De));if(g.some(we=>we<=sbe))return!1;const S=_[0][0]*_[1][0]+_[0][1]*_[1][1],D=_[1][0]*_[2][0]+_[1][1]*_[2][1],F=_[2][0]*_[3][0]+_[2][1]*_[3][1],z=_[3][0]*_[0][0]+_[3][1]*_[0][1],ee=_[0][0]*_[2][1]-_[0][1]*_[2][0],pe=_[1][0]*_[3][1]-_[1][1]*_[3][0];return Math.abs(S)<=1e-6*Math.max(1,g[0]*g[1])&&Math.abs(D)<=1e-6*Math.max(1,g[1]*g[2])&&Math.abs(F)<=1e-6*Math.max(1,g[2]*g[3])&&Math.abs(z)<=1e-6*Math.max(1,g[3]*g[0])&&Math.abs(ee)<=1e-6*Math.max(1,g[0]*g[2])&&Math.abs(pe)<=1e-6*Math.max(1,g[1]*g[3])}function BSt(l,_){if(l.scaleTop)return xp("unsupported-edge-base","Edge finishing v1 does not support tapered extrudes (`scaleTop`) yet.");if(l.center)return xp("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"||!jSt(l.profile.points))return xp("unsupported-edge-profile","Edge finishing v1 currently supports tracked rectangle extrusions only; generic sketch extrudes are outside the supported subset.");const g=(()=>{switch(_){case"vert-bl":return 0;case"vert-br":return 1;case"vert-tr":return 2;case"vert-tl":return 3;default:return-1}})();if(g<0)return xp("unsupported-edge-name",`Edge finishing v1 currently supports only tracked vertical rectangle/box edges (${["vert-bl","vert-br","vert-tr","vert-tl"].join(", ")}).`);const S=l.profile.points,[D,F,z,ee]=S,pe=RJ([F[0]-D[0],F[1]-D[1],0]),we=RJ([ee[0]-D[0],ee[1]-D[1],0]),De=S[g],te=g===0?[1,-1]:g===1?[-1,-1]:g===2?[-1,1]:[1,1];return{ok:!0,selection:{kind:"line-segment",edgeName:_,start:[De[0],De[1],0],end:[De[0],De[1],l.height],midpoint:[De[0],De[1],l.height*.5],axis:[0,0,1],basisX:[pe[0],pe[1],pe[2]],basisY:[-we[0],-we[1],-we[2]],quadrant:te}}}function cJe(l,_){const g=_.point(l.start),S=_.point(l.end),D=RJ(_.vector(l.basisX)),F=RJ(_.vector(l.basisY)),z=RJ(PSt(S,g));return{kind:"line-segment",edgeName:l.edgeName,start:g,end:S,midpoint:DSt(g,S),axis:z,basisX:D,basisY:F,quadrant:[l.quadrant[0],l.quadrant[1]]}}function Sve(l,_){switch(l.kind){case"transform":{const g=Sve(l.base,_);if(!g.ok)return g;const S=nJe(Sa.identity(),l.steps);return S.transform?{ok:!0,selection:cJe(g.selection,S.transform)}:xp(S.issue.code,S.issue.reason)}case"box":return RSt(l,_);case"extrude":return BSt(l,_);case"queryOwner":return Sve(l.base,_);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 xp("unsupported-edge-base","Edge finishing v1 currently supports tracked vertical edges from compile-covered box() bodies and rectangle extrusions before topology-changing edits.")}}function _N(l,_){const g=qSt(l,_);return g.kind==="single"?ez(g.selection,g.query):g.kind==="edge-chain"?xp("edge-query-ambiguous-after-rewrite",g.note??"The selected edge resolves to a defended descendant chain, not one single edge target."):g.query==null&&_==null?xp("missing-edge-query",g.reason):g.query==null&&(_!=null&&_.selector)&&_.selector!=="edge"||g.reason.includes("selector")?xp("unsupported-edge-selector",g.reason):g.reason.includes("owner")?xp("edge-owner-not-found",g.reason):xp("edge-query-unsupported-after-rewrite",g.reason)}function JSt(l,_){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:Tl(_),reason:"The selected propagated edge query does not point at a topology-rewrite result on this target shape."};const g=rJe(l,_);if(!g||g.kind!=="edge-chain")return{kind:"unsupported",query:Tl(_),reason:"This target shape does not record a defended descendant edge chain for the selected query."};const S=sJe(l,_.source);return S.ok?{kind:"edge-chain",semantic:"chain",query:Tl(_),selection:S.selection,note:g.note}:{kind:"unsupported",query:Tl(_),reason:S.issue.reason,note:g.note}}function zSt(l,_){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:Tl(_),reason:"The selected created-edge query does not point at a topology-rewrite result on this target shape."};const g=rJe(l,_);return!g||g.kind!=="edge-chain"?{kind:"unsupported",query:Tl(_),reason:"This target shape does not record a defended descendant edge chain for the selected created-edge query."}:{kind:"edge-chain",semantic:"chain",query:Tl(_),note:g.note}}function qSt(l,_){var D;if(!_)return{kind:"unsupported",reason:"Edge finishing currently requires a tracked edge query from a compile-covered target body."};if(_.selector!=="edge")return{kind:"unsupported",query:Tl(_),reason:"Edge finishing v1 currently supports whole-edge selections only; use shape.edge(name), not .start/.end/.midpoint selectors."};if(_.kind==="edge-ref")return{kind:"unsupported",query:Tl(_),reason:"Edge finishing v1 supports compiler-owned tracked-edge, propagated-edge, and inspectable created-edge queries only, not direct edge refs."};if(!_.owner)return{kind:"unsupported",query:Tl(_),reason:"Edge finishing currently requires a tracked edge query with a compiler-owned parent body owner."};const g=FF(l,_.owner);if(!g.match)return{kind:"unsupported",query:Tl(_),reason:((D=g.issue)==null?void 0:D.reason)??"The selected tracked edge is not owned by this target shape or any preserved query ancestor."};if(_.kind==="created-edge"){const F=zSt(g.match.base,_);if(F.kind==="unsupported")return F;for(const z of g.match.steps)if(z.kind==="rewrite")return{kind:"unsupported",query:Tl(_),reason:"Later topology rewrites do not yet preserve this defended created-edge chain as a new downstream chain contract.",note:F.note};return F}const S=FSt(g.match.base,_);if(S.ok){const F=LSt({selection:S.selection,query:S.query},g.match.steps);return F.ok?{kind:"single",semantic:"edge",query:F.query,selection:F.selection}:{kind:"unsupported",query:Tl(_),reason:F.issue.reason}}if(_.kind==="propagated-edge"){const F=JSt(g.match.base,_);if(F.kind!=="unsupported"){let z=F;for(const ee of g.match.steps){if(ee.kind==="transform"){if(!z.selection)continue;const pe=iJe({selection:z.selection,query:z.query},ee.steps);if(!pe.ok)return{kind:"unsupported",query:Tl(_),reason:pe.issue.reason,note:z.note};z={...z,selection:pe.selection,query:pe.query};continue}return{kind:"unsupported",query:Tl(_),reason:"Later topology rewrites do not yet preserve this defended edge chain as a new downstream chain contract.",note:z.note}}return z}}return{kind:"unsupported",query:Tl(_),reason:S.issue.reason}}function lJe(l,_){if(!l)return[];const g=oJe(_);if(!g)return[];const S=[];for(const D of tJe){if(D===g.edgeName)continue;const F={kind:"tracked-edge",edgeName:D,selector:"edge",owner:fp(g.owner)},z=_N(l,F);z.ok&&S.push(z.query)}return S}const hee=.01;function uJe(l,_=0){const g=[l.start[0]+l.axis[0]*_,l.start[1]+l.axis[1]*_,l.start[2]+l.axis[2]*_];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,g[0],g[1],g[2],1]}function _Je(l){const _=l.end[0]-l.start[0],g=l.end[1]-l.start[1],S=l.end[2]-l.start[2];return Math.hypot(_,g,S)}function WSt(l,_,g,S,D){const F=_Je(_);if(!(F>1e-6))return l;const[z,ee]=_.quadrant,pe=F+hee*2,we=uJe(_,-hee),De=D.CrossSection.square([g,g],!1).translate(z>0?0:-g,ee>0?0:-g).extrude(pe,0,0,void 0,!1).transform(we),te=D.CrossSection.circle(g,Math.max(3,S)).extrude(pe,0,0,void 0,!1).transform(we);return D.Manifold.union([D.Manifold.difference([l,De]),te])}function VSt(l,_,g,S){const D=_Je(_);if(!(D>1e-6))return l;const[F,z]=_.quadrant,ee=D+hee*2,pe=uJe(_,-hee),De=new S.CrossSection([[[0,0],[F*g,0],[0,z*g]]]).extrude(ee,0,0,void 0,!1).transform(pe);return S.Manifold.difference([l,De])}function USt(l,_){switch(_.kind){case"translate":return l.translate(_.x,_.y);case"rotate":return l.rotate(_.degrees);case"scale":return l.scale([_.x,_.y]);case"mirror":return l.mirror([_.normalX,_.normalY])}}function Bk(l,_){let g=l;for(const S of _)g=USt(g,S);return g}function $St(l,_){const g=l.profiles.map(D=>mP(D,_));if(g.length===0)throw new Error(`Cannot lower empty profile boolean (${l.op})`);if(g.length===1)return Bk(g[0],l.transforms);const S=(()=>{switch(l.op){case"union":return _.CrossSection.union(g);case"difference":return _.CrossSection.difference(g);case"intersection":return _.CrossSection.intersection(g)}})();return Bk(S,l.transforms)}function HSt(l,_){const g=l.profiles.map(S=>mP(S,_));if(g.length===0)throw new Error("Cannot lower empty profile hull");return g.length===1?Bk(g[0],l.transforms):Bk(_.CrossSection.hull(g),l.transforms)}function mP(l,_){switch(l.kind){case"rect":return Bk(_.CrossSection.square([l.width,l.height],l.center),l.transforms);case"roundedRect":{const g=Math.min(l.radius,l.width/2,l.height/2),S=_.CrossSection.square([l.width-2*g,l.height-2*g],!0).translate(l.center?0:l.width/2,l.center?0:l.height/2).offset(g,"Round");return Bk(S,l.transforms)}case"circle":return Bk(_.CrossSection.circle(l.radius,l.segments??0),l.transforms);case"polygon":return Bk(new _.CrossSection([l.points]),l.transforms);case"boolean":return $St(l,_);case"offset":return Bk(mP(l.base,_).offset(l.delta,l.join),l.transforms);case"hull":return HSt(l,_);case"project":{const g=ab(l.sourceShape,_).transform(eJe(l.plane)).project();return Bk(g,l.transforms)}}}function GSt(l,_){switch(_.kind){case"translate":return l.translate(_.x,_.y,_.z);case"rotate":return l.rotate(_.xDeg,_.yDeg,_.zDeg);case"scale":return l.scale([_.x,_.y,_.z]);case"rotateAround":return l.transform(Sa.rotationAxis([_.axisX,_.axisY,_.axisZ],_.degrees,[_.pivotX,_.pivotY,_.pivotZ]).toArray());case"mirror":return l.mirror([_.normalX,_.normalY,_.normalZ]);case"workplanePlacement":return l.transform(_.matrix)}}function XSt(l,_){let g=l;for(const S of _)g=GSt(g,S);return g}function QSt(l,_){const g=l.shapes.map(S=>ab(S,_));if(g.length===0)throw new Error(`Cannot lower empty shape boolean (${l.op})`);if(g.length===1)return g[0];switch(l.op){case"union":return _.Manifold.union(g);case"difference":return _.Manifold.difference(g);case"intersection":return _.Manifold.intersection(g)}}function YSt(l,_){const S=[...l.shapes.map(D=>ab(D,_)),...l.points.map(([D,F,z])=>[D,F,z])];if(S.length===0)throw new Error("Cannot lower empty shape hull");return _.Manifold.hull(S)}function ZSt(l,_){return ab(l.base,_).trimByPlane([l.normalX,l.normalY,l.normalZ],l.originOffset)}function KSt(l,_){const g=l.profiles.map(F=>mP(F,_).toPolygons());if(g.length>=2&&g.every(F=>F.length===1)){const F=kSt(g,l.heights,_);if(F)return F}const D=GBe(g,l.heights,{edgeLength:l.edgeLength,boundsPadding:l.boundsPadding});return _.Manifold.levelSet(D.sdf,D.bounds,D.edgeLength,0)}function eTt(l,_){const g=XBe(mP(l.profile,_).toPolygons(),l.path.points.map(([S,D,F])=>[S,D,F]),{edgeLength:l.edgeLength,boundsPadding:l.boundsPadding,up:[l.up[0],l.up[1],l.up[2]]});return _.Manifold.levelSet(g.sdf,g.bounds,g.edgeLength,0)}function tTt(l,_){const g=_N(l.base,l.edge);if(!g.ok)throw new Error(g.issue.reason);if(g.selection.quadrant[0]!==l.quadrant[0]||g.selection.quadrant[1]!==l.quadrant[1])throw new Error(`filletEdge() currently supports ${g.selection.edgeName} only with quadrant [${g.selection.quadrant[0]}, ${g.selection.quadrant[1]}].`);return WSt(ab(l.base,_),g.selection,l.radius,l.segments,_)}function rTt(l,_){const g=_N(l.base,l.edge);if(!g.ok)throw new Error(g.issue.reason);if(g.selection.quadrant[0]!==l.quadrant[0]||g.selection.quadrant[1]!==l.quadrant[1])throw new Error(`chamferEdge() currently supports ${g.selection.edgeName} only with quadrant [${g.selection.quadrant[0]}, ${g.selection.quadrant[1]}].`);return VSt(ab(l.base,_),g.selection,l.size,_)}function ab(l,_){switch(l.kind){case"box":return _.Manifold.cube([l.x,l.y,l.z],l.center);case"cylinder":return _.Manifold.cylinder(l.height,l.radius,l.radiusTop??-1,l.segments??0,l.center);case"sphere":return _.Manifold.sphere(l.radius,l.segments??0);case"extrude":return mP(l.profile,_).extrude(l.height,0,0,l.scaleTop,l.center);case"sheetMetal":return ab(N2t(l.model,l.output),_);case"shell":{const g=$Be(l);if(!g.ok)throw new Error(g.reason);return ab(g.plan,_)}case"hole":{const g=cSt(l);if(!g.ok)throw new Error(g.reason);return ab(g.plan,_)}case"cut":{const g=lSt(l);if(!g.ok)throw new Error(g.reason);return ab(g.plan,_)}case"revolve":return mP(l.profile,_).revolve(l.segments??0,l.degrees);case"loft":return KSt(l,_);case"sweep":return eTt(l,_);case"boolean":return QSt(l,_);case"transform":return XSt(ab(l.base,_),l.steps);case"queryOwner":return ab(l.base,_);case"fillet":return tTt(l,_);case"chamfer":return rTt(l,_);case"hull":return YSt(l,_);case"trimByPlane":return ZSt(l,_)}}function nTt(l,_){return JBe(ab(l,_))}function fJe(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 FJ(l){if(!l)return[];const _=[];switch(l.kind){case"transform":_.push(...FJ(l.base)),_.push(...l.steps.map(fJe));break;case"queryOwner":_.push(...FJ(l.base));break;case"boolean":l.shapes.length>0&&_.push(...FJ(l.shapes[0]));break;case"shell":case"hole":case"cut":case"fillet":case"chamfer":case"trimByPlane":_.push(...FJ(l.base));break}return _}function Tve(l){if(!l)return{operation:"unknown"};switch(l.kind){case"queryOwner":return{operation:l.owner.operation,owner:l.owner};case"transform":return Tve(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 Tve(l.base);default:return{operation:l.kind}}}function K1e(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 Mk(l,_){switch(l.kind){case"queryOwner":Mk(l.base,_);return;case"transform":Mk(l.base,_);for(const g of l.steps){const S=fJe(g),D=g.kind==="translate"?"Move":g.kind==="rotate"?"Rotate":g.kind==="rotateAround"?"Rotate Around":g.kind==="scale"?"Scale":g.kind==="mirror"?"Mirror":"Place on Workplane";_.push({kind:g.kind,label:D,summary:S.description,category:"transform"})}return;case"shell":Mk(l.base,_),_.push({kind:"shell",label:"Shell",summary:`t = ${l.thickness}`,category:"modifier"});return;case"hole":Mk(l.base,_),_.push({kind:"hole",label:"Hole",summary:`r = ${l.hole.radius}`,category:"modifier"});return;case"cut":Mk(l.base,_),_.push({kind:"cut",label:"Cut",summary:K1e(l.profile),category:"modifier"});return;case"fillet":Mk(l.base,_),_.push({kind:"fillet",label:"Fillet",summary:`r = ${l.radius}`,category:"modifier"});return;case"chamfer":Mk(l.base,_),_.push({kind:"chamfer",label:"Chamfer",summary:`size = ${l.size}`,category:"modifier"});return;case"trimByPlane":Mk(l.base,_),_.push({kind:"trimByPlane",label:"Trim by Plane",summary:`normal [${l.normalX}, ${l.normalY}, ${l.normalZ}]`,category:"modifier"});return;case"boolean":l.shapes.length>0&&Mk(l.shapes[0],_),_.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":_.push({kind:"hull",label:"Hull",summary:`${l.shapes.length} shapes`,category:"boolean"});return;case"extrude":_.push({kind:"extrude",label:"Extrude",summary:`${K1e(l.profile)}, h = ${l.height}`,category:"sketch"});return;case"revolve":_.push({kind:"revolve",label:"Revolve",summary:`${l.degrees}°`,category:"sketch"});return;case"loft":_.push({kind:"loft",label:"Loft",summary:`${l.profiles.length} sections`,category:"sketch"});return;case"sweep":_.push({kind:"sweep",label:"Sweep",summary:K1e(l.profile),category:"sketch"});return;case"box":_.push({kind:"box",label:"Box",summary:`${l.x} × ${l.y} × ${l.z}`,category:"primitive"});return;case"cylinder":_.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":_.push({kind:"sphere",label:"Sphere",summary:`r = ${l.radius}`,category:"primitive"});return;case"sheetMetal":_.push({kind:"sheetMetal",label:"Sheet Metal",summary:"",category:"primitive"});return;default:{const g=l.kind;_.push({kind:g,label:g,summary:"",category:"primitive"});return}}}function iTt(l){if(!l)return[];const _=[];return Mk(l,_),_}function sTt(l,_){const g=FJ(l),S=Tve(l),D=iTt(l);return{faceName:_.name,origin:S,transformations:g,query:_.query,timeline:D}}let hE=null;async function aTt(){if(hE)return hE;const l=(await import("./manifold-DEOPQqeC.js")).default;return hE=await l(),hE.setup(),hE.setMinCircularAngle(2),hE.setMinCircularEdgeLength(.5),hE}function wd(){if(!hE)throw new Error("Kernel not initialized — call initKernel() first");return hE}function obe(l){if(l instanceof Ys)return l;if(l&&typeof l=="object"&&typeof l.toShape=="function"){const _=l.toShape();if(_ instanceof Ys)return _;throw new Error(`expected toShape() to return a Shape, got ${pee(_)}`)}throw new Error(`expected a Shape or TrackedShape-compatible value, got ${pee(l)}`)}const kve=new WeakMap,pJe=new WeakMap,dJe=new WeakMap,Cve=new WeakMap,mJe=new WeakMap;let _je=0;const iN={backend:"manifold",representation:"mesh-solid",fidelity:"unknown",topology:"none",sources:["unknown"]};function cbe(l){const _=[],g=new Set;for(const S of l)g.has(S)||(g.add(S),_.push(S));return _}function gJe(l){return{backend:l.backend,representation:l.representation,fidelity:l.fidelity,topology:l.topology,sources:[...l.sources]}}function tz(l={}){return{backend:l.backend??iN.backend,representation:l.representation??iN.representation,fidelity:l.fidelity??iN.fidelity,topology:l.topology??iN.topology,sources:cbe(l.sources?[...l.sources]:[...iN.sources])}}function T_(l,_){return pJe.set(l,gJe(_)),l}function oTt(l,_){const g=nSt(_)?_:JBe(_);return mJe.set(l,g),l}function Zl(l,_){return dJe.set(l,s_(_)),l}function rz(l,_){return f2t(_)?Cve.set(l,xBe(_)):Cve.delete(l),l}function jf(l){return gJe(pJe.get(l)??iN)}function i_(l){const _=mJe.get(l);if(!_)throw new Error("Runtime backend missing on Shape");return _}function Pu(l){return s_(dJe.get(l)??null)}function bE(l){return xBe(Cve.get(l)??YF())}function OK(l,_){const g=[...new Set(l)];return g.length===1?g[0]:_}function Ok(l,_,g={}){return tz({backend:g.backend??l.backend,representation:g.representation??l.representation,fidelity:g.fidelity??l.fidelity,topology:g.topology??l.topology,sources:cbe([_,...l.sources,...g.sources??[]])})}function fP(l,_,g={}){return tz({backend:g.backend??OK(l.map(S=>S.backend),"hybrid"),representation:g.representation??OK(l.map(S=>S.representation),"mixed"),fidelity:g.fidelity??OK(l.map(S=>S.fidelity),"mixed"),topology:g.topology??OK(l.map(S=>S.topology),"none"),sources:cbe([_,...l.flatMap(S=>S.sources),...g.sources??[]])})}function hJe(){return _je+=1,`shape-dim-${_je}`}function cTt(l,_=!1){return{id:_?hJe():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 nz(l,_=!1){return l.map(g=>cTt(g,_))}function XF(l,_){return _.length===0?kve.delete(l):kve.set(l,_),l}function iz(l){return kve.get(l)??[]}function fje(l,_){const g=_[0],S=_[1],D=_[2];return[l[0]*g+l[4]*S+l[8]*D+l[12],l[1]*g+l[5]*S+l[9]*D+l[13],l[2]*g+l[6]*S+l[10]*D+l[14]]}function lTt(l,_){return l.map(g=>({id:hJe(),from:fje(_,g.from),to:fje(_,g.to),offset:g.offset,autoOffset:g.autoOffset,label:g.label,color:g.color,components:g.components?[...g.components]:void 0,currentComponent:g.currentComponent}))}function uTt(l,_,g){return Sa.identity().rotateAxis([1,0,0],l).rotateAxis([0,1,0],_).rotateAxis([0,0,1],g).toArray()}function _Tt(l,_,g){const[S,D,F]=g,z=_*Math.PI/180,ee=Math.cos(z),pe=Math.sin(z),we=Math.sqrt(l[0]**2+l[1]**2+l[2]**2)||1,De=l[0]/we,te=l[1]/we,nt=l[2]/we,Te=ee+De*De*(1-ee),Me=De*te*(1-ee)-nt*pe,bt=De*nt*(1-ee)+te*pe,vt=te*De*(1-ee)+nt*pe,Bt=ee+te*te*(1-ee),fr=te*nt*(1-ee)-De*pe,hn=nt*De*(1-ee)-te*pe,vr=nt*te*(1-ee)+De*pe,Xt=ee+nt*nt*(1-ee),Wt=S-(Te*S+Me*D+bt*F),Hn=D-(vt*S+Bt*D+fr*F),zn=F-(hn*S+vr*D+Xt*F);return[Te,vt,hn,0,Me,Bt,vr,0,bt,fr,Xt,0,Wt,Hn,zn,1]}function fTt(l){const[_,g,S]=l,D=Math.hypot(_,g,S);if(D<1e-12)return Sa.identity().toArray();const F=_/D,z=g/D,ee=S/D,pe=1-2*F*F,we=-2*F*z,De=-2*F*ee,te=-2*z*F,nt=1-2*z*z,Te=-2*z*ee,Me=-2*ee*F,bt=-2*ee*z,vt=1-2*ee*ee;return[pe,te,Me,0,we,nt,bt,0,De,Te,vt,0,0,0,0,1]}function pTt(l){const _=typeof l=="number"?[l,l,l]:l;return!Number.isFinite(_[0])||!Number.isFinite(_[1])||!Number.isFinite(_[2])||Math.abs(_[0])<1e-12||Math.abs(_[1])<1e-12||Math.abs(_[2])<1e-12?null:[_[0],_[1],_[2]]}function MK(l,_){return l[0]*_[0]+l[1]*_[1]+l[2]*_[2]}function dTt(l,_){return[l[1]*_[2]-l[2]*_[1],l[2]*_[0]-l[0]*_[2],l[0]*_[1]-l[1]*_[0]]}function YK(l){return Math.hypot(l[0],l[1],l[2])}function pje(l){const _=YK(l);return _<1e-12?[1,0,0]:[l[0]/_,l[1]/_,l[2]/_]}function mTt(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 g=[l[0],l[1],l[2]],S=[l[4],l[5],l[6]],D=[l[8],l[9],l[10]],F=YK(g),z=YK(S),ee=YK(D);if(Math.abs(F-1)>1e-6||Math.abs(z-1)>1e-6||Math.abs(ee-1)>1e-6||Math.abs(MK(g,S))>1e-6||Math.abs(MK(g,D))>1e-6||Math.abs(MK(S,D))>1e-6)return null;const pe=MK(g,dTt(S,D));if(Math.abs(pe-1)>1e-6)return null;const we=l[0],De=l[4],te=l[8],nt=l[1],Te=l[5],Me=l[9],bt=l[2],vt=l[6],Bt=l[10],fr=l[12],hn=l[13],vr=l[14],Xt=[],Wt=we+Te+Bt,Hn=Math.max(-1,Math.min(1,(Wt-1)/2)),zn=Math.acos(Hn),Fs=zn*180/Math.PI;if(Fs>1e-6){let Jn;if(Math.PI-zn<1e-5){const oc=Math.max(0,(we+1)/2),ro=Math.max(0,(Te+1)/2),Br=Math.max(0,(Bt+1)/2),pc=(De+nt)/4,eo=(te+bt)/4,Gt=(Me+vt)/4;if(oc>=ro&&oc>=Br){const fa=Math.sqrt(oc);Jn=[fa,fa>1e-6?pc/fa:0,fa>1e-6?eo/fa:0]}else if(ro>=Br){const fa=Math.sqrt(ro);Jn=[fa>1e-6?pc/fa:0,fa,fa>1e-6?Gt/fa:0]}else{const fa=Math.sqrt(Br);Jn=[fa>1e-6?eo/fa:0,fa>1e-6?Gt/fa:0,fa]}}else Jn=pje([vt-Me,te-bt,nt-De]);Jn=pje(Jn),Xt.push({kind:"rotateAround",axisX:Jn[0],axisY:Jn[1],axisZ:Jn[2],degrees:Fs,pivotX:0,pivotY:0,pivotZ:0})}return(Math.abs(fr)>1e-6||Math.abs(hn)>1e-6||Math.abs(vr)>1e-6)&&Xt.push({kind:"translate",x:fr,y:hn,z:vr}),Xt}function eN(l,_){return XF(_,nz(iz(l),!0)),T_(_,jf(l)),rz(_,bE(l)),Zl(_,Pu(l))}function IF(l,_,g){const S=iz(l);return S.length===0?XF(_,[]):XF(_,lTt(S,g)),T_(_,jf(l)),rz(_,p2t(bE(l),g)),Zl(_,Pu(l))}function HJ(l,_){const g=l.flatMap(F=>iz(F));XF(_,nz(g,!0));const S=l.length>0?jf(l[0]):iN;T_(_,S),rz(_,SBe(...l.map(F=>bE(F))));const D=l.length>0?Pu(l[0]):null;return Zl(_,D)}function T1(l,_){return XF(_,nz(iz(l),!0)),T_(_,jf(l)),rz(_,bE(l)),Zl(_,Pu(l))}function dje(l,_){return Array.isArray(_)?[_[0],_[1],_[2]]:l.referencePoint(_)}function yee(l,_,g={}){const S=g.regenerateIds??!0;return XF(l,nz(_,S))}function lbe(l){return nz(iz(l),!1)}function Lee(l,_,g={}){const S=g.merge??!0?QRe(bE(l),_):QRe(YF(),_);return rz(l,S)}function yJe(l){return bE(l)}function vJe(l){return jf(l)}function Ree(l,_){const g=jf(l);return T_(l,tz({backend:_.backend??g.backend,representation:_.representation??g.representation,fidelity:_.fidelity??g.fidelity,topology:_.topology??g.topology,sources:_.sources??g.sources}))}function gP(l){return Pu(l)}function jee(l,_){return Zl(l,_)}function vee(l){return Iee(Pu(l))}function bJe(l){return U2t(Pu(l))}function gTt(l){return NJ(Pu(l))}function k_(l,_,g){return jee(new Ys(nTt(l,wd()),_,g),l)}function C1(l,_,g){if(!l)return null;const S=Nee(_);return KJ(rbe(l,g(S)),S)}class Ys{constructor(_,g,S){of(this,"colorHex");this.colorHex=g,oTt(this,_),T_(this,tz(S)),Zl(this,null)}setColor(_){return eN(this,new Ys(i_(this).clone(),_))}color(_){return this.setColor(_)}clone(){return eN(this,new Ys(i_(this).clone(),this.colorHex))}duplicate(){return this.clone()}geometryInfo(){return jf(this)}withReferences(_){return Lee(this.clone(),_,{merge:!0})}referenceNames(_){return TBe(bE(this),_)}referencePoint(_){return xJe(this,_)}face(_){const g=Pu(this),S=sje(g,_);if(S)return S;throw new Error(aje(g,_))}faceNames(){return Dxt(Pu(this))}faceHistory(_){const g=Pu(this),S=sje(g,_);if(!S)throw new Error(aje(g,_));return sTt(g,S)}placeReference(_,g,S){const D=this.referencePoint(_);let F=g[0]-D[0],z=g[1]-D[1],ee=g[2]-D[2];return S&&(F+=S[0],z+=S[1],ee+=S[2]),this.translate(F,z,ee)}translate(_,g,S){const D=E1(Pu(this),{kind:"translate",x:_,y:g,z:S});return Zl(IF(this,D?k_(D,this.colorHex):new Ys(i_(this).translate(_,g,S),this.colorHex),Sa.translation(_,g,S).toArray()),D)}moveTo(_,g,S){const D=this.boundingBox();return this.translate(_-D.min[0],g-D.min[1],S-D.min[2])}moveToLocal(_,g,S,D){const z=("toShape"in _?_.toShape():_).boundingBox();return this.moveTo(z.min[0]+g,z.min[1]+S,z.min[2]+D)}rotate(_,g,S){const D=E1(Pu(this),{kind:"rotate",xDeg:_,yDeg:g,zDeg:S});return Zl(IF(this,D?k_(D,this.colorHex):new Ys(i_(this).rotate(_,g,S),this.colorHex),uTt(_,g,S)),D)}transform(_){const g=_ instanceof Sa?_.toArray():_,S=(()=>{const D=mTt(g);return D==null?null:D.length===0?Pu(this):V2t(Pu(this),D)})();return Zl(IF(this,S?k_(S,this.colorHex):new Ys(i_(this).transform(g),this.colorHex),g),S)}scale(_){const g=pTt(_),S=g?E1(Pu(this),{kind:"scale",x:g[0],y:g[1],z:g[2]}):null;return Zl(IF(this,S?k_(S,this.colorHex):new Ys(i_(this).scale(_),this.colorHex),Sa.scale(_).toArray()),S)}mirror(_){const g=E1(Pu(this),{kind:"mirror",normalX:_[0],normalY:_[1],normalZ:_[2]}),S=jBe(g,"mirror");return Zl(IF(this,S?k_(S,this.colorHex):new Ys(i_(this).mirror(_),this.colorHex),fTt(_)),S)}pointAlong(_){const[g,S,D]=_,F=Math.sqrt(g*g+S*S+D*D)||1,z=g/F,ee=S/F,pe=D/F,we=-ee,De=z,te=0,nt=Math.sqrt(we*we+De*De+te*te),Te=pe;if(nt<1e-10)return Te>0?this:this.rotate(180,0,0);const Me=Math.atan2(nt,Te)*180/Math.PI,bt=we/nt,vt=De/nt,Bt=te/nt;return this.rotateAround([bt,vt,Bt],Me)}rotateAround(_,g,S=[0,0,0]){const D=Math.sqrt(_[0]**2+_[1]**2+_[2]**2)||1,F=[_[0]/D,_[1]/D,_[2]/D],z=_Tt(F,g,S),ee=E1(Pu(this),{kind:"rotateAround",axisX:F[0],axisY:F[1],axisZ:F[2],degrees:g,pivotX:S[0],pivotY:S[1],pivotZ:S[2]});return Zl(IF(this,ee?k_(ee,this.colorHex):new Ys(i_(this).transform(z),this.colorHex),z),ee)}rotateAroundTo(_,g,S,D,F={}){const z=dje(this,S),ee=dje(this,D),pe=fBe(_,g,z,ee,F);return this.rotateAround(_,pe,g)}smoothOut(_=60,g=0){return Zl(T_(eN(this,new Ys(i_(this).smoothOut(_,g),this.colorHex)),Ok(jf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}refine(_){const g=n2t(_);return g<=0?this.clone():Zl(T_(eN(this,new Ys(i_(this).refine(g),this.colorHex)),Ok(jf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}refineToLength(_){const g=i2t(_);return Zl(T_(eN(this,new Ys(i_(this).refineToLength(g),this.colorHex)),Ok(jf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}refineToTolerance(_){const g=s2t(_);return Zl(T_(eN(this,new Ys(i_(this).refineToTolerance(g),this.colorHex)),Ok(jf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}warp(_){return Zl(T_(eN(this,new Ys(i_(this).warp(_),this.colorHex)),Ok(jf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}static _unwrap(_){return obe(_)}add(..._){const g=[this,...BF("Shape.add()",_,1,"Use shape.add(other1, other2) or shape.add([other1, other2]).")],S=g.map(F=>Pu(F)),D=C1(Sy("union",S),"boolean:union",F=>lP("union",F,S));return Zl(T_(HJ(g,D?k_(D,this.colorHex):new Ys(wd().Manifold.union(JF("Shape.add()",g)),this.colorHex)),fP(g.map(F=>jf(F)),"boolean",{topology:"none"})),D)}subtract(..._){const g=[this,...BF("Shape.subtract()",_,1,"Use shape.subtract(other1, other2) or shape.subtract([other1, other2]).")],S=g.map(F=>Pu(F)),D=C1(Sy("difference",S),"boolean:difference",F=>lP("difference",F,S));return Zl(T_(T1(this,D?k_(D,this.colorHex):new Ys(wd().Manifold.difference(JF("Shape.subtract()",g)),this.colorHex)),fP(g.map(F=>jf(F)),"boolean",{topology:"none"})),D)}intersect(..._){const g=[this,...BF("Shape.intersect()",_,1,"Use shape.intersect(other1, other2) or shape.intersect([other1, other2]).")],S=g.map(F=>Pu(F)),D=C1(Sy("intersection",S),"boolean:intersection",F=>lP("intersection",F,S));return Zl(T_(HJ(g,D?k_(D,this.colorHex):new Ys(wd().Manifold.intersection(JF("Shape.intersect()",g)),this.colorHex)),fP(g.map(F=>jf(F)),"boolean",{topology:"none"})),D)}split(_){const g=Ys._unwrap(_),S=[Pu(this),Pu(g)],D=C1(Sy("intersection",S),"split:inside",De=>lP("intersection",De,S)),F=[Pu(this),Pu(g)],z=C1(Sy("difference",F),"split:outside",De=>lP("difference",De,F)),ee=fP([jf(this),jf(g)],"boolean",{topology:"none"});if(D&&z)return[Zl(T_(T1(this,k_(D,this.colorHex)),ee),D),Zl(T_(T1(this,k_(z,this.colorHex)),ee),z)];const[pe,we]=i_(this).split(i_(g));return[Zl(T_(T1(this,new Ys(pe,this.colorHex)),ee),null),Zl(T_(T1(this,new Ys(we,this.colorHex)),ee),null)]}splitByPlane(_,g=0){const S=Ok(jf(this),"boolean",{topology:"none"}),D=Pu(this),F=C1(H1e(D,_,g),"splitByPlane:positive",we=>Q1e(we,D)),z=C1(H1e(D,[-_[0],-_[1],-_[2]],-g),"splitByPlane:opposite",we=>Q1e(we,D));if(F&&z)return[Zl(T_(T1(this,k_(F,this.colorHex)),S),F),Zl(T_(T1(this,k_(z,this.colorHex)),S),z)];const[ee,pe]=i_(this).splitByPlane(_,g);return[Zl(T_(T1(this,new Ys(ee,this.colorHex)),S),null),Zl(T_(T1(this,new Ys(pe,this.colorHex)),S),null)]}trimByPlane(_,g=0){const S=Pu(this),D=C1(H1e(S,_,g),"trimByPlane",F=>Q1e(F,S));return Zl(T_(T1(this,D?k_(D,this.colorHex):new Ys(i_(this).trimByPlane(_,g),this.colorHex)),Ok(jf(this),"boolean",{topology:"none"})),D)}shell(_,g={}){const S=Pu(this),D=C1(mSt(S,_,g.openFaces),"shell",F=>Qxt(F,S,g.openFaces??[]));if(!D)throw new Error("Shape.shell() currently supports compile-covered box(), cylinder(), and straight extrude() solids with optional top/bottom openings and rigid transforms.");return Zl(T_(T1(this,k_(D,this.colorHex)),Ok(jf(this),"shell",{topology:"none"})),D)}hull(){const _=C1(EBe([Pu(this)]),"hull",g=>RBe(g));return Zl(T_(T1(this,_?k_(_,this.colorHex):new Ys(i_(this).hull(),this.colorHex)),Ok(jf(this),"hull",{topology:"none"})),_)}simplify(_){return Zl(T_(T1(this,new Ys(i_(this).simplify(_),this.colorHex)),Ok(jf(this),"deform",{fidelity:"deformed",topology:"none"})),null)}boundingBox(){return i_(this).boundingBox()}volume(){return i_(this).volume()}surfaceArea(){return i_(this).surfaceArea()}minGap(_,g){const S="toShape"in _?_.toShape():_;return i_(this).minGap(i_(S),g)}isEmpty(){return i_(this).isEmpty()}numTri(){return i_(this).numTri()}getMesh(){return i_(this).getMesh()}slice(_=0){return i_(this).slice(_)}project(){return i_(this).project()}attachTo(_,g,S="center",D){const F=hTt(_,g),z=this.referencePoint(S);let ee=F[0]-z[0],pe=F[1]-z[1],we=F[2]-z[2];return D&&(ee+=D[0],pe+=D[1],we+=D[2]),this.translate(ee,pe,we)}onFace(_,g,S={}){const D=S.u??0,F=S.v??0,z=S.protrude??0,ee={front:"back",back:"front",left:"right",right:"left",top:"bottom",bottom:"top"},pe={front:(te,nt,Te)=>[te,-Te,nt],back:(te,nt,Te)=>[te,Te,nt],left:(te,nt,Te)=>[-Te,te,nt],right:(te,nt,Te)=>[Te,te,nt],top:(te,nt,Te)=>[te,nt,Te],bottom:(te,nt,Te)=>[te,nt,-Te]},we=ee[g],De=pe[g](D,F,z);return this.attachTo(_,g,we,De)}}function mje(l,_){const S=(typeof l.toShape=="function"?l.toShape():l).boundingBox();return pP(S.min,S.max,_)}function xJe(l,_){if(vBe(_))return mje(l,_);const g=d2t(bE(l),_);if(g)return g;const S=Pee(_);if(S)return mje(l,S);throw new Error(`Unknown placement reference "${_}". Available: ${TBe(bE(l)).join(", ")||"none"}`)}function hTt(l,_){if(l instanceof Ys)return xJe(l,_);if("referencePoint"in l&&typeof l.referencePoint=="function")return l.referencePoint(_);const g=Pee(_);if(!g)throw new Error(`ShapeGroup targets only support built-in anchors, got "${_}"`);if(!("_bbox"in l)||typeof l._bbox!="function")throw new Error("ShapeGroup anchor target is missing _bbox()");const S=l._bbox();return pP(S.min,S.max,g)}function DS(l,_,g,S=!1){return k_(kE({kind:"box",x:l,y:_,z:g,center:S},"primitive:box"),void 0,{fidelity:"kernel-native",sources:["primitive"]})}function lg(l,_,g,S,D=!1){return k_(kE({kind:"cylinder",height:l,radius:_,radiusTop:g!=null&&g>=0?g:void 0,segments:S!=null&&S>0?S:void 0,center:D},"primitive:cylinder"),void 0,{fidelity:"kernel-native",sources:["primitive"]})}function yTt(l,_){return k_(kE({kind:"sphere",radius:l,segments:_!=null&&_>0?_:void 0},"primitive:sphere"),void 0,{fidelity:"kernel-native",sources:["primitive"]})}function BF(l,_,g,S){return DBe({apiName:l,inputs:_,minCount:g,itemName:"shape",usage:S,coerce:D=>obe(D)})}function vTt(l,_,g){if(Array.isArray(l)&&l.length===3&&l.every(S=>typeof S=="number"&&Number.isFinite(S)))return l;throw new Error(`${_} argument ${g}: expected a [x, y, z] point, got ${pee(l)}`)}function JF(l,_){return _.map((g,S)=>gee(i_(g),`${l} operand ${S+1}`))}function I1(...l){const _=BF("union()",l,1,"Use union(shape1, shape2) or union([shape1, shape2]).");if(_.length===0)throw new Error("union requires at least one shape");if(_.length===1)return _[0];const g=_.map(D=>Pu(D)),S=C1(Sy("union",g),"boolean:union",D=>lP("union",D,g));return Zl(T_(HJ(_,S?k_(S,_[0].colorHex):new Ys(wd().Manifold.union(JF("union()",_)),_[0].colorHex)),fP(_.map(D=>jf(D)),"boolean",{topology:"none"})),S)}function bTt(...l){const _=BF("difference()",l,2,"Use difference(base, cutter1, cutter2) or difference([base, cutter1, cutter2]).");if(_.length<2)throw new Error("difference requires at least two shapes");const g=_.map(D=>Pu(D)),S=C1(Sy("difference",g),"boolean:difference",D=>lP("difference",D,g));return Zl(T_(T1(_[0],S?k_(S,_[0].colorHex):new Ys(wd().Manifold.difference(JF("difference()",_)),_[0].colorHex)),fP(_.map(D=>jf(D)),"boolean",{topology:"none"})),S)}function xTt(...l){const _=BF("intersection()",l,2,"Use intersection(shape1, shape2) or intersection([shape1, shape2]).");if(_.length<2)throw new Error("intersection requires at least two shapes");const g=_.map(D=>Pu(D)),S=C1(Sy("intersection",g),"boolean:intersection",D=>lP("intersection",D,g));return Zl(T_(HJ(_,S?k_(S,_[0].colorHex):new Ys(wd().Manifold.intersection(JF("intersection()",_)),_[0].colorHex)),fP(_.map(D=>jf(D)),"boolean",{topology:"none"})),S)}function STt(...l){var z,ee;const _=[],g=[],S=l.map((pe,we)=>{if(pe instanceof Ys||pe&&typeof pe=="object"&&typeof pe.toShape=="function"){const te=obe(pe);return _.push(te),gee(i_(te),`hull3d() shape ${_.length}`)}const De=vTt(pe,"hull3d()",we+1);return g.push(De),De}),D=C1(EBe(_.map(pe=>Pu(pe)),g),"hull",pe=>RBe(pe)),F=D?k_(D,(z=_[0])==null?void 0:z.colorHex):new Ys(wd().Manifold.hull(S),(ee=_[0])==null?void 0:ee.colorHex);return Zl(T_(HJ(_,F),_.length>0?fP(_.map(pe=>jf(pe)),"hull",{topology:"none"}):tz({fidelity:"kernel-native",sources:["hull"]})),D)}function ube(l,_,g,S=0){return new Ys(wd().Manifold.levelSet(l,{min:_.min,max:_.max},g,S),void 0,{fidelity:"sampled",sources:["level-set"]})}const SJe=new WeakMap,TJe=new WeakMap,kJe=new WeakMap;function ZK(l,_){return SJe.set(l,Cd(_)),l}function CJe(l){return l?[...l]:null}function jJ(l,_){return TJe.set(l,CJe(_)),l}function BJ(l,_){return kJe.set(l,TE(_)),l}class So{constructor(_,g){of(this,"colorHex");this.cross=_,this.colorHex=g,ZK(this,null),jJ(this,null),BJ(this,null)}color(_){return BJ(jJ(ZK(new So(this.cross,_),tm(this)),xE(this)),SE(this))}clone(){return BJ(jJ(ZK(new So(this.cross,this.colorHex),tm(this)),xE(this)),SE(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(_,g){throw new Error("Not implemented")}rotate(_){throw new Error("Not implemented")}rotateAround(_,g){throw new Error("Not implemented")}scale(_){throw new Error("Not implemented")}mirror(_){throw new Error("Not implemented")}add(..._){throw new Error("Not implemented")}subtract(..._){throw new Error("Not implemented")}intersect(..._){throw new Error("Not implemented")}offset(_,g="Round"){return X2(this,new So(this.cross.offset(_,g),this.colorHex))}hull(){return X2(this,new So(this.cross.hull(),this.colorHex))}simplify(_=1e-6){return X2(this,new So(this.cross.simplify(_),this.colorHex))}warp(_){return X2(this,new So(this.cross.warp(_),this.colorHex))}extrude(_,g){throw new Error("Not implemented")}revolve(_,g){throw new Error("Not implemented")}attachTo(_,g,S,D){throw new Error("Not implemented")}onFace(_,g,S){throw new Error("Not implemented")}}function tm(l){return Cd(SJe.get(l)??null)}function Ty(l,_){return ZK(l,_)}function Oh(l,_){return Ty(new So(mP(l,wd()),_),l)}function xE(l){return CJe(TJe.get(l)??null)}function hP(l,_){return jJ(l,_)}function SE(l){return TE(kJe.get(l)??null)}function yP(l,_){return BJ(l,_)}function X2(l,_){return BJ(jJ(_,xE(l)),SE(l))}function TTt(l,_,g=1e-8){if(l==null||_==null)return l==null&&_==null;for(let S=0;S<16;S+=1)if(Math.abs(l[S]-_[S])>g)return!1;return!0}function kTt(l,_,g=1e-8){if(l==null||_==null)return l==null&&_==null;if(!IS(l.source,_.source))return!1;const S=[[l.origin,_.origin],[l.u,_.u],[l.v,_.v],[l.normal,_.normal]];for(const[D,F]of S)for(let z=0;z<D.length;z+=1)if(Math.abs(D[z]-F[z])>g)return!1;return!0}function CTt(l,_,g=1e-8){return l==null||_==null?l==null&&_==null:kTt(l.workplane,_.workplane,g)&&Math.abs(l.u-_.u)<=g&&Math.abs(l.v-_.v)<=g&&Math.abs(l.protrude-_.protrude)<=g&&l.selfAnchor===_.selfAnchor}function hN(l){if(l.length===0)return null;const _=xE(l[0]);for(let g=1;g<l.length;g+=1)if(!TTt(_,xE(l[g])))return null;return _}function yN(l){if(l.length===0)return null;const _=SE(l[0]);for(let g=1;g<l.length;g+=1)if(!CTt(_,SE(l[g])))return null;return _}function wTt(l){const _=l.map(S=>Array.isArray(S)?[S[0],S[1]]:[S.x,S.y]);let g=0;for(let S=0;S<_.length;S++){const[D,F]=_[S],[z,ee]=_[(S+1)%_.length];g+=(z-D)*(ee+F)}return g>0&&_.reverse(),_.map(([S,D])=>[S,D])}function ES(l,_,g=!1){return Oh({kind:"rect",width:l,height:_,center:g,transforms:[]})}function _b(l,_){return Oh({kind:"circle",radius:l,segments:_!=null&&_>0?_:void 0,transforms:[]})}function bee(l,_,g,S=!1){const D=Math.min(g,l/2,_/2);return Oh({kind:"roundedRect",width:l,height:_,radius:D,center:S,transforms:[]})}function Ed(l){const _=wTt(l);return Oh({kind:"polygon",points:_,transforms:[]})}function ETt(l,_){const g=[];for(let S=0;S<l;S++){const D=2*Math.PI*S/l-Math.PI/2;g.push([_*Math.cos(D),_*Math.sin(D)])}return Ed(g)}function DTt(l,_,g=64){const S=[];for(let D=0;D<g;D++){const F=2*Math.PI*D/g;S.push([l*Math.cos(F),_*Math.sin(F)])}return Ed(S)}function PTt(l,_){const g=_/2,S=ES(l-_,_,!0),D=_b(g).translate(-(l-_)/2,0),F=_b(g).translate((l-_)/2,0);return S.add(D).add(F)}function ATt(l,_,g){const S=[];for(let D=0;D<l*2;D++){const F=Math.PI*D/l-Math.PI/2,z=D%2===0?_:g;S.push([z*Math.cos(F),z*Math.sin(F)])}return Ed(S)}function fN(l,_,g=0){const S=lb(tm(l),{kind:"translate",x:_,y:g});return X2(l,S?Oh(S,l.colorHex):Ty(new So(l.cross.translate(_,g),l.colorHex),null))}function H2(l,_){const g=lb(tm(l),{kind:"rotate",degrees:_});return X2(l,g?Oh(g,l.colorHex):Ty(new So(l.cross.rotate(_),l.colorHex),null))}function NTt(l,_,g){return fN(H2(fN(l,-g[0],-g[1]),_),g[0],g[1])}function ITt(l,_){const g=typeof _=="number"?[_,_]:_,S=lb(tm(l),{kind:"scale",x:g[0],y:g[1]});return X2(l,S?Oh(S,l.colorHex):Ty(new So(l.cross.scale(_),l.colorHex),null))}function FTt(l,_){const g=lb(tm(l),{kind:"mirror",normalX:_[0],normalY:_[1]});return X2(l,g?Oh(g,l.colorHex):Ty(new So(l.cross.mirror(_),l.colorHex),null))}So.prototype.translate=function(l,_=0){return fN(this,l,_)};So.prototype.rotate=function(l){return H2(this,l)};So.prototype.rotateAround=function(l,_){return NTt(this,l,_)};So.prototype.scale=function(l){return ITt(this,l)};So.prototype.mirror=function(l){return FTt(this,l)};function k1(l,_,g){return{name:l,start:_,end:g,query:{kind:"tracked-edge",edgeName:l,selector:"edge"}}}class lo{constructor(_,g,S,D){this.shape=_,this.topology=g,this.baseHeight=S,this.extrudeUp=D,Lee(this.shape,LTt(this.topology),{merge:!0})}face(_){var D;const g=this.topology.faces.get(_);if(!g){const F=[...this.topology.faces.keys()].join(", ");throw new Error(`Face "${_}" not found. Available: ${F}`)}const S=vee(this.shape);return{...g,normal:[g.normal[0],g.normal[1],g.normal[2]],center:[g.center[0],g.center[1],g.center[2]],query:Kl({kind:"tracked-face",faceName:_,owner:fp(S??((D=g.query)==null?void 0:D.owner))}),uAxis:g.uAxis?[g.uAxis[0],g.uAxis[1],g.uAxis[2]]:void 0,vAxis:g.vAxis?[g.vAxis[0],g.vAxis[1],g.vAxis[2]]:void 0}}edge(_){var D;const g=this.topology.edges.get(_);if(!g){const F=[...this.topology.edges.keys()].join(", ");throw new Error(`Edge "${_}" not found. Available: ${F}`)}const S=vee(this.shape);return{...g,start:[g.start[0],g.start[1],g.start[2]],end:[g.end[0],g.end[1],g.end[2]],query:Tl({kind:"tracked-edge",edgeName:_,selector:"edge",owner:fp(S??((D=g.query)==null?void 0:D.owner))})}}faceNames(){return[...this.topology.faces.keys()]}edgeNames(){return[...this.topology.edges.keys()]}clone(){return new lo(this.shape.clone(),eve(this.topology),this.baseHeight,this.extrudeUp)}duplicate(){return this.clone()}geometryInfo(){const _=this.shape.geometryInfo(),g=this.topology.faces.size>0||this.topology.edges.size>0;return{..._,topology:g?"synthetic":_.topology}}withReferences(_){return new lo(this.shape.withReferences(_),eve(this.topology),this.baseHeight,this.extrudeUp)}referenceNames(_){return this.shape.referenceNames(_)}referencePoint(_){return this.shape.referencePoint(_)}placeReference(_,g,S){return new lo(this.shape.placeReference(_,g,S),eve(this.topology),this.baseHeight,this.extrudeUp)}translate(_,g,S){const D=OTt(this.topology,_,g,S);return new lo(this.shape.translate(_,g,S),D,this.baseHeight,this.extrudeUp)}moveTo(_,g,S){const D=this.shape.boundingBox();return this.translate(_-D.min[0],g-D.min[1],S-D.min[2])}moveToLocal(_,g,S,D){const z=(_ instanceof lo?_.toShape():_).boundingBox();return this.moveTo(z.min[0]+g,z.min[1]+S,z.min[2]+D)}moveBy(_,g,S){return this.translate(_,g,S)}rotateAroundEdge(_,g){const S=this.edge(_),[D,F,z]=S.start,ee=S.end[0]-D,pe=S.end[1]-F,we=S.end[2]-z,De=Math.sqrt(ee*ee+pe*pe+we*we)||1,te=ee/De,nt=pe/De,Te=we/De,Me=g*Math.PI/180,bt=Math.cos(Me),vt=Math.sin(Me),Bt=1-bt,fr=Bt*te*te+bt,hn=Bt*te*nt-vt*Te,vr=Bt*te*Te+vt*nt,Xt=Bt*te*nt+vt*Te,Wt=Bt*nt*nt+bt,Hn=Bt*nt*Te-vt*te,zn=Bt*te*Te-vt*nt,Fs=Bt*nt*Te+vt*te,Jn=Bt*Te*Te+bt,oc=-fr*D-hn*F-vr*z+D,ro=-Xt*D-Wt*F-Hn*z+F,Br=-zn*D-Fs*F-Jn*z+z,pc=[fr,Xt,zn,0,hn,Wt,Fs,0,vr,Hn,Jn,0,oc,ro,Br,1],eo=this.shape.transform(pc);return new lo(eo,{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}rotate(_,g,S){return new lo(this.shape.rotate(_,g,S),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}transform(_){return new lo(this.shape.transform(_),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}pointAlong(_){return new lo(this.shape.pointAlong(_),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}rotateAround(_,g,S=[0,0,0]){return new lo(this.shape.rotateAround(_,g,S),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}rotateAroundTo(_,g,S,D,F={}){return new lo(this.shape.rotateAroundTo(_,g,S,D,F),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}scale(_){return new lo(this.shape.scale(_),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}mirror(_){return new lo(this.shape.mirror(_),{faces:new Map,edges:new Map},this.baseHeight,this.extrudeUp)}color(_){return new lo(this.shape.color(_),this.topology,this.baseHeight,this.extrudeUp)}toShape(){return this.shape}attachTo(_,g,S="center",D){let F;if(typeof _._bbox=="function"&&!(_ instanceof lo)&&!(_ instanceof Ys)){if(g.includes("."))throw new Error(`ShapeGroup targets only support built-in anchors, got "${g}"`);const De=_._bbox();F=pP(De.min,De.max,g)}else F=(_ instanceof lo,_).referencePoint(g);const z=this.referencePoint(S);let ee=F[0]-z[0],pe=F[1]-z[1],we=F[2]-z[2];return D&&(ee+=D[0],pe+=D[1],we+=D[2]),this.translate(ee,pe,we)}onFace(_,g,S={}){const D=S.u??0,F=S.v??0,z=S.protrude??0,ee={front:"back",back:"front",left:"right",right:"left",top:"bottom",bottom:"top"},pe={front:(we,De,te)=>[we,-te,De],back:(we,De,te)=>[we,te,De],left:(we,De,te)=>[-te,we,De],right:(we,De,te)=>[te,we,De],top:(we,De,te)=>[we,De,te],bottom:(we,De,te)=>[we,De,-te]};return this.attachTo(_,g,ee[g],pe[g](D,F,z))}subtract(..._){return this.shape.subtract(..._)}add(..._){return this.shape.add(..._)}intersect(..._){return this.shape.intersect(..._)}shell(_,g={}){return this.shape.shell(_,g)}boundingBox(){return this.shape.boundingBox()}get volume(){return this.shape.volume()}}function OTt(l,_,g,S){const D=new Map;for(const[z,ee]of l.faces)D.set(z,{...ee,center:[ee.center[0]+_,ee.center[1]+g,ee.center[2]+S],query:Kl(ee.query),uAxis:ee.uAxis?[ee.uAxis[0],ee.uAxis[1],ee.uAxis[2]]:void 0,vAxis:ee.vAxis?[ee.vAxis[0],ee.vAxis[1],ee.vAxis[2]]:void 0});const F=new Map;for(const[z,ee]of l.edges)F.set(z,{...ee,start:[ee.start[0]+_,ee.start[1]+g,ee.start[2]+S],end:[ee.end[0]+_,ee.end[1]+g,ee.end[2]+S],query:Tl(ee.query)});return{faces:D,edges:F}}function eve(l){const _=new Map;for(const[S,D]of l.faces)_.set(S,{...D,normal:[D.normal[0],D.normal[1],D.normal[2]],center:[D.center[0],D.center[1],D.center[2]],query:Kl(D.query),uAxis:D.uAxis?[D.uAxis[0],D.uAxis[1],D.uAxis[2]]:void 0,vAxis:D.vAxis?[D.vAxis[0],D.vAxis[1],D.vAxis[2]]:void 0});const g=new Map;for(const[S,D]of l.edges)g.set(S,{...D,start:[D.start[0],D.start[1],D.start[2]],end:[D.end[0],D.end[1],D.end[2]],query:Tl(D.query)});return{faces:_,edges:g}}function MTt(l,_){const g=Sa.from(_),S=new Map;for(const[F,z]of l.faces)S.set(F,{...z,normal:$p(g.vector(z.normal)),center:g.point(z.center),query:Kl(z.query),uAxis:z.uAxis?$p(g.vector(z.uAxis)):void 0,vAxis:z.vAxis?$p(g.vector(z.vAxis)):void 0});const D=new Map;for(const[F,z]of l.edges)D.set(F,{...z,start:g.point(z.start),end:g.point(z.end),query:Tl(z.query)});return{faces:S,edges:D}}function LTt(l){const _={};for(const[S,D]of l.faces)_[S]={center:[D.center[0],D.center[1],D.center[2]],normal:[D.normal[0],D.normal[1],D.normal[2]]};const g={};for(const[S,D]of l.edges)g[S]={start:[D.start[0],D.start[1],D.start[2]],end:[D.end[0],D.end[1],D.end[2]]};return{surfaces:_,edges:g}}function wJe(l,_,g=!0,S=0){const D=new Map,F=new Map,[z,ee,pe,we]=l.vertices,De=S,te=S+(g?_:-_),nt=Math.max(De,te),Te=Math.min(De,te),Me=l.center.x,bt=l.center.y,vt=$p([ee.x-z.x,ee.y-z.y,0]),Bt=$p([we.x-z.x,we.y-z.y,0]);D.set("top",{name:"top",normal:[0,0,1],center:[Me,bt,nt],planar:!0,uAxis:vt,vAxis:Bt}),D.set("bottom",{name:"bottom",normal:[0,0,-1],center:[Me,bt,Te],planar:!0,uAxis:vt,vAxis:[-Bt[0],-Bt[1],-Bt[2]]});const fr=[["bottom",z,ee],["right",ee,pe],["top",pe,we],["left",we,z]];for(const[hn,vr,Xt]of fr){const Wt=vr.midpointTo(Xt),Hn=Xt.x-vr.x,zn=Xt.y-vr.y,Fs=Math.sqrt(Hn*Hn+zn*zn)||1,Jn=zn/Fs,oc=-Hn/Fs,ro=[Hn/Fs,zn/Fs,0];D.set(`side-${hn}`,{name:`side-${hn}`,normal:[Jn,oc,0],center:[Wt.x,Wt.y,(nt+Te)/2],planar:!0,uAxis:ro,vAxis:[0,0,1]})}return F.set("bottom-bottom",k1("bottom-bottom",[z.x,z.y,Te],[ee.x,ee.y,Te])),F.set("bottom-right",k1("bottom-right",[ee.x,ee.y,Te],[pe.x,pe.y,Te])),F.set("bottom-top",k1("bottom-top",[pe.x,pe.y,Te],[we.x,we.y,Te])),F.set("bottom-left",k1("bottom-left",[we.x,we.y,Te],[z.x,z.y,Te])),F.set("top-bottom",k1("top-bottom",[z.x,z.y,nt],[ee.x,ee.y,nt])),F.set("top-right",k1("top-right",[ee.x,ee.y,nt],[pe.x,pe.y,nt])),F.set("top-top",k1("top-top",[pe.x,pe.y,nt],[we.x,we.y,nt])),F.set("top-left",k1("top-left",[we.x,we.y,nt],[z.x,z.y,nt])),F.set("vert-bl",k1("vert-bl",[z.x,z.y,Te],[z.x,z.y,nt])),F.set("vert-br",k1("vert-br",[ee.x,ee.y,Te],[ee.x,ee.y,nt])),F.set("vert-tr",k1("vert-tr",[pe.x,pe.y,Te],[pe.x,pe.y,nt])),F.set("vert-tl",k1("vert-tl",[we.x,we.y,Te],[we.x,we.y,nt])),{faces:D,edges:F}}function EJe(l,_,g=!1){const S=new Map,D=new Map,F=l.center.x,z=l.center.y,ee=g?-_/2:0,pe=g?_/2:_,we=Math.min(ee,pe),De=Math.max(ee,pe),te=l.radiusTop??l.radius,nt=(Math.abs(l.radius)+Math.abs(te))/2;return S.set("top",{name:"top",normal:[0,0,1],center:[F,z,De],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0]}),S.set("bottom",{name:"bottom",normal:[0,0,-1],center:[F,z,we],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0]}),S.set("side",{name:"side",normal:[1,0,0],center:[F+nt,z,(De+we)/2],planar:!1}),D.set("top-rim",k1("top-rim",[F+te,z,De],[F,z+te,De])),D.set("bottom-rim",k1("bottom-rim",[F+l.radius,z,we],[F,z+l.radius,we])),{faces:S,edges:D}}function RTt(l,_){const g=l.bounds(),[S,D]=g.min,[F,z]=g.max,ee=(S+F)/2,pe=(D+z)/2;switch(_){case"center":return[ee,pe];case"top-left":return[S,z];case"top-right":return[F,z];case"bottom-left":return[S,D];case"bottom-right":return[F,D];case"top":return[ee,z];case"bottom":return[ee,D];case"left":return[S,pe];case"right":return[F,pe]}}function jTt(l,_){if(typeof l._bbox=="function"){const D=l._bbox();return pP(D.min,D.max,_)}const g=l;return("toShape"in g?g.toShape():g).referencePoint(_)}function BTt(l){if(typeof l._bbox=="function")return;const _=l,g="toShape"in _?_.toShape():_;return fp(vee(g)??void 0)}function gje(l){return l==="front"||l==="back"||l==="left"||l==="right"||l==="top"||l==="bottom"}function hje(l){if(!l||typeof l!="object")return!1;const _=l;return typeof _.name=="string"&&Array.isArray(_.normal)&&Array.isArray(_.center)}function JTt(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 LK(l){if(l.planar===!1||!l.uAxis||!l.vAxis)throw new Error(`Face "${l.name}" is not planar and cannot host a sketch.`);const _=(()=>{var S;if(l.query&&l.query.kind!=="tracked-face"&&l.query.kind!=="canonical-face")return Kl(l.query);const g=fp((S=l.query)==null?void 0:S.owner);return{kind:"face-ref",faceName:l.name,owner:g}})();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:_}}function zTt(l,_){var D;const g=l.topology.faces.get(_);if(!g)return null;const S=vee(l.toShape())??((D=g.query)==null?void 0:D.owner);return{...g,normal:[g.normal[0],g.normal[1],g.normal[2]],center:[g.center[0],g.center[1],g.center[2]],query:Kl({kind:"tracked-face",faceName:_,owner:fp(S??void 0)}),uAxis:g.uAxis?[g.uAxis[0],g.uAxis[1],g.uAxis[2]]:void 0,vAxis:g.vAxis?[g.vAxis[0],g.vAxis[1],g.vAxis[2]]:void 0}}function qTt(l){return l.faceNames().filter(_=>{const g=l.topology.faces.get(_);return!!g&&g.planar!==!1&&!!g.uAxis&&!!g.vAxis})}function WTt(l,_){const g=l instanceof Error?l.message:String(l);return g===`Face "${_}" is not available. Supported faces: none`||g.startsWith(`Face "${_}" is not available. Supported faces: `)}function QF(l,_){if(hje(l))return LK(l);if(_==null)throw new Error("Sketch.onFace(parent, face, opts) requires a face name or FaceRef.");if(hje(_))return LK(_);if(typeof _!="string")throw new Error("Sketch.onFace() requires a face name or FaceRef.");if(l instanceof lo){const g=zTt(l,_);if(g)return{...LK(g),source:Kl(g.query)??{kind:"tracked-face",faceName:_}}}if(l instanceof Ys&&gP(l))try{return LK(l.face(_))}catch(g){if(!gje(_)||!WTt(g,_))throw g}if(gje(_)){const g=JTt(_);return{origin:jTt(l,_),u:g.u,v:g.v,normal:g.normal,source:{kind:"canonical-face",face:_,owner:BTt(l)}}}if(l instanceof lo){const g=qTt(l).join(", ")||"none";throw new Error(`Face "${_}" not found or is not planar. Available planar faces: ${g}`)}throw new Error(`Named face "${_}" requires a TrackedShape parent or a FaceRef target.`)}function VTt(l,_,g,S){return[l[0],l[1],l[2],0,_[0],_[1],_[2],0,g[0],g[1],g[2],0,S[0],S[1],S[2],1]}function UTt(l,_){const[g,S]=RTt(l,_.selfAnchor),D=[_.workplane.origin[0]+_.workplane.u[0]*_.u+_.workplane.v[0]*_.v+_.workplane.normal[0]*_.protrude,_.workplane.origin[1]+_.workplane.u[1]*_.u+_.workplane.v[1]*_.v+_.workplane.normal[1]*_.protrude,_.workplane.origin[2]+_.workplane.u[2]*_.u+_.workplane.v[2]*_.v+_.workplane.normal[2]*_.protrude],F=VTt(_.workplane.u,_.workplane.v,_.workplane.normal,D);return Sa.translation(-g,-S,0).mul(F).toArray()}function $Tt(l){if(!l||typeof l!="object")return!1;const _=l;return typeof _.name=="string"&&Array.isArray(_.normal)&&Array.isArray(_.center)}function HTt(l,_,g,S={}){const D=$Tt(_);if(D&&typeof g=="string")throw new Error("Sketch.onFace(faceRef, opts) accepts options as the second argument, not a face name.");const F=D?QF(_):QF(_,g),z=(D?g:S)??{},ee={workplane:F,u:z.u??0,v:z.v??0,protrude:z.protrude??0,selfAnchor:z.selfAnchor??"center"};return yP(hP(l.clone(),UTt(l,ee)),ee)}So.prototype.onFace=function(l,_,g={}){return HTt(this,l,_,g)};function vN(l,_,g,S){return DBe({apiName:l,inputs:_,minCount:g,itemName:"sketch",usage:S,coerce:D=>{if(D instanceof So)return D;throw new Error(`expected a Sketch, got ${pee(D)}`)}})}function GTt(l,..._){const g=[l,...vN("Sketch.add()",_,1,"Use sketch.add(other1, other2) or sketch.add([other1, other2]).")],S=NS("union",g.map(D=>tm(D)));return yP(hP(S?Oh(S,l.colorHex):Ty(new So(wd().CrossSection.union(g.map(D=>D.cross)),l.colorHex),null),hN(g)),yN(g))}function XTt(l,..._){const g=[l,...vN("Sketch.subtract()",_,1,"Use sketch.subtract(other1, other2) or sketch.subtract([other1, other2]).")],S=NS("difference",g.map(D=>tm(D)));return yP(hP(S?Oh(S,l.colorHex):Ty(new So(wd().CrossSection.difference(g.map(D=>D.cross)),l.colorHex),null),hN(g)),yN(g))}function QTt(l,..._){const g=[l,...vN("Sketch.intersect()",_,1,"Use sketch.intersect(other1, other2) or sketch.intersect([other1, other2]).")],S=NS("intersection",g.map(D=>tm(D)));return yP(hP(S?Oh(S,l.colorHex):Ty(new So(wd().CrossSection.intersection(g.map(D=>D.cross)),l.colorHex),null),hN(g)),yN(g))}function Fh(...l){const _=vN("union2d()",l,1,"Use union2d(sketch1, sketch2) or union2d([sketch1, sketch2]).");if(_.length===0)throw new Error("union2d requires at least one sketch");if(_.length===1)return _[0];const g=NS("union",_.map(S=>tm(S)));return yP(hP(g?Oh(g,_[0].colorHex):Ty(new So(wd().CrossSection.union(_.map(S=>S.cross)),_[0].colorHex),null),hN(_)),yN(_))}function N1(...l){const _=vN("difference2d()",l,2,"Use difference2d(base, cutter1, cutter2) or difference2d([base, cutter1, cutter2]).");if(_.length<2)throw new Error("difference2d requires at least two sketches");const g=NS("difference",_.map(S=>tm(S)));return yP(hP(g?Oh(g,_[0].colorHex):Ty(new So(wd().CrossSection.difference(_.map(S=>S.cross)),_[0].colorHex),null),hN(_)),yN(_))}function YTt(...l){const _=vN("intersection2d()",l,2,"Use intersection2d(sketch1, sketch2) or intersection2d([sketch1, sketch2]).");if(_.length<2)throw new Error("intersection2d requires at least two sketches");const g=NS("intersection",_.map(S=>tm(S)));return yP(hP(g?Oh(g,_[0].colorHex):Ty(new So(wd().CrossSection.intersection(_.map(S=>S.cross)),_[0].colorHex),null),hN(_)),yN(_))}function ZTt(...l){const _=vN("hull2d()",l,1,"Use hull2d(sketch1, sketch2) or hull2d([sketch1, sketch2]).");if(_.length===0)throw new Error("hull2d requires at least one sketch");const g=wBe(_.map(S=>tm(S)));return yP(hP(g?Oh(g,_[0].colorHex):Ty(new So(wd().CrossSection.hull(_.map(S=>S.cross)),_[0].colorHex),null),hN(_)),yN(_))}So.prototype.add=function(...l){return GTt(this,...l)};So.prototype.subtract=function(...l){return XTt(this,...l)};So.prototype.intersect=function(...l){return QTt(this,...l)};function KTt(l,_,g="Round"){const S=g==="Round"?CBe(tm(l),_,"Round"):null;return X2(l,S?Oh(S,l.colorHex):Ty(new So(l.cross.offset(_,g),l.colorHex),null))}function ekt(l){const _=wBe([tm(l)]);return X2(l,_?Oh(_,l.colorHex):Ty(new So(l.cross.hull(),l.colorHex),null))}function tkt(l,_=1e-6){return X2(l,new So(l.cross.simplify(_),l.colorHex))}function rkt(l,_){return X2(l,new So(l.cross.warp(_),l.colorHex))}So.prototype.offset=function(l,_="Round"){return KTt(this,l,_)};So.prototype.hull=function(){return ekt(this)};So.prototype.simplify=function(l=1e-6){return tkt(this,l)};So.prototype.warp=function(l){return rkt(this,l)};function nkt(l,_,g){const S=new Map,D=new Map,F=l.bounds(),z=(F.min[0]+F.max[0])/2,ee=(F.min[1]+F.max[1])/2,pe=g?-_/2:0,we=g?_/2:_;return S.set("top",{name:"top",normal:[0,0,1],center:[z,ee,we],planar:!0,uAxis:[1,0,0],vAxis:[0,1,0]}),S.set("bottom",{name:"bottom",normal:[0,0,-1],center:[z,ee,pe],planar:!0,uAxis:[1,0,0],vAxis:[0,-1,0]}),S.set("side",{name:"side",normal:[1,0,0],center:[F.max[0],ee,(we+pe)/2],planar:!1}),{faces:S,edges:D}}function FS(l,_,g){const S=typeof(g==null?void 0:g.scaleTop)=="number"?[g.scaleTop,g.scaleTop]:g==null?void 0:g.scaleTop,D=((g==null?void 0:g.twist)==null||g.twist===0)&&((g==null?void 0:g.divisions)==null||g.divisions===0)?(()=>{const nt=tm(l);return nt?{kind:"extrude",profile:nt,height:_,center:(g==null?void 0:g.center)??!1,scaleTop:S}:null})():null,F=xE(l),z=SE(l),ee=D&&F&&z?E1(D,{kind:"workplanePlacement",matrix:F,placement:z}):D,pe=kE(ee,"extrude"),we=pe?k_(pe,l.colorHex,{fidelity:"kernel-native",sources:["extrude"]}):jee(new Ys(l.cross.extrude(_,(g==null?void 0:g.divisions)??0,(g==null?void 0:g.twist)??0,S,(g==null?void 0:g.center)??!1),l.colorHex,{fidelity:"kernel-native",sources:["extrude"]}),null),De=nkt(l,_,(g==null?void 0:g.center)??!1);if(!F)return new lo(we,De,0,!0);const te=MTt(De,F);return pe&&z?new lo(we,te,0,!0):new lo(we.transform(F),te,0,!0)}function ikt(l,_=360,g){const S=(()=>{const we=tm(l);return we?{kind:"revolve",profile:we,degrees:_,segments:g!=null&&g>0?g:void 0}:null})(),D=xE(l),F=SE(l),z=S&&D&&F?E1(S,{kind:"workplanePlacement",matrix:D,placement:F}):S,ee=kE(z,"revolve"),pe=ee?k_(ee,l.colorHex,{fidelity:"kernel-native",sources:["revolve"]}):jee(new Ys(l.cross.revolve(g??0,_),l.colorHex,{fidelity:"kernel-native",sources:["revolve"]}),null);return!D||ee&&F?pe:pe.transform(D)}So.prototype.extrude=function(l,_){return FS(this,l,_)};So.prototype.revolve=function(l=360,_){return ikt(this,l,_)};class DJe{constructor(){of(this,"points",[]);of(this,"x",0);of(this,"y",0)}moveTo(_,g){return this.x=_,this.y=g,this.points.push([_,g]),this}lineTo(_,g){return this.x=_,this.y=g,this.points.push([_,g]),this}lineH(_){return this.lineTo(this.x+_,this.y)}lineV(_){return this.lineTo(this.x,this.y+_)}lineAngled(_,g){const S=g*Math.PI/180;return this.lineTo(this.x+_*Math.cos(S),this.y+_*Math.sin(S))}close(){if(this.points.length<3)throw new Error("Path needs at least 3 points");const _=this.points;let g=0;for(let S=0;S<_.length;S++){const[D,F]=_[S],[z,ee]=_[(S+1)%_.length];g+=(z-D)*(ee+F)}return g>0&&_.reverse(),Ed(_)}stroke(_,g="Square"){if(this.points.length<2)throw new Error("Stroke needs at least 2 points");const S=_/2,D=this.points,F=D.length,z=[];for(let nt=0;nt<F-1;nt++){const Te=D[nt+1][0]-D[nt][0],Me=D[nt+1][1]-D[nt][1],bt=Math.sqrt(Te*Te+Me*Me);z.push([-Me/bt,Te/bt])}const ee=[],pe=[];for(let nt=0;nt<F;nt++){const[Te,Me]=D[nt];if(nt===0||nt===F-1){const bt=z[nt===0?0:F-2];ee.push([Te+bt[0]*S,Me+bt[1]*S]),pe.push([Te-bt[0]*S,Me-bt[1]*S])}else{const bt=z[nt-1],vt=z[nt];let Bt=bt[0]+vt[0],fr=bt[1]+vt[1],hn=Math.sqrt(Bt*Bt+fr*fr);hn<1e-9&&(Bt=bt[0],fr=bt[1],hn=1),Bt/=hn,fr/=hn;const vr=S/(Bt*bt[0]+fr*bt[1]);ee.push([Te+Bt*vr,Me+fr*vr]),pe.push([Te-Bt*vr,Me-fr*vr])}}const we=[...ee,...pe.reverse()];let De=0;for(let nt=0;nt<we.length;nt++){const[Te,Me]=we[nt],[bt,vt]=we[(nt+1)%we.length];De+=(bt-Te)*(vt+Me)}De>0&&we.reverse();let te=Ed(we);return g==="Round"&&(te=te.offset(-S/2,"Round").offset(S/2,"Round")),te}}function skt(){return new DJe}function _be(l,_,g="Square"){const S=new DJe;S.moveTo(l[0][0],l[0][1]);for(let D=1;D<l.length;D++)S.lineTo(l[D][0],l[D][1]);return S.stroke(_,g)}function yje(l,_){const g=l.bounds(),[S,D]=g.min,[F,z]=g.max,ee=(S+F)/2,pe=(D+z)/2;switch(_){case"center":return[ee,pe];case"top-left":return[S,z];case"top-right":return[F,z];case"bottom-left":return[S,D];case"bottom-right":return[F,D];case"top":return[ee,z];case"bottom":return[ee,D];case"left":return[S,pe];case"right":return[F,pe]}}function akt(l,_,g,S="center",D){const F=yje(_,g),z=yje(l,S);let ee=F[0]-z[0],pe=F[1]-z[1];return D&&(ee+=D[0],pe+=D[1]),l.translate(ee,pe)}So.prototype.attachTo=function(l,_,g="center",S){return akt(this,l,_,g,S)};const xee=.001,PJe=l=>l*Math.PI/180,rN=(l,_)=>{const g=_.x-l.x,S=_.y-l.y;return Math.sqrt(g*g+S*S)},w1=(l,_)=>[(l.x+_.x)/2,(l.y+_.y)/2],vje=(l,_)=>{const g=rN(l,_)||1;return[(_.x-l.x)/g,(_.y-l.y)/g]},bje=(l,_)=>Math.atan2(_.y-l.y,_.x-l.x),okt=l=>{let _=l;for(;_>Math.PI;)_-=Math.PI*2;for(;_<-Math.PI;)_+=Math.PI*2;return _},AJe=(l,_,g)=>{const S=g.x-_.x,D=g.y-_.y,F=S*S+D*D;if(F<1e-9)return[_.x,_.y];const z=((l.x-_.x)*S+(l.y-_.y)*D)/F;return[_.x+z*S,_.y+z*D]},xje=(l,_,g)=>{const S=AJe(l,_,g);return[2*S[0]-l.x,2*S[1]-l.y]},NJe=l=>({points:l.points.map(_=>({..._})),lines:l.lines.map(_=>({..._})),circles:l.circles.map(_=>({..._})),loops:l.loops.map(_=>_.type==="poly"?{type:"poly",points:[..._.points]}:{type:"circle",circle:_.circle}),constraints:l.constraints.map(_=>({..._})),rejectedConstraints:l.rejectedConstraints.map(_=>({..._}))}),ckt=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"}},lkt=l=>l==="distance"||l==="length"||l==="angle"||l==="radius"||l==="diameter"||l==="hDistance"||l==="vDistance",ukt=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},_kt=(l,_)=>{l.type==="distance"&&(l.value=_),l.type==="length"&&(l.value=_),l.type==="angle"&&(l.value=_),l.type==="radius"&&(l.value=_),l.type==="diameter"&&(l.value=_),l.type==="hDistance"&&(l.value=_),l.type==="vDistance"&&(l.value=_)},Sje=(l,_)=>{const g=new Map(l.points.map(z=>[z.id,z])),S=new Map(l.lines.map(z=>[z.id,z])),D=new Map(l.circles.map(z=>[z.id,z])),F=[];return l.constraints.forEach(z=>{let ee=[0,0];if(z.type==="coincident"||z.type==="distance"||z.type==="hDistance"||z.type==="vDistance"){const pe=g.get(z.a),we=g.get(z.b);pe&&we&&(ee=w1(pe,we))}else if(z.type==="horizontal"||z.type==="vertical"||z.type==="length"){const pe=S.get(z.line);if(pe){const we=g.get(pe.a),De=g.get(pe.b);we&&De&&(ee=w1(we,De))}}else if(z.type==="parallel"||z.type==="perpendicular"||z.type==="equal"||z.type==="angle"){const pe=S.get(z.a),we=S.get(z.b);if(pe&&we){const De=g.get(pe.a),te=g.get(pe.b),nt=g.get(we.a),Te=g.get(we.b);if(De&&te&&nt&&Te){const Me=w1(De,te),bt=w1(nt,Te);ee=[(Me[0]+bt[0])/2,(Me[1]+bt[1])/2]}}}else if(z.type==="radius"||z.type==="diameter"){const pe=D.get(z.circle);if(pe){const we=g.get(pe.center);we&&(ee=[we.x+pe.radius,we.y])}}else if(z.type==="concentric"){const pe=D.get(z.a),we=D.get(z.b);if(pe&&we){const De=g.get(pe.center),te=g.get(we.center);De&&te&&(ee=w1(De,te))}}else if(z.type==="collinear"){const pe=g.get(z.point);pe&&(ee=[pe.x,pe.y])}else if(z.type==="fixed"){const pe=g.get(z.point);pe&&(ee=[pe.x,pe.y])}else if(z.type==="symmetric"){const pe=g.get(z.a),we=g.get(z.b);pe&&we&&(ee=w1(pe,we))}else if(z.type==="tangent"){if(z.line&&z.circle){const pe=S.get(z.line),we=D.get(z.circle);if(pe&&we){const De=g.get(pe.a),te=g.get(pe.b);De&&te&&(ee=w1(De,te))}}else if(z.a&&z.b){const pe=D.get(z.a),we=D.get(z.b);if(pe&&we){const De=g.get(pe.center),te=g.get(we.center);De&&te&&(ee=w1(De,te))}}}F.push({id:z.id,type:z.type,label:ckt(z.type),position:ee,value:ukt(z),isDimension:lkt(z.type),isConflicting:_.has(z.id)})}),F},fkt=l=>{const _=[];if(l.loops.forEach(g=>{if(g.type==="poly"){const S=g.points.map(D=>{const F=l.points.find(z=>z.id===D);if(!F)throw new Error(`Missing point ${D}`);return[F.x,F.y]});S.length>=3&&_.push(Ed(S))}else if(g.type==="circle"){const S=l.circles.find(z=>z.id===g.circle);if(!S)throw new Error(`Missing circle ${g.circle}`);const D=l.points.find(z=>z.id===S.center);if(!D)throw new Error(`Missing center ${S.center}`);const F=new So(wd().CrossSection.circle(S.radius,S.segments));_.push(F.translate(D.x,D.y))}}),_.length===0)throw new Error("Constrained sketch needs at least one closed loop");return Fh(..._)},pkt=l=>{const _=new Map(l.points.map(D=>[D.id,D])),g=l.lines.filter(D=>D.construction).map(D=>{const F=_.get(D.a),z=_.get(D.b);return!F||!z?null:{a:[F.x,F.y],b:[z.x,z.y]}}).filter(D=>D!==null),S=l.circles.filter(D=>D.construction).map(D=>{const F=_.get(D.center);return F?{center:[F.x,F.y],radius:D.radius}:null}).filter(D=>D!==null);return{lines:g,circles:S}},dkt=(l,_)=>{l.fixed=!0,l.x=_.x,l.y=_.y},IJe=(l,_)=>{const g=_.iterations??40,S=_.tolerance??xee,D=new Map(l.points.map(we=>[we.id,we])),F=new Map(l.lines.map(we=>[we.id,we])),z=new Map(l.circles.map(we=>[we.id,we]));l.constraints.forEach(we=>{if(we.type==="fixed"){const De=D.get(we.point);De&&dkt(De,we)}});const ee=(we,De,te)=>we.fixed?!1:(we.x+=De,we.y+=te,!0);let pe=0;for(let we=0;we<g&&(pe=0,l.constraints.forEach(De=>{let te=0;if(De.type==="coincident"){const nt=D.get(De.a),Te=D.get(De.b);if(!nt||!Te)return;const Me=Te.x-nt.x,bt=Te.y-nt.y;if(te=Math.sqrt(Me*Me+bt*bt),te<=S||nt.fixed&&Te.fixed)return;if(nt.fixed){Te.x=nt.x,Te.y=nt.y;return}if(Te.fixed){nt.x=Te.x,nt.y=Te.y;return}const vt=(nt.x+Te.x)/2,Bt=(nt.y+Te.y)/2;nt.x=vt,nt.y=Bt,Te.x=vt,Te.y=Bt}if(De.type==="horizontal"){const nt=F.get(De.line);if(!nt)return;const Te=D.get(nt.a),Me=D.get(nt.b);if(!Te||!Me||(te=Math.abs(Me.y-Te.y),te<=S)||Te.fixed&&Me.fixed)return;const bt=(Te.y+Me.y)/2;Te.fixed||(Te.y=bt),Me.fixed||(Me.y=bt)}if(De.type==="vertical"){const nt=F.get(De.line);if(!nt)return;const Te=D.get(nt.a),Me=D.get(nt.b);if(!Te||!Me||(te=Math.abs(Me.x-Te.x),te<=S)||Te.fixed&&Me.fixed)return;const bt=(Te.x+Me.x)/2;Te.fixed||(Te.x=bt),Me.fixed||(Me.x=bt)}if(De.type==="parallel"||De.type==="perpendicular"||De.type==="angle"){const nt=F.get(De.a),Te=F.get(De.b);if(!nt||!Te)return;const Me=D.get(nt.a),bt=D.get(nt.b),vt=D.get(Te.a),Bt=D.get(Te.b);if(!Me||!bt||!vt||!Bt)return;const fr=bje(Me,bt),hn=De.type==="parallel"?fr:De.type==="perpendicular"?fr+Math.PI/2:fr+PJe(De.value),vr=bje(vt,Bt),Xt=okt(vr-hn);if(te=Math.abs(Xt),te<=S||vt.fixed&&Bt.fixed)return;const Wt=rN(vt,Bt)||1,Hn=[Math.cos(hn),Math.sin(hn)];if(vt.fixed)Bt.x=vt.x+Hn[0]*Wt,Bt.y=vt.y+Hn[1]*Wt;else if(Bt.fixed)vt.x=Bt.x-Hn[0]*Wt,vt.y=Bt.y-Hn[1]*Wt;else{const zn=w1(vt,Bt);vt.x=zn[0]-Hn[0]*Wt/2,vt.y=zn[1]-Hn[1]*Wt/2,Bt.x=zn[0]+Hn[0]*Wt/2,Bt.y=zn[1]+Hn[1]*Wt/2}}if(De.type==="equal"){const nt=F.get(De.a),Te=F.get(De.b);if(!nt||!Te)return;const Me=D.get(nt.a),bt=D.get(nt.b),vt=D.get(Te.a),Bt=D.get(Te.b);if(!Me||!bt||!vt||!Bt)return;const fr=rN(Me,bt),hn=rN(vt,Bt)||1;if(te=Math.abs(hn-fr),te<=S||vt.fixed&&Bt.fixed)return;const vr=vje(vt,Bt);if(vt.fixed)Bt.x=vt.x+vr[0]*fr,Bt.y=vt.y+vr[1]*fr;else if(Bt.fixed)vt.x=Bt.x-vr[0]*fr,vt.y=Bt.y-vr[1]*fr;else{const Xt=w1(vt,Bt);vt.x=Xt[0]-vr[0]*fr/2,vt.y=Xt[1]-vr[1]*fr/2,Bt.x=Xt[0]+vr[0]*fr/2,Bt.y=Xt[1]+vr[1]*fr/2}}if(De.type==="distance"){const nt=D.get(De.a),Te=D.get(De.b);if(!nt||!Te)return;const Me=rN(nt,Te)||1;if(te=Math.abs(Me-De.value),te<=S)return;const bt=[(Te.x-nt.x)/Me,(Te.y-nt.y)/Me];if(nt.fixed&&Te.fixed)return;if(nt.fixed)Te.x=nt.x+bt[0]*De.value,Te.y=nt.y+bt[1]*De.value;else if(Te.fixed)nt.x=Te.x-bt[0]*De.value,nt.y=Te.y-bt[1]*De.value;else{const vt=w1(nt,Te);nt.x=vt[0]-bt[0]*De.value/2,nt.y=vt[1]-bt[1]*De.value/2,Te.x=vt[0]+bt[0]*De.value/2,Te.y=vt[1]+bt[1]*De.value/2}}if(De.type==="length"){const nt=F.get(De.line);if(!nt)return;const Te=D.get(nt.a),Me=D.get(nt.b);if(!Te||!Me)return;const bt=rN(Te,Me)||1;if(te=Math.abs(bt-De.value),te<=S)return;const vt=vje(Te,Me);if(Te.fixed&&Me.fixed)return;if(Te.fixed)Me.x=Te.x+vt[0]*De.value,Me.y=Te.y+vt[1]*De.value;else if(Me.fixed)Te.x=Me.x-vt[0]*De.value,Te.y=Me.y-vt[1]*De.value;else{const Bt=w1(Te,Me);Te.x=Bt[0]-vt[0]*De.value/2,Te.y=Bt[1]-vt[1]*De.value/2,Me.x=Bt[0]+vt[0]*De.value/2,Me.y=Bt[1]+vt[1]*De.value/2}}if(De.type==="radius"||De.type==="diameter"){const nt=z.get(De.circle);if(!nt)return;const Te=De.type==="radius"?De.value:De.value/2;if(te=Math.abs(nt.radius-Te),te<=S)return;nt.fixedRadius||(nt.radius=Te)}if(De.type==="hDistance"){const nt=D.get(De.a),Te=D.get(De.b);if(!nt||!Te||(te=Math.abs(Te.x-nt.x-De.value),te<=S)||nt.fixed&&Te.fixed)return;if(nt.fixed)Te.x=nt.x+De.value;else if(Te.fixed)nt.x=Te.x-De.value;else{const Me=(nt.x+Te.x)/2;nt.x=Me-De.value/2,Te.x=Me+De.value/2}}if(De.type==="vDistance"){const nt=D.get(De.a),Te=D.get(De.b);if(!nt||!Te||(te=Math.abs(Te.y-nt.y-De.value),te<=S)||nt.fixed&&Te.fixed)return;if(nt.fixed)Te.y=nt.y+De.value;else if(Te.fixed)nt.y=Te.y-De.value;else{const Me=(nt.y+Te.y)/2;nt.y=Me-De.value/2,Te.y=Me+De.value/2}}if(De.type==="concentric"){const nt=z.get(De.a),Te=z.get(De.b);if(!nt||!Te)return;const Me=D.get(nt.center),bt=D.get(Te.center);if(!Me||!bt)return;const vt=bt.x-Me.x,Bt=bt.y-Me.y;if(te=Math.sqrt(vt*vt+Bt*Bt),te<=S||Me.fixed&&bt.fixed)return;if(Me.fixed)bt.x=Me.x,bt.y=Me.y;else if(bt.fixed)Me.x=bt.x,Me.y=bt.y;else{const fr=w1(Me,bt);Me.x=fr[0],Me.y=fr[1],bt.x=fr[0],bt.y=fr[1]}}if(De.type==="collinear"){const nt=D.get(De.point),Te=F.get(De.line);if(!nt||!Te)return;const Me=D.get(Te.a),bt=D.get(Te.b);if(!Me||!bt)return;const vt=AJe(nt,Me,bt);if(te=Math.sqrt((nt.x-vt[0])**2+(nt.y-vt[1])**2),te<=S)return;if(!nt.fixed)nt.x=vt[0],nt.y=vt[1];else{const Bt=vt[0]-nt.x,fr=vt[1]-nt.y;Me.fixed||ee(Me,-Bt,-fr),bt.fixed||ee(bt,-Bt,-fr)}}if(De.type==="symmetric"){const nt=D.get(De.a),Te=D.get(De.b),Me=F.get(De.axis);if(!nt||!Te||!Me)return;const bt=D.get(Me.a),vt=D.get(Me.b);if(!bt||!vt)return;const Bt=xje(nt,bt,vt),fr=xje(Te,bt,vt);if(te=Math.sqrt((Te.x-Bt[0])**2+(Te.y-Bt[1])**2),te<=S||nt.fixed&&Te.fixed)return;nt.fixed?(Te.x=Bt[0],Te.y=Bt[1]):Te.fixed?(nt.x=fr[0],nt.y=fr[1]):(Te.x=Bt[0],Te.y=Bt[1])}if(De.type==="tangent"){if(De.line&&De.circle){const nt=F.get(De.line),Te=z.get(De.circle);if(!nt||!Te)return;const Me=D.get(nt.a),bt=D.get(nt.b),vt=D.get(Te.center);if(!Me||!bt||!vt)return;const Bt=bt.x-Me.x,fr=bt.y-Me.y,hn=Math.sqrt(Bt*Bt+fr*fr)||1,vr=-fr/hn,Xt=Bt/hn,Wt=(vt.x-Me.x)*vr+(vt.y-Me.y)*Xt;if(te=Math.abs(Math.abs(Wt)-Te.radius),te<=S)return;const Hn=Wt>0?Wt-Te.radius:Wt+Te.radius;!Me.fixed||!bt.fixed?(Me.fixed||(Me.x+=vr*-Hn,Me.y+=Xt*-Hn),bt.fixed||(bt.x+=vr*-Hn,bt.y+=Xt*-Hn)):vt.fixed||(vt.x+=vr*-Hn,vt.y+=Xt*-Hn)}else if(De.a&&De.b){const nt=z.get(De.a),Te=z.get(De.b);if(!nt||!Te)return;const Me=D.get(nt.center),bt=D.get(Te.center);if(!Me||!bt)return;const vt=nt.radius+Te.radius,Bt=rN(Me,bt)||1;if(te=Math.abs(Bt-vt),te<=S)return;const fr=[(bt.x-Me.x)/Bt,(bt.y-Me.y)/Bt];if(Me.fixed&&bt.fixed)return;if(Me.fixed)bt.x=Me.x+fr[0]*vt,bt.y=Me.y+fr[1]*vt;else if(bt.fixed)Me.x=bt.x-fr[0]*vt,Me.y=bt.y-fr[1]*vt;else{const hn=w1(Me,bt);Me.x=hn[0]-fr[0]*vt/2,Me.y=hn[1]-fr[1]*vt/2,bt.x=hn[0]+fr[0]*vt/2,bt.y=hn[1]+fr[1]*vt/2}}}pe=Math.max(pe,te)}),!(pe<=S));we+=1);return{maxError:pe}},mkt=(l,_,g)=>{if(_>g*5)return"over";const S=new Map;return l.points.forEach(F=>S.set(F.id,0)),l.constraints.forEach(F=>{if(F.type==="fixed"){const z=S.get(F.point)??0;S.set(F.point,z+2);return}if(F.type==="coincident"||F.type==="distance"||F.type==="hDistance"||F.type==="vDistance"){S.set(F.a,(S.get(F.a)??0)+1),S.set(F.b,(S.get(F.b)??0)+1);return}if(F.type==="collinear"){S.set(F.point,(S.get(F.point)??0)+1);return}if(F.type==="symmetric"){S.set(F.a,(S.get(F.a)??0)+1),S.set(F.b,(S.get(F.b)??0)+1);return}if(F.type==="horizontal"||F.type==="vertical"||F.type==="length"){const z=l.lines.find(ee=>ee.id===F.line);z&&(S.set(z.a,(S.get(z.a)??0)+1),S.set(z.b,(S.get(z.b)??0)+1));return}if(F.type==="parallel"||F.type==="perpendicular"||F.type==="equal"||F.type==="angle"){const z=l.lines.find(pe=>pe.id===F.a),ee=l.lines.find(pe=>pe.id===F.b);z&&(S.set(z.a,(S.get(z.a)??0)+1),S.set(z.b,(S.get(z.b)??0)+1)),ee&&(S.set(ee.a,(S.get(ee.a)??0)+1),S.set(ee.b,(S.get(ee.b)??0)+1));return}}),l.points.some(F=>!F.fixed&&(S.get(F.id)??0)<2)?"under":"fully"};class See extends So{constructor(_,g,S){super(_),this.constraintMeta=g,this.definition=S}withUpdatedConstraint(_,g){const S=NJe(this.definition),D=S.constraints.find(F=>F.id===_);return D?(_kt(D,g),FJe(S)):this}}const gkt=l=>l instanceof See;class hkt{constructor(){of(this,"points",[]);of(this,"lines",[]);of(this,"circles",[]);of(this,"constraints",[]);of(this,"loops",[]);of(this,"rejectedConstraints",[]);of(this,"cursor",null);of(this,"loopStart",null);of(this,"nextId",1)}point(_,g,S=!1){const D=`pt-${this.nextId++}`;return this.points.push({id:D,x:_,y:g,fixed:S}),D}pointAt(_){const g=this.points[_];if(!g)throw new Error(`Point index ${_} out of range`);return g.id}line(_,g,S=!1){const D=`ln-${this.nextId++}`;return this.lines.push({id:D,a:_,b:g,construction:S}),D}lineAt(_){const g=this.lines[_];if(!g)throw new Error(`Line index ${_} out of range`);return g.id}circle(_,g,S=!1,D=48){const F=`c-${this.nextId++}`;return this.circles.push({id:F,center:_,radius:g,construction:S,fixedRadius:!1,segments:D}),S||this.loops.push({type:"circle",circle:F}),F}circleAt(_){const g=this.circles[_];if(!g)throw new Error(`Circle index ${_} out of range`);return g.id}moveTo(_,g){const S=this.point(_,g);return this.cursor=S,this.loopStart=S,this.loops.push({type:"poly",points:[S]}),this}lineTo(_,g){if(!this.cursor)return this.moveTo(_,g);const S=this.point(_,g);this.line(this.cursor,S);const D=this.loops[this.loops.length-1];return D&&D.type==="poly"&&D.points.push(S),this.cursor=S,this}lineH(_){const g=this.getPoint(this.cursor);return g?this.lineTo(g.x+_,g.y):this}lineV(_){const g=this.getPoint(this.cursor);return g?this.lineTo(g.x,g.y+_):this}lineAngled(_,g){const S=this.getPoint(this.cursor);if(!S)return this;const D=PJe(g);return this.lineTo(S.x+Math.cos(D)*_,S.y+Math.sin(D)*_)}close(){return!this.cursor||!this.loopStart||this.cursor===this.loopStart?this:(this.line(this.cursor,this.loopStart),this.cursor=this.loopStart,this)}addLoopCircle(_,g,S=48){return this.circle(_,g,!1,S),this}constrain(_){const g=`cst-${this.nextId++}`,S={..._,id:g},D=this.buildDefinition(S),{maxError:F}=IJe(D,{iterations:30,tolerance:xee});if(F>xee*5)return this.rejectedConstraints.push(S),this;if(S.type==="fixed"){const z=this.points.find(ee=>ee.id===S.point);z&&(z.fixed=!0,z.x=S.x,z.y=S.y)}return this.constraints.push(S),this}solve(_={}){return FJe(this.buildDefinition(),_)}buildDefinition(_){return{points:this.points.map(g=>({...g})),lines:this.lines.map(g=>({...g})),circles:this.circles.map(g=>({...g})),loops:this.loops.map(g=>g.type==="poly"?{type:"poly",points:[...g.points]}:{type:"circle",circle:g.circle}),constraints:_?[...this.constraints,_]:[...this.constraints],rejectedConstraints:[...this.rejectedConstraints]}}getPoint(_){return _?this.points.find(g=>g.id===_)??null:null}importPoint(_,g=!1){return this.point(_.x,_.y,g)}importLine(_,g=!1){const S=this.importPoint(_.start,g),D=this.importPoint(_.end,g);return this.line(S,D)}importRectangle(_,g=!1){const[S,D,F,z]=_.vertices.map(ee=>this.importPoint(ee,g));return{bottom:this.line(S,D),right:this.line(D,F),top:this.line(F,z),left:this.line(z,S),points:[S,D,F,z]}}}function ykt(){return new hkt}const FJe=(l,_={})=>{const g=NJe(l),S=_.tolerance??xee,{maxError:D}=IJe(g,_),F=mkt(g,D,S),z=new Set(F==="over"?g.constraints.map(te=>te.id):[]),ee=Sje(g,z),pe=Sje({...g,constraints:g.rejectedConstraints},new Set(g.rejectedConstraints.map(te=>te.id))),we=fkt(g),De=pkt(g);return new See(we.cross,{status:F,maxError:D,constraints:ee,rejected:pe,construction:De},g)};class J_{constructor(_,g){this.x=_,this.y=g}distanceTo(_){const g=_.x-this.x,S=_.y-this.y;return Math.sqrt(g*g+S*S)}midpointTo(_){return new J_((this.x+_.x)/2,(this.y+_.y)/2)}translate(_,g){return new J_(this.x+_,this.y+g)}toTuple(){return[this.x,this.y]}}function vkt(l,_){return new J_(l,_)}class ob{constructor(_,g){this.start=_,this.end=g}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 _=this.length||1;return[(this.end.x-this.start.x)/_,(this.end.y-this.start.y)/_]}parallel(_){const[g,S]=this.direction,D=-S*_,F=g*_;return new ob(this.start.translate(D,F),this.end.translate(D,F))}intersect(_){const g=this.start.x,S=this.start.y,D=this.end.x,F=this.end.y,z=_.start.x,ee=_.start.y,pe=_.end.x,we=_.end.y,De=(g-D)*(ee-we)-(S-F)*(z-pe);if(Math.abs(De)<1e-12)return null;const te=((g-z)*(ee-we)-(S-ee)*(z-pe))/De;return new J_(g+te*(D-g),S+te*(F-S))}intersectSegment(_){const g=this.start.x,S=this.start.y,D=this.end.x,F=this.end.y,z=_.start.x,ee=_.start.y,pe=_.end.x,we=_.end.y,De=(g-D)*(ee-we)-(S-F)*(z-pe);if(Math.abs(De)<1e-12)return null;const te=((g-z)*(ee-we)-(S-ee)*(z-pe))/De,nt=-((g-D)*(S-ee)-(S-F)*(g-z))/De;return te<-1e-12||te>1+1e-12||nt<-1e-12||nt>1+1e-12?null:new J_(g+te*(D-g),S+te*(F-S))}static fromCoordinates(_,g,S,D){return new ob(new J_(_,g),new J_(S,D))}static fromPointAndAngle(_,g,S){const D=g*(Math.PI/180);return new ob(_,new J_(_.x+Math.cos(D)*S,_.y+Math.sin(D)*S))}static fromPointAndDirection(_,g,S){const D=Math.sqrt(g[0]*g[0]+g[1]*g[1])||1;return new ob(_,new J_(_.x+g[0]/D*S,_.y+g[1]/D*S))}}function bkt(l,_,g,S){return ob.fromCoordinates(l,_,g,S)}class zF{constructor(_,g){this.center=_,this.radius=g}get diameter(){return this.radius*2}get circumference(){return 2*Math.PI*this.radius}get area(){return Math.PI*this.radius*this.radius}pointAtAngle(_){const g=_*Math.PI/180;return new J_(this.center.x+Math.cos(g)*this.radius,this.center.y+Math.sin(g)*this.radius)}translate(_,g){return new zF(this.center.translate(_,g),this.radius)}toSketch(_){const S=wd().CrossSection.circle(this.radius,_??0).translate([this.center.x,this.center.y]);return new So(S)}extrude(_,g){const S=this.toSketch(g),D=FS(S,_),F=EJe(this,_);return new lo(D.shape,F,_,!0)}static fromCenterAndRadius(_,g){return new zF(_,g)}static fromDiameter(_,g){return new zF(_,g/2)}}function xkt(l,_,g){return new zF(new J_(l,_),g)}class zk{constructor(_){of(this,"vertices");this.vertices=_}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(_){const[g,S,D,F]=this.vertices;switch(_){case"bottom":return new ob(g,S);case"right":return new ob(S,D);case"top":return new ob(D,F);case"left":return new ob(F,g)}}sideAt(_){const g=["bottom","right","top","left"];return this.side(g[_%4])}vertex(_){const[g,S,D,F]=this.vertices;switch(_){case"bottom-left":return g;case"bottom-right":return S;case"top-right":return D;case"top-left":return F}}diagonals(){const[_,g,S,D]=this.vertices;return[new ob(_,S),new ob(g,D)]}toSketch(){return Ed(this.vertices.map(_=>_.toTuple()))}translate(_,g){return new zk(this.vertices.map(S=>S.translate(_,g)))}static fromDimensions(_,g,S,D){return new zk([new J_(_,g),new J_(_+S,g),new J_(_+S,g+D),new J_(_,g+D)])}static fromCenterAndDimensions(_,g,S){const D=g/2,F=S/2;return new zk([new J_(_.x-D,_.y-F),new J_(_.x+D,_.y-F),new J_(_.x+D,_.y+F),new J_(_.x-D,_.y+F)])}static from2Corners(_,g){const S=Math.min(_.x,g.x),D=Math.max(_.x,g.x),F=Math.min(_.y,g.y),z=Math.max(_.y,g.y);return new zk([new J_(S,F),new J_(D,F),new J_(D,z),new J_(S,z)])}static from3Points(_,g,S){const D=g.x-_.x,F=g.y-_.y,z=Math.sqrt(D*D+F*F)||1,ee=D/z,we=-(F/z),De=ee,te=(S.x-_.x)*we+(S.y-_.y)*De;return new zk([_,g,new J_(g.x+we*te,g.y+De*te),new J_(_.x+we*te,_.y+De*te)])}extrude(_,g=!0){const S=this.toSketch(),D=Math.abs(_),F=FS(S,D),z=g?F.shape:F.shape.translate(0,0,-D),ee=wJe(this,D,g);return new lo(z,ee,D,g)}}function Skt(l,_,g,S){return zk.fromDimensions(l,_,g,S)}function Tkt(l){return l}function kkt(l){return l*(180/Math.PI)}function kS(l,_){return typeof _=="string"?_:l.importLine(_)}function DJ(l,_){return typeof _=="string"?_:l.importPoint(_)}const Ckt={makeParallel(l,_,g){return l.constrain({type:"parallel",a:kS(l,_),b:kS(l,g)})},enforceAngle(l,_,g,S){return l.constrain({type:"angle",a:kS(l,_),b:kS(l,g),value:S})},horizontal(l,_){return l.constrain({type:"horizontal",line:kS(l,_)})},vertical(l,_){return l.constrain({type:"vertical",line:kS(l,_)})},equalLength(l,_,g){return l.constrain({type:"equal",a:kS(l,_),b:kS(l,g)})},distance(l,_,g,S){return l.constrain({type:"distance",a:DJ(l,_),b:DJ(l,g),value:S})},fix(l,_,g,S){return l.constrain({type:"fixed",point:DJ(l,_),x:g,y:S})},coincident(l,_,g){return l.constrain({type:"coincident",a:DJ(l,_),b:DJ(l,g)})},perpendicular(l,_,g){return l.constrain({type:"perpendicular",a:kS(l,_),b:kS(l,g)})},length(l,_,g){return l.constrain({type:"length",line:kS(l,_),value:g})}},fbe=l=>l instanceof lo?l.toShape():l;function OJe(l,_,g){return jee(l,jBe(gP(l),rSt(_,g)))}function wkt(l,_,g,S,D=0){const F=fbe(l),z=[];for(let ee=0;ee<_;ee++){const pe=ee===0?F.clone():F.translate(g*ee,S*ee,D*ee);z.push(OJe(pe,"linear",ee))}return I1(...z)}function Ekt(l,_,g=0,S=0){const D=fbe(l),F=360/_,z=[];for(let ee=0;ee<_;ee++){const pe=ee===0?D.clone():D.translate(-g,-S,0).rotate(0,0,F*ee).translate(g,S,0);z.push(OJe(pe,"circular",ee))}return I1(...z)}function Dkt(l,_){const g=fbe(l);return I1(g,g.mirror(_))}function MJe(l){return l instanceof lo?l.toShape():l}function LJe(l,_){const g=l??[-1,-1],S=Math.sign(g[0]),D=Math.sign(g[1]);if(S!==1&&S!==-1||D!==1&&D!==-1)throw new Error(`${_} requires quadrant signs of either 1 or -1.`);return[S,D]}function Pkt(l,_){return _?bJe(l).some(g=>cb(g,_)):!0}function RJe(l,_,g){var S;if(!Pkt(l,(S=_.query)==null?void 0:S.owner))throw new Error(`${g} requires an edge query owned by the target shape or one of its preserved query ancestors.`)}function jJe(l,_,g,S){if(!l)return null;const D=Nee(_);return KJ(rbe(l,Kxt(_,D,g,S.filter(F=>F!=null))),D)}function BJe(l,_,g){if(!_)throw new Error(`Could not record compiler intent for ${g} on this target shape.`);const S=vJe(l),D=k_(_,l.colorHex,{backend:S.backend,representation:S.representation,fidelity:S.fidelity,topology:"none",sources:[g,...S.sources]});return yee(D,lbe(l)),Lee(D,yJe(l),{merge:!1}),Ree(D,{backend:S.backend,representation:S.representation,fidelity:S.fidelity,topology:"none",sources:[g,...S.sources]}),D}function Akt(l,_,g,S=[-1,-1],D=16){if(!Number.isFinite(g)||!(g>0))throw new Error("filletEdge() requires a positive finite radius.");if(!Number.isFinite(D)||D<2)throw new Error("filletEdge() requires at least 2 segments.");const F=MJe(l);RJe(F,_,"filletEdge()");const z=gP(F);if(!z)throw new Error("filletEdge() currently requires a compile-covered target shape.");const ee=LJe(S,"filletEdge()"),pe=_N(z,_.query);if(!pe.ok)throw new Error(`filletEdge(): ${pe.issue.reason}`);const we=lJe(z,_.query);if(pe.selection.quadrant[0]!==ee[0]||pe.selection.quadrant[1]!==ee[1])throw new Error(`filletEdge() currently supports ${pe.selection.edgeName} only with quadrant [${pe.selection.quadrant[0]}, ${pe.selection.quadrant[1]}].`);const De=jJe($2t(z,pe.query,g,ee,Math.round(D)),"fillet",pe.query,we);return BJe(F,De,"fillet")}function Nkt(l,_,g,S=[-1,-1]){if(!Number.isFinite(g)||!(g>0))throw new Error("chamferEdge() requires a positive finite size.");const D=MJe(l);RJe(D,_,"chamferEdge()");const F=gP(D);if(!F)throw new Error("chamferEdge() currently requires a compile-covered target shape.");const z=LJe(S,"chamferEdge()"),ee=_N(F,_.query);if(!ee.ok)throw new Error(`chamferEdge(): ${ee.issue.reason}`);const pe=lJe(F,_.query);if(ee.selection.quadrant[0]!==z[0]||ee.selection.quadrant[1]!==z[1])throw new Error(`chamferEdge() currently supports ${ee.selection.edgeName} only with quadrant [${ee.selection.quadrant[0]}, ${ee.selection.quadrant[1]}].`);const we=jJe(H2t(F,ee.query,g,z),"chamfer",ee.query,pe);return BJe(D,we,"chamfer")}const uP=1e-8;function Ikt(l){return Array.isArray(l)?[l[0],l[1]]:[l.x,l.y]}function wve(l,_){const g=_[0]-l[0],S=_[1]-l[1];return Math.hypot(g,S)}function tve(l,_){const g=Math.hypot(l,_);if(g<=uP)throw new Error("filletCorners requires non-degenerate edges");return[l/g,_/g]}function Fkt(l,_,g){return Math.max(_,Math.min(g,l))}function Okt(l){let _=0;for(let g=0;g<l.length;g+=1){const[S,D]=l[g],[F,z]=l[(g+1)%l.length];_+=S*z-F*D}return _/2}function Mkt(l){return Math.max(3,Math.ceil(Math.abs(l)/(Math.PI/15)))}function Tje(l,_,g=1e-6){return Math.abs(l[0]-_[0])<=g&&Math.abs(l[1]-_[1])<=g}function Lkt(l,_,g){const S=l.length;if(!Number.isInteger(_.index)||_.index<0||_.index>=S)throw new Error(`filletCorners corner index ${_.index} is out of range for ${S} points`);if(!(_.radius>0))throw new Error(`filletCorners corner ${_.index} must have a positive radius`);const D=l[(_.index-1+S)%S],F=l[_.index],z=l[(_.index+1)%S],ee=wve(D,F),pe=wve(F,z),[we,De]=tve(F[0]-D[0],F[1]-D[1]),[te,nt]=tve(z[0]-F[0],z[1]-F[1]);if((we*nt-De*te)*g<=uP)throw new Error(`filletCorners corner ${_.index} is concave or collinear; only convex corners are supported`);const Me=[-we,-De],bt=[te,nt],vt=Math.acos(Fkt(Me[0]*bt[0]+Me[1]*bt[1],-1,1));if(vt<=uP||vt>=Math.PI-uP)throw new Error(`filletCorners corner ${_.index} has an unsupported angle`);const Bt=_.radius/Math.tan(vt/2);if(Bt>=ee-uP||Bt>=pe-uP){const Jn=Math.min(ee,pe)*Math.tan(vt/2);throw new Error(`filletCorners radius ${_.radius} is too large for corner ${_.index}; max is ${Jn.toFixed(3)}`)}const fr=[F[0]-we*Bt,F[1]-De*Bt],hn=[F[0]+te*Bt,F[1]+nt*Bt],[vr,Xt]=tve(Me[0]+bt[0],Me[1]+bt[1]),Wt=_.radius/Math.sin(vt/2),Hn=[F[0]+vr*Wt,F[1]+Xt*Wt],zn=_.segments==null?Mkt(vt):Math.round(_.segments),Fs=Math.max(2,zn);return{radius:_.radius,tangentDistance:Bt,segments:Fs,start:fr,end:hn,center:Hn,startAngle:Math.atan2(fr[1]-Hn[1],fr[0]-Hn[0]),sweep:g*vt}}function Rkt(l,_){var pe,we;if(l.length<3)throw new Error("filletCorners requires at least 3 points");if(_.length===0)return Ed(l);const g=l.map(Ikt),S=Okt(g);if(Math.abs(S)<=uP)throw new Error("filletCorners requires a non-degenerate polygon");const D=Math.sign(S),F=new Map;for(const De of _){if(F.has(De.index))throw new Error(`filletCorners corner ${De.index} is specified more than once`);F.set(De.index,Lkt(g,De,D))}for(let De=0;De<g.length;De+=1){const te=(De+1)%g.length,nt=wve(g[De],g[te]),Te=((pe=F.get(De))==null?void 0:pe.tangentDistance)??0,Me=((we=F.get(te))==null?void 0:we.tangentDistance)??0;if(Te+Me>=nt-uP)throw new Error(`filletCorners adjacent fillets overlap on edge ${De} -> ${te}; reduce one of the radii`)}const z=[],ee=De=>{(z.length===0||!Tje(z[z.length-1],De))&&z.push(De)};for(let De=0;De<g.length;De+=1){const te=F.get(De);if(te==null){ee(g[De]);continue}ee(te.start);for(let nt=1;nt<te.segments;nt+=1){const Te=te.startAngle+te.sweep*nt/te.segments;ee([te.center[0]+Math.cos(Te)*te.radius,te.center[1]+Math.sin(Te)*te.radius])}ee(te.end)}return z.length>=2&&Tje(z[0],z[z.length-1])&&z.pop(),Ed(z)}function Tee(l,_){return[l[0]-_[0],l[1]-_[1],l[2]-_[2]]}function kje(l,_){return[l[0]+_[0],l[1]+_[1],l[2]+_[2]]}function Eve(l,_){return[l[0]*_,l[1]*_,l[2]*_]}function yE(l,_){return l[0]*_[0]+l[1]*_[1]+l[2]*_[2]}function jkt(l,_){return[l[1]*_[2]-l[2]*_[1],l[2]*_[0]-l[0]*_[2],l[0]*_[1]-l[1]*_[0]]}function pbe(l){return Math.sqrt(yE(l,l))}function Dve(l){const _=pbe(l)||1;return[l[0]/_,l[1]/_,l[2]/_]}function Cje(l,_){return[(l[0]+_[0])/2,(l[1]+_[1])/2,(l[2]+_[2])/2]}function wje(l){if(l instanceof zk){const[_,g,S,D]=l.vertices;return{corners:[[_.x,_.y,0],[g.x,g.y,0],[S.x,S.y,0],[D.x,D.y,0]]}}return l}function Eje(l,_){const[g,S,D,F]=l.corners;return[{name:`${_}-bottom`,start:g,end:S},{name:`${_}-right`,start:S,end:D},{name:`${_}-top`,start:D,end:F},{name:`${_}-left`,start:F,end:g}]}function kee(l){return Dve(Tee(l.end,l.start))}function Bkt(l,_,g){const S=kee(l),D=kee(_);if(!(Math.abs(yE(S,D))>.999))throw new Error("Inner edges are not parallel");const z=yE(l.start,S),ee=yE(l.end,S),pe=yE(_.start,S),we=yE(_.end,S),De=Math.min(z,ee),te=Math.max(z,ee),nt=Math.min(pe,we),Te=Math.max(pe,we),Me=Math.max(De,nt),vt=Math.min(te,Te)-Me;if(vt<1e-6)throw new Error("Inner edges do not overlap along their direction");const Bt=kje(l.start,Eve(S,Me-z)),fr=kje(_.start,Eve(S,Me-pe)),hn=Tee(fr,Bt),vr=yE(hn,S),Xt=[hn[0]-S[0]*vr,hn[1]-S[1]*vr,hn[2]-S[2]*vr],Wt=pbe(Xt);if(Wt<1e-6)throw new Error("Edges are coincident — no arc to build");const Hn=Dve(Xt),zn=Dve(jkt(S,Hn)),Fs=Wt/2,Jn=[Wt/2,0],oc=[];for(let Es=0;Es<=g;Es++){const Ho=Math.PI*Es/g,qi=Jn[0]-Fs*Math.cos(Ho),Yc=Fs*Math.sin(Ho);oc.push([qi,Yc])}const ro=Math.max(.5,Wt*.02),Br=[];for(let Es=g;Es>=0;Es--){const Ho=Math.PI*Es/g,qi=Fs-ro,Yc=Jn[0]-qi*Math.cos(Ho),Hp=qi*Math.sin(Ho);Br.push([Yc,Hp])}const pc=Ed([...oc,...Br]),eo=FS(pc,vt).toShape(),Gt=Bt,fa=[Hn[0],Hn[1],Hn[2],0,zn[0],zn[1],zn[2],0,S[0],S[1],S[2],0,Gt[0],Gt[1],Gt[2],1];return eo.transform(fa)}function Jkt(l,_,g=12){const S=wje(l),D=wje(_),F=Eje(S,"a"),z=Eje(D,"b");let ee=null;for(const pe of F){const we=kee(pe);for(const De of z){const te=kee(De);if(Math.abs(yE(we,te))<.999)continue;const nt=Cje(pe.start,pe.end),Te=Cje(De.start,De.end),Me=Tee(Te,nt),bt=yE(Me,we),vt=Tee(Me,Eve(we,bt)),Bt=pbe(vt);Bt<1e-6||(!ee||Bt<ee.dist)&&(ee={edgeA:pe,edgeB:De,dist:Bt})}}if(!ee)throw new Error("No parallel inner edges found between the two rectangles");return Bkt(ee.edgeA,ee.edgeB,g)}let oN=[],Pve=0;function zkt(){oN=[],Pve=0}function Ave(){return oN}function qkt(l){const _=Math.max(0,Math.min(l,oN.length)),g=oN.slice(_);return oN=oN.slice(0,_),g}function Dje(l){return l instanceof J_?[l.x,l.y,0]:l.length===2?[l[0],l[1],0]:[l[0],l[1],l[2]]}function JJe(l,_,g){Pve++;const S=(()=>{if(typeof(g==null?void 0:g.component)=="string"){const D=g.component.trim();return D?[D]:void 0}if(Array.isArray(g==null?void 0:g.component)){const D=Array.from(new Set(g.component.map(F=>typeof F=="string"?F.trim():"").filter(Boolean)));return D.length>0?D:void 0}})();oN.push({id:`dim-${Pve}`,from:Dje(l),to:Dje(_),offset:(g==null?void 0:g.offset)??10,autoOffset:(g==null?void 0:g.offset)===void 0,label:g==null?void 0:g.label,color:g==null?void 0:g.color,components:S,currentComponent:!!(g!=null&&g.currentComponent)})}function Wkt(l,_){JJe([l.start.x,l.start.y],[l.end.x,l.end.y],_)}function OJ(l,_,g){return Math.max(_,Math.min(g,l))}function Vkt(l,_){return[l[0]+_[0],l[1]+_[1],l[2]+_[2]]}function Nve(l,_){return[l[0]-_[0],l[1]-_[1],l[2]-_[2]]}function Pje(l,_){return[l[0]*_,l[1]*_,l[2]*_]}function Ukt(l,_){return l[0]*_[0]+l[1]*_[1]+l[2]*_[2]}function dbe(l){return Math.sqrt(Ukt(l,l))}function $kt(l){const _=dbe(l);return _<1e-9?[0,0,1]:[l[0]/_,l[1]/_,l[2]/_]}function Aje(l,_,g,S,D,F){const z=D*D,ee=z*D,pe=(1-F)*.5,we=(g[0]-l[0])*pe,De=(g[1]-l[1])*pe,te=(S[0]-_[0])*pe,nt=(S[1]-_[1])*pe,Te=2*ee-3*z+1,Me=ee-2*z+D,bt=-2*ee+3*z,vt=ee-z;return[Te*_[0]+Me*we+bt*g[0]+vt*te,Te*_[1]+Me*De+bt*g[1]+vt*nt]}function Nje(l,_,g,S,D,F){const z=D*D,ee=z*D,pe=(1-F)*.5,we=[(g[0]-l[0])*pe,(g[1]-l[1])*pe,(g[2]-l[2])*pe],De=[(S[0]-_[0])*pe,(S[1]-_[1])*pe,(S[2]-_[2])*pe],te=2*ee-3*z+1,nt=ee-2*z+D,Te=-2*ee+3*z,Me=ee-z;return[te*_[0]+nt*we[0]+Te*g[0]+Me*De[0],te*_[1]+nt*we[1]+Te*g[1]+Me*De[1],te*_[2]+nt*we[2]+Te*g[2]+Me*De[2]]}function Hkt(l,_,g,S){if(l.length<2)throw new Error("spline2d requires at least 2 points");const D=l.length,F=[],z=_?D:D-1;for(let ee=0;ee<z;ee++){const pe=l[(ee-1+D)%D],we=l[ee%D],De=l[(ee+1)%D],te=l[(ee+2)%D];if(!_){const nt=ee===0?we:pe,Te=ee===D-2?De:te;for(let Me=0;Me<g;Me++){const bt=Me/g;F.push(Aje(nt,we,De,Te,bt,S))}continue}for(let nt=0;nt<g;nt++){const Te=nt/g;F.push(Aje(pe,we,De,te,Te,S))}}return _||F.push(l[D-1]),F}function Gkt(l,_,g,S){if(l.length<2)throw new Error("spline3d requires at least 2 points");const D=l.length,F=[],z=_?D:D-1;for(let ee=0;ee<z;ee++){const pe=l[(ee-1+D)%D],we=l[ee%D],De=l[(ee+1)%D],te=l[(ee+2)%D];if(!_){const nt=ee===0?we:pe,Te=ee===D-2?De:te;for(let Me=0;Me<g;Me++){const bt=Me/g;F.push(Nje(nt,we,De,Te,bt,S))}continue}for(let nt=0;nt<g;nt++){const Te=nt/g;F.push(Nje(pe,we,De,te,Te,S))}}return _||F.push(l[D-1]),F}class zJe{constructor(_,g={}){of(this,"points");of(this,"closed");of(this,"tension");if(_.length<2)throw new Error("Curve3D needs at least 2 points");this.points=_.map(S=>[S[0],S[1],S[2]]),this.closed=g.closed??!1,this.tension=OJ(g.tension??.5,0,1)}sampleBySegment(_=16){const g=Math.max(3,Math.floor(_));return Gkt(this.points,this.closed,g,this.tension)}sample(_=64){const g=Math.max(2,Math.floor(_)),S=Math.max(3,Math.ceil(g/Math.max(1,this.points.length-(this.closed?0:1)))),D=this.sampleBySegment(S);if(D.length<=g)return D;const F=[];for(let z=0;z<g;z++){const ee=Math.round(z/(g-1)*(D.length-1));F.push(D[ee])}return F}pointAt(_){const g=this.sample(200),D=OJ(_,0,1)*(g.length-1),F=Math.floor(D),z=Math.min(g.length-1,F+1),ee=D-F;return Vkt(Pje(g[F],1-ee),Pje(g[z],ee))}tangentAt(_){const S=this.pointAt(OJ(_-.001,0,1)),D=this.pointAt(OJ(_+.001,0,1));return $kt(Nve(D,S))}length(_=200){const g=this.sample(_);let S=0;for(let D=1;D<g.length;D++)S+=dbe(Nve(g[D],g[D-1]));return S}}function Xkt(l,_={}){const g=_.closed??!0,S=OJ(_.tension??.5,0,1),D=t2t(_.samplesPerSegment??16),F=Hkt(l,g,D,S);if(g)return Ed(F);if(_.strokeWidth==null||_.strokeWidth<=0)throw new Error("spline2d: open spline requires options.strokeWidth > 0 to create a solid Sketch");return _be(F,_.strokeWidth,_.join??"Round")}function Qkt(l,_={}){return new zJe(l,_)}function Ykt(l,_,g={}){var hn;if(l.length<2)throw new Error("loft requires at least two profiles");if(l.length!==_.length)throw new Error("loft requires heights.length === profiles.length");const S=l.map((vr,Xt)=>({profile:vr,z:_[Xt]})).sort((vr,Xt)=>vr.z-Xt.z);for(let vr=1;vr<S.length;vr++)if(Math.abs(S[vr].z-S[vr-1].z)<1e-8)throw new Error("loft requires strictly increasing, unique heights");const D=S.map(vr=>vr.z);let F=1/0,z=1/0,ee=-1/0,pe=-1/0;for(const vr of S){const Xt=vr.profile.bounds();F=Math.min(F,Xt.min[0]),z=Math.min(z,Xt.min[1]),ee=Math.max(ee,Xt.max[0]),pe=Math.max(pe,Xt.max[1])}const we=D[0],De=D[D.length-1],te=Math.max(ee-F,pe-z,De-we,1),nt=g.edgeLength??Math.max(.35,te/90),Te=gBe(nt),Me=g.boundsPadding??Math.max(Te*3,te*.06,1.5),bt=hBe(Me),vt=G2t(S.map(vr=>tm(vr.profile)),D,{edgeLength:Te,boundsPadding:bt}),Bt=kE(vt,"loft");if(Bt)return k_(Bt,(hn=S[0])==null?void 0:hn.profile.colorHex,{fidelity:"sampled",sources:["loft","level-set"]});const fr=GBe(S.map(vr=>vr.profile.toPolygons()),D,{edgeLength:Te,boundsPadding:bt});return Ree(ube(fr.sdf,fr.bounds,fr.edgeLength),{fidelity:"sampled",sources:["loft","level-set"]})}function Zkt(l,_,g={}){const S=Math.max(4,g.samples??48),D=r2t(S),F=Array.isArray(_)?_:_.sample(D);if(F.length<2)throw new Error("sweep requires a path with at least two points");const z=g.up??[0,0,1],ee=l.bounds(),pe=Math.max(Math.abs(ee.min[0]),Math.abs(ee.max[0]),Math.abs(ee.min[1]),Math.abs(ee.max[1]));let we=1/0,De=1/0,te=1/0,nt=-1/0,Te=-1/0,Me=-1/0;for(const zn of F)we=Math.min(we,zn[0]),De=Math.min(De,zn[1]),te=Math.min(te,zn[2]),nt=Math.max(nt,zn[0]),Te=Math.max(Te,zn[1]),Me=Math.max(Me,zn[2]);let bt=0;for(let zn=1;zn<F.length;zn++)bt+=dbe(Nve(F[zn],F[zn-1]));const vt=Math.max(nt-we,Te-De,Me-te,bt,1),Bt=g.edgeLength??Math.max(.3,vt/110),fr=gBe(Bt),hn=g.boundsPadding??Math.max(pe+fr*2,vt*.04,2),vr=hBe(hn),Xt=X2t(tm(l),{kind:"polyline",points:F.map(([zn,Fs,Jn])=>[zn,Fs,Jn])},{edgeLength:fr,boundsPadding:vr,up:z}),Wt=kE(Xt,"sweep");if(Wt)return k_(Wt,l.colorHex,{fidelity:"sampled",sources:["sweep","level-set"]});const Hn=XBe(l.toPolygons(),F.map(([zn,Fs,Jn])=>[zn,Fs,Jn]),{edgeLength:fr,boundsPadding:vr,up:z});return Ree(ube(Hn.sdf,Hn.bounds,Hn.edgeLength),{fidelity:"sampled",sources:["sweep","level-set"]})}const qJe=1e-7,gu=1e-9,Kkt={fill:"black",stroke:"none",strokeWidth:1,fillRule:"nonzero",strokeJoin:"miter",display:"inline",visibility:"visible",opacity:1,fillOpacity:1,strokeOpacity:1},eCt={px:1,pt:96/72,pc:16,in:96,cm:96/2.54,mm:96/25.4,q:96/101.6};function pN(l,_,g){return Math.max(_,Math.min(g,l))}function iP(l){return l*l}function cN(l,_){return Math.hypot(l[0]-_[0],l[1]-_[1])}function mbe(l){let _=0;for(let g=0;g<l.length;g+=1){const[S,D]=l[g],[F,z]=l[(g+1)%l.length];_+=S*z-F*D}return _*.5}function tCt(l){if(l.length===0)return[0,0];let _=0,g=0;for(const[S,D]of l)_+=S,g+=D;return[_/l.length,g/l.length]}function WJe(l){let _=0,g=0,S=0;for(let F=0;F<l.length;F+=1){const[z,ee]=l[F],[pe,we]=l[(F+1)%l.length],De=z*we-pe*ee;S+=De,_+=(z+pe)*De,g+=(ee+we)*De}if(Math.abs(S)<gu)return tCt(l);const D=1/(3*S);return[_*D,g*D]}function VJe(l,_){const[g,S]=l;let D=!1;for(let F=0,z=_.length-1;F<_.length;z=F++){const[ee,pe]=_[F],[we,De]=_[z];pe>S!=De>S&&g<(we-ee)*(S-pe)/(De-pe||1e-20)+ee&&(D=!D)}return D}function MF(){return[1,0,0,1,0,0]}function lN(l,_){const[g,S,D,F,z,ee]=l,[pe,we,De,te,nt,Te]=_;return[g*pe+D*we,S*pe+F*we,g*De+D*te,S*De+F*te,g*nt+D*Te+z,S*nt+F*Te+ee]}function rCt(l,_){const[g,S,D,F,z,ee]=l,[pe,we]=_;return[g*pe+D*we+z,S*pe+F*we+ee]}function KK(l,_){return[1,0,0,1,l,_]}function Ive(l,_){return[l,0,0,_,0,0]}function Ije(l){const _=l*Math.PI/180,g=Math.cos(_),S=Math.sin(_);return[g,S,-S,g,0,0]}function nCt(l){const _=l*Math.PI/180;return[1,0,Math.tan(_),1,0,0]}function iCt(l){const _=l*Math.PI/180;return[1,Math.tan(_),0,1,0,0]}function Tm(l,_=NaN){if(typeof l!="string")return _;const g=l.trim();if(!g)return _;const S=g.match(/^([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)([a-z%]*)$/i);if(!S)return _;const D=Number(S[1]);if(!Number.isFinite(D))return _;const F=S[2].toLowerCase();return F===""||F==="px"?D:F==="%"?_:D*(eCt[F]??1)}function gbe(l){if(!l)return[];const _=[],g=/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g;let S;for(;(S=g.exec(l))!==null;){const D=Number(S[0]);Number.isFinite(D)&&_.push(D)}return _}function sCt(l){return l.replace(/&(#x?[0-9a-fA-F]+|amp|lt|gt|quot|apos);/g,(_,g)=>{switch(g){case"amp":return"&";case"lt":return"<";case"gt":return">";case"quot":return'"';case"apos":return"'";default:if(g.startsWith("#x")||g.startsWith("#X")){const S=Number.parseInt(g.slice(2),16);return Number.isFinite(S)?String.fromCodePoint(S):""}if(g.startsWith("#")){const S=Number.parseInt(g.slice(1),10);return Number.isFinite(S)?String.fromCodePoint(S):""}return""}})}function aCt(l){const _={},g=/([:@A-Za-z_][\w:.-]*)\s*=\s*("([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/g;let S;for(;(S=g.exec(l))!==null;){const D=S[1],F=S[3]??S[4]??S[5]??"";_[D]=sCt(F)}return _}function oCt(l){const _={};return l&&l.split(";").forEach(g=>{const S=g.indexOf(":");if(S<0)return;const D=g.slice(0,S).trim().toLowerCase(),F=g.slice(S+1).trim();D&&(_[D]=F)}),_}function cCt(l,_){return l?l.trim().toLowerCase()==="evenodd"?"evenodd":"nonzero":_}function lCt(l,_){if(!l)return _;const g=l.trim().toLowerCase();return g==="round"||g==="bevel"?g:"miter"}function rve(l,_){const g=Tm(l,NaN);return Number.isFinite(g)?pN(g,0,1):_}function RK(l,_){if(typeof l!="string")return _;const g=l.trim().toLowerCase();return g||_}function uCt(l,_){const g={...l},S=oCt(_.style),D=z=>S[z]??_[z];g.fill=RK(D("fill"),g.fill),g.stroke=RK(D("stroke"),g.stroke);const F=Tm(D("stroke-width"),NaN);return Number.isFinite(F)&&F>=0&&(g.strokeWidth=F),g.fillRule=cCt(D("fill-rule"),g.fillRule),g.strokeJoin=lCt(D("stroke-linejoin"),g.strokeJoin),g.display=RK(D("display"),g.display),g.visibility=RK(D("visibility"),g.visibility),g.opacity=rve(D("opacity"),g.opacity),g.fillOpacity=rve(D("fill-opacity"),g.fillOpacity),g.strokeOpacity=rve(D("stroke-opacity"),g.strokeOpacity),g}function _Ct(l){if(!l)return MF();const _=l.trim();if(!_)return MF();const g=/([a-zA-Z]+)\s*\(([^)]*)\)/g;let S,D=MF();for(;(S=g.exec(_))!==null;){const F=S[1].toLowerCase(),z=gbe(S[2]);let ee=MF();F==="matrix"&&z.length>=6?ee=[z[0],z[1],z[2],z[3],z[4],z[5]]:F==="translate"&&z.length>=1?ee=KK(z[0],z.length>=2?z[1]:0):F==="scale"&&z.length>=1?ee=Ive(z[0],z.length>=2?z[1]:z[0]):F==="rotate"&&z.length>=1?z.length>=3?ee=lN(KK(z[1],z[2]),lN(Ije(z[0]),KK(-z[1],-z[2]))):ee=Ije(z[0]):F==="skewx"&&z.length>=1?ee=nCt(z[0]):F==="skewy"&&z.length>=1&&(ee=iCt(z[0])),D=lN(ee,D)}return D}function Ih(l,_){if(l.length===0){l.push([_[0],_[1]]);return}const g=l[l.length-1];cN(g,_)>qJe&&l.push([_[0],_[1]])}function bN(l){return l.length<=1?l:cN(l[0],l[l.length-1])<=qJe?l.slice(0,-1):l}function Fje(l,_,g,S,D){const F=cN(l,_)+cN(_,g)+cN(g,S),z=pN(Math.ceil(F/Math.max(D,1e-4)),4,512),ee=[];for(let pe=1;pe<=z;pe+=1){const we=pe/z,De=1-we,te=De*De*De*l[0]+3*De*De*we*_[0]+3*De*we*we*g[0]+we*we*we*S[0],nt=De*De*De*l[1]+3*De*De*we*_[1]+3*De*we*we*g[1]+we*we*we*S[1];ee.push([te,nt])}return ee}function Oje(l,_,g,S){const D=cN(l,_)+cN(_,g),F=pN(Math.ceil(D/Math.max(S,1e-4)),4,512),z=[];for(let ee=1;ee<=F;ee+=1){const pe=ee/F,we=1-pe,De=we*we*l[0]+2*we*pe*_[0]+pe*pe*g[0],te=we*we*l[1]+2*we*pe*_[1]+pe*pe*g[1];z.push([De,te])}return z}function Mje(l,_,g,S){const D=l*g+_*S,F=l*S-_*g;return Math.atan2(F,D)}function fCt(l,_,g,S,D,F,z,ee,pe,we,De){let te=Math.abs(g),nt=Math.abs(S);if(te<gu||nt<gu)return[[ee,pe]];const Te=D*Math.PI/180,Me=Math.cos(Te),bt=Math.sin(Te),vt=(l-ee)/2,Bt=(_-pe)/2,fr=Me*vt+bt*Bt,hn=-bt*vt+Me*Bt,vr=iP(fr)/iP(te)+iP(hn)/iP(nt);if(vr>1){const Ci=Math.sqrt(vr);te*=Ci,nt*=Ci}const Xt=iP(te),Wt=iP(nt),Hn=iP(fr),zn=iP(hn);let Fs=Xt*Wt-Xt*zn-Wt*Hn,Jn=Xt*zn+Wt*Hn;Jn<gu&&(Jn=gu),Fs=Math.max(0,Fs);const oc=(F===z?-1:1)*Math.sqrt(Fs/Jn),ro=oc*(te*hn/nt),Br=oc*(-(nt*fr)/te),pc=Me*ro-bt*Br+(l+ee)/2,eo=bt*ro+Me*Br+(_+pe)/2,Gt=(fr-ro)/te,fa=(hn-Br)/nt,Es=(-fr-ro)/te,Ho=(-hn-Br)/nt;let qi=Mje(1,0,Gt,fa),Yc=Mje(Gt,fa,Es,Ho);!z&&Yc>0&&(Yc-=Math.PI*2),z&&Yc<0&&(Yc+=Math.PI*2);const Hp=Math.max(te,nt),Gp=Math.max(De,Math.ceil(Math.abs(Yc)*Hp/Math.max(we,1e-4))),q_=[];for(let Ci=1;Ci<=Gp;Ci+=1){const Bf=Ci/Gp,F1=qi+Yc*Bf,Qg=Math.cos(F1),xN=Math.sin(F1),SN=Me*te*Qg-bt*nt*xN+pc,ZF=bt*te*Qg+Me*nt*xN+eo;q_.push([SN,ZF])}return q_}function pCt(l,_){return l.map(g=>{const S=[];for(const D of g.points)Ih(S,rCt(_,D));return{points:S,closed:g.closed}})}function dCt(l,_,g){const S=l.match(/[AaCcHhLlMmQqSsTtVvZz]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[],D=[];let F=0,z="",ee=0,pe=0,we=0,De=0,te=null,nt=null,Te=null;const Me=Bt=>{if(!te)return;const fr=bN(te.points);fr.length>=2&&D.push({points:fr,closed:Bt}),te=null},bt=()=>{te||(te={points:[[ee,pe]],closed:!1})},vt=()=>{if(F>=S.length)return null;const Bt=S[F];if(/^[AaCcHhLlMmQqSsTtVvZz]$/.test(Bt))return null;F+=1;const fr=Number(Bt);return Number.isFinite(fr)?fr:null};for(;F<S.length;){if(/^[AaCcHhLlMmQqSsTtVvZz]$/.test(S[F]))z=S[F],F+=1;else if(!z){F+=1;continue}switch(z){case"M":case"m":{let Bt=!0;for(;;){const fr=vt(),hn=vt();if(fr==null||hn==null)break;const vr=z==="m"?ee+fr:fr,Xt=z==="m"?pe+hn:hn;Bt?(Me(!1),te={points:[[vr,Xt]],closed:!1},ee=vr,pe=Xt,we=vr,De=Xt,Bt=!1):(bt(),Ih(te.points,[vr,Xt]),ee=vr,pe=Xt)}nt=null,Te=null;break}case"L":case"l":{for(;;){const Bt=vt(),fr=vt();if(Bt==null||fr==null)break;const hn=z==="l"?ee+Bt:Bt,vr=z==="l"?pe+fr:fr;bt(),Ih(te.points,[hn,vr]),ee=hn,pe=vr}nt=null,Te=null;break}case"H":case"h":{for(;;){const Bt=vt();if(Bt==null)break;const fr=z==="h"?ee+Bt:Bt;bt(),Ih(te.points,[fr,pe]),ee=fr}nt=null,Te=null;break}case"V":case"v":{for(;;){const Bt=vt();if(Bt==null)break;const fr=z==="v"?pe+Bt:Bt;bt(),Ih(te.points,[ee,fr]),pe=fr}nt=null,Te=null;break}case"C":case"c":{for(;;){const Bt=vt(),fr=vt(),hn=vt(),vr=vt(),Xt=vt(),Wt=vt();if(Bt==null||fr==null||hn==null||vr==null||Xt==null||Wt==null)break;const Hn=[ee,pe],zn=[z==="c"?ee+Bt:Bt,z==="c"?pe+fr:fr],Fs=[z==="c"?ee+hn:hn,z==="c"?pe+vr:vr],Jn=[z==="c"?ee+Xt:Xt,z==="c"?pe+Wt:Wt];bt(),Fje(Hn,zn,Fs,Jn,_).forEach(oc=>Ih(te.points,oc)),ee=Jn[0],pe=Jn[1],nt=Fs,Te=null}break}case"S":case"s":{for(;;){const Bt=vt(),fr=vt(),hn=vt(),vr=vt();if(Bt==null||fr==null||hn==null||vr==null)break;const Xt=[ee,pe],Wt=nt?[2*ee-nt[0],2*pe-nt[1]]:[ee,pe],Hn=[z==="s"?ee+Bt:Bt,z==="s"?pe+fr:fr],zn=[z==="s"?ee+hn:hn,z==="s"?pe+vr:vr];bt(),Fje(Xt,Wt,Hn,zn,_).forEach(Fs=>Ih(te.points,Fs)),ee=zn[0],pe=zn[1],nt=Hn,Te=null}break}case"Q":case"q":{for(;;){const Bt=vt(),fr=vt(),hn=vt(),vr=vt();if(Bt==null||fr==null||hn==null||vr==null)break;const Xt=[ee,pe],Wt=[z==="q"?ee+Bt:Bt,z==="q"?pe+fr:fr],Hn=[z==="q"?ee+hn:hn,z==="q"?pe+vr:vr];bt(),Oje(Xt,Wt,Hn,_).forEach(zn=>Ih(te.points,zn)),ee=Hn[0],pe=Hn[1],Te=Wt,nt=null}break}case"T":case"t":{for(;;){const Bt=vt(),fr=vt();if(Bt==null||fr==null)break;const hn=[ee,pe],vr=Te?[2*ee-Te[0],2*pe-Te[1]]:[ee,pe],Xt=[z==="t"?ee+Bt:Bt,z==="t"?pe+fr:fr];bt(),Oje(hn,vr,Xt,_).forEach(Wt=>Ih(te.points,Wt)),ee=Xt[0],pe=Xt[1],Te=vr,nt=null}break}case"A":case"a":{for(;;){const Bt=vt(),fr=vt(),hn=vt(),vr=vt(),Xt=vt(),Wt=vt(),Hn=vt();if(Bt==null||fr==null||hn==null||vr==null||Xt==null||Wt==null||Hn==null)break;const zn=z==="a"?ee+Wt:Wt,Fs=z==="a"?pe+Hn:Hn;bt(),fCt(ee,pe,Bt,fr,hn,Math.abs(vr)>=.5,Math.abs(Xt)>=.5,zn,Fs,_,g).forEach(Jn=>Ih(te.points,Jn)),ee=zn,pe=Fs,nt=null,Te=null}break}case"Z":case"z":{te&&Ih(te.points,[we,De]),Me(!0),ee=we,pe=De,nt=null,Te=null;break}default:{nt=null,Te=null;break}}}return Me(!1),D}function Lje(l,_,g,S,D){if(!(g>gu)||!(S>gu))return[];const F=2*Math.PI*Math.max(g,S),z=pN(Math.ceil(F/Math.max(D,1e-4)),16,720),ee=[];for(let pe=0;pe<z;pe+=1){const we=2*Math.PI*pe/z;ee.push([l+g*Math.cos(we),_+S*Math.sin(we)])}return[{points:ee,closed:!0}]}function jK(l,_,g,S,D,F,z,ee){const pe=Math.abs(z-F),we=pN(Math.ceil(pe*Math.max(S,D)/Math.max(ee,1e-4)),2,180);for(let De=1;De<=we;De+=1){const te=F+pe*De/we*Math.sign(z-F);Ih(l,[_+S*Math.cos(te),g+D*Math.sin(te)])}}function mCt(l,_,g,S,D,F,z){const ee=g,pe=S;if(!(ee>gu)||!(pe>gu))return[];const we=pN(D,0,ee/2),De=pN(F,0,pe/2);if(we<gu||De<gu)return[{points:[[l,_],[l+ee,_],[l+ee,_+pe],[l,_+pe]],closed:!0}];const te=[];return Ih(te,[l+we,_]),Ih(te,[l+ee-we,_]),jK(te,l+ee-we,_+De,we,De,-Math.PI/2,0,z),Ih(te,[l+ee,_+pe-De]),jK(te,l+ee-we,_+pe-De,we,De,0,Math.PI/2,z),Ih(te,[l+we,_+pe]),jK(te,l+we,_+pe-De,we,De,Math.PI/2,Math.PI,z),Ih(te,[l,_+De]),jK(te,l+we,_+De,we,De,Math.PI,3*Math.PI/2,z),[{points:bN(te),closed:!0}]}function Rje(l){const _=gbe(l),g=[];for(let S=0;S+1<_.length;S+=2)g.push([_[S],_[S+1]]);return bN(g)}function gCt(l,_,g,S){const D=l.toLowerCase();if(D==="path"){const F=_.d??"";return F.trim()?dCt(F,g,S):[]}if(D==="rect"){const F=Tm(_.x,0),z=Tm(_.y,0),ee=Tm(_.width,NaN),pe=Tm(_.height,NaN);if(!(ee>gu)||!(pe>gu))return[];let we=Tm(_.rx,NaN),De=Tm(_.ry,NaN);return!Number.isFinite(we)&&Number.isFinite(De)&&(we=De),!Number.isFinite(De)&&Number.isFinite(we)&&(De=we),Number.isFinite(we)||(we=0),Number.isFinite(De)||(De=0),mCt(F,z,ee,pe,we,De,g)}if(D==="circle"){const F=Tm(_.cx,0),z=Tm(_.cy,0),ee=Tm(_.r,NaN);return ee>gu?Lje(F,z,ee,ee,g):[]}if(D==="ellipse"){const F=Tm(_.cx,0),z=Tm(_.cy,0),ee=Tm(_.rx,NaN),pe=Tm(_.ry,NaN);return!(ee>gu)||!(pe>gu)?[]:Lje(F,z,ee,pe,g)}if(D==="line"){const F=Tm(_.x1,0),z=Tm(_.y1,0),ee=Tm(_.x2,0),pe=Tm(_.y2,0);return[{points:[[F,z],[ee,pe]],closed:!1}]}if(D==="polyline"){const F=Rje(_.points);return F.length<2?[]:[{points:F,closed:!1}]}if(D==="polygon"){const F=Rje(_.points);return F.length<3?[]:[{points:F,closed:!0}]}return[]}function hCt(l){const _=[];for(const g of l){const S=bN(g.points);g.closed?S.length>=3&&Math.abs(mbe(S))>gu&&_.push({points:S,closed:!0}):S.length>=2&&_.push({points:S,closed:!1})}return _}function yCt(l){return l.fill!=="none"&&l.fill!=="transparent"&&l.opacity>gu&&l.fillOpacity>gu}function vCt(l){return l.stroke!=="none"&&l.stroke!=="transparent"&&l.strokeWidth>gu&&l.opacity>gu&&l.strokeOpacity>gu}function bCt(l){const _=[];for(const g of l){if(!g.closed)continue;const S=bN(g.points);if(S.length<3)continue;const D=mbe(S),F=Math.abs(D);F<=gu||_.push({points:S,area:D,absArea:F,sample:WJe(S)})}return _}function xCt(l,_){const g=bCt(l);if(g.length===0)return null;const S=[],D=[];if(_==="evenodd"){const z=[...g].sort((ee,pe)=>ee.absArea-pe.absArea);for(const ee of z){let pe=0;for(const De of g)De!==ee&&(De.absArea<=ee.absArea+gu||VJe(ee.sample,De.points)&&(pe+=1));const we=Ed(ee.points);pe%2===0?S.push(we):D.push(we)}}else{const ee=[...g].sort((pe,we)=>we.absArea-pe.absArea)[0].area>=0?1:-1;for(const pe of g){const we=Ed(pe.points);(pe.area>=0?1:-1)===ee?S.push(we):D.push(we)}}S.length===0&&S.push(Ed(g[0].points));let F=S.length===1?S[0]:Fh(...S);return D.length>0&&(F=N1(F,...D)),F.isEmpty()?null:F}function SCt(l){return l==="round"?"Round":"Square"}function TCt(l,_,g){const S=Ed(l),D=S.offset(_/2,g),F=S.offset(-_/2,g);if(F.isEmpty())return D.isEmpty()?null:D;const z=N1(D,F);return z.isEmpty()?null:z}function kCt(l,_,g){if(!(_>gu))return null;const S=SCt(g),D=[];for(const F of l){const z=bN(F.points);if(F.closed){if(z.length<3)continue;const ee=TCt(z,_,S);ee&&!ee.isEmpty()&&D.push(ee)}else{if(z.length<2)continue;const ee=_be(z,_,S);ee.isEmpty()||D.push(ee)}}return D.length===0?null:D.length===1?D[0]:Fh(...D)}function CCt(l){const g=l.toPolygons().map(ee=>ee.map(([pe,we])=>[pe,we])).map(ee=>bN(ee)).filter(ee=>ee.length>=3).map(ee=>{const pe=mbe(ee);return{points:ee,area:pe,absArea:Math.abs(pe),sample:WJe(ee)}}).filter(ee=>ee.absArea>gu);if(g.length===0)return[];const S=g.filter(ee=>ee.area>0),D=g.filter(ee=>ee.area<0);if(S.length===0){const ee=Ed(g[0].points);return ee.isEmpty()?[]:[{sketch:ee,area:ee.area()}]}const F=S.map(ee=>({outer:ee,holes:[]}));for(const ee of D){const pe=F.filter(we=>VJe(ee.sample,we.outer.points)).sort((we,De)=>we.outer.absArea-De.outer.absArea);pe.length>0&&pe[0].holes.push(ee)}const z=[];for(const ee of F){let pe=Ed(ee.outer.points);if(ee.holes.length>0){const we=ee.holes.map(De=>Ed(De.points));pe=N1(pe,...we)}pe.isEmpty()||z.push({area:Math.abs(pe.area()),sketch:pe})}return z.sort((ee,pe)=>pe.area-ee.area),z}function wCt(l,_){const g=CCt(l);if(g.length===0)return l;const S=g[0].area,D=Math.max(_.minRegionArea,S*_.minRegionAreaRatio);let F=g.filter(z=>z.area+gu>=D);if(F.length===0&&(F=[g[0]]),_.regionSelection==="largest"&&(F=[F[0]]),Number.isFinite(_.maxRegions)){const z=Math.max(1,Math.floor(_.maxRegions));F=F.slice(0,z)}return F.length===1?F[0].sketch:Fh(...F.map(z=>z.sketch))}function ECt(l,_){const g=Number.isFinite(_.maxWidth),S=Number.isFinite(_.maxHeight);if(!g&&!S)return l;const D=l.bounds(),F=D.min,z=D.max,ee=Math.max(0,(z[0]??0)-(F[0]??0)),pe=Math.max(0,(z[1]??0)-(F[1]??0));let we=Number.POSITIVE_INFINITY;return g&&ee>gu&&(we=Math.min(we,_.maxWidth/ee)),S&&pe>gu&&(we=Math.min(we,_.maxHeight/pe)),!Number.isFinite(we)||we<=0||we>=1-gu?l:l.scale(we)}function DCt(l,_){if(!_.centerOnOrigin)return l;const g=l.bounds(),S=g.min,D=g.max,F=((S[0]??0)+(D[0]??0))*.5,z=((S[1]??0)+(D[1]??0))*.5;return Math.abs(F)<=gu&&Math.abs(z)<=gu?l:l.translate(-F,-z)}function PCt(l,_){let g=MF();if(_.invertY){const S=gbe(l.viewBox),D=Tm(l.height,NaN),F=S.length>=4?S[1]+S[3]:Number.isFinite(D)?D:0;g=lN(KK(0,F),Ive(1,-1))}return Math.abs(_.scale-1)>gu&&(g=lN(Ive(_.scale,_.scale),g)),g}const ACt=new Set(["path","rect","circle","ellipse","line","polyline","polygon"]);function NCt(l,_){const g=[],S=[{tag:"__root__",ctx:{transform:MF(),style:{...Kkt},hidden:!1,inDefs:!1}}];let D=!1;const F=/<!--[\s\S]*?-->|<\?[\s\S]*?\?>|<!DOCTYPE[\s\S]*?>|<!\[CDATA\[[\s\S]*?\]\]>|<\/?[^>]+>/gi;let z;for(;(z=F.exec(l))!==null;){const ee=z[0];if(ee.startsWith("<!--")||ee.startsWith("<?")||ee.startsWith("<!"))continue;if(ee.startsWith("</")){const Wt=ee.slice(2,-1).trim().toLowerCase();for(;S.length>1;){const Hn=S.pop();if(!Hn||Hn.tag===Wt)break}continue}const we=ee.endsWith("/>"),De=ee.slice(1,ee.length-(we?2:1)).trim();if(!De)continue;const te=De.search(/\s/),nt=(te<0?De:De.slice(0,te)).toLowerCase(),Te=te<0?"":De.slice(te+1),Me=aCt(Te),bt=S[S.length-1].ctx,vt=uCt(bt.style,Me),Bt=_Ct(Me.transform);let fr=lN(bt.transform,Bt);!D&&nt==="svg"&&(D=!0,fr=lN(PCt(Me,_),fr));const hn=bt.hidden||vt.display==="none"||vt.visibility==="hidden"||vt.opacity<=gu,vr=bt.inDefs||nt==="defs"||nt==="symbol"||nt==="clipPath"||nt==="mask"||nt==="pattern",Xt={transform:fr,style:vt,hidden:hn,inDefs:vr};if(!Xt.hidden&&!Xt.inDefs&&ACt.has(nt)){const Wt=gCt(nt,Me,_.flattenTolerance,_.arcSegments),Hn=hCt(pCt(Wt,Xt.transform));Hn.length>0&&g.push({subpaths:Hn,style:{...Xt.style}})}we||S.push({tag:nt,ctx:Xt})}return g}function ICt(l={}){const _=l.include??"auto",g=l.regionSelection??"all",S=Number.isFinite(l.flattenTolerance)?Math.max(.01,l.flattenTolerance):.35,D=Number.isFinite(l.arcSegments)?Math.max(2,Math.floor(l.arcSegments)):12,F=Number.isFinite(l.maxRegions)?Math.max(1,Math.floor(l.maxRegions)):Number.POSITIVE_INFINITY,z=Number.isFinite(l.minRegionArea)?Math.max(0,l.minRegionArea):0,ee=Number.isFinite(l.minRegionAreaRatio)?Math.max(0,l.minRegionAreaRatio):0,pe=Number.isFinite(l.scale)?Math.max(1e-6,l.scale):1,we=Number.isFinite(l.maxWidth)?Math.max(1e-6,l.maxWidth):Number.POSITIVE_INFINITY,De=Number.isFinite(l.maxHeight)?Math.max(1e-6,l.maxHeight):Number.POSITIVE_INFINITY,te=l.centerOnOrigin??!1,nt=Number.isFinite(l.simplify)?Math.max(0,l.simplify):0,Te=l.invertY??!0;return{include:_,regionSelection:g,maxRegions:F,minRegionArea:z,minRegionAreaRatio:ee,flattenTolerance:S,arcSegments:D,scale:pe,maxWidth:we,maxHeight:De,centerOnOrigin:te,simplify:nt,invertY:Te}}function FCt(l={}){const _=(g,S,D=!0)=>{if(g!=null){if(typeof g!="number"||!Number.isFinite(g))throw new Error(`SVG import option "${S}" must be a finite number`);if(!D&&g<=0)throw new Error(`SVG import option "${S}" 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(_(l.maxRegions,"maxRegions"),_(l.minRegionArea,"minRegionArea"),_(l.minRegionAreaRatio,"minRegionAreaRatio"),_(l.flattenTolerance,"flattenTolerance",!1),_(l.arcSegments,"arcSegments",!1),_(l.scale,"scale",!1),_(l.maxWidth,"maxWidth",!1),_(l.maxHeight,"maxHeight",!1),_(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 OCt(l,_,g){return g==="fill"?l:g==="stroke"?_:g==="fill-and-stroke"?[...l,..._]:l.length>0?l:_}function jje(l,_={}){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");FCt(_);const g=ICt(_),S=NCt(l,g);if(S.length===0)throw new Error("SVG import produced no supported shape geometry");const D=[],F=[];for(const pe of S){if(yCt(pe.style)){const we=xCt(pe.subpaths,pe.style.fillRule);we&&!we.isEmpty()&&D.push(we)}if(vCt(pe.style)){const we=kCt(pe.subpaths,pe.style.strokeWidth,pe.style.strokeJoin);we&&!we.isEmpty()&&F.push(we)}}const z=OCt(D,F,g.include);if(z.length===0)throw new Error("SVG import found no fill/stroke geometry after style filtering");let ee=z.length===1?z[0]:Fh(...z);if(ee=wCt(ee,g),ee=ECt(ee,g),g.simplify>0&&(ee=ee.simplify(g.simplify)),ee.isEmpty())throw new Error("SVG import generated an empty sketch");return ee=DCt(ee,g),ee}const Fve=1e-6;function tN(l,_){return l[0]*_[0]+l[1]*_[1]+l[2]*_[2]}function MCt(l,_){return[l[0]-_[0],l[1]-_[1],l[2]-_[2]]}function Bje(l,_){return Math.hypot(l,_)}function eee(l){const _=Math.hypot(l[0],l[1],l[2]);return _<1e-12?[0,0,1]:[l[0]/_,l[1]/_,l[2]/_]}function sP(l,_,g=Fve){return Math.abs(l-_)<=g}function Jje(l,_,g,S){return{kind:"project",sourceShape:s_(l),plane:{origin:[_.origin[0],_.origin[1],_.origin[2]],u:[_.u[0],_.u[1],_.u[2]],v:[_.v[0],_.v[1],_.v[2]],normal:[_.normal[0],_.normal[1],_.normal[2]]},sourcePlacement:g?TE(g):void 0,replayReason:S,transforms:[]}}const LCt={matrix:Sa.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 BK(l){return{profile:Cd(l.profile),placement:AS(l.placement)}}function hbe(l){return{origin:[l.placement.workplane.origin[0],l.placement.workplane.origin[1],l.placement.workplane.origin[2]],u:eee([l.placement.workplane.u[0],l.placement.workplane.u[1],l.placement.workplane.u[2]]),v:eee([l.placement.workplane.v[0],l.placement.workplane.v[1],l.placement.workplane.v[2]]),normal:eee([l.placement.workplane.normal[0],l.placement.workplane.normal[1],l.placement.workplane.normal[2]])}}function RCt(l){const _=Math.hypot(l[0],l[1],l[2]);if(_<1e-12)return Sa.identity().toArray();const g=l[0]/_,S=l[1]/_,D=l[2]/_;return[1-2*g*g,-2*g*S,-2*g*D,0,-2*S*g,1-2*S*S,-2*S*D,0,-2*D*g,-2*D*S,1-2*D*D,0,0,0,0,1]}function jCt(l){switch(l.kind){case"translate":return Sa.translation(l.x,l.y,l.z).toArray();case"rotate":return Sa.identity().rotateAxis([1,0,0],l.xDeg).rotateAxis([0,1,0],l.yDeg).rotateAxis([0,0,1],l.zDeg).toArray();case"scale":return Sa.scale([l.x,l.y,l.z]).toArray();case"rotateAround":return Sa.rotationAxis([l.axisX,l.axisY,l.axisZ],l.degrees,[l.pivotX,l.pivotY,l.pivotZ]).toArray();case"mirror":return RCt([l.normalX,l.normalY,l.normalZ])}}function BCt(l,_){const g=jCt(_),S=Sa.from(g),D=AS(l);return{matrix:Sa.from(D.matrix).mul(g).toArray(),placement:{...D.placement,workplane:{...D.placement.workplane,origin:S.point(D.placement.workplane.origin),u:S.vector(D.placement.workplane.u),v:S.vector(D.placement.workplane.v),normal:S.vector(D.placement.workplane.normal)}}}}function Bee(l,_,g){const S=Sa.from(_.matrix),D=S.point([0,0,0]),F=S.vector([1,0,0]),z=S.vector([0,1,0]),ee=S.vector([0,0,1]),pe=Math.abs(tN(eee(ee),g.normal));if(!sP(pe,1,1e-5))return{reason:"projection replay currently requires the target plane to stay parallel to the source workplane."};const we=tN(F,g.u),De=tN(z,g.u),te=tN(F,g.v),nt=tN(z,g.v),Te=Bje(we,te),Me=Bje(De,nt);if(Te<Fve||Me<Fve)return{reason:"projection replay requires a non-degenerate in-plane basis."};const bt=we*De+te*nt;if(Math.abs(bt)>1e-5*Math.max(1,Te*Me))return{reason:"projection replay does not support in-plane shear from downstream 3D transforms yet."};const vt=we/Te,Bt=De/Me,fr=te/Te,hn=nt/Me,vr=vt*hn-Bt*fr;if(!sP(Math.abs(vr),1,1e-5))return{reason:"projection replay requires a rigid or mirrored in-plane basis."};let Xt=Cd(l);if((!sP(Te,1)||!sP(Me,1))&&(Xt=lb(Xt,{kind:"scale",x:Te,y:Me})),vr<0){Xt=lb(Xt,{kind:"mirror",normalX:1,normalY:0});const Fs=Math.atan2(-fr,-vt)*180/Math.PI;sP(Fs,0)||(Xt=lb(Xt,{kind:"rotate",degrees:Fs}))}else{const Fs=Math.atan2(fr,vt)*180/Math.PI;sP(Fs,0)||(Xt=lb(Xt,{kind:"rotate",degrees:Fs}))}const Wt=MCt(D,g.origin),Hn=tN(Wt,g.u),zn=tN(Wt,g.v);return(!sP(Hn,0)||!sP(zn,0))&&(Xt=lb(Xt,{kind:"translate",x:Hn,y:zn})),{profile:Xt}}function JCt(l,_,g){return Bee(l,_,g)}function UJe(l){return{kind:"circle",radius:l,transforms:[]}}function zCt(l){var _,g;return Math.max(l.hole.radius,((_=l.hole.counterbore)==null?void 0:_.radius)??0,((g=l.hole.countersink)==null?void 0:g.radius)??0)}function nve(l){return{profile:Cd(l),placement:AS(LCt)}}function qCt(l,_){const g=Bee(l.profile,l.placement,hbe(_));return g.profile?{ok:!0,context:{profile:g.profile,placement:AS(_)}}:{ok:!1,reason:g.reason??"projection replay could not map a compatible source plane."}}function WCt(l,_){const g=Bee(UJe(zCt(_)),_.placement,hbe(l.placement));if(!g.profile)return{ok:!1,reason:`projection replay can only absorb hole rewrites when the hole axis stays parallel to the projected source basis. ${g.reason??""}`.trim()};const S=NS("difference",[l.profile,g.profile]);return S?{ok:!0,context:{profile:S,placement:AS(l.placement)}}:{ok:!1,reason:"projection replay could not subtract the hole silhouette from the projected source profile."}}function VCt(l,_){const g=Bee(_.profile,_.placement,hbe(l.placement));if(!g.profile)return{ok:!1,reason:`projection replay can only absorb cut rewrites when the cut workplane stays parallel to the projected source basis. ${g.reason??""}`.trim()};const S=NS("difference",[l.profile,g.profile]);return S?{ok:!0,context:{profile:S,placement:AS(l.placement)}}:{ok:!1,reason:"projection replay could not subtract the cut silhouette from the projected source profile."}}function nN(l){if(!l)return{ok:!1,reason:"projection replay currently requires compiler-owned source intent."};switch(l.kind){case"queryOwner":return nN(l.base);case"transform":{const _=nN(l.base);if(!_.ok)return _;let g=BK(_.context);for(const S of l.steps){if(S.kind==="workplanePlacement"){g.placement=AS({matrix:S.matrix,placement:S.placement});continue}g.placement=BCt(g.placement,S)}return{ok:!0,context:g}}case"extrude":return l.scaleTop?{ok:!1,reason:"projection replay currently supports straight extrusions without tapered tops."}:{ok:!0,context:nve(l.profile)};case"box":return{ok:!0,context:nve({kind:"rect",width:l.x,height:l.y,center:l.center,transforms:[]})};case"cylinder":return{ok:!0,context:nve(UJe(Math.max(Math.abs(l.radius),Math.abs(l.radiusTop??l.radius))))};case"shell":{const _=nN(l.base);return _.ok?{ok:!0,context:BK(_.context)}:_}case"hole":{const _=nN(l.base);return _.ok?l.extent.kind==="two-sided"&&wm(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."}:wm(l.extent).kind!=="through"?{ok:!0,context:BK(_.context)}:WCt(_.context,l):_}case"cut":{const _=nN(l.base);return _.ok?l.extent.kind==="two-sided"&&wm(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||wm(l.extent).kind!=="through"?l.taper&&wm(l.extent).kind==="through"?{ok:!1,reason:"projection replay currently supports straight through cuts without tapered side walls."}:{ok:!0,context:BK(_.context)}:VCt(_.context,l):_}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 _=[];for(let F=0;F<l.shapes.length;F+=1){const z=nN(l.shapes[F]);if(!z.ok)return{ok:!1,reason:`projection replay could not derive a compatible union operand at index ${F}: ${z.reason}`};_.push(z.context)}if(_.length===0)return{ok:!1,reason:"projection replay cannot derive an empty boolean union source."};const g=AS(_[0].placement),S=[];for(let F=0;F<_.length;F+=1){const z=qCt(_[F],g);if(!z.ok)return{ok:!1,reason:`projection replay could not align union operand ${F} to a shared projection basis: ${z.reason}`};S.push(z.context.profile)}const D=NS("union",S);return D?{ok:!0,context:{profile:D,placement:g}}:{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 UCt(l,_){var z;const g=gP(l);if(!g)return null;const S=KBe(_),D=nN(g);if(!D.ok)return Jje(g,S,(z=gTt(l))==null?void 0:z.placement,D.reason);const F=JCt(D.context.profile,D.context.placement,S);return F.profile?{kind:"project",sourceShape:s_(g),plane:{origin:[S.origin[0],S.origin[1],S.origin[2]],u:[S.u[0],S.u[1],S.u[2]],v:[S.v[0],S.v[1],S.v[2]],normal:[S.normal[0],S.normal[1],S.normal[2]]},sourcePlacement:TE(D.context.placement.placement),replayProfile:F.profile,transforms:[]}:Jje(g,S,D.context.placement.placement,F.reason??"projection replay could not derive a supported 2D profile.")}function $Je(l,_){const g=KBe(_),S=eJe(g);return l.transform(S)}function $Ct(l,_){const g=$Je(l,_);return new So(g.slice(0))}function HCt(l,_){const g=$Je(l,_),S=new So(g.project()),D=UCt(l,_);return D?Ty(S,D):S}function ybe(l){if(!l||typeof l!="object")return!1;const _=l;return typeof _.name=="string"&&Array.isArray(_.normal)&&Array.isArray(_.center)}function vE(l){return Number.isFinite(l)&&l>0}function Ove(l,_){return l[0]*_[0]+l[1]*_[1]+l[2]*_[2]}function Cee(l){const _=Math.hypot(l[0],l[1],l[2]);if(_<1e-12)throw new Error("Hole/cut feature direction could not be normalized.");return[l[0]/_,l[1]/_,l[2]/_]}function GCt(l){const{workplane:_,u:g,v:S,protrude:D}=l,F=[_.origin[0]+_.u[0]*g+_.v[0]*S+_.normal[0]*D,_.origin[1]+_.u[1]*g+_.v[1]*S+_.normal[1]*D,_.origin[2]+_.u[2]*g+_.v[2]*S+_.normal[2]*D];return[_.u[0],_.u[1],_.u[2],0,_.v[0],_.v[1],_.v[2],0,_.normal[0],_.normal[1],_.normal[2],0,F[0],F[1],F[2],1]}function XCt(l,_){return _?bJe(l).some(g=>cb(g,_)):!0}function vbe(l,_,g){if(!XCt(l,_))throw new Error(`${g} requires a face/workplane owned by the target shape or one of its preserved query ancestors.`)}function bbe(l,_,g){const S=Axt(gP(l),g);if(S)throw new Error(`${_} ${S}`)}function QCt(l){const _=l.boundingBox(),[g,S,D]=_.min,[F,z,ee]=_.max;return[[g,S,D],[g,S,ee],[g,z,D],[g,z,ee],[F,S,D],[F,S,ee],[F,z,D],[F,z,ee]]}function YCt(l,_,g){const S=Cee(g);let D=0;for(const we of QCt(l)){const De=[we[0]-_[0],we[1]-_[1],we[2]-_[2]];D=Math.max(D,Ove(De,S))}if(D>1e-6)return D;const F=l.boundingBox(),z=F.max[0]-F.min[0],ee=F.max[1]-F.min[1],pe=F.max[2]-F.min[2];return Math.max(Math.hypot(z,ee,pe),1)}function ZCt(l,_){return ybe(_)?_:l.face(_)}function KCt(l,_,g,S,D={requireDefendedQuery:!0}){const F=ybe(g)?QF(g):QF(l,g);return vbe(_,F.source.owner,S),D.requireDefendedQuery&&bbe(_,S,F.source),{face:ZCt(l,g),query:F.source}}function ewt(l,_,g,S){if(g.planar===!1||!g.uAxis||!g.vAxis)throw new Error(`${S} upToFace currently requires a planar termination face.`);const D=Cee(_),F=Cee(g.normal);if(Math.abs(Math.abs(Ove(D,F))-1)>1e-6)throw new Error(`${S} upToFace currently requires a termination face parallel to the feature direction.`);const z=[g.center[0]-l[0],g.center[1]-l[1],g.center[2]-l[2]],ee=Ove(z,D);if(!(ee>1e-6))throw new Error(`${S} upToFace requires the termination face to lie in the feature direction.`);return ee}function PJ(l,_,g,S,D,F,z,ee={allowThrough:!0}){if(+(D.depth!=null)+ +(D.upToFace!=null)+ +(D.through===!0)!==1)throw new Error(`${F} ${z} extent must specify exactly one of through, depth, or upToFace.`);if(D.through){if(!ee.allowThrough)throw new Error(`${F} reverse two-sided extents do not support through termination yet.`);return{kind:"through",depth:YCt(_,g,S)}}if(D.upToFace!=null){const we=KCt(l,_,D.upToFace,F,{requireDefendedQuery:!1});return{kind:"upToFace",depth:ewt(g,S,we.face,F),face:we.query}}if(!vE(D.depth))throw new Error(`${F} ${z} extent requires a positive finite blind depth.`);return{kind:"blind",depth:D.depth}}function HJe(l,_,g,S,D,F){if(D.extent){if(D.depth!=null||D.upToFace!=null)throw new Error(`${F} accepts either top-level depth/upToFace or extent.forward/extent.reverse, not both.`);if(!D.extent.forward)throw new Error(`${F} extent.forward is required when using structured feature extents.`);const z=PJ(l,_,g,[-S[0],-S[1],-S[2]],D.extent.forward,F,"forward");if(!D.extent.reverse)return z;const ee=PJ(l,_,g,Cee(S),D.extent.reverse,F,"reverse",{allowThrough:!1});if(ee.kind==="through")throw new Error(`${F} reverse two-sided extents do not support through termination yet.`);return{kind:"two-sided",forward:z,reverse:ee}}if(D.depth!=null&&D.upToFace!=null)throw new Error(`${F} accepts either depth or upToFace, not both.`);return D.upToFace!=null?PJ(l,_,g,[-S[0],-S[1],-S[2]],{upToFace:D.upToFace},F,"forward"):D.depth==null?PJ(l,_,g,[-S[0],-S[1],-S[2]],{through:!0},F,"forward"):PJ(l,_,g,[-S[0],-S[1],-S[2]],{depth:D.depth},F,"forward")}function twt(l){var g,S;const _={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(!vE(l.counterbore.diameter)||l.counterbore.diameter<=l.diameter)throw new Error("Shape.hole() counterbore diameter must be greater than the hole diameter.");if(!vE(l.counterbore.depth))throw new Error("Shape.hole() counterbore depth must be a positive finite value.");_.counterbore={radius:l.counterbore.diameter/2,depth:l.counterbore.depth}}if(l.countersink){if(!vE(l.countersink.diameter)||l.countersink.diameter<=l.diameter)throw new Error("Shape.hole() countersink diameter must be greater than the hole diameter.");const D=l.countersink.angleDeg??90;if(!Number.isFinite(D)||D<=0||D>=180)throw new Error("Shape.hole() countersink angleDeg must be between 0 and 180 degrees.");const F=D*Math.PI/360,z=Math.tan(F);if(!(z>1e-9))throw new Error("Shape.hole() countersink angleDeg is too small to form a defended taper.");_.countersink={radius:l.countersink.diameter/2,angleDeg:D,depth:(l.countersink.diameter-l.diameter)/2/z}}if(l.thread){const D=(g=l.thread.designation)==null?void 0:g.trim(),F=(S=l.thread.class)==null?void 0:S.trim();if(D==="")throw new Error("Shape.hole() thread.designation must be a non-empty string when provided.");if(F==="")throw new Error("Shape.hole() thread.class must be a non-empty string when provided.");if(l.thread.pitch!=null&&!vE(l.thread.pitch))throw new Error("Shape.hole() thread.pitch must be a positive finite value when provided.");if(l.thread.depth!=null&&!vE(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(D==null&&F==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.");_.thread={designation:D,pitch:l.thread.pitch,class:F,handedness:l.thread.handedness,depth:l.thread.depth,modeled:!1}}return _}function rwt(l,_){var D,F,z;if((l.counterbore||l.countersink)&&_.kind==="two-sided")throw new Error("Shape.hole() does not yet combine reverse two-sided extents with counterbore or countersink heads.");const g=wm(_),S=((D=l.counterbore)==null?void 0:D.depth)??((F=l.countersink)==null?void 0:F.depth)??0;if(S>0&&S>=g.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(((z=l.thread)==null?void 0:z.depth)!=null&&l.thread.depth>g.depth+1e-6)throw new Error("Shape.hole() thread.depth cannot exceed the primary forward hole depth.")}function nwt(l,_,g){if(_.taperScale==null)return;if(g.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 S=Array.isArray(_.taperScale)?_.taperScale:[_.taperScale,_.taperScale];if(S.length!==2||!vE(S[0])||!vE(S[1]))throw new Error("Shape.cutout() taperScale must be a positive finite number or [x, y] pair.");if(l.kind==="circle"&&Math.abs(S[0]-S[1])>1e-6)throw new Error("Shape.cutout() circular tapered cuts currently require a uniform taperScale.");return{scale:[S[0],S[1]]}}function GJe(l,_,g){if(!l)return null;const S=Nee(_);return KJ(rbe(l,g(S)),S)}function XJe(l,_){if(!_)throw new Error("Hole/cut feature could not record compiler intent for this target.");const g=vJe(l),S=k_(_,l.colorHex,{backend:g.backend,representation:g.representation,fidelity:g.fidelity,topology:"none",sources:["boolean",...g.sources]});return yee(S,lbe(l)),Lee(S,yJe(l),{merge:!1}),Ree(S,{backend:g.backend,representation:g.representation,fidelity:g.fidelity,topology:"none",sources:["boolean",...g.sources]}),S}function iwt(l,_,g,S){const D=ybe(g)?QF(g):QF(l,g);return vbe(_,D.source.owner,"Shape.hole()"),bbe(_,"Shape.hole()",D.source),{placement:{placement:{workplane:dve(D),u:S.u??0,v:S.v??0,protrude:0,selfAnchor:"center"},matrix:GCt({workplane:dve(D),u:S.u??0,v:S.v??0,protrude:0})},extent:HJe(l,_,D.origin,D.normal,{depth:S.depth,upToFace:S.upToFace,extent:S.extent},"Shape.hole()")}}function QJe(l,_,g,S){if(!vE(S.diameter))throw new Error("Shape.hole() requires a positive finite diameter.");const D=gP(l);if(!D)throw new Error("Shape.hole() currently requires a compile-covered target shape.");const{placement:F,extent:z}=iwt(_,l,g,S),ee=twt(S);rwt(ee,z);const pe=GJe(aSt(D,F,ee,z),"hole",we=>Yxt(we,D,F.placement,ee,z));return XJe(l,pe)}function YJe(l,_,g={}){const S=gP(l);if(!S)throw new Error("Shape.cutout() currently requires a compile-covered target shape.");const D=tm(_);if(!D)throw new Error("Shape.cutout() requires a compile-covered sketch profile.");const F=SE(_),z=xE(_);if(!F||!z)throw new Error("Shape.cutout() requires a sketch placed with Sketch.onFace(...).");vbe(l,F.workplane.source.owner,"Shape.cutout()"),bbe(l,"Shape.cutout()",F.workplane.source);const ee=HJe(l,l,F.workplane.origin,F.workplane.normal,{depth:g.depth,upToFace:g.upToFace,extent:g.extent},"Shape.cutout()"),pe=nwt(D,g,ee),we=GJe(oSt(S,{matrix:z,placement:TE(F)},D,ee,pe),"cut",De=>Zxt(De,S,F,D,ee));return XJe(l,we)}Ys.prototype.hole=function(_,g){return QJe(this,this,_,g)};Ys.prototype.cutout=function(_,g={}){return YJe(this,_,g)};lo.prototype.hole=function(_,g){return QJe(this.toShape(),this,_,g)};lo.prototype.cutout=function(_,g={}){return YJe(this.toShape(),_,g)};const swt={fidelity:"kernel-native",topology:"synthetic",sources:["sheet-metal"]};function awt(l){var g,S;const _=l.bendRadius+l.thickness;return{kind:((g=l.cornerRelief)==null?void 0:g.kind)??"rect",size:((S=l.cornerRelief)==null?void 0:S.size)??_}}function owt(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:awt(l),flanges:[]}}function cwt(l){return l==="panel"?"panel":`"${l}"`}function lwt(l){return{region:l.region,sketch:l.sketch.clone(),u:l.u,v:l.v,selfAnchor:l.selfAnchor}}function uwt(l){if(SE(l)!=null)throw new Error("SheetMetalPart.cutout() expects an unplaced 2D sketch. Pass the profile before calling onFace(...).");if(!tm(l))throw new Error("SheetMetalPart.cutout() requires a compile-covered sketch profile.")}function _wt(l,_){const g=kE({kind:"sheetMetal",model:_ee(l),output:_},`sheet-metal:${_}`);if(!g)throw new Error("sheetMetal() could not build the compiler-owned base plan.");return k_(g,void 0,swt)}function fwt(l,_){const g=new Set(x2t(l));if(!g.has(_)&&_!=="panel")throw new Error(`SheetMetalPart.cutout() cannot target ${cwt(_)} because that flange has not been added. Supported planar regions: ${Array.from(g).join(", ")}`)}class GJ{constructor(_,g=[]){of(this,"model");of(this,"cutouts");this.model=_ee(_),this.cutouts=g.map(lwt)}flange(_,g){const S=_ee(this.model);if(S.flanges.find(z=>z.edge===_))throw new Error(`${_} flange is already defined on this SheetMetalPart.`);S.flanges.push({edge:_,length:g.length,angleDeg:g.angleDeg??90});const F=fee(S);if(F)throw new Error(F);return HF(S),new GJ(S,this.cutouts)}cutout(_,g,S={}){if(!S2t(_))throw new Error(`SheetMetalPart.cutout() does not support region "${String(_)}".`);return fwt(this.model,_),uwt(g),new GJ(this.model,[...this.cutouts,{region:_,sketch:g.clone(),u:S.u??0,v:S.v??0,selfAnchor:S.selfAnchor??"center"}])}regionNames(){return["panel",...Array.from(new Set(this.model.flanges.flatMap(_=>[`bend-${_.edge}`,`flange-${_.edge}`])))]}folded(){return this.buildOutput("folded")}flatPattern(){return this.buildOutput("flat")}buildOutput(_){const g=fee(this.model);if(g)throw new Error(g);HF(this.model);let S=_wt(this.model,_);for(const D of this.cutouts){const F=D.sketch.onFace(S,D.region,{u:D.u,v:D.v,selfAnchor:D.selfAnchor});S=S.cutout(F)}return S}}function pwt(l){const _=owt(l),g=fee(_);if(g)throw new Error(g);return HF(_),new GJ(_)}let Jee=[],XJ={},dN=[];function dwt(){Jee=[],dN=[]}function mwt(l){XJ=l}function zje(){return Jee}function gwt(l,_){dN.push(l);try{return _()}finally{dN.pop()}}function ZJe(l,_){return Object.prototype.hasOwnProperty.call(l,_)}function KJe(l,_,g={}){const S=dN[dN.length-1],D=S!=null&&S.namePrefix?`${S.namePrefix} / ${l}`:l,F=S==null?void 0:S.localOverrides,z=!!(F&&ZJe(F,l)),ee=(z?F[l]:void 0)??XJ[D]??XJ[l]??_,pe=g.integer??!1,we=pe?Math.round(ee):ee,De=g.min??0,te=g.max??_*4,nt=g.step??(pe||te-De>100?1:.1);if(!z){const Te=pe?Math.round(_):_;Jee.push({name:D,value:we,defaultValue:Te,min:De,max:te,step:nt,unit:g.unit,integer:pe,reverse:g.reverse})}return we}function hwt(l,_){const g=dN[dN.length-1],S=g!=null&&g.namePrefix?`${g.namePrefix} / ${l}`:l,D=g==null?void 0:g.localOverrides,F=!!(D&&ZJe(D,l)),z=_?1:0,pe=((F?D[l]:void 0)??XJ[S]??XJ[l]??z)>=.5?1:0;return F||Jee.push({name:S,value:pe,defaultValue:z,min:0,max:1,step:1,boolean:!0}),pe===1}function ywt(l,_,g,S={}){const D=S.axis??[0,0,1],F=S.min??0,z=S.max??360,ee=S.default??0,pe=KJe(l,ee,{min:F,max:z,unit:S.unit??"°",reverse:S.reverse});return _.rotateAround(D,pe,g)}function xbe(l){if(typeof l!="string")return;const _=l.trim();return _.length>0?_:void 0}function vwt(l){return!!l&&typeof l=="object"&&typeof l.name=="string"}function bwt(l){const _=xbe(l.name);if(!_)throw new Error("group(...) named items require a non-empty name");const g=l.shape!==void 0,S=l.sketch!==void 0,D=Array.isArray(l.group);if(Number(g)+Number(S)+Number(D)!==1)throw new Error(`group(...) named item "${_}" must provide exactly one of shape, sketch, or group`);if(g){if(!(l.shape instanceof Ys)&&!(l.shape instanceof lo)&&!(l.shape instanceof iu))throw new Error(`group(...) named item "${_}" shape must be a Shape, TrackedShape, or ShapeGroup`);return l.shape}if(S){if(!(l.sketch instanceof So))throw new Error(`group(...) named item "${_}" sketch must be a Sketch`);return l.sketch}return Sbe(...l.group)}function xwt(l){const _=[],g=[];return l.forEach(S=>{if(vwt(S)){_.push(bwt(S)),g.push(xbe(S.name));return}_.push(S),g.push(void 0)}),{children:_,childNames:g}}class iu{constructor(_,g){of(this,"children");of(this,"childNames");if(g&&g.length!==_.length)throw new Error("ShapeGroup childNames must match children length");this.children=[..._],this.childNames=this.children.map((S,D)=>xbe(g==null?void 0:g[D]))}childName(_){return this.childNames[_]}mapChildren(_){return new iu(this.children.map(_),this.childNames)}clone(){return this.mapChildren(_=>(_ instanceof iu||_ instanceof lo||_ instanceof Ys,_.clone()))}duplicate(){return this.clone()}translate(_,g,S){return this.mapChildren(D=>D instanceof iu||D instanceof lo||D instanceof Ys?D.translate(_,g,S):D.translate(_,g))}_bbox(){let _=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0];for(const S of this.children){if(S instanceof iu){const z=S._bbox();for(let ee=0;ee<3;ee++)z.min[ee]<_[ee]&&(_[ee]=z.min[ee]),z.max[ee]>g[ee]&&(g[ee]=z.max[ee]);continue}const D=S instanceof lo?S.toShape():S instanceof Ys?S:null;if(!D)continue;const F=D.boundingBox();for(let z=0;z<3;z++)F.min[z]<_[z]&&(_[z]=F.min[z]),F.max[z]>g[z]&&(g[z]=F.max[z])}return{min:_,max:g}}boundingBox(){const _=this._bbox();return{min:_.min,max:_.max}}resolveRotatePoint(_){if(Array.isArray(_))return[_[0],_[1],_[2]];const g=this._bbox();return pP(g.min,g.max,_)}moveTo(_,g,S){const D=this._bbox();return this.translate(_-D.min[0],g-D.min[1],S-D.min[2])}moveToLocal(_,g,S,D){let F;return _ instanceof iu?F=_._bbox():F={min:(_ instanceof lo?_.toShape():_).boundingBox().min},this.moveTo(F.min[0]+g,F.min[1]+S,F.min[2]+D)}attachTo(_,g,S="center",D){const F=_ instanceof iu?_._bbox():(()=>{const Te=(_ instanceof lo?_.toShape():_).boundingBox();return{min:Te.min,max:Te.max}})(),z=this._bbox(),ee=_ instanceof iu||vBe(g)?pP(F.min,F.max,g):(_ instanceof lo,_.referencePoint(g)),pe=pP(z.min,z.max,S);let we=ee[0]-pe[0],De=ee[1]-pe[1],te=ee[2]-pe[2];return D&&(we+=D[0],De+=D[1],te+=D[2]),this.translate(we,De,te)}onFace(_,g,S={}){const D=S.u??0,F=S.v??0,z=S.protrude??0,ee={front:"back",back:"front",left:"right",right:"left",top:"bottom",bottom:"top"},pe={front:(we,De,te)=>[we,-te,De],back:(we,De,te)=>[we,te,De],left:(we,De,te)=>[-te,we,De],right:(we,De,te)=>[te,we,De],top:(we,De,te)=>[we,De,te],bottom:(we,De,te)=>[we,De,-te]};return this.attachTo(_,g,ee[g],pe[g](D,F,z))}rotate(_,g,S){return this.mapChildren(D=>D instanceof iu||D instanceof lo||D instanceof Ys?D.rotate(_,g,S):D.rotate(_))}rotateAround(_,g,S=[0,0,0]){return this.transform(Sa.rotationAxis(_,g,S))}rotateAroundTo(_,g,S,D,F={}){return this.transform(Sa.rotateAroundTo(_,g,this.resolveRotatePoint(S),this.resolveRotatePoint(D),F))}pointAlong(_){const[g,S,D]=_,F=Math.sqrt(g*g+S*S+D*D)||1,z=g/F,ee=S/F,pe=D/F,we=-ee,De=z,te=0,nt=Math.sqrt(we*we+De*De+te*te),Te=pe;if(nt<1e-10)return Te>0?this:this.rotate(180,0,0);const Me=Math.atan2(nt,Te)*180/Math.PI,bt=[we/nt,De/nt,te/nt];return this.rotateAround(bt,Me)}transform(_){return new iu(this.children.map(g=>{if(g instanceof iu||g instanceof lo||g instanceof Ys)return g.transform(_);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(_){return this.mapChildren(g=>g instanceof iu||g instanceof lo||g instanceof Ys?g.scale(_):g.scale(typeof _=="number"?_:[_[0],_[1]]))}mirror(_){return this.mapChildren(g=>g instanceof iu||g instanceof lo||g instanceof Ys?g.mirror(_):g.mirror([_[0],_[1]]))}color(_){return this.mapChildren(g=>(g instanceof iu||g instanceof lo||g instanceof Ys,g.color(_)))}}function Sbe(...l){const _=xwt(l);return new iu(_.children,_.childNames)}function eze(l){const _=["part","qty","material","process","tolerance","notes"],g=D=>`"${D.replace(/"/g,'""')}"`,S=[_.join(",")];for(const D of l)S.push([g(D.part),String(D.qty),g(D.material??""),g(D.process??""),g(D.tolerance??""),g(D.notes??"")].join(","));return S.join(`
2
2
  `)}function Swt(l,_){return l instanceof lo||l instanceof Ys,l.transform(_)}function tze(l){if(l instanceof lo)return[l.toShape()];if(l instanceof Ys)return[l];const _=[];for(const g of l.children)g instanceof iu?_.push(...tze(g)):g instanceof lo?_.push(g.toShape()):g instanceof Ys&&_.push(g);return _}function JK(l){const _=tze(l);return _.length===0?null:_.length===1?_[0]:I1(..._)}function Twt(l,_){if(l.type==="fixed")return Sa.identity();if(l.type==="revolute")return Sa.identity().rotateAxis(l.axis,_);const g=l.axis[0]*_,S=l.axis[1]*_,D=l.axis[2]*_;return Sa.identity().translate(g,S,D)}function kwt(l,_){let g=Number.isFinite(_)?_:l.defaultValue;return l.min!=null&&(g=Math.max(l.min,g)),l.max!=null&&(g=Math.min(l.max,g)),{value:g,wasClamped:g!==_}}class rze{constructor(_,g,S,D,F){this.name=_,this.parts=g,this.transforms=S,this.jointValues=D,this.solveWarnings=F}warnings(){return[...this.solveWarnings]}getJointState(){return{...this.jointValues}}getTransform(_){const g=this.transforms.get(_);if(!g)throw new Error(`Unknown part "${_}"`);return g}getPart(_){const g=this.parts.get(_);if(!g)throw new Error(`Unknown part "${_}"`);return Swt(g.part,this.getTransform(_))}toScene(){const _=(S,D,F)=>{S.children.forEach((z,ee)=>{const pe=S.childName(ee),we=pe?`${D}.${pe}`:`${D}.${ee+1}`;if(z instanceof iu){_(z,we,F);return}if(z instanceof lo){F.push({name:we,shape:z.toShape()});return}z instanceof Ys&&F.push({name:we,shape:z})})},g=[];for(const[S,D]of this.parts){const F=this.getPart(S);if(F instanceof iu){const z=[];_(F,S,z),g.push({name:S,group:z,metadata:D.metadata})}else F instanceof lo?g.push({name:S,shape:F.toShape(),metadata:D.metadata}):g.push({name:S,shape:F,metadata:D.metadata})}return g}bom(){var g,S,D,F,z;const _=[];for(const ee of this.parts.values())_.push({part:ee.name,qty:Math.max(1,Math.round(((g=ee.metadata)==null?void 0:g.qty)??1)),material:(S=ee.metadata)==null?void 0:S.material,process:(D=ee.metadata)==null?void 0:D.process,tolerance:(F=ee.metadata)==null?void 0:F.tolerance,notes:(z=ee.metadata)==null?void 0:z.notes,metadata:ee.metadata?{...ee.metadata}:void 0});return _}bomCsv(){return eze(this.bom())}collisionReport(_={}){const g=(_.parts??[...this.parts.keys()]).filter(z=>this.parts.has(z)),S=_.minOverlapVolume??.1,D=new Set((_.ignorePairs??[]).map(([z,ee])=>[z,ee].sort().join("|"))),F=[];for(let z=0;z<g.length;z++)for(let ee=z+1;ee<g.length;ee++){const pe=g[z],we=g[ee];if(D.has([pe,we].sort().join("|")))continue;const De=JK(this.getPart(pe)),te=JK(this.getPart(we));if(!(!De||!te))try{const nt=De.intersect(te);if(nt.isEmpty())continue;const Te=nt.volume();Te>S&&F.push({partA:pe,partB:we,overlapVolume:Te})}catch{}}return F}minClearance(_,g,S=10){const D=JK(this.getPart(_)),F=JK(this.getPart(g));if(!D||!F)throw new Error(`Cannot compute clearance between "${_}" and "${g}"`);try{const z=D.intersect(F);if(!z.isEmpty()&&z.volume()>0)return 0}catch{}return D.minGap(F,S)}}class nze{constructor(_="Assembly"){of(this,"parts",new Map);of(this,"joints",new Map);of(this,"jointCouplings",new Map);this.name=_}addFrame(_,g={}){return this.addPart(_,Sbe(),g)}addPart(_,g,S={}){if(this.parts.has(_))throw new Error(`Part "${_}" already exists`);return this.parts.set(_,{name:_,part:g,base:S.transform?Sa.from(S.transform):Sa.identity(),metadata:S.metadata?{...S.metadata}:void 0}),this}addJoint(_,g,S,D,F={}){if(this.joints.has(_))throw new Error(`Joint "${_}" already exists`);if(!this.parts.has(S))throw new Error(`Unknown parent part "${S}"`);if(!this.parts.has(D))throw new Error(`Unknown child part "${D}"`);if(S===D)throw new Error(`Joint "${_}" cannot connect a part to itself`);const z=$p(F.axis??[0,0,1]);return this.joints.set(_,{name:_,type:g,parent:S,child:D,frame:F.frame?Sa.from(F.frame):Sa.identity(),axis:z,min:F.min,max:F.max,defaultValue:F.default??0,unit:F.unit,effort:F.effort,velocity:F.velocity,damping:F.damping,friction:F.friction}),this}addRevolute(_,g,S,D={}){return this.addJoint(_,"revolute",g,S,D)}addPrismatic(_,g,S,D={}){return this.addJoint(_,"prismatic",g,S,D)}addFixed(_,g,S,D={}){return this.addJoint(_,"fixed",g,S,D)}addJointCoupling(_,g){const S=this.joints.get(_);if(!S)throw new Error(`Unknown joint "${_}"`);if(S.type==="fixed")throw new Error(`Joint "${_}" is fixed and cannot be coupled`);if(!g||typeof g!="object")throw new Error("addJointCoupling(...) expects an options object");if(!Array.isArray(g.terms)||g.terms.length===0)throw new Error(`Joint coupling "${_}" requires a non-empty terms array`);if(g.offset!==void 0&&!Number.isFinite(g.offset))throw new Error(`Joint coupling "${_}" offset must be finite`);const D=new Set,F=g.terms.map((z,ee)=>{if(!z||typeof z!="object")throw new Error(`Joint coupling "${_}" term[${ee}] must be an object`);const pe=typeof z.joint=="string"?z.joint.trim():"";if(!pe)throw new Error(`Joint coupling "${_}" term[${ee}] joint is required`);if(!this.joints.has(pe))throw new Error(`Joint coupling "${_}" references unknown joint "${pe}"`);if(pe===_)throw new Error(`Joint coupling "${_}" cannot reference itself`);if(D.has(pe))throw new Error(`Joint coupling "${_}" has duplicate source joint "${pe}"`);D.add(pe);const we=z.ratio??1;if(!Number.isFinite(we))throw new Error(`Joint coupling "${_}" term[${ee}] ratio must be finite`);return{joint:pe,ratio:we}});return this.jointCouplings.set(_,{joint:_,terms:F,offset:g.offset??0}),this.assertJointCouplingsAcyclic(),this}addGearCoupling(_,g,S={}){if(!S||typeof S!="object")throw new Error("addGearCoupling(...) expects an options object");const D=this.joints.get(_);if(!D)throw new Error(`Unknown joint "${_}"`);if(D.type!=="revolute")throw new Error(`addGearCoupling(...) expects driven joint "${_}" to be revolute`);const F=this.joints.get(g);if(!F)throw new Error(`Unknown joint "${g}"`);if(F.type!=="revolute")throw new Error(`addGearCoupling(...) expects driver joint "${g}" to be revolute`);if(S.offset!==void 0&&!Number.isFinite(S.offset))throw new Error(`Gear coupling "${_}" offset must be finite`);const z=S.ratio!==void 0,ee=S.pair!==void 0,pe=S.driverTeeth!==void 0||S.drivenTeeth!==void 0;if(Number(z)+Number(ee)+Number(pe)!==1)throw new Error(`Gear coupling "${_}" must provide exactly one ratio source: ratio, pair, or driverTeeth/drivenTeeth`);if(S.mesh!==void 0&&!pe)throw new Error(`Gear coupling "${_}" mesh may only be set when using driverTeeth/drivenTeeth`);let De;if(z)De=S.ratio;else if(ee){const te=S.pair;if(!te||typeof te!="object")throw new Error(`Gear coupling "${_}" pair must be an object with jointRatio`);De=te.jointRatio}else{if(!Number.isFinite(S.driverTeeth)||!Number.isFinite(S.drivenTeeth))throw new Error(`Gear coupling "${_}" driverTeeth/drivenTeeth must be finite`);if(S.driverTeeth<=0||S.drivenTeeth<=0)throw new Error(`Gear coupling "${_}" driverTeeth/drivenTeeth must be > 0`);De=((S.mesh??"external")==="internal"?1:-1)*(S.driverTeeth/S.drivenTeeth)}if(!Number.isFinite(De)||De===0)throw new Error(`Gear coupling "${_}" resolved ratio must be finite and non-zero`);return this.addJointCoupling(_,{terms:[{joint:g,ratio:De}],offset:S.offset})}assertJointCouplingsAcyclic(){const _=new Set,g=new Set,S=D=>{if(g.has(D))return;if(_.has(D))throw new Error(`Joint coupling cycle detected at "${D}"`);_.add(D);const F=this.jointCouplings.get(D);F&&F.terms.forEach(z=>S(z.joint)),_.delete(D),g.add(D)};this.jointCouplings.forEach((D,F)=>S(F))}solve(_={}){const g=new Map,S=new Map,D=[];for(const Te of this.joints.values()){if(g.has(Te.child))throw new Error(`Part "${Te.child}" has multiple parent joints`);g.set(Te.child,Te.name);const Me=S.get(Te.parent)??[];Me.push(Te),S.set(Te.parent,Me)}const F=[...this.parts.keys()].filter(Te=>!g.has(Te));if(F.length===0&&this.parts.size>0)throw new Error("Assembly has no root part (cyclic joint graph)");const z=new Map,ee=new Set,pe=new Set,we={},De=new Set,te=Te=>{const Me=we[Te];if(Me!==void 0)return Me;if(De.has(Te))throw new Error(`Joint coupling cycle detected at "${Te}"`);const bt=this.joints.get(Te);if(!bt)throw new Error(`Unknown joint "${Te}"`);De.add(Te);let vt=_[Te]??bt.defaultValue;const Bt=this.jointCouplings.get(Te);Bt&&(vt=Bt.offset,Bt.terms.forEach(vr=>{vt+=vr.ratio*te(vr.joint)}),_[Te]!==void 0&&D.push(`Joint "${Te}" state override ignored because it is coupled`));const{value:fr,wasClamped:hn}=kwt(bt,vt);return we[Te]=fr,hn&&D.push(`Joint "${Te}" clamped from ${vt} to ${fr}${bt.unit??""}`),De.delete(Te),fr},nt=(Te,Me)=>{if(ee.has(Te))throw new Error(`Cycle detected at part "${Te}"`);ee.add(Te),z.set(Te,Me),pe.add(Te);const bt=S.get(Te)??[];for(const vt of bt){const Bt=te(vt.name),fr=this.parts.get(vt.child),hn=pBe(fr.base,Twt(vt,Bt),vt.frame,Me);nt(vt.child,hn)}ee.delete(Te)};for(const Te of F){const Me=this.parts.get(Te);nt(Te,Me.base)}if(pe.size!==this.parts.size){const Te=[...this.parts.keys()].filter(Me=>!pe.has(Me));throw new Error(`Assembly graph unresolved for parts: ${Te.join(", ")}`)}return new rze(this.name,this.parts,z,we,D)}sweepJoint(_,g,S,D,F={},z={}){if(!this.joints.has(_))throw new Error(`Unknown joint "${_}"`);if(this.jointCouplings.has(_))throw new Error(`Cannot sweep coupled joint "${_}". Sweep one of its source joints instead.`);const ee=Math.max(1,Math.floor(D)),pe=[];for(let we=0;we<=ee;we++){const De=ee===0?0:we/ee,te=g+(S-g)*De,nt=this.solve({...F,[_]:te});pe.push({value:te,collisions:nt.collisionReport(z),warnings:nt.warnings()})}return pe}describe(){return{name:this.name,parts:[...this.parts.values()].map(_=>({name:_.name,part:_.part,base:_.base,metadata:_.metadata?{..._.metadata}:void 0})),joints:[...this.joints.values()].map(_=>({name:_.name,type:_.type,parent:_.parent,child:_.child,frame:_.frame,axis:[..._.axis],min:_.min,max:_.max,defaultValue:_.defaultValue,unit:_.unit,effort:_.effort,velocity:_.velocity,damping:_.damping,friction:_.friction})),jointCouplings:[...this.jointCouplings.values()].map(_=>({joint:_.joint,terms:_.terms.map(g=>({joint:g.joint,ratio:g.ratio})),offset:_.offset}))}}}function Cwt(l){return new nze(l)}let wee=null;function wwt(l){return l?Object.fromEntries(Object.entries(l).map(([_,g])=>[_,{...g}])):{}}function Ewt(l){return l?Object.fromEntries(Object.entries(l).map(([_,g])=>[_,{...g}])):{}}function Dwt(l){if(l)return{...l,leftJoints:[...l.leftJoints],rightJoints:[...l.rightJoints]}}function Pwt(l){if(l)return{...l,joints:l.joints?[...l.joints]:void 0}}function Awt(l){return l?{...l,spawnPose:l.spawnPose?[...l.spawnPose]:void 0,keyboardTeleop:l.keyboardTeleop?{...l.keyboardTeleop}:void 0}:null}function CS(l,_){if(l!==void 0&&!Number.isFinite(l))throw new Error(`${_} must be finite`)}function Nwt(l){return new Map(l.joints.map(_=>[_.name,_]))}function Iwt(){wee=null}function qje(){return wee}function Fwt(l){var we,De,te,nt;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 _=l.assembly.describe(),g=new Set(_.parts.map(Te=>Te.name)),S=Nwt(_),D=wwt(l.links);for(const[Te,Me]of Object.entries(D)){if(!g.has(Te))throw new Error(`robotExport(...) unknown link "${Te}"`);CS(Me.massKg,`robotExport link "${Te}" massKg`),CS(Me.densityKgM3,`robotExport link "${Te}" densityKgM3`)}const F=Ewt(l.joints);for(const[Te,Me]of Object.entries(F)){if(!S.has(Te))throw new Error(`robotExport(...) unknown joint "${Te}"`);CS(Me.effort,`robotExport joint "${Te}" effort`),CS(Me.velocity,`robotExport joint "${Te}" velocity`),CS(Me.damping,`robotExport joint "${Te}" damping`),CS(Me.friction,`robotExport joint "${Te}" friction`)}const z=Dwt((we=l.plugins)==null?void 0:we.diffDrive);if(z){if(z.leftJoints.length===0||z.rightJoints.length===0)throw new Error("robotExport(...) diffDrive requires at least one left joint and one right joint");if(CS(z.wheelSeparationMm,"robotExport(...) diffDrive wheelSeparationMm"),CS(z.wheelRadiusMm,"robotExport(...) diffDrive wheelRadiusMm"),z.wheelSeparationMm<=0||z.wheelRadiusMm<=0)throw new Error("robotExport(...) diffDrive wheel separation and radius must be > 0");[...z.leftJoints,...z.rightJoints].forEach(Te=>{const Me=S.get(Te);if(!Me)throw new Error(`robotExport(...) diffDrive references unknown joint "${Te}"`);if(Me.type!=="revolute")throw new Error(`robotExport(...) diffDrive joint "${Te}" must be revolute`)})}const ee=Pwt((De=l.plugins)==null?void 0:De.jointStatePublisher);ee!=null&&ee.joints&&ee.joints.forEach(Te=>{if(!S.has(Te))throw new Error(`robotExport(...) jointStatePublisher references unknown joint "${Te}"`)});const pe=Awt(l.world);return pe!=null&&pe.spawnPose&&pe.spawnPose.forEach((Te,Me)=>CS(Te,`robotExport(...) world spawnPose[${Me}]`)),CS((te=pe==null?void 0:pe.keyboardTeleop)==null?void 0:te.linearStep,"robotExport(...) world keyboardTeleop.linearStep"),CS((nt=pe==null?void 0:pe.keyboardTeleop)==null?void 0:nt.angularStep,"robotExport(...) world keyboardTeleop.angularStep"),wee={modelName:(l.modelName??_.name??"ForgeCAD Robot").trim()||"ForgeCAD Robot",assembly:_,state:{...l.state??{}},static:l.static??!1,selfCollide:l.selfCollide??!1,allowAutoDisable:l.allowAutoDisable??!0,links:D,joints:F,plugins:{diffDrive:z,jointStatePublisher:ee},world:pe},wee}var Wje=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Owt(l){if(Object.prototype.hasOwnProperty.call(l,"__esModule"))return l;var _=l.default;if(typeof _=="function"){var g=function S(){return this instanceof S?Reflect.construct(_,arguments,this.constructor):_.apply(this,arguments)};g.prototype=_.prototype}else g={};return Object.defineProperty(g,"__esModule",{value:!0}),Object.keys(l).forEach(function(S){var D=Object.getOwnPropertyDescriptor(l,S);Object.defineProperty(g,S,D.get?D:{enumerable:!0,get:function(){return l[S]}})}),g}function Vje(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 ive={exports:{}},Mwt={},Lwt=Object.freeze({__proto__:null,default:Mwt}),aP=Owt(Lwt),Uje;function Rwt(){return Uje||(Uje=1,(function(l){var _={};/*! *****************************************************************************
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