@tscircuit/runframe 0.0.3028 → 0.0.3030
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.
|
@@ -5316,7 +5316,7 @@ ${Q.join(`
|
|
|
5316
5316
|
${c}polygon: ${a.polygon.vertices}
|
|
5317
5317
|
`:Q+=`
|
|
5318
5318
|
`,a.children.length>0&&E.push(a.children)}return Q}};A.exports=o}}),qbt=fg({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(g,A){var I=_bt(),e=vbt(),t=class{constructor(B){this.polygonTree=new e,this.rootnode=new I(null),B&&this.addPolygons(B)}invert(){this.polygonTree.invert(),this.rootnode.invert()}clipTo(B,o=!1){this.rootnode.clipTo(B,o)}allPolygons(){const B=[];return this.polygonTree.getPolygons(B),B}addPolygons(B){const o=new Array(B.length);for(let C=0;C<B.length;C++)o[C]=this.polygonTree.addChild(B[C]);this.rootnode.addPolygonTreeNodes(o)}clear(){this.polygonTree.clear()}toString(){return"Tree: "+this.polygonTree.toString("")}};A.exports=t}}),o$A=fg({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(g,A){A.exports={Tree:qbt()}}}),Tbt=fg({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(g,A){var I=yQ(),e=B$A(),{Tree:t}=o$A(),B=(o,C)=>{if(!e(o,C))return I.create();const Q=new t(I.toPolygons(o)),i=new t(I.toPolygons(C));Q.invert(),i.clipTo(Q),i.invert(),Q.clipTo(i),i.clipTo(Q),Q.addPolygons(i.allPolygons()),Q.invert();const E=Q.allPolygons();return I.create(E)};A.exports=B}}),ZdI=fg({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(g,A){var I=TC(),e=OgA(),t=Tbt(),B=(...o)=>{o=I(o);let C=o.shift();return o.forEach(Q=>{C=t(C,Q)}),C=e(C),C};A.exports=B}}),Zbt=fg({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(g,A){var I=TC(),e=yQ(),t=o3(),B=e$A(),o=t$A(),C=ZdI(),Q=(...i)=>{i=I(i);const E=i.map(r=>o({z0:-1,z1:1},r)),n=C(E),s=t(n);return B(s,e.toPolygons(n))};A.exports=Q}}),Obt=fg({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(g,A){var I=TC(),e=ZgA(),t=fQ(),B=yQ(),o=Zbt(),C=ZdI(),Q=(...i)=>{if(i=I(i),i.length===0)throw new Error("wrong number of arguments");if(!e(i))throw new Error("only intersect of the types are supported");const E=i[0];return t.isA(E)?o(i):B.isA(E)?C(i):E};A.exports=Q}}),C$A=fg({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(g,A){var I=_i(),e=jDI(),t=B=>e(B,{skipTriangulation:!0}).map(Q=>{const i=Q.map(E=>B[E]);return I.create(i)});A.exports=t}}),OdI=fg({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(g,A){var I=yQ(),e=B$A(),{Tree:t}=o$A(),B=(C,Q)=>{if(!e(C,Q))return o(C,Q);const i=new t(I.toPolygons(C)),E=new t(I.toPolygons(Q));i.clipTo(E,!1),E.clipTo(i),E.invert(),E.clipTo(i),E.invert();const n=i.allPolygons().concat(E.allPolygons());return I.create(n)},o=(C,Q)=>{let i=I.toPolygons(C);return i=i.concat(I.toPolygons(Q)),I.create(i)};A.exports=B}}),Q$A=fg({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(g,A){var I=TC(),e=OgA(),t=OdI(),B=(...o)=>{o=I(o);let C;for(C=1;C<o.length;C+=2)o.push(t(o[C-1],o[C]));let Q=o[C-1];return Q=e(Q),Q};A.exports=B}}),WdI=fg({"node_modules/@jscad/modeling/src/operations/minkowski/minkowskiSum.js"(g,A){var I=TC(),e=yQ(),t=_i(),B=C$A(),o=Q$A(),C=(...r)=>{if(r=I(r),r.length!==2)throw new Error("minkowskiSum requires exactly two geometries");const[a,c]=r;if(!e.isA(a)||!e.isA(c))throw new Error("minkowskiSum requires geom3 geometries");const h=e.isConvex(a),l=e.isConvex(c);if(h&&l)return n(a,c);if(!h&&l)return Q(a,c);if(h&&!l)return Q(c,a);throw new Error("minkowskiSum of two non-convex geometries is not yet supported")},Q=(r,a)=>{const c=i(r);if(c.length===0)return e.create();const h=c.map(l=>n(l,a));return h.length===1?h[0]:o(h)},i=r=>{const a=e.toPolygons(r);if(a.length===0)return[];const c=[];for(let h=0;h<a.length;h++){const l=a[h],D=l.vertices;let d=0,y=0,w=0;for(let R=0;R<D.length;R++)d+=D[R][0],y+=D[R][1],w+=D[R][2];d/=D.length,y/=D.length,w/=D.length;const u=t.plane(l),G=u[0],m=u[1],p=u[2],k=.1,S=[d-G*k,y-m*k,w-p*k];for(let R=1;R<D.length-1;R++){const F=D[0],N=D[R],U=D[R+1],P=E(S,F,N,U);c.push(e.create(P))}}return c},E=(r,a,c,h)=>[t.create([r,c,a]),t.create([r,a,h]),t.create([a,c,h]),t.create([c,r,h])],n=(r,a)=>{const c=s(r),h=s(a);if(c.length===0||h.length===0)return e.create();const l=[];for(let d=0;d<c.length;d++){const y=c[d];for(let w=0;w<h.length;w++){const u=h[w];l.push([y[0]+u[0],y[1]+u[1],y[2]+u[2]])}}const D=B(l);return e.create(D)},s=r=>{const a=new Set,c=[],h=e.toPolygons(r);for(let l=0;l<h.length;l++){const D=h[l].vertices;for(let d=0;d<D.length;d++){const y=D[d],w=`${y[0]},${y[1]},${y[2]}`;a.has(w)||(a.add(w),c.push(y))}}return c};A.exports=C}}),Wbt=fg({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(g,A){var I=yo(),e=o3(),t=yQ(),B=i=>i.sort((E,n)=>E-n).filter((E,n,s)=>!n||E!==s[n-1]),o=(i,E,n)=>{const s=`${E}`,r=i.get(s);r===void 0?i.set(s,[n]):r.push(n)},C=(i,E)=>{const n=`${E}`;return i.get(n)},Q=i=>{const E=e(i),n=t.toPolygons(i),s=n.length,r=new Map,a=I.create();n.forEach((d,y)=>{d.vertices.forEach(w=>{o(r,I.snap(a,w,E),y)})});const c=n.map(d=>{let y=[];return d.vertices.forEach(w=>{y=y.concat(C(r,I.snap(a,w,E)))}),{e:1,d:B(y)}});r.clear();let h=0;const l=c.length;for(let d=0;d<l;d++){const y=c[d];if(y.e>0){const w=new Array(s);w[d]=!0;do h=0,w.forEach((u,G)=>{const m=c[G];if(m.e>0){m.e=-1;for(let p=0;p<m.d.length;p++)w[m.d[p]]=!0;h++}});while(h>0);y.indexes=w}}const D=[];for(let d=0;d<l;d++)if(c[d].indexes){const y=[];c[d].indexes.forEach((w,u)=>y.push(n[u])),D.push(t.create(y))}return D};A.exports=Q}}),Vbt=fg({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(g,A){var I=TC(),e=yQ(),t=Wbt(),B=(...o)=>{if(o=I(o),o.length===0)throw new Error("wrong number of arguments");const C=o.map(Q=>e.isA(Q)?t(Q):Q);return C.length===1?C[0]:C};A.exports=B}}),jbt=fg({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(g,A){var I=yQ(),e=B$A(),{Tree:t}=o$A(),B=(o,C)=>{if(!e(o,C))return I.clone(o);const Q=new t(I.toPolygons(o)),i=new t(I.toPolygons(C));Q.invert(),Q.clipTo(i),i.clipTo(Q,!0),Q.addPolygons(i.allPolygons()),Q.invert();const E=Q.allPolygons();return I.create(E)};A.exports=B}}),VdI=fg({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(g,A){var I=TC(),e=OgA(),t=jbt(),B=(...o)=>{o=I(o);let C=o.shift();return o.forEach(Q=>{C=t(C,Q)}),C=e(C),C};A.exports=B}}),zbt=fg({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(g,A){var I=TC(),e=yQ(),t=o3(),B=e$A(),o=t$A(),C=VdI(),Q=(...i)=>{i=I(i);const E=i.map(r=>o({z0:-1,z1:1},r)),n=C(E),s=t(n);return B(s,e.toPolygons(n))};A.exports=Q}}),Xbt=fg({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(g,A){var I=TC(),e=ZgA(),t=fQ(),B=yQ(),o=zbt(),C=VdI(),Q=(...i)=>{if(i=I(i),i.length===0)throw new Error("wrong number of arguments");if(!e(i))throw new Error("only subtract of the types are supported");const E=i[0];return t.isA(E)?o(i):B.isA(E)?C(i):E};A.exports=Q}}),jdI=fg({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(g,A){var I=TC(),e=yQ(),t=o3(),B=e$A(),o=t$A(),C=Q$A(),Q=(...i)=>{i=I(i);const E=i.map(r=>o({z0:-1,z1:1},r)),n=C(E),s=t(n);return B(s,e.toPolygons(n))};A.exports=Q}}),i$A=fg({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(g,A){var I=TC(),e=ZgA(),t=fQ(),B=yQ(),o=jdI(),C=Q$A(),Q=(...i)=>{if(i=I(i),i.length===0)throw new Error("wrong number of arguments");if(!e(i))throw new Error("only unions of the same type are supported");const E=i[0];return t.isA(E)?o(i):B.isA(E)?C(i):E};A.exports=Q}}),WgA=fg({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(g,A){A.exports={intersect:Obt(),minkowski:WdI(),scission:Vbt(),subtract:Xbt(),union:i$A()}}}),ldA=fg({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(g,A){var{EPS:I,TAU:e}=nE(),t=mdI(),B=XXA(),o=Ci(),C=rdA(),Q=(i,E)=>{const n={delta:1,corners:"edge",closed:!1,segments:16};let{delta:s,corners:r,closed:a,segments:c}=Object.assign({},n,i);if(Math.abs(s)<I)return E;let h=i.closed?C(E):1;h===0&&(h=1);const l=h>0&&s>=0||h<0&&s<0;s=Math.abs(s);let D=null,d=[];const y=[],w=o.create(),u=E.length;for(let G=0;G<u;G++){const m=(G+1)%u,p=E[G],k=E[m];l?o.subtract(w,p,k):o.subtract(w,k,p),o.normal(w,w),o.normalize(w,w),o.scale(w,w,s);const S=o.add(o.create(),p,w),R=o.add(o.create(),k,w),F=[S,R];if(D!=null&&(a||!a&&m!==0)){const N=t(D[0],D[1],F[0],F[1]);N?(d.pop(),F[0]=N):y.push({c:p,s0:D,s1:F})}D=[S,R],!(m===0&&!a)&&(d.push(F[0]),d.push(F[1]))}if(a&&D!=null){const G=d[0],m=d[1],p=t(D[0],D[1],G,m);if(p)d[0]=p,d.pop();else{const k=E[0],S=[G,m];y.push({c:k,s0:D,s1:S})}}if(r==="edge"){const G=new Map;d.forEach((k,S)=>G.set(k,S));const m=B.create(),p=B.create();y.forEach(k=>{B.fromPoints(m,k.s0[0],k.s0[1]),B.fromPoints(p,k.s1[0],k.s1[1]);const S=B.intersectPointOfLines(m,p);if(Number.isFinite(S[0])&&Number.isFinite(S[1])){const R=k.s0[1],F=G.get(R);d[F]=S,d[(F+1)%d.length]=void 0}else{const R=k.s1[0],F=G.get(R);d[F]=void 0}}),d=d.filter(k=>k!==void 0)}if(r==="round"){let G=Math.floor(c/4);const m=o.create();y.forEach(p=>{let k=o.angle(o.subtract(m,p.s1[0],p.c));if(k-=o.angle(o.subtract(m,p.s0[1],p.c)),l&&k<0&&(k=k+Math.PI,k<0&&(k=k+Math.PI)),!l&&k>0&&(k=k-Math.PI,k>0&&(k=k-Math.PI)),k!==0){G=Math.floor(c*(Math.abs(k)/e));const S=k/G,R=o.angle(o.subtract(m,p.s0[1],p.c)),F=[];for(let N=1;N<G;N++){const U=R+S*N,P=o.fromAngleRadians(o.create(),U);o.scale(P,P,s),o.add(P,P,p.c),F.push(P)}if(F.length>0){const N=p.s0[1];let U=d.findIndex(P=>o.equals(N,P));U=(U+1)%d.length,d.splice(U,0,...F)}}else{const S=p.s1[0],R=d.findIndex(F=>o.equals(S,F));d.splice(R,1)}})}return d};A.exports=Q}}),$bt=fg({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(g,A){var I=fQ(),e=ldA(),t=(B,o)=>{const C={delta:1,corners:"edge",segments:16},{delta:Q,corners:i,segments:E}=Object.assign({},C,B);if(!(i==="edge"||i==="chamfer"||i==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const r=I.toOutlines(o).map(a=>(B={delta:Q,corners:i,closed:!0,segments:E},e(B,a))).reduce((a,c)=>a.concat(I.toSides(I.fromPoints(c))),[]);return I.create(r)};A.exports=t}}),A9t=fg({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(g,A){var I=_a(),e=yo(),t=yQ(),B=_i(),o=(C,Q)=>{e.dot(B.plane(Q),C)>0&&(Q=B.invert(Q));const E=[Q],n=B.transform(I.fromTranslation(I.create(),C),Q),s=Q.vertices.length;for(let r=0;r<s;r++){const a=r<s-1?r+1:0,c=B.create([Q.vertices[r],n.vertices[r],n.vertices[a],Q.vertices[a]]);E.push(c)}return E.push(B.invert(n)),t.create(E)};A.exports=o}}),g9t=fg({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(g,A){var{EPS:I,TAU:e}=nE(),t=_a(),B=yo(),o=qdI(),C=yQ(),Q=_i(),i=PdI(),E=OgA(),n=OdI(),s=A9t(),r=(l,D,d)=>{const y=D.toString();if(l.has(y))l.get(y)[1].push(d);else{const w=[D,[d]];l.set(y,w)}},a=(l,D,d)=>{const y=D[0].toString(),w=D[1].toString(),u=y<w?`${y},${w}`:`${w},${y}`;if(l.has(u))l.get(u)[1].push(d);else{const G=[D,[d]];l.set(u,G)}},c=(l,D)=>{l.findIndex(y=>y===D)<0&&l.push(D)},h=(l,D)=>{const d={delta:1,segments:12},{delta:y,segments:w}=Object.assign({},d,l);let u=C.create();const G=new Map,m=new Map,p=B.create(),k=B.create();return C.toPolygons(D).forEach((R,F)=>{const N=B.scale(B.create(),Q.plane(R),2*y),U=Q.transform(t.fromTranslation(t.create(),B.scale(B.create(),N,-.5)),R),P=s(N,U);u=n(u,P);const b=R.vertices;for(let H=0;H<b.length;H++){r(G,b[H],Q.plane(R));const q=(H+1)%b.length,j=[b[H],b[q]];a(m,j,Q.plane(R))}}),m.forEach(R=>{const F=R[0],N=R[1],U=F[0],P=F[1],b=B.subtract(B.create(),P,U);B.normalize(b,b);const H=N[0],q=B.cross(B.create(),H,b);let j=[];for(let DA=0;DA<w;DA++)c(j,DA*e/w);for(let DA=0,CA=N.length;DA<CA;DA++){const cA=N[DA],nA=B.dot(q,cA),hA=B.dot(H,cA);let fA=Math.atan2(nA,hA);fA<0&&(fA+=e),c(j,fA),fA=Math.atan2(-nA,-hA),fA<0&&(fA+=e),c(j,fA)}j=j.sort(o);const Z=j.length;let O,AA;const tA=[],eA=[],iA=[];for(let DA=-1;DA<Z;DA++){const CA=j[DA<0?DA+Z:DA],cA=Math.sin(CA),nA=Math.cos(CA);B.scale(p,H,nA*y),B.scale(k,q,cA*y),B.add(p,p,k);const hA=B.add(B.create(),U,p),fA=B.add(B.create(),P,p);let NA=!1;if(DA>=0&&B.distance(hA,O)<I&&(NA=!0),!NA){if(DA>=0){tA.push(hA),eA.push(fA);const aA=[AA,fA,hA,O],xA=Q.create(aA);iA.push(xA)}O=hA,AA=fA}}eA.reverse(),iA.push(Q.create(tA)),iA.push(Q.create(eA));const sA=C.create(iA);u=n(u,sA)}),G.forEach(R=>{const F=R[0],N=R[1],U=N[0];let P=null,b=0;for(let Z=1;Z<N.length;Z++){const O=N[Z],AA=B.cross(p,U,O),tA=B.length(AA);tA>.05&&tA>b&&(b=tA,P=O)}P||(P=B.orthogonal(p,U));const H=B.cross(p,U,P);B.normalize(H,H);const q=B.cross(k,H,U),j=i({center:[F[0],F[1],F[2]],radius:y,segments:w,axes:[U,H,q]});u=n(u,j)}),E(u)};A.exports=h}}),I9t=fg({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(g,A){var I=yQ(),e=i$A(),t=g9t(),B=(o,C)=>{const Q={delta:1,corners:"round",segments:12},{delta:i,corners:E,segments:n}=Object.assign({},Q,o);if(E!=="round")throw new Error('corners must be "round" for 3D geometries');if(I.toPolygons(C).length===0)throw new Error("the given geometry cannot be empty");o={delta:i,corners:E,segments:n};const r=t(o,C);return e(C,r)};A.exports=B}}),e9t=fg({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(g,A){var I=rdA(),e=Ci(),t=fQ(),B=ca(),o=ldA(),C=E=>{let{external:n,internal:s}=E;I(n)<0?n=n.reverse():s=s.reverse();const r=B.fromPoints({closed:!0},n),a=B.fromPoints({closed:!0},s),c=t.toSides(t.fromPoints(B.toPoints(r))),h=t.toSides(t.fromPoints(B.toPoints(a)));return c.push(...h),t.create(c)},Q=(E,n,s,r)=>{const{points:a,external:c,internal:h}=E,l=Math.floor(n/2),D=[],d=[];if(s==="round"&&l>0){const w=Math.PI/l,u=a[a.length-1],G=e.angle(e.subtract(e.create(),c[c.length-1],u)),m=a[0],p=e.angle(e.subtract(e.create(),h[0],m));for(let k=1;k<l;k++){let S=G+w*k,R=e.fromAngleRadians(e.create(),S);e.scale(R,R,r),e.add(R,R,u),D.push(R),S=p+w*k,R=e.fromAngleRadians(e.create(),S),e.scale(R,R,r),e.add(R,R,m),d.push(R)}}const y=[];return y.push(...c,...D,...h.reverse(),...d),t.fromPoints(y)},i=(E,n)=>{E=Object.assign({},{delta:1,corners:"edge",segments:16},E);const{delta:r,corners:a,segments:c}=E;if(r<=0)throw new Error("the given delta must be positive for paths");if(!(a==="edge"||a==="chamfer"||a==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const h=n.isClosed,l=B.toPoints(n);if(l.length===0)throw new Error("the given geometry cannot be empty");const D={points:l,external:o({delta:r,corners:a,segments:c,closed:h},l),internal:o({delta:-r,corners:a,segments:c,closed:h},l)};return n.isClosed?C(D):Q(D,c,a,r)};A.exports=i}}),E$A=fg({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(g,A){var I=TC(),e=fQ(),t=yQ(),B=ca(),o=$bt(),C=I9t(),Q=e9t(),i=(E,...n)=>{if(n=I(n),n.length===0)throw new Error("wrong number of arguments");const s=n.map(r=>B.isA(r)?Q(E,r):e.isA(r)?o(E,r):t.isA(r)?C(E,r):r);return s.length===1?s[0]:s};A.exports=i}}),t9t=fg({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(g,A){var I=fQ(),e=OXA(),t=ldA(),B=(o,C)=>{const Q={delta:1,corners:"edge",segments:0},{delta:i,corners:E,segments:n}=Object.assign({},Q,o);if(!(E==="edge"||E==="chamfer"||E==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const s=I.toOutlines(C),a=s.map(c=>(o={delta:s.reduce((D,d)=>D+e.arePointsInside(c,e.create(d)),0)%2===0?i:-i,corners:E,closed:!0,segments:n},t(o,c))).reduce((c,h)=>c.concat(I.toSides(I.fromPoints(h))),[]);return I.create(a)};A.exports=B}}),B9t=fg({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(g,A){var I=ca(),e=ldA(),t=(B,o)=>{const C={delta:1,corners:"edge",closed:o.isClosed,segments:16},{delta:Q,corners:i,closed:E,segments:n}=Object.assign({},C,B);if(!(i==="edge"||i==="chamfer"||i==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');B={delta:Q,corners:i,closed:E,segments:n};const s=e(B,I.toPoints(o));return I.fromPoints({closed:E},s)};A.exports=t}}),o9t=fg({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(g,A){var I=TC(),e=fQ(),t=ca(),B=t9t(),o=B9t(),C=(Q,...i)=>{if(i=I(i),i.length===0)throw new Error("wrong number of arguments");const E=i.map(n=>t.isA(n)?o(Q,n):e.isA(n)?B(Q,n):n);return E.length===1?E[0]:E};A.exports=C}}),zdI=fg({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(g,A){A.exports={expand:E$A(),offset:o9t()}}}),DdA=fg({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(g,A){var I=_a(),e=yo(),t=fQ(),B=QT(),o=hdA(),C=(Q,i)=>{const E={offset:[0,0,1],twistAngle:0,twistSteps:12,repair:!0};let{offset:n,twistAngle:s,twistSteps:r,repair:a}=Object.assign({},E,Q);if(r<1)throw new Error("twistSteps must be 1 or more");s===0&&(r=1);const c=e.clone(n),h=t.toSides(i);if(h.length===0)throw new Error("the given geometry cannot be empty");const l=B.fromSides(h);c[2]<0&&B.reverse(l,l);const D=I.create(),d=(y,w,u)=>{const G=w/r*s,m=e.scale(e.create(),c,w/r);return I.multiply(D,I.fromZRotation(D,G),I.fromTranslation(I.create(),m)),B.transform(D,u)};return Q={numberOfSlices:r+1,capStart:!0,capEnd:!0,repair:a,callback:d},o(Q,l)};A.exports=C}}),C9t=fg({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(g,A){var I=fQ(),e=ca(),t=DdA(),B=(o,C)=>{if(!C.isClosed)throw new Error("extruded path must be closed");const Q=e.toPoints(C),i=I.fromPoints(Q);return t(o,i)};A.exports=B}}),Q9t=fg({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(g,A){var I=TC(),e=fQ(),t=ca(),B=DdA(),o=C9t(),C=(Q,...i)=>{const E={height:1,twistAngle:0,twistSteps:1,repair:!0},{height:n,twistAngle:s,twistSteps:r,repair:a}=Object.assign({},E,Q);if(i=I(i),i.length===0)throw new Error("wrong number of arguments");Q={offset:[0,0,n],twistAngle:s,twistSteps:r,repair:a};const c=i.map(h=>t.isA(h)?o(Q,h):e.isA(h)?B(Q,h):h);return c.length===1?c[0]:c};A.exports=C}}),i9t=fg({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(g,A){var I=ca(),e=E$A(),t=DdA(),B=(o,C)=>{const Q={size:1,height:1},{size:i,height:E}=Object.assign({},Q,o);if(o.delta=i,o.offset=[0,0,E],I.toPoints(C).length===0)throw new Error("the given geometry cannot be empty");const s=e(o,C);return t(o,s)};A.exports=B}}),E9t=fg({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(g,A){var{area:I}=HgA(),e=fQ(),t=ca(),B=E$A(),o=DdA(),C=(Q,i)=>{const E={size:1,height:1},{size:n,height:s}=Object.assign({},E,Q);Q.delta=n,Q.offset=[0,0,s];const r=e.toOutlines(i);if(r.length===0)throw new Error("the given geometry cannot be empty");const c=r.map(l=>(I(l)<0&&l.reverse(),B(Q,t.fromPoints({closed:!0},l)))).reduce((l,D)=>l.concat(e.toSides(D)),[]),h=e.create(c);return o(Q,h)};A.exports=C}}),n9t=fg({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(g,A){var I=TC(),e=fQ(),t=ca(),B=i9t(),o=E9t(),C=(Q,...i)=>{const E={size:1,height:1},{size:n,height:s}=Object.assign({},E,Q);if(i=I(i),i.length===0)throw new Error("wrong number of arguments");if(n<=0)throw new Error("size must be positive");if(s<=0)throw new Error("height must be positive");const r=i.map(a=>t.isA(a)?B(Q,a):e.isA(a)?o(Q,a):a);return r.length===1?r[0]:r};A.exports=C}}),s9t=fg({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(g,A){var{TAU:I}=nE(),e=_a(),t=fQ(),B=hdA(),o=QT(),C=(Q,i)=>{const E={angle:I,startAngle:0,pitch:10,height:0,endOffset:0,segmentsPerRotation:32};let{angle:n,startAngle:s,pitch:r,height:a,endOffset:c,segmentsPerRotation:h}=Object.assign({},E,Q);if(a!=0&&(r=a/(n/I)),h<3)throw new Error("The number of segments per rotation needs to be at least 3.");const D=t.toSides(i);if(D.length===0)throw new Error("The given geometry cannot be empty");const d=D.filter(k=>k[0][0]>=0);let y=o.fromSides(D);d.length===0&&(y=o.reverse(y));const w=Math.round(h/I*Math.abs(n)),u=w>=2?w:2,G=e.create(),m=e.create(),p=(k,S,R)=>{const F=s+n/u*S,N=c/u*S,U=(F-s)/I*r;return e.multiply(G,e.fromTranslation(e.create(),[N,0,U*Math.sign(n)]),e.fromXRotation(e.create(),-I/4*Math.sign(n))),e.multiply(m,e.fromZRotation(e.create(),F),G),o.transform(m,R)};return B({numberOfSlices:u+1,callback:p},y)};A.exports=C}}),a9t=fg({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(g,A){var I=TC(),e=zXA(),t=ix(),B=_a(),o=fQ(),C=yQ(),Q=_i(),i=o3(),E=jdI(),n=(r,a)=>{const c=t.fromNormalAndPoint(t.create(),r.axis,r.origin);if(Number.isNaN(c[0])||Number.isNaN(c[1])||Number.isNaN(c[2])||Number.isNaN(c[3]))throw new Error("project: invalid axis or origin");const h=i(a),l=h*h*Math.sqrt(3)/4;if(h===0)return o.create();const D=C.toPolygons(a);let d=[];for(let w=0;w<D.length;w++){const u=D[w].vertices.map(p=>t.projectionOfPoint(c,p)),G=Q.create(u),m=Q.plane(G);e(c,m)&&(Q.measureArea(G)<l||d.push(G))}if(!e(c,[0,0,1])){const w=B.fromVectorRotation(B.create(),c,[0,0,1]);d=d.map(u=>Q.transform(w,u))}d=d.sort((w,u)=>Q.measureArea(u)-Q.measureArea(w));const y=d.map(w=>o.fromPoints(w.vertices));return E(y)},s=(r,...a)=>{const c={axis:[0,0,1],origin:[0,0,0]},{axis:h,origin:l}=Object.assign({},c,r);if(a=I(a),a.length===0)throw new Error("wrong number of arguments");r={axis:h,origin:l};const D=a.map(d=>C.isA(d)?n(r,d):d);return D.length===1?D[0]:D};A.exports=s}}),VgA=fg({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(g,A){A.exports={extrudeFromSlices:hdA(),extrudeLinear:Q9t(),extrudeRectangular:n9t(),extrudeRotate:bdI(),extrudeHelical:s9t(),project:a9t(),slice:QT()}}}),n$A=fg({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(g,A){var I=Ci(),e=o=>{let C=I.fromValues(1/0,1/0);o.forEach(E=>{(E[1]<C[1]||E[1]===C[1]&&E[0]<C[0])&&(C=E)});const Q=[];o.forEach(E=>{const n=B(E[1]-C[1],E[0]-C[0]),s=I.squaredDistance(E,C);Q.push({point:E,angle:n,distSq:s})}),Q.sort((E,n)=>E.angle!==n.angle?E.angle-n.angle:E.distSq-n.distSq);const i=[];return Q.forEach(E=>{let n=i.length;for(;n>1&&t(i[n-2],i[n-1],E.point)<=Number.EPSILON;)i.pop(),n=i.length;i.push(E.point)}),i},t=(o,C,Q)=>(C[0]-o[0])*(Q[1]-o[1])-(C[1]-o[1])*(Q[0]-o[0]),B=(o,C)=>o===0&&C===0?-1/0:-C/o;A.exports=e}}),s$A=fg({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(g,A){var I=fQ(),e=yQ(),t=ca(),B=o=>{const C=new Set,Q=[],i=E=>{const n=E.toString();C.has(n)||(Q.push(E),C.add(n))};return o.forEach(E=>{I.isA(E)?I.toPoints(E).forEach(i):e.isA(E)?e.toPoints(E).forEach(n=>n.forEach(i)):t.isA(E)&&t.toPoints(E).forEach(i)}),Q};A.exports=B}}),r9t=fg({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(g,A){var I=TC(),e=ca(),t=n$A(),B=s$A(),o=(...C)=>{C=I(C);const Q=B(C),i=t(Q);return e.fromPoints({closed:!0},i)};A.exports=o}}),c9t=fg({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(g,A){var I=TC(),e=fQ(),t=n$A(),B=s$A(),o=(...C)=>{C=I(C);const Q=B(C),i=t(Q);return i.length<3?e.create():e.fromPoints(i)};A.exports=o}}),h9t=fg({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(g,A){var I=TC(),e=yQ(),t=s$A(),B=C$A(),o=(...C)=>{C=I(C);const Q=t(C);return Q.length===0?e.create():e.create(B(Q))};A.exports=o}}),XdI=fg({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(g,A){var I=TC(),e=ZgA(),t=fQ(),B=yQ(),o=ca(),C=r9t(),Q=c9t(),i=h9t(),E=(...n)=>{if(n=I(n),n.length===0)throw new Error("wrong number of arguments");if(!e(n))throw new Error("only hulls of the same type are supported");const s=n[0];return o.isA(s)?C(n):t.isA(s)?Q(n):B.isA(s)?i(n):s};A.exports=E}}),l9t=fg({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(g,A){var I=TC(),e=i$A(),t=XdI(),B=(...o)=>{if(o=I(o),o.length<2)throw new Error("wrong number of arguments");const C=[];for(let Q=1;Q<o.length;Q++)C.push(t(o[Q-1],o[Q]));return e(C)};A.exports=B}}),D9t=fg({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(g,A){A.exports={hull:XdI(),hullChain:l9t(),hullPoints2:n$A(),hullPoints3:C$A()}}}),d9t=fg({"node_modules/@jscad/modeling/src/operations/minkowski/index.js"(g,A){A.exports={minkowskiSum:WdI()}}}),$dI=fg({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(g,A){var I=yo(),e=_i(),t=(o,C)=>{const Q=Math.abs(e.measureArea(C));return Number.isFinite(Q)&&Q>o},B=(o,C)=>{let Q=C.map(E=>{const n=E.vertices.map(a=>I.snap(I.create(),a,o)),s=[];for(let a=0;a<n.length;a++){const c=(a+1)%n.length;I.equals(n[a],n[c])||s.push(n[a])}const r=e.create(s);return E.color&&(r.color=E.color),r});const i=o*o*Math.sqrt(3)/4;return Q=Q.filter(E=>t(i,E)),Q};A.exports=B}}),y9t=fg({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(g,A){var I=zXA(),e=yo(),t=_i(),B=l=>{const D=t.toPoints(l),d=[];for(let y=0;y<D.length;y++){const w=(y+1)%D.length,u={v1:D[y],v2:D[w]};d.push(u)}for(let y=0;y<d.length;y++){const w=(y+1)%D.length;d[y].next=d[w],d[w].prev=d[y]}return d},o=(l,D)=>{const d=`${D.v1}:${D.v2}`;l.set(d,D)},C=(l,D)=>{const d=`${D.v1}:${D.v2}`;l.delete(d)},Q=(l,D)=>{const d=`${D.v2}:${D.v1}`;return l.get(d)},i=(l,D,d)=>{let y=l.prev.v1,w=l.prev.v2,u=D.next.v2;const G=s(y,w,u,d);y=D.prev.v1,w=D.prev.v2,u=l.next.v2;const m=s(y,w,u,d);return[G,m]},E=e.create(),n=e.create(),s=(l,D,d,y)=>{const w=e.subtract(E,D,l),u=e.subtract(n,d,D);return e.cross(w,w,u),e.dot(w,y)},r=l=>{let D;const d=[];for(;l.next;){const y=l.next;d.push(l.v1),l.v1=null,l.v2=null,l.next=null,l.prev=null,l=y}return d.length>0&&(D=t.create(d)),D},a=l=>{if(l.length<2)return l;const D=l[0].plane,d=l.slice(),y=new Map;for(;d.length>0;){const u=d.shift(),G=B(u);for(let m=0;m<G.length;m++){const p=G[m],k=Q(y,p);if(k){const S=i(p,k,D);if(S[0]>=0&&S[1]>=0){const R=k.next,F=p.next;p.prev.next=k.next,p.next.prev=k.prev,k.prev.next=p.next,k.next.prev=p.prev,p.v1=null,p.v2=null,p.next=null,p.prev=null,C(y,k),k.v1=null,k.v2=null,k.next=null,k.prev=null;const N=(U,P,b)=>{const H={v1:b.v1,v2:P.v2,next:P.next,prev:b.prev};b.prev.next=H,P.next.prev=H,C(U,P),P.v1=null,P.v2=null,P.next=null,P.prev=null,C(U,b),b.v1=null,b.v2=null,b.next=null,b.prev=null};S[0]===0&&N(y,R,R.prev),S[1]===0&&N(y,F,F.prev)}}else p.next&&o(y,p)}}const w=[];return y.forEach(u=>{const G=r(u);G&&w.push(G)}),y.clear(),w},c=(l,D)=>Math.abs(l[3]-D[3])<15e-8?I(l,D):!1,h=(l,D)=>{const d=[];D.forEach(w=>{const u=d.find(G=>c(G[0],t.plane(w)));u?u[1].push(w):d.push([t.plane(w),[w]])});let y=[];return d.forEach(w=>{const u=w[1],G=a(u);y=y.concat(G)}),y};A.exports=h}}),w9t=fg({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(g,A){var I=nE(),e=yo(),t=_i(),B=i=>`${i}`,o=(i,E,n,s,r,a)=>{const c=B(s),h=B(r),l=`${c}/${h}`,D=`${h}/${c}`;if(i.has(D))return C(i,E,n,r,s,null),null;const d={vertex0:s,vertex1:r,polygonindex:a};return i.has(l)?i.get(l).push(d):i.set(l,[d]),E.has(c)?E.get(c).push(l):E.set(c,[l]),n.has(h)?n.get(h).push(l):n.set(h,[l]),l},C=(i,E,n,s,r,a)=>{const c=B(s),h=B(r),l=`${c}/${h}`;let D=-1;const d=i.get(l);for(let y=0;y<d.length;y++){const w=d[y];let u=B(w.vertex0);if(u===c&&(u=B(w.vertex1),u===h&&!(a!==null&&w.polygonindex!==a))){D=y;break}}d.splice(D,1),d.length===0&&i.delete(l),D=E.get(c).indexOf(l),E.get(c).splice(D,1),E.get(c).length===0&&E.delete(c),D=n.get(h).indexOf(l),n.get(h).splice(D,1),n.get(h).length===0&&n.delete(h)},Q=i=>{const E=new Map;for(let n=0;n<i.length;n++){const s=i[n],r=s.vertices.length;if(r>=3){let a=s.vertices[0],c=B(a);for(let h=0;h<r;h++){let l=h+1;l===r&&(l=0);const D=s.vertices[l],d=B(D),y=`${c}/${d}`,w=`${d}/${c}`;if(E.has(w)){const u=E.get(w);u.splice(-1,1),u.length===0&&E.delete(w)}else{const u={vertex0:a,vertex1:D,polygonindex:n};E.has(y)?E.get(y).push(u):E.set(y,[u])}a=D,c=d}}else console.warn("warning: invalid polygon found during insertTjunctions")}if(E.size>0){const n=new Map,s=new Map,r=new Map;for(const[c,h]of E)r.set(c,!0),h.forEach(l=>{const D=B(l.vertex0),d=B(l.vertex1);n.has(D)?n.get(D).push(c):n.set(D,[c]),s.has(d)?s.get(d).push(c):s.set(d,[c])});const a=i.slice(0);for(;E.size!==0;){for(const h of E.keys())r.set(h,!0);let c=!1;for(;;){const h=Array.from(r.keys());if(h.length===0)break;const l=h[0];let D=!0;if(E.has(l)){const y=E.get(l)[0];for(let w=0;w<2;w++){const u=w===0?y.vertex0:y.vertex1,G=w===0?y.vertex1:y.vertex0,m=B(u),p=B(G);let k=[];w===0?s.has(m)&&(k=s.get(m)):n.has(m)&&(k=n.get(m));for(let S=0;S<k.length;S++){const R=k[S],F=E.get(R)[0],N=w===0?F.vertex0:F.vertex1;if(w===0?F.vertex1:F.vertex0,B(N)===p){C(E,n,s,u,G,null),C(E,n,s,G,u,null),D=!1,w=2,c=!0;break}else{const P=u,b=G,H=N,q=e.subtract(e.create(),H,P),j=e.dot(e.subtract(e.create(),b,P),q)/e.dot(q,q);if(j>0&&j<1){const Z=e.scale(e.create(),q,j);if(e.add(Z,Z,P),e.squaredDistance(Z,b)<I.EPS*I.EPS){const AA=F.polygonindex,tA=a[AA],eA=B(F.vertex1);let iA=-1;for(let nA=0;nA<tA.vertices.length;nA++)if(B(tA.vertices[nA])===eA){iA=nA;break}const sA=tA.vertices.slice(0);sA.splice(iA,0,G);const DA=t.create(sA);a[AA]=DA,C(E,n,s,F.vertex0,F.vertex1,AA);const CA=o(E,n,s,F.vertex0,G,AA),cA=o(E,n,s,G,F.vertex1,AA);CA!==null&&r.set(CA,!0),cA!==null&&r.set(cA,!0),D=!1,w=2,c=!0;break}}}}}}D&&r.delete(l)}if(!c)break}i=a}return E.clear(),i};A.exports=Q}}),u9t=fg({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(g,A){var I=yo(),e=_i(),t=(o,C,Q)=>{const i=C.vertices.length;if(i>3){if(i>4){const s=[0,0,0];C.vertices.forEach(r=>I.add(s,s,r)),I.snap(s,I.divide(s,s,[i,i,i]),o);for(let r=0;r<i;r++){const a=e.create([s,C.vertices[r],C.vertices[(r+1)%i]]);C.color&&(a.color=C.color),Q.push(a)}return}const E=e.create([C.vertices[0],C.vertices[1],C.vertices[2]]),n=e.create([C.vertices[0],C.vertices[2],C.vertices[3]]);C.color&&(E.color=C.color,n.color=C.color),Q.push(E,n);return}Q.push(C)},B=(o,C)=>{const Q=[];return C.forEach(i=>{t(o,i,Q)}),Q};A.exports=B}}),G9t=fg({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(g,A){var I=TC(),e=o3(),t=fQ(),B=yQ(),o=ca(),C=$dI(),Q=y9t(),i=w9t(),E=u9t(),n=(c,h)=>h,s=(c,h)=>h,r=(c,h)=>{const l={snap:!1,simplify:!1,triangulate:!1},{snap:D,simplify:d,triangulate:y}=Object.assign({},l,c),w=e(h);let u=B.toPolygons(h);D&&(u=C(w,u)),d&&(u=Q(w,u)),y&&(u=i(u),u=E(w,u));const G=Object.assign({},h);return G.polygons=u,G},a=(c,...h)=>{if(h=I(h),h.length===0)throw new Error("wrong number of arguments");const l=h.map(D=>{if(o.isA(D))return n(c,D);if(t.isA(D))return s(c,D);if(B.isA(D))return r(c,D);throw new Error("invalid geometry")});return l.length===1?l[0]:l};A.exports=a}}),m9t=fg({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(g,A){var I=TC(),e=Ci(),t=fQ(),B=yQ(),o=ca(),C=o3(),Q=$dI(),i=r=>{const a=C(r),h=o.toPoints(r).map(l=>e.snap(e.create(),l,a));return o.create(h)},E=r=>{const a=C(r);let h=t.toSides(r).map(l=>[e.snap(e.create(),l[0],a),e.snap(e.create(),l[1],a)]);return h=h.filter(l=>!e.equals(l[0],l[1])),t.create(h)},n=r=>{const a=C(r),c=B.toPolygons(r),h=Q(a,c);return B.create(h)},s=(...r)=>{if(r=I(r),r.length===0)throw new Error("wrong number of arguments");const a=r.map(c=>o.isA(c)?i(c):t.isA(c)?E(c):B.isA(c)?n(c):c);return a.length===1?a[0]:a};A.exports=s}}),p9t=fg({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(g,A){A.exports={generalize:G9t(),snap:m9t(),retessellate:OgA()}}}),k9t=fg({"node_modules/@jscad/modeling/src/utils/padArrayToLength.js"(g,A){var I=(e,t,B)=>{for(e=e.slice();e.length<B;)e.push(t);return e};A.exports=I}}),M9t=fg({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(g,A){var I=TC(),e=k9t(),t=$XA(),{translate:B}=A5(),o=E=>{if(!Array.isArray(E.modes)||E.modes.length>3)throw new Error("align(): modes must be an array of length <= 3");if(E.modes=e(E.modes,"none",3),E.modes.filter(n=>["center","max","min","none"].includes(n)).length!==3)throw new Error('align(): all modes must be one of "center", "max" or "min"');if(!Array.isArray(E.relativeTo)||E.relativeTo.length>3)throw new Error("align(): relativeTo must be an array of length <= 3");if(E.relativeTo=e(E.relativeTo,0,3),E.relativeTo.filter(n=>Number.isFinite(n)||n==null).length!==3)throw new Error("align(): all relativeTo values must be a number, or null.");if(typeof E.grouped!="boolean")throw new Error("align(): grouped must be a boolean value.");return E},C=(E,n,s)=>{for(let r=0;r<3;r++)E[r]==null&&(n[r]==="center"?E[r]=(s[0][r]+s[1][r])/2:n[r]==="max"?E[r]=s[1][r]:n[r]==="min"&&(E[r]=s[0][r]));return E},Q=(E,n,s)=>{const r=t(E),a=[0,0,0];for(let c=0;c<3;c++)n[c]==="center"?a[c]=s[c]-(r[0][c]+r[1][c])/2:n[c]==="max"?a[c]=s[c]-r[1][c]:n[c]==="min"&&(a[c]=s[c]-r[0][c]);return B(a,E)},i=(E,...n)=>{E=Object.assign({},{modes:["center","center","min"],relativeTo:[0,0,0],grouped:!1},E),E=o(E);let{modes:r,relativeTo:a,grouped:c}=E;if(n=I(n),n.length===0)throw new Error("align(): No geometries were provided to act upon");if(a.filter(h=>h==null).length){const h=t(n);a=C(a,r,h)}return c?n=Q(n,r,a):n=n.map(h=>Q(h,r,a)),n.length===1?n[0]:n};A.exports=i}}),ddA=fg({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(g,A){var I=TC(),e=fQ(),t=yQ(),B=ca(),o=X_(),{translate:C}=A5(),Q=(r,a)=>{const c={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:h,relativeTo:l}=Object.assign({},c,r),D=o(a),d=[0,0,0];return h[0]&&(d[0]=l[0]-(D[0][0]+(D[1][0]-D[0][0])/2)),h[1]&&(d[1]=l[1]-(D[0][1]+(D[1][1]-D[0][1])/2)),h[2]&&(d[2]=l[2]-(D[0][2]+(D[1][2]-D[0][2])/2)),C(d,a)},i=(r,...a)=>{const c={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:h,relativeTo:l}=Object.assign({},c,r);if(a=I(a),a.length===0)throw new Error("wrong number of arguments");if(l.length!==3)throw new Error("relativeTo must be an array of length 3");r={axes:h,relativeTo:l};const D=a.map(d=>B.isA(d)||e.isA(d)||t.isA(d)?Q(r,d):d);return D.length===1?D[0]:D},E=(...r)=>i({axes:[!0,!1,!1]},r),n=(...r)=>i({axes:[!1,!0,!1]},r),s=(...r)=>i({axes:[!1,!1,!0]},r);A.exports={center:i,centerX:E,centerY:n,centerZ:s}}}),ydA=fg({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(g,A){var I=TC(),e=_a(),t=fQ(),B=yQ(),o=ca(),C=(n,...s)=>{if(!Array.isArray(n))throw new Error("factors must be an array");if(s=I(s),s.length===0)throw new Error("wrong number of arguments");for(n=n.slice();n.length<3;)n.push(1);if(n[0]<=0||n[1]<=0||n[2]<=0)throw new Error("factors must be positive");const r=e.fromScaling(e.create(),n),a=s.map(c=>o.isA(c)?o.transform(r,c):t.isA(c)?t.transform(r,c):B.isA(c)?B.transform(r,c):c);return a.length===1?a[0]:a},Q=(n,...s)=>C([n,1,1],s),i=(n,...s)=>C([1,n,1],s),E=(n,...s)=>C([1,1,n],s);A.exports={scale:C,scaleX:Q,scaleY:i,scaleZ:E}}}),S9t=fg({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(g,A){var I=TC(),e=fQ(),t=yQ(),B=ca(),o=(C,...Q)=>{if(Q=I(Q),Q.length===0)throw new Error("wrong number of arguments");const i=Q.map(E=>B.isA(E)?B.transform(C,E):e.isA(E)?e.transform(C,E):t.isA(E)?t.transform(C,E):E);return i.length===1?i[0]:i};A.exports=o}}),I5=fg({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(g,A){A.exports={align:M9t(),center:ddA().center,centerX:ddA().centerX,centerY:ddA().centerY,centerZ:ddA().centerZ,mirror:qgA().mirror,mirrorX:qgA().mirrorX,mirrorY:qgA().mirrorY,mirrorZ:qgA().mirrorZ,rotate:TgA().rotate,rotateX:TgA().rotateX,rotateY:TgA().rotateY,rotateZ:TgA().rotateZ,scale:ydA().scale,scaleX:ydA().scaleX,scaleY:ydA().scaleY,scaleZ:ydA().scaleZ,transform:S9t(),translate:A5().translate,translateX:A5().translateX,translateY:A5().translateY,translateZ:A5().translateZ}}}),wdA=fg({"node_modules/@jscad/modeling/src/index.js"(g,A){A.exports={colors:adA(),curves:G5t(),geometries:WXA(),maths:W5t(),measurements:RdI(),primitives:g5(),text:Fbt(),utils:TdI(),booleans:WgA(),expansions:zdI(),extrusions:VgA(),hulls:D9t(),minkowski:d9t(),modifiers:p9t(),transforms:I5()}}}),AyI={};wR(AyI,{ANGLE_ORDER:()=>a$A,ARRAY_TYPE:()=>Si,EPSILON:()=>ao,RANDOM:()=>J2,equals:()=>x9t,round:()=>Ex,setMatrixArrayType:()=>f9t,toDegree:()=>N9t,toRadian:()=>R9t});function Ex(g){return g>=0?Math.round(g):g%.5===0?Math.floor(g):Math.round(g)}function f9t(g){Si=g}function R9t(g){return g*gyI}function N9t(g){return g*IyI}function x9t(g,A){var I=arguments.length>2&&arguments[2]!==void 0?arguments[2]:ao;return Math.abs(g-A)<=I*Math.max(1,Math.abs(g),Math.abs(A))}var ao,Si,J2,a$A,gyI,IyI,nx=yR({"node_modules/gl-matrix/esm/common.js"(){ao=1e-6,Si=typeof Float32Array<"u"?Float32Array:Array,J2=Math.random,a$A="zyx",gyI=Math.PI/180,IyI=180/Math.PI}}),eyI={};wR(eyI,{LDU:()=>V9t,add:()=>j9t,adjoint:()=>b9t,clone:()=>U9t,copy:()=>J9t,create:()=>F9t,determinant:()=>H9t,equals:()=>X9t,exactEquals:()=>z9t,frob:()=>W9t,fromRotation:()=>T9t,fromScaling:()=>Z9t,fromValues:()=>P9t,identity:()=>K9t,invert:()=>_9t,mul:()=>oyI,multiply:()=>tyI,multiplyScalar:()=>$9t,multiplyScalarAndAdd:()=>AHt,rotate:()=>v9t,scale:()=>q9t,set:()=>L9t,str:()=>O9t,sub:()=>CyI,subtract:()=>ByI,transpose:()=>Y9t});function F9t(){var g=new Si(4);return Si!=Float32Array&&(g[1]=0,g[2]=0),g[0]=1,g[3]=1,g}function U9t(g){var A=new Si(4);return A[0]=g[0],A[1]=g[1],A[2]=g[2],A[3]=g[3],A}function J9t(g,A){return g[0]=A[0],g[1]=A[1],g[2]=A[2],g[3]=A[3],g}function K9t(g){return g[0]=1,g[1]=0,g[2]=0,g[3]=1,g}function P9t(g,A,I,e){var t=new Si(4);return t[0]=g,t[1]=A,t[2]=I,t[3]=e,t}function L9t(g,A,I,e,t){return g[0]=A,g[1]=I,g[2]=e,g[3]=t,g}function Y9t(g,A){if(g===A){var I=A[1];g[1]=A[2],g[2]=I}else g[0]=A[0],g[1]=A[2],g[2]=A[1],g[3]=A[3];return g}function _9t(g,A){var I=A[0],e=A[1],t=A[2],B=A[3],o=I*B-t*e;return o?(o=1/o,g[0]=B*o,g[1]=-e*o,g[2]=-t*o,g[3]=I*o,g):null}function b9t(g,A){var I=A[0];return g[0]=A[3],g[1]=-A[1],g[2]=-A[2],g[3]=I,g}function H9t(g){return g[0]*g[3]-g[2]*g[1]}function tyI(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=I[0],Q=I[1],i=I[2],E=I[3];return g[0]=e*C+B*Q,g[1]=t*C+o*Q,g[2]=e*i+B*E,g[3]=t*i+o*E,g}function v9t(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=Math.sin(I),Q=Math.cos(I);return g[0]=e*Q+B*C,g[1]=t*Q+o*C,g[2]=e*-C+B*Q,g[3]=t*-C+o*Q,g}function q9t(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=I[0],Q=I[1];return g[0]=e*C,g[1]=t*C,g[2]=B*Q,g[3]=o*Q,g}function T9t(g,A){var I=Math.sin(A),e=Math.cos(A);return g[0]=e,g[1]=I,g[2]=-I,g[3]=e,g}function Z9t(g,A){return g[0]=A[0],g[1]=0,g[2]=0,g[3]=A[1],g}function O9t(g){return"mat2("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")"}function W9t(g){return Math.sqrt(g[0]*g[0]+g[1]*g[1]+g[2]*g[2]+g[3]*g[3])}function V9t(g,A,I,e){return g[2]=e[2]/e[0],I[0]=e[0],I[1]=e[1],I[3]=e[3]-g[2]*I[1],[g,A,I]}function j9t(g,A,I){return g[0]=A[0]+I[0],g[1]=A[1]+I[1],g[2]=A[2]+I[2],g[3]=A[3]+I[3],g}function ByI(g,A,I){return g[0]=A[0]-I[0],g[1]=A[1]-I[1],g[2]=A[2]-I[2],g[3]=A[3]-I[3],g}function z9t(g,A){return g[0]===A[0]&&g[1]===A[1]&&g[2]===A[2]&&g[3]===A[3]}function X9t(g,A){var I=g[0],e=g[1],t=g[2],B=g[3],o=A[0],C=A[1],Q=A[2],i=A[3];return Math.abs(I-o)<=ao*Math.max(1,Math.abs(I),Math.abs(o))&&Math.abs(e-C)<=ao*Math.max(1,Math.abs(e),Math.abs(C))&&Math.abs(t-Q)<=ao*Math.max(1,Math.abs(t),Math.abs(Q))&&Math.abs(B-i)<=ao*Math.max(1,Math.abs(B),Math.abs(i))}function $9t(g,A,I){return g[0]=A[0]*I,g[1]=A[1]*I,g[2]=A[2]*I,g[3]=A[3]*I,g}function AHt(g,A,I,e){return g[0]=A[0]+I[0]*e,g[1]=A[1]+I[1]*e,g[2]=A[2]+I[2]*e,g[3]=A[3]+I[3]*e,g}var oyI,CyI,gHt=yR({"node_modules/gl-matrix/esm/mat2.js"(){nx(),oyI=tyI,CyI=ByI}}),QyI={};wR(QyI,{add:()=>DHt,clone:()=>eHt,copy:()=>tHt,create:()=>IHt,determinant:()=>iHt,equals:()=>uHt,exactEquals:()=>wHt,frob:()=>lHt,fromRotation:()=>aHt,fromScaling:()=>rHt,fromTranslation:()=>cHt,fromValues:()=>oHt,identity:()=>BHt,invert:()=>QHt,mul:()=>nyI,multiply:()=>iyI,multiplyScalar:()=>dHt,multiplyScalarAndAdd:()=>yHt,rotate:()=>EHt,scale:()=>nHt,set:()=>CHt,str:()=>hHt,sub:()=>syI,subtract:()=>EyI,translate:()=>sHt});function IHt(){var g=new Si(6);return Si!=Float32Array&&(g[1]=0,g[2]=0,g[4]=0,g[5]=0),g[0]=1,g[3]=1,g}function eHt(g){var A=new Si(6);return A[0]=g[0],A[1]=g[1],A[2]=g[2],A[3]=g[3],A[4]=g[4],A[5]=g[5],A}function tHt(g,A){return g[0]=A[0],g[1]=A[1],g[2]=A[2],g[3]=A[3],g[4]=A[4],g[5]=A[5],g}function BHt(g){return g[0]=1,g[1]=0,g[2]=0,g[3]=1,g[4]=0,g[5]=0,g}function oHt(g,A,I,e,t,B){var o=new Si(6);return o[0]=g,o[1]=A,o[2]=I,o[3]=e,o[4]=t,o[5]=B,o}function CHt(g,A,I,e,t,B,o){return g[0]=A,g[1]=I,g[2]=e,g[3]=t,g[4]=B,g[5]=o,g}function QHt(g,A){var I=A[0],e=A[1],t=A[2],B=A[3],o=A[4],C=A[5],Q=I*B-e*t;return Q?(Q=1/Q,g[0]=B*Q,g[1]=-e*Q,g[2]=-t*Q,g[3]=I*Q,g[4]=(t*C-B*o)*Q,g[5]=(e*o-I*C)*Q,g):null}function iHt(g){return g[0]*g[3]-g[1]*g[2]}function iyI(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=A[4],Q=A[5],i=I[0],E=I[1],n=I[2],s=I[3],r=I[4],a=I[5];return g[0]=e*i+B*E,g[1]=t*i+o*E,g[2]=e*n+B*s,g[3]=t*n+o*s,g[4]=e*r+B*a+C,g[5]=t*r+o*a+Q,g}function EHt(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=A[4],Q=A[5],i=Math.sin(I),E=Math.cos(I);return g[0]=e*E+B*i,g[1]=t*E+o*i,g[2]=e*-i+B*E,g[3]=t*-i+o*E,g[4]=C,g[5]=Q,g}function nHt(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=A[4],Q=A[5],i=I[0],E=I[1];return g[0]=e*i,g[1]=t*i,g[2]=B*E,g[3]=o*E,g[4]=C,g[5]=Q,g}function sHt(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=A[4],Q=A[5],i=I[0],E=I[1];return g[0]=e,g[1]=t,g[2]=B,g[3]=o,g[4]=e*i+B*E+C,g[5]=t*i+o*E+Q,g}function aHt(g,A){var I=Math.sin(A),e=Math.cos(A);return g[0]=e,g[1]=I,g[2]=-I,g[3]=e,g[4]=0,g[5]=0,g}function rHt(g,A){return g[0]=A[0],g[1]=0,g[2]=0,g[3]=A[1],g[4]=0,g[5]=0,g}function cHt(g,A){return g[0]=1,g[1]=0,g[2]=0,g[3]=1,g[4]=A[0],g[5]=A[1],g}function hHt(g){return"mat2d("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+", "+g[4]+", "+g[5]+")"}function lHt(g){return Math.sqrt(g[0]*g[0]+g[1]*g[1]+g[2]*g[2]+g[3]*g[3]+g[4]*g[4]+g[5]*g[5]+1)}function DHt(g,A,I){return g[0]=A[0]+I[0],g[1]=A[1]+I[1],g[2]=A[2]+I[2],g[3]=A[3]+I[3],g[4]=A[4]+I[4],g[5]=A[5]+I[5],g}function EyI(g,A,I){return g[0]=A[0]-I[0],g[1]=A[1]-I[1],g[2]=A[2]-I[2],g[3]=A[3]-I[3],g[4]=A[4]-I[4],g[5]=A[5]-I[5],g}function dHt(g,A,I){return g[0]=A[0]*I,g[1]=A[1]*I,g[2]=A[2]*I,g[3]=A[3]*I,g[4]=A[4]*I,g[5]=A[5]*I,g}function yHt(g,A,I,e){return g[0]=A[0]+I[0]*e,g[1]=A[1]+I[1]*e,g[2]=A[2]+I[2]*e,g[3]=A[3]+I[3]*e,g[4]=A[4]+I[4]*e,g[5]=A[5]+I[5]*e,g}function wHt(g,A){return g[0]===A[0]&&g[1]===A[1]&&g[2]===A[2]&&g[3]===A[3]&&g[4]===A[4]&&g[5]===A[5]}function uHt(g,A){var I=g[0],e=g[1],t=g[2],B=g[3],o=g[4],C=g[5],Q=A[0],i=A[1],E=A[2],n=A[3],s=A[4],r=A[5];return Math.abs(I-Q)<=ao*Math.max(1,Math.abs(I),Math.abs(Q))&&Math.abs(e-i)<=ao*Math.max(1,Math.abs(e),Math.abs(i))&&Math.abs(t-E)<=ao*Math.max(1,Math.abs(t),Math.abs(E))&&Math.abs(B-n)<=ao*Math.max(1,Math.abs(B),Math.abs(n))&&Math.abs(o-s)<=ao*Math.max(1,Math.abs(o),Math.abs(s))&&Math.abs(C-r)<=ao*Math.max(1,Math.abs(C),Math.abs(r))}var nyI,syI,GHt=yR({"node_modules/gl-matrix/esm/mat2d.js"(){nx(),nyI=iyI,syI=EyI}}),ayI={};wR(ayI,{add:()=>ZHt,adjoint:()=>xHt,clone:()=>pHt,copy:()=>kHt,create:()=>ryI,determinant:()=>FHt,equals:()=>jHt,exactEquals:()=>VHt,frob:()=>THt,fromMat2d:()=>_Ht,fromMat4:()=>mHt,fromQuat:()=>bHt,fromRotation:()=>LHt,fromScaling:()=>YHt,fromTranslation:()=>PHt,fromValues:()=>MHt,identity:()=>fHt,invert:()=>NHt,mul:()=>lyI,multiply:()=>cyI,multiplyScalar:()=>OHt,multiplyScalarAndAdd:()=>WHt,normalFromMat4:()=>HHt,projection:()=>vHt,rotate:()=>JHt,scale:()=>KHt,set:()=>SHt,str:()=>qHt,sub:()=>DyI,subtract:()=>hyI,translate:()=>UHt,transpose:()=>RHt});function ryI(){var g=new Si(9);return Si!=Float32Array&&(g[1]=0,g[2]=0,g[3]=0,g[5]=0,g[6]=0,g[7]=0),g[0]=1,g[4]=1,g[8]=1,g}function mHt(g,A){return g[0]=A[0],g[1]=A[1],g[2]=A[2],g[3]=A[4],g[4]=A[5],g[5]=A[6],g[6]=A[8],g[7]=A[9],g[8]=A[10],g}function pHt(g){var A=new Si(9);return A[0]=g[0],A[1]=g[1],A[2]=g[2],A[3]=g[3],A[4]=g[4],A[5]=g[5],A[6]=g[6],A[7]=g[7],A[8]=g[8],A}function kHt(g,A){return g[0]=A[0],g[1]=A[1],g[2]=A[2],g[3]=A[3],g[4]=A[4],g[5]=A[5],g[6]=A[6],g[7]=A[7],g[8]=A[8],g}function MHt(g,A,I,e,t,B,o,C,Q){var i=new Si(9);return i[0]=g,i[1]=A,i[2]=I,i[3]=e,i[4]=t,i[5]=B,i[6]=o,i[7]=C,i[8]=Q,i}function SHt(g,A,I,e,t,B,o,C,Q,i){return g[0]=A,g[1]=I,g[2]=e,g[3]=t,g[4]=B,g[5]=o,g[6]=C,g[7]=Q,g[8]=i,g}function fHt(g){return g[0]=1,g[1]=0,g[2]=0,g[3]=0,g[4]=1,g[5]=0,g[6]=0,g[7]=0,g[8]=1,g}function RHt(g,A){if(g===A){var I=A[1],e=A[2],t=A[5];g[1]=A[3],g[2]=A[6],g[3]=I,g[5]=A[7],g[6]=e,g[7]=t}else g[0]=A[0],g[1]=A[3],g[2]=A[6],g[3]=A[1],g[4]=A[4],g[5]=A[7],g[6]=A[2],g[7]=A[5],g[8]=A[8];return g}function NHt(g,A){var I=A[0],e=A[1],t=A[2],B=A[3],o=A[4],C=A[5],Q=A[6],i=A[7],E=A[8],n=E*o-C*i,s=-E*B+C*Q,r=i*B-o*Q,a=I*n+e*s+t*r;return a?(a=1/a,g[0]=n*a,g[1]=(-E*e+t*i)*a,g[2]=(C*e-t*o)*a,g[3]=s*a,g[4]=(E*I-t*Q)*a,g[5]=(-C*I+t*B)*a,g[6]=r*a,g[7]=(-i*I+e*Q)*a,g[8]=(o*I-e*B)*a,g):null}function xHt(g,A){var I=A[0],e=A[1],t=A[2],B=A[3],o=A[4],C=A[5],Q=A[6],i=A[7],E=A[8];return g[0]=o*E-C*i,g[1]=t*i-e*E,g[2]=e*C-t*o,g[3]=C*Q-B*E,g[4]=I*E-t*Q,g[5]=t*B-I*C,g[6]=B*i-o*Q,g[7]=e*Q-I*i,g[8]=I*o-e*B,g}function FHt(g){var A=g[0],I=g[1],e=g[2],t=g[3],B=g[4],o=g[5],C=g[6],Q=g[7],i=g[8];return A*(i*B-o*Q)+I*(-i*t+o*C)+e*(Q*t-B*C)}function cyI(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=A[4],Q=A[5],i=A[6],E=A[7],n=A[8],s=I[0],r=I[1],a=I[2],c=I[3],h=I[4],l=I[5],D=I[6],d=I[7],y=I[8];return g[0]=s*e+r*o+a*i,g[1]=s*t+r*C+a*E,g[2]=s*B+r*Q+a*n,g[3]=c*e+h*o+l*i,g[4]=c*t+h*C+l*E,g[5]=c*B+h*Q+l*n,g[6]=D*e+d*o+y*i,g[7]=D*t+d*C+y*E,g[8]=D*B+d*Q+y*n,g}function UHt(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=A[4],Q=A[5],i=A[6],E=A[7],n=A[8],s=I[0],r=I[1];return g[0]=e,g[1]=t,g[2]=B,g[3]=o,g[4]=C,g[5]=Q,g[6]=s*e+r*o+i,g[7]=s*t+r*C+E,g[8]=s*B+r*Q+n,g}function JHt(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=A[4],Q=A[5],i=A[6],E=A[7],n=A[8],s=Math.sin(I),r=Math.cos(I);return g[0]=r*e+s*o,g[1]=r*t+s*C,g[2]=r*B+s*Q,g[3]=r*o-s*e,g[4]=r*C-s*t,g[5]=r*Q-s*B,g[6]=i,g[7]=E,g[8]=n,g}function KHt(g,A,I){var e=I[0],t=I[1];return g[0]=e*A[0],g[1]=e*A[1],g[2]=e*A[2],g[3]=t*A[3],g[4]=t*A[4],g[5]=t*A[5],g[6]=A[6],g[7]=A[7],g[8]=A[8],g}function PHt(g,A){return g[0]=1,g[1]=0,g[2]=0,g[3]=0,g[4]=1,g[5]=0,g[6]=A[0],g[7]=A[1],g[8]=1,g}function LHt(g,A){var I=Math.sin(A),e=Math.cos(A);return g[0]=e,g[1]=I,g[2]=0,g[3]=-I,g[4]=e,g[5]=0,g[6]=0,g[7]=0,g[8]=1,g}function YHt(g,A){return g[0]=A[0],g[1]=0,g[2]=0,g[3]=0,g[4]=A[1],g[5]=0,g[6]=0,g[7]=0,g[8]=1,g}function _Ht(g,A){return g[0]=A[0],g[1]=A[1],g[2]=0,g[3]=A[2],g[4]=A[3],g[5]=0,g[6]=A[4],g[7]=A[5],g[8]=1,g}function bHt(g,A){var I=A[0],e=A[1],t=A[2],B=A[3],o=I+I,C=e+e,Q=t+t,i=I*o,E=e*o,n=e*C,s=t*o,r=t*C,a=t*Q,c=B*o,h=B*C,l=B*Q;return g[0]=1-n-a,g[3]=E-l,g[6]=s+h,g[1]=E+l,g[4]=1-i-a,g[7]=r-c,g[2]=s-h,g[5]=r+c,g[8]=1-i-n,g}function HHt(g,A){var I=A[0],e=A[1],t=A[2],B=A[3],o=A[4],C=A[5],Q=A[6],i=A[7],E=A[8],n=A[9],s=A[10],r=A[11],a=A[12],c=A[13],h=A[14],l=A[15],D=I*C-e*o,d=I*Q-t*o,y=I*i-B*o,w=e*Q-t*C,u=e*i-B*C,G=t*i-B*Q,m=E*c-n*a,p=E*h-s*a,k=E*l-r*a,S=n*h-s*c,R=n*l-r*c,F=s*l-r*h,N=D*F-d*R+y*S+w*k-u*p+G*m;return N?(N=1/N,g[0]=(C*F-Q*R+i*S)*N,g[1]=(Q*k-o*F-i*p)*N,g[2]=(o*R-C*k+i*m)*N,g[3]=(t*R-e*F-B*S)*N,g[4]=(I*F-t*k+B*p)*N,g[5]=(e*k-I*R-B*m)*N,g[6]=(c*G-h*u+l*w)*N,g[7]=(h*y-a*G-l*d)*N,g[8]=(a*u-c*y+l*D)*N,g):null}function vHt(g,A,I){return g[0]=2/A,g[1]=0,g[2]=0,g[3]=0,g[4]=-2/I,g[5]=0,g[6]=-1,g[7]=1,g[8]=1,g}function qHt(g){return"mat3("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+", "+g[4]+", "+g[5]+", "+g[6]+", "+g[7]+", "+g[8]+")"}function THt(g){return Math.sqrt(g[0]*g[0]+g[1]*g[1]+g[2]*g[2]+g[3]*g[3]+g[4]*g[4]+g[5]*g[5]+g[6]*g[6]+g[7]*g[7]+g[8]*g[8])}function ZHt(g,A,I){return g[0]=A[0]+I[0],g[1]=A[1]+I[1],g[2]=A[2]+I[2],g[3]=A[3]+I[3],g[4]=A[4]+I[4],g[5]=A[5]+I[5],g[6]=A[6]+I[6],g[7]=A[7]+I[7],g[8]=A[8]+I[8],g}function hyI(g,A,I){return g[0]=A[0]-I[0],g[1]=A[1]-I[1],g[2]=A[2]-I[2],g[3]=A[3]-I[3],g[4]=A[4]-I[4],g[5]=A[5]-I[5],g[6]=A[6]-I[6],g[7]=A[7]-I[7],g[8]=A[8]-I[8],g}function OHt(g,A,I){return g[0]=A[0]*I,g[1]=A[1]*I,g[2]=A[2]*I,g[3]=A[3]*I,g[4]=A[4]*I,g[5]=A[5]*I,g[6]=A[6]*I,g[7]=A[7]*I,g[8]=A[8]*I,g}function WHt(g,A,I,e){return g[0]=A[0]+I[0]*e,g[1]=A[1]+I[1]*e,g[2]=A[2]+I[2]*e,g[3]=A[3]+I[3]*e,g[4]=A[4]+I[4]*e,g[5]=A[5]+I[5]*e,g[6]=A[6]+I[6]*e,g[7]=A[7]+I[7]*e,g[8]=A[8]+I[8]*e,g}function VHt(g,A){return g[0]===A[0]&&g[1]===A[1]&&g[2]===A[2]&&g[3]===A[3]&&g[4]===A[4]&&g[5]===A[5]&&g[6]===A[6]&&g[7]===A[7]&&g[8]===A[8]}function jHt(g,A){var I=g[0],e=g[1],t=g[2],B=g[3],o=g[4],C=g[5],Q=g[6],i=g[7],E=g[8],n=A[0],s=A[1],r=A[2],a=A[3],c=A[4],h=A[5],l=A[6],D=A[7],d=A[8];return Math.abs(I-n)<=ao*Math.max(1,Math.abs(I),Math.abs(n))&&Math.abs(e-s)<=ao*Math.max(1,Math.abs(e),Math.abs(s))&&Math.abs(t-r)<=ao*Math.max(1,Math.abs(t),Math.abs(r))&&Math.abs(B-a)<=ao*Math.max(1,Math.abs(B),Math.abs(a))&&Math.abs(o-c)<=ao*Math.max(1,Math.abs(o),Math.abs(c))&&Math.abs(C-h)<=ao*Math.max(1,Math.abs(C),Math.abs(h))&&Math.abs(Q-l)<=ao*Math.max(1,Math.abs(Q),Math.abs(l))&&Math.abs(i-D)<=ao*Math.max(1,Math.abs(i),Math.abs(D))&&Math.abs(E-d)<=ao*Math.max(1,Math.abs(E),Math.abs(d))}var lyI,DyI,dyI=yR({"node_modules/gl-matrix/esm/mat3.js"(){nx(),lyI=cyI,DyI=hyI}}),yyI={};wR(yyI,{add:()=>N6t,adjoint:()=>t6t,clone:()=>XHt,copy:()=>$Ht,create:()=>zHt,decompose:()=>d6t,determinant:()=>B6t,equals:()=>J6t,exactEquals:()=>U6t,frob:()=>R6t,fromQuat:()=>u6t,fromQuat2:()=>D6t,fromRotation:()=>r6t,fromRotationTranslation:()=>GyI,fromRotationTranslationScale:()=>y6t,fromRotationTranslationScaleOrigin:()=>w6t,fromScaling:()=>a6t,fromTranslation:()=>s6t,fromValues:()=>A6t,fromXRotation:()=>c6t,fromYRotation:()=>h6t,fromZRotation:()=>l6t,frustum:()=>G6t,getRotation:()=>kyI,getScaling:()=>pyI,getTranslation:()=>myI,identity:()=>wyI,invert:()=>e6t,lookAt:()=>M6t,mul:()=>xyI,multiply:()=>uyI,multiplyScalar:()=>x6t,multiplyScalarAndAdd:()=>F6t,ortho:()=>NyI,orthoNO:()=>SyI,orthoZO:()=>k6t,perspective:()=>RyI,perspectiveFromFieldOfView:()=>p6t,perspectiveNO:()=>MyI,perspectiveZO:()=>m6t,rotate:()=>Q6t,rotateX:()=>i6t,rotateY:()=>E6t,rotateZ:()=>n6t,scale:()=>C6t,set:()=>g6t,str:()=>f6t,sub:()=>FyI,subtract:()=>fyI,targetTo:()=>S6t,translate:()=>o6t,transpose:()=>I6t});function zHt(){var g=new Si(16);return Si!=Float32Array&&(g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[6]=0,g[7]=0,g[8]=0,g[9]=0,g[11]=0,g[12]=0,g[13]=0,g[14]=0),g[0]=1,g[5]=1,g[10]=1,g[15]=1,g}function XHt(g){var A=new Si(16);return A[0]=g[0],A[1]=g[1],A[2]=g[2],A[3]=g[3],A[4]=g[4],A[5]=g[5],A[6]=g[6],A[7]=g[7],A[8]=g[8],A[9]=g[9],A[10]=g[10],A[11]=g[11],A[12]=g[12],A[13]=g[13],A[14]=g[14],A[15]=g[15],A}function $Ht(g,A){return g[0]=A[0],g[1]=A[1],g[2]=A[2],g[3]=A[3],g[4]=A[4],g[5]=A[5],g[6]=A[6],g[7]=A[7],g[8]=A[8],g[9]=A[9],g[10]=A[10],g[11]=A[11],g[12]=A[12],g[13]=A[13],g[14]=A[14],g[15]=A[15],g}function A6t(g,A,I,e,t,B,o,C,Q,i,E,n,s,r,a,c){var h=new Si(16);return h[0]=g,h[1]=A,h[2]=I,h[3]=e,h[4]=t,h[5]=B,h[6]=o,h[7]=C,h[8]=Q,h[9]=i,h[10]=E,h[11]=n,h[12]=s,h[13]=r,h[14]=a,h[15]=c,h}function g6t(g,A,I,e,t,B,o,C,Q,i,E,n,s,r,a,c,h){return g[0]=A,g[1]=I,g[2]=e,g[3]=t,g[4]=B,g[5]=o,g[6]=C,g[7]=Q,g[8]=i,g[9]=E,g[10]=n,g[11]=s,g[12]=r,g[13]=a,g[14]=c,g[15]=h,g}function wyI(g){return g[0]=1,g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[5]=1,g[6]=0,g[7]=0,g[8]=0,g[9]=0,g[10]=1,g[11]=0,g[12]=0,g[13]=0,g[14]=0,g[15]=1,g}function I6t(g,A){if(g===A){var I=A[1],e=A[2],t=A[3],B=A[6],o=A[7],C=A[11];g[1]=A[4],g[2]=A[8],g[3]=A[12],g[4]=I,g[6]=A[9],g[7]=A[13],g[8]=e,g[9]=B,g[11]=A[14],g[12]=t,g[13]=o,g[14]=C}else g[0]=A[0],g[1]=A[4],g[2]=A[8],g[3]=A[12],g[4]=A[1],g[5]=A[5],g[6]=A[9],g[7]=A[13],g[8]=A[2],g[9]=A[6],g[10]=A[10],g[11]=A[14],g[12]=A[3],g[13]=A[7],g[14]=A[11],g[15]=A[15];return g}function e6t(g,A){var I=A[0],e=A[1],t=A[2],B=A[3],o=A[4],C=A[5],Q=A[6],i=A[7],E=A[8],n=A[9],s=A[10],r=A[11],a=A[12],c=A[13],h=A[14],l=A[15],D=I*C-e*o,d=I*Q-t*o,y=I*i-B*o,w=e*Q-t*C,u=e*i-B*C,G=t*i-B*Q,m=E*c-n*a,p=E*h-s*a,k=E*l-r*a,S=n*h-s*c,R=n*l-r*c,F=s*l-r*h,N=D*F-d*R+y*S+w*k-u*p+G*m;return N?(N=1/N,g[0]=(C*F-Q*R+i*S)*N,g[1]=(t*R-e*F-B*S)*N,g[2]=(c*G-h*u+l*w)*N,g[3]=(s*u-n*G-r*w)*N,g[4]=(Q*k-o*F-i*p)*N,g[5]=(I*F-t*k+B*p)*N,g[6]=(h*y-a*G-l*d)*N,g[7]=(E*G-s*y+r*d)*N,g[8]=(o*R-C*k+i*m)*N,g[9]=(e*k-I*R-B*m)*N,g[10]=(a*u-c*y+l*D)*N,g[11]=(n*y-E*u-r*D)*N,g[12]=(C*p-o*S-Q*m)*N,g[13]=(I*S-e*p+t*m)*N,g[14]=(c*d-a*w-h*D)*N,g[15]=(E*w-n*d+s*D)*N,g):null}function t6t(g,A){var I=A[0],e=A[1],t=A[2],B=A[3],o=A[4],C=A[5],Q=A[6],i=A[7],E=A[8],n=A[9],s=A[10],r=A[11],a=A[12],c=A[13],h=A[14],l=A[15],D=I*C-e*o,d=I*Q-t*o,y=I*i-B*o,w=e*Q-t*C,u=e*i-B*C,G=t*i-B*Q,m=E*c-n*a,p=E*h-s*a,k=E*l-r*a,S=n*h-s*c,R=n*l-r*c,F=s*l-r*h;return g[0]=C*F-Q*R+i*S,g[1]=t*R-e*F-B*S,g[2]=c*G-h*u+l*w,g[3]=s*u-n*G-r*w,g[4]=Q*k-o*F-i*p,g[5]=I*F-t*k+B*p,g[6]=h*y-a*G-l*d,g[7]=E*G-s*y+r*d,g[8]=o*R-C*k+i*m,g[9]=e*k-I*R-B*m,g[10]=a*u-c*y+l*D,g[11]=n*y-E*u-r*D,g[12]=C*p-o*S-Q*m,g[13]=I*S-e*p+t*m,g[14]=c*d-a*w-h*D,g[15]=E*w-n*d+s*D,g}function B6t(g){var A=g[0],I=g[1],e=g[2],t=g[3],B=g[4],o=g[5],C=g[6],Q=g[7],i=g[8],E=g[9],n=g[10],s=g[11],r=g[12],a=g[13],c=g[14],h=g[15],l=A*o-I*B,D=A*C-e*B,d=I*C-e*o,y=i*a-E*r,w=i*c-n*r,u=E*c-n*a,G=A*u-I*w+e*y,m=B*u-o*w+C*y,p=i*d-E*D+n*l,k=r*d-a*D+c*l;return Q*G-t*m+h*p-s*k}function uyI(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=A[4],Q=A[5],i=A[6],E=A[7],n=A[8],s=A[9],r=A[10],a=A[11],c=A[12],h=A[13],l=A[14],D=A[15],d=I[0],y=I[1],w=I[2],u=I[3];return g[0]=d*e+y*C+w*n+u*c,g[1]=d*t+y*Q+w*s+u*h,g[2]=d*B+y*i+w*r+u*l,g[3]=d*o+y*E+w*a+u*D,d=I[4],y=I[5],w=I[6],u=I[7],g[4]=d*e+y*C+w*n+u*c,g[5]=d*t+y*Q+w*s+u*h,g[6]=d*B+y*i+w*r+u*l,g[7]=d*o+y*E+w*a+u*D,d=I[8],y=I[9],w=I[10],u=I[11],g[8]=d*e+y*C+w*n+u*c,g[9]=d*t+y*Q+w*s+u*h,g[10]=d*B+y*i+w*r+u*l,g[11]=d*o+y*E+w*a+u*D,d=I[12],y=I[13],w=I[14],u=I[15],g[12]=d*e+y*C+w*n+u*c,g[13]=d*t+y*Q+w*s+u*h,g[14]=d*B+y*i+w*r+u*l,g[15]=d*o+y*E+w*a+u*D,g}function o6t(g,A,I){var e=I[0],t=I[1],B=I[2],o,C,Q,i,E,n,s,r,a,c,h,l;return A===g?(g[12]=A[0]*e+A[4]*t+A[8]*B+A[12],g[13]=A[1]*e+A[5]*t+A[9]*B+A[13],g[14]=A[2]*e+A[6]*t+A[10]*B+A[14],g[15]=A[3]*e+A[7]*t+A[11]*B+A[15]):(o=A[0],C=A[1],Q=A[2],i=A[3],E=A[4],n=A[5],s=A[6],r=A[7],a=A[8],c=A[9],h=A[10],l=A[11],g[0]=o,g[1]=C,g[2]=Q,g[3]=i,g[4]=E,g[5]=n,g[6]=s,g[7]=r,g[8]=a,g[9]=c,g[10]=h,g[11]=l,g[12]=o*e+E*t+a*B+A[12],g[13]=C*e+n*t+c*B+A[13],g[14]=Q*e+s*t+h*B+A[14],g[15]=i*e+r*t+l*B+A[15]),g}function C6t(g,A,I){var e=I[0],t=I[1],B=I[2];return g[0]=A[0]*e,g[1]=A[1]*e,g[2]=A[2]*e,g[3]=A[3]*e,g[4]=A[4]*t,g[5]=A[5]*t,g[6]=A[6]*t,g[7]=A[7]*t,g[8]=A[8]*B,g[9]=A[9]*B,g[10]=A[10]*B,g[11]=A[11]*B,g[12]=A[12],g[13]=A[13],g[14]=A[14],g[15]=A[15],g}function Q6t(g,A,I,e){var t=e[0],B=e[1],o=e[2],C=Math.sqrt(t*t+B*B+o*o),Q,i,E,n,s,r,a,c,h,l,D,d,y,w,u,G,m,p,k,S,R,F,N,U;return C<ao?null:(C=1/C,t*=C,B*=C,o*=C,Q=Math.sin(I),i=Math.cos(I),E=1-i,n=A[0],s=A[1],r=A[2],a=A[3],c=A[4],h=A[5],l=A[6],D=A[7],d=A[8],y=A[9],w=A[10],u=A[11],G=t*t*E+i,m=B*t*E+o*Q,p=o*t*E-B*Q,k=t*B*E-o*Q,S=B*B*E+i,R=o*B*E+t*Q,F=t*o*E+B*Q,N=B*o*E-t*Q,U=o*o*E+i,g[0]=n*G+c*m+d*p,g[1]=s*G+h*m+y*p,g[2]=r*G+l*m+w*p,g[3]=a*G+D*m+u*p,g[4]=n*k+c*S+d*R,g[5]=s*k+h*S+y*R,g[6]=r*k+l*S+w*R,g[7]=a*k+D*S+u*R,g[8]=n*F+c*N+d*U,g[9]=s*F+h*N+y*U,g[10]=r*F+l*N+w*U,g[11]=a*F+D*N+u*U,A!==g&&(g[12]=A[12],g[13]=A[13],g[14]=A[14],g[15]=A[15]),g)}function i6t(g,A,I){var e=Math.sin(I),t=Math.cos(I),B=A[4],o=A[5],C=A[6],Q=A[7],i=A[8],E=A[9],n=A[10],s=A[11];return A!==g&&(g[0]=A[0],g[1]=A[1],g[2]=A[2],g[3]=A[3],g[12]=A[12],g[13]=A[13],g[14]=A[14],g[15]=A[15]),g[4]=B*t+i*e,g[5]=o*t+E*e,g[6]=C*t+n*e,g[7]=Q*t+s*e,g[8]=i*t-B*e,g[9]=E*t-o*e,g[10]=n*t-C*e,g[11]=s*t-Q*e,g}function E6t(g,A,I){var e=Math.sin(I),t=Math.cos(I),B=A[0],o=A[1],C=A[2],Q=A[3],i=A[8],E=A[9],n=A[10],s=A[11];return A!==g&&(g[4]=A[4],g[5]=A[5],g[6]=A[6],g[7]=A[7],g[12]=A[12],g[13]=A[13],g[14]=A[14],g[15]=A[15]),g[0]=B*t-i*e,g[1]=o*t-E*e,g[2]=C*t-n*e,g[3]=Q*t-s*e,g[8]=B*e+i*t,g[9]=o*e+E*t,g[10]=C*e+n*t,g[11]=Q*e+s*t,g}function n6t(g,A,I){var e=Math.sin(I),t=Math.cos(I),B=A[0],o=A[1],C=A[2],Q=A[3],i=A[4],E=A[5],n=A[6],s=A[7];return A!==g&&(g[8]=A[8],g[9]=A[9],g[10]=A[10],g[11]=A[11],g[12]=A[12],g[13]=A[13],g[14]=A[14],g[15]=A[15]),g[0]=B*t+i*e,g[1]=o*t+E*e,g[2]=C*t+n*e,g[3]=Q*t+s*e,g[4]=i*t-B*e,g[5]=E*t-o*e,g[6]=n*t-C*e,g[7]=s*t-Q*e,g}function s6t(g,A){return g[0]=1,g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[5]=1,g[6]=0,g[7]=0,g[8]=0,g[9]=0,g[10]=1,g[11]=0,g[12]=A[0],g[13]=A[1],g[14]=A[2],g[15]=1,g}function a6t(g,A){return g[0]=A[0],g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[5]=A[1],g[6]=0,g[7]=0,g[8]=0,g[9]=0,g[10]=A[2],g[11]=0,g[12]=0,g[13]=0,g[14]=0,g[15]=1,g}function r6t(g,A,I){var e=I[0],t=I[1],B=I[2],o=Math.sqrt(e*e+t*t+B*B),C,Q,i;return o<ao?null:(o=1/o,e*=o,t*=o,B*=o,C=Math.sin(A),Q=Math.cos(A),i=1-Q,g[0]=e*e*i+Q,g[1]=t*e*i+B*C,g[2]=B*e*i-t*C,g[3]=0,g[4]=e*t*i-B*C,g[5]=t*t*i+Q,g[6]=B*t*i+e*C,g[7]=0,g[8]=e*B*i+t*C,g[9]=t*B*i-e*C,g[10]=B*B*i+Q,g[11]=0,g[12]=0,g[13]=0,g[14]=0,g[15]=1,g)}function c6t(g,A){var I=Math.sin(A),e=Math.cos(A);return g[0]=1,g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[5]=e,g[6]=I,g[7]=0,g[8]=0,g[9]=-I,g[10]=e,g[11]=0,g[12]=0,g[13]=0,g[14]=0,g[15]=1,g}function h6t(g,A){var I=Math.sin(A),e=Math.cos(A);return g[0]=e,g[1]=0,g[2]=-I,g[3]=0,g[4]=0,g[5]=1,g[6]=0,g[7]=0,g[8]=I,g[9]=0,g[10]=e,g[11]=0,g[12]=0,g[13]=0,g[14]=0,g[15]=1,g}function l6t(g,A){var I=Math.sin(A),e=Math.cos(A);return g[0]=e,g[1]=I,g[2]=0,g[3]=0,g[4]=-I,g[5]=e,g[6]=0,g[7]=0,g[8]=0,g[9]=0,g[10]=1,g[11]=0,g[12]=0,g[13]=0,g[14]=0,g[15]=1,g}function GyI(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=e+e,Q=t+t,i=B+B,E=e*C,n=e*Q,s=e*i,r=t*Q,a=t*i,c=B*i,h=o*C,l=o*Q,D=o*i;return g[0]=1-(r+c),g[1]=n+D,g[2]=s-l,g[3]=0,g[4]=n-D,g[5]=1-(E+c),g[6]=a+h,g[7]=0,g[8]=s+l,g[9]=a-h,g[10]=1-(E+r),g[11]=0,g[12]=I[0],g[13]=I[1],g[14]=I[2],g[15]=1,g}function D6t(g,A){var I=new Si(3),e=-A[0],t=-A[1],B=-A[2],o=A[3],C=A[4],Q=A[5],i=A[6],E=A[7],n=e*e+t*t+B*B+o*o;return n>0?(I[0]=(C*o+E*e+Q*B-i*t)*2/n,I[1]=(Q*o+E*t+i*e-C*B)*2/n,I[2]=(i*o+E*B+C*t-Q*e)*2/n):(I[0]=(C*o+E*e+Q*B-i*t)*2,I[1]=(Q*o+E*t+i*e-C*B)*2,I[2]=(i*o+E*B+C*t-Q*e)*2),GyI(g,A,I),g}function myI(g,A){return g[0]=A[12],g[1]=A[13],g[2]=A[14],g}function pyI(g,A){var I=A[0],e=A[1],t=A[2],B=A[4],o=A[5],C=A[6],Q=A[8],i=A[9],E=A[10];return g[0]=Math.sqrt(I*I+e*e+t*t),g[1]=Math.sqrt(B*B+o*o+C*C),g[2]=Math.sqrt(Q*Q+i*i+E*E),g}function kyI(g,A){var I=new Si(3);pyI(I,A);var e=1/I[0],t=1/I[1],B=1/I[2],o=A[0]*e,C=A[1]*t,Q=A[2]*B,i=A[4]*e,E=A[5]*t,n=A[6]*B,s=A[8]*e,r=A[9]*t,a=A[10]*B,c=o+E+a,h=0;return c>0?(h=Math.sqrt(c+1)*2,g[3]=.25*h,g[0]=(n-r)/h,g[1]=(s-Q)/h,g[2]=(C-i)/h):o>E&&o>a?(h=Math.sqrt(1+o-E-a)*2,g[3]=(n-r)/h,g[0]=.25*h,g[1]=(C+i)/h,g[2]=(s+Q)/h):E>a?(h=Math.sqrt(1+E-o-a)*2,g[3]=(s-Q)/h,g[0]=(C+i)/h,g[1]=.25*h,g[2]=(n+r)/h):(h=Math.sqrt(1+a-o-E)*2,g[3]=(C-i)/h,g[0]=(s+Q)/h,g[1]=(n+r)/h,g[2]=.25*h),g}function d6t(g,A,I,e){A[0]=e[12],A[1]=e[13],A[2]=e[14];var t=e[0],B=e[1],o=e[2],C=e[4],Q=e[5],i=e[6],E=e[8],n=e[9],s=e[10];I[0]=Math.sqrt(t*t+B*B+o*o),I[1]=Math.sqrt(C*C+Q*Q+i*i),I[2]=Math.sqrt(E*E+n*n+s*s);var r=1/I[0],a=1/I[1],c=1/I[2],h=t*r,l=B*a,D=o*c,d=C*r,y=Q*a,w=i*c,u=E*r,G=n*a,m=s*c,p=h+y+m,k=0;return p>0?(k=Math.sqrt(p+1)*2,g[3]=.25*k,g[0]=(w-G)/k,g[1]=(u-D)/k,g[2]=(l-d)/k):h>y&&h>m?(k=Math.sqrt(1+h-y-m)*2,g[3]=(w-G)/k,g[0]=.25*k,g[1]=(l+d)/k,g[2]=(u+D)/k):y>m?(k=Math.sqrt(1+y-h-m)*2,g[3]=(u-D)/k,g[0]=(l+d)/k,g[1]=.25*k,g[2]=(w+G)/k):(k=Math.sqrt(1+m-h-y)*2,g[3]=(l-d)/k,g[0]=(u+D)/k,g[1]=(w+G)/k,g[2]=.25*k),g}function y6t(g,A,I,e){var t=A[0],B=A[1],o=A[2],C=A[3],Q=t+t,i=B+B,E=o+o,n=t*Q,s=t*i,r=t*E,a=B*i,c=B*E,h=o*E,l=C*Q,D=C*i,d=C*E,y=e[0],w=e[1],u=e[2];return g[0]=(1-(a+h))*y,g[1]=(s+d)*y,g[2]=(r-D)*y,g[3]=0,g[4]=(s-d)*w,g[5]=(1-(n+h))*w,g[6]=(c+l)*w,g[7]=0,g[8]=(r+D)*u,g[9]=(c-l)*u,g[10]=(1-(n+a))*u,g[11]=0,g[12]=I[0],g[13]=I[1],g[14]=I[2],g[15]=1,g}function w6t(g,A,I,e,t){var B=A[0],o=A[1],C=A[2],Q=A[3],i=B+B,E=o+o,n=C+C,s=B*i,r=B*E,a=B*n,c=o*E,h=o*n,l=C*n,D=Q*i,d=Q*E,y=Q*n,w=e[0],u=e[1],G=e[2],m=t[0],p=t[1],k=t[2],S=(1-(c+l))*w,R=(r+y)*w,F=(a-d)*w,N=(r-y)*u,U=(1-(s+l))*u,P=(h+D)*u,b=(a+d)*G,H=(h-D)*G,q=(1-(s+c))*G;return g[0]=S,g[1]=R,g[2]=F,g[3]=0,g[4]=N,g[5]=U,g[6]=P,g[7]=0,g[8]=b,g[9]=H,g[10]=q,g[11]=0,g[12]=I[0]+m-(S*m+N*p+b*k),g[13]=I[1]+p-(R*m+U*p+H*k),g[14]=I[2]+k-(F*m+P*p+q*k),g[15]=1,g}function u6t(g,A){var I=A[0],e=A[1],t=A[2],B=A[3],o=I+I,C=e+e,Q=t+t,i=I*o,E=e*o,n=e*C,s=t*o,r=t*C,a=t*Q,c=B*o,h=B*C,l=B*Q;return g[0]=1-n-a,g[1]=E+l,g[2]=s-h,g[3]=0,g[4]=E-l,g[5]=1-i-a,g[6]=r+c,g[7]=0,g[8]=s+h,g[9]=r-c,g[10]=1-i-n,g[11]=0,g[12]=0,g[13]=0,g[14]=0,g[15]=1,g}function G6t(g,A,I,e,t,B,o){var C=1/(I-A),Q=1/(t-e),i=1/(B-o);return g[0]=B*2*C,g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[5]=B*2*Q,g[6]=0,g[7]=0,g[8]=(I+A)*C,g[9]=(t+e)*Q,g[10]=(o+B)*i,g[11]=-1,g[12]=0,g[13]=0,g[14]=o*B*2*i,g[15]=0,g}function MyI(g,A,I,e,t){var B=1/Math.tan(A/2);if(g[0]=B/I,g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[5]=B,g[6]=0,g[7]=0,g[8]=0,g[9]=0,g[11]=-1,g[12]=0,g[13]=0,g[15]=0,t!=null&&t!==1/0){var o=1/(e-t);g[10]=(t+e)*o,g[14]=2*t*e*o}else g[10]=-1,g[14]=-2*e;return g}function m6t(g,A,I,e,t){var B=1/Math.tan(A/2);if(g[0]=B/I,g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[5]=B,g[6]=0,g[7]=0,g[8]=0,g[9]=0,g[11]=-1,g[12]=0,g[13]=0,g[15]=0,t!=null&&t!==1/0){var o=1/(e-t);g[10]=t*o,g[14]=t*e*o}else g[10]=-1,g[14]=-e;return g}function p6t(g,A,I,e){var t=Math.tan(A.upDegrees*Math.PI/180),B=Math.tan(A.downDegrees*Math.PI/180),o=Math.tan(A.leftDegrees*Math.PI/180),C=Math.tan(A.rightDegrees*Math.PI/180),Q=2/(o+C),i=2/(t+B);return g[0]=Q,g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[5]=i,g[6]=0,g[7]=0,g[8]=-((o-C)*Q*.5),g[9]=(t-B)*i*.5,g[10]=e/(I-e),g[11]=-1,g[12]=0,g[13]=0,g[14]=e*I/(I-e),g[15]=0,g}function SyI(g,A,I,e,t,B,o){var C=1/(A-I),Q=1/(e-t),i=1/(B-o);return g[0]=-2*C,g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[5]=-2*Q,g[6]=0,g[7]=0,g[8]=0,g[9]=0,g[10]=2*i,g[11]=0,g[12]=(A+I)*C,g[13]=(t+e)*Q,g[14]=(o+B)*i,g[15]=1,g}function k6t(g,A,I,e,t,B,o){var C=1/(A-I),Q=1/(e-t),i=1/(B-o);return g[0]=-2*C,g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[5]=-2*Q,g[6]=0,g[7]=0,g[8]=0,g[9]=0,g[10]=i,g[11]=0,g[12]=(A+I)*C,g[13]=(t+e)*Q,g[14]=B*i,g[15]=1,g}function M6t(g,A,I,e){var t,B,o,C,Q,i,E,n,s,r,a=A[0],c=A[1],h=A[2],l=e[0],D=e[1],d=e[2],y=I[0],w=I[1],u=I[2];return Math.abs(a-y)<ao&&Math.abs(c-w)<ao&&Math.abs(h-u)<ao?wyI(g):(E=a-y,n=c-w,s=h-u,r=1/Math.sqrt(E*E+n*n+s*s),E*=r,n*=r,s*=r,t=D*s-d*n,B=d*E-l*s,o=l*n-D*E,r=Math.sqrt(t*t+B*B+o*o),r?(r=1/r,t*=r,B*=r,o*=r):(t=0,B=0,o=0),C=n*o-s*B,Q=s*t-E*o,i=E*B-n*t,r=Math.sqrt(C*C+Q*Q+i*i),r?(r=1/r,C*=r,Q*=r,i*=r):(C=0,Q=0,i=0),g[0]=t,g[1]=C,g[2]=E,g[3]=0,g[4]=B,g[5]=Q,g[6]=n,g[7]=0,g[8]=o,g[9]=i,g[10]=s,g[11]=0,g[12]=-(t*a+B*c+o*h),g[13]=-(C*a+Q*c+i*h),g[14]=-(E*a+n*c+s*h),g[15]=1,g)}function S6t(g,A,I,e){var t=A[0],B=A[1],o=A[2],C=e[0],Q=e[1],i=e[2],E=t-I[0],n=B-I[1],s=o-I[2],r=E*E+n*n+s*s;r>0&&(r=1/Math.sqrt(r),E*=r,n*=r,s*=r);var a=Q*s-i*n,c=i*E-C*s,h=C*n-Q*E;return r=a*a+c*c+h*h,r>0&&(r=1/Math.sqrt(r),a*=r,c*=r,h*=r),g[0]=a,g[1]=c,g[2]=h,g[3]=0,g[4]=n*h-s*c,g[5]=s*a-E*h,g[6]=E*c-n*a,g[7]=0,g[8]=E,g[9]=n,g[10]=s,g[11]=0,g[12]=t,g[13]=B,g[14]=o,g[15]=1,g}function f6t(g){return"mat4("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+", "+g[4]+", "+g[5]+", "+g[6]+", "+g[7]+", "+g[8]+", "+g[9]+", "+g[10]+", "+g[11]+", "+g[12]+", "+g[13]+", "+g[14]+", "+g[15]+")"}function R6t(g){return Math.sqrt(g[0]*g[0]+g[1]*g[1]+g[2]*g[2]+g[3]*g[3]+g[4]*g[4]+g[5]*g[5]+g[6]*g[6]+g[7]*g[7]+g[8]*g[8]+g[9]*g[9]+g[10]*g[10]+g[11]*g[11]+g[12]*g[12]+g[13]*g[13]+g[14]*g[14]+g[15]*g[15])}function N6t(g,A,I){return g[0]=A[0]+I[0],g[1]=A[1]+I[1],g[2]=A[2]+I[2],g[3]=A[3]+I[3],g[4]=A[4]+I[4],g[5]=A[5]+I[5],g[6]=A[6]+I[6],g[7]=A[7]+I[7],g[8]=A[8]+I[8],g[9]=A[9]+I[9],g[10]=A[10]+I[10],g[11]=A[11]+I[11],g[12]=A[12]+I[12],g[13]=A[13]+I[13],g[14]=A[14]+I[14],g[15]=A[15]+I[15],g}function fyI(g,A,I){return g[0]=A[0]-I[0],g[1]=A[1]-I[1],g[2]=A[2]-I[2],g[3]=A[3]-I[3],g[4]=A[4]-I[4],g[5]=A[5]-I[5],g[6]=A[6]-I[6],g[7]=A[7]-I[7],g[8]=A[8]-I[8],g[9]=A[9]-I[9],g[10]=A[10]-I[10],g[11]=A[11]-I[11],g[12]=A[12]-I[12],g[13]=A[13]-I[13],g[14]=A[14]-I[14],g[15]=A[15]-I[15],g}function x6t(g,A,I){return g[0]=A[0]*I,g[1]=A[1]*I,g[2]=A[2]*I,g[3]=A[3]*I,g[4]=A[4]*I,g[5]=A[5]*I,g[6]=A[6]*I,g[7]=A[7]*I,g[8]=A[8]*I,g[9]=A[9]*I,g[10]=A[10]*I,g[11]=A[11]*I,g[12]=A[12]*I,g[13]=A[13]*I,g[14]=A[14]*I,g[15]=A[15]*I,g}function F6t(g,A,I,e){return g[0]=A[0]+I[0]*e,g[1]=A[1]+I[1]*e,g[2]=A[2]+I[2]*e,g[3]=A[3]+I[3]*e,g[4]=A[4]+I[4]*e,g[5]=A[5]+I[5]*e,g[6]=A[6]+I[6]*e,g[7]=A[7]+I[7]*e,g[8]=A[8]+I[8]*e,g[9]=A[9]+I[9]*e,g[10]=A[10]+I[10]*e,g[11]=A[11]+I[11]*e,g[12]=A[12]+I[12]*e,g[13]=A[13]+I[13]*e,g[14]=A[14]+I[14]*e,g[15]=A[15]+I[15]*e,g}function U6t(g,A){return g[0]===A[0]&&g[1]===A[1]&&g[2]===A[2]&&g[3]===A[3]&&g[4]===A[4]&&g[5]===A[5]&&g[6]===A[6]&&g[7]===A[7]&&g[8]===A[8]&&g[9]===A[9]&&g[10]===A[10]&&g[11]===A[11]&&g[12]===A[12]&&g[13]===A[13]&&g[14]===A[14]&&g[15]===A[15]}function J6t(g,A){var I=g[0],e=g[1],t=g[2],B=g[3],o=g[4],C=g[5],Q=g[6],i=g[7],E=g[8],n=g[9],s=g[10],r=g[11],a=g[12],c=g[13],h=g[14],l=g[15],D=A[0],d=A[1],y=A[2],w=A[3],u=A[4],G=A[5],m=A[6],p=A[7],k=A[8],S=A[9],R=A[10],F=A[11],N=A[12],U=A[13],P=A[14],b=A[15];return Math.abs(I-D)<=ao*Math.max(1,Math.abs(I),Math.abs(D))&&Math.abs(e-d)<=ao*Math.max(1,Math.abs(e),Math.abs(d))&&Math.abs(t-y)<=ao*Math.max(1,Math.abs(t),Math.abs(y))&&Math.abs(B-w)<=ao*Math.max(1,Math.abs(B),Math.abs(w))&&Math.abs(o-u)<=ao*Math.max(1,Math.abs(o),Math.abs(u))&&Math.abs(C-G)<=ao*Math.max(1,Math.abs(C),Math.abs(G))&&Math.abs(Q-m)<=ao*Math.max(1,Math.abs(Q),Math.abs(m))&&Math.abs(i-p)<=ao*Math.max(1,Math.abs(i),Math.abs(p))&&Math.abs(E-k)<=ao*Math.max(1,Math.abs(E),Math.abs(k))&&Math.abs(n-S)<=ao*Math.max(1,Math.abs(n),Math.abs(S))&&Math.abs(s-R)<=ao*Math.max(1,Math.abs(s),Math.abs(R))&&Math.abs(r-F)<=ao*Math.max(1,Math.abs(r),Math.abs(F))&&Math.abs(a-N)<=ao*Math.max(1,Math.abs(a),Math.abs(N))&&Math.abs(c-U)<=ao*Math.max(1,Math.abs(c),Math.abs(U))&&Math.abs(h-P)<=ao*Math.max(1,Math.abs(h),Math.abs(P))&&Math.abs(l-b)<=ao*Math.max(1,Math.abs(l),Math.abs(b))}var RyI,NyI,xyI,FyI,UyI=yR({"node_modules/gl-matrix/esm/mat4.js"(){nx(),RyI=MyI,NyI=SyI,xyI=uyI,FyI=fyI}}),JyI={};wR(JyI,{add:()=>Y6t,angle:()=>ovt,bezier:()=>X6t,ceil:()=>_6t,clone:()=>K6t,copy:()=>P6t,create:()=>r$A,cross:()=>GdA,dist:()=>OyI,distance:()=>_yI,div:()=>ZyI,divide:()=>YyI,dot:()=>udA,equals:()=>Evt,exactEquals:()=>ivt,floor:()=>b6t,forEach:()=>jyI,fromValues:()=>c$A,hermite:()=>z6t,inverse:()=>W6t,len:()=>h$A,length:()=>KyI,lerp:()=>V6t,max:()=>v6t,min:()=>H6t,mul:()=>TyI,multiply:()=>LyI,negate:()=>O6t,normalize:()=>vyI,random:()=>$6t,rotateX:()=>evt,rotateY:()=>tvt,rotateZ:()=>Bvt,round:()=>q6t,scale:()=>T6t,scaleAndAdd:()=>Z6t,set:()=>L6t,slerp:()=>j6t,sqrDist:()=>WyI,sqrLen:()=>VyI,squaredDistance:()=>byI,squaredLength:()=>HyI,str:()=>Qvt,sub:()=>qyI,subtract:()=>PyI,transformMat3:()=>gvt,transformMat4:()=>Avt,transformQuat:()=>Ivt,zero:()=>Cvt});function r$A(){var g=new Si(3);return Si!=Float32Array&&(g[0]=0,g[1]=0,g[2]=0),g}function K6t(g){var A=new Si(3);return A[0]=g[0],A[1]=g[1],A[2]=g[2],A}function KyI(g){var A=g[0],I=g[1],e=g[2];return Math.sqrt(A*A+I*I+e*e)}function c$A(g,A,I){var e=new Si(3);return e[0]=g,e[1]=A,e[2]=I,e}function P6t(g,A){return g[0]=A[0],g[1]=A[1],g[2]=A[2],g}function L6t(g,A,I,e){return g[0]=A,g[1]=I,g[2]=e,g}function Y6t(g,A,I){return g[0]=A[0]+I[0],g[1]=A[1]+I[1],g[2]=A[2]+I[2],g}function PyI(g,A,I){return g[0]=A[0]-I[0],g[1]=A[1]-I[1],g[2]=A[2]-I[2],g}function LyI(g,A,I){return g[0]=A[0]*I[0],g[1]=A[1]*I[1],g[2]=A[2]*I[2],g}function YyI(g,A,I){return g[0]=A[0]/I[0],g[1]=A[1]/I[1],g[2]=A[2]/I[2],g}function _6t(g,A){return g[0]=Math.ceil(A[0]),g[1]=Math.ceil(A[1]),g[2]=Math.ceil(A[2]),g}function b6t(g,A){return g[0]=Math.floor(A[0]),g[1]=Math.floor(A[1]),g[2]=Math.floor(A[2]),g}function H6t(g,A,I){return g[0]=Math.min(A[0],I[0]),g[1]=Math.min(A[1],I[1]),g[2]=Math.min(A[2],I[2]),g}function v6t(g,A,I){return g[0]=Math.max(A[0],I[0]),g[1]=Math.max(A[1],I[1]),g[2]=Math.max(A[2],I[2]),g}function q6t(g,A){return g[0]=Ex(A[0]),g[1]=Ex(A[1]),g[2]=Ex(A[2]),g}function T6t(g,A,I){return g[0]=A[0]*I,g[1]=A[1]*I,g[2]=A[2]*I,g}function Z6t(g,A,I,e){return g[0]=A[0]+I[0]*e,g[1]=A[1]+I[1]*e,g[2]=A[2]+I[2]*e,g}function _yI(g,A){var I=A[0]-g[0],e=A[1]-g[1],t=A[2]-g[2];return Math.sqrt(I*I+e*e+t*t)}function byI(g,A){var I=A[0]-g[0],e=A[1]-g[1],t=A[2]-g[2];return I*I+e*e+t*t}function HyI(g){var A=g[0],I=g[1],e=g[2];return A*A+I*I+e*e}function O6t(g,A){return g[0]=-A[0],g[1]=-A[1],g[2]=-A[2],g}function W6t(g,A){return g[0]=1/A[0],g[1]=1/A[1],g[2]=1/A[2],g}function vyI(g,A){var I=A[0],e=A[1],t=A[2],B=I*I+e*e+t*t;return B>0&&(B=1/Math.sqrt(B)),g[0]=A[0]*B,g[1]=A[1]*B,g[2]=A[2]*B,g}function udA(g,A){return g[0]*A[0]+g[1]*A[1]+g[2]*A[2]}function GdA(g,A,I){var e=A[0],t=A[1],B=A[2],o=I[0],C=I[1],Q=I[2];return g[0]=t*Q-B*C,g[1]=B*o-e*Q,g[2]=e*C-t*o,g}function V6t(g,A,I,e){var t=A[0],B=A[1],o=A[2];return g[0]=t+e*(I[0]-t),g[1]=B+e*(I[1]-B),g[2]=o+e*(I[2]-o),g}function j6t(g,A,I,e){var t=Math.acos(Math.min(Math.max(udA(A,I),-1),1)),B=Math.sin(t),o=Math.sin((1-e)*t)/B,C=Math.sin(e*t)/B;return g[0]=o*A[0]+C*I[0],g[1]=o*A[1]+C*I[1],g[2]=o*A[2]+C*I[2],g}function z6t(g,A,I,e,t,B){var o=B*B,C=o*(2*B-3)+1,Q=o*(B-2)+B,i=o*(B-1),E=o*(3-2*B);return g[0]=A[0]*C+I[0]*Q+e[0]*i+t[0]*E,g[1]=A[1]*C+I[1]*Q+e[1]*i+t[1]*E,g[2]=A[2]*C+I[2]*Q+e[2]*i+t[2]*E,g}function X6t(g,A,I,e,t,B){var o=1-B,C=o*o,Q=B*B,i=C*o,E=3*B*C,n=3*Q*o,s=Q*B;return g[0]=A[0]*i+I[0]*E+e[0]*n+t[0]*s,g[1]=A[1]*i+I[1]*E+e[1]*n+t[1]*s,g[2]=A[2]*i+I[2]*E+e[2]*n+t[2]*s,g}function $6t(g,A){A=A===void 0?1:A;var I=J2()*2*Math.PI,e=J2()*2-1,t=Math.sqrt(1-e*e)*A;return g[0]=Math.cos(I)*t,g[1]=Math.sin(I)*t,g[2]=e*A,g}function Avt(g,A,I){var e=A[0],t=A[1],B=A[2],o=I[3]*e+I[7]*t+I[11]*B+I[15];return o=o||1,g[0]=(I[0]*e+I[4]*t+I[8]*B+I[12])/o,g[1]=(I[1]*e+I[5]*t+I[9]*B+I[13])/o,g[2]=(I[2]*e+I[6]*t+I[10]*B+I[14])/o,g}function gvt(g,A,I){var e=A[0],t=A[1],B=A[2];return g[0]=e*I[0]+t*I[3]+B*I[6],g[1]=e*I[1]+t*I[4]+B*I[7],g[2]=e*I[2]+t*I[5]+B*I[8],g}function Ivt(g,A,I){var e=I[0],t=I[1],B=I[2],o=I[3],C=A[0],Q=A[1],i=A[2],E=t*i-B*Q,n=B*C-e*i,s=e*Q-t*C;return E=E+E,n=n+n,s=s+s,g[0]=C+o*E+t*s-B*n,g[1]=Q+o*n+B*E-e*s,g[2]=i+o*s+e*n-t*E,g}function evt(g,A,I,e){var t=[],B=[];return t[0]=A[0]-I[0],t[1]=A[1]-I[1],t[2]=A[2]-I[2],B[0]=t[0],B[1]=t[1]*Math.cos(e)-t[2]*Math.sin(e),B[2]=t[1]*Math.sin(e)+t[2]*Math.cos(e),g[0]=B[0]+I[0],g[1]=B[1]+I[1],g[2]=B[2]+I[2],g}function tvt(g,A,I,e){var t=[],B=[];return t[0]=A[0]-I[0],t[1]=A[1]-I[1],t[2]=A[2]-I[2],B[0]=t[2]*Math.sin(e)+t[0]*Math.cos(e),B[1]=t[1],B[2]=t[2]*Math.cos(e)-t[0]*Math.sin(e),g[0]=B[0]+I[0],g[1]=B[1]+I[1],g[2]=B[2]+I[2],g}function Bvt(g,A,I,e){var t=[],B=[];return t[0]=A[0]-I[0],t[1]=A[1]-I[1],t[2]=A[2]-I[2],B[0]=t[0]*Math.cos(e)-t[1]*Math.sin(e),B[1]=t[0]*Math.sin(e)+t[1]*Math.cos(e),B[2]=t[2],g[0]=B[0]+I[0],g[1]=B[1]+I[1],g[2]=B[2]+I[2],g}function ovt(g,A){var I=g[0],e=g[1],t=g[2],B=A[0],o=A[1],C=A[2],Q=Math.sqrt((I*I+e*e+t*t)*(B*B+o*o+C*C)),i=Q&&udA(g,A)/Q;return Math.acos(Math.min(Math.max(i,-1),1))}function Cvt(g){return g[0]=0,g[1]=0,g[2]=0,g}function Qvt(g){return"vec3("+g[0]+", "+g[1]+", "+g[2]+")"}function ivt(g,A){return g[0]===A[0]&&g[1]===A[1]&&g[2]===A[2]}function Evt(g,A){var I=g[0],e=g[1],t=g[2],B=A[0],o=A[1],C=A[2];return Math.abs(I-B)<=ao*Math.max(1,Math.abs(I),Math.abs(B))&&Math.abs(e-o)<=ao*Math.max(1,Math.abs(e),Math.abs(o))&&Math.abs(t-C)<=ao*Math.max(1,Math.abs(t),Math.abs(C))}var qyI,TyI,ZyI,OyI,WyI,h$A,VyI,jyI,zyI=yR({"node_modules/gl-matrix/esm/vec3.js"(){nx(),qyI=PyI,TyI=LyI,ZyI=YyI,OyI=_yI,WyI=byI,h$A=KyI,VyI=HyI,jyI=(function(){var g=r$A();return function(A,I,e,t,B,o){var C,Q;for(I||(I=3),e||(e=0),t?Q=Math.min(t*I+e,A.length):Q=A.length,C=e;C<Q;C+=I)g[0]=A[C],g[1]=A[C+1],g[2]=A[C+2],B(g,g,o),A[C]=g[0],A[C+1]=g[1],A[C+2]=g[2];return A}})()}}),XyI={};wR(XyI,{add:()=>twI,ceil:()=>nvt,clone:()=>AwI,copy:()=>IwI,create:()=>$yI,cross:()=>dvt,dist:()=>lwI,distance:()=>iwI,div:()=>hwI,divide:()=>CwI,dot:()=>d$A,equals:()=>pvt,exactEquals:()=>awI,floor:()=>svt,forEach:()=>wwI,fromValues:()=>gwI,inverse:()=>Dvt,len:()=>dwI,length:()=>l$A,lerp:()=>swI,max:()=>rvt,min:()=>avt,mul:()=>cwI,multiply:()=>owI,negate:()=>lvt,normalize:()=>nwI,random:()=>yvt,round:()=>cvt,scale:()=>QwI,scaleAndAdd:()=>hvt,set:()=>ewI,sqrDist:()=>DwI,sqrLen:()=>ywI,squaredDistance:()=>EwI,squaredLength:()=>D$A,str:()=>mvt,sub:()=>rwI,subtract:()=>BwI,transformMat4:()=>wvt,transformQuat:()=>uvt,zero:()=>Gvt});function $yI(){var g=new Si(4);return Si!=Float32Array&&(g[0]=0,g[1]=0,g[2]=0,g[3]=0),g}function AwI(g){var A=new Si(4);return A[0]=g[0],A[1]=g[1],A[2]=g[2],A[3]=g[3],A}function gwI(g,A,I,e){var t=new Si(4);return t[0]=g,t[1]=A,t[2]=I,t[3]=e,t}function IwI(g,A){return g[0]=A[0],g[1]=A[1],g[2]=A[2],g[3]=A[3],g}function ewI(g,A,I,e,t){return g[0]=A,g[1]=I,g[2]=e,g[3]=t,g}function twI(g,A,I){return g[0]=A[0]+I[0],g[1]=A[1]+I[1],g[2]=A[2]+I[2],g[3]=A[3]+I[3],g}function BwI(g,A,I){return g[0]=A[0]-I[0],g[1]=A[1]-I[1],g[2]=A[2]-I[2],g[3]=A[3]-I[3],g}function owI(g,A,I){return g[0]=A[0]*I[0],g[1]=A[1]*I[1],g[2]=A[2]*I[2],g[3]=A[3]*I[3],g}function CwI(g,A,I){return g[0]=A[0]/I[0],g[1]=A[1]/I[1],g[2]=A[2]/I[2],g[3]=A[3]/I[3],g}function nvt(g,A){return g[0]=Math.ceil(A[0]),g[1]=Math.ceil(A[1]),g[2]=Math.ceil(A[2]),g[3]=Math.ceil(A[3]),g}function svt(g,A){return g[0]=Math.floor(A[0]),g[1]=Math.floor(A[1]),g[2]=Math.floor(A[2]),g[3]=Math.floor(A[3]),g}function avt(g,A,I){return g[0]=Math.min(A[0],I[0]),g[1]=Math.min(A[1],I[1]),g[2]=Math.min(A[2],I[2]),g[3]=Math.min(A[3],I[3]),g}function rvt(g,A,I){return g[0]=Math.max(A[0],I[0]),g[1]=Math.max(A[1],I[1]),g[2]=Math.max(A[2],I[2]),g[3]=Math.max(A[3],I[3]),g}function cvt(g,A){return g[0]=Ex(A[0]),g[1]=Ex(A[1]),g[2]=Ex(A[2]),g[3]=Ex(A[3]),g}function QwI(g,A,I){return g[0]=A[0]*I,g[1]=A[1]*I,g[2]=A[2]*I,g[3]=A[3]*I,g}function hvt(g,A,I,e){return g[0]=A[0]+I[0]*e,g[1]=A[1]+I[1]*e,g[2]=A[2]+I[2]*e,g[3]=A[3]+I[3]*e,g}function iwI(g,A){var I=A[0]-g[0],e=A[1]-g[1],t=A[2]-g[2],B=A[3]-g[3];return Math.sqrt(I*I+e*e+t*t+B*B)}function EwI(g,A){var I=A[0]-g[0],e=A[1]-g[1],t=A[2]-g[2],B=A[3]-g[3];return I*I+e*e+t*t+B*B}function l$A(g){var A=g[0],I=g[1],e=g[2],t=g[3];return Math.sqrt(A*A+I*I+e*e+t*t)}function D$A(g){var A=g[0],I=g[1],e=g[2],t=g[3];return A*A+I*I+e*e+t*t}function lvt(g,A){return g[0]=-A[0],g[1]=-A[1],g[2]=-A[2],g[3]=-A[3],g}function Dvt(g,A){return g[0]=1/A[0],g[1]=1/A[1],g[2]=1/A[2],g[3]=1/A[3],g}function nwI(g,A){var I=A[0],e=A[1],t=A[2],B=A[3],o=I*I+e*e+t*t+B*B;return o>0&&(o=1/Math.sqrt(o)),g[0]=I*o,g[1]=e*o,g[2]=t*o,g[3]=B*o,g}function d$A(g,A){return g[0]*A[0]+g[1]*A[1]+g[2]*A[2]+g[3]*A[3]}function dvt(g,A,I,e){var t=I[0]*e[1]-I[1]*e[0],B=I[0]*e[2]-I[2]*e[0],o=I[0]*e[3]-I[3]*e[0],C=I[1]*e[2]-I[2]*e[1],Q=I[1]*e[3]-I[3]*e[1],i=I[2]*e[3]-I[3]*e[2],E=A[0],n=A[1],s=A[2],r=A[3];return g[0]=n*i-s*Q+r*C,g[1]=-(E*i)+s*o-r*B,g[2]=E*Q-n*o+r*t,g[3]=-(E*C)+n*B-s*t,g}function swI(g,A,I,e){var t=A[0],B=A[1],o=A[2],C=A[3];return g[0]=t+e*(I[0]-t),g[1]=B+e*(I[1]-B),g[2]=o+e*(I[2]-o),g[3]=C+e*(I[3]-C),g}function yvt(g,A){A=A===void 0?1:A;var I,e,t,B,o,C,Q;Q=J2(),I=Q*2-1,e=(4*J2()-2)*Math.sqrt(Q*-Q+Q),o=I*I+e*e,Q=J2(),t=Q*2-1,B=(4*J2()-2)*Math.sqrt(Q*-Q+Q),C=t*t+B*B;var i=Math.sqrt((1-o)/C);return g[0]=A*I,g[1]=A*e,g[2]=A*t*i,g[3]=A*B*i,g}function wvt(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3];return g[0]=I[0]*e+I[4]*t+I[8]*B+I[12]*o,g[1]=I[1]*e+I[5]*t+I[9]*B+I[13]*o,g[2]=I[2]*e+I[6]*t+I[10]*B+I[14]*o,g[3]=I[3]*e+I[7]*t+I[11]*B+I[15]*o,g}function uvt(g,A,I){var e=I[0],t=I[1],B=I[2],o=I[3],C=A[0],Q=A[1],i=A[2],E=t*i-B*Q,n=B*C-e*i,s=e*Q-t*C;return E=E+E,n=n+n,s=s+s,g[0]=C+o*E+t*s-B*n,g[1]=Q+o*n+B*E-e*s,g[2]=i+o*s+e*n-t*E,g[3]=A[3],g}function Gvt(g){return g[0]=0,g[1]=0,g[2]=0,g[3]=0,g}function mvt(g){return"vec4("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")"}function awI(g,A){return g[0]===A[0]&&g[1]===A[1]&&g[2]===A[2]&&g[3]===A[3]}function pvt(g,A){var I=g[0],e=g[1],t=g[2],B=g[3],o=A[0],C=A[1],Q=A[2],i=A[3];return Math.abs(I-o)<=ao*Math.max(1,Math.abs(I),Math.abs(o))&&Math.abs(e-C)<=ao*Math.max(1,Math.abs(e),Math.abs(C))&&Math.abs(t-Q)<=ao*Math.max(1,Math.abs(t),Math.abs(Q))&&Math.abs(B-i)<=ao*Math.max(1,Math.abs(B),Math.abs(i))}var rwI,cwI,hwI,lwI,DwI,dwI,ywI,wwI,uwI=yR({"node_modules/gl-matrix/esm/vec4.js"(){nx(),rwI=BwI,cwI=owI,hwI=CwI,lwI=iwI,DwI=EwI,dwI=l$A,ywI=D$A,wwI=(function(){var g=$yI();return function(A,I,e,t,B,o){var C,Q;for(I||(I=4),e||(e=0),t?Q=Math.min(t*I+e,A.length):Q=A.length,C=e;C<Q;C+=I)g[0]=A[C],g[1]=A[C+1],g[2]=A[C+2],g[3]=A[C+3],B(g,g,o),A[C]=g[0],A[C+1]=g[1],A[C+2]=g[2],A[C+3]=g[3];return A}})()}}),GwI={};wR(GwI,{add:()=>JwI,calculateW:()=>fvt,clone:()=>xwI,conjugate:()=>Fvt,copy:()=>kdA,create:()=>mdA,dot:()=>MdA,equals:()=>Kvt,exactEquals:()=>_wI,exp:()=>fwI,fromEuler:()=>Uvt,fromMat3:()=>NwI,fromValues:()=>FwI,getAngle:()=>Svt,getAxisAngle:()=>Mvt,identity:()=>kvt,invert:()=>xvt,len:()=>LwI,length:()=>SdA,lerp:()=>PwI,ln:()=>RwI,mul:()=>KwI,multiply:()=>pwI,normalize:()=>RdA,pow:()=>Rvt,random:()=>Nvt,rotateX:()=>kwI,rotateY:()=>MwI,rotateZ:()=>SwI,rotationTo:()=>bwI,scale:()=>y$A,set:()=>UwI,setAxes:()=>vwI,setAxisAngle:()=>mwI,slerp:()=>pdA,sqlerp:()=>HwI,sqrLen:()=>YwI,squaredLength:()=>fdA,str:()=>Jvt});function mdA(){var g=new Si(4);return Si!=Float32Array&&(g[0]=0,g[1]=0,g[2]=0),g[3]=1,g}function kvt(g){return g[0]=0,g[1]=0,g[2]=0,g[3]=1,g}function mwI(g,A,I){I=I*.5;var e=Math.sin(I);return g[0]=e*A[0],g[1]=e*A[1],g[2]=e*A[2],g[3]=Math.cos(I),g}function Mvt(g,A){var I=Math.acos(A[3])*2,e=Math.sin(I/2);return e>ao?(g[0]=A[0]/e,g[1]=A[1]/e,g[2]=A[2]/e):(g[0]=1,g[1]=0,g[2]=0),I}function Svt(g,A){var I=MdA(g,A);return Math.acos(2*I*I-1)}function pwI(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=I[0],Q=I[1],i=I[2],E=I[3];return g[0]=e*E+o*C+t*i-B*Q,g[1]=t*E+o*Q+B*C-e*i,g[2]=B*E+o*i+e*Q-t*C,g[3]=o*E-e*C-t*Q-B*i,g}function kwI(g,A,I){I*=.5;var e=A[0],t=A[1],B=A[2],o=A[3],C=Math.sin(I),Q=Math.cos(I);return g[0]=e*Q+o*C,g[1]=t*Q+B*C,g[2]=B*Q-t*C,g[3]=o*Q-e*C,g}function MwI(g,A,I){I*=.5;var e=A[0],t=A[1],B=A[2],o=A[3],C=Math.sin(I),Q=Math.cos(I);return g[0]=e*Q-B*C,g[1]=t*Q+o*C,g[2]=B*Q+e*C,g[3]=o*Q-t*C,g}function SwI(g,A,I){I*=.5;var e=A[0],t=A[1],B=A[2],o=A[3],C=Math.sin(I),Q=Math.cos(I);return g[0]=e*Q+t*C,g[1]=t*Q-e*C,g[2]=B*Q+o*C,g[3]=o*Q-B*C,g}function fvt(g,A){var I=A[0],e=A[1],t=A[2];return g[0]=I,g[1]=e,g[2]=t,g[3]=Math.sqrt(Math.abs(1-I*I-e*e-t*t)),g}function fwI(g,A){var I=A[0],e=A[1],t=A[2],B=A[3],o=Math.sqrt(I*I+e*e+t*t),C=Math.exp(B),Q=o>0?C*Math.sin(o)/o:0;return g[0]=I*Q,g[1]=e*Q,g[2]=t*Q,g[3]=C*Math.cos(o),g}function RwI(g,A){var I=A[0],e=A[1],t=A[2],B=A[3],o=Math.sqrt(I*I+e*e+t*t),C=o>0?Math.atan2(o,B)/o:0;return g[0]=I*C,g[1]=e*C,g[2]=t*C,g[3]=.5*Math.log(I*I+e*e+t*t+B*B),g}function Rvt(g,A,I){return RwI(g,A),y$A(g,g,I),fwI(g,g),g}function pdA(g,A,I,e){var t=A[0],B=A[1],o=A[2],C=A[3],Q=I[0],i=I[1],E=I[2],n=I[3],s,r,a,c,h;return r=t*Q+B*i+o*E+C*n,r<0&&(r=-r,Q=-Q,i=-i,E=-E,n=-n),1-r>ao?(s=Math.acos(r),a=Math.sin(s),c=Math.sin((1-e)*s)/a,h=Math.sin(e*s)/a):(c=1-e,h=e),g[0]=c*t+h*Q,g[1]=c*B+h*i,g[2]=c*o+h*E,g[3]=c*C+h*n,g}function Nvt(g){var A=J2(),I=J2(),e=J2(),t=Math.sqrt(1-A),B=Math.sqrt(A);return g[0]=t*Math.sin(2*Math.PI*I),g[1]=t*Math.cos(2*Math.PI*I),g[2]=B*Math.sin(2*Math.PI*e),g[3]=B*Math.cos(2*Math.PI*e),g}function xvt(g,A){var I=A[0],e=A[1],t=A[2],B=A[3],o=I*I+e*e+t*t+B*B,C=o?1/o:0;return g[0]=-I*C,g[1]=-e*C,g[2]=-t*C,g[3]=B*C,g}function Fvt(g,A){return g[0]=-A[0],g[1]=-A[1],g[2]=-A[2],g[3]=A[3],g}function NwI(g,A){var I=A[0]+A[4]+A[8],e;if(I>0)e=Math.sqrt(I+1),g[3]=.5*e,e=.5/e,g[0]=(A[5]-A[7])*e,g[1]=(A[6]-A[2])*e,g[2]=(A[1]-A[3])*e;else{var t=0;A[4]>A[0]&&(t=1),A[8]>A[t*3+t]&&(t=2);var B=(t+1)%3,o=(t+2)%3;e=Math.sqrt(A[t*3+t]-A[B*3+B]-A[o*3+o]+1),g[t]=.5*e,e=.5/e,g[3]=(A[B*3+o]-A[o*3+B])*e,g[B]=(A[B*3+t]+A[t*3+B])*e,g[o]=(A[o*3+t]+A[t*3+o])*e}return g}function Uvt(g,A,I,e){var t=arguments.length>4&&arguments[4]!==void 0?arguments[4]:a$A,B=Math.PI/360;A*=B,e*=B,I*=B;var o=Math.sin(A),C=Math.cos(A),Q=Math.sin(I),i=Math.cos(I),E=Math.sin(e),n=Math.cos(e);switch(t){case"xyz":g[0]=o*i*n+C*Q*E,g[1]=C*Q*n-o*i*E,g[2]=C*i*E+o*Q*n,g[3]=C*i*n-o*Q*E;break;case"xzy":g[0]=o*i*n-C*Q*E,g[1]=C*Q*n-o*i*E,g[2]=C*i*E+o*Q*n,g[3]=C*i*n+o*Q*E;break;case"yxz":g[0]=o*i*n+C*Q*E,g[1]=C*Q*n-o*i*E,g[2]=C*i*E-o*Q*n,g[3]=C*i*n+o*Q*E;break;case"yzx":g[0]=o*i*n+C*Q*E,g[1]=C*Q*n+o*i*E,g[2]=C*i*E-o*Q*n,g[3]=C*i*n-o*Q*E;break;case"zxy":g[0]=o*i*n-C*Q*E,g[1]=C*Q*n+o*i*E,g[2]=C*i*E+o*Q*n,g[3]=C*i*n-o*Q*E;break;case"zyx":g[0]=o*i*n-C*Q*E,g[1]=C*Q*n+o*i*E,g[2]=C*i*E-o*Q*n,g[3]=C*i*n+o*Q*E;break;default:throw new Error("Unknown angle order "+t)}return g}function Jvt(g){return"quat("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")"}function Kvt(g,A){return Math.abs(d$A(g,A))>=1-ao}var xwI,FwI,kdA,UwI,JwI,KwI,y$A,MdA,PwI,SdA,LwI,fdA,YwI,RdA,_wI,bwI,HwI,vwI,qwI=yR({"node_modules/gl-matrix/esm/quat.js"(){nx(),dyI(),zyI(),uwI(),xwI=AwI,FwI=gwI,kdA=IwI,UwI=ewI,JwI=twI,KwI=pwI,y$A=QwI,MdA=d$A,PwI=swI,SdA=l$A,LwI=SdA,fdA=D$A,YwI=fdA,RdA=nwI,_wI=awI,bwI=(function(){var g=r$A(),A=c$A(1,0,0),I=c$A(0,1,0);return function(e,t,B){var o=udA(t,B);return o<-.999999?(GdA(g,A,t),h$A(g)<1e-6&&GdA(g,I,t),vyI(g,g),mwI(e,g,Math.PI),e):o>.999999?(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e):(GdA(g,t,B),e[0]=g[0],e[1]=g[1],e[2]=g[2],e[3]=1+o,RdA(e,e))}})(),HwI=(function(){var g=mdA(),A=mdA();return function(I,e,t,B,o,C){return pdA(g,e,o,C),pdA(A,t,B,C),pdA(I,g,A,2*C*(1-C)),I}})(),vwI=(function(){var g=ryI();return function(A,I,e,t){return g[0]=e[0],g[3]=e[1],g[6]=e[2],g[1]=t[0],g[4]=t[1],g[7]=t[2],g[2]=-I[0],g[5]=-I[1],g[8]=-I[2],RdA(A,NwI(A,g))}})()}}),TwI={};wR(TwI,{add:()=>Iqt,clone:()=>Lvt,conjugate:()=>oqt,copy:()=>OwI,create:()=>Pvt,dot:()=>w$A,equals:()=>Eqt,exactEquals:()=>iqt,fromMat4:()=>vvt,fromRotation:()=>Hvt,fromRotationTranslation:()=>ZwI,fromRotationTranslationValues:()=>_vt,fromTranslation:()=>bvt,fromValues:()=>Yvt,getDual:()=>Zvt,getReal:()=>VwI,getTranslation:()=>Wvt,identity:()=>qvt,invert:()=>Bqt,len:()=>XwI,length:()=>u$A,lerp:()=>tqt,mul:()=>zwI,multiply:()=>WwI,normalize:()=>Cqt,rotateAroundAxis:()=>gqt,rotateByQuatAppend:()=>$vt,rotateByQuatPrepend:()=>Aqt,rotateX:()=>jvt,rotateY:()=>zvt,rotateZ:()=>Xvt,scale:()=>eqt,set:()=>Tvt,setDual:()=>Ovt,setReal:()=>jwI,sqrLen:()=>$wI,squaredLength:()=>jgA,str:()=>Qqt,translate:()=>Vvt});function Pvt(){var g=new Si(8);return Si!=Float32Array&&(g[0]=0,g[1]=0,g[2]=0,g[4]=0,g[5]=0,g[6]=0,g[7]=0),g[3]=1,g}function Lvt(g){var A=new Si(8);return A[0]=g[0],A[1]=g[1],A[2]=g[2],A[3]=g[3],A[4]=g[4],A[5]=g[5],A[6]=g[6],A[7]=g[7],A}function Yvt(g,A,I,e,t,B,o,C){var Q=new Si(8);return Q[0]=g,Q[1]=A,Q[2]=I,Q[3]=e,Q[4]=t,Q[5]=B,Q[6]=o,Q[7]=C,Q}function _vt(g,A,I,e,t,B,o){var C=new Si(8);C[0]=g,C[1]=A,C[2]=I,C[3]=e;var Q=t*.5,i=B*.5,E=o*.5;return C[4]=Q*e+i*I-E*A,C[5]=i*e+E*g-Q*I,C[6]=E*e+Q*A-i*g,C[7]=-Q*g-i*A-E*I,C}function ZwI(g,A,I){var e=I[0]*.5,t=I[1]*.5,B=I[2]*.5,o=A[0],C=A[1],Q=A[2],i=A[3];return g[0]=o,g[1]=C,g[2]=Q,g[3]=i,g[4]=e*i+t*Q-B*C,g[5]=t*i+B*o-e*Q,g[6]=B*i+e*C-t*o,g[7]=-e*o-t*C-B*Q,g}function bvt(g,A){return g[0]=0,g[1]=0,g[2]=0,g[3]=1,g[4]=A[0]*.5,g[5]=A[1]*.5,g[6]=A[2]*.5,g[7]=0,g}function Hvt(g,A){return g[0]=A[0],g[1]=A[1],g[2]=A[2],g[3]=A[3],g[4]=0,g[5]=0,g[6]=0,g[7]=0,g}function vvt(g,A){var I=mdA();kyI(I,A);var e=new Si(3);return myI(e,A),ZwI(g,I,e),g}function OwI(g,A){return g[0]=A[0],g[1]=A[1],g[2]=A[2],g[3]=A[3],g[4]=A[4],g[5]=A[5],g[6]=A[6],g[7]=A[7],g}function qvt(g){return g[0]=0,g[1]=0,g[2]=0,g[3]=1,g[4]=0,g[5]=0,g[6]=0,g[7]=0,g}function Tvt(g,A,I,e,t,B,o,C,Q){return g[0]=A,g[1]=I,g[2]=e,g[3]=t,g[4]=B,g[5]=o,g[6]=C,g[7]=Q,g}function Zvt(g,A){return g[0]=A[4],g[1]=A[5],g[2]=A[6],g[3]=A[7],g}function Ovt(g,A){return g[4]=A[0],g[5]=A[1],g[6]=A[2],g[7]=A[3],g}function Wvt(g,A){var I=A[4],e=A[5],t=A[6],B=A[7],o=-A[0],C=-A[1],Q=-A[2],i=A[3];return g[0]=(I*i+B*o+e*Q-t*C)*2,g[1]=(e*i+B*C+t*o-I*Q)*2,g[2]=(t*i+B*Q+I*C-e*o)*2,g}function Vvt(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=I[0]*.5,Q=I[1]*.5,i=I[2]*.5,E=A[4],n=A[5],s=A[6],r=A[7];return g[0]=e,g[1]=t,g[2]=B,g[3]=o,g[4]=o*C+t*i-B*Q+E,g[5]=o*Q+B*C-e*i+n,g[6]=o*i+e*Q-t*C+s,g[7]=-e*C-t*Q-B*i+r,g}function jvt(g,A,I){var e=-A[0],t=-A[1],B=-A[2],o=A[3],C=A[4],Q=A[5],i=A[6],E=A[7],n=C*o+E*e+Q*B-i*t,s=Q*o+E*t+i*e-C*B,r=i*o+E*B+C*t-Q*e,a=E*o-C*e-Q*t-i*B;return kwI(g,A,I),e=g[0],t=g[1],B=g[2],o=g[3],g[4]=n*o+a*e+s*B-r*t,g[5]=s*o+a*t+r*e-n*B,g[6]=r*o+a*B+n*t-s*e,g[7]=a*o-n*e-s*t-r*B,g}function zvt(g,A,I){var e=-A[0],t=-A[1],B=-A[2],o=A[3],C=A[4],Q=A[5],i=A[6],E=A[7],n=C*o+E*e+Q*B-i*t,s=Q*o+E*t+i*e-C*B,r=i*o+E*B+C*t-Q*e,a=E*o-C*e-Q*t-i*B;return MwI(g,A,I),e=g[0],t=g[1],B=g[2],o=g[3],g[4]=n*o+a*e+s*B-r*t,g[5]=s*o+a*t+r*e-n*B,g[6]=r*o+a*B+n*t-s*e,g[7]=a*o-n*e-s*t-r*B,g}function Xvt(g,A,I){var e=-A[0],t=-A[1],B=-A[2],o=A[3],C=A[4],Q=A[5],i=A[6],E=A[7],n=C*o+E*e+Q*B-i*t,s=Q*o+E*t+i*e-C*B,r=i*o+E*B+C*t-Q*e,a=E*o-C*e-Q*t-i*B;return SwI(g,A,I),e=g[0],t=g[1],B=g[2],o=g[3],g[4]=n*o+a*e+s*B-r*t,g[5]=s*o+a*t+r*e-n*B,g[6]=r*o+a*B+n*t-s*e,g[7]=a*o-n*e-s*t-r*B,g}function $vt(g,A,I){var e=I[0],t=I[1],B=I[2],o=I[3],C=A[0],Q=A[1],i=A[2],E=A[3];return g[0]=C*o+E*e+Q*B-i*t,g[1]=Q*o+E*t+i*e-C*B,g[2]=i*o+E*B+C*t-Q*e,g[3]=E*o-C*e-Q*t-i*B,C=A[4],Q=A[5],i=A[6],E=A[7],g[4]=C*o+E*e+Q*B-i*t,g[5]=Q*o+E*t+i*e-C*B,g[6]=i*o+E*B+C*t-Q*e,g[7]=E*o-C*e-Q*t-i*B,g}function Aqt(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=I[0],Q=I[1],i=I[2],E=I[3];return g[0]=e*E+o*C+t*i-B*Q,g[1]=t*E+o*Q+B*C-e*i,g[2]=B*E+o*i+e*Q-t*C,g[3]=o*E-e*C-t*Q-B*i,C=I[4],Q=I[5],i=I[6],E=I[7],g[4]=e*E+o*C+t*i-B*Q,g[5]=t*E+o*Q+B*C-e*i,g[6]=B*E+o*i+e*Q-t*C,g[7]=o*E-e*C-t*Q-B*i,g}function gqt(g,A,I,e){if(Math.abs(e)<ao)return OwI(g,A);var t=Math.sqrt(I[0]*I[0]+I[1]*I[1]+I[2]*I[2]);e=e*.5;var B=Math.sin(e),o=B*I[0]/t,C=B*I[1]/t,Q=B*I[2]/t,i=Math.cos(e),E=A[0],n=A[1],s=A[2],r=A[3];g[0]=E*i+r*o+n*Q-s*C,g[1]=n*i+r*C+s*o-E*Q,g[2]=s*i+r*Q+E*C-n*o,g[3]=r*i-E*o-n*C-s*Q;var a=A[4],c=A[5],h=A[6],l=A[7];return g[4]=a*i+l*o+c*Q-h*C,g[5]=c*i+l*C+h*o-a*Q,g[6]=h*i+l*Q+a*C-c*o,g[7]=l*i-a*o-c*C-h*Q,g}function Iqt(g,A,I){return g[0]=A[0]+I[0],g[1]=A[1]+I[1],g[2]=A[2]+I[2],g[3]=A[3]+I[3],g[4]=A[4]+I[4],g[5]=A[5]+I[5],g[6]=A[6]+I[6],g[7]=A[7]+I[7],g}function WwI(g,A,I){var e=A[0],t=A[1],B=A[2],o=A[3],C=I[4],Q=I[5],i=I[6],E=I[7],n=A[4],s=A[5],r=A[6],a=A[7],c=I[0],h=I[1],l=I[2],D=I[3];return g[0]=e*D+o*c+t*l-B*h,g[1]=t*D+o*h+B*c-e*l,g[2]=B*D+o*l+e*h-t*c,g[3]=o*D-e*c-t*h-B*l,g[4]=e*E+o*C+t*i-B*Q+n*D+a*c+s*l-r*h,g[5]=t*E+o*Q+B*C-e*i+s*D+a*h+r*c-n*l,g[6]=B*E+o*i+e*Q-t*C+r*D+a*l+n*h-s*c,g[7]=o*E-e*C-t*Q-B*i+a*D-n*c-s*h-r*l,g}function eqt(g,A,I){return g[0]=A[0]*I,g[1]=A[1]*I,g[2]=A[2]*I,g[3]=A[3]*I,g[4]=A[4]*I,g[5]=A[5]*I,g[6]=A[6]*I,g[7]=A[7]*I,g}function tqt(g,A,I,e){var t=1-e;return w$A(A,I)<0&&(e=-e),g[0]=A[0]*t+I[0]*e,g[1]=A[1]*t+I[1]*e,g[2]=A[2]*t+I[2]*e,g[3]=A[3]*t+I[3]*e,g[4]=A[4]*t+I[4]*e,g[5]=A[5]*t+I[5]*e,g[6]=A[6]*t+I[6]*e,g[7]=A[7]*t+I[7]*e,g}function Bqt(g,A){var I=jgA(A);return g[0]=-A[0]/I,g[1]=-A[1]/I,g[2]=-A[2]/I,g[3]=A[3]/I,g[4]=-A[4]/I,g[5]=-A[5]/I,g[6]=-A[6]/I,g[7]=A[7]/I,g}function oqt(g,A){return g[0]=-A[0],g[1]=-A[1],g[2]=-A[2],g[3]=A[3],g[4]=-A[4],g[5]=-A[5],g[6]=-A[6],g[7]=A[7],g}function Cqt(g,A){var I=jgA(A);if(I>0){I=Math.sqrt(I);var e=A[0]/I,t=A[1]/I,B=A[2]/I,o=A[3]/I,C=A[4],Q=A[5],i=A[6],E=A[7],n=e*C+t*Q+B*i+o*E;g[0]=e,g[1]=t,g[2]=B,g[3]=o,g[4]=(C-e*n)/I,g[5]=(Q-t*n)/I,g[6]=(i-B*n)/I,g[7]=(E-o*n)/I}return g}function Qqt(g){return"quat2("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+", "+g[4]+", "+g[5]+", "+g[6]+", "+g[7]+")"}function iqt(g,A){return g[0]===A[0]&&g[1]===A[1]&&g[2]===A[2]&&g[3]===A[3]&&g[4]===A[4]&&g[5]===A[5]&&g[6]===A[6]&&g[7]===A[7]}function Eqt(g,A){var I=g[0],e=g[1],t=g[2],B=g[3],o=g[4],C=g[5],Q=g[6],i=g[7],E=A[0],n=A[1],s=A[2],r=A[3],a=A[4],c=A[5],h=A[6],l=A[7];return Math.abs(I-E)<=ao*Math.max(1,Math.abs(I),Math.abs(E))&&Math.abs(e-n)<=ao*Math.max(1,Math.abs(e),Math.abs(n))&&Math.abs(t-s)<=ao*Math.max(1,Math.abs(t),Math.abs(s))&&Math.abs(B-r)<=ao*Math.max(1,Math.abs(B),Math.abs(r))&&Math.abs(o-a)<=ao*Math.max(1,Math.abs(o),Math.abs(a))&&Math.abs(C-c)<=ao*Math.max(1,Math.abs(C),Math.abs(c))&&Math.abs(Q-h)<=ao*Math.max(1,Math.abs(Q),Math.abs(h))&&Math.abs(i-l)<=ao*Math.max(1,Math.abs(i),Math.abs(l))}var VwI,jwI,zwI,w$A,u$A,XwI,jgA,$wI,nqt=yR({"node_modules/gl-matrix/esm/quat2.js"(){nx(),qwI(),UyI(),VwI=kdA,jwI=kdA,zwI=WwI,w$A=MdA,u$A=SdA,XwI=u$A,jgA=fdA,$wI=jgA}}),AuI={};wR(AuI,{add:()=>hqt,angle:()=>Kqt,ceil:()=>lqt,clone:()=>sqt,copy:()=>rqt,create:()=>guI,cross:()=>Sqt,dist:()=>auI,distance:()=>BuI,div:()=>suI,divide:()=>tuI,dot:()=>Mqt,equals:()=>bqt,exactEquals:()=>_qt,floor:()=>Dqt,forEach:()=>huI,fromValues:()=>aqt,inverse:()=>pqt,len:()=>iuI,length:()=>CuI,lerp:()=>fqt,max:()=>yqt,min:()=>dqt,mul:()=>nuI,multiply:()=>euI,negate:()=>mqt,normalize:()=>kqt,random:()=>Rqt,rotate:()=>Jqt,round:()=>wqt,scale:()=>uqt,scaleAndAdd:()=>Gqt,set:()=>cqt,signedAngle:()=>Pqt,sqrDist:()=>ruI,sqrLen:()=>cuI,squaredDistance:()=>ouI,squaredLength:()=>QuI,str:()=>Yqt,sub:()=>EuI,subtract:()=>IuI,transformMat2:()=>Nqt,transformMat2d:()=>xqt,transformMat3:()=>Fqt,transformMat4:()=>Uqt,zero:()=>Lqt});function guI(){var g=new Si(2);return Si!=Float32Array&&(g[0]=0,g[1]=0),g}function sqt(g){var A=new Si(2);return A[0]=g[0],A[1]=g[1],A}function aqt(g,A){var I=new Si(2);return I[0]=g,I[1]=A,I}function rqt(g,A){return g[0]=A[0],g[1]=A[1],g}function cqt(g,A,I){return g[0]=A,g[1]=I,g}function hqt(g,A,I){return g[0]=A[0]+I[0],g[1]=A[1]+I[1],g}function IuI(g,A,I){return g[0]=A[0]-I[0],g[1]=A[1]-I[1],g}function euI(g,A,I){return g[0]=A[0]*I[0],g[1]=A[1]*I[1],g}function tuI(g,A,I){return g[0]=A[0]/I[0],g[1]=A[1]/I[1],g}function lqt(g,A){return g[0]=Math.ceil(A[0]),g[1]=Math.ceil(A[1]),g}function Dqt(g,A){return g[0]=Math.floor(A[0]),g[1]=Math.floor(A[1]),g}function dqt(g,A,I){return g[0]=Math.min(A[0],I[0]),g[1]=Math.min(A[1],I[1]),g}function yqt(g,A,I){return g[0]=Math.max(A[0],I[0]),g[1]=Math.max(A[1],I[1]),g}function wqt(g,A){return g[0]=Ex(A[0]),g[1]=Ex(A[1]),g}function uqt(g,A,I){return g[0]=A[0]*I,g[1]=A[1]*I,g}function Gqt(g,A,I,e){return g[0]=A[0]+I[0]*e,g[1]=A[1]+I[1]*e,g}function BuI(g,A){var I=A[0]-g[0],e=A[1]-g[1];return Math.sqrt(I*I+e*e)}function ouI(g,A){var I=A[0]-g[0],e=A[1]-g[1];return I*I+e*e}function CuI(g){var A=g[0],I=g[1];return Math.sqrt(A*A+I*I)}function QuI(g){var A=g[0],I=g[1];return A*A+I*I}function mqt(g,A){return g[0]=-A[0],g[1]=-A[1],g}function pqt(g,A){return g[0]=1/A[0],g[1]=1/A[1],g}function kqt(g,A){var I=A[0],e=A[1],t=I*I+e*e;return t>0&&(t=1/Math.sqrt(t)),g[0]=A[0]*t,g[1]=A[1]*t,g}function Mqt(g,A){return g[0]*A[0]+g[1]*A[1]}function Sqt(g,A,I){var e=A[0]*I[1]-A[1]*I[0];return g[0]=g[1]=0,g[2]=e,g}function fqt(g,A,I,e){var t=A[0],B=A[1];return g[0]=t+e*(I[0]-t),g[1]=B+e*(I[1]-B),g}function Rqt(g,A){A=A===void 0?1:A;var I=J2()*2*Math.PI;return g[0]=Math.cos(I)*A,g[1]=Math.sin(I)*A,g}function Nqt(g,A,I){var e=A[0],t=A[1];return g[0]=I[0]*e+I[2]*t,g[1]=I[1]*e+I[3]*t,g}function xqt(g,A,I){var e=A[0],t=A[1];return g[0]=I[0]*e+I[2]*t+I[4],g[1]=I[1]*e+I[3]*t+I[5],g}function Fqt(g,A,I){var e=A[0],t=A[1];return g[0]=I[0]*e+I[3]*t+I[6],g[1]=I[1]*e+I[4]*t+I[7],g}function Uqt(g,A,I){var e=A[0],t=A[1];return g[0]=I[0]*e+I[4]*t+I[12],g[1]=I[1]*e+I[5]*t+I[13],g}function Jqt(g,A,I,e){var t=A[0]-I[0],B=A[1]-I[1],o=Math.sin(e),C=Math.cos(e);return g[0]=t*C-B*o+I[0],g[1]=t*o+B*C+I[1],g}function Kqt(g,A){var I=g[0],e=g[1],t=A[0],B=A[1];return Math.abs(Math.atan2(e*t-I*B,I*t+e*B))}function Pqt(g,A){var I=g[0],e=g[1],t=A[0],B=A[1];return Math.atan2(I*B-e*t,I*t+e*B)}function Lqt(g){return g[0]=0,g[1]=0,g}function Yqt(g){return"vec2("+g[0]+", "+g[1]+")"}function _qt(g,A){return g[0]===A[0]&&g[1]===A[1]}function bqt(g,A){var I=g[0],e=g[1],t=A[0],B=A[1];return Math.abs(I-t)<=ao*Math.max(1,Math.abs(I),Math.abs(t))&&Math.abs(e-B)<=ao*Math.max(1,Math.abs(e),Math.abs(B))}var iuI,EuI,nuI,suI,auI,ruI,cuI,huI,Hqt=yR({"node_modules/gl-matrix/esm/vec2.js"(){nx(),iuI=CuI,EuI=IuI,nuI=euI,suI=tuI,auI=BuI,ruI=ouI,cuI=QuI,huI=(function(){var g=guI();return function(A,I,e,t,B,o){var C,Q;for(I||(I=2),e||(e=0),t?Q=Math.min(t*I+e,A.length):Q=A.length,C=e;C<Q;C+=I)g[0]=A[C],g[1]=A[C+1],B(g,g,o),A[C]=g[0],A[C+1]=g[1];return A}})()}}),luI={};wR(luI,{glMatrix:()=>AyI,mat2:()=>eyI,mat2d:()=>QyI,mat3:()=>ayI,mat4:()=>yyI,quat:()=>GwI,quat2:()=>TwI,vec2:()=>AuI,vec3:()=>JyI,vec4:()=>XyI});var vqt=yR({"node_modules/gl-matrix/esm/index.js"(){nx(),gHt(),GHt(),dyI(),UyI(),qwI(),nqt(),Hqt(),zyI(),uwI()}}),DuI=fg({"node_modules/jscad-planner/dist/index.cjs"(g,A){var I=Object.defineProperty,e=Object.getOwnPropertyDescriptor,t=Object.getOwnPropertyNames,B=Object.prototype.hasOwnProperty,o=(w,u)=>{for(var G in u)I(w,G,{get:u[G],enumerable:!0})},C=(w,u,G,m)=>{if(u&&typeof u=="object"||typeof u=="function")for(let p of t(u))!B.call(w,p)&&p!==G&&I(w,p,{get:()=>u[p],enumerable:!(m=e(u,p))||m.enumerable});return w},Q=w=>C(I({},"__esModule",{value:!0}),w),i={};o(i,{assertTransformMatrix:()=>n,executeJscadOperations:()=>d,jscadPlanner:()=>r,resolveReferencePlanes:()=>D,toTransformMatrix:()=>s}),A.exports=Q(i);var E="Transform matrix must be a column-major array of exactly 16 finite numbers";function n(w){if(!Array.isArray(w)||w.length!==16||!Array.from(w).every(Number.isFinite))throw new Error(E)}function s(w){if(w==null||w.length!==16)throw new Error(E);const u=Array.from(w);return n(u),u}var r={booleans:{intersect:(...w)=>({type:"intersect",shapes:w}),subtract:(...w)=>({type:"subtract",shapes:w}),union:(...w)=>({type:"union",shapes:w})},hulls:{hull:(...w)=>({type:"hull",shapes:w.flat()}),hullChain:(...w)=>({type:"hullChain",shapes:w.flat()})},colors:{colorize:(w,u)=>({type:"colorize",color:w,shape:u})},primitives:{rectangle:w=>({...w,type:"rectangle"}),cube:w=>({type:"cube",...w}),sphere:w=>({type:"sphere",...w}),cylinder:w=>({type:"cylinder",...w}),polygon:w=>({type:"polygon",...w}),cuboid:w=>({type:"cuboid",...w}),roundedCuboid:w=>({type:"roundedCuboid",...w})},transforms:{transform:(w,u)=>(n(w),{type:"transform",matrix:w,shape:u}),rotate:(w,u)=>({type:"rotate",angles:w,shape:u}),rotateX:(w,u)=>({type:"rotateX",angle:w,shape:u}),rotateY:(w,u)=>({type:"rotateY",angle:w,shape:u}),rotateZ:(w,u)=>({type:"rotateZ",angle:w,shape:u}),scale:(w,u)=>({type:"scale",factors:w,shape:u}),translate:(w,u)=>({type:"translate",vector:w,shape:u})},extrusions:{extrudeLinear:(w,u)=>({type:"extrudeLinear",options:w,shape:u}),extrudeRotate:(w,u)=>({type:"extrudeRotate",options:w,shape:u})},maths:{vec2:{create:(w,u)=>[w,u],fromValues:(w,u)=>[w,u]},vec3:{create:(w,u,G)=>[w,u,G],fromValues:(w,u,G)=>[w,u,G]}},geometries:{geom2:{create:w=>({type:"createGeom2",points:w}),fromPoints:w=>({type:"fromPointsGeom2",points:w})},geom3:{create:w=>({type:"createGeom3",polygons:w})},path2:{create:w=>({type:"createPath2",points:w})}},measurements:{measureBoundingBox:w=>({type:"measureBoundingBox",shape:w}),measureArea:w=>({type:"measureArea",shape:w}),measureVolume:w=>({type:"measureVolume",shape:w})},utils:{degToRad:w=>w*Math.PI/180,radToDeg:w=>w*180/Math.PI}},a=(vqt(),qYt(luI)),c=()=>s(a.mat4.create());function h(w){const u=c();switch(w.type){case"transform":return n(w.matrix),[...w.matrix];case"translate":return s(a.mat4.fromTranslation(u,w.vector));case"scale":return s(a.mat4.fromScaling(u,w.factors));case"rotate":return a.mat4.rotateZ(u,u,w.angles[2]),a.mat4.rotateY(u,u,w.angles[1]),a.mat4.rotateX(u,u,w.angles[0]),u;case"rotateX":return s(a.mat4.fromXRotation(u,w.angle));case"rotateY":return s(a.mat4.fromYRotation(u,w.angle));case"rotateZ":return s(a.mat4.fromZRotation(u,w.angle));default:throw new Error(`Cannot use ${w.type} as a reference transform`)}}function l(w,u){const G=w.name;if(!G?.trim())throw new Error("Reference rectangles require a nonblank name");let m;if(w.type==="rectangle"){if(w.size.length!==2||!w.size.every(N=>Number.isFinite(N)&&N>0))throw new Error(`Reference rectangle "${G}" requires two positive finite dimensions`);m=w.center??[0,0]}else{const N=w.points;if(w.paths||N.length!==4||!N.every(H=>H.length===2&&H.every(q=>typeof q=="number"&&Number.isFinite(q))))throw new Error(`Reference polygon "${G}" must be an axis-aligned rectangle`);const U=N,P=[...new Set(U.map(H=>H[0]))],b=[...new Set(U.map(H=>H[1]))];if(P.length!==2||b.length!==2||new Set(U.map(H=>JSON.stringify(H))).size!==4)throw new Error(`Reference polygon "${G}" must be an axis-aligned rectangle`);m=[(P[0]+P[1])/2,(b[0]+b[1])/2]}if(m.length!==2||!m.every(Number.isFinite))throw new Error(`Reference rectangle "${G}" has an invalid center`);const p=c();for(const N of u)a.mat4.multiply(p,p,h(N));if(n(p),p[3]!==0||p[7]!==0||p[11]!==0||p[15]!==1)throw new Error(`Reference rectangle "${G}" requires affine transforms`);const k=a.mat4.invert(c(),p);if(!k)throw new Error(`Reference rectangle "${G}" has a singular transform`);const S=[0,0,0];a.vec3.transformMat4(S,[m[0],m[1],0],p);const R=[k[2],k[6],k[10]],F=[p[0],p[1],p[2]];if(![...S,...R,...F].every(Number.isFinite)||!a.vec3.length(R)||!a.vec3.length(F))throw new Error(`Reference rectangle "${G}" has an invalid frame`);return a.vec3.normalize(R,R),a.vec3.normalize(F,F),{name:G,origin:S,normal:R,xAxis:F}}function D(w){const u=[],G=new Set;function m(S,R,F=!1){if(S.reference){if(S.type!=="rectangle"&&S.type!=="polygon")throw new Error("Only rectangles can be reference geometry");if(F)throw new Error("Reference rectangles must be outside extrusion and measurement inputs");const N=l(S,R);if(G.has(N.name))throw new Error(`Duplicate reference plane "${N.name}"`);G.add(N.name),u.push(N);return}switch(S.type){case"translate":case"rotate":case"rotateX":case"rotateY":case"rotateZ":case"scale":case"transform":{const N=m(S.shape,[...R,S],F);return N?{...S,shape:N}:void 0}case"colorize":{const N=m(S.shape,R,F);return N?{...S,shape:N}:void 0}case"extrudeLinear":case"extrudeRotate":case"measureArea":case"measureVolume":case"measureBoundingBox":{const N=m(S.shape,R,!0);return N?{...S,shape:N}:void 0}case"union":case"subtract":case"intersect":case"hull":case"hullChain":{const N=S.shapes.map(P=>m(P,R,F));if(S.type==="subtract"&&S.shapes.length&&!N[0])throw new Error("A subtraction base cannot be reference geometry");const U=N.filter(P=>P!==void 0);return U.length?U.length===1?U[0]:{...S,shapes:U}:void 0}default:return{...S}}}const p=(Array.isArray(w)?w:[w]).map(S=>m(S,[])).filter(S=>S!==void 0);return{geometry:p.length>1?{type:"union",shapes:p}:p[0],referencePlanes:u}}var d=(w,u)=>{if(Array.isArray(u)&&u.length===1)return d(w,u[0]);if(Array.isArray(u))throw new Error("executeJscadOperations currently doesn't support Array<JscadOperation>, try adding a root union or or executing each element individually");const{geometry:G}=D(u);if(!G)throw new Error("JSCAD plan contains only reference geometry");return y(w,G)},y=(w,u)=>{const G=k=>y(w,k),{type:m,...p}=u;switch(m){case"rectangle":if(!w.primitives.rectangle)throw new Error("JSCAD adapter does not support primitives.rectangle");return w.primitives.rectangle({size:u.size,center:u.center??[0,0]});case"intersect":return w.booleans.intersect(...u.shapes.map(G));case"subtract":return w.booleans.subtract(...u.shapes.map(G));case"union":return w.booleans.union(...u.shapes.map(G));case"hull":return w.hulls.hull(...u.shapes.map(G));case"hullChain":return w.hulls.hullChain(...u.shapes.map(G));case"colorize":return w.colors.colorize(u.color,G(u.shape));case"cube":return w.primitives.cube(p);case"sphere":return w.primitives.sphere(p);case"cylinder":return w.primitives.cylinder(p);case"polygon":return w.primitives.polygon(p);case"cuboid":return w.primitives.cuboid(p);case"roundedCuboid":return w.primitives.roundedCuboid(p);case"transform":if(n(u.matrix),!w.transforms.transform)throw new Error('Cannot execute "transform" operation: this JSCAD adapter does not support transforms.transform');return w.transforms.transform(u.matrix,G(u.shape));case"rotate":return w.transforms.rotate(u.angles,G(u.shape));case"rotateX":return w.transforms.rotateX(u.angle,G(u.shape));case"rotateY":return w.transforms.rotateY(u.angle,G(u.shape));case"rotateZ":return w.transforms.rotateZ(u.angle,G(u.shape));case"scale":return w.transforms.scale(u.factors,G(u.shape));case"translate":return w.transforms.translate(u.vector,G(u.shape));case"extrudeLinear":return w.extrusions.extrudeLinear(u.options,G(u.shape));case"extrudeRotate":return w.extrusions.extrudeRotate(u.options,G(u.shape));case"createGeom2":return w.geometries.geom2.create(u.points);case"fromPointsGeom2":return w.geometries.geom2.fromPoints(u.points);case"createGeom3":return w.geometries.geom3.create(u.polygons);case"createPath2":return w.geometries.path2.create(u.points);case"measureBoundingBox":return w.measurements.measureBoundingBox(G(u.shape));case"measureArea":return w.measurements.measureArea(G(u.shape));case"measureVolume":return w.measurements.measureVolume(G(u.shape));case"degToRad":return w.utils.degToRad(u.degrees);case"radToDeg":return w.utils.radToDeg(u.radians);default:throw u.type===void 0?new Error(`Operation type is undefined. This usually means the operation object is malformed or not properly initialized. Operation: ${JSON.stringify(u,null,2).slice(0,200)}...`):new Error(`Unsupported operation type: ${u.type}. Operation: ${JSON.stringify(u,null,2)}`)}}}}),qqt=fg({"node_modules/ms/index.js"(g,A){var I=1e3,e=I*60,t=e*60,B=t*24,o=B*7,C=B*365.25;A.exports=function(s,r){r=r||{};var a=typeof s;if(a==="string"&&s.length>0)return Q(s);if(a==="number"&&isFinite(s))return r.long?E(s):i(s);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(s))};function Q(s){if(s=String(s),!(s.length>100)){var r=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(s);if(r){var a=parseFloat(r[1]),c=(r[2]||"ms").toLowerCase();switch(c){case"years":case"year":case"yrs":case"yr":case"y":return a*C;case"weeks":case"week":case"w":return a*o;case"days":case"day":case"d":return a*B;case"hours":case"hour":case"hrs":case"hr":case"h":return a*t;case"minutes":case"minute":case"mins":case"min":case"m":return a*e;case"seconds":case"second":case"secs":case"sec":case"s":return a*I;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}}}function i(s){var r=Math.abs(s);return r>=B?Math.round(s/B)+"d":r>=t?Math.round(s/t)+"h":r>=e?Math.round(s/e)+"m":r>=I?Math.round(s/I)+"s":s+"ms"}function E(s){var r=Math.abs(s);return r>=B?n(s,r,B,"day"):r>=t?n(s,r,t,"hour"):r>=e?n(s,r,e,"minute"):r>=I?n(s,r,I,"second"):s+" ms"}function n(s,r,a,c){var h=r>=a*1.5;return Math.round(s/a)+" "+c+(h?"s":"")}}}),Tqt=fg({"node_modules/debug/src/common.js"(g,A){function I(e){B.debug=B,B.default=B,B.coerce=n,B.disable=i,B.enable=C,B.enabled=E,B.humanize=qqt(),B.destroy=s,Object.keys(e).forEach(r=>{B[r]=e[r]}),B.names=[],B.skips=[],B.formatters={};function t(r){let a=0;for(let c=0;c<r.length;c++)a=(a<<5)-a+r.charCodeAt(c),a|=0;return B.colors[Math.abs(a)%B.colors.length]}B.selectColor=t;function B(r){let a,c=null,h,l;function D(...d){if(!D.enabled)return;const y=D,w=Number(new Date),u=w-(a||w);y.diff=u,y.prev=a,y.curr=w,a=w,d[0]=B.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let G=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(p,k)=>{if(p==="%%")return"%";G++;const S=B.formatters[k];if(typeof S=="function"){const R=d[G];p=S.call(y,R),d.splice(G,1),G--}return p}),B.formatArgs.call(y,d),(y.log||B.log).apply(y,d)}return D.namespace=r,D.useColors=B.useColors(),D.color=B.selectColor(r),D.extend=o,D.destroy=B.destroy,Object.defineProperty(D,"enabled",{enumerable:!0,configurable:!1,get:()=>c!==null?c:(h!==B.namespaces&&(h=B.namespaces,l=B.enabled(r)),l),set:d=>{c=d}}),typeof B.init=="function"&&B.init(D),D}function o(r,a){const c=B(this.namespace+(typeof a>"u"?":":a)+r);return c.log=this.log,c}function C(r){B.save(r),B.namespaces=r,B.names=[],B.skips=[];const a=(typeof r=="string"?r:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const c of a)c[0]==="-"?B.skips.push(c.slice(1)):B.names.push(c)}function Q(r,a){let c=0,h=0,l=-1,D=0;for(;c<r.length;)if(h<a.length&&(a[h]===r[c]||a[h]==="*"))a[h]==="*"?(l=h,D=c,h++):(c++,h++);else if(l!==-1)h=l+1,D++,c=D;else return!1;for(;h<a.length&&a[h]==="*";)h++;return h===a.length}function i(){const r=[...B.names,...B.skips.map(a=>"-"+a)].join(",");return B.enable(""),r}function E(r){for(const a of B.skips)if(Q(r,a))return!1;for(const a of B.names)if(Q(r,a))return!0;return!1}function n(r){return r instanceof Error?r.stack||r.message:r}function s(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return B.enable(B.load()),B}A.exports=I}}),Zqt=fg({"node_modules/debug/src/browser.js"(g,A){g.formatArgs=e,g.save=t,g.load=B,g.useColors=I,g.storage=o(),g.destroy=(()=>{let Q=!1;return()=>{Q||(Q=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),g.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function I(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let Q;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(Q=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(Q[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function e(Q){if(Q[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+Q[0]+(this.useColors?"%c ":" ")+"+"+A.exports.humanize(this.diff),!this.useColors)return;const i="color: "+this.color;Q.splice(1,0,i,"color: inherit");let E=0,n=0;Q[0].replace(/%[a-zA-Z%]/g,s=>{s!=="%%"&&(E++,s==="%c"&&(n=E))}),Q.splice(n,0,i)}g.log=console.debug||console.log||(()=>{});function t(Q){try{Q?g.storage.setItem("debug",Q):g.storage.removeItem("debug")}catch{}}function B(){let Q;try{Q=g.storage.getItem("debug")||g.storage.getItem("DEBUG")}catch{}return!Q&&typeof PXA<"u"&&"env"in PXA&&(Q=PXA.env.DEBUG),Q}function o(){try{return localStorage}catch{}}A.exports=Tqt()(g);var{formatters:C}=A.exports;C.j=function(Q){try{return JSON.stringify(Q)}catch(i){return"[UnexpectedJSONParseError]: "+i.message}}}}),G$A=gA.createContext(null),SD=()=>{const g=gA.useContext(G$A);if(!g)throw new Error("useThree must be used within a ThreeProvider");return g},zgA=(g,A=[])=>{const{addFrameListener:I,removeFrameListener:e}=SD();nC.useEffect(()=>(I(g),()=>e(g)),[I,e,...A])},m$A=gA.createContext(null),Oqt=()=>{const g=gA.useContext(m$A),A=SD();return gA.useEffect(()=>{if(g)return g.current=A,()=>{g.current=null}},[g,A]),null},Wqt=({cadComponent:g,children:A})=>{const I=SD(),e=gA.useMemo(()=>new Nc,[]);e.userData.cad_component_id=g.cad_component_id,e.userData.pcb_component_id=g.pcb_component_id,gA.useEffect(()=>(I.rootObject.add(e),()=>{I.rootObject.remove(e)}),[I.rootObject,e]);const t=gA.useMemo(()=>({...I,rootObject:e}),[I,e]);return W.jsx(G$A.Provider,{value:t,children:A})},duI=(g,A)=>{if(!g)return;const{camera:I,rootObject:e,renderer:t}=g,B=t.domElement.getBoundingClientRect();if(!B.width||!B.height||A.x<B.left||A.x>B.right||A.y<B.top||A.y>B.bottom)return;const o=new QFg;I.updateWorldMatrix(!0,!1),e.updateWorldMatrix(!0,!0),o.setFromCamera(new ct((A.x-B.left)/B.width*2-1,-((A.y-B.top)/B.height)*2+1),I);for(const C of o.intersectObject(e,!0)){if(!(C.object instanceof FB))continue;let Q=C.object,i=!0;for(;Q;)Q.visible||(i=!1),Q=Q.parent;if(i)return C.object}},Vqt=(g,A,I)=>{let e=duI(g,A)??null,t;for(;e;)t??=e.userData.pcb_component_id,e=e.parent;if(!t)return;const B=I.find(C=>C.type==="pcb_component"&&C.pcb_component_id===t);if(B?.type!=="pcb_component")return;const o=I.find(C=>C.type==="source_component"&&C.source_component_id===B.source_component_id);if(o?.type==="source_component")return{source_component_id:o.source_component_id,pcb_component_id:B.pcb_component_id,refdes:o.name}};function yuI(g,A){return A??g.some(I=>I.type==="cad_component"&&I.is_on_folded_board===!0)}var jqt=(g,A,I)=>{let e=duI(g,A)??null;for(;e;){const t=e.userData.cad_component_id;if(t){const B=I.find(C=>C.type==="cad_component"&&C.cad_component_id===t);if(B?.type!=="cad_component")return;const o=I.find(C=>C.type==="source_component"&&C.source_component_id===B.source_component_id);return{cad_component_id:B.cad_component_id,componentName:o?.type==="source_component"?o.name:B.cad_component_id}}e=e.parent}},NdA=new Set,zqt=g=>{const[A,I]=gA.useState({circuitKey:g,ids:NdA}),e=A.circuitKey===g?A.ids:NdA;return A.circuitKey!==g&&I({circuitKey:g,ids:NdA}),{hiddenCadComponentIds:e,hideComponent:t=>{I(B=>({circuitKey:g,ids:new Set([...B.circuitKey===g?B.ids:[],t])}))},unhideAllComponents:()=>{I({circuitKey:g,ids:NdA})}}};function XgA(g,A,I){const e=typeof window<"u"?window.TSCIRCUIT_JSCDN_BASE_URL:void 0;return e?new URL(`${e.replace(/\/+$/,"")}/${g}/${A}/${I}`,window.location.href).href:`https://cdn.jsdelivr.net/npm/${g}@${A}/${I}`}var wuI=!1;function Xqt(){wuI||typeof window>"u"||!window.TSCIRCUIT_JSCDN_BASE_URL||(OGe({defaultFontURL:XgA("three","0.165.0","examples/fonts/ttf/kenpixel.ttf"),unicodeFontsURL:XgA("troika-three-text","0.52.5","unicode-fonts/")}),wuI=!0)}var p$A=g=>gA.useMemo(()=>{if(!g)return[];const A=new Fkt;return A.add(g),A.render(),A.getCircuitJson()},[g]),$qt=(g,A)=>{const I=g.pcb_component_id?A.find(e=>e.type==="pcb_component"&&e.pcb_component_id===g.pcb_component_id):void 0;return{pcbComponent:I,layer:g.layer??I?.layer??"top",isThroughHole:!!(I&&A.some(e=>e.type==="pcb_plated_hole"&&e.pcb_component_id===I.pcb_component_id))}},k$A=["translucent","opaque","hidden"],A7t=g=>k$A[(k$A.indexOf(g)+1)%k$A.length],uuI={boardBody:!0,topCopper:!0,bottomCopper:!0,keepout:!0,adhesive:!1,solderPaste:!1,topSilkscreen:!0,bottomSilkscreen:!0,topMask:!0,bottomMask:!0,throughHoleModels:!0,smtModels:!0,translucentModels:!0,modelsNotInPosFile:!1,modelsMarkedDNP:!1,modelBoundingBoxes:!1,threedAxis:!1,pcbNotes:!1,backgroundStart:!0,backgroundEnd:!0,enclosure:"translucent"},GuI=gA.createContext(void 0),g7t=({children:g})=>{const[A,I]=gA.useState(uuI),e=gA.useCallback((o,C)=>{I(Q=>({...Q,[o]:C}))},[]),t=gA.useCallback(()=>{I(uuI)},[]),B=gA.useMemo(()=>({visibility:A,setLayerVisibility:e,resetToDefaults:t}),[A,e,t]);return W.jsx(GuI.Provider,{value:B,children:g})},e5=()=>{const g=gA.useContext(GuI);if(!g)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return g},M$A=1.2;function muI(g){return gA.useMemo(()=>{if(!g)return M$A;try{return jB(g).pcb_board.list()[0]?.thickness??M$A}catch{return M$A}},[g])}var $gA={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:110,appearanceMenu:111},puI=({children:g,position:A,style:I})=>{const{camera:e,renderer:t}=SD(),B=gA.useRef(document.createElement("div")),[o,C]=gA.useState(null);return gA.useEffect(()=>{const Q=t?.domElement.parentNode;if(Q)return Q.style.position!=="relative"&&Q.style.position!=="absolute"&&(Q.style.position="relative"),Q.appendChild(B.current),C(ycg.createPortal(g,B.current)),()=>{Q.contains(B.current)&&Q.removeChild(B.current)}},[t,g]),zgA(()=>{if(!e||!B.current||!t)return;const Q=new oI(...A);Q.project(e);const i=t.domElement.getBoundingClientRect(),E=Math.round((Q.x+1)/2*i.width),n=Math.round((-Q.y+1)/2*i.height);B.current.style.position="absolute",B.current.style.left=`${E}px`,B.current.style.top=`${n}px`,B.current.style.pointerEvents="none",B.current.style.zIndex=$gA.htmlElements.toString(),I&&Object.assign(B.current.style,I)},[e,t,A,I]),o},I7t=ts(wdA()),kuI=gA.createContext(null),e7t=()=>{const g=gA.useContext(kuI);if(!g)throw new Error("useHover must be used within a HoverProvider");return g},t7t=({children:g})=>{const{camera:A,renderer:I}=SD(),[e,t]=gA.useState([]),B=gA.useMemo(()=>new QFg,[]),o=gA.useMemo(()=>new ct,[]),C=gA.useRef(e);C.current=e;const Q=gA.useRef(null),i=gA.useCallback(a=>{t(c=>[...c,a])},[]),E=gA.useCallback(a=>{if(Q.current){let c=!1,h=Q.current.object;for(;h;){if(h===a){c=!0;break}h=h.parent}c&&(Q.current.onUnhover(),Q.current=null)}t(c=>c.filter(h=>h.object!==a))},[]),n=gA.useCallback(a=>{let c=a;for(;c;){const h=C.current.find(l=>l.object===c);if(h)return h;c=c.parent}},[]),s=gA.useCallback(a=>{if(!I.domElement)return;const c=I.domElement.getBoundingClientRect();o.x=(a.clientX-c.left)/c.width*2-1,o.y=-((a.clientY-c.top)/c.height)*2+1,B.setFromCamera(o,A);const h=C.current.map(D=>D.object);if(h.length===0){Q.current&&(Q.current.onUnhover(),Q.current=null);return}const l=B.intersectObjects(h,!0);if(l.length>0){const D=l[0],d=n(D.object);if(d){const y={mousePosition:[D.point.x,D.point.y,D.point.z]};Q.current!==d?(Q.current?.onUnhover(),d.onHover(y),Q.current=d):d.onHover(y)}else Q.current&&(Q.current.onUnhover(),Q.current=null)}else Q.current&&(Q.current.onUnhover(),Q.current=null)},[A,I,B,o,n]);gA.useEffect(()=>{const a=I.domElement;return a.addEventListener("mousemove",s),()=>{a.removeEventListener("mousemove",s)}},[I,s]);const r=gA.useMemo(()=>({addHoverable:i,removeHoverable:E}),[i,E]);return W.jsx(kuI.Provider,{value:r,children:g})},B7t=({children:g,object:A,onHover:I,onUnhover:e,isHovered:t})=>{const{addHoverable:B,removeHoverable:o}=e7t();return gA.useEffect(()=>A?(B({object:A,onHover:I,onUnhover:e}),()=>{o(A)}):void 0,[A,I,e,B,o]),W.jsx(W.Fragment,{children:g})},AIA=B7t,ZM=(g,{castShadow:A=!0,receiveShadow:I=!0}={})=>{g.traverse(e=>{e instanceof FB&&(e.castShadow=A,e.receiveShadow=I)})},o7t=({positionOffset:g,footprint:A,rotationOffset:I,onHover:e,onUnhover:t,isHovered:B,scale:o,isTranslucent:C=!1})=>{const{rootObject:Q}=SD(),i=gA.useMemo(()=>{if(!A)return null;const{geometries:E}=$4t(A,I7t),n=new Nc;for(const s of E.flat(1/0)){const r=s.geom;if(!r||!r.polygons&&!r.sides)continue;const a=new tB(s.color);a.convertLinearToSRGB();const c={...r,color:[a.r,a.g,a.b]},h=q0I(c),l=new Ps({vertexColors:!0,side:yl,transparent:C,opacity:C?.5:1,depthWrite:!C}),D=new FB(h,l);D.renderOrder=C?2:1,ZM(D,{castShadow:!C,receiveShadow:!0}),n.add(D)}return n},[A,C]);return gA.useEffect(()=>{if(!(!i||!Q))return Q.add(i),()=>{Q.remove(i)}},[Q,i]),gA.useEffect(()=>{i&&(g&&i.position.fromArray(g),I&&i.rotation.fromArray(I),o!==void 0&&i.scale.setScalar(o))},[i,g?.[0],g?.[1],g?.[2],I?.[0],I?.[1],I?.[2],o]),gA.useEffect(()=>{i&&i.traverse(E=>{E instanceof FB&&E.material instanceof Ps&&(B?(E.material.emissive.setHex(255),E.material.emissiveIntensity=.2):E.material.emissiveIntensity=0)})},[B,i]),i?W.jsx(AIA,{isHovered:B,onHover:e,onUnhover:t,object:i}):null},MuI=new WeakMap,C7t=()=>{const g=new Hr;return g.name="fallback-environment-map",g.mapping=rEA,g},Q7t=g=>{if(!g)return null;const A=g,I=MuI.get(A);if(I)return I;let e;if(g instanceof ZEA){const t=new j4A(g);e=t.fromScene(GKt(),.04).texture,t.dispose()}else e=C7t();return MuI.set(A,e),e};function i7t(g){const A=new WG;let I=!1;g.updateWorldMatrix(!0,!1);const e=g.parent?g.parent.matrixWorld.clone().invert():new iQ;return g.traverse(t=>{if(t.updateWorldMatrix(!0,!1),t instanceof FB&&t.geometry&&(t.geometry.boundingBox||t.geometry.computeBoundingBox(),t.geometry.boundingBox)){const B=e.clone().multiply(t.matrixWorld),o=t.geometry.boundingBox.clone();o.applyMatrix4(B),I?A.union(o):(A.copy(o),I=!0)}}),I?A:null}function E7t(g){const A=i7t(g);return A?A.getSize(new oI):new oI}function n7t(g,A,I="contain_within_bounds"){if(!A)return[1,1,1];const e=E7t(g),t=[e.x>0?A[0]/e.x:1,e.y>0?A[1]/e.y:1,e.z>0?A[2]/e.z:1];if(I==="fill_bounds")return t;const B=Math.min(...t);return[B,B,B]}var S$A=({model:g,position:A,rotation:I,modelOffset:e=[0,0,0],modelRotation:t=[0,0,0],sourceCoordinateTransform:B,modelSize:o,modelFitMode:C="contain_within_bounds",scale:Q})=>{const{rootObject:i}=SD(),E=gA.useMemo(()=>new Nc,[]),n=gA.useMemo(()=>new Nc,[]),s=gA.useMemo(()=>new Nc,[]),r=gA.useMemo(()=>new Nc,[]);return gA.useEffect(()=>(E.add(n),()=>{E.remove(n)}),[E,n]),gA.useEffect(()=>(n.add(s),()=>{n.remove(s)}),[n,s]),gA.useEffect(()=>(s.add(r),()=>{s.remove(r)}),[s,r]),gA.useEffect(()=>{for(;r.children.length>0;){const a=r.children[0];if(!a)break;r.remove(a)}g&&r.add(g)},[r,g]),gA.useEffect(()=>{if(!B){r.matrixAutoUpdate=!0,r.position.set(0,0,0),r.rotation.set(0,0,0),r.scale.set(1,1,1),r.updateMatrix();return}r.matrixAutoUpdate=!1,r.matrix.copy(B),r.matrixWorldNeedsUpdate=!0},[r,B]),gA.useEffect(()=>{if(i)return i.add(E),()=>{i.remove(E)}},[i,E]),gA.useEffect(()=>{if(A?E.position.fromArray(A):E.position.set(0,0,0),I?E.rotation.fromArray(I):E.rotation.set(0,0,0),s.position.fromArray(e),s.rotation.fromArray(t),s.scale.setScalar(Q??1),!g){n.scale.set(1,1,1);return}n.scale.set(1,1,1),n.updateWorldMatrix(!0,!0);const a=n7t(s,o,C);n.scale.set(a[0],a[1],a[2])},[E,n,g,C,e,r,s,t,o,A,I,Q]),{boardTransformGroup:E}},SuI=1.25;function fuI({gltfUrl:g,position:A,rotation:I,modelOffset:e=[0,0,0],modelRotation:t=[0,0,0],sourceCoordinateTransform:B,modelSize:o,modelFitMode:C="contain_within_bounds",onHover:Q,onUnhover:i,isHovered:E,scale:n,isTranslucent:s=!1}){const{renderer:r}=SD(),[a,c]=gA.useState(null),[h,l]=gA.useState(null),{boardTransformGroup:D}=S$A({model:a,position:A,rotation:I,modelOffset:e,modelRotation:t,sourceCoordinateTransform:B,modelSize:o,modelFitMode:C,scale:n});if(gA.useEffect(()=>{if(!g)return;const d=new pKt;let y=!0;return d.load(g,w=>{if(!y)return;const u=w.scene;u.traverse(G=>{if(G instanceof FB&&G.material){const m=p=>{p.transparent=s,p.opacity=s?.5:1,p.depthWrite=!s,p.needsUpdate=!0};Array.isArray(G.material)?G.material.forEach(m):m(G.material),G.renderOrder=s?2:1}}),ZM(u,{castShadow:!s,receiveShadow:!0}),c(u)},void 0,w=>{if(!y)return;console.error(`An error happened loading ${g}`,w);const u=w instanceof Error?w:new Error(`Failed to load glTF model from ${g}`);l(u)}),()=>{y=!1}},[g,s]),gA.useEffect(()=>{if(!a||!r)return;const d=Q7t(r);if(!d)return;const y=[],w=u=>{u instanceof Ps&&(y.push({material:u,envMap:u.envMap??null,envMapIntensity:u.envMapIntensity??1}),u.envMap=d,(typeof u.envMapIntensity!="number"||u.envMapIntensity<SuI)&&(u.envMapIntensity=SuI),u.needsUpdate=!0)};return a.traverse(u=>{if(!(u instanceof FB))return;const G=u.material;Array.isArray(G)?G.forEach(w):G&&w(G)}),()=>{y.forEach(({material:u,envMap:G,envMapIntensity:m})=>{u.envMap=G,u.envMapIntensity=m,u.needsUpdate=!0})}},[a,r]),gA.useEffect(()=>{a&&a.traverse(d=>{if(!(d instanceof FB))return;const y=Array.isArray(d.material)?d.material:[d.material];for(const w of y)w instanceof Ps&&(E?(w.emissive.setHex(255),w.emissiveIntensity=.2):w.emissiveIntensity=0)})},[E,a]),h)throw h;return a?W.jsx(AIA,{isHovered:E,onHover:Q,onUnhover:i,object:D}):null}var s7t=ts(DuI()),a7t=ts(wdA()),r7t=({jscadPlan:g,positionOffset:A,rotationOffset:I,modelOffset:e=[0,0,0],modelRotation:t=[0,0,0],sourceCoordinateTransform:B,modelSize:o,modelFitMode:C="contain_within_bounds",onHover:Q,onUnhover:i,isHovered:E,scale:n,isTranslucent:s=!1})=>{const[r,a]=gA.useState(null);gA.useEffect(()=>{const l=(0,s7t.executeJscadOperations)(a7t.default,g);if(!l||!l.polygons&&!l.sides){a(null);return}const D=q0I(l),d=new Ps({vertexColors:!0,side:yl}),y=new FB(D,d);return a(y),()=>{D.dispose(),d.dispose()}},[g]),gA.useEffect(()=>{if(!r)return;const l=r.material;l.transparent=s,l.opacity=s?.5:1,l.depthWrite=!s,l.needsUpdate=!0,r.renderOrder=s?2:1,ZM(r,{castShadow:!s,receiveShadow:!0})},[r,s]);const c=r?.material,{boardTransformGroup:h}=S$A({model:r,position:A,rotation:I,modelOffset:e,modelRotation:t,sourceCoordinateTransform:B,modelSize:o,modelFitMode:C,scale:n});return gA.useEffect(()=>{if(c)if(E){const l=new tB(c.color.getHex());c.emissive.copy(l),c.emissive.setRGB(0,0,1),c.emissiveIntensity=.2}else c.emissiveIntensity=0},[E,c]),r?W.jsx(AIA,{isHovered:E,onHover:Q,onUnhover:i,object:h}):null};function c7t(g){return g.replace(/(DEF|USE)\s+([^\s]+)/g,(A,I,e)=>`${I} ${e.replace(/-/g,"_")}`)}async function h7t(g){const A=await fetch(g);if(!A.ok)throw new Error(`Failed to fetch "${g}": ${A.status} ${A.statusText}`);const I=await A.text();return new EPt().parse(c7t(I),g)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function l7t(g){const[A,I]=gA.useState(null);return gA.useEffect(()=>{if(!g)return;const e=g.replace(/&cachebust_origin=$/,""),t=window.TSCIRCUIT_OBJ_LOADER_CACHE;let B=!1;async function o(){try{if(e.endsWith(".wrl"))return await h7t(e);const Q=await fetch(e);if(!Q.ok)throw new Error(`Failed to fetch "${e}": ${Q.status} ${Q.statusText}`);const i=await Q.text(),E=i.match(/newmtl[\s\S]*?endmtl/g),n=new dPt;if(E?.length){const s=E.join(`
|
|
5319
|
-
`).replace(/^d\s+0\./gm,"d 1."),r=i.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),a=new CPt;a.setMaterialOptions({invertTrProperty:!0});const c=a.parse(s,"embedded.mtl");return n.setMaterials(c),n.parse(r)}return n.parse(i.replace(/^mtllib.*/gm,""))}catch(Q){return Q}}function C(){if(t.has(e)){const i=t.get(e);return i.result?Promise.resolve(i.result.clone()):i.promise.then(E=>E instanceof Error?E:E.clone())}const Q=o().then(i=>(i instanceof Error||t.set(e,{...t.get(e),result:i}),i));return t.set(e,{promise:Q,result:null}),Q}return C().then(Q=>{B||I(Q)}).catch(Q=>{console.error(Q)}),()=>{B=!0}},[g]),A}function D7t({url:g,position:A,rotation:I,modelOffset:e=[0,0,0],modelRotation:t=[0,0,0],sourceCoordinateTransform:B,modelSize:o,modelFitMode:C="contain_within_bounds",onHover:Q,onUnhover:i,isHovered:E,scale:n,isTranslucent:s=!1}){const r=l7t(g),a=gA.useMemo(()=>{if(r&&!(r instanceof Error))return r.traverse(l=>{if(l instanceof FB&&l.material){const D=d=>{d.transparent=s,d.opacity=s?.5:1,d.depthWrite=!s,d.needsUpdate=!0};Array.isArray(l.material)?l.material.forEach(D):D(l.material),l.renderOrder=s?2:1}}),ZM(r,{castShadow:!s,receiveShadow:!0}),r;const h=new FB(new Jp(.5,.5,.5),new Ps({transparent:!0,color:"red",opacity:.25}));return ZM(h,{castShadow:!1,receiveShadow:!0}),h},[r,s]),{boardTransformGroup:c}=S$A({model:a,position:Array.isArray(A)?A:A?[A.x,A.y,A.z]:void 0,rotation:Array.isArray(I)?I:I?[I.x,I.y,I.z]:void 0,modelOffset:e,modelRotation:t,sourceCoordinateTransform:B,modelSize:o,modelFitMode:C,scale:n});if(r instanceof Error)throw r;return W.jsx(AIA,{isHovered:E,onHover:Q,onUnhover:i,object:c})}var d7t=new tB(.82,.82,.82),RuI=g=>new Ps({color:g?new tB(g[0],g[1],g[2]):d7t});function y7t(g,A){const I=RuI(A.color),e=A.brep_faces??[];if(e.length===0)return[I];const t=e.length>1?[...e].sort((n,s)=>n.first-s.first):e,B=[I],o=new Map,C=A.index.array.length/3;let Q=0,i=0;const E=n=>{if(!n)return 0;const s=n.join(","),r=o.get(s);if(r!==void 0)return r;const a=B.length;return B.push(RuI(n)),o.set(s,a),a};for(;Q<C;){const n=t[i];let s=C,r=0;n&&(Q<n.first?s=n.first:(s=n.last+1,r=E(n.color),i+=1)),s>Q&&g.addGroup(Q*3,(s-Q)*3,r),Q=s}return B}function w7t(g){const A=new Nc;for(const I of g){const e=I.attributes.position?.array??[],t=I.index?.array??[];if(!e.length||!t.length)continue;const B=new Jn;B.setAttribute("position",new To(e,3));const o=I.attributes.normal?.array??[];o.length?B.setAttribute("normal",new To(o,3)):B.computeVertexNormals(),B.setIndex(t),B.clearGroups();const C=y7t(B,I),Q=new FB(B,C.length>1?C:C[0]);Q.name=I.name,A.add(Q)}return A}var xdA;function u7t(g){if(typeof g=="function")return g;if(g&&typeof g=="object"&&"default"in g&&typeof g.default=="function")return g.default;throw new Error("Unable to resolve occt-import-js factory export")}async function G7t(){return xdA||(xdA=(async()=>{const g=await import(XgA("occt-import-js","0.0.23","+esm"));return u7t(g)({locateFile:I=>XgA("occt-import-js","0.0.23",`dist/${I}`)})})().catch(g=>{throw xdA=void 0,g})),xdA}async function m7t(g){const A=await fetch(g);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const I=await A.arrayBuffer(),t=(await G7t()).ReadStepFile(new Uint8Array(I),null);if(!t.success||!t.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const B=w7t(t.meshes),o=new XzA;return await new Promise((Q,i)=>{o.parse(B,E=>{E instanceof ArrayBuffer?Q(E):i(new Error("GLTFExporter did not return binary output"))},E=>{i(E)},{binary:!0})})}var NuI="step-glb-cache:v2:";function p7t(g){const A=new Uint8Array(g),I=32768;let e="";for(let t=0;t<A.length;t+=I){const B=A.subarray(t,t+I);e+=String.fromCharCode(...B)}return btoa(e)}function k7t(g){const A=atob(g),I=new Uint8Array(A.length);for(let e=0;e<A.length;e+=1)I[e]=A.charCodeAt(e);return I.buffer}function M7t(g){try{const A=localStorage.getItem(`${NuI}${g}`);return A?k7t(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function xuI(g,A){try{const I=p7t(A);localStorage.setItem(`${NuI}${g}`,I)}catch(I){console.warn("Failed to write STEP GLB cache",I)}}function S7t(){const g=globalThis;return g.stepUrlToGltfModelConversions||(g.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),g.stepUrlToGltfModelConversions}var f7t=({stepUrl:g,position:A,rotation:I,modelOffset:e,modelRotation:t,sourceCoordinateTransform:B,modelSize:o,modelFitMode:C,scale:Q,onHover:i,onUnhover:E,isHovered:n,isTranslucent:s})=>{const[r,a]=gA.useState(null);return gA.useEffect(()=>{let c=!0,h=null,l=!0;const D=S7t(),d=M7t(g);if(d){const u={arrayBuffer:d,blobUrl:URL.createObjectURL(new Blob([d],{type:"model/gltf-binary"}))};return D.completed.set(g,u),h=u.blobUrl,l=!1,a(u.blobUrl),()=>{c=!1,h&&l&&URL.revokeObjectURL(h)}}const y=D.completed.get(g);if(y)return h=y.blobUrl,l=!1,a(y.blobUrl),xuI(g,y.arrayBuffer),()=>{c=!1,h&&l&&URL.revokeObjectURL(h)};let w=D.inProgress.get(g);return w||(w=m7t(g).then(u=>{const G={arrayBuffer:u,blobUrl:URL.createObjectURL(new Blob([u],{type:"model/gltf-binary"}))};return D.completed.set(g,G),D.inProgress.delete(g),G}).catch(u=>{throw D.inProgress.delete(g),u}),D.inProgress.set(g,w)),w.then(u=>{c&&(h=u.blobUrl,l=!1,a(u.blobUrl),xuI(g,u.arrayBuffer))}).catch(u=>{console.error("Failed to convert STEP file to GLB",u),c&&a(null)}),()=>{c=!1,h&&l&&URL.revokeObjectURL(h)}},[g]),r?W.jsx(fuI,{gltfUrl:r,position:A,rotation:I,modelOffset:e,modelRotation:t,sourceCoordinateTransform:B,modelSize:o,modelFitMode:C,scale:Q,onHover:i,onUnhover:E,isHovered:n,isTranslucent:s}):null};function FdA(g,A){let{x:I,y:e,z:t}=g;if(A.axisMapping){const B={x:I,y:e,z:t};A.axisMapping.x&&(I=f$A(B,A.axisMapping.x)),A.axisMapping.y&&(e=f$A(B,A.axisMapping.y)),A.axisMapping.z&&(t=f$A(B,A.axisMapping.z))}if(I*=A.flipX??1,e*=A.flipY??1,t*=A.flipZ??1,A.rotation){if(A.rotation.x){const B=A.rotation.x*Math.PI/180,o=Math.cos(B),C=Math.sin(B),Q=e*o-t*C,i=e*C+t*o;e=Q,t=i}if(A.rotation.y){const B=A.rotation.y*Math.PI/180,o=Math.cos(B),C=Math.sin(B),Q=I*o+t*C,i=-I*C+t*o;I=Q,t=i}if(A.rotation.z){const B=A.rotation.z*Math.PI/180,o=Math.cos(B),C=Math.sin(B),Q=I*o-e*C,i=I*C+e*o;I=Q,e=i}}return{x:I,y:e,z:t}}function f$A(g,A){switch(A){case"x":return g.x;case"y":return g.y;case"z":return g.z;case"-x":return-g.x;case"-y":return-g.y;case"-z":return-g.z;default:return 0}}var R$A={STEP_INVERTED:{axisMapping:{x:"-x",y:"z",z:"-y"}},Z_UP_TO_Y_UP_USB_FIX:{axisMapping:{x:"x",y:"-z",z:"y"},flipZ:-1},FOOTPRINTER_MODEL_TRANSFORM:{axisMapping:{x:"x",y:"-z",z:"y"},flipX:-1,rotation:{x:180,y:180}}};function R7t(g,A){if(A.coordinateTransform)return A.coordinateTransform;if(!A.usingGlbCoordinates){if(A.hasFootprinterModel)return R$A.FOOTPRINTER_MODEL_TRANSFORM;if(!A.usingObjFormat)return A.usingStepFormat?R$A.STEP_INVERTED:R$A.Z_UP_TO_Y_UP_USB_FIX}}function gIA(g,A){return R7t(g,{usingGlbCoordinates:A==="gltf"||A==="glb"||A==="jscad",usingObjFormat:A==="obj"||A==="wrl",usingStepFormat:A==="step",hasFootprinterModel:A==="footprinter"})}function UdA(g){if(!g)return;const A=FdA({x:1,y:0,z:0},g),I=FdA({x:0,y:1,z:0},g),e=FdA({x:0,y:0,z:1},g);return new iQ().makeBasis(new oI(A.x,A.y,A.z),new oI(I.x,I.y,I.z),new oI(e.x,e.y,e.z))}function C3(g){return g*Math.PI/180}function N7t(g){if(g==="z+")return[0,0,0];switch(g){case"x+":return[0,C3(-90),0];case"x-":return[0,C3(90),0];case"y+":return[C3(90),0,0];case"y-":return[C3(-90),0,0];case"z-":return[C3(180),0,0];default:return[0,0,0]}}function x7t(g,A,I){if(!g.position)return;let e=g.position.z;return!g.is_on_folded_board&&g.pcb_component_id&&A==="bottom"&&g.position.z>=0&&(e=-(g.position.z+I)),[g.position.x,g.position.y,e]}function F7t(g,A){return g.rotation?[C3(g.rotation.x),C3(g.rotation.y),C3(g.rotation.z)]:A==="bottom"?[Math.PI,0,0]:[0,0,0]}function U7t(g,A){const I=new oI(g.x,g.y,g.z),e=new VG(A[0],A[1],A[2],"XYZ");return I.applyEuler(e),[I.x,I.y,I.z]}function J7t(g,A,I){if(!g.model_origin_position)return[0,0,0];const e=A?FdA(g.model_origin_position,A):g.model_origin_position;return U7t(e,I)}function K7t(g,A){const I=x7t(g,A.layer,A.pcbThickness),e=F7t(g,A.layer),t=gIA(g,A.modelType),B=N7t(g.model_board_normal_direction??"z+"),o=J7t(g,t,B);return{position:I,rotation:e,modelPosition:[-o[0],-o[1],-o[2]],modelRotation:B,scale:g.model_unit_to_mm_scale_factor??void 0,fitMode:g.model_object_fit??"contain_within_bounds",size:g.size?[g.size.x,g.size.y,g.size.z]:void 0}}var P7t=g=>g.model_glb_url||g.model_gltf_url?g.model_glb_url?"glb":"gltf":g.model_obj_url||g.model_wrl_url||g.model_stl_url?g.model_wrl_url?"wrl":g.model_stl_url?"stl":"obj":g.model_jscad?"jscad":g.footprinter_string?"footprinter":g.model_step_url?"step":"unknown",L7t=g=>g==="step"?"glb":g,Y7t=(g,A)=>{if(!g.pcb_component_id||!g.model_jscad||g.model_origin_alignment!=="bottom_center_of_component")return!1;const I=A.find(e=>e.type==="pcb_component"&&e.pcb_component_id===g.pcb_component_id);return!!(I&&I.do_not_place&&I.is_allowed_to_be_off_board&&I.obstructs_within_bounds===!1)},_7t=(g,A)=>{if(g)return A?A(g):g},b7t=(...g)=>g,N$A=class extends nC.Component{constructor(g){super(g),this.state={hasError:!1,error:null}}static getDerivedStateFromError(g){return{hasError:!0,error:g}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},H7t=({error:g,onError:A})=>(gA.useEffect(()=>{A(g)},[g,A]),null),FuI=({cad_component:g,circuitJson:A,resolveStaticAsset:I})=>{const e=muI(A),[t,B]=gA.useState(!1),{visibility:o}=e5(),[C,Q]=gA.useState(null),i=gA.useCallback(H=>{H?.mousePosition?(B(!0),Q(H.mousePosition)):(B(!1),Q(null))},[]),E=gA.useCallback(()=>{B(!1),Q(null)},[]),n=gA.useMemo(()=>jB(A).source_component.getUsing({source_component_id:g.source_component_id})?.name,[A,g.source_component_id]),{pcbComponent:s,layer:r,isThroughHole:a}=gA.useMemo(()=>$qt(g,A),[g,A]),c=gA.useCallback(H=>_7t(H,I),[I]),h=c(g.model_wrl_url??g.model_stl_url??g.model_obj_url),l=c(g.model_glb_url??g.model_gltf_url),D=c(g.model_step_url),[d,y]=gA.useState(0),[w,u]=gA.useState(null);gA.useEffect(()=>{y(0),u(null)},[g.cad_component_id,h,l,D]);const G=gA.useMemo(()=>Y7t(g,A),[g,A]),m=G?o.enclosure==="translucent":!!g.show_as_translucent_model,p=P7t(g),k=L7t(p),S=g.model_glb_url?"glb":"gltf",R=g.model_wrl_url?"wrl":g.model_stl_url?"stl":"obj",F=gA.useMemo(()=>K7t(g,{layer:r,pcbThickness:e,modelType:k}),[g,r,e,k]),N=b7t(...F.rotation),U=F.position,P=gA.useMemo(()=>{const H=[];return l&&H.push(W.jsx(fuI,{gltfUrl:l,position:U,rotation:N,modelOffset:F.modelPosition,modelRotation:F.modelRotation,sourceCoordinateTransform:UdA(gIA(g,S)),scale:F.scale,modelSize:F.size,modelFitMode:F.fitMode,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m},`${g.cad_component_id}-gltf-${l}`)),h&&H.push(W.jsx(D7t,{url:h,position:U,rotation:N,modelOffset:F.modelPosition,modelRotation:F.modelRotation,sourceCoordinateTransform:UdA(gIA(g,R)),scale:F.scale,modelSize:F.size,modelFitMode:F.fitMode,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m},`${g.cad_component_id}-mixed-${h}`)),D&&!g.model_jscad&&!g.footprinter_string&&H.push(W.jsx(f7t,{stepUrl:D,position:U,rotation:N,modelOffset:F.modelPosition,modelRotation:F.modelRotation,sourceCoordinateTransform:UdA(gIA(g,k)),scale:F.scale,modelSize:F.size,modelFitMode:F.fitMode,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m},`${g.cad_component_id}-step-${D}`)),H},[U,g.cad_component_id,g.footprinter_string,g.model_jscad,m,l,S,i,E,t,R,F.modelPosition,F.modelRotation,F.scale,F.fitMode,F.size,k,N,D,h]);let b=null;if(P.length>0){if(d>=P.length){if(w)throw w;return null}b=W.jsx(N$A,{fallback:({error:H})=>W.jsx(H7t,{error:H,onError:q=>{u(q),y(j=>Math.max(j,d+1))}}),children:P[d]},`${g.cad_component_id}-fallback-${d}`)}else g.model_jscad?b=W.jsx(r7t,{jscadPlan:g.model_jscad,positionOffset:U,rotationOffset:N,modelOffset:F.modelPosition,modelRotation:F.modelRotation,sourceCoordinateTransform:UdA(gIA(g,"jscad")),scale:F.scale,modelSize:F.size,modelFitMode:F.fitMode,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m},g.cad_component_id):g.footprinter_string&&(b=W.jsx(o7t,{positionOffset:U,rotationOffset:N,footprint:g.footprinter_string,scale:F.scale,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m}));if(G){if(o.enclosure==="hidden")return null}else if(g.show_as_translucent_model){if(!o.translucentModels)return null}else if(s&&(a&&!o.throughHoleModels||!a&&!o.smtModels))return null;return W.jsxs(W.Fragment,{children:[W.jsx(Wqt,{cadComponent:g,children:b}),t&&C?W.jsx(puI,{position:C,style:{fontFamily:"sans-serif",transform:"translate3d(1rem, 1rem, 0)",backgroundColor:"white",padding:"5px",borderRadius:"3px",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:n??"<unknown>"}):null]})},UuI={version:"0.0.625"},JuI="cadViewerLightingEnabled",v7t=()=>typeof window>"u"?!0:window.localStorage.getItem(JuI)!=="false",KuI=gA.createContext(void 0),q7t=({children:g})=>{const[A,I]=gA.useState(!1),[e,t]=gA.useState(!1),[B,o]=gA.useState(v7t);gA.useEffect(()=>{window.localStorage.setItem(JuI,B?"true":"false")},[B]);const C=gA.useMemo(()=>({darkBackgroundEnabled:A,setDarkBackgroundEnabled:I,gridEnabled:e,setGridEnabled:t,lightingEnabled:B,setLightingEnabled:o}),[A,e,B]);return W.jsx(KuI.Provider,{value:C,children:g})},x$A=()=>{const g=gA.useContext(KuI);if(!g)throw new Error("useAppearance must be used within an AppearanceProvider");return g},PuI="cadViewerCameraStateSession";function LuI(g){return g?`${PuI}:${g}`:PuI}function T7t({camera:g,controls:A,cameraSessionScope:I}){try{const e={position:g.position.toArray(),quaternion:g.quaternion.toArray(),up:g.up.toArray(),fov:g instanceof $h?g.fov:50,target:A.target.toArray()};sessionStorage.setItem(LuI(I),JSON.stringify(e))}catch(e){console.warn("Failed to save camera:",e)}}function Z7t({camera:g,controls:A,cameraSessionScope:I}){try{const e=sessionStorage.getItem(LuI(I));if(!e)return!1;const t=JSON.parse(e);return g.position.fromArray(t.position),g.quaternion.fromArray(t.quaternion),g.up.fromArray(t.up),g instanceof $h&&(g.fov=t.fov,g.updateProjectionMatrix()),A.target.fromArray(t.target),A.update(),g.updateMatrixWorld(),!0}catch(e){return console.warn("Failed to restore camera:",e),!1}}function YuI(g){return"controls"in g?g:{controls:g}}var _uI=(g,A)=>{const{controls:I,cameraSessionScope:e}=YuI(A);T7t({camera:g,controls:I,cameraSessionScope:e})},F$A=(g,A)=>{const{controls:I,cameraSessionScope:e}=YuI(A);return Z7t({camera:g,controls:I,cameraSessionScope:e})},buI=gA.createContext(void 0),O7t=({children:g,defaultTarget:A,initialCameraPosition:I,initialCameraType:e})=>{const t=gA.useRef(null),B=gA.useRef(null),[o,C]=gA.useState(null),[Q,i]=gA.useState(e??"perspective"),[E,n]=gA.useState(I??null),[s,r]=gA.useState(new VG(0,0,0)),a=gA.useMemo(()=>{const[D,d,y]=I??[5,-5,5],w=Math.hypot(D-A.x,d-A.y,y-A.z);return w>0?w:5},[I,A]),c=gA.useCallback(D=>{const d=[A.x,A.y,A.z],y=B.current,w=t.current;let u=a;switch(y&&w&&(u=y.position.distanceTo(w.target)),D){case"Top Center Angled":{const G=u/Math.sqrt(2);return{position:[A.x,A.y-G,A.z+G],target:d,up:[0,0,1]}}case"Top Down":return{position:[A.x,A.y,A.z+u],target:d,up:[0,0,1]};case"Top Left Corner":return{position:[A.x-u*.6,A.y-u*.6,A.z+u*.6],target:d,up:[0,0,1]};case"Top Right Corner":return{position:[A.x+u*.6,A.y-u*.6,A.z+u*.6],target:d,up:[0,0,1]};case"Left Sideview":return{position:[A.x-u,A.y,A.z],target:d,up:[0,0,1]};case"Right Sideview":return{position:[A.x+u,A.y,A.z],target:d,up:[0,0,1]};case"Front":return{position:[A.x,A.y-u,A.z],target:d,up:[0,0,1]};default:return null}},[a,A,B,t]),h=gA.useCallback(D=>{t.current=D},[]),l=gA.useMemo(()=>({controlsRef:t,mainCameraRef:B,defaultTarget:A,baseDistance:a,controller:o,setController:C,getPresetConfig:c,handleControlsChange:h,cameraType:Q,setCameraType:i,cameraPosition:E,setCameraPosition:n,cameraRotation:s,setCameraRotation:r,saveCameraToSession:_uI,loadCameraFromSession:F$A}),[A,a,o,c,h,Q,E,s]);return W.jsx(buI.Provider,{value:l,children:g})},gJ=()=>{const g=gA.useContext(buI);if(!g)throw new Error("useCameraController must be used within a CameraControllerProvider");return g},W7t=g=>g<.5?4*g*g*g:1-Math.pow(-2*g+2,3)/2,V7t=()=>{const{controlsRef:g,mainCameraRef:A,defaultTarget:I,setController:e,getPresetConfig:t}=gJ(),B=gA.useRef(null),o=gA.useRef(new OG),C=gA.useRef(new oI),Q=gA.useRef(new oI),i=gA.useRef(new OG),E=gA.useRef(new OG),n=gA.useRef(new Ks),s=gA.useRef(new Ks),r=gA.useCallback(({position:c,target:h,up:l,durationMs:D=600})=>{if(!A.current)return;const d=g.current?.target??I,y=new oI(c[0],c[1],c[2]),w=h?new oI(h[0],h[1],h[2]):I.clone(),u=new oI(...l??[0,0,1]).normalize(),G=s.current;G.position.copy(y),G.up.copy(u),G.lookAt(w);const m=G.quaternion.clone(),p=A.current.quaternion.clone(),k=A.current.position.clone(),S=d.clone(),R=n.current;R.up.set(0,0,1),R.position.copy(k),R.lookAt(S);const F=R.quaternion.clone();R.up.set(0,0,1),R.position.copy(y),R.lookAt(w);const N=R.quaternion.clone(),U=F.clone().invert().multiply(p).normalize(),P=N.clone().invert().multiply(m).normalize();B.current={fromPosition:k,toPosition:y,fromTarget:S,toTarget:w,toQuaternion:m,rollFrom:U,rollTo:P,startTime:performance.now(),duration:D}},[A,g,I]),a=gA.useCallback(c=>{if(c==="Custom")return;const h=t(c);h&&r(h)},[r,t]);return gA.useEffect(()=>A.current?(e({animateTo:r,animateToPreset:a}),()=>{e(null)}):void 0,[r,a,A,e]),zgA(()=>{if(!A.current||!B.current)return;const{fromPosition:c,toPosition:h,fromTarget:l,toTarget:D,toQuaternion:d,rollFrom:y,rollTo:w,startTime:u,duration:G}=B.current,m=performance.now()-u,p=G<=0?1:Math.min(m/G,1),k=W7t(p);A.current.position.lerpVectors(c,h,k);const S=C.current;S.copy(l).lerp(D,k);const R=n.current;R.up.set(0,0,1),R.position.copy(A.current.position),R.lookAt(S);const F=o.current;F.copy(R.quaternion);const N=i.current;N.copy(y);const U=E.current;U.copy(w),y.dot(w)<0&&(U.x*=-1,U.y*=-1,U.z*=-1,U.w*=-1),U.normalize(),N.slerp(U,k),A.current.quaternion.copy(F).multiply(N).normalize();const P=Q.current;P.set(0,1,0).applyQuaternion(A.current.quaternion).normalize(),A.current.up.copy(P),g.current?.target.copy(S),A.current.updateMatrixWorld(),g.current?.update(),p>=1&&(A.current.position.copy(h),A.current.quaternion.copy(d),A.current.up.set(0,0,1),A.current.updateMatrixWorld(),g.current?.target.copy(D),g.current?.update(),B.current=null)}),null},j7t=Symbol("camera-session-not-restored"),z7t=({cameraSessionScope:g}={})=>{const{controlsRef:A}=gJ(),I=gA.useRef(null),e=gA.useRef(j7t),t=gA.useRef(null);gA.useEffect(()=>()=>{t.current!==null&&(clearTimeout(t.current),t.current=null)},[g]);const B=gA.useCallback(C=>{if(I.current=C,e.current!==g&&A.current){const Q=F$A(C,{controls:A.current,cameraSessionScope:g});if(e.current=g,Q)return}},[g,A]),o=gA.useCallback(()=>{if(!(!I.current||!A.current)){if(e.current!==g){const C=F$A(I.current,{controls:A.current,cameraSessionScope:g});if(e.current=g,C)return}t.current!==null&&clearTimeout(t.current),t.current=setTimeout(()=>{I.current&&A.current&&_uI(I.current,{controls:A.current,cameraSessionScope:g})},150)}},[g,A]);return{handleCameraCreated:B,handleControlsChange:o}};function X7t(g){g.querySelectorAll("canvas").forEach(A=>A.remove())}var $7t=g=>{g.outputColorSpace=Fp,g.toneMapping=MNg,g.toneMappingExposure=1,g.shadowMap.enabled=!0,g.shadowMap.type=GNg},ATt=gA.forwardRef(({children:g,scene:A,camera:I,style:e,onCreated:t},B)=>{const{cameraType:o}=gJ(),C=gA.useRef(null),[Q,i]=gA.useState(null),E=gA.useRef([]),n=gA.useRef(void 0);n.current=t;const s=gA.useRef(null),r=gA.useCallback(l=>{E.current.push(l)},[]),a=gA.useCallback(l=>{E.current=E.current.filter(D=>D!==l)},[]),c=gA.useMemo(()=>new pY,[]);A?.up&&c.up.set(A.up.x,A.up.y,A.up.z);const h=gA.useRef(new Ks);return gA.useImperativeHandle(B,()=>h.current),gA.useEffect(()=>{if(!C.current)return;X7t(C.current);const l=new ZEA({antialias:!0,alpha:!0});$7t(l),l.setSize(C.current.clientWidth,C.current.clientHeight),l.setPixelRatio(window.devicePixelRatio),C.current.appendChild(l.domElement);const D=C.current.clientWidth/C.current.clientHeight,d=o==="perspective"?new $h(75,D,.1,1e3):new XH(-10*D,10*D,10,-10,-1e3,1e3);s.current?(d.position.copy(s.current.position),d.quaternion.copy(s.current.quaternion),d.up.copy(s.current.up)):(I?.up&&d.up.set(I.up[0],I.up[1],I.up[2]),I?.position&&d.position.set(I.position[0],I.position[1],I.position[2]),d.lookAt(0,0,0)),c.add(h.current),window.__TSCIRCUIT_THREE_OBJECT=h.current,i({scene:c,camera:d,renderer:l,rootObject:h.current,addFrameListener:r,removeFrameListener:a}),n.current?.({camera:d,renderer:l});let y;const w=new oGe;let u=!0;const G=new IntersectionObserver(([k])=>{u=k?.isIntersecting??!1,u&&p()});G.observe(C.current);const m=()=>{if(y=requestAnimationFrame(m),!u)return;const k=w.getElapsedTime(),S=w.getDelta();E.current.forEach(R=>R(k,S)),l.render(c,d)};m();const p=()=>{if(C.current?.clientWidth&&C.current.clientHeight){const k=C.current.clientWidth/C.current.clientHeight;d instanceof $h?d.aspect=k:d instanceof XH&&(d.left=-10*k,d.right=10*k,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),l.setSize(C.current.clientWidth,C.current.clientHeight)}};return window.addEventListener("resize",p),()=>{s.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",p),cancelAnimationFrame(y),G.disconnect(),C.current&&l.domElement&&C.current.removeChild(l.domElement),l.dispose(),c.remove(h.current),window.__TSCIRCUIT_THREE_OBJECT===h.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[c,r,a,o]),W.jsx("div",{ref:C,style:{width:"100%",height:"100%",...e},children:Q&&W.jsx(G$A.Provider,{value:Q,children:W.jsx(t7t,{children:g})})})}),gTt=`
|
|
5319
|
+
`).replace(/^d\s+0\./gm,"d 1."),r=i.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),a=new CPt;a.setMaterialOptions({invertTrProperty:!0});const c=a.parse(s,"embedded.mtl");return n.setMaterials(c),n.parse(r)}return n.parse(i.replace(/^mtllib.*/gm,""))}catch(Q){return Q}}function C(){if(t.has(e)){const i=t.get(e);return i.result?Promise.resolve(i.result.clone()):i.promise.then(E=>E instanceof Error?E:E.clone())}const Q=o().then(i=>(i instanceof Error||t.set(e,{...t.get(e),result:i}),i));return t.set(e,{promise:Q,result:null}),Q}return C().then(Q=>{B||I(Q)}).catch(Q=>{console.error(Q)}),()=>{B=!0}},[g]),A}function D7t({url:g,position:A,rotation:I,modelOffset:e=[0,0,0],modelRotation:t=[0,0,0],sourceCoordinateTransform:B,modelSize:o,modelFitMode:C="contain_within_bounds",onHover:Q,onUnhover:i,isHovered:E,scale:n,isTranslucent:s=!1}){const r=l7t(g),a=gA.useMemo(()=>{if(r&&!(r instanceof Error))return r.traverse(l=>{if(l instanceof FB&&l.material){const D=d=>{d.transparent=s,d.opacity=s?.5:1,d.depthWrite=!s,d.needsUpdate=!0};Array.isArray(l.material)?l.material.forEach(D):D(l.material),l.renderOrder=s?2:1}}),ZM(r,{castShadow:!s,receiveShadow:!0}),r;const h=new FB(new Jp(.5,.5,.5),new Ps({transparent:!0,color:"red",opacity:.25}));return ZM(h,{castShadow:!1,receiveShadow:!0}),h},[r,s]),{boardTransformGroup:c}=S$A({model:a,position:Array.isArray(A)?A:A?[A.x,A.y,A.z]:void 0,rotation:Array.isArray(I)?I:I?[I.x,I.y,I.z]:void 0,modelOffset:e,modelRotation:t,sourceCoordinateTransform:B,modelSize:o,modelFitMode:C,scale:n});if(r instanceof Error)throw r;return W.jsx(AIA,{isHovered:E,onHover:Q,onUnhover:i,object:c})}var d7t=new tB(.82,.82,.82),RuI=g=>new Ps({color:g?new tB(g[0],g[1],g[2]):d7t});function y7t(g,A){const I=RuI(A.color),e=A.brep_faces??[];if(e.length===0)return[I];const t=e.length>1?[...e].sort((n,s)=>n.first-s.first):e,B=[I],o=new Map,C=A.index.array.length/3;let Q=0,i=0;const E=n=>{if(!n)return 0;const s=n.join(","),r=o.get(s);if(r!==void 0)return r;const a=B.length;return B.push(RuI(n)),o.set(s,a),a};for(;Q<C;){const n=t[i];let s=C,r=0;n&&(Q<n.first?s=n.first:(s=n.last+1,r=E(n.color),i+=1)),s>Q&&g.addGroup(Q*3,(s-Q)*3,r),Q=s}return B}function w7t(g){const A=new Nc;for(const I of g){const e=I.attributes.position?.array??[],t=I.index?.array??[];if(!e.length||!t.length)continue;const B=new Jn;B.setAttribute("position",new To(e,3));const o=I.attributes.normal?.array??[];o.length?B.setAttribute("normal",new To(o,3)):B.computeVertexNormals(),B.setIndex(t),B.clearGroups();const C=y7t(B,I),Q=new FB(B,C.length>1?C:C[0]);Q.name=I.name,A.add(Q)}return A}var xdA;function u7t(g){if(typeof g=="function")return g;if(g&&typeof g=="object"&&"default"in g&&typeof g.default=="function")return g.default;throw new Error("Unable to resolve occt-import-js factory export")}async function G7t(){return xdA||(xdA=(async()=>{const g=await import(XgA("occt-import-js","0.0.23","+esm"));return u7t(g)({locateFile:I=>XgA("occt-import-js","0.0.23",`dist/${I}`)})})().catch(g=>{throw xdA=void 0,g})),xdA}async function m7t(g){const A=await fetch(g);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const I=await A.arrayBuffer(),t=(await G7t()).ReadStepFile(new Uint8Array(I),null);if(!t.success||!t.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const B=w7t(t.meshes),o=new XzA;return await new Promise((Q,i)=>{o.parse(B,E=>{E instanceof ArrayBuffer?Q(E):i(new Error("GLTFExporter did not return binary output"))},E=>{i(E)},{binary:!0})})}var NuI="step-glb-cache:v2:";function p7t(g){const A=new Uint8Array(g),I=32768;let e="";for(let t=0;t<A.length;t+=I){const B=A.subarray(t,t+I);e+=String.fromCharCode(...B)}return btoa(e)}function k7t(g){const A=atob(g),I=new Uint8Array(A.length);for(let e=0;e<A.length;e+=1)I[e]=A.charCodeAt(e);return I.buffer}function M7t(g){try{const A=localStorage.getItem(`${NuI}${g}`);return A?k7t(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function xuI(g,A){try{const I=p7t(A);localStorage.setItem(`${NuI}${g}`,I)}catch(I){console.warn("Failed to write STEP GLB cache",I)}}function S7t(){const g=globalThis;return g.stepUrlToGltfModelConversions||(g.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),g.stepUrlToGltfModelConversions}var f7t=({stepUrl:g,position:A,rotation:I,modelOffset:e,modelRotation:t,sourceCoordinateTransform:B,modelSize:o,modelFitMode:C,scale:Q,onHover:i,onUnhover:E,isHovered:n,isTranslucent:s})=>{const[r,a]=gA.useState(null);return gA.useEffect(()=>{let c=!0,h=null,l=!0;const D=S7t(),d=M7t(g);if(d){const u={arrayBuffer:d,blobUrl:URL.createObjectURL(new Blob([d],{type:"model/gltf-binary"}))};return D.completed.set(g,u),h=u.blobUrl,l=!1,a(u.blobUrl),()=>{c=!1,h&&l&&URL.revokeObjectURL(h)}}const y=D.completed.get(g);if(y)return h=y.blobUrl,l=!1,a(y.blobUrl),xuI(g,y.arrayBuffer),()=>{c=!1,h&&l&&URL.revokeObjectURL(h)};let w=D.inProgress.get(g);return w||(w=m7t(g).then(u=>{const G={arrayBuffer:u,blobUrl:URL.createObjectURL(new Blob([u],{type:"model/gltf-binary"}))};return D.completed.set(g,G),D.inProgress.delete(g),G}).catch(u=>{throw D.inProgress.delete(g),u}),D.inProgress.set(g,w)),w.then(u=>{c&&(h=u.blobUrl,l=!1,a(u.blobUrl),xuI(g,u.arrayBuffer))}).catch(u=>{console.error("Failed to convert STEP file to GLB",u),c&&a(null)}),()=>{c=!1,h&&l&&URL.revokeObjectURL(h)}},[g]),r?W.jsx(fuI,{gltfUrl:r,position:A,rotation:I,modelOffset:e,modelRotation:t,sourceCoordinateTransform:B,modelSize:o,modelFitMode:C,scale:Q,onHover:i,onUnhover:E,isHovered:n,isTranslucent:s}):null};function FdA(g,A){let{x:I,y:e,z:t}=g;if(A.axisMapping){const B={x:I,y:e,z:t};A.axisMapping.x&&(I=f$A(B,A.axisMapping.x)),A.axisMapping.y&&(e=f$A(B,A.axisMapping.y)),A.axisMapping.z&&(t=f$A(B,A.axisMapping.z))}if(I*=A.flipX??1,e*=A.flipY??1,t*=A.flipZ??1,A.rotation){if(A.rotation.x){const B=A.rotation.x*Math.PI/180,o=Math.cos(B),C=Math.sin(B),Q=e*o-t*C,i=e*C+t*o;e=Q,t=i}if(A.rotation.y){const B=A.rotation.y*Math.PI/180,o=Math.cos(B),C=Math.sin(B),Q=I*o+t*C,i=-I*C+t*o;I=Q,t=i}if(A.rotation.z){const B=A.rotation.z*Math.PI/180,o=Math.cos(B),C=Math.sin(B),Q=I*o-e*C,i=I*C+e*o;I=Q,e=i}}return{x:I,y:e,z:t}}function f$A(g,A){switch(A){case"x":return g.x;case"y":return g.y;case"z":return g.z;case"-x":return-g.x;case"-y":return-g.y;case"-z":return-g.z;default:return 0}}var R$A={STEP_INVERTED:{axisMapping:{x:"-x",y:"z",z:"-y"}},Z_UP_TO_Y_UP_USB_FIX:{axisMapping:{x:"x",y:"-z",z:"y"},flipZ:-1},FOOTPRINTER_MODEL_TRANSFORM:{axisMapping:{x:"x",y:"-z",z:"y"},flipX:-1,rotation:{x:180,y:180}}};function R7t(g,A){if(A.coordinateTransform)return A.coordinateTransform;if(!A.usingGlbCoordinates){if(A.hasFootprinterModel)return R$A.FOOTPRINTER_MODEL_TRANSFORM;if(!A.usingObjFormat)return A.usingStepFormat?R$A.STEP_INVERTED:R$A.Z_UP_TO_Y_UP_USB_FIX}}function gIA(g,A){return R7t(g,{usingGlbCoordinates:A==="gltf"||A==="glb"||A==="jscad",usingObjFormat:A==="obj"||A==="wrl",usingStepFormat:A==="step",hasFootprinterModel:A==="footprinter"})}function UdA(g){if(!g)return;const A=FdA({x:1,y:0,z:0},g),I=FdA({x:0,y:1,z:0},g),e=FdA({x:0,y:0,z:1},g);return new iQ().makeBasis(new oI(A.x,A.y,A.z),new oI(I.x,I.y,I.z),new oI(e.x,e.y,e.z))}function C3(g){return g*Math.PI/180}function N7t(g){if(g==="z+")return[0,0,0];switch(g){case"x+":return[0,C3(-90),0];case"x-":return[0,C3(90),0];case"y+":return[C3(90),0,0];case"y-":return[C3(-90),0,0];case"z-":return[C3(180),0,0];default:return[0,0,0]}}function x7t(g,A,I){if(!g.position)return;let e=g.position.z;return!g.is_on_folded_board&&g.pcb_component_id&&A==="bottom"&&g.position.z>=0&&(e=-(g.position.z+I)),[g.position.x,g.position.y,e]}function F7t(g,A){return g.rotation?[C3(g.rotation.x),C3(g.rotation.y),C3(g.rotation.z)]:A==="bottom"?[Math.PI,0,0]:[0,0,0]}function U7t(g,A){const I=new oI(g.x,g.y,g.z),e=new VG(A[0],A[1],A[2],"XYZ");return I.applyEuler(e),[I.x,I.y,I.z]}function J7t(g,A,I){if(!g.model_origin_position)return[0,0,0];const e=A?FdA(g.model_origin_position,A):g.model_origin_position;return U7t(e,I)}function K7t(g,A){const I=x7t(g,A.layer,A.pcbThickness),e=F7t(g,A.layer),t=gIA(g,A.modelType),B=N7t(g.model_board_normal_direction??"z+"),o=J7t(g,t,B);return{position:I,rotation:e,modelPosition:[-o[0],-o[1],-o[2]],modelRotation:B,scale:g.model_unit_to_mm_scale_factor??void 0,fitMode:g.model_object_fit??"contain_within_bounds",size:g.size?[g.size.x,g.size.y,g.size.z]:void 0}}var P7t=g=>g.model_glb_url||g.model_gltf_url?g.model_glb_url?"glb":"gltf":g.model_obj_url||g.model_wrl_url||g.model_stl_url?g.model_wrl_url?"wrl":g.model_stl_url?"stl":"obj":g.model_jscad?"jscad":g.footprinter_string?"footprinter":g.model_step_url?"step":"unknown",L7t=g=>g==="step"?"glb":g,Y7t=(g,A)=>{if(!g.pcb_component_id||!g.model_jscad||g.model_origin_alignment!=="bottom_center_of_component")return!1;const I=A.find(e=>e.type==="pcb_component"&&e.pcb_component_id===g.pcb_component_id);return!!(I&&I.do_not_place&&I.is_allowed_to_be_off_board&&I.obstructs_within_bounds===!1)},_7t=(g,A)=>{if(g)return A?A(g):g},b7t=(...g)=>g,N$A=class extends nC.Component{constructor(g){super(g),this.state={hasError:!1,error:null}}static getDerivedStateFromError(g){return{hasError:!0,error:g}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},H7t=({error:g,onError:A})=>(gA.useEffect(()=>{A(g)},[g,A]),null),FuI=({cad_component:g,circuitJson:A,resolveStaticAsset:I})=>{const e=muI(A),[t,B]=gA.useState(!1),{visibility:o}=e5(),[C,Q]=gA.useState(null),i=gA.useCallback(H=>{H?.mousePosition?(B(!0),Q(H.mousePosition)):(B(!1),Q(null))},[]),E=gA.useCallback(()=>{B(!1),Q(null)},[]),n=gA.useMemo(()=>jB(A).source_component.getUsing({source_component_id:g.source_component_id})?.name,[A,g.source_component_id]),{pcbComponent:s,layer:r,isThroughHole:a}=gA.useMemo(()=>$qt(g,A),[g,A]),c=gA.useCallback(H=>_7t(H,I),[I]),h=c(g.model_wrl_url??g.model_stl_url??g.model_obj_url),l=c(g.model_glb_url??g.model_gltf_url),D=c(g.model_step_url),[d,y]=gA.useState(0),[w,u]=gA.useState(null);gA.useEffect(()=>{y(0),u(null)},[g.cad_component_id,h,l,D]);const G=gA.useMemo(()=>Y7t(g,A),[g,A]),m=G?o.enclosure==="translucent":!!g.show_as_translucent_model,p=P7t(g),k=L7t(p),S=g.model_glb_url?"glb":"gltf",R=g.model_wrl_url?"wrl":g.model_stl_url?"stl":"obj",F=gA.useMemo(()=>K7t(g,{layer:r,pcbThickness:e,modelType:k}),[g,r,e,k]),N=b7t(...F.rotation),U=F.position,P=gA.useMemo(()=>{const H=[];return l&&H.push(W.jsx(fuI,{gltfUrl:l,position:U,rotation:N,modelOffset:F.modelPosition,modelRotation:F.modelRotation,sourceCoordinateTransform:UdA(gIA(g,S)),scale:F.scale,modelSize:F.size,modelFitMode:F.fitMode,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m},`${g.cad_component_id}-gltf-${l}`)),h&&H.push(W.jsx(D7t,{url:h,position:U,rotation:N,modelOffset:F.modelPosition,modelRotation:F.modelRotation,sourceCoordinateTransform:UdA(gIA(g,R)),scale:F.scale,modelSize:F.size,modelFitMode:F.fitMode,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m},`${g.cad_component_id}-mixed-${h}`)),D&&!g.model_jscad&&!g.footprinter_string&&H.push(W.jsx(f7t,{stepUrl:D,position:U,rotation:N,modelOffset:F.modelPosition,modelRotation:F.modelRotation,sourceCoordinateTransform:UdA(gIA(g,k)),scale:F.scale,modelSize:F.size,modelFitMode:F.fitMode,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m},`${g.cad_component_id}-step-${D}`)),H},[U,g.cad_component_id,g.footprinter_string,g.model_jscad,m,l,S,i,E,t,R,F.modelPosition,F.modelRotation,F.scale,F.fitMode,F.size,k,N,D,h]);let b=null;if(P.length>0){if(d>=P.length){if(w)throw w;return null}b=W.jsx(N$A,{fallback:({error:H})=>W.jsx(H7t,{error:H,onError:q=>{u(q),y(j=>Math.max(j,d+1))}}),children:P[d]},`${g.cad_component_id}-fallback-${d}`)}else g.model_jscad?b=W.jsx(r7t,{jscadPlan:g.model_jscad,positionOffset:U,rotationOffset:N,modelOffset:F.modelPosition,modelRotation:F.modelRotation,sourceCoordinateTransform:UdA(gIA(g,"jscad")),scale:F.scale,modelSize:F.size,modelFitMode:F.fitMode,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m},g.cad_component_id):g.footprinter_string&&(b=W.jsx(o7t,{positionOffset:U,rotationOffset:N,footprint:g.footprinter_string,scale:F.scale,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m}));if(G){if(o.enclosure==="hidden")return null}else if(g.show_as_translucent_model){if(!o.translucentModels)return null}else if(s&&(a&&!o.throughHoleModels||!a&&!o.smtModels))return null;return W.jsxs(W.Fragment,{children:[W.jsx(Wqt,{cadComponent:g,children:b}),t&&C?W.jsx(puI,{position:C,style:{fontFamily:"sans-serif",transform:"translate3d(1rem, 1rem, 0)",backgroundColor:"white",padding:"5px",borderRadius:"3px",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:n??"<unknown>"}):null]})},UuI={version:"0.0.626"},JuI="cadViewerLightingEnabled",v7t=()=>typeof window>"u"?!0:window.localStorage.getItem(JuI)!=="false",KuI=gA.createContext(void 0),q7t=({children:g})=>{const[A,I]=gA.useState(!1),[e,t]=gA.useState(!1),[B,o]=gA.useState(v7t);gA.useEffect(()=>{window.localStorage.setItem(JuI,B?"true":"false")},[B]);const C=gA.useMemo(()=>({darkBackgroundEnabled:A,setDarkBackgroundEnabled:I,gridEnabled:e,setGridEnabled:t,lightingEnabled:B,setLightingEnabled:o}),[A,e,B]);return W.jsx(KuI.Provider,{value:C,children:g})},x$A=()=>{const g=gA.useContext(KuI);if(!g)throw new Error("useAppearance must be used within an AppearanceProvider");return g},PuI="cadViewerCameraStateSession";function LuI(g){return g?`${PuI}:${g}`:PuI}function T7t({camera:g,controls:A,cameraSessionScope:I}){try{const e={position:g.position.toArray(),quaternion:g.quaternion.toArray(),up:g.up.toArray(),fov:g instanceof $h?g.fov:50,target:A.target.toArray()};sessionStorage.setItem(LuI(I),JSON.stringify(e))}catch(e){console.warn("Failed to save camera:",e)}}function Z7t({camera:g,controls:A,cameraSessionScope:I}){try{const e=sessionStorage.getItem(LuI(I));if(!e)return!1;const t=JSON.parse(e);return g.position.fromArray(t.position),g.quaternion.fromArray(t.quaternion),g.up.fromArray(t.up),g instanceof $h&&(g.fov=t.fov,g.updateProjectionMatrix()),A.target.fromArray(t.target),A.update(),g.updateMatrixWorld(),!0}catch(e){return console.warn("Failed to restore camera:",e),!1}}function YuI(g){return"controls"in g?g:{controls:g}}var _uI=(g,A)=>{const{controls:I,cameraSessionScope:e}=YuI(A);T7t({camera:g,controls:I,cameraSessionScope:e})},F$A=(g,A)=>{const{controls:I,cameraSessionScope:e}=YuI(A);return Z7t({camera:g,controls:I,cameraSessionScope:e})},buI=gA.createContext(void 0),O7t=({children:g,defaultTarget:A,initialCameraPosition:I,initialCameraType:e})=>{const t=gA.useRef(null),B=gA.useRef(null),[o,C]=gA.useState(null),[Q,i]=gA.useState(e??"perspective"),[E,n]=gA.useState(I??null),[s,r]=gA.useState(new VG(0,0,0)),a=gA.useMemo(()=>{const[D,d,y]=I??[5,-5,5],w=Math.hypot(D-A.x,d-A.y,y-A.z);return w>0?w:5},[I,A]),c=gA.useCallback(D=>{const d=[A.x,A.y,A.z],y=B.current,w=t.current;let u=a;switch(y&&w&&(u=y.position.distanceTo(w.target)),D){case"Top Center Angled":{const G=u/Math.sqrt(2);return{position:[A.x,A.y-G,A.z+G],target:d,up:[0,0,1]}}case"Top Down":return{position:[A.x,A.y,A.z+u],target:d,up:[0,0,1]};case"Top Left Corner":return{position:[A.x-u*.6,A.y-u*.6,A.z+u*.6],target:d,up:[0,0,1]};case"Top Right Corner":return{position:[A.x+u*.6,A.y-u*.6,A.z+u*.6],target:d,up:[0,0,1]};case"Left Sideview":return{position:[A.x-u,A.y,A.z],target:d,up:[0,0,1]};case"Right Sideview":return{position:[A.x+u,A.y,A.z],target:d,up:[0,0,1]};case"Front":return{position:[A.x,A.y-u,A.z],target:d,up:[0,0,1]};default:return null}},[a,A,B,t]),h=gA.useCallback(D=>{t.current=D},[]),l=gA.useMemo(()=>({controlsRef:t,mainCameraRef:B,defaultTarget:A,baseDistance:a,controller:o,setController:C,getPresetConfig:c,handleControlsChange:h,cameraType:Q,setCameraType:i,cameraPosition:E,setCameraPosition:n,cameraRotation:s,setCameraRotation:r,saveCameraToSession:_uI,loadCameraFromSession:F$A}),[A,a,o,c,h,Q,E,s]);return W.jsx(buI.Provider,{value:l,children:g})},gJ=()=>{const g=gA.useContext(buI);if(!g)throw new Error("useCameraController must be used within a CameraControllerProvider");return g},W7t=g=>g<.5?4*g*g*g:1-Math.pow(-2*g+2,3)/2,V7t=()=>{const{controlsRef:g,mainCameraRef:A,defaultTarget:I,setController:e,getPresetConfig:t}=gJ(),B=gA.useRef(null),o=gA.useRef(new OG),C=gA.useRef(new oI),Q=gA.useRef(new oI),i=gA.useRef(new OG),E=gA.useRef(new OG),n=gA.useRef(new Ks),s=gA.useRef(new Ks),r=gA.useCallback(({position:c,target:h,up:l,durationMs:D=600})=>{if(!A.current)return;const d=g.current?.target??I,y=new oI(c[0],c[1],c[2]),w=h?new oI(h[0],h[1],h[2]):I.clone(),u=new oI(...l??[0,0,1]).normalize(),G=s.current;G.position.copy(y),G.up.copy(u),G.lookAt(w);const m=G.quaternion.clone(),p=A.current.quaternion.clone(),k=A.current.position.clone(),S=d.clone(),R=n.current;R.up.set(0,0,1),R.position.copy(k),R.lookAt(S);const F=R.quaternion.clone();R.up.set(0,0,1),R.position.copy(y),R.lookAt(w);const N=R.quaternion.clone(),U=F.clone().invert().multiply(p).normalize(),P=N.clone().invert().multiply(m).normalize();B.current={fromPosition:k,toPosition:y,fromTarget:S,toTarget:w,toQuaternion:m,rollFrom:U,rollTo:P,startTime:performance.now(),duration:D}},[A,g,I]),a=gA.useCallback(c=>{if(c==="Custom")return;const h=t(c);h&&r(h)},[r,t]);return gA.useEffect(()=>A.current?(e({animateTo:r,animateToPreset:a}),()=>{e(null)}):void 0,[r,a,A,e]),zgA(()=>{if(!A.current||!B.current)return;const{fromPosition:c,toPosition:h,fromTarget:l,toTarget:D,toQuaternion:d,rollFrom:y,rollTo:w,startTime:u,duration:G}=B.current,m=performance.now()-u,p=G<=0?1:Math.min(m/G,1),k=W7t(p);A.current.position.lerpVectors(c,h,k);const S=C.current;S.copy(l).lerp(D,k);const R=n.current;R.up.set(0,0,1),R.position.copy(A.current.position),R.lookAt(S);const F=o.current;F.copy(R.quaternion);const N=i.current;N.copy(y);const U=E.current;U.copy(w),y.dot(w)<0&&(U.x*=-1,U.y*=-1,U.z*=-1,U.w*=-1),U.normalize(),N.slerp(U,k),A.current.quaternion.copy(F).multiply(N).normalize();const P=Q.current;P.set(0,1,0).applyQuaternion(A.current.quaternion).normalize(),A.current.up.copy(P),g.current?.target.copy(S),A.current.updateMatrixWorld(),g.current?.update(),p>=1&&(A.current.position.copy(h),A.current.quaternion.copy(d),A.current.up.set(0,0,1),A.current.updateMatrixWorld(),g.current?.target.copy(D),g.current?.update(),B.current=null)}),null},j7t=Symbol("camera-session-not-restored"),z7t=({cameraSessionScope:g}={})=>{const{controlsRef:A}=gJ(),I=gA.useRef(null),e=gA.useRef(j7t),t=gA.useRef(null);gA.useEffect(()=>()=>{t.current!==null&&(clearTimeout(t.current),t.current=null)},[g]);const B=gA.useCallback(C=>{if(I.current=C,e.current!==g&&A.current){const Q=F$A(C,{controls:A.current,cameraSessionScope:g});if(e.current=g,Q)return}},[g,A]),o=gA.useCallback(()=>{if(!(!I.current||!A.current)){if(e.current!==g){const C=F$A(I.current,{controls:A.current,cameraSessionScope:g});if(e.current=g,C)return}t.current!==null&&clearTimeout(t.current),t.current=setTimeout(()=>{I.current&&A.current&&_uI(I.current,{controls:A.current,cameraSessionScope:g})},150)}},[g,A]);return{handleCameraCreated:B,handleControlsChange:o}};function X7t(g){g.querySelectorAll("canvas").forEach(A=>A.remove())}var $7t=g=>{g.outputColorSpace=Fp,g.toneMapping=MNg,g.toneMappingExposure=1,g.shadowMap.enabled=!0,g.shadowMap.type=GNg},ATt=gA.forwardRef(({children:g,scene:A,camera:I,style:e,onCreated:t},B)=>{const{cameraType:o}=gJ(),C=gA.useRef(null),[Q,i]=gA.useState(null),E=gA.useRef([]),n=gA.useRef(void 0);n.current=t;const s=gA.useRef(null),r=gA.useCallback(l=>{E.current.push(l)},[]),a=gA.useCallback(l=>{E.current=E.current.filter(D=>D!==l)},[]),c=gA.useMemo(()=>new pY,[]);A?.up&&c.up.set(A.up.x,A.up.y,A.up.z);const h=gA.useRef(new Ks);return gA.useImperativeHandle(B,()=>h.current),gA.useEffect(()=>{if(!C.current)return;X7t(C.current);const l=new ZEA({antialias:!0,alpha:!0});$7t(l),l.setSize(C.current.clientWidth,C.current.clientHeight),l.setPixelRatio(window.devicePixelRatio),C.current.appendChild(l.domElement);const D=C.current.clientWidth/C.current.clientHeight,d=o==="perspective"?new $h(75,D,.1,1e3):new XH(-10*D,10*D,10,-10,-1e3,1e3);s.current?(d.position.copy(s.current.position),d.quaternion.copy(s.current.quaternion),d.up.copy(s.current.up)):(I?.up&&d.up.set(I.up[0],I.up[1],I.up[2]),I?.position&&d.position.set(I.position[0],I.position[1],I.position[2]),d.lookAt(0,0,0)),c.add(h.current),window.__TSCIRCUIT_THREE_OBJECT=h.current,i({scene:c,camera:d,renderer:l,rootObject:h.current,addFrameListener:r,removeFrameListener:a}),n.current?.({camera:d,renderer:l});let y;const w=new oGe;let u=!0;const G=new IntersectionObserver(([k])=>{u=k?.isIntersecting??!1,u&&p()});G.observe(C.current);const m=()=>{if(y=requestAnimationFrame(m),!u)return;const k=w.getElapsedTime(),S=w.getDelta();E.current.forEach(R=>R(k,S)),l.render(c,d)};m();const p=()=>{if(C.current?.clientWidth&&C.current.clientHeight){const k=C.current.clientWidth/C.current.clientHeight;d instanceof $h?d.aspect=k:d instanceof XH&&(d.left=-10*k,d.right=10*k,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),l.setSize(C.current.clientWidth,C.current.clientHeight)}};return window.addEventListener("resize",p),()=>{s.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",p),cancelAnimationFrame(y),G.disconnect(),C.current&&l.domElement&&C.current.removeChild(l.domElement),l.dispose(),c.remove(h.current),window.__TSCIRCUIT_THREE_OBJECT===h.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[c,r,a,o]),W.jsx("div",{ref:C,style:{width:"100%",height:"100%",...e},children:Q&&W.jsx(G$A.Provider,{value:Q,children:W.jsx(t7t,{children:g})})})}),gTt=`
|
|
5320
5320
|
varying vec3 worldPosition;
|
|
5321
5321
|
void main() {
|
|
5322
5322
|
worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
@@ -5350,7 +5350,7 @@ ${Q.join(`
|
|
|
5350
5350
|
gl_FragColor = vec4(color, max(g1, g2) * a);
|
|
5351
5351
|
if (gl_FragColor.a <= 0.0) discard;
|
|
5352
5352
|
}
|
|
5353
|
-
`,eTt=({rotation:g,infiniteGrid:A,cellSize:I=1,sectionSize:e=10})=>{const{scene:t,camera:B}=SD(),o=1e3,C=gA.useMemo(()=>{const Q=new Sf(o,o);Q.rotateX(-Math.PI/2);const i=new KN({vertexShader:gTt,fragmentShader:ITt,uniforms:{cellSize:{value:I},sectionSize:{value:e},gridColor:{value:new tB(15658734)},sectionColor:{value:new tB(13421823)},fadeDistance:{value:100},fadeStrength:{value:1.5}},transparent:!0,side:yl}),E=new FB(Q,i);return g&&E.rotation.fromArray(g),E},[o,I,e,g]);return zgA(()=>{A&&C.position.set(B.position.x,B.position.y,0)}),gA.useEffect(()=>{if(!(!t||!C))return t.add(C),()=>{t.remove(C),C.geometry.dispose(),Array.isArray(C.material)?C.material.forEach(Q=>Q.dispose()):C.material.dispose()}},[t,C]),null},U$A=.75,tTt=({boardDimensions:g,boardCenter:A,darkBackgroundEnabled:I=!1,shadowsEnabled:e=!1})=>{const{scene:t}=SD(),B=gA.useMemo(()=>{const o=new Nc;o.name="cad-viewer-light-rig";const C=A?.x??0,Q=A?.y??0,i=Math.max(g?.width??0,g?.height??0,20),E=i*.8,n=i,s=i*1.7,r=new BFg(16186360,.22);r.name="cad-viewer-soft-ambient",o.add(r);const a=new $ue(15004141,1581597,.2);a.name="cad-viewer-hemisphere",o.add(a);const c=(h,l,D,d,y=!1)=>{const w=new tFg(l,D);if(w.name=h,w.position.set(C+d[0],Q+d[1],d[2]),w.target.position.set(C,Q,0),w.castShadow=y,y){w.shadow.mapSize.set(2048,2048),w.shadow.bias=-2e-4,w.shadow.normalBias=.03,w.shadow.radius=5;const u=w.shadow.camera;u.left=-E,u.right=E,u.top=E,u.bottom=-E,u.near=.5,u.far=Math.max(i*4,Math.hypot(...d)+i*2),u.updateProjectionMatrix()}o.add(w),o.add(w.target)};return c("cad-viewer-key-light",16775406,1.35,[s*.68,-s*.8,s*1.08],e),c("cad-viewer-fill-light",14477554,.25,[-n*.85,n*.55,n*.75]),c("cad-viewer-rim-light",12184275,.5,[-n*.35,n*.85,n*.95]),c("cad-viewer-underside-key-light",16775406,1.35*U$A,[s*.68,-s*.8,-s*1.08]),c("cad-viewer-underside-fill-light",14477554,.25*U$A,[-n*.85,n*.55,-n*.75]),c("cad-viewer-underside-rim-light",12184275,.5*U$A,[-n*.35,n*.85,-n*.95]),o},[A,g,e]);return gA.useEffect(()=>{const o=t.background,C=t.environment;return t.background=I?new tB(1053456):null,t.environment=null,()=>{t.background=o,t.environment=C}},[I,t]),gA.useEffect(()=>{if(t)return t.add(B),()=>{t.remove(B)}},[t,B]),null},BTt=.05,oTt=({camera:g,initialOrbitDistance:A})=>{const I=Number.isFinite(A)?A*BTt:0;return Math.max(I,g.near,Number.EPSILON)},CTt=({camera:g,controls:A,minimumDollyDistance:I})=>{if(!(g instanceof $h))return!1;const e=A.getDistance();if(Number.isFinite(e)&&e>=I)return!1;const t=new oI;return g.getWorldDirection(t),A.target.copy(g.position).addScaledVector(t,I),!0},QTt=({autoRotate:g,autoRotateSpeed:A,onStart:I,panSpeed:e,rotateSpeed:t,zoomSpeed:B,enableDamping:o,dampingFactor:C,target:Q,onControlsChange:i})=>{const{camera:E,renderer:n}=SD(),s=gA.useMemo(()=>!E||!n?null:new wPt(E,n.domElement),[E,n]),r=gA.useMemo(()=>{if(!s||!(E instanceof $h))return Number.EPSILON;const a=Q?Math.hypot(E.position.x-Q[0],E.position.y-Q[1],E.position.z-Q[2]):s.getDistance();return oTt({camera:E,initialOrbitDistance:a})},[E,s,Q]);return gA.useEffect(()=>(i?.(s??null),()=>i?.(null)),[s,i]),gA.useEffect(()=>{if(!s)return;const a=()=>{i?.(s)};return s.addEventListener("change",a),()=>{s.removeEventListener("change",a)}},[s,i]),gA.useEffect(()=>{s&&(s.autoRotate=g||!1,s.autoRotateSpeed=A||1,e!==void 0&&(s.panSpeed=e),t!==void 0&&(s.rotateSpeed=t),B!==void 0&&(s.zoomSpeed=B),o!==void 0&&(s.enableDamping=o),C!==void 0&&(s.dampingFactor=C),s.zoomToCursor=!0,s.mouseButtons={LEFT:b4.ROTATE,MIDDLE:b4.PAN,RIGHT:null},Q&&(s.target.set(Q[0],Q[1],Q[2]),s.update()))},[s,g,A,e,t,B,o,C,Q]),gA.useEffect(()=>{if(!(!s||!I))return s.addEventListener("start",I),()=>{s.removeEventListener("start",I)}},[s,I]),gA.useEffect(()=>{if(s)return()=>{s.dispose()}},[s]),zgA(()=>{s&&(CTt({camera:E,controls:s,minimumDollyDistance:r}),s.update())},[E,s,r]),null},iTt=10,iT={banana:{type:"banana",label:"Show Banana",width:190,height:60,depth:34,zCenter:17},"credit-card":{type:"credit-card",label:"Show Credit Card",width:85.6,height:53.98,depth:.76,zCenter:0},"14in-macbook":{type:"14in-macbook",label:"Show 14in Macbook",width:312.6,height:221.2,depth:15.5,zCenter:0}},ETt=Object.values(iT),nTt=[{type:null,label:"None"},...ETt],sTt=(g,A)=>g===A?null:A,J$A=g=>Number.isFinite(g)?Math.max(g??0,0):0,JdA=g=>Number.isFinite(g)?g??0:0,HuI=(g,A,I)=>{const e=iT[g],t=J$A(A?.width),B=JdA(I?.x),o=JdA(I?.y);return{x:B+t/2+iTt+e.width/2,y:o,z:0}},aTt=(g,A,I)=>{const e=iT[g],t=J$A(A?.width),B=J$A(A?.height),o=JdA(I?.x),C=JdA(I?.y),Q=HuI(g,A,I);return{minX:Math.min(o-t/2,Q.x-e.width/2),maxX:Math.max(o+t/2,Q.x+e.width/2),minY:Math.min(C-B/2,Q.y-e.height/2),maxY:Math.max(C+B/2,Q.y+e.height/2),minZ:Math.min(0,Q.z+e.zCenter-e.depth/2),maxZ:Math.max(0,Q.z+e.zCenter+e.depth/2)}};function rTt(g,A){const I=new OG().setFromEuler(new VG(g.x,g.y,g.z)),e=new oI(0,0,1);return e.applyQuaternion(I),e.multiplyScalar(A)}var cTt=()=>{const{mainCameraRef:g}=gJ(),A=gA.useRef(null);return gA.useEffect(()=>{if(!A.current)return;const I=A.current,e=document.createElement("canvas");I.appendChild(e);const t=new ZEA({canvas:e,antialias:!0,alpha:!0});t.setSize(120,120),t.setPixelRatio(window.devicePixelRatio);const B=new pY,o=new $h(75,1,.1,1e3);o.up.set(0,0,1);const C=new BFg(16777215,Math.PI/2);B.add(C);const Q=new Nc;Q.rotation.fromArray([Math.PI/2,0,0]);const i=1,E=new FB(new Jp(i,i,i),new Ps({color:"white"}));Q.add(E);const n=new Cj(new wue(new Jp(i,i,i)),new kY({color:0,linewidth:2}));Q.add(n),B.add(Q);const s=.51,r=(m,p,k)=>{const S=new YKA;return S.text=m,S.position.fromArray(p),k&&S.rotation.fromArray(k),S.color="black",S.fontSize=.25,S.anchorX="center",S.anchorY="middle",S.depthOffset=0,S.font=null,S.sync(),S},a=r("Front",[0,0,s]),c=r("Back",[0,0,-s],[0,Math.PI,0]),h=r("Right",[s,0,0],[0,Math.PI/2,0]),l=r("Left",[-s,0,0],[0,-Math.PI/2,0]),D=r("Top",[0,s,0],[-Math.PI/2,0,0]),d=r("Bottom",[0,-s,0],[Math.PI/2,0,0]);Q.add(a),Q.add(c),Q.add(h),Q.add(l),Q.add(D),Q.add(d);let y=null,w=!0;const u=new IntersectionObserver(([m])=>{w=m?.isIntersecting??!1});u.observe(e);const G=()=>{if(y=requestAnimationFrame(G),!!w){if(g.current){const m=rTt(g.current.rotation??new VG(0,0,0),2);m.equals(o.position)||(o.position.copy(m),o.lookAt(0,0,0))}t.render(B,o)}};return G(),()=>{u.disconnect(),e.remove(),y!==null&&cancelAnimationFrame(y),a.dispose(),c.dispose(),h.dispose(),l.dispose(),D.dispose(),d.dispose(),E.geometry.dispose(),E.material.dispose(),n.geometry.dispose(),n.material.dispose(),B.clear(),t.dispose(),t.forceContextLoss()}},[g]),W.jsx("div",{ref:A,style:{position:"absolute",top:0,left:0,width:120,height:120,zIndex:$gA.orientationCube}})},vuI=(g,A,I)=>{const e=g/2,t=A/2,B=Math.min(I,e,t),o=new vxg;return o.moveTo(-e+B,-t),o.lineTo(e-B,-t),o.quadraticCurveTo(e,-t,e,-t+B),o.lineTo(e,t-B),o.quadraticCurveTo(e,t,e-B,t),o.lineTo(-e+B,t),o.quadraticCurveTo(-e,t,-e,t-B),o.lineTo(-e,-t+B),o.quadraticCurveTo(-e,-t,-e+B,-t),o},K$A=(g,A,I,e)=>quI(vuI(g,A,e),I),quI=(g,A)=>{const I=new wKA(g,{depth:A,bevelEnabled:!1,curveSegments:24});return I.translate(0,0,-A/2),I.computeVertexNormals(),I},hTt=(g,A)=>{const I=iT[A];g.updateMatrixWorld(!0);const t=new WG().setFromObject(g).getSize(new oI);g.scale.set(I.width/t.x,I.height/t.y,I.depth/t.z),g.updateMatrixWorld(!0);const o=new WG().setFromObject(g).getCenter(new oI);g.position.set(-o.x,-o.y,I.zCenter-o.z),g.updateMatrixWorld(!0)},lTt=()=>{const g=new Pxg([new oI(-82,18,16),new oI(-67,7,15),new oI(-43,-9,14),new oI(-15,-18,14),new oI(16,-18,14),new oI(47,-8,14.5),new oI(72,8,16),new oI(84,19,17)]),A=84,I=30,e=g.computeFrenetFrames(A,!1),t=[],B=[],o=[],C=[],Q=[],i=new tB(16766023),E=new tB(12038965);for(let s=0;s<=A;s++){const r=s/A,a=g.getPointAt(r),c=e.normals[s],h=e.binormals[s],D=3.4+12.4*Math.sin(Math.PI*r)**.48,d=Math.max(0,(r-.82)/.18)*.38,y=i.clone().lerp(E,d);for(let w=0;w<=I;w++){const u=w/I*Math.PI*2,G=Math.sin(u),m=Math.cos(u),p=1+Math.cos(u*5+.35)*.035,k=new oI().addScaledVector(c,m).addScaledVector(h,G*.9).normalize(),S=a.clone().addScaledVector(c,m*D*p).addScaledVector(h,G*D*.9*p);t.push(S.x,S.y,S.z),B.push(k.x,k.y,k.z),o.push(y.r,y.g,y.b),C.push(r,w/I)}}for(let s=1;s<=A;s++)for(let r=1;r<=I;r++){const a=I+1,c=a*(s-1)+(r-1),h=a*s+(r-1),l=a*s+r,D=a*(s-1)+r;Q.push(c,D,h,h,D,l)}const n=new Jn;return n.setIndex(Q),n.setAttribute("position",new To(t,3)),n.setAttribute("normal",new To(B,3)),n.setAttribute("color",new To(o,3)),n.setAttribute("uv",new To(C,2)),n.computeBoundingBox(),n.computeBoundingSphere(),{geometry:n,curve:g}},DTt=()=>{const g=new Nc,A=new Nc,{geometry:I,curve:e}=lTt(),t=new FB(I,new Ps({color:16777215,roughness:.72,metalness:0,vertexColors:!0}));t.name="banana-peel",A.add(t);const B=new FB(new fY(3.4,20,12),new Ps({color:6242844,roughness:.92}));B.position.copy(e.getPointAt(0)),B.scale.set(1.15,.78,.78),B.name="banana-blossom-tip",A.add(B);const o=11,C=e.getTangentAt(1).normalize(),Q=new FB(new e6(2.5,4.1,o,18),new Ps({color:8483625,roughness:.82}));Q.quaternion.setFromUnitVectors(new oI(0,1,0),C),Q.position.copy(e.getPointAt(1)).addScaledVector(C,o/2),Q.name="banana-stem",A.add(Q);const i=new FB(new fY(2.55,18,10),new Ps({color:5981470,roughness:.9}));return i.position.copy(e.getPointAt(1)).addScaledVector(C,o),i.name="banana-stem-tip",A.add(i),hTt(A,"banana"),g.add(A),g},dTt=(g,A,I,e,t)=>{const B=vuI(g,A,e),o=new hKA;return o.absarc(0,0,t,0,Math.PI*2,!0),B.holes.push(o),quI(B,I)},yTt=(g,A)=>{const t=new FB(new e6(A-.15,A-.15,.25,48),new Ps({color:10199202,roughness:.48,metalness:.28}));return t.rotation.x=Math.PI/2,t.position.z=g-.35-.25/2,t.name="macbook-lid-indent",t},wTt=()=>{const g=iT["credit-card"],A=new Nc,I=new FB(K$A(g.width,g.height,g.depth,3.18),new Ps({color:2383272,roughness:.38,metalness:.08}));I.name="credit-card-body",A.add(I);const e=g.depth/2+.08,t=new FB(K$A(12,9,.14,1.2),new Ps({color:14003525,roughness:.3,metalness:.62}));t.position.set(-21,3,e),t.name="credit-card-chip",A.add(t);const B=new Ps({color:15331061,roughness:.45,metalness:.05});for(let o=0;o<4;o++){const C=new FB(new Jp(o===3?8:12,.8,.1),B);C.position.set(-20+o*14,-14,e+.08),C.name="credit-card-detail",A.add(C)}return A},uTt=()=>{const g=iT["14in-macbook"],A=new Nc,I=new Ps({color:12896201,roughness:.3,metalness:.38}),e=new FB(K$A(g.width,g.height,13.5,9),I);e.position.z=-1,e.name="macbook-body",A.add(e);const t=2,B=6.75,o=B+t/2,C=12,Q=new FB(dTt(g.width-1.8,g.height-1.8,t,8.2,C),I.clone());Q.position.z=B,Q.name="macbook-lid",A.add(Q);const i=new FB(new Jp(g.width-42,3.2,1.2),new Ps({color:3158838,roughness:.55,metalness:.45}));i.position.set(0,g.height/2-2.4,6.15),i.name="macbook-hinge",A.add(i),A.add(yTt(o,C));const E=new FB(new Jp(54,1.2,.8),new Ps({color:6712174,roughness:.45,metalness:.5}));return E.position.set(0,-221.2/2+.5,2.5),E.name="macbook-front-notch",A.add(E),A},GTt=g=>{const A=g==="banana"?DTt():g==="credit-card"?wTt():uTt();return A.name=`reference-object-${g}`,A.userData.isReferenceObject=!0,A.userData.referenceObjectType=g,ZM(A),A},mTt=g=>{const A=new Set,I=new Set;g.traverse(e=>{if(!(e instanceof FB))return;A.add(e.geometry);const t=Array.isArray(e.material)?e.material:[e.material];for(const B of t)I.add(B)});for(const e of A)e.dispose();for(const e of I)e.dispose()},pTt=(g,A,I,e=1.18)=>{const t=Math.max(I.maxX-I.minX,0),B=Math.max(I.maxY-I.minY,0),o=Math.max(I.maxZ-I.minZ,0),C=new oI((I.minX+I.maxX)/2,(I.minY+I.maxY)/2,(I.minZ+I.maxZ)/2),Q=Math.max(Math.hypot(t,B,o)/2,1),i=A?.target??new oI,E=new oI(0,-.75,.9).normalize();let n=Math.max(g.position.distanceTo(i),5);if(g instanceof $h){const s=FH.degToRad(g.fov),r=2*Math.atan(Math.tan(s/2)*g.aspect),a=Math.min(s,r);n=Q*e/Math.sin(a/2),g.far=Math.max(g.far,n+Q*e*3),g.updateProjectionMatrix()}else if(g instanceof XH){const s=Math.abs(g.right-g.left)/2,r=Math.abs(g.top-g.bottom)/2;g.zoom=Math.min(s/(Q*e),r/(Q*e)),n=Math.max(n,Q*e*2),g.updateProjectionMatrix()}return g.position.copy(C).addScaledVector(E,n),g.lookAt(C),g.updateMatrixWorld(),A&&(A.target.copy(C),A.update()),{center:C,radius:Q,distance:n}},kTt=({type:g,boardDimensions:A,boardCenter:I})=>{const{scene:e}=SD(),t=gA.useMemo(()=>{const B=GTt(g),o=HuI(g,A,I);return B.position.set(o.x,o.y,o.z),B},[g,A,I]);return gA.useEffect(()=>(e.add(t),()=>{e.remove(t),mTt(t)}),[e,t]),null},TuI=({bounds:g})=>{const{camera:A}=SD(),{controlsRef:I}=gJ();return gA.useEffect(()=>{pTt(A,I.current,g)},[g,A,I]),null},MTt=()=>{const{camera:g}=SD(),{setCameraRotation:A}=gJ();return zgA(()=>{g&&A(g.rotation)}),null},ZuI=gA.forwardRef(({children:g,initialCameraPosition:A=[5,-5,5],autoRotateDisabled:I,clickToInteractEnabled:e=!1,boardDimensions:t,boardCenter:B,cameraSessionScope:o,referenceObject:C,onUserInteraction:Q,onCameraControllerReady:i},E)=>{const[n,s]=gA.useState(!e),{mainCameraRef:r,handleControlsChange:a,controller:c}=gJ(),{darkBackgroundEnabled:h,gridEnabled:l,lightingEnabled:D}=x$A(),{handleCameraCreated:d,handleControlsChange:y}=z7t({cameraSessionScope:o});gA.useEffect(()=>{i&&i(c)},[c,i]);const w=gA.useMemo(()=>{if(C)return aTt(C,t,B)},[C,t,B]),u=gA.useMemo(()=>{if(!t)return 10;const m=t.width??0,p=t.height??0;return Math.max(Math.max(m,p)*1.5,10)},[t]),G=gA.useMemo(()=>{if(w)return[(w.minX+w.maxX)/2,(w.minY+w.maxY)/2,(w.minZ+w.maxZ)/2];if(B)return[B.x,B.y,0]},[B,w]);return W.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[W.jsx(cTt,{}),W.jsxs(ATt,{ref:E,scene:{up:new oI(0,0,1)},camera:{up:[0,0,1],position:A},onCreated:({camera:m})=>{r.current=m,d(m)},children:[W.jsx(Oqt,{}),W.jsx(V7t,{}),W.jsx(MTt,{}),n&&W.jsx(QTt,{autoRotate:!I,autoRotateSpeed:1,onStart:Q,rotateSpeed:.5,panSpeed:.75,zoomSpeed:.5,enableDamping:!0,dampingFactor:.1,target:G,onControlsChange:m=>{a(m),y()}}),W.jsx(tTt,{boardDimensions:t,boardCenter:B,darkBackgroundEnabled:h,shadowsEnabled:D}),C&&W.jsx(kTt,{type:C,boardDimensions:t,boardCenter:B}),w&&W.jsx(TuI,{bounds:w}),l&&W.jsx(eTt,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:3,sectionSize:u}),g]},o),W.jsxs("div",{style:{position:"absolute",right:24,bottom:24,fontFamily:"sans-serif",color:"white",WebkitTextStroke:"0.5px rgba(0, 0, 0, 0.5)",fontSize:11},children:["@",UuI.version]}),e&&!n&&W.jsx("button",{type:"button",onClick:()=>s(!0),onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&s(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:$gA.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center"},children:W.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",fontFamily:"sans-serif",pointerEvents:"none"},children:"Click to Interact"})})]})}),STt=g=>{const[A,I]=gA.useState([]),[e,t]=gA.useState(!0);return gA.useEffect(()=>{if(!g)return;(async()=>{t(!0);const C=(Array.isArray(g)?g:[g]).map(async(Q,i)=>{const E=UPt.serialize({binary:!0},[Q]),s=await new Blob(E).arrayBuffer(),a=Q.layerType||(i===0?"board":void 0);return{stlData:s,color:Q.color,layerType:a}});try{const Q=await Promise.all(C);I(Q)}catch(Q){console.error("Error generating STLs:",Q),I([])}finally{t(!1)}})()},[g]),{stls:A,loading:e}},fTt=ts(adA()),RTt=ts(g5()),NTt=ts(VgA()),xTt=ts(g5()),FTt=ts(I5()),UTt=ts(zdI()),OuI=g=>{let A=0;for(let e=0;e<g.length;e++){const t=(e+1)%g.length;A+=g[e][0]*g[t][1],A-=g[t][0]*g[e][1]}return A/2<=0},P$A=(g,A=1.2,I={})=>{const{xyOutset:e=0}=I,{outline:t}=g;let B=t.map(Q=>[Q.x,Q.y]);OuI(B)&&(B=B.reverse());let o=(0,xTt.polygon)({points:B});e!==0&&(o=(0,UTt.expand)({delta:e,corners:"edge"},o));let C=(0,NTt.extrudeLinear)({height:A},o);return C=(0,FTt.translate)([0,0,-A/2],C),C},Oo=.01,jE={copper:[.78,.63,.39],fr4Tan:[.6,.43,.28],fr4SolderMaskGreen:[.06,.31,.19],fr4TracesWithMaskGreen:[.09,.38,.23],fr4TracesWithoutMaskTan:[.6,.43,.28],flexAmber:[.8,.61,.2],fr1Tan:[.8,.4,.2],fr1TracesWithMaskCopper:[.9,.6,.2],fr1SolderMaskGreen:[.02,.1,.04]},uR=.001,fd=32,K2=150,KdA=.6,JTt={fr1:jE.fr1Tan,fr4:jE.fr4Tan,flex:jE.flexAmber},KTt={fr1:jE.fr1SolderMaskGreen,fr4:jE.fr4SolderMaskGreen,flex:jE.flexAmber},PTt={red:"#650202",blue:"#003f7d",purple:"#4c1d69",black:"#071014",white:"#dddddd",yellow:"#dcc84a"},LTt=.875,YTt=/^#(?:[\da-f]{3}|[\da-f]{6})$/i,_Tt=/^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/i,bTt=/^rgb\(\s*\d+%\s*,\s*\d+%\s*,\s*\d+%\s*\)$/i,HTt=/^hsl\(\s*\d*\.?\d+\s*,\s*\d*\.?\d+%\s*,\s*\d*\.?\d+%\s*\)$/i,vTt={blue:.96,purple:.96,black:.99,yellow:.92},WuI=g=>{const A=g?.trim();if(!A)return null;const I=A.toLowerCase();if(I==="green"||I==="not_specified")return null;const t=PTt[I];return t?new tB(t):Object.hasOwn(tB.NAMES,I)||YTt.test(A)||_Tt.test(A)||bTt.test(A)||HTt.test(A)?new tB(I):null},qTt=g=>{const A=g?.trim().toLowerCase();return vTt[A]??LTt},TTt=({red:g,green:A,blue:I})=>Math.hypot(g-220,A-200,I-74)<4||Math.hypot(g-218,A-197,I-76)<4,ZTt=({soldermaskColor:g,copperColor:A,soldermaskOpacity:I})=>g.clone().multiplyScalar(I).add(A.clone().multiplyScalar(1-I)),VuI=g=>{const A=g.clone().convertLinearToSRGB();return`rgb(${[Math.round(A.r*255),Math.round(A.g*255),Math.round(A.b*255)].join(",")})`},OTt=new tB(1063462),L$A=({material:g,solder_mask_color:A})=>{const I=WuI(A);if(I)return I;if(g==="fr4")return OTt.clone();const e=JTt[g]??jE.fr4Tan;return new tB(e[0],e[1],e[2])},WTt=g=>{const A=g.filter(Q=>Q.type==="pcb_panel"),I=jB(g).pcb_board.list();let e,t,B=1.2;if(A.length>0)e=A[0],t=I.find(Q=>Q.pcb_panel_id===e.pcb_panel_id),B=t?.thickness??1.2;else{if(e=I.filter(i=>!i.pcb_panel_id)[0],!e)return console.warn("No pcb_board or pcb_panel found for simplified geometry"),[];t=e,B=e.thickness??1.2}let o;"outline"in e&&e.outline&&e.outline.length>0?o=P$A({outline:e.outline},B):o=(0,RTt.cuboid)({size:[e.width??10,e.height??10,B],center:[e.center.x,e.center.y,0]});const C=L$A({material:t?.material??"fr4",solder_mask_color:t?.solder_mask_color});return[(0,fTt.colorize)([C.r,C.g,C.b],o)]},Y$A=ts(adA()),Pw=ts(WgA()),juI=ts(RdI()),_$A=ts(VgA()),Ck=ts(I5()),rr=ts(g5()),Q3=ts(g5()),VTt=ts(VgA()),PdA=ts(I5()),jTt=ts(WgA()),zTt=64,XTt=(g,A,I)=>{const e=(0,Q3.ellipse)({center:[0,0],radius:[Math.max(g/2,Oo/2),Math.max(A/2,Oo/2)],segments:zTt}),t=(0,VTt.extrudeLinear)({height:I},e);return(0,PdA.translate)([0,0,-I/2],t)},$Tt=(g,A,I)=>{const e=Math.max(g,Oo),t=Math.max(A,Oo);if(Math.abs(e-t)<1e-6)return(0,Q3.cylinder)({center:[0,0,0],radius:e/2,height:I});const B=e>=t,o=B?e:t,C=B?t:e,Q=Math.max(o-C,0),i=(0,Q3.cuboid)({center:[0,0,0],size:B?[Q,C,I]:[C,Q,I]});if(Q<=1e-6)return(0,Q3.cylinder)({center:[0,0,0],radius:C/2,height:I});const E=Q/2,n=(0,Q3.cylinder)({center:B?[-E,0,0]:[0,-E,0],radius:C/2,height:I}),s=(0,Q3.cylinder)({center:B?[E,0,0]:[0,E,0],radius:C/2,height:I});return(0,jTt.union)(i,n,s)},LdA=(g,A,I={})=>{const e=g.hole_shape||"circle",t=I.sizeDelta??0,B=g.hole_offset_x||0,o=g.hole_offset_y||0,C=[g.x+B,g.y+o,0];if(e==="circle"){const r=Math.max((g.hole_diameter??0)+t,Oo),a=Math.max(r/2,Oo/2);return(0,Q3.cylinder)({center:C,radius:a,height:A})}const Q=g.hole_width??g.hole_diameter,i=g.hole_height??g.hole_diameter;if(!Q||!i)return null;const E=Math.max(Q+t,Oo),n=Math.max(i+t,Oo);if(e==="oval"){const r=XTt(E,n,A);return(0,PdA.translate)([C[0],C[1],0],r)}if(e==="pill"||e==="rotated_pill"){let r=$Tt(E,n,A);if(!r)return null;const a=g.ccw_rotation||0;return a&&(r=(0,PdA.rotateZ)(a*Math.PI/180,r)),(0,PdA.translate)(C,r)}const s=Math.max((g.hole_diameter??Q??i??Oo)+t,Oo);return(0,Q3.cylinder)({center:C,radius:s/2,height:A})},zE=ts(g5()),sx=ts(adA()),gc=ts(WgA()),zuI=ts(I5()),YdA=ts(VgA()),Qk=ts(I5()),AZt=1e-5;function XuI(g,A,I){if(typeof I!="number"||!Number.isFinite(I)||I<=0)return 0;const e=g/2,t=A/2,B=Math.min(e,t)-2*AZt;return Math.max(0,Math.min(I,B))}function i3(g){if(!(!g||typeof g!="object"))return g.corner_radius??g.cornerRadius??g.rect_pad_border_radius??g.rectPadBorderRadius??g.rect_border_radius??g.rectBorderRadius??void 0}var gZt=.05,b$A=64,t5=(g,A)=>A?(0,gc.intersect)(A,g):g,IIA=(g,A,I={})=>{const{clipGeom:e}=I;g.shape||(g.shape="circle");const t=Math.max(A.pcbThickness*.002,Oo/5),B=Math.max(A.pcbThickness*3e-4,Oo/20),o=Math.max(A.pcbThickness*.0025,Oo/4),C=A.pcbThickness+2*gZt+4*Oo,Q=Math.max(A.pcbThickness-2*(t+B+o),Oo),i=Math.max(Q,Oo);if(g.shape==="circle"){const E=g.outer_diameter??Math.max(g.hole_diameter,0),n=Q,s=(0,zE.cylinder)({center:[g.x,g.y,0],radius:E/2,height:n}),r=t5(s,e),a=(0,zE.cylinder)({center:[g.x,g.y,0],radius:Math.max(g.hole_diameter/2,.01),height:C});return(0,sx.colorize)(jE.copper,(0,gc.subtract)(r,a))}if(g.shape==="oval"){const E=g.outer_width||g.hole_width||0,n=g.outer_height||g.hole_height||0,s=g.hole_width||0,r=g.hole_height||0,a=(()=>{const l=(0,zE.cylinder)({center:[0,0,0],radius:1,height:Q,segments:64}),D=(0,zuI.scale)([E/2,n/2,1],l);return(0,Qk.translate)([g.x,g.y,0],D)})(),c=t5(a,e),h=(()=>{const l=(0,zE.cylinder)({center:[0,0,0],radius:1,height:C,segments:64}),D=(0,zuI.scale)([Math.max(s/2,.01),Math.max(r/2,.01),1],l);return(0,Qk.translate)([g.x,g.y,0],D)})();return(0,sx.colorize)(jE.copper,(0,gc.subtract)(c,h))}if(g.shape==="circular_hole_with_rect_pad"){const E=g.hole_offset_x||0,n=g.hole_offset_y||0,s=g.rect_pad_width||g.hole_diameter,r=g.rect_pad_height||g.hole_diameter,a=i3(g),c=t5((0,gc.union)((()=>{const D=(0,zE.roundedRectangle)({size:[s,r],roundRadius:a||0,segments:b$A}),d=(0,YdA.extrudeLinear)({height:Q},D);return(0,Qk.translate)([g.x,g.y,-Q/2],d)})(),(0,zE.cylinder)({center:[g.x+(E||0),g.y+(n||0),0],radius:g.hole_diameter/2,height:i})),e),h=(0,zE.cylinder)({center:[g.x+(E||0),g.y+(n||0),0],radius:Math.max(g.hole_diameter/2-Oo,.01),height:C}),l=(0,gc.subtract)(c,h);return I.clipGeom?(0,sx.colorize)(jE.copper,(0,gc.intersect)(l,I.clipGeom)):(0,sx.colorize)(jE.copper,l)}if(g.shape==="pill"){const E=(g.ccw_rotation||0)*Math.PI/180,n=R=>{if(!E)return R;const F=(0,Qk.translate)([-g.x,-g.y,0],R),N=(0,Qk.rotate)([0,0,E],F);return(0,Qk.translate)([g.x,g.y,0],N)},s=g.hole_height>g.hole_width,r=s?g.hole_height:g.hole_width,a=s?g.hole_width:g.hole_height,c=s?g.outer_height||a+.2:g.outer_width||r+.2,h=s?g.outer_width||r+.2:g.outer_height||a+.2,l=a/2,D=Math.abs(r-a),w=((R,F,N)=>{const U=F/2,P=Math.abs(R-F);if(P<=1e-6)return(0,zE.cylinder)({center:[g.x,g.y,0],radius:U,height:N});const b=(0,zE.cuboid)({center:[g.x,g.y,0],size:s?[F,P,N]:[P,F,N]}),H=(0,zE.cylinder)({center:s?[g.x,g.y-P/2,0]:[g.x-P/2,g.y,0],radius:U,height:N}),q=(0,zE.cylinder)({center:s?[g.x,g.y+P/2,0]:[g.x+P/2,g.y,0],radius:U,height:N});return(0,gc.union)(b,H,q)})(c,h,Q),u=(0,zE.cuboid)({center:[g.x,g.y,0],size:s?[a-2*Oo,D,C]:[D,a-2*Oo,C]}),G=(0,zE.cylinder)({center:s?[g.x,g.y-D/2,0]:[g.x-D/2,g.y,0],radius:l-Oo,height:C}),m=(0,zE.cylinder)({center:s?[g.x,g.y+D/2,0]:[g.x+D/2,g.y,0],radius:l-Oo,height:C}),p=(0,gc.union)(u,G,m),k=t5(n(w),e),S=n(p);return(0,sx.colorize)(jE.copper,(0,gc.subtract)(k,S))}if(g.shape==="pill_hole_with_rect_pad"){if(g.hole_shape&&g.hole_shape!=="pill"||g.pad_shape&&g.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for pill_hole_with_rect_pad");const E=g.hole_offset_x||0,n=g.hole_offset_y||0,s=g.hole_height>g.hole_width,r=s?g.hole_height:g.hole_width,a=s?g.hole_width:g.hole_height,c=a/2,h=Math.abs(r-a),l=g.rect_pad_width||r+.2,D=g.rect_pad_height||a+.2,d=i3(g),y=.03,w=(0,gc.union)((0,zE.cuboid)({center:[g.x+E,g.y+n,0],size:s?[a+2*y,h+2*y,i]:[h+2*y,a+2*y,i]}),(0,zE.cylinder)({center:s?[g.x+E,g.y+n-h/2,0]:[g.x+E-h/2,g.y+n,0],radius:c+y,height:i}),(0,zE.cylinder)({center:s?[g.x+E,g.y+n+h/2,0]:[g.x+E+h/2,g.y+n,0],radius:c+y,height:i})),u=(0,gc.union)((0,zE.cuboid)({center:[g.x+E,g.y+n,0],size:s?[a,h,C]:[h,a,C]}),(0,zE.cylinder)({center:s?[g.x+E,g.y+n-h/2,0]:[g.x+E-h/2,g.y+n,0],radius:c,height:C}),(0,zE.cylinder)({center:s?[g.x+E,g.y+n+h/2,0]:[g.x+E+h/2,g.y+n,0],radius:c,height:C})),G=(()=>{const R=(0,zE.roundedRectangle)({size:[l,D],roundRadius:d||0,segments:b$A}),F=(0,YdA.extrudeLinear)({height:Q},R);return(0,Qk.translate)([g.x,g.y,-Q/2],F)})(),m=(0,gc.subtract)(G,u),p=(0,gc.union)((0,zE.cuboid)({center:[g.x+E,g.y+n,0],size:s?[a-2*Oo,h-2*Oo,C]:[h-2*Oo,a-2*Oo,C]}),(0,zE.cylinder)({center:s?[g.x+E,g.y+n-h/2,0]:[g.x+E-h/2,g.y+n,0],radius:c-Oo,height:C}),(0,zE.cylinder)({center:s?[g.x+E,g.y+n+h/2,0]:[g.x+E+h/2,g.y+n,0],radius:c-Oo,height:C})),k=(0,gc.subtract)(w,p),S=t5((0,gc.union)(m,k),e);return(0,sx.colorize)(jE.copper,S)}else if(g.shape==="rotated_pill_hole_with_rect_pad"){if(g.hole_shape&&g.hole_shape!=="rotated_pill"||g.pad_shape&&g.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for rotated_pill_hole_with_rect_pad");const E=g.hole_offset_x||0,n=g.hole_offset_y||0,s=g.hole_width,r=g.hole_height,a=s>=r,c=a?s:r,h=a?r:s,l=h/2,D=Math.abs(c-h),d=g.rect_pad_width||s+.2,y=g.rect_pad_height||r+.2,w=i3(g),u=.03,G=(g.hole_ccw_rotation||0)*Math.PI/180,m=(g.rect_ccw_rotation||0)*Math.PI/180,p=H=>{const q=E*Math.cos(G)-n*Math.sin(G),j=E*Math.sin(G)+n*Math.cos(G),Z=(0,Qk.rotate)([0,0,G],H);return(0,Qk.translate)([g.x+q,g.y+j,0],Z)},k=H=>{if(!m)return H;const q=(0,Qk.translate)([-g.x,-g.y,0],H),j=(0,Qk.rotate)([0,0,m],q);return(0,Qk.translate)([g.x,g.y,0],j)},S=p((0,gc.union)((0,zE.cuboid)({center:[0,0,0],size:a?[D+2*u,h+2*u,i]:[h+2*u,D+2*u,i]}),(0,zE.cylinder)({center:a?[-D/2,0,0]:[0,-D/2,0],radius:l+u,height:i}),(0,zE.cylinder)({center:a?[D/2,0,0]:[0,D/2,0],radius:l+u,height:i}))),R=p((0,gc.union)((0,zE.cuboid)({center:[0,0,0],size:a?[D,h,C]:[h,D,C]}),(0,zE.cylinder)({center:a?[-D/2,0,0]:[0,-D/2,0],radius:l,height:C}),(0,zE.cylinder)({center:a?[D/2,0,0]:[0,D/2,0],radius:l,height:C}))),F=k((()=>{const H=(0,zE.roundedRectangle)({size:[d,y],roundRadius:w||0,segments:b$A}),q=(0,YdA.extrudeLinear)({height:Q},H);return(0,Qk.translate)([g.x,g.y,-Q/2],q)})()),N=(0,gc.subtract)(F,R),U=p((0,gc.union)((0,zE.cuboid)({center:[0,0,0],size:a?[D-2*Oo,h-2*Oo,C]:[h-2*Oo,D-2*Oo,C]}),(0,zE.cylinder)({center:a?[-D/2,0,0]:[0,-D/2,0],radius:l-Oo,height:C}),(0,zE.cylinder)({center:a?[D/2,0,0]:[0,D/2,0],radius:l-Oo,height:C}))),P=(0,gc.subtract)(S,U),b=t5((0,gc.union)(N,P),e);return(0,sx.colorize)(jE.copper,b)}else if(g.shape==="hole_with_polygon_pad"){const E=g.pad_outline;if(!Array.isArray(E)||E.length<3)throw new Error(`Invalid pad_outline for plated hole at (${g.x}, ${g.y})`);const n=E.map(y=>[y.x,y.y]),s=(0,zE.polygon)({points:n}),c=((y,w)=>{const u=Math.max(y,Oo),G=(0,YdA.extrudeLinear)({height:u},s);return(0,Qk.translate)([g.x,g.y,w-u/2],G)})(Q,0),h=t5(c,e),l=LdA(g,i);if(!l)return(0,sx.colorize)(jE.copper,h);const D=LdA(g,C,{sizeDelta:-2*Oo})||l;let d=(0,gc.union)((0,gc.subtract)(h,l),l);return I.clipGeom?(d=(0,gc.subtract)(d,D),d=(0,gc.intersect)(d,I.clipGeom),(0,sx.colorize)(jE.copper,d)):(0,sx.colorize)(jE.copper,(0,gc.subtract)(d,D))}else throw new Error(`Unsupported plated hole shape: ${g.shape}`)},IZt=ts(WgA()),eZt=ts(I5()),H$A=ts(g5());function tZt({x:g,y:A,outerDiameter:I,holeDiameter:e,thickness:t}){if(I<=e)throw new Error(`Invalid via geometry: outerDiameter (${I}) must be > holeDiameter (${e})`);const B=Oo,o=Math.min(I/2,e/2+B),Q=(0,H$A.cylinder)({center:[0,0,0],radius:o,height:t,segments:fd}),i=t+2*Oo,E=(0,H$A.cylinder)({center:[0,0,0],radius:e/2,height:i,segments:fd}),n=(0,IZt.subtract)(Q,E);return(0,eZt.translate)([g,A,0],n)}function BZt({x:g,y:A,holeDiameter:I,thickness:e}){const t=e*1.5,B=I/2+Oo;return(0,H$A.cylinder)({center:[g,A,0],radius:B,height:t,segments:fd})}function v$A(g){const A=qpg(g),I=[...jB(g).pcb_via.list()],e=new Map;for(const t of I){const o=`${A.get(t.pcb_via_id)?.pcb_board_id??""}:${t.x}:${t.y}`,C=e.get(o)??[];C.push(t),e.set(o,C)}for(const t of jB(g).pcb_trace.list()){const B=A.get(t.pcb_trace_id);for(const[o,C]of t.route.entries()){if(C.route_type!=="via")continue;const Q=`${B?.pcb_board_id??""}:${C.x}:${C.y}`,i=e.get(Q)??[];if(i.some(s=>s.layers.includes(C.from_layer)&&s.layers.includes(C.to_layer)))continue;const n={type:"pcb_via",pcb_via_id:`${t.pcb_trace_id}_route_via_${o}`,pcb_trace_id:t.pcb_trace_id,subcircuit_id:t.subcircuit_id,pcb_group_id:t.pcb_group_id,x:C.x,y:C.y,layers:[C.from_layer,C.to_layer],hole_diameter:C.hole_diameter??B?.min_via_hole_diameter??.25,outer_diameter:C.outer_diameter??B?.min_via_pad_diameter??.6,tented_on_top:C.tented_on_top,tented_on_bottom:C.tented_on_bottom};I.push(n),i.push(n),e.set(Q,i)}}return I}var oZt=64,CZt=1,q$A=.05,$uI=["initializing","processing_plated_holes","processing_holes","processing_cutouts","processing_vias","finalizing","done"],QZt=class{board;plated_holes;holes;pcb_vias;pcb_cutouts;boardGeom=null;platedHoleGeoms=[];viaGeoms=[];copperDrills=[];boardClipGeom=null;state="initializing";currentIndex=0;ctx;onCompleteCallback;finalGeoms=[];constructor(g,A){this.onCompleteCallback=A;const I=g.filter(t=>t.type==="pcb_panel"),e=jB(g).pcb_board.list();if(I.length>0){const t=I[0],B=e.find(o=>o.pcb_panel_id===t.pcb_panel_id);this.board={type:"pcb_board",pcb_board_id:t.pcb_panel_id,center:t.center,width:t.width,height:t.height,thickness:B?.thickness??1.4,material:B?.material??"fr4",num_layers:B?.num_layers??2,solder_mask_color:B?.solder_mask_color}}else{const t=e.filter(B=>!B.pcb_panel_id);this.board=t[0]}this.plated_holes=jB(g).pcb_plated_hole.list(),this.holes=jB(g).pcb_hole.list(),this.pcb_vias=v$A(g),this.pcb_cutouts=jB(g).pcb_cutout.list(),this.ctx={pcbThickness:this.board.thickness??1.2},this.initializeBoard()}initializeBoard(){const g=this.ctx.pcbThickness+2*CZt;this.board.outline&&this.board.outline.length>0?(this.boardGeom=P$A({outline:this.board.outline},this.ctx.pcbThickness),this.boardClipGeom=P$A({outline:this.board.outline},g,{xyOutset:q$A})):(this.boardGeom=(0,rr.cuboid)({size:[this.board.width,this.board.height,this.ctx.pcbThickness],center:[this.board.center.x,this.board.center.y,0]}),this.boardClipGeom=(0,rr.cuboid)({size:[this.board.width+2*q$A,this.board.height+2*q$A,g],center:[this.board.center.x,this.board.center.y,0]})),this.state="processing_plated_holes",this.currentIndex=0}goToNextState(){const g=$uI.indexOf(this.state);g!==-1&&(this.state=$uI[g+1],this.currentIndex=0)}step(g=1){if(this.state==="done"||!this.boardGeom)return!0;for(let A=0;A<g&&this.state!=="done";A++)switch(this.state){case"processing_plated_holes":this.currentIndex<this.plated_holes.length?(this.processPlatedHole(this.plated_holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_holes":this.currentIndex<this.holes.length?(this.processHole(this.holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_vias":this.currentIndex<this.pcb_vias.length?(this.processVia(this.pcb_vias[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_cutouts":this.currentIndex<this.pcb_cutouts.length?(this.processCutout(this.pcb_cutouts[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"finalizing":this.finalize(),this.state="done";break}return this.state==="done"}processCutout(g){if(!this.boardGeom)return;let A=null;const I=this.ctx.pcbThickness*1.5;switch(g.shape){case"rect":{const e=XuI(g.width,g.height,i3(g));if(e>0){const t=(0,rr.roundedRectangle)({size:[g.width,g.height],roundRadius:e,segments:oZt});A=(0,_$A.extrudeLinear)({height:I},t),A=(0,Ck.translate)([0,0,-I/2],A)}else A=(0,rr.cuboid)({center:[0,0,0],size:[g.width,g.height,I]});if(g.rotation){const t=g.rotation*Math.PI/180;A=(0,Ck.rotateZ)(t,A)}A=(0,Ck.translate)([g.center.x,g.center.y,0],A);break}case"circle":A=(0,rr.cylinder)({center:[g.center.x,g.center.y,0],radius:g.radius,height:I});break;case"polygon":{let e=g.points.map(B=>[B.x,B.y]);if(e.length<3){console.warn(`PCB Cutout [${g.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);break}OuI(e)&&(e=e.reverse());const t=(0,rr.polygon)({points:e});A=(0,_$A.extrudeLinear)({height:I},t),A=(0,Ck.translate)([0,0,-I/2],A);break}}A&&(this.boardGeom=(0,Pw.subtract)(this.boardGeom,A))}processPlatedHole(g,A={}){if(this.boardGeom){if(g.shape==="circle"||g.shape==="circular_hole_with_rect_pad"){let I=null;if(g.shape==="circular_hole_with_rect_pad"){if(g.hole_shape&&g.hole_shape!=="circle"||g.pad_shape&&g.pad_shape!=="rect")return;I=(0,rr.cylinder)({center:[g.x+(g.hole_offset_x||0),g.y+(g.hole_offset_y||0),0],radius:g.hole_diameter/2+Oo,height:this.ctx.pcbThickness*1.5})}else I=(0,rr.cylinder)({center:[g.x,g.y,0],radius:g.hole_diameter/2+Oo,height:this.ctx.pcbThickness*1.5});A.dontCutBoard||(this.boardGeom=(0,Pw.subtract)(this.boardGeom,I),this.copperDrills.push({geom:I,platedHoleIndex:this.platedHoleGeoms.length}));const e=IIA(g,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(e)}else if(g.shape==="pill"||g.shape==="oval"){const I=g.hole_height>g.hole_width,e=I?g.hole_height:g.hole_width,t=I?g.hole_width:g.hole_height,B=t/2,o=Math.abs(e-t);let C;if(C=(0,Pw.union)((0,rr.cuboid)({center:[g.x,g.y,0],size:I?[t,o,this.ctx.pcbThickness*1.5]:[o,t,this.ctx.pcbThickness*1.5]}),(0,rr.cylinder)({center:I?[g.x,g.y-o/2,0]:[g.x-o/2,g.y,0],radius:B,height:this.ctx.pcbThickness*1.5}),(0,rr.cylinder)({center:I?[g.x,g.y+o/2,0]:[g.x+o/2,g.y,0],radius:B,height:this.ctx.pcbThickness*1.5})),g.ccw_rotation){const i=g.ccw_rotation*Math.PI/180;C=(0,Ck.translate)([g.x,g.y,0],(0,Ck.rotateZ)(i,(0,Ck.translate)([-g.x,-g.y,0],C)))}A.dontCutBoard||(this.boardGeom=(0,Pw.subtract)(this.boardGeom,C),this.copperDrills.push({geom:C,platedHoleIndex:this.platedHoleGeoms.length}));const Q=IIA(g,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(Q)}else if(g.shape==="pill_hole_with_rect_pad"){if(g.hole_shape&&g.hole_shape!=="pill"||g.pad_shape&&g.pad_shape!=="rect")return;const I=g.hole_height>g.hole_width,e=I?g.hole_height:g.hole_width,t=I?g.hole_width:g.hole_height,B=t/2,o=Math.abs(e-t);let C;C=(0,Pw.union)((0,rr.cuboid)({center:[g.x+(g.hole_offset_x||0),g.y+(g.hole_offset_y||0),0],size:I?[t,o,this.ctx.pcbThickness*1.5]:[o,t,this.ctx.pcbThickness*1.5]}),(0,rr.cylinder)({center:I?[g.x+(g.hole_offset_x||0),g.y+(g.hole_offset_y||0)-o/2,0]:[g.x+(g.hole_offset_x||0)-o/2,g.y+(g.hole_offset_y||0),0],radius:B,height:this.ctx.pcbThickness*1.5}),(0,rr.cylinder)({center:I?[g.x+(g.hole_offset_x||0),g.y+(g.hole_offset_y||0)+o/2,0]:[g.x+(g.hole_offset_x||0)+o/2,g.y+(g.hole_offset_y||0),0],radius:B,height:this.ctx.pcbThickness*1.5})),A.dontCutBoard||(this.boardGeom=(0,Pw.subtract)(this.boardGeom,C),this.copperDrills.push({geom:C,platedHoleIndex:this.platedHoleGeoms.length}));const Q=IIA(g,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(Q)}else if(g.shape==="rotated_pill_hole_with_rect_pad"){if(g.hole_shape&&g.hole_shape!=="rotated_pill"||g.pad_shape&&g.pad_shape!=="rect")return;const I=g.hole_width,e=g.hole_height,t=I>=e,B=t?I:e,o=t?e:I,C=o/2,Q=Math.abs(B-o),i=g.hole_offset_x||0,E=g.hole_offset_y||0;let n=(0,Pw.union)((0,rr.cuboid)({center:[0,0,0],size:t?[Q,o,this.ctx.pcbThickness*1.5]:[o,Q,this.ctx.pcbThickness*1.5]}),(0,rr.cylinder)({center:t?[-Q/2,0,0]:[0,-Q/2,0],radius:C,height:this.ctx.pcbThickness*1.5}),(0,rr.cylinder)({center:t?[Q/2,0,0]:[0,Q/2,0],radius:C,height:this.ctx.pcbThickness*1.5}));const s=(g.hole_ccw_rotation||0)*Math.PI/180,r=i*Math.cos(s)-E*Math.sin(s),a=i*Math.sin(s)+E*Math.cos(s);n=(0,Ck.rotateZ)(s,n);const c=(0,Ck.translate)([g.x+r,g.y+a,0],n);A.dontCutBoard||(this.boardGeom=(0,Pw.subtract)(this.boardGeom,c),this.copperDrills.push({geom:c,platedHoleIndex:this.platedHoleGeoms.length}));const h=IIA(g,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(h)}else if(g.shape==="hole_with_polygon_pad"){const I=g.pad_outline;if(!Array.isArray(I)||I.length<3)return;const e=this.ctx.pcbThickness*1.5,t=LdA(g,e,{sizeDelta:2*Oo}),B=LdA(g,e,{sizeDelta:-2*Oo});if(!t||!B)return;A.dontCutBoard||(this.boardGeom=(0,Pw.subtract)(this.boardGeom,t),this.copperDrills.push({geom:t,platedHoleIndex:this.platedHoleGeoms.length}));const o=IIA(g,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(o)}}}processHole(g){if(!this.boardGeom)return;const A=this.ctx.pcbThickness*1.5;if(g.hole_shape==="circle"){const I=(0,rr.cylinder)({center:[g.x,g.y,0],radius:g.hole_diameter/2+Oo,height:A});this.boardGeom=(0,Pw.subtract)(this.boardGeom,I);const e=(0,rr.cylinder)({center:[g.x,g.y,0],radius:g.hole_diameter/2+Oo/2,height:A});this.copperDrills.push({geom:e})}else if(g.hole_shape==="pill"||g.hole_shape==="rotated_pill"||g.hole_shape==="rect"||g.hole_shape==="oval"){const I=g.hole_width??g.hole_diameter,e=g.hole_height??g.hole_diameter,t=g.ccw_rotation??g.rotation??0,B=.02,o=(i,E,n,s)=>{if(i<=0||E<=0)return null;if(g.hole_shape==="rect")return(0,rr.cuboid)({center:[0,0,0],size:[i,E,n]});if(s)return(0,Ck.translate)([0,0,-n/2],(0,_$A.extrudeLinear)({height:n},(0,rr.ellipse)({radius:[i/2,E/2]})));const r=Math.min(i,E)/2,a=Math.abs(i-E);return i>E?(0,Pw.union)((0,rr.cuboid)({center:[0,0,0],size:[a,E,n]}),(0,rr.cylinder)({center:[-a/2,0,0],radius:r,height:n}),(0,rr.cylinder)({center:[a/2,0,0],radius:r,height:n})):(0,Pw.union)((0,rr.cuboid)({center:[0,0,0],size:[i,a,n]}),(0,rr.cylinder)({center:[0,-a/2,0],radius:r,height:n}),(0,rr.cylinder)({center:[0,a/2,0],radius:r,height:n}))};let C=o(I,e,A,g.hole_shape==="oval"),Q=o(I-2*B,e-2*B,A,g.hole_shape==="oval");if(C&&t!==0&&(C=(0,Ck.rotateZ)(t*Math.PI/180,C)),Q&&t!==0&&(Q=(0,Ck.rotateZ)(t*Math.PI/180,Q)),C){const i=(0,Ck.translate)([g.x,g.y,0],C);this.boardGeom=(0,Pw.subtract)(this.boardGeom,i)}if(Q){const i=(0,Ck.translate)([g.x,g.y,0],Q);this.copperDrills.push({geom:i})}}}processVia(g){if(!this.boardGeom)return;let A;if(typeof g.outer_diameter=="number"&&typeof g.hole_diameter=="number"){const I=tZt({x:g.x,y:g.y,outerDiameter:g.outer_diameter,holeDiameter:g.hole_diameter,thickness:this.ctx.pcbThickness});let e=I;this.boardClipGeom&&(e=(0,Pw.intersect)(this.boardClipGeom,I),e=(0,Y$A.colorize)(jE.copper,e)),A=this.viaGeoms.length,this.viaGeoms.push(e)}if(typeof g.hole_diameter=="number"){const I=BZt({x:g.x,y:g.y,holeDiameter:g.hole_diameter,thickness:this.ctx.pcbThickness});this.boardGeom=(0,Pw.subtract)(this.boardGeom,I),this.copperDrills.push({geom:I,viaIndex:A})}}finalize(){if(!this.boardGeom)return;const g=this.copperDrills.map(e=>({...e,bounds:(0,juI.measureBoundingBox)(e.geom)})),A=(e,t,B)=>{const o=(0,juI.measureBoundingBox)(e),C=g.filter(Q=>Q[B]!==t&&[0,1,2].every(i=>Q.bounds[0][i]<=o[1][i]&&Q.bounds[1][i]>=o[0][i])).map(Q=>Q.geom);return(0,Y$A.colorize)(jE.copper,C.length?(0,Pw.subtract)(e,(0,Pw.union)(...C)):e)};this.platedHoleGeoms=this.platedHoleGeoms.map((e,t)=>A(e,t,"platedHoleIndex")),this.viaGeoms=this.viaGeoms.map((e,t)=>A(e,t,"viaIndex"));const I=L$A(this.board);this.boardGeom=(0,Y$A.colorize)([I.r,I.g,I.b],this.boardGeom),this.finalGeoms=[this.boardGeom,...this.platedHoleGeoms,...this.viaGeoms],this.onCompleteCallback&&this.onCompleteCallback(this.finalGeoms)}getGeoms(){return this.finalGeoms}},iZt=g=>{const[A,I]=gA.useState(null),e=gA.useRef(!1);return gA.useEffect(()=>{let t=!1;if(!g){I(null);return}if(!g.some(i=>i.type==="pcb_board"||i.type==="pcb_panel")){I(null);return}const o=WTt(g);I(o);const C=new QZt(g,i=>{});return(async()=>{if(!e.current){e.current=!0;try{let i=!1;for(;!i&&!t;)i=C.step(1),i||await new Promise(E=>setTimeout(E,0));t||I(C.getGeoms())}catch(i){console.error("Error during board geometry building:",i)}finally{e.current=!1}}})(),()=>{t=!0}},[g]),A},EZt=({children:g,parent:A,position:I,rotation:e,scale:t,color:B,fontSize:o,anchorX:C,anchorY:Q,depthOffset:i})=>{const{rootObject:E}=SD(),n=gA.useMemo(()=>{const s=new YKA;return s.text=g,I&&s.position.fromArray(I),e&&s.rotation.fromArray(e),t&&s.scale.fromArray(t),s.color=B||"white",s.fontSize=o||1,s.anchorX=C||"center",s.anchorY=Q||"middle",s.depthOffset=i||0,s.font=null,s.sync(),s},[g,I,e,t,B,o,C,Q,i]);return gA.useEffect(()=>{const s=A||E;if(!(!s||!n))return s.add(n),()=>{s.remove(n),n.dispose()}},[E,A,n]),null},AGI=({error:g,cad_component:A})=>{const{rootObject:I}=SD(),[e,t]=gA.useState(!1),[B,o]=gA.useState(null),C=gA.useCallback(n=>{n?.mousePosition?(t(!0),o(n.mousePosition)):(t(!1),o(null))},[]),Q=gA.useCallback(()=>{t(!1),o(null)},[]),i=gA.useMemo(()=>A?.position?[A.position.x,A.position.y,A.position.z].map(s=>Number.isNaN(s)?0:s):[0,0,0],[A]),E=gA.useMemo(()=>{const n=new Nc;return n.position.fromArray(i),n},[i]);return E.userData.cad_component_id=A?.cad_component_id,E.userData.pcb_component_id=A?.pcb_component_id,gA.useEffect(()=>{if(I)return I.add(E),()=>{I.remove(E)}},[I,E]),W.jsxs(W.Fragment,{children:[W.jsxs(AIA,{isHovered:e,onHover:C,onUnhover:Q,object:E,children:[W.jsx(nZt,{parent:E}),W.jsx(EZt,{parent:E,scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:`${g.toString().slice(0,50)}...`})]}),e&&B?W.jsx(puI,{position:B,style:{fontFamily:"sans-serif",transform:"translate3d(-1rem, 0rem, 0)",backgroundColor:"white",padding:"6px",borderRadius:"4px",color:"red",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:g.toString()}):null]})},nZt=({parent:g})=>{const A=gA.useMemo(()=>{const I=new FB(new Jp(.5,.5,.5),new Ps({depthTest:!1,transparent:!0,color:"red",opacity:.5}));return I.renderOrder=999999,I.rotation.fromArray([Math.PI/4,Math.PI/4,0]),I},[]);return gA.useEffect(()=>(g.add(A),()=>{g.remove(A)}),[g,A]),null},sZt=g=>{if(g.length===0)return null;let A=g[0].x,I=g[0].y,e=g[0].x,t=g[0].y;for(let B=1;B<g.length;B++){const o=g[B];o.x<A&&(A=o.x),o.y<I&&(I=o.y),o.x>e&&(e=o.x),o.y>t&&(t=o.y)}return{minX:A,minY:I,maxX:e,maxY:t}};function ky(g){if(g.outline&&g.outline.length>=3){const o=sZt(g.outline);return{...o,width:o.maxX-o.minX,height:o.maxY-o.minY,centerX:(o.minX+o.maxX)/2,centerY:(o.minY+o.maxY)/2}}const A=g.width??0,I=g.height??0,e=g.center?.x??0,t=g.center?.y??0;return{...{minX:e-A/2,maxX:e+A/2,minY:t-I/2,maxY:t+I/2},width:A,height:I,centerX:e,centerY:t}}function aZt(g,A,I){const e=v$A(g);if(!e.length)return[];const t=ky(A),B=Math.floor(t.width*I),o=Math.floor(t.height*I);if(B<=0||o<=0)return[];const C=new Set;for(const Q of["top","bottom"]){const i=g.filter(a=>(a.type==="pcb_smtpad"&&a.layer===Q||a.type==="pcb_plated_hole"&&(!Array.isArray(a.layers)||a.layers.includes(Q)))&&a.is_covered_with_solder_mask!==!0);if(!i.length)continue;const E=document.createElement("canvas");E.width=B,E.height=o;const n=E.getContext("2d");if(!n)continue;const s=new VE(n);s.configure({colorOverrides:{copper:{top:"white",bottom:"white",inner1:"white",inner2:"white",inner3:"white",inner4:"white",inner5:"white",inner6:"white",inner7:"white",inner8:"white"},drill:"rgba(0,0,0,0)"}}),s.setCameraBounds(t),s.drawElements(i,{layers:[Q==="top"?"top_copper":"bottom_copper"],drawSoldermask:!1});const r=n.getImageData(0,0,B,o).data;for(const a of e){if(C.has(a)||!a.layers.includes(Q))continue;const c=a.outer_diameter/2,h=(a.x-t.minX)*B/t.width,l=(t.maxY-a.y)*o/t.height,D=c*B/t.width,d=c*o/t.height;if(D<=0||d<=0)continue;const y=Math.max(0,Math.floor(h-D)),w=Math.min(B-1,Math.ceil(h+D)),u=Math.max(0,Math.floor(l-d)),G=Math.min(o-1,Math.ceil(l+d));let m=!1;for(let p=u;p<=G&&!m;p++)for(let k=y;k<=w;k++)if(r[(p*B+k)*4+3]>=128&&((k+.5-h)/D)**2+((p+.5-l)/d)**2<=1){m=!0;break}m&&C.add(a)}}return[...C]}function rZt({ctx:g,vias:A,boardData:I,layer:e,width:t,height:B}){if(!A.length)return;const o=ky(I);g.save(),g.globalCompositeOperation="destination-out",g.fillStyle="black";for(const C of A){if(!C.layers.includes(e))continue;const Q=(C.x-o.minX)*t/o.width,i=(e==="top"?o.maxY-C.y:C.y-o.minY)*B/o.height;g.beginPath(),g.ellipse(Q,i,C.hole_diameter/2*t/o.width,C.hole_diameter/2*B/o.height,0,0,Math.PI*2),g.fill()}g.restore()}function cZt({layer:g,circuitJson:A,boardData:I,copperColor:e,traceTextureResolution:t}){const o=jB(A).pcb_smtpad.list().filter(w=>w.layer===g);if(o.length===0)return null;const C=jB(A).pcb_hole.list(),Q=jB(A).pcb_plated_hole.list().filter(w=>!Array.isArray(w.layers)||w.layers.includes(g)),i=jB(A).pcb_via.list().filter(w=>!Array.isArray(w.layers)||w.layers.includes(g)),E=jB(A).pcb_cutout.list(),n=[...C,...Q,...i],s=g==="top"?"top_copper":"bottom_copper",r=ky(I),a=document.createElement("canvas"),c=Math.floor(r.width*t),h=Math.floor(r.height*t);a.width=c,a.height=h;const l=a.getContext("2d");if(!l)return null;g==="bottom"&&(l.translate(0,h),l.scale(1,-1));const D="rgba(0,0,0,0)",d=new VE(l);d.configure({colorOverrides:{copper:{top:e,bottom:e,inner1:e,inner2:e,inner3:e,inner4:e,inner5:e,inner6:e,inner7:e,inner8:e},copperPour:{top:D,bottom:D},drill:D,boardOutline:D,substrate:D,keepout:{top:D,bottom:D},fabricationNote:D,courtyard:{top:D,bottom:D},silkscreen:{top:D,bottom:D},soldermask:{top:D,bottom:D},soldermaskWithCopperUnderneath:{top:D,bottom:D},soldermaskOverCopper:{top:D,bottom:D}}}),d.setCameraBounds({minX:r.minX,maxX:r.maxX,minY:r.minY,maxY:r.maxY}),d.drawElements([...o,...n,...E],{layers:[s],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});const y=new Kp(a);return y.generateMipmaps=!0,y.minFilter=wl,y.magFilter=Un,y.anisotropy=16,y.needsUpdate=!0,y}var hZt=g=>{const A=g.filter(I=>I.type==="pcb_panel");return A.length===0?null:A.length===1?A[0].pcb_panel_id:null};function lZt({layer:g,circuitJson:A,panelData:I,outlineColor:e="black",traceTextureResolution:t}){const B=hZt(A);if(!B)return null;const C=jB(A).pcb_board.list().filter(c=>c.pcb_panel_id===B||c.position_mode==="relative_to_panel_anchor"&&!c.pcb_panel_id);if(C.length===0)return null;const Q=document.createElement("canvas"),i=Math.floor(I.width*t),E=Math.floor(I.height*t);Q.width=i,Q.height=E;const n=Q.getContext("2d");if(!n)return null;g==="bottom"&&(n.translate(0,E),n.scale(1,-1)),n.strokeStyle=e,n.lineWidth=.05*t;const s=c=>(c-I.center.x+I.width/2)*t,r=c=>(-(c-I.center.y)+I.height/2)*t;C.forEach(c=>{if(c.outline&&c.outline.length>=2)n.beginPath(),c.outline.forEach((h,l)=>{const D=s(h.x),d=r(h.y);l===0?n.moveTo(D,d):n.lineTo(D,d)}),n.closePath(),n.stroke();else{const h=c.width,l=c.height,{x:D,y:d}=c.center,y=s(D-h/2),w=r(d+l/2);n.strokeRect(y,w,h*t,l*t)}});const a=new Kp(Q);return a.generateMipmaps=!0,a.minFilter=wl,a.magFilter=Un,a.anisotropy=16,a.needsUpdate=!0,a}function DZt({layer:g,circuitJson:A,boardData:I,traceColor:e,traceTextureResolution:t}){const B=jB(A).pcb_trace.list(),o=jB(A).pcb_via.list(),C=jB(A).pcb_plated_hole.list(),Q=g==="top"?"top_copper":"bottom_copper",i=B.filter(y=>Xpg(y).includes(Q));if(i.length===0)return null;const E=C.filter(y=>y.layers.includes(g)),n=[...i,...o,...E],s=ky(I),r=document.createElement("canvas"),a=Math.floor(s.width*t),c=Math.floor(s.height*t);r.width=a,r.height=c;const h=r.getContext("2d");if(!h)return null;g==="bottom"&&(h.translate(0,c),h.scale(1,-1));const l="rgba(0,0,0,0)",D=new VE(h);D.configure({colorOverrides:{copper:{top:e,bottom:e,inner1:e,inner2:e,inner3:e,inner4:e,inner5:e,inner6:e,inner7:e,inner8:e},copperPour:{top:l,bottom:l},drill:l,boardOutline:l,substrate:l,keepout:{top:l,bottom:l},fabricationNote:l,courtyard:{top:l,bottom:l},silkscreen:{top:l,bottom:l},soldermask:{top:l,bottom:l},soldermaskWithCopperUnderneath:{top:l,bottom:l},soldermaskOverCopper:{top:l,bottom:l}}}),D.setCameraBounds({minX:s.minX,maxX:s.maxX,minY:s.minY,maxY:s.maxY}),D.drawElements(n,{layers:[Q],clipContextElements:A,drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});const d=new Kp(r);return d.generateMipmaps=!0,d.minFilter=wl,d.magFilter=Un,d.anisotropy=16,d.needsUpdate=!0,d}var dZt=g=>{const[A=0,I=0,e=0]=g;return`rgb(${Math.round(A*255)}, ${Math.round(I*255)}, ${Math.round(e*255)})`},yZt=8;function gGI({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=K2,copperColor:t=dZt(jE.copper),onlyCoveredBySoldermask:B=!1}){const o=A.filter(p=>p.type==="pcb_copper_pour"),C=g==="top"?"top_copper":"bottom_copper",Q=o.filter(p=>p.layer===g&&(!B||p.covered_with_solder_mask!==!1));if(Q.length===0)return null;const i=A.filter(p=>p.type==="pcb_hole"),E=A.filter(p=>p.type!=="pcb_plated_hole"?!1:!Array.isArray(p.layers)||p.layers.includes(g)),n=A.filter(p=>p.type!=="pcb_via"?!1:!Array.isArray(p.layers)||p.layers.includes(g)),s=[...i,...E,...n],r=ky(I),a=document.createElement("canvas"),c=Math.floor(r.width*e),h=Math.floor(r.height*e);a.width=c,a.height=h;const l=a.getContext("2d");if(!l)return null;g==="bottom"&&(l.translate(0,h),l.scale(1,-1));const D="rgba(0,0,0,0)",d=t,y=t,w=(p,k)=>{if(p.length===0)return;const S=[...p,...s],R=new VE(l);R.configure({colorOverrides:{copper:{top:k,bottom:k,inner1:k,inner2:k,inner3:k,inner4:k,inner5:k,inner6:k,inner7:k,inner8:k},copperPour:{top:D,bottom:D},drill:D,boardOutline:D,substrate:D,keepout:{top:D,bottom:D},fabricationNote:D,courtyard:{top:D,bottom:D},silkscreen:{top:D,bottom:D},soldermask:{top:D,bottom:D},soldermaskWithCopperUnderneath:{top:D,bottom:D},soldermaskOverCopper:{top:D,bottom:D}}}),R.setCameraBounds({minX:r.minX,maxX:r.maxX,minY:r.minY,maxY:r.maxY}),R.drawElements(S,{layers:[C],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});for(let F=1;F<yZt;F+=1)R.drawElements(S,{layers:[C],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1})},u=Q.filter(p=>p.covered_with_solder_mask!==!1),G=Q.filter(p=>p.covered_with_solder_mask===!1);w(u,d),B||w(G,y);const m=new Kp(a);return m.generateMipmaps=!0,m.minFilter=wl,m.magFilter=Un,m.anisotropy=16,m.needsUpdate=!0,m}var IGI=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},wZt=({ctx:g,layer:A,bounds:I,elements:e,copperColor:t})=>{const B=A==="top"?"top_copper":"bottom_copper",o=new VE(g);o.configure({colorOverrides:{copper:{top:t,bottom:t,inner1:t,inner2:t,inner3:t,inner4:t,inner5:t,inner6:t,inner7:t,inner8:t}}}),IGI(o,I),o.drawElements(e,{layers:[B]});const C=e.filter(n=>n.type==="pcb_copper_text"&&n.is_knockout===!0);if(C.length===0)return;const Q=document.createElement("canvas");Q.width=g.canvas.width,Q.height=g.canvas.height;const i=Q.getContext("2d");if(!i)return;const E=new VE(i);E.configure({colorOverrides:{copper:{top:"rgb(255,255,255)",bottom:"rgb(255,255,255)",inner1:"rgb(255,255,255)",inner2:"rgb(255,255,255)",inner3:"rgb(255,255,255)",inner4:"rgb(255,255,255)",inner5:"rgb(255,255,255)",inner6:"rgb(255,255,255)",inner7:"rgb(255,255,255)",inner8:"rgb(255,255,255)"}}}),IGI(E,I),E.drawElements(C.map(n=>({...n,is_knockout:!1})),{layers:[B]}),g.save(),g.globalCompositeOperation="destination-out",g.drawImage(Q,0,0),g.restore()};function uZt({layer:g,circuitJson:A,boardData:I,copperColor:e="rgb(230, 153, 51)",traceTextureResolution:t=K2}){const B=A.filter(s=>s.type==="pcb_copper_text"&&"layer"in s&&s.layer===g);if(B.length===0)return null;const o=ky(I),C=Math.floor(o.width*t),Q=Math.floor(o.height*t);if(C<=0||Q<=0)return null;const i=document.createElement("canvas");i.width=C,i.height=Q;const E=i.getContext("2d");if(!E)return null;g==="bottom"&&(E.translate(0,Q),E.scale(1,-1)),wZt({ctx:E,layer:g,bounds:o,elements:B,copperColor:e});const n=new Kp(i);return n.generateMipmaps=!0,n.minFilter=wl,n.magFilter=Un,n.anisotropy=16,n.needsUpdate=!0,n}var eGI=25.4,GZt=eGI/1e3,mZt=/^\s*(-?\d*(?:\.\d+)?)(?:\s*(mm|mil|inch|in|"))?\s*$/i;function pZt(g){if(!g)return;const A=g.trim().toLowerCase();return A==='"'||A==="inch"?"in":A}function _dA(g){if(g==null)return;if(typeof g=="number")return Number.isFinite(g)?g:void 0;if(typeof g!="string")return;const A=g.trim();if(A.length===0)return;const I=A.match(mZt);if(!I){const C=Number.parseFloat(A);return Number.isFinite(C)?C:void 0}const[,e,t]=I,B=Number.parseFloat(e||"0");if(!Number.isFinite(B))return;switch(pZt(t)){case"mil":return B*GZt;case"in":return B*eGI;case"mm":case void 0:return B;default:return B}}function vs(g,A){const I=_dA(g);return I===void 0?A:I}var kZt="rgb(255,243,204)",cr="rgba(0,0,0,0)",MZt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},SZt=g=>g.type==="pcb_fabrication_note_rect"?{...g,width:_dA(g.width)??0,height:_dA(g.height)??0,stroke_width:vs(g.stroke_width,.1),corner_radius:_dA(g.corner_radius)}:g.type==="pcb_fabrication_note_path"?{...g,stroke_width:vs(g.stroke_width,.1)}:g.type==="pcb_fabrication_note_text"?{...g,font_size:vs(g.font_size,1)}:g.type==="pcb_fabrication_note_dimension"?{...g,font_size:vs(g.font_size,1),arrow_size:vs(g.arrow_size,1),offset_distance:vs(g.offset_distance,0)}:g,fZt=({ctx:g,layer:A,bounds:I,elements:e})=>{const t=`${A}_fabrication_note`,B=e.map(SZt),o=new VE(g);o.configure({colorOverrides:{copper:{top:cr,bottom:cr,inner1:cr,inner2:cr,inner3:cr,inner4:cr,inner5:cr,inner6:cr,inner7:cr,inner8:cr},copperPour:{top:cr,bottom:cr},drill:cr,boardOutline:cr,substrate:cr,keepout:{top:cr,bottom:cr},courtyard:{top:cr,bottom:cr},soldermask:{top:cr,bottom:cr},soldermaskWithCopperUnderneath:{top:cr,bottom:cr},soldermaskOverCopper:{top:cr,bottom:cr},silkscreen:{top:cr,bottom:cr},fabricationNote:kZt}}),MZt(o,I),o.drawElements(B,{layers:[t]})},RZt=g=>({minX:g.center.x-g.width/2,maxX:g.center.x+g.width/2,minY:g.center.y-g.height/2,maxY:g.center.y+g.height/2,width:g.width,height:g.height,centerX:g.center.x,centerY:g.center.y}),NZt=(g,A)=>{const I=Math.min(g.minX,A.minX),e=Math.max(g.maxX,A.maxX),t=Math.min(g.minY,A.minY),B=Math.max(g.maxY,A.maxY);return{minX:I,maxX:e,minY:t,maxY:B,width:e-I,height:B-t,centerX:(I+e)/2,centerY:(t+B)/2}},bdA=(g,A)=>{const I=g.filter(o=>o.type==="pcb_panel"),e=g.filter(o=>o.type==="pcb_board"),t=I.find(o=>o.pcb_panel_id===A.pcb_board_id)??I[0];return t&&t.width>0&&t.height>0?RZt(t):(e.length>1?e:[A]).map(o=>ky(o)).reduce((o,C)=>NZt(o,C))},xZt=(g,A)=>{if(!("layer"in g)||g.layer!==A)return!1;const I=g.type;return I.startsWith("pcb_fabrication_note_")&&I!=="pcb_fabrication_note_text"&&I!=="pcb_fabrication_note_dimension"};function FZt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=K2}){const t=A.filter(n=>xZt(n,g));if(t.length===0)return null;const B=bdA(A,I),o=Math.floor(B.width*e),C=Math.floor(B.height*e);if(o<=0||C<=0)return null;const Q=document.createElement("canvas");Q.width=o,Q.height=C;const i=Q.getContext("2d");if(!i)return null;g==="bottom"&&(i.translate(0,C),i.scale(1,-1)),fZt({ctx:i,layer:g,bounds:B,elements:t});const E=new Kp(Q);return E.generateMipmaps=!0,E.minFilter=wl,E.magFilter=Un,E.anisotropy=16,E.needsUpdate=!0,E}var UZt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},JZt=({ctx:g,layer:A,bounds:I,elements:e,keepoutColor:t})=>{const B=A==="top"?"top_copper":"bottom_copper",o=new VE(g);o.configure({colorOverrides:{keepout:{top:t,bottom:t}}}),UZt(o,I),o.drawElements(e,{layers:[B],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1})},KZt=(g,A)=>g.type!=="pcb_keepout"?!1:!("layers"in g)||!Array.isArray(g.layers)?!0:g.layers.includes(A);function PZt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=K2,keepoutColor:t=g==="bottom"?"#4b72d2":"#d24b4b"}){const B=A.filter(s=>KZt(s,g));if(B.length===0)return null;const o=ky(I),C=Math.floor(o.width*e),Q=Math.floor(o.height*e);if(C<=0||Q<=0)return null;const i=document.createElement("canvas");i.width=C,i.height=Q;const E=i.getContext("2d");if(!E)return null;g==="bottom"&&(E.translate(0,Q),E.scale(1,-1)),JZt({ctx:E,layer:g,bounds:o,elements:B,keepoutColor:t});const n=new Kp(i);return n.generateMipmaps=!0,n.minFilter=wl,n.magFilter=Un,n.anisotropy=16,n.needsUpdate=!0,n}var ba="rgba(0,0,0,0)",LZt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},YZt=g=>g.type==="pcb_note_line"?{...g,x1:vs(g.x1,0),y1:vs(g.y1,0),x2:vs(g.x2,0),y2:vs(g.y2,0),stroke_width:vs(g.stroke_width,.1)}:g.type==="pcb_note_rect"?{...g,center:{x:vs(g.center.x,0),y:vs(g.center.y,0)},width:vs(g.width,0),height:vs(g.height,0),stroke_width:vs(g.stroke_width,.1),corner_radius:vs(g.corner_radius,0)}:g.type==="pcb_note_text"?{...g,anchor_position:{x:vs(g.anchor_position.x,0),y:vs(g.anchor_position.y,0)},font_size:vs(g.font_size,1)}:g.type==="pcb_note_path"?{...g,route:g.route.map(A=>({...A,x:vs(A.x,0),y:vs(A.y,0)})),stroke_width:vs(g.stroke_width,.1)}:g.type==="pcb_note_dimension"?{...g,from:{x:vs(g.from.x,0),y:vs(g.from.y,0)},to:{x:vs(g.to.x,0),y:vs(g.to.y,0)},font_size:vs(g.font_size,1),arrow_size:vs(g.arrow_size,1),offset_distance:vs(g.offset_distance,0)}:g,_Zt=({ctx:g,bounds:A,elements:I})=>{const e=I.map(YZt),t=new VE(g);t.configure({colorOverrides:{copper:{top:ba,bottom:ba,inner1:ba,inner2:ba,inner3:ba,inner4:ba,inner5:ba,inner6:ba,inner7:ba,inner8:ba},copperPour:{top:ba,bottom:ba},drill:ba,boardOutline:ba,substrate:ba,keepout:{top:ba,bottom:ba},courtyard:{top:ba,bottom:ba},soldermask:{top:ba,bottom:ba},soldermaskWithCopperUnderneath:{top:ba,bottom:ba},soldermaskOverCopper:{top:ba,bottom:ba},silkscreen:{top:ba,bottom:ba},fabricationNote:ba}}),LZt(t,A),t.drawElements(e)},bZt=(g,A)=>{if(!("layer"in g)||g.layer!==A)return!1;const I=g.type;return I.startsWith("pcb_note_")&&I!=="pcb_note_dimension"};function HZt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=K2}){const t=A.filter(n=>bZt(n,g));if(t.length===0)return null;const B=bdA(A,I),o=Math.floor(B.width*e),C=Math.floor(B.height*e);if(o<=0||C<=0)return null;const Q=document.createElement("canvas");Q.width=o,Q.height=C;const i=Q.getContext("2d");if(!i)return null;g==="bottom"&&(i.translate(0,C),i.scale(1,-1)),_Zt({ctx:i,bounds:B,elements:t});const E=new Kp(Q);return E.generateMipmaps=!0,E.minFilter=wl,E.magFilter=Un,E.anisotropy=16,E.needsUpdate=!0,E}var vZt="rgb(255,243,204)",_c="rgba(0,0,0,0)",tGI=(g,A,I)=>{const e=A==="top"?g.tented_on_top:g.tented_on_bottom,t="is_tented"in g?g.is_tented:void 0,B=A==="top"?I?.default_via_tented_on_top:I?.default_via_tented_on_bottom;return e??t??B??!1},qZt=(g,A,I,e)=>g.type==="pcb_cutout"?!0:g.type==="pcb_via"?!e||!tGI(g,A,I):g.type==="pcb_hole"||g.type==="pcb_plated_hole"?!e||g.is_covered_with_solder_mask!==!0:!1,TZt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},ZZt=({ctx:g,layer:A,bounds:I,elements:e,circuitJson:t,silkscreenColor:B,soldermaskVisible:o})=>{const C=A==="top"?"top_silkscreen":"bottom_silkscreen",Q=new VE(g);Q.configure({colorOverrides:{copper:{top:_c,bottom:_c,inner1:_c,inner2:_c,inner3:_c,inner4:_c,inner5:_c,inner6:_c,inner7:_c,inner8:_c},copperPour:{top:_c,bottom:_c},drill:_c,boardOutline:_c,substrate:_c,keepout:{top:_c,bottom:_c},courtyard:{top:_c,bottom:_c},soldermask:{top:_c,bottom:_c},soldermaskWithCopperUnderneath:{top:_c,bottom:_c},soldermaskOverCopper:{top:_c,bottom:_c},silkscreen:{top:B,bottom:B},fabricationNote:vZt}}),TZt(Q,I),Q.drawElements(e,{layers:[C],clipContextElements:t});const i=t.flatMap(E=>{if(E.type==="pcb_trace"){const s=g.boardOwnerMap?.get(E.pcb_trace_id),r=E.route.filter(a=>a.route_type==="via"&&(!o||!tGI(a,A,s)));return r.length?[{...E,route:r}]:[]}const n=E.type==="pcb_via"?g.boardOwnerMap?.get(E.pcb_via_id):void 0;return qZt(E,A,n,o)?[E]:[]});Q.drawElements(i,{layers:[C],clipContextElements:t,clearDrillHoles:!0})},OZt=(g,A)=>!("layer"in g)||g.layer!==A?!1:g.type.startsWith("pcb_silkscreen_");function WZt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=K2,silkscreenColor:t="rgb(255,255,255)",soldermaskVisible:B=!0}){const o=A.filter(r=>OZt(r,g));if(o.length===0)return null;const C=bdA(A,I),Q=Math.floor(C.width*e),i=Math.floor(C.height*e);if(Q<=0||i<=0)return null;const E=document.createElement("canvas");E.width=Q,E.height=i;const n=E.getContext("2d");if(!n)return null;g==="bottom"&&(n.translate(0,i),n.scale(1,-1)),ZZt({ctx:n,layer:g,bounds:C,elements:o,circuitJson:A,silkscreenColor:t,soldermaskVisible:B});const s=new Kp(E);return s.generateMipmaps=!0,s.minFilter=wl,s.magFilter=Un,s.anisotropy=16,s.needsUpdate=!0,s}var eIA=g=>{const[A=0,I=0,e=0]=g;return`rgb(${Math.round(A*255)}, ${Math.round(I*255)}, ${Math.round(e*255)})`},VZt=g=>{const A=eIA(KTt[g.material]??jE.fr4SolderMaskGreen),I=g.material==="fr1"?eIA(jE.fr1TracesWithMaskCopper):eIA(jE.fr4TracesWithMaskGreen),e=WuI(g.solder_mask_color);if(!e)return{soldermask:A,soldermaskOverCopper:I,copper:eIA(jE.copper),transparent:"rgba(0,0,0,0)"};const t=new tB().setRGB(jE.copper[0],jE.copper[1],jE.copper[2],Fp);return{soldermask:VuI(e),soldermaskOverCopper:VuI(ZTt({soldermaskColor:e,copperColor:t,soldermaskOpacity:qTt(g.solder_mask_color)})),copper:eIA(jE.copper),transparent:"rgba(0,0,0,0)"}},BGI=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},jZt=g=>g.type.startsWith("pcb_note_")||g.type.startsWith("pcb_fabrication_note_"),zZt=({ctx:g,layer:A,bounds:I,elements:e,boardData:t})=>{const B=VZt(t),o=A==="top"?"top_copper":"bottom_copper",C=new VE(g);C.configure({colorOverrides:{copper:{top:B.transparent,bottom:B.transparent,inner1:B.transparent,inner2:B.transparent,inner3:B.transparent,inner4:B.transparent,inner5:B.transparent,inner6:B.transparent,inner7:B.transparent,inner8:B.transparent},drill:B.transparent,boardOutline:B.transparent,substrate:B.transparent,keepout:{top:B.transparent,bottom:B.transparent},fabricationNote:B.transparent,silkscreen:{top:B.transparent,bottom:B.transparent},courtyard:{top:B.transparent,bottom:B.transparent},soldermask:{top:B.soldermask,bottom:B.soldermask},soldermaskWithCopperUnderneath:{top:B.soldermaskOverCopper,bottom:B.soldermaskOverCopper},soldermaskOverCopper:{top:B.soldermaskOverCopper,bottom:B.soldermaskOverCopper}}}),BGI(C,I);const Q=e.filter(E=>E.type!=="pcb_keepout"&&!jZt(E));C.drawElements(Q,{layers:[o],drawSoldermask:!0,drawSoldermaskTop:A==="top",drawSoldermaskBottom:A==="bottom"});const i=Q.filter(E=>E.type==="pcb_copper_pour"&&E.layer===A&&E.covered_with_solder_mask===!1);if(i.length>0){g.save(),g.globalCompositeOperation="destination-out";const E=new VE(g);E.configure({colorOverrides:{copper:{top:B.copper,bottom:B.copper,inner1:B.copper,inner2:B.copper,inner3:B.copper,inner4:B.copper,inner5:B.copper,inner6:B.copper,inner7:B.copper,inner8:B.copper}}}),BGI(E,I),E.drawElements(i,{layers:[o]}),g.restore()}};function XZt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=K2}){const t=bdA(A,I),B=Math.floor(t.width*e),o=Math.floor(t.height*e);if(B<=0||o<=0)return null;const C=document.createElement("canvas");C.width=B,C.height=o;const Q=C.getContext("2d");if(!Q)return null;g==="bottom"&&(Q.translate(0,o),Q.scale(1,-1));const i=A.some(n=>n.type==="pcb_board")?A:[I,...A];zZt({ctx:Q,layer:g,bounds:t,elements:i,boardData:I});const E=new Kp(C);return E.generateMipmaps=!0,E.minFilter=wl,E.magFilter=Un,E.anisotropy=16,E.needsUpdate=!0,E}var $Zt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},AOt=({ctx:g,layer:A,bounds:I,elements:e,copperColor:t})=>{const B=A==="top"?"top_copper":"bottom_copper",o="rgba(0,0,0,0)",C=new VE(g);C.configure({colorOverrides:{copper:{top:t,bottom:t,inner1:t,inner2:t,inner3:t,inner4:t,inner5:t,inner6:t,inner7:t,inner8:t},drill:o,boardOutline:o,substrate:o,keepout:{top:o,bottom:o},fabricationNote:o,silkscreen:{top:o,bottom:o},courtyard:{top:o,bottom:o},soldermask:{top:o,bottom:o},soldermaskWithCopperUnderneath:{top:o,bottom:o},soldermaskOverCopper:{top:o,bottom:o}}}),$Zt(C,I),C.drawElements(e,{layers:[B]})};function gOt({layer:g,circuitJson:A,boardData:I,copperColor:e="rgb(230, 153, 51)",traceTextureResolution:t=K2}){const B=A.filter(s=>{if(s.type==="pcb_via")return!0;if(s.type!=="pcb_plated_hole")return!1;const r=s;return!Array.isArray(r.layers)||r.layers.includes(g)});if(B.length===0)return null;const o=ky(I),C=Math.floor(o.width*t),Q=Math.floor(o.height*t);if(C<=0||Q<=0)return null;const i=document.createElement("canvas");i.width=C,i.height=Q;const E=i.getContext("2d");if(!E)return null;g==="bottom"&&(E.translate(0,Q),E.scale(1,-1)),AOt({ctx:E,layer:g,bounds:o,elements:B,copperColor:e});const n=new Kp(i);return n.generateMipmaps=!0,n.minFilter=wl,n.magFilter=Un,n.anisotropy=16,n.needsUpdate=!0,n}var oGI=g=>{const[A=0,I=0,e=0]=g;return`rgb(${Math.round(A*255)}, ${Math.round(I*255)}, ${Math.round(e*255)})`},T$A=g=>Math.max(0,Math.min(255,g)),IOt=(g,A,I,e={})=>{const t=g.getImageData(0,0,A,I),B=t.data,o=Math.max(A-1,1),C=Math.max(I-1,1);for(let Q=0;Q<B.length;Q+=4){if((B[Q+3]??0)<16)continue;const E=B[Q]??0,n=B[Q+1]??0,s=B[Q+2]??0,r=.2126*E+.7152*n+.0722*s;if(!(n>E*1.35&&n>s*1.15&&r<90&&E<80&&s<80))continue;const c=Q/4,h=c%A,l=Math.floor(c/A),D=h/o,d=l/C,y=D*.62+(1-d)*.38,w=Math.sin((D*1.15+d*.35)*Math.PI)*.04,u=.74+y*.18+w,G=e.includeReflection?(()=>{const F=D-.36,N=d-.22,U=Math.max(0,1-Math.hypot(F,N)/.38);return U*U*.07})():0,m=(E*.9+3)*u,p=(n*1.08+15)*u,k=(s*1.28+13)*u;B[Q]=T$A(m*(1-G)+255*G),B[Q+1]=T$A(p*(1-G)+255*G),B[Q+2]=T$A(k*(1-G)+255*G)}g.putImageData(t,0,0)},eOt=({textures:g,boardData:A,traceTextureResolution:I,layer:e,openViaHoles:t})=>{if(!g.some(s=>s?.image))return null;const o=ky(A),C=Math.floor(o.width*I),Q=Math.floor(o.height*I);if(C<=0||Q<=0)return null;const i=document.createElement("canvas");i.width=C,i.height=Q+1;const E=i.getContext("2d");if(!E)return null;for(const s of g){if(!s?.image)continue;const r=s.image;E.drawImage(r,0,0,C,Q)}rZt({ctx:E,vias:t,boardData:A,layer:e,width:C,height:Q}),IOt(E,C,Q,{includeReflection:e==="top"});const n=new Kp(i);return n.generateMipmaps=!1,n.minFilter=Un,n.magFilter=Un,n.premultiplyAlpha=!0,n.anisotropy=16,n.needsUpdate=!0,n},tOt=({textures:g,soldermaskTexture:A,boardData:I,traceTextureResolution:e})=>{if(!A?.image||!g.some(E=>E?.image))return null;const t=ky(I),B=Math.floor(t.width*e),o=Math.floor(t.height*e);if(B<=0||o<=0)return null;const C=document.createElement("canvas");C.width=B,C.height=o+1;const Q=C.getContext("2d");if(!Q)return null;for(const E of g)E?.image&&Q.drawImage(E.image,0,0,B,o);Q.globalCompositeOperation="destination-in",Q.drawImage(A.image,0,0,B,o),Q.globalCompositeOperation="source-over";const i=new Kp(C);return i.colorSpace=JN,i.generateMipmaps=!1,i.minFilter=Un,i.magFilter=Un,i.premultiplyAlpha=!1,i.needsUpdate=!0,i};function CGI({circuitJson:g,boardData:A,traceTextureResolution:I,visibility:e}){const t=oGI(jE.copper),B="rgb(255,255,255)",o=oGI(jE.copper),C=e?.boardBody??!0,Q=aZt(g,A,I),i=r=>{const a=(r==="top"?e?.topMask:e?.bottomMask)??!0,c=(r==="top"?e?.topCopper:e?.bottomCopper)??!0,h=(r==="top"?e?.topSilkscreen:e?.bottomSilkscreen)??!0,l=e?.keepout??!0,D=a?XZt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,d=c?DZt({layer:r,circuitJson:g,boardData:A,traceColor:t,traceTextureResolution:I}):null,y=c?gGI({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I,copperColor:o}):null,w=a&&c?gGI({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I,copperColor:o,onlyCoveredBySoldermask:!0}):null,u=c?uZt({layer:r,circuitJson:g,boardData:A,copperColor:o,traceTextureResolution:I}):null,G=c?cZt({layer:r,circuitJson:g,boardData:A,copperColor:o,traceTextureResolution:I}):null,m=c?gOt({layer:r,circuitJson:g,boardData:A,copperColor:o,traceTextureResolution:I}):null,p=h?WZt({layer:r,circuitJson:g,boardData:A,silkscreenColor:B,traceTextureResolution:I,soldermaskVisible:a}):null,k=h?FZt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,R=e?.pcbNotes??!1?HZt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,F=C?lZt({layer:r,circuitJson:g,panelData:A,traceTextureResolution:I}):null,N=l?PZt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,U=eOt({openViaHoles:Q,textures:[y,d,G,m,D,u,p,k,R,F,N],boardData:A,traceTextureResolution:I,layer:r}),P=a&&c?tOt({textures:[d,w],soldermaskTexture:D,boardData:A,traceTextureResolution:I}):null;return{boardTexture:U,maskedCopperTexture:P}},E=A.num_layers??2,n=i("top"),s=E<2?null:i("bottom");return{topBoard:n.boardTexture,bottomBoard:s?.boardTexture??null,topMaskedCopper:n.maskedCopperTexture,bottomMaskedCopper:s?.maskedCopperTexture??null}}var GR={bumpScale:.12,normalScale:.08,roughnessBias:.015,clearcoat:.08,clearcoatRoughness:.55},HdA={roughness:.42,metalness:.5,roughnessVariance:.035,detailStrength:.028},vdA=.22,BOt=.7,oOt=.86,QGI={height:vdA,microSurfaceWeight:1,roughness:.7,metalness:.015,isExposedCopper:!1,isMaskedCopper:!1},COt={height:BOt,microSurfaceWeight:.9,roughness:.54,metalness:.025,isExposedCopper:!1,isMaskedCopper:!0},Z$A=g=>Math.max(0,Math.min(1,g)),iGI=g=>1-g,tIA=(g,A,I)=>{let e=Math.imul(g,374761393)^Math.imul(A,668265263)^I;return e=Math.imul(e^e>>>13,1274126177),((e^e>>>16)>>>0)/4294967295},EGI=g=>g*g*(3-2*g),O$A=(g,A,I)=>g+(A-g)*I,W$A=(g,A,I,e)=>{const t=g/I,B=A/I,o=Math.floor(t),C=Math.floor(B),Q=EGI(t-o),i=EGI(B-C),E=O$A(tIA(o,C,e),tIA(o+1,C,e),Q),n=O$A(tIA(o,C+1,e),tIA(o+1,C+1,e),Q);return O$A(E,n,i)},QOt=(g,A,I)=>{const e=(W$A(g,A,7,I+31)-.5)*.55,t=Math.sin(g*.12+W$A(g,A,44,I+37)*2)*.22;return(e+t)*HdA.detailStrength},iOt=(g,A,I)=>{const e=(tIA(g,A,I+53)-.5)*.42,t=Math.sin(g*.26+A*.06)*.2+Math.sin(A*.31-g*.04)*.12;return(e+t)*.045},EOt=(g,A,I,e)=>e?COt:TTt({red:g,green:A,blue:I})?QGI:g>120&&A>70&&I<150&&g>A*1.05&&A>I*1.15?{height:oOt,microSurfaceWeight:.9,roughness:HdA.roughness,metalness:HdA.metalness,isExposedCopper:!0,isMaskedCopper:!1}:g>170&&A>170&&I>160?{height:vdA,microSurfaceWeight:.4,roughness:.76,metalness:0,isExposedCopper:!1,isMaskedCopper:!1}:A>g*1.25&&A>I*1.05&&g<110&&A<180&&I<130?QGI:{height:vdA,microSurfaceWeight:.7,roughness:.58,metalness:.015,isExposedCopper:!1,isMaskedCopper:!1},qdA=g=>{const A=new Kp(g);return A.colorSpace=JN,A.generateMipmaps=!1,A.minFilter=Un,A.magFilter=Un,A.wrapS=ZG,A.wrapT=ZG,A.needsUpdate=!0,A},nGI=(g,A)=>{const I=g.image;if(!I?.width||!I.height)return null;const{width:e,height:t}=I,B=I.getContext("2d");if(!B)return null;const o=A?.image,C=o?.getContext("2d"),Q=o?.width??0,i=o?.height??0,E=C&&Q&&i?C.getImageData(0,0,Q,i):null,n=B.getImageData(0,0,e,t),s=n.data,r=new Float32Array(e*t),a=document.createElement("canvas"),c=document.createElement("canvas");a.width=c.width=e,a.height=c.height=t;const h=a.getContext("2d"),l=c.getContext("2d");if(!h||!l)return null;const D=h.createImageData(e,t),d=l.createImageData(e,t),y=D.data,w=d.data;for(let F=0;F<s.length;F+=4){const N=F/4,U=N%e,P=Math.floor(N/e);if((s[F+3]??0)<16){r[N]=iGI(vdA);continue}const H=E?Math.min(Q-1,Math.floor(U/e*Q)):0,q=E?Math.min(i-1,Math.floor(P/t*i)):0,j=E?E.data[(q*Q+H)*4+3]??0:0,Z=EOt(s[F]??0,s[F+1]??0,s[F+2]??0,j>=16),O=e+t,AA=Z.isExposedCopper?QOt(U,P,O):Z.isMaskedCopper?iOt(U,P,O):0,tA=Z$A(iGI(Z.height)+AA*Z.microSurfaceWeight);r[N]=tA;const eA=tA*255;s[F]=s[F+1]=s[F+2]=eA,s[F+3]=255;const sA=(Z.isExposedCopper?Z$A(Z.roughness+AA*.7+(W$A(U,P,36,O+17)-.5)*HdA.roughnessVariance):Z.isMaskedCopper?Z$A(Z.roughness+AA+GR.roughnessBias):Z.roughness)*255;y[F]=y[F+1]=y[F+2]=sA,y[F+3]=255;const DA=Z.metalness*255;w[F]=w[F+1]=w[F+2]=DA,w[F+3]=255}h.putImageData(D,0,0),l.putImageData(d,0,0);const u=document.createElement("canvas");u.width=e,u.height=t;const G=u.getContext("2d");if(!G)return null;G.putImageData(n,0,0);const m=document.createElement("canvas");m.width=e,m.height=t;const p=m.getContext("2d");if(!p)return null;const k=p.createImageData(e,t),S=k.data,R=(F,N)=>r[Math.max(0,Math.min(t-1,N))*e+Math.max(0,Math.min(e-1,F))]??0;for(let F=0;F<t;F++)for(let N=0;N<e;N++){const U=(R(N+1,F)-R(N-1,F))*4,P=(R(N,F+1)-R(N,F-1))*4,b=1/Math.sqrt(U*U+P*P+1),H=(F*e+N)*4;S[H]=(-U*b*.5+.5)*255,S[H+1]=(-P*b*.5+.5)*255,S[H+2]=(b*.5+.5)*255,S[H+3]=255}return p.putImageData(k,0,0),{bumpMap:qdA(u),normalMap:qdA(m),roughnessMap:qdA(a),metalnessMap:qdA(c)}};function sGI(g,A){const{texture:I,maskedCopperMask:e,yOffset:t,isBottomLayer:B,usePolygonOffset:o=!1,renderOrder:C=0,isFaux:Q=!1}=g;if(!I)return null;const i=ky(A),E=new Sf(i.width,i.height);I.colorSpace=Fp;const n={map:I,transparent:!0,alphaTest:.08,side:cM,depthWrite:!0,polygonOffset:o,polygonOffsetFactor:o?-4:0,polygonOffsetUnits:o?-4:0,opacity:Q?KdA:1},s=nGI(I,e),r=new dM({...n,bumpMap:s?.bumpMap??null,bumpScale:GR.bumpScale,normalMap:s?.normalMap??null,normalScale:new ct(GR.normalScale,GR.normalScale),roughnessMap:s?.roughnessMap??null,roughness:1,metalnessMap:s?.metalnessMap??null,metalness:1,clearcoat:GR.clearcoat,clearcoatRoughness:GR.clearcoatRoughness,envMapIntensity:.18}),a=new FB(E,r);return a.position.set(i.centerX,i.centerY,t),B&&a.rotation.set(Math.PI,0,0),a.name=`${B?"bottom":"top"}-board-texture-plane`,a.renderOrder=C,ZM(a,{castShadow:!1,receiveShadow:!0}),a}function nOt(g,A,I,e=!1){const t=[];if(!g||!A||I===null)return t;const B=.005,o=sGI({texture:g.topBoard,maskedCopperMask:g.topMaskedCopper,yOffset:I/2+B,isBottomLayer:!1,usePolygonOffset:!0,renderOrder:1,isFaux:e},A);o&&t.push(o);const C=sGI({texture:g.bottomBoard,maskedCopperMask:g.bottomMaskedCopper,yOffset:-I/2-B,isBottomLayer:!0,usePolygonOffset:!0,renderOrder:1,isFaux:e},A);return C&&t.push(C),t}var aGI=g=>{const{boardBody:A,topCopper:I,bottomCopper:e,topSilkscreen:t,bottomSilkscreen:B,topMask:o,bottomMask:C,keepout:Q,pcbNotes:i}=g;return gA.useMemo(()=>({boardBody:A,topCopper:I,bottomCopper:e,topSilkscreen:t,bottomSilkscreen:B,topMask:o,bottomMask:C,keepout:Q,pcbNotes:i}),[A,I,e,t,B,o,C,Q,i])},sOt=4e6,aOt=4096,rOt=1;function rGI(g,A,I={}){const{maxTexturePixels:e=sOt,maxTextureDimension:t=aOt,minTextureResolution:B=rOt}=I,o=ky(g);if(!Number.isFinite(o.width)||!Number.isFinite(o.height)||o.width<=0||o.height<=0)return A;const C=Math.max(o.width,o.height),Q=t/C,i=Math.sqrt(e/(o.width*o.height)),E=Math.min(A,Q,i);return Math.max(B,E)}function cOt({circuitJson:g,pcbThickness:A,isFaux:I=!1}){const{rootObject:e}=SD(),{visibility:t}=e5(),B=aGI(t),o=gA.useMemo(()=>{const i=g.filter(s=>s.type==="pcb_panel"),E=jB(g).pcb_board.list();if(i.length>0){const s=i[0],r=E.find(a=>a.pcb_panel_id===s.pcb_panel_id);return{type:"pcb_board",pcb_board_id:s.pcb_panel_id,center:s.center,width:s.width,height:s.height,thickness:r?.thickness??1.4,material:r?.material??"fr4",num_layers:r?.num_layers??2,solder_mask_color:r?.solder_mask_color}}const n=E.filter(s=>!s.pcb_panel_id);return n.length>0?n[0]:null},[g]),C=gA.useMemo(()=>o?rGI(o,K2):K2,[o]),Q=gA.useMemo(()=>!o?.width||!o.height?null:CGI({circuitJson:g,boardData:o,traceTextureResolution:C,visibility:B}),[g,o,C,B]);return gA.useEffect(()=>{if(!e||!o||!Q)return;const i=[],E=c=>{const h=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],l=c;for(const D of h){const d=l[D];d&&d instanceof Hr&&(d.dispose(),l[D]=null)}c.dispose()},n=({texture:c,maskedCopperMask:h,zOffset:l,isBottomLayer:D,name:d,usePolygonOffset:y=!1,depthWrite:w=!0,renderOrder:u=1})=>{if(!c)return null;const G=ky(o),m=new Sf(G.width,G.height);c.colorSpace=Fp;const p={map:c,transparent:!0,alphaTest:.08,side:cM,depthWrite:w,polygonOffset:y,polygonOffsetFactor:y?-4:0,polygonOffsetUnits:y?-4:0,opacity:I?KdA:1},k=nGI(c,h),S=new dM({...p,bumpMap:k?.bumpMap??null,bumpScale:GR.bumpScale,normalMap:k?.normalMap??null,normalScale:new ct(GR.normalScale,GR.normalScale),roughnessMap:k?.roughnessMap??null,roughness:1,metalnessMap:k?.metalnessMap??null,metalness:1,clearcoat:GR.clearcoat,clearcoatRoughness:GR.clearcoatRoughness,envMapIntensity:.18}),R=new FB(m,S);return R.position.set(G.centerX,G.centerY,l),D&&R.rotation.set(Math.PI,0,0),R.name=d,R.renderOrder=u,R.frustumCulled=!1,ZM(R,{castShadow:!1,receiveShadow:!0}),R},s=.005,r=n({texture:Q.topBoard,maskedCopperMask:Q.topMaskedCopper,zOffset:A/2+s,isBottomLayer:!1,name:"jscad-top-board-texture",usePolygonOffset:!0});r&&(i.push(r),e.add(r));const a=n({texture:Q.bottomBoard,maskedCopperMask:Q.bottomMaskedCopper,zOffset:-A/2-s,isBottomLayer:!0,name:"jscad-bottom-board-texture",usePolygonOffset:!0});return a&&(i.push(a),e.add(a)),()=>{for(const c of i)if(c.parent===e&&e.remove(c),c.geometry.dispose(),Array.isArray(c.material))for(const h of c.material)E(h);else c.material instanceof Up&&E(c.material);Q.topBoard?.dispose(),Q.bottomBoard?.dispose()}},[e,o,Q,A]),null}function hOt({stlUrl:g,stlData:A,mtlUrl:I,color:e,opacity:t=1,layerType:B}){const{rootObject:o}=SD(),[C,Q]=gA.useState(null);gA.useEffect(()=>{const E=new oPt;if(A){try{const n=E.parse(A);Q(n)}catch(n){console.error("Failed to parse STL data",n),Q(null)}return}g&&E.load(g,n=>{Q(n)})},[g,A]);const i=gA.useMemo(()=>{if(!C)return null;const E=B==="board",n=new Ps({color:Array.isArray(e)?new tB(e[0],e[1],e[2]):e,transparent:t!==1,opacity:t,polygonOffset:E,polygonOffsetFactor:E?6:0,polygonOffsetUnits:E?6:0}),s=new FB(C,n);return s.renderOrder=E?-1:1,ZM(s,{castShadow:!E&&t===1,receiveShadow:!0}),s},[C,e,t,B]);return gA.useEffect(()=>{if(!(!o||!i))return o.add(i),()=>{o.remove(i),i.geometry.dispose(),Array.isArray(i.material)?i.material.forEach(E=>E.dispose()):i.material.dispose()}},[o,i]),null}function lOt({stlData:g,color:A,opacity:I=1,layerType:e}){const{visibility:t}=e5();let B=!0;return e==="board"?B=t.boardBody:e==="top-copper"?B=t.topCopper:e==="bottom-copper"?B=t.bottomCopper:e==="top-silkscreen"?B=t.topSilkscreen:e==="bottom-silkscreen"&&(B=t.bottomSilkscreen),B?W.jsx(hOt,{stlData:g,color:A,opacity:I,layerType:e}):null}var DOt=g=>{if(!g||typeof g!="object")return!1;const A=g;return A.type==="cad_cable"&&typeof A.cad_cable_id=="string"&&typeof A.cableprinter_string=="string"&&Array.isArray(A.path)},cGI=g=>g.filter(DOt),dOt=({x:g,y:A,z:I})=>[g,A,I],hGI=({path:g,pin1Position:A,end:I})=>{if(!A||g.length<2)return;const e=I==="start"?g[0]:g[g.length-1],t=I==="start"?g[1]:g[g.length-2];if(!e||!t)return;const B=new oI(t.x-e.x,t.y-e.y,t.z-e.z);if(B.lengthSq()<1e-12)return;B.normalize();const o=new oI(A.x-e.x,A.y-e.y,A.z-e.z);if(o.addScaledVector(B,-o.dot(B)),!(o.lengthSq()<1e-12))return o.normalize(),[o.x,o.y,o.z]},yOt=g=>{const A=YLt(g.cableprinter_string),I=XLt({definition:A,path:g.path.map(dOt),startPin1Side:hGI({path:g.path,pin1Position:g.from_connector_pin1_position,end:"start"}),endPin1Side:hGI({path:g.path,pin1Position:g.to_connector_pin1_position,end:"end"})}),e=new Nc;e.name=`cad-cable-${g.cad_cable_id}`,e.userData={cadCableId:g.cad_cable_id,name:g.name};for(const t of I){let B=new Jn;B.setAttribute("position",new To(t.positions,3)),B.setIndex(t.indices),t.smooth||(B=B.toNonIndexed()),B.computeVertexNormals();const[o,C,Q,i]=t.color,E=new Ps({color:new tB(o,C,Q),metalness:t.material?.metalness??0,roughness:t.material?.roughness??.7,opacity:i,transparent:i<1,side:yl}),n=new FB(B,E);n.name=`${e.name}:${t.name}`,ZM(n,{castShadow:!0,receiveShadow:!0}),e.add(n)}return e},wOt=g=>{g.traverse(A=>{if(!(A instanceof FB))return;A.geometry.dispose();const I=Array.isArray(A.material)?A.material:[A.material];for(const e of I)e.dispose()})},lGI=({cable:g})=>{const{rootObject:A}=SD(),I=gA.useMemo(()=>{try{return yOt(g)}catch(e){return console.error(`Failed to render CAD cable ${g.cad_cable_id}`,e),null}},[g]);return gA.useEffect(()=>{if(I)return A.add(I),()=>{A.remove(I),wOt(I)}},[I,A]),null};function DGI({boardDimensions:g,boardCenter:A}){if(!g||!A)return[5,-5,5];const I=Math.max(g.width??0,1),e=Math.max(g.height??0,1),t=Math.max(I,e,5);return[A.x+t*.4,A.y-t*.7,t*.9]}function uOt(g){const A=jB(g).cad_component.list().filter(D=>D.pcb_component_id),I=jB(g).pcb_smtpad.list(),e=jB(g).pcb_hole.list(),t=jB(g).pcb_plated_hole.list(),B=jB(g).pcb_via.list();if(A.length===0&&I.length===0&&e.length===0&&t.length===0&&B.length===0)return null;const o=[...e,...t,...B,...I],C=xF(o);let Q=C.minX,i=C.maxX,E=C.minY,n=C.maxY;for(const D of A)if(D.position){const d=D.position.x,y=D.position.y;Q=Math.min(Q,d),i=Math.max(i,d),E=Math.min(E,y),n=Math.max(n,y)}Q===1/0&&(Q=-10,i=10,E=-10,n=10);const s=2,r=Math.max(Math.abs(Q),Math.abs(i))+s,a=Math.max(Math.abs(E),Math.abs(n))+s,c=Math.max(2*r,10),h=Math.max(2*a,10);return{type:"pcb_board",pcb_board_id:"faux-board",center:{x:0,y:0},width:c,height:h,thickness:1.4,material:"fr4",num_layers:2}}function dGI(g){if(jB(g).pcb_board.list().length>0)return g;const I=uOt(g);if(!I)return g;const t=I.thickness/2;return[...g.map(o=>{if(o.type==="cad_component"&&o.pcb_component_id){const C=o;if(C.position){const Q=C.position.z??0;return{...C,position:{...C.position,z:Q+t}}}}return o}),I]}var GOt=gA.forwardRef(({circuitJson:g,children:A,autoRotateDisabled:I,clickToInteractEnabled:e,onUserInteraction:t,onCameraControllerReady:B,resolveStaticAsset:o,referenceObject:C,hiddenCadComponentIds:Q},i)=>{const E=p$A(A),n=gA.useMemo(()=>dGI(g??E),[g,E]),s=iZt(n),r=gA.useMemo(()=>{if(!n)return!1;try{const u=jB(n).pcb_board.list()[0];return!!u&&u.pcb_board_id==="faux-board"}catch{return!1}},[n]),a=gA.useMemo(()=>{if(n)try{const u=jB(n).pcb_board.list()[0];if(!u)return;const G=ky(u);return{width:G.width,height:G.height}}catch(u){console.error(u);return}},[n]),c=gA.useMemo(()=>{if(n)try{const u=jB(n).pcb_board.list()[0];if(!u)return;const G=ky(u);return{x:G.centerX,y:G.centerY}}catch(u){console.error(u);return}},[n]),h=gA.useMemo(()=>{if(!n)return;const u=jB(n).pcb_board.list()[0];if(u)return JSON.stringify({pcbBoardId:u.pcb_board_id,center:c,dimensions:a})},[n,c,a]),l=gA.useMemo(()=>DGI({boardDimensions:a,boardCenter:c}),[a,c]),D=muI(n),{stls:d}=STt(s),y=jB(n).cad_component.list().filter(u=>!Q?.has(u.cad_component_id)),w=cGI(n);return W.jsxs(ZuI,{ref:i,autoRotateDisabled:I,initialCameraPosition:l,clickToInteractEnabled:e,boardDimensions:a,boardCenter:c,cameraSessionScope:h,referenceObject:C,onUserInteraction:t,onCameraControllerReady:B,children:[d.map(({stlData:u,color:G,layerType:m},p)=>W.jsx(lOt,{stlData:u,color:G,opacity:p===0?r?.8:.95:1,layerType:m},`board-${p}`)),W.jsx(cOt,{circuitJson:n,pcbThickness:D,isFaux:r}),y.map(u=>W.jsx(N$A,{fallback:({error:G})=>W.jsx(AGI,{cad_component:u,error:G}),children:W.jsx(FuI,{cad_component:u,circuitJson:n,resolveStaticAsset:o},u.cad_component_id)},u.cad_component_id)),w.map(u=>W.jsx(lGI,{cable:u},u.cad_cable_id))]})}),TdA=new Set,V$A=!1;function mOt(g,A,I=2){const e=g.length;TdA.size&&TdA.clear();let t=pOt(g,0,e,I,!0);const B=[];if(!t||t.next===t.prev)return B;let o=0,C=0,Q=0;if(g.length>80*I){o=g[0],C=g[1];let i=o,E=C;for(let n=I;n<e;n+=I){const s=g[n],r=g[n+1];s<o&&(o=s),r<C&&(C=r),s>i&&(i=s),r>E&&(E=r)}Q=Math.max(i-o,E-C),Q=Q!==0?32767/Q:0}return j$A(t,B,o,C,Q),B}function pOt(g,A,I,e,t){let B=null;if(t===KOt(g,A,I,e)>0)for(let o=A;o<I;o+=e)B=wGI(o/e|0,g[o],g[o+1],B);else for(let o=I-e;o>=A;o-=e)B=wGI(o/e|0,g[o],g[o+1],B);return B&&$$A(B,B.next)&&(CIA(B),B=B.next),B}function ZdA(g,A=g){const I=A===g;let e=g,t;do t=!1,e!==e.next&&(TdA.size===0||!TdA.has(e))&&($$A(e,e.next)||My(e.prev,e,e.next)===0)?((I||e===A)&&(A=e.prev),V$A=!0,CIA(e),e=e.prev,t=!0):(I||e!==A)&&(e=e.next,t=!I);while(t||e!==A);return A}function j$A(g,A,I,e,t){t&&ROt(g,I,e,t);let B=g,o=!1;for(;g.prev!==g.next;){const C=g.prev,Q=g.next;if(My(C,g,Q)<0&&(t?MOt(g,I,e,t):kOt(g))){A.push(C.i,g.i,Q.i),CIA(g),g=Q,B=Q;continue}if(g=Q,g===B){if(V$A=!1,g=ZdA(g),V$A){B=g;continue}if(!o){g=SOt(g,A),B=g,o=!0;continue}fOt(g,A,I,e,t);break}}}function kOt(g){const A=g.prev,I=g,e=g.next,t=A.x,B=I.x,o=e.x,C=A.y,Q=I.y,i=e.y,E=Math.min(t,B,o),n=Math.min(C,Q,i),s=Math.max(t,B,o),r=Math.max(C,Q,i);let a=e.next;for(;a!==A;){if(a.x>=E&&a.x<=s&&a.y>=n&&a.y<=r&&!(t===a.x&&C===a.y)&&X$A(t,C,B,Q,o,i,a.x,a.y)&&My(a.prev,a,a.next)>=0)return!1;a=a.next}return!0}function MOt(g,A,I,e){const t=g.prev,B=g,o=g.next,C=t.x,Q=B.x,i=o.x,E=t.y,n=B.y,s=o.y,r=Math.min(C,Q,i),a=Math.min(E,n,s),c=Math.max(C,Q,i),h=Math.max(E,n,s),l=z$A(r,a,A,I,e),D=z$A(c,h,A,I,e);let d=g.prevZ;for(;d&&d.z>=l;){if(d.x>=r&&d.x<=c&&d.y>=a&&d.y<=h&&d!==o&&!(C===d.x&&E===d.y)&&X$A(C,E,Q,n,i,s,d.x,d.y)&&My(d.prev,d,d.next)>=0)return!1;d=d.prevZ}let y=g.nextZ;for(;y&&y.z<=D;){if(y.x>=r&&y.x<=c&&y.y>=a&&y.y<=h&&y!==o&&!(C===y.x&&E===y.y)&&X$A(C,E,Q,n,i,s,y.x,y.y)&&My(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function SOt(g,A){let I=g,e=!1;do{const t=I.prev,B=I.next.next;yGI(t,I,I.next,B,!1)&&VdA(t,B)&&VdA(B,t)&&(A.push(t.i,I.i,B.i),CIA(I),CIA(I.next),I=g=B,e=!0),I=I.next}while(I!==g);return e?ZdA(I):I}function fOt(g,A,I,e,t){let B=g;do{let o=B.next.next;for(;o!==B.prev;){if(B.i!==o.i&&xOt(B,o)){let C=JOt(B,o);B=ZdA(B,B.next),C=ZdA(C,C.next),j$A(B,A,I,e,t),j$A(C,A,I,e,t);return}o=o.next}B=B.next}while(B!==g)}var OM=[],ET=[],B5=new Uint32Array(0),BIA=new Uint32Array(0),oIA=new Uint32Array(256);function ROt(g,A,I,e){let t=g,B=0;do t.z=z$A(t.x,t.y,A,I,e),OM[B++]=t,t=t.next;while(t!==g);NOt(B);let o=null;for(let C=0;C<B;C++){const Q=OM[C];Q.prevZ=o,o&&(o.nextZ=Q),o=Q}o.nextZ=null,OM.fill(null,0,B),ET.fill(null,0,B)}function NOt(g){if(g<=32){for(let A=1;A<g;A++){const I=OM[A],e=I.z;let t=A-1;for(;t>=0&&OM[t].z>e;)OM[t+1]=OM[t],t--;OM[t+1]=I}return}B5.length<g&&(B5=new Uint32Array(g),BIA=new Uint32Array(g),ET=new Array(g));for(let A=0;A<g;A++)B5[A]=OM[A].z;OdA(g,OM,B5,ET,BIA,0),OdA(g,ET,BIA,OM,B5,8),OdA(g,OM,B5,ET,BIA,16),OdA(g,ET,BIA,OM,B5,24)}function OdA(g,A,I,e,t,B){oIA.fill(0);for(let C=0;C<g;C++)oIA[I[C]>>>B&255]++;let o=0;for(let C=0;C<256;C++){const Q=oIA[C];oIA[C]=o,o+=Q}for(let C=0;C<g;C++){const Q=I[C],i=oIA[Q>>>B&255]++;e[i]=A[C],t[i]=Q}}function z$A(g,A,I,e,t){return g=(g-I)*t|0,A=(A-e)*t|0,g=(g|g<<8)&16711935,g=(g|g<<4)&252645135,g=(g|g<<2)&858993459,g=(g|g<<1)&1431655765,A=(A|A<<8)&16711935,A=(A|A<<4)&252645135,A=(A|A<<2)&858993459,A=(A|A<<1)&1431655765,g|A<<1}function X$A(g,A,I,e,t,B,o,C){return(t-o)*(A-C)>=(g-o)*(B-C)&&(g-o)*(e-C)>=(I-o)*(A-C)&&(I-o)*(B-C)>=(t-o)*(e-C)}function xOt(g,A){const I=$$A(g,A)&&My(g.prev,g,g.next)>0&&My(A.prev,A,A.next)>0;return g.next.i!==A.i&&(I||VdA(g,A)&&VdA(A,g)&&(My(g.prev,g,A.prev)!==0||My(g,A.prev,A)!==0))&&!FOt(g,A)&&(I||UOt(g,A))}function My(g,A,I){return(A.y-g.y)*(I.x-A.x)-(A.x-g.x)*(I.y-A.y)}function $$A(g,A){return g.x===A.x&&g.y===A.y}function yGI(g,A,I,e,t=!0){const B=My(g,A,I),o=My(g,A,e),C=My(I,e,g),Q=My(I,e,A);return(B>0&&o<0||B<0&&o>0)&&(C>0&&Q<0||C<0&&Q>0)?!0:t?!!(B===0&&WdA(g,I,A)||o===0&&WdA(g,e,A)||C===0&&WdA(I,g,e)||Q===0&&WdA(I,A,e)):!1}function WdA(g,A,I){return A.x<=Math.max(g.x,I.x)&&A.x>=Math.min(g.x,I.x)&&A.y<=Math.max(g.y,I.y)&&A.y>=Math.min(g.y,I.y)}function FOt(g,A){const I=Math.min(g.x,A.x),e=Math.max(g.x,A.x),t=Math.min(g.y,A.y),B=Math.max(g.y,A.y);let o=g;do{const C=o.next;if(o.x>e&&C.x>e||o.x<I&&C.x<I||o.y>B&&C.y>B||o.y<t&&C.y<t){o=C;continue}if(o.i!==g.i&&C.i!==g.i&&o.i!==A.i&&C.i!==A.i&&yGI(o,C,g,A))return!0;o=C}while(o!==g);return!1}function VdA(g,A){return My(g.prev,g,g.next)<0?My(g,A,g.next)>=0&&My(g,g.prev,A)>=0:My(g,A,g.prev)<0||My(g,g.next,A)<0}function UOt(g,A){let I=g,e=!1;const t=(g.x+A.x)/2,B=(g.y+A.y)/2;do{const o=I.next;I.y>B!=o.y>B&&t<(o.x-I.x)*(B-I.y)/(o.y-I.y)+I.x&&(e=!e),I=o}while(I!==g);return e}function JOt(g,A){const I=AAg(g.i,g.x,g.y),e=AAg(A.i,A.x,A.y),t=g.next,B=A.prev;return g.next=A,A.prev=g,I.next=t,t.prev=I,e.next=I,I.prev=e,B.next=e,e.prev=B,e}function wGI(g,A,I,e){const t=AAg(g,A,I);return e?(t.next=e.next,t.prev=e,e.next.prev=t,e.next=t):(t.prev=t,t.next=t),t}function CIA(g){g.next.prev=g.prev,g.prev.next=g.next,g.prevZ&&(g.prevZ.nextZ=g.nextZ),g.nextZ&&(g.nextZ.prevZ=g.prevZ)}function AAg(g,A,I){return{i:g,x:A,y:I,prev:null,next:null,z:0,prevZ:null,nextZ:null}}function KOt(g,A,I,e){let t=0;for(let B=A,o=I-e;B<I;B+=e)t+=(g[o]-g[B])*(g[B+1]+g[o+1]),o=B;return t}var o5=1e-7;function uGI(g,A){if(!Number.isFinite(A)||A<0)throw new Error("Board thickness must be finite and nonnegative");const I=g.map(C=>{const{start:Q,end:i,bend_angle:E,bend_radius:n}=C;if([Q?.x,Q?.y,i?.x,i?.y,E,n].some(y=>!Number.isFinite(y))||n<=A/2||!["left","right"].includes(C.bend_side))throw new Error(`Invalid PCB bend ${C.pcb_bend_id}: finite geometry and radius greater than half the board thickness are required`);const r=Math.hypot(i.x-Q.x,i.y-Q.y);if(r<o5||Math.abs(E)>180)throw new Error(`Unsupported PCB bend ${C.pcb_bend_id}: distinct endpoints and angles within ±180 degrees are required`);const a=C.bend_side==="right"?1:-1,c=a*(i.y-Q.y)/r,h=-a*(i.x-Q.x)/r,l=E*Math.PI/180,D=n*Math.abs(l),d=Q.x*c+Q.y*h;return{id:C.pcb_bend_id,nx:c,ny:h,start:d-D/2,end:d+D/2,angle:l,radius:n,axisMin:Math.min(-h*Q.x+c*Q.y,-h*i.x+c*i.y),axisMax:Math.max(-h*Q.x+c*Q.y,-h*i.x+c*i.y)}}).filter(C=>Math.abs(C.angle)>o5),e=I[0];if(e&&I.some(C=>Math.abs(C.nx-e.nx)>o5||Math.abs(C.ny-e.ny)>o5))throw new Error("Folded PCB rendering currently requires parallel bends with the same moving direction");I.sort((C,Q)=>C.start-Q.start);for(let C=1;C<I.length;C++)if(I[C].start<I[C-1].end-o5)throw new Error("Overlapping PCB bend zones are not supported");const t=[...I].reverse(),B=({p:C,anchor:Q,direction:i})=>{let E={...C};for(const n of t){const s=n.end-n.start,r=Q.x*n.nx+Q.y*n.ny-n.start,a=Math.max(0,Math.min(s,r)),c=n.angle*a/s,h=Math.cos(c),l=Math.sin(c),D=E.x*n.nx+E.y*n.ny-(i?0:n.start),d=E.x-(D+(i?0:n.start))*n.nx,y=E.y-(D+(i?0:n.start))*n.ny,w=Math.sign(n.angle)*n.radius,u=i?0:w*l-a*h,G=i?0:w*(1-h)-a*l,m=D*h-E.z*l+u;E={x:d+(m+(i?0:n.start))*n.nx,y:y+(m+(i?0:n.start))*n.ny,z:D*l+E.z*h+G}}return E},o=({p:C,anchor:Q,direction:i})=>{const E=i?{x:0,y:0,z:0}:B({p:{x:0,y:0,z:0},anchor:Q,direction:!1}),n={x:C.x-E.x,y:C.y-E.y,z:C.z-E.z},s=[{x:1,y:0,z:0},{x:0,y:1,z:0},{x:0,y:0,z:1}].map(a=>B({p:a,anchor:Q,direction:!0})),r=a=>a.x*n.x+a.y*n.y+a.z*n.z;return{x:r(s[0]),y:r(s[1]),z:r(s[2])}};return{bends:I,inversePoint:(C,Q)=>o({p:C,anchor:Q,direction:!1}),inverseDirection:(C,Q)=>o({p:C,anchor:Q,direction:!0}),point:(C,Q=C)=>B({p:C,anchor:Q,direction:!1}),direction:(C,Q)=>B({p:C,anchor:Q,direction:!0}),assertRigid(C,Q){for(const i of I){const E=C.map(n=>n.x*i.nx+n.y*i.ny);if(Math.max(...E)>i.start+o5&&Math.min(...E)<i.end-o5)throw new Error(`${Q} intersects PCB bend zone ${i.id}`)}}}}var mR=1e-7;function QIA(g){const A=g.flatMap(t=>t.vertices);if(!A.length)return{min:{x:0,y:0,z:0},max:{x:0,y:0,z:0}};const I={x:1/0,y:1/0,z:1/0},e={x:-1/0,y:-1/0,z:-1/0};for(const t of A)for(const B of["x","y","z"])I[B]=Math.min(I[B],t[B]),e[B]=Math.max(e[B],t[B]);return{min:I,max:e}}function GGI(g,A){const I=A.bends.flatMap(C=>{const Q=Math.ceil(Math.abs(C.angle)/(Math.PI/36));return Array.from({length:Q+1},(i,E)=>({b:C,d:C.start+(C.end-C.start)*E/Q}))}),{min:e,max:t}=g.boundingBox,B=({polygon:C,nx:Q,ny:i,d:E})=>{const n=C.map(({p:r})=>Q*r.x+i*r.y-E);if(Math.min(...n)>=-mR||Math.max(...n)<=mR)return[C];const s=[[],[]];for(let r=0;r<2;r++){const a=r===0?1:-1;for(let c=0;c<C.length;c++){const h=C[c],l=(c+1)%C.length,D=C[l],d=n[c]*a,y=n[l]*a;if(d>=-mR&&s[r].push(h),d>mR&&y<-mR||d<-mR&&y>mR){const w=d/(d-y);s[r].push({p:{x:h.p.x+(D.p.x-h.p.x)*w,y:h.p.y+(D.p.y-h.p.y)*w,z:h.p.z+(D.p.z-h.p.z)*w},uv:{u:h.uv.u+(D.uv.u-h.uv.u)*w,v:h.uv.v+(D.uv.v-h.uv.v)*w}})}}}return s.filter(r=>r.length>=3)},o=[];for(const C of g.triangles){const Q=C.pcbFace??(C.normal.z>.8?"top":C.normal.z<-.8?"bottom":"side");let i=[C.vertices.map((E,n)=>({p:E,uv:C.uvs?.[n]??{u:(E.x-e.x)/(t.x-e.x),v:1-(E.y-e.y)/(t.y-e.y)}}))];for(const{b:E,d:n}of I)i=i.flatMap(s=>B({polygon:s,nx:E.nx,ny:E.ny,d:n}));for(const E of i){for(const n of A.bends){const s=E.reduce((r,{p:a})=>r+a.x*n.nx+a.y*n.ny,0)/E.length;if(s>n.start+mR&&s<n.end-mR&&E.some(({p:r})=>{const a=-n.ny*r.x+n.nx*r.y;return a<n.axisMin-mR||a>n.axisMax+mR}))throw new Error(`PCB bend ${n.id} must span the full board cross-section through its bend zone`)}for(let n=1;n+1<E.length;n++){const s=[E[0],E[n],E[n+1]],r=s.map(({p:w})=>A.point(w)),[a,c,h]=r,l={x:c.x-a.x,y:c.y-a.y,z:c.z-a.z},D={x:h.x-a.x,y:h.y-a.y,z:h.z-a.z},d={x:l.y*D.z-l.z*D.y,y:l.z*D.x-l.x*D.z,z:l.x*D.y-l.y*D.x},y=Math.hypot(d.x,d.y,d.z);y<1e-12||o.push({...C,vertices:r,normal:{x:d.x/y,y:d.y/y,z:d.z/y},pcbFace:Q,uvs:s.map(({uv:w})=>w)})}}}return{...g,triangles:o,boundingBox:QIA(o)}}var POt=[{x:1,y:0,z:0},{x:0,y:1,z:0},{x:0,y:0,z:1}];function LOt(g,A){const[I,e,t]=[A.x,A.y,A.z].map(C=>C*Math.PI/180),B={x:Math.cos(t)*g.x-Math.sin(t)*g.y,y:Math.sin(t)*g.x+Math.cos(t)*g.y,z:g.z},o={x:Math.cos(e)*B.x+Math.sin(e)*B.z,y:B.y,z:-Math.sin(e)*B.x+Math.cos(e)*B.z};return{x:o.x,y:Math.cos(I)*o.y-Math.sin(I)*o.z,z:Math.sin(I)*o.y+Math.cos(I)*o.z}}function YOt([g,A,I]){const e=Math.asin(Math.max(-1,Math.min(1,I.x))),t=Math.abs(I.x)<1-1e-12;return{x:(t?Math.atan2(-I.y,I.z):Math.atan2(A.z,A.y))*180/Math.PI,y:e*180/Math.PI,z:(t?Math.atan2(-A.x,g.x):0)*180/Math.PI}}function _Ot({cadComponent:g,foldPcbs:A},I){return bOt({cadComponentPlacement:g,foldPcbs:A},I)}function bOt({cadComponentPlacement:g,foldPcbs:A},I){if(g.is_on_folded_board===!0===A)return g;const{fold:e,boardCenter:t,flatMount:B}=I,o={x:B.x-t.x,y:B.y-t.y,z:0};e.assertRigid([o],"CAD mount");const C={x:g.position.x-t.x,y:g.position.y-t.y,z:g.position.z},Q=A?e.direction:e.inverseDirection,i=A?e.point(C,o):e.inversePoint(C,o),E=g.rotation??I.defaultRotation??{x:0,y:0,z:0},n=POt.map(s=>Q(LOt(s,E),o));return{...g,position:{x:i.x+t.x,y:i.y+t.y,z:i.z},rotation:YOt(n),is_on_folded_board:A}}function HOt(g,A){const I=A.find(Q=>Q.type==="pcb_component"&&Q.pcb_component_id===g.pcb_component_id);if(I?.type!=="pcb_component"){if(g.is_on_folded_board)throw new Error(`Folded CAD ${g.cad_component_id} requires its flat pcb_component reference`);return}const e=A.filter(Q=>Q.type==="pcb_board"),t=I.positioned_relative_to_pcb_board_id,B=t?e.filter(Q=>Q.pcb_board_id===t):e.filter(Q=>Q.subcircuit_id&&Q.subcircuit_id===I.subcircuit_id),o=B.length===1?B[0]:!t&&!B.length&&e.length===1?e[0]:void 0;if(!o)throw new Error(`Cannot unambiguously resolve board for CAD ${g.cad_component_id}`);const C=A.filter(Q=>Q.type==="pcb_bend"&&Q.pcb_board_id===o.pcb_board_id);return{fold:uGI(C,o.thickness??1.6),boardCenter:o.center,flatMount:I.center,defaultRotation:{x:(g.layer??I.layer)==="bottom"?180:0,y:0,z:0}}}function vOt(g,A){const I=g.some(e=>e.type==="pcb_bend");return g.map(e=>{if(e.type!=="cad_component")return e;const t=e;if(!I&&!t.is_on_folded_board||t.is_on_folded_board===!0===A.foldPcbs)return e;const B=HOt(t,g);return!B||!B.fold.bends.length&&!t.is_on_folded_board?e:_Ot({cadComponent:t,foldPcbs:A.foldPcbs},B)})}function qOt({outline:g,bottom:A,top:I}){if(g.length<3||!Number.isFinite(A)||!Number.isFinite(I)||I<=A||g.some(Q=>!Number.isFinite(Q.x)||!Number.isFinite(Q.y)))throw new Error("A finite polygon and positive extrusion thickness are required");let e=0;for(const[Q,i]of g.entries()){const E=g[(Q+1)%g.length];e+=i.x*E.y-E.x*i.y}if(Math.abs(e)<1e-12)throw new Error("Degenerate polygon");const t=e>0?g:[...g].reverse(),B=[],o=({a:Q,b:i,c:E,pcbFace:n})=>{const s={x:i.x-Q.x,y:i.y-Q.y,z:i.z-Q.z},r={x:E.x-Q.x,y:E.y-Q.y,z:E.z-Q.z},a={x:s.y*r.z-s.z*r.y,y:s.z*r.x-s.x*r.z,z:s.x*r.y-s.y*r.x},c=Math.hypot(a.x,a.y,a.z);c>1e-12&&B.push({vertices:[Q,i,E],normal:{x:a.x/c,y:a.y/c,z:a.z/c},pcbFace:n})},C=mOt(t.flatMap(Q=>[Q.x,Q.y]));for(let Q=0;Q<C.length;Q+=3){const[i,E,n]=C.slice(Q,Q+3).map(s=>t[s]);o({a:{...i,z:I},b:{...E,z:I},c:{...n,z:I},pcbFace:"top"}),o({a:{...n,z:A},b:{...E,z:A},c:{...i,z:A},pcbFace:"bottom"})}for(let Q=0;Q<t.length;Q++){const i=t[Q],E=t[(Q+1)%t.length];o({a:{...i,z:A},b:{...E,z:A},c:{...E,z:I},pcbFace:"side"}),o({a:{...i,z:A},b:{...E,z:I},c:{...i,z:I},pcbFace:"side"})}return{triangles:B,boundingBox:QIA(B)}}function TOt({stiffener:g,boardThickness:A,fold:I}){const e=g.adhesive_thickness??0;if(!Number.isFinite(e)||e<0||!Number.isFinite(g.thickness)||g.thickness<=0||!["top","bottom"].includes(g.layer))throw new Error(`Invalid PCB stiffener ${g.pcb_stiffener_id}`);const t=g.shape==="polygon"?g.outline:(()=>{if(!(g.width>0&&g.height>0))throw new Error("Invalid stiffener dimensions");const E=(g.rotation??0)*Math.PI/180;return[[-1,-1],[1,-1],[1,1],[-1,1]].map(([n,s])=>({x:g.center.x+n*g.width/2*Math.cos(E)-s*g.height/2*Math.sin(E),y:g.center.y+n*g.width/2*Math.sin(E)+s*g.height/2*Math.cos(E)}))})(),B=A/2+e,o=B+g.thickness,C=qOt({outline:t,bottom:g.layer==="top"?B:-o,top:g.layer==="top"?o:-B});if(!I)return C;I.assertRigid(C.triangles.flatMap(E=>E.vertices),g.pcb_stiffener_id);const Q={x:t.reduce((E,n)=>E+n.x,0)/t.length,y:t.reduce((E,n)=>E+n.y,0)/t.length,z:0},i=C.triangles.map(E=>({...E,vertices:E.vertices.map(n=>I.point(n,Q)),normal:I.direction(E.normal,Q)}));return{...C,triangles:i,boundingBox:QIA(i)}}var ZOt=g=>{let A=0;for(let e=0;e<g.length;e++){const t=(e+1)%g.length;g[e]&&g[t]&&(A+=g[e][0]*g[t][1],A-=g[t][0]*g[e][1])}return A/2<=0};function OOt(g,A,I,e,t){let B,o=null;if(I.outline&&I.outline.length>=3){let C=I.outline.map(i=>[i.x,i.y]);ZOt(C)&&(C=C.reverse());const Q=A.ofPolygons([C]);t.push(Q),o=Q,B=g.extrude(Q,e,void 0,void 0,void 0,!0),t.push(B)}else I.outline&&I.outline.length>0&&console.warn("Board outline has fewer than 3 points, falling back to rectangular board."),B=g.cube([I.width,I.height,e],!0),t.push(B),B=B.translate([I.center.x,I.center.y,0]),t.push(B);return{boardOp:B,outlineCrossSection:o}}var WOt=64;function C5({Manifold:g,width:A,height:I,thickness:e,borderRadius:t}){const B=XuI(A,I,t);if(B<=0)return g.cube([A,I,e],!0);const o=[],C=A-2*B,Q=I-2*B;return C>0&&o.push(g.cube([C,I,e],!0)),Q>0&&o.push(g.cube([A,Q,e],!0)),[[A/2-B,I/2-B],[-A/2+B,I/2-B],[-A/2+B,-I/2+B],[A/2-B,-I/2+B]].forEach(([E,n])=>{o.push(g.cylinder(e,B,B,WOt,!0).translate([E,n,0]))}),g.union(o)}var VOt=g=>{let A=0;for(let e=0;e<g.length;e++){const t=(e+1)%g.length;g[e]&&g[t]&&(A+=g[e][0]*g[t][1],A-=g[t][0]*g[e][1])}return A/2<=0};function jOt(g,A,I,e,t){const B=[],o=jB(I).pcb_cutout.list();for(const C of o){let Q;const i=e*1.5;switch(C.shape){case"rect":{const s=i3(C);if(typeof s=="number"&&s>0?Q=C5({Manifold:g,width:C.width,height:C.height,thickness:i,borderRadius:s}):Q=g.cube([C.width,C.height,i],!0),t.push(Q),C.rotation){const r=Q.rotate([0,0,C.rotation]);t.push(r),Q=r}Q=Q.translate([C.center.x,C.center.y,0]),t.push(Q);break}case"circle":Q=g.cylinder(i,C.radius,-1,fd,!0),t.push(Q),Q=Q.translate([C.center.x,C.center.y,0]),t.push(Q);break;case"polygon":if(C.points.length<3){console.warn(`PCB Cutout [${C.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);continue}let E=C.points.map(s=>[s.x,s.y]);VOt(E)&&(E=E.reverse());const n=A.ofPolygons([E]);t.push(n),Q=g.extrude(n,i,0,0,[1,1],!0),t.push(Q);break;default:console.warn(`Unsupported cutout shape: ${C.shape} for cutout ${C.pcb_cutout_id}`);continue}Q&&B.push(Q)}return{cutoutOps:B}}function mGI({Manifold:g,x:A,y:I,diameter:e,thickness:t,segments:B=32}){return g.cylinder(t*1.2,e/2,e/2,B,!0).translate([A,I,0])}function pGI({Manifold:g,x:A,y:I,holeDiameter:e,thickness:t,zOffset:B=.001,segments:o=32}){const C=e/2+B;return g.cylinder(t*1.2,C,C,o,!0).translate([A,I,0])}function zOt(g,A,I,e,t){const B=[],o=jB(I).pcb_hole.list(),C=(E,n,s)=>{const r=C5({Manifold:g,width:E,height:n,thickness:s,borderRadius:Math.min(E,n)/2});return t.push(r),r},Q=(E,n,s)=>{const r=g.cube([E,n,s],!0);return t.push(r),r},i=(E,n,s)=>{const r=[];for(let a=0;a<s;a++){const c=2*Math.PI*a/s;r.push([E/2*Math.cos(c),n/2*Math.sin(c)])}return r};for(const E of o){const n=E.hole_shape,s=E.x,r=E.y,a=e*1.2,c=E.ccw_rotation??E.rotation??0,h=E.hole_width??E.hole_diameter,l=E.hole_height??E.hole_diameter;let D=null;if(n==="circle"){D=mGI({Manifold:g,x:s,y:r,diameter:E.hole_diameter,thickness:e,segments:fd}),B.push(D),t.push(D);continue}if(n==="pill"||n==="rotated_pill")D=C(h,l,a);else if(n==="rect")D=Q(h,l,a);else if(n==="oval"){let d=i(h,l,fd),y=0;for(let u=0;u<d.length;u++){const G=(u+1)%d.length;y+=d[u][0]*d[G][1],y-=d[G][0]*d[u][1]}y<=0&&(d=d.reverse());const w=A.ofPolygons([d]);t.push(w),D=g.extrude(w,a,0,0,[1,1],!0),t.push(D)}if(D){if(c!==0){const y=D.rotate([0,0,c]);t.push(y),D=y}const d=D.translate([s,r,0]);t.push(d),B.push(d)}}return{nonPlatedHoleBoardDrills:B}}function ax(g){const A=new Jn;if(A.setAttribute("position",new To(g.vertProperties,3)),A.setIndex(new _4A(g.triVerts,1)),g.runIndex&&g.runIndex.length>1&&g.runOriginalID)for(let I=0;I<g.runIndex.length-1;I++){const e=g.runIndex[I],t=g.runIndex[I+1]-e;A.addGroup(e,t,0)}else A.addGroup(0,g.triVerts.length,0);return A}var iIA=g=>{let A=0;for(let e=0;e<g.length;e++){const t=(e+1)%g.length;g[e]&&g[t]&&(A+=g[e][0]*g[t][1],A-=g[t][0]*g[e][1])}return A/2<=0},jdA=(g,A,I)=>{const e=[];for(let t=0;t<I;t++){const B=2*Math.PI*t/I;e.push([g/2*Math.cos(B),A/2*Math.sin(B)])}return e},Q5=new tB(...jE.copper),zdA=.05,EIA=.003,nIA=5e-4,sIA=.004;function XOt(g,A,I,e,t,B){const o=[],C=jB(I).pcb_plated_hole.list(),Q=[],i=[],E=(a,c,h)=>{const l=C5({Manifold:g,width:a,height:c,thickness:h,borderRadius:Math.min(a,c)/2});return t.push(l),l},n=({padOutline:a,thickness:c})=>{if(!Array.isArray(a)||a.length<3)return null;let h=a.map(d=>[d.x,d.y]);iIA(h)&&(h=h.reverse());const l=A.ofPolygons([h]);t.push(l);const D=g.extrude(l,c,0,0,[1,1],!0);return t.push(D),D},s=({ph:a,depth:c,sizeDelta:h=0})=>{if(a.shape!=="hole_with_polygon_pad")return null;const D=a.pad_outline;if(!Array.isArray(D)||D.length<3)return null;const d=a.hole_shape||"circle",y=a.hole_offset_x||0,w=a.hole_offset_y||0;let u=null;if(d==="circle"){const G=Math.max((a.hole_diameter??0)+h,Oo),m=Math.max(G/2,Oo/2);u=g.cylinder(c,m,m,fd,!0),t.push(u)}else{const G=a.hole_width??a.hole_diameter,m=a.hole_height??a.hole_diameter;if(!G||!m)return null;const p=Math.max(G+h,Oo),k=Math.max(m+h,Oo);if(d==="oval"){let S=jdA(p,k,fd);iIA(S)&&(S=S.reverse());const R=A.ofPolygons([S]);t.push(R),u=g.extrude(R,c,0,0,[1,1],!0),t.push(u)}else(d==="pill"||d==="rotated_pill")&&(u=C5({Manifold:g,width:p,height:k,thickness:c,borderRadius:Math.min(p,k)/2}),t.push(u))}if(!u)return null;if(y||w){const G=u.translate([y,w,0]);t.push(G),u=G}return u};C.forEach((a,c)=>{const h=Math.max(e-2*(EIA+nIA+sIA),Oo);if(a.shape==="circle"){const l=pGI({Manifold:g,x:a.x,y:a.y,holeDiameter:a.hole_diameter*1.02,thickness:e,zOffset:uR,segments:fd});t.push(l),o.push(l);const D=h,d=g.cylinder(D,a.outer_diameter/2,a.outer_diameter/2,fd,!0);t.push(d);const y=g.cylinder(D*1.05,a.hole_diameter/2,a.hole_diameter/2,fd,!0);t.push(y);const w=d.subtract(y);t.push(w);const u=w.translate([a.x,a.y,0]);t.push(u);let G=u;if(B){const p=g.intersection([u,B]);t.push(p),G=p}i.push(G);const m=ax(G.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:m,color:Q5})}else if(a.shape==="pill"){const l=a.hole_width,D=a.hole_height,d=.4,y=a.outer_width??l+d,w=a.outer_height??D+d,u=l+2*uR,G=D+2*uR,m=e*1.2;let p=E(u,G,m);if(a.ccw_rotation){const H=p.rotate([0,0,a.ccw_rotation]);t.push(H),p=H}const k=p.translate([a.x,a.y,0]);t.push(k),o.push(k);const S=h,R=E(y,w,S),F=E(l,D,S*1.05);let N=R.subtract(F);if(t.push(N),a.ccw_rotation){const H=N.rotate([0,0,a.ccw_rotation]);t.push(H),N=H}const U=N.translate([a.x,a.y,0]);t.push(U);let P=U;if(B){const H=g.intersection([U,B]);t.push(H),P=H}i.push(P);const b=ax(P.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:b,color:Q5})}else if(a.shape==="pill_hole_with_rect_pad"){if(a.hole_shape&&a.hole_shape!=="pill"||a.pad_shape&&a.pad_shape!=="rect")return;const l=a.hole_width,D=a.hole_height,d=a.hole_offset_x||0,y=a.hole_offset_y||0,w=a.rect_pad_width,u=a.rect_pad_height,G=i3(a),m=EIA,p=l+2*uR,k=D+2*uR,S=e*1.2,F=E(p,k,S).translate([d,y,0]).translate([a.x,a.y,0]);t.push(F),o.push(F);const N=C5({Manifold:g,width:w,height:u,thickness:Math.max(e-2*(m+nIA+sIA),Oo),borderRadius:G});t.push(N);const U=E(l,D,e*.8).translate([d,y,0]);t.push(U);const P=g.union([N,U]);t.push(P);const b=E(Math.max(l-2*zdA,.01),Math.max(D-2*zdA,.01),e*1.2).translate([d,y,0]);t.push(b);const H=P.subtract(b);t.push(H);const q=H.translate([a.x,a.y,0]);t.push(q);let j=q;if(B){const O=g.intersection([q,B]);t.push(O),j=O}i.push(j);const Z=ax(j.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:Z,color:Q5})}else if(a.shape==="rotated_pill_hole_with_rect_pad"){if(a.hole_shape&&a.hole_shape!=="rotated_pill"||a.pad_shape&&a.pad_shape!=="rect")return;const l=a.hole_width,D=a.hole_height,d=a.hole_offset_x||0,y=a.hole_offset_y||0,w=a.rect_pad_width,u=a.rect_pad_height,G=i3(a),m=EIA,p=l+2*uR,k=D+2*uR,S=e*1.2;let R=E(p,k,S).translate([d,y,0]);if(a.hole_ccw_rotation){const O=R.rotate([0,0,a.hole_ccw_rotation]);t.push(O),R=O}const F=R.translate([a.x,a.y,0]);t.push(F),o.push(F);let N=C5({Manifold:g,width:w,height:u,thickness:Math.max(e-2*(m+nIA+sIA),Oo),borderRadius:G});if(t.push(N),a.rect_ccw_rotation){const O=N.rotate([0,0,a.rect_ccw_rotation]);t.push(O),N=O}let U=E(l,D,e*.8).translate([d,y,0]);if(a.hole_ccw_rotation){const O=U.rotate([0,0,a.hole_ccw_rotation]);t.push(O),U=O}t.push(U);const P=g.union([N,U]);t.push(P);let b=E(Math.max(l-2*zdA,.01),Math.max(D-2*zdA,.01),e*1.2).translate([d,y,0]);if(a.hole_ccw_rotation){const O=b.rotate([0,0,a.hole_ccw_rotation]);t.push(O),b=O}t.push(b);const H=P.subtract(b);t.push(H);const q=H.translate([a.x,a.y,0]);t.push(q);let j=q;if(B){const O=g.intersection([q,B]);t.push(O),j=O}i.push(j);const Z=ax(j.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:Z,color:Q5})}else if(a.shape==="hole_with_polygon_pad"){const l=a.pad_outline;if(!Array.isArray(l)||l.length<3)return;const D=s({ph:a,depth:e*1.2,sizeDelta:2*Oo});if(!D)return;const d=D.translate([a.x,a.y,0]);t.push(d),o.push(d);const w=Math.max(e-2*(EIA+nIA+sIA),Oo),u=n({padOutline:l,thickness:w});if(!u)return;const G=s({ph:a,depth:e*1.02});if(!G)return;const m=s({ph:a,depth:e*.8,sizeDelta:-2*Oo})||G,p=g.union([u,G]);t.push(p);const k=p.subtract(m);t.push(k);const S=k.translate([a.x,a.y,0]);t.push(S);let R=S;if(B){const N=g.intersection([S,B]);t.push(N),R=N}i.push(R);const F=ax(R.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:F,color:Q5})}else if(a.shape==="oval"){const l=a.hole_width,D=a.hole_height,d=a.outer_width??l+.4,y=a.outer_height??D+.4,w=l+2*uR,u=D+2*uR,G=e*1.2;let m=jdA(w,u,fd);iIA(m)&&(m=m.reverse());const p=A.ofPolygons([m]);t.push(p);let k=g.extrude(p,G,0,0,[1,1],!0);if(t.push(k),a.ccw_rotation){const AA=k.rotate([0,0,a.ccw_rotation]);t.push(AA),k=AA}const S=k.translate([a.x,a.y,0]);t.push(S),o.push(S);const R=h;let F=jdA(d,y,fd);iIA(F)&&(F=F.reverse());const N=A.ofPolygons([F]);t.push(N);const U=g.extrude(N,R,0,0,[1,1],!0);t.push(U);let P=jdA(l,D,fd);iIA(P)&&(P=P.reverse());const b=A.ofPolygons([P]);t.push(b);const H=g.extrude(b,R*1.05,0,0,[1,1],!0);t.push(H);let q=U.subtract(H);if(t.push(q),a.ccw_rotation){const AA=q.rotate([0,0,a.ccw_rotation]);t.push(AA),q=AA}const j=q.translate([a.x,a.y,0]);t.push(j);let Z=j;if(B){const AA=g.intersection([j,B]);t.push(AA),Z=AA}i.push(Z);const O=ax(Z.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:O,color:Q5})}else if(a.shape==="circular_hole_with_rect_pad"){if(a.hole_shape&&a.hole_shape!=="circle"||a.pad_shape&&a.pad_shape!=="rect")return;const l=a.hole_offset_x||0,D=a.hole_offset_y||0,d=mGI({Manifold:g,x:a.x+l,y:a.y+D,diameter:a.hole_diameter,thickness:e,segments:fd});t.push(d),o.push(d);const y=a.rect_pad_width??a.hole_diameter,w=a.rect_pad_height??a.hole_diameter,u=i3(a),G=EIA,m=a.hole_diameter/2,p=C5({Manifold:g,width:y,height:w,thickness:Math.max(e-2*(G+nIA+sIA),Oo),borderRadius:u});t.push(p);const k=g.cylinder(e*.8,m,m,fd,!0).translate([l,D,0]);t.push(k);const S=g.union([p,k]);t.push(S);const R=g.cylinder(e*1.2,Math.max(m-Oo,.01),Math.max(m-Oo,.01),fd,!0).translate([l,D,0]);t.push(R);const F=S.subtract(R);t.push(F);const N=F.translate([a.x,a.y,0]);t.push(N);let U=N;if(B){const b=g.intersection([N,B]);t.push(b),U=b}i.push(U);const P=ax(U.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:P,color:Q5})}});let r;return i.length>0&&(r=g.union(i),t.push(r)),{platedHoleBoardDrills:o,platedHoleCopperGeoms:Q,platedHoleSubtractOp:r}}function $Ot({Manifold:g,x:A,y:I,outerDiameter:e,holeDiameter:t,thickness:B,zOffset:o=.001,segments:C=32}){const Q=o;if(e<t)throw new Error(`Invalid via geometry: outerDiameter (${e}) must be >= holeDiameter (${t})`);const i=Math.min(e/2,t/2+Q),n=g.cylinder(B,i,-1,C,!0),s=B+2*o,r=g.cylinder(s,t/2,-1,C,!0);return n.subtract(r).translate([A,I,0])}var AWt=new tB(...jE.copper);function gWt(g,A,I,e,t,B=[]){const o=[],C=v$A(A),Q=[],i=[];C.forEach((n,s)=>{let r;if(typeof n.hole_diameter=="number"){const a=pGI({Manifold:g,x:n.x,y:n.y,holeDiameter:n.hole_diameter,thickness:I,zOffset:uR,segments:fd});e.push(a),o.push(a),r=a}if(typeof n.outer_diameter=="number"&&typeof n.hole_diameter=="number"){const a=$Ot({Manifold:g,x:n.x,y:n.y,outerDiameter:n.outer_diameter,holeDiameter:n.hole_diameter,thickness:I,zOffset:uR,segments:fd});e.push(a);let c=a;if(t){const h=g.intersection([a,t]);e.push(h),c=h}i.push({key:`via-${n.pcb_via_id||s}`,copper:c,ownDrill:r})}});const E=[...B,...o].map(n=>({drill:n,bounds:n.boundingBox()}));for(const{key:n,copper:s,ownDrill:r}of i){const a=s.boundingBox(),c=E.filter(({drill:l,bounds:D})=>l!==r&&[0,1,2].every(d=>D.min[d]<=a.max[d]&&D.max[d]>=a.min[d])).map(({drill:l})=>l);let h=s;if(c.length){const l=g.union(c);h=s.subtract(l),e.push(l,h)}Q.push({key:n,geometry:ax(h.getMesh()),color:AWt})}return{viaBoardDrills:o,viaCopperGeoms:Q}}var IWt=(g,A,I)=>{const e=aGI(I),[t,B]=gA.useState(null),[o,C]=gA.useState(null),[Q,i]=gA.useState(null),[E,n]=gA.useState(!0),s=gA.useRef([]),r=gA.useMemo(()=>{const l=A.filter(y=>y.type==="pcb_panel"),D=jB(A).pcb_board.list();if(l.length>0){const y=l[0],w=D.find(u=>u.pcb_panel_id===y.pcb_panel_id);return{type:"pcb_board",pcb_board_id:y.pcb_panel_id,center:y.center,width:y.width,height:y.height,thickness:w?.thickness??1.4,material:w?.material??"fr4",num_layers:w?.num_layers??2,solder_mask_color:w?.solder_mask_color}}const d=D.filter(y=>!y.pcb_panel_id);return d.length>0?d[0]:null},[A]),a=gA.useMemo(()=>{const l=jB(A).pcb_board.list();return l.length>0&&l[0].pcb_board_id==="faux-board"},[A]),c=gA.useMemo(()=>r?rGI(r,K2):K2,[r]);gA.useEffect(()=>{if(!g||!r){B(null),C(null),n(!1);return}if((r.width===0||!r.width)&&(r.height===0||!r.height)&&(!r.outline||r.outline.length<3)){B({platedHoles:[],vias:[]}),C(r.thickness??0),n(!1);return}n(!0),i(null);const l=g.Manifold,D=g.CrossSection,d=u=>{if(!(!u||typeof u.delete!="function"))try{u.delete()}catch(G){(!(G instanceof Error)||!G.message?.includes("Manifold instance already deleted"))&&console.warn("Failed to delete Manifold instance",G)}};s.current.forEach(d),s.current=[];let y=null;const w={};try{const u=r.thickness||1.4;C(u);const{boardOp:G,outlineCrossSection:m}=OOt(l,D,r,u,s.current);let p=G;const S=u+2*1;let R=null;const F=.01;if(m){let AA=m;if(F>0){const eA=m.offset(F);s.current.push(eA),AA=eA}const tA=l.extrude(AA,S,void 0,void 0,void 0,!0);s.current.push(tA),R=tA}else{const AA=(r.width||0)+2*F,tA=(r.height||0)+2*F,eA=l.cube([AA,tA,S],!0);s.current.push(eA);const iA=eA.translate([r.center.x,r.center.y,0]);s.current.push(iA),R=iA}const N=[];let U=null;const{nonPlatedHoleBoardDrills:P}=zOt(l,D,A,u,s.current);N.push(...P);const{platedHoleBoardDrills:b,platedHoleCopperGeoms:H,platedHoleSubtractOp:q}=XOt(l,D,A,u,s.current,R);N.push(...b),w.platedHoles=H;const{viaBoardDrills:j,viaCopperGeoms:Z}=gWt(l,A,u,s.current,R,N);if(N.push(...j),w.vias=Z,N.length>0){U=l.union(N),s.current.push(U);const AA=q?l.union([U,q]):U;s.current.push(AA);const tA=p.subtract(AA);if(s.current.push(tA),p=tA,q){const eA=q.subtract(U);s.current.push(eA);const iA=eA.getMesh(),sA=ax(iA);w.platedHoles=[{key:"plated-holes-union",geometry:sA,color:new tB(jE.copper[0],jE.copper[1],jE.copper[2])}]}}const{cutoutOps:O}=jOt(l,D,A,u,s.current);if(O.length>0){const AA=l.union(O);s.current.push(AA);const tA=p.subtract(AA);s.current.push(tA),p=tA}if(y=p,y){const AA=y.getMesh(),tA=ax(AA);w.board={geometry:tA,color:L$A(r),material:r.material,isFaux:a}}B(w)}catch(u){console.error("Error processing geometry with Manifold in hook:",u),i(u.message||"An unknown error occurred while processing geometry in hook."),B(null)}finally{n(!1)}return()=>{s.current.forEach(d),s.current=[]}},[g,A,r]);const h=gA.useMemo(()=>!r||!c?null:CGI({circuitJson:A,boardData:r,traceTextureResolution:c,visibility:e}),[A,r,c,e]);return{geoms:t,textures:h,pcbThickness:o,error:Q,isLoading:E,boardData:r,isFauxBoard:a}};function kGI(g,A){g.updateMatrix();const I=g.geometry.index?g.geometry.toNonIndexed():g.geometry,e=I.getAttribute("position"),t=I.getAttribute("uv"),B=[];for(let o=0;o<e.count;o+=3){const C=[0,1,2].map(s=>{const r=new oI().fromBufferAttribute(e,o+s).applyMatrix4(g.matrix);return{x:r.x-A.x,y:r.y-A.y,z:r.z}}),[Q,i,E]=C,n=new oI(i.x-Q.x,i.y-Q.y,i.z-Q.z).cross(new oI(E.x-Q.x,E.y-Q.y,E.z-Q.z)).normalize();B.push({vertices:C,normal:{x:n.x,y:n.y,z:n.z},...t?{uvs:[0,1,2].map(s=>({u:t.getX(o+s),v:t.getY(o+s)}))}:{}})}return I!==g.geometry&&I.dispose(),{triangles:B,boundingBox:QIA(B)}}function MGI(g,A){const I=[],e=[],t=[];for(const o of g.triangles)o.vertices.forEach((C,Q)=>{I.push(C.x+A.x,C.y+A.y,C.z),e.push(o.normal.x,o.normal.y,o.normal.z),t.push(o.uvs?.[Q]?.u??0,o.uvs?.[Q]?.v??0)});const B=new Jn;return B.setAttribute("position",new To(I,3)),B.setAttribute("normal",new To(e,3)),B.setAttribute("uv",new To(t,2)),B.computeBoundingBox(),B.computeBoundingSphere(),B}function SGI(g,A,I){const e=g.clone();return e.geometry=MGI(A,I.center),e.position.set(0,0,0),e.rotation.set(0,0,0),e.scale.set(1,1,1),e.updateMatrix(),e}function eWt(g,A,I,e){const t=I.filter(a=>a.type==="pcb_board"),B=I.filter(a=>a.type==="pcb_bend"),o=I.filter(a=>a.type==="pcb_stiffener");if(!B.length&&!o.length)return{geometryMeshes:g,textureMeshes:A};const C=t[0];if(!C||t.length!==1||I.some(a=>a.type==="pcb_panel")||[...B,...o].some(a=>a.pcb_board_id!==C.pcb_board_id))throw new Error("Flex rendering requires one board, matching board references, and no panel");const Q=e?uGI(B,C.thickness??1.6):void 0,i=g.find(a=>a.name==="board-geom"),E=i?kGI(i,C.center):void 0,n=Q?g.map(a=>SGI(a,GGI(kGI(a,C.center),Q),C)):[...g],s=Q&&E?A.map(a=>{a.updateMatrix();const c=a.matrix.clone().invert(),h=a.name.startsWith("bottom"),l=a.geometry.parameters,D=E.triangles.filter(y=>h?y.normal.z<-.9:y.normal.z>.9).map(y=>{const w=y.vertices.map(G=>({...G,z:a.position.z})),u=w.map(G=>{const m=new oI(G.x+C.center.x,G.y+C.center.y,G.z).applyMatrix4(c);return{u:m.x/l.width+.5,v:m.y/l.height+.5}});return{...y,vertices:w,uvs:u}}),d=SGI(a,GGI({triangles:D,boundingBox:QIA(D)},Q),C);return a.geometry.dispose(),d}):A;for(const a of o){const c=new FB(MGI(TOt({stiffener:a,boardThickness:C.thickness??1.6,fold:Q}),C.center),new Ps({color:a.material==="fr4"?"#879568":a.material==="polyimide"?"#bd7f27":"#b8bdc4",side:yl}));c.name="board-stiffener",ZM(c),n.push(c)}const r=new WG;for(const a of[...n,...s])r.expandByObject(a);return{geometryMeshes:n,textureMeshes:s,bounds:{minX:r.min.x,maxX:r.max.x,minY:r.min.y,maxY:r.max.y,minZ:r.min.z,maxZ:r.max.z}}}var tWt=yl,BWt=({material:g,color:A,side:I=tWt,isFaux:e=!1})=>g==="fr4"?new dM({color:A,side:I,metalness:0,roughness:.48,specularIntensity:.3,ior:1.45,sheen:0,clearcoat:.16,clearcoatRoughness:.3,transparent:e,opacity:e?KdA:1,flatShading:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}):new Ps({color:A,side:I,flatShading:!0,metalness:.1,roughness:.8,transparent:!0,opacity:e?KdA:.9,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});function oWt(g){const A=[];if(!g)return A;if(g.board?.geometry){const e=new FB(g.board.geometry,BWt({material:g.board.material,color:g.board.color,side:yl,isFaux:g.board.isFaux}));e.name="board-geom",ZM(e,{castShadow:!1,receiveShadow:!0}),A.push(e)}const I=e=>{if(e)for(const t of e){const B=new FB(t.geometry,new Ps({color:t.color,side:yl,flatShading:!0}));B.name=t.key,ZM(B),A.push(B)}};return I(g.platedHoles),I(g.vias),A}var XdA;function CWt(){return XdA||(XdA=(async()=>{const g=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(g&&typeof g=="object"&&g.setup)return window.ManifoldModule=g,g;const I=await(g??(await import(XgA("manifold-3d","3.2.1","manifold.js"))).default)();return I.setup(),window.ManifoldModule=I,I})().catch(g=>{throw XdA=void 0,g})),XdA}var QWt=({geometryMeshes:g,textureMeshes:A})=>{const{rootObject:I}=SD(),{visibility:e}=e5(),t=B=>{B.geometry.dispose();const o=Array.isArray(B.material)?B.material:[B.material];for(const C of o){if(!C)continue;const Q=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],i=C;for(const E of Q){const n=i[E];n&&n instanceof Hr&&n.dispose()}C.dispose()}};return gA.useEffect(()=>{if(I){for(const B of g){let o=!0;B.name==="board-geom"||B.name==="board-stiffener"?o=e.boardBody:(B.name.includes("plated_hole")||B.name.includes("via"))&&(o=e.topCopper||e.bottomCopper),o&&I.add(B)}return()=>{for(const B of g)B.parent===I&&I.remove(B),t(B)}}},[I,g,e]),gA.useEffect(()=>{if(I){for(const B of A)I.add(B);return()=>{for(const B of A)B.parent===I&&I.remove(B),t(B)}}},[I,A]),null},iWt=({circuitJson:g,foldPcbs:A,autoRotateDisabled:I,clickToInteractEnabled:e,onUserInteraction:t,children:B,onCameraControllerReady:o,resolveStaticAsset:C,referenceObject:Q,hiddenCadComponentIds:i})=>{const E=p$A(B),n=gA.useMemo(()=>dGI(g??E),[g,E]),[s,r]=gA.useState(null),[a,c]=gA.useState(null),{visibility:h}=e5();gA.useEffect(()=>{let U=!0;return CWt().then(P=>{U&&r(P)}).catch(P=>{U&&(console.error("Failed to initialize Manifold:",P),c(`Failed to initialize Manifold: ${P instanceof Error?P.message:"Unknown error"}`))}),()=>{U=!1}},[]);const{geoms:l,textures:D,pcbThickness:d,error:y,isLoading:w,boardData:u,isFauxBoard:G}=IWt(s,n,h),m=gA.useMemo(()=>{try{const U=yuI(n,A),P=vOt(n,{foldPcbs:U});return{...eWt(oWt(l),nOt(D,u,d,G),n,U),posedJson:P,error:void 0}}catch(U){return{error:U instanceof Error?U.message:String(U),geometryMeshes:[],textureMeshes:[],posedJson:n,bounds:void 0}}},[l,D,u,d,G,n,A]),p=gA.useMemo(()=>jB(m.posedJson).cad_component.list().filter(U=>!i?.has(U.cad_component_id)),[m.posedJson,i]),k=gA.useMemo(()=>cGI(m.posedJson),[m.posedJson]),S=gA.useMemo(()=>{if(!u)return;const U=ky(u);return{width:U.width,height:U.height}},[u]),R=gA.useMemo(()=>{if(!u)return;const U=ky(u);return{x:U.centerX,y:U.centerY}},[u]),F=gA.useMemo(()=>DGI({boardDimensions:S,boardCenter:R}),[S,R]),N=gA.useMemo(()=>{if(u)return JSON.stringify({pcbBoardId:u.pcb_board_id,center:R,dimensions:S})},[u,R,S]);return a?W.jsxs("div",{style:{color:"red",padding:"1em",border:"1px solid red",margin:"1em"},children:["Error: ",a]}):s?y||m.error?W.jsxs("div",{role:"alert",style:{color:"red",padding:"1em",border:"1px solid red",margin:"1em"},children:["Error: ",y??m.error]}):w?W.jsx("div",{style:{padding:"1em"},children:"Processing board geometry..."}):W.jsxs(ZuI,{initialCameraPosition:F,autoRotateDisabled:I,clickToInteractEnabled:e,boardDimensions:S,boardCenter:R,cameraSessionScope:N,referenceObject:Q,onUserInteraction:t,onCameraControllerReady:o,children:[W.jsx(QWt,{geometryMeshes:m.geometryMeshes,textureMeshes:m.textureMeshes}),m.bounds&&W.jsx(TuI,{bounds:m.bounds}),p.map(U=>W.jsx(N$A,{fallback:({error:P})=>W.jsx(AGI,{cad_component:U,error:P}),children:W.jsx(FuI,{cad_component:U,circuitJson:m.posedJson,resolveStaticAsset:C})},U.cad_component_id)),k.map(U=>W.jsx(lGI,{cable:U},U.cad_cable_id))]}):W.jsx("div",{style:{padding:"1em"},children:"Loading Manifold module..."})},fGI=iWt,EWt=Object.defineProperty,nT=(g,A)=>EWt(g,"name",{value:A,configurable:!0}),RGI=!!(typeof window<"u"&&window.document&&window.document.createElement);function un(g,A,{checkForDefaultPrevented:I=!0}={}){return nT(function(t){if(g?.(t),I===!1||!t||!t.defaultPrevented)return A?.(t)},"handleEvent")}nT(un,"composeEventHandlers");function nWt(g){if(!RGI)throw new Error("Cannot access window outside of the DOM");return g?.ownerDocument?.defaultView??window}nT(nWt,"getOwnerWindow");function gAg(g){if(!RGI)throw new Error("Cannot access document outside of the DOM");return g?.ownerDocument??document}nT(gAg,"getOwnerDocument");function NGI(g,A=!1){const{activeElement:I}=gAg(g);if(!I?.nodeName)return null;if(xGI(I)&&I.contentDocument)return NGI(I.contentDocument.body,A);if(A){const e=I.getAttribute("aria-activedescendant");if(e){const t=gAg(I).getElementById(e);if(t)return t}}return I}nT(NGI,"getActiveElement");function xGI(g){return g.tagName==="IFRAME"}nT(xGI,"isFrame");var sWt=Object.defineProperty,IAg=(g,A)=>sWt(g,"name",{value:A,configurable:!0});function eAg(g,A){if(typeof g=="function")return g(A);g!=null&&(g.current=A)}IAg(eAg,"setRef");function FGI(...g){return A=>{let I=!1;const e=g.map(t=>{const B=eAg(t,A);return!I&&typeof B=="function"&&(I=!0),B});if(I)return()=>{for(let t=0;t<e.length;t++){const B=e[t];typeof B=="function"?B():eAg(g[t],null)}}}}IAg(FGI,"composeRefs");function Rd(...g){return gA.useCallback(FGI(...g),g)}IAg(Rd,"useComposedRefs");var aWt=Object.defineProperty,P2=(g,A)=>aWt(g,"name",{value:A,configurable:!0});function rWt(g,A){const I=gA.createContext(A);I.displayName=g+"Context";const e=P2(B=>{const{children:o,...C}=B,Q=gA.useMemo(()=>C,Object.values(C));return W.jsx(I.Provider,{value:Q,children:o})},"Provider");e.displayName=g+"Provider";function t(B,o={}){const{optional:C=!1}=o,Q=gA.useContext(I);if(Q)return Q;if(A!==void 0)return A;if(!C)throw new Error(`\`${B}\` must be used within \`${g}\``)}return P2(t,"useContext"),[e,t]}P2(rWt,"createContext");function i5(g,A=[]){let I=[];function e(B,o){const C=gA.createContext(o);C.displayName=B+"Context";const Q=I.length;I=[...I,o];const i=P2(n=>{const{scope:s,children:r,...a}=n,c=s?.[g]?.[Q]||C,h=gA.useMemo(()=>a,Object.values(a));return W.jsx(c.Provider,{value:h,children:r})},"Provider");i.displayName=B+"Provider";function E(n,s,r={}){const{optional:a=!1}=r,c=s?.[g]?.[Q]||C,h=gA.useContext(c);if(h)return h;if(o!==void 0)return o;if(!a)throw new Error(`\`${n}\` must be used within \`${B}\``)}return P2(E,"useContext"),[i,E]}P2(e,"createContext");const t=P2(()=>{const B=I.map(o=>gA.createContext(o));return P2(function(C){const Q=C?.[g]||B;return gA.useMemo(()=>({[`__scope${g}`]:{...C,[g]:Q}}),[C,Q])},"useScope")},"createScope");return t.scopeName=g,[e,UGI(t,...A)]}P2(i5,"createContextScope");function UGI(...g){const A=g[0];if(g.length===1)return A;const I=P2(()=>{const e=g.map(t=>({useScope:t(),scopeName:t.scopeName}));return P2(function(B){const o=e.reduce((C,{useScope:Q,scopeName:i})=>{const n=Q(B)[`__scope${i}`];return{...C,...n}},{});return gA.useMemo(()=>({[`__scope${A.scopeName}`]:o}),[o])},"useComposedScopes")},"createScope");return I.scopeName=A.scopeName,I}P2(UGI,"composeContextScopes");var WM=globalThis?.document?gA.useLayoutEffect:()=>{},cWt=Object.defineProperty,hWt=(g,A)=>cWt(g,"name",{value:A,configurable:!0}),JGI=Gp[" useEffectEvent ".trim().toString()],KGI=Gp[" useInsertionEffect ".trim().toString()];function PGI(g){if(typeof JGI=="function")return JGI(g);const A=gA.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof KGI=="function"?KGI(()=>{A.current=g}):WM(()=>{A.current=g}),gA.useMemo(()=>((...I)=>A.current?.(...I)),[])}hWt(PGI,"useEffectEvent");var lWt=Object.defineProperty,aIA=(g,A)=>lWt(g,"name",{value:A,configurable:!0}),DWt=Gp[" useInsertionEffect ".trim().toString()]||WM;function $dA({prop:g,defaultProp:A,onChange:I=aIA(()=>{},"onChange"),caller:e}){const[t,B,o]=LGI({defaultProp:A,onChange:I}),C=g!==void 0,Q=C?g:t,i=gA.useCallback(E=>{if(C){const n=YGI(E)?E(g):E;n!==g&&o.current?.(n)}else B(E)},[C,g,B,o]);return[Q,i]}aIA($dA,"useControllableState");function LGI({defaultProp:g,onChange:A}){const[I,e]=gA.useState(g),t=gA.useRef(I),B=gA.useRef(A);return DWt(()=>{B.current=A},[A]),gA.useEffect(()=>{t.current!==I&&(B.current?.(I),t.current=I)},[I,t]),[I,e,B]}aIA(LGI,"useUncontrolledState");function YGI(g){return typeof g=="function"}aIA(YGI,"isFunction");var _GI=Symbol("RADIX:SYNC_STATE");function dWt(g,A,I,e){const{prop:t,defaultProp:B,onChange:o,caller:C}=A,Q=t!==void 0,i=PGI(o),E=[{...I,state:B}];e&&E.push(e);const[n,s]=gA.useReducer((h,l)=>{if(l.type===_GI)return{...h,state:l.state};const D=g(h,l);return Q&&!Object.is(D.state,h.state)&&i(D.state),D},...E),r=n.state,a=gA.useRef(r);gA.useEffect(()=>{a.current!==r&&(a.current=r,Q||i(r))},[r,a,Q]);const c=gA.useMemo(()=>t!==void 0?{...n,state:t}:n,[n,t]);return gA.useEffect(()=>{Q&&!Object.is(t,n.state)&&s({type:_GI,state:t})},[t,n.state,Q]),[c,s]}aIA(dWt,"useControllableStateReducer");var yWt=Object.defineProperty,VM=(g,A)=>yWt(g,"name",{value:A,configurable:!0});function E5(g){const A=gA.forwardRef((I,e)=>{let{children:t,...B}=I,o=null,C=!1;const Q=[];t=ZGI(t),gA.Children.forEach(t,s=>{if(qGI(s)){C=!0;const r=s;let a="child"in r.props?r.props.child:r.props.children;for(;tAg(a)&&typeof AyA=="function";)a=AyA(a._payload);o=uWt(r,a),Q.push(o?.props?.children)}else Q.push(s)}),o?o=gA.cloneElement(o,void 0,Q):!C&&gA.Children.count(t)===1&&gA.isValidElement(t)&&(o=t);const i=o?vGI(o):void 0,E=Rd(e,i);if(!o){if(t||t===0)throw new Error(C?pWt(g):mWt(g));return t}const n=HGI(B,o.props??{});return o.type!==gA.Fragment&&(n.ref=e?E:i),gA.cloneElement(o,n)});return A.displayName=`${g}.Slot`,A}VM(E5,"createSlot");var bGI=Symbol.for("radix.slottable");function wWt(g){const A=VM(I=>"child"in I?I.children(I.child):I.children,"Slottable");return A.displayName=`${g}.Slottable`,A.__radixId=bGI,A}VM(wWt,"createSlottable");var uWt=VM((g,A)=>"child"in g.props?gA.isValidElement(A)?gA.cloneElement(A,void 0,g.props.children(A.props.children)):null:gA.isValidElement(A)?A:null,"getSlottableElementFromSlottable");function HGI(g,A){const I={...A};for(const e in A){const t=g[e],B=A[e];/^on[A-Z]/.test(e)?t&&B?I[e]=(...C)=>{const Q=B(...C);return t(...C),Q}:t&&(I[e]=t):e==="style"?I[e]={...t,...B}:e==="className"?I[e]=[t,B].filter(Boolean).join(" "):e==="aria-describedby"&&(I[e]=OGI(B,t))}return{...g,...I}}VM(HGI,"mergeProps");function vGI(g){let A=Object.getOwnPropertyDescriptor(g.props,"ref")?.get,I=A&&"isReactWarning"in A&&A.isReactWarning;return I?g.ref:(A=Object.getOwnPropertyDescriptor(g,"ref")?.get,I=A&&"isReactWarning"in A&&A.isReactWarning,I?g.props.ref:g.props.ref||g.ref)}VM(vGI,"getElementRef");function qGI(g){return gA.isValidElement(g)&&typeof g.type=="function"&&"__radixId"in g.type&&g.type.__radixId===bGI}VM(qGI,"isSlottable");var GWt=Symbol.for("react.lazy");function tAg(g){return g!=null&&typeof g=="object"&&"$$typeof"in g&&g.$$typeof===GWt&&"_payload"in g&&TGI(g._payload)}VM(tAg,"isLazyComponent");function TGI(g){return typeof g=="object"&&g!==null&&"then"in g}VM(TGI,"isPromiseLike");function ZGI(g){let A=g;for(;tAg(A)&&typeof AyA=="function";)A=AyA(A._payload);return A}VM(ZGI,"useUnwrappedLazy");function OGI(...g){const A=new Set;for(const I of g)if(typeof I=="string")for(const e of String(I).trim().split(/\s+/))e&&A.add(e);return A.size>0?Array.from(A).join(" "):void 0}VM(OGI,"concatAriaDescribedby");var mWt=VM(g=>`${g} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),pWt=VM(g=>`${g} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),AyA=Gp[" use ".trim().toString()],kWt=Object.defineProperty,MWt=(g,A)=>kWt(g,"name",{value:A,configurable:!0}),SWt=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],rx=SWt.reduce((g,A)=>{const I=E5(`Primitive.${A}`),e=gA.forwardRef((t,B)=>{const{asChild:o,...C}=t,Q=o?I:A;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),W.jsx(Q,{...C,ref:B})});return e.displayName=`Primitive.${A}`,{...g,[A]:e}},{});function BAg(g,A){g&&CN.flushSync(()=>g.dispatchEvent(A))}MWt(BAg,"dispatchDiscreteCustomEvent");var fWt=Object.defineProperty,Nd=(g,A)=>fWt(g,"name",{value:A,configurable:!0});function oAg(g){const A=g+"CollectionProvider",[I,e]=i5(A),[t,B]=I(A,{collectionRef:{current:null},itemMap:new Map}),o=Nd(c=>{const{scope:h,children:l}=c,D=gA.useRef(null),d=gA.useRef(new Map).current;return W.jsx(t,{scope:h,itemMap:d,collectionRef:D,children:l})},"CollectionProvider");o.displayName=A;const C=g+"CollectionSlot",Q=E5(C),i=gA.forwardRef((c,h)=>{const{scope:l,children:D}=c,d=B(C,l),y=Rd(h,d.collectionRef);return W.jsx(Q,{ref:y,children:D})});i.displayName=C;const E=g+"CollectionItemSlot",n="data-radix-collection-item",s=E5(E),r=gA.forwardRef((c,h)=>{const{scope:l,children:D,...d}=c,y=gA.useRef(null),w=Rd(h,y),u=B(E,l);return gA.useEffect(()=>(u.itemMap.set(y,{ref:y,...d}),()=>{u.itemMap.delete(y)})),W.jsx(s,{[n]:"",ref:w,children:D})});r.displayName=E;function a(c){const h=B(g+"CollectionConsumer",c);return gA.useCallback(()=>{const D=h.collectionRef.current;if(!D)return[];const d=Array.from(D.querySelectorAll(`[${n}]`));return Array.from(h.itemMap.values()).sort((u,G)=>d.indexOf(u.ref.current)-d.indexOf(G.ref.current))},[h.collectionRef,h.itemMap])}return Nd(a,"useCollection"),[{Provider:o,Slot:i,ItemSlot:r},a,e]}Nd(oAg,"createCollection");var WGI=new WeakMap,gyA=(nS=class extends Map{constructor(I){super(I);Drg(this,Jl);pBA(this,Jl,[...super.keys()]),WGI.set(this,!0)}set(I,e){return WGI.get(this)&&!this.has(I)&&jn(this,Jl).push(I),super.set(I,e),this}insert(I,e,t){const B=this.has(e),o=B?this.size:this.size+1,C=CAg(I),Q=C>=0?Math.min(C,o-1):Math.max(o+C,0);if(B?jn(this,Jl).indexOf(e)===Q:Q===this.size)return this.set(e,t),this;const i=jn(this,Jl).filter(n=>n!==e);i.splice(Q,0,e);const E=i.map(n=>[n,n===e?t:this.get(n)]);this.clear();for(const[n,s]of E)this.set(n,s);return this}with(I,e,t){const B=new nS(this);return B.insert(I,e,t),B}before(I){const e=jn(this,Jl).indexOf(I)-1;if(!(e<0))return this.entryAt(e)}setBefore(I,e,t){const B=jn(this,Jl).indexOf(I);if(B===-1)return this;const o=jn(this,Jl).indexOf(e),C=o!==-1&&o<B?B-1:B;return this.insert(C,e,t)}after(I){let e=jn(this,Jl).indexOf(I);if(e=e===-1||e===this.size-1?-1:e+1,e!==-1)return this.entryAt(e)}setAfter(I,e,t){const B=jn(this,Jl).indexOf(I);if(B===-1)return this;const o=jn(this,Jl).indexOf(e),C=o!==-1&&o<=B?B:B+1;return this.insert(C,e,t)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return pBA(this,Jl,[]),super.clear()}delete(I){const e=super.delete(I);return e&&jn(this,Jl).splice(jn(this,Jl).indexOf(I),1),e}deleteAt(I){const e=this.keyAt(I);return e!==void 0?this.delete(e):!1}at(I){const e=IyA(jn(this,Jl),I);if(e!==void 0)return this.get(e)}entryAt(I){const e=IyA(jn(this,Jl),I);if(e!==void 0)return[e,this.get(e)]}indexOf(I){return jn(this,Jl).indexOf(I)}keyAt(I){return IyA(jn(this,Jl),I)}from(I,e){const t=this.indexOf(I);if(t===-1)return;let B=t+e;return B<0&&(B=0),B>=this.size&&(B=this.size-1),this.at(B)}keyFrom(I,e){const t=this.indexOf(I);if(t===-1)return;let B=t+e;return B<0&&(B=0),B>=this.size&&(B=this.size-1),this.keyAt(B)}find(I,e){let t=0;for(const B of this){if(Reflect.apply(I,e,[B,t,this]))return B;t++}}findIndex(I,e){let t=0;for(const B of this){if(Reflect.apply(I,e,[B,t,this]))return t;t++}return-1}filter(I,e){const t=[];let B=0;for(const o of this)Reflect.apply(I,e,[o,B,this])&&t.push(o),B++;return new nS(t)}map(I,e){const t=[];let B=0;for(const o of this)t.push([o[0],Reflect.apply(I,e,[o,B,this])]),B++;return new nS(t)}reduce(...I){const[e,t]=I,B=I.length>1;if(!B&&this.size===0)throw new TypeError("Reduce of empty OrderedDict with no initial value");let o=0,C=t;for(const Q of this)o===0&&!B?C=Q:C=Reflect.apply(e,this,[C,Q,o,this]),o++;return C}reduceRight(...I){const[e,t]=I,B=I.length>1;if(!B&&this.size===0)throw new TypeError("Reduce of empty OrderedDict with no initial value");let o=t;for(let C=this.size-1;C>=0;C--){const Q=this.entryAt(C);C===this.size-1&&!B?o=Q:o=Reflect.apply(e,this,[o,Q,C,this])}return o}sort(I){if(typeof I!="function")throw new TypeError("OrderedDict.sort requires a compare function");const e=[...this.entries()].sort(I);this.clear();for(const[t,B]of e)this.set(t,B);return this}toSorted(I){if(typeof I!="function")throw new TypeError("OrderedDict.toSorted requires a compare function");const e=[...this.entries()].sort(I);return new nS(e)}toReversed(){const I=new nS;for(let e=this.size-1;e>=0;e--){const t=this.keyAt(e),B=this.get(t);I.set(t,B)}return I}toSpliced(...I){const e=[...this.entries()];return e.splice(...I),new nS(e)}slice(I,e){const t=new nS;for(const B of jn(this,Jl).slice(I,e))t.set(B,this.get(B));return t}every(I,e){let t=0;for(const B of this){if(!Reflect.apply(I,e,[B,t,this]))return!1;t++}return!0}some(I,e){let t=0;for(const B of this){if(Reflect.apply(I,e,[B,t,this]))return!0;t++}return!1}},Jl=new WeakMap,Nd(nS,"OrderedDict"),nS);function IyA(g,A){if("at"in Array.prototype)return Array.prototype.at.call(g,A);const I=VGI(g,A);return I===-1?void 0:g[I]}Nd(IyA,"at");function VGI(g,A){const I=g.length,e=CAg(A),t=e>=0?e:I+e;return t<0||t>=I?-1:t}Nd(VGI,"toSafeIndex");function CAg(g){return g!==g||g===0?0:Math.trunc(g)}Nd(CAg,"toSafeInteger");function RWt(g){const A=g+"CollectionProvider",[I,e]=i5(A),[t,B]=I(A);t.displayName=g+"CollectionStableContextProvider";const[o,C]=I(A);o.displayName=g+"CollectionStatefulContextProvider";const Q=Nd(({state:u,...G})=>u?W.jsx(E,{...G,state:u}):W.jsx(i,{...G}),"CollectionProvider");Q.displayName=A;const i=Nd(u=>{const G=D();return W.jsx(E,{...u,state:G})},"CollectionInit");i.displayName=g+"CollectionInit";const E=Nd(u=>{const{scope:G,children:m,state:p}=u,k=gA.useRef(null),[S,R]=gA.useState(null),F=Rd(k,R),[N,U]=p,P=gA.useRef(new gyA),b=gA.useCallback(()=>{const H=P.current;return XGI(H)||H.sort(eyA),H},[]);return gA.useEffect(()=>{if(!S)return;const H=$GI(()=>{U(q=>{const j=q.toSorted(eyA);return j.some(([O],AA)=>q.keyAt(AA)!==O)?j:q})});return H.observe(S,{childList:!0,subtree:!0}),()=>{H.disconnect()}},[S,U]),W.jsx(t,{scope:G,collectionElementRef:F,collectionElementRefObject:k,getCollection:b,setCollection:U,registryRef:P,children:W.jsx(o,{scope:G,collectionElement:S,collection:N,children:m})})},"CollectionProviderImpl");E.displayName=g+"CollectionProviderImpl";const n=g+"CollectionSlot",s=E5(n),r=gA.forwardRef((u,G)=>{const{scope:m,children:p}=u,k=B(n,m),S=Rd(G,k.collectionElementRef);return W.jsx(s,{ref:S,children:p})});r.displayName=n;const a=g+"CollectionItemSlot",c="data-radix-collection-item",h=E5(a),l=gA.forwardRef((u,G)=>{const{scope:m,children:p,...k}=u,S=gA.useRef(null),R=B(a,m),{setCollection:F,registryRef:N}=R,U=gA.useRef(k);jGI(U.current,k)||(U.current=k);const P=U.current,b=gA.useCallback(j=>{const Z=N.current;j?Z.set(j,{...U.current,element:j}):S.current&&Z.delete(S.current)},[N]),H=Rd(G,b,S);WM(()=>{const j=S.current,Z=N.current;j&&Z.has(j)&&Z.set(j,{...P,element:j})},[P,N]);const q=gA.useRef(null);return gA.useEffect(()=>{const j=S.current,Z=q.current;(Z?.element??null)===j&&(!j||Z?.itemData===P)||(q.current=j?{element:j,itemData:P}:null,F(O=>{const AA=new gyA(O);return Z&&Z.element!==j&&AA.delete(Z.element),j&&AA.set(j,{...P,element:j}),AA.sort(eyA)}))}),gA.useEffect(()=>()=>{const j=q.current;q.current=null,j&&F(Z=>{if(!Z.has(j.element))return Z;const O=new gyA(Z);return O.delete(j.element),O})},[F]),W.jsx(h,{[c]:"",ref:H,children:p})});l.displayName=a;function D(){return gA.useState(new gyA)}Nd(D,"useInitCollection");function d(u){const{collection:G}=C(g+"CollectionConsumer",u);return G}Nd(d,"useCollection");function y(u){const{getCollection:G}=B(g+"CollectionConsumer",u);return G}return Nd(y,"useGetCollection"),[{Provider:Q,Slot:r,ItemSlot:l},{createCollectionScope:e,useCollection:d,useGetCollection:y,useInitCollection:D}]}Nd(RWt,"createCollection");function jGI(g,A){if(g===A)return!0;if(typeof g!="object"||typeof A!="object"||g==null||A==null)return!1;const I=Object.keys(g),e=Object.keys(A);if(I.length!==e.length)return!1;for(const t of I)if(!Object.prototype.hasOwnProperty.call(A,t)||g[t]!==A[t])return!1;return!0}Nd(jGI,"shallowEqual");function zGI(g,A){return!!(A.compareDocumentPosition(g)&Node.DOCUMENT_POSITION_PRECEDING)}Nd(zGI,"isElementPreceding");function XGI(g){let A;for(const I of g.keys()){if(A){const e=A.compareDocumentPosition(I);if(!(e&Node.DOCUMENT_POSITION_DISCONNECTED)&&e&Node.DOCUMENT_POSITION_PRECEDING)return!1}A=I}return!0}Nd(XGI,"isInDocumentOrder");function eyA(g,A){return!g[1].element||!A[1].element?0:zGI(g[1].element,A[1].element)?-1:1}Nd(eyA,"sortByDocumentPosition");function $GI(g){return new MutationObserver(I=>{for(const e of I)if(e.type==="childList"){g();return}})}Nd($GI,"getChildListObserver");var NWt=Object.defineProperty,xWt=(g,A)=>NWt(g,"name",{value:A,configurable:!0}),FWt={LTR:"ltr"},UWt=gA.createContext(void 0);function QAg(g){const A=gA.useContext(UWt);return g||A||FWt.LTR}xWt(QAg,"useDirection");var JWt=Object.defineProperty,KWt=(g,A)=>JWt(g,"name",{value:A,configurable:!0}),AmI=Gp[" useInsertionEffect ".trim().toString()];function cx(g){const A=gA.useRef(g);return typeof AmI=="function"?AmI(()=>{A.current=g}):WM(()=>{A.current=g}),gA.useMemo(()=>((...I)=>A.current?.(...I)),[])}KWt(cx,"useCallbackRef");var PWt=Object.defineProperty,Sy=(g,A)=>PWt(g,"name",{value:A,configurable:!0}),iAg="dismissableLayer.update",LWt="dismissableLayer.pointerDownOutside",YWt="dismissableLayer.focusOutside",gmI,ImI=gA.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),_Wt=gA.forwardRef(Sy(function(A,I){const{disableOutsidePointerEvents:e=!1,deferPointerDownOutside:t=!1,onEscapeKeyDown:B,onPointerDownOutside:o,onFocusOutside:C,onInteractOutside:Q,onDismiss:i,...E}=A,n=gA.useContext(ImI),[s,r]=gA.useState(null),a=s?.ownerDocument??globalThis?.document,[,c]=gA.useState({}),h=Rd(I,r),l=Array.from(n.layers),[D]=[...n.layersWithOutsidePointerEventsDisabled].slice(-1),d=D?l.indexOf(D):-1,y=s?l.indexOf(s):-1,w=n.layersWithOutsidePointerEventsDisabled.size>0,u=y>=d,G=gA.useRef(!1),m=emI(R=>{o?.(R),Q?.(R),R.defaultPrevented||i?.()},{ownerDocument:a,deferPointerDownOutside:t,isDeferredPointerDownOutsideRef:G,dismissableSurfaces:n.dismissableSurfaces,shouldHandlePointerDownOutside:gA.useCallback(R=>{if(!(R instanceof Node))return!1;const F=[...n.branches].some(N=>N.contains(R));return u&&!F},[n.branches,u])}),p=tmI(R=>{if(t&&G.current)return;const F=R.target;[...n.branches].some(U=>U.contains(F))||(C?.(R),Q?.(R),R.defaultPrevented||i?.())},a),k=s?y===l.length-1:!1,S=cx(R=>{R.key==="Escape"&&(B?.(R),!R.defaultPrevented&&i&&(R.preventDefault(),i()))});return gA.useEffect(()=>{if(k)return a.addEventListener("keydown",S,{capture:!0}),()=>a.removeEventListener("keydown",S,{capture:!0})},[a,k,S]),gA.useEffect(()=>{if(s)return e&&(n.layersWithOutsidePointerEventsDisabled.size===0&&(gmI=a.body.style.pointerEvents,a.body.style.pointerEvents="none"),n.layersWithOutsidePointerEventsDisabled.add(s)),n.layers.add(s),EAg(),()=>{e&&(n.layersWithOutsidePointerEventsDisabled.delete(s),n.layersWithOutsidePointerEventsDisabled.size===0&&(a.body.style.pointerEvents=gmI))}},[s,a,e,n]),gA.useEffect(()=>()=>{s&&(n.layers.delete(s),n.layersWithOutsidePointerEventsDisabled.delete(s),EAg())},[s,n]),gA.useEffect(()=>{const R=Sy(()=>c({}),"handleUpdate");return document.addEventListener(iAg,R),()=>document.removeEventListener(iAg,R)},[]),W.jsx(rx.div,{...E,ref:h,style:{pointerEvents:w?u?"auto":"none":void 0,...A.style},onFocusCapture:un(A.onFocusCapture,p.onFocusCapture),onBlurCapture:un(A.onBlurCapture,p.onBlurCapture),onPointerDownCapture:un(A.onPointerDownCapture,m.onPointerDownCapture)})},"DismissableLayer"));function bWt(){const g=gA.useContext(ImI),[A,I]=gA.useState(null);return gA.useEffect(()=>{if(A)return g.dismissableSurfaces.add(A),()=>{g.dismissableSurfaces.delete(A)}},[A,g.dismissableSurfaces]),I}Sy(bWt,"useDismissableLayerSurface");var HWt=Sy(()=>!0,"IS_TRUE");function emI(g,A){const{ownerDocument:I=globalThis?.document,deferPointerDownOutside:e=!1,isDeferredPointerDownOutsideRef:t,dismissableSurfaces:B,shouldHandlePointerDownOutside:o=HWt}=A,C=cx(g),Q=gA.useRef(!1),i=gA.useRef(!1),E=gA.useRef(new Map),n=gA.useRef(()=>{});return gA.useEffect(()=>{function s(){i.current=!1,t.current=!1,E.current.clear()}Sy(s,"resetOutsideInteraction");function r(){return Array.from(E.current.values()).some(Boolean)}Sy(r,"isOutsideInteractionIntercepted");function a(d){if(!i.current)return;const y=d.target;y instanceof Node&&[...B].some(u=>u.contains(y))||E.current.set(d.type,!0),d.type==="click"&&window.setTimeout(()=>{i.current&&n.current()},0)}Sy(a,"handleInteractionCapture");function c(d){i.current&&E.current.set(d.type,!1)}Sy(c,"handleInteractionBubble");const h=Sy(d=>{if(d.target&&!Q.current){let y=function(){I.removeEventListener("click",n.current);const u=r();s(),u||nAg(LWt,C,w,{discrete:!0})};if(Sy(y,"handleAndDispatchPointerDownOutsideEvent"),!o(d.target)){I.removeEventListener("click",n.current),s(),Q.current=!1;return}const w={originalEvent:d};i.current=!0,t.current=e&&d.button===0,E.current.clear(),!e||d.button!==0?y():(I.removeEventListener("click",n.current),n.current=y,I.addEventListener("click",n.current,{once:!0}))}else I.removeEventListener("click",n.current),s();Q.current=!1},"handlePointerDown"),l=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const d of l)I.addEventListener(d,a,!0),I.addEventListener(d,c);const D=window.setTimeout(()=>{I.addEventListener("pointerdown",h)},0);return()=>{window.clearTimeout(D),I.removeEventListener("pointerdown",h),I.removeEventListener("click",n.current);for(const d of l)I.removeEventListener(d,a,!0),I.removeEventListener(d,c)}},[I,C,e,t,B,o]),{onPointerDownCapture:Sy(()=>Q.current=!0,"onPointerDownCapture")}}Sy(emI,"usePointerDownOutside");function tmI(g,A=globalThis?.document){const I=cx(g),e=gA.useRef(!1);return gA.useEffect(()=>{const t=Sy(B=>{B.target&&!e.current&&nAg(YWt,I,{originalEvent:B},{discrete:!1})},"handleFocus");return A.addEventListener("focusin",t),()=>A.removeEventListener("focusin",t)},[A,I]),{onFocusCapture:Sy(()=>e.current=!0,"onFocusCapture"),onBlurCapture:Sy(()=>e.current=!1,"onBlurCapture")}}Sy(tmI,"useFocusOutside");function EAg(){const g=new CustomEvent(iAg);document.dispatchEvent(g)}Sy(EAg,"dispatchUpdate");function nAg(g,A,I,{discrete:e}){const t=I.originalEvent.target,B=new CustomEvent(g,{bubbles:!1,cancelable:!0,detail:I});A&&t.addEventListener(g,A,{once:!0}),e?BAg(t,B):t.dispatchEvent(B)}Sy(nAg,"handleAndDispatchCustomEvent");var vWt=Object.defineProperty,sAg=(g,A)=>vWt(g,"name",{value:A,configurable:!0}),tyA=0,sT=null;function qWt(g){return aAg(),g.children}sAg(qWt,"FocusGuards");function aAg(){gA.useEffect(()=>{sT||(sT={start:rAg(),end:rAg()});const{start:g,end:A}=sT;return document.body.firstElementChild!==g&&document.body.insertAdjacentElement("afterbegin",g),document.body.lastElementChild!==A&&document.body.insertAdjacentElement("beforeend",A),tyA++,()=>{tyA===1&&(sT?.start.remove(),sT?.end.remove(),sT=null),tyA=Math.max(0,tyA-1)}},[])}sAg(aAg,"useFocusGuards");function rAg(){const g=document.createElement("span");return g.setAttribute("data-radix-focus-guard",""),g.tabIndex=0,g.style.outline="none",g.style.opacity="0",g.style.position="fixed",g.style.pointerEvents="none",g}sAg(rAg,"createFocusGuard");var TWt=Object.defineProperty,fD=(g,A)=>TWt(g,"name",{value:A,configurable:!0}),cAg="focusScope.autoFocusOnMount",hAg="focusScope.autoFocusOnUnmount",BmI={bubbles:!1,cancelable:!0},ZWt=gA.forwardRef(fD(function(A,I){const{loop:e=!1,trapped:t=!1,branches:B,onMountAutoFocus:o,onUnmountAutoFocus:C,...Q}=A,[i,E]=gA.useState(null),n=cx(o),s=cx(C),r=gA.useRef(null),a=Rd(I,E),c=gA.useRef(B);gA.useEffect(()=>{c.current=B});const h=gA.useCallback(d=>d?i?.contains(d)?!0:!!c.current?.some(y=>y.contains(d)):!1,[i]),l=gA.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;gA.useEffect(()=>{if(t){let d=function(G){if(l.paused||!i)return;const m=G.target;h(m)?r.current=m:IJ(r.current,{select:!0})},y=function(G){if(l.paused||!i)return;const m=G.relatedTarget;m!==null&&(h(m)||IJ(r.current,{select:!0}))},w=function(G){if(document.activeElement===document.body)for(const p of G)p.removedNodes.length>0&&IJ(i)};fD(d,"handleFocusIn"),fD(y,"handleFocusOut"),fD(w,"handleMutations"),document.addEventListener("focusin",d),document.addEventListener("focusout",y);const u=new MutationObserver(w);return i&&u.observe(i,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",d),document.removeEventListener("focusout",y),u.disconnect()}}},[t,i,l.paused,h]),gA.useEffect(()=>{if(i){rmI.add(l);const d=document.activeElement;if(!i.contains(d)){const w=new CustomEvent(cAg,BmI);i.addEventListener(cAg,n),i.dispatchEvent(w),w.defaultPrevented||(EmI(hmI(lAg(i)),{select:!0}),document.activeElement===d&&IJ(i))}return()=>{i.removeEventListener(cAg,n);const w=i.ownerDocument,u=CustomEvent;setTimeout(()=>{const G=new u(hAg,BmI);i.addEventListener(hAg,s),i.dispatchEvent(G),G.defaultPrevented||IJ(d??w.body,{select:!0}),i.removeEventListener(hAg,s),rmI.remove(l)},0)}}},[i,n,s,l]);const D=gA.useCallback(d=>{if(!e&&!t||l.paused)return;const y=d.key==="Tab"&&!d.altKey&&!d.ctrlKey&&!d.metaKey,w=document.activeElement;if(y&&w){const u=d.currentTarget,[G,m]=nmI(u);G&&m?!d.shiftKey&&w===m?(d.preventDefault(),e&&IJ(G,{select:!0})):d.shiftKey&&w===G&&(d.preventDefault(),e&&IJ(m,{select:!0})):w===u&&d.preventDefault()}},[e,t,l.paused]);return W.jsx(rx.div,{tabIndex:-1,...Q,ref:a,onKeyDown:D})},"FocusScope")),omI=gA.createContext(null);function CmI({registry:g,children:A}){return g?W.jsx(omI.Provider,{value:g,children:A}):A}fD(CmI,"FocusScopeBranchProvider");function QmI(){const[g,A]=gA.useState([]),I=gA.useMemo(()=>({add:fD(e=>A(t=>t.includes(e)?t:[...t,e]),"add"),remove:fD(e=>A(t=>t.filter(B=>B!==e)),"remove")}),[]);return{nodes:g,registry:I}}fD(QmI,"useFocusScopeBranchRegistry");function imI(g){const A=gA.useContext(omI);gA.useEffect(()=>{if(!(!g||!A))return A.add(g),()=>A.remove(g)},[g,A])}fD(imI,"useFocusScopeBranch");function EmI(g,{select:A=!1}={}){const I=document.activeElement;for(const e of g)if(IJ(e,{select:A}),document.activeElement!==I)return}fD(EmI,"focusFirst");function nmI(g){const A=lAg(g),I=DAg(A,g),e=DAg(A.reverse(),g);return[I,e]}fD(nmI,"getTabbableEdges");function lAg(g){const A=[],e=g.ownerDocument.createTreeWalker(g,NodeFilter.SHOW_ELEMENT,{acceptNode:fD(t=>{const B=t.tagName==="INPUT"&&t.type==="hidden";return t.disabled||t.hidden||B?NodeFilter.FILTER_SKIP:t.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;e.nextNode();)A.push(e.currentNode);return A}fD(lAg,"getTabbableCandidates");function DAg(g,A){const I=typeof A.checkVisibility=="function"&&A.checkVisibility({checkVisibilityCSS:!0});for(const e of g)if(!(I?!e.checkVisibility({checkVisibilityCSS:!0}):smI(e,{upTo:A})))return e}fD(DAg,"findVisible");function smI(g,{upTo:A}){if(getComputedStyle(g).visibility==="hidden")return!0;for(;g;){if(A!==void 0&&g===A)return!1;if(getComputedStyle(g).display==="none")return!0;g=g.parentElement}return!1}fD(smI,"isHidden");function amI(g){return g.tagName==="INPUT"&&typeof g.select=="function"}fD(amI,"isSelectableInput");function IJ(g,{select:A=!1}={}){if(g&&g.focus){const e=(g.ownerDocument??document).activeElement;g.focus({preventScroll:!0}),g!==e&&amI(g)&&A&&g.select()}}fD(IJ,"focus");var rmI=cmI();function cmI(){let g=[];return{add(A){const I=g[0];A!==I&&I?.pause(),g=dAg(g,A),g.unshift(A)},remove(A){g=dAg(g,A),g[0]?.resume()}}}fD(cmI,"createFocusScopesStack");function dAg(g,A){const I=[...g],e=I.indexOf(A);return e!==-1&&I.splice(e,1),I}fD(dAg,"arrayRemove");function hmI(g){return g.filter(A=>A.tagName!=="A")}fD(hmI,"removeLinks");var OWt=Object.defineProperty,WWt=(g,A)=>OWt(g,"name",{value:A,configurable:!0}),VWt=Gp[" useId ".trim().toString()]||(()=>{}),jWt=0;function aT(g){const[A,I]=gA.useState(VWt());return WM(()=>{g||I(e=>e??String(jWt++))},[g]),g||(A?`radix-${A}`:"")}WWt(aT,"useId");var zWt=["top","right","bottom","left"],E3=Math.min,eJ=Math.max,ByA=Math.round,oyA=Math.floor,tJ=g=>({x:g,y:g}),XWt={left:"right",right:"left",bottom:"top",top:"bottom"};function lmI(g,A,I){return eJ(g,E3(A,I))}function BJ(g,A){return typeof g=="function"?g(A):g}function n3(g){return g.split("-")[0]}function rT(g){return g.split("-")[1]}function yAg(g){return g==="x"?"y":"x"}function wAg(g){return g==="y"?"height":"width"}function hx(g){const A=g[0];return A==="t"||A==="b"?"y":"x"}function uAg(g){return yAg(hx(g))}function $Wt(g,A,I){I===void 0&&(I=!1);const e=rT(g),t=uAg(g),B=wAg(t);let o=t==="x"?e===(I?"end":"start")?"right":"left":e==="start"?"bottom":"top";return A.reference[B]>A.floating[B]&&(o=CyA(o)),[o,CyA(o)]}function AVt(g){const A=CyA(g);return[GAg(g),A,GAg(A)]}function GAg(g){return g.includes("start")?g.replace("start","end"):g.replace("end","start")}var DmI=["left","right"],dmI=["right","left"],gVt=["top","bottom"],IVt=["bottom","top"];function eVt(g,A,I){switch(g){case"top":case"bottom":return I?A?dmI:DmI:A?DmI:dmI;case"left":case"right":return A?gVt:IVt;default:return[]}}function tVt(g,A,I,e){const t=rT(g);let B=eVt(n3(g),I==="start",e);return t&&(B=B.map(o=>o+"-"+t),A&&(B=B.concat(B.map(GAg)))),B}function CyA(g){const A=n3(g);return XWt[A]+g.slice(A.length)}function BVt(g){var A,I,e,t;return{top:(A=g.top)!=null?A:0,right:(I=g.right)!=null?I:0,bottom:(e=g.bottom)!=null?e:0,left:(t=g.left)!=null?t:0}}function ymI(g){return typeof g!="number"?BVt(g):{top:g,right:g,bottom:g,left:g}}function QyA(g){const{x:A,y:I,width:e,height:t}=g;return{width:e,height:t,top:I,left:A,right:A+e,bottom:I+t,x:A,y:I}}function wmI(g,A,I){let{reference:e,floating:t}=g;const B=hx(A),o=uAg(A),C=wAg(o),Q=n3(A),i=B==="y",E=e.x+e.width/2-t.width/2,n=e.y+e.height/2-t.height/2,s=e[C]/2-t[C]/2;let r;switch(Q){case"top":r={x:E,y:e.y-t.height};break;case"bottom":r={x:E,y:e.y+e.height};break;case"right":r={x:e.x+e.width,y:n};break;case"left":r={x:e.x-t.width,y:n};break;default:r={x:e.x,y:e.y}}const a=rT(A);return a&&(r[o]+=s*(a==="end"?1:-1)*(I&&i?-1:1)),r}async function oVt(g,A){var I;A===void 0&&(A={});const{x:e,y:t,platform:B,rects:o,elements:C,strategy:Q}=g,{boundary:i="clippingAncestors",rootBoundary:E="viewport",elementContext:n="floating",altBoundary:s=!1,padding:r=0}=BJ(A,g),a=ymI(r),h=C[s?n==="floating"?"reference":"floating":n],l=QyA(await B.getClippingRect({element:(I=await(B.isElement==null?void 0:B.isElement(h)))==null||I?h:h.contextElement||await(B.getDocumentElement==null?void 0:B.getDocumentElement(C.floating)),boundary:i,rootBoundary:E,strategy:Q})),D=n==="floating"?{x:e,y:t,width:o.floating.width,height:o.floating.height}:o.reference,d=await(B.getOffsetParent==null?void 0:B.getOffsetParent(C.floating)),y=await(B.isElement==null?void 0:B.isElement(d))&&await(B.getScale==null?void 0:B.getScale(d))||{x:1,y:1},w=QyA(B.convertOffsetParentRelativeRectToViewportRelativeRect?await B.convertOffsetParentRelativeRectToViewportRelativeRect({elements:C,rect:D,offsetParent:d,strategy:Q}):D);return{top:(l.top-w.top+a.top)/y.y,bottom:(w.bottom-l.bottom+a.bottom)/y.y,left:(l.left-w.left+a.left)/y.x,right:(w.right-l.right+a.right)/y.x}}var CVt=50,QVt=async(g,A,I)=>{const{placement:e="bottom",strategy:t="absolute",middleware:B=[],platform:o}=I,C=o.detectOverflow?o:{...o,detectOverflow:oVt},Q=await(o.isRTL==null?void 0:o.isRTL(A));let i=await o.getElementRects({reference:g,floating:A,strategy:t}),{x:E,y:n}=wmI(i,e,Q),s=e,r=0;const a={};for(let c=0;c<B.length;c++){const h=B[c];if(!h)continue;const{name:l,fn:D}=h,{x:d,y,data:w,reset:u}=await D({x:E,y:n,initialPlacement:e,placement:s,strategy:t,middlewareData:a,rects:i,platform:C,elements:{reference:g,floating:A}});E=d??E,n=y??n,a[l]={...a[l],...w},u&&r<CVt&&(r++,typeof u=="object"&&(u.placement&&(s=u.placement),u.rects&&(i=u.rects===!0?await o.getElementRects({reference:g,floating:A,strategy:t}):u.rects),{x:E,y:n}=wmI(i,s,Q)),c=-1)}return{x:E,y:n,placement:s,strategy:t,middlewareData:a}},iVt=g=>({name:"arrow",options:g,async fn(A){const{x:I,y:e,placement:t,rects:B,platform:o,elements:C,middlewareData:Q}=A,{element:i,padding:E=0}=BJ(g,A)||{};if(i==null)return{};const n=ymI(E),s={x:I,y:e},r=uAg(t),a=wAg(r),c=await o.getDimensions(i),h=r==="y",l=h?"top":"left",D=h?"bottom":"right",d=h?"clientHeight":"clientWidth",y=B.reference[a]+B.reference[r]-s[r]-B.floating[a],w=s[r]-B.reference[r],u=await(o.getOffsetParent==null?void 0:o.getOffsetParent(i));let G=u?u[d]:0;(!G||!await(o.isElement==null?void 0:o.isElement(u)))&&(G=C.floating[d]||B.floating[a]);const m=y/2-w/2,p=G/2-c[a]/2-1,k=E3(n[l],p),S=E3(n[D],p),R=G-c[a]-S,F=G/2-c[a]/2+m,N=lmI(k,F,R),U=!Q.arrow&&rT(t)!=null&&F!==N&&B.reference[a]/2-(F<k?k:S)-c[a]/2<0,P=U?F<k?F-k:F-R:0;return{[r]:s[r]+P,data:{[r]:N,centerOffset:F-N-P,...U&&{alignmentOffset:P}},reset:U}}}),EVt=function(g){return g===void 0&&(g={}),{name:"flip",options:g,async fn(A){var I,e;const{placement:t,middlewareData:B,rects:o,initialPlacement:C,platform:Q,elements:i}=A,{mainAxis:E=!0,crossAxis:n=!0,fallbackPlacements:s,fallbackStrategy:r="bestFit",fallbackAxisSideDirection:a="none",flipAlignment:c=!0,...h}=BJ(g,A);if((I=B.arrow)!=null&&I.alignmentOffset)return{};const l=n3(t),D=hx(C),d=n3(C)===C,y=await(Q.isRTL==null?void 0:Q.isRTL(i.floating)),w=s||(d||!c?[CyA(C)]:AVt(C)),u=a!=="none";!s&&u&&w.push(...tVt(C,c,a,y));const G=[C,...w],m=await Q.detectOverflow(A,h),p=[];let k=((e=B.flip)==null?void 0:e.overflows)||[];if(E&&p.push(m[l]),n){const N=$Wt(t,o,y);p.push(m[N[0]],m[N[1]])}if(k=[...k,{placement:t,overflows:p}],!p.every(N=>N<=0)){var S,R;const N=(((S=B.flip)==null?void 0:S.index)||0)+1,U=G[N];if(U&&(!(n==="alignment"?D!==hx(U):!1)||k.every(H=>hx(H.placement)===D?H.overflows[0]>0:!0)))return{data:{index:N,overflows:k},reset:{placement:U}};let P=(R=k.filter(b=>b.overflows[0]<=0).sort((b,H)=>b.overflows[1]-H.overflows[1])[0])==null?void 0:R.placement;if(!P)switch(r){case"bestFit":{var F;const b=(F=k.filter(H=>{if(u){const q=hx(H.placement);return q===D||q==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(q=>q>0).reduce((q,j)=>q+j,0)]).sort((H,q)=>H[1]-q[1])[0])==null?void 0:F[0];b&&(P=b);break}case"initialPlacement":P=C;break}if(t!==P)return{reset:{placement:P}}}return{}}}};function umI(g,A){return{top:g.top-A.height,right:g.right-A.width,bottom:g.bottom-A.height,left:g.left-A.width}}function GmI(g){return zWt.some(A=>g[A]>=0)}var nVt=function(g){return g===void 0&&(g={}),{name:"hide",options:g,async fn(A){const{rects:I,platform:e}=A,{strategy:t="referenceHidden",...B}=BJ(g,A);switch(t){case"referenceHidden":{const o=await e.detectOverflow(A,{...B,elementContext:"reference"}),C=umI(o,I.reference);return{data:{referenceHiddenOffsets:C,referenceHidden:GmI(C)}}}case"escaped":{const o=await e.detectOverflow(A,{...B,altBoundary:!0}),C=umI(o,I.floating);return{data:{escapedOffsets:C,escaped:GmI(C)}}}default:return{}}}}},mmI=new Set(["left","top"]);async function sVt(g,A){const{placement:I,platform:e,elements:t}=g,B=await(e.isRTL==null?void 0:e.isRTL(t.floating)),o=n3(I),C=rT(I),Q=hx(I)==="y",i=mmI.has(o)?-1:1,E=B&&Q?-1:1,n=BJ(A,g);let{mainAxis:s,crossAxis:r,alignmentAxis:a}=typeof n=="number"?{mainAxis:n,crossAxis:0,alignmentAxis:null}:{mainAxis:n.mainAxis||0,crossAxis:n.crossAxis||0,alignmentAxis:n.alignmentAxis};return C&&typeof a=="number"&&(r=C==="end"?a*-1:a),Q?{x:r*E,y:s*i}:{x:s*i,y:r*E}}var aVt=function(g){return g===void 0&&(g=0),{name:"offset",options:g,async fn(A){var I,e;const{x:t,y:B,placement:o,middlewareData:C}=A,Q=await sVt(A,g);return o===((I=C.offset)==null?void 0:I.placement)&&(e=C.arrow)!=null&&e.alignmentOffset?{}:{x:t+Q.x,y:B+Q.y,data:{...Q,placement:o}}}}},rVt=function(g){return g===void 0&&(g={}),{name:"shift",options:g,async fn(A){const{x:I,y:e,placement:t,platform:B}=A,{mainAxis:o=!0,crossAxis:C=!1,limiter:Q={fn:D=>{let{x:d,y}=D;return{x:d,y}}},...i}=BJ(g,A),E={x:I,y:e},n=await B.detectOverflow(A,i),s=hx(t),r=yAg(s);let a=E[r],c=E[s];const h=(D,d)=>lmI(d+n[D==="y"?"top":"left"],d,d-n[D==="y"?"bottom":"right"]);o&&(a=h(r,a)),C&&(c=h(s,c));const l=Q.fn({...A,[r]:a,[s]:c});return{...l,data:{x:l.x-I,y:l.y-e,enabled:{[r]:o,[s]:C}}}}}},cVt=function(g){return g===void 0&&(g={}),{options:g,fn(A){var I,e;const{x:t,y:B,placement:o,rects:C,middlewareData:Q}=A,{offset:i=0,mainAxis:E=!0,crossAxis:n=!0}=BJ(g,A),s={x:t,y:B},r=hx(o),a=yAg(r);let c=s[a],h=s[r];const l=BJ(i,A),D=typeof l=="number"?{mainAxis:l,crossAxis:0}:{mainAxis:(I=l.mainAxis)!=null?I:0,crossAxis:(e=l.crossAxis)!=null?e:0};if(E){const w=a==="y"?"height":"width",u=C.reference[a]-C.floating[w]+D.mainAxis,G=C.reference[a]+C.reference[w]-D.mainAxis;c<u?c=u:c>G&&(c=G)}if(n){var d,y;const w=a==="y"?"width":"height",u=mmI.has(n3(o)),G=C.reference[r]-C.floating[w]+(u&&((d=Q.offset)==null?void 0:d[r])||0)+(u?0:D.crossAxis),m=C.reference[r]+C.reference[w]+(u?0:((y=Q.offset)==null?void 0:y[r])||0)-(u?D.crossAxis:0);h<G?h=G:h>m&&(h=m)}return{[a]:c,[r]:h}}}},hVt=function(g){return g===void 0&&(g={}),{name:"size",options:g,async fn(A){const{placement:I,rects:e,platform:t,elements:B}=A,{apply:o=()=>{},...C}=BJ(g,A),Q=await t.detectOverflow(A,C),i=n3(I),E=rT(I),n=hx(I)==="y",{width:s,height:r}=e.floating;let a,c;i==="top"||i==="bottom"?(a=i,c=E===(await(t.isRTL==null?void 0:t.isRTL(B.floating))?"start":"end")?"left":"right"):(c=i,a=E==="end"?"top":"bottom");const h=r-Q.top-Q.bottom,l=s-Q.left-Q.right,D=E3(r-Q[a],h),d=E3(s-Q[c],l),y=A.middlewareData.shift,w=!y;let u=D,G=d;y!=null&&y.enabled.x&&(G=l),y!=null&&y.enabled.y&&(u=h),w&&!E&&(n?G=s-2*eJ(Q.left,Q.right):u=r-2*eJ(Q.top,Q.bottom)),await o({...A,availableWidth:G,availableHeight:u});const m=await t.getDimensions(B.floating);return s!==m.width||r!==m.height?{reset:{rects:!0}}:{}}}};function iyA(){return typeof window<"u"}function cT(g){return pmI(g)?(g.nodeName||"").toLowerCase():"#document"}function ik(g){var A;return(g==null||(A=g.ownerDocument)==null?void 0:A.defaultView)||window}function oJ(g){var A;return(A=(pmI(g)?g.ownerDocument:g.document)||window.document)==null?void 0:A.documentElement}function pmI(g){return iyA()?g instanceof Node||g instanceof ik(g).Node:!1}function lx(g){return iyA()?g instanceof Element||g instanceof ik(g).Element:!1}function s3(g){return iyA()?g instanceof HTMLElement||g instanceof ik(g).HTMLElement:!1}function kmI(g){return!iyA()||typeof ShadowRoot>"u"?!1:g instanceof ShadowRoot||g instanceof ik(g).ShadowRoot}function EyA(g){const{overflow:A,overflowX:I,overflowY:e,display:t}=Dx(g);return/auto|scroll|overlay|hidden|clip/.test(A+e+I)&&t!=="inline"&&t!=="contents"}function lVt(g){return/^(table|td|th)$/.test(cT(g))}function nyA(g){try{if(g.matches(":popover-open"))return!0}catch{}try{return g.matches(":modal")}catch{return!1}}var DVt=/transform|translate|scale|rotate|perspective|filter/,dVt=/paint|layout|strict|content/,n5=g=>!!g&&g!=="none",mAg;function pAg(g){const A=lx(g)?Dx(g):g;return n5(A.transform)||n5(A.translate)||n5(A.scale)||n5(A.rotate)||n5(A.perspective)||!kAg()&&(n5(A.backdropFilter)||n5(A.filter))||DVt.test(A.willChange||"")||dVt.test(A.contain||"")}function yVt(g){let A=s5(g);for(;s3(A)&&!rIA(A);){if(pAg(A))return A;if(nyA(A))return null;A=s5(A)}return null}function kAg(){return mAg==null&&(mAg=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),mAg}function rIA(g){return/^(html|body|#document)$/.test(cT(g))}function Dx(g){return ik(g).getComputedStyle(g)}function syA(g){return lx(g)?{scrollLeft:g.scrollLeft,scrollTop:g.scrollTop}:{scrollLeft:g.scrollX,scrollTop:g.scrollY}}function s5(g){if(cT(g)==="html")return g;const A=g.assignedSlot||g.parentNode||kmI(g)&&g.host||oJ(g);return kmI(A)?A.host:A}function MmI(g){const A=s5(g);return rIA(A)?(g.ownerDocument||g).body:s3(A)&&EyA(A)?A:MmI(A)}function cIA(g,A,I){var e;A===void 0&&(A=[]),I===void 0&&(I=!0);const t=MmI(g),B=t===((e=g.ownerDocument)==null?void 0:e.body),o=ik(t);if(B){const C=MAg(o);return A.concat(o,o.visualViewport||[],EyA(t)?t:[],C&&I?cIA(C):[])}else return A.concat(t,cIA(t,[],I))}function MAg(g){return g.parent&&Object.getPrototypeOf(g.parent)?g.frameElement:null}function SmI(g){const A=Dx(g);let I=parseFloat(A.width)||0,e=parseFloat(A.height)||0;const t=s3(g),B=t?g.offsetWidth:I,o=t?g.offsetHeight:e,C=ByA(I)!==B||ByA(e)!==o;return C&&(I=B,e=o),{width:I,height:e,$:C}}function SAg(g){return lx(g)?g:g.contextElement}function hT(g){const A=SAg(g);if(!s3(A))return tJ(1);const I=A.getBoundingClientRect(),{width:e,height:t,$:B}=SmI(A);let o=(B?ByA(I.width):I.width)/e,C=(B?ByA(I.height):I.height)/t;return(!o||!Number.isFinite(o))&&(o=1),(!C||!Number.isFinite(C))&&(C=1),{x:o,y:C}}var wVt=tJ(0);function fmI(g){const A=ik(g);return!kAg()||!A.visualViewport?wVt:{x:A.visualViewport.offsetLeft,y:A.visualViewport.offsetTop}}function uVt(g,A,I){return A===void 0&&(A=!1),!!I&&A&&I===ik(g)}function a5(g,A,I,e){A===void 0&&(A=!1),I===void 0&&(I=!1);const t=g.getBoundingClientRect(),B=SAg(g);let o=tJ(1);A&&(e?lx(e)&&(o=hT(e)):o=hT(g));const C=uVt(B,I,e)?fmI(B):tJ(0);let Q=(t.left+C.x)/o.x,i=(t.top+C.y)/o.y,E=t.width/o.x,n=t.height/o.y;if(B&&e){const s=ik(B),r=lx(e)?ik(e):e;let a=s,c=MAg(a);for(;c&&r!==a;){const h=hT(c),l=c.getBoundingClientRect(),D=Dx(c),d=l.left+(c.clientLeft+parseFloat(D.paddingLeft))*h.x,y=l.top+(c.clientTop+parseFloat(D.paddingTop))*h.y;Q*=h.x,i*=h.y,E*=h.x,n*=h.y,Q+=d,i+=y,a=ik(c),c=MAg(a)}}return QyA({width:E,height:n,x:Q,y:i})}function ayA(g,A){const I=syA(g).scrollLeft;return A?A.left+I:a5(oJ(g)).left+I}function RmI(g,A){const I=g.getBoundingClientRect(),e=I.left+A.scrollLeft-ayA(g,I),t=I.top+A.scrollTop;return{x:e,y:t}}function GVt(g){let{elements:A,rect:I,offsetParent:e,strategy:t}=g;const B=t==="fixed",o=oJ(e),C=A?nyA(A.floating):!1;if(e===o||C&&B)return I;let Q={scrollLeft:0,scrollTop:0},i=tJ(1);const E=tJ(0),n=s3(e);if((n||!B)&&((cT(e)!=="body"||EyA(o))&&(Q=syA(e)),n)){const r=a5(e);i=hT(e),E.x=r.x+e.clientLeft,E.y=r.y+e.clientTop}const s=o&&!n&&!B?RmI(o,Q):tJ(0);return{width:I.width*i.x,height:I.height*i.y,x:I.x*i.x-Q.scrollLeft*i.x+E.x+s.x,y:I.y*i.y-Q.scrollTop*i.y+E.y+s.y}}function mVt(g){return g.getClientRects?Array.from(g.getClientRects()):[]}function pVt(g){const A=syA(g),I=g.ownerDocument.body,e=eJ(g.scrollWidth,g.clientWidth,I.scrollWidth,I.clientWidth),t=eJ(g.scrollHeight,g.clientHeight,I.scrollHeight,I.clientHeight);let B=-A.scrollLeft+ayA(g);const o=-A.scrollTop;return Dx(I).direction==="rtl"&&(B+=eJ(g.clientWidth,I.clientWidth)-e),{width:e,height:t,x:B,y:o}}var kVt=25;function MVt(g,A,I){I===void 0&&(I="viewport");const e=I==="layoutViewport",t=ik(g),B=oJ(g),o=t.visualViewport;let C=B.clientWidth,Q=B.clientHeight,i=0,E=0;if(o){const s=!kAg()||A==="fixed";e?s||(i=-o.offsetLeft,E=-o.offsetTop):(C=o.width,Q=o.height,s&&(i=o.offsetLeft,E=o.offsetTop))}if(ayA(B)<=0){const s=B.ownerDocument,r=s.body,a=getComputedStyle(r),c=s.compatMode==="CSS1Compat"&&parseFloat(a.marginLeft)+parseFloat(a.marginRight)||0,h=Math.abs(B.clientWidth-r.clientWidth-c),l=getComputedStyle(B).scrollbarGutter==="stable both-edges"?h/2:h;l<=kVt&&(C-=l)}return{width:C,height:Q,x:i,y:E}}function SVt(g,A){const I=a5(g,!0,A==="fixed"),e=I.top+g.clientTop,t=I.left+g.clientLeft,B=hT(g),o=g.clientWidth*B.x,C=g.clientHeight*B.y,Q=t*B.x,i=e*B.y;return{width:o,height:C,x:Q,y:i}}function NmI(g,A,I){let e;if(A==="viewport"||A==="layoutViewport")e=MVt(g,I,A);else if(A==="document")e=pVt(oJ(g));else if(lx(A))e=SVt(A,I);else{const t=fmI(g);e={x:A.x-t.x,y:A.y-t.y,width:A.width,height:A.height}}return QyA(e)}function fVt(g,A){const I=A.get(g);if(I)return I;let e=cIA(g,[],!1).filter(C=>lx(C)&&cT(C)!=="body"),t=null;const B=Dx(g).position==="fixed";let o=B?s5(g):g;for(;lx(o)&&!rIA(o);){const C=Dx(o),Q=pAg(o),i=t?t.position:B?"fixed":"";!Q&&(i==="fixed"||i==="absolute"&&C.position==="static")?e=e.filter(n=>n!==o):t=C,o=s5(o)}return A.set(g,e),e}function RVt(g){let{element:A,boundary:I,rootBoundary:e,strategy:t}=g;const o=[...I==="clippingAncestors"?nyA(A)?[]:fVt(A,this._c):[].concat(I),e],C=NmI(A,o[0],t);let Q=C.top,i=C.right,E=C.bottom,n=C.left;for(let s=1;s<o.length;s++){const r=NmI(A,o[s],t);Q=eJ(r.top,Q),i=E3(r.right,i),E=E3(r.bottom,E),n=eJ(r.left,n)}return{width:i-n,height:E-Q,x:n,y:Q}}function NVt(g){const{width:A,height:I}=SmI(g);return{width:A,height:I}}function xVt(g,A,I){const e=s3(A),t=oJ(A),B=I==="fixed",o=a5(g,!0,B,A);let C={scrollLeft:0,scrollTop:0};const Q=tJ(0);if((e||!B)&&((cT(A)!=="body"||EyA(t))&&(C=syA(A)),e)){const s=a5(A,!0,B,A);Q.x=s.x+A.clientLeft,Q.y=s.y+A.clientTop}!e&&t&&(Q.x=ayA(t));const i=t&&!e&&!B?RmI(t,C):tJ(0),E=o.left+C.scrollLeft-Q.x-i.x,n=o.top+C.scrollTop-Q.y-i.y;return{x:E,y:n,width:o.width,height:o.height}}function fAg(g){return Dx(g).position==="static"}function xmI(g,A){if(!s3(g)||Dx(g).position==="fixed")return null;if(A)return A(g);let I=g.offsetParent;return oJ(g)===I&&(I=I.ownerDocument.body),I}function FmI(g,A){const I=ik(g);if(nyA(g))return I;if(!s3(g)){let t=s5(g);for(;t&&!rIA(t);){if(lx(t)&&!fAg(t))return t;t=s5(t)}return I}let e=xmI(g,A);for(;e&&lVt(e)&&fAg(e);)e=xmI(e,A);return e&&rIA(e)&&fAg(e)&&!pAg(e)?I:e||yVt(g)||I}var FVt=async function(g){const A=this.getOffsetParent||FmI,I=this.getDimensions,e=await I(g.floating);return{reference:xVt(g.reference,await A(g.floating),g.strategy),floating:{x:0,y:0,width:e.width,height:e.height}}};function UVt(g){return Dx(g).direction==="rtl"}var JVt={convertOffsetParentRelativeRectToViewportRelativeRect:GVt,getDocumentElement:oJ,getClippingRect:RVt,getOffsetParent:FmI,getElementRects:FVt,getClientRects:mVt,getDimensions:NVt,getScale:hT,isElement:lx,isRTL:UVt};function UmI(g,A){return g.x===A.x&&g.y===A.y&&g.width===A.width&&g.height===A.height}function KVt(g,A,I){let e=null,t;const B=oJ(g);function o(){var E;clearTimeout(t),(E=e)==null||E.disconnect(),e=null}function C(E,n){E===void 0&&(E=!1),n===void 0&&(n=1),o();const s=g.getBoundingClientRect(),{left:r,top:a,width:c,height:h}=s;if(E||A(),!c||!h)return;const l=oyA(a),D=oyA(B.clientWidth-(r+c)),d=oyA(B.clientHeight-(a+h)),y=oyA(r),u={rootMargin:-l+"px "+-D+"px "+-d+"px "+-y+"px",threshold:eJ(0,E3(1,n))||1};let G=!0;function m(p){const k=p[0].intersectionRatio;if(!UmI(s,g.getBoundingClientRect()))return C();if(k!==n){if(!G)return C();k?C(!1,k):t=setTimeout(()=>{C(!1,1e-7)},1e3)}G=!1}try{e=new IntersectionObserver(m,{...u,root:B.ownerDocument})}catch{e=new IntersectionObserver(m,u)}e.observe(g)}const Q=ik(g),i=()=>C(I);return Q.addEventListener("resize",i),C(!0),()=>{Q.removeEventListener("resize",i),o()}}function PVt(g,A,I,e){e===void 0&&(e={});const{ancestorScroll:t=!0,ancestorResize:B=!0,elementResize:o=typeof ResizeObserver=="function",layoutShift:C=typeof IntersectionObserver=="function",animationFrame:Q=!1}=e,i=SAg(g),E=t||B?[...i?cIA(i):[],...A?cIA(A):[]]:[];E.forEach(l=>{t&&l.addEventListener("scroll",I),B&&l.addEventListener("resize",I)});const n=i&&C?KVt(i,I,B):null;let s=-1,r=null;o&&(r=new ResizeObserver(l=>{let[D]=l;D&&D.target===i&&r&&A&&(r.unobserve(A),cancelAnimationFrame(s),s=requestAnimationFrame(()=>{var d;(d=r)==null||d.observe(A)})),I()}),i&&!Q&&r.observe(i),A&&r.observe(A));let a,c=Q?a5(g):null;Q&&h();function h(){const l=a5(g);c&&!UmI(c,l)&&I(),c=l,a=requestAnimationFrame(h)}return I(),()=>{var l;E.forEach(D=>{t&&D.removeEventListener("scroll",I),B&&D.removeEventListener("resize",I)}),n?.(),(l=r)==null||l.disconnect(),r=null,Q&&cancelAnimationFrame(a)}}var LVt=aVt,YVt=rVt,_Vt=EVt,bVt=hVt,HVt=nVt,JmI=iVt,vVt=cVt,qVt=(g,A,I)=>{const e=new Map,t=I??{},B={...JVt,...t.platform,_c:e};return QVt(g,A,{...t,platform:B})},TVt=typeof document<"u",ZVt=function(){},ryA=TVt?gA.useLayoutEffect:ZVt;function cyA(g,A){if(g===A)return!0;if(typeof g!=typeof A)return!1;if(typeof g=="function"&&g.toString()===A.toString())return!0;let I,e,t;if(g&&A&&typeof g=="object"){if(Array.isArray(g)){if(I=g.length,I!==A.length)return!1;for(e=I;e--!==0;)if(!cyA(g[e],A[e]))return!1;return!0}if(t=Object.keys(g),I=t.length,I!==Object.keys(A).length)return!1;for(e=I;e--!==0;)if(!{}.hasOwnProperty.call(A,t[e]))return!1;for(e=I;e--!==0;){const B=t[e];if(!(B==="_owner"&&g.$$typeof)&&!cyA(g[B],A[B]))return!1}return!0}return g!==g&&A!==A}function KmI(g){return typeof window>"u"?1:(g.ownerDocument.defaultView||window).devicePixelRatio||1}function PmI(g,A){const I=KmI(g);return Math.round(A*I)/I}function RAg(g){const A=gA.useRef(g);return ryA(()=>{A.current=g}),A}function OVt(g){g===void 0&&(g={});const{placement:A="bottom",strategy:I="absolute",middleware:e=[],platform:t,elements:{reference:B,floating:o}={},transform:C=!0,whileElementsMounted:Q,open:i}=g,[E,n]=gA.useState({x:0,y:0,strategy:I,placement:A,middlewareData:{},isPositioned:!1}),[s,r]=gA.useState(e);cyA(s,e)||r(e);const[a,c]=gA.useState(null),[h,l]=gA.useState(null),D=gA.useCallback(H=>{H!==u.current&&(u.current=H,c(H))},[]),d=gA.useCallback(H=>{H!==G.current&&(G.current=H,l(H))},[]),y=B||a,w=o||h,u=gA.useRef(null),G=gA.useRef(null),m=gA.useRef(E),p=Q!=null,k=RAg(Q),S=RAg(t),R=RAg(i),F=gA.useCallback(()=>{if(!u.current||!G.current)return;const H={placement:A,strategy:I,middleware:s};S.current&&(H.platform=S.current),qVt(u.current,G.current,H).then(q=>{const j={...q,isPositioned:R.current!==!1};N.current&&!cyA(m.current,j)&&(m.current=j,CN.flushSync(()=>{n(j)}))})},[s,A,I,S,R]);ryA(()=>{i===!1&&m.current.isPositioned&&(m.current.isPositioned=!1,n(H=>({...H,isPositioned:!1})))},[i]);const N=gA.useRef(!1);ryA(()=>(N.current=!0,()=>{N.current=!1}),[]),ryA(()=>{if(y&&(u.current=y),w&&(G.current=w),y&&w){if(k.current)return k.current(y,w,F);F()}},[y,w,F,k,p]);const U=gA.useMemo(()=>({reference:u,floating:G,setReference:D,setFloating:d}),[D,d]),P=gA.useMemo(()=>({reference:y,floating:w}),[y,w]),b=gA.useMemo(()=>{const H={position:I,left:0,top:0};if(!P.floating)return H;const q=PmI(P.floating,E.x),j=PmI(P.floating,E.y);return C?{...H,transform:"translate("+q+"px, "+j+"px)",...KmI(P.floating)>=1.5&&{willChange:"transform"}}:{position:I,left:q,top:j}},[I,C,P.floating,E.x,E.y]);return gA.useMemo(()=>({...E,update:F,refs:U,elements:P,floatingStyles:b}),[E,F,U,P,b])}var WVt=g=>{function A(I){return{}.hasOwnProperty.call(I,"current")}return{name:"arrow",options:g,fn(I){const{element:e,padding:t}=typeof g=="function"?g(I):g;return e&&A(e)?e.current!=null?JmI({element:e.current,padding:t}).fn(I):{}:e?JmI({element:e,padding:t}).fn(I):{}}}},VVt=(g,A)=>{const I=LVt(g);return{name:I.name,fn:I.fn,options:[g,A]}},jVt=(g,A)=>{const I=YVt(g);return{name:I.name,fn:I.fn,options:[g,A]}},zVt=(g,A)=>({fn:vVt(g).fn,options:[g,A]}),XVt=(g,A)=>{const I=_Vt(g);return{name:I.name,fn:I.fn,options:[g,A]}},$Vt=(g,A)=>{const I=bVt(g);return{name:I.name,fn:I.fn,options:[g,A]}},Ajt=(g,A)=>{const I=HVt(g);return{name:I.name,fn:I.fn,options:[g,A]}},gjt=(g,A)=>{const I=WVt(g);return{name:I.name,fn:I.fn,options:[g,A]}},Ijt=Object.defineProperty,ejt=(g,A)=>Ijt(g,"name",{value:A,configurable:!0});function LmI(g){const[A,I]=gA.useState(void 0);return WM(()=>{if(g){I({width:g.offsetWidth,height:g.offsetHeight});let e=0;const t=new ResizeObserver(B=>{if(!Array.isArray(B)||!B.length)return;const o=B[0];window.cancelAnimationFrame(e),e=window.requestAnimationFrame(()=>{let C,Q;if("borderBoxSize"in o){const i=o.borderBoxSize,E=Array.isArray(i)?i[0]:i;C=E.inlineSize,Q=E.blockSize}else C=g.offsetWidth,Q=g.offsetHeight;I({width:C,height:Q})})});return t.observe(g,{box:"border-box"}),()=>{window.cancelAnimationFrame(e),t.unobserve(g)}}else I(void 0)},[g]),A}ejt(LmI,"useSize");var tjt=Object.defineProperty,a3=(g,A)=>tjt(g,"name",{value:A,configurable:!0}),YmI={Partial:"partial"},_mI={Optimized:"optimized",Always:"always"},bmI="Popper",[HmI,vmI]=i5(bmI),[Bjt,qmI]=HmI(bmI),TmI=a3(g=>{const{__scopePopper:A,children:I}=g,[e,t]=gA.useState(null),[B,o]=gA.useState(void 0);return W.jsx(Bjt,{scope:A,anchor:e,onAnchorChange:t,placementState:B,setPlacementState:o,children:I})},"Popper"),ojt="PopperAnchor",Cjt=gA.forwardRef(a3(function(A,I){const{__scopePopper:e,virtualRef:t,...B}=A,o=qmI(ojt,e),C=gA.useRef(null),Q=o.onAnchorChange,i=gA.useCallback(c=>{C.current=c,c&&Q(c)},[Q]),E=Rd(I,i),n=gA.useRef(null);gA.useEffect(()=>{if(!t)return;const c=n.current;n.current=t.current,c!==n.current&&Q(n.current)});const s=o.placementState&&hyA(o.placementState),r=s?.[0],a=s?.[1];return t?null:W.jsx(rx.div,{"data-radix-popper-side":r,"data-radix-popper-align":a,...B,ref:E})},"PopperAnchor")),ZmI="PopperContent",[Qjt,iWB]=HmI(ZmI),ijt=gA.forwardRef(a3(function(A,I){const{__scopePopper:e,side:t="bottom",sideOffset:B=0,align:o="center",alignOffset:C=0,arrowPadding:Q=0,avoidCollisions:i=!0,collisionBoundary:E=[],collisionPadding:n=0,sticky:s=YmI.Partial,hideWhenDetached:r=!1,updatePositionStrategy:a=_mI.Optimized,onPlaced:c,...h}=A,l=qmI(ZmI,e),[D,d]=gA.useState(null),y=Rd(I,d),[w,u]=gA.useState(null),G=LmI(w),m=G?.width??0,p=G?.height??0,k=t+(o!=="center"?"-"+o:""),S=typeof n=="number"?n:{top:0,right:0,bottom:0,left:0,...n},R=Array.isArray(E)?E:[E],F=R.length>0,N={padding:S,boundary:R.filter(OmI),altBoundary:F},{refs:U,floatingStyles:P,placement:b,isPositioned:H,middlewareData:q}=OVt({strategy:"fixed",placement:k,whileElementsMounted:a3((...CA)=>PVt(...CA,{animationFrame:a===_mI.Always}),"whileElementsMounted"),elements:{reference:l.anchor},middleware:[VVt({mainAxis:B+p,alignmentAxis:C}),i&&jVt({mainAxis:!0,crossAxis:!1,...s===YmI.Partial?{limiter:zVt()}:{},...N}),i&&XVt({...N}),$Vt({...N,apply:a3(({elements:CA,rects:cA,availableWidth:nA,availableHeight:hA})=>{const{width:fA,height:NA}=cA.reference,aA=CA.floating.style;aA.setProperty("--radix-popper-available-width",`${nA}px`),aA.setProperty("--radix-popper-available-height",`${hA}px`),aA.setProperty("--radix-popper-anchor-width",`${fA}px`),aA.setProperty("--radix-popper-anchor-height",`${NA}px`)},"apply")}),w&&gjt({element:w,padding:Q}),Ejt({arrowWidth:m,arrowHeight:p}),r&&Ajt(F?{strategy:"referenceHidden",...N}:{strategy:"referenceHidden",padding:N.padding,altBoundary:N.altBoundary})]}),j=l.setPlacementState;WM(()=>(j(b),()=>{j(void 0)}),[b,j]);const[Z,O]=hyA(b),AA=cx(c);WM(()=>{H&&AA?.()},[H,AA]);const tA=q.arrow?.x,eA=q.arrow?.y,iA=q.arrow?.centerOffset!==0,[sA,DA]=gA.useState();return WM(()=>{D&&DA(window.getComputedStyle(D).zIndex)},[D]),W.jsx("div",{ref:U.setFloating,"data-radix-popper-content-wrapper":"",style:{...P,transform:H?P.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:sA,"--radix-popper-transform-origin":[q.transformOrigin?.x,q.transformOrigin?.y].join(" "),...q.hide?.referenceHidden&&{visibility:"hidden",pointerEvents:"none"}},dir:A.dir,children:W.jsx(Qjt,{scope:e,placedSide:Z,placedAlign:O,onArrowChange:u,arrowX:tA,arrowY:eA,shouldHideArrow:iA,children:W.jsx(rx.div,{"data-side":Z,"data-align":O,...h,ref:y,style:{...h.style,animation:H?h.style?.animation:"none"}})})})},"PopperContent"));function OmI(g){return g!==null}a3(OmI,"isNotNull");var Ejt=a3(g=>({name:"transformOrigin",options:g,fn(A){const{placement:I,rects:e,middlewareData:t}=A,o=t.arrow?.centerOffset!==0,C=o?0:g.arrowWidth,Q=o?0:g.arrowHeight,[i,E]=hyA(I),n={start:"0%",center:"50%",end:"100%"}[E],s=(t.arrow?.x??0)+C/2,r=(t.arrow?.y??0)+Q/2;let a="",c="";return i==="bottom"?(a=o?n:`${s}px`,c=`${-Q}px`):i==="top"?(a=o?n:`${s}px`,c=`${e.floating.height+Q}px`):i==="right"?(a=`${-Q}px`,c=o?n:`${r}px`):i==="left"&&(a=`${e.floating.width+Q}px`,c=o?n:`${r}px`),{data:{x:a,y:c}}}}),"transformOrigin");function hyA(g){const[A,I="center"]=g.split("-");return[A,I]}a3(hyA,"getSideAndAlignFromPlacement");var njt=Object.defineProperty,sjt=(g,A)=>njt(g,"name",{value:A,configurable:!0}),ajt=gA.forwardRef(sjt(function(A,I){const{container:e,...t}=A,[B,o]=gA.useState(!1);WM(()=>o(!0),[]);const C=e||B&&globalThis?.document?.body;return C?CN.createPortal(W.jsx(rx.div,{...t,ref:I}),C):null},"Portal")),rjt=Object.defineProperty,CJ=(g,A)=>rjt(g,"name",{value:A,configurable:!0});function WmI(g,A){return gA.useReducer((I,e)=>A[I][e]??I,g)}CJ(WmI,"useStateMachine");var NAg=CJ(g=>{const{present:A,children:I}=g,e=VmI(A),t=typeof I=="function"?I({present:e.isPresent}):gA.Children.only(I),B=jmI(e.ref,zmI(t));return typeof I=="function"||e.isPresent?gA.cloneElement(t,{ref:B}):null},"Presence");function VmI(g){const[A,I]=gA.useState(),e=gA.useRef(null),t=gA.useRef(g),B=gA.useRef("none"),o=gA.useRef(void 0),C=g?"mounted":"unmounted",[Q,i]=WmI(C,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return gA.useEffect(()=>{Q==="mounted"?(B.current=o.current??lT(e.current),o.current=void 0):B.current="none"},[Q]),WM(()=>{const E=e.current,n=t.current;if(n!==g){const r=B.current,a=lT(E);g?(o.current=a,i("MOUNT")):a==="none"||E?.display==="none"?i("UNMOUNT"):i(n&&r!==a?"ANIMATION_OUT":"UNMOUNT"),t.current=g}},[g,i]),WM(()=>{if(A){let E;const n=A.ownerDocument.defaultView??window,s=CJ(a=>{const h=lT(e.current).includes(CSS.escape(a.animationName));if(a.target===A&&h&&(i("ANIMATION_END"),!t.current)){const l=A.style.animationFillMode;A.style.animationFillMode="forwards",E=n.setTimeout(()=>{A.style.animationFillMode==="forwards"&&(A.style.animationFillMode=l)})}},"handleAnimationEnd"),r=CJ(a=>{a.target===A&&(B.current=lT(e.current))},"handleAnimationStart");return A.addEventListener("animationstart",r),A.addEventListener("animationcancel",s),A.addEventListener("animationend",s),()=>{n.clearTimeout(E),A.removeEventListener("animationstart",r),A.removeEventListener("animationcancel",s),A.removeEventListener("animationend",s)}}else i("ANIMATION_END")},[A,i]),{isPresent:["mounted","unmountSuspended"].includes(Q),ref:gA.useCallback(E=>{if(E){const n=getComputedStyle(E);e.current=n,o.current=lT(n)}else e.current=null;I(E)},[])}}CJ(VmI,"usePresence");function xAg(g,A){if(typeof g=="function")return g(A);g!=null&&(g.current=A)}CJ(xAg,"setRef");function jmI(...g){const A=gA.useRef(g);return A.current=g,gA.useCallback(I=>{const e=A.current;let t=!1;const B=e.map(o=>{const C=xAg(o,I);return!t&&typeof C=="function"&&(t=!0),C});if(t)return()=>{for(let o=0;o<B.length;o++){const C=B[o];typeof C=="function"?C():xAg(e[o],null)}}},[])}CJ(jmI,"useStableComposedRefs");function lT(g){return g?.animationName||"none"}CJ(lT,"getAnimationName");function zmI(g){let A=Object.getOwnPropertyDescriptor(g.props,"ref")?.get,I=A&&"isReactWarning"in A&&A.isReactWarning;return I?g.ref:(A=Object.getOwnPropertyDescriptor(g,"ref")?.get,I=A&&"isReactWarning"in A&&A.isReactWarning,I?g.props.ref:g.props.ref||g.ref)}CJ(zmI,"getElementRef");var cjt=Object.defineProperty,FAg=(g,A)=>cjt(g,"name",{value:A,configurable:!0}),UAg=!1;function XmI(){const[g,A]=gA.useState(UAg);return gA.useEffect(()=>{UAg||(UAg=!0,A(!0))},[]),g}FAg(XmI,"useIsHydrated");var $mI=Gp[" useSyncExternalStore ".trim().toString()];function ApI(){return()=>{}}FAg(ApI,"subscribe");function gpI(){return $mI(ApI,()=>!0,()=>!1)}FAg(gpI,"useIsHydratedModern");var hjt=typeof $mI=="function"?gpI:XmI,ljt=Object.defineProperty,r5=(g,A)=>ljt(g,"name",{value:A,configurable:!0}),JAg="rovingFocusGroup.onEntryFocus",Djt={bubbles:!1,cancelable:!0},lyA="RovingFocusGroup",[KAg,IpI,djt]=oAg(lyA),[yjt,epI]=i5(lyA,[djt]),tpI={Vertical:"vertical",Horizontal:"horizontal"},wjt={RTL:"rtl"},[ujt,Gjt]=yjt(lyA),mjt=gA.forwardRef(r5(function(A,I){return W.jsx(KAg.Provider,{scope:A.__scopeRovingFocusGroup,children:W.jsx(KAg.Slot,{scope:A.__scopeRovingFocusGroup,children:W.jsx(pjt,{...A,ref:I})})})},"RovingFocusGroup")),pjt=gA.forwardRef(r5(function(A,I){const{__scopeRovingFocusGroup:e,orientation:t,loop:B=!1,dir:o,currentTabStopId:C,defaultCurrentTabStopId:Q,onCurrentTabStopIdChange:i,onEntryFocus:E,preventScrollOnEntryFocus:n=!1,...s}=A,r=gA.useRef(null),a=Rd(I,r),c=QAg(o),[h,l]=$dA({prop:C,defaultProp:Q??null,onChange:i,caller:lyA}),[D,d]=gA.useState(!1),y=cx(E),w=IpI(e),u=gA.useRef(!1),[G,m]=gA.useState(0);return gA.useEffect(()=>{const p=r.current;if(p)return p.addEventListener(JAg,y),()=>p.removeEventListener(JAg,y)},[y]),W.jsx(ujt,{scope:e,orientation:t,dir:c,loop:B,currentTabStopId:h,onItemFocus:gA.useCallback(p=>l(p),[l]),onItemShiftTab:gA.useCallback(()=>d(!0),[]),onFocusableItemAdd:gA.useCallback(()=>m(p=>p+1),[]),onFocusableItemRemove:gA.useCallback(()=>m(p=>p-1),[]),children:W.jsx(rx.div,{tabIndex:D||G===0?-1:0,"data-orientation":t,...s,ref:a,style:{outline:"none",...A.style},onMouseDown:un(A.onMouseDown,()=>{u.current=!0}),onFocus:un(A.onFocus,p=>{const k=!u.current;if(p.target===p.currentTarget&&k&&!D){const S=new CustomEvent(JAg,Djt);if(p.currentTarget.dispatchEvent(S),!S.defaultPrevented){const R=w().filter(b=>b.focusable),F=R.find(b=>b.active),N=R.find(b=>b.id===h),P=[F,N,...R].filter(Boolean).map(b=>b.ref.current);PAg(P,n)}}u.current=!1}),onBlur:un(A.onBlur,()=>d(!1))})})},"RovingFocusGroupImpl")),kjt="RovingFocusGroupItem",Mjt=gA.forwardRef(r5(function(A,I){const{__scopeRovingFocusGroup:e,focusable:t=!0,active:B=!1,tabStopId:o,children:C,...Q}=A,i=aT(),E=o||i,n=Gjt(kjt,e),s=n.currentTabStopId===E,r=IpI(e),{onFocusableItemAdd:a,onFocusableItemRemove:c,currentTabStopId:h}=n,l=hjt();return WM(()=>{if(!(!l||!t))return a(),()=>c()},[l,t,a,c]),gA.useEffect(()=>{if(!(l||!t))return a(),()=>c()},[l,t,a,c]),W.jsx(KAg.ItemSlot,{scope:e,id:E,focusable:t,active:B,children:W.jsx(rx.span,{tabIndex:s?0:-1,"data-orientation":n.orientation,...Q,ref:I,onMouseDown:un(A.onMouseDown,D=>{t?n.onItemFocus(E):D.preventDefault()}),onFocus:un(A.onFocus,()=>n.onItemFocus(E)),onKeyDown:un(A.onKeyDown,D=>{if(D.key==="Tab"&&D.shiftKey){n.onItemShiftTab();return}if(D.target!==D.currentTarget)return;const d=opI(D,n.orientation,n.dir);if(d!==void 0){if(D.metaKey||D.ctrlKey||D.altKey||D.shiftKey)return;D.preventDefault();let w=r().filter(u=>u.focusable).map(u=>u.ref.current);if(d==="last")w.reverse();else if(d==="prev"||d==="next"){d==="prev"&&w.reverse();const u=w.indexOf(D.currentTarget);w=n.loop?CpI(w,u+1):w.slice(u+1)}setTimeout(()=>PAg(w))}}),children:typeof C=="function"?C({isCurrentTabStop:s,hasTabStop:h!=null}):C})})},"RovingFocusGroupItem")),Sjt={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function BpI(g,A){return A!==wjt.RTL?g:g==="ArrowLeft"?"ArrowRight":g==="ArrowRight"?"ArrowLeft":g}r5(BpI,"getDirectionAwareKey");function opI(g,A,I){const e=BpI(g.key,I);if(!(A===tpI.Vertical&&["ArrowLeft","ArrowRight"].includes(e))&&!(A===tpI.Horizontal&&["ArrowUp","ArrowDown"].includes(e)))return Sjt[e]}r5(opI,"getFocusIntent");function PAg(g,A=!1){const I=document.activeElement;for(const e of g)if(e===I||(e.focus({preventScroll:A}),document.activeElement!==I))return}r5(PAg,"focusFirst");function CpI(g,A){return g.map((I,e)=>g[(A+e)%g.length])}r5(CpI,"wrapArray");var fjt=function(g){if(typeof document>"u")return null;var A=Array.isArray(g)?g[0]:g;return A.ownerDocument.body},DT=new WeakMap,DyA=new WeakMap,dyA={},LAg=0,QpI=function(g){return g&&(g.host||QpI(g.parentNode))},Rjt=function(g,A){return A.map(function(I){if(g.contains(I))return I;var e=QpI(I);return e&&g.contains(e)?e:(console.error("aria-hidden",I,"in not contained inside",g,". Doing nothing"),null)}).filter(function(I){return!!I})},Njt=function(g,A,I,e){var t=Rjt(A,Array.isArray(g)?g:[g]);dyA[I]||(dyA[I]=new WeakMap);var B=dyA[I],o=[],C=new Set,Q=new Set(t),i=function(n){!n||C.has(n)||(C.add(n),i(n.parentNode))};t.forEach(i);var E=function(n){!n||Q.has(n)||Array.prototype.forEach.call(n.children,function(s){if(C.has(s))E(s);else try{var r=s.getAttribute(e),a=r!==null&&r!=="false",c=(DT.get(s)||0)+1,h=(B.get(s)||0)+1;DT.set(s,c),B.set(s,h),o.push(s),c===1&&a&&DyA.set(s,!0),h===1&&s.setAttribute(I,"true"),a||s.setAttribute(e,"true")}catch(l){console.error("aria-hidden: cannot operate on ",s,l)}})};return E(A),C.clear(),LAg++,function(){o.forEach(function(n){var s=DT.get(n)-1,r=B.get(n)-1;DT.set(n,s),B.set(n,r),s||(DyA.has(n)||n.removeAttribute(e),DyA.delete(n)),r||n.removeAttribute(I)}),LAg--,LAg||(DT=new WeakMap,DT=new WeakMap,DyA=new WeakMap,dyA={})}},xjt=function(g,A,I){I===void 0&&(I="data-aria-hidden");var e=Array.from(Array.isArray(g)?g:[g]),t=fjt(g);return t?(e.push.apply(e,Array.from(t.querySelectorAll("[aria-live], script"))),Njt(e,t,I,"aria-hidden")):function(){return null}},dx=function(){return dx=Object.assign||function(A){for(var I,e=1,t=arguments.length;e<t;e++){I=arguments[e];for(var B in I)Object.prototype.hasOwnProperty.call(I,B)&&(A[B]=I[B])}return A},dx.apply(this,arguments)};function ipI(g,A){var I={};for(var e in g)Object.prototype.hasOwnProperty.call(g,e)&&A.indexOf(e)<0&&(I[e]=g[e]);if(g!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(g);t<e.length;t++)A.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(g,e[t])&&(I[e[t]]=g[e[t]]);return I}function Fjt(g,A,I){for(var e=0,t=A.length,B;e<t;e++)(B||!(e in A))&&(B||(B=Array.prototype.slice.call(A,0,e)),B[e]=A[e]);return g.concat(B||Array.prototype.slice.call(A))}var yyA="right-scroll-bar-position",wyA="width-before-scroll-bar",Ujt="with-scroll-bars-hidden",Jjt="--removed-body-scroll-bar-size";function YAg(g,A){return typeof g=="function"?g(A):g&&(g.current=A),g}function Kjt(g,A){var I=gA.useState(function(){return{value:g,callback:A,facade:{get current(){return I.value},set current(e){var t=I.value;t!==e&&(I.value=e,I.callback(e,t))}}}})[0];return I.callback=A,I.facade}var Pjt=typeof window<"u"?gA.useLayoutEffect:gA.useEffect,EpI=new WeakMap;function Ljt(g,A){var I=Kjt(null,function(e){return g.forEach(function(t){return YAg(t,e)})});return Pjt(function(){var e=EpI.get(I);if(e){var t=new Set(e),B=new Set(g),o=I.current;t.forEach(function(C){B.has(C)||YAg(C,null)}),B.forEach(function(C){t.has(C)||YAg(C,o)})}EpI.set(I,g)},[g]),I}function Yjt(g){return g}function _jt(g,A){A===void 0&&(A=Yjt);var I=[],e=!1,t={read:function(){if(e)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return I.length?I[I.length-1]:g},useMedium:function(B){var o=A(B,e);return I.push(o),function(){I=I.filter(function(C){return C!==o})}},assignSyncMedium:function(B){for(e=!0;I.length;){var o=I;I=[],o.forEach(B)}I={push:function(C){return B(C)},filter:function(){return I}}},assignMedium:function(B){e=!0;var o=[];if(I.length){var C=I;I=[],C.forEach(B),o=I}var Q=function(){var E=o;o=[],E.forEach(B)},i=function(){return Promise.resolve().then(Q)};i(),I={push:function(E){o.push(E),i()},filter:function(E){return o=o.filter(E),I}}}};return t}function bjt(g){g===void 0&&(g={});var A=_jt(null);return A.options=dx({async:!0,ssr:!1},g),A}var npI=function(g){var A=g.sideCar,I=ipI(g,["sideCar"]);if(!A)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var e=A.read();if(!e)throw new Error("Sidecar medium not found");return gA.createElement(e,dx({},I))};npI.isSideCarExport=!0;function Hjt(g,A){return g.useMedium(A),npI}var spI=bjt(),_Ag=function(){},uyA=gA.forwardRef(function(g,A){var I=gA.useRef(null),e=gA.useState({onScrollCapture:_Ag,onWheelCapture:_Ag,onTouchMoveCapture:_Ag}),t=e[0],B=e[1],o=g.forwardProps,C=g.children,Q=g.className,i=g.removeScrollBar,E=g.enabled,n=g.shards,s=g.sideCar,r=g.noRelative,a=g.noIsolation,c=g.inert,h=g.allowPinchZoom,l=g.as,D=l===void 0?"div":l,d=g.gapMode,y=ipI(g,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),w=s,u=Ljt([I,A]),G=dx(dx({},y),t);return gA.createElement(gA.Fragment,null,E&&gA.createElement(w,{sideCar:spI,removeScrollBar:i,shards:n,noRelative:r,noIsolation:a,inert:c,setCallbacks:B,allowPinchZoom:!!h,lockRef:I,gapMode:d}),o?gA.cloneElement(gA.Children.only(C),dx(dx({},G),{ref:u})):gA.createElement(D,dx({},G,{className:Q,ref:u}),C))});uyA.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},uyA.classNames={fullWidth:wyA,zeroRight:yyA};var vjt=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function qjt(){if(!document)return null;var g=document.createElement("style");g.type="text/css";var A=vjt();return A&&g.setAttribute("nonce",A),g}function Tjt(g,A){g.styleSheet?g.styleSheet.cssText=A:g.appendChild(document.createTextNode(A))}function Zjt(g){var A=document.head||document.getElementsByTagName("head")[0];A.appendChild(g)}var Ojt=function(){var g=0,A=null;return{add:function(I){g==0&&(A=qjt())&&(Tjt(A,I),Zjt(A)),g++},remove:function(){g--,!g&&A&&(A.parentNode&&A.parentNode.removeChild(A),A=null)}}},Wjt=function(){var g=Ojt();return function(A,I){gA.useEffect(function(){return g.add(A),function(){g.remove()}},[A&&I])}},apI=function(){var g=Wjt(),A=function(I){var e=I.styles,t=I.dynamic;return g(e,t),null};return A},Vjt={left:0,top:0,right:0,gap:0},bAg=function(g){return parseInt(g||"",10)||0},jjt=function(g){var A=window.getComputedStyle(document.body),I=A[g==="padding"?"paddingLeft":"marginLeft"],e=A[g==="padding"?"paddingTop":"marginTop"],t=A[g==="padding"?"paddingRight":"marginRight"];return[bAg(I),bAg(e),bAg(t)]},zjt=function(g){if(g===void 0&&(g="margin"),typeof window>"u")return Vjt;var A=jjt(g),I=document.documentElement.clientWidth,e=window.innerWidth;return{left:A[0],top:A[1],right:A[2],gap:Math.max(0,e-I+A[2]-A[0])}},Xjt=apI(),dT="data-scroll-locked",$jt=function(g,A,I,e){var t=g.left,B=g.top,o=g.right,C=g.gap;return I===void 0&&(I="margin"),`
|
|
5353
|
+
`,eTt=({rotation:g,infiniteGrid:A,cellSize:I=1,sectionSize:e=10})=>{const{scene:t,camera:B}=SD(),o=1e3,C=gA.useMemo(()=>{const Q=new Sf(o,o);Q.rotateX(-Math.PI/2);const i=new KN({vertexShader:gTt,fragmentShader:ITt,uniforms:{cellSize:{value:I},sectionSize:{value:e},gridColor:{value:new tB(15658734)},sectionColor:{value:new tB(13421823)},fadeDistance:{value:100},fadeStrength:{value:1.5}},transparent:!0,side:yl}),E=new FB(Q,i);return g&&E.rotation.fromArray(g),E},[o,I,e,g]);return zgA(()=>{A&&C.position.set(B.position.x,B.position.y,0)}),gA.useEffect(()=>{if(!(!t||!C))return t.add(C),()=>{t.remove(C),C.geometry.dispose(),Array.isArray(C.material)?C.material.forEach(Q=>Q.dispose()):C.material.dispose()}},[t,C]),null},U$A=.75,tTt=({boardDimensions:g,boardCenter:A,darkBackgroundEnabled:I=!1,shadowsEnabled:e=!1})=>{const{scene:t}=SD(),B=gA.useMemo(()=>{const o=new Nc;o.name="cad-viewer-light-rig";const C=A?.x??0,Q=A?.y??0,i=Math.max(g?.width??0,g?.height??0,20),E=i*.8,n=i,s=i*1.7,r=new BFg(16186360,.22);r.name="cad-viewer-soft-ambient",o.add(r);const a=new $ue(15004141,1581597,.2);a.name="cad-viewer-hemisphere",o.add(a);const c=(h,l,D,d,y=!1)=>{const w=new tFg(l,D);if(w.name=h,w.position.set(C+d[0],Q+d[1],d[2]),w.target.position.set(C,Q,0),w.castShadow=y,y){w.shadow.mapSize.set(2048,2048),w.shadow.bias=-2e-4,w.shadow.normalBias=.03,w.shadow.radius=5;const u=w.shadow.camera;u.left=-E,u.right=E,u.top=E,u.bottom=-E,u.near=.5,u.far=Math.max(i*4,Math.hypot(...d)+i*2),u.updateProjectionMatrix()}o.add(w),o.add(w.target)};return c("cad-viewer-key-light",16775406,1.35,[s*.68,-s*.8,s*1.08],e),c("cad-viewer-fill-light",14477554,.25,[-n*.85,n*.55,n*.75]),c("cad-viewer-rim-light",12184275,.5,[-n*.35,n*.85,n*.95]),c("cad-viewer-underside-key-light",16775406,1.35*U$A,[s*.68,-s*.8,-s*1.08]),c("cad-viewer-underside-fill-light",14477554,.25*U$A,[-n*.85,n*.55,-n*.75]),c("cad-viewer-underside-rim-light",12184275,.5*U$A,[-n*.35,n*.85,-n*.95]),o},[A,g,e]);return gA.useEffect(()=>{const o=t.background,C=t.environment;return t.background=I?new tB(1053456):null,t.environment=null,()=>{t.background=o,t.environment=C}},[I,t]),gA.useEffect(()=>{if(t)return t.add(B),()=>{t.remove(B)}},[t,B]),null},BTt=.05,oTt=({camera:g,initialOrbitDistance:A})=>{const I=Number.isFinite(A)?A*BTt:0;return Math.max(I,g.near,Number.EPSILON)},CTt=({camera:g,controls:A,minimumDollyDistance:I})=>{if(!(g instanceof $h))return!1;const e=A.getDistance();if(Number.isFinite(e)&&e>=I)return!1;const t=new oI;return g.getWorldDirection(t),A.target.copy(g.position).addScaledVector(t,I),!0},QTt=({autoRotate:g,autoRotateSpeed:A,onStart:I,panSpeed:e,rotateSpeed:t,zoomSpeed:B,enableDamping:o,dampingFactor:C,target:Q,onControlsChange:i})=>{const{camera:E,renderer:n}=SD(),s=gA.useMemo(()=>!E||!n?null:new wPt(E,n.domElement),[E,n]),r=gA.useMemo(()=>{if(!s||!(E instanceof $h))return Number.EPSILON;const a=Q?Math.hypot(E.position.x-Q[0],E.position.y-Q[1],E.position.z-Q[2]):s.getDistance();return oTt({camera:E,initialOrbitDistance:a})},[E,s,Q]);return gA.useEffect(()=>(i?.(s??null),()=>i?.(null)),[s,i]),gA.useEffect(()=>{if(!s)return;const a=()=>{i?.(s)};return s.addEventListener("change",a),()=>{s.removeEventListener("change",a)}},[s,i]),gA.useEffect(()=>{s&&(s.autoRotate=g||!1,s.autoRotateSpeed=A||1,e!==void 0&&(s.panSpeed=e),t!==void 0&&(s.rotateSpeed=t),B!==void 0&&(s.zoomSpeed=B),o!==void 0&&(s.enableDamping=o),C!==void 0&&(s.dampingFactor=C),s.zoomToCursor=!0,s.mouseButtons={LEFT:b4.ROTATE,MIDDLE:b4.PAN,RIGHT:null},Q&&(s.target.set(Q[0],Q[1],Q[2]),s.update()))},[s,g,A,e,t,B,o,C,Q]),gA.useEffect(()=>{if(!(!s||!I))return s.addEventListener("start",I),()=>{s.removeEventListener("start",I)}},[s,I]),gA.useEffect(()=>{if(s)return()=>{s.dispose()}},[s]),zgA(()=>{s&&(CTt({camera:E,controls:s,minimumDollyDistance:r}),s.update())},[E,s,r]),null},iTt=10,iT={banana:{type:"banana",label:"Show Banana",width:190,height:60,depth:34,zCenter:17},"credit-card":{type:"credit-card",label:"Show Credit Card",width:85.6,height:53.98,depth:.76,zCenter:0},"14in-macbook":{type:"14in-macbook",label:"Show 14in Macbook",width:312.6,height:221.2,depth:15.5,zCenter:0}},ETt=Object.values(iT),nTt=[{type:null,label:"None"},...ETt],sTt=(g,A)=>g===A?null:A,J$A=g=>Number.isFinite(g)?Math.max(g??0,0):0,JdA=g=>Number.isFinite(g)?g??0:0,HuI=(g,A,I)=>{const e=iT[g],t=J$A(A?.width),B=JdA(I?.x),o=JdA(I?.y);return{x:B+t/2+iTt+e.width/2,y:o,z:0}},aTt=(g,A,I)=>{const e=iT[g],t=J$A(A?.width),B=J$A(A?.height),o=JdA(I?.x),C=JdA(I?.y),Q=HuI(g,A,I);return{minX:Math.min(o-t/2,Q.x-e.width/2),maxX:Math.max(o+t/2,Q.x+e.width/2),minY:Math.min(C-B/2,Q.y-e.height/2),maxY:Math.max(C+B/2,Q.y+e.height/2),minZ:Math.min(0,Q.z+e.zCenter-e.depth/2),maxZ:Math.max(0,Q.z+e.zCenter+e.depth/2)}};function rTt(g,A){const I=new OG().setFromEuler(new VG(g.x,g.y,g.z)),e=new oI(0,0,1);return e.applyQuaternion(I),e.multiplyScalar(A)}var cTt=()=>{const{mainCameraRef:g}=gJ(),A=gA.useRef(null);return gA.useEffect(()=>{if(!A.current)return;const I=A.current,e=document.createElement("canvas");I.appendChild(e);const t=new ZEA({canvas:e,antialias:!0,alpha:!0});t.setSize(120,120),t.setPixelRatio(window.devicePixelRatio);const B=new pY,o=new $h(75,1,.1,1e3);o.up.set(0,0,1);const C=new BFg(16777215,Math.PI/2);B.add(C);const Q=new Nc;Q.rotation.fromArray([Math.PI/2,0,0]);const i=1,E=new FB(new Jp(i,i,i),new Ps({color:"white"}));Q.add(E);const n=new Cj(new wue(new Jp(i,i,i)),new kY({color:0,linewidth:2}));Q.add(n),B.add(Q);const s=.51,r=(m,p,k)=>{const S=new YKA;return S.text=m,S.position.fromArray(p),k&&S.rotation.fromArray(k),S.color="black",S.fontSize=.25,S.anchorX="center",S.anchorY="middle",S.depthOffset=0,S.font=null,S.sync(),S},a=r("Front",[0,0,s]),c=r("Back",[0,0,-s],[0,Math.PI,0]),h=r("Right",[s,0,0],[0,Math.PI/2,0]),l=r("Left",[-s,0,0],[0,-Math.PI/2,0]),D=r("Top",[0,s,0],[-Math.PI/2,0,0]),d=r("Bottom",[0,-s,0],[Math.PI/2,0,0]);Q.add(a),Q.add(c),Q.add(h),Q.add(l),Q.add(D),Q.add(d);let y=null,w=!0;const u=new IntersectionObserver(([m])=>{w=m?.isIntersecting??!1});u.observe(e);const G=()=>{if(y=requestAnimationFrame(G),!!w){if(g.current){const m=rTt(g.current.rotation??new VG(0,0,0),2);m.equals(o.position)||(o.position.copy(m),o.lookAt(0,0,0))}t.render(B,o)}};return G(),()=>{u.disconnect(),e.remove(),y!==null&&cancelAnimationFrame(y),a.dispose(),c.dispose(),h.dispose(),l.dispose(),D.dispose(),d.dispose(),E.geometry.dispose(),E.material.dispose(),n.geometry.dispose(),n.material.dispose(),B.clear(),t.dispose(),t.forceContextLoss()}},[g]),W.jsx("div",{ref:A,style:{position:"absolute",top:0,left:0,width:120,height:120,zIndex:$gA.orientationCube}})},vuI=(g,A,I)=>{const e=g/2,t=A/2,B=Math.min(I,e,t),o=new vxg;return o.moveTo(-e+B,-t),o.lineTo(e-B,-t),o.quadraticCurveTo(e,-t,e,-t+B),o.lineTo(e,t-B),o.quadraticCurveTo(e,t,e-B,t),o.lineTo(-e+B,t),o.quadraticCurveTo(-e,t,-e,t-B),o.lineTo(-e,-t+B),o.quadraticCurveTo(-e,-t,-e+B,-t),o},K$A=(g,A,I,e)=>quI(vuI(g,A,e),I),quI=(g,A)=>{const I=new wKA(g,{depth:A,bevelEnabled:!1,curveSegments:24});return I.translate(0,0,-A/2),I.computeVertexNormals(),I},hTt=(g,A)=>{const I=iT[A];g.updateMatrixWorld(!0);const t=new WG().setFromObject(g).getSize(new oI);g.scale.set(I.width/t.x,I.height/t.y,I.depth/t.z),g.updateMatrixWorld(!0);const o=new WG().setFromObject(g).getCenter(new oI);g.position.set(-o.x,-o.y,I.zCenter-o.z),g.updateMatrixWorld(!0)},lTt=()=>{const g=new Pxg([new oI(-82,18,16),new oI(-67,7,15),new oI(-43,-9,14),new oI(-15,-18,14),new oI(16,-18,14),new oI(47,-8,14.5),new oI(72,8,16),new oI(84,19,17)]),A=84,I=30,e=g.computeFrenetFrames(A,!1),t=[],B=[],o=[],C=[],Q=[],i=new tB(16766023),E=new tB(12038965);for(let s=0;s<=A;s++){const r=s/A,a=g.getPointAt(r),c=e.normals[s],h=e.binormals[s],D=3.4+12.4*Math.sin(Math.PI*r)**.48,d=Math.max(0,(r-.82)/.18)*.38,y=i.clone().lerp(E,d);for(let w=0;w<=I;w++){const u=w/I*Math.PI*2,G=Math.sin(u),m=Math.cos(u),p=1+Math.cos(u*5+.35)*.035,k=new oI().addScaledVector(c,m).addScaledVector(h,G*.9).normalize(),S=a.clone().addScaledVector(c,m*D*p).addScaledVector(h,G*D*.9*p);t.push(S.x,S.y,S.z),B.push(k.x,k.y,k.z),o.push(y.r,y.g,y.b),C.push(r,w/I)}}for(let s=1;s<=A;s++)for(let r=1;r<=I;r++){const a=I+1,c=a*(s-1)+(r-1),h=a*s+(r-1),l=a*s+r,D=a*(s-1)+r;Q.push(c,D,h,h,D,l)}const n=new Jn;return n.setIndex(Q),n.setAttribute("position",new To(t,3)),n.setAttribute("normal",new To(B,3)),n.setAttribute("color",new To(o,3)),n.setAttribute("uv",new To(C,2)),n.computeBoundingBox(),n.computeBoundingSphere(),{geometry:n,curve:g}},DTt=()=>{const g=new Nc,A=new Nc,{geometry:I,curve:e}=lTt(),t=new FB(I,new Ps({color:16777215,roughness:.72,metalness:0,vertexColors:!0}));t.name="banana-peel",A.add(t);const B=new FB(new fY(3.4,20,12),new Ps({color:6242844,roughness:.92}));B.position.copy(e.getPointAt(0)),B.scale.set(1.15,.78,.78),B.name="banana-blossom-tip",A.add(B);const o=11,C=e.getTangentAt(1).normalize(),Q=new FB(new e6(2.5,4.1,o,18),new Ps({color:8483625,roughness:.82}));Q.quaternion.setFromUnitVectors(new oI(0,1,0),C),Q.position.copy(e.getPointAt(1)).addScaledVector(C,o/2),Q.name="banana-stem",A.add(Q);const i=new FB(new fY(2.55,18,10),new Ps({color:5981470,roughness:.9}));return i.position.copy(e.getPointAt(1)).addScaledVector(C,o),i.name="banana-stem-tip",A.add(i),hTt(A,"banana"),g.add(A),g},dTt=(g,A,I,e,t)=>{const B=vuI(g,A,e),o=new hKA;return o.absarc(0,0,t,0,Math.PI*2,!0),B.holes.push(o),quI(B,I)},yTt=(g,A)=>{const t=new FB(new e6(A-.15,A-.15,.25,48),new Ps({color:10199202,roughness:.48,metalness:.28}));return t.rotation.x=Math.PI/2,t.position.z=g-.35-.25/2,t.name="macbook-lid-indent",t},wTt=()=>{const g=iT["credit-card"],A=new Nc,I=new FB(K$A(g.width,g.height,g.depth,3.18),new Ps({color:2383272,roughness:.38,metalness:.08}));I.name="credit-card-body",A.add(I);const e=g.depth/2+.08,t=new FB(K$A(12,9,.14,1.2),new Ps({color:14003525,roughness:.3,metalness:.62}));t.position.set(-21,3,e),t.name="credit-card-chip",A.add(t);const B=new Ps({color:15331061,roughness:.45,metalness:.05});for(let o=0;o<4;o++){const C=new FB(new Jp(o===3?8:12,.8,.1),B);C.position.set(-20+o*14,-14,e+.08),C.name="credit-card-detail",A.add(C)}return A},uTt=()=>{const g=iT["14in-macbook"],A=new Nc,I=new Ps({color:12896201,roughness:.3,metalness:.38}),e=new FB(K$A(g.width,g.height,13.5,9),I);e.position.z=-1,e.name="macbook-body",A.add(e);const t=2,B=6.75,o=B+t/2,C=12,Q=new FB(dTt(g.width-1.8,g.height-1.8,t,8.2,C),I.clone());Q.position.z=B,Q.name="macbook-lid",A.add(Q);const i=new FB(new Jp(g.width-42,3.2,1.2),new Ps({color:3158838,roughness:.55,metalness:.45}));i.position.set(0,g.height/2-2.4,6.15),i.name="macbook-hinge",A.add(i),A.add(yTt(o,C));const E=new FB(new Jp(54,1.2,.8),new Ps({color:6712174,roughness:.45,metalness:.5}));return E.position.set(0,-221.2/2+.5,2.5),E.name="macbook-front-notch",A.add(E),A},GTt=g=>{const A=g==="banana"?DTt():g==="credit-card"?wTt():uTt();return A.name=`reference-object-${g}`,A.userData.isReferenceObject=!0,A.userData.referenceObjectType=g,ZM(A),A},mTt=g=>{const A=new Set,I=new Set;g.traverse(e=>{if(!(e instanceof FB))return;A.add(e.geometry);const t=Array.isArray(e.material)?e.material:[e.material];for(const B of t)I.add(B)});for(const e of A)e.dispose();for(const e of I)e.dispose()},pTt=(g,A,I,e=1.18)=>{const t=Math.max(I.maxX-I.minX,0),B=Math.max(I.maxY-I.minY,0),o=Math.max(I.maxZ-I.minZ,0),C=new oI((I.minX+I.maxX)/2,(I.minY+I.maxY)/2,(I.minZ+I.maxZ)/2),Q=Math.max(Math.hypot(t,B,o)/2,1),i=A?.target??new oI,E=new oI(0,-.75,.9).normalize();let n=Math.max(g.position.distanceTo(i),5);if(g instanceof $h){const s=FH.degToRad(g.fov),r=2*Math.atan(Math.tan(s/2)*g.aspect),a=Math.min(s,r);n=Q*e/Math.sin(a/2),g.far=Math.max(g.far,n+Q*e*3),g.updateProjectionMatrix()}else if(g instanceof XH){const s=Math.abs(g.right-g.left)/2,r=Math.abs(g.top-g.bottom)/2;g.zoom=Math.min(s/(Q*e),r/(Q*e)),n=Math.max(n,Q*e*2),g.updateProjectionMatrix()}return g.position.copy(C).addScaledVector(E,n),g.lookAt(C),g.updateMatrixWorld(),A&&(A.target.copy(C),A.update()),{center:C,radius:Q,distance:n}},kTt=({type:g,boardDimensions:A,boardCenter:I})=>{const{scene:e}=SD(),t=gA.useMemo(()=>{const B=GTt(g),o=HuI(g,A,I);return B.position.set(o.x,o.y,o.z),B},[g,A,I]);return gA.useEffect(()=>(e.add(t),()=>{e.remove(t),mTt(t)}),[e,t]),null},TuI=({bounds:g})=>{const{camera:A}=SD(),{controlsRef:I}=gJ();return gA.useEffect(()=>{pTt(A,I.current,g)},[g,A,I]),null},MTt=()=>{const{camera:g}=SD(),{setCameraRotation:A}=gJ();return zgA(()=>{g&&A(g.rotation)}),null},ZuI=gA.forwardRef(({children:g,initialCameraPosition:A=[5,-5,5],autoRotateDisabled:I,clickToInteractEnabled:e=!1,boardDimensions:t,boardCenter:B,cameraSessionScope:o,referenceObject:C,onUserInteraction:Q,onCameraControllerReady:i},E)=>{const[n,s]=gA.useState(!e),{mainCameraRef:r,handleControlsChange:a,controller:c}=gJ(),{darkBackgroundEnabled:h,gridEnabled:l,lightingEnabled:D}=x$A(),{handleCameraCreated:d,handleControlsChange:y}=z7t({cameraSessionScope:o});gA.useEffect(()=>{i&&i(c)},[c,i]);const w=gA.useMemo(()=>{if(C)return aTt(C,t,B)},[C,t,B]),u=gA.useMemo(()=>{if(!t)return 10;const m=t.width??0,p=t.height??0;return Math.max(Math.max(m,p)*1.5,10)},[t]),G=gA.useMemo(()=>{if(w)return[(w.minX+w.maxX)/2,(w.minY+w.maxY)/2,(w.minZ+w.maxZ)/2];if(B)return[B.x,B.y,0]},[B,w]);return W.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[W.jsx(cTt,{}),W.jsxs(ATt,{ref:E,scene:{up:new oI(0,0,1)},camera:{up:[0,0,1],position:A},onCreated:({camera:m})=>{r.current=m,d(m)},children:[W.jsx(Oqt,{}),W.jsx(V7t,{}),W.jsx(MTt,{}),n&&W.jsx(QTt,{autoRotate:!I,autoRotateSpeed:1,onStart:Q,rotateSpeed:.5,panSpeed:.75,zoomSpeed:.5,enableDamping:!0,dampingFactor:.1,target:G,onControlsChange:m=>{a(m),y()}}),W.jsx(tTt,{boardDimensions:t,boardCenter:B,darkBackgroundEnabled:h,shadowsEnabled:D}),C&&W.jsx(kTt,{type:C,boardDimensions:t,boardCenter:B}),w&&W.jsx(TuI,{bounds:w}),l&&W.jsx(eTt,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:3,sectionSize:u}),g]},o),W.jsxs("div",{style:{position:"absolute",right:24,bottom:24,fontFamily:"sans-serif",color:"white",WebkitTextStroke:"0.5px rgba(0, 0, 0, 0.5)",fontSize:11},children:["@",UuI.version]}),e&&!n&&W.jsx("button",{type:"button",onClick:()=>s(!0),onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&s(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:$gA.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center"},children:W.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",fontFamily:"sans-serif",pointerEvents:"none"},children:"Click to Interact"})})]})}),STt=g=>{const[A,I]=gA.useState([]),[e,t]=gA.useState(!0);return gA.useEffect(()=>{if(!g)return;(async()=>{t(!0);const C=(Array.isArray(g)?g:[g]).map(async(Q,i)=>{const E=UPt.serialize({binary:!0},[Q]),s=await new Blob(E).arrayBuffer(),a=Q.layerType||(i===0?"board":void 0);return{stlData:s,color:Q.color,layerType:a}});try{const Q=await Promise.all(C);I(Q)}catch(Q){console.error("Error generating STLs:",Q),I([])}finally{t(!1)}})()},[g]),{stls:A,loading:e}},fTt=ts(adA()),RTt=ts(g5()),NTt=ts(VgA()),xTt=ts(g5()),FTt=ts(I5()),UTt=ts(zdI()),OuI=g=>{let A=0;for(let e=0;e<g.length;e++){const t=(e+1)%g.length;A+=g[e][0]*g[t][1],A-=g[t][0]*g[e][1]}return A/2<=0},P$A=(g,A=1.2,I={})=>{const{xyOutset:e=0}=I,{outline:t}=g;let B=t.map(Q=>[Q.x,Q.y]);OuI(B)&&(B=B.reverse());let o=(0,xTt.polygon)({points:B});e!==0&&(o=(0,UTt.expand)({delta:e,corners:"edge"},o));let C=(0,NTt.extrudeLinear)({height:A},o);return C=(0,FTt.translate)([0,0,-A/2],C),C},Oo=.01,jE={copper:[.78,.63,.39],fr4Tan:[.6,.43,.28],fr4SolderMaskGreen:[.06,.31,.19],fr4TracesWithMaskGreen:[.09,.38,.23],fr4TracesWithoutMaskTan:[.6,.43,.28],flexAmber:[.8,.61,.2],fr1Tan:[.8,.4,.2],fr1TracesWithMaskCopper:[.9,.6,.2],fr1SolderMaskGreen:[.02,.1,.04]},uR=.001,fd=32,K2=150,KdA=.6,JTt={fr1:jE.fr1Tan,fr4:jE.fr4Tan,flex:jE.flexAmber},KTt={fr1:jE.fr1SolderMaskGreen,fr4:jE.fr4SolderMaskGreen,flex:jE.flexAmber},PTt={red:"#650202",blue:"#003f7d",purple:"#4c1d69",black:"#071014",white:"#dddddd",yellow:"#dcc84a"},LTt=.875,YTt=/^#(?:[\da-f]{3}|[\da-f]{6})$/i,_Tt=/^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/i,bTt=/^rgb\(\s*\d+%\s*,\s*\d+%\s*,\s*\d+%\s*\)$/i,HTt=/^hsl\(\s*\d*\.?\d+\s*,\s*\d*\.?\d+%\s*,\s*\d*\.?\d+%\s*\)$/i,vTt={blue:.96,purple:.96,black:.99,yellow:.92},WuI=g=>{const A=g?.trim();if(!A)return null;const I=A.toLowerCase();if(I==="green"||I==="not_specified")return null;const t=PTt[I];return t?new tB(t):Object.hasOwn(tB.NAMES,I)||YTt.test(A)||_Tt.test(A)||bTt.test(A)||HTt.test(A)?new tB(I):null},qTt=g=>{const A=g?.trim().toLowerCase();return vTt[A]??LTt},TTt=({red:g,green:A,blue:I})=>Math.hypot(g-220,A-200,I-74)<4||Math.hypot(g-218,A-197,I-76)<4,ZTt=({soldermaskColor:g,copperColor:A,soldermaskOpacity:I})=>g.clone().multiplyScalar(I).add(A.clone().multiplyScalar(1-I)),VuI=g=>{const A=g.clone().convertLinearToSRGB();return`rgb(${[Math.round(A.r*255),Math.round(A.g*255),Math.round(A.b*255)].join(",")})`},OTt=new tB(1063462),L$A=({material:g,solder_mask_color:A})=>{const I=WuI(A);if(I)return I;if(g==="fr4")return OTt.clone();const e=JTt[g]??jE.fr4Tan;return new tB(e[0],e[1],e[2])},WTt=g=>{const A=g.filter(Q=>Q.type==="pcb_panel"),I=jB(g).pcb_board.list();let e,t,B=1.2;if(A.length>0)e=A[0],t=I.find(Q=>Q.pcb_panel_id===e.pcb_panel_id),B=t?.thickness??1.2;else{if(e=I.filter(i=>!i.pcb_panel_id)[0],!e)return console.warn("No pcb_board or pcb_panel found for simplified geometry"),[];t=e,B=e.thickness??1.2}let o;"outline"in e&&e.outline&&e.outline.length>0?o=P$A({outline:e.outline},B):o=(0,RTt.cuboid)({size:[e.width??10,e.height??10,B],center:[e.center.x,e.center.y,0]});const C=L$A({material:t?.material??"fr4",solder_mask_color:t?.solder_mask_color});return[(0,fTt.colorize)([C.r,C.g,C.b],o)]},Y$A=ts(adA()),Pw=ts(WgA()),juI=ts(RdI()),_$A=ts(VgA()),Ck=ts(I5()),rr=ts(g5()),Q3=ts(g5()),VTt=ts(VgA()),PdA=ts(I5()),jTt=ts(WgA()),zTt=64,XTt=(g,A,I)=>{const e=(0,Q3.ellipse)({center:[0,0],radius:[Math.max(g/2,Oo/2),Math.max(A/2,Oo/2)],segments:zTt}),t=(0,VTt.extrudeLinear)({height:I},e);return(0,PdA.translate)([0,0,-I/2],t)},$Tt=(g,A,I)=>{const e=Math.max(g,Oo),t=Math.max(A,Oo);if(Math.abs(e-t)<1e-6)return(0,Q3.cylinder)({center:[0,0,0],radius:e/2,height:I});const B=e>=t,o=B?e:t,C=B?t:e,Q=Math.max(o-C,0),i=(0,Q3.cuboid)({center:[0,0,0],size:B?[Q,C,I]:[C,Q,I]});if(Q<=1e-6)return(0,Q3.cylinder)({center:[0,0,0],radius:C/2,height:I});const E=Q/2,n=(0,Q3.cylinder)({center:B?[-E,0,0]:[0,-E,0],radius:C/2,height:I}),s=(0,Q3.cylinder)({center:B?[E,0,0]:[0,E,0],radius:C/2,height:I});return(0,jTt.union)(i,n,s)},LdA=(g,A,I={})=>{const e=g.hole_shape||"circle",t=I.sizeDelta??0,B=g.hole_offset_x||0,o=g.hole_offset_y||0,C=[g.x+B,g.y+o,0];if(e==="circle"){const r=Math.max((g.hole_diameter??0)+t,Oo),a=Math.max(r/2,Oo/2);return(0,Q3.cylinder)({center:C,radius:a,height:A})}const Q=g.hole_width??g.hole_diameter,i=g.hole_height??g.hole_diameter;if(!Q||!i)return null;const E=Math.max(Q+t,Oo),n=Math.max(i+t,Oo);if(e==="oval"){const r=XTt(E,n,A);return(0,PdA.translate)([C[0],C[1],0],r)}if(e==="pill"||e==="rotated_pill"){let r=$Tt(E,n,A);if(!r)return null;const a=g.ccw_rotation||0;return a&&(r=(0,PdA.rotateZ)(a*Math.PI/180,r)),(0,PdA.translate)(C,r)}const s=Math.max((g.hole_diameter??Q??i??Oo)+t,Oo);return(0,Q3.cylinder)({center:C,radius:s/2,height:A})},zE=ts(g5()),sx=ts(adA()),gc=ts(WgA()),zuI=ts(I5()),YdA=ts(VgA()),Qk=ts(I5()),AZt=1e-5;function XuI(g,A,I){if(typeof I!="number"||!Number.isFinite(I)||I<=0)return 0;const e=g/2,t=A/2,B=Math.min(e,t)-2*AZt;return Math.max(0,Math.min(I,B))}function i3(g){if(!(!g||typeof g!="object"))return g.corner_radius??g.cornerRadius??g.rect_pad_border_radius??g.rectPadBorderRadius??g.rect_border_radius??g.rectBorderRadius??void 0}var gZt=.05,b$A=64,t5=(g,A)=>A?(0,gc.intersect)(A,g):g,IIA=(g,A,I={})=>{const{clipGeom:e}=I;g.shape||(g.shape="circle");const t=Math.max(A.pcbThickness*.002,Oo/5),B=Math.max(A.pcbThickness*3e-4,Oo/20),o=Math.max(A.pcbThickness*.0025,Oo/4),C=A.pcbThickness+2*gZt+4*Oo,Q=Math.max(A.pcbThickness-2*(t+B+o),Oo),i=Math.max(Q,Oo);if(g.shape==="circle"){const E=g.outer_diameter??Math.max(g.hole_diameter,0),n=Q,s=(0,zE.cylinder)({center:[g.x,g.y,0],radius:E/2,height:n}),r=t5(s,e),a=(0,zE.cylinder)({center:[g.x,g.y,0],radius:Math.max(g.hole_diameter/2,.01),height:C});return(0,sx.colorize)(jE.copper,(0,gc.subtract)(r,a))}if(g.shape==="oval"){const E=g.outer_width||g.hole_width||0,n=g.outer_height||g.hole_height||0,s=g.hole_width||0,r=g.hole_height||0,a=(()=>{const l=(0,zE.cylinder)({center:[0,0,0],radius:1,height:Q,segments:64}),D=(0,zuI.scale)([E/2,n/2,1],l);return(0,Qk.translate)([g.x,g.y,0],D)})(),c=t5(a,e),h=(()=>{const l=(0,zE.cylinder)({center:[0,0,0],radius:1,height:C,segments:64}),D=(0,zuI.scale)([Math.max(s/2,.01),Math.max(r/2,.01),1],l);return(0,Qk.translate)([g.x,g.y,0],D)})();return(0,sx.colorize)(jE.copper,(0,gc.subtract)(c,h))}if(g.shape==="circular_hole_with_rect_pad"){const E=g.hole_offset_x||0,n=g.hole_offset_y||0,s=g.rect_pad_width||g.hole_diameter,r=g.rect_pad_height||g.hole_diameter,a=i3(g),c=t5((0,gc.union)((()=>{const D=(0,zE.roundedRectangle)({size:[s,r],roundRadius:a||0,segments:b$A}),d=(0,YdA.extrudeLinear)({height:Q},D);return(0,Qk.translate)([g.x,g.y,-Q/2],d)})(),(0,zE.cylinder)({center:[g.x+(E||0),g.y+(n||0),0],radius:g.hole_diameter/2,height:i})),e),h=(0,zE.cylinder)({center:[g.x+(E||0),g.y+(n||0),0],radius:Math.max(g.hole_diameter/2-Oo,.01),height:C}),l=(0,gc.subtract)(c,h);return I.clipGeom?(0,sx.colorize)(jE.copper,(0,gc.intersect)(l,I.clipGeom)):(0,sx.colorize)(jE.copper,l)}if(g.shape==="pill"){const E=(g.ccw_rotation||0)*Math.PI/180,n=R=>{if(!E)return R;const F=(0,Qk.translate)([-g.x,-g.y,0],R),N=(0,Qk.rotate)([0,0,E],F);return(0,Qk.translate)([g.x,g.y,0],N)},s=g.hole_height>g.hole_width,r=s?g.hole_height:g.hole_width,a=s?g.hole_width:g.hole_height,c=s?g.outer_height||a+.2:g.outer_width||r+.2,h=s?g.outer_width||r+.2:g.outer_height||a+.2,l=a/2,D=Math.abs(r-a),w=((R,F,N)=>{const U=F/2,P=Math.abs(R-F);if(P<=1e-6)return(0,zE.cylinder)({center:[g.x,g.y,0],radius:U,height:N});const b=(0,zE.cuboid)({center:[g.x,g.y,0],size:s?[F,P,N]:[P,F,N]}),H=(0,zE.cylinder)({center:s?[g.x,g.y-P/2,0]:[g.x-P/2,g.y,0],radius:U,height:N}),q=(0,zE.cylinder)({center:s?[g.x,g.y+P/2,0]:[g.x+P/2,g.y,0],radius:U,height:N});return(0,gc.union)(b,H,q)})(c,h,Q),u=(0,zE.cuboid)({center:[g.x,g.y,0],size:s?[a-2*Oo,D,C]:[D,a-2*Oo,C]}),G=(0,zE.cylinder)({center:s?[g.x,g.y-D/2,0]:[g.x-D/2,g.y,0],radius:l-Oo,height:C}),m=(0,zE.cylinder)({center:s?[g.x,g.y+D/2,0]:[g.x+D/2,g.y,0],radius:l-Oo,height:C}),p=(0,gc.union)(u,G,m),k=t5(n(w),e),S=n(p);return(0,sx.colorize)(jE.copper,(0,gc.subtract)(k,S))}if(g.shape==="pill_hole_with_rect_pad"){if(g.hole_shape&&g.hole_shape!=="pill"||g.pad_shape&&g.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for pill_hole_with_rect_pad");const E=g.hole_offset_x||0,n=g.hole_offset_y||0,s=g.hole_height>g.hole_width,r=s?g.hole_height:g.hole_width,a=s?g.hole_width:g.hole_height,c=a/2,h=Math.abs(r-a),l=g.rect_pad_width||r+.2,D=g.rect_pad_height||a+.2,d=i3(g),y=.03,w=(0,gc.union)((0,zE.cuboid)({center:[g.x+E,g.y+n,0],size:s?[a+2*y,h+2*y,i]:[h+2*y,a+2*y,i]}),(0,zE.cylinder)({center:s?[g.x+E,g.y+n-h/2,0]:[g.x+E-h/2,g.y+n,0],radius:c+y,height:i}),(0,zE.cylinder)({center:s?[g.x+E,g.y+n+h/2,0]:[g.x+E+h/2,g.y+n,0],radius:c+y,height:i})),u=(0,gc.union)((0,zE.cuboid)({center:[g.x+E,g.y+n,0],size:s?[a,h,C]:[h,a,C]}),(0,zE.cylinder)({center:s?[g.x+E,g.y+n-h/2,0]:[g.x+E-h/2,g.y+n,0],radius:c,height:C}),(0,zE.cylinder)({center:s?[g.x+E,g.y+n+h/2,0]:[g.x+E+h/2,g.y+n,0],radius:c,height:C})),G=(()=>{const R=(0,zE.roundedRectangle)({size:[l,D],roundRadius:d||0,segments:b$A}),F=(0,YdA.extrudeLinear)({height:Q},R);return(0,Qk.translate)([g.x,g.y,-Q/2],F)})(),m=(0,gc.subtract)(G,u),p=(0,gc.union)((0,zE.cuboid)({center:[g.x+E,g.y+n,0],size:s?[a-2*Oo,h-2*Oo,C]:[h-2*Oo,a-2*Oo,C]}),(0,zE.cylinder)({center:s?[g.x+E,g.y+n-h/2,0]:[g.x+E-h/2,g.y+n,0],radius:c-Oo,height:C}),(0,zE.cylinder)({center:s?[g.x+E,g.y+n+h/2,0]:[g.x+E+h/2,g.y+n,0],radius:c-Oo,height:C})),k=(0,gc.subtract)(w,p),S=t5((0,gc.union)(m,k),e);return(0,sx.colorize)(jE.copper,S)}else if(g.shape==="rotated_pill_hole_with_rect_pad"){if(g.hole_shape&&g.hole_shape!=="rotated_pill"||g.pad_shape&&g.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for rotated_pill_hole_with_rect_pad");const E=g.hole_offset_x||0,n=g.hole_offset_y||0,s=g.hole_width,r=g.hole_height,a=s>=r,c=a?s:r,h=a?r:s,l=h/2,D=Math.abs(c-h),d=g.rect_pad_width||s+.2,y=g.rect_pad_height||r+.2,w=i3(g),u=.03,G=(g.hole_ccw_rotation||0)*Math.PI/180,m=(g.rect_ccw_rotation||0)*Math.PI/180,p=H=>{const q=E*Math.cos(G)-n*Math.sin(G),j=E*Math.sin(G)+n*Math.cos(G),Z=(0,Qk.rotate)([0,0,G],H);return(0,Qk.translate)([g.x+q,g.y+j,0],Z)},k=H=>{if(!m)return H;const q=(0,Qk.translate)([-g.x,-g.y,0],H),j=(0,Qk.rotate)([0,0,m],q);return(0,Qk.translate)([g.x,g.y,0],j)},S=p((0,gc.union)((0,zE.cuboid)({center:[0,0,0],size:a?[D+2*u,h+2*u,i]:[h+2*u,D+2*u,i]}),(0,zE.cylinder)({center:a?[-D/2,0,0]:[0,-D/2,0],radius:l+u,height:i}),(0,zE.cylinder)({center:a?[D/2,0,0]:[0,D/2,0],radius:l+u,height:i}))),R=p((0,gc.union)((0,zE.cuboid)({center:[0,0,0],size:a?[D,h,C]:[h,D,C]}),(0,zE.cylinder)({center:a?[-D/2,0,0]:[0,-D/2,0],radius:l,height:C}),(0,zE.cylinder)({center:a?[D/2,0,0]:[0,D/2,0],radius:l,height:C}))),F=k((()=>{const H=(0,zE.roundedRectangle)({size:[d,y],roundRadius:w||0,segments:b$A}),q=(0,YdA.extrudeLinear)({height:Q},H);return(0,Qk.translate)([g.x,g.y,-Q/2],q)})()),N=(0,gc.subtract)(F,R),U=p((0,gc.union)((0,zE.cuboid)({center:[0,0,0],size:a?[D-2*Oo,h-2*Oo,C]:[h-2*Oo,D-2*Oo,C]}),(0,zE.cylinder)({center:a?[-D/2,0,0]:[0,-D/2,0],radius:l-Oo,height:C}),(0,zE.cylinder)({center:a?[D/2,0,0]:[0,D/2,0],radius:l-Oo,height:C}))),P=(0,gc.subtract)(S,U),b=t5((0,gc.union)(N,P),e);return(0,sx.colorize)(jE.copper,b)}else if(g.shape==="hole_with_polygon_pad"){const E=g.pad_outline;if(!Array.isArray(E)||E.length<3)throw new Error(`Invalid pad_outline for plated hole at (${g.x}, ${g.y})`);const n=E.map(y=>[y.x,y.y]),s=(0,zE.polygon)({points:n}),c=((y,w)=>{const u=Math.max(y,Oo),G=(0,YdA.extrudeLinear)({height:u},s);return(0,Qk.translate)([g.x,g.y,w-u/2],G)})(Q,0),h=t5(c,e),l=LdA(g,i);if(!l)return(0,sx.colorize)(jE.copper,h);const D=LdA(g,C,{sizeDelta:-2*Oo})||l;let d=(0,gc.union)((0,gc.subtract)(h,l),l);return I.clipGeom?(d=(0,gc.subtract)(d,D),d=(0,gc.intersect)(d,I.clipGeom),(0,sx.colorize)(jE.copper,d)):(0,sx.colorize)(jE.copper,(0,gc.subtract)(d,D))}else throw new Error(`Unsupported plated hole shape: ${g.shape}`)},IZt=ts(WgA()),eZt=ts(I5()),H$A=ts(g5());function tZt({x:g,y:A,outerDiameter:I,holeDiameter:e,thickness:t}){if(I<=e)throw new Error(`Invalid via geometry: outerDiameter (${I}) must be > holeDiameter (${e})`);const B=Oo,o=Math.min(I/2,e/2+B),Q=(0,H$A.cylinder)({center:[0,0,0],radius:o,height:t,segments:fd}),i=t+2*Oo,E=(0,H$A.cylinder)({center:[0,0,0],radius:e/2,height:i,segments:fd}),n=(0,IZt.subtract)(Q,E);return(0,eZt.translate)([g,A,0],n)}function BZt({x:g,y:A,holeDiameter:I,thickness:e}){const t=e*1.5,B=I/2+Oo;return(0,H$A.cylinder)({center:[g,A,0],radius:B,height:t,segments:fd})}function v$A(g){const A=qpg(g),I=[...jB(g).pcb_via.list()],e=new Map;for(const t of I){const o=`${A.get(t.pcb_via_id)?.pcb_board_id??""}:${t.x}:${t.y}`,C=e.get(o)??[];C.push(t),e.set(o,C)}for(const t of jB(g).pcb_trace.list()){const B=A.get(t.pcb_trace_id);for(const[o,C]of t.route.entries()){if(C.route_type!=="via")continue;const Q=`${B?.pcb_board_id??""}:${C.x}:${C.y}`,i=e.get(Q)??[];if(i.some(s=>s.layers.includes(C.from_layer)&&s.layers.includes(C.to_layer)))continue;const n={type:"pcb_via",pcb_via_id:`${t.pcb_trace_id}_route_via_${o}`,pcb_trace_id:t.pcb_trace_id,subcircuit_id:t.subcircuit_id,pcb_group_id:t.pcb_group_id,x:C.x,y:C.y,layers:[C.from_layer,C.to_layer],hole_diameter:C.hole_diameter??B?.min_via_hole_diameter??.25,outer_diameter:C.outer_diameter??B?.min_via_pad_diameter??.6,tented_on_top:C.tented_on_top,tented_on_bottom:C.tented_on_bottom};I.push(n),i.push(n),e.set(Q,i)}}return I}var oZt=64,CZt=1,q$A=.05,$uI=["initializing","processing_plated_holes","processing_holes","processing_cutouts","processing_vias","finalizing","done"],QZt=class{board;plated_holes;holes;pcb_vias;pcb_cutouts;boardGeom=null;platedHoleGeoms=[];viaGeoms=[];copperDrills=[];boardClipGeom=null;state="initializing";currentIndex=0;ctx;onCompleteCallback;finalGeoms=[];constructor(g,A){this.onCompleteCallback=A;const I=g.filter(t=>t.type==="pcb_panel"),e=jB(g).pcb_board.list();if(I.length>0){const t=I[0],B=e.find(o=>o.pcb_panel_id===t.pcb_panel_id);this.board={type:"pcb_board",pcb_board_id:t.pcb_panel_id,center:t.center,width:t.width,height:t.height,thickness:B?.thickness??1.4,material:B?.material??"fr4",num_layers:B?.num_layers??2,solder_mask_color:B?.solder_mask_color}}else{const t=e.filter(B=>!B.pcb_panel_id);this.board=t[0]}this.plated_holes=jB(g).pcb_plated_hole.list(),this.holes=jB(g).pcb_hole.list(),this.pcb_vias=v$A(g),this.pcb_cutouts=jB(g).pcb_cutout.list(),this.ctx={pcbThickness:this.board.thickness??1.2},this.initializeBoard()}initializeBoard(){const g=this.ctx.pcbThickness+2*CZt;this.board.outline&&this.board.outline.length>0?(this.boardGeom=P$A({outline:this.board.outline},this.ctx.pcbThickness),this.boardClipGeom=P$A({outline:this.board.outline},g,{xyOutset:q$A})):(this.boardGeom=(0,rr.cuboid)({size:[this.board.width,this.board.height,this.ctx.pcbThickness],center:[this.board.center.x,this.board.center.y,0]}),this.boardClipGeom=(0,rr.cuboid)({size:[this.board.width+2*q$A,this.board.height+2*q$A,g],center:[this.board.center.x,this.board.center.y,0]})),this.state="processing_plated_holes",this.currentIndex=0}goToNextState(){const g=$uI.indexOf(this.state);g!==-1&&(this.state=$uI[g+1],this.currentIndex=0)}step(g=1){if(this.state==="done"||!this.boardGeom)return!0;for(let A=0;A<g&&this.state!=="done";A++)switch(this.state){case"processing_plated_holes":this.currentIndex<this.plated_holes.length?(this.processPlatedHole(this.plated_holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_holes":this.currentIndex<this.holes.length?(this.processHole(this.holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_vias":this.currentIndex<this.pcb_vias.length?(this.processVia(this.pcb_vias[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_cutouts":this.currentIndex<this.pcb_cutouts.length?(this.processCutout(this.pcb_cutouts[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"finalizing":this.finalize(),this.state="done";break}return this.state==="done"}processCutout(g){if(!this.boardGeom)return;let A=null;const I=this.ctx.pcbThickness*1.5;switch(g.shape){case"rect":{const e=XuI(g.width,g.height,i3(g));if(e>0){const t=(0,rr.roundedRectangle)({size:[g.width,g.height],roundRadius:e,segments:oZt});A=(0,_$A.extrudeLinear)({height:I},t),A=(0,Ck.translate)([0,0,-I/2],A)}else A=(0,rr.cuboid)({center:[0,0,0],size:[g.width,g.height,I]});if(g.rotation){const t=g.rotation*Math.PI/180;A=(0,Ck.rotateZ)(t,A)}A=(0,Ck.translate)([g.center.x,g.center.y,0],A);break}case"circle":A=(0,rr.cylinder)({center:[g.center.x,g.center.y,0],radius:g.radius,height:I});break;case"polygon":{let e=g.points.map(B=>[B.x,B.y]);if(e.length<3){console.warn(`PCB Cutout [${g.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);break}OuI(e)&&(e=e.reverse());const t=(0,rr.polygon)({points:e});A=(0,_$A.extrudeLinear)({height:I},t),A=(0,Ck.translate)([0,0,-I/2],A);break}}A&&(this.boardGeom=(0,Pw.subtract)(this.boardGeom,A))}processPlatedHole(g,A={}){if(this.boardGeom){if(g.shape==="circle"||g.shape==="circular_hole_with_rect_pad"){let I=null;if(g.shape==="circular_hole_with_rect_pad"){if(g.hole_shape&&g.hole_shape!=="circle"||g.pad_shape&&g.pad_shape!=="rect")return;I=(0,rr.cylinder)({center:[g.x+(g.hole_offset_x||0),g.y+(g.hole_offset_y||0),0],radius:g.hole_diameter/2+Oo,height:this.ctx.pcbThickness*1.5})}else I=(0,rr.cylinder)({center:[g.x,g.y,0],radius:g.hole_diameter/2+Oo,height:this.ctx.pcbThickness*1.5});A.dontCutBoard||(this.boardGeom=(0,Pw.subtract)(this.boardGeom,I),this.copperDrills.push({geom:I,platedHoleIndex:this.platedHoleGeoms.length}));const e=IIA(g,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(e)}else if(g.shape==="pill"||g.shape==="oval"){const I=g.hole_height>g.hole_width,e=I?g.hole_height:g.hole_width,t=I?g.hole_width:g.hole_height,B=t/2,o=Math.abs(e-t);let C;if(C=(0,Pw.union)((0,rr.cuboid)({center:[g.x,g.y,0],size:I?[t,o,this.ctx.pcbThickness*1.5]:[o,t,this.ctx.pcbThickness*1.5]}),(0,rr.cylinder)({center:I?[g.x,g.y-o/2,0]:[g.x-o/2,g.y,0],radius:B,height:this.ctx.pcbThickness*1.5}),(0,rr.cylinder)({center:I?[g.x,g.y+o/2,0]:[g.x+o/2,g.y,0],radius:B,height:this.ctx.pcbThickness*1.5})),g.ccw_rotation){const i=g.ccw_rotation*Math.PI/180;C=(0,Ck.translate)([g.x,g.y,0],(0,Ck.rotateZ)(i,(0,Ck.translate)([-g.x,-g.y,0],C)))}A.dontCutBoard||(this.boardGeom=(0,Pw.subtract)(this.boardGeom,C),this.copperDrills.push({geom:C,platedHoleIndex:this.platedHoleGeoms.length}));const Q=IIA(g,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(Q)}else if(g.shape==="pill_hole_with_rect_pad"){if(g.hole_shape&&g.hole_shape!=="pill"||g.pad_shape&&g.pad_shape!=="rect")return;const I=g.hole_height>g.hole_width,e=I?g.hole_height:g.hole_width,t=I?g.hole_width:g.hole_height,B=t/2,o=Math.abs(e-t);let C;C=(0,Pw.union)((0,rr.cuboid)({center:[g.x+(g.hole_offset_x||0),g.y+(g.hole_offset_y||0),0],size:I?[t,o,this.ctx.pcbThickness*1.5]:[o,t,this.ctx.pcbThickness*1.5]}),(0,rr.cylinder)({center:I?[g.x+(g.hole_offset_x||0),g.y+(g.hole_offset_y||0)-o/2,0]:[g.x+(g.hole_offset_x||0)-o/2,g.y+(g.hole_offset_y||0),0],radius:B,height:this.ctx.pcbThickness*1.5}),(0,rr.cylinder)({center:I?[g.x+(g.hole_offset_x||0),g.y+(g.hole_offset_y||0)+o/2,0]:[g.x+(g.hole_offset_x||0)+o/2,g.y+(g.hole_offset_y||0),0],radius:B,height:this.ctx.pcbThickness*1.5})),A.dontCutBoard||(this.boardGeom=(0,Pw.subtract)(this.boardGeom,C),this.copperDrills.push({geom:C,platedHoleIndex:this.platedHoleGeoms.length}));const Q=IIA(g,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(Q)}else if(g.shape==="rotated_pill_hole_with_rect_pad"){if(g.hole_shape&&g.hole_shape!=="rotated_pill"||g.pad_shape&&g.pad_shape!=="rect")return;const I=g.hole_width,e=g.hole_height,t=I>=e,B=t?I:e,o=t?e:I,C=o/2,Q=Math.abs(B-o),i=g.hole_offset_x||0,E=g.hole_offset_y||0;let n=(0,Pw.union)((0,rr.cuboid)({center:[0,0,0],size:t?[Q,o,this.ctx.pcbThickness*1.5]:[o,Q,this.ctx.pcbThickness*1.5]}),(0,rr.cylinder)({center:t?[-Q/2,0,0]:[0,-Q/2,0],radius:C,height:this.ctx.pcbThickness*1.5}),(0,rr.cylinder)({center:t?[Q/2,0,0]:[0,Q/2,0],radius:C,height:this.ctx.pcbThickness*1.5}));const s=(g.hole_ccw_rotation||0)*Math.PI/180,r=i*Math.cos(s)-E*Math.sin(s),a=i*Math.sin(s)+E*Math.cos(s);n=(0,Ck.rotateZ)(s,n);const c=(0,Ck.translate)([g.x+r,g.y+a,0],n);A.dontCutBoard||(this.boardGeom=(0,Pw.subtract)(this.boardGeom,c),this.copperDrills.push({geom:c,platedHoleIndex:this.platedHoleGeoms.length}));const h=IIA(g,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(h)}else if(g.shape==="hole_with_polygon_pad"){const I=g.pad_outline;if(!Array.isArray(I)||I.length<3)return;const e=this.ctx.pcbThickness*1.5,t=LdA(g,e,{sizeDelta:2*Oo}),B=LdA(g,e,{sizeDelta:-2*Oo});if(!t||!B)return;A.dontCutBoard||(this.boardGeom=(0,Pw.subtract)(this.boardGeom,t),this.copperDrills.push({geom:t,platedHoleIndex:this.platedHoleGeoms.length}));const o=IIA(g,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(o)}}}processHole(g){if(!this.boardGeom)return;const A=this.ctx.pcbThickness*1.5;if(g.hole_shape==="circle"){const I=(0,rr.cylinder)({center:[g.x,g.y,0],radius:g.hole_diameter/2+Oo,height:A});this.boardGeom=(0,Pw.subtract)(this.boardGeom,I);const e=(0,rr.cylinder)({center:[g.x,g.y,0],radius:g.hole_diameter/2+Oo/2,height:A});this.copperDrills.push({geom:e})}else if(g.hole_shape==="pill"||g.hole_shape==="rotated_pill"||g.hole_shape==="rect"||g.hole_shape==="oval"){const I=g.hole_width??g.hole_diameter,e=g.hole_height??g.hole_diameter,t=g.ccw_rotation??g.rotation??0,B=.02,o=(i,E,n,s)=>{if(i<=0||E<=0)return null;if(g.hole_shape==="rect")return(0,rr.cuboid)({center:[0,0,0],size:[i,E,n]});if(s)return(0,Ck.translate)([0,0,-n/2],(0,_$A.extrudeLinear)({height:n},(0,rr.ellipse)({radius:[i/2,E/2]})));const r=Math.min(i,E)/2,a=Math.abs(i-E);return i>E?(0,Pw.union)((0,rr.cuboid)({center:[0,0,0],size:[a,E,n]}),(0,rr.cylinder)({center:[-a/2,0,0],radius:r,height:n}),(0,rr.cylinder)({center:[a/2,0,0],radius:r,height:n})):(0,Pw.union)((0,rr.cuboid)({center:[0,0,0],size:[i,a,n]}),(0,rr.cylinder)({center:[0,-a/2,0],radius:r,height:n}),(0,rr.cylinder)({center:[0,a/2,0],radius:r,height:n}))};let C=o(I,e,A,g.hole_shape==="oval"),Q=o(I-2*B,e-2*B,A,g.hole_shape==="oval");if(C&&t!==0&&(C=(0,Ck.rotateZ)(t*Math.PI/180,C)),Q&&t!==0&&(Q=(0,Ck.rotateZ)(t*Math.PI/180,Q)),C){const i=(0,Ck.translate)([g.x,g.y,0],C);this.boardGeom=(0,Pw.subtract)(this.boardGeom,i)}if(Q){const i=(0,Ck.translate)([g.x,g.y,0],Q);this.copperDrills.push({geom:i})}}}processVia(g){if(!this.boardGeom)return;let A;if(typeof g.outer_diameter=="number"&&typeof g.hole_diameter=="number"){const I=tZt({x:g.x,y:g.y,outerDiameter:g.outer_diameter,holeDiameter:g.hole_diameter,thickness:this.ctx.pcbThickness});let e=I;this.boardClipGeom&&(e=(0,Pw.intersect)(this.boardClipGeom,I),e=(0,Y$A.colorize)(jE.copper,e)),A=this.viaGeoms.length,this.viaGeoms.push(e)}if(typeof g.hole_diameter=="number"){const I=BZt({x:g.x,y:g.y,holeDiameter:g.hole_diameter,thickness:this.ctx.pcbThickness});this.boardGeom=(0,Pw.subtract)(this.boardGeom,I),this.copperDrills.push({geom:I,viaIndex:A})}}finalize(){if(!this.boardGeom)return;const g=this.copperDrills.map(e=>({...e,bounds:(0,juI.measureBoundingBox)(e.geom)})),A=(e,t,B)=>{const o=(0,juI.measureBoundingBox)(e),C=g.filter(Q=>Q[B]!==t&&[0,1,2].every(i=>Q.bounds[0][i]<=o[1][i]&&Q.bounds[1][i]>=o[0][i])).map(Q=>Q.geom);return(0,Y$A.colorize)(jE.copper,C.length?(0,Pw.subtract)(e,(0,Pw.union)(...C)):e)};this.platedHoleGeoms=this.platedHoleGeoms.map((e,t)=>A(e,t,"platedHoleIndex")),this.viaGeoms=this.viaGeoms.map((e,t)=>A(e,t,"viaIndex"));const I=L$A(this.board);this.boardGeom=(0,Y$A.colorize)([I.r,I.g,I.b],this.boardGeom),this.finalGeoms=[this.boardGeom,...this.platedHoleGeoms,...this.viaGeoms],this.onCompleteCallback&&this.onCompleteCallback(this.finalGeoms)}getGeoms(){return this.finalGeoms}},iZt=g=>{const[A,I]=gA.useState(null),e=gA.useRef(!1);return gA.useEffect(()=>{let t=!1;if(!g){I(null);return}if(!g.some(i=>i.type==="pcb_board"||i.type==="pcb_panel")){I(null);return}const o=WTt(g);I(o);const C=new QZt(g,i=>{});return(async()=>{if(!e.current){e.current=!0;try{let i=!1;for(;!i&&!t;)i=C.step(1),i||await new Promise(E=>setTimeout(E,0));t||I(C.getGeoms())}catch(i){console.error("Error during board geometry building:",i)}finally{e.current=!1}}})(),()=>{t=!0}},[g]),A},EZt=({children:g,parent:A,position:I,rotation:e,scale:t,color:B,fontSize:o,anchorX:C,anchorY:Q,depthOffset:i})=>{const{rootObject:E}=SD(),n=gA.useMemo(()=>{const s=new YKA;return s.text=g,I&&s.position.fromArray(I),e&&s.rotation.fromArray(e),t&&s.scale.fromArray(t),s.color=B||"white",s.fontSize=o||1,s.anchorX=C||"center",s.anchorY=Q||"middle",s.depthOffset=i||0,s.font=null,s.sync(),s},[g,I,e,t,B,o,C,Q,i]);return gA.useEffect(()=>{const s=A||E;if(!(!s||!n))return s.add(n),()=>{s.remove(n),n.dispose()}},[E,A,n]),null},AGI=({error:g,cad_component:A})=>{const{rootObject:I}=SD(),[e,t]=gA.useState(!1),[B,o]=gA.useState(null),C=gA.useCallback(n=>{n?.mousePosition?(t(!0),o(n.mousePosition)):(t(!1),o(null))},[]),Q=gA.useCallback(()=>{t(!1),o(null)},[]),i=gA.useMemo(()=>A?.position?[A.position.x,A.position.y,A.position.z].map(s=>Number.isNaN(s)?0:s):[0,0,0],[A]),E=gA.useMemo(()=>{const n=new Nc;return n.position.fromArray(i),n},[i]);return E.userData.cad_component_id=A?.cad_component_id,E.userData.pcb_component_id=A?.pcb_component_id,gA.useEffect(()=>{if(I)return I.add(E),()=>{I.remove(E)}},[I,E]),W.jsxs(W.Fragment,{children:[W.jsxs(AIA,{isHovered:e,onHover:C,onUnhover:Q,object:E,children:[W.jsx(nZt,{parent:E}),W.jsx(EZt,{parent:E,scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:`${g.toString().slice(0,50)}...`})]}),e&&B?W.jsx(puI,{position:B,style:{fontFamily:"sans-serif",transform:"translate3d(-1rem, 0rem, 0)",backgroundColor:"white",padding:"6px",borderRadius:"4px",color:"red",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:g.toString()}):null]})},nZt=({parent:g})=>{const A=gA.useMemo(()=>{const I=new FB(new Jp(.5,.5,.5),new Ps({depthTest:!1,transparent:!0,color:"red",opacity:.5}));return I.renderOrder=999999,I.rotation.fromArray([Math.PI/4,Math.PI/4,0]),I},[]);return gA.useEffect(()=>(g.add(A),()=>{g.remove(A)}),[g,A]),null},sZt=g=>{if(g.length===0)return null;let A=g[0].x,I=g[0].y,e=g[0].x,t=g[0].y;for(let B=1;B<g.length;B++){const o=g[B];o.x<A&&(A=o.x),o.y<I&&(I=o.y),o.x>e&&(e=o.x),o.y>t&&(t=o.y)}return{minX:A,minY:I,maxX:e,maxY:t}};function ky(g){if(g.outline&&g.outline.length>=3){const o=sZt(g.outline);return{...o,width:o.maxX-o.minX,height:o.maxY-o.minY,centerX:(o.minX+o.maxX)/2,centerY:(o.minY+o.maxY)/2}}const A=g.width??0,I=g.height??0,e=g.center?.x??0,t=g.center?.y??0;return{...{minX:e-A/2,maxX:e+A/2,minY:t-I/2,maxY:t+I/2},width:A,height:I,centerX:e,centerY:t}}function aZt(g,A,I){const e=v$A(g);if(!e.length)return[];const t=ky(A),B=Math.floor(t.width*I),o=Math.floor(t.height*I);if(B<=0||o<=0)return[];const C=new Set;for(const Q of["top","bottom"]){const i=g.filter(a=>(a.type==="pcb_smtpad"&&a.layer===Q||a.type==="pcb_plated_hole"&&(!Array.isArray(a.layers)||a.layers.includes(Q)))&&a.is_covered_with_solder_mask!==!0);if(!i.length)continue;const E=document.createElement("canvas");E.width=B,E.height=o;const n=E.getContext("2d");if(!n)continue;const s=new VE(n);s.configure({colorOverrides:{copper:{top:"white",bottom:"white",inner1:"white",inner2:"white",inner3:"white",inner4:"white",inner5:"white",inner6:"white",inner7:"white",inner8:"white"},drill:"rgba(0,0,0,0)"}}),s.setCameraBounds(t),s.drawElements(i,{layers:[Q==="top"?"top_copper":"bottom_copper"],drawSoldermask:!1});const r=n.getImageData(0,0,B,o).data;for(const a of e){if(C.has(a)||!a.layers.includes(Q))continue;const c=a.outer_diameter/2,h=(a.x-t.minX)*B/t.width,l=(t.maxY-a.y)*o/t.height,D=c*B/t.width,d=c*o/t.height;if(D<=0||d<=0)continue;const y=Math.max(0,Math.floor(h-D)),w=Math.min(B-1,Math.ceil(h+D)),u=Math.max(0,Math.floor(l-d)),G=Math.min(o-1,Math.ceil(l+d));let m=!1;for(let p=u;p<=G&&!m;p++)for(let k=y;k<=w;k++)if(r[(p*B+k)*4+3]>=128&&((k+.5-h)/D)**2+((p+.5-l)/d)**2<=1){m=!0;break}m&&C.add(a)}}return[...C]}function rZt({ctx:g,vias:A,boardData:I,layer:e,width:t,height:B}){if(!A.length)return;const o=ky(I);g.save(),g.globalCompositeOperation="destination-out",g.fillStyle="black";for(const C of A){if(!C.layers.includes(e))continue;const Q=(C.x-o.minX)*t/o.width,i=(e==="top"?o.maxY-C.y:C.y-o.minY)*B/o.height;g.beginPath(),g.ellipse(Q,i,C.hole_diameter/2*t/o.width,C.hole_diameter/2*B/o.height,0,0,Math.PI*2),g.fill()}g.restore()}function cZt({layer:g,circuitJson:A,boardData:I,copperColor:e,traceTextureResolution:t}){const o=jB(A).pcb_smtpad.list().filter(w=>w.layer===g);if(o.length===0)return null;const C=jB(A).pcb_hole.list(),Q=jB(A).pcb_plated_hole.list().filter(w=>!Array.isArray(w.layers)||w.layers.includes(g)),i=jB(A).pcb_via.list().filter(w=>!Array.isArray(w.layers)||w.layers.includes(g)),E=jB(A).pcb_cutout.list(),n=[...C,...Q,...i],s=g==="top"?"top_copper":"bottom_copper",r=ky(I),a=document.createElement("canvas"),c=Math.floor(r.width*t),h=Math.floor(r.height*t);a.width=c,a.height=h;const l=a.getContext("2d");if(!l)return null;g==="bottom"&&(l.translate(0,h),l.scale(1,-1));const D="rgba(0,0,0,0)",d=new VE(l);d.configure({colorOverrides:{copper:{top:e,bottom:e,inner1:e,inner2:e,inner3:e,inner4:e,inner5:e,inner6:e,inner7:e,inner8:e},copperPour:{top:D,bottom:D},drill:D,boardOutline:D,substrate:D,keepout:{top:D,bottom:D},fabricationNote:D,courtyard:{top:D,bottom:D},silkscreen:{top:D,bottom:D},soldermask:{top:D,bottom:D},soldermaskWithCopperUnderneath:{top:D,bottom:D},soldermaskOverCopper:{top:D,bottom:D}}}),d.setCameraBounds({minX:r.minX,maxX:r.maxX,minY:r.minY,maxY:r.maxY}),d.drawElements([...o,...n,...E],{layers:[s],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});const y=new Kp(a);return y.generateMipmaps=!0,y.minFilter=wl,y.magFilter=Un,y.anisotropy=16,y.needsUpdate=!0,y}var hZt=g=>{const A=g.filter(I=>I.type==="pcb_panel");return A.length===0?null:A.length===1?A[0].pcb_panel_id:null};function lZt({layer:g,circuitJson:A,panelData:I,outlineColor:e="black",traceTextureResolution:t}){const B=hZt(A);if(!B)return null;const C=jB(A).pcb_board.list().filter(c=>c.pcb_panel_id===B||c.position_mode==="relative_to_panel_anchor"&&!c.pcb_panel_id);if(C.length===0)return null;const Q=document.createElement("canvas"),i=Math.floor(I.width*t),E=Math.floor(I.height*t);Q.width=i,Q.height=E;const n=Q.getContext("2d");if(!n)return null;g==="bottom"&&(n.translate(0,E),n.scale(1,-1)),n.strokeStyle=e,n.lineWidth=.05*t;const s=c=>(c-I.center.x+I.width/2)*t,r=c=>(-(c-I.center.y)+I.height/2)*t;C.forEach(c=>{if(c.outline&&c.outline.length>=2)n.beginPath(),c.outline.forEach((h,l)=>{const D=s(h.x),d=r(h.y);l===0?n.moveTo(D,d):n.lineTo(D,d)}),n.closePath(),n.stroke();else{const h=c.width,l=c.height,{x:D,y:d}=c.center,y=s(D-h/2),w=r(d+l/2);n.strokeRect(y,w,h*t,l*t)}});const a=new Kp(Q);return a.generateMipmaps=!0,a.minFilter=wl,a.magFilter=Un,a.anisotropy=16,a.needsUpdate=!0,a}function DZt({layer:g,circuitJson:A,boardData:I,traceColor:e,traceTextureResolution:t}){const B=jB(A).pcb_trace.list(),o=jB(A).pcb_via.list(),C=jB(A).pcb_plated_hole.list(),Q=g==="top"?"top_copper":"bottom_copper",i=B.filter(y=>Xpg(y).includes(Q));if(i.length===0)return null;const E=C.filter(y=>y.layers.includes(g)),n=[...i,...o,...E],s=ky(I),r=document.createElement("canvas"),a=Math.floor(s.width*t),c=Math.floor(s.height*t);r.width=a,r.height=c;const h=r.getContext("2d");if(!h)return null;g==="bottom"&&(h.translate(0,c),h.scale(1,-1));const l="rgba(0,0,0,0)",D=new VE(h);D.configure({colorOverrides:{copper:{top:e,bottom:e,inner1:e,inner2:e,inner3:e,inner4:e,inner5:e,inner6:e,inner7:e,inner8:e},copperPour:{top:l,bottom:l},drill:l,boardOutline:l,substrate:l,keepout:{top:l,bottom:l},fabricationNote:l,courtyard:{top:l,bottom:l},silkscreen:{top:l,bottom:l},soldermask:{top:l,bottom:l},soldermaskWithCopperUnderneath:{top:l,bottom:l},soldermaskOverCopper:{top:l,bottom:l}}}),D.setCameraBounds({minX:s.minX,maxX:s.maxX,minY:s.minY,maxY:s.maxY}),D.drawElements(n,{layers:[Q],clipContextElements:A,drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});const d=new Kp(r);return d.generateMipmaps=!0,d.minFilter=wl,d.magFilter=Un,d.anisotropy=16,d.needsUpdate=!0,d}var dZt=g=>{const[A=0,I=0,e=0]=g;return`rgb(${Math.round(A*255)}, ${Math.round(I*255)}, ${Math.round(e*255)})`},yZt=8;function gGI({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=K2,copperColor:t=dZt(jE.copper),onlyCoveredBySoldermask:B=!1}){const o=A.filter(p=>p.type==="pcb_copper_pour"),C=g==="top"?"top_copper":"bottom_copper",Q=o.filter(p=>p.layer===g&&(!B||p.covered_with_solder_mask!==!1));if(Q.length===0)return null;const i=A.filter(p=>p.type==="pcb_hole"),E=A.filter(p=>p.type!=="pcb_plated_hole"?!1:!Array.isArray(p.layers)||p.layers.includes(g)),n=A.filter(p=>p.type!=="pcb_via"?!1:!Array.isArray(p.layers)||p.layers.includes(g)),s=[...i,...E,...n],r=ky(I),a=document.createElement("canvas"),c=Math.floor(r.width*e),h=Math.floor(r.height*e);a.width=c,a.height=h;const l=a.getContext("2d");if(!l)return null;g==="bottom"&&(l.translate(0,h),l.scale(1,-1));const D="rgba(0,0,0,0)",d=t,y=t,w=(p,k)=>{if(p.length===0)return;const S=[...p,...s],R=new VE(l);R.configure({colorOverrides:{copper:{top:k,bottom:k,inner1:k,inner2:k,inner3:k,inner4:k,inner5:k,inner6:k,inner7:k,inner8:k},copperPour:{top:D,bottom:D},drill:D,boardOutline:D,substrate:D,keepout:{top:D,bottom:D},fabricationNote:D,courtyard:{top:D,bottom:D},silkscreen:{top:D,bottom:D},soldermask:{top:D,bottom:D},soldermaskWithCopperUnderneath:{top:D,bottom:D},soldermaskOverCopper:{top:D,bottom:D}}}),R.setCameraBounds({minX:r.minX,maxX:r.maxX,minY:r.minY,maxY:r.maxY}),R.drawElements(S,{layers:[C],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});for(let F=1;F<yZt;F+=1)R.drawElements(S,{layers:[C],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1})},u=Q.filter(p=>p.covered_with_solder_mask!==!1),G=Q.filter(p=>p.covered_with_solder_mask===!1);w(u,d),B||w(G,y);const m=new Kp(a);return m.generateMipmaps=!0,m.minFilter=wl,m.magFilter=Un,m.anisotropy=16,m.needsUpdate=!0,m}var IGI=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},wZt=({ctx:g,layer:A,bounds:I,elements:e,copperColor:t})=>{const B=A==="top"?"top_copper":"bottom_copper",o=new VE(g);o.configure({colorOverrides:{copper:{top:t,bottom:t,inner1:t,inner2:t,inner3:t,inner4:t,inner5:t,inner6:t,inner7:t,inner8:t}}}),IGI(o,I),o.drawElements(e,{layers:[B]});const C=e.filter(n=>n.type==="pcb_copper_text"&&n.is_knockout===!0);if(C.length===0)return;const Q=document.createElement("canvas");Q.width=g.canvas.width,Q.height=g.canvas.height;const i=Q.getContext("2d");if(!i)return;const E=new VE(i);E.configure({colorOverrides:{copper:{top:"rgb(255,255,255)",bottom:"rgb(255,255,255)",inner1:"rgb(255,255,255)",inner2:"rgb(255,255,255)",inner3:"rgb(255,255,255)",inner4:"rgb(255,255,255)",inner5:"rgb(255,255,255)",inner6:"rgb(255,255,255)",inner7:"rgb(255,255,255)",inner8:"rgb(255,255,255)"}}}),IGI(E,I),E.drawElements(C.map(n=>({...n,is_knockout:!1})),{layers:[B]}),g.save(),g.globalCompositeOperation="destination-out",g.drawImage(Q,0,0),g.restore()};function uZt({layer:g,circuitJson:A,boardData:I,copperColor:e="rgb(230, 153, 51)",traceTextureResolution:t=K2}){const B=A.filter(s=>s.type==="pcb_copper_text"&&"layer"in s&&s.layer===g);if(B.length===0)return null;const o=ky(I),C=Math.floor(o.width*t),Q=Math.floor(o.height*t);if(C<=0||Q<=0)return null;const i=document.createElement("canvas");i.width=C,i.height=Q;const E=i.getContext("2d");if(!E)return null;g==="bottom"&&(E.translate(0,Q),E.scale(1,-1)),wZt({ctx:E,layer:g,bounds:o,elements:B,copperColor:e});const n=new Kp(i);return n.generateMipmaps=!0,n.minFilter=wl,n.magFilter=Un,n.anisotropy=16,n.needsUpdate=!0,n}var eGI=25.4,GZt=eGI/1e3,mZt=/^\s*(-?\d*(?:\.\d+)?)(?:\s*(mm|mil|inch|in|"))?\s*$/i;function pZt(g){if(!g)return;const A=g.trim().toLowerCase();return A==='"'||A==="inch"?"in":A}function _dA(g){if(g==null)return;if(typeof g=="number")return Number.isFinite(g)?g:void 0;if(typeof g!="string")return;const A=g.trim();if(A.length===0)return;const I=A.match(mZt);if(!I){const C=Number.parseFloat(A);return Number.isFinite(C)?C:void 0}const[,e,t]=I,B=Number.parseFloat(e||"0");if(!Number.isFinite(B))return;switch(pZt(t)){case"mil":return B*GZt;case"in":return B*eGI;case"mm":case void 0:return B;default:return B}}function vs(g,A){const I=_dA(g);return I===void 0?A:I}var kZt="rgb(255,243,204)",cr="rgba(0,0,0,0)",MZt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},SZt=g=>g.type==="pcb_fabrication_note_rect"?{...g,width:_dA(g.width)??0,height:_dA(g.height)??0,stroke_width:vs(g.stroke_width,.1),corner_radius:_dA(g.corner_radius)}:g.type==="pcb_fabrication_note_path"?{...g,stroke_width:vs(g.stroke_width,.1)}:g.type==="pcb_fabrication_note_text"?{...g,font_size:vs(g.font_size,1)}:g.type==="pcb_fabrication_note_dimension"?{...g,font_size:vs(g.font_size,1),arrow_size:vs(g.arrow_size,1),offset_distance:vs(g.offset_distance,0)}:g,fZt=({ctx:g,layer:A,bounds:I,elements:e})=>{const t=`${A}_fabrication_note`,B=e.map(SZt),o=new VE(g);o.configure({colorOverrides:{copper:{top:cr,bottom:cr,inner1:cr,inner2:cr,inner3:cr,inner4:cr,inner5:cr,inner6:cr,inner7:cr,inner8:cr},copperPour:{top:cr,bottom:cr},drill:cr,boardOutline:cr,substrate:cr,keepout:{top:cr,bottom:cr},courtyard:{top:cr,bottom:cr},soldermask:{top:cr,bottom:cr},soldermaskWithCopperUnderneath:{top:cr,bottom:cr},soldermaskOverCopper:{top:cr,bottom:cr},silkscreen:{top:cr,bottom:cr},fabricationNote:kZt}}),MZt(o,I),o.drawElements(B,{layers:[t]})},RZt=g=>({minX:g.center.x-g.width/2,maxX:g.center.x+g.width/2,minY:g.center.y-g.height/2,maxY:g.center.y+g.height/2,width:g.width,height:g.height,centerX:g.center.x,centerY:g.center.y}),NZt=(g,A)=>{const I=Math.min(g.minX,A.minX),e=Math.max(g.maxX,A.maxX),t=Math.min(g.minY,A.minY),B=Math.max(g.maxY,A.maxY);return{minX:I,maxX:e,minY:t,maxY:B,width:e-I,height:B-t,centerX:(I+e)/2,centerY:(t+B)/2}},bdA=(g,A)=>{const I=g.filter(o=>o.type==="pcb_panel"),e=g.filter(o=>o.type==="pcb_board"),t=I.find(o=>o.pcb_panel_id===A.pcb_board_id)??I[0];return t&&t.width>0&&t.height>0?RZt(t):(e.length>1?e:[A]).map(o=>ky(o)).reduce((o,C)=>NZt(o,C))},xZt=(g,A)=>{if(!("layer"in g)||g.layer!==A)return!1;const I=g.type;return I.startsWith("pcb_fabrication_note_")&&I!=="pcb_fabrication_note_text"&&I!=="pcb_fabrication_note_dimension"};function FZt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=K2}){const t=A.filter(n=>xZt(n,g));if(t.length===0)return null;const B=bdA(A,I),o=Math.floor(B.width*e),C=Math.floor(B.height*e);if(o<=0||C<=0)return null;const Q=document.createElement("canvas");Q.width=o,Q.height=C;const i=Q.getContext("2d");if(!i)return null;g==="bottom"&&(i.translate(0,C),i.scale(1,-1)),fZt({ctx:i,layer:g,bounds:B,elements:t});const E=new Kp(Q);return E.generateMipmaps=!0,E.minFilter=wl,E.magFilter=Un,E.anisotropy=16,E.needsUpdate=!0,E}var UZt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},JZt=({ctx:g,layer:A,bounds:I,elements:e,keepoutColor:t})=>{const B=A==="top"?"top_copper":"bottom_copper",o=new VE(g);o.configure({colorOverrides:{keepout:{top:t,bottom:t}}}),UZt(o,I),o.drawElements(e,{layers:[B],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1})},KZt=(g,A)=>g.type!=="pcb_keepout"?!1:!("layers"in g)||!Array.isArray(g.layers)?!0:g.layers.includes(A);function PZt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=K2,keepoutColor:t=g==="bottom"?"#4b72d2":"#d24b4b"}){const B=A.filter(s=>KZt(s,g));if(B.length===0)return null;const o=ky(I),C=Math.floor(o.width*e),Q=Math.floor(o.height*e);if(C<=0||Q<=0)return null;const i=document.createElement("canvas");i.width=C,i.height=Q;const E=i.getContext("2d");if(!E)return null;g==="bottom"&&(E.translate(0,Q),E.scale(1,-1)),JZt({ctx:E,layer:g,bounds:o,elements:B,keepoutColor:t});const n=new Kp(i);return n.generateMipmaps=!0,n.minFilter=wl,n.magFilter=Un,n.anisotropy=16,n.needsUpdate=!0,n}var ba="rgba(0,0,0,0)",LZt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},YZt=g=>g.type==="pcb_note_line"?{...g,x1:vs(g.x1,0),y1:vs(g.y1,0),x2:vs(g.x2,0),y2:vs(g.y2,0),stroke_width:vs(g.stroke_width,.1)}:g.type==="pcb_note_rect"?{...g,center:{x:vs(g.center.x,0),y:vs(g.center.y,0)},width:vs(g.width,0),height:vs(g.height,0),stroke_width:vs(g.stroke_width,.1),corner_radius:vs(g.corner_radius,0)}:g.type==="pcb_note_text"?{...g,anchor_position:{x:vs(g.anchor_position.x,0),y:vs(g.anchor_position.y,0)},font_size:vs(g.font_size,1)}:g.type==="pcb_note_path"?{...g,route:g.route.map(A=>({...A,x:vs(A.x,0),y:vs(A.y,0)})),stroke_width:vs(g.stroke_width,.1)}:g.type==="pcb_note_dimension"?{...g,from:{x:vs(g.from.x,0),y:vs(g.from.y,0)},to:{x:vs(g.to.x,0),y:vs(g.to.y,0)},font_size:vs(g.font_size,1),arrow_size:vs(g.arrow_size,1),offset_distance:vs(g.offset_distance,0)}:g,_Zt=({ctx:g,bounds:A,elements:I})=>{const e=I.map(YZt),t=new VE(g);t.configure({colorOverrides:{copper:{top:ba,bottom:ba,inner1:ba,inner2:ba,inner3:ba,inner4:ba,inner5:ba,inner6:ba,inner7:ba,inner8:ba},copperPour:{top:ba,bottom:ba},drill:ba,boardOutline:ba,substrate:ba,keepout:{top:ba,bottom:ba},courtyard:{top:ba,bottom:ba},soldermask:{top:ba,bottom:ba},soldermaskWithCopperUnderneath:{top:ba,bottom:ba},soldermaskOverCopper:{top:ba,bottom:ba},silkscreen:{top:ba,bottom:ba},fabricationNote:ba}}),LZt(t,A),t.drawElements(e)},bZt=(g,A)=>{if(!("layer"in g)||g.layer!==A)return!1;const I=g.type;return I.startsWith("pcb_note_")&&I!=="pcb_note_dimension"};function HZt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=K2}){const t=A.filter(n=>bZt(n,g));if(t.length===0)return null;const B=bdA(A,I),o=Math.floor(B.width*e),C=Math.floor(B.height*e);if(o<=0||C<=0)return null;const Q=document.createElement("canvas");Q.width=o,Q.height=C;const i=Q.getContext("2d");if(!i)return null;g==="bottom"&&(i.translate(0,C),i.scale(1,-1)),_Zt({ctx:i,bounds:B,elements:t});const E=new Kp(Q);return E.generateMipmaps=!0,E.minFilter=wl,E.magFilter=Un,E.anisotropy=16,E.needsUpdate=!0,E}var vZt="rgb(255,243,204)",_c="rgba(0,0,0,0)",tGI=(g,A,I)=>{const e=A==="top"?g.tented_on_top:g.tented_on_bottom,t="is_tented"in g?g.is_tented:void 0,B=A==="top"?I?.default_via_tented_on_top:I?.default_via_tented_on_bottom;return e??t??B??!1},qZt=(g,A,I,e)=>g.type==="pcb_cutout"?!0:g.type==="pcb_via"?!e||!tGI(g,A,I):g.type==="pcb_hole"||g.type==="pcb_plated_hole"?!e||g.is_covered_with_solder_mask!==!0:!1,TZt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},ZZt=({ctx:g,layer:A,bounds:I,elements:e,circuitJson:t,silkscreenColor:B,soldermaskVisible:o})=>{const C=A==="top"?"top_silkscreen":"bottom_silkscreen",Q=new VE(g);Q.configure({colorOverrides:{copper:{top:_c,bottom:_c,inner1:_c,inner2:_c,inner3:_c,inner4:_c,inner5:_c,inner6:_c,inner7:_c,inner8:_c},copperPour:{top:_c,bottom:_c},drill:_c,boardOutline:_c,substrate:_c,keepout:{top:_c,bottom:_c},courtyard:{top:_c,bottom:_c},soldermask:{top:_c,bottom:_c},soldermaskWithCopperUnderneath:{top:_c,bottom:_c},soldermaskOverCopper:{top:_c,bottom:_c},silkscreen:{top:B,bottom:B},fabricationNote:vZt}}),TZt(Q,I),Q.drawElements(e,{layers:[C],clipContextElements:t});const i=t.flatMap(E=>{if(E.type==="pcb_trace"){const s=g.boardOwnerMap?.get(E.pcb_trace_id),r=E.route.filter(a=>a.route_type==="via"&&(!o||!tGI(a,A,s)));return r.length?[{...E,route:r}]:[]}const n=E.type==="pcb_via"?g.boardOwnerMap?.get(E.pcb_via_id):void 0;return qZt(E,A,n,o)?[E]:[]});Q.drawElements(i,{layers:[C],clipContextElements:t,clearDrillHoles:!0})},OZt=(g,A)=>!("layer"in g)||g.layer!==A?!1:g.type.startsWith("pcb_silkscreen_");function WZt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=K2,silkscreenColor:t="rgb(255,255,255)",soldermaskVisible:B=!0}){const o=A.filter(r=>OZt(r,g));if(o.length===0)return null;const C=bdA(A,I),Q=Math.floor(C.width*e),i=Math.floor(C.height*e);if(Q<=0||i<=0)return null;const E=document.createElement("canvas");E.width=Q,E.height=i;const n=E.getContext("2d");if(!n)return null;g==="bottom"&&(n.translate(0,i),n.scale(1,-1)),ZZt({ctx:n,layer:g,bounds:C,elements:o,circuitJson:A,silkscreenColor:t,soldermaskVisible:B});const s=new Kp(E);return s.generateMipmaps=!0,s.minFilter=wl,s.magFilter=Un,s.anisotropy=16,s.needsUpdate=!0,s}var eIA=g=>{const[A=0,I=0,e=0]=g;return`rgb(${Math.round(A*255)}, ${Math.round(I*255)}, ${Math.round(e*255)})`},VZt=g=>{const A=eIA(KTt[g.material]??jE.fr4SolderMaskGreen),I=g.material==="fr1"?eIA(jE.fr1TracesWithMaskCopper):eIA(jE.fr4TracesWithMaskGreen),e=WuI(g.solder_mask_color);if(!e)return{soldermask:A,soldermaskOverCopper:I,copper:eIA(jE.copper),transparent:"rgba(0,0,0,0)"};const t=new tB().setRGB(jE.copper[0],jE.copper[1],jE.copper[2],Fp);return{soldermask:VuI(e),soldermaskOverCopper:VuI(ZTt({soldermaskColor:e,copperColor:t,soldermaskOpacity:qTt(g.solder_mask_color)})),copper:eIA(jE.copper),transparent:"rgba(0,0,0,0)"}},BGI=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},jZt=g=>g.type.startsWith("pcb_note_")||g.type.startsWith("pcb_fabrication_note_"),zZt=({ctx:g,layer:A,bounds:I,elements:e,boardData:t})=>{const B=VZt(t),o=A==="top"?"top_copper":"bottom_copper",C=new VE(g);C.configure({colorOverrides:{copper:{top:B.transparent,bottom:B.transparent,inner1:B.transparent,inner2:B.transparent,inner3:B.transparent,inner4:B.transparent,inner5:B.transparent,inner6:B.transparent,inner7:B.transparent,inner8:B.transparent},drill:B.transparent,boardOutline:B.transparent,substrate:B.transparent,keepout:{top:B.transparent,bottom:B.transparent},fabricationNote:B.transparent,silkscreen:{top:B.transparent,bottom:B.transparent},courtyard:{top:B.transparent,bottom:B.transparent},soldermask:{top:B.soldermask,bottom:B.soldermask},soldermaskWithCopperUnderneath:{top:B.soldermaskOverCopper,bottom:B.soldermaskOverCopper},soldermaskOverCopper:{top:B.soldermaskOverCopper,bottom:B.soldermaskOverCopper}}}),BGI(C,I);const Q=e.filter(E=>E.type!=="pcb_keepout"&&!jZt(E));C.drawElements(Q,{layers:[o],drawSoldermask:!0,drawSoldermaskTop:A==="top",drawSoldermaskBottom:A==="bottom"});const i=Q.filter(E=>E.type==="pcb_copper_pour"&&E.layer===A&&E.covered_with_solder_mask===!1);if(i.length>0){g.save(),g.globalCompositeOperation="destination-out";const E=new VE(g);E.configure({colorOverrides:{copper:{top:B.copper,bottom:B.copper,inner1:B.copper,inner2:B.copper,inner3:B.copper,inner4:B.copper,inner5:B.copper,inner6:B.copper,inner7:B.copper,inner8:B.copper}}}),BGI(E,I),E.drawElements(i,{layers:[o]}),g.restore()}};function XZt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=K2}){const t=bdA(A,I),B=Math.floor(t.width*e),o=Math.floor(t.height*e);if(B<=0||o<=0)return null;const C=document.createElement("canvas");C.width=B,C.height=o;const Q=C.getContext("2d");if(!Q)return null;g==="bottom"&&(Q.translate(0,o),Q.scale(1,-1));const i=A.some(n=>n.type==="pcb_board")?A:[I,...A];zZt({ctx:Q,layer:g,bounds:t,elements:i,boardData:I});const E=new Kp(C);return E.generateMipmaps=!0,E.minFilter=wl,E.magFilter=Un,E.anisotropy=16,E.needsUpdate=!0,E}var $Zt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},AOt=({ctx:g,layer:A,bounds:I,elements:e,copperColor:t})=>{const B=A==="top"?"top_copper":"bottom_copper",o="rgba(0,0,0,0)",C=new VE(g);C.configure({colorOverrides:{copper:{top:t,bottom:t,inner1:t,inner2:t,inner3:t,inner4:t,inner5:t,inner6:t,inner7:t,inner8:t},drill:o,boardOutline:o,substrate:o,keepout:{top:o,bottom:o},fabricationNote:o,silkscreen:{top:o,bottom:o},courtyard:{top:o,bottom:o},soldermask:{top:o,bottom:o},soldermaskWithCopperUnderneath:{top:o,bottom:o},soldermaskOverCopper:{top:o,bottom:o}}}),$Zt(C,I),C.drawElements(e,{layers:[B]})};function gOt({layer:g,circuitJson:A,boardData:I,copperColor:e="rgb(230, 153, 51)",traceTextureResolution:t=K2}){const B=A.filter(s=>{if(s.type==="pcb_via")return!0;if(s.type!=="pcb_plated_hole")return!1;const r=s;return!Array.isArray(r.layers)||r.layers.includes(g)});if(B.length===0)return null;const o=ky(I),C=Math.floor(o.width*t),Q=Math.floor(o.height*t);if(C<=0||Q<=0)return null;const i=document.createElement("canvas");i.width=C,i.height=Q;const E=i.getContext("2d");if(!E)return null;g==="bottom"&&(E.translate(0,Q),E.scale(1,-1)),AOt({ctx:E,layer:g,bounds:o,elements:B,copperColor:e});const n=new Kp(i);return n.generateMipmaps=!0,n.minFilter=wl,n.magFilter=Un,n.anisotropy=16,n.needsUpdate=!0,n}var oGI=g=>{const[A=0,I=0,e=0]=g;return`rgb(${Math.round(A*255)}, ${Math.round(I*255)}, ${Math.round(e*255)})`},T$A=g=>Math.max(0,Math.min(255,g)),IOt=(g,A,I,e={})=>{const t=g.getImageData(0,0,A,I),B=t.data,o=Math.max(A-1,1),C=Math.max(I-1,1);for(let Q=0;Q<B.length;Q+=4){if((B[Q+3]??0)<16)continue;const E=B[Q]??0,n=B[Q+1]??0,s=B[Q+2]??0,r=.2126*E+.7152*n+.0722*s;if(!(n>E*1.35&&n>s*1.15&&r<90&&E<80&&s<80))continue;const c=Q/4,h=c%A,l=Math.floor(c/A),D=h/o,d=l/C,y=D*.62+(1-d)*.38,w=Math.sin((D*1.15+d*.35)*Math.PI)*.04,u=.74+y*.18+w,G=e.includeReflection?(()=>{const F=D-.36,N=d-.22,U=Math.max(0,1-Math.hypot(F,N)/.38);return U*U*.07})():0,m=(E*.9+3)*u,p=(n*1.08+15)*u,k=(s*1.28+13)*u;B[Q]=T$A(m*(1-G)+255*G),B[Q+1]=T$A(p*(1-G)+255*G),B[Q+2]=T$A(k*(1-G)+255*G)}g.putImageData(t,0,0)},eOt=({textures:g,boardData:A,traceTextureResolution:I,layer:e,openViaHoles:t})=>{if(!g.some(s=>s?.image))return null;const o=ky(A),C=Math.floor(o.width*I),Q=Math.floor(o.height*I);if(C<=0||Q<=0)return null;const i=document.createElement("canvas");i.width=C,i.height=Q+1;const E=i.getContext("2d");if(!E)return null;for(const s of g){if(!s?.image)continue;const r=s.image;E.drawImage(r,0,0,C,Q)}rZt({ctx:E,vias:t,boardData:A,layer:e,width:C,height:Q}),IOt(E,C,Q,{includeReflection:e==="top"});const n=new Kp(i);return n.generateMipmaps=!1,n.minFilter=Un,n.magFilter=Un,n.premultiplyAlpha=!0,n.anisotropy=16,n.needsUpdate=!0,n},tOt=({textures:g,soldermaskTexture:A,boardData:I,traceTextureResolution:e})=>{if(!A?.image||!g.some(E=>E?.image))return null;const t=ky(I),B=Math.floor(t.width*e),o=Math.floor(t.height*e);if(B<=0||o<=0)return null;const C=document.createElement("canvas");C.width=B,C.height=o+1;const Q=C.getContext("2d");if(!Q)return null;for(const E of g)E?.image&&Q.drawImage(E.image,0,0,B,o);Q.globalCompositeOperation="destination-in",Q.drawImage(A.image,0,0,B,o),Q.globalCompositeOperation="source-over";const i=new Kp(C);return i.colorSpace=JN,i.generateMipmaps=!1,i.minFilter=Un,i.magFilter=Un,i.premultiplyAlpha=!1,i.needsUpdate=!0,i};function CGI({circuitJson:g,boardData:A,traceTextureResolution:I,visibility:e}){const t=oGI(jE.copper),B="rgb(255,255,255)",o=oGI(jE.copper),C=e?.boardBody??!0,Q=aZt(g,A,I),i=r=>{const a=(r==="top"?e?.topMask:e?.bottomMask)??!0,c=(r==="top"?e?.topCopper:e?.bottomCopper)??!0,h=(r==="top"?e?.topSilkscreen:e?.bottomSilkscreen)??!0,l=e?.keepout??!0,D=a?XZt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,d=c?DZt({layer:r,circuitJson:g,boardData:A,traceColor:t,traceTextureResolution:I}):null,y=c?gGI({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I,copperColor:o}):null,w=a&&c?gGI({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I,copperColor:o,onlyCoveredBySoldermask:!0}):null,u=c?uZt({layer:r,circuitJson:g,boardData:A,copperColor:o,traceTextureResolution:I}):null,G=c?cZt({layer:r,circuitJson:g,boardData:A,copperColor:o,traceTextureResolution:I}):null,m=c?gOt({layer:r,circuitJson:g,boardData:A,copperColor:o,traceTextureResolution:I}):null,p=h?WZt({layer:r,circuitJson:g,boardData:A,silkscreenColor:B,traceTextureResolution:I,soldermaskVisible:a}):null,k=h?FZt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,R=e?.pcbNotes??!1?HZt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,F=C?lZt({layer:r,circuitJson:g,panelData:A,traceTextureResolution:I}):null,N=l?PZt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,U=eOt({openViaHoles:Q,textures:[y,d,G,m,D,u,p,k,R,F,N],boardData:A,traceTextureResolution:I,layer:r}),P=a&&c?tOt({textures:[d,w],soldermaskTexture:D,boardData:A,traceTextureResolution:I}):null;return{boardTexture:U,maskedCopperTexture:P}},E=A.num_layers??2,n=i("top"),s=E<2?null:i("bottom");return{topBoard:n.boardTexture,bottomBoard:s?.boardTexture??null,topMaskedCopper:n.maskedCopperTexture,bottomMaskedCopper:s?.maskedCopperTexture??null}}var GR={bumpScale:.12,normalScale:.08,roughnessBias:.015,clearcoat:.08,clearcoatRoughness:.55},HdA={roughness:.42,metalness:.5,roughnessVariance:.035,detailStrength:.028},vdA=.22,BOt=.7,oOt=.86,QGI={height:vdA,microSurfaceWeight:1,roughness:.7,metalness:.015,isExposedCopper:!1,isMaskedCopper:!1},COt={height:BOt,microSurfaceWeight:.9,roughness:.54,metalness:.025,isExposedCopper:!1,isMaskedCopper:!0},Z$A=g=>Math.max(0,Math.min(1,g)),iGI=g=>1-g,tIA=(g,A,I)=>{let e=Math.imul(g,374761393)^Math.imul(A,668265263)^I;return e=Math.imul(e^e>>>13,1274126177),((e^e>>>16)>>>0)/4294967295},EGI=g=>g*g*(3-2*g),O$A=(g,A,I)=>g+(A-g)*I,W$A=(g,A,I,e)=>{const t=g/I,B=A/I,o=Math.floor(t),C=Math.floor(B),Q=EGI(t-o),i=EGI(B-C),E=O$A(tIA(o,C,e),tIA(o+1,C,e),Q),n=O$A(tIA(o,C+1,e),tIA(o+1,C+1,e),Q);return O$A(E,n,i)},QOt=(g,A,I)=>{const e=(W$A(g,A,7,I+31)-.5)*.55,t=Math.sin(g*.12+W$A(g,A,44,I+37)*2)*.22;return(e+t)*HdA.detailStrength},iOt=(g,A,I)=>{const e=(tIA(g,A,I+53)-.5)*.42,t=Math.sin(g*.26+A*.06)*.2+Math.sin(A*.31-g*.04)*.12;return(e+t)*.045},EOt=(g,A,I,e)=>e?COt:TTt({red:g,green:A,blue:I})?QGI:g>120&&A>70&&I<150&&g>A*1.05&&A>I*1.15?{height:oOt,microSurfaceWeight:.9,roughness:HdA.roughness,metalness:HdA.metalness,isExposedCopper:!0,isMaskedCopper:!1}:g>170&&A>170&&I>160?{height:vdA,microSurfaceWeight:.4,roughness:.76,metalness:0,isExposedCopper:!1,isMaskedCopper:!1}:A>g*1.25&&A>I*1.05&&g<110&&A<180&&I<130?QGI:{height:vdA,microSurfaceWeight:.7,roughness:.58,metalness:.015,isExposedCopper:!1,isMaskedCopper:!1},qdA=g=>{const A=new Kp(g);return A.colorSpace=JN,A.generateMipmaps=!1,A.minFilter=Un,A.magFilter=Un,A.wrapS=ZG,A.wrapT=ZG,A.needsUpdate=!0,A},nGI=(g,A)=>{const I=g.image;if(!I?.width||!I.height)return null;const{width:e,height:t}=I,B=I.getContext("2d");if(!B)return null;const o=A?.image,C=o?.getContext("2d"),Q=o?.width??0,i=o?.height??0,E=C&&Q&&i?C.getImageData(0,0,Q,i):null,n=B.getImageData(0,0,e,t),s=n.data,r=new Float32Array(e*t),a=document.createElement("canvas"),c=document.createElement("canvas");a.width=c.width=e,a.height=c.height=t;const h=a.getContext("2d"),l=c.getContext("2d");if(!h||!l)return null;const D=h.createImageData(e,t),d=l.createImageData(e,t),y=D.data,w=d.data;for(let F=0;F<s.length;F+=4){const N=F/4,U=N%e,P=Math.floor(N/e);if((s[F+3]??0)<16){r[N]=iGI(vdA);continue}const H=E?Math.min(Q-1,Math.floor(U/e*Q)):0,q=E?Math.min(i-1,Math.floor(P/t*i)):0,j=E?E.data[(q*Q+H)*4+3]??0:0,Z=EOt(s[F]??0,s[F+1]??0,s[F+2]??0,j>=16),O=e+t,AA=Z.isExposedCopper?QOt(U,P,O):Z.isMaskedCopper?iOt(U,P,O):0,tA=Z$A(iGI(Z.height)+AA*Z.microSurfaceWeight);r[N]=tA;const eA=tA*255;s[F]=s[F+1]=s[F+2]=eA,s[F+3]=255;const sA=(Z.isExposedCopper?Z$A(Z.roughness+AA*.7+(W$A(U,P,36,O+17)-.5)*HdA.roughnessVariance):Z.isMaskedCopper?Z$A(Z.roughness+AA+GR.roughnessBias):Z.roughness)*255;y[F]=y[F+1]=y[F+2]=sA,y[F+3]=255;const DA=Z.metalness*255;w[F]=w[F+1]=w[F+2]=DA,w[F+3]=255}h.putImageData(D,0,0),l.putImageData(d,0,0);const u=document.createElement("canvas");u.width=e,u.height=t;const G=u.getContext("2d");if(!G)return null;G.putImageData(n,0,0);const m=document.createElement("canvas");m.width=e,m.height=t;const p=m.getContext("2d");if(!p)return null;const k=p.createImageData(e,t),S=k.data,R=(F,N)=>r[Math.max(0,Math.min(t-1,N))*e+Math.max(0,Math.min(e-1,F))]??0;for(let F=0;F<t;F++)for(let N=0;N<e;N++){const U=(R(N+1,F)-R(N-1,F))*4,P=(R(N,F+1)-R(N,F-1))*4,b=1/Math.sqrt(U*U+P*P+1),H=(F*e+N)*4;S[H]=(-U*b*.5+.5)*255,S[H+1]=(-P*b*.5+.5)*255,S[H+2]=(b*.5+.5)*255,S[H+3]=255}return p.putImageData(k,0,0),{bumpMap:qdA(u),normalMap:qdA(m),roughnessMap:qdA(a),metalnessMap:qdA(c)}};function sGI(g,A){const{texture:I,maskedCopperMask:e,yOffset:t,isBottomLayer:B,usePolygonOffset:o=!1,renderOrder:C=0,isFaux:Q=!1}=g;if(!I)return null;const i=ky(A),E=new Sf(i.width,i.height);I.colorSpace=Fp;const n={map:I,transparent:!0,alphaTest:.08,side:cM,depthWrite:!0,polygonOffset:o,polygonOffsetFactor:o?-4:0,polygonOffsetUnits:o?-4:0,opacity:Q?KdA:1},s=nGI(I,e),r=new dM({...n,bumpMap:s?.bumpMap??null,bumpScale:GR.bumpScale,normalMap:s?.normalMap??null,normalScale:new ct(GR.normalScale,GR.normalScale),roughnessMap:s?.roughnessMap??null,roughness:1,metalnessMap:s?.metalnessMap??null,metalness:1,clearcoat:GR.clearcoat,clearcoatRoughness:GR.clearcoatRoughness,envMapIntensity:.18}),a=new FB(E,r);return a.position.set(i.centerX,i.centerY,t),B&&a.rotation.set(Math.PI,0,0),a.name=`${B?"bottom":"top"}-board-texture-plane`,a.renderOrder=C,ZM(a,{castShadow:!1,receiveShadow:!0}),a}function nOt(g,A,I,e=!1){const t=[];if(!g||!A||I===null)return t;const B=.005,o=sGI({texture:g.topBoard,maskedCopperMask:g.topMaskedCopper,yOffset:I/2+B,isBottomLayer:!1,usePolygonOffset:!0,renderOrder:1,isFaux:e},A);o&&t.push(o);const C=sGI({texture:g.bottomBoard,maskedCopperMask:g.bottomMaskedCopper,yOffset:-I/2-B,isBottomLayer:!0,usePolygonOffset:!0,renderOrder:1,isFaux:e},A);return C&&t.push(C),t}var aGI=g=>{const{boardBody:A,topCopper:I,bottomCopper:e,topSilkscreen:t,bottomSilkscreen:B,topMask:o,bottomMask:C,keepout:Q,pcbNotes:i}=g;return gA.useMemo(()=>({boardBody:A,topCopper:I,bottomCopper:e,topSilkscreen:t,bottomSilkscreen:B,topMask:o,bottomMask:C,keepout:Q,pcbNotes:i}),[A,I,e,t,B,o,C,Q,i])},sOt=4e6,aOt=4096,rOt=1;function rGI(g,A,I={}){const{maxTexturePixels:e=sOt,maxTextureDimension:t=aOt,minTextureResolution:B=rOt}=I,o=ky(g);if(!Number.isFinite(o.width)||!Number.isFinite(o.height)||o.width<=0||o.height<=0)return A;const C=Math.max(o.width,o.height),Q=t/C,i=Math.sqrt(e/(o.width*o.height)),E=Math.min(A,Q,i);return Math.max(B,E)}function cOt({circuitJson:g,pcbThickness:A,isFaux:I=!1}){const{rootObject:e}=SD(),{visibility:t}=e5(),B=aGI(t),o=gA.useMemo(()=>{const i=g.filter(s=>s.type==="pcb_panel"),E=jB(g).pcb_board.list();if(i.length>0){const s=i[0],r=E.find(a=>a.pcb_panel_id===s.pcb_panel_id);return{type:"pcb_board",pcb_board_id:s.pcb_panel_id,center:s.center,width:s.width,height:s.height,thickness:r?.thickness??1.4,material:r?.material??"fr4",num_layers:r?.num_layers??2,solder_mask_color:r?.solder_mask_color}}const n=E.filter(s=>!s.pcb_panel_id);return n.length>0?n[0]:null},[g]),C=gA.useMemo(()=>o?rGI(o,K2):K2,[o]),Q=gA.useMemo(()=>!o?.width||!o.height?null:CGI({circuitJson:g,boardData:o,traceTextureResolution:C,visibility:B}),[g,o,C,B]);return gA.useEffect(()=>{if(!e||!o||!Q)return;const i=[],E=c=>{const h=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],l=c;for(const D of h){const d=l[D];d&&d instanceof Hr&&(d.dispose(),l[D]=null)}c.dispose()},n=({texture:c,maskedCopperMask:h,zOffset:l,isBottomLayer:D,name:d,usePolygonOffset:y=!1,depthWrite:w=!0,renderOrder:u=1})=>{if(!c)return null;const G=ky(o),m=new Sf(G.width,G.height);c.colorSpace=Fp;const p={map:c,transparent:!0,alphaTest:.08,side:cM,depthWrite:w,polygonOffset:y,polygonOffsetFactor:y?-4:0,polygonOffsetUnits:y?-4:0,opacity:I?KdA:1},k=nGI(c,h),S=new dM({...p,bumpMap:k?.bumpMap??null,bumpScale:GR.bumpScale,normalMap:k?.normalMap??null,normalScale:new ct(GR.normalScale,GR.normalScale),roughnessMap:k?.roughnessMap??null,roughness:1,metalnessMap:k?.metalnessMap??null,metalness:1,clearcoat:GR.clearcoat,clearcoatRoughness:GR.clearcoatRoughness,envMapIntensity:.18}),R=new FB(m,S);return R.position.set(G.centerX,G.centerY,l),D&&R.rotation.set(Math.PI,0,0),R.name=d,R.renderOrder=u,R.frustumCulled=!1,ZM(R,{castShadow:!1,receiveShadow:!0}),R},s=.005,r=n({texture:Q.topBoard,maskedCopperMask:Q.topMaskedCopper,zOffset:A/2+s,isBottomLayer:!1,name:"jscad-top-board-texture",usePolygonOffset:!0});r&&(i.push(r),e.add(r));const a=n({texture:Q.bottomBoard,maskedCopperMask:Q.bottomMaskedCopper,zOffset:-A/2-s,isBottomLayer:!0,name:"jscad-bottom-board-texture",usePolygonOffset:!0});return a&&(i.push(a),e.add(a)),()=>{for(const c of i)if(c.parent===e&&e.remove(c),c.geometry.dispose(),Array.isArray(c.material))for(const h of c.material)E(h);else c.material instanceof Up&&E(c.material);Q.topBoard?.dispose(),Q.bottomBoard?.dispose()}},[e,o,Q,A]),null}function hOt({stlUrl:g,stlData:A,mtlUrl:I,color:e,opacity:t=1,layerType:B}){const{rootObject:o}=SD(),[C,Q]=gA.useState(null);gA.useEffect(()=>{const E=new oPt;if(A){try{const n=E.parse(A);Q(n)}catch(n){console.error("Failed to parse STL data",n),Q(null)}return}g&&E.load(g,n=>{Q(n)})},[g,A]);const i=gA.useMemo(()=>{if(!C)return null;const E=B==="board",n=new Ps({color:Array.isArray(e)?new tB(e[0],e[1],e[2]):e,transparent:t!==1,opacity:t,polygonOffset:E,polygonOffsetFactor:E?6:0,polygonOffsetUnits:E?6:0}),s=new FB(C,n);return s.renderOrder=E?-1:1,ZM(s,{castShadow:!E&&t===1,receiveShadow:!0}),s},[C,e,t,B]);return gA.useEffect(()=>{if(!(!o||!i))return o.add(i),()=>{o.remove(i),i.geometry.dispose(),Array.isArray(i.material)?i.material.forEach(E=>E.dispose()):i.material.dispose()}},[o,i]),null}function lOt({stlData:g,color:A,opacity:I=1,layerType:e}){const{visibility:t}=e5();let B=!0;return e==="board"?B=t.boardBody:e==="top-copper"?B=t.topCopper:e==="bottom-copper"?B=t.bottomCopper:e==="top-silkscreen"?B=t.topSilkscreen:e==="bottom-silkscreen"&&(B=t.bottomSilkscreen),B?W.jsx(hOt,{stlData:g,color:A,opacity:I,layerType:e}):null}var DOt=g=>{if(!g||typeof g!="object")return!1;const A=g;return A.type==="cad_cable"&&typeof A.cad_cable_id=="string"&&typeof A.cableprinter_string=="string"&&Array.isArray(A.path)},cGI=g=>g.filter(DOt),dOt=({x:g,y:A,z:I})=>[g,A,I],hGI=({path:g,pin1Position:A,end:I})=>{if(!A||g.length<2)return;const e=I==="start"?g[0]:g[g.length-1],t=I==="start"?g[1]:g[g.length-2];if(!e||!t)return;const B=new oI(t.x-e.x,t.y-e.y,t.z-e.z);if(B.lengthSq()<1e-12)return;B.normalize();const o=new oI(A.x-e.x,A.y-e.y,A.z-e.z);if(o.addScaledVector(B,-o.dot(B)),!(o.lengthSq()<1e-12))return o.normalize(),[o.x,o.y,o.z]},yOt=g=>{const A=YLt(g.cableprinter_string),I=XLt({definition:A,path:g.path.map(dOt),startPin1Side:hGI({path:g.path,pin1Position:g.from_connector_pin1_position,end:"start"}),endPin1Side:hGI({path:g.path,pin1Position:g.to_connector_pin1_position,end:"end"})}),e=new Nc;e.name=`cad-cable-${g.cad_cable_id}`,e.userData={cadCableId:g.cad_cable_id,name:g.name};for(const t of I){let B=new Jn;B.setAttribute("position",new To(t.positions,3)),B.setIndex(t.indices),t.smooth||(B=B.toNonIndexed()),B.computeVertexNormals();const[o,C,Q,i]=t.color,E=new Ps({color:new tB(o,C,Q),metalness:t.material?.metalness??0,roughness:t.material?.roughness??.7,opacity:i,transparent:i<1,side:yl}),n=new FB(B,E);n.name=`${e.name}:${t.name}`,ZM(n,{castShadow:!0,receiveShadow:!0}),e.add(n)}return e},wOt=g=>{g.traverse(A=>{if(!(A instanceof FB))return;A.geometry.dispose();const I=Array.isArray(A.material)?A.material:[A.material];for(const e of I)e.dispose()})},lGI=({cable:g})=>{const{rootObject:A}=SD(),I=gA.useMemo(()=>{try{return yOt(g)}catch(e){return console.error(`Failed to render CAD cable ${g.cad_cable_id}`,e),null}},[g]);return gA.useEffect(()=>{if(I)return A.add(I),()=>{A.remove(I),wOt(I)}},[I,A]),null};function DGI({boardDimensions:g,boardCenter:A}){if(!g||!A)return[5,-5,5];const I=Math.max(g.width??0,1),e=Math.max(g.height??0,1),t=Math.max(I,e,5);return[A.x+t*.4,A.y-t*.7,t*.9]}function uOt(g){const A=jB(g).cad_component.list().filter(D=>D.pcb_component_id),I=jB(g).pcb_smtpad.list(),e=jB(g).pcb_hole.list(),t=jB(g).pcb_plated_hole.list(),B=jB(g).pcb_via.list();if(A.length===0&&I.length===0&&e.length===0&&t.length===0&&B.length===0)return null;const o=[...e,...t,...B,...I],C=xF(o);let Q=C.minX,i=C.maxX,E=C.minY,n=C.maxY;for(const D of A)if(D.position){const d=D.position.x,y=D.position.y;Q=Math.min(Q,d),i=Math.max(i,d),E=Math.min(E,y),n=Math.max(n,y)}Q===1/0&&(Q=-10,i=10,E=-10,n=10);const s=2,r=Math.max(Math.abs(Q),Math.abs(i))+s,a=Math.max(Math.abs(E),Math.abs(n))+s,c=Math.max(2*r,10),h=Math.max(2*a,10);return{type:"pcb_board",pcb_board_id:"faux-board",center:{x:0,y:0},width:c,height:h,thickness:1.4,material:"fr4",num_layers:2}}function dGI(g){if(jB(g).pcb_board.list().length>0)return g;const I=uOt(g);if(!I)return g;const t=I.thickness/2;return[...g.map(o=>{if(o.type==="cad_component"&&o.pcb_component_id){const C=o;if(C.position){const Q=C.position.z??0;return{...C,position:{...C.position,z:Q+t}}}}return o}),I]}var GOt=gA.forwardRef(({circuitJson:g,children:A,autoRotateDisabled:I,clickToInteractEnabled:e,onUserInteraction:t,onCameraControllerReady:B,resolveStaticAsset:o,referenceObject:C,hiddenCadComponentIds:Q},i)=>{const E=p$A(A),n=gA.useMemo(()=>dGI(g??E),[g,E]),s=iZt(n),r=gA.useMemo(()=>{if(!n)return!1;try{const u=jB(n).pcb_board.list()[0];return!!u&&u.pcb_board_id==="faux-board"}catch{return!1}},[n]),a=gA.useMemo(()=>{if(n)try{const u=jB(n).pcb_board.list()[0];if(!u)return;const G=ky(u);return{width:G.width,height:G.height}}catch(u){console.error(u);return}},[n]),c=gA.useMemo(()=>{if(n)try{const u=jB(n).pcb_board.list()[0];if(!u)return;const G=ky(u);return{x:G.centerX,y:G.centerY}}catch(u){console.error(u);return}},[n]),h=gA.useMemo(()=>{if(!n)return;const u=jB(n).pcb_board.list()[0];if(u)return JSON.stringify({pcbBoardId:u.pcb_board_id,center:c,dimensions:a})},[n,c,a]),l=gA.useMemo(()=>DGI({boardDimensions:a,boardCenter:c}),[a,c]),D=muI(n),{stls:d}=STt(s),y=jB(n).cad_component.list().filter(u=>!Q?.has(u.cad_component_id)),w=cGI(n);return W.jsxs(ZuI,{ref:i,autoRotateDisabled:I,initialCameraPosition:l,clickToInteractEnabled:e,boardDimensions:a,boardCenter:c,cameraSessionScope:h,referenceObject:C,onUserInteraction:t,onCameraControllerReady:B,children:[d.map(({stlData:u,color:G,layerType:m},p)=>W.jsx(lOt,{stlData:u,color:G,opacity:p===0?r?.8:.95:1,layerType:m},`board-${p}`)),W.jsx(cOt,{circuitJson:n,pcbThickness:D,isFaux:r}),y.map(u=>W.jsx(N$A,{fallback:({error:G})=>W.jsx(AGI,{cad_component:u,error:G}),children:W.jsx(FuI,{cad_component:u,circuitJson:n,resolveStaticAsset:o},u.cad_component_id)},u.cad_component_id)),w.map(u=>W.jsx(lGI,{cable:u},u.cad_cable_id))]})}),TdA=new Set,V$A=!1;function mOt(g,A,I=2){const e=g.length;TdA.size&&TdA.clear();let t=pOt(g,0,e,I,!0);const B=[];if(!t||t.next===t.prev)return B;let o=0,C=0,Q=0;if(g.length>80*I){o=g[0],C=g[1];let i=o,E=C;for(let n=I;n<e;n+=I){const s=g[n],r=g[n+1];s<o&&(o=s),r<C&&(C=r),s>i&&(i=s),r>E&&(E=r)}Q=Math.max(i-o,E-C),Q=Q!==0?32767/Q:0}return j$A(t,B,o,C,Q),B}function pOt(g,A,I,e,t){let B=null;if(t===KOt(g,A,I,e)>0)for(let o=A;o<I;o+=e)B=wGI(o/e|0,g[o],g[o+1],B);else for(let o=I-e;o>=A;o-=e)B=wGI(o/e|0,g[o],g[o+1],B);return B&&$$A(B,B.next)&&(CIA(B),B=B.next),B}function ZdA(g,A=g){const I=A===g;let e=g,t;do t=!1,e!==e.next&&(TdA.size===0||!TdA.has(e))&&($$A(e,e.next)||My(e.prev,e,e.next)===0)?((I||e===A)&&(A=e.prev),V$A=!0,CIA(e),e=e.prev,t=!0):(I||e!==A)&&(e=e.next,t=!I);while(t||e!==A);return A}function j$A(g,A,I,e,t){t&&ROt(g,I,e,t);let B=g,o=!1;for(;g.prev!==g.next;){const C=g.prev,Q=g.next;if(My(C,g,Q)<0&&(t?MOt(g,I,e,t):kOt(g))){A.push(C.i,g.i,Q.i),CIA(g),g=Q,B=Q;continue}if(g=Q,g===B){if(V$A=!1,g=ZdA(g),V$A){B=g;continue}if(!o){g=SOt(g,A),B=g,o=!0;continue}fOt(g,A,I,e,t);break}}}function kOt(g){const A=g.prev,I=g,e=g.next,t=A.x,B=I.x,o=e.x,C=A.y,Q=I.y,i=e.y,E=Math.min(t,B,o),n=Math.min(C,Q,i),s=Math.max(t,B,o),r=Math.max(C,Q,i);let a=e.next;for(;a!==A;){if(a.x>=E&&a.x<=s&&a.y>=n&&a.y<=r&&!(t===a.x&&C===a.y)&&X$A(t,C,B,Q,o,i,a.x,a.y)&&My(a.prev,a,a.next)>=0)return!1;a=a.next}return!0}function MOt(g,A,I,e){const t=g.prev,B=g,o=g.next,C=t.x,Q=B.x,i=o.x,E=t.y,n=B.y,s=o.y,r=Math.min(C,Q,i),a=Math.min(E,n,s),c=Math.max(C,Q,i),h=Math.max(E,n,s),l=z$A(r,a,A,I,e),D=z$A(c,h,A,I,e);let d=g.prevZ;for(;d&&d.z>=l;){if(d.x>=r&&d.x<=c&&d.y>=a&&d.y<=h&&d!==o&&!(C===d.x&&E===d.y)&&X$A(C,E,Q,n,i,s,d.x,d.y)&&My(d.prev,d,d.next)>=0)return!1;d=d.prevZ}let y=g.nextZ;for(;y&&y.z<=D;){if(y.x>=r&&y.x<=c&&y.y>=a&&y.y<=h&&y!==o&&!(C===y.x&&E===y.y)&&X$A(C,E,Q,n,i,s,y.x,y.y)&&My(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function SOt(g,A){let I=g,e=!1;do{const t=I.prev,B=I.next.next;yGI(t,I,I.next,B,!1)&&VdA(t,B)&&VdA(B,t)&&(A.push(t.i,I.i,B.i),CIA(I),CIA(I.next),I=g=B,e=!0),I=I.next}while(I!==g);return e?ZdA(I):I}function fOt(g,A,I,e,t){let B=g;do{let o=B.next.next;for(;o!==B.prev;){if(B.i!==o.i&&xOt(B,o)){let C=JOt(B,o);B=ZdA(B,B.next),C=ZdA(C,C.next),j$A(B,A,I,e,t),j$A(C,A,I,e,t);return}o=o.next}B=B.next}while(B!==g)}var OM=[],ET=[],B5=new Uint32Array(0),BIA=new Uint32Array(0),oIA=new Uint32Array(256);function ROt(g,A,I,e){let t=g,B=0;do t.z=z$A(t.x,t.y,A,I,e),OM[B++]=t,t=t.next;while(t!==g);NOt(B);let o=null;for(let C=0;C<B;C++){const Q=OM[C];Q.prevZ=o,o&&(o.nextZ=Q),o=Q}o.nextZ=null,OM.fill(null,0,B),ET.fill(null,0,B)}function NOt(g){if(g<=32){for(let A=1;A<g;A++){const I=OM[A],e=I.z;let t=A-1;for(;t>=0&&OM[t].z>e;)OM[t+1]=OM[t],t--;OM[t+1]=I}return}B5.length<g&&(B5=new Uint32Array(g),BIA=new Uint32Array(g),ET=new Array(g));for(let A=0;A<g;A++)B5[A]=OM[A].z;OdA(g,OM,B5,ET,BIA,0),OdA(g,ET,BIA,OM,B5,8),OdA(g,OM,B5,ET,BIA,16),OdA(g,ET,BIA,OM,B5,24)}function OdA(g,A,I,e,t,B){oIA.fill(0);for(let C=0;C<g;C++)oIA[I[C]>>>B&255]++;let o=0;for(let C=0;C<256;C++){const Q=oIA[C];oIA[C]=o,o+=Q}for(let C=0;C<g;C++){const Q=I[C],i=oIA[Q>>>B&255]++;e[i]=A[C],t[i]=Q}}function z$A(g,A,I,e,t){return g=(g-I)*t|0,A=(A-e)*t|0,g=(g|g<<8)&16711935,g=(g|g<<4)&252645135,g=(g|g<<2)&858993459,g=(g|g<<1)&1431655765,A=(A|A<<8)&16711935,A=(A|A<<4)&252645135,A=(A|A<<2)&858993459,A=(A|A<<1)&1431655765,g|A<<1}function X$A(g,A,I,e,t,B,o,C){return(t-o)*(A-C)>=(g-o)*(B-C)&&(g-o)*(e-C)>=(I-o)*(A-C)&&(I-o)*(B-C)>=(t-o)*(e-C)}function xOt(g,A){const I=$$A(g,A)&&My(g.prev,g,g.next)>0&&My(A.prev,A,A.next)>0;return g.next.i!==A.i&&(I||VdA(g,A)&&VdA(A,g)&&(My(g.prev,g,A.prev)!==0||My(g,A.prev,A)!==0))&&!FOt(g,A)&&(I||UOt(g,A))}function My(g,A,I){return(A.y-g.y)*(I.x-A.x)-(A.x-g.x)*(I.y-A.y)}function $$A(g,A){return g.x===A.x&&g.y===A.y}function yGI(g,A,I,e,t=!0){const B=My(g,A,I),o=My(g,A,e),C=My(I,e,g),Q=My(I,e,A);return(B>0&&o<0||B<0&&o>0)&&(C>0&&Q<0||C<0&&Q>0)?!0:t?!!(B===0&&WdA(g,I,A)||o===0&&WdA(g,e,A)||C===0&&WdA(I,g,e)||Q===0&&WdA(I,A,e)):!1}function WdA(g,A,I){return A.x<=Math.max(g.x,I.x)&&A.x>=Math.min(g.x,I.x)&&A.y<=Math.max(g.y,I.y)&&A.y>=Math.min(g.y,I.y)}function FOt(g,A){const I=Math.min(g.x,A.x),e=Math.max(g.x,A.x),t=Math.min(g.y,A.y),B=Math.max(g.y,A.y);let o=g;do{const C=o.next;if(o.x>e&&C.x>e||o.x<I&&C.x<I||o.y>B&&C.y>B||o.y<t&&C.y<t){o=C;continue}if(o.i!==g.i&&C.i!==g.i&&o.i!==A.i&&C.i!==A.i&&yGI(o,C,g,A))return!0;o=C}while(o!==g);return!1}function VdA(g,A){return My(g.prev,g,g.next)<0?My(g,A,g.next)>=0&&My(g,g.prev,A)>=0:My(g,A,g.prev)<0||My(g,g.next,A)<0}function UOt(g,A){let I=g,e=!1;const t=(g.x+A.x)/2,B=(g.y+A.y)/2;do{const o=I.next;I.y>B!=o.y>B&&t<(o.x-I.x)*(B-I.y)/(o.y-I.y)+I.x&&(e=!e),I=o}while(I!==g);return e}function JOt(g,A){const I=AAg(g.i,g.x,g.y),e=AAg(A.i,A.x,A.y),t=g.next,B=A.prev;return g.next=A,A.prev=g,I.next=t,t.prev=I,e.next=I,I.prev=e,B.next=e,e.prev=B,e}function wGI(g,A,I,e){const t=AAg(g,A,I);return e?(t.next=e.next,t.prev=e,e.next.prev=t,e.next=t):(t.prev=t,t.next=t),t}function CIA(g){g.next.prev=g.prev,g.prev.next=g.next,g.prevZ&&(g.prevZ.nextZ=g.nextZ),g.nextZ&&(g.nextZ.prevZ=g.prevZ)}function AAg(g,A,I){return{i:g,x:A,y:I,prev:null,next:null,z:0,prevZ:null,nextZ:null}}function KOt(g,A,I,e){let t=0;for(let B=A,o=I-e;B<I;B+=e)t+=(g[o]-g[B])*(g[B+1]+g[o+1]),o=B;return t}var o5=1e-7;function uGI(g,A){if(!Number.isFinite(A)||A<0)throw new Error("Board thickness must be finite and nonnegative");const I=g.map(C=>{const{start:Q,end:i,bend_angle:E,bend_radius:n}=C;if([Q?.x,Q?.y,i?.x,i?.y,E,n].some(y=>!Number.isFinite(y))||n<=A/2||!["left","right"].includes(C.bend_side))throw new Error(`Invalid PCB bend ${C.pcb_bend_id}: finite geometry and radius greater than half the board thickness are required`);const r=Math.hypot(i.x-Q.x,i.y-Q.y);if(r<o5||Math.abs(E)>180)throw new Error(`Unsupported PCB bend ${C.pcb_bend_id}: distinct endpoints and angles within ±180 degrees are required`);const a=C.bend_side==="right"?1:-1,c=a*(i.y-Q.y)/r,h=-a*(i.x-Q.x)/r,l=E*Math.PI/180,D=n*Math.abs(l),d=Q.x*c+Q.y*h;return{id:C.pcb_bend_id,nx:c,ny:h,start:d-D/2,end:d+D/2,angle:l,radius:n,axisMin:Math.min(-h*Q.x+c*Q.y,-h*i.x+c*i.y),axisMax:Math.max(-h*Q.x+c*Q.y,-h*i.x+c*i.y)}}).filter(C=>Math.abs(C.angle)>o5),e=I[0];if(e&&I.some(C=>Math.abs(C.nx-e.nx)>o5||Math.abs(C.ny-e.ny)>o5))throw new Error("Folded PCB rendering currently requires parallel bends with the same moving direction");I.sort((C,Q)=>C.start-Q.start);for(let C=1;C<I.length;C++)if(I[C].start<I[C-1].end-o5)throw new Error("Overlapping PCB bend zones are not supported");const t=[...I].reverse(),B=({p:C,anchor:Q,direction:i})=>{let E={...C};for(const n of t){const s=n.end-n.start,r=Q.x*n.nx+Q.y*n.ny-n.start,a=Math.max(0,Math.min(s,r)),c=n.angle*a/s,h=Math.cos(c),l=Math.sin(c),D=E.x*n.nx+E.y*n.ny-(i?0:n.start),d=E.x-(D+(i?0:n.start))*n.nx,y=E.y-(D+(i?0:n.start))*n.ny,w=Math.sign(n.angle)*n.radius,u=i?0:w*l-a*h,G=i?0:w*(1-h)-a*l,m=D*h-E.z*l+u;E={x:d+(m+(i?0:n.start))*n.nx,y:y+(m+(i?0:n.start))*n.ny,z:D*l+E.z*h+G}}return E},o=({p:C,anchor:Q,direction:i})=>{const E=i?{x:0,y:0,z:0}:B({p:{x:0,y:0,z:0},anchor:Q,direction:!1}),n={x:C.x-E.x,y:C.y-E.y,z:C.z-E.z},s=[{x:1,y:0,z:0},{x:0,y:1,z:0},{x:0,y:0,z:1}].map(a=>B({p:a,anchor:Q,direction:!0})),r=a=>a.x*n.x+a.y*n.y+a.z*n.z;return{x:r(s[0]),y:r(s[1]),z:r(s[2])}};return{bends:I,inversePoint:(C,Q)=>o({p:C,anchor:Q,direction:!1}),inverseDirection:(C,Q)=>o({p:C,anchor:Q,direction:!0}),point:(C,Q=C)=>B({p:C,anchor:Q,direction:!1}),direction:(C,Q)=>B({p:C,anchor:Q,direction:!0}),assertRigid(C,Q){for(const i of I){const E=C.map(n=>n.x*i.nx+n.y*i.ny);if(Math.max(...E)>i.start+o5&&Math.min(...E)<i.end-o5)throw new Error(`${Q} intersects PCB bend zone ${i.id}`)}}}}var mR=1e-7;function QIA(g){const A=g.flatMap(t=>t.vertices);if(!A.length)return{min:{x:0,y:0,z:0},max:{x:0,y:0,z:0}};const I={x:1/0,y:1/0,z:1/0},e={x:-1/0,y:-1/0,z:-1/0};for(const t of A)for(const B of["x","y","z"])I[B]=Math.min(I[B],t[B]),e[B]=Math.max(e[B],t[B]);return{min:I,max:e}}function GGI(g,A){const I=A.bends.flatMap(C=>{const Q=Math.ceil(Math.abs(C.angle)/(Math.PI/36));return Array.from({length:Q+1},(i,E)=>({b:C,d:C.start+(C.end-C.start)*E/Q}))}),{min:e,max:t}=g.boundingBox,B=({polygon:C,nx:Q,ny:i,d:E})=>{const n=C.map(({p:r})=>Q*r.x+i*r.y-E);if(Math.min(...n)>=-mR||Math.max(...n)<=mR)return[C];const s=[[],[]];for(let r=0;r<2;r++){const a=r===0?1:-1;for(let c=0;c<C.length;c++){const h=C[c],l=(c+1)%C.length,D=C[l],d=n[c]*a,y=n[l]*a;if(d>=-mR&&s[r].push(h),d>mR&&y<-mR||d<-mR&&y>mR){const w=d/(d-y);s[r].push({p:{x:h.p.x+(D.p.x-h.p.x)*w,y:h.p.y+(D.p.y-h.p.y)*w,z:h.p.z+(D.p.z-h.p.z)*w},uv:{u:h.uv.u+(D.uv.u-h.uv.u)*w,v:h.uv.v+(D.uv.v-h.uv.v)*w}})}}}return s.filter(r=>r.length>=3)},o=[];for(const C of g.triangles){const Q=C.pcbFace??(C.normal.z>.8?"top":C.normal.z<-.8?"bottom":"side");let i=[C.vertices.map((E,n)=>({p:E,uv:C.uvs?.[n]??{u:(E.x-e.x)/(t.x-e.x),v:1-(E.y-e.y)/(t.y-e.y)}}))];for(const{b:E,d:n}of I)i=i.flatMap(s=>B({polygon:s,nx:E.nx,ny:E.ny,d:n}));for(const E of i){for(const n of A.bends){const s=E.reduce((r,{p:a})=>r+a.x*n.nx+a.y*n.ny,0)/E.length;if(s>n.start+mR&&s<n.end-mR&&E.some(({p:r})=>{const a=-n.ny*r.x+n.nx*r.y;return a<n.axisMin-mR||a>n.axisMax+mR}))throw new Error(`PCB bend ${n.id} must span the full board cross-section through its bend zone`)}for(let n=1;n+1<E.length;n++){const s=[E[0],E[n],E[n+1]],r=s.map(({p:w})=>A.point(w)),[a,c,h]=r,l={x:c.x-a.x,y:c.y-a.y,z:c.z-a.z},D={x:h.x-a.x,y:h.y-a.y,z:h.z-a.z},d={x:l.y*D.z-l.z*D.y,y:l.z*D.x-l.x*D.z,z:l.x*D.y-l.y*D.x},y=Math.hypot(d.x,d.y,d.z);y<1e-12||o.push({...C,vertices:r,normal:{x:d.x/y,y:d.y/y,z:d.z/y},pcbFace:Q,uvs:s.map(({uv:w})=>w)})}}}return{...g,triangles:o,boundingBox:QIA(o)}}var POt=[{x:1,y:0,z:0},{x:0,y:1,z:0},{x:0,y:0,z:1}];function LOt(g,A){const[I,e,t]=[A.x,A.y,A.z].map(C=>C*Math.PI/180),B={x:Math.cos(t)*g.x-Math.sin(t)*g.y,y:Math.sin(t)*g.x+Math.cos(t)*g.y,z:g.z},o={x:Math.cos(e)*B.x+Math.sin(e)*B.z,y:B.y,z:-Math.sin(e)*B.x+Math.cos(e)*B.z};return{x:o.x,y:Math.cos(I)*o.y-Math.sin(I)*o.z,z:Math.sin(I)*o.y+Math.cos(I)*o.z}}function YOt([g,A,I]){const e=Math.asin(Math.max(-1,Math.min(1,I.x))),t=Math.abs(I.x)<1-1e-12;return{x:(t?Math.atan2(-I.y,I.z):Math.atan2(A.z,A.y))*180/Math.PI,y:e*180/Math.PI,z:(t?Math.atan2(-A.x,g.x):0)*180/Math.PI}}function _Ot({cadComponent:g,foldPcbs:A},I){return bOt({cadComponentPlacement:g,foldPcbs:A},I)}function bOt({cadComponentPlacement:g,foldPcbs:A},I){if(g.is_on_folded_board===!0===A)return g;const{fold:e,boardCenter:t,flatMount:B}=I,o={x:B.x-t.x,y:B.y-t.y,z:0};e.assertRigid([o],"CAD mount");const C={x:g.position.x-t.x,y:g.position.y-t.y,z:g.position.z},Q=A?e.direction:e.inverseDirection,i=A?e.point(C,o):e.inversePoint(C,o),E=g.rotation??I.defaultRotation??{x:0,y:0,z:0},n=POt.map(s=>Q(LOt(s,E),o));return{...g,position:{x:i.x+t.x,y:i.y+t.y,z:i.z},rotation:YOt(n),is_on_folded_board:A}}function HOt(g,A){const I=A.find(Q=>Q.type==="pcb_component"&&Q.pcb_component_id===g.pcb_component_id);if(I?.type!=="pcb_component"){if(g.is_on_folded_board)throw new Error(`Folded CAD ${g.cad_component_id} requires its flat pcb_component reference`);return}const e=A.filter(Q=>Q.type==="pcb_board"),t=I.positioned_relative_to_pcb_board_id,B=t?e.filter(Q=>Q.pcb_board_id===t):e.filter(Q=>Q.subcircuit_id&&Q.subcircuit_id===I.subcircuit_id),o=B.length===1?B[0]:!t&&!B.length&&e.length===1?e[0]:void 0;if(!o)throw new Error(`Cannot unambiguously resolve board for CAD ${g.cad_component_id}`);const C=A.filter(Q=>Q.type==="pcb_bend"&&Q.pcb_board_id===o.pcb_board_id);return{fold:uGI(C,o.thickness??1.6),boardCenter:o.center,flatMount:I.center,defaultRotation:{x:(g.layer??I.layer)==="bottom"?180:0,y:0,z:0}}}function vOt(g,A){const I=g.some(e=>e.type==="pcb_bend");return g.map(e=>{if(e.type!=="cad_component")return e;const t=e;if(!I&&!t.is_on_folded_board||t.is_on_folded_board===!0===A.foldPcbs)return e;const B=HOt(t,g);return!B||!B.fold.bends.length&&!t.is_on_folded_board?e:_Ot({cadComponent:t,foldPcbs:A.foldPcbs},B)})}function qOt({outline:g,bottom:A,top:I}){if(g.length<3||!Number.isFinite(A)||!Number.isFinite(I)||I<=A||g.some(Q=>!Number.isFinite(Q.x)||!Number.isFinite(Q.y)))throw new Error("A finite polygon and positive extrusion thickness are required");let e=0;for(const[Q,i]of g.entries()){const E=g[(Q+1)%g.length];e+=i.x*E.y-E.x*i.y}if(Math.abs(e)<1e-12)throw new Error("Degenerate polygon");const t=e>0?g:[...g].reverse(),B=[],o=({a:Q,b:i,c:E,pcbFace:n})=>{const s={x:i.x-Q.x,y:i.y-Q.y,z:i.z-Q.z},r={x:E.x-Q.x,y:E.y-Q.y,z:E.z-Q.z},a={x:s.y*r.z-s.z*r.y,y:s.z*r.x-s.x*r.z,z:s.x*r.y-s.y*r.x},c=Math.hypot(a.x,a.y,a.z);c>1e-12&&B.push({vertices:[Q,i,E],normal:{x:a.x/c,y:a.y/c,z:a.z/c},pcbFace:n})},C=mOt(t.flatMap(Q=>[Q.x,Q.y]));for(let Q=0;Q<C.length;Q+=3){const[i,E,n]=C.slice(Q,Q+3).map(s=>t[s]);o({a:{...i,z:I},b:{...E,z:I},c:{...n,z:I},pcbFace:"top"}),o({a:{...n,z:A},b:{...E,z:A},c:{...i,z:A},pcbFace:"bottom"})}for(let Q=0;Q<t.length;Q++){const i=t[Q],E=t[(Q+1)%t.length];o({a:{...i,z:A},b:{...E,z:A},c:{...E,z:I},pcbFace:"side"}),o({a:{...i,z:A},b:{...E,z:I},c:{...i,z:I},pcbFace:"side"})}return{triangles:B,boundingBox:QIA(B)}}function TOt({stiffener:g,boardThickness:A,fold:I}){const e=g.adhesive_thickness??0;if(!Number.isFinite(e)||e<0||!Number.isFinite(g.thickness)||g.thickness<=0||!["top","bottom"].includes(g.layer))throw new Error(`Invalid PCB stiffener ${g.pcb_stiffener_id}`);const t=g.shape==="polygon"?g.outline:(()=>{if(!(g.width>0&&g.height>0))throw new Error("Invalid stiffener dimensions");const E=(g.rotation??0)*Math.PI/180;return[[-1,-1],[1,-1],[1,1],[-1,1]].map(([n,s])=>({x:g.center.x+n*g.width/2*Math.cos(E)-s*g.height/2*Math.sin(E),y:g.center.y+n*g.width/2*Math.sin(E)+s*g.height/2*Math.cos(E)}))})(),B=A/2+e,o=B+g.thickness,C=qOt({outline:t,bottom:g.layer==="top"?B:-o,top:g.layer==="top"?o:-B});if(!I)return C;I.assertRigid(C.triangles.flatMap(E=>E.vertices),g.pcb_stiffener_id);const Q={x:t.reduce((E,n)=>E+n.x,0)/t.length,y:t.reduce((E,n)=>E+n.y,0)/t.length,z:0},i=C.triangles.map(E=>({...E,vertices:E.vertices.map(n=>I.point(n,Q)),normal:I.direction(E.normal,Q)}));return{...C,triangles:i,boundingBox:QIA(i)}}var ZOt=g=>{let A=0;for(let e=0;e<g.length;e++){const t=(e+1)%g.length;g[e]&&g[t]&&(A+=g[e][0]*g[t][1],A-=g[t][0]*g[e][1])}return A/2<=0};function OOt(g,A,I,e,t){let B,o=null;if(I.outline&&I.outline.length>=3){let C=I.outline.map(i=>[i.x,i.y]);ZOt(C)&&(C=C.reverse());const Q=A.ofPolygons([C]);t.push(Q),o=Q,B=g.extrude(Q,e,void 0,void 0,void 0,!0),t.push(B)}else I.outline&&I.outline.length>0&&console.warn("Board outline has fewer than 3 points, falling back to rectangular board."),B=g.cube([I.width,I.height,e],!0),t.push(B),B=B.translate([I.center.x,I.center.y,0]),t.push(B);return{boardOp:B,outlineCrossSection:o}}var WOt=64;function C5({Manifold:g,width:A,height:I,thickness:e,borderRadius:t}){const B=XuI(A,I,t);if(B<=0)return g.cube([A,I,e],!0);const o=[],C=A-2*B,Q=I-2*B;return C>0&&o.push(g.cube([C,I,e],!0)),Q>0&&o.push(g.cube([A,Q,e],!0)),[[A/2-B,I/2-B],[-A/2+B,I/2-B],[-A/2+B,-I/2+B],[A/2-B,-I/2+B]].forEach(([E,n])=>{o.push(g.cylinder(e,B,B,WOt,!0).translate([E,n,0]))}),g.union(o)}var VOt=g=>{let A=0;for(let e=0;e<g.length;e++){const t=(e+1)%g.length;g[e]&&g[t]&&(A+=g[e][0]*g[t][1],A-=g[t][0]*g[e][1])}return A/2<=0};function jOt(g,A,I,e,t){const B=[],o=jB(I).pcb_cutout.list();for(const C of o){let Q;const i=e*1.5;switch(C.shape){case"rect":{const s=i3(C);if(typeof s=="number"&&s>0?Q=C5({Manifold:g,width:C.width,height:C.height,thickness:i,borderRadius:s}):Q=g.cube([C.width,C.height,i],!0),t.push(Q),C.rotation){const r=Q.rotate([0,0,C.rotation]);t.push(r),Q=r}Q=Q.translate([C.center.x,C.center.y,0]),t.push(Q);break}case"circle":Q=g.cylinder(i,C.radius,-1,fd,!0),t.push(Q),Q=Q.translate([C.center.x,C.center.y,0]),t.push(Q);break;case"polygon":if(C.points.length<3){console.warn(`PCB Cutout [${C.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);continue}let E=C.points.map(s=>[s.x,s.y]);VOt(E)&&(E=E.reverse());const n=A.ofPolygons([E]);t.push(n),Q=g.extrude(n,i,0,0,[1,1],!0),t.push(Q);break;default:console.warn(`Unsupported cutout shape: ${C.shape} for cutout ${C.pcb_cutout_id}`);continue}Q&&B.push(Q)}return{cutoutOps:B}}function mGI({Manifold:g,x:A,y:I,diameter:e,thickness:t,segments:B=32}){return g.cylinder(t*1.2,e/2,e/2,B,!0).translate([A,I,0])}function pGI({Manifold:g,x:A,y:I,holeDiameter:e,thickness:t,zOffset:B=.001,segments:o=32}){const C=e/2+B;return g.cylinder(t*1.2,C,C,o,!0).translate([A,I,0])}function zOt(g,A,I,e,t){const B=[],o=jB(I).pcb_hole.list(),C=(E,n,s)=>{const r=C5({Manifold:g,width:E,height:n,thickness:s,borderRadius:Math.min(E,n)/2});return t.push(r),r},Q=(E,n,s)=>{const r=g.cube([E,n,s],!0);return t.push(r),r},i=(E,n,s)=>{const r=[];for(let a=0;a<s;a++){const c=2*Math.PI*a/s;r.push([E/2*Math.cos(c),n/2*Math.sin(c)])}return r};for(const E of o){const n=E.hole_shape,s=E.x,r=E.y,a=e*1.2,c=E.ccw_rotation??E.rotation??0,h=E.hole_width??E.hole_diameter,l=E.hole_height??E.hole_diameter;let D=null;if(n==="circle"){D=mGI({Manifold:g,x:s,y:r,diameter:E.hole_diameter,thickness:e,segments:fd}),B.push(D),t.push(D);continue}if(n==="pill"||n==="rotated_pill")D=C(h,l,a);else if(n==="rect")D=Q(h,l,a);else if(n==="oval"){let d=i(h,l,fd),y=0;for(let u=0;u<d.length;u++){const G=(u+1)%d.length;y+=d[u][0]*d[G][1],y-=d[G][0]*d[u][1]}y<=0&&(d=d.reverse());const w=A.ofPolygons([d]);t.push(w),D=g.extrude(w,a,0,0,[1,1],!0),t.push(D)}if(D){if(c!==0){const y=D.rotate([0,0,c]);t.push(y),D=y}const d=D.translate([s,r,0]);t.push(d),B.push(d)}}return{nonPlatedHoleBoardDrills:B}}function ax(g){const A=new Jn;if(A.setAttribute("position",new To(g.vertProperties,3)),A.setIndex(new _4A(g.triVerts,1)),g.runIndex&&g.runIndex.length>1&&g.runOriginalID)for(let I=0;I<g.runIndex.length-1;I++){const e=g.runIndex[I],t=g.runIndex[I+1]-e;A.addGroup(e,t,0)}else A.addGroup(0,g.triVerts.length,0);return A}var iIA=g=>{let A=0;for(let e=0;e<g.length;e++){const t=(e+1)%g.length;g[e]&&g[t]&&(A+=g[e][0]*g[t][1],A-=g[t][0]*g[e][1])}return A/2<=0},jdA=(g,A,I)=>{const e=[];for(let t=0;t<I;t++){const B=2*Math.PI*t/I;e.push([g/2*Math.cos(B),A/2*Math.sin(B)])}return e},Q5=new tB(...jE.copper),zdA=.05,EIA=.003,nIA=5e-4,sIA=.004;function XOt(g,A,I,e,t,B){const o=[],C=jB(I).pcb_plated_hole.list(),Q=[],i=[],E=(a,c,h)=>{const l=C5({Manifold:g,width:a,height:c,thickness:h,borderRadius:Math.min(a,c)/2});return t.push(l),l},n=({padOutline:a,thickness:c})=>{if(!Array.isArray(a)||a.length<3)return null;let h=a.map(d=>[d.x,d.y]);iIA(h)&&(h=h.reverse());const l=A.ofPolygons([h]);t.push(l);const D=g.extrude(l,c,0,0,[1,1],!0);return t.push(D),D},s=({ph:a,depth:c,sizeDelta:h=0})=>{if(a.shape!=="hole_with_polygon_pad")return null;const D=a.pad_outline;if(!Array.isArray(D)||D.length<3)return null;const d=a.hole_shape||"circle",y=a.hole_offset_x||0,w=a.hole_offset_y||0;let u=null;if(d==="circle"){const G=Math.max((a.hole_diameter??0)+h,Oo),m=Math.max(G/2,Oo/2);u=g.cylinder(c,m,m,fd,!0),t.push(u)}else{const G=a.hole_width??a.hole_diameter,m=a.hole_height??a.hole_diameter;if(!G||!m)return null;const p=Math.max(G+h,Oo),k=Math.max(m+h,Oo);if(d==="oval"){let S=jdA(p,k,fd);iIA(S)&&(S=S.reverse());const R=A.ofPolygons([S]);t.push(R),u=g.extrude(R,c,0,0,[1,1],!0),t.push(u)}else(d==="pill"||d==="rotated_pill")&&(u=C5({Manifold:g,width:p,height:k,thickness:c,borderRadius:Math.min(p,k)/2}),t.push(u))}if(!u)return null;if(y||w){const G=u.translate([y,w,0]);t.push(G),u=G}return u};C.forEach((a,c)=>{const h=Math.max(e-2*(EIA+nIA+sIA),Oo);if(a.shape==="circle"){const l=pGI({Manifold:g,x:a.x,y:a.y,holeDiameter:a.hole_diameter*1.02,thickness:e,zOffset:uR,segments:fd});t.push(l),o.push(l);const D=h,d=g.cylinder(D,a.outer_diameter/2,a.outer_diameter/2,fd,!0);t.push(d);const y=g.cylinder(D*1.05,a.hole_diameter/2,a.hole_diameter/2,fd,!0);t.push(y);const w=d.subtract(y);t.push(w);const u=w.translate([a.x,a.y,0]);t.push(u);let G=u;if(B){const p=g.intersection([u,B]);t.push(p),G=p}i.push(G);const m=ax(G.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:m,color:Q5})}else if(a.shape==="pill"){const l=a.hole_width,D=a.hole_height,d=.4,y=a.outer_width??l+d,w=a.outer_height??D+d,u=l+2*uR,G=D+2*uR,m=e*1.2;let p=E(u,G,m);if(a.ccw_rotation){const H=p.rotate([0,0,a.ccw_rotation]);t.push(H),p=H}const k=p.translate([a.x,a.y,0]);t.push(k),o.push(k);const S=h,R=E(y,w,S),F=E(l,D,S*1.05);let N=R.subtract(F);if(t.push(N),a.ccw_rotation){const H=N.rotate([0,0,a.ccw_rotation]);t.push(H),N=H}const U=N.translate([a.x,a.y,0]);t.push(U);let P=U;if(B){const H=g.intersection([U,B]);t.push(H),P=H}i.push(P);const b=ax(P.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:b,color:Q5})}else if(a.shape==="pill_hole_with_rect_pad"){if(a.hole_shape&&a.hole_shape!=="pill"||a.pad_shape&&a.pad_shape!=="rect")return;const l=a.hole_width,D=a.hole_height,d=a.hole_offset_x||0,y=a.hole_offset_y||0,w=a.rect_pad_width,u=a.rect_pad_height,G=i3(a),m=EIA,p=l+2*uR,k=D+2*uR,S=e*1.2,F=E(p,k,S).translate([d,y,0]).translate([a.x,a.y,0]);t.push(F),o.push(F);const N=C5({Manifold:g,width:w,height:u,thickness:Math.max(e-2*(m+nIA+sIA),Oo),borderRadius:G});t.push(N);const U=E(l,D,e*.8).translate([d,y,0]);t.push(U);const P=g.union([N,U]);t.push(P);const b=E(Math.max(l-2*zdA,.01),Math.max(D-2*zdA,.01),e*1.2).translate([d,y,0]);t.push(b);const H=P.subtract(b);t.push(H);const q=H.translate([a.x,a.y,0]);t.push(q);let j=q;if(B){const O=g.intersection([q,B]);t.push(O),j=O}i.push(j);const Z=ax(j.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:Z,color:Q5})}else if(a.shape==="rotated_pill_hole_with_rect_pad"){if(a.hole_shape&&a.hole_shape!=="rotated_pill"||a.pad_shape&&a.pad_shape!=="rect")return;const l=a.hole_width,D=a.hole_height,d=a.hole_offset_x||0,y=a.hole_offset_y||0,w=a.rect_pad_width,u=a.rect_pad_height,G=i3(a),m=EIA,p=l+2*uR,k=D+2*uR,S=e*1.2;let R=E(p,k,S).translate([d,y,0]);if(a.hole_ccw_rotation){const O=R.rotate([0,0,a.hole_ccw_rotation]);t.push(O),R=O}const F=R.translate([a.x,a.y,0]);t.push(F),o.push(F);let N=C5({Manifold:g,width:w,height:u,thickness:Math.max(e-2*(m+nIA+sIA),Oo),borderRadius:G});if(t.push(N),a.rect_ccw_rotation){const O=N.rotate([0,0,a.rect_ccw_rotation]);t.push(O),N=O}let U=E(l,D,e*.8).translate([d,y,0]);if(a.hole_ccw_rotation){const O=U.rotate([0,0,a.hole_ccw_rotation]);t.push(O),U=O}t.push(U);const P=g.union([N,U]);t.push(P);let b=E(Math.max(l-2*zdA,.01),Math.max(D-2*zdA,.01),e*1.2).translate([d,y,0]);if(a.hole_ccw_rotation){const O=b.rotate([0,0,a.hole_ccw_rotation]);t.push(O),b=O}t.push(b);const H=P.subtract(b);t.push(H);const q=H.translate([a.x,a.y,0]);t.push(q);let j=q;if(B){const O=g.intersection([q,B]);t.push(O),j=O}i.push(j);const Z=ax(j.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:Z,color:Q5})}else if(a.shape==="hole_with_polygon_pad"){const l=a.pad_outline;if(!Array.isArray(l)||l.length<3)return;const D=s({ph:a,depth:e*1.2,sizeDelta:2*Oo});if(!D)return;const d=D.translate([a.x,a.y,0]);t.push(d),o.push(d);const w=Math.max(e-2*(EIA+nIA+sIA),Oo),u=n({padOutline:l,thickness:w});if(!u)return;const G=s({ph:a,depth:e*1.02});if(!G)return;const m=s({ph:a,depth:e*.8,sizeDelta:-2*Oo})||G,p=g.union([u,G]);t.push(p);const k=p.subtract(m);t.push(k);const S=k.translate([a.x,a.y,0]);t.push(S);let R=S;if(B){const N=g.intersection([S,B]);t.push(N),R=N}i.push(R);const F=ax(R.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:F,color:Q5})}else if(a.shape==="oval"){const l=a.hole_width,D=a.hole_height,d=a.outer_width??l+.4,y=a.outer_height??D+.4,w=l+2*uR,u=D+2*uR,G=e*1.2;let m=jdA(w,u,fd);iIA(m)&&(m=m.reverse());const p=A.ofPolygons([m]);t.push(p);let k=g.extrude(p,G,0,0,[1,1],!0);if(t.push(k),a.ccw_rotation){const AA=k.rotate([0,0,a.ccw_rotation]);t.push(AA),k=AA}const S=k.translate([a.x,a.y,0]);t.push(S),o.push(S);const R=h;let F=jdA(d,y,fd);iIA(F)&&(F=F.reverse());const N=A.ofPolygons([F]);t.push(N);const U=g.extrude(N,R,0,0,[1,1],!0);t.push(U);let P=jdA(l,D,fd);iIA(P)&&(P=P.reverse());const b=A.ofPolygons([P]);t.push(b);const H=g.extrude(b,R*1.05,0,0,[1,1],!0);t.push(H);let q=U.subtract(H);if(t.push(q),a.ccw_rotation){const AA=q.rotate([0,0,a.ccw_rotation]);t.push(AA),q=AA}const j=q.translate([a.x,a.y,0]);t.push(j);let Z=j;if(B){const AA=g.intersection([j,B]);t.push(AA),Z=AA}i.push(Z);const O=ax(Z.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:O,color:Q5})}else if(a.shape==="circular_hole_with_rect_pad"){if(a.hole_shape&&a.hole_shape!=="circle"||a.pad_shape&&a.pad_shape!=="rect")return;const l=a.hole_offset_x||0,D=a.hole_offset_y||0,d=mGI({Manifold:g,x:a.x+l,y:a.y+D,diameter:a.hole_diameter,thickness:e,segments:fd});t.push(d),o.push(d);const y=a.rect_pad_width??a.hole_diameter,w=a.rect_pad_height??a.hole_diameter,u=i3(a),G=EIA,m=a.hole_diameter/2,p=C5({Manifold:g,width:y,height:w,thickness:Math.max(e-2*(G+nIA+sIA),Oo),borderRadius:u});t.push(p);const k=g.cylinder(e*.8,m,m,fd,!0).translate([l,D,0]);t.push(k);const S=g.union([p,k]);t.push(S);const R=g.cylinder(e*1.2,Math.max(m-Oo,.01),Math.max(m-Oo,.01),fd,!0).translate([l,D,0]);t.push(R);const F=S.subtract(R);t.push(F);const N=F.translate([a.x,a.y,0]);t.push(N);let U=N;if(B){const b=g.intersection([N,B]);t.push(b),U=b}i.push(U);const P=ax(U.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:P,color:Q5})}});let r;return i.length>0&&(r=g.union(i),t.push(r)),{platedHoleBoardDrills:o,platedHoleCopperGeoms:Q,platedHoleSubtractOp:r}}function $Ot({Manifold:g,x:A,y:I,outerDiameter:e,holeDiameter:t,thickness:B,zOffset:o=.001,segments:C=32}){const Q=o;if(e<t)throw new Error(`Invalid via geometry: outerDiameter (${e}) must be >= holeDiameter (${t})`);const i=Math.min(e/2,t/2+Q),n=g.cylinder(B,i,-1,C,!0),s=B+2*o,r=g.cylinder(s,t/2,-1,C,!0);return n.subtract(r).translate([A,I,0])}var AWt=new tB(...jE.copper);function gWt(g,A,I,e,t,B=[]){const o=[],C=v$A(A),Q=[],i=[];C.forEach((n,s)=>{let r;if(typeof n.hole_diameter=="number"){const a=pGI({Manifold:g,x:n.x,y:n.y,holeDiameter:n.hole_diameter,thickness:I,zOffset:uR,segments:fd});e.push(a),o.push(a),r=a}if(typeof n.outer_diameter=="number"&&typeof n.hole_diameter=="number"){const a=$Ot({Manifold:g,x:n.x,y:n.y,outerDiameter:n.outer_diameter,holeDiameter:n.hole_diameter,thickness:I,zOffset:uR,segments:fd});e.push(a);let c=a;if(t){const h=g.intersection([a,t]);e.push(h),c=h}i.push({key:`via-${n.pcb_via_id||s}`,copper:c,ownDrill:r})}});const E=[...B,...o].map(n=>({drill:n,bounds:n.boundingBox()}));for(const{key:n,copper:s,ownDrill:r}of i){const a=s.boundingBox(),c=E.filter(({drill:l,bounds:D})=>l!==r&&[0,1,2].every(d=>D.min[d]<=a.max[d]&&D.max[d]>=a.min[d])).map(({drill:l})=>l);let h=s;if(c.length){const l=g.union(c);h=s.subtract(l),e.push(l,h)}Q.push({key:n,geometry:ax(h.getMesh()),color:AWt})}return{viaBoardDrills:o,viaCopperGeoms:Q}}var IWt=(g,A,I)=>{const e=aGI(I),[t,B]=gA.useState(null),[o,C]=gA.useState(null),[Q,i]=gA.useState(null),[E,n]=gA.useState(!0),s=gA.useRef([]),r=gA.useMemo(()=>{const l=A.filter(y=>y.type==="pcb_panel"),D=jB(A).pcb_board.list();if(l.length>0){const y=l[0],w=D.find(u=>u.pcb_panel_id===y.pcb_panel_id);return{type:"pcb_board",pcb_board_id:y.pcb_panel_id,center:y.center,width:y.width,height:y.height,thickness:w?.thickness??1.4,material:w?.material??"fr4",num_layers:w?.num_layers??2,solder_mask_color:w?.solder_mask_color}}const d=D.filter(y=>!y.pcb_panel_id);return d.length>0?d[0]:null},[A]),a=gA.useMemo(()=>{const l=jB(A).pcb_board.list();return l.length>0&&l[0].pcb_board_id==="faux-board"},[A]),c=gA.useMemo(()=>r?rGI(r,K2):K2,[r]);gA.useEffect(()=>{if(!g||!r){B(null),C(null),n(!1);return}if((r.width===0||!r.width)&&(r.height===0||!r.height)&&(!r.outline||r.outline.length<3)){B({platedHoles:[],vias:[]}),C(r.thickness??0),n(!1);return}n(!0),i(null);const l=g.Manifold,D=g.CrossSection,d=u=>{if(!(!u||typeof u.delete!="function"))try{u.delete()}catch(G){(!(G instanceof Error)||!G.message?.includes("Manifold instance already deleted"))&&console.warn("Failed to delete Manifold instance",G)}};s.current.forEach(d),s.current=[];let y=null;const w={};try{const u=r.thickness||1.4;C(u);const{boardOp:G,outlineCrossSection:m}=OOt(l,D,r,u,s.current);let p=G;const S=u+2*1;let R=null;const F=.01;if(m){let AA=m;if(F>0){const eA=m.offset(F);s.current.push(eA),AA=eA}const tA=l.extrude(AA,S,void 0,void 0,void 0,!0);s.current.push(tA),R=tA}else{const AA=(r.width||0)+2*F,tA=(r.height||0)+2*F,eA=l.cube([AA,tA,S],!0);s.current.push(eA);const iA=eA.translate([r.center.x,r.center.y,0]);s.current.push(iA),R=iA}const N=[];let U=null;const{nonPlatedHoleBoardDrills:P}=zOt(l,D,A,u,s.current);N.push(...P);const{platedHoleBoardDrills:b,platedHoleCopperGeoms:H,platedHoleSubtractOp:q}=XOt(l,D,A,u,s.current,R);N.push(...b),w.platedHoles=H;const{viaBoardDrills:j,viaCopperGeoms:Z}=gWt(l,A,u,s.current,R,N);if(N.push(...j),w.vias=Z,N.length>0){U=l.union(N),s.current.push(U);const AA=q?l.union([U,q]):U;s.current.push(AA);const tA=p.subtract(AA);if(s.current.push(tA),p=tA,q){const eA=q.subtract(U);s.current.push(eA);const iA=eA.getMesh(),sA=ax(iA);w.platedHoles=[{key:"plated-holes-union",geometry:sA,color:new tB(jE.copper[0],jE.copper[1],jE.copper[2])}]}}const{cutoutOps:O}=jOt(l,D,A,u,s.current);if(O.length>0){const AA=l.union(O);s.current.push(AA);const tA=p.subtract(AA);s.current.push(tA),p=tA}if(y=p,y){const AA=y.getMesh(),tA=ax(AA);w.board={geometry:tA,color:L$A(r),material:r.material,isFaux:a}}B(w)}catch(u){console.error("Error processing geometry with Manifold in hook:",u),i(u.message||"An unknown error occurred while processing geometry in hook."),B(null)}finally{n(!1)}return()=>{s.current.forEach(d),s.current=[]}},[g,A,r]);const h=gA.useMemo(()=>!r||!c?null:CGI({circuitJson:A,boardData:r,traceTextureResolution:c,visibility:e}),[A,r,c,e]);return{geoms:t,textures:h,pcbThickness:o,error:Q,isLoading:E,boardData:r,isFauxBoard:a}};function kGI(g,A){g.updateMatrix();const I=g.geometry.index?g.geometry.toNonIndexed():g.geometry,e=I.getAttribute("position"),t=I.getAttribute("uv"),B=[];for(let o=0;o<e.count;o+=3){const C=[0,1,2].map(s=>{const r=new oI().fromBufferAttribute(e,o+s).applyMatrix4(g.matrix);return{x:r.x-A.x,y:r.y-A.y,z:r.z}}),[Q,i,E]=C,n=new oI(i.x-Q.x,i.y-Q.y,i.z-Q.z).cross(new oI(E.x-Q.x,E.y-Q.y,E.z-Q.z)).normalize();B.push({vertices:C,normal:{x:n.x,y:n.y,z:n.z},...t?{uvs:[0,1,2].map(s=>({u:t.getX(o+s),v:t.getY(o+s)}))}:{}})}return I!==g.geometry&&I.dispose(),{triangles:B,boundingBox:QIA(B)}}function MGI(g,A){const I=[],e=[],t=[];for(const o of g.triangles)o.vertices.forEach((C,Q)=>{I.push(C.x+A.x,C.y+A.y,C.z),e.push(o.normal.x,o.normal.y,o.normal.z),t.push(o.uvs?.[Q]?.u??0,o.uvs?.[Q]?.v??0)});const B=new Jn;return B.setAttribute("position",new To(I,3)),B.setAttribute("normal",new To(e,3)),B.setAttribute("uv",new To(t,2)),B.computeBoundingBox(),B.computeBoundingSphere(),B}function SGI(g,A,I){const e=g.clone();return e.geometry=MGI(A,I.center),e.position.set(0,0,0),e.rotation.set(0,0,0),e.scale.set(1,1,1),e.updateMatrix(),e}function eWt(g,A,I,e){const t=I.filter(a=>a.type==="pcb_board"),B=I.filter(a=>a.type==="pcb_bend"),o=I.filter(a=>a.type==="pcb_stiffener");if(!B.length&&!o.length)return{geometryMeshes:g,textureMeshes:A};const C=t[0];if(!C||t.length!==1||I.some(a=>a.type==="pcb_panel")||[...B,...o].some(a=>a.pcb_board_id!==C.pcb_board_id))throw new Error("Flex rendering requires one board, matching board references, and no panel");const Q=e?uGI(B,C.thickness??1.6):void 0,i=g.find(a=>a.name==="board-geom"),E=i?kGI(i,C.center):void 0,n=Q?g.map(a=>SGI(a,GGI(kGI(a,C.center),Q),C)):[...g],s=Q&&E?A.map(a=>{a.updateMatrix();const c=a.matrix.clone().invert(),h=a.name.startsWith("bottom"),l=a.geometry.parameters,D=E.triangles.filter(y=>h?y.normal.z<-.9:y.normal.z>.9).map(y=>{const w=y.vertices.map(G=>({...G,z:a.position.z})),u=w.map(G=>{const m=new oI(G.x+C.center.x,G.y+C.center.y,G.z).applyMatrix4(c);return{u:m.x/l.width+.5,v:m.y/l.height+.5}});return{...y,vertices:w,uvs:u}}),d=SGI(a,GGI({triangles:D,boundingBox:QIA(D)},Q),C);return a.geometry.dispose(),d}):A;for(const a of o){const c=new FB(MGI(TOt({stiffener:a,boardThickness:C.thickness??1.6,fold:Q}),C.center),new Ps({color:a.material==="fr4"?"#879568":a.material==="polyimide"?"#bd7f27":"#b8bdc4",side:yl}));c.name="board-stiffener",ZM(c),n.push(c)}const r=new WG;for(const a of[...n,...s])r.expandByObject(a);return{geometryMeshes:n,textureMeshes:s,bounds:{minX:r.min.x,maxX:r.max.x,minY:r.min.y,maxY:r.max.y,minZ:r.min.z,maxZ:r.max.z}}}var tWt=yl,BWt=({material:g,color:A,side:I=tWt,isFaux:e=!1})=>g==="fr4"?new dM({color:A,side:I,metalness:0,roughness:.48,specularIntensity:.3,ior:1.45,sheen:0,clearcoat:.16,clearcoatRoughness:.3,transparent:e,opacity:e?KdA:1,flatShading:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}):new Ps({color:A,side:I,flatShading:!0,metalness:.1,roughness:.8,transparent:!0,opacity:e?KdA:.9,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});function oWt(g){const A=[];if(!g)return A;if(g.board?.geometry){const e=new FB(g.board.geometry,BWt({material:g.board.material,color:g.board.color,side:yl,isFaux:g.board.isFaux}));e.name="board-geom",ZM(e,{castShadow:!1,receiveShadow:!0}),A.push(e)}const I=e=>{if(e)for(const t of e){const B=new FB(t.geometry,new Ps({color:t.color,side:yl,flatShading:!0}));B.name=t.key,ZM(B),A.push(B)}};return I(g.platedHoles),I(g.vias),A}var XdA;function CWt(){return XdA||(XdA=(async()=>{const g=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(g&&typeof g=="object"&&g.setup)return window.ManifoldModule=g,g;const I=await(g??(await import(XgA("manifold-3d","3.5.1","manifold.js"))).default)();return I.setup(),window.ManifoldModule=I,I})().catch(g=>{throw XdA=void 0,g})),XdA}var QWt=({geometryMeshes:g,textureMeshes:A})=>{const{rootObject:I}=SD(),{visibility:e}=e5(),t=B=>{B.geometry.dispose();const o=Array.isArray(B.material)?B.material:[B.material];for(const C of o){if(!C)continue;const Q=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],i=C;for(const E of Q){const n=i[E];n&&n instanceof Hr&&n.dispose()}C.dispose()}};return gA.useEffect(()=>{if(I){for(const B of g){let o=!0;B.name==="board-geom"||B.name==="board-stiffener"?o=e.boardBody:(B.name.includes("plated_hole")||B.name.includes("via"))&&(o=e.topCopper||e.bottomCopper),o&&I.add(B)}return()=>{for(const B of g)B.parent===I&&I.remove(B),t(B)}}},[I,g,e]),gA.useEffect(()=>{if(I){for(const B of A)I.add(B);return()=>{for(const B of A)B.parent===I&&I.remove(B),t(B)}}},[I,A]),null},iWt=({circuitJson:g,foldPcbs:A,autoRotateDisabled:I,clickToInteractEnabled:e,onUserInteraction:t,children:B,onCameraControllerReady:o,resolveStaticAsset:C,referenceObject:Q,hiddenCadComponentIds:i})=>{const E=p$A(B),n=gA.useMemo(()=>dGI(g??E),[g,E]),[s,r]=gA.useState(null),[a,c]=gA.useState(null),{visibility:h}=e5();gA.useEffect(()=>{let U=!0;return CWt().then(P=>{U&&r(P)}).catch(P=>{U&&(console.error("Failed to initialize Manifold:",P),c(`Failed to initialize Manifold: ${P instanceof Error?P.message:"Unknown error"}`))}),()=>{U=!1}},[]);const{geoms:l,textures:D,pcbThickness:d,error:y,isLoading:w,boardData:u,isFauxBoard:G}=IWt(s,n,h),m=gA.useMemo(()=>{try{const U=yuI(n,A),P=vOt(n,{foldPcbs:U});return{...eWt(oWt(l),nOt(D,u,d,G),n,U),posedJson:P,error:void 0}}catch(U){return{error:U instanceof Error?U.message:String(U),geometryMeshes:[],textureMeshes:[],posedJson:n,bounds:void 0}}},[l,D,u,d,G,n,A]),p=gA.useMemo(()=>jB(m.posedJson).cad_component.list().filter(U=>!i?.has(U.cad_component_id)),[m.posedJson,i]),k=gA.useMemo(()=>cGI(m.posedJson),[m.posedJson]),S=gA.useMemo(()=>{if(!u)return;const U=ky(u);return{width:U.width,height:U.height}},[u]),R=gA.useMemo(()=>{if(!u)return;const U=ky(u);return{x:U.centerX,y:U.centerY}},[u]),F=gA.useMemo(()=>DGI({boardDimensions:S,boardCenter:R}),[S,R]),N=gA.useMemo(()=>{if(u)return JSON.stringify({pcbBoardId:u.pcb_board_id,center:R,dimensions:S})},[u,R,S]);return a?W.jsxs("div",{style:{color:"red",padding:"1em",border:"1px solid red",margin:"1em"},children:["Error: ",a]}):s?y||m.error?W.jsxs("div",{role:"alert",style:{color:"red",padding:"1em",border:"1px solid red",margin:"1em"},children:["Error: ",y??m.error]}):w?W.jsx("div",{style:{padding:"1em"},children:"Processing board geometry..."}):W.jsxs(ZuI,{initialCameraPosition:F,autoRotateDisabled:I,clickToInteractEnabled:e,boardDimensions:S,boardCenter:R,cameraSessionScope:N,referenceObject:Q,onUserInteraction:t,onCameraControllerReady:o,children:[W.jsx(QWt,{geometryMeshes:m.geometryMeshes,textureMeshes:m.textureMeshes}),m.bounds&&W.jsx(TuI,{bounds:m.bounds}),p.map(U=>W.jsx(N$A,{fallback:({error:P})=>W.jsx(AGI,{cad_component:U,error:P}),children:W.jsx(FuI,{cad_component:U,circuitJson:m.posedJson,resolveStaticAsset:C})},U.cad_component_id)),k.map(U=>W.jsx(lGI,{cable:U},U.cad_cable_id))]}):W.jsx("div",{style:{padding:"1em"},children:"Loading Manifold module..."})},fGI=iWt,EWt=Object.defineProperty,nT=(g,A)=>EWt(g,"name",{value:A,configurable:!0}),RGI=!!(typeof window<"u"&&window.document&&window.document.createElement);function un(g,A,{checkForDefaultPrevented:I=!0}={}){return nT(function(t){if(g?.(t),I===!1||!t||!t.defaultPrevented)return A?.(t)},"handleEvent")}nT(un,"composeEventHandlers");function nWt(g){if(!RGI)throw new Error("Cannot access window outside of the DOM");return g?.ownerDocument?.defaultView??window}nT(nWt,"getOwnerWindow");function gAg(g){if(!RGI)throw new Error("Cannot access document outside of the DOM");return g?.ownerDocument??document}nT(gAg,"getOwnerDocument");function NGI(g,A=!1){const{activeElement:I}=gAg(g);if(!I?.nodeName)return null;if(xGI(I)&&I.contentDocument)return NGI(I.contentDocument.body,A);if(A){const e=I.getAttribute("aria-activedescendant");if(e){const t=gAg(I).getElementById(e);if(t)return t}}return I}nT(NGI,"getActiveElement");function xGI(g){return g.tagName==="IFRAME"}nT(xGI,"isFrame");var sWt=Object.defineProperty,IAg=(g,A)=>sWt(g,"name",{value:A,configurable:!0});function eAg(g,A){if(typeof g=="function")return g(A);g!=null&&(g.current=A)}IAg(eAg,"setRef");function FGI(...g){return A=>{let I=!1;const e=g.map(t=>{const B=eAg(t,A);return!I&&typeof B=="function"&&(I=!0),B});if(I)return()=>{for(let t=0;t<e.length;t++){const B=e[t];typeof B=="function"?B():eAg(g[t],null)}}}}IAg(FGI,"composeRefs");function Rd(...g){return gA.useCallback(FGI(...g),g)}IAg(Rd,"useComposedRefs");var aWt=Object.defineProperty,P2=(g,A)=>aWt(g,"name",{value:A,configurable:!0});function rWt(g,A){const I=gA.createContext(A);I.displayName=g+"Context";const e=P2(B=>{const{children:o,...C}=B,Q=gA.useMemo(()=>C,Object.values(C));return W.jsx(I.Provider,{value:Q,children:o})},"Provider");e.displayName=g+"Provider";function t(B,o={}){const{optional:C=!1}=o,Q=gA.useContext(I);if(Q)return Q;if(A!==void 0)return A;if(!C)throw new Error(`\`${B}\` must be used within \`${g}\``)}return P2(t,"useContext"),[e,t]}P2(rWt,"createContext");function i5(g,A=[]){let I=[];function e(B,o){const C=gA.createContext(o);C.displayName=B+"Context";const Q=I.length;I=[...I,o];const i=P2(n=>{const{scope:s,children:r,...a}=n,c=s?.[g]?.[Q]||C,h=gA.useMemo(()=>a,Object.values(a));return W.jsx(c.Provider,{value:h,children:r})},"Provider");i.displayName=B+"Provider";function E(n,s,r={}){const{optional:a=!1}=r,c=s?.[g]?.[Q]||C,h=gA.useContext(c);if(h)return h;if(o!==void 0)return o;if(!a)throw new Error(`\`${n}\` must be used within \`${B}\``)}return P2(E,"useContext"),[i,E]}P2(e,"createContext");const t=P2(()=>{const B=I.map(o=>gA.createContext(o));return P2(function(C){const Q=C?.[g]||B;return gA.useMemo(()=>({[`__scope${g}`]:{...C,[g]:Q}}),[C,Q])},"useScope")},"createScope");return t.scopeName=g,[e,UGI(t,...A)]}P2(i5,"createContextScope");function UGI(...g){const A=g[0];if(g.length===1)return A;const I=P2(()=>{const e=g.map(t=>({useScope:t(),scopeName:t.scopeName}));return P2(function(B){const o=e.reduce((C,{useScope:Q,scopeName:i})=>{const n=Q(B)[`__scope${i}`];return{...C,...n}},{});return gA.useMemo(()=>({[`__scope${A.scopeName}`]:o}),[o])},"useComposedScopes")},"createScope");return I.scopeName=A.scopeName,I}P2(UGI,"composeContextScopes");var WM=globalThis?.document?gA.useLayoutEffect:()=>{},cWt=Object.defineProperty,hWt=(g,A)=>cWt(g,"name",{value:A,configurable:!0}),JGI=Gp[" useEffectEvent ".trim().toString()],KGI=Gp[" useInsertionEffect ".trim().toString()];function PGI(g){if(typeof JGI=="function")return JGI(g);const A=gA.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof KGI=="function"?KGI(()=>{A.current=g}):WM(()=>{A.current=g}),gA.useMemo(()=>((...I)=>A.current?.(...I)),[])}hWt(PGI,"useEffectEvent");var lWt=Object.defineProperty,aIA=(g,A)=>lWt(g,"name",{value:A,configurable:!0}),DWt=Gp[" useInsertionEffect ".trim().toString()]||WM;function $dA({prop:g,defaultProp:A,onChange:I=aIA(()=>{},"onChange"),caller:e}){const[t,B,o]=LGI({defaultProp:A,onChange:I}),C=g!==void 0,Q=C?g:t,i=gA.useCallback(E=>{if(C){const n=YGI(E)?E(g):E;n!==g&&o.current?.(n)}else B(E)},[C,g,B,o]);return[Q,i]}aIA($dA,"useControllableState");function LGI({defaultProp:g,onChange:A}){const[I,e]=gA.useState(g),t=gA.useRef(I),B=gA.useRef(A);return DWt(()=>{B.current=A},[A]),gA.useEffect(()=>{t.current!==I&&(B.current?.(I),t.current=I)},[I,t]),[I,e,B]}aIA(LGI,"useUncontrolledState");function YGI(g){return typeof g=="function"}aIA(YGI,"isFunction");var _GI=Symbol("RADIX:SYNC_STATE");function dWt(g,A,I,e){const{prop:t,defaultProp:B,onChange:o,caller:C}=A,Q=t!==void 0,i=PGI(o),E=[{...I,state:B}];e&&E.push(e);const[n,s]=gA.useReducer((h,l)=>{if(l.type===_GI)return{...h,state:l.state};const D=g(h,l);return Q&&!Object.is(D.state,h.state)&&i(D.state),D},...E),r=n.state,a=gA.useRef(r);gA.useEffect(()=>{a.current!==r&&(a.current=r,Q||i(r))},[r,a,Q]);const c=gA.useMemo(()=>t!==void 0?{...n,state:t}:n,[n,t]);return gA.useEffect(()=>{Q&&!Object.is(t,n.state)&&s({type:_GI,state:t})},[t,n.state,Q]),[c,s]}aIA(dWt,"useControllableStateReducer");var yWt=Object.defineProperty,VM=(g,A)=>yWt(g,"name",{value:A,configurable:!0});function E5(g){const A=gA.forwardRef((I,e)=>{let{children:t,...B}=I,o=null,C=!1;const Q=[];t=ZGI(t),gA.Children.forEach(t,s=>{if(qGI(s)){C=!0;const r=s;let a="child"in r.props?r.props.child:r.props.children;for(;tAg(a)&&typeof AyA=="function";)a=AyA(a._payload);o=uWt(r,a),Q.push(o?.props?.children)}else Q.push(s)}),o?o=gA.cloneElement(o,void 0,Q):!C&&gA.Children.count(t)===1&&gA.isValidElement(t)&&(o=t);const i=o?vGI(o):void 0,E=Rd(e,i);if(!o){if(t||t===0)throw new Error(C?pWt(g):mWt(g));return t}const n=HGI(B,o.props??{});return o.type!==gA.Fragment&&(n.ref=e?E:i),gA.cloneElement(o,n)});return A.displayName=`${g}.Slot`,A}VM(E5,"createSlot");var bGI=Symbol.for("radix.slottable");function wWt(g){const A=VM(I=>"child"in I?I.children(I.child):I.children,"Slottable");return A.displayName=`${g}.Slottable`,A.__radixId=bGI,A}VM(wWt,"createSlottable");var uWt=VM((g,A)=>"child"in g.props?gA.isValidElement(A)?gA.cloneElement(A,void 0,g.props.children(A.props.children)):null:gA.isValidElement(A)?A:null,"getSlottableElementFromSlottable");function HGI(g,A){const I={...A};for(const e in A){const t=g[e],B=A[e];/^on[A-Z]/.test(e)?t&&B?I[e]=(...C)=>{const Q=B(...C);return t(...C),Q}:t&&(I[e]=t):e==="style"?I[e]={...t,...B}:e==="className"?I[e]=[t,B].filter(Boolean).join(" "):e==="aria-describedby"&&(I[e]=OGI(B,t))}return{...g,...I}}VM(HGI,"mergeProps");function vGI(g){let A=Object.getOwnPropertyDescriptor(g.props,"ref")?.get,I=A&&"isReactWarning"in A&&A.isReactWarning;return I?g.ref:(A=Object.getOwnPropertyDescriptor(g,"ref")?.get,I=A&&"isReactWarning"in A&&A.isReactWarning,I?g.props.ref:g.props.ref||g.ref)}VM(vGI,"getElementRef");function qGI(g){return gA.isValidElement(g)&&typeof g.type=="function"&&"__radixId"in g.type&&g.type.__radixId===bGI}VM(qGI,"isSlottable");var GWt=Symbol.for("react.lazy");function tAg(g){return g!=null&&typeof g=="object"&&"$$typeof"in g&&g.$$typeof===GWt&&"_payload"in g&&TGI(g._payload)}VM(tAg,"isLazyComponent");function TGI(g){return typeof g=="object"&&g!==null&&"then"in g}VM(TGI,"isPromiseLike");function ZGI(g){let A=g;for(;tAg(A)&&typeof AyA=="function";)A=AyA(A._payload);return A}VM(ZGI,"useUnwrappedLazy");function OGI(...g){const A=new Set;for(const I of g)if(typeof I=="string")for(const e of String(I).trim().split(/\s+/))e&&A.add(e);return A.size>0?Array.from(A).join(" "):void 0}VM(OGI,"concatAriaDescribedby");var mWt=VM(g=>`${g} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),pWt=VM(g=>`${g} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),AyA=Gp[" use ".trim().toString()],kWt=Object.defineProperty,MWt=(g,A)=>kWt(g,"name",{value:A,configurable:!0}),SWt=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],rx=SWt.reduce((g,A)=>{const I=E5(`Primitive.${A}`),e=gA.forwardRef((t,B)=>{const{asChild:o,...C}=t,Q=o?I:A;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),W.jsx(Q,{...C,ref:B})});return e.displayName=`Primitive.${A}`,{...g,[A]:e}},{});function BAg(g,A){g&&CN.flushSync(()=>g.dispatchEvent(A))}MWt(BAg,"dispatchDiscreteCustomEvent");var fWt=Object.defineProperty,Nd=(g,A)=>fWt(g,"name",{value:A,configurable:!0});function oAg(g){const A=g+"CollectionProvider",[I,e]=i5(A),[t,B]=I(A,{collectionRef:{current:null},itemMap:new Map}),o=Nd(c=>{const{scope:h,children:l}=c,D=gA.useRef(null),d=gA.useRef(new Map).current;return W.jsx(t,{scope:h,itemMap:d,collectionRef:D,children:l})},"CollectionProvider");o.displayName=A;const C=g+"CollectionSlot",Q=E5(C),i=gA.forwardRef((c,h)=>{const{scope:l,children:D}=c,d=B(C,l),y=Rd(h,d.collectionRef);return W.jsx(Q,{ref:y,children:D})});i.displayName=C;const E=g+"CollectionItemSlot",n="data-radix-collection-item",s=E5(E),r=gA.forwardRef((c,h)=>{const{scope:l,children:D,...d}=c,y=gA.useRef(null),w=Rd(h,y),u=B(E,l);return gA.useEffect(()=>(u.itemMap.set(y,{ref:y,...d}),()=>{u.itemMap.delete(y)})),W.jsx(s,{[n]:"",ref:w,children:D})});r.displayName=E;function a(c){const h=B(g+"CollectionConsumer",c);return gA.useCallback(()=>{const D=h.collectionRef.current;if(!D)return[];const d=Array.from(D.querySelectorAll(`[${n}]`));return Array.from(h.itemMap.values()).sort((u,G)=>d.indexOf(u.ref.current)-d.indexOf(G.ref.current))},[h.collectionRef,h.itemMap])}return Nd(a,"useCollection"),[{Provider:o,Slot:i,ItemSlot:r},a,e]}Nd(oAg,"createCollection");var WGI=new WeakMap,gyA=(nS=class extends Map{constructor(I){super(I);Drg(this,Jl);pBA(this,Jl,[...super.keys()]),WGI.set(this,!0)}set(I,e){return WGI.get(this)&&!this.has(I)&&jn(this,Jl).push(I),super.set(I,e),this}insert(I,e,t){const B=this.has(e),o=B?this.size:this.size+1,C=CAg(I),Q=C>=0?Math.min(C,o-1):Math.max(o+C,0);if(B?jn(this,Jl).indexOf(e)===Q:Q===this.size)return this.set(e,t),this;const i=jn(this,Jl).filter(n=>n!==e);i.splice(Q,0,e);const E=i.map(n=>[n,n===e?t:this.get(n)]);this.clear();for(const[n,s]of E)this.set(n,s);return this}with(I,e,t){const B=new nS(this);return B.insert(I,e,t),B}before(I){const e=jn(this,Jl).indexOf(I)-1;if(!(e<0))return this.entryAt(e)}setBefore(I,e,t){const B=jn(this,Jl).indexOf(I);if(B===-1)return this;const o=jn(this,Jl).indexOf(e),C=o!==-1&&o<B?B-1:B;return this.insert(C,e,t)}after(I){let e=jn(this,Jl).indexOf(I);if(e=e===-1||e===this.size-1?-1:e+1,e!==-1)return this.entryAt(e)}setAfter(I,e,t){const B=jn(this,Jl).indexOf(I);if(B===-1)return this;const o=jn(this,Jl).indexOf(e),C=o!==-1&&o<=B?B:B+1;return this.insert(C,e,t)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return pBA(this,Jl,[]),super.clear()}delete(I){const e=super.delete(I);return e&&jn(this,Jl).splice(jn(this,Jl).indexOf(I),1),e}deleteAt(I){const e=this.keyAt(I);return e!==void 0?this.delete(e):!1}at(I){const e=IyA(jn(this,Jl),I);if(e!==void 0)return this.get(e)}entryAt(I){const e=IyA(jn(this,Jl),I);if(e!==void 0)return[e,this.get(e)]}indexOf(I){return jn(this,Jl).indexOf(I)}keyAt(I){return IyA(jn(this,Jl),I)}from(I,e){const t=this.indexOf(I);if(t===-1)return;let B=t+e;return B<0&&(B=0),B>=this.size&&(B=this.size-1),this.at(B)}keyFrom(I,e){const t=this.indexOf(I);if(t===-1)return;let B=t+e;return B<0&&(B=0),B>=this.size&&(B=this.size-1),this.keyAt(B)}find(I,e){let t=0;for(const B of this){if(Reflect.apply(I,e,[B,t,this]))return B;t++}}findIndex(I,e){let t=0;for(const B of this){if(Reflect.apply(I,e,[B,t,this]))return t;t++}return-1}filter(I,e){const t=[];let B=0;for(const o of this)Reflect.apply(I,e,[o,B,this])&&t.push(o),B++;return new nS(t)}map(I,e){const t=[];let B=0;for(const o of this)t.push([o[0],Reflect.apply(I,e,[o,B,this])]),B++;return new nS(t)}reduce(...I){const[e,t]=I,B=I.length>1;if(!B&&this.size===0)throw new TypeError("Reduce of empty OrderedDict with no initial value");let o=0,C=t;for(const Q of this)o===0&&!B?C=Q:C=Reflect.apply(e,this,[C,Q,o,this]),o++;return C}reduceRight(...I){const[e,t]=I,B=I.length>1;if(!B&&this.size===0)throw new TypeError("Reduce of empty OrderedDict with no initial value");let o=t;for(let C=this.size-1;C>=0;C--){const Q=this.entryAt(C);C===this.size-1&&!B?o=Q:o=Reflect.apply(e,this,[o,Q,C,this])}return o}sort(I){if(typeof I!="function")throw new TypeError("OrderedDict.sort requires a compare function");const e=[...this.entries()].sort(I);this.clear();for(const[t,B]of e)this.set(t,B);return this}toSorted(I){if(typeof I!="function")throw new TypeError("OrderedDict.toSorted requires a compare function");const e=[...this.entries()].sort(I);return new nS(e)}toReversed(){const I=new nS;for(let e=this.size-1;e>=0;e--){const t=this.keyAt(e),B=this.get(t);I.set(t,B)}return I}toSpliced(...I){const e=[...this.entries()];return e.splice(...I),new nS(e)}slice(I,e){const t=new nS;for(const B of jn(this,Jl).slice(I,e))t.set(B,this.get(B));return t}every(I,e){let t=0;for(const B of this){if(!Reflect.apply(I,e,[B,t,this]))return!1;t++}return!0}some(I,e){let t=0;for(const B of this){if(Reflect.apply(I,e,[B,t,this]))return!0;t++}return!1}},Jl=new WeakMap,Nd(nS,"OrderedDict"),nS);function IyA(g,A){if("at"in Array.prototype)return Array.prototype.at.call(g,A);const I=VGI(g,A);return I===-1?void 0:g[I]}Nd(IyA,"at");function VGI(g,A){const I=g.length,e=CAg(A),t=e>=0?e:I+e;return t<0||t>=I?-1:t}Nd(VGI,"toSafeIndex");function CAg(g){return g!==g||g===0?0:Math.trunc(g)}Nd(CAg,"toSafeInteger");function RWt(g){const A=g+"CollectionProvider",[I,e]=i5(A),[t,B]=I(A);t.displayName=g+"CollectionStableContextProvider";const[o,C]=I(A);o.displayName=g+"CollectionStatefulContextProvider";const Q=Nd(({state:u,...G})=>u?W.jsx(E,{...G,state:u}):W.jsx(i,{...G}),"CollectionProvider");Q.displayName=A;const i=Nd(u=>{const G=D();return W.jsx(E,{...u,state:G})},"CollectionInit");i.displayName=g+"CollectionInit";const E=Nd(u=>{const{scope:G,children:m,state:p}=u,k=gA.useRef(null),[S,R]=gA.useState(null),F=Rd(k,R),[N,U]=p,P=gA.useRef(new gyA),b=gA.useCallback(()=>{const H=P.current;return XGI(H)||H.sort(eyA),H},[]);return gA.useEffect(()=>{if(!S)return;const H=$GI(()=>{U(q=>{const j=q.toSorted(eyA);return j.some(([O],AA)=>q.keyAt(AA)!==O)?j:q})});return H.observe(S,{childList:!0,subtree:!0}),()=>{H.disconnect()}},[S,U]),W.jsx(t,{scope:G,collectionElementRef:F,collectionElementRefObject:k,getCollection:b,setCollection:U,registryRef:P,children:W.jsx(o,{scope:G,collectionElement:S,collection:N,children:m})})},"CollectionProviderImpl");E.displayName=g+"CollectionProviderImpl";const n=g+"CollectionSlot",s=E5(n),r=gA.forwardRef((u,G)=>{const{scope:m,children:p}=u,k=B(n,m),S=Rd(G,k.collectionElementRef);return W.jsx(s,{ref:S,children:p})});r.displayName=n;const a=g+"CollectionItemSlot",c="data-radix-collection-item",h=E5(a),l=gA.forwardRef((u,G)=>{const{scope:m,children:p,...k}=u,S=gA.useRef(null),R=B(a,m),{setCollection:F,registryRef:N}=R,U=gA.useRef(k);jGI(U.current,k)||(U.current=k);const P=U.current,b=gA.useCallback(j=>{const Z=N.current;j?Z.set(j,{...U.current,element:j}):S.current&&Z.delete(S.current)},[N]),H=Rd(G,b,S);WM(()=>{const j=S.current,Z=N.current;j&&Z.has(j)&&Z.set(j,{...P,element:j})},[P,N]);const q=gA.useRef(null);return gA.useEffect(()=>{const j=S.current,Z=q.current;(Z?.element??null)===j&&(!j||Z?.itemData===P)||(q.current=j?{element:j,itemData:P}:null,F(O=>{const AA=new gyA(O);return Z&&Z.element!==j&&AA.delete(Z.element),j&&AA.set(j,{...P,element:j}),AA.sort(eyA)}))}),gA.useEffect(()=>()=>{const j=q.current;q.current=null,j&&F(Z=>{if(!Z.has(j.element))return Z;const O=new gyA(Z);return O.delete(j.element),O})},[F]),W.jsx(h,{[c]:"",ref:H,children:p})});l.displayName=a;function D(){return gA.useState(new gyA)}Nd(D,"useInitCollection");function d(u){const{collection:G}=C(g+"CollectionConsumer",u);return G}Nd(d,"useCollection");function y(u){const{getCollection:G}=B(g+"CollectionConsumer",u);return G}return Nd(y,"useGetCollection"),[{Provider:Q,Slot:r,ItemSlot:l},{createCollectionScope:e,useCollection:d,useGetCollection:y,useInitCollection:D}]}Nd(RWt,"createCollection");function jGI(g,A){if(g===A)return!0;if(typeof g!="object"||typeof A!="object"||g==null||A==null)return!1;const I=Object.keys(g),e=Object.keys(A);if(I.length!==e.length)return!1;for(const t of I)if(!Object.prototype.hasOwnProperty.call(A,t)||g[t]!==A[t])return!1;return!0}Nd(jGI,"shallowEqual");function zGI(g,A){return!!(A.compareDocumentPosition(g)&Node.DOCUMENT_POSITION_PRECEDING)}Nd(zGI,"isElementPreceding");function XGI(g){let A;for(const I of g.keys()){if(A){const e=A.compareDocumentPosition(I);if(!(e&Node.DOCUMENT_POSITION_DISCONNECTED)&&e&Node.DOCUMENT_POSITION_PRECEDING)return!1}A=I}return!0}Nd(XGI,"isInDocumentOrder");function eyA(g,A){return!g[1].element||!A[1].element?0:zGI(g[1].element,A[1].element)?-1:1}Nd(eyA,"sortByDocumentPosition");function $GI(g){return new MutationObserver(I=>{for(const e of I)if(e.type==="childList"){g();return}})}Nd($GI,"getChildListObserver");var NWt=Object.defineProperty,xWt=(g,A)=>NWt(g,"name",{value:A,configurable:!0}),FWt={LTR:"ltr"},UWt=gA.createContext(void 0);function QAg(g){const A=gA.useContext(UWt);return g||A||FWt.LTR}xWt(QAg,"useDirection");var JWt=Object.defineProperty,KWt=(g,A)=>JWt(g,"name",{value:A,configurable:!0}),AmI=Gp[" useInsertionEffect ".trim().toString()];function cx(g){const A=gA.useRef(g);return typeof AmI=="function"?AmI(()=>{A.current=g}):WM(()=>{A.current=g}),gA.useMemo(()=>((...I)=>A.current?.(...I)),[])}KWt(cx,"useCallbackRef");var PWt=Object.defineProperty,Sy=(g,A)=>PWt(g,"name",{value:A,configurable:!0}),iAg="dismissableLayer.update",LWt="dismissableLayer.pointerDownOutside",YWt="dismissableLayer.focusOutside",gmI,ImI=gA.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),_Wt=gA.forwardRef(Sy(function(A,I){const{disableOutsidePointerEvents:e=!1,deferPointerDownOutside:t=!1,onEscapeKeyDown:B,onPointerDownOutside:o,onFocusOutside:C,onInteractOutside:Q,onDismiss:i,...E}=A,n=gA.useContext(ImI),[s,r]=gA.useState(null),a=s?.ownerDocument??globalThis?.document,[,c]=gA.useState({}),h=Rd(I,r),l=Array.from(n.layers),[D]=[...n.layersWithOutsidePointerEventsDisabled].slice(-1),d=D?l.indexOf(D):-1,y=s?l.indexOf(s):-1,w=n.layersWithOutsidePointerEventsDisabled.size>0,u=y>=d,G=gA.useRef(!1),m=emI(R=>{o?.(R),Q?.(R),R.defaultPrevented||i?.()},{ownerDocument:a,deferPointerDownOutside:t,isDeferredPointerDownOutsideRef:G,dismissableSurfaces:n.dismissableSurfaces,shouldHandlePointerDownOutside:gA.useCallback(R=>{if(!(R instanceof Node))return!1;const F=[...n.branches].some(N=>N.contains(R));return u&&!F},[n.branches,u])}),p=tmI(R=>{if(t&&G.current)return;const F=R.target;[...n.branches].some(U=>U.contains(F))||(C?.(R),Q?.(R),R.defaultPrevented||i?.())},a),k=s?y===l.length-1:!1,S=cx(R=>{R.key==="Escape"&&(B?.(R),!R.defaultPrevented&&i&&(R.preventDefault(),i()))});return gA.useEffect(()=>{if(k)return a.addEventListener("keydown",S,{capture:!0}),()=>a.removeEventListener("keydown",S,{capture:!0})},[a,k,S]),gA.useEffect(()=>{if(s)return e&&(n.layersWithOutsidePointerEventsDisabled.size===0&&(gmI=a.body.style.pointerEvents,a.body.style.pointerEvents="none"),n.layersWithOutsidePointerEventsDisabled.add(s)),n.layers.add(s),EAg(),()=>{e&&(n.layersWithOutsidePointerEventsDisabled.delete(s),n.layersWithOutsidePointerEventsDisabled.size===0&&(a.body.style.pointerEvents=gmI))}},[s,a,e,n]),gA.useEffect(()=>()=>{s&&(n.layers.delete(s),n.layersWithOutsidePointerEventsDisabled.delete(s),EAg())},[s,n]),gA.useEffect(()=>{const R=Sy(()=>c({}),"handleUpdate");return document.addEventListener(iAg,R),()=>document.removeEventListener(iAg,R)},[]),W.jsx(rx.div,{...E,ref:h,style:{pointerEvents:w?u?"auto":"none":void 0,...A.style},onFocusCapture:un(A.onFocusCapture,p.onFocusCapture),onBlurCapture:un(A.onBlurCapture,p.onBlurCapture),onPointerDownCapture:un(A.onPointerDownCapture,m.onPointerDownCapture)})},"DismissableLayer"));function bWt(){const g=gA.useContext(ImI),[A,I]=gA.useState(null);return gA.useEffect(()=>{if(A)return g.dismissableSurfaces.add(A),()=>{g.dismissableSurfaces.delete(A)}},[A,g.dismissableSurfaces]),I}Sy(bWt,"useDismissableLayerSurface");var HWt=Sy(()=>!0,"IS_TRUE");function emI(g,A){const{ownerDocument:I=globalThis?.document,deferPointerDownOutside:e=!1,isDeferredPointerDownOutsideRef:t,dismissableSurfaces:B,shouldHandlePointerDownOutside:o=HWt}=A,C=cx(g),Q=gA.useRef(!1),i=gA.useRef(!1),E=gA.useRef(new Map),n=gA.useRef(()=>{});return gA.useEffect(()=>{function s(){i.current=!1,t.current=!1,E.current.clear()}Sy(s,"resetOutsideInteraction");function r(){return Array.from(E.current.values()).some(Boolean)}Sy(r,"isOutsideInteractionIntercepted");function a(d){if(!i.current)return;const y=d.target;y instanceof Node&&[...B].some(u=>u.contains(y))||E.current.set(d.type,!0),d.type==="click"&&window.setTimeout(()=>{i.current&&n.current()},0)}Sy(a,"handleInteractionCapture");function c(d){i.current&&E.current.set(d.type,!1)}Sy(c,"handleInteractionBubble");const h=Sy(d=>{if(d.target&&!Q.current){let y=function(){I.removeEventListener("click",n.current);const u=r();s(),u||nAg(LWt,C,w,{discrete:!0})};if(Sy(y,"handleAndDispatchPointerDownOutsideEvent"),!o(d.target)){I.removeEventListener("click",n.current),s(),Q.current=!1;return}const w={originalEvent:d};i.current=!0,t.current=e&&d.button===0,E.current.clear(),!e||d.button!==0?y():(I.removeEventListener("click",n.current),n.current=y,I.addEventListener("click",n.current,{once:!0}))}else I.removeEventListener("click",n.current),s();Q.current=!1},"handlePointerDown"),l=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const d of l)I.addEventListener(d,a,!0),I.addEventListener(d,c);const D=window.setTimeout(()=>{I.addEventListener("pointerdown",h)},0);return()=>{window.clearTimeout(D),I.removeEventListener("pointerdown",h),I.removeEventListener("click",n.current);for(const d of l)I.removeEventListener(d,a,!0),I.removeEventListener(d,c)}},[I,C,e,t,B,o]),{onPointerDownCapture:Sy(()=>Q.current=!0,"onPointerDownCapture")}}Sy(emI,"usePointerDownOutside");function tmI(g,A=globalThis?.document){const I=cx(g),e=gA.useRef(!1);return gA.useEffect(()=>{const t=Sy(B=>{B.target&&!e.current&&nAg(YWt,I,{originalEvent:B},{discrete:!1})},"handleFocus");return A.addEventListener("focusin",t),()=>A.removeEventListener("focusin",t)},[A,I]),{onFocusCapture:Sy(()=>e.current=!0,"onFocusCapture"),onBlurCapture:Sy(()=>e.current=!1,"onBlurCapture")}}Sy(tmI,"useFocusOutside");function EAg(){const g=new CustomEvent(iAg);document.dispatchEvent(g)}Sy(EAg,"dispatchUpdate");function nAg(g,A,I,{discrete:e}){const t=I.originalEvent.target,B=new CustomEvent(g,{bubbles:!1,cancelable:!0,detail:I});A&&t.addEventListener(g,A,{once:!0}),e?BAg(t,B):t.dispatchEvent(B)}Sy(nAg,"handleAndDispatchCustomEvent");var vWt=Object.defineProperty,sAg=(g,A)=>vWt(g,"name",{value:A,configurable:!0}),tyA=0,sT=null;function qWt(g){return aAg(),g.children}sAg(qWt,"FocusGuards");function aAg(){gA.useEffect(()=>{sT||(sT={start:rAg(),end:rAg()});const{start:g,end:A}=sT;return document.body.firstElementChild!==g&&document.body.insertAdjacentElement("afterbegin",g),document.body.lastElementChild!==A&&document.body.insertAdjacentElement("beforeend",A),tyA++,()=>{tyA===1&&(sT?.start.remove(),sT?.end.remove(),sT=null),tyA=Math.max(0,tyA-1)}},[])}sAg(aAg,"useFocusGuards");function rAg(){const g=document.createElement("span");return g.setAttribute("data-radix-focus-guard",""),g.tabIndex=0,g.style.outline="none",g.style.opacity="0",g.style.position="fixed",g.style.pointerEvents="none",g}sAg(rAg,"createFocusGuard");var TWt=Object.defineProperty,fD=(g,A)=>TWt(g,"name",{value:A,configurable:!0}),cAg="focusScope.autoFocusOnMount",hAg="focusScope.autoFocusOnUnmount",BmI={bubbles:!1,cancelable:!0},ZWt=gA.forwardRef(fD(function(A,I){const{loop:e=!1,trapped:t=!1,branches:B,onMountAutoFocus:o,onUnmountAutoFocus:C,...Q}=A,[i,E]=gA.useState(null),n=cx(o),s=cx(C),r=gA.useRef(null),a=Rd(I,E),c=gA.useRef(B);gA.useEffect(()=>{c.current=B});const h=gA.useCallback(d=>d?i?.contains(d)?!0:!!c.current?.some(y=>y.contains(d)):!1,[i]),l=gA.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;gA.useEffect(()=>{if(t){let d=function(G){if(l.paused||!i)return;const m=G.target;h(m)?r.current=m:IJ(r.current,{select:!0})},y=function(G){if(l.paused||!i)return;const m=G.relatedTarget;m!==null&&(h(m)||IJ(r.current,{select:!0}))},w=function(G){if(document.activeElement===document.body)for(const p of G)p.removedNodes.length>0&&IJ(i)};fD(d,"handleFocusIn"),fD(y,"handleFocusOut"),fD(w,"handleMutations"),document.addEventListener("focusin",d),document.addEventListener("focusout",y);const u=new MutationObserver(w);return i&&u.observe(i,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",d),document.removeEventListener("focusout",y),u.disconnect()}}},[t,i,l.paused,h]),gA.useEffect(()=>{if(i){rmI.add(l);const d=document.activeElement;if(!i.contains(d)){const w=new CustomEvent(cAg,BmI);i.addEventListener(cAg,n),i.dispatchEvent(w),w.defaultPrevented||(EmI(hmI(lAg(i)),{select:!0}),document.activeElement===d&&IJ(i))}return()=>{i.removeEventListener(cAg,n);const w=i.ownerDocument,u=CustomEvent;setTimeout(()=>{const G=new u(hAg,BmI);i.addEventListener(hAg,s),i.dispatchEvent(G),G.defaultPrevented||IJ(d??w.body,{select:!0}),i.removeEventListener(hAg,s),rmI.remove(l)},0)}}},[i,n,s,l]);const D=gA.useCallback(d=>{if(!e&&!t||l.paused)return;const y=d.key==="Tab"&&!d.altKey&&!d.ctrlKey&&!d.metaKey,w=document.activeElement;if(y&&w){const u=d.currentTarget,[G,m]=nmI(u);G&&m?!d.shiftKey&&w===m?(d.preventDefault(),e&&IJ(G,{select:!0})):d.shiftKey&&w===G&&(d.preventDefault(),e&&IJ(m,{select:!0})):w===u&&d.preventDefault()}},[e,t,l.paused]);return W.jsx(rx.div,{tabIndex:-1,...Q,ref:a,onKeyDown:D})},"FocusScope")),omI=gA.createContext(null);function CmI({registry:g,children:A}){return g?W.jsx(omI.Provider,{value:g,children:A}):A}fD(CmI,"FocusScopeBranchProvider");function QmI(){const[g,A]=gA.useState([]),I=gA.useMemo(()=>({add:fD(e=>A(t=>t.includes(e)?t:[...t,e]),"add"),remove:fD(e=>A(t=>t.filter(B=>B!==e)),"remove")}),[]);return{nodes:g,registry:I}}fD(QmI,"useFocusScopeBranchRegistry");function imI(g){const A=gA.useContext(omI);gA.useEffect(()=>{if(!(!g||!A))return A.add(g),()=>A.remove(g)},[g,A])}fD(imI,"useFocusScopeBranch");function EmI(g,{select:A=!1}={}){const I=document.activeElement;for(const e of g)if(IJ(e,{select:A}),document.activeElement!==I)return}fD(EmI,"focusFirst");function nmI(g){const A=lAg(g),I=DAg(A,g),e=DAg(A.reverse(),g);return[I,e]}fD(nmI,"getTabbableEdges");function lAg(g){const A=[],e=g.ownerDocument.createTreeWalker(g,NodeFilter.SHOW_ELEMENT,{acceptNode:fD(t=>{const B=t.tagName==="INPUT"&&t.type==="hidden";return t.disabled||t.hidden||B?NodeFilter.FILTER_SKIP:t.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;e.nextNode();)A.push(e.currentNode);return A}fD(lAg,"getTabbableCandidates");function DAg(g,A){const I=typeof A.checkVisibility=="function"&&A.checkVisibility({checkVisibilityCSS:!0});for(const e of g)if(!(I?!e.checkVisibility({checkVisibilityCSS:!0}):smI(e,{upTo:A})))return e}fD(DAg,"findVisible");function smI(g,{upTo:A}){if(getComputedStyle(g).visibility==="hidden")return!0;for(;g;){if(A!==void 0&&g===A)return!1;if(getComputedStyle(g).display==="none")return!0;g=g.parentElement}return!1}fD(smI,"isHidden");function amI(g){return g.tagName==="INPUT"&&typeof g.select=="function"}fD(amI,"isSelectableInput");function IJ(g,{select:A=!1}={}){if(g&&g.focus){const e=(g.ownerDocument??document).activeElement;g.focus({preventScroll:!0}),g!==e&&amI(g)&&A&&g.select()}}fD(IJ,"focus");var rmI=cmI();function cmI(){let g=[];return{add(A){const I=g[0];A!==I&&I?.pause(),g=dAg(g,A),g.unshift(A)},remove(A){g=dAg(g,A),g[0]?.resume()}}}fD(cmI,"createFocusScopesStack");function dAg(g,A){const I=[...g],e=I.indexOf(A);return e!==-1&&I.splice(e,1),I}fD(dAg,"arrayRemove");function hmI(g){return g.filter(A=>A.tagName!=="A")}fD(hmI,"removeLinks");var OWt=Object.defineProperty,WWt=(g,A)=>OWt(g,"name",{value:A,configurable:!0}),VWt=Gp[" useId ".trim().toString()]||(()=>{}),jWt=0;function aT(g){const[A,I]=gA.useState(VWt());return WM(()=>{g||I(e=>e??String(jWt++))},[g]),g||(A?`radix-${A}`:"")}WWt(aT,"useId");var zWt=["top","right","bottom","left"],E3=Math.min,eJ=Math.max,ByA=Math.round,oyA=Math.floor,tJ=g=>({x:g,y:g}),XWt={left:"right",right:"left",bottom:"top",top:"bottom"};function lmI(g,A,I){return eJ(g,E3(A,I))}function BJ(g,A){return typeof g=="function"?g(A):g}function n3(g){return g.split("-")[0]}function rT(g){return g.split("-")[1]}function yAg(g){return g==="x"?"y":"x"}function wAg(g){return g==="y"?"height":"width"}function hx(g){const A=g[0];return A==="t"||A==="b"?"y":"x"}function uAg(g){return yAg(hx(g))}function $Wt(g,A,I){I===void 0&&(I=!1);const e=rT(g),t=uAg(g),B=wAg(t);let o=t==="x"?e===(I?"end":"start")?"right":"left":e==="start"?"bottom":"top";return A.reference[B]>A.floating[B]&&(o=CyA(o)),[o,CyA(o)]}function AVt(g){const A=CyA(g);return[GAg(g),A,GAg(A)]}function GAg(g){return g.includes("start")?g.replace("start","end"):g.replace("end","start")}var DmI=["left","right"],dmI=["right","left"],gVt=["top","bottom"],IVt=["bottom","top"];function eVt(g,A,I){switch(g){case"top":case"bottom":return I?A?dmI:DmI:A?DmI:dmI;case"left":case"right":return A?gVt:IVt;default:return[]}}function tVt(g,A,I,e){const t=rT(g);let B=eVt(n3(g),I==="start",e);return t&&(B=B.map(o=>o+"-"+t),A&&(B=B.concat(B.map(GAg)))),B}function CyA(g){const A=n3(g);return XWt[A]+g.slice(A.length)}function BVt(g){var A,I,e,t;return{top:(A=g.top)!=null?A:0,right:(I=g.right)!=null?I:0,bottom:(e=g.bottom)!=null?e:0,left:(t=g.left)!=null?t:0}}function ymI(g){return typeof g!="number"?BVt(g):{top:g,right:g,bottom:g,left:g}}function QyA(g){const{x:A,y:I,width:e,height:t}=g;return{width:e,height:t,top:I,left:A,right:A+e,bottom:I+t,x:A,y:I}}function wmI(g,A,I){let{reference:e,floating:t}=g;const B=hx(A),o=uAg(A),C=wAg(o),Q=n3(A),i=B==="y",E=e.x+e.width/2-t.width/2,n=e.y+e.height/2-t.height/2,s=e[C]/2-t[C]/2;let r;switch(Q){case"top":r={x:E,y:e.y-t.height};break;case"bottom":r={x:E,y:e.y+e.height};break;case"right":r={x:e.x+e.width,y:n};break;case"left":r={x:e.x-t.width,y:n};break;default:r={x:e.x,y:e.y}}const a=rT(A);return a&&(r[o]+=s*(a==="end"?1:-1)*(I&&i?-1:1)),r}async function oVt(g,A){var I;A===void 0&&(A={});const{x:e,y:t,platform:B,rects:o,elements:C,strategy:Q}=g,{boundary:i="clippingAncestors",rootBoundary:E="viewport",elementContext:n="floating",altBoundary:s=!1,padding:r=0}=BJ(A,g),a=ymI(r),h=C[s?n==="floating"?"reference":"floating":n],l=QyA(await B.getClippingRect({element:(I=await(B.isElement==null?void 0:B.isElement(h)))==null||I?h:h.contextElement||await(B.getDocumentElement==null?void 0:B.getDocumentElement(C.floating)),boundary:i,rootBoundary:E,strategy:Q})),D=n==="floating"?{x:e,y:t,width:o.floating.width,height:o.floating.height}:o.reference,d=await(B.getOffsetParent==null?void 0:B.getOffsetParent(C.floating)),y=await(B.isElement==null?void 0:B.isElement(d))&&await(B.getScale==null?void 0:B.getScale(d))||{x:1,y:1},w=QyA(B.convertOffsetParentRelativeRectToViewportRelativeRect?await B.convertOffsetParentRelativeRectToViewportRelativeRect({elements:C,rect:D,offsetParent:d,strategy:Q}):D);return{top:(l.top-w.top+a.top)/y.y,bottom:(w.bottom-l.bottom+a.bottom)/y.y,left:(l.left-w.left+a.left)/y.x,right:(w.right-l.right+a.right)/y.x}}var CVt=50,QVt=async(g,A,I)=>{const{placement:e="bottom",strategy:t="absolute",middleware:B=[],platform:o}=I,C=o.detectOverflow?o:{...o,detectOverflow:oVt},Q=await(o.isRTL==null?void 0:o.isRTL(A));let i=await o.getElementRects({reference:g,floating:A,strategy:t}),{x:E,y:n}=wmI(i,e,Q),s=e,r=0;const a={};for(let c=0;c<B.length;c++){const h=B[c];if(!h)continue;const{name:l,fn:D}=h,{x:d,y,data:w,reset:u}=await D({x:E,y:n,initialPlacement:e,placement:s,strategy:t,middlewareData:a,rects:i,platform:C,elements:{reference:g,floating:A}});E=d??E,n=y??n,a[l]={...a[l],...w},u&&r<CVt&&(r++,typeof u=="object"&&(u.placement&&(s=u.placement),u.rects&&(i=u.rects===!0?await o.getElementRects({reference:g,floating:A,strategy:t}):u.rects),{x:E,y:n}=wmI(i,s,Q)),c=-1)}return{x:E,y:n,placement:s,strategy:t,middlewareData:a}},iVt=g=>({name:"arrow",options:g,async fn(A){const{x:I,y:e,placement:t,rects:B,platform:o,elements:C,middlewareData:Q}=A,{element:i,padding:E=0}=BJ(g,A)||{};if(i==null)return{};const n=ymI(E),s={x:I,y:e},r=uAg(t),a=wAg(r),c=await o.getDimensions(i),h=r==="y",l=h?"top":"left",D=h?"bottom":"right",d=h?"clientHeight":"clientWidth",y=B.reference[a]+B.reference[r]-s[r]-B.floating[a],w=s[r]-B.reference[r],u=await(o.getOffsetParent==null?void 0:o.getOffsetParent(i));let G=u?u[d]:0;(!G||!await(o.isElement==null?void 0:o.isElement(u)))&&(G=C.floating[d]||B.floating[a]);const m=y/2-w/2,p=G/2-c[a]/2-1,k=E3(n[l],p),S=E3(n[D],p),R=G-c[a]-S,F=G/2-c[a]/2+m,N=lmI(k,F,R),U=!Q.arrow&&rT(t)!=null&&F!==N&&B.reference[a]/2-(F<k?k:S)-c[a]/2<0,P=U?F<k?F-k:F-R:0;return{[r]:s[r]+P,data:{[r]:N,centerOffset:F-N-P,...U&&{alignmentOffset:P}},reset:U}}}),EVt=function(g){return g===void 0&&(g={}),{name:"flip",options:g,async fn(A){var I,e;const{placement:t,middlewareData:B,rects:o,initialPlacement:C,platform:Q,elements:i}=A,{mainAxis:E=!0,crossAxis:n=!0,fallbackPlacements:s,fallbackStrategy:r="bestFit",fallbackAxisSideDirection:a="none",flipAlignment:c=!0,...h}=BJ(g,A);if((I=B.arrow)!=null&&I.alignmentOffset)return{};const l=n3(t),D=hx(C),d=n3(C)===C,y=await(Q.isRTL==null?void 0:Q.isRTL(i.floating)),w=s||(d||!c?[CyA(C)]:AVt(C)),u=a!=="none";!s&&u&&w.push(...tVt(C,c,a,y));const G=[C,...w],m=await Q.detectOverflow(A,h),p=[];let k=((e=B.flip)==null?void 0:e.overflows)||[];if(E&&p.push(m[l]),n){const N=$Wt(t,o,y);p.push(m[N[0]],m[N[1]])}if(k=[...k,{placement:t,overflows:p}],!p.every(N=>N<=0)){var S,R;const N=(((S=B.flip)==null?void 0:S.index)||0)+1,U=G[N];if(U&&(!(n==="alignment"?D!==hx(U):!1)||k.every(H=>hx(H.placement)===D?H.overflows[0]>0:!0)))return{data:{index:N,overflows:k},reset:{placement:U}};let P=(R=k.filter(b=>b.overflows[0]<=0).sort((b,H)=>b.overflows[1]-H.overflows[1])[0])==null?void 0:R.placement;if(!P)switch(r){case"bestFit":{var F;const b=(F=k.filter(H=>{if(u){const q=hx(H.placement);return q===D||q==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(q=>q>0).reduce((q,j)=>q+j,0)]).sort((H,q)=>H[1]-q[1])[0])==null?void 0:F[0];b&&(P=b);break}case"initialPlacement":P=C;break}if(t!==P)return{reset:{placement:P}}}return{}}}};function umI(g,A){return{top:g.top-A.height,right:g.right-A.width,bottom:g.bottom-A.height,left:g.left-A.width}}function GmI(g){return zWt.some(A=>g[A]>=0)}var nVt=function(g){return g===void 0&&(g={}),{name:"hide",options:g,async fn(A){const{rects:I,platform:e}=A,{strategy:t="referenceHidden",...B}=BJ(g,A);switch(t){case"referenceHidden":{const o=await e.detectOverflow(A,{...B,elementContext:"reference"}),C=umI(o,I.reference);return{data:{referenceHiddenOffsets:C,referenceHidden:GmI(C)}}}case"escaped":{const o=await e.detectOverflow(A,{...B,altBoundary:!0}),C=umI(o,I.floating);return{data:{escapedOffsets:C,escaped:GmI(C)}}}default:return{}}}}},mmI=new Set(["left","top"]);async function sVt(g,A){const{placement:I,platform:e,elements:t}=g,B=await(e.isRTL==null?void 0:e.isRTL(t.floating)),o=n3(I),C=rT(I),Q=hx(I)==="y",i=mmI.has(o)?-1:1,E=B&&Q?-1:1,n=BJ(A,g);let{mainAxis:s,crossAxis:r,alignmentAxis:a}=typeof n=="number"?{mainAxis:n,crossAxis:0,alignmentAxis:null}:{mainAxis:n.mainAxis||0,crossAxis:n.crossAxis||0,alignmentAxis:n.alignmentAxis};return C&&typeof a=="number"&&(r=C==="end"?a*-1:a),Q?{x:r*E,y:s*i}:{x:s*i,y:r*E}}var aVt=function(g){return g===void 0&&(g=0),{name:"offset",options:g,async fn(A){var I,e;const{x:t,y:B,placement:o,middlewareData:C}=A,Q=await sVt(A,g);return o===((I=C.offset)==null?void 0:I.placement)&&(e=C.arrow)!=null&&e.alignmentOffset?{}:{x:t+Q.x,y:B+Q.y,data:{...Q,placement:o}}}}},rVt=function(g){return g===void 0&&(g={}),{name:"shift",options:g,async fn(A){const{x:I,y:e,placement:t,platform:B}=A,{mainAxis:o=!0,crossAxis:C=!1,limiter:Q={fn:D=>{let{x:d,y}=D;return{x:d,y}}},...i}=BJ(g,A),E={x:I,y:e},n=await B.detectOverflow(A,i),s=hx(t),r=yAg(s);let a=E[r],c=E[s];const h=(D,d)=>lmI(d+n[D==="y"?"top":"left"],d,d-n[D==="y"?"bottom":"right"]);o&&(a=h(r,a)),C&&(c=h(s,c));const l=Q.fn({...A,[r]:a,[s]:c});return{...l,data:{x:l.x-I,y:l.y-e,enabled:{[r]:o,[s]:C}}}}}},cVt=function(g){return g===void 0&&(g={}),{options:g,fn(A){var I,e;const{x:t,y:B,placement:o,rects:C,middlewareData:Q}=A,{offset:i=0,mainAxis:E=!0,crossAxis:n=!0}=BJ(g,A),s={x:t,y:B},r=hx(o),a=yAg(r);let c=s[a],h=s[r];const l=BJ(i,A),D=typeof l=="number"?{mainAxis:l,crossAxis:0}:{mainAxis:(I=l.mainAxis)!=null?I:0,crossAxis:(e=l.crossAxis)!=null?e:0};if(E){const w=a==="y"?"height":"width",u=C.reference[a]-C.floating[w]+D.mainAxis,G=C.reference[a]+C.reference[w]-D.mainAxis;c<u?c=u:c>G&&(c=G)}if(n){var d,y;const w=a==="y"?"width":"height",u=mmI.has(n3(o)),G=C.reference[r]-C.floating[w]+(u&&((d=Q.offset)==null?void 0:d[r])||0)+(u?0:D.crossAxis),m=C.reference[r]+C.reference[w]+(u?0:((y=Q.offset)==null?void 0:y[r])||0)-(u?D.crossAxis:0);h<G?h=G:h>m&&(h=m)}return{[a]:c,[r]:h}}}},hVt=function(g){return g===void 0&&(g={}),{name:"size",options:g,async fn(A){const{placement:I,rects:e,platform:t,elements:B}=A,{apply:o=()=>{},...C}=BJ(g,A),Q=await t.detectOverflow(A,C),i=n3(I),E=rT(I),n=hx(I)==="y",{width:s,height:r}=e.floating;let a,c;i==="top"||i==="bottom"?(a=i,c=E===(await(t.isRTL==null?void 0:t.isRTL(B.floating))?"start":"end")?"left":"right"):(c=i,a=E==="end"?"top":"bottom");const h=r-Q.top-Q.bottom,l=s-Q.left-Q.right,D=E3(r-Q[a],h),d=E3(s-Q[c],l),y=A.middlewareData.shift,w=!y;let u=D,G=d;y!=null&&y.enabled.x&&(G=l),y!=null&&y.enabled.y&&(u=h),w&&!E&&(n?G=s-2*eJ(Q.left,Q.right):u=r-2*eJ(Q.top,Q.bottom)),await o({...A,availableWidth:G,availableHeight:u});const m=await t.getDimensions(B.floating);return s!==m.width||r!==m.height?{reset:{rects:!0}}:{}}}};function iyA(){return typeof window<"u"}function cT(g){return pmI(g)?(g.nodeName||"").toLowerCase():"#document"}function ik(g){var A;return(g==null||(A=g.ownerDocument)==null?void 0:A.defaultView)||window}function oJ(g){var A;return(A=(pmI(g)?g.ownerDocument:g.document)||window.document)==null?void 0:A.documentElement}function pmI(g){return iyA()?g instanceof Node||g instanceof ik(g).Node:!1}function lx(g){return iyA()?g instanceof Element||g instanceof ik(g).Element:!1}function s3(g){return iyA()?g instanceof HTMLElement||g instanceof ik(g).HTMLElement:!1}function kmI(g){return!iyA()||typeof ShadowRoot>"u"?!1:g instanceof ShadowRoot||g instanceof ik(g).ShadowRoot}function EyA(g){const{overflow:A,overflowX:I,overflowY:e,display:t}=Dx(g);return/auto|scroll|overlay|hidden|clip/.test(A+e+I)&&t!=="inline"&&t!=="contents"}function lVt(g){return/^(table|td|th)$/.test(cT(g))}function nyA(g){try{if(g.matches(":popover-open"))return!0}catch{}try{return g.matches(":modal")}catch{return!1}}var DVt=/transform|translate|scale|rotate|perspective|filter/,dVt=/paint|layout|strict|content/,n5=g=>!!g&&g!=="none",mAg;function pAg(g){const A=lx(g)?Dx(g):g;return n5(A.transform)||n5(A.translate)||n5(A.scale)||n5(A.rotate)||n5(A.perspective)||!kAg()&&(n5(A.backdropFilter)||n5(A.filter))||DVt.test(A.willChange||"")||dVt.test(A.contain||"")}function yVt(g){let A=s5(g);for(;s3(A)&&!rIA(A);){if(pAg(A))return A;if(nyA(A))return null;A=s5(A)}return null}function kAg(){return mAg==null&&(mAg=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),mAg}function rIA(g){return/^(html|body|#document)$/.test(cT(g))}function Dx(g){return ik(g).getComputedStyle(g)}function syA(g){return lx(g)?{scrollLeft:g.scrollLeft,scrollTop:g.scrollTop}:{scrollLeft:g.scrollX,scrollTop:g.scrollY}}function s5(g){if(cT(g)==="html")return g;const A=g.assignedSlot||g.parentNode||kmI(g)&&g.host||oJ(g);return kmI(A)?A.host:A}function MmI(g){const A=s5(g);return rIA(A)?(g.ownerDocument||g).body:s3(A)&&EyA(A)?A:MmI(A)}function cIA(g,A,I){var e;A===void 0&&(A=[]),I===void 0&&(I=!0);const t=MmI(g),B=t===((e=g.ownerDocument)==null?void 0:e.body),o=ik(t);if(B){const C=MAg(o);return A.concat(o,o.visualViewport||[],EyA(t)?t:[],C&&I?cIA(C):[])}else return A.concat(t,cIA(t,[],I))}function MAg(g){return g.parent&&Object.getPrototypeOf(g.parent)?g.frameElement:null}function SmI(g){const A=Dx(g);let I=parseFloat(A.width)||0,e=parseFloat(A.height)||0;const t=s3(g),B=t?g.offsetWidth:I,o=t?g.offsetHeight:e,C=ByA(I)!==B||ByA(e)!==o;return C&&(I=B,e=o),{width:I,height:e,$:C}}function SAg(g){return lx(g)?g:g.contextElement}function hT(g){const A=SAg(g);if(!s3(A))return tJ(1);const I=A.getBoundingClientRect(),{width:e,height:t,$:B}=SmI(A);let o=(B?ByA(I.width):I.width)/e,C=(B?ByA(I.height):I.height)/t;return(!o||!Number.isFinite(o))&&(o=1),(!C||!Number.isFinite(C))&&(C=1),{x:o,y:C}}var wVt=tJ(0);function fmI(g){const A=ik(g);return!kAg()||!A.visualViewport?wVt:{x:A.visualViewport.offsetLeft,y:A.visualViewport.offsetTop}}function uVt(g,A,I){return A===void 0&&(A=!1),!!I&&A&&I===ik(g)}function a5(g,A,I,e){A===void 0&&(A=!1),I===void 0&&(I=!1);const t=g.getBoundingClientRect(),B=SAg(g);let o=tJ(1);A&&(e?lx(e)&&(o=hT(e)):o=hT(g));const C=uVt(B,I,e)?fmI(B):tJ(0);let Q=(t.left+C.x)/o.x,i=(t.top+C.y)/o.y,E=t.width/o.x,n=t.height/o.y;if(B&&e){const s=ik(B),r=lx(e)?ik(e):e;let a=s,c=MAg(a);for(;c&&r!==a;){const h=hT(c),l=c.getBoundingClientRect(),D=Dx(c),d=l.left+(c.clientLeft+parseFloat(D.paddingLeft))*h.x,y=l.top+(c.clientTop+parseFloat(D.paddingTop))*h.y;Q*=h.x,i*=h.y,E*=h.x,n*=h.y,Q+=d,i+=y,a=ik(c),c=MAg(a)}}return QyA({width:E,height:n,x:Q,y:i})}function ayA(g,A){const I=syA(g).scrollLeft;return A?A.left+I:a5(oJ(g)).left+I}function RmI(g,A){const I=g.getBoundingClientRect(),e=I.left+A.scrollLeft-ayA(g,I),t=I.top+A.scrollTop;return{x:e,y:t}}function GVt(g){let{elements:A,rect:I,offsetParent:e,strategy:t}=g;const B=t==="fixed",o=oJ(e),C=A?nyA(A.floating):!1;if(e===o||C&&B)return I;let Q={scrollLeft:0,scrollTop:0},i=tJ(1);const E=tJ(0),n=s3(e);if((n||!B)&&((cT(e)!=="body"||EyA(o))&&(Q=syA(e)),n)){const r=a5(e);i=hT(e),E.x=r.x+e.clientLeft,E.y=r.y+e.clientTop}const s=o&&!n&&!B?RmI(o,Q):tJ(0);return{width:I.width*i.x,height:I.height*i.y,x:I.x*i.x-Q.scrollLeft*i.x+E.x+s.x,y:I.y*i.y-Q.scrollTop*i.y+E.y+s.y}}function mVt(g){return g.getClientRects?Array.from(g.getClientRects()):[]}function pVt(g){const A=syA(g),I=g.ownerDocument.body,e=eJ(g.scrollWidth,g.clientWidth,I.scrollWidth,I.clientWidth),t=eJ(g.scrollHeight,g.clientHeight,I.scrollHeight,I.clientHeight);let B=-A.scrollLeft+ayA(g);const o=-A.scrollTop;return Dx(I).direction==="rtl"&&(B+=eJ(g.clientWidth,I.clientWidth)-e),{width:e,height:t,x:B,y:o}}var kVt=25;function MVt(g,A,I){I===void 0&&(I="viewport");const e=I==="layoutViewport",t=ik(g),B=oJ(g),o=t.visualViewport;let C=B.clientWidth,Q=B.clientHeight,i=0,E=0;if(o){const s=!kAg()||A==="fixed";e?s||(i=-o.offsetLeft,E=-o.offsetTop):(C=o.width,Q=o.height,s&&(i=o.offsetLeft,E=o.offsetTop))}if(ayA(B)<=0){const s=B.ownerDocument,r=s.body,a=getComputedStyle(r),c=s.compatMode==="CSS1Compat"&&parseFloat(a.marginLeft)+parseFloat(a.marginRight)||0,h=Math.abs(B.clientWidth-r.clientWidth-c),l=getComputedStyle(B).scrollbarGutter==="stable both-edges"?h/2:h;l<=kVt&&(C-=l)}return{width:C,height:Q,x:i,y:E}}function SVt(g,A){const I=a5(g,!0,A==="fixed"),e=I.top+g.clientTop,t=I.left+g.clientLeft,B=hT(g),o=g.clientWidth*B.x,C=g.clientHeight*B.y,Q=t*B.x,i=e*B.y;return{width:o,height:C,x:Q,y:i}}function NmI(g,A,I){let e;if(A==="viewport"||A==="layoutViewport")e=MVt(g,I,A);else if(A==="document")e=pVt(oJ(g));else if(lx(A))e=SVt(A,I);else{const t=fmI(g);e={x:A.x-t.x,y:A.y-t.y,width:A.width,height:A.height}}return QyA(e)}function fVt(g,A){const I=A.get(g);if(I)return I;let e=cIA(g,[],!1).filter(C=>lx(C)&&cT(C)!=="body"),t=null;const B=Dx(g).position==="fixed";let o=B?s5(g):g;for(;lx(o)&&!rIA(o);){const C=Dx(o),Q=pAg(o),i=t?t.position:B?"fixed":"";!Q&&(i==="fixed"||i==="absolute"&&C.position==="static")?e=e.filter(n=>n!==o):t=C,o=s5(o)}return A.set(g,e),e}function RVt(g){let{element:A,boundary:I,rootBoundary:e,strategy:t}=g;const o=[...I==="clippingAncestors"?nyA(A)?[]:fVt(A,this._c):[].concat(I),e],C=NmI(A,o[0],t);let Q=C.top,i=C.right,E=C.bottom,n=C.left;for(let s=1;s<o.length;s++){const r=NmI(A,o[s],t);Q=eJ(r.top,Q),i=E3(r.right,i),E=E3(r.bottom,E),n=eJ(r.left,n)}return{width:i-n,height:E-Q,x:n,y:Q}}function NVt(g){const{width:A,height:I}=SmI(g);return{width:A,height:I}}function xVt(g,A,I){const e=s3(A),t=oJ(A),B=I==="fixed",o=a5(g,!0,B,A);let C={scrollLeft:0,scrollTop:0};const Q=tJ(0);if((e||!B)&&((cT(A)!=="body"||EyA(t))&&(C=syA(A)),e)){const s=a5(A,!0,B,A);Q.x=s.x+A.clientLeft,Q.y=s.y+A.clientTop}!e&&t&&(Q.x=ayA(t));const i=t&&!e&&!B?RmI(t,C):tJ(0),E=o.left+C.scrollLeft-Q.x-i.x,n=o.top+C.scrollTop-Q.y-i.y;return{x:E,y:n,width:o.width,height:o.height}}function fAg(g){return Dx(g).position==="static"}function xmI(g,A){if(!s3(g)||Dx(g).position==="fixed")return null;if(A)return A(g);let I=g.offsetParent;return oJ(g)===I&&(I=I.ownerDocument.body),I}function FmI(g,A){const I=ik(g);if(nyA(g))return I;if(!s3(g)){let t=s5(g);for(;t&&!rIA(t);){if(lx(t)&&!fAg(t))return t;t=s5(t)}return I}let e=xmI(g,A);for(;e&&lVt(e)&&fAg(e);)e=xmI(e,A);return e&&rIA(e)&&fAg(e)&&!pAg(e)?I:e||yVt(g)||I}var FVt=async function(g){const A=this.getOffsetParent||FmI,I=this.getDimensions,e=await I(g.floating);return{reference:xVt(g.reference,await A(g.floating),g.strategy),floating:{x:0,y:0,width:e.width,height:e.height}}};function UVt(g){return Dx(g).direction==="rtl"}var JVt={convertOffsetParentRelativeRectToViewportRelativeRect:GVt,getDocumentElement:oJ,getClippingRect:RVt,getOffsetParent:FmI,getElementRects:FVt,getClientRects:mVt,getDimensions:NVt,getScale:hT,isElement:lx,isRTL:UVt};function UmI(g,A){return g.x===A.x&&g.y===A.y&&g.width===A.width&&g.height===A.height}function KVt(g,A,I){let e=null,t;const B=oJ(g);function o(){var E;clearTimeout(t),(E=e)==null||E.disconnect(),e=null}function C(E,n){E===void 0&&(E=!1),n===void 0&&(n=1),o();const s=g.getBoundingClientRect(),{left:r,top:a,width:c,height:h}=s;if(E||A(),!c||!h)return;const l=oyA(a),D=oyA(B.clientWidth-(r+c)),d=oyA(B.clientHeight-(a+h)),y=oyA(r),u={rootMargin:-l+"px "+-D+"px "+-d+"px "+-y+"px",threshold:eJ(0,E3(1,n))||1};let G=!0;function m(p){const k=p[0].intersectionRatio;if(!UmI(s,g.getBoundingClientRect()))return C();if(k!==n){if(!G)return C();k?C(!1,k):t=setTimeout(()=>{C(!1,1e-7)},1e3)}G=!1}try{e=new IntersectionObserver(m,{...u,root:B.ownerDocument})}catch{e=new IntersectionObserver(m,u)}e.observe(g)}const Q=ik(g),i=()=>C(I);return Q.addEventListener("resize",i),C(!0),()=>{Q.removeEventListener("resize",i),o()}}function PVt(g,A,I,e){e===void 0&&(e={});const{ancestorScroll:t=!0,ancestorResize:B=!0,elementResize:o=typeof ResizeObserver=="function",layoutShift:C=typeof IntersectionObserver=="function",animationFrame:Q=!1}=e,i=SAg(g),E=t||B?[...i?cIA(i):[],...A?cIA(A):[]]:[];E.forEach(l=>{t&&l.addEventListener("scroll",I),B&&l.addEventListener("resize",I)});const n=i&&C?KVt(i,I,B):null;let s=-1,r=null;o&&(r=new ResizeObserver(l=>{let[D]=l;D&&D.target===i&&r&&A&&(r.unobserve(A),cancelAnimationFrame(s),s=requestAnimationFrame(()=>{var d;(d=r)==null||d.observe(A)})),I()}),i&&!Q&&r.observe(i),A&&r.observe(A));let a,c=Q?a5(g):null;Q&&h();function h(){const l=a5(g);c&&!UmI(c,l)&&I(),c=l,a=requestAnimationFrame(h)}return I(),()=>{var l;E.forEach(D=>{t&&D.removeEventListener("scroll",I),B&&D.removeEventListener("resize",I)}),n?.(),(l=r)==null||l.disconnect(),r=null,Q&&cancelAnimationFrame(a)}}var LVt=aVt,YVt=rVt,_Vt=EVt,bVt=hVt,HVt=nVt,JmI=iVt,vVt=cVt,qVt=(g,A,I)=>{const e=new Map,t=I??{},B={...JVt,...t.platform,_c:e};return QVt(g,A,{...t,platform:B})},TVt=typeof document<"u",ZVt=function(){},ryA=TVt?gA.useLayoutEffect:ZVt;function cyA(g,A){if(g===A)return!0;if(typeof g!=typeof A)return!1;if(typeof g=="function"&&g.toString()===A.toString())return!0;let I,e,t;if(g&&A&&typeof g=="object"){if(Array.isArray(g)){if(I=g.length,I!==A.length)return!1;for(e=I;e--!==0;)if(!cyA(g[e],A[e]))return!1;return!0}if(t=Object.keys(g),I=t.length,I!==Object.keys(A).length)return!1;for(e=I;e--!==0;)if(!{}.hasOwnProperty.call(A,t[e]))return!1;for(e=I;e--!==0;){const B=t[e];if(!(B==="_owner"&&g.$$typeof)&&!cyA(g[B],A[B]))return!1}return!0}return g!==g&&A!==A}function KmI(g){return typeof window>"u"?1:(g.ownerDocument.defaultView||window).devicePixelRatio||1}function PmI(g,A){const I=KmI(g);return Math.round(A*I)/I}function RAg(g){const A=gA.useRef(g);return ryA(()=>{A.current=g}),A}function OVt(g){g===void 0&&(g={});const{placement:A="bottom",strategy:I="absolute",middleware:e=[],platform:t,elements:{reference:B,floating:o}={},transform:C=!0,whileElementsMounted:Q,open:i}=g,[E,n]=gA.useState({x:0,y:0,strategy:I,placement:A,middlewareData:{},isPositioned:!1}),[s,r]=gA.useState(e);cyA(s,e)||r(e);const[a,c]=gA.useState(null),[h,l]=gA.useState(null),D=gA.useCallback(H=>{H!==u.current&&(u.current=H,c(H))},[]),d=gA.useCallback(H=>{H!==G.current&&(G.current=H,l(H))},[]),y=B||a,w=o||h,u=gA.useRef(null),G=gA.useRef(null),m=gA.useRef(E),p=Q!=null,k=RAg(Q),S=RAg(t),R=RAg(i),F=gA.useCallback(()=>{if(!u.current||!G.current)return;const H={placement:A,strategy:I,middleware:s};S.current&&(H.platform=S.current),qVt(u.current,G.current,H).then(q=>{const j={...q,isPositioned:R.current!==!1};N.current&&!cyA(m.current,j)&&(m.current=j,CN.flushSync(()=>{n(j)}))})},[s,A,I,S,R]);ryA(()=>{i===!1&&m.current.isPositioned&&(m.current.isPositioned=!1,n(H=>({...H,isPositioned:!1})))},[i]);const N=gA.useRef(!1);ryA(()=>(N.current=!0,()=>{N.current=!1}),[]),ryA(()=>{if(y&&(u.current=y),w&&(G.current=w),y&&w){if(k.current)return k.current(y,w,F);F()}},[y,w,F,k,p]);const U=gA.useMemo(()=>({reference:u,floating:G,setReference:D,setFloating:d}),[D,d]),P=gA.useMemo(()=>({reference:y,floating:w}),[y,w]),b=gA.useMemo(()=>{const H={position:I,left:0,top:0};if(!P.floating)return H;const q=PmI(P.floating,E.x),j=PmI(P.floating,E.y);return C?{...H,transform:"translate("+q+"px, "+j+"px)",...KmI(P.floating)>=1.5&&{willChange:"transform"}}:{position:I,left:q,top:j}},[I,C,P.floating,E.x,E.y]);return gA.useMemo(()=>({...E,update:F,refs:U,elements:P,floatingStyles:b}),[E,F,U,P,b])}var WVt=g=>{function A(I){return{}.hasOwnProperty.call(I,"current")}return{name:"arrow",options:g,fn(I){const{element:e,padding:t}=typeof g=="function"?g(I):g;return e&&A(e)?e.current!=null?JmI({element:e.current,padding:t}).fn(I):{}:e?JmI({element:e,padding:t}).fn(I):{}}}},VVt=(g,A)=>{const I=LVt(g);return{name:I.name,fn:I.fn,options:[g,A]}},jVt=(g,A)=>{const I=YVt(g);return{name:I.name,fn:I.fn,options:[g,A]}},zVt=(g,A)=>({fn:vVt(g).fn,options:[g,A]}),XVt=(g,A)=>{const I=_Vt(g);return{name:I.name,fn:I.fn,options:[g,A]}},$Vt=(g,A)=>{const I=bVt(g);return{name:I.name,fn:I.fn,options:[g,A]}},Ajt=(g,A)=>{const I=HVt(g);return{name:I.name,fn:I.fn,options:[g,A]}},gjt=(g,A)=>{const I=WVt(g);return{name:I.name,fn:I.fn,options:[g,A]}},Ijt=Object.defineProperty,ejt=(g,A)=>Ijt(g,"name",{value:A,configurable:!0});function LmI(g){const[A,I]=gA.useState(void 0);return WM(()=>{if(g){I({width:g.offsetWidth,height:g.offsetHeight});let e=0;const t=new ResizeObserver(B=>{if(!Array.isArray(B)||!B.length)return;const o=B[0];window.cancelAnimationFrame(e),e=window.requestAnimationFrame(()=>{let C,Q;if("borderBoxSize"in o){const i=o.borderBoxSize,E=Array.isArray(i)?i[0]:i;C=E.inlineSize,Q=E.blockSize}else C=g.offsetWidth,Q=g.offsetHeight;I({width:C,height:Q})})});return t.observe(g,{box:"border-box"}),()=>{window.cancelAnimationFrame(e),t.unobserve(g)}}else I(void 0)},[g]),A}ejt(LmI,"useSize");var tjt=Object.defineProperty,a3=(g,A)=>tjt(g,"name",{value:A,configurable:!0}),YmI={Partial:"partial"},_mI={Optimized:"optimized",Always:"always"},bmI="Popper",[HmI,vmI]=i5(bmI),[Bjt,qmI]=HmI(bmI),TmI=a3(g=>{const{__scopePopper:A,children:I}=g,[e,t]=gA.useState(null),[B,o]=gA.useState(void 0);return W.jsx(Bjt,{scope:A,anchor:e,onAnchorChange:t,placementState:B,setPlacementState:o,children:I})},"Popper"),ojt="PopperAnchor",Cjt=gA.forwardRef(a3(function(A,I){const{__scopePopper:e,virtualRef:t,...B}=A,o=qmI(ojt,e),C=gA.useRef(null),Q=o.onAnchorChange,i=gA.useCallback(c=>{C.current=c,c&&Q(c)},[Q]),E=Rd(I,i),n=gA.useRef(null);gA.useEffect(()=>{if(!t)return;const c=n.current;n.current=t.current,c!==n.current&&Q(n.current)});const s=o.placementState&&hyA(o.placementState),r=s?.[0],a=s?.[1];return t?null:W.jsx(rx.div,{"data-radix-popper-side":r,"data-radix-popper-align":a,...B,ref:E})},"PopperAnchor")),ZmI="PopperContent",[Qjt,iWB]=HmI(ZmI),ijt=gA.forwardRef(a3(function(A,I){const{__scopePopper:e,side:t="bottom",sideOffset:B=0,align:o="center",alignOffset:C=0,arrowPadding:Q=0,avoidCollisions:i=!0,collisionBoundary:E=[],collisionPadding:n=0,sticky:s=YmI.Partial,hideWhenDetached:r=!1,updatePositionStrategy:a=_mI.Optimized,onPlaced:c,...h}=A,l=qmI(ZmI,e),[D,d]=gA.useState(null),y=Rd(I,d),[w,u]=gA.useState(null),G=LmI(w),m=G?.width??0,p=G?.height??0,k=t+(o!=="center"?"-"+o:""),S=typeof n=="number"?n:{top:0,right:0,bottom:0,left:0,...n},R=Array.isArray(E)?E:[E],F=R.length>0,N={padding:S,boundary:R.filter(OmI),altBoundary:F},{refs:U,floatingStyles:P,placement:b,isPositioned:H,middlewareData:q}=OVt({strategy:"fixed",placement:k,whileElementsMounted:a3((...CA)=>PVt(...CA,{animationFrame:a===_mI.Always}),"whileElementsMounted"),elements:{reference:l.anchor},middleware:[VVt({mainAxis:B+p,alignmentAxis:C}),i&&jVt({mainAxis:!0,crossAxis:!1,...s===YmI.Partial?{limiter:zVt()}:{},...N}),i&&XVt({...N}),$Vt({...N,apply:a3(({elements:CA,rects:cA,availableWidth:nA,availableHeight:hA})=>{const{width:fA,height:NA}=cA.reference,aA=CA.floating.style;aA.setProperty("--radix-popper-available-width",`${nA}px`),aA.setProperty("--radix-popper-available-height",`${hA}px`),aA.setProperty("--radix-popper-anchor-width",`${fA}px`),aA.setProperty("--radix-popper-anchor-height",`${NA}px`)},"apply")}),w&&gjt({element:w,padding:Q}),Ejt({arrowWidth:m,arrowHeight:p}),r&&Ajt(F?{strategy:"referenceHidden",...N}:{strategy:"referenceHidden",padding:N.padding,altBoundary:N.altBoundary})]}),j=l.setPlacementState;WM(()=>(j(b),()=>{j(void 0)}),[b,j]);const[Z,O]=hyA(b),AA=cx(c);WM(()=>{H&&AA?.()},[H,AA]);const tA=q.arrow?.x,eA=q.arrow?.y,iA=q.arrow?.centerOffset!==0,[sA,DA]=gA.useState();return WM(()=>{D&&DA(window.getComputedStyle(D).zIndex)},[D]),W.jsx("div",{ref:U.setFloating,"data-radix-popper-content-wrapper":"",style:{...P,transform:H?P.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:sA,"--radix-popper-transform-origin":[q.transformOrigin?.x,q.transformOrigin?.y].join(" "),...q.hide?.referenceHidden&&{visibility:"hidden",pointerEvents:"none"}},dir:A.dir,children:W.jsx(Qjt,{scope:e,placedSide:Z,placedAlign:O,onArrowChange:u,arrowX:tA,arrowY:eA,shouldHideArrow:iA,children:W.jsx(rx.div,{"data-side":Z,"data-align":O,...h,ref:y,style:{...h.style,animation:H?h.style?.animation:"none"}})})})},"PopperContent"));function OmI(g){return g!==null}a3(OmI,"isNotNull");var Ejt=a3(g=>({name:"transformOrigin",options:g,fn(A){const{placement:I,rects:e,middlewareData:t}=A,o=t.arrow?.centerOffset!==0,C=o?0:g.arrowWidth,Q=o?0:g.arrowHeight,[i,E]=hyA(I),n={start:"0%",center:"50%",end:"100%"}[E],s=(t.arrow?.x??0)+C/2,r=(t.arrow?.y??0)+Q/2;let a="",c="";return i==="bottom"?(a=o?n:`${s}px`,c=`${-Q}px`):i==="top"?(a=o?n:`${s}px`,c=`${e.floating.height+Q}px`):i==="right"?(a=`${-Q}px`,c=o?n:`${r}px`):i==="left"&&(a=`${e.floating.width+Q}px`,c=o?n:`${r}px`),{data:{x:a,y:c}}}}),"transformOrigin");function hyA(g){const[A,I="center"]=g.split("-");return[A,I]}a3(hyA,"getSideAndAlignFromPlacement");var njt=Object.defineProperty,sjt=(g,A)=>njt(g,"name",{value:A,configurable:!0}),ajt=gA.forwardRef(sjt(function(A,I){const{container:e,...t}=A,[B,o]=gA.useState(!1);WM(()=>o(!0),[]);const C=e||B&&globalThis?.document?.body;return C?CN.createPortal(W.jsx(rx.div,{...t,ref:I}),C):null},"Portal")),rjt=Object.defineProperty,CJ=(g,A)=>rjt(g,"name",{value:A,configurable:!0});function WmI(g,A){return gA.useReducer((I,e)=>A[I][e]??I,g)}CJ(WmI,"useStateMachine");var NAg=CJ(g=>{const{present:A,children:I}=g,e=VmI(A),t=typeof I=="function"?I({present:e.isPresent}):gA.Children.only(I),B=jmI(e.ref,zmI(t));return typeof I=="function"||e.isPresent?gA.cloneElement(t,{ref:B}):null},"Presence");function VmI(g){const[A,I]=gA.useState(),e=gA.useRef(null),t=gA.useRef(g),B=gA.useRef("none"),o=gA.useRef(void 0),C=g?"mounted":"unmounted",[Q,i]=WmI(C,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return gA.useEffect(()=>{Q==="mounted"?(B.current=o.current??lT(e.current),o.current=void 0):B.current="none"},[Q]),WM(()=>{const E=e.current,n=t.current;if(n!==g){const r=B.current,a=lT(E);g?(o.current=a,i("MOUNT")):a==="none"||E?.display==="none"?i("UNMOUNT"):i(n&&r!==a?"ANIMATION_OUT":"UNMOUNT"),t.current=g}},[g,i]),WM(()=>{if(A){let E;const n=A.ownerDocument.defaultView??window,s=CJ(a=>{const h=lT(e.current).includes(CSS.escape(a.animationName));if(a.target===A&&h&&(i("ANIMATION_END"),!t.current)){const l=A.style.animationFillMode;A.style.animationFillMode="forwards",E=n.setTimeout(()=>{A.style.animationFillMode==="forwards"&&(A.style.animationFillMode=l)})}},"handleAnimationEnd"),r=CJ(a=>{a.target===A&&(B.current=lT(e.current))},"handleAnimationStart");return A.addEventListener("animationstart",r),A.addEventListener("animationcancel",s),A.addEventListener("animationend",s),()=>{n.clearTimeout(E),A.removeEventListener("animationstart",r),A.removeEventListener("animationcancel",s),A.removeEventListener("animationend",s)}}else i("ANIMATION_END")},[A,i]),{isPresent:["mounted","unmountSuspended"].includes(Q),ref:gA.useCallback(E=>{if(E){const n=getComputedStyle(E);e.current=n,o.current=lT(n)}else e.current=null;I(E)},[])}}CJ(VmI,"usePresence");function xAg(g,A){if(typeof g=="function")return g(A);g!=null&&(g.current=A)}CJ(xAg,"setRef");function jmI(...g){const A=gA.useRef(g);return A.current=g,gA.useCallback(I=>{const e=A.current;let t=!1;const B=e.map(o=>{const C=xAg(o,I);return!t&&typeof C=="function"&&(t=!0),C});if(t)return()=>{for(let o=0;o<B.length;o++){const C=B[o];typeof C=="function"?C():xAg(e[o],null)}}},[])}CJ(jmI,"useStableComposedRefs");function lT(g){return g?.animationName||"none"}CJ(lT,"getAnimationName");function zmI(g){let A=Object.getOwnPropertyDescriptor(g.props,"ref")?.get,I=A&&"isReactWarning"in A&&A.isReactWarning;return I?g.ref:(A=Object.getOwnPropertyDescriptor(g,"ref")?.get,I=A&&"isReactWarning"in A&&A.isReactWarning,I?g.props.ref:g.props.ref||g.ref)}CJ(zmI,"getElementRef");var cjt=Object.defineProperty,FAg=(g,A)=>cjt(g,"name",{value:A,configurable:!0}),UAg=!1;function XmI(){const[g,A]=gA.useState(UAg);return gA.useEffect(()=>{UAg||(UAg=!0,A(!0))},[]),g}FAg(XmI,"useIsHydrated");var $mI=Gp[" useSyncExternalStore ".trim().toString()];function ApI(){return()=>{}}FAg(ApI,"subscribe");function gpI(){return $mI(ApI,()=>!0,()=>!1)}FAg(gpI,"useIsHydratedModern");var hjt=typeof $mI=="function"?gpI:XmI,ljt=Object.defineProperty,r5=(g,A)=>ljt(g,"name",{value:A,configurable:!0}),JAg="rovingFocusGroup.onEntryFocus",Djt={bubbles:!1,cancelable:!0},lyA="RovingFocusGroup",[KAg,IpI,djt]=oAg(lyA),[yjt,epI]=i5(lyA,[djt]),tpI={Vertical:"vertical",Horizontal:"horizontal"},wjt={RTL:"rtl"},[ujt,Gjt]=yjt(lyA),mjt=gA.forwardRef(r5(function(A,I){return W.jsx(KAg.Provider,{scope:A.__scopeRovingFocusGroup,children:W.jsx(KAg.Slot,{scope:A.__scopeRovingFocusGroup,children:W.jsx(pjt,{...A,ref:I})})})},"RovingFocusGroup")),pjt=gA.forwardRef(r5(function(A,I){const{__scopeRovingFocusGroup:e,orientation:t,loop:B=!1,dir:o,currentTabStopId:C,defaultCurrentTabStopId:Q,onCurrentTabStopIdChange:i,onEntryFocus:E,preventScrollOnEntryFocus:n=!1,...s}=A,r=gA.useRef(null),a=Rd(I,r),c=QAg(o),[h,l]=$dA({prop:C,defaultProp:Q??null,onChange:i,caller:lyA}),[D,d]=gA.useState(!1),y=cx(E),w=IpI(e),u=gA.useRef(!1),[G,m]=gA.useState(0);return gA.useEffect(()=>{const p=r.current;if(p)return p.addEventListener(JAg,y),()=>p.removeEventListener(JAg,y)},[y]),W.jsx(ujt,{scope:e,orientation:t,dir:c,loop:B,currentTabStopId:h,onItemFocus:gA.useCallback(p=>l(p),[l]),onItemShiftTab:gA.useCallback(()=>d(!0),[]),onFocusableItemAdd:gA.useCallback(()=>m(p=>p+1),[]),onFocusableItemRemove:gA.useCallback(()=>m(p=>p-1),[]),children:W.jsx(rx.div,{tabIndex:D||G===0?-1:0,"data-orientation":t,...s,ref:a,style:{outline:"none",...A.style},onMouseDown:un(A.onMouseDown,()=>{u.current=!0}),onFocus:un(A.onFocus,p=>{const k=!u.current;if(p.target===p.currentTarget&&k&&!D){const S=new CustomEvent(JAg,Djt);if(p.currentTarget.dispatchEvent(S),!S.defaultPrevented){const R=w().filter(b=>b.focusable),F=R.find(b=>b.active),N=R.find(b=>b.id===h),P=[F,N,...R].filter(Boolean).map(b=>b.ref.current);PAg(P,n)}}u.current=!1}),onBlur:un(A.onBlur,()=>d(!1))})})},"RovingFocusGroupImpl")),kjt="RovingFocusGroupItem",Mjt=gA.forwardRef(r5(function(A,I){const{__scopeRovingFocusGroup:e,focusable:t=!0,active:B=!1,tabStopId:o,children:C,...Q}=A,i=aT(),E=o||i,n=Gjt(kjt,e),s=n.currentTabStopId===E,r=IpI(e),{onFocusableItemAdd:a,onFocusableItemRemove:c,currentTabStopId:h}=n,l=hjt();return WM(()=>{if(!(!l||!t))return a(),()=>c()},[l,t,a,c]),gA.useEffect(()=>{if(!(l||!t))return a(),()=>c()},[l,t,a,c]),W.jsx(KAg.ItemSlot,{scope:e,id:E,focusable:t,active:B,children:W.jsx(rx.span,{tabIndex:s?0:-1,"data-orientation":n.orientation,...Q,ref:I,onMouseDown:un(A.onMouseDown,D=>{t?n.onItemFocus(E):D.preventDefault()}),onFocus:un(A.onFocus,()=>n.onItemFocus(E)),onKeyDown:un(A.onKeyDown,D=>{if(D.key==="Tab"&&D.shiftKey){n.onItemShiftTab();return}if(D.target!==D.currentTarget)return;const d=opI(D,n.orientation,n.dir);if(d!==void 0){if(D.metaKey||D.ctrlKey||D.altKey||D.shiftKey)return;D.preventDefault();let w=r().filter(u=>u.focusable).map(u=>u.ref.current);if(d==="last")w.reverse();else if(d==="prev"||d==="next"){d==="prev"&&w.reverse();const u=w.indexOf(D.currentTarget);w=n.loop?CpI(w,u+1):w.slice(u+1)}setTimeout(()=>PAg(w))}}),children:typeof C=="function"?C({isCurrentTabStop:s,hasTabStop:h!=null}):C})})},"RovingFocusGroupItem")),Sjt={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function BpI(g,A){return A!==wjt.RTL?g:g==="ArrowLeft"?"ArrowRight":g==="ArrowRight"?"ArrowLeft":g}r5(BpI,"getDirectionAwareKey");function opI(g,A,I){const e=BpI(g.key,I);if(!(A===tpI.Vertical&&["ArrowLeft","ArrowRight"].includes(e))&&!(A===tpI.Horizontal&&["ArrowUp","ArrowDown"].includes(e)))return Sjt[e]}r5(opI,"getFocusIntent");function PAg(g,A=!1){const I=document.activeElement;for(const e of g)if(e===I||(e.focus({preventScroll:A}),document.activeElement!==I))return}r5(PAg,"focusFirst");function CpI(g,A){return g.map((I,e)=>g[(A+e)%g.length])}r5(CpI,"wrapArray");var fjt=function(g){if(typeof document>"u")return null;var A=Array.isArray(g)?g[0]:g;return A.ownerDocument.body},DT=new WeakMap,DyA=new WeakMap,dyA={},LAg=0,QpI=function(g){return g&&(g.host||QpI(g.parentNode))},Rjt=function(g,A){return A.map(function(I){if(g.contains(I))return I;var e=QpI(I);return e&&g.contains(e)?e:(console.error("aria-hidden",I,"in not contained inside",g,". Doing nothing"),null)}).filter(function(I){return!!I})},Njt=function(g,A,I,e){var t=Rjt(A,Array.isArray(g)?g:[g]);dyA[I]||(dyA[I]=new WeakMap);var B=dyA[I],o=[],C=new Set,Q=new Set(t),i=function(n){!n||C.has(n)||(C.add(n),i(n.parentNode))};t.forEach(i);var E=function(n){!n||Q.has(n)||Array.prototype.forEach.call(n.children,function(s){if(C.has(s))E(s);else try{var r=s.getAttribute(e),a=r!==null&&r!=="false",c=(DT.get(s)||0)+1,h=(B.get(s)||0)+1;DT.set(s,c),B.set(s,h),o.push(s),c===1&&a&&DyA.set(s,!0),h===1&&s.setAttribute(I,"true"),a||s.setAttribute(e,"true")}catch(l){console.error("aria-hidden: cannot operate on ",s,l)}})};return E(A),C.clear(),LAg++,function(){o.forEach(function(n){var s=DT.get(n)-1,r=B.get(n)-1;DT.set(n,s),B.set(n,r),s||(DyA.has(n)||n.removeAttribute(e),DyA.delete(n)),r||n.removeAttribute(I)}),LAg--,LAg||(DT=new WeakMap,DT=new WeakMap,DyA=new WeakMap,dyA={})}},xjt=function(g,A,I){I===void 0&&(I="data-aria-hidden");var e=Array.from(Array.isArray(g)?g:[g]),t=fjt(g);return t?(e.push.apply(e,Array.from(t.querySelectorAll("[aria-live], script"))),Njt(e,t,I,"aria-hidden")):function(){return null}},dx=function(){return dx=Object.assign||function(A){for(var I,e=1,t=arguments.length;e<t;e++){I=arguments[e];for(var B in I)Object.prototype.hasOwnProperty.call(I,B)&&(A[B]=I[B])}return A},dx.apply(this,arguments)};function ipI(g,A){var I={};for(var e in g)Object.prototype.hasOwnProperty.call(g,e)&&A.indexOf(e)<0&&(I[e]=g[e]);if(g!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(g);t<e.length;t++)A.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(g,e[t])&&(I[e[t]]=g[e[t]]);return I}function Fjt(g,A,I){for(var e=0,t=A.length,B;e<t;e++)(B||!(e in A))&&(B||(B=Array.prototype.slice.call(A,0,e)),B[e]=A[e]);return g.concat(B||Array.prototype.slice.call(A))}var yyA="right-scroll-bar-position",wyA="width-before-scroll-bar",Ujt="with-scroll-bars-hidden",Jjt="--removed-body-scroll-bar-size";function YAg(g,A){return typeof g=="function"?g(A):g&&(g.current=A),g}function Kjt(g,A){var I=gA.useState(function(){return{value:g,callback:A,facade:{get current(){return I.value},set current(e){var t=I.value;t!==e&&(I.value=e,I.callback(e,t))}}}})[0];return I.callback=A,I.facade}var Pjt=typeof window<"u"?gA.useLayoutEffect:gA.useEffect,EpI=new WeakMap;function Ljt(g,A){var I=Kjt(null,function(e){return g.forEach(function(t){return YAg(t,e)})});return Pjt(function(){var e=EpI.get(I);if(e){var t=new Set(e),B=new Set(g),o=I.current;t.forEach(function(C){B.has(C)||YAg(C,null)}),B.forEach(function(C){t.has(C)||YAg(C,o)})}EpI.set(I,g)},[g]),I}function Yjt(g){return g}function _jt(g,A){A===void 0&&(A=Yjt);var I=[],e=!1,t={read:function(){if(e)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return I.length?I[I.length-1]:g},useMedium:function(B){var o=A(B,e);return I.push(o),function(){I=I.filter(function(C){return C!==o})}},assignSyncMedium:function(B){for(e=!0;I.length;){var o=I;I=[],o.forEach(B)}I={push:function(C){return B(C)},filter:function(){return I}}},assignMedium:function(B){e=!0;var o=[];if(I.length){var C=I;I=[],C.forEach(B),o=I}var Q=function(){var E=o;o=[],E.forEach(B)},i=function(){return Promise.resolve().then(Q)};i(),I={push:function(E){o.push(E),i()},filter:function(E){return o=o.filter(E),I}}}};return t}function bjt(g){g===void 0&&(g={});var A=_jt(null);return A.options=dx({async:!0,ssr:!1},g),A}var npI=function(g){var A=g.sideCar,I=ipI(g,["sideCar"]);if(!A)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var e=A.read();if(!e)throw new Error("Sidecar medium not found");return gA.createElement(e,dx({},I))};npI.isSideCarExport=!0;function Hjt(g,A){return g.useMedium(A),npI}var spI=bjt(),_Ag=function(){},uyA=gA.forwardRef(function(g,A){var I=gA.useRef(null),e=gA.useState({onScrollCapture:_Ag,onWheelCapture:_Ag,onTouchMoveCapture:_Ag}),t=e[0],B=e[1],o=g.forwardProps,C=g.children,Q=g.className,i=g.removeScrollBar,E=g.enabled,n=g.shards,s=g.sideCar,r=g.noRelative,a=g.noIsolation,c=g.inert,h=g.allowPinchZoom,l=g.as,D=l===void 0?"div":l,d=g.gapMode,y=ipI(g,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),w=s,u=Ljt([I,A]),G=dx(dx({},y),t);return gA.createElement(gA.Fragment,null,E&&gA.createElement(w,{sideCar:spI,removeScrollBar:i,shards:n,noRelative:r,noIsolation:a,inert:c,setCallbacks:B,allowPinchZoom:!!h,lockRef:I,gapMode:d}),o?gA.cloneElement(gA.Children.only(C),dx(dx({},G),{ref:u})):gA.createElement(D,dx({},G,{className:Q,ref:u}),C))});uyA.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},uyA.classNames={fullWidth:wyA,zeroRight:yyA};var vjt=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function qjt(){if(!document)return null;var g=document.createElement("style");g.type="text/css";var A=vjt();return A&&g.setAttribute("nonce",A),g}function Tjt(g,A){g.styleSheet?g.styleSheet.cssText=A:g.appendChild(document.createTextNode(A))}function Zjt(g){var A=document.head||document.getElementsByTagName("head")[0];A.appendChild(g)}var Ojt=function(){var g=0,A=null;return{add:function(I){g==0&&(A=qjt())&&(Tjt(A,I),Zjt(A)),g++},remove:function(){g--,!g&&A&&(A.parentNode&&A.parentNode.removeChild(A),A=null)}}},Wjt=function(){var g=Ojt();return function(A,I){gA.useEffect(function(){return g.add(A),function(){g.remove()}},[A&&I])}},apI=function(){var g=Wjt(),A=function(I){var e=I.styles,t=I.dynamic;return g(e,t),null};return A},Vjt={left:0,top:0,right:0,gap:0},bAg=function(g){return parseInt(g||"",10)||0},jjt=function(g){var A=window.getComputedStyle(document.body),I=A[g==="padding"?"paddingLeft":"marginLeft"],e=A[g==="padding"?"paddingTop":"marginTop"],t=A[g==="padding"?"paddingRight":"marginRight"];return[bAg(I),bAg(e),bAg(t)]},zjt=function(g){if(g===void 0&&(g="margin"),typeof window>"u")return Vjt;var A=jjt(g),I=document.documentElement.clientWidth,e=window.innerWidth;return{left:A[0],top:A[1],right:A[2],gap:Math.max(0,e-I+A[2]-A[0])}},Xjt=apI(),dT="data-scroll-locked",$jt=function(g,A,I,e){var t=g.left,B=g.top,o=g.right,C=g.gap;return I===void 0&&(I="margin"),`
|
|
5354
5354
|
.`.concat(Ujt,` {
|
|
5355
5355
|
overflow: hidden `).concat(e,`;
|
|
5356
5356
|
padding-right: `).concat(C,"px ").concat(e,`;
|
|
@@ -5661,7 +5661,7 @@ test("${i} should solve problem correctly", () => {
|
|
|
5661
5661
|
// Add more specific assertions based on expected output
|
|
5662
5662
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5663
5663
|
})
|
|
5664
|
-
`,n=new Blob([E],{type:"text/plain"}),s=URL.createObjectURL(n),r=document.createElement("a");r.href=s,r.download=`${i}.test.ts`,r.click(),URL.revokeObjectURL(s)}catch(Q){alert(`Error generating test.ts for ${g.getSolverName()}: ${Q instanceof Error?Q.message:String(Q)}`)}e(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:t,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>e(!I),title:`Download options for ${g.getSolverName()}`,children:g.getSolverName()}),I&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:B,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:C,children:"Download test.ts"})]})]})},C1I=g=>g.activeSubSolver?[g,...C1I(g.activeSubSolver)]:[g],e0B=({solver:g})=>{const A=C1I(g);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((I,e)=>W.jsxs("div",{className:"flex items-center",children:[e>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(I0B,{solver:I})]},I.getSolverName()))})},t0B=({solver:g,triggerRender:A,animationSpeed:I=25,renderer:e,onRendererChange:t,onAnimationSpeedChange:B,onDownloadVisualization:o,onSolverStarted:C,onSolverCompleted:Q})=>{const[i,E]=gA.useReducer(m=>!m,!1),n=gA.useRef(void 0),s=gA.useRef(null),r="solver-debugger-last-iteration",[a,c]=gA.useState(null),h=gA.useRef(null),l=gA.useMemo(()=>[{label:"Slow",value:250,description:"250ms"},{label:"Normal",value:100,description:"100ms"},{label:"Fast",value:10,description:"10ms"},{label:"Fast (2x)",value:5,description:"5ms"},{label:"Fast (10x)",value:1,description:"1ms"},{label:"Fast 20x",value:.5,description:"2 steps / 1ms"},{label:"Fast 100x",value:.1,description:"10 steps / 1ms"}],[]),D=()=>{const m=Math.max(1,I),p=I<1?Math.round(1/I):1;n.current=setInterval(()=>{if(g.solved||g.failed){n.current&&(clearInterval(n.current),n.current=void 0),E(),A(),Q&&g.solved&&Q(g);return}for(let k=0;k<p&&!(g.solved||g.failed);k++)g.step();A()},m)},d=()=>{n.current&&(clearInterval(n.current),n.current=void 0)},y=()=>{!g.solved&&!g.failed&&(g.step(),A())},w=()=>{!g.solved&&!g.failed&&(C&&C(g),g.solve(),A(),Q&&Q(g))},u=()=>{i?(d(),E()):(E(),D())},G=()=>{if(g.solved||g.failed||i)return;s.current===null&&typeof window<"u"&&(s.current=window.localStorage.getItem(r));const m=window.prompt("Step until which iteration?",s.current??`${g.iterations}`);if(m===null)return;s.current=m,typeof window<"u"&&window.localStorage.setItem(r,m);const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;g.iterations<p&&!g.solved&&!g.failed;)g.step();A(),g.solved&&Q&&Q(g)};return gA.useEffect(()=>()=>{d()},[]),gA.useEffect(()=>{(g.solved||g.failed)&&i&&(d(),E())},[g.solved,g.failed,i]),gA.useEffect(()=>{i&&(d(),D())},[I,i]),gA.useEffect(()=>{if(typeof document>"u")return;const m=p=>{h.current&&!h.current.contains(p.target)&&c(null)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[]),W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsxs("div",{className:"flex items-center gap-2",ref:h,children:[W.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="renderer"?null:"renderer"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="renderer"?"open":"closed",children:"Renderer"}),a==="renderer"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[10rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:["vector","canvas"].map(m=>W.jsxs("button",{type:"button",onClick:()=>{t(m),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m==="vector"?"Vector":"Canvas",e===m&&W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},m))})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="debug"?null:"debug"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="debug"?"open":"closed",children:"Debug"}),a==="debug"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:W.jsx("button",{type:"button",onClick:()=>{o(),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="animation"?null:"animation"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="animation"?"open":"closed",children:"Animation"}),a==="animation"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:l.map(m=>W.jsxs("button",{type:"button",onClick:()=>{B(m.value),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m.label,W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:m.description}),I===m.value&&W.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},m.value))})]})]}),W.jsx(e0B,{solver:g})]})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:y,disabled:g.solved||g.failed||i,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:w,disabled:g.solved||g.failed||i,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:u,disabled:g.solved||g.failed,className:`px-3 py-1 rounded text-white text-sm ${i?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:i?"Stop":"Animate"}),W.jsx("button",{onClick:G,disabled:g.solved||g.failed||i,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",g.iterations]}),g.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(g.timeToSolve/1e3).toFixed(3),"s"]}),g.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),g.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),g.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",g.error]})]})},B0B=g=>g!==null&&"pipelineDef"in g&&Array.isArray(g.pipelineDef),o0B=(g,A,I)=>{const e=g.currentPipelineStageIndex;return A<e?"Completed":A===e&&g.activeSubSolver?g.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},C0B=(g,A)=>{const e=g.pipelineDef[A].solverName,t=o0B(g,A),B=g[e],o=g.firstIterationOfStage?.[e]??(A===g.currentPipelineStageIndex?g.iterations:null),C=g.iterations;let Q=0;if(t==="Completed"){const s=g.pipelineDef[A+1],r=s?g.firstIterationOfStage?.[s.solverName]:void 0;r!==void 0&&o!==null?Q=r-o:o!==null&&(Q=C-o)}else t==="In Progress"&&o!==null&&(Q=C-o);const i=g.timeSpentOnStage?.[e]??0;let E=0;t==="Completed"?E=1:t==="In Progress"&&B&&(E=B.progress??0);const n=B?.stats??null;return{index:A,name:e,status:t,firstIteration:o,iterations:Q,progress:E,timeSpent:i,stats:n&&Object.keys(n).length>0?n:null,solverInstance:B??null}},Q0B=({status:g})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[g]}`,children:g})},i0B=({progress:g})=>{if(g===0)return null;const A=Math.round(g*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},Q1I=g=>{if(typeof g=="string")return g;if(typeof g=="number"||typeof g=="boolean"||typeof g=="bigint"||g==null)return String(g);if(typeof g=="object")try{return JSON.stringify(g)}catch{return String(g)}return String(g)},E0B=g=>Object.entries(g).map(([A,I])=>`${A}: ${Q1I(I)}`).join(", "),n0B=({stats:g})=>{if(!g||Object.keys(g).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(g),I=E0B(g);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:I}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([e,t])=>W.jsxs("div",{children:[e,": ",Q1I(t)]},e))})]})},ttg=g=>{if(g===null||typeof g!="object")return g;if(Array.isArray(g))return g.map(ttg);const A={};for(const[I,e]of Object.entries(g))I.startsWith("_")||(A[I]=ttg(e));return A},s0B=(g,A)=>{try{if(typeof g.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const I=ttg(g.getConstructorParams()),e=new Blob([JSON.stringify(I,null,2)],{type:"application/json"}),t=URL.createObjectURL(e),B=document.createElement("a");B.href=t,B.download=`${A}_input.json`,B.click(),URL.revokeObjectURL(t)}catch(I){alert(`Error downloading input for ${A}: ${I instanceof Error?I.message:String(I)}`)}},a0B=({expanded:g})=>W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:`w-4 h-4 transition-transform duration-200 ${g?"rotate-90":""}`,children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})}),i1I=g=>{let A=g;for(;A.activeSubSolver;)A=A.activeSubSolver;return A},E1I=({solver:g,onStepUntilPhase:A,onDownloadInput:I,isNested:e=!1,indentLevel:t=0,triggerRender:B})=>{const[o,C]=gA.useState(new Set),Q=g.pipelineDef.map((h,l)=>C0B(g,l)),i=h=>{C(l=>{const D=new Set(l);return D.has(h)?D.delete(h):D.add(h),D})},E=h=>{A?.(h)},n=h=>{h.solverInstance&&(I?I(h.solverInstance,h.name):s0B(h.solverInstance,h.name))},s=h=>`${(h/1e3).toFixed(2)}s`,r=()=>{if(!g.solved&&!g.failed){const h=g.activeSubSolver;for(;!g.solved&&!g.failed&&(g.step(),!(g.activeSubSolver&&g.activeSubSolver!==h)););B?.()}},a=()=>{if(!g.solved&&!g.failed){const h=i1I(g);for(;!g.solved&&!g.failed&&(g.step(),i1I(g)===h););B?.()}},c=t*24;return W.jsxs("div",{className:e?"":"border-t border-gray-200",children:[!e&&W.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),W.jsxs("div",{className:"flex gap-2",children:[W.jsx("button",{onClick:a,disabled:g.solved||g.failed,className:"bg-indigo-500 hover:bg-indigo-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Solver"}),W.jsx("button",{onClick:r,disabled:g.solved||g.failed,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Stage"})]})]}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[!e&&W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:Q.map(h=>{const l=B0B(h.solverInstance),D=o.has(h.name);return W.jsxs(nC.Fragment,{children:[W.jsxs("tr",{className:`border-b border-gray-100 ${h.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:c},children:[l?W.jsx("button",{onClick:()=>i(h.name),className:"text-gray-500 hover:text-gray-700",title:D?"Collapse":"Expand",children:W.jsx(a0B,{expanded:D})}):W.jsx("span",{className:"w-4"}),W.jsx("span",{className:"text-gray-400 w-6",children:String(h.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>E(h.name),disabled:h.status==="Completed"||g.solved||g.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${h.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:h.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(Q0B,{status:h.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:h.firstIteration!==null?h.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:h.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(i0B,{progress:h.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(h.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(n0B,{stats:h.stats})}),W.jsx("td",{className:"px-4 py-2",children:h.solverInstance?W.jsxs("button",{onClick:()=>n(h),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${h.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]}),l&&D&&W.jsx("tr",{children:W.jsx("td",{colSpan:8,className:"p-0",children:W.jsx(E1I,{solver:h.solverInstance,onStepUntilPhase:A,onDownloadInput:I,isNested:!0,indentLevel:t+1,triggerRender:B})})})]},h.name)})})]})})]})};function r0B({graphics:g}){const A=g.points??[],I=g.lines??[],e=g.rects??[],t=g.circles??[],B=g.texts??[];let o=Number.POSITIVE_INFINITY,C=Number.POSITIVE_INFINITY,Q=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;const E=(h,l)=>{typeof h=="number"&&(h<o&&(o=h),h>Q&&(Q=h)),typeof l=="number"&&(l<C&&(C=l),l>i&&(i=l))};for(const h of A)E(h.x,h.y);for(const h of I){const l=h.points??[];for(const D of l)E(D.x,D.y)}for(const h of e){const l=h.x??0,D=h.y??0,d=h.width??0,y=h.height??0;E(l,D),E(l+d,D+y)}for(const h of t){const l=h.x??0,D=h.y??0,d=h.radius??1;E(l-d,D-d),E(l+d,D+d)}for(const h of B)E(h.x,h.y);(!isFinite(o)||!isFinite(C)||!isFinite(Q)||!isFinite(i))&&(o=-20,C=-20,Q=20,i=20);const n=10,s=o-n,r=C-n,a=Math.max(1,Q-o+2*n),c=Math.max(1,i-C+2*n);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${s} ${r} ${a} ${c}`,role:"img","aria-label":"Graphics fallback",children:[e.map((h,l)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${l}`)),I.map((h,l)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(D=>`${D.x??0},${D.y??0}`).join(" ")},`line-${l}`)),t.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${l}`)),A.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${l}`)),B.map((h,l)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${l}`))]})}var c0B=class extends nC.Component{constructor(g){super(g),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(g){console.error("InteractiveGraphics render error:",g)}render(){return this.state.hasError?this.props.fallback:this.props.children}},h0B=({solver:g,createSolver:A,animationSpeed:I=25,onSolverStarted:e,onSolverCompleted:t})=>{const[B,o]=gA.useReducer(D=>D+1,0),[C]=gA.useState(()=>{if(A)return A();if(!g)throw new Error("GenericSolverDebugger requires solver or createSolver");return g}),[Q,i]=gA.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[E,n]=gA.useState(I),s=gA.useMemo(()=>{try{return C.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(D){return console.error("Visualization error:",D),{points:[],lines:[],rects:[],circles:[]}}},[C,B]),r=gA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);gA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const D=document.createElement("script");D.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(D)}},[]),gA.useEffect(()=>{n(I)},[I]);const a=C.pipelineDef!==void 0,c=D=>{const d=C;if(!C.solved&&!C.failed){for(;!C.solved&&!C.failed&&d.currentPipelineStageIndex<=d.pipelineDef.findIndex(y=>y.solverName===D);)C.step();o()}},h=()=>{const D=JSON.stringify(s,null,2),d=new Blob([D],{type:"application/json"}),y=URL.createObjectURL(d),w=document.createElement("a");w.download="visualization.json",w.href=y,document.body.appendChild(w),w.click(),document.body.removeChild(w),URL.revokeObjectURL(y)},l=D=>{i(D),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",D)};return W.jsxs("div",{children:[W.jsx(t0B,{solver:C,triggerRender:o,animationSpeed:E,renderer:Q,onRendererChange:l,onAnimationSpeedChange:n,onDownloadVisualization:h,onSolverStarted:e,onSolverCompleted:t}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(c0B,{fallback:W.jsx(r0B,{graphics:s}),children:Q==="canvas"?W.jsx(g0B,{graphics:s}):W.jsx(XhB,{graphics:s})}),a&&W.jsx(E1I,{solver:C,onStepUntilPhase:c,triggerRender:o})]})};const l0B=()=>{gA.useEffect(()=>{const g="tailwind-cdn-script";if(document.getElementById(g)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const I=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),I)return;const e=document.createElement("script");e.id=g,e.src="https://cdn.tailwindcss.com",document.head.appendChild(e)},[])},D0B=1e3,dk=(g,A)=>{const{fileName:I,mimeType:e="text/plain"}=A,t=g instanceof Blob?g:new Blob([g],{type:e}),B=URL.createObjectURL(t),o=document.createElement("a");o.href=B,o.download=I,o.target="_blank",o.rel="noopener noreferrer",o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>{URL.revokeObjectURL(B)},D0B)},Btg=g=>{let A=g.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(A)&&(A=`_${A}`),A=A.slice(0,200),A||"untitled"},d0B=g=>{const A=g.solverConstructorArgs??[g.solverParams];if(g.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||A.length!==1)return A;const[{input:I,options:e}]=A;return[I,e]},Kx="https://github.com/tscircuit/tscircuit-autorouter/issues/new",n1I="https://github.com/tscircuit/copper-pour-solver/issues/new",s1I="https://github.com/tscircuit/calculate-packing/issues/new",y0B="https://github.com/tscircuit/matchpack/issues/new",a1I="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",w0B={PackSolver2:s1I,LayoutPipelineSolver:y0B,AutoroutingPipelineSolver:Kx,AssignableAutoroutingPipeline2:Kx,AssignableAutoroutingPipeline3:Kx,AutoroutingPipeline1_OriginalUnravel:Kx,AutoroutingPipelineSolver3_HgPortPointPathing:Kx,AutoroutingPipelineSolver4:Kx,AutoroutingPipelineSolver5:Kx,AutoroutingPipelineSolver7_MultiGraph:Kx,AutoroutingPipelineSolver8:Kx,CopperPourPipelineSolver:n1I,SchematicTracePipelineSolver:a1I},u0B=g=>g.toLowerCase().includes("pack")?KBB:g.toLowerCase().includes("rout")?$SI:SBB,r1I=g=>{const A=w0B[g];if(A)return A;const I=g.toLowerCase();return I.includes("autorout")?Kx:I.includes("schematic")&&I.includes("trace")?a1I:I.includes("copperpour")?n1I:I.includes("pack")?s1I:null},G0B=g=>`${Btg(`${g.componentName}-${g.solverName}`)}-solver-input.json`,c1I=g=>{dk(JSON.stringify(g.solverParams,null,2),{fileName:G0B(g),mimeType:"application/json"})},m0B=({solverEvent:g})=>{const A=r1I(g.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[W.jsxs(XE,{type:"button",variant:"outline",size:"sm",onClick:()=>c1I(g),children:[W.jsx(qIA,{className:"rf-w-4 rf-h-4"}),"Download"]}),A?W.jsx(XE,{asChild:!0,variant:"outline",size:"sm",children:W.jsxs("a",{href:A,target:"_blank",rel:"noopener noreferrer",children:[W.jsx(awA,{className:"rf-w-4 rf-h-4"}),"Report"]})}):W.jsxs(XE,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[W.jsx(awA,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},p0B=({solverEvent:g})=>{const A=r1I(g.solverName);return A?W.jsx(XE,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:W.jsx("a",{href:A,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:W.jsx(awA,{className:"rf-w-4 rf-h-4"})})}):W.jsx(XE,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:W.jsx(awA,{className:"rf-w-4 rf-h-4"})})},k0B=({solverEvents:g=[]})=>{const[A,I]=gA.useState(null);l0B();const e=gA.useMemo(()=>{const C=new Map;for(const Q of g){const i=`${Q.componentName}-${Q.solverName}`;C.set(i,Q)}return C},[g]),t=gA.useMemo(()=>Array.from(e.keys()),[e]),B=A?e.get(A):null,o=gA.useMemo(()=>{if(!B)return{instance:null,error:null,classFound:!1};const C=F6A[B.solverName];if(!C)return{instance:null,error:`Solver class "${B.solverName}" not found in SOLVERS registry. Available: ${Object.keys(F6A).join(", ")}`,classFound:!1};try{return{instance:new C(...d0B(B)),error:null,classFound:!0}}catch(Q){const i=Q instanceof Error?Q.message:String(Q);return console.error("Failed to reconstruct solver:",Q),{instance:null,error:`Failed to instantiate solver: ${i}`,classFound:!0}}},[B]);return g.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[t.length," ",t.length===1?"Solver":"Solvers"]}),t.map(C=>{const Q=e.get(C),i=A===C;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${i?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>I(C),children:(()=>{const E=u0B(Q.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(E,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:Q.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:Q.solverName})]})]})})()},C)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:B?o.instance?W.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[W.jsx(m0B,{solverEvent:B}),W.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:W.jsx(SR,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",B.solverName]})]})}),children:W.jsx(h0B,{solver:o.instance})})})]}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:B.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",B.componentName]})]}),o.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${o.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${o.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:o.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(p0B,{solverEvent:B}),W.jsx(XE,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>c1I(B),children:W.jsx(qIA,{className:"rf-w-4 rf-h-4"})})]})]}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(B.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},M0B=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),S0B=new Set(["tscircuit","default","auto","auto_local"]);function f0B(g){if(g==="FanoutSolver")return"Fanout";if(g==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const A=g.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(A)return`Pipeline${A[1]}`;const I=g.match(/^AssignableAutoroutingPipeline(\d+)$/);return I?`Assignable${I[1]}`:g}function R0B(g){const A=g.autorouterName?.trim(),I=A?.replace(/-/g,"_"),e=I&&M0B.get(I);if(e)return e;if(I&&!S0B.has(I))return A;const t=g.solverName?.trim();if(t)return f0B(t);const B=g.autorouterVersion?.trim();if(B){const o=B.match(/^beta[_-]pipeline(\d+)$/);return o?`Pipeline${o[1]}`:B==="latest"?"default":B}return A?"default":"Unknown"}const otg="#fbbf24";function N0B(g){const A=g.endSimpleRouteJson?.traces??[],I=new Set(A.flatMap(t=>[t.pcb_trace_id,t.__replaces_pcb_trace_id].filter(B=>B!==void 0)));return[...(g.startSimpleRouteJson?.traces??[]).filter(t=>!I.has(t.pcb_trace_id)),...A]}function h1I(g){const A=new Map((g.startSimpleRouteJson?.traces??[]).map(I=>[I.pcb_trace_id,I]));return(g.endSimpleRouteJson?.traces??[]).filter(I=>{const e=A.get(I.pcb_trace_id);return!e||!!I.__replaces_pcb_trace_id&&I.__replaces_pcb_trace_id!==e.__replaces_pcb_trace_id||JSON.stringify(e.route)!==JSON.stringify(I.route)}).map(I=>I.pcb_trace_id)}function x0B(g,A){return{outer_diameter:g.via_diameter??A.minViaPadDiameter??A.min_via_pad_diameter??A.minViaDiameter??.6,hole_diameter:g.via_hole_diameter??A.minViaHoleDiameter??A.min_via_hole_diameter??.3}}function l1I(g,A){const I=[];for(const C of g.route)C.route_type==="wire"?I.push({...C,layer:C.layer}):C.route_type==="via"?I.push({route_type:"via",x:C.x,y:C.y,from_layer:C.from_layer,to_layer:C.to_layer,...x0B(C,A)}):C.route_type==="through_obstacle"&&I.push({route_type:"through_pad",start:{...C.start},end:{...C.end},width:C.width,start_layer:C.from_layer,end_layer:C.to_layer,pcb_smtpad_id:C.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:C.circuitJsonMetadata?.pcb_plated_hole_id});const e=C=>{let Q=-1,i=Number.POSITIVE_INFINITY;return I.forEach((E,n)=>{if(E.route_type!=="wire")return;const s=Math.hypot(E.x-C.x,E.y-C.y);s<i&&(i=s,Q=n)}),Q},t=g.route.filter(C=>C.route_type==="jumper").map(C=>[e(C.start),e(C.end)].sort((Q,i)=>Q-i)).filter(([C,Q])=>C>=0&&Q>C).sort(([C],[Q])=>C-Q),B=[];let o=0;for(const[C,Q]of t)C>=o&&B.push(I.slice(o,C+1)),o=Math.max(o,Q);return o<I.length&&B.push(I.slice(o)),B}function F0B(g){const A=[],I=[],e=g.endSimpleRouteJson;if(!e)return{lines:A,circles:I};const t=new Set(h1I(g));for(const B of e.traces??[])if(t.has(B.pcb_trace_id))for(const o of l1I(B,e)){let C;for(const Q of o){if(Q.route_type==="through_pad"){C={...Q.end,layer:Q.end_layer,width:Q.width};continue}const i=Q.route_type==="wire"?Q.layer:Q.from_layer;C&&C.layer===i&&(C.x!==Q.x||C.y!==Q.y)&&A.push({points:[{x:C.x,y:C.y},{x:Q.x,y:Q.y}],strokeWidth:Q.route_type==="wire"?Q.width:C.width,strokeColor:otg,layer:i}),Q.route_type==="via"&&I.push({center:{x:Q.x,y:Q.y},radius:Q.outer_diameter/2,stroke:otg,fill:"transparent"}),C={x:Q.x,y:Q.y,layer:Q.route_type==="wire"?Q.layer:Q.to_layer,width:Q.route_type==="wire"?Q.width:C?.width??e.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:A,circles:I}}function U0B(g){const A=JSON.stringify(g);let I=2166136261;for(let e=0;e<A.length;e++)I=Math.imul(I^A.charCodeAt(e),16777619);return(I>>>0).toString(36)}const J0B=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function K0B(g,A,I){const e=I==="input"?A.startSimpleRouteJson??A.errorSimpleRouteJson:A.endSimpleRouteJson,t=g.filter(i=>!J0B.has(i.type)&&!i.type.endsWith("_error")&&!i.type.endsWith("_warning"));if(!e)return t;const B=I==="input"?e.traces??[]:N0B(A),o=new Set(g.filter(i=>i.type==="source_trace").map(i=>i.source_trace_id)),C=["top",...Array.from({length:Math.max(0,e.layerCount-2)},(i,E)=>`inner${E+1}`),...e.layerCount>1?["bottom"]:[]],Q=[];for(const i of B){const n=e.connections.find(r=>r.name===i.connection_name||r.source_trace_id===i.connection_name)?.source_trace_id??i.connection_name??"",s=l1I(i,e);for(const[r,a]of s.entries()){const c={type:"pcb_trace",pcb_trace_id:`${A.id}_${I}_${i.pcb_trace_id}_${r}_${U0B(a)}`,subcircuit_id:A.subcircuit_id??void 0,source_trace_id:o.has(n)?n:void 0,route:a};Q.push(c);for(const[h,l]of a.entries()){if(l.route_type!=="via")continue;const D=C.indexOf(l.from_layer),d=C.indexOf(l.to_layer),y={type:"pcb_via",pcb_via_id:`${c.pcb_trace_id}_via_${h}`,pcb_trace_id:c.pcb_trace_id,subcircuit_id:A.subcircuit_id??void 0,x:l.x,y:l.y,outer_diameter:l.outer_diameter,hole_diameter:l.hole_diameter,layers:D>=0&&d>=0?C.slice(Math.min(D,d),Math.max(D,d)+1):[l.from_layer,l.to_layer]};Q.push(y)}}}return[...t,...Q]}const Ctg=(g,A)=>g.phaseName||`Phase ${g.phaseOrdinal??A+1}`,D1I=g=>g.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||g.componentDisplayName||g.subcircuit_id||"Board",d1I=g=>g.startSimpleRouteJson??g.endSimpleRouteJson??g.errorSimpleRouteJson,P0B={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},L0B=({circuitJson:g,phases:A=[],isRunning:I=!1})=>{const[e,t]=gA.useState(null),[B,o]=gA.useState("output"),[C,Q]=gA.useState(!0),[i,E]=gA.useState(!1),n=gA.useRef(null),[s,r]=gA.useState(480),a=e?A.findIndex(N=>N.id===e.id&&d1I(N)===d1I(e)):-1,c=a<0?A.length-1:a,h=A[c],l=a<0,D=!!h?.endSimpleRouteJson,d=h?.startSimpleRouteJson??h?.errorSimpleRouteJson,y=!!d,w=B==="output"&&!D?"input":B==="input"&&!y?"output":B,u=w==="input"?d:h?.endSimpleRouteJson,G=gA.useMemo(()=>!h||!u?null:K0B(g??[],h,w),[g,h,u,w]),m=gA.useMemo(()=>h&&w==="output"&&C?F0B(h):{lines:[],circles:[]},[h,w,C]);if(gA.useLayoutEffect(()=>{const N=n.current;if(!N)return;const U=()=>r(Math.max(360,N.clientHeight));U();const P=new ResizeObserver(U);return P.observe(N),()=>P.disconnect()},[!!h]),!h)return W.jsxs("div",{className:"rf-flex rf-min-h-[400px] rf-flex-col rf-items-center rf-justify-center rf-gap-3 rf-p-8 rf-text-center",children:[W.jsx($SI,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),W.jsx("h3",{className:"rf-text-base rf-font-medium",children:I?"Waiting for autorouting":"No autorouting captures"}),W.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:I?"Phases appear as the circuit routes. Each capture includes its input and output on the PCB.":"Run a circuit with autorouting enabled to inspect its phases. A circuit JSON file alone does not include routing history."})]});const p=Ctg(h,c),k=h.status==="running"&&I,S=!D,R=d?.connections.length,F=G?.filter(N=>N.type==="pcb_trace").length??0;return W.jsxs("div",{className:"rf-flex rf-h-full rf-min-h-[620px] rf-flex-col rf-bg-white md:rf-flex-row","data-testid":"autorouting-explorer",children:[W.jsxs("aside",{className:"rf-flex rf-shrink-0 rf-flex-col rf-border-b rf-border-gray-200 md:rf-w-52 md:rf-border-b-0 md:rf-border-r","aria-label":"Routing phases",children:[W.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-px-3 rf-py-2 rf-text-xs rf-text-gray-500",children:[W.jsx("span",{children:"Routing phases"}),W.jsx("span",{children:A.length})]}),W.jsx("div",{className:"rf-flex rf-gap-1 rf-overflow-x-auto rf-px-1.5 rf-pb-1.5 md:rf-flex-col md:rf-overflow-x-hidden md:rf-overflow-y-auto",children:A.map((N,U)=>{const P=h1I(N).length,b=N.endSimpleRouteJson?`${P} ${P===1?"trace":"traces"} routed`:N.status==="error"?"Failed":N.status==="running"&&I?"Routing…":"No output";return W.jsxs("button",{type:"button","aria-pressed":U===c,title:`${D1I(N)} · ${b}`,onClick:()=>t(N),className:no("rf-flex rf-min-w-[192px] rf-items-start rf-gap-2 rf-rounded-md rf-border rf-px-2 rf-py-2 rf-text-left md:rf-min-w-0",U===c?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[W.jsx("span",{className:no("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",U===c?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:U+1}),W.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[W.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx("span",{className:"rf-min-w-0 rf-flex-1 rf-truncate rf-text-xs rf-font-medium rf-leading-5 rf-text-gray-800",title:Ctg(N,U),children:Ctg(N,U)}),N.status==="complete"?W.jsx(vIA,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):N.status==="error"?W.jsx(cIg,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):I?W.jsx(b2,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),W.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[R0B(N)," · ",b]})]})]},N.id)})})]}),W.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-gap-3 rf-border-b rf-border-gray-200 rf-px-4 rf-py-3",children:[W.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[p,W.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[c+1," of ",A.length]})]}),I&&W.jsx("button",{type:"button",onClick:()=>t(null),disabled:l,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:l?"Following latest":"Follow latest"}),W.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(N=>W.jsx("button",{type:"button","aria-pressed":w===N,disabled:N==="input"?!y:!D,onClick:()=>o(N),className:no("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",w===N?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:N==="input"?"Input":"Output"},N))})]}),W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-px-4 rf-py-2 rf-text-xs rf-text-gray-600",children:[W.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx("input",{type:"checkbox",checked:C,disabled:w!=="output",onChange:N=>Q(N.target.checked),className:"rf-accent-blue-600"}),W.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:otg}}),"Highlight changes (all layers)"]}),W.jsxs("span",{children:[w==="input"?"Before this phase":"After this phase"," ","· ",F," traces"]})]}),S&&W.jsx("div",{className:no("rf-border-y rf-px-4 rf-py-2 rf-text-xs",h.status==="error"?"rf-border-red-100 rf-bg-red-50 rf-text-red-700":"rf-border-blue-100 rf-bg-blue-50 rf-text-blue-700"),role:"status",children:h.status==="error"?`Routing failed: ${h.error?.message||"No output was captured."}`:k?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),W.jsx("div",{ref:n,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:G?W.jsx(sIg,{circuitJson:G,height:s,allowEditing:!1,clickToInteractEnabled:!1,initialState:P0B,debugGraphics:m}):W.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-border-t rf-border-gray-200 rf-px-4 rf-py-3 rf-text-xs rf-text-gray-500",children:[W.jsxs("span",{children:[R===void 0?"Input unavailable":`${R} input connections`,` · ${D1I(h)}`]}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[W.jsxs("button",{type:"button",disabled:!u,onClick:()=>dk(JSON.stringify(u,null,2),{fileName:`${h.id}-${w}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[W.jsx(qIA,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),W.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>E(!i),className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(qT,{className:no("rf-h-3 rf-w-3",i&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),i&&W.jsx("pre",{className:"rf-m-0 rf-max-h-64 rf-overflow-auto rf-border-t rf-border-gray-200 rf-bg-gray-50 rf-p-4 rf-text-xs","aria-label":`${p} ${w} SRJ`,children:u?JSON.stringify(u,null,2):"No snapshot captured."})]})]})},y1I=({errorMessage:g,errorStack:A,circuitJsonErrors:I})=>{gA.useEffect(()=>{if(wF("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&g){const e=new Error(g);A&&(e.stack=A);try{s9.captureException(e)}catch{}}},[g,A]),gA.useEffect(()=>{if(wF("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&I&&I.length>0)for(const e of I){const t=new Error(e.message||"Circuit JSON Error");e.stack&&(t.stack=e.stack);try{s9.captureException(t,{error_type:e.type})}catch{}}},[I])},Y0B=g=>{gA.useEffect(()=>{try{NVI(g)}catch{}},[g.source,g.component,g.isWebEmbedded,g.activeTab])},w1I="0.0.3027",_0B={version:w1I},Qtg={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},itg=new Map,NuA=g=>{const A=itg.get(g);return A?Object.fromEntries(Object.entries(A.stores).map(([I,e])=>[I,e.getState()])):{}},b0B=(g,A,I)=>{if(g===void 0)return{type:"untracked",connection:A.connect(I)};const e=itg.get(I.name);if(e)return{type:"tracked",store:g,...e};const t={connection:A.connect(I),stores:{}};return itg.set(I.name,t),{type:"tracked",store:g,...t}},u1I=(g,A={})=>(I,e,t)=>{const{enabled:B,anonymousActionType:o,store:C,...Q}=A;let i;try{i=(B??(Qtg?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!i)return(Qtg?"production":void 0)!=="production"&&B&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),g(I,e,t);const{connection:E,...n}=b0B(C,i,Q);let s=!0;t.setState=(c,h,l)=>{const D=I(c,h);if(!s)return D;const d=l===void 0?{type:o||"anonymous"}:typeof l=="string"?{type:l}:l;return C===void 0?(E?.send(d,e()),D):(E?.send({...d,type:`${C}/${d.type}`},{...NuA(Q.name),[C]:t.getState()}),D)};const r=(...c)=>{const h=s;s=!1,I(...c),s=h},a=g(t.setState,e,t);if(n.type==="untracked"?E?.init(a):(n.stores[n.store]=t,E?.init(Object.fromEntries(Object.entries(n.stores).map(([c,h])=>[c,c===n.store?a:h.getState()])))),t.dispatchFromDevtools&&typeof t.dispatch=="function"){let c=!1;const h=t.dispatch;t.dispatch=(...l)=>{(Qtg?"production":void 0)!=="production"&&l[0].type==="__setState"&&!c&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),c=!0),h(...l)}}return E.subscribe(c=>{var h;switch(c.type){case"ACTION":if(typeof c.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Etg(c.payload,l=>{if(l.type==="__setState"){if(C===void 0){r(l.state);return}Object.keys(l.state).length!==1&&console.error(`
|
|
5664
|
+
`,n=new Blob([E],{type:"text/plain"}),s=URL.createObjectURL(n),r=document.createElement("a");r.href=s,r.download=`${i}.test.ts`,r.click(),URL.revokeObjectURL(s)}catch(Q){alert(`Error generating test.ts for ${g.getSolverName()}: ${Q instanceof Error?Q.message:String(Q)}`)}e(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:t,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>e(!I),title:`Download options for ${g.getSolverName()}`,children:g.getSolverName()}),I&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:B,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:C,children:"Download test.ts"})]})]})},C1I=g=>g.activeSubSolver?[g,...C1I(g.activeSubSolver)]:[g],e0B=({solver:g})=>{const A=C1I(g);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((I,e)=>W.jsxs("div",{className:"flex items-center",children:[e>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(I0B,{solver:I})]},I.getSolverName()))})},t0B=({solver:g,triggerRender:A,animationSpeed:I=25,renderer:e,onRendererChange:t,onAnimationSpeedChange:B,onDownloadVisualization:o,onSolverStarted:C,onSolverCompleted:Q})=>{const[i,E]=gA.useReducer(m=>!m,!1),n=gA.useRef(void 0),s=gA.useRef(null),r="solver-debugger-last-iteration",[a,c]=gA.useState(null),h=gA.useRef(null),l=gA.useMemo(()=>[{label:"Slow",value:250,description:"250ms"},{label:"Normal",value:100,description:"100ms"},{label:"Fast",value:10,description:"10ms"},{label:"Fast (2x)",value:5,description:"5ms"},{label:"Fast (10x)",value:1,description:"1ms"},{label:"Fast 20x",value:.5,description:"2 steps / 1ms"},{label:"Fast 100x",value:.1,description:"10 steps / 1ms"}],[]),D=()=>{const m=Math.max(1,I),p=I<1?Math.round(1/I):1;n.current=setInterval(()=>{if(g.solved||g.failed){n.current&&(clearInterval(n.current),n.current=void 0),E(),A(),Q&&g.solved&&Q(g);return}for(let k=0;k<p&&!(g.solved||g.failed);k++)g.step();A()},m)},d=()=>{n.current&&(clearInterval(n.current),n.current=void 0)},y=()=>{!g.solved&&!g.failed&&(g.step(),A())},w=()=>{!g.solved&&!g.failed&&(C&&C(g),g.solve(),A(),Q&&Q(g))},u=()=>{i?(d(),E()):(E(),D())},G=()=>{if(g.solved||g.failed||i)return;s.current===null&&typeof window<"u"&&(s.current=window.localStorage.getItem(r));const m=window.prompt("Step until which iteration?",s.current??`${g.iterations}`);if(m===null)return;s.current=m,typeof window<"u"&&window.localStorage.setItem(r,m);const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;g.iterations<p&&!g.solved&&!g.failed;)g.step();A(),g.solved&&Q&&Q(g)};return gA.useEffect(()=>()=>{d()},[]),gA.useEffect(()=>{(g.solved||g.failed)&&i&&(d(),E())},[g.solved,g.failed,i]),gA.useEffect(()=>{i&&(d(),D())},[I,i]),gA.useEffect(()=>{if(typeof document>"u")return;const m=p=>{h.current&&!h.current.contains(p.target)&&c(null)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[]),W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsxs("div",{className:"flex items-center gap-2",ref:h,children:[W.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="renderer"?null:"renderer"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="renderer"?"open":"closed",children:"Renderer"}),a==="renderer"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[10rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:["vector","canvas"].map(m=>W.jsxs("button",{type:"button",onClick:()=>{t(m),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m==="vector"?"Vector":"Canvas",e===m&&W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},m))})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="debug"?null:"debug"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="debug"?"open":"closed",children:"Debug"}),a==="debug"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:W.jsx("button",{type:"button",onClick:()=>{o(),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="animation"?null:"animation"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="animation"?"open":"closed",children:"Animation"}),a==="animation"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:l.map(m=>W.jsxs("button",{type:"button",onClick:()=>{B(m.value),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m.label,W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:m.description}),I===m.value&&W.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},m.value))})]})]}),W.jsx(e0B,{solver:g})]})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:y,disabled:g.solved||g.failed||i,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:w,disabled:g.solved||g.failed||i,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:u,disabled:g.solved||g.failed,className:`px-3 py-1 rounded text-white text-sm ${i?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:i?"Stop":"Animate"}),W.jsx("button",{onClick:G,disabled:g.solved||g.failed||i,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",g.iterations]}),g.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(g.timeToSolve/1e3).toFixed(3),"s"]}),g.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),g.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),g.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",g.error]})]})},B0B=g=>g!==null&&"pipelineDef"in g&&Array.isArray(g.pipelineDef),o0B=(g,A,I)=>{const e=g.currentPipelineStageIndex;return A<e?"Completed":A===e&&g.activeSubSolver?g.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},C0B=(g,A)=>{const e=g.pipelineDef[A].solverName,t=o0B(g,A),B=g[e],o=g.firstIterationOfStage?.[e]??(A===g.currentPipelineStageIndex?g.iterations:null),C=g.iterations;let Q=0;if(t==="Completed"){const s=g.pipelineDef[A+1],r=s?g.firstIterationOfStage?.[s.solverName]:void 0;r!==void 0&&o!==null?Q=r-o:o!==null&&(Q=C-o)}else t==="In Progress"&&o!==null&&(Q=C-o);const i=g.timeSpentOnStage?.[e]??0;let E=0;t==="Completed"?E=1:t==="In Progress"&&B&&(E=B.progress??0);const n=B?.stats??null;return{index:A,name:e,status:t,firstIteration:o,iterations:Q,progress:E,timeSpent:i,stats:n&&Object.keys(n).length>0?n:null,solverInstance:B??null}},Q0B=({status:g})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[g]}`,children:g})},i0B=({progress:g})=>{if(g===0)return null;const A=Math.round(g*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},Q1I=g=>{if(typeof g=="string")return g;if(typeof g=="number"||typeof g=="boolean"||typeof g=="bigint"||g==null)return String(g);if(typeof g=="object")try{return JSON.stringify(g)}catch{return String(g)}return String(g)},E0B=g=>Object.entries(g).map(([A,I])=>`${A}: ${Q1I(I)}`).join(", "),n0B=({stats:g})=>{if(!g||Object.keys(g).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(g),I=E0B(g);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:I}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([e,t])=>W.jsxs("div",{children:[e,": ",Q1I(t)]},e))})]})},ttg=g=>{if(g===null||typeof g!="object")return g;if(Array.isArray(g))return g.map(ttg);const A={};for(const[I,e]of Object.entries(g))I.startsWith("_")||(A[I]=ttg(e));return A},s0B=(g,A)=>{try{if(typeof g.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const I=ttg(g.getConstructorParams()),e=new Blob([JSON.stringify(I,null,2)],{type:"application/json"}),t=URL.createObjectURL(e),B=document.createElement("a");B.href=t,B.download=`${A}_input.json`,B.click(),URL.revokeObjectURL(t)}catch(I){alert(`Error downloading input for ${A}: ${I instanceof Error?I.message:String(I)}`)}},a0B=({expanded:g})=>W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:`w-4 h-4 transition-transform duration-200 ${g?"rotate-90":""}`,children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})}),i1I=g=>{let A=g;for(;A.activeSubSolver;)A=A.activeSubSolver;return A},E1I=({solver:g,onStepUntilPhase:A,onDownloadInput:I,isNested:e=!1,indentLevel:t=0,triggerRender:B})=>{const[o,C]=gA.useState(new Set),Q=g.pipelineDef.map((h,l)=>C0B(g,l)),i=h=>{C(l=>{const D=new Set(l);return D.has(h)?D.delete(h):D.add(h),D})},E=h=>{A?.(h)},n=h=>{h.solverInstance&&(I?I(h.solverInstance,h.name):s0B(h.solverInstance,h.name))},s=h=>`${(h/1e3).toFixed(2)}s`,r=()=>{if(!g.solved&&!g.failed){const h=g.activeSubSolver;for(;!g.solved&&!g.failed&&(g.step(),!(g.activeSubSolver&&g.activeSubSolver!==h)););B?.()}},a=()=>{if(!g.solved&&!g.failed){const h=i1I(g);for(;!g.solved&&!g.failed&&(g.step(),i1I(g)===h););B?.()}},c=t*24;return W.jsxs("div",{className:e?"":"border-t border-gray-200",children:[!e&&W.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),W.jsxs("div",{className:"flex gap-2",children:[W.jsx("button",{onClick:a,disabled:g.solved||g.failed,className:"bg-indigo-500 hover:bg-indigo-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Solver"}),W.jsx("button",{onClick:r,disabled:g.solved||g.failed,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Stage"})]})]}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[!e&&W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:Q.map(h=>{const l=B0B(h.solverInstance),D=o.has(h.name);return W.jsxs(nC.Fragment,{children:[W.jsxs("tr",{className:`border-b border-gray-100 ${h.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:c},children:[l?W.jsx("button",{onClick:()=>i(h.name),className:"text-gray-500 hover:text-gray-700",title:D?"Collapse":"Expand",children:W.jsx(a0B,{expanded:D})}):W.jsx("span",{className:"w-4"}),W.jsx("span",{className:"text-gray-400 w-6",children:String(h.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>E(h.name),disabled:h.status==="Completed"||g.solved||g.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${h.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:h.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(Q0B,{status:h.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:h.firstIteration!==null?h.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:h.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(i0B,{progress:h.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(h.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(n0B,{stats:h.stats})}),W.jsx("td",{className:"px-4 py-2",children:h.solverInstance?W.jsxs("button",{onClick:()=>n(h),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${h.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]}),l&&D&&W.jsx("tr",{children:W.jsx("td",{colSpan:8,className:"p-0",children:W.jsx(E1I,{solver:h.solverInstance,onStepUntilPhase:A,onDownloadInput:I,isNested:!0,indentLevel:t+1,triggerRender:B})})})]},h.name)})})]})})]})};function r0B({graphics:g}){const A=g.points??[],I=g.lines??[],e=g.rects??[],t=g.circles??[],B=g.texts??[];let o=Number.POSITIVE_INFINITY,C=Number.POSITIVE_INFINITY,Q=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;const E=(h,l)=>{typeof h=="number"&&(h<o&&(o=h),h>Q&&(Q=h)),typeof l=="number"&&(l<C&&(C=l),l>i&&(i=l))};for(const h of A)E(h.x,h.y);for(const h of I){const l=h.points??[];for(const D of l)E(D.x,D.y)}for(const h of e){const l=h.x??0,D=h.y??0,d=h.width??0,y=h.height??0;E(l,D),E(l+d,D+y)}for(const h of t){const l=h.x??0,D=h.y??0,d=h.radius??1;E(l-d,D-d),E(l+d,D+d)}for(const h of B)E(h.x,h.y);(!isFinite(o)||!isFinite(C)||!isFinite(Q)||!isFinite(i))&&(o=-20,C=-20,Q=20,i=20);const n=10,s=o-n,r=C-n,a=Math.max(1,Q-o+2*n),c=Math.max(1,i-C+2*n);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${s} ${r} ${a} ${c}`,role:"img","aria-label":"Graphics fallback",children:[e.map((h,l)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${l}`)),I.map((h,l)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(D=>`${D.x??0},${D.y??0}`).join(" ")},`line-${l}`)),t.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${l}`)),A.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${l}`)),B.map((h,l)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${l}`))]})}var c0B=class extends nC.Component{constructor(g){super(g),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(g){console.error("InteractiveGraphics render error:",g)}render(){return this.state.hasError?this.props.fallback:this.props.children}},h0B=({solver:g,createSolver:A,animationSpeed:I=25,onSolverStarted:e,onSolverCompleted:t})=>{const[B,o]=gA.useReducer(D=>D+1,0),[C]=gA.useState(()=>{if(A)return A();if(!g)throw new Error("GenericSolverDebugger requires solver or createSolver");return g}),[Q,i]=gA.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[E,n]=gA.useState(I),s=gA.useMemo(()=>{try{return C.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(D){return console.error("Visualization error:",D),{points:[],lines:[],rects:[],circles:[]}}},[C,B]),r=gA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);gA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const D=document.createElement("script");D.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(D)}},[]),gA.useEffect(()=>{n(I)},[I]);const a=C.pipelineDef!==void 0,c=D=>{const d=C;if(!C.solved&&!C.failed){for(;!C.solved&&!C.failed&&d.currentPipelineStageIndex<=d.pipelineDef.findIndex(y=>y.solverName===D);)C.step();o()}},h=()=>{const D=JSON.stringify(s,null,2),d=new Blob([D],{type:"application/json"}),y=URL.createObjectURL(d),w=document.createElement("a");w.download="visualization.json",w.href=y,document.body.appendChild(w),w.click(),document.body.removeChild(w),URL.revokeObjectURL(y)},l=D=>{i(D),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",D)};return W.jsxs("div",{children:[W.jsx(t0B,{solver:C,triggerRender:o,animationSpeed:E,renderer:Q,onRendererChange:l,onAnimationSpeedChange:n,onDownloadVisualization:h,onSolverStarted:e,onSolverCompleted:t}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(c0B,{fallback:W.jsx(r0B,{graphics:s}),children:Q==="canvas"?W.jsx(g0B,{graphics:s}):W.jsx(XhB,{graphics:s})}),a&&W.jsx(E1I,{solver:C,onStepUntilPhase:c,triggerRender:o})]})};const l0B=()=>{gA.useEffect(()=>{const g="tailwind-cdn-script";if(document.getElementById(g)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const I=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),I)return;const e=document.createElement("script");e.id=g,e.src="https://cdn.tailwindcss.com",document.head.appendChild(e)},[])},D0B=1e3,dk=(g,A)=>{const{fileName:I,mimeType:e="text/plain"}=A,t=g instanceof Blob?g:new Blob([g],{type:e}),B=URL.createObjectURL(t),o=document.createElement("a");o.href=B,o.download=I,o.target="_blank",o.rel="noopener noreferrer",o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>{URL.revokeObjectURL(B)},D0B)},Btg=g=>{let A=g.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(A)&&(A=`_${A}`),A=A.slice(0,200),A||"untitled"},d0B=g=>{const A=g.solverConstructorArgs??[g.solverParams];if(g.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||A.length!==1)return A;const[{input:I,options:e}]=A;return[I,e]},Kx="https://github.com/tscircuit/tscircuit-autorouter/issues/new",n1I="https://github.com/tscircuit/copper-pour-solver/issues/new",s1I="https://github.com/tscircuit/calculate-packing/issues/new",y0B="https://github.com/tscircuit/matchpack/issues/new",a1I="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",w0B={PackSolver2:s1I,LayoutPipelineSolver:y0B,AutoroutingPipelineSolver:Kx,AssignableAutoroutingPipeline2:Kx,AssignableAutoroutingPipeline3:Kx,AutoroutingPipeline1_OriginalUnravel:Kx,AutoroutingPipelineSolver3_HgPortPointPathing:Kx,AutoroutingPipelineSolver4:Kx,AutoroutingPipelineSolver5:Kx,AutoroutingPipelineSolver7_MultiGraph:Kx,AutoroutingPipelineSolver8:Kx,CopperPourPipelineSolver:n1I,SchematicTracePipelineSolver:a1I},u0B=g=>g.toLowerCase().includes("pack")?KBB:g.toLowerCase().includes("rout")?$SI:SBB,r1I=g=>{const A=w0B[g];if(A)return A;const I=g.toLowerCase();return I.includes("autorout")?Kx:I.includes("schematic")&&I.includes("trace")?a1I:I.includes("copperpour")?n1I:I.includes("pack")?s1I:null},G0B=g=>`${Btg(`${g.componentName}-${g.solverName}`)}-solver-input.json`,c1I=g=>{dk(JSON.stringify(g.solverParams,null,2),{fileName:G0B(g),mimeType:"application/json"})},m0B=({solverEvent:g})=>{const A=r1I(g.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[W.jsxs(XE,{type:"button",variant:"outline",size:"sm",onClick:()=>c1I(g),children:[W.jsx(qIA,{className:"rf-w-4 rf-h-4"}),"Download"]}),A?W.jsx(XE,{asChild:!0,variant:"outline",size:"sm",children:W.jsxs("a",{href:A,target:"_blank",rel:"noopener noreferrer",children:[W.jsx(awA,{className:"rf-w-4 rf-h-4"}),"Report"]})}):W.jsxs(XE,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[W.jsx(awA,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},p0B=({solverEvent:g})=>{const A=r1I(g.solverName);return A?W.jsx(XE,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:W.jsx("a",{href:A,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:W.jsx(awA,{className:"rf-w-4 rf-h-4"})})}):W.jsx(XE,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:W.jsx(awA,{className:"rf-w-4 rf-h-4"})})},k0B=({solverEvents:g=[]})=>{const[A,I]=gA.useState(null);l0B();const e=gA.useMemo(()=>{const C=new Map;for(const Q of g){const i=`${Q.componentName}-${Q.solverName}`;C.set(i,Q)}return C},[g]),t=gA.useMemo(()=>Array.from(e.keys()),[e]),B=A?e.get(A):null,o=gA.useMemo(()=>{if(!B)return{instance:null,error:null,classFound:!1};const C=F6A[B.solverName];if(!C)return{instance:null,error:`Solver class "${B.solverName}" not found in SOLVERS registry. Available: ${Object.keys(F6A).join(", ")}`,classFound:!1};try{return{instance:new C(...d0B(B)),error:null,classFound:!0}}catch(Q){const i=Q instanceof Error?Q.message:String(Q);return console.error("Failed to reconstruct solver:",Q),{instance:null,error:`Failed to instantiate solver: ${i}`,classFound:!0}}},[B]);return g.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[t.length," ",t.length===1?"Solver":"Solvers"]}),t.map(C=>{const Q=e.get(C),i=A===C;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${i?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>I(C),children:(()=>{const E=u0B(Q.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(E,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:Q.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:Q.solverName})]})]})})()},C)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:B?o.instance?W.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[W.jsx(m0B,{solverEvent:B}),W.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:W.jsx(SR,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",B.solverName]})]})}),children:W.jsx(h0B,{solver:o.instance})})})]}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:B.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",B.componentName]})]}),o.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${o.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${o.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:o.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(p0B,{solverEvent:B}),W.jsx(XE,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>c1I(B),children:W.jsx(qIA,{className:"rf-w-4 rf-h-4"})})]})]}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(B.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},M0B=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),S0B=new Set(["tscircuit","default","auto","auto_local"]);function f0B(g){if(g==="FanoutSolver")return"Fanout";if(g==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const A=g.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(A)return`Pipeline${A[1]}`;const I=g.match(/^AssignableAutoroutingPipeline(\d+)$/);return I?`Assignable${I[1]}`:g}function R0B(g){const A=g.autorouterName?.trim(),I=A?.replace(/-/g,"_"),e=I&&M0B.get(I);if(e)return e;if(I&&!S0B.has(I))return A;const t=g.solverName?.trim();if(t)return f0B(t);const B=g.autorouterVersion?.trim();if(B){const o=B.match(/^beta[_-]pipeline(\d+)$/);return o?`Pipeline${o[1]}`:B==="latest"?"default":B}return A?"default":"Unknown"}const otg="#fbbf24";function N0B(g){const A=g.endSimpleRouteJson?.traces??[],I=new Set(A.flatMap(t=>[t.pcb_trace_id,t.__replaces_pcb_trace_id].filter(B=>B!==void 0)));return[...(g.startSimpleRouteJson?.traces??[]).filter(t=>!I.has(t.pcb_trace_id)),...A]}function h1I(g){const A=new Map((g.startSimpleRouteJson?.traces??[]).map(I=>[I.pcb_trace_id,I]));return(g.endSimpleRouteJson?.traces??[]).filter(I=>{const e=A.get(I.pcb_trace_id);return!e||!!I.__replaces_pcb_trace_id&&I.__replaces_pcb_trace_id!==e.__replaces_pcb_trace_id||JSON.stringify(e.route)!==JSON.stringify(I.route)}).map(I=>I.pcb_trace_id)}function x0B(g,A){return{outer_diameter:g.via_diameter??A.minViaPadDiameter??A.min_via_pad_diameter??A.minViaDiameter??.6,hole_diameter:g.via_hole_diameter??A.minViaHoleDiameter??A.min_via_hole_diameter??.3}}function l1I(g,A){const I=[];for(const C of g.route)C.route_type==="wire"?I.push({...C,layer:C.layer}):C.route_type==="via"?I.push({route_type:"via",x:C.x,y:C.y,from_layer:C.from_layer,to_layer:C.to_layer,...x0B(C,A)}):C.route_type==="through_obstacle"&&I.push({route_type:"through_pad",start:{...C.start},end:{...C.end},width:C.width,start_layer:C.from_layer,end_layer:C.to_layer,pcb_smtpad_id:C.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:C.circuitJsonMetadata?.pcb_plated_hole_id});const e=C=>{let Q=-1,i=Number.POSITIVE_INFINITY;return I.forEach((E,n)=>{if(E.route_type!=="wire")return;const s=Math.hypot(E.x-C.x,E.y-C.y);s<i&&(i=s,Q=n)}),Q},t=g.route.filter(C=>C.route_type==="jumper").map(C=>[e(C.start),e(C.end)].sort((Q,i)=>Q-i)).filter(([C,Q])=>C>=0&&Q>C).sort(([C],[Q])=>C-Q),B=[];let o=0;for(const[C,Q]of t)C>=o&&B.push(I.slice(o,C+1)),o=Math.max(o,Q);return o<I.length&&B.push(I.slice(o)),B}function F0B(g){const A=[],I=[],e=g.endSimpleRouteJson;if(!e)return{lines:A,circles:I};const t=new Set(h1I(g));for(const B of e.traces??[])if(t.has(B.pcb_trace_id))for(const o of l1I(B,e)){let C;for(const Q of o){if(Q.route_type==="through_pad"){C={...Q.end,layer:Q.end_layer,width:Q.width};continue}const i=Q.route_type==="wire"?Q.layer:Q.from_layer;C&&C.layer===i&&(C.x!==Q.x||C.y!==Q.y)&&A.push({points:[{x:C.x,y:C.y},{x:Q.x,y:Q.y}],strokeWidth:Q.route_type==="wire"?Q.width:C.width,strokeColor:otg,layer:i}),Q.route_type==="via"&&I.push({center:{x:Q.x,y:Q.y},radius:Q.outer_diameter/2,stroke:otg,fill:"transparent"}),C={x:Q.x,y:Q.y,layer:Q.route_type==="wire"?Q.layer:Q.to_layer,width:Q.route_type==="wire"?Q.width:C?.width??e.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:A,circles:I}}function U0B(g){const A=JSON.stringify(g);let I=2166136261;for(let e=0;e<A.length;e++)I=Math.imul(I^A.charCodeAt(e),16777619);return(I>>>0).toString(36)}const J0B=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function K0B(g,A,I){const e=I==="input"?A.startSimpleRouteJson??A.errorSimpleRouteJson:A.endSimpleRouteJson,t=g.filter(i=>!J0B.has(i.type)&&!i.type.endsWith("_error")&&!i.type.endsWith("_warning"));if(!e)return t;const B=I==="input"?e.traces??[]:N0B(A),o=new Set(g.filter(i=>i.type==="source_trace").map(i=>i.source_trace_id)),C=["top",...Array.from({length:Math.max(0,e.layerCount-2)},(i,E)=>`inner${E+1}`),...e.layerCount>1?["bottom"]:[]],Q=[];for(const i of B){const n=e.connections.find(r=>r.name===i.connection_name||r.source_trace_id===i.connection_name)?.source_trace_id??i.connection_name??"",s=l1I(i,e);for(const[r,a]of s.entries()){const c={type:"pcb_trace",pcb_trace_id:`${A.id}_${I}_${i.pcb_trace_id}_${r}_${U0B(a)}`,subcircuit_id:A.subcircuit_id??void 0,source_trace_id:o.has(n)?n:void 0,route:a};Q.push(c);for(const[h,l]of a.entries()){if(l.route_type!=="via")continue;const D=C.indexOf(l.from_layer),d=C.indexOf(l.to_layer),y={type:"pcb_via",pcb_via_id:`${c.pcb_trace_id}_via_${h}`,pcb_trace_id:c.pcb_trace_id,subcircuit_id:A.subcircuit_id??void 0,x:l.x,y:l.y,outer_diameter:l.outer_diameter,hole_diameter:l.hole_diameter,layers:D>=0&&d>=0?C.slice(Math.min(D,d),Math.max(D,d)+1):[l.from_layer,l.to_layer]};Q.push(y)}}}return[...t,...Q]}const Ctg=(g,A)=>g.phaseName||`Phase ${g.phaseOrdinal??A+1}`,D1I=g=>g.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||g.componentDisplayName||g.subcircuit_id||"Board",d1I=g=>g.startSimpleRouteJson??g.endSimpleRouteJson??g.errorSimpleRouteJson,P0B={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},L0B=({circuitJson:g,phases:A=[],isRunning:I=!1})=>{const[e,t]=gA.useState(null),[B,o]=gA.useState("output"),[C,Q]=gA.useState(!0),[i,E]=gA.useState(!1),n=gA.useRef(null),[s,r]=gA.useState(480),a=e?A.findIndex(N=>N.id===e.id&&d1I(N)===d1I(e)):-1,c=a<0?A.length-1:a,h=A[c],l=a<0,D=!!h?.endSimpleRouteJson,d=h?.startSimpleRouteJson??h?.errorSimpleRouteJson,y=!!d,w=B==="output"&&!D?"input":B==="input"&&!y?"output":B,u=w==="input"?d:h?.endSimpleRouteJson,G=gA.useMemo(()=>!h||!u?null:K0B(g??[],h,w),[g,h,u,w]),m=gA.useMemo(()=>h&&w==="output"&&C?F0B(h):{lines:[],circles:[]},[h,w,C]);if(gA.useLayoutEffect(()=>{const N=n.current;if(!N)return;const U=()=>r(Math.max(360,N.clientHeight));U();const P=new ResizeObserver(U);return P.observe(N),()=>P.disconnect()},[!!h]),!h)return W.jsxs("div",{className:"rf-flex rf-min-h-[400px] rf-flex-col rf-items-center rf-justify-center rf-gap-3 rf-p-8 rf-text-center",children:[W.jsx($SI,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),W.jsx("h3",{className:"rf-text-base rf-font-medium",children:I?"Waiting for autorouting":"No autorouting captures"}),W.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:I?"Phases appear as the circuit routes. Each capture includes its input and output on the PCB.":"Run a circuit with autorouting enabled to inspect its phases. A circuit JSON file alone does not include routing history."})]});const p=Ctg(h,c),k=h.status==="running"&&I,S=!D,R=d?.connections.length,F=G?.filter(N=>N.type==="pcb_trace").length??0;return W.jsxs("div",{className:"rf-flex rf-h-full rf-min-h-[620px] rf-flex-col rf-bg-white md:rf-flex-row","data-testid":"autorouting-explorer",children:[W.jsxs("aside",{className:"rf-flex rf-shrink-0 rf-flex-col rf-border-b rf-border-gray-200 md:rf-w-52 md:rf-border-b-0 md:rf-border-r","aria-label":"Routing phases",children:[W.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-px-3 rf-py-2 rf-text-xs rf-text-gray-500",children:[W.jsx("span",{children:"Routing phases"}),W.jsx("span",{children:A.length})]}),W.jsx("div",{className:"rf-flex rf-gap-1 rf-overflow-x-auto rf-px-1.5 rf-pb-1.5 md:rf-flex-col md:rf-overflow-x-hidden md:rf-overflow-y-auto",children:A.map((N,U)=>{const P=h1I(N).length,b=N.endSimpleRouteJson?`${P} ${P===1?"trace":"traces"} routed`:N.status==="error"?"Failed":N.status==="running"&&I?"Routing…":"No output";return W.jsxs("button",{type:"button","aria-pressed":U===c,title:`${D1I(N)} · ${b}`,onClick:()=>t(N),className:no("rf-flex rf-min-w-[192px] rf-items-start rf-gap-2 rf-rounded-md rf-border rf-px-2 rf-py-2 rf-text-left md:rf-min-w-0",U===c?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[W.jsx("span",{className:no("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",U===c?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:U+1}),W.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[W.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx("span",{className:"rf-min-w-0 rf-flex-1 rf-truncate rf-text-xs rf-font-medium rf-leading-5 rf-text-gray-800",title:Ctg(N,U),children:Ctg(N,U)}),N.status==="complete"?W.jsx(vIA,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):N.status==="error"?W.jsx(cIg,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):I?W.jsx(b2,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),W.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[R0B(N)," · ",b]})]})]},N.id)})})]}),W.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-gap-3 rf-border-b rf-border-gray-200 rf-px-4 rf-py-3",children:[W.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[p,W.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[c+1," of ",A.length]})]}),I&&W.jsx("button",{type:"button",onClick:()=>t(null),disabled:l,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:l?"Following latest":"Follow latest"}),W.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(N=>W.jsx("button",{type:"button","aria-pressed":w===N,disabled:N==="input"?!y:!D,onClick:()=>o(N),className:no("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",w===N?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:N==="input"?"Input":"Output"},N))})]}),W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-px-4 rf-py-2 rf-text-xs rf-text-gray-600",children:[W.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx("input",{type:"checkbox",checked:C,disabled:w!=="output",onChange:N=>Q(N.target.checked),className:"rf-accent-blue-600"}),W.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:otg}}),"Highlight changes (all layers)"]}),W.jsxs("span",{children:[w==="input"?"Before this phase":"After this phase"," ","· ",F," traces"]})]}),S&&W.jsx("div",{className:no("rf-border-y rf-px-4 rf-py-2 rf-text-xs",h.status==="error"?"rf-border-red-100 rf-bg-red-50 rf-text-red-700":"rf-border-blue-100 rf-bg-blue-50 rf-text-blue-700"),role:"status",children:h.status==="error"?`Routing failed: ${h.error?.message||"No output was captured."}`:k?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),W.jsx("div",{ref:n,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:G?W.jsx(sIg,{circuitJson:G,height:s,allowEditing:!1,clickToInteractEnabled:!1,initialState:P0B,debugGraphics:m}):W.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-border-t rf-border-gray-200 rf-px-4 rf-py-3 rf-text-xs rf-text-gray-500",children:[W.jsxs("span",{children:[R===void 0?"Input unavailable":`${R} input connections`,` · ${D1I(h)}`]}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[W.jsxs("button",{type:"button",disabled:!u,onClick:()=>dk(JSON.stringify(u,null,2),{fileName:`${h.id}-${w}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[W.jsx(qIA,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),W.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>E(!i),className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(qT,{className:no("rf-h-3 rf-w-3",i&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),i&&W.jsx("pre",{className:"rf-m-0 rf-max-h-64 rf-overflow-auto rf-border-t rf-border-gray-200 rf-bg-gray-50 rf-p-4 rf-text-xs","aria-label":`${p} ${w} SRJ`,children:u?JSON.stringify(u,null,2):"No snapshot captured."})]})]})},y1I=({errorMessage:g,errorStack:A,circuitJsonErrors:I})=>{gA.useEffect(()=>{if(wF("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&g){const e=new Error(g);A&&(e.stack=A);try{s9.captureException(e)}catch{}}},[g,A]),gA.useEffect(()=>{if(wF("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&I&&I.length>0)for(const e of I){const t=new Error(e.message||"Circuit JSON Error");e.stack&&(t.stack=e.stack);try{s9.captureException(t,{error_type:e.type})}catch{}}},[I])},Y0B=g=>{gA.useEffect(()=>{try{NVI(g)}catch{}},[g.source,g.component,g.isWebEmbedded,g.activeTab])},w1I="0.0.3028",_0B={version:w1I},Qtg={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},itg=new Map,NuA=g=>{const A=itg.get(g);return A?Object.fromEntries(Object.entries(A.stores).map(([I,e])=>[I,e.getState()])):{}},b0B=(g,A,I)=>{if(g===void 0)return{type:"untracked",connection:A.connect(I)};const e=itg.get(I.name);if(e)return{type:"tracked",store:g,...e};const t={connection:A.connect(I),stores:{}};return itg.set(I.name,t),{type:"tracked",store:g,...t}},u1I=(g,A={})=>(I,e,t)=>{const{enabled:B,anonymousActionType:o,store:C,...Q}=A;let i;try{i=(B??(Qtg?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!i)return(Qtg?"production":void 0)!=="production"&&B&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),g(I,e,t);const{connection:E,...n}=b0B(C,i,Q);let s=!0;t.setState=(c,h,l)=>{const D=I(c,h);if(!s)return D;const d=l===void 0?{type:o||"anonymous"}:typeof l=="string"?{type:l}:l;return C===void 0?(E?.send(d,e()),D):(E?.send({...d,type:`${C}/${d.type}`},{...NuA(Q.name),[C]:t.getState()}),D)};const r=(...c)=>{const h=s;s=!1,I(...c),s=h},a=g(t.setState,e,t);if(n.type==="untracked"?E?.init(a):(n.stores[n.store]=t,E?.init(Object.fromEntries(Object.entries(n.stores).map(([c,h])=>[c,c===n.store?a:h.getState()])))),t.dispatchFromDevtools&&typeof t.dispatch=="function"){let c=!1;const h=t.dispatch;t.dispatch=(...l)=>{(Qtg?"production":void 0)!=="production"&&l[0].type==="__setState"&&!c&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),c=!0),h(...l)}}return E.subscribe(c=>{var h;switch(c.type){case"ACTION":if(typeof c.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Etg(c.payload,l=>{if(l.type==="__setState"){if(C===void 0){r(l.state);return}Object.keys(l.state).length!==1&&console.error(`
|
|
5665
5665
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
5666
5666
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
5667
5667
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|