@tscircuit/runframe 0.0.3028 → 0.0.3029

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.
@@ -5320,7 +5320,7 @@ ${Q.join(`
5320
5320
  ${c}polygon: ${a.polygon.vertices}
5321
5321
  `:Q+=`
5322
5322
  `,a.children.length>0&&E.push(a.children)}return Q}};A.exports=B}}),N6t=fg({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(g,A){var I=M6t(),e=R6t(),t=class{constructor(o){this.polygonTree=new e,this.rootnode=new I(null),o&&this.addPolygons(o)}invert(){this.polygonTree.invert(),this.rootnode.invert()}clipTo(o,B=!1){this.rootnode.clipTo(o,B)}allPolygons(){const o=[];return this.polygonTree.getPolygons(o),o}addPolygons(o){const B=new Array(o.length);for(let C=0;C<o.length;C++)B[C]=this.polygonTree.addChild(o[C]);this.rootnode.addPolygonTreeNodes(B)}clear(){this.polygonTree.clear()}toString(){return"Tree: "+this.polygonTree.toString("")}};A.exports=t}}),sAg=fg({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(g,A){A.exports={Tree:N6t()}}}),x6t=fg({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(g,A){var I=wQ(),e=nAg(),{Tree:t}=sAg(),o=(B,C)=>{if(!e(B,C))return I.create();const Q=new t(I.toPolygons(B)),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=o}}),uwI=fg({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(g,A){var I=ZC(),e=rIA(),t=x6t(),o=(...B)=>{B=I(B);let C=B.shift();return B.forEach(Q=>{C=t(C,Q)}),C=e(C),C};A.exports=o}}),F6t=fg({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(g,A){var I=ZC(),e=wQ(),t=h3(),o=iAg(),B=EAg(),C=uwI(),Q=(...i)=>{i=I(i);const E=i.map(r=>B({z0:-1,z1:1},r)),n=C(E),s=t(n);return o(s,e.toPolygons(n))};A.exports=Q}}),U6t=fg({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(g,A){var I=ZC(),e=aIA(),t=RQ(),o=wQ(),B=F6t(),C=uwI(),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)?B(i):o.isA(E)?C(i):E};A.exports=Q}}),aAg=fg({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(g,A){var I=vi(),e=kyI(),t=o=>e(o,{skipTriangulation:!0}).map(Q=>{const i=Q.map(E=>o[E]);return I.create(i)});A.exports=t}}),GwI=fg({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(g,A){var I=wQ(),e=nAg(),{Tree:t}=sAg(),o=(C,Q)=>{if(!e(C,Q))return B(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)},B=(C,Q)=>{let i=I.toPolygons(C);return i=i.concat(I.toPolygons(Q)),I.create(i)};A.exports=o}}),rAg=fg({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(g,A){var I=ZC(),e=rIA(),t=GwI(),o=(...B)=>{B=I(B);let C;for(C=1;C<B.length;C+=2)B.push(t(B[C-1],B[C]));let Q=B[C-1];return Q=e(Q),Q};A.exports=o}}),mwI=fg({"node_modules/@jscad/modeling/src/operations/minkowski/minkowskiSum.js"(g,A){var I=ZC(),e=wQ(),t=vi(),o=aAg(),B=rAg(),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]:B(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 x=D[0],N=D[R],U=D[R+1],K=E(S,x,N,U);c.push(e.create(K))}}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=o(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}}),J6t=fg({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(g,A){var I=yB(),e=h3(),t=wQ(),o=i=>i.sort((E,n)=>E-n).filter((E,n,s)=>!n||E!==s[n-1]),B=(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=>{B(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:o(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}}),P6t=fg({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(g,A){var I=ZC(),e=wQ(),t=J6t(),o=(...B)=>{if(B=I(B),B.length===0)throw new Error("wrong number of arguments");const C=B.map(Q=>e.isA(Q)?t(Q):Q);return C.length===1?C[0]:C};A.exports=o}}),K6t=fg({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(g,A){var I=wQ(),e=nAg(),{Tree:t}=sAg(),o=(B,C)=>{if(!e(B,C))return I.clone(B);const Q=new t(I.toPolygons(B)),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=o}}),pwI=fg({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(g,A){var I=ZC(),e=rIA(),t=K6t(),o=(...B)=>{B=I(B);let C=B.shift();return B.forEach(Q=>{C=t(C,Q)}),C=e(C),C};A.exports=o}}),L6t=fg({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(g,A){var I=ZC(),e=wQ(),t=h3(),o=iAg(),B=EAg(),C=pwI(),Q=(...i)=>{i=I(i);const E=i.map(r=>B({z0:-1,z1:1},r)),n=C(E),s=t(n);return o(s,e.toPolygons(n))};A.exports=Q}}),Y6t=fg({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(g,A){var I=ZC(),e=aIA(),t=RQ(),o=wQ(),B=L6t(),C=pwI(),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)?B(i):o.isA(E)?C(i):E};A.exports=Q}}),kwI=fg({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(g,A){var I=ZC(),e=wQ(),t=h3(),o=iAg(),B=EAg(),C=rAg(),Q=(...i)=>{i=I(i);const E=i.map(r=>B({z0:-1,z1:1},r)),n=C(E),s=t(n);return o(s,e.toPolygons(n))};A.exports=Q}}),cAg=fg({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(g,A){var I=ZC(),e=aIA(),t=RQ(),o=wQ(),B=kwI(),C=rAg(),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)?B(i):o.isA(E)?C(i):E};A.exports=Q}}),cIA=fg({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(g,A){A.exports={intersect:U6t(),minkowski:mwI(),scission:P6t(),subtract:Y6t(),union:cAg()}}}),AyA=fg({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(g,A){var{EPS:I,TAU:e}=aE(),t=AwI(),o=tAg(),B=Qi(),C=zdA(),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=B.create(),u=E.length;for(let G=0;G<u;G++){const m=(G+1)%u,p=E[G],k=E[m];l?B.subtract(w,p,k):B.subtract(w,k,p),B.normal(w,w),B.normalize(w,w),B.scale(w,w,s);const S=B.add(B.create(),p,w),R=B.add(B.create(),k,w),x=[S,R];if(D!=null&&(a||!a&&m!==0)){const N=t(D[0],D[1],x[0],x[1]);N?(d.pop(),x[0]=N):y.push({c:p,s0:D,s1:x})}D=[S,R],!(m===0&&!a)&&(d.push(x[0]),d.push(x[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=o.create(),p=o.create();y.forEach(k=>{o.fromPoints(m,k.s0[0],k.s0[1]),o.fromPoints(p,k.s1[0],k.s1[1]);const S=o.intersectPointOfLines(m,p);if(Number.isFinite(S[0])&&Number.isFinite(S[1])){const R=k.s0[1],x=G.get(R);d[x]=S,d[(x+1)%d.length]=void 0}else{const R=k.s1[0],x=G.get(R);d[x]=void 0}}),d=d.filter(k=>k!==void 0)}if(r==="round"){let G=Math.floor(c/4);const m=B.create();y.forEach(p=>{let k=B.angle(B.subtract(m,p.s1[0],p.c));if(k-=B.angle(B.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=B.angle(B.subtract(m,p.s0[1],p.c)),x=[];for(let N=1;N<G;N++){const U=R+S*N,K=B.fromAngleRadians(B.create(),U);B.scale(K,K,s),B.add(K,K,p.c),x.push(K)}if(x.length>0){const N=p.s0[1];let U=d.findIndex(K=>B.equals(N,K));U=(U+1)%d.length,d.splice(U,0,...x)}}else{const S=p.s1[0],R=d.findIndex(x=>B.equals(S,x));d.splice(R,1)}})}return d};A.exports=Q}}),_6t=fg({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(g,A){var I=RQ(),e=AyA(),t=(o,B)=>{const C={delta:1,corners:"edge",segments:16},{delta:Q,corners:i,segments:E}=Object.assign({},C,o);if(!(i==="edge"||i==="chamfer"||i==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const r=I.toOutlines(B).map(a=>(o={delta:Q,corners:i,closed:!0,segments:E},e(o,a))).reduce((a,c)=>a.concat(I.toSides(I.fromPoints(c))),[]);return I.create(r)};A.exports=t}}),b6t=fg({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(g,A){var I=ba(),e=yB(),t=wQ(),o=vi(),B=(C,Q)=>{e.dot(o.plane(Q),C)>0&&(Q=o.invert(Q));const E=[Q],n=o.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=o.create([Q.vertices[r],n.vertices[r],n.vertices[a],Q.vertices[a]]);E.push(c)}return E.push(o.invert(n)),t.create(E)};A.exports=B}}),H6t=fg({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(g,A){var{EPS:I,TAU:e}=aE(),t=ba(),o=yB(),B=ywI(),C=wQ(),Q=vi(),i=awI(),E=rIA(),n=GwI(),s=b6t(),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=o.create(),k=o.create();return C.toPolygons(D).forEach((R,x)=>{const N=o.scale(o.create(),Q.plane(R),2*y),U=Q.transform(t.fromTranslation(t.create(),o.scale(o.create(),N,-.5)),R),K=s(N,U);u=n(u,K);const _=R.vertices;for(let H=0;H<_.length;H++){r(G,_[H],Q.plane(R));const T=(H+1)%_.length,j=[_[H],_[T]];a(m,j,Q.plane(R))}}),m.forEach(R=>{const x=R[0],N=R[1],U=x[0],K=x[1],_=o.subtract(o.create(),K,U);o.normalize(_,_);const H=N[0],T=o.cross(o.create(),H,_);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 hA=N[DA],sA=o.dot(T,hA),cA=o.dot(H,hA);let SA=Math.atan2(sA,cA);SA<0&&(SA+=e),c(j,SA),SA=Math.atan2(-sA,-cA),SA<0&&(SA+=e),c(j,SA)}j=j.sort(B);const W=j.length;let O,gA;const tA=[],IA=[],QA=[];for(let DA=-1;DA<W;DA++){const CA=j[DA<0?DA+W:DA],hA=Math.sin(CA),sA=Math.cos(CA);o.scale(p,H,sA*y),o.scale(k,T,hA*y),o.add(p,p,k);const cA=o.add(o.create(),U,p),SA=o.add(o.create(),K,p);let xA=!1;if(DA>=0&&o.distance(cA,O)<I&&(xA=!0),!xA){if(DA>=0){tA.push(cA),IA.push(SA);const aA=[gA,SA,cA,O],FA=Q.create(aA);QA.push(FA)}O=cA,gA=SA}}IA.reverse(),QA.push(Q.create(tA)),QA.push(Q.create(IA));const nA=C.create(QA);u=n(u,nA)}),G.forEach(R=>{const x=R[0],N=R[1],U=N[0];let K=null,_=0;for(let W=1;W<N.length;W++){const O=N[W],gA=o.cross(p,U,O),tA=o.length(gA);tA>.05&&tA>_&&(_=tA,K=O)}K||(K=o.orthogonal(p,U));const H=o.cross(p,U,K);o.normalize(H,H);const T=o.cross(k,H,U),j=i({center:[x[0],x[1],x[2]],radius:y,segments:w,axes:[U,H,T]});u=n(u,j)}),E(u)};A.exports=h}}),v6t=fg({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(g,A){var I=wQ(),e=cAg(),t=H6t(),o=(B,C)=>{const Q={delta:1,corners:"round",segments:12},{delta:i,corners:E,segments:n}=Object.assign({},Q,B);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");B={delta:i,corners:E,segments:n};const r=t(B,C);return e(C,r)};A.exports=o}}),q6t=fg({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(g,A){var I=zdA(),e=Qi(),t=RQ(),o=ha(),B=AyA(),C=E=>{let{external:n,internal:s}=E;I(n)<0?n=n.reverse():s=s.reverse();const r=o.fromPoints({closed:!0},n),a=o.fromPoints({closed:!0},s),c=t.toSides(t.fromPoints(o.toPoints(r))),h=t.toSides(t.fromPoints(o.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=o.toPoints(n);if(l.length===0)throw new Error("the given geometry cannot be empty");const D={points:l,external:B({delta:r,corners:a,segments:c,closed:h},l),internal:B({delta:-r,corners:a,segments:c,closed:h},l)};return n.isClosed?C(D):Q(D,c,a,r)};A.exports=i}}),hAg=fg({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(g,A){var I=ZC(),e=RQ(),t=wQ(),o=ha(),B=_6t(),C=v6t(),Q=q6t(),i=(E,...n)=>{if(n=I(n),n.length===0)throw new Error("wrong number of arguments");const s=n.map(r=>o.isA(r)?Q(E,r):e.isA(r)?B(E,r):t.isA(r)?C(E,r):r);return s.length===1?s[0]:s};A.exports=i}}),T6t=fg({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(g,A){var I=RQ(),e=$$A(),t=AyA(),o=(B,C)=>{const Q={delta:1,corners:"edge",segments:0},{delta:i,corners:E,segments:n}=Object.assign({},Q,B);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=>(B={delta:s.reduce((D,d)=>D+e.arePointsInside(c,e.create(d)),0)%2===0?i:-i,corners:E,closed:!0,segments:n},t(B,c))).reduce((c,h)=>c.concat(I.toSides(I.fromPoints(h))),[]);return I.create(a)};A.exports=o}}),Z6t=fg({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(g,A){var I=ha(),e=AyA(),t=(o,B)=>{const C={delta:1,corners:"edge",closed:B.isClosed,segments:16},{delta:Q,corners:i,closed:E,segments:n}=Object.assign({},C,o);if(!(i==="edge"||i==="chamfer"||i==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');o={delta:Q,corners:i,closed:E,segments:n};const s=e(o,I.toPoints(B));return I.fromPoints({closed:E},s)};A.exports=t}}),O6t=fg({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(g,A){var I=ZC(),e=RQ(),t=ha(),o=T6t(),B=Z6t(),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)?B(Q,n):e.isA(n)?o(Q,n):n);return E.length===1?E[0]:E};A.exports=C}}),MwI=fg({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(g,A){A.exports={expand:hAg(),offset:O6t()}}}),gyA=fg({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(g,A){var I=ba(),e=yB(),t=RQ(),o=p7(),B=$dA(),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=o.fromSides(h);c[2]<0&&o.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)),o.transform(D,u)};return Q={numberOfSlices:r+1,capStart:!0,capEnd:!0,repair:a,callback:d},B(Q,l)};A.exports=C}}),W6t=fg({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(g,A){var I=RQ(),e=ha(),t=gyA(),o=(B,C)=>{if(!C.isClosed)throw new Error("extruded path must be closed");const Q=e.toPoints(C),i=I.fromPoints(Q);return t(B,i)};A.exports=o}}),V6t=fg({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(g,A){var I=ZC(),e=RQ(),t=ha(),o=gyA(),B=W6t(),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)?B(Q,h):e.isA(h)?o(Q,h):h);return c.length===1?c[0]:c};A.exports=C}}),j6t=fg({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(g,A){var I=ha(),e=hAg(),t=gyA(),o=(B,C)=>{const Q={size:1,height:1},{size:i,height:E}=Object.assign({},Q,B);if(B.delta=i,B.offset=[0,0,E],I.toPoints(C).length===0)throw new Error("the given geometry cannot be empty");const s=e(B,C);return t(B,s)};A.exports=o}}),z6t=fg({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(g,A){var{area:I}=iIA(),e=RQ(),t=ha(),o=hAg(),B=gyA(),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(),o(Q,t.fromPoints({closed:!0},l)))).reduce((l,D)=>l.concat(e.toSides(D)),[]),h=e.create(c);return B(Q,h)};A.exports=C}}),X6t=fg({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(g,A){var I=ZC(),e=RQ(),t=ha(),o=j6t(),B=z6t(),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)?o(Q,a):e.isA(a)?B(Q,a):a);return r.length===1?r[0]:r};A.exports=C}}),$6t=fg({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(g,A){var{TAU:I}=aE(),e=ba(),t=RQ(),o=$dA(),B=p7(),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=B.fromSides(D);d.length===0&&(y=B.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 x=s+n/u*S,N=c/u*S,U=(x-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(),x),G),B.transform(m,R)};return o({numberOfSlices:u+1,callback:p},y)};A.exports=C}}),Avt=fg({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(g,A){var I=ZC(),e=eAg(),t=lx(),o=ba(),B=RQ(),C=wQ(),Q=vi(),i=h3(),E=kwI(),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 B.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=o.fromVectorRotation(o.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=>B.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}}),hIA=fg({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(g,A){A.exports={extrudeFromSlices:$dA(),extrudeLinear:V6t(),extrudeRectangular:X6t(),extrudeRotate:lwI(),extrudeHelical:$6t(),project:Avt(),slice:p7()}}}),lAg=fg({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(g,A){var I=Qi(),e=B=>{let C=I.fromValues(1/0,1/0);B.forEach(E=>{(E[1]<C[1]||E[1]===C[1]&&E[0]<C[0])&&(C=E)});const Q=[];B.forEach(E=>{const n=o(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=(B,C,Q)=>(C[0]-B[0])*(Q[1]-B[1])-(C[1]-B[1])*(Q[0]-B[0]),o=(B,C)=>B===0&&C===0?-1/0:-C/B;A.exports=e}}),DAg=fg({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(g,A){var I=RQ(),e=wQ(),t=ha(),o=B=>{const C=new Set,Q=[],i=E=>{const n=E.toString();C.has(n)||(Q.push(E),C.add(n))};return B.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=o}}),gvt=fg({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(g,A){var I=ZC(),e=ha(),t=lAg(),o=DAg(),B=(...C)=>{C=I(C);const Q=o(C),i=t(Q);return e.fromPoints({closed:!0},i)};A.exports=B}}),Ivt=fg({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(g,A){var I=ZC(),e=RQ(),t=lAg(),o=DAg(),B=(...C)=>{C=I(C);const Q=o(C),i=t(Q);return i.length<3?e.create():e.fromPoints(i)};A.exports=B}}),evt=fg({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(g,A){var I=ZC(),e=wQ(),t=DAg(),o=aAg(),B=(...C)=>{C=I(C);const Q=t(C);return Q.length===0?e.create():e.create(o(Q))};A.exports=B}}),SwI=fg({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(g,A){var I=ZC(),e=aIA(),t=RQ(),o=wQ(),B=ha(),C=gvt(),Q=Ivt(),i=evt(),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 B.isA(s)?C(n):t.isA(s)?Q(n):o.isA(s)?i(n):s};A.exports=E}}),tvt=fg({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(g,A){var I=ZC(),e=cAg(),t=SwI(),o=(...B)=>{if(B=I(B),B.length<2)throw new Error("wrong number of arguments");const C=[];for(let Q=1;Q<B.length;Q++)C.push(t(B[Q-1],B[Q]));return e(C)};A.exports=o}}),ovt=fg({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(g,A){A.exports={hull:SwI(),hullChain:tvt(),hullPoints2:lAg(),hullPoints3:aAg()}}}),Bvt=fg({"node_modules/@jscad/modeling/src/operations/minkowski/index.js"(g,A){A.exports={minkowskiSum:mwI()}}}),fwI=fg({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(g,A){var I=yB(),e=vi(),t=(B,C)=>{const Q=Math.abs(e.measureArea(C));return Number.isFinite(Q)&&Q>B},o=(B,C)=>{let Q=C.map(E=>{const n=E.vertices.map(a=>I.snap(I.create(),a,B)),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=B*B*Math.sqrt(3)/4;return Q=Q.filter(E=>t(i,E)),Q};A.exports=o}}),Cvt=fg({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(g,A){var I=eAg(),e=yB(),t=vi(),o=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},B=(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=o(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,x=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,K,_)=>{const H={v1:_.v1,v2:K.v2,next:K.next,prev:_.prev};_.prev.next=H,K.next.prev=H,C(U,K),K.v1=null,K.v2=null,K.next=null,K.prev=null,C(U,_),_.v1=null,_.v2=null,_.next=null,_.prev=null};S[0]===0&&N(y,R,R.prev),S[1]===0&&N(y,x,x.prev)}}else p.next&&B(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}}),Qvt=fg({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(g,A){var I=aE(),e=yB(),t=vi(),o=i=>`${i}`,B=(i,E,n,s,r,a)=>{const c=o(s),h=o(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=o(s),h=o(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=o(w.vertex0);if(u===c&&(u=o(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=o(a);for(let h=0;h<r;h++){let l=h+1;l===r&&(l=0);const D=s.vertices[l],d=o(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=o(l.vertex0),d=o(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=o(u),p=o(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],x=E.get(R)[0],N=w===0?x.vertex0:x.vertex1;if(w===0?x.vertex1:x.vertex0,o(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 K=u,_=G,H=N,T=e.subtract(e.create(),H,K),j=e.dot(e.subtract(e.create(),_,K),T)/e.dot(T,T);if(j>0&&j<1){const W=e.scale(e.create(),T,j);if(e.add(W,W,K),e.squaredDistance(W,_)<I.EPS*I.EPS){const gA=x.polygonindex,tA=a[gA],IA=o(x.vertex1);let QA=-1;for(let sA=0;sA<tA.vertices.length;sA++)if(o(tA.vertices[sA])===IA){QA=sA;break}const nA=tA.vertices.slice(0);nA.splice(QA,0,G);const DA=t.create(nA);a[gA]=DA,C(E,n,s,x.vertex0,x.vertex1,gA);const CA=B(E,n,s,x.vertex0,G,gA),hA=B(E,n,s,G,x.vertex1,gA);CA!==null&&r.set(CA,!0),hA!==null&&r.set(hA,!0),D=!1,w=2,c=!0;break}}}}}}D&&r.delete(l)}if(!c)break}i=a}return E.clear(),i};A.exports=Q}}),ivt=fg({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(g,A){var I=yB(),e=vi(),t=(B,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]),B);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)},o=(B,C)=>{const Q=[];return C.forEach(i=>{t(B,i,Q)}),Q};A.exports=o}}),Evt=fg({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(g,A){var I=ZC(),e=h3(),t=RQ(),o=wQ(),B=ha(),C=fwI(),Q=Cvt(),i=Qvt(),E=ivt(),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=o.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(B.isA(D))return n(c,D);if(t.isA(D))return s(c,D);if(o.isA(D))return r(c,D);throw new Error("invalid geometry")});return l.length===1?l[0]:l};A.exports=a}}),nvt=fg({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(g,A){var I=ZC(),e=Qi(),t=RQ(),o=wQ(),B=ha(),C=h3(),Q=fwI(),i=r=>{const a=C(r),h=B.toPoints(r).map(l=>e.snap(e.create(),l,a));return B.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=o.toPolygons(r),h=Q(a,c);return o.create(h)},s=(...r)=>{if(r=I(r),r.length===0)throw new Error("wrong number of arguments");const a=r.map(c=>B.isA(c)?i(c):t.isA(c)?E(c):o.isA(c)?n(c):c);return a.length===1?a[0]:a};A.exports=s}}),svt=fg({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(g,A){A.exports={generalize:Evt(),snap:nvt(),retessellate:rIA()}}}),avt=fg({"node_modules/@jscad/modeling/src/utils/padArrayToLength.js"(g,A){var I=(e,t,o)=>{for(e=e.slice();e.length<o;)e.push(t);return e};A.exports=I}}),rvt=fg({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(g,A){var I=ZC(),e=avt(),t=oAg(),{translate:o}=r5(),B=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 o(a,E)},i=(E,...n)=>{E=Object.assign({},{modes:["center","center","min"],relativeTo:[0,0,0],grouped:!1},E),E=B(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}}),IyA=fg({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(g,A){var I=ZC(),e=RQ(),t=wQ(),o=ha(),B=s5(),{translate:C}=r5(),Q=(r,a)=>{const c={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:h,relativeTo:l}=Object.assign({},c,r),D=B(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=>o.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}}}),eyA=fg({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(g,A){var I=ZC(),e=ba(),t=RQ(),o=wQ(),B=ha(),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=>B.isA(c)?B.transform(r,c):t.isA(c)?t.transform(r,c):o.isA(c)?o.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}}}),cvt=fg({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(g,A){var I=ZC(),e=RQ(),t=wQ(),o=ha(),B=(C,...Q)=>{if(Q=I(Q),Q.length===0)throw new Error("wrong number of arguments");const i=Q.map(E=>o.isA(E)?o.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=B}}),h5=fg({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(g,A){A.exports={align:rvt(),center:IyA().center,centerX:IyA().centerX,centerY:IyA().centerY,centerZ:IyA().centerZ,mirror:nIA().mirror,mirrorX:nIA().mirrorX,mirrorY:nIA().mirrorY,mirrorZ:nIA().mirrorZ,rotate:sIA().rotate,rotateX:sIA().rotateX,rotateY:sIA().rotateY,rotateZ:sIA().rotateZ,scale:eyA().scale,scaleX:eyA().scaleX,scaleY:eyA().scaleY,scaleZ:eyA().scaleZ,transform:cvt(),translate:r5().translate,translateX:r5().translateX,translateY:r5().translateY,translateZ:r5().translateZ}}}),tyA=fg({"node_modules/@jscad/modeling/src/index.js"(g,A){A.exports={colors:jdA(),curves:EHt(),geometries:AAg(),maths:JHt(),measurements:BwI(),primitives:c5(),text:y6t(),utils:wwI(),booleans:cIA(),expansions:MwI(),extrusions:hIA(),hulls:ovt(),minkowski:Bvt(),modifiers:svt(),transforms:h5()}}}),RwI={};xR(RwI,{ANGLE_ORDER:()=>dAg,ARRAY_TYPE:()=>Ni,EPSILON:()=>rB,RANDOM:()=>Z2,equals:()=>dvt,round:()=>Dx,setMatrixArrayType:()=>hvt,toDegree:()=>Dvt,toRadian:()=>lvt});function Dx(g){return g>=0?Math.round(g):g%.5===0?Math.floor(g):Math.round(g)}function hvt(g){Ni=g}function lvt(g){return g*NwI}function Dvt(g){return g*xwI}function dvt(g,A){var I=arguments.length>2&&arguments[2]!==void 0?arguments[2]:rB;return Math.abs(g-A)<=I*Math.max(1,Math.abs(g),Math.abs(A))}var rB,Ni,Z2,dAg,NwI,xwI,dx=NR({"node_modules/gl-matrix/esm/common.js"(){rB=1e-6,Ni=typeof Float32Array<"u"?Float32Array:Array,Z2=Math.random,dAg="zyx",NwI=Math.PI/180,xwI=180/Math.PI}}),FwI={};xR(FwI,{LDU:()=>Pvt,add:()=>Kvt,adjoint:()=>Svt,clone:()=>wvt,copy:()=>uvt,create:()=>yvt,determinant:()=>fvt,equals:()=>Yvt,exactEquals:()=>Lvt,frob:()=>Jvt,fromRotation:()=>xvt,fromScaling:()=>Fvt,fromValues:()=>mvt,identity:()=>Gvt,invert:()=>Mvt,mul:()=>PwI,multiply:()=>UwI,multiplyScalar:()=>_vt,multiplyScalarAndAdd:()=>bvt,rotate:()=>Rvt,scale:()=>Nvt,set:()=>pvt,str:()=>Uvt,sub:()=>KwI,subtract:()=>JwI,transpose:()=>kvt});function yvt(){var g=new Ni(4);return Ni!=Float32Array&&(g[1]=0,g[2]=0),g[0]=1,g[3]=1,g}function wvt(g){var A=new Ni(4);return A[0]=g[0],A[1]=g[1],A[2]=g[2],A[3]=g[3],A}function uvt(g,A){return g[0]=A[0],g[1]=A[1],g[2]=A[2],g[3]=A[3],g}function Gvt(g){return g[0]=1,g[1]=0,g[2]=0,g[3]=1,g}function mvt(g,A,I,e){var t=new Ni(4);return t[0]=g,t[1]=A,t[2]=I,t[3]=e,t}function pvt(g,A,I,e,t){return g[0]=A,g[1]=I,g[2]=e,g[3]=t,g}function kvt(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 Mvt(g,A){var I=A[0],e=A[1],t=A[2],o=A[3],B=I*o-t*e;return B?(B=1/B,g[0]=o*B,g[1]=-e*B,g[2]=-t*B,g[3]=I*B,g):null}function Svt(g,A){var I=A[0];return g[0]=A[3],g[1]=-A[1],g[2]=-A[2],g[3]=I,g}function fvt(g){return g[0]*g[3]-g[2]*g[1]}function UwI(g,A,I){var e=A[0],t=A[1],o=A[2],B=A[3],C=I[0],Q=I[1],i=I[2],E=I[3];return g[0]=e*C+o*Q,g[1]=t*C+B*Q,g[2]=e*i+o*E,g[3]=t*i+B*E,g}function Rvt(g,A,I){var e=A[0],t=A[1],o=A[2],B=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]=e*-C+o*Q,g[3]=t*-C+B*Q,g}function Nvt(g,A,I){var e=A[0],t=A[1],o=A[2],B=A[3],C=I[0],Q=I[1];return g[0]=e*C,g[1]=t*C,g[2]=o*Q,g[3]=B*Q,g}function xvt(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 Fvt(g,A){return g[0]=A[0],g[1]=0,g[2]=0,g[3]=A[1],g}function Uvt(g){return"mat2("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")"}function Jvt(g){return Math.sqrt(g[0]*g[0]+g[1]*g[1]+g[2]*g[2]+g[3]*g[3])}function Pvt(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 Kvt(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 JwI(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 Lvt(g,A){return g[0]===A[0]&&g[1]===A[1]&&g[2]===A[2]&&g[3]===A[3]}function Yvt(g,A){var I=g[0],e=g[1],t=g[2],o=g[3],B=A[0],C=A[1],Q=A[2],i=A[3];return Math.abs(I-B)<=rB*Math.max(1,Math.abs(I),Math.abs(B))&&Math.abs(e-C)<=rB*Math.max(1,Math.abs(e),Math.abs(C))&&Math.abs(t-Q)<=rB*Math.max(1,Math.abs(t),Math.abs(Q))&&Math.abs(o-i)<=rB*Math.max(1,Math.abs(o),Math.abs(i))}function _vt(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 bvt(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 PwI,KwI,Hvt=NR({"node_modules/gl-matrix/esm/mat2.js"(){dx(),PwI=UwI,KwI=JwI}}),LwI={};xR(LwI,{add:()=>oqt,clone:()=>qvt,copy:()=>Tvt,create:()=>vvt,determinant:()=>jvt,equals:()=>iqt,exactEquals:()=>Qqt,frob:()=>tqt,fromRotation:()=>Aqt,fromScaling:()=>gqt,fromTranslation:()=>Iqt,fromValues:()=>Ovt,identity:()=>Zvt,invert:()=>Vvt,mul:()=>bwI,multiply:()=>YwI,multiplyScalar:()=>Bqt,multiplyScalarAndAdd:()=>Cqt,rotate:()=>zvt,scale:()=>Xvt,set:()=>Wvt,str:()=>eqt,sub:()=>HwI,subtract:()=>_wI,translate:()=>$vt});function vvt(){var g=new Ni(6);return Ni!=Float32Array&&(g[1]=0,g[2]=0,g[4]=0,g[5]=0),g[0]=1,g[3]=1,g}function qvt(g){var A=new Ni(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 Tvt(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 Zvt(g){return g[0]=1,g[1]=0,g[2]=0,g[3]=1,g[4]=0,g[5]=0,g}function Ovt(g,A,I,e,t,o){var B=new Ni(6);return B[0]=g,B[1]=A,B[2]=I,B[3]=e,B[4]=t,B[5]=o,B}function Wvt(g,A,I,e,t,o,B){return g[0]=A,g[1]=I,g[2]=e,g[3]=t,g[4]=o,g[5]=B,g}function Vvt(g,A){var I=A[0],e=A[1],t=A[2],o=A[3],B=A[4],C=A[5],Q=I*o-e*t;return Q?(Q=1/Q,g[0]=o*Q,g[1]=-e*Q,g[2]=-t*Q,g[3]=I*Q,g[4]=(t*C-o*B)*Q,g[5]=(e*B-I*C)*Q,g):null}function jvt(g){return g[0]*g[3]-g[1]*g[2]}function YwI(g,A,I){var e=A[0],t=A[1],o=A[2],B=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+o*E,g[1]=t*i+B*E,g[2]=e*n+o*s,g[3]=t*n+B*s,g[4]=e*r+o*a+C,g[5]=t*r+B*a+Q,g}function zvt(g,A,I){var e=A[0],t=A[1],o=A[2],B=A[3],C=A[4],Q=A[5],i=Math.sin(I),E=Math.cos(I);return g[0]=e*E+o*i,g[1]=t*E+B*i,g[2]=e*-i+o*E,g[3]=t*-i+B*E,g[4]=C,g[5]=Q,g}function Xvt(g,A,I){var e=A[0],t=A[1],o=A[2],B=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]=o*E,g[3]=B*E,g[4]=C,g[5]=Q,g}function $vt(g,A,I){var e=A[0],t=A[1],o=A[2],B=A[3],C=A[4],Q=A[5],i=I[0],E=I[1];return g[0]=e,g[1]=t,g[2]=o,g[3]=B,g[4]=e*i+o*E+C,g[5]=t*i+B*E+Q,g}function Aqt(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 gqt(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 Iqt(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 eqt(g){return"mat2d("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+", "+g[4]+", "+g[5]+")"}function tqt(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 oqt(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 _wI(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 Bqt(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 Cqt(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 Qqt(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 iqt(g,A){var I=g[0],e=g[1],t=g[2],o=g[3],B=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)<=rB*Math.max(1,Math.abs(I),Math.abs(Q))&&Math.abs(e-i)<=rB*Math.max(1,Math.abs(e),Math.abs(i))&&Math.abs(t-E)<=rB*Math.max(1,Math.abs(t),Math.abs(E))&&Math.abs(o-n)<=rB*Math.max(1,Math.abs(o),Math.abs(n))&&Math.abs(B-s)<=rB*Math.max(1,Math.abs(B),Math.abs(s))&&Math.abs(C-r)<=rB*Math.max(1,Math.abs(C),Math.abs(r))}var bwI,HwI,Eqt=NR({"node_modules/gl-matrix/esm/mat2d.js"(){dx(),bwI=YwI,HwI=_wI}}),vwI={};xR(vwI,{add:()=>Fqt,adjoint:()=>dqt,clone:()=>sqt,copy:()=>aqt,create:()=>qwI,determinant:()=>yqt,equals:()=>Kqt,exactEquals:()=>Pqt,frob:()=>xqt,fromMat2d:()=>Mqt,fromMat4:()=>nqt,fromQuat:()=>Sqt,fromRotation:()=>pqt,fromScaling:()=>kqt,fromTranslation:()=>mqt,fromValues:()=>rqt,identity:()=>hqt,invert:()=>Dqt,mul:()=>OwI,multiply:()=>TwI,multiplyScalar:()=>Uqt,multiplyScalarAndAdd:()=>Jqt,normalFromMat4:()=>fqt,projection:()=>Rqt,rotate:()=>uqt,scale:()=>Gqt,set:()=>cqt,str:()=>Nqt,sub:()=>WwI,subtract:()=>ZwI,translate:()=>wqt,transpose:()=>lqt});function qwI(){var g=new Ni(9);return Ni!=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 nqt(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 sqt(g){var A=new Ni(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 aqt(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 rqt(g,A,I,e,t,o,B,C,Q){var i=new Ni(9);return i[0]=g,i[1]=A,i[2]=I,i[3]=e,i[4]=t,i[5]=o,i[6]=B,i[7]=C,i[8]=Q,i}function cqt(g,A,I,e,t,o,B,C,Q,i){return g[0]=A,g[1]=I,g[2]=e,g[3]=t,g[4]=o,g[5]=B,g[6]=C,g[7]=Q,g[8]=i,g}function hqt(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 lqt(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 Dqt(g,A){var I=A[0],e=A[1],t=A[2],o=A[3],B=A[4],C=A[5],Q=A[6],i=A[7],E=A[8],n=E*B-C*i,s=-E*o+C*Q,r=i*o-B*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*B)*a,g[3]=s*a,g[4]=(E*I-t*Q)*a,g[5]=(-C*I+t*o)*a,g[6]=r*a,g[7]=(-i*I+e*Q)*a,g[8]=(B*I-e*o)*a,g):null}function dqt(g,A){var I=A[0],e=A[1],t=A[2],o=A[3],B=A[4],C=A[5],Q=A[6],i=A[7],E=A[8];return g[0]=B*E-C*i,g[1]=t*i-e*E,g[2]=e*C-t*B,g[3]=C*Q-o*E,g[4]=I*E-t*Q,g[5]=t*o-I*C,g[6]=o*i-B*Q,g[7]=e*Q-I*i,g[8]=I*B-e*o,g}function yqt(g){var A=g[0],I=g[1],e=g[2],t=g[3],o=g[4],B=g[5],C=g[6],Q=g[7],i=g[8];return A*(i*o-B*Q)+I*(-i*t+B*C)+e*(Q*t-o*C)}function TwI(g,A,I){var e=A[0],t=A[1],o=A[2],B=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*B+a*i,g[1]=s*t+r*C+a*E,g[2]=s*o+r*Q+a*n,g[3]=c*e+h*B+l*i,g[4]=c*t+h*C+l*E,g[5]=c*o+h*Q+l*n,g[6]=D*e+d*B+y*i,g[7]=D*t+d*C+y*E,g[8]=D*o+d*Q+y*n,g}function wqt(g,A,I){var e=A[0],t=A[1],o=A[2],B=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]=o,g[3]=B,g[4]=C,g[5]=Q,g[6]=s*e+r*B+i,g[7]=s*t+r*C+E,g[8]=s*o+r*Q+n,g}function uqt(g,A,I){var e=A[0],t=A[1],o=A[2],B=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*B,g[1]=r*t+s*C,g[2]=r*o+s*Q,g[3]=r*B-s*e,g[4]=r*C-s*t,g[5]=r*Q-s*o,g[6]=i,g[7]=E,g[8]=n,g}function Gqt(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 mqt(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 pqt(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 kqt(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 Mqt(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 Sqt(g,A){var I=A[0],e=A[1],t=A[2],o=A[3],B=I+I,C=e+e,Q=t+t,i=I*B,E=e*B,n=e*C,s=t*B,r=t*C,a=t*Q,c=o*B,h=o*C,l=o*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 fqt(g,A){var I=A[0],e=A[1],t=A[2],o=A[3],B=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*B,d=I*Q-t*B,y=I*i-o*B,w=e*Q-t*C,u=e*i-o*C,G=t*i-o*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,x=s*l-r*h,N=D*x-d*R+y*S+w*k-u*p+G*m;return N?(N=1/N,g[0]=(C*x-Q*R+i*S)*N,g[1]=(Q*k-B*x-i*p)*N,g[2]=(B*R-C*k+i*m)*N,g[3]=(t*R-e*x-o*S)*N,g[4]=(I*x-t*k+o*p)*N,g[5]=(e*k-I*R-o*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 Rqt(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 Nqt(g){return"mat3("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+", "+g[4]+", "+g[5]+", "+g[6]+", "+g[7]+", "+g[8]+")"}function xqt(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 Fqt(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 ZwI(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 Uqt(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 Jqt(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 Pqt(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 Kqt(g,A){var I=g[0],e=g[1],t=g[2],o=g[3],B=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)<=rB*Math.max(1,Math.abs(I),Math.abs(n))&&Math.abs(e-s)<=rB*Math.max(1,Math.abs(e),Math.abs(s))&&Math.abs(t-r)<=rB*Math.max(1,Math.abs(t),Math.abs(r))&&Math.abs(o-a)<=rB*Math.max(1,Math.abs(o),Math.abs(a))&&Math.abs(B-c)<=rB*Math.max(1,Math.abs(B),Math.abs(c))&&Math.abs(C-h)<=rB*Math.max(1,Math.abs(C),Math.abs(h))&&Math.abs(Q-l)<=rB*Math.max(1,Math.abs(Q),Math.abs(l))&&Math.abs(i-D)<=rB*Math.max(1,Math.abs(i),Math.abs(D))&&Math.abs(E-d)<=rB*Math.max(1,Math.abs(E),Math.abs(d))}var OwI,WwI,VwI=NR({"node_modules/gl-matrix/esm/mat3.js"(){dx(),OwI=TwI,WwI=ZwI}}),jwI={};xR(jwI,{add:()=>DTt,adjoint:()=>Tqt,clone:()=>Yqt,copy:()=>_qt,create:()=>Lqt,decompose:()=>BTt,determinant:()=>Zqt,equals:()=>uTt,exactEquals:()=>wTt,frob:()=>lTt,fromQuat:()=>iTt,fromQuat2:()=>oTt,fromRotation:()=>gTt,fromRotationTranslation:()=>$wI,fromRotationTranslationScale:()=>CTt,fromRotationTranslationScaleOrigin:()=>QTt,fromScaling:()=>ATt,fromTranslation:()=>$qt,fromValues:()=>bqt,fromXRotation:()=>ITt,fromYRotation:()=>eTt,fromZRotation:()=>tTt,frustum:()=>ETt,getRotation:()=>IuI,getScaling:()=>guI,getTranslation:()=>AuI,identity:()=>zwI,invert:()=>qqt,lookAt:()=>rTt,mul:()=>QuI,multiply:()=>XwI,multiplyScalar:()=>dTt,multiplyScalarAndAdd:()=>yTt,ortho:()=>CuI,orthoNO:()=>tuI,orthoZO:()=>aTt,perspective:()=>BuI,perspectiveFromFieldOfView:()=>sTt,perspectiveNO:()=>euI,perspectiveZO:()=>nTt,rotate:()=>Vqt,rotateX:()=>jqt,rotateY:()=>zqt,rotateZ:()=>Xqt,scale:()=>Wqt,set:()=>Hqt,str:()=>hTt,sub:()=>iuI,subtract:()=>ouI,targetTo:()=>cTt,translate:()=>Oqt,transpose:()=>vqt});function Lqt(){var g=new Ni(16);return Ni!=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 Yqt(g){var A=new Ni(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 _qt(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 bqt(g,A,I,e,t,o,B,C,Q,i,E,n,s,r,a,c){var h=new Ni(16);return h[0]=g,h[1]=A,h[2]=I,h[3]=e,h[4]=t,h[5]=o,h[6]=B,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 Hqt(g,A,I,e,t,o,B,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]=o,g[5]=B,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 zwI(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 vqt(g,A){if(g===A){var I=A[1],e=A[2],t=A[3],o=A[6],B=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]=o,g[11]=A[14],g[12]=t,g[13]=B,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 qqt(g,A){var I=A[0],e=A[1],t=A[2],o=A[3],B=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*B,d=I*Q-t*B,y=I*i-o*B,w=e*Q-t*C,u=e*i-o*C,G=t*i-o*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,x=s*l-r*h,N=D*x-d*R+y*S+w*k-u*p+G*m;return N?(N=1/N,g[0]=(C*x-Q*R+i*S)*N,g[1]=(t*R-e*x-o*S)*N,g[2]=(c*G-h*u+l*w)*N,g[3]=(s*u-n*G-r*w)*N,g[4]=(Q*k-B*x-i*p)*N,g[5]=(I*x-t*k+o*p)*N,g[6]=(h*y-a*G-l*d)*N,g[7]=(E*G-s*y+r*d)*N,g[8]=(B*R-C*k+i*m)*N,g[9]=(e*k-I*R-o*m)*N,g[10]=(a*u-c*y+l*D)*N,g[11]=(n*y-E*u-r*D)*N,g[12]=(C*p-B*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 Tqt(g,A){var I=A[0],e=A[1],t=A[2],o=A[3],B=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*B,d=I*Q-t*B,y=I*i-o*B,w=e*Q-t*C,u=e*i-o*C,G=t*i-o*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,x=s*l-r*h;return g[0]=C*x-Q*R+i*S,g[1]=t*R-e*x-o*S,g[2]=c*G-h*u+l*w,g[3]=s*u-n*G-r*w,g[4]=Q*k-B*x-i*p,g[5]=I*x-t*k+o*p,g[6]=h*y-a*G-l*d,g[7]=E*G-s*y+r*d,g[8]=B*R-C*k+i*m,g[9]=e*k-I*R-o*m,g[10]=a*u-c*y+l*D,g[11]=n*y-E*u-r*D,g[12]=C*p-B*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 Zqt(g){var A=g[0],I=g[1],e=g[2],t=g[3],o=g[4],B=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*B-I*o,D=A*C-e*o,d=I*C-e*B,y=i*a-E*r,w=i*c-n*r,u=E*c-n*a,G=A*u-I*w+e*y,m=o*u-B*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 XwI(g,A,I){var e=A[0],t=A[1],o=A[2],B=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*o+y*i+w*r+u*l,g[3]=d*B+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*o+y*i+w*r+u*l,g[7]=d*B+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*o+y*i+w*r+u*l,g[11]=d*B+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*o+y*i+w*r+u*l,g[15]=d*B+y*E+w*a+u*D,g}function Oqt(g,A,I){var e=I[0],t=I[1],o=I[2],B,C,Q,i,E,n,s,r,a,c,h,l;return A===g?(g[12]=A[0]*e+A[4]*t+A[8]*o+A[12],g[13]=A[1]*e+A[5]*t+A[9]*o+A[13],g[14]=A[2]*e+A[6]*t+A[10]*o+A[14],g[15]=A[3]*e+A[7]*t+A[11]*o+A[15]):(B=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]=B,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]=B*e+E*t+a*o+A[12],g[13]=C*e+n*t+c*o+A[13],g[14]=Q*e+s*t+h*o+A[14],g[15]=i*e+r*t+l*o+A[15]),g}function Wqt(g,A,I){var e=I[0],t=I[1],o=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]*o,g[9]=A[9]*o,g[10]=A[10]*o,g[11]=A[11]*o,g[12]=A[12],g[13]=A[13],g[14]=A[14],g[15]=A[15],g}function Vqt(g,A,I,e){var t=e[0],o=e[1],B=e[2],C=Math.sqrt(t*t+o*o+B*B),Q,i,E,n,s,r,a,c,h,l,D,d,y,w,u,G,m,p,k,S,R,x,N,U;return C<rB?null:(C=1/C,t*=C,o*=C,B*=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=o*t*E+B*Q,p=B*t*E-o*Q,k=t*o*E-B*Q,S=o*o*E+i,R=B*o*E+t*Q,x=t*B*E+o*Q,N=o*B*E-t*Q,U=B*B*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*x+c*N+d*U,g[9]=s*x+h*N+y*U,g[10]=r*x+l*N+w*U,g[11]=a*x+D*N+u*U,A!==g&&(g[12]=A[12],g[13]=A[13],g[14]=A[14],g[15]=A[15]),g)}function jqt(g,A,I){var e=Math.sin(I),t=Math.cos(I),o=A[4],B=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]=o*t+i*e,g[5]=B*t+E*e,g[6]=C*t+n*e,g[7]=Q*t+s*e,g[8]=i*t-o*e,g[9]=E*t-B*e,g[10]=n*t-C*e,g[11]=s*t-Q*e,g}function zqt(g,A,I){var e=Math.sin(I),t=Math.cos(I),o=A[0],B=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]=o*t-i*e,g[1]=B*t-E*e,g[2]=C*t-n*e,g[3]=Q*t-s*e,g[8]=o*e+i*t,g[9]=B*e+E*t,g[10]=C*e+n*t,g[11]=Q*e+s*t,g}function Xqt(g,A,I){var e=Math.sin(I),t=Math.cos(I),o=A[0],B=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]=o*t+i*e,g[1]=B*t+E*e,g[2]=C*t+n*e,g[3]=Q*t+s*e,g[4]=i*t-o*e,g[5]=E*t-B*e,g[6]=n*t-C*e,g[7]=s*t-Q*e,g}function $qt(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 ATt(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 gTt(g,A,I){var e=I[0],t=I[1],o=I[2],B=Math.sqrt(e*e+t*t+o*o),C,Q,i;return B<rB?null:(B=1/B,e*=B,t*=B,o*=B,C=Math.sin(A),Q=Math.cos(A),i=1-Q,g[0]=e*e*i+Q,g[1]=t*e*i+o*C,g[2]=o*e*i-t*C,g[3]=0,g[4]=e*t*i-o*C,g[5]=t*t*i+Q,g[6]=o*t*i+e*C,g[7]=0,g[8]=e*o*i+t*C,g[9]=t*o*i-e*C,g[10]=o*o*i+Q,g[11]=0,g[12]=0,g[13]=0,g[14]=0,g[15]=1,g)}function ITt(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 eTt(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 tTt(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 $wI(g,A,I){var e=A[0],t=A[1],o=A[2],B=A[3],C=e+e,Q=t+t,i=o+o,E=e*C,n=e*Q,s=e*i,r=t*Q,a=t*i,c=o*i,h=B*C,l=B*Q,D=B*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 oTt(g,A){var I=new Ni(3),e=-A[0],t=-A[1],o=-A[2],B=A[3],C=A[4],Q=A[5],i=A[6],E=A[7],n=e*e+t*t+o*o+B*B;return n>0?(I[0]=(C*B+E*e+Q*o-i*t)*2/n,I[1]=(Q*B+E*t+i*e-C*o)*2/n,I[2]=(i*B+E*o+C*t-Q*e)*2/n):(I[0]=(C*B+E*e+Q*o-i*t)*2,I[1]=(Q*B+E*t+i*e-C*o)*2,I[2]=(i*B+E*o+C*t-Q*e)*2),$wI(g,A,I),g}function AuI(g,A){return g[0]=A[12],g[1]=A[13],g[2]=A[14],g}function guI(g,A){var I=A[0],e=A[1],t=A[2],o=A[4],B=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(o*o+B*B+C*C),g[2]=Math.sqrt(Q*Q+i*i+E*E),g}function IuI(g,A){var I=new Ni(3);guI(I,A);var e=1/I[0],t=1/I[1],o=1/I[2],B=A[0]*e,C=A[1]*t,Q=A[2]*o,i=A[4]*e,E=A[5]*t,n=A[6]*o,s=A[8]*e,r=A[9]*t,a=A[10]*o,c=B+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):B>E&&B>a?(h=Math.sqrt(1+B-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-B-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-B-E)*2,g[3]=(C-i)/h,g[0]=(s+Q)/h,g[1]=(n+r)/h,g[2]=.25*h),g}function BTt(g,A,I,e){A[0]=e[12],A[1]=e[13],A[2]=e[14];var t=e[0],o=e[1],B=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+o*o+B*B),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=o*a,D=B*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 CTt(g,A,I,e){var t=A[0],o=A[1],B=A[2],C=A[3],Q=t+t,i=o+o,E=B+B,n=t*Q,s=t*i,r=t*E,a=o*i,c=o*E,h=B*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 QTt(g,A,I,e,t){var o=A[0],B=A[1],C=A[2],Q=A[3],i=o+o,E=B+B,n=C+C,s=o*i,r=o*E,a=o*n,c=B*E,h=B*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,x=(a-d)*w,N=(r-y)*u,U=(1-(s+l))*u,K=(h+D)*u,_=(a+d)*G,H=(h-D)*G,T=(1-(s+c))*G;return g[0]=S,g[1]=R,g[2]=x,g[3]=0,g[4]=N,g[5]=U,g[6]=K,g[7]=0,g[8]=_,g[9]=H,g[10]=T,g[11]=0,g[12]=I[0]+m-(S*m+N*p+_*k),g[13]=I[1]+p-(R*m+U*p+H*k),g[14]=I[2]+k-(x*m+K*p+T*k),g[15]=1,g}function iTt(g,A){var I=A[0],e=A[1],t=A[2],o=A[3],B=I+I,C=e+e,Q=t+t,i=I*B,E=e*B,n=e*C,s=t*B,r=t*C,a=t*Q,c=o*B,h=o*C,l=o*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 ETt(g,A,I,e,t,o,B){var C=1/(I-A),Q=1/(t-e),i=1/(o-B);return g[0]=o*2*C,g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[5]=o*2*Q,g[6]=0,g[7]=0,g[8]=(I+A)*C,g[9]=(t+e)*Q,g[10]=(B+o)*i,g[11]=-1,g[12]=0,g[13]=0,g[14]=B*o*2*i,g[15]=0,g}function euI(g,A,I,e,t){var o=1/Math.tan(A/2);if(g[0]=o/I,g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[5]=o,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 B=1/(e-t);g[10]=(t+e)*B,g[14]=2*t*e*B}else g[10]=-1,g[14]=-2*e;return g}function nTt(g,A,I,e,t){var o=1/Math.tan(A/2);if(g[0]=o/I,g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[5]=o,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 B=1/(e-t);g[10]=t*B,g[14]=t*e*B}else g[10]=-1,g[14]=-e;return g}function sTt(g,A,I,e){var t=Math.tan(A.upDegrees*Math.PI/180),o=Math.tan(A.downDegrees*Math.PI/180),B=Math.tan(A.leftDegrees*Math.PI/180),C=Math.tan(A.rightDegrees*Math.PI/180),Q=2/(B+C),i=2/(t+o);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]=-((B-C)*Q*.5),g[9]=(t-o)*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 tuI(g,A,I,e,t,o,B){var C=1/(A-I),Q=1/(e-t),i=1/(o-B);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]=(B+o)*i,g[15]=1,g}function aTt(g,A,I,e,t,o,B){var C=1/(A-I),Q=1/(e-t),i=1/(o-B);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]=o*i,g[15]=1,g}function rTt(g,A,I,e){var t,o,B,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)<rB&&Math.abs(c-w)<rB&&Math.abs(h-u)<rB?zwI(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,o=d*E-l*s,B=l*n-D*E,r=Math.sqrt(t*t+o*o+B*B),r?(r=1/r,t*=r,o*=r,B*=r):(t=0,o=0,B=0),C=n*B-s*o,Q=s*t-E*B,i=E*o-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]=o,g[5]=Q,g[6]=n,g[7]=0,g[8]=B,g[9]=i,g[10]=s,g[11]=0,g[12]=-(t*a+o*c+B*h),g[13]=-(C*a+Q*c+i*h),g[14]=-(E*a+n*c+s*h),g[15]=1,g)}function cTt(g,A,I,e){var t=A[0],o=A[1],B=A[2],C=e[0],Q=e[1],i=e[2],E=t-I[0],n=o-I[1],s=B-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]=o,g[14]=B,g[15]=1,g}function hTt(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 lTt(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 DTt(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 ouI(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 dTt(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 yTt(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 wTt(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 uTt(g,A){var I=g[0],e=g[1],t=g[2],o=g[3],B=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],x=A[11],N=A[12],U=A[13],K=A[14],_=A[15];return Math.abs(I-D)<=rB*Math.max(1,Math.abs(I),Math.abs(D))&&Math.abs(e-d)<=rB*Math.max(1,Math.abs(e),Math.abs(d))&&Math.abs(t-y)<=rB*Math.max(1,Math.abs(t),Math.abs(y))&&Math.abs(o-w)<=rB*Math.max(1,Math.abs(o),Math.abs(w))&&Math.abs(B-u)<=rB*Math.max(1,Math.abs(B),Math.abs(u))&&Math.abs(C-G)<=rB*Math.max(1,Math.abs(C),Math.abs(G))&&Math.abs(Q-m)<=rB*Math.max(1,Math.abs(Q),Math.abs(m))&&Math.abs(i-p)<=rB*Math.max(1,Math.abs(i),Math.abs(p))&&Math.abs(E-k)<=rB*Math.max(1,Math.abs(E),Math.abs(k))&&Math.abs(n-S)<=rB*Math.max(1,Math.abs(n),Math.abs(S))&&Math.abs(s-R)<=rB*Math.max(1,Math.abs(s),Math.abs(R))&&Math.abs(r-x)<=rB*Math.max(1,Math.abs(r),Math.abs(x))&&Math.abs(a-N)<=rB*Math.max(1,Math.abs(a),Math.abs(N))&&Math.abs(c-U)<=rB*Math.max(1,Math.abs(c),Math.abs(U))&&Math.abs(h-K)<=rB*Math.max(1,Math.abs(h),Math.abs(K))&&Math.abs(l-_)<=rB*Math.max(1,Math.abs(l),Math.abs(_))}var BuI,CuI,QuI,iuI,EuI=NR({"node_modules/gl-matrix/esm/mat4.js"(){dx(),BuI=euI,CuI=tuI,QuI=XwI,iuI=ouI}}),nuI={};xR(nuI,{add:()=>kTt,angle:()=>OTt,bezier:()=>YTt,ceil:()=>MTt,clone:()=>GTt,copy:()=>mTt,create:()=>yAg,cross:()=>ByA,dist:()=>GuI,distance:()=>huI,div:()=>uuI,divide:()=>cuI,dot:()=>oyA,equals:()=>zTt,exactEquals:()=>jTt,floor:()=>STt,forEach:()=>kuI,fromValues:()=>wAg,hermite:()=>LTt,inverse:()=>JTt,len:()=>uAg,length:()=>suI,lerp:()=>PTt,max:()=>RTt,min:()=>fTt,mul:()=>wuI,multiply:()=>ruI,negate:()=>UTt,normalize:()=>duI,random:()=>_Tt,rotateX:()=>qTt,rotateY:()=>TTt,rotateZ:()=>ZTt,round:()=>NTt,scale:()=>xTt,scaleAndAdd:()=>FTt,set:()=>pTt,slerp:()=>KTt,sqrDist:()=>muI,sqrLen:()=>puI,squaredDistance:()=>luI,squaredLength:()=>DuI,str:()=>VTt,sub:()=>yuI,subtract:()=>auI,transformMat3:()=>HTt,transformMat4:()=>bTt,transformQuat:()=>vTt,zero:()=>WTt});function yAg(){var g=new Ni(3);return Ni!=Float32Array&&(g[0]=0,g[1]=0,g[2]=0),g}function GTt(g){var A=new Ni(3);return A[0]=g[0],A[1]=g[1],A[2]=g[2],A}function suI(g){var A=g[0],I=g[1],e=g[2];return Math.sqrt(A*A+I*I+e*e)}function wAg(g,A,I){var e=new Ni(3);return e[0]=g,e[1]=A,e[2]=I,e}function mTt(g,A){return g[0]=A[0],g[1]=A[1],g[2]=A[2],g}function pTt(g,A,I,e){return g[0]=A,g[1]=I,g[2]=e,g}function kTt(g,A,I){return g[0]=A[0]+I[0],g[1]=A[1]+I[1],g[2]=A[2]+I[2],g}function auI(g,A,I){return g[0]=A[0]-I[0],g[1]=A[1]-I[1],g[2]=A[2]-I[2],g}function ruI(g,A,I){return g[0]=A[0]*I[0],g[1]=A[1]*I[1],g[2]=A[2]*I[2],g}function cuI(g,A,I){return g[0]=A[0]/I[0],g[1]=A[1]/I[1],g[2]=A[2]/I[2],g}function MTt(g,A){return g[0]=Math.ceil(A[0]),g[1]=Math.ceil(A[1]),g[2]=Math.ceil(A[2]),g}function STt(g,A){return g[0]=Math.floor(A[0]),g[1]=Math.floor(A[1]),g[2]=Math.floor(A[2]),g}function fTt(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 RTt(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 NTt(g,A){return g[0]=Dx(A[0]),g[1]=Dx(A[1]),g[2]=Dx(A[2]),g}function xTt(g,A,I){return g[0]=A[0]*I,g[1]=A[1]*I,g[2]=A[2]*I,g}function FTt(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 huI(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 luI(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 DuI(g){var A=g[0],I=g[1],e=g[2];return A*A+I*I+e*e}function UTt(g,A){return g[0]=-A[0],g[1]=-A[1],g[2]=-A[2],g}function JTt(g,A){return g[0]=1/A[0],g[1]=1/A[1],g[2]=1/A[2],g}function duI(g,A){var I=A[0],e=A[1],t=A[2],o=I*I+e*e+t*t;return o>0&&(o=1/Math.sqrt(o)),g[0]=A[0]*o,g[1]=A[1]*o,g[2]=A[2]*o,g}function oyA(g,A){return g[0]*A[0]+g[1]*A[1]+g[2]*A[2]}function ByA(g,A,I){var e=A[0],t=A[1],o=A[2],B=I[0],C=I[1],Q=I[2];return g[0]=t*Q-o*C,g[1]=o*B-e*Q,g[2]=e*C-t*B,g}function PTt(g,A,I,e){var t=A[0],o=A[1],B=A[2];return g[0]=t+e*(I[0]-t),g[1]=o+e*(I[1]-o),g[2]=B+e*(I[2]-B),g}function KTt(g,A,I,e){var t=Math.acos(Math.min(Math.max(oyA(A,I),-1),1)),o=Math.sin(t),B=Math.sin((1-e)*t)/o,C=Math.sin(e*t)/o;return g[0]=B*A[0]+C*I[0],g[1]=B*A[1]+C*I[1],g[2]=B*A[2]+C*I[2],g}function LTt(g,A,I,e,t,o){var B=o*o,C=B*(2*o-3)+1,Q=B*(o-2)+o,i=B*(o-1),E=B*(3-2*o);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 YTt(g,A,I,e,t,o){var B=1-o,C=B*B,Q=o*o,i=C*B,E=3*o*C,n=3*Q*B,s=Q*o;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 _Tt(g,A){A=A===void 0?1:A;var I=Z2()*2*Math.PI,e=Z2()*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 bTt(g,A,I){var e=A[0],t=A[1],o=A[2],B=I[3]*e+I[7]*t+I[11]*o+I[15];return B=B||1,g[0]=(I[0]*e+I[4]*t+I[8]*o+I[12])/B,g[1]=(I[1]*e+I[5]*t+I[9]*o+I[13])/B,g[2]=(I[2]*e+I[6]*t+I[10]*o+I[14])/B,g}function HTt(g,A,I){var e=A[0],t=A[1],o=A[2];return g[0]=e*I[0]+t*I[3]+o*I[6],g[1]=e*I[1]+t*I[4]+o*I[7],g[2]=e*I[2]+t*I[5]+o*I[8],g}function vTt(g,A,I){var e=I[0],t=I[1],o=I[2],B=I[3],C=A[0],Q=A[1],i=A[2],E=t*i-o*Q,n=o*C-e*i,s=e*Q-t*C;return E=E+E,n=n+n,s=s+s,g[0]=C+B*E+t*s-o*n,g[1]=Q+B*n+o*E-e*s,g[2]=i+B*s+e*n-t*E,g}function qTt(g,A,I,e){var t=[],o=[];return t[0]=A[0]-I[0],t[1]=A[1]-I[1],t[2]=A[2]-I[2],o[0]=t[0],o[1]=t[1]*Math.cos(e)-t[2]*Math.sin(e),o[2]=t[1]*Math.sin(e)+t[2]*Math.cos(e),g[0]=o[0]+I[0],g[1]=o[1]+I[1],g[2]=o[2]+I[2],g}function TTt(g,A,I,e){var t=[],o=[];return t[0]=A[0]-I[0],t[1]=A[1]-I[1],t[2]=A[2]-I[2],o[0]=t[2]*Math.sin(e)+t[0]*Math.cos(e),o[1]=t[1],o[2]=t[2]*Math.cos(e)-t[0]*Math.sin(e),g[0]=o[0]+I[0],g[1]=o[1]+I[1],g[2]=o[2]+I[2],g}function ZTt(g,A,I,e){var t=[],o=[];return t[0]=A[0]-I[0],t[1]=A[1]-I[1],t[2]=A[2]-I[2],o[0]=t[0]*Math.cos(e)-t[1]*Math.sin(e),o[1]=t[0]*Math.sin(e)+t[1]*Math.cos(e),o[2]=t[2],g[0]=o[0]+I[0],g[1]=o[1]+I[1],g[2]=o[2]+I[2],g}function OTt(g,A){var I=g[0],e=g[1],t=g[2],o=A[0],B=A[1],C=A[2],Q=Math.sqrt((I*I+e*e+t*t)*(o*o+B*B+C*C)),i=Q&&oyA(g,A)/Q;return Math.acos(Math.min(Math.max(i,-1),1))}function WTt(g){return g[0]=0,g[1]=0,g[2]=0,g}function VTt(g){return"vec3("+g[0]+", "+g[1]+", "+g[2]+")"}function jTt(g,A){return g[0]===A[0]&&g[1]===A[1]&&g[2]===A[2]}function zTt(g,A){var I=g[0],e=g[1],t=g[2],o=A[0],B=A[1],C=A[2];return Math.abs(I-o)<=rB*Math.max(1,Math.abs(I),Math.abs(o))&&Math.abs(e-B)<=rB*Math.max(1,Math.abs(e),Math.abs(B))&&Math.abs(t-C)<=rB*Math.max(1,Math.abs(t),Math.abs(C))}var yuI,wuI,uuI,GuI,muI,uAg,puI,kuI,MuI=NR({"node_modules/gl-matrix/esm/vec3.js"(){dx(),yuI=auI,wuI=ruI,uuI=cuI,GuI=huI,muI=luI,uAg=suI,puI=DuI,kuI=(function(){var g=yAg();return function(A,I,e,t,o,B){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],o(g,g,B),A[C]=g[0],A[C+1]=g[1],A[C+2]=g[2];return A}})()}}),SuI={};xR(SuI,{add:()=>UuI,ceil:()=>XTt,clone:()=>RuI,copy:()=>xuI,create:()=>fuI,cross:()=>B7t,dist:()=>OuI,distance:()=>YuI,div:()=>ZuI,divide:()=>KuI,dot:()=>pAg,equals:()=>s7t,exactEquals:()=>vuI,floor:()=>$Tt,forEach:()=>zuI,fromValues:()=>NuI,inverse:()=>o7t,len:()=>VuI,length:()=>GAg,lerp:()=>HuI,max:()=>g7t,min:()=>A7t,mul:()=>TuI,multiply:()=>PuI,negate:()=>t7t,normalize:()=>buI,random:()=>C7t,round:()=>I7t,scale:()=>LuI,scaleAndAdd:()=>e7t,set:()=>FuI,sqrDist:()=>WuI,sqrLen:()=>juI,squaredDistance:()=>_uI,squaredLength:()=>mAg,str:()=>n7t,sub:()=>quI,subtract:()=>JuI,transformMat4:()=>Q7t,transformQuat:()=>i7t,zero:()=>E7t});function fuI(){var g=new Ni(4);return Ni!=Float32Array&&(g[0]=0,g[1]=0,g[2]=0,g[3]=0),g}function RuI(g){var A=new Ni(4);return A[0]=g[0],A[1]=g[1],A[2]=g[2],A[3]=g[3],A}function NuI(g,A,I,e){var t=new Ni(4);return t[0]=g,t[1]=A,t[2]=I,t[3]=e,t}function xuI(g,A){return g[0]=A[0],g[1]=A[1],g[2]=A[2],g[3]=A[3],g}function FuI(g,A,I,e,t){return g[0]=A,g[1]=I,g[2]=e,g[3]=t,g}function UuI(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 JuI(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 PuI(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 KuI(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 XTt(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 $Tt(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 A7t(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 g7t(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 I7t(g,A){return g[0]=Dx(A[0]),g[1]=Dx(A[1]),g[2]=Dx(A[2]),g[3]=Dx(A[3]),g}function LuI(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 e7t(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 YuI(g,A){var I=A[0]-g[0],e=A[1]-g[1],t=A[2]-g[2],o=A[3]-g[3];return Math.sqrt(I*I+e*e+t*t+o*o)}function _uI(g,A){var I=A[0]-g[0],e=A[1]-g[1],t=A[2]-g[2],o=A[3]-g[3];return I*I+e*e+t*t+o*o}function GAg(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 mAg(g){var A=g[0],I=g[1],e=g[2],t=g[3];return A*A+I*I+e*e+t*t}function t7t(g,A){return g[0]=-A[0],g[1]=-A[1],g[2]=-A[2],g[3]=-A[3],g}function o7t(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 buI(g,A){var I=A[0],e=A[1],t=A[2],o=A[3],B=I*I+e*e+t*t+o*o;return B>0&&(B=1/Math.sqrt(B)),g[0]=I*B,g[1]=e*B,g[2]=t*B,g[3]=o*B,g}function pAg(g,A){return g[0]*A[0]+g[1]*A[1]+g[2]*A[2]+g[3]*A[3]}function B7t(g,A,I,e){var t=I[0]*e[1]-I[1]*e[0],o=I[0]*e[2]-I[2]*e[0],B=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*B-r*o,g[2]=E*Q-n*B+r*t,g[3]=-(E*C)+n*o-s*t,g}function HuI(g,A,I,e){var t=A[0],o=A[1],B=A[2],C=A[3];return g[0]=t+e*(I[0]-t),g[1]=o+e*(I[1]-o),g[2]=B+e*(I[2]-B),g[3]=C+e*(I[3]-C),g}function C7t(g,A){A=A===void 0?1:A;var I,e,t,o,B,C,Q;Q=Z2(),I=Q*2-1,e=(4*Z2()-2)*Math.sqrt(Q*-Q+Q),B=I*I+e*e,Q=Z2(),t=Q*2-1,o=(4*Z2()-2)*Math.sqrt(Q*-Q+Q),C=t*t+o*o;var i=Math.sqrt((1-B)/C);return g[0]=A*I,g[1]=A*e,g[2]=A*t*i,g[3]=A*o*i,g}function Q7t(g,A,I){var e=A[0],t=A[1],o=A[2],B=A[3];return g[0]=I[0]*e+I[4]*t+I[8]*o+I[12]*B,g[1]=I[1]*e+I[5]*t+I[9]*o+I[13]*B,g[2]=I[2]*e+I[6]*t+I[10]*o+I[14]*B,g[3]=I[3]*e+I[7]*t+I[11]*o+I[15]*B,g}function i7t(g,A,I){var e=I[0],t=I[1],o=I[2],B=I[3],C=A[0],Q=A[1],i=A[2],E=t*i-o*Q,n=o*C-e*i,s=e*Q-t*C;return E=E+E,n=n+n,s=s+s,g[0]=C+B*E+t*s-o*n,g[1]=Q+B*n+o*E-e*s,g[2]=i+B*s+e*n-t*E,g[3]=A[3],g}function E7t(g){return g[0]=0,g[1]=0,g[2]=0,g[3]=0,g}function n7t(g){return"vec4("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")"}function vuI(g,A){return g[0]===A[0]&&g[1]===A[1]&&g[2]===A[2]&&g[3]===A[3]}function s7t(g,A){var I=g[0],e=g[1],t=g[2],o=g[3],B=A[0],C=A[1],Q=A[2],i=A[3];return Math.abs(I-B)<=rB*Math.max(1,Math.abs(I),Math.abs(B))&&Math.abs(e-C)<=rB*Math.max(1,Math.abs(e),Math.abs(C))&&Math.abs(t-Q)<=rB*Math.max(1,Math.abs(t),Math.abs(Q))&&Math.abs(o-i)<=rB*Math.max(1,Math.abs(o),Math.abs(i))}var quI,TuI,ZuI,OuI,WuI,VuI,juI,zuI,XuI=NR({"node_modules/gl-matrix/esm/vec4.js"(){dx(),quI=JuI,TuI=PuI,ZuI=KuI,OuI=YuI,WuI=_uI,VuI=GAg,juI=mAg,zuI=(function(){var g=fuI();return function(A,I,e,t,o,B){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],o(g,g,B),A[C]=g[0],A[C+1]=g[1],A[C+2]=g[2],A[C+3]=g[3];return A}})()}}),$uI={};xR($uI,{add:()=>nGI,calculateW:()=>h7t,clone:()=>QGI,conjugate:()=>y7t,copy:()=>iyA,create:()=>CyA,dot:()=>EyA,equals:()=>G7t,exactEquals:()=>hGI,exp:()=>oGI,fromEuler:()=>w7t,fromMat3:()=>CGI,fromValues:()=>iGI,getAngle:()=>c7t,getAxisAngle:()=>r7t,identity:()=>a7t,invert:()=>d7t,len:()=>rGI,length:()=>nyA,lerp:()=>aGI,ln:()=>BGI,mul:()=>sGI,multiply:()=>gGI,normalize:()=>ayA,pow:()=>l7t,random:()=>D7t,rotateX:()=>IGI,rotateY:()=>eGI,rotateZ:()=>tGI,rotationTo:()=>lGI,scale:()=>kAg,set:()=>EGI,setAxes:()=>dGI,setAxisAngle:()=>AGI,slerp:()=>QyA,sqlerp:()=>DGI,sqrLen:()=>cGI,squaredLength:()=>syA,str:()=>u7t});function CyA(){var g=new Ni(4);return Ni!=Float32Array&&(g[0]=0,g[1]=0,g[2]=0),g[3]=1,g}function a7t(g){return g[0]=0,g[1]=0,g[2]=0,g[3]=1,g}function AGI(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 r7t(g,A){var I=Math.acos(A[3])*2,e=Math.sin(I/2);return e>rB?(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 c7t(g,A){var I=EyA(g,A);return Math.acos(2*I*I-1)}function gGI(g,A,I){var e=A[0],t=A[1],o=A[2],B=A[3],C=I[0],Q=I[1],i=I[2],E=I[3];return g[0]=e*E+B*C+t*i-o*Q,g[1]=t*E+B*Q+o*C-e*i,g[2]=o*E+B*i+e*Q-t*C,g[3]=B*E-e*C-t*Q-o*i,g}function IGI(g,A,I){I*=.5;var e=A[0],t=A[1],o=A[2],B=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]=o*Q-t*C,g[3]=B*Q-e*C,g}function eGI(g,A,I){I*=.5;var e=A[0],t=A[1],o=A[2],B=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]=o*Q+e*C,g[3]=B*Q-t*C,g}function tGI(g,A,I){I*=.5;var e=A[0],t=A[1],o=A[2],B=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]=o*Q+B*C,g[3]=B*Q-o*C,g}function h7t(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 oGI(g,A){var I=A[0],e=A[1],t=A[2],o=A[3],B=Math.sqrt(I*I+e*e+t*t),C=Math.exp(o),Q=B>0?C*Math.sin(B)/B:0;return g[0]=I*Q,g[1]=e*Q,g[2]=t*Q,g[3]=C*Math.cos(B),g}function BGI(g,A){var I=A[0],e=A[1],t=A[2],o=A[3],B=Math.sqrt(I*I+e*e+t*t),C=B>0?Math.atan2(B,o)/B: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+o*o),g}function l7t(g,A,I){return BGI(g,A),kAg(g,g,I),oGI(g,g),g}function QyA(g,A,I,e){var t=A[0],o=A[1],B=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+o*i+B*E+C*n,r<0&&(r=-r,Q=-Q,i=-i,E=-E,n=-n),1-r>rB?(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*o+h*i,g[2]=c*B+h*E,g[3]=c*C+h*n,g}function D7t(g){var A=Z2(),I=Z2(),e=Z2(),t=Math.sqrt(1-A),o=Math.sqrt(A);return g[0]=t*Math.sin(2*Math.PI*I),g[1]=t*Math.cos(2*Math.PI*I),g[2]=o*Math.sin(2*Math.PI*e),g[3]=o*Math.cos(2*Math.PI*e),g}function d7t(g,A){var I=A[0],e=A[1],t=A[2],o=A[3],B=I*I+e*e+t*t+o*o,C=B?1/B:0;return g[0]=-I*C,g[1]=-e*C,g[2]=-t*C,g[3]=o*C,g}function y7t(g,A){return g[0]=-A[0],g[1]=-A[1],g[2]=-A[2],g[3]=A[3],g}function CGI(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 o=(t+1)%3,B=(t+2)%3;e=Math.sqrt(A[t*3+t]-A[o*3+o]-A[B*3+B]+1),g[t]=.5*e,e=.5/e,g[3]=(A[o*3+B]-A[B*3+o])*e,g[o]=(A[o*3+t]+A[t*3+o])*e,g[B]=(A[B*3+t]+A[t*3+B])*e}return g}function w7t(g,A,I,e){var t=arguments.length>4&&arguments[4]!==void 0?arguments[4]:dAg,o=Math.PI/360;A*=o,e*=o,I*=o;var B=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]=B*i*n+C*Q*E,g[1]=C*Q*n-B*i*E,g[2]=C*i*E+B*Q*n,g[3]=C*i*n-B*Q*E;break;case"xzy":g[0]=B*i*n-C*Q*E,g[1]=C*Q*n-B*i*E,g[2]=C*i*E+B*Q*n,g[3]=C*i*n+B*Q*E;break;case"yxz":g[0]=B*i*n+C*Q*E,g[1]=C*Q*n-B*i*E,g[2]=C*i*E-B*Q*n,g[3]=C*i*n+B*Q*E;break;case"yzx":g[0]=B*i*n+C*Q*E,g[1]=C*Q*n+B*i*E,g[2]=C*i*E-B*Q*n,g[3]=C*i*n-B*Q*E;break;case"zxy":g[0]=B*i*n-C*Q*E,g[1]=C*Q*n+B*i*E,g[2]=C*i*E+B*Q*n,g[3]=C*i*n-B*Q*E;break;case"zyx":g[0]=B*i*n-C*Q*E,g[1]=C*Q*n+B*i*E,g[2]=C*i*E-B*Q*n,g[3]=C*i*n+B*Q*E;break;default:throw new Error("Unknown angle order "+t)}return g}function u7t(g){return"quat("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")"}function G7t(g,A){return Math.abs(pAg(g,A))>=1-rB}var QGI,iGI,iyA,EGI,nGI,sGI,kAg,EyA,aGI,nyA,rGI,syA,cGI,ayA,hGI,lGI,DGI,dGI,yGI=NR({"node_modules/gl-matrix/esm/quat.js"(){dx(),VwI(),MuI(),XuI(),QGI=RuI,iGI=NuI,iyA=xuI,EGI=FuI,nGI=UuI,sGI=gGI,kAg=LuI,EyA=pAg,aGI=HuI,nyA=GAg,rGI=nyA,syA=mAg,cGI=syA,ayA=buI,hGI=vuI,lGI=(function(){var g=yAg(),A=wAg(1,0,0),I=wAg(0,1,0);return function(e,t,o){var B=oyA(t,o);return B<-.999999?(ByA(g,A,t),uAg(g)<1e-6&&ByA(g,I,t),duI(g,g),AGI(e,g,Math.PI),e):B>.999999?(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e):(ByA(g,t,o),e[0]=g[0],e[1]=g[1],e[2]=g[2],e[3]=1+B,ayA(e,e))}})(),DGI=(function(){var g=CyA(),A=CyA();return function(I,e,t,o,B,C){return QyA(g,e,B,C),QyA(A,t,o,C),QyA(I,g,A,2*C*(1-C)),I}})(),dGI=(function(){var g=qwI();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],ayA(A,CGI(A,g))}})()}}),wGI={};xR(wGI,{add:()=>v7t,clone:()=>p7t,conjugate:()=>O7t,copy:()=>GGI,create:()=>m7t,dot:()=>MAg,equals:()=>z7t,exactEquals:()=>j7t,fromMat4:()=>R7t,fromRotation:()=>f7t,fromRotationTranslation:()=>uGI,fromRotationTranslationValues:()=>M7t,fromTranslation:()=>S7t,fromValues:()=>k7t,getDual:()=>F7t,getReal:()=>pGI,getTranslation:()=>J7t,identity:()=>N7t,invert:()=>Z7t,len:()=>SGI,length:()=>SAg,lerp:()=>T7t,mul:()=>MGI,multiply:()=>mGI,normalize:()=>W7t,rotateAroundAxis:()=>H7t,rotateByQuatAppend:()=>_7t,rotateByQuatPrepend:()=>b7t,rotateX:()=>K7t,rotateY:()=>L7t,rotateZ:()=>Y7t,scale:()=>q7t,set:()=>x7t,setDual:()=>U7t,setReal:()=>kGI,sqrLen:()=>fGI,squaredLength:()=>lIA,str:()=>V7t,translate:()=>P7t});function m7t(){var g=new Ni(8);return Ni!=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 p7t(g){var A=new Ni(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 k7t(g,A,I,e,t,o,B,C){var Q=new Ni(8);return Q[0]=g,Q[1]=A,Q[2]=I,Q[3]=e,Q[4]=t,Q[5]=o,Q[6]=B,Q[7]=C,Q}function M7t(g,A,I,e,t,o,B){var C=new Ni(8);C[0]=g,C[1]=A,C[2]=I,C[3]=e;var Q=t*.5,i=o*.5,E=B*.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 uGI(g,A,I){var e=I[0]*.5,t=I[1]*.5,o=I[2]*.5,B=A[0],C=A[1],Q=A[2],i=A[3];return g[0]=B,g[1]=C,g[2]=Q,g[3]=i,g[4]=e*i+t*Q-o*C,g[5]=t*i+o*B-e*Q,g[6]=o*i+e*C-t*B,g[7]=-e*B-t*C-o*Q,g}function S7t(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 f7t(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 R7t(g,A){var I=CyA();IuI(I,A);var e=new Ni(3);return AuI(e,A),uGI(g,I,e),g}function GGI(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 N7t(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 x7t(g,A,I,e,t,o,B,C,Q){return g[0]=A,g[1]=I,g[2]=e,g[3]=t,g[4]=o,g[5]=B,g[6]=C,g[7]=Q,g}function F7t(g,A){return g[0]=A[4],g[1]=A[5],g[2]=A[6],g[3]=A[7],g}function U7t(g,A){return g[4]=A[0],g[5]=A[1],g[6]=A[2],g[7]=A[3],g}function J7t(g,A){var I=A[4],e=A[5],t=A[6],o=A[7],B=-A[0],C=-A[1],Q=-A[2],i=A[3];return g[0]=(I*i+o*B+e*Q-t*C)*2,g[1]=(e*i+o*C+t*B-I*Q)*2,g[2]=(t*i+o*Q+I*C-e*B)*2,g}function P7t(g,A,I){var e=A[0],t=A[1],o=A[2],B=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]=o,g[3]=B,g[4]=B*C+t*i-o*Q+E,g[5]=B*Q+o*C-e*i+n,g[6]=B*i+e*Q-t*C+s,g[7]=-e*C-t*Q-o*i+r,g}function K7t(g,A,I){var e=-A[0],t=-A[1],o=-A[2],B=A[3],C=A[4],Q=A[5],i=A[6],E=A[7],n=C*B+E*e+Q*o-i*t,s=Q*B+E*t+i*e-C*o,r=i*B+E*o+C*t-Q*e,a=E*B-C*e-Q*t-i*o;return IGI(g,A,I),e=g[0],t=g[1],o=g[2],B=g[3],g[4]=n*B+a*e+s*o-r*t,g[5]=s*B+a*t+r*e-n*o,g[6]=r*B+a*o+n*t-s*e,g[7]=a*B-n*e-s*t-r*o,g}function L7t(g,A,I){var e=-A[0],t=-A[1],o=-A[2],B=A[3],C=A[4],Q=A[5],i=A[6],E=A[7],n=C*B+E*e+Q*o-i*t,s=Q*B+E*t+i*e-C*o,r=i*B+E*o+C*t-Q*e,a=E*B-C*e-Q*t-i*o;return eGI(g,A,I),e=g[0],t=g[1],o=g[2],B=g[3],g[4]=n*B+a*e+s*o-r*t,g[5]=s*B+a*t+r*e-n*o,g[6]=r*B+a*o+n*t-s*e,g[7]=a*B-n*e-s*t-r*o,g}function Y7t(g,A,I){var e=-A[0],t=-A[1],o=-A[2],B=A[3],C=A[4],Q=A[5],i=A[6],E=A[7],n=C*B+E*e+Q*o-i*t,s=Q*B+E*t+i*e-C*o,r=i*B+E*o+C*t-Q*e,a=E*B-C*e-Q*t-i*o;return tGI(g,A,I),e=g[0],t=g[1],o=g[2],B=g[3],g[4]=n*B+a*e+s*o-r*t,g[5]=s*B+a*t+r*e-n*o,g[6]=r*B+a*o+n*t-s*e,g[7]=a*B-n*e-s*t-r*o,g}function _7t(g,A,I){var e=I[0],t=I[1],o=I[2],B=I[3],C=A[0],Q=A[1],i=A[2],E=A[3];return g[0]=C*B+E*e+Q*o-i*t,g[1]=Q*B+E*t+i*e-C*o,g[2]=i*B+E*o+C*t-Q*e,g[3]=E*B-C*e-Q*t-i*o,C=A[4],Q=A[5],i=A[6],E=A[7],g[4]=C*B+E*e+Q*o-i*t,g[5]=Q*B+E*t+i*e-C*o,g[6]=i*B+E*o+C*t-Q*e,g[7]=E*B-C*e-Q*t-i*o,g}function b7t(g,A,I){var e=A[0],t=A[1],o=A[2],B=A[3],C=I[0],Q=I[1],i=I[2],E=I[3];return g[0]=e*E+B*C+t*i-o*Q,g[1]=t*E+B*Q+o*C-e*i,g[2]=o*E+B*i+e*Q-t*C,g[3]=B*E-e*C-t*Q-o*i,C=I[4],Q=I[5],i=I[6],E=I[7],g[4]=e*E+B*C+t*i-o*Q,g[5]=t*E+B*Q+o*C-e*i,g[6]=o*E+B*i+e*Q-t*C,g[7]=B*E-e*C-t*Q-o*i,g}function H7t(g,A,I,e){if(Math.abs(e)<rB)return GGI(g,A);var t=Math.sqrt(I[0]*I[0]+I[1]*I[1]+I[2]*I[2]);e=e*.5;var o=Math.sin(e),B=o*I[0]/t,C=o*I[1]/t,Q=o*I[2]/t,i=Math.cos(e),E=A[0],n=A[1],s=A[2],r=A[3];g[0]=E*i+r*B+n*Q-s*C,g[1]=n*i+r*C+s*B-E*Q,g[2]=s*i+r*Q+E*C-n*B,g[3]=r*i-E*B-n*C-s*Q;var a=A[4],c=A[5],h=A[6],l=A[7];return g[4]=a*i+l*B+c*Q-h*C,g[5]=c*i+l*C+h*B-a*Q,g[6]=h*i+l*Q+a*C-c*B,g[7]=l*i-a*B-c*C-h*Q,g}function v7t(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 mGI(g,A,I){var e=A[0],t=A[1],o=A[2],B=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+B*c+t*l-o*h,g[1]=t*D+B*h+o*c-e*l,g[2]=o*D+B*l+e*h-t*c,g[3]=B*D-e*c-t*h-o*l,g[4]=e*E+B*C+t*i-o*Q+n*D+a*c+s*l-r*h,g[5]=t*E+B*Q+o*C-e*i+s*D+a*h+r*c-n*l,g[6]=o*E+B*i+e*Q-t*C+r*D+a*l+n*h-s*c,g[7]=B*E-e*C-t*Q-o*i+a*D-n*c-s*h-r*l,g}function q7t(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 T7t(g,A,I,e){var t=1-e;return MAg(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 Z7t(g,A){var I=lIA(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 O7t(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 W7t(g,A){var I=lIA(A);if(I>0){I=Math.sqrt(I);var e=A[0]/I,t=A[1]/I,o=A[2]/I,B=A[3]/I,C=A[4],Q=A[5],i=A[6],E=A[7],n=e*C+t*Q+o*i+B*E;g[0]=e,g[1]=t,g[2]=o,g[3]=B,g[4]=(C-e*n)/I,g[5]=(Q-t*n)/I,g[6]=(i-o*n)/I,g[7]=(E-B*n)/I}return g}function V7t(g){return"quat2("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+", "+g[4]+", "+g[5]+", "+g[6]+", "+g[7]+")"}function j7t(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 z7t(g,A){var I=g[0],e=g[1],t=g[2],o=g[3],B=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)<=rB*Math.max(1,Math.abs(I),Math.abs(E))&&Math.abs(e-n)<=rB*Math.max(1,Math.abs(e),Math.abs(n))&&Math.abs(t-s)<=rB*Math.max(1,Math.abs(t),Math.abs(s))&&Math.abs(o-r)<=rB*Math.max(1,Math.abs(o),Math.abs(r))&&Math.abs(B-a)<=rB*Math.max(1,Math.abs(B),Math.abs(a))&&Math.abs(C-c)<=rB*Math.max(1,Math.abs(C),Math.abs(c))&&Math.abs(Q-h)<=rB*Math.max(1,Math.abs(Q),Math.abs(h))&&Math.abs(i-l)<=rB*Math.max(1,Math.abs(i),Math.abs(l))}var pGI,kGI,MGI,MAg,SAg,SGI,lIA,fGI,X7t=NR({"node_modules/gl-matrix/esm/quat2.js"(){dx(),yGI(),EuI(),pGI=iyA,kGI=iyA,MGI=mGI,MAg=EyA,SAg=nyA,SGI=SAg,lIA=syA,fGI=lIA}}),RGI={};xR(RGI,{add:()=>eZt,angle:()=>GZt,ceil:()=>tZt,clone:()=>$7t,copy:()=>gZt,create:()=>NGI,cross:()=>cZt,dist:()=>vGI,distance:()=>JGI,div:()=>HGI,divide:()=>UGI,dot:()=>rZt,equals:()=>SZt,exactEquals:()=>MZt,floor:()=>oZt,forEach:()=>ZGI,fromValues:()=>AZt,inverse:()=>sZt,len:()=>YGI,length:()=>KGI,lerp:()=>hZt,max:()=>CZt,min:()=>BZt,mul:()=>bGI,multiply:()=>FGI,negate:()=>nZt,normalize:()=>aZt,random:()=>lZt,rotate:()=>uZt,round:()=>QZt,scale:()=>iZt,scaleAndAdd:()=>EZt,set:()=>IZt,signedAngle:()=>mZt,sqrDist:()=>qGI,sqrLen:()=>TGI,squaredDistance:()=>PGI,squaredLength:()=>LGI,str:()=>kZt,sub:()=>_GI,subtract:()=>xGI,transformMat2:()=>DZt,transformMat2d:()=>dZt,transformMat3:()=>yZt,transformMat4:()=>wZt,zero:()=>pZt});function NGI(){var g=new Ni(2);return Ni!=Float32Array&&(g[0]=0,g[1]=0),g}function $7t(g){var A=new Ni(2);return A[0]=g[0],A[1]=g[1],A}function AZt(g,A){var I=new Ni(2);return I[0]=g,I[1]=A,I}function gZt(g,A){return g[0]=A[0],g[1]=A[1],g}function IZt(g,A,I){return g[0]=A,g[1]=I,g}function eZt(g,A,I){return g[0]=A[0]+I[0],g[1]=A[1]+I[1],g}function xGI(g,A,I){return g[0]=A[0]-I[0],g[1]=A[1]-I[1],g}function FGI(g,A,I){return g[0]=A[0]*I[0],g[1]=A[1]*I[1],g}function UGI(g,A,I){return g[0]=A[0]/I[0],g[1]=A[1]/I[1],g}function tZt(g,A){return g[0]=Math.ceil(A[0]),g[1]=Math.ceil(A[1]),g}function oZt(g,A){return g[0]=Math.floor(A[0]),g[1]=Math.floor(A[1]),g}function BZt(g,A,I){return g[0]=Math.min(A[0],I[0]),g[1]=Math.min(A[1],I[1]),g}function CZt(g,A,I){return g[0]=Math.max(A[0],I[0]),g[1]=Math.max(A[1],I[1]),g}function QZt(g,A){return g[0]=Dx(A[0]),g[1]=Dx(A[1]),g}function iZt(g,A,I){return g[0]=A[0]*I,g[1]=A[1]*I,g}function EZt(g,A,I,e){return g[0]=A[0]+I[0]*e,g[1]=A[1]+I[1]*e,g}function JGI(g,A){var I=A[0]-g[0],e=A[1]-g[1];return Math.sqrt(I*I+e*e)}function PGI(g,A){var I=A[0]-g[0],e=A[1]-g[1];return I*I+e*e}function KGI(g){var A=g[0],I=g[1];return Math.sqrt(A*A+I*I)}function LGI(g){var A=g[0],I=g[1];return A*A+I*I}function nZt(g,A){return g[0]=-A[0],g[1]=-A[1],g}function sZt(g,A){return g[0]=1/A[0],g[1]=1/A[1],g}function aZt(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 rZt(g,A){return g[0]*A[0]+g[1]*A[1]}function cZt(g,A,I){var e=A[0]*I[1]-A[1]*I[0];return g[0]=g[1]=0,g[2]=e,g}function hZt(g,A,I,e){var t=A[0],o=A[1];return g[0]=t+e*(I[0]-t),g[1]=o+e*(I[1]-o),g}function lZt(g,A){A=A===void 0?1:A;var I=Z2()*2*Math.PI;return g[0]=Math.cos(I)*A,g[1]=Math.sin(I)*A,g}function DZt(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 dZt(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 yZt(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 wZt(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 uZt(g,A,I,e){var t=A[0]-I[0],o=A[1]-I[1],B=Math.sin(e),C=Math.cos(e);return g[0]=t*C-o*B+I[0],g[1]=t*B+o*C+I[1],g}function GZt(g,A){var I=g[0],e=g[1],t=A[0],o=A[1];return Math.abs(Math.atan2(e*t-I*o,I*t+e*o))}function mZt(g,A){var I=g[0],e=g[1],t=A[0],o=A[1];return Math.atan2(I*o-e*t,I*t+e*o)}function pZt(g){return g[0]=0,g[1]=0,g}function kZt(g){return"vec2("+g[0]+", "+g[1]+")"}function MZt(g,A){return g[0]===A[0]&&g[1]===A[1]}function SZt(g,A){var I=g[0],e=g[1],t=A[0],o=A[1];return Math.abs(I-t)<=rB*Math.max(1,Math.abs(I),Math.abs(t))&&Math.abs(e-o)<=rB*Math.max(1,Math.abs(e),Math.abs(o))}var YGI,_GI,bGI,HGI,vGI,qGI,TGI,ZGI,fZt=NR({"node_modules/gl-matrix/esm/vec2.js"(){dx(),YGI=KGI,_GI=xGI,bGI=FGI,HGI=UGI,vGI=JGI,qGI=PGI,TGI=LGI,ZGI=(function(){var g=NGI();return function(A,I,e,t,o,B){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],o(g,g,B),A[C]=g[0],A[C+1]=g[1];return A}})()}}),OGI={};xR(OGI,{glMatrix:()=>RwI,mat2:()=>FwI,mat2d:()=>LwI,mat3:()=>vwI,mat4:()=>jwI,quat:()=>$uI,quat2:()=>wGI,vec2:()=>RGI,vec3:()=>nuI,vec4:()=>SuI});var RZt=NR({"node_modules/gl-matrix/esm/index.js"(){dx(),Hvt(),Eqt(),VwI(),EuI(),yGI(),X7t(),fZt(),MuI(),XuI()}}),WGI=fg({"node_modules/jscad-planner/dist/index.cjs"(g,A){var I=Object.defineProperty,e=Object.getOwnPropertyDescriptor,t=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,B=(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))!o.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={};B(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=(RZt(),N5t(OGI)),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(T=>typeof T=="number"&&Number.isFinite(T))))throw new Error(`Reference polygon "${G}" must be an axis-aligned rectangle`);const U=N,K=[...new Set(U.map(H=>H[0]))],_=[...new Set(U.map(H=>H[1]))];if(K.length!==2||_.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=[(K[0]+K[1])/2,(_[0]+_[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]],x=[p[0],p[1],p[2]];if(![...S,...R,...x].every(Number.isFinite)||!a.vec3.length(R)||!a.vec3.length(x))throw new Error(`Reference rectangle "${G}" has an invalid frame`);return a.vec3.normalize(R,R),a.vec3.normalize(x,x),{name:G,origin:S,normal:R,xAxis:x}}function D(w){const u=[],G=new Set;function m(S,R,x=!1){if(S.reference){if(S.type!=="rectangle"&&S.type!=="polygon")throw new Error("Only rectangles can be reference geometry");if(x)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],x);return N?{...S,shape:N}:void 0}case"colorize":{const N=m(S.shape,R,x);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(K=>m(K,R,x));if(S.type==="subtract"&&S.shapes.length&&!N[0])throw new Error("A subtraction base cannot be reference geometry");const U=N.filter(K=>K!==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)}`)}}}}),NZt=fg({"node_modules/ms/index.js"(g,A){var I=1e3,e=I*60,t=e*60,o=t*24,B=o*7,C=o*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*B;case"days":case"day":case"d":return a*o;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>=o?Math.round(s/o)+"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>=o?n(s,r,o,"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":"")}}}),xZt=fg({"node_modules/debug/src/common.js"(g,A){function I(e){o.debug=o,o.default=o,o.coerce=n,o.disable=i,o.enable=C,o.enabled=E,o.humanize=NZt(),o.destroy=s,Object.keys(e).forEach(r=>{o[r]=e[r]}),o.names=[],o.skips=[],o.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 o.colors[Math.abs(a)%o.colors.length]}o.selectColor=t;function o(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]=o.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=o.formatters[k];if(typeof S=="function"){const R=d[G];p=S.call(y,R),d.splice(G,1),G--}return p}),o.formatArgs.call(y,d),(y.log||o.log).apply(y,d)}return D.namespace=r,D.useColors=o.useColors(),D.color=o.selectColor(r),D.extend=B,D.destroy=o.destroy,Object.defineProperty(D,"enabled",{enumerable:!0,configurable:!1,get:()=>c!==null?c:(h!==o.namespaces&&(h=o.namespaces,l=o.enabled(r)),l),set:d=>{c=d}}),typeof o.init=="function"&&o.init(D),D}function B(r,a){const c=o(this.namespace+(typeof a>"u"?":":a)+r);return c.log=this.log,c}function C(r){o.save(r),o.namespaces=r,o.names=[],o.skips=[];const a=(typeof r=="string"?r:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const c of a)c[0]==="-"?o.skips.push(c.slice(1)):o.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=[...o.names,...o.skips.map(a=>"-"+a)].join(",");return o.enable(""),r}function E(r){for(const a of o.skips)if(Q(r,a))return!1;for(const a of o.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 o.enable(o.load()),o}A.exports=I}}),FZt=fg({"node_modules/debug/src/browser.js"(g,A){g.formatArgs=e,g.save=t,g.load=o,g.useColors=I,g.storage=B(),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 o(){let Q;try{Q=g.storage.getItem("debug")||g.storage.getItem("DEBUG")}catch{}return!Q&&typeof v$A<"u"&&"env"in v$A&&(Q=v$A.env.DEBUG),Q}function B(){try{return localStorage}catch{}}A.exports=xZt()(g);var{formatters:C}=A.exports;C.j=function(Q){try{return JSON.stringify(Q)}catch(i){return"[UnexpectedJSONParseError]: "+i.message}}}}),fAg=X.createContext(null),RD=()=>{const g=X.useContext(fAg);if(!g)throw new Error("useThree must be used within a ThreeProvider");return g},DIA=(g,A=[])=>{const{addFrameListener:I,removeFrameListener:e}=RD();sC.useEffect(()=>(I(g),()=>e(g)),[I,e,...A])},RAg=X.createContext(null),UZt=()=>{const g=X.useContext(RAg),A=RD();return X.useEffect(()=>{if(g)return g.current=A,()=>{g.current=null}},[g,A]),null},JZt=({cadComponent:g,children:A})=>{const I=RD(),e=X.useMemo(()=>new Yc,[]);e.userData.cad_component_id=g.cad_component_id,e.userData.pcb_component_id=g.pcb_component_id,X.useEffect(()=>(I.rootObject.add(e),()=>{I.rootObject.remove(e)}),[I.rootObject,e]);const t=X.useMemo(()=>({...I,rootObject:e}),[I,e]);return q.jsx(fAg.Provider,{value:t,children:A})},VGI=(g,A)=>{if(!g)return;const{camera:I,rootObject:e,renderer:t}=g,o=t.domElement.getBoundingClientRect();if(!o.width||!o.height||A.x<o.left||A.x>o.right||A.y<o.top||A.y>o.bottom)return;const B=new yBI;I.updateWorldMatrix(!0,!1),e.updateWorldMatrix(!0,!0),B.setFromCamera(new ct((A.x-o.left)/o.width*2-1,-((A.y-o.top)/o.height)*2+1),I);for(const C of B.intersectObject(e,!0)){if(!(C.object instanceof Ko))continue;let Q=C.object,i=!0;for(;Q;)Q.visible||(i=!1),Q=Q.parent;if(i)return C.object}},PZt=(g,A,I)=>{let e=VGI(g,A)??null,t;for(;e;)t??=e.userData.pcb_component_id,e=e.parent;if(!t)return;const o=I.find(C=>C.type==="pcb_component"&&C.pcb_component_id===t);if(o?.type!=="pcb_component")return;const B=I.find(C=>C.type==="source_component"&&C.source_component_id===o.source_component_id);if(B?.type==="source_component")return{source_component_id:B.source_component_id,pcb_component_id:o.pcb_component_id,refdes:B.name}};function jGI(g,A){return A??g.some(I=>I.type==="cad_component"&&I.is_on_folded_board===!0)}var KZt=(g,A,I)=>{let e=VGI(g,A)??null;for(;e;){const t=e.userData.cad_component_id;if(t){const o=I.find(C=>C.type==="cad_component"&&C.cad_component_id===t);if(o?.type!=="cad_component")return;const B=I.find(C=>C.type==="source_component"&&C.source_component_id===o.source_component_id);return{cad_component_id:o.cad_component_id,componentName:B?.type==="source_component"?B.name:o.cad_component_id}}e=e.parent}},ryA=new Set,LZt=g=>{const[A,I]=X.useState({circuitKey:g,ids:ryA}),e=A.circuitKey===g?A.ids:ryA;return A.circuitKey!==g&&I({circuitKey:g,ids:ryA}),{hiddenCadComponentIds:e,hideComponent:t=>{I(o=>({circuitKey:g,ids:new Set([...o.circuitKey===g?o.ids:[],t])}))},unhideAllComponents:()=>{I({circuitKey:g,ids:ryA})}}};function dIA(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 zGI=!1;function YZt(){zGI||typeof window>"u"||!window.TSCIRCUIT_JSCDN_BASE_URL||(t2t({defaultFontURL:dIA("three","0.165.0","examples/fonts/ttf/kenpixel.ttf"),unicodeFontsURL:dIA("troika-three-text","0.52.5","unicode-fonts/")}),zGI=!0)}var NAg=g=>X.useMemo(()=>{if(!g)return[];const A=new bit;return A.add(g),A.render(),A.getCircuitJson()},[g]),_Zt=(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))}},xAg=["translucent","opaque","hidden"],bZt=g=>xAg[(xAg.indexOf(g)+1)%xAg.length],XGI={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"},$GI=X.createContext(void 0),HZt=({children:g})=>{const[A,I]=X.useState(XGI),e=X.useCallback((B,C)=>{I(Q=>({...Q,[B]:C}))},[]),t=X.useCallback(()=>{I(XGI)},[]),o=X.useMemo(()=>({visibility:A,setLayerVisibility:e,resetToDefaults:t}),[A,e,t]);return q.jsx($GI.Provider,{value:o,children:g})},l5=()=>{const g=X.useContext($GI);if(!g)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return g},FAg=1.2;function AmI(g){return X.useMemo(()=>{if(!g)return FAg;try{return Xo(g).pcb_board.list()[0]?.thickness??FAg}catch{return FAg}},[g])}var yIA={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:110,appearanceMenu:111},gmI=({children:g,position:A,style:I})=>{const{camera:e,renderer:t}=RD(),o=X.useRef(document.createElement("div")),[B,C]=X.useState(null);return X.useEffect(()=>{const Q=t?.domElement.parentNode;if(Q)return Q.style.position!=="relative"&&Q.style.position!=="absolute"&&(Q.style.position="relative"),Q.appendChild(o.current),C(Ejg.createPortal(g,o.current)),()=>{Q.contains(o.current)&&Q.removeChild(o.current)}},[t,g]),DIA(()=>{if(!e||!o.current||!t)return;const Q=new BI(...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);o.current.style.position="absolute",o.current.style.left=`${E}px`,o.current.style.top=`${n}px`,o.current.style.pointerEvents="none",o.current.style.zIndex=yIA.htmlElements.toString(),I&&Object.assign(o.current.style,I)},[e,t,A,I]),B},vZt=Bs(tyA()),ImI=X.createContext(null),qZt=()=>{const g=X.useContext(ImI);if(!g)throw new Error("useHover must be used within a HoverProvider");return g},TZt=({children:g})=>{const{camera:A,renderer:I}=RD(),[e,t]=X.useState([]),o=X.useMemo(()=>new yBI,[]),B=X.useMemo(()=>new ct,[]),C=X.useRef(e);C.current=e;const Q=X.useRef(null),i=X.useCallback(a=>{t(c=>[...c,a])},[]),E=X.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=X.useCallback(a=>{let c=a;for(;c;){const h=C.current.find(l=>l.object===c);if(h)return h;c=c.parent}},[]),s=X.useCallback(a=>{if(!I.domElement)return;const c=I.domElement.getBoundingClientRect();B.x=(a.clientX-c.left)/c.width*2-1,B.y=-((a.clientY-c.top)/c.height)*2+1,o.setFromCamera(B,A);const h=C.current.map(D=>D.object);if(h.length===0){Q.current&&(Q.current.onUnhover(),Q.current=null);return}const l=o.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,o,B,n]);X.useEffect(()=>{const a=I.domElement;return a.addEventListener("mousemove",s),()=>{a.removeEventListener("mousemove",s)}},[I,s]);const r=X.useMemo(()=>({addHoverable:i,removeHoverable:E}),[i,E]);return q.jsx(ImI.Provider,{value:r,children:g})},ZZt=({children:g,object:A,onHover:I,onUnhover:e,isHovered:t})=>{const{addHoverable:o,removeHoverable:B}=qZt();return X.useEffect(()=>A?(o({object:A,onHover:I,onUnhover:e}),()=>{B(A)}):void 0,[A,I,e,o,B]),q.jsx(q.Fragment,{children:g})},wIA=ZZt,AS=(g,{castShadow:A=!0,receiveShadow:I=!0}={})=>{g.traverse(e=>{e instanceof Ko&&(e.castShadow=A,e.receiveShadow=I)})},OZt=({positionOffset:g,footprint:A,rotationOffset:I,onHover:e,onUnhover:t,isHovered:o,scale:B,isTranslucent:C=!1})=>{const{rootObject:Q}=RD(),i=X.useMemo(()=>{if(!A)return null;const{geometries:E}=_3t(A,vZt),n=new Yc;for(const s of E.flat(1/0)){const r=s.geom;if(!r||!r.polygons&&!r.sides)continue;const a=new oo(s.color);a.convertLinearToSRGB();const c={...r,color:[a.r,a.g,a.b]},h=yDI(c),l=new Hs({vertexColors:!0,side:Sl,transparent:C,opacity:C?.5:1,depthWrite:!C}),D=new Ko(h,l);D.renderOrder=C?2:1,AS(D,{castShadow:!C,receiveShadow:!0}),n.add(D)}return n},[A,C]);return X.useEffect(()=>{if(!(!i||!Q))return Q.add(i),()=>{Q.remove(i)}},[Q,i]),X.useEffect(()=>{i&&(g&&i.position.fromArray(g),I&&i.rotation.fromArray(I),B!==void 0&&i.scale.setScalar(B))},[i,g?.[0],g?.[1],g?.[2],I?.[0],I?.[1],I?.[2],B]),X.useEffect(()=>{i&&i.traverse(E=>{E instanceof Ko&&E.material instanceof Hs&&(o?(E.material.emissive.setHex(255),E.material.emissiveIntensity=.2):E.material.emissiveIntensity=0)})},[o,i]),i?q.jsx(wIA,{isHovered:o,onHover:e,onUnhover:t,object:i}):null},emI=new WeakMap,WZt=()=>{const g=new $r;return g.name="fallback-environment-map",g.mapping=blA,g},VZt=g=>{if(!g)return null;const A=g,I=emI.get(A);if(I)return I;let e;if(g instanceof dDA){const t=new RvA(g);e=t.fromScene(ELt(),.04).texture,t.dispose()}else e=WZt();return emI.set(A,e),e};function jZt(g){const A=new pm;let I=!1;g.updateWorldMatrix(!0,!1);const e=g.parent?g.parent.matrixWorld.clone().invert():new aQ;return g.traverse(t=>{if(t.updateWorldMatrix(!0,!1),t instanceof Ko&&t.geometry&&(t.geometry.boundingBox||t.geometry.computeBoundingBox(),t.geometry.boundingBox)){const o=e.clone().multiply(t.matrixWorld),B=t.geometry.boundingBox.clone();B.applyMatrix4(o),I?A.union(B):(A.copy(B),I=!0)}}),I?A:null}function zZt(g){const A=jZt(g);return A?A.getSize(new BI):new BI}function XZt(g,A,I="contain_within_bounds"){if(!A)return[1,1,1];const e=zZt(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 o=Math.min(...t);return[o,o,o]}var UAg=({model:g,position:A,rotation:I,modelOffset:e=[0,0,0],modelRotation:t=[0,0,0],sourceCoordinateTransform:o,modelSize:B,modelFitMode:C="contain_within_bounds",scale:Q})=>{const{rootObject:i}=RD(),E=X.useMemo(()=>new Yc,[]),n=X.useMemo(()=>new Yc,[]),s=X.useMemo(()=>new Yc,[]),r=X.useMemo(()=>new Yc,[]);return X.useEffect(()=>(E.add(n),()=>{E.remove(n)}),[E,n]),X.useEffect(()=>(n.add(s),()=>{n.remove(s)}),[n,s]),X.useEffect(()=>(s.add(r),()=>{s.remove(r)}),[s,r]),X.useEffect(()=>{for(;r.children.length>0;){const a=r.children[0];if(!a)break;r.remove(a)}g&&r.add(g)},[r,g]),X.useEffect(()=>{if(!o){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(o),r.matrixWorldNeedsUpdate=!0},[r,o]),X.useEffect(()=>{if(i)return i.add(E),()=>{i.remove(E)}},[i,E]),X.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=XZt(s,B,C);n.scale.set(a[0],a[1],a[2])},[E,n,g,C,e,r,s,t,B,A,I,Q]),{boardTransformGroup:E}},tmI=1.25;function omI({gltfUrl:g,position:A,rotation:I,modelOffset:e=[0,0,0],modelRotation:t=[0,0,0],sourceCoordinateTransform:o,modelSize:B,modelFitMode:C="contain_within_bounds",onHover:Q,onUnhover:i,isHovered:E,scale:n,isTranslucent:s=!1}){const{renderer:r}=RD(),[a,c]=X.useState(null),[h,l]=X.useState(null),{boardTransformGroup:D}=UAg({model:a,position:A,rotation:I,modelOffset:e,modelRotation:t,sourceCoordinateTransform:o,modelSize:B,modelFitMode:C,scale:n});if(X.useEffect(()=>{if(!g)return;const d=new sLt;let y=!0;return d.load(g,w=>{if(!y)return;const u=w.scene;u.traverse(G=>{if(G instanceof Ko&&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}}),AS(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]),X.useEffect(()=>{if(!a||!r)return;const d=VZt(r);if(!d)return;const y=[],w=u=>{u instanceof Hs&&(y.push({material:u,envMap:u.envMap??null,envMapIntensity:u.envMapIntensity??1}),u.envMap=d,(typeof u.envMapIntensity!="number"||u.envMapIntensity<tmI)&&(u.envMapIntensity=tmI),u.needsUpdate=!0)};return a.traverse(u=>{if(!(u instanceof Ko))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]),X.useEffect(()=>{a&&a.traverse(d=>{if(!(d instanceof Ko))return;const y=Array.isArray(d.material)?d.material:[d.material];for(const w of y)w instanceof Hs&&(E?(w.emissive.setHex(255),w.emissiveIntensity=.2):w.emissiveIntensity=0)})},[E,a]),h)throw h;return a?q.jsx(wIA,{isHovered:E,onHover:Q,onUnhover:i,object:D}):null}var $Zt=Bs(WGI()),AOt=Bs(tyA()),gOt=({jscadPlan:g,positionOffset:A,rotationOffset:I,modelOffset:e=[0,0,0],modelRotation:t=[0,0,0],sourceCoordinateTransform:o,modelSize:B,modelFitMode:C="contain_within_bounds",onHover:Q,onUnhover:i,isHovered:E,scale:n,isTranslucent:s=!1})=>{const[r,a]=X.useState(null);X.useEffect(()=>{const l=(0,$Zt.executeJscadOperations)(AOt.default,g);if(!l||!l.polygons&&!l.sides){a(null);return}const D=yDI(l),d=new Hs({vertexColors:!0,side:Sl}),y=new Ko(D,d);return a(y),()=>{D.dispose(),d.dispose()}},[g]),X.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,AS(r,{castShadow:!s,receiveShadow:!0})},[r,s]);const c=r?.material,{boardTransformGroup:h}=UAg({model:r,position:A,rotation:I,modelOffset:e,modelRotation:t,sourceCoordinateTransform:o,modelSize:B,modelFitMode:C,scale:n});return X.useEffect(()=>{if(c)if(E){const l=new oo(c.color.getHex());c.emissive.copy(l),c.emissive.setRGB(0,0,1),c.emissiveIntensity=.2}else c.emissiveIntensity=0},[E,c]),r?q.jsx(wIA,{isHovered:E,onHover:Q,onUnhover:i,object:h}):null};function IOt(g){return g.replace(/(DEF|USE)\s+([^\s]+)/g,(A,I,e)=>`${I} ${e.replace(/-/g,"_")}`)}async function eOt(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 zLt().parse(IOt(I),g)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function tOt(g){const[A,I]=X.useState(null);return X.useEffect(()=>{if(!g)return;const e=g.replace(/&cachebust_origin=$/,""),t=window.TSCIRCUIT_OBJ_LOADER_CACHE;let o=!1;async function B(){try{if(e.endsWith(".wrl"))return await eOt(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 BYt;if(E?.length){const s=E.join(`
5323
- `).replace(/^d\s+0\./gm,"d 1."),r=i.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),a=new WLt;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=B().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=>{o||I(Q)}).catch(Q=>{console.error(Q)}),()=>{o=!0}},[g]),A}function oOt({url:g,position:A,rotation:I,modelOffset:e=[0,0,0],modelRotation:t=[0,0,0],sourceCoordinateTransform:o,modelSize:B,modelFitMode:C="contain_within_bounds",onHover:Q,onUnhover:i,isHovered:E,scale:n,isTranslucent:s=!1}){const r=tOt(g),a=X.useMemo(()=>{if(r&&!(r instanceof Error))return r.traverse(l=>{if(l instanceof Ko&&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}}),AS(r,{castShadow:!s,receiveShadow:!0}),r;const h=new Ko(new ik(.5,.5,.5),new Hs({transparent:!0,color:"red",opacity:.25}));return AS(h,{castShadow:!1,receiveShadow:!0}),h},[r,s]),{boardTransformGroup:c}=UAg({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:o,modelSize:B,modelFitMode:C,scale:n});if(r instanceof Error)throw r;return q.jsx(wIA,{isHovered:E,onHover:Q,onUnhover:i,object:c})}var BOt=new oo(.82,.82,.82),BmI=g=>new Hs({color:g?new oo(g[0],g[1],g[2]):BOt});function COt(g,A){const I=BmI(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,o=[I],B=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=B.get(s);if(r!==void 0)return r;const a=o.length;return o.push(BmI(n)),B.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 o}function QOt(g){const A=new Yc;for(const I of g){const e=I.attributes.position?.array??[],t=I.index?.array??[];if(!e.length||!t.length)continue;const o=new Yn;o.setAttribute("position",new ZB(e,3));const B=I.attributes.normal?.array??[];B.length?o.setAttribute("normal",new ZB(B,3)):o.computeVertexNormals(),o.setIndex(t),o.clearGroups();const C=COt(o,I),Q=new Ko(o,C.length>1?C:C[0]);Q.name=I.name,A.add(Q)}return A}var cyA;function iOt(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 EOt(){return cyA||(cyA=(async()=>{const g=await import(dIA("occt-import-js","0.0.23","+esm"));return iOt(g)({locateFile:I=>dIA("occt-import-js","0.0.23",`dist/${I}`)})})().catch(g=>{throw cyA=void 0,g})),cyA}async function nOt(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 EOt()).ReadStepFile(new Uint8Array(I),null);if(!t.success||!t.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=QOt(t.meshes),B=new t$A;return await new Promise((Q,i)=>{B.parse(o,E=>{E instanceof ArrayBuffer?Q(E):i(new Error("GLTFExporter did not return binary output"))},E=>{i(E)},{binary:!0})})}var CmI="step-glb-cache:v2:";function sOt(g){const A=new Uint8Array(g),I=32768;let e="";for(let t=0;t<A.length;t+=I){const o=A.subarray(t,t+I);e+=String.fromCharCode(...o)}return btoa(e)}function aOt(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 rOt(g){try{const A=localStorage.getItem(`${CmI}${g}`);return A?aOt(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function QmI(g,A){try{const I=sOt(A);localStorage.setItem(`${CmI}${g}`,I)}catch(I){console.warn("Failed to write STEP GLB cache",I)}}function cOt(){const g=globalThis;return g.stepUrlToGltfModelConversions||(g.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),g.stepUrlToGltfModelConversions}var hOt=({stepUrl:g,position:A,rotation:I,modelOffset:e,modelRotation:t,sourceCoordinateTransform:o,modelSize:B,modelFitMode:C,scale:Q,onHover:i,onUnhover:E,isHovered:n,isTranslucent:s})=>{const[r,a]=X.useState(null);return X.useEffect(()=>{let c=!0,h=null,l=!0;const D=cOt(),d=rOt(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),QmI(g,y.arrayBuffer),()=>{c=!1,h&&l&&URL.revokeObjectURL(h)};let w=D.inProgress.get(g);return w||(w=nOt(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),QmI(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?q.jsx(omI,{gltfUrl:r,position:A,rotation:I,modelOffset:e,modelRotation:t,sourceCoordinateTransform:o,modelSize:B,modelFitMode:C,scale:Q,onHover:i,onUnhover:E,isHovered:n,isTranslucent:s}):null};function hyA(g,A){let{x:I,y:e,z:t}=g;if(A.axisMapping){const o={x:I,y:e,z:t};A.axisMapping.x&&(I=JAg(o,A.axisMapping.x)),A.axisMapping.y&&(e=JAg(o,A.axisMapping.y)),A.axisMapping.z&&(t=JAg(o,A.axisMapping.z))}if(I*=A.flipX??1,e*=A.flipY??1,t*=A.flipZ??1,A.rotation){if(A.rotation.x){const o=A.rotation.x*Math.PI/180,B=Math.cos(o),C=Math.sin(o),Q=e*B-t*C,i=e*C+t*B;e=Q,t=i}if(A.rotation.y){const o=A.rotation.y*Math.PI/180,B=Math.cos(o),C=Math.sin(o),Q=I*B+t*C,i=-I*C+t*B;I=Q,t=i}if(A.rotation.z){const o=A.rotation.z*Math.PI/180,B=Math.cos(o),C=Math.sin(o),Q=I*B-e*C,i=I*C+e*B;I=Q,e=i}}return{x:I,y:e,z:t}}function JAg(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 PAg={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 lOt(g,A){if(A.coordinateTransform)return A.coordinateTransform;if(!A.usingGlbCoordinates){if(A.hasFootprinterModel)return PAg.FOOTPRINTER_MODEL_TRANSFORM;if(!A.usingObjFormat)return A.usingStepFormat?PAg.STEP_INVERTED:PAg.Z_UP_TO_Y_UP_USB_FIX}}function uIA(g,A){return lOt(g,{usingGlbCoordinates:A==="gltf"||A==="glb"||A==="jscad",usingObjFormat:A==="obj"||A==="wrl",usingStepFormat:A==="step",hasFootprinterModel:A==="footprinter"})}function lyA(g){if(!g)return;const A=hyA({x:1,y:0,z:0},g),I=hyA({x:0,y:1,z:0},g),e=hyA({x:0,y:0,z:1},g);return new aQ().makeBasis(new BI(A.x,A.y,A.z),new BI(I.x,I.y,I.z),new BI(e.x,e.y,e.z))}function l3(g){return g*Math.PI/180}function DOt(g){if(g==="z+")return[0,0,0];switch(g){case"x+":return[0,l3(-90),0];case"x-":return[0,l3(90),0];case"y+":return[l3(90),0,0];case"y-":return[l3(-90),0,0];case"z-":return[l3(180),0,0];default:return[0,0,0]}}function dOt(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 yOt(g,A){return g.rotation?[l3(g.rotation.x),l3(g.rotation.y),l3(g.rotation.z)]:A==="bottom"?[Math.PI,0,0]:[0,0,0]}function wOt(g,A){const I=new BI(g.x,g.y,g.z),e=new km(A[0],A[1],A[2],"XYZ");return I.applyEuler(e),[I.x,I.y,I.z]}function uOt(g,A,I){if(!g.model_origin_position)return[0,0,0];const e=A?hyA(g.model_origin_position,A):g.model_origin_position;return wOt(e,I)}function GOt(g,A){const I=dOt(g,A.layer,A.pcbThickness),e=yOt(g,A.layer),t=uIA(g,A.modelType),o=DOt(g.model_board_normal_direction??"z+"),B=uOt(g,t,o);return{position:I,rotation:e,modelPosition:[-B[0],-B[1],-B[2]],modelRotation:o,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 mOt=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",pOt=g=>g==="step"?"glb":g,kOt=(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)},MOt=(g,A)=>{if(g)return A?A(g):g},SOt=(...g)=>g,KAg=class extends sC.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}},fOt=({error:g,onError:A})=>(X.useEffect(()=>{A(g)},[g,A]),null),imI=({cad_component:g,circuitJson:A,resolveStaticAsset:I})=>{const e=AmI(A),[t,o]=X.useState(!1),{visibility:B}=l5(),[C,Q]=X.useState(null),i=X.useCallback(H=>{H?.mousePosition?(o(!0),Q(H.mousePosition)):(o(!1),Q(null))},[]),E=X.useCallback(()=>{o(!1),Q(null)},[]),n=X.useMemo(()=>Xo(A).source_component.getUsing({source_component_id:g.source_component_id})?.name,[A,g.source_component_id]),{pcbComponent:s,layer:r,isThroughHole:a}=X.useMemo(()=>_Zt(g,A),[g,A]),c=X.useCallback(H=>MOt(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]=X.useState(0),[w,u]=X.useState(null);X.useEffect(()=>{y(0),u(null)},[g.cad_component_id,h,l,D]);const G=X.useMemo(()=>kOt(g,A),[g,A]),m=G?B.enclosure==="translucent":!!g.show_as_translucent_model,p=mOt(g),k=pOt(p),S=g.model_glb_url?"glb":"gltf",R=g.model_wrl_url?"wrl":g.model_stl_url?"stl":"obj",x=X.useMemo(()=>GOt(g,{layer:r,pcbThickness:e,modelType:k}),[g,r,e,k]),N=SOt(...x.rotation),U=x.position,K=X.useMemo(()=>{const H=[];return l&&H.push(q.jsx(omI,{gltfUrl:l,position:U,rotation:N,modelOffset:x.modelPosition,modelRotation:x.modelRotation,sourceCoordinateTransform:lyA(uIA(g,S)),scale:x.scale,modelSize:x.size,modelFitMode:x.fitMode,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m},`${g.cad_component_id}-gltf-${l}`)),h&&H.push(q.jsx(oOt,{url:h,position:U,rotation:N,modelOffset:x.modelPosition,modelRotation:x.modelRotation,sourceCoordinateTransform:lyA(uIA(g,R)),scale:x.scale,modelSize:x.size,modelFitMode:x.fitMode,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m},`${g.cad_component_id}-mixed-${h}`)),D&&!g.model_jscad&&!g.footprinter_string&&H.push(q.jsx(hOt,{stepUrl:D,position:U,rotation:N,modelOffset:x.modelPosition,modelRotation:x.modelRotation,sourceCoordinateTransform:lyA(uIA(g,k)),scale:x.scale,modelSize:x.size,modelFitMode:x.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,x.modelPosition,x.modelRotation,x.scale,x.fitMode,x.size,k,N,D,h]);let _=null;if(K.length>0){if(d>=K.length){if(w)throw w;return null}_=q.jsx(KAg,{fallback:({error:H})=>q.jsx(fOt,{error:H,onError:T=>{u(T),y(j=>Math.max(j,d+1))}}),children:K[d]},`${g.cad_component_id}-fallback-${d}`)}else g.model_jscad?_=q.jsx(gOt,{jscadPlan:g.model_jscad,positionOffset:U,rotationOffset:N,modelOffset:x.modelPosition,modelRotation:x.modelRotation,sourceCoordinateTransform:lyA(uIA(g,"jscad")),scale:x.scale,modelSize:x.size,modelFitMode:x.fitMode,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m},g.cad_component_id):g.footprinter_string&&(_=q.jsx(OZt,{positionOffset:U,rotationOffset:N,footprint:g.footprinter_string,scale:x.scale,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m}));if(G){if(B.enclosure==="hidden")return null}else if(g.show_as_translucent_model){if(!B.translucentModels)return null}else if(s&&(a&&!B.throughHoleModels||!a&&!B.smtModels))return null;return q.jsxs(q.Fragment,{children:[q.jsx(JZt,{cadComponent:g,children:_}),t&&C?q.jsx(gmI,{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]})},EmI={version:"0.0.625"},nmI="cadViewerLightingEnabled",ROt=()=>typeof window>"u"?!0:window.localStorage.getItem(nmI)!=="false",smI=X.createContext(void 0),NOt=({children:g})=>{const[A,I]=X.useState(!1),[e,t]=X.useState(!1),[o,B]=X.useState(ROt);X.useEffect(()=>{window.localStorage.setItem(nmI,o?"true":"false")},[o]);const C=X.useMemo(()=>({darkBackgroundEnabled:A,setDarkBackgroundEnabled:I,gridEnabled:e,setGridEnabled:t,lightingEnabled:o,setLightingEnabled:B}),[A,e,o]);return q.jsx(smI.Provider,{value:C,children:g})},LAg=()=>{const g=X.useContext(smI);if(!g)throw new Error("useAppearance must be used within an AppearanceProvider");return g},amI="cadViewerCameraStateSession";function rmI(g){return g?`${amI}:${g}`:amI}function xOt({camera:g,controls:A,cameraSessionScope:I}){try{const e={position:g.position.toArray(),quaternion:g.quaternion.toArray(),up:g.up.toArray(),fov:g instanceof Q0?g.fov:50,target:A.target.toArray()};sessionStorage.setItem(rmI(I),JSON.stringify(e))}catch(e){console.warn("Failed to save camera:",e)}}function FOt({camera:g,controls:A,cameraSessionScope:I}){try{const e=sessionStorage.getItem(rmI(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 Q0&&(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 cmI(g){return"controls"in g?g:{controls:g}}var hmI=(g,A)=>{const{controls:I,cameraSessionScope:e}=cmI(A);xOt({camera:g,controls:I,cameraSessionScope:e})},YAg=(g,A)=>{const{controls:I,cameraSessionScope:e}=cmI(A);return FOt({camera:g,controls:I,cameraSessionScope:e})},lmI=X.createContext(void 0),UOt=({children:g,defaultTarget:A,initialCameraPosition:I,initialCameraType:e})=>{const t=X.useRef(null),o=X.useRef(null),[B,C]=X.useState(null),[Q,i]=X.useState(e??"perspective"),[E,n]=X.useState(I??null),[s,r]=X.useState(new km(0,0,0)),a=X.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=X.useCallback(D=>{const d=[A.x,A.y,A.z],y=o.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,o,t]),h=X.useCallback(D=>{t.current=D},[]),l=X.useMemo(()=>({controlsRef:t,mainCameraRef:o,defaultTarget:A,baseDistance:a,controller:B,setController:C,getPresetConfig:c,handleControlsChange:h,cameraType:Q,setCameraType:i,cameraPosition:E,setCameraPosition:n,cameraRotation:s,setCameraRotation:r,saveCameraToSession:hmI,loadCameraFromSession:YAg}),[A,a,B,c,h,Q,E,s]);return q.jsx(lmI.Provider,{value:l,children:g})},iJ=()=>{const g=X.useContext(lmI);if(!g)throw new Error("useCameraController must be used within a CameraControllerProvider");return g},JOt=g=>g<.5?4*g*g*g:1-Math.pow(-2*g+2,3)/2,POt=()=>{const{controlsRef:g,mainCameraRef:A,defaultTarget:I,setController:e,getPresetConfig:t}=iJ(),o=X.useRef(null),B=X.useRef(new mm),C=X.useRef(new BI),Q=X.useRef(new BI),i=X.useRef(new mm),E=X.useRef(new mm),n=X.useRef(new bs),s=X.useRef(new bs),r=X.useCallback(({position:c,target:h,up:l,durationMs:D=600})=>{if(!A.current)return;const d=g.current?.target??I,y=new BI(c[0],c[1],c[2]),w=h?new BI(h[0],h[1],h[2]):I.clone(),u=new BI(...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 x=R.quaternion.clone();R.up.set(0,0,1),R.position.copy(y),R.lookAt(w);const N=R.quaternion.clone(),U=x.clone().invert().multiply(p).normalize(),K=N.clone().invert().multiply(m).normalize();o.current={fromPosition:k,toPosition:y,fromTarget:S,toTarget:w,toQuaternion:m,rollFrom:U,rollTo:K,startTime:performance.now(),duration:D}},[A,g,I]),a=X.useCallback(c=>{if(c==="Custom")return;const h=t(c);h&&r(h)},[r,t]);return X.useEffect(()=>A.current?(e({animateTo:r,animateToPreset:a}),()=>{e(null)}):void 0,[r,a,A,e]),DIA(()=>{if(!A.current||!o.current)return;const{fromPosition:c,toPosition:h,fromTarget:l,toTarget:D,toQuaternion:d,rollFrom:y,rollTo:w,startTime:u,duration:G}=o.current,m=performance.now()-u,p=G<=0?1:Math.min(m/G,1),k=JOt(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 x=B.current;x.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(x).multiply(N).normalize();const K=Q.current;K.set(0,1,0).applyQuaternion(A.current.quaternion).normalize(),A.current.up.copy(K),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(),o.current=null)}),null},KOt=Symbol("camera-session-not-restored"),LOt=({cameraSessionScope:g}={})=>{const{controlsRef:A}=iJ(),I=X.useRef(null),e=X.useRef(KOt),t=X.useRef(null);X.useEffect(()=>()=>{t.current!==null&&(clearTimeout(t.current),t.current=null)},[g]);const o=X.useCallback(C=>{if(I.current=C,e.current!==g&&A.current){const Q=YAg(C,{controls:A.current,cameraSessionScope:g});if(e.current=g,Q)return}},[g,A]),B=X.useCallback(()=>{if(!(!I.current||!A.current)){if(e.current!==g){const C=YAg(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&&hmI(I.current,{controls:A.current,cameraSessionScope:g})},150)}},[g,A]);return{handleCameraCreated:o,handleControlsChange:B}};function YOt(g){g.querySelectorAll("canvas").forEach(A=>A.remove())}var _Ot=g=>{g.outputColorSpace=Ck,g.toneMapping=YeI,g.toneMappingExposure=1,g.shadowMap.enabled=!0,g.shadowMap.type=JeI},bOt=X.forwardRef(({children:g,scene:A,camera:I,style:e,onCreated:t},o)=>{const{cameraType:B}=iJ(),C=X.useRef(null),[Q,i]=X.useState(null),E=X.useRef([]),n=X.useRef(void 0);n.current=t;const s=X.useRef(null),r=X.useCallback(l=>{E.current.push(l)},[]),a=X.useCallback(l=>{E.current=E.current.filter(D=>D!==l)},[]),c=X.useMemo(()=>new W_,[]);A?.up&&c.up.set(A.up.x,A.up.y,A.up.z);const h=X.useRef(new bs);return X.useImperativeHandle(o,()=>h.current),X.useEffect(()=>{if(!C.current)return;YOt(C.current);const l=new dDA({antialias:!0,alpha:!0});_Ot(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=B==="perspective"?new Q0(75,D,.1,1e3):new NT(-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 lSt;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 Q0?d.aspect=k:d instanceof NT&&(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,B]),q.jsx("div",{ref:C,style:{width:"100%",height:"100%",...e},children:Q&&q.jsx(fAg.Provider,{value:Q,children:q.jsx(TZt,{children:g})})})}),HOt=`
5323
+ `).replace(/^d\s+0\./gm,"d 1."),r=i.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),a=new WLt;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=B().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=>{o||I(Q)}).catch(Q=>{console.error(Q)}),()=>{o=!0}},[g]),A}function oOt({url:g,position:A,rotation:I,modelOffset:e=[0,0,0],modelRotation:t=[0,0,0],sourceCoordinateTransform:o,modelSize:B,modelFitMode:C="contain_within_bounds",onHover:Q,onUnhover:i,isHovered:E,scale:n,isTranslucent:s=!1}){const r=tOt(g),a=X.useMemo(()=>{if(r&&!(r instanceof Error))return r.traverse(l=>{if(l instanceof Ko&&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}}),AS(r,{castShadow:!s,receiveShadow:!0}),r;const h=new Ko(new ik(.5,.5,.5),new Hs({transparent:!0,color:"red",opacity:.25}));return AS(h,{castShadow:!1,receiveShadow:!0}),h},[r,s]),{boardTransformGroup:c}=UAg({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:o,modelSize:B,modelFitMode:C,scale:n});if(r instanceof Error)throw r;return q.jsx(wIA,{isHovered:E,onHover:Q,onUnhover:i,object:c})}var BOt=new oo(.82,.82,.82),BmI=g=>new Hs({color:g?new oo(g[0],g[1],g[2]):BOt});function COt(g,A){const I=BmI(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,o=[I],B=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=B.get(s);if(r!==void 0)return r;const a=o.length;return o.push(BmI(n)),B.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 o}function QOt(g){const A=new Yc;for(const I of g){const e=I.attributes.position?.array??[],t=I.index?.array??[];if(!e.length||!t.length)continue;const o=new Yn;o.setAttribute("position",new ZB(e,3));const B=I.attributes.normal?.array??[];B.length?o.setAttribute("normal",new ZB(B,3)):o.computeVertexNormals(),o.setIndex(t),o.clearGroups();const C=COt(o,I),Q=new Ko(o,C.length>1?C:C[0]);Q.name=I.name,A.add(Q)}return A}var cyA;function iOt(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 EOt(){return cyA||(cyA=(async()=>{const g=await import(dIA("occt-import-js","0.0.23","+esm"));return iOt(g)({locateFile:I=>dIA("occt-import-js","0.0.23",`dist/${I}`)})})().catch(g=>{throw cyA=void 0,g})),cyA}async function nOt(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 EOt()).ReadStepFile(new Uint8Array(I),null);if(!t.success||!t.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=QOt(t.meshes),B=new t$A;return await new Promise((Q,i)=>{B.parse(o,E=>{E instanceof ArrayBuffer?Q(E):i(new Error("GLTFExporter did not return binary output"))},E=>{i(E)},{binary:!0})})}var CmI="step-glb-cache:v2:";function sOt(g){const A=new Uint8Array(g),I=32768;let e="";for(let t=0;t<A.length;t+=I){const o=A.subarray(t,t+I);e+=String.fromCharCode(...o)}return btoa(e)}function aOt(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 rOt(g){try{const A=localStorage.getItem(`${CmI}${g}`);return A?aOt(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function QmI(g,A){try{const I=sOt(A);localStorage.setItem(`${CmI}${g}`,I)}catch(I){console.warn("Failed to write STEP GLB cache",I)}}function cOt(){const g=globalThis;return g.stepUrlToGltfModelConversions||(g.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),g.stepUrlToGltfModelConversions}var hOt=({stepUrl:g,position:A,rotation:I,modelOffset:e,modelRotation:t,sourceCoordinateTransform:o,modelSize:B,modelFitMode:C,scale:Q,onHover:i,onUnhover:E,isHovered:n,isTranslucent:s})=>{const[r,a]=X.useState(null);return X.useEffect(()=>{let c=!0,h=null,l=!0;const D=cOt(),d=rOt(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),QmI(g,y.arrayBuffer),()=>{c=!1,h&&l&&URL.revokeObjectURL(h)};let w=D.inProgress.get(g);return w||(w=nOt(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),QmI(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?q.jsx(omI,{gltfUrl:r,position:A,rotation:I,modelOffset:e,modelRotation:t,sourceCoordinateTransform:o,modelSize:B,modelFitMode:C,scale:Q,onHover:i,onUnhover:E,isHovered:n,isTranslucent:s}):null};function hyA(g,A){let{x:I,y:e,z:t}=g;if(A.axisMapping){const o={x:I,y:e,z:t};A.axisMapping.x&&(I=JAg(o,A.axisMapping.x)),A.axisMapping.y&&(e=JAg(o,A.axisMapping.y)),A.axisMapping.z&&(t=JAg(o,A.axisMapping.z))}if(I*=A.flipX??1,e*=A.flipY??1,t*=A.flipZ??1,A.rotation){if(A.rotation.x){const o=A.rotation.x*Math.PI/180,B=Math.cos(o),C=Math.sin(o),Q=e*B-t*C,i=e*C+t*B;e=Q,t=i}if(A.rotation.y){const o=A.rotation.y*Math.PI/180,B=Math.cos(o),C=Math.sin(o),Q=I*B+t*C,i=-I*C+t*B;I=Q,t=i}if(A.rotation.z){const o=A.rotation.z*Math.PI/180,B=Math.cos(o),C=Math.sin(o),Q=I*B-e*C,i=I*C+e*B;I=Q,e=i}}return{x:I,y:e,z:t}}function JAg(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 PAg={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 lOt(g,A){if(A.coordinateTransform)return A.coordinateTransform;if(!A.usingGlbCoordinates){if(A.hasFootprinterModel)return PAg.FOOTPRINTER_MODEL_TRANSFORM;if(!A.usingObjFormat)return A.usingStepFormat?PAg.STEP_INVERTED:PAg.Z_UP_TO_Y_UP_USB_FIX}}function uIA(g,A){return lOt(g,{usingGlbCoordinates:A==="gltf"||A==="glb"||A==="jscad",usingObjFormat:A==="obj"||A==="wrl",usingStepFormat:A==="step",hasFootprinterModel:A==="footprinter"})}function lyA(g){if(!g)return;const A=hyA({x:1,y:0,z:0},g),I=hyA({x:0,y:1,z:0},g),e=hyA({x:0,y:0,z:1},g);return new aQ().makeBasis(new BI(A.x,A.y,A.z),new BI(I.x,I.y,I.z),new BI(e.x,e.y,e.z))}function l3(g){return g*Math.PI/180}function DOt(g){if(g==="z+")return[0,0,0];switch(g){case"x+":return[0,l3(-90),0];case"x-":return[0,l3(90),0];case"y+":return[l3(90),0,0];case"y-":return[l3(-90),0,0];case"z-":return[l3(180),0,0];default:return[0,0,0]}}function dOt(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 yOt(g,A){return g.rotation?[l3(g.rotation.x),l3(g.rotation.y),l3(g.rotation.z)]:A==="bottom"?[Math.PI,0,0]:[0,0,0]}function wOt(g,A){const I=new BI(g.x,g.y,g.z),e=new km(A[0],A[1],A[2],"XYZ");return I.applyEuler(e),[I.x,I.y,I.z]}function uOt(g,A,I){if(!g.model_origin_position)return[0,0,0];const e=A?hyA(g.model_origin_position,A):g.model_origin_position;return wOt(e,I)}function GOt(g,A){const I=dOt(g,A.layer,A.pcbThickness),e=yOt(g,A.layer),t=uIA(g,A.modelType),o=DOt(g.model_board_normal_direction??"z+"),B=uOt(g,t,o);return{position:I,rotation:e,modelPosition:[-B[0],-B[1],-B[2]],modelRotation:o,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 mOt=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",pOt=g=>g==="step"?"glb":g,kOt=(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)},MOt=(g,A)=>{if(g)return A?A(g):g},SOt=(...g)=>g,KAg=class extends sC.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}},fOt=({error:g,onError:A})=>(X.useEffect(()=>{A(g)},[g,A]),null),imI=({cad_component:g,circuitJson:A,resolveStaticAsset:I})=>{const e=AmI(A),[t,o]=X.useState(!1),{visibility:B}=l5(),[C,Q]=X.useState(null),i=X.useCallback(H=>{H?.mousePosition?(o(!0),Q(H.mousePosition)):(o(!1),Q(null))},[]),E=X.useCallback(()=>{o(!1),Q(null)},[]),n=X.useMemo(()=>Xo(A).source_component.getUsing({source_component_id:g.source_component_id})?.name,[A,g.source_component_id]),{pcbComponent:s,layer:r,isThroughHole:a}=X.useMemo(()=>_Zt(g,A),[g,A]),c=X.useCallback(H=>MOt(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]=X.useState(0),[w,u]=X.useState(null);X.useEffect(()=>{y(0),u(null)},[g.cad_component_id,h,l,D]);const G=X.useMemo(()=>kOt(g,A),[g,A]),m=G?B.enclosure==="translucent":!!g.show_as_translucent_model,p=mOt(g),k=pOt(p),S=g.model_glb_url?"glb":"gltf",R=g.model_wrl_url?"wrl":g.model_stl_url?"stl":"obj",x=X.useMemo(()=>GOt(g,{layer:r,pcbThickness:e,modelType:k}),[g,r,e,k]),N=SOt(...x.rotation),U=x.position,K=X.useMemo(()=>{const H=[];return l&&H.push(q.jsx(omI,{gltfUrl:l,position:U,rotation:N,modelOffset:x.modelPosition,modelRotation:x.modelRotation,sourceCoordinateTransform:lyA(uIA(g,S)),scale:x.scale,modelSize:x.size,modelFitMode:x.fitMode,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m},`${g.cad_component_id}-gltf-${l}`)),h&&H.push(q.jsx(oOt,{url:h,position:U,rotation:N,modelOffset:x.modelPosition,modelRotation:x.modelRotation,sourceCoordinateTransform:lyA(uIA(g,R)),scale:x.scale,modelSize:x.size,modelFitMode:x.fitMode,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m},`${g.cad_component_id}-mixed-${h}`)),D&&!g.model_jscad&&!g.footprinter_string&&H.push(q.jsx(hOt,{stepUrl:D,position:U,rotation:N,modelOffset:x.modelPosition,modelRotation:x.modelRotation,sourceCoordinateTransform:lyA(uIA(g,k)),scale:x.scale,modelSize:x.size,modelFitMode:x.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,x.modelPosition,x.modelRotation,x.scale,x.fitMode,x.size,k,N,D,h]);let _=null;if(K.length>0){if(d>=K.length){if(w)throw w;return null}_=q.jsx(KAg,{fallback:({error:H})=>q.jsx(fOt,{error:H,onError:T=>{u(T),y(j=>Math.max(j,d+1))}}),children:K[d]},`${g.cad_component_id}-fallback-${d}`)}else g.model_jscad?_=q.jsx(gOt,{jscadPlan:g.model_jscad,positionOffset:U,rotationOffset:N,modelOffset:x.modelPosition,modelRotation:x.modelRotation,sourceCoordinateTransform:lyA(uIA(g,"jscad")),scale:x.scale,modelSize:x.size,modelFitMode:x.fitMode,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m},g.cad_component_id):g.footprinter_string&&(_=q.jsx(OZt,{positionOffset:U,rotationOffset:N,footprint:g.footprinter_string,scale:x.scale,onHover:i,onUnhover:E,isHovered:t,isTranslucent:m}));if(G){if(B.enclosure==="hidden")return null}else if(g.show_as_translucent_model){if(!B.translucentModels)return null}else if(s&&(a&&!B.throughHoleModels||!a&&!B.smtModels))return null;return q.jsxs(q.Fragment,{children:[q.jsx(JZt,{cadComponent:g,children:_}),t&&C?q.jsx(gmI,{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]})},EmI={version:"0.0.626"},nmI="cadViewerLightingEnabled",ROt=()=>typeof window>"u"?!0:window.localStorage.getItem(nmI)!=="false",smI=X.createContext(void 0),NOt=({children:g})=>{const[A,I]=X.useState(!1),[e,t]=X.useState(!1),[o,B]=X.useState(ROt);X.useEffect(()=>{window.localStorage.setItem(nmI,o?"true":"false")},[o]);const C=X.useMemo(()=>({darkBackgroundEnabled:A,setDarkBackgroundEnabled:I,gridEnabled:e,setGridEnabled:t,lightingEnabled:o,setLightingEnabled:B}),[A,e,o]);return q.jsx(smI.Provider,{value:C,children:g})},LAg=()=>{const g=X.useContext(smI);if(!g)throw new Error("useAppearance must be used within an AppearanceProvider");return g},amI="cadViewerCameraStateSession";function rmI(g){return g?`${amI}:${g}`:amI}function xOt({camera:g,controls:A,cameraSessionScope:I}){try{const e={position:g.position.toArray(),quaternion:g.quaternion.toArray(),up:g.up.toArray(),fov:g instanceof Q0?g.fov:50,target:A.target.toArray()};sessionStorage.setItem(rmI(I),JSON.stringify(e))}catch(e){console.warn("Failed to save camera:",e)}}function FOt({camera:g,controls:A,cameraSessionScope:I}){try{const e=sessionStorage.getItem(rmI(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 Q0&&(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 cmI(g){return"controls"in g?g:{controls:g}}var hmI=(g,A)=>{const{controls:I,cameraSessionScope:e}=cmI(A);xOt({camera:g,controls:I,cameraSessionScope:e})},YAg=(g,A)=>{const{controls:I,cameraSessionScope:e}=cmI(A);return FOt({camera:g,controls:I,cameraSessionScope:e})},lmI=X.createContext(void 0),UOt=({children:g,defaultTarget:A,initialCameraPosition:I,initialCameraType:e})=>{const t=X.useRef(null),o=X.useRef(null),[B,C]=X.useState(null),[Q,i]=X.useState(e??"perspective"),[E,n]=X.useState(I??null),[s,r]=X.useState(new km(0,0,0)),a=X.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=X.useCallback(D=>{const d=[A.x,A.y,A.z],y=o.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,o,t]),h=X.useCallback(D=>{t.current=D},[]),l=X.useMemo(()=>({controlsRef:t,mainCameraRef:o,defaultTarget:A,baseDistance:a,controller:B,setController:C,getPresetConfig:c,handleControlsChange:h,cameraType:Q,setCameraType:i,cameraPosition:E,setCameraPosition:n,cameraRotation:s,setCameraRotation:r,saveCameraToSession:hmI,loadCameraFromSession:YAg}),[A,a,B,c,h,Q,E,s]);return q.jsx(lmI.Provider,{value:l,children:g})},iJ=()=>{const g=X.useContext(lmI);if(!g)throw new Error("useCameraController must be used within a CameraControllerProvider");return g},JOt=g=>g<.5?4*g*g*g:1-Math.pow(-2*g+2,3)/2,POt=()=>{const{controlsRef:g,mainCameraRef:A,defaultTarget:I,setController:e,getPresetConfig:t}=iJ(),o=X.useRef(null),B=X.useRef(new mm),C=X.useRef(new BI),Q=X.useRef(new BI),i=X.useRef(new mm),E=X.useRef(new mm),n=X.useRef(new bs),s=X.useRef(new bs),r=X.useCallback(({position:c,target:h,up:l,durationMs:D=600})=>{if(!A.current)return;const d=g.current?.target??I,y=new BI(c[0],c[1],c[2]),w=h?new BI(h[0],h[1],h[2]):I.clone(),u=new BI(...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 x=R.quaternion.clone();R.up.set(0,0,1),R.position.copy(y),R.lookAt(w);const N=R.quaternion.clone(),U=x.clone().invert().multiply(p).normalize(),K=N.clone().invert().multiply(m).normalize();o.current={fromPosition:k,toPosition:y,fromTarget:S,toTarget:w,toQuaternion:m,rollFrom:U,rollTo:K,startTime:performance.now(),duration:D}},[A,g,I]),a=X.useCallback(c=>{if(c==="Custom")return;const h=t(c);h&&r(h)},[r,t]);return X.useEffect(()=>A.current?(e({animateTo:r,animateToPreset:a}),()=>{e(null)}):void 0,[r,a,A,e]),DIA(()=>{if(!A.current||!o.current)return;const{fromPosition:c,toPosition:h,fromTarget:l,toTarget:D,toQuaternion:d,rollFrom:y,rollTo:w,startTime:u,duration:G}=o.current,m=performance.now()-u,p=G<=0?1:Math.min(m/G,1),k=JOt(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 x=B.current;x.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(x).multiply(N).normalize();const K=Q.current;K.set(0,1,0).applyQuaternion(A.current.quaternion).normalize(),A.current.up.copy(K),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(),o.current=null)}),null},KOt=Symbol("camera-session-not-restored"),LOt=({cameraSessionScope:g}={})=>{const{controlsRef:A}=iJ(),I=X.useRef(null),e=X.useRef(KOt),t=X.useRef(null);X.useEffect(()=>()=>{t.current!==null&&(clearTimeout(t.current),t.current=null)},[g]);const o=X.useCallback(C=>{if(I.current=C,e.current!==g&&A.current){const Q=YAg(C,{controls:A.current,cameraSessionScope:g});if(e.current=g,Q)return}},[g,A]),B=X.useCallback(()=>{if(!(!I.current||!A.current)){if(e.current!==g){const C=YAg(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&&hmI(I.current,{controls:A.current,cameraSessionScope:g})},150)}},[g,A]);return{handleCameraCreated:o,handleControlsChange:B}};function YOt(g){g.querySelectorAll("canvas").forEach(A=>A.remove())}var _Ot=g=>{g.outputColorSpace=Ck,g.toneMapping=YeI,g.toneMappingExposure=1,g.shadowMap.enabled=!0,g.shadowMap.type=JeI},bOt=X.forwardRef(({children:g,scene:A,camera:I,style:e,onCreated:t},o)=>{const{cameraType:B}=iJ(),C=X.useRef(null),[Q,i]=X.useState(null),E=X.useRef([]),n=X.useRef(void 0);n.current=t;const s=X.useRef(null),r=X.useCallback(l=>{E.current.push(l)},[]),a=X.useCallback(l=>{E.current=E.current.filter(D=>D!==l)},[]),c=X.useMemo(()=>new W_,[]);A?.up&&c.up.set(A.up.x,A.up.y,A.up.z);const h=X.useRef(new bs);return X.useImperativeHandle(o,()=>h.current),X.useEffect(()=>{if(!C.current)return;YOt(C.current);const l=new dDA({antialias:!0,alpha:!0});_Ot(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=B==="perspective"?new Q0(75,D,.1,1e3):new NT(-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 lSt;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 Q0?d.aspect=k:d instanceof NT&&(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,B]),q.jsx("div",{ref:C,style:{width:"100%",height:"100%",...e},children:Q&&q.jsx(fAg.Provider,{value:Q,children:q.jsx(TZt,{children:g})})})}),HOt=`
5324
5324
  varying vec3 worldPosition;
5325
5325
  void main() {
5326
5326
  worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
@@ -5354,7 +5354,7 @@ ${Q.join(`
5354
5354
  gl_FragColor = vec4(color, max(g1, g2) * a);
5355
5355
  if (gl_FragColor.a <= 0.0) discard;
5356
5356
  }
5357
- `,qOt=({rotation:g,infiniteGrid:A,cellSize:I=1,sectionSize:e=10})=>{const{scene:t,camera:o}=RD(),B=1e3,C=X.useMemo(()=>{const Q=new pR(B,B);Q.rotateX(-Math.PI/2);const i=new Cx({vertexShader:HOt,fragmentShader:vOt,uniforms:{cellSize:{value:I},sectionSize:{value:e},gridColor:{value:new oo(15658734)},sectionColor:{value:new oo(13421823)},fadeDistance:{value:100},fadeStrength:{value:1.5}},transparent:!0,side:Sl}),E=new Ko(Q,i);return g&&E.rotation.fromArray(g),E},[B,I,e,g]);return DIA(()=>{A&&C.position.set(o.position.x,o.position.y,0)}),X.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},_Ag=.75,TOt=({boardDimensions:g,boardCenter:A,darkBackgroundEnabled:I=!1,shadowsEnabled:e=!1})=>{const{scene:t}=RD(),o=X.useMemo(()=>{const B=new Yc;B.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 lBI(16186360,.22);r.name="cad-viewer-soft-ambient",B.add(r);const a=new ESt(15004141,1581597,.2);a.name="cad-viewer-hemisphere",B.add(a);const c=(h,l,D,d,y=!1)=>{const w=new hBI(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()}B.add(w),B.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*_Ag,[s*.68,-s*.8,-s*1.08]),c("cad-viewer-underside-fill-light",14477554,.25*_Ag,[-n*.85,n*.55,-n*.75]),c("cad-viewer-underside-rim-light",12184275,.5*_Ag,[-n*.35,n*.85,-n*.95]),B},[A,g,e]);return X.useEffect(()=>{const B=t.background,C=t.environment;return t.background=I?new oo(1053456):null,t.environment=null,()=>{t.background=B,t.environment=C}},[I,t]),X.useEffect(()=>{if(t)return t.add(o),()=>{t.remove(o)}},[t,o]),null},ZOt=.05,OOt=({camera:g,initialOrbitDistance:A})=>{const I=Number.isFinite(A)?A*ZOt:0;return Math.max(I,g.near,Number.EPSILON)},WOt=({camera:g,controls:A,minimumDollyDistance:I})=>{if(!(g instanceof Q0))return!1;const e=A.getDistance();if(Number.isFinite(e)&&e>=I)return!1;const t=new BI;return g.getWorldDirection(t),A.target.copy(g.position).addScaledVector(t,I),!0},VOt=({autoRotate:g,autoRotateSpeed:A,onStart:I,panSpeed:e,rotateSpeed:t,zoomSpeed:o,enableDamping:B,dampingFactor:C,target:Q,onControlsChange:i})=>{const{camera:E,renderer:n}=RD(),s=X.useMemo(()=>!E||!n?null:new QYt(E,n.domElement),[E,n]),r=X.useMemo(()=>{if(!s||!(E instanceof Q0))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 OOt({camera:E,initialOrbitDistance:a})},[E,s,Q]);return X.useEffect(()=>(i?.(s??null),()=>i?.(null)),[s,i]),X.useEffect(()=>{if(!s)return;const a=()=>{i?.(s)};return s.addEventListener("change",a),()=>{s.removeEventListener("change",a)}},[s,i]),X.useEffect(()=>{s&&(s.autoRotate=g||!1,s.autoRotateSpeed=A||1,e!==void 0&&(s.panSpeed=e),t!==void 0&&(s.rotateSpeed=t),o!==void 0&&(s.zoomSpeed=o),B!==void 0&&(s.enableDamping=B),C!==void 0&&(s.dampingFactor=C),s.zoomToCursor=!0,s.mouseButtons={LEFT:ZK.ROTATE,MIDDLE:ZK.PAN,RIGHT:null},Q&&(s.target.set(Q[0],Q[1],Q[2]),s.update()))},[s,g,A,e,t,o,B,C,Q]),X.useEffect(()=>{if(!(!s||!I))return s.addEventListener("start",I),()=>{s.removeEventListener("start",I)}},[s,I]),X.useEffect(()=>{if(s)return()=>{s.dispose()}},[s]),DIA(()=>{s&&(WOt({camera:E,controls:s,minimumDollyDistance:r}),s.update())},[E,s,r]),null},jOt=10,k7={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}},zOt=Object.values(k7),XOt=[{type:null,label:"None"},...zOt],$Ot=(g,A)=>g===A?null:A,bAg=g=>Number.isFinite(g)?Math.max(g??0,0):0,DyA=g=>Number.isFinite(g)?g??0:0,DmI=(g,A,I)=>{const e=k7[g],t=bAg(A?.width),o=DyA(I?.x),B=DyA(I?.y);return{x:o+t/2+jOt+e.width/2,y:B,z:0}},AWt=(g,A,I)=>{const e=k7[g],t=bAg(A?.width),o=bAg(A?.height),B=DyA(I?.x),C=DyA(I?.y),Q=DmI(g,A,I);return{minX:Math.min(B-t/2,Q.x-e.width/2),maxX:Math.max(B+t/2,Q.x+e.width/2),minY:Math.min(C-o/2,Q.y-e.height/2),maxY:Math.max(C+o/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 gWt(g,A){const I=new mm().setFromEuler(new km(g.x,g.y,g.z)),e=new BI(0,0,1);return e.applyQuaternion(I),e.multiplyScalar(A)}var IWt=()=>{const{mainCameraRef:g}=iJ(),A=X.useRef(null);return X.useEffect(()=>{if(!A.current)return;const I=A.current,e=document.createElement("canvas");I.appendChild(e);const t=new dDA({canvas:e,antialias:!0,alpha:!0});t.setSize(120,120),t.setPixelRatio(window.devicePixelRatio);const o=new W_,B=new Q0(75,1,.1,1e3);B.up.set(0,0,1);const C=new lBI(16777215,Math.PI/2);o.add(C);const Q=new Yc;Q.rotation.fromArray([Math.PI/2,0,0]);const i=1,E=new Ko(new ik(i,i,i),new Hs({color:"white"}));Q.add(E);const n=new egA(new xMt(new ik(i,i,i)),new V_({color:0,linewidth:2}));Q.add(n),o.add(Q);const s=.51,r=(m,p,k)=>{const S=new dqA;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=gWt(g.current.rotation??new km(0,0,0),2);m.equals(B.position)||(B.position.copy(m),B.lookAt(0,0,0))}t.render(o,B)}};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(),o.clear(),t.dispose(),t.forceContextLoss()}},[g]),q.jsx("div",{ref:A,style:{position:"absolute",top:0,left:0,width:120,height:120,zIndex:yIA.orientationCube}})},dmI=(g,A,I)=>{const e=g/2,t=A/2,o=Math.min(I,e,t),B=new gBI;return B.moveTo(-e+o,-t),B.lineTo(e-o,-t),B.quadraticCurveTo(e,-t,e,-t+o),B.lineTo(e,t-o),B.quadraticCurveTo(e,t,e-o,t),B.lineTo(-e+o,t),B.quadraticCurveTo(-e,t,-e,t-o),B.lineTo(-e,-t+o),B.quadraticCurveTo(-e,-t,-e+o,-t),B},HAg=(g,A,I,e)=>ymI(dmI(g,A,e),I),ymI=(g,A)=>{const I=new gqA(g,{depth:A,bevelEnabled:!1,curveSegments:24});return I.translate(0,0,-A/2),I.computeVertexNormals(),I},eWt=(g,A)=>{const I=k7[A];g.updateMatrixWorld(!0);const t=new pm().setFromObject(g).getSize(new BI);g.scale.set(I.width/t.x,I.height/t.y,I.depth/t.z),g.updateMatrixWorld(!0);const B=new pm().setFromObject(g).getCenter(new BI);g.position.set(-B.x,-B.y,I.zCenter-B.z),g.updateMatrixWorld(!0)},tWt=()=>{const g=new VoI([new BI(-82,18,16),new BI(-67,7,15),new BI(-43,-9,14),new BI(-15,-18,14),new BI(16,-18,14),new BI(47,-8,14.5),new BI(72,8,16),new BI(84,19,17)]),A=84,I=30,e=g.computeFrenetFrames(A,!1),t=[],o=[],B=[],C=[],Q=[],i=new oo(16766023),E=new oo(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 BI().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),o.push(k.x,k.y,k.z),B.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 Yn;return n.setIndex(Q),n.setAttribute("position",new ZB(t,3)),n.setAttribute("normal",new ZB(o,3)),n.setAttribute("color",new ZB(B,3)),n.setAttribute("uv",new ZB(C,2)),n.computeBoundingBox(),n.computeBoundingSphere(),{geometry:n,curve:g}},oWt=()=>{const g=new Yc,A=new Yc,{geometry:I,curve:e}=tWt(),t=new Ko(I,new Hs({color:16777215,roughness:.72,metalness:0,vertexColors:!0}));t.name="banana-peel",A.add(t);const o=new Ko(new X_(3.4,20,12),new Hs({color:6242844,roughness:.92}));o.position.copy(e.getPointAt(0)),o.scale.set(1.15,.78,.78),o.name="banana-blossom-tip",A.add(o);const B=11,C=e.getTangentAt(1).normalize(),Q=new Ko(new PT(2.5,4.1,B,18),new Hs({color:8483625,roughness:.82}));Q.quaternion.setFromUnitVectors(new BI(0,1,0),C),Q.position.copy(e.getPointAt(1)).addScaledVector(C,B/2),Q.name="banana-stem",A.add(Q);const i=new Ko(new X_(2.55,18,10),new Hs({color:5981470,roughness:.9}));return i.position.copy(e.getPointAt(1)).addScaledVector(C,B),i.name="banana-stem-tip",A.add(i),eWt(A,"banana"),g.add(A),g},BWt=(g,A,I,e,t)=>{const o=dmI(g,A,e),B=new jvA;return B.absarc(0,0,t,0,Math.PI*2,!0),o.holes.push(B),ymI(o,I)},CWt=(g,A)=>{const t=new Ko(new PT(A-.15,A-.15,.25,48),new Hs({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},QWt=()=>{const g=k7["credit-card"],A=new Yc,I=new Ko(HAg(g.width,g.height,g.depth,3.18),new Hs({color:2383272,roughness:.38,metalness:.08}));I.name="credit-card-body",A.add(I);const e=g.depth/2+.08,t=new Ko(HAg(12,9,.14,1.2),new Hs({color:14003525,roughness:.3,metalness:.62}));t.position.set(-21,3,e),t.name="credit-card-chip",A.add(t);const o=new Hs({color:15331061,roughness:.45,metalness:.05});for(let B=0;B<4;B++){const C=new Ko(new ik(B===3?8:12,.8,.1),o);C.position.set(-20+B*14,-14,e+.08),C.name="credit-card-detail",A.add(C)}return A},iWt=()=>{const g=k7["14in-macbook"],A=new Yc,I=new Hs({color:12896201,roughness:.3,metalness:.38}),e=new Ko(HAg(g.width,g.height,13.5,9),I);e.position.z=-1,e.name="macbook-body",A.add(e);const t=2,o=6.75,B=o+t/2,C=12,Q=new Ko(BWt(g.width-1.8,g.height-1.8,t,8.2,C),I.clone());Q.position.z=o,Q.name="macbook-lid",A.add(Q);const i=new Ko(new ik(g.width-42,3.2,1.2),new Hs({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(CWt(B,C));const E=new Ko(new ik(54,1.2,.8),new Hs({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},EWt=g=>{const A=g==="banana"?oWt():g==="credit-card"?QWt():iWt();return A.name=`reference-object-${g}`,A.userData.isReferenceObject=!0,A.userData.referenceObjectType=g,AS(A),A},nWt=g=>{const A=new Set,I=new Set;g.traverse(e=>{if(!(e instanceof Ko))return;A.add(e.geometry);const t=Array.isArray(e.material)?e.material:[e.material];for(const o of t)I.add(o)});for(const e of A)e.dispose();for(const e of I)e.dispose()},sWt=(g,A,I,e=1.18)=>{const t=Math.max(I.maxX-I.minX,0),o=Math.max(I.maxY-I.minY,0),B=Math.max(I.maxZ-I.minZ,0),C=new BI((I.minX+I.maxX)/2,(I.minY+I.maxY)/2,(I.minZ+I.maxZ)/2),Q=Math.max(Math.hypot(t,o,B)/2,1),i=A?.target??new BI,E=new BI(0,-.75,.9).normalize();let n=Math.max(g.position.distanceTo(i),5);if(g instanceof Q0){const s=sT.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 NT){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}},aWt=({type:g,boardDimensions:A,boardCenter:I})=>{const{scene:e}=RD(),t=X.useMemo(()=>{const o=EWt(g),B=DmI(g,A,I);return o.position.set(B.x,B.y,B.z),o},[g,A,I]);return X.useEffect(()=>(e.add(t),()=>{e.remove(t),nWt(t)}),[e,t]),null},wmI=({bounds:g})=>{const{camera:A}=RD(),{controlsRef:I}=iJ();return X.useEffect(()=>{sWt(A,I.current,g)},[g,A,I]),null},rWt=()=>{const{camera:g}=RD(),{setCameraRotation:A}=iJ();return DIA(()=>{g&&A(g.rotation)}),null},umI=X.forwardRef(({children:g,initialCameraPosition:A=[5,-5,5],autoRotateDisabled:I,clickToInteractEnabled:e=!1,boardDimensions:t,boardCenter:o,cameraSessionScope:B,referenceObject:C,onUserInteraction:Q,onCameraControllerReady:i},E)=>{const[n,s]=X.useState(!e),{mainCameraRef:r,handleControlsChange:a,controller:c}=iJ(),{darkBackgroundEnabled:h,gridEnabled:l,lightingEnabled:D}=LAg(),{handleCameraCreated:d,handleControlsChange:y}=LOt({cameraSessionScope:B});X.useEffect(()=>{i&&i(c)},[c,i]);const w=X.useMemo(()=>{if(C)return AWt(C,t,o)},[C,t,o]),u=X.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=X.useMemo(()=>{if(w)return[(w.minX+w.maxX)/2,(w.minY+w.maxY)/2,(w.minZ+w.maxZ)/2];if(o)return[o.x,o.y,0]},[o,w]);return q.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[q.jsx(IWt,{}),q.jsxs(bOt,{ref:E,scene:{up:new BI(0,0,1)},camera:{up:[0,0,1],position:A},onCreated:({camera:m})=>{r.current=m,d(m)},children:[q.jsx(UZt,{}),q.jsx(POt,{}),q.jsx(rWt,{}),n&&q.jsx(VOt,{autoRotate:!I,autoRotateSpeed:1,onStart:Q,rotateSpeed:.5,panSpeed:.75,zoomSpeed:.5,enableDamping:!0,dampingFactor:.1,target:G,onControlsChange:m=>{a(m),y()}}),q.jsx(TOt,{boardDimensions:t,boardCenter:o,darkBackgroundEnabled:h,shadowsEnabled:D}),C&&q.jsx(aWt,{type:C,boardDimensions:t,boardCenter:o}),w&&q.jsx(wmI,{bounds:w}),l&&q.jsx(qOt,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:3,sectionSize:u}),g]},B),q.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:["@",EmI.version]}),e&&!n&&q.jsx("button",{type:"button",onClick:()=>s(!0),onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&s(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:yIA.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center"},children:q.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"})})]})}),cWt=g=>{const[A,I]=X.useState([]),[e,t]=X.useState(!0);return X.useEffect(()=>{if(!g)return;(async()=>{t(!0);const C=(Array.isArray(g)?g:[g]).map(async(Q,i)=>{const E=wYt.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}},hWt=Bs(jdA()),lWt=Bs(c5()),DWt=Bs(hIA()),dWt=Bs(c5()),yWt=Bs(h5()),wWt=Bs(MwI()),GmI=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},vAg=(g,A=1.2,I={})=>{const{xyOutset:e=0}=I,{outline:t}=g;let o=t.map(Q=>[Q.x,Q.y]);GmI(o)&&(o=o.reverse());let B=(0,dWt.polygon)({points:o});e!==0&&(B=(0,wWt.expand)({delta:e,corners:"edge"},B));let C=(0,DWt.extrudeLinear)({height:A},B);return C=(0,yWt.translate)([0,0,-A/2],C),C},OB=.01,$E={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]},FR=.001,Nd=32,O2=150,dyA=.6,uWt={fr1:$E.fr1Tan,fr4:$E.fr4Tan,flex:$E.flexAmber},GWt={fr1:$E.fr1SolderMaskGreen,fr4:$E.fr4SolderMaskGreen,flex:$E.flexAmber},mWt={red:"#650202",blue:"#003f7d",purple:"#4c1d69",black:"#071014",white:"#dddddd",yellow:"#dcc84a"},pWt=.875,kWt=/^#(?:[\da-f]{3}|[\da-f]{6})$/i,MWt=/^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/i,SWt=/^rgb\(\s*\d+%\s*,\s*\d+%\s*,\s*\d+%\s*\)$/i,fWt=/^hsl\(\s*\d*\.?\d+\s*,\s*\d*\.?\d+%\s*,\s*\d*\.?\d+%\s*\)$/i,RWt={blue:.96,purple:.96,black:.99,yellow:.92},mmI=g=>{const A=g?.trim();if(!A)return null;const I=A.toLowerCase();if(I==="green"||I==="not_specified")return null;const t=mWt[I];return t?new oo(t):Object.hasOwn(oo.NAMES,I)||kWt.test(A)||MWt.test(A)||SWt.test(A)||fWt.test(A)?new oo(I):null},NWt=g=>{const A=g?.trim().toLowerCase();return RWt[A]??pWt},xWt=({red:g,green:A,blue:I})=>Math.hypot(g-220,A-200,I-74)<4||Math.hypot(g-218,A-197,I-76)<4,FWt=({soldermaskColor:g,copperColor:A,soldermaskOpacity:I})=>g.clone().multiplyScalar(I).add(A.clone().multiplyScalar(1-I)),pmI=g=>{const A=g.clone().convertLinearToSRGB();return`rgb(${[Math.round(A.r*255),Math.round(A.g*255),Math.round(A.b*255)].join(",")})`},UWt=new oo(1063462),qAg=({material:g,solder_mask_color:A})=>{const I=mmI(A);if(I)return I;if(g==="fr4")return UWt.clone();const e=uWt[g]??$E.fr4Tan;return new oo(e[0],e[1],e[2])},JWt=g=>{const A=g.filter(Q=>Q.type==="pcb_panel"),I=Xo(g).pcb_board.list();let e,t,o=1.2;if(A.length>0)e=A[0],t=I.find(Q=>Q.pcb_panel_id===e.pcb_panel_id),o=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,o=e.thickness??1.2}let B;"outline"in e&&e.outline&&e.outline.length>0?B=vAg({outline:e.outline},o):B=(0,lWt.cuboid)({size:[e.width??10,e.height??10,o],center:[e.center.x,e.center.y,0]});const C=qAg({material:t?.material??"fr4",solder_mask_color:t?.solder_mask_color});return[(0,hWt.colorize)([C.r,C.g,C.b],B)]},TAg=Bs(jdA()),Yw=Bs(cIA()),kmI=Bs(BwI()),ZAg=Bs(hIA()),ak=Bs(h5()),rr=Bs(c5()),D3=Bs(c5()),PWt=Bs(hIA()),yyA=Bs(h5()),KWt=Bs(cIA()),LWt=64,YWt=(g,A,I)=>{const e=(0,D3.ellipse)({center:[0,0],radius:[Math.max(g/2,OB/2),Math.max(A/2,OB/2)],segments:LWt}),t=(0,PWt.extrudeLinear)({height:I},e);return(0,yyA.translate)([0,0,-I/2],t)},_Wt=(g,A,I)=>{const e=Math.max(g,OB),t=Math.max(A,OB);if(Math.abs(e-t)<1e-6)return(0,D3.cylinder)({center:[0,0,0],radius:e/2,height:I});const o=e>=t,B=o?e:t,C=o?t:e,Q=Math.max(B-C,0),i=(0,D3.cuboid)({center:[0,0,0],size:o?[Q,C,I]:[C,Q,I]});if(Q<=1e-6)return(0,D3.cylinder)({center:[0,0,0],radius:C/2,height:I});const E=Q/2,n=(0,D3.cylinder)({center:o?[-E,0,0]:[0,-E,0],radius:C/2,height:I}),s=(0,D3.cylinder)({center:o?[E,0,0]:[0,E,0],radius:C/2,height:I});return(0,KWt.union)(i,n,s)},wyA=(g,A,I={})=>{const e=g.hole_shape||"circle",t=I.sizeDelta??0,o=g.hole_offset_x||0,B=g.hole_offset_y||0,C=[g.x+o,g.y+B,0];if(e==="circle"){const r=Math.max((g.hole_diameter??0)+t,OB),a=Math.max(r/2,OB/2);return(0,D3.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,OB),n=Math.max(i+t,OB);if(e==="oval"){const r=YWt(E,n,A);return(0,yyA.translate)([C[0],C[1],0],r)}if(e==="pill"||e==="rotated_pill"){let r=_Wt(E,n,A);if(!r)return null;const a=g.ccw_rotation||0;return a&&(r=(0,yyA.rotateZ)(a*Math.PI/180,r)),(0,yyA.translate)(C,r)}const s=Math.max((g.hole_diameter??Q??i??OB)+t,OB);return(0,D3.cylinder)({center:C,radius:s/2,height:A})},An=Bs(c5()),yx=Bs(jdA()),gc=Bs(cIA()),MmI=Bs(h5()),uyA=Bs(hIA()),rk=Bs(h5()),bWt=1e-5;function SmI(g,A,I){if(typeof I!="number"||!Number.isFinite(I)||I<=0)return 0;const e=g/2,t=A/2,o=Math.min(e,t)-2*bWt;return Math.max(0,Math.min(I,o))}function d3(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 HWt=.05,OAg=64,D5=(g,A)=>A?(0,gc.intersect)(A,g):g,GIA=(g,A,I={})=>{const{clipGeom:e}=I;g.shape||(g.shape="circle");const t=Math.max(A.pcbThickness*.002,OB/5),o=Math.max(A.pcbThickness*3e-4,OB/20),B=Math.max(A.pcbThickness*.0025,OB/4),C=A.pcbThickness+2*HWt+4*OB,Q=Math.max(A.pcbThickness-2*(t+o+B),OB),i=Math.max(Q,OB);if(g.shape==="circle"){const E=g.outer_diameter??Math.max(g.hole_diameter,0),n=Q,s=(0,An.cylinder)({center:[g.x,g.y,0],radius:E/2,height:n}),r=D5(s,e),a=(0,An.cylinder)({center:[g.x,g.y,0],radius:Math.max(g.hole_diameter/2,.01),height:C});return(0,yx.colorize)($E.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,An.cylinder)({center:[0,0,0],radius:1,height:Q,segments:64}),D=(0,MmI.scale)([E/2,n/2,1],l);return(0,rk.translate)([g.x,g.y,0],D)})(),c=D5(a,e),h=(()=>{const l=(0,An.cylinder)({center:[0,0,0],radius:1,height:C,segments:64}),D=(0,MmI.scale)([Math.max(s/2,.01),Math.max(r/2,.01),1],l);return(0,rk.translate)([g.x,g.y,0],D)})();return(0,yx.colorize)($E.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=d3(g),c=D5((0,gc.union)((()=>{const D=(0,An.roundedRectangle)({size:[s,r],roundRadius:a||0,segments:OAg}),d=(0,uyA.extrudeLinear)({height:Q},D);return(0,rk.translate)([g.x,g.y,-Q/2],d)})(),(0,An.cylinder)({center:[g.x+(E||0),g.y+(n||0),0],radius:g.hole_diameter/2,height:i})),e),h=(0,An.cylinder)({center:[g.x+(E||0),g.y+(n||0),0],radius:Math.max(g.hole_diameter/2-OB,.01),height:C}),l=(0,gc.subtract)(c,h);return I.clipGeom?(0,yx.colorize)($E.copper,(0,gc.intersect)(l,I.clipGeom)):(0,yx.colorize)($E.copper,l)}if(g.shape==="pill"){const E=(g.ccw_rotation||0)*Math.PI/180,n=R=>{if(!E)return R;const x=(0,rk.translate)([-g.x,-g.y,0],R),N=(0,rk.rotate)([0,0,E],x);return(0,rk.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,x,N)=>{const U=x/2,K=Math.abs(R-x);if(K<=1e-6)return(0,An.cylinder)({center:[g.x,g.y,0],radius:U,height:N});const _=(0,An.cuboid)({center:[g.x,g.y,0],size:s?[x,K,N]:[K,x,N]}),H=(0,An.cylinder)({center:s?[g.x,g.y-K/2,0]:[g.x-K/2,g.y,0],radius:U,height:N}),T=(0,An.cylinder)({center:s?[g.x,g.y+K/2,0]:[g.x+K/2,g.y,0],radius:U,height:N});return(0,gc.union)(_,H,T)})(c,h,Q),u=(0,An.cuboid)({center:[g.x,g.y,0],size:s?[a-2*OB,D,C]:[D,a-2*OB,C]}),G=(0,An.cylinder)({center:s?[g.x,g.y-D/2,0]:[g.x-D/2,g.y,0],radius:l-OB,height:C}),m=(0,An.cylinder)({center:s?[g.x,g.y+D/2,0]:[g.x+D/2,g.y,0],radius:l-OB,height:C}),p=(0,gc.union)(u,G,m),k=D5(n(w),e),S=n(p);return(0,yx.colorize)($E.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=d3(g),y=.03,w=(0,gc.union)((0,An.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,An.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,An.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,An.cuboid)({center:[g.x+E,g.y+n,0],size:s?[a,h,C]:[h,a,C]}),(0,An.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,An.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,An.roundedRectangle)({size:[l,D],roundRadius:d||0,segments:OAg}),x=(0,uyA.extrudeLinear)({height:Q},R);return(0,rk.translate)([g.x,g.y,-Q/2],x)})(),m=(0,gc.subtract)(G,u),p=(0,gc.union)((0,An.cuboid)({center:[g.x+E,g.y+n,0],size:s?[a-2*OB,h-2*OB,C]:[h-2*OB,a-2*OB,C]}),(0,An.cylinder)({center:s?[g.x+E,g.y+n-h/2,0]:[g.x+E-h/2,g.y+n,0],radius:c-OB,height:C}),(0,An.cylinder)({center:s?[g.x+E,g.y+n+h/2,0]:[g.x+E+h/2,g.y+n,0],radius:c-OB,height:C})),k=(0,gc.subtract)(w,p),S=D5((0,gc.union)(m,k),e);return(0,yx.colorize)($E.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=d3(g),u=.03,G=(g.hole_ccw_rotation||0)*Math.PI/180,m=(g.rect_ccw_rotation||0)*Math.PI/180,p=H=>{const T=E*Math.cos(G)-n*Math.sin(G),j=E*Math.sin(G)+n*Math.cos(G),W=(0,rk.rotate)([0,0,G],H);return(0,rk.translate)([g.x+T,g.y+j,0],W)},k=H=>{if(!m)return H;const T=(0,rk.translate)([-g.x,-g.y,0],H),j=(0,rk.rotate)([0,0,m],T);return(0,rk.translate)([g.x,g.y,0],j)},S=p((0,gc.union)((0,An.cuboid)({center:[0,0,0],size:a?[D+2*u,h+2*u,i]:[h+2*u,D+2*u,i]}),(0,An.cylinder)({center:a?[-D/2,0,0]:[0,-D/2,0],radius:l+u,height:i}),(0,An.cylinder)({center:a?[D/2,0,0]:[0,D/2,0],radius:l+u,height:i}))),R=p((0,gc.union)((0,An.cuboid)({center:[0,0,0],size:a?[D,h,C]:[h,D,C]}),(0,An.cylinder)({center:a?[-D/2,0,0]:[0,-D/2,0],radius:l,height:C}),(0,An.cylinder)({center:a?[D/2,0,0]:[0,D/2,0],radius:l,height:C}))),x=k((()=>{const H=(0,An.roundedRectangle)({size:[d,y],roundRadius:w||0,segments:OAg}),T=(0,uyA.extrudeLinear)({height:Q},H);return(0,rk.translate)([g.x,g.y,-Q/2],T)})()),N=(0,gc.subtract)(x,R),U=p((0,gc.union)((0,An.cuboid)({center:[0,0,0],size:a?[D-2*OB,h-2*OB,C]:[h-2*OB,D-2*OB,C]}),(0,An.cylinder)({center:a?[-D/2,0,0]:[0,-D/2,0],radius:l-OB,height:C}),(0,An.cylinder)({center:a?[D/2,0,0]:[0,D/2,0],radius:l-OB,height:C}))),K=(0,gc.subtract)(S,U),_=D5((0,gc.union)(N,K),e);return(0,yx.colorize)($E.copper,_)}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,An.polygon)({points:n}),c=((y,w)=>{const u=Math.max(y,OB),G=(0,uyA.extrudeLinear)({height:u},s);return(0,rk.translate)([g.x,g.y,w-u/2],G)})(Q,0),h=D5(c,e),l=wyA(g,i);if(!l)return(0,yx.colorize)($E.copper,h);const D=wyA(g,C,{sizeDelta:-2*OB})||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,yx.colorize)($E.copper,d)):(0,yx.colorize)($E.copper,(0,gc.subtract)(d,D))}else throw new Error(`Unsupported plated hole shape: ${g.shape}`)},vWt=Bs(cIA()),qWt=Bs(h5()),WAg=Bs(c5());function TWt({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 o=OB,B=Math.min(I/2,e/2+o),Q=(0,WAg.cylinder)({center:[0,0,0],radius:B,height:t,segments:Nd}),i=t+2*OB,E=(0,WAg.cylinder)({center:[0,0,0],radius:e/2,height:i,segments:Nd}),n=(0,vWt.subtract)(Q,E);return(0,qWt.translate)([g,A,0],n)}function ZWt({x:g,y:A,holeDiameter:I,thickness:e}){const t=e*1.5,o=I/2+OB;return(0,WAg.cylinder)({center:[g,A,0],radius:o,height:t,segments:Nd})}function VAg(g){const A=SSg(g),I=[...Xo(g).pcb_via.list()],e=new Map;for(const t of I){const B=`${A.get(t.pcb_via_id)?.pcb_board_id??""}:${t.x}:${t.y}`,C=e.get(B)??[];C.push(t),e.set(B,C)}for(const t of Xo(g).pcb_trace.list()){const o=A.get(t.pcb_trace_id);for(const[B,C]of t.route.entries()){if(C.route_type!=="via")continue;const Q=`${o?.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_${B}`,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??o?.min_via_hole_diameter??.25,outer_diameter:C.outer_diameter??o?.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 OWt=64,WWt=1,jAg=.05,fmI=["initializing","processing_plated_holes","processing_holes","processing_cutouts","processing_vias","finalizing","done"],VWt=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=Xo(g).pcb_board.list();if(I.length>0){const t=I[0],o=e.find(B=>B.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:o?.thickness??1.4,material:o?.material??"fr4",num_layers:o?.num_layers??2,solder_mask_color:o?.solder_mask_color}}else{const t=e.filter(o=>!o.pcb_panel_id);this.board=t[0]}this.plated_holes=Xo(g).pcb_plated_hole.list(),this.holes=Xo(g).pcb_hole.list(),this.pcb_vias=VAg(g),this.pcb_cutouts=Xo(g).pcb_cutout.list(),this.ctx={pcbThickness:this.board.thickness??1.2},this.initializeBoard()}initializeBoard(){const g=this.ctx.pcbThickness+2*WWt;this.board.outline&&this.board.outline.length>0?(this.boardGeom=vAg({outline:this.board.outline},this.ctx.pcbThickness),this.boardClipGeom=vAg({outline:this.board.outline},g,{xyOutset:jAg})):(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*jAg,this.board.height+2*jAg,g],center:[this.board.center.x,this.board.center.y,0]})),this.state="processing_plated_holes",this.currentIndex=0}goToNextState(){const g=fmI.indexOf(this.state);g!==-1&&(this.state=fmI[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=SmI(g.width,g.height,d3(g));if(e>0){const t=(0,rr.roundedRectangle)({size:[g.width,g.height],roundRadius:e,segments:OWt});A=(0,ZAg.extrudeLinear)({height:I},t),A=(0,ak.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,ak.rotateZ)(t,A)}A=(0,ak.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(o=>[o.x,o.y]);if(e.length<3){console.warn(`PCB Cutout [${g.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);break}GmI(e)&&(e=e.reverse());const t=(0,rr.polygon)({points:e});A=(0,ZAg.extrudeLinear)({height:I},t),A=(0,ak.translate)([0,0,-I/2],A);break}}A&&(this.boardGeom=(0,Yw.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+OB,height:this.ctx.pcbThickness*1.5})}else I=(0,rr.cylinder)({center:[g.x,g.y,0],radius:g.hole_diameter/2+OB,height:this.ctx.pcbThickness*1.5});A.dontCutBoard||(this.boardGeom=(0,Yw.subtract)(this.boardGeom,I),this.copperDrills.push({geom:I,platedHoleIndex:this.platedHoleGeoms.length}));const e=GIA(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,o=t/2,B=Math.abs(e-t);let C;if(C=(0,Yw.union)((0,rr.cuboid)({center:[g.x,g.y,0],size:I?[t,B,this.ctx.pcbThickness*1.5]:[B,t,this.ctx.pcbThickness*1.5]}),(0,rr.cylinder)({center:I?[g.x,g.y-B/2,0]:[g.x-B/2,g.y,0],radius:o,height:this.ctx.pcbThickness*1.5}),(0,rr.cylinder)({center:I?[g.x,g.y+B/2,0]:[g.x+B/2,g.y,0],radius:o,height:this.ctx.pcbThickness*1.5})),g.ccw_rotation){const i=g.ccw_rotation*Math.PI/180;C=(0,ak.translate)([g.x,g.y,0],(0,ak.rotateZ)(i,(0,ak.translate)([-g.x,-g.y,0],C)))}A.dontCutBoard||(this.boardGeom=(0,Yw.subtract)(this.boardGeom,C),this.copperDrills.push({geom:C,platedHoleIndex:this.platedHoleGeoms.length}));const Q=GIA(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,o=t/2,B=Math.abs(e-t);let C;C=(0,Yw.union)((0,rr.cuboid)({center:[g.x+(g.hole_offset_x||0),g.y+(g.hole_offset_y||0),0],size:I?[t,B,this.ctx.pcbThickness*1.5]:[B,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)-B/2,0]:[g.x+(g.hole_offset_x||0)-B/2,g.y+(g.hole_offset_y||0),0],radius:o,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)+B/2,0]:[g.x+(g.hole_offset_x||0)+B/2,g.y+(g.hole_offset_y||0),0],radius:o,height:this.ctx.pcbThickness*1.5})),A.dontCutBoard||(this.boardGeom=(0,Yw.subtract)(this.boardGeom,C),this.copperDrills.push({geom:C,platedHoleIndex:this.platedHoleGeoms.length}));const Q=GIA(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,o=t?I:e,B=t?e:I,C=B/2,Q=Math.abs(o-B),i=g.hole_offset_x||0,E=g.hole_offset_y||0;let n=(0,Yw.union)((0,rr.cuboid)({center:[0,0,0],size:t?[Q,B,this.ctx.pcbThickness*1.5]:[B,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,ak.rotateZ)(s,n);const c=(0,ak.translate)([g.x+r,g.y+a,0],n);A.dontCutBoard||(this.boardGeom=(0,Yw.subtract)(this.boardGeom,c),this.copperDrills.push({geom:c,platedHoleIndex:this.platedHoleGeoms.length}));const h=GIA(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=wyA(g,e,{sizeDelta:2*OB}),o=wyA(g,e,{sizeDelta:-2*OB});if(!t||!o)return;A.dontCutBoard||(this.boardGeom=(0,Yw.subtract)(this.boardGeom,t),this.copperDrills.push({geom:t,platedHoleIndex:this.platedHoleGeoms.length}));const B=GIA(g,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(B)}}}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+OB,height:A});this.boardGeom=(0,Yw.subtract)(this.boardGeom,I);const e=(0,rr.cylinder)({center:[g.x,g.y,0],radius:g.hole_diameter/2+OB/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,o=.02,B=(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,ak.translate)([0,0,-n/2],(0,ZAg.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,Yw.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,Yw.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=B(I,e,A,g.hole_shape==="oval"),Q=B(I-2*o,e-2*o,A,g.hole_shape==="oval");if(C&&t!==0&&(C=(0,ak.rotateZ)(t*Math.PI/180,C)),Q&&t!==0&&(Q=(0,ak.rotateZ)(t*Math.PI/180,Q)),C){const i=(0,ak.translate)([g.x,g.y,0],C);this.boardGeom=(0,Yw.subtract)(this.boardGeom,i)}if(Q){const i=(0,ak.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=TWt({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,Yw.intersect)(this.boardClipGeom,I),e=(0,TAg.colorize)($E.copper,e)),A=this.viaGeoms.length,this.viaGeoms.push(e)}if(typeof g.hole_diameter=="number"){const I=ZWt({x:g.x,y:g.y,holeDiameter:g.hole_diameter,thickness:this.ctx.pcbThickness});this.boardGeom=(0,Yw.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,kmI.measureBoundingBox)(e.geom)})),A=(e,t,o)=>{const B=(0,kmI.measureBoundingBox)(e),C=g.filter(Q=>Q[o]!==t&&[0,1,2].every(i=>Q.bounds[0][i]<=B[1][i]&&Q.bounds[1][i]>=B[0][i])).map(Q=>Q.geom);return(0,TAg.colorize)($E.copper,C.length?(0,Yw.subtract)(e,(0,Yw.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=qAg(this.board);this.boardGeom=(0,TAg.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}},jWt=g=>{const[A,I]=X.useState(null),e=X.useRef(!1);return X.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 B=JWt(g);I(B);const C=new VWt(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},zWt=({children:g,parent:A,position:I,rotation:e,scale:t,color:o,fontSize:B,anchorX:C,anchorY:Q,depthOffset:i})=>{const{rootObject:E}=RD(),n=X.useMemo(()=>{const s=new dqA;return s.text=g,I&&s.position.fromArray(I),e&&s.rotation.fromArray(e),t&&s.scale.fromArray(t),s.color=o||"white",s.fontSize=B||1,s.anchorX=C||"center",s.anchorY=Q||"middle",s.depthOffset=i||0,s.font=null,s.sync(),s},[g,I,e,t,o,B,C,Q,i]);return X.useEffect(()=>{const s=A||E;if(!(!s||!n))return s.add(n),()=>{s.remove(n),n.dispose()}},[E,A,n]),null},RmI=({error:g,cad_component:A})=>{const{rootObject:I}=RD(),[e,t]=X.useState(!1),[o,B]=X.useState(null),C=X.useCallback(n=>{n?.mousePosition?(t(!0),B(n.mousePosition)):(t(!1),B(null))},[]),Q=X.useCallback(()=>{t(!1),B(null)},[]),i=X.useMemo(()=>A?.position?[A.position.x,A.position.y,A.position.z].map(s=>Number.isNaN(s)?0:s):[0,0,0],[A]),E=X.useMemo(()=>{const n=new Yc;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,X.useEffect(()=>{if(I)return I.add(E),()=>{I.remove(E)}},[I,E]),q.jsxs(q.Fragment,{children:[q.jsxs(wIA,{isHovered:e,onHover:C,onUnhover:Q,object:E,children:[q.jsx(XWt,{parent:E}),q.jsx(zWt,{parent:E,scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:`${g.toString().slice(0,50)}...`})]}),e&&o?q.jsx(gmI,{position:o,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]})},XWt=({parent:g})=>{const A=X.useMemo(()=>{const I=new Ko(new ik(.5,.5,.5),new Hs({depthTest:!1,transparent:!0,color:"red",opacity:.5}));return I.renderOrder=999999,I.rotation.fromArray([Math.PI/4,Math.PI/4,0]),I},[]);return X.useEffect(()=>(g.add(A),()=>{g.remove(A)}),[g,A]),null},$Wt=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 o=1;o<g.length;o++){const B=g[o];B.x<A&&(A=B.x),B.y<I&&(I=B.y),B.x>e&&(e=B.x),B.y>t&&(t=B.y)}return{minX:A,minY:I,maxX:e,maxY:t}};function Sy(g){if(g.outline&&g.outline.length>=3){const B=$Wt(g.outline);return{...B,width:B.maxX-B.minX,height:B.maxY-B.minY,centerX:(B.minX+B.maxX)/2,centerY:(B.minY+B.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 AVt(g,A,I){const e=VAg(g);if(!e.length)return[];const t=Sy(A),o=Math.floor(t.width*I),B=Math.floor(t.height*I);if(o<=0||B<=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=o,E.height=B;const n=E.getContext("2d");if(!n)continue;const s=new XE(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,o,B).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)*o/t.width,l=(t.maxY-a.y)*B/t.height,D=c*o/t.width,d=c*B/t.height;if(D<=0||d<=0)continue;const y=Math.max(0,Math.floor(h-D)),w=Math.min(o-1,Math.ceil(h+D)),u=Math.max(0,Math.floor(l-d)),G=Math.min(B-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*o+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 gVt({ctx:g,vias:A,boardData:I,layer:e,width:t,height:o}){if(!A.length)return;const B=Sy(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-B.minX)*t/B.width,i=(e==="top"?B.maxY-C.y:C.y-B.minY)*o/B.height;g.beginPath(),g.ellipse(Q,i,C.hole_diameter/2*t/B.width,C.hole_diameter/2*o/B.height,0,0,Math.PI*2),g.fill()}g.restore()}function IVt({layer:g,circuitJson:A,boardData:I,copperColor:e,traceTextureResolution:t}){const B=Xo(A).pcb_smtpad.list().filter(w=>w.layer===g);if(B.length===0)return null;const C=Xo(A).pcb_hole.list(),Q=Xo(A).pcb_plated_hole.list().filter(w=>!Array.isArray(w.layers)||w.layers.includes(g)),i=Xo(A).pcb_via.list().filter(w=>!Array.isArray(w.layers)||w.layers.includes(g)),E=Xo(A).pcb_cutout.list(),n=[...C,...Q,...i],s=g==="top"?"top_copper":"bottom_copper",r=Sy(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 XE(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([...B,...n,...E],{layers:[s],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});const y=new Ek(a);return y.generateMipmaps=!0,y.minFilter=fl,y.magFilter=Ln,y.anisotropy=16,y.needsUpdate=!0,y}var eVt=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 tVt({layer:g,circuitJson:A,panelData:I,outlineColor:e="black",traceTextureResolution:t}){const o=eVt(A);if(!o)return null;const C=Xo(A).pcb_board.list().filter(c=>c.pcb_panel_id===o||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 Ek(Q);return a.generateMipmaps=!0,a.minFilter=fl,a.magFilter=Ln,a.anisotropy=16,a.needsUpdate=!0,a}function oVt({layer:g,circuitJson:A,boardData:I,traceColor:e,traceTextureResolution:t}){const o=Xo(A).pcb_trace.list(),B=Xo(A).pcb_via.list(),C=Xo(A).pcb_plated_hole.list(),Q=g==="top"?"top_copper":"bottom_copper",i=o.filter(y=>PSg(y).includes(Q));if(i.length===0)return null;const E=C.filter(y=>y.layers.includes(g)),n=[...i,...B,...E],s=Sy(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 XE(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 Ek(r);return d.generateMipmaps=!0,d.minFilter=fl,d.magFilter=Ln,d.anisotropy=16,d.needsUpdate=!0,d}var BVt=g=>{const[A=0,I=0,e=0]=g;return`rgb(${Math.round(A*255)}, ${Math.round(I*255)}, ${Math.round(e*255)})`},CVt=8;function NmI({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=O2,copperColor:t=BVt($E.copper),onlyCoveredBySoldermask:o=!1}){const B=A.filter(p=>p.type==="pcb_copper_pour"),C=g==="top"?"top_copper":"bottom_copper",Q=B.filter(p=>p.layer===g&&(!o||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=Sy(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 XE(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 x=1;x<CVt;x+=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),o||w(G,y);const m=new Ek(a);return m.generateMipmaps=!0,m.minFilter=fl,m.magFilter=Ln,m.anisotropy=16,m.needsUpdate=!0,m}var xmI=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},QVt=({ctx:g,layer:A,bounds:I,elements:e,copperColor:t})=>{const o=A==="top"?"top_copper":"bottom_copper",B=new XE(g);B.configure({colorOverrides:{copper:{top:t,bottom:t,inner1:t,inner2:t,inner3:t,inner4:t,inner5:t,inner6:t,inner7:t,inner8:t}}}),xmI(B,I),B.drawElements(e,{layers:[o]});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 XE(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)"}}}),xmI(E,I),E.drawElements(C.map(n=>({...n,is_knockout:!1})),{layers:[o]}),g.save(),g.globalCompositeOperation="destination-out",g.drawImage(Q,0,0),g.restore()};function iVt({layer:g,circuitJson:A,boardData:I,copperColor:e="rgb(230, 153, 51)",traceTextureResolution:t=O2}){const o=A.filter(s=>s.type==="pcb_copper_text"&&"layer"in s&&s.layer===g);if(o.length===0)return null;const B=Sy(I),C=Math.floor(B.width*t),Q=Math.floor(B.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)),QVt({ctx:E,layer:g,bounds:B,elements:o,copperColor:e});const n=new Ek(i);return n.generateMipmaps=!0,n.minFilter=fl,n.magFilter=Ln,n.anisotropy=16,n.needsUpdate=!0,n}var FmI=25.4,EVt=FmI/1e3,nVt=/^\s*(-?\d*(?:\.\d+)?)(?:\s*(mm|mil|inch|in|"))?\s*$/i;function sVt(g){if(!g)return;const A=g.trim().toLowerCase();return A==='"'||A==="inch"?"in":A}function GyA(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(nVt);if(!I){const C=Number.parseFloat(A);return Number.isFinite(C)?C:void 0}const[,e,t]=I,o=Number.parseFloat(e||"0");if(!Number.isFinite(o))return;switch(sVt(t)){case"mil":return o*EVt;case"in":return o*FmI;case"mm":case void 0:return o;default:return o}}function qs(g,A){const I=GyA(g);return I===void 0?A:I}var aVt="rgb(255,243,204)",cr="rgba(0,0,0,0)",rVt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},cVt=g=>g.type==="pcb_fabrication_note_rect"?{...g,width:GyA(g.width)??0,height:GyA(g.height)??0,stroke_width:qs(g.stroke_width,.1),corner_radius:GyA(g.corner_radius)}:g.type==="pcb_fabrication_note_path"?{...g,stroke_width:qs(g.stroke_width,.1)}:g.type==="pcb_fabrication_note_text"?{...g,font_size:qs(g.font_size,1)}:g.type==="pcb_fabrication_note_dimension"?{...g,font_size:qs(g.font_size,1),arrow_size:qs(g.arrow_size,1),offset_distance:qs(g.offset_distance,0)}:g,hVt=({ctx:g,layer:A,bounds:I,elements:e})=>{const t=`${A}_fabrication_note`,o=e.map(cVt),B=new XE(g);B.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:aVt}}),rVt(B,I),B.drawElements(o,{layers:[t]})},lVt=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}),DVt=(g,A)=>{const I=Math.min(g.minX,A.minX),e=Math.max(g.maxX,A.maxX),t=Math.min(g.minY,A.minY),o=Math.max(g.maxY,A.maxY);return{minX:I,maxX:e,minY:t,maxY:o,width:e-I,height:o-t,centerX:(I+e)/2,centerY:(t+o)/2}},myA=(g,A)=>{const I=g.filter(B=>B.type==="pcb_panel"),e=g.filter(B=>B.type==="pcb_board"),t=I.find(B=>B.pcb_panel_id===A.pcb_board_id)??I[0];return t&&t.width>0&&t.height>0?lVt(t):(e.length>1?e:[A]).map(B=>Sy(B)).reduce((B,C)=>DVt(B,C))},dVt=(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 yVt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=O2}){const t=A.filter(n=>dVt(n,g));if(t.length===0)return null;const o=myA(A,I),B=Math.floor(o.width*e),C=Math.floor(o.height*e);if(B<=0||C<=0)return null;const Q=document.createElement("canvas");Q.width=B,Q.height=C;const i=Q.getContext("2d");if(!i)return null;g==="bottom"&&(i.translate(0,C),i.scale(1,-1)),hVt({ctx:i,layer:g,bounds:o,elements:t});const E=new Ek(Q);return E.generateMipmaps=!0,E.minFilter=fl,E.magFilter=Ln,E.anisotropy=16,E.needsUpdate=!0,E}var wVt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},uVt=({ctx:g,layer:A,bounds:I,elements:e,keepoutColor:t})=>{const o=A==="top"?"top_copper":"bottom_copper",B=new XE(g);B.configure({colorOverrides:{keepout:{top:t,bottom:t}}}),wVt(B,I),B.drawElements(e,{layers:[o],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1})},GVt=(g,A)=>g.type!=="pcb_keepout"?!1:!("layers"in g)||!Array.isArray(g.layers)?!0:g.layers.includes(A);function mVt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=O2,keepoutColor:t=g==="bottom"?"#4b72d2":"#d24b4b"}){const o=A.filter(s=>GVt(s,g));if(o.length===0)return null;const B=Sy(I),C=Math.floor(B.width*e),Q=Math.floor(B.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)),uVt({ctx:E,layer:g,bounds:B,elements:o,keepoutColor:t});const n=new Ek(i);return n.generateMipmaps=!0,n.minFilter=fl,n.magFilter=Ln,n.anisotropy=16,n.needsUpdate=!0,n}var Ha="rgba(0,0,0,0)",pVt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},kVt=g=>g.type==="pcb_note_line"?{...g,x1:qs(g.x1,0),y1:qs(g.y1,0),x2:qs(g.x2,0),y2:qs(g.y2,0),stroke_width:qs(g.stroke_width,.1)}:g.type==="pcb_note_rect"?{...g,center:{x:qs(g.center.x,0),y:qs(g.center.y,0)},width:qs(g.width,0),height:qs(g.height,0),stroke_width:qs(g.stroke_width,.1),corner_radius:qs(g.corner_radius,0)}:g.type==="pcb_note_text"?{...g,anchor_position:{x:qs(g.anchor_position.x,0),y:qs(g.anchor_position.y,0)},font_size:qs(g.font_size,1)}:g.type==="pcb_note_path"?{...g,route:g.route.map(A=>({...A,x:qs(A.x,0),y:qs(A.y,0)})),stroke_width:qs(g.stroke_width,.1)}:g.type==="pcb_note_dimension"?{...g,from:{x:qs(g.from.x,0),y:qs(g.from.y,0)},to:{x:qs(g.to.x,0),y:qs(g.to.y,0)},font_size:qs(g.font_size,1),arrow_size:qs(g.arrow_size,1),offset_distance:qs(g.offset_distance,0)}:g,MVt=({ctx:g,bounds:A,elements:I})=>{const e=I.map(kVt),t=new XE(g);t.configure({colorOverrides:{copper:{top:Ha,bottom:Ha,inner1:Ha,inner2:Ha,inner3:Ha,inner4:Ha,inner5:Ha,inner6:Ha,inner7:Ha,inner8:Ha},copperPour:{top:Ha,bottom:Ha},drill:Ha,boardOutline:Ha,substrate:Ha,keepout:{top:Ha,bottom:Ha},courtyard:{top:Ha,bottom:Ha},soldermask:{top:Ha,bottom:Ha},soldermaskWithCopperUnderneath:{top:Ha,bottom:Ha},soldermaskOverCopper:{top:Ha,bottom:Ha},silkscreen:{top:Ha,bottom:Ha},fabricationNote:Ha}}),pVt(t,A),t.drawElements(e)},SVt=(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 fVt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=O2}){const t=A.filter(n=>SVt(n,g));if(t.length===0)return null;const o=myA(A,I),B=Math.floor(o.width*e),C=Math.floor(o.height*e);if(B<=0||C<=0)return null;const Q=document.createElement("canvas");Q.width=B,Q.height=C;const i=Q.getContext("2d");if(!i)return null;g==="bottom"&&(i.translate(0,C),i.scale(1,-1)),MVt({ctx:i,bounds:o,elements:t});const E=new Ek(Q);return E.generateMipmaps=!0,E.minFilter=fl,E.magFilter=Ln,E.anisotropy=16,E.needsUpdate=!0,E}var RVt="rgb(255,243,204)",bc="rgba(0,0,0,0)",UmI=(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,o=A==="top"?I?.default_via_tented_on_top:I?.default_via_tented_on_bottom;return e??t??o??!1},NVt=(g,A,I,e)=>g.type==="pcb_cutout"?!0:g.type==="pcb_via"?!e||!UmI(g,A,I):g.type==="pcb_hole"||g.type==="pcb_plated_hole"?!e||g.is_covered_with_solder_mask!==!0:!1,xVt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},FVt=({ctx:g,layer:A,bounds:I,elements:e,circuitJson:t,silkscreenColor:o,soldermaskVisible:B})=>{const C=A==="top"?"top_silkscreen":"bottom_silkscreen",Q=new XE(g);Q.configure({colorOverrides:{copper:{top:bc,bottom:bc,inner1:bc,inner2:bc,inner3:bc,inner4:bc,inner5:bc,inner6:bc,inner7:bc,inner8:bc},copperPour:{top:bc,bottom:bc},drill:bc,boardOutline:bc,substrate:bc,keepout:{top:bc,bottom:bc},courtyard:{top:bc,bottom:bc},soldermask:{top:bc,bottom:bc},soldermaskWithCopperUnderneath:{top:bc,bottom:bc},soldermaskOverCopper:{top:bc,bottom:bc},silkscreen:{top:o,bottom:o},fabricationNote:RVt}}),xVt(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"&&(!B||!UmI(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 NVt(E,A,n,B)?[E]:[]});Q.drawElements(i,{layers:[C],clipContextElements:t,clearDrillHoles:!0})},UVt=(g,A)=>!("layer"in g)||g.layer!==A?!1:g.type.startsWith("pcb_silkscreen_");function JVt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=O2,silkscreenColor:t="rgb(255,255,255)",soldermaskVisible:o=!0}){const B=A.filter(r=>UVt(r,g));if(B.length===0)return null;const C=myA(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)),FVt({ctx:n,layer:g,bounds:C,elements:B,circuitJson:A,silkscreenColor:t,soldermaskVisible:o});const s=new Ek(E);return s.generateMipmaps=!0,s.minFilter=fl,s.magFilter=Ln,s.anisotropy=16,s.needsUpdate=!0,s}var mIA=g=>{const[A=0,I=0,e=0]=g;return`rgb(${Math.round(A*255)}, ${Math.round(I*255)}, ${Math.round(e*255)})`},PVt=g=>{const A=mIA(GWt[g.material]??$E.fr4SolderMaskGreen),I=g.material==="fr1"?mIA($E.fr1TracesWithMaskCopper):mIA($E.fr4TracesWithMaskGreen),e=mmI(g.solder_mask_color);if(!e)return{soldermask:A,soldermaskOverCopper:I,copper:mIA($E.copper),transparent:"rgba(0,0,0,0)"};const t=new oo().setRGB($E.copper[0],$E.copper[1],$E.copper[2],Ck);return{soldermask:pmI(e),soldermaskOverCopper:pmI(FWt({soldermaskColor:e,copperColor:t,soldermaskOpacity:NWt(g.solder_mask_color)})),copper:mIA($E.copper),transparent:"rgba(0,0,0,0)"}},JmI=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},KVt=g=>g.type.startsWith("pcb_note_")||g.type.startsWith("pcb_fabrication_note_"),LVt=({ctx:g,layer:A,bounds:I,elements:e,boardData:t})=>{const o=PVt(t),B=A==="top"?"top_copper":"bottom_copper",C=new XE(g);C.configure({colorOverrides:{copper:{top:o.transparent,bottom:o.transparent,inner1:o.transparent,inner2:o.transparent,inner3:o.transparent,inner4:o.transparent,inner5:o.transparent,inner6:o.transparent,inner7:o.transparent,inner8:o.transparent},drill:o.transparent,boardOutline:o.transparent,substrate:o.transparent,keepout:{top:o.transparent,bottom:o.transparent},fabricationNote:o.transparent,silkscreen:{top:o.transparent,bottom:o.transparent},courtyard:{top:o.transparent,bottom:o.transparent},soldermask:{top:o.soldermask,bottom:o.soldermask},soldermaskWithCopperUnderneath:{top:o.soldermaskOverCopper,bottom:o.soldermaskOverCopper},soldermaskOverCopper:{top:o.soldermaskOverCopper,bottom:o.soldermaskOverCopper}}}),JmI(C,I);const Q=e.filter(E=>E.type!=="pcb_keepout"&&!KVt(E));C.drawElements(Q,{layers:[B],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 XE(g);E.configure({colorOverrides:{copper:{top:o.copper,bottom:o.copper,inner1:o.copper,inner2:o.copper,inner3:o.copper,inner4:o.copper,inner5:o.copper,inner6:o.copper,inner7:o.copper,inner8:o.copper}}}),JmI(E,I),E.drawElements(i,{layers:[B]}),g.restore()}};function YVt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=O2}){const t=myA(A,I),o=Math.floor(t.width*e),B=Math.floor(t.height*e);if(o<=0||B<=0)return null;const C=document.createElement("canvas");C.width=o,C.height=B;const Q=C.getContext("2d");if(!Q)return null;g==="bottom"&&(Q.translate(0,B),Q.scale(1,-1));const i=A.some(n=>n.type==="pcb_board")?A:[I,...A];LVt({ctx:Q,layer:g,bounds:t,elements:i,boardData:I});const E=new Ek(C);return E.generateMipmaps=!0,E.minFilter=fl,E.magFilter=Ln,E.anisotropy=16,E.needsUpdate=!0,E}var _Vt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},bVt=({ctx:g,layer:A,bounds:I,elements:e,copperColor:t})=>{const o=A==="top"?"top_copper":"bottom_copper",B="rgba(0,0,0,0)",C=new XE(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:B,boardOutline:B,substrate:B,keepout:{top:B,bottom:B},fabricationNote:B,silkscreen:{top:B,bottom:B},courtyard:{top:B,bottom:B},soldermask:{top:B,bottom:B},soldermaskWithCopperUnderneath:{top:B,bottom:B},soldermaskOverCopper:{top:B,bottom:B}}}),_Vt(C,I),C.drawElements(e,{layers:[o]})};function HVt({layer:g,circuitJson:A,boardData:I,copperColor:e="rgb(230, 153, 51)",traceTextureResolution:t=O2}){const o=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(o.length===0)return null;const B=Sy(I),C=Math.floor(B.width*t),Q=Math.floor(B.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)),bVt({ctx:E,layer:g,bounds:B,elements:o,copperColor:e});const n=new Ek(i);return n.generateMipmaps=!0,n.minFilter=fl,n.magFilter=Ln,n.anisotropy=16,n.needsUpdate=!0,n}var PmI=g=>{const[A=0,I=0,e=0]=g;return`rgb(${Math.round(A*255)}, ${Math.round(I*255)}, ${Math.round(e*255)})`},zAg=g=>Math.max(0,Math.min(255,g)),vVt=(g,A,I,e={})=>{const t=g.getImageData(0,0,A,I),o=t.data,B=Math.max(A-1,1),C=Math.max(I-1,1);for(let Q=0;Q<o.length;Q+=4){if((o[Q+3]??0)<16)continue;const E=o[Q]??0,n=o[Q+1]??0,s=o[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/B,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 x=D-.36,N=d-.22,U=Math.max(0,1-Math.hypot(x,N)/.38);return U*U*.07})():0,m=(E*.9+3)*u,p=(n*1.08+15)*u,k=(s*1.28+13)*u;o[Q]=zAg(m*(1-G)+255*G),o[Q+1]=zAg(p*(1-G)+255*G),o[Q+2]=zAg(k*(1-G)+255*G)}g.putImageData(t,0,0)},qVt=({textures:g,boardData:A,traceTextureResolution:I,layer:e,openViaHoles:t})=>{if(!g.some(s=>s?.image))return null;const B=Sy(A),C=Math.floor(B.width*I),Q=Math.floor(B.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)}gVt({ctx:E,vias:t,boardData:A,layer:e,width:C,height:Q}),vVt(E,C,Q,{includeReflection:e==="top"});const n=new Ek(i);return n.generateMipmaps=!1,n.minFilter=Ln,n.magFilter=Ln,n.premultiplyAlpha=!0,n.anisotropy=16,n.needsUpdate=!0,n},TVt=({textures:g,soldermaskTexture:A,boardData:I,traceTextureResolution:e})=>{if(!A?.image||!g.some(E=>E?.image))return null;const t=Sy(I),o=Math.floor(t.width*e),B=Math.floor(t.height*e);if(o<=0||B<=0)return null;const C=document.createElement("canvas");C.width=o,C.height=B+1;const Q=C.getContext("2d");if(!Q)return null;for(const E of g)E?.image&&Q.drawImage(E.image,0,0,o,B);Q.globalCompositeOperation="destination-in",Q.drawImage(A.image,0,0,o,B),Q.globalCompositeOperation="source-over";const i=new Ek(C);return i.colorSpace=Bx,i.generateMipmaps=!1,i.minFilter=Ln,i.magFilter=Ln,i.premultiplyAlpha=!1,i.needsUpdate=!0,i};function KmI({circuitJson:g,boardData:A,traceTextureResolution:I,visibility:e}){const t=PmI($E.copper),o="rgb(255,255,255)",B=PmI($E.copper),C=e?.boardBody??!0,Q=AVt(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?YVt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,d=c?oVt({layer:r,circuitJson:g,boardData:A,traceColor:t,traceTextureResolution:I}):null,y=c?NmI({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I,copperColor:B}):null,w=a&&c?NmI({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I,copperColor:B,onlyCoveredBySoldermask:!0}):null,u=c?iVt({layer:r,circuitJson:g,boardData:A,copperColor:B,traceTextureResolution:I}):null,G=c?IVt({layer:r,circuitJson:g,boardData:A,copperColor:B,traceTextureResolution:I}):null,m=c?HVt({layer:r,circuitJson:g,boardData:A,copperColor:B,traceTextureResolution:I}):null,p=h?JVt({layer:r,circuitJson:g,boardData:A,silkscreenColor:o,traceTextureResolution:I,soldermaskVisible:a}):null,k=h?yVt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,R=e?.pcbNotes??!1?fVt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,x=C?tVt({layer:r,circuitJson:g,panelData:A,traceTextureResolution:I}):null,N=l?mVt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,U=qVt({openViaHoles:Q,textures:[y,d,G,m,D,u,p,k,R,x,N],boardData:A,traceTextureResolution:I,layer:r}),K=a&&c?TVt({textures:[d,w],soldermaskTexture:D,boardData:A,traceTextureResolution:I}):null;return{boardTexture:U,maskedCopperTexture:K}},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 UR={bumpScale:.12,normalScale:.08,roughnessBias:.015,clearcoat:.08,clearcoatRoughness:.55},pyA={roughness:.42,metalness:.5,roughnessVariance:.035,detailStrength:.028},kyA=.22,ZVt=.7,OVt=.86,LmI={height:kyA,microSurfaceWeight:1,roughness:.7,metalness:.015,isExposedCopper:!1,isMaskedCopper:!1},WVt={height:ZVt,microSurfaceWeight:.9,roughness:.54,metalness:.025,isExposedCopper:!1,isMaskedCopper:!0},XAg=g=>Math.max(0,Math.min(1,g)),YmI=g=>1-g,pIA=(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},_mI=g=>g*g*(3-2*g),$Ag=(g,A,I)=>g+(A-g)*I,Agg=(g,A,I,e)=>{const t=g/I,o=A/I,B=Math.floor(t),C=Math.floor(o),Q=_mI(t-B),i=_mI(o-C),E=$Ag(pIA(B,C,e),pIA(B+1,C,e),Q),n=$Ag(pIA(B,C+1,e),pIA(B+1,C+1,e),Q);return $Ag(E,n,i)},VVt=(g,A,I)=>{const e=(Agg(g,A,7,I+31)-.5)*.55,t=Math.sin(g*.12+Agg(g,A,44,I+37)*2)*.22;return(e+t)*pyA.detailStrength},jVt=(g,A,I)=>{const e=(pIA(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},zVt=(g,A,I,e)=>e?WVt:xWt({red:g,green:A,blue:I})?LmI:g>120&&A>70&&I<150&&g>A*1.05&&A>I*1.15?{height:OVt,microSurfaceWeight:.9,roughness:pyA.roughness,metalness:pyA.metalness,isExposedCopper:!0,isMaskedCopper:!1}:g>170&&A>170&&I>160?{height:kyA,microSurfaceWeight:.4,roughness:.76,metalness:0,isExposedCopper:!1,isMaskedCopper:!1}:A>g*1.25&&A>I*1.05&&g<110&&A<180&&I<130?LmI:{height:kyA,microSurfaceWeight:.7,roughness:.58,metalness:.015,isExposedCopper:!1,isMaskedCopper:!1},MyA=g=>{const A=new Ek(g);return A.colorSpace=Bx,A.generateMipmaps=!1,A.minFilter=Ln,A.magFilter=Ln,A.wrapS=Gm,A.wrapT=Gm,A.needsUpdate=!0,A},bmI=(g,A)=>{const I=g.image;if(!I?.width||!I.height)return null;const{width:e,height:t}=I,o=I.getContext("2d");if(!o)return null;const B=A?.image,C=B?.getContext("2d"),Q=B?.width??0,i=B?.height??0,E=C&&Q&&i?C.getImageData(0,0,Q,i):null,n=o.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 x=0;x<s.length;x+=4){const N=x/4,U=N%e,K=Math.floor(N/e);if((s[x+3]??0)<16){r[N]=YmI(kyA);continue}const H=E?Math.min(Q-1,Math.floor(U/e*Q)):0,T=E?Math.min(i-1,Math.floor(K/t*i)):0,j=E?E.data[(T*Q+H)*4+3]??0:0,W=zVt(s[x]??0,s[x+1]??0,s[x+2]??0,j>=16),O=e+t,gA=W.isExposedCopper?VVt(U,K,O):W.isMaskedCopper?jVt(U,K,O):0,tA=XAg(YmI(W.height)+gA*W.microSurfaceWeight);r[N]=tA;const IA=tA*255;s[x]=s[x+1]=s[x+2]=IA,s[x+3]=255;const nA=(W.isExposedCopper?XAg(W.roughness+gA*.7+(Agg(U,K,36,O+17)-.5)*pyA.roughnessVariance):W.isMaskedCopper?XAg(W.roughness+gA+UR.roughnessBias):W.roughness)*255;y[x]=y[x+1]=y[x+2]=nA,y[x+3]=255;const DA=W.metalness*255;w[x]=w[x+1]=w[x+2]=DA,w[x+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=(x,N)=>r[Math.max(0,Math.min(t-1,N))*e+Math.max(0,Math.min(e-1,x))]??0;for(let x=0;x<t;x++)for(let N=0;N<e;N++){const U=(R(N+1,x)-R(N-1,x))*4,K=(R(N,x+1)-R(N,x-1))*4,_=1/Math.sqrt(U*U+K*K+1),H=(x*e+N)*4;S[H]=(-U*_*.5+.5)*255,S[H+1]=(-K*_*.5+.5)*255,S[H+2]=(_*.5+.5)*255,S[H+3]=255}return p.putImageData(k,0,0),{bumpMap:MyA(u),normalMap:MyA(m),roughnessMap:MyA(a),metalnessMap:MyA(c)}};function HmI(g,A){const{texture:I,maskedCopperMask:e,yOffset:t,isBottomLayer:o,usePolygonOffset:B=!1,renderOrder:C=0,isFaux:Q=!1}=g;if(!I)return null;const i=Sy(A),E=new pR(i.width,i.height);I.colorSpace=Ck;const n={map:I,transparent:!0,alphaTest:.08,side:vM,depthWrite:!0,polygonOffset:B,polygonOffsetFactor:B?-4:0,polygonOffsetUnits:B?-4:0,opacity:Q?dyA:1},s=bmI(I,e),r=new OM({...n,bumpMap:s?.bumpMap??null,bumpScale:UR.bumpScale,normalMap:s?.normalMap??null,normalScale:new ct(UR.normalScale,UR.normalScale),roughnessMap:s?.roughnessMap??null,roughness:1,metalnessMap:s?.metalnessMap??null,metalness:1,clearcoat:UR.clearcoat,clearcoatRoughness:UR.clearcoatRoughness,envMapIntensity:.18}),a=new Ko(E,r);return a.position.set(i.centerX,i.centerY,t),o&&a.rotation.set(Math.PI,0,0),a.name=`${o?"bottom":"top"}-board-texture-plane`,a.renderOrder=C,AS(a,{castShadow:!1,receiveShadow:!0}),a}function XVt(g,A,I,e=!1){const t=[];if(!g||!A||I===null)return t;const o=.005,B=HmI({texture:g.topBoard,maskedCopperMask:g.topMaskedCopper,yOffset:I/2+o,isBottomLayer:!1,usePolygonOffset:!0,renderOrder:1,isFaux:e},A);B&&t.push(B);const C=HmI({texture:g.bottomBoard,maskedCopperMask:g.bottomMaskedCopper,yOffset:-I/2-o,isBottomLayer:!0,usePolygonOffset:!0,renderOrder:1,isFaux:e},A);return C&&t.push(C),t}var vmI=g=>{const{boardBody:A,topCopper:I,bottomCopper:e,topSilkscreen:t,bottomSilkscreen:o,topMask:B,bottomMask:C,keepout:Q,pcbNotes:i}=g;return X.useMemo(()=>({boardBody:A,topCopper:I,bottomCopper:e,topSilkscreen:t,bottomSilkscreen:o,topMask:B,bottomMask:C,keepout:Q,pcbNotes:i}),[A,I,e,t,o,B,C,Q,i])},$Vt=4e6,Ajt=4096,gjt=1;function qmI(g,A,I={}){const{maxTexturePixels:e=$Vt,maxTextureDimension:t=Ajt,minTextureResolution:o=gjt}=I,B=Sy(g);if(!Number.isFinite(B.width)||!Number.isFinite(B.height)||B.width<=0||B.height<=0)return A;const C=Math.max(B.width,B.height),Q=t/C,i=Math.sqrt(e/(B.width*B.height)),E=Math.min(A,Q,i);return Math.max(o,E)}function Ijt({circuitJson:g,pcbThickness:A,isFaux:I=!1}){const{rootObject:e}=RD(),{visibility:t}=l5(),o=vmI(t),B=X.useMemo(()=>{const i=g.filter(s=>s.type==="pcb_panel"),E=Xo(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=X.useMemo(()=>B?qmI(B,O2):O2,[B]),Q=X.useMemo(()=>!B?.width||!B.height?null:KmI({circuitJson:g,boardData:B,traceTextureResolution:C,visibility:o}),[g,B,C,o]);return X.useEffect(()=>{if(!e||!B||!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 $r&&(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=Sy(B),m=new pR(G.width,G.height);c.colorSpace=Ck;const p={map:c,transparent:!0,alphaTest:.08,side:vM,depthWrite:w,polygonOffset:y,polygonOffsetFactor:y?-4:0,polygonOffsetUnits:y?-4:0,opacity:I?dyA:1},k=bmI(c,h),S=new OM({...p,bumpMap:k?.bumpMap??null,bumpScale:UR.bumpScale,normalMap:k?.normalMap??null,normalScale:new ct(UR.normalScale,UR.normalScale),roughnessMap:k?.roughnessMap??null,roughness:1,metalnessMap:k?.metalnessMap??null,metalness:1,clearcoat:UR.clearcoat,clearcoatRoughness:UR.clearcoatRoughness,envMapIntensity:.18}),R=new Ko(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,AS(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 Qk&&E(c.material);Q.topBoard?.dispose(),Q.bottomBoard?.dispose()}},[e,B,Q,A]),null}function ejt({stlUrl:g,stlData:A,mtlUrl:I,color:e,opacity:t=1,layerType:o}){const{rootObject:B}=RD(),[C,Q]=X.useState(null);X.useEffect(()=>{const E=new OLt;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=X.useMemo(()=>{if(!C)return null;const E=o==="board",n=new Hs({color:Array.isArray(e)?new oo(e[0],e[1],e[2]):e,transparent:t!==1,opacity:t,polygonOffset:E,polygonOffsetFactor:E?6:0,polygonOffsetUnits:E?6:0}),s=new Ko(C,n);return s.renderOrder=E?-1:1,AS(s,{castShadow:!E&&t===1,receiveShadow:!0}),s},[C,e,t,o]);return X.useEffect(()=>{if(!(!B||!i))return B.add(i),()=>{B.remove(i),i.geometry.dispose(),Array.isArray(i.material)?i.material.forEach(E=>E.dispose()):i.material.dispose()}},[B,i]),null}function tjt({stlData:g,color:A,opacity:I=1,layerType:e}){const{visibility:t}=l5();let o=!0;return e==="board"?o=t.boardBody:e==="top-copper"?o=t.topCopper:e==="bottom-copper"?o=t.bottomCopper:e==="top-silkscreen"?o=t.topSilkscreen:e==="bottom-silkscreen"&&(o=t.bottomSilkscreen),o?q.jsx(ejt,{stlData:g,color:A,opacity:I,layerType:e}):null}var ojt=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)},TmI=g=>g.filter(ojt),Bjt=({x:g,y:A,z:I})=>[g,A,I],ZmI=({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 o=new BI(t.x-e.x,t.y-e.y,t.z-e.z);if(o.lengthSq()<1e-12)return;o.normalize();const B=new BI(A.x-e.x,A.y-e.y,A.z-e.z);if(B.addScaledVector(o,-B.dot(o)),!(B.lengthSq()<1e-12))return B.normalize(),[B.x,B.y,B.z]},Cjt=g=>{const A=k_t(g.cableprinter_string),I=Y_t({definition:A,path:g.path.map(Bjt),startPin1Side:ZmI({path:g.path,pin1Position:g.from_connector_pin1_position,end:"start"}),endPin1Side:ZmI({path:g.path,pin1Position:g.to_connector_pin1_position,end:"end"})}),e=new Yc;e.name=`cad-cable-${g.cad_cable_id}`,e.userData={cadCableId:g.cad_cable_id,name:g.name};for(const t of I){let o=new Yn;o.setAttribute("position",new ZB(t.positions,3)),o.setIndex(t.indices),t.smooth||(o=o.toNonIndexed()),o.computeVertexNormals();const[B,C,Q,i]=t.color,E=new Hs({color:new oo(B,C,Q),metalness:t.material?.metalness??0,roughness:t.material?.roughness??.7,opacity:i,transparent:i<1,side:Sl}),n=new Ko(o,E);n.name=`${e.name}:${t.name}`,AS(n,{castShadow:!0,receiveShadow:!0}),e.add(n)}return e},Qjt=g=>{g.traverse(A=>{if(!(A instanceof Ko))return;A.geometry.dispose();const I=Array.isArray(A.material)?A.material:[A.material];for(const e of I)e.dispose()})},OmI=({cable:g})=>{const{rootObject:A}=RD(),I=X.useMemo(()=>{try{return Cjt(g)}catch(e){return console.error(`Failed to render CAD cable ${g.cad_cable_id}`,e),null}},[g]);return X.useEffect(()=>{if(I)return A.add(I),()=>{A.remove(I),Qjt(I)}},[I,A]),null};function WmI({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 ijt(g){const A=Xo(g).cad_component.list().filter(D=>D.pcb_component_id),I=Xo(g).pcb_smtpad.list(),e=Xo(g).pcb_hole.list(),t=Xo(g).pcb_plated_hole.list(),o=Xo(g).pcb_via.list();if(A.length===0&&I.length===0&&e.length===0&&t.length===0&&o.length===0)return null;const B=[...e,...t,...o,...I],C=UF(B);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 VmI(g){if(Xo(g).pcb_board.list().length>0)return g;const I=ijt(g);if(!I)return g;const t=I.thickness/2;return[...g.map(B=>{if(B.type==="cad_component"&&B.pcb_component_id){const C=B;if(C.position){const Q=C.position.z??0;return{...C,position:{...C.position,z:Q+t}}}}return B}),I]}var Ejt=X.forwardRef(({circuitJson:g,children:A,autoRotateDisabled:I,clickToInteractEnabled:e,onUserInteraction:t,onCameraControllerReady:o,resolveStaticAsset:B,referenceObject:C,hiddenCadComponentIds:Q},i)=>{const E=NAg(A),n=X.useMemo(()=>VmI(g??E),[g,E]),s=jWt(n),r=X.useMemo(()=>{if(!n)return!1;try{const u=Xo(n).pcb_board.list()[0];return!!u&&u.pcb_board_id==="faux-board"}catch{return!1}},[n]),a=X.useMemo(()=>{if(n)try{const u=Xo(n).pcb_board.list()[0];if(!u)return;const G=Sy(u);return{width:G.width,height:G.height}}catch(u){console.error(u);return}},[n]),c=X.useMemo(()=>{if(n)try{const u=Xo(n).pcb_board.list()[0];if(!u)return;const G=Sy(u);return{x:G.centerX,y:G.centerY}}catch(u){console.error(u);return}},[n]),h=X.useMemo(()=>{if(!n)return;const u=Xo(n).pcb_board.list()[0];if(u)return JSON.stringify({pcbBoardId:u.pcb_board_id,center:c,dimensions:a})},[n,c,a]),l=X.useMemo(()=>WmI({boardDimensions:a,boardCenter:c}),[a,c]),D=AmI(n),{stls:d}=cWt(s),y=Xo(n).cad_component.list().filter(u=>!Q?.has(u.cad_component_id)),w=TmI(n);return q.jsxs(umI,{ref:i,autoRotateDisabled:I,initialCameraPosition:l,clickToInteractEnabled:e,boardDimensions:a,boardCenter:c,cameraSessionScope:h,referenceObject:C,onUserInteraction:t,onCameraControllerReady:o,children:[d.map(({stlData:u,color:G,layerType:m},p)=>q.jsx(tjt,{stlData:u,color:G,opacity:p===0?r?.8:.95:1,layerType:m},`board-${p}`)),q.jsx(Ijt,{circuitJson:n,pcbThickness:D,isFaux:r}),y.map(u=>q.jsx(KAg,{fallback:({error:G})=>q.jsx(RmI,{cad_component:u,error:G}),children:q.jsx(imI,{cad_component:u,circuitJson:n,resolveStaticAsset:B},u.cad_component_id)},u.cad_component_id)),w.map(u=>q.jsx(OmI,{cable:u},u.cad_cable_id))]})}),SyA=new Set,ggg=!1;function njt(g,A,I=2){const e=g.length;SyA.size&&SyA.clear();let t=sjt(g,0,e,I,!0);const o=[];if(!t||t.next===t.prev)return o;let B=0,C=0,Q=0;if(g.length>80*I){B=g[0],C=g[1];let i=B,E=C;for(let n=I;n<e;n+=I){const s=g[n],r=g[n+1];s<B&&(B=s),r<C&&(C=r),s>i&&(i=s),r>E&&(E=r)}Q=Math.max(i-B,E-C),Q=Q!==0?32767/Q:0}return Igg(t,o,B,C,Q),o}function sjt(g,A,I,e,t){let o=null;if(t===Gjt(g,A,I,e)>0)for(let B=A;B<I;B+=e)o=zmI(B/e|0,g[B],g[B+1],o);else for(let B=I-e;B>=A;B-=e)o=zmI(B/e|0,g[B],g[B+1],o);return o&&ogg(o,o.next)&&(SIA(o),o=o.next),o}function fyA(g,A=g){const I=A===g;let e=g,t;do t=!1,e!==e.next&&(SyA.size===0||!SyA.has(e))&&(ogg(e,e.next)||fy(e.prev,e,e.next)===0)?((I||e===A)&&(A=e.prev),ggg=!0,SIA(e),e=e.prev,t=!0):(I||e!==A)&&(e=e.next,t=!I);while(t||e!==A);return A}function Igg(g,A,I,e,t){t&&ljt(g,I,e,t);let o=g,B=!1;for(;g.prev!==g.next;){const C=g.prev,Q=g.next;if(fy(C,g,Q)<0&&(t?rjt(g,I,e,t):ajt(g))){A.push(C.i,g.i,Q.i),SIA(g),g=Q,o=Q;continue}if(g=Q,g===o){if(ggg=!1,g=fyA(g),ggg){o=g;continue}if(!B){g=cjt(g,A),o=g,B=!0;continue}hjt(g,A,I,e,t);break}}}function ajt(g){const A=g.prev,I=g,e=g.next,t=A.x,o=I.x,B=e.x,C=A.y,Q=I.y,i=e.y,E=Math.min(t,o,B),n=Math.min(C,Q,i),s=Math.max(t,o,B),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)&&tgg(t,C,o,Q,B,i,a.x,a.y)&&fy(a.prev,a,a.next)>=0)return!1;a=a.next}return!0}function rjt(g,A,I,e){const t=g.prev,o=g,B=g.next,C=t.x,Q=o.x,i=B.x,E=t.y,n=o.y,s=B.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=egg(r,a,A,I,e),D=egg(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!==B&&!(C===d.x&&E===d.y)&&tgg(C,E,Q,n,i,s,d.x,d.y)&&fy(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!==B&&!(C===y.x&&E===y.y)&&tgg(C,E,Q,n,i,s,y.x,y.y)&&fy(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function cjt(g,A){let I=g,e=!1;do{const t=I.prev,o=I.next.next;jmI(t,I,I.next,o,!1)&&xyA(t,o)&&xyA(o,t)&&(A.push(t.i,I.i,o.i),SIA(I),SIA(I.next),I=g=o,e=!0),I=I.next}while(I!==g);return e?fyA(I):I}function hjt(g,A,I,e,t){let o=g;do{let B=o.next.next;for(;B!==o.prev;){if(o.i!==B.i&&djt(o,B)){let C=ujt(o,B);o=fyA(o,o.next),C=fyA(C,C.next),Igg(o,A,I,e,t),Igg(C,A,I,e,t);return}B=B.next}o=o.next}while(o!==g)}var gS=[],M7=[],d5=new Uint32Array(0),kIA=new Uint32Array(0),MIA=new Uint32Array(256);function ljt(g,A,I,e){let t=g,o=0;do t.z=egg(t.x,t.y,A,I,e),gS[o++]=t,t=t.next;while(t!==g);Djt(o);let B=null;for(let C=0;C<o;C++){const Q=gS[C];Q.prevZ=B,B&&(B.nextZ=Q),B=Q}B.nextZ=null,gS.fill(null,0,o),M7.fill(null,0,o)}function Djt(g){if(g<=32){for(let A=1;A<g;A++){const I=gS[A],e=I.z;let t=A-1;for(;t>=0&&gS[t].z>e;)gS[t+1]=gS[t],t--;gS[t+1]=I}return}d5.length<g&&(d5=new Uint32Array(g),kIA=new Uint32Array(g),M7=new Array(g));for(let A=0;A<g;A++)d5[A]=gS[A].z;RyA(g,gS,d5,M7,kIA,0),RyA(g,M7,kIA,gS,d5,8),RyA(g,gS,d5,M7,kIA,16),RyA(g,M7,kIA,gS,d5,24)}function RyA(g,A,I,e,t,o){MIA.fill(0);for(let C=0;C<g;C++)MIA[I[C]>>>o&255]++;let B=0;for(let C=0;C<256;C++){const Q=MIA[C];MIA[C]=B,B+=Q}for(let C=0;C<g;C++){const Q=I[C],i=MIA[Q>>>o&255]++;e[i]=A[C],t[i]=Q}}function egg(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 tgg(g,A,I,e,t,o,B,C){return(t-B)*(A-C)>=(g-B)*(o-C)&&(g-B)*(e-C)>=(I-B)*(A-C)&&(I-B)*(o-C)>=(t-B)*(e-C)}function djt(g,A){const I=ogg(g,A)&&fy(g.prev,g,g.next)>0&&fy(A.prev,A,A.next)>0;return g.next.i!==A.i&&(I||xyA(g,A)&&xyA(A,g)&&(fy(g.prev,g,A.prev)!==0||fy(g,A.prev,A)!==0))&&!yjt(g,A)&&(I||wjt(g,A))}function fy(g,A,I){return(A.y-g.y)*(I.x-A.x)-(A.x-g.x)*(I.y-A.y)}function ogg(g,A){return g.x===A.x&&g.y===A.y}function jmI(g,A,I,e,t=!0){const o=fy(g,A,I),B=fy(g,A,e),C=fy(I,e,g),Q=fy(I,e,A);return(o>0&&B<0||o<0&&B>0)&&(C>0&&Q<0||C<0&&Q>0)?!0:t?!!(o===0&&NyA(g,I,A)||B===0&&NyA(g,e,A)||C===0&&NyA(I,g,e)||Q===0&&NyA(I,A,e)):!1}function NyA(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 yjt(g,A){const I=Math.min(g.x,A.x),e=Math.max(g.x,A.x),t=Math.min(g.y,A.y),o=Math.max(g.y,A.y);let B=g;do{const C=B.next;if(B.x>e&&C.x>e||B.x<I&&C.x<I||B.y>o&&C.y>o||B.y<t&&C.y<t){B=C;continue}if(B.i!==g.i&&C.i!==g.i&&B.i!==A.i&&C.i!==A.i&&jmI(B,C,g,A))return!0;B=C}while(B!==g);return!1}function xyA(g,A){return fy(g.prev,g,g.next)<0?fy(g,A,g.next)>=0&&fy(g,g.prev,A)>=0:fy(g,A,g.prev)<0||fy(g,g.next,A)<0}function wjt(g,A){let I=g,e=!1;const t=(g.x+A.x)/2,o=(g.y+A.y)/2;do{const B=I.next;I.y>o!=B.y>o&&t<(B.x-I.x)*(o-I.y)/(B.y-I.y)+I.x&&(e=!e),I=B}while(I!==g);return e}function ujt(g,A){const I=Bgg(g.i,g.x,g.y),e=Bgg(A.i,A.x,A.y),t=g.next,o=A.prev;return g.next=A,A.prev=g,I.next=t,t.prev=I,e.next=I,I.prev=e,o.next=e,e.prev=o,e}function zmI(g,A,I,e){const t=Bgg(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 SIA(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 Bgg(g,A,I){return{i:g,x:A,y:I,prev:null,next:null,z:0,prevZ:null,nextZ:null}}function Gjt(g,A,I,e){let t=0;for(let o=A,B=I-e;o<I;o+=e)t+=(g[B]-g[o])*(g[o+1]+g[B+1]),B=o;return t}var y5=1e-7;function XmI(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<y5||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)>y5),e=I[0];if(e&&I.some(C=>Math.abs(C.nx-e.nx)>y5||Math.abs(C.ny-e.ny)>y5))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-y5)throw new Error("Overlapping PCB bend zones are not supported");const t=[...I].reverse(),o=({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},B=({p:C,anchor:Q,direction:i})=>{const E=i?{x:0,y:0,z:0}:o({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=>o({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)=>B({p:C,anchor:Q,direction:!1}),inverseDirection:(C,Q)=>B({p:C,anchor:Q,direction:!0}),point:(C,Q=C)=>o({p:C,anchor:Q,direction:!1}),direction:(C,Q)=>o({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+y5&&Math.min(...E)<i.end-y5)throw new Error(`${Q} intersects PCB bend zone ${i.id}`)}}}}var JR=1e-7;function fIA(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 o of["x","y","z"])I[o]=Math.min(I[o],t[o]),e[o]=Math.max(e[o],t[o]);return{min:I,max:e}}function $mI(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,o=({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)>=-JR||Math.max(...n)<=JR)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>=-JR&&s[r].push(h),d>JR&&y<-JR||d<-JR&&y>JR){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)},B=[];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=>o({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+JR&&s<n.end-JR&&E.some(({p:r})=>{const a=-n.ny*r.x+n.nx*r.y;return a<n.axisMin-JR||a>n.axisMax+JR}))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||B.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:B,boundingBox:fIA(B)}}var mjt=[{x:1,y:0,z:0},{x:0,y:1,z:0},{x:0,y:0,z:1}];function pjt(g,A){const[I,e,t]=[A.x,A.y,A.z].map(C=>C*Math.PI/180),o={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},B={x:Math.cos(e)*o.x+Math.sin(e)*o.z,y:o.y,z:-Math.sin(e)*o.x+Math.cos(e)*o.z};return{x:B.x,y:Math.cos(I)*B.y-Math.sin(I)*B.z,z:Math.sin(I)*B.y+Math.cos(I)*B.z}}function kjt([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 Mjt({cadComponent:g,foldPcbs:A},I){return Sjt({cadComponentPlacement:g,foldPcbs:A},I)}function Sjt({cadComponentPlacement:g,foldPcbs:A},I){if(g.is_on_folded_board===!0===A)return g;const{fold:e,boardCenter:t,flatMount:o}=I,B={x:o.x-t.x,y:o.y-t.y,z:0};e.assertRigid([B],"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,B):e.inversePoint(C,B),E=g.rotation??I.defaultRotation??{x:0,y:0,z:0},n=mjt.map(s=>Q(pjt(s,E),B));return{...g,position:{x:i.x+t.x,y:i.y+t.y,z:i.z},rotation:kjt(n),is_on_folded_board:A}}function fjt(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,o=t?e.filter(Q=>Q.pcb_board_id===t):e.filter(Q=>Q.subcircuit_id&&Q.subcircuit_id===I.subcircuit_id),B=o.length===1?o[0]:!t&&!o.length&&e.length===1?e[0]:void 0;if(!B)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===B.pcb_board_id);return{fold:XmI(C,B.thickness??1.6),boardCenter:B.center,flatMount:I.center,defaultRotation:{x:(g.layer??I.layer)==="bottom"?180:0,y:0,z:0}}}function Rjt(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 o=fjt(t,g);return!o||!o.fold.bends.length&&!t.is_on_folded_board?e:Mjt({cadComponent:t,foldPcbs:A.foldPcbs},o)})}function Njt({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(),o=[],B=({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&&o.push({vertices:[Q,i,E],normal:{x:a.x/c,y:a.y/c,z:a.z/c},pcbFace:n})},C=njt(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]);B({a:{...i,z:I},b:{...E,z:I},c:{...n,z:I},pcbFace:"top"}),B({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];B({a:{...i,z:A},b:{...E,z:A},c:{...E,z:I},pcbFace:"side"}),B({a:{...i,z:A},b:{...E,z:I},c:{...i,z:I},pcbFace:"side"})}return{triangles:o,boundingBox:fIA(o)}}function xjt({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)}))})(),o=A/2+e,B=o+g.thickness,C=Njt({outline:t,bottom:g.layer==="top"?o:-B,top:g.layer==="top"?B:-o});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:fIA(i)}}var Fjt=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 Ujt(g,A,I,e,t){let o,B=null;if(I.outline&&I.outline.length>=3){let C=I.outline.map(i=>[i.x,i.y]);Fjt(C)&&(C=C.reverse());const Q=A.ofPolygons([C]);t.push(Q),B=Q,o=g.extrude(Q,e,void 0,void 0,void 0,!0),t.push(o)}else I.outline&&I.outline.length>0&&console.warn("Board outline has fewer than 3 points, falling back to rectangular board."),o=g.cube([I.width,I.height,e],!0),t.push(o),o=o.translate([I.center.x,I.center.y,0]),t.push(o);return{boardOp:o,outlineCrossSection:B}}var Jjt=64;function w5({Manifold:g,width:A,height:I,thickness:e,borderRadius:t}){const o=SmI(A,I,t);if(o<=0)return g.cube([A,I,e],!0);const B=[],C=A-2*o,Q=I-2*o;return C>0&&B.push(g.cube([C,I,e],!0)),Q>0&&B.push(g.cube([A,Q,e],!0)),[[A/2-o,I/2-o],[-A/2+o,I/2-o],[-A/2+o,-I/2+o],[A/2-o,-I/2+o]].forEach(([E,n])=>{B.push(g.cylinder(e,o,o,Jjt,!0).translate([E,n,0]))}),g.union(B)}var Pjt=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 Kjt(g,A,I,e,t){const o=[],B=Xo(I).pcb_cutout.list();for(const C of B){let Q;const i=e*1.5;switch(C.shape){case"rect":{const s=d3(C);if(typeof s=="number"&&s>0?Q=w5({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,Nd,!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]);Pjt(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&&o.push(Q)}return{cutoutOps:o}}function ApI({Manifold:g,x:A,y:I,diameter:e,thickness:t,segments:o=32}){return g.cylinder(t*1.2,e/2,e/2,o,!0).translate([A,I,0])}function gpI({Manifold:g,x:A,y:I,holeDiameter:e,thickness:t,zOffset:o=.001,segments:B=32}){const C=e/2+o;return g.cylinder(t*1.2,C,C,B,!0).translate([A,I,0])}function Ljt(g,A,I,e,t){const o=[],B=Xo(I).pcb_hole.list(),C=(E,n,s)=>{const r=w5({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 B){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=ApI({Manifold:g,x:s,y:r,diameter:E.hole_diameter,thickness:e,segments:Nd}),o.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,Nd),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),o.push(d)}}return{nonPlatedHoleBoardDrills:o}}function wx(g){const A=new Yn;if(A.setAttribute("position",new ZB(g.vertProperties,3)),A.setIndex(new yvA(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 RIA=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},FyA=(g,A,I)=>{const e=[];for(let t=0;t<I;t++){const o=2*Math.PI*t/I;e.push([g/2*Math.cos(o),A/2*Math.sin(o)])}return e},u5=new oo(...$E.copper),UyA=.05,NIA=.003,xIA=5e-4,FIA=.004;function Yjt(g,A,I,e,t,o){const B=[],C=Xo(I).pcb_plated_hole.list(),Q=[],i=[],E=(a,c,h)=>{const l=w5({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]);RIA(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,OB),m=Math.max(G/2,OB/2);u=g.cylinder(c,m,m,Nd,!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,OB),k=Math.max(m+h,OB);if(d==="oval"){let S=FyA(p,k,Nd);RIA(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=w5({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*(NIA+xIA+FIA),OB);if(a.shape==="circle"){const l=gpI({Manifold:g,x:a.x,y:a.y,holeDiameter:a.hole_diameter*1.02,thickness:e,zOffset:FR,segments:Nd});t.push(l),B.push(l);const D=h,d=g.cylinder(D,a.outer_diameter/2,a.outer_diameter/2,Nd,!0);t.push(d);const y=g.cylinder(D*1.05,a.hole_diameter/2,a.hole_diameter/2,Nd,!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(o){const p=g.intersection([u,o]);t.push(p),G=p}i.push(G);const m=wx(G.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:m,color:u5})}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*FR,G=D+2*FR,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),B.push(k);const S=h,R=E(y,w,S),x=E(l,D,S*1.05);let N=R.subtract(x);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 K=U;if(o){const H=g.intersection([U,o]);t.push(H),K=H}i.push(K);const _=wx(K.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:_,color:u5})}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=d3(a),m=NIA,p=l+2*FR,k=D+2*FR,S=e*1.2,x=E(p,k,S).translate([d,y,0]).translate([a.x,a.y,0]);t.push(x),B.push(x);const N=w5({Manifold:g,width:w,height:u,thickness:Math.max(e-2*(m+xIA+FIA),OB),borderRadius:G});t.push(N);const U=E(l,D,e*.8).translate([d,y,0]);t.push(U);const K=g.union([N,U]);t.push(K);const _=E(Math.max(l-2*UyA,.01),Math.max(D-2*UyA,.01),e*1.2).translate([d,y,0]);t.push(_);const H=K.subtract(_);t.push(H);const T=H.translate([a.x,a.y,0]);t.push(T);let j=T;if(o){const O=g.intersection([T,o]);t.push(O),j=O}i.push(j);const W=wx(j.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:W,color:u5})}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=d3(a),m=NIA,p=l+2*FR,k=D+2*FR,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 x=R.translate([a.x,a.y,0]);t.push(x),B.push(x);let N=w5({Manifold:g,width:w,height:u,thickness:Math.max(e-2*(m+xIA+FIA),OB),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 K=g.union([N,U]);t.push(K);let _=E(Math.max(l-2*UyA,.01),Math.max(D-2*UyA,.01),e*1.2).translate([d,y,0]);if(a.hole_ccw_rotation){const O=_.rotate([0,0,a.hole_ccw_rotation]);t.push(O),_=O}t.push(_);const H=K.subtract(_);t.push(H);const T=H.translate([a.x,a.y,0]);t.push(T);let j=T;if(o){const O=g.intersection([T,o]);t.push(O),j=O}i.push(j);const W=wx(j.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:W,color:u5})}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*OB});if(!D)return;const d=D.translate([a.x,a.y,0]);t.push(d),B.push(d);const w=Math.max(e-2*(NIA+xIA+FIA),OB),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*OB})||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(o){const N=g.intersection([S,o]);t.push(N),R=N}i.push(R);const x=wx(R.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:x,color:u5})}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*FR,u=D+2*FR,G=e*1.2;let m=FyA(w,u,Nd);RIA(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 gA=k.rotate([0,0,a.ccw_rotation]);t.push(gA),k=gA}const S=k.translate([a.x,a.y,0]);t.push(S),B.push(S);const R=h;let x=FyA(d,y,Nd);RIA(x)&&(x=x.reverse());const N=A.ofPolygons([x]);t.push(N);const U=g.extrude(N,R,0,0,[1,1],!0);t.push(U);let K=FyA(l,D,Nd);RIA(K)&&(K=K.reverse());const _=A.ofPolygons([K]);t.push(_);const H=g.extrude(_,R*1.05,0,0,[1,1],!0);t.push(H);let T=U.subtract(H);if(t.push(T),a.ccw_rotation){const gA=T.rotate([0,0,a.ccw_rotation]);t.push(gA),T=gA}const j=T.translate([a.x,a.y,0]);t.push(j);let W=j;if(o){const gA=g.intersection([j,o]);t.push(gA),W=gA}i.push(W);const O=wx(W.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:O,color:u5})}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=ApI({Manifold:g,x:a.x+l,y:a.y+D,diameter:a.hole_diameter,thickness:e,segments:Nd});t.push(d),B.push(d);const y=a.rect_pad_width??a.hole_diameter,w=a.rect_pad_height??a.hole_diameter,u=d3(a),G=NIA,m=a.hole_diameter/2,p=w5({Manifold:g,width:y,height:w,thickness:Math.max(e-2*(G+xIA+FIA),OB),borderRadius:u});t.push(p);const k=g.cylinder(e*.8,m,m,Nd,!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-OB,.01),Math.max(m-OB,.01),Nd,!0).translate([l,D,0]);t.push(R);const x=S.subtract(R);t.push(x);const N=x.translate([a.x,a.y,0]);t.push(N);let U=N;if(o){const _=g.intersection([N,o]);t.push(_),U=_}i.push(U);const K=wx(U.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:K,color:u5})}});let r;return i.length>0&&(r=g.union(i),t.push(r)),{platedHoleBoardDrills:B,platedHoleCopperGeoms:Q,platedHoleSubtractOp:r}}function _jt({Manifold:g,x:A,y:I,outerDiameter:e,holeDiameter:t,thickness:o,zOffset:B=.001,segments:C=32}){const Q=B;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(o,i,-1,C,!0),s=o+2*B,r=g.cylinder(s,t/2,-1,C,!0);return n.subtract(r).translate([A,I,0])}var bjt=new oo(...$E.copper);function Hjt(g,A,I,e,t,o=[]){const B=[],C=VAg(A),Q=[],i=[];C.forEach((n,s)=>{let r;if(typeof n.hole_diameter=="number"){const a=gpI({Manifold:g,x:n.x,y:n.y,holeDiameter:n.hole_diameter,thickness:I,zOffset:FR,segments:Nd});e.push(a),B.push(a),r=a}if(typeof n.outer_diameter=="number"&&typeof n.hole_diameter=="number"){const a=_jt({Manifold:g,x:n.x,y:n.y,outerDiameter:n.outer_diameter,holeDiameter:n.hole_diameter,thickness:I,zOffset:FR,segments:Nd});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=[...o,...B].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:wx(h.getMesh()),color:bjt})}return{viaBoardDrills:B,viaCopperGeoms:Q}}var vjt=(g,A,I)=>{const e=vmI(I),[t,o]=X.useState(null),[B,C]=X.useState(null),[Q,i]=X.useState(null),[E,n]=X.useState(!0),s=X.useRef([]),r=X.useMemo(()=>{const l=A.filter(y=>y.type==="pcb_panel"),D=Xo(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=X.useMemo(()=>{const l=Xo(A).pcb_board.list();return l.length>0&&l[0].pcb_board_id==="faux-board"},[A]),c=X.useMemo(()=>r?qmI(r,O2):O2,[r]);X.useEffect(()=>{if(!g||!r){o(null),C(null),n(!1);return}if((r.width===0||!r.width)&&(r.height===0||!r.height)&&(!r.outline||r.outline.length<3)){o({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}=Ujt(l,D,r,u,s.current);let p=G;const S=u+2*1;let R=null;const x=.01;if(m){let gA=m;if(x>0){const IA=m.offset(x);s.current.push(IA),gA=IA}const tA=l.extrude(gA,S,void 0,void 0,void 0,!0);s.current.push(tA),R=tA}else{const gA=(r.width||0)+2*x,tA=(r.height||0)+2*x,IA=l.cube([gA,tA,S],!0);s.current.push(IA);const QA=IA.translate([r.center.x,r.center.y,0]);s.current.push(QA),R=QA}const N=[];let U=null;const{nonPlatedHoleBoardDrills:K}=Ljt(l,D,A,u,s.current);N.push(...K);const{platedHoleBoardDrills:_,platedHoleCopperGeoms:H,platedHoleSubtractOp:T}=Yjt(l,D,A,u,s.current,R);N.push(..._),w.platedHoles=H;const{viaBoardDrills:j,viaCopperGeoms:W}=Hjt(l,A,u,s.current,R,N);if(N.push(...j),w.vias=W,N.length>0){U=l.union(N),s.current.push(U);const gA=T?l.union([U,T]):U;s.current.push(gA);const tA=p.subtract(gA);if(s.current.push(tA),p=tA,T){const IA=T.subtract(U);s.current.push(IA);const QA=IA.getMesh(),nA=wx(QA);w.platedHoles=[{key:"plated-holes-union",geometry:nA,color:new oo($E.copper[0],$E.copper[1],$E.copper[2])}]}}const{cutoutOps:O}=Kjt(l,D,A,u,s.current);if(O.length>0){const gA=l.union(O);s.current.push(gA);const tA=p.subtract(gA);s.current.push(tA),p=tA}if(y=p,y){const gA=y.getMesh(),tA=wx(gA);w.board={geometry:tA,color:qAg(r),material:r.material,isFaux:a}}o(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."),o(null)}finally{n(!1)}return()=>{s.current.forEach(d),s.current=[]}},[g,A,r]);const h=X.useMemo(()=>!r||!c?null:KmI({circuitJson:A,boardData:r,traceTextureResolution:c,visibility:e}),[A,r,c,e]);return{geoms:t,textures:h,pcbThickness:B,error:Q,isLoading:E,boardData:r,isFauxBoard:a}};function IpI(g,A){g.updateMatrix();const I=g.geometry.index?g.geometry.toNonIndexed():g.geometry,e=I.getAttribute("position"),t=I.getAttribute("uv"),o=[];for(let B=0;B<e.count;B+=3){const C=[0,1,2].map(s=>{const r=new BI().fromBufferAttribute(e,B+s).applyMatrix4(g.matrix);return{x:r.x-A.x,y:r.y-A.y,z:r.z}}),[Q,i,E]=C,n=new BI(i.x-Q.x,i.y-Q.y,i.z-Q.z).cross(new BI(E.x-Q.x,E.y-Q.y,E.z-Q.z)).normalize();o.push({vertices:C,normal:{x:n.x,y:n.y,z:n.z},...t?{uvs:[0,1,2].map(s=>({u:t.getX(B+s),v:t.getY(B+s)}))}:{}})}return I!==g.geometry&&I.dispose(),{triangles:o,boundingBox:fIA(o)}}function epI(g,A){const I=[],e=[],t=[];for(const B of g.triangles)B.vertices.forEach((C,Q)=>{I.push(C.x+A.x,C.y+A.y,C.z),e.push(B.normal.x,B.normal.y,B.normal.z),t.push(B.uvs?.[Q]?.u??0,B.uvs?.[Q]?.v??0)});const o=new Yn;return o.setAttribute("position",new ZB(I,3)),o.setAttribute("normal",new ZB(e,3)),o.setAttribute("uv",new ZB(t,2)),o.computeBoundingBox(),o.computeBoundingSphere(),o}function tpI(g,A,I){const e=g.clone();return e.geometry=epI(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 qjt(g,A,I,e){const t=I.filter(a=>a.type==="pcb_board"),o=I.filter(a=>a.type==="pcb_bend"),B=I.filter(a=>a.type==="pcb_stiffener");if(!o.length&&!B.length)return{geometryMeshes:g,textureMeshes:A};const C=t[0];if(!C||t.length!==1||I.some(a=>a.type==="pcb_panel")||[...o,...B].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?XmI(o,C.thickness??1.6):void 0,i=g.find(a=>a.name==="board-geom"),E=i?IpI(i,C.center):void 0,n=Q?g.map(a=>tpI(a,$mI(IpI(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 BI(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=tpI(a,$mI({triangles:D,boundingBox:fIA(D)},Q),C);return a.geometry.dispose(),d}):A;for(const a of B){const c=new Ko(epI(xjt({stiffener:a,boardThickness:C.thickness??1.6,fold:Q}),C.center),new Hs({color:a.material==="fr4"?"#879568":a.material==="polyimide"?"#bd7f27":"#b8bdc4",side:Sl}));c.name="board-stiffener",AS(c),n.push(c)}const r=new pm;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 Tjt=Sl,Zjt=({material:g,color:A,side:I=Tjt,isFaux:e=!1})=>g==="fr4"?new OM({color:A,side:I,metalness:0,roughness:.48,specularIntensity:.3,ior:1.45,sheen:0,clearcoat:.16,clearcoatRoughness:.3,transparent:e,opacity:e?dyA:1,flatShading:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}):new Hs({color:A,side:I,flatShading:!0,metalness:.1,roughness:.8,transparent:!0,opacity:e?dyA:.9,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});function Ojt(g){const A=[];if(!g)return A;if(g.board?.geometry){const e=new Ko(g.board.geometry,Zjt({material:g.board.material,color:g.board.color,side:Sl,isFaux:g.board.isFaux}));e.name="board-geom",AS(e,{castShadow:!1,receiveShadow:!0}),A.push(e)}const I=e=>{if(e)for(const t of e){const o=new Ko(t.geometry,new Hs({color:t.color,side:Sl,flatShading:!0}));o.name=t.key,AS(o),A.push(o)}};return I(g.platedHoles),I(g.vias),A}var JyA;function Wjt(){return JyA||(JyA=(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(dIA("manifold-3d","3.2.1","manifold.js"))).default)();return I.setup(),window.ManifoldModule=I,I})().catch(g=>{throw JyA=void 0,g})),JyA}var Vjt=({geometryMeshes:g,textureMeshes:A})=>{const{rootObject:I}=RD(),{visibility:e}=l5(),t=o=>{o.geometry.dispose();const B=Array.isArray(o.material)?o.material:[o.material];for(const C of B){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 $r&&n.dispose()}C.dispose()}};return X.useEffect(()=>{if(I){for(const o of g){let B=!0;o.name==="board-geom"||o.name==="board-stiffener"?B=e.boardBody:(o.name.includes("plated_hole")||o.name.includes("via"))&&(B=e.topCopper||e.bottomCopper),B&&I.add(o)}return()=>{for(const o of g)o.parent===I&&I.remove(o),t(o)}}},[I,g,e]),X.useEffect(()=>{if(I){for(const o of A)I.add(o);return()=>{for(const o of A)o.parent===I&&I.remove(o),t(o)}}},[I,A]),null},jjt=({circuitJson:g,foldPcbs:A,autoRotateDisabled:I,clickToInteractEnabled:e,onUserInteraction:t,children:o,onCameraControllerReady:B,resolveStaticAsset:C,referenceObject:Q,hiddenCadComponentIds:i})=>{const E=NAg(o),n=X.useMemo(()=>VmI(g??E),[g,E]),[s,r]=X.useState(null),[a,c]=X.useState(null),{visibility:h}=l5();X.useEffect(()=>{let U=!0;return Wjt().then(K=>{U&&r(K)}).catch(K=>{U&&(console.error("Failed to initialize Manifold:",K),c(`Failed to initialize Manifold: ${K instanceof Error?K.message:"Unknown error"}`))}),()=>{U=!1}},[]);const{geoms:l,textures:D,pcbThickness:d,error:y,isLoading:w,boardData:u,isFauxBoard:G}=vjt(s,n,h),m=X.useMemo(()=>{try{const U=jGI(n,A),K=Rjt(n,{foldPcbs:U});return{...qjt(Ojt(l),XVt(D,u,d,G),n,U),posedJson:K,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=X.useMemo(()=>Xo(m.posedJson).cad_component.list().filter(U=>!i?.has(U.cad_component_id)),[m.posedJson,i]),k=X.useMemo(()=>TmI(m.posedJson),[m.posedJson]),S=X.useMemo(()=>{if(!u)return;const U=Sy(u);return{width:U.width,height:U.height}},[u]),R=X.useMemo(()=>{if(!u)return;const U=Sy(u);return{x:U.centerX,y:U.centerY}},[u]),x=X.useMemo(()=>WmI({boardDimensions:S,boardCenter:R}),[S,R]),N=X.useMemo(()=>{if(u)return JSON.stringify({pcbBoardId:u.pcb_board_id,center:R,dimensions:S})},[u,R,S]);return a?q.jsxs("div",{style:{color:"red",padding:"1em",border:"1px solid red",margin:"1em"},children:["Error: ",a]}):s?y||m.error?q.jsxs("div",{role:"alert",style:{color:"red",padding:"1em",border:"1px solid red",margin:"1em"},children:["Error: ",y??m.error]}):w?q.jsx("div",{style:{padding:"1em"},children:"Processing board geometry..."}):q.jsxs(umI,{initialCameraPosition:x,autoRotateDisabled:I,clickToInteractEnabled:e,boardDimensions:S,boardCenter:R,cameraSessionScope:N,referenceObject:Q,onUserInteraction:t,onCameraControllerReady:B,children:[q.jsx(Vjt,{geometryMeshes:m.geometryMeshes,textureMeshes:m.textureMeshes}),m.bounds&&q.jsx(wmI,{bounds:m.bounds}),p.map(U=>q.jsx(KAg,{fallback:({error:K})=>q.jsx(RmI,{cad_component:U,error:K}),children:q.jsx(imI,{cad_component:U,circuitJson:m.posedJson,resolveStaticAsset:C})},U.cad_component_id)),k.map(U=>q.jsx(OmI,{cable:U},U.cad_cable_id))]}):q.jsx("div",{style:{padding:"1em"},children:"Loading Manifold module..."})},opI=jjt,zjt=Object.defineProperty,S7=(g,A)=>zjt(g,"name",{value:A,configurable:!0}),BpI=!!(typeof window<"u"&&window.document&&window.document.createElement);function mn(g,A,{checkForDefaultPrevented:I=!0}={}){return S7(function(t){if(g?.(t),I===!1||!t||!t.defaultPrevented)return A?.(t)},"handleEvent")}S7(mn,"composeEventHandlers");function Xjt(g){if(!BpI)throw new Error("Cannot access window outside of the DOM");return g?.ownerDocument?.defaultView??window}S7(Xjt,"getOwnerWindow");function Cgg(g){if(!BpI)throw new Error("Cannot access document outside of the DOM");return g?.ownerDocument??document}S7(Cgg,"getOwnerDocument");function CpI(g,A=!1){const{activeElement:I}=Cgg(g);if(!I?.nodeName)return null;if(QpI(I)&&I.contentDocument)return CpI(I.contentDocument.body,A);if(A){const e=I.getAttribute("aria-activedescendant");if(e){const t=Cgg(I).getElementById(e);if(t)return t}}return I}S7(CpI,"getActiveElement");function QpI(g){return g.tagName==="IFRAME"}S7(QpI,"isFrame");var $jt=Object.defineProperty,Qgg=(g,A)=>$jt(g,"name",{value:A,configurable:!0});function igg(g,A){if(typeof g=="function")return g(A);g!=null&&(g.current=A)}Qgg(igg,"setRef");function ipI(...g){return A=>{let I=!1;const e=g.map(t=>{const o=igg(t,A);return!I&&typeof o=="function"&&(I=!0),o});if(I)return()=>{for(let t=0;t<e.length;t++){const o=e[t];typeof o=="function"?o():igg(g[t],null)}}}}Qgg(ipI,"composeRefs");function xd(...g){return X.useCallback(ipI(...g),g)}Qgg(xd,"useComposedRefs");var Azt=Object.defineProperty,W2=(g,A)=>Azt(g,"name",{value:A,configurable:!0});function gzt(g,A){const I=X.createContext(A);I.displayName=g+"Context";const e=W2(o=>{const{children:B,...C}=o,Q=X.useMemo(()=>C,Object.values(C));return q.jsx(I.Provider,{value:Q,children:B})},"Provider");e.displayName=g+"Provider";function t(o,B={}){const{optional:C=!1}=B,Q=X.useContext(I);if(Q)return Q;if(A!==void 0)return A;if(!C)throw new Error(`\`${o}\` must be used within \`${g}\``)}return W2(t,"useContext"),[e,t]}W2(gzt,"createContext");function G5(g,A=[]){let I=[];function e(o,B){const C=X.createContext(B);C.displayName=o+"Context";const Q=I.length;I=[...I,B];const i=W2(n=>{const{scope:s,children:r,...a}=n,c=s?.[g]?.[Q]||C,h=X.useMemo(()=>a,Object.values(a));return q.jsx(c.Provider,{value:h,children:r})},"Provider");i.displayName=o+"Provider";function E(n,s,r={}){const{optional:a=!1}=r,c=s?.[g]?.[Q]||C,h=X.useContext(c);if(h)return h;if(B!==void 0)return B;if(!a)throw new Error(`\`${n}\` must be used within \`${o}\``)}return W2(E,"useContext"),[i,E]}W2(e,"createContext");const t=W2(()=>{const o=I.map(B=>X.createContext(B));return W2(function(C){const Q=C?.[g]||o;return X.useMemo(()=>({[`__scope${g}`]:{...C,[g]:Q}}),[C,Q])},"useScope")},"createScope");return t.scopeName=g,[e,EpI(t,...A)]}W2(G5,"createContextScope");function EpI(...g){const A=g[0];if(g.length===1)return A;const I=W2(()=>{const e=g.map(t=>({useScope:t(),scopeName:t.scopeName}));return W2(function(o){const B=e.reduce((C,{useScope:Q,scopeName:i})=>{const n=Q(o)[`__scope${i}`];return{...C,...n}},{});return X.useMemo(()=>({[`__scope${A.scopeName}`]:B}),[B])},"useComposedScopes")},"createScope");return I.scopeName=A.scopeName,I}W2(EpI,"composeContextScopes");var IS=globalThis?.document?X.useLayoutEffect:()=>{},Izt=Object.defineProperty,ezt=(g,A)=>Izt(g,"name",{value:A,configurable:!0}),npI=fp[" useEffectEvent ".trim().toString()],spI=fp[" useInsertionEffect ".trim().toString()];function apI(g){if(typeof npI=="function")return npI(g);const A=X.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof spI=="function"?spI(()=>{A.current=g}):IS(()=>{A.current=g}),X.useMemo(()=>((...I)=>A.current?.(...I)),[])}ezt(apI,"useEffectEvent");var tzt=Object.defineProperty,UIA=(g,A)=>tzt(g,"name",{value:A,configurable:!0}),ozt=fp[" useInsertionEffect ".trim().toString()]||IS;function PyA({prop:g,defaultProp:A,onChange:I=UIA(()=>{},"onChange"),caller:e}){const[t,o,B]=rpI({defaultProp:A,onChange:I}),C=g!==void 0,Q=C?g:t,i=X.useCallback(E=>{if(C){const n=cpI(E)?E(g):E;n!==g&&B.current?.(n)}else o(E)},[C,g,o,B]);return[Q,i]}UIA(PyA,"useControllableState");function rpI({defaultProp:g,onChange:A}){const[I,e]=X.useState(g),t=X.useRef(I),o=X.useRef(A);return ozt(()=>{o.current=A},[A]),X.useEffect(()=>{t.current!==I&&(o.current?.(I),t.current=I)},[I,t]),[I,e,o]}UIA(rpI,"useUncontrolledState");function cpI(g){return typeof g=="function"}UIA(cpI,"isFunction");var hpI=Symbol("RADIX:SYNC_STATE");function Bzt(g,A,I,e){const{prop:t,defaultProp:o,onChange:B,caller:C}=A,Q=t!==void 0,i=apI(B),E=[{...I,state:o}];e&&E.push(e);const[n,s]=X.useReducer((h,l)=>{if(l.type===hpI)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=X.useRef(r);X.useEffect(()=>{a.current!==r&&(a.current=r,Q||i(r))},[r,a,Q]);const c=X.useMemo(()=>t!==void 0?{...n,state:t}:n,[n,t]);return X.useEffect(()=>{Q&&!Object.is(t,n.state)&&s({type:hpI,state:t})},[t,n.state,Q]),[c,s]}UIA(Bzt,"useControllableStateReducer");var Czt=Object.defineProperty,eS=(g,A)=>Czt(g,"name",{value:A,configurable:!0});function m5(g){const A=X.forwardRef((I,e)=>{let{children:t,...o}=I,B=null,C=!1;const Q=[];t=upI(t),X.Children.forEach(t,s=>{if(ypI(s)){C=!0;const r=s;let a="child"in r.props?r.props.child:r.props.children;for(;Egg(a)&&typeof KyA=="function";)a=KyA(a._payload);B=izt(r,a),Q.push(B?.props?.children)}else Q.push(s)}),B?B=X.cloneElement(B,void 0,Q):!C&&X.Children.count(t)===1&&X.isValidElement(t)&&(B=t);const i=B?dpI(B):void 0,E=xd(e,i);if(!B){if(t||t===0)throw new Error(C?szt(g):nzt(g));return t}const n=DpI(o,B.props??{});return B.type!==X.Fragment&&(n.ref=e?E:i),X.cloneElement(B,n)});return A.displayName=`${g}.Slot`,A}eS(m5,"createSlot");var lpI=Symbol.for("radix.slottable");function Qzt(g){const A=eS(I=>"child"in I?I.children(I.child):I.children,"Slottable");return A.displayName=`${g}.Slottable`,A.__radixId=lpI,A}eS(Qzt,"createSlottable");var izt=eS((g,A)=>"child"in g.props?X.isValidElement(A)?X.cloneElement(A,void 0,g.props.children(A.props.children)):null:X.isValidElement(A)?A:null,"getSlottableElementFromSlottable");function DpI(g,A){const I={...A};for(const e in A){const t=g[e],o=A[e];/^on[A-Z]/.test(e)?t&&o?I[e]=(...C)=>{const Q=o(...C);return t(...C),Q}:t&&(I[e]=t):e==="style"?I[e]={...t,...o}:e==="className"?I[e]=[t,o].filter(Boolean).join(" "):e==="aria-describedby"&&(I[e]=GpI(o,t))}return{...g,...I}}eS(DpI,"mergeProps");function dpI(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)}eS(dpI,"getElementRef");function ypI(g){return X.isValidElement(g)&&typeof g.type=="function"&&"__radixId"in g.type&&g.type.__radixId===lpI}eS(ypI,"isSlottable");var Ezt=Symbol.for("react.lazy");function Egg(g){return g!=null&&typeof g=="object"&&"$$typeof"in g&&g.$$typeof===Ezt&&"_payload"in g&&wpI(g._payload)}eS(Egg,"isLazyComponent");function wpI(g){return typeof g=="object"&&g!==null&&"then"in g}eS(wpI,"isPromiseLike");function upI(g){let A=g;for(;Egg(A)&&typeof KyA=="function";)A=KyA(A._payload);return A}eS(upI,"useUnwrappedLazy");function GpI(...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}eS(GpI,"concatAriaDescribedby");var nzt=eS(g=>`${g} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),szt=eS(g=>`${g} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),KyA=fp[" use ".trim().toString()],azt=Object.defineProperty,rzt=(g,A)=>azt(g,"name",{value:A,configurable:!0}),czt=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ux=czt.reduce((g,A)=>{const I=m5(`Primitive.${A}`),e=X.forwardRef((t,o)=>{const{asChild:B,...C}=t,Q=B?I:A;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),q.jsx(Q,{...C,ref:o})});return e.displayName=`Primitive.${A}`,{...g,[A]:e}},{});function ngg(g,A){g&&j1.flushSync(()=>g.dispatchEvent(A))}rzt(ngg,"dispatchDiscreteCustomEvent");var hzt=Object.defineProperty,Fd=(g,A)=>hzt(g,"name",{value:A,configurable:!0});function sgg(g){const A=g+"CollectionProvider",[I,e]=G5(A),[t,o]=I(A,{collectionRef:{current:null},itemMap:new Map}),B=Fd(c=>{const{scope:h,children:l}=c,D=X.useRef(null),d=X.useRef(new Map).current;return q.jsx(t,{scope:h,itemMap:d,collectionRef:D,children:l})},"CollectionProvider");B.displayName=A;const C=g+"CollectionSlot",Q=m5(C),i=X.forwardRef((c,h)=>{const{scope:l,children:D}=c,d=o(C,l),y=xd(h,d.collectionRef);return q.jsx(Q,{ref:y,children:D})});i.displayName=C;const E=g+"CollectionItemSlot",n="data-radix-collection-item",s=m5(E),r=X.forwardRef((c,h)=>{const{scope:l,children:D,...d}=c,y=X.useRef(null),w=xd(h,y),u=o(E,l);return X.useEffect(()=>(u.itemMap.set(y,{ref:y,...d}),()=>{u.itemMap.delete(y)})),q.jsx(s,{[n]:"",ref:w,children:D})});r.displayName=E;function a(c){const h=o(g+"CollectionConsumer",c);return X.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 Fd(a,"useCollection"),[{Provider:B,Slot:i,ItemSlot:r},a,e]}Fd(sgg,"createCollection");var mpI=new WeakMap,LyA=(uS=class extends Map{constructor(I){super(I);xcg(this,Kl);BBA(this,Kl,[...super.keys()]),mpI.set(this,!0)}set(I,e){return mpI.get(this)&&!this.has(I)&&Xn(this,Kl).push(I),super.set(I,e),this}insert(I,e,t){const o=this.has(e),B=o?this.size:this.size+1,C=agg(I),Q=C>=0?Math.min(C,B-1):Math.max(B+C,0);if(o?Xn(this,Kl).indexOf(e)===Q:Q===this.size)return this.set(e,t),this;const i=Xn(this,Kl).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 o=new uS(this);return o.insert(I,e,t),o}before(I){const e=Xn(this,Kl).indexOf(I)-1;if(!(e<0))return this.entryAt(e)}setBefore(I,e,t){const o=Xn(this,Kl).indexOf(I);if(o===-1)return this;const B=Xn(this,Kl).indexOf(e),C=B!==-1&&B<o?o-1:o;return this.insert(C,e,t)}after(I){let e=Xn(this,Kl).indexOf(I);if(e=e===-1||e===this.size-1?-1:e+1,e!==-1)return this.entryAt(e)}setAfter(I,e,t){const o=Xn(this,Kl).indexOf(I);if(o===-1)return this;const B=Xn(this,Kl).indexOf(e),C=B!==-1&&B<=o?o:o+1;return this.insert(C,e,t)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return BBA(this,Kl,[]),super.clear()}delete(I){const e=super.delete(I);return e&&Xn(this,Kl).splice(Xn(this,Kl).indexOf(I),1),e}deleteAt(I){const e=this.keyAt(I);return e!==void 0?this.delete(e):!1}at(I){const e=YyA(Xn(this,Kl),I);if(e!==void 0)return this.get(e)}entryAt(I){const e=YyA(Xn(this,Kl),I);if(e!==void 0)return[e,this.get(e)]}indexOf(I){return Xn(this,Kl).indexOf(I)}keyAt(I){return YyA(Xn(this,Kl),I)}from(I,e){const t=this.indexOf(I);if(t===-1)return;let o=t+e;return o<0&&(o=0),o>=this.size&&(o=this.size-1),this.at(o)}keyFrom(I,e){const t=this.indexOf(I);if(t===-1)return;let o=t+e;return o<0&&(o=0),o>=this.size&&(o=this.size-1),this.keyAt(o)}find(I,e){let t=0;for(const o of this){if(Reflect.apply(I,e,[o,t,this]))return o;t++}}findIndex(I,e){let t=0;for(const o of this){if(Reflect.apply(I,e,[o,t,this]))return t;t++}return-1}filter(I,e){const t=[];let o=0;for(const B of this)Reflect.apply(I,e,[B,o,this])&&t.push(B),o++;return new uS(t)}map(I,e){const t=[];let o=0;for(const B of this)t.push([B[0],Reflect.apply(I,e,[B,o,this])]),o++;return new uS(t)}reduce(...I){const[e,t]=I,o=I.length>1;if(!o&&this.size===0)throw new TypeError("Reduce of empty OrderedDict with no initial value");let B=0,C=t;for(const Q of this)B===0&&!o?C=Q:C=Reflect.apply(e,this,[C,Q,B,this]),B++;return C}reduceRight(...I){const[e,t]=I,o=I.length>1;if(!o&&this.size===0)throw new TypeError("Reduce of empty OrderedDict with no initial value");let B=t;for(let C=this.size-1;C>=0;C--){const Q=this.entryAt(C);C===this.size-1&&!o?B=Q:B=Reflect.apply(e,this,[B,Q,C,this])}return B}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,o]of e)this.set(t,o);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 uS(e)}toReversed(){const I=new uS;for(let e=this.size-1;e>=0;e--){const t=this.keyAt(e),o=this.get(t);I.set(t,o)}return I}toSpliced(...I){const e=[...this.entries()];return e.splice(...I),new uS(e)}slice(I,e){const t=new uS;for(const o of Xn(this,Kl).slice(I,e))t.set(o,this.get(o));return t}every(I,e){let t=0;for(const o of this){if(!Reflect.apply(I,e,[o,t,this]))return!1;t++}return!0}some(I,e){let t=0;for(const o of this){if(Reflect.apply(I,e,[o,t,this]))return!0;t++}return!1}},Kl=new WeakMap,Fd(uS,"OrderedDict"),uS);function YyA(g,A){if("at"in Array.prototype)return Array.prototype.at.call(g,A);const I=ppI(g,A);return I===-1?void 0:g[I]}Fd(YyA,"at");function ppI(g,A){const I=g.length,e=agg(A),t=e>=0?e:I+e;return t<0||t>=I?-1:t}Fd(ppI,"toSafeIndex");function agg(g){return g!==g||g===0?0:Math.trunc(g)}Fd(agg,"toSafeInteger");function lzt(g){const A=g+"CollectionProvider",[I,e]=G5(A),[t,o]=I(A);t.displayName=g+"CollectionStableContextProvider";const[B,C]=I(A);B.displayName=g+"CollectionStatefulContextProvider";const Q=Fd(({state:u,...G})=>u?q.jsx(E,{...G,state:u}):q.jsx(i,{...G}),"CollectionProvider");Q.displayName=A;const i=Fd(u=>{const G=D();return q.jsx(E,{...u,state:G})},"CollectionInit");i.displayName=g+"CollectionInit";const E=Fd(u=>{const{scope:G,children:m,state:p}=u,k=X.useRef(null),[S,R]=X.useState(null),x=xd(k,R),[N,U]=p,K=X.useRef(new LyA),_=X.useCallback(()=>{const H=K.current;return SpI(H)||H.sort(_yA),H},[]);return X.useEffect(()=>{if(!S)return;const H=fpI(()=>{U(T=>{const j=T.toSorted(_yA);return j.some(([O],gA)=>T.keyAt(gA)!==O)?j:T})});return H.observe(S,{childList:!0,subtree:!0}),()=>{H.disconnect()}},[S,U]),q.jsx(t,{scope:G,collectionElementRef:x,collectionElementRefObject:k,getCollection:_,setCollection:U,registryRef:K,children:q.jsx(B,{scope:G,collectionElement:S,collection:N,children:m})})},"CollectionProviderImpl");E.displayName=g+"CollectionProviderImpl";const n=g+"CollectionSlot",s=m5(n),r=X.forwardRef((u,G)=>{const{scope:m,children:p}=u,k=o(n,m),S=xd(G,k.collectionElementRef);return q.jsx(s,{ref:S,children:p})});r.displayName=n;const a=g+"CollectionItemSlot",c="data-radix-collection-item",h=m5(a),l=X.forwardRef((u,G)=>{const{scope:m,children:p,...k}=u,S=X.useRef(null),R=o(a,m),{setCollection:x,registryRef:N}=R,U=X.useRef(k);kpI(U.current,k)||(U.current=k);const K=U.current,_=X.useCallback(j=>{const W=N.current;j?W.set(j,{...U.current,element:j}):S.current&&W.delete(S.current)},[N]),H=xd(G,_,S);IS(()=>{const j=S.current,W=N.current;j&&W.has(j)&&W.set(j,{...K,element:j})},[K,N]);const T=X.useRef(null);return X.useEffect(()=>{const j=S.current,W=T.current;(W?.element??null)===j&&(!j||W?.itemData===K)||(T.current=j?{element:j,itemData:K}:null,x(O=>{const gA=new LyA(O);return W&&W.element!==j&&gA.delete(W.element),j&&gA.set(j,{...K,element:j}),gA.sort(_yA)}))}),X.useEffect(()=>()=>{const j=T.current;T.current=null,j&&x(W=>{if(!W.has(j.element))return W;const O=new LyA(W);return O.delete(j.element),O})},[x]),q.jsx(h,{[c]:"",ref:H,children:p})});l.displayName=a;function D(){return X.useState(new LyA)}Fd(D,"useInitCollection");function d(u){const{collection:G}=C(g+"CollectionConsumer",u);return G}Fd(d,"useCollection");function y(u){const{getCollection:G}=o(g+"CollectionConsumer",u);return G}return Fd(y,"useGetCollection"),[{Provider:Q,Slot:r,ItemSlot:l},{createCollectionScope:e,useCollection:d,useGetCollection:y,useInitCollection:D}]}Fd(lzt,"createCollection");function kpI(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}Fd(kpI,"shallowEqual");function MpI(g,A){return!!(A.compareDocumentPosition(g)&Node.DOCUMENT_POSITION_PRECEDING)}Fd(MpI,"isElementPreceding");function SpI(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}Fd(SpI,"isInDocumentOrder");function _yA(g,A){return!g[1].element||!A[1].element?0:MpI(g[1].element,A[1].element)?-1:1}Fd(_yA,"sortByDocumentPosition");function fpI(g){return new MutationObserver(I=>{for(const e of I)if(e.type==="childList"){g();return}})}Fd(fpI,"getChildListObserver");var Dzt=Object.defineProperty,dzt=(g,A)=>Dzt(g,"name",{value:A,configurable:!0}),yzt={LTR:"ltr"},wzt=X.createContext(void 0);function rgg(g){const A=X.useContext(wzt);return g||A||yzt.LTR}dzt(rgg,"useDirection");var uzt=Object.defineProperty,Gzt=(g,A)=>uzt(g,"name",{value:A,configurable:!0}),RpI=fp[" useInsertionEffect ".trim().toString()];function Gx(g){const A=X.useRef(g);return typeof RpI=="function"?RpI(()=>{A.current=g}):IS(()=>{A.current=g}),X.useMemo(()=>((...I)=>A.current?.(...I)),[])}Gzt(Gx,"useCallbackRef");var mzt=Object.defineProperty,Ry=(g,A)=>mzt(g,"name",{value:A,configurable:!0}),cgg="dismissableLayer.update",pzt="dismissableLayer.pointerDownOutside",kzt="dismissableLayer.focusOutside",NpI,xpI=X.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Mzt=X.forwardRef(Ry(function(A,I){const{disableOutsidePointerEvents:e=!1,deferPointerDownOutside:t=!1,onEscapeKeyDown:o,onPointerDownOutside:B,onFocusOutside:C,onInteractOutside:Q,onDismiss:i,...E}=A,n=X.useContext(xpI),[s,r]=X.useState(null),a=s?.ownerDocument??globalThis?.document,[,c]=X.useState({}),h=xd(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=X.useRef(!1),m=FpI(R=>{B?.(R),Q?.(R),R.defaultPrevented||i?.()},{ownerDocument:a,deferPointerDownOutside:t,isDeferredPointerDownOutsideRef:G,dismissableSurfaces:n.dismissableSurfaces,shouldHandlePointerDownOutside:X.useCallback(R=>{if(!(R instanceof Node))return!1;const x=[...n.branches].some(N=>N.contains(R));return u&&!x},[n.branches,u])}),p=UpI(R=>{if(t&&G.current)return;const x=R.target;[...n.branches].some(U=>U.contains(x))||(C?.(R),Q?.(R),R.defaultPrevented||i?.())},a),k=s?y===l.length-1:!1,S=Gx(R=>{R.key==="Escape"&&(o?.(R),!R.defaultPrevented&&i&&(R.preventDefault(),i()))});return X.useEffect(()=>{if(k)return a.addEventListener("keydown",S,{capture:!0}),()=>a.removeEventListener("keydown",S,{capture:!0})},[a,k,S]),X.useEffect(()=>{if(s)return e&&(n.layersWithOutsidePointerEventsDisabled.size===0&&(NpI=a.body.style.pointerEvents,a.body.style.pointerEvents="none"),n.layersWithOutsidePointerEventsDisabled.add(s)),n.layers.add(s),hgg(),()=>{e&&(n.layersWithOutsidePointerEventsDisabled.delete(s),n.layersWithOutsidePointerEventsDisabled.size===0&&(a.body.style.pointerEvents=NpI))}},[s,a,e,n]),X.useEffect(()=>()=>{s&&(n.layers.delete(s),n.layersWithOutsidePointerEventsDisabled.delete(s),hgg())},[s,n]),X.useEffect(()=>{const R=Ry(()=>c({}),"handleUpdate");return document.addEventListener(cgg,R),()=>document.removeEventListener(cgg,R)},[]),q.jsx(ux.div,{...E,ref:h,style:{pointerEvents:w?u?"auto":"none":void 0,...A.style},onFocusCapture:mn(A.onFocusCapture,p.onFocusCapture),onBlurCapture:mn(A.onBlurCapture,p.onBlurCapture),onPointerDownCapture:mn(A.onPointerDownCapture,m.onPointerDownCapture)})},"DismissableLayer"));function Szt(){const g=X.useContext(xpI),[A,I]=X.useState(null);return X.useEffect(()=>{if(A)return g.dismissableSurfaces.add(A),()=>{g.dismissableSurfaces.delete(A)}},[A,g.dismissableSurfaces]),I}Ry(Szt,"useDismissableLayerSurface");var fzt=Ry(()=>!0,"IS_TRUE");function FpI(g,A){const{ownerDocument:I=globalThis?.document,deferPointerDownOutside:e=!1,isDeferredPointerDownOutsideRef:t,dismissableSurfaces:o,shouldHandlePointerDownOutside:B=fzt}=A,C=Gx(g),Q=X.useRef(!1),i=X.useRef(!1),E=X.useRef(new Map),n=X.useRef(()=>{});return X.useEffect(()=>{function s(){i.current=!1,t.current=!1,E.current.clear()}Ry(s,"resetOutsideInteraction");function r(){return Array.from(E.current.values()).some(Boolean)}Ry(r,"isOutsideInteractionIntercepted");function a(d){if(!i.current)return;const y=d.target;y instanceof Node&&[...o].some(u=>u.contains(y))||E.current.set(d.type,!0),d.type==="click"&&window.setTimeout(()=>{i.current&&n.current()},0)}Ry(a,"handleInteractionCapture");function c(d){i.current&&E.current.set(d.type,!1)}Ry(c,"handleInteractionBubble");const h=Ry(d=>{if(d.target&&!Q.current){let y=function(){I.removeEventListener("click",n.current);const u=r();s(),u||lgg(pzt,C,w,{discrete:!0})};if(Ry(y,"handleAndDispatchPointerDownOutsideEvent"),!B(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,o,B]),{onPointerDownCapture:Ry(()=>Q.current=!0,"onPointerDownCapture")}}Ry(FpI,"usePointerDownOutside");function UpI(g,A=globalThis?.document){const I=Gx(g),e=X.useRef(!1);return X.useEffect(()=>{const t=Ry(o=>{o.target&&!e.current&&lgg(kzt,I,{originalEvent:o},{discrete:!1})},"handleFocus");return A.addEventListener("focusin",t),()=>A.removeEventListener("focusin",t)},[A,I]),{onFocusCapture:Ry(()=>e.current=!0,"onFocusCapture"),onBlurCapture:Ry(()=>e.current=!1,"onBlurCapture")}}Ry(UpI,"useFocusOutside");function hgg(){const g=new CustomEvent(cgg);document.dispatchEvent(g)}Ry(hgg,"dispatchUpdate");function lgg(g,A,I,{discrete:e}){const t=I.originalEvent.target,o=new CustomEvent(g,{bubbles:!1,cancelable:!0,detail:I});A&&t.addEventListener(g,A,{once:!0}),e?ngg(t,o):t.dispatchEvent(o)}Ry(lgg,"handleAndDispatchCustomEvent");var Rzt=Object.defineProperty,Dgg=(g,A)=>Rzt(g,"name",{value:A,configurable:!0}),byA=0,f7=null;function Nzt(g){return dgg(),g.children}Dgg(Nzt,"FocusGuards");function dgg(){X.useEffect(()=>{f7||(f7={start:ygg(),end:ygg()});const{start:g,end:A}=f7;return document.body.firstElementChild!==g&&document.body.insertAdjacentElement("afterbegin",g),document.body.lastElementChild!==A&&document.body.insertAdjacentElement("beforeend",A),byA++,()=>{byA===1&&(f7?.start.remove(),f7?.end.remove(),f7=null),byA=Math.max(0,byA-1)}},[])}Dgg(dgg,"useFocusGuards");function ygg(){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}Dgg(ygg,"createFocusGuard");var xzt=Object.defineProperty,ND=(g,A)=>xzt(g,"name",{value:A,configurable:!0}),wgg="focusScope.autoFocusOnMount",ugg="focusScope.autoFocusOnUnmount",JpI={bubbles:!1,cancelable:!0},Fzt=X.forwardRef(ND(function(A,I){const{loop:e=!1,trapped:t=!1,branches:o,onMountAutoFocus:B,onUnmountAutoFocus:C,...Q}=A,[i,E]=X.useState(null),n=Gx(B),s=Gx(C),r=X.useRef(null),a=xd(I,E),c=X.useRef(o);X.useEffect(()=>{c.current=o});const h=X.useCallback(d=>d?i?.contains(d)?!0:!!c.current?.some(y=>y.contains(d)):!1,[i]),l=X.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;X.useEffect(()=>{if(t){let d=function(G){if(l.paused||!i)return;const m=G.target;h(m)?r.current=m:EJ(r.current,{select:!0})},y=function(G){if(l.paused||!i)return;const m=G.relatedTarget;m!==null&&(h(m)||EJ(r.current,{select:!0}))},w=function(G){if(document.activeElement===document.body)for(const p of G)p.removedNodes.length>0&&EJ(i)};ND(d,"handleFocusIn"),ND(y,"handleFocusOut"),ND(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]),X.useEffect(()=>{if(i){qpI.add(l);const d=document.activeElement;if(!i.contains(d)){const w=new CustomEvent(wgg,JpI);i.addEventListener(wgg,n),i.dispatchEvent(w),w.defaultPrevented||(_pI(ZpI(Ggg(i)),{select:!0}),document.activeElement===d&&EJ(i))}return()=>{i.removeEventListener(wgg,n);const w=i.ownerDocument,u=CustomEvent;setTimeout(()=>{const G=new u(ugg,JpI);i.addEventListener(ugg,s),i.dispatchEvent(G),G.defaultPrevented||EJ(d??w.body,{select:!0}),i.removeEventListener(ugg,s),qpI.remove(l)},0)}}},[i,n,s,l]);const D=X.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]=bpI(u);G&&m?!d.shiftKey&&w===m?(d.preventDefault(),e&&EJ(G,{select:!0})):d.shiftKey&&w===G&&(d.preventDefault(),e&&EJ(m,{select:!0})):w===u&&d.preventDefault()}},[e,t,l.paused]);return q.jsx(ux.div,{tabIndex:-1,...Q,ref:a,onKeyDown:D})},"FocusScope")),PpI=X.createContext(null);function KpI({registry:g,children:A}){return g?q.jsx(PpI.Provider,{value:g,children:A}):A}ND(KpI,"FocusScopeBranchProvider");function LpI(){const[g,A]=X.useState([]),I=X.useMemo(()=>({add:ND(e=>A(t=>t.includes(e)?t:[...t,e]),"add"),remove:ND(e=>A(t=>t.filter(o=>o!==e)),"remove")}),[]);return{nodes:g,registry:I}}ND(LpI,"useFocusScopeBranchRegistry");function YpI(g){const A=X.useContext(PpI);X.useEffect(()=>{if(!(!g||!A))return A.add(g),()=>A.remove(g)},[g,A])}ND(YpI,"useFocusScopeBranch");function _pI(g,{select:A=!1}={}){const I=document.activeElement;for(const e of g)if(EJ(e,{select:A}),document.activeElement!==I)return}ND(_pI,"focusFirst");function bpI(g){const A=Ggg(g),I=mgg(A,g),e=mgg(A.reverse(),g);return[I,e]}ND(bpI,"getTabbableEdges");function Ggg(g){const A=[],e=g.ownerDocument.createTreeWalker(g,NodeFilter.SHOW_ELEMENT,{acceptNode:ND(t=>{const o=t.tagName==="INPUT"&&t.type==="hidden";return t.disabled||t.hidden||o?NodeFilter.FILTER_SKIP:t.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;e.nextNode();)A.push(e.currentNode);return A}ND(Ggg,"getTabbableCandidates");function mgg(g,A){const I=typeof A.checkVisibility=="function"&&A.checkVisibility({checkVisibilityCSS:!0});for(const e of g)if(!(I?!e.checkVisibility({checkVisibilityCSS:!0}):HpI(e,{upTo:A})))return e}ND(mgg,"findVisible");function HpI(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}ND(HpI,"isHidden");function vpI(g){return g.tagName==="INPUT"&&typeof g.select=="function"}ND(vpI,"isSelectableInput");function EJ(g,{select:A=!1}={}){if(g&&g.focus){const e=(g.ownerDocument??document).activeElement;g.focus({preventScroll:!0}),g!==e&&vpI(g)&&A&&g.select()}}ND(EJ,"focus");var qpI=TpI();function TpI(){let g=[];return{add(A){const I=g[0];A!==I&&I?.pause(),g=pgg(g,A),g.unshift(A)},remove(A){g=pgg(g,A),g[0]?.resume()}}}ND(TpI,"createFocusScopesStack");function pgg(g,A){const I=[...g],e=I.indexOf(A);return e!==-1&&I.splice(e,1),I}ND(pgg,"arrayRemove");function ZpI(g){return g.filter(A=>A.tagName!=="A")}ND(ZpI,"removeLinks");var Uzt=Object.defineProperty,Jzt=(g,A)=>Uzt(g,"name",{value:A,configurable:!0}),Pzt=fp[" useId ".trim().toString()]||(()=>{}),Kzt=0;function R7(g){const[A,I]=X.useState(Pzt());return IS(()=>{g||I(e=>e??String(Kzt++))},[g]),g||(A?`radix-${A}`:"")}Jzt(R7,"useId");var Lzt=["top","right","bottom","left"],y3=Math.min,nJ=Math.max,HyA=Math.round,vyA=Math.floor,sJ=g=>({x:g,y:g}),Yzt={left:"right",right:"left",bottom:"top",top:"bottom"};function OpI(g,A,I){return nJ(g,y3(A,I))}function aJ(g,A){return typeof g=="function"?g(A):g}function w3(g){return g.split("-")[0]}function N7(g){return g.split("-")[1]}function kgg(g){return g==="x"?"y":"x"}function Mgg(g){return g==="y"?"height":"width"}function mx(g){const A=g[0];return A==="t"||A==="b"?"y":"x"}function Sgg(g){return kgg(mx(g))}function _zt(g,A,I){I===void 0&&(I=!1);const e=N7(g),t=Sgg(g),o=Mgg(t);let B=t==="x"?e===(I?"end":"start")?"right":"left":e==="start"?"bottom":"top";return A.reference[o]>A.floating[o]&&(B=qyA(B)),[B,qyA(B)]}function bzt(g){const A=qyA(g);return[fgg(g),A,fgg(A)]}function fgg(g){return g.includes("start")?g.replace("start","end"):g.replace("end","start")}var WpI=["left","right"],VpI=["right","left"],Hzt=["top","bottom"],vzt=["bottom","top"];function qzt(g,A,I){switch(g){case"top":case"bottom":return I?A?VpI:WpI:A?WpI:VpI;case"left":case"right":return A?Hzt:vzt;default:return[]}}function Tzt(g,A,I,e){const t=N7(g);let o=qzt(w3(g),I==="start",e);return t&&(o=o.map(B=>B+"-"+t),A&&(o=o.concat(o.map(fgg)))),o}function qyA(g){const A=w3(g);return Yzt[A]+g.slice(A.length)}function Zzt(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 jpI(g){return typeof g!="number"?Zzt(g):{top:g,right:g,bottom:g,left:g}}function TyA(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 zpI(g,A,I){let{reference:e,floating:t}=g;const o=mx(A),B=Sgg(A),C=Mgg(B),Q=w3(A),i=o==="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=N7(A);return a&&(r[B]+=s*(a==="end"?1:-1)*(I&&i?-1:1)),r}async function Ozt(g,A){var I;A===void 0&&(A={});const{x:e,y:t,platform:o,rects:B,elements:C,strategy:Q}=g,{boundary:i="clippingAncestors",rootBoundary:E="viewport",elementContext:n="floating",altBoundary:s=!1,padding:r=0}=aJ(A,g),a=jpI(r),h=C[s?n==="floating"?"reference":"floating":n],l=TyA(await o.getClippingRect({element:(I=await(o.isElement==null?void 0:o.isElement(h)))==null||I?h:h.contextElement||await(o.getDocumentElement==null?void 0:o.getDocumentElement(C.floating)),boundary:i,rootBoundary:E,strategy:Q})),D=n==="floating"?{x:e,y:t,width:B.floating.width,height:B.floating.height}:B.reference,d=await(o.getOffsetParent==null?void 0:o.getOffsetParent(C.floating)),y=await(o.isElement==null?void 0:o.isElement(d))&&await(o.getScale==null?void 0:o.getScale(d))||{x:1,y:1},w=TyA(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.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 Wzt=50,Vzt=async(g,A,I)=>{const{placement:e="bottom",strategy:t="absolute",middleware:o=[],platform:B}=I,C=B.detectOverflow?B:{...B,detectOverflow:Ozt},Q=await(B.isRTL==null?void 0:B.isRTL(A));let i=await B.getElementRects({reference:g,floating:A,strategy:t}),{x:E,y:n}=zpI(i,e,Q),s=e,r=0;const a={};for(let c=0;c<o.length;c++){const h=o[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<Wzt&&(r++,typeof u=="object"&&(u.placement&&(s=u.placement),u.rects&&(i=u.rects===!0?await B.getElementRects({reference:g,floating:A,strategy:t}):u.rects),{x:E,y:n}=zpI(i,s,Q)),c=-1)}return{x:E,y:n,placement:s,strategy:t,middlewareData:a}},jzt=g=>({name:"arrow",options:g,async fn(A){const{x:I,y:e,placement:t,rects:o,platform:B,elements:C,middlewareData:Q}=A,{element:i,padding:E=0}=aJ(g,A)||{};if(i==null)return{};const n=jpI(E),s={x:I,y:e},r=Sgg(t),a=Mgg(r),c=await B.getDimensions(i),h=r==="y",l=h?"top":"left",D=h?"bottom":"right",d=h?"clientHeight":"clientWidth",y=o.reference[a]+o.reference[r]-s[r]-o.floating[a],w=s[r]-o.reference[r],u=await(B.getOffsetParent==null?void 0:B.getOffsetParent(i));let G=u?u[d]:0;(!G||!await(B.isElement==null?void 0:B.isElement(u)))&&(G=C.floating[d]||o.floating[a]);const m=y/2-w/2,p=G/2-c[a]/2-1,k=y3(n[l],p),S=y3(n[D],p),R=G-c[a]-S,x=G/2-c[a]/2+m,N=OpI(k,x,R),U=!Q.arrow&&N7(t)!=null&&x!==N&&o.reference[a]/2-(x<k?k:S)-c[a]/2<0,K=U?x<k?x-k:x-R:0;return{[r]:s[r]+K,data:{[r]:N,centerOffset:x-N-K,...U&&{alignmentOffset:K}},reset:U}}}),zzt=function(g){return g===void 0&&(g={}),{name:"flip",options:g,async fn(A){var I,e;const{placement:t,middlewareData:o,rects:B,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}=aJ(g,A);if((I=o.arrow)!=null&&I.alignmentOffset)return{};const l=w3(t),D=mx(C),d=w3(C)===C,y=await(Q.isRTL==null?void 0:Q.isRTL(i.floating)),w=s||(d||!c?[qyA(C)]:bzt(C)),u=a!=="none";!s&&u&&w.push(...Tzt(C,c,a,y));const G=[C,...w],m=await Q.detectOverflow(A,h),p=[];let k=((e=o.flip)==null?void 0:e.overflows)||[];if(E&&p.push(m[l]),n){const N=_zt(t,B,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=o.flip)==null?void 0:S.index)||0)+1,U=G[N];if(U&&(!(n==="alignment"?D!==mx(U):!1)||k.every(H=>mx(H.placement)===D?H.overflows[0]>0:!0)))return{data:{index:N,overflows:k},reset:{placement:U}};let K=(R=k.filter(_=>_.overflows[0]<=0).sort((_,H)=>_.overflows[1]-H.overflows[1])[0])==null?void 0:R.placement;if(!K)switch(r){case"bestFit":{var x;const _=(x=k.filter(H=>{if(u){const T=mx(H.placement);return T===D||T==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(T=>T>0).reduce((T,j)=>T+j,0)]).sort((H,T)=>H[1]-T[1])[0])==null?void 0:x[0];_&&(K=_);break}case"initialPlacement":K=C;break}if(t!==K)return{reset:{placement:K}}}return{}}}};function XpI(g,A){return{top:g.top-A.height,right:g.right-A.width,bottom:g.bottom-A.height,left:g.left-A.width}}function $pI(g){return Lzt.some(A=>g[A]>=0)}var Xzt=function(g){return g===void 0&&(g={}),{name:"hide",options:g,async fn(A){const{rects:I,platform:e}=A,{strategy:t="referenceHidden",...o}=aJ(g,A);switch(t){case"referenceHidden":{const B=await e.detectOverflow(A,{...o,elementContext:"reference"}),C=XpI(B,I.reference);return{data:{referenceHiddenOffsets:C,referenceHidden:$pI(C)}}}case"escaped":{const B=await e.detectOverflow(A,{...o,altBoundary:!0}),C=XpI(B,I.floating);return{data:{escapedOffsets:C,escaped:$pI(C)}}}default:return{}}}}},AkI=new Set(["left","top"]);async function $zt(g,A){const{placement:I,platform:e,elements:t}=g,o=await(e.isRTL==null?void 0:e.isRTL(t.floating)),B=w3(I),C=N7(I),Q=mx(I)==="y",i=AkI.has(B)?-1:1,E=o&&Q?-1:1,n=aJ(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 AXt=function(g){return g===void 0&&(g=0),{name:"offset",options:g,async fn(A){var I,e;const{x:t,y:o,placement:B,middlewareData:C}=A,Q=await $zt(A,g);return B===((I=C.offset)==null?void 0:I.placement)&&(e=C.arrow)!=null&&e.alignmentOffset?{}:{x:t+Q.x,y:o+Q.y,data:{...Q,placement:B}}}}},gXt=function(g){return g===void 0&&(g={}),{name:"shift",options:g,async fn(A){const{x:I,y:e,placement:t,platform:o}=A,{mainAxis:B=!0,crossAxis:C=!1,limiter:Q={fn:D=>{let{x:d,y}=D;return{x:d,y}}},...i}=aJ(g,A),E={x:I,y:e},n=await o.detectOverflow(A,i),s=mx(t),r=kgg(s);let a=E[r],c=E[s];const h=(D,d)=>OpI(d+n[D==="y"?"top":"left"],d,d-n[D==="y"?"bottom":"right"]);B&&(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]:B,[s]:C}}}}}},IXt=function(g){return g===void 0&&(g={}),{options:g,fn(A){var I,e;const{x:t,y:o,placement:B,rects:C,middlewareData:Q}=A,{offset:i=0,mainAxis:E=!0,crossAxis:n=!0}=aJ(g,A),s={x:t,y:o},r=mx(B),a=kgg(r);let c=s[a],h=s[r];const l=aJ(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=AkI.has(w3(B)),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}}}},eXt=function(g){return g===void 0&&(g={}),{name:"size",options:g,async fn(A){const{placement:I,rects:e,platform:t,elements:o}=A,{apply:B=()=>{},...C}=aJ(g,A),Q=await t.detectOverflow(A,C),i=w3(I),E=N7(I),n=mx(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(o.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=y3(r-Q[a],h),d=y3(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*nJ(Q.left,Q.right):u=r-2*nJ(Q.top,Q.bottom)),await B({...A,availableWidth:G,availableHeight:u});const m=await t.getDimensions(o.floating);return s!==m.width||r!==m.height?{reset:{rects:!0}}:{}}}};function ZyA(){return typeof window<"u"}function x7(g){return gkI(g)?(g.nodeName||"").toLowerCase():"#document"}function ck(g){var A;return(g==null||(A=g.ownerDocument)==null?void 0:A.defaultView)||window}function rJ(g){var A;return(A=(gkI(g)?g.ownerDocument:g.document)||window.document)==null?void 0:A.documentElement}function gkI(g){return ZyA()?g instanceof Node||g instanceof ck(g).Node:!1}function px(g){return ZyA()?g instanceof Element||g instanceof ck(g).Element:!1}function u3(g){return ZyA()?g instanceof HTMLElement||g instanceof ck(g).HTMLElement:!1}function IkI(g){return!ZyA()||typeof ShadowRoot>"u"?!1:g instanceof ShadowRoot||g instanceof ck(g).ShadowRoot}function OyA(g){const{overflow:A,overflowX:I,overflowY:e,display:t}=kx(g);return/auto|scroll|overlay|hidden|clip/.test(A+e+I)&&t!=="inline"&&t!=="contents"}function tXt(g){return/^(table|td|th)$/.test(x7(g))}function WyA(g){try{if(g.matches(":popover-open"))return!0}catch{}try{return g.matches(":modal")}catch{return!1}}var oXt=/transform|translate|scale|rotate|perspective|filter/,BXt=/paint|layout|strict|content/,p5=g=>!!g&&g!=="none",Rgg;function Ngg(g){const A=px(g)?kx(g):g;return p5(A.transform)||p5(A.translate)||p5(A.scale)||p5(A.rotate)||p5(A.perspective)||!xgg()&&(p5(A.backdropFilter)||p5(A.filter))||oXt.test(A.willChange||"")||BXt.test(A.contain||"")}function CXt(g){let A=k5(g);for(;u3(A)&&!JIA(A);){if(Ngg(A))return A;if(WyA(A))return null;A=k5(A)}return null}function xgg(){return Rgg==null&&(Rgg=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Rgg}function JIA(g){return/^(html|body|#document)$/.test(x7(g))}function kx(g){return ck(g).getComputedStyle(g)}function VyA(g){return px(g)?{scrollLeft:g.scrollLeft,scrollTop:g.scrollTop}:{scrollLeft:g.scrollX,scrollTop:g.scrollY}}function k5(g){if(x7(g)==="html")return g;const A=g.assignedSlot||g.parentNode||IkI(g)&&g.host||rJ(g);return IkI(A)?A.host:A}function ekI(g){const A=k5(g);return JIA(A)?(g.ownerDocument||g).body:u3(A)&&OyA(A)?A:ekI(A)}function PIA(g,A,I){var e;A===void 0&&(A=[]),I===void 0&&(I=!0);const t=ekI(g),o=t===((e=g.ownerDocument)==null?void 0:e.body),B=ck(t);if(o){const C=Fgg(B);return A.concat(B,B.visualViewport||[],OyA(t)?t:[],C&&I?PIA(C):[])}else return A.concat(t,PIA(t,[],I))}function Fgg(g){return g.parent&&Object.getPrototypeOf(g.parent)?g.frameElement:null}function tkI(g){const A=kx(g);let I=parseFloat(A.width)||0,e=parseFloat(A.height)||0;const t=u3(g),o=t?g.offsetWidth:I,B=t?g.offsetHeight:e,C=HyA(I)!==o||HyA(e)!==B;return C&&(I=o,e=B),{width:I,height:e,$:C}}function Ugg(g){return px(g)?g:g.contextElement}function F7(g){const A=Ugg(g);if(!u3(A))return sJ(1);const I=A.getBoundingClientRect(),{width:e,height:t,$:o}=tkI(A);let B=(o?HyA(I.width):I.width)/e,C=(o?HyA(I.height):I.height)/t;return(!B||!Number.isFinite(B))&&(B=1),(!C||!Number.isFinite(C))&&(C=1),{x:B,y:C}}var QXt=sJ(0);function okI(g){const A=ck(g);return!xgg()||!A.visualViewport?QXt:{x:A.visualViewport.offsetLeft,y:A.visualViewport.offsetTop}}function iXt(g,A,I){return A===void 0&&(A=!1),!!I&&A&&I===ck(g)}function M5(g,A,I,e){A===void 0&&(A=!1),I===void 0&&(I=!1);const t=g.getBoundingClientRect(),o=Ugg(g);let B=sJ(1);A&&(e?px(e)&&(B=F7(e)):B=F7(g));const C=iXt(o,I,e)?okI(o):sJ(0);let Q=(t.left+C.x)/B.x,i=(t.top+C.y)/B.y,E=t.width/B.x,n=t.height/B.y;if(o&&e){const s=ck(o),r=px(e)?ck(e):e;let a=s,c=Fgg(a);for(;c&&r!==a;){const h=F7(c),l=c.getBoundingClientRect(),D=kx(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=ck(c),c=Fgg(a)}}return TyA({width:E,height:n,x:Q,y:i})}function jyA(g,A){const I=VyA(g).scrollLeft;return A?A.left+I:M5(rJ(g)).left+I}function BkI(g,A){const I=g.getBoundingClientRect(),e=I.left+A.scrollLeft-jyA(g,I),t=I.top+A.scrollTop;return{x:e,y:t}}function EXt(g){let{elements:A,rect:I,offsetParent:e,strategy:t}=g;const o=t==="fixed",B=rJ(e),C=A?WyA(A.floating):!1;if(e===B||C&&o)return I;let Q={scrollLeft:0,scrollTop:0},i=sJ(1);const E=sJ(0),n=u3(e);if((n||!o)&&((x7(e)!=="body"||OyA(B))&&(Q=VyA(e)),n)){const r=M5(e);i=F7(e),E.x=r.x+e.clientLeft,E.y=r.y+e.clientTop}const s=B&&!n&&!o?BkI(B,Q):sJ(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 nXt(g){return g.getClientRects?Array.from(g.getClientRects()):[]}function sXt(g){const A=VyA(g),I=g.ownerDocument.body,e=nJ(g.scrollWidth,g.clientWidth,I.scrollWidth,I.clientWidth),t=nJ(g.scrollHeight,g.clientHeight,I.scrollHeight,I.clientHeight);let o=-A.scrollLeft+jyA(g);const B=-A.scrollTop;return kx(I).direction==="rtl"&&(o+=nJ(g.clientWidth,I.clientWidth)-e),{width:e,height:t,x:o,y:B}}var aXt=25;function rXt(g,A,I){I===void 0&&(I="viewport");const e=I==="layoutViewport",t=ck(g),o=rJ(g),B=t.visualViewport;let C=o.clientWidth,Q=o.clientHeight,i=0,E=0;if(B){const s=!xgg()||A==="fixed";e?s||(i=-B.offsetLeft,E=-B.offsetTop):(C=B.width,Q=B.height,s&&(i=B.offsetLeft,E=B.offsetTop))}if(jyA(o)<=0){const s=o.ownerDocument,r=s.body,a=getComputedStyle(r),c=s.compatMode==="CSS1Compat"&&parseFloat(a.marginLeft)+parseFloat(a.marginRight)||0,h=Math.abs(o.clientWidth-r.clientWidth-c),l=getComputedStyle(o).scrollbarGutter==="stable both-edges"?h/2:h;l<=aXt&&(C-=l)}return{width:C,height:Q,x:i,y:E}}function cXt(g,A){const I=M5(g,!0,A==="fixed"),e=I.top+g.clientTop,t=I.left+g.clientLeft,o=F7(g),B=g.clientWidth*o.x,C=g.clientHeight*o.y,Q=t*o.x,i=e*o.y;return{width:B,height:C,x:Q,y:i}}function CkI(g,A,I){let e;if(A==="viewport"||A==="layoutViewport")e=rXt(g,I,A);else if(A==="document")e=sXt(rJ(g));else if(px(A))e=cXt(A,I);else{const t=okI(g);e={x:A.x-t.x,y:A.y-t.y,width:A.width,height:A.height}}return TyA(e)}function hXt(g,A){const I=A.get(g);if(I)return I;let e=PIA(g,[],!1).filter(C=>px(C)&&x7(C)!=="body"),t=null;const o=kx(g).position==="fixed";let B=o?k5(g):g;for(;px(B)&&!JIA(B);){const C=kx(B),Q=Ngg(B),i=t?t.position:o?"fixed":"";!Q&&(i==="fixed"||i==="absolute"&&C.position==="static")?e=e.filter(n=>n!==B):t=C,B=k5(B)}return A.set(g,e),e}function lXt(g){let{element:A,boundary:I,rootBoundary:e,strategy:t}=g;const B=[...I==="clippingAncestors"?WyA(A)?[]:hXt(A,this._c):[].concat(I),e],C=CkI(A,B[0],t);let Q=C.top,i=C.right,E=C.bottom,n=C.left;for(let s=1;s<B.length;s++){const r=CkI(A,B[s],t);Q=nJ(r.top,Q),i=y3(r.right,i),E=y3(r.bottom,E),n=nJ(r.left,n)}return{width:i-n,height:E-Q,x:n,y:Q}}function DXt(g){const{width:A,height:I}=tkI(g);return{width:A,height:I}}function dXt(g,A,I){const e=u3(A),t=rJ(A),o=I==="fixed",B=M5(g,!0,o,A);let C={scrollLeft:0,scrollTop:0};const Q=sJ(0);if((e||!o)&&((x7(A)!=="body"||OyA(t))&&(C=VyA(A)),e)){const s=M5(A,!0,o,A);Q.x=s.x+A.clientLeft,Q.y=s.y+A.clientTop}!e&&t&&(Q.x=jyA(t));const i=t&&!e&&!o?BkI(t,C):sJ(0),E=B.left+C.scrollLeft-Q.x-i.x,n=B.top+C.scrollTop-Q.y-i.y;return{x:E,y:n,width:B.width,height:B.height}}function Jgg(g){return kx(g).position==="static"}function QkI(g,A){if(!u3(g)||kx(g).position==="fixed")return null;if(A)return A(g);let I=g.offsetParent;return rJ(g)===I&&(I=I.ownerDocument.body),I}function ikI(g,A){const I=ck(g);if(WyA(g))return I;if(!u3(g)){let t=k5(g);for(;t&&!JIA(t);){if(px(t)&&!Jgg(t))return t;t=k5(t)}return I}let e=QkI(g,A);for(;e&&tXt(e)&&Jgg(e);)e=QkI(e,A);return e&&JIA(e)&&Jgg(e)&&!Ngg(e)?I:e||CXt(g)||I}var yXt=async function(g){const A=this.getOffsetParent||ikI,I=this.getDimensions,e=await I(g.floating);return{reference:dXt(g.reference,await A(g.floating),g.strategy),floating:{x:0,y:0,width:e.width,height:e.height}}};function wXt(g){return kx(g).direction==="rtl"}var uXt={convertOffsetParentRelativeRectToViewportRelativeRect:EXt,getDocumentElement:rJ,getClippingRect:lXt,getOffsetParent:ikI,getElementRects:yXt,getClientRects:nXt,getDimensions:DXt,getScale:F7,isElement:px,isRTL:wXt};function EkI(g,A){return g.x===A.x&&g.y===A.y&&g.width===A.width&&g.height===A.height}function GXt(g,A,I){let e=null,t;const o=rJ(g);function B(){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),B();const s=g.getBoundingClientRect(),{left:r,top:a,width:c,height:h}=s;if(E||A(),!c||!h)return;const l=vyA(a),D=vyA(o.clientWidth-(r+c)),d=vyA(o.clientHeight-(a+h)),y=vyA(r),u={rootMargin:-l+"px "+-D+"px "+-d+"px "+-y+"px",threshold:nJ(0,y3(1,n))||1};let G=!0;function m(p){const k=p[0].intersectionRatio;if(!EkI(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:o.ownerDocument})}catch{e=new IntersectionObserver(m,u)}e.observe(g)}const Q=ck(g),i=()=>C(I);return Q.addEventListener("resize",i),C(!0),()=>{Q.removeEventListener("resize",i),B()}}function mXt(g,A,I,e){e===void 0&&(e={});const{ancestorScroll:t=!0,ancestorResize:o=!0,elementResize:B=typeof ResizeObserver=="function",layoutShift:C=typeof IntersectionObserver=="function",animationFrame:Q=!1}=e,i=Ugg(g),E=t||o?[...i?PIA(i):[],...A?PIA(A):[]]:[];E.forEach(l=>{t&&l.addEventListener("scroll",I),o&&l.addEventListener("resize",I)});const n=i&&C?GXt(i,I,o):null;let s=-1,r=null;B&&(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?M5(g):null;Q&&h();function h(){const l=M5(g);c&&!EkI(c,l)&&I(),c=l,a=requestAnimationFrame(h)}return I(),()=>{var l;E.forEach(D=>{t&&D.removeEventListener("scroll",I),o&&D.removeEventListener("resize",I)}),n?.(),(l=r)==null||l.disconnect(),r=null,Q&&cancelAnimationFrame(a)}}var pXt=AXt,kXt=gXt,MXt=zzt,SXt=eXt,fXt=Xzt,nkI=jzt,RXt=IXt,NXt=(g,A,I)=>{const e=new Map,t=I??{},o={...uXt,...t.platform,_c:e};return Vzt(g,A,{...t,platform:o})},xXt=typeof document<"u",FXt=function(){},zyA=xXt?X.useLayoutEffect:FXt;function XyA(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(!XyA(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 o=t[e];if(!(o==="_owner"&&g.$$typeof)&&!XyA(g[o],A[o]))return!1}return!0}return g!==g&&A!==A}function skI(g){return typeof window>"u"?1:(g.ownerDocument.defaultView||window).devicePixelRatio||1}function akI(g,A){const I=skI(g);return Math.round(A*I)/I}function Pgg(g){const A=X.useRef(g);return zyA(()=>{A.current=g}),A}function UXt(g){g===void 0&&(g={});const{placement:A="bottom",strategy:I="absolute",middleware:e=[],platform:t,elements:{reference:o,floating:B}={},transform:C=!0,whileElementsMounted:Q,open:i}=g,[E,n]=X.useState({x:0,y:0,strategy:I,placement:A,middlewareData:{},isPositioned:!1}),[s,r]=X.useState(e);XyA(s,e)||r(e);const[a,c]=X.useState(null),[h,l]=X.useState(null),D=X.useCallback(H=>{H!==u.current&&(u.current=H,c(H))},[]),d=X.useCallback(H=>{H!==G.current&&(G.current=H,l(H))},[]),y=o||a,w=B||h,u=X.useRef(null),G=X.useRef(null),m=X.useRef(E),p=Q!=null,k=Pgg(Q),S=Pgg(t),R=Pgg(i),x=X.useCallback(()=>{if(!u.current||!G.current)return;const H={placement:A,strategy:I,middleware:s};S.current&&(H.platform=S.current),NXt(u.current,G.current,H).then(T=>{const j={...T,isPositioned:R.current!==!1};N.current&&!XyA(m.current,j)&&(m.current=j,j1.flushSync(()=>{n(j)}))})},[s,A,I,S,R]);zyA(()=>{i===!1&&m.current.isPositioned&&(m.current.isPositioned=!1,n(H=>({...H,isPositioned:!1})))},[i]);const N=X.useRef(!1);zyA(()=>(N.current=!0,()=>{N.current=!1}),[]),zyA(()=>{if(y&&(u.current=y),w&&(G.current=w),y&&w){if(k.current)return k.current(y,w,x);x()}},[y,w,x,k,p]);const U=X.useMemo(()=>({reference:u,floating:G,setReference:D,setFloating:d}),[D,d]),K=X.useMemo(()=>({reference:y,floating:w}),[y,w]),_=X.useMemo(()=>{const H={position:I,left:0,top:0};if(!K.floating)return H;const T=akI(K.floating,E.x),j=akI(K.floating,E.y);return C?{...H,transform:"translate("+T+"px, "+j+"px)",...skI(K.floating)>=1.5&&{willChange:"transform"}}:{position:I,left:T,top:j}},[I,C,K.floating,E.x,E.y]);return X.useMemo(()=>({...E,update:x,refs:U,elements:K,floatingStyles:_}),[E,x,U,K,_])}var JXt=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?nkI({element:e.current,padding:t}).fn(I):{}:e?nkI({element:e,padding:t}).fn(I):{}}}},PXt=(g,A)=>{const I=pXt(g);return{name:I.name,fn:I.fn,options:[g,A]}},KXt=(g,A)=>{const I=kXt(g);return{name:I.name,fn:I.fn,options:[g,A]}},LXt=(g,A)=>({fn:RXt(g).fn,options:[g,A]}),YXt=(g,A)=>{const I=MXt(g);return{name:I.name,fn:I.fn,options:[g,A]}},_Xt=(g,A)=>{const I=SXt(g);return{name:I.name,fn:I.fn,options:[g,A]}},bXt=(g,A)=>{const I=fXt(g);return{name:I.name,fn:I.fn,options:[g,A]}},HXt=(g,A)=>{const I=JXt(g);return{name:I.name,fn:I.fn,options:[g,A]}},vXt=Object.defineProperty,qXt=(g,A)=>vXt(g,"name",{value:A,configurable:!0});function rkI(g){const[A,I]=X.useState(void 0);return IS(()=>{if(g){I({width:g.offsetWidth,height:g.offsetHeight});let e=0;const t=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const B=o[0];window.cancelAnimationFrame(e),e=window.requestAnimationFrame(()=>{let C,Q;if("borderBoxSize"in B){const i=B.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}qXt(rkI,"useSize");var TXt=Object.defineProperty,G3=(g,A)=>TXt(g,"name",{value:A,configurable:!0}),ckI={Partial:"partial"},hkI={Optimized:"optimized",Always:"always"},lkI="Popper",[DkI,dkI]=G5(lkI),[ZXt,ykI]=DkI(lkI),wkI=G3(g=>{const{__scopePopper:A,children:I}=g,[e,t]=X.useState(null),[o,B]=X.useState(void 0);return q.jsx(ZXt,{scope:A,anchor:e,onAnchorChange:t,placementState:o,setPlacementState:B,children:I})},"Popper"),OXt="PopperAnchor",WXt=X.forwardRef(G3(function(A,I){const{__scopePopper:e,virtualRef:t,...o}=A,B=ykI(OXt,e),C=X.useRef(null),Q=B.onAnchorChange,i=X.useCallback(c=>{C.current=c,c&&Q(c)},[Q]),E=xd(I,i),n=X.useRef(null);X.useEffect(()=>{if(!t)return;const c=n.current;n.current=t.current,c!==n.current&&Q(n.current)});const s=B.placementState&&$yA(B.placementState),r=s?.[0],a=s?.[1];return t?null:q.jsx(ux.div,{"data-radix-popper-side":r,"data-radix-popper-align":a,...o,ref:E})},"PopperAnchor")),ukI="PopperContent",[VXt,_$o]=DkI(ukI),jXt=X.forwardRef(G3(function(A,I){const{__scopePopper:e,side:t="bottom",sideOffset:o=0,align:B="center",alignOffset:C=0,arrowPadding:Q=0,avoidCollisions:i=!0,collisionBoundary:E=[],collisionPadding:n=0,sticky:s=ckI.Partial,hideWhenDetached:r=!1,updatePositionStrategy:a=hkI.Optimized,onPlaced:c,...h}=A,l=ykI(ukI,e),[D,d]=X.useState(null),y=xd(I,d),[w,u]=X.useState(null),G=rkI(w),m=G?.width??0,p=G?.height??0,k=t+(B!=="center"?"-"+B:""),S=typeof n=="number"?n:{top:0,right:0,bottom:0,left:0,...n},R=Array.isArray(E)?E:[E],x=R.length>0,N={padding:S,boundary:R.filter(GkI),altBoundary:x},{refs:U,floatingStyles:K,placement:_,isPositioned:H,middlewareData:T}=UXt({strategy:"fixed",placement:k,whileElementsMounted:G3((...CA)=>mXt(...CA,{animationFrame:a===hkI.Always}),"whileElementsMounted"),elements:{reference:l.anchor},middleware:[PXt({mainAxis:o+p,alignmentAxis:C}),i&&KXt({mainAxis:!0,crossAxis:!1,...s===ckI.Partial?{limiter:LXt()}:{},...N}),i&&YXt({...N}),_Xt({...N,apply:G3(({elements:CA,rects:hA,availableWidth:sA,availableHeight:cA})=>{const{width:SA,height:xA}=hA.reference,aA=CA.floating.style;aA.setProperty("--radix-popper-available-width",`${sA}px`),aA.setProperty("--radix-popper-available-height",`${cA}px`),aA.setProperty("--radix-popper-anchor-width",`${SA}px`),aA.setProperty("--radix-popper-anchor-height",`${xA}px`)},"apply")}),w&&HXt({element:w,padding:Q}),zXt({arrowWidth:m,arrowHeight:p}),r&&bXt(x?{strategy:"referenceHidden",...N}:{strategy:"referenceHidden",padding:N.padding,altBoundary:N.altBoundary})]}),j=l.setPlacementState;IS(()=>(j(_),()=>{j(void 0)}),[_,j]);const[W,O]=$yA(_),gA=Gx(c);IS(()=>{H&&gA?.()},[H,gA]);const tA=T.arrow?.x,IA=T.arrow?.y,QA=T.arrow?.centerOffset!==0,[nA,DA]=X.useState();return IS(()=>{D&&DA(window.getComputedStyle(D).zIndex)},[D]),q.jsx("div",{ref:U.setFloating,"data-radix-popper-content-wrapper":"",style:{...K,transform:H?K.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:nA,"--radix-popper-transform-origin":[T.transformOrigin?.x,T.transformOrigin?.y].join(" "),...T.hide?.referenceHidden&&{visibility:"hidden",pointerEvents:"none"}},dir:A.dir,children:q.jsx(VXt,{scope:e,placedSide:W,placedAlign:O,onArrowChange:u,arrowX:tA,arrowY:IA,shouldHideArrow:QA,children:q.jsx(ux.div,{"data-side":W,"data-align":O,...h,ref:y,style:{...h.style,animation:H?h.style?.animation:"none"}})})})},"PopperContent"));function GkI(g){return g!==null}G3(GkI,"isNotNull");var zXt=G3(g=>({name:"transformOrigin",options:g,fn(A){const{placement:I,rects:e,middlewareData:t}=A,B=t.arrow?.centerOffset!==0,C=B?0:g.arrowWidth,Q=B?0:g.arrowHeight,[i,E]=$yA(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=B?n:`${s}px`,c=`${-Q}px`):i==="top"?(a=B?n:`${s}px`,c=`${e.floating.height+Q}px`):i==="right"?(a=`${-Q}px`,c=B?n:`${r}px`):i==="left"&&(a=`${e.floating.width+Q}px`,c=B?n:`${r}px`),{data:{x:a,y:c}}}}),"transformOrigin");function $yA(g){const[A,I="center"]=g.split("-");return[A,I]}G3($yA,"getSideAndAlignFromPlacement");var XXt=Object.defineProperty,$Xt=(g,A)=>XXt(g,"name",{value:A,configurable:!0}),A$t=X.forwardRef($Xt(function(A,I){const{container:e,...t}=A,[o,B]=X.useState(!1);IS(()=>B(!0),[]);const C=e||o&&globalThis?.document?.body;return C?j1.createPortal(q.jsx(ux.div,{...t,ref:I}),C):null},"Portal")),g$t=Object.defineProperty,cJ=(g,A)=>g$t(g,"name",{value:A,configurable:!0});function mkI(g,A){return X.useReducer((I,e)=>A[I][e]??I,g)}cJ(mkI,"useStateMachine");var Kgg=cJ(g=>{const{present:A,children:I}=g,e=pkI(A),t=typeof I=="function"?I({present:e.isPresent}):X.Children.only(I),o=kkI(e.ref,MkI(t));return typeof I=="function"||e.isPresent?X.cloneElement(t,{ref:o}):null},"Presence");function pkI(g){const[A,I]=X.useState(),e=X.useRef(null),t=X.useRef(g),o=X.useRef("none"),B=X.useRef(void 0),C=g?"mounted":"unmounted",[Q,i]=mkI(C,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return X.useEffect(()=>{Q==="mounted"?(o.current=B.current??U7(e.current),B.current=void 0):o.current="none"},[Q]),IS(()=>{const E=e.current,n=t.current;if(n!==g){const r=o.current,a=U7(E);g?(B.current=a,i("MOUNT")):a==="none"||E?.display==="none"?i("UNMOUNT"):i(n&&r!==a?"ANIMATION_OUT":"UNMOUNT"),t.current=g}},[g,i]),IS(()=>{if(A){let E;const n=A.ownerDocument.defaultView??window,s=cJ(a=>{const h=U7(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&&(o.current=U7(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:X.useCallback(E=>{if(E){const n=getComputedStyle(E);e.current=n,B.current=U7(n)}else e.current=null;I(E)},[])}}cJ(pkI,"usePresence");function Lgg(g,A){if(typeof g=="function")return g(A);g!=null&&(g.current=A)}cJ(Lgg,"setRef");function kkI(...g){const A=X.useRef(g);return A.current=g,X.useCallback(I=>{const e=A.current;let t=!1;const o=e.map(B=>{const C=Lgg(B,I);return!t&&typeof C=="function"&&(t=!0),C});if(t)return()=>{for(let B=0;B<o.length;B++){const C=o[B];typeof C=="function"?C():Lgg(e[B],null)}}},[])}cJ(kkI,"useStableComposedRefs");function U7(g){return g?.animationName||"none"}cJ(U7,"getAnimationName");function MkI(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(MkI,"getElementRef");var I$t=Object.defineProperty,Ygg=(g,A)=>I$t(g,"name",{value:A,configurable:!0}),_gg=!1;function SkI(){const[g,A]=X.useState(_gg);return X.useEffect(()=>{_gg||(_gg=!0,A(!0))},[]),g}Ygg(SkI,"useIsHydrated");var fkI=fp[" useSyncExternalStore ".trim().toString()];function RkI(){return()=>{}}Ygg(RkI,"subscribe");function NkI(){return fkI(RkI,()=>!0,()=>!1)}Ygg(NkI,"useIsHydratedModern");var e$t=typeof fkI=="function"?NkI:SkI,t$t=Object.defineProperty,S5=(g,A)=>t$t(g,"name",{value:A,configurable:!0}),bgg="rovingFocusGroup.onEntryFocus",o$t={bubbles:!1,cancelable:!0},AwA="RovingFocusGroup",[Hgg,xkI,B$t]=sgg(AwA),[C$t,FkI]=G5(AwA,[B$t]),UkI={Vertical:"vertical",Horizontal:"horizontal"},Q$t={RTL:"rtl"},[i$t,E$t]=C$t(AwA),n$t=X.forwardRef(S5(function(A,I){return q.jsx(Hgg.Provider,{scope:A.__scopeRovingFocusGroup,children:q.jsx(Hgg.Slot,{scope:A.__scopeRovingFocusGroup,children:q.jsx(s$t,{...A,ref:I})})})},"RovingFocusGroup")),s$t=X.forwardRef(S5(function(A,I){const{__scopeRovingFocusGroup:e,orientation:t,loop:o=!1,dir:B,currentTabStopId:C,defaultCurrentTabStopId:Q,onCurrentTabStopIdChange:i,onEntryFocus:E,preventScrollOnEntryFocus:n=!1,...s}=A,r=X.useRef(null),a=xd(I,r),c=rgg(B),[h,l]=PyA({prop:C,defaultProp:Q??null,onChange:i,caller:AwA}),[D,d]=X.useState(!1),y=Gx(E),w=xkI(e),u=X.useRef(!1),[G,m]=X.useState(0);return X.useEffect(()=>{const p=r.current;if(p)return p.addEventListener(bgg,y),()=>p.removeEventListener(bgg,y)},[y]),q.jsx(i$t,{scope:e,orientation:t,dir:c,loop:o,currentTabStopId:h,onItemFocus:X.useCallback(p=>l(p),[l]),onItemShiftTab:X.useCallback(()=>d(!0),[]),onFocusableItemAdd:X.useCallback(()=>m(p=>p+1),[]),onFocusableItemRemove:X.useCallback(()=>m(p=>p-1),[]),children:q.jsx(ux.div,{tabIndex:D||G===0?-1:0,"data-orientation":t,...s,ref:a,style:{outline:"none",...A.style},onMouseDown:mn(A.onMouseDown,()=>{u.current=!0}),onFocus:mn(A.onFocus,p=>{const k=!u.current;if(p.target===p.currentTarget&&k&&!D){const S=new CustomEvent(bgg,o$t);if(p.currentTarget.dispatchEvent(S),!S.defaultPrevented){const R=w().filter(_=>_.focusable),x=R.find(_=>_.active),N=R.find(_=>_.id===h),K=[x,N,...R].filter(Boolean).map(_=>_.ref.current);vgg(K,n)}}u.current=!1}),onBlur:mn(A.onBlur,()=>d(!1))})})},"RovingFocusGroupImpl")),a$t="RovingFocusGroupItem",r$t=X.forwardRef(S5(function(A,I){const{__scopeRovingFocusGroup:e,focusable:t=!0,active:o=!1,tabStopId:B,children:C,...Q}=A,i=R7(),E=B||i,n=E$t(a$t,e),s=n.currentTabStopId===E,r=xkI(e),{onFocusableItemAdd:a,onFocusableItemRemove:c,currentTabStopId:h}=n,l=e$t();return IS(()=>{if(!(!l||!t))return a(),()=>c()},[l,t,a,c]),X.useEffect(()=>{if(!(l||!t))return a(),()=>c()},[l,t,a,c]),q.jsx(Hgg.ItemSlot,{scope:e,id:E,focusable:t,active:o,children:q.jsx(ux.span,{tabIndex:s?0:-1,"data-orientation":n.orientation,...Q,ref:I,onMouseDown:mn(A.onMouseDown,D=>{t?n.onItemFocus(E):D.preventDefault()}),onFocus:mn(A.onFocus,()=>n.onItemFocus(E)),onKeyDown:mn(A.onKeyDown,D=>{if(D.key==="Tab"&&D.shiftKey){n.onItemShiftTab();return}if(D.target!==D.currentTarget)return;const d=PkI(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?KkI(w,u+1):w.slice(u+1)}setTimeout(()=>vgg(w))}}),children:typeof C=="function"?C({isCurrentTabStop:s,hasTabStop:h!=null}):C})})},"RovingFocusGroupItem")),c$t={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function JkI(g,A){return A!==Q$t.RTL?g:g==="ArrowLeft"?"ArrowRight":g==="ArrowRight"?"ArrowLeft":g}S5(JkI,"getDirectionAwareKey");function PkI(g,A,I){const e=JkI(g.key,I);if(!(A===UkI.Vertical&&["ArrowLeft","ArrowRight"].includes(e))&&!(A===UkI.Horizontal&&["ArrowUp","ArrowDown"].includes(e)))return c$t[e]}S5(PkI,"getFocusIntent");function vgg(g,A=!1){const I=document.activeElement;for(const e of g)if(e===I||(e.focus({preventScroll:A}),document.activeElement!==I))return}S5(vgg,"focusFirst");function KkI(g,A){return g.map((I,e)=>g[(A+e)%g.length])}S5(KkI,"wrapArray");var h$t=function(g){if(typeof document>"u")return null;var A=Array.isArray(g)?g[0]:g;return A.ownerDocument.body},J7=new WeakMap,gwA=new WeakMap,IwA={},qgg=0,LkI=function(g){return g&&(g.host||LkI(g.parentNode))},l$t=function(g,A){return A.map(function(I){if(g.contains(I))return I;var e=LkI(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})},D$t=function(g,A,I,e){var t=l$t(A,Array.isArray(g)?g:[g]);IwA[I]||(IwA[I]=new WeakMap);var o=IwA[I],B=[],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=(J7.get(s)||0)+1,h=(o.get(s)||0)+1;J7.set(s,c),o.set(s,h),B.push(s),c===1&&a&&gwA.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(),qgg++,function(){B.forEach(function(n){var s=J7.get(n)-1,r=o.get(n)-1;J7.set(n,s),o.set(n,r),s||(gwA.has(n)||n.removeAttribute(e),gwA.delete(n)),r||n.removeAttribute(I)}),qgg--,qgg||(J7=new WeakMap,J7=new WeakMap,gwA=new WeakMap,IwA={})}},d$t=function(g,A,I){I===void 0&&(I="data-aria-hidden");var e=Array.from(Array.isArray(g)?g:[g]),t=h$t(g);return t?(e.push.apply(e,Array.from(t.querySelectorAll("[aria-live], script"))),D$t(e,t,I,"aria-hidden")):function(){return null}},Mx=function(){return Mx=Object.assign||function(A){for(var I,e=1,t=arguments.length;e<t;e++){I=arguments[e];for(var o in I)Object.prototype.hasOwnProperty.call(I,o)&&(A[o]=I[o])}return A},Mx.apply(this,arguments)};function YkI(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 y$t(g,A,I){for(var e=0,t=A.length,o;e<t;e++)(o||!(e in A))&&(o||(o=Array.prototype.slice.call(A,0,e)),o[e]=A[e]);return g.concat(o||Array.prototype.slice.call(A))}var ewA="right-scroll-bar-position",twA="width-before-scroll-bar",w$t="with-scroll-bars-hidden",u$t="--removed-body-scroll-bar-size";function Tgg(g,A){return typeof g=="function"?g(A):g&&(g.current=A),g}function G$t(g,A){var I=X.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 m$t=typeof window<"u"?X.useLayoutEffect:X.useEffect,_kI=new WeakMap;function p$t(g,A){var I=G$t(null,function(e){return g.forEach(function(t){return Tgg(t,e)})});return m$t(function(){var e=_kI.get(I);if(e){var t=new Set(e),o=new Set(g),B=I.current;t.forEach(function(C){o.has(C)||Tgg(C,null)}),o.forEach(function(C){t.has(C)||Tgg(C,B)})}_kI.set(I,g)},[g]),I}function k$t(g){return g}function M$t(g,A){A===void 0&&(A=k$t);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(o){var B=A(o,e);return I.push(B),function(){I=I.filter(function(C){return C!==B})}},assignSyncMedium:function(o){for(e=!0;I.length;){var B=I;I=[],B.forEach(o)}I={push:function(C){return o(C)},filter:function(){return I}}},assignMedium:function(o){e=!0;var B=[];if(I.length){var C=I;I=[],C.forEach(o),B=I}var Q=function(){var E=B;B=[],E.forEach(o)},i=function(){return Promise.resolve().then(Q)};i(),I={push:function(E){B.push(E),i()},filter:function(E){return B=B.filter(E),I}}}};return t}function S$t(g){g===void 0&&(g={});var A=M$t(null);return A.options=Mx({async:!0,ssr:!1},g),A}var bkI=function(g){var A=g.sideCar,I=YkI(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 X.createElement(e,Mx({},I))};bkI.isSideCarExport=!0;function f$t(g,A){return g.useMedium(A),bkI}var HkI=S$t(),Zgg=function(){},owA=X.forwardRef(function(g,A){var I=X.useRef(null),e=X.useState({onScrollCapture:Zgg,onWheelCapture:Zgg,onTouchMoveCapture:Zgg}),t=e[0],o=e[1],B=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=YkI(g,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),w=s,u=p$t([I,A]),G=Mx(Mx({},y),t);return X.createElement(X.Fragment,null,E&&X.createElement(w,{sideCar:HkI,removeScrollBar:i,shards:n,noRelative:r,noIsolation:a,inert:c,setCallbacks:o,allowPinchZoom:!!h,lockRef:I,gapMode:d}),B?X.cloneElement(X.Children.only(C),Mx(Mx({},G),{ref:u})):X.createElement(D,Mx({},G,{className:Q,ref:u}),C))});owA.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},owA.classNames={fullWidth:twA,zeroRight:ewA};var R$t=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function N$t(){if(!document)return null;var g=document.createElement("style");g.type="text/css";var A=R$t();return A&&g.setAttribute("nonce",A),g}function x$t(g,A){g.styleSheet?g.styleSheet.cssText=A:g.appendChild(document.createTextNode(A))}function F$t(g){var A=document.head||document.getElementsByTagName("head")[0];A.appendChild(g)}var U$t=function(){var g=0,A=null;return{add:function(I){g==0&&(A=N$t())&&(x$t(A,I),F$t(A)),g++},remove:function(){g--,!g&&A&&(A.parentNode&&A.parentNode.removeChild(A),A=null)}}},J$t=function(){var g=U$t();return function(A,I){X.useEffect(function(){return g.add(A),function(){g.remove()}},[A&&I])}},vkI=function(){var g=J$t(),A=function(I){var e=I.styles,t=I.dynamic;return g(e,t),null};return A},P$t={left:0,top:0,right:0,gap:0},Ogg=function(g){return parseInt(g||"",10)||0},K$t=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[Ogg(I),Ogg(e),Ogg(t)]},L$t=function(g){if(g===void 0&&(g="margin"),typeof window>"u")return P$t;var A=K$t(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])}},Y$t=vkI(),P7="data-scroll-locked",_$t=function(g,A,I,e){var t=g.left,o=g.top,B=g.right,C=g.gap;return I===void 0&&(I="margin"),`
5357
+ `,qOt=({rotation:g,infiniteGrid:A,cellSize:I=1,sectionSize:e=10})=>{const{scene:t,camera:o}=RD(),B=1e3,C=X.useMemo(()=>{const Q=new pR(B,B);Q.rotateX(-Math.PI/2);const i=new Cx({vertexShader:HOt,fragmentShader:vOt,uniforms:{cellSize:{value:I},sectionSize:{value:e},gridColor:{value:new oo(15658734)},sectionColor:{value:new oo(13421823)},fadeDistance:{value:100},fadeStrength:{value:1.5}},transparent:!0,side:Sl}),E=new Ko(Q,i);return g&&E.rotation.fromArray(g),E},[B,I,e,g]);return DIA(()=>{A&&C.position.set(o.position.x,o.position.y,0)}),X.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},_Ag=.75,TOt=({boardDimensions:g,boardCenter:A,darkBackgroundEnabled:I=!1,shadowsEnabled:e=!1})=>{const{scene:t}=RD(),o=X.useMemo(()=>{const B=new Yc;B.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 lBI(16186360,.22);r.name="cad-viewer-soft-ambient",B.add(r);const a=new ESt(15004141,1581597,.2);a.name="cad-viewer-hemisphere",B.add(a);const c=(h,l,D,d,y=!1)=>{const w=new hBI(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()}B.add(w),B.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*_Ag,[s*.68,-s*.8,-s*1.08]),c("cad-viewer-underside-fill-light",14477554,.25*_Ag,[-n*.85,n*.55,-n*.75]),c("cad-viewer-underside-rim-light",12184275,.5*_Ag,[-n*.35,n*.85,-n*.95]),B},[A,g,e]);return X.useEffect(()=>{const B=t.background,C=t.environment;return t.background=I?new oo(1053456):null,t.environment=null,()=>{t.background=B,t.environment=C}},[I,t]),X.useEffect(()=>{if(t)return t.add(o),()=>{t.remove(o)}},[t,o]),null},ZOt=.05,OOt=({camera:g,initialOrbitDistance:A})=>{const I=Number.isFinite(A)?A*ZOt:0;return Math.max(I,g.near,Number.EPSILON)},WOt=({camera:g,controls:A,minimumDollyDistance:I})=>{if(!(g instanceof Q0))return!1;const e=A.getDistance();if(Number.isFinite(e)&&e>=I)return!1;const t=new BI;return g.getWorldDirection(t),A.target.copy(g.position).addScaledVector(t,I),!0},VOt=({autoRotate:g,autoRotateSpeed:A,onStart:I,panSpeed:e,rotateSpeed:t,zoomSpeed:o,enableDamping:B,dampingFactor:C,target:Q,onControlsChange:i})=>{const{camera:E,renderer:n}=RD(),s=X.useMemo(()=>!E||!n?null:new QYt(E,n.domElement),[E,n]),r=X.useMemo(()=>{if(!s||!(E instanceof Q0))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 OOt({camera:E,initialOrbitDistance:a})},[E,s,Q]);return X.useEffect(()=>(i?.(s??null),()=>i?.(null)),[s,i]),X.useEffect(()=>{if(!s)return;const a=()=>{i?.(s)};return s.addEventListener("change",a),()=>{s.removeEventListener("change",a)}},[s,i]),X.useEffect(()=>{s&&(s.autoRotate=g||!1,s.autoRotateSpeed=A||1,e!==void 0&&(s.panSpeed=e),t!==void 0&&(s.rotateSpeed=t),o!==void 0&&(s.zoomSpeed=o),B!==void 0&&(s.enableDamping=B),C!==void 0&&(s.dampingFactor=C),s.zoomToCursor=!0,s.mouseButtons={LEFT:ZK.ROTATE,MIDDLE:ZK.PAN,RIGHT:null},Q&&(s.target.set(Q[0],Q[1],Q[2]),s.update()))},[s,g,A,e,t,o,B,C,Q]),X.useEffect(()=>{if(!(!s||!I))return s.addEventListener("start",I),()=>{s.removeEventListener("start",I)}},[s,I]),X.useEffect(()=>{if(s)return()=>{s.dispose()}},[s]),DIA(()=>{s&&(WOt({camera:E,controls:s,minimumDollyDistance:r}),s.update())},[E,s,r]),null},jOt=10,k7={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}},zOt=Object.values(k7),XOt=[{type:null,label:"None"},...zOt],$Ot=(g,A)=>g===A?null:A,bAg=g=>Number.isFinite(g)?Math.max(g??0,0):0,DyA=g=>Number.isFinite(g)?g??0:0,DmI=(g,A,I)=>{const e=k7[g],t=bAg(A?.width),o=DyA(I?.x),B=DyA(I?.y);return{x:o+t/2+jOt+e.width/2,y:B,z:0}},AWt=(g,A,I)=>{const e=k7[g],t=bAg(A?.width),o=bAg(A?.height),B=DyA(I?.x),C=DyA(I?.y),Q=DmI(g,A,I);return{minX:Math.min(B-t/2,Q.x-e.width/2),maxX:Math.max(B+t/2,Q.x+e.width/2),minY:Math.min(C-o/2,Q.y-e.height/2),maxY:Math.max(C+o/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 gWt(g,A){const I=new mm().setFromEuler(new km(g.x,g.y,g.z)),e=new BI(0,0,1);return e.applyQuaternion(I),e.multiplyScalar(A)}var IWt=()=>{const{mainCameraRef:g}=iJ(),A=X.useRef(null);return X.useEffect(()=>{if(!A.current)return;const I=A.current,e=document.createElement("canvas");I.appendChild(e);const t=new dDA({canvas:e,antialias:!0,alpha:!0});t.setSize(120,120),t.setPixelRatio(window.devicePixelRatio);const o=new W_,B=new Q0(75,1,.1,1e3);B.up.set(0,0,1);const C=new lBI(16777215,Math.PI/2);o.add(C);const Q=new Yc;Q.rotation.fromArray([Math.PI/2,0,0]);const i=1,E=new Ko(new ik(i,i,i),new Hs({color:"white"}));Q.add(E);const n=new egA(new xMt(new ik(i,i,i)),new V_({color:0,linewidth:2}));Q.add(n),o.add(Q);const s=.51,r=(m,p,k)=>{const S=new dqA;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=gWt(g.current.rotation??new km(0,0,0),2);m.equals(B.position)||(B.position.copy(m),B.lookAt(0,0,0))}t.render(o,B)}};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(),o.clear(),t.dispose(),t.forceContextLoss()}},[g]),q.jsx("div",{ref:A,style:{position:"absolute",top:0,left:0,width:120,height:120,zIndex:yIA.orientationCube}})},dmI=(g,A,I)=>{const e=g/2,t=A/2,o=Math.min(I,e,t),B=new gBI;return B.moveTo(-e+o,-t),B.lineTo(e-o,-t),B.quadraticCurveTo(e,-t,e,-t+o),B.lineTo(e,t-o),B.quadraticCurveTo(e,t,e-o,t),B.lineTo(-e+o,t),B.quadraticCurveTo(-e,t,-e,t-o),B.lineTo(-e,-t+o),B.quadraticCurveTo(-e,-t,-e+o,-t),B},HAg=(g,A,I,e)=>ymI(dmI(g,A,e),I),ymI=(g,A)=>{const I=new gqA(g,{depth:A,bevelEnabled:!1,curveSegments:24});return I.translate(0,0,-A/2),I.computeVertexNormals(),I},eWt=(g,A)=>{const I=k7[A];g.updateMatrixWorld(!0);const t=new pm().setFromObject(g).getSize(new BI);g.scale.set(I.width/t.x,I.height/t.y,I.depth/t.z),g.updateMatrixWorld(!0);const B=new pm().setFromObject(g).getCenter(new BI);g.position.set(-B.x,-B.y,I.zCenter-B.z),g.updateMatrixWorld(!0)},tWt=()=>{const g=new VoI([new BI(-82,18,16),new BI(-67,7,15),new BI(-43,-9,14),new BI(-15,-18,14),new BI(16,-18,14),new BI(47,-8,14.5),new BI(72,8,16),new BI(84,19,17)]),A=84,I=30,e=g.computeFrenetFrames(A,!1),t=[],o=[],B=[],C=[],Q=[],i=new oo(16766023),E=new oo(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 BI().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),o.push(k.x,k.y,k.z),B.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 Yn;return n.setIndex(Q),n.setAttribute("position",new ZB(t,3)),n.setAttribute("normal",new ZB(o,3)),n.setAttribute("color",new ZB(B,3)),n.setAttribute("uv",new ZB(C,2)),n.computeBoundingBox(),n.computeBoundingSphere(),{geometry:n,curve:g}},oWt=()=>{const g=new Yc,A=new Yc,{geometry:I,curve:e}=tWt(),t=new Ko(I,new Hs({color:16777215,roughness:.72,metalness:0,vertexColors:!0}));t.name="banana-peel",A.add(t);const o=new Ko(new X_(3.4,20,12),new Hs({color:6242844,roughness:.92}));o.position.copy(e.getPointAt(0)),o.scale.set(1.15,.78,.78),o.name="banana-blossom-tip",A.add(o);const B=11,C=e.getTangentAt(1).normalize(),Q=new Ko(new PT(2.5,4.1,B,18),new Hs({color:8483625,roughness:.82}));Q.quaternion.setFromUnitVectors(new BI(0,1,0),C),Q.position.copy(e.getPointAt(1)).addScaledVector(C,B/2),Q.name="banana-stem",A.add(Q);const i=new Ko(new X_(2.55,18,10),new Hs({color:5981470,roughness:.9}));return i.position.copy(e.getPointAt(1)).addScaledVector(C,B),i.name="banana-stem-tip",A.add(i),eWt(A,"banana"),g.add(A),g},BWt=(g,A,I,e,t)=>{const o=dmI(g,A,e),B=new jvA;return B.absarc(0,0,t,0,Math.PI*2,!0),o.holes.push(B),ymI(o,I)},CWt=(g,A)=>{const t=new Ko(new PT(A-.15,A-.15,.25,48),new Hs({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},QWt=()=>{const g=k7["credit-card"],A=new Yc,I=new Ko(HAg(g.width,g.height,g.depth,3.18),new Hs({color:2383272,roughness:.38,metalness:.08}));I.name="credit-card-body",A.add(I);const e=g.depth/2+.08,t=new Ko(HAg(12,9,.14,1.2),new Hs({color:14003525,roughness:.3,metalness:.62}));t.position.set(-21,3,e),t.name="credit-card-chip",A.add(t);const o=new Hs({color:15331061,roughness:.45,metalness:.05});for(let B=0;B<4;B++){const C=new Ko(new ik(B===3?8:12,.8,.1),o);C.position.set(-20+B*14,-14,e+.08),C.name="credit-card-detail",A.add(C)}return A},iWt=()=>{const g=k7["14in-macbook"],A=new Yc,I=new Hs({color:12896201,roughness:.3,metalness:.38}),e=new Ko(HAg(g.width,g.height,13.5,9),I);e.position.z=-1,e.name="macbook-body",A.add(e);const t=2,o=6.75,B=o+t/2,C=12,Q=new Ko(BWt(g.width-1.8,g.height-1.8,t,8.2,C),I.clone());Q.position.z=o,Q.name="macbook-lid",A.add(Q);const i=new Ko(new ik(g.width-42,3.2,1.2),new Hs({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(CWt(B,C));const E=new Ko(new ik(54,1.2,.8),new Hs({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},EWt=g=>{const A=g==="banana"?oWt():g==="credit-card"?QWt():iWt();return A.name=`reference-object-${g}`,A.userData.isReferenceObject=!0,A.userData.referenceObjectType=g,AS(A),A},nWt=g=>{const A=new Set,I=new Set;g.traverse(e=>{if(!(e instanceof Ko))return;A.add(e.geometry);const t=Array.isArray(e.material)?e.material:[e.material];for(const o of t)I.add(o)});for(const e of A)e.dispose();for(const e of I)e.dispose()},sWt=(g,A,I,e=1.18)=>{const t=Math.max(I.maxX-I.minX,0),o=Math.max(I.maxY-I.minY,0),B=Math.max(I.maxZ-I.minZ,0),C=new BI((I.minX+I.maxX)/2,(I.minY+I.maxY)/2,(I.minZ+I.maxZ)/2),Q=Math.max(Math.hypot(t,o,B)/2,1),i=A?.target??new BI,E=new BI(0,-.75,.9).normalize();let n=Math.max(g.position.distanceTo(i),5);if(g instanceof Q0){const s=sT.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 NT){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}},aWt=({type:g,boardDimensions:A,boardCenter:I})=>{const{scene:e}=RD(),t=X.useMemo(()=>{const o=EWt(g),B=DmI(g,A,I);return o.position.set(B.x,B.y,B.z),o},[g,A,I]);return X.useEffect(()=>(e.add(t),()=>{e.remove(t),nWt(t)}),[e,t]),null},wmI=({bounds:g})=>{const{camera:A}=RD(),{controlsRef:I}=iJ();return X.useEffect(()=>{sWt(A,I.current,g)},[g,A,I]),null},rWt=()=>{const{camera:g}=RD(),{setCameraRotation:A}=iJ();return DIA(()=>{g&&A(g.rotation)}),null},umI=X.forwardRef(({children:g,initialCameraPosition:A=[5,-5,5],autoRotateDisabled:I,clickToInteractEnabled:e=!1,boardDimensions:t,boardCenter:o,cameraSessionScope:B,referenceObject:C,onUserInteraction:Q,onCameraControllerReady:i},E)=>{const[n,s]=X.useState(!e),{mainCameraRef:r,handleControlsChange:a,controller:c}=iJ(),{darkBackgroundEnabled:h,gridEnabled:l,lightingEnabled:D}=LAg(),{handleCameraCreated:d,handleControlsChange:y}=LOt({cameraSessionScope:B});X.useEffect(()=>{i&&i(c)},[c,i]);const w=X.useMemo(()=>{if(C)return AWt(C,t,o)},[C,t,o]),u=X.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=X.useMemo(()=>{if(w)return[(w.minX+w.maxX)/2,(w.minY+w.maxY)/2,(w.minZ+w.maxZ)/2];if(o)return[o.x,o.y,0]},[o,w]);return q.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[q.jsx(IWt,{}),q.jsxs(bOt,{ref:E,scene:{up:new BI(0,0,1)},camera:{up:[0,0,1],position:A},onCreated:({camera:m})=>{r.current=m,d(m)},children:[q.jsx(UZt,{}),q.jsx(POt,{}),q.jsx(rWt,{}),n&&q.jsx(VOt,{autoRotate:!I,autoRotateSpeed:1,onStart:Q,rotateSpeed:.5,panSpeed:.75,zoomSpeed:.5,enableDamping:!0,dampingFactor:.1,target:G,onControlsChange:m=>{a(m),y()}}),q.jsx(TOt,{boardDimensions:t,boardCenter:o,darkBackgroundEnabled:h,shadowsEnabled:D}),C&&q.jsx(aWt,{type:C,boardDimensions:t,boardCenter:o}),w&&q.jsx(wmI,{bounds:w}),l&&q.jsx(qOt,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:3,sectionSize:u}),g]},B),q.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:["@",EmI.version]}),e&&!n&&q.jsx("button",{type:"button",onClick:()=>s(!0),onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&s(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:yIA.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center"},children:q.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"})})]})}),cWt=g=>{const[A,I]=X.useState([]),[e,t]=X.useState(!0);return X.useEffect(()=>{if(!g)return;(async()=>{t(!0);const C=(Array.isArray(g)?g:[g]).map(async(Q,i)=>{const E=wYt.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}},hWt=Bs(jdA()),lWt=Bs(c5()),DWt=Bs(hIA()),dWt=Bs(c5()),yWt=Bs(h5()),wWt=Bs(MwI()),GmI=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},vAg=(g,A=1.2,I={})=>{const{xyOutset:e=0}=I,{outline:t}=g;let o=t.map(Q=>[Q.x,Q.y]);GmI(o)&&(o=o.reverse());let B=(0,dWt.polygon)({points:o});e!==0&&(B=(0,wWt.expand)({delta:e,corners:"edge"},B));let C=(0,DWt.extrudeLinear)({height:A},B);return C=(0,yWt.translate)([0,0,-A/2],C),C},OB=.01,$E={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]},FR=.001,Nd=32,O2=150,dyA=.6,uWt={fr1:$E.fr1Tan,fr4:$E.fr4Tan,flex:$E.flexAmber},GWt={fr1:$E.fr1SolderMaskGreen,fr4:$E.fr4SolderMaskGreen,flex:$E.flexAmber},mWt={red:"#650202",blue:"#003f7d",purple:"#4c1d69",black:"#071014",white:"#dddddd",yellow:"#dcc84a"},pWt=.875,kWt=/^#(?:[\da-f]{3}|[\da-f]{6})$/i,MWt=/^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/i,SWt=/^rgb\(\s*\d+%\s*,\s*\d+%\s*,\s*\d+%\s*\)$/i,fWt=/^hsl\(\s*\d*\.?\d+\s*,\s*\d*\.?\d+%\s*,\s*\d*\.?\d+%\s*\)$/i,RWt={blue:.96,purple:.96,black:.99,yellow:.92},mmI=g=>{const A=g?.trim();if(!A)return null;const I=A.toLowerCase();if(I==="green"||I==="not_specified")return null;const t=mWt[I];return t?new oo(t):Object.hasOwn(oo.NAMES,I)||kWt.test(A)||MWt.test(A)||SWt.test(A)||fWt.test(A)?new oo(I):null},NWt=g=>{const A=g?.trim().toLowerCase();return RWt[A]??pWt},xWt=({red:g,green:A,blue:I})=>Math.hypot(g-220,A-200,I-74)<4||Math.hypot(g-218,A-197,I-76)<4,FWt=({soldermaskColor:g,copperColor:A,soldermaskOpacity:I})=>g.clone().multiplyScalar(I).add(A.clone().multiplyScalar(1-I)),pmI=g=>{const A=g.clone().convertLinearToSRGB();return`rgb(${[Math.round(A.r*255),Math.round(A.g*255),Math.round(A.b*255)].join(",")})`},UWt=new oo(1063462),qAg=({material:g,solder_mask_color:A})=>{const I=mmI(A);if(I)return I;if(g==="fr4")return UWt.clone();const e=uWt[g]??$E.fr4Tan;return new oo(e[0],e[1],e[2])},JWt=g=>{const A=g.filter(Q=>Q.type==="pcb_panel"),I=Xo(g).pcb_board.list();let e,t,o=1.2;if(A.length>0)e=A[0],t=I.find(Q=>Q.pcb_panel_id===e.pcb_panel_id),o=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,o=e.thickness??1.2}let B;"outline"in e&&e.outline&&e.outline.length>0?B=vAg({outline:e.outline},o):B=(0,lWt.cuboid)({size:[e.width??10,e.height??10,o],center:[e.center.x,e.center.y,0]});const C=qAg({material:t?.material??"fr4",solder_mask_color:t?.solder_mask_color});return[(0,hWt.colorize)([C.r,C.g,C.b],B)]},TAg=Bs(jdA()),Yw=Bs(cIA()),kmI=Bs(BwI()),ZAg=Bs(hIA()),ak=Bs(h5()),rr=Bs(c5()),D3=Bs(c5()),PWt=Bs(hIA()),yyA=Bs(h5()),KWt=Bs(cIA()),LWt=64,YWt=(g,A,I)=>{const e=(0,D3.ellipse)({center:[0,0],radius:[Math.max(g/2,OB/2),Math.max(A/2,OB/2)],segments:LWt}),t=(0,PWt.extrudeLinear)({height:I},e);return(0,yyA.translate)([0,0,-I/2],t)},_Wt=(g,A,I)=>{const e=Math.max(g,OB),t=Math.max(A,OB);if(Math.abs(e-t)<1e-6)return(0,D3.cylinder)({center:[0,0,0],radius:e/2,height:I});const o=e>=t,B=o?e:t,C=o?t:e,Q=Math.max(B-C,0),i=(0,D3.cuboid)({center:[0,0,0],size:o?[Q,C,I]:[C,Q,I]});if(Q<=1e-6)return(0,D3.cylinder)({center:[0,0,0],radius:C/2,height:I});const E=Q/2,n=(0,D3.cylinder)({center:o?[-E,0,0]:[0,-E,0],radius:C/2,height:I}),s=(0,D3.cylinder)({center:o?[E,0,0]:[0,E,0],radius:C/2,height:I});return(0,KWt.union)(i,n,s)},wyA=(g,A,I={})=>{const e=g.hole_shape||"circle",t=I.sizeDelta??0,o=g.hole_offset_x||0,B=g.hole_offset_y||0,C=[g.x+o,g.y+B,0];if(e==="circle"){const r=Math.max((g.hole_diameter??0)+t,OB),a=Math.max(r/2,OB/2);return(0,D3.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,OB),n=Math.max(i+t,OB);if(e==="oval"){const r=YWt(E,n,A);return(0,yyA.translate)([C[0],C[1],0],r)}if(e==="pill"||e==="rotated_pill"){let r=_Wt(E,n,A);if(!r)return null;const a=g.ccw_rotation||0;return a&&(r=(0,yyA.rotateZ)(a*Math.PI/180,r)),(0,yyA.translate)(C,r)}const s=Math.max((g.hole_diameter??Q??i??OB)+t,OB);return(0,D3.cylinder)({center:C,radius:s/2,height:A})},An=Bs(c5()),yx=Bs(jdA()),gc=Bs(cIA()),MmI=Bs(h5()),uyA=Bs(hIA()),rk=Bs(h5()),bWt=1e-5;function SmI(g,A,I){if(typeof I!="number"||!Number.isFinite(I)||I<=0)return 0;const e=g/2,t=A/2,o=Math.min(e,t)-2*bWt;return Math.max(0,Math.min(I,o))}function d3(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 HWt=.05,OAg=64,D5=(g,A)=>A?(0,gc.intersect)(A,g):g,GIA=(g,A,I={})=>{const{clipGeom:e}=I;g.shape||(g.shape="circle");const t=Math.max(A.pcbThickness*.002,OB/5),o=Math.max(A.pcbThickness*3e-4,OB/20),B=Math.max(A.pcbThickness*.0025,OB/4),C=A.pcbThickness+2*HWt+4*OB,Q=Math.max(A.pcbThickness-2*(t+o+B),OB),i=Math.max(Q,OB);if(g.shape==="circle"){const E=g.outer_diameter??Math.max(g.hole_diameter,0),n=Q,s=(0,An.cylinder)({center:[g.x,g.y,0],radius:E/2,height:n}),r=D5(s,e),a=(0,An.cylinder)({center:[g.x,g.y,0],radius:Math.max(g.hole_diameter/2,.01),height:C});return(0,yx.colorize)($E.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,An.cylinder)({center:[0,0,0],radius:1,height:Q,segments:64}),D=(0,MmI.scale)([E/2,n/2,1],l);return(0,rk.translate)([g.x,g.y,0],D)})(),c=D5(a,e),h=(()=>{const l=(0,An.cylinder)({center:[0,0,0],radius:1,height:C,segments:64}),D=(0,MmI.scale)([Math.max(s/2,.01),Math.max(r/2,.01),1],l);return(0,rk.translate)([g.x,g.y,0],D)})();return(0,yx.colorize)($E.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=d3(g),c=D5((0,gc.union)((()=>{const D=(0,An.roundedRectangle)({size:[s,r],roundRadius:a||0,segments:OAg}),d=(0,uyA.extrudeLinear)({height:Q},D);return(0,rk.translate)([g.x,g.y,-Q/2],d)})(),(0,An.cylinder)({center:[g.x+(E||0),g.y+(n||0),0],radius:g.hole_diameter/2,height:i})),e),h=(0,An.cylinder)({center:[g.x+(E||0),g.y+(n||0),0],radius:Math.max(g.hole_diameter/2-OB,.01),height:C}),l=(0,gc.subtract)(c,h);return I.clipGeom?(0,yx.colorize)($E.copper,(0,gc.intersect)(l,I.clipGeom)):(0,yx.colorize)($E.copper,l)}if(g.shape==="pill"){const E=(g.ccw_rotation||0)*Math.PI/180,n=R=>{if(!E)return R;const x=(0,rk.translate)([-g.x,-g.y,0],R),N=(0,rk.rotate)([0,0,E],x);return(0,rk.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,x,N)=>{const U=x/2,K=Math.abs(R-x);if(K<=1e-6)return(0,An.cylinder)({center:[g.x,g.y,0],radius:U,height:N});const _=(0,An.cuboid)({center:[g.x,g.y,0],size:s?[x,K,N]:[K,x,N]}),H=(0,An.cylinder)({center:s?[g.x,g.y-K/2,0]:[g.x-K/2,g.y,0],radius:U,height:N}),T=(0,An.cylinder)({center:s?[g.x,g.y+K/2,0]:[g.x+K/2,g.y,0],radius:U,height:N});return(0,gc.union)(_,H,T)})(c,h,Q),u=(0,An.cuboid)({center:[g.x,g.y,0],size:s?[a-2*OB,D,C]:[D,a-2*OB,C]}),G=(0,An.cylinder)({center:s?[g.x,g.y-D/2,0]:[g.x-D/2,g.y,0],radius:l-OB,height:C}),m=(0,An.cylinder)({center:s?[g.x,g.y+D/2,0]:[g.x+D/2,g.y,0],radius:l-OB,height:C}),p=(0,gc.union)(u,G,m),k=D5(n(w),e),S=n(p);return(0,yx.colorize)($E.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=d3(g),y=.03,w=(0,gc.union)((0,An.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,An.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,An.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,An.cuboid)({center:[g.x+E,g.y+n,0],size:s?[a,h,C]:[h,a,C]}),(0,An.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,An.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,An.roundedRectangle)({size:[l,D],roundRadius:d||0,segments:OAg}),x=(0,uyA.extrudeLinear)({height:Q},R);return(0,rk.translate)([g.x,g.y,-Q/2],x)})(),m=(0,gc.subtract)(G,u),p=(0,gc.union)((0,An.cuboid)({center:[g.x+E,g.y+n,0],size:s?[a-2*OB,h-2*OB,C]:[h-2*OB,a-2*OB,C]}),(0,An.cylinder)({center:s?[g.x+E,g.y+n-h/2,0]:[g.x+E-h/2,g.y+n,0],radius:c-OB,height:C}),(0,An.cylinder)({center:s?[g.x+E,g.y+n+h/2,0]:[g.x+E+h/2,g.y+n,0],radius:c-OB,height:C})),k=(0,gc.subtract)(w,p),S=D5((0,gc.union)(m,k),e);return(0,yx.colorize)($E.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=d3(g),u=.03,G=(g.hole_ccw_rotation||0)*Math.PI/180,m=(g.rect_ccw_rotation||0)*Math.PI/180,p=H=>{const T=E*Math.cos(G)-n*Math.sin(G),j=E*Math.sin(G)+n*Math.cos(G),W=(0,rk.rotate)([0,0,G],H);return(0,rk.translate)([g.x+T,g.y+j,0],W)},k=H=>{if(!m)return H;const T=(0,rk.translate)([-g.x,-g.y,0],H),j=(0,rk.rotate)([0,0,m],T);return(0,rk.translate)([g.x,g.y,0],j)},S=p((0,gc.union)((0,An.cuboid)({center:[0,0,0],size:a?[D+2*u,h+2*u,i]:[h+2*u,D+2*u,i]}),(0,An.cylinder)({center:a?[-D/2,0,0]:[0,-D/2,0],radius:l+u,height:i}),(0,An.cylinder)({center:a?[D/2,0,0]:[0,D/2,0],radius:l+u,height:i}))),R=p((0,gc.union)((0,An.cuboid)({center:[0,0,0],size:a?[D,h,C]:[h,D,C]}),(0,An.cylinder)({center:a?[-D/2,0,0]:[0,-D/2,0],radius:l,height:C}),(0,An.cylinder)({center:a?[D/2,0,0]:[0,D/2,0],radius:l,height:C}))),x=k((()=>{const H=(0,An.roundedRectangle)({size:[d,y],roundRadius:w||0,segments:OAg}),T=(0,uyA.extrudeLinear)({height:Q},H);return(0,rk.translate)([g.x,g.y,-Q/2],T)})()),N=(0,gc.subtract)(x,R),U=p((0,gc.union)((0,An.cuboid)({center:[0,0,0],size:a?[D-2*OB,h-2*OB,C]:[h-2*OB,D-2*OB,C]}),(0,An.cylinder)({center:a?[-D/2,0,0]:[0,-D/2,0],radius:l-OB,height:C}),(0,An.cylinder)({center:a?[D/2,0,0]:[0,D/2,0],radius:l-OB,height:C}))),K=(0,gc.subtract)(S,U),_=D5((0,gc.union)(N,K),e);return(0,yx.colorize)($E.copper,_)}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,An.polygon)({points:n}),c=((y,w)=>{const u=Math.max(y,OB),G=(0,uyA.extrudeLinear)({height:u},s);return(0,rk.translate)([g.x,g.y,w-u/2],G)})(Q,0),h=D5(c,e),l=wyA(g,i);if(!l)return(0,yx.colorize)($E.copper,h);const D=wyA(g,C,{sizeDelta:-2*OB})||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,yx.colorize)($E.copper,d)):(0,yx.colorize)($E.copper,(0,gc.subtract)(d,D))}else throw new Error(`Unsupported plated hole shape: ${g.shape}`)},vWt=Bs(cIA()),qWt=Bs(h5()),WAg=Bs(c5());function TWt({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 o=OB,B=Math.min(I/2,e/2+o),Q=(0,WAg.cylinder)({center:[0,0,0],radius:B,height:t,segments:Nd}),i=t+2*OB,E=(0,WAg.cylinder)({center:[0,0,0],radius:e/2,height:i,segments:Nd}),n=(0,vWt.subtract)(Q,E);return(0,qWt.translate)([g,A,0],n)}function ZWt({x:g,y:A,holeDiameter:I,thickness:e}){const t=e*1.5,o=I/2+OB;return(0,WAg.cylinder)({center:[g,A,0],radius:o,height:t,segments:Nd})}function VAg(g){const A=SSg(g),I=[...Xo(g).pcb_via.list()],e=new Map;for(const t of I){const B=`${A.get(t.pcb_via_id)?.pcb_board_id??""}:${t.x}:${t.y}`,C=e.get(B)??[];C.push(t),e.set(B,C)}for(const t of Xo(g).pcb_trace.list()){const o=A.get(t.pcb_trace_id);for(const[B,C]of t.route.entries()){if(C.route_type!=="via")continue;const Q=`${o?.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_${B}`,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??o?.min_via_hole_diameter??.25,outer_diameter:C.outer_diameter??o?.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 OWt=64,WWt=1,jAg=.05,fmI=["initializing","processing_plated_holes","processing_holes","processing_cutouts","processing_vias","finalizing","done"],VWt=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=Xo(g).pcb_board.list();if(I.length>0){const t=I[0],o=e.find(B=>B.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:o?.thickness??1.4,material:o?.material??"fr4",num_layers:o?.num_layers??2,solder_mask_color:o?.solder_mask_color}}else{const t=e.filter(o=>!o.pcb_panel_id);this.board=t[0]}this.plated_holes=Xo(g).pcb_plated_hole.list(),this.holes=Xo(g).pcb_hole.list(),this.pcb_vias=VAg(g),this.pcb_cutouts=Xo(g).pcb_cutout.list(),this.ctx={pcbThickness:this.board.thickness??1.2},this.initializeBoard()}initializeBoard(){const g=this.ctx.pcbThickness+2*WWt;this.board.outline&&this.board.outline.length>0?(this.boardGeom=vAg({outline:this.board.outline},this.ctx.pcbThickness),this.boardClipGeom=vAg({outline:this.board.outline},g,{xyOutset:jAg})):(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*jAg,this.board.height+2*jAg,g],center:[this.board.center.x,this.board.center.y,0]})),this.state="processing_plated_holes",this.currentIndex=0}goToNextState(){const g=fmI.indexOf(this.state);g!==-1&&(this.state=fmI[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=SmI(g.width,g.height,d3(g));if(e>0){const t=(0,rr.roundedRectangle)({size:[g.width,g.height],roundRadius:e,segments:OWt});A=(0,ZAg.extrudeLinear)({height:I},t),A=(0,ak.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,ak.rotateZ)(t,A)}A=(0,ak.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(o=>[o.x,o.y]);if(e.length<3){console.warn(`PCB Cutout [${g.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);break}GmI(e)&&(e=e.reverse());const t=(0,rr.polygon)({points:e});A=(0,ZAg.extrudeLinear)({height:I},t),A=(0,ak.translate)([0,0,-I/2],A);break}}A&&(this.boardGeom=(0,Yw.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+OB,height:this.ctx.pcbThickness*1.5})}else I=(0,rr.cylinder)({center:[g.x,g.y,0],radius:g.hole_diameter/2+OB,height:this.ctx.pcbThickness*1.5});A.dontCutBoard||(this.boardGeom=(0,Yw.subtract)(this.boardGeom,I),this.copperDrills.push({geom:I,platedHoleIndex:this.platedHoleGeoms.length}));const e=GIA(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,o=t/2,B=Math.abs(e-t);let C;if(C=(0,Yw.union)((0,rr.cuboid)({center:[g.x,g.y,0],size:I?[t,B,this.ctx.pcbThickness*1.5]:[B,t,this.ctx.pcbThickness*1.5]}),(0,rr.cylinder)({center:I?[g.x,g.y-B/2,0]:[g.x-B/2,g.y,0],radius:o,height:this.ctx.pcbThickness*1.5}),(0,rr.cylinder)({center:I?[g.x,g.y+B/2,0]:[g.x+B/2,g.y,0],radius:o,height:this.ctx.pcbThickness*1.5})),g.ccw_rotation){const i=g.ccw_rotation*Math.PI/180;C=(0,ak.translate)([g.x,g.y,0],(0,ak.rotateZ)(i,(0,ak.translate)([-g.x,-g.y,0],C)))}A.dontCutBoard||(this.boardGeom=(0,Yw.subtract)(this.boardGeom,C),this.copperDrills.push({geom:C,platedHoleIndex:this.platedHoleGeoms.length}));const Q=GIA(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,o=t/2,B=Math.abs(e-t);let C;C=(0,Yw.union)((0,rr.cuboid)({center:[g.x+(g.hole_offset_x||0),g.y+(g.hole_offset_y||0),0],size:I?[t,B,this.ctx.pcbThickness*1.5]:[B,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)-B/2,0]:[g.x+(g.hole_offset_x||0)-B/2,g.y+(g.hole_offset_y||0),0],radius:o,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)+B/2,0]:[g.x+(g.hole_offset_x||0)+B/2,g.y+(g.hole_offset_y||0),0],radius:o,height:this.ctx.pcbThickness*1.5})),A.dontCutBoard||(this.boardGeom=(0,Yw.subtract)(this.boardGeom,C),this.copperDrills.push({geom:C,platedHoleIndex:this.platedHoleGeoms.length}));const Q=GIA(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,o=t?I:e,B=t?e:I,C=B/2,Q=Math.abs(o-B),i=g.hole_offset_x||0,E=g.hole_offset_y||0;let n=(0,Yw.union)((0,rr.cuboid)({center:[0,0,0],size:t?[Q,B,this.ctx.pcbThickness*1.5]:[B,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,ak.rotateZ)(s,n);const c=(0,ak.translate)([g.x+r,g.y+a,0],n);A.dontCutBoard||(this.boardGeom=(0,Yw.subtract)(this.boardGeom,c),this.copperDrills.push({geom:c,platedHoleIndex:this.platedHoleGeoms.length}));const h=GIA(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=wyA(g,e,{sizeDelta:2*OB}),o=wyA(g,e,{sizeDelta:-2*OB});if(!t||!o)return;A.dontCutBoard||(this.boardGeom=(0,Yw.subtract)(this.boardGeom,t),this.copperDrills.push({geom:t,platedHoleIndex:this.platedHoleGeoms.length}));const B=GIA(g,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(B)}}}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+OB,height:A});this.boardGeom=(0,Yw.subtract)(this.boardGeom,I);const e=(0,rr.cylinder)({center:[g.x,g.y,0],radius:g.hole_diameter/2+OB/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,o=.02,B=(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,ak.translate)([0,0,-n/2],(0,ZAg.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,Yw.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,Yw.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=B(I,e,A,g.hole_shape==="oval"),Q=B(I-2*o,e-2*o,A,g.hole_shape==="oval");if(C&&t!==0&&(C=(0,ak.rotateZ)(t*Math.PI/180,C)),Q&&t!==0&&(Q=(0,ak.rotateZ)(t*Math.PI/180,Q)),C){const i=(0,ak.translate)([g.x,g.y,0],C);this.boardGeom=(0,Yw.subtract)(this.boardGeom,i)}if(Q){const i=(0,ak.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=TWt({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,Yw.intersect)(this.boardClipGeom,I),e=(0,TAg.colorize)($E.copper,e)),A=this.viaGeoms.length,this.viaGeoms.push(e)}if(typeof g.hole_diameter=="number"){const I=ZWt({x:g.x,y:g.y,holeDiameter:g.hole_diameter,thickness:this.ctx.pcbThickness});this.boardGeom=(0,Yw.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,kmI.measureBoundingBox)(e.geom)})),A=(e,t,o)=>{const B=(0,kmI.measureBoundingBox)(e),C=g.filter(Q=>Q[o]!==t&&[0,1,2].every(i=>Q.bounds[0][i]<=B[1][i]&&Q.bounds[1][i]>=B[0][i])).map(Q=>Q.geom);return(0,TAg.colorize)($E.copper,C.length?(0,Yw.subtract)(e,(0,Yw.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=qAg(this.board);this.boardGeom=(0,TAg.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}},jWt=g=>{const[A,I]=X.useState(null),e=X.useRef(!1);return X.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 B=JWt(g);I(B);const C=new VWt(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},zWt=({children:g,parent:A,position:I,rotation:e,scale:t,color:o,fontSize:B,anchorX:C,anchorY:Q,depthOffset:i})=>{const{rootObject:E}=RD(),n=X.useMemo(()=>{const s=new dqA;return s.text=g,I&&s.position.fromArray(I),e&&s.rotation.fromArray(e),t&&s.scale.fromArray(t),s.color=o||"white",s.fontSize=B||1,s.anchorX=C||"center",s.anchorY=Q||"middle",s.depthOffset=i||0,s.font=null,s.sync(),s},[g,I,e,t,o,B,C,Q,i]);return X.useEffect(()=>{const s=A||E;if(!(!s||!n))return s.add(n),()=>{s.remove(n),n.dispose()}},[E,A,n]),null},RmI=({error:g,cad_component:A})=>{const{rootObject:I}=RD(),[e,t]=X.useState(!1),[o,B]=X.useState(null),C=X.useCallback(n=>{n?.mousePosition?(t(!0),B(n.mousePosition)):(t(!1),B(null))},[]),Q=X.useCallback(()=>{t(!1),B(null)},[]),i=X.useMemo(()=>A?.position?[A.position.x,A.position.y,A.position.z].map(s=>Number.isNaN(s)?0:s):[0,0,0],[A]),E=X.useMemo(()=>{const n=new Yc;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,X.useEffect(()=>{if(I)return I.add(E),()=>{I.remove(E)}},[I,E]),q.jsxs(q.Fragment,{children:[q.jsxs(wIA,{isHovered:e,onHover:C,onUnhover:Q,object:E,children:[q.jsx(XWt,{parent:E}),q.jsx(zWt,{parent:E,scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:`${g.toString().slice(0,50)}...`})]}),e&&o?q.jsx(gmI,{position:o,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]})},XWt=({parent:g})=>{const A=X.useMemo(()=>{const I=new Ko(new ik(.5,.5,.5),new Hs({depthTest:!1,transparent:!0,color:"red",opacity:.5}));return I.renderOrder=999999,I.rotation.fromArray([Math.PI/4,Math.PI/4,0]),I},[]);return X.useEffect(()=>(g.add(A),()=>{g.remove(A)}),[g,A]),null},$Wt=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 o=1;o<g.length;o++){const B=g[o];B.x<A&&(A=B.x),B.y<I&&(I=B.y),B.x>e&&(e=B.x),B.y>t&&(t=B.y)}return{minX:A,minY:I,maxX:e,maxY:t}};function Sy(g){if(g.outline&&g.outline.length>=3){const B=$Wt(g.outline);return{...B,width:B.maxX-B.minX,height:B.maxY-B.minY,centerX:(B.minX+B.maxX)/2,centerY:(B.minY+B.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 AVt(g,A,I){const e=VAg(g);if(!e.length)return[];const t=Sy(A),o=Math.floor(t.width*I),B=Math.floor(t.height*I);if(o<=0||B<=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=o,E.height=B;const n=E.getContext("2d");if(!n)continue;const s=new XE(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,o,B).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)*o/t.width,l=(t.maxY-a.y)*B/t.height,D=c*o/t.width,d=c*B/t.height;if(D<=0||d<=0)continue;const y=Math.max(0,Math.floor(h-D)),w=Math.min(o-1,Math.ceil(h+D)),u=Math.max(0,Math.floor(l-d)),G=Math.min(B-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*o+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 gVt({ctx:g,vias:A,boardData:I,layer:e,width:t,height:o}){if(!A.length)return;const B=Sy(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-B.minX)*t/B.width,i=(e==="top"?B.maxY-C.y:C.y-B.minY)*o/B.height;g.beginPath(),g.ellipse(Q,i,C.hole_diameter/2*t/B.width,C.hole_diameter/2*o/B.height,0,0,Math.PI*2),g.fill()}g.restore()}function IVt({layer:g,circuitJson:A,boardData:I,copperColor:e,traceTextureResolution:t}){const B=Xo(A).pcb_smtpad.list().filter(w=>w.layer===g);if(B.length===0)return null;const C=Xo(A).pcb_hole.list(),Q=Xo(A).pcb_plated_hole.list().filter(w=>!Array.isArray(w.layers)||w.layers.includes(g)),i=Xo(A).pcb_via.list().filter(w=>!Array.isArray(w.layers)||w.layers.includes(g)),E=Xo(A).pcb_cutout.list(),n=[...C,...Q,...i],s=g==="top"?"top_copper":"bottom_copper",r=Sy(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 XE(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([...B,...n,...E],{layers:[s],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});const y=new Ek(a);return y.generateMipmaps=!0,y.minFilter=fl,y.magFilter=Ln,y.anisotropy=16,y.needsUpdate=!0,y}var eVt=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 tVt({layer:g,circuitJson:A,panelData:I,outlineColor:e="black",traceTextureResolution:t}){const o=eVt(A);if(!o)return null;const C=Xo(A).pcb_board.list().filter(c=>c.pcb_panel_id===o||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 Ek(Q);return a.generateMipmaps=!0,a.minFilter=fl,a.magFilter=Ln,a.anisotropy=16,a.needsUpdate=!0,a}function oVt({layer:g,circuitJson:A,boardData:I,traceColor:e,traceTextureResolution:t}){const o=Xo(A).pcb_trace.list(),B=Xo(A).pcb_via.list(),C=Xo(A).pcb_plated_hole.list(),Q=g==="top"?"top_copper":"bottom_copper",i=o.filter(y=>PSg(y).includes(Q));if(i.length===0)return null;const E=C.filter(y=>y.layers.includes(g)),n=[...i,...B,...E],s=Sy(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 XE(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 Ek(r);return d.generateMipmaps=!0,d.minFilter=fl,d.magFilter=Ln,d.anisotropy=16,d.needsUpdate=!0,d}var BVt=g=>{const[A=0,I=0,e=0]=g;return`rgb(${Math.round(A*255)}, ${Math.round(I*255)}, ${Math.round(e*255)})`},CVt=8;function NmI({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=O2,copperColor:t=BVt($E.copper),onlyCoveredBySoldermask:o=!1}){const B=A.filter(p=>p.type==="pcb_copper_pour"),C=g==="top"?"top_copper":"bottom_copper",Q=B.filter(p=>p.layer===g&&(!o||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=Sy(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 XE(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 x=1;x<CVt;x+=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),o||w(G,y);const m=new Ek(a);return m.generateMipmaps=!0,m.minFilter=fl,m.magFilter=Ln,m.anisotropy=16,m.needsUpdate=!0,m}var xmI=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},QVt=({ctx:g,layer:A,bounds:I,elements:e,copperColor:t})=>{const o=A==="top"?"top_copper":"bottom_copper",B=new XE(g);B.configure({colorOverrides:{copper:{top:t,bottom:t,inner1:t,inner2:t,inner3:t,inner4:t,inner5:t,inner6:t,inner7:t,inner8:t}}}),xmI(B,I),B.drawElements(e,{layers:[o]});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 XE(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)"}}}),xmI(E,I),E.drawElements(C.map(n=>({...n,is_knockout:!1})),{layers:[o]}),g.save(),g.globalCompositeOperation="destination-out",g.drawImage(Q,0,0),g.restore()};function iVt({layer:g,circuitJson:A,boardData:I,copperColor:e="rgb(230, 153, 51)",traceTextureResolution:t=O2}){const o=A.filter(s=>s.type==="pcb_copper_text"&&"layer"in s&&s.layer===g);if(o.length===0)return null;const B=Sy(I),C=Math.floor(B.width*t),Q=Math.floor(B.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)),QVt({ctx:E,layer:g,bounds:B,elements:o,copperColor:e});const n=new Ek(i);return n.generateMipmaps=!0,n.minFilter=fl,n.magFilter=Ln,n.anisotropy=16,n.needsUpdate=!0,n}var FmI=25.4,EVt=FmI/1e3,nVt=/^\s*(-?\d*(?:\.\d+)?)(?:\s*(mm|mil|inch|in|"))?\s*$/i;function sVt(g){if(!g)return;const A=g.trim().toLowerCase();return A==='"'||A==="inch"?"in":A}function GyA(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(nVt);if(!I){const C=Number.parseFloat(A);return Number.isFinite(C)?C:void 0}const[,e,t]=I,o=Number.parseFloat(e||"0");if(!Number.isFinite(o))return;switch(sVt(t)){case"mil":return o*EVt;case"in":return o*FmI;case"mm":case void 0:return o;default:return o}}function qs(g,A){const I=GyA(g);return I===void 0?A:I}var aVt="rgb(255,243,204)",cr="rgba(0,0,0,0)",rVt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},cVt=g=>g.type==="pcb_fabrication_note_rect"?{...g,width:GyA(g.width)??0,height:GyA(g.height)??0,stroke_width:qs(g.stroke_width,.1),corner_radius:GyA(g.corner_radius)}:g.type==="pcb_fabrication_note_path"?{...g,stroke_width:qs(g.stroke_width,.1)}:g.type==="pcb_fabrication_note_text"?{...g,font_size:qs(g.font_size,1)}:g.type==="pcb_fabrication_note_dimension"?{...g,font_size:qs(g.font_size,1),arrow_size:qs(g.arrow_size,1),offset_distance:qs(g.offset_distance,0)}:g,hVt=({ctx:g,layer:A,bounds:I,elements:e})=>{const t=`${A}_fabrication_note`,o=e.map(cVt),B=new XE(g);B.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:aVt}}),rVt(B,I),B.drawElements(o,{layers:[t]})},lVt=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}),DVt=(g,A)=>{const I=Math.min(g.minX,A.minX),e=Math.max(g.maxX,A.maxX),t=Math.min(g.minY,A.minY),o=Math.max(g.maxY,A.maxY);return{minX:I,maxX:e,minY:t,maxY:o,width:e-I,height:o-t,centerX:(I+e)/2,centerY:(t+o)/2}},myA=(g,A)=>{const I=g.filter(B=>B.type==="pcb_panel"),e=g.filter(B=>B.type==="pcb_board"),t=I.find(B=>B.pcb_panel_id===A.pcb_board_id)??I[0];return t&&t.width>0&&t.height>0?lVt(t):(e.length>1?e:[A]).map(B=>Sy(B)).reduce((B,C)=>DVt(B,C))},dVt=(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 yVt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=O2}){const t=A.filter(n=>dVt(n,g));if(t.length===0)return null;const o=myA(A,I),B=Math.floor(o.width*e),C=Math.floor(o.height*e);if(B<=0||C<=0)return null;const Q=document.createElement("canvas");Q.width=B,Q.height=C;const i=Q.getContext("2d");if(!i)return null;g==="bottom"&&(i.translate(0,C),i.scale(1,-1)),hVt({ctx:i,layer:g,bounds:o,elements:t});const E=new Ek(Q);return E.generateMipmaps=!0,E.minFilter=fl,E.magFilter=Ln,E.anisotropy=16,E.needsUpdate=!0,E}var wVt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},uVt=({ctx:g,layer:A,bounds:I,elements:e,keepoutColor:t})=>{const o=A==="top"?"top_copper":"bottom_copper",B=new XE(g);B.configure({colorOverrides:{keepout:{top:t,bottom:t}}}),wVt(B,I),B.drawElements(e,{layers:[o],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1})},GVt=(g,A)=>g.type!=="pcb_keepout"?!1:!("layers"in g)||!Array.isArray(g.layers)?!0:g.layers.includes(A);function mVt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=O2,keepoutColor:t=g==="bottom"?"#4b72d2":"#d24b4b"}){const o=A.filter(s=>GVt(s,g));if(o.length===0)return null;const B=Sy(I),C=Math.floor(B.width*e),Q=Math.floor(B.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)),uVt({ctx:E,layer:g,bounds:B,elements:o,keepoutColor:t});const n=new Ek(i);return n.generateMipmaps=!0,n.minFilter=fl,n.magFilter=Ln,n.anisotropy=16,n.needsUpdate=!0,n}var Ha="rgba(0,0,0,0)",pVt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},kVt=g=>g.type==="pcb_note_line"?{...g,x1:qs(g.x1,0),y1:qs(g.y1,0),x2:qs(g.x2,0),y2:qs(g.y2,0),stroke_width:qs(g.stroke_width,.1)}:g.type==="pcb_note_rect"?{...g,center:{x:qs(g.center.x,0),y:qs(g.center.y,0)},width:qs(g.width,0),height:qs(g.height,0),stroke_width:qs(g.stroke_width,.1),corner_radius:qs(g.corner_radius,0)}:g.type==="pcb_note_text"?{...g,anchor_position:{x:qs(g.anchor_position.x,0),y:qs(g.anchor_position.y,0)},font_size:qs(g.font_size,1)}:g.type==="pcb_note_path"?{...g,route:g.route.map(A=>({...A,x:qs(A.x,0),y:qs(A.y,0)})),stroke_width:qs(g.stroke_width,.1)}:g.type==="pcb_note_dimension"?{...g,from:{x:qs(g.from.x,0),y:qs(g.from.y,0)},to:{x:qs(g.to.x,0),y:qs(g.to.y,0)},font_size:qs(g.font_size,1),arrow_size:qs(g.arrow_size,1),offset_distance:qs(g.offset_distance,0)}:g,MVt=({ctx:g,bounds:A,elements:I})=>{const e=I.map(kVt),t=new XE(g);t.configure({colorOverrides:{copper:{top:Ha,bottom:Ha,inner1:Ha,inner2:Ha,inner3:Ha,inner4:Ha,inner5:Ha,inner6:Ha,inner7:Ha,inner8:Ha},copperPour:{top:Ha,bottom:Ha},drill:Ha,boardOutline:Ha,substrate:Ha,keepout:{top:Ha,bottom:Ha},courtyard:{top:Ha,bottom:Ha},soldermask:{top:Ha,bottom:Ha},soldermaskWithCopperUnderneath:{top:Ha,bottom:Ha},soldermaskOverCopper:{top:Ha,bottom:Ha},silkscreen:{top:Ha,bottom:Ha},fabricationNote:Ha}}),pVt(t,A),t.drawElements(e)},SVt=(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 fVt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=O2}){const t=A.filter(n=>SVt(n,g));if(t.length===0)return null;const o=myA(A,I),B=Math.floor(o.width*e),C=Math.floor(o.height*e);if(B<=0||C<=0)return null;const Q=document.createElement("canvas");Q.width=B,Q.height=C;const i=Q.getContext("2d");if(!i)return null;g==="bottom"&&(i.translate(0,C),i.scale(1,-1)),MVt({ctx:i,bounds:o,elements:t});const E=new Ek(Q);return E.generateMipmaps=!0,E.minFilter=fl,E.magFilter=Ln,E.anisotropy=16,E.needsUpdate=!0,E}var RVt="rgb(255,243,204)",bc="rgba(0,0,0,0)",UmI=(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,o=A==="top"?I?.default_via_tented_on_top:I?.default_via_tented_on_bottom;return e??t??o??!1},NVt=(g,A,I,e)=>g.type==="pcb_cutout"?!0:g.type==="pcb_via"?!e||!UmI(g,A,I):g.type==="pcb_hole"||g.type==="pcb_plated_hole"?!e||g.is_covered_with_solder_mask!==!0:!1,xVt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},FVt=({ctx:g,layer:A,bounds:I,elements:e,circuitJson:t,silkscreenColor:o,soldermaskVisible:B})=>{const C=A==="top"?"top_silkscreen":"bottom_silkscreen",Q=new XE(g);Q.configure({colorOverrides:{copper:{top:bc,bottom:bc,inner1:bc,inner2:bc,inner3:bc,inner4:bc,inner5:bc,inner6:bc,inner7:bc,inner8:bc},copperPour:{top:bc,bottom:bc},drill:bc,boardOutline:bc,substrate:bc,keepout:{top:bc,bottom:bc},courtyard:{top:bc,bottom:bc},soldermask:{top:bc,bottom:bc},soldermaskWithCopperUnderneath:{top:bc,bottom:bc},soldermaskOverCopper:{top:bc,bottom:bc},silkscreen:{top:o,bottom:o},fabricationNote:RVt}}),xVt(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"&&(!B||!UmI(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 NVt(E,A,n,B)?[E]:[]});Q.drawElements(i,{layers:[C],clipContextElements:t,clearDrillHoles:!0})},UVt=(g,A)=>!("layer"in g)||g.layer!==A?!1:g.type.startsWith("pcb_silkscreen_");function JVt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=O2,silkscreenColor:t="rgb(255,255,255)",soldermaskVisible:o=!0}){const B=A.filter(r=>UVt(r,g));if(B.length===0)return null;const C=myA(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)),FVt({ctx:n,layer:g,bounds:C,elements:B,circuitJson:A,silkscreenColor:t,soldermaskVisible:o});const s=new Ek(E);return s.generateMipmaps=!0,s.minFilter=fl,s.magFilter=Ln,s.anisotropy=16,s.needsUpdate=!0,s}var mIA=g=>{const[A=0,I=0,e=0]=g;return`rgb(${Math.round(A*255)}, ${Math.round(I*255)}, ${Math.round(e*255)})`},PVt=g=>{const A=mIA(GWt[g.material]??$E.fr4SolderMaskGreen),I=g.material==="fr1"?mIA($E.fr1TracesWithMaskCopper):mIA($E.fr4TracesWithMaskGreen),e=mmI(g.solder_mask_color);if(!e)return{soldermask:A,soldermaskOverCopper:I,copper:mIA($E.copper),transparent:"rgba(0,0,0,0)"};const t=new oo().setRGB($E.copper[0],$E.copper[1],$E.copper[2],Ck);return{soldermask:pmI(e),soldermaskOverCopper:pmI(FWt({soldermaskColor:e,copperColor:t,soldermaskOpacity:NWt(g.solder_mask_color)})),copper:mIA($E.copper),transparent:"rgba(0,0,0,0)"}},JmI=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},KVt=g=>g.type.startsWith("pcb_note_")||g.type.startsWith("pcb_fabrication_note_"),LVt=({ctx:g,layer:A,bounds:I,elements:e,boardData:t})=>{const o=PVt(t),B=A==="top"?"top_copper":"bottom_copper",C=new XE(g);C.configure({colorOverrides:{copper:{top:o.transparent,bottom:o.transparent,inner1:o.transparent,inner2:o.transparent,inner3:o.transparent,inner4:o.transparent,inner5:o.transparent,inner6:o.transparent,inner7:o.transparent,inner8:o.transparent},drill:o.transparent,boardOutline:o.transparent,substrate:o.transparent,keepout:{top:o.transparent,bottom:o.transparent},fabricationNote:o.transparent,silkscreen:{top:o.transparent,bottom:o.transparent},courtyard:{top:o.transparent,bottom:o.transparent},soldermask:{top:o.soldermask,bottom:o.soldermask},soldermaskWithCopperUnderneath:{top:o.soldermaskOverCopper,bottom:o.soldermaskOverCopper},soldermaskOverCopper:{top:o.soldermaskOverCopper,bottom:o.soldermaskOverCopper}}}),JmI(C,I);const Q=e.filter(E=>E.type!=="pcb_keepout"&&!KVt(E));C.drawElements(Q,{layers:[B],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 XE(g);E.configure({colorOverrides:{copper:{top:o.copper,bottom:o.copper,inner1:o.copper,inner2:o.copper,inner3:o.copper,inner4:o.copper,inner5:o.copper,inner6:o.copper,inner7:o.copper,inner8:o.copper}}}),JmI(E,I),E.drawElements(i,{layers:[B]}),g.restore()}};function YVt({layer:g,circuitJson:A,boardData:I,traceTextureResolution:e=O2}){const t=myA(A,I),o=Math.floor(t.width*e),B=Math.floor(t.height*e);if(o<=0||B<=0)return null;const C=document.createElement("canvas");C.width=o,C.height=B;const Q=C.getContext("2d");if(!Q)return null;g==="bottom"&&(Q.translate(0,B),Q.scale(1,-1));const i=A.some(n=>n.type==="pcb_board")?A:[I,...A];LVt({ctx:Q,layer:g,bounds:t,elements:i,boardData:I});const E=new Ek(C);return E.generateMipmaps=!0,E.minFilter=fl,E.magFilter=Ln,E.anisotropy=16,E.needsUpdate=!0,E}var _Vt=(g,A)=>{g.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},bVt=({ctx:g,layer:A,bounds:I,elements:e,copperColor:t})=>{const o=A==="top"?"top_copper":"bottom_copper",B="rgba(0,0,0,0)",C=new XE(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:B,boardOutline:B,substrate:B,keepout:{top:B,bottom:B},fabricationNote:B,silkscreen:{top:B,bottom:B},courtyard:{top:B,bottom:B},soldermask:{top:B,bottom:B},soldermaskWithCopperUnderneath:{top:B,bottom:B},soldermaskOverCopper:{top:B,bottom:B}}}),_Vt(C,I),C.drawElements(e,{layers:[o]})};function HVt({layer:g,circuitJson:A,boardData:I,copperColor:e="rgb(230, 153, 51)",traceTextureResolution:t=O2}){const o=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(o.length===0)return null;const B=Sy(I),C=Math.floor(B.width*t),Q=Math.floor(B.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)),bVt({ctx:E,layer:g,bounds:B,elements:o,copperColor:e});const n=new Ek(i);return n.generateMipmaps=!0,n.minFilter=fl,n.magFilter=Ln,n.anisotropy=16,n.needsUpdate=!0,n}var PmI=g=>{const[A=0,I=0,e=0]=g;return`rgb(${Math.round(A*255)}, ${Math.round(I*255)}, ${Math.round(e*255)})`},zAg=g=>Math.max(0,Math.min(255,g)),vVt=(g,A,I,e={})=>{const t=g.getImageData(0,0,A,I),o=t.data,B=Math.max(A-1,1),C=Math.max(I-1,1);for(let Q=0;Q<o.length;Q+=4){if((o[Q+3]??0)<16)continue;const E=o[Q]??0,n=o[Q+1]??0,s=o[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/B,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 x=D-.36,N=d-.22,U=Math.max(0,1-Math.hypot(x,N)/.38);return U*U*.07})():0,m=(E*.9+3)*u,p=(n*1.08+15)*u,k=(s*1.28+13)*u;o[Q]=zAg(m*(1-G)+255*G),o[Q+1]=zAg(p*(1-G)+255*G),o[Q+2]=zAg(k*(1-G)+255*G)}g.putImageData(t,0,0)},qVt=({textures:g,boardData:A,traceTextureResolution:I,layer:e,openViaHoles:t})=>{if(!g.some(s=>s?.image))return null;const B=Sy(A),C=Math.floor(B.width*I),Q=Math.floor(B.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)}gVt({ctx:E,vias:t,boardData:A,layer:e,width:C,height:Q}),vVt(E,C,Q,{includeReflection:e==="top"});const n=new Ek(i);return n.generateMipmaps=!1,n.minFilter=Ln,n.magFilter=Ln,n.premultiplyAlpha=!0,n.anisotropy=16,n.needsUpdate=!0,n},TVt=({textures:g,soldermaskTexture:A,boardData:I,traceTextureResolution:e})=>{if(!A?.image||!g.some(E=>E?.image))return null;const t=Sy(I),o=Math.floor(t.width*e),B=Math.floor(t.height*e);if(o<=0||B<=0)return null;const C=document.createElement("canvas");C.width=o,C.height=B+1;const Q=C.getContext("2d");if(!Q)return null;for(const E of g)E?.image&&Q.drawImage(E.image,0,0,o,B);Q.globalCompositeOperation="destination-in",Q.drawImage(A.image,0,0,o,B),Q.globalCompositeOperation="source-over";const i=new Ek(C);return i.colorSpace=Bx,i.generateMipmaps=!1,i.minFilter=Ln,i.magFilter=Ln,i.premultiplyAlpha=!1,i.needsUpdate=!0,i};function KmI({circuitJson:g,boardData:A,traceTextureResolution:I,visibility:e}){const t=PmI($E.copper),o="rgb(255,255,255)",B=PmI($E.copper),C=e?.boardBody??!0,Q=AVt(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?YVt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,d=c?oVt({layer:r,circuitJson:g,boardData:A,traceColor:t,traceTextureResolution:I}):null,y=c?NmI({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I,copperColor:B}):null,w=a&&c?NmI({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I,copperColor:B,onlyCoveredBySoldermask:!0}):null,u=c?iVt({layer:r,circuitJson:g,boardData:A,copperColor:B,traceTextureResolution:I}):null,G=c?IVt({layer:r,circuitJson:g,boardData:A,copperColor:B,traceTextureResolution:I}):null,m=c?HVt({layer:r,circuitJson:g,boardData:A,copperColor:B,traceTextureResolution:I}):null,p=h?JVt({layer:r,circuitJson:g,boardData:A,silkscreenColor:o,traceTextureResolution:I,soldermaskVisible:a}):null,k=h?yVt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,R=e?.pcbNotes??!1?fVt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,x=C?tVt({layer:r,circuitJson:g,panelData:A,traceTextureResolution:I}):null,N=l?mVt({layer:r,circuitJson:g,boardData:A,traceTextureResolution:I}):null,U=qVt({openViaHoles:Q,textures:[y,d,G,m,D,u,p,k,R,x,N],boardData:A,traceTextureResolution:I,layer:r}),K=a&&c?TVt({textures:[d,w],soldermaskTexture:D,boardData:A,traceTextureResolution:I}):null;return{boardTexture:U,maskedCopperTexture:K}},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 UR={bumpScale:.12,normalScale:.08,roughnessBias:.015,clearcoat:.08,clearcoatRoughness:.55},pyA={roughness:.42,metalness:.5,roughnessVariance:.035,detailStrength:.028},kyA=.22,ZVt=.7,OVt=.86,LmI={height:kyA,microSurfaceWeight:1,roughness:.7,metalness:.015,isExposedCopper:!1,isMaskedCopper:!1},WVt={height:ZVt,microSurfaceWeight:.9,roughness:.54,metalness:.025,isExposedCopper:!1,isMaskedCopper:!0},XAg=g=>Math.max(0,Math.min(1,g)),YmI=g=>1-g,pIA=(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},_mI=g=>g*g*(3-2*g),$Ag=(g,A,I)=>g+(A-g)*I,Agg=(g,A,I,e)=>{const t=g/I,o=A/I,B=Math.floor(t),C=Math.floor(o),Q=_mI(t-B),i=_mI(o-C),E=$Ag(pIA(B,C,e),pIA(B+1,C,e),Q),n=$Ag(pIA(B,C+1,e),pIA(B+1,C+1,e),Q);return $Ag(E,n,i)},VVt=(g,A,I)=>{const e=(Agg(g,A,7,I+31)-.5)*.55,t=Math.sin(g*.12+Agg(g,A,44,I+37)*2)*.22;return(e+t)*pyA.detailStrength},jVt=(g,A,I)=>{const e=(pIA(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},zVt=(g,A,I,e)=>e?WVt:xWt({red:g,green:A,blue:I})?LmI:g>120&&A>70&&I<150&&g>A*1.05&&A>I*1.15?{height:OVt,microSurfaceWeight:.9,roughness:pyA.roughness,metalness:pyA.metalness,isExposedCopper:!0,isMaskedCopper:!1}:g>170&&A>170&&I>160?{height:kyA,microSurfaceWeight:.4,roughness:.76,metalness:0,isExposedCopper:!1,isMaskedCopper:!1}:A>g*1.25&&A>I*1.05&&g<110&&A<180&&I<130?LmI:{height:kyA,microSurfaceWeight:.7,roughness:.58,metalness:.015,isExposedCopper:!1,isMaskedCopper:!1},MyA=g=>{const A=new Ek(g);return A.colorSpace=Bx,A.generateMipmaps=!1,A.minFilter=Ln,A.magFilter=Ln,A.wrapS=Gm,A.wrapT=Gm,A.needsUpdate=!0,A},bmI=(g,A)=>{const I=g.image;if(!I?.width||!I.height)return null;const{width:e,height:t}=I,o=I.getContext("2d");if(!o)return null;const B=A?.image,C=B?.getContext("2d"),Q=B?.width??0,i=B?.height??0,E=C&&Q&&i?C.getImageData(0,0,Q,i):null,n=o.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 x=0;x<s.length;x+=4){const N=x/4,U=N%e,K=Math.floor(N/e);if((s[x+3]??0)<16){r[N]=YmI(kyA);continue}const H=E?Math.min(Q-1,Math.floor(U/e*Q)):0,T=E?Math.min(i-1,Math.floor(K/t*i)):0,j=E?E.data[(T*Q+H)*4+3]??0:0,W=zVt(s[x]??0,s[x+1]??0,s[x+2]??0,j>=16),O=e+t,gA=W.isExposedCopper?VVt(U,K,O):W.isMaskedCopper?jVt(U,K,O):0,tA=XAg(YmI(W.height)+gA*W.microSurfaceWeight);r[N]=tA;const IA=tA*255;s[x]=s[x+1]=s[x+2]=IA,s[x+3]=255;const nA=(W.isExposedCopper?XAg(W.roughness+gA*.7+(Agg(U,K,36,O+17)-.5)*pyA.roughnessVariance):W.isMaskedCopper?XAg(W.roughness+gA+UR.roughnessBias):W.roughness)*255;y[x]=y[x+1]=y[x+2]=nA,y[x+3]=255;const DA=W.metalness*255;w[x]=w[x+1]=w[x+2]=DA,w[x+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=(x,N)=>r[Math.max(0,Math.min(t-1,N))*e+Math.max(0,Math.min(e-1,x))]??0;for(let x=0;x<t;x++)for(let N=0;N<e;N++){const U=(R(N+1,x)-R(N-1,x))*4,K=(R(N,x+1)-R(N,x-1))*4,_=1/Math.sqrt(U*U+K*K+1),H=(x*e+N)*4;S[H]=(-U*_*.5+.5)*255,S[H+1]=(-K*_*.5+.5)*255,S[H+2]=(_*.5+.5)*255,S[H+3]=255}return p.putImageData(k,0,0),{bumpMap:MyA(u),normalMap:MyA(m),roughnessMap:MyA(a),metalnessMap:MyA(c)}};function HmI(g,A){const{texture:I,maskedCopperMask:e,yOffset:t,isBottomLayer:o,usePolygonOffset:B=!1,renderOrder:C=0,isFaux:Q=!1}=g;if(!I)return null;const i=Sy(A),E=new pR(i.width,i.height);I.colorSpace=Ck;const n={map:I,transparent:!0,alphaTest:.08,side:vM,depthWrite:!0,polygonOffset:B,polygonOffsetFactor:B?-4:0,polygonOffsetUnits:B?-4:0,opacity:Q?dyA:1},s=bmI(I,e),r=new OM({...n,bumpMap:s?.bumpMap??null,bumpScale:UR.bumpScale,normalMap:s?.normalMap??null,normalScale:new ct(UR.normalScale,UR.normalScale),roughnessMap:s?.roughnessMap??null,roughness:1,metalnessMap:s?.metalnessMap??null,metalness:1,clearcoat:UR.clearcoat,clearcoatRoughness:UR.clearcoatRoughness,envMapIntensity:.18}),a=new Ko(E,r);return a.position.set(i.centerX,i.centerY,t),o&&a.rotation.set(Math.PI,0,0),a.name=`${o?"bottom":"top"}-board-texture-plane`,a.renderOrder=C,AS(a,{castShadow:!1,receiveShadow:!0}),a}function XVt(g,A,I,e=!1){const t=[];if(!g||!A||I===null)return t;const o=.005,B=HmI({texture:g.topBoard,maskedCopperMask:g.topMaskedCopper,yOffset:I/2+o,isBottomLayer:!1,usePolygonOffset:!0,renderOrder:1,isFaux:e},A);B&&t.push(B);const C=HmI({texture:g.bottomBoard,maskedCopperMask:g.bottomMaskedCopper,yOffset:-I/2-o,isBottomLayer:!0,usePolygonOffset:!0,renderOrder:1,isFaux:e},A);return C&&t.push(C),t}var vmI=g=>{const{boardBody:A,topCopper:I,bottomCopper:e,topSilkscreen:t,bottomSilkscreen:o,topMask:B,bottomMask:C,keepout:Q,pcbNotes:i}=g;return X.useMemo(()=>({boardBody:A,topCopper:I,bottomCopper:e,topSilkscreen:t,bottomSilkscreen:o,topMask:B,bottomMask:C,keepout:Q,pcbNotes:i}),[A,I,e,t,o,B,C,Q,i])},$Vt=4e6,Ajt=4096,gjt=1;function qmI(g,A,I={}){const{maxTexturePixels:e=$Vt,maxTextureDimension:t=Ajt,minTextureResolution:o=gjt}=I,B=Sy(g);if(!Number.isFinite(B.width)||!Number.isFinite(B.height)||B.width<=0||B.height<=0)return A;const C=Math.max(B.width,B.height),Q=t/C,i=Math.sqrt(e/(B.width*B.height)),E=Math.min(A,Q,i);return Math.max(o,E)}function Ijt({circuitJson:g,pcbThickness:A,isFaux:I=!1}){const{rootObject:e}=RD(),{visibility:t}=l5(),o=vmI(t),B=X.useMemo(()=>{const i=g.filter(s=>s.type==="pcb_panel"),E=Xo(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=X.useMemo(()=>B?qmI(B,O2):O2,[B]),Q=X.useMemo(()=>!B?.width||!B.height?null:KmI({circuitJson:g,boardData:B,traceTextureResolution:C,visibility:o}),[g,B,C,o]);return X.useEffect(()=>{if(!e||!B||!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 $r&&(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=Sy(B),m=new pR(G.width,G.height);c.colorSpace=Ck;const p={map:c,transparent:!0,alphaTest:.08,side:vM,depthWrite:w,polygonOffset:y,polygonOffsetFactor:y?-4:0,polygonOffsetUnits:y?-4:0,opacity:I?dyA:1},k=bmI(c,h),S=new OM({...p,bumpMap:k?.bumpMap??null,bumpScale:UR.bumpScale,normalMap:k?.normalMap??null,normalScale:new ct(UR.normalScale,UR.normalScale),roughnessMap:k?.roughnessMap??null,roughness:1,metalnessMap:k?.metalnessMap??null,metalness:1,clearcoat:UR.clearcoat,clearcoatRoughness:UR.clearcoatRoughness,envMapIntensity:.18}),R=new Ko(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,AS(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 Qk&&E(c.material);Q.topBoard?.dispose(),Q.bottomBoard?.dispose()}},[e,B,Q,A]),null}function ejt({stlUrl:g,stlData:A,mtlUrl:I,color:e,opacity:t=1,layerType:o}){const{rootObject:B}=RD(),[C,Q]=X.useState(null);X.useEffect(()=>{const E=new OLt;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=X.useMemo(()=>{if(!C)return null;const E=o==="board",n=new Hs({color:Array.isArray(e)?new oo(e[0],e[1],e[2]):e,transparent:t!==1,opacity:t,polygonOffset:E,polygonOffsetFactor:E?6:0,polygonOffsetUnits:E?6:0}),s=new Ko(C,n);return s.renderOrder=E?-1:1,AS(s,{castShadow:!E&&t===1,receiveShadow:!0}),s},[C,e,t,o]);return X.useEffect(()=>{if(!(!B||!i))return B.add(i),()=>{B.remove(i),i.geometry.dispose(),Array.isArray(i.material)?i.material.forEach(E=>E.dispose()):i.material.dispose()}},[B,i]),null}function tjt({stlData:g,color:A,opacity:I=1,layerType:e}){const{visibility:t}=l5();let o=!0;return e==="board"?o=t.boardBody:e==="top-copper"?o=t.topCopper:e==="bottom-copper"?o=t.bottomCopper:e==="top-silkscreen"?o=t.topSilkscreen:e==="bottom-silkscreen"&&(o=t.bottomSilkscreen),o?q.jsx(ejt,{stlData:g,color:A,opacity:I,layerType:e}):null}var ojt=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)},TmI=g=>g.filter(ojt),Bjt=({x:g,y:A,z:I})=>[g,A,I],ZmI=({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 o=new BI(t.x-e.x,t.y-e.y,t.z-e.z);if(o.lengthSq()<1e-12)return;o.normalize();const B=new BI(A.x-e.x,A.y-e.y,A.z-e.z);if(B.addScaledVector(o,-B.dot(o)),!(B.lengthSq()<1e-12))return B.normalize(),[B.x,B.y,B.z]},Cjt=g=>{const A=k_t(g.cableprinter_string),I=Y_t({definition:A,path:g.path.map(Bjt),startPin1Side:ZmI({path:g.path,pin1Position:g.from_connector_pin1_position,end:"start"}),endPin1Side:ZmI({path:g.path,pin1Position:g.to_connector_pin1_position,end:"end"})}),e=new Yc;e.name=`cad-cable-${g.cad_cable_id}`,e.userData={cadCableId:g.cad_cable_id,name:g.name};for(const t of I){let o=new Yn;o.setAttribute("position",new ZB(t.positions,3)),o.setIndex(t.indices),t.smooth||(o=o.toNonIndexed()),o.computeVertexNormals();const[B,C,Q,i]=t.color,E=new Hs({color:new oo(B,C,Q),metalness:t.material?.metalness??0,roughness:t.material?.roughness??.7,opacity:i,transparent:i<1,side:Sl}),n=new Ko(o,E);n.name=`${e.name}:${t.name}`,AS(n,{castShadow:!0,receiveShadow:!0}),e.add(n)}return e},Qjt=g=>{g.traverse(A=>{if(!(A instanceof Ko))return;A.geometry.dispose();const I=Array.isArray(A.material)?A.material:[A.material];for(const e of I)e.dispose()})},OmI=({cable:g})=>{const{rootObject:A}=RD(),I=X.useMemo(()=>{try{return Cjt(g)}catch(e){return console.error(`Failed to render CAD cable ${g.cad_cable_id}`,e),null}},[g]);return X.useEffect(()=>{if(I)return A.add(I),()=>{A.remove(I),Qjt(I)}},[I,A]),null};function WmI({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 ijt(g){const A=Xo(g).cad_component.list().filter(D=>D.pcb_component_id),I=Xo(g).pcb_smtpad.list(),e=Xo(g).pcb_hole.list(),t=Xo(g).pcb_plated_hole.list(),o=Xo(g).pcb_via.list();if(A.length===0&&I.length===0&&e.length===0&&t.length===0&&o.length===0)return null;const B=[...e,...t,...o,...I],C=UF(B);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 VmI(g){if(Xo(g).pcb_board.list().length>0)return g;const I=ijt(g);if(!I)return g;const t=I.thickness/2;return[...g.map(B=>{if(B.type==="cad_component"&&B.pcb_component_id){const C=B;if(C.position){const Q=C.position.z??0;return{...C,position:{...C.position,z:Q+t}}}}return B}),I]}var Ejt=X.forwardRef(({circuitJson:g,children:A,autoRotateDisabled:I,clickToInteractEnabled:e,onUserInteraction:t,onCameraControllerReady:o,resolveStaticAsset:B,referenceObject:C,hiddenCadComponentIds:Q},i)=>{const E=NAg(A),n=X.useMemo(()=>VmI(g??E),[g,E]),s=jWt(n),r=X.useMemo(()=>{if(!n)return!1;try{const u=Xo(n).pcb_board.list()[0];return!!u&&u.pcb_board_id==="faux-board"}catch{return!1}},[n]),a=X.useMemo(()=>{if(n)try{const u=Xo(n).pcb_board.list()[0];if(!u)return;const G=Sy(u);return{width:G.width,height:G.height}}catch(u){console.error(u);return}},[n]),c=X.useMemo(()=>{if(n)try{const u=Xo(n).pcb_board.list()[0];if(!u)return;const G=Sy(u);return{x:G.centerX,y:G.centerY}}catch(u){console.error(u);return}},[n]),h=X.useMemo(()=>{if(!n)return;const u=Xo(n).pcb_board.list()[0];if(u)return JSON.stringify({pcbBoardId:u.pcb_board_id,center:c,dimensions:a})},[n,c,a]),l=X.useMemo(()=>WmI({boardDimensions:a,boardCenter:c}),[a,c]),D=AmI(n),{stls:d}=cWt(s),y=Xo(n).cad_component.list().filter(u=>!Q?.has(u.cad_component_id)),w=TmI(n);return q.jsxs(umI,{ref:i,autoRotateDisabled:I,initialCameraPosition:l,clickToInteractEnabled:e,boardDimensions:a,boardCenter:c,cameraSessionScope:h,referenceObject:C,onUserInteraction:t,onCameraControllerReady:o,children:[d.map(({stlData:u,color:G,layerType:m},p)=>q.jsx(tjt,{stlData:u,color:G,opacity:p===0?r?.8:.95:1,layerType:m},`board-${p}`)),q.jsx(Ijt,{circuitJson:n,pcbThickness:D,isFaux:r}),y.map(u=>q.jsx(KAg,{fallback:({error:G})=>q.jsx(RmI,{cad_component:u,error:G}),children:q.jsx(imI,{cad_component:u,circuitJson:n,resolveStaticAsset:B},u.cad_component_id)},u.cad_component_id)),w.map(u=>q.jsx(OmI,{cable:u},u.cad_cable_id))]})}),SyA=new Set,ggg=!1;function njt(g,A,I=2){const e=g.length;SyA.size&&SyA.clear();let t=sjt(g,0,e,I,!0);const o=[];if(!t||t.next===t.prev)return o;let B=0,C=0,Q=0;if(g.length>80*I){B=g[0],C=g[1];let i=B,E=C;for(let n=I;n<e;n+=I){const s=g[n],r=g[n+1];s<B&&(B=s),r<C&&(C=r),s>i&&(i=s),r>E&&(E=r)}Q=Math.max(i-B,E-C),Q=Q!==0?32767/Q:0}return Igg(t,o,B,C,Q),o}function sjt(g,A,I,e,t){let o=null;if(t===Gjt(g,A,I,e)>0)for(let B=A;B<I;B+=e)o=zmI(B/e|0,g[B],g[B+1],o);else for(let B=I-e;B>=A;B-=e)o=zmI(B/e|0,g[B],g[B+1],o);return o&&ogg(o,o.next)&&(SIA(o),o=o.next),o}function fyA(g,A=g){const I=A===g;let e=g,t;do t=!1,e!==e.next&&(SyA.size===0||!SyA.has(e))&&(ogg(e,e.next)||fy(e.prev,e,e.next)===0)?((I||e===A)&&(A=e.prev),ggg=!0,SIA(e),e=e.prev,t=!0):(I||e!==A)&&(e=e.next,t=!I);while(t||e!==A);return A}function Igg(g,A,I,e,t){t&&ljt(g,I,e,t);let o=g,B=!1;for(;g.prev!==g.next;){const C=g.prev,Q=g.next;if(fy(C,g,Q)<0&&(t?rjt(g,I,e,t):ajt(g))){A.push(C.i,g.i,Q.i),SIA(g),g=Q,o=Q;continue}if(g=Q,g===o){if(ggg=!1,g=fyA(g),ggg){o=g;continue}if(!B){g=cjt(g,A),o=g,B=!0;continue}hjt(g,A,I,e,t);break}}}function ajt(g){const A=g.prev,I=g,e=g.next,t=A.x,o=I.x,B=e.x,C=A.y,Q=I.y,i=e.y,E=Math.min(t,o,B),n=Math.min(C,Q,i),s=Math.max(t,o,B),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)&&tgg(t,C,o,Q,B,i,a.x,a.y)&&fy(a.prev,a,a.next)>=0)return!1;a=a.next}return!0}function rjt(g,A,I,e){const t=g.prev,o=g,B=g.next,C=t.x,Q=o.x,i=B.x,E=t.y,n=o.y,s=B.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=egg(r,a,A,I,e),D=egg(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!==B&&!(C===d.x&&E===d.y)&&tgg(C,E,Q,n,i,s,d.x,d.y)&&fy(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!==B&&!(C===y.x&&E===y.y)&&tgg(C,E,Q,n,i,s,y.x,y.y)&&fy(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function cjt(g,A){let I=g,e=!1;do{const t=I.prev,o=I.next.next;jmI(t,I,I.next,o,!1)&&xyA(t,o)&&xyA(o,t)&&(A.push(t.i,I.i,o.i),SIA(I),SIA(I.next),I=g=o,e=!0),I=I.next}while(I!==g);return e?fyA(I):I}function hjt(g,A,I,e,t){let o=g;do{let B=o.next.next;for(;B!==o.prev;){if(o.i!==B.i&&djt(o,B)){let C=ujt(o,B);o=fyA(o,o.next),C=fyA(C,C.next),Igg(o,A,I,e,t),Igg(C,A,I,e,t);return}B=B.next}o=o.next}while(o!==g)}var gS=[],M7=[],d5=new Uint32Array(0),kIA=new Uint32Array(0),MIA=new Uint32Array(256);function ljt(g,A,I,e){let t=g,o=0;do t.z=egg(t.x,t.y,A,I,e),gS[o++]=t,t=t.next;while(t!==g);Djt(o);let B=null;for(let C=0;C<o;C++){const Q=gS[C];Q.prevZ=B,B&&(B.nextZ=Q),B=Q}B.nextZ=null,gS.fill(null,0,o),M7.fill(null,0,o)}function Djt(g){if(g<=32){for(let A=1;A<g;A++){const I=gS[A],e=I.z;let t=A-1;for(;t>=0&&gS[t].z>e;)gS[t+1]=gS[t],t--;gS[t+1]=I}return}d5.length<g&&(d5=new Uint32Array(g),kIA=new Uint32Array(g),M7=new Array(g));for(let A=0;A<g;A++)d5[A]=gS[A].z;RyA(g,gS,d5,M7,kIA,0),RyA(g,M7,kIA,gS,d5,8),RyA(g,gS,d5,M7,kIA,16),RyA(g,M7,kIA,gS,d5,24)}function RyA(g,A,I,e,t,o){MIA.fill(0);for(let C=0;C<g;C++)MIA[I[C]>>>o&255]++;let B=0;for(let C=0;C<256;C++){const Q=MIA[C];MIA[C]=B,B+=Q}for(let C=0;C<g;C++){const Q=I[C],i=MIA[Q>>>o&255]++;e[i]=A[C],t[i]=Q}}function egg(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 tgg(g,A,I,e,t,o,B,C){return(t-B)*(A-C)>=(g-B)*(o-C)&&(g-B)*(e-C)>=(I-B)*(A-C)&&(I-B)*(o-C)>=(t-B)*(e-C)}function djt(g,A){const I=ogg(g,A)&&fy(g.prev,g,g.next)>0&&fy(A.prev,A,A.next)>0;return g.next.i!==A.i&&(I||xyA(g,A)&&xyA(A,g)&&(fy(g.prev,g,A.prev)!==0||fy(g,A.prev,A)!==0))&&!yjt(g,A)&&(I||wjt(g,A))}function fy(g,A,I){return(A.y-g.y)*(I.x-A.x)-(A.x-g.x)*(I.y-A.y)}function ogg(g,A){return g.x===A.x&&g.y===A.y}function jmI(g,A,I,e,t=!0){const o=fy(g,A,I),B=fy(g,A,e),C=fy(I,e,g),Q=fy(I,e,A);return(o>0&&B<0||o<0&&B>0)&&(C>0&&Q<0||C<0&&Q>0)?!0:t?!!(o===0&&NyA(g,I,A)||B===0&&NyA(g,e,A)||C===0&&NyA(I,g,e)||Q===0&&NyA(I,A,e)):!1}function NyA(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 yjt(g,A){const I=Math.min(g.x,A.x),e=Math.max(g.x,A.x),t=Math.min(g.y,A.y),o=Math.max(g.y,A.y);let B=g;do{const C=B.next;if(B.x>e&&C.x>e||B.x<I&&C.x<I||B.y>o&&C.y>o||B.y<t&&C.y<t){B=C;continue}if(B.i!==g.i&&C.i!==g.i&&B.i!==A.i&&C.i!==A.i&&jmI(B,C,g,A))return!0;B=C}while(B!==g);return!1}function xyA(g,A){return fy(g.prev,g,g.next)<0?fy(g,A,g.next)>=0&&fy(g,g.prev,A)>=0:fy(g,A,g.prev)<0||fy(g,g.next,A)<0}function wjt(g,A){let I=g,e=!1;const t=(g.x+A.x)/2,o=(g.y+A.y)/2;do{const B=I.next;I.y>o!=B.y>o&&t<(B.x-I.x)*(o-I.y)/(B.y-I.y)+I.x&&(e=!e),I=B}while(I!==g);return e}function ujt(g,A){const I=Bgg(g.i,g.x,g.y),e=Bgg(A.i,A.x,A.y),t=g.next,o=A.prev;return g.next=A,A.prev=g,I.next=t,t.prev=I,e.next=I,I.prev=e,o.next=e,e.prev=o,e}function zmI(g,A,I,e){const t=Bgg(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 SIA(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 Bgg(g,A,I){return{i:g,x:A,y:I,prev:null,next:null,z:0,prevZ:null,nextZ:null}}function Gjt(g,A,I,e){let t=0;for(let o=A,B=I-e;o<I;o+=e)t+=(g[B]-g[o])*(g[o+1]+g[B+1]),B=o;return t}var y5=1e-7;function XmI(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<y5||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)>y5),e=I[0];if(e&&I.some(C=>Math.abs(C.nx-e.nx)>y5||Math.abs(C.ny-e.ny)>y5))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-y5)throw new Error("Overlapping PCB bend zones are not supported");const t=[...I].reverse(),o=({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},B=({p:C,anchor:Q,direction:i})=>{const E=i?{x:0,y:0,z:0}:o({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=>o({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)=>B({p:C,anchor:Q,direction:!1}),inverseDirection:(C,Q)=>B({p:C,anchor:Q,direction:!0}),point:(C,Q=C)=>o({p:C,anchor:Q,direction:!1}),direction:(C,Q)=>o({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+y5&&Math.min(...E)<i.end-y5)throw new Error(`${Q} intersects PCB bend zone ${i.id}`)}}}}var JR=1e-7;function fIA(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 o of["x","y","z"])I[o]=Math.min(I[o],t[o]),e[o]=Math.max(e[o],t[o]);return{min:I,max:e}}function $mI(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,o=({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)>=-JR||Math.max(...n)<=JR)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>=-JR&&s[r].push(h),d>JR&&y<-JR||d<-JR&&y>JR){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)},B=[];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=>o({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+JR&&s<n.end-JR&&E.some(({p:r})=>{const a=-n.ny*r.x+n.nx*r.y;return a<n.axisMin-JR||a>n.axisMax+JR}))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||B.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:B,boundingBox:fIA(B)}}var mjt=[{x:1,y:0,z:0},{x:0,y:1,z:0},{x:0,y:0,z:1}];function pjt(g,A){const[I,e,t]=[A.x,A.y,A.z].map(C=>C*Math.PI/180),o={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},B={x:Math.cos(e)*o.x+Math.sin(e)*o.z,y:o.y,z:-Math.sin(e)*o.x+Math.cos(e)*o.z};return{x:B.x,y:Math.cos(I)*B.y-Math.sin(I)*B.z,z:Math.sin(I)*B.y+Math.cos(I)*B.z}}function kjt([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 Mjt({cadComponent:g,foldPcbs:A},I){return Sjt({cadComponentPlacement:g,foldPcbs:A},I)}function Sjt({cadComponentPlacement:g,foldPcbs:A},I){if(g.is_on_folded_board===!0===A)return g;const{fold:e,boardCenter:t,flatMount:o}=I,B={x:o.x-t.x,y:o.y-t.y,z:0};e.assertRigid([B],"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,B):e.inversePoint(C,B),E=g.rotation??I.defaultRotation??{x:0,y:0,z:0},n=mjt.map(s=>Q(pjt(s,E),B));return{...g,position:{x:i.x+t.x,y:i.y+t.y,z:i.z},rotation:kjt(n),is_on_folded_board:A}}function fjt(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,o=t?e.filter(Q=>Q.pcb_board_id===t):e.filter(Q=>Q.subcircuit_id&&Q.subcircuit_id===I.subcircuit_id),B=o.length===1?o[0]:!t&&!o.length&&e.length===1?e[0]:void 0;if(!B)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===B.pcb_board_id);return{fold:XmI(C,B.thickness??1.6),boardCenter:B.center,flatMount:I.center,defaultRotation:{x:(g.layer??I.layer)==="bottom"?180:0,y:0,z:0}}}function Rjt(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 o=fjt(t,g);return!o||!o.fold.bends.length&&!t.is_on_folded_board?e:Mjt({cadComponent:t,foldPcbs:A.foldPcbs},o)})}function Njt({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(),o=[],B=({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&&o.push({vertices:[Q,i,E],normal:{x:a.x/c,y:a.y/c,z:a.z/c},pcbFace:n})},C=njt(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]);B({a:{...i,z:I},b:{...E,z:I},c:{...n,z:I},pcbFace:"top"}),B({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];B({a:{...i,z:A},b:{...E,z:A},c:{...E,z:I},pcbFace:"side"}),B({a:{...i,z:A},b:{...E,z:I},c:{...i,z:I},pcbFace:"side"})}return{triangles:o,boundingBox:fIA(o)}}function xjt({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)}))})(),o=A/2+e,B=o+g.thickness,C=Njt({outline:t,bottom:g.layer==="top"?o:-B,top:g.layer==="top"?B:-o});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:fIA(i)}}var Fjt=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 Ujt(g,A,I,e,t){let o,B=null;if(I.outline&&I.outline.length>=3){let C=I.outline.map(i=>[i.x,i.y]);Fjt(C)&&(C=C.reverse());const Q=A.ofPolygons([C]);t.push(Q),B=Q,o=g.extrude(Q,e,void 0,void 0,void 0,!0),t.push(o)}else I.outline&&I.outline.length>0&&console.warn("Board outline has fewer than 3 points, falling back to rectangular board."),o=g.cube([I.width,I.height,e],!0),t.push(o),o=o.translate([I.center.x,I.center.y,0]),t.push(o);return{boardOp:o,outlineCrossSection:B}}var Jjt=64;function w5({Manifold:g,width:A,height:I,thickness:e,borderRadius:t}){const o=SmI(A,I,t);if(o<=0)return g.cube([A,I,e],!0);const B=[],C=A-2*o,Q=I-2*o;return C>0&&B.push(g.cube([C,I,e],!0)),Q>0&&B.push(g.cube([A,Q,e],!0)),[[A/2-o,I/2-o],[-A/2+o,I/2-o],[-A/2+o,-I/2+o],[A/2-o,-I/2+o]].forEach(([E,n])=>{B.push(g.cylinder(e,o,o,Jjt,!0).translate([E,n,0]))}),g.union(B)}var Pjt=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 Kjt(g,A,I,e,t){const o=[],B=Xo(I).pcb_cutout.list();for(const C of B){let Q;const i=e*1.5;switch(C.shape){case"rect":{const s=d3(C);if(typeof s=="number"&&s>0?Q=w5({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,Nd,!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]);Pjt(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&&o.push(Q)}return{cutoutOps:o}}function ApI({Manifold:g,x:A,y:I,diameter:e,thickness:t,segments:o=32}){return g.cylinder(t*1.2,e/2,e/2,o,!0).translate([A,I,0])}function gpI({Manifold:g,x:A,y:I,holeDiameter:e,thickness:t,zOffset:o=.001,segments:B=32}){const C=e/2+o;return g.cylinder(t*1.2,C,C,B,!0).translate([A,I,0])}function Ljt(g,A,I,e,t){const o=[],B=Xo(I).pcb_hole.list(),C=(E,n,s)=>{const r=w5({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 B){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=ApI({Manifold:g,x:s,y:r,diameter:E.hole_diameter,thickness:e,segments:Nd}),o.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,Nd),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),o.push(d)}}return{nonPlatedHoleBoardDrills:o}}function wx(g){const A=new Yn;if(A.setAttribute("position",new ZB(g.vertProperties,3)),A.setIndex(new yvA(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 RIA=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},FyA=(g,A,I)=>{const e=[];for(let t=0;t<I;t++){const o=2*Math.PI*t/I;e.push([g/2*Math.cos(o),A/2*Math.sin(o)])}return e},u5=new oo(...$E.copper),UyA=.05,NIA=.003,xIA=5e-4,FIA=.004;function Yjt(g,A,I,e,t,o){const B=[],C=Xo(I).pcb_plated_hole.list(),Q=[],i=[],E=(a,c,h)=>{const l=w5({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]);RIA(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,OB),m=Math.max(G/2,OB/2);u=g.cylinder(c,m,m,Nd,!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,OB),k=Math.max(m+h,OB);if(d==="oval"){let S=FyA(p,k,Nd);RIA(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=w5({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*(NIA+xIA+FIA),OB);if(a.shape==="circle"){const l=gpI({Manifold:g,x:a.x,y:a.y,holeDiameter:a.hole_diameter*1.02,thickness:e,zOffset:FR,segments:Nd});t.push(l),B.push(l);const D=h,d=g.cylinder(D,a.outer_diameter/2,a.outer_diameter/2,Nd,!0);t.push(d);const y=g.cylinder(D*1.05,a.hole_diameter/2,a.hole_diameter/2,Nd,!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(o){const p=g.intersection([u,o]);t.push(p),G=p}i.push(G);const m=wx(G.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:m,color:u5})}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*FR,G=D+2*FR,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),B.push(k);const S=h,R=E(y,w,S),x=E(l,D,S*1.05);let N=R.subtract(x);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 K=U;if(o){const H=g.intersection([U,o]);t.push(H),K=H}i.push(K);const _=wx(K.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:_,color:u5})}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=d3(a),m=NIA,p=l+2*FR,k=D+2*FR,S=e*1.2,x=E(p,k,S).translate([d,y,0]).translate([a.x,a.y,0]);t.push(x),B.push(x);const N=w5({Manifold:g,width:w,height:u,thickness:Math.max(e-2*(m+xIA+FIA),OB),borderRadius:G});t.push(N);const U=E(l,D,e*.8).translate([d,y,0]);t.push(U);const K=g.union([N,U]);t.push(K);const _=E(Math.max(l-2*UyA,.01),Math.max(D-2*UyA,.01),e*1.2).translate([d,y,0]);t.push(_);const H=K.subtract(_);t.push(H);const T=H.translate([a.x,a.y,0]);t.push(T);let j=T;if(o){const O=g.intersection([T,o]);t.push(O),j=O}i.push(j);const W=wx(j.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:W,color:u5})}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=d3(a),m=NIA,p=l+2*FR,k=D+2*FR,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 x=R.translate([a.x,a.y,0]);t.push(x),B.push(x);let N=w5({Manifold:g,width:w,height:u,thickness:Math.max(e-2*(m+xIA+FIA),OB),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 K=g.union([N,U]);t.push(K);let _=E(Math.max(l-2*UyA,.01),Math.max(D-2*UyA,.01),e*1.2).translate([d,y,0]);if(a.hole_ccw_rotation){const O=_.rotate([0,0,a.hole_ccw_rotation]);t.push(O),_=O}t.push(_);const H=K.subtract(_);t.push(H);const T=H.translate([a.x,a.y,0]);t.push(T);let j=T;if(o){const O=g.intersection([T,o]);t.push(O),j=O}i.push(j);const W=wx(j.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:W,color:u5})}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*OB});if(!D)return;const d=D.translate([a.x,a.y,0]);t.push(d),B.push(d);const w=Math.max(e-2*(NIA+xIA+FIA),OB),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*OB})||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(o){const N=g.intersection([S,o]);t.push(N),R=N}i.push(R);const x=wx(R.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:x,color:u5})}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*FR,u=D+2*FR,G=e*1.2;let m=FyA(w,u,Nd);RIA(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 gA=k.rotate([0,0,a.ccw_rotation]);t.push(gA),k=gA}const S=k.translate([a.x,a.y,0]);t.push(S),B.push(S);const R=h;let x=FyA(d,y,Nd);RIA(x)&&(x=x.reverse());const N=A.ofPolygons([x]);t.push(N);const U=g.extrude(N,R,0,0,[1,1],!0);t.push(U);let K=FyA(l,D,Nd);RIA(K)&&(K=K.reverse());const _=A.ofPolygons([K]);t.push(_);const H=g.extrude(_,R*1.05,0,0,[1,1],!0);t.push(H);let T=U.subtract(H);if(t.push(T),a.ccw_rotation){const gA=T.rotate([0,0,a.ccw_rotation]);t.push(gA),T=gA}const j=T.translate([a.x,a.y,0]);t.push(j);let W=j;if(o){const gA=g.intersection([j,o]);t.push(gA),W=gA}i.push(W);const O=wx(W.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:O,color:u5})}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=ApI({Manifold:g,x:a.x+l,y:a.y+D,diameter:a.hole_diameter,thickness:e,segments:Nd});t.push(d),B.push(d);const y=a.rect_pad_width??a.hole_diameter,w=a.rect_pad_height??a.hole_diameter,u=d3(a),G=NIA,m=a.hole_diameter/2,p=w5({Manifold:g,width:y,height:w,thickness:Math.max(e-2*(G+xIA+FIA),OB),borderRadius:u});t.push(p);const k=g.cylinder(e*.8,m,m,Nd,!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-OB,.01),Math.max(m-OB,.01),Nd,!0).translate([l,D,0]);t.push(R);const x=S.subtract(R);t.push(x);const N=x.translate([a.x,a.y,0]);t.push(N);let U=N;if(o){const _=g.intersection([N,o]);t.push(_),U=_}i.push(U);const K=wx(U.getMesh());Q.push({key:`ph-${a.pcb_plated_hole_id||c}`,geometry:K,color:u5})}});let r;return i.length>0&&(r=g.union(i),t.push(r)),{platedHoleBoardDrills:B,platedHoleCopperGeoms:Q,platedHoleSubtractOp:r}}function _jt({Manifold:g,x:A,y:I,outerDiameter:e,holeDiameter:t,thickness:o,zOffset:B=.001,segments:C=32}){const Q=B;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(o,i,-1,C,!0),s=o+2*B,r=g.cylinder(s,t/2,-1,C,!0);return n.subtract(r).translate([A,I,0])}var bjt=new oo(...$E.copper);function Hjt(g,A,I,e,t,o=[]){const B=[],C=VAg(A),Q=[],i=[];C.forEach((n,s)=>{let r;if(typeof n.hole_diameter=="number"){const a=gpI({Manifold:g,x:n.x,y:n.y,holeDiameter:n.hole_diameter,thickness:I,zOffset:FR,segments:Nd});e.push(a),B.push(a),r=a}if(typeof n.outer_diameter=="number"&&typeof n.hole_diameter=="number"){const a=_jt({Manifold:g,x:n.x,y:n.y,outerDiameter:n.outer_diameter,holeDiameter:n.hole_diameter,thickness:I,zOffset:FR,segments:Nd});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=[...o,...B].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:wx(h.getMesh()),color:bjt})}return{viaBoardDrills:B,viaCopperGeoms:Q}}var vjt=(g,A,I)=>{const e=vmI(I),[t,o]=X.useState(null),[B,C]=X.useState(null),[Q,i]=X.useState(null),[E,n]=X.useState(!0),s=X.useRef([]),r=X.useMemo(()=>{const l=A.filter(y=>y.type==="pcb_panel"),D=Xo(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=X.useMemo(()=>{const l=Xo(A).pcb_board.list();return l.length>0&&l[0].pcb_board_id==="faux-board"},[A]),c=X.useMemo(()=>r?qmI(r,O2):O2,[r]);X.useEffect(()=>{if(!g||!r){o(null),C(null),n(!1);return}if((r.width===0||!r.width)&&(r.height===0||!r.height)&&(!r.outline||r.outline.length<3)){o({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}=Ujt(l,D,r,u,s.current);let p=G;const S=u+2*1;let R=null;const x=.01;if(m){let gA=m;if(x>0){const IA=m.offset(x);s.current.push(IA),gA=IA}const tA=l.extrude(gA,S,void 0,void 0,void 0,!0);s.current.push(tA),R=tA}else{const gA=(r.width||0)+2*x,tA=(r.height||0)+2*x,IA=l.cube([gA,tA,S],!0);s.current.push(IA);const QA=IA.translate([r.center.x,r.center.y,0]);s.current.push(QA),R=QA}const N=[];let U=null;const{nonPlatedHoleBoardDrills:K}=Ljt(l,D,A,u,s.current);N.push(...K);const{platedHoleBoardDrills:_,platedHoleCopperGeoms:H,platedHoleSubtractOp:T}=Yjt(l,D,A,u,s.current,R);N.push(..._),w.platedHoles=H;const{viaBoardDrills:j,viaCopperGeoms:W}=Hjt(l,A,u,s.current,R,N);if(N.push(...j),w.vias=W,N.length>0){U=l.union(N),s.current.push(U);const gA=T?l.union([U,T]):U;s.current.push(gA);const tA=p.subtract(gA);if(s.current.push(tA),p=tA,T){const IA=T.subtract(U);s.current.push(IA);const QA=IA.getMesh(),nA=wx(QA);w.platedHoles=[{key:"plated-holes-union",geometry:nA,color:new oo($E.copper[0],$E.copper[1],$E.copper[2])}]}}const{cutoutOps:O}=Kjt(l,D,A,u,s.current);if(O.length>0){const gA=l.union(O);s.current.push(gA);const tA=p.subtract(gA);s.current.push(tA),p=tA}if(y=p,y){const gA=y.getMesh(),tA=wx(gA);w.board={geometry:tA,color:qAg(r),material:r.material,isFaux:a}}o(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."),o(null)}finally{n(!1)}return()=>{s.current.forEach(d),s.current=[]}},[g,A,r]);const h=X.useMemo(()=>!r||!c?null:KmI({circuitJson:A,boardData:r,traceTextureResolution:c,visibility:e}),[A,r,c,e]);return{geoms:t,textures:h,pcbThickness:B,error:Q,isLoading:E,boardData:r,isFauxBoard:a}};function IpI(g,A){g.updateMatrix();const I=g.geometry.index?g.geometry.toNonIndexed():g.geometry,e=I.getAttribute("position"),t=I.getAttribute("uv"),o=[];for(let B=0;B<e.count;B+=3){const C=[0,1,2].map(s=>{const r=new BI().fromBufferAttribute(e,B+s).applyMatrix4(g.matrix);return{x:r.x-A.x,y:r.y-A.y,z:r.z}}),[Q,i,E]=C,n=new BI(i.x-Q.x,i.y-Q.y,i.z-Q.z).cross(new BI(E.x-Q.x,E.y-Q.y,E.z-Q.z)).normalize();o.push({vertices:C,normal:{x:n.x,y:n.y,z:n.z},...t?{uvs:[0,1,2].map(s=>({u:t.getX(B+s),v:t.getY(B+s)}))}:{}})}return I!==g.geometry&&I.dispose(),{triangles:o,boundingBox:fIA(o)}}function epI(g,A){const I=[],e=[],t=[];for(const B of g.triangles)B.vertices.forEach((C,Q)=>{I.push(C.x+A.x,C.y+A.y,C.z),e.push(B.normal.x,B.normal.y,B.normal.z),t.push(B.uvs?.[Q]?.u??0,B.uvs?.[Q]?.v??0)});const o=new Yn;return o.setAttribute("position",new ZB(I,3)),o.setAttribute("normal",new ZB(e,3)),o.setAttribute("uv",new ZB(t,2)),o.computeBoundingBox(),o.computeBoundingSphere(),o}function tpI(g,A,I){const e=g.clone();return e.geometry=epI(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 qjt(g,A,I,e){const t=I.filter(a=>a.type==="pcb_board"),o=I.filter(a=>a.type==="pcb_bend"),B=I.filter(a=>a.type==="pcb_stiffener");if(!o.length&&!B.length)return{geometryMeshes:g,textureMeshes:A};const C=t[0];if(!C||t.length!==1||I.some(a=>a.type==="pcb_panel")||[...o,...B].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?XmI(o,C.thickness??1.6):void 0,i=g.find(a=>a.name==="board-geom"),E=i?IpI(i,C.center):void 0,n=Q?g.map(a=>tpI(a,$mI(IpI(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 BI(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=tpI(a,$mI({triangles:D,boundingBox:fIA(D)},Q),C);return a.geometry.dispose(),d}):A;for(const a of B){const c=new Ko(epI(xjt({stiffener:a,boardThickness:C.thickness??1.6,fold:Q}),C.center),new Hs({color:a.material==="fr4"?"#879568":a.material==="polyimide"?"#bd7f27":"#b8bdc4",side:Sl}));c.name="board-stiffener",AS(c),n.push(c)}const r=new pm;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 Tjt=Sl,Zjt=({material:g,color:A,side:I=Tjt,isFaux:e=!1})=>g==="fr4"?new OM({color:A,side:I,metalness:0,roughness:.48,specularIntensity:.3,ior:1.45,sheen:0,clearcoat:.16,clearcoatRoughness:.3,transparent:e,opacity:e?dyA:1,flatShading:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}):new Hs({color:A,side:I,flatShading:!0,metalness:.1,roughness:.8,transparent:!0,opacity:e?dyA:.9,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});function Ojt(g){const A=[];if(!g)return A;if(g.board?.geometry){const e=new Ko(g.board.geometry,Zjt({material:g.board.material,color:g.board.color,side:Sl,isFaux:g.board.isFaux}));e.name="board-geom",AS(e,{castShadow:!1,receiveShadow:!0}),A.push(e)}const I=e=>{if(e)for(const t of e){const o=new Ko(t.geometry,new Hs({color:t.color,side:Sl,flatShading:!0}));o.name=t.key,AS(o),A.push(o)}};return I(g.platedHoles),I(g.vias),A}var JyA;function Wjt(){return JyA||(JyA=(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(dIA("manifold-3d","3.5.1","manifold.js"))).default)();return I.setup(),window.ManifoldModule=I,I})().catch(g=>{throw JyA=void 0,g})),JyA}var Vjt=({geometryMeshes:g,textureMeshes:A})=>{const{rootObject:I}=RD(),{visibility:e}=l5(),t=o=>{o.geometry.dispose();const B=Array.isArray(o.material)?o.material:[o.material];for(const C of B){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 $r&&n.dispose()}C.dispose()}};return X.useEffect(()=>{if(I){for(const o of g){let B=!0;o.name==="board-geom"||o.name==="board-stiffener"?B=e.boardBody:(o.name.includes("plated_hole")||o.name.includes("via"))&&(B=e.topCopper||e.bottomCopper),B&&I.add(o)}return()=>{for(const o of g)o.parent===I&&I.remove(o),t(o)}}},[I,g,e]),X.useEffect(()=>{if(I){for(const o of A)I.add(o);return()=>{for(const o of A)o.parent===I&&I.remove(o),t(o)}}},[I,A]),null},jjt=({circuitJson:g,foldPcbs:A,autoRotateDisabled:I,clickToInteractEnabled:e,onUserInteraction:t,children:o,onCameraControllerReady:B,resolveStaticAsset:C,referenceObject:Q,hiddenCadComponentIds:i})=>{const E=NAg(o),n=X.useMemo(()=>VmI(g??E),[g,E]),[s,r]=X.useState(null),[a,c]=X.useState(null),{visibility:h}=l5();X.useEffect(()=>{let U=!0;return Wjt().then(K=>{U&&r(K)}).catch(K=>{U&&(console.error("Failed to initialize Manifold:",K),c(`Failed to initialize Manifold: ${K instanceof Error?K.message:"Unknown error"}`))}),()=>{U=!1}},[]);const{geoms:l,textures:D,pcbThickness:d,error:y,isLoading:w,boardData:u,isFauxBoard:G}=vjt(s,n,h),m=X.useMemo(()=>{try{const U=jGI(n,A),K=Rjt(n,{foldPcbs:U});return{...qjt(Ojt(l),XVt(D,u,d,G),n,U),posedJson:K,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=X.useMemo(()=>Xo(m.posedJson).cad_component.list().filter(U=>!i?.has(U.cad_component_id)),[m.posedJson,i]),k=X.useMemo(()=>TmI(m.posedJson),[m.posedJson]),S=X.useMemo(()=>{if(!u)return;const U=Sy(u);return{width:U.width,height:U.height}},[u]),R=X.useMemo(()=>{if(!u)return;const U=Sy(u);return{x:U.centerX,y:U.centerY}},[u]),x=X.useMemo(()=>WmI({boardDimensions:S,boardCenter:R}),[S,R]),N=X.useMemo(()=>{if(u)return JSON.stringify({pcbBoardId:u.pcb_board_id,center:R,dimensions:S})},[u,R,S]);return a?q.jsxs("div",{style:{color:"red",padding:"1em",border:"1px solid red",margin:"1em"},children:["Error: ",a]}):s?y||m.error?q.jsxs("div",{role:"alert",style:{color:"red",padding:"1em",border:"1px solid red",margin:"1em"},children:["Error: ",y??m.error]}):w?q.jsx("div",{style:{padding:"1em"},children:"Processing board geometry..."}):q.jsxs(umI,{initialCameraPosition:x,autoRotateDisabled:I,clickToInteractEnabled:e,boardDimensions:S,boardCenter:R,cameraSessionScope:N,referenceObject:Q,onUserInteraction:t,onCameraControllerReady:B,children:[q.jsx(Vjt,{geometryMeshes:m.geometryMeshes,textureMeshes:m.textureMeshes}),m.bounds&&q.jsx(wmI,{bounds:m.bounds}),p.map(U=>q.jsx(KAg,{fallback:({error:K})=>q.jsx(RmI,{cad_component:U,error:K}),children:q.jsx(imI,{cad_component:U,circuitJson:m.posedJson,resolveStaticAsset:C})},U.cad_component_id)),k.map(U=>q.jsx(OmI,{cable:U},U.cad_cable_id))]}):q.jsx("div",{style:{padding:"1em"},children:"Loading Manifold module..."})},opI=jjt,zjt=Object.defineProperty,S7=(g,A)=>zjt(g,"name",{value:A,configurable:!0}),BpI=!!(typeof window<"u"&&window.document&&window.document.createElement);function mn(g,A,{checkForDefaultPrevented:I=!0}={}){return S7(function(t){if(g?.(t),I===!1||!t||!t.defaultPrevented)return A?.(t)},"handleEvent")}S7(mn,"composeEventHandlers");function Xjt(g){if(!BpI)throw new Error("Cannot access window outside of the DOM");return g?.ownerDocument?.defaultView??window}S7(Xjt,"getOwnerWindow");function Cgg(g){if(!BpI)throw new Error("Cannot access document outside of the DOM");return g?.ownerDocument??document}S7(Cgg,"getOwnerDocument");function CpI(g,A=!1){const{activeElement:I}=Cgg(g);if(!I?.nodeName)return null;if(QpI(I)&&I.contentDocument)return CpI(I.contentDocument.body,A);if(A){const e=I.getAttribute("aria-activedescendant");if(e){const t=Cgg(I).getElementById(e);if(t)return t}}return I}S7(CpI,"getActiveElement");function QpI(g){return g.tagName==="IFRAME"}S7(QpI,"isFrame");var $jt=Object.defineProperty,Qgg=(g,A)=>$jt(g,"name",{value:A,configurable:!0});function igg(g,A){if(typeof g=="function")return g(A);g!=null&&(g.current=A)}Qgg(igg,"setRef");function ipI(...g){return A=>{let I=!1;const e=g.map(t=>{const o=igg(t,A);return!I&&typeof o=="function"&&(I=!0),o});if(I)return()=>{for(let t=0;t<e.length;t++){const o=e[t];typeof o=="function"?o():igg(g[t],null)}}}}Qgg(ipI,"composeRefs");function xd(...g){return X.useCallback(ipI(...g),g)}Qgg(xd,"useComposedRefs");var Azt=Object.defineProperty,W2=(g,A)=>Azt(g,"name",{value:A,configurable:!0});function gzt(g,A){const I=X.createContext(A);I.displayName=g+"Context";const e=W2(o=>{const{children:B,...C}=o,Q=X.useMemo(()=>C,Object.values(C));return q.jsx(I.Provider,{value:Q,children:B})},"Provider");e.displayName=g+"Provider";function t(o,B={}){const{optional:C=!1}=B,Q=X.useContext(I);if(Q)return Q;if(A!==void 0)return A;if(!C)throw new Error(`\`${o}\` must be used within \`${g}\``)}return W2(t,"useContext"),[e,t]}W2(gzt,"createContext");function G5(g,A=[]){let I=[];function e(o,B){const C=X.createContext(B);C.displayName=o+"Context";const Q=I.length;I=[...I,B];const i=W2(n=>{const{scope:s,children:r,...a}=n,c=s?.[g]?.[Q]||C,h=X.useMemo(()=>a,Object.values(a));return q.jsx(c.Provider,{value:h,children:r})},"Provider");i.displayName=o+"Provider";function E(n,s,r={}){const{optional:a=!1}=r,c=s?.[g]?.[Q]||C,h=X.useContext(c);if(h)return h;if(B!==void 0)return B;if(!a)throw new Error(`\`${n}\` must be used within \`${o}\``)}return W2(E,"useContext"),[i,E]}W2(e,"createContext");const t=W2(()=>{const o=I.map(B=>X.createContext(B));return W2(function(C){const Q=C?.[g]||o;return X.useMemo(()=>({[`__scope${g}`]:{...C,[g]:Q}}),[C,Q])},"useScope")},"createScope");return t.scopeName=g,[e,EpI(t,...A)]}W2(G5,"createContextScope");function EpI(...g){const A=g[0];if(g.length===1)return A;const I=W2(()=>{const e=g.map(t=>({useScope:t(),scopeName:t.scopeName}));return W2(function(o){const B=e.reduce((C,{useScope:Q,scopeName:i})=>{const n=Q(o)[`__scope${i}`];return{...C,...n}},{});return X.useMemo(()=>({[`__scope${A.scopeName}`]:B}),[B])},"useComposedScopes")},"createScope");return I.scopeName=A.scopeName,I}W2(EpI,"composeContextScopes");var IS=globalThis?.document?X.useLayoutEffect:()=>{},Izt=Object.defineProperty,ezt=(g,A)=>Izt(g,"name",{value:A,configurable:!0}),npI=fp[" useEffectEvent ".trim().toString()],spI=fp[" useInsertionEffect ".trim().toString()];function apI(g){if(typeof npI=="function")return npI(g);const A=X.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof spI=="function"?spI(()=>{A.current=g}):IS(()=>{A.current=g}),X.useMemo(()=>((...I)=>A.current?.(...I)),[])}ezt(apI,"useEffectEvent");var tzt=Object.defineProperty,UIA=(g,A)=>tzt(g,"name",{value:A,configurable:!0}),ozt=fp[" useInsertionEffect ".trim().toString()]||IS;function PyA({prop:g,defaultProp:A,onChange:I=UIA(()=>{},"onChange"),caller:e}){const[t,o,B]=rpI({defaultProp:A,onChange:I}),C=g!==void 0,Q=C?g:t,i=X.useCallback(E=>{if(C){const n=cpI(E)?E(g):E;n!==g&&B.current?.(n)}else o(E)},[C,g,o,B]);return[Q,i]}UIA(PyA,"useControllableState");function rpI({defaultProp:g,onChange:A}){const[I,e]=X.useState(g),t=X.useRef(I),o=X.useRef(A);return ozt(()=>{o.current=A},[A]),X.useEffect(()=>{t.current!==I&&(o.current?.(I),t.current=I)},[I,t]),[I,e,o]}UIA(rpI,"useUncontrolledState");function cpI(g){return typeof g=="function"}UIA(cpI,"isFunction");var hpI=Symbol("RADIX:SYNC_STATE");function Bzt(g,A,I,e){const{prop:t,defaultProp:o,onChange:B,caller:C}=A,Q=t!==void 0,i=apI(B),E=[{...I,state:o}];e&&E.push(e);const[n,s]=X.useReducer((h,l)=>{if(l.type===hpI)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=X.useRef(r);X.useEffect(()=>{a.current!==r&&(a.current=r,Q||i(r))},[r,a,Q]);const c=X.useMemo(()=>t!==void 0?{...n,state:t}:n,[n,t]);return X.useEffect(()=>{Q&&!Object.is(t,n.state)&&s({type:hpI,state:t})},[t,n.state,Q]),[c,s]}UIA(Bzt,"useControllableStateReducer");var Czt=Object.defineProperty,eS=(g,A)=>Czt(g,"name",{value:A,configurable:!0});function m5(g){const A=X.forwardRef((I,e)=>{let{children:t,...o}=I,B=null,C=!1;const Q=[];t=upI(t),X.Children.forEach(t,s=>{if(ypI(s)){C=!0;const r=s;let a="child"in r.props?r.props.child:r.props.children;for(;Egg(a)&&typeof KyA=="function";)a=KyA(a._payload);B=izt(r,a),Q.push(B?.props?.children)}else Q.push(s)}),B?B=X.cloneElement(B,void 0,Q):!C&&X.Children.count(t)===1&&X.isValidElement(t)&&(B=t);const i=B?dpI(B):void 0,E=xd(e,i);if(!B){if(t||t===0)throw new Error(C?szt(g):nzt(g));return t}const n=DpI(o,B.props??{});return B.type!==X.Fragment&&(n.ref=e?E:i),X.cloneElement(B,n)});return A.displayName=`${g}.Slot`,A}eS(m5,"createSlot");var lpI=Symbol.for("radix.slottable");function Qzt(g){const A=eS(I=>"child"in I?I.children(I.child):I.children,"Slottable");return A.displayName=`${g}.Slottable`,A.__radixId=lpI,A}eS(Qzt,"createSlottable");var izt=eS((g,A)=>"child"in g.props?X.isValidElement(A)?X.cloneElement(A,void 0,g.props.children(A.props.children)):null:X.isValidElement(A)?A:null,"getSlottableElementFromSlottable");function DpI(g,A){const I={...A};for(const e in A){const t=g[e],o=A[e];/^on[A-Z]/.test(e)?t&&o?I[e]=(...C)=>{const Q=o(...C);return t(...C),Q}:t&&(I[e]=t):e==="style"?I[e]={...t,...o}:e==="className"?I[e]=[t,o].filter(Boolean).join(" "):e==="aria-describedby"&&(I[e]=GpI(o,t))}return{...g,...I}}eS(DpI,"mergeProps");function dpI(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)}eS(dpI,"getElementRef");function ypI(g){return X.isValidElement(g)&&typeof g.type=="function"&&"__radixId"in g.type&&g.type.__radixId===lpI}eS(ypI,"isSlottable");var Ezt=Symbol.for("react.lazy");function Egg(g){return g!=null&&typeof g=="object"&&"$$typeof"in g&&g.$$typeof===Ezt&&"_payload"in g&&wpI(g._payload)}eS(Egg,"isLazyComponent");function wpI(g){return typeof g=="object"&&g!==null&&"then"in g}eS(wpI,"isPromiseLike");function upI(g){let A=g;for(;Egg(A)&&typeof KyA=="function";)A=KyA(A._payload);return A}eS(upI,"useUnwrappedLazy");function GpI(...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}eS(GpI,"concatAriaDescribedby");var nzt=eS(g=>`${g} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),szt=eS(g=>`${g} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),KyA=fp[" use ".trim().toString()],azt=Object.defineProperty,rzt=(g,A)=>azt(g,"name",{value:A,configurable:!0}),czt=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ux=czt.reduce((g,A)=>{const I=m5(`Primitive.${A}`),e=X.forwardRef((t,o)=>{const{asChild:B,...C}=t,Q=B?I:A;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),q.jsx(Q,{...C,ref:o})});return e.displayName=`Primitive.${A}`,{...g,[A]:e}},{});function ngg(g,A){g&&j1.flushSync(()=>g.dispatchEvent(A))}rzt(ngg,"dispatchDiscreteCustomEvent");var hzt=Object.defineProperty,Fd=(g,A)=>hzt(g,"name",{value:A,configurable:!0});function sgg(g){const A=g+"CollectionProvider",[I,e]=G5(A),[t,o]=I(A,{collectionRef:{current:null},itemMap:new Map}),B=Fd(c=>{const{scope:h,children:l}=c,D=X.useRef(null),d=X.useRef(new Map).current;return q.jsx(t,{scope:h,itemMap:d,collectionRef:D,children:l})},"CollectionProvider");B.displayName=A;const C=g+"CollectionSlot",Q=m5(C),i=X.forwardRef((c,h)=>{const{scope:l,children:D}=c,d=o(C,l),y=xd(h,d.collectionRef);return q.jsx(Q,{ref:y,children:D})});i.displayName=C;const E=g+"CollectionItemSlot",n="data-radix-collection-item",s=m5(E),r=X.forwardRef((c,h)=>{const{scope:l,children:D,...d}=c,y=X.useRef(null),w=xd(h,y),u=o(E,l);return X.useEffect(()=>(u.itemMap.set(y,{ref:y,...d}),()=>{u.itemMap.delete(y)})),q.jsx(s,{[n]:"",ref:w,children:D})});r.displayName=E;function a(c){const h=o(g+"CollectionConsumer",c);return X.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 Fd(a,"useCollection"),[{Provider:B,Slot:i,ItemSlot:r},a,e]}Fd(sgg,"createCollection");var mpI=new WeakMap,LyA=(uS=class extends Map{constructor(I){super(I);xcg(this,Kl);BBA(this,Kl,[...super.keys()]),mpI.set(this,!0)}set(I,e){return mpI.get(this)&&!this.has(I)&&Xn(this,Kl).push(I),super.set(I,e),this}insert(I,e,t){const o=this.has(e),B=o?this.size:this.size+1,C=agg(I),Q=C>=0?Math.min(C,B-1):Math.max(B+C,0);if(o?Xn(this,Kl).indexOf(e)===Q:Q===this.size)return this.set(e,t),this;const i=Xn(this,Kl).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 o=new uS(this);return o.insert(I,e,t),o}before(I){const e=Xn(this,Kl).indexOf(I)-1;if(!(e<0))return this.entryAt(e)}setBefore(I,e,t){const o=Xn(this,Kl).indexOf(I);if(o===-1)return this;const B=Xn(this,Kl).indexOf(e),C=B!==-1&&B<o?o-1:o;return this.insert(C,e,t)}after(I){let e=Xn(this,Kl).indexOf(I);if(e=e===-1||e===this.size-1?-1:e+1,e!==-1)return this.entryAt(e)}setAfter(I,e,t){const o=Xn(this,Kl).indexOf(I);if(o===-1)return this;const B=Xn(this,Kl).indexOf(e),C=B!==-1&&B<=o?o:o+1;return this.insert(C,e,t)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return BBA(this,Kl,[]),super.clear()}delete(I){const e=super.delete(I);return e&&Xn(this,Kl).splice(Xn(this,Kl).indexOf(I),1),e}deleteAt(I){const e=this.keyAt(I);return e!==void 0?this.delete(e):!1}at(I){const e=YyA(Xn(this,Kl),I);if(e!==void 0)return this.get(e)}entryAt(I){const e=YyA(Xn(this,Kl),I);if(e!==void 0)return[e,this.get(e)]}indexOf(I){return Xn(this,Kl).indexOf(I)}keyAt(I){return YyA(Xn(this,Kl),I)}from(I,e){const t=this.indexOf(I);if(t===-1)return;let o=t+e;return o<0&&(o=0),o>=this.size&&(o=this.size-1),this.at(o)}keyFrom(I,e){const t=this.indexOf(I);if(t===-1)return;let o=t+e;return o<0&&(o=0),o>=this.size&&(o=this.size-1),this.keyAt(o)}find(I,e){let t=0;for(const o of this){if(Reflect.apply(I,e,[o,t,this]))return o;t++}}findIndex(I,e){let t=0;for(const o of this){if(Reflect.apply(I,e,[o,t,this]))return t;t++}return-1}filter(I,e){const t=[];let o=0;for(const B of this)Reflect.apply(I,e,[B,o,this])&&t.push(B),o++;return new uS(t)}map(I,e){const t=[];let o=0;for(const B of this)t.push([B[0],Reflect.apply(I,e,[B,o,this])]),o++;return new uS(t)}reduce(...I){const[e,t]=I,o=I.length>1;if(!o&&this.size===0)throw new TypeError("Reduce of empty OrderedDict with no initial value");let B=0,C=t;for(const Q of this)B===0&&!o?C=Q:C=Reflect.apply(e,this,[C,Q,B,this]),B++;return C}reduceRight(...I){const[e,t]=I,o=I.length>1;if(!o&&this.size===0)throw new TypeError("Reduce of empty OrderedDict with no initial value");let B=t;for(let C=this.size-1;C>=0;C--){const Q=this.entryAt(C);C===this.size-1&&!o?B=Q:B=Reflect.apply(e,this,[B,Q,C,this])}return B}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,o]of e)this.set(t,o);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 uS(e)}toReversed(){const I=new uS;for(let e=this.size-1;e>=0;e--){const t=this.keyAt(e),o=this.get(t);I.set(t,o)}return I}toSpliced(...I){const e=[...this.entries()];return e.splice(...I),new uS(e)}slice(I,e){const t=new uS;for(const o of Xn(this,Kl).slice(I,e))t.set(o,this.get(o));return t}every(I,e){let t=0;for(const o of this){if(!Reflect.apply(I,e,[o,t,this]))return!1;t++}return!0}some(I,e){let t=0;for(const o of this){if(Reflect.apply(I,e,[o,t,this]))return!0;t++}return!1}},Kl=new WeakMap,Fd(uS,"OrderedDict"),uS);function YyA(g,A){if("at"in Array.prototype)return Array.prototype.at.call(g,A);const I=ppI(g,A);return I===-1?void 0:g[I]}Fd(YyA,"at");function ppI(g,A){const I=g.length,e=agg(A),t=e>=0?e:I+e;return t<0||t>=I?-1:t}Fd(ppI,"toSafeIndex");function agg(g){return g!==g||g===0?0:Math.trunc(g)}Fd(agg,"toSafeInteger");function lzt(g){const A=g+"CollectionProvider",[I,e]=G5(A),[t,o]=I(A);t.displayName=g+"CollectionStableContextProvider";const[B,C]=I(A);B.displayName=g+"CollectionStatefulContextProvider";const Q=Fd(({state:u,...G})=>u?q.jsx(E,{...G,state:u}):q.jsx(i,{...G}),"CollectionProvider");Q.displayName=A;const i=Fd(u=>{const G=D();return q.jsx(E,{...u,state:G})},"CollectionInit");i.displayName=g+"CollectionInit";const E=Fd(u=>{const{scope:G,children:m,state:p}=u,k=X.useRef(null),[S,R]=X.useState(null),x=xd(k,R),[N,U]=p,K=X.useRef(new LyA),_=X.useCallback(()=>{const H=K.current;return SpI(H)||H.sort(_yA),H},[]);return X.useEffect(()=>{if(!S)return;const H=fpI(()=>{U(T=>{const j=T.toSorted(_yA);return j.some(([O],gA)=>T.keyAt(gA)!==O)?j:T})});return H.observe(S,{childList:!0,subtree:!0}),()=>{H.disconnect()}},[S,U]),q.jsx(t,{scope:G,collectionElementRef:x,collectionElementRefObject:k,getCollection:_,setCollection:U,registryRef:K,children:q.jsx(B,{scope:G,collectionElement:S,collection:N,children:m})})},"CollectionProviderImpl");E.displayName=g+"CollectionProviderImpl";const n=g+"CollectionSlot",s=m5(n),r=X.forwardRef((u,G)=>{const{scope:m,children:p}=u,k=o(n,m),S=xd(G,k.collectionElementRef);return q.jsx(s,{ref:S,children:p})});r.displayName=n;const a=g+"CollectionItemSlot",c="data-radix-collection-item",h=m5(a),l=X.forwardRef((u,G)=>{const{scope:m,children:p,...k}=u,S=X.useRef(null),R=o(a,m),{setCollection:x,registryRef:N}=R,U=X.useRef(k);kpI(U.current,k)||(U.current=k);const K=U.current,_=X.useCallback(j=>{const W=N.current;j?W.set(j,{...U.current,element:j}):S.current&&W.delete(S.current)},[N]),H=xd(G,_,S);IS(()=>{const j=S.current,W=N.current;j&&W.has(j)&&W.set(j,{...K,element:j})},[K,N]);const T=X.useRef(null);return X.useEffect(()=>{const j=S.current,W=T.current;(W?.element??null)===j&&(!j||W?.itemData===K)||(T.current=j?{element:j,itemData:K}:null,x(O=>{const gA=new LyA(O);return W&&W.element!==j&&gA.delete(W.element),j&&gA.set(j,{...K,element:j}),gA.sort(_yA)}))}),X.useEffect(()=>()=>{const j=T.current;T.current=null,j&&x(W=>{if(!W.has(j.element))return W;const O=new LyA(W);return O.delete(j.element),O})},[x]),q.jsx(h,{[c]:"",ref:H,children:p})});l.displayName=a;function D(){return X.useState(new LyA)}Fd(D,"useInitCollection");function d(u){const{collection:G}=C(g+"CollectionConsumer",u);return G}Fd(d,"useCollection");function y(u){const{getCollection:G}=o(g+"CollectionConsumer",u);return G}return Fd(y,"useGetCollection"),[{Provider:Q,Slot:r,ItemSlot:l},{createCollectionScope:e,useCollection:d,useGetCollection:y,useInitCollection:D}]}Fd(lzt,"createCollection");function kpI(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}Fd(kpI,"shallowEqual");function MpI(g,A){return!!(A.compareDocumentPosition(g)&Node.DOCUMENT_POSITION_PRECEDING)}Fd(MpI,"isElementPreceding");function SpI(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}Fd(SpI,"isInDocumentOrder");function _yA(g,A){return!g[1].element||!A[1].element?0:MpI(g[1].element,A[1].element)?-1:1}Fd(_yA,"sortByDocumentPosition");function fpI(g){return new MutationObserver(I=>{for(const e of I)if(e.type==="childList"){g();return}})}Fd(fpI,"getChildListObserver");var Dzt=Object.defineProperty,dzt=(g,A)=>Dzt(g,"name",{value:A,configurable:!0}),yzt={LTR:"ltr"},wzt=X.createContext(void 0);function rgg(g){const A=X.useContext(wzt);return g||A||yzt.LTR}dzt(rgg,"useDirection");var uzt=Object.defineProperty,Gzt=(g,A)=>uzt(g,"name",{value:A,configurable:!0}),RpI=fp[" useInsertionEffect ".trim().toString()];function Gx(g){const A=X.useRef(g);return typeof RpI=="function"?RpI(()=>{A.current=g}):IS(()=>{A.current=g}),X.useMemo(()=>((...I)=>A.current?.(...I)),[])}Gzt(Gx,"useCallbackRef");var mzt=Object.defineProperty,Ry=(g,A)=>mzt(g,"name",{value:A,configurable:!0}),cgg="dismissableLayer.update",pzt="dismissableLayer.pointerDownOutside",kzt="dismissableLayer.focusOutside",NpI,xpI=X.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Mzt=X.forwardRef(Ry(function(A,I){const{disableOutsidePointerEvents:e=!1,deferPointerDownOutside:t=!1,onEscapeKeyDown:o,onPointerDownOutside:B,onFocusOutside:C,onInteractOutside:Q,onDismiss:i,...E}=A,n=X.useContext(xpI),[s,r]=X.useState(null),a=s?.ownerDocument??globalThis?.document,[,c]=X.useState({}),h=xd(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=X.useRef(!1),m=FpI(R=>{B?.(R),Q?.(R),R.defaultPrevented||i?.()},{ownerDocument:a,deferPointerDownOutside:t,isDeferredPointerDownOutsideRef:G,dismissableSurfaces:n.dismissableSurfaces,shouldHandlePointerDownOutside:X.useCallback(R=>{if(!(R instanceof Node))return!1;const x=[...n.branches].some(N=>N.contains(R));return u&&!x},[n.branches,u])}),p=UpI(R=>{if(t&&G.current)return;const x=R.target;[...n.branches].some(U=>U.contains(x))||(C?.(R),Q?.(R),R.defaultPrevented||i?.())},a),k=s?y===l.length-1:!1,S=Gx(R=>{R.key==="Escape"&&(o?.(R),!R.defaultPrevented&&i&&(R.preventDefault(),i()))});return X.useEffect(()=>{if(k)return a.addEventListener("keydown",S,{capture:!0}),()=>a.removeEventListener("keydown",S,{capture:!0})},[a,k,S]),X.useEffect(()=>{if(s)return e&&(n.layersWithOutsidePointerEventsDisabled.size===0&&(NpI=a.body.style.pointerEvents,a.body.style.pointerEvents="none"),n.layersWithOutsidePointerEventsDisabled.add(s)),n.layers.add(s),hgg(),()=>{e&&(n.layersWithOutsidePointerEventsDisabled.delete(s),n.layersWithOutsidePointerEventsDisabled.size===0&&(a.body.style.pointerEvents=NpI))}},[s,a,e,n]),X.useEffect(()=>()=>{s&&(n.layers.delete(s),n.layersWithOutsidePointerEventsDisabled.delete(s),hgg())},[s,n]),X.useEffect(()=>{const R=Ry(()=>c({}),"handleUpdate");return document.addEventListener(cgg,R),()=>document.removeEventListener(cgg,R)},[]),q.jsx(ux.div,{...E,ref:h,style:{pointerEvents:w?u?"auto":"none":void 0,...A.style},onFocusCapture:mn(A.onFocusCapture,p.onFocusCapture),onBlurCapture:mn(A.onBlurCapture,p.onBlurCapture),onPointerDownCapture:mn(A.onPointerDownCapture,m.onPointerDownCapture)})},"DismissableLayer"));function Szt(){const g=X.useContext(xpI),[A,I]=X.useState(null);return X.useEffect(()=>{if(A)return g.dismissableSurfaces.add(A),()=>{g.dismissableSurfaces.delete(A)}},[A,g.dismissableSurfaces]),I}Ry(Szt,"useDismissableLayerSurface");var fzt=Ry(()=>!0,"IS_TRUE");function FpI(g,A){const{ownerDocument:I=globalThis?.document,deferPointerDownOutside:e=!1,isDeferredPointerDownOutsideRef:t,dismissableSurfaces:o,shouldHandlePointerDownOutside:B=fzt}=A,C=Gx(g),Q=X.useRef(!1),i=X.useRef(!1),E=X.useRef(new Map),n=X.useRef(()=>{});return X.useEffect(()=>{function s(){i.current=!1,t.current=!1,E.current.clear()}Ry(s,"resetOutsideInteraction");function r(){return Array.from(E.current.values()).some(Boolean)}Ry(r,"isOutsideInteractionIntercepted");function a(d){if(!i.current)return;const y=d.target;y instanceof Node&&[...o].some(u=>u.contains(y))||E.current.set(d.type,!0),d.type==="click"&&window.setTimeout(()=>{i.current&&n.current()},0)}Ry(a,"handleInteractionCapture");function c(d){i.current&&E.current.set(d.type,!1)}Ry(c,"handleInteractionBubble");const h=Ry(d=>{if(d.target&&!Q.current){let y=function(){I.removeEventListener("click",n.current);const u=r();s(),u||lgg(pzt,C,w,{discrete:!0})};if(Ry(y,"handleAndDispatchPointerDownOutsideEvent"),!B(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,o,B]),{onPointerDownCapture:Ry(()=>Q.current=!0,"onPointerDownCapture")}}Ry(FpI,"usePointerDownOutside");function UpI(g,A=globalThis?.document){const I=Gx(g),e=X.useRef(!1);return X.useEffect(()=>{const t=Ry(o=>{o.target&&!e.current&&lgg(kzt,I,{originalEvent:o},{discrete:!1})},"handleFocus");return A.addEventListener("focusin",t),()=>A.removeEventListener("focusin",t)},[A,I]),{onFocusCapture:Ry(()=>e.current=!0,"onFocusCapture"),onBlurCapture:Ry(()=>e.current=!1,"onBlurCapture")}}Ry(UpI,"useFocusOutside");function hgg(){const g=new CustomEvent(cgg);document.dispatchEvent(g)}Ry(hgg,"dispatchUpdate");function lgg(g,A,I,{discrete:e}){const t=I.originalEvent.target,o=new CustomEvent(g,{bubbles:!1,cancelable:!0,detail:I});A&&t.addEventListener(g,A,{once:!0}),e?ngg(t,o):t.dispatchEvent(o)}Ry(lgg,"handleAndDispatchCustomEvent");var Rzt=Object.defineProperty,Dgg=(g,A)=>Rzt(g,"name",{value:A,configurable:!0}),byA=0,f7=null;function Nzt(g){return dgg(),g.children}Dgg(Nzt,"FocusGuards");function dgg(){X.useEffect(()=>{f7||(f7={start:ygg(),end:ygg()});const{start:g,end:A}=f7;return document.body.firstElementChild!==g&&document.body.insertAdjacentElement("afterbegin",g),document.body.lastElementChild!==A&&document.body.insertAdjacentElement("beforeend",A),byA++,()=>{byA===1&&(f7?.start.remove(),f7?.end.remove(),f7=null),byA=Math.max(0,byA-1)}},[])}Dgg(dgg,"useFocusGuards");function ygg(){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}Dgg(ygg,"createFocusGuard");var xzt=Object.defineProperty,ND=(g,A)=>xzt(g,"name",{value:A,configurable:!0}),wgg="focusScope.autoFocusOnMount",ugg="focusScope.autoFocusOnUnmount",JpI={bubbles:!1,cancelable:!0},Fzt=X.forwardRef(ND(function(A,I){const{loop:e=!1,trapped:t=!1,branches:o,onMountAutoFocus:B,onUnmountAutoFocus:C,...Q}=A,[i,E]=X.useState(null),n=Gx(B),s=Gx(C),r=X.useRef(null),a=xd(I,E),c=X.useRef(o);X.useEffect(()=>{c.current=o});const h=X.useCallback(d=>d?i?.contains(d)?!0:!!c.current?.some(y=>y.contains(d)):!1,[i]),l=X.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;X.useEffect(()=>{if(t){let d=function(G){if(l.paused||!i)return;const m=G.target;h(m)?r.current=m:EJ(r.current,{select:!0})},y=function(G){if(l.paused||!i)return;const m=G.relatedTarget;m!==null&&(h(m)||EJ(r.current,{select:!0}))},w=function(G){if(document.activeElement===document.body)for(const p of G)p.removedNodes.length>0&&EJ(i)};ND(d,"handleFocusIn"),ND(y,"handleFocusOut"),ND(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]),X.useEffect(()=>{if(i){qpI.add(l);const d=document.activeElement;if(!i.contains(d)){const w=new CustomEvent(wgg,JpI);i.addEventListener(wgg,n),i.dispatchEvent(w),w.defaultPrevented||(_pI(ZpI(Ggg(i)),{select:!0}),document.activeElement===d&&EJ(i))}return()=>{i.removeEventListener(wgg,n);const w=i.ownerDocument,u=CustomEvent;setTimeout(()=>{const G=new u(ugg,JpI);i.addEventListener(ugg,s),i.dispatchEvent(G),G.defaultPrevented||EJ(d??w.body,{select:!0}),i.removeEventListener(ugg,s),qpI.remove(l)},0)}}},[i,n,s,l]);const D=X.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]=bpI(u);G&&m?!d.shiftKey&&w===m?(d.preventDefault(),e&&EJ(G,{select:!0})):d.shiftKey&&w===G&&(d.preventDefault(),e&&EJ(m,{select:!0})):w===u&&d.preventDefault()}},[e,t,l.paused]);return q.jsx(ux.div,{tabIndex:-1,...Q,ref:a,onKeyDown:D})},"FocusScope")),PpI=X.createContext(null);function KpI({registry:g,children:A}){return g?q.jsx(PpI.Provider,{value:g,children:A}):A}ND(KpI,"FocusScopeBranchProvider");function LpI(){const[g,A]=X.useState([]),I=X.useMemo(()=>({add:ND(e=>A(t=>t.includes(e)?t:[...t,e]),"add"),remove:ND(e=>A(t=>t.filter(o=>o!==e)),"remove")}),[]);return{nodes:g,registry:I}}ND(LpI,"useFocusScopeBranchRegistry");function YpI(g){const A=X.useContext(PpI);X.useEffect(()=>{if(!(!g||!A))return A.add(g),()=>A.remove(g)},[g,A])}ND(YpI,"useFocusScopeBranch");function _pI(g,{select:A=!1}={}){const I=document.activeElement;for(const e of g)if(EJ(e,{select:A}),document.activeElement!==I)return}ND(_pI,"focusFirst");function bpI(g){const A=Ggg(g),I=mgg(A,g),e=mgg(A.reverse(),g);return[I,e]}ND(bpI,"getTabbableEdges");function Ggg(g){const A=[],e=g.ownerDocument.createTreeWalker(g,NodeFilter.SHOW_ELEMENT,{acceptNode:ND(t=>{const o=t.tagName==="INPUT"&&t.type==="hidden";return t.disabled||t.hidden||o?NodeFilter.FILTER_SKIP:t.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;e.nextNode();)A.push(e.currentNode);return A}ND(Ggg,"getTabbableCandidates");function mgg(g,A){const I=typeof A.checkVisibility=="function"&&A.checkVisibility({checkVisibilityCSS:!0});for(const e of g)if(!(I?!e.checkVisibility({checkVisibilityCSS:!0}):HpI(e,{upTo:A})))return e}ND(mgg,"findVisible");function HpI(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}ND(HpI,"isHidden");function vpI(g){return g.tagName==="INPUT"&&typeof g.select=="function"}ND(vpI,"isSelectableInput");function EJ(g,{select:A=!1}={}){if(g&&g.focus){const e=(g.ownerDocument??document).activeElement;g.focus({preventScroll:!0}),g!==e&&vpI(g)&&A&&g.select()}}ND(EJ,"focus");var qpI=TpI();function TpI(){let g=[];return{add(A){const I=g[0];A!==I&&I?.pause(),g=pgg(g,A),g.unshift(A)},remove(A){g=pgg(g,A),g[0]?.resume()}}}ND(TpI,"createFocusScopesStack");function pgg(g,A){const I=[...g],e=I.indexOf(A);return e!==-1&&I.splice(e,1),I}ND(pgg,"arrayRemove");function ZpI(g){return g.filter(A=>A.tagName!=="A")}ND(ZpI,"removeLinks");var Uzt=Object.defineProperty,Jzt=(g,A)=>Uzt(g,"name",{value:A,configurable:!0}),Pzt=fp[" useId ".trim().toString()]||(()=>{}),Kzt=0;function R7(g){const[A,I]=X.useState(Pzt());return IS(()=>{g||I(e=>e??String(Kzt++))},[g]),g||(A?`radix-${A}`:"")}Jzt(R7,"useId");var Lzt=["top","right","bottom","left"],y3=Math.min,nJ=Math.max,HyA=Math.round,vyA=Math.floor,sJ=g=>({x:g,y:g}),Yzt={left:"right",right:"left",bottom:"top",top:"bottom"};function OpI(g,A,I){return nJ(g,y3(A,I))}function aJ(g,A){return typeof g=="function"?g(A):g}function w3(g){return g.split("-")[0]}function N7(g){return g.split("-")[1]}function kgg(g){return g==="x"?"y":"x"}function Mgg(g){return g==="y"?"height":"width"}function mx(g){const A=g[0];return A==="t"||A==="b"?"y":"x"}function Sgg(g){return kgg(mx(g))}function _zt(g,A,I){I===void 0&&(I=!1);const e=N7(g),t=Sgg(g),o=Mgg(t);let B=t==="x"?e===(I?"end":"start")?"right":"left":e==="start"?"bottom":"top";return A.reference[o]>A.floating[o]&&(B=qyA(B)),[B,qyA(B)]}function bzt(g){const A=qyA(g);return[fgg(g),A,fgg(A)]}function fgg(g){return g.includes("start")?g.replace("start","end"):g.replace("end","start")}var WpI=["left","right"],VpI=["right","left"],Hzt=["top","bottom"],vzt=["bottom","top"];function qzt(g,A,I){switch(g){case"top":case"bottom":return I?A?VpI:WpI:A?WpI:VpI;case"left":case"right":return A?Hzt:vzt;default:return[]}}function Tzt(g,A,I,e){const t=N7(g);let o=qzt(w3(g),I==="start",e);return t&&(o=o.map(B=>B+"-"+t),A&&(o=o.concat(o.map(fgg)))),o}function qyA(g){const A=w3(g);return Yzt[A]+g.slice(A.length)}function Zzt(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 jpI(g){return typeof g!="number"?Zzt(g):{top:g,right:g,bottom:g,left:g}}function TyA(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 zpI(g,A,I){let{reference:e,floating:t}=g;const o=mx(A),B=Sgg(A),C=Mgg(B),Q=w3(A),i=o==="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=N7(A);return a&&(r[B]+=s*(a==="end"?1:-1)*(I&&i?-1:1)),r}async function Ozt(g,A){var I;A===void 0&&(A={});const{x:e,y:t,platform:o,rects:B,elements:C,strategy:Q}=g,{boundary:i="clippingAncestors",rootBoundary:E="viewport",elementContext:n="floating",altBoundary:s=!1,padding:r=0}=aJ(A,g),a=jpI(r),h=C[s?n==="floating"?"reference":"floating":n],l=TyA(await o.getClippingRect({element:(I=await(o.isElement==null?void 0:o.isElement(h)))==null||I?h:h.contextElement||await(o.getDocumentElement==null?void 0:o.getDocumentElement(C.floating)),boundary:i,rootBoundary:E,strategy:Q})),D=n==="floating"?{x:e,y:t,width:B.floating.width,height:B.floating.height}:B.reference,d=await(o.getOffsetParent==null?void 0:o.getOffsetParent(C.floating)),y=await(o.isElement==null?void 0:o.isElement(d))&&await(o.getScale==null?void 0:o.getScale(d))||{x:1,y:1},w=TyA(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.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 Wzt=50,Vzt=async(g,A,I)=>{const{placement:e="bottom",strategy:t="absolute",middleware:o=[],platform:B}=I,C=B.detectOverflow?B:{...B,detectOverflow:Ozt},Q=await(B.isRTL==null?void 0:B.isRTL(A));let i=await B.getElementRects({reference:g,floating:A,strategy:t}),{x:E,y:n}=zpI(i,e,Q),s=e,r=0;const a={};for(let c=0;c<o.length;c++){const h=o[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<Wzt&&(r++,typeof u=="object"&&(u.placement&&(s=u.placement),u.rects&&(i=u.rects===!0?await B.getElementRects({reference:g,floating:A,strategy:t}):u.rects),{x:E,y:n}=zpI(i,s,Q)),c=-1)}return{x:E,y:n,placement:s,strategy:t,middlewareData:a}},jzt=g=>({name:"arrow",options:g,async fn(A){const{x:I,y:e,placement:t,rects:o,platform:B,elements:C,middlewareData:Q}=A,{element:i,padding:E=0}=aJ(g,A)||{};if(i==null)return{};const n=jpI(E),s={x:I,y:e},r=Sgg(t),a=Mgg(r),c=await B.getDimensions(i),h=r==="y",l=h?"top":"left",D=h?"bottom":"right",d=h?"clientHeight":"clientWidth",y=o.reference[a]+o.reference[r]-s[r]-o.floating[a],w=s[r]-o.reference[r],u=await(B.getOffsetParent==null?void 0:B.getOffsetParent(i));let G=u?u[d]:0;(!G||!await(B.isElement==null?void 0:B.isElement(u)))&&(G=C.floating[d]||o.floating[a]);const m=y/2-w/2,p=G/2-c[a]/2-1,k=y3(n[l],p),S=y3(n[D],p),R=G-c[a]-S,x=G/2-c[a]/2+m,N=OpI(k,x,R),U=!Q.arrow&&N7(t)!=null&&x!==N&&o.reference[a]/2-(x<k?k:S)-c[a]/2<0,K=U?x<k?x-k:x-R:0;return{[r]:s[r]+K,data:{[r]:N,centerOffset:x-N-K,...U&&{alignmentOffset:K}},reset:U}}}),zzt=function(g){return g===void 0&&(g={}),{name:"flip",options:g,async fn(A){var I,e;const{placement:t,middlewareData:o,rects:B,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}=aJ(g,A);if((I=o.arrow)!=null&&I.alignmentOffset)return{};const l=w3(t),D=mx(C),d=w3(C)===C,y=await(Q.isRTL==null?void 0:Q.isRTL(i.floating)),w=s||(d||!c?[qyA(C)]:bzt(C)),u=a!=="none";!s&&u&&w.push(...Tzt(C,c,a,y));const G=[C,...w],m=await Q.detectOverflow(A,h),p=[];let k=((e=o.flip)==null?void 0:e.overflows)||[];if(E&&p.push(m[l]),n){const N=_zt(t,B,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=o.flip)==null?void 0:S.index)||0)+1,U=G[N];if(U&&(!(n==="alignment"?D!==mx(U):!1)||k.every(H=>mx(H.placement)===D?H.overflows[0]>0:!0)))return{data:{index:N,overflows:k},reset:{placement:U}};let K=(R=k.filter(_=>_.overflows[0]<=0).sort((_,H)=>_.overflows[1]-H.overflows[1])[0])==null?void 0:R.placement;if(!K)switch(r){case"bestFit":{var x;const _=(x=k.filter(H=>{if(u){const T=mx(H.placement);return T===D||T==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(T=>T>0).reduce((T,j)=>T+j,0)]).sort((H,T)=>H[1]-T[1])[0])==null?void 0:x[0];_&&(K=_);break}case"initialPlacement":K=C;break}if(t!==K)return{reset:{placement:K}}}return{}}}};function XpI(g,A){return{top:g.top-A.height,right:g.right-A.width,bottom:g.bottom-A.height,left:g.left-A.width}}function $pI(g){return Lzt.some(A=>g[A]>=0)}var Xzt=function(g){return g===void 0&&(g={}),{name:"hide",options:g,async fn(A){const{rects:I,platform:e}=A,{strategy:t="referenceHidden",...o}=aJ(g,A);switch(t){case"referenceHidden":{const B=await e.detectOverflow(A,{...o,elementContext:"reference"}),C=XpI(B,I.reference);return{data:{referenceHiddenOffsets:C,referenceHidden:$pI(C)}}}case"escaped":{const B=await e.detectOverflow(A,{...o,altBoundary:!0}),C=XpI(B,I.floating);return{data:{escapedOffsets:C,escaped:$pI(C)}}}default:return{}}}}},AkI=new Set(["left","top"]);async function $zt(g,A){const{placement:I,platform:e,elements:t}=g,o=await(e.isRTL==null?void 0:e.isRTL(t.floating)),B=w3(I),C=N7(I),Q=mx(I)==="y",i=AkI.has(B)?-1:1,E=o&&Q?-1:1,n=aJ(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 AXt=function(g){return g===void 0&&(g=0),{name:"offset",options:g,async fn(A){var I,e;const{x:t,y:o,placement:B,middlewareData:C}=A,Q=await $zt(A,g);return B===((I=C.offset)==null?void 0:I.placement)&&(e=C.arrow)!=null&&e.alignmentOffset?{}:{x:t+Q.x,y:o+Q.y,data:{...Q,placement:B}}}}},gXt=function(g){return g===void 0&&(g={}),{name:"shift",options:g,async fn(A){const{x:I,y:e,placement:t,platform:o}=A,{mainAxis:B=!0,crossAxis:C=!1,limiter:Q={fn:D=>{let{x:d,y}=D;return{x:d,y}}},...i}=aJ(g,A),E={x:I,y:e},n=await o.detectOverflow(A,i),s=mx(t),r=kgg(s);let a=E[r],c=E[s];const h=(D,d)=>OpI(d+n[D==="y"?"top":"left"],d,d-n[D==="y"?"bottom":"right"]);B&&(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]:B,[s]:C}}}}}},IXt=function(g){return g===void 0&&(g={}),{options:g,fn(A){var I,e;const{x:t,y:o,placement:B,rects:C,middlewareData:Q}=A,{offset:i=0,mainAxis:E=!0,crossAxis:n=!0}=aJ(g,A),s={x:t,y:o},r=mx(B),a=kgg(r);let c=s[a],h=s[r];const l=aJ(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=AkI.has(w3(B)),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}}}},eXt=function(g){return g===void 0&&(g={}),{name:"size",options:g,async fn(A){const{placement:I,rects:e,platform:t,elements:o}=A,{apply:B=()=>{},...C}=aJ(g,A),Q=await t.detectOverflow(A,C),i=w3(I),E=N7(I),n=mx(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(o.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=y3(r-Q[a],h),d=y3(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*nJ(Q.left,Q.right):u=r-2*nJ(Q.top,Q.bottom)),await B({...A,availableWidth:G,availableHeight:u});const m=await t.getDimensions(o.floating);return s!==m.width||r!==m.height?{reset:{rects:!0}}:{}}}};function ZyA(){return typeof window<"u"}function x7(g){return gkI(g)?(g.nodeName||"").toLowerCase():"#document"}function ck(g){var A;return(g==null||(A=g.ownerDocument)==null?void 0:A.defaultView)||window}function rJ(g){var A;return(A=(gkI(g)?g.ownerDocument:g.document)||window.document)==null?void 0:A.documentElement}function gkI(g){return ZyA()?g instanceof Node||g instanceof ck(g).Node:!1}function px(g){return ZyA()?g instanceof Element||g instanceof ck(g).Element:!1}function u3(g){return ZyA()?g instanceof HTMLElement||g instanceof ck(g).HTMLElement:!1}function IkI(g){return!ZyA()||typeof ShadowRoot>"u"?!1:g instanceof ShadowRoot||g instanceof ck(g).ShadowRoot}function OyA(g){const{overflow:A,overflowX:I,overflowY:e,display:t}=kx(g);return/auto|scroll|overlay|hidden|clip/.test(A+e+I)&&t!=="inline"&&t!=="contents"}function tXt(g){return/^(table|td|th)$/.test(x7(g))}function WyA(g){try{if(g.matches(":popover-open"))return!0}catch{}try{return g.matches(":modal")}catch{return!1}}var oXt=/transform|translate|scale|rotate|perspective|filter/,BXt=/paint|layout|strict|content/,p5=g=>!!g&&g!=="none",Rgg;function Ngg(g){const A=px(g)?kx(g):g;return p5(A.transform)||p5(A.translate)||p5(A.scale)||p5(A.rotate)||p5(A.perspective)||!xgg()&&(p5(A.backdropFilter)||p5(A.filter))||oXt.test(A.willChange||"")||BXt.test(A.contain||"")}function CXt(g){let A=k5(g);for(;u3(A)&&!JIA(A);){if(Ngg(A))return A;if(WyA(A))return null;A=k5(A)}return null}function xgg(){return Rgg==null&&(Rgg=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Rgg}function JIA(g){return/^(html|body|#document)$/.test(x7(g))}function kx(g){return ck(g).getComputedStyle(g)}function VyA(g){return px(g)?{scrollLeft:g.scrollLeft,scrollTop:g.scrollTop}:{scrollLeft:g.scrollX,scrollTop:g.scrollY}}function k5(g){if(x7(g)==="html")return g;const A=g.assignedSlot||g.parentNode||IkI(g)&&g.host||rJ(g);return IkI(A)?A.host:A}function ekI(g){const A=k5(g);return JIA(A)?(g.ownerDocument||g).body:u3(A)&&OyA(A)?A:ekI(A)}function PIA(g,A,I){var e;A===void 0&&(A=[]),I===void 0&&(I=!0);const t=ekI(g),o=t===((e=g.ownerDocument)==null?void 0:e.body),B=ck(t);if(o){const C=Fgg(B);return A.concat(B,B.visualViewport||[],OyA(t)?t:[],C&&I?PIA(C):[])}else return A.concat(t,PIA(t,[],I))}function Fgg(g){return g.parent&&Object.getPrototypeOf(g.parent)?g.frameElement:null}function tkI(g){const A=kx(g);let I=parseFloat(A.width)||0,e=parseFloat(A.height)||0;const t=u3(g),o=t?g.offsetWidth:I,B=t?g.offsetHeight:e,C=HyA(I)!==o||HyA(e)!==B;return C&&(I=o,e=B),{width:I,height:e,$:C}}function Ugg(g){return px(g)?g:g.contextElement}function F7(g){const A=Ugg(g);if(!u3(A))return sJ(1);const I=A.getBoundingClientRect(),{width:e,height:t,$:o}=tkI(A);let B=(o?HyA(I.width):I.width)/e,C=(o?HyA(I.height):I.height)/t;return(!B||!Number.isFinite(B))&&(B=1),(!C||!Number.isFinite(C))&&(C=1),{x:B,y:C}}var QXt=sJ(0);function okI(g){const A=ck(g);return!xgg()||!A.visualViewport?QXt:{x:A.visualViewport.offsetLeft,y:A.visualViewport.offsetTop}}function iXt(g,A,I){return A===void 0&&(A=!1),!!I&&A&&I===ck(g)}function M5(g,A,I,e){A===void 0&&(A=!1),I===void 0&&(I=!1);const t=g.getBoundingClientRect(),o=Ugg(g);let B=sJ(1);A&&(e?px(e)&&(B=F7(e)):B=F7(g));const C=iXt(o,I,e)?okI(o):sJ(0);let Q=(t.left+C.x)/B.x,i=(t.top+C.y)/B.y,E=t.width/B.x,n=t.height/B.y;if(o&&e){const s=ck(o),r=px(e)?ck(e):e;let a=s,c=Fgg(a);for(;c&&r!==a;){const h=F7(c),l=c.getBoundingClientRect(),D=kx(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=ck(c),c=Fgg(a)}}return TyA({width:E,height:n,x:Q,y:i})}function jyA(g,A){const I=VyA(g).scrollLeft;return A?A.left+I:M5(rJ(g)).left+I}function BkI(g,A){const I=g.getBoundingClientRect(),e=I.left+A.scrollLeft-jyA(g,I),t=I.top+A.scrollTop;return{x:e,y:t}}function EXt(g){let{elements:A,rect:I,offsetParent:e,strategy:t}=g;const o=t==="fixed",B=rJ(e),C=A?WyA(A.floating):!1;if(e===B||C&&o)return I;let Q={scrollLeft:0,scrollTop:0},i=sJ(1);const E=sJ(0),n=u3(e);if((n||!o)&&((x7(e)!=="body"||OyA(B))&&(Q=VyA(e)),n)){const r=M5(e);i=F7(e),E.x=r.x+e.clientLeft,E.y=r.y+e.clientTop}const s=B&&!n&&!o?BkI(B,Q):sJ(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 nXt(g){return g.getClientRects?Array.from(g.getClientRects()):[]}function sXt(g){const A=VyA(g),I=g.ownerDocument.body,e=nJ(g.scrollWidth,g.clientWidth,I.scrollWidth,I.clientWidth),t=nJ(g.scrollHeight,g.clientHeight,I.scrollHeight,I.clientHeight);let o=-A.scrollLeft+jyA(g);const B=-A.scrollTop;return kx(I).direction==="rtl"&&(o+=nJ(g.clientWidth,I.clientWidth)-e),{width:e,height:t,x:o,y:B}}var aXt=25;function rXt(g,A,I){I===void 0&&(I="viewport");const e=I==="layoutViewport",t=ck(g),o=rJ(g),B=t.visualViewport;let C=o.clientWidth,Q=o.clientHeight,i=0,E=0;if(B){const s=!xgg()||A==="fixed";e?s||(i=-B.offsetLeft,E=-B.offsetTop):(C=B.width,Q=B.height,s&&(i=B.offsetLeft,E=B.offsetTop))}if(jyA(o)<=0){const s=o.ownerDocument,r=s.body,a=getComputedStyle(r),c=s.compatMode==="CSS1Compat"&&parseFloat(a.marginLeft)+parseFloat(a.marginRight)||0,h=Math.abs(o.clientWidth-r.clientWidth-c),l=getComputedStyle(o).scrollbarGutter==="stable both-edges"?h/2:h;l<=aXt&&(C-=l)}return{width:C,height:Q,x:i,y:E}}function cXt(g,A){const I=M5(g,!0,A==="fixed"),e=I.top+g.clientTop,t=I.left+g.clientLeft,o=F7(g),B=g.clientWidth*o.x,C=g.clientHeight*o.y,Q=t*o.x,i=e*o.y;return{width:B,height:C,x:Q,y:i}}function CkI(g,A,I){let e;if(A==="viewport"||A==="layoutViewport")e=rXt(g,I,A);else if(A==="document")e=sXt(rJ(g));else if(px(A))e=cXt(A,I);else{const t=okI(g);e={x:A.x-t.x,y:A.y-t.y,width:A.width,height:A.height}}return TyA(e)}function hXt(g,A){const I=A.get(g);if(I)return I;let e=PIA(g,[],!1).filter(C=>px(C)&&x7(C)!=="body"),t=null;const o=kx(g).position==="fixed";let B=o?k5(g):g;for(;px(B)&&!JIA(B);){const C=kx(B),Q=Ngg(B),i=t?t.position:o?"fixed":"";!Q&&(i==="fixed"||i==="absolute"&&C.position==="static")?e=e.filter(n=>n!==B):t=C,B=k5(B)}return A.set(g,e),e}function lXt(g){let{element:A,boundary:I,rootBoundary:e,strategy:t}=g;const B=[...I==="clippingAncestors"?WyA(A)?[]:hXt(A,this._c):[].concat(I),e],C=CkI(A,B[0],t);let Q=C.top,i=C.right,E=C.bottom,n=C.left;for(let s=1;s<B.length;s++){const r=CkI(A,B[s],t);Q=nJ(r.top,Q),i=y3(r.right,i),E=y3(r.bottom,E),n=nJ(r.left,n)}return{width:i-n,height:E-Q,x:n,y:Q}}function DXt(g){const{width:A,height:I}=tkI(g);return{width:A,height:I}}function dXt(g,A,I){const e=u3(A),t=rJ(A),o=I==="fixed",B=M5(g,!0,o,A);let C={scrollLeft:0,scrollTop:0};const Q=sJ(0);if((e||!o)&&((x7(A)!=="body"||OyA(t))&&(C=VyA(A)),e)){const s=M5(A,!0,o,A);Q.x=s.x+A.clientLeft,Q.y=s.y+A.clientTop}!e&&t&&(Q.x=jyA(t));const i=t&&!e&&!o?BkI(t,C):sJ(0),E=B.left+C.scrollLeft-Q.x-i.x,n=B.top+C.scrollTop-Q.y-i.y;return{x:E,y:n,width:B.width,height:B.height}}function Jgg(g){return kx(g).position==="static"}function QkI(g,A){if(!u3(g)||kx(g).position==="fixed")return null;if(A)return A(g);let I=g.offsetParent;return rJ(g)===I&&(I=I.ownerDocument.body),I}function ikI(g,A){const I=ck(g);if(WyA(g))return I;if(!u3(g)){let t=k5(g);for(;t&&!JIA(t);){if(px(t)&&!Jgg(t))return t;t=k5(t)}return I}let e=QkI(g,A);for(;e&&tXt(e)&&Jgg(e);)e=QkI(e,A);return e&&JIA(e)&&Jgg(e)&&!Ngg(e)?I:e||CXt(g)||I}var yXt=async function(g){const A=this.getOffsetParent||ikI,I=this.getDimensions,e=await I(g.floating);return{reference:dXt(g.reference,await A(g.floating),g.strategy),floating:{x:0,y:0,width:e.width,height:e.height}}};function wXt(g){return kx(g).direction==="rtl"}var uXt={convertOffsetParentRelativeRectToViewportRelativeRect:EXt,getDocumentElement:rJ,getClippingRect:lXt,getOffsetParent:ikI,getElementRects:yXt,getClientRects:nXt,getDimensions:DXt,getScale:F7,isElement:px,isRTL:wXt};function EkI(g,A){return g.x===A.x&&g.y===A.y&&g.width===A.width&&g.height===A.height}function GXt(g,A,I){let e=null,t;const o=rJ(g);function B(){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),B();const s=g.getBoundingClientRect(),{left:r,top:a,width:c,height:h}=s;if(E||A(),!c||!h)return;const l=vyA(a),D=vyA(o.clientWidth-(r+c)),d=vyA(o.clientHeight-(a+h)),y=vyA(r),u={rootMargin:-l+"px "+-D+"px "+-d+"px "+-y+"px",threshold:nJ(0,y3(1,n))||1};let G=!0;function m(p){const k=p[0].intersectionRatio;if(!EkI(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:o.ownerDocument})}catch{e=new IntersectionObserver(m,u)}e.observe(g)}const Q=ck(g),i=()=>C(I);return Q.addEventListener("resize",i),C(!0),()=>{Q.removeEventListener("resize",i),B()}}function mXt(g,A,I,e){e===void 0&&(e={});const{ancestorScroll:t=!0,ancestorResize:o=!0,elementResize:B=typeof ResizeObserver=="function",layoutShift:C=typeof IntersectionObserver=="function",animationFrame:Q=!1}=e,i=Ugg(g),E=t||o?[...i?PIA(i):[],...A?PIA(A):[]]:[];E.forEach(l=>{t&&l.addEventListener("scroll",I),o&&l.addEventListener("resize",I)});const n=i&&C?GXt(i,I,o):null;let s=-1,r=null;B&&(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?M5(g):null;Q&&h();function h(){const l=M5(g);c&&!EkI(c,l)&&I(),c=l,a=requestAnimationFrame(h)}return I(),()=>{var l;E.forEach(D=>{t&&D.removeEventListener("scroll",I),o&&D.removeEventListener("resize",I)}),n?.(),(l=r)==null||l.disconnect(),r=null,Q&&cancelAnimationFrame(a)}}var pXt=AXt,kXt=gXt,MXt=zzt,SXt=eXt,fXt=Xzt,nkI=jzt,RXt=IXt,NXt=(g,A,I)=>{const e=new Map,t=I??{},o={...uXt,...t.platform,_c:e};return Vzt(g,A,{...t,platform:o})},xXt=typeof document<"u",FXt=function(){},zyA=xXt?X.useLayoutEffect:FXt;function XyA(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(!XyA(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 o=t[e];if(!(o==="_owner"&&g.$$typeof)&&!XyA(g[o],A[o]))return!1}return!0}return g!==g&&A!==A}function skI(g){return typeof window>"u"?1:(g.ownerDocument.defaultView||window).devicePixelRatio||1}function akI(g,A){const I=skI(g);return Math.round(A*I)/I}function Pgg(g){const A=X.useRef(g);return zyA(()=>{A.current=g}),A}function UXt(g){g===void 0&&(g={});const{placement:A="bottom",strategy:I="absolute",middleware:e=[],platform:t,elements:{reference:o,floating:B}={},transform:C=!0,whileElementsMounted:Q,open:i}=g,[E,n]=X.useState({x:0,y:0,strategy:I,placement:A,middlewareData:{},isPositioned:!1}),[s,r]=X.useState(e);XyA(s,e)||r(e);const[a,c]=X.useState(null),[h,l]=X.useState(null),D=X.useCallback(H=>{H!==u.current&&(u.current=H,c(H))},[]),d=X.useCallback(H=>{H!==G.current&&(G.current=H,l(H))},[]),y=o||a,w=B||h,u=X.useRef(null),G=X.useRef(null),m=X.useRef(E),p=Q!=null,k=Pgg(Q),S=Pgg(t),R=Pgg(i),x=X.useCallback(()=>{if(!u.current||!G.current)return;const H={placement:A,strategy:I,middleware:s};S.current&&(H.platform=S.current),NXt(u.current,G.current,H).then(T=>{const j={...T,isPositioned:R.current!==!1};N.current&&!XyA(m.current,j)&&(m.current=j,j1.flushSync(()=>{n(j)}))})},[s,A,I,S,R]);zyA(()=>{i===!1&&m.current.isPositioned&&(m.current.isPositioned=!1,n(H=>({...H,isPositioned:!1})))},[i]);const N=X.useRef(!1);zyA(()=>(N.current=!0,()=>{N.current=!1}),[]),zyA(()=>{if(y&&(u.current=y),w&&(G.current=w),y&&w){if(k.current)return k.current(y,w,x);x()}},[y,w,x,k,p]);const U=X.useMemo(()=>({reference:u,floating:G,setReference:D,setFloating:d}),[D,d]),K=X.useMemo(()=>({reference:y,floating:w}),[y,w]),_=X.useMemo(()=>{const H={position:I,left:0,top:0};if(!K.floating)return H;const T=akI(K.floating,E.x),j=akI(K.floating,E.y);return C?{...H,transform:"translate("+T+"px, "+j+"px)",...skI(K.floating)>=1.5&&{willChange:"transform"}}:{position:I,left:T,top:j}},[I,C,K.floating,E.x,E.y]);return X.useMemo(()=>({...E,update:x,refs:U,elements:K,floatingStyles:_}),[E,x,U,K,_])}var JXt=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?nkI({element:e.current,padding:t}).fn(I):{}:e?nkI({element:e,padding:t}).fn(I):{}}}},PXt=(g,A)=>{const I=pXt(g);return{name:I.name,fn:I.fn,options:[g,A]}},KXt=(g,A)=>{const I=kXt(g);return{name:I.name,fn:I.fn,options:[g,A]}},LXt=(g,A)=>({fn:RXt(g).fn,options:[g,A]}),YXt=(g,A)=>{const I=MXt(g);return{name:I.name,fn:I.fn,options:[g,A]}},_Xt=(g,A)=>{const I=SXt(g);return{name:I.name,fn:I.fn,options:[g,A]}},bXt=(g,A)=>{const I=fXt(g);return{name:I.name,fn:I.fn,options:[g,A]}},HXt=(g,A)=>{const I=JXt(g);return{name:I.name,fn:I.fn,options:[g,A]}},vXt=Object.defineProperty,qXt=(g,A)=>vXt(g,"name",{value:A,configurable:!0});function rkI(g){const[A,I]=X.useState(void 0);return IS(()=>{if(g){I({width:g.offsetWidth,height:g.offsetHeight});let e=0;const t=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const B=o[0];window.cancelAnimationFrame(e),e=window.requestAnimationFrame(()=>{let C,Q;if("borderBoxSize"in B){const i=B.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}qXt(rkI,"useSize");var TXt=Object.defineProperty,G3=(g,A)=>TXt(g,"name",{value:A,configurable:!0}),ckI={Partial:"partial"},hkI={Optimized:"optimized",Always:"always"},lkI="Popper",[DkI,dkI]=G5(lkI),[ZXt,ykI]=DkI(lkI),wkI=G3(g=>{const{__scopePopper:A,children:I}=g,[e,t]=X.useState(null),[o,B]=X.useState(void 0);return q.jsx(ZXt,{scope:A,anchor:e,onAnchorChange:t,placementState:o,setPlacementState:B,children:I})},"Popper"),OXt="PopperAnchor",WXt=X.forwardRef(G3(function(A,I){const{__scopePopper:e,virtualRef:t,...o}=A,B=ykI(OXt,e),C=X.useRef(null),Q=B.onAnchorChange,i=X.useCallback(c=>{C.current=c,c&&Q(c)},[Q]),E=xd(I,i),n=X.useRef(null);X.useEffect(()=>{if(!t)return;const c=n.current;n.current=t.current,c!==n.current&&Q(n.current)});const s=B.placementState&&$yA(B.placementState),r=s?.[0],a=s?.[1];return t?null:q.jsx(ux.div,{"data-radix-popper-side":r,"data-radix-popper-align":a,...o,ref:E})},"PopperAnchor")),ukI="PopperContent",[VXt,_$o]=DkI(ukI),jXt=X.forwardRef(G3(function(A,I){const{__scopePopper:e,side:t="bottom",sideOffset:o=0,align:B="center",alignOffset:C=0,arrowPadding:Q=0,avoidCollisions:i=!0,collisionBoundary:E=[],collisionPadding:n=0,sticky:s=ckI.Partial,hideWhenDetached:r=!1,updatePositionStrategy:a=hkI.Optimized,onPlaced:c,...h}=A,l=ykI(ukI,e),[D,d]=X.useState(null),y=xd(I,d),[w,u]=X.useState(null),G=rkI(w),m=G?.width??0,p=G?.height??0,k=t+(B!=="center"?"-"+B:""),S=typeof n=="number"?n:{top:0,right:0,bottom:0,left:0,...n},R=Array.isArray(E)?E:[E],x=R.length>0,N={padding:S,boundary:R.filter(GkI),altBoundary:x},{refs:U,floatingStyles:K,placement:_,isPositioned:H,middlewareData:T}=UXt({strategy:"fixed",placement:k,whileElementsMounted:G3((...CA)=>mXt(...CA,{animationFrame:a===hkI.Always}),"whileElementsMounted"),elements:{reference:l.anchor},middleware:[PXt({mainAxis:o+p,alignmentAxis:C}),i&&KXt({mainAxis:!0,crossAxis:!1,...s===ckI.Partial?{limiter:LXt()}:{},...N}),i&&YXt({...N}),_Xt({...N,apply:G3(({elements:CA,rects:hA,availableWidth:sA,availableHeight:cA})=>{const{width:SA,height:xA}=hA.reference,aA=CA.floating.style;aA.setProperty("--radix-popper-available-width",`${sA}px`),aA.setProperty("--radix-popper-available-height",`${cA}px`),aA.setProperty("--radix-popper-anchor-width",`${SA}px`),aA.setProperty("--radix-popper-anchor-height",`${xA}px`)},"apply")}),w&&HXt({element:w,padding:Q}),zXt({arrowWidth:m,arrowHeight:p}),r&&bXt(x?{strategy:"referenceHidden",...N}:{strategy:"referenceHidden",padding:N.padding,altBoundary:N.altBoundary})]}),j=l.setPlacementState;IS(()=>(j(_),()=>{j(void 0)}),[_,j]);const[W,O]=$yA(_),gA=Gx(c);IS(()=>{H&&gA?.()},[H,gA]);const tA=T.arrow?.x,IA=T.arrow?.y,QA=T.arrow?.centerOffset!==0,[nA,DA]=X.useState();return IS(()=>{D&&DA(window.getComputedStyle(D).zIndex)},[D]),q.jsx("div",{ref:U.setFloating,"data-radix-popper-content-wrapper":"",style:{...K,transform:H?K.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:nA,"--radix-popper-transform-origin":[T.transformOrigin?.x,T.transformOrigin?.y].join(" "),...T.hide?.referenceHidden&&{visibility:"hidden",pointerEvents:"none"}},dir:A.dir,children:q.jsx(VXt,{scope:e,placedSide:W,placedAlign:O,onArrowChange:u,arrowX:tA,arrowY:IA,shouldHideArrow:QA,children:q.jsx(ux.div,{"data-side":W,"data-align":O,...h,ref:y,style:{...h.style,animation:H?h.style?.animation:"none"}})})})},"PopperContent"));function GkI(g){return g!==null}G3(GkI,"isNotNull");var zXt=G3(g=>({name:"transformOrigin",options:g,fn(A){const{placement:I,rects:e,middlewareData:t}=A,B=t.arrow?.centerOffset!==0,C=B?0:g.arrowWidth,Q=B?0:g.arrowHeight,[i,E]=$yA(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=B?n:`${s}px`,c=`${-Q}px`):i==="top"?(a=B?n:`${s}px`,c=`${e.floating.height+Q}px`):i==="right"?(a=`${-Q}px`,c=B?n:`${r}px`):i==="left"&&(a=`${e.floating.width+Q}px`,c=B?n:`${r}px`),{data:{x:a,y:c}}}}),"transformOrigin");function $yA(g){const[A,I="center"]=g.split("-");return[A,I]}G3($yA,"getSideAndAlignFromPlacement");var XXt=Object.defineProperty,$Xt=(g,A)=>XXt(g,"name",{value:A,configurable:!0}),A$t=X.forwardRef($Xt(function(A,I){const{container:e,...t}=A,[o,B]=X.useState(!1);IS(()=>B(!0),[]);const C=e||o&&globalThis?.document?.body;return C?j1.createPortal(q.jsx(ux.div,{...t,ref:I}),C):null},"Portal")),g$t=Object.defineProperty,cJ=(g,A)=>g$t(g,"name",{value:A,configurable:!0});function mkI(g,A){return X.useReducer((I,e)=>A[I][e]??I,g)}cJ(mkI,"useStateMachine");var Kgg=cJ(g=>{const{present:A,children:I}=g,e=pkI(A),t=typeof I=="function"?I({present:e.isPresent}):X.Children.only(I),o=kkI(e.ref,MkI(t));return typeof I=="function"||e.isPresent?X.cloneElement(t,{ref:o}):null},"Presence");function pkI(g){const[A,I]=X.useState(),e=X.useRef(null),t=X.useRef(g),o=X.useRef("none"),B=X.useRef(void 0),C=g?"mounted":"unmounted",[Q,i]=mkI(C,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return X.useEffect(()=>{Q==="mounted"?(o.current=B.current??U7(e.current),B.current=void 0):o.current="none"},[Q]),IS(()=>{const E=e.current,n=t.current;if(n!==g){const r=o.current,a=U7(E);g?(B.current=a,i("MOUNT")):a==="none"||E?.display==="none"?i("UNMOUNT"):i(n&&r!==a?"ANIMATION_OUT":"UNMOUNT"),t.current=g}},[g,i]),IS(()=>{if(A){let E;const n=A.ownerDocument.defaultView??window,s=cJ(a=>{const h=U7(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&&(o.current=U7(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:X.useCallback(E=>{if(E){const n=getComputedStyle(E);e.current=n,B.current=U7(n)}else e.current=null;I(E)},[])}}cJ(pkI,"usePresence");function Lgg(g,A){if(typeof g=="function")return g(A);g!=null&&(g.current=A)}cJ(Lgg,"setRef");function kkI(...g){const A=X.useRef(g);return A.current=g,X.useCallback(I=>{const e=A.current;let t=!1;const o=e.map(B=>{const C=Lgg(B,I);return!t&&typeof C=="function"&&(t=!0),C});if(t)return()=>{for(let B=0;B<o.length;B++){const C=o[B];typeof C=="function"?C():Lgg(e[B],null)}}},[])}cJ(kkI,"useStableComposedRefs");function U7(g){return g?.animationName||"none"}cJ(U7,"getAnimationName");function MkI(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(MkI,"getElementRef");var I$t=Object.defineProperty,Ygg=(g,A)=>I$t(g,"name",{value:A,configurable:!0}),_gg=!1;function SkI(){const[g,A]=X.useState(_gg);return X.useEffect(()=>{_gg||(_gg=!0,A(!0))},[]),g}Ygg(SkI,"useIsHydrated");var fkI=fp[" useSyncExternalStore ".trim().toString()];function RkI(){return()=>{}}Ygg(RkI,"subscribe");function NkI(){return fkI(RkI,()=>!0,()=>!1)}Ygg(NkI,"useIsHydratedModern");var e$t=typeof fkI=="function"?NkI:SkI,t$t=Object.defineProperty,S5=(g,A)=>t$t(g,"name",{value:A,configurable:!0}),bgg="rovingFocusGroup.onEntryFocus",o$t={bubbles:!1,cancelable:!0},AwA="RovingFocusGroup",[Hgg,xkI,B$t]=sgg(AwA),[C$t,FkI]=G5(AwA,[B$t]),UkI={Vertical:"vertical",Horizontal:"horizontal"},Q$t={RTL:"rtl"},[i$t,E$t]=C$t(AwA),n$t=X.forwardRef(S5(function(A,I){return q.jsx(Hgg.Provider,{scope:A.__scopeRovingFocusGroup,children:q.jsx(Hgg.Slot,{scope:A.__scopeRovingFocusGroup,children:q.jsx(s$t,{...A,ref:I})})})},"RovingFocusGroup")),s$t=X.forwardRef(S5(function(A,I){const{__scopeRovingFocusGroup:e,orientation:t,loop:o=!1,dir:B,currentTabStopId:C,defaultCurrentTabStopId:Q,onCurrentTabStopIdChange:i,onEntryFocus:E,preventScrollOnEntryFocus:n=!1,...s}=A,r=X.useRef(null),a=xd(I,r),c=rgg(B),[h,l]=PyA({prop:C,defaultProp:Q??null,onChange:i,caller:AwA}),[D,d]=X.useState(!1),y=Gx(E),w=xkI(e),u=X.useRef(!1),[G,m]=X.useState(0);return X.useEffect(()=>{const p=r.current;if(p)return p.addEventListener(bgg,y),()=>p.removeEventListener(bgg,y)},[y]),q.jsx(i$t,{scope:e,orientation:t,dir:c,loop:o,currentTabStopId:h,onItemFocus:X.useCallback(p=>l(p),[l]),onItemShiftTab:X.useCallback(()=>d(!0),[]),onFocusableItemAdd:X.useCallback(()=>m(p=>p+1),[]),onFocusableItemRemove:X.useCallback(()=>m(p=>p-1),[]),children:q.jsx(ux.div,{tabIndex:D||G===0?-1:0,"data-orientation":t,...s,ref:a,style:{outline:"none",...A.style},onMouseDown:mn(A.onMouseDown,()=>{u.current=!0}),onFocus:mn(A.onFocus,p=>{const k=!u.current;if(p.target===p.currentTarget&&k&&!D){const S=new CustomEvent(bgg,o$t);if(p.currentTarget.dispatchEvent(S),!S.defaultPrevented){const R=w().filter(_=>_.focusable),x=R.find(_=>_.active),N=R.find(_=>_.id===h),K=[x,N,...R].filter(Boolean).map(_=>_.ref.current);vgg(K,n)}}u.current=!1}),onBlur:mn(A.onBlur,()=>d(!1))})})},"RovingFocusGroupImpl")),a$t="RovingFocusGroupItem",r$t=X.forwardRef(S5(function(A,I){const{__scopeRovingFocusGroup:e,focusable:t=!0,active:o=!1,tabStopId:B,children:C,...Q}=A,i=R7(),E=B||i,n=E$t(a$t,e),s=n.currentTabStopId===E,r=xkI(e),{onFocusableItemAdd:a,onFocusableItemRemove:c,currentTabStopId:h}=n,l=e$t();return IS(()=>{if(!(!l||!t))return a(),()=>c()},[l,t,a,c]),X.useEffect(()=>{if(!(l||!t))return a(),()=>c()},[l,t,a,c]),q.jsx(Hgg.ItemSlot,{scope:e,id:E,focusable:t,active:o,children:q.jsx(ux.span,{tabIndex:s?0:-1,"data-orientation":n.orientation,...Q,ref:I,onMouseDown:mn(A.onMouseDown,D=>{t?n.onItemFocus(E):D.preventDefault()}),onFocus:mn(A.onFocus,()=>n.onItemFocus(E)),onKeyDown:mn(A.onKeyDown,D=>{if(D.key==="Tab"&&D.shiftKey){n.onItemShiftTab();return}if(D.target!==D.currentTarget)return;const d=PkI(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?KkI(w,u+1):w.slice(u+1)}setTimeout(()=>vgg(w))}}),children:typeof C=="function"?C({isCurrentTabStop:s,hasTabStop:h!=null}):C})})},"RovingFocusGroupItem")),c$t={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function JkI(g,A){return A!==Q$t.RTL?g:g==="ArrowLeft"?"ArrowRight":g==="ArrowRight"?"ArrowLeft":g}S5(JkI,"getDirectionAwareKey");function PkI(g,A,I){const e=JkI(g.key,I);if(!(A===UkI.Vertical&&["ArrowLeft","ArrowRight"].includes(e))&&!(A===UkI.Horizontal&&["ArrowUp","ArrowDown"].includes(e)))return c$t[e]}S5(PkI,"getFocusIntent");function vgg(g,A=!1){const I=document.activeElement;for(const e of g)if(e===I||(e.focus({preventScroll:A}),document.activeElement!==I))return}S5(vgg,"focusFirst");function KkI(g,A){return g.map((I,e)=>g[(A+e)%g.length])}S5(KkI,"wrapArray");var h$t=function(g){if(typeof document>"u")return null;var A=Array.isArray(g)?g[0]:g;return A.ownerDocument.body},J7=new WeakMap,gwA=new WeakMap,IwA={},qgg=0,LkI=function(g){return g&&(g.host||LkI(g.parentNode))},l$t=function(g,A){return A.map(function(I){if(g.contains(I))return I;var e=LkI(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})},D$t=function(g,A,I,e){var t=l$t(A,Array.isArray(g)?g:[g]);IwA[I]||(IwA[I]=new WeakMap);var o=IwA[I],B=[],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=(J7.get(s)||0)+1,h=(o.get(s)||0)+1;J7.set(s,c),o.set(s,h),B.push(s),c===1&&a&&gwA.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(),qgg++,function(){B.forEach(function(n){var s=J7.get(n)-1,r=o.get(n)-1;J7.set(n,s),o.set(n,r),s||(gwA.has(n)||n.removeAttribute(e),gwA.delete(n)),r||n.removeAttribute(I)}),qgg--,qgg||(J7=new WeakMap,J7=new WeakMap,gwA=new WeakMap,IwA={})}},d$t=function(g,A,I){I===void 0&&(I="data-aria-hidden");var e=Array.from(Array.isArray(g)?g:[g]),t=h$t(g);return t?(e.push.apply(e,Array.from(t.querySelectorAll("[aria-live], script"))),D$t(e,t,I,"aria-hidden")):function(){return null}},Mx=function(){return Mx=Object.assign||function(A){for(var I,e=1,t=arguments.length;e<t;e++){I=arguments[e];for(var o in I)Object.prototype.hasOwnProperty.call(I,o)&&(A[o]=I[o])}return A},Mx.apply(this,arguments)};function YkI(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 y$t(g,A,I){for(var e=0,t=A.length,o;e<t;e++)(o||!(e in A))&&(o||(o=Array.prototype.slice.call(A,0,e)),o[e]=A[e]);return g.concat(o||Array.prototype.slice.call(A))}var ewA="right-scroll-bar-position",twA="width-before-scroll-bar",w$t="with-scroll-bars-hidden",u$t="--removed-body-scroll-bar-size";function Tgg(g,A){return typeof g=="function"?g(A):g&&(g.current=A),g}function G$t(g,A){var I=X.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 m$t=typeof window<"u"?X.useLayoutEffect:X.useEffect,_kI=new WeakMap;function p$t(g,A){var I=G$t(null,function(e){return g.forEach(function(t){return Tgg(t,e)})});return m$t(function(){var e=_kI.get(I);if(e){var t=new Set(e),o=new Set(g),B=I.current;t.forEach(function(C){o.has(C)||Tgg(C,null)}),o.forEach(function(C){t.has(C)||Tgg(C,B)})}_kI.set(I,g)},[g]),I}function k$t(g){return g}function M$t(g,A){A===void 0&&(A=k$t);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(o){var B=A(o,e);return I.push(B),function(){I=I.filter(function(C){return C!==B})}},assignSyncMedium:function(o){for(e=!0;I.length;){var B=I;I=[],B.forEach(o)}I={push:function(C){return o(C)},filter:function(){return I}}},assignMedium:function(o){e=!0;var B=[];if(I.length){var C=I;I=[],C.forEach(o),B=I}var Q=function(){var E=B;B=[],E.forEach(o)},i=function(){return Promise.resolve().then(Q)};i(),I={push:function(E){B.push(E),i()},filter:function(E){return B=B.filter(E),I}}}};return t}function S$t(g){g===void 0&&(g={});var A=M$t(null);return A.options=Mx({async:!0,ssr:!1},g),A}var bkI=function(g){var A=g.sideCar,I=YkI(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 X.createElement(e,Mx({},I))};bkI.isSideCarExport=!0;function f$t(g,A){return g.useMedium(A),bkI}var HkI=S$t(),Zgg=function(){},owA=X.forwardRef(function(g,A){var I=X.useRef(null),e=X.useState({onScrollCapture:Zgg,onWheelCapture:Zgg,onTouchMoveCapture:Zgg}),t=e[0],o=e[1],B=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=YkI(g,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),w=s,u=p$t([I,A]),G=Mx(Mx({},y),t);return X.createElement(X.Fragment,null,E&&X.createElement(w,{sideCar:HkI,removeScrollBar:i,shards:n,noRelative:r,noIsolation:a,inert:c,setCallbacks:o,allowPinchZoom:!!h,lockRef:I,gapMode:d}),B?X.cloneElement(X.Children.only(C),Mx(Mx({},G),{ref:u})):X.createElement(D,Mx({},G,{className:Q,ref:u}),C))});owA.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},owA.classNames={fullWidth:twA,zeroRight:ewA};var R$t=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function N$t(){if(!document)return null;var g=document.createElement("style");g.type="text/css";var A=R$t();return A&&g.setAttribute("nonce",A),g}function x$t(g,A){g.styleSheet?g.styleSheet.cssText=A:g.appendChild(document.createTextNode(A))}function F$t(g){var A=document.head||document.getElementsByTagName("head")[0];A.appendChild(g)}var U$t=function(){var g=0,A=null;return{add:function(I){g==0&&(A=N$t())&&(x$t(A,I),F$t(A)),g++},remove:function(){g--,!g&&A&&(A.parentNode&&A.parentNode.removeChild(A),A=null)}}},J$t=function(){var g=U$t();return function(A,I){X.useEffect(function(){return g.add(A),function(){g.remove()}},[A&&I])}},vkI=function(){var g=J$t(),A=function(I){var e=I.styles,t=I.dynamic;return g(e,t),null};return A},P$t={left:0,top:0,right:0,gap:0},Ogg=function(g){return parseInt(g||"",10)||0},K$t=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[Ogg(I),Ogg(e),Ogg(t)]},L$t=function(g){if(g===void 0&&(g="margin"),typeof window>"u")return P$t;var A=K$t(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])}},Y$t=vkI(),P7="data-scroll-locked",_$t=function(g,A,I,e){var t=g.left,o=g.top,B=g.right,C=g.gap;return I===void 0&&(I="margin"),`
5358
5358
  .`.concat(w$t,` {
5359
5359
  overflow: hidden `).concat(e,`;
5360
5360
  padding-right: `).concat(C,"px ").concat(e,`;