@tscircuit/runframe 0.0.1540 → 0.0.1541
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/standalone.min.js
CHANGED
|
@@ -5135,7 +5135,7 @@ ${a.join(`
|
|
|
5135
5135
|
${Q}polygon: ${C.polygon.vertices}
|
|
5136
5136
|
`:a+=`
|
|
5137
5137
|
`,C.children.length>0&&c.push(C.children)}return a}};A.exports=s}}),_ft=ae({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(t,A){var e=wft(),i=bft(),o=class{constructor(n){this.polygonTree=new i,this.rootnode=new e(null),n&&this.addPolygons(n)}invert(){this.polygonTree.invert(),this.rootnode.invert()}clipTo(n,s=!1){this.rootnode.clipTo(n,s)}allPolygons(){const n=[];return this.polygonTree.getPolygons(n),n}addPolygons(n){const s=new Array(n.length);for(let r=0;r<n.length;r++)s[r]=this.polygonTree.addChild(n[r]);this.rootnode.addPolygonTreeNodes(s)}clear(){this.polygonTree.clear()}toString(){return"Tree: "+this.polygonTree.toString("")}};A.exports=o}}),sEA=ae({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(t,A){A.exports={Tree:_ft()}}}),xft=ae({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(t,A){var e=$n(),i=nEA(),{Tree:o}=sEA(),n=(s,r)=>{if(!i(s,r))return e.create();const a=new o(e.toPolygons(s)),g=new o(e.toPolygons(r));a.invert(),g.clipTo(a),g.invert(),a.clipTo(g),g.clipTo(a),a.addPolygons(g.allPolygons()),a.invert();const c=a.allPolygons();return e.create(c)};A.exports=n}}),zXA=ae({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(t,A){var e=Yn(),i=SH(),o=xft(),n=(...s)=>{s=e(s);let r=s.shift();return s.forEach(a=>{r=o(r,a)}),r=i(r),r};A.exports=n}}),kft=ae({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(t,A){var e=Yn(),i=$n(),o=yx(),n=iEA(),s=oEA(),r=zXA(),a=(...g)=>{g=e(g);const c=g.map(B=>s({z0:-1,z1:1},B)),I=r(c),l=o(I);return n(l,i.toPolygons(I))};A.exports=a}}),Fft=ae({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(t,A){var e=Yn(),i=DH(),o=Xn(),n=$n(),s=kft(),r=zXA(),a=(...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only intersect of the types are supported");const c=g[0];return o.isA(c)?s(g):n.isA(c)?r(g):c};A.exports=a}}),Gft=ae({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(t,A){var e=So(),i=yx(),o=$n(),n=g=>g.sort((c,I)=>c-I).filter((c,I,l)=>!I||c!==l[I-1]),s=(g,c,I)=>{const l=`${c}`,B=g.get(l);B===void 0?g.set(l,[I]):B.push(I)},r=(g,c)=>{const I=`${c}`;return g.get(I)},a=g=>{const c=i(g),I=o.toPolygons(g),l=I.length,B=new Map,C=e.create();I.forEach((d,f)=>{d.vertices.forEach(m=>{s(B,e.snap(C,m,c),f)})});const Q=I.map(d=>{let f=[];return d.vertices.forEach(m=>{f=f.concat(r(B,e.snap(C,m,c)))}),{e:1,d:n(f)}});B.clear();let h=0;const E=Q.length;for(let d=0;d<E;d++){const f=Q[d];if(f.e>0){const m=new Array(l);m[d]=!0;do h=0,m.forEach((D,w)=>{const b=Q[w];if(b.e>0){b.e=-1;for(let k=0;k<b.d.length;k++)m[b.d[k]]=!0;h++}});while(h>0);f.indexes=m}}const u=[];for(let d=0;d<E;d++)if(Q[d].indexes){const f=[];Q[d].indexes.forEach((m,D)=>f.push(I[D])),u.push(o.create(f))}return u};A.exports=a}}),Rft=ae({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(t,A){var e=Yn(),i=$n(),o=Gft(),n=(...s)=>{if(s=e(s),s.length===0)throw new Error("wrong number of arguments");const r=s.map(a=>i.isA(a)?o(a):a);return r.length===1?r[0]:r};A.exports=n}}),vft=ae({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(t,A){var e=$n(),i=nEA(),{Tree:o}=sEA(),n=(s,r)=>{if(!i(s,r))return e.clone(s);const a=new o(e.toPolygons(s)),g=new o(e.toPolygons(r));a.invert(),a.clipTo(g),g.clipTo(a,!0),a.addPolygons(g.allPolygons()),a.invert();const c=a.allPolygons();return e.create(c)};A.exports=n}}),XXA=ae({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(t,A){var e=Yn(),i=SH(),o=vft(),n=(...s)=>{s=e(s);let r=s.shift();return s.forEach(a=>{r=o(r,a)}),r=i(r),r};A.exports=n}}),Mft=ae({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(t,A){var e=Yn(),i=$n(),o=yx(),n=iEA(),s=oEA(),r=XXA(),a=(...g)=>{g=e(g);const c=g.map(B=>s({z0:-1,z1:1},B)),I=r(c),l=o(I);return n(l,i.toPolygons(I))};A.exports=a}}),Nft=ae({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(t,A){var e=Yn(),i=DH(),o=Xn(),n=$n(),s=Mft(),r=XXA(),a=(...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only subtract of the types are supported");const c=g[0];return o.isA(c)?s(g):n.isA(c)?r(g):c};A.exports=a}}),$XA=ae({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(t,A){var e=$n(),i=nEA(),{Tree:o}=sEA(),n=(r,a)=>{if(!i(r,a))return s(r,a);const g=new o(e.toPolygons(r)),c=new o(e.toPolygons(a));g.clipTo(c,!1),c.clipTo(g),c.invert(),c.clipTo(g),c.invert();const I=g.allPolygons().concat(c.allPolygons());return e.create(I)},s=(r,a)=>{let g=e.toPolygons(r);return g=g.concat(e.toPolygons(a)),e.create(g)};A.exports=n}}),A6A=ae({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(t,A){var e=Yn(),i=SH(),o=$XA(),n=(...s)=>{s=e(s);let r;for(r=1;r<s.length;r+=2)s.push(o(s[r-1],s[r]));let a=s[r-1];return a=i(a),a};A.exports=n}}),e6A=ae({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(t,A){var e=Yn(),i=$n(),o=yx(),n=iEA(),s=oEA(),r=A6A(),a=(...g)=>{g=e(g);const c=g.map(B=>s({z0:-1,z1:1},B)),I=r(c),l=o(I);return n(l,i.toPolygons(I))};A.exports=a}}),rEA=ae({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(t,A){var e=Yn(),i=DH(),o=Xn(),n=$n(),s=e6A(),r=A6A(),a=(...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only unions of the same type are supported");const c=g[0];return o.isA(c)?s(g):n.isA(c)?r(g):c};A.exports=a}}),sN=ae({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(t,A){A.exports={intersect:Fft(),scission:Rft(),subtract:Nft(),union:rEA()}}}),NW=ae({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(t,A){var{EPS:e,TAU:i}=wr(),o=kXA(),n=zhA(),s=ms(),r=RW(),a=(g,c)=>{const I={delta:1,corners:"edge",closed:!1,segments:16};let{delta:l,corners:B,closed:C,segments:Q}=Object.assign({},I,g);if(Math.abs(l)<e)return c;let h=g.closed?r(c):1;h===0&&(h=1);const E=h>0&&l>=0||h<0&&l<0;l=Math.abs(l);let u=null,d=[];const f=[],m=s.create(),D=c.length;for(let w=0;w<D;w++){const b=(w+1)%D,k=c[w],_=c[b];E?s.subtract(m,k,_):s.subtract(m,_,k),s.normal(m,m),s.normalize(m,m),s.scale(m,m,l);const M=s.add(s.create(),k,m),v=s.add(s.create(),_,m),U=[M,v];if(u!=null&&(C||!C&&b!==0)){const J=o(u[0],u[1],U[0],U[1]);J?(d.pop(),U[0]=J):f.push({c:k,s0:u,s1:U})}u=[M,v],!(b===0&&!C)&&(d.push(U[0]),d.push(U[1]))}if(C&&u!=null){const w=d[0],b=d[1],k=o(u[0],u[1],w,b);if(k)d[0]=k,d.pop();else{const _=c[0],M=[w,b];f.push({c:_,s0:u,s1:M})}}if(B==="edge"){const w=new Map;d.forEach((_,M)=>w.set(_,M));const b=n.create(),k=n.create();f.forEach(_=>{n.fromPoints(b,_.s0[0],_.s0[1]),n.fromPoints(k,_.s1[0],_.s1[1]);const M=n.intersectPointOfLines(b,k);if(Number.isFinite(M[0])&&Number.isFinite(M[1])){const v=_.s0[1],U=w.get(v);d[U]=M,d[(U+1)%d.length]=void 0}else{const v=_.s1[0],U=w.get(v);d[U]=void 0}}),d=d.filter(_=>_!==void 0)}if(B==="round"){let w=Math.floor(Q/4);const b=s.create();f.forEach(k=>{let _=s.angle(s.subtract(b,k.s1[0],k.c));if(_-=s.angle(s.subtract(b,k.s0[1],k.c)),E&&_<0&&(_=_+Math.PI,_<0&&(_=_+Math.PI)),!E&&_>0&&(_=_-Math.PI,_>0&&(_=_-Math.PI)),_!==0){w=Math.floor(Q*(Math.abs(_)/i));const M=_/w,v=s.angle(s.subtract(b,k.s0[1],k.c)),U=[];for(let J=1;J<w;J++){const Y=v+M*J,O=s.fromAngleRadians(s.create(),Y);s.scale(O,O,l),s.add(O,O,k.c),U.push(O)}if(U.length>0){const J=k.s0[1];let Y=d.findIndex(O=>s.equals(J,O));Y=(Y+1)%d.length,d.splice(Y,0,...U)}}else{const M=k.s1[0],v=d.findIndex(U=>s.equals(M,U));d.splice(v,1)}})}return d};A.exports=a}}),Lft=ae({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(t,A){var e=Xn(),i=NW(),o=(n,s)=>{const r={delta:1,corners:"edge",segments:16},{delta:a,corners:g,segments:c}=Object.assign({},r,n);if(!(g==="edge"||g==="chamfer"||g==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const B=e.toOutlines(s).map(C=>(n={delta:a,corners:g,closed:!0,segments:c},i(n,C))).reduce((C,Q)=>C.concat(e.toSides(e.fromPoints(Q))),[]);return e.create(B)};A.exports=o}}),Uft=ae({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(t,A){var e=$g(),i=So(),o=$n(),n=ar(),s=(r,a)=>{i.dot(n.plane(a),r)>0&&(a=n.invert(a));const c=[a],I=n.transform(e.fromTranslation(e.create(),r),a),l=a.vertices.length;for(let B=0;B<l;B++){const C=B<l-1?B+1:0,Q=n.create([a.vertices[B],I.vertices[B],I.vertices[C],a.vertices[C]]);c.push(Q)}return c.push(n.invert(I)),o.create(c)};A.exports=s}}),Hft=ae({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(t,A){var{EPS:e,TAU:i}=wr(),o=$g(),n=So(),s=VXA(),r=$n(),a=ar(),g=TXA(),c=SH(),I=$XA(),l=Uft(),B=(E,u,d)=>{const f=u.toString();if(E.has(f))E.get(f)[1].push(d);else{const m=[u,[d]];E.set(f,m)}},C=(E,u,d)=>{const f=u[0].toString(),m=u[1].toString(),D=f<m?`${f},${m}`:`${m},${f}`;if(E.has(D))E.get(D)[1].push(d);else{const w=[u,[d]];E.set(D,w)}},Q=(E,u)=>{E.findIndex(f=>f===u)<0&&E.push(u)},h=(E,u)=>{const d={delta:1,segments:12},{delta:f,segments:m}=Object.assign({},d,E);let D=r.create();const w=new Map,b=new Map,k=n.create(),_=n.create();return r.toPolygons(u).forEach((v,U)=>{const J=n.scale(n.create(),a.plane(v),2*f),Y=a.transform(o.fromTranslation(o.create(),n.scale(n.create(),J,-.5)),v),O=l(J,Y);D=I(D,O);const Z=v.vertices;for(let $=0;$<Z.length;$++){B(w,Z[$],a.plane(v));const iA=($+1)%Z.length,aA=[Z[$],Z[iA]];C(b,aA,a.plane(v))}}),b.forEach(v=>{const U=v[0],J=v[1],Y=U[0],O=U[1],Z=n.subtract(n.create(),O,Y);n.normalize(Z,Z);const $=J[0],iA=n.cross(n.create(),$,Z);let aA=[];for(let NA=0;NA<m;NA++)Q(aA,NA*i/m);for(let NA=0,QA=J.length;NA<QA;NA++){const xA=J[NA],uA=n.dot(iA,xA),OA=n.dot($,xA);let PA=Math.atan2(uA,OA);PA<0&&(PA+=i),Q(aA,PA),PA=Math.atan2(-uA,-OA),PA<0&&(PA+=i),Q(aA,PA)}aA=aA.sort(s);const eA=aA.length;let oA,rA;const lA=[],EA=[],bA=[];for(let NA=-1;NA<eA;NA++){const QA=aA[NA<0?NA+eA:NA],xA=Math.sin(QA),uA=Math.cos(QA);n.scale(k,$,uA*f),n.scale(_,iA,xA*f),n.add(k,k,_);const OA=n.add(n.create(),Y,k),PA=n.add(n.create(),O,k);let ne=!1;if(NA>=0&&n.distance(OA,oA)<e&&(ne=!0),!ne){if(NA>=0){lA.push(OA),EA.push(PA);const yA=[rA,PA,OA,oA],Ae=a.create(yA);bA.push(Ae)}oA=OA,rA=PA}}EA.reverse(),bA.push(a.create(lA)),bA.push(a.create(EA));const GA=r.create(bA);D=I(D,GA)}),w.forEach(v=>{const U=v[0],J=v[1],Y=J[0];let O=null,Z=0;for(let eA=1;eA<J.length;eA++){const oA=J[eA],rA=n.cross(k,Y,oA),lA=n.length(rA);lA>.05&&lA>Z&&(Z=lA,O=oA)}O||(O=n.orthogonal(k,Y));const $=n.cross(k,Y,O);n.normalize($,$);const iA=n.cross(_,$,Y),aA=g({center:[U[0],U[1],U[2]],radius:f,segments:m,axes:[Y,$,iA]});D=I(D,aA)}),c(D)};A.exports=h}}),Yft=ae({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(t,A){var e=$n(),i=rEA(),o=Hft(),n=(s,r)=>{const a={delta:1,corners:"round",segments:12},{delta:g,corners:c,segments:I}=Object.assign({},a,s);if(c!=="round")throw new Error('corners must be "round" for 3D geometries');if(e.toPolygons(r).length===0)throw new Error("the given geometry cannot be empty");s={delta:g,corners:c,segments:I};const B=o(s,r);return i(r,B)};A.exports=n}}),Jft=ae({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(t,A){var e=RW(),i=ms(),o=Xn(),n=Gg(),s=NW(),r=c=>{let{external:I,internal:l}=c;e(I)<0?I=I.reverse():l=l.reverse();const B=n.fromPoints({closed:!0},I),C=n.fromPoints({closed:!0},l),Q=o.toSides(o.fromPoints(n.toPoints(B))),h=o.toSides(o.fromPoints(n.toPoints(C)));return Q.push(...h),o.create(Q)},a=(c,I,l,B)=>{const{points:C,external:Q,internal:h}=c,E=Math.floor(I/2),u=[],d=[];if(l==="round"&&E>0){const m=Math.PI/E,D=C[C.length-1],w=i.angle(i.subtract(i.create(),Q[Q.length-1],D)),b=C[0],k=i.angle(i.subtract(i.create(),h[0],b));for(let _=1;_<E;_++){let M=w+m*_,v=i.fromAngleRadians(i.create(),M);i.scale(v,v,B),i.add(v,v,D),u.push(v),M=k+m*_,v=i.fromAngleRadians(i.create(),M),i.scale(v,v,B),i.add(v,v,b),d.push(v)}}const f=[];return f.push(...Q,...u,...h.reverse(),...d),o.fromPoints(f)},g=(c,I)=>{c=Object.assign({},{delta:1,corners:"edge",segments:16},c);const{delta:B,corners:C,segments:Q}=c;if(B<=0)throw new Error("the given delta must be positive for paths");if(!(C==="edge"||C==="chamfer"||C==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const h=I.isClosed,E=n.toPoints(I);if(E.length===0)throw new Error("the given geometry cannot be empty");const u={points:E,external:s({delta:B,corners:C,segments:Q,closed:h},E),internal:s({delta:-B,corners:C,segments:Q,closed:h},E)};return I.isClosed?r(u):a(u,Q,C,B)};A.exports=g}}),aEA=ae({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(t,A){var e=Yn(),i=Xn(),o=$n(),n=Gg(),s=Lft(),r=Yft(),a=Jft(),g=(c,...I)=>{if(I=e(I),I.length===0)throw new Error("wrong number of arguments");const l=I.map(B=>n.isA(B)?a(c,B):i.isA(B)?s(c,B):o.isA(B)?r(c,B):B);return l.length===1?l[0]:l};A.exports=g}}),Tft=ae({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(t,A){var e=Xn(),i=OhA(),o=NW(),n=(s,r)=>{const a={delta:1,corners:"edge",segments:0},{delta:g,corners:c,segments:I}=Object.assign({},a,s);if(!(c==="edge"||c==="chamfer"||c==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const l=e.toOutlines(r),C=l.map(Q=>(s={delta:l.reduce((u,d)=>u+i.arePointsInside(Q,i.create(d)),0)%2===0?g:-g,corners:c,closed:!0,segments:I},o(s,Q))).reduce((Q,h)=>Q.concat(e.toSides(e.fromPoints(h))),[]);return e.create(C)};A.exports=n}}),Kft=ae({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(t,A){var e=Gg(),i=NW(),o=(n,s)=>{const r={delta:1,corners:"edge",closed:s.isClosed,segments:16},{delta:a,corners:g,closed:c,segments:I}=Object.assign({},r,n);if(!(g==="edge"||g==="chamfer"||g==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');n={delta:a,corners:g,closed:c,segments:I};const l=i(n,e.toPoints(s));return e.fromPoints({closed:c},l)};A.exports=o}}),Pft=ae({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(t,A){var e=Yn(),i=Xn(),o=Gg(),n=Tft(),s=Kft(),r=(a,...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");const c=g.map(I=>o.isA(I)?s(a,I):i.isA(I)?n(a,I):I);return c.length===1?c[0]:c};A.exports=r}}),t6A=ae({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(t,A){A.exports={expand:aEA(),offset:Pft()}}}),LW=ae({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(t,A){var e=$g(),i=So(),o=Xn(),n=nN(),s=MW(),r=(a,g)=>{const c={offset:[0,0,1],twistAngle:0,twistSteps:12,repair:!0};let{offset:I,twistAngle:l,twistSteps:B,repair:C}=Object.assign({},c,a);if(B<1)throw new Error("twistSteps must be 1 or more");l===0&&(B=1);const Q=i.clone(I),h=o.toSides(g);if(h.length===0)throw new Error("the given geometry cannot be empty");const E=n.fromSides(h);Q[2]<0&&n.reverse(E,E);const u=e.create(),d=(f,m,D)=>{const w=m/B*l,b=i.scale(i.create(),Q,m/B);return e.multiply(u,e.fromZRotation(u,w),e.fromTranslation(e.create(),b)),n.transform(u,D)};return a={numberOfSlices:B+1,capStart:!0,capEnd:!0,repair:C,callback:d},s(a,E)};A.exports=r}}),qft=ae({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(t,A){var e=Xn(),i=Gg(),o=LW(),n=(s,r)=>{if(!r.isClosed)throw new Error("extruded path must be closed");const a=i.toPoints(r),g=e.fromPoints(a);return o(s,g)};A.exports=n}}),Oft=ae({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(t,A){var e=Yn(),i=Xn(),o=Gg(),n=LW(),s=qft(),r=(a,...g)=>{const c={height:1,twistAngle:0,twistSteps:1,repair:!0},{height:I,twistAngle:l,twistSteps:B,repair:C}=Object.assign({},c,a);if(g=e(g),g.length===0)throw new Error("wrong number of arguments");a={offset:[0,0,I],twistAngle:l,twistSteps:B,repair:C};const Q=g.map(h=>o.isA(h)?s(a,h):i.isA(h)?n(a,h):h);return Q.length===1?Q[0]:Q};A.exports=r}}),Wft=ae({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(t,A){var e=Gg(),i=aEA(),o=LW(),n=(s,r)=>{const a={size:1,height:1},{size:g,height:c}=Object.assign({},a,s);if(s.delta=g,s.offset=[0,0,c],e.toPoints(r).length===0)throw new Error("the given geometry cannot be empty");const l=i(s,r);return o(s,l)};A.exports=n}}),Zft=ae({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(t,A){var{area:e}=fH(),i=Xn(),o=Gg(),n=aEA(),s=LW(),r=(a,g)=>{const c={size:1,height:1},{size:I,height:l}=Object.assign({},c,a);a.delta=I,a.offset=[0,0,l];const B=i.toOutlines(g);if(B.length===0)throw new Error("the given geometry cannot be empty");const Q=B.map(E=>(e(E)<0&&E.reverse(),n(a,o.fromPoints({closed:!0},E)))).reduce((E,u)=>E.concat(i.toSides(u)),[]),h=i.create(Q);return s(a,h)};A.exports=r}}),Vft=ae({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(t,A){var e=Yn(),i=Xn(),o=Gg(),n=Wft(),s=Zft(),r=(a,...g)=>{const c={size:1,height:1},{size:I,height:l}=Object.assign({},c,a);if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(I<=0)throw new Error("size must be positive");if(l<=0)throw new Error("height must be positive");const B=g.map(C=>o.isA(C)?n(a,C):i.isA(C)?s(a,C):C);return B.length===1?B[0]:B};A.exports=r}}),jft=ae({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(t,A){var{TAU:e}=wr(),i=$g(),o=Xn(),n=MW(),s=nN(),r=(a,g)=>{const c={angle:e,startAngle:0,pitch:10,height:0,endOffset:0,segmentsPerRotation:32};let{angle:I,startAngle:l,pitch:B,height:C,endOffset:Q,segmentsPerRotation:h}=Object.assign({},c,a);if(C!=0&&(B=C/(I/e)),h<3)throw new Error("The number of segments per rotation needs to be at least 3.");const u=o.toSides(g);if(u.length===0)throw new Error("The given geometry cannot be empty");const d=u.filter(_=>_[0][0]>=0);let f=s.fromSides(u);d.length===0&&(f=s.reverse(f));const m=Math.round(h/e*Math.abs(I)),D=m>=2?m:2,w=i.create(),b=i.create(),k=(_,M,v)=>{const U=l+I/D*M,J=Q/D*M,Y=(U-l)/e*B;return i.multiply(w,i.fromTranslation(i.create(),[J,0,Y*Math.sign(I)]),i.fromXRotation(i.create(),-e/4*Math.sign(I))),i.multiply(b,i.fromZRotation(i.create(),U),w),s.transform(b,v)};return n({numberOfSlices:D+1,callback:k},f)};A.exports=r}}),zft=ae({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(t,A){var e=Yn(),i=jhA(),o=hD(),n=$g(),s=Xn(),r=$n(),a=ar(),g=yx(),c=e6A(),I=(B,C)=>{const Q=o.fromNormalAndPoint(o.create(),B.axis,B.origin);if(Number.isNaN(Q[0])||Number.isNaN(Q[1])||Number.isNaN(Q[2])||Number.isNaN(Q[3]))throw new Error("project: invalid axis or origin");const h=g(C),E=h*h*Math.sqrt(3)/4;if(h===0)return s.create();const u=r.toPolygons(C);let d=[];for(let m=0;m<u.length;m++){const D=u[m].vertices.map(k=>o.projectionOfPoint(Q,k)),w=a.create(D),b=a.plane(w);i(Q,b)&&(a.measureArea(w)<E||d.push(w))}if(!i(Q,[0,0,1])){const m=n.fromVectorRotation(n.create(),Q,[0,0,1]);d=d.map(D=>a.transform(m,D))}d=d.sort((m,D)=>a.measureArea(D)-a.measureArea(m));const f=d.map(m=>s.fromPoints(m.vertices));return c(f)},l=(B,...C)=>{const Q={axis:[0,0,1],origin:[0,0,0]},{axis:h,origin:E}=Object.assign({},Q,B);if(C=e(C),C.length===0)throw new Error("wrong number of arguments");B={axis:h,origin:E};const u=C.map(d=>r.isA(d)?I(B,d):d);return u.length===1?u[0]:u};A.exports=l}}),bH=ae({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(t,A){A.exports={extrudeFromSlices:MW(),extrudeLinear:Oft(),extrudeRectangular:Vft(),extrudeRotate:OXA(),extrudeHelical:jft(),project:zft(),slice:nN()}}}),gEA=ae({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(t,A){var e=ms(),i=s=>{let r=e.fromValues(1/0,1/0);s.forEach(c=>{(c[1]<r[1]||c[1]===r[1]&&c[0]<r[0])&&(r=c)});const a=[];s.forEach(c=>{const I=n(c[1]-r[1],c[0]-r[0]),l=e.squaredDistance(c,r);a.push({point:c,angle:I,distSq:l})}),a.sort((c,I)=>c.angle!==I.angle?c.angle-I.angle:c.distSq-I.distSq);const g=[];return a.forEach(c=>{let I=g.length;for(;I>1&&o(g[I-2],g[I-1],c.point)<=Number.EPSILON;)g.pop(),I=g.length;g.push(c.point)}),g},o=(s,r,a)=>(r[0]-s[0])*(a[1]-s[1])-(r[1]-s[1])*(a[0]-s[0]),n=(s,r)=>s===0&&r===0?-1/0:-r/s;A.exports=i}}),cEA=ae({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(t,A){var e=Xn(),i=$n(),o=Gg(),n=s=>{const r=new Set,a=[],g=c=>{const I=c.toString();r.has(I)||(a.push(c),r.add(I))};return s.forEach(c=>{e.isA(c)?e.toPoints(c).forEach(g):i.isA(c)?i.toPoints(c).forEach(I=>I.forEach(g)):o.isA(c)&&o.toPoints(c).forEach(g)}),a};A.exports=n}}),Xft=ae({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(t,A){var e=Yn(),i=Gg(),o=gEA(),n=cEA(),s=(...r)=>{r=e(r);const a=n(r),g=o(a);return i.fromPoints({closed:!0},g)};A.exports=s}}),$ft=ae({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(t,A){var e=Yn(),i=Xn(),o=gEA(),n=cEA(),s=(...r)=>{r=e(r);const a=n(r),g=o(a);return g.length<3?i.create():i.fromPoints(g)};A.exports=s}}),i6A=ae({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(t,A){var e=ar(),i=eXA(),o=n=>i(n,{skipTriangulation:!0}).map(a=>{const g=a.map(c=>n[c]);return e.create(g)});A.exports=o}}),A0t=ae({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(t,A){var e=Yn(),i=$n(),o=cEA(),n=i6A(),s=(...r)=>{r=e(r);const a=o(r);return a.length===0?i.create():i.create(n(a))};A.exports=s}}),o6A=ae({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(t,A){var e=Yn(),i=DH(),o=Xn(),n=$n(),s=Gg(),r=Xft(),a=$ft(),g=A0t(),c=(...I)=>{if(I=e(I),I.length===0)throw new Error("wrong number of arguments");if(!i(I))throw new Error("only hulls of the same type are supported");const l=I[0];return s.isA(l)?r(I):o.isA(l)?a(I):n.isA(l)?g(I):l};A.exports=c}}),e0t=ae({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(t,A){var e=Yn(),i=rEA(),o=o6A(),n=(...s)=>{if(s=e(s),s.length<2)throw new Error("wrong number of arguments");const r=[];for(let a=1;a<s.length;a++)r.push(o(s[a-1],s[a]));return i(r)};A.exports=n}}),t0t=ae({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(t,A){A.exports={hull:o6A(),hullChain:e0t(),hullPoints2:gEA(),hullPoints3:i6A()}}}),n6A=ae({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(t,A){var e=So(),i=ar(),o=(s,r)=>{const a=Math.abs(i.measureArea(r));return Number.isFinite(a)&&a>s},n=(s,r)=>{let a=r.map(c=>{const I=c.vertices.map(C=>e.snap(e.create(),C,s)),l=[];for(let C=0;C<I.length;C++){const Q=(C+1)%I.length;e.equals(I[C],I[Q])||l.push(I[C])}const B=i.create(l);return c.color&&(B.color=c.color),B});const g=s*s*Math.sqrt(3)/4;return a=a.filter(c=>o(g,c)),a};A.exports=n}}),i0t=ae({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(t,A){var e=jhA(),i=So(),o=ar(),n=E=>{const u=o.toPoints(E),d=[];for(let f=0;f<u.length;f++){const m=(f+1)%u.length,D={v1:u[f],v2:u[m]};d.push(D)}for(let f=0;f<d.length;f++){const m=(f+1)%u.length;d[f].next=d[m],d[m].prev=d[f]}return d},s=(E,u)=>{const d=`${u.v1}:${u.v2}`;E.set(d,u)},r=(E,u)=>{const d=`${u.v1}:${u.v2}`;E.delete(d)},a=(E,u)=>{const d=`${u.v2}:${u.v1}`;return E.get(d)},g=(E,u,d)=>{let f=E.prev.v1,m=E.prev.v2,D=u.next.v2;const w=l(f,m,D,d);f=u.prev.v1,m=u.prev.v2,D=E.next.v2;const b=l(f,m,D,d);return[w,b]},c=i.create(),I=i.create(),l=(E,u,d,f)=>{const m=i.subtract(c,u,E),D=i.subtract(I,d,u);return i.cross(m,m,D),i.dot(m,f)},B=E=>{let u;const d=[];for(;E.next;){const f=E.next;d.push(E.v1),E.v1=null,E.v2=null,E.next=null,E.prev=null,E=f}return d.length>0&&(u=o.create(d)),u},C=E=>{if(E.length<2)return E;const u=E[0].plane,d=E.slice(),f=new Map;for(;d.length>0;){const D=d.shift(),w=n(D);for(let b=0;b<w.length;b++){const k=w[b],_=a(f,k);if(_){const M=g(k,_,u);if(M[0]>=0&&M[1]>=0){const v=_.next,U=k.next;k.prev.next=_.next,k.next.prev=_.prev,_.prev.next=k.next,_.next.prev=k.prev,k.v1=null,k.v2=null,k.next=null,k.prev=null,r(f,_),_.v1=null,_.v2=null,_.next=null,_.prev=null;const J=(Y,O,Z)=>{const $={v1:Z.v1,v2:O.v2,next:O.next,prev:Z.prev};Z.prev.next=$,O.next.prev=$,r(Y,O),O.v1=null,O.v2=null,O.next=null,O.prev=null,r(Y,Z),Z.v1=null,Z.v2=null,Z.next=null,Z.prev=null};M[0]===0&&J(f,v,v.prev),M[1]===0&&J(f,U,U.prev)}}else k.next&&s(f,k)}}const m=[];return f.forEach(D=>{const w=B(D);w&&m.push(w)}),f.clear(),m},Q=(E,u)=>Math.abs(E[3]-u[3])<15e-8?e(E,u):!1,h=(E,u)=>{const d=[];u.forEach(m=>{const D=d.find(w=>Q(w[0],o.plane(m)));D?D[1].push(m):d.push([o.plane(m),[m]])});let f=[];return d.forEach(m=>{const D=m[1],w=C(D);f=f.concat(w)}),f};A.exports=h}}),o0t=ae({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(t,A){var e=wr(),i=So(),o=ar(),n=g=>`${g}`,s=(g,c,I,l,B,C)=>{const Q=n(l),h=n(B),E=`${Q}/${h}`,u=`${h}/${Q}`;if(g.has(u))return r(g,c,I,B,l,null),null;const d={vertex0:l,vertex1:B,polygonindex:C};return g.has(E)?g.get(E).push(d):g.set(E,[d]),c.has(Q)?c.get(Q).push(E):c.set(Q,[E]),I.has(h)?I.get(h).push(E):I.set(h,[E]),E},r=(g,c,I,l,B,C)=>{const Q=n(l),h=n(B),E=`${Q}/${h}`;let u=-1;const d=g.get(E);for(let f=0;f<d.length;f++){const m=d[f];let D=n(m.vertex0);if(D===Q&&(D=n(m.vertex1),D===h&&!(C!==null&&m.polygonindex!==C))){u=f;break}}d.splice(u,1),d.length===0&&g.delete(E),u=c.get(Q).indexOf(E),c.get(Q).splice(u,1),c.get(Q).length===0&&c.delete(Q),u=I.get(h).indexOf(E),I.get(h).splice(u,1),I.get(h).length===0&&I.delete(h)},a=g=>{const c=new Map;for(let I=0;I<g.length;I++){const l=g[I],B=l.vertices.length;if(B>=3){let C=l.vertices[0],Q=n(C);for(let h=0;h<B;h++){let E=h+1;E===B&&(E=0);const u=l.vertices[E],d=n(u),f=`${Q}/${d}`,m=`${d}/${Q}`;if(c.has(m)){const D=c.get(m);D.splice(-1,1),D.length===0&&c.delete(m)}else{const D={vertex0:C,vertex1:u,polygonindex:I};c.has(f)?c.get(f).push(D):c.set(f,[D])}C=u,Q=d}}else console.warn("warning: invalid polygon found during insertTjunctions")}if(c.size>0){const I=new Map,l=new Map,B=new Map;for(const[Q,h]of c)B.set(Q,!0),h.forEach(E=>{const u=n(E.vertex0),d=n(E.vertex1);I.has(u)?I.get(u).push(Q):I.set(u,[Q]),l.has(d)?l.get(d).push(Q):l.set(d,[Q])});const C=g.slice(0);for(;c.size!==0;){for(const h of c.keys())B.set(h,!0);let Q=!1;for(;;){const h=Array.from(B.keys());if(h.length===0)break;const E=h[0];let u=!0;if(c.has(E)){const f=c.get(E)[0];for(let m=0;m<2;m++){const D=m===0?f.vertex0:f.vertex1,w=m===0?f.vertex1:f.vertex0,b=n(D),k=n(w);let _=[];m===0?l.has(b)&&(_=l.get(b)):I.has(b)&&(_=I.get(b));for(let M=0;M<_.length;M++){const v=_[M],U=c.get(v)[0],J=m===0?U.vertex0:U.vertex1;if(m===0?U.vertex1:U.vertex0,n(J)===k){r(c,I,l,D,w,null),r(c,I,l,w,D,null),u=!1,m=2,Q=!0;break}else{const O=D,Z=w,$=J,iA=i.subtract(i.create(),$,O),aA=i.dot(i.subtract(i.create(),Z,O),iA)/i.dot(iA,iA);if(aA>0&&aA<1){const eA=i.scale(i.create(),iA,aA);if(i.add(eA,eA,O),i.squaredDistance(eA,Z)<e.EPS*e.EPS){const rA=U.polygonindex,lA=C[rA],EA=n(U.vertex1);let bA=-1;for(let uA=0;uA<lA.vertices.length;uA++)if(n(lA.vertices[uA])===EA){bA=uA;break}const GA=lA.vertices.slice(0);GA.splice(bA,0,w);const NA=o.create(GA);C[rA]=NA,r(c,I,l,U.vertex0,U.vertex1,rA);const QA=s(c,I,l,U.vertex0,w,rA),xA=s(c,I,l,w,U.vertex1,rA);QA!==null&&B.set(QA,!0),xA!==null&&B.set(xA,!0),u=!1,m=2,Q=!0;break}}}}}}u&&B.delete(E)}if(!Q)break}g=C}return c.clear(),g};A.exports=a}}),n0t=ae({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(t,A){var e=So(),i=ar(),o=(s,r,a)=>{const g=r.vertices.length;if(g>3){if(g>4){const l=[0,0,0];r.vertices.forEach(B=>e.add(l,l,B)),e.snap(l,e.divide(l,l,[g,g,g]),s);for(let B=0;B<g;B++){const C=i.create([l,r.vertices[B],r.vertices[(B+1)%g]]);r.color&&(C.color=r.color),a.push(C)}return}const c=i.create([r.vertices[0],r.vertices[1],r.vertices[2]]),I=i.create([r.vertices[0],r.vertices[2],r.vertices[3]]);r.color&&(c.color=r.color,I.color=r.color),a.push(c,I);return}a.push(r)},n=(s,r)=>{const a=[];return r.forEach(g=>{o(s,g,a)}),a};A.exports=n}}),s0t=ae({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(t,A){var e=Yn(),i=yx(),o=Xn(),n=$n(),s=Gg(),r=n6A(),a=i0t(),g=o0t(),c=n0t(),I=(Q,h)=>h,l=(Q,h)=>h,B=(Q,h)=>{const E={snap:!1,simplify:!1,triangulate:!1},{snap:u,simplify:d,triangulate:f}=Object.assign({},E,Q),m=i(h);let D=n.toPolygons(h);u&&(D=r(m,D)),d&&(D=a(m,D)),f&&(D=g(D),D=c(m,D));const w=Object.assign({},h);return w.polygons=D,w},C=(Q,...h)=>{if(h=e(h),h.length===0)throw new Error("wrong number of arguments");const E=h.map(u=>{if(s.isA(u))return I(Q,u);if(o.isA(u))return l(Q,u);if(n.isA(u))return B(Q,u);throw new Error("invalid geometry")});return E.length===1?E[0]:E};A.exports=C}}),r0t=ae({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(t,A){var e=Yn(),i=ms(),o=Xn(),n=$n(),s=Gg(),r=yx(),a=n6A(),g=B=>{const C=r(B),h=s.toPoints(B).map(E=>i.snap(i.create(),E,C));return s.create(h)},c=B=>{const C=r(B);let h=o.toSides(B).map(E=>[i.snap(i.create(),E[0],C),i.snap(i.create(),E[1],C)]);return h=h.filter(E=>!i.equals(E[0],E[1])),o.create(h)},I=B=>{const C=r(B),Q=n.toPolygons(B),h=a(C,Q);return n.create(h)},l=(...B)=>{if(B=e(B),B.length===0)throw new Error("wrong number of arguments");const C=B.map(Q=>s.isA(Q)?g(Q):o.isA(Q)?c(Q):n.isA(Q)?I(Q):Q);return C.length===1?C[0]:C};A.exports=l}}),a0t=ae({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(t,A){A.exports={generalize:s0t(),snap:r0t(),retessellate:SH()}}}),g0t=ae({"node_modules/@jscad/modeling/src/utils/padArrayToLength.js"(t,A){var e=(i,o,n)=>{for(i=i.slice();i.length<n;)i.push(o);return i};A.exports=e}}),c0t=ae({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(t,A){var e=Yn(),i=g0t(),o=XhA(),{translate:n}=oG(),s=c=>{if(!Array.isArray(c.modes)||c.modes.length>3)throw new Error("align(): modes must be an array of length <= 3");if(c.modes=i(c.modes,"none",3),c.modes.filter(I=>["center","max","min","none"].includes(I)).length!==3)throw new Error('align(): all modes must be one of "center", "max" or "min"');if(!Array.isArray(c.relativeTo)||c.relativeTo.length>3)throw new Error("align(): relativeTo must be an array of length <= 3");if(c.relativeTo=i(c.relativeTo,0,3),c.relativeTo.filter(I=>Number.isFinite(I)||I==null).length!==3)throw new Error("align(): all relativeTo values must be a number, or null.");if(typeof c.grouped!="boolean")throw new Error("align(): grouped must be a boolean value.");return c},r=(c,I,l)=>{for(let B=0;B<3;B++)c[B]==null&&(I[B]==="center"?c[B]=(l[0][B]+l[1][B])/2:I[B]==="max"?c[B]=l[1][B]:I[B]==="min"&&(c[B]=l[0][B]));return c},a=(c,I,l)=>{const B=o(c),C=[0,0,0];for(let Q=0;Q<3;Q++)I[Q]==="center"?C[Q]=l[Q]-(B[0][Q]+B[1][Q])/2:I[Q]==="max"?C[Q]=l[Q]-B[1][Q]:I[Q]==="min"&&(C[Q]=l[Q]-B[0][Q]);return n(C,c)},g=(c,...I)=>{c=Object.assign({},{modes:["center","center","min"],relativeTo:[0,0,0],grouped:!1},c),c=s(c);let{modes:B,relativeTo:C,grouped:Q}=c;if(I=e(I),I.length===0)throw new Error("align(): No geometries were provided to act upon");if(C.filter(h=>h==null).length){const h=o(I);C=r(C,B,h)}return Q?I=a(I,B,C):I=I.map(h=>a(h,B,C)),I.length===1?I[0]:I};A.exports=g}}),UW=ae({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(t,A){var e=Yn(),i=Xn(),o=$n(),n=Gg(),s=tG(),{translate:r}=oG(),a=(B,C)=>{const Q={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:h,relativeTo:E}=Object.assign({},Q,B),u=s(C),d=[0,0,0];return h[0]&&(d[0]=E[0]-(u[0][0]+(u[1][0]-u[0][0])/2)),h[1]&&(d[1]=E[1]-(u[0][1]+(u[1][1]-u[0][1])/2)),h[2]&&(d[2]=E[2]-(u[0][2]+(u[1][2]-u[0][2])/2)),r(d,C)},g=(B,...C)=>{const Q={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:h,relativeTo:E}=Object.assign({},Q,B);if(C=e(C),C.length===0)throw new Error("wrong number of arguments");if(E.length!==3)throw new Error("relativeTo must be an array of length 3");B={axes:h,relativeTo:E};const u=C.map(d=>n.isA(d)||i.isA(d)||o.isA(d)?a(B,d):d);return u.length===1?u[0]:u},c=(...B)=>g({axes:[!0,!1,!1]},B),I=(...B)=>g({axes:[!1,!0,!1]},B),l=(...B)=>g({axes:[!1,!1,!0]},B);A.exports={center:g,centerX:c,centerY:I,centerZ:l}}}),HW=ae({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(t,A){var e=Yn(),i=$g(),o=Xn(),n=$n(),s=Gg(),r=(I,...l)=>{if(!Array.isArray(I))throw new Error("factors must be an array");if(l=e(l),l.length===0)throw new Error("wrong number of arguments");for(I=I.slice();I.length<3;)I.push(1);if(I[0]<=0||I[1]<=0||I[2]<=0)throw new Error("factors must be positive");const B=i.fromScaling(i.create(),I),C=l.map(Q=>s.isA(Q)?s.transform(B,Q):o.isA(Q)?o.transform(B,Q):n.isA(Q)?n.transform(B,Q):Q);return C.length===1?C[0]:C},a=(I,...l)=>r([I,1,1],l),g=(I,...l)=>r([1,I,1],l),c=(I,...l)=>r([1,1,I],l);A.exports={scale:r,scaleX:a,scaleY:g,scaleZ:c}}}),I0t=ae({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(t,A){var e=Yn(),i=Xn(),o=$n(),n=Gg(),s=(r,...a)=>{if(a=e(a),a.length===0)throw new Error("wrong number of arguments");const g=a.map(c=>n.isA(c)?n.transform(r,c):i.isA(c)?i.transform(r,c):o.isA(c)?o.transform(r,c):c);return g.length===1?g[0]:g};A.exports=s}}),nG=ae({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(t,A){A.exports={align:c0t(),center:UW().center,centerX:UW().centerX,centerY:UW().centerY,centerZ:UW().centerZ,mirror:mH().mirror,mirrorX:mH().mirrorX,mirrorY:mH().mirrorY,mirrorZ:mH().mirrorZ,rotate:wH().rotate,rotateX:wH().rotateX,rotateY:wH().rotateY,rotateZ:wH().rotateZ,scale:HW().scale,scaleX:HW().scaleX,scaleY:HW().scaleY,scaleZ:HW().scaleZ,transform:I0t(),translate:oG().translate,translateX:oG().translateX,translateY:oG().translateY,translateZ:oG().translateZ}}}),YW=ae({"node_modules/@jscad/modeling/src/index.js"(t,A){A.exports={colors:GW(),curves:rpt(),geometries:WhA(),maths:Gpt(),measurements:Ypt(),primitives:mx(),text:tEA(),utils:jXA(),booleans:sN(),expansions:t6A(),extrusions:bH(),hulls:t0t(),modifiers:a0t(),transforms:nG()}}}),s6A=ae({"node_modules/jscad-planner/dist/index.cjs"(t,A){var e=Object.defineProperty,i=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,s=(l,B)=>{for(var C in B)e(l,C,{get:B[C],enumerable:!0})},r=(l,B,C,Q)=>{if(B&&typeof B=="object"||typeof B=="function")for(let h of o(B))!n.call(l,h)&&h!==C&&e(l,h,{get:()=>B[h],enumerable:!(Q=i(B,h))||Q.enumerable});return l},a=l=>r(e({},"__esModule",{value:!0}),l),g={};s(g,{executeJscadOperations:()=>I,jscadPlanner:()=>c}),A.exports=a(g);var c={booleans:{intersect:(...l)=>({type:"intersect",shapes:l}),subtract:(...l)=>({type:"subtract",shapes:l}),union:(...l)=>({type:"union",shapes:l})},hulls:{hull:(...l)=>({type:"hull",shapes:l.flat()}),hullChain:(...l)=>({type:"hullChain",shapes:l.flat()})},colors:{colorize:(l,B)=>({type:"colorize",color:l,shape:B})},primitives:{cube:l=>({type:"cube",...l}),sphere:l=>({type:"sphere",...l}),cylinder:l=>({type:"cylinder",...l}),polygon:l=>({type:"polygon",...l}),cuboid:l=>({type:"cuboid",...l}),roundedCuboid:l=>({type:"roundedCuboid",...l})},transforms:{rotate:(l,B)=>({type:"rotate",angles:l,shape:B}),scale:(l,B)=>({type:"scale",factors:l,shape:B}),translate:(l,B)=>({type:"translate",vector:l,shape:B})},extrusions:{extrudeLinear:(l,B)=>({type:"extrudeLinear",options:l,shape:B}),extrudeRotate:(l,B)=>({type:"extrudeRotate",options:l,shape:B})},maths:{vec2:{create:(l,B)=>[l,B],fromValues:(l,B)=>[l,B]},vec3:{create:(l,B,C)=>[l,B,C],fromValues:(l,B,C)=>[l,B,C]}},geometries:{geom2:{create:l=>({type:"createGeom2",points:l})},geom3:{create:l=>({type:"createGeom3",polygons:l})},path2:{create:l=>({type:"createPath2",points:l})}},measurements:{measureBoundingBox:l=>({type:"measureBoundingBox",shape:l}),measureArea:l=>({type:"measureArea",shape:l}),measureVolume:l=>({type:"measureVolume",shape:l})},utils:{degToRad:l=>l*Math.PI/180,radToDeg:l=>l*180/Math.PI}},I=(l,B)=>{if(Array.isArray(B)&&B.length===1)return I(l,B[0]);if(Array.isArray(B))throw new Error("executeJscadOperations currently doesn't support Array<JscadOperation>, try adding a root union or or executing each element individually");const C=E=>I(l,E),{type:Q,...h}=B;switch(Q){case"intersect":return l.booleans.intersect(...B.shapes.map(C));case"subtract":return l.booleans.subtract(...B.shapes.map(C));case"union":return l.booleans.union(...B.shapes.map(C));case"hull":return l.hulls.hull(...B.shapes.map(C));case"hullChain":return l.hulls.hullChain(...B.shapes.map(C));case"colorize":return l.colors.colorize(B.color,C(B.shape));case"cube":return l.primitives.cube(h);case"sphere":return l.primitives.sphere(h);case"cylinder":return l.primitives.cylinder(h);case"polygon":return l.primitives.polygon(h);case"cuboid":return l.primitives.cuboid(h);case"roundedCuboid":return l.primitives.roundedCuboid(h);case"rotate":return l.transforms.rotate(B.angles,C(B.shape));case"scale":return l.transforms.scale(B.factors,C(B.shape));case"translate":return l.transforms.translate(B.vector,C(B.shape));case"extrudeLinear":return l.extrusions.extrudeLinear(B.options,C(B.shape));case"extrudeRotate":return l.extrusions.extrudeRotate(B.options,C(B.shape));case"createGeom2":return l.geometries.geom2.create(B.points);case"createGeom3":return l.geometries.geom3.create(B.polygons);case"createPath2":return l.geometries.path2.create(B.points);case"measureBoundingBox":return l.measurements.measureBoundingBox(C(B.shape));case"measureArea":return l.measurements.measureArea(C(B.shape));case"measureVolume":return l.measurements.measureVolume(C(B.shape));case"degToRad":return l.utils.degToRad(B.degrees);case"radToDeg":return l.utils.radToDeg(B.radians);default:throw B.type===void 0?new Error(`Operation type is undefined. This usually means the operation object is malformed or not properly initialized. Operation: ${JSON.stringify(B,null,2).slice(0,200)}...`):new Error(`Unsupported operation type: ${B.type}. Operation: ${JSON.stringify(B,null,2)}`)}}}}),l0t=ae({"node_modules/ms/index.js"(t,A){var e=1e3,i=e*60,o=i*60,n=o*24,s=n*7,r=n*365.25;A.exports=function(l,B){B=B||{};var C=typeof l;if(C==="string"&&l.length>0)return a(l);if(C==="number"&&isFinite(l))return B.long?c(l):g(l);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(l))};function a(l){if(l=String(l),!(l.length>100)){var B=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(l);if(B){var C=parseFloat(B[1]),Q=(B[2]||"ms").toLowerCase();switch(Q){case"years":case"year":case"yrs":case"yr":case"y":return C*r;case"weeks":case"week":case"w":return C*s;case"days":case"day":case"d":return C*n;case"hours":case"hour":case"hrs":case"hr":case"h":return C*o;case"minutes":case"minute":case"mins":case"min":case"m":return C*i;case"seconds":case"second":case"secs":case"sec":case"s":return C*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return C;default:return}}}}function g(l){var B=Math.abs(l);return B>=n?Math.round(l/n)+"d":B>=o?Math.round(l/o)+"h":B>=i?Math.round(l/i)+"m":B>=e?Math.round(l/e)+"s":l+"ms"}function c(l){var B=Math.abs(l);return B>=n?I(l,B,n,"day"):B>=o?I(l,B,o,"hour"):B>=i?I(l,B,i,"minute"):B>=e?I(l,B,e,"second"):l+" ms"}function I(l,B,C,Q){var h=B>=C*1.5;return Math.round(l/C)+" "+Q+(h?"s":"")}}}),B0t=ae({"node_modules/debug/src/common.js"(t,A){function e(i){n.debug=n,n.default=n,n.coerce=I,n.disable=g,n.enable=r,n.enabled=c,n.humanize=l0t(),n.destroy=l,Object.keys(i).forEach(B=>{n[B]=i[B]}),n.names=[],n.skips=[],n.formatters={};function o(B){let C=0;for(let Q=0;Q<B.length;Q++)C=(C<<5)-C+B.charCodeAt(Q),C|=0;return n.colors[Math.abs(C)%n.colors.length]}n.selectColor=o;function n(B){let C,Q=null,h,E;function u(...d){if(!u.enabled)return;const f=u,m=Number(new Date),D=m-(C||m);f.diff=D,f.prev=C,f.curr=m,C=m,d[0]=n.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let w=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(k,_)=>{if(k==="%%")return"%";w++;const M=n.formatters[_];if(typeof M=="function"){const v=d[w];k=M.call(f,v),d.splice(w,1),w--}return k}),n.formatArgs.call(f,d),(f.log||n.log).apply(f,d)}return u.namespace=B,u.useColors=n.useColors(),u.color=n.selectColor(B),u.extend=s,u.destroy=n.destroy,Object.defineProperty(u,"enabled",{enumerable:!0,configurable:!1,get:()=>Q!==null?Q:(h!==n.namespaces&&(h=n.namespaces,E=n.enabled(B)),E),set:d=>{Q=d}}),typeof n.init=="function"&&n.init(u),u}function s(B,C){const Q=n(this.namespace+(typeof C>"u"?":":C)+B);return Q.log=this.log,Q}function r(B){n.save(B),n.namespaces=B,n.names=[],n.skips=[];const C=(typeof B=="string"?B:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const Q of C)Q[0]==="-"?n.skips.push(Q.slice(1)):n.names.push(Q)}function a(B,C){let Q=0,h=0,E=-1,u=0;for(;Q<B.length;)if(h<C.length&&(C[h]===B[Q]||C[h]==="*"))C[h]==="*"?(E=h,u=Q,h++):(Q++,h++);else if(E!==-1)h=E+1,u++,Q=u;else return!1;for(;h<C.length&&C[h]==="*";)h++;return h===C.length}function g(){const B=[...n.names,...n.skips.map(C=>"-"+C)].join(",");return n.enable(""),B}function c(B){for(const C of n.skips)if(a(B,C))return!1;for(const C of n.names)if(a(B,C))return!0;return!1}function I(B){return B instanceof Error?B.stack||B.message:B}function l(){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 n.enable(n.load()),n}A.exports=e}}),C0t=ae({"node_modules/debug/src/browser.js"(t,A){t.formatArgs=i,t.save=o,t.load=n,t.useColors=e,t.storage=s(),t.destroy=(()=>{let a=!1;return()=>{a||(a=!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`."))}})(),t.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 e(){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 a;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&&(a=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(a[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function i(a){if(a[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+a[0]+(this.useColors?"%c ":" ")+"+"+A.exports.humanize(this.diff),!this.useColors)return;const g="color: "+this.color;a.splice(1,0,g,"color: inherit");let c=0,I=0;a[0].replace(/%[a-zA-Z%]/g,l=>{l!=="%%"&&(c++,l==="%c"&&(I=c))}),a.splice(I,0,g)}t.log=console.debug||console.log||(()=>{});function o(a){try{a?t.storage.setItem("debug",a):t.storage.removeItem("debug")}catch{}}function n(){let a;try{a=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch{}return!a&&typeof UhA<"u"&&"env"in UhA&&(a=UhA.env.DEBUG),a}function s(){try{return localStorage}catch{}}A.exports=B0t()(t);var{formatters:r}=A.exports;r.j=function(a){try{return JSON.stringify(a)}catch(g){return"[UnexpectedJSONParseError]: "+g.message}}}}),r6A={boardBody:!0,topCopper:!0,bottomCopper:!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,backgroundStart:!0,backgroundEnd:!0},a6A=V.createContext(void 0),Q0t=({children:t})=>{const[A,e]=V.useState(r6A),i=V.useCallback((s,r)=>{e(a=>({...a,[s]:r}))},[]),o=V.useCallback(()=>{e(r6A)},[]),n=V.useMemo(()=>({visibility:A,setLayerVisibility:i,resetToDefaults:o}),[A,i,o]);return W.jsx(a6A.Provider,{value:n,children:t})},rN=()=>{const t=V.useContext(a6A);if(!t)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return t},IEA=1.2;function g6A(t){return V.useMemo(()=>{if(!t)return IEA;try{return _i(t).pcb_board.list()[0]?.thickness??IEA}catch{return IEA}},[t])}var c6A=V.createContext(null),Ou=()=>{const t=V.useContext(c6A);if(!t)throw new Error("useThree must be used within a ThreeProvider");return t},_H=(t,A=[])=>{const{addFrameListener:e,removeFrameListener:i}=Ou();no.useEffect(()=>(e(t),()=>i(t)),[e,i,...A])},xH={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:90,appearanceMenu:91},I6A=({children:t,position:A,style:e})=>{const{camera:i,renderer:o}=Ou(),n=V.useRef(document.createElement("div")),[s,r]=V.useState(null);return V.useEffect(()=>{const a=o?.domElement.parentNode;if(a)return a.style.position!=="relative"&&a.style.position!=="absolute"&&(a.style.position="relative"),a.appendChild(n.current),r(h5.createPortal(t,n.current)),()=>{a.contains(n.current)&&a.removeChild(n.current)}},[o,t]),_H(()=>{if(!i||!n.current||!o)return;const a=new Re(...A);a.project(i);const g=o.domElement.getBoundingClientRect(),c=Math.round((a.x+1)/2*g.width),I=Math.round((-a.y+1)/2*g.height);n.current.style.position="absolute",n.current.style.left=`${c}px`,n.current.style.top=`${I}px`,n.current.style.pointerEvents="none",n.current.style.zIndex=xH.htmlElements.toString(),e&&Object.assign(n.current.style,e)},[i,o,A,e]),s},l6A={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},vr=t=>{let A=typeof t=="number"?"mm":t.replace(/^[^a-zA-Z]+/g,"").toLowerCase();A||(A="mm");const e=typeof t=="number"?t:Number.parseFloat(t.split(A)[0]);if(A in l6A)return e*l6A[A];throw new Error(`Unsupported unit: ${A}`)},Rl=vr,B6A={Hz:{baseUnit:"Hz",variants:{MHz:1e6,kHz:1e3,Hz:1}},g:{baseUnit:"g",variants:{kg:1e3,g:1}},Ω:{baseUnit:"Ω",variants:{mΩ:.001,Ω:1,kΩ:1e3,KΩ:1e3,kohm:1e3,MΩ:1e6,GΩ:1e9,TΩ:1e12}},V:{baseUnit:"V",variants:{mV:.001,V:1,kV:1e3,KV:1e3,MV:1e6,GV:1e9,TV:1e12}},A:{baseUnit:"A",variants:{µA:1e-6,mA:.001,ma:.001,A:1,kA:1e3,MA:1e6}},F:{baseUnit:"F",variants:{pF:1e-12,nF:1e-9,µF:1e-6,uF:1e-6,mF:.001,F:1}},ml:{baseUnit:"ml",variants:{ml:1,mL:1,l:1e3,L:1e3}},deg:{baseUnit:"deg",variants:{rad:180/Math.PI}},ms:{baseUnit:"ms",variants:{fs:1e-12,ps:1e-9,ns:1e-6,us:.001,µs:.001,ms:1,s:1e3}},mm:{baseUnit:"mm",variants:{nm:1e-6,µm:.001,um:.001,mm:1,cm:10,dm:100,m:1e3,km:1e6,in:25.4,ft:304.8,IN:25.4,FT:304.8,yd:914.4,mi:1609344,mil:.0254}}},lEA=new Set;for(const[t,A]of Object.entries(B6A)){lEA.add(t);for(const e of Object.keys(A.variants))lEA.add(e)}function h0t(t){for(const[A,e]of Object.entries(B6A))if(t in e.variants)return{baseUnit:e.baseUnit,conversionFactor:e.variants[t]};return{baseUnit:t,conversionFactor:1}}var C6A={tera:1e12,T:1e12,giga:1e9,G:1e9,mega:1e6,M:1e6,kilo:1e3,k:1e3,deci:.1,d:.1,centi:.01,c:.01,milli:.001,m:.001,micro:1e-6,u:1e-6,µ:1e-6,nano:1e-9,n:1e-9,pico:1e-12,p:1e-12};function sw(t){if(t==null)return{parsedUnit:null,unitOfValue:null,value:null};if(typeof t=="string"&&t.match(/^-?[\d\.]+$/))return{value:Number.parseFloat(t),parsedUnit:null,unitOfValue:null};if(typeof t=="number")return{value:t,parsedUnit:null,unitOfValue:null};if(typeof t=="object"&&"x"in t&&"y"in t){const{parsedUnit:r,unitOfValue:a}=sw(t.x),g=sw(t.x),c=sw(t.y);return g.value===null||c.value===null?{parsedUnit:null,unitOfValue:null,value:null}:{parsedUnit:r,unitOfValue:a,value:{x:g.value,y:c.value}}}const e=t.toString().split("").reverse().join("").match(/[^\d\s]+/)?.[0];if(!e)throw new Error(`Could not determine unit: "${t}"`);const i=e.split("").reverse().join(""),o=t.slice(0,-i.length);if(i in C6A&&!lEA.has(i)){const r=C6A[i];return{parsedUnit:null,unitOfValue:null,value:Number.parseFloat(o)*r}}const{baseUnit:n,conversionFactor:s}=h0t(i);return{parsedUnit:i,unitOfValue:n,value:s*Number.parseFloat(o)}}var BEA=N().or(vA()).transform(t=>sw(t).value),Q6A=N().or(vA()).transform(t=>sw(t).value).transform(t=>Number.parseFloat(t.toPrecision(12))),E0t=N().or(vA()).transform(t=>sw(t).value),aN=N().or(vA()).transform(t=>sw(t).value),ee=N().or(vA()).transform(t=>sw(t).value),JW=N().or(vA()).transform(t=>sw(t).value),bt=ee,CEA=N().or(vA()).transform(t=>sw(t).value),QEA=N().or(vA()).transform(t=>sw(t).value),gN=QEA,u0t=N().datetime(),qd=N().or(vA()).transform(t=>typeof t=="number"?t:t.endsWith("deg")?Number.parseFloat(t.split("deg")[0]):t.endsWith("rad")?Number.parseFloat(t.split("rad")[0])*180/Math.PI:Number.parseFloat(t)),d0t=vA().or(N().endsWith("mAh")).transform(t=>{if(typeof t=="string"){const A=t.replace("mAh",""),e=Number.parseFloat(A);if(Number.isNaN(e))throw new Error("Invalid capacity");return e}return t}).describe("Battery capacity in mAh"),Lo=RA({x:bt,y:bt}),hEA=RA({x:bt,y:bt,z:bt}),h6A=RA({width:vA(),height:vA()}),p0t=t=>{const A="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";return Array.from({length:t},()=>A[Math.floor(Math.random()*A.length)]).join("")},Ai=t=>N().optional().default(()=>`${t}_${p0t(10)}`),sG=Te(["top_left","top_center","top_right","center_left","center","center_right","bottom_left","bottom_center","bottom_right"]);Te(["top_silkscreen","bottom_silkscreen","top_copper","bottom_copper","top_soldermask","bottom_soldermask","top_fabrication_note","bottom_fabrication_note","inner1_copper","inner2_copper","inner3_copper","inner4_copper","inner5_copper","inner6_copper"]);var f0t=Te(["jlcpcb","macrofab","pcbway","digikey","mouser","lcsc"]),vl=RA({type:CA("source_component"),ftype:N().optional(),source_component_id:N(),name:N(),manufacturer_part_number:N().optional(),supplier_part_numbers:qr(f0t,de(N())).optional(),display_value:N().optional(),are_pins_interchangeable:$A().optional(),internally_connected_source_port_ids:de(de(N())).optional(),source_group_id:N().optional(),subcircuit_id:N().optional()}),E6A=vl.extend({ftype:CA("simple_capacitor"),capacitance:Q6A,max_voltage_rating:aN.optional(),display_capacitance:N().optional(),max_decoupling_trace_length:bt.optional()}),u6A=vl.extend({ftype:CA("simple_resistor"),resistance:BEA,display_resistance:N().optional()}),EEA=vl.extend({ftype:CA("simple_diode")}),y0t=vl.extend({ftype:CA("simple_fiducial")}),d6A=EEA.extend({ftype:CA("simple_led"),color:N().optional(),wavelength:N().optional()}),m0t=vl.extend({ftype:CA("simple_ground")}),p6A=vl.extend({ftype:CA("simple_chip")}),f6A=vl.extend({ftype:CA("simple_power_source"),voltage:aN}),w0t=vl.extend({ftype:CA("simple_fuse"),current_rating_amps:vA().describe("Nominal current in amps the fuse is rated for"),voltage_rating_volts:vA().describe("Voltage rating in volts, e.g. ±5V would be 5")}),y6A=vl.extend({ftype:CA("simple_battery"),capacity:d0t}),m6A=vl.extend({ftype:CA("simple_inductor"),inductance:E0t,max_current_rating:vA().optional()}),w6A=vl.extend({ftype:CA("simple_push_button")}),D6A=vl.extend({ftype:CA("simple_potentiometer"),max_resistance:BEA}),D0t=vl.extend({ftype:CA("simple_crystal"),frequency:vA().describe("Frequency in Hz"),load_capacitance:vA().optional().describe("Load capacitance in pF")}),S6A=vl.extend({ftype:CA("simple_pin_header"),pin_count:vA(),gender:Te(["male","female"]).optional().default("male")}),b6A=vl.extend({ftype:CA("simple_pinout")}),_6A=vl.extend({ftype:CA("simple_resonator"),load_capacitance:Q6A,equivalent_series_resistance:BEA.optional(),frequency:JW}),x6A=vl.extend({ftype:CA("simple_transistor"),transistor_type:Te(["npn","pnp"])}),k6A=vl.extend({ftype:CA("simple_test_point"),footprint_variant:Te(["pad","through_hole"]).optional(),pad_shape:Te(["rect","circle"]).optional(),pad_diameter:Ht([vA(),N()]).optional(),hole_diameter:Ht([vA(),N()]).optional(),width:Ht([vA(),N()]).optional(),height:Ht([vA(),N()]).optional()}),F6A=vl.extend({ftype:CA("simple_mosfet"),channel_type:Te(["n","p"]),mosfet_mode:Te(["enhancement","depletion"])}),G6A=vl.extend({ftype:CA("simple_op_amp")}),R6A=vl.extend({ftype:CA("simple_switch")}),v6A=RA({type:CA("source_project_metadata"),name:N().optional(),software_used_string:N().optional(),project_url:N().optional(),created_at:u0t.optional()}),S0t=RA({type:CA("source_missing_property_error"),source_missing_property_error_id:Ai("source_missing_property_error"),source_component_id:N(),property_name:N(),subcircuit_id:N().optional(),error_type:CA("source_missing_property_error").default("source_missing_property_error"),message:N()}).describe("The source code is missing a property"),b0t=RA({type:CA("source_failed_to_create_component_error"),source_failed_to_create_component_error_id:Ai("source_failed_to_create_component_error"),error_type:CA("source_failed_to_create_component_error").default("source_failed_to_create_component_error"),component_name:N().optional(),subcircuit_id:N().optional(),parent_source_component_id:N().optional(),message:N(),pcb_center:RA({x:vA().optional(),y:vA().optional()}).optional(),schematic_center:RA({x:vA().optional(),y:vA().optional()}).optional()}).describe("Error emitted when a component fails to be constructed"),M6A=RA({type:CA("source_trace_not_connected_error"),source_trace_not_connected_error_id:Ai("source_trace_not_connected_error"),error_type:CA("source_trace_not_connected_error").default("source_trace_not_connected_error"),message:N(),subcircuit_id:N().optional(),source_group_id:N().optional(),source_trace_id:N().optional(),connected_source_port_ids:de(N()).optional(),selectors_not_found:de(N()).optional()}).describe("Occurs when a source trace selector does not match any ports"),_0t=RA({type:CA("source_property_ignored_warning"),source_property_ignored_warning_id:Ai("source_property_ignored_warning"),source_component_id:N(),property_name:N(),subcircuit_id:N().optional(),error_type:CA("source_property_ignored_warning").default("source_property_ignored_warning"),message:N()}).describe("The source property was ignored"),N6A=RA({type:CA("source_pin_missing_trace_warning"),source_pin_missing_trace_warning_id:Ai("source_pin_missing_trace_warning"),warning_type:CA("source_pin_missing_trace_warning").default("source_pin_missing_trace_warning"),message:N(),source_component_id:N(),source_port_id:N(),subcircuit_id:N().optional()}).describe("Warning emitted when a source component pin is missing a trace connection"),x0t=vl.extend({ftype:CA("simple_voltage_probe")}),k0t=vl.extend({ftype:CA("interconnect")}),F0t=Ht([u6A,E6A,EEA,y0t,d6A,m0t,p6A,f6A,y6A,m6A,w6A,D6A,D0t,S6A,b6A,_6A,R6A,x6A,k6A,F6A,G6A,w0t,x0t,k0t,v6A,S0t,b0t,M6A,_0t,N6A]),G0t=RA({type:CA("source_port"),pin_number:vA().optional(),port_hints:de(N()).optional(),name:N(),source_port_id:N(),source_component_id:N().optional(),source_group_id:N().optional(),subcircuit_id:N().optional(),subcircuit_connectivity_map_key:N().optional(),must_be_connected:$A().optional()}),R0t=RA({type:CA("source_component_internal_connection"),source_component_internal_connection_id:N(),source_component_id:N(),source_port_ids:de(N()),subcircuit_id:N().optional()}),v0t=RA({type:CA("source_trace"),source_trace_id:N(),connected_source_port_ids:de(N()),connected_source_net_ids:de(N()),subcircuit_id:N().optional(),subcircuit_connectivity_map_key:N().optional(),max_length:vA().optional(),min_trace_thickness:vA().optional(),display_name:N().optional()}),M0t=RA({type:CA("source_group"),source_group_id:N(),subcircuit_id:N().optional(),parent_subcircuit_id:N().optional(),parent_source_group_id:N().optional(),is_subcircuit:$A().optional(),show_as_schematic_box:$A().optional(),name:N().optional(),was_automatically_named:$A().optional()}),N0t=RA({type:CA("source_net"),source_net_id:N(),name:N(),member_source_group_ids:de(N()),is_power:$A().optional(),is_ground:$A().optional(),is_digital_signal:$A().optional(),is_analog_signal:$A().optional(),is_positive_voltage_source:$A().optional(),trace_width:vA().optional(),subcircuit_id:N().optional(),subcircuit_connectivity_map_key:N().optional()}),L0t=RA({type:CA("source_board"),source_board_id:N(),source_group_id:N(),title:N().optional()}).describe("Defines a board in the source domain"),U0t=RA({type:CA("source_pcb_ground_plane"),source_pcb_ground_plane_id:N(),source_group_id:N(),source_net_id:N(),subcircuit_id:N().optional()}).describe("Defines a ground plane in the source domain"),H0t=["top","bottom","inner1","inner2","inner3","inner4","inner5","inner6"],L6A=Te(H0t),Wr=L6A.or(RA({name:L6A})).transform(t=>typeof t=="string"?t:t.name),ED=Te(["top","bottom"]),Y0t=RA({type:CA("source_manually_placed_via"),source_manually_placed_via_id:N(),source_group_id:N(),source_net_id:N(),subcircuit_id:N().optional(),source_trace_id:N().optional()}).describe("Defines a via that is manually placed in the source domain"),J0t=RA({type:CA("source_pin_must_be_connected_error"),source_pin_must_be_connected_error_id:Ai("source_pin_must_be_connected_error"),error_type:CA("source_pin_must_be_connected_error").default("source_pin_must_be_connected_error"),message:N(),source_component_id:N(),source_port_id:N(),subcircuit_id:N().optional()}).describe("Error emitted when a pin with mustBeConnected attribute is not connected to any trace"),T0t=RA({type:CA("unknown_error_finding_part"),unknown_error_finding_part_id:Ai("unknown_error_finding_part"),error_type:CA("unknown_error_finding_part").default("unknown_error_finding_part"),message:N(),source_component_id:N().optional(),subcircuit_id:N().optional()}).describe("Error emitted when an unexpected error occurs while finding a part"),K0t=RA({type:CA("schematic_box"),schematic_component_id:N().optional(),width:bt,height:bt,is_dashed:$A().default(!1),x:bt,y:bt,subcircuit_id:N().optional()}).describe("Draws a box on the schematic"),P0t=RA({type:CA("schematic_path"),schematic_component_id:N(),fill_color:Te(["red","blue"]).optional(),is_filled:$A().optional(),points:de(Lo),subcircuit_id:N().optional()}),q0t=qr(RA({left_margin:ee.optional(),right_margin:ee.optional(),top_margin:ee.optional(),bottom_margin:ee.optional()})),O0t=RA({left_size:vA(),right_size:vA(),top_size:vA().optional(),bottom_size:vA().optional()}),W0t=RA({left_side:RA({pins:de(vA()),direction:Te(["top-to-bottom","bottom-to-top"]).optional()}).optional(),right_side:RA({pins:de(vA()),direction:Te(["top-to-bottom","bottom-to-top"]).optional()}).optional(),top_side:RA({pins:de(vA()),direction:Te(["left-to-right","right-to-left"]).optional()}).optional(),bottom_side:RA({pins:de(vA()),direction:Te(["left-to-right","right-to-left"]).optional()}).optional()}),Z0t=Ht([O0t,W0t]),V0t=RA({type:CA("schematic_component"),size:h6A,center:Lo,source_component_id:N().optional(),schematic_component_id:N(),pin_spacing:ee.optional(),pin_styles:q0t.optional(),box_width:ee.optional(),symbol_name:N().optional(),port_arrangement:Z0t.optional(),port_labels:qr(N()).optional(),symbol_display_value:N().optional(),subcircuit_id:N().optional(),schematic_group_id:N().optional(),is_schematic_group:$A().optional(),source_group_id:N().optional(),is_box_with_pins:$A().optional().default(!0)}),j0t=RA({type:CA("schematic_line"),schematic_line_id:Ai("schematic_line"),schematic_component_id:N(),x1:bt,y1:bt,x2:bt,y2:bt,stroke_width:bt.nullable().optional(),color:N().default("#000000"),is_dashed:$A().default(!1),subcircuit_id:N().optional()}).describe("Draws a styled line on the schematic"),z0t=RA({type:CA("schematic_rect"),schematic_rect_id:Ai("schematic_rect"),schematic_component_id:N(),center:Lo,width:bt,height:bt,rotation:qd.default(0),stroke_width:bt.nullable().optional(),color:N().default("#000000"),is_filled:$A().default(!1),fill_color:N().optional(),is_dashed:$A().default(!1),subcircuit_id:N().optional()}).describe("Draws a styled rectangle on the schematic"),X0t=RA({type:CA("schematic_circle"),schematic_circle_id:Ai("schematic_circle"),schematic_component_id:N(),center:Lo,radius:bt,stroke_width:bt.nullable().optional(),color:N().default("#000000"),is_filled:$A().default(!1),fill_color:N().optional(),is_dashed:$A().default(!1),subcircuit_id:N().optional()}).describe("Draws a styled circle on the schematic"),$0t=RA({type:CA("schematic_arc"),schematic_arc_id:Ai("schematic_arc"),schematic_component_id:N(),center:Lo,radius:bt,start_angle_degrees:qd,end_angle_degrees:qd,direction:Te(["clockwise","counterclockwise"]).default("counterclockwise"),stroke_width:bt.nullable().optional(),color:N().default("#000000"),is_dashed:$A().default(!1),subcircuit_id:N().optional()}).describe("Draws a styled arc on the schematic"),Ayt=RA({type:CA("schematic_trace"),schematic_trace_id:N(),source_trace_id:N().optional(),junctions:de(RA({x:vA(),y:vA()})),edges:de(RA({from:RA({x:vA(),y:vA()}),to:RA({x:vA(),y:vA()}),is_crossing:$A().optional(),from_schematic_port_id:N().optional(),to_schematic_port_id:N().optional()})),subcircuit_id:N().optional(),subcircuit_connectivity_map_key:N().optional()}),eyt=Te(["center","left","right","top","bottom"]),tyt=RA({type:CA("schematic_text"),schematic_component_id:N().optional(),schematic_text_id:N(),text:N(),font_size:vA().default(.18),position:RA({x:bt,y:bt}),rotation:vA().default(0),anchor:Ht([eyt.describe("legacy"),sG]).default("center"),color:N().default("#000000"),subcircuit_id:N().optional()}),iyt=RA({type:CA("schematic_port"),schematic_port_id:N(),source_port_id:N(),schematic_component_id:N().optional(),center:Lo,facing_direction:Te(["up","down","left","right"]).optional(),distance_from_component_edge:vA().optional(),side_of_component:Te(["top","bottom","left","right"]).optional(),true_ccw_index:vA().optional(),pin_number:vA().optional(),display_pin_label:N().optional(),subcircuit_id:N().optional(),is_connected:$A().optional(),has_input_arrow:$A().optional(),has_output_arrow:$A().optional()}).describe("Defines a port on a schematic component"),oyt=RA({type:CA("schematic_net_label"),schematic_net_label_id:Ai("schematic_net_label"),schematic_trace_id:N().optional(),source_trace_id:N().optional(),source_net_id:N(),center:Lo,anchor_position:Lo.optional(),anchor_side:Te(["top","bottom","left","right"]),text:N(),symbol_name:N().optional(),is_movable:$A().optional(),subcircuit_id:N().optional()}),nyt=RA({type:CA("schematic_error"),schematic_error_id:N(),error_type:CA("schematic_port_not_found").default("schematic_port_not_found"),message:N(),subcircuit_id:N().optional()}).describe("Defines a schematic error on the schematic"),syt=RA({type:CA("schematic_layout_error"),schematic_layout_error_id:Ai("schematic_layout_error"),error_type:CA("schematic_layout_error").default("schematic_layout_error"),message:N(),source_group_id:N(),schematic_group_id:N(),subcircuit_id:N().optional()}).describe("Error emitted when schematic layout fails for a group"),uEA=RA({type:CA("schematic_debug_object"),label:N().optional(),subcircuit_id:N().optional()}),ryt=uEA.extend({shape:CA("rect"),center:Lo,size:h6A}),ayt=uEA.extend({shape:CA("line"),start:Lo,end:Lo}),gyt=uEA.extend({shape:CA("point"),center:Lo}),cyt=fh("shape",[ryt,ayt,gyt]),Iyt=RA({type:CA("schematic_voltage_probe"),schematic_voltage_probe_id:N(),source_component_id:N().optional(),name:N().optional(),position:Lo,schematic_trace_id:N(),voltage:aN.optional(),subcircuit_id:N().optional(),color:N().optional(),label_alignment:sG.optional()}).describe("Defines a voltage probe measurement point on a schematic trace"),lyt=RA({type:CA("schematic_manual_edit_conflict_warning"),schematic_manual_edit_conflict_warning_id:Ai("schematic_manual_edit_conflict_warning"),warning_type:CA("schematic_manual_edit_conflict_warning").default("schematic_manual_edit_conflict_warning"),message:N(),schematic_component_id:N(),schematic_group_id:N().optional(),subcircuit_id:N().optional(),source_component_id:N()}).describe("Warning emitted when a component has both manual placement and explicit schX/schY coordinates"),Byt=RA({type:CA("schematic_group"),schematic_group_id:Ai("schematic_group"),source_group_id:N(),is_subcircuit:$A().optional(),subcircuit_id:N().optional(),width:ee,height:ee,center:Lo,schematic_component_ids:de(N()),show_as_schematic_box:$A().optional(),name:N().optional(),description:N().optional()}).describe("Defines a group of components on the schematic"),Cyt=RA({type:CA("schematic_table"),schematic_table_id:Ai("schematic_table"),anchor_position:Lo,column_widths:de(bt),row_heights:de(bt),cell_padding:bt.optional(),border_width:bt.optional(),subcircuit_id:N().optional(),schematic_component_id:N().optional(),anchor:sG.optional()}).describe("Defines a table on the schematic"),Qyt=RA({type:CA("schematic_table_cell"),schematic_table_cell_id:Ai("schematic_table_cell"),schematic_table_id:N(),start_row_index:vA(),end_row_index:vA(),start_column_index:vA(),end_column_index:vA(),text:N().optional(),center:Lo,width:bt,height:bt,horizontal_align:Te(["left","center","right"]).optional(),vertical_align:Te(["top","middle","bottom"]).optional(),font_size:bt.optional(),subcircuit_id:N().optional()}).describe("Defines a cell within a schematic_table"),hyt=RA({type:CA("schematic_sheet"),schematic_sheet_id:Ai("schematic_sheet"),name:N().optional(),subcircuit_id:N().optional()}).describe("Defines a schematic sheet or page that components can be placed on"),Eyt=RA({x:bt,y:bt,bulge:vA().optional()}),U6A=RA({vertices:de(Eyt)}),uyt=RA({outer_ring:U6A,inner_rings:de(U6A).default([])}),dyt=RA({x:bt,y:bt,via:$A().optional(),via_to_layer:Wr.optional()});de(dyt);var pyt=RA({x:bt,y:bt,via:$A().optional(),to_layer:Wr.optional(),trace_width:bt.optional()}),fyt=RA({type:CA("pcb_component"),pcb_component_id:Ai("pcb_component"),source_component_id:N(),center:Lo,layer:Wr,rotation:qd,display_offset_x:N().optional().describe("How to display the x offset for this part, usually corresponding with how the user specified it"),display_offset_y:N().optional().describe("How to display the y offset for this part, usually corresponding with how the user specified it"),width:ee,height:ee,do_not_place:$A().optional(),subcircuit_id:N().optional(),pcb_group_id:N().optional(),position_mode:Te(["packed","relative_to_group_anchor","none"]).optional(),positioned_relative_to_pcb_group_id:N().optional(),positioned_relative_to_pcb_board_id:N().optional(),obstructs_within_bounds:$A().default(!0).describe("Does this component take up all the space within its bounds on a layer. This is generally true except for when separated pin headers are being represented by a single component (in which case, chips can be placed between the pin headers) or for tall modules where chips fit underneath")}).describe("Defines a component on the PCB"),H6A=RA({type:CA("pcb_hole"),pcb_hole_id:Ai("pcb_hole"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),pcb_component_id:N().optional(),hole_shape:CA("circle"),hole_diameter:vA(),x:bt,y:bt,is_covered_with_solder_mask:$A().optional(),soldermask_margin:vA().optional()});H6A.describe("Defines a circular hole on the PCB");var Y6A=RA({type:CA("pcb_hole"),pcb_hole_id:Ai("pcb_hole"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),pcb_component_id:N().optional(),hole_shape:CA("rect"),hole_width:vA(),hole_height:vA(),x:bt,y:bt,is_covered_with_solder_mask:$A().optional(),soldermask_margin:vA().optional()});Y6A.describe("Defines a rectangular (square-capable) hole on the PCB. Use equal width/height for square.");var J6A=RA({type:CA("pcb_hole"),pcb_hole_id:Ai("pcb_hole"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),pcb_component_id:N().optional(),hole_shape:Te(["circle","square"]),hole_diameter:vA(),x:bt,y:bt,is_covered_with_solder_mask:$A().optional(),soldermask_margin:vA().optional()});J6A.describe("Defines a circular or square hole on the PCB");var T6A=RA({type:CA("pcb_hole"),pcb_hole_id:Ai("pcb_hole"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),pcb_component_id:N().optional(),hole_shape:CA("oval"),hole_width:vA(),hole_height:vA(),x:bt,y:bt,is_covered_with_solder_mask:$A().optional(),soldermask_margin:vA().optional()});T6A.describe("Defines an oval hole on the PCB");var K6A=RA({type:CA("pcb_hole"),pcb_hole_id:Ai("pcb_hole"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),pcb_component_id:N().optional(),hole_shape:CA("pill"),hole_width:vA(),hole_height:vA(),x:bt,y:bt,is_covered_with_solder_mask:$A().optional(),soldermask_margin:vA().optional()});K6A.describe("Defines a pill-shaped hole on the PCB");var P6A=RA({type:CA("pcb_hole"),pcb_hole_id:Ai("pcb_hole"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),pcb_component_id:N().optional(),hole_shape:CA("rotated_pill"),hole_width:vA(),hole_height:vA(),x:bt,y:bt,ccw_rotation:qd,is_covered_with_solder_mask:$A().optional(),soldermask_margin:vA().optional()});P6A.describe("Defines a rotated pill-shaped hole on the PCB");var yyt=J6A.or(T6A).or(K6A).or(P6A).or(H6A).or(Y6A),myt=RA({type:CA("pcb_plated_hole"),shape:CA("circle"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),outer_diameter:vA(),hole_diameter:vA(),is_covered_with_solder_mask:$A().optional(),x:bt,y:bt,layers:de(Wr),port_hints:de(N()).optional(),pcb_component_id:N().optional(),pcb_port_id:N().optional(),pcb_plated_hole_id:Ai("pcb_plated_hole"),soldermask_margin:vA().optional()}),wyt=RA({type:CA("pcb_plated_hole"),shape:Te(["oval","pill"]),pcb_group_id:N().optional(),subcircuit_id:N().optional(),outer_width:vA(),outer_height:vA(),hole_width:vA(),hole_height:vA(),is_covered_with_solder_mask:$A().optional(),x:bt,y:bt,ccw_rotation:qd,layers:de(Wr),port_hints:de(N()).optional(),pcb_component_id:N().optional(),pcb_port_id:N().optional(),pcb_plated_hole_id:Ai("pcb_plated_hole"),soldermask_margin:vA().optional()}),Dyt=RA({type:CA("pcb_plated_hole"),shape:CA("circular_hole_with_rect_pad"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),hole_shape:CA("circle"),pad_shape:CA("rect"),hole_diameter:vA(),rect_pad_width:vA(),rect_pad_height:vA(),rect_border_radius:vA().optional(),hole_offset_x:bt.default(0),hole_offset_y:bt.default(0),is_covered_with_solder_mask:$A().optional(),x:bt,y:bt,layers:de(Wr),port_hints:de(N()).optional(),pcb_component_id:N().optional(),pcb_port_id:N().optional(),pcb_plated_hole_id:Ai("pcb_plated_hole"),soldermask_margin:vA().optional()}),Syt=RA({type:CA("pcb_plated_hole"),shape:CA("pill_hole_with_rect_pad"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),hole_shape:CA("pill"),pad_shape:CA("rect"),hole_width:vA(),hole_height:vA(),rect_pad_width:vA(),rect_pad_height:vA(),rect_border_radius:vA().optional(),hole_offset_x:bt.default(0),hole_offset_y:bt.default(0),is_covered_with_solder_mask:$A().optional(),x:bt,y:bt,layers:de(Wr),port_hints:de(N()).optional(),pcb_component_id:N().optional(),pcb_port_id:N().optional(),pcb_plated_hole_id:Ai("pcb_plated_hole"),soldermask_margin:vA().optional()}),byt=RA({type:CA("pcb_plated_hole"),shape:CA("rotated_pill_hole_with_rect_pad"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),hole_shape:CA("rotated_pill"),pad_shape:CA("rect"),hole_width:vA(),hole_height:vA(),hole_ccw_rotation:qd,rect_pad_width:vA(),rect_pad_height:vA(),rect_border_radius:vA().optional(),rect_ccw_rotation:qd,hole_offset_x:bt.default(0),hole_offset_y:bt.default(0),is_covered_with_solder_mask:$A().optional(),x:bt,y:bt,layers:de(Wr),port_hints:de(N()).optional(),pcb_component_id:N().optional(),pcb_port_id:N().optional(),pcb_plated_hole_id:Ai("pcb_plated_hole"),soldermask_margin:vA().optional()}),_yt=RA({type:CA("pcb_plated_hole"),shape:CA("hole_with_polygon_pad"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),hole_shape:Te(["circle","oval","pill","rotated_pill"]),hole_diameter:vA().optional(),hole_width:vA().optional(),hole_height:vA().optional(),pad_outline:de(RA({x:bt,y:bt})).min(3),hole_offset_x:bt.default(0),hole_offset_y:bt.default(0),is_covered_with_solder_mask:$A().optional(),x:bt,y:bt,layers:de(Wr),port_hints:de(N()).optional(),pcb_component_id:N().optional(),pcb_port_id:N().optional(),pcb_plated_hole_id:Ai("pcb_plated_hole"),soldermask_margin:vA().optional()}),xyt=Ht([myt,wyt,Dyt,Syt,byt,_yt]),kyt=RA({type:CA("pcb_port"),pcb_port_id:Ai("pcb_port"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),source_port_id:N(),pcb_component_id:N().optional(),x:bt,y:bt,layers:de(Wr),is_board_pinout:$A().optional()}).describe("Defines a port on the PCB"),Fyt=RA({type:CA("pcb_smtpad"),shape:CA("circle"),pcb_smtpad_id:Ai("pcb_smtpad"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),x:bt,y:bt,radius:vA(),layer:Wr,port_hints:de(N()).optional(),pcb_component_id:N().optional(),pcb_port_id:N().optional(),is_covered_with_solder_mask:$A().optional(),soldermask_margin:vA().optional()}),Gyt=RA({type:CA("pcb_smtpad"),shape:CA("rect"),pcb_smtpad_id:Ai("pcb_smtpad"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),x:bt,y:bt,width:vA(),height:vA(),rect_border_radius:vA().optional(),corner_radius:vA().optional(),layer:Wr,port_hints:de(N()).optional(),pcb_component_id:N().optional(),pcb_port_id:N().optional(),is_covered_with_solder_mask:$A().optional(),soldermask_margin:vA().optional()}),Ryt=RA({type:CA("pcb_smtpad"),shape:CA("rotated_rect"),pcb_smtpad_id:Ai("pcb_smtpad"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),x:bt,y:bt,width:vA(),height:vA(),rect_border_radius:vA().optional(),corner_radius:vA().optional(),ccw_rotation:qd,layer:Wr,port_hints:de(N()).optional(),pcb_component_id:N().optional(),pcb_port_id:N().optional(),is_covered_with_solder_mask:$A().optional(),soldermask_margin:vA().optional()}),vyt=RA({type:CA("pcb_smtpad"),shape:CA("pill"),pcb_smtpad_id:Ai("pcb_smtpad"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),x:bt,y:bt,width:vA(),height:vA(),radius:vA(),layer:Wr,port_hints:de(N()).optional(),pcb_component_id:N().optional(),pcb_port_id:N().optional(),is_covered_with_solder_mask:$A().optional(),soldermask_margin:vA().optional()}),Myt=RA({type:CA("pcb_smtpad"),shape:CA("rotated_pill"),pcb_smtpad_id:Ai("pcb_smtpad"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),x:bt,y:bt,width:vA(),height:vA(),radius:vA(),ccw_rotation:qd,layer:Wr,port_hints:de(N()).optional(),pcb_component_id:N().optional(),pcb_port_id:N().optional(),is_covered_with_solder_mask:$A().optional(),soldermask_margin:vA().optional()}),Nyt=RA({type:CA("pcb_smtpad"),shape:CA("polygon"),pcb_smtpad_id:Ai("pcb_smtpad"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),points:de(Lo),layer:Wr,port_hints:de(N()).optional(),pcb_component_id:N().optional(),pcb_port_id:N().optional(),is_covered_with_solder_mask:$A().optional(),soldermask_margin:vA().optional()}),Lyt=fh("shape",[Fyt,Gyt,Ryt,Myt,vyt,Nyt]).describe("Defines an SMT pad on the PCB"),Uyt=RA({type:CA("pcb_solder_paste"),shape:CA("circle"),pcb_solder_paste_id:Ai("pcb_solder_paste"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),x:bt,y:bt,radius:vA(),layer:Wr,pcb_component_id:N().optional(),pcb_smtpad_id:N().optional()}),Hyt=RA({type:CA("pcb_solder_paste"),shape:CA("rect"),pcb_solder_paste_id:Ai("pcb_solder_paste"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),x:bt,y:bt,width:vA(),height:vA(),layer:Wr,pcb_component_id:N().optional(),pcb_smtpad_id:N().optional()}),Yyt=RA({type:CA("pcb_solder_paste"),shape:CA("pill"),pcb_solder_paste_id:Ai("pcb_solder_paste"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),x:bt,y:bt,width:vA(),height:vA(),radius:vA(),layer:Wr,pcb_component_id:N().optional(),pcb_smtpad_id:N().optional()}),Jyt=RA({type:CA("pcb_solder_paste"),shape:CA("rotated_rect"),pcb_solder_paste_id:Ai("pcb_solder_paste"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),x:bt,y:bt,width:vA(),height:vA(),ccw_rotation:bt,layer:Wr,pcb_component_id:N().optional(),pcb_smtpad_id:N().optional()}),Tyt=RA({type:CA("pcb_solder_paste"),shape:CA("oval"),pcb_solder_paste_id:Ai("pcb_solder_paste"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),x:bt,y:bt,width:vA(),height:vA(),layer:Wr,pcb_component_id:N().optional(),pcb_smtpad_id:N().optional()}),Kyt=Ht([Uyt,Hyt,Yyt,Jyt,Tyt]).describe("Defines solderpaste on the PCB"),Pyt=RA({type:CA("pcb_text"),pcb_text_id:Ai("pcb_text"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),text:N(),center:Lo,layer:Wr,width:ee,height:ee,lines:vA(),align:Te(["bottom-left"])}).describe("Defines text on the PCB"),qyt=RA({route_type:CA("wire"),x:bt,y:bt,width:bt,start_pcb_port_id:N().optional(),end_pcb_port_id:N().optional(),layer:Wr}),Oyt=RA({route_type:CA("via"),x:bt,y:bt,hole_diameter:bt.optional(),outer_diameter:bt.optional(),from_layer:N(),to_layer:N()}),Wyt=Ht([qyt,Oyt]),Zyt=RA({type:CA("pcb_trace"),source_trace_id:N().optional(),pcb_component_id:N().optional(),pcb_trace_id:Ai("pcb_trace"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),route_thickness_mode:Te(["constant","interpolated"]).default("constant").optional(),route_order_index:vA().optional(),should_round_corners:$A().optional(),trace_length:vA().optional(),highlight_color:N().optional(),route:de(Wyt)}).describe("Defines a trace on the PCB"),Vyt=RA({type:CA("pcb_trace_error"),pcb_trace_error_id:Ai("pcb_trace_error"),error_type:CA("pcb_trace_error").default("pcb_trace_error"),message:N(),center:Lo.optional(),pcb_trace_id:N(),source_trace_id:N(),pcb_component_ids:de(N()),pcb_port_ids:de(N()),subcircuit_id:N().optional()}).describe("Defines a trace error on the PCB"),jyt=RA({type:CA("pcb_trace_missing_error"),pcb_trace_missing_error_id:Ai("pcb_trace_missing_error"),error_type:CA("pcb_trace_missing_error").default("pcb_trace_missing_error"),message:N(),center:Lo.optional(),source_trace_id:N(),pcb_component_ids:de(N()),pcb_port_ids:de(N()),subcircuit_id:N().optional()}).describe("Defines an error when a source trace has no corresponding PCB trace"),zyt=RA({type:CA("pcb_port_not_matched_error"),pcb_error_id:Ai("pcb_error"),error_type:CA("pcb_port_not_matched_error").default("pcb_port_not_matched_error"),message:N(),pcb_component_ids:de(N()),subcircuit_id:N().optional()}).describe("Defines a trace error on the PCB where a port is not matched"),Xyt=RA({type:CA("pcb_port_not_connected_error"),pcb_port_not_connected_error_id:Ai("pcb_port_not_connected_error"),error_type:CA("pcb_port_not_connected_error").default("pcb_port_not_connected_error"),message:N(),pcb_port_ids:de(N()),pcb_component_ids:de(N()),subcircuit_id:N().optional()}).describe("Defines an error when a pcb port is not connected to any trace"),$yt=RA({type:CA("pcb_net"),pcb_net_id:Ai("pcb_net"),source_net_id:N().optional(),highlight_color:N().optional()}).describe("Defines a net on the PCB"),Amt=RA({type:CA("pcb_via"),pcb_via_id:Ai("pcb_via"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),subcircuit_connectivity_map_key:N().optional(),x:bt,y:bt,outer_diameter:bt.default("0.6mm"),hole_diameter:bt.default("0.25mm"),from_layer:Wr.optional(),to_layer:Wr.optional(),layers:de(Wr),pcb_trace_id:N().optional(),net_is_assignable:$A().optional(),net_assigned:$A().optional(),is_tented:$A().optional()}).describe("Defines a via on the PCB"),emt=RA({type:CA("pcb_board"),pcb_board_id:Ai("pcb_board"),pcb_panel_id:N().optional(),is_subcircuit:$A().optional(),subcircuit_id:N().optional(),width:ee.optional(),height:ee.optional(),center:Lo,display_offset_x:N().optional().describe("How to display the x offset for this board, usually corresponding with how the user specified it"),display_offset_y:N().optional().describe("How to display the y offset for this board, usually corresponding with how the user specified it"),thickness:ee.optional().default(1.4),num_layers:vA().optional().default(4),outline:de(Lo).optional(),shape:Te(["rect","polygon"]).optional(),material:Te(["fr4","fr1"]).default("fr4"),anchor_position:Lo.optional(),anchor_alignment:sG.optional(),position_mode:Te(["relative_to_panel_anchor","none"]).optional()}).describe("Defines the board outline of the PCB"),tmt=RA({type:CA("pcb_panel"),pcb_panel_id:Ai("pcb_panel"),width:ee,height:ee,center:Lo,covered_with_solder_mask:$A().optional().default(!0)}).describe("Defines a PCB panel that can contain multiple boards"),imt=RA({type:CA("pcb_placement_error"),pcb_placement_error_id:Ai("pcb_placement_error"),error_type:CA("pcb_placement_error").default("pcb_placement_error"),message:N(),subcircuit_id:N().optional()}).describe("Defines a placement error on the PCB"),omt=RA({type:CA("pcb_trace_hint"),pcb_trace_hint_id:Ai("pcb_trace_hint"),pcb_port_id:N(),pcb_component_id:N(),route:de(pyt),subcircuit_id:N().optional()}).describe("A hint that can be used during generation of a PCB trace"),nmt=RA({type:CA("pcb_silkscreen_line"),pcb_silkscreen_line_id:Ai("pcb_silkscreen_line"),pcb_component_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),stroke_width:bt.default("0.1mm"),x1:bt,y1:bt,x2:bt,y2:bt,layer:ED}).describe("Defines a silkscreen line on the PCB"),smt=RA({type:CA("pcb_silkscreen_path"),pcb_silkscreen_path_id:Ai("pcb_silkscreen_path"),pcb_component_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),layer:ED,route:de(Lo),stroke_width:ee}).describe("Defines a silkscreen path on the PCB"),rmt=RA({type:CA("pcb_silkscreen_text"),pcb_silkscreen_text_id:Ai("pcb_silkscreen_text"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),font:CA("tscircuit2024").default("tscircuit2024"),font_size:bt.default("0.2mm"),pcb_component_id:N(),text:N(),is_knockout:$A().default(!1).optional(),knockout_padding:RA({left:ee,top:ee,bottom:ee,right:ee}).default({left:"0.2mm",top:"0.2mm",bottom:"0.2mm",right:"0.2mm"}).optional(),ccw_rotation:vA().optional(),layer:Wr,is_mirrored:$A().default(!1).optional(),anchor_position:Lo.default({x:0,y:0}),anchor_alignment:sG.default("center")}).describe("Defines silkscreen text on the PCB"),amt=RA({type:CA("pcb_copper_text"),pcb_copper_text_id:Ai("pcb_copper_text"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),font:CA("tscircuit2024").default("tscircuit2024"),font_size:bt.default("0.2mm"),pcb_component_id:N(),text:N(),is_knockout:$A().default(!1).optional(),knockout_padding:RA({left:ee,top:ee,bottom:ee,right:ee}).default({left:"0.2mm",top:"0.2mm",bottom:"0.2mm",right:"0.2mm"}).optional(),ccw_rotation:vA().optional(),layer:Wr,is_mirrored:$A().default(!1).optional(),anchor_position:Lo.default({x:0,y:0}),anchor_alignment:sG.default("center")}).describe("Defines copper text on the PCB"),gmt=RA({type:CA("pcb_silkscreen_rect"),pcb_silkscreen_rect_id:Ai("pcb_silkscreen_rect"),pcb_component_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),center:Lo,width:ee,height:ee,layer:Wr,stroke_width:ee.default("1mm"),corner_radius:ee.optional(),is_filled:$A().default(!0).optional(),has_stroke:$A().optional(),is_stroke_dashed:$A().optional(),ccw_rotation:vA().optional()}).describe("Defines a silkscreen rect on the PCB"),cmt=RA({type:CA("pcb_silkscreen_circle"),pcb_silkscreen_circle_id:Ai("pcb_silkscreen_circle"),pcb_component_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),center:Lo,radius:ee,layer:ED,stroke_width:ee.default("1mm")}).describe("Defines a silkscreen circle on the PCB"),Imt=RA({type:CA("pcb_silkscreen_oval"),pcb_silkscreen_oval_id:Ai("pcb_silkscreen_oval"),pcb_component_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),center:Lo,radius_x:bt,radius_y:bt,layer:ED,ccw_rotation:qd.optional()}).describe("Defines a silkscreen oval on the PCB"),lmt=RA({type:CA("pcb_silkscreen_pill"),pcb_silkscreen_pill_id:Ai("pcb_silkscreen_pill"),pcb_component_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),center:Lo,width:ee,height:ee,layer:Wr,ccw_rotation:vA().optional()}).describe("Defines a silkscreen pill on the PCB"),Bmt=RA({type:CA("pcb_fabrication_note_text"),pcb_fabrication_note_text_id:Ai("pcb_fabrication_note_text"),subcircuit_id:N().optional(),pcb_group_id:N().optional(),font:CA("tscircuit2024").default("tscircuit2024"),font_size:bt.default("1mm"),pcb_component_id:N(),text:N(),layer:ED,anchor_position:Lo.default({x:0,y:0}),anchor_alignment:Te(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),color:N().optional()}).describe("Defines a fabrication note in text on the PCB, useful for leaving notes for assemblers or fabricators"),Cmt=RA({type:CA("pcb_fabrication_note_path"),pcb_fabrication_note_path_id:Ai("pcb_fabrication_note_path"),pcb_component_id:N(),subcircuit_id:N().optional(),layer:Wr,route:de(Lo),stroke_width:ee,color:N().optional()}).describe("Defines a fabrication path on the PCB for fabricators or assemblers"),Qmt=RA({type:CA("pcb_fabrication_note_rect"),pcb_fabrication_note_rect_id:Ai("pcb_fabrication_note_rect"),pcb_component_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),center:Lo,width:ee,height:ee,layer:ED,stroke_width:ee.default("0.1mm"),corner_radius:ee.optional(),is_filled:$A().optional(),has_stroke:$A().optional(),is_stroke_dashed:$A().optional(),color:N().optional()}).describe("Defines a fabrication note rectangle on the PCB"),hmt=RA({type:CA("pcb_fabrication_note_dimension"),pcb_fabrication_note_dimension_id:Ai("pcb_fabrication_note_dimension"),pcb_component_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),layer:ED,from:Lo,to:Lo,text:N().optional(),text_ccw_rotation:vA().optional(),offset:ee.optional(),offset_distance:ee.optional(),offset_direction:RA({x:vA(),y:vA()}).optional(),font:CA("tscircuit2024").default("tscircuit2024"),font_size:ee.default("1mm"),color:N().optional(),arrow_size:ee.default("1mm")}).describe("Defines a measurement annotation within PCB fabrication notes"),Emt=RA({type:CA("pcb_note_text"),pcb_note_text_id:Ai("pcb_note_text"),pcb_component_id:N().optional(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),name:N().optional(),font:CA("tscircuit2024").default("tscircuit2024"),font_size:bt.default("1mm"),text:N().optional(),anchor_position:Lo.default({x:0,y:0}),anchor_alignment:Te(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),color:N().optional()}).describe("Defines a documentation note in text on the PCB"),umt=RA({type:CA("pcb_note_rect"),pcb_note_rect_id:Ai("pcb_note_rect"),pcb_component_id:N().optional(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),name:N().optional(),text:N().optional(),center:Lo,width:ee,height:ee,stroke_width:ee.default("0.1mm"),corner_radius:ee.optional(),is_filled:$A().optional(),has_stroke:$A().optional(),is_stroke_dashed:$A().optional(),color:N().optional()}).describe("Defines a rectangular documentation note on the PCB"),dmt=RA({type:CA("pcb_note_path"),pcb_note_path_id:Ai("pcb_note_path"),pcb_component_id:N().optional(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),name:N().optional(),text:N().optional(),route:de(Lo),stroke_width:ee.default("0.1mm"),color:N().optional()}).describe("Defines a polyline documentation note on the PCB"),pmt=RA({type:CA("pcb_note_line"),pcb_note_line_id:Ai("pcb_note_line"),pcb_component_id:N().optional(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),name:N().optional(),text:N().optional(),x1:bt,y1:bt,x2:bt,y2:bt,stroke_width:bt.default("0.1mm"),color:N().optional(),is_dashed:$A().optional()}).describe("Defines a straight documentation note line on the PCB"),fmt=RA({type:CA("pcb_note_dimension"),pcb_note_dimension_id:Ai("pcb_note_dimension"),pcb_component_id:N().optional(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),name:N().optional(),from:Lo,to:Lo,text:N().optional(),text_ccw_rotation:vA().optional(),offset_distance:ee.optional(),offset_direction:RA({x:vA(),y:vA()}).optional(),font:CA("tscircuit2024").default("tscircuit2024"),font_size:ee.default("1mm"),color:N().optional(),arrow_size:ee.default("1mm")}).describe("Defines a measurement annotation within PCB documentation notes"),ymt=RA({type:CA("pcb_footprint_overlap_error"),pcb_error_id:Ai("pcb_error"),error_type:CA("pcb_footprint_overlap_error").default("pcb_footprint_overlap_error"),message:N(),pcb_smtpad_ids:de(N()).optional(),pcb_plated_hole_ids:de(N()).optional(),pcb_hole_ids:de(N()).optional(),pcb_keepout_ids:de(N()).optional()}).describe("Error emitted when a pcb footprint overlaps with another element"),mmt=RA({type:CA("pcb_keepout"),shape:CA("rect"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),center:Lo,width:bt,height:bt,pcb_keepout_id:N(),layers:de(N()),description:N().optional()}).or(RA({type:CA("pcb_keepout"),shape:CA("circle"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),center:Lo,radius:bt,pcb_keepout_id:N(),layers:de(N()),description:N().optional()})),TW=RA({type:CA("pcb_cutout"),pcb_cutout_id:Ai("pcb_cutout"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),pcb_board_id:N().optional(),pcb_panel_id:N().optional()}),wmt=TW.extend({shape:CA("rect"),center:Lo,width:ee,height:ee,rotation:qd.optional(),corner_radius:ee.optional()}),Dmt=TW.extend({shape:CA("circle"),center:Lo,radius:ee}),Smt=TW.extend({shape:CA("polygon"),points:de(Lo)}),bmt=TW.extend({shape:CA("path"),route:de(Lo),slot_width:ee,slot_length:ee.optional(),space_between_slots:ee.optional(),slot_corner_radius:ee.optional()}),_mt=fh("shape",[wmt,Dmt,Smt,bmt]).describe("Defines a cutout on the PCB, removing board material."),xmt=RA({type:CA("pcb_missing_footprint_error"),pcb_missing_footprint_error_id:Ai("pcb_missing_footprint_error"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),error_type:CA("pcb_missing_footprint_error").default("pcb_missing_footprint_error"),source_component_id:N(),message:N()}).describe("Defines a missing footprint error on the PCB"),kmt=RA({type:CA("external_footprint_load_error"),external_footprint_load_error_id:Ai("external_footprint_load_error"),pcb_component_id:N(),source_component_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),footprinter_string:N().optional(),error_type:CA("external_footprint_load_error").default("external_footprint_load_error"),message:N()}).describe("Defines an error when an external footprint fails to load"),Fmt=RA({type:CA("circuit_json_footprint_load_error"),circuit_json_footprint_load_error_id:Ai("circuit_json_footprint_load_error"),pcb_component_id:N(),source_component_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),error_type:CA("circuit_json_footprint_load_error").default("circuit_json_footprint_load_error"),message:N(),circuit_json:de(jg()).optional()}).describe("Defines an error when a circuit JSON footprint fails to load"),Gmt=RA({type:CA("pcb_group"),pcb_group_id:Ai("pcb_group"),source_group_id:N(),is_subcircuit:$A().optional(),subcircuit_id:N().optional(),width:ee.optional(),height:ee.optional(),center:Lo,display_offset_x:N().optional().describe("How to display the x offset for this group, usually corresponding with how the user specified it"),display_offset_y:N().optional().describe("How to display the y offset for this group, usually corresponding with how the user specified it"),outline:de(Lo).optional(),anchor_position:Lo.optional(),anchor_alignment:sG.default("center"),position_mode:Te(["packed","relative_to_group_anchor","none"]).optional(),positioned_relative_to_pcb_group_id:N().optional(),positioned_relative_to_pcb_board_id:N().optional(),pcb_component_ids:de(N()),child_layout_mode:Te(["packed","none"]).optional(),name:N().optional(),description:N().optional(),layout_mode:N().optional(),autorouter_configuration:RA({trace_clearance:ee}).optional(),autorouter_used_string:N().optional()}).describe("Defines a group of components on the PCB"),Rmt=RA({type:CA("pcb_autorouting_error"),pcb_error_id:Ai("pcb_autorouting_error"),error_type:CA("pcb_autorouting_error").default("pcb_autorouting_error"),message:N(),subcircuit_id:N().optional()}).describe("The autorouting has failed to route a portion of the board"),vmt=RA({type:CA("pcb_manual_edit_conflict_warning"),pcb_manual_edit_conflict_warning_id:Ai("pcb_manual_edit_conflict_warning"),warning_type:CA("pcb_manual_edit_conflict_warning").default("pcb_manual_edit_conflict_warning"),message:N(),pcb_component_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),source_component_id:N()}).describe("Warning emitted when a component has both manual placement and explicit pcbX/pcbY coordinates"),Mmt=RA({type:CA("pcb_breakout_point"),pcb_breakout_point_id:Ai("pcb_breakout_point"),pcb_group_id:N(),subcircuit_id:N().optional(),source_trace_id:N().optional(),source_port_id:N().optional(),source_net_id:N().optional(),x:bt,y:bt}).describe("Defines a routing target within a pcb_group for a source_trace or source_net"),Nmt=RA({type:CA("pcb_ground_plane"),pcb_ground_plane_id:Ai("pcb_ground_plane"),source_pcb_ground_plane_id:N(),source_net_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional()}).describe("Defines a ground plane on the PCB"),Lmt=RA({type:CA("pcb_ground_plane_region"),pcb_ground_plane_region_id:Ai("pcb_ground_plane_region"),pcb_ground_plane_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),layer:Wr,points:de(Lo)}).describe("Defines a polygon region of a ground plane"),Umt=RA({type:CA("pcb_thermal_spoke"),pcb_thermal_spoke_id:Ai("pcb_thermal_spoke"),pcb_ground_plane_id:N(),shape:N(),spoke_count:vA(),spoke_thickness:bt,spoke_inner_diameter:bt,spoke_outer_diameter:bt,pcb_plated_hole_id:N().optional(),subcircuit_id:N().optional()}).describe("Pattern for connecting a ground plane to a plated hole"),dEA=RA({type:CA("pcb_copper_pour"),pcb_copper_pour_id:Ai("pcb_copper_pour"),pcb_group_id:N().optional(),subcircuit_id:N().optional(),layer:Wr,source_net_id:N().optional(),covered_with_solder_mask:$A().optional().default(!0)}),Hmt=dEA.extend({shape:CA("rect"),center:Lo,width:ee,height:ee,rotation:qd.optional()}),Ymt=dEA.extend({shape:CA("brep"),brep_shape:uyt}),Jmt=dEA.extend({shape:CA("polygon"),points:de(Lo)}),Tmt=fh("shape",[Hmt,Ymt,Jmt]).describe("Defines a copper pour on the PCB."),Kmt=RA({type:CA("pcb_component_outside_board_error"),pcb_component_outside_board_error_id:Ai("pcb_component_outside_board_error"),error_type:CA("pcb_component_outside_board_error").default("pcb_component_outside_board_error"),message:N(),pcb_component_id:N(),pcb_board_id:N(),component_center:Lo,component_bounds:RA({min_x:vA(),max_x:vA(),min_y:vA(),max_y:vA()}),subcircuit_id:N().optional(),source_component_id:N().optional()}).describe("Error emitted when a PCB component is placed outside the board boundaries"),Pmt=RA({type:CA("pcb_component_invalid_layer_error"),pcb_component_invalid_layer_error_id:Ai("pcb_component_invalid_layer_error"),error_type:CA("pcb_component_invalid_layer_error").default("pcb_component_invalid_layer_error"),message:N(),pcb_component_id:N().optional(),source_component_id:N(),layer:Wr,subcircuit_id:N().optional()}).describe("Error emitted when a component is placed on an invalid layer (components can only be on 'top' or 'bottom' layers)"),qmt=RA({type:CA("pcb_via_clearance_error"),pcb_error_id:Ai("pcb_error"),error_type:CA("pcb_via_clearance_error").default("pcb_via_clearance_error"),message:N(),pcb_via_ids:de(N()).min(2),minimum_clearance:bt.optional(),actual_clearance:bt.optional(),pcb_center:RA({x:vA().optional(),y:vA().optional()}).optional(),subcircuit_id:N().optional()}).describe("Error emitted when vias are closer than the allowed clearance"),Omt=RA({type:CA("pcb_courtyard_rect"),pcb_courtyard_rect_id:Ai("pcb_courtyard_rect"),pcb_component_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),center:Lo,width:ee,height:ee,layer:ED,color:N().optional()}).describe("Defines a courtyard rectangle on the PCB"),Wmt=RA({type:CA("pcb_courtyard_outline"),pcb_courtyard_outline_id:Ai("pcb_courtyard_outline"),pcb_component_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),layer:ED,outline:de(Lo).min(2),stroke_width:ee.default("0.1mm"),is_closed:$A().optional(),is_stroke_dashed:$A().optional(),color:N().optional()}).describe("Defines a courtyard outline on the PCB"),Zmt=RA({type:CA("pcb_courtyard_polygon"),pcb_courtyard_polygon_id:Ai("pcb_courtyard_polygon"),pcb_component_id:N(),pcb_group_id:N().optional(),subcircuit_id:N().optional(),layer:ED,points:de(Lo).min(3),color:N().optional()}).describe("Defines a courtyard polygon on the PCB"),Vmt=RA({type:CA("cad_component"),cad_component_id:N(),pcb_component_id:N(),source_component_id:N(),position:hEA,rotation:hEA.optional(),size:hEA.optional(),layer:Wr.optional(),subcircuit_id:N().optional(),footprinter_string:N().optional(),model_obj_url:N().optional(),model_stl_url:N().optional(),model_3mf_url:N().optional(),model_gltf_url:N().optional(),model_glb_url:N().optional(),model_step_url:N().optional(),model_wrl_url:N().optional(),model_unit_to_mm_scale_factor:vA().optional(),model_jscad:jg().optional(),show_as_translucent_model:$A().optional()}).describe("Defines a component on the PCB"),q6A=Te(["sinewave","square","triangle","sawtooth"]),jmt=Ht([N(),vA()]).transform(t=>typeof t=="string"?t.endsWith("%")?parseFloat(t.slice(0,-1))/100:parseFloat(t):t).pipe(vA().min(0,"Duty cycle must be non-negative").max(1,"Duty cycle cannot be greater than 100%")),zmt=RA({type:CA("simulation_voltage_source"),simulation_voltage_source_id:Ai("simulation_voltage_source"),is_dc_source:CA(!0).optional().default(!0),positive_source_port_id:N().optional(),negative_source_port_id:N().optional(),positive_source_net_id:N().optional(),negative_source_net_id:N().optional(),voltage:aN}).describe("Defines a DC voltage source for simulation"),Xmt=RA({type:CA("simulation_voltage_source"),simulation_voltage_source_id:Ai("simulation_voltage_source"),is_dc_source:CA(!1),terminal1_source_port_id:N().optional(),terminal2_source_port_id:N().optional(),terminal1_source_net_id:N().optional(),terminal2_source_net_id:N().optional(),voltage:aN.optional(),frequency:JW.optional(),peak_to_peak_voltage:aN.optional(),wave_shape:q6A.optional(),phase:qd.optional(),duty_cycle:jmt.optional()}).describe("Defines an AC voltage source for simulation"),$mt=Ht([zmt,Xmt]).describe("Defines a voltage source for simulation"),Awt=Ht([N(),vA()]).transform(t=>typeof t=="string"?t.endsWith("%")?parseFloat(t.slice(0,-1))/100:parseFloat(t):t).pipe(vA().min(0,"Duty cycle must be non-negative").max(1,"Duty cycle cannot be greater than 100%")),ewt=RA({type:CA("simulation_current_source"),simulation_current_source_id:Ai("simulation_current_source"),is_dc_source:CA(!0).optional().default(!0),positive_source_port_id:N().optional(),negative_source_port_id:N().optional(),positive_source_net_id:N().optional(),negative_source_net_id:N().optional(),current:CEA}).describe("Defines a DC current source for simulation"),twt=RA({type:CA("simulation_current_source"),simulation_current_source_id:Ai("simulation_current_source"),is_dc_source:CA(!1),terminal1_source_port_id:N().optional(),terminal2_source_port_id:N().optional(),terminal1_source_net_id:N().optional(),terminal2_source_net_id:N().optional(),current:CEA.optional(),frequency:JW.optional(),peak_to_peak_current:CEA.optional(),wave_shape:q6A.optional(),phase:qd.optional(),duty_cycle:Awt.optional()}).describe("Defines an AC current source for simulation"),iwt=Ht([ewt,twt]).describe("Defines a current source for simulation"),owt=Ht([CA("spice_dc_sweep"),CA("spice_dc_operating_point"),CA("spice_transient_analysis"),CA("spice_ac_analysis")]),nwt=RA({type:CA("simulation_experiment"),simulation_experiment_id:Ai("simulation_experiment"),name:N(),experiment_type:owt,time_per_step:QEA.optional(),start_time_ms:gN.optional(),end_time_ms:gN.optional()}).describe("Defines a simulation experiment configuration"),swt=RA({type:CA("simulation_transient_voltage_graph"),simulation_transient_voltage_graph_id:Ai("simulation_transient_voltage_graph"),simulation_experiment_id:N(),timestamps_ms:de(vA()).optional(),voltage_levels:de(vA()),source_component_id:N().optional(),subcircuit_connectivity_map_key:N().optional(),time_per_step:QEA,start_time_ms:gN,end_time_ms:gN,name:N().optional(),color:N().optional()}).describe("Stores voltage measurements over time for a simulation"),rwt=RA({type:CA("simulation_switch"),simulation_switch_id:Ai("simulation_switch"),source_component_id:N().optional(),closes_at:gN.optional(),opens_at:gN.optional(),starts_closed:$A().optional(),switching_frequency:JW.optional()}).describe("Defines a switch for simulation timing control"),awt=RA({type:CA("simulation_voltage_probe"),simulation_voltage_probe_id:Ai("simulation_voltage_probe"),source_component_id:N().optional(),name:N().optional(),signal_input_source_port_id:N().optional(),signal_input_source_net_id:N().optional(),reference_input_source_port_id:N().optional(),reference_input_source_net_id:N().optional(),subcircuit_id:N().optional(),color:N().optional()}).describe("Defines a voltage probe for simulation. If a reference input is not provided, it measures against ground. If a reference input is provided, it measures the differential voltage between two points.").superRefine((t,A)=>{if(t.reference_input_source_port_id||t.reference_input_source_net_id){const i=!!t.signal_input_source_port_id||!!t.reference_input_source_port_id,o=!!t.signal_input_source_net_id||!!t.reference_input_source_net_id;i&&o?A.addIssue({code:Ot.custom,message:"Cannot mix port and net connections in a differential probe."}):i?(!t.signal_input_source_port_id||!t.reference_input_source_port_id)&&A.addIssue({code:Ot.custom,message:"Differential port probe requires both signal_input_source_port_id and reference_input_source_port_id."}):o&&(!t.signal_input_source_net_id||!t.reference_input_source_net_id)&&A.addIssue({code:Ot.custom,message:"Differential net probe requires both signal_input_source_net_id and reference_input_source_net_id."})}else!!t.signal_input_source_port_id==!!t.signal_input_source_net_id&&A.addIssue({code:Ot.custom,message:"A voltage probe must have exactly one of signal_input_source_port_id or signal_input_source_net_id."})}),gwt=RA({type:CA("simulation_unknown_experiment_error"),simulation_unknown_experiment_error_id:Ai("simulation_unknown_experiment_error"),error_type:CA("simulation_unknown_experiment_error").default("simulation_unknown_experiment_error"),message:N(),simulation_experiment_id:N().optional(),subcircuit_id:N().optional()}).describe("An unknown error occurred during the simulation experiment."),cwt=RA({type:CA("simulation_op_amp"),simulation_op_amp_id:Ai("simulation_op_amp"),source_component_id:N().optional(),inverting_input_source_port_id:N(),non_inverting_input_source_port_id:N(),output_source_port_id:N(),positive_supply_source_port_id:N(),negative_supply_source_port_id:N()}).describe("Defines a simple ideal operational amplifier for simulation");Ht([v0t,G0t,R0t,F0t,N0t,M0t,p6A,E6A,EEA,d6A,u6A,f6A,y6A,m6A,S6A,b6A,_6A,R6A,x6A,k6A,F6A,G6A,D6A,w6A,U0t,Y0t,L0t,v6A,M6A,N6A,J0t,T0t,fyt,yyt,xmt,kmt,Fmt,vmt,xyt,mmt,kyt,$yt,Pyt,Zyt,Amt,Lyt,Kyt,emt,tmt,Gmt,omt,nmt,smt,rmt,lmt,amt,gmt,cmt,Imt,Vyt,jyt,imt,zyt,Xyt,qmt,Cmt,Bmt,Qmt,hmt,Emt,umt,dmt,pmt,fmt,Rmt,ymt,Mmt,_mt,Nmt,Lmt,Umt,Tmt,Kmt,Pmt,Omt,Wmt,Zmt,K0t,tyt,j0t,z0t,X0t,$0t,V0t,iyt,Ayt,P0t,nyt,syt,oyt,cyt,Iyt,lyt,Byt,hyt,Cyt,Qyt,Vmt,$mt,iwt,nwt,swt,rwt,awt,gwt,cwt]);var Iwt=Object.defineProperty,lwt=(t,A)=>{for(var e in A)Iwt(t,e,{get:A[e],enumerable:!0})},Ib={};lwt(Ib,{axial:()=>MDt,bga:()=>Pwt,breakoutheaders:()=>ZDt,cap:()=>dwt,dfn:()=>hDt,diode:()=>uwt,dip:()=>Qwt,electrolytic:()=>F_t,hc49:()=>jDt,jst:()=>$bt,led:()=>pwt,lqfp:()=>ODt,m2host:()=>X_t,melf:()=>abt,micromelf:()=>lbt,minimelf:()=>Abt,mlp:()=>$wt,ms012:()=>mDt,ms013:()=>DDt,msop:()=>g_t,pad:()=>zDt,pinrow:()=>dDt,platedhole:()=>K_t,potentiometer:()=>__t,pushbutton:()=>YDt,qfn:()=>jwt,qfp:()=>Xwt,quad:()=>IN,radial:()=>UDt,res:()=>Jwt,sma:()=>hbt,smb:()=>wbt,smbf:()=>R_t,smc:()=>_bt,smf:()=>pbt,smtpad:()=>J_t,sod110:()=>e_t,sod123:()=>FDt,sod123f:()=>GSt,sod123fl:()=>NSt,sod123w:()=>lSt,sod128:()=>PSt,sod323:()=>hSt,sod323f:()=>_St,sod323fl:()=>Q_t,sod323w:()=>I_t,sod523:()=>tSt,sod723:()=>YSt,sod80:()=>aSt,sod882:()=>wSt,sod882d:()=>obt,sod923:()=>pSt,soic:()=>Owt,solderjumper:()=>p_t,son:()=>d_t,sop8:()=>sSt,sot:()=>q_t,sot223:()=>Gbt,sot23:()=>gDt,sot23w:()=>Jbt,sot25:()=>BDt,sot323:()=>L_t,sot343:()=>Z_t,sot363:()=>nDt,sot457:()=>m_t,sot563:()=>fDt,sot723:()=>bDt,sot886:()=>rDt,sot89:()=>jSt,sot963:()=>D_t,ssop:()=>eDt,stampboard:()=>TDt,stampreceiver:()=>qDt,to220:()=>XSt,to92:()=>ASt,to92l:()=>Axt,to92s:()=>Wbt,tqfp:()=>zwt,tssop:()=>iDt,vssop:()=>s_t});var Zi=(t,A,e)=>({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:e,pcb_component_id:"pcb_component_1",text:"{REF}",layer:"top",anchor_position:{x:t,y:A},anchor_alignment:"center"}),Vi=RA({norefdes:$A().optional().describe("disable reference designator label"),invert:$A().optional().describe("hint to invert the orientation of the 3D model"),faceup:$A().optional().describe("The male pin header should face upwards, out of the top layer"),nosilkscreen:$A().optional().describe("omit all silkscreen elements from the footprint")}),As=(t,A,e,i,o)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circle",x:A,y:e,hole_diameter:vr(i),outer_diameter:vr(o),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()]}),lb=(t,A,e,i,o,n,s,r)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circular_hole_with_rect_pad",x:A,y:e,hole_diameter:vr(i),hole_shape:"circle",pad_shape:"rect",rect_pad_width:vr(o),rect_pad_height:vr(n),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()],hole_offset_x:s,hole_offset_y:r}),O6A=Array.from({length:9},(t,A)=>Math.cos(A/8*Math.PI-Math.PI)).map(t=>({x:t,y:-Math.sqrt(1-t**2)}));function wx(t){return typeof t=="string"?t.trim().toLowerCase().endsWith("mil")?parseFloat(t)*.0254:parseFloat(t):Number(t)}var KW=Ht([N(),vA()]).transform(t=>wx(t)),Bwt=t=>Vi.extend({fn:N(),num_pins:vA().optional().default(6),wide:$A().optional(),narrow:$A().optional(),w:KW.optional(),p:KW.default(t.p??"2.54mm"),id:KW.optional(),od:KW.optional(),nosquareplating:$A().optional().default(!1).describe("do not use rectangular pad for pin 1")}).transform(A=>(!A.id&&!A.od?Math.abs(A.p-1.27)<.01?(A.id=wx("0.55mm"),A.od=wx("0.95mm")):(A.id=wx("0.8mm"),A.od=wx("1.6mm")):A.id?A.od||(A.od=A.id*(1.5/1)):A.id=A.od*(1/1.5),A.w||(A.wide?A.w=wx("600mil"):A.narrow?A.w=wx("300mil"):A.w=wx(t.w??"300mil")),A)),Cwt=Bwt({}),W6A=(t,A,e,i,o)=>{const n=t/2,s=A<=n,r=n-1,a=i,g=a*r;return s?{x:-e/2,y:g/2-(A-1)*a}:{x:e/2,y:-g/2+(A-n-1)*a}},Qwt=t=>{const A=Cwt.parse(t),e=[];for(let g=0;g<A.num_pins;g++){const{x:c,y:I}=W6A(A.num_pins,g+1,A.w,A.p??2.54,A.nosquareplating);if(g===0&&!A.nosquareplating){e.push(lb(g+1,c,I,A.id??"0.8mm",A.od??"1mm",A.od??"1mm"));continue}e.push(As(g+1,c,I,A.id??"0.8mm",A.od??"1mm"))}(A.num_pins/2-1)*A.p+A.od;const o=A.w-A.od-1,n=(A.num_pins/2-1)*A.p+A.od+.4,s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-o/2,y:-n/2},{x:-o/2,y:n/2},...O6A.map(({x:g,y:c})=>({x:g*o/6,y:c*o/6+n/2})),{x:o/2,y:n/2},{x:o/2,y:-n/2},{x:-o/2,y:-n/2}],type:"pcb_silkscreen_path",stroke_width:.1},r=[];for(let g=0;g<A.num_pins;g++){const c=g<A.num_pins/2,I=.6,{y:l}=W6A(A.num_pins,g+1,A.w,A.p??2.54,A.nosquareplating),B=c?-A.w/2-A.od/2-I:A.w/2+A.od/2+I,C=l;r.push({type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:`pin_${g+1}`,layer:"top",pcb_component_id:`pin_${g+1}`,text:`{pin${g+1}}`,anchor_position:{x:B,y:C},font_size:.3,font:"tscircuit2024",anchor_alignment:"top_left"})}const a=Zi(0,n/2+.5,.4);return{circuitJson:[...e,s,a,...r],parameters:A}},yi=(t,A,e,i,o)=>({type:"pcb_smtpad",x:A,y:e,width:i,height:o,layer:"top",shape:"rect",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(n=>n.toString()):[t.toString()]}),Z6A=[{imperial:"01005",metric:"0402",p_mm_min:.5,pw_mm_min:.4,ph_mm_min:.3,w_mm_min:.58,h_mm_min:.21},{imperial:"0504",metric:"1310",p_mm_min:1.1,pw_mm_min:.65,ph_mm_min:1.3,w_mm_min:.58,h_mm_min:.21},{imperial:"1812",metric:"4532",p_mm_min:4.275,pw_mm_min:1.125,ph_mm_min:3.4,w_mm_min:5.4,h_mm_min:3.4},{imperial:"0201",metric:"0603",p_mm_min:.66,pw_mm_min:.46,ph_mm_min:.4,w_mm_min:.9,h_mm_min:.3},{imperial:"0402",metric:"1005",p_mm_min:1.02,pw_mm_min:.54,ph_mm_min:.64,w_mm_min:1.56,h_mm_min:.64},{imperial:"0603",metric:"1608",p_mm_min:1.65,pw_mm_min:.8,ph_mm_min:.95,w_mm_min:2.45,h_mm_min:.95},{imperial:"0805",metric:"2012",p_mm_min:1.825,pw_mm_min:1.025,ph_mm_min:1.4,w_mm_min:2.8499999999999996,h_mm_min:1.4},{imperial:"1206",metric:"3216",p_mm_min:2.925,pw_mm_min:1.125,ph_mm_min:1.75,w_mm_min:4.05,h_mm_min:1.75},{imperial:"1210",metric:"3225",p_mm_min:2.925,pw_mm_min:1.125,ph_mm_min:2.65,w_mm_min:4.05,h_mm_min:2.65},{imperial:"2010",metric:"5025",p_mm_min:4.625,pw_mm_min:1.225,ph_mm_min:2.65,w_mm_min:5.85,h_mm_min:2.65},{imperial:"2512",metric:"6332",p_mm_min:5.925,pw_mm_min:1.225,ph_mm_min:3.35,w_mm_min:7.15,h_mm_min:3.35}],hwt=Object.fromEntries(Z6A.map(t=>[t.metric,t])),Ewt=Object.fromEntries(Z6A.map(t=>[t.imperial,t]));Vi.extend({tht:$A(),p:ee.optional(),pw:ee.optional(),ph:ee.optional(),metric:bt.optional(),imperial:bt.optional(),w:ee.optional(),h:ee.optional(),textbottom:$A().optional()});var PW=t=>{let{tht:A,p:e,pw:i,ph:o,metric:n,imperial:s,w:r,h:a,textbottom:g}=t;if(typeof r=="string"&&(r=Rl(r)),typeof a=="string"&&(a=Rl(a)),typeof e=="string"&&(e=Rl(e)),typeof i=="string"&&(i=Rl(i)),typeof o=="string"&&(o=Rl(o)),a!==void 0&&r!==void 0&&a>r)throw new Error("height cannot be greater than width (rotated footprint not yet implemented)");let c;if(n&&(c=hwt[n]),s&&(c=Ewt[s]),c&&(r=c.w_mm_min,a=c.h_mm_min,e=c.p_mm_min,i=c.pw_mm_min,o=c.ph_mm_min),e===void 0||i===void 0||o===void 0)throw new Error("Could not determine required pad dimensions (p, pw, ph)");const I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:e/2,y:o/2+.4},{x:-e/2-i/2-.2,y:o/2+.4},{x:-e/2-i/2-.2,y:-o/2-.4},{x:e/2,y:-o/2-.4}],stroke_width:.1,pcb_silkscreen_path_id:""},l=g?-o/2-.9:o/2+.9,B=Zi(0,l,.2);return A?[As(1,-e/2,0,i,i*1/.8),As(2,e/2,0,i,i*1/.8),I,B]:[yi(["1","left"],-e/2,0,i,o),yi(["2","right"],e/2,0,i,o),I,B]},uwt=t=>({circuitJson:PW(t),parameters:t}),dwt=t=>({circuitJson:PW(t),parameters:t}),pwt=t=>({circuitJson:PW(t),parameters:t}),cN=t=>{const{padSpacing:A,padWidth:e,padHeight:i,padPitch:o,numRows:n,textbottom:s}=t,r=[],a=(n-1)*(o/2);for(let b=0;b<n;b++)r.push(a-b*o);const g=[];r.forEach((b,k)=>{g.push(yi(k+1,-A/2,b,e,i))}),r.slice().reverse().forEach((b,k)=>{g.push(yi(k+n+1,A/2,b,e,i))});const c=Math.max(...r)+i/2+.4,I=Math.min(...r)-i/2-.4,l=-A/2-e/2-.4,B=A/2+e/2+.4,C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B*.5,y:c},{x:l*.5,y:c}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_top"},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B*.5,y:I},{x:l*.5,y:I}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_bottom"},h=-A/2,E=Math.max(...r),u=.2,d=h-e/2-.1,f=E+i/2+.1,m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:[{x:d,y:f},{x:d-u,y:f},{x:d,y:f+u},{x:d,y:f}],stroke_width:.1},D=s?I-.9:c+.9,w=Zi(0,D,.2);return[...g,C,Q,m,w]},fwt=Vi.extend({pw:N().default("0.5mm"),ph:N().default("0.4mm"),p:N().default("0.7mm"),textbottom:$A().optional()}),ywt=1,mwt=t=>{const A=fwt.parse(t),e=Rl(A.pw),i=Rl(A.ph),o=Rl(A.p);return cN({padSpacing:ywt,padWidth:e,padHeight:i,padPitch:o,numRows:2,textbottom:A.textbottom})},wwt=Vi.extend({pw:N().default("0.5mm"),ph:N().default("0.32mm"),p:N().default("0.5mm"),textbottom:$A().optional()}),Dwt=1,Swt=t=>{const A=wwt.parse(t),e=Rl(A.pw),i=Rl(A.ph),o=Rl(A.p);return cN({padSpacing:Dwt,padWidth:e,padHeight:i,padPitch:o,numRows:4,textbottom:A.textbottom})},bwt=Vi.extend({pw:N().default("0.9mm"),ph:N().default("0.4mm"),p:N().default("0.8mm"),textbottom:$A().optional()}),_wt=1.7,xwt=t=>{const A=bwt.parse(t),e=Rl(A.pw),i=Rl(A.ph),o=Rl(A.p);return cN({padSpacing:_wt,padWidth:e,padHeight:i,padPitch:o,numRows:2,textbottom:A.textbottom})},kwt=Vi.extend({pw:N().default("0.9mm"),ph:N().default("0.4mm"),p:N().default("0.8mm"),textbottom:$A().optional()}),Fwt=1.7,Gwt=t=>{const A=kwt.parse(t),e=Rl(A.pw),i=Rl(A.ph),o=Rl(A.p);return cN({padSpacing:Fwt,padWidth:e,padHeight:i,padPitch:o,numRows:4,textbottom:A.textbottom})},Rwt=Vi.extend({pw:N().default("0.7mm"),ph:N().default("0.64mm"),p:N().default("0.94mm"),textbottom:$A().optional()}),vwt=1.4,Mwt=t=>{const A=Rwt.parse(t),e=Rl(A.pw),i=Rl(A.ph),o=Rl(A.p);return cN({padSpacing:vwt,padWidth:e,padHeight:i,padPitch:o,numRows:2,textbottom:A.textbottom})},Nwt=Vi.extend({pw:N().default("0.9mm"),ph:N().default("0.9mm"),p:N().default("1.34mm"),textbottom:$A().optional()}),Lwt=3,Uwt=t=>{const A=Nwt.parse(t),e=Rl(A.pw),i=Rl(A.ph),o=Rl(A.p);return cN({padSpacing:Lwt,padWidth:e,padHeight:i,padPitch:o,numRows:4,textbottom:A.textbottom})},Hwt=t=>{const A=t.array??t.x;if(typeof A=="number")return Number.isNaN(A)?void 0:A;if(typeof A=="string"){const e=Number.parseInt(A,10);return Number.isNaN(e)?void 0:e}if(typeof t.imperial=="string"){const i=t.imperial.match(/(?:array|x)(2|4)$/)?.[1];if(i)return Number.parseInt(i,10)}},Ywt=t=>t?(typeof t=="number"?`${t}`:t).split("_")[0]:void 0,Jwt=t=>{const A=Hwt(t),e=Ywt(t.imperial);return A===2&&e==="0402"?{circuitJson:mwt(t),parameters:t}:A===4&&e==="0402"?{circuitJson:Swt(t),parameters:t}:A===2&&e==="0603"?{circuitJson:xwt(t),parameters:t}:A===4&&e==="0603"?{circuitJson:Gwt(t),parameters:t}:A===2&&e==="0606"?{circuitJson:Mwt(t),parameters:t}:A===4&&e==="1206"?{circuitJson:Uwt(t),parameters:t}:{circuitJson:PW(t),parameters:t}},V6A=(t,{x:A,y:e,radius:i})=>({type:"pcb_smtpad",x:A,y:e,radius:i,layer:"top",shape:"circle",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(o=>o.toString()):[t.toString()]}),j6A="ABCDEFGHIJKLMNOPQRSTUVWXYZ",z6A=N().transform(t=>{const[A,e]=t.split(/[x ]/);return{x:parseFloat(A),y:parseFloat(e)}}).pipe(RA({x:vA(),y:vA()})),Twt=N().or(de(jg())).transform(t=>Array.isArray(t)?t:(t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,-1)),t.split(",").map(A=>{const e=Number(A);return isNaN(e)?A:e}))).pipe(de(N().or(vA()))),Kwt=Vi.extend({fn:N(),num_pins:vA().optional().default(64),grid:z6A.optional(),p:bt.default("0.8mm"),w:ee.optional(),h:ee.optional(),ball:ee.optional().describe("ball diameter"),pad:ee.optional().describe("pad width/height"),circularpads:$A().optional().describe("use circular pads"),tlorigin:$A().optional(),blorigin:$A().optional(),trorigin:$A().optional(),brorigin:$A().optional(),missing:Twt.default([])}).transform(t=>{let A="tl";if(t.blorigin&&(A="bl"),t.trorigin&&(A="tr"),t.brorigin&&(A="br"),!t.grid){const i=Math.ceil(Math.sqrt(t.num_pins));t.grid={x:i,y:i}}return t.missing&&(t.missing=t.missing.map(i=>{if(typeof i=="number")return i;if(i==="center")return"center";if(i==="topleft")return"topleft";const o=i.match(/([A-Z]+)(\d+)/);if(!o)return i;const n=j6A.indexOf(o[1]),s=Number.parseInt(o[2])-1;return n*t.grid.x+s+1})),{...t,origin:A}}),Pwt=t=>{const A=Kwt.parse(t);let{num_pins:e,grid:i,p:o,w:n,h:s,ball:r,pad:a,missing:g}=A;r??=.75/1.27*o,a??=r*.8;const c=[],I=(g??[]).filter(m=>typeof m=="number"),l=i.x*i.y-e;if(g.length===0&&l>0&&(Math.sqrt(l)%1===0?g.push("center"):l===1&&g.push("topleft")),g?.includes("center")){const m=Math.floor(Math.sqrt(l)),D=Math.floor((i.x-m)/2),w=Math.floor((i.y-m)/2);for(let b=w;b<w+m;b++)for(let k=D;k<D+m;k++)I.push(b*i.x+k+1)}g?.includes("topleft")&&I.push(1);const B=new Set(I);let C=0;for(let m=0;m<i.y;m++)for(let D=0;D<i.x;D++){const w=(D-(i.x-1)/2)*o,b=(m-(i.y-1)/2)*o;let k=D,_=m;switch(A.origin){case"bl":k=D,_=i.y-1-m;break;case"br":k=i.x-1-D,_=i.y-1-m;break;case"tr":k=i.x-1-D,_=m;break}let M=_*i.x+k+1;if(B.has(M)){C++;continue}M-=C;const v=[M,`${j6A[_]}${k+1}`];c.push(A.circularpads?V6A(v,{x:w,y:b,radius:a/2}):yi(v,w,b,a,a))}const Q=Zi(0,i.y*o/2,.2),h=o/6;let E;const u=i.x*o/2,d=i.y*o/2;switch(A.origin){case"bl":E=[{x:-u,y:-d},{x:-u,y:-d-h},{x:-u-h,y:-d},{x:-u,y:-d}];break;case"br":E=[{x:u,y:-d},{x:u,y:-d-h},{x:u+h,y:-d},{x:u,y:-d}];break;case"tr":E=[{x:u,y:d},{x:u,y:d+h},{x:u+h,y:d},{x:u,y:d}];break;default:E=[{x:-u,y:d},{x:-u,y:d+h},{x:-u-h,y:d},{x:-u,y:d}];break}const f={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:E,stroke_width:.05};return{circuitJson:[...c,Q,f],parameters:A}},qW=(t,A,e,i,o)=>({type:"pcb_smtpad",x:A,y:e,width:i,height:o,radius:o/2,layer:"top",shape:"pill",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(n=>n.toString()):[t.toString()]}),uD=t=>Vi.extend({fn:N(),num_pins:vA().optional().default(8),w:ee.default(ee.parse(t.w??"5.3mm")),p:ee.default(ee.parse(t.p??"1.27mm")),pw:ee.default(ee.parse(t.pw??"0.6mm")),pl:ee.default(ee.parse(t.pl??"1.0mm")),legsoutside:$A().optional().default(t.legsoutside??!1),pillpads:$A().optional().default(t.pillpads??!1),silkscreen_stroke_width:vA().optional().default(.1)}).transform(A=>(!A.pw&&!A.pl?(A.pw=ee.parse("0.6mm"),A.pl=ee.parse("1.0mm")):A.pw?A.pl||(A.pl=A.pw*(1/.6)):A.pw=A.pl*(.6/1),A)),qwt=uD({}),pEA=t=>{t.widthincludeslegs!==void 0&&(t.legsoutside=!t.widthincludeslegs);const{num_pins:A,pn:e,w:i,p:o,pl:n,legsoutside:s}=t,r=A/2,a=e<=r,g=r-1,c=o,I=c*g,l=s?n/2:-n/2;return a?{x:-i/2-l,y:I/2-(e-1)*c}:{x:i/2+l,y:-I/2+(e-r-1)*c}},Owt=t=>{const A=qwt.parse(t);return{circuitJson:Dx(A),parameters:A}},Dx=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=pEA({num_pins:t.num_pins,pn:r+1,w:t.w,p:t.p,pl:t.pl,legsoutside:t.legsoutside});t.pillpads?A.push(qW(r+1,a,g,t.pl,t.pw)):A.push(yi(r+1,a,g,t.pl,t.pw))}const e=Math.min(1,t.p/2),i=t.w-(t.legsoutside?0:t.pl*2)-.2,o=(t.num_pins/2-1)*t.p+t.pw+e,n=Zi(0,o/2+.4,o/12),s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:t.silkscreen_stroke_width??.1,route:[{x:-i/2,y:-o/2},{x:-i/2,y:o/2},...O6A.map(({x:r,y:a})=>({x:r*i/6,y:a*i/6+o/2})),{x:i/2,y:o/2},{x:i/2,y:-o/2},{x:-i/2,y:-o/2}]};return[...A,s,n]},X6A=Te(["leftside","topside","rightside","bottomside","toppin","bottompin","leftpin","rightpin"]),Wwt=({num_pins:t,cw:A,ccw:e,startingpin:i})=>{const o=[],n=t/4;let s=1;const r={};for(const a of i??[])r[a]=!0;!r.leftside&&!r.topside&&!r.rightside&&!r.bottomside&&(r.leftside=!0),!r.bottompin&&!r.leftpin&&!r.rightpin&&!r.toppin&&(r.leftside?r.toppin=!0:r.topside?r.rightpin=!0:r.rightside?r.bottompin=!0:r.bottomside&&(r.leftpin=!0)),r.leftside&&r.toppin?s=1:r.leftside&&r.bottompin?s=n:r.bottomside&&r.leftpin?s=n+1:r.bottomside&&r.rightpin?s=n*2:r.rightside&&r.bottompin?s=n*2+1:r.rightside&&r.toppin?s=n*3:r.topside&&r.rightpin?s=n*3+1:r.topside&&r.leftpin&&(s=n*4),o.push(-1);for(let a=0;a<t;a++)o[s]=a+1,e||!A?(s++,s>t&&(s=1)):(s--,s<1&&(s=t));return o},fEA=Vi.extend({fn:N(),cc:$A().default(!0).optional(),ccw:$A().default(!0).optional(),startingpin:N().or(de(X6A)).transform(t=>typeof t=="string"?t.slice(1,-1).split(","):t).pipe(de(X6A)).optional(),num_pins:vA().optional().default(64),w:ee.optional(),h:ee.optional(),p:ee.default(ee.parse("0.5mm")),pw:ee.optional(),pl:ee.optional(),thermalpad:Ht([CA(!0),z6A]).optional(),legsoutside:$A().default(!1)}),yEA=t=>{t.w&&!t.h?t.h=t.w:!t.w&&t.h&&(t.w=t.h);const A=t.num_pins/4;if(!t.p&&!t.pw&&!t.pl&&t.w){const e=A+4;t.p=t.w/e}return!t.p&&t.w&&t.h&&t.pw&&t.pl&&(t.p=(t.w-t.pl*2)/(A-1)),!t.w&&!t.h&&t.p&&(t.w=t.p*(A+4),t.h=t.w),t.p&&!t.pw&&!t.pl?(t.pw=t.p/2,t.pl=t.p/2):t.pw?t.pl||(t.pl=t.pw*(1/.6)):t.pw=t.pl*(.6/1),t},$6A=fEA.transform(yEA),Zwt=["left","bottom","right","top"],Vwt=t=>{const{pin_count:A,pn:e,w:i,h:o,p:n,pl:s,legsoutside:r}=t,a=A/4,g=Zwt[Math.floor((e-1)/a)],c=(e-1)%a,I=n*(a-1),l=n*(a-1),B=r?s/2:-s/2;switch(g){case"left":return{x:-i/2-B+.1,y:l/2-c*n,o:"vert"};case"bottom":return{x:-I/2+c*n,y:-o/2-B+.1,o:"horz"};case"right":return{x:i/2+B-.1,y:-l/2+c*n,o:"vert"};case"top":return{x:I/2-c*n,y:o/2+B-.1,o:"horz"};default:throw new Error("Invalid pin number")}},IN=t=>{const A=$6A.parse(t),e=[],i=Wwt(A),o=A.num_pins/4;for(let r=0;r<A.num_pins;r++){const{x:a,y:g,o:c}=Vwt({pin_count:A.num_pins,pn:r+1,w:A.w,h:A.h,p:A.p??.5,pl:A.pl,legsoutside:A.legsoutside});let I=A.pw,l=A.pl;c==="vert"&&([I,l]=[l,I]);const B=i[r+1];e.push(yi(B,a,g,I,l))}if(A.thermalpad)if(typeof A.thermalpad=="boolean"){const r=A.p*(o-1)+A.pw,a=A.p*(o-1)+A.pw;e.push(yi(["thermalpad"],0,0,r,a))}else e.push(yi(["thermalpad"],0,0,A.thermalpad.x,A.thermalpad.y));const n=[];for(const[r,a,g]of[["top-left",-1,1],["bottom-left",-1,-1],["bottom-right",1,-1],["top-right",1,1]]){const c=A.w/2*a,I=A.h/2*g;let l="none",B=c,C=I;const Q=A.pw*2;i[1]===1&&r==="top-left"?l="in1":i[o*4]===1&&r==="top-left"||i[o*3+1]===1&&r==="top-right"?l="in2":i[o*3]===1&&r==="top-right"||i[o]===1&&r==="bottom-left"?l="in1":i[o+1]===1&&r==="bottom-left"?l="in2":i[o*2]===1&&r==="bottom-right"?l="in1":i[o*2+1]===1&&r==="bottom-right"&&(l="in2");const h=l==="in1"?1:-1;if(A.legsoutside){const E=l==="in1"?A.pl/2:A.pw/2,u=l==="in1"?A.pw/2:A.pl/2;B+=E*a*h,C-=u*g*h}(l==="none"||A.legsoutside)&&n.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}`,route:[{x:c-Q*a,y:I},{x:c,y:I},{x:c,y:I-Q*g}],type:"pcb_silkscreen_path",stroke_width:.1}),(l==="in1"||l==="in2")&&!A.legsoutside&&n.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_1`,route:[{x:c-Q*a,y:I},{x:c-Q*a/2,y:I}],type:"pcb_silkscreen_path",stroke_width:0},{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_2`,route:[{x:c,y:I-Q*g/2},{x:c,y:I-Q*g}],type:"pcb_silkscreen_path",stroke_width:.1}),(l==="in1"||l==="in2")&&n.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_3`,route:[{x:B-.2*-a,y:C+.2*h},{x:B,y:C},{x:B+.2*h*-a,y:C+.2},{x:B-.2*-a,y:C+.2*h}],type:"pcb_silkscreen_path",stroke_width:.1})}const s=Zi(0,A.h/2+(A.legsoutside?A.pl*1.2:.5),.3);return{circuitJson:[...e,...n,s],parameters:A}};fEA.extend({}).transform(yEA);var jwt=t=>(t.legsoutside=!1,t.pl||(t.pl=.875),t.pw||(t.pw=.25),IN(t)),zwt=t=>{if(t.legsoutside=!0,!t.p)switch(t.num_pins){case 32:t.p=.8;break;case 44:case 48:t.p=.5;break;case 64:case 80:case 100:t.p=.5;break;case 144:t.p=.5;break}if(!t.pl)switch(t.num_pins){case 32:case 44:case 48:case 64:case 80:case 100:t.pl=1.475;break;case 144:t.pl=1.6;break}if(!t.pw)switch(t.num_pins){case 32:t.pw=.55;break;case 44:case 48:case 64:case 80:case 100:t.pw=.3;break;case 144:t.pw=.25;break}return IN(t)},Xwt=t=>{t.legsoutside=!0;const A=$6A.parse(t);if(!t.p)switch(t.num_pins){case 44:case 64:t.p=.8;break;case 52:t.w===14?t.p=1:t.p=.65;break;case 208:t.p=.5;break}if(!t.pl)switch(t.num_pins){case 44:case 52:case 64:t.pl=2.25;break;case 208:t.pl=1.65;break;default:t.pl=A.pl*4;break}if(!t.pw)switch(t.num_pins){case 44:case 64:t.pw=.5;break;case 52:t.w===14?t.pw=.45:t.pw=.55;break;case 208:t.pw=.3;break;default:t.pw=A.pw;break}return IN(t)};fEA.extend({}).transform(yEA);var $wt=t=>(t.legsoutside=!1,t.thermalpad===void 0&&(t.thermalpad=!0),IN(t)),ADt=uD({w:"3.9mm",p:"1.27mm"}),eDt=t=>{const A=ADt.parse(t);return{circuitJson:Dx(A),parameters:A}},tDt=uD({w:"7.1mm",p:"0.65mm",pl:"1.35mm",pw:"0.40mm",legsoutside:!0}),iDt=t=>{const A=tDt.parse(t);return{circuitJson:Dx(A),parameters:A}},oDt=uD({}),nDt=t=>{const A=oDt.parse({fn:"sot363",num_pins:6,w:2.56,p:.65,pw:.4,pl:.65,legoutside:!0});return{circuitJson:Dx(A),parameters:A}},sDt=Vi.extend({fn:N(),num_pins:CA(6).default(6),w:N().default("1.01mm"),h:N().default("1.45mm"),p:N().default("0.5mm"),pl:N().default("0.33mm"),pw:N().default("0.27mm"),string:N().optional()}),rDt=t=>{const A=sDt.parse({fn:"sot886",...t}),e=ee.parse(A.w),i=ee.parse(A.h),o=ee.parse(A.p),n=ee.parse(A.pl),s=ee.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=A7A(B+1,e,o,n);r.push(yi(B+1,C,Q,n,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:i/2},{x:e/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:-i/2},{x:e/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=A7A(1,e,o,n),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-n/2-.3,y:c.y},{x:c.x-n/2-.45,y:c.y+.15},{x:c.x-n/2-.45,y:c.y-.15},{x:c.x-n/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Zi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},A7A=(t,A,e,i)=>{const o=A/2-i/2;return t<=3?{x:-o,y:e-(t-1)*e}:{x:o,y:-e+(t-4)*e}},e7A=Vi.extend({fn:N(),num_pins:vA().default(3),w:N().default("1.92mm"),h:N().default("2.74mm"),pl:N().default("1.32mm"),pw:N().default("0.6mm"),p:N().default("0.95mm"),string:N().optional()}),aDt=uD({p:"0.95mm",w:"1.6mm",legsoutside:!0}),gDt=t=>{const A=t.string?.match(/^sot23_(\d+)/),e=A?Number.parseInt(A[1],10):3;if(e===6||e===8){const o=aDt.parse({...t,num_pins:e});return{circuitJson:Dx(o),parameters:o}}const i=e7A.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:IDt(i),parameters:i};if(i.num_pins===5)return{circuitJson:i7A(i),parameters:i};throw new Error("Invalid number of pins")},cDt=t=>{const{pn:A,p:e}=t;return A===1?{x:-1.155,y:e}:A===2?{x:-1.155,y:-e}:{x:1.15,y:0}},IDt=t=>{const A=[];for(let i=0;i<t.num_pins;i++){const{x:o,y:n}=cDt({num_pins:t.num_pins,pn:i+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(yi(i+1,o,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=Zi(0,Number.parseInt(t.h),.3);return[...A,e]},t7A=t=>{const{p:A,h:e,pn:i}=t;if(i===1)return{x:-e/2-.5,y:A};if(i===2)return{x:-e/2-.5,y:0};if(i===3)return{x:-e/2-.5,y:-A};if(i===4)return{x:e/2+.5,y:-A};if(i===5)return{x:e/2+.5,y:A};throw new Error("Invalid pin number")},i7A=t=>{const A=[];for(let I=1;I<=t.num_pins;I++){const{x:l,y:B}=t7A({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:I});A.push(yi(I,l,B,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=(t.num_pins+1)/2*Number.parseFloat(t.p),i=Number.parseFloat(t.h),o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e/3,y:i/2+Number.parseFloat(t.p)/1.3},{x:e/3,y:i/2+Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e/3,y:-i/2-Number.parseFloat(t.p)/1.3},{x:e/3,y:-i/2-Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Zi(0,i+.3,.3),r=t7A({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});r.x=r.x-Number.parseFloat(t.pw)*1.5;const a=.3,g=.4,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:r.x+a/2,y:r.y},{x:r.x-a/2,y:r.y+g/2},{x:r.x-a/2,y:r.y-g/2},{x:r.x+a/2,y:r.y}],stroke_width:.05};return[...A,s,o,n,c]},lDt=e7A.extend({}),BDt=t=>{const A=lDt.parse({...t,num_pins:5});return{circuitJson:i7A(A),parameters:A}},CDt=[{name:"top-left",dx:-1,dy:1},{name:"top-right",dx:1,dy:1},{name:"bottom-left",dx:-1,dy:-1},{name:"bottom-right",dx:1,dy:-1}],QDt=uD({}),hDt=t=>{const A=QDt.parse(t),e=[];for(let I=0;I<A.num_pins;I++){const{x:l,y:B}=pEA({num_pins:A.num_pins,pn:I+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});e.push(yi(I+1,l,B,A.pl??"1mm",A.pw??"0.6mm"))}const i=Math.min(1,A.p/2),o=A.w+i,n=(A.num_pins/2-1)*A.p+A.pw+i,s=[];for(const I of CDt){const{dx:l,dy:B}=I;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",route:[{x:l*o/2-l*A.p,y:B*n/2},{x:l*o/2,y:B*n/2},{x:l*o/2,y:B*n/2-B*A.p}],type:"pcb_silkscreen_path",stroke_width:.1})}const r=A.p/4,a=-o/2-r/2,g=n/2-A.p/2;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:a,y:g},{x:a-r,y:g+r},{x:a-r,y:g-r},{x:a,y:g}],stroke_width:.1});const c=Zi(0,n/2+.4,n/12);return{circuitJson:[...e,c,...s],parameters:A}},mEA=({fs:t,pn:A,anchor_x:e,anchor_y:i,textalign:o="center",orthogonal:n=!1,verticallyinverted:s=!1,layer:r="top"})=>{let a=0;n&&s?a=270:s?a=180:n?a=90:a=0;let g="center";return o==="left"&&(s?g="center_right":g="center_left"),o==="right"&&(s?g="center_left":g="center_right"),r==="bottom"&&(g==="center_left"?g="center_right":g==="center_right"&&(g="center_left")),{type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:t,pcb_component_id:"pcb_component_1",text:`{PIN${A}}`,layer:r,anchor_position:{x:e,y:i},anchor_alignment:g,ccw_rotation:a}};function EDt({pinlabeltextalignleft:t,pinlabeltextalignright:A,pinlabelorthogonal:e}){let i="top";return e?i="left":i="top",t&&(e?i="bottom":i="right"),A&&(e?i="top":i="left"),i}var uDt=Vi.extend({fn:N(),num_pins:vA().optional().default(6),rows:Ht([N(),vA()]).transform(t=>Number(t)).optional().default(1).describe("number of rows"),p:ee.default("0.1in").describe("pitch"),id:ee.default("1.0mm").describe("inner diameter"),od:ee.default("1.5mm").describe("outer diameter"),male:$A().optional().describe("for male pin headers"),female:$A().optional().describe("for female pin headers"),smd:$A().optional().describe("surface mount device"),surfacemount:$A().optional().describe("surface mount device (verbose)"),rightangle:$A().optional().describe("right angle"),pw:ee.optional().default("1.0mm").describe("pad width for SMD"),pl:ee.optional().default("2.0mm").describe("pad length for SMD"),pinlabeltextalignleft:$A().optional().default(!1),pinlabeltextaligncenter:$A().optional().default(!1),pinlabeltextalignright:$A().optional().default(!1),pinlabelverticallyinverted:$A().optional().default(!1),pinlabelorthogonal:$A().optional().default(!1),nosquareplating:$A().optional().default(!1).describe("do not use rectangular pad for pin 1"),nopinlabels:$A().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:$A().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:$A().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top")}).transform(t=>{const A=EDt(t);return{...t,pinlabelAnchorSide:A,male:t.male??!t.female,female:t.female??!1,smd:t.smd??t.surfacemount??!1,rightangle:t.rightangle??!1}}).superRefine((t,A)=>{t.male&&t.female&&A.addIssue({code:Ot.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),dDt=t=>{const A=uDt.parse(t),{p:e,id:i,od:o,rows:n,num_pins:s,pinlabelAnchorSide:r,pinlabelverticallyinverted:a,pinlabelorthogonal:g,pinlabeltextalignleft:c,pinlabeltextalignright:I,nopinlabels:l,doublesidedpinlabel:B,bottomsidepinlabel:C}=A;let Q="center";c?Q="left":I&&(Q="right");const h=[],E=Math.ceil(s/n),u=-e,d=({xoff:b,yoff:k,od:_,anchorSide:M,smd:v,pw:U,pl:J})=>{let Y=0,O=0;if(v){const Z=_/5;switch(M){case"right":Y=U/2+Z;break;case"top":O=J/2+Z;break;case"bottom":O=-(J/2+Z);break;case"left":Y=-(U/2+Z);break}}else{const Z=_*.75;switch(M){case"right":Y=Z;break;case"top":O=Z;break;case"bottom":O=-Z;break;case"left":Y=-Z;break}}return{anchor_x:b+Y,anchor_y:k+O}},f=(b,k,_)=>{A.smd?h.push(yi(b,k,_,A.pw,A.pl)):b===1&&!A.nosquareplating?h.push(lb(b,k,_,i,o,o,0,0)):h.push(As(b,k,_,i,o));const{anchor_x:M,anchor_y:v}=d({xoff:k,yoff:_,od:o,anchorSide:r,smd:A.smd,pw:A.pw,pl:A.pl});l||(C?h.push(mEA({fs:o/5,pn:b,anchor_x:M,anchor_y:v,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})):h.push(mEA({fs:o/5,pn:b,anchor_x:M,anchor_y:v,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"top"})),B&&h.push(mEA({fs:o/5,pn:b,anchor_x:M,anchor_y:v,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})))},m=new Set,D=n>2&&E>2;if(n===1){const b=-((s-1)/2)*e;for(let k=0;k<s;k++){const _=k+1,M=b+k*e,v=`${M},0`;if(m.has(v))throw new Error(`Overlap at ${v}`);m.add(v),f(_,M,0)}}else if(D){const b=-((E-1)/2)*e;let k=1;for(let _=0;_<n&&k<=s;_++)for(let M=0;M<E&&k<=s;M++){const v=b+M*e,U=_*u,J=`${v},${U}`;if(m.has(J))throw new Error(`Overlap at ${J}`);m.add(J),f(k++,v,U)}}else{const b=-((E-1)/2)*e;let k=1,_=0,M=n-1,v=0,U=E-1;for(;k<=s&&_<=M&&v<=U;){for(let J=_;J<=M&&k<=s;J++){const Y=b+v*e,O=J*u,Z=`${Y},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),f(k++,Y,O)}v++;for(let J=v;J<=U&&k<=s;J++){const Y=b+J*e,O=M*u,Z=`${Y},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),f(k++,Y,O)}if(M--,v<=U){for(let J=M;J>=_&&k<=s;J--){const Y=b+U*e,O=J*u,Z=`${Y},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),f(k++,Y,O)}U--}if(_<=M){for(let J=U;J>=v&&k<=s;J--){const Y=b+J*e,O=_*u,Z=`${Y},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),f(k++,Y,O)}_++}}if(k-1<s)throw new Error(`Missing pins: assigned ${k-1}, expected ${s}`)}const w=Zi(0,e,.5);return{circuitJson:[...h,w],parameters:A}},pDt=Vi.extend({fn:N(),num_pins:CA(6).default(6),w:N().default("2.1mm"),h:N().default("2.45mm"),p:N().default("0.5mm"),pl:N().default("0.675mm"),pw:N().default("0.35mm"),string:N().optional()}),fDt=t=>{const A=pDt.parse({...t,fn:"sot563"}),e=ee.parse(A.w),i=ee.parse(A.h),o=ee.parse(A.p),n=ee.parse(A.pl),s=ee.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=o7A(B+1,e,o,n);r.push(yi(B+1,C,Q,n,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:i/2},{x:e/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:-i/2},{x:e/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=o7A(1,e,o,n),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-n/2-.3,y:c.y},{x:c.x-n/2-.45,y:c.y+.15},{x:c.x-n/2-.45,y:c.y-.15},{x:c.x-n/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Zi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},o7A=(t,A,e,i)=>{const o=A/2-i/2;return t<=3?{x:-o,y:e-(t-1)*e}:{x:o,y:-e+(t-4)*e}},yDt=uD({p:"1.27mm",w:"3.9mm",legsoutside:!0}),mDt=t=>{const A=yDt.parse({...t,num_pins:8});return{circuitJson:Dx(A),parameters:A}},wDt=uD({p:"1.27mm",w:"7.5mm",legsoutside:!0}),DDt=t=>{const A=wDt.parse({...t,num_pins:16});return{circuitJson:Dx(A),parameters:A}},SDt=Vi.extend({fn:N(),num_pins:CA(3).default(3),w:N().default("1.2mm"),h:N().default("1.2mm"),pw:N().default("0.40mm"),pl:N().default("0.45mm"),p:N().default("0.575mm")}),bDt=t=>{const A=SDt.parse(t),e=xDt(A),i=Zi(0,ee.parse(A.h),.2);return{circuitJson:[...e,i],parameters:A}},_Dt=t=>{const{pn:A,p:e}=t;return A===1?{x:e,y:0}:A===2?{x:-e,y:-.4}:{x:-e,y:.4}},xDt=t=>{const A=[];for(let e=0;e<3;e++){const{x:i,y:o}=_Dt({num_pins:t.num_pins,pn:e+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(yi(e+1,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},kDt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("2.36mm"),h:N().default("1.22mm"),pl:N().default("0.9mm"),pw:N().default("1.2mm"),p:N().default("3.30mm")}),FDt=t=>{const A=kDt.parse(t),e=Zi(0,ee.parse(A.h)/4+.4,.3);return{circuitJson:RDt(A).concat(e),parameters:A}},GDt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},RDt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=GDt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},vDt=Vi.extend({fn:N(),p:ee.optional().default("2.54mm"),id:ee.optional().default("0.7mm"),od:ee.optional().default("1.4mm")}),MDt=t=>{const A=vDt.parse(t),{p:e,id:i,od:o}=A,n=[As(1,-e/2,0,i,o),As(2,e/2,0,i,o)],s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2+o+i/2,y:0},{x:e/2-o-i/2,y:0}],stroke_width:.1,pcb_silkscreen_path_id:""},r=Zi(0,1.5,.5);return{circuitJson:[...n,s,r],parameters:A}},NDt=(t,A,e,i,o,n=.1)=>{const s=[],r=[],a=Math.max(1,Math.ceil(Math.PI*e/n)),g=Math.PI/a;for(let c=0;c<=a;c++){const I=c*g,l=t+Math.cos(I)*e,B=A+Math.sin(I)*e;l<t-i&&B>=A-o/2&&B<=A+o/2||s.push({x:l,y:B})}for(let c=0;c<=a;c++){const I=Math.PI+c*g,l=t+Math.cos(I)*e,B=A+Math.sin(I)*e;l<t-i&&B>=A-o/2&&B<=A+o/2||r.push({x:l,y:B})}return{topArc:s,bottomArc:r}},LDt=Vi.extend({fn:N(),p:ee.optional().default("5mm"),id:ee.optional().default("0.8mm"),od:ee.optional().default("1.6mm"),ceramic:$A().optional(),electrolytic:$A().optional(),polarized:$A().optional()}),UDt=t=>{const A=LDt.parse(t),{p:e,id:i,od:o}=A;i===.8&&o===1.6&&(A.id=e===5?.8:e*.25,A.od=e===5?1.6:e*.5);const n=[As(1,-e/2,0,A.id,A.od),As(2,e/2,0,A.id,A.od)],s=e+.1,{topArc:r,bottomArc:a}=NDt(0,0,s,A.od/2,A.od),g=.02*e,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:r,stroke_width:g,pcb_silkscreen_path_id:""},I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:g,pcb_silkscreen_path_id:""},l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:s},{x:0,y:-s}],stroke_width:g,pcb_silkscreen_path_id:""},B=.1*e,C=-(e+B+.04*e),Q=s-B-.08*e,h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:C-B,y:Q},{x:C+B,y:Q}],stroke_width:g,pcb_silkscreen_path_id:""},E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:C,y:Q-B},{x:C,y:Q+B}],stroke_width:g,pcb_silkscreen_path_id:""},u=Zi(0,s+.12*e,.1*e),d=[...n,c,I,l,u];return(A.electrolytic===!0||A.polarized===!0)&&d.push(h,E),{circuitJson:d,parameters:A}},OW=(t,A={})=>({type:"pcb_silkscreen_path",layer:A.layer||"top",pcb_component_id:A.pcb_component_id||"",pcb_silkscreen_path_id:A.pcb_silkscreen_path_id||"",route:t,stroke_width:A.stroke_width||.1}),HDt=Vi.extend({fn:CA("pushbutton"),w:ee.default(4.5),h:ee.default(6.5),id:ee.default(1),od:ee.default(1.2)}),YDt=t=>{const A=HDt.parse(t),e=A.w,i=A.h,o=A.id,n=[As(1,-e/2,i/2,o,o*1.5),As(2,-e/2,-i/2,o,o*1.5),As(3,e/2,-i/2,o,o*1.5),As(4,e/2,i/2,o,o*1.5)],s=[OW([{x:-e/2,y:-i/2},{x:-e/2,y:i/2}]),OW([{x:e/2,y:-i/2},{x:e/2,y:i/2}]),OW([{x:-e/2,y:0},{x:-e/5,y:0},{x:e/5*1/Math.sqrt(2),y:i/8}]),OW([{x:e/2,y:0},{x:e/5,y:0}])],r=Zi(0,i/2+.4,.5);return{circuitJson:[...n,...s,r],parameters:A}},n7A=Vi.extend({fn:N(),w:ee.default("22.58mm"),h:ee.optional(),left:ee.optional().default(20),right:ee.optional().default(20),top:ee.optional().default(2),bottom:ee.optional().default(2),p:ee.default(ee.parse("2.54mm")),pw:ee.default(ee.parse("1.6mm")),pl:ee.default(ee.parse("2.4mm")),innerhole:$A().default(!1),innerholeedgedistance:ee.default(ee.parse("1.61mm")),silkscreenlabels:$A().default(!1),silkscreenlabelmargin:ee.default(ee.parse("0.1mm"))}),JDt=t=>{const A=n7A.parse(t);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},WW=(t,A,e)=>{let i=[];return e==="right"&&(i=[{x:t+1/2,y:A},{x:t-1/2,y:A+.6/2},{x:t-1/2,y:A-.6/2},{x:t+1/2,y:A}]),e==="left"&&(i=[{x:t-1/2,y:A},{x:t+1/2,y:A+.6/2},{x:t+1/2,y:A-.6/2},{x:t-1/2,y:A}]),e==="top"&&(i=[{x:t,y:A+1/2},{x:t-.6/2,y:A-1/2},{x:t+.6/2,y:A-1/2},{x:t,y:A+1/2}]),e==="bottom"&&(i=[{x:t,y:A-1/2},{x:t-.6/2,y:A+1/2},{x:t+.6/2,y:A+1/2},{x:t,y:A-1/2}]),i},TDt=t=>{const A=n7A.parse(t),e=A.h??JDt(A),i=[],o=[],n=[];let s=[];const r=1,a=r,g=A.left+A.right+(A.bottom??0)+(A.top??0),I=`pin${g}`.length*.7/2;if(A.right){const Q=-((A.right-1)/2)*A.p;for(let h=0;h<A.right;h++){if(h===0&&!A.left&&!A.bottom&&!A.silkscreenlabels&&(s=WW(A.w/2-A.pl*1.4,Q+h*A.p,"right")),i.push(yi(h+1+A.left+(A.bottom??0),A.w/2-A.pl/2,Q+h*A.p,A.pl,A.pw)),A.silkscreenlabels){const E=h+1+A.left+(A.bottom??0),u=`pin${E}`;n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:A.w/2-A.pl-(I+A.silkscreenlabelmargin),y:Q+h*A.p},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}A.innerhole&&(o.push(As(h+1+A.left+(A.bottom??0)+g,A.w/2,Q+h*A.p,r,a)),o.push(As(h+1+A.left+(A.bottom??0)+g*2,A.w/2-A.innerholeedgedistance,Q+h*A.p,r,a)))}}if(A.left){const Q=(A.left-1)/2*A.p;for(let h=0;h<A.left;h++){if(h===0&&!A.silkscreenlabels&&(s=WW(-A.w/2+A.pl*1.4,Q-h*A.p,"left")),i.push(yi(h+1,-A.w/2+A.pl/2,Q-h*A.p,A.pl,A.pw)),A.silkscreenlabels){const E=h+1,u=`pin${E}`;n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-A.w/2+A.pl+(I+A.silkscreenlabelmargin),y:Q-h*A.p},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}A.innerhole&&(o.push(As(h+1+g,-A.w/2,Q-h*A.p,r,a)),o.push(As(h+1+g*2,-A.w/2+A.innerholeedgedistance,Q-h*A.p,r,a)))}}if(A.top){const Q=(A.top-1)/2*A.p;for(let h=0;h<A.top;h++){if(h===0&&!A.left&&!A.bottom&&!A.right&&!A.silkscreenlabels&&(s=WW(Q-h*A.p,e/2-A.pl*1.4,"top")),i.push(yi(h+1+A.left+A.right+(A.bottom??0),Q-h*A.p,e/2-A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const E=h+1+A.left+A.right+(A.bottom??0),u=`pin${E}`;n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:Q-h*A.p,y:e/2-A.pl-(I+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:270})}A.innerhole&&(o.push(As(h+1+A.left+A.right+(A.bottom??0)+g,Q-h*A.p,e/2,r,a)),o.push(As(h+1+A.left+A.right+(A.bottom??0)+g*2,Q-h*A.p,e/2-A.innerholeedgedistance,r,a)))}}if(A.bottom){const Q=-((A.bottom-1)/2)*A.p;for(let h=0;h<A.bottom;h++){if(h===0&&!A.left&&!A.silkscreenlabels&&(s=WW(Q+h*A.p,-e/2+A.pl*1.4,"bottom")),i.push(yi(h+1+A.left,Q+h*A.p,-e/2+A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const E=h+1+A.left,u=`pin${E}`;n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:Q+h*A.p,y:-e/2+A.pl+(I+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:90})}A.innerhole&&(o.push(As(h+1+A.left+g,Q+h*A.p,-e/2,r,a)),o.push(As(h+1+A.left+g*2,Q+h*A.p,-e/2+A.innerholeedgedistance,r,a)))}}const l={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_triangle_1",pcb_component_id:"2",route:s,stroke_width:.1,layer:"top"},B={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2,y:e/2},{x:A.w/2,y:e/2},{x:A.w/2,y:-e/2},{x:-A.w/2,y:-e/2},{x:-A.w/2,y:e/2}],stroke_width:.1,layer:"top"},C=Zi(0,e/1.8,e/25);return{circuitJson:[...i,...o,...n,B,...A.silkscreenlabels?[]:[l],C],parameters:A}},s7A=Vi.extend({fn:N(),w:ee.default("22.58mm"),h:ee.optional(),left:ee.optional().default(20),right:ee.optional().default(20),top:ee.optional().default(2),bottom:ee.optional().default(2),p:ee.default(ee.parse("2.54mm")),pw:ee.default(ee.parse("1.6mm")),pl:ee.default(ee.parse("3.2mm")),innerhole:$A().default(!1),innerholeedgedistance:ee.default(ee.parse("1.61mm"))}),KDt=t=>{const A=s7A.parse(t);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},PDt=(t,A,e,i=1,o=.6)=>{const n=i/2,s=o/2;return{left:[{x:t+n,y:A},{x:t-n,y:A+s},{x:t-n,y:A-s},{x:t+n,y:A}],right:[{x:t-n,y:A},{x:t+n,y:A+s},{x:t+n,y:A-s},{x:t-n,y:A}],top:[{x:t,y:A-n},{x:t-s,y:A+n},{x:t+s,y:A+n},{x:t,y:A-n}],bottom:[{x:t,y:A+n},{x:t-s,y:A-n},{x:t+s,y:A-n},{x:t,y:A+n}]}[e]},qDt=t=>{const A=s7A.parse(t),e=A.h??KDt(A),i=[],o=[],n=[],s=1,r=1.2,a=A.left+A.right+(A.bottom??0)+(A.top??0);let g=[],c=1;if(A.left){const C=(A.left-1)/2*A.p;for(let Q=0;Q<A.left;Q++)Q===0&&(g=PDt(-A.w/2-A.pl/2,C-Q*A.p,"left")),i.push(yi(c,-A.w/2+A.pl/2,C-Q*A.p,A.pl,A.pw)),o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-A.w/2+A.pl/2-4.5,y:C-Q*A.p},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&n.push(As(c+a,-A.w/2+A.innerholeedgedistance,C-Q*A.p,s,r))}if(A.bottom){const C=(A.bottom-1)/2*A.p;for(let Q=A.bottom-1;Q>=0;Q--)i.push(yi(c,C-Q*A.p,-e/2+A.pl/2,A.pw,A.pl)),o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:C-Q*A.p,y:-e/2+A.pl/2-3.2},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&n.push(As(c+a,C-Q*A.p,-e/2+A.innerholeedgedistance,s,r))}if(A.right){const C=-((A.right-1)/2)*A.p;for(let Q=0;Q<A.right;Q++)i.push(yi(c,A.w/2-A.pl/2,C+Q*A.p,A.pl,A.pw)),o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:A.w/2-A.pl/2+3.7,y:C+Q*A.p},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&n.push(As(c+a,A.w/2-A.innerholeedgedistance,C+Q*A.p,s,r))}if(A.top){const C=-((A.top-1)/2)*A.p;for(let Q=A.top-1;Q>=0;Q--)i.push(yi(c,C+Q*A.p,e/2-A.pl/2,A.pw,A.pl)),o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:C+Q*A.p,y:e/2-A.pl/2+3.2},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&n.push(As(c+a,C+Q*A.p,e/2-A.innerholeedgedistance,s,r))}const I={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"1",pcb_component_id:"1",layer:"top",route:g,stroke_width:.1},l={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2-A.pl/3,y:e/2+A.pl/3},{x:A.w/2+A.pl/3,y:e/2+A.pl/3},{x:A.w/2+A.pl/3,y:-e/2-A.pl/3},{x:-A.w/2-A.pl/3,y:-e/2-A.pl/3},{x:-A.w/2-A.pl/3,y:e/2+A.pl/3}],stroke_width:.1,layer:"top"},B=Zi(0,e/1.8,e/25);return{circuitJson:[...n,...i,...o,l,I,B],parameters:A}},ODt=t=>(t.legsoutside=!0,t.pl||(t.pl=1.5),t.pw||(t.pw=.3),IN(t)),r7A=Vi.extend({fn:N(),w:ee.default("10mm"),h:ee.optional(),left:ee.optional().default(20),right:ee.optional().default(20),top:ee.optional().default(0),bottom:ee.optional().default(0),p:ee.default(ee.parse("2.54mm")),id:ee.optional().default(ee.parse("1mm")),od:ee.optional().default(ee.parse("1.5mm"))}),WDt=t=>{const A=r7A.parse(t);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},ZW=(t,A,e,i=1,o=.6)=>{const n=i/2,s=o/2;return{left:[{x:t+n,y:A},{x:t-n,y:A+s},{x:t-n,y:A-s},{x:t+n,y:A}],right:[{x:t-n,y:A},{x:t+n,y:A+s},{x:t+n,y:A-s},{x:t-n,y:A}],top:[{x:t,y:A-n},{x:t-s,y:A+n},{x:t+s,y:A+n},{x:t,y:A-n}],bottom:[{x:t,y:A+n},{x:t-s,y:A-n},{x:t+s,y:A-n},{x:t,y:A+n}]}[e]},ZDt=t=>{const A=r7A.parse(t),e=A.h??WDt(A),i=[],o=A.id,n=A.od;let s=[];if(A.right){const c=-((A.right-1)/2)*A.p;for(let I=0;I<A.right;I++)I===0&&!A.left&&!A.bottom&&(s=ZW(A.w/2+n*1.4,c+I*A.p,"right")),i.push(As(I+1+A.left+(A.bottom??0),A.w/2,c+I*A.p,o,n))}if(A.left){const c=-((A.left-1)/2)*A.p;for(let I=0;I<A.left;I++)I===A.left-1&&(s=ZW(-A.w/2-n*1.4,c+I*A.p,"left")),i.push(As(I+1,-A.w/2,c+I*A.p,o,n))}if(A.top){const c=-((A.top-1)/2)*A.p;for(let I=0;I<A.top;I++)I===A.top-1&&!A.left&&!A.bottom&&!A.right&&(s=ZW(c+I*A.p,e/2+n*1.4,"top")),i.push(As(I+1+A.right+(A.bottom??0)+A.left,c+I*A.p,e/2,o,n))}if(A.bottom){const c=-((A.bottom-1)/2)*A.p;for(let I=0;I<A.bottom;I++)I===0&&!A.left&&(s=ZW(c+I*A.p,-e/2-n*1.4,"bottom")),i.push(As(I+1+A.left,c+I*A.p,-e/2,o,n))}const r={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"1",pcb_component_id:"1",layer:"top",route:s,stroke_width:.1},a={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2-n,y:e/2+n},{x:A.w/2+n,y:e/2+n},{x:A.w/2+n,y:-e/2-n},{x:-A.w/2-n,y:-e/2-n},{x:-A.w/2-n,y:e/2+n}],stroke_width:.1,layer:"top"},g=Zi(0,e/1.7,e/25);return{circuitJson:[...i,a,g,r],parameters:A}},a7A=(t,A,e,i)=>Array.from({length:25},(o,n)=>{const s=n/24*Math.PI-Math.PI/2;return{x:t+(i==="right"?1:-1)*Math.cos(s)*e,y:A+Math.sin(s)*e}}),VDt=Vi.extend({fn:N(),p:ee.optional().default("4.88mm"),id:ee.optional().default("0.8mm"),od:ee.optional().default("1.5mm"),w:ee.optional().default("5.6mm"),h:ee.optional().default("3.5mm")}),jDt=t=>{const A=VDt.parse(t),{p:e,id:i,od:o,w:n,h:s}=A,r=s/2,a=[As(1,-e/2,0,i,o),As(2,e/2,0,i,o)],g=a7A(-n/2,0,r,"left"),c=a7A(n/2,0,r,"right"),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...g,...g.slice(1).reverse(),{x:-n/2,y:-s/2},{x:n/2,y:-s/2},...c,{x:n/2,y:s/2},{x:-n/2,y:s/2}],stroke_width:.1,pcb_silkscreen_path_id:""},l=Zi(0,e/4,.5);return{circuitJson:[...a,I,l],parameters:A}};Vi.extend({w:ee,h:ee});var zDt=t=>{const{w:A,h:e}=t,i=vr(A),o=vr(e);return{circuitJson:[yi(1,0,0,i,o),Zi(0,o/2+.5,.2)],parameters:t}},kH=(t,A,e,i,o,n)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"pill",x:A,y:e,outer_width:vr(o),outer_height:vr(n),hole_width:vr(i),hole_height:vr(i),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()],ccw_rotation:0}),XDt=Vi.extend({fn:N(),num_pins:Ht([CA(3),CA(2)]).default(3),p:N().default("1.27mm"),id:N().default("0.72mm"),od:N().default("0.95mm"),w:N().default("4.5mm"),h:N().default("4.5mm"),inline:$A().default(!1),string:N().optional()}),$Dt=(t,A,e)=>Array.from({length:25},(i,o)=>{const n=o/24*Math.PI;return{x:t+Math.cos(n)*e,y:A+Math.sin(n)*e}}),ASt=t=>{const A=t.string?.match(/^to92_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=XDt.parse({...t,num_pins:e}),{p:o,id:n,od:s,w:r,h:a,inline:g}=i,c=Number.parseFloat(a)/2,I=Number.parseFloat(o),l=Number.parseFloat(n),B=Number.parseFloat(s),C=B,Q=B*(1.5/1.05);let h=[];if(i.num_pins===3)g?h=[lb(1,-I,c-I,l,B,Q,0,0),kH(2,0,c-I,l,C,Q),kH(3,I,c-I,l,C,Q)]:h=[lb(1,-I,c-I,l,B,B,0,0),As(2,0,c,l,B),As(3,I,c-I,l,B)];else if(i.num_pins===2)h=[lb(1,-I,c-I,l,C,Q,0,0),kH(2,I,c-I,l,C,Q)];else throw new Error("Invalid number of pins for TO-92");const E=Number.parseFloat(r)/2,u=$Dt(0,c,E),d={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...u,{x:-E,y:0},{x:E,y:0},u[0]],stroke_width:.1,pcb_silkscreen_path_id:""},f=Zi(0,c+1,.5);return{circuitJson:[...h,d,f],parameters:i}},eSt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("2.15mm"),h:N().default("1.20mm"),pl:N().default("0.5mm"),pw:N().default("0.6mm"),p:N().default("1.4mm")}),tSt=t=>{const A=eSt.parse(t),e=Zi(0,ee.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:oSt(A).concat(i,e),parameters:A}},iSt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},oSt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=iSt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},nSt=uD({}),sSt=t=>{const A=nSt.parse(t),e=[];for(let s=0;s<A.num_pins;s++){const{x:r,y:a}=pEA({num_pins:A.num_pins,pn:s+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});e.push(yi(s+1,r,a,A.pl??"1.5mm",A.pw??"0.6mm"))}const i=(A.num_pins/2-1)*A.p+A.pw,o=Zi(0,i/2-.5,i/12),n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-A.w/3,y:i/2+.2},{x:A.w/3,y:i/2+.2}],stroke_width:.1};return{circuitJson:[...e,o,n],parameters:A}},rSt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("5.0mm"),h:N().default("2.30mm"),pl:N().default("1.25mm"),pw:N().default("2mm"),p:N().default("3.75mm")}),aSt=t=>{const A=rSt.parse(t),e=Zi(0,ee.parse(A.h)/2+1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2+.5,y:ee.parse(A.h)/2+.5},{x:-ee.parse(A.w)/2-.5,y:ee.parse(A.h)/2+.5},{x:-ee.parse(A.w)/2-.5,y:-ee.parse(A.h)/2-.5},{x:ee.parse(A.p)/2+.5,y:-ee.parse(A.h)/2-.5}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:cSt(A).concat(i,e),parameters:A}},gSt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},cSt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=gSt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},ISt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("4.4mm"),h:N().default("2.1mm"),pl:N().default("1.2mm"),pw:N().default("1.2mm"),p:N().default("2.9mm")}),lSt=t=>{const A=ISt.parse(t),e=Zi(0,ee.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:CSt(A).concat(i,e),parameters:A}},BSt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},CSt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=BSt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},QSt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("3.30mm"),h:N().default("1.80mm"),pl:N().default("0.60mm"),pw:N().default("0.45mm"),p:N().default("2.1mm")}),hSt=t=>{const A=QSt.parse(t),e=Zi(0,ee.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:uSt(A).concat(i,e),parameters:A}},ESt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},uSt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=ESt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},dSt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("1.4mm"),h:N().default("0.9mm"),pl:N().default("0.36mm"),pw:N().default("0.25mm"),p:N().default("0.85mm")}),pSt=t=>{const A=dSt.parse(t),e=Zi(0,ee.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2+.15,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.15,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.15,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2+.15,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:ySt(A).concat(i,e),parameters:A}},fSt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},ySt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=fSt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},mSt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("1.3mm"),h:N().default("0.9mm"),pl:N().default("0.4mm"),pw:N().default("0.7mm"),p:N().default("0.7mm")}),wSt=t=>{const A=mSt.parse(t),e=Zi(0,ee.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2+.2,y:ee.parse(A.h)/2+.2},{x:-ee.parse(A.w)/2-.2,y:ee.parse(A.h)/2+.2},{x:-ee.parse(A.w)/2-.2,y:-ee.parse(A.h)/2-.2},{x:ee.parse(A.p)/2+.2,y:-ee.parse(A.h)/2-.2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:SSt(A).concat(i,e),parameters:A}},DSt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},SSt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=DSt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},bSt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("3,05mm"),h:N().default("1.65mm"),pl:N().default("0.6mm"),pw:N().default("0.6mm"),pad_spacing:N().default("2.2mm")}),_St=t=>{const A=bSt.parse(t),e=Zi(0,ee.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.pad_spacing)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:-ee.parse(A.h)/2},{x:ee.parse(A.pad_spacing)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:kSt(A).concat(i,e),parameters:A}},xSt=t=>{const{pn:A,pad_spacing:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},kSt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=xSt({pn:e,pad_spacing:Number.parseFloat(t.pad_spacing)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},FSt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("4.4mm"),h:N().default("2.1mm"),pl:N().default("1.2mm"),pw:N().default("1.2mm"),p:N().default("2.9mm")}),GSt=t=>{const A=FSt.parse(t),e=Zi(0,ee.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:vSt(A).concat(i,e),parameters:A}},RSt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},vSt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=RSt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},MSt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("4.4mm"),h:N().default("2.1mm"),pl:N().default("0.91mm"),pw:N().default("1.22mm"),p:N().default("3.146mm")}),NSt=t=>{const A=MSt.parse(t),e=Zi(0,ee.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:USt(A).concat(i,e),parameters:A}},LSt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},USt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=LSt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},HSt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("1.80mm"),h:N().default("1.00mm"),pl:N().default("0.66mm"),pw:N().default("0.5mm"),p:N().default("0.8mm")}),YSt=t=>{const A=HSt.parse(t),e=Zi(0,ee.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.1,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.1,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:TSt(A).concat(i,e),parameters:A}},JSt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},TSt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=JSt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},KSt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("6.2mm"),h:N().default("3.4mm"),pl:N().default("1.4mm"),pw:N().default("2.1mm"),p:N().default("4.4mm")}),PSt=t=>{const A=KSt.parse(t),e=Zi(0,ee.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:OSt(A).concat(i,e),parameters:A}},qSt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},OSt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=qSt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},WSt=Vi.extend({fn:N(),num_pins:Ht([CA(3),CA(5)]).default(3),w:N().default("4.20mm"),h:N().default("4.80mm"),pl:N().default("1.3mm"),pw:N().default("0.9mm"),p:N().default("1.5mm"),string:N().optional()}),ZSt=t=>{const A=[],e=Number.parseFloat(t.p),i=Number.parseFloat(t.pw),o=Number.parseFloat(t.w),n=Number.parseFloat(t.pl),s=.175,r=(n-(n+s))/2;A.push(yi(1,-o/2+r,e,n,i),yi(2,-o/2,0,n+s,i),yi(3,-o/2+r,-e,n,i));const a=Zi(0,0,.3),g=Number.parseFloat(t.w)/2-1,c=Number.parseFloat(t.h)/2,I={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-g,y:c},{x:g,y:c},{x:g,y:c/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},l={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-g,y:-c},{x:g,y:-c},{x:g,y:-c/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,I,l,a]},VSt=t=>{const A=[];Number.parseFloat(t.p),Number.parseFloat(t.pw),Number.parseFloat(t.w),A.push(yi(1,-1.85,-1.5,1.5,.7),yi(2,-1.85,1.5,1.5,.7),yi(3,0,0,.8,2),yi(4,1.85,-1.5,1.5,.7),yi(5,1.85,1.5,1.5,.7));const e=Zi(0,Number.parseFloat(t.h)/2+.5,.3),i=Number.parseFloat(t.w)/2-1,o=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:o},{x:i,y:o}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-o},{x:i,y:-o}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,n,s,e]},jSt=t=>{const A=t.string?.match(/^sot89_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=WSt.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:ZSt(i),parameters:i};if(i.num_pins===5)return{circuitJson:VSt(i),parameters:i};throw new Error("Invalid number of pins for SOT89")},zSt=Vi.extend({fn:N(),p:ee.optional().default("5.0mm"),id:ee.optional().default("1.0mm"),od:ee.optional().default("1.9mm"),w:ee.optional().default("13mm"),h:ee.optional().default("7mm"),num_pins:vA().optional(),string:N().optional()}),XSt=t=>{const A=zSt.parse(t),{fn:e,id:i,od:o,w:n,h:s,string:r}=A,a=Number.parseInt(r?.split("_")[1]??"3"),g=-1,c=n/2,I=s/2,l=2.5,B=n*.4,C=Math.max(l,B/(a-1)),Q=Array.from({length:a},(m,D)=>{const w=a%2===0?(D-a/2+.5)*C:(D-Math.floor(a/2))*C;return As(D+1,w,g,i,o)}),h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c,y:-I},{x:c,y:-I},{x:c,y:I},{x:-c,y:I},{x:-c,y:-I}],stroke_width:.1,pcb_silkscreen_path_id:""},E=-I+2*s/3,u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c,y:E},{x:c,y:E}],stroke_width:.1,pcb_silkscreen_path_id:""},d=[{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/6,y:E},{x:-n/6,y:I}],stroke_width:.1,pcb_silkscreen_path_id:""},{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:n/6,y:E},{x:n/6,y:I}],stroke_width:.1,pcb_silkscreen_path_id:""}],f=Zi(0,s/2+.6,.5);return{circuitJson:[...Q,h,u,...d,f],parameters:{...A,p:C}}},$St=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("5.40mm"),h:N().default("2.30mm"),pl:N().default("1.30mm"),pw:N().default("1.70mm"),p:N().default("3.5mm")}),Abt=t=>{const A=$St.parse(t),e=Zi(0,ee.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:tbt(A).concat(i,e),parameters:A}},ebt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},tbt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=ebt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},ibt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("1.90mm"),h:N().default("1.33mm"),pl:N().default("0.5mm"),pw:N().default("0.7mm"),p:N().default("0.8mm")}),obt=t=>{const A=ibt.parse(t),e=Zi(0,ee.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2+.1,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2+.1,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:sbt(A).concat(i,e),parameters:A}},nbt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},sbt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=nbt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},rbt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("7.0mm"),h:N().default("3.35mm"),pl:N().default("1.50mm"),pw:N().default("2.70mm"),p:N().default("4.8mm")}),abt=t=>{const A=rbt.parse(t),e=Zi(0,ee.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:cbt(A).concat(i,e),parameters:A}},gbt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},cbt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=gbt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Ibt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("3.0mm"),h:N().default("1.80mm"),pl:N().default("0.80mm"),pw:N().default("1.20mm"),p:N().default("1.6mm")}),lbt=t=>{const A=Ibt.parse(t),e=Zi(0,ee.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.1,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.1,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Cbt(A).concat(i,e),parameters:A}},Bbt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Cbt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=Bbt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Qbt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("7.10mm"),h:N().default("3.40mm"),pl:N().default("2.45mm"),pw:N().default("1.80mm"),p:N().default("4.05mm")}),hbt=t=>{const A=Qbt.parse(t),e=Zi(0,ee.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.5,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.5,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:ubt(A).concat(i,e),parameters:A}},Ebt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},ubt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=Ebt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},dbt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("4.80mm"),h:N().default("2.10mm"),pl:N().default("1.30mm"),pw:N().default("1.40mm"),p:N().default("2.9mm")}),pbt=t=>{const A=dbt.parse(t),e=Zi(0,ee.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:ybt(A).concat(i,e),parameters:A}},fbt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},ybt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=fbt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},mbt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("7.30mm"),h:N().default("4.40mm"),pl:N().default("2.50mm"),pw:N().default("2.30mm"),p:N().default("4.30mm")}),wbt=t=>{const A=mbt.parse(t),e=Zi(0,ee.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.1,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.1,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Sbt(A).concat(i,e),parameters:A}},Dbt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Sbt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=Dbt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},bbt=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("10.70mm"),h:N().default("6.60mm"),pl:N().default("3.30mm"),pw:N().default("2.50mm"),p:N().default("6.80mm")}),_bt=t=>{const A=bbt.parse(t),e=Zi(0,3,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2-.8},{x:-ee.parse(A.w)/2-.8,y:ee.parse(A.h)/2-.8},{x:-ee.parse(A.w)/2-.8,y:-ee.parse(A.h)/2+.8},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2+.8}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:kbt(A).concat(i,e),parameters:A}},xbt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},kbt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=xbt({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Fbt=Vi.extend({fn:N(),num_pins:vA().default(4),w:N().default("8.50mm"),h:N().default("6.90mm"),pl:N().default("2mm"),pw:N().default("1.5mm"),p:N().default("2.30mm"),string:N().optional()}),Gbt=t=>{const A=t.string?.match(/^sot223_(\d+)/),e=A?Number.parseInt(A[1],10):4;if(e===8){const o=Mbt.parse({...t,num_pins:e});return{circuitJson:Dx(o),parameters:o}}const i=Fbt.parse({...t,num_pins:e});if(i.num_pins===4)return{circuitJson:vbt(i),parameters:i};if(i.num_pins===5)return{circuitJson:Lbt(i),parameters:i};if(i.num_pins===6)return{circuitJson:Hbt(i),parameters:i};throw new Error("Invalid number of pins")},Rbt=t=>{const{pn:A,w:e,p:i}=t;return A===1?{x:-e/2+1.1,y:i}:A===2?{x:-e/2+1.1,y:0}:A===3?{x:-e/2+1.1,y:-i}:{x:e/2-1.1,y:0}},vbt=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=Rbt({num_pins:t.num_pins,pn:r+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)}),c=r===3?3.8:Number.parseFloat(t.pw);A.push(yi(r+1,a,g,Number.parseFloat(t.pl),c))}const e=Zi(0,0,.3),i=Number.parseFloat(t.w)/2-2.4,o=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:o},{x:i,y:o},{x:i,y:o/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-o},{x:i,y:-o},{x:i,y:-o/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,n,s,e]},Mbt=uD({p:"0.90mm",w:"2.8mm",legsoutside:!0}),Nbt=t=>{const{p:A,pn:e,w:i}=t;if(e===1)return{x:-i/2+1.2,y:A/2+A};if(e===2)return{x:-i/2+1.2,y:A/2};if(e===3)return{x:-i/2+1.2,y:-A/2};if(e===4)return{x:-i/2+1.2,y:-A/2-A};if(e===5)return{x:i/2-1,y:0};throw new Error("Invalid pin number")},Lbt=t=>{const A=[];for(let r=1;r<=t.num_pins;r++){const{x:a,y:g}=Nbt({h:Number.parseFloat(t.h),p:1.5,pn:r,w:Number.parseFloat(t.w)});let c=Number.parseFloat(t.pw),I=Number.parseFloat(t.pl);r===5?(c=3.4,I=1.8):(c=1,I=2.2),A.push(yi(r,a,g,I,c))}const e=Number.parseFloat(t.w)/2-2.4,i=Number.parseFloat(t.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e,y:i},{x:e,y:i},{x:e,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e,y:-i},{x:e,y:-i},{x:e,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Zi(0,0,.3);return[...A,o,n,s]},Ubt=t=>{const{p:A,pn:e,w:i}=t;if(e===1)return{x:-i/2+1.2,y:2*A};if(e===2)return{x:-i/2+1.2,y:A};if(e===3)return{x:-i/2+1.2,y:0};if(e===4)return{x:-i/2+1.2,y:-A};if(e===5)return{x:-i/2+1.2,y:-2*A};if(e===6)return{x:i/2-1.175,y:0};throw new Error("Invalid pin number")},Hbt=t=>{const A=[];for(let r=1;r<=t.num_pins;r++){const{x:a,y:g}=Ubt({h:Number.parseFloat(t.h),p:1.3,pn:r,w:8.7});let c=Number.parseFloat(t.pw),I=Number.parseFloat(t.pl);r===6?(c=3.4,I=2.15):(c=.6,I=2.2),A.push(yi(r,a,g,I,c))}const e=Number.parseFloat(t.w)/2-2.4,i=Number.parseFloat(t.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e,y:i},{x:e,y:i},{x:e,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e,y:-i},{x:e,y:-i},{x:e,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Zi(0,0,.3);return[...A,o,n,s]},Ybt=Vi.extend({fn:N(),num_pins:vA().default(3),w:N().default("3.40mm"),h:N().default("3.30mm"),pl:N().default("1mm"),pw:N().default("0.7mm"),p:N().default("1.2mm"),string:N().optional()}),Jbt=t=>{const A=t.string?.match(/^sot23w_(\d+)/),e=A?Number.parseInt(A[1],3):3,i=Ybt.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:Kbt(i),parameters:i};throw new Error("Invalid number of pins")},Tbt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e,y:.95}:A===2?{x:-e,y:-.95}:{x:e,y:0}},Kbt=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=Tbt({num_pins:t.num_pins,pn:r+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(yi(r+1,a,g,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=Zi(0,Number.parseInt(t.h)/2+1,.3),i=Number.parseFloat(t.w)/2-1,o=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:o},{x:i+.3,y:o},{x:i+.3,y:o/2}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-o},{x:i+.3,y:-o},{x:i+.3,y:-o/2}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,n,s,e]},Pbt=Vi.extend({fn:N(),num_pins:Ht([CA(3),CA(2)]).default(3),p:N().default("1.27mm"),id:N().default("0.72mm"),od:N().default("0.95mm"),w:N().default("2.5mm"),h:N().default("4.2mm"),string:N().optional()}),qbt=t=>{const{p:A,id:e,od:i,w:o,h:n}=t,s=Number.parseFloat(n)/2,r=Number.parseFloat(A);return[As(1,-r,s-r,e,i),As(2,0,s-r,e,i),As(3,r,s-r,e,i)]},Obt=t=>{const{p:A,id:e,od:i,h:o}=t,n=Number.parseFloat(o)/2,s=Number.parseFloat(A);return[As(1,-s,n-s,e,i),As(2,s,n-s,e,i)]},Wbt=t=>{const A=t.string?.match(/^to92s_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=Pbt.parse({...t,num_pins:e});let o=[];if(i.num_pins===3)o=qbt(i);else if(i.num_pins===2)o=Obt(i);else throw new Error("Invalid number of pins for TO-92");const n=Number.parseFloat(i.h)/2,s=Number.parseFloat(i.p),r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n,y:n-s},{x:-1.9,y:0},{x:1.9,y:0},{x:n,y:n-s},{x:1.5,y:Number.parseFloat(i.h)/2+.5},{x:-1.5,y:Number.parseFloat(i.h)/2+.5},{x:-n,y:n-s}],stroke_width:.1,pcb_silkscreen_path_id:""},a=Zi(0,n+1,.5);return{circuitJson:[...o,r,a],parameters:i}},Zbt=Vi.extend({fn:N(),p:ee.optional(),id:ee.optional(),pw:ee.optional(),pl:ee.optional(),w:ee.optional(),h:ee.optional(),sh:Ht([$A(),N(),vA()]).optional().transform(t=>{if(typeof t=="string"){const A=Number(t);return Number.isNaN(A)?!0:A}return t}).describe('JST SH (Surface-mount) connector family. SH stands for "Super High-density".'),ph:$A().optional().describe('JST PH (Through-hole) connector family. PH stands for "Pin Header".'),string:N().optional()}),Vbt={ph:{p:ee.parse("2.2mm"),id:ee.parse("0.70mm"),pw:ee.parse("1.20mm"),pl:ee.parse("1.20mm"),w:ee.parse("6mm"),h:ee.parse("5mm")},sh:{p:ee.parse("1mm"),pw:ee.parse("0.6mm"),pl:ee.parse("1.55mm"),w:ee.parse("5.8mm"),h:ee.parse("7.8mm")}};function jbt(t){return t.sh?"sh":(t.ph,"ph")}function zbt(t,A,e,i,o,n){const s=[];if(t==="ph"){const r=e/2;s.push(lb(1,-r,2,i,o,n)),s.push(lb(2,r,2,i,o,n))}else{const r=-((A-1)/2)*e;for(let g=0;g<A;g++){const c=r+g*e;console.log("x si",c),s.push(yi(g+1,c,-1.325,o,n))}const a=(A-1)/2*e+1.3;console.log("offset",a),s.push(yi(A+1,-a,1.22,1.2,1.8)),s.push(yi(A+2,a,1.22,1.2,1.8))}return s}function Xbt(t,A,e){return t==="ph"?{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-3,y:3},{x:3,y:3},{x:3,y:-2},{x:-3,y:-2},{x:-3,y:3}],stroke_width:.1,pcb_silkscreen_path_id:""}:{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[],stroke_width:.1,pcb_silkscreen_path_id:""}}var $bt=t=>{const A=Zbt.parse(t),e=jbt(A),i=Vbt[e],o=A.p??i.p,n=A.id??i.id,s=A.pw??i.pw,r=A.pl??i.pl,a=A.w??i.w,g=A.h??i.h;let c=e==="sh"?4:2;if(e==="sh"){const Q=(typeof t.string=="string"?t.string:"").match(/sh(\d+)/);if(Q&&Q[1]){const h=parseInt(Q[1],10);Number.isNaN(h)||(c=h)}else typeof A.sh=="number"&&(c=A.sh)}const I=zbt(e,c,o,n,s,r),l=Xbt(e),B=Zi(0,g/2+1,.5);return{circuitJson:[...I,l,B],parameters:{...A,p:o,id:n,pw:s,pl:r,w:a,h:g,num_pins:c,sh:e==="sh",ph:e==="ph"}}},A_t=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("3.30mm"),h:N().default("1.70mm"),pl:N().default("0.80mm"),pw:N().default("1mm"),p:N().default("1.90mm")}),e_t=t=>{const A=A_t.parse(t),e=Zi(0,ee.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:i_t(A).concat(i,e),parameters:A}},t_t=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},i_t=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=t_t({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},o_t=t=>{switch(t){case 8:return{w:"3.06mm",h:"3.14mm",p:"0.65mm",pl:"1.6mm",pw:"0.5mm"};case 10:return{w:"3.10mm",h:"3.33mm",p:"0.5mm",pl:"1.45mm",pw:"0.3mm"};default:return{w:"3.06mm",h:"3.14mm",p:"0.65mm",pl:"1.6mm",pw:"0.5mm"}}},n_t=Vi.extend({fn:N(),num_pins:Ht([CA(8),CA(10)]).default(8),w:N().optional(),h:N().optional(),p:N().optional(),pl:N().optional(),pw:N().optional(),string:N().optional()}),s_t=t=>{const A=n_t.parse(t),e=o_t(A.num_pins),i=ee.parse(A.w||e.w),o=ee.parse(A.h||e.h),n=ee.parse(A.p||e.p),s=ee.parse(A.pl||e.pl),r=ee.parse(A.pw||e.pw),a=[],g=A.num_pins/2;for(let u=0;u<A.num_pins;u++){const{x:d,y:f}=g7A(A.num_pins,u+1,i,n),m=u<g?u+1:A.num_pins-(u-g);a.push(yi(m,d,f,s,r))}const c=i,I=o,l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c/2,y:I/2},{x:c/2,y:I/2}],stroke_width:.05,pcb_silkscreen_path_id:""},B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c/2,y:-I/2},{x:c/2,y:-I/2}],stroke_width:.05,pcb_silkscreen_path_id:""},C=g7A(A.num_pins,1,c,n),Q={x:C.x-.8,y:C.y},h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:Q.x-.4,y:Q.y},{x:Q.x-.7,y:Q.y+.3},{x:Q.x-.7,y:Q.y-.3},{x:Q.x-.4,y:Q.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},E=Zi(0,I/2+.5,.3);return{circuitJson:[...a,l,B,E,h],parameters:A}},g7A=(t,A,e,i)=>{const o=t/2,n=(A-1)%o,s=A<=o?-1:1,r=(o-1)/2-n;return{x:s*ee.parse(t===8?"1.8mm":"2.2mm"),y:r*i}},r_t=t=>{switch(t){case 10:return{w:"3.10mm",h:"3.32mm",p:"0.5mm",pl:"1.63mm",pw:"0.33mm"};case 12:return{w:"3mm",h:"4mm",p:"0.65mm",pl:"0.88mm",pw:"0.4mm"};case 16:return{w:"3.10mm",h:"4mm",p:"0.5mm",pl:"0.88mm",pw:"0.3mm"};default:return{w:"3.10mm",h:"3.32mm",p:"0.65mm",pl:"1.63mm",pw:"0.4mm"}}},a_t=Vi.extend({fn:N(),num_pins:Ht([CA(8),CA(10),CA(12),CA(16)]).default(8),w:N().optional(),h:N().optional(),p:N().optional(),pl:N().optional(),pw:N().optional(),string:N().optional()}),c7A=(t,A,e,i)=>{const o=t/2,n=(A-1)%o,s=A<=o?-1:1,r=(o-1)/2-n;return{x:s*ee.parse("2mm"),y:r*i}},g_t=t=>{const A=a_t.parse(t),e=r_t(A.num_pins),i=ee.parse(A.w||e.w),o=ee.parse(A.h||e.h),n=ee.parse(A.p||e.p),s=ee.parse(A.pl||e.pl),r=ee.parse(A.pw||e.pw),a=[];for(let E=0;E<A.num_pins;E++){const{x:u,y:d}=c7A(A.num_pins,E+1,i,n);a.push(yi(E+1,u,d,s,r))}const g=i,c=o,I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g/2,y:c/2},{x:g/2,y:c/2}],stroke_width:.05,pcb_silkscreen_path_id:""},l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g/2,y:-c/2},{x:g/2,y:-c/2}],stroke_width:.05,pcb_silkscreen_path_id:""},B=c7A(A.num_pins,1,g,n),C={x:B.x-.8,y:B.y},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:C.x-.4,y:C.y},{x:C.x-.7,y:C.y+.3},{x:C.x-.7,y:C.y-.3},{x:C.x-.4,y:C.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},h=Zi(0,c/2+.5,.3);return{circuitJson:[...a,I,l,h,Q],parameters:A}},c_t=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("3.8mm"),h:N().default("1.65mm"),pl:N().default("1.2mm"),pw:N().default("1.2mm"),pad_spacing:N().default("2.6mm")}),I_t=t=>{const A=c_t.parse(t),e=Zi(0,ee.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.pad_spacing)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:-ee.parse(A.h)/2},{x:ee.parse(A.pad_spacing)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:B_t(A).concat(i,e),parameters:A}},l_t=t=>{const{pn:A,pad_spacing:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},B_t=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=l_t({pn:e,pad_spacing:Number.parseFloat(t.pad_spacing)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},C_t=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("3.20mm"),h:N().default("1.65mm"),pl:N().default("0.8mm"),pw:N().default("0.9mm"),pad_spacing:N().default("2.1mm")}),Q_t=t=>{const A=C_t.parse(t),e=Zi(0,ee.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.pad_spacing)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.2,y:-ee.parse(A.h)/2},{x:ee.parse(A.pad_spacing)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:E_t(A).concat(i,e),parameters:A}},h_t=t=>{const{pn:A,pad_spacing:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},E_t=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=h_t({pn:e,pad_spacing:Number.parseFloat(t.pad_spacing)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},u_t=Vi.extend({fn:N(),num_pins:Ht([CA(6),CA(8)]).default(8),w:N().default("3mm"),h:N().default("3mm"),p:N().default("0.5mm"),pl:N().default("0.52mm"),pw:N().default("0.35mm"),epw:N().default("1.40mm"),eph:N().default("1.60mm"),string:N().optional(),ep:$A().default(!1)}),d_t=t=>{t.string&&t.string.includes("_ep")&&(t.ep=!0);const A=t.string?.match(/^son_(\d+)/),e=A?Number.parseInt(A[1],10):t.num_pins||8,i=u_t.parse({...t,num_pins:e}),o=ee.parse(i.w),n=ee.parse(i.h),s=ee.parse(i.p),r=ee.parse(i.pl),a=ee.parse(i.pw),g=ee.parse(i.epw),c=ee.parse(i.eph),I=[];for(let f=0;f<i.num_pins;f++){const{x:m,y:D}=I7A(i.num_pins,f+1,o,s);I.push(yi(f+1,m,D,r,a))}i.ep&&I.push(yi(i.num_pins+1,0,0,g,c));const l=o,B=n,C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l/2,y:B/2},{x:l/2,y:B/2}],stroke_width:.05,pcb_silkscreen_path_id:""},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l/2,y:-B/2},{x:l/2,y:-B/2}],stroke_width:.05,pcb_silkscreen_path_id:""},h=I7A(i.num_pins,1,l,s),E={x:h.x-.4,y:h.y},u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:E.x-.4,y:E.y},{x:E.x-.7,y:E.y+.3},{x:E.x-.7,y:E.y-.3},{x:E.x-.4,y:E.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},d=Zi(0,B/2+.5,.3);return{circuitJson:[...I,C,Q,d,u],parameters:i}},I7A=(t,A,e,i)=>{const o=t/2,n=(A-1)%o,s=A<=o?-1:1,r=(o-1)/2-n;return{x:s*ee.parse("1.4mm"),y:r*i}},p_t=t=>{const{num_pins:A,bridged:e,p:i=2.54,pw:o=1.5,ph:n=1.5}=t,s=ee.parse(i),r=ee.parse(o),a=ee.parse(n),g=Math.min(a/4,.5),c=[];for(let f=0;f<A;f++)c.push(yi(f+1,f*s,0,r,a));let I=[];if(e){const f=e.split("").map(Number);if(f.length>1)for(let m=0;m<f.length-1;m++){const D=f[m],w=f[m+1];if(typeof D=="number"&&typeof w=="number"&&!isNaN(D)&&!isNaN(w)){const b=(D-1)*s,k=(w-1)*s,_=Math.sign(k-b),M=b+_*(r/2),v=k-_*(r/2);I.push({type:"pcb_trace",pcb_trace_id:"",route:[{start_pcb_port_id:`{PIN${D}}`,x:M,y:0,width:g,layer:"top",route_type:"wire"},{end_pcb_port_id:`{PIN${w}}`,x:v,y:0,width:g,layer:"top",route_type:"wire"}]})}}}const l=(A-1)*s+r+.7,B=a+1,C=(A-1)*s/2,Q=0,h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"outline",route:[{x:C-l/2,y:Q-B/2},{x:C+l/2,y:Q-B/2},{x:C+l/2,y:Q+B/2},{x:C-l/2,y:Q+B/2},{x:C-l/2,y:Q-B/2}],stroke_width:.15},u=Q+B/2+.6,d=Zi(C,u,.4);return{circuitJson:[...c,...I,h,d],parameters:t}},l7A={fn:CA("sot457"),num_pins:CA(6).default(6),pillh:N().default("0.45mm"),pillw:N().default("1.45mm"),pl:N(),pw:N(),p:N(),wave:$A().optional(),reflow:$A().optional()},f_t=Vi.extend({...l7A,h:N().default("2.5mm"),w:N().default("2.7mm"),pl:N().default("0.8mm"),pw:N().default("0.55mm"),p:N().default("0.95mm")}),y_t=Vi.extend({...l7A,h:N().default("3mm"),w:N().default("4mm"),pillr:N().default("0.225mm"),pl:N().default("1.45mm"),pw:N().default("1.5mm"),p:N().default("1.475mm")}).transform(t=>({...t,wave:t.wave??(t.reflow===void 0?!0:!t.reflow),reflow:t.reflow??(t.wave===void 0?!1:!t.wave)})),Bb=t=>Number.parseFloat(t.replace("mm","")),B7A=({pitch:t,width:A,pinNumber:e})=>{const n={1:{x:-A/2-.1,y:t},2:{x:-A/2-.1,y:0},3:{x:-A/2-.1,y:-t},4:{x:A/2+.1,y:-t},5:{x:A/2+.1,y:0},6:{x:A/2+.1,y:t}}[e];if(!n)throw new Error(`Invalid pin number: ${e}`);return n},C7A=t=>{const A=[],e=Bb(t.p),i=Bb(t.pl),o=Bb(t.pw),n=Bb(t.w),s=Bb(t.h);if(t.wave){const C={1:({padWidth:Q,padHeight:h})=>yi(1,-e,e,h,Q),2:({padWidth:Q,padHeight:h})=>yi(2,-e,-e,h,Q),3:({padWidth:Q,padHeight:h})=>qW(3,-e,0,Bb(t.pillw),Bb(t.pillh)),4:({padWidth:Q,padHeight:h})=>qW(4,e,0,Bb(t.pillw),Bb(t.pillh)),5:({padWidth:Q,padHeight:h})=>yi(5,e,e,h,Q),6:({padWidth:Q,padHeight:h})=>yi(6,e,-e,h,Q)};for(let Q=1;Q<=t.num_pins;Q++){const h=C[Q];h&&A.push(h({padWidth:i,padHeight:o}))}}else for(let C=1;C<=t.num_pins;C++){const{x:Q,y:h}=B7A({pitch:e,width:n,pinNumber:C});A.push(yi(C,Q,h,i,o))}const r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-n/3,y:s/2+e/1.3},{x:n/3,y:s/2+e/1.3}],stroke_width:.05},a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-n/3,y:-s/2-e/1.3},{x:n/3,y:-s/2-e/1.3}],stroke_width:.05},g=Zi(0,s+.5,.3),c=B7A({pitch:e,width:n,pinNumber:1}),I=t.wave?1:.5,l=t.wave?.7:.3;c.x-=t.wave?o:o*1.7;const B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:c.x+I/2,y:c.y},{x:c.x-I/2,y:c.y+l/2},{x:c.x-I/2,y:c.y-l/2},{x:c.x+I/2,y:c.y}],stroke_width:.05};return[g,r,a,B,...A]},m_t=t=>{if(t.wave){const e=y_t.parse({...t,fn:"sot457"});return{circuitJson:C7A(e),parameters:e}}const A=f_t.parse(t);return{circuitJson:C7A(A),parameters:A}},w_t=Vi.extend({fn:N(),num_pins:CA(6).default(6),w:N().default("1.1mm"),h:N().default("1.45mm"),p:N().default("0.35mm"),pl:N().default("0.2mm"),pw:N().default("0.2mm"),string:N().optional()}),D_t=t=>{const A=w_t.parse({...t,fn:"sot963"}),e=ee.parse(A.w),i=ee.parse(A.h),o=ee.parse(A.p),n=ee.parse(A.pl),s=ee.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=Q7A(B+1,e,o,n);r.push(yi(B+1,C,Q,n,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:i/2},{x:e/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:-i/2},{x:e/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=Q7A(1,e,o,n),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-n/2-.3,y:c.y},{x:c.x-n/2-.45,y:c.y+.15},{x:c.x-n/2-.45,y:c.y-.15},{x:c.x-n/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Zi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},Q7A=(t,A,e,i)=>{const o=A/2-i/2;return t<=3?{x:-o,y:e-(t-1)*e}:{x:o,y:-e+(t-4)*e}},S_t=Vi.extend({fn:N(),num_pins:Ht([CA(3),CA(2)]).default(3),p:N().default("3.8mm"),id:N().default("1.25mm"),od:N().default("2.35mm"),ca:N().default("14mm").describe("Caliper axis (width or diameter of the potentiometer body or adjustment knob)"),w:N().default("5.35mm"),h:N().default("4mm"),string:N().optional()}),b_t=t=>{const{p:A,id:e,od:i,h:o,ca:n}=t,s=Number.parseFloat(o),r=Number.parseFloat(n);return[As(1,0,r/4+.3,e,i),As(2,s,0,e,i),As(3,0,-r/4-.3,e,i)]},__t=t=>{const A=t.string?.match(/^potentiometer_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=S_t.parse({...t,num_pins:e});let o=[];i.num_pins===3&&(o=b_t(i));const n=Number.parseFloat(i.ca)/2+.15,s=Number.parseFloat(i.w),r=Number.parseFloat(i.od)/2+.35,a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:n-1.75},{x:0,y:n},{x:s,y:n},{x:s,y:r}],stroke_width:.1,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:s,y:-r},{x:s,y:-n},{x:0,y:-n},{x:0,y:-n+1.75}],stroke_width:.1,pcb_silkscreen_path_id:""},c=Number.parseFloat(i.w)/2,I=Zi(c,n+1,.5);return{circuitJson:[...o,a,g,I],parameters:i}},x_t=Vi.extend({fn:N(),p:ee.optional().default("7.5mm"),id:ee.optional().default("1mm"),od:ee.optional().default("2mm"),d:ee.optional().default("10.5mm")}),k_t=(t,A,e,i,o)=>{const n=[],s=[];for(let r=0;r<=50;r++){const a=r/50*Math.PI,g=t+Math.cos(a)*e,c=A+Math.sin(a)*e;g<t-i&&c>=A-o/2&&c<=A+o/2||n.push({x:g,y:c})}for(let r=0;r<=50;r++){const a=Math.PI+r/50*Math.PI,g=t+Math.cos(a)*e,c=A+Math.sin(a)*e;g<t-i&&c>=A-o/2&&c<=A+o/2||s.push({x:g,y:c})}return{topArc:n,bottomArc:s}},F_t=t=>{const A=x_t.parse(t),{p:e,id:i,od:o,d:n}=A,s=[As(1,-e/2,0,i,o),As(2,e/2,0,i,o)],{topArc:r,bottomArc:a}=k_t(0,0,n/2+.1,o/2,o),g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:r,stroke_width:.1,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:.1,pcb_silkscreen_path_id:""},I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:n/2+.1},{x:0,y:-(n/2+.1)}],stroke_width:.1,pcb_silkscreen_path_id:""},l=-(n/2+.5),B=o/2+1.5,C=.5,Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:l-C,y:B},{x:l+C,y:B}],stroke_width:.1,pcb_silkscreen_path_id:""},h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:l,y:B-C},{x:l,y:B+C}],stroke_width:.1,pcb_silkscreen_path_id:""},E=Zi(0,n/2+1,.5);return{circuitJson:[...s,g,c,I,Q,h,E],parameters:A}},G_t=Vi.extend({fn:N(),num_pins:CA(2).default(2),w:N().default("6.5mm"),h:N().default("3mm"),pl:N().default("1.75mm"),pw:N().default("2.40mm"),p:N().default("4.75mm")}),R_t=t=>{const A=G_t.parse(t),e=Zi(0,ee.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ee.parse(A.p)/2,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.3,y:ee.parse(A.h)/2},{x:-ee.parse(A.w)/2-.3,y:-ee.parse(A.h)/2},{x:ee.parse(A.p)/2,y:-ee.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:M_t(A).concat(i,e),parameters:A}},v_t=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},M_t=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=v_t({pn:e,p:Number.parseFloat(t.p)});A.push(yi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},N_t=Vi.extend({fn:N(),num_pins:vA().default(3),w:N().default("2.45mm"),h:N().default("2.40mm"),pl:N().default("1.225mm"),pw:N().default("0.5mm"),p:N().default("0.95mm"),string:N().optional()}),L_t=t=>{const A=t.string?.match(/^sot323_(\d+)/),e=A?Number.parseInt(A[1],3):3,i=N_t.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:H_t(i),parameters:i};throw new Error("Invalid number of pins")},U_t=t=>{const{pn:A,p:e}=t;return A===1?{x:-e,y:.65}:A===2?{x:-e,y:-.65}:{x:e,y:0}},H_t=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=U_t({num_pins:t.num_pins,pn:r+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(yi(r+1,a,g,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=Zi(0,Number.parseInt(t.h)/2+1,.3),i=Number.parseFloat(t.w)/2-Number.parseFloat(t.pl),o=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:o+.3},{x:i,y:o+.3},{x:i,y:o/2}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-o-.3},{x:i,y:-o-.3},{x:i,y:-o/2}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,n,s,e]},Y_t=Vi.extend({fn:N(),circle:$A().optional(),rect:$A().optional(),square:$A().optional(),pill:$A().optional(),d:ee.optional(),pd:ee.optional(),diameter:ee.optional(),r:ee.optional(),pr:ee.optional(),radius:ee.optional(),w:ee.optional(),pw:ee.optional(),width:ee.optional(),h:ee.optional(),ph:ee.optional(),height:ee.optional(),s:ee.optional(),size:ee.optional(),string:N().optional()}).transform(t=>{let A="rect";t.circle&&(A="circle"),t.square&&(A="square"),t.rect&&(A="rect"),t.pill&&(A="pill");let e,i,o;return A==="circle"?t.r!==void 0?e=vr(t.r):t.pr!==void 0?e=vr(t.pr):t.radius!==void 0?e=vr(t.radius):t.d!==void 0?e=vr(t.d)/2:t.pd!==void 0?e=vr(t.pd)/2:t.diameter!==void 0?e=vr(t.diameter)/2:e=vr("1mm")/2:(t.w!==void 0?i=vr(t.w):t.pw!==void 0?i=vr(t.pw):t.width!==void 0?i=vr(t.width):t.s!==void 0?i=vr(t.s):t.size!==void 0?i=vr(t.size):i=vr("1mm"),t.h!==void 0?o=vr(t.h):t.ph!==void 0?o=vr(t.ph):t.height!==void 0?o=vr(t.height):A==="square"||A==="rect"?o=i:o=vr("1mm")),{fn:t.fn,shape:A,radius:e,width:i,height:o}}),J_t=t=>{const A=Y_t.parse(t),{shape:e,radius:i,width:o,height:n}=A;let s,r;return e==="circle"?(s=V6A(1,{x:0,y:0,radius:i}),r=i+.5):e==="pill"?(s=qW(1,0,0,o,n),r=Math.max(o,n)/2+.5):(s=yi(1,0,0,o,n),r=n/2+.5),{circuitJson:[s,Zi(0,r,.2)],parameters:A}},T_t=Vi.extend({fn:N(),d:ee.optional(),hd:ee.optional(),r:ee.optional(),hr:ee.optional(),pd:ee.optional(),pr:ee.optional(),squarepad:$A().optional().default(!1)}).transform(t=>{let A;t.d!==void 0?A=vr(t.d):t.hd!==void 0?A=vr(t.hd):t.r!==void 0?A=vr(t.r)*2:t.hr!==void 0?A=vr(t.hr)*2:A=vr("1mm");let e;return t.pd!==void 0?e=vr(t.pd):t.pr!==void 0?e=vr(t.pr)*2:e=A*(1.5/1),{fn:t.fn,d:A,pd:e,squarepad:t.squarepad??!1}}),K_t=t=>{const A=T_t.parse(t),{d:e,pd:i,squarepad:o}=A;return{circuitJson:[o?lb(1,0,0,e,i,i):As(1,0,0,e,i),Zi(0,i/2+.5,.2)],parameters:A}},P_t=Vi.extend({fn:N(),num_pins:CA(6).default(6),h:N().default("1.6mm"),pl:N().default("1mm"),pw:N().default("0.7mm"),p:N().default("0.95mm")}),q_t=t=>{const A=P_t.parse(t);return{circuitJson:O_t(A),parameters:A}},h7A=t=>{const{p:A,h:e,pn:i}=t;if(i===1)return{x:-e/2-.5,y:A};if(i===2)return{x:-e/2-.5,y:0};if(i===3)return{x:-e/2-.5,y:-A};if(i===4)return{x:e/2+.5,y:-A};if(i===5)return{x:e/2+.5,y:0};if(i===6)return{x:e/2+.5,y:A};throw new Error("Invalid pin number")},O_t=t=>{const A=[];for(let I=1;I<=t.num_pins;I++){const{x:l,y:B}=h7A({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:I});A.push(yi(I,l,B,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=t.num_pins/2*Number.parseFloat(t.p),i=Number.parseFloat(t.h),o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e/3,y:i/2+Number.parseFloat(t.p)/1.3},{x:e/3,y:i/2+Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e/3,y:-i/2-Number.parseFloat(t.p)/1.3},{x:e/3,y:-i/2-Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Zi(0,i+.3,.3),r=h7A({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});r.x=r.x-Number.parseFloat(t.pw)*1.5;const a=.7,g=.3,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:r.x+a/2,y:r.y},{x:r.x-a/2,y:r.y+g/2},{x:r.x-a/2,y:r.y-g/2},{x:r.x+a/2,y:r.y}],stroke_width:.05};return[...A,s,o,n,c]},W_t=Vi.extend({fn:N(),num_pins:vA().default(4),w:N().default("3.2mm"),h:N().default("2.6mm"),pl:N().default("1.35mm"),pw:N().default("0.50mm"),p:N().default("0.6mm"),string:N().optional()}),Z_t=t=>{const A=t.string?.match(/^sot343_(\d+)/),e=A?Number.parseInt(A[1],4):4,i=W_t.parse({...t,num_pins:e});if(i.num_pins===4)return{circuitJson:j_t(i),parameters:i};throw new Error("Invalid number of pins")},V_t=t=>{const{pn:A,p:e}=t;return A===1?{x:-e*1.92,y:-.65}:A===2?{x:-e*1.92,y:.65}:A===3?{x:e,y:.65}:A===4?{x:e,y:-.65}:{x:0,y:0}},j_t=t=>{const A=[],e=Number.parseFloat(t.w),i=Number.parseFloat(t.h),o=Number.parseFloat(t.pl),n=Number.parseFloat(t.pw),s=Number.parseFloat(t.p);let r=1/0,a=-1/0,g=1/0,c=-1/0;for(let d=0;d<t.num_pins;d++){const{x:f,y:m}=V_t({num_pins:t.num_pins,pn:d+1,p:s});A.push(yi(d+1,f,m,o,n)),f<r&&(r=f),f>a&&(a=f),m<g&&(g=m),m>c&&(c=m)}const I=(r+a)/2,l=c-g,B=i*.3,C=l/2+B;let Q=e*.8;i<=2.6&&(Q/=2);const h=Zi(I,C+.5,.3),E={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_top",route:[{x:I-Q/2,y:C},{x:I+Q/2,y:C}],type:"pcb_silkscreen_path",stroke_width:.1},u={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_bottom",route:[{x:I-Q/2,y:-C},{x:I+Q/2,y:-C}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,E,u,h]},z_t=Vi.extend({fn:N()}),X_t=t=>{const A=z_t.parse(t),e=[],i=.5-.15,o=1.5,s=.5/2,r=75,a=-37/2;for(let w=0;w<r;w++){const b=w+1;if(b>=24&&b<=31)continue;const k=a-w*s,_=b%2===0,M=o+(_?.25:0),U=.5-M/2,J=yi(b,U,k,M,i);J.layer=_?"bottom":"top",e.push(J)}const g=46*.0254,c=137*.0254,I=261*.0254,l={type:"pcb_cutout",pcb_cutout_id:"",shape:"rect",center:{x:-c/2+o/2,y:a-I},width:c,height:g},B={x:-.5,y:a},C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:B.x-.4,y:B.y},{x:B.x-.7,y:B.y+.3},{x:B.x-.7,y:B.y-.3},{x:B.x-.4,y:B.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"};let Q=1/0,h=-1/0,E=1/0,u=-1/0;const d=(w,b,k=0,_=0)=>{Q=Math.min(Q,w-k/2),h=Math.max(h,w+k/2),E=Math.min(E,b-_/2),u=Math.max(u,b+_/2)};for(const w of e)d(w.x,w.y,w.width,w.height);d(l.center.x,l.center.y,l.width,l.height);for(const w of C.route)d(w.x,w.y);const f=(Q+h)/2,m=(E+u)/2,D=w=>{typeof w.x=="number"&&(w.x-=f),typeof w.y=="number"&&(w.y-=m),w.center&&(w.center.x-=f,w.center.y-=m),Array.isArray(w.route)&&(w.route=w.route.map(b=>({x:b.x-f,y:b.y-m})))};for(const w of e)D(w);return D(l),D(C),{circuitJson:[...e,l,C],parameters:A}},$_t=Vi.extend({fn:N(),num_pins:vA().default(3),inline:$A().default(!1),p:N().default("1.27mm"),id:N().default("0.75mm"),od:N().default("1.3mm"),w:N().default("4.8mm"),h:N().default("4.0mm")}),Axt=t=>{const A=$_t.parse(t),e=Number.parseFloat(A.p),i=Number.parseFloat(A.w),o=Number.parseFloat(A.h),n=A.inline?1.05:Number.parseFloat(A.od),s=A.inline?1.5:n,r=[lb(1,0,0,A.id,n,s,0,0),A.inline?kH(2,e,0,A.id,n,s):As(2,e,e,A.id,n),A.inline?kH(3,e*2,0,A.id,n,s):As(3,e*2,0,A.id,n)],a=i/2,g=A.inline?e-.09:e,c=.2,I=c+a-o,l=Array.from({length:32},(Q,h)=>{const E=Math.PI*h/31;return{x:g+a*Math.cos(E),y:c+a*Math.sin(E)}}),B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",stroke_width:.12,route:[...l,{x:g-a,y:I},{x:g+a,y:I},l[0]]},C=Zi(g,c+a+1,.5);return{circuitJson:[...r,B,C],parameters:A}};function ext(t){return t!=null}var txt=(t,A)=>{if(!A)return t;const e=t.filter(c=>c.type==="pcb_smtpad"||c.type==="pcb_plated_hole"||c.type==="pcb_thtpad");if(e.length===0)return t;let i=1/0,o=-1/0,n=1/0,s=-1/0;const r=(c,I,l=0,B=0)=>{const C=c-l/2,Q=c+l/2,h=I-B/2,E=I+B/2;i=Math.min(i,C),o=Math.max(o,Q),n=Math.min(n,h),s=Math.max(s,E)};for(const c of e)if(c.type==="pcb_smtpad"){const I=c.shape==="circle"?c.radius*2:c.width,l=c.shape==="circle"?c.radius*2:c.height;r(c.x,c.y,I,l)}else if(c.type==="pcb_plated_hole"){const I=c.outer_diameter??c.hole_diameter;r(c.x,c.y,I,I)}else if(c.type==="pcb_thtpad"){const I=c.diameter;r(c.x,c.y,I,I)}let a=0,g=0;switch(A){case"center":a=(i+o)/2,g=(n+s)/2;break;case"bottomleft":a=i,g=n;break;case"bottomcenter":case"centerbottom":a=(i+o)/2,g=n;break;case"topcenter":case"centertop":a=(i+o)/2,g=s;break;case"leftcenter":case"centerleft":a=i,g=(n+s)/2;break;case"rightcenter":case"centerright":a=o,g=(n+s)/2;break;case"pin1":const c=e.find(I=>I.port_hints?.[0]==="1")||e[0];a=c.x,g=c.y;break}if(a===0&&g===0)return t;for(const c of t){if(typeof c.x=="number"&&(c.x-=a),typeof c.y=="number"&&(c.y-=g),c.center&&typeof c.center.x=="number"&&(c.center.x-=a,c.center.y-=g),c.type==="pcb_silkscreen_path")for(const I of c.route)I.x-=a,I.y-=g;c.type==="pcb_silkscreen_text"&&c.anchor_position&&(c.anchor_position.x-=a,c.anchor_position.y-=g)}return t},ixt=(t,A)=>{const e=t.filter(i=>i.type==="pcb_silkscreen_text");if(e.length===0)return t;for(const i of e)A.norefdes&&(i.text="");return t},oxt=(t,A)=>A.nosilkscreen?t.filter(e=>e.type!=="pcb_silkscreen_path"&&e.type!=="pcb_silkscreen_text"):t,nxt=t=>{let A=VW();const i=t.replace(/^((?:\d{4}|\d{5}))(?=$|_)/,"res$1").split(/_(?!metric)/).map(o=>{const n=o.match(/([a-zA-Z]+)([\(\d\.\+\?].*)?/);if(!n)return null;const[,s,r]=n;if(!s)return null;const a=s.toLowerCase();return r?.includes("?")?null:{fn:a,v:r}}).filter(ext);for(const{fn:o,v:n}of i)A=A[o](n);return A.setString(t),A},sxt=()=>Object.keys(Ib),VW=()=>{const t=new Proxy({},{get:(A,e)=>{if(e==="soup"||e==="circuitJson"){if("fn"in A&&Ib[A.fn])return()=>{const{circuitJson:i}=Ib[A.fn](A),o=oxt(i,A),n=ixt(o,A);return txt(n,A.origin)};if(!Ib[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>{throw new Error(`No function found for footprinter, make sure to specify .dip, .lr, .p, etc. Got "${e}"`)}}if(e==="json"){if(!Ib[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>Ib[A.fn](A).parameters}return e==="getFootprintNames"?()=>Object.keys(Ib):e==="params"?()=>A:e==="setString"?i=>(A.string=i,t):i=>(Object.keys(A).length===0?`${e}${i}`in Ib?(A[`${e}${i}`]=!0,A.fn=`${e}${i}`):(A[e]=!0,A.fn=e,e==="res"||e==="cap"?i&&(typeof i=="string"&&i.includes("_metric")?A.metric=i.split("_metric")[0]:A.imperial=i):A.num_pins=Number.isNaN(Number.parseFloat(i))?void 0:Number.parseFloat(i)):!i&&["w","h","p"].includes(e)||(A[e]=i??!0),t)}});return t};VW.string=nxt,VW.getFootprintNames=sxt;var rxt=VW,E7A=Symbol("Fragment");function wEA(t,A,...e){const i=e.length?e:A?.children!==void 0?[A.children]:[],o=[],n=(Array.isArray(i)?i:[i]).flat(1/0);for(const s of n)s==null||s===!1||(Array.isArray(s)?o.push(...s):o.push(s));return{type:t,props:(A&&A.children!==void 0?{...A,children:void 0}:A)||{},children:o}}var ut=Symbol("Cuboid"),u7A=Symbol("Cube"),Ef=Symbol("Cylinder"),d7A=Symbol("Sphere"),FH=Symbol("RoundedCuboid"),to=Symbol("Translate"),RQ=Symbol("Rotate"),kh=Symbol("Union"),rG=Symbol("Subtract"),yc=Symbol("Hull"),Gs=Symbol("Colorize"),GH=Symbol("Polygon"),RH=Symbol("ExtrudeLinear"),uf=Symbol("RoundedCylinder"),An=E7A,te=(t,A,e)=>wEA(t,A),Wt=(t,A,e)=>wEA(t,A),cB=({center:t,width:A,length:e,height:i,heightAboveSurface:o=.15,color:n="#555",taperRatio:s=.12,faceRatio:r=.75,straightHeightRatio:a=.5,includeNotch:g=!0,notchRadius:c,notchPosition:I,notchRotation:l=[0,0,0],notchLength:B=.5,notchWidth:C=.25,chamferSize:Q=0})=>{const h=i*a,E=i-h,u=Math.min(A,e)*s,d=Math.max(A-u,A*r),f=Math.max(e-u,e*r),m=Math.min(A,e)*.12,D=c??m,w={x:0,y:e/2-D*.25,z:i},b=I??w,k=Wt(kh,{children:[Wt(yc,{children:[te(to,{z:.005,children:te(ut,{size:[d,f,.01]})}),te(to,{z:h,children:te(ut,{size:[A,e,.01]})})]}),Wt(yc,{children:[te(to,{z:h,children:te(ut,{size:[A,e,.01]})}),te(to,{z:h+E,children:te(ut,{size:[d,f,.01]})})]})]}),_=(v,U)=>te(to,{offset:{x:v,y:U,z:0},children:te(RQ,{rotation:[0,0,Math.PI/4],children:te(ut,{size:[Q*Math.SQRT2,Q*Math.SQRT2,i*3]})})});let M=k;if(Q>0){const v=A/2,U=e/2;M=Wt(rG,{children:[k,_(v,U),_(-v,U),_(v,-U),_(-v,-U)]})}return te(Gs,{color:n,children:te(to,{offset:t,children:te(to,{offset:{x:0,y:0,z:o},children:g?Wt(rG,{children:[M,te(to,{offset:b,children:te(RQ,{rotation:l,children:te(Ef,{radius:D,height:C})})})]}):M})})})},axt=t=>Array.from({length:t},(A,e)=>e);function DEA(t,A){if(t.length<2)throw new Error("Stroke must have at least two points");const e=Array.isArray(t[0])?t.map(([c,I])=>({x:c,y:I})):t,i=A/2,o=[],n=[];function s(c,I){const l=I.x-c.x,B=I.y-c.y,C=Math.sqrt(l*l+B*B);return{x:-B/C,y:l/C}}function r(c,I,l){const B={x:c.x+I.x*i*l,y:c.y+I.y*i*l};l>0?o.push(B):n.unshift(B)}const a=s(e[0],e[1]);r(e[0],a,1),r(e[0],a,-1);for(let c=1;c<e.length-1;c++){const I=e[c-1],l=e[c],B=e[c+1],C=s(I,l),Q=s(l,B),h=C.x+Q.x,E=C.y+Q.y,u=Math.sqrt(h*h+E*E);if(u/2>2*i)r(l,C,1),r(l,Q,1),r(l,C,-1),r(l,Q,-1);else{const f=1/u;r(l,{x:h*f,y:E*f},1),r(l,{x:h*f,y:E*f},-1)}}const g=s(e[e.length-2],e[e.length-1]);return r(e[e.length-1],g,1),r(e[e.length-1],g,-1),[...o,...n]}var gxt=t=>{const A=Math.min(...t.map(r=>r.x)),e=Math.max(...t.map(r=>r.x)),i=Math.min(...t.map(r=>r.y)),s=5.47/(Math.max(...t.map(r=>r.y))-i);return t.map(r=>({x:(r.x-A-(e-A)/2)*s,y:(r.y-i)*s}))},cxt=gxt([{x:20,y:105},{x:20,y:109},{x:20,y:102},{x:26,y:102},{x:26,y:109},{x:24,y:111},{x:24,y:118},{x:22,y:118},{x:22,y:111},{x:20,y:109}]),p7A=5.47,jW=.5,Ixt=({x:t,y:A,z:e})=>{const i=t>0;return Wt(An,{children:[te(to,{offset:{x:t+.25/2,y:A,z:e},children:te(RQ,{rotation:["-90deg",0,"90deg"],children:te(RH,{height:.25,children:te(GH,{points:cxt.slice().reverse().map(o=>[o.x,o.y])})})})}),te(to,{offset:{x:t,y:A+(i?1:-1),z:e},children:te(RQ,{rotation:["-90deg","90deg",i?"180deg":"0deg"],children:te(RH,{height:2,children:te(GH,{points:DEA([[0,0],[-1,0],[-1,-1]],.25).map(o=>[o.x,o.y])})})})})]})},lxt=({numPins:t=8,pitch:A=2.54,bodyWidth:e=6.4,rowSpacing:i})=>{const o=Math.floor(t/2),n=i??(e>=7?e:e+1.22),s=e>=7?n-1.22:e;return Wt(An,{children:[axt(t).map(r=>{const a=r%o,g=(Math.floor(r/o)-.5)*2;return te(Ixt,{x:g*n/2,y:a*A-(o-1)/2*A,z:p7A/2+jW})}),te(cB,{width:s,length:o*A+.5,height:p7A-jW,heightAboveSurface:jW,center:{x:0,y:0,z:jW}})]})};function Bxt(t,{height:A,padContactLength:e,curveLength:i,bodyDistance:o,steepness:n=10}){i||(i=o*.3);let s=o-e-i;s<0&&(i+=s,s=0);const r=e*.75,a=e+i+(o-e-i)*.25;if(t<=r)return 0;if(t>=a)return A;const g=(t-r)/(a-r);return A/(1+Math.exp(-n*(g-.5)))}var on=t=>{const{thickness:A,width:e,padContactLength:i,bodyDistance:o,height:n,rotation:s}=t,r=15,a=Array.from({length:r}).map((c,I)=>I/(r-1)*o).map(c=>[c,Bxt(c,t)]),g=DEA(a,A);return te(Gs,{color:"#fff",children:te(to,{offset:{z:0,y:0,x:0,...t.position},children:te(RQ,{rotation:["90deg",0,s??0],children:te(to,{offset:{x:0,y:0,z:-e/2},children:te(RH,{height:e,children:te(GH,{points:g.map(c=>[c.x,c.y])})})})})})})},Cxt=({pinCount:t,leadLength:A,leadWidth:e,pitch:i,bodyWidth:o})=>{const n=Math.ceil(t/2),s=i*t/2+e/2,r=(n-1)*i/2,a=.25;return Wt(An,{children:[Array.from({length:n}).map((g,c)=>te(on,{position:{x:-o/2-A,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),Array.from({length:n}).map((g,c)=>te(on,{rotation:Math.PI,position:{x:o/2+A,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),te(cB,{center:{x:0,y:0,z:a/2},width:o-e-1,length:s,height:1.5})]})},Qxt=({pinCount:t,padContactLength:A=.4,leadWidth:e=.2,pitch:i=.65,bodyWidth:o=3})=>{const n=Math.ceil(t/2),s=(n-1)*i/2,r=.2;return Wt(An,{children:[Array.from({length:n}).map((a,g)=>te(on,{position:{x:-o/2-A-.3,y:g*i-s,z:r/2},width:e,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),Array.from({length:n}).map((a,g)=>te(on,{rotation:Math.PI,position:{x:o/2+A+.3,y:g*i-s,z:r/2},width:e,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),te(cB,{center:{x:0,y:0,z:r/2},width:o,length:o,height:1.1,notchRadius:.35,heightAboveSurface:.1,taperRatio:.09})]})},SEA=1,bEA=.5,lN=.5,vH=.2,hxt=SEA-vH*2,f7A=({color:t="#333"})=>Wt(An,{children:[te(ut,{size:[hxt,bEA,lN],offset:[0,0,lN/2],color:t}),te(ut,{size:[vH,lN,bEA],offset:[SEA/2-vH/2,0,lN/2],color:"#ccc"}),te(ut,{size:[vH,lN,bEA],offset:[-SEA/2+vH/2,0,lN/2],color:"#ccc"})]}),_EA=1.6,Ext=_EA-.3*2,zW=.3,xEA=.85,BN=.6,y7A=({color:t="#333"})=>Wt(An,{children:[te(ut,{size:[Ext,xEA,BN],offset:[0,0,BN/2],color:t}),te(ut,{size:[zW,xEA,BN],offset:[_EA/2-zW/2,0,BN/2],color:"#ccc"}),te(ut,{size:[zW,xEA,BN],offset:[-_EA/2+zW/2,0,BN/2],color:"#ccc"})]}),kEA=2,FEA=1.25,CN=.55,MH=.5,uxt=kEA-MH*2,m7A=({color:t="#333"})=>Wt(An,{children:[te(ut,{size:[uxt,FEA,CN],offset:[0,0,CN/2],color:t}),te(ut,{size:[MH,FEA,CN],offset:[kEA/2-MH/2,0,CN/2],color:"#ccc"}),te(ut,{size:[MH,FEA,CN],offset:[-kEA/2+MH/2,0,CN/2],color:"#ccc"})]}),dxt=({pinCount:t,pitch:A,leadWidth:e,padContactLength:i,bodyWidth:o})=>{const n=t/4;A||(A=pxt(t,o)),i||(i=fxt(t)),e||(e=yxt(t,o)),o||(o=A*(n+4));const s=o,r=(n-1)*A/2,a=s+2*i,g=a,c=.8,I=.15,l=(g-o)/2+.5;return Wt(An,{children:[Array.from({length:n}).map((B,C)=>te(on,{position:{x:-g/2-.4,y:C*A-r,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:n}).map((B,C)=>te(on,{rotation:Math.PI,position:{x:g/2+.4,y:C*A-r,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:n}).map((B,C)=>te(on,{rotation:Math.PI/2,position:{x:C*A-r,y:-a/2-.4,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:n}).map((B,C)=>te(on,{rotation:-Math.PI/2,position:{x:C*A-r,y:a/2+.4,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),te(cB,{center:{x:0,y:0,z:0},width:o,length:s,height:1.5,taperRatio:.03,chamferSize:.7,notchPosition:{x:-(s/2-1.5),y:o/2-1.5,z:1.5},notchRadius:1.5/2})]})},pxt=(t,A)=>{switch(t){case 44:case 64:return .8;case 52:return A===14?1:.65;case 208:return .5;default:return .5}},fxt=t=>{switch(t){case 32:return .6;case 40:return .6;case 52:case 64:return .65;case 208:return 1.65;default:return .6}},yxt=(t,A)=>{switch(t){case 44:case 64:return .5;case 52:return A===14?.45:.55;case 208:return .3;default:return .25}},mxt=({numberOfPins:t,pitch:A=2.54,longSidePinLength:e=6,invert:i,faceup:o,rows:n=1})=>{const a=Math.ceil(t/n),g=2.54,c=a*A,I=n>1?(n-1)*g+.63*3:.63*3,l=3,B=-((a-1)/2)*A,C=n>1?-((n-1)*g)/2:0,Q=h=>i||o?-h+2:h;return Wt(An,{children:[te(ut,{color:"#222",size:[c,I,2],center:[0,C,Q(2/2)]}),Array.from({length:t},(h,E)=>{const u=Math.floor(E/a),d=E%a,f=B+d*A,m=-u*g;return Wt(An,{children:[!o&&te(Gs,{color:"gold",children:Wt(yc,{children:[te(ut,{color:"gold",size:[.63,.63,l*.9],center:[f,m,Q(2*.9+2/2)]}),te(ut,{color:"gold",size:[.63/1.8,.63/1.8,l],center:[f,m,Q(2+2/2)]})]})}),te(Gs,{color:"gold",children:Wt(yc,{children:[te(ut,{color:"gold",size:[.63,.63,e*.9],center:[f,m,Q(-e/2*.9)]}),te(ut,{color:"gold",size:[.63/1.8,.63/1.8,e],center:[f,m,Q(-e/2)]})]})})]})})]})},wxt=t=>{const A=["left","bottom","right","top"],{pin_count:e,pn:i,w:o,h:n,p:s,pl:r}=t,a=e/4,g=A[Math.floor((i-1)/a)],c=(i-1)%a,I=s*(a-1),l=s*(a-1),B=-r/2;switch(g){case"left":return{x:-o/2-B,y:l/2-c*s,o:"vert"};case"bottom":return{x:-I/2+c*s,y:-n/2-B,o:"horz"};case"right":return{x:o/2+B,y:-l/2+c*s,o:"vert"};case"top":return{x:I/2-c*s,y:n/2+B,o:"horz"};default:throw new Error("Invalid pin number")}},Dxt=({num_pins:t,cw:A,ccw:e,startingpin:i})=>{const o=[],n=t/4;let s=1;const r={};for(const a of i??[])r[a]=!0;!r.leftside&&!r.topside&&!r.rightside&&!r.bottomside&&(r.leftside=!0),!r.bottompin&&!r.leftpin&&!r.rightpin&&!r.toppin&&(r.leftside?r.toppin=!0:r.topside?r.rightpin=!0:r.rightside?r.bottompin=!0:r.bottomside&&(r.leftpin=!0)),r.leftside&&r.toppin?s=1:r.leftside&&r.bottompin?s=n:r.bottomside&&r.leftpin?s=n+1:r.bottomside&&r.rightpin?s=n*2:r.rightside&&r.bottompin?s=n*2+1:r.rightside&&r.toppin?s=n*3:r.topside&&r.rightpin?s=n*3+1:r.topside&&r.leftpin&&(s=n*4),o.push(-1);for(let a=0;a<t;a++)o[s]=a+1,s++,s>t&&(s=1);return o},Sxt=({num_pins:t=16,bodyWidth:A=9,bodyLength:e=9,bodyThickness:i=.8,thermalPadSize:o,padWidth:n=.25,padLength:s=.25,pitch:r=.5,thermalPadThickness:a=.05})=>{const g=Dxt({num_pins:t,cw:!0,ccw:!0}),c=[];for(let I=0;I<t;I++){const{x:l,y:B,o:C}=wxt({pin_count:t,pn:I+1,w:A,h:e,p:r,pl:s});let Q=n,h=s;C==="vert"&&([Q,h]=[h,Q]);const E=g[I+1];c.push({pn:E,x:l,y:B,pw:Q,pl:h})}return Wt(An,{children:[te(Gs,{color:"grey",children:te(ut,{center:{x:0,y:0,z:i/2},size:[A,e,i]})}),c.map((I,l)=>te(ut,{center:{x:I.x,y:I.y,z:a/2},size:[I.pw,I.pl,a]})),o?.length!==void 0&&o?.width!==void 0&&te(ut,{center:{x:0,y:0,z:a/2},size:[o.width,o.length,a]})]})},bxt=Sxt,_xt=()=>{const a=1.1999999999999997;return Wt(An,{children:[te(on,{rotation:Math.PI,position:{x:2.8/2+a/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),te(on,{rotation:Math.PI,position:{x:2.8/2+a/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),te(on,{position:{x:-2.8/2-a/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),te(on,{position:{x:-2.8/2-a/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),te(on,{position:{x:-2.8/2-a/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),te(cB,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2})]})},xxt=_xt,kxt=({fullWidth:t=2.9,fullLength:A=2.8})=>{const c=(t-1.92)/2+.3;return Wt(An,{children:[te(on,{rotation:Math.PI,position:{x:t/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),te(on,{position:{x:-t/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),te(on,{position:{x:-t/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),te(cB,{center:{x:0,y:0,z:0},width:1.92,length:2.9,height:1.1,straightHeightRatio:.45,heightAboveSurface:.05})]})},GEA=.6,REA=.3,QN=.33,NH=.1,Fxt=GEA-NH*2,w7A=({color:t="#333"})=>Wt(An,{children:[te(ut,{size:[Fxt,REA,QN],offset:[0,0,QN/2],color:t}),te(ut,{size:[NH,REA,QN],offset:[GEA/2-NH/2,0,QN/2],color:"#ccc"}),te(ut,{size:[NH,REA,QN],offset:[-GEA/2+NH/2,0,QN/2],color:"#ccc"})]}),vEA=.4,MEA=.2,hN=.13,LH=.07,Gxt=vEA-LH*2,D7A=({color:t="#333"})=>Wt(An,{children:[te(ut,{size:[Gxt,MEA,hN],offset:[0,0,hN/2],color:t}),te(ut,{size:[LH,MEA,hN],offset:[vEA/2-LH/2,0,hN/2],color:"#ccc"}),te(ut,{size:[LH,MEA,hN],offset:[-vEA/2+LH/2,0,hN/2],color:"#ccc"})]}),NEA=3.2,LEA=1.6,EN=.9,UH=.5,Rxt=NEA-UH*2,S7A=({color:t="#333"})=>Wt(An,{children:[te(ut,{size:[Rxt,LEA,EN],offset:[0,0,EN/2],color:t}),te(ut,{size:[UH,LEA,EN],offset:[NEA/2-UH/2,0,EN/2],color:"#ccc"}),te(ut,{size:[UH,LEA,EN],offset:[-NEA/2+UH/2,0,EN/2],color:"#ccc"})]}),UEA=3.2,HEA=2.5,uN=1,HH=.6,vxt=UEA-HH*2,b7A=({color:t="#333"})=>Wt(An,{children:[te(ut,{size:[vxt,HEA,uN],offset:[0,0,uN/2],color:t}),te(ut,{size:[HH,HEA,uN],offset:[UEA/2-HH/2,0,uN/2],color:"#ccc"}),te(ut,{size:[HH,HEA,uN],offset:[-UEA/2+HH/2,0,uN/2],color:"#ccc"})]}),YEA=5,JEA=2.5,dN=1.4,YH=.6,Mxt=YEA-YH*2,_7A=({color:t="#333"})=>Wt(An,{children:[te(ut,{size:[Mxt,JEA,dN],offset:[0,0,dN/2],color:t}),te(ut,{size:[YH,JEA,dN],offset:[YEA/2-YH/2,0,dN/2],color:"#ccc"}),te(ut,{size:[YH,JEA,dN],offset:[-YEA/2+YH/2,0,dN/2],color:"#ccc"})]}),TEA=6.3,KEA=3.2,pN=1.8,JH=.8,Nxt=TEA-JH*2,x7A=({color:t="#333"})=>Wt(An,{children:[te(ut,{size:[Nxt,KEA,pN],offset:[0,0,pN/2],color:t}),te(ut,{size:[JH,KEA,pN],offset:[TEA/2-JH/2,0,pN/2],color:"#ccc"}),te(ut,{size:[JH,KEA,pN],offset:[-TEA/2+JH/2,0,pN/2],color:"#ccc"})]}),Lxt=({numberOfPins:t,pitch:A=2.54,legsLength:e=3,outerDiameter:i=.945,innerDiameter:o=.945,rows:n=1})=>{const s=o/1.5,r=s*2+i,a=5,g=Math.ceil(t/n),c=2.54,I=(g-1)*A+i+A/2,l=n>1?(n-1)*c+r:r,B=s*1.6,C=-((g-1)/2)*A,Q=n>1?-((n-1)*c)/2:0,h=te(Gs,{color:"#1a1a1a",children:Wt(rG,{children:[te(ut,{color:"#000",size:[I,l,a],center:[0,Q,a/2]}),Array.from({length:t},(E,u)=>{const d=Math.floor(u/g),f=u%g,m=C+f*A,D=-d*c;return o?te(Ef,{height:a+.1,radius:o/2,center:[m,D,a/2],color:"#222"},u):te(ut,{size:[B,B,a],center:[m,D,a/2]},u)})]})});return Wt(An,{children:[h,Array.from({length:t},(E,u)=>{const d=Math.floor(u/g),f=u%g,m=C+f*A,D=-d*c;return Wt(Gs,{color:"silver",children:[Wt(yc,{children:[te(ut,{color:"silver",size:[s,s,e*.9],center:[m,D,-e/2*.9]}),te(ut,{color:"silver",size:[s/1.8,s/1.8,e],center:[m,D,-e/2]})]}),te(ut,{color:"silver",size:[B,B,B*.5],center:[m,D,B/2*.5]})]},u)})]})},Uxt=({width:t,length:A,innerDiameter:e=1})=>{const i=t,o=A,n=t*.7,s=e/2.5;return Wt(An,{children:[te(FH,{color:"#1a1a1f",center:[0,0,n/2],size:[o,o,n],roundRadius:.3}),te(FH,{color:"#f2f2f2",center:[0,0,n+n*.1/2.5],size:[o,o,n*.1],roundRadius:.14}),te(Ef,{color:"#1a1a1f",height:n*.8,radius:i/3,center:[0,0,n+n*.8/2]}),te(Ef,{color:"#1a1a1f",height:n*.2,radius:e/2,center:[o/3,o/3,n+n*.1/2]}),te(Ef,{color:"#1a1a1f",height:n*.2,radius:e/2,center:[-o/3,-o/3,n+n*.1/2]}),te(Ef,{color:"#1a1a1f",height:n*.2,radius:e/2,center:[-o/3,o/3,n+n*.1/2]}),te(Ef,{color:"#1a1a1f",height:n*.2,radius:e/2,center:[o/3,-o/3,n+n*.1/2]}),te(XW,{thickness:e/3,width:s,horizontalLength:o*.8,verticalLength:n/2,position:{x:-i/2,y:-o/2,z:-n*1.2}}),te(XW,{thickness:e/3,width:s,horizontalLength:o*.8,verticalLength:n/2,position:{x:-i/2,y:o/2,z:-n*1.2},rotation:Math.PI}),te(XW,{thickness:e/3,width:s,horizontalLength:o*.8,verticalLength:n/2,position:{x:i/2,y:o/2,z:-n*1.2},rotation:Math.PI}),te(XW,{thickness:e/3,width:s,horizontalLength:o*.8,verticalLength:n/2,position:{x:i/2+e/3.6,y:-o/2,z:-n*1.2}})]})},XW=t=>{const{thickness:A,width:e,horizontalLength:i,verticalLength:o,rotation:n=0,position:s}=t,r=[[0,i],[-o/3,i/3],[-o/5,i/4],[0,0]],a=DEA(r,A);return te(Gs,{color:"#f2f2f2",children:te(to,{offset:{x:s?.x||0,y:s?.y||0,z:s?.z||0},children:te(RQ,{rotation:[0,55,n],children:te(RH,{height:e,children:te(GH,{points:a.map(g=>[g.y,g.x])})})})})})},Hxt=({pinCount:t,leadLength:A,leadWidth:e,pitch:i,bodyWidth:o})=>{const n=Math.ceil(t/2),s=(n-1)*i/2,r=.25,a=1,g=.8,c=A*0,I=i*(n-1)+e+.2,l=o*.55;return Wt(An,{children:[Array.from({length:n}).map((B,C)=>te(on,{position:{x:-o/2-c,y:C*i-s,z:r/2},width:e,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),Array.from({length:n}).map((B,C)=>te(on,{rotation:Math.PI,position:{x:o/2+c,y:C*i-s,z:r/2},width:e,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),te(cB,{center:{x:0,y:0,z:r/2},width:l,length:I,height:a})]})},Yxt=({pinCount:t,pitch:A,leadWidth:e,leadLength:i,bodyWidth:o,bodyLength:n})=>{const s=t===8?{pitch:.65,leadWidth:.3}:{pitch:.5,leadWidth:.225},r=isNaN(parseFloat(A))?s.pitch:parseFloat(A),a=isNaN(parseFloat(e))?s.leadWidth:parseFloat(e)*.8,g=isNaN(parseFloat(o))?2.6:parseFloat(o)*.8,c=isNaN(parseFloat(n))?2+Number(r)*1.4:parseFloat(n),I=t/2,l=(I-1)*r/2,B=.15,C=.8,Q=4.5,h=(Q-g)/2,E=h*.5;return Wt(An,{children:[Array.from({length:I}).map((u,d)=>te(on,{position:{x:-Q/2,y:l-d*r,z:B/2},width:a,thickness:B,padContactLength:E+.05,bodyDistance:h+.1,height:C})),Array.from({length:I}).map((u,d)=>te(on,{rotation:Math.PI,position:{x:Q/2,y:l-d*r,z:B/2},width:a,thickness:B,padContactLength:E+.05,bodyDistance:h+.1,height:C})),te(cB,{center:{x:0,y:0,z:B/2},width:g,length:c,height:1})]})},Jxt=()=>Wt(An,{children:[te(ut,{color:"#ccc",size:[.5,.6,.12],center:[-.725,0,.12/2]}),te(ut,{color:"#ccc",size:[.5,.6,.12],center:[.725,0,.12/2]}),te(Gs,{color:"#222",children:Wt(kh,{children:[te(to,{z:.3/2,children:te(ut,{size:[1.65,.8,.3]})}),Wt(yc,{children:[te(to,{z:.3,children:te(ut,{size:[1.65,.8,.01]})}),te(to,{z:.6,children:te(ut,{size:[1.65-.2,.8-.2,.01]})})]})]})})]}),Txt=()=>Wt(An,{children:[te(ut,{color:"#ccc",size:[.26,.51,.12],center:[-.325,0,.12/2]}),te(ut,{color:"#ccc",size:[.26,.51,.12],center:[.325,0,.12/2]}),te(Gs,{color:"#222",children:te(to,{z:.47/2+.02,children:te(ut,{size:[.98,.58,.47]})})}),te(ut,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,.26/2,.47/4]}),te(ut,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,-.26/2,.47/4]}),te(ut,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[.65/2,0,.47/4]}),te(ut,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[-.65/2,0,.47/4]})]}),Kxt=()=>{const g=te(Gs,{color:"#1a1a1a",children:Wt(kh,{children:[Wt(yc,{children:[te(to,{z:.13,children:te(ut,{size:[4,3,.03]})}),te(to,{z:1.15,children:te(ut,{size:[4.4,3.4,.01]})})]}),Wt(yc,{children:[te(to,{z:1.15,children:te(ut,{size:[4.4,3.4,.01]})}),te(to,{z:2.3,children:te(ut,{size:[4,3,.01]})})]})]})}),c=({xDir:I})=>{const C=I*1.78,Q=I*(3.4/2-.2/2+1),h=I*(3.4/2-.2/2),E=Math.abs(h-Q),u=(Q+h)/2;return te(Gs,{color:"#c0c0c0",children:Wt(kh,{children:[te(ut,{size:[2.3*.8,1.45,.2],center:[C,0,.2/2]}),te(ut,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),te(ut,{size:[E,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return Wt(An,{children:[te(c,{xDir:1}),te(c,{xDir:-1}),g]})},Pxt=()=>{const g=te(Gs,{color:"#1a1a1a",children:Wt(kh,{children:[Wt(yc,{children:[te(to,{z:.13,children:te(ut,{size:[4,3,.03]})}),te(to,{z:1.15,children:te(ut,{size:[4.4,3.4,.01]})})]}),Wt(yc,{children:[te(to,{z:1.15,children:te(ut,{size:[4.4,3.4,.01]})}),te(to,{z:2.3,children:te(ut,{size:[4,3,.01]})})]})]})}),c=({xDir:I})=>{const C=I*1.78,Q=I*(3.4/2-.2/2+1),h=I*(3.4/2-.2/2),E=Math.abs(h-Q),u=(Q+h)/2;return te(Gs,{color:"#c0c0c0",children:Wt(kh,{children:[te(ut,{size:[2.3*.8,1.45,.2],center:[C,0,.2/2]}),te(ut,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),te(ut,{size:[E,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return Wt(An,{children:[te(c,{xDir:1}),te(c,{xDir:-1}),g]})},qxt=()=>{const g=te(Gs,{color:"#1a1a1a",children:Wt(kh,{children:[Wt(yc,{children:[te(to,{z:.21000000000000002,children:te(ut,{size:[6.3999999999999995,5.6,.03]})}),te(to,{z:1.15,children:te(ut,{size:[6.8,6,.01]})})]}),Wt(yc,{children:[te(to,{z:1.15,children:te(ut,{size:[6.8,6,.01]})}),te(to,{z:2.3,children:te(ut,{size:[6.3999999999999995,5.6,.01]})})]})]})}),c=({xDir:I})=>{const C=I*3.08,Q=I*(6/2-.2/2+1),h=I*(6/2-.2/2),E=Math.abs(h-Q),u=(Q+h)/2;return te(Gs,{color:"#c0c0c0",children:Wt(kh,{children:[te(ut,{size:[2.3*.8,2.95,.2],center:[C,0,.2/2]}),te(ut,{size:[.2,2.95,1.14],center:[Q,0,1.14/2+.2]}),te(ut,{size:[E,2.95,.2],center:[u,0,.2/2+1.14]})]})})};return Wt(An,{children:[te(c,{xDir:1}),te(c,{xDir:-1}),g]})},Oxt=()=>{const I=te(Gs,{color:"#222",children:Wt(kh,{children:[te(to,{z:.27,children:te(ut,{size:[2.9,1.9,.54]})}),Wt(yc,{children:[te(to,{z:.54,children:te(ut,{size:[2.9,1.9,.01]})}),te(to,{z:1.08,children:te(ut,{size:[2.6999999999999997,1.7,.01]})})]})]})});return Wt(An,{children:[te(ut,{color:"#ccc",size:[1,1.2,.25],center:[-1.3,0,.25/2]}),te(ut,{color:"#ccc",size:[1,1.2,.25],center:[1.3,0,.25/2]}),I]})},Wxt=()=>Wt(An,{children:[te(ut,{color:"#ccc",size:[1,.6,.12],center:[-1.3,0,.12/2]}),te(ut,{color:"#ccc",size:[1,.6,.12],center:[1.3,0,.12/2]}),te(Gs,{color:"#222",children:Wt(kh,{children:[te(to,{z:.55/2,children:te(ut,{size:[2.7,1.6,.55]})}),Wt(yc,{children:[te(to,{z:.55,children:te(ut,{size:[2.7,1.6,.01]})}),te(to,{z:1.1,children:te(ut,{size:[2.7-.2,1.6-.2,.01]})})]})]})})]}),Zxt=()=>Wt(An,{children:[te(ut,{color:"#ccc",size:[1,.9,.2],center:[-1.3,0,.2/2]}),te(ut,{color:"#ccc",size:[1,.9,.2],center:[1.3,0,.2/2]}),te(Gs,{color:"#222",children:Wt(kh,{children:[te(to,{z:.2/2,children:te(ut,{size:[2.75,1.8,.2]})}),Wt(yc,{children:[te(to,{z:.2,children:te(ut,{size:[2.75,1.8,.01]})}),te(to,{z:1,children:te(ut,{size:[2.75-.4,1.8-.4,.01]})})]})]})}),te(ut,{color:"#777",size:[.2,1.8-.4,.01],center:[-1.3+.4,0,1]})]}),Vxt=()=>Wt(An,{children:[te(ut,{color:"#ccc",size:[.9,.9,.2],center:[-1.225,0,.2/2]}),te(ut,{color:"#ccc",size:[.9,.9,.2],center:[1.225,0,.2/2]}),te(Gs,{color:"#222",children:Wt(kh,{children:[Wt(yc,{children:[te(to,{z:.2,children:te(ut,{size:[2.6-.1/2,1.7-.1/2,.01]})}),te(to,{z:.01,children:te(ut,{size:[2.6-.1,1.7-.1,.01]})})]}),Wt(yc,{children:[te(to,{z:.2,children:te(ut,{size:[2.6,1.7,.01]})}),te(to,{z:1,children:te(ut,{size:[2.6-.4,1.7-.4,.01]})})]})]})}),te(ut,{color:"#777",size:[.2*2.7,1.7-.4,.02],center:[-1.225+.4,0,1]})]}),jxt=()=>Wt(An,{children:[te(ut,{color:"#ccc",size:[.9,1.75,.2],center:[-1.825,0,.2/2]}),te(ut,{color:"#ccc",size:[.9,1.75,.2],center:[1.825,0,.2/2]}),te(Gs,{color:"#222",children:Wt(kh,{children:[Wt(yc,{children:[te(to,{z:.2,children:te(ut,{size:[3.8-.05/2,2.5-.05/2,.01]})}),te(to,{z:.01,children:te(ut,{size:[3.8-.05,2.5-.05,.01]})})]}),Wt(yc,{children:[te(to,{z:.2,children:te(ut,{size:[3.8,2.5,.01]})}),te(to,{z:1,children:te(ut,{size:[3.8-.4,2.5-.4,.01]})})]})]})}),te(ut,{color:"#777",size:[.2*2.7,2.5-.4,.02],center:[-1.825+.4,0,1]})]}),zxt=()=>Wt(An,{children:[te(ut,{color:"#ccc",size:[.4,.25,.14],center:[-.4,0,.14/2]}),te(ut,{color:"#ccc",size:[.4,.25,.14],center:[.4,0,.14/2]}),te(Gs,{color:"#222",children:Wt(kh,{children:[te(to,{z:.14/2,children:te(ut,{size:[.8,.6,.14]})}),Wt(yc,{children:[te(to,{z:.14,children:te(ut,{size:[.8,.6,.01]})}),te(to,{z:.37,children:te(ut,{size:[.8-.1,.6-.1,.01]})})]})]})})]}),Xxt=()=>{const c=3.0999999999999996;return Wt(An,{children:[te(on,{rotation:Math.PI,position:{x:6.6/2+c/4,y:0,z:.25/2},width:3,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),te(on,{position:{x:-6.6/2-c/4,y:0,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),te(on,{position:{x:-6.6/2-c/4,y:-2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),te(on,{position:{x:-6.6/2-c/4,y:2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),te(cB,{center:{x:0,y:0,z:0},width:3.5,length:6.5,height:1.7,includeNotch:!1,taperRatio:.06,straightHeightRatio:.45})]})},$xt=()=>Wt(An,{children:[Array.from({length:16}).map((B,C)=>te(on,{position:{x:-10.5/2,y:C*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((B,C)=>te(on,{rotation:Math.PI,position:{x:10.5/2,y:C*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((B,C)=>te(on,{rotation:Math.PI/2,position:{x:C*.5-3.75,y:-10.5/2,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((B,C)=>te(on,{rotation:-Math.PI/2,position:{x:C*.5-3.75,y:10.5/2,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),te(cB,{center:{x:0,y:0,z:0},width:9,length:9,height:1.2,chamferSize:.7,taperRatio:.05,notchPosition:{x:-3.5,y:3.5,z:1.2},notchRadius:1.2/2})]}),Akt=$xt,ekt=()=>{const g=.7999999999999998;return Wt(An,{children:[te(on,{rotation:Math.PI,position:{x:2.05/2+g/4,y:0,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),te(on,{position:{x:-2.05/2-g/4,y:-.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),te(on,{position:{x:-2.05/2-g/4,y:.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),te(cB,{center:{x:0,y:0,z:0},width:1.25,length:2,height:.9,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})]})},tkt=({pinCount:t,pitch:A,leadWidth:e,padContactLength:i,bodyWidth:o})=>{const n=t/4;if(n!==Math.floor(n))throw new Error(`LQFP pinCount must be divisible by 4, got ${t}`);A||(A=.5),i||(i=.6),e||(e=.22),o||(o=A*(n+4));const s=o,r=(n-1)*A/2,a=s+3.3*i,g=a,c=.8,I=.2,l=(g-o)/2+.4;return Wt(An,{children:[Array.from({length:n}).map((B,C)=>te(on,{position:{x:-g/2-.36,y:C*A-r,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:n}).map((B,C)=>te(on,{rotation:Math.PI,position:{x:g/2+.36,y:C*A-r,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:n}).map((B,C)=>te(on,{rotation:Math.PI/2,position:{x:C*A-r,y:-a/2-.36,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:n}).map((B,C)=>te(on,{rotation:-Math.PI/2,position:{x:C*A-r,y:a/2+.36,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),te(cB,{center:{x:0,y:0,z:0},width:o,length:s,height:1.5,heightAboveSurface:.1,taperRatio:.04,chamferSize:.7,notchPosition:{x:-(s/2-1.5),y:s/2-1.5,z:1.5},notchRadius:1.5/2})]})},ikt=()=>{const i=.20900000000000002,o=.1,n=.3,s=.1,r=.2;return Wt(An,{children:[te(Gs,{color:"#222",children:Wt(kh,{children:[te(ut,{size:[.85,1.2,i],center:[0,0,i/2]}),Wt(yc,{children:[te(to,{z:i,children:te(ut,{size:[.85,1.2,.01]})}),te(to,{z:.38,children:te(ut,{size:[.85-o,1.2-o,.01]})})]})]})}),te(ut,{color:"#ccc",size:[n,.25,s],center:[.55,0,s/2]}),te(ut,{color:"#ccc",size:[n,r,s],center:[-.55,.4,s/2]}),te(ut,{color:"#ccc",size:[n,r,s],center:[-.55,-.4,s/2]})]})},okt=({num_pins:t,bodyWidth:A=5.3,bodyLength:e=5.3,bodyThickness:i=1,thermalPadSize:o,padWidth:n=e/5.3*.6,padLength:s=e/5.3*1,pitch:r=.5,thermalPadThickness:a=.2})=>{const g=[],c=Math.floor(t/2),I=r*(c-1);for(let l=0;l<t;l++){const B=l<c?"left":"right",C=l%c,Q=I/2-C*r,h=s,E=n,u=B==="left"?-A/2+h/2:A/2-h/2,d=l+1;g.push({pinNumber:d,x:u,y:Q,padSizeX:h,padSizeY:E})}return Wt(An,{children:[te(cB,{center:{x:0,y:0,z:0},width:A,length:e,height:i,heightAboveSurface:0,color:"grey",chamferSize:.2,taperRatio:0,notchPosition:{x:-(A/2-s),y:e/2-s,z:i}}),g.map((l,B)=>te(ut,{center:[l.x,l.y,a/2],size:[l.padSizeX,l.padSizeY,a]})),o?.length!==void 0&&o?.width!==void 0&&te(ut,{center:[0,0,a/2],size:[o.width,o.length,a]})]})},nkt=({bodyLength:t=10.2,bodyWidth:A=4.65,bodyHeight:e=13.46,leadSpacing:i=5,leadDiameter:o=.8,leadLength:n=12.7,color:s="#ddd",leadColor:r="#b87333"})=>{const a=t/2,g=A/2,c=a-g,I=i/2,l=.85;return Wt(An,{children:[Wt(Gs,{color:s,children:[Wt(yc,{children:[te(uf,{height:e,roundRadius:.5,radius:g,center:[-c,0,e]}),te(uf,{height:e,roundRadius:.5,radius:g,center:[c,0,e]})]}),Wt(yc,{children:[te(uf,{height:l,roundRadius:.1,radius:g+.85,center:[-c,0,e/2+l/2]}),te(uf,{height:l,roundRadius:.1,radius:g+.85,center:[c,0,e/2+l/2]})]})]}),Wt(Gs,{color:r,children:[te(Ef,{height:n+e/2,radius:o/2,center:[-I+.06,0,-(n/2)+e/2]}),te(Ef,{height:n+e/2,radius:o/2,center:[I-.06,0,-(n/2)+e/2]})]})]})},skt=({bodyLength:t=1.4,bodyDiameter:A=1.1,color:e="#3a3a3aff",contactColor:i="#c6c6c6",cathodeIdentification:o="#111"})=>Wt(An,{children:[te(Gs,{color:e,children:Wt(RQ,{rotation:[0,"90deg",0],children:[te(FH,{size:[A,A,t-.2],roundRadius:.2,center:[-A/2,0,.05]}),te(Ef,{height:.2/2,radius:A/2-.2,center:[-A/2,0,-t/2+.2/2]})]})}),te(Gs,{color:o,children:te(RQ,{rotation:[0,"90deg",0],children:te(FH,{size:[A*1.01,A*1.01,t/3],roundRadius:.2,center:[-A/2,0,-t/4+.1]})})}),te(Gs,{color:i,children:te(RQ,{rotation:[0,"90deg",0],children:te(uf,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,-t/2]})})}),te(Gs,{color:i,children:te(RQ,{rotation:[0,"90deg",0],children:te(uf,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,t/2]})})})]}),rkt=({bodyLength:t=3.5,bodyDiameter:A=1.5,color:e="#3a3a3aff",contactColor:i="#c6c6c6"})=>Wt(An,{children:[te(Gs,{color:e,children:te(RQ,{rotation:[0,"90deg",0],children:te(uf,{height:t,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),te(Gs,{color:i,children:te(RQ,{rotation:[0,"90deg",0],children:te(uf,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,-t/2]})})}),te(Gs,{color:i,children:te(RQ,{rotation:[0,"90deg",0],children:te(uf,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,t/2]})})})]}),akt=({bodyLength:t=3.9,bodyDiameter:A=2.5,color:e="#3a3a3aff",contactColor:i="#c6c6c6"})=>Wt(An,{children:[te(Gs,{color:e,children:te(RQ,{rotation:[0,"90deg",0],children:te(uf,{height:t,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),te(Gs,{color:i,children:te(RQ,{rotation:[0,"90deg",0],children:te(uf,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,-t/2]})})}),te(Gs,{color:i,children:te(RQ,{rotation:[0,"90deg",0],children:te(uf,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,t/2]})})})]}),gkt=({pinCount:t,padContactLength:A=.6,leadWidth:e=.41,pitch:i=1.27})=>{if(t%2!==0)throw new Error("MS012 pinCount must be even");const o=t/2,n=4.9,s=3.9,r=(o-1)*i/2,a=.2;return Wt(An,{children:[Array.from({length:o}).map((g,c)=>te(on,{position:{x:-s/2-A-.3,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:o}).map((g,c)=>te(on,{rotation:Math.PI,position:{x:s/2+A+.3,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),te(cB,{center:{x:0,y:0,z:a/2},width:s,length:n,height:1.55,notchPosition:{x:-.95,y:n/2-1,z:1.55},heightAboveSurface:.17,taperRatio:.09})]})},ckt=({pinCount:t=16,padContactLength:A=.6,leadWidth:e=.41,pitch:i=1.27})=>{if(t!==16)throw new Error("MS013 only supports 16 pins");const o=t/2,n=7.5,s=10.3,r=(o-1)*i/2,a=.2;return Wt(An,{children:[Array.from({length:o}).map((g,c)=>te(on,{position:{x:-n/2-A-.3,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:o}).map((g,c)=>te(on,{rotation:Math.PI,position:{x:n/2+A+.3,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),te(cB,{center:{x:0,y:0,z:a/2},width:n,length:s,height:1.1,notchPosition:{x:-2.25,y:s/2-1.5,z:1.1},heightAboveSurface:.17,taperRatio:.05})]})},Ikt=()=>{const Q=7.050000000000001,h=24.95+6.5/2;return te(to,{center:[0,0,1],children:Wt(An,{children:[Wt(RQ,{rotation:[0,55,-55],children:[Wt(rG,{children:[te(ut,{color:"#ccc",size:[6.5+.1,9.9,1.3],center:[h,0,1.3-2]}),te(Ef,{color:"black",center:[h,0,1.3-2],radius:3/2,height:1.3*1.2})]}),te(Gs,{color:"#222",children:te(cB,{width:9.9,length:9.9,height:4.5,center:{x:20,y:0,z:-2.4},includeNotch:!1,straightHeightRatio:.3,taperRatio:.04,heightAboveSurface:1})})]}),te(RQ,{rotation:[0,55,55],children:Array.from({length:3}).map((E,u)=>{const d=Q,f=(u-1)*2.7,m=-.5-.6;return Wt(Gs,{color:"gold",children:[Wt(yc,{children:[te(to,{center:[15.05-4.5/2+.1,f,m],children:te(ut,{size:[4.5,.81+1,.5]})}),te(to,{center:[15.05-4.5/2-1+.1,f,m],children:te(ut,{size:[4.5,.81,.5]})})]}),te(to,{center:[d,f,m],children:te(ut,{size:[16+.1,.81,.5]})})]},`prong-${u}`)})})]})})},lkt=()=>{const g=1.1999999999999997;return Wt(An,{children:[te(on,{rotation:Math.PI,position:{x:2.8/2+g/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),te(on,{rotation:Math.PI,position:{x:2.8/2+g/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),te(on,{rotation:Math.PI,position:{x:2.8/2+g/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),te(on,{position:{x:-2.8/2-g/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),te(on,{position:{x:-2.8/2-g/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),te(on,{position:{x:-2.8/2-g/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),te(cB,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2,straightHeightRatio:.6,notchPosition:{x:-.4,y:1.2/2+.4,z:1.2+.05},notchRadius:.1})]})},Bkt=()=>Wt(An,{children:[te(cB,{center:{x:0,y:0,z:0},width:.8,length:1,height:.37,heightAboveSurface:0,color:"#1a1a1a",taperRatio:.15,straightHeightRatio:0,notchPosition:{x:-.8/4,y:.7/2.2,z:.37+.1}}),[0,1,2].map(g=>{const c=-.35+g*.35;return te(ut,{center:[-.8/2+.19/2-.1,c,.12/2],size:[.19,.15,.12]})}),[0,1,2].map(g=>{const c=-.35+g*.35;return te(ut,{center:[.8/2-.19/2+.1,c,.12/2],size:[.19,.15,.12]})})]}),Ckt=()=>{const s="#222",a=[.43,.4,1.32],g=[.43,.4,.25],c=[0,0,-.66],I=[0,0,-1.32],l=[0,1.28,-2.72],B=[0,1.28,-8.9],C=-7.5;return Wt(to,{center:[0,1,10.5],children:[te(Gs,{color:s,children:Wt(rG,{children:[te(to,{center:[0,0,2.25],children:te(Ef,{radius:2.4,height:4.5})}),te(to,{center:[0,-1.8499999999999999,2.25],children:te(ut,{size:[2.4*2,1.1,4.5+.2]})})]})}),te(to,{center:c,children:te(ut,{size:a})}),Wt(yc,{children:[te(to,{center:I,children:te(ut,{size:g})}),te(to,{center:l,children:te(ut,{size:g})})]}),te(to,{center:B,children:te(ut,{size:[.43,.4,12.2]})}),te(to,{center:[1.3,0,C],children:te(ut,{size:[.43,.4,15]})}),te(to,{center:[-1.3,0,C],children:te(ut,{size:[.43,.4,15]})})]})},Qkt=()=>Wt(An,{children:[te(on,{rotation:Math.PI,position:{x:2/2+.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),te(on,{rotation:Math.PI,position:{x:2/2+.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),te(on,{rotation:Math.PI,position:{x:2/2+.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),te(on,{position:{x:-2/2-.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),te(on,{position:{x:-2/2-.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),te(on,{position:{x:-2/2-.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),te(cB,{center:{x:0,y:0,z:0},width:1.25,length:2,height:1.1,straightHeightRatio:.6,notchPosition:{x:-.375,y:1.1/2+.2,z:1.1},heightAboveSurface:.1})]}),hkt=Qkt,Ekt=()=>Wt(An,{children:[te(cB,{center:{x:0,y:0,z:.05},width:1,length:1.45,height:.5,heightAboveSurface:0,color:"#1a1a1a",taperRatio:0,includeNotch:!1}),[0,1,2].map(r=>{const a=-.5+r*.5;return te(ut,{center:[-1/2+.3/2,a,.05/2],size:[.3,.2,.05]})}),[0,1,2].map(r=>{const a=-.5+r*.5;return te(ut,{center:[1/2-.3/2,a,.05/2],size:[.3,.2,.05]})})]}),ukt=()=>Wt(An,{children:[te(on,{position:{x:-2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),te(on,{rotation:Math.PI,position:{x:2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),te(Gs,{color:"#222",children:te(cB,{center:{x:0,y:0,z:0},width:1.7,length:1.25,height:.95,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})}),te(ut,{color:"#777",size:[1.7/3,1.25-.075,.02],center:[-.85*2/3+.035,0,.95+.05]})]}),dkt=()=>Wt(An,{children:[te(ut,{color:"#ccc",size:[.4,.325,.175],center:[-1.05,0,.175/2]}),te(ut,{color:"#ccc",size:[.4,.325,.175],center:[1.05,0,.175/2]}),te(Gs,{color:"#222",children:Wt(kh,{children:[te(to,{z:.175/2,children:te(ut,{size:[1.7,1.25,.175]})}),Wt(yc,{children:[te(to,{z:.175,children:te(ut,{size:[1.7,1.25,.01]})}),te(to,{z:.725,children:te(ut,{size:[1.7-.2,1.25-.2,.01]})})]})]})}),te(ut,{color:"#777",size:[1.7/3,1.25-.2,.02],center:[-1.05+1.7/4.4+.2,0,.725]})]}),pkt=()=>{const s=-1.0474999999999999,r=1.775/2+.4/2-.04;return Wt(An,{children:[te(ut,{color:"#ccc",size:[.4,.325,.13],center:[s,0,.13/2]}),te(ut,{color:"#ccc",size:[.4,.325,.13],center:[r,0,.13/2]}),te(Gs,{color:"#222",children:te(cB,{width:1.775,length:1.25,height:.725,center:{x:0,y:0,z:0},heightAboveSurface:0,straightHeightRatio:.7,taperRatio:.06,includeNotch:!1})}),te(ut,{color:"#777",size:[1.775/3,1.25-.05,.02],center:[s+1.775/4.4+.2,0,.725]})]})},fkt=({footprint:t})=>{const A=rxt.string(t).json();switch(A.fn){case"dip":return te(lxt,{numPins:A.num_pins,pitch:A.p,bodyWidth:A.w});case"tssop":return te(Cxt,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"msop":return te(Qxt,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"vssop":return te(Yxt,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w,bodyLength:A.h});case"qfp":return te(dxt,{pinCount:A.num_pins,pitch:A.p,leadWidth:A.pw,padContactLength:A.pl,bodyWidth:A.w});case"tqfp":return te(Akt,{});case"lqfp":return te(tkt,{pinCount:A.num_pins});case"qfn":{const o=typeof A.thermalpad?.x=="number"&&typeof A.thermalpad?.y=="number";return te(bxt,{num_pins:A.num_pins,bodyWidth:A.w,bodyLength:A.h,pitch:A.p,padLength:A.pl,padWidth:A.pw,thermalPadSize:o?{width:A.thermalpad.x,length:A.thermalpad.y}:void 0})}case"dfn":{const o=typeof A.thermalpad?.x=="number"&&typeof A.thermalpad?.y=="number";return te(okt,{num_pins:A.num_pins,bodyWidth:A.w,bodyLength:A.h,pitch:A.p,padLength:A.pl,padWidth:A.pw,thermalPadSize:o?{width:A.thermalpad.x,length:A.thermalpad.y}:void 0})}case"pinrow":{const o=t.match(/_rows(\d+)/),n=o&&o[1]?parseInt(o[1],10):1;if(A.male)return te(mxt,{numberOfPins:A.num_pins,pitch:A.p,invert:A.invert,faceup:A.faceup,rows:n});if(A.female)return te(Lxt,{numberOfPins:A.num_pins,pitch:A.p,rows:n})}case"cap":switch(A.imperial){case"0402":return te(f7A,{color:"#856c4d"});case"0603":return te(y7A,{color:"#856c4d"});case"0805":return te(m7A,{color:"#856c4d"});case"0201":return te(w7A,{color:"#856c4d"});case"01005":return te(D7A,{color:"#856c4d"});case"1206":return te(S7A,{color:"#856c4d"});case"1210":return te(b7A,{color:"#856c4d"});case"2010":return te(_7A,{color:"#856c4d"});case"2512":return te(x7A,{color:"#856c4d"})}case"sot235":return te(xxt,{});case"sot457":return te(lkt,{});case"sot223":return te(Xxt,{});case"sot23w":return te(kxt,{});case"sot323":return te(ekt,{});case"sod323f":return te(dkt,{});case"sod323fl":return te(pkt,{});case"sot363":return te(hkt,{});case"sot886":return te(Ekt,{});case"sot963":return te(Bkt,{});case"pushbutton":return te(Uxt,{width:A.w,length:A.h,innerDiameter:A.id});case"soic":return te(Hxt,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"sod523":return te(Jxt,{});case"sod882":return te(Txt,{});case"sma":return te(Kxt,{});case"smb":return te(Pxt,{});case"smc":return te(qxt,{});case"smf":return te(Oxt,{});case"sod123f":return te(Wxt,{});case"sod123fl":return te(Zxt,{});case"sod123w":return te(Vxt,{});case"sod128":return te(jxt,{});case"sod323":return te(ukt,{});case"sod923":return te(zxt,{});case"hc49":return te(nkt,{});case"micromelf":return te(skt,{});case"minimelf":return te(rkt,{});case"melf":return te(akt,{});case"ms012":return te(gkt,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"ms013":return te(ckt,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"sot723":return te(ikt,{});case"to220":return te(Ikt,{});case"to92":return te(Ckt,{})}const e=t.match(/_color\(([^)]+)\)/),i=e?e[1]:void 0;switch(A.imperial){case"0402":return te(f7A,{color:i});case"0603":return te(y7A,{color:i});case"0805":return te(m7A,{color:i});case"0201":return te(w7A,{color:i});case"01005":return te(D7A,{color:i});case"1206":return te(S7A,{color:i});case"1210":return te(b7A,{color:i});case"2010":return te(_7A,{color:i});case"2512":return te(x7A,{color:i})}return null},ykt=t=>t&&typeof t=="object"&&"type"in t,fN=t=>{if(typeof t=="number")return t;if(typeof t=="string"){const A=/^(-?\d+(?:\.\d+)?)\s*deg$/i.exec(t);if(A)return parseFloat(A[1])*Math.PI/180;const e=Number(t);if(!Number.isNaN(e))return e}return 0},mkt=t=>Array.isArray(t)?[Number(t[0])||0,Number(t[1])||0,Number(t[2])||0]:typeof t=="object"&&t?[Number(t.x)||0,Number(t.y)||0,Number(t.z)||0]:[0,0,0];function dD(t,A,e){const{jscad:{primitives:i,booleans:o,hulls:n,geometries:s,extrusions:r,transforms:a}}=e;if(t==null||t===!1)return[];if(Array.isArray(t))return t.flatMap(l=>dD(l,A,e));if(!ykt(t))return[];const{type:g,props:c,children:I}=t;if(g===E7A)return(I??[]).flatMap(l=>dD(l,A,e));if(g===Gs){const l=c?.color;return(I??[]).flatMap(B=>dD(B,l??A,e))}if(g===to){const l=mkt(c?.offset??c?.center??{x:c?.x,y:c?.y,z:c?.z});return(I??[]).flatMap(C=>dD(C,A,e)).map(({geom:C,color:Q})=>({geom:a.translate(l,C),color:Q??A}))}if(g===RQ){const l=Array.isArray(c?.rotation)?[fN(c.rotation[0]),fN(c.rotation[1]),fN(c.rotation[2])]:[fN(c?.x??0),fN(c?.y??0),fN(c?.z??0)];return(I??[]).flatMap(C=>dD(C,A,e)).map(({geom:C,color:Q})=>({geom:a.rotateZ(l[2],a.rotateY(l[1],a.rotateX(l[0],C))),color:Q}))}if(g===kh||g===rG||g===yc){const l=(I??[]).flatMap(C=>dD(C,A,e)).map(C=>C.geom);if(l.length===0)return[];let B;return g===kh?B=o.union(l):g===rG?B=o.subtract(l[0],l.slice(1)):B=n.hull(l),[{geom:B,color:A}]}if(g===GH){const l=c?.points??[];return[{geom:s.geom2.fromPoints(l),color:A??c?.color}]}if(g===RH){const l=(I??[]).flatMap(h=>dD(h,A,e)).map(h=>h.geom);if(l.length===0)return[];const B=l.length>1?o.union(l):l[0],C=c?.height??c?.h??1;let Q=r.extrudeLinear({height:C},B);if(Q.polygons)for(const h of Q.polygons)!h.plane||!h.vertices||h.vertices.length<3||h.vertices.reverse();return[{geom:Q,color:A??c?.color}]}if(g===ut||g===u7A||g===Ef||g===d7A||g===FH||g===uf){let l;if(g===ut){const B=c?.size??[1,1,1],C=c?.offset,Q=c?.center??(C?[C[0],C[1],C[2]]:[0,0,0]);l=i.cuboid({size:B,center:Q})}else if(g===u7A){const B=c?.size??1,C=c?.offset,Q=c?.center??(C?[C[0],C[1],C[2]]:[0,0,0]);l=i.cube({size:B,center:Q})}else if(g===Ef){const B=c?.height??1,C=c?.radius??1,Q=c?.center??[0,0,0];l=i.cylinder({height:B,radius:C,center:Q})}else if(g===d7A){const B=c?.radius??1,C=c?.center??[0,0,0];l=i.sphere({radius:B,center:C})}else if(g===uf){const B=c?.height??1,C=c?.radius??1,Q=c?.roundRadius??.1,h=c?.center??[0,0,0];l=i.roundedCylinder({height:B,radius:C,roundRadius:Q,center:h})}else{const B=c?.size??[1,1,1],C=c?.roundRadius??.1,Q=c?.center??[0,0,0];l=i.roundedCuboid({size:B,roundRadius:C,center:Q})}return[{geom:l,color:A??c?.color}]}if(typeof g=="function"){const l=g(c??{});return dD(l,A,e)}return(I??[]).flatMap(l=>dD(l,A,e))}function wkt(t,A){return{geometries:dD(t,void 0,{jscad:A})}}function k7A(t){if(t.polygons){const A=[],e=[],i=[];let o=0;for(const s of t.polygons){for(const a of s.vertices)a.index=o,A.push(a[0],a[1],a[2]),t.color&&t.color.length>=3?i.push(t.color[0],t.color[1],t.color[2]):i.push(1,1,1),o++;const r=s.vertices[0].index;for(let a=2;a<s.vertices.length;a++){const g=s.vertices[a-1].index,c=s.vertices[a].index;e.push(r,g,c)}}const n=new kg;if(n.setAttribute("position",new pc(new Float32Array(A),3)),n.setIndex(e),i.length>0&&n.setAttribute("color",new pc(new Float32Array(i),3)),t.transforms){const s=new cs;s.fromArray(t.transforms),n.applyMatrix4(s)}return n.computeVertexNormals(),n}if(t.sides){const A=[],e=[];for(const o of t.sides)A.push(o[0][0],o[0][1],0),t.color&&t.color.length>=3?e.push(t.color[0],t.color[1],t.color[2]):e.push(1,1,1);const i=new kg;if(i.setAttribute("position",new pc(new Float32Array(A),3)),e.length>0&&i.setAttribute("color",new pc(new Float32Array(e),3)),t.transforms){const o=new cs;o.fromArray(t.transforms),i.applyMatrix4(o)}return i}return console.error("Invalid CSG object: neither polygons nor sides found"),new kg}function Dkt(t,A){const e=wEA(fkt,{footprint:t});return wkt(e,A)}var Skt=Or(YW()),F7A=V.createContext(null),bkt=()=>{const t=V.useContext(F7A);if(!t)throw new Error("useHover must be used within a HoverProvider");return t},_kt=({children:t})=>{const{camera:A,renderer:e}=Ou(),[i,o]=V.useState([]),n=V.useMemo(()=>new Qat,[]),s=V.useMemo(()=>new Bo,[]),r=V.useRef(i);r.current=i;const a=V.useRef(null),g=V.useCallback(C=>{o(Q=>[...Q,C])},[]),c=V.useCallback(C=>{if(a.current){let Q=!1,h=a.current.object;for(;h;){if(h===C){Q=!0;break}h=h.parent}Q&&(a.current.onUnhover(),a.current=null)}o(Q=>Q.filter(h=>h.object!==C))},[]),I=V.useCallback(C=>{let Q=C;for(;Q;){const h=r.current.find(E=>E.object===Q);if(h)return h;Q=Q.parent}},[]),l=V.useCallback(C=>{if(!e.domElement)return;const Q=e.domElement.getBoundingClientRect();s.x=(C.clientX-Q.left)/Q.width*2-1,s.y=-((C.clientY-Q.top)/Q.height)*2+1,n.setFromCamera(s,A);const h=r.current.map(u=>u.object);if(h.length===0){a.current&&(a.current.onUnhover(),a.current=null);return}const E=n.intersectObjects(h,!0);if(E.length>0){const u=E[0],d=I(u.object);if(d){const f={mousePosition:[u.point.x,u.point.y,u.point.z]};a.current!==d?(a.current?.onUnhover(),d.onHover(f),a.current=d):d.onHover(f)}else a.current&&(a.current.onUnhover(),a.current=null)}else a.current&&(a.current.onUnhover(),a.current=null)},[A,e,n,s,I]);V.useEffect(()=>{const C=e.domElement;return C.addEventListener("mousemove",l),()=>{C.removeEventListener("mousemove",l)}},[e,l]);const B=V.useMemo(()=>({addHoverable:g,removeHoverable:c}),[g,c]);return W.jsx(F7A.Provider,{value:B,children:t})},xkt=({children:t,object:A,onHover:e,onUnhover:i,isHovered:o})=>{const{addHoverable:n,removeHoverable:s}=bkt();return V.useEffect(()=>A?(n({object:A,onHover:e,onUnhover:i}),()=>{s(A)}):void 0,[A,e,i,n,s]),W.jsx(W.Fragment,{children:t})},TH=xkt,kkt=({positionOffset:t,footprint:A,rotationOffset:e,onHover:i,onUnhover:o,isHovered:n,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=Ou(),g=V.useMemo(()=>{if(!A)return null;const{geometries:c}=Dkt(A,Skt),I=new hf;for(const l of c.flat(1/0)){const B=l.geom;if(!B||!B.polygons&&!B.sides)continue;const C=new Oi(l.color);C.convertLinearToSRGB();const Q={...B,color:[C.r,C.g,C.b]},h=k7A(Q),E=new RE({vertexColors:!0,side:zB,transparent:r,opacity:r?.5:1,depthWrite:!r}),u=new an(h,E);I.add(u)}return I},[A,r]);return V.useEffect(()=>{if(!(!g||!a))return a.add(g),()=>{a.remove(g)}},[a,g]),V.useEffect(()=>{g&&(t&&g.position.fromArray(t),e&&g.rotation.fromArray(e),s!==void 0&&g.scale.setScalar(s))},[g,t?.[0],t?.[1],t?.[2],e?.[0],e?.[1],e?.[2],s]),V.useEffect(()=>{g&&g.traverse(c=>{c instanceof an&&c.material instanceof RE&&(n?(c.material.emissive.setHex(255),c.material.emissiveIntensity=.2):c.material.emissiveIntensity=0)})},[n,g]),g?W.jsx(TH,{isHovered:n,onHover:i,onUnhover:o,object:g}):null},G7A=new WeakMap,Fkt=()=>{const t=new zI;return t.name="fallback-environment-map",t.mapping=j5,t},Gkt=t=>{if(!t)return null;const A=t,e=G7A.get(A);if(e)return e;let i;if(t instanceof _8){const o=new mrA(t);i=o.fromScene(Hat(),.04).texture,o.dispose()}else i=Fkt();return G7A.set(A,i),i},R7A=1.25;function v7A({gltfUrl:t,position:A,rotation:e,onHover:i,onUnhover:o,isHovered:n,scale:s,isTranslucent:r=!1}){const{renderer:a,rootObject:g}=Ou(),[c,I]=V.useState(null),[l,B]=V.useState(null);if(V.useEffect(()=>{if(!t)return;const C=new Jat;let Q=!0;return C.load(t,h=>{if(!Q)return;const E=h.scene;E.traverse(u=>{if(u instanceof an&&u.material){const d=f=>{f.transparent=r,f.opacity=r?.5:1,f.depthWrite=!r,f.needsUpdate=!0};Array.isArray(u.material)?u.material.forEach(d):d(u.material)}}),I(E)},void 0,h=>{if(!Q)return;console.error(`An error happened loading ${t}`,h);const E=h instanceof Error?h:new Error(`Failed to load glTF model from ${t}`);B(E)}),()=>{Q=!1}},[t,r]),V.useEffect(()=>{c&&(A&&c.position.fromArray(A),e&&c.rotation.fromArray(e),s!==void 0&&c.scale.setScalar(s))},[c,A?.[0],A?.[1],A?.[2],e?.[0],e?.[1],e?.[2],s]),V.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),V.useEffect(()=>{if(!c||!a)return;const C=Gkt(a);if(!C)return;const Q=[],h=E=>{E instanceof RE&&(Q.push({material:E,envMap:E.envMap??null,envMapIntensity:E.envMapIntensity??1}),E.envMap=C,(typeof E.envMapIntensity!="number"||E.envMapIntensity<R7A)&&(E.envMapIntensity=R7A),E.needsUpdate=!0)};return c.traverse(E=>{if(!(E instanceof an))return;const u=E.material;Array.isArray(u)?u.forEach(h):u&&h(u)}),()=>{Q.forEach(({material:E,envMap:u,envMapIntensity:d})=>{E.envMap=u,E.envMapIntensity=d,E.needsUpdate=!0})}},[c,a]),V.useEffect(()=>{c&&c.traverse(C=>{C instanceof an&&C.material instanceof RE&&(n?(C.material.emissive.setHex(255),C.material.emissiveIntensity=.2):C.material.emissiveIntensity=0)})},[n,c]),l)throw l;return c?W.jsx(TH,{isHovered:n,onHover:i,onUnhover:o,object:c}):null}var Rkt=Or(s6A()),vkt=Or(YW()),Mkt=({jscadPlan:t,positionOffset:A,rotationOffset:e,onHover:i,onUnhover:o,isHovered:n,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=Ou(),{threeGeom:g,material:c}=V.useMemo(()=>{const l=(0,Rkt.executeJscadOperations)(vkt.default,t);if(!l||!l.polygons&&!l.sides)return{threeGeom:null,material:null};const B=k7A(l),C=new RE({vertexColors:!0,side:zB,transparent:r,opacity:r?.5:1,depthWrite:!r});return{threeGeom:B,material:C}},[t,r]),I=V.useMemo(()=>g?new an(g,c):null,[g,c]);return V.useEffect(()=>{if(!(!I||!a))return a.add(I),()=>{a.remove(I)}},[a,I]),V.useEffect(()=>{I&&(A&&I.position.fromArray(A),e&&I.rotation.fromArray(e),s!==void 0&&I.scale.setScalar(s))},[I,A?.[0],A?.[1],A?.[2],e?.[0],e?.[1],e?.[2],s]),V.useMemo(()=>{if(c)if(n){const l=new Oi(c.color.getHex());c.emissive.copy(l),c.emissive.setRGB(0,0,1),c.emissiveIntensity=.2}else c.emissiveIntensity=0},[n,c]),g?W.jsx(TH,{isHovered:n,onHover:i,onUnhover:o,object:I}):null};function Nkt(t){return t.replace(/(DEF|USE)\s+([^\s]+)/g,(A,e,i)=>`${e} ${i.replace(/-/g,"_")}`)}async function Lkt(t){const A=await fetch(t);if(!A.ok)throw new Error(`Failed to fetch "${t}": ${A.status} ${A.statusText}`);const e=await A.text();return new Sgt().parse(Nkt(e),t)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function Ukt(t){const[A,e]=V.useState(null);return V.useEffect(()=>{if(!t)return;const i=t.replace(/&cachebust_origin=$/,""),o=window.TSCIRCUIT_OBJ_LOADER_CACHE;let n=!1;async function s(){try{if(i.endsWith(".wrl"))return await Lkt(i);const a=await fetch(i);if(!a.ok)throw new Error(`Failed to fetch "${i}": ${a.status} ${a.statusText}`);const g=await a.text(),c=g.match(/newmtl[\s\S]*?endmtl/g),I=new Mgt;if(c?.length){const l=c.join(`
|
|
5138
|
-
`).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new mgt;C.setMaterialOptions({invertTrProperty:!0});const Q=C.parse(l.replace(/Kd\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/g,"Kd $2 $2 $2"),"embedded.mtl");return I.setMaterials(Q),I.parse(B)}return I.parse(g.replace(/^mtllib.*/gm,""))}catch(a){return a}}function r(){if(o.has(i)){const g=o.get(i);return g.result?Promise.resolve(g.result.clone()):g.promise.then(c=>c instanceof Error?c:c.clone())}const a=s().then(g=>(g instanceof Error||o.set(i,{...o.get(i),result:g}),g));return o.set(i,{promise:a,result:null}),a}return r().then(a=>{n||e(a)}).catch(a=>{console.error(a)}),()=>{n=!0}},[t]),A}function Hkt({url:t,position:A,rotation:e,onHover:i,onUnhover:o,isHovered:n,scale:s,isTranslucent:r=!1}){const a=Ukt(t),{rootObject:g}=Ou(),c=V.useMemo(()=>a&&!(a instanceof Error)?(a.traverse(I=>{if(I instanceof an&&I.material){const l=B=>{B.transparent=r,B.opacity=r?.5:1,B.depthWrite=!r,B.needsUpdate=!0};Array.isArray(I.material)?I.material.forEach(l):l(I.material)}}),a):new an(new tw(.5,.5,.5),new RE({transparent:!0,color:"red",opacity:.25})),[a,r]);if(V.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),V.useEffect(()=>{c&&(A&&(Array.isArray(A)?c.position.fromArray(A):c.position.copy(A)),e&&(Array.isArray(e)?c.rotation.fromArray(e):c.rotation.copy(e)),s!==void 0&&c.scale.setScalar(s))},[c,Array.isArray(A)?A[0]:A?.x,Array.isArray(A)?A[1]:A?.y,Array.isArray(A)?A[2]:A?.z,Array.isArray(e)?e[0]:e?.x,Array.isArray(e)?e[1]:e?.y,Array.isArray(e)?e[2]:e?.z,s]),a instanceof Error)throw a;return W.jsx(TH,{isHovered:n,onHover:i,onUnhover:o,object:c})}var PEA,Ykt="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function Jkt(t){if(typeof t=="function")return t;if(t&&typeof t=="object"&&"default"in t&&typeof t.default=="function")return t.default;throw new Error("Unable to resolve occt-import-js factory export")}async function Tkt(){if(!PEA){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");PEA=Jkt(t)({locateFile:e=>`${Ykt}/${e}`})}return PEA}function Kkt(t){const A=new hf;for(const e of t){const i=e.attributes.position?.array??[],o=e.index?.array??[];if(!i.length||!o.length)continue;const n=new kg;n.setAttribute("position",new On(i,3));const s=e.attributes.normal?.array??[];s.length?n.setAttribute("normal",new On(s,3)):n.computeVertexNormals(),n.setIndex(o);const r=new RE({color:e.color?new Oi(e.color[0],e.color[1],e.color[2]):new Oi(.82,.82,.82)}),a=new an(n,r);a.name=e.name,A.add(a)}return A}async function Pkt(t){const A=await fetch(t);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const e=await A.arrayBuffer(),o=(await Tkt()).ReadStepFile(new Uint8Array(e),null);if(!o.success||!o.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const n=Kkt(o.meshes),s=new AaA,r=await new Promise((a,g)=>{s.parse(n,c=>{c instanceof ArrayBuffer?a(c):g(new Error("GLTFExporter did not return binary output"))},c=>{g(c)},{binary:!0})});return URL.createObjectURL(new Blob([r],{type:"model/gltf-binary"}))}var M7A="step-glb-cache:";function qkt(t){const A=new Uint8Array(t),e=32768;let i="";for(let o=0;o<A.length;o+=e){const n=A.subarray(o,o+e);i+=String.fromCharCode(...n)}return btoa(i)}function Okt(t){const A=atob(t),e=new Uint8Array(A.length);for(let i=0;i<A.length;i+=1)e[i]=A.charCodeAt(i);return e.buffer}function Wkt(t){try{const A=localStorage.getItem(`${M7A}${t}`);return A?Okt(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function Zkt(t,A){try{const e=qkt(A);localStorage.setItem(`${M7A}${t}`,e)}catch(e){console.warn("Failed to write STEP GLB cache",e)}}var Vkt=({stepUrl:t,position:A,rotation:e,scale:i,onHover:o,onUnhover:n,isHovered:s,isTranslucent:r})=>{const[a,g]=V.useState(null);return V.useEffect(()=>{let c=!0,I=null;const l=Wkt(t);return l?(I=URL.createObjectURL(new Blob([l],{type:"model/gltf-binary"})),g(I),()=>{c=!1,I&&URL.revokeObjectURL(I)}):(Pkt(t).then(B=>{if(!c){URL.revokeObjectURL(B);return}I=B,g(B),fetch(B).then(C=>C.arrayBuffer()).then(C=>{Zkt(t,C)}).catch(C=>{console.warn("Failed to cache STEP GLB",C)})}).catch(B=>{console.error("Failed to convert STEP file to GLB",B),c&&g(null)}),()=>{c=!1,I&&URL.revokeObjectURL(I)})},[t]),a?W.jsx(v7A,{gltfUrl:a,position:A,rotation:e,scale:i,onHover:o,onUnhover:n,isHovered:s,isTranslucent:r}):null},qEA=(...t)=>t,N7A=({cad_component:t,circuitJson:A})=>{const e=g6A(A),[i,o]=V.useState(!1),{visibility:n}=rN(),[s,r]=V.useState(null),a=V.useCallback(f=>{f?.mousePosition?(o(!0),r(f.mousePosition)):(o(!1),r(null))},[]),g=V.useCallback(()=>{o(!1),r(null)},[]),c=V.useMemo(()=>_i(A).source_component.getUsing({source_component_id:t.source_component_id})?.name,[A,t.source_component_id]),I=V.useMemo(()=>A.filter(m=>m.type==="pcb_plated_hole"&&m.pcb_component_id===t.pcb_component_id).length>0,[A,t.pcb_component_id]),l=t.model_obj_url??t.model_wrl_url??t.model_stl_url,B=t.model_glb_url??t.model_gltf_url,C=t.model_step_url,h=A.find(f=>f.type==="pcb_component"&&f.source_component_id===t.source_component_id)?.layer??"top",E=V.useMemo(()=>{const f=t.rotation?qEA(t.rotation.x*Math.PI/180,t.rotation.y*Math.PI/180,t.rotation.z*Math.PI/180):qEA(0,0,0);return h==="bottom"?qEA(f[0]+Math.PI,f[1],-f[2]):f},[t.rotation,h]),u=V.useMemo(()=>{if(!t.position)return;const f=.55;let m;return h==="top"?m=e/2:h==="bottom"?m=-(e/2)-f:m=t.position.z,[t.position.x,t.position.y,m]},[t.position,h,e]);let d=null;if(l?d=W.jsx(Hkt,{url:l,position:u,rotation:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):B?d=W.jsx(v7A,{gltfUrl:B,position:u,rotation:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):C&&!t.model_jscad&&!t.footprinter_string?d=W.jsx(Vkt,{stepUrl:C,position:u,rotation:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model}):t.model_jscad?d=W.jsx(Mkt,{jscadPlan:t.model_jscad,positionOffset:u,rotationOffset:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):t.footprinter_string&&(d=W.jsx(kkt,{positionOffset:u,rotationOffset:E,footprint:t.footprinter_string,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model})),t.show_as_translucent_model){if(!n.translucentModels)return null}else if(I&&!n.throughHoleModels||!I&&!n.smtModels)return null;return W.jsxs(W.Fragment,{children:[d,i&&s?W.jsx(I6A,{position:s,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:c??"<unknown>"}):null]})},L7A={version:"0.0.501"};function jkt(t){t.querySelectorAll("canvas").forEach(A=>A.remove())}var zkt=t=>{t.outputColorSpace=Wm,t.toneMapping=WKA,t.toneMappingExposure=1},U7A="cadViewerCameraStateSession",H7A=(t,A)=>{try{const e={position:t.position.toArray(),quaternion:t.quaternion.toArray(),up:t.up.toArray(),fov:t.fov??50,target:A.target.toArray()};sessionStorage.setItem(U7A,JSON.stringify(e))}catch(e){console.warn("Failed to save camera:",e)}},OEA=(t,A)=>{try{const e=sessionStorage.getItem(U7A);if(!e)return!1;const i=JSON.parse(e);if(t.position.fromArray(i.position),t.quaternion.fromArray(i.quaternion),t.up.fromArray(i.up),"fov"in t){const o=t;o.fov=i.fov,o.updateProjectionMatrix?.()}return A.target.fromArray(i.target),A.update(),t.updateMatrixWorld(),!0}catch(e){return console.warn("Failed to restore camera:",e),!1}},Y7A=V.createContext(void 0),Xkt=({children:t,defaultTarget:A,initialCameraPosition:e})=>{const i=V.useRef(null),o=V.useRef(null),[n,s]=V.useState(null),[r,a]=V.useState("perspective"),[g,c]=V.useState(e??null),[I,l]=V.useState(new Cf(0,0,0)),B=V.useMemo(()=>{const[E,u,d]=e??[5,-5,5],f=Math.hypot(E-A.x,u-A.y,d-A.z);return f>0?f:5},[e,A]),C=V.useCallback(E=>{const u=[A.x,A.y,A.z],d=o.current,f=i.current;let m=B;switch(d&&f&&(m=d.position.distanceTo(f.target)),E){case"Top Center Angled":{const D=m/Math.sqrt(2);return{position:[A.x,A.y-D,A.z+D],target:u,up:[0,0,1]}}case"Top Down":return{position:[A.x,A.y,A.z+m],target:u,up:[0,0,1]};case"Top Left Corner":return{position:[A.x-m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Top Right Corner":return{position:[A.x+m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Left Sideview":return{position:[A.x-m,A.y,A.z],target:u,up:[0,0,1]};case"Right Sideview":return{position:[A.x+m,A.y,A.z],target:u,up:[0,0,1]};case"Front":return{position:[A.x,A.y-m,A.z],target:u,up:[0,0,1]};default:return null}},[B,A,o,i]),Q=V.useCallback(E=>{i.current=E},[]),h=V.useMemo(()=>({controlsRef:i,mainCameraRef:o,defaultTarget:A,baseDistance:B,controller:n,setController:s,getPresetConfig:C,handleControlsChange:Q,cameraType:r,setCameraType:a,cameraPosition:g,setCameraPosition:c,cameraRotation:I,setCameraRotation:l,saveCameraToSession:H7A,loadCameraFromSession:OEA}),[A,B,n,C,Q,r,g,I]);return W.jsx(Y7A.Provider,{value:h,children:t})},Sx=()=>{const t=V.useContext(Y7A);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},$kt=V.forwardRef(({children:t,scene:A,camera:e,style:i,onCreated:o},n)=>{const{cameraType:s}=Sx(),r=V.useRef(null),[a,g]=V.useState(null),c=V.useRef([]),I=V.useRef(void 0);I.current=o;const l=V.useRef(null),B=V.useCallback(E=>{c.current.push(E)},[]),C=V.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=V.useMemo(()=>new KF,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=V.useRef(new xg);return V.useImperativeHandle(n,()=>h.current),V.useEffect(()=>{if(!r.current)return;jkt(r.current);const E=new _8({antialias:!0,alpha:!0});zkt(E),E.setSize(r.current.clientWidth,r.current.clientHeight),E.setPixelRatio(window.devicePixelRatio),r.current.appendChild(E.domElement);const u=r.current.clientWidth/r.current.clientHeight,d=s==="perspective"?new xh(75,u,.1,1e3):new HU(-10*u,10*u,10,-10,-1e3,1e3);l.current?(d.position.copy(l.current.position),d.quaternion.copy(l.current.quaternion),d.up.copy(l.current.up)):(e?.up&&d.up.set(e.up[0],e.up[1],e.up[2]),e?.position&&d.position.set(e.position[0],e.position[1],e.position[2]),d.lookAt(0,0,0)),Q.add(h.current),window.__TSCIRCUIT_THREE_OBJECT=h.current,g({scene:Q,camera:d,renderer:E,rootObject:h.current,addFrameListener:B,removeFrameListener:C}),I.current?.({camera:d,renderer:E});let f;const m=new nat,D=()=>{const b=m.getElapsedTime(),k=m.getDelta();c.current.forEach(_=>_(b,k)),E.render(Q,d),f=requestAnimationFrame(D)};D();const w=()=>{if(r.current){const b=r.current.clientWidth/r.current.clientHeight;d instanceof xh?d.aspect=b:d instanceof HU&&(d.left=-10*b,d.right=10*b,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),E.setSize(r.current.clientWidth,r.current.clientHeight)}};return window.addEventListener("resize",w),()=>{l.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",w),cancelAnimationFrame(f),r.current&&E.domElement&&r.current.removeChild(E.domElement),E.dispose(),Q.remove(h.current),window.__TSCIRCUIT_THREE_OBJECT===h.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[Q,B,C,s]),W.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&W.jsx(c6A.Provider,{value:a,children:W.jsx(_kt,{children:t})})})}),AFt=({autoRotate:t,autoRotateSpeed:A,onStart:e,panSpeed:i,rotateSpeed:o,zoomSpeed:n,enableDamping:s,dampingFactor:r,target:a,onControlsChange:g})=>{const{camera:c,renderer:I}=Ou(),l=V.useMemo(()=>!c||!I?null:new Lgt(c,I.domElement),[c,I]);return V.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),V.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),V.useEffect(()=>{l&&(l.autoRotate=t||!1,l.autoRotateSpeed=A||1,i!==void 0&&(l.panSpeed=i),o!==void 0&&(l.rotateSpeed=o),n!==void 0&&(l.zoomSpeed=n),s!==void 0&&(l.enableDamping=s),r!==void 0&&(l.dampingFactor=r),l.zoomToCursor=!0,l.mouseButtons={LEFT:tx.ROTATE,MIDDLE:tx.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,t,A,i,o,n,s,r,a]),V.useEffect(()=>{if(!(!l||!e))return l.addEventListener("start",e),()=>{l.removeEventListener("start",e)}},[l,e]),V.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),_H(()=>{l?.update()},[l]),null},eFt=`
|
|
5138
|
+
`).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new mgt;C.setMaterialOptions({invertTrProperty:!0});const Q=C.parse(l.replace(/Kd\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/g,"Kd $2 $2 $2"),"embedded.mtl");return I.setMaterials(Q),I.parse(B)}return I.parse(g.replace(/^mtllib.*/gm,""))}catch(a){return a}}function r(){if(o.has(i)){const g=o.get(i);return g.result?Promise.resolve(g.result.clone()):g.promise.then(c=>c instanceof Error?c:c.clone())}const a=s().then(g=>(g instanceof Error||o.set(i,{...o.get(i),result:g}),g));return o.set(i,{promise:a,result:null}),a}return r().then(a=>{n||e(a)}).catch(a=>{console.error(a)}),()=>{n=!0}},[t]),A}function Hkt({url:t,position:A,rotation:e,onHover:i,onUnhover:o,isHovered:n,scale:s,isTranslucent:r=!1}){const a=Ukt(t),{rootObject:g}=Ou(),c=V.useMemo(()=>a&&!(a instanceof Error)?(a.traverse(I=>{if(I instanceof an&&I.material){const l=B=>{B.transparent=r,B.opacity=r?.5:1,B.depthWrite=!r,B.needsUpdate=!0};Array.isArray(I.material)?I.material.forEach(l):l(I.material)}}),a):new an(new tw(.5,.5,.5),new RE({transparent:!0,color:"red",opacity:.25})),[a,r]);if(V.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),V.useEffect(()=>{c&&(A&&(Array.isArray(A)?c.position.fromArray(A):c.position.copy(A)),e&&(Array.isArray(e)?c.rotation.fromArray(e):c.rotation.copy(e)),s!==void 0&&c.scale.setScalar(s))},[c,Array.isArray(A)?A[0]:A?.x,Array.isArray(A)?A[1]:A?.y,Array.isArray(A)?A[2]:A?.z,Array.isArray(e)?e[0]:e?.x,Array.isArray(e)?e[1]:e?.y,Array.isArray(e)?e[2]:e?.z,s]),a instanceof Error)throw a;return W.jsx(TH,{isHovered:n,onHover:i,onUnhover:o,object:c})}var PEA,Ykt="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function Jkt(t){if(typeof t=="function")return t;if(t&&typeof t=="object"&&"default"in t&&typeof t.default=="function")return t.default;throw new Error("Unable to resolve occt-import-js factory export")}async function Tkt(){if(!PEA){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");PEA=Jkt(t)({locateFile:e=>`${Ykt}/${e}`})}return PEA}function Kkt(t){const A=new hf;for(const e of t){const i=e.attributes.position?.array??[],o=e.index?.array??[];if(!i.length||!o.length)continue;const n=new kg;n.setAttribute("position",new On(i,3));const s=e.attributes.normal?.array??[];s.length?n.setAttribute("normal",new On(s,3)):n.computeVertexNormals(),n.setIndex(o);const r=new RE({color:e.color?new Oi(e.color[0],e.color[1],e.color[2]):new Oi(.82,.82,.82)}),a=new an(n,r);a.name=e.name,A.add(a)}return A}async function Pkt(t){const A=await fetch(t);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const e=await A.arrayBuffer(),o=(await Tkt()).ReadStepFile(new Uint8Array(e),null);if(!o.success||!o.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const n=Kkt(o.meshes),s=new AaA,r=await new Promise((a,g)=>{s.parse(n,c=>{c instanceof ArrayBuffer?a(c):g(new Error("GLTFExporter did not return binary output"))},c=>{g(c)},{binary:!0})});return URL.createObjectURL(new Blob([r],{type:"model/gltf-binary"}))}var M7A="step-glb-cache:";function qkt(t){const A=new Uint8Array(t),e=32768;let i="";for(let o=0;o<A.length;o+=e){const n=A.subarray(o,o+e);i+=String.fromCharCode(...n)}return btoa(i)}function Okt(t){const A=atob(t),e=new Uint8Array(A.length);for(let i=0;i<A.length;i+=1)e[i]=A.charCodeAt(i);return e.buffer}function Wkt(t){try{const A=localStorage.getItem(`${M7A}${t}`);return A?Okt(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function Zkt(t,A){try{const e=qkt(A);localStorage.setItem(`${M7A}${t}`,e)}catch(e){console.warn("Failed to write STEP GLB cache",e)}}var Vkt=({stepUrl:t,position:A,rotation:e,scale:i,onHover:o,onUnhover:n,isHovered:s,isTranslucent:r})=>{const[a,g]=V.useState(null);return V.useEffect(()=>{let c=!0,I=null;const l=Wkt(t);return l?(I=URL.createObjectURL(new Blob([l],{type:"model/gltf-binary"})),g(I),()=>{c=!1,I&&URL.revokeObjectURL(I)}):(Pkt(t).then(B=>{if(!c){URL.revokeObjectURL(B);return}I=B,g(B),fetch(B).then(C=>C.arrayBuffer()).then(C=>{Zkt(t,C)}).catch(C=>{console.warn("Failed to cache STEP GLB",C)})}).catch(B=>{console.error("Failed to convert STEP file to GLB",B),c&&g(null)}),()=>{c=!1,I&&URL.revokeObjectURL(I)})},[t]),a?W.jsx(v7A,{gltfUrl:a,position:A,rotation:e,scale:i,onHover:o,onUnhover:n,isHovered:s,isTranslucent:r}):null},qEA=(...t)=>t,N7A=({cad_component:t,circuitJson:A})=>{const e=g6A(A),[i,o]=V.useState(!1),{visibility:n}=rN(),[s,r]=V.useState(null),a=V.useCallback(f=>{f?.mousePosition?(o(!0),r(f.mousePosition)):(o(!1),r(null))},[]),g=V.useCallback(()=>{o(!1),r(null)},[]),c=V.useMemo(()=>_i(A).source_component.getUsing({source_component_id:t.source_component_id})?.name,[A,t.source_component_id]),I=V.useMemo(()=>A.filter(m=>m.type==="pcb_plated_hole"&&m.pcb_component_id===t.pcb_component_id).length>0,[A,t.pcb_component_id]),l=t.model_obj_url??t.model_wrl_url??t.model_stl_url,B=t.model_glb_url??t.model_gltf_url,C=t.model_step_url,h=A.find(f=>f.type==="pcb_component"&&f.source_component_id===t.source_component_id)?.layer??"top",E=V.useMemo(()=>{const f=t.rotation?qEA(t.rotation.x*Math.PI/180,t.rotation.y*Math.PI/180,t.rotation.z*Math.PI/180):qEA(0,0,0);return h==="bottom"?qEA(f[0]+Math.PI,f[1],-f[2]):f},[t.rotation,h]),u=V.useMemo(()=>{if(!t.position)return;const f=.55;let m;return h==="top"?m=e/2:h==="bottom"?m=-(e/2)-f:m=t.position.z,[t.position.x,t.position.y,m]},[t.position,h,e]);let d=null;if(l?d=W.jsx(Hkt,{url:l,position:u,rotation:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):B?d=W.jsx(v7A,{gltfUrl:B,position:u,rotation:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):C&&!t.model_jscad&&!t.footprinter_string?d=W.jsx(Vkt,{stepUrl:C,position:u,rotation:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model}):t.model_jscad?d=W.jsx(Mkt,{jscadPlan:t.model_jscad,positionOffset:u,rotationOffset:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):t.footprinter_string&&(d=W.jsx(kkt,{positionOffset:u,rotationOffset:E,footprint:t.footprinter_string,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model})),t.show_as_translucent_model){if(!n.translucentModels)return null}else if(I&&!n.throughHoleModels||!I&&!n.smtModels)return null;return W.jsxs(W.Fragment,{children:[d,i&&s?W.jsx(I6A,{position:s,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:c??"<unknown>"}):null]})},L7A={version:"0.0.502"};function jkt(t){t.querySelectorAll("canvas").forEach(A=>A.remove())}var zkt=t=>{t.outputColorSpace=Wm,t.toneMapping=WKA,t.toneMappingExposure=1},U7A="cadViewerCameraStateSession",H7A=(t,A)=>{try{const e={position:t.position.toArray(),quaternion:t.quaternion.toArray(),up:t.up.toArray(),fov:t.fov??50,target:A.target.toArray()};sessionStorage.setItem(U7A,JSON.stringify(e))}catch(e){console.warn("Failed to save camera:",e)}},OEA=(t,A)=>{try{const e=sessionStorage.getItem(U7A);if(!e)return!1;const i=JSON.parse(e);if(t.position.fromArray(i.position),t.quaternion.fromArray(i.quaternion),t.up.fromArray(i.up),"fov"in t){const o=t;o.fov=i.fov,o.updateProjectionMatrix?.()}return A.target.fromArray(i.target),A.update(),t.updateMatrixWorld(),!0}catch(e){return console.warn("Failed to restore camera:",e),!1}},Y7A=V.createContext(void 0),Xkt=({children:t,defaultTarget:A,initialCameraPosition:e})=>{const i=V.useRef(null),o=V.useRef(null),[n,s]=V.useState(null),[r,a]=V.useState("perspective"),[g,c]=V.useState(e??null),[I,l]=V.useState(new Cf(0,0,0)),B=V.useMemo(()=>{const[E,u,d]=e??[5,-5,5],f=Math.hypot(E-A.x,u-A.y,d-A.z);return f>0?f:5},[e,A]),C=V.useCallback(E=>{const u=[A.x,A.y,A.z],d=o.current,f=i.current;let m=B;switch(d&&f&&(m=d.position.distanceTo(f.target)),E){case"Top Center Angled":{const D=m/Math.sqrt(2);return{position:[A.x,A.y-D,A.z+D],target:u,up:[0,0,1]}}case"Top Down":return{position:[A.x,A.y,A.z+m],target:u,up:[0,0,1]};case"Top Left Corner":return{position:[A.x-m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Top Right Corner":return{position:[A.x+m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Left Sideview":return{position:[A.x-m,A.y,A.z],target:u,up:[0,0,1]};case"Right Sideview":return{position:[A.x+m,A.y,A.z],target:u,up:[0,0,1]};case"Front":return{position:[A.x,A.y-m,A.z],target:u,up:[0,0,1]};default:return null}},[B,A,o,i]),Q=V.useCallback(E=>{i.current=E},[]),h=V.useMemo(()=>({controlsRef:i,mainCameraRef:o,defaultTarget:A,baseDistance:B,controller:n,setController:s,getPresetConfig:C,handleControlsChange:Q,cameraType:r,setCameraType:a,cameraPosition:g,setCameraPosition:c,cameraRotation:I,setCameraRotation:l,saveCameraToSession:H7A,loadCameraFromSession:OEA}),[A,B,n,C,Q,r,g,I]);return W.jsx(Y7A.Provider,{value:h,children:t})},Sx=()=>{const t=V.useContext(Y7A);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},$kt=V.forwardRef(({children:t,scene:A,camera:e,style:i,onCreated:o},n)=>{const{cameraType:s}=Sx(),r=V.useRef(null),[a,g]=V.useState(null),c=V.useRef([]),I=V.useRef(void 0);I.current=o;const l=V.useRef(null),B=V.useCallback(E=>{c.current.push(E)},[]),C=V.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=V.useMemo(()=>new KF,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=V.useRef(new xg);return V.useImperativeHandle(n,()=>h.current),V.useEffect(()=>{if(!r.current)return;jkt(r.current);const E=new _8({antialias:!0,alpha:!0});zkt(E),E.setSize(r.current.clientWidth,r.current.clientHeight),E.setPixelRatio(window.devicePixelRatio),r.current.appendChild(E.domElement);const u=r.current.clientWidth/r.current.clientHeight,d=s==="perspective"?new xh(75,u,.1,1e3):new HU(-10*u,10*u,10,-10,-1e3,1e3);l.current?(d.position.copy(l.current.position),d.quaternion.copy(l.current.quaternion),d.up.copy(l.current.up)):(e?.up&&d.up.set(e.up[0],e.up[1],e.up[2]),e?.position&&d.position.set(e.position[0],e.position[1],e.position[2]),d.lookAt(0,0,0)),Q.add(h.current),window.__TSCIRCUIT_THREE_OBJECT=h.current,g({scene:Q,camera:d,renderer:E,rootObject:h.current,addFrameListener:B,removeFrameListener:C}),I.current?.({camera:d,renderer:E});let f;const m=new nat,D=()=>{const b=m.getElapsedTime(),k=m.getDelta();c.current.forEach(_=>_(b,k)),E.render(Q,d),f=requestAnimationFrame(D)};D();const w=()=>{if(r.current){const b=r.current.clientWidth/r.current.clientHeight;d instanceof xh?d.aspect=b:d instanceof HU&&(d.left=-10*b,d.right=10*b,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),E.setSize(r.current.clientWidth,r.current.clientHeight)}};return window.addEventListener("resize",w),()=>{l.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",w),cancelAnimationFrame(f),r.current&&E.domElement&&r.current.removeChild(E.domElement),E.dispose(),Q.remove(h.current),window.__TSCIRCUIT_THREE_OBJECT===h.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[Q,B,C,s]),W.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&W.jsx(c6A.Provider,{value:a,children:W.jsx(_kt,{children:t})})})}),AFt=({autoRotate:t,autoRotateSpeed:A,onStart:e,panSpeed:i,rotateSpeed:o,zoomSpeed:n,enableDamping:s,dampingFactor:r,target:a,onControlsChange:g})=>{const{camera:c,renderer:I}=Ou(),l=V.useMemo(()=>!c||!I?null:new Lgt(c,I.domElement),[c,I]);return V.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),V.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),V.useEffect(()=>{l&&(l.autoRotate=t||!1,l.autoRotateSpeed=A||1,i!==void 0&&(l.panSpeed=i),o!==void 0&&(l.rotateSpeed=o),n!==void 0&&(l.zoomSpeed=n),s!==void 0&&(l.enableDamping=s),r!==void 0&&(l.dampingFactor=r),l.zoomToCursor=!0,l.mouseButtons={LEFT:tx.ROTATE,MIDDLE:tx.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,t,A,i,o,n,s,r,a]),V.useEffect(()=>{if(!(!l||!e))return l.addEventListener("start",e),()=>{l.removeEventListener("start",e)}},[l,e]),V.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),_H(()=>{l?.update()},[l]),null},eFt=`
|
|
5139
5139
|
varying vec3 worldPosition;
|
|
5140
5140
|
void main() {
|
|
5141
5141
|
worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
@@ -5169,12 +5169,12 @@ ${a.join(`
|
|
|
5169
5169
|
gl_FragColor = vec4(color, max(g1, g2) * a);
|
|
5170
5170
|
if (gl_FragColor.a <= 0.0) discard;
|
|
5171
5171
|
}
|
|
5172
|
-
`,iFt=({rotation:t,infiniteGrid:A,cellSize:e=1,sectionSize:i=10})=>{const{scene:o,camera:n}=Ou(),s=1e3,r=V.useMemo(()=>{const a=new iw(s,s);a.rotateX(-Math.PI/2);const g=new gD({vertexShader:eFt,fragmentShader:tFt,uniforms:{cellSize:{value:e},sectionSize:{value:i},gridColor:{value:new Oi(15658734)},sectionColor:{value:new Oi(13421823)},fadeDistance:{value:100},fadeStrength:{value:1.5}},transparent:!0,side:zB}),c=new an(a,g);return t&&c.rotation.fromArray(t),c},[s,e,i,t]);return _H(()=>{A&&r.position.set(n.position.x,n.position.y,0)}),V.useEffect(()=>{if(!(!o||!r))return o.add(r),()=>{o.remove(r),r.geometry.dispose(),Array.isArray(r.material)?r.material.forEach(a=>a.dispose()):r.material.dispose()}},[o,r]),null},oFt=()=>{const{scene:t}=Ou(),A=V.useMemo(()=>new h4A(16777215,Math.PI/2),[]),e=V.useMemo(()=>{const i=new WrA(16777215,Math.PI/4);return i.position.set(-10,-10,10),i.decay=0,i},[]);return V.useEffect(()=>{if(t)return t.add(A),t.add(e),()=>{t.remove(A),t.remove(e)}},[t,A,e]),null},nFt=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,sFt=()=>{const{controlsRef:t,mainCameraRef:A,defaultTarget:e,setController:i,getPresetConfig:o}=Sx(),n=V.useRef(null),s=V.useRef(new Jd),r=V.useRef(new Re),a=V.useRef(new Re),g=V.useRef(new Jd),c=V.useRef(new Jd),I=V.useRef(new xg),l=V.useRef(new xg),B=V.useCallback(({position:Q,target:h,up:E,durationMs:u=600})=>{if(!A.current)return;const d=t.current?.target??e,f=new Re(Q[0],Q[1],Q[2]),m=h?new Re(h[0],h[1],h[2]):e.clone(),D=new Re(...E??[0,0,1]).normalize(),w=l.current;w.position.copy(f),w.up.copy(D),w.lookAt(m);const b=w.quaternion.clone(),k=A.current.quaternion.clone(),_=A.current.position.clone(),M=d.clone(),v=I.current;v.up.set(0,0,1),v.position.copy(_),v.lookAt(M);const U=v.quaternion.clone();v.up.set(0,0,1),v.position.copy(f),v.lookAt(m);const J=v.quaternion.clone(),Y=U.clone().invert().multiply(k).normalize(),O=J.clone().invert().multiply(b).normalize();n.current={fromPosition:_,toPosition:f,fromTarget:M,toTarget:m,toQuaternion:b,rollFrom:Y,rollTo:O,startTime:performance.now(),duration:u}},[A,t,e]),C=V.useCallback(Q=>{if(Q==="Custom")return;const h=o(Q);h&&B(h)},[B,o]);return V.useEffect(()=>A.current?(i({animateTo:B,animateToPreset:C}),()=>{i(null)}):void 0,[B,C,A,i]),_H(()=>{if(!A.current||!n.current)return;const{fromPosition:Q,toPosition:h,fromTarget:E,toTarget:u,toQuaternion:d,rollFrom:f,rollTo:m,startTime:D,duration:w}=n.current,b=performance.now()-D,k=w<=0?1:Math.min(b/w,1),_=nFt(k);A.current.position.lerpVectors(Q,h,_);const M=r.current;M.copy(E).lerp(u,_);const v=I.current;v.up.set(0,0,1),v.position.copy(A.current.position),v.lookAt(M);const U=s.current;U.copy(v.quaternion);const J=g.current;J.copy(f);const Y=c.current;Y.copy(m),f.dot(m)<0&&(Y.x*=-1,Y.y*=-1,Y.z*=-1,Y.w*=-1),Y.normalize(),J.slerp(Y,_),A.current.quaternion.copy(U).multiply(J).normalize();const O=a.current;O.set(0,1,0).applyQuaternion(A.current.quaternion).normalize(),A.current.up.copy(O),t.current?.target.copy(M),A.current.updateMatrixWorld(),t.current?.update(),k>=1&&(A.current.position.copy(h),A.current.quaternion.copy(d),A.current.up.set(0,0,1),A.current.updateMatrixWorld(),t.current?.target.copy(u),t.current?.update(),n.current=null)}),null},rFt=()=>{const{controlsRef:t}=Sx(),A=V.useRef(null),e=V.useRef(!1),i=V.useRef(null),o=V.useCallback(s=>{A.current=s,!e.current&&t.current&&OEA(s,t.current)&&(e.current=!0)},[t]),n=V.useCallback(()=>{if(!(!A.current||!t.current)){if(!e.current&&OEA(A.current,t.current)){e.current=!0;return}clearTimeout(i.current),i.current=setTimeout(()=>{A.current&&t.current&&H7A(A.current,t.current)},150)}},[t]);return{handleCameraCreated:o,handleControlsChange:n}};function aFt(t,A){const e=new Jd().setFromEuler(new Cf(t.x,t.y,t.z)),i=new Re(0,0,1);return i.applyQuaternion(e),i.multiplyScalar(A)}var gFt=()=>{const{mainCameraRef:t}=Sx(),A=V.useRef(null),e=V.useRef(null),i=V.useRef(null),o=V.useRef(null),n=V.useRef(null),s=V.useRef(null);return V.useEffect(()=>{if(!A.current)return;const r=document.createElement("canvas");e.current=r,A.current.appendChild(r);const a=new _8({canvas:r,antialias:!0,alpha:!0});a.setSize(120,120),a.setPixelRatio(window.devicePixelRatio),i.current=a;const g=new KF;o.current=g;const c=new xh(75,1,.1,1e3);c.up.set(0,0,1),n.current=c;const I=new h4A(16777215,Math.PI/2);g.add(I);const l=new hf;l.rotation.fromArray([Math.PI/2,0,0]);const B=1,C=new an(new tw(B,B,B),new RE({color:"white"}));l.add(C);const Q=new PU(new yrt(new tw(B,B,B)),new PF({color:0,linewidth:2}));l.add(Q),g.add(l);const h=.51,E=(k,_,M)=>{const v=new daA;return v.text=k,v.position.fromArray(_),M&&v.rotation.fromArray(M),v.color="black",v.fontSize=.25,v.anchorX="center",v.anchorY="middle",v.depthOffset=0,v.font=null,v.sync(),v},u=E("Front",[0,0,h]),d=E("Back",[0,0,-h],[0,Math.PI,0]),f=E("Right",[h,0,0],[0,Math.PI/2,0]),m=E("Left",[-h,0,0],[0,-Math.PI/2,0]),D=E("Top",[0,h,0],[-Math.PI/2,0,0]),w=E("Bottom",[0,-h,0],[Math.PI/2,0,0]);l.add(u),l.add(d),l.add(f),l.add(m),l.add(D),l.add(w);const b=()=>{if(t.current){const k=aFt(t.current.rotation??new Cf(0,0,0),2);k.equals(c.position)||(c.position.copy(k),c.lookAt(0,0,0))}a.render(g,c),s.current=requestAnimationFrame(b)};return b(),()=>{s.current&&cancelAnimationFrame(s.current),u.dispose(),d.dispose(),f.dispose(),m.dispose(),D.dispose(),w.dispose(),C.geometry.dispose(),C.material.dispose(),Q.geometry.dispose(),Q.material.dispose(),g.clear(),a.dispose(),e.current&&A.current&&A.current.removeChild(e.current)}},[t]),W.jsx("div",{ref:A,style:{position:"absolute",top:0,left:0,width:120,height:120,zIndex:xH.orientationCube}})},cFt=()=>{const{camera:t}=Ou(),{setCameraRotation:A}=Sx();return _H(()=>{t&&A(t.rotation)}),null},J7A=V.forwardRef(({children:t,initialCameraPosition:A=[5,-5,5],autoRotateDisabled:e,clickToInteractEnabled:i=!1,boardDimensions:o,boardCenter:n,onUserInteraction:s,onCameraControllerReady:r},a)=>{const[g,c]=V.useState(!i),{mainCameraRef:I,handleControlsChange:l,controller:B}=Sx(),{handleCameraCreated:C,handleControlsChange:Q}=rFt();V.useEffect(()=>{r&&r(B)},[B,r]);const h=V.useMemo(()=>{if(!o)return 10;const u=o.width??0,d=o.height??0,m=Math.max(u,d)*1.5;return m>10?m:10},[o]),E=V.useMemo(()=>{if(n)return[n.x,n.y,0]},[n]);return W.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[W.jsx(gFt,{}),W.jsxs($kt,{ref:a,scene:{up:new Re(0,0,1)},camera:{up:[0,0,1],position:A},onCreated:({camera:u})=>{I.current=u,C(u)},children:[W.jsx(sFt,{}),W.jsx(cFt,{}),g&&W.jsx(AFt,{autoRotate:!e,autoRotateSpeed:1,onStart:s,rotateSpeed:.5,panSpeed:.75,zoomSpeed:.5,enableDamping:!0,dampingFactor:.1,target:E,onControlsChange:u=>{l(u),Q()}}),W.jsx(oFt,{}),W.jsx(iFt,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:3,sectionSize:h,args:[h,h]}),t]}),W.jsxs("div",{style:{position:"absolute",right:24,bottom:24,fontFamily:"sans-serif",color:"white",WebkitTextStroke:"0.5px rgba(0, 0, 0, 0.5)",fontSize:11},children:["@",L7A.version]}),i&&!g&&W.jsx("button",{type:"button",onClick:()=>c(!0),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&c(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:xH.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center"},children:W.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",fontFamily:"sans-serif",pointerEvents:"none"},children:"Click to Interact"})})]})}),T7A=t=>V.useMemo(()=>{if(!t)return[];const A=new B6e;return A.add(t),A.render(),A.getCircuitJson()},[t]),IFt=t=>{const[A,e]=V.useState([]),[i,o]=V.useState(!0);return V.useEffect(()=>{if(!t)return;(async()=>{o(!0);const r=(Array.isArray(t)?t:[t]).map(async(a,g)=>{const c=RQt.serialize({binary:!0},[a]),l=await new Blob(c).arrayBuffer(),C=a.layerType||(g===0?"board":void 0);return{stlData:l,color:a.color,layerType:C}});try{const a=await Promise.all(r);e(a)}catch(a){console.error("Error generating STLs:",a),e([])}finally{o(!1)}})()},[t]),{stls:A,loading:i}},lFt=Or(mx()),BFt=Or(GW()),Po=.01,Xa={traces:.001,copper:.002},en={copper:[.9,.6,.2],fr4Tan:[.6,.43,.28],fr4SolderMaskGreen:[.02,.1,.04],fr4TracesWithMaskGreen:[0,.5,.25],fr4TracesWithoutMaskTan:[.6,.43,.28],fr1Tan:[.8,.4,.2],fr1TracesWithMaskCopper:[.9,.6,.2],fr1SolderMaskGreen:[.02,.1,.04]},df=.001,$B=32,KH=.035,mc=150,$W=.6,WEA={fr1:en.fr1Tan,fr4:en.fr4Tan},K7A={fr1:en.fr1SolderMaskGreen,fr4:en.fr4SolderMaskGreen},CFt=Or(bH()),QFt=Or(mx()),hFt=Or(nG()),EFt=Or(t6A()),P7A=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1]}return A/2<=0},ZEA=(t,A=1.2,e={})=>{const{xyOutset:i=0}=e,{outline:o}=t;let n=o.map(a=>[a.x,a.y]);P7A(n)&&(n=n.reverse());let s=(0,QFt.polygon)({points:n});i!==0&&(s=(0,EFt.expand)({delta:i,corners:"edge"},s));let r=(0,CFt.extrudeLinear)({height:A},s);return r=(0,hFt.translate)([0,0,-A/2],r),r},uFt=t=>{const A=t.filter(a=>a.type==="pcb_panel"),e=_i(t).pcb_board.list();let i,o=1.2;if(A.length>0)i=A[0],o=e.find(g=>g.pcb_panel_id===i.pcb_panel_id)?.thickness??1.2;else{if(i=e.filter(g=>!g.pcb_panel_id)[0],!i)return console.warn("No pcb_board or pcb_panel found for simplified geometry"),[];o=i.thickness??1.2}let n;"outline"in i&&i.outline&&i.outline.length>0?n=ZEA({outline:i.outline},o):n=(0,lFt.cuboid)({size:[i.width??10,i.height??10,o],center:[i.center.x,i.center.y,0]});const s="material"in i&&i.material?i.material:A.length>0?e.find(a=>a.pcb_panel_id===i.pcb_panel_id)?.material??"fr4":"fr4",r=WEA[s]??en.fr4Tan;return[(0,BFt.colorize)(r,n)]},Fh=Or(nG()),Rg=Or(mx()),Wu=Or(GW()),vg=Or(sN()),gr=Or(mx()),pD=Or(GW()),ga=Or(sN()),q7A=Or(nG()),PH=Or(bH()),Od=Or(nG()),dFt=1e-5;function x0(t,A,e){if(typeof e!="number"||!Number.isFinite(e)||e<=0)return 0;const i=t/2,o=A/2,n=Math.min(i,o)-2*dFt;return Math.max(0,Math.min(e,n))}function HC(t){if(!(!t||typeof t!="object"))return t.corner_radius??t.cornerRadius??t.rect_pad_border_radius??t.rectPadBorderRadius??t.rect_border_radius??t.rectBorderRadius??void 0}var bx=Or(mx()),pFt=Or(bH()),AZ=Or(nG()),fFt=Or(sN()),yFt=64,mFt=(t,A,e)=>{const i=(0,bx.ellipse)({center:[0,0],radius:[Math.max(t/2,Po/2),Math.max(A/2,Po/2)],segments:yFt}),o=(0,pFt.extrudeLinear)({height:e},i);return(0,AZ.translate)([0,0,-e/2],o)},wFt=(t,A,e)=>{const i=Math.max(t,Po),o=Math.max(A,Po);if(Math.abs(i-o)<1e-6)return(0,bx.cylinder)({center:[0,0,0],radius:i/2,height:e});const n=i>=o,s=n?i:o,r=n?o:i,a=Math.max(s-r,0),g=(0,bx.cuboid)({center:[0,0,0],size:n?[a,r,e]:[r,a,e]});if(a<=1e-6)return(0,bx.cylinder)({center:[0,0,0],radius:r/2,height:e});const c=a/2,I=(0,bx.cylinder)({center:n?[-c,0,0]:[0,-c,0],radius:r/2,height:e}),l=(0,bx.cylinder)({center:n?[c,0,0]:[0,c,0],radius:r/2,height:e});return(0,fFt.union)(g,I,l)},eZ=(t,A,e={})=>{const i=t.hole_shape||"circle",o=e.sizeDelta??0,n=t.hole_offset_x||0,s=t.hole_offset_y||0,r=[t.x+n,t.y+s,0];if(i==="circle"){const B=Math.max((t.hole_diameter??0)+o,Po),C=Math.max(B/2,Po/2);return(0,bx.cylinder)({center:r,radius:C,height:A})}const a=t.hole_width??t.hole_diameter,g=t.hole_height??t.hole_diameter;if(!a||!g)return null;const c=Math.max(a+o,Po),I=Math.max(g+o,Po);if(i==="oval"){const B=mFt(c,I,A);return(0,AZ.translate)([r[0],r[1],0],B)}if(i==="pill"||i==="rotated_pill"){let B=wFt(c,I,A);if(!B)return null;const C=t.ccw_rotation||0;return C&&(B=(0,AZ.rotateZ)(C*Math.PI/180,B)),(0,AZ.translate)(r,B)}const l=Math.max((t.hole_diameter??a??g??Po)+o,Po);return(0,bx.cylinder)({center:r,radius:l/2,height:A})},k0=.02,tZ=64,aG=(t,A)=>A?(0,ga.intersect)(A,t):t,yN=({width:t,height:A,thickness:e,center:i,borderRadius:o})=>{const n=x0(t,A,o);if(n<=0)return(0,gr.cuboid)({center:i,size:[t,A,e]});const s=(0,gr.roundedRectangle)({size:[t,A],roundRadius:n,segments:tZ}),r=(0,PH.extrudeLinear)({height:e},s),a=i[2]-e/2;return(0,Od.translate)([i[0],i[1],a],r)},qH=(t,A,e={})=>{const{clipGeom:i}=e;t.shape||(t.shape="circle");const o=A.pcbThickness+2*k0+4*Po,n=A.pcbThickness/2+Xa.copper,s=-A.pcbThickness/2-Xa.copper,r=n-s;if(t.shape==="circle"){const a=t.outer_diameter??Math.max(t.hole_diameter,0),g=r+.01,c=(0,gr.cylinder)({center:[t.x,t.y,0],radius:a/2,height:g}),I=aG(c,i),l=(0,gr.cylinder)({center:[t.x,t.y,0],radius:Math.max(t.hole_diameter/2,.01),height:o});return(0,pD.colorize)(en.copper,(0,ga.subtract)(I,l))}if(t.shape==="oval"){const a=t.outer_width||t.hole_width||0,g=t.outer_height||t.hole_height||0,c=t.hole_width||0,I=t.hole_height||0,l=(()=>{const Q=(0,gr.cylinder)({center:[0,0,0],radius:1,height:r+.01,segments:64}),h=(0,q7A.scale)([a/2,g/2,1],Q);return(0,Od.translate)([t.x,t.y,0],h)})(),B=aG(l,i),C=(()=>{const Q=(0,gr.cylinder)({center:[0,0,0],radius:1,height:o,segments:64}),h=(0,q7A.scale)([Math.max(c/2,.01),Math.max(I/2,.01),1],Q);return(0,Od.translate)([t.x,t.y,0],h)})();return(0,pD.colorize)(en.copper,(0,ga.subtract)(B,C))}if(t.shape==="circular_hole_with_rect_pad"){const a=t.hole_offset_x||0,g=t.hole_offset_y||0,c=t.rect_pad_width||t.hole_diameter,I=t.rect_pad_height||t.hole_diameter,l=HC(t),B=aG((0,ga.union)(yN({width:c,height:I,thickness:k0,center:[t.x,t.y,n],borderRadius:l}),yN({width:c,height:I,thickness:k0,center:[t.x,t.y,s],borderRadius:l}),(()=>{const E=Math.max(r-k0*2,Po),f=(n+s)/2,m=(0,gr.roundedRectangle)({size:[c,I],roundRadius:l||0,segments:tZ}),D=(0,PH.extrudeLinear)({height:E},m);return(0,Od.translate)([t.x,t.y,f-E/2],D)})(),(0,gr.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:t.hole_diameter/2,height:r})),i),C=(0,gr.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:Math.max(t.hole_diameter/2-Po,.01),height:o}),Q=(0,gr.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:t.hole_diameter/2,height:r});let h=(0,ga.union)((0,ga.subtract)(B,Q),Q);return e.clipGeom?(h=(0,ga.subtract)(h,C),h=(0,ga.intersect)(h,e.clipGeom),(0,pD.colorize)(en.copper,h)):(0,pD.colorize)(en.copper,(0,ga.subtract)(h,C))}if(t.shape==="pill"){const a=(t.ccw_rotation||0)*Math.PI/180,g=_=>{if(!a)return _;const M=(0,Od.translate)([-t.x,-t.y,0],_),v=(0,Od.rotate)([0,0,a],M);return(0,Od.translate)([t.x,t.y,0],v)},c=t.hole_height>t.hole_width,I=c?t.hole_height:t.hole_width,l=c?t.hole_width:t.hole_height,B=c?t.outer_height||l+.2:t.outer_width||I+.2,C=c?t.outer_width||I+.2:t.outer_height||l+.2,Q=l/2,h=Math.abs(I-l),E=r+.01,d=((_,M,v)=>{const U=M/2,J=Math.abs(_-M);if(J<=1e-6)return(0,gr.cylinder)({center:[t.x,t.y,0],radius:U,height:v});const Y=(0,gr.cuboid)({center:[t.x,t.y,0],size:c?[M,J,v]:[J,M,v]}),O=(0,gr.cylinder)({center:c?[t.x,t.y-J/2,0]:[t.x-J/2,t.y,0],radius:U,height:v}),Z=(0,gr.cylinder)({center:c?[t.x,t.y+J/2,0]:[t.x+J/2,t.y,0],radius:U,height:v});return(0,ga.union)(Y,O,Z)})(B,C,E),f=(0,gr.cuboid)({center:[t.x,t.y,0],size:c?[l-2*Po,h,o]:[h,l-2*Po,o]}),m=(0,gr.cylinder)({center:c?[t.x,t.y-h/2,0]:[t.x-h/2,t.y,0],radius:Q-Po,height:o}),D=(0,gr.cylinder)({center:c?[t.x,t.y+h/2,0]:[t.x+h/2,t.y,0],radius:Q-Po,height:o}),w=(0,ga.union)(f,m,D),b=aG(g(d),i),k=g(w);return(0,pD.colorize)(en.copper,(0,ga.subtract)(b,k))}if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for pill_hole_with_rect_pad");const a=t.hole_offset_x||0,g=t.hole_offset_y||0,c=t.hole_height>t.hole_width,I=c?t.hole_height:t.hole_width,l=c?t.hole_width:t.hole_height,B=l/2,C=Math.abs(I-l),Q=t.rect_pad_width||I+.2,h=t.rect_pad_height||l+.2,E=HC(t),u=.03,d=(0,ga.union)((0,gr.cuboid)({center:[t.x+a,t.y+g,0],size:c?[l+2*u,C+2*u,r]:[C+2*u,l+2*u,r]}),(0,gr.cylinder)({center:c?[t.x+a,t.y+g-C/2,0]:[t.x+a-C/2,t.y+g,0],radius:B+u,height:r}),(0,gr.cylinder)({center:c?[t.x+a,t.y+g+C/2,0]:[t.x+a+C/2,t.y+g,0],radius:B+u,height:r})),f=(0,ga.union)((0,gr.cuboid)({center:[t.x+a,t.y+g,0],size:c?[l,C,o*1.1]:[C,l,o*1.1]}),(0,gr.cylinder)({center:c?[t.x+a,t.y+g-C/2,0]:[t.x+a-C/2,t.y+g,0],radius:B,height:o*1.1}),(0,gr.cylinder)({center:c?[t.x+a,t.y+g+C/2,0]:[t.x+a+C/2,t.y+g,0],radius:B,height:o*1.1})),m=yN({width:Q,height:h,thickness:k0,center:[t.x,t.y,n],borderRadius:E}),D=yN({width:Q,height:h,thickness:k0,center:[t.x,t.y,s],borderRadius:E}),w=(()=>{const J=Math.max(r-k0*2,Po),Z=(n+s)/2,$=(0,gr.roundedRectangle)({size:[Q,h],roundRadius:E||0,segments:tZ}),iA=(0,PH.extrudeLinear)({height:J},$);return(0,Od.translate)([t.x,t.y,Z-J/2],iA)})(),b=(0,ga.subtract)(m,f),k=(0,ga.subtract)(D,f),_=(0,ga.subtract)(w,f),M=(0,ga.union)((0,gr.cuboid)({center:[t.x+a,t.y+g,0],size:c?[l-2*Po,C-2*Po,o*1.1]:[C-2*Po,l-2*Po,o*1.1]}),(0,gr.cylinder)({center:c?[t.x+a,t.y+g-C/2,0]:[t.x+a-C/2,t.y+g,0],radius:B-Po,height:o*1.1}),(0,gr.cylinder)({center:c?[t.x+a,t.y+g+C/2,0]:[t.x+a+C/2,t.y+g,0],radius:B-Po,height:o*1.1})),v=(0,ga.subtract)(d,M),U=aG((0,ga.union)(b,k,_,v),i);return(0,pD.colorize)(en.copper,U)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for rotated_pill_hole_with_rect_pad");const a=t.hole_offset_x||0,g=t.hole_offset_y||0,c=t.hole_width,I=t.hole_height,l=c>=I,B=l?c:I,C=l?I:c,Q=C/2,h=Math.abs(B-C),E=t.rect_pad_width||c+.2,u=t.rect_pad_height||I+.2,d=HC(t),f=.03,m=(t.hole_ccw_rotation||0)*Math.PI/180,D=(t.rect_ccw_rotation||0)*Math.PI/180,w=aA=>{const eA=a*Math.cos(m)-g*Math.sin(m),oA=a*Math.sin(m)+g*Math.cos(m),rA=(0,Od.rotate)([0,0,m],aA);return(0,Od.translate)([t.x+eA,t.y+oA,0],rA)},b=aA=>{if(!D)return aA;const eA=(0,Od.translate)([-t.x,-t.y,0],aA),oA=(0,Od.rotate)([0,0,D],eA);return(0,Od.translate)([t.x,t.y,0],oA)},k=w((0,ga.union)((0,gr.cuboid)({center:[0,0,0],size:l?[h+2*f,C+2*f,r]:[C+2*f,h+2*f,r]}),(0,gr.cylinder)({center:l?[-h/2,0,0]:[0,-h/2,0],radius:Q+f,height:r}),(0,gr.cylinder)({center:l?[h/2,0,0]:[0,h/2,0],radius:Q+f,height:r}))),_=w((0,ga.union)((0,gr.cuboid)({center:[0,0,0],size:l?[h,C,o*1.1]:[C,h,o*1.1]}),(0,gr.cylinder)({center:l?[-h/2,0,0]:[0,-h/2,0],radius:Q,height:o*1.1}),(0,gr.cylinder)({center:l?[h/2,0,0]:[0,h/2,0],radius:Q,height:o*1.1}))),M=b(yN({width:E,height:u,thickness:k0,center:[t.x,t.y,n],borderRadius:d})),v=b(yN({width:E,height:u,thickness:k0,center:[t.x,t.y,s],borderRadius:d})),U=b((()=>{const aA=Math.max(r-k0*2,Po),rA=(n+s)/2,lA=(0,gr.roundedRectangle)({size:[E,u],roundRadius:d||0,segments:tZ}),EA=(0,PH.extrudeLinear)({height:aA},lA);return(0,Od.translate)([t.x,t.y,rA-aA/2],EA)})()),J=(0,ga.subtract)(M,_),Y=(0,ga.subtract)(v,_),O=(0,ga.subtract)(U,_),Z=w((0,ga.union)((0,gr.cuboid)({center:[0,0,0],size:l?[h-2*Po,C-2*Po,o*1.1]:[C-2*Po,h-2*Po,o*1.1]}),(0,gr.cylinder)({center:l?[-h/2,0,0]:[0,-h/2,0],radius:Q-Po,height:o*1.1}),(0,gr.cylinder)({center:l?[h/2,0,0]:[0,h/2,0],radius:Q-Po,height:o*1.1}))),$=(0,ga.subtract)(k,Z),iA=aG((0,ga.union)(J,Y,O,$),i);return(0,pD.colorize)(en.copper,iA)}else if(t.shape==="hole_with_polygon_pad"){const a=t.pad_outline;if(!Array.isArray(a)||a.length<3)throw new Error(`Invalid pad_outline for plated hole at (${t.x}, ${t.y})`);const g=a.map(f=>[f.x,f.y]),c=(0,gr.polygon)({points:g}),I=(n+s)/2,l=(f,m)=>{const D=Math.max(f,Po),w=(0,PH.extrudeLinear)({height:D},c);return(0,Od.translate)([t.x,t.y,m-D/2],w)},B=l(Math.max(r-k0*2,Po),I),C=l(k0,n),Q=l(k0,s),h=aG((0,ga.union)(B,C,Q),i),E=eZ(t,r);if(!E)return(0,pD.colorize)(en.copper,h);const u=eZ(t,o,{sizeDelta:-2*Po})||E;let d=(0,ga.union)((0,ga.subtract)(h,E),E);return e.clipGeom?(d=(0,ga.subtract)(d,u),d=(0,ga.intersect)(d,e.clipGeom),(0,pD.colorize)(en.copper,d)):(0,pD.colorize)(en.copper,(0,ga.subtract)(d,u))}else throw new Error(`Unsupported plated hole shape: ${t.shape}`)},iZ=Or(bH()),O7A=Or(sN()),DFt=Or(nG()),OH=Or(mx());function SFt({x:t,y:A,outerDiameter:e,holeDiameter:i,thickness:o}){if(e<=i)throw new Error(`Invalid via geometry: outerDiameter (${e}) must be > holeDiameter (${i})`);const n=Po,s=Po,r=Math.min(e/2,i/2+s),a=(0,OH.cylinder)({center:[0,0,0],radius:r,height:o,segments:$B}),g=(0,OH.cylinder)({center:[0,0,o/2],radius:e/2,height:n,segments:$B}),c=(0,OH.cylinder)({center:[0,0,-o/2],radius:e/2,height:n,segments:$B}),I=(0,O7A.union)([a,g,c]),l=o+n*2,B=(0,OH.cylinder)({center:[0,0,0],radius:i/2,height:l,segments:$B}),C=(0,O7A.subtract)(I,B);return(0,DFt.translate)([t,A,0],C)}function bFt({x:t,y:A,holeDiameter:e,thickness:i}){const o=i*1.5,n=e/2+Po;return(0,OH.cylinder)({center:[t,A,0],radius:n,height:o,segments:$B})}var W7A=64,_Ft=1,VEA=.05,Z7A=(t,A,e,i)=>{const o=x0(t,A,i);if(o<=0)return(0,Rg.cuboid)({center:[0,0,0],size:[t,A,e]});const n=(0,Rg.roundedRectangle)({size:[t,A],roundRadius:o,segments:W7A}),s=(0,iZ.extrudeLinear)({height:e},n);return(0,Fh.translate)([0,0,-e/2],s)},V7A=["initializing","processing_pads","processing_copper_pours","processing_plated_holes","processing_holes","processing_cutouts","processing_vias","finalizing","done"],xFt=class{circuitJson;board;plated_holes;holes;pads;traces;pcb_vias;pcb_cutouts;boardGeom=null;platedHoleGeoms=[];padGeoms=[];viaGeoms=[];copperPourGeoms=[];boardClipGeom=null;state="initializing";currentIndex=0;ctx;onCompleteCallback;finalGeoms=[];getHoleToCut(t,A){const e=Po/10;for(const i of this.pcb_vias)if(Math.abs(i.x-t)<e&&Math.abs(i.y-A)<e&&i.hole_diameter)return{diameter:i.hole_diameter};for(const i of this.plated_holes)if(i.shape==="circle"&&Math.abs(i.x-t)<e&&Math.abs(i.y-A)<e&&i.hole_diameter)return{diameter:i.hole_diameter};return null}constructor(t,A){this.circuitJson=t,this.onCompleteCallback=A;const e=t.filter(o=>o.type==="pcb_panel"),i=_i(t).pcb_board.list();if(e.length>0){const o=e[0],n=i.find(s=>s.pcb_panel_id===o.pcb_panel_id);this.board={type:"pcb_board",pcb_board_id:o.pcb_panel_id,center:o.center,width:o.width,height:o.height,thickness:n?.thickness??1.4,material:n?.material??"fr4",num_layers:n?.num_layers??2}}else{const o=i.filter(n=>!n.pcb_panel_id);this.board=o[0]}this.plated_holes=_i(t).pcb_plated_hole.list(),this.holes=_i(t).pcb_hole.list(),this.pads=_i(t).pcb_smtpad.list(),this.traces=_i(t).pcb_trace.list(),this.pcb_vias=_i(t).pcb_via.list(),this.pcb_cutouts=_i(t).pcb_cutout.list(),this.ctx={pcbThickness:this.board.thickness??1.2},this.initializeBoard()}initializeBoard(){const t=this.ctx.pcbThickness+2*_Ft;this.board.outline&&this.board.outline.length>0?(this.boardGeom=ZEA({outline:this.board.outline},this.ctx.pcbThickness),this.boardClipGeom=ZEA({outline:this.board.outline},t,{xyOutset:VEA})):(this.boardGeom=(0,Rg.cuboid)({size:[this.board.width,this.board.height,this.ctx.pcbThickness],center:[this.board.center.x,this.board.center.y,0]}),this.boardClipGeom=(0,Rg.cuboid)({size:[this.board.width+2*VEA,this.board.height+2*VEA,t],center:[this.board.center.x,this.board.center.y,0]})),this.state="processing_pads",this.currentIndex=0}goToNextState(){const t=V7A.indexOf(this.state);t!==-1&&(this.state=V7A[t+1],this.currentIndex=0)}step(t=1){if(this.state==="done"||!this.boardGeom)return!0;for(let A=0;A<t&&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_pads":this.currentIndex<this.pads.length?(this.processPad(this.pads[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(t){if(!this.boardGeom)return;let A=null;const e=this.ctx.pcbThickness*1.5;switch(t.shape){case"rect":{const i=x0(t.width,t.height,HC(t));if(i>0){const o=(0,Rg.roundedRectangle)({size:[t.width,t.height],roundRadius:i,segments:W7A});A=(0,iZ.extrudeLinear)({height:e},o),A=(0,Fh.translate)([0,0,-e/2],A)}else A=(0,Rg.cuboid)({center:[0,0,0],size:[t.width,t.height,e]});if(t.rotation){const o=t.rotation*Math.PI/180;A=(0,Fh.rotateZ)(o,A)}A=(0,Fh.translate)([t.center.x,t.center.y,0],A);break}case"circle":A=(0,Rg.cylinder)({center:[t.center.x,t.center.y,0],radius:t.radius,height:e});break;case"polygon":{let i=t.points.map(n=>[n.x,n.y]);if(i.length<3){console.warn(`PCB Cutout [${t.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);break}P7A(i)&&(i=i.reverse());const o=(0,Rg.polygon)({points:i});A=(0,iZ.extrudeLinear)({height:e},o),A=(0,Fh.translate)([0,0,-e/2],A);break}}A&&(this.boardGeom=(0,vg.subtract)(this.boardGeom,A))}processPlatedHole(t,A={}){if(this.boardGeom){if(t.shape==="circle"||t.shape==="circular_hole_with_rect_pad"){let e=null;if(t.shape==="circular_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="circle"||t.pad_shape&&t.pad_shape!=="rect")return;e=(0,Rg.cylinder)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],radius:t.hole_diameter/2+Po,height:this.ctx.pcbThickness*1.5})}else e=(0,Rg.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+Po,height:this.ctx.pcbThickness*1.5});A.dontCutBoard||(this.boardGeom=(0,vg.subtract)(this.boardGeom,e)),this.padGeoms=this.padGeoms.map(o=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(o,e)));const i=qH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(i)}else if(t.shape==="pill"||t.shape==="oval"){const e=t.hole_height>t.hole_width,i=e?t.hole_height:t.hole_width,o=e?t.hole_width:t.hole_height,n=o/2,s=Math.abs(i-o);let r;if(r=(0,vg.union)((0,Rg.cuboid)({center:[t.x,t.y,0],size:e?[o,s,this.ctx.pcbThickness*1.5]:[s,o,this.ctx.pcbThickness*1.5]}),(0,Rg.cylinder)({center:e?[t.x,t.y-s/2,0]:[t.x-s/2,t.y,0],radius:n,height:this.ctx.pcbThickness*1.5}),(0,Rg.cylinder)({center:e?[t.x,t.y+s/2,0]:[t.x+s/2,t.y,0],radius:n,height:this.ctx.pcbThickness*1.5})),t.ccw_rotation){const g=t.ccw_rotation*Math.PI/180;r=(0,Fh.translate)([t.x,t.y,0],(0,Fh.rotateZ)(g,(0,Fh.translate)([-t.x,-t.y,0],r)))}A.dontCutBoard||(this.boardGeom=(0,vg.subtract)(this.boardGeom,r)),this.padGeoms=this.padGeoms.map(g=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(g,r)));const a=qH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")return;const e=t.hole_height>t.hole_width,i=e?t.hole_height:t.hole_width,o=e?t.hole_width:t.hole_height,n=o/2,s=Math.abs(i-o);let r;r=(0,vg.union)((0,Rg.cuboid)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],size:e?[o,s,this.ctx.pcbThickness*1.5]:[s,o,this.ctx.pcbThickness*1.5]}),(0,Rg.cylinder)({center:e?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)-s/2,0]:[t.x+(t.hole_offset_x||0)-s/2,t.y+(t.hole_offset_y||0),0],radius:n,height:this.ctx.pcbThickness*1.5}),(0,Rg.cylinder)({center:e?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)+s/2,0]:[t.x+(t.hole_offset_x||0)+s/2,t.y+(t.hole_offset_y||0),0],radius:n,height:this.ctx.pcbThickness*1.5})),A.dontCutBoard||(this.boardGeom=(0,vg.subtract)(this.boardGeom,r)),this.padGeoms=this.padGeoms.map(g=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(g,r)));const a=qH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")return;const e=t.hole_width,i=t.hole_height,o=e>=i,n=o?e:i,s=o?i:e,r=s/2,a=Math.abs(n-s),g=t.hole_offset_x||0,c=t.hole_offset_y||0;let I=(0,vg.union)((0,Rg.cuboid)({center:[0,0,0],size:o?[a,s,this.ctx.pcbThickness*1.5]:[s,a,this.ctx.pcbThickness*1.5]}),(0,Rg.cylinder)({center:o?[-a/2,0,0]:[0,-a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}),(0,Rg.cylinder)({center:o?[a/2,0,0]:[0,a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}));const l=(t.hole_ccw_rotation||0)*Math.PI/180,B=g*Math.cos(l)-c*Math.sin(l),C=g*Math.sin(l)+c*Math.cos(l);I=(0,Fh.rotateZ)(l,I);const Q=(0,Fh.translate)([t.x+B,t.y+C,0],I);A.dontCutBoard||(this.boardGeom=(0,vg.subtract)(this.boardGeom,Q)),this.padGeoms=this.padGeoms.map(E=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(E,Q)));const h=qH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(h)}else if(t.shape==="hole_with_polygon_pad"){const e=t.pad_outline;if(!Array.isArray(e)||e.length<3)return;const i=this.ctx.pcbThickness*1.5,o=eZ(t,i,{sizeDelta:2*Po}),n=eZ(t,i,{sizeDelta:-2*Po});if(!o||!n)return;A.dontCutBoard||(this.boardGeom=(0,vg.subtract)(this.boardGeom,o)),this.padGeoms=this.padGeoms.map(r=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(r,o))),this.platedHoleGeoms=this.platedHoleGeoms.map(r=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(r,n)));const s=qH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(s)}}}processHole(t){if(!this.boardGeom)return;const A=this.ctx.pcbThickness*1.5;if(t.hole_shape==="circle"){const e=(0,Rg.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+Po,height:A});this.boardGeom=(0,vg.subtract)(this.boardGeom,e),this.padGeoms=this.padGeoms.map(o=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(o,e)));const i=(0,Rg.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+Po/2,height:A});this.platedHoleGeoms=this.platedHoleGeoms.map(o=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(o,i)))}else if(t.hole_shape==="pill"||t.hole_shape==="rotated_pill"||t.hole_shape==="oval"){const e=t.hole_width??t.hole_diameter,i=t.hole_height??t.hole_diameter,o=t.ccw_rotation??t.rotation??0,n=.02,s=(g,c,I,l)=>{if(g<=0||c<=0)return null;if(l)return(0,Fh.translate)([0,0,-I/2],(0,iZ.extrudeLinear)({height:I},(0,Rg.ellipse)({radius:[g/2,c/2]})));const B=Math.min(g,c)/2,C=Math.abs(g-c);return g>c?(0,vg.union)((0,Rg.cuboid)({center:[0,0,0],size:[C,c,I]}),(0,Rg.cylinder)({center:[-C/2,0,0],radius:B,height:I}),(0,Rg.cylinder)({center:[C/2,0,0],radius:B,height:I})):(0,vg.union)((0,Rg.cuboid)({center:[0,0,0],size:[g,C,I]}),(0,Rg.cylinder)({center:[0,-C/2,0],radius:B,height:I}),(0,Rg.cylinder)({center:[0,C/2,0],radius:B,height:I}))};let r=s(e,i,A,t.hole_shape==="oval"),a=s(e-2*n,i-2*n,A,t.hole_shape==="oval");if(r&&o!==0&&(r=(0,Fh.rotateZ)(o*Math.PI/180,r)),a&&o!==0&&(a=(0,Fh.rotateZ)(o*Math.PI/180,a)),r){const g=(0,Fh.translate)([t.x,t.y,0],r);this.boardGeom=(0,vg.subtract)(this.boardGeom,g),this.padGeoms=this.padGeoms.map(c=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(c,g)))}if(a){const g=(0,Fh.translate)([t.x,t.y,0],a);this.platedHoleGeoms=this.platedHoleGeoms.map(c=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(c,g)))}}}processPad(t){const A=t.layer==="bottom"?-1:1,e=A*this.ctx.pcbThickness/2+A*Xa.copper,i=HC(t);if(t.shape==="rect"){const o=Z7A(t.width,t.height,Po,i);let s=(0,Fh.translate)([t.x,t.y,e],o);this.boardClipGeom&&(s=(0,vg.intersect)(this.boardClipGeom,s)),s=(0,Wu.colorize)(en.copper,s),this.padGeoms.push(s)}else if(t.shape==="rotated_rect"){let o=Z7A(t.width,t.height,Po,i);const n=t.ccw_rotation*Math.PI/180;o=(0,Fh.rotateZ)(n,o);let r=(0,Fh.translate)([t.x,t.y,e],o);this.boardClipGeom&&(r=(0,vg.intersect)(this.boardClipGeom,r)),r=(0,Wu.colorize)(en.copper,r),this.padGeoms.push(r)}else if(t.shape==="circle"){let o=(0,Rg.cylinder)({center:[t.x,t.y,e],radius:t.radius,height:Po});this.boardClipGeom&&(o=(0,vg.intersect)(this.boardClipGeom,o)),o=(0,Wu.colorize)(en.copper,o),this.padGeoms.push(o)}}processVia(t){if(this.boardGeom){if(typeof t.outer_diameter=="number"&&typeof t.hole_diameter=="number"){const A=SFt({x:t.x,y:t.y,outerDiameter:t.outer_diameter,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});let e=A;this.boardClipGeom&&(e=(0,vg.intersect)(this.boardClipGeom,A),e=(0,Wu.colorize)(en.copper,e)),this.viaGeoms.push(e)}if(typeof t.hole_diameter=="number"){const A=bFt({x:t.x,y:t.y,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});this.boardGeom=(0,vg.subtract)(this.boardGeom,A),this.padGeoms=this.padGeoms.map(e=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(e,A)))}}}finalize(){if(!this.boardGeom)return;const t=WEA[this.board.material]??en.fr4Tan;this.boardGeom=(0,Wu.colorize)(t,this.boardGeom),this.finalGeoms=[this.boardGeom,...this.platedHoleGeoms,...this.padGeoms,...this.viaGeoms,...this.copperPourGeoms],this.onCompleteCallback&&this.onCompleteCallback(this.finalGeoms)}getGeoms(){return this.finalGeoms}},kFt=t=>{const[A,e]=V.useState(null),i=V.useRef(!1);return V.useEffect(()=>{let o=!1;if(!t){e(null);return}if(!t.some(g=>g.type==="pcb_board"||g.type==="pcb_panel")){e(null);return}const s=uFt(t);e(s);const r=new xFt(t,g=>{});return(async()=>{if(!i.current){i.current=!0;try{let g=!1;for(;!g&&!o;)g=r.step(1),g||await new Promise(c=>setTimeout(c,0));o||e(r.getGeoms())}catch(g){console.error("Error during board geometry building:",g)}finally{i.current=!1}}})(),()=>{o=!0}},[t]),A},FFt=({children:t,parent:A,position:e,rotation:i,scale:o,color:n,fontSize:s,anchorX:r,anchorY:a,depthOffset:g})=>{const{rootObject:c}=Ou(),I=V.useMemo(()=>{const l=new daA;return l.text=t,e&&l.position.fromArray(e),i&&l.rotation.fromArray(i),o&&l.scale.fromArray(o),l.color=n||"white",l.fontSize=s||1,l.anchorX=r||"center",l.anchorY=a||"middle",l.depthOffset=g||0,l.font=null,l.sync(),l},[t,e,i,o,n,s,r,a,g]);return V.useEffect(()=>{const l=A||c;if(!(!l||!I))return l.add(I),()=>{l.remove(I),I.dispose()}},[c,A,I]),null},j7A=({error:t,cad_component:A})=>{const{rootObject:e}=Ou(),[i,o]=V.useState(!1),[n,s]=V.useState(null),r=V.useCallback(I=>{I?.mousePosition?(o(!0),s(I.mousePosition)):(o(!1),s(null))},[]),a=V.useCallback(()=>{o(!1),s(null)},[]),g=V.useMemo(()=>A?.position?[A.position.x,A.position.y,A.position.z].map(l=>Number.isNaN(l)?0:l):[0,0,0],[A]),c=V.useMemo(()=>{const I=new hf;return I.position.fromArray(g),I},[g]);return V.useEffect(()=>{if(e)return e.add(c),()=>{e.remove(c)}},[e,c]),W.jsxs(W.Fragment,{children:[W.jsxs(TH,{isHovered:i,onHover:r,onUnhover:a,object:c,children:[W.jsx(GFt,{parent:c}),W.jsx(FFt,{parent:c,scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:`${t.toString().slice(0,50)}...`})]}),i&&n?W.jsx(I6A,{position:n,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:t.toString()}):null]})},GFt=({parent:t})=>{const A=V.useMemo(()=>{const e=new an(new tw(.5,.5,.5),new RE({depthTest:!1,transparent:!0,color:"red",opacity:.5}));return e.renderOrder=999999,e.rotation.fromArray([Math.PI/4,Math.PI/4,0]),e},[]);return V.useEffect(()=>(t.add(A),()=>{t.remove(A)}),[t,A]),null};function RFt({stlUrl:t,stlData:A,mtlUrl:e,color:i,opacity:o=1}){const{rootObject:n}=Ou(),[s,r]=V.useState(null);V.useEffect(()=>{const g=new ygt;if(A){try{const c=g.parse(A);r(c)}catch(c){console.error("Failed to parse STL data",c),r(null)}return}t&&g.load(t,c=>{r(c)})},[t,A]);const a=V.useMemo(()=>{if(!s)return null;const g=new RE({color:Array.isArray(i)?new Oi(i[0],i[1],i[2]):i,transparent:o!==1,opacity:o});return new an(s,g)},[s,i,o]);return V.useEffect(()=>{if(!(!n||!a))return n.add(a),()=>{n.remove(a),a.geometry.dispose(),Array.isArray(a.material)?a.material.forEach(g=>g.dispose()):a.material.dispose()}},[n,a]),null}function vFt({stlData:t,color:A,opacity:e=1,layerType:i}){const{visibility:o}=rN();let n=!0;return i==="board"?n=o.boardBody:i==="top-copper"?n=o.topCopper:i==="bottom-copper"?n=o.bottomCopper:i==="top-silkscreen"?n=o.topSilkscreen:i==="bottom-silkscreen"&&(n=o.bottomSilkscreen),n?W.jsx(RFt,{stlData:t,color:A,opacity:e}):null}var z7A=class extends no.Component{constructor(t){super(t),this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},MFt=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,o=t[0].y;for(let n=1;n<t.length;n++){const s=t[n];s.x<A&&(A=s.x),s.y<e&&(e=s.y),s.x>i&&(i=s.x),s.y>o&&(o=s.y)}return{minX:A,minY:e,maxX:i,maxY:o}};function gG(t){if(t.outline&&t.outline.length>=3){const s=MFt(t.outline);return{...s,width:s.maxX-s.minX,height:s.maxY-s.minY,centerX:(s.minX+s.maxX)/2,centerY:(s.minY+s.maxY)/2}}const A=t.width??0,e=t.height??0,i=t.center?.x??0,o=t.center?.y??0;return{...{minX:i-A/2,maxX:i+A/2,minY:o-e/2,maxY:o+e/2},width:A,height:e,centerX:i,centerY:o}}function oZ({layer:t,circuitJson:A,boardData:e,soldermaskColor:i,traceTextureResolution:o}){const n=gG(e),s=document.createElement("canvas"),r=Math.floor(n.width*o),a=Math.floor(n.height*o);s.width=r,s.height=a;const g=s.getContext("2d");if(!g)return null;t==="bottom"&&(g.translate(0,a),g.scale(1,-1));const c=f=>(f-n.minX)*o,I=f=>(n.maxY-f)*o;if(g.fillStyle=i,e.outline&&e.outline.length>=3){g.beginPath();const f=e.outline[0];g.moveTo(c(f.x),I(f.y));for(let m=1;m<e.outline.length;m++){const D=e.outline[m];g.lineTo(c(D.x),I(D.y))}g.closePath(),g.fill()}else g.fillRect(0,0,r,a);g.globalCompositeOperation="destination-out",g.fillStyle="black",_i(A).pcb_smtpad.list().filter(f=>f.layer===t).forEach(f=>{if(f.shape==="polygon"&&f.points){g.beginPath(),f.points.forEach((k,_)=>{const M=c(k.x),v=I(k.y);_===0?g.moveTo(M,v):g.lineTo(M,v)}),g.closePath(),g.fill();return}if(f.x===void 0||f.y===void 0)return;if(Number.isNaN(f.x)||Number.isNaN(f.y)){console.warn(`[soldermask-texture] Skipping pad ${f.pcb_smtpad_id} with NaN coordinates`);return}const m=f.x,D=f.y,w=c(m),b=I(D);if(f.shape==="rect"){const k=f.width*o,_=f.height*o,M=HC(f),v=x0(f.width,f.height,M)*o;v>0?(g.beginPath(),g.roundRect(w-k/2,b-_/2,k,_,v),g.fill()):g.fillRect(w-k/2,b-_/2,k,_)}else if(f.shape==="circle"){const k=(f.radius??f.width/2)*o;g.beginPath(),g.arc(w,b,k,0,2*Math.PI),g.fill()}else if(f.shape==="pill"){const k=f.width*o,_=f.height*o,M=HC(f),v=x0(f.width,f.height,M)*o;g.beginPath(),g.roundRect(w-k/2,b-_/2,k,_,v),g.fill()}else if(f.shape==="rotated_rect"){const k=f.width*o,_=f.height*o,M=HC(f),v=x0(f.width,f.height,M)*o,J=-(f.ccw_rotation||0)*(Math.PI/180);g.save(),g.translate(w,b),g.rotate(J),g.beginPath(),g.roundRect(-k/2,-_/2,k,_,v),g.fill(),g.restore()}}),_i(A).pcb_via.list().forEach(f=>{const m=c(f.x),D=I(f.y),w=f.outer_diameter/2*o;g.beginPath(),g.arc(m,D,w,0,2*Math.PI),g.fill()}),_i(A).pcb_plated_hole.list().forEach(f=>{if(!f.layers?.includes(t))return;const m=f.x,D=f.y,w=c(m),b=I(D);if(f.shape==="circle"){const _=f.outer_diameter/2*o;g.beginPath(),g.arc(w,b,_,0,2*Math.PI),g.fill()}else if(f.shape==="pill"){const k=(f.outer_width??f.outer_diameter??f.hole_width)*o,_=(f.outer_height??f.outer_diameter??f.hole_height)*o,M=Math.min(k,_)/2,U=-(f.ccw_rotation||0);U?(g.save(),g.translate(w,b),g.rotate(U*Math.PI/180),g.beginPath(),g.roundRect(-k/2,-_/2,k,_,M),g.fill(),g.restore()):(g.beginPath(),g.roundRect(w-k/2,b-_/2,k,_,M),g.fill())}else if(f.shape==="oval"){const k=(f.outer_width??f.outer_diameter??f.hole_width)*o,_=(f.outer_height??f.outer_diameter??f.hole_height)*o,M=k/2,v=_/2,J=-(f.ccw_rotation||0);J?(g.save(),g.translate(w,b),g.rotate(J*Math.PI/180),g.beginPath(),g.ellipse(0,0,M,v,0,0,2*Math.PI),g.fill(),g.restore()):(g.beginPath(),g.ellipse(w,b,M,v,0,0,2*Math.PI),g.fill())}else if(f.shape==="hole_with_polygon_pad"){const k=f.hole_shape||"circle",_=f.hole_offset_x||0,M=f.hole_offset_y||0,v=c(f.x+_),U=I(f.y+M);if(k==="pill"||k==="rotated_pill"){const J=(f.outer_width??f.outer_diameter??f.hole_width)*o,Y=(f.outer_height??f.outer_diameter??f.hole_height)*o,O=Math.min(J,Y)/2,$=-(f.ccw_rotation||0);$?(g.save(),g.translate(v,U),g.rotate($*Math.PI/180),g.beginPath(),g.roundRect(-J/2,-Y/2,J,Y,O),g.fill(),g.restore()):(g.beginPath(),g.roundRect(v-J/2,U-Y/2,J,Y,O),g.fill())}else if(k==="oval"){const J=(f.outer_width??f.outer_diameter??f.hole_width)*o,Y=(f.outer_height??f.outer_diameter??f.hole_height)*o,O=J/2,Z=Y/2,iA=-(f.ccw_rotation||0);iA?(g.save(),g.translate(v,U),g.rotate(iA*Math.PI/180),g.beginPath(),g.ellipse(0,0,O,Z,0,0,2*Math.PI),g.fill(),g.restore()):(g.beginPath(),g.ellipse(v,U,O,Z,0,0,2*Math.PI),g.fill())}else if(k==="circle"){const Y=(f.outer_diameter??f.hole_diameter??0)*o/2;g.beginPath(),g.arc(v,U,Y,0,2*Math.PI),g.fill()}f.pad_outline&&f.pad_outline.length>=3&&(g.beginPath(),f.pad_outline.forEach((J,Y)=>{const O=c(f.x+J.x),Z=I(f.y+J.y);Y===0?g.moveTo(O,Z):g.lineTo(O,Z)}),g.closePath(),g.fill())}else if(f.shape==="circular_hole_with_rect_pad"){const k=(f.rect_pad_width??f.hole_diameter??0)*o,_=(f.rect_pad_height??f.hole_diameter??0)*o,M=HC(f),v=x0(f.rect_pad_width??f.hole_diameter??0,f.rect_pad_height??f.hole_diameter??0,M)*o;v>0?(g.beginPath(),g.roundRect(w-k/2,b-_/2,k,_,v),g.fill()):g.fillRect(w-k/2,b-_/2,k,_)}else if(f.shape==="pill_hole_with_rect_pad"){const k=(f.rect_pad_width??f.hole_width??0)*o,_=(f.rect_pad_height??f.hole_height??0)*o,M=HC(f),v=x0(f.rect_pad_width??f.hole_width??0,f.rect_pad_height??f.hole_height??0,M)*o,J=-(f.ccw_rotation||0);J?(g.save(),g.translate(w,b),g.rotate(J*Math.PI/180),g.beginPath(),g.roundRect(-k/2,-_/2,k,_,v),g.fill(),g.restore()):(g.beginPath(),g.roundRect(w-k/2,b-_/2,k,_,v),g.fill())}else if(f.shape==="rotated_pill_hole_with_rect_pad"){const k=(f.rect_pad_width??f.hole_width??0)*o,_=(f.rect_pad_height??f.hole_height??0)*o,M=HC(f),v=x0(f.rect_pad_width??f.hole_width??0,f.rect_pad_height??f.hole_height??0,M)*o,J=-(f.rect_ccw_rotation||0);J?(g.save(),g.translate(w,b),g.rotate(J*Math.PI/180),g.beginPath(),g.roundRect(-k/2,-_/2,k,_,v),g.fill(),g.restore()):(g.beginPath(),g.roundRect(w-k/2,b-_/2,k,_,v),g.fill())}}),_i(A).pcb_hole.list().forEach(f=>{const m=f.x,D=f.y,w=c(m),b=I(D),k=f.hole_shape;if(k==="circle"&&typeof f.hole_diameter=="number"){const _=f.hole_diameter/2*o;g.beginPath(),g.arc(w,b,_,0,2*Math.PI),g.fill()}else if(k==="pill"&&typeof f.hole_width=="number"&&typeof f.hole_height=="number"){const _=f.hole_width*o,M=f.hole_height*o,v=Math.min(_,M)/2;g.beginPath(),g.roundRect(w-_/2,b-M/2,_,M,v),g.fill()}else if(k==="rotated_pill"&&typeof f.hole_width=="number"&&typeof f.hole_height=="number"){const _=f.hole_width*o,M=f.hole_height*o,v=Math.min(_,M)/2,J=-(f.ccw_rotation||0)*(Math.PI/180);J?(g.save(),g.translate(w,b),g.rotate(J),g.beginPath(),g.roundRect(-_/2,-M/2,_,M,v),g.fill(),g.restore()):(g.beginPath(),g.roundRect(w-_/2,b-M/2,_,M,v),g.fill())}else if(k==="oval"&&typeof f.hole_width=="number"&&typeof f.hole_height=="number"){const _=f.hole_width*o,M=f.hole_height*o,v=_/2,U=M/2;g.beginPath(),g.ellipse(w,b,v,U,0,0,2*Math.PI),g.fill()}}),_i(A).pcb_copper_pour.list().forEach(f=>{if(f.layer===t&&f.covered_with_solder_mask===!1)if(f.shape==="rect"){const m=c(f.center.x),D=I(f.center.y),w=f.width*o,b=f.height*o;g.fillRect(m-w/2,D-b/2,w,b)}else f.shape==="polygon"&&f.points&&(g.beginPath(),f.points.forEach((m,D)=>{const w=c(m.x),b=I(m.y);D===0?g.moveTo(w,b):g.lineTo(w,b)}),g.closePath(),g.fill())}),_i(A).pcb_cutout.list().forEach(f=>{switch(f.shape){case"rect":{const m=c(f.center.x),D=I(f.center.y),w=f.width*o,b=f.height*o,k=HC(f),_=x0(f.width,f.height,k);if(f.rotation){g.save(),g.translate(m,D);const M=-f.rotation*(Math.PI/180);g.rotate(M),_>0?(g.beginPath(),g.roundRect(-w/2,-b/2,w,b,_*o),g.fill()):g.fillRect(-w/2,-b/2,w,b),g.restore()}else _>0?(g.beginPath(),g.roundRect(m-w/2,D-b/2,w,b,_*o),g.fill()):g.fillRect(m-w/2,D-b/2,w,b);break}case"circle":{const m=c(f.center.x),D=I(f.center.y),w=f.radius*o;g.beginPath(),g.arc(m,D,w,0,2*Math.PI),g.fill();break}case"polygon":{if(!f.points||f.points.length<3){console.warn(`PCB Cutout [${f.pcb_cutout_id}] polygon has fewer than 3 points, skipping in soldermask texture.`);break}g.beginPath(),f.points.forEach((m,D)=>{const w=c(m.x),b=I(m.y);D===0?g.moveTo(w,b):g.lineTo(w,b)}),g.closePath(),g.fill();break}default:console.warn(`Unsupported cutout shape: ${f.shape} for cutout ${f.pcb_cutout_id} in soldermask texture.`)}}),g.globalCompositeOperation="source-over";const d=new TM(s);return d.generateMipmaps=!0,d.minFilter=Tu,d.magFilter=gB,d.anisotropy=16,d.needsUpdate=!0,d}var NFt=Or(tEA());function X7A(t,A){return Array.isArray(A)?[t.a*A[0]+t.c*A[1]+t.e,t.b*A[0]+t.d*A[1]+t.f]:{x:t.a*A.x+t.c*A.y+t.e,y:t.b*A.x+t.d*A.y+t.f}}function _x(t,A=0){return{a:1,c:0,e:t,b:0,d:1,f:A}}function $7A(...t){t=Array.isArray(t[0])?t[0]:t;const A=(e,i)=>({a:e.a*i.a+e.c*i.b,c:e.a*i.c+e.c*i.d,e:e.a*i.e+e.c*i.f+e.e,b:e.b*i.a+e.d*i.b,d:e.b*i.c+e.d*i.d,f:e.b*i.e+e.d*i.f+e.f});switch(t.length){case 0:throw new Error("no matrices provided");case 1:return t[0];case 2:return A(t[0],t[1]);default:{const[e,i,...o]=t,n=A(e,i);return $7A(n,...o)}}}function A$A(...t){return $7A(...t)}var{cos:LFt,sin:UFt}=Math;function e$A(t,A,e){const i=LFt(t),o=UFt(t);return{a:i,c:-o,e:0,b:o,d:i,f:0}}function HFt(t,A){function e(){this.constructor=t}e.prototype=A.prototype,t.prototype=new e}function nZ(t,A,e,i){var o=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(o,nZ.prototype),o.expected=A,o.found=e,o.location=i,o.name="SyntaxError",o}HFt(nZ,Error);function jEA(t,A,e){return e=e||" ",t.length>A?t:(A-=t.length,e+=e.repeat(A),t+e.slice(0,A))}nZ.prototype.format=function(t){var A="Error: "+this.message;if(this.location){var e=null,i;for(i=0;i<t.length;i++)if(t[i].source===this.location.source){e=t[i].text.split(/\r\n|\n|\r/g);break}var o=this.location.start,n=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(o):o,s=this.location.source+":"+n.line+":"+n.column;if(e){var r=this.location.end,a=jEA("",n.line.toString().length," "),g=e[o.line-1],c=o.line===r.line?r.column:g.length+1,I=c-o.column||1;A+=`
|
|
5172
|
+
`,iFt=({rotation:t,infiniteGrid:A,cellSize:e=1,sectionSize:i=10})=>{const{scene:o,camera:n}=Ou(),s=1e3,r=V.useMemo(()=>{const a=new iw(s,s);a.rotateX(-Math.PI/2);const g=new gD({vertexShader:eFt,fragmentShader:tFt,uniforms:{cellSize:{value:e},sectionSize:{value:i},gridColor:{value:new Oi(15658734)},sectionColor:{value:new Oi(13421823)},fadeDistance:{value:100},fadeStrength:{value:1.5}},transparent:!0,side:zB}),c=new an(a,g);return t&&c.rotation.fromArray(t),c},[s,e,i,t]);return _H(()=>{A&&r.position.set(n.position.x,n.position.y,0)}),V.useEffect(()=>{if(!(!o||!r))return o.add(r),()=>{o.remove(r),r.geometry.dispose(),Array.isArray(r.material)?r.material.forEach(a=>a.dispose()):r.material.dispose()}},[o,r]),null},oFt=()=>{const{scene:t}=Ou(),A=V.useMemo(()=>new h4A(16777215,Math.PI/2),[]),e=V.useMemo(()=>{const i=new WrA(16777215,Math.PI/4);return i.position.set(-10,-10,10),i.decay=0,i},[]);return V.useEffect(()=>{if(t)return t.add(A),t.add(e),()=>{t.remove(A),t.remove(e)}},[t,A,e]),null},nFt=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,sFt=()=>{const{controlsRef:t,mainCameraRef:A,defaultTarget:e,setController:i,getPresetConfig:o}=Sx(),n=V.useRef(null),s=V.useRef(new Jd),r=V.useRef(new Re),a=V.useRef(new Re),g=V.useRef(new Jd),c=V.useRef(new Jd),I=V.useRef(new xg),l=V.useRef(new xg),B=V.useCallback(({position:Q,target:h,up:E,durationMs:u=600})=>{if(!A.current)return;const d=t.current?.target??e,f=new Re(Q[0],Q[1],Q[2]),m=h?new Re(h[0],h[1],h[2]):e.clone(),D=new Re(...E??[0,0,1]).normalize(),w=l.current;w.position.copy(f),w.up.copy(D),w.lookAt(m);const b=w.quaternion.clone(),k=A.current.quaternion.clone(),_=A.current.position.clone(),M=d.clone(),v=I.current;v.up.set(0,0,1),v.position.copy(_),v.lookAt(M);const U=v.quaternion.clone();v.up.set(0,0,1),v.position.copy(f),v.lookAt(m);const J=v.quaternion.clone(),Y=U.clone().invert().multiply(k).normalize(),O=J.clone().invert().multiply(b).normalize();n.current={fromPosition:_,toPosition:f,fromTarget:M,toTarget:m,toQuaternion:b,rollFrom:Y,rollTo:O,startTime:performance.now(),duration:u}},[A,t,e]),C=V.useCallback(Q=>{if(Q==="Custom")return;const h=o(Q);h&&B(h)},[B,o]);return V.useEffect(()=>A.current?(i({animateTo:B,animateToPreset:C}),()=>{i(null)}):void 0,[B,C,A,i]),_H(()=>{if(!A.current||!n.current)return;const{fromPosition:Q,toPosition:h,fromTarget:E,toTarget:u,toQuaternion:d,rollFrom:f,rollTo:m,startTime:D,duration:w}=n.current,b=performance.now()-D,k=w<=0?1:Math.min(b/w,1),_=nFt(k);A.current.position.lerpVectors(Q,h,_);const M=r.current;M.copy(E).lerp(u,_);const v=I.current;v.up.set(0,0,1),v.position.copy(A.current.position),v.lookAt(M);const U=s.current;U.copy(v.quaternion);const J=g.current;J.copy(f);const Y=c.current;Y.copy(m),f.dot(m)<0&&(Y.x*=-1,Y.y*=-1,Y.z*=-1,Y.w*=-1),Y.normalize(),J.slerp(Y,_),A.current.quaternion.copy(U).multiply(J).normalize();const O=a.current;O.set(0,1,0).applyQuaternion(A.current.quaternion).normalize(),A.current.up.copy(O),t.current?.target.copy(M),A.current.updateMatrixWorld(),t.current?.update(),k>=1&&(A.current.position.copy(h),A.current.quaternion.copy(d),A.current.up.set(0,0,1),A.current.updateMatrixWorld(),t.current?.target.copy(u),t.current?.update(),n.current=null)}),null},rFt=()=>{const{controlsRef:t}=Sx(),A=V.useRef(null),e=V.useRef(!1),i=V.useRef(null),o=V.useCallback(s=>{A.current=s,!e.current&&t.current&&OEA(s,t.current)&&(e.current=!0)},[t]),n=V.useCallback(()=>{if(!(!A.current||!t.current)){if(!e.current&&OEA(A.current,t.current)){e.current=!0;return}clearTimeout(i.current),i.current=setTimeout(()=>{A.current&&t.current&&H7A(A.current,t.current)},150)}},[t]);return{handleCameraCreated:o,handleControlsChange:n}};function aFt(t,A){const e=new Jd().setFromEuler(new Cf(t.x,t.y,t.z)),i=new Re(0,0,1);return i.applyQuaternion(e),i.multiplyScalar(A)}var gFt=()=>{const{mainCameraRef:t}=Sx(),A=V.useRef(null),e=V.useRef(null),i=V.useRef(null),o=V.useRef(null),n=V.useRef(null),s=V.useRef(null);return V.useEffect(()=>{if(!A.current)return;const r=document.createElement("canvas");e.current=r,A.current.appendChild(r);const a=new _8({canvas:r,antialias:!0,alpha:!0});a.setSize(120,120),a.setPixelRatio(window.devicePixelRatio),i.current=a;const g=new KF;o.current=g;const c=new xh(75,1,.1,1e3);c.up.set(0,0,1),n.current=c;const I=new h4A(16777215,Math.PI/2);g.add(I);const l=new hf;l.rotation.fromArray([Math.PI/2,0,0]);const B=1,C=new an(new tw(B,B,B),new RE({color:"white"}));l.add(C);const Q=new PU(new yrt(new tw(B,B,B)),new PF({color:0,linewidth:2}));l.add(Q),g.add(l);const h=.51,E=(k,_,M)=>{const v=new daA;return v.text=k,v.position.fromArray(_),M&&v.rotation.fromArray(M),v.color="black",v.fontSize=.25,v.anchorX="center",v.anchorY="middle",v.depthOffset=0,v.font=null,v.sync(),v},u=E("Front",[0,0,h]),d=E("Back",[0,0,-h],[0,Math.PI,0]),f=E("Right",[h,0,0],[0,Math.PI/2,0]),m=E("Left",[-h,0,0],[0,-Math.PI/2,0]),D=E("Top",[0,h,0],[-Math.PI/2,0,0]),w=E("Bottom",[0,-h,0],[Math.PI/2,0,0]);l.add(u),l.add(d),l.add(f),l.add(m),l.add(D),l.add(w);const b=()=>{if(t.current){const k=aFt(t.current.rotation??new Cf(0,0,0),2);k.equals(c.position)||(c.position.copy(k),c.lookAt(0,0,0))}a.render(g,c),s.current=requestAnimationFrame(b)};return b(),()=>{s.current&&cancelAnimationFrame(s.current),u.dispose(),d.dispose(),f.dispose(),m.dispose(),D.dispose(),w.dispose(),C.geometry.dispose(),C.material.dispose(),Q.geometry.dispose(),Q.material.dispose(),g.clear(),a.dispose(),e.current&&A.current&&A.current.removeChild(e.current)}},[t]),W.jsx("div",{ref:A,style:{position:"absolute",top:0,left:0,width:120,height:120,zIndex:xH.orientationCube}})},cFt=()=>{const{camera:t}=Ou(),{setCameraRotation:A}=Sx();return _H(()=>{t&&A(t.rotation)}),null},J7A=V.forwardRef(({children:t,initialCameraPosition:A=[5,-5,5],autoRotateDisabled:e,clickToInteractEnabled:i=!1,boardDimensions:o,boardCenter:n,onUserInteraction:s,onCameraControllerReady:r},a)=>{const[g,c]=V.useState(!i),{mainCameraRef:I,handleControlsChange:l,controller:B}=Sx(),{handleCameraCreated:C,handleControlsChange:Q}=rFt();V.useEffect(()=>{r&&r(B)},[B,r]);const h=V.useMemo(()=>{if(!o)return 10;const u=o.width??0,d=o.height??0,m=Math.max(u,d)*1.5;return m>10?m:10},[o]),E=V.useMemo(()=>{if(n)return[n.x,n.y,0]},[n]);return W.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[W.jsx(gFt,{}),W.jsxs($kt,{ref:a,scene:{up:new Re(0,0,1)},camera:{up:[0,0,1],position:A},onCreated:({camera:u})=>{I.current=u,C(u)},children:[W.jsx(sFt,{}),W.jsx(cFt,{}),g&&W.jsx(AFt,{autoRotate:!e,autoRotateSpeed:1,onStart:s,rotateSpeed:.5,panSpeed:.75,zoomSpeed:.5,enableDamping:!0,dampingFactor:.1,target:E,onControlsChange:u=>{l(u),Q()}}),W.jsx(oFt,{}),W.jsx(iFt,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:3,sectionSize:h,args:[h,h]}),t]}),W.jsxs("div",{style:{position:"absolute",right:24,bottom:24,fontFamily:"sans-serif",color:"white",WebkitTextStroke:"0.5px rgba(0, 0, 0, 0.5)",fontSize:11},children:["@",L7A.version]}),i&&!g&&W.jsx("button",{type:"button",onClick:()=>c(!0),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&c(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:xH.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center"},children:W.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",fontFamily:"sans-serif",pointerEvents:"none"},children:"Click to Interact"})})]})}),T7A=t=>V.useMemo(()=>{if(!t)return[];const A=new B6e;return A.add(t),A.render(),A.getCircuitJson()},[t]),IFt=t=>{const[A,e]=V.useState([]),[i,o]=V.useState(!0);return V.useEffect(()=>{if(!t)return;(async()=>{o(!0);const r=(Array.isArray(t)?t:[t]).map(async(a,g)=>{const c=RQt.serialize({binary:!0},[a]),l=await new Blob(c).arrayBuffer(),C=a.layerType||(g===0?"board":void 0);return{stlData:l,color:a.color,layerType:C}});try{const a=await Promise.all(r);e(a)}catch(a){console.error("Error generating STLs:",a),e([])}finally{o(!1)}})()},[t]),{stls:A,loading:i}},lFt=Or(mx()),BFt=Or(GW()),Po=.01,Xa={traces:.001,copper:.002},en={copper:[.9,.6,.2],fr4Tan:[.6,.43,.28],fr4SolderMaskGreen:[.02,.1,.04],fr4TracesWithMaskGreen:[0,.5,.25],fr4TracesWithoutMaskTan:[.6,.43,.28],fr1Tan:[.8,.4,.2],fr1TracesWithMaskCopper:[.9,.6,.2],fr1SolderMaskGreen:[.02,.1,.04]},df=.001,$B=32,KH=.035,mc=150,$W=.6,WEA={fr1:en.fr1Tan,fr4:en.fr4Tan},K7A={fr1:en.fr1SolderMaskGreen,fr4:en.fr4SolderMaskGreen},CFt=Or(bH()),QFt=Or(mx()),hFt=Or(nG()),EFt=Or(t6A()),P7A=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1]}return A/2<=0},ZEA=(t,A=1.2,e={})=>{const{xyOutset:i=0}=e,{outline:o}=t;let n=o.map(a=>[a.x,a.y]);P7A(n)&&(n=n.reverse());let s=(0,QFt.polygon)({points:n});i!==0&&(s=(0,EFt.expand)({delta:i,corners:"edge"},s));let r=(0,CFt.extrudeLinear)({height:A},s);return r=(0,hFt.translate)([0,0,-A/2],r),r},uFt=t=>{const A=t.filter(a=>a.type==="pcb_panel"),e=_i(t).pcb_board.list();let i,o=1.2;if(A.length>0)i=A[0],o=e.find(g=>g.pcb_panel_id===i.pcb_panel_id)?.thickness??1.2;else{if(i=e.filter(g=>!g.pcb_panel_id)[0],!i)return console.warn("No pcb_board or pcb_panel found for simplified geometry"),[];o=i.thickness??1.2}let n;"outline"in i&&i.outline&&i.outline.length>0?n=ZEA({outline:i.outline},o):n=(0,lFt.cuboid)({size:[i.width??10,i.height??10,o],center:[i.center.x,i.center.y,0]});const s="material"in i&&i.material?i.material:A.length>0?e.find(a=>a.pcb_panel_id===i.pcb_panel_id)?.material??"fr4":"fr4",r=WEA[s]??en.fr4Tan;return[(0,BFt.colorize)(r,n)]},Fh=Or(nG()),Rg=Or(mx()),Wu=Or(GW()),vg=Or(sN()),gr=Or(mx()),pD=Or(GW()),ga=Or(sN()),q7A=Or(nG()),PH=Or(bH()),Od=Or(nG()),dFt=1e-5;function x0(t,A,e){if(typeof e!="number"||!Number.isFinite(e)||e<=0)return 0;const i=t/2,o=A/2,n=Math.min(i,o)-2*dFt;return Math.max(0,Math.min(e,n))}function HC(t){if(!(!t||typeof t!="object"))return t.corner_radius??t.cornerRadius??t.rect_pad_border_radius??t.rectPadBorderRadius??t.rect_border_radius??t.rectBorderRadius??void 0}var bx=Or(mx()),pFt=Or(bH()),AZ=Or(nG()),fFt=Or(sN()),yFt=64,mFt=(t,A,e)=>{const i=(0,bx.ellipse)({center:[0,0],radius:[Math.max(t/2,Po/2),Math.max(A/2,Po/2)],segments:yFt}),o=(0,pFt.extrudeLinear)({height:e},i);return(0,AZ.translate)([0,0,-e/2],o)},wFt=(t,A,e)=>{const i=Math.max(t,Po),o=Math.max(A,Po);if(Math.abs(i-o)<1e-6)return(0,bx.cylinder)({center:[0,0,0],radius:i/2,height:e});const n=i>=o,s=n?i:o,r=n?o:i,a=Math.max(s-r,0),g=(0,bx.cuboid)({center:[0,0,0],size:n?[a,r,e]:[r,a,e]});if(a<=1e-6)return(0,bx.cylinder)({center:[0,0,0],radius:r/2,height:e});const c=a/2,I=(0,bx.cylinder)({center:n?[-c,0,0]:[0,-c,0],radius:r/2,height:e}),l=(0,bx.cylinder)({center:n?[c,0,0]:[0,c,0],radius:r/2,height:e});return(0,fFt.union)(g,I,l)},eZ=(t,A,e={})=>{const i=t.hole_shape||"circle",o=e.sizeDelta??0,n=t.hole_offset_x||0,s=t.hole_offset_y||0,r=[t.x+n,t.y+s,0];if(i==="circle"){const B=Math.max((t.hole_diameter??0)+o,Po),C=Math.max(B/2,Po/2);return(0,bx.cylinder)({center:r,radius:C,height:A})}const a=t.hole_width??t.hole_diameter,g=t.hole_height??t.hole_diameter;if(!a||!g)return null;const c=Math.max(a+o,Po),I=Math.max(g+o,Po);if(i==="oval"){const B=mFt(c,I,A);return(0,AZ.translate)([r[0],r[1],0],B)}if(i==="pill"||i==="rotated_pill"){let B=wFt(c,I,A);if(!B)return null;const C=t.ccw_rotation||0;return C&&(B=(0,AZ.rotateZ)(C*Math.PI/180,B)),(0,AZ.translate)(r,B)}const l=Math.max((t.hole_diameter??a??g??Po)+o,Po);return(0,bx.cylinder)({center:r,radius:l/2,height:A})},k0=.02,tZ=64,aG=(t,A)=>A?(0,ga.intersect)(A,t):t,yN=({width:t,height:A,thickness:e,center:i,borderRadius:o})=>{const n=x0(t,A,o);if(n<=0)return(0,gr.cuboid)({center:i,size:[t,A,e]});const s=(0,gr.roundedRectangle)({size:[t,A],roundRadius:n,segments:tZ}),r=(0,PH.extrudeLinear)({height:e},s),a=i[2]-e/2;return(0,Od.translate)([i[0],i[1],a],r)},qH=(t,A,e={})=>{const{clipGeom:i}=e;t.shape||(t.shape="circle");const o=A.pcbThickness+2*k0+4*Po,n=A.pcbThickness/2+Xa.copper,s=-A.pcbThickness/2-Xa.copper,r=n-s;if(t.shape==="circle"){const a=t.outer_diameter??Math.max(t.hole_diameter,0),g=r+.01,c=(0,gr.cylinder)({center:[t.x,t.y,0],radius:a/2,height:g}),I=aG(c,i),l=(0,gr.cylinder)({center:[t.x,t.y,0],radius:Math.max(t.hole_diameter/2,.01),height:o});return(0,pD.colorize)(en.copper,(0,ga.subtract)(I,l))}if(t.shape==="oval"){const a=t.outer_width||t.hole_width||0,g=t.outer_height||t.hole_height||0,c=t.hole_width||0,I=t.hole_height||0,l=(()=>{const Q=(0,gr.cylinder)({center:[0,0,0],radius:1,height:r+.01,segments:64}),h=(0,q7A.scale)([a/2,g/2,1],Q);return(0,Od.translate)([t.x,t.y,0],h)})(),B=aG(l,i),C=(()=>{const Q=(0,gr.cylinder)({center:[0,0,0],radius:1,height:o,segments:64}),h=(0,q7A.scale)([Math.max(c/2,.01),Math.max(I/2,.01),1],Q);return(0,Od.translate)([t.x,t.y,0],h)})();return(0,pD.colorize)(en.copper,(0,ga.subtract)(B,C))}if(t.shape==="circular_hole_with_rect_pad"){const a=t.hole_offset_x||0,g=t.hole_offset_y||0,c=t.rect_pad_width||t.hole_diameter,I=t.rect_pad_height||t.hole_diameter,l=HC(t),B=aG((0,ga.union)(yN({width:c,height:I,thickness:k0,center:[t.x,t.y,n],borderRadius:l}),yN({width:c,height:I,thickness:k0,center:[t.x,t.y,s],borderRadius:l}),(()=>{const E=Math.max(r-k0*2,Po),f=(n+s)/2,m=(0,gr.roundedRectangle)({size:[c,I],roundRadius:l||0,segments:tZ}),D=(0,PH.extrudeLinear)({height:E},m);return(0,Od.translate)([t.x,t.y,f-E/2],D)})(),(0,gr.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:t.hole_diameter/2,height:r})),i),C=(0,gr.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:Math.max(t.hole_diameter/2-Po,.01),height:o}),Q=(0,gr.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:t.hole_diameter/2,height:r});let h=(0,ga.union)((0,ga.subtract)(B,Q),Q);return e.clipGeom?(h=(0,ga.subtract)(h,C),h=(0,ga.intersect)(h,e.clipGeom),(0,pD.colorize)(en.copper,h)):(0,pD.colorize)(en.copper,(0,ga.subtract)(h,C))}if(t.shape==="pill"){const a=(t.ccw_rotation||0)*Math.PI/180,g=_=>{if(!a)return _;const M=(0,Od.translate)([-t.x,-t.y,0],_),v=(0,Od.rotate)([0,0,a],M);return(0,Od.translate)([t.x,t.y,0],v)},c=t.hole_height>t.hole_width,I=c?t.hole_height:t.hole_width,l=c?t.hole_width:t.hole_height,B=c?t.outer_height||l+.2:t.outer_width||I+.2,C=c?t.outer_width||I+.2:t.outer_height||l+.2,Q=l/2,h=Math.abs(I-l),E=r+.01,d=((_,M,v)=>{const U=M/2,J=Math.abs(_-M);if(J<=1e-6)return(0,gr.cylinder)({center:[t.x,t.y,0],radius:U,height:v});const Y=(0,gr.cuboid)({center:[t.x,t.y,0],size:c?[M,J,v]:[J,M,v]}),O=(0,gr.cylinder)({center:c?[t.x,t.y-J/2,0]:[t.x-J/2,t.y,0],radius:U,height:v}),Z=(0,gr.cylinder)({center:c?[t.x,t.y+J/2,0]:[t.x+J/2,t.y,0],radius:U,height:v});return(0,ga.union)(Y,O,Z)})(B,C,E),f=(0,gr.cuboid)({center:[t.x,t.y,0],size:c?[l-2*Po,h,o]:[h,l-2*Po,o]}),m=(0,gr.cylinder)({center:c?[t.x,t.y-h/2,0]:[t.x-h/2,t.y,0],radius:Q-Po,height:o}),D=(0,gr.cylinder)({center:c?[t.x,t.y+h/2,0]:[t.x+h/2,t.y,0],radius:Q-Po,height:o}),w=(0,ga.union)(f,m,D),b=aG(g(d),i),k=g(w);return(0,pD.colorize)(en.copper,(0,ga.subtract)(b,k))}if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for pill_hole_with_rect_pad");const a=t.hole_offset_x||0,g=t.hole_offset_y||0,c=t.hole_height>t.hole_width,I=c?t.hole_height:t.hole_width,l=c?t.hole_width:t.hole_height,B=l/2,C=Math.abs(I-l),Q=t.rect_pad_width||I+.2,h=t.rect_pad_height||l+.2,E=HC(t),u=.03,d=(0,ga.union)((0,gr.cuboid)({center:[t.x+a,t.y+g,0],size:c?[l+2*u,C+2*u,r]:[C+2*u,l+2*u,r]}),(0,gr.cylinder)({center:c?[t.x+a,t.y+g-C/2,0]:[t.x+a-C/2,t.y+g,0],radius:B+u,height:r}),(0,gr.cylinder)({center:c?[t.x+a,t.y+g+C/2,0]:[t.x+a+C/2,t.y+g,0],radius:B+u,height:r})),f=(0,ga.union)((0,gr.cuboid)({center:[t.x+a,t.y+g,0],size:c?[l,C,o*1.1]:[C,l,o*1.1]}),(0,gr.cylinder)({center:c?[t.x+a,t.y+g-C/2,0]:[t.x+a-C/2,t.y+g,0],radius:B,height:o*1.1}),(0,gr.cylinder)({center:c?[t.x+a,t.y+g+C/2,0]:[t.x+a+C/2,t.y+g,0],radius:B,height:o*1.1})),m=yN({width:Q,height:h,thickness:k0,center:[t.x,t.y,n],borderRadius:E}),D=yN({width:Q,height:h,thickness:k0,center:[t.x,t.y,s],borderRadius:E}),w=(()=>{const J=Math.max(r-k0*2,Po),Z=(n+s)/2,$=(0,gr.roundedRectangle)({size:[Q,h],roundRadius:E||0,segments:tZ}),iA=(0,PH.extrudeLinear)({height:J},$);return(0,Od.translate)([t.x,t.y,Z-J/2],iA)})(),b=(0,ga.subtract)(m,f),k=(0,ga.subtract)(D,f),_=(0,ga.subtract)(w,f),M=(0,ga.union)((0,gr.cuboid)({center:[t.x+a,t.y+g,0],size:c?[l-2*Po,C-2*Po,o*1.1]:[C-2*Po,l-2*Po,o*1.1]}),(0,gr.cylinder)({center:c?[t.x+a,t.y+g-C/2,0]:[t.x+a-C/2,t.y+g,0],radius:B-Po,height:o*1.1}),(0,gr.cylinder)({center:c?[t.x+a,t.y+g+C/2,0]:[t.x+a+C/2,t.y+g,0],radius:B-Po,height:o*1.1})),v=(0,ga.subtract)(d,M),U=aG((0,ga.union)(b,k,_,v),i);return(0,pD.colorize)(en.copper,U)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for rotated_pill_hole_with_rect_pad");const a=t.hole_offset_x||0,g=t.hole_offset_y||0,c=t.hole_width,I=t.hole_height,l=c>=I,B=l?c:I,C=l?I:c,Q=C/2,h=Math.abs(B-C),E=t.rect_pad_width||c+.2,u=t.rect_pad_height||I+.2,d=HC(t),f=.03,m=(t.hole_ccw_rotation||0)*Math.PI/180,D=(t.rect_ccw_rotation||0)*Math.PI/180,w=aA=>{const eA=a*Math.cos(m)-g*Math.sin(m),oA=a*Math.sin(m)+g*Math.cos(m),rA=(0,Od.rotate)([0,0,m],aA);return(0,Od.translate)([t.x+eA,t.y+oA,0],rA)},b=aA=>{if(!D)return aA;const eA=(0,Od.translate)([-t.x,-t.y,0],aA),oA=(0,Od.rotate)([0,0,D],eA);return(0,Od.translate)([t.x,t.y,0],oA)},k=w((0,ga.union)((0,gr.cuboid)({center:[0,0,0],size:l?[h+2*f,C+2*f,r]:[C+2*f,h+2*f,r]}),(0,gr.cylinder)({center:l?[-h/2,0,0]:[0,-h/2,0],radius:Q+f,height:r}),(0,gr.cylinder)({center:l?[h/2,0,0]:[0,h/2,0],radius:Q+f,height:r}))),_=w((0,ga.union)((0,gr.cuboid)({center:[0,0,0],size:l?[h,C,o*1.1]:[C,h,o*1.1]}),(0,gr.cylinder)({center:l?[-h/2,0,0]:[0,-h/2,0],radius:Q,height:o*1.1}),(0,gr.cylinder)({center:l?[h/2,0,0]:[0,h/2,0],radius:Q,height:o*1.1}))),M=b(yN({width:E,height:u,thickness:k0,center:[t.x,t.y,n],borderRadius:d})),v=b(yN({width:E,height:u,thickness:k0,center:[t.x,t.y,s],borderRadius:d})),U=b((()=>{const aA=Math.max(r-k0*2,Po),rA=(n+s)/2,lA=(0,gr.roundedRectangle)({size:[E,u],roundRadius:d||0,segments:tZ}),EA=(0,PH.extrudeLinear)({height:aA},lA);return(0,Od.translate)([t.x,t.y,rA-aA/2],EA)})()),J=(0,ga.subtract)(M,_),Y=(0,ga.subtract)(v,_),O=(0,ga.subtract)(U,_),Z=w((0,ga.union)((0,gr.cuboid)({center:[0,0,0],size:l?[h-2*Po,C-2*Po,o*1.1]:[C-2*Po,h-2*Po,o*1.1]}),(0,gr.cylinder)({center:l?[-h/2,0,0]:[0,-h/2,0],radius:Q-Po,height:o*1.1}),(0,gr.cylinder)({center:l?[h/2,0,0]:[0,h/2,0],radius:Q-Po,height:o*1.1}))),$=(0,ga.subtract)(k,Z),iA=aG((0,ga.union)(J,Y,O,$),i);return(0,pD.colorize)(en.copper,iA)}else if(t.shape==="hole_with_polygon_pad"){const a=t.pad_outline;if(!Array.isArray(a)||a.length<3)throw new Error(`Invalid pad_outline for plated hole at (${t.x}, ${t.y})`);const g=a.map(f=>[f.x,f.y]),c=(0,gr.polygon)({points:g}),I=(n+s)/2,l=(f,m)=>{const D=Math.max(f,Po),w=(0,PH.extrudeLinear)({height:D},c);return(0,Od.translate)([t.x,t.y,m-D/2],w)},B=l(Math.max(r-k0*2,Po),I),C=l(k0,n),Q=l(k0,s),h=aG((0,ga.union)(B,C,Q),i),E=eZ(t,r);if(!E)return(0,pD.colorize)(en.copper,h);const u=eZ(t,o,{sizeDelta:-2*Po})||E;let d=(0,ga.union)((0,ga.subtract)(h,E),E);return e.clipGeom?(d=(0,ga.subtract)(d,u),d=(0,ga.intersect)(d,e.clipGeom),(0,pD.colorize)(en.copper,d)):(0,pD.colorize)(en.copper,(0,ga.subtract)(d,u))}else throw new Error(`Unsupported plated hole shape: ${t.shape}`)},iZ=Or(bH()),O7A=Or(sN()),DFt=Or(nG()),OH=Or(mx());function SFt({x:t,y:A,outerDiameter:e,holeDiameter:i,thickness:o}){if(e<=i)throw new Error(`Invalid via geometry: outerDiameter (${e}) must be > holeDiameter (${i})`);const n=Po,s=Po,r=Math.min(e/2,i/2+s),a=(0,OH.cylinder)({center:[0,0,0],radius:r,height:o,segments:$B}),g=(0,OH.cylinder)({center:[0,0,o/2],radius:e/2,height:n,segments:$B}),c=(0,OH.cylinder)({center:[0,0,-o/2],radius:e/2,height:n,segments:$B}),I=(0,O7A.union)([a,g,c]),l=o+n*2,B=(0,OH.cylinder)({center:[0,0,0],radius:i/2,height:l,segments:$B}),C=(0,O7A.subtract)(I,B);return(0,DFt.translate)([t,A,0],C)}function bFt({x:t,y:A,holeDiameter:e,thickness:i}){const o=i*1.5,n=e/2+Po;return(0,OH.cylinder)({center:[t,A,0],radius:n,height:o,segments:$B})}var W7A=64,_Ft=1,VEA=.05,Z7A=(t,A,e,i)=>{const o=x0(t,A,i);if(o<=0)return(0,Rg.cuboid)({center:[0,0,0],size:[t,A,e]});const n=(0,Rg.roundedRectangle)({size:[t,A],roundRadius:o,segments:W7A}),s=(0,iZ.extrudeLinear)({height:e},n);return(0,Fh.translate)([0,0,-e/2],s)},V7A=["initializing","processing_pads","processing_copper_pours","processing_plated_holes","processing_holes","processing_cutouts","processing_vias","finalizing","done"],xFt=class{circuitJson;board;plated_holes;holes;pads;traces;pcb_vias;pcb_cutouts;boardGeom=null;platedHoleGeoms=[];padGeoms=[];viaGeoms=[];copperPourGeoms=[];boardClipGeom=null;state="initializing";currentIndex=0;ctx;onCompleteCallback;finalGeoms=[];getHoleToCut(t,A){const e=Po/10;for(const i of this.pcb_vias)if(Math.abs(i.x-t)<e&&Math.abs(i.y-A)<e&&i.hole_diameter)return{diameter:i.hole_diameter};for(const i of this.plated_holes)if(i.shape==="circle"&&Math.abs(i.x-t)<e&&Math.abs(i.y-A)<e&&i.hole_diameter)return{diameter:i.hole_diameter};return null}constructor(t,A){this.circuitJson=t,this.onCompleteCallback=A;const e=t.filter(o=>o.type==="pcb_panel"),i=_i(t).pcb_board.list();if(e.length>0){const o=e[0],n=i.find(s=>s.pcb_panel_id===o.pcb_panel_id);this.board={type:"pcb_board",pcb_board_id:o.pcb_panel_id,center:o.center,width:o.width,height:o.height,thickness:n?.thickness??1.4,material:n?.material??"fr4",num_layers:n?.num_layers??2}}else{const o=i.filter(n=>!n.pcb_panel_id);this.board=o[0]}this.plated_holes=_i(t).pcb_plated_hole.list(),this.holes=_i(t).pcb_hole.list(),this.pads=_i(t).pcb_smtpad.list(),this.traces=_i(t).pcb_trace.list(),this.pcb_vias=_i(t).pcb_via.list(),this.pcb_cutouts=_i(t).pcb_cutout.list(),this.ctx={pcbThickness:this.board.thickness??1.2},this.initializeBoard()}initializeBoard(){const t=this.ctx.pcbThickness+2*_Ft;this.board.outline&&this.board.outline.length>0?(this.boardGeom=ZEA({outline:this.board.outline},this.ctx.pcbThickness),this.boardClipGeom=ZEA({outline:this.board.outline},t,{xyOutset:VEA})):(this.boardGeom=(0,Rg.cuboid)({size:[this.board.width,this.board.height,this.ctx.pcbThickness],center:[this.board.center.x,this.board.center.y,0]}),this.boardClipGeom=(0,Rg.cuboid)({size:[this.board.width+2*VEA,this.board.height+2*VEA,t],center:[this.board.center.x,this.board.center.y,0]})),this.state="processing_pads",this.currentIndex=0}goToNextState(){const t=V7A.indexOf(this.state);t!==-1&&(this.state=V7A[t+1],this.currentIndex=0)}step(t=1){if(this.state==="done"||!this.boardGeom)return!0;for(let A=0;A<t&&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_pads":this.currentIndex<this.pads.length?(this.processPad(this.pads[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(t){if(!this.boardGeom)return;let A=null;const e=this.ctx.pcbThickness*1.5;switch(t.shape){case"rect":{const i=x0(t.width,t.height,HC(t));if(i>0){const o=(0,Rg.roundedRectangle)({size:[t.width,t.height],roundRadius:i,segments:W7A});A=(0,iZ.extrudeLinear)({height:e},o),A=(0,Fh.translate)([0,0,-e/2],A)}else A=(0,Rg.cuboid)({center:[0,0,0],size:[t.width,t.height,e]});if(t.rotation){const o=t.rotation*Math.PI/180;A=(0,Fh.rotateZ)(o,A)}A=(0,Fh.translate)([t.center.x,t.center.y,0],A);break}case"circle":A=(0,Rg.cylinder)({center:[t.center.x,t.center.y,0],radius:t.radius,height:e});break;case"polygon":{let i=t.points.map(n=>[n.x,n.y]);if(i.length<3){console.warn(`PCB Cutout [${t.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);break}P7A(i)&&(i=i.reverse());const o=(0,Rg.polygon)({points:i});A=(0,iZ.extrudeLinear)({height:e},o),A=(0,Fh.translate)([0,0,-e/2],A);break}}A&&(this.boardGeom=(0,vg.subtract)(this.boardGeom,A))}processPlatedHole(t,A={}){if(this.boardGeom){if(t.shape==="circle"||t.shape==="circular_hole_with_rect_pad"){let e=null;if(t.shape==="circular_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="circle"||t.pad_shape&&t.pad_shape!=="rect")return;e=(0,Rg.cylinder)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],radius:t.hole_diameter/2+Po,height:this.ctx.pcbThickness*1.5})}else e=(0,Rg.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+Po,height:this.ctx.pcbThickness*1.5});A.dontCutBoard||(this.boardGeom=(0,vg.subtract)(this.boardGeom,e)),this.padGeoms=this.padGeoms.map(o=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(o,e)));const i=qH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(i)}else if(t.shape==="pill"||t.shape==="oval"){const e=t.hole_height>t.hole_width,i=e?t.hole_height:t.hole_width,o=e?t.hole_width:t.hole_height,n=o/2,s=Math.abs(i-o);let r;if(r=(0,vg.union)((0,Rg.cuboid)({center:[t.x,t.y,0],size:e?[o,s,this.ctx.pcbThickness*1.5]:[s,o,this.ctx.pcbThickness*1.5]}),(0,Rg.cylinder)({center:e?[t.x,t.y-s/2,0]:[t.x-s/2,t.y,0],radius:n,height:this.ctx.pcbThickness*1.5}),(0,Rg.cylinder)({center:e?[t.x,t.y+s/2,0]:[t.x+s/2,t.y,0],radius:n,height:this.ctx.pcbThickness*1.5})),t.ccw_rotation){const g=t.ccw_rotation*Math.PI/180;r=(0,Fh.translate)([t.x,t.y,0],(0,Fh.rotateZ)(g,(0,Fh.translate)([-t.x,-t.y,0],r)))}A.dontCutBoard||(this.boardGeom=(0,vg.subtract)(this.boardGeom,r)),this.padGeoms=this.padGeoms.map(g=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(g,r)));const a=qH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")return;const e=t.hole_height>t.hole_width,i=e?t.hole_height:t.hole_width,o=e?t.hole_width:t.hole_height,n=o/2,s=Math.abs(i-o);let r;r=(0,vg.union)((0,Rg.cuboid)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],size:e?[o,s,this.ctx.pcbThickness*1.5]:[s,o,this.ctx.pcbThickness*1.5]}),(0,Rg.cylinder)({center:e?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)-s/2,0]:[t.x+(t.hole_offset_x||0)-s/2,t.y+(t.hole_offset_y||0),0],radius:n,height:this.ctx.pcbThickness*1.5}),(0,Rg.cylinder)({center:e?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)+s/2,0]:[t.x+(t.hole_offset_x||0)+s/2,t.y+(t.hole_offset_y||0),0],radius:n,height:this.ctx.pcbThickness*1.5})),A.dontCutBoard||(this.boardGeom=(0,vg.subtract)(this.boardGeom,r)),this.padGeoms=this.padGeoms.map(g=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(g,r)));const a=qH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")return;const e=t.hole_width,i=t.hole_height,o=e>=i,n=o?e:i,s=o?i:e,r=s/2,a=Math.abs(n-s),g=t.hole_offset_x||0,c=t.hole_offset_y||0;let I=(0,vg.union)((0,Rg.cuboid)({center:[0,0,0],size:o?[a,s,this.ctx.pcbThickness*1.5]:[s,a,this.ctx.pcbThickness*1.5]}),(0,Rg.cylinder)({center:o?[-a/2,0,0]:[0,-a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}),(0,Rg.cylinder)({center:o?[a/2,0,0]:[0,a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}));const l=(t.hole_ccw_rotation||0)*Math.PI/180,B=g*Math.cos(l)-c*Math.sin(l),C=g*Math.sin(l)+c*Math.cos(l);I=(0,Fh.rotateZ)(l,I);const Q=(0,Fh.translate)([t.x+B,t.y+C,0],I);A.dontCutBoard||(this.boardGeom=(0,vg.subtract)(this.boardGeom,Q)),this.padGeoms=this.padGeoms.map(E=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(E,Q)));const h=qH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(h)}else if(t.shape==="hole_with_polygon_pad"){const e=t.pad_outline;if(!Array.isArray(e)||e.length<3)return;const i=this.ctx.pcbThickness*1.5,o=eZ(t,i,{sizeDelta:2*Po}),n=eZ(t,i,{sizeDelta:-2*Po});if(!o||!n)return;A.dontCutBoard||(this.boardGeom=(0,vg.subtract)(this.boardGeom,o)),this.padGeoms=this.padGeoms.map(r=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(r,o))),this.platedHoleGeoms=this.platedHoleGeoms.map(r=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(r,n)));const s=qH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(s)}}}processHole(t){if(!this.boardGeom)return;const A=this.ctx.pcbThickness*1.5;if(t.hole_shape==="circle"){const e=(0,Rg.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+Po,height:A});this.boardGeom=(0,vg.subtract)(this.boardGeom,e),this.padGeoms=this.padGeoms.map(o=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(o,e)));const i=(0,Rg.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+Po/2,height:A});this.platedHoleGeoms=this.platedHoleGeoms.map(o=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(o,i)))}else if(t.hole_shape==="pill"||t.hole_shape==="rotated_pill"||t.hole_shape==="oval"){const e=t.hole_width??t.hole_diameter,i=t.hole_height??t.hole_diameter,o=t.ccw_rotation??t.rotation??0,n=.02,s=(g,c,I,l)=>{if(g<=0||c<=0)return null;if(l)return(0,Fh.translate)([0,0,-I/2],(0,iZ.extrudeLinear)({height:I},(0,Rg.ellipse)({radius:[g/2,c/2]})));const B=Math.min(g,c)/2,C=Math.abs(g-c);return g>c?(0,vg.union)((0,Rg.cuboid)({center:[0,0,0],size:[C,c,I]}),(0,Rg.cylinder)({center:[-C/2,0,0],radius:B,height:I}),(0,Rg.cylinder)({center:[C/2,0,0],radius:B,height:I})):(0,vg.union)((0,Rg.cuboid)({center:[0,0,0],size:[g,C,I]}),(0,Rg.cylinder)({center:[0,-C/2,0],radius:B,height:I}),(0,Rg.cylinder)({center:[0,C/2,0],radius:B,height:I}))};let r=s(e,i,A,t.hole_shape==="oval"),a=s(e-2*n,i-2*n,A,t.hole_shape==="oval");if(r&&o!==0&&(r=(0,Fh.rotateZ)(o*Math.PI/180,r)),a&&o!==0&&(a=(0,Fh.rotateZ)(o*Math.PI/180,a)),r){const g=(0,Fh.translate)([t.x,t.y,0],r);this.boardGeom=(0,vg.subtract)(this.boardGeom,g),this.padGeoms=this.padGeoms.map(c=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(c,g)))}if(a){const g=(0,Fh.translate)([t.x,t.y,0],a);this.platedHoleGeoms=this.platedHoleGeoms.map(c=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(c,g)))}}}processPad(t){const A=t.layer==="bottom"?-1:1,e=A*this.ctx.pcbThickness/2+A*Xa.copper,i=HC(t);if(t.shape==="rect"){const o=Z7A(t.width,t.height,Po,i);let s=(0,Fh.translate)([t.x,t.y,e],o);this.boardClipGeom&&(s=(0,vg.intersect)(this.boardClipGeom,s)),s=(0,Wu.colorize)(en.copper,s),this.padGeoms.push(s)}else if(t.shape==="rotated_rect"){let o=Z7A(t.width,t.height,Po,i);const n=t.ccw_rotation*Math.PI/180;o=(0,Fh.rotateZ)(n,o);let r=(0,Fh.translate)([t.x,t.y,e],o);this.boardClipGeom&&(r=(0,vg.intersect)(this.boardClipGeom,r)),r=(0,Wu.colorize)(en.copper,r),this.padGeoms.push(r)}else if(t.shape==="circle"){let o=(0,Rg.cylinder)({center:[t.x,t.y,e],radius:t.radius,height:Po});this.boardClipGeom&&(o=(0,vg.intersect)(this.boardClipGeom,o)),o=(0,Wu.colorize)(en.copper,o),this.padGeoms.push(o)}}processVia(t){if(this.boardGeom){if(typeof t.outer_diameter=="number"&&typeof t.hole_diameter=="number"){const A=SFt({x:t.x,y:t.y,outerDiameter:t.outer_diameter,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});let e=A;this.boardClipGeom&&(e=(0,vg.intersect)(this.boardClipGeom,A),e=(0,Wu.colorize)(en.copper,e)),this.viaGeoms.push(e)}if(typeof t.hole_diameter=="number"){const A=bFt({x:t.x,y:t.y,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});this.boardGeom=(0,vg.subtract)(this.boardGeom,A),this.padGeoms=this.padGeoms.map(e=>(0,Wu.colorize)(en.copper,(0,vg.subtract)(e,A)))}}}finalize(){if(!this.boardGeom)return;const t=WEA[this.board.material]??en.fr4Tan;this.boardGeom=(0,Wu.colorize)(t,this.boardGeom),this.finalGeoms=[this.boardGeom,...this.platedHoleGeoms,...this.padGeoms,...this.viaGeoms,...this.copperPourGeoms],this.onCompleteCallback&&this.onCompleteCallback(this.finalGeoms)}getGeoms(){return this.finalGeoms}},kFt=t=>{const[A,e]=V.useState(null),i=V.useRef(!1);return V.useEffect(()=>{let o=!1;if(!t){e(null);return}if(!t.some(g=>g.type==="pcb_board"||g.type==="pcb_panel")){e(null);return}const s=uFt(t);e(s);const r=new xFt(t,g=>{});return(async()=>{if(!i.current){i.current=!0;try{let g=!1;for(;!g&&!o;)g=r.step(1),g||await new Promise(c=>setTimeout(c,0));o||e(r.getGeoms())}catch(g){console.error("Error during board geometry building:",g)}finally{i.current=!1}}})(),()=>{o=!0}},[t]),A},FFt=({children:t,parent:A,position:e,rotation:i,scale:o,color:n,fontSize:s,anchorX:r,anchorY:a,depthOffset:g})=>{const{rootObject:c}=Ou(),I=V.useMemo(()=>{const l=new daA;return l.text=t,e&&l.position.fromArray(e),i&&l.rotation.fromArray(i),o&&l.scale.fromArray(o),l.color=n||"white",l.fontSize=s||1,l.anchorX=r||"center",l.anchorY=a||"middle",l.depthOffset=g||0,l.font=null,l.sync(),l},[t,e,i,o,n,s,r,a,g]);return V.useEffect(()=>{const l=A||c;if(!(!l||!I))return l.add(I),()=>{l.remove(I),I.dispose()}},[c,A,I]),null},j7A=({error:t,cad_component:A})=>{const{rootObject:e}=Ou(),[i,o]=V.useState(!1),[n,s]=V.useState(null),r=V.useCallback(I=>{I?.mousePosition?(o(!0),s(I.mousePosition)):(o(!1),s(null))},[]),a=V.useCallback(()=>{o(!1),s(null)},[]),g=V.useMemo(()=>A?.position?[A.position.x,A.position.y,A.position.z].map(l=>Number.isNaN(l)?0:l):[0,0,0],[A]),c=V.useMemo(()=>{const I=new hf;return I.position.fromArray(g),I},[g]);return V.useEffect(()=>{if(e)return e.add(c),()=>{e.remove(c)}},[e,c]),W.jsxs(W.Fragment,{children:[W.jsxs(TH,{isHovered:i,onHover:r,onUnhover:a,object:c,children:[W.jsx(GFt,{parent:c}),W.jsx(FFt,{parent:c,scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:`${t.toString().slice(0,50)}...`})]}),i&&n?W.jsx(I6A,{position:n,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:t.toString()}):null]})},GFt=({parent:t})=>{const A=V.useMemo(()=>{const e=new an(new tw(.5,.5,.5),new RE({depthTest:!1,transparent:!0,color:"red",opacity:.5}));return e.renderOrder=999999,e.rotation.fromArray([Math.PI/4,Math.PI/4,0]),e},[]);return V.useEffect(()=>(t.add(A),()=>{t.remove(A)}),[t,A]),null};function RFt({stlUrl:t,stlData:A,mtlUrl:e,color:i,opacity:o=1}){const{rootObject:n}=Ou(),[s,r]=V.useState(null);V.useEffect(()=>{const g=new ygt;if(A){try{const c=g.parse(A);r(c)}catch(c){console.error("Failed to parse STL data",c),r(null)}return}t&&g.load(t,c=>{r(c)})},[t,A]);const a=V.useMemo(()=>{if(!s)return null;const g=new RE({color:Array.isArray(i)?new Oi(i[0],i[1],i[2]):i,transparent:o!==1,opacity:o});return new an(s,g)},[s,i,o]);return V.useEffect(()=>{if(!(!n||!a))return n.add(a),()=>{n.remove(a),a.geometry.dispose(),Array.isArray(a.material)?a.material.forEach(g=>g.dispose()):a.material.dispose()}},[n,a]),null}function vFt({stlData:t,color:A,opacity:e=1,layerType:i}){const{visibility:o}=rN();let n=!0;return i==="board"?n=o.boardBody:i==="top-copper"?n=o.topCopper:i==="bottom-copper"?n=o.bottomCopper:i==="top-silkscreen"?n=o.topSilkscreen:i==="bottom-silkscreen"&&(n=o.bottomSilkscreen),n?W.jsx(RFt,{stlData:t,color:A,opacity:e}):null}var z7A=class extends no.Component{constructor(t){super(t),this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},MFt=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,o=t[0].y;for(let n=1;n<t.length;n++){const s=t[n];s.x<A&&(A=s.x),s.y<e&&(e=s.y),s.x>i&&(i=s.x),s.y>o&&(o=s.y)}return{minX:A,minY:e,maxX:i,maxY:o}};function gG(t){if(t.outline&&t.outline.length>=3){const s=MFt(t.outline);return{...s,width:s.maxX-s.minX,height:s.maxY-s.minY,centerX:(s.minX+s.maxX)/2,centerY:(s.minY+s.maxY)/2}}const A=t.width??0,e=t.height??0,i=t.center?.x??0,o=t.center?.y??0;return{...{minX:i-A/2,maxX:i+A/2,minY:o-e/2,maxY:o+e/2},width:A,height:e,centerX:i,centerY:o}}Or(mx()),Or(sN());function NFt(t,A,e,i){if(!e||Math.abs(e)<1e-9)return[];const o=4*Math.atan(e),n=A[0]-t[0],s=A[1]-t[1],r=Math.sqrt(n*n+s*s);if(r<1e-9)return[];const a=Math.abs(r/(2*Math.sin(o/2))),g=Math.sqrt(Math.max(0,a*a-r/2*(r/2))),c=[(t[0]+A[0])/2,(t[1]+A[1])/2],I=n/r,B=-(s/r),C=I,Q=c[0]+B*g*Math.sign(e),h=c[1]+C*g*Math.sign(e),E=Math.atan2(t[1]-h,t[0]-Q),u=[],d=Math.max(2,Math.ceil(i*Math.abs(o)/(Math.PI*2)*4)),f=o/d;for(let m=1;m<d;m++){const D=E+f*m;u.push([Q+a*Math.cos(D),h+a*Math.sin(D)])}return u}function X7A(t,A){const e=[],i=t.vertices;for(let o=0;o<i.length;o++){const n=i[o],s=i[(o+1)%i.length];if(e.push([n.x,n.y]),n.bulge){const r=NFt([n.x,n.y],[s.x,s.y],n.bulge,A);e.push(...r)}}return e}function $7A({ctx:t,points:A,canvasXFromPcb:e,canvasYFromPcb:i}){A.length<3||(t.beginPath(),A.forEach((o,n)=>{const s=e(o[0]),r=i(o[1]);n===0?t.moveTo(s,r):t.lineTo(s,r)}),t.closePath(),t.fill())}function LFt({ctx:t,pour:A,canvasXFromPcb:e,canvasYFromPcb:i}){const o=A.brep_shape;if(!o||!o.outer_ring)return;const n=X7A(o.outer_ring,32);if(n.length>=3&&$7A({ctx:t,points:n,canvasXFromPcb:e,canvasYFromPcb:i}),o.inner_rings&&o.inner_rings.length>0){t.globalCompositeOperation="destination-out";for(const s of o.inner_rings){const r=X7A(s,32);r.length>=3&&$7A({ctx:t,points:r,canvasXFromPcb:e,canvasYFromPcb:i})}t.globalCompositeOperation="source-over"}}function oZ({layer:t,circuitJson:A,boardData:e,traceTextureResolution:i=mc}){const o=A.filter(E=>E.type==="pcb_copper_pour"),n=t==="top"?"top_copper":"bottom_copper",s=o.filter(E=>E.layer===t);if(s.length===0)return null;const r=gG(e),a=document.createElement("canvas"),g=Math.floor(r.width*i),c=Math.floor(r.height*i);a.width=g,a.height=c;const I=a.getContext("2d");if(!I)return null;t==="bottom"&&(I.translate(0,c),I.scale(1,-1));const l=E=>(E-r.minX)*i,B=E=>(r.maxY-E)*i,C=s.filter(E=>E.shape==="rect"||E.shape==="polygon"),Q=s.filter(E=>E.shape==="brep");if(C.length>0){const E=new Lht(I);E.setCameraBounds({minX:r.minX,maxX:r.maxX,minY:r.minY,maxY:r.maxY});const u=C.filter(D=>D.covered_with_solder_mask!==!1),d=C.filter(D=>D.covered_with_solder_mask===!1),f=`rgb(${en.fr4TracesWithMaskGreen.map(D=>D*255).join(",")})`,m=`rgb(${en.copper.map(D=>D*255).join(",")})`;u.length>0&&(E.configure({colorOverrides:{copper:{top:f,bottom:f,inner1:f,inner2:f,inner3:f,inner4:f,inner5:f,inner6:f}}}),E.drawElements(u,{layers:[n]})),d.length>0&&(E.configure({colorOverrides:{copper:{top:m,bottom:m,inner1:m,inner2:m,inner3:m,inner4:m,inner5:m,inner6:m}}}),E.drawElements(d,{layers:[n]}))}for(const E of Q){const d=E.covered_with_solder_mask!==!1?en.fr4TracesWithMaskGreen:en.copper,f=`rgb(${d[0]*255}, ${d[1]*255}, ${d[2]*255})`;I.fillStyle=f,LFt({ctx:I,pour:E,canvasXFromPcb:l,canvasYFromPcb:B})}const h=new TM(a);return h.generateMipmaps=!0,h.minFilter=Tu,h.magFilter=gB,h.anisotropy=16,h.needsUpdate=!0,h}function pf(t,A){const{texture:e,yOffset:i,isBottomLayer:o,textureType:n,usePolygonOffset:s=!1,renderOrder:r=0,isFaux:a=!1}=t;if(!e)return null;const g=gG(A),c=new iw(g.width,g.height),I=new Td({map:e,transparent:!0,side:zB,depthWrite:n==="panel-outlines",polygonOffset:s,polygonOffsetFactor:s?-4:0,polygonOffsetUnits:s?-4:0,opacity:a?$W:1}),l=new an(c,I);return l.position.set(g.centerX,g.centerY,i),o&&l.rotation.set(Math.PI,0,0),l.name=`${o?"bottom":"top"}-${n}-texture-plane`,l.renderOrder=r,l}function UFt(t,A,e,i=!1){const o=[];if(!t||!A||e===null)return o;const n=pf({texture:t.topTrace,yOffset:e/2+Xa.traces,isBottomLayer:!1,textureType:"trace",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);n&&o.push(n);const s=pf({texture:t.topTraceWithMask,yOffset:e/2+Xa.traces,isBottomLayer:!1,textureType:"trace-with-mask",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);s&&o.push(s);const r=pf({texture:t.topSilkscreen,yOffset:e/2+.003,isBottomLayer:!1,textureType:"silkscreen",usePolygonOffset:!1,renderOrder:3,isFaux:i},A);r&&o.push(r);const a=pf({texture:t.bottomTrace,yOffset:-e/2-Xa.traces,isBottomLayer:!0,textureType:"trace",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);a&&o.push(a);const g=pf({texture:t.bottomTraceWithMask,yOffset:-e/2-Xa.traces,isBottomLayer:!0,textureType:"trace-with-mask",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);g&&o.push(g);const c=pf({texture:t.bottomSilkscreen,yOffset:-e/2-.003,isBottomLayer:!0,textureType:"silkscreen",usePolygonOffset:!1,renderOrder:3,isFaux:i},A);c&&o.push(c);const I=pf({texture:t.topSoldermask,yOffset:e/2+.001,isBottomLayer:!1,textureType:"soldermask",usePolygonOffset:!0,renderOrder:1,isFaux:i},A);I&&o.push(I);const l=pf({texture:t.bottomSoldermask,yOffset:-e/2-.001,isBottomLayer:!0,textureType:"soldermask",usePolygonOffset:!0,renderOrder:1,isFaux:i},A);l&&o.push(l);const B=pf({texture:t.topCopperText,yOffset:e/2+Xa.copper,isBottomLayer:!1,textureType:"copper-text",usePolygonOffset:!0,renderOrder:2,isFaux:i},A);B&&o.push(B);const C=pf({texture:t.bottomCopperText,yOffset:-e/2-Xa.copper,isBottomLayer:!0,textureType:"copper-text",usePolygonOffset:!0,renderOrder:2,isFaux:i},A);C&&o.push(C);const Q=pf({texture:t.topCopper,yOffset:e/2+Xa.copper,isBottomLayer:!1,textureType:"copper",usePolygonOffset:!0,renderOrder:2,isFaux:i},A);Q&&o.push(Q);const h=pf({texture:t.bottomCopper,yOffset:-e/2-Xa.copper,isBottomLayer:!0,textureType:"copper",usePolygonOffset:!0,renderOrder:2,isFaux:i},A);h&&o.push(h);const E=pf({texture:t.topPanelOutlines,yOffset:e/2+.004,isBottomLayer:!1,textureType:"panel-outlines",usePolygonOffset:!1,renderOrder:4,isFaux:i},A);E&&o.push(E);const u=pf({texture:t.bottomPanelOutlines,yOffset:-e/2-.004,isBottomLayer:!0,textureType:"panel-outlines",usePolygonOffset:!1,renderOrder:4,isFaux:i},A);return u&&o.push(u),o}var HFt=Or(tEA());function A$A(t,A){return Array.isArray(A)?[t.a*A[0]+t.c*A[1]+t.e,t.b*A[0]+t.d*A[1]+t.f]:{x:t.a*A.x+t.c*A.y+t.e,y:t.b*A.x+t.d*A.y+t.f}}function _x(t,A=0){return{a:1,c:0,e:t,b:0,d:1,f:A}}function e$A(...t){t=Array.isArray(t[0])?t[0]:t;const A=(e,i)=>({a:e.a*i.a+e.c*i.b,c:e.a*i.c+e.c*i.d,e:e.a*i.e+e.c*i.f+e.e,b:e.b*i.a+e.d*i.b,d:e.b*i.c+e.d*i.d,f:e.b*i.e+e.d*i.f+e.f});switch(t.length){case 0:throw new Error("no matrices provided");case 1:return t[0];case 2:return A(t[0],t[1]);default:{const[e,i,...o]=t,n=A(e,i);return e$A(n,...o)}}}function t$A(...t){return e$A(...t)}var{cos:YFt,sin:JFt}=Math;function i$A(t,A,e){const i=YFt(t),o=JFt(t);return{a:i,c:-o,e:0,b:o,d:i,f:0}}function TFt(t,A){function e(){this.constructor=t}e.prototype=A.prototype,t.prototype=new e}function nZ(t,A,e,i){var o=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(o,nZ.prototype),o.expected=A,o.found=e,o.location=i,o.name="SyntaxError",o}TFt(nZ,Error);function jEA(t,A,e){return e=e||" ",t.length>A?t:(A-=t.length,e+=e.repeat(A),t+e.slice(0,A))}nZ.prototype.format=function(t){var A="Error: "+this.message;if(this.location){var e=null,i;for(i=0;i<t.length;i++)if(t[i].source===this.location.source){e=t[i].text.split(/\r\n|\n|\r/g);break}var o=this.location.start,n=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(o):o,s=this.location.source+":"+n.line+":"+n.column;if(e){var r=this.location.end,a=jEA("",n.line.toString().length," "),g=e[o.line-1],c=o.line===r.line?r.column:g.length+1,I=c-o.column||1;A+=`
|
|
5173
5173
|
--> `+s+`
|
|
5174
5174
|
`+a+` |
|
|
5175
5175
|
`+n.line+" | "+g+`
|
|
5176
5176
|
`+a+" | "+jEA("",o.column-1," ")+jEA("",I,"^")}else A+=`
|
|
5177
|
-
at `+s}return A},nZ.buildMessage=function(t,A){var e={literal:function(g){return'"'+o(g.text)+'"'},class:function(g){var c=g.parts.map(function(I){return Array.isArray(I)?n(I[0])+"-"+n(I[1]):n(I)});return"["+(g.inverted?"^":"")+c.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(g){return g.description}};function i(g){return g.charCodeAt(0).toString(16).toUpperCase()}function o(g){return g.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(c){return"\\x0"+i(c)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(c){return"\\x"+i(c)})}function n(g){return g.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(c){return"\\x0"+i(c)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(c){return"\\x"+i(c)})}function s(g){return e[g.type](g)}function r(g){var c=g.map(s),I,l;if(c.sort(),c.length>0){for(I=1,l=1;I<c.length;I++)c[I-1]!==c[I]&&(c[l]=c[I],l++);c.length=l}switch(c.length){case 1:return c[0];case 2:return c[0]+" or "+c[1];default:return c.slice(0,-1).join(", ")+", or "+c[c.length-1]}}function a(g){return g?'"'+o(g)+'"':"end of input"}return"Expected "+r(t)+" but "+a(A)+" found."};var t$A=25.4,YFt=t$A/1e3,JFt=/^\s*(-?\d*(?:\.\d+)?)(?:\s*(mm|mil|inch|in|"))?\s*$/i;function TFt(t){if(!t)return;const A=t.trim().toLowerCase();return A==='"'||A==="inch"?"in":A}function vQ(t){if(t==null)return;if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(typeof t!="string")return;const A=t.trim();if(A.length===0)return;const e=A.match(JFt);if(!e){const r=Number.parseFloat(A);return Number.isFinite(r)?r:void 0}const[,i,o]=e,n=Number.parseFloat(i||"0");if(!Number.isFinite(n))return;switch(TFt(o)){case"mil":return n*YFt;case"in":return n*t$A;case"mm":case void 0:return n;default:return n}}function rw(t,A){const e=vQ(t);return e===void 0?A:e}function i$A(t){let A=t;if(A.startsWith("#")&&(A=A.slice(1)),A.length===6){const e=parseInt(A.slice(0,2),16),i=parseInt(A.slice(2,4),16),o=parseInt(A.slice(4,6),16);return`rgb(${e}, ${i}, ${o})`}return t.startsWith("rgb")?t:"rgb(255, 243, 204)"}function sZ({layer:t,circuitJson:A,boardData:e,silkscreenColor:i="rgb(255,255,255)",traceTextureResolution:o}){const n=_i(A).pcb_silkscreen_text.list(),s=_i(A).pcb_silkscreen_path.list(),r=_i(A).pcb_silkscreen_line.list(),a=_i(A).pcb_silkscreen_rect.list(),g=_i(A).pcb_silkscreen_circle.list(),c=_i(A).pcb_fabrication_note_rect.list(),I=_i(A).pcb_note_line.list(),l=n.filter(M=>M.layer===t),B=s.filter(M=>M.layer===t),C=r.filter(M=>M.layer===t),Q=a.filter(M=>M.layer===t),h=g.filter(M=>M.layer===t),E=c.filter(M=>M.layer===t),u=I.filter(M=>M.layer===t);if(l.length===0&&B.length===0&&C.length===0&&Q.length===0&&h.length===0&&E.length===0&&u.length===0)return null;const d=gG(e),f=document.createElement("canvas"),m=Math.floor(d.width*o),D=Math.floor(d.height*o);f.width=m,f.height=D;const w=f.getContext("2d");if(!w)return null;t==="bottom"&&(w.translate(0,D),w.scale(1,-1)),w.strokeStyle=i,w.fillStyle=i;const b=M=>(M-d.minX)*o,k=M=>(d.maxY-M)*o;C.forEach(M=>{const v=vQ(M.x1)??0,U=vQ(M.y1)??0,J=vQ(M.x2)??0,Y=vQ(M.y2)??0;v===J&&U===Y||(w.beginPath(),w.lineWidth=rw(M.stroke_width,.1)*o,w.lineCap="round",w.moveTo(b(v),k(U)),w.lineTo(b(J),k(Y)),w.stroke())}),u.forEach(M=>{const v=vQ(M.x1)??0,U=vQ(M.y1)??0,J=vQ(M.x2)??0,Y=vQ(M.y2)??0;if(v===J&&U===Y)return;w.save();let O=i;M.color?O=i$A(M.color):O="rgb(255, 243, 204)",w.strokeStyle=O,w.beginPath(),w.lineWidth=rw(M.stroke_width,.1)*o,w.lineCap="round";const Z=M.is_dashed??!1;if(Z){const $=Math.max(w.lineWidth*2,1);w.setLineDash([$,$])}w.moveTo(b(v),k(U)),w.lineTo(b(J),k(Y)),w.stroke(),Z&&w.setLineDash([]),w.restore()}),B.forEach(M=>{M.route.length<2||(w.beginPath(),w.lineWidth=rw(M.stroke_width,.1)*o,w.lineCap="round",w.lineJoin="round",M.route.forEach((v,U)=>{const J=b(vQ(v.x)??0),Y=k(vQ(v.y)??0);U===0?w.moveTo(J,Y):w.lineTo(J,Y)}),w.stroke())}),h.forEach(M=>{const v=rw(M.radius,0);if(v<=0)return;const U=rw(M.stroke_width,.12),J=U>0,Y=vQ(M.center?.x)??0,O=vQ(M.center?.y)??0,Z=b(Y),$=k(O),iA=v*o;if(w.save(),w.translate(Z,$),J){const aA=iA+U/2*o,eA=Math.max(0,iA-U/2*o);eA>0?(w.beginPath(),w.arc(0,0,aA,0,2*Math.PI),w.arc(0,0,eA,0,2*Math.PI,!0),w.fill("evenodd")):(w.beginPath(),w.arc(0,0,aA,0,2*Math.PI),w.fill())}else w.beginPath(),w.arc(0,0,iA,0,2*Math.PI),w.fill();w.restore()}),Q.forEach(M=>{const v=rw(M.width,0),U=rw(M.height,0);if(v<=0||U<=0)return;const J=vQ(M.center?.x)??0,Y=vQ(M.center?.y)??0,O=b(J),Z=k(Y),$=HC(M),iA=typeof $=="string"?vQ($):$,aA=x0(v,U,iA);w.save(),w.translate(O,Z);const eA=v/2*o,oA=U/2*o,rA=Math.min(aA*o,eA,oA),lA=M.stroke_width??!1,EA=M.is_filled??!0,bA=M.is_stroke_dashed??!1,GA=lA?rw(M.stroke_width,.1)*o:0;if(((QA,xA,uA,OA,PA)=>{if(w.beginPath(),PA<=0)w.rect(QA,xA,uA,OA);else{const ne=PA,yA=QA+uA,Ae=xA+OA;w.moveTo(QA+ne,xA),w.lineTo(yA-ne,xA),w.quadraticCurveTo(yA,xA,yA,xA+ne),w.lineTo(yA,Ae-ne),w.quadraticCurveTo(yA,Ae,yA-ne,Ae),w.lineTo(QA+ne,Ae),w.quadraticCurveTo(QA,Ae,QA,Ae-ne),w.lineTo(QA,xA+ne),w.quadraticCurveTo(QA,xA,QA+ne,xA),w.closePath()}})(-eA,-oA,eA*2,oA*2,rA),EA&&w.fill(),lA&&GA>0){if(w.lineWidth=GA,bA){const QA=Math.max(GA*2,1);w.setLineDash([QA,QA])}w.stroke(),bA&&w.setLineDash([])}w.restore()}),E.forEach(M=>{const v=rw(M.width,0),U=rw(M.height,0);if(v<=0||U<=0)return;const J=vQ(M.center?.x)??0,Y=vQ(M.center?.y)??0,O=b(J),Z=k(Y),$=HC(M),iA=typeof $=="string"?vQ($):$,aA=x0(v,U,iA);w.save(),w.translate(O,Z);const eA=v/2*o,oA=U/2*o,rA=Math.min(aA*o,eA,oA),lA=M.has_stroke??!1,EA=M.is_filled??!0,bA=M.is_stroke_dashed??!1,GA=lA?rw(M.stroke_width,.1)*o:0;let NA=i,QA=i;if(M.color){const uA=i$A(M.color);NA=uA,QA=uA}else NA="rgb(255, 243, 204)",QA="rgb(255, 243, 204)";if(((uA,OA,PA,ne,yA)=>{if(w.beginPath(),yA<=0)w.rect(uA,OA,PA,ne);else{const Ae=yA,qA=uA+PA,JA=OA+ne;w.moveTo(uA+Ae,OA),w.lineTo(qA-Ae,OA),w.quadraticCurveTo(qA,OA,qA,OA+Ae),w.lineTo(qA,JA-Ae),w.quadraticCurveTo(qA,JA,qA-Ae,JA),w.lineTo(uA+Ae,JA),w.quadraticCurveTo(uA,JA,uA,JA-Ae),w.lineTo(uA,OA+Ae),w.quadraticCurveTo(uA,OA,uA+Ae,OA),w.closePath()}})(-eA,-oA,eA*2,oA*2,rA),EA&&(w.fillStyle=NA,w.fill()),lA&&GA>0){if(w.strokeStyle=QA,w.lineWidth=GA,bA){const uA=Math.max(GA*2,1);w.setLineDash([uA,uA])}w.stroke(),bA&&w.setLineDash([])}w.restore()}),l.forEach(M=>{const v=M.font_size||.25,U=Math.min(Math.max(.01,v*.1),v*.05)*o;w.lineWidth=U,w.lineCap="butt",w.lineJoin="miter";const J=(0,NFt.vectorText)({height:v*.45,input:M.text}),Y=[];J.forEach(bA=>{bA.length===29?(Y.push(bA.slice(0,15)),Y.push(bA.slice(14,29))):bA.length===17?(Y.push(bA.slice(0,10)),Y.push(bA.slice(9,17))):Y.push(bA)});const O=Y.flat(),Z={minX:O.length>0?Math.min(...O.map(bA=>bA[0])):0,maxX:O.length>0?Math.max(...O.map(bA=>bA[0])):0,minY:O.length>0?Math.min(...O.map(bA=>bA[1])):0,maxY:O.length>0?Math.max(...O.map(bA=>bA[1])):0},$=(Z.minX+Z.maxX)/2,iA=(Z.minY+Z.maxY)/2;let aA=-$,eA=-iA;const oA=M.anchor_alignment||"center";oA.includes("left")?aA=-Z.minX:oA.includes("right")&&(aA=-Z.maxX),oA.includes("top")?eA=-Z.maxY:oA.includes("bottom")&&(eA=-Z.minY);const rA=[];let lA=M.ccw_rotation??0;if(M.layer==="bottom"&&(rA.push(_x($,iA),{a:-1,b:0,c:0,d:1,e:0,f:0},_x(-$,-iA)),lA=-lA),lA){const bA=lA*Math.PI/180;rA.push(_x($,iA),e$A(bA),_x(-$,-iA))}const EA=rA.length>0?A$A(...rA):void 0;Y.forEach(bA=>{w.beginPath(),bA.forEach((GA,NA)=>{let QA={x:GA[0],y:GA[1]};EA&&(QA=X7A(EA,QA));const xA=QA.x+aA+M.anchor_position.x,uA=QA.y+eA+M.anchor_position.y,OA=b(xA),PA=k(uA);NA===0?w.moveTo(OA,PA):w.lineTo(OA,PA)}),w.stroke()})});const _=new TM(f);return _.generateMipmaps=!0,_.minFilter=Tu,_.magFilter=gB,_.anisotropy=16,_.needsUpdate=!0,_}function o$A(t){return t&&t.route_type==="wire"&&typeof t.layer=="string"&&typeof t.width=="number"}function mN({layer:t,circuitJson:A,boardData:e,traceColor:i,traceTextureResolution:o}){const n=_i(A).pcb_trace.list(),s=_i(A).pcb_via.list(),r=_i(A).pcb_plated_hole.list(),a=n.filter(Q=>Q.route.some(h=>o$A(h)&&h.layer===t));if(a.length===0)return null;const g=gG(e),c=document.createElement("canvas"),I=Math.floor(g.width*o),l=Math.floor(g.height*o);c.width=I,c.height=l;const B=c.getContext("2d");if(!B)return null;t==="bottom"&&(B.translate(0,l),B.scale(1,-1)),a.forEach(Q=>{let h=!0;B.beginPath(),B.strokeStyle=i,B.lineCap="round",B.lineJoin="round";let E=0;for(const u of Q.route){if(!o$A(u)||u.layer!==t){h||B.stroke(),h=!0;continue}const d=u.x,f=u.y;E=u.width*o,B.lineWidth=E;const m=(d-g.minX)*o,D=(g.maxY-f)*o;h?(B.moveTo(m,D),h=!1):B.lineTo(m,D)}h||B.stroke()}),B.globalCompositeOperation="destination-out",B.fillStyle="black",s.forEach(Q=>{const h=(Q.x-g.minX)*o,E=(g.maxY-Q.y)*o,u=Q.outer_diameter/2*o;B.beginPath(),B.arc(h,E,u,0,2*Math.PI,!1),B.fill()}),r.forEach(Q=>{if(Q.layers.includes(t)&&Q.shape==="circle"){const h=(Q.x-g.minX)*o,E=(g.maxY-Q.y)*o,u=Q.outer_diameter/2*o;B.beginPath(),B.arc(h,E,u,0,2*Math.PI,!1),B.fill()}else if(Q.layers.includes(t)&&Q.shape==="rotated_pill_hole_with_rect_pad"){const h=(Q.x-g.minX)*o,E=(g.maxY-Q.y)*o,u=(Q.rect_pad_width??Q.hole_width??0)*o,d=(Q.rect_pad_height??Q.hole_height??0)*o,m=-(Q.rect_ccw_rotation||0);m?(B.save(),B.translate(h,E),B.rotate(m*Math.PI/180),B.beginPath(),B.rect(-u/2,-d/2,u,d),B.fill(),B.restore()):(B.beginPath(),B.rect(h-u/2,E-d/2,u,d),B.fill())}}),B.globalCompositeOperation="source-over";const C=new TM(c);return C.generateMipmaps=!0,C.minFilter=Tu,C.magFilter=gB,C.anisotropy=16,C.needsUpdate=!0,C}var KFt=Or(tEA());function rZ(t,A){if(t===void 0)return A;if(typeof t=="number")return t;const e=parseFloat(t.replace(/mm$/,""));return isNaN(e)?A:e}function PFt(t){return t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0}function qFt(t){const A=t.flat();if(A.length===0)return{minX:0,maxX:0,minY:0,maxY:0,width:0,height:0,centerX:0,centerY:0};const e=Math.min(...A.map(s=>s[0])),i=Math.max(...A.map(s=>s[0])),o=Math.min(...A.map(s=>s[1])),n=Math.max(...A.map(s=>s[1]));return{minX:e,maxX:i,minY:o,maxY:n,width:i-e,height:n-o,centerX:(e+i)/2,centerY:(o+n)/2}}function OFt(t){const A=[];return t.forEach(e=>{e.length===29?(A.push(e.slice(0,15)),A.push(e.slice(14,29))):e.length===17?(A.push(e.slice(0,10)),A.push(e.slice(9,17))):A.push(e)}),A}function WFt(t,A){let e=-t.centerX,i=-t.centerY;return A.includes("left")?e=-t.minX:A.includes("right")&&(e=-t.maxX),A.includes("top")?i=-t.maxY:A.includes("bottom")&&(i=-t.minY),{x:e,y:i}}function ZFt(t,A){const e=[];let i=t.ccw_rotation??0;if(PFt(t)&&(e.push(_x(A.centerX,A.centerY),{a:-1,b:0,c:0,d:1,e:0,f:0},_x(-A.centerX,-A.centerY)),i=-i),i){const s=i*Math.PI/180;e.push(_x(A.centerX,A.centerY),e$A(s),_x(-A.centerX,-A.centerY))}return{matrix:e.length>0?A$A(...e):void 0,rotationDeg:i}}function n$A(t,A,e,i,o,n,s){A.forEach(r=>{t.beginPath(),r.forEach((a,g)=>{let c={x:a[0],y:a[1]};e&&(c=X7A(e,c));const I=c.x+i.x+o.x,l=c.y+i.y+o.y,B=n(I),C=s(l);g===0?t.moveTo(B,C):t.lineTo(B,C)}),t.stroke()})}function VFt(t,A,e,i,o,n){t.save(),t.translate(A,e),t.rotate(-n),t.fillRect(-i/2,-o/2,i,o),t.restore()}function jFt(t,A,e,i,o,n,s,r,a,g){const c=typeof A.font_size=="number"?A.font_size:.2,I={left:rZ(A.knockout_padding?.left,c*.5),right:rZ(A.knockout_padding?.right,c*.5),top:rZ(A.knockout_padding?.top,c*.3),bottom:rZ(A.knockout_padding?.bottom,c*.3)},l=i.width+I.left+I.right,B=i.height+I.top+I.bottom,C=s(A.anchor_position.x),Q=r(A.anchor_position.y),h=l*a,E=B*a;t.fillStyle=g;const u=n*Math.PI/180;VFt(t,C,Q,h,E,u);const d={x:-i.centerX,y:-i.centerY};t.globalCompositeOperation="destination-out",n$A(t,e,o,d,A.anchor_position,s,r),t.globalCompositeOperation="source-over"}function aZ({layer:t,circuitJson:A,boardData:e,copperColor:i="rgb(230, 153, 51)",traceTextureResolution:o}){const s=A.filter(Q=>Q.type==="pcb_copper_text").filter(Q=>Q.layer===t);if(s.length===0)return null;const r=gG(e),a=document.createElement("canvas"),g=Math.floor(r.width*o),c=Math.floor(r.height*o);a.width=g,a.height=c;const I=a.getContext("2d");if(!I)return null;t==="bottom"&&(I.translate(0,c),I.scale(1,-1)),I.strokeStyle=i,I.fillStyle=i;const l=Q=>(Q-r.minX)*o,B=Q=>(r.maxY-Q)*o;s.forEach(Q=>{const h=typeof Q.font_size=="number"?Q.font_size:.2,E=Math.max(.02,h*.08)*o;I.lineWidth=E,I.lineCap="round",I.lineJoin="round";const u=(0,KFt.vectorText)({height:h*.45,input:Q.text}),d=OFt(u),f=qFt(d),{matrix:m,rotationDeg:D}=ZFt(Q,f);if(Q.is_knockout)jFt(I,Q,d,f,m,D,l,B,o,i);else{const w=Q.anchor_alignment||"center",b=WFt(f,w);n$A(I,d,m,b,Q.anchor_position,l,B)}});const C=new TM(a);return C.generateMipmaps=!0,C.minFilter=Tu,C.magFilter=gB,C.anisotropy=16,C.needsUpdate=!0,C}function gZ({layer:t,circuitJson:A,panelData:e,outlineColor:i="black",traceTextureResolution:o}){const n=_i(A).pcb_board.list().filter(B=>B.pcb_panel_id===e.pcb_board_id);if(n.length===0)return null;const s=document.createElement("canvas"),r=Math.floor(e.width*o),a=Math.floor(e.height*o);s.width=r,s.height=a;const g=s.getContext("2d");if(!g)return null;t==="bottom"&&(g.translate(0,a),g.scale(1,-1)),g.strokeStyle=i,g.lineWidth=.05*o;const c=B=>(B-e.center.x+e.width/2)*o,I=B=>(-(B-e.center.y)+e.height/2)*o;n.forEach(B=>{if(B.outline&&B.outline.length>=2)g.beginPath(),B.outline.forEach((C,Q)=>{const h=c(C.x),E=I(C.y);Q===0?g.moveTo(h,E):g.lineTo(h,E)}),g.closePath(),g.stroke();else{const C=B.width,Q=B.height,{x:h,y:E}=B.center,u=c(h-C/2),d=I(E+Q/2);g.strokeRect(u,d,C*o,Q*o)}});const l=new TM(s);return l.generateMipmaps=!0,l.minFilter=Tu,l.magFilter=gB,l.anisotropy=16,l.needsUpdate=!0,l}Or(mx()),Or(sN());function zFt(t,A,e,i){if(!e||Math.abs(e)<1e-9)return[];const o=4*Math.atan(e),n=A[0]-t[0],s=A[1]-t[1],r=Math.sqrt(n*n+s*s);if(r<1e-9)return[];const a=Math.abs(r/(2*Math.sin(o/2))),g=Math.sqrt(Math.max(0,a*a-r/2*(r/2))),c=[(t[0]+A[0])/2,(t[1]+A[1])/2],I=n/r,B=-(s/r),C=I,Q=c[0]+B*g*Math.sign(e),h=c[1]+C*g*Math.sign(e),E=Math.atan2(t[1]-h,t[0]-Q),u=[],d=Math.max(2,Math.ceil(i*Math.abs(o)/(Math.PI*2)*4)),f=o/d;for(let m=1;m<d;m++){const D=E+f*m;u.push([Q+a*Math.cos(D),h+a*Math.sin(D)])}return u}function s$A(t,A){const e=[],i=t.vertices;for(let o=0;o<i.length;o++){const n=i[o],s=i[(o+1)%i.length];if(e.push([n.x,n.y]),n.bulge){const r=zFt([n.x,n.y],[s.x,s.y],n.bulge,A);e.push(...r)}}return e}function r$A({ctx:t,points:A,canvasXFromPcb:e,canvasYFromPcb:i}){A.length<3||(t.beginPath(),A.forEach((o,n)=>{const s=e(o[0]),r=i(o[1]);n===0?t.moveTo(s,r):t.lineTo(s,r)}),t.closePath(),t.fill())}function XFt({ctx:t,pour:A,canvasXFromPcb:e,canvasYFromPcb:i}){const o=A.brep_shape;if(!o||!o.outer_ring)return;const n=s$A(o.outer_ring,32);if(n.length>=3&&r$A({ctx:t,points:n,canvasXFromPcb:e,canvasYFromPcb:i}),o.inner_rings&&o.inner_rings.length>0){t.globalCompositeOperation="destination-out";for(const s of o.inner_rings){const r=s$A(s,32);r.length>=3&&r$A({ctx:t,points:r,canvasXFromPcb:e,canvasYFromPcb:i})}t.globalCompositeOperation="source-over"}}function cZ({layer:t,circuitJson:A,boardData:e,traceTextureResolution:i=mc}){const o=A.filter(E=>E.type==="pcb_copper_pour"),n=t==="top"?"top_copper":"bottom_copper",s=o.filter(E=>E.layer===t);if(s.length===0)return null;const r=gG(e),a=document.createElement("canvas"),g=Math.floor(r.width*i),c=Math.floor(r.height*i);a.width=g,a.height=c;const I=a.getContext("2d");if(!I)return null;t==="bottom"&&(I.translate(0,c),I.scale(1,-1));const l=E=>(E-r.minX)*i,B=E=>(r.maxY-E)*i,C=s.filter(E=>E.shape==="rect"||E.shape==="polygon"),Q=s.filter(E=>E.shape==="brep");if(C.length>0){const E=new Lht(I);E.setCameraBounds({minX:r.minX,maxX:r.maxX,minY:r.minY,maxY:r.maxY});const u=C.filter(D=>D.covered_with_solder_mask!==!1),d=C.filter(D=>D.covered_with_solder_mask===!1),f=`rgb(${en.fr4TracesWithMaskGreen.map(D=>D*255).join(",")})`,m=`rgb(${en.copper.map(D=>D*255).join(",")})`;u.length>0&&(E.configure({colorOverrides:{copper:{top:f,bottom:f,inner1:f,inner2:f,inner3:f,inner4:f,inner5:f,inner6:f}}}),E.drawElements(u,{layers:[n]})),d.length>0&&(E.configure({colorOverrides:{copper:{top:m,bottom:m,inner1:m,inner2:m,inner3:m,inner4:m,inner5:m,inner6:m}}}),E.drawElements(d,{layers:[n]}))}for(const E of Q){const d=E.covered_with_solder_mask!==!1?en.fr4TracesWithMaskGreen:en.copper,f=`rgb(${d[0]*255}, ${d[1]*255}, ${d[2]*255})`;I.fillStyle=f,XFt({ctx:I,pour:E,canvasXFromPcb:l,canvasYFromPcb:B})}const h=new TM(a);return h.generateMipmaps=!0,h.minFilter=Tu,h.magFilter=gB,h.anisotropy=16,h.needsUpdate=!0,h}function pf(t,A){const{texture:e,yOffset:i,isBottomLayer:o,textureType:n,usePolygonOffset:s=!1,renderOrder:r=0,isFaux:a=!1}=t;if(!e)return null;const g=gG(A),c=new iw(g.width,g.height),I=new Td({map:e,transparent:!0,side:zB,depthWrite:n==="panel-outlines",polygonOffset:s,polygonOffsetFactor:s?-4:0,polygonOffsetUnits:s?-4:0,opacity:a?$W:1}),l=new an(c,I);return l.position.set(g.centerX,g.centerY,i),o&&l.rotation.set(Math.PI,0,0),l.name=`${o?"bottom":"top"}-${n}-texture-plane`,l.renderOrder=r,l}function $Ft(t,A,e,i=!1){const o=[];if(!t||!A||e===null)return o;const n=pf({texture:t.topTrace,yOffset:e/2+Xa.traces,isBottomLayer:!1,textureType:"trace",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);n&&o.push(n);const s=pf({texture:t.topTraceWithMask,yOffset:e/2+Xa.traces,isBottomLayer:!1,textureType:"trace-with-mask",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);s&&o.push(s);const r=pf({texture:t.topSilkscreen,yOffset:e/2+.003,isBottomLayer:!1,textureType:"silkscreen",usePolygonOffset:!1,renderOrder:3,isFaux:i},A);r&&o.push(r);const a=pf({texture:t.bottomTrace,yOffset:-e/2-Xa.traces,isBottomLayer:!0,textureType:"trace",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);a&&o.push(a);const g=pf({texture:t.bottomTraceWithMask,yOffset:-e/2-Xa.traces,isBottomLayer:!0,textureType:"trace-with-mask",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);g&&o.push(g);const c=pf({texture:t.bottomSilkscreen,yOffset:-e/2-.003,isBottomLayer:!0,textureType:"silkscreen",usePolygonOffset:!1,renderOrder:3,isFaux:i},A);c&&o.push(c);const I=pf({texture:t.topSoldermask,yOffset:e/2+.001,isBottomLayer:!1,textureType:"soldermask",usePolygonOffset:!0,renderOrder:1,isFaux:i},A);I&&o.push(I);const l=pf({texture:t.bottomSoldermask,yOffset:-e/2-.001,isBottomLayer:!0,textureType:"soldermask",usePolygonOffset:!0,renderOrder:1,isFaux:i},A);l&&o.push(l);const B=pf({texture:t.topCopperText,yOffset:e/2+Xa.copper,isBottomLayer:!1,textureType:"copper-text",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);B&&o.push(B);const C=pf({texture:t.bottomCopperText,yOffset:-e/2-Xa.copper,isBottomLayer:!0,textureType:"copper-text",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);C&&o.push(C);const Q=pf({texture:t.topCopper,yOffset:e/2+Xa.copper,isBottomLayer:!1,textureType:"copper",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);Q&&o.push(Q);const h=pf({texture:t.bottomCopper,yOffset:-e/2-Xa.copper,isBottomLayer:!0,textureType:"copper",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);h&&o.push(h);const E=pf({texture:t.topPanelOutlines,yOffset:e/2+.004,isBottomLayer:!1,textureType:"panel-outlines",usePolygonOffset:!1,renderOrder:4,isFaux:i},A);E&&o.push(E);const u=pf({texture:t.bottomPanelOutlines,yOffset:-e/2-.004,isBottomLayer:!0,textureType:"panel-outlines",usePolygonOffset:!1,renderOrder:4,isFaux:i},A);return u&&o.push(u),o}function AGt({circuitJson:t,pcbThickness:A,isFaux:e=!1}){const{rootObject:i}=Ou(),{visibility:o}=rN(),n=V.useMemo(()=>{const r=t.filter(c=>c.type==="pcb_panel"),a=_i(t).pcb_board.list();if(r.length>0){const c=r[0],I=a.find(l=>l.pcb_panel_id===c.pcb_panel_id);return{type:"pcb_board",pcb_board_id:c.pcb_panel_id,center:c.center,width:c.width,height:c.height,thickness:I?.thickness??1.4,material:I?.material??"fr4",num_layers:I?.num_layers??2}}const g=a.filter(c=>!c.pcb_panel_id);return g.length>0?g[0]:null},[t]),s=V.useMemo(()=>{if(!n||!n.width||!n.height)return null;const r=K7A[n.material]??en.fr4SolderMaskGreen,a=`rgb(${Math.round(r[0]*255)}, ${Math.round(r[1]*255)}, ${Math.round(r[2]*255)})`,g="rgb(255,255,255)",c=en.fr4TracesWithMaskGreen,I=`rgb(${Math.round(c[0]*255)}, ${Math.round(c[1]*255)}, ${Math.round(c[2]*255)})`;return{topSoldermask:oZ({layer:"top",circuitJson:t,boardData:n,soldermaskColor:a,traceTextureResolution:mc}),bottomSoldermask:oZ({layer:"bottom",circuitJson:t,boardData:n,soldermaskColor:a,traceTextureResolution:mc}),topSilkscreen:sZ({layer:"top",circuitJson:t,boardData:n,silkscreenColor:g,traceTextureResolution:mc}),bottomSilkscreen:sZ({layer:"bottom",circuitJson:t,boardData:n,silkscreenColor:g,traceTextureResolution:mc}),topTraceWithMask:mN({layer:"top",circuitJson:t,boardData:n,traceColor:I,traceTextureResolution:mc}),bottomTraceWithMask:mN({layer:"bottom",circuitJson:t,boardData:n,traceColor:I,traceTextureResolution:mc}),topCopperText:aZ({layer:"top",circuitJson:t,boardData:n,copperColor:`rgb(${Math.round(en.copper[0]*255)}, ${Math.round(en.copper[1]*255)}, ${Math.round(en.copper[2]*255)})`,traceTextureResolution:mc}),bottomCopperText:aZ({layer:"bottom",circuitJson:t,boardData:n,copperColor:`rgb(${Math.round(en.copper[0]*255)}, ${Math.round(en.copper[1]*255)}, ${Math.round(en.copper[2]*255)})`,traceTextureResolution:mc}),topPanelOutlines:gZ({layer:"top",circuitJson:t,panelData:n,traceTextureResolution:mc}),bottomPanelOutlines:gZ({layer:"bottom",circuitJson:t,panelData:n,traceTextureResolution:mc}),topCopper:cZ({layer:"top",circuitJson:t,boardData:n,traceTextureResolution:mc}),bottomCopper:cZ({layer:"bottom",circuitJson:t,boardData:n,traceTextureResolution:mc})}},[t,n]);return V.useEffect(()=>{if(!i||!n||!s)return;const r=[],a=(c,I,l,B,C=!1,Q=!1)=>{if(!c)return null;const h=gG(n),E=new iw(h.width,h.height),u=new Td({map:c,transparent:!0,side:zB,depthWrite:Q,polygonOffset:C,polygonOffsetFactor:C?-1:0,polygonOffsetUnits:C?-1:0,opacity:e?$W:1}),d=new an(E,u);return d.position.set(h.centerX,h.centerY,I),l&&d.rotation.set(Math.PI,0,0),d.name=B,d},g=.001;if(o.topMask){const c=a(s.topSoldermask,A/2+g,!1,"jscad-top-soldermask",!0);c&&(r.push(c),i.add(c))}if(o.bottomMask){const c=a(s.bottomSoldermask,-A/2-g,!0,"jscad-bottom-soldermask",!0);c&&(r.push(c),i.add(c))}if(o.topCopper&&o.topMask){const c=a(s.topTraceWithMask,A/2+Xa.traces+.004,!1,"jscad-top-trace-with-mask");c&&(r.push(c),i.add(c))}if(o.bottomCopper&&o.bottomMask){const c=a(s.bottomTraceWithMask,-A/2-Xa.traces-.005,!0,"jscad-bottom-trace-with-mask");c&&(r.push(c),i.add(c))}if(o.topSilkscreen){const c=a(s.topSilkscreen,A/2+g+.002,!1,"jscad-top-silkscreen");c&&(r.push(c),i.add(c))}if(o.bottomSilkscreen){const c=a(s.bottomSilkscreen,-A/2-g-.002,!0,"jscad-bottom-silkscreen");c&&(r.push(c),i.add(c))}if(o.topCopper){const c=a(s.topCopperText,A/2+Xa.copper,!1,"jscad-top-copper-text");c&&(r.push(c),i.add(c))}if(o.bottomCopper){const c=a(s.bottomCopperText,-A/2-Xa.copper,!0,"jscad-bottom-copper-text");c&&(r.push(c),i.add(c))}if(o.topCopper){const c=a(s.topCopper,A/2+Xa.copper,!1,"jscad-top-copper-pour");c&&(r.push(c),i.add(c))}if(o.bottomCopper){const c=a(s.bottomCopper,-A/2-Xa.copper,!0,"jscad-bottom-copper-pour");c&&(r.push(c),i.add(c))}if(o.boardBody){const c=a(s.topPanelOutlines,A/2+g+.003,!1,"jscad-top-panel-outlines",!1,!0);c&&(r.push(c),i.add(c));const I=a(s.bottomPanelOutlines,-A/2-g-.003,!0,"jscad-bottom-panel-outlines",!1,!0);I&&(r.push(I),i.add(I))}return()=>{r.forEach(c=>{c.parent===i&&i.remove(c),c.geometry.dispose(),c.material instanceof Qf&&c.material.dispose()})}},[i,n,s,A,o]),null}function eGt(t){const A=_i(t).cad_component.list(),e=_i(t).pcb_smtpad.list(),i=_i(t).pcb_hole.list(),o=_i(t).pcb_plated_hole.list(),n=_i(t).pcb_via.list();if(A.length===0&&e.length===0&&i.length===0&&o.length===0&&n.length===0)return null;const s=[...i,...o,...n,...e],r=EL(s);let a=r.minX,g=r.maxX,c=r.minY,I=r.maxY;for(const u of A)if(u.position){const d=u.position.x,f=u.position.y;a=Math.min(a,d),g=Math.max(g,d),c=Math.min(c,f),I=Math.max(I,f)}a===1/0&&(a=-10,g=10,c=-10,I=10);const l=2,B=Math.max(Math.abs(a),Math.abs(g))+l,C=Math.max(Math.abs(c),Math.abs(I))+l,Q=Math.max(2*B,10),h=Math.max(2*C,10);return{type:"pcb_board",pcb_board_id:"faux-board",center:{x:0,y:0},width:Q,height:h,thickness:1.4,material:"fr4",num_layers:2}}function a$A(t){if(_i(t).pcb_board.list().length>0)return t;const e=eGt(t);if(!e)return t;const o=e.thickness/2;return[...t.map(s=>{if(s.type==="cad_component"){const r=s;if(r.position){const a=r.position.z??0;return{...r,position:{...r.position,z:a+o}}}}return s}),e]}var tGt=V.forwardRef(({circuitJson:t,children:A,autoRotateDisabled:e,clickToInteractEnabled:i,onUserInteraction:o,onCameraControllerReady:n},s)=>{const r=T7A(A),a=V.useMemo(()=>a$A(t??r),[t,r]),g=kFt(a),c=V.useMemo(()=>{if(!a)return[5,-5,5];try{const E=_i(a).pcb_board.list()[0];if(!E)return[5,-5,5];const{width:u,height:d}=E;if(!u&&!d)return[5,-5,5];const f=5,m=Math.max(u,f),D=Math.max(d,f),w=Math.max(m,D);return[w*.4,-w*.7,w*.9]}catch(E){return console.error(E),[5,-5,5]}},[a]),I=V.useMemo(()=>{if(!a)return!1;try{const E=_i(a).pcb_board.list()[0];return!!E&&E.pcb_board_id==="faux-board"}catch{return!1}},[a]),l=V.useMemo(()=>{if(a)try{const E=_i(a).pcb_board.list()[0];return E?{width:E.width??0,height:E.height??0}:void 0}catch(E){console.error(E);return}},[a]),B=V.useMemo(()=>{if(a)try{const E=_i(a).pcb_board.list()[0];return!E||!E.center?void 0:{x:E.center.x,y:E.center.y}}catch(E){console.error(E);return}},[a]),C=g6A(a),{stls:Q}=IFt(g),h=_i(a).cad_component.list();return W.jsxs(J7A,{ref:s,autoRotateDisabled:e,initialCameraPosition:c,clickToInteractEnabled:i,boardDimensions:l,boardCenter:B,onUserInteraction:o,onCameraControllerReady:n,children:[Q.map(({stlData:E,color:u,layerType:d},f)=>W.jsx(vFt,{stlData:E,color:u,opacity:f===0?I?.8:.95:1,layerType:d},`board-${f}`)),W.jsx(AGt,{circuitJson:a,pcbThickness:C,isFaux:I}),h.map(E=>W.jsx(z7A,{fallback:({error:u})=>W.jsx(j7A,{cad_component:E,error:u}),children:W.jsx(N7A,{cad_component:E,circuitJson:a},E.cad_component_id)},E.cad_component_id))]})}),iGt=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;t[i]&&t[o]&&(A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1])}return A/2<=0};function oGt(t,A,e,i,o){let n,s=null;if(e.outline&&e.outline.length>=3){let r=e.outline.map(g=>[g.x,g.y]);iGt(r)&&(r=r.reverse());const a=A.ofPolygons([r]);o.push(a),s=a,n=t.extrude(a,i,void 0,void 0,void 0,!0),o.push(n)}else e.outline&&e.outline.length>0&&console.warn("Board outline has fewer than 3 points, falling back to rectangular board."),n=t.cube([e.width,e.height,i],!0),o.push(n),n=n.translate([e.center.x,e.center.y,0]),o.push(n);return{boardOp:n,outlineCrossSection:s}}var nGt=64;function Wd({Manifold:t,width:A,height:e,thickness:i,borderRadius:o}){const n=x0(A,e,o);if(n<=0)return t.cube([A,e,i],!0);const s=[],r=A-2*n,a=e-2*n;return r>0&&s.push(t.cube([r,e,i],!0)),a>0&&s.push(t.cube([A,a,i],!0)),[[A/2-n,e/2-n],[-A/2+n,e/2-n],[-A/2+n,-e/2+n],[A/2-n,-e/2+n]].forEach(([c,I])=>{s.push(t.cylinder(i,n,n,nGt,!0).translate([c,I,0]))}),t.union(s)}function sGt({Manifold:t,pad:A,padBaseThickness:e}){if(A.shape==="rect"){const i=HC(A);return Wd({Manifold:t,width:A.width,height:A.height,thickness:e,borderRadius:i})}else if(A.shape==="rotated_rect"){const i=HC(A);let o=Wd({Manifold:t,width:A.width,height:A.height,thickness:e,borderRadius:i});const n=A.ccw_rotation??0;return n&&(o=o.rotate([0,0,n])),o}else if(A.shape==="circle"&&A.radius)return t.cylinder(e,A.radius,-1,32,!0);return null}var rGt=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;t[i]&&t[o]&&(A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1])}return A/2<=0};function aGt(t,A,e,i,o){const n=[],s=_i(e).pcb_cutout.list();for(const r of s){let a;const g=i*1.5;switch(r.shape){case"rect":{const l=HC(r);if(typeof l=="number"&&l>0?a=Wd({Manifold:t,width:r.width,height:r.height,thickness:g,borderRadius:l}):a=t.cube([r.width,r.height,g],!0),o.push(a),r.rotation){const B=a.rotate([0,0,r.rotation]);o.push(B),a=B}a=a.translate([r.center.x,r.center.y,0]),o.push(a);break}case"circle":a=t.cylinder(g,r.radius,-1,$B,!0),o.push(a),a=a.translate([r.center.x,r.center.y,0]),o.push(a);break;case"polygon":if(r.points.length<3){console.warn(`PCB Cutout [${r.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);continue}let c=r.points.map(l=>[l.x,l.y]);rGt(c)&&(c=c.reverse());const I=A.ofPolygons([c]);o.push(I),a=t.extrude(I,g,0,0,[1,1],!0),o.push(a);break;default:console.warn(`Unsupported cutout shape: ${r.shape} for cutout ${r.pcb_cutout_id}`);continue}a&&n.push(a)}return{cutoutOps:n}}function g$A({Manifold:t,x:A,y:e,diameter:i,thickness:o,segments:n=32}){return t.cylinder(o*1.2,i/2,i/2,n,!0).translate([A,e,0])}function c$A({Manifold:t,x:A,y:e,holeDiameter:i,thickness:o,zOffset:n=.001,segments:s=32}){const r=i/2+n;return t.cylinder(o*1.2,r,r,s,!0).translate([A,e,0])}function gGt(t,A,e,i,o){const n=[],s=_i(e).pcb_hole.list(),r=(g,c,I)=>{const l=Wd({Manifold:t,width:g,height:c,thickness:I,borderRadius:Math.min(g,c)/2});return o.push(l),l},a=(g,c,I)=>{const l=[];for(let B=0;B<I;B++){const C=2*Math.PI*B/I;l.push([g/2*Math.cos(C),c/2*Math.sin(C)])}return l};return s.forEach(g=>{const c=g.hole_shape,I=g.x,l=g.y,B=i*1.2,C=g.ccw_rotation??g.rotation??0,Q=g.hole_width??g.hole_diameter,h=g.hole_height??g.hole_diameter;let E=null;if(c==="circle"){E=g$A({Manifold:t,x:I,y:l,diameter:g.hole_diameter,thickness:i,segments:$B}),n.push(E),o.push(E);return}if(c==="pill"||c==="rotated_pill")E=r(Q,h,B);else if(c==="oval"){let u=a(Q,h,$B),d=0;for(let m=0;m<u.length;m++){const D=(m+1)%u.length;d+=u[m][0]*u[D][1],d-=u[D][0]*u[m][1]}d<=0&&(u=u.reverse());const f=A.ofPolygons([u]);o.push(f),E=t.extrude(f,B,0,0,[1,1],!0),o.push(E)}if(E){if(C!==0){const d=E.rotate([0,0,C]);o.push(d),E=d}const u=E.translate([I,l,0]);o.push(u),n.push(u)}}),{nonPlatedHoleBoardDrills:n}}function aw(t){const A=new kg;if(A.setAttribute("position",new On(t.vertProperties,3)),A.setIndex(new BrA(t.triVerts,1)),t.runIndex&&t.runIndex.length>1&&t.runOriginalID)for(let e=0;e<t.runIndex.length-1;e++){const i=t.runIndex[e],o=t.runIndex[e+1]-i;A.addGroup(i,o,0)}else A.addGroup(0,t.triVerts.length,0);return A}var WH=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;t[i]&&t[o]&&(A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1])}return A/2<=0},IZ=(t,A,e)=>{const i=[];for(let o=0;o<e;o++){const n=2*Math.PI*o/e;i.push([t/2*Math.cos(n),A/2*Math.sin(n)])}return i},cG=new Oi(...en.copper),lZ=.05;function cGt(t,A,e,i,o,n){const s=[],r=_i(e).pcb_plated_hole.list(),a=[],g=[],c=(C,Q,h)=>{const E=Wd({Manifold:t,width:C,height:Q,thickness:h,borderRadius:Math.min(C,Q)/2});return o.push(E),E},I=({padOutline:C,thickness:Q})=>{if(!Array.isArray(C)||C.length<3)return null;let h=C.map(d=>[d.x,d.y]);WH(h)&&(h=h.reverse());const E=A.ofPolygons([h]);o.push(E);const u=t.extrude(E,Q,0,0,[1,1],!0);return o.push(u),u},l=({ph:C,depth:Q,sizeDelta:h=0})=>{if(C.shape!=="hole_with_polygon_pad")return null;const u=C.pad_outline;if(!Array.isArray(u)||u.length<3)return null;const d=C.hole_shape||"circle",f=C.hole_offset_x||0,m=C.hole_offset_y||0;let D=null;if(d==="circle"){const w=Math.max((C.hole_diameter??0)+h,Po),b=Math.max(w/2,Po/2);D=t.cylinder(Q,b,b,$B,!0),o.push(D)}else{const w=C.hole_width??C.hole_diameter,b=C.hole_height??C.hole_diameter;if(!w||!b)return null;const k=Math.max(w+h,Po),_=Math.max(b+h,Po);if(d==="oval"){let M=IZ(k,_,$B);WH(M)&&(M=M.reverse());const v=A.ofPolygons([M]);o.push(v),D=t.extrude(v,Q,0,0,[1,1],!0),o.push(D)}else(d==="pill"||d==="rotated_pill")&&(D=Wd({Manifold:t,width:k,height:_,thickness:Q,borderRadius:Math.min(k,_)/2}),o.push(D))}if(!D)return null;if(f||m){const w=D.translate([f,m,0]);o.push(w),D=w}return D};r.forEach((C,Q)=>{if(C.shape==="circle"){const h=c$A({Manifold:t,x:C.x,y:C.y,holeDiameter:C.hole_diameter*1.02,thickness:i,zOffset:df,segments:$B});o.push(h),s.push(h);const E=i+2*df,u=t.cylinder(E,C.outer_diameter/2,C.outer_diameter/2,$B,!0);o.push(u);const d=t.cylinder(E*1.05,C.hole_diameter/2,C.hole_diameter/2,$B,!0);o.push(d);const f=u.subtract(d);o.push(f);const m=f.translate([C.x,C.y,0]);o.push(m);let D=m;if(n){const b=t.intersection([m,n]);o.push(b),D=b}g.push(D);const w=aw(D.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:w,color:cG})}else if(C.shape==="pill"){const h=C.hole_width,E=C.hole_height,u=.4,d=C.outer_width??h+u,f=C.outer_height??E+u,m=h+2*df,D=E+2*df,w=i*1.2;let b=c(m,D,w);if(C.ccw_rotation){const Z=b.rotate([0,0,C.ccw_rotation]);o.push(Z),b=Z}const k=b.translate([C.x,C.y,0]);o.push(k),s.push(k);const _=i+2*df,M=c(d,f,_),v=c(h,E,_*1.05);let U=M.subtract(v);if(o.push(U),C.ccw_rotation){const Z=U.rotate([0,0,C.ccw_rotation]);o.push(Z),U=Z}const J=U.translate([C.x,C.y,0]);o.push(J);let Y=J;if(n){const Z=t.intersection([J,n]);o.push(Z),Y=Z}g.push(Y);const O=aw(Y.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:O,color:cG})}else if(C.shape==="pill_hole_with_rect_pad"){if(C.hole_shape&&C.hole_shape!=="pill"||C.pad_shape&&C.pad_shape!=="rect")return;const h=C.hole_width,E=C.hole_height,u=C.hole_offset_x||0,d=C.hole_offset_y||0,f=C.rect_pad_width,m=C.rect_pad_height,D=HC(C),w=KH,b=h+2*df,k=E+2*df,_=i*1.2,v=c(b,k,_).translate([u,d,0]).translate([C.x,C.y,0]);o.push(v),s.push(v);const U=Wd({Manifold:t,width:f,height:m,thickness:i-2*w-2*Xa.copper+.1,borderRadius:D});o.push(U);const J=Wd({Manifold:t,width:f,height:m,thickness:w,borderRadius:D}).translate([0,0,i/2/2+Xa.copper]),Y=Wd({Manifold:t,width:f,height:m,thickness:w,borderRadius:D}).translate([0,0,-i/2/2-Xa.copper]);o.push(J,Y);const O=c(h,E,i*1.02).translate([u,d,0]);o.push(O);const Z=t.union([U,J,Y,O]);o.push(Z);const $=c(Math.max(h-2*lZ,.01),Math.max(E-2*lZ,.01),i*1.2).translate([u,d,0]);o.push($);const iA=Z.subtract($);o.push(iA);const aA=iA.translate([C.x,C.y,0]);o.push(aA);let eA=aA;if(n){const rA=t.intersection([aA,n]);o.push(rA),eA=rA}g.push(eA);const oA=aw(eA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:oA,color:cG})}else if(C.shape==="rotated_pill_hole_with_rect_pad"){if(C.hole_shape&&C.hole_shape!=="rotated_pill"||C.pad_shape&&C.pad_shape!=="rect")return;const h=C.hole_width,E=C.hole_height,u=C.hole_offset_x||0,d=C.hole_offset_y||0,f=C.rect_pad_width,m=C.rect_pad_height,D=HC(C),w=KH,b=h+2*df,k=E+2*df,_=i*1.2;let M=c(b,k,_).translate([u,d,0]);if(C.hole_ccw_rotation){const rA=M.rotate([0,0,C.hole_ccw_rotation]);o.push(rA),M=rA}const v=M.translate([C.x,C.y,0]);o.push(v),s.push(v);let U=Wd({Manifold:t,width:f,height:m,thickness:i-2*w-2*Xa.copper+.1,borderRadius:D});if(o.push(U),C.rect_ccw_rotation){const rA=U.rotate([0,0,C.rect_ccw_rotation]);o.push(rA),U=rA}let J=Wd({Manifold:t,width:f,height:m,thickness:w,borderRadius:D}).translate([0,0,i/2/2+Xa.copper]);if(C.rect_ccw_rotation){const rA=J.rotate([0,0,C.rect_ccw_rotation]);o.push(rA),J=rA}let Y=Wd({Manifold:t,width:f,height:m,thickness:w,borderRadius:D}).translate([0,0,-i/2/2-Xa.copper]);if(C.rect_ccw_rotation){const rA=Y.rotate([0,0,C.rect_ccw_rotation]);o.push(rA),Y=rA}o.push(J,Y);let O=c(h,E,i*1.02).translate([u,d,0]);if(C.hole_ccw_rotation){const rA=O.rotate([0,0,C.hole_ccw_rotation]);o.push(rA),O=rA}o.push(O);const Z=t.union([U,J,Y,O]);o.push(Z);let $=c(Math.max(h-2*lZ,.01),Math.max(E-2*lZ,.01),i*1.2).translate([u,d,0]);if(C.hole_ccw_rotation){const rA=$.rotate([0,0,C.hole_ccw_rotation]);o.push(rA),$=rA}o.push($);const iA=Z.subtract($);o.push(iA);const aA=iA.translate([C.x,C.y,0]);o.push(aA);let eA=aA;if(n){const rA=t.intersection([aA,n]);o.push(rA),eA=rA}g.push(eA);const oA=aw(eA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:oA,color:cG})}else if(C.shape==="hole_with_polygon_pad"){const h=C.pad_outline;if(!Array.isArray(h)||h.length<3)return;const E=l({ph:C,depth:i*1.2,sizeDelta:2*Po});if(!E)return;const u=E.translate([C.x,C.y,0]);o.push(u),s.push(u);const d=KH,f=Math.max(i-2*d-2*Xa.copper+.1,Po),m=I({padOutline:h,thickness:f}),D=I({padOutline:h,thickness:d}),w=I({padOutline:h,thickness:d});if(!m||!D||!w)return;const b=D.translate([0,0,i/2/2+Xa.copper]),k=w.translate([0,0,-i/2/2-Xa.copper]);o.push(b,k);const _=l({ph:C,depth:i*1.02});if(!_)return;const M=l({ph:C,depth:i*1.2,sizeDelta:-2*Po})||_,v=t.union([m,b,k,_]);o.push(v);const U=v.subtract(M);o.push(U);const J=U.translate([C.x,C.y,0]);o.push(J);let Y=J;if(n){const Z=t.intersection([J,n]);o.push(Z),Y=Z}g.push(Y);const O=aw(Y.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:O,color:cG})}else if(C.shape==="oval"){const h=C.hole_width,E=C.hole_height,u=C.outer_width??h+.4,d=C.outer_height??E+.4,f=h+2*df,m=E+2*df,D=i*1.2;let w=IZ(f,m,$B);WH(w)&&(w=w.reverse());const b=A.ofPolygons([w]);o.push(b);let k=t.extrude(b,D,0,0,[1,1],!0);if(o.push(k),C.ccw_rotation){const oA=k.rotate([0,0,C.ccw_rotation]);o.push(oA),k=oA}const _=k.translate([C.x,C.y,0]);o.push(_),s.push(_);const M=i+2*df;let v=IZ(u,d,$B);WH(v)&&(v=v.reverse());const U=A.ofPolygons([v]);o.push(U);const J=t.extrude(U,M,0,0,[1,1],!0);o.push(J);let Y=IZ(h,E,$B);WH(Y)&&(Y=Y.reverse());const O=A.ofPolygons([Y]);o.push(O);const Z=t.extrude(O,M*1.05,0,0,[1,1],!0);o.push(Z);let $=J.subtract(Z);if(o.push($),C.ccw_rotation){const oA=$.rotate([0,0,C.ccw_rotation]);o.push(oA),$=oA}const iA=$.translate([C.x,C.y,0]);o.push(iA);let aA=iA;if(n){const oA=t.intersection([iA,n]);o.push(oA),aA=oA}g.push(aA);const eA=aw(aA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:eA,color:cG})}else if(C.shape==="circular_hole_with_rect_pad"){if(C.hole_shape&&C.hole_shape!=="circle"||C.pad_shape&&C.pad_shape!=="rect")return;const h=C.hole_offset_x||0,E=C.hole_offset_y||0,u=g$A({Manifold:t,x:C.x+h,y:C.y+E,diameter:C.hole_diameter,thickness:i,segments:$B});o.push(u),s.push(u);const d=C.rect_pad_width??C.hole_diameter,f=C.rect_pad_height??C.hole_diameter,m=HC(C),D=KH,w=C.hole_diameter/2,b=Wd({Manifold:t,width:d,height:f,thickness:i-2*D-2*Xa.copper+.1,borderRadius:m});o.push(b);const k=Wd({Manifold:t,width:d,height:f,thickness:D,borderRadius:m}).translate([0,0,i/2/2+Xa.copper]),_=Wd({Manifold:t,width:d,height:f,thickness:D,borderRadius:m}).translate([0,0,-i/2/2-Xa.copper]);o.push(k,_);const M=t.cylinder(i*1.02,w,w,$B,!0).translate([h,E,0]);o.push(M);const v=t.union([b,k,_,M]);o.push(v);const U=t.cylinder(i*1.2,Math.max(w-Po,.01),Math.max(w-Po,.01),$B,!0).translate([h,E,0]);o.push(U);const J=v.subtract(U);o.push(J);const Y=J.translate([C.x,C.y,0]);o.push(Y);let O=Y;if(n){const $=t.intersection([Y,n]);o.push($),O=$}g.push(O);const Z=aw(O.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:Z,color:cG})}});let B;return g.length>0&&(B=t.union(g),o.push(B)),{platedHoleBoardDrills:s,platedHoleCopperGeoms:a,platedHoleSubtractOp:B}}var IGt=new Oi(...en.copper);function lGt(t,A,e,i,o,n){const s=[];return _i(A).pcb_smtpad.list().forEach((a,g)=>{const c=KH,I=a.layer==="bottom"?-e/2-Xa.copper:e/2+Xa.copper;let l=sGt({Manifold:t,pad:a,padBaseThickness:c});if(l){i.push(l);const B=l.translate([a.x,a.y,I]);i.push(B);let C=B;if(o&&(C=B.subtract(o),i.push(C)),n){const h=t.intersection([C,n]);i.push(h),C=h}const Q=aw(C.getMesh());s.push({key:`smt_pad-${a.layer||"top"}-${a.pcb_smtpad_id||g}`,geometry:Q,color:IGt})}}),{smtPadGeoms:s}}function BGt({Manifold:t,x:A,y:e,outerDiameter:i,holeDiameter:o,thickness:n,zOffset:s=.001,segments:r=32}){const a=s,g=s;if(i<o)throw new Error(`Invalid via geometry: outerDiameter (${i}) must be >= holeDiameter (${o})`);const c=Math.min(i/2,o/2+g),I=t.cylinder(n,c,-1,r,!0),l=t.cylinder(a,i/2,-1,r,!0).translate([0,0,n/2]),B=t.cylinder(a,i/2,-1,r,!0).translate([0,0,-n/2]),C=t.union([I,l,B]),Q=n+a*2,h=t.cylinder(Q,o/2,-1,r,!0);return C.subtract(h).translate([A,e,0])}var CGt=new Oi(...en.copper);function QGt(t,A,e,i,o){const n=[],s=_i(A).pcb_via.list(),r=[];return s.forEach((a,g)=>{if(typeof a.hole_diameter=="number"){const c=c$A({Manifold:t,x:a.x,y:a.y,holeDiameter:a.hole_diameter,thickness:e,zOffset:df,segments:$B});i.push(c),n.push(c)}if(typeof a.outer_diameter=="number"&&typeof a.hole_diameter=="number"){const c=BGt({Manifold:t,x:a.x,y:a.y,outerDiameter:a.outer_diameter,holeDiameter:a.hole_diameter,thickness:e,zOffset:df,segments:$B});i.push(c);let I=c;if(o){const B=t.intersection([c,o]);i.push(B),I=B}const l=aw(I.getMesh());r.push({key:`via-${a.pcb_via_id||g}`,geometry:l,color:CGt})}}),{viaBoardDrills:n,viaCopperGeoms:r}}var hGt=(t,A)=>{const[e,i]=V.useState(null),[o,n]=V.useState(null),[s,r]=V.useState(null),[a,g]=V.useState(null),[c,I]=V.useState(!0),l=V.useRef([]),B=V.useMemo(()=>{const Q=A.filter(u=>u.type==="pcb_panel"),h=_i(A).pcb_board.list();if(Q.length>0){const u=Q[0],d=h.find(f=>f.pcb_panel_id===u.pcb_panel_id);return{type:"pcb_board",pcb_board_id:u.pcb_panel_id,center:u.center,width:u.width,height:u.height,thickness:d?.thickness??1.4,material:d?.material??"fr4",num_layers:d?.num_layers??2}}const E=h.filter(u=>!u.pcb_panel_id);return E.length>0?E[0]:null},[A]),C=V.useMemo(()=>{const Q=_i(A).pcb_board.list();return Q.length>0&&Q[0].pcb_board_id==="faux-board"},[A]);return V.useEffect(()=>{if(!t||!B){i(null),n(null),r(null),I(!1);return}if((B.width===0||!B.width)&&(B.height===0||!B.height)&&(!B.outline||B.outline.length<3)){i({platedHoles:[],smtPads:[],vias:[]}),n({}),r(B.thickness??0),I(!1);return}I(!0),g(null);const Q=t.Manifold,h=t.CrossSection,E=m=>{if(!(!m||typeof m.delete!="function"))try{m.delete()}catch(D){(!(D instanceof Error)||!D.message?.includes("Manifold instance already deleted"))&&console.warn("Failed to delete Manifold instance",D)}};l.current.forEach(E),l.current=[];let u=null;const d={},f={};try{const m=B.thickness||1.4;r(m);const{boardOp:D,outlineCrossSection:w}=oGt(Q,h,B,m,l.current);let b=D;const _=m+2*1;let M=null;const v=.01;if(w){let OA=w;if(v>0){const ne=w.offset(v);l.current.push(ne),OA=ne}const PA=Q.extrude(OA,_,void 0,void 0,void 0,!0);l.current.push(PA),M=PA}else{const OA=(B.width||0)+2*v,PA=(B.height||0)+2*v,ne=Q.cube([OA,PA,_],!0);l.current.push(ne);const yA=ne.translate([B.center.x,B.center.y,0]);l.current.push(yA),M=yA}const U=[];let J=null;const{nonPlatedHoleBoardDrills:Y}=gGt(Q,h,A,m,l.current);U.push(...Y);const{platedHoleBoardDrills:O,platedHoleCopperGeoms:Z,platedHoleSubtractOp:$}=cGt(Q,h,A,m,l.current,M);U.push(...O),d.platedHoles=Z;const{viaBoardDrills:iA,viaCopperGeoms:aA}=QGt(Q,A,m,l.current,M);if(U.push(...iA),d.vias=aA,U.length>0){J=Q.union(U),l.current.push(J);const OA=$?Q.union([J,$]):J;l.current.push(OA);const PA=b.subtract(OA);if(l.current.push(PA),b=PA,$){const ne=$.subtract(J);l.current.push(ne);const yA=ne.getMesh(),Ae=aw(yA);d.platedHoles=[{key:"plated-holes-union",geometry:Ae,color:new Oi(en.copper[0],en.copper[1],en.copper[2])}]}}const{cutoutOps:eA}=aGt(Q,h,A,m,l.current);if(eA.length>0){const OA=Q.union(eA);l.current.push(OA);const PA=b.subtract(OA);l.current.push(PA),b=PA}if(u=b,u){const OA=u.getMesh(),PA=aw(OA),ne=WEA[B.material]??en.fr4Tan;d.board={geometry:PA,color:new Oi(ne[0],ne[1],ne[2]),material:B.material,isFaux:C}}const{smtPadGeoms:oA}=lGt(Q,A,m,l.current,J,M);d.smtPads=oA,i(d);const rA=en.fr4TracesWithoutMaskTan,lA=`rgb(${Math.round(rA[0]*255)}, ${Math.round(rA[1]*255)}, ${Math.round(rA[2]*255)})`;f.topTrace=mN({layer:"top",circuitJson:A,boardData:B,traceColor:lA,traceTextureResolution:mc}),f.bottomTrace=mN({layer:"bottom",circuitJson:A,boardData:B,traceColor:lA,traceTextureResolution:mc});const EA=en.fr4TracesWithMaskGreen,bA=`rgb(${Math.round(EA[0]*255)}, ${Math.round(EA[1]*255)}, ${Math.round(EA[2]*255)})`;f.topTraceWithMask=mN({layer:"top",circuitJson:A,boardData:B,traceColor:bA,traceTextureResolution:mc}),f.bottomTraceWithMask=mN({layer:"bottom",circuitJson:A,boardData:B,traceColor:bA,traceTextureResolution:mc});const GA="rgb(255,255,255)";f.topSilkscreen=sZ({layer:"top",circuitJson:A,boardData:B,silkscreenColor:GA,traceTextureResolution:mc}),f.bottomSilkscreen=sZ({layer:"bottom",circuitJson:A,boardData:B,silkscreenColor:GA,traceTextureResolution:mc});const NA=K7A[B.material]??en.fr4SolderMaskGreen,QA=`rgb(${Math.round(NA[0]*255)}, ${Math.round(NA[1]*255)}, ${Math.round(NA[2]*255)})`;f.topSoldermask=oZ({layer:"top",circuitJson:A,boardData:B,soldermaskColor:QA,traceTextureResolution:mc}),f.bottomSoldermask=oZ({layer:"bottom",circuitJson:A,boardData:B,soldermaskColor:QA,traceTextureResolution:mc});const xA=en.copper,uA=`rgb(${Math.round(xA[0]*255)}, ${Math.round(xA[1]*255)}, ${Math.round(xA[2]*255)})`;f.topCopperText=aZ({layer:"top",circuitJson:A,boardData:B,copperColor:uA,traceTextureResolution:mc}),f.bottomCopperText=aZ({layer:"bottom",circuitJson:A,boardData:B,copperColor:uA,traceTextureResolution:mc}),f.topPanelOutlines=gZ({layer:"top",circuitJson:A,panelData:B,traceTextureResolution:mc}),f.bottomPanelOutlines=gZ({layer:"bottom",circuitJson:A,panelData:B,traceTextureResolution:mc}),f.topCopper=cZ({layer:"top",circuitJson:A,boardData:B,traceTextureResolution:mc}),f.bottomCopper=cZ({layer:"bottom",circuitJson:A,boardData:B,traceTextureResolution:mc}),n(f)}catch(m){console.error("Error processing geometry with Manifold in hook:",m),g(m.message||"An unknown error occurred while processing geometry in hook."),i(null),n(null)}finally{I(!1)}return()=>{l.current.forEach(E),l.current=[]}},[t,A,B]),{geoms:e,textures:o,pcbThickness:s,error:a,isLoading:c,boardData:B,isFauxBoard:C}},EGt=zB,uGt=({material:t,color:A,side:e=EGt,isFaux:i=!1})=>t==="fr4"?new ow({color:A,side:e,metalness:0,roughness:.8,specularIntensity:.2,ior:1.45,sheen:0,clearcoat:0,transparent:i,opacity:i?$W:1,flatShading:!0}):new RE({color:A,side:e,flatShading:!0,metalness:.1,roughness:.8,transparent:!0,opacity:i?$W:.9});function dGt(t){const A=[];if(!t)return A;if(t.board&&t.board.geometry){const i=new an(t.board.geometry,uGt({material:t.board.material,color:t.board.color,side:zB,isFaux:t.board.isFaux}));i.name="board-geom",A.push(i)}const e=i=>{i&&i.forEach(o=>{const n=new an(o.geometry,new RE({color:o.color,side:zB,flatShading:!0,polygonOffset:!0,polygonOffsetFactor:-1,polygonOffsetUnits:-1}));n.name=o.key,A.push(n)})};return e(t.platedHoles),e(t.smtPads),e(t.vias),A}var pGt=({geometryMeshes:t,textureMeshes:A})=>{const{rootObject:e}=Ou(),{visibility:i}=rN();return V.useEffect(()=>{if(e)return t.forEach(o=>{let n=!0;o.name==="board-geom"?n=i.boardBody:o.name.includes("smt_pad")?o.name.includes("smt_pad-top")?n=i.topCopper:o.name.includes("smt_pad-bottom")?n=i.bottomCopper:n=i.topCopper||i.bottomCopper:(o.name.includes("plated_hole")||o.name.includes("via"))&&(n=i.topCopper||i.bottomCopper),n&&e.add(o)}),A.forEach(o=>{let n=!0;o.name.includes("top-trace-texture-plane")&&!o.name.includes("with-mask")?n=i.topCopper&&!i.topMask:o.name.includes("top-trace-with-mask")?n=i.topCopper&&i.topMask:o.name.includes("bottom-trace-texture-plane")&&!o.name.includes("with-mask")?n=i.bottomCopper&&!i.bottomMask:o.name.includes("bottom-trace-with-mask")?n=i.bottomCopper&&i.bottomMask:o.name.includes("top-silkscreen")?n=i.topSilkscreen:o.name.includes("bottom-silkscreen")?n=i.bottomSilkscreen:o.name.includes("top-soldermask")?n=i.topMask:o.name.includes("bottom-soldermask")?n=i.bottomMask:o.name.includes("top-copper-text")?n=i.topCopper:o.name.includes("bottom-copper-text")?n=i.bottomCopper:o.name.includes("top-copper")?n=i.topCopper:o.name.includes("bottom-copper")?n=i.bottomCopper:o.name.includes("panel-outlines")&&(n=i.boardBody),n&&e.add(o)}),()=>{t.forEach(o=>{o.parent===e&&e.remove(o)}),A.forEach(o=>{o.parent===e&&e.remove(o)})}},[e,t,A,i]),null},fGt="https://cdn.jsdelivr.net/npm/manifold-3d@3.2.1",yGt=({circuitJson:t,autoRotateDisabled:A,clickToInteractEnabled:e,onUserInteraction:i,children:o,onCameraControllerReady:n})=>{const s=T7A(o),r=V.useMemo(()=>a$A(t??s),[t,s]),[a,g]=V.useState(null),[c,I]=V.useState(null);V.useEffect(()=>{if(window.ManifoldModule&&typeof window.ManifoldModule=="object"&&window.ManifoldModule.setup){g(window.ManifoldModule);return}const k=async Y=>{try{const O=await Y();O.setup(),window.ManifoldModule=O,g(O)}catch(O){console.error("Failed to initialize Manifold:",O),I(`Failed to initialize Manifold: ${O instanceof Error?O.message:"Unknown error"}`)}},_=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(_){window.ManifoldModule=_,k(window.ManifoldModule);return}const M="manifoldLoaded",v=()=>{const Y=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(Y)window.ManifoldModule=Y,k(window.ManifoldModule);else{const O="ManifoldModule not found on window after script load.";console.error(O),I(O)}};window.addEventListener(M,v,{once:!0});const U=document.createElement("script");U.type="module",U.innerHTML=`
|
|
5177
|
+
at `+s}return A},nZ.buildMessage=function(t,A){var e={literal:function(g){return'"'+o(g.text)+'"'},class:function(g){var c=g.parts.map(function(I){return Array.isArray(I)?n(I[0])+"-"+n(I[1]):n(I)});return"["+(g.inverted?"^":"")+c.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(g){return g.description}};function i(g){return g.charCodeAt(0).toString(16).toUpperCase()}function o(g){return g.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(c){return"\\x0"+i(c)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(c){return"\\x"+i(c)})}function n(g){return g.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(c){return"\\x0"+i(c)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(c){return"\\x"+i(c)})}function s(g){return e[g.type](g)}function r(g){var c=g.map(s),I,l;if(c.sort(),c.length>0){for(I=1,l=1;I<c.length;I++)c[I-1]!==c[I]&&(c[l]=c[I],l++);c.length=l}switch(c.length){case 1:return c[0];case 2:return c[0]+" or "+c[1];default:return c.slice(0,-1).join(", ")+", or "+c[c.length-1]}}function a(g){return g?'"'+o(g)+'"':"end of input"}return"Expected "+r(t)+" but "+a(A)+" found."};function sZ(t,A){if(t===void 0)return A;if(typeof t=="number")return t;const e=parseFloat(t.replace(/mm$/,""));return isNaN(e)?A:e}function KFt(t){return t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0}function PFt(t){const A=t.flat();if(A.length===0)return{minX:0,maxX:0,minY:0,maxY:0,width:0,height:0,centerX:0,centerY:0};const e=Math.min(...A.map(s=>s[0])),i=Math.max(...A.map(s=>s[0])),o=Math.min(...A.map(s=>s[1])),n=Math.max(...A.map(s=>s[1]));return{minX:e,maxX:i,minY:o,maxY:n,width:i-e,height:n-o,centerX:(e+i)/2,centerY:(o+n)/2}}function qFt(t){const A=[];return t.forEach(e=>{e.length===29?(A.push(e.slice(0,15)),A.push(e.slice(14,29))):e.length===17?(A.push(e.slice(0,10)),A.push(e.slice(9,17))):A.push(e)}),A}function OFt(t,A){let e=-t.centerX,i=-t.centerY;return A.includes("left")?e=-t.minX:A.includes("right")&&(e=-t.maxX),A.includes("top")?i=-t.maxY:A.includes("bottom")&&(i=-t.minY),{x:e,y:i}}function WFt(t,A){const e=[];let i=t.ccw_rotation??0;if(KFt(t)&&(e.push(_x(A.centerX,A.centerY),{a:-1,b:0,c:0,d:1,e:0,f:0},_x(-A.centerX,-A.centerY)),i=-i),i){const s=i*Math.PI/180;e.push(_x(A.centerX,A.centerY),i$A(s),_x(-A.centerX,-A.centerY))}return{matrix:e.length>0?t$A(...e):void 0,rotationDeg:i}}function o$A(t,A,e,i,o,n,s){A.forEach(r=>{t.beginPath(),r.forEach((a,g)=>{let c={x:a[0],y:a[1]};e&&(c=A$A(e,c));const I=c.x+i.x+o.x,l=c.y+i.y+o.y,B=n(I),C=s(l);g===0?t.moveTo(B,C):t.lineTo(B,C)}),t.stroke()})}function ZFt(t,A,e,i,o,n){t.save(),t.translate(A,e),t.rotate(-n),t.fillRect(-i/2,-o/2,i,o),t.restore()}function VFt(t,A,e,i,o,n,s,r,a,g){const c=typeof A.font_size=="number"?A.font_size:.2,I={left:sZ(A.knockout_padding?.left,c*.5),right:sZ(A.knockout_padding?.right,c*.5),top:sZ(A.knockout_padding?.top,c*.3),bottom:sZ(A.knockout_padding?.bottom,c*.3)},l=i.width+I.left+I.right,B=i.height+I.top+I.bottom,C=s(A.anchor_position.x),Q=r(A.anchor_position.y),h=l*a,E=B*a;t.fillStyle=g;const u=n*Math.PI/180;ZFt(t,C,Q,h,E,u);const d={x:-i.centerX,y:-i.centerY};t.globalCompositeOperation="destination-out",o$A(t,e,o,d,A.anchor_position,s,r),t.globalCompositeOperation="source-over"}function rZ({layer:t,circuitJson:A,boardData:e,copperColor:i="rgb(230, 153, 51)",traceTextureResolution:o}){const s=A.filter(Q=>Q.type==="pcb_copper_text").filter(Q=>Q.layer===t);if(s.length===0)return null;const r=gG(e),a=document.createElement("canvas"),g=Math.floor(r.width*o),c=Math.floor(r.height*o);a.width=g,a.height=c;const I=a.getContext("2d");if(!I)return null;t==="bottom"&&(I.translate(0,c),I.scale(1,-1)),I.strokeStyle=i,I.fillStyle=i;const l=Q=>(Q-r.minX)*o,B=Q=>(r.maxY-Q)*o;s.forEach(Q=>{const h=typeof Q.font_size=="number"?Q.font_size:.2,E=Math.max(.02,h*.08)*o;I.lineWidth=E,I.lineCap="round",I.lineJoin="round";const u=(0,HFt.vectorText)({height:h*.45,input:Q.text}),d=qFt(u),f=PFt(d),{matrix:m,rotationDeg:D}=WFt(Q,f);if(Q.is_knockout)VFt(I,Q,d,f,m,D,l,B,o,i);else{const w=Q.anchor_alignment||"center",b=OFt(f,w);o$A(I,d,m,b,Q.anchor_position,l,B)}});const C=new TM(a);return C.generateMipmaps=!0,C.minFilter=Tu,C.magFilter=gB,C.anisotropy=16,C.needsUpdate=!0,C}function aZ({layer:t,circuitJson:A,panelData:e,outlineColor:i="black",traceTextureResolution:o}){const n=_i(A).pcb_board.list().filter(B=>B.pcb_panel_id===e.pcb_board_id);if(n.length===0)return null;const s=document.createElement("canvas"),r=Math.floor(e.width*o),a=Math.floor(e.height*o);s.width=r,s.height=a;const g=s.getContext("2d");if(!g)return null;t==="bottom"&&(g.translate(0,a),g.scale(1,-1)),g.strokeStyle=i,g.lineWidth=.05*o;const c=B=>(B-e.center.x+e.width/2)*o,I=B=>(-(B-e.center.y)+e.height/2)*o;n.forEach(B=>{if(B.outline&&B.outline.length>=2)g.beginPath(),B.outline.forEach((C,Q)=>{const h=c(C.x),E=I(C.y);Q===0?g.moveTo(h,E):g.lineTo(h,E)}),g.closePath(),g.stroke();else{const C=B.width,Q=B.height,{x:h,y:E}=B.center,u=c(h-C/2),d=I(E+Q/2);g.strokeRect(u,d,C*o,Q*o)}});const l=new TM(s);return l.generateMipmaps=!0,l.minFilter=Tu,l.magFilter=gB,l.anisotropy=16,l.needsUpdate=!0,l}var jFt=Or(tEA()),n$A=25.4,zFt=n$A/1e3,XFt=/^\s*(-?\d*(?:\.\d+)?)(?:\s*(mm|mil|inch|in|"))?\s*$/i;function $Ft(t){if(!t)return;const A=t.trim().toLowerCase();return A==='"'||A==="inch"?"in":A}function vQ(t){if(t==null)return;if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(typeof t!="string")return;const A=t.trim();if(A.length===0)return;const e=A.match(XFt);if(!e){const r=Number.parseFloat(A);return Number.isFinite(r)?r:void 0}const[,i,o]=e,n=Number.parseFloat(i||"0");if(!Number.isFinite(n))return;switch($Ft(o)){case"mil":return n*zFt;case"in":return n*n$A;case"mm":case void 0:return n;default:return n}}function rw(t,A){const e=vQ(t);return e===void 0?A:e}function s$A(t){let A=t;if(A.startsWith("#")&&(A=A.slice(1)),A.length===6){const e=parseInt(A.slice(0,2),16),i=parseInt(A.slice(2,4),16),o=parseInt(A.slice(4,6),16);return`rgb(${e}, ${i}, ${o})`}return t.startsWith("rgb")?t:"rgb(255, 243, 204)"}function gZ({layer:t,circuitJson:A,boardData:e,silkscreenColor:i="rgb(255,255,255)",traceTextureResolution:o}){const n=_i(A).pcb_silkscreen_text.list(),s=_i(A).pcb_silkscreen_path.list(),r=_i(A).pcb_silkscreen_line.list(),a=_i(A).pcb_silkscreen_rect.list(),g=_i(A).pcb_silkscreen_circle.list(),c=_i(A).pcb_fabrication_note_rect.list(),I=_i(A).pcb_note_line.list(),l=n.filter(M=>M.layer===t),B=s.filter(M=>M.layer===t),C=r.filter(M=>M.layer===t),Q=a.filter(M=>M.layer===t),h=g.filter(M=>M.layer===t),E=c.filter(M=>M.layer===t),u=I.filter(M=>M.layer===t);if(l.length===0&&B.length===0&&C.length===0&&Q.length===0&&h.length===0&&E.length===0&&u.length===0)return null;const d=gG(e),f=document.createElement("canvas"),m=Math.floor(d.width*o),D=Math.floor(d.height*o);f.width=m,f.height=D;const w=f.getContext("2d");if(!w)return null;t==="bottom"&&(w.translate(0,D),w.scale(1,-1)),w.strokeStyle=i,w.fillStyle=i;const b=M=>(M-d.minX)*o,k=M=>(d.maxY-M)*o;C.forEach(M=>{const v=vQ(M.x1)??0,U=vQ(M.y1)??0,J=vQ(M.x2)??0,Y=vQ(M.y2)??0;v===J&&U===Y||(w.beginPath(),w.lineWidth=rw(M.stroke_width,.1)*o,w.lineCap="round",w.moveTo(b(v),k(U)),w.lineTo(b(J),k(Y)),w.stroke())}),u.forEach(M=>{const v=vQ(M.x1)??0,U=vQ(M.y1)??0,J=vQ(M.x2)??0,Y=vQ(M.y2)??0;if(v===J&&U===Y)return;w.save();let O=i;M.color?O=s$A(M.color):O="rgb(255, 243, 204)",w.strokeStyle=O,w.beginPath(),w.lineWidth=rw(M.stroke_width,.1)*o,w.lineCap="round";const Z=M.is_dashed??!1;if(Z){const $=Math.max(w.lineWidth*2,1);w.setLineDash([$,$])}w.moveTo(b(v),k(U)),w.lineTo(b(J),k(Y)),w.stroke(),Z&&w.setLineDash([]),w.restore()}),B.forEach(M=>{M.route.length<2||(w.beginPath(),w.lineWidth=rw(M.stroke_width,.1)*o,w.lineCap="round",w.lineJoin="round",M.route.forEach((v,U)=>{const J=b(vQ(v.x)??0),Y=k(vQ(v.y)??0);U===0?w.moveTo(J,Y):w.lineTo(J,Y)}),w.stroke())}),h.forEach(M=>{const v=rw(M.radius,0);if(v<=0)return;const U=rw(M.stroke_width,.12),J=U>0,Y=vQ(M.center?.x)??0,O=vQ(M.center?.y)??0,Z=b(Y),$=k(O),iA=v*o;if(w.save(),w.translate(Z,$),J){const aA=iA+U/2*o,eA=Math.max(0,iA-U/2*o);eA>0?(w.beginPath(),w.arc(0,0,aA,0,2*Math.PI),w.arc(0,0,eA,0,2*Math.PI,!0),w.fill("evenodd")):(w.beginPath(),w.arc(0,0,aA,0,2*Math.PI),w.fill())}else w.beginPath(),w.arc(0,0,iA,0,2*Math.PI),w.fill();w.restore()}),Q.forEach(M=>{const v=rw(M.width,0),U=rw(M.height,0);if(v<=0||U<=0)return;const J=vQ(M.center?.x)??0,Y=vQ(M.center?.y)??0,O=b(J),Z=k(Y),$=HC(M),iA=typeof $=="string"?vQ($):$,aA=x0(v,U,iA);w.save(),w.translate(O,Z);const eA=v/2*o,oA=U/2*o,rA=Math.min(aA*o,eA,oA),lA=M.stroke_width??!1,EA=M.is_filled??!0,bA=M.is_stroke_dashed??!1,GA=lA?rw(M.stroke_width,.1)*o:0;if(((QA,xA,uA,OA,PA)=>{if(w.beginPath(),PA<=0)w.rect(QA,xA,uA,OA);else{const ne=PA,yA=QA+uA,Ae=xA+OA;w.moveTo(QA+ne,xA),w.lineTo(yA-ne,xA),w.quadraticCurveTo(yA,xA,yA,xA+ne),w.lineTo(yA,Ae-ne),w.quadraticCurveTo(yA,Ae,yA-ne,Ae),w.lineTo(QA+ne,Ae),w.quadraticCurveTo(QA,Ae,QA,Ae-ne),w.lineTo(QA,xA+ne),w.quadraticCurveTo(QA,xA,QA+ne,xA),w.closePath()}})(-eA,-oA,eA*2,oA*2,rA),EA&&w.fill(),lA&&GA>0){if(w.lineWidth=GA,bA){const QA=Math.max(GA*2,1);w.setLineDash([QA,QA])}w.stroke(),bA&&w.setLineDash([])}w.restore()}),E.forEach(M=>{const v=rw(M.width,0),U=rw(M.height,0);if(v<=0||U<=0)return;const J=vQ(M.center?.x)??0,Y=vQ(M.center?.y)??0,O=b(J),Z=k(Y),$=HC(M),iA=typeof $=="string"?vQ($):$,aA=x0(v,U,iA);w.save(),w.translate(O,Z);const eA=v/2*o,oA=U/2*o,rA=Math.min(aA*o,eA,oA),lA=M.has_stroke??!1,EA=M.is_filled??!0,bA=M.is_stroke_dashed??!1,GA=lA?rw(M.stroke_width,.1)*o:0;let NA=i,QA=i;if(M.color){const uA=s$A(M.color);NA=uA,QA=uA}else NA="rgb(255, 243, 204)",QA="rgb(255, 243, 204)";if(((uA,OA,PA,ne,yA)=>{if(w.beginPath(),yA<=0)w.rect(uA,OA,PA,ne);else{const Ae=yA,qA=uA+PA,JA=OA+ne;w.moveTo(uA+Ae,OA),w.lineTo(qA-Ae,OA),w.quadraticCurveTo(qA,OA,qA,OA+Ae),w.lineTo(qA,JA-Ae),w.quadraticCurveTo(qA,JA,qA-Ae,JA),w.lineTo(uA+Ae,JA),w.quadraticCurveTo(uA,JA,uA,JA-Ae),w.lineTo(uA,OA+Ae),w.quadraticCurveTo(uA,OA,uA+Ae,OA),w.closePath()}})(-eA,-oA,eA*2,oA*2,rA),EA&&(w.fillStyle=NA,w.fill()),lA&&GA>0){if(w.strokeStyle=QA,w.lineWidth=GA,bA){const uA=Math.max(GA*2,1);w.setLineDash([uA,uA])}w.stroke(),bA&&w.setLineDash([])}w.restore()}),l.forEach(M=>{const v=M.font_size||.25,U=Math.min(Math.max(.01,v*.1),v*.05)*o;w.lineWidth=U,w.lineCap="butt",w.lineJoin="miter";const J=(0,jFt.vectorText)({height:v*.45,input:M.text}),Y=[];J.forEach(bA=>{bA.length===29?(Y.push(bA.slice(0,15)),Y.push(bA.slice(14,29))):bA.length===17?(Y.push(bA.slice(0,10)),Y.push(bA.slice(9,17))):Y.push(bA)});const O=Y.flat(),Z={minX:O.length>0?Math.min(...O.map(bA=>bA[0])):0,maxX:O.length>0?Math.max(...O.map(bA=>bA[0])):0,minY:O.length>0?Math.min(...O.map(bA=>bA[1])):0,maxY:O.length>0?Math.max(...O.map(bA=>bA[1])):0},$=(Z.minX+Z.maxX)/2,iA=(Z.minY+Z.maxY)/2;let aA=-$,eA=-iA;const oA=M.anchor_alignment||"center";oA.includes("left")?aA=-Z.minX:oA.includes("right")&&(aA=-Z.maxX),oA.includes("top")?eA=-Z.maxY:oA.includes("bottom")&&(eA=-Z.minY);const rA=[];let lA=M.ccw_rotation??0;if(M.layer==="bottom"&&(rA.push(_x($,iA),{a:-1,b:0,c:0,d:1,e:0,f:0},_x(-$,-iA)),lA=-lA),lA){const bA=lA*Math.PI/180;rA.push(_x($,iA),i$A(bA),_x(-$,-iA))}const EA=rA.length>0?t$A(...rA):void 0;Y.forEach(bA=>{w.beginPath(),bA.forEach((GA,NA)=>{let QA={x:GA[0],y:GA[1]};EA&&(QA=A$A(EA,QA));const xA=QA.x+aA+M.anchor_position.x,uA=QA.y+eA+M.anchor_position.y,OA=b(xA),PA=k(uA);NA===0?w.moveTo(OA,PA):w.lineTo(OA,PA)}),w.stroke()})});const _=new TM(f);return _.generateMipmaps=!0,_.minFilter=Tu,_.magFilter=gB,_.anisotropy=16,_.needsUpdate=!0,_}function cZ({layer:t,circuitJson:A,boardData:e,soldermaskColor:i,traceTextureResolution:o}){const n=gG(e),s=document.createElement("canvas"),r=Math.floor(n.width*o),a=Math.floor(n.height*o);s.width=r,s.height=a;const g=s.getContext("2d");if(!g)return null;t==="bottom"&&(g.translate(0,a),g.scale(1,-1));const c=f=>(f-n.minX)*o,I=f=>(n.maxY-f)*o;if(g.fillStyle=i,e.outline&&e.outline.length>=3){g.beginPath();const f=e.outline[0];g.moveTo(c(f.x),I(f.y));for(let m=1;m<e.outline.length;m++){const D=e.outline[m];g.lineTo(c(D.x),I(D.y))}g.closePath(),g.fill()}else g.fillRect(0,0,r,a);g.globalCompositeOperation="destination-out",g.fillStyle="black",_i(A).pcb_smtpad.list().filter(f=>f.layer===t).forEach(f=>{if(f.shape==="polygon"&&f.points){g.beginPath(),f.points.forEach((k,_)=>{const M=c(k.x),v=I(k.y);_===0?g.moveTo(M,v):g.lineTo(M,v)}),g.closePath(),g.fill();return}if(f.x===void 0||f.y===void 0)return;if(Number.isNaN(f.x)||Number.isNaN(f.y)){console.warn(`[soldermask-texture] Skipping pad ${f.pcb_smtpad_id} with NaN coordinates`);return}const m=f.x,D=f.y,w=c(m),b=I(D);if(f.shape==="rect"){const k=f.width*o,_=f.height*o,M=HC(f),v=x0(f.width,f.height,M)*o;v>0?(g.beginPath(),g.roundRect(w-k/2,b-_/2,k,_,v),g.fill()):g.fillRect(w-k/2,b-_/2,k,_)}else if(f.shape==="circle"){const k=(f.radius??f.width/2)*o;g.beginPath(),g.arc(w,b,k,0,2*Math.PI),g.fill()}else if(f.shape==="pill"){const k=f.width*o,_=f.height*o,M=HC(f),v=x0(f.width,f.height,M)*o;g.beginPath(),g.roundRect(w-k/2,b-_/2,k,_,v),g.fill()}else if(f.shape==="rotated_rect"){const k=f.width*o,_=f.height*o,M=HC(f),v=x0(f.width,f.height,M)*o,J=-(f.ccw_rotation||0)*(Math.PI/180);g.save(),g.translate(w,b),g.rotate(J),g.beginPath(),g.roundRect(-k/2,-_/2,k,_,v),g.fill(),g.restore()}}),_i(A).pcb_via.list().forEach(f=>{const m=c(f.x),D=I(f.y),w=f.outer_diameter/2*o;g.beginPath(),g.arc(m,D,w,0,2*Math.PI),g.fill()}),_i(A).pcb_plated_hole.list().forEach(f=>{if(!f.layers?.includes(t))return;const m=f.x,D=f.y,w=c(m),b=I(D);if(f.shape==="circle"){const _=f.outer_diameter/2*o;g.beginPath(),g.arc(w,b,_,0,2*Math.PI),g.fill()}else if(f.shape==="pill"){const k=(f.outer_width??f.outer_diameter??f.hole_width)*o,_=(f.outer_height??f.outer_diameter??f.hole_height)*o,M=Math.min(k,_)/2,U=-(f.ccw_rotation||0);U?(g.save(),g.translate(w,b),g.rotate(U*Math.PI/180),g.beginPath(),g.roundRect(-k/2,-_/2,k,_,M),g.fill(),g.restore()):(g.beginPath(),g.roundRect(w-k/2,b-_/2,k,_,M),g.fill())}else if(f.shape==="oval"){const k=(f.outer_width??f.outer_diameter??f.hole_width)*o,_=(f.outer_height??f.outer_diameter??f.hole_height)*o,M=k/2,v=_/2,J=-(f.ccw_rotation||0);J?(g.save(),g.translate(w,b),g.rotate(J*Math.PI/180),g.beginPath(),g.ellipse(0,0,M,v,0,0,2*Math.PI),g.fill(),g.restore()):(g.beginPath(),g.ellipse(w,b,M,v,0,0,2*Math.PI),g.fill())}else if(f.shape==="hole_with_polygon_pad"){const k=f.hole_shape||"circle",_=f.hole_offset_x||0,M=f.hole_offset_y||0,v=c(f.x+_),U=I(f.y+M);if(k==="pill"||k==="rotated_pill"){const J=(f.outer_width??f.outer_diameter??f.hole_width)*o,Y=(f.outer_height??f.outer_diameter??f.hole_height)*o,O=Math.min(J,Y)/2,$=-(f.ccw_rotation||0);$?(g.save(),g.translate(v,U),g.rotate($*Math.PI/180),g.beginPath(),g.roundRect(-J/2,-Y/2,J,Y,O),g.fill(),g.restore()):(g.beginPath(),g.roundRect(v-J/2,U-Y/2,J,Y,O),g.fill())}else if(k==="oval"){const J=(f.outer_width??f.outer_diameter??f.hole_width)*o,Y=(f.outer_height??f.outer_diameter??f.hole_height)*o,O=J/2,Z=Y/2,iA=-(f.ccw_rotation||0);iA?(g.save(),g.translate(v,U),g.rotate(iA*Math.PI/180),g.beginPath(),g.ellipse(0,0,O,Z,0,0,2*Math.PI),g.fill(),g.restore()):(g.beginPath(),g.ellipse(v,U,O,Z,0,0,2*Math.PI),g.fill())}else if(k==="circle"){const Y=(f.outer_diameter??f.hole_diameter??0)*o/2;g.beginPath(),g.arc(v,U,Y,0,2*Math.PI),g.fill()}f.pad_outline&&f.pad_outline.length>=3&&(g.beginPath(),f.pad_outline.forEach((J,Y)=>{const O=c(f.x+J.x),Z=I(f.y+J.y);Y===0?g.moveTo(O,Z):g.lineTo(O,Z)}),g.closePath(),g.fill())}else if(f.shape==="circular_hole_with_rect_pad"){const k=(f.rect_pad_width??f.hole_diameter??0)*o,_=(f.rect_pad_height??f.hole_diameter??0)*o,M=HC(f),v=x0(f.rect_pad_width??f.hole_diameter??0,f.rect_pad_height??f.hole_diameter??0,M)*o;v>0?(g.beginPath(),g.roundRect(w-k/2,b-_/2,k,_,v),g.fill()):g.fillRect(w-k/2,b-_/2,k,_)}else if(f.shape==="pill_hole_with_rect_pad"){const k=(f.rect_pad_width??f.hole_width??0)*o,_=(f.rect_pad_height??f.hole_height??0)*o,M=HC(f),v=x0(f.rect_pad_width??f.hole_width??0,f.rect_pad_height??f.hole_height??0,M)*o,J=-(f.ccw_rotation||0);J?(g.save(),g.translate(w,b),g.rotate(J*Math.PI/180),g.beginPath(),g.roundRect(-k/2,-_/2,k,_,v),g.fill(),g.restore()):(g.beginPath(),g.roundRect(w-k/2,b-_/2,k,_,v),g.fill())}else if(f.shape==="rotated_pill_hole_with_rect_pad"){const k=(f.rect_pad_width??f.hole_width??0)*o,_=(f.rect_pad_height??f.hole_height??0)*o,M=HC(f),v=x0(f.rect_pad_width??f.hole_width??0,f.rect_pad_height??f.hole_height??0,M)*o,J=-(f.rect_ccw_rotation||0);J?(g.save(),g.translate(w,b),g.rotate(J*Math.PI/180),g.beginPath(),g.roundRect(-k/2,-_/2,k,_,v),g.fill(),g.restore()):(g.beginPath(),g.roundRect(w-k/2,b-_/2,k,_,v),g.fill())}}),_i(A).pcb_hole.list().forEach(f=>{const m=f.x,D=f.y,w=c(m),b=I(D),k=f.hole_shape;if(k==="circle"&&typeof f.hole_diameter=="number"){const _=f.hole_diameter/2*o;g.beginPath(),g.arc(w,b,_,0,2*Math.PI),g.fill()}else if(k==="pill"&&typeof f.hole_width=="number"&&typeof f.hole_height=="number"){const _=f.hole_width*o,M=f.hole_height*o,v=Math.min(_,M)/2;g.beginPath(),g.roundRect(w-_/2,b-M/2,_,M,v),g.fill()}else if(k==="rotated_pill"&&typeof f.hole_width=="number"&&typeof f.hole_height=="number"){const _=f.hole_width*o,M=f.hole_height*o,v=Math.min(_,M)/2,J=-(f.ccw_rotation||0)*(Math.PI/180);J?(g.save(),g.translate(w,b),g.rotate(J),g.beginPath(),g.roundRect(-_/2,-M/2,_,M,v),g.fill(),g.restore()):(g.beginPath(),g.roundRect(w-_/2,b-M/2,_,M,v),g.fill())}else if(k==="oval"&&typeof f.hole_width=="number"&&typeof f.hole_height=="number"){const _=f.hole_width*o,M=f.hole_height*o,v=_/2,U=M/2;g.beginPath(),g.ellipse(w,b,v,U,0,0,2*Math.PI),g.fill()}}),_i(A).pcb_copper_pour.list().forEach(f=>{if(f.layer===t&&f.covered_with_solder_mask===!1)if(f.shape==="rect"){const m=c(f.center.x),D=I(f.center.y),w=f.width*o,b=f.height*o;g.fillRect(m-w/2,D-b/2,w,b)}else f.shape==="polygon"&&f.points&&(g.beginPath(),f.points.forEach((m,D)=>{const w=c(m.x),b=I(m.y);D===0?g.moveTo(w,b):g.lineTo(w,b)}),g.closePath(),g.fill())}),_i(A).pcb_cutout.list().forEach(f=>{switch(f.shape){case"rect":{const m=c(f.center.x),D=I(f.center.y),w=f.width*o,b=f.height*o,k=HC(f),_=x0(f.width,f.height,k);if(f.rotation){g.save(),g.translate(m,D);const M=-f.rotation*(Math.PI/180);g.rotate(M),_>0?(g.beginPath(),g.roundRect(-w/2,-b/2,w,b,_*o),g.fill()):g.fillRect(-w/2,-b/2,w,b),g.restore()}else _>0?(g.beginPath(),g.roundRect(m-w/2,D-b/2,w,b,_*o),g.fill()):g.fillRect(m-w/2,D-b/2,w,b);break}case"circle":{const m=c(f.center.x),D=I(f.center.y),w=f.radius*o;g.beginPath(),g.arc(m,D,w,0,2*Math.PI),g.fill();break}case"polygon":{if(!f.points||f.points.length<3){console.warn(`PCB Cutout [${f.pcb_cutout_id}] polygon has fewer than 3 points, skipping in soldermask texture.`);break}g.beginPath(),f.points.forEach((m,D)=>{const w=c(m.x),b=I(m.y);D===0?g.moveTo(w,b):g.lineTo(w,b)}),g.closePath(),g.fill();break}default:console.warn(`Unsupported cutout shape: ${f.shape} for cutout ${f.pcb_cutout_id} in soldermask texture.`)}}),g.globalCompositeOperation="source-over";const d=new TM(s);return d.generateMipmaps=!0,d.minFilter=Tu,d.magFilter=gB,d.anisotropy=16,d.needsUpdate=!0,d}function r$A(t){return t&&t.route_type==="wire"&&typeof t.layer=="string"&&typeof t.width=="number"}function mN({layer:t,circuitJson:A,boardData:e,traceColor:i,traceTextureResolution:o}){const n=_i(A).pcb_trace.list(),s=_i(A).pcb_via.list(),r=_i(A).pcb_plated_hole.list(),a=n.filter(Q=>Q.route.some(h=>r$A(h)&&h.layer===t));if(a.length===0)return null;const g=gG(e),c=document.createElement("canvas"),I=Math.floor(g.width*o),l=Math.floor(g.height*o);c.width=I,c.height=l;const B=c.getContext("2d");if(!B)return null;t==="bottom"&&(B.translate(0,l),B.scale(1,-1)),a.forEach(Q=>{let h=!0;B.beginPath(),B.strokeStyle=i,B.lineCap="round",B.lineJoin="round";let E=0;for(const u of Q.route){if(!r$A(u)||u.layer!==t){h||B.stroke(),h=!0;continue}const d=u.x,f=u.y;E=u.width*o,B.lineWidth=E;const m=(d-g.minX)*o,D=(g.maxY-f)*o;h?(B.moveTo(m,D),h=!1):B.lineTo(m,D)}h||B.stroke()}),B.globalCompositeOperation="destination-out",B.fillStyle="black",s.forEach(Q=>{const h=(Q.x-g.minX)*o,E=(g.maxY-Q.y)*o,u=Q.outer_diameter/2*o;B.beginPath(),B.arc(h,E,u,0,2*Math.PI,!1),B.fill()}),r.forEach(Q=>{if(Q.layers.includes(t)&&Q.shape==="circle"){const h=(Q.x-g.minX)*o,E=(g.maxY-Q.y)*o,u=Q.outer_diameter/2*o;B.beginPath(),B.arc(h,E,u,0,2*Math.PI,!1),B.fill()}else if(Q.layers.includes(t)&&Q.shape==="rotated_pill_hole_with_rect_pad"){const h=(Q.x-g.minX)*o,E=(g.maxY-Q.y)*o,u=(Q.rect_pad_width??Q.hole_width??0)*o,d=(Q.rect_pad_height??Q.hole_height??0)*o,m=-(Q.rect_ccw_rotation||0);m?(B.save(),B.translate(h,E),B.rotate(m*Math.PI/180),B.beginPath(),B.rect(-u/2,-d/2,u,d),B.fill(),B.restore()):(B.beginPath(),B.rect(h-u/2,E-d/2,u,d),B.fill())}}),B.globalCompositeOperation="source-over";const C=new TM(c);return C.generateMipmaps=!0,C.minFilter=Tu,C.magFilter=gB,C.anisotropy=16,C.needsUpdate=!0,C}function AGt({circuitJson:t,pcbThickness:A,isFaux:e=!1}){const{rootObject:i}=Ou(),{visibility:o}=rN(),n=V.useMemo(()=>{const r=t.filter(c=>c.type==="pcb_panel"),a=_i(t).pcb_board.list();if(r.length>0){const c=r[0],I=a.find(l=>l.pcb_panel_id===c.pcb_panel_id);return{type:"pcb_board",pcb_board_id:c.pcb_panel_id,center:c.center,width:c.width,height:c.height,thickness:I?.thickness??1.4,material:I?.material??"fr4",num_layers:I?.num_layers??2}}const g=a.filter(c=>!c.pcb_panel_id);return g.length>0?g[0]:null},[t]),s=V.useMemo(()=>{if(!n||!n.width||!n.height)return null;const r=K7A[n.material]??en.fr4SolderMaskGreen,a=`rgb(${Math.round(r[0]*255)}, ${Math.round(r[1]*255)}, ${Math.round(r[2]*255)})`,g="rgb(255,255,255)",c=en.fr4TracesWithMaskGreen,I=`rgb(${Math.round(c[0]*255)}, ${Math.round(c[1]*255)}, ${Math.round(c[2]*255)})`;return{topSoldermask:cZ({layer:"top",circuitJson:t,boardData:n,soldermaskColor:a,traceTextureResolution:mc}),bottomSoldermask:cZ({layer:"bottom",circuitJson:t,boardData:n,soldermaskColor:a,traceTextureResolution:mc}),topSilkscreen:gZ({layer:"top",circuitJson:t,boardData:n,silkscreenColor:g,traceTextureResolution:mc}),bottomSilkscreen:gZ({layer:"bottom",circuitJson:t,boardData:n,silkscreenColor:g,traceTextureResolution:mc}),topTraceWithMask:mN({layer:"top",circuitJson:t,boardData:n,traceColor:I,traceTextureResolution:mc}),bottomTraceWithMask:mN({layer:"bottom",circuitJson:t,boardData:n,traceColor:I,traceTextureResolution:mc}),topCopperText:rZ({layer:"top",circuitJson:t,boardData:n,copperColor:`rgb(${Math.round(en.copper[0]*255)}, ${Math.round(en.copper[1]*255)}, ${Math.round(en.copper[2]*255)})`,traceTextureResolution:mc}),bottomCopperText:rZ({layer:"bottom",circuitJson:t,boardData:n,copperColor:`rgb(${Math.round(en.copper[0]*255)}, ${Math.round(en.copper[1]*255)}, ${Math.round(en.copper[2]*255)})`,traceTextureResolution:mc}),topPanelOutlines:aZ({layer:"top",circuitJson:t,panelData:n,traceTextureResolution:mc}),bottomPanelOutlines:aZ({layer:"bottom",circuitJson:t,panelData:n,traceTextureResolution:mc}),topCopper:oZ({layer:"top",circuitJson:t,boardData:n,traceTextureResolution:mc}),bottomCopper:oZ({layer:"bottom",circuitJson:t,boardData:n,traceTextureResolution:mc})}},[t,n]);return V.useEffect(()=>{if(!i||!n||!s)return;const r=[],a=(c,I,l,B,C=!1,Q=!1)=>{if(!c)return null;const h=gG(n),E=new iw(h.width,h.height),u=new Td({map:c,transparent:!0,side:zB,depthWrite:Q,polygonOffset:C,polygonOffsetUnits:C?-.8:0,opacity:e?$W:1}),d=new an(E,u);return d.position.set(h.centerX,h.centerY,I),l&&d.rotation.set(Math.PI,0,0),d.name=B,d},g=.001;if(o.topMask){const c=a(s.topSoldermask,A/2+g,!1,"jscad-top-soldermask",!0);c&&(r.push(c),i.add(c))}if(o.bottomMask){const c=a(s.bottomSoldermask,-A/2-g,!0,"jscad-bottom-soldermask",!0);c&&(r.push(c),i.add(c))}if(o.topCopper&&o.topMask){const c=a(s.topTraceWithMask,A/2+Xa.traces+.004,!1,"jscad-top-trace-with-mask");c&&(r.push(c),i.add(c))}if(o.bottomCopper&&o.bottomMask){const c=a(s.bottomTraceWithMask,-A/2-Xa.traces-.005,!0,"jscad-bottom-trace-with-mask");c&&(r.push(c),i.add(c))}if(o.topSilkscreen){const c=a(s.topSilkscreen,A/2+g+.002,!1,"jscad-top-silkscreen");c&&(r.push(c),i.add(c))}if(o.bottomSilkscreen){const c=a(s.bottomSilkscreen,-A/2-g-.002,!0,"jscad-bottom-silkscreen");c&&(r.push(c),i.add(c))}if(o.topCopper){const c=a(s.topCopperText,A/2+Xa.copper,!1,"jscad-top-copper-text",!0);c&&(r.push(c),i.add(c))}if(o.bottomCopper){const c=a(s.bottomCopperText,-A/2-Xa.copper,!0,"jscad-bottom-copper-text",!0);c&&(r.push(c),i.add(c))}if(o.topCopper){const c=a(s.topCopper,A/2+Xa.copper,!1,"jscad-top-copper-pour",!0);c&&(r.push(c),i.add(c))}if(o.bottomCopper){const c=a(s.bottomCopper,-A/2-Xa.copper,!0,"jscad-bottom-copper-pour",!0);c&&(r.push(c),i.add(c))}if(o.boardBody){const c=a(s.topPanelOutlines,A/2+g+.003,!1,"jscad-top-panel-outlines",!1,!0);c&&(r.push(c),i.add(c));const I=a(s.bottomPanelOutlines,-A/2-g-.003,!0,"jscad-bottom-panel-outlines",!1,!0);I&&(r.push(I),i.add(I))}return()=>{r.forEach(c=>{c.parent===i&&i.remove(c),c.geometry.dispose(),c.material instanceof Qf&&c.material.dispose()})}},[i,n,s,A,o]),null}function eGt(t){const A=_i(t).cad_component.list(),e=_i(t).pcb_smtpad.list(),i=_i(t).pcb_hole.list(),o=_i(t).pcb_plated_hole.list(),n=_i(t).pcb_via.list();if(A.length===0&&e.length===0&&i.length===0&&o.length===0&&n.length===0)return null;const s=[...i,...o,...n,...e],r=EL(s);let a=r.minX,g=r.maxX,c=r.minY,I=r.maxY;for(const u of A)if(u.position){const d=u.position.x,f=u.position.y;a=Math.min(a,d),g=Math.max(g,d),c=Math.min(c,f),I=Math.max(I,f)}a===1/0&&(a=-10,g=10,c=-10,I=10);const l=2,B=Math.max(Math.abs(a),Math.abs(g))+l,C=Math.max(Math.abs(c),Math.abs(I))+l,Q=Math.max(2*B,10),h=Math.max(2*C,10);return{type:"pcb_board",pcb_board_id:"faux-board",center:{x:0,y:0},width:Q,height:h,thickness:1.4,material:"fr4",num_layers:2}}function a$A(t){if(_i(t).pcb_board.list().length>0)return t;const e=eGt(t);if(!e)return t;const o=e.thickness/2;return[...t.map(s=>{if(s.type==="cad_component"){const r=s;if(r.position){const a=r.position.z??0;return{...r,position:{...r.position,z:a+o}}}}return s}),e]}var tGt=V.forwardRef(({circuitJson:t,children:A,autoRotateDisabled:e,clickToInteractEnabled:i,onUserInteraction:o,onCameraControllerReady:n},s)=>{const r=T7A(A),a=V.useMemo(()=>a$A(t??r),[t,r]),g=kFt(a),c=V.useMemo(()=>{if(!a)return[5,-5,5];try{const E=_i(a).pcb_board.list()[0];if(!E)return[5,-5,5];const{width:u,height:d}=E;if(!u&&!d)return[5,-5,5];const f=5,m=Math.max(u,f),D=Math.max(d,f),w=Math.max(m,D);return[w*.4,-w*.7,w*.9]}catch(E){return console.error(E),[5,-5,5]}},[a]),I=V.useMemo(()=>{if(!a)return!1;try{const E=_i(a).pcb_board.list()[0];return!!E&&E.pcb_board_id==="faux-board"}catch{return!1}},[a]),l=V.useMemo(()=>{if(a)try{const E=_i(a).pcb_board.list()[0];return E?{width:E.width??0,height:E.height??0}:void 0}catch(E){console.error(E);return}},[a]),B=V.useMemo(()=>{if(a)try{const E=_i(a).pcb_board.list()[0];return!E||!E.center?void 0:{x:E.center.x,y:E.center.y}}catch(E){console.error(E);return}},[a]),C=g6A(a),{stls:Q}=IFt(g),h=_i(a).cad_component.list();return W.jsxs(J7A,{ref:s,autoRotateDisabled:e,initialCameraPosition:c,clickToInteractEnabled:i,boardDimensions:l,boardCenter:B,onUserInteraction:o,onCameraControllerReady:n,children:[Q.map(({stlData:E,color:u,layerType:d},f)=>W.jsx(vFt,{stlData:E,color:u,opacity:f===0?I?.8:.95:1,layerType:d},`board-${f}`)),W.jsx(AGt,{circuitJson:a,pcbThickness:C,isFaux:I}),h.map(E=>W.jsx(z7A,{fallback:({error:u})=>W.jsx(j7A,{cad_component:E,error:u}),children:W.jsx(N7A,{cad_component:E,circuitJson:a},E.cad_component_id)},E.cad_component_id))]})}),iGt=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;t[i]&&t[o]&&(A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1])}return A/2<=0};function oGt(t,A,e,i,o){let n,s=null;if(e.outline&&e.outline.length>=3){let r=e.outline.map(g=>[g.x,g.y]);iGt(r)&&(r=r.reverse());const a=A.ofPolygons([r]);o.push(a),s=a,n=t.extrude(a,i,void 0,void 0,void 0,!0),o.push(n)}else e.outline&&e.outline.length>0&&console.warn("Board outline has fewer than 3 points, falling back to rectangular board."),n=t.cube([e.width,e.height,i],!0),o.push(n),n=n.translate([e.center.x,e.center.y,0]),o.push(n);return{boardOp:n,outlineCrossSection:s}}var nGt=64;function Wd({Manifold:t,width:A,height:e,thickness:i,borderRadius:o}){const n=x0(A,e,o);if(n<=0)return t.cube([A,e,i],!0);const s=[],r=A-2*n,a=e-2*n;return r>0&&s.push(t.cube([r,e,i],!0)),a>0&&s.push(t.cube([A,a,i],!0)),[[A/2-n,e/2-n],[-A/2+n,e/2-n],[-A/2+n,-e/2+n],[A/2-n,-e/2+n]].forEach(([c,I])=>{s.push(t.cylinder(i,n,n,nGt,!0).translate([c,I,0]))}),t.union(s)}function sGt({Manifold:t,pad:A,padBaseThickness:e}){if(A.shape==="rect"){const i=HC(A);return Wd({Manifold:t,width:A.width,height:A.height,thickness:e,borderRadius:i})}else if(A.shape==="rotated_rect"){const i=HC(A);let o=Wd({Manifold:t,width:A.width,height:A.height,thickness:e,borderRadius:i});const n=A.ccw_rotation??0;return n&&(o=o.rotate([0,0,n])),o}else if(A.shape==="circle"&&A.radius)return t.cylinder(e,A.radius,-1,32,!0);return null}var rGt=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;t[i]&&t[o]&&(A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1])}return A/2<=0};function aGt(t,A,e,i,o){const n=[],s=_i(e).pcb_cutout.list();for(const r of s){let a;const g=i*1.5;switch(r.shape){case"rect":{const l=HC(r);if(typeof l=="number"&&l>0?a=Wd({Manifold:t,width:r.width,height:r.height,thickness:g,borderRadius:l}):a=t.cube([r.width,r.height,g],!0),o.push(a),r.rotation){const B=a.rotate([0,0,r.rotation]);o.push(B),a=B}a=a.translate([r.center.x,r.center.y,0]),o.push(a);break}case"circle":a=t.cylinder(g,r.radius,-1,$B,!0),o.push(a),a=a.translate([r.center.x,r.center.y,0]),o.push(a);break;case"polygon":if(r.points.length<3){console.warn(`PCB Cutout [${r.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);continue}let c=r.points.map(l=>[l.x,l.y]);rGt(c)&&(c=c.reverse());const I=A.ofPolygons([c]);o.push(I),a=t.extrude(I,g,0,0,[1,1],!0),o.push(a);break;default:console.warn(`Unsupported cutout shape: ${r.shape} for cutout ${r.pcb_cutout_id}`);continue}a&&n.push(a)}return{cutoutOps:n}}function g$A({Manifold:t,x:A,y:e,diameter:i,thickness:o,segments:n=32}){return t.cylinder(o*1.2,i/2,i/2,n,!0).translate([A,e,0])}function c$A({Manifold:t,x:A,y:e,holeDiameter:i,thickness:o,zOffset:n=.001,segments:s=32}){const r=i/2+n;return t.cylinder(o*1.2,r,r,s,!0).translate([A,e,0])}function gGt(t,A,e,i,o){const n=[],s=_i(e).pcb_hole.list(),r=(g,c,I)=>{const l=Wd({Manifold:t,width:g,height:c,thickness:I,borderRadius:Math.min(g,c)/2});return o.push(l),l},a=(g,c,I)=>{const l=[];for(let B=0;B<I;B++){const C=2*Math.PI*B/I;l.push([g/2*Math.cos(C),c/2*Math.sin(C)])}return l};return s.forEach(g=>{const c=g.hole_shape,I=g.x,l=g.y,B=i*1.2,C=g.ccw_rotation??g.rotation??0,Q=g.hole_width??g.hole_diameter,h=g.hole_height??g.hole_diameter;let E=null;if(c==="circle"){E=g$A({Manifold:t,x:I,y:l,diameter:g.hole_diameter,thickness:i,segments:$B}),n.push(E),o.push(E);return}if(c==="pill"||c==="rotated_pill")E=r(Q,h,B);else if(c==="oval"){let u=a(Q,h,$B),d=0;for(let m=0;m<u.length;m++){const D=(m+1)%u.length;d+=u[m][0]*u[D][1],d-=u[D][0]*u[m][1]}d<=0&&(u=u.reverse());const f=A.ofPolygons([u]);o.push(f),E=t.extrude(f,B,0,0,[1,1],!0),o.push(E)}if(E){if(C!==0){const d=E.rotate([0,0,C]);o.push(d),E=d}const u=E.translate([I,l,0]);o.push(u),n.push(u)}}),{nonPlatedHoleBoardDrills:n}}function aw(t){const A=new kg;if(A.setAttribute("position",new On(t.vertProperties,3)),A.setIndex(new BrA(t.triVerts,1)),t.runIndex&&t.runIndex.length>1&&t.runOriginalID)for(let e=0;e<t.runIndex.length-1;e++){const i=t.runIndex[e],o=t.runIndex[e+1]-i;A.addGroup(i,o,0)}else A.addGroup(0,t.triVerts.length,0);return A}var WH=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;t[i]&&t[o]&&(A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1])}return A/2<=0},IZ=(t,A,e)=>{const i=[];for(let o=0;o<e;o++){const n=2*Math.PI*o/e;i.push([t/2*Math.cos(n),A/2*Math.sin(n)])}return i},cG=new Oi(...en.copper),lZ=.05;function cGt(t,A,e,i,o,n){const s=[],r=_i(e).pcb_plated_hole.list(),a=[],g=[],c=(C,Q,h)=>{const E=Wd({Manifold:t,width:C,height:Q,thickness:h,borderRadius:Math.min(C,Q)/2});return o.push(E),E},I=({padOutline:C,thickness:Q})=>{if(!Array.isArray(C)||C.length<3)return null;let h=C.map(d=>[d.x,d.y]);WH(h)&&(h=h.reverse());const E=A.ofPolygons([h]);o.push(E);const u=t.extrude(E,Q,0,0,[1,1],!0);return o.push(u),u},l=({ph:C,depth:Q,sizeDelta:h=0})=>{if(C.shape!=="hole_with_polygon_pad")return null;const u=C.pad_outline;if(!Array.isArray(u)||u.length<3)return null;const d=C.hole_shape||"circle",f=C.hole_offset_x||0,m=C.hole_offset_y||0;let D=null;if(d==="circle"){const w=Math.max((C.hole_diameter??0)+h,Po),b=Math.max(w/2,Po/2);D=t.cylinder(Q,b,b,$B,!0),o.push(D)}else{const w=C.hole_width??C.hole_diameter,b=C.hole_height??C.hole_diameter;if(!w||!b)return null;const k=Math.max(w+h,Po),_=Math.max(b+h,Po);if(d==="oval"){let M=IZ(k,_,$B);WH(M)&&(M=M.reverse());const v=A.ofPolygons([M]);o.push(v),D=t.extrude(v,Q,0,0,[1,1],!0),o.push(D)}else(d==="pill"||d==="rotated_pill")&&(D=Wd({Manifold:t,width:k,height:_,thickness:Q,borderRadius:Math.min(k,_)/2}),o.push(D))}if(!D)return null;if(f||m){const w=D.translate([f,m,0]);o.push(w),D=w}return D};r.forEach((C,Q)=>{if(C.shape==="circle"){const h=c$A({Manifold:t,x:C.x,y:C.y,holeDiameter:C.hole_diameter*1.02,thickness:i,zOffset:df,segments:$B});o.push(h),s.push(h);const E=i+2*df,u=t.cylinder(E,C.outer_diameter/2,C.outer_diameter/2,$B,!0);o.push(u);const d=t.cylinder(E*1.05,C.hole_diameter/2,C.hole_diameter/2,$B,!0);o.push(d);const f=u.subtract(d);o.push(f);const m=f.translate([C.x,C.y,0]);o.push(m);let D=m;if(n){const b=t.intersection([m,n]);o.push(b),D=b}g.push(D);const w=aw(D.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:w,color:cG})}else if(C.shape==="pill"){const h=C.hole_width,E=C.hole_height,u=.4,d=C.outer_width??h+u,f=C.outer_height??E+u,m=h+2*df,D=E+2*df,w=i*1.2;let b=c(m,D,w);if(C.ccw_rotation){const Z=b.rotate([0,0,C.ccw_rotation]);o.push(Z),b=Z}const k=b.translate([C.x,C.y,0]);o.push(k),s.push(k);const _=i+2*df,M=c(d,f,_),v=c(h,E,_*1.05);let U=M.subtract(v);if(o.push(U),C.ccw_rotation){const Z=U.rotate([0,0,C.ccw_rotation]);o.push(Z),U=Z}const J=U.translate([C.x,C.y,0]);o.push(J);let Y=J;if(n){const Z=t.intersection([J,n]);o.push(Z),Y=Z}g.push(Y);const O=aw(Y.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:O,color:cG})}else if(C.shape==="pill_hole_with_rect_pad"){if(C.hole_shape&&C.hole_shape!=="pill"||C.pad_shape&&C.pad_shape!=="rect")return;const h=C.hole_width,E=C.hole_height,u=C.hole_offset_x||0,d=C.hole_offset_y||0,f=C.rect_pad_width,m=C.rect_pad_height,D=HC(C),w=KH,b=h+2*df,k=E+2*df,_=i*1.2,v=c(b,k,_).translate([u,d,0]).translate([C.x,C.y,0]);o.push(v),s.push(v);const U=Wd({Manifold:t,width:f,height:m,thickness:i-2*w-2*Xa.copper+.1,borderRadius:D});o.push(U);const J=Wd({Manifold:t,width:f,height:m,thickness:w,borderRadius:D}).translate([0,0,i/2/2+Xa.copper]),Y=Wd({Manifold:t,width:f,height:m,thickness:w,borderRadius:D}).translate([0,0,-i/2/2-Xa.copper]);o.push(J,Y);const O=c(h,E,i*1.02).translate([u,d,0]);o.push(O);const Z=t.union([U,J,Y,O]);o.push(Z);const $=c(Math.max(h-2*lZ,.01),Math.max(E-2*lZ,.01),i*1.2).translate([u,d,0]);o.push($);const iA=Z.subtract($);o.push(iA);const aA=iA.translate([C.x,C.y,0]);o.push(aA);let eA=aA;if(n){const rA=t.intersection([aA,n]);o.push(rA),eA=rA}g.push(eA);const oA=aw(eA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:oA,color:cG})}else if(C.shape==="rotated_pill_hole_with_rect_pad"){if(C.hole_shape&&C.hole_shape!=="rotated_pill"||C.pad_shape&&C.pad_shape!=="rect")return;const h=C.hole_width,E=C.hole_height,u=C.hole_offset_x||0,d=C.hole_offset_y||0,f=C.rect_pad_width,m=C.rect_pad_height,D=HC(C),w=KH,b=h+2*df,k=E+2*df,_=i*1.2;let M=c(b,k,_).translate([u,d,0]);if(C.hole_ccw_rotation){const rA=M.rotate([0,0,C.hole_ccw_rotation]);o.push(rA),M=rA}const v=M.translate([C.x,C.y,0]);o.push(v),s.push(v);let U=Wd({Manifold:t,width:f,height:m,thickness:i-2*w-2*Xa.copper+.1,borderRadius:D});if(o.push(U),C.rect_ccw_rotation){const rA=U.rotate([0,0,C.rect_ccw_rotation]);o.push(rA),U=rA}let J=Wd({Manifold:t,width:f,height:m,thickness:w,borderRadius:D}).translate([0,0,i/2/2+Xa.copper]);if(C.rect_ccw_rotation){const rA=J.rotate([0,0,C.rect_ccw_rotation]);o.push(rA),J=rA}let Y=Wd({Manifold:t,width:f,height:m,thickness:w,borderRadius:D}).translate([0,0,-i/2/2-Xa.copper]);if(C.rect_ccw_rotation){const rA=Y.rotate([0,0,C.rect_ccw_rotation]);o.push(rA),Y=rA}o.push(J,Y);let O=c(h,E,i*1.02).translate([u,d,0]);if(C.hole_ccw_rotation){const rA=O.rotate([0,0,C.hole_ccw_rotation]);o.push(rA),O=rA}o.push(O);const Z=t.union([U,J,Y,O]);o.push(Z);let $=c(Math.max(h-2*lZ,.01),Math.max(E-2*lZ,.01),i*1.2).translate([u,d,0]);if(C.hole_ccw_rotation){const rA=$.rotate([0,0,C.hole_ccw_rotation]);o.push(rA),$=rA}o.push($);const iA=Z.subtract($);o.push(iA);const aA=iA.translate([C.x,C.y,0]);o.push(aA);let eA=aA;if(n){const rA=t.intersection([aA,n]);o.push(rA),eA=rA}g.push(eA);const oA=aw(eA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:oA,color:cG})}else if(C.shape==="hole_with_polygon_pad"){const h=C.pad_outline;if(!Array.isArray(h)||h.length<3)return;const E=l({ph:C,depth:i*1.2,sizeDelta:2*Po});if(!E)return;const u=E.translate([C.x,C.y,0]);o.push(u),s.push(u);const d=KH,f=Math.max(i-2*d-2*Xa.copper+.1,Po),m=I({padOutline:h,thickness:f}),D=I({padOutline:h,thickness:d}),w=I({padOutline:h,thickness:d});if(!m||!D||!w)return;const b=D.translate([0,0,i/2/2+Xa.copper]),k=w.translate([0,0,-i/2/2-Xa.copper]);o.push(b,k);const _=l({ph:C,depth:i*1.02});if(!_)return;const M=l({ph:C,depth:i*1.2,sizeDelta:-2*Po})||_,v=t.union([m,b,k,_]);o.push(v);const U=v.subtract(M);o.push(U);const J=U.translate([C.x,C.y,0]);o.push(J);let Y=J;if(n){const Z=t.intersection([J,n]);o.push(Z),Y=Z}g.push(Y);const O=aw(Y.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:O,color:cG})}else if(C.shape==="oval"){const h=C.hole_width,E=C.hole_height,u=C.outer_width??h+.4,d=C.outer_height??E+.4,f=h+2*df,m=E+2*df,D=i*1.2;let w=IZ(f,m,$B);WH(w)&&(w=w.reverse());const b=A.ofPolygons([w]);o.push(b);let k=t.extrude(b,D,0,0,[1,1],!0);if(o.push(k),C.ccw_rotation){const oA=k.rotate([0,0,C.ccw_rotation]);o.push(oA),k=oA}const _=k.translate([C.x,C.y,0]);o.push(_),s.push(_);const M=i+2*df;let v=IZ(u,d,$B);WH(v)&&(v=v.reverse());const U=A.ofPolygons([v]);o.push(U);const J=t.extrude(U,M,0,0,[1,1],!0);o.push(J);let Y=IZ(h,E,$B);WH(Y)&&(Y=Y.reverse());const O=A.ofPolygons([Y]);o.push(O);const Z=t.extrude(O,M*1.05,0,0,[1,1],!0);o.push(Z);let $=J.subtract(Z);if(o.push($),C.ccw_rotation){const oA=$.rotate([0,0,C.ccw_rotation]);o.push(oA),$=oA}const iA=$.translate([C.x,C.y,0]);o.push(iA);let aA=iA;if(n){const oA=t.intersection([iA,n]);o.push(oA),aA=oA}g.push(aA);const eA=aw(aA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:eA,color:cG})}else if(C.shape==="circular_hole_with_rect_pad"){if(C.hole_shape&&C.hole_shape!=="circle"||C.pad_shape&&C.pad_shape!=="rect")return;const h=C.hole_offset_x||0,E=C.hole_offset_y||0,u=g$A({Manifold:t,x:C.x+h,y:C.y+E,diameter:C.hole_diameter,thickness:i,segments:$B});o.push(u),s.push(u);const d=C.rect_pad_width??C.hole_diameter,f=C.rect_pad_height??C.hole_diameter,m=HC(C),D=KH,w=C.hole_diameter/2,b=Wd({Manifold:t,width:d,height:f,thickness:i-2*D-2*Xa.copper+.1,borderRadius:m});o.push(b);const k=Wd({Manifold:t,width:d,height:f,thickness:D,borderRadius:m}).translate([0,0,i/2/2+Xa.copper]),_=Wd({Manifold:t,width:d,height:f,thickness:D,borderRadius:m}).translate([0,0,-i/2/2-Xa.copper]);o.push(k,_);const M=t.cylinder(i*1.02,w,w,$B,!0).translate([h,E,0]);o.push(M);const v=t.union([b,k,_,M]);o.push(v);const U=t.cylinder(i*1.2,Math.max(w-Po,.01),Math.max(w-Po,.01),$B,!0).translate([h,E,0]);o.push(U);const J=v.subtract(U);o.push(J);const Y=J.translate([C.x,C.y,0]);o.push(Y);let O=Y;if(n){const $=t.intersection([Y,n]);o.push($),O=$}g.push(O);const Z=aw(O.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:Z,color:cG})}});let B;return g.length>0&&(B=t.union(g),o.push(B)),{platedHoleBoardDrills:s,platedHoleCopperGeoms:a,platedHoleSubtractOp:B}}var IGt=new Oi(...en.copper);function lGt(t,A,e,i,o,n){const s=[];return _i(A).pcb_smtpad.list().forEach((a,g)=>{const c=KH,I=a.layer==="bottom"?-e/2-Xa.copper:e/2+Xa.copper;let l=sGt({Manifold:t,pad:a,padBaseThickness:c});if(l){i.push(l);const B=l.translate([a.x,a.y,I]);i.push(B);let C=B;if(o&&(C=B.subtract(o),i.push(C)),n){const h=t.intersection([C,n]);i.push(h),C=h}const Q=aw(C.getMesh());s.push({key:`smt_pad-${a.layer||"top"}-${a.pcb_smtpad_id||g}`,geometry:Q,color:IGt})}}),{smtPadGeoms:s}}function BGt({Manifold:t,x:A,y:e,outerDiameter:i,holeDiameter:o,thickness:n,zOffset:s=.001,segments:r=32}){const a=s,g=s;if(i<o)throw new Error(`Invalid via geometry: outerDiameter (${i}) must be >= holeDiameter (${o})`);const c=Math.min(i/2,o/2+g),I=t.cylinder(n,c,-1,r,!0),l=t.cylinder(a,i/2,-1,r,!0).translate([0,0,n/2]),B=t.cylinder(a,i/2,-1,r,!0).translate([0,0,-n/2]),C=t.union([I,l,B]),Q=n+a*2,h=t.cylinder(Q,o/2,-1,r,!0);return C.subtract(h).translate([A,e,0])}var CGt=new Oi(...en.copper);function QGt(t,A,e,i,o){const n=[],s=_i(A).pcb_via.list(),r=[];return s.forEach((a,g)=>{if(typeof a.hole_diameter=="number"){const c=c$A({Manifold:t,x:a.x,y:a.y,holeDiameter:a.hole_diameter,thickness:e,zOffset:df,segments:$B});i.push(c),n.push(c)}if(typeof a.outer_diameter=="number"&&typeof a.hole_diameter=="number"){const c=BGt({Manifold:t,x:a.x,y:a.y,outerDiameter:a.outer_diameter,holeDiameter:a.hole_diameter,thickness:e,zOffset:df,segments:$B});i.push(c);let I=c;if(o){const B=t.intersection([c,o]);i.push(B),I=B}const l=aw(I.getMesh());r.push({key:`via-${a.pcb_via_id||g}`,geometry:l,color:CGt})}}),{viaBoardDrills:n,viaCopperGeoms:r}}var hGt=(t,A)=>{const[e,i]=V.useState(null),[o,n]=V.useState(null),[s,r]=V.useState(null),[a,g]=V.useState(null),[c,I]=V.useState(!0),l=V.useRef([]),B=V.useMemo(()=>{const Q=A.filter(u=>u.type==="pcb_panel"),h=_i(A).pcb_board.list();if(Q.length>0){const u=Q[0],d=h.find(f=>f.pcb_panel_id===u.pcb_panel_id);return{type:"pcb_board",pcb_board_id:u.pcb_panel_id,center:u.center,width:u.width,height:u.height,thickness:d?.thickness??1.4,material:d?.material??"fr4",num_layers:d?.num_layers??2}}const E=h.filter(u=>!u.pcb_panel_id);return E.length>0?E[0]:null},[A]),C=V.useMemo(()=>{const Q=_i(A).pcb_board.list();return Q.length>0&&Q[0].pcb_board_id==="faux-board"},[A]);return V.useEffect(()=>{if(!t||!B){i(null),n(null),r(null),I(!1);return}if((B.width===0||!B.width)&&(B.height===0||!B.height)&&(!B.outline||B.outline.length<3)){i({platedHoles:[],smtPads:[],vias:[]}),n({}),r(B.thickness??0),I(!1);return}I(!0),g(null);const Q=t.Manifold,h=t.CrossSection,E=m=>{if(!(!m||typeof m.delete!="function"))try{m.delete()}catch(D){(!(D instanceof Error)||!D.message?.includes("Manifold instance already deleted"))&&console.warn("Failed to delete Manifold instance",D)}};l.current.forEach(E),l.current=[];let u=null;const d={},f={};try{const m=B.thickness||1.4;r(m);const{boardOp:D,outlineCrossSection:w}=oGt(Q,h,B,m,l.current);let b=D;const _=m+2*1;let M=null;const v=.01;if(w){let OA=w;if(v>0){const ne=w.offset(v);l.current.push(ne),OA=ne}const PA=Q.extrude(OA,_,void 0,void 0,void 0,!0);l.current.push(PA),M=PA}else{const OA=(B.width||0)+2*v,PA=(B.height||0)+2*v,ne=Q.cube([OA,PA,_],!0);l.current.push(ne);const yA=ne.translate([B.center.x,B.center.y,0]);l.current.push(yA),M=yA}const U=[];let J=null;const{nonPlatedHoleBoardDrills:Y}=gGt(Q,h,A,m,l.current);U.push(...Y);const{platedHoleBoardDrills:O,platedHoleCopperGeoms:Z,platedHoleSubtractOp:$}=cGt(Q,h,A,m,l.current,M);U.push(...O),d.platedHoles=Z;const{viaBoardDrills:iA,viaCopperGeoms:aA}=QGt(Q,A,m,l.current,M);if(U.push(...iA),d.vias=aA,U.length>0){J=Q.union(U),l.current.push(J);const OA=$?Q.union([J,$]):J;l.current.push(OA);const PA=b.subtract(OA);if(l.current.push(PA),b=PA,$){const ne=$.subtract(J);l.current.push(ne);const yA=ne.getMesh(),Ae=aw(yA);d.platedHoles=[{key:"plated-holes-union",geometry:Ae,color:new Oi(en.copper[0],en.copper[1],en.copper[2])}]}}const{cutoutOps:eA}=aGt(Q,h,A,m,l.current);if(eA.length>0){const OA=Q.union(eA);l.current.push(OA);const PA=b.subtract(OA);l.current.push(PA),b=PA}if(u=b,u){const OA=u.getMesh(),PA=aw(OA),ne=WEA[B.material]??en.fr4Tan;d.board={geometry:PA,color:new Oi(ne[0],ne[1],ne[2]),material:B.material,isFaux:C}}const{smtPadGeoms:oA}=lGt(Q,A,m,l.current,J,M);d.smtPads=oA,i(d);const rA=en.fr4TracesWithoutMaskTan,lA=`rgb(${Math.round(rA[0]*255)}, ${Math.round(rA[1]*255)}, ${Math.round(rA[2]*255)})`;f.topTrace=mN({layer:"top",circuitJson:A,boardData:B,traceColor:lA,traceTextureResolution:mc}),f.bottomTrace=mN({layer:"bottom",circuitJson:A,boardData:B,traceColor:lA,traceTextureResolution:mc});const EA=en.fr4TracesWithMaskGreen,bA=`rgb(${Math.round(EA[0]*255)}, ${Math.round(EA[1]*255)}, ${Math.round(EA[2]*255)})`;f.topTraceWithMask=mN({layer:"top",circuitJson:A,boardData:B,traceColor:bA,traceTextureResolution:mc}),f.bottomTraceWithMask=mN({layer:"bottom",circuitJson:A,boardData:B,traceColor:bA,traceTextureResolution:mc});const GA="rgb(255,255,255)";f.topSilkscreen=gZ({layer:"top",circuitJson:A,boardData:B,silkscreenColor:GA,traceTextureResolution:mc}),f.bottomSilkscreen=gZ({layer:"bottom",circuitJson:A,boardData:B,silkscreenColor:GA,traceTextureResolution:mc});const NA=K7A[B.material]??en.fr4SolderMaskGreen,QA=`rgb(${Math.round(NA[0]*255)}, ${Math.round(NA[1]*255)}, ${Math.round(NA[2]*255)})`;f.topSoldermask=cZ({layer:"top",circuitJson:A,boardData:B,soldermaskColor:QA,traceTextureResolution:mc}),f.bottomSoldermask=cZ({layer:"bottom",circuitJson:A,boardData:B,soldermaskColor:QA,traceTextureResolution:mc});const xA=en.copper,uA=`rgb(${Math.round(xA[0]*255)}, ${Math.round(xA[1]*255)}, ${Math.round(xA[2]*255)})`;f.topCopperText=rZ({layer:"top",circuitJson:A,boardData:B,copperColor:uA,traceTextureResolution:mc}),f.bottomCopperText=rZ({layer:"bottom",circuitJson:A,boardData:B,copperColor:uA,traceTextureResolution:mc}),f.topPanelOutlines=aZ({layer:"top",circuitJson:A,panelData:B,traceTextureResolution:mc}),f.bottomPanelOutlines=aZ({layer:"bottom",circuitJson:A,panelData:B,traceTextureResolution:mc}),f.topCopper=oZ({layer:"top",circuitJson:A,boardData:B,traceTextureResolution:mc}),f.bottomCopper=oZ({layer:"bottom",circuitJson:A,boardData:B,traceTextureResolution:mc}),n(f)}catch(m){console.error("Error processing geometry with Manifold in hook:",m),g(m.message||"An unknown error occurred while processing geometry in hook."),i(null),n(null)}finally{I(!1)}return()=>{l.current.forEach(E),l.current=[]}},[t,A,B]),{geoms:e,textures:o,pcbThickness:s,error:a,isLoading:c,boardData:B,isFauxBoard:C}},EGt=zB,uGt=({material:t,color:A,side:e=EGt,isFaux:i=!1})=>t==="fr4"?new ow({color:A,side:e,metalness:0,roughness:.8,specularIntensity:.2,ior:1.45,sheen:0,clearcoat:0,transparent:i,opacity:i?$W:1,flatShading:!0}):new RE({color:A,side:e,flatShading:!0,metalness:.1,roughness:.8,transparent:!0,opacity:i?$W:.9});function dGt(t){const A=[];if(!t)return A;if(t.board&&t.board.geometry){const i=new an(t.board.geometry,uGt({material:t.board.material,color:t.board.color,side:zB,isFaux:t.board.isFaux}));i.name="board-geom",A.push(i)}const e=i=>{i&&i.forEach(o=>{const n=new an(o.geometry,new RE({color:o.color,side:zB,flatShading:!0,polygonOffset:!0,polygonOffsetFactor:-1,polygonOffsetUnits:-1}));n.name=o.key,A.push(n)})};return e(t.platedHoles),e(t.smtPads),e(t.vias),A}var pGt=({geometryMeshes:t,textureMeshes:A})=>{const{rootObject:e}=Ou(),{visibility:i}=rN();return V.useEffect(()=>{if(e)return t.forEach(o=>{let n=!0;o.name==="board-geom"?n=i.boardBody:o.name.includes("smt_pad")?o.name.includes("smt_pad-top")?n=i.topCopper:o.name.includes("smt_pad-bottom")?n=i.bottomCopper:n=i.topCopper||i.bottomCopper:(o.name.includes("plated_hole")||o.name.includes("via"))&&(n=i.topCopper||i.bottomCopper),n&&e.add(o)}),A.forEach(o=>{let n=!0;o.name.includes("top-trace-texture-plane")&&!o.name.includes("with-mask")?n=i.topCopper&&!i.topMask:o.name.includes("top-trace-with-mask")?n=i.topCopper&&i.topMask:o.name.includes("bottom-trace-texture-plane")&&!o.name.includes("with-mask")?n=i.bottomCopper&&!i.bottomMask:o.name.includes("bottom-trace-with-mask")?n=i.bottomCopper&&i.bottomMask:o.name.includes("top-silkscreen")?n=i.topSilkscreen:o.name.includes("bottom-silkscreen")?n=i.bottomSilkscreen:o.name.includes("top-soldermask")?n=i.topMask:o.name.includes("bottom-soldermask")?n=i.bottomMask:o.name.includes("top-copper-text")?n=i.topCopper:o.name.includes("bottom-copper-text")?n=i.bottomCopper:o.name.includes("top-copper")?n=i.topCopper:o.name.includes("bottom-copper")?n=i.bottomCopper:o.name.includes("panel-outlines")&&(n=i.boardBody),n&&e.add(o)}),()=>{t.forEach(o=>{o.parent===e&&e.remove(o)}),A.forEach(o=>{o.parent===e&&e.remove(o)})}},[e,t,A,i]),null},fGt="https://cdn.jsdelivr.net/npm/manifold-3d@3.2.1",yGt=({circuitJson:t,autoRotateDisabled:A,clickToInteractEnabled:e,onUserInteraction:i,children:o,onCameraControllerReady:n})=>{const s=T7A(o),r=V.useMemo(()=>a$A(t??s),[t,s]),[a,g]=V.useState(null),[c,I]=V.useState(null);V.useEffect(()=>{if(window.ManifoldModule&&typeof window.ManifoldModule=="object"&&window.ManifoldModule.setup){g(window.ManifoldModule);return}const k=async Y=>{try{const O=await Y();O.setup(),window.ManifoldModule=O,g(O)}catch(O){console.error("Failed to initialize Manifold:",O),I(`Failed to initialize Manifold: ${O instanceof Error?O.message:"Unknown error"}`)}},_=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(_){window.ManifoldModule=_,k(window.ManifoldModule);return}const M="manifoldLoaded",v=()=>{const Y=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(Y)window.ManifoldModule=Y,k(window.ManifoldModule);else{const O="ManifoldModule not found on window after script load.";console.error(O),I(O)}};window.addEventListener(M,v,{once:!0});const U=document.createElement("script");U.type="module",U.innerHTML=`
|
|
5178
5178
|
try {
|
|
5179
5179
|
const { default: ManifoldModule } = await import('${fGt}/manifold.js');
|
|
5180
5180
|
window.ManifoldModule = ManifoldModule;
|
|
@@ -5183,7 +5183,7 @@ try {
|
|
|
5183
5183
|
} finally {
|
|
5184
5184
|
window.dispatchEvent(new CustomEvent('${M}'));
|
|
5185
5185
|
}
|
|
5186
|
-
`.trim();const J=Y=>{const O="Failed to load Manifold loader script.";console.error(O,Y),I(O),window.removeEventListener(M,v)};return U.addEventListener("error",J),document.body.appendChild(U),()=>{window.removeEventListener(M,v),U.removeEventListener("error",J)}},[]);const{geoms:l,textures:B,pcbThickness:C,error:Q,isLoading:h,boardData:E,isFauxBoard:u}=hGt(a,r),d=V.useMemo(()=>dGt(l),[l]),f=V.useMemo(()=>$Ft(B,E,C,u),[B,E,C,u]),m=V.useMemo(()=>_i(r).cad_component.list(),[r]),D=V.useMemo(()=>{if(!E)return;const{width:k=0,height:_=0}=E;return{width:k,height:_}},[E]),w=V.useMemo(()=>{if(!E)return;const{center:k}=E;if(k)return{x:k.x,y:k.y}},[E]),b=V.useMemo(()=>{if(!E)return[5,-5,5];const{width:k=0,height:_=0}=E,M=Math.max(k,1),v=Math.max(_,1),U=Math.max(M,v,5);return[U*.4,-U*.7,U*.9]},[E]);return c?W.jsxs("div",{style:{color:"red",padding:"1em",border:"1px solid red",margin:"1em"},children:["Error: ",c]}):a?Q?W.jsxs("div",{style:{color:"red",padding:"1em",border:"1px solid red",margin:"1em"},children:["Error: ",Q]}):h?W.jsx("div",{style:{padding:"1em"},children:"Processing board geometry..."}):W.jsxs(J7A,{initialCameraPosition:b,autoRotateDisabled:A,clickToInteractEnabled:e,boardDimensions:D,boardCenter:w,onUserInteraction:i,onCameraControllerReady:n,children:[W.jsx(pGt,{geometryMeshes:d,textureMeshes:f}),m.map(k=>W.jsx(z7A,{fallback:({error:_})=>W.jsx(j7A,{cad_component:k,error:_}),children:W.jsx(N7A,{cad_component:k,circuitJson:r})},k.cad_component_id))]}):W.jsx("div",{style:{padding:"1em"},children:"Loading Manifold module..."})},mGt=yGt,wGt=({containerRef:t})=>{const[A,e]=V.useState(!1),[i,o]=V.useState({x:0,y:0}),n=V.useRef(null),s=V.useRef(null),r=V.useRef(null),a=V.useRef(!1),g=()=>{r.current!==null&&(clearTimeout(r.current),r.current=null)},c=V.useCallback(h=>{h.preventDefault();const E=typeof h.clientX=="number"?h.clientX:0,u=typeof h.clientY=="number"?h.clientY:0;if(a.current){a.current=!1;return}if(!s.current)return;const{x:d,y:f}=s.current,m=Math.abs(E-d),D=Math.abs(u-f),w=10;if(m>w||D>w){s.current=null;return}o({x:E,y:u}),e(!0),s.current=null},[o,e]),I=V.useCallback(h=>{if(h.touches.length===1){const E=h.touches[0];E?(s.current={x:E.clientX,y:E.clientY},g(),r.current=window.setTimeout(()=>{if(s.current){if(t.current){const u=t.current.getBoundingClientRect();o({x:u.left+u.width/2,y:u.top+u.height/2}),e(!0),a.current=!0}s.current=null}},600)):s.current=null}else s.current=null,g()},[t]),l=V.useCallback(h=>{if(!s.current||h.touches.length!==1)return;const E=h.touches[0];if(E){const u=Math.abs(E.clientX-s.current.x),d=Math.abs(E.clientY-s.current.y),f=10;(u>f||d>f)&&(s.current=null,g())}else s.current=null,g()},[]),B=V.useCallback(()=>{g(),setTimeout(()=>{s.current&&(s.current=null)},0)},[]),C=V.useCallback(h=>{const E=h.target;n.current&&n.current.contains(E)||E.closest?.("[data-radix-popper-content-wrapper], [data-radix-dropdown-menu-content], [data-radix-dropdown-menu-sub-content]")||e(!1)},[]);return V.useEffect(()=>{if(A)return document.addEventListener("mousedown",C),document.addEventListener("touchstart",C),()=>{document.removeEventListener("mousedown",C),document.removeEventListener("touchstart",C)}},[A,C]),{menuVisible:A,menuPos:i,menuRef:n,contextMenuEventHandlers:{onMouseDown:h=>{h.button===2?s.current={x:h.clientX,y:h.clientY}:s.current=null},onContextMenu:c,onTouchStart:I,onTouchMove:l,onTouchEnd:B},setMenuVisible:e}};function DGt({setAutoRotate:t,setAutoRotateUserToggled:A,setCameraPreset:e,closeMenu:i,cameraControllerRef:o,isAnimatingRef:n,lastPresetSelectTime:s}){return{handleCameraPresetSelect:V.useCallback(a=>{t(!1),A(!0),e(a),i(),s.current=Date.now(),a!=="Custom"&&(n.current=!0,o.current?.animateToPreset(a),setTimeout(()=>{n.current=!1},600))},[t,A,e,i,o,n,s])}}var SGt=()=>V.useCallback(()=>{const t=window.__TSCIRCUIT_THREE_OBJECT;if(!t)return;new AaA().parse(t,e=>{const i=new Blob([e instanceof ArrayBuffer?e:JSON.stringify(e)],{type:"model/gltf+json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download="scene.gltf",n.click(),URL.revokeObjectURL(o)},e=>{console.error("Failed to export GLTF",e)})},[]),wN=new Map,zEA=new Set,I$A=!1,XEA=0,$EA=0,BZ=null,l$A=!1,bGt=20,_Gt=t=>{const A=t.toLowerCase().split("+"),e=A[A.length-1],i=A.slice(0,-1);return{key:e,ctrl:i.includes("ctrl"),cmd:i.includes("cmd"),shift:i.includes("shift"),alt:i.includes("alt")}},xGt=(t,A)=>{const e=_Gt(A),i=t.key.toLowerCase()===e.key,o=e.ctrl===t.ctrlKey,n=e.cmd===t.metaKey,s=e.shift===t.shiftKey,r=e.alt===t.altKey;return i&&o&&n&&s&&r},kGt=t=>{if(!t||typeof t!="object")return!1;const A=t,e=A.tagName,i=["INPUT","TEXTAREA","SELECT"];if(i.includes(e))return!0;const o=A.getAttribute?.("contenteditable");if(o==="true"||o==="")return!0;let n=A.parentElement;for(let s=0;s<bGt&&n;s++){const r=n.tagName;if(i.includes(r))return!0;const a=n.getAttribute?.("contenteditable");if(a==="true"||a==="")return!0;n=n.parentElement}return!1},FGt=()=>{if(typeof document>"u")return!1;const t=document.activeElement;if(!t)return!1;const A=t.tagName;if(A==="INPUT"||A==="TEXTAREA"||A==="SELECT")return!0;const e=t.getAttribute("contenteditable");return e==="true"||e===""},GGt=()=>{if(!BZ)return!0;const t=BZ.getBoundingClientRect();return XEA>=t.left&&XEA<=t.right&&$EA>=t.top&&$EA<=t.bottom},RGt=()=>{l$A||typeof window>"u"||(window.addEventListener("mousemove",t=>{XEA=t.clientX,$EA=t.clientY}),l$A=!0)},vGt=t=>{kGt(t.target)||FGt()||BZ&&!GGt()||wN.forEach(A=>{xGt(t,A.shortcut)&&(t.preventDefault(),A.invoke())})},B$A=()=>{const t=Array.from(wN.values());zEA.forEach(A=>A(t))},MGt=()=>{I$A||typeof window>"u"||(window.addEventListener("keydown",vGt),I$A=!0)},NGt=t=>{wN.set(t.id,t),B$A(),MGt()},LGt=t=>{wN.delete(t)&&B$A()},UGt=t=>(zEA.add(t),t(Array.from(wN.values())),()=>{zEA.delete(t)}),CZ=(t,A,e)=>{const i=V.useRef(A);i.current=A;const o=V.useMemo(()=>({shortcut:e.shortcut,description:e.description}),[e.shortcut,e.description]);V.useEffect(()=>{const n={id:t,...o,invoke:()=>i.current()};return NGt(n),()=>{LGt(t)}},[t,o])},HGt=()=>{const[t,A]=V.useState(()=>Array.from(wN.values()));return V.useEffect(()=>UGt(A),[]),t},YGt=t=>{BZ=t,RGt()},JGt=()=>({showToast:(t,A=2e3)=>{ys(t,{duration:A})}}),TGt=({children:t})=>W.jsxs(W.Fragment,{children:[t,W.jsx(vzA,{position:"bottom-right"})]});function ca(t,A,{checkForDefaultPrevented:e=!0}={}){return function(o){if(t?.(o),e===!1||!o.defaultPrevented)return A?.(o)}}function C$A(t,A){if(typeof t=="function")return t(A);t!=null&&(t.current=A)}function QZ(...t){return A=>{let e=!1;const i=t.map(o=>{const n=C$A(o,A);return!e&&typeof n=="function"&&(e=!0),n});if(e)return()=>{for(let o=0;o<i.length;o++){const n=i[o];typeof n=="function"?n():C$A(t[o],null)}}}}function ff(...t){return V.useCallback(QZ(...t),t)}function ZH(t,A=[]){let e=[];function i(n,s){const r=V.createContext(s),a=e.length;e=[...e,s];const g=I=>{const{scope:l,children:B,...C}=I,Q=l?.[t]?.[a]||r,h=V.useMemo(()=>C,Object.values(C));return W.jsx(Q.Provider,{value:h,children:B})};g.displayName=n+"Provider";function c(I,l){const B=l?.[t]?.[a]||r,C=V.useContext(B);if(C)return C;if(s!==void 0)return s;throw new Error(`\`${I}\` must be used within \`${n}\``)}return[g,c]}const o=()=>{const n=e.map(s=>V.createContext(s));return function(r){const a=r?.[t]||n;return V.useMemo(()=>({[`__scope${t}`]:{...r,[t]:a}}),[r,a])}};return o.scopeName=t,[i,KGt(o,...A)]}function KGt(...t){const A=t[0];if(t.length===1)return A;const e=()=>{const i=t.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(n){const s=i.reduce((r,{useScope:a,scopeName:g})=>{const I=a(n)[`__scope${g}`];return{...r,...I}},{});return V.useMemo(()=>({[`__scope${A.scopeName}`]:s}),[s])}};return e.scopeName=A.scopeName,e}var xx=globalThis?.document?V.useLayoutEffect:()=>{},PGt=k2[" useInsertionEffect ".trim().toString()]||xx;function AuA({prop:t,defaultProp:A,onChange:e=()=>{},caller:i}){const[o,n,s]=qGt({defaultProp:A,onChange:e}),r=t!==void 0,a=r?t:o;{const c=V.useRef(t!==void 0);V.useEffect(()=>{const I=c.current;I!==r&&console.warn(`${i} is changing from ${I?"controlled":"uncontrolled"} to ${r?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),c.current=r},[r,i])}const g=V.useCallback(c=>{if(r){const I=OGt(c)?c(t):c;I!==t&&s.current?.(I)}else n(c)},[r,t,n,s]);return[a,g]}function qGt({defaultProp:t,onChange:A}){const[e,i]=V.useState(t),o=V.useRef(e),n=V.useRef(A);return PGt(()=>{n.current=A},[A]),V.useEffect(()=>{o.current!==e&&(n.current?.(e),o.current=e)},[e,o]),[e,i,n]}function OGt(t){return typeof t=="function"}function hZ(t){const A=WGt(t),e=V.forwardRef((i,o)=>{const{children:n,...s}=i,r=V.Children.toArray(n),a=r.find(VGt);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:o,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:o,children:n})});return e.displayName=`${t}.Slot`,e}function WGt(t){const A=V.forwardRef((e,i)=>{const{children:o,...n}=e;if(V.isValidElement(o)){const s=zGt(o),r=jGt(n,o.props);return o.type!==V.Fragment&&(r.ref=i?QZ(i,s):s),V.cloneElement(o,r)}return V.Children.count(o)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var ZGt=Symbol("radix.slottable");function VGt(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===ZGt}function jGt(t,A){const e={...A};for(const i in A){const o=t[i],n=A[i];/^on[A-Z]/.test(i)?o&&n?e[i]=(...r)=>{const a=n(...r);return o(...r),a}:o&&(e[i]=o):i==="style"?e[i]={...o,...n}:i==="className"&&(e[i]=[o,n].filter(Boolean).join(" "))}return{...t,...e}}function zGt(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var XGt=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Zd=XGt.reduce((t,A)=>{const e=hZ(`Primitive.${A}`),i=V.forwardRef((o,n)=>{const{asChild:s,...r}=o,a=s?e:A;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),W.jsx(a,{...r,ref:n})});return i.displayName=`Primitive.${A}`,{...t,[A]:i}},{});function Q$A(t,A){t&&jL.flushSync(()=>t.dispatchEvent(A))}function h$A(t){const A=t+"CollectionProvider",[e,i]=ZH(A),[o,n]=e(A,{collectionRef:{current:null},itemMap:new Map}),s=Q=>{const{scope:h,children:E}=Q,u=no.useRef(null),d=no.useRef(new Map).current;return W.jsx(o,{scope:h,itemMap:d,collectionRef:u,children:E})};s.displayName=A;const r=t+"CollectionSlot",a=hZ(r),g=no.forwardRef((Q,h)=>{const{scope:E,children:u}=Q,d=n(r,E),f=ff(h,d.collectionRef);return W.jsx(a,{ref:f,children:u})});g.displayName=r;const c=t+"CollectionItemSlot",I="data-radix-collection-item",l=hZ(c),B=no.forwardRef((Q,h)=>{const{scope:E,children:u,...d}=Q,f=no.useRef(null),m=ff(h,f),D=n(c,E);return no.useEffect(()=>(D.itemMap.set(f,{ref:f,...d}),()=>{D.itemMap.delete(f)})),W.jsx(l,{[I]:"",ref:m,children:u})});B.displayName=c;function C(Q){const h=n(t+"CollectionConsumer",Q);return no.useCallback(()=>{const u=h.collectionRef.current;if(!u)return[];const d=Array.from(u.querySelectorAll(`[${I}]`));return Array.from(h.itemMap.values()).sort((D,w)=>d.indexOf(D.ref.current)-d.indexOf(w.ref.current))},[h.collectionRef,h.itemMap])}return[{Provider:s,Slot:g,ItemSlot:B},C,i]}var $Gt=V.createContext(void 0);function E$A(t){const A=V.useContext($Gt);return t||A||"ltr"}function fD(t){const A=V.useRef(t);return V.useEffect(()=>{A.current=t}),V.useMemo(()=>(...e)=>A.current?.(...e),[])}function ARt(t,A=globalThis?.document){const e=fD(t);V.useEffect(()=>{const i=o=>{o.key==="Escape"&&e(o)};return A.addEventListener("keydown",i,{capture:!0}),()=>A.removeEventListener("keydown",i,{capture:!0})},[e,A])}var eRt="DismissableLayer",euA="dismissableLayer.update",tRt="dismissableLayer.pointerDownOutside",iRt="dismissableLayer.focusOutside",u$A,d$A=V.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),p$A=V.forwardRef((t,A)=>{const{disableOutsidePointerEvents:e=!1,onEscapeKeyDown:i,onPointerDownOutside:o,onFocusOutside:n,onInteractOutside:s,onDismiss:r,...a}=t,g=V.useContext(d$A),[c,I]=V.useState(null),l=c?.ownerDocument??globalThis?.document,[,B]=V.useState({}),C=ff(A,w=>I(w)),Q=Array.from(g.layers),[h]=[...g.layersWithOutsidePointerEventsDisabled].slice(-1),E=Q.indexOf(h),u=c?Q.indexOf(c):-1,d=g.layersWithOutsidePointerEventsDisabled.size>0,f=u>=E,m=sRt(w=>{const b=w.target,k=[...g.branches].some(_=>_.contains(b));!f||k||(o?.(w),s?.(w),w.defaultPrevented||r?.())},l),D=rRt(w=>{const b=w.target;[...g.branches].some(_=>_.contains(b))||(n?.(w),s?.(w),w.defaultPrevented||r?.())},l);return ARt(w=>{u===g.layers.size-1&&(i?.(w),!w.defaultPrevented&&r&&(w.preventDefault(),r()))},l),V.useEffect(()=>{if(c)return e&&(g.layersWithOutsidePointerEventsDisabled.size===0&&(u$A=l.body.style.pointerEvents,l.body.style.pointerEvents="none"),g.layersWithOutsidePointerEventsDisabled.add(c)),g.layers.add(c),f$A(),()=>{e&&g.layersWithOutsidePointerEventsDisabled.size===1&&(l.body.style.pointerEvents=u$A)}},[c,l,e,g]),V.useEffect(()=>()=>{c&&(g.layers.delete(c),g.layersWithOutsidePointerEventsDisabled.delete(c),f$A())},[c,g]),V.useEffect(()=>{const w=()=>B({});return document.addEventListener(euA,w),()=>document.removeEventListener(euA,w)},[]),W.jsx(Zd.div,{...a,ref:C,style:{pointerEvents:d?f?"auto":"none":void 0,...t.style},onFocusCapture:ca(t.onFocusCapture,D.onFocusCapture),onBlurCapture:ca(t.onBlurCapture,D.onBlurCapture),onPointerDownCapture:ca(t.onPointerDownCapture,m.onPointerDownCapture)})});p$A.displayName=eRt;var oRt="DismissableLayerBranch",nRt=V.forwardRef((t,A)=>{const e=V.useContext(d$A),i=V.useRef(null),o=ff(A,i);return V.useEffect(()=>{const n=i.current;if(n)return e.branches.add(n),()=>{e.branches.delete(n)}},[e.branches]),W.jsx(Zd.div,{...t,ref:o})});nRt.displayName=oRt;function sRt(t,A=globalThis?.document){const e=fD(t),i=V.useRef(!1),o=V.useRef(()=>{});return V.useEffect(()=>{const n=r=>{if(r.target&&!i.current){let a=function(){y$A(tRt,e,g,{discrete:!0})};const g={originalEvent:r};r.pointerType==="touch"?(A.removeEventListener("click",o.current),o.current=a,A.addEventListener("click",o.current,{once:!0})):a()}else A.removeEventListener("click",o.current);i.current=!1},s=window.setTimeout(()=>{A.addEventListener("pointerdown",n)},0);return()=>{window.clearTimeout(s),A.removeEventListener("pointerdown",n),A.removeEventListener("click",o.current)}},[A,e]),{onPointerDownCapture:()=>i.current=!0}}function rRt(t,A=globalThis?.document){const e=fD(t),i=V.useRef(!1);return V.useEffect(()=>{const o=n=>{n.target&&!i.current&&y$A(iRt,e,{originalEvent:n},{discrete:!1})};return A.addEventListener("focusin",o),()=>A.removeEventListener("focusin",o)},[A,e]),{onFocusCapture:()=>i.current=!0,onBlurCapture:()=>i.current=!1}}function f$A(){const t=new CustomEvent(euA);document.dispatchEvent(t)}function y$A(t,A,e,{discrete:i}){const o=e.originalEvent.target,n=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:e});A&&o.addEventListener(t,A,{once:!0}),i?Q$A(o,n):o.dispatchEvent(n)}var tuA=0;function aRt(){V.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??m$A()),document.body.insertAdjacentElement("beforeend",t[1]??m$A()),tuA++,()=>{tuA===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(A=>A.remove()),tuA--}},[])}function m$A(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.outline="none",t.style.opacity="0",t.style.position="fixed",t.style.pointerEvents="none",t}var iuA="focusScope.autoFocusOnMount",ouA="focusScope.autoFocusOnUnmount",w$A={bubbles:!1,cancelable:!0},gRt="FocusScope",D$A=V.forwardRef((t,A)=>{const{loop:e=!1,trapped:i=!1,onMountAutoFocus:o,onUnmountAutoFocus:n,...s}=t,[r,a]=V.useState(null),g=fD(o),c=fD(n),I=V.useRef(null),l=ff(A,Q=>a(Q)),B=V.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;V.useEffect(()=>{if(i){let Q=function(d){if(B.paused||!r)return;const f=d.target;r.contains(f)?I.current=f:kx(I.current,{select:!0})},h=function(d){if(B.paused||!r)return;const f=d.relatedTarget;f!==null&&(r.contains(f)||kx(I.current,{select:!0}))},E=function(d){if(document.activeElement===document.body)for(const m of d)m.removedNodes.length>0&&kx(r)};document.addEventListener("focusin",Q),document.addEventListener("focusout",h);const u=new MutationObserver(E);return r&&u.observe(r,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",Q),document.removeEventListener("focusout",h),u.disconnect()}}},[i,r,B.paused]),V.useEffect(()=>{if(r){_$A.add(B);const Q=document.activeElement;if(!r.contains(Q)){const E=new CustomEvent(iuA,w$A);r.addEventListener(iuA,g),r.dispatchEvent(E),E.defaultPrevented||(cRt(QRt(S$A(r)),{select:!0}),document.activeElement===Q&&kx(r))}return()=>{r.removeEventListener(iuA,g),setTimeout(()=>{const E=new CustomEvent(ouA,w$A);r.addEventListener(ouA,c),r.dispatchEvent(E),E.defaultPrevented||kx(Q??document.body,{select:!0}),r.removeEventListener(ouA,c),_$A.remove(B)},0)}}},[r,g,c,B]);const C=V.useCallback(Q=>{if(!e&&!i||B.paused)return;const h=Q.key==="Tab"&&!Q.altKey&&!Q.ctrlKey&&!Q.metaKey,E=document.activeElement;if(h&&E){const u=Q.currentTarget,[d,f]=IRt(u);d&&f?!Q.shiftKey&&E===f?(Q.preventDefault(),e&&kx(d,{select:!0})):Q.shiftKey&&E===d&&(Q.preventDefault(),e&&kx(f,{select:!0})):E===u&&Q.preventDefault()}},[e,i,B.paused]);return W.jsx(Zd.div,{tabIndex:-1,...s,ref:l,onKeyDown:C})});D$A.displayName=gRt;function cRt(t,{select:A=!1}={}){const e=document.activeElement;for(const i of t)if(kx(i,{select:A}),document.activeElement!==e)return}function IRt(t){const A=S$A(t),e=b$A(A,t),i=b$A(A.reverse(),t);return[e,i]}function S$A(t){const A=[],e=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:i=>{const o=i.tagName==="INPUT"&&i.type==="hidden";return i.disabled||i.hidden||o?NodeFilter.FILTER_SKIP:i.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;e.nextNode();)A.push(e.currentNode);return A}function b$A(t,A){for(const e of t)if(!lRt(e,{upTo:A}))return e}function lRt(t,{upTo:A}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(A!==void 0&&t===A)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function BRt(t){return t instanceof HTMLInputElement&&"select"in t}function kx(t,{select:A=!1}={}){if(t&&t.focus){const e=document.activeElement;t.focus({preventScroll:!0}),t!==e&&BRt(t)&&A&&t.select()}}var _$A=CRt();function CRt(){let t=[];return{add(A){const e=t[0];A!==e&&e?.pause(),t=x$A(t,A),t.unshift(A)},remove(A){t=x$A(t,A),t[0]?.resume()}}}function x$A(t,A){const e=[...t],i=e.indexOf(A);return i!==-1&&e.splice(i,1),e}function QRt(t){return t.filter(A=>A.tagName!=="A")}var hRt=k2[" useId ".trim().toString()]||(()=>{}),ERt=0;function VH(t){const[A,e]=V.useState(hRt());return xx(()=>{e(i=>i??String(ERt++))},[t]),A?`radix-${A}`:""}var uRt=["top","right","bottom","left"],Fx=Math.min,F0=Math.max,EZ=Math.round,uZ=Math.floor,yD=t=>({x:t,y:t}),dRt={left:"right",right:"left",bottom:"top",top:"bottom"},pRt={start:"end",end:"start"};function nuA(t,A,e){return F0(t,Fx(A,e))}function Cb(t,A){return typeof t=="function"?t(A):t}function Qb(t){return t.split("-")[0]}function DN(t){return t.split("-")[1]}function suA(t){return t==="x"?"y":"x"}function ruA(t){return t==="y"?"height":"width"}var fRt=new Set(["top","bottom"]);function mD(t){return fRt.has(Qb(t))?"y":"x"}function auA(t){return suA(mD(t))}function yRt(t,A,e){e===void 0&&(e=!1);const i=DN(t),o=auA(t),n=ruA(o);let s=o==="x"?i===(e?"end":"start")?"right":"left":i==="start"?"bottom":"top";return A.reference[n]>A.floating[n]&&(s=dZ(s)),[s,dZ(s)]}function mRt(t){const A=dZ(t);return[guA(t),A,guA(A)]}function guA(t){return t.replace(/start|end/g,A=>pRt[A])}var k$A=["left","right"],F$A=["right","left"],wRt=["top","bottom"],DRt=["bottom","top"];function SRt(t,A,e){switch(t){case"top":case"bottom":return e?A?F$A:k$A:A?k$A:F$A;case"left":case"right":return A?wRt:DRt;default:return[]}}function bRt(t,A,e,i){const o=DN(t);let n=SRt(Qb(t),e==="start",i);return o&&(n=n.map(s=>s+"-"+o),A&&(n=n.concat(n.map(guA)))),n}function dZ(t){return t.replace(/left|right|bottom|top/g,A=>dRt[A])}function _Rt(t){return{top:0,right:0,bottom:0,left:0,...t}}function G$A(t){return typeof t!="number"?_Rt(t):{top:t,right:t,bottom:t,left:t}}function pZ(t){const{x:A,y:e,width:i,height:o}=t;return{width:i,height:o,top:e,left:A,right:A+i,bottom:e+o,x:A,y:e}}function R$A(t,A,e){let{reference:i,floating:o}=t;const n=mD(A),s=auA(A),r=ruA(s),a=Qb(A),g=n==="y",c=i.x+i.width/2-o.width/2,I=i.y+i.height/2-o.height/2,l=i[r]/2-o[r]/2;let B;switch(a){case"top":B={x:c,y:i.y-o.height};break;case"bottom":B={x:c,y:i.y+i.height};break;case"right":B={x:i.x+i.width,y:I};break;case"left":B={x:i.x-o.width,y:I};break;default:B={x:i.x,y:i.y}}switch(DN(A)){case"start":B[s]-=l*(e&&g?-1:1);break;case"end":B[s]+=l*(e&&g?-1:1);break}return B}async function xRt(t,A){var e;A===void 0&&(A={});const{x:i,y:o,platform:n,rects:s,elements:r,strategy:a}=t,{boundary:g="clippingAncestors",rootBoundary:c="viewport",elementContext:I="floating",altBoundary:l=!1,padding:B=0}=Cb(A,t),C=G$A(B),h=r[l?I==="floating"?"reference":"floating":I],E=pZ(await n.getClippingRect({element:(e=await(n.isElement==null?void 0:n.isElement(h)))==null||e?h:h.contextElement||await(n.getDocumentElement==null?void 0:n.getDocumentElement(r.floating)),boundary:g,rootBoundary:c,strategy:a})),u=I==="floating"?{x:i,y:o,width:s.floating.width,height:s.floating.height}:s.reference,d=await(n.getOffsetParent==null?void 0:n.getOffsetParent(r.floating)),f=await(n.isElement==null?void 0:n.isElement(d))?await(n.getScale==null?void 0:n.getScale(d))||{x:1,y:1}:{x:1,y:1},m=pZ(n.convertOffsetParentRelativeRectToViewportRelativeRect?await n.convertOffsetParentRelativeRectToViewportRelativeRect({elements:r,rect:u,offsetParent:d,strategy:a}):u);return{top:(E.top-m.top+C.top)/f.y,bottom:(m.bottom-E.bottom+C.bottom)/f.y,left:(E.left-m.left+C.left)/f.x,right:(m.right-E.right+C.right)/f.x}}var kRt=async(t,A,e)=>{const{placement:i="bottom",strategy:o="absolute",middleware:n=[],platform:s}=e,r=n.filter(Boolean),a=await(s.isRTL==null?void 0:s.isRTL(A));let g=await s.getElementRects({reference:t,floating:A,strategy:o}),{x:c,y:I}=R$A(g,i,a),l=i,B={},C=0;for(let h=0;h<r.length;h++){var Q;const{name:E,fn:u}=r[h],{x:d,y:f,data:m,reset:D}=await u({x:c,y:I,initialPlacement:i,placement:l,strategy:o,middlewareData:B,rects:g,platform:{...s,detectOverflow:(Q=s.detectOverflow)!=null?Q:xRt},elements:{reference:t,floating:A}});c=d??c,I=f??I,B={...B,[E]:{...B[E],...m}},D&&C<=50&&(C++,typeof D=="object"&&(D.placement&&(l=D.placement),D.rects&&(g=D.rects===!0?await s.getElementRects({reference:t,floating:A,strategy:o}):D.rects),{x:c,y:I}=R$A(g,l,a)),h=-1)}return{x:c,y:I,placement:l,strategy:o,middlewareData:B}},FRt=t=>({name:"arrow",options:t,async fn(A){const{x:e,y:i,placement:o,rects:n,platform:s,elements:r,middlewareData:a}=A,{element:g,padding:c=0}=Cb(t,A)||{};if(g==null)return{};const I=G$A(c),l={x:e,y:i},B=auA(o),C=ruA(B),Q=await s.getDimensions(g),h=B==="y",E=h?"top":"left",u=h?"bottom":"right",d=h?"clientHeight":"clientWidth",f=n.reference[C]+n.reference[B]-l[B]-n.floating[C],m=l[B]-n.reference[B],D=await(s.getOffsetParent==null?void 0:s.getOffsetParent(g));let w=D?D[d]:0;(!w||!await(s.isElement==null?void 0:s.isElement(D)))&&(w=r.floating[d]||n.floating[C]);const b=f/2-m/2,k=w/2-Q[C]/2-1,_=Fx(I[E],k),M=Fx(I[u],k),v=_,U=w-Q[C]-M,J=w/2-Q[C]/2+b,Y=nuA(v,J,U),O=!a.arrow&&DN(o)!=null&&J!==Y&&n.reference[C]/2-(J<v?_:M)-Q[C]/2<0,Z=O?J<v?J-v:J-U:0;return{[B]:l[B]+Z,data:{[B]:Y,centerOffset:J-Y-Z,...O&&{alignmentOffset:Z}},reset:O}}}),GRt=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(A){var e,i;const{placement:o,middlewareData:n,rects:s,initialPlacement:r,platform:a,elements:g}=A,{mainAxis:c=!0,crossAxis:I=!0,fallbackPlacements:l,fallbackStrategy:B="bestFit",fallbackAxisSideDirection:C="none",flipAlignment:Q=!0,...h}=Cb(t,A);if((e=n.arrow)!=null&&e.alignmentOffset)return{};const E=Qb(o),u=mD(r),d=Qb(r)===r,f=await(a.isRTL==null?void 0:a.isRTL(g.floating)),m=l||(d||!Q?[dZ(r)]:mRt(r)),D=C!=="none";!l&&D&&m.push(...bRt(r,Q,C,f));const w=[r,...m],b=await a.detectOverflow(A,h),k=[];let _=((i=n.flip)==null?void 0:i.overflows)||[];if(c&&k.push(b[E]),I){const J=yRt(o,s,f);k.push(b[J[0]],b[J[1]])}if(_=[..._,{placement:o,overflows:k}],!k.every(J=>J<=0)){var M,v;const J=(((M=n.flip)==null?void 0:M.index)||0)+1,Y=w[J];if(Y&&(!(I==="alignment"?u!==mD(Y):!1)||_.every($=>mD($.placement)===u?$.overflows[0]>0:!0)))return{data:{index:J,overflows:_},reset:{placement:Y}};let O=(v=_.filter(Z=>Z.overflows[0]<=0).sort((Z,$)=>Z.overflows[1]-$.overflows[1])[0])==null?void 0:v.placement;if(!O)switch(B){case"bestFit":{var U;const Z=(U=_.filter($=>{if(D){const iA=mD($.placement);return iA===u||iA==="y"}return!0}).map($=>[$.placement,$.overflows.filter(iA=>iA>0).reduce((iA,aA)=>iA+aA,0)]).sort(($,iA)=>$[1]-iA[1])[0])==null?void 0:U[0];Z&&(O=Z);break}case"initialPlacement":O=r;break}if(o!==O)return{reset:{placement:O}}}return{}}}};function v$A(t,A){return{top:t.top-A.height,right:t.right-A.width,bottom:t.bottom-A.height,left:t.left-A.width}}function M$A(t){return uRt.some(A=>t[A]>=0)}var RRt=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(A){const{rects:e,platform:i}=A,{strategy:o="referenceHidden",...n}=Cb(t,A);switch(o){case"referenceHidden":{const s=await i.detectOverflow(A,{...n,elementContext:"reference"}),r=v$A(s,e.reference);return{data:{referenceHiddenOffsets:r,referenceHidden:M$A(r)}}}case"escaped":{const s=await i.detectOverflow(A,{...n,altBoundary:!0}),r=v$A(s,e.floating);return{data:{escapedOffsets:r,escaped:M$A(r)}}}default:return{}}}}},N$A=new Set(["left","top"]);async function vRt(t,A){const{placement:e,platform:i,elements:o}=t,n=await(i.isRTL==null?void 0:i.isRTL(o.floating)),s=Qb(e),r=DN(e),a=mD(e)==="y",g=N$A.has(s)?-1:1,c=n&&a?-1:1,I=Cb(A,t);let{mainAxis:l,crossAxis:B,alignmentAxis:C}=typeof I=="number"?{mainAxis:I,crossAxis:0,alignmentAxis:null}:{mainAxis:I.mainAxis||0,crossAxis:I.crossAxis||0,alignmentAxis:I.alignmentAxis};return r&&typeof C=="number"&&(B=r==="end"?C*-1:C),a?{x:B*c,y:l*g}:{x:l*g,y:B*c}}var MRt=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(A){var e,i;const{x:o,y:n,placement:s,middlewareData:r}=A,a=await vRt(A,t);return s===((e=r.offset)==null?void 0:e.placement)&&(i=r.arrow)!=null&&i.alignmentOffset?{}:{x:o+a.x,y:n+a.y,data:{...a,placement:s}}}}},NRt=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(A){const{x:e,y:i,placement:o,platform:n}=A,{mainAxis:s=!0,crossAxis:r=!1,limiter:a={fn:E=>{let{x:u,y:d}=E;return{x:u,y:d}}},...g}=Cb(t,A),c={x:e,y:i},I=await n.detectOverflow(A,g),l=mD(Qb(o)),B=suA(l);let C=c[B],Q=c[l];if(s){const E=B==="y"?"top":"left",u=B==="y"?"bottom":"right",d=C+I[E],f=C-I[u];C=nuA(d,C,f)}if(r){const E=l==="y"?"top":"left",u=l==="y"?"bottom":"right",d=Q+I[E],f=Q-I[u];Q=nuA(d,Q,f)}const h=a.fn({...A,[B]:C,[l]:Q});return{...h,data:{x:h.x-e,y:h.y-i,enabled:{[B]:s,[l]:r}}}}}},LRt=function(t){return t===void 0&&(t={}),{options:t,fn(A){const{x:e,y:i,placement:o,rects:n,middlewareData:s}=A,{offset:r=0,mainAxis:a=!0,crossAxis:g=!0}=Cb(t,A),c={x:e,y:i},I=mD(o),l=suA(I);let B=c[l],C=c[I];const Q=Cb(r,A),h=typeof Q=="number"?{mainAxis:Q,crossAxis:0}:{mainAxis:0,crossAxis:0,...Q};if(a){const d=l==="y"?"height":"width",f=n.reference[l]-n.floating[d]+h.mainAxis,m=n.reference[l]+n.reference[d]-h.mainAxis;B<f?B=f:B>m&&(B=m)}if(g){var E,u;const d=l==="y"?"width":"height",f=N$A.has(Qb(o)),m=n.reference[I]-n.floating[d]+(f&&((E=s.offset)==null?void 0:E[I])||0)+(f?0:h.crossAxis),D=n.reference[I]+n.reference[d]+(f?0:((u=s.offset)==null?void 0:u[I])||0)-(f?h.crossAxis:0);C<m?C=m:C>D&&(C=D)}return{[l]:B,[I]:C}}}},URt=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(A){var e,i;const{placement:o,rects:n,platform:s,elements:r}=A,{apply:a=()=>{},...g}=Cb(t,A),c=await s.detectOverflow(A,g),I=Qb(o),l=DN(o),B=mD(o)==="y",{width:C,height:Q}=n.floating;let h,E;I==="top"||I==="bottom"?(h=I,E=l===(await(s.isRTL==null?void 0:s.isRTL(r.floating))?"start":"end")?"left":"right"):(E=I,h=l==="end"?"top":"bottom");const u=Q-c.top-c.bottom,d=C-c.left-c.right,f=Fx(Q-c[h],u),m=Fx(C-c[E],d),D=!A.middlewareData.shift;let w=f,b=m;if((e=A.middlewareData.shift)!=null&&e.enabled.x&&(b=d),(i=A.middlewareData.shift)!=null&&i.enabled.y&&(w=u),D&&!l){const _=F0(c.left,0),M=F0(c.right,0),v=F0(c.top,0),U=F0(c.bottom,0);B?b=C-2*(_!==0||M!==0?_+M:F0(c.left,c.right)):w=Q-2*(v!==0||U!==0?v+U:F0(c.top,c.bottom))}await a({...A,availableWidth:b,availableHeight:w});const k=await s.getDimensions(r.floating);return C!==k.width||Q!==k.height?{reset:{rects:!0}}:{}}}};function fZ(){return typeof window<"u"}function SN(t){return L$A(t)?(t.nodeName||"").toLowerCase():"#document"}function G0(t){var A;return(t==null||(A=t.ownerDocument)==null?void 0:A.defaultView)||window}function wD(t){var A;return(A=(L$A(t)?t.ownerDocument:t.document)||window.document)==null?void 0:A.documentElement}function L$A(t){return fZ()?t instanceof Node||t instanceof G0(t).Node:!1}function gw(t){return fZ()?t instanceof Element||t instanceof G0(t).Element:!1}function DD(t){return fZ()?t instanceof HTMLElement||t instanceof G0(t).HTMLElement:!1}function U$A(t){return!fZ()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof G0(t).ShadowRoot}var HRt=new Set(["inline","contents"]);function jH(t){const{overflow:A,overflowX:e,overflowY:i,display:o}=cw(t);return/auto|scroll|overlay|hidden|clip/.test(A+i+e)&&!HRt.has(o)}var YRt=new Set(["table","td","th"]);function JRt(t){return YRt.has(SN(t))}var TRt=[":popover-open",":modal"];function yZ(t){return TRt.some(A=>{try{return t.matches(A)}catch{return!1}})}var KRt=["transform","translate","scale","rotate","perspective"],PRt=["transform","translate","scale","rotate","perspective","filter"],qRt=["paint","layout","strict","content"];function cuA(t){const A=IuA(),e=gw(t)?cw(t):t;return KRt.some(i=>e[i]?e[i]!=="none":!1)||(e.containerType?e.containerType!=="normal":!1)||!A&&(e.backdropFilter?e.backdropFilter!=="none":!1)||!A&&(e.filter?e.filter!=="none":!1)||PRt.some(i=>(e.willChange||"").includes(i))||qRt.some(i=>(e.contain||"").includes(i))}function ORt(t){let A=Gx(t);for(;DD(A)&&!bN(A);){if(cuA(A))return A;if(yZ(A))return null;A=Gx(A)}return null}function IuA(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var WRt=new Set(["html","body","#document"]);function bN(t){return WRt.has(SN(t))}function cw(t){return G0(t).getComputedStyle(t)}function mZ(t){return gw(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function Gx(t){if(SN(t)==="html")return t;const A=t.assignedSlot||t.parentNode||U$A(t)&&t.host||wD(t);return U$A(A)?A.host:A}function H$A(t){const A=Gx(t);return bN(A)?t.ownerDocument?t.ownerDocument.body:t.body:DD(A)&&jH(A)?A:H$A(A)}function zH(t,A,e){var i;A===void 0&&(A=[]),e===void 0&&(e=!0);const o=H$A(t),n=o===((i=t.ownerDocument)==null?void 0:i.body),s=G0(o);if(n){const r=luA(s);return A.concat(s,s.visualViewport||[],jH(o)?o:[],r&&e?zH(r):[])}return A.concat(o,zH(o,[],e))}function luA(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Y$A(t){const A=cw(t);let e=parseFloat(A.width)||0,i=parseFloat(A.height)||0;const o=DD(t),n=o?t.offsetWidth:e,s=o?t.offsetHeight:i,r=EZ(e)!==n||EZ(i)!==s;return r&&(e=n,i=s),{width:e,height:i,$:r}}function BuA(t){return gw(t)?t:t.contextElement}function _N(t){const A=BuA(t);if(!DD(A))return yD(1);const e=A.getBoundingClientRect(),{width:i,height:o,$:n}=Y$A(A);let s=(n?EZ(e.width):e.width)/i,r=(n?EZ(e.height):e.height)/o;return(!s||!Number.isFinite(s))&&(s=1),(!r||!Number.isFinite(r))&&(r=1),{x:s,y:r}}var ZRt=yD(0);function J$A(t){const A=G0(t);return!IuA()||!A.visualViewport?ZRt:{x:A.visualViewport.offsetLeft,y:A.visualViewport.offsetTop}}function VRt(t,A,e){return A===void 0&&(A=!1),!e||A&&e!==G0(t)?!1:A}function IG(t,A,e,i){A===void 0&&(A=!1),e===void 0&&(e=!1);const o=t.getBoundingClientRect(),n=BuA(t);let s=yD(1);A&&(i?gw(i)&&(s=_N(i)):s=_N(t));const r=VRt(n,e,i)?J$A(n):yD(0);let a=(o.left+r.x)/s.x,g=(o.top+r.y)/s.y,c=o.width/s.x,I=o.height/s.y;if(n){const l=G0(n),B=i&&gw(i)?G0(i):i;let C=l,Q=luA(C);for(;Q&&i&&B!==C;){const h=_N(Q),E=Q.getBoundingClientRect(),u=cw(Q),d=E.left+(Q.clientLeft+parseFloat(u.paddingLeft))*h.x,f=E.top+(Q.clientTop+parseFloat(u.paddingTop))*h.y;a*=h.x,g*=h.y,c*=h.x,I*=h.y,a+=d,g+=f,C=G0(Q),Q=luA(C)}}return pZ({width:c,height:I,x:a,y:g})}function wZ(t,A){const e=mZ(t).scrollLeft;return A?A.left+e:IG(wD(t)).left+e}function T$A(t,A){const e=t.getBoundingClientRect(),i=e.left+A.scrollLeft-wZ(t,e),o=e.top+A.scrollTop;return{x:i,y:o}}function jRt(t){let{elements:A,rect:e,offsetParent:i,strategy:o}=t;const n=o==="fixed",s=wD(i),r=A?yZ(A.floating):!1;if(i===s||r&&n)return e;let a={scrollLeft:0,scrollTop:0},g=yD(1);const c=yD(0),I=DD(i);if((I||!I&&!n)&&((SN(i)!=="body"||jH(s))&&(a=mZ(i)),DD(i))){const B=IG(i);g=_N(i),c.x=B.x+i.clientLeft,c.y=B.y+i.clientTop}const l=s&&!I&&!n?T$A(s,a):yD(0);return{width:e.width*g.x,height:e.height*g.y,x:e.x*g.x-a.scrollLeft*g.x+c.x+l.x,y:e.y*g.y-a.scrollTop*g.y+c.y+l.y}}function zRt(t){return Array.from(t.getClientRects())}function XRt(t){const A=wD(t),e=mZ(t),i=t.ownerDocument.body,o=F0(A.scrollWidth,A.clientWidth,i.scrollWidth,i.clientWidth),n=F0(A.scrollHeight,A.clientHeight,i.scrollHeight,i.clientHeight);let s=-e.scrollLeft+wZ(t);const r=-e.scrollTop;return cw(i).direction==="rtl"&&(s+=F0(A.clientWidth,i.clientWidth)-o),{width:o,height:n,x:s,y:r}}var K$A=25;function $Rt(t,A){const e=G0(t),i=wD(t),o=e.visualViewport;let n=i.clientWidth,s=i.clientHeight,r=0,a=0;if(o){n=o.width,s=o.height;const c=IuA();(!c||c&&A==="fixed")&&(r=o.offsetLeft,a=o.offsetTop)}const g=wZ(i);if(g<=0){const c=i.ownerDocument,I=c.body,l=getComputedStyle(I),B=c.compatMode==="CSS1Compat"&&parseFloat(l.marginLeft)+parseFloat(l.marginRight)||0,C=Math.abs(i.clientWidth-I.clientWidth-B);C<=K$A&&(n-=C)}else g<=K$A&&(n+=g);return{width:n,height:s,x:r,y:a}}var Avt=new Set(["absolute","fixed"]);function evt(t,A){const e=IG(t,!0,A==="fixed"),i=e.top+t.clientTop,o=e.left+t.clientLeft,n=DD(t)?_N(t):yD(1),s=t.clientWidth*n.x,r=t.clientHeight*n.y,a=o*n.x,g=i*n.y;return{width:s,height:r,x:a,y:g}}function P$A(t,A,e){let i;if(A==="viewport")i=$Rt(t,e);else if(A==="document")i=XRt(wD(t));else if(gw(A))i=evt(A,e);else{const o=J$A(t);i={x:A.x-o.x,y:A.y-o.y,width:A.width,height:A.height}}return pZ(i)}function q$A(t,A){const e=Gx(t);return e===A||!gw(e)||bN(e)?!1:cw(e).position==="fixed"||q$A(e,A)}function tvt(t,A){const e=A.get(t);if(e)return e;let i=zH(t,[],!1).filter(r=>gw(r)&&SN(r)!=="body"),o=null;const n=cw(t).position==="fixed";let s=n?Gx(t):t;for(;gw(s)&&!bN(s);){const r=cw(s),a=cuA(s);!a&&r.position==="fixed"&&(o=null),(n?!a&&!o:!a&&r.position==="static"&&!!o&&Avt.has(o.position)||jH(s)&&!a&&q$A(t,s))?i=i.filter(c=>c!==s):o=r,s=Gx(s)}return A.set(t,i),i}function ivt(t){let{element:A,boundary:e,rootBoundary:i,strategy:o}=t;const s=[...e==="clippingAncestors"?yZ(A)?[]:tvt(A,this._c):[].concat(e),i],r=s[0],a=s.reduce((g,c)=>{const I=P$A(A,c,o);return g.top=F0(I.top,g.top),g.right=Fx(I.right,g.right),g.bottom=Fx(I.bottom,g.bottom),g.left=F0(I.left,g.left),g},P$A(A,r,o));return{width:a.right-a.left,height:a.bottom-a.top,x:a.left,y:a.top}}function ovt(t){const{width:A,height:e}=Y$A(t);return{width:A,height:e}}function nvt(t,A,e){const i=DD(A),o=wD(A),n=e==="fixed",s=IG(t,!0,n,A);let r={scrollLeft:0,scrollTop:0};const a=yD(0);function g(){a.x=wZ(o)}if(i||!i&&!n)if((SN(A)!=="body"||jH(o))&&(r=mZ(A)),i){const B=IG(A,!0,n,A);a.x=B.x+A.clientLeft,a.y=B.y+A.clientTop}else o&&g();n&&!i&&o&&g();const c=o&&!i&&!n?T$A(o,r):yD(0),I=s.left+r.scrollLeft-a.x-c.x,l=s.top+r.scrollTop-a.y-c.y;return{x:I,y:l,width:s.width,height:s.height}}function CuA(t){return cw(t).position==="static"}function O$A(t,A){if(!DD(t)||cw(t).position==="fixed")return null;if(A)return A(t);let e=t.offsetParent;return wD(t)===e&&(e=e.ownerDocument.body),e}function W$A(t,A){const e=G0(t);if(yZ(t))return e;if(!DD(t)){let o=Gx(t);for(;o&&!bN(o);){if(gw(o)&&!CuA(o))return o;o=Gx(o)}return e}let i=O$A(t,A);for(;i&&JRt(i)&&CuA(i);)i=O$A(i,A);return i&&bN(i)&&CuA(i)&&!cuA(i)?e:i||ORt(t)||e}var svt=async function(t){const A=this.getOffsetParent||W$A,e=this.getDimensions,i=await e(t.floating);return{reference:nvt(t.reference,await A(t.floating),t.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}};function rvt(t){return cw(t).direction==="rtl"}var avt={convertOffsetParentRelativeRectToViewportRelativeRect:jRt,getDocumentElement:wD,getClippingRect:ivt,getOffsetParent:W$A,getElementRects:svt,getClientRects:zRt,getDimensions:ovt,getScale:_N,isElement:gw,isRTL:rvt};function Z$A(t,A){return t.x===A.x&&t.y===A.y&&t.width===A.width&&t.height===A.height}function gvt(t,A){let e=null,i;const o=wD(t);function n(){var r;clearTimeout(i),(r=e)==null||r.disconnect(),e=null}function s(r,a){r===void 0&&(r=!1),a===void 0&&(a=1),n();const g=t.getBoundingClientRect(),{left:c,top:I,width:l,height:B}=g;if(r||A(),!l||!B)return;const C=uZ(I),Q=uZ(o.clientWidth-(c+l)),h=uZ(o.clientHeight-(I+B)),E=uZ(c),d={rootMargin:-C+"px "+-Q+"px "+-h+"px "+-E+"px",threshold:F0(0,Fx(1,a))||1};let f=!0;function m(D){const w=D[0].intersectionRatio;if(w!==a){if(!f)return s();w?s(!1,w):i=setTimeout(()=>{s(!1,1e-7)},1e3)}w===1&&!Z$A(g,t.getBoundingClientRect())&&s(),f=!1}try{e=new IntersectionObserver(m,{...d,root:o.ownerDocument})}catch{e=new IntersectionObserver(m,d)}e.observe(t)}return s(!0),n}function cvt(t,A,e,i){i===void 0&&(i={});const{ancestorScroll:o=!0,ancestorResize:n=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:r=typeof IntersectionObserver=="function",animationFrame:a=!1}=i,g=BuA(t),c=o||n?[...g?zH(g):[],...zH(A)]:[];c.forEach(E=>{o&&E.addEventListener("scroll",e,{passive:!0}),n&&E.addEventListener("resize",e)});const I=g&&r?gvt(g,e):null;let l=-1,B=null;s&&(B=new ResizeObserver(E=>{let[u]=E;u&&u.target===g&&B&&(B.unobserve(A),cancelAnimationFrame(l),l=requestAnimationFrame(()=>{var d;(d=B)==null||d.observe(A)})),e()}),g&&!a&&B.observe(g),B.observe(A));let C,Q=a?IG(t):null;a&&h();function h(){const E=IG(t);Q&&!Z$A(Q,E)&&e(),Q=E,C=requestAnimationFrame(h)}return e(),()=>{var E;c.forEach(u=>{o&&u.removeEventListener("scroll",e),n&&u.removeEventListener("resize",e)}),I?.(),(E=B)==null||E.disconnect(),B=null,a&&cancelAnimationFrame(C)}}var Ivt=MRt,lvt=NRt,Bvt=GRt,Cvt=URt,Qvt=RRt,V$A=FRt,hvt=LRt,Evt=(t,A,e)=>{const i=new Map,o={platform:avt,...e},n={...o.platform,_c:i};return kRt(t,A,{...o,platform:n})},uvt=typeof document<"u",dvt=function(){},DZ=uvt?V.useLayoutEffect:dvt;function SZ(t,A){if(t===A)return!0;if(typeof t!=typeof A)return!1;if(typeof t=="function"&&t.toString()===A.toString())return!0;let e,i,o;if(t&&A&&typeof t=="object"){if(Array.isArray(t)){if(e=t.length,e!==A.length)return!1;for(i=e;i--!==0;)if(!SZ(t[i],A[i]))return!1;return!0}if(o=Object.keys(t),e=o.length,e!==Object.keys(A).length)return!1;for(i=e;i--!==0;)if(!{}.hasOwnProperty.call(A,o[i]))return!1;for(i=e;i--!==0;){const n=o[i];if(!(n==="_owner"&&t.$$typeof)&&!SZ(t[n],A[n]))return!1}return!0}return t!==t&&A!==A}function j$A(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function z$A(t,A){const e=j$A(t);return Math.round(A*e)/e}function QuA(t){const A=V.useRef(t);return DZ(()=>{A.current=t}),A}function pvt(t){t===void 0&&(t={});const{placement:A="bottom",strategy:e="absolute",middleware:i=[],platform:o,elements:{reference:n,floating:s}={},transform:r=!0,whileElementsMounted:a,open:g}=t,[c,I]=V.useState({x:0,y:0,strategy:e,placement:A,middlewareData:{},isPositioned:!1}),[l,B]=V.useState(i);SZ(l,i)||B(i);const[C,Q]=V.useState(null),[h,E]=V.useState(null),u=V.useCallback($=>{$!==D.current&&(D.current=$,Q($))},[]),d=V.useCallback($=>{$!==w.current&&(w.current=$,E($))},[]),f=n||C,m=s||h,D=V.useRef(null),w=V.useRef(null),b=V.useRef(c),k=a!=null,_=QuA(a),M=QuA(o),v=QuA(g),U=V.useCallback(()=>{if(!D.current||!w.current)return;const $={placement:A,strategy:e,middleware:l};M.current&&($.platform=M.current),Evt(D.current,w.current,$).then(iA=>{const aA={...iA,isPositioned:v.current!==!1};J.current&&!SZ(b.current,aA)&&(b.current=aA,jL.flushSync(()=>{I(aA)}))})},[l,A,e,M,v]);DZ(()=>{g===!1&&b.current.isPositioned&&(b.current.isPositioned=!1,I($=>({...$,isPositioned:!1})))},[g]);const J=V.useRef(!1);DZ(()=>(J.current=!0,()=>{J.current=!1}),[]),DZ(()=>{if(f&&(D.current=f),m&&(w.current=m),f&&m){if(_.current)return _.current(f,m,U);U()}},[f,m,U,_,k]);const Y=V.useMemo(()=>({reference:D,floating:w,setReference:u,setFloating:d}),[u,d]),O=V.useMemo(()=>({reference:f,floating:m}),[f,m]),Z=V.useMemo(()=>{const $={position:e,left:0,top:0};if(!O.floating)return $;const iA=z$A(O.floating,c.x),aA=z$A(O.floating,c.y);return r?{...$,transform:"translate("+iA+"px, "+aA+"px)",...j$A(O.floating)>=1.5&&{willChange:"transform"}}:{position:e,left:iA,top:aA}},[e,r,O.floating,c.x,c.y]);return V.useMemo(()=>({...c,update:U,refs:Y,elements:O,floatingStyles:Z}),[c,U,Y,O,Z])}var fvt=t=>{function A(e){return{}.hasOwnProperty.call(e,"current")}return{name:"arrow",options:t,fn(e){const{element:i,padding:o}=typeof t=="function"?t(e):t;return i&&A(i)?i.current!=null?V$A({element:i.current,padding:o}).fn(e):{}:i?V$A({element:i,padding:o}).fn(e):{}}}},yvt=(t,A)=>({...Ivt(t),options:[t,A]}),mvt=(t,A)=>({...lvt(t),options:[t,A]}),wvt=(t,A)=>({...hvt(t),options:[t,A]}),Dvt=(t,A)=>({...Bvt(t),options:[t,A]}),Svt=(t,A)=>({...Cvt(t),options:[t,A]}),bvt=(t,A)=>({...Qvt(t),options:[t,A]}),_vt=(t,A)=>({...fvt(t),options:[t,A]}),xvt="Arrow",X$A=V.forwardRef((t,A)=>{const{children:e,width:i=10,height:o=5,...n}=t;return W.jsx(Zd.svg,{...n,ref:A,width:i,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:t.asChild?e:W.jsx("polygon",{points:"0,0 30,0 15,10"})})});X$A.displayName=xvt;var kvt=X$A;function Fvt(t){const[A,e]=V.useState(void 0);return xx(()=>{if(t){e({width:t.offsetWidth,height:t.offsetHeight});const i=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const n=o[0];let s,r;if("borderBoxSize"in n){const a=n.borderBoxSize,g=Array.isArray(a)?a[0]:a;s=g.inlineSize,r=g.blockSize}else s=t.offsetWidth,r=t.offsetHeight;e({width:s,height:r})});return i.observe(t,{box:"border-box"}),()=>i.unobserve(t)}else e(void 0)},[t]),A}var huA="Popper",[$$A,AAe]=ZH(huA),[Gvt,eAe]=$$A(huA),tAe=t=>{const{__scopePopper:A,children:e}=t,[i,o]=V.useState(null);return W.jsx(Gvt,{scope:A,anchor:i,onAnchorChange:o,children:e})};tAe.displayName=huA;var iAe="PopperAnchor",oAe=V.forwardRef((t,A)=>{const{__scopePopper:e,virtualRef:i,...o}=t,n=eAe(iAe,e),s=V.useRef(null),r=ff(A,s),a=V.useRef(null);return V.useEffect(()=>{const g=a.current;a.current=i?.current||s.current,g!==a.current&&n.onAnchorChange(a.current)}),i?null:W.jsx(Zd.div,{...o,ref:r})});oAe.displayName=iAe;var EuA="PopperContent",[Rvt,vvt]=$$A(EuA),nAe=V.forwardRef((t,A)=>{const{__scopePopper:e,side:i="bottom",sideOffset:o=0,align:n="center",alignOffset:s=0,arrowPadding:r=0,avoidCollisions:a=!0,collisionBoundary:g=[],collisionPadding:c=0,sticky:I="partial",hideWhenDetached:l=!1,updatePositionStrategy:B="optimized",onPlaced:C,...Q}=t,h=eAe(EuA,e),[E,u]=V.useState(null),d=ff(A,GA=>u(GA)),[f,m]=V.useState(null),D=Fvt(f),w=D?.width??0,b=D?.height??0,k=i+(n!=="center"?"-"+n:""),_=typeof c=="number"?c:{top:0,right:0,bottom:0,left:0,...c},M=Array.isArray(g)?g:[g],v=M.length>0,U={padding:_,boundary:M.filter(Nvt),altBoundary:v},{refs:J,floatingStyles:Y,placement:O,isPositioned:Z,middlewareData:$}=pvt({strategy:"fixed",placement:k,whileElementsMounted:(...GA)=>cvt(...GA,{animationFrame:B==="always"}),elements:{reference:h.anchor},middleware:[yvt({mainAxis:o+b,alignmentAxis:s}),a&&mvt({mainAxis:!0,crossAxis:!1,limiter:I==="partial"?wvt():void 0,...U}),a&&Dvt({...U}),Svt({...U,apply:({elements:GA,rects:NA,availableWidth:QA,availableHeight:xA})=>{const{width:uA,height:OA}=NA.reference,PA=GA.floating.style;PA.setProperty("--radix-popper-available-width",`${QA}px`),PA.setProperty("--radix-popper-available-height",`${xA}px`),PA.setProperty("--radix-popper-anchor-width",`${uA}px`),PA.setProperty("--radix-popper-anchor-height",`${OA}px`)}}),f&&_vt({element:f,padding:r}),Lvt({arrowWidth:w,arrowHeight:b}),l&&bvt({strategy:"referenceHidden",...U})]}),[iA,aA]=aAe(O),eA=fD(C);xx(()=>{Z&&eA?.()},[Z,eA]);const oA=$.arrow?.x,rA=$.arrow?.y,lA=$.arrow?.centerOffset!==0,[EA,bA]=V.useState();return xx(()=>{E&&bA(window.getComputedStyle(E).zIndex)},[E]),W.jsx("div",{ref:J.setFloating,"data-radix-popper-content-wrapper":"",style:{...Y,transform:Z?Y.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:EA,"--radix-popper-transform-origin":[$.transformOrigin?.x,$.transformOrigin?.y].join(" "),...$.hide?.referenceHidden&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:W.jsx(Rvt,{scope:e,placedSide:iA,onArrowChange:m,arrowX:oA,arrowY:rA,shouldHideArrow:lA,children:W.jsx(Zd.div,{"data-side":iA,"data-align":aA,...Q,ref:d,style:{...Q.style,animation:Z?void 0:"none"}})})})});nAe.displayName=EuA;var sAe="PopperArrow",Mvt={top:"bottom",right:"left",bottom:"top",left:"right"},rAe=V.forwardRef(function(A,e){const{__scopePopper:i,...o}=A,n=vvt(sAe,i),s=Mvt[n.placedSide];return W.jsx("span",{ref:n.onArrowChange,style:{position:"absolute",left:n.arrowX,top:n.arrowY,[s]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[n.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[n.placedSide],visibility:n.shouldHideArrow?"hidden":void 0},children:W.jsx(kvt,{...o,ref:e,style:{...o.style,display:"block"}})})});rAe.displayName=sAe;function Nvt(t){return t!==null}var Lvt=t=>({name:"transformOrigin",options:t,fn(A){const{placement:e,rects:i,middlewareData:o}=A,s=o.arrow?.centerOffset!==0,r=s?0:t.arrowWidth,a=s?0:t.arrowHeight,[g,c]=aAe(e),I={start:"0%",center:"50%",end:"100%"}[c],l=(o.arrow?.x??0)+r/2,B=(o.arrow?.y??0)+a/2;let C="",Q="";return g==="bottom"?(C=s?I:`${l}px`,Q=`${-a}px`):g==="top"?(C=s?I:`${l}px`,Q=`${i.floating.height+a}px`):g==="right"?(C=`${-a}px`,Q=s?I:`${B}px`):g==="left"&&(C=`${i.floating.width+a}px`,Q=s?I:`${B}px`),{data:{x:C,y:Q}}}});function aAe(t){const[A,e="center"]=t.split("-");return[A,e]}var gAe=tAe,Uvt=oAe,Hvt=nAe,Yvt=rAe,Jvt="Portal",cAe=V.forwardRef((t,A)=>{const{container:e,...i}=t,[o,n]=V.useState(!1);xx(()=>n(!0),[]);const s=e||o&&globalThis?.document?.body;return s?h5.createPortal(W.jsx(Zd.div,{...i,ref:A}),s):null});cAe.displayName=Jvt;function Tvt(t,A){return V.useReducer((e,i)=>A[e][i]??e,t)}var XH=t=>{const{present:A,children:e}=t,i=Kvt(A),o=typeof e=="function"?e({present:i.isPresent}):V.Children.only(e),n=ff(i.ref,Pvt(o));return typeof e=="function"||i.isPresent?V.cloneElement(o,{ref:n}):null};XH.displayName="Presence";function Kvt(t){const[A,e]=V.useState(),i=V.useRef(null),o=V.useRef(t),n=V.useRef("none"),s=t?"mounted":"unmounted",[r,a]=Tvt(s,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return V.useEffect(()=>{const g=bZ(i.current);n.current=r==="mounted"?g:"none"},[r]),xx(()=>{const g=i.current,c=o.current;if(c!==t){const l=n.current,B=bZ(g);t?a("MOUNT"):B==="none"||g?.display==="none"?a("UNMOUNT"):a(c&&l!==B?"ANIMATION_OUT":"UNMOUNT"),o.current=t}},[t,a]),xx(()=>{if(A){let g;const c=A.ownerDocument.defaultView??window,I=B=>{const Q=bZ(i.current).includes(CSS.escape(B.animationName));if(B.target===A&&Q&&(a("ANIMATION_END"),!o.current)){const h=A.style.animationFillMode;A.style.animationFillMode="forwards",g=c.setTimeout(()=>{A.style.animationFillMode==="forwards"&&(A.style.animationFillMode=h)})}},l=B=>{B.target===A&&(n.current=bZ(i.current))};return A.addEventListener("animationstart",l),A.addEventListener("animationcancel",I),A.addEventListener("animationend",I),()=>{c.clearTimeout(g),A.removeEventListener("animationstart",l),A.removeEventListener("animationcancel",I),A.removeEventListener("animationend",I)}}else a("ANIMATION_END")},[A,a]),{isPresent:["mounted","unmountSuspended"].includes(r),ref:V.useCallback(g=>{i.current=g?getComputedStyle(g):null,e(g)},[])}}function bZ(t){return t?.animationName||"none"}function Pvt(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var uuA="rovingFocusGroup.onEntryFocus",qvt={bubbles:!1,cancelable:!0},$H="RovingFocusGroup",[duA,IAe,Ovt]=h$A($H),[Wvt,lAe]=ZH($H,[Ovt]),[Zvt,Vvt]=Wvt($H),BAe=V.forwardRef((t,A)=>W.jsx(duA.Provider,{scope:t.__scopeRovingFocusGroup,children:W.jsx(duA.Slot,{scope:t.__scopeRovingFocusGroup,children:W.jsx(jvt,{...t,ref:A})})}));BAe.displayName=$H;var jvt=V.forwardRef((t,A)=>{const{__scopeRovingFocusGroup:e,orientation:i,loop:o=!1,dir:n,currentTabStopId:s,defaultCurrentTabStopId:r,onCurrentTabStopIdChange:a,onEntryFocus:g,preventScrollOnEntryFocus:c=!1,...I}=t,l=V.useRef(null),B=ff(A,l),C=E$A(n),[Q,h]=AuA({prop:s,defaultProp:r??null,onChange:a,caller:$H}),[E,u]=V.useState(!1),d=fD(g),f=IAe(e),m=V.useRef(!1),[D,w]=V.useState(0);return V.useEffect(()=>{const b=l.current;if(b)return b.addEventListener(uuA,d),()=>b.removeEventListener(uuA,d)},[d]),W.jsx(Zvt,{scope:e,orientation:i,dir:C,loop:o,currentTabStopId:Q,onItemFocus:V.useCallback(b=>h(b),[h]),onItemShiftTab:V.useCallback(()=>u(!0),[]),onFocusableItemAdd:V.useCallback(()=>w(b=>b+1),[]),onFocusableItemRemove:V.useCallback(()=>w(b=>b-1),[]),children:W.jsx(Zd.div,{tabIndex:E||D===0?-1:0,"data-orientation":i,...I,ref:B,style:{outline:"none",...t.style},onMouseDown:ca(t.onMouseDown,()=>{m.current=!0}),onFocus:ca(t.onFocus,b=>{const k=!m.current;if(b.target===b.currentTarget&&k&&!E){const _=new CustomEvent(uuA,qvt);if(b.currentTarget.dispatchEvent(_),!_.defaultPrevented){const M=f().filter(O=>O.focusable),v=M.find(O=>O.active),U=M.find(O=>O.id===Q),Y=[v,U,...M].filter(Boolean).map(O=>O.ref.current);hAe(Y,c)}}m.current=!1}),onBlur:ca(t.onBlur,()=>u(!1))})})}),CAe="RovingFocusGroupItem",QAe=V.forwardRef((t,A)=>{const{__scopeRovingFocusGroup:e,focusable:i=!0,active:o=!1,tabStopId:n,children:s,...r}=t,a=VH(),g=n||a,c=Vvt(CAe,e),I=c.currentTabStopId===g,l=IAe(e),{onFocusableItemAdd:B,onFocusableItemRemove:C,currentTabStopId:Q}=c;return V.useEffect(()=>{if(i)return B(),()=>C()},[i,B,C]),W.jsx(duA.ItemSlot,{scope:e,id:g,focusable:i,active:o,children:W.jsx(Zd.span,{tabIndex:I?0:-1,"data-orientation":c.orientation,...r,ref:A,onMouseDown:ca(t.onMouseDown,h=>{i?c.onItemFocus(g):h.preventDefault()}),onFocus:ca(t.onFocus,()=>c.onItemFocus(g)),onKeyDown:ca(t.onKeyDown,h=>{if(h.key==="Tab"&&h.shiftKey){c.onItemShiftTab();return}if(h.target!==h.currentTarget)return;const E=$vt(h,c.orientation,c.dir);if(E!==void 0){if(h.metaKey||h.ctrlKey||h.altKey||h.shiftKey)return;h.preventDefault();let d=l().filter(f=>f.focusable).map(f=>f.ref.current);if(E==="last")d.reverse();else if(E==="prev"||E==="next"){E==="prev"&&d.reverse();const f=d.indexOf(h.currentTarget);d=c.loop?AMt(d,f+1):d.slice(f+1)}setTimeout(()=>hAe(d))}}),children:typeof s=="function"?s({isCurrentTabStop:I,hasTabStop:Q!=null}):s})})});QAe.displayName=CAe;var zvt={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Xvt(t,A){return A!=="rtl"?t:t==="ArrowLeft"?"ArrowRight":t==="ArrowRight"?"ArrowLeft":t}function $vt(t,A,e){const i=Xvt(t.key,e);if(!(A==="vertical"&&["ArrowLeft","ArrowRight"].includes(i))&&!(A==="horizontal"&&["ArrowUp","ArrowDown"].includes(i)))return zvt[i]}function hAe(t,A=!1){const e=document.activeElement;for(const i of t)if(i===e||(i.focus({preventScroll:A}),document.activeElement!==e))return}function AMt(t,A){return t.map((e,i)=>t[(A+i)%t.length])}var eMt=BAe,tMt=QAe,iMt=function(t){if(typeof document>"u")return null;var A=Array.isArray(t)?t[0]:t;return A.ownerDocument.body},xN=new WeakMap,_Z=new WeakMap,xZ={},puA=0,EAe=function(t){return t&&(t.host||EAe(t.parentNode))},oMt=function(t,A){return A.map(function(e){if(t.contains(e))return e;var i=EAe(e);return i&&t.contains(i)?i:(console.error("aria-hidden",e,"in not contained inside",t,". Doing nothing"),null)}).filter(function(e){return!!e})},nMt=function(t,A,e,i){var o=oMt(A,Array.isArray(t)?t:[t]);xZ[e]||(xZ[e]=new WeakMap);var n=xZ[e],s=[],r=new Set,a=new Set(o),g=function(I){!I||r.has(I)||(r.add(I),g(I.parentNode))};o.forEach(g);var c=function(I){!I||a.has(I)||Array.prototype.forEach.call(I.children,function(l){if(r.has(l))c(l);else try{var B=l.getAttribute(i),C=B!==null&&B!=="false",Q=(xN.get(l)||0)+1,h=(n.get(l)||0)+1;xN.set(l,Q),n.set(l,h),s.push(l),Q===1&&C&&_Z.set(l,!0),h===1&&l.setAttribute(e,"true"),C||l.setAttribute(i,"true")}catch(E){console.error("aria-hidden: cannot operate on ",l,E)}})};return c(A),r.clear(),puA++,function(){s.forEach(function(I){var l=xN.get(I)-1,B=n.get(I)-1;xN.set(I,l),n.set(I,B),l||(_Z.has(I)||I.removeAttribute(i),_Z.delete(I)),B||I.removeAttribute(e)}),puA--,puA||(xN=new WeakMap,xN=new WeakMap,_Z=new WeakMap,xZ={})}},sMt=function(t,A,e){e===void 0&&(e="data-aria-hidden");var i=Array.from(Array.isArray(t)?t:[t]),o=iMt(t);return o?(i.push.apply(i,Array.from(o.querySelectorAll("[aria-live], script"))),nMt(i,o,e,"aria-hidden")):function(){return null}},SD=function(){return SD=Object.assign||function(A){for(var e,i=1,o=arguments.length;i<o;i++){e=arguments[i];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(A[n]=e[n])}return A},SD.apply(this,arguments)};function uAe(t,A){var e={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&A.indexOf(i)<0&&(e[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,i=Object.getOwnPropertySymbols(t);o<i.length;o++)A.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(t,i[o])&&(e[i[o]]=t[i[o]]);return e}function rMt(t,A,e){for(var i=0,o=A.length,n;i<o;i++)(n||!(i in A))&&(n||(n=Array.prototype.slice.call(A,0,i)),n[i]=A[i]);return t.concat(n||Array.prototype.slice.call(A))}var kZ="right-scroll-bar-position",FZ="width-before-scroll-bar",aMt="with-scroll-bars-hidden",gMt="--removed-body-scroll-bar-size";function fuA(t,A){return typeof t=="function"?t(A):t&&(t.current=A),t}function cMt(t,A){var e=V.useState(function(){return{value:t,callback:A,facade:{get current(){return e.value},set current(i){var o=e.value;o!==i&&(e.value=i,e.callback(i,o))}}}})[0];return e.callback=A,e.facade}var IMt=typeof window<"u"?V.useLayoutEffect:V.useEffect,dAe=new WeakMap;function lMt(t,A){var e=cMt(null,function(i){return t.forEach(function(o){return fuA(o,i)})});return IMt(function(){var i=dAe.get(e);if(i){var o=new Set(i),n=new Set(t),s=e.current;o.forEach(function(r){n.has(r)||fuA(r,null)}),n.forEach(function(r){o.has(r)||fuA(r,s)})}dAe.set(e,t)},[t]),e}function BMt(t){return t}function CMt(t,A){A===void 0&&(A=BMt);var e=[],i=!1,o={read:function(){if(i)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return e.length?e[e.length-1]:t},useMedium:function(n){var s=A(n,i);return e.push(s),function(){e=e.filter(function(r){return r!==s})}},assignSyncMedium:function(n){for(i=!0;e.length;){var s=e;e=[],s.forEach(n)}e={push:function(r){return n(r)},filter:function(){return e}}},assignMedium:function(n){i=!0;var s=[];if(e.length){var r=e;e=[],r.forEach(n),s=e}var a=function(){var c=s;s=[],c.forEach(n)},g=function(){return Promise.resolve().then(a)};g(),e={push:function(c){s.push(c),g()},filter:function(c){return s=s.filter(c),e}}}};return o}function QMt(t){t===void 0&&(t={});var A=CMt(null);return A.options=SD({async:!0,ssr:!1},t),A}var pAe=function(t){var A=t.sideCar,e=uAe(t,["sideCar"]);if(!A)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var i=A.read();if(!i)throw new Error("Sidecar medium not found");return V.createElement(i,SD({},e))};pAe.isSideCarExport=!0;function hMt(t,A){return t.useMedium(A),pAe}var fAe=QMt(),yuA=function(){},GZ=V.forwardRef(function(t,A){var e=V.useRef(null),i=V.useState({onScrollCapture:yuA,onWheelCapture:yuA,onTouchMoveCapture:yuA}),o=i[0],n=i[1],s=t.forwardProps,r=t.children,a=t.className,g=t.removeScrollBar,c=t.enabled,I=t.shards,l=t.sideCar,B=t.noRelative,C=t.noIsolation,Q=t.inert,h=t.allowPinchZoom,E=t.as,u=E===void 0?"div":E,d=t.gapMode,f=uAe(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),m=l,D=lMt([e,A]),w=SD(SD({},f),o);return V.createElement(V.Fragment,null,c&&V.createElement(m,{sideCar:fAe,removeScrollBar:g,shards:I,noRelative:B,noIsolation:C,inert:Q,setCallbacks:n,allowPinchZoom:!!h,lockRef:e,gapMode:d}),s?V.cloneElement(V.Children.only(r),SD(SD({},w),{ref:D})):V.createElement(u,SD({},w,{className:a,ref:D}),r))});GZ.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},GZ.classNames={fullWidth:FZ,zeroRight:kZ};var EMt=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function uMt(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var A=EMt();return A&&t.setAttribute("nonce",A),t}function dMt(t,A){t.styleSheet?t.styleSheet.cssText=A:t.appendChild(document.createTextNode(A))}function pMt(t){var A=document.head||document.getElementsByTagName("head")[0];A.appendChild(t)}var fMt=function(){var t=0,A=null;return{add:function(e){t==0&&(A=uMt())&&(dMt(A,e),pMt(A)),t++},remove:function(){t--,!t&&A&&(A.parentNode&&A.parentNode.removeChild(A),A=null)}}},yMt=function(){var t=fMt();return function(A,e){V.useEffect(function(){return t.add(A),function(){t.remove()}},[A&&e])}},yAe=function(){var t=yMt(),A=function(e){var i=e.styles,o=e.dynamic;return t(i,o),null};return A},mMt={left:0,top:0,right:0,gap:0},muA=function(t){return parseInt(t||"",10)||0},wMt=function(t){var A=window.getComputedStyle(document.body),e=A[t==="padding"?"paddingLeft":"marginLeft"],i=A[t==="padding"?"paddingTop":"marginTop"],o=A[t==="padding"?"paddingRight":"marginRight"];return[muA(e),muA(i),muA(o)]},DMt=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return mMt;var A=wMt(t),e=document.documentElement.clientWidth,i=window.innerWidth;return{left:A[0],top:A[1],right:A[2],gap:Math.max(0,i-e+A[2]-A[0])}},SMt=yAe(),kN="data-scroll-locked",bMt=function(t,A,e,i){var o=t.left,n=t.top,s=t.right,r=t.gap;return e===void 0&&(e="margin"),`
|
|
5186
|
+
`.trim();const J=Y=>{const O="Failed to load Manifold loader script.";console.error(O,Y),I(O),window.removeEventListener(M,v)};return U.addEventListener("error",J),document.body.appendChild(U),()=>{window.removeEventListener(M,v),U.removeEventListener("error",J)}},[]);const{geoms:l,textures:B,pcbThickness:C,error:Q,isLoading:h,boardData:E,isFauxBoard:u}=hGt(a,r),d=V.useMemo(()=>dGt(l),[l]),f=V.useMemo(()=>UFt(B,E,C,u),[B,E,C,u]),m=V.useMemo(()=>_i(r).cad_component.list(),[r]),D=V.useMemo(()=>{if(!E)return;const{width:k=0,height:_=0}=E;return{width:k,height:_}},[E]),w=V.useMemo(()=>{if(!E)return;const{center:k}=E;if(k)return{x:k.x,y:k.y}},[E]),b=V.useMemo(()=>{if(!E)return[5,-5,5];const{width:k=0,height:_=0}=E,M=Math.max(k,1),v=Math.max(_,1),U=Math.max(M,v,5);return[U*.4,-U*.7,U*.9]},[E]);return c?W.jsxs("div",{style:{color:"red",padding:"1em",border:"1px solid red",margin:"1em"},children:["Error: ",c]}):a?Q?W.jsxs("div",{style:{color:"red",padding:"1em",border:"1px solid red",margin:"1em"},children:["Error: ",Q]}):h?W.jsx("div",{style:{padding:"1em"},children:"Processing board geometry..."}):W.jsxs(J7A,{initialCameraPosition:b,autoRotateDisabled:A,clickToInteractEnabled:e,boardDimensions:D,boardCenter:w,onUserInteraction:i,onCameraControllerReady:n,children:[W.jsx(pGt,{geometryMeshes:d,textureMeshes:f}),m.map(k=>W.jsx(z7A,{fallback:({error:_})=>W.jsx(j7A,{cad_component:k,error:_}),children:W.jsx(N7A,{cad_component:k,circuitJson:r})},k.cad_component_id))]}):W.jsx("div",{style:{padding:"1em"},children:"Loading Manifold module..."})},mGt=yGt,wGt=({containerRef:t})=>{const[A,e]=V.useState(!1),[i,o]=V.useState({x:0,y:0}),n=V.useRef(null),s=V.useRef(null),r=V.useRef(null),a=V.useRef(!1),g=()=>{r.current!==null&&(clearTimeout(r.current),r.current=null)},c=V.useCallback(h=>{h.preventDefault();const E=typeof h.clientX=="number"?h.clientX:0,u=typeof h.clientY=="number"?h.clientY:0;if(a.current){a.current=!1;return}if(!s.current)return;const{x:d,y:f}=s.current,m=Math.abs(E-d),D=Math.abs(u-f),w=10;if(m>w||D>w){s.current=null;return}o({x:E,y:u}),e(!0),s.current=null},[o,e]),I=V.useCallback(h=>{if(h.touches.length===1){const E=h.touches[0];E?(s.current={x:E.clientX,y:E.clientY},g(),r.current=window.setTimeout(()=>{if(s.current){if(t.current){const u=t.current.getBoundingClientRect();o({x:u.left+u.width/2,y:u.top+u.height/2}),e(!0),a.current=!0}s.current=null}},600)):s.current=null}else s.current=null,g()},[t]),l=V.useCallback(h=>{if(!s.current||h.touches.length!==1)return;const E=h.touches[0];if(E){const u=Math.abs(E.clientX-s.current.x),d=Math.abs(E.clientY-s.current.y),f=10;(u>f||d>f)&&(s.current=null,g())}else s.current=null,g()},[]),B=V.useCallback(()=>{g(),setTimeout(()=>{s.current&&(s.current=null)},0)},[]),C=V.useCallback(h=>{const E=h.target;n.current&&n.current.contains(E)||E.closest?.("[data-radix-popper-content-wrapper], [data-radix-dropdown-menu-content], [data-radix-dropdown-menu-sub-content]")||e(!1)},[]);return V.useEffect(()=>{if(A)return document.addEventListener("mousedown",C),document.addEventListener("touchstart",C),()=>{document.removeEventListener("mousedown",C),document.removeEventListener("touchstart",C)}},[A,C]),{menuVisible:A,menuPos:i,menuRef:n,contextMenuEventHandlers:{onMouseDown:h=>{h.button===2?s.current={x:h.clientX,y:h.clientY}:s.current=null},onContextMenu:c,onTouchStart:I,onTouchMove:l,onTouchEnd:B},setMenuVisible:e}};function DGt({setAutoRotate:t,setAutoRotateUserToggled:A,setCameraPreset:e,closeMenu:i,cameraControllerRef:o,isAnimatingRef:n,lastPresetSelectTime:s}){return{handleCameraPresetSelect:V.useCallback(a=>{t(!1),A(!0),e(a),i(),s.current=Date.now(),a!=="Custom"&&(n.current=!0,o.current?.animateToPreset(a),setTimeout(()=>{n.current=!1},600))},[t,A,e,i,o,n,s])}}var SGt=()=>V.useCallback(()=>{const t=window.__TSCIRCUIT_THREE_OBJECT;if(!t)return;new AaA().parse(t,e=>{const i=new Blob([e instanceof ArrayBuffer?e:JSON.stringify(e)],{type:"model/gltf+json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download="scene.gltf",n.click(),URL.revokeObjectURL(o)},e=>{console.error("Failed to export GLTF",e)})},[]),wN=new Map,zEA=new Set,I$A=!1,XEA=0,$EA=0,BZ=null,l$A=!1,bGt=20,_Gt=t=>{const A=t.toLowerCase().split("+"),e=A[A.length-1],i=A.slice(0,-1);return{key:e,ctrl:i.includes("ctrl"),cmd:i.includes("cmd"),shift:i.includes("shift"),alt:i.includes("alt")}},xGt=(t,A)=>{const e=_Gt(A),i=t.key.toLowerCase()===e.key,o=e.ctrl===t.ctrlKey,n=e.cmd===t.metaKey,s=e.shift===t.shiftKey,r=e.alt===t.altKey;return i&&o&&n&&s&&r},kGt=t=>{if(!t||typeof t!="object")return!1;const A=t,e=A.tagName,i=["INPUT","TEXTAREA","SELECT"];if(i.includes(e))return!0;const o=A.getAttribute?.("contenteditable");if(o==="true"||o==="")return!0;let n=A.parentElement;for(let s=0;s<bGt&&n;s++){const r=n.tagName;if(i.includes(r))return!0;const a=n.getAttribute?.("contenteditable");if(a==="true"||a==="")return!0;n=n.parentElement}return!1},FGt=()=>{if(typeof document>"u")return!1;const t=document.activeElement;if(!t)return!1;const A=t.tagName;if(A==="INPUT"||A==="TEXTAREA"||A==="SELECT")return!0;const e=t.getAttribute("contenteditable");return e==="true"||e===""},GGt=()=>{if(!BZ)return!0;const t=BZ.getBoundingClientRect();return XEA>=t.left&&XEA<=t.right&&$EA>=t.top&&$EA<=t.bottom},RGt=()=>{l$A||typeof window>"u"||(window.addEventListener("mousemove",t=>{XEA=t.clientX,$EA=t.clientY}),l$A=!0)},vGt=t=>{kGt(t.target)||FGt()||BZ&&!GGt()||wN.forEach(A=>{xGt(t,A.shortcut)&&(t.preventDefault(),A.invoke())})},B$A=()=>{const t=Array.from(wN.values());zEA.forEach(A=>A(t))},MGt=()=>{I$A||typeof window>"u"||(window.addEventListener("keydown",vGt),I$A=!0)},NGt=t=>{wN.set(t.id,t),B$A(),MGt()},LGt=t=>{wN.delete(t)&&B$A()},UGt=t=>(zEA.add(t),t(Array.from(wN.values())),()=>{zEA.delete(t)}),CZ=(t,A,e)=>{const i=V.useRef(A);i.current=A;const o=V.useMemo(()=>({shortcut:e.shortcut,description:e.description}),[e.shortcut,e.description]);V.useEffect(()=>{const n={id:t,...o,invoke:()=>i.current()};return NGt(n),()=>{LGt(t)}},[t,o])},HGt=()=>{const[t,A]=V.useState(()=>Array.from(wN.values()));return V.useEffect(()=>UGt(A),[]),t},YGt=t=>{BZ=t,RGt()},JGt=()=>({showToast:(t,A=2e3)=>{ys(t,{duration:A})}}),TGt=({children:t})=>W.jsxs(W.Fragment,{children:[t,W.jsx(vzA,{position:"bottom-right"})]});function ca(t,A,{checkForDefaultPrevented:e=!0}={}){return function(o){if(t?.(o),e===!1||!o.defaultPrevented)return A?.(o)}}function C$A(t,A){if(typeof t=="function")return t(A);t!=null&&(t.current=A)}function QZ(...t){return A=>{let e=!1;const i=t.map(o=>{const n=C$A(o,A);return!e&&typeof n=="function"&&(e=!0),n});if(e)return()=>{for(let o=0;o<i.length;o++){const n=i[o];typeof n=="function"?n():C$A(t[o],null)}}}}function ff(...t){return V.useCallback(QZ(...t),t)}function ZH(t,A=[]){let e=[];function i(n,s){const r=V.createContext(s),a=e.length;e=[...e,s];const g=I=>{const{scope:l,children:B,...C}=I,Q=l?.[t]?.[a]||r,h=V.useMemo(()=>C,Object.values(C));return W.jsx(Q.Provider,{value:h,children:B})};g.displayName=n+"Provider";function c(I,l){const B=l?.[t]?.[a]||r,C=V.useContext(B);if(C)return C;if(s!==void 0)return s;throw new Error(`\`${I}\` must be used within \`${n}\``)}return[g,c]}const o=()=>{const n=e.map(s=>V.createContext(s));return function(r){const a=r?.[t]||n;return V.useMemo(()=>({[`__scope${t}`]:{...r,[t]:a}}),[r,a])}};return o.scopeName=t,[i,KGt(o,...A)]}function KGt(...t){const A=t[0];if(t.length===1)return A;const e=()=>{const i=t.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(n){const s=i.reduce((r,{useScope:a,scopeName:g})=>{const I=a(n)[`__scope${g}`];return{...r,...I}},{});return V.useMemo(()=>({[`__scope${A.scopeName}`]:s}),[s])}};return e.scopeName=A.scopeName,e}var xx=globalThis?.document?V.useLayoutEffect:()=>{},PGt=k2[" useInsertionEffect ".trim().toString()]||xx;function AuA({prop:t,defaultProp:A,onChange:e=()=>{},caller:i}){const[o,n,s]=qGt({defaultProp:A,onChange:e}),r=t!==void 0,a=r?t:o;{const c=V.useRef(t!==void 0);V.useEffect(()=>{const I=c.current;I!==r&&console.warn(`${i} is changing from ${I?"controlled":"uncontrolled"} to ${r?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),c.current=r},[r,i])}const g=V.useCallback(c=>{if(r){const I=OGt(c)?c(t):c;I!==t&&s.current?.(I)}else n(c)},[r,t,n,s]);return[a,g]}function qGt({defaultProp:t,onChange:A}){const[e,i]=V.useState(t),o=V.useRef(e),n=V.useRef(A);return PGt(()=>{n.current=A},[A]),V.useEffect(()=>{o.current!==e&&(n.current?.(e),o.current=e)},[e,o]),[e,i,n]}function OGt(t){return typeof t=="function"}function hZ(t){const A=WGt(t),e=V.forwardRef((i,o)=>{const{children:n,...s}=i,r=V.Children.toArray(n),a=r.find(VGt);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:o,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:o,children:n})});return e.displayName=`${t}.Slot`,e}function WGt(t){const A=V.forwardRef((e,i)=>{const{children:o,...n}=e;if(V.isValidElement(o)){const s=zGt(o),r=jGt(n,o.props);return o.type!==V.Fragment&&(r.ref=i?QZ(i,s):s),V.cloneElement(o,r)}return V.Children.count(o)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var ZGt=Symbol("radix.slottable");function VGt(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===ZGt}function jGt(t,A){const e={...A};for(const i in A){const o=t[i],n=A[i];/^on[A-Z]/.test(i)?o&&n?e[i]=(...r)=>{const a=n(...r);return o(...r),a}:o&&(e[i]=o):i==="style"?e[i]={...o,...n}:i==="className"&&(e[i]=[o,n].filter(Boolean).join(" "))}return{...t,...e}}function zGt(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var XGt=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Zd=XGt.reduce((t,A)=>{const e=hZ(`Primitive.${A}`),i=V.forwardRef((o,n)=>{const{asChild:s,...r}=o,a=s?e:A;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),W.jsx(a,{...r,ref:n})});return i.displayName=`Primitive.${A}`,{...t,[A]:i}},{});function Q$A(t,A){t&&jL.flushSync(()=>t.dispatchEvent(A))}function h$A(t){const A=t+"CollectionProvider",[e,i]=ZH(A),[o,n]=e(A,{collectionRef:{current:null},itemMap:new Map}),s=Q=>{const{scope:h,children:E}=Q,u=no.useRef(null),d=no.useRef(new Map).current;return W.jsx(o,{scope:h,itemMap:d,collectionRef:u,children:E})};s.displayName=A;const r=t+"CollectionSlot",a=hZ(r),g=no.forwardRef((Q,h)=>{const{scope:E,children:u}=Q,d=n(r,E),f=ff(h,d.collectionRef);return W.jsx(a,{ref:f,children:u})});g.displayName=r;const c=t+"CollectionItemSlot",I="data-radix-collection-item",l=hZ(c),B=no.forwardRef((Q,h)=>{const{scope:E,children:u,...d}=Q,f=no.useRef(null),m=ff(h,f),D=n(c,E);return no.useEffect(()=>(D.itemMap.set(f,{ref:f,...d}),()=>{D.itemMap.delete(f)})),W.jsx(l,{[I]:"",ref:m,children:u})});B.displayName=c;function C(Q){const h=n(t+"CollectionConsumer",Q);return no.useCallback(()=>{const u=h.collectionRef.current;if(!u)return[];const d=Array.from(u.querySelectorAll(`[${I}]`));return Array.from(h.itemMap.values()).sort((D,w)=>d.indexOf(D.ref.current)-d.indexOf(w.ref.current))},[h.collectionRef,h.itemMap])}return[{Provider:s,Slot:g,ItemSlot:B},C,i]}var $Gt=V.createContext(void 0);function E$A(t){const A=V.useContext($Gt);return t||A||"ltr"}function fD(t){const A=V.useRef(t);return V.useEffect(()=>{A.current=t}),V.useMemo(()=>(...e)=>A.current?.(...e),[])}function ARt(t,A=globalThis?.document){const e=fD(t);V.useEffect(()=>{const i=o=>{o.key==="Escape"&&e(o)};return A.addEventListener("keydown",i,{capture:!0}),()=>A.removeEventListener("keydown",i,{capture:!0})},[e,A])}var eRt="DismissableLayer",euA="dismissableLayer.update",tRt="dismissableLayer.pointerDownOutside",iRt="dismissableLayer.focusOutside",u$A,d$A=V.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),p$A=V.forwardRef((t,A)=>{const{disableOutsidePointerEvents:e=!1,onEscapeKeyDown:i,onPointerDownOutside:o,onFocusOutside:n,onInteractOutside:s,onDismiss:r,...a}=t,g=V.useContext(d$A),[c,I]=V.useState(null),l=c?.ownerDocument??globalThis?.document,[,B]=V.useState({}),C=ff(A,w=>I(w)),Q=Array.from(g.layers),[h]=[...g.layersWithOutsidePointerEventsDisabled].slice(-1),E=Q.indexOf(h),u=c?Q.indexOf(c):-1,d=g.layersWithOutsidePointerEventsDisabled.size>0,f=u>=E,m=sRt(w=>{const b=w.target,k=[...g.branches].some(_=>_.contains(b));!f||k||(o?.(w),s?.(w),w.defaultPrevented||r?.())},l),D=rRt(w=>{const b=w.target;[...g.branches].some(_=>_.contains(b))||(n?.(w),s?.(w),w.defaultPrevented||r?.())},l);return ARt(w=>{u===g.layers.size-1&&(i?.(w),!w.defaultPrevented&&r&&(w.preventDefault(),r()))},l),V.useEffect(()=>{if(c)return e&&(g.layersWithOutsidePointerEventsDisabled.size===0&&(u$A=l.body.style.pointerEvents,l.body.style.pointerEvents="none"),g.layersWithOutsidePointerEventsDisabled.add(c)),g.layers.add(c),f$A(),()=>{e&&g.layersWithOutsidePointerEventsDisabled.size===1&&(l.body.style.pointerEvents=u$A)}},[c,l,e,g]),V.useEffect(()=>()=>{c&&(g.layers.delete(c),g.layersWithOutsidePointerEventsDisabled.delete(c),f$A())},[c,g]),V.useEffect(()=>{const w=()=>B({});return document.addEventListener(euA,w),()=>document.removeEventListener(euA,w)},[]),W.jsx(Zd.div,{...a,ref:C,style:{pointerEvents:d?f?"auto":"none":void 0,...t.style},onFocusCapture:ca(t.onFocusCapture,D.onFocusCapture),onBlurCapture:ca(t.onBlurCapture,D.onBlurCapture),onPointerDownCapture:ca(t.onPointerDownCapture,m.onPointerDownCapture)})});p$A.displayName=eRt;var oRt="DismissableLayerBranch",nRt=V.forwardRef((t,A)=>{const e=V.useContext(d$A),i=V.useRef(null),o=ff(A,i);return V.useEffect(()=>{const n=i.current;if(n)return e.branches.add(n),()=>{e.branches.delete(n)}},[e.branches]),W.jsx(Zd.div,{...t,ref:o})});nRt.displayName=oRt;function sRt(t,A=globalThis?.document){const e=fD(t),i=V.useRef(!1),o=V.useRef(()=>{});return V.useEffect(()=>{const n=r=>{if(r.target&&!i.current){let a=function(){y$A(tRt,e,g,{discrete:!0})};const g={originalEvent:r};r.pointerType==="touch"?(A.removeEventListener("click",o.current),o.current=a,A.addEventListener("click",o.current,{once:!0})):a()}else A.removeEventListener("click",o.current);i.current=!1},s=window.setTimeout(()=>{A.addEventListener("pointerdown",n)},0);return()=>{window.clearTimeout(s),A.removeEventListener("pointerdown",n),A.removeEventListener("click",o.current)}},[A,e]),{onPointerDownCapture:()=>i.current=!0}}function rRt(t,A=globalThis?.document){const e=fD(t),i=V.useRef(!1);return V.useEffect(()=>{const o=n=>{n.target&&!i.current&&y$A(iRt,e,{originalEvent:n},{discrete:!1})};return A.addEventListener("focusin",o),()=>A.removeEventListener("focusin",o)},[A,e]),{onFocusCapture:()=>i.current=!0,onBlurCapture:()=>i.current=!1}}function f$A(){const t=new CustomEvent(euA);document.dispatchEvent(t)}function y$A(t,A,e,{discrete:i}){const o=e.originalEvent.target,n=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:e});A&&o.addEventListener(t,A,{once:!0}),i?Q$A(o,n):o.dispatchEvent(n)}var tuA=0;function aRt(){V.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??m$A()),document.body.insertAdjacentElement("beforeend",t[1]??m$A()),tuA++,()=>{tuA===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(A=>A.remove()),tuA--}},[])}function m$A(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.outline="none",t.style.opacity="0",t.style.position="fixed",t.style.pointerEvents="none",t}var iuA="focusScope.autoFocusOnMount",ouA="focusScope.autoFocusOnUnmount",w$A={bubbles:!1,cancelable:!0},gRt="FocusScope",D$A=V.forwardRef((t,A)=>{const{loop:e=!1,trapped:i=!1,onMountAutoFocus:o,onUnmountAutoFocus:n,...s}=t,[r,a]=V.useState(null),g=fD(o),c=fD(n),I=V.useRef(null),l=ff(A,Q=>a(Q)),B=V.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;V.useEffect(()=>{if(i){let Q=function(d){if(B.paused||!r)return;const f=d.target;r.contains(f)?I.current=f:kx(I.current,{select:!0})},h=function(d){if(B.paused||!r)return;const f=d.relatedTarget;f!==null&&(r.contains(f)||kx(I.current,{select:!0}))},E=function(d){if(document.activeElement===document.body)for(const m of d)m.removedNodes.length>0&&kx(r)};document.addEventListener("focusin",Q),document.addEventListener("focusout",h);const u=new MutationObserver(E);return r&&u.observe(r,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",Q),document.removeEventListener("focusout",h),u.disconnect()}}},[i,r,B.paused]),V.useEffect(()=>{if(r){_$A.add(B);const Q=document.activeElement;if(!r.contains(Q)){const E=new CustomEvent(iuA,w$A);r.addEventListener(iuA,g),r.dispatchEvent(E),E.defaultPrevented||(cRt(QRt(S$A(r)),{select:!0}),document.activeElement===Q&&kx(r))}return()=>{r.removeEventListener(iuA,g),setTimeout(()=>{const E=new CustomEvent(ouA,w$A);r.addEventListener(ouA,c),r.dispatchEvent(E),E.defaultPrevented||kx(Q??document.body,{select:!0}),r.removeEventListener(ouA,c),_$A.remove(B)},0)}}},[r,g,c,B]);const C=V.useCallback(Q=>{if(!e&&!i||B.paused)return;const h=Q.key==="Tab"&&!Q.altKey&&!Q.ctrlKey&&!Q.metaKey,E=document.activeElement;if(h&&E){const u=Q.currentTarget,[d,f]=IRt(u);d&&f?!Q.shiftKey&&E===f?(Q.preventDefault(),e&&kx(d,{select:!0})):Q.shiftKey&&E===d&&(Q.preventDefault(),e&&kx(f,{select:!0})):E===u&&Q.preventDefault()}},[e,i,B.paused]);return W.jsx(Zd.div,{tabIndex:-1,...s,ref:l,onKeyDown:C})});D$A.displayName=gRt;function cRt(t,{select:A=!1}={}){const e=document.activeElement;for(const i of t)if(kx(i,{select:A}),document.activeElement!==e)return}function IRt(t){const A=S$A(t),e=b$A(A,t),i=b$A(A.reverse(),t);return[e,i]}function S$A(t){const A=[],e=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:i=>{const o=i.tagName==="INPUT"&&i.type==="hidden";return i.disabled||i.hidden||o?NodeFilter.FILTER_SKIP:i.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;e.nextNode();)A.push(e.currentNode);return A}function b$A(t,A){for(const e of t)if(!lRt(e,{upTo:A}))return e}function lRt(t,{upTo:A}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(A!==void 0&&t===A)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function BRt(t){return t instanceof HTMLInputElement&&"select"in t}function kx(t,{select:A=!1}={}){if(t&&t.focus){const e=document.activeElement;t.focus({preventScroll:!0}),t!==e&&BRt(t)&&A&&t.select()}}var _$A=CRt();function CRt(){let t=[];return{add(A){const e=t[0];A!==e&&e?.pause(),t=x$A(t,A),t.unshift(A)},remove(A){t=x$A(t,A),t[0]?.resume()}}}function x$A(t,A){const e=[...t],i=e.indexOf(A);return i!==-1&&e.splice(i,1),e}function QRt(t){return t.filter(A=>A.tagName!=="A")}var hRt=k2[" useId ".trim().toString()]||(()=>{}),ERt=0;function VH(t){const[A,e]=V.useState(hRt());return xx(()=>{e(i=>i??String(ERt++))},[t]),A?`radix-${A}`:""}var uRt=["top","right","bottom","left"],Fx=Math.min,F0=Math.max,EZ=Math.round,uZ=Math.floor,yD=t=>({x:t,y:t}),dRt={left:"right",right:"left",bottom:"top",top:"bottom"},pRt={start:"end",end:"start"};function nuA(t,A,e){return F0(t,Fx(A,e))}function Cb(t,A){return typeof t=="function"?t(A):t}function Qb(t){return t.split("-")[0]}function DN(t){return t.split("-")[1]}function suA(t){return t==="x"?"y":"x"}function ruA(t){return t==="y"?"height":"width"}var fRt=new Set(["top","bottom"]);function mD(t){return fRt.has(Qb(t))?"y":"x"}function auA(t){return suA(mD(t))}function yRt(t,A,e){e===void 0&&(e=!1);const i=DN(t),o=auA(t),n=ruA(o);let s=o==="x"?i===(e?"end":"start")?"right":"left":i==="start"?"bottom":"top";return A.reference[n]>A.floating[n]&&(s=dZ(s)),[s,dZ(s)]}function mRt(t){const A=dZ(t);return[guA(t),A,guA(A)]}function guA(t){return t.replace(/start|end/g,A=>pRt[A])}var k$A=["left","right"],F$A=["right","left"],wRt=["top","bottom"],DRt=["bottom","top"];function SRt(t,A,e){switch(t){case"top":case"bottom":return e?A?F$A:k$A:A?k$A:F$A;case"left":case"right":return A?wRt:DRt;default:return[]}}function bRt(t,A,e,i){const o=DN(t);let n=SRt(Qb(t),e==="start",i);return o&&(n=n.map(s=>s+"-"+o),A&&(n=n.concat(n.map(guA)))),n}function dZ(t){return t.replace(/left|right|bottom|top/g,A=>dRt[A])}function _Rt(t){return{top:0,right:0,bottom:0,left:0,...t}}function G$A(t){return typeof t!="number"?_Rt(t):{top:t,right:t,bottom:t,left:t}}function pZ(t){const{x:A,y:e,width:i,height:o}=t;return{width:i,height:o,top:e,left:A,right:A+i,bottom:e+o,x:A,y:e}}function R$A(t,A,e){let{reference:i,floating:o}=t;const n=mD(A),s=auA(A),r=ruA(s),a=Qb(A),g=n==="y",c=i.x+i.width/2-o.width/2,I=i.y+i.height/2-o.height/2,l=i[r]/2-o[r]/2;let B;switch(a){case"top":B={x:c,y:i.y-o.height};break;case"bottom":B={x:c,y:i.y+i.height};break;case"right":B={x:i.x+i.width,y:I};break;case"left":B={x:i.x-o.width,y:I};break;default:B={x:i.x,y:i.y}}switch(DN(A)){case"start":B[s]-=l*(e&&g?-1:1);break;case"end":B[s]+=l*(e&&g?-1:1);break}return B}async function xRt(t,A){var e;A===void 0&&(A={});const{x:i,y:o,platform:n,rects:s,elements:r,strategy:a}=t,{boundary:g="clippingAncestors",rootBoundary:c="viewport",elementContext:I="floating",altBoundary:l=!1,padding:B=0}=Cb(A,t),C=G$A(B),h=r[l?I==="floating"?"reference":"floating":I],E=pZ(await n.getClippingRect({element:(e=await(n.isElement==null?void 0:n.isElement(h)))==null||e?h:h.contextElement||await(n.getDocumentElement==null?void 0:n.getDocumentElement(r.floating)),boundary:g,rootBoundary:c,strategy:a})),u=I==="floating"?{x:i,y:o,width:s.floating.width,height:s.floating.height}:s.reference,d=await(n.getOffsetParent==null?void 0:n.getOffsetParent(r.floating)),f=await(n.isElement==null?void 0:n.isElement(d))?await(n.getScale==null?void 0:n.getScale(d))||{x:1,y:1}:{x:1,y:1},m=pZ(n.convertOffsetParentRelativeRectToViewportRelativeRect?await n.convertOffsetParentRelativeRectToViewportRelativeRect({elements:r,rect:u,offsetParent:d,strategy:a}):u);return{top:(E.top-m.top+C.top)/f.y,bottom:(m.bottom-E.bottom+C.bottom)/f.y,left:(E.left-m.left+C.left)/f.x,right:(m.right-E.right+C.right)/f.x}}var kRt=async(t,A,e)=>{const{placement:i="bottom",strategy:o="absolute",middleware:n=[],platform:s}=e,r=n.filter(Boolean),a=await(s.isRTL==null?void 0:s.isRTL(A));let g=await s.getElementRects({reference:t,floating:A,strategy:o}),{x:c,y:I}=R$A(g,i,a),l=i,B={},C=0;for(let h=0;h<r.length;h++){var Q;const{name:E,fn:u}=r[h],{x:d,y:f,data:m,reset:D}=await u({x:c,y:I,initialPlacement:i,placement:l,strategy:o,middlewareData:B,rects:g,platform:{...s,detectOverflow:(Q=s.detectOverflow)!=null?Q:xRt},elements:{reference:t,floating:A}});c=d??c,I=f??I,B={...B,[E]:{...B[E],...m}},D&&C<=50&&(C++,typeof D=="object"&&(D.placement&&(l=D.placement),D.rects&&(g=D.rects===!0?await s.getElementRects({reference:t,floating:A,strategy:o}):D.rects),{x:c,y:I}=R$A(g,l,a)),h=-1)}return{x:c,y:I,placement:l,strategy:o,middlewareData:B}},FRt=t=>({name:"arrow",options:t,async fn(A){const{x:e,y:i,placement:o,rects:n,platform:s,elements:r,middlewareData:a}=A,{element:g,padding:c=0}=Cb(t,A)||{};if(g==null)return{};const I=G$A(c),l={x:e,y:i},B=auA(o),C=ruA(B),Q=await s.getDimensions(g),h=B==="y",E=h?"top":"left",u=h?"bottom":"right",d=h?"clientHeight":"clientWidth",f=n.reference[C]+n.reference[B]-l[B]-n.floating[C],m=l[B]-n.reference[B],D=await(s.getOffsetParent==null?void 0:s.getOffsetParent(g));let w=D?D[d]:0;(!w||!await(s.isElement==null?void 0:s.isElement(D)))&&(w=r.floating[d]||n.floating[C]);const b=f/2-m/2,k=w/2-Q[C]/2-1,_=Fx(I[E],k),M=Fx(I[u],k),v=_,U=w-Q[C]-M,J=w/2-Q[C]/2+b,Y=nuA(v,J,U),O=!a.arrow&&DN(o)!=null&&J!==Y&&n.reference[C]/2-(J<v?_:M)-Q[C]/2<0,Z=O?J<v?J-v:J-U:0;return{[B]:l[B]+Z,data:{[B]:Y,centerOffset:J-Y-Z,...O&&{alignmentOffset:Z}},reset:O}}}),GRt=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(A){var e,i;const{placement:o,middlewareData:n,rects:s,initialPlacement:r,platform:a,elements:g}=A,{mainAxis:c=!0,crossAxis:I=!0,fallbackPlacements:l,fallbackStrategy:B="bestFit",fallbackAxisSideDirection:C="none",flipAlignment:Q=!0,...h}=Cb(t,A);if((e=n.arrow)!=null&&e.alignmentOffset)return{};const E=Qb(o),u=mD(r),d=Qb(r)===r,f=await(a.isRTL==null?void 0:a.isRTL(g.floating)),m=l||(d||!Q?[dZ(r)]:mRt(r)),D=C!=="none";!l&&D&&m.push(...bRt(r,Q,C,f));const w=[r,...m],b=await a.detectOverflow(A,h),k=[];let _=((i=n.flip)==null?void 0:i.overflows)||[];if(c&&k.push(b[E]),I){const J=yRt(o,s,f);k.push(b[J[0]],b[J[1]])}if(_=[..._,{placement:o,overflows:k}],!k.every(J=>J<=0)){var M,v;const J=(((M=n.flip)==null?void 0:M.index)||0)+1,Y=w[J];if(Y&&(!(I==="alignment"?u!==mD(Y):!1)||_.every($=>mD($.placement)===u?$.overflows[0]>0:!0)))return{data:{index:J,overflows:_},reset:{placement:Y}};let O=(v=_.filter(Z=>Z.overflows[0]<=0).sort((Z,$)=>Z.overflows[1]-$.overflows[1])[0])==null?void 0:v.placement;if(!O)switch(B){case"bestFit":{var U;const Z=(U=_.filter($=>{if(D){const iA=mD($.placement);return iA===u||iA==="y"}return!0}).map($=>[$.placement,$.overflows.filter(iA=>iA>0).reduce((iA,aA)=>iA+aA,0)]).sort(($,iA)=>$[1]-iA[1])[0])==null?void 0:U[0];Z&&(O=Z);break}case"initialPlacement":O=r;break}if(o!==O)return{reset:{placement:O}}}return{}}}};function v$A(t,A){return{top:t.top-A.height,right:t.right-A.width,bottom:t.bottom-A.height,left:t.left-A.width}}function M$A(t){return uRt.some(A=>t[A]>=0)}var RRt=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(A){const{rects:e,platform:i}=A,{strategy:o="referenceHidden",...n}=Cb(t,A);switch(o){case"referenceHidden":{const s=await i.detectOverflow(A,{...n,elementContext:"reference"}),r=v$A(s,e.reference);return{data:{referenceHiddenOffsets:r,referenceHidden:M$A(r)}}}case"escaped":{const s=await i.detectOverflow(A,{...n,altBoundary:!0}),r=v$A(s,e.floating);return{data:{escapedOffsets:r,escaped:M$A(r)}}}default:return{}}}}},N$A=new Set(["left","top"]);async function vRt(t,A){const{placement:e,platform:i,elements:o}=t,n=await(i.isRTL==null?void 0:i.isRTL(o.floating)),s=Qb(e),r=DN(e),a=mD(e)==="y",g=N$A.has(s)?-1:1,c=n&&a?-1:1,I=Cb(A,t);let{mainAxis:l,crossAxis:B,alignmentAxis:C}=typeof I=="number"?{mainAxis:I,crossAxis:0,alignmentAxis:null}:{mainAxis:I.mainAxis||0,crossAxis:I.crossAxis||0,alignmentAxis:I.alignmentAxis};return r&&typeof C=="number"&&(B=r==="end"?C*-1:C),a?{x:B*c,y:l*g}:{x:l*g,y:B*c}}var MRt=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(A){var e,i;const{x:o,y:n,placement:s,middlewareData:r}=A,a=await vRt(A,t);return s===((e=r.offset)==null?void 0:e.placement)&&(i=r.arrow)!=null&&i.alignmentOffset?{}:{x:o+a.x,y:n+a.y,data:{...a,placement:s}}}}},NRt=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(A){const{x:e,y:i,placement:o,platform:n}=A,{mainAxis:s=!0,crossAxis:r=!1,limiter:a={fn:E=>{let{x:u,y:d}=E;return{x:u,y:d}}},...g}=Cb(t,A),c={x:e,y:i},I=await n.detectOverflow(A,g),l=mD(Qb(o)),B=suA(l);let C=c[B],Q=c[l];if(s){const E=B==="y"?"top":"left",u=B==="y"?"bottom":"right",d=C+I[E],f=C-I[u];C=nuA(d,C,f)}if(r){const E=l==="y"?"top":"left",u=l==="y"?"bottom":"right",d=Q+I[E],f=Q-I[u];Q=nuA(d,Q,f)}const h=a.fn({...A,[B]:C,[l]:Q});return{...h,data:{x:h.x-e,y:h.y-i,enabled:{[B]:s,[l]:r}}}}}},LRt=function(t){return t===void 0&&(t={}),{options:t,fn(A){const{x:e,y:i,placement:o,rects:n,middlewareData:s}=A,{offset:r=0,mainAxis:a=!0,crossAxis:g=!0}=Cb(t,A),c={x:e,y:i},I=mD(o),l=suA(I);let B=c[l],C=c[I];const Q=Cb(r,A),h=typeof Q=="number"?{mainAxis:Q,crossAxis:0}:{mainAxis:0,crossAxis:0,...Q};if(a){const d=l==="y"?"height":"width",f=n.reference[l]-n.floating[d]+h.mainAxis,m=n.reference[l]+n.reference[d]-h.mainAxis;B<f?B=f:B>m&&(B=m)}if(g){var E,u;const d=l==="y"?"width":"height",f=N$A.has(Qb(o)),m=n.reference[I]-n.floating[d]+(f&&((E=s.offset)==null?void 0:E[I])||0)+(f?0:h.crossAxis),D=n.reference[I]+n.reference[d]+(f?0:((u=s.offset)==null?void 0:u[I])||0)-(f?h.crossAxis:0);C<m?C=m:C>D&&(C=D)}return{[l]:B,[I]:C}}}},URt=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(A){var e,i;const{placement:o,rects:n,platform:s,elements:r}=A,{apply:a=()=>{},...g}=Cb(t,A),c=await s.detectOverflow(A,g),I=Qb(o),l=DN(o),B=mD(o)==="y",{width:C,height:Q}=n.floating;let h,E;I==="top"||I==="bottom"?(h=I,E=l===(await(s.isRTL==null?void 0:s.isRTL(r.floating))?"start":"end")?"left":"right"):(E=I,h=l==="end"?"top":"bottom");const u=Q-c.top-c.bottom,d=C-c.left-c.right,f=Fx(Q-c[h],u),m=Fx(C-c[E],d),D=!A.middlewareData.shift;let w=f,b=m;if((e=A.middlewareData.shift)!=null&&e.enabled.x&&(b=d),(i=A.middlewareData.shift)!=null&&i.enabled.y&&(w=u),D&&!l){const _=F0(c.left,0),M=F0(c.right,0),v=F0(c.top,0),U=F0(c.bottom,0);B?b=C-2*(_!==0||M!==0?_+M:F0(c.left,c.right)):w=Q-2*(v!==0||U!==0?v+U:F0(c.top,c.bottom))}await a({...A,availableWidth:b,availableHeight:w});const k=await s.getDimensions(r.floating);return C!==k.width||Q!==k.height?{reset:{rects:!0}}:{}}}};function fZ(){return typeof window<"u"}function SN(t){return L$A(t)?(t.nodeName||"").toLowerCase():"#document"}function G0(t){var A;return(t==null||(A=t.ownerDocument)==null?void 0:A.defaultView)||window}function wD(t){var A;return(A=(L$A(t)?t.ownerDocument:t.document)||window.document)==null?void 0:A.documentElement}function L$A(t){return fZ()?t instanceof Node||t instanceof G0(t).Node:!1}function gw(t){return fZ()?t instanceof Element||t instanceof G0(t).Element:!1}function DD(t){return fZ()?t instanceof HTMLElement||t instanceof G0(t).HTMLElement:!1}function U$A(t){return!fZ()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof G0(t).ShadowRoot}var HRt=new Set(["inline","contents"]);function jH(t){const{overflow:A,overflowX:e,overflowY:i,display:o}=cw(t);return/auto|scroll|overlay|hidden|clip/.test(A+i+e)&&!HRt.has(o)}var YRt=new Set(["table","td","th"]);function JRt(t){return YRt.has(SN(t))}var TRt=[":popover-open",":modal"];function yZ(t){return TRt.some(A=>{try{return t.matches(A)}catch{return!1}})}var KRt=["transform","translate","scale","rotate","perspective"],PRt=["transform","translate","scale","rotate","perspective","filter"],qRt=["paint","layout","strict","content"];function cuA(t){const A=IuA(),e=gw(t)?cw(t):t;return KRt.some(i=>e[i]?e[i]!=="none":!1)||(e.containerType?e.containerType!=="normal":!1)||!A&&(e.backdropFilter?e.backdropFilter!=="none":!1)||!A&&(e.filter?e.filter!=="none":!1)||PRt.some(i=>(e.willChange||"").includes(i))||qRt.some(i=>(e.contain||"").includes(i))}function ORt(t){let A=Gx(t);for(;DD(A)&&!bN(A);){if(cuA(A))return A;if(yZ(A))return null;A=Gx(A)}return null}function IuA(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var WRt=new Set(["html","body","#document"]);function bN(t){return WRt.has(SN(t))}function cw(t){return G0(t).getComputedStyle(t)}function mZ(t){return gw(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function Gx(t){if(SN(t)==="html")return t;const A=t.assignedSlot||t.parentNode||U$A(t)&&t.host||wD(t);return U$A(A)?A.host:A}function H$A(t){const A=Gx(t);return bN(A)?t.ownerDocument?t.ownerDocument.body:t.body:DD(A)&&jH(A)?A:H$A(A)}function zH(t,A,e){var i;A===void 0&&(A=[]),e===void 0&&(e=!0);const o=H$A(t),n=o===((i=t.ownerDocument)==null?void 0:i.body),s=G0(o);if(n){const r=luA(s);return A.concat(s,s.visualViewport||[],jH(o)?o:[],r&&e?zH(r):[])}return A.concat(o,zH(o,[],e))}function luA(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Y$A(t){const A=cw(t);let e=parseFloat(A.width)||0,i=parseFloat(A.height)||0;const o=DD(t),n=o?t.offsetWidth:e,s=o?t.offsetHeight:i,r=EZ(e)!==n||EZ(i)!==s;return r&&(e=n,i=s),{width:e,height:i,$:r}}function BuA(t){return gw(t)?t:t.contextElement}function _N(t){const A=BuA(t);if(!DD(A))return yD(1);const e=A.getBoundingClientRect(),{width:i,height:o,$:n}=Y$A(A);let s=(n?EZ(e.width):e.width)/i,r=(n?EZ(e.height):e.height)/o;return(!s||!Number.isFinite(s))&&(s=1),(!r||!Number.isFinite(r))&&(r=1),{x:s,y:r}}var ZRt=yD(0);function J$A(t){const A=G0(t);return!IuA()||!A.visualViewport?ZRt:{x:A.visualViewport.offsetLeft,y:A.visualViewport.offsetTop}}function VRt(t,A,e){return A===void 0&&(A=!1),!e||A&&e!==G0(t)?!1:A}function IG(t,A,e,i){A===void 0&&(A=!1),e===void 0&&(e=!1);const o=t.getBoundingClientRect(),n=BuA(t);let s=yD(1);A&&(i?gw(i)&&(s=_N(i)):s=_N(t));const r=VRt(n,e,i)?J$A(n):yD(0);let a=(o.left+r.x)/s.x,g=(o.top+r.y)/s.y,c=o.width/s.x,I=o.height/s.y;if(n){const l=G0(n),B=i&&gw(i)?G0(i):i;let C=l,Q=luA(C);for(;Q&&i&&B!==C;){const h=_N(Q),E=Q.getBoundingClientRect(),u=cw(Q),d=E.left+(Q.clientLeft+parseFloat(u.paddingLeft))*h.x,f=E.top+(Q.clientTop+parseFloat(u.paddingTop))*h.y;a*=h.x,g*=h.y,c*=h.x,I*=h.y,a+=d,g+=f,C=G0(Q),Q=luA(C)}}return pZ({width:c,height:I,x:a,y:g})}function wZ(t,A){const e=mZ(t).scrollLeft;return A?A.left+e:IG(wD(t)).left+e}function T$A(t,A){const e=t.getBoundingClientRect(),i=e.left+A.scrollLeft-wZ(t,e),o=e.top+A.scrollTop;return{x:i,y:o}}function jRt(t){let{elements:A,rect:e,offsetParent:i,strategy:o}=t;const n=o==="fixed",s=wD(i),r=A?yZ(A.floating):!1;if(i===s||r&&n)return e;let a={scrollLeft:0,scrollTop:0},g=yD(1);const c=yD(0),I=DD(i);if((I||!I&&!n)&&((SN(i)!=="body"||jH(s))&&(a=mZ(i)),DD(i))){const B=IG(i);g=_N(i),c.x=B.x+i.clientLeft,c.y=B.y+i.clientTop}const l=s&&!I&&!n?T$A(s,a):yD(0);return{width:e.width*g.x,height:e.height*g.y,x:e.x*g.x-a.scrollLeft*g.x+c.x+l.x,y:e.y*g.y-a.scrollTop*g.y+c.y+l.y}}function zRt(t){return Array.from(t.getClientRects())}function XRt(t){const A=wD(t),e=mZ(t),i=t.ownerDocument.body,o=F0(A.scrollWidth,A.clientWidth,i.scrollWidth,i.clientWidth),n=F0(A.scrollHeight,A.clientHeight,i.scrollHeight,i.clientHeight);let s=-e.scrollLeft+wZ(t);const r=-e.scrollTop;return cw(i).direction==="rtl"&&(s+=F0(A.clientWidth,i.clientWidth)-o),{width:o,height:n,x:s,y:r}}var K$A=25;function $Rt(t,A){const e=G0(t),i=wD(t),o=e.visualViewport;let n=i.clientWidth,s=i.clientHeight,r=0,a=0;if(o){n=o.width,s=o.height;const c=IuA();(!c||c&&A==="fixed")&&(r=o.offsetLeft,a=o.offsetTop)}const g=wZ(i);if(g<=0){const c=i.ownerDocument,I=c.body,l=getComputedStyle(I),B=c.compatMode==="CSS1Compat"&&parseFloat(l.marginLeft)+parseFloat(l.marginRight)||0,C=Math.abs(i.clientWidth-I.clientWidth-B);C<=K$A&&(n-=C)}else g<=K$A&&(n+=g);return{width:n,height:s,x:r,y:a}}var Avt=new Set(["absolute","fixed"]);function evt(t,A){const e=IG(t,!0,A==="fixed"),i=e.top+t.clientTop,o=e.left+t.clientLeft,n=DD(t)?_N(t):yD(1),s=t.clientWidth*n.x,r=t.clientHeight*n.y,a=o*n.x,g=i*n.y;return{width:s,height:r,x:a,y:g}}function P$A(t,A,e){let i;if(A==="viewport")i=$Rt(t,e);else if(A==="document")i=XRt(wD(t));else if(gw(A))i=evt(A,e);else{const o=J$A(t);i={x:A.x-o.x,y:A.y-o.y,width:A.width,height:A.height}}return pZ(i)}function q$A(t,A){const e=Gx(t);return e===A||!gw(e)||bN(e)?!1:cw(e).position==="fixed"||q$A(e,A)}function tvt(t,A){const e=A.get(t);if(e)return e;let i=zH(t,[],!1).filter(r=>gw(r)&&SN(r)!=="body"),o=null;const n=cw(t).position==="fixed";let s=n?Gx(t):t;for(;gw(s)&&!bN(s);){const r=cw(s),a=cuA(s);!a&&r.position==="fixed"&&(o=null),(n?!a&&!o:!a&&r.position==="static"&&!!o&&Avt.has(o.position)||jH(s)&&!a&&q$A(t,s))?i=i.filter(c=>c!==s):o=r,s=Gx(s)}return A.set(t,i),i}function ivt(t){let{element:A,boundary:e,rootBoundary:i,strategy:o}=t;const s=[...e==="clippingAncestors"?yZ(A)?[]:tvt(A,this._c):[].concat(e),i],r=s[0],a=s.reduce((g,c)=>{const I=P$A(A,c,o);return g.top=F0(I.top,g.top),g.right=Fx(I.right,g.right),g.bottom=Fx(I.bottom,g.bottom),g.left=F0(I.left,g.left),g},P$A(A,r,o));return{width:a.right-a.left,height:a.bottom-a.top,x:a.left,y:a.top}}function ovt(t){const{width:A,height:e}=Y$A(t);return{width:A,height:e}}function nvt(t,A,e){const i=DD(A),o=wD(A),n=e==="fixed",s=IG(t,!0,n,A);let r={scrollLeft:0,scrollTop:0};const a=yD(0);function g(){a.x=wZ(o)}if(i||!i&&!n)if((SN(A)!=="body"||jH(o))&&(r=mZ(A)),i){const B=IG(A,!0,n,A);a.x=B.x+A.clientLeft,a.y=B.y+A.clientTop}else o&&g();n&&!i&&o&&g();const c=o&&!i&&!n?T$A(o,r):yD(0),I=s.left+r.scrollLeft-a.x-c.x,l=s.top+r.scrollTop-a.y-c.y;return{x:I,y:l,width:s.width,height:s.height}}function CuA(t){return cw(t).position==="static"}function O$A(t,A){if(!DD(t)||cw(t).position==="fixed")return null;if(A)return A(t);let e=t.offsetParent;return wD(t)===e&&(e=e.ownerDocument.body),e}function W$A(t,A){const e=G0(t);if(yZ(t))return e;if(!DD(t)){let o=Gx(t);for(;o&&!bN(o);){if(gw(o)&&!CuA(o))return o;o=Gx(o)}return e}let i=O$A(t,A);for(;i&&JRt(i)&&CuA(i);)i=O$A(i,A);return i&&bN(i)&&CuA(i)&&!cuA(i)?e:i||ORt(t)||e}var svt=async function(t){const A=this.getOffsetParent||W$A,e=this.getDimensions,i=await e(t.floating);return{reference:nvt(t.reference,await A(t.floating),t.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}};function rvt(t){return cw(t).direction==="rtl"}var avt={convertOffsetParentRelativeRectToViewportRelativeRect:jRt,getDocumentElement:wD,getClippingRect:ivt,getOffsetParent:W$A,getElementRects:svt,getClientRects:zRt,getDimensions:ovt,getScale:_N,isElement:gw,isRTL:rvt};function Z$A(t,A){return t.x===A.x&&t.y===A.y&&t.width===A.width&&t.height===A.height}function gvt(t,A){let e=null,i;const o=wD(t);function n(){var r;clearTimeout(i),(r=e)==null||r.disconnect(),e=null}function s(r,a){r===void 0&&(r=!1),a===void 0&&(a=1),n();const g=t.getBoundingClientRect(),{left:c,top:I,width:l,height:B}=g;if(r||A(),!l||!B)return;const C=uZ(I),Q=uZ(o.clientWidth-(c+l)),h=uZ(o.clientHeight-(I+B)),E=uZ(c),d={rootMargin:-C+"px "+-Q+"px "+-h+"px "+-E+"px",threshold:F0(0,Fx(1,a))||1};let f=!0;function m(D){const w=D[0].intersectionRatio;if(w!==a){if(!f)return s();w?s(!1,w):i=setTimeout(()=>{s(!1,1e-7)},1e3)}w===1&&!Z$A(g,t.getBoundingClientRect())&&s(),f=!1}try{e=new IntersectionObserver(m,{...d,root:o.ownerDocument})}catch{e=new IntersectionObserver(m,d)}e.observe(t)}return s(!0),n}function cvt(t,A,e,i){i===void 0&&(i={});const{ancestorScroll:o=!0,ancestorResize:n=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:r=typeof IntersectionObserver=="function",animationFrame:a=!1}=i,g=BuA(t),c=o||n?[...g?zH(g):[],...zH(A)]:[];c.forEach(E=>{o&&E.addEventListener("scroll",e,{passive:!0}),n&&E.addEventListener("resize",e)});const I=g&&r?gvt(g,e):null;let l=-1,B=null;s&&(B=new ResizeObserver(E=>{let[u]=E;u&&u.target===g&&B&&(B.unobserve(A),cancelAnimationFrame(l),l=requestAnimationFrame(()=>{var d;(d=B)==null||d.observe(A)})),e()}),g&&!a&&B.observe(g),B.observe(A));let C,Q=a?IG(t):null;a&&h();function h(){const E=IG(t);Q&&!Z$A(Q,E)&&e(),Q=E,C=requestAnimationFrame(h)}return e(),()=>{var E;c.forEach(u=>{o&&u.removeEventListener("scroll",e),n&&u.removeEventListener("resize",e)}),I?.(),(E=B)==null||E.disconnect(),B=null,a&&cancelAnimationFrame(C)}}var Ivt=MRt,lvt=NRt,Bvt=GRt,Cvt=URt,Qvt=RRt,V$A=FRt,hvt=LRt,Evt=(t,A,e)=>{const i=new Map,o={platform:avt,...e},n={...o.platform,_c:i};return kRt(t,A,{...o,platform:n})},uvt=typeof document<"u",dvt=function(){},DZ=uvt?V.useLayoutEffect:dvt;function SZ(t,A){if(t===A)return!0;if(typeof t!=typeof A)return!1;if(typeof t=="function"&&t.toString()===A.toString())return!0;let e,i,o;if(t&&A&&typeof t=="object"){if(Array.isArray(t)){if(e=t.length,e!==A.length)return!1;for(i=e;i--!==0;)if(!SZ(t[i],A[i]))return!1;return!0}if(o=Object.keys(t),e=o.length,e!==Object.keys(A).length)return!1;for(i=e;i--!==0;)if(!{}.hasOwnProperty.call(A,o[i]))return!1;for(i=e;i--!==0;){const n=o[i];if(!(n==="_owner"&&t.$$typeof)&&!SZ(t[n],A[n]))return!1}return!0}return t!==t&&A!==A}function j$A(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function z$A(t,A){const e=j$A(t);return Math.round(A*e)/e}function QuA(t){const A=V.useRef(t);return DZ(()=>{A.current=t}),A}function pvt(t){t===void 0&&(t={});const{placement:A="bottom",strategy:e="absolute",middleware:i=[],platform:o,elements:{reference:n,floating:s}={},transform:r=!0,whileElementsMounted:a,open:g}=t,[c,I]=V.useState({x:0,y:0,strategy:e,placement:A,middlewareData:{},isPositioned:!1}),[l,B]=V.useState(i);SZ(l,i)||B(i);const[C,Q]=V.useState(null),[h,E]=V.useState(null),u=V.useCallback($=>{$!==D.current&&(D.current=$,Q($))},[]),d=V.useCallback($=>{$!==w.current&&(w.current=$,E($))},[]),f=n||C,m=s||h,D=V.useRef(null),w=V.useRef(null),b=V.useRef(c),k=a!=null,_=QuA(a),M=QuA(o),v=QuA(g),U=V.useCallback(()=>{if(!D.current||!w.current)return;const $={placement:A,strategy:e,middleware:l};M.current&&($.platform=M.current),Evt(D.current,w.current,$).then(iA=>{const aA={...iA,isPositioned:v.current!==!1};J.current&&!SZ(b.current,aA)&&(b.current=aA,jL.flushSync(()=>{I(aA)}))})},[l,A,e,M,v]);DZ(()=>{g===!1&&b.current.isPositioned&&(b.current.isPositioned=!1,I($=>({...$,isPositioned:!1})))},[g]);const J=V.useRef(!1);DZ(()=>(J.current=!0,()=>{J.current=!1}),[]),DZ(()=>{if(f&&(D.current=f),m&&(w.current=m),f&&m){if(_.current)return _.current(f,m,U);U()}},[f,m,U,_,k]);const Y=V.useMemo(()=>({reference:D,floating:w,setReference:u,setFloating:d}),[u,d]),O=V.useMemo(()=>({reference:f,floating:m}),[f,m]),Z=V.useMemo(()=>{const $={position:e,left:0,top:0};if(!O.floating)return $;const iA=z$A(O.floating,c.x),aA=z$A(O.floating,c.y);return r?{...$,transform:"translate("+iA+"px, "+aA+"px)",...j$A(O.floating)>=1.5&&{willChange:"transform"}}:{position:e,left:iA,top:aA}},[e,r,O.floating,c.x,c.y]);return V.useMemo(()=>({...c,update:U,refs:Y,elements:O,floatingStyles:Z}),[c,U,Y,O,Z])}var fvt=t=>{function A(e){return{}.hasOwnProperty.call(e,"current")}return{name:"arrow",options:t,fn(e){const{element:i,padding:o}=typeof t=="function"?t(e):t;return i&&A(i)?i.current!=null?V$A({element:i.current,padding:o}).fn(e):{}:i?V$A({element:i,padding:o}).fn(e):{}}}},yvt=(t,A)=>({...Ivt(t),options:[t,A]}),mvt=(t,A)=>({...lvt(t),options:[t,A]}),wvt=(t,A)=>({...hvt(t),options:[t,A]}),Dvt=(t,A)=>({...Bvt(t),options:[t,A]}),Svt=(t,A)=>({...Cvt(t),options:[t,A]}),bvt=(t,A)=>({...Qvt(t),options:[t,A]}),_vt=(t,A)=>({...fvt(t),options:[t,A]}),xvt="Arrow",X$A=V.forwardRef((t,A)=>{const{children:e,width:i=10,height:o=5,...n}=t;return W.jsx(Zd.svg,{...n,ref:A,width:i,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:t.asChild?e:W.jsx("polygon",{points:"0,0 30,0 15,10"})})});X$A.displayName=xvt;var kvt=X$A;function Fvt(t){const[A,e]=V.useState(void 0);return xx(()=>{if(t){e({width:t.offsetWidth,height:t.offsetHeight});const i=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const n=o[0];let s,r;if("borderBoxSize"in n){const a=n.borderBoxSize,g=Array.isArray(a)?a[0]:a;s=g.inlineSize,r=g.blockSize}else s=t.offsetWidth,r=t.offsetHeight;e({width:s,height:r})});return i.observe(t,{box:"border-box"}),()=>i.unobserve(t)}else e(void 0)},[t]),A}var huA="Popper",[$$A,AAe]=ZH(huA),[Gvt,eAe]=$$A(huA),tAe=t=>{const{__scopePopper:A,children:e}=t,[i,o]=V.useState(null);return W.jsx(Gvt,{scope:A,anchor:i,onAnchorChange:o,children:e})};tAe.displayName=huA;var iAe="PopperAnchor",oAe=V.forwardRef((t,A)=>{const{__scopePopper:e,virtualRef:i,...o}=t,n=eAe(iAe,e),s=V.useRef(null),r=ff(A,s),a=V.useRef(null);return V.useEffect(()=>{const g=a.current;a.current=i?.current||s.current,g!==a.current&&n.onAnchorChange(a.current)}),i?null:W.jsx(Zd.div,{...o,ref:r})});oAe.displayName=iAe;var EuA="PopperContent",[Rvt,vvt]=$$A(EuA),nAe=V.forwardRef((t,A)=>{const{__scopePopper:e,side:i="bottom",sideOffset:o=0,align:n="center",alignOffset:s=0,arrowPadding:r=0,avoidCollisions:a=!0,collisionBoundary:g=[],collisionPadding:c=0,sticky:I="partial",hideWhenDetached:l=!1,updatePositionStrategy:B="optimized",onPlaced:C,...Q}=t,h=eAe(EuA,e),[E,u]=V.useState(null),d=ff(A,GA=>u(GA)),[f,m]=V.useState(null),D=Fvt(f),w=D?.width??0,b=D?.height??0,k=i+(n!=="center"?"-"+n:""),_=typeof c=="number"?c:{top:0,right:0,bottom:0,left:0,...c},M=Array.isArray(g)?g:[g],v=M.length>0,U={padding:_,boundary:M.filter(Nvt),altBoundary:v},{refs:J,floatingStyles:Y,placement:O,isPositioned:Z,middlewareData:$}=pvt({strategy:"fixed",placement:k,whileElementsMounted:(...GA)=>cvt(...GA,{animationFrame:B==="always"}),elements:{reference:h.anchor},middleware:[yvt({mainAxis:o+b,alignmentAxis:s}),a&&mvt({mainAxis:!0,crossAxis:!1,limiter:I==="partial"?wvt():void 0,...U}),a&&Dvt({...U}),Svt({...U,apply:({elements:GA,rects:NA,availableWidth:QA,availableHeight:xA})=>{const{width:uA,height:OA}=NA.reference,PA=GA.floating.style;PA.setProperty("--radix-popper-available-width",`${QA}px`),PA.setProperty("--radix-popper-available-height",`${xA}px`),PA.setProperty("--radix-popper-anchor-width",`${uA}px`),PA.setProperty("--radix-popper-anchor-height",`${OA}px`)}}),f&&_vt({element:f,padding:r}),Lvt({arrowWidth:w,arrowHeight:b}),l&&bvt({strategy:"referenceHidden",...U})]}),[iA,aA]=aAe(O),eA=fD(C);xx(()=>{Z&&eA?.()},[Z,eA]);const oA=$.arrow?.x,rA=$.arrow?.y,lA=$.arrow?.centerOffset!==0,[EA,bA]=V.useState();return xx(()=>{E&&bA(window.getComputedStyle(E).zIndex)},[E]),W.jsx("div",{ref:J.setFloating,"data-radix-popper-content-wrapper":"",style:{...Y,transform:Z?Y.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:EA,"--radix-popper-transform-origin":[$.transformOrigin?.x,$.transformOrigin?.y].join(" "),...$.hide?.referenceHidden&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:W.jsx(Rvt,{scope:e,placedSide:iA,onArrowChange:m,arrowX:oA,arrowY:rA,shouldHideArrow:lA,children:W.jsx(Zd.div,{"data-side":iA,"data-align":aA,...Q,ref:d,style:{...Q.style,animation:Z?void 0:"none"}})})})});nAe.displayName=EuA;var sAe="PopperArrow",Mvt={top:"bottom",right:"left",bottom:"top",left:"right"},rAe=V.forwardRef(function(A,e){const{__scopePopper:i,...o}=A,n=vvt(sAe,i),s=Mvt[n.placedSide];return W.jsx("span",{ref:n.onArrowChange,style:{position:"absolute",left:n.arrowX,top:n.arrowY,[s]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[n.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[n.placedSide],visibility:n.shouldHideArrow?"hidden":void 0},children:W.jsx(kvt,{...o,ref:e,style:{...o.style,display:"block"}})})});rAe.displayName=sAe;function Nvt(t){return t!==null}var Lvt=t=>({name:"transformOrigin",options:t,fn(A){const{placement:e,rects:i,middlewareData:o}=A,s=o.arrow?.centerOffset!==0,r=s?0:t.arrowWidth,a=s?0:t.arrowHeight,[g,c]=aAe(e),I={start:"0%",center:"50%",end:"100%"}[c],l=(o.arrow?.x??0)+r/2,B=(o.arrow?.y??0)+a/2;let C="",Q="";return g==="bottom"?(C=s?I:`${l}px`,Q=`${-a}px`):g==="top"?(C=s?I:`${l}px`,Q=`${i.floating.height+a}px`):g==="right"?(C=`${-a}px`,Q=s?I:`${B}px`):g==="left"&&(C=`${i.floating.width+a}px`,Q=s?I:`${B}px`),{data:{x:C,y:Q}}}});function aAe(t){const[A,e="center"]=t.split("-");return[A,e]}var gAe=tAe,Uvt=oAe,Hvt=nAe,Yvt=rAe,Jvt="Portal",cAe=V.forwardRef((t,A)=>{const{container:e,...i}=t,[o,n]=V.useState(!1);xx(()=>n(!0),[]);const s=e||o&&globalThis?.document?.body;return s?h5.createPortal(W.jsx(Zd.div,{...i,ref:A}),s):null});cAe.displayName=Jvt;function Tvt(t,A){return V.useReducer((e,i)=>A[e][i]??e,t)}var XH=t=>{const{present:A,children:e}=t,i=Kvt(A),o=typeof e=="function"?e({present:i.isPresent}):V.Children.only(e),n=ff(i.ref,Pvt(o));return typeof e=="function"||i.isPresent?V.cloneElement(o,{ref:n}):null};XH.displayName="Presence";function Kvt(t){const[A,e]=V.useState(),i=V.useRef(null),o=V.useRef(t),n=V.useRef("none"),s=t?"mounted":"unmounted",[r,a]=Tvt(s,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return V.useEffect(()=>{const g=bZ(i.current);n.current=r==="mounted"?g:"none"},[r]),xx(()=>{const g=i.current,c=o.current;if(c!==t){const l=n.current,B=bZ(g);t?a("MOUNT"):B==="none"||g?.display==="none"?a("UNMOUNT"):a(c&&l!==B?"ANIMATION_OUT":"UNMOUNT"),o.current=t}},[t,a]),xx(()=>{if(A){let g;const c=A.ownerDocument.defaultView??window,I=B=>{const Q=bZ(i.current).includes(CSS.escape(B.animationName));if(B.target===A&&Q&&(a("ANIMATION_END"),!o.current)){const h=A.style.animationFillMode;A.style.animationFillMode="forwards",g=c.setTimeout(()=>{A.style.animationFillMode==="forwards"&&(A.style.animationFillMode=h)})}},l=B=>{B.target===A&&(n.current=bZ(i.current))};return A.addEventListener("animationstart",l),A.addEventListener("animationcancel",I),A.addEventListener("animationend",I),()=>{c.clearTimeout(g),A.removeEventListener("animationstart",l),A.removeEventListener("animationcancel",I),A.removeEventListener("animationend",I)}}else a("ANIMATION_END")},[A,a]),{isPresent:["mounted","unmountSuspended"].includes(r),ref:V.useCallback(g=>{i.current=g?getComputedStyle(g):null,e(g)},[])}}function bZ(t){return t?.animationName||"none"}function Pvt(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var uuA="rovingFocusGroup.onEntryFocus",qvt={bubbles:!1,cancelable:!0},$H="RovingFocusGroup",[duA,IAe,Ovt]=h$A($H),[Wvt,lAe]=ZH($H,[Ovt]),[Zvt,Vvt]=Wvt($H),BAe=V.forwardRef((t,A)=>W.jsx(duA.Provider,{scope:t.__scopeRovingFocusGroup,children:W.jsx(duA.Slot,{scope:t.__scopeRovingFocusGroup,children:W.jsx(jvt,{...t,ref:A})})}));BAe.displayName=$H;var jvt=V.forwardRef((t,A)=>{const{__scopeRovingFocusGroup:e,orientation:i,loop:o=!1,dir:n,currentTabStopId:s,defaultCurrentTabStopId:r,onCurrentTabStopIdChange:a,onEntryFocus:g,preventScrollOnEntryFocus:c=!1,...I}=t,l=V.useRef(null),B=ff(A,l),C=E$A(n),[Q,h]=AuA({prop:s,defaultProp:r??null,onChange:a,caller:$H}),[E,u]=V.useState(!1),d=fD(g),f=IAe(e),m=V.useRef(!1),[D,w]=V.useState(0);return V.useEffect(()=>{const b=l.current;if(b)return b.addEventListener(uuA,d),()=>b.removeEventListener(uuA,d)},[d]),W.jsx(Zvt,{scope:e,orientation:i,dir:C,loop:o,currentTabStopId:Q,onItemFocus:V.useCallback(b=>h(b),[h]),onItemShiftTab:V.useCallback(()=>u(!0),[]),onFocusableItemAdd:V.useCallback(()=>w(b=>b+1),[]),onFocusableItemRemove:V.useCallback(()=>w(b=>b-1),[]),children:W.jsx(Zd.div,{tabIndex:E||D===0?-1:0,"data-orientation":i,...I,ref:B,style:{outline:"none",...t.style},onMouseDown:ca(t.onMouseDown,()=>{m.current=!0}),onFocus:ca(t.onFocus,b=>{const k=!m.current;if(b.target===b.currentTarget&&k&&!E){const _=new CustomEvent(uuA,qvt);if(b.currentTarget.dispatchEvent(_),!_.defaultPrevented){const M=f().filter(O=>O.focusable),v=M.find(O=>O.active),U=M.find(O=>O.id===Q),Y=[v,U,...M].filter(Boolean).map(O=>O.ref.current);hAe(Y,c)}}m.current=!1}),onBlur:ca(t.onBlur,()=>u(!1))})})}),CAe="RovingFocusGroupItem",QAe=V.forwardRef((t,A)=>{const{__scopeRovingFocusGroup:e,focusable:i=!0,active:o=!1,tabStopId:n,children:s,...r}=t,a=VH(),g=n||a,c=Vvt(CAe,e),I=c.currentTabStopId===g,l=IAe(e),{onFocusableItemAdd:B,onFocusableItemRemove:C,currentTabStopId:Q}=c;return V.useEffect(()=>{if(i)return B(),()=>C()},[i,B,C]),W.jsx(duA.ItemSlot,{scope:e,id:g,focusable:i,active:o,children:W.jsx(Zd.span,{tabIndex:I?0:-1,"data-orientation":c.orientation,...r,ref:A,onMouseDown:ca(t.onMouseDown,h=>{i?c.onItemFocus(g):h.preventDefault()}),onFocus:ca(t.onFocus,()=>c.onItemFocus(g)),onKeyDown:ca(t.onKeyDown,h=>{if(h.key==="Tab"&&h.shiftKey){c.onItemShiftTab();return}if(h.target!==h.currentTarget)return;const E=$vt(h,c.orientation,c.dir);if(E!==void 0){if(h.metaKey||h.ctrlKey||h.altKey||h.shiftKey)return;h.preventDefault();let d=l().filter(f=>f.focusable).map(f=>f.ref.current);if(E==="last")d.reverse();else if(E==="prev"||E==="next"){E==="prev"&&d.reverse();const f=d.indexOf(h.currentTarget);d=c.loop?AMt(d,f+1):d.slice(f+1)}setTimeout(()=>hAe(d))}}),children:typeof s=="function"?s({isCurrentTabStop:I,hasTabStop:Q!=null}):s})})});QAe.displayName=CAe;var zvt={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Xvt(t,A){return A!=="rtl"?t:t==="ArrowLeft"?"ArrowRight":t==="ArrowRight"?"ArrowLeft":t}function $vt(t,A,e){const i=Xvt(t.key,e);if(!(A==="vertical"&&["ArrowLeft","ArrowRight"].includes(i))&&!(A==="horizontal"&&["ArrowUp","ArrowDown"].includes(i)))return zvt[i]}function hAe(t,A=!1){const e=document.activeElement;for(const i of t)if(i===e||(i.focus({preventScroll:A}),document.activeElement!==e))return}function AMt(t,A){return t.map((e,i)=>t[(A+i)%t.length])}var eMt=BAe,tMt=QAe,iMt=function(t){if(typeof document>"u")return null;var A=Array.isArray(t)?t[0]:t;return A.ownerDocument.body},xN=new WeakMap,_Z=new WeakMap,xZ={},puA=0,EAe=function(t){return t&&(t.host||EAe(t.parentNode))},oMt=function(t,A){return A.map(function(e){if(t.contains(e))return e;var i=EAe(e);return i&&t.contains(i)?i:(console.error("aria-hidden",e,"in not contained inside",t,". Doing nothing"),null)}).filter(function(e){return!!e})},nMt=function(t,A,e,i){var o=oMt(A,Array.isArray(t)?t:[t]);xZ[e]||(xZ[e]=new WeakMap);var n=xZ[e],s=[],r=new Set,a=new Set(o),g=function(I){!I||r.has(I)||(r.add(I),g(I.parentNode))};o.forEach(g);var c=function(I){!I||a.has(I)||Array.prototype.forEach.call(I.children,function(l){if(r.has(l))c(l);else try{var B=l.getAttribute(i),C=B!==null&&B!=="false",Q=(xN.get(l)||0)+1,h=(n.get(l)||0)+1;xN.set(l,Q),n.set(l,h),s.push(l),Q===1&&C&&_Z.set(l,!0),h===1&&l.setAttribute(e,"true"),C||l.setAttribute(i,"true")}catch(E){console.error("aria-hidden: cannot operate on ",l,E)}})};return c(A),r.clear(),puA++,function(){s.forEach(function(I){var l=xN.get(I)-1,B=n.get(I)-1;xN.set(I,l),n.set(I,B),l||(_Z.has(I)||I.removeAttribute(i),_Z.delete(I)),B||I.removeAttribute(e)}),puA--,puA||(xN=new WeakMap,xN=new WeakMap,_Z=new WeakMap,xZ={})}},sMt=function(t,A,e){e===void 0&&(e="data-aria-hidden");var i=Array.from(Array.isArray(t)?t:[t]),o=iMt(t);return o?(i.push.apply(i,Array.from(o.querySelectorAll("[aria-live], script"))),nMt(i,o,e,"aria-hidden")):function(){return null}},SD=function(){return SD=Object.assign||function(A){for(var e,i=1,o=arguments.length;i<o;i++){e=arguments[i];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(A[n]=e[n])}return A},SD.apply(this,arguments)};function uAe(t,A){var e={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&A.indexOf(i)<0&&(e[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,i=Object.getOwnPropertySymbols(t);o<i.length;o++)A.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(t,i[o])&&(e[i[o]]=t[i[o]]);return e}function rMt(t,A,e){for(var i=0,o=A.length,n;i<o;i++)(n||!(i in A))&&(n||(n=Array.prototype.slice.call(A,0,i)),n[i]=A[i]);return t.concat(n||Array.prototype.slice.call(A))}var kZ="right-scroll-bar-position",FZ="width-before-scroll-bar",aMt="with-scroll-bars-hidden",gMt="--removed-body-scroll-bar-size";function fuA(t,A){return typeof t=="function"?t(A):t&&(t.current=A),t}function cMt(t,A){var e=V.useState(function(){return{value:t,callback:A,facade:{get current(){return e.value},set current(i){var o=e.value;o!==i&&(e.value=i,e.callback(i,o))}}}})[0];return e.callback=A,e.facade}var IMt=typeof window<"u"?V.useLayoutEffect:V.useEffect,dAe=new WeakMap;function lMt(t,A){var e=cMt(null,function(i){return t.forEach(function(o){return fuA(o,i)})});return IMt(function(){var i=dAe.get(e);if(i){var o=new Set(i),n=new Set(t),s=e.current;o.forEach(function(r){n.has(r)||fuA(r,null)}),n.forEach(function(r){o.has(r)||fuA(r,s)})}dAe.set(e,t)},[t]),e}function BMt(t){return t}function CMt(t,A){A===void 0&&(A=BMt);var e=[],i=!1,o={read:function(){if(i)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return e.length?e[e.length-1]:t},useMedium:function(n){var s=A(n,i);return e.push(s),function(){e=e.filter(function(r){return r!==s})}},assignSyncMedium:function(n){for(i=!0;e.length;){var s=e;e=[],s.forEach(n)}e={push:function(r){return n(r)},filter:function(){return e}}},assignMedium:function(n){i=!0;var s=[];if(e.length){var r=e;e=[],r.forEach(n),s=e}var a=function(){var c=s;s=[],c.forEach(n)},g=function(){return Promise.resolve().then(a)};g(),e={push:function(c){s.push(c),g()},filter:function(c){return s=s.filter(c),e}}}};return o}function QMt(t){t===void 0&&(t={});var A=CMt(null);return A.options=SD({async:!0,ssr:!1},t),A}var pAe=function(t){var A=t.sideCar,e=uAe(t,["sideCar"]);if(!A)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var i=A.read();if(!i)throw new Error("Sidecar medium not found");return V.createElement(i,SD({},e))};pAe.isSideCarExport=!0;function hMt(t,A){return t.useMedium(A),pAe}var fAe=QMt(),yuA=function(){},GZ=V.forwardRef(function(t,A){var e=V.useRef(null),i=V.useState({onScrollCapture:yuA,onWheelCapture:yuA,onTouchMoveCapture:yuA}),o=i[0],n=i[1],s=t.forwardProps,r=t.children,a=t.className,g=t.removeScrollBar,c=t.enabled,I=t.shards,l=t.sideCar,B=t.noRelative,C=t.noIsolation,Q=t.inert,h=t.allowPinchZoom,E=t.as,u=E===void 0?"div":E,d=t.gapMode,f=uAe(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),m=l,D=lMt([e,A]),w=SD(SD({},f),o);return V.createElement(V.Fragment,null,c&&V.createElement(m,{sideCar:fAe,removeScrollBar:g,shards:I,noRelative:B,noIsolation:C,inert:Q,setCallbacks:n,allowPinchZoom:!!h,lockRef:e,gapMode:d}),s?V.cloneElement(V.Children.only(r),SD(SD({},w),{ref:D})):V.createElement(u,SD({},w,{className:a,ref:D}),r))});GZ.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},GZ.classNames={fullWidth:FZ,zeroRight:kZ};var EMt=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function uMt(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var A=EMt();return A&&t.setAttribute("nonce",A),t}function dMt(t,A){t.styleSheet?t.styleSheet.cssText=A:t.appendChild(document.createTextNode(A))}function pMt(t){var A=document.head||document.getElementsByTagName("head")[0];A.appendChild(t)}var fMt=function(){var t=0,A=null;return{add:function(e){t==0&&(A=uMt())&&(dMt(A,e),pMt(A)),t++},remove:function(){t--,!t&&A&&(A.parentNode&&A.parentNode.removeChild(A),A=null)}}},yMt=function(){var t=fMt();return function(A,e){V.useEffect(function(){return t.add(A),function(){t.remove()}},[A&&e])}},yAe=function(){var t=yMt(),A=function(e){var i=e.styles,o=e.dynamic;return t(i,o),null};return A},mMt={left:0,top:0,right:0,gap:0},muA=function(t){return parseInt(t||"",10)||0},wMt=function(t){var A=window.getComputedStyle(document.body),e=A[t==="padding"?"paddingLeft":"marginLeft"],i=A[t==="padding"?"paddingTop":"marginTop"],o=A[t==="padding"?"paddingRight":"marginRight"];return[muA(e),muA(i),muA(o)]},DMt=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return mMt;var A=wMt(t),e=document.documentElement.clientWidth,i=window.innerWidth;return{left:A[0],top:A[1],right:A[2],gap:Math.max(0,i-e+A[2]-A[0])}},SMt=yAe(),kN="data-scroll-locked",bMt=function(t,A,e,i){var o=t.left,n=t.top,s=t.right,r=t.gap;return e===void 0&&(e="margin"),`
|
|
5187
5187
|
.`.concat(aMt,` {
|
|
5188
5188
|
overflow: hidden `).concat(i,`;
|
|
5189
5189
|
padding-right: `).concat(r,"px ").concat(i,`;
|
|
@@ -5686,7 +5686,7 @@ test("${g} should solve problem correctly", () => {
|
|
|
5686
5686
|
// Add more specific assertions based on expected output
|
|
5687
5687
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5688
5688
|
})
|
|
5689
|
-
`,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:o,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:n,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},YIe=t=>t.activeSubSolver?[t,...YIe(t.activeSubSolver)]:[t],mXt=({solver:t})=>{const A=YIe(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(yXt,{solver:e})]},e.constructor.name))})},wXt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,s]=V.useReducer(Q=>!Q,!1),r=V.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),o&&o(t))},c=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&t.solved&&o(t);return}t.step(),A()},e))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||n)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&o&&o(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,n]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(mXt,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:g,disabled:t.solved||t.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:c,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||n,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&W.jsx("button",{onClick:I,disabled:t.solved||t.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},DXt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},SXt=(t,A)=>{const i=t.pipelineDef[A].solverName,o=DXt(t,A),n=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(o==="Completed"){const l=t.pipelineDef[A+1],B=l?t.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else o==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let c=0;o==="Completed"?c=1:o==="In Progress"&&n&&(c=n.progress??0);const I=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:n??null}},bXt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},_Xt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},xXt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),kXt=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=xXt(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,o])=>W.jsxs("div",{children:[i,": ",String(o)]},i))})]})},s0A=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(s0A);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=s0A(i));return A},FXt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=s0A(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},GXt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>SXt(t,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):FXt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>o(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(bXt,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(_Xt,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(kXt,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},RXt=class extends no.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function vXt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],o=t.circles??[],n=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of e){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of o){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of n)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),e.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),o.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),n.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var MXt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[o,n]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,o]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();n()}};return W.jsxs("div",{children:[W.jsx(wXt,{solver:t,triggerRender:n,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(RXt,{fallback:W.jsx(vXt,{graphics:s}),children:W.jsx(fXt,{graphics:s})}),a&&W.jsx(GXt,{solver:t,onStepUntilPhase:g})]})};const NXt=()=>{V.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},LXt=t=>t.toLowerCase().includes("pack")?j1t:t.toLowerCase().includes("rout")?e2t:M1t,UXt=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);NXt();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),o=V.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=V.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=enA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(enA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.map(r=>{const a=i.get(r),g=A===r;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const c=LXt(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:n?s.instance?W.jsx(Oy,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",n.solverName]})]})}),children:W.jsx(MXt,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:n.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.componentName]})]}),s.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(n.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},JIe=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{q5.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{q5.captureException(o,{error_type:i.type})}catch{}}},[e])},TIe="0.0.1539",HXt={version:TIe},ij=LYA()(UYA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),YXt=t=>{const[A,e]=V.useState([]),[i,o]=V.useState(null),[n,s]=V.useState(""),[r,a]=I1("eval-version-selection",null),g=ij(B=>B.setLastRunEvalVersion),c=ij(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(o(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(n)).slice(0,50),[A,n]),latestVersion:i,lastRunEvalVersion:c,search:n,setSearch:s,selectVersion:B=>{a(B),s("")}}},JXt=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[o,n]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?n(a[0]):g&&n(s))};return W.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${o===I?"bg-blue-50":""}`,onClick:()=>n(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${o===s?"bg-blue-50":""}`,onClick:()=>n(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>o&&A(o),disabled:!o,children:o===s?`Create "${o}"`:`Save to ${o}`})]})]})})},TXt=t=>{const A=V.useRef(null),e=jI(i=>i.recentEvents);V.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function KXt(t){const A=PXt(t),e=V.forwardRef((i,o)=>{const{children:n,...s}=i,r=V.Children.toArray(n),a=r.find(OXt);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:o,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:o,children:n})});return e.displayName=`${t}.Slot`,e}function PXt(t){const A=V.forwardRef((e,i)=>{const{children:o,...n}=e;if(V.isValidElement(o)){const s=ZXt(o),r=WXt(n,o.props);return o.type!==V.Fragment&&(r.ref=i?cf(i,s):s),V.cloneElement(o,r)}return V.Children.count(o)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var qXt=Symbol("radix.slottable");function OXt(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===qXt}function WXt(t,A){const e={...A};for(const i in A){const o=t[i],n=A[i];/^on[A-Z]/.test(i)?o&&n?e[i]=(...r)=>{const a=n(...r);return o(...r),a}:o&&(e[i]=o):i==="style"?e[i]={...o,...n}:i==="className"&&(e[i]=[o,n].filter(Boolean).join(" "))}return{...t,...e}}function ZXt(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var oj="Dialog",[KIe,PIe]=Km(oj),[VXt,Ew]=KIe(oj),qIe=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:o,onOpenChange:n,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=q_({prop:i,defaultProp:o??!1,onChange:n,caller:oj});return W.jsx(VXt,{scope:A,triggerRef:r,contentRef:a,contentId:_E(),titleId:_E(),descriptionId:_E(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};qIe.displayName=oj;var OIe="DialogTrigger",WIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(OIe,e),n=yI(A,o.triggerRef);return W.jsx(ja.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":g0A(o.open),...i,ref:n,onClick:To(t.onClick,o.onOpenToggle)})});WIe.displayName=OIe;var r0A="DialogPortal",[jXt,ZIe]=KIe(r0A,{forceMount:void 0}),VIe=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:o}=t,n=Ew(r0A,A);return W.jsx(jXt,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(f0,{present:e||n.open,children:W.jsx(AV,{asChild:!0,container:o,children:s})}))})};VIe.displayName=r0A;var nj="DialogOverlay",jIe=V.forwardRef((t,A)=>{const e=ZIe(nj,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Ew(nj,t.__scopeDialog);return n.modal?W.jsx(f0,{present:i||n.open,children:W.jsx(XXt,{...o,ref:A})}):null});jIe.displayName=nj;var zXt=KXt("DialogOverlay.RemoveScroll"),XXt=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(nj,e);return W.jsx(aV,{as:zXt,allowPinchZoom:!0,shards:[o.contentRef],children:W.jsx(ja.div,{"data-state":g0A(o.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),JG="DialogContent",zIe=V.forwardRef((t,A)=>{const e=ZIe(JG,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Ew(JG,t.__scopeDialog);return W.jsx(f0,{present:i||n.open,children:n.modal?W.jsx($Xt,{...o,ref:A}):W.jsx(A6t,{...o,ref:A})})});zIe.displayName=JG;var $Xt=V.forwardRef((t,A)=>{const e=Ew(JG,t.__scopeDialog),i=V.useRef(null),o=yI(A,e.contentRef,i);return V.useEffect(()=>{const n=i.current;if(n)return rdA(n)},[]),W.jsx(XIe,{...t,ref:o,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:To(t.onCloseAutoFocus,n=>{n.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:To(t.onPointerDownOutside,n=>{const s=n.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&n.preventDefault()}),onFocusOutside:To(t.onFocusOutside,n=>n.preventDefault())})}),A6t=V.forwardRef((t,A)=>{const e=Ew(JG,t.__scopeDialog),i=V.useRef(!1),o=V.useRef(!1);return W.jsx(XIe,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:n=>{t.onCloseAutoFocus?.(n),n.defaultPrevented||(i.current||e.triggerRef.current?.focus(),n.preventDefault()),i.current=!1,o.current=!1},onInteractOutside:n=>{t.onInteractOutside?.(n),n.defaultPrevented||(i.current=!0,n.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const s=n.target;e.triggerRef.current?.contains(s)&&n.preventDefault(),n.detail.originalEvent.type==="focusin"&&o.current&&n.preventDefault()}})}),XIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:o,onCloseAutoFocus:n,...s}=t,r=Ew(JG,e),a=V.useRef(null),g=yI(A,a);return TuA(),W.jsxs(W.Fragment,{children:[W.jsx(JZ,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:o,onUnmountAutoFocus:n,children:W.jsx(aY,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":g0A(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(t6t,{titleId:r.titleId}),W.jsx(o6t,{contentRef:a,descriptionId:r.descriptionId})]})]})}),a0A="DialogTitle",$Ie=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(a0A,e);return W.jsx(ja.h2,{id:o.titleId,...i,ref:A})});$Ie.displayName=a0A;var Ale="DialogDescription",ele=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(Ale,e);return W.jsx(ja.p,{id:o.descriptionId,...i,ref:A})});ele.displayName=Ale;var tle="DialogClose",ile=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(tle,e);return W.jsx(ja.button,{type:"button",...i,ref:A,onClick:To(t.onClick,()=>o.onOpenChange(!1))})});ile.displayName=tle;function g0A(t){return t?"open":"closed"}var ole="DialogTitleWarning",[e6t,nle]=R6e(ole,{contentName:JG,titleName:a0A,docsSlug:"dialog"}),t6t=({titleId:t})=>{const A=nle(ole),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
|
|
5689
|
+
`,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:o,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:n,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},YIe=t=>t.activeSubSolver?[t,...YIe(t.activeSubSolver)]:[t],mXt=({solver:t})=>{const A=YIe(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(yXt,{solver:e})]},e.constructor.name))})},wXt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,s]=V.useReducer(Q=>!Q,!1),r=V.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),o&&o(t))},c=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&t.solved&&o(t);return}t.step(),A()},e))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||n)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&o&&o(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,n]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(mXt,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:g,disabled:t.solved||t.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:c,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||n,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&W.jsx("button",{onClick:I,disabled:t.solved||t.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},DXt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},SXt=(t,A)=>{const i=t.pipelineDef[A].solverName,o=DXt(t,A),n=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(o==="Completed"){const l=t.pipelineDef[A+1],B=l?t.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else o==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let c=0;o==="Completed"?c=1:o==="In Progress"&&n&&(c=n.progress??0);const I=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:n??null}},bXt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},_Xt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},xXt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),kXt=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=xXt(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,o])=>W.jsxs("div",{children:[i,": ",String(o)]},i))})]})},s0A=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(s0A);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=s0A(i));return A},FXt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=s0A(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},GXt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>SXt(t,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):FXt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>o(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(bXt,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(_Xt,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(kXt,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},RXt=class extends no.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function vXt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],o=t.circles??[],n=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of e){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of o){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of n)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),e.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),o.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),n.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var MXt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[o,n]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,o]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();n()}};return W.jsxs("div",{children:[W.jsx(wXt,{solver:t,triggerRender:n,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(RXt,{fallback:W.jsx(vXt,{graphics:s}),children:W.jsx(fXt,{graphics:s})}),a&&W.jsx(GXt,{solver:t,onStepUntilPhase:g})]})};const NXt=()=>{V.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},LXt=t=>t.toLowerCase().includes("pack")?j1t:t.toLowerCase().includes("rout")?e2t:M1t,UXt=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);NXt();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),o=V.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=V.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=enA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(enA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.map(r=>{const a=i.get(r),g=A===r;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const c=LXt(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:n?s.instance?W.jsx(Oy,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",n.solverName]})]})}),children:W.jsx(MXt,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:n.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.componentName]})]}),s.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(n.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},JIe=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{q5.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{q5.captureException(o,{error_type:i.type})}catch{}}},[e])},TIe="0.0.1540",HXt={version:TIe},ij=LYA()(UYA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),YXt=t=>{const[A,e]=V.useState([]),[i,o]=V.useState(null),[n,s]=V.useState(""),[r,a]=I1("eval-version-selection",null),g=ij(B=>B.setLastRunEvalVersion),c=ij(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(o(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(n)).slice(0,50),[A,n]),latestVersion:i,lastRunEvalVersion:c,search:n,setSearch:s,selectVersion:B=>{a(B),s("")}}},JXt=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[o,n]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?n(a[0]):g&&n(s))};return W.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${o===I?"bg-blue-50":""}`,onClick:()=>n(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${o===s?"bg-blue-50":""}`,onClick:()=>n(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>o&&A(o),disabled:!o,children:o===s?`Create "${o}"`:`Save to ${o}`})]})]})})},TXt=t=>{const A=V.useRef(null),e=jI(i=>i.recentEvents);V.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function KXt(t){const A=PXt(t),e=V.forwardRef((i,o)=>{const{children:n,...s}=i,r=V.Children.toArray(n),a=r.find(OXt);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:o,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:o,children:n})});return e.displayName=`${t}.Slot`,e}function PXt(t){const A=V.forwardRef((e,i)=>{const{children:o,...n}=e;if(V.isValidElement(o)){const s=ZXt(o),r=WXt(n,o.props);return o.type!==V.Fragment&&(r.ref=i?cf(i,s):s),V.cloneElement(o,r)}return V.Children.count(o)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var qXt=Symbol("radix.slottable");function OXt(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===qXt}function WXt(t,A){const e={...A};for(const i in A){const o=t[i],n=A[i];/^on[A-Z]/.test(i)?o&&n?e[i]=(...r)=>{const a=n(...r);return o(...r),a}:o&&(e[i]=o):i==="style"?e[i]={...o,...n}:i==="className"&&(e[i]=[o,n].filter(Boolean).join(" "))}return{...t,...e}}function ZXt(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var oj="Dialog",[KIe,PIe]=Km(oj),[VXt,Ew]=KIe(oj),qIe=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:o,onOpenChange:n,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=q_({prop:i,defaultProp:o??!1,onChange:n,caller:oj});return W.jsx(VXt,{scope:A,triggerRef:r,contentRef:a,contentId:_E(),titleId:_E(),descriptionId:_E(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};qIe.displayName=oj;var OIe="DialogTrigger",WIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(OIe,e),n=yI(A,o.triggerRef);return W.jsx(ja.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":g0A(o.open),...i,ref:n,onClick:To(t.onClick,o.onOpenToggle)})});WIe.displayName=OIe;var r0A="DialogPortal",[jXt,ZIe]=KIe(r0A,{forceMount:void 0}),VIe=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:o}=t,n=Ew(r0A,A);return W.jsx(jXt,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(f0,{present:e||n.open,children:W.jsx(AV,{asChild:!0,container:o,children:s})}))})};VIe.displayName=r0A;var nj="DialogOverlay",jIe=V.forwardRef((t,A)=>{const e=ZIe(nj,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Ew(nj,t.__scopeDialog);return n.modal?W.jsx(f0,{present:i||n.open,children:W.jsx(XXt,{...o,ref:A})}):null});jIe.displayName=nj;var zXt=KXt("DialogOverlay.RemoveScroll"),XXt=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(nj,e);return W.jsx(aV,{as:zXt,allowPinchZoom:!0,shards:[o.contentRef],children:W.jsx(ja.div,{"data-state":g0A(o.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),JG="DialogContent",zIe=V.forwardRef((t,A)=>{const e=ZIe(JG,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Ew(JG,t.__scopeDialog);return W.jsx(f0,{present:i||n.open,children:n.modal?W.jsx($Xt,{...o,ref:A}):W.jsx(A6t,{...o,ref:A})})});zIe.displayName=JG;var $Xt=V.forwardRef((t,A)=>{const e=Ew(JG,t.__scopeDialog),i=V.useRef(null),o=yI(A,e.contentRef,i);return V.useEffect(()=>{const n=i.current;if(n)return rdA(n)},[]),W.jsx(XIe,{...t,ref:o,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:To(t.onCloseAutoFocus,n=>{n.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:To(t.onPointerDownOutside,n=>{const s=n.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&n.preventDefault()}),onFocusOutside:To(t.onFocusOutside,n=>n.preventDefault())})}),A6t=V.forwardRef((t,A)=>{const e=Ew(JG,t.__scopeDialog),i=V.useRef(!1),o=V.useRef(!1);return W.jsx(XIe,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:n=>{t.onCloseAutoFocus?.(n),n.defaultPrevented||(i.current||e.triggerRef.current?.focus(),n.preventDefault()),i.current=!1,o.current=!1},onInteractOutside:n=>{t.onInteractOutside?.(n),n.defaultPrevented||(i.current=!0,n.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const s=n.target;e.triggerRef.current?.contains(s)&&n.preventDefault(),n.detail.originalEvent.type==="focusin"&&o.current&&n.preventDefault()}})}),XIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:o,onCloseAutoFocus:n,...s}=t,r=Ew(JG,e),a=V.useRef(null),g=yI(A,a);return TuA(),W.jsxs(W.Fragment,{children:[W.jsx(JZ,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:o,onUnmountAutoFocus:n,children:W.jsx(aY,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":g0A(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(t6t,{titleId:r.titleId}),W.jsx(o6t,{contentRef:a,descriptionId:r.descriptionId})]})]})}),a0A="DialogTitle",$Ie=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(a0A,e);return W.jsx(ja.h2,{id:o.titleId,...i,ref:A})});$Ie.displayName=a0A;var Ale="DialogDescription",ele=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(Ale,e);return W.jsx(ja.p,{id:o.descriptionId,...i,ref:A})});ele.displayName=Ale;var tle="DialogClose",ile=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(tle,e);return W.jsx(ja.button,{type:"button",...i,ref:A,onClick:To(t.onClick,()=>o.onOpenChange(!1))})});ile.displayName=tle;function g0A(t){return t?"open":"closed"}var ole="DialogTitleWarning",[e6t,nle]=R6e(ole,{contentName:JG,titleName:a0A,docsSlug:"dialog"}),t6t=({titleId:t})=>{const A=nle(ole),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
|
|
5690
5690
|
|
|
5691
5691
|
If you want to hide the \`${A.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
5692
5692
|
|