@tscircuit/runframe 0.0.1738 → 0.0.1739
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.
|
@@ -5149,7 +5149,7 @@ ${a.join(`
|
|
|
5149
5149
|
${Q}polygon: ${C.polygon.vertices}
|
|
5150
5150
|
`:a+=`
|
|
5151
5151
|
`,C.children.length>0&&c.push(C.children)}return a}};A.exports=s}}),n_e=at({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(e,A){var t=A_e(),i=i_e(),n=class{constructor(o){this.polygonTree=new i,this.rootnode=new t(null),o&&this.addPolygons(o)}invert(){this.polygonTree.invert(),this.rootnode.invert()}clipTo(o,s=!1){this.rootnode.clipTo(o,s)}allPolygons(){const o=[];return this.polygonTree.getPolygons(o),o}addPolygons(o){const s=new Array(o.length);for(let r=0;r<o.length;r++)s[r]=this.polygonTree.addChild(o[r]);this.rootnode.addPolygonTreeNodes(s)}clear(){this.polygonTree.clear()}toString(){return"Tree: "+this.polygonTree.toString("")}};A.exports=n}}),TuA=at({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(e,A){A.exports={Tree:n_e()}}}),o_e=at({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(e,A){var t=As(),i=JuA(),{Tree:n}=TuA(),o=(s,r)=>{if(!i(s,r))return t.create();const a=new n(t.toPolygons(s)),g=new n(t.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 t.create(c)};A.exports=o}}),ytt=at({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(e,A){var t=ko(),i=NY(),n=o_e(),o=(...s)=>{s=t(s);let r=s.shift();return s.forEach(a=>{r=n(r,a)}),r=i(r),r};A.exports=o}}),s_e=at({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(e,A){var t=ko(),i=As(),n=sk(),o=HuA(),s=YuA(),r=ytt(),a=(...g)=>{g=t(g);const c=g.map(B=>s({z0:-1,z1:1},B)),I=r(c),l=n(I);return o(l,i.toPolygons(I))};A.exports=a}}),r_e=at({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(e,A){var t=ko(),i=RY(),n=os(),o=As(),s=s_e(),r=ytt(),a=(...g)=>{if(g=t(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 n.isA(c)?s(g):o.isA(c)?r(g):c};A.exports=a}}),PuA=at({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(e,A){var t=tr(),i=bAt(),n=o=>i(o,{skipTriangulation:!0}).map(a=>{const g=a.map(c=>o[c]);return t.create(g)});A.exports=n}}),mtt=at({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(e,A){var t=As(),i=JuA(),{Tree:n}=TuA(),o=(r,a)=>{if(!i(r,a))return s(r,a);const g=new n(t.toPolygons(r)),c=new n(t.toPolygons(a));g.clipTo(c,!1),c.clipTo(g),c.invert(),c.clipTo(g),c.invert();const I=g.allPolygons().concat(c.allPolygons());return t.create(I)},s=(r,a)=>{let g=t.toPolygons(r);return g=g.concat(t.toPolygons(a)),t.create(g)};A.exports=o}}),KuA=at({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(e,A){var t=ko(),i=NY(),n=mtt(),o=(...s)=>{s=t(s);let r;for(r=1;r<s.length;r+=2)s.push(n(s[r-1],s[r]));let a=s[r-1];return a=i(a),a};A.exports=o}}),wtt=at({"node_modules/@jscad/modeling/src/operations/minkowski/minkowskiSum.js"(e,A){var t=ko(),i=As(),n=tr(),o=PuA(),s=KuA(),r=(...B)=>{if(B=t(B),B.length!==2)throw new Error("minkowskiSum requires exactly two geometries");const[C,Q]=B;if(!i.isA(C)||!i.isA(Q))throw new Error("minkowskiSum requires geom3 geometries");const h=i.isConvex(C),E=i.isConvex(Q);if(h&&E)return I(C,Q);if(!h&&E)return a(C,Q);if(h&&!E)return a(Q,C);throw new Error("minkowskiSum of two non-convex geometries is not yet supported")},a=(B,C)=>{const Q=g(B);if(Q.length===0)return i.create();const h=Q.map(E=>I(E,C));return h.length===1?h[0]:s(h)},g=B=>{const C=i.toPolygons(B);if(C.length===0)return[];const Q=[];for(let h=0;h<C.length;h++){const E=C[h],u=E.vertices;let d=0,f=0,m=0;for(let F=0;F<u.length;F++)d+=u[F][0],f+=u[F][1],m+=u[F][2];d/=u.length,f/=u.length,m/=u.length;const w=n.plane(E),D=w[0],S=w[1],_=w[2],b=.1,R=[d-D*b,f-S*b,m-_*b];for(let F=1;F<u.length-1;F++){const H=u[0],Y=u[F],J=u[F+1],O=c(R,H,Y,J);Q.push(i.create(O))}}return Q},c=(B,C,Q,h)=>[n.create([B,Q,C]),n.create([B,C,h]),n.create([C,Q,h]),n.create([Q,B,h])],I=(B,C)=>{const Q=l(B),h=l(C);if(Q.length===0||h.length===0)return i.create();const E=[];for(let d=0;d<Q.length;d++){const f=Q[d];for(let m=0;m<h.length;m++){const w=h[m];E.push([f[0]+w[0],f[1]+w[1],f[2]+w[2]])}}const u=o(E);return i.create(u)},l=B=>{const C=new Set,Q=[],h=i.toPolygons(B);for(let E=0;E<h.length;E++){const u=h[E].vertices;for(let d=0;d<u.length;d++){const f=u[d],m=`${f[0]},${f[1]},${f[2]}`;C.has(m)||(C.add(m),Q.push(f))}}return Q};A.exports=r}}),a_e=at({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(e,A){var t=bn(),i=sk(),n=As(),o=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=n.toPolygons(g),l=I.length,B=new Map,C=t.create();I.forEach((d,f)=>{d.vertices.forEach(m=>{s(B,t.snap(C,m,c),f)})});const Q=I.map(d=>{let f=[];return d.vertices.forEach(m=>{f=f.concat(r(B,t.snap(C,m,c)))}),{e:1,d:o(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((w,D)=>{const S=Q[D];if(S.e>0){S.e=-1;for(let _=0;_<S.d.length;_++)m[S.d[_]]=!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,w)=>f.push(I[w])),u.push(n.create(f))}return u};A.exports=a}}),g_e=at({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(e,A){var t=ko(),i=As(),n=a_e(),o=(...s)=>{if(s=t(s),s.length===0)throw new Error("wrong number of arguments");const r=s.map(a=>i.isA(a)?n(a):a);return r.length===1?r[0]:r};A.exports=o}}),c_e=at({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(e,A){var t=As(),i=JuA(),{Tree:n}=TuA(),o=(s,r)=>{if(!i(s,r))return t.clone(s);const a=new n(t.toPolygons(s)),g=new n(t.toPolygons(r));a.invert(),a.clipTo(g),g.clipTo(a,!0),a.addPolygons(g.allPolygons()),a.invert();const c=a.allPolygons();return t.create(c)};A.exports=o}}),Dtt=at({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(e,A){var t=ko(),i=NY(),n=c_e(),o=(...s)=>{s=t(s);let r=s.shift();return s.forEach(a=>{r=n(r,a)}),r=i(r),r};A.exports=o}}),I_e=at({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(e,A){var t=ko(),i=As(),n=sk(),o=HuA(),s=YuA(),r=Dtt(),a=(...g)=>{g=t(g);const c=g.map(B=>s({z0:-1,z1:1},B)),I=r(c),l=n(I);return o(l,i.toPolygons(I))};A.exports=a}}),l_e=at({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(e,A){var t=ko(),i=RY(),n=os(),o=As(),s=I_e(),r=Dtt(),a=(...g)=>{if(g=t(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 n.isA(c)?s(g):o.isA(c)?r(g):c};A.exports=a}}),Stt=at({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(e,A){var t=ko(),i=As(),n=sk(),o=HuA(),s=YuA(),r=KuA(),a=(...g)=>{g=t(g);const c=g.map(B=>s({z0:-1,z1:1},B)),I=r(c),l=n(I);return o(l,i.toPolygons(I))};A.exports=a}}),quA=at({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(e,A){var t=ko(),i=RY(),n=os(),o=As(),s=Stt(),r=KuA(),a=(...g)=>{if(g=t(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 n.isA(c)?s(g):o.isA(c)?r(g):c};A.exports=a}}),LY=at({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(e,A){A.exports={intersect:r_e(),minkowski:wtt(),scission:g_e(),subtract:l_e(),union:quA()}}}),eV=at({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(e,A){var{EPS:t,TAU:i}=Cr(),n=ttt(),o=GuA(),s=_s(),r=$Z(),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)<t)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(),w=c.length;for(let D=0;D<w;D++){const S=(D+1)%w,_=c[D],b=c[S];E?s.subtract(m,_,b):s.subtract(m,b,_),s.normal(m,m),s.normalize(m,m),s.scale(m,m,l);const R=s.add(s.create(),_,m),F=s.add(s.create(),b,m),H=[R,F];if(u!=null&&(C||!C&&S!==0)){const Y=n(u[0],u[1],H[0],H[1]);Y?(d.pop(),H[0]=Y):f.push({c:_,s0:u,s1:H})}u=[R,F],!(S===0&&!C)&&(d.push(H[0]),d.push(H[1]))}if(C&&u!=null){const D=d[0],S=d[1],_=n(u[0],u[1],D,S);if(_)d[0]=_,d.pop();else{const b=c[0],R=[D,S];f.push({c:b,s0:u,s1:R})}}if(B==="edge"){const D=new Map;d.forEach((b,R)=>D.set(b,R));const S=o.create(),_=o.create();f.forEach(b=>{o.fromPoints(S,b.s0[0],b.s0[1]),o.fromPoints(_,b.s1[0],b.s1[1]);const R=o.intersectPointOfLines(S,_);if(Number.isFinite(R[0])&&Number.isFinite(R[1])){const F=b.s0[1],H=D.get(F);d[H]=R,d[(H+1)%d.length]=void 0}else{const F=b.s1[0],H=D.get(F);d[H]=void 0}}),d=d.filter(b=>b!==void 0)}if(B==="round"){let D=Math.floor(Q/4);const S=s.create();f.forEach(_=>{let b=s.angle(s.subtract(S,_.s1[0],_.c));if(b-=s.angle(s.subtract(S,_.s0[1],_.c)),E&&b<0&&(b=b+Math.PI,b<0&&(b=b+Math.PI)),!E&&b>0&&(b=b-Math.PI,b>0&&(b=b-Math.PI)),b!==0){D=Math.floor(Q*(Math.abs(b)/i));const R=b/D,F=s.angle(s.subtract(S,_.s0[1],_.c)),H=[];for(let Y=1;Y<D;Y++){const J=F+R*Y,O=s.fromAngleRadians(s.create(),J);s.scale(O,O,l),s.add(O,O,_.c),H.push(O)}if(H.length>0){const Y=_.s0[1];let J=d.findIndex(O=>s.equals(Y,O));J=(J+1)%d.length,d.splice(J,0,...H)}}else{const R=_.s1[0],F=d.findIndex(H=>s.equals(R,H));d.splice(F,1)}})}return d};A.exports=a}}),B_e=at({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(e,A){var t=os(),i=eV(),n=(o,s)=>{const r={delta:1,corners:"edge",segments:16},{delta:a,corners:g,segments:c}=Object.assign({},r,o);if(!(g==="edge"||g==="chamfer"||g==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const B=t.toOutlines(s).map(C=>(o={delta:a,corners:g,closed:!0,segments:c},i(o,C))).reduce((C,Q)=>C.concat(t.toSides(t.fromPoints(Q))),[]);return t.create(B)};A.exports=n}}),C_e=at({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(e,A){var t=$g(),i=bn(),n=As(),o=tr(),s=(r,a)=>{i.dot(o.plane(a),r)>0&&(a=o.invert(a));const c=[a],I=o.transform(t.fromTranslation(t.create(),r),a),l=a.vertices.length;for(let B=0;B<l;B++){const C=B<l-1?B+1:0,Q=o.create([a.vertices[B],I.vertices[B],I.vertices[C],a.vertices[C]]);c.push(Q)}return c.push(o.invert(I)),n.create(c)};A.exports=s}}),Q_e=at({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(e,A){var{EPS:t,TAU:i}=Cr(),n=$g(),o=bn(),s=ptt(),r=As(),a=tr(),g=Btt(),c=NY(),I=mtt(),l=C_e(),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(),w=f<m?`${f},${m}`:`${m},${f}`;if(E.has(w))E.get(w)[1].push(d);else{const D=[u,[d]];E.set(w,D)}},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 w=r.create();const D=new Map,S=new Map,_=o.create(),b=o.create();return r.toPolygons(u).forEach((F,H)=>{const Y=o.scale(o.create(),a.plane(F),2*f),J=a.transform(n.fromTranslation(n.create(),o.scale(o.create(),Y,-.5)),F),O=l(Y,J);w=I(w,O);const W=F.vertices;for(let z=0;z<W.length;z++){B(D,W[z],a.plane(F));const tA=(z+1)%W.length,aA=[W[z],W[tA]];C(S,aA,a.plane(F))}}),S.forEach(F=>{const H=F[0],Y=F[1],J=H[0],O=H[1],W=o.subtract(o.create(),O,J);o.normalize(W,W);const z=Y[0],tA=o.cross(o.create(),z,W);let aA=[];for(let PA=0;PA<m;PA++)Q(aA,PA*i/m);for(let PA=0,EA=Y.length;PA<EA;PA++){const xA=Y[PA],dA=o.dot(tA,xA),OA=o.dot(z,xA);let VA=Math.atan2(dA,OA);VA<0&&(VA+=i),Q(aA,VA),VA=Math.atan2(-dA,-OA),VA<0&&(VA+=i),Q(aA,VA)}aA=aA.sort(s);const eA=aA.length;let oA,rA;const BA=[],pA=[],_A=[];for(let PA=-1;PA<eA;PA++){const EA=aA[PA<0?PA+eA:PA],xA=Math.sin(EA),dA=Math.cos(EA);o.scale(_,z,dA*f),o.scale(b,tA,xA*f),o.add(_,_,b);const OA=o.add(o.create(),J,_),VA=o.add(o.create(),O,_);let It=!1;if(PA>=0&&o.distance(OA,oA)<t&&(It=!0),!It){if(PA>=0){BA.push(OA),pA.push(VA);const mA=[rA,VA,OA,oA],gt=a.create(mA);_A.push(gt)}oA=OA,rA=VA}}pA.reverse(),_A.push(a.create(BA)),_A.push(a.create(pA));const FA=r.create(_A);w=I(w,FA)}),D.forEach(F=>{const H=F[0],Y=F[1],J=Y[0];let O=null,W=0;for(let eA=1;eA<Y.length;eA++){const oA=Y[eA],rA=o.cross(_,J,oA),BA=o.length(rA);BA>.05&&BA>W&&(W=BA,O=oA)}O||(O=o.orthogonal(_,J));const z=o.cross(_,J,O);o.normalize(z,z);const tA=o.cross(b,z,J),aA=g({center:[H[0],H[1],H[2]],radius:f,segments:m,axes:[J,z,tA]});w=I(w,aA)}),c(w)};A.exports=h}}),h_e=at({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(e,A){var t=As(),i=quA(),n=Q_e(),o=(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(t.toPolygons(r).length===0)throw new Error("the given geometry cannot be empty");s={delta:g,corners:c,segments:I};const B=n(s,r);return i(r,B)};A.exports=o}}),E_e=at({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(e,A){var t=$Z(),i=_s(),n=os(),o=Mg(),s=eV(),r=c=>{let{external:I,internal:l}=c;t(I)<0?I=I.reverse():l=l.reverse();const B=o.fromPoints({closed:!0},I),C=o.fromPoints({closed:!0},l),Q=n.toSides(n.fromPoints(o.toPoints(B))),h=n.toSides(n.fromPoints(o.toPoints(C)));return Q.push(...h),n.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,w=C[C.length-1],D=i.angle(i.subtract(i.create(),Q[Q.length-1],w)),S=C[0],_=i.angle(i.subtract(i.create(),h[0],S));for(let b=1;b<E;b++){let R=D+m*b,F=i.fromAngleRadians(i.create(),R);i.scale(F,F,B),i.add(F,F,w),u.push(F),R=_+m*b,F=i.fromAngleRadians(i.create(),R),i.scale(F,F,B),i.add(F,F,S),d.push(F)}}const f=[];return f.push(...Q,...u,...h.reverse(),...d),n.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=o.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}}),OuA=at({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(e,A){var t=ko(),i=os(),n=As(),o=Mg(),s=B_e(),r=h_e(),a=E_e(),g=(c,...I)=>{if(I=t(I),I.length===0)throw new Error("wrong number of arguments");const l=I.map(B=>o.isA(B)?a(c,B):i.isA(B)?s(c,B):n.isA(B)?r(c,B):B);return l.length===1?l[0]:l};A.exports=g}}),u_e=at({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(e,A){var t=os(),i=_uA(),n=eV(),o=(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=t.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},n(s,Q))).reduce((Q,h)=>Q.concat(t.toSides(t.fromPoints(h))),[]);return t.create(C)};A.exports=o}}),d_e=at({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(e,A){var t=Mg(),i=eV(),n=(o,s)=>{const r={delta:1,corners:"edge",closed:s.isClosed,segments:16},{delta:a,corners:g,closed:c,segments:I}=Object.assign({},r,o);if(!(g==="edge"||g==="chamfer"||g==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');o={delta:a,corners:g,closed:c,segments:I};const l=i(o,t.toPoints(s));return t.fromPoints({closed:c},l)};A.exports=n}}),p_e=at({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(e,A){var t=ko(),i=os(),n=Mg(),o=u_e(),s=d_e(),r=(a,...g)=>{if(g=t(g),g.length===0)throw new Error("wrong number of arguments");const c=g.map(I=>n.isA(I)?s(a,I):i.isA(I)?o(a,I):I);return c.length===1?c[0]:c};A.exports=r}}),btt=at({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(e,A){A.exports={expand:OuA(),offset:p_e()}}}),iV=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(e,A){var t=$g(),i=bn(),n=os(),o=a2(),s=tV(),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=n.toSides(g);if(h.length===0)throw new Error("the given geometry cannot be empty");const E=o.fromSides(h);Q[2]<0&&o.reverse(E,E);const u=t.create(),d=(f,m,w)=>{const D=m/B*l,S=i.scale(i.create(),Q,m/B);return t.multiply(u,t.fromZRotation(u,D),t.fromTranslation(t.create(),S)),o.transform(u,w)};return a={numberOfSlices:B+1,capStart:!0,capEnd:!0,repair:C,callback:d},s(a,E)};A.exports=r}}),f_e=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(e,A){var t=os(),i=Mg(),n=iV(),o=(s,r)=>{if(!r.isClosed)throw new Error("extruded path must be closed");const a=i.toPoints(r),g=t.fromPoints(a);return n(s,g)};A.exports=o}}),y_e=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(e,A){var t=ko(),i=os(),n=Mg(),o=iV(),s=f_e(),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=t(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=>n.isA(h)?s(a,h):i.isA(h)?o(a,h):h);return Q.length===1?Q[0]:Q};A.exports=r}}),m_e=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(e,A){var t=Mg(),i=OuA(),n=iV(),o=(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],t.toPoints(r).length===0)throw new Error("the given geometry cannot be empty");const l=i(s,r);return n(s,l)};A.exports=o}}),w_e=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(e,A){var{area:t}=vY(),i=os(),n=Mg(),o=OuA(),s=iV(),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=>(t(E)<0&&E.reverse(),o(a,n.fromPoints({closed:!0},E)))).reduce((E,u)=>E.concat(i.toSides(u)),[]),h=i.create(Q);return s(a,h)};A.exports=r}}),D_e=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(e,A){var t=ko(),i=os(),n=Mg(),o=m_e(),s=w_e(),r=(a,...g)=>{const c={size:1,height:1},{size:I,height:l}=Object.assign({},c,a);if(g=t(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=>n.isA(C)?o(a,C):i.isA(C)?s(a,C):C);return B.length===1?B[0]:B};A.exports=r}}),S_e=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(e,A){var{TAU:t}=Cr(),i=$g(),n=os(),o=tV(),s=a2(),r=(a,g)=>{const c={angle:t,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/t)),h<3)throw new Error("The number of segments per rotation needs to be at least 3.");const u=n.toSides(g);if(u.length===0)throw new Error("The given geometry cannot be empty");const d=u.filter(b=>b[0][0]>=0);let f=s.fromSides(u);d.length===0&&(f=s.reverse(f));const m=Math.round(h/t*Math.abs(I)),w=m>=2?m:2,D=i.create(),S=i.create(),_=(b,R,F)=>{const H=l+I/w*R,Y=Q/w*R,J=(H-l)/t*B;return i.multiply(D,i.fromTranslation(i.create(),[Y,0,J*Math.sign(I)]),i.fromXRotation(i.create(),-t/4*Math.sign(I))),i.multiply(S,i.fromZRotation(i.create(),H),D),s.transform(S,F)};return o({numberOfSlices:w+1,callback:_},f)};A.exports=r}}),b_e=at({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(e,A){var t=ko(),i=MuA(),n=UD(),o=$g(),s=os(),r=As(),a=tr(),g=sk(),c=Stt(),I=(B,C)=>{const Q=n.fromNormalAndPoint(n.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 w=u[m].vertices.map(_=>n.projectionOfPoint(Q,_)),D=a.create(w),S=a.plane(D);i(Q,S)&&(a.measureArea(D)<E||d.push(D))}if(!i(Q,[0,0,1])){const m=o.fromVectorRotation(o.create(),Q,[0,0,1]);d=d.map(w=>a.transform(m,w))}d=d.sort((m,w)=>a.measureArea(w)-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=t(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}}),UY=at({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(e,A){A.exports={extrudeFromSlices:tV(),extrudeLinear:y_e(),extrudeRectangular:D_e(),extrudeRotate:Ett(),extrudeHelical:S_e(),project:b_e(),slice:a2()}}}),WuA=at({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(e,A){var t=_s(),i=s=>{let r=t.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=o(c[1]-r[1],c[0]-r[0]),l=t.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&&n(g[I-2],g[I-1],c.point)<=Number.EPSILON;)g.pop(),I=g.length;g.push(c.point)}),g},n=(s,r,a)=>(r[0]-s[0])*(a[1]-s[1])-(r[1]-s[1])*(a[0]-s[0]),o=(s,r)=>s===0&&r===0?-1/0:-r/s;A.exports=i}}),ZuA=at({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(e,A){var t=os(),i=As(),n=Mg(),o=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=>{t.isA(c)?t.toPoints(c).forEach(g):i.isA(c)?i.toPoints(c).forEach(I=>I.forEach(g)):n.isA(c)&&n.toPoints(c).forEach(g)}),a};A.exports=o}}),x_e=at({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(e,A){var t=ko(),i=Mg(),n=WuA(),o=ZuA(),s=(...r)=>{r=t(r);const a=o(r),g=n(a);return i.fromPoints({closed:!0},g)};A.exports=s}}),__e=at({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(e,A){var t=ko(),i=os(),n=WuA(),o=ZuA(),s=(...r)=>{r=t(r);const a=o(r),g=n(a);return g.length<3?i.create():i.fromPoints(g)};A.exports=s}}),k_e=at({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(e,A){var t=ko(),i=As(),n=ZuA(),o=PuA(),s=(...r)=>{r=t(r);const a=n(r);return a.length===0?i.create():i.create(o(a))};A.exports=s}}),xtt=at({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(e,A){var t=ko(),i=RY(),n=os(),o=As(),s=Mg(),r=x_e(),a=__e(),g=k_e(),c=(...I)=>{if(I=t(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):n.isA(l)?a(I):o.isA(l)?g(I):l};A.exports=c}}),v_e=at({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(e,A){var t=ko(),i=quA(),n=xtt(),o=(...s)=>{if(s=t(s),s.length<2)throw new Error("wrong number of arguments");const r=[];for(let a=1;a<s.length;a++)r.push(n(s[a-1],s[a]));return i(r)};A.exports=o}}),F_e=at({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(e,A){A.exports={hull:xtt(),hullChain:v_e(),hullPoints2:WuA(),hullPoints3:PuA()}}}),M_e=at({"node_modules/@jscad/modeling/src/operations/minkowski/index.js"(e,A){A.exports={minkowskiSum:wtt()}}}),_tt=at({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(e,A){var t=bn(),i=tr(),n=(s,r)=>{const a=Math.abs(i.measureArea(r));return Number.isFinite(a)&&a>s},o=(s,r)=>{let a=r.map(c=>{const I=c.vertices.map(C=>t.snap(t.create(),C,s)),l=[];for(let C=0;C<I.length;C++){const Q=(C+1)%I.length;t.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=>n(g,c)),a};A.exports=o}}),G_e=at({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(e,A){var t=MuA(),i=bn(),n=tr(),o=E=>{const u=n.toPoints(E),d=[];for(let f=0;f<u.length;f++){const m=(f+1)%u.length,w={v1:u[f],v2:u[m]};d.push(w)}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,w=u.next.v2;const D=l(f,m,w,d);f=u.prev.v1,m=u.prev.v2,w=E.next.v2;const S=l(f,m,w,d);return[D,S]},c=i.create(),I=i.create(),l=(E,u,d,f)=>{const m=i.subtract(c,u,E),w=i.subtract(I,d,u);return i.cross(m,m,w),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=n.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 w=d.shift(),D=o(w);for(let S=0;S<D.length;S++){const _=D[S],b=a(f,_);if(b){const R=g(_,b,u);if(R[0]>=0&&R[1]>=0){const F=b.next,H=_.next;_.prev.next=b.next,_.next.prev=b.prev,b.prev.next=_.next,b.next.prev=_.prev,_.v1=null,_.v2=null,_.next=null,_.prev=null,r(f,b),b.v1=null,b.v2=null,b.next=null,b.prev=null;const Y=(J,O,W)=>{const z={v1:W.v1,v2:O.v2,next:O.next,prev:W.prev};W.prev.next=z,O.next.prev=z,r(J,O),O.v1=null,O.v2=null,O.next=null,O.prev=null,r(J,W),W.v1=null,W.v2=null,W.next=null,W.prev=null};R[0]===0&&Y(f,F,F.prev),R[1]===0&&Y(f,H,H.prev)}}else _.next&&s(f,_)}}const m=[];return f.forEach(w=>{const D=B(w);D&&m.push(D)}),f.clear(),m},Q=(E,u)=>Math.abs(E[3]-u[3])<15e-8?t(E,u):!1,h=(E,u)=>{const d=[];u.forEach(m=>{const w=d.find(D=>Q(D[0],n.plane(m)));w?w[1].push(m):d.push([n.plane(m),[m]])});let f=[];return d.forEach(m=>{const w=m[1],D=C(w);f=f.concat(D)}),f};A.exports=h}}),R_e=at({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(e,A){var t=Cr(),i=bn(),n=tr(),o=g=>`${g}`,s=(g,c,I,l,B,C)=>{const Q=o(l),h=o(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=o(l),h=o(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 w=o(m.vertex0);if(w===Q&&(w=o(m.vertex1),w===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=o(C);for(let h=0;h<B;h++){let E=h+1;E===B&&(E=0);const u=l.vertices[E],d=o(u),f=`${Q}/${d}`,m=`${d}/${Q}`;if(c.has(m)){const w=c.get(m);w.splice(-1,1),w.length===0&&c.delete(m)}else{const w={vertex0:C,vertex1:u,polygonindex:I};c.has(f)?c.get(f).push(w):c.set(f,[w])}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=o(E.vertex0),d=o(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 w=m===0?f.vertex0:f.vertex1,D=m===0?f.vertex1:f.vertex0,S=o(w),_=o(D);let b=[];m===0?l.has(S)&&(b=l.get(S)):I.has(S)&&(b=I.get(S));for(let R=0;R<b.length;R++){const F=b[R],H=c.get(F)[0],Y=m===0?H.vertex0:H.vertex1;if(m===0?H.vertex1:H.vertex0,o(Y)===_){r(c,I,l,w,D,null),r(c,I,l,D,w,null),u=!1,m=2,Q=!0;break}else{const O=w,W=D,z=Y,tA=i.subtract(i.create(),z,O),aA=i.dot(i.subtract(i.create(),W,O),tA)/i.dot(tA,tA);if(aA>0&&aA<1){const eA=i.scale(i.create(),tA,aA);if(i.add(eA,eA,O),i.squaredDistance(eA,W)<t.EPS*t.EPS){const rA=H.polygonindex,BA=C[rA],pA=o(H.vertex1);let _A=-1;for(let dA=0;dA<BA.vertices.length;dA++)if(o(BA.vertices[dA])===pA){_A=dA;break}const FA=BA.vertices.slice(0);FA.splice(_A,0,D);const PA=n.create(FA);C[rA]=PA,r(c,I,l,H.vertex0,H.vertex1,rA);const EA=s(c,I,l,H.vertex0,D,rA),xA=s(c,I,l,D,H.vertex1,rA);EA!==null&&B.set(EA,!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}}),N_e=at({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(e,A){var t=bn(),i=tr(),n=(s,r,a)=>{const g=r.vertices.length;if(g>3){if(g>4){const l=[0,0,0];r.vertices.forEach(B=>t.add(l,l,B)),t.snap(l,t.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)},o=(s,r)=>{const a=[];return r.forEach(g=>{n(s,g,a)}),a};A.exports=o}}),L_e=at({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(e,A){var t=ko(),i=sk(),n=os(),o=As(),s=Mg(),r=_tt(),a=G_e(),g=R_e(),c=N_e(),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 w=o.toPolygons(h);u&&(w=r(m,w)),d&&(w=a(m,w)),f&&(w=g(w),w=c(m,w));const D=Object.assign({},h);return D.polygons=w,D},C=(Q,...h)=>{if(h=t(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(n.isA(u))return l(Q,u);if(o.isA(u))return B(Q,u);throw new Error("invalid geometry")});return E.length===1?E[0]:E};A.exports=C}}),U_e=at({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(e,A){var t=ko(),i=_s(),n=os(),o=As(),s=Mg(),r=sk(),a=_tt(),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=n.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])),n.create(h)},I=B=>{const C=r(B),Q=o.toPolygons(B),h=a(C,Q);return o.create(h)},l=(...B)=>{if(B=t(B),B.length===0)throw new Error("wrong number of arguments");const C=B.map(Q=>s.isA(Q)?g(Q):n.isA(Q)?c(Q):o.isA(Q)?I(Q):Q);return C.length===1?C[0]:C};A.exports=l}}),H_e=at({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(e,A){A.exports={generalize:L_e(),snap:U_e(),retessellate:NY()}}}),Y_e=at({"node_modules/@jscad/modeling/src/utils/padArrayToLength.js"(e,A){var t=(i,n,o)=>{for(i=i.slice();i.length<o;)i.push(n);return i};A.exports=t}}),J_e=at({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(e,A){var t=ko(),i=Y_e(),n=RuA(),{translate:o}=PF(),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=n(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 o(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=t(I),I.length===0)throw new Error("align(): No geometries were provided to act upon");if(C.filter(h=>h==null).length){const h=n(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}}),nV=at({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(e,A){var t=ko(),i=os(),n=As(),o=Mg(),s=JF(),{translate:r}=PF(),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=t(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=>o.isA(d)||i.isA(d)||n.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}}}),oV=at({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(e,A){var t=ko(),i=$g(),n=os(),o=As(),s=Mg(),r=(I,...l)=>{if(!Array.isArray(I))throw new Error("factors must be an array");if(l=t(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):n.isA(Q)?n.transform(B,Q):o.isA(Q)?o.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}}}),T_e=at({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(e,A){var t=ko(),i=os(),n=As(),o=Mg(),s=(r,...a)=>{if(a=t(a),a.length===0)throw new Error("wrong number of arguments");const g=a.map(c=>o.isA(c)?o.transform(r,c):i.isA(c)?i.transform(r,c):n.isA(c)?n.transform(r,c):c);return g.length===1?g[0]:g};A.exports=s}}),qF=at({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(e,A){A.exports={align:J_e(),center:nV().center,centerX:nV().centerX,centerY:nV().centerY,centerZ:nV().centerZ,mirror:MY().mirror,mirrorX:MY().mirrorX,mirrorY:MY().mirrorY,mirrorZ:MY().mirrorZ,rotate:GY().rotate,rotateX:GY().rotateX,rotateY:GY().rotateY,rotateZ:GY().rotateZ,scale:oV().scale,scaleX:oV().scaleX,scaleY:oV().scaleY,scaleZ:oV().scaleZ,transform:T_e(),translate:PF().translate,translateX:PF().translateX,translateY:PF().translateY,translateZ:PF().translateZ}}}),sV=at({"node_modules/@jscad/modeling/src/index.js"(e,A){A.exports={colors:XZ(),curves:Nbe(),geometries:kuA(),maths:rxe(),measurements:Qxe(),primitives:KF(),text:Wxe(),utils:ftt(),booleans:LY(),expansions:btt(),extrusions:UY(),hulls:F_e(),minkowski:M_e(),modifiers:H_e(),transforms:qF()}}}),ktt=at({"node_modules/jscad-planner/dist/index.cjs"(e,A){var t=Object.defineProperty,i=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,s=(l,B)=>{for(var C in B)t(l,C,{get:B[C],enumerable:!0})},r=(l,B,C,Q)=>{if(B&&typeof B=="object"||typeof B=="function")for(let h of n(B))!o.call(l,h)&&h!==C&&t(l,h,{get:()=>B[h],enumerable:!(Q=i(B,h))||Q.enumerable});return l},a=l=>r(t({},"__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)}`)}}}}),P_e=at({"node_modules/ms/index.js"(e,A){var t=1e3,i=t*60,n=i*60,o=n*24,s=o*7,r=o*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*o;case"hours":case"hour":case"hrs":case"hr":case"h":return C*n;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*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return C;default:return}}}}function g(l){var B=Math.abs(l);return B>=o?Math.round(l/o)+"d":B>=n?Math.round(l/n)+"h":B>=i?Math.round(l/i)+"m":B>=t?Math.round(l/t)+"s":l+"ms"}function c(l){var B=Math.abs(l);return B>=o?I(l,B,o,"day"):B>=n?I(l,B,n,"hour"):B>=i?I(l,B,i,"minute"):B>=t?I(l,B,t,"second"):l+" ms"}function I(l,B,C,Q){var h=B>=C*1.5;return Math.round(l/C)+" "+Q+(h?"s":"")}}}),K_e=at({"node_modules/debug/src/common.js"(e,A){function t(i){o.debug=o,o.default=o,o.coerce=I,o.disable=g,o.enable=r,o.enabled=c,o.humanize=P_e(),o.destroy=l,Object.keys(i).forEach(B=>{o[B]=i[B]}),o.names=[],o.skips=[],o.formatters={};function n(B){let C=0;for(let Q=0;Q<B.length;Q++)C=(C<<5)-C+B.charCodeAt(Q),C|=0;return o.colors[Math.abs(C)%o.colors.length]}o.selectColor=n;function o(B){let C,Q=null,h,E;function u(...d){if(!u.enabled)return;const f=u,m=Number(new Date),w=m-(C||m);f.diff=w,f.prev=C,f.curr=m,C=m,d[0]=o.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let D=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(_,b)=>{if(_==="%%")return"%";D++;const R=o.formatters[b];if(typeof R=="function"){const F=d[D];_=R.call(f,F),d.splice(D,1),D--}return _}),o.formatArgs.call(f,d),(f.log||o.log).apply(f,d)}return u.namespace=B,u.useColors=o.useColors(),u.color=o.selectColor(B),u.extend=s,u.destroy=o.destroy,Object.defineProperty(u,"enabled",{enumerable:!0,configurable:!1,get:()=>Q!==null?Q:(h!==o.namespaces&&(h=o.namespaces,E=o.enabled(B)),E),set:d=>{Q=d}}),typeof o.init=="function"&&o.init(u),u}function s(B,C){const Q=o(this.namespace+(typeof C>"u"?":":C)+B);return Q.log=this.log,Q}function r(B){o.save(B),o.namespaces=B,o.names=[],o.skips=[];const C=(typeof B=="string"?B:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const Q of C)Q[0]==="-"?o.skips.push(Q.slice(1)):o.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=[...o.names,...o.skips.map(C=>"-"+C)].join(",");return o.enable(""),B}function c(B){for(const C of o.skips)if(a(B,C))return!1;for(const C of o.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 o.enable(o.load()),o}A.exports=t}}),q_e=at({"node_modules/debug/src/browser.js"(e,A){e.formatArgs=i,e.save=n,e.load=o,e.useColors=t,e.storage=s(),e.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`."))}})(),e.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 t(){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)}e.log=console.debug||console.log||(()=>{});function n(a){try{a?e.storage.setItem("debug",a):e.storage.removeItem("debug")}catch{}}function o(){let a;try{a=e.storage.getItem("debug")||e.storage.getItem("DEBUG")}catch{}return!a&&typeof puA<"u"&&"env"in puA&&(a=puA.env.DEBUG),a}function s(){try{return localStorage}catch{}}A.exports=K_e()(e);var{formatters:r}=A.exports;r.j=function(a){try{return JSON.stringify(a)}catch(g){return"[UnexpectedJSONParseError]: "+g.message}}}}),vtt={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,pcbNotes:!1,backgroundStart:!0,backgroundEnd:!0},Ftt=AA.createContext(void 0),O_e=({children:e})=>{const[A,t]=AA.useState(vtt),i=AA.useCallback((s,r)=>{t(a=>({...a,[s]:r}))},[]),n=AA.useCallback(()=>{t(vtt)},[]),o=AA.useMemo(()=>({visibility:A,setLayerVisibility:i,resetToDefaults:n}),[A,i,n]);return Z.jsx(Ftt.Provider,{value:o,children:e})},OF=()=>{const e=AA.useContext(Ftt);if(!e)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return e},VuA=1.2;function Mtt(e){return AA.useMemo(()=>{if(!e)return VuA;try{return yn(e).pcb_board.list()[0]?.thickness??VuA}catch{return VuA}},[e])}var Gtt=AA.createContext(null),nd=()=>{const e=AA.useContext(Gtt);if(!e)throw new Error("useThree must be used within a ThreeProvider");return e},HY=(e,A=[])=>{const{addFrameListener:t,removeFrameListener:i}=nd();Qn.useEffect(()=>(t(e),()=>i(e)),[t,i,...A])},YY={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:90,appearanceMenu:91},Rtt=({children:e,position:A,style:t})=>{const{camera:i,renderer:n}=nd(),o=AA.useRef(document.createElement("div")),[s,r]=AA.useState(null);return AA.useEffect(()=>{const a=n?.domElement.parentNode;if(a)return a.style.position!=="relative"&&a.style.position!=="absolute"&&(a.style.position="relative"),a.appendChild(o.current),r(UK.createPortal(e,o.current)),()=>{a.contains(o.current)&&a.removeChild(o.current)}},[n,e]),HY(()=>{if(!i||!o.current||!n)return;const a=new Gt(...A);a.project(i);const g=n.domElement.getBoundingClientRect(),c=Math.round((a.x+1)/2*g.width),I=Math.round((-a.y+1)/2*g.height);o.current.style.position="absolute",o.current.style.left=`${c}px`,o.current.style.top=`${I}px`,o.current.style.pointerEvents="none",o.current.style.zIndex=YY.htmlElements.toString(),t&&Object.assign(o.current.style,t)},[i,n,A,t]),s},Ntt={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},Ur=e=>{let A=typeof e=="number"?"mm":e.replace(/^[^a-zA-Z]+/g,"").toLowerCase();A||(A="mm");const t=typeof e=="number"?e:Number.parseFloat(e.split(A)[0]);if(A in Ntt)return t*Ntt[A];throw new Error(`Unsupported unit: ${A}`)},Pl=Ur,W_e=Object.defineProperty,Z_e=(e,A)=>{for(var t in A)W_e(e,t,{get:A[t],enumerable:!0})},Gb={};Z_e(Gb,{axial:()=>uve,bga:()=>Ske,breakoutheaders:()=>vve,cap:()=>tke,dfn:()=>Ave,diode:()=>Ake,dip:()=>z_e,electrolytic:()=>uGe,hc49:()=>Mve,jst:()=>NMe,led:()=>eke,lqfp:()=>_ve,m2host:()=>HGe,melf:()=>qFe,micromelf:()=>VFe,minimelf:()=>LFe,mlp:()=>Rke,mountedpcbmodule:()=>JGe,ms012:()=>sve,ms013:()=>ave,msop:()=>OMe,pad:()=>Gve,pinrow:()=>eve,platedhole:()=>kGe,potentiometer:()=>QGe,pushbutton:()=>mve,qfn:()=>Fke,qfp:()=>Gke,quad:()=>c2,radial:()=>fve,res:()=>mke,sma:()=>$Fe,smb:()=>rMe,smbf:()=>pGe,smc:()=>IMe,smf:()=>iMe,smtpad:()=>xGe,sod110:()=>UMe,sod123:()=>Cve,sod123f:()=>QFe,sod123fl:()=>dFe,sod123w:()=>Vve,sod128:()=>bFe,sod323:()=>$ve,sod323f:()=>IFe,sod323fl:()=>XMe,sod323w:()=>ZMe,sod523:()=>Hve,sod723:()=>mFe,sod80:()=>qve,sod882:()=>rFe,sod882d:()=>JFe,sod923:()=>iFe,soic:()=>xke,solderjumper:()=>rGe,son:()=>eGe,sop8:()=>Pve,sot:()=>FGe,sot223:()=>QMe,sot23:()=>Wke,sot23w:()=>wMe,sot25:()=>zke,sot323:()=>wGe,sot343:()=>RGe,sot363:()=>Pke,sot457:()=>cGe,sot563:()=>nve,sot723:()=>cve,sot886:()=>qke,sot89:()=>MFe,sot963:()=>lGe,ssop:()=>Uke,stampboard:()=>Dve,stampreceiver:()=>xve,to220:()=>RFe,to92:()=>Lve,to92l:()=>PGe,to92s:()=>kMe,tqfp:()=>Mke,tssop:()=>Jke,vson:()=>nGe,vssop:()=>PMe});var Li=(e,A,t)=>({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:t,pcb_component_id:"pcb_component_1",text:"{REF}",layer:"top",anchor_position:{x:e,y:A},anchor_alignment:"center"}),Ui=et({norefdes:TA().optional().describe("disable reference designator label"),invert:TA().optional().describe("hint to invert the orientation of the 3D model"),faceup:TA().optional().describe("The male pin header should face upwards, out of the top layer"),nosilkscreen:TA().optional().describe("omit all silkscreen elements from the footprint")}),vo=(e,A,t,i,n)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circle",x:A,y:t,hole_diameter:Ur(i),outer_diameter:Ur(n),pcb_port_id:"",layers:["top","bottom"],port_hints:[e.toString()]}),HD=e=>{const{pn:A,x:t,y:i,holeDiameter:n,rectPadWidth:o,rectPadHeight:s,holeOffsetX:r=0,holeOffsetY:a=0}=e;return{pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circular_hole_with_rect_pad",x:t,y:i,hole_diameter:Ur(n),hole_shape:"circle",pad_shape:"rect",rect_pad_width:Ur(o),rect_pad_height:Ur(s),pcb_port_id:"",layers:["top","bottom"],port_hints:[A.toString()],hole_offset_x:r,hole_offset_y:a}},rV=Array.from({length:9},(e,A)=>Math.cos(A/8*Math.PI-Math.PI)).map(e=>({x:e,y:-Math.sqrt(1-e**2)}));function rk(e){return typeof e=="string"?e.trim().toLowerCase().endsWith("mil")?parseFloat(e)*.0254:parseFloat(e):Number(e)}var aV=Ge([L(),qA()]).transform(e=>rk(e)),V_e=e=>Ui.extend({fn:L(),num_pins:qA().optional().default(6),wide:TA().optional(),narrow:TA().optional(),w:aV.optional(),p:aV.default(e.p??"2.54mm"),id:aV.optional(),od:aV.optional(),nosquareplating:TA().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=rk("0.55mm"),A.od=rk("0.95mm")):(A.id=rk("0.8mm"),A.od=rk("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=rk("600mil"):A.narrow?A.w=rk("300mil"):A.w=rk(e.w??"300mil")),A)),j_e=V_e({}),Ltt=(e,A,t,i,n)=>{const o=e/2,s=A<=o,r=o-1,a=i,g=a*r;return s?{x:-t/2,y:g/2-(A-1)*a}:{x:t/2,y:-g/2+(A-o-1)*a}},z_e=e=>{const A=j_e.parse(e),t=[];for(let g=0;g<A.num_pins;g++){const{x:c,y:I}=Ltt(A.num_pins,g+1,A.w,A.p??2.54,A.nosquareplating);if(g===0&&!A.nosquareplating){t.push(HD({pn:g+1,x:c,y:I,holeDiameter:A.id??"0.8mm",rectPadWidth:A.od??"1mm",rectPadHeight:A.od??"1mm"}));continue}t.push(vo(g+1,c,I,A.id??"0.8mm",A.od??"1mm"))}(A.num_pins/2-1)*A.p+A.od;const n=A.w-A.od-1,o=(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:-n/2,y:-o/2},{x:-n/2,y:o/2},...rV.map(({x:g,y:c})=>({x:g*n/6,y:c*n/6+o/2})),{x:n/2,y:o/2},{x:n/2,y:-o/2},{x:-n/2,y:-o/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}=Ltt(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=Li(0,o/2+.5,.4);return{circuitJson:[...t,s,a,...r],parameters:A}},li=(e,A,t,i,n)=>({type:"pcb_smtpad",x:A,y:t,width:i,height:n,layer:"top",shape:"rect",pcb_smtpad_id:"",port_hints:Array.isArray(e)?e.map(o=>o.toString()):[e.toString()]}),Utt=[{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}],X_e=Object.fromEntries(Utt.map(e=>[e.metric,e])),$_e=Object.fromEntries(Utt.map(e=>[e.imperial,e]));Ui.extend({tht:TA(),p:IA.optional(),pw:IA.optional(),ph:IA.optional(),metric:st.optional(),imperial:st.optional(),w:IA.optional(),h:IA.optional(),textbottom:TA().optional()});var gV=e=>{let{tht:A,p:t,pw:i,ph:n,metric:o,imperial:s,w:r,h:a,textbottom:g}=e;if(typeof r=="string"&&(r=Pl(r)),typeof a=="string"&&(a=Pl(a)),typeof t=="string"&&(t=Pl(t)),typeof i=="string"&&(i=Pl(i)),typeof n=="string"&&(n=Pl(n)),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(o&&(c=X_e[o]),s&&(c=$_e[s]),c&&(r=c.w_mm_min,a=c.h_mm_min,t=c.p_mm_min,i=c.pw_mm_min,n=c.ph_mm_min),t===void 0||i===void 0||n===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:t/2,y:n/2+.4},{x:-t/2-i/2-.2,y:n/2+.4},{x:-t/2-i/2-.2,y:-n/2-.4},{x:t/2,y:-n/2-.4}],stroke_width:.1,pcb_silkscreen_path_id:""},l=g?-n/2-.9:n/2+.9,B=Li(0,l,.2);return A?[vo(1,-t/2,0,i,i*1/.8),vo(2,t/2,0,i,i*1/.8),I,B]:[li(["1","left"],-t/2,0,i,n),li(["2","right"],t/2,0,i,n),I,B]},Ake=e=>({circuitJson:gV(e),parameters:e}),tke=e=>({circuitJson:gV(e),parameters:e}),eke=e=>({circuitJson:gV(e),parameters:e}),g2=e=>{const{padSpacing:A,padWidth:t,padHeight:i,padPitch:n,numRows:o,textbottom:s}=e,r=[],a=(o-1)*(n/2);for(let S=0;S<o;S++)r.push(a-S*n);const g=[];r.forEach((S,_)=>{g.push(li(_+1,-A/2,S,t,i))}),r.slice().reverse().forEach((S,_)=>{g.push(li(_+o+1,A/2,S,t,i))});const c=Math.max(...r)+i/2+.4,I=Math.min(...r)-i/2-.4,l=-A/2-t/2-.4,B=A/2+t/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-t/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},w=s?I-.9:c+.9,D=Li(0,w,.2);return[...g,C,Q,m,D]},ike=Ui.extend({pw:IA.default("0.5mm"),ph:IA.default("0.4mm"),p:IA.default("0.7mm"),textbottom:TA().optional(),convex:TA().optional(),concave:TA().optional()}),nke=1,oke=e=>{const A=ike.parse(e);if(A.concave===!0)return[];const t=Pl(A.pw),i=Pl(A.ph),n=Pl(A.p);return g2({padSpacing:nke,padWidth:t,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},ske=Ui.extend({pw:IA.default("0.5mm"),ph:IA.default("0.32mm"),p:IA.default("0.5mm"),textbottom:TA().optional(),convex:TA().optional(),concave:TA().optional()}),rke=1,ake=e=>{const A=ske.parse(e),t=Pl(A.pw),i=Pl(A.ph),n=Pl(A.p);return g2({padSpacing:rke,padWidth:t,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},gke=Ui.extend({pw:IA.default("0.9mm"),ph:IA.default("0.4mm"),p:IA.default("0.8mm"),textbottom:TA().optional(),convex:TA().optional(),concave:TA().optional()}),cke=1.7,Ike=e=>{const A=gke.parse(e),t=Pl(A.pw),i=Pl(A.ph),n=Pl(A.p);return g2({padSpacing:cke,padWidth:t,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},lke=Ui.extend({pw:IA.default("0.9mm"),ph:IA.default("0.4mm"),p:IA.default("0.8mm"),textbottom:TA().optional(),convex:TA().optional(),concave:TA().optional()}),Bke=1.7,Cke=e=>{const A=lke.parse(e),t=Pl(A.pw),i=Pl(A.ph),n=Pl(A.p);return g2({padSpacing:Bke,padWidth:t,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},Qke=Ui.extend({pw:IA.default("0.7mm"),ph:IA.default("0.64mm"),p:IA.default("0.94mm"),textbottom:TA().optional(),convex:TA().optional(),concave:TA().optional()}),hke=1.4,Eke=e=>{const A=Qke.parse(e),t=Pl(A.pw),i=Pl(A.ph),n=Pl(A.p);return g2({padSpacing:hke,padWidth:t,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},uke=Ui.extend({pw:IA.default("0.9mm"),ph:IA.default("0.9mm"),p:IA.default("1.34mm"),textbottom:TA().optional(),convex:TA().optional(),concave:TA().optional()}),dke=3,pke=e=>{const A=uke.parse(e),t=Pl(A.pw),i=Pl(A.ph),n=Pl(A.p);return g2({padSpacing:dke,padWidth:t,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},fke=e=>{const A=e.array??e.x;if(typeof A=="number")return Number.isNaN(A)?void 0:A;if(typeof A=="string"){const t=Number.parseInt(A,10);return Number.isNaN(t)?void 0:t}if(typeof e.imperial=="string"){const i=e.imperial.match(/x(2|4)$/)?.[1];if(i)return Number.parseInt(i,10)}},yke=e=>e?(typeof e=="number"?`${e}`:e).split(/[_x]/)[0]:void 0,mke=e=>{const A=fke(e),t=yke(e.imperial);return A===2&&t==="0402"?{circuitJson:oke(e),parameters:e}:A===4&&t==="0402"?{circuitJson:ake(e),parameters:e}:A===2&&t==="0603"?{circuitJson:Ike(e),parameters:e}:A===4&&t==="0603"?{circuitJson:Cke(e),parameters:e}:A===2&&t==="0606"?{circuitJson:Eke(e),parameters:e}:A===4&&t==="1206"?{circuitJson:pke(e),parameters:e}:{circuitJson:gV(e),parameters:e}},Htt=(e,{x:A,y:t,radius:i})=>({type:"pcb_smtpad",x:A,y:t,radius:i,layer:"top",shape:"circle",pcb_smtpad_id:"",port_hints:Array.isArray(e)?e.map(n=>n.toString()):[e.toString()]}),Ytt="ABCDEFGHIJKLMNOPQRSTUVWXYZ",cV=L().transform(e=>{const[A,t]=e.split(/[x ]/);return{x:parseFloat(A??""),y:parseFloat(t??"")}}).pipe(et({x:qA(),y:qA()})),wke=L().or(St(AI())).transform(e=>Array.isArray(e)?e:(e.startsWith("(")&&e.endsWith(")")&&(e=e.slice(1,-1)),e.split(",").map(A=>{const t=Number(A);return isNaN(t)?A:t}))).pipe(St(L().or(qA()))),Dke=Ui.extend({fn:L(),num_pins:qA().optional().default(64),grid:cV.optional(),p:st.default("0.8mm"),w:IA.optional(),h:IA.optional(),ball:IA.optional().describe("ball diameter"),pad:IA.optional().describe("pad width/height"),circularpads:TA().optional().describe("use circular pads"),tlorigin:TA().optional(),blorigin:TA().optional(),trorigin:TA().optional(),brorigin:TA().optional(),missing:wke.default([])}).transform(e=>{let A="tl";if(e.blorigin&&(A="bl"),e.trorigin&&(A="tr"),e.brorigin&&(A="br"),!e.grid){const i=Math.ceil(Math.sqrt(e.num_pins));e.grid={x:i,y:i}}return e.missing&&(e.missing=e.missing.map(i=>{if(typeof i=="number")return i;if(i==="center")return"center";if(i==="topleft")return"topleft";const n=i.match(/([A-Z]+)(\d+)/);if(!n)return i;const o=Ytt.indexOf(n[1]),s=Number.parseInt(n[2])-1;return o*e.grid.x+s+1})),{...e,origin:A}}),Ske=e=>{const A=Dke.parse(e);let{num_pins:t,grid:i,p:n,w:o,h:s,ball:r,pad:a,missing:g}=A;r??=.75/1.27*n,a??=r*.8;const c=[],I=(g??[]).filter(m=>typeof m=="number"),l=i.x*i.y-t;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)),w=Math.floor((i.x-m)/2),D=Math.floor((i.y-m)/2);for(let S=D;S<D+m;S++)for(let _=w;_<w+m;_++)I.push(S*i.x+_+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 w=0;w<i.x;w++){const D=(w-(i.x-1)/2)*n,S=(m-(i.y-1)/2)*n;let _=w,b=m;switch(A.origin){case"bl":_=w,b=i.y-1-m;break;case"br":_=i.x-1-w,b=i.y-1-m;break;case"tr":_=i.x-1-w,b=m;break}let R=b*i.x+_+1;if(B.has(R)){C++;continue}R-=C;const F=[R,`${Ytt[b]}${_+1}`];c.push(A.circularpads?Htt(F,{x:D,y:S,radius:a/2}):li(F,D,S,a,a))}const Q=Li(0,i.y*n/2,.2),h=n/6;let E;const u=i.x*n/2,d=i.y*n/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}},IV=(e,A,t,i,n)=>({type:"pcb_smtpad",x:A,y:t,width:i,height:n,radius:n/2,layer:"top",shape:"pill",pcb_smtpad_id:"",port_hints:Array.isArray(e)?e.map(o=>o.toString()):[e.toString()]}),WF=e=>Ui.extend({fn:L(),num_pins:qA().optional().default(8),w:IA.default(IA.parse(e.w??"5.3mm")),p:IA.default(IA.parse(e.p??"1.27mm")),pw:IA.default(IA.parse(e.pw??"0.6mm")),pl:IA.default(IA.parse(e.pl??"1.0mm")),legsoutside:TA().optional().default(e.legsoutside??!1),pillpads:TA().optional().default(e.pillpads??!1),silkscreen_stroke_width:qA().optional().default(.1)}).transform(A=>(!A.pw&&!A.pl?(A.pw=IA.parse("0.6mm"),A.pl=IA.parse("1.0mm")):A.pw?A.pl||(A.pl=A.pw*(1/.6)):A.pw=A.pl*(.6/1),A)),bke=WF({}),juA=e=>{e.widthincludeslegs!==void 0&&(e.legsoutside=!e.widthincludeslegs);const{num_pins:A,pn:t,w:i,p:n,pl:o,legsoutside:s}=e,r=A/2,a=t<=r,g=r-1,c=n,I=c*g,l=s?o/2:-o/2;return a?{x:-i/2-l,y:I/2-(t-1)*c}:{x:i/2+l,y:-I/2+(t-r-1)*c}},xke=e=>{const A=bke.parse(e);return{circuitJson:JY(A),parameters:A}},JY=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=juA({num_pins:e.num_pins,pn:r+1,w:e.w,p:e.p,pl:e.pl,legsoutside:e.legsoutside});e.pillpads?A.push(IV(r+1,a,g,e.pl,e.pw)):A.push(li(r+1,a,g,e.pl,e.pw))}const t=Math.min(1,e.p/2),i=e.w-(e.legsoutside?0:e.pl*2)-.2,n=(e.num_pins/2-1)*e.p+e.pw+t,o=Li(0,n/2+.4,n/12),s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:e.silkscreen_stroke_width??.1,route:[{x:-i/2,y:-n/2},{x:-i/2,y:n/2},...rV.map(({x:r,y:a})=>({x:r*i/6,y:a*i/6+n/2})),{x:i/2,y:n/2},{x:i/2,y:-n/2},{x:-i/2,y:-n/2}]};return[...A,s,o]},Jtt=Xt(["leftside","topside","rightside","bottomside","toppin","bottompin","leftpin","rightpin"]),_ke=({num_pins:e,cw:A,ccw:t,startingpin:i})=>{const n=[],o=e/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=o:r.bottomside&&r.leftpin?s=o+1:r.bottomside&&r.rightpin?s=o*2:r.rightside&&r.bottompin?s=o*2+1:r.rightside&&r.toppin?s=o*3:r.topside&&r.rightpin?s=o*3+1:r.topside&&r.leftpin&&(s=o*4),n.push(-1);for(let a=0;a<e;a++)n[s]=a+1,t||!A?(s++,s>e&&(s=1)):(s--,s<1&&(s=e));return n},zuA=Ui.extend({fn:L(),cc:TA().default(!0).optional(),ccw:TA().default(!0).optional(),startingpin:L().or(St(Jtt)).transform(e=>typeof e=="string"?e.slice(1,-1).split(","):e).pipe(St(Jtt)).optional(),num_pins:qA().optional().default(64),w:IA.optional(),h:IA.optional(),p:IA.default(IA.parse("0.5mm")),pw:IA.optional(),pl:IA.optional(),thermalpad:Ge([bA(!0),cV]).optional(),legsoutside:TA().default(!1)}),XuA=e=>{e.w&&!e.h?e.h=e.w:!e.w&&e.h&&(e.w=e.h);const A=e.num_pins/4;if(!e.p&&!e.pw&&!e.pl&&e.w){const t=A+4;e.p=e.w/t}return!e.p&&e.w&&e.h&&e.pw&&e.pl&&(e.p=(e.w-e.pl*2)/(A-1)),!e.w&&!e.h&&e.p&&(e.w=e.p*(A+4),e.h=e.w),e.p&&!e.pw&&!e.pl?(e.pw=e.p/2,e.pl=e.p/2):e.pw?e.pl||(e.pl=e.pw*(1/.6)):e.pw=e.pl*(.6/1),e},Ttt=zuA.transform(XuA),kke=["left","bottom","right","top"],vke=e=>{const{pin_count:A,pn:t,w:i,h:n,p:o,pl:s,legsoutside:r}=e,a=A/4,g=kke[Math.floor((t-1)/a)],c=(t-1)%a,I=o*(a-1),l=o*(a-1),B=r?s/2:-s/2;switch(g){case"left":return{x:-i/2-B+.1,y:l/2-c*o,o:"vert"};case"bottom":return{x:-I/2+c*o,y:-n/2-B+.1,o:"horz"};case"right":return{x:i/2+B-.1,y:-l/2+c*o,o:"vert"};case"top":return{x:I/2-c*o,y:n/2+B-.1,o:"horz"};default:throw new Error("Invalid pin number")}},c2=e=>{const A=Ttt.parse(e),t=[],i=_ke(A),n=A.num_pins/4;for(let r=0;r<A.num_pins;r++){const{x:a,y:g,o:c}=vke({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];t.push(li(B,a,g,I,l))}if(A.thermalpad)if(typeof A.thermalpad=="boolean"){const r=A.p*(n-1)+A.pw,a=A.p*(n-1)+A.pw;t.push(li(["thermalpad"],0,0,r,a))}else t.push(li(["thermalpad"],0,0,A.thermalpad.x,A.thermalpad.y));const o=[];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[n*4]===1&&r==="top-left"||i[n*3+1]===1&&r==="top-right"?l="in2":i[n*3]===1&&r==="top-right"||i[n]===1&&r==="bottom-left"?l="in1":i[n+1]===1&&r==="bottom-left"?l="in2":i[n*2]===1&&r==="bottom-right"?l="in1":i[n*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)&&o.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&&o.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")&&o.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=Li(0,A.h/2+(A.legsoutside?A.pl*1.2:.5),.3);return{circuitJson:[...t,...o,s],parameters:A}};zuA.extend({}).transform(XuA);var Fke=e=>(e.legsoutside=!1,e.pl||(e.pl=.875),e.pw||(e.pw=.25),c2(e)),Mke=e=>{if(e.legsoutside=!0,!e.p)switch(e.num_pins){case 32:e.p=.8;break;case 44:case 48:e.p=.5;break;case 64:case 80:case 100:e.p=.5;break;case 144:e.p=.5;break}if(!e.pl)switch(e.num_pins){case 32:case 44:case 48:case 64:case 80:case 100:e.pl=1.475;break;case 144:e.pl=1.6;break}if(!e.pw)switch(e.num_pins){case 32:e.pw=.55;break;case 44:case 48:case 64:case 80:case 100:e.pw=.3;break;case 144:e.pw=.25;break}return c2(e)},Gke=e=>{e.legsoutside=!0;const A=Ttt.parse(e);if(!e.p)switch(e.num_pins){case 44:case 64:e.p=.8;break;case 52:e.w===14?e.p=1:e.p=.65;break;case 208:e.p=.5;break}if(!e.pl)switch(e.num_pins){case 44:case 52:case 64:e.pl=2.25;break;case 208:e.pl=1.65;break;default:e.pl=A.pl*4;break}if(!e.pw)switch(e.num_pins){case 44:case 64:e.pw=.5;break;case 52:e.w===14?e.pw=.45:e.pw=.55;break;case 208:e.pw=.3;break;default:e.pw=A.pw;break}return c2(e)};zuA.extend({}).transform(XuA);var Rke=e=>(e.legsoutside=!1,e.thermalpad===void 0&&(e.thermalpad=!0),c2(e)),Nke=Ui.extend({fn:L(),num_pins:qA().optional().default(8),w:IA.default(IA.parse("3.9mm")),p:IA.default(IA.parse("1.27mm")),pw:IA.optional(),pl:IA.optional(),legsoutside:TA().optional().default(!1),silkscreen_stroke_width:qA().optional().default(.1)}).transform(e=>(e.pw==null&&e.pl==null?(e.pw=IA.parse("0.51mm"),e.pl=IA.parse("1.1mm")):e.pw==null?e.pw=e.pl*(.51/1.1):e.pl==null&&(e.pl=e.pw*(1.1/.51)),e)),Lke=e=>{const{num_pins:A,pn:t,w:i,p:n}=e,o=A/2,s=t<=o,r=o-1,a=n,g=a*r,c=i+IA.parse("0.2mm"),I=(s?-1:1)*(c/2);return s?{x:I,y:g/2-(t-1)*a}:{x:I,y:-g/2+(t-o-1)*a}},Uke=e=>{const A=Nke.parse(e),t=[];for(let a=0;a<A.num_pins;a++){const{x:g,y:c}=Lke({num_pins:A.num_pins,pn:a+1,w:A.w,p:A.p,pl:A.pl,legsoutside:A.legsoutside});t.push(li(a+1,g,c,A.pl,A.pw))}const i=Math.min(1,A.p/2),n=A.w-(A.legsoutside?0:A.pl)-.2,o=(A.num_pins/2-1)*A.p+A.pw+i,s=Li(0,o/2+.4,o/12),r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:A.silkscreen_stroke_width??.1,route:[{x:-n/2,y:-o/2},{x:-n/2,y:o/2},...rV.map(({x:a,y:g})=>({x:a*n/6,y:g*n/6+o/2})),{x:n/2,y:o/2},{x:n/2,y:-o/2},{x:-n/2,y:-o/2}]};return{circuitJson:[...t,r,s],parameters:A}},Hke=Ui.extend({fn:L(),num_pins:qA().optional().default(8),w:IA.default(IA.parse("3.0mm")),p:IA.default(IA.parse("0.5mm")),pw:IA.default(IA.parse("0.30mm")),pl:IA.default(IA.parse("1.45mm")),legsoutside:TA().optional().default(!0),silkscreen_stroke_width:qA().optional().default(.1)}),Yke=e=>{const{num_pins:A,pn:t,w:i,p:n,pl:o,legsoutside:s}=e,r=A/2,a=t<=r,g=r-1,c=n*g,I=s?o/2:-o/2;return a?{x:-i/2-I,y:c/2-(t-1)*n}:{x:i/2+I,y:-c/2+(t-r-1)*n}},Jke=e=>{const A={...e},t=A.p,i=typeof t=="string"||typeof t=="number"?IA.parse(t):void 0,n=i!=null&&i<=IA.parse("0.5mm"),o=Hke.parse(A),s=[],r=n?o.w-IA.parse("0.15mm"):o.w;for(let B=0;B<o.num_pins;B++){const{x:C,y:Q}=Yke({num_pins:o.num_pins,pn:B+1,w:r,p:o.p,pl:o.pl,legsoutside:o.legsoutside});s.push(li(B+1,C,Q,o.pl,o.pw))}const a=Math.min(1,o.p/2),g=o.w-(o.legsoutside?0:o.pl*2)-.2,c=(o.num_pins/2-1)*o.p+o.pw+a,I=Li(0,c/2+.4,c/12),l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:o.silkscreen_stroke_width??.1,route:[{x:-g/2,y:-c/2},{x:-g/2,y:c/2},...rV.map(({x:B,y:C})=>({x:B*g/6,y:C*g/6+c/2})),{x:g/2,y:c/2},{x:g/2,y:-c/2},{x:-g/2,y:-c/2}]};return{circuitJson:[...s,l,I],parameters:o}},Tke=Ui.extend({fn:L(),num_pins:bA(6).default(6),w:L().default("3.1mm"),h:L().default("2.0mm"),p:L().default("0.65mm"),pl:L().default("1.03mm"),pw:L().default("0.35mm"),string:L().optional()}),Pke=e=>{const A=Tke.parse({...e,fn:"sot363"}),t=IA.parse(A.w),i=IA.parse(A.h),n=IA.parse(A.p),o=IA.parse(A.pl),s=IA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=Ptt(B+1,t,n);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/4,y:i/2+.1},{x:t/4,y:i/2+.1}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/4,y:-i/2-.1},{x:t/4,y:-i/2-.1}],stroke_width:.05,pcb_silkscreen_path_id:""},c=Ptt(1,t,n),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-o/2-.3,y:c.y},{x:c.x-o/2-.45,y:c.y+.15},{x:c.x-o/2-.45,y:c.y-.15},{x:c.x-o/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Li(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},Ptt=(e,A,t,i)=>e<=3?{x:-.84,y:t-(e-1)*t}:{x:.84,y:-t+(e-4)*t},Kke=Ui.extend({fn:L(),num_pins:bA(6).default(6),w:L().default("1.01mm"),h:L().default("1.45mm"),p:L().default("0.5mm"),pl:L().default("0.33mm"),pw:L().default("0.27mm"),string:L().optional()}),qke=e=>{const A=Kke.parse({...e,fn:"sot886"}),t=IA.parse(A.w),i=IA.parse(A.h),n=IA.parse(A.p),o=IA.parse(A.pl),s=IA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=Ktt(B+1,t,n,o);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:i/2},{x:t/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:-i/2},{x:t/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=Ktt(1,t,n,o),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-o/2-.3,y:c.y},{x:c.x-o/2-.45,y:c.y+.15},{x:c.x-o/2-.45,y:c.y-.15},{x:c.x-o/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Li(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},Ktt=(e,A,t,i)=>{const n=A/2-i/2;return e<=3?{x:-n,y:t-(e-1)*t}:{x:n,y:-t+(e-4)*t}},qtt=Ui.extend({fn:L(),num_pins:qA().default(3),w:L().default("1.92mm"),h:L().default("2.74mm"),pl:L().default("1.32mm"),pw:L().default("0.6mm"),p:L().default("0.95mm"),string:L().optional()}),Oke=WF({p:"0.95mm",w:"1.6mm",legsoutside:!0}),Wke=e=>{const A=e.string?.match(/^sot23_(\d+)/),t=A?Number.parseInt(A[1],10):3;if(t===6||t===8){const n=Oke.parse({...e,num_pins:t});return{circuitJson:JY(n),parameters:n}}const i=qtt.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:Vke(i),parameters:i};if(i.num_pins===5)return{circuitJson:Wtt(i),parameters:i};throw new Error("Invalid number of pins")},Zke=e=>{const{pn:A,p:t}=e;return A===1?{x:-1.155,y:t}:A===2?{x:-1.155,y:-t}:{x:1.15,y:0}},Vke=e=>{const A=[];for(let i=0;i<e.num_pins;i++){const{x:n,y:o}=Zke({num_pins:e.num_pins,pn:i+1,w:Number.parseFloat(e.w),h:Number.parseFloat(e.h),pl:Number.parseFloat(e.pl),p:Number.parseFloat(e.p)});A.push(li(i+1,n,o,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=Li(0,Number.parseInt(e.h),.3);return[...A,t]},Ott=e=>{const{p:A,h:t,pn:i}=e;if(i===1)return{x:-t/2-.5,y:A};if(i===2)return{x:-t/2-.5,y:0};if(i===3)return{x:-t/2-.5,y:-A};if(i===4)return{x:t/2+.5,y:-A};if(i===5)return{x:t/2+.5,y:A};throw new Error("Invalid pin number")},Wtt=e=>{const A=[];for(let I=1;I<=e.num_pins;I++){const{x:l,y:B}=Ott({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:I});A.push(li(I,l,B,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=(e.num_pins+1)/2*Number.parseFloat(e.p),i=Number.parseFloat(e.h),n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-t/3,y:i/2+Number.parseFloat(e.p)/1.3},{x:t/3,y:i/2+Number.parseFloat(e.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-t/3,y:-i/2-Number.parseFloat(e.p)/1.3},{x:t/3,y:-i/2-Number.parseFloat(e.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Li(0,i+.3,.3),r=Ott({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:1});r.x=r.x-Number.parseFloat(e.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,n,o,c]},jke=qtt.extend({}),zke=e=>{const A=jke.parse({...e,num_pins:5});return{circuitJson:Wtt(A),parameters:A}},Xke=[{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}],$ke=WF({}),Ave=e=>{const A=$ke.parse(e),t=[];for(let I=0;I<A.num_pins;I++){const{x:l,y:B}=juA({num_pins:A.num_pins,pn:I+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});t.push(li(I+1,l,B,A.pl??"1mm",A.pw??"0.6mm"))}const i=Math.min(1,A.p/2),n=A.w+i,o=(A.num_pins/2-1)*A.p+A.pw+i,s=[];for(const I of Xke){const{dx:l,dy:B}=I;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",route:[{x:l*n/2-l*A.p,y:B*o/2},{x:l*n/2,y:B*o/2},{x:l*n/2,y:B*o/2-B*A.p}],type:"pcb_silkscreen_path",stroke_width:.1})}const r=A.p/4,a=-n/2-r/2,g=o/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=Li(0,o/2+.4,o/12);return{circuitJson:[...t,c,...s],parameters:A}},ZF=({fs:e,pn:A,anchor_x:t,anchor_y:i,textalign:n="center",orthogonal:o=!1,verticallyinverted:s=!1,layer:r="top"})=>{let a=0;o&&s?a=270:s?a=180:o?a=90:a=0;let g="center";return n==="left"&&(s?g="center_right":g="center_left"),n==="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:e,pcb_component_id:"pcb_component_1",text:`{PIN${A}}`,layer:r,anchor_position:{x:t,y:i},anchor_alignment:g,ccw_rotation:a}};function Ztt({pinlabeltextalignleft:e,pinlabeltextalignright:A,pinlabelorthogonal:t}){let i="top";return t?i="left":i="top",e&&(t?i="bottom":i="right"),A&&(t?i="top":i="left"),i}var tve=Ui.extend({fn:L(),num_pins:qA().optional().default(6),rows:Ge([L(),qA()]).transform(e=>Number(e)).optional().default(1).describe("number of rows"),p:IA.default("0.1in").describe("pitch"),id:IA.default("1.0mm").describe("inner diameter"),od:IA.default("1.5mm").describe("outer diameter"),male:TA().optional().describe("for male pin headers"),female:TA().optional().describe("for female pin headers"),smd:TA().optional().describe("surface mount device"),surfacemount:TA().optional().describe("surface mount device (verbose)"),rightangle:TA().optional().describe("right angle"),pw:IA.optional().default("1.0mm").describe("pad width for SMD"),pl:IA.optional().default("2.0mm").describe("pad length for SMD"),pinlabeltextalignleft:TA().optional().default(!1),pinlabeltextaligncenter:TA().optional().default(!1),pinlabeltextalignright:TA().optional().default(!1),pinlabelverticallyinverted:TA().optional().default(!1),pinlabelorthogonal:TA().optional().default(!1),nosquareplating:TA().optional().default(!1).describe("do not use rectangular pad for pin 1"),nopinlabels:TA().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:TA().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:TA().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top")}).transform(e=>{const A=Ztt(e);return{...e,pinlabelAnchorSide:A,male:e.male??!e.female,female:e.female??!1,smd:e.smd??e.surfacemount??!1,rightangle:e.rightangle??!1}}).superRefine((e,A)=>{e.male&&e.female&&A.addIssue({code:ze.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),eve=e=>{const A=tve.parse(e),{p:t,id:i,od:n,rows:o,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/o),u=-t,d=({xoff:S,yoff:_,od:b,anchorSide:R,smd:F,pw:H,pl:Y})=>{let J=0,O=0;if(F){const W=b/5;switch(R){case"right":J=H/2+W;break;case"top":O=Y/2+W;break;case"bottom":O=-(Y/2+W);break;case"left":J=-(H/2+W);break}}else{const W=b*.75;switch(R){case"right":J=W;break;case"top":O=W;break;case"bottom":O=-W;break;case"left":J=-W;break}}return{anchor_x:S+J,anchor_y:_+O}},f=(S,_,b)=>{A.smd?h.push(li(S,_,b,A.pw,A.pl)):S===1&&!A.nosquareplating?h.push(HD({pn:S,x:_,y:b,holeDiameter:i,rectPadWidth:n,rectPadHeight:n})):h.push(vo(S,_,b,i,n));const{anchor_x:R,anchor_y:F}=d({xoff:_,yoff:b,od:n,anchorSide:r,smd:A.smd,pw:A.pw,pl:A.pl});l||(C?h.push(ZF({fs:n/5,pn:S,anchor_x:R,anchor_y:F,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})):h.push(ZF({fs:n/5,pn:S,anchor_x:R,anchor_y:F,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"top"})),B&&h.push(ZF({fs:n/5,pn:S,anchor_x:R,anchor_y:F,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})))},m=new Set,w=o>2&&E>2;if(o===1){const S=-((s-1)/2)*t;for(let _=0;_<s;_++){const b=_+1,R=S+_*t,F=`${R},0`;if(m.has(F))throw new Error(`Overlap at ${F}`);m.add(F),f(b,R,0)}}else if(w){const S=-((E-1)/2)*t;let _=1;for(let b=0;b<o&&_<=s;b++)for(let R=0;R<E&&_<=s;R++){const F=S+R*t,H=b*u,Y=`${F},${H}`;if(m.has(Y))throw new Error(`Overlap at ${Y}`);m.add(Y),f(_++,F,H)}}else{const S=-((E-1)/2)*t;let _=1,b=0,R=o-1,F=0,H=E-1;for(;_<=s&&b<=R&&F<=H;){for(let Y=b;Y<=R&&_<=s;Y++){const J=S+F*t,O=Y*u,W=`${J},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(_++,J,O)}F++;for(let Y=F;Y<=H&&_<=s;Y++){const J=S+Y*t,O=R*u,W=`${J},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(_++,J,O)}if(R--,F<=H){for(let Y=R;Y>=b&&_<=s;Y--){const J=S+H*t,O=Y*u,W=`${J},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(_++,J,O)}H--}if(b<=R){for(let Y=H;Y>=F&&_<=s;Y--){const J=S+Y*t,O=b*u,W=`${J},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(_++,J,O)}b++}}if(_-1<s)throw new Error(`Missing pins: assigned ${_-1}, expected ${s}`)}const D=Li(0,t,.5);return{circuitJson:[...h,D],parameters:A}},ive=Ui.extend({fn:L(),num_pins:bA(6).default(6),w:L().default("2.1mm"),h:L().default("2.45mm"),p:L().default("0.5mm"),pl:L().default("0.675mm"),pw:L().default("0.35mm"),string:L().optional()}),nve=e=>{const A=ive.parse({...e,fn:"sot563"}),t=IA.parse(A.w),i=IA.parse(A.h),n=IA.parse(A.p),o=IA.parse(A.pl),s=IA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=Vtt(B+1,t,n,o);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:i/2},{x:t/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:-i/2},{x:t/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=Vtt(1,t,n,o),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-o/2-.3,y:c.y},{x:c.x-o/2-.45,y:c.y+.15},{x:c.x-o/2-.45,y:c.y-.15},{x:c.x-o/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Li(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},Vtt=(e,A,t,i)=>{const n=A/2-i/2;return e<=3?{x:-n,y:t-(e-1)*t}:{x:n,y:-t+(e-4)*t}},ove=WF({p:"1.27mm",w:"3.9mm",legsoutside:!0}),sve=e=>{const A=ove.parse({...e,num_pins:8});return{circuitJson:JY(A),parameters:A}},rve=WF({p:"1.27mm",w:"7.5mm",legsoutside:!0}),ave=e=>{const A=rve.parse({...e,num_pins:16});return{circuitJson:JY(A),parameters:A}},gve=Ui.extend({fn:L(),num_pins:bA(3).default(3),w:L().default("1.2mm"),h:L().default("1.2mm"),pw:L().default("0.40mm"),pl:L().default("0.45mm"),p:L().default("0.575mm")}),cve=e=>{const A=gve.parse(e),t=lve(A),i=Li(0,IA.parse(A.h),.2);return{circuitJson:[...t,i],parameters:A}},Ive=e=>{const{pn:A,p:t}=e;return A===1?{x:t,y:0}:A===2?{x:-t,y:-.4}:{x:-t,y:.4}},lve=e=>{const A=[];for(let t=0;t<3;t++){const{x:i,y:n}=Ive({num_pins:e.num_pins,pn:t+1,w:Number.parseFloat(e.w),h:Number.parseFloat(e.h),pl:Number.parseFloat(e.pl),p:Number.parseFloat(e.p)});A.push(li(t+1,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Bve=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("2.36mm"),h:L().default("1.22mm"),pl:L().default("0.9mm"),pw:L().default("1.2mm"),p:L().default("3.30mm")}),Cve=e=>{const A=Bve.parse(e),t=Li(0,IA.parse(A.h)/4+.4,.3);return{circuitJson:hve(A).concat(t),parameters:A}},Qve=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},hve=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Qve({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Eve=Ui.extend({fn:L(),p:IA.optional().default("2.54mm"),id:IA.optional().default("0.7mm"),od:IA.optional().default("1.4mm")}),uve=e=>{const A=Eve.parse(e),{p:t,id:i,od:n}=A,o=[vo(1,-t/2,0,i,n),vo(2,t/2,0,i,n)],s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2+n+i/2,y:0},{x:t/2-n-i/2,y:0}],stroke_width:.1,pcb_silkscreen_path_id:""},r=Li(0,1.5,.5);return{circuitJson:[...o,s,r],parameters:A}},dve=(e,A,t,i,n,o=.1)=>{const s=[],r=[],a=Math.max(1,Math.ceil(Math.PI*t/o)),g=Math.PI/a;for(let c=0;c<=a;c++){const I=c*g,l=e+Math.cos(I)*t,B=A+Math.sin(I)*t;l<e-i&&B>=A-n/2&&B<=A+n/2||s.push({x:l,y:B})}for(let c=0;c<=a;c++){const I=Math.PI+c*g,l=e+Math.cos(I)*t,B=A+Math.sin(I)*t;l<e-i&&B>=A-n/2&&B<=A+n/2||r.push({x:l,y:B})}return{topArc:s,bottomArc:r}},pve=Ui.extend({fn:L(),p:IA.optional().default("5mm"),id:IA.optional().default("0.8mm"),od:IA.optional().default("1.6mm"),ceramic:TA().optional(),electrolytic:TA().optional(),polarized:TA().optional()}),fve=e=>{const A=pve.parse(e),{p:t,id:i,od:n}=A;i===.8&&n===1.6&&(A.id=t===5?.8:t*.25,A.od=t===5?1.6:t*.5);const o=[vo(1,-t/2,0,A.id,A.od),vo(2,t/2,0,A.id,A.od)],s=t+.1,{topArc:r,bottomArc:a}=dve(0,0,s,A.od/2,A.od),g=.02*t,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*t,C=-(t+B+.04*t),Q=s-B-.08*t,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=Li(0,s+.12*t,.1*t),d=[...o,c,I,l,u];return(A.electrolytic===!0||A.polarized===!0)&&d.push(h,E),{circuitJson:d,parameters:A}},VF=(e,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:e,stroke_width:A.stroke_width||.1}),yve=Ui.extend({fn:bA("pushbutton"),w:IA.default(4.5),h:IA.default(6.5),id:IA.default(1),od:IA.default(1.2)}),mve=e=>{const A=yve.parse(e),t=A.w,i=A.h,n=A.id,o=[vo(1,-t/2,i/2,n,n*1.5),vo(2,-t/2,-i/2,n,n*1.5),vo(3,t/2,-i/2,n,n*1.5),vo(4,t/2,i/2,n,n*1.5)],s=[VF([{x:-t/2,y:-i/2},{x:-t/2,y:i/2}]),VF([{x:t/2,y:-i/2},{x:t/2,y:i/2}]),VF([{x:-t/2,y:0},{x:-t/5,y:0},{x:t/5*1/Math.sqrt(2),y:i/8}]),VF([{x:t/2,y:0},{x:t/5,y:0}])],r=Li(0,i/2+.4,.5);return{circuitJson:[...o,...s,r],parameters:A}},jtt=Ui.extend({fn:L(),w:IA.default("22.58mm"),h:IA.optional(),left:IA.optional().default(20),right:IA.optional().default(20),top:IA.optional().default(2),bottom:IA.optional().default(2),p:IA.default(IA.parse("2.54mm")),pw:IA.default(IA.parse("1.6mm")),pl:IA.default(IA.parse("2.4mm")),innerhole:TA().default(!1),innerholeedgedistance:IA.default(IA.parse("1.61mm")),silkscreenlabels:TA().default(!1),silkscreenlabelmargin:IA.default(IA.parse("0.1mm"))}),wve=e=>{const A=jtt.parse(e);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},lV=(e,A,t)=>{let i=[];return t==="right"&&(i=[{x:e+1/2,y:A},{x:e-1/2,y:A+.6/2},{x:e-1/2,y:A-.6/2},{x:e+1/2,y:A}]),t==="left"&&(i=[{x:e-1/2,y:A},{x:e+1/2,y:A+.6/2},{x:e+1/2,y:A-.6/2},{x:e-1/2,y:A}]),t==="top"&&(i=[{x:e,y:A+1/2},{x:e-.6/2,y:A-1/2},{x:e+.6/2,y:A-1/2},{x:e,y:A+1/2}]),t==="bottom"&&(i=[{x:e,y:A-1/2},{x:e-.6/2,y:A+1/2},{x:e+.6/2,y:A+1/2},{x:e,y:A-1/2}]),i},Dve=e=>{const A=jtt.parse(e),t=A.h??wve(A),i=[],n=[],o=[];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=lV(A.w/2-A.pl*1.4,Q+h*A.p,"right")),i.push(li(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}`;o.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&&(n.push(vo(h+1+A.left+(A.bottom??0)+g,A.w/2,Q+h*A.p,r,a)),n.push(vo(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=lV(-A.w/2+A.pl*1.4,Q-h*A.p,"left")),i.push(li(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}`;o.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&&(n.push(vo(h+1+g,-A.w/2,Q-h*A.p,r,a)),n.push(vo(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=lV(Q-h*A.p,t/2-A.pl*1.4,"top")),i.push(li(h+1+A.left+A.right+(A.bottom??0),Q-h*A.p,t/2-A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const E=h+1+A.left+A.right+(A.bottom??0),u=`pin${E}`;o.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:t/2-A.pl-(I+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:270})}A.innerhole&&(n.push(vo(h+1+A.left+A.right+(A.bottom??0)+g,Q-h*A.p,t/2,r,a)),n.push(vo(h+1+A.left+A.right+(A.bottom??0)+g*2,Q-h*A.p,t/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=lV(Q+h*A.p,-t/2+A.pl*1.4,"bottom")),i.push(li(h+1+A.left,Q+h*A.p,-t/2+A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const E=h+1+A.left,u=`pin${E}`;o.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:-t/2+A.pl+(I+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:90})}A.innerhole&&(n.push(vo(h+1+A.left+g,Q+h*A.p,-t/2,r,a)),n.push(vo(h+1+A.left+g*2,Q+h*A.p,-t/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:t/2},{x:A.w/2,y:t/2},{x:A.w/2,y:-t/2},{x:-A.w/2,y:-t/2},{x:-A.w/2,y:t/2}],stroke_width:.1,layer:"top"},C=Li(0,t/1.8,t/25);return{circuitJson:[...i,...n,...o,B,...A.silkscreenlabels?[]:[l],C],parameters:A}},ztt=Ui.extend({fn:L(),w:IA.default("22.58mm"),h:IA.optional(),left:IA.optional().default(20),right:IA.optional().default(20),top:IA.optional().default(2),bottom:IA.optional().default(2),p:IA.default(IA.parse("2.54mm")),pw:IA.default(IA.parse("1.6mm")),pl:IA.default(IA.parse("3.2mm")),innerhole:TA().default(!1),innerholeedgedistance:IA.default(IA.parse("1.61mm"))}),Sve=e=>{const A=ztt.parse(e);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},bve=(e,A,t,i=1,n=.6)=>{const o=i/2,s=n/2;return{left:[{x:e+o,y:A},{x:e-o,y:A+s},{x:e-o,y:A-s},{x:e+o,y:A}],right:[{x:e-o,y:A},{x:e+o,y:A+s},{x:e+o,y:A-s},{x:e-o,y:A}],top:[{x:e,y:A-o},{x:e-s,y:A+o},{x:e+s,y:A+o},{x:e,y:A-o}],bottom:[{x:e,y:A+o},{x:e-s,y:A-o},{x:e+s,y:A-o},{x:e,y:A+o}]}[t]},xve=e=>{const A=ztt.parse(e),t=A.h??Sve(A),i=[],n=[],o=[],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=bve(-A.w/2-A.pl/2,C-Q*A.p,"left")),i.push(li(c,-A.w/2+A.pl/2,C-Q*A.p,A.pl,A.pw)),n.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&&o.push(vo(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(li(c,C-Q*A.p,-t/2+A.pl/2,A.pw,A.pl)),n.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:-t/2+A.pl/2-3.2},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(vo(c+a,C-Q*A.p,-t/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(li(c,A.w/2-A.pl/2,C+Q*A.p,A.pl,A.pw)),n.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&&o.push(vo(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(li(c,C+Q*A.p,t/2-A.pl/2,A.pw,A.pl)),n.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:t/2-A.pl/2+3.2},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(vo(c+a,C+Q*A.p,t/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:t/2+A.pl/3},{x:A.w/2+A.pl/3,y:t/2+A.pl/3},{x:A.w/2+A.pl/3,y:-t/2-A.pl/3},{x:-A.w/2-A.pl/3,y:-t/2-A.pl/3},{x:-A.w/2-A.pl/3,y:t/2+A.pl/3}],stroke_width:.1,layer:"top"},B=Li(0,t/1.8,t/25);return{circuitJson:[...o,...i,...n,l,I,B],parameters:A}},_ve=e=>(e.legsoutside=!0,e.pl||(e.pl=1.5),e.pw||(e.pw=.3),c2(e)),Xtt=Ui.extend({fn:L(),w:IA.default("10mm"),h:IA.optional(),left:IA.optional().default(20),right:IA.optional().default(20),top:IA.optional().default(0),bottom:IA.optional().default(0),p:IA.default(IA.parse("2.54mm")),id:IA.optional().default(IA.parse("1mm")),od:IA.optional().default(IA.parse("1.5mm"))}),kve=e=>{const A=Xtt.parse(e);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},BV=(e,A,t,i=1,n=.6)=>{const o=i/2,s=n/2;return{left:[{x:e+o,y:A},{x:e-o,y:A+s},{x:e-o,y:A-s},{x:e+o,y:A}],right:[{x:e-o,y:A},{x:e+o,y:A+s},{x:e+o,y:A-s},{x:e-o,y:A}],top:[{x:e,y:A-o},{x:e-s,y:A+o},{x:e+s,y:A+o},{x:e,y:A-o}],bottom:[{x:e,y:A+o},{x:e-s,y:A-o},{x:e+s,y:A-o},{x:e,y:A+o}]}[t]},vve=e=>{const A=Xtt.parse(e),t=A.h??kve(A),i=[],n=A.id,o=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=BV(A.w/2+o*1.4,c+I*A.p,"right")),i.push(vo(I+1+A.left+(A.bottom??0),A.w/2,c+I*A.p,n,o))}if(A.left){const c=-((A.left-1)/2)*A.p;for(let I=0;I<A.left;I++)I===A.left-1&&(s=BV(-A.w/2-o*1.4,c+I*A.p,"left")),i.push(vo(I+1,-A.w/2,c+I*A.p,n,o))}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=BV(c+I*A.p,t/2+o*1.4,"top")),i.push(vo(I+1+A.right+(A.bottom??0)+A.left,c+I*A.p,t/2,n,o))}if(A.bottom){const c=-((A.bottom-1)/2)*A.p;for(let I=0;I<A.bottom;I++)I===0&&!A.left&&(s=BV(c+I*A.p,-t/2-o*1.4,"bottom")),i.push(vo(I+1+A.left,c+I*A.p,-t/2,n,o))}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-o,y:t/2+o},{x:A.w/2+o,y:t/2+o},{x:A.w/2+o,y:-t/2-o},{x:-A.w/2-o,y:-t/2-o},{x:-A.w/2-o,y:t/2+o}],stroke_width:.1,layer:"top"},g=Li(0,t/1.7,t/25);return{circuitJson:[...i,a,g,r],parameters:A}},$tt=(e,A,t,i)=>Array.from({length:25},(n,o)=>{const s=o/24*Math.PI-Math.PI/2;return{x:e+(i==="right"?1:-1)*Math.cos(s)*t,y:A+Math.sin(s)*t}}),Fve=Ui.extend({fn:L(),p:IA.optional().default("4.88mm"),id:IA.optional().default("0.8mm"),od:IA.optional().default("1.5mm"),w:IA.optional().default("5.6mm"),h:IA.optional().default("3.5mm")}),Mve=e=>{const A=Fve.parse(e),{p:t,id:i,od:n,w:o,h:s}=A,r=s/2,a=[vo(1,-t/2,0,i,n),vo(2,t/2,0,i,n)],g=$tt(-o/2,0,r,"left"),c=$tt(o/2,0,r,"right"),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...g,...g.slice(1).reverse(),{x:-o/2,y:-s/2},{x:o/2,y:-s/2},...c,{x:o/2,y:s/2},{x:-o/2,y:s/2}],stroke_width:.1,pcb_silkscreen_path_id:""},l=Li(0,t/4,.5);return{circuitJson:[...a,I,l],parameters:A}};Ui.extend({w:IA,h:IA});var Gve=e=>{const{w:A,h:t}=e,i=Ur(A),n=Ur(t);return{circuitJson:[li(1,0,0,i,n),Li(0,n/2+.5,.2)],parameters:e}},TY=(e,A,t,i,n,o)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"pill",x:A,y:t,outer_width:Ur(n),outer_height:Ur(o),hole_width:Ur(i),hole_height:Ur(i),pcb_port_id:"",layers:["top","bottom"],port_hints:[e.toString()],ccw_rotation:0}),Rve=Ui.extend({fn:L(),num_pins:Ge([bA(3),bA(2)]).default(3),p:L().default("1.27mm"),id:L().default("0.72mm"),od:L().default("0.95mm"),w:L().default("4.5mm"),h:L().default("4.5mm"),inline:TA().default(!1),string:L().optional()}),Nve=(e,A,t)=>Array.from({length:25},(i,n)=>{const o=n/24*Math.PI;return{x:e+Math.cos(o)*t,y:A+Math.sin(o)*t}}),Lve=e=>{const A=e.string?.match(/^to92_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=Rve.parse({...e,num_pins:t}),{p:n,id:o,od:s,w:r,h:a,inline:g}=i,c=Number.parseFloat(a)/2,I=Number.parseFloat(n),l=Number.parseFloat(o),B=Number.parseFloat(s),C=B,Q=B*(1.5/1.05);let h=[];if(i.num_pins===3)g?h=[HD({pn:1,x:-I,y:c-I,holeDiameter:l,rectPadWidth:B,rectPadHeight:Q}),TY(2,0,c-I,l,C,Q),TY(3,I,c-I,l,C,Q)]:h=[HD({pn:1,x:-I,y:c-I,holeDiameter:l,rectPadWidth:B,rectPadHeight:B}),vo(2,0,c,l,B),vo(3,I,c-I,l,B)];else if(i.num_pins===2)h=[HD({pn:1,x:-I,y:c-I,holeDiameter:l,rectPadWidth:C,rectPadHeight:Q}),TY(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=Nve(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=Li(0,c+1,.5);return{circuitJson:[...h,d,f],parameters:i}},Uve=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("2.15mm"),h:L().default("1.20mm"),pl:L().default("0.5mm"),pw:L().default("0.6mm"),p:L().default("1.4mm")}),Hve=e=>{const A=Uve.parse(e),t=Li(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Jve(A).concat(i,t),parameters:A}},Yve=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Jve=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Yve({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Tve=WF({w:"7.05mm",p:"1.27mm",pw:"0.65mm",pl:"1.975mm"}),Pve=e=>{const A=Tve.parse(e),t=[];for(let s=0;s<A.num_pins;s++){const{x:r,y:a}=juA({num_pins:A.num_pins,pn:s+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});t.push(li(s+1,r,a,A.pl??"1.5mm",A.pw??"0.6mm"))}const i=(A.num_pins/2-1)*A.p+A.pw,n=Li(0,i/2+1,i/12),o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-A.w/3,y:i/2+.4},{x:A.w/3,y:i/2+.4}],stroke_width:.1};return{circuitJson:[...t,n,o],parameters:A}},Kve=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("5.0mm"),h:L().default("2.30mm"),pl:L().default("1.25mm"),pw:L().default("2mm"),p:L().default("3.75mm")}),qve=e=>{const A=Kve.parse(e),t=Li(0,IA.parse(A.h)/2+1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2+.5,y:IA.parse(A.h)/2+.5},{x:-IA.parse(A.w)/2-.5,y:IA.parse(A.h)/2+.5},{x:-IA.parse(A.w)/2-.5,y:-IA.parse(A.h)/2-.5},{x:IA.parse(A.p)/2+.5,y:-IA.parse(A.h)/2-.5}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Wve(A).concat(i,t),parameters:A}},Ove=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Wve=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Ove({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Zve=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("4.4mm"),h:L().default("2.1mm"),pl:L().default("1.2mm"),pw:L().default("1.2mm"),p:L().default("2.9mm")}),Vve=e=>{const A=Zve.parse(e),t=Li(0,IA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:zve(A).concat(i,t),parameters:A}},jve=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},zve=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=jve({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Xve=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("3.30mm"),h:L().default("1.80mm"),pl:L().default("0.60mm"),pw:L().default("0.45mm"),p:L().default("2.1mm")}),$ve=e=>{const A=Xve.parse(e),t=Li(0,IA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:tFe(A).concat(i,t),parameters:A}},AFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},tFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=AFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},eFe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("1.4mm"),h:L().default("0.9mm"),pl:L().default("0.36mm"),pw:L().default("0.25mm"),p:L().default("0.85mm")}),iFe=e=>{const A=eFe.parse(e),t=Li(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2+.15,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.15,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.15,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2+.15,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:oFe(A).concat(i,t),parameters:A}},nFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},oFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=nFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},sFe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("1.3mm"),h:L().default("0.9mm"),pl:L().default("0.4mm"),pw:L().default("0.7mm"),p:L().default("0.7mm")}),rFe=e=>{const A=sFe.parse(e),t=Li(0,IA.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2+.2,y:IA.parse(A.h)/2+.2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2+.2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2-.2},{x:IA.parse(A.p)/2+.2,y:-IA.parse(A.h)/2-.2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:gFe(A).concat(i,t),parameters:A}},aFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},gFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=aFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},cFe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("3,05mm"),h:L().default("1.65mm"),pl:L().default("0.6mm"),pw:L().default("0.6mm"),pad_spacing:L().default("2.2mm")}),IFe=e=>{const A=cFe.parse(e),t=Li(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.pad_spacing)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.pad_spacing)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:BFe(A).concat(i,t),parameters:A}},lFe=e=>{const{pn:A,pad_spacing:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},BFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=lFe({pn:t,pad_spacing:Number.parseFloat(e.pad_spacing)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},CFe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("4.4mm"),h:L().default("2.1mm"),pl:L().default("1.10mm"),pw:L().default("1.10mm"),p:L().default("2.8mm")}),QFe=e=>{const A=CFe.parse(e),t=Li(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:EFe(A).concat(i,t),parameters:A}},hFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},EFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=hFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},uFe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("4.4mm"),h:L().default("2.1mm"),pl:L().default("0.91mm"),pw:L().default("1.22mm"),p:L().default("3.146mm")}),dFe=e=>{const A=uFe.parse(e),t=Li(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:fFe(A).concat(i,t),parameters:A}},pFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},fFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=pFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},yFe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("1.80mm"),h:L().default("1.00mm"),pl:L().default("0.66mm"),pw:L().default("0.5mm"),p:L().default("0.8mm")}),mFe=e=>{const A=yFe.parse(e),t=Li(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.1,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.1,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:DFe(A).concat(i,t),parameters:A}},wFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},DFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=wFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},SFe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("6.2mm"),h:L().default("3.4mm"),pl:L().default("1.4mm"),pw:L().default("2.1mm"),p:L().default("4.4mm")}),bFe=e=>{const A=SFe.parse(e),t=Li(0,IA.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:_Fe(A).concat(i,t),parameters:A}},xFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},_Fe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=xFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},kFe=Ui.extend({fn:L(),num_pins:Ge([bA(3),bA(5)]).default(3),w:L().default("4.20mm"),h:L().default("4.80mm"),pl:L().default("1.3mm"),pw:L().default("0.9mm"),p:L().default("1.5mm"),string:L().optional()}),vFe=e=>{const A=[],t=Number.parseFloat(e.p),i=Number.parseFloat(e.pw),n=Number.parseFloat(e.w),o=Number.parseFloat(e.pl),s=.175,r=(o-(o+s))/2;A.push(li(1,-n/2+r,t,o,i),li(2,-n/2,0,o+s,i),li(3,-n/2+r,-t,o,i));const a=Li(0,0,.3),g=Number.parseFloat(e.w)/2-1,c=Number.parseFloat(e.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]},FFe=e=>{const A=[];Number.parseFloat(e.p),Number.parseFloat(e.pw),Number.parseFloat(e.w),A.push(li(1,-1.85,-1.5,1.5,.7),li(2,-1.85,1.5,1.5,.7),li(3,0,0,.8,2),li(4,1.85,-1.5,1.5,.7),li(5,1.85,1.5,1.5,.7));const t=Li(0,Number.parseFloat(e.h)/2+.5,.3),i=Number.parseFloat(e.w)/2-1,n=Number.parseFloat(e.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n},{x:i,y:n}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-n},{x:i,y:-n}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,t]},MFe=e=>{const A=e.string?.match(/^sot89_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=kFe.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:vFe(i),parameters:i};if(i.num_pins===5)return{circuitJson:FFe(i),parameters:i};throw new Error("Invalid number of pins for SOT89")},GFe=Ui.extend({fn:L(),p:IA.optional().default("5.0mm"),id:IA.optional().default("1.0mm"),od:IA.optional().default("1.9mm"),w:IA.optional().default("13mm"),h:IA.optional().default("7mm"),num_pins:qA().optional(),string:L().optional()}),RFe=e=>{const A=GFe.parse(e),{fn:t,id:i,od:n,w:o,h:s,string:r}=A,a=Number.parseInt(r?.split("_")[1]??"3"),g=-1,c=o/2,I=s/2,l=2.5,B=o*.4,C=Math.max(l,B/(a-1)),Q=Array.from({length:a},(m,w)=>{const D=a%2===0?(w-a/2+.5)*C:(w-Math.floor(a/2))*C;return vo(w+1,D,g,i,n)}),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:-o/6,y:E},{x:-o/6,y:I}],stroke_width:.1,pcb_silkscreen_path_id:""},{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:o/6,y:E},{x:o/6,y:I}],stroke_width:.1,pcb_silkscreen_path_id:""}],f=Li(0,s/2+.6,.5);return{circuitJson:[...Q,h,u,...d,f],parameters:{...A,p:C}}},NFe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("5.40mm"),h:L().default("2.30mm"),pl:L().default("1.30mm"),pw:L().default("1.70mm"),p:L().default("3.5mm")}),LFe=e=>{const A=NFe.parse(e),t=Li(0,IA.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:HFe(A).concat(i,t),parameters:A}},UFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},HFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=UFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},YFe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("1.90mm"),h:L().default("1.33mm"),pl:L().default("0.5mm"),pw:L().default("0.7mm"),p:L().default("0.8mm")}),JFe=e=>{const A=YFe.parse(e),t=Li(0,IA.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2+.1,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2+.1,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:PFe(A).concat(i,t),parameters:A}},TFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},PFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=TFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},KFe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("7.0mm"),h:L().default("3.35mm"),pl:L().default("1.50mm"),pw:L().default("2.70mm"),p:L().default("4.8mm")}),qFe=e=>{const A=KFe.parse(e),t=Li(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:WFe(A).concat(i,t),parameters:A}},OFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},WFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=OFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},ZFe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("3.0mm"),h:L().default("1.80mm"),pl:L().default("0.80mm"),pw:L().default("1.20mm"),p:L().default("1.6mm")}),VFe=e=>{const A=ZFe.parse(e),t=Li(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.1,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.1,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:zFe(A).concat(i,t),parameters:A}},jFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},zFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=jFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},XFe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("7.10mm"),h:L().default("3.40mm"),pl:L().default("2.45mm"),pw:L().default("1.80mm"),p:L().default("4.05mm")}),$Fe=e=>{const A=XFe.parse(e),t=Li(0,IA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.5,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.5,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:tMe(A).concat(i,t),parameters:A}},AMe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},tMe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=AMe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},eMe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("4.80mm"),h:L().default("2.10mm"),pl:L().default("1.30mm"),pw:L().default("1.40mm"),p:L().default("2.9mm")}),iMe=e=>{const A=eMe.parse(e),t=Li(0,IA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:oMe(A).concat(i,t),parameters:A}},nMe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},oMe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=nMe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},sMe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("7.30mm"),h:L().default("4.40mm"),pl:L().default("2.50mm"),pw:L().default("2.30mm"),p:L().default("4.30mm")}),rMe=e=>{const A=sMe.parse(e),t=Li(0,IA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.1,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.1,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:gMe(A).concat(i,t),parameters:A}},aMe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},gMe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=aMe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},cMe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("10.70mm"),h:L().default("6.60mm"),pl:L().default("3.30mm"),pw:L().default("2.50mm"),p:L().default("6.80mm")}),IMe=e=>{const A=cMe.parse(e),t=Li(0,3,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2-.8},{x:-IA.parse(A.w)/2-.8,y:IA.parse(A.h)/2-.8},{x:-IA.parse(A.w)/2-.8,y:-IA.parse(A.h)/2+.8},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2+.8}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:BMe(A).concat(i,t),parameters:A}},lMe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},BMe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=lMe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},CMe=Ui.extend({fn:L(),num_pins:qA().default(4),w:L().default("8.50mm"),h:L().default("6.90mm"),pl:L().default("2mm"),pw:L().default("1.5mm"),p:L().default("2.30mm"),string:L().optional()}),QMe=e=>{const A=e.string?.match(/^sot223_(\d+)/),t=A?Number.parseInt(A[1],10):4;if(t===8){const n=uMe.parse({...e,num_pins:t});return{circuitJson:JY(n),parameters:n}}const i=CMe.parse({...e,num_pins:t});if(i.num_pins===4)return{circuitJson:EMe(i),parameters:i};if(i.num_pins===5)return{circuitJson:pMe(i),parameters:i};if(i.num_pins===6)return{circuitJson:yMe(i),parameters:i};throw new Error("Invalid number of pins")},hMe=e=>{const{pn:A,w:t,p:i}=e;return A===1?{x:-t/2+1.1,y:i}:A===2?{x:-t/2+1.1,y:0}:A===3?{x:-t/2+1.1,y:-i}:{x:t/2-1.1,y:0}},EMe=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=hMe({num_pins:e.num_pins,pn:r+1,w:Number.parseFloat(e.w),h:Number.parseFloat(e.h),pl:Number.parseFloat(e.pl),p:Number.parseFloat(e.p)}),c=r===3?3.8:Number.parseFloat(e.pw);A.push(li(r+1,a,g,Number.parseFloat(e.pl),c))}const t=Li(0,0,.3),i=Number.parseFloat(e.w)/2-2.4,n=Number.parseFloat(e.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n},{x:i,y:n},{x:i,y:n/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:-n},{x:i,y:-n},{x:i,y:-n/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,t]},uMe=WF({p:"0.90mm",w:"2.8mm",legsoutside:!0}),dMe=e=>{const{p:A,pn:t,w:i}=e;if(t===1)return{x:-i/2+1.2,y:A/2+A};if(t===2)return{x:-i/2+1.2,y:A/2};if(t===3)return{x:-i/2+1.2,y:-A/2};if(t===4)return{x:-i/2+1.2,y:-A/2-A};if(t===5)return{x:i/2-1,y:0};throw new Error("Invalid pin number")},pMe=e=>{const A=[];for(let r=1;r<=e.num_pins;r++){const{x:a,y:g}=dMe({h:Number.parseFloat(e.h),p:1.5,pn:r,w:Number.parseFloat(e.w)});let c=Number.parseFloat(e.pw),I=Number.parseFloat(e.pl);r===5?(c=3.4,I=1.8):(c=1,I=2.2),A.push(li(r,a,g,I,c))}const t=Number.parseFloat(e.w)/2-2.4,i=Number.parseFloat(e.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-t,y:i},{x:t,y:i},{x:t,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-t,y:-i},{x:t,y:-i},{x:t,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Li(0,0,.3);return[...A,n,o,s]},fMe=e=>{const{p:A,pn:t,w:i}=e;if(t===1)return{x:-i/2+1.2,y:2*A};if(t===2)return{x:-i/2+1.2,y:A};if(t===3)return{x:-i/2+1.2,y:0};if(t===4)return{x:-i/2+1.2,y:-A};if(t===5)return{x:-i/2+1.2,y:-2*A};if(t===6)return{x:i/2-1.175,y:0};throw new Error("Invalid pin number")},yMe=e=>{const A=[];for(let r=1;r<=e.num_pins;r++){const{x:a,y:g}=fMe({h:Number.parseFloat(e.h),p:1.3,pn:r,w:8.7});let c=Number.parseFloat(e.pw),I=Number.parseFloat(e.pl);r===6?(c=3.4,I=2.15):(c=.6,I=2.2),A.push(li(r,a,g,I,c))}const t=Number.parseFloat(e.w)/2-2.4,i=Number.parseFloat(e.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-t,y:i},{x:t,y:i},{x:t,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-t,y:-i},{x:t,y:-i},{x:t,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Li(0,0,.3);return[...A,n,o,s]},mMe=Ui.extend({fn:L(),num_pins:qA().default(3),w:L().default("3.40mm"),h:L().default("3.30mm"),pl:L().default("1mm"),pw:L().default("0.7mm"),p:L().default("1.2mm"),string:L().optional()}),wMe=e=>{const A=e.string?.match(/^sot23w_(\d+)/),t=A?Number.parseInt(A[1],3):3,i=mMe.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:SMe(i),parameters:i};throw new Error("Invalid number of pins")},DMe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t,y:.95}:A===2?{x:-t,y:-.95}:{x:t,y:0}},SMe=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=DMe({num_pins:e.num_pins,pn:r+1,w:Number.parseFloat(e.w),h:Number.parseFloat(e.h),pl:Number.parseFloat(e.pl),p:Number.parseFloat(e.p)});A.push(li(r+1,a,g,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=Li(0,Number.parseInt(e.h)/2+1,.3),i=Number.parseFloat(e.w)/2-1,n=Number.parseFloat(e.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n},{x:i+.3,y:n},{x:i+.3,y:n/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:-n},{x:i+.3,y:-n},{x:i+.3,y:-n/2}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,t]},bMe=Ui.extend({fn:L(),num_pins:Ge([bA(3),bA(2)]).default(3),p:L().default("1.27mm"),id:L().default("0.72mm"),od:L().default("0.95mm"),w:L().default("2.5mm"),h:L().default("4.2mm"),string:L().optional()}),xMe=e=>{const{p:A,id:t,od:i,w:n,h:o}=e,s=Number.parseFloat(o)/2,r=Number.parseFloat(A);return[vo(1,-r,s-r,t,i),vo(2,0,s-r,t,i),vo(3,r,s-r,t,i)]},_Me=e=>{const{p:A,id:t,od:i,h:n}=e,o=Number.parseFloat(n)/2,s=Number.parseFloat(A);return[vo(1,-s,o-s,t,i),vo(2,s,o-s,t,i)]},kMe=e=>{const A=e.string?.match(/^to92s_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=bMe.parse({...e,num_pins:t});let n=[];if(i.num_pins===3)n=xMe(i);else if(i.num_pins===2)n=_Me(i);else throw new Error("Invalid number of pins for TO-92");const o=Number.parseFloat(i.h)/2,s=Number.parseFloat(i.p),r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-o,y:o-s},{x:-1.9,y:0},{x:1.9,y:0},{x:o,y:o-s},{x:1.5,y:Number.parseFloat(i.h)/2+.5},{x:-1.5,y:Number.parseFloat(i.h)/2+.5},{x:-o,y:o-s}],stroke_width:.1,pcb_silkscreen_path_id:""},a=Li(0,o+1,.5);return{circuitJson:[...n,r,a],parameters:i}},vMe=Ui.extend({fn:L(),p:IA.optional(),id:IA.optional(),pw:IA.optional(),pl:IA.optional(),w:IA.optional(),h:IA.optional(),sh:TA().optional().describe('JST SH (Surface-mount) connector family. SH stands for "Super High-density".'),ph:TA().optional().describe('JST PH (Through-hole) connector family. PH stands for "Pin Header".'),string:L().optional()}),FMe={ph:{p:IA.parse("2.2mm"),id:IA.parse("0.70mm"),pw:IA.parse("1.20mm"),pl:IA.parse("1.20mm"),w:IA.parse("6mm"),h:IA.parse("5mm")},sh:{p:IA.parse("1mm"),pw:IA.parse("0.6mm"),pl:IA.parse("1.55mm"),w:IA.parse("5.8mm"),h:IA.parse("7.8mm")}};function MMe(e){return e.sh?"sh":(e.ph,"ph")}function GMe(e,A,t,i,n,o){const s=[];if(e==="ph"){const r=-((A-1)/2)*t;for(let a=0;a<A;a++){const g=r+a*t;s.push(HD({pn:a+1,x:g,y:2,holeDiameter:i,rectPadWidth:n,rectPadHeight:o}))}}else{const r=-((A-1)/2)*t;for(let g=0;g<A;g++){const c=r+g*t;s.push(li(g+1,c,-1.325,n,o))}const a=(A-1)/2*t+1.3;s.push(li(A+1,-a,1.22,1.2,1.8)),s.push(li(A+2,a,1.22,1.2,1.8))}return s}function RMe(e,A,t){return e==="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 NMe=e=>{const A=vMe.parse(e),t=MMe(A),i=FMe[t],n=A.p??i.p,o=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;const I=e.num_pins;typeof I=="number"&&(c=I);const B=(typeof e.string=="string"?e.string:"").match(/(?:^|_)jst(\d+)(?:_|$)/);if(B&&B[1]){const E=parseInt(B[1],10);Number.isNaN(E)||(c=E)}if(typeof c!="number")throw new Error(`JST requires an explicit pin count (e.g. jst6_sh or .jst(6))${A.string?`, from string "${A.string}"`:""}`);const C=GMe(t,c,n,o,s,r),Q=RMe(t),h=Li(0,g/2+1,.5);return{circuitJson:[...C,Q,h],parameters:{...A,p:n,id:o,pw:s,pl:r,w:a,h:g,num_pins:c,sh:t==="sh",ph:t==="ph"}}},LMe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("3.30mm"),h:L().default("1.70mm"),pl:L().default("0.80mm"),pw:L().default("1mm"),p:L().default("1.90mm")}),UMe=e=>{const A=LMe.parse(e),t=Li(0,IA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:YMe(A).concat(i,t),parameters:A}},HMe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},YMe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=HMe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},JMe=e=>{switch(e){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"}}},TMe=Ui.extend({fn:L(),num_pins:Ge([bA(8),bA(10)]).default(8),w:L().optional(),h:L().optional(),p:L().optional(),pl:L().optional(),pw:L().optional(),string:L().optional()}),PMe=e=>{const A=TMe.parse(e),t=JMe(A.num_pins),i=IA.parse(A.w||t.w),n=IA.parse(A.h||t.h),o=IA.parse(A.p||t.p),s=IA.parse(A.pl||t.pl),r=IA.parse(A.pw||t.pw),a=[],g=A.num_pins/2;for(let u=0;u<A.num_pins;u++){const{x:d,y:f}=Aet(A.num_pins,u+1,i,o),m=u<g?u+1:A.num_pins-(u-g);a.push(li(m,d,f,s,r))}const c=i,I=n,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=Aet(A.num_pins,1,c,o),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=Li(0,I/2+.5,.3);return{circuitJson:[...a,l,B,E,h],parameters:A}},Aet=(e,A,t,i)=>{const n=e/2,o=(A-1)%n,s=A<=n?-1:1,r=(n-1)/2-o;return{x:s*IA.parse(e===8?"1.8mm":"2.2mm"),y:r*i}},KMe=e=>{switch(e){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"}}},qMe=Ui.extend({fn:L(),num_pins:Ge([bA(8),bA(10),bA(12),bA(16)]).default(8),w:L().optional(),h:L().optional(),p:L().optional(),pl:L().optional(),pw:L().optional(),string:L().optional()}),tet=(e,A,t,i)=>{const n=e/2,o=(A-1)%n,s=A<=n?-1:1,r=(n-1)/2-o;return{x:s*IA.parse("2mm"),y:r*i}},OMe=e=>{const A=qMe.parse(e),t=KMe(A.num_pins),i=IA.parse(A.w||t.w),n=IA.parse(A.h||t.h),o=IA.parse(A.p||t.p),s=IA.parse(A.pl||t.pl),r=IA.parse(A.pw||t.pw),a=[];for(let E=0;E<A.num_pins;E++){const{x:u,y:d}=tet(A.num_pins,E+1,i,o);a.push(li(E+1,u,d,s,r))}const g=i,c=n,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=tet(A.num_pins,1,g,o),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=Li(0,c/2+.5,.3);return{circuitJson:[...a,I,l,h,Q],parameters:A}},WMe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("3.8mm"),h:L().default("1.65mm"),pl:L().default("1.2mm"),pw:L().default("1.2mm"),pad_spacing:L().default("2.6mm")}),ZMe=e=>{const A=WMe.parse(e),t=Li(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.pad_spacing)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.pad_spacing)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:jMe(A).concat(i,t),parameters:A}},VMe=e=>{const{pn:A,pad_spacing:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},jMe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=VMe({pn:t,pad_spacing:Number.parseFloat(e.pad_spacing)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},zMe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("3.20mm"),h:L().default("1.65mm"),pl:L().default("0.8mm"),pw:L().default("0.9mm"),pad_spacing:L().default("2.1mm")}),XMe=e=>{const A=zMe.parse(e),t=Li(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.pad_spacing)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.pad_spacing)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:AGe(A).concat(i,t),parameters:A}},$Me=e=>{const{pn:A,pad_spacing:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},AGe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=$Me({pn:t,pad_spacing:Number.parseFloat(e.pad_spacing)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},tGe=Ui.extend({fn:L(),num_pins:Ge([bA(6),bA(8)]).default(8),w:L().default("3mm"),h:L().default("3mm"),p:L().default("0.5mm"),pl:L().default("0.52mm"),pw:L().default("0.35mm"),epw:L().default("1.40mm"),eph:L().default("1.60mm"),string:L().optional(),ep:TA().default(!1)}),eGe=e=>{e.string&&e.string.includes("_ep")&&(e.ep=!0);const A=e.string?.match(/^son_(\d+)/),t=A?Number.parseInt(A[1],10):e.num_pins||8,i=tGe.parse({...e,num_pins:t}),n=IA.parse(i.w),o=IA.parse(i.h),s=IA.parse(i.p),r=IA.parse(i.pl),a=IA.parse(i.pw),g=IA.parse(i.epw),c=IA.parse(i.eph),I=[];for(let f=0;f<i.num_pins;f++){const{x:m,y:w}=eet(i.num_pins,f+1,n,s);I.push(li(f+1,m,w,r,a))}i.ep&&I.push(li(i.num_pins+1,0,0,g,c));const l=n,B=o,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=eet(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=Li(0,B/2+.5,.3);return{circuitJson:[...I,C,Q,d,u],parameters:i}},eet=(e,A,t,i)=>{const n=e/2,o=(A-1)%n,s=A<=n?-1:1,r=(n-1)/2-o;return{x:s*IA.parse("1.4mm"),y:r*i}},iGe=Ui.extend({fn:L(),num_pins:qA().optional().default(8),p:st.describe("pitch (distance between center of each pin)"),w:IA.describe("width between vertical rows of pins"),grid:cV.describe("width and height of the border of the footprint"),ep:cV.default("0x0mm").describe("width and height of the central exposed thermal pad"),epx:IA.default("0mm").describe("x offset of the center of the central exposed thermal pad"),pinw:IA.describe("width of the pin pads"),pinh:IA.describe("height of the pin pads")}),nGe=e=>{const A=iGe.parse(e),{num_pins:t,p:i,w:n,grid:o,ep:s,epx:r,pinw:a,pinh:g}=A;if(t%2!==0)throw new Error("invalid number of pins");const c=[];for(let B=0;B<t;B++){const{pinX:C,pinY:Q}=oGe({pinCount:t,pinIndex:B,width:n,pitch:i});c.push(li(B+1,C,Q,a,g))}s.x>0&&s.y>0&&c.push(li(A.num_pins+1,r,0,s.x,s.y));const I=sGe(o),l=Li(0,o.y/2+i,o.y/6);return{circuitJson:[...c,...I,l],parameters:A}},oGe=e=>{let A=0,t=0;const i=(e.pinCount/2-1)*e.pitch/2,n=e.pinCount/2;return e.pinIndex+1<=n?(A=e.pitch*e.pinIndex-i,t=0-e.width/2):(A=e.pitch*(e.pinCount-e.pinIndex-1)-i,t=e.width/2),{pinX:t,pinY:A}},sGe=e=>{const t=e.y/30;return[{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-e.x/2-.1,y:e.y/2+.1-t},{x:-e.x/2-.1,y:e.y/2+.1},{x:e.x/2+.1,y:e.y/2+.1},{x:e.x/2+.1,y:e.y/2+.1-t}],stroke_width:e.y/30},{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-e.x/2-.1,y:-e.y/2-.1+t},{x:-e.x/2-.1,y:-e.y/2-.1},{x:e.x/2+.1,y:-e.y/2-.1},{x:e.x/2+.1,y:-e.y/2-.1+t}],stroke_width:e.y/30}]},rGe=e=>{const{num_pins:A,bridged:t,p:i=2.54,pw:n=1.5,ph:o=1.5}=e,s=IA.parse(i),r=IA.parse(n),a=IA.parse(o),g=Math.min(a/4,.5),c=[];for(let f=0;f<A;f++)c.push(li(f+1,f*s,0,r,a));let I=[];if(t){const f=t.split("").map(Number);if(f.length>1)for(let m=0;m<f.length-1;m++){const w=f[m],D=f[m+1];if(typeof w=="number"&&typeof D=="number"&&!isNaN(w)&&!isNaN(D)){const S=(w-1)*s,_=(D-1)*s,b=Math.sign(_-S),R=S+b*(r/2),F=_-b*(r/2);I.push({type:"pcb_trace",pcb_trace_id:"",route:[{start_pcb_port_id:`{PIN${w}}`,x:R,y:0,width:g,layer:"top",route_type:"wire"},{end_pcb_port_id:`{PIN${D}}`,x:F,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=Li(C,u,.4);return{circuitJson:[...c,...I,h,d],parameters:e}},iet={fn:bA("sot457"),num_pins:bA(6).default(6),pillh:L().default("0.45mm"),pillw:L().default("1.45mm"),pl:L(),pw:L(),p:L(),wave:TA().optional(),reflow:TA().optional()},aGe=Ui.extend({...iet,h:L().default("2.5mm"),w:L().default("2.7mm"),pl:L().default("0.8mm"),pw:L().default("0.55mm"),p:L().default("0.95mm")}),gGe=Ui.extend({...iet,h:L().default("3mm"),w:L().default("4mm"),pillr:L().default("0.225mm"),pl:L().default("1.45mm"),pw:L().default("1.5mm"),p:L().default("1.475mm")}).transform(e=>({...e,wave:e.wave??(e.reflow===void 0?!0:!e.reflow),reflow:e.reflow??(e.wave===void 0?!1:!e.wave)})),Rb=e=>Number.parseFloat(e.replace("mm","")),net=({pitch:e,width:A,pinNumber:t})=>{const o={1:{x:-A/2-.1,y:e},2:{x:-A/2-.1,y:0},3:{x:-A/2-.1,y:-e},4:{x:A/2+.1,y:-e},5:{x:A/2+.1,y:0},6:{x:A/2+.1,y:e}}[t];if(!o)throw new Error(`Invalid pin number: ${t}`);return o},oet=e=>{const A=[],t=Rb(e.p),i=Rb(e.pl),n=Rb(e.pw),o=Rb(e.w),s=Rb(e.h);if(e.wave){const C={1:({padWidth:Q,padHeight:h})=>li(1,-t,t,h,Q),2:({padWidth:Q,padHeight:h})=>li(2,-t,-t,h,Q),3:({padWidth:Q,padHeight:h})=>IV(3,-t,0,Rb(e.pillw),Rb(e.pillh)),4:({padWidth:Q,padHeight:h})=>IV(4,t,0,Rb(e.pillw),Rb(e.pillh)),5:({padWidth:Q,padHeight:h})=>li(5,t,t,h,Q),6:({padWidth:Q,padHeight:h})=>li(6,t,-t,h,Q)};for(let Q=1;Q<=e.num_pins;Q++){const h=C[Q];h&&A.push(h({padWidth:i,padHeight:n}))}}else for(let C=1;C<=e.num_pins;C++){const{x:Q,y:h}=net({pitch:t,width:o,pinNumber:C});A.push(li(C,Q,h,i,n))}const r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-o/3,y:s/2+t/1.3},{x:o/3,y:s/2+t/1.3}],stroke_width:.05},a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-o/3,y:-s/2-t/1.3},{x:o/3,y:-s/2-t/1.3}],stroke_width:.05},g=Li(0,s+.5,.3),c=net({pitch:t,width:o,pinNumber:1}),I=e.wave?1:.5,l=e.wave?.7:.3;c.x-=e.wave?n:n*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]},cGe=e=>{if(e.wave){const t=gGe.parse({...e,fn:"sot457"});return{circuitJson:oet(t),parameters:t}}const A=aGe.parse(e);return{circuitJson:oet(A),parameters:A}},IGe=Ui.extend({fn:L(),num_pins:bA(6).default(6),w:L().default("1.1mm"),h:L().default("1.45mm"),p:L().default("0.35mm"),pl:L().default("0.2mm"),pw:L().default("0.2mm"),string:L().optional()}),lGe=e=>{const A=IGe.parse({...e,fn:"sot963"}),t=IA.parse(A.w),i=IA.parse(A.h),n=IA.parse(A.p),o=IA.parse(A.pl),s=IA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=set(B+1,t,n,o);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:i/2},{x:t/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:-i/2},{x:t/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=set(1,t,n,o),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-o/2-.3,y:c.y},{x:c.x-o/2-.45,y:c.y+.15},{x:c.x-o/2-.45,y:c.y-.15},{x:c.x-o/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Li(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},set=(e,A,t,i)=>{const n=A/2-i/2;return e<=3?{x:-n,y:t-(e-1)*t}:{x:n,y:-t+(e-4)*t}},BGe=Ui.extend({fn:L(),num_pins:Ge([bA(3),bA(2)]).default(3),p:L().default("3.8mm"),id:L().default("1.25mm"),od:L().default("2.35mm"),ca:L().default("14mm").describe("Caliper axis (width or diameter of the potentiometer body or adjustment knob)"),w:L().default("5.35mm"),h:L().default("4mm"),string:L().optional()}),CGe=e=>{const{p:A,id:t,od:i,h:n,ca:o}=e,s=Number.parseFloat(n),r=Number.parseFloat(o);return[vo(1,0,r/4+.3,t,i),vo(2,s,0,t,i),vo(3,0,-r/4-.3,t,i)]},QGe=e=>{const A=e.string?.match(/^potentiometer_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=BGe.parse({...e,num_pins:t});let n=[];i.num_pins===3&&(n=CGe(i));const o=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:o-1.75},{x:0,y:o},{x:s,y:o},{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:-o},{x:0,y:-o},{x:0,y:-o+1.75}],stroke_width:.1,pcb_silkscreen_path_id:""},c=Number.parseFloat(i.w)/2,I=Li(c,o+1,.5);return{circuitJson:[...n,a,g,I],parameters:i}},hGe=Ui.extend({fn:L(),p:IA.optional().default("7.5mm"),id:IA.optional().default("1mm"),od:IA.optional().default("2mm"),d:IA.optional().default("10.5mm")}),EGe=(e,A,t,i,n)=>{const o=[],s=[];for(let r=0;r<=50;r++){const a=r/50*Math.PI,g=e+Math.cos(a)*t,c=A+Math.sin(a)*t;g<e-i&&c>=A-n/2&&c<=A+n/2||o.push({x:g,y:c})}for(let r=0;r<=50;r++){const a=Math.PI+r/50*Math.PI,g=e+Math.cos(a)*t,c=A+Math.sin(a)*t;g<e-i&&c>=A-n/2&&c<=A+n/2||s.push({x:g,y:c})}return{topArc:o,bottomArc:s}},uGe=e=>{const A=hGe.parse(e),{p:t,id:i,od:n,d:o}=A,s=[vo(1,-t/2,0,i,n),vo(2,t/2,0,i,n)],{topArc:r,bottomArc:a}=EGe(0,0,o/2+.1,n/2,n),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:o/2+.1},{x:0,y:-(o/2+.1)}],stroke_width:.1,pcb_silkscreen_path_id:""},l=-(o/2+.5),B=n/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=Li(0,o/2+1,.5);return{circuitJson:[...s,g,c,I,Q,h,E],parameters:A}},dGe=Ui.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("6.5mm"),h:L().default("3mm"),pl:L().default("1.75mm"),pw:L().default("2.40mm"),p:L().default("4.75mm")}),pGe=e=>{const A=dGe.parse(e),t=Li(0,IA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.3,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.3,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:yGe(A).concat(i,t),parameters:A}},fGe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},yGe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=fGe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},mGe=Ui.extend({fn:L(),num_pins:qA().default(3),w:L().default("2.45mm"),h:L().default("2.40mm"),pl:L().default("0.92mm"),pw:L().default("0.45mm"),p:L().default("0.891mm"),string:L().optional()}),wGe=e=>{const A=e.string?.match(/^sot323_(\d+)/),t=A?Number.parseInt(A[1],3):3,i=mGe.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:SGe(i),parameters:i};throw new Error("Invalid number of pins")},DGe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t,y:.65}:A===2?{x:-t,y:-.65}:{x:t,y:0}},SGe=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=DGe({num_pins:e.num_pins,pn:r+1,w:Number.parseFloat(e.w),h:Number.parseFloat(e.h),pl:Number.parseFloat(e.pl),p:Number.parseFloat(e.p)});A.push(li(r+1,a,g,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=Li(0,Number.parseInt(e.h)/2+1,.3),i=Number.parseFloat(e.w)/2-Number.parseFloat(e.pl),n=Number.parseFloat(e.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n+.3},{x:i,y:n+.3},{x:i,y:n/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:-n-.3},{x:i,y:-n-.3},{x:i,y:-n/2}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,t]},bGe=Ui.extend({fn:L(),circle:TA().optional(),rect:TA().optional(),square:TA().optional(),pill:TA().optional(),d:IA.optional(),pd:IA.optional(),diameter:IA.optional(),r:IA.optional(),pr:IA.optional(),radius:IA.optional(),w:IA.optional(),pw:IA.optional(),width:IA.optional(),h:IA.optional(),ph:IA.optional(),height:IA.optional(),s:IA.optional(),size:IA.optional(),string:L().optional()}).transform(e=>{let A="rect";e.circle&&(A="circle"),e.square&&(A="square"),e.rect&&(A="rect"),e.pill&&(A="pill");let t,i,n;return A==="circle"?e.r!==void 0?t=Ur(e.r):e.pr!==void 0?t=Ur(e.pr):e.radius!==void 0?t=Ur(e.radius):e.d!==void 0?t=Ur(e.d)/2:e.pd!==void 0?t=Ur(e.pd)/2:e.diameter!==void 0?t=Ur(e.diameter)/2:t=Ur("1mm")/2:(e.w!==void 0?i=Ur(e.w):e.pw!==void 0?i=Ur(e.pw):e.width!==void 0?i=Ur(e.width):e.s!==void 0?i=Ur(e.s):e.size!==void 0?i=Ur(e.size):i=Ur("1mm"),e.h!==void 0?n=Ur(e.h):e.ph!==void 0?n=Ur(e.ph):e.height!==void 0?n=Ur(e.height):A==="square"||A==="rect"?n=i:n=Ur("1mm")),{fn:e.fn,shape:A,radius:t,width:i,height:n}}),xGe=e=>{const A=bGe.parse(e),{shape:t,radius:i,width:n,height:o}=A;let s,r;return t==="circle"?(s=Htt(1,{x:0,y:0,radius:i}),r=i+.5):t==="pill"?(s=IV(1,0,0,n,o),r=Math.max(n,o)/2+.5):(s=li(1,0,0,n,o),r=o/2+.5),{circuitJson:[s,Li(0,r,.2)],parameters:A}},_Ge=Ui.extend({fn:L(),d:IA.optional(),hd:IA.optional(),r:IA.optional(),hr:IA.optional(),pd:IA.optional(),pr:IA.optional(),squarepad:TA().optional().default(!1)}).transform(e=>{let A;e.d!==void 0?A=Ur(e.d):e.hd!==void 0?A=Ur(e.hd):e.r!==void 0?A=Ur(e.r)*2:e.hr!==void 0?A=Ur(e.hr)*2:A=Ur("1mm");let t;return e.pd!==void 0?t=Ur(e.pd):e.pr!==void 0?t=Ur(e.pr)*2:t=A*(1.5/1),{fn:e.fn,d:A,pd:t,squarepad:e.squarepad??!1}}),kGe=e=>{const A=_Ge.parse(e),{d:t,pd:i,squarepad:n}=A;return{circuitJson:[n?HD({pn:1,x:0,y:0,holeDiameter:t,rectPadWidth:i,rectPadHeight:i}):vo(1,0,0,t,i),Li(0,i/2+.5,.2)],parameters:A}},vGe=Ui.extend({fn:L(),num_pins:bA(6).default(6),h:L().default("1.6mm"),pl:L().default("1mm"),pw:L().default("0.7mm"),p:L().default("0.95mm")}),FGe=e=>{const A=vGe.parse(e);return{circuitJson:MGe(A),parameters:A}},ret=e=>{const{p:A,h:t,pn:i}=e;if(i===1)return{x:-t/2-.5,y:A};if(i===2)return{x:-t/2-.5,y:0};if(i===3)return{x:-t/2-.5,y:-A};if(i===4)return{x:t/2+.5,y:-A};if(i===5)return{x:t/2+.5,y:0};if(i===6)return{x:t/2+.5,y:A};throw new Error("Invalid pin number")},MGe=e=>{const A=[];for(let I=1;I<=e.num_pins;I++){const{x:l,y:B}=ret({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:I});A.push(li(I,l,B,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=e.num_pins/2*Number.parseFloat(e.p),i=Number.parseFloat(e.h),n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-t/3,y:i/2+Number.parseFloat(e.p)/1.3},{x:t/3,y:i/2+Number.parseFloat(e.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-t/3,y:-i/2-Number.parseFloat(e.p)/1.3},{x:t/3,y:-i/2-Number.parseFloat(e.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Li(0,i+.3,.3),r=ret({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:1});r.x=r.x-Number.parseFloat(e.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,n,o,c]},GGe=Ui.extend({fn:L(),num_pins:qA().default(4),w:L().default("3.2mm"),h:L().default("2.6mm"),pl:L().default("1.05mm"),pw:L().default("0.45mm"),p:L().default("0.55mm"),string:L().optional()}),RGe=e=>{const A=e.string?.match(/^sot343_(\d+)/),t=A?Number.parseInt(A[1],4):4,i=GGe.parse({...e,num_pins:t});if(i.num_pins===4)return{circuitJson:LGe(i),parameters:i};throw new Error("Invalid number of pins")},NGe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t*1.92,y:-.65}:A===2?{x:-t*1.92,y:.65}:A===3?{x:t,y:.65}:A===4?{x:t,y:-.65}:{x:0,y:0}},LGe=e=>{const A=[],t=Number.parseFloat(e.w),i=Number.parseFloat(e.h),n=Number.parseFloat(e.pl),o=Number.parseFloat(e.pw),s=Number.parseFloat(e.p);let r=1/0,a=-1/0,g=1/0,c=-1/0;for(let d=0;d<e.num_pins;d++){const{x:f,y:m}=NGe({num_pins:e.num_pins,pn:d+1,p:s});A.push(li(d+1,f,m,n,o)),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=t*.8;i<=2.6&&(Q/=2);const h=Li(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]},UGe=Ui.extend({fn:L()}),HGe=e=>{const A=UGe.parse(e),t=[],i=.5-.15,n=1.5,s=.5/2,r=75,a=-37/2;for(let D=0;D<r;D++){const S=D+1;if(S>=24&&S<=31)continue;const _=a-D*s,b=S%2===0,R=n+(b?.25:0),H=.5-R/2,Y=li(S,H,_,R,i);Y.layer=b?"bottom":"top",t.push(Y)}const g=46*.0254,c=137*.0254,I=261*.0254,l={type:"pcb_cutout",pcb_cutout_id:"",shape:"rect",center:{x:-c/2+n/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=(D,S,_=0,b=0)=>{Q=Math.min(Q,D-_/2),h=Math.max(h,D+_/2),E=Math.min(E,S-b/2),u=Math.max(u,S+b/2)};for(const D of t){const S=D;d(S.x,S.y,S.width,S.height)}d(l.center.x,l.center.y,l.width,l.height);for(const D of C.route)d(D.x,D.y);const f=(Q+h)/2,m=(E+u)/2,w=D=>{typeof D.x=="number"&&(D.x-=f),typeof D.y=="number"&&(D.y-=m),D.center&&(D.center.x-=f,D.center.y-=m),Array.isArray(D.route)&&(D.route=D.route.map(S=>({x:S.x-f,y:S.y-m})))};for(const D of t)w(D);return w(l),w(C),{circuitJson:[...t,l,C],parameters:A}},YGe=Ui.extend({fn:L(),numPins:qA().optional().default(0),rows:Ge([L(),qA()]).transform(e=>Number(e)).optional().default(1).describe("number of rows"),p:IA.default("2.54mm").describe("pitch"),id:IA.default("1.0mm").describe("inner diameter"),od:IA.default("1.5mm").describe("outer diameter"),male:TA().optional().describe("the module uses male headers"),nopin:TA().optional().default(!1).describe("omit pins rendering"),female:TA().optional().describe("the module uses female headers"),smd:TA().optional().describe("surface mount device"),pinlabeltextalignleft:TA().optional().default(!1),pinlabeltextaligncenter:TA().optional().default(!1),pinlabeltextalignright:TA().optional().default(!1),pinlabelverticallyinverted:TA().optional().default(!1),pinlabelorthogonal:TA().optional().default(!1),nopinlabels:TA().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:TA().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:TA().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top"),pinRowSide:Xt(["left","right","top","bottom"]).optional().default("left"),pinrowleft:TA().optional().default(!1),pinrowright:TA().optional().default(!1),pinrowtop:TA().optional().default(!1),pinrowbottom:TA().optional().default(!1),pinrowleftpins:Ge([L(),qA()]).transform(e=>Number(e)).optional(),pinrowrightpins:Ge([L(),qA()]).transform(e=>Number(e)).optional(),pinrowtoppins:Ge([L(),qA()]).transform(e=>Number(e)).optional(),pinrowbottompins:Ge([L(),qA()]).transform(e=>Number(e)).optional(),width:IA.optional(),height:IA.optional(),pinRowHoleEdgeToEdgeDist:IA.default("2mm"),holes:Ge([L(),St(L())]).optional().transform(e=>!e||Array.isArray(e)?e:e.startsWith("(")&&e.endsWith(")")?e.slice(1,-1).split(",").map(A=>A.trim()):[e]),holeXDist:IA.optional(),holeYDist:IA.optional(),holeInset:IA.default("1mm"),pinrow:Ge([L(),qA()]).optional(),usbposition:Xt(["left","right","top","bottom"]).optional().default("left"),usbleft:TA().optional().default(!1),usbtop:TA().optional().default(!1),usbright:TA().optional().default(!1),usbbottom:TA().optional().default(!1),usbtype:Xt(["micro","c"]).optional(),usbmicro:TA().optional().default(!1),usbc:TA().optional().default(!1),screen:TA().optional().default(!1).describe("add silkscreen outline for screen/display area"),screenwidth:IA.optional(),screenheight:IA.optional(),screencenteroffsetx:IA.optional(),screencenteroffsety:IA.optional()}).transform(e=>{const A=Ztt(e);let t=e.pinRowSide;e.pinrowleft&&(t="left"),e.pinrowright&&(t="right"),e.pinrowtop&&(t="top"),e.pinrowbottom&&(t="bottom");let i=e.usbposition;e.usbleft&&(i="left"),e.usbtop&&(i="top"),e.usbright&&(i="right"),e.usbbottom&&(i="bottom");let n=e.usbtype;e.usbmicro&&(n="micro"),e.usbc&&(n="c"),e.pinrow!==void 0&&(e.numPins=Number(e.pinrow));const o={left:e.pinrowleftpins,right:e.pinrowrightpins,top:e.pinrowtoppins,bottom:e.pinrowbottompins},s=Object.values(o).some(f=>f!==void 0&&f>0),r=(o.left??0)>0&&(o.right??0)>0,a=(o.top??0)>0&&(o.bottom??0)>0;s&&((o.left??0)>0?t="left":(o.right??0)>0?t="right":(o.top??0)>0?t="top":(o.bottom??0)>0&&(t="bottom"),e.numPins=(o.left??0)+(o.right??0)+(o.top??0)+(o.bottom??0));const g=Math.ceil(e.numPins/e.rows),c=Math.max(o.left??0,o.right??0),I=Math.max(o.top??0,o.bottom??0);let l,B;if(s){const f=r?e.p:0,m=a?e.p:0;l=(I>0?(I-1)*e.p:0)+2*e.pinRowHoleEdgeToEdgeDist+f,B=(c>0?(c-1)*e.p:0)+2*e.pinRowHoleEdgeToEdgeDist+m}else t==="left"||t==="right"?(l=(e.rows-1)*e.p+2*e.pinRowHoleEdgeToEdgeDist,B=(g-1)*e.p+2*e.pinRowHoleEdgeToEdgeDist):(B=(e.rows-1)*e.p+2*e.pinRowHoleEdgeToEdgeDist,l=(g-1)*e.p+2*e.pinRowHoleEdgeToEdgeDist);e.numPins===0&&(l=10,B=10);const C=e.width??l,Q=e.height??B,h=e.screenwidth??C*.95,E=e.screenheight??Q*.95,u=e.screencenteroffsetx??0,d=e.screencenteroffsety??0;return{...e,pinlabelAnchorSide:A,pinRowSide:t,usbposition:i,usbtype:n,male:e.male??!e.female,female:e.female??!1,width:C,height:Q,screenwidth:h,screenheight:E,screencenteroffsetx:u,screencenteroffsety:d,pinrowleftpins:o.left,pinrowrightpins:o.right,pinrowtoppins:o.top,pinrowbottompins:o.bottom}}).superRefine((e,A)=>{e.male&&e.female&&A.addIssue({code:ze.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),JGe=e=>{const A=YGe.parse(e),{p:t,id:i,od:n,rows:o,numPins:s,pinlabelAnchorSide:r,pinlabelverticallyinverted:a,pinlabelorthogonal:g,pinlabeltextalignleft:c,pinlabeltextalignright:I,nopinlabels:l,doublesidedpinlabel:B,bottomsidepinlabel:C,pinRowSide:Q,width:h,height:E,pinRowHoleEdgeToEdgeDist:u,holes:d,holeXDist:f,holeYDist:m,holeInset:w,pinrowleftpins:D,pinrowrightpins:S,pinrowtoppins:_,pinrowbottompins:b,usbposition:R,usbtype:F,screen:H,screenwidth:Y,screenheight:J,screencenteroffsetx:O,screencenteroffsety:W}=A;let z="center";c?z="left":I&&(z="right");const tA=[],aA={left:D,right:S,top:_,bottom:b},eA=Object.values(aA).some(BA=>BA!==void 0&&BA>0),oA=(BA,pA,_A,FA)=>{if(A.smd?tA.push(li(BA,pA,_A,A.od,A.od)):BA===1?tA.push(HD({pn:BA,x:pA,y:_A,holeDiameter:i,rectPadWidth:n,rectPadHeight:n})):tA.push(vo(BA,pA,_A,i,n)),!l){const PA=pA+(FA==="left"?-n:FA==="right"?n:0),EA=_A+(FA==="top"?n:FA==="bottom"?-n:0);C||tA.push(ZF({fs:n/5,pn:BA,anchor_x:PA,anchor_y:EA,textalign:z,orthogonal:g,verticallyinverted:a,layer:"top"})),(B||C)&&tA.push(ZF({fs:n/5,pn:BA,anchor_x:PA,anchor_y:EA,textalign:z,orthogonal:g,verticallyinverted:a,layer:"bottom"}))}};if(eA){const BA=t;let pA=1;const _A=aA.left??0,FA=aA.right??0,PA=aA.top??0,EA=aA.bottom??0,xA=(dA,OA)=>{if(!(OA<=0))if(dA==="left"||dA==="right"){const VA=dA==="left"?-h/2+u:h/2-u,It=(OA-1)/2*BA;for(let mA=0;mA<OA;mA++)oA(pA,VA,It-mA*BA,dA),pA++}else{const VA=dA==="top"?E/2-u:-E/2+u,It=-((OA-1)/2)*BA;for(let mA=0;mA<OA;mA++)oA(pA,It+mA*BA,VA,dA),pA++}};xA("left",_A),xA("right",FA),xA("top",PA),xA("bottom",EA)}else{const BA=t;let pA=0,_A=0,FA=0,PA=0,EA=0,xA=0;const dA=Math.ceil(s/o);Q==="left"||Q==="right"?(pA=Q==="left"?-h/2+u:h/2-u,_A=(dA-1)/2*BA,FA=0,PA=-BA,EA=Q==="left"?BA:-BA,xA=0):(pA=-(dA-1)/2*BA,_A=Q==="top"?E/2-u:-E/2+u,FA=BA,PA=0,EA=0,xA=Q==="top"?-BA:BA);let OA=1;for(let VA=0;VA<o&&OA<=s;VA++)for(let It=0;It<dA&&OA<=s;It++){const mA=pA+It*FA+VA*EA,gt=_A+It*PA+VA*xA;if(A.smd?tA.push(li(OA,mA,gt,A.od,A.od)):OA===1?tA.push(HD({pn:OA,x:mA,y:gt,holeDiameter:i,rectPadWidth:n,rectPadHeight:n})):tA.push(vo(OA,mA,gt,i,n)),!l){const ZA=mA+(Q==="left"?-n:Q==="right"?n:0),GA=gt+(Q==="top"?n:Q==="bottom"?-n:0);C||tA.push(ZF({fs:n/5,pn:OA,anchor_x:ZA,anchor_y:GA,textalign:z,orthogonal:g,verticallyinverted:a,layer:"top"})),(B||C)&&tA.push(ZF({fs:n/5,pn:OA,anchor_x:ZA,anchor_y:GA,textalign:z,orthogonal:g,verticallyinverted:a,layer:"bottom"}))}OA++}}if(d)for(const BA of d){let pA=0,_A=0;BA==="topleft"?(pA=-h/2+w,_A=E/2-w):BA==="topright"?(pA=h/2-w,_A=E/2-w):BA==="bottomleft"?(pA=-h/2+w,_A=-E/2+w):BA==="bottomright"?(pA=h/2-w,_A=-E/2+w):BA==="center"&&(pA=0,_A=0),f!==void 0&&(pA+=f),m!==void 0&&(_A+=m),tA.push(vo(s+d.indexOf(BA)+1,pA,_A,i,n))}if(!A.nosilkscreen){const BA=[{x:-h/2,y:-E/2},{x:h/2,y:-E/2},{x:h/2,y:E/2},{x:-h/2,y:E/2},{x:-h/2,y:-E/2}];tA.push(VF(BA,{stroke_width:.1,layer:"top"}))}const rA=Li(0,E/2+1,.5);if(tA.push(rA),R&&F){let BA,pA;if(F==="c")BA=8,pA=3;else if(F==="micro")BA=6,pA=2;else return{circuitJson:tA,parameters:A};let _A;if(R==="left")_A=[{x:-h/2,y:-BA/2},{x:-h/2+pA,y:-BA/2},{x:-h/2+pA,y:BA/2},{x:-h/2,y:BA/2},{x:-h/2,y:-BA/2}];else if(R==="right")_A=[{x:h/2-pA,y:-BA/2},{x:h/2,y:-BA/2},{x:h/2,y:BA/2},{x:h/2-pA,y:BA/2},{x:h/2-pA,y:-BA/2}];else if(R==="top")_A=[{x:-BA/2,y:E/2-pA},{x:BA/2,y:E/2-pA},{x:BA/2,y:E/2},{x:-BA/2,y:E/2},{x:-BA/2,y:E/2-pA}];else if(R==="bottom")_A=[{x:-BA/2,y:-E/2},{x:BA/2,y:-E/2},{x:BA/2,y:-E/2+pA},{x:-BA/2,y:-E/2+pA},{x:-BA/2,y:-E/2}];else return{circuitJson:tA,parameters:A};tA.push(VF(_A,{stroke_width:.1,layer:"top"}))}if(H){const BA=Y/2,pA=J/2,_A=O,FA=W,PA=[{x:-BA+_A,y:-pA+FA},{x:BA+_A,y:-pA+FA},{x:BA+_A,y:pA+FA},{x:-BA+_A,y:pA+FA},{x:-BA+_A,y:-pA+FA}];tA.push(VF(PA,{stroke_width:.05,layer:"top"}))}return{circuitJson:tA,parameters:A}},TGe=Ui.extend({fn:L(),num_pins:qA().default(3),inline:TA().default(!1),p:L().default("1.27mm"),id:L().default("0.75mm"),od:L().default("1.3mm"),w:L().default("4.8mm"),h:L().default("4.0mm")}),PGe=e=>{const A=TGe.parse(e),t=Number.parseFloat(A.p),i=Number.parseFloat(A.w),n=Number.parseFloat(A.h),o=A.inline?1.05:Number.parseFloat(A.od),s=A.inline?1.5:o,r=[HD({pn:1,x:0,y:0,holeDiameter:A.id,rectPadWidth:o,rectPadHeight:s}),A.inline?TY(2,t,0,Number.parseFloat(A.id),o,s):vo(2,t,t,A.id,o),A.inline?TY(3,t*2,0,Number.parseFloat(A.id),o,s):vo(3,t*2,0,A.id,o)],a=i/2,g=A.inline?t-.09:t,c=.2,I=c+a-n,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=Li(g,c+a+1,.5);return{circuitJson:[...r,B,C],parameters:A}};function KGe(e){return e!=null}var qGe=(e,A)=>{if(!A)return e;const t=e.filter(c=>c.type==="pcb_smtpad"||c.type==="pcb_plated_hole"||c.type==="pcb_thtpad");if(t.length===0)return e;let i=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;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),n=Math.max(n,Q),o=Math.min(o,h),s=Math.max(s,E)};for(const c of t)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+n)/2,g=(o+s)/2;break;case"bottomleft":a=i,g=o;break;case"bottomcenter":case"centerbottom":a=(i+n)/2,g=o;break;case"topcenter":case"centertop":a=(i+n)/2,g=s;break;case"leftcenter":case"centerleft":a=i,g=(o+s)/2;break;case"rightcenter":case"centerright":a=n,g=(o+s)/2;break;case"pin1":{const c=t.find(I=>I.port_hints?.[0]==="1")||t[0];a=c.x,g=c.y;break}}if(a===0&&g===0)return e;for(const c of e){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 e},OGe=(e,A)=>{const t=e.filter(i=>i.type==="pcb_silkscreen_text");if(t.length===0)return e;for(const i of t)A.norefdes&&(i.text="");return e},WGe=(e,A)=>A.nosilkscreen?e.filter(t=>t.type!=="pcb_silkscreen_path"&&t.type!=="pcb_silkscreen_text"):e,ZGe=e=>{let A=CV();const i=e.replace(/^((?:\d{4}|\d{5}))(?=$|_|x)/,"res$1").split(/_(?!metric)/).map(n=>{const o=n.match(/([a-zA-Z]+)([\(\d\.\+\?].*)?/);if(!o)return null;const[,s,r]=o;if(!s)return null;const a=s.toLowerCase();return r?.includes("?")?null:{fn:a,v:r}}).filter(KGe);for(const{fn:n,v:o}of i)A=A[n](o);return A.setString(e),A},VGe=()=>Object.keys(Gb),CV=()=>{const e=new Proxy({},{get:(A,t)=>{if(t==="soup"||t==="circuitJson"){if("fn"in A&&Gb[A.fn])return()=>{const{circuitJson:i}=Gb[A.fn](A),n=WGe(i,A),o=OGe(n,A);return qGe(o,A.origin)};if(!Gb[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 "${t}"`)}}if(t==="json"){if(!Gb[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>Gb[A.fn](A).parameters}return t==="getFootprintNames"?()=>Object.keys(Gb):t==="params"?()=>A:t==="setString"?i=>(A.string=i,e):i=>(Object.keys(A).length===0?`${t}${i}`in Gb?(A[`${t}${i}`]=!0,A.fn=`${t}${i}`):(A[t]=!0,A.fn=t,t==="res"||t==="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(t)||(A[t]=i??!0),e)}});return e};CV.string=ZGe,CV.getFootprintNames=VGe;var jGe=CV,aet=Symbol("Fragment");function $uA(e,A,...t){const i=t.length?t:A?.children!==void 0?[A.children]:[],n=[],o=(Array.isArray(i)?i:[i]).flat(1/0);for(const s of o)s==null||s===!1||(Array.isArray(s)?n.push(...s):n.push(s));return{type:e,props:(A&&A.children!==void 0?{...A,children:void 0}:A)||{},children:n}}var Qe=Symbol("Cuboid"),get=Symbol("Cube"),Kl=Symbol("Cylinder"),QV=Symbol("Sphere"),PY=Symbol("RoundedCuboid"),Zi=Symbol("Translate"),rC=Symbol("Rotate"),zQ=Symbol("Union"),Im=Symbol("Subtract"),Sc=Symbol("Hull"),mo=Symbol("Colorize"),KY=Symbol("Polygon"),qY=Symbol("ExtrudeLinear"),_f=Symbol("RoundedCylinder"),Jn=aet,zA=(e,A,t)=>$uA(e,A),qe=(e,A,t)=>$uA(e,A),pB=({center:e,width:A,length:t,height:i,heightAboveSurface:n=.15,color:o="#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,t)*s,d=Math.max(A-u,A*r),f=Math.max(t-u,t*r),m=Math.min(A,t)*.12,w=c??m,D={x:0,y:t/2-w*.25,z:i},S=I??D,_=qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.005,children:zA(Qe,{size:[d,f,.01]})}),zA(Zi,{z:h,children:zA(Qe,{size:[A,t,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:h,children:zA(Qe,{size:[A,t,.01]})}),zA(Zi,{z:h+E,children:zA(Qe,{size:[d,f,.01]})})]})]}),b=(F,H)=>zA(Zi,{offset:{x:F,y:H,z:0},children:zA(rC,{rotation:[0,0,Math.PI/4],children:zA(Qe,{size:[Q*Math.SQRT2,Q*Math.SQRT2,i*3]})})});let R=_;if(Q>0){const F=A/2,H=t/2;R=qe(Im,{children:[_,b(F,H),b(-F,H),b(F,-H),b(-F,-H)]})}return zA(mo,{color:o,children:zA(Zi,{offset:e,children:zA(Zi,{offset:{x:0,y:0,z:n},children:g?qe(Im,{children:[R,zA(Zi,{offset:S,children:zA(rC,{rotation:l,children:zA(Kl,{radius:w,height:C})})})]}):R})})})},zGe=e=>Array.from({length:e},(A,t)=>t);function AdA(e,A){if(e.length<2)throw new Error("Stroke must have at least two points");const t=Array.isArray(e[0])?e.map(([c,I])=>({x:c,y:I})):e,i=A/2,n=[],o=[];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?n.push(B):o.unshift(B)}const a=s(t[0],t[1]);r(t[0],a,1),r(t[0],a,-1);for(let c=1;c<t.length-1;c++){const I=t[c-1],l=t[c],B=t[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(t[t.length-2],t[t.length-1]);return r(t[t.length-1],g,1),r(t[t.length-1],g,-1),[...n,...o]}var XGe=e=>{const A=Math.min(...e.map(r=>r.x)),t=Math.max(...e.map(r=>r.x)),i=Math.min(...e.map(r=>r.y)),s=5.47/(Math.max(...e.map(r=>r.y))-i);return e.map(r=>({x:(r.x-A-(t-A)/2)*s,y:(r.y-i)*s}))},$Ge=XGe([{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}]),cet=5.47,hV=.5,ARe=({x:e,y:A,z:t})=>{const i=e>0;return qe(Jn,{children:[zA(Zi,{offset:{x:e+.25/2,y:A,z:t},children:zA(rC,{rotation:["-90deg",0,"90deg"],children:zA(qY,{height:.25,children:zA(KY,{points:$Ge.slice().reverse().map(n=>[n.x,n.y])})})})}),zA(Zi,{offset:{x:e,y:A+(i?1:-1),z:t},children:zA(rC,{rotation:["-90deg","90deg",i?"180deg":"0deg"],children:zA(qY,{height:2,children:zA(KY,{points:AdA([[0,0],[-1,0],[-1,-1]],.25).map(n=>[n.x,n.y])})})})})]})},tRe=({numPins:e=8,pitch:A=2.54,bodyWidth:t=6.4,rowSpacing:i})=>{const n=Math.floor(e/2),o=i??(t>=7?t:t+1.22),s=t>=7?o-1.22:t;return qe(Jn,{children:[zGe(e).map(r=>{const a=r%n,g=(Math.floor(r/n)-.5)*2;return zA(ARe,{x:g*o/2,y:a*A-(n-1)/2*A,z:cet/2+hV})}),zA(pB,{width:s,length:n*A+.5,height:cet-hV,heightAboveSurface:hV,center:{x:0,y:0,z:hV}})]})};function eRe(e,{height:A,padContactLength:t,curveLength:i,bodyDistance:n,steepness:o=10}){i||(i=n*.3);let s=n-t-i;s<0&&(i+=s,s=0);const r=t*.75,a=t+i+(n-t-i)*.25;if(e<=r)return 0;if(e>=a)return A;const g=(e-r)/(a-r);return A/(1+Math.exp(-o*(g-.5)))}var no=e=>{const{thickness:A,width:t,padContactLength:i,bodyDistance:n,height:o,rotation:s}=e,r=15,a=Array.from({length:r}).map((c,I)=>I/(r-1)*n).map(c=>[c,eRe(c,e)]),g=AdA(a,A);return zA(mo,{color:"#fff",children:zA(Zi,{offset:{z:0,y:0,x:0,...e.position},children:zA(rC,{rotation:["90deg",0,s??0],children:zA(Zi,{offset:{x:0,y:0,z:-t/2},children:zA(qY,{height:t,children:zA(KY,{points:g.map(c=>[c.x,c.y])})})})})})})},iRe=({pinCount:e,leadLength:A,leadWidth:t,pitch:i,bodyWidth:n})=>{const o=Math.ceil(e/2),s=i*e/2+t/2,r=(o-1)*i/2,a=.25;return qe(Jn,{children:[Array.from({length:o}).map((g,c)=>zA(no,{position:{x:-n/2-A,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),Array.from({length:o}).map((g,c)=>zA(no,{rotation:Math.PI,position:{x:n/2+A,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),zA(pB,{center:{x:0,y:0,z:a/2},width:n-t-1,length:s,height:1.5})]})},nRe=({pinCount:e,padContactLength:A=.4,leadWidth:t=.2,pitch:i=.65,bodyWidth:n=3})=>{const o=Math.ceil(e/2),s=(o-1)*i/2,r=.2;return qe(Jn,{children:[Array.from({length:o}).map((a,g)=>zA(no,{position:{x:-n/2-A-.3,y:g*i-s,z:r/2},width:t,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),Array.from({length:o}).map((a,g)=>zA(no,{rotation:Math.PI,position:{x:n/2+A+.3,y:g*i-s,z:r/2},width:t,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),zA(pB,{center:{x:0,y:0,z:r/2},width:n,length:n,height:1.1,notchRadius:.35,heightAboveSurface:.1,taperRatio:.09})]})},tdA=1,edA=.5,I2=.5,OY=.2,oRe=tdA-OY*2,Iet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[oRe,edA,I2],offset:[0,0,I2/2],color:e}),zA(Qe,{size:[OY,I2,edA],offset:[tdA/2-OY/2,0,I2/2],color:"#ccc"}),zA(Qe,{size:[OY,I2,edA],offset:[-tdA/2+OY/2,0,I2/2],color:"#ccc"})]}),idA=1.6,sRe=idA-.3*2,EV=.3,ndA=.85,l2=.6,Bet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[sRe,ndA,l2],offset:[0,0,l2/2],color:e}),zA(Qe,{size:[EV,ndA,l2],offset:[idA/2-EV/2,0,l2/2],color:"#ccc"}),zA(Qe,{size:[EV,ndA,l2],offset:[-idA/2+EV/2,0,l2/2],color:"#ccc"})]}),odA=2,sdA=1.25,B2=.55,WY=.5,rRe=odA-WY*2,Cet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[rRe,sdA,B2],offset:[0,0,B2/2],color:e}),zA(Qe,{size:[WY,sdA,B2],offset:[odA/2-WY/2,0,B2/2],color:"#ccc"}),zA(Qe,{size:[WY,sdA,B2],offset:[-odA/2+WY/2,0,B2/2],color:"#ccc"})]}),aRe=({pinCount:e,pitch:A,leadWidth:t,padContactLength:i,bodyWidth:n})=>{const o=e/4;A||(A=gRe(e,n)),i||(i=cRe(e)),t||(t=IRe(e,n)),n||(n=A*(o+4));const s=n,r=(o-1)*A/2,a=s+2*i,g=a,c=.8,I=.15,l=(g-n)/2+.5;return qe(Jn,{children:[Array.from({length:o}).map((B,C)=>zA(no,{position:{x:-g/2-.4,y:C*A-r,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:Math.PI,position:{x:g/2+.4,y:C*A-r,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:Math.PI/2,position:{x:C*A-r,y:-a/2-.4,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:-Math.PI/2,position:{x:C*A-r,y:a/2+.4,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),zA(pB,{center:{x:0,y:0,z:0},width:n,length:s,height:1.5,taperRatio:.03,chamferSize:.7,notchPosition:{x:-(s/2-1.5),y:n/2-1.5,z:1.5},notchRadius:1.5/2})]})},gRe=(e,A)=>{switch(e){case 44:case 64:return .8;case 52:return A===14?1:.65;case 208:return .5;default:return .5}},cRe=e=>{switch(e){case 32:return .6;case 40:return .6;case 52:case 64:return .65;case 208:return 1.65;default:return .6}},IRe=(e,A)=>{switch(e){case 44:case 64:return .5;case 52:return A===14?.45:.55;case 208:return .3;default:return .25}},Qet=({x:e,y:A,pinThickness:t,shortSidePinLength:i,longSidePinLength:n,bodyHeight:o,bodyLength:s=2.54,bodyWidth:r=2.54,flipZ:a,faceup:g,smd:c,rightangle:I})=>qe(Jn,{children:[zA(Zi,{y:I?-3:0,children:zA(Qe,{color:"#222",size:[s,r,o],center:[e,A,a(o/2)]})}),!g&&zA(mo,{color:"gold",children:c?zA(no,{rotation:-Math.PI/2,position:{x:e,y:A+1,z:t/2},thickness:t,width:t,height:t,padContactLength:2,bodyDistance:3}):qe(Sc,{children:[zA(Qe,{color:"gold",size:[t,t,i*.9],center:[e,A,a(o*.9+o/2)]}),zA(Qe,{color:"gold",size:[t/1.8,t/1.8,i],center:[e,A,a(o+o/2)]})]})}),zA(mo,{color:"gold",children:zA(Zi,{y:I?-3.9:0,z:I?1:0,children:zA(rC,{rotation:I?[-Math.PI/2,0,0]:[0,0,0],children:qe(Sc,{children:[zA(Qe,{color:"gold",size:[t,t,n*.9],center:[e,A,a(-n/2*.9)]}),zA(Qe,{color:"gold",size:[t/1.8,t/1.8,n],center:[e,A,a(-n/2)]})]})})})})]}),lRe=({numberOfPins:e,pitch:A=2.54,longSidePinLength:t=6,invert:i,faceup:n,rows:o=1,smd:s,rightangle:r})=>{const c=Math.ceil(e/o),I=2.54,l=3,B=-((c-1)/2)*A,C=!s&&!r?-2-1.6:0,Q=h=>(i||n?-h+2:h)+C;return zA(Jn,{children:Array.from({length:e},(h,E)=>{const u=Math.floor(E/c),d=E%c,f=B+d*A,m=-u*I;return zA(Qet,{x:f,y:m,pinThickness:.63,shortSidePinLength:l,longSidePinLength:t,bodyHeight:2,flipZ:Q,faceup:n,smd:s,rightangle:r},E)})})},BRe=e=>{const A=["left","bottom","right","top"],{pin_count:t,pn:i,w:n,h:o,p:s,pl:r}=e,a=t/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:-n/2-B,y:l/2-c*s,o:"vert"};case"bottom":return{x:-I/2+c*s,y:-o/2-B,o:"horz"};case"right":return{x:n/2+B,y:-l/2+c*s,o:"vert"};case"top":return{x:I/2-c*s,y:o/2+B,o:"horz"};default:throw new Error("Invalid pin number")}},CRe=({num_pins:e,cw:A,ccw:t,startingpin:i})=>{const n=[],o=e/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=o:r.bottomside&&r.leftpin?s=o+1:r.bottomside&&r.rightpin?s=o*2:r.rightside&&r.bottompin?s=o*2+1:r.rightside&&r.toppin?s=o*3:r.topside&&r.rightpin?s=o*3+1:r.topside&&r.leftpin&&(s=o*4),n.push(-1);for(let a=0;a<e;a++)n[s]=a+1,s++,s>e&&(s=1);return n},QRe=({num_pins:e=16,bodyWidth:A=9,bodyLength:t=9,bodyThickness:i=.8,thermalPadSize:n,padWidth:o=.25,padLength:s=.25,pitch:r=.5,thermalPadThickness:a=.05})=>{const g=CRe({num_pins:e,cw:!0,ccw:!0}),c=[];for(let I=0;I<e;I++){const{x:l,y:B,o:C}=BRe({pin_count:e,pn:I+1,w:A,h:t,p:r,pl:s});let Q=o,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 qe(Jn,{children:[zA(mo,{color:"grey",children:zA(Qe,{center:{x:0,y:0,z:i/2},size:[A,t,i]})}),c.map((I,l)=>zA(Qe,{center:{x:I.x,y:I.y,z:a/2},size:[I.pw,I.pl,a]})),n?.length!==void 0&&n?.width!==void 0&&zA(Qe,{center:{x:0,y:0,z:a/2},size:[n.width,n.length,a]})]})},hRe=QRe,ERe=()=>{const a=1.1999999999999997;return qe(Jn,{children:[zA(no,{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}),zA(no,{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}),zA(no,{position:{x:-2.8/2-a/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(no,{position:{x:-2.8/2-a/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(no,{position:{x:-2.8/2-a/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(pB,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2})]})},uRe=ERe,dRe=({fullWidth:e=2.9,fullLength:A=2.8})=>{const c=(e-1.92)/2+.3;return qe(Jn,{children:[zA(no,{rotation:Math.PI,position:{x:e/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(no,{position:{x:-e/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(no,{position:{x:-e/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(pB,{center:{x:0,y:0,z:0},width:1.92,length:2.9,height:1.1,straightHeightRatio:.45,heightAboveSurface:.05})]})},rdA=.6,adA=.3,C2=.33,ZY=.1,pRe=rdA-ZY*2,het=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[pRe,adA,C2],offset:[0,0,C2/2],color:e}),zA(Qe,{size:[ZY,adA,C2],offset:[rdA/2-ZY/2,0,C2/2],color:"#ccc"}),zA(Qe,{size:[ZY,adA,C2],offset:[-rdA/2+ZY/2,0,C2/2],color:"#ccc"})]}),gdA=.4,cdA=.2,Q2=.13,VY=.07,fRe=gdA-VY*2,Eet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[fRe,cdA,Q2],offset:[0,0,Q2/2],color:e}),zA(Qe,{size:[VY,cdA,Q2],offset:[gdA/2-VY/2,0,Q2/2],color:"#ccc"}),zA(Qe,{size:[VY,cdA,Q2],offset:[-gdA/2+VY/2,0,Q2/2],color:"#ccc"})]}),IdA=3.2,ldA=1.6,h2=.9,jY=.5,yRe=IdA-jY*2,uet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[yRe,ldA,h2],offset:[0,0,h2/2],color:e}),zA(Qe,{size:[jY,ldA,h2],offset:[IdA/2-jY/2,0,h2/2],color:"#ccc"}),zA(Qe,{size:[jY,ldA,h2],offset:[-IdA/2+jY/2,0,h2/2],color:"#ccc"})]}),BdA=3.2,CdA=2.5,E2=1,zY=.6,mRe=BdA-zY*2,det=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[mRe,CdA,E2],offset:[0,0,E2/2],color:e}),zA(Qe,{size:[zY,CdA,E2],offset:[BdA/2-zY/2,0,E2/2],color:"#ccc"}),zA(Qe,{size:[zY,CdA,E2],offset:[-BdA/2+zY/2,0,E2/2],color:"#ccc"})]}),QdA=5,hdA=2.5,u2=1.4,XY=.6,wRe=QdA-XY*2,pet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[wRe,hdA,u2],offset:[0,0,u2/2],color:e}),zA(Qe,{size:[XY,hdA,u2],offset:[QdA/2-XY/2,0,u2/2],color:"#ccc"}),zA(Qe,{size:[XY,hdA,u2],offset:[-QdA/2+XY/2,0,u2/2],color:"#ccc"})]}),EdA=6.3,udA=3.2,d2=1.8,$Y=.8,DRe=EdA-$Y*2,fet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[DRe,udA,d2],offset:[0,0,d2/2],color:e}),zA(Qe,{size:[$Y,udA,d2],offset:[EdA/2-$Y/2,0,d2/2],color:"#ccc"}),zA(Qe,{size:[$Y,udA,d2],offset:[-EdA/2+$Y/2,0,d2/2],color:"#ccc"})]}),yet=({x:e,y:A,z:t=0,pitch:i=2.54,legsLength:n=3,innerDiameter:o=.945,bodyHeight:s=5,bodyLength:r=i,bodyWidth:a=i,flipZ:g})=>{const c=o/1.5,I=c*1.6;return qe(Jn,{children:[zA(mo,{color:"#1a1a1a",children:qe(Im,{children:[zA(Qe,{color:"#000",size:[r,a,s],center:[e,A,g(t+s/2)]}),o?zA(Kl,{height:s+.1,radius:o/2,center:[e,A,g(t+s/2)],color:"#222"}):zA(Qe,{size:[I,I,s],center:[e,A,g(t+s/2)]})]})}),qe(mo,{color:"silver",children:[qe(Sc,{children:[zA(Qe,{color:"silver",size:[c,c,n*.9],center:[e,A,g(t+-n/2*.9)]}),zA(Qe,{color:"silver",size:[c/1.8,c/1.8,n],center:[e,A,g(t+-n/2)]})]}),zA(Qe,{color:"silver",size:[I,I,I*.5],center:[e,A,g(t+I/2*.5)]})]})]})},SRe=({numberOfPins:e,pitch:A=2.54,legsLength:t=3,innerDiameter:i=.945,rows:n=1,invert:o})=>{const r=Math.ceil(e/n),a=2.54,g=-((r-1)/2)*A,c=I=>o?-I+5:I;return zA(Jn,{children:Array.from({length:e},(I,l)=>{const B=Math.floor(l/r),C=l%r,Q=g+C*A,h=-B*a;return zA(yet,{x:Q,y:h,pitch:A,legsLength:t,innerDiameter:i,flipZ:c},l)})})},bRe=({width:e,length:A,innerDiameter:t=1})=>{const i=e,n=A,o=e*.7,s=t/2.5;return qe(Jn,{children:[zA(PY,{color:"#1a1a1f",center:[0,0,o/2],size:[n,n,o],roundRadius:.3}),zA(PY,{color:"#f2f2f2",center:[0,0,o+o*.1/2.5],size:[n,n,o*.1],roundRadius:.14}),zA(Kl,{color:"#1a1a1f",height:o*.8,radius:i/3,center:[0,0,o+o*.8/2]}),zA(Kl,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[n/3,n/3,o+o*.1/2]}),zA(Kl,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[-n/3,-n/3,o+o*.1/2]}),zA(Kl,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[-n/3,n/3,o+o*.1/2]}),zA(Kl,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[n/3,-n/3,o+o*.1/2]}),zA(uV,{thickness:t/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:-i/2,y:-n/2,z:-o*1.2}}),zA(uV,{thickness:t/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:-i/2,y:n/2,z:-o*1.2},rotation:Math.PI}),zA(uV,{thickness:t/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:i/2,y:n/2,z:-o*1.2},rotation:Math.PI}),zA(uV,{thickness:t/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:i/2+t/3.6,y:-n/2,z:-o*1.2}})]})},uV=e=>{const{thickness:A,width:t,horizontalLength:i,verticalLength:n,rotation:o=0,position:s}=e,r=[[0,i],[-n/3,i/3],[-n/5,i/4],[0,0]],a=AdA(r,A);return zA(mo,{color:"#f2f2f2",children:zA(Zi,{offset:{x:s?.x||0,y:s?.y||0,z:s?.z||0},children:zA(rC,{rotation:[0,55,o],children:zA(qY,{height:t,children:zA(KY,{points:a.map(g=>[g.y,g.x])})})})})})},xRe=({pinCount:e,leadLength:A,leadWidth:t,pitch:i,bodyWidth:n})=>{const o=Math.ceil(e/2),s=(o-1)*i/2,r=.25,a=1,g=.8,c=A*0,I=i*(o-1)+t+.2,l=n*.55;return qe(Jn,{children:[Array.from({length:o}).map((B,C)=>zA(no,{position:{x:-n/2-c,y:C*i-s,z:r/2},width:t,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:Math.PI,position:{x:n/2+c,y:C*i-s,z:r/2},width:t,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),zA(pB,{center:{x:0,y:0,z:r/2},width:l,length:I,height:a})]})},_Re=({pinCount:e,pitch:A,leadWidth:t,leadLength:i,bodyWidth:n,bodyLength:o})=>{const s=e===8?{pitch:.65,leadWidth:.3}:{pitch:.5,leadWidth:.225},r=isNaN(parseFloat(A))?s.pitch:parseFloat(A),a=isNaN(parseFloat(t))?s.leadWidth:parseFloat(t)*.8,g=isNaN(parseFloat(n))?2.6:parseFloat(n)*.8,c=isNaN(parseFloat(o))?2+Number(r)*1.4:parseFloat(o),I=e/2,l=(I-1)*r/2,B=.15,C=.8,Q=4.5,h=(Q-g)/2,E=h*.5;return qe(Jn,{children:[Array.from({length:I}).map((u,d)=>zA(no,{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)=>zA(no,{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})),zA(pB,{center:{x:0,y:0,z:B/2},width:g,length:c,height:1})]})},kRe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.5,.6,.12],center:[-.725,0,.12/2]}),zA(Qe,{color:"#ccc",size:[.5,.6,.12],center:[.725,0,.12/2]}),zA(mo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.3/2,children:zA(Qe,{size:[1.65,.8,.3]})}),qe(Sc,{children:[zA(Zi,{z:.3,children:zA(Qe,{size:[1.65,.8,.01]})}),zA(Zi,{z:.6,children:zA(Qe,{size:[1.65-.2,.8-.2,.01]})})]})]})})]}),vRe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.26,.51,.12],center:[-.325,0,.12/2]}),zA(Qe,{color:"#ccc",size:[.26,.51,.12],center:[.325,0,.12/2]}),zA(mo,{color:"#222",children:zA(Zi,{z:.47/2+.02,children:zA(Qe,{size:[.98,.58,.47]})})}),zA(Qe,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,.26/2,.47/4]}),zA(Qe,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,-.26/2,.47/4]}),zA(Qe,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[.65/2,0,.47/4]}),zA(Qe,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[-.65/2,0,.47/4]})]}),FRe=()=>{const g=zA(mo,{color:"#1a1a1a",children:qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.13,children:zA(Qe,{size:[4,3,.03]})}),zA(Zi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})}),zA(Zi,{z:2.3,children:zA(Qe,{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 zA(mo,{color:"#c0c0c0",children:qe(zQ,{children:[zA(Qe,{size:[2.3*.8,1.45,.2],center:[C,0,.2/2]}),zA(Qe,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),zA(Qe,{size:[E,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return qe(Jn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},MRe=()=>{const g=zA(mo,{color:"#1a1a1a",children:qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.13,children:zA(Qe,{size:[4,3,.03]})}),zA(Zi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})}),zA(Zi,{z:2.3,children:zA(Qe,{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 zA(mo,{color:"#c0c0c0",children:qe(zQ,{children:[zA(Qe,{size:[2.3*.8,1.45,.2],center:[C,0,.2/2]}),zA(Qe,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),zA(Qe,{size:[E,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return qe(Jn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},GRe=()=>{const g=zA(mo,{color:"#1a1a1a",children:qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.21000000000000002,children:zA(Qe,{size:[6.3999999999999995,5.6,.03]})}),zA(Zi,{z:1.15,children:zA(Qe,{size:[6.8,6,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:1.15,children:zA(Qe,{size:[6.8,6,.01]})}),zA(Zi,{z:2.3,children:zA(Qe,{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 zA(mo,{color:"#c0c0c0",children:qe(zQ,{children:[zA(Qe,{size:[2.3*.8,2.95,.2],center:[C,0,.2/2]}),zA(Qe,{size:[.2,2.95,1.14],center:[Q,0,1.14/2+.2]}),zA(Qe,{size:[E,2.95,.2],center:[u,0,.2/2+1.14]})]})})};return qe(Jn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},RRe=()=>{const I=zA(mo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.27,children:zA(Qe,{size:[2.9,1.9,.54]})}),qe(Sc,{children:[zA(Zi,{z:.54,children:zA(Qe,{size:[2.9,1.9,.01]})}),zA(Zi,{z:1.08,children:zA(Qe,{size:[2.6999999999999997,1.7,.01]})})]})]})});return qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[1,1.2,.25],center:[-1.3,0,.25/2]}),zA(Qe,{color:"#ccc",size:[1,1.2,.25],center:[1.3,0,.25/2]}),I]})},NRe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[1,.6,.12],center:[-1.3,0,.12/2]}),zA(Qe,{color:"#ccc",size:[1,.6,.12],center:[1.3,0,.12/2]}),zA(mo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.55/2,children:zA(Qe,{size:[2.7,1.6,.55]})}),qe(Sc,{children:[zA(Zi,{z:.55,children:zA(Qe,{size:[2.7,1.6,.01]})}),zA(Zi,{z:1.1,children:zA(Qe,{size:[2.7-.2,1.6-.2,.01]})})]})]})})]}),LRe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[1,.9,.2],center:[-1.3,0,.2/2]}),zA(Qe,{color:"#ccc",size:[1,.9,.2],center:[1.3,0,.2/2]}),zA(mo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.2/2,children:zA(Qe,{size:[2.75,1.8,.2]})}),qe(Sc,{children:[zA(Zi,{z:.2,children:zA(Qe,{size:[2.75,1.8,.01]})}),zA(Zi,{z:1,children:zA(Qe,{size:[2.75-.4,1.8-.4,.01]})})]})]})}),zA(Qe,{color:"#777",size:[.2,1.8-.4,.01],center:[-1.3+.4,0,1]})]}),URe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.9,.9,.2],center:[-1.225,0,.2/2]}),zA(Qe,{color:"#ccc",size:[.9,.9,.2],center:[1.225,0,.2/2]}),zA(mo,{color:"#222",children:qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.2,children:zA(Qe,{size:[2.6-.1/2,1.7-.1/2,.01]})}),zA(Zi,{z:.01,children:zA(Qe,{size:[2.6-.1,1.7-.1,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:.2,children:zA(Qe,{size:[2.6,1.7,.01]})}),zA(Zi,{z:1,children:zA(Qe,{size:[2.6-.4,1.7-.4,.01]})})]})]})}),zA(Qe,{color:"#777",size:[.2*2.7,1.7-.4,.02],center:[-1.225+.4,0,1]})]}),HRe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.9,1.75,.2],center:[-1.825,0,.2/2]}),zA(Qe,{color:"#ccc",size:[.9,1.75,.2],center:[1.825,0,.2/2]}),zA(mo,{color:"#222",children:qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.2,children:zA(Qe,{size:[3.8-.05/2,2.5-.05/2,.01]})}),zA(Zi,{z:.01,children:zA(Qe,{size:[3.8-.05,2.5-.05,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:.2,children:zA(Qe,{size:[3.8,2.5,.01]})}),zA(Zi,{z:1,children:zA(Qe,{size:[3.8-.4,2.5-.4,.01]})})]})]})}),zA(Qe,{color:"#777",size:[.2*2.7,2.5-.4,.02],center:[-1.825+.4,0,1]})]}),YRe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.4,.25,.14],center:[-.4,0,.14/2]}),zA(Qe,{color:"#ccc",size:[.4,.25,.14],center:[.4,0,.14/2]}),zA(mo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.14/2,children:zA(Qe,{size:[.8,.6,.14]})}),qe(Sc,{children:[zA(Zi,{z:.14,children:zA(Qe,{size:[.8,.6,.01]})}),zA(Zi,{z:.37,children:zA(Qe,{size:[.8-.1,.6-.1,.01]})})]})]})})]}),JRe=()=>{const c=3.0999999999999996;return qe(Jn,{children:[zA(no,{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}),zA(no,{position:{x:-6.6/2-c/4,y:0,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(no,{position:{x:-6.6/2-c/4,y:-2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(no,{position:{x:-6.6/2-c/4,y:2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(pB,{center:{x:0,y:0,z:0},width:3.5,length:6.5,height:1.7,includeNotch:!1,taperRatio:.06,straightHeightRatio:.45})]})},TRe=()=>qe(Jn,{children:[Array.from({length:16}).map((B,C)=>zA(no,{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)=>zA(no,{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)=>zA(no,{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)=>zA(no,{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})),zA(pB,{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})]}),PRe=TRe,KRe=()=>{const g=.7999999999999998;return qe(Jn,{children:[zA(no,{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}),zA(no,{position:{x:-2.05/2-g/4,y:-.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),zA(no,{position:{x:-2.05/2-g/4,y:.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),zA(pB,{center:{x:0,y:0,z:0},width:1.25,length:2,height:.9,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})]})},qRe=({pinCount:e,pitch:A,leadWidth:t,padContactLength:i,bodyWidth:n})=>{const o=e/4;if(o!==Math.floor(o))throw new Error(`LQFP pinCount must be divisible by 4, got ${e}`);A||(A=.5),i||(i=.6),t||(t=.22),n||(n=A*(o+4));const s=n,r=(o-1)*A/2,a=s+3.3*i,g=a,c=.8,I=.2,l=(g-n)/2+.4;return qe(Jn,{children:[Array.from({length:o}).map((B,C)=>zA(no,{position:{x:-g/2-.36,y:C*A-r,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:Math.PI,position:{x:g/2+.36,y:C*A-r,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:Math.PI/2,position:{x:C*A-r,y:-a/2-.36,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:-Math.PI/2,position:{x:C*A-r,y:a/2+.36,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),zA(pB,{center:{x:0,y:0,z:0},width:n,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})]})},ORe=()=>{const i=.20900000000000002,n=.1,o=.3,s=.1,r=.2;return qe(Jn,{children:[zA(mo,{color:"#222",children:qe(zQ,{children:[zA(Qe,{size:[.85,1.2,i],center:[0,0,i/2]}),qe(Sc,{children:[zA(Zi,{z:i,children:zA(Qe,{size:[.85,1.2,.01]})}),zA(Zi,{z:.38,children:zA(Qe,{size:[.85-n,1.2-n,.01]})})]})]})}),zA(Qe,{color:"#ccc",size:[o,.25,s],center:[.55,0,s/2]}),zA(Qe,{color:"#ccc",size:[o,r,s],center:[-.55,.4,s/2]}),zA(Qe,{color:"#ccc",size:[o,r,s],center:[-.55,-.4,s/2]})]})},WRe=({num_pins:e,bodyWidth:A=5.3,bodyLength:t=5.3,bodyThickness:i=1,thermalPadSize:n,padWidth:o=t/5.3*.6,padLength:s=t/5.3*1,pitch:r=.5,thermalPadThickness:a=.2})=>{const g=[],c=Math.floor(e/2),I=r*(c-1);for(let l=0;l<e;l++){const B=l<c?"left":"right",C=l%c,Q=I/2-C*r,h=s,E=o,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 qe(Jn,{children:[zA(pB,{center:{x:0,y:0,z:0},width:A,length:t,height:i,heightAboveSurface:0,color:"grey",chamferSize:.2,taperRatio:0,notchPosition:{x:-(A/2-s),y:t/2-s,z:i}}),g.map((l,B)=>zA(Qe,{center:[l.x,l.y,a/2],size:[l.padSizeX,l.padSizeY,a]})),n?.length!==void 0&&n?.width!==void 0&&zA(Qe,{center:[0,0,a/2],size:[n.width,n.length,a]})]})},ZRe=({bodyLength:e=10.2,bodyWidth:A=4.65,bodyHeight:t=13.46,leadSpacing:i=5,leadDiameter:n=.8,leadLength:o=12.7,color:s="#ddd",leadColor:r="#b87333"})=>{const a=e/2,g=A/2,c=a-g,I=i/2,l=.85;return qe(Jn,{children:[qe(mo,{color:s,children:[qe(Sc,{children:[zA(_f,{height:t,roundRadius:.5,radius:g,center:[-c,0,t]}),zA(_f,{height:t,roundRadius:.5,radius:g,center:[c,0,t]})]}),qe(Sc,{children:[zA(_f,{height:l,roundRadius:.1,radius:g+.85,center:[-c,0,t/2+l/2]}),zA(_f,{height:l,roundRadius:.1,radius:g+.85,center:[c,0,t/2+l/2]})]})]}),qe(mo,{color:r,children:[zA(Kl,{height:o+t/2,radius:n/2,center:[-I+.06,0,-(o/2)+t/2]}),zA(Kl,{height:o+t/2,radius:n/2,center:[I-.06,0,-(o/2)+t/2]})]})]})},VRe=({bodyLength:e=1.4,bodyDiameter:A=1.1,color:t="#3a3a3aff",contactColor:i="#c6c6c6",cathodeIdentification:n="#111"})=>qe(Jn,{children:[zA(mo,{color:t,children:qe(rC,{rotation:[0,"90deg",0],children:[zA(PY,{size:[A,A,e-.2],roundRadius:.2,center:[-A/2,0,.05]}),zA(Kl,{height:.2/2,radius:A/2-.2,center:[-A/2,0,-e/2+.2/2]})]})}),zA(mo,{color:n,children:zA(rC,{rotation:[0,"90deg",0],children:zA(PY,{size:[A*1.01,A*1.01,e/3],roundRadius:.2,center:[-A/2,0,-e/4+.1]})})}),zA(mo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(_f,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,-e/2]})})}),zA(mo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(_f,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,e/2]})})})]}),jRe=({bodyLength:e=3.5,bodyDiameter:A=1.5,color:t="#3a3a3aff",contactColor:i="#c6c6c6"})=>qe(Jn,{children:[zA(mo,{color:t,children:zA(rC,{rotation:[0,"90deg",0],children:zA(_f,{height:e,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),zA(mo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(_f,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,-e/2]})})}),zA(mo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(_f,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,e/2]})})})]}),zRe=({bodyLength:e=3.9,bodyDiameter:A=2.5,color:t="#3a3a3aff",contactColor:i="#c6c6c6"})=>qe(Jn,{children:[zA(mo,{color:t,children:zA(rC,{rotation:[0,"90deg",0],children:zA(_f,{height:e,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),zA(mo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(_f,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,-e/2]})})}),zA(mo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(_f,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,e/2]})})})]}),XRe=({pinCount:e,padContactLength:A=.6,leadWidth:t=.41,pitch:i=1.27})=>{if(e%2!==0)throw new Error("MS012 pinCount must be even");const n=e/2,o=4.9,s=3.9,r=(n-1)*i/2,a=.2;return qe(Jn,{children:[Array.from({length:n}).map((g,c)=>zA(no,{position:{x:-s/2-A-.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:n}).map((g,c)=>zA(no,{rotation:Math.PI,position:{x:s/2+A+.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),zA(pB,{center:{x:0,y:0,z:a/2},width:s,length:o,height:1.55,notchPosition:{x:-.95,y:o/2-1,z:1.55},heightAboveSurface:.17,taperRatio:.09})]})},$Re=({pinCount:e=16,padContactLength:A=.6,leadWidth:t=.41,pitch:i=1.27})=>{if(e!==16)throw new Error("MS013 only supports 16 pins");const n=e/2,o=7.5,s=10.3,r=(n-1)*i/2,a=.2;return qe(Jn,{children:[Array.from({length:n}).map((g,c)=>zA(no,{position:{x:-o/2-A-.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:n}).map((g,c)=>zA(no,{rotation:Math.PI,position:{x:o/2+A+.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),zA(pB,{center:{x:0,y:0,z:a/2},width:o,length:s,height:1.1,notchPosition:{x:-2.25,y:s/2-1.5,z:1.1},heightAboveSurface:.17,taperRatio:.05})]})},ANe=()=>{const Q=7.050000000000001,h=24.95+6.5/2;return zA(Zi,{center:[0,0,1],children:qe(Jn,{children:[qe(rC,{rotation:[0,55,-55],children:[qe(Im,{children:[zA(Qe,{color:"#ccc",size:[6.5+.1,9.9,1.3],center:[h,0,1.3-2]}),zA(Kl,{color:"black",center:[h,0,1.3-2],radius:3/2,height:1.3*1.2})]}),zA(mo,{color:"#222",children:zA(pB,{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})})]}),zA(rC,{rotation:[0,55,55],children:Array.from({length:3}).map((E,u)=>{const d=Q,f=(u-1)*2.7,m=-.5-.6;return qe(mo,{color:"gold",children:[qe(Sc,{children:[zA(Zi,{center:[15.05-4.5/2+.1,f,m],children:zA(Qe,{size:[4.5,.81+1,.5]})}),zA(Zi,{center:[15.05-4.5/2-1+.1,f,m],children:zA(Qe,{size:[4.5,.81,.5]})})]}),zA(Zi,{center:[d,f,m],children:zA(Qe,{size:[16+.1,.81,.5]})})]},`prong-${u}`)})})]})})},tNe=()=>{const g=1.1999999999999997;return qe(Jn,{children:[zA(no,{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}),zA(no,{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}),zA(no,{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}),zA(no,{position:{x:-2.8/2-g/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(no,{position:{x:-2.8/2-g/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(no,{position:{x:-2.8/2-g/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(pB,{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})]})},eNe=()=>qe(Jn,{children:[zA(pB,{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 zA(Qe,{center:[-.8/2+.19/2-.1,c,.12/2],size:[.19,.15,.12]})}),[0,1,2].map(g=>{const c=-.35+g*.35;return zA(Qe,{center:[.8/2-.19/2+.1,c,.12/2],size:[.19,.15,.12]})})]}),iNe=()=>{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 qe(Zi,{center:[0,1,10.5],children:[zA(mo,{color:s,children:qe(Im,{children:[zA(Zi,{center:[0,0,2.25],children:zA(Kl,{radius:2.4,height:4.5})}),zA(Zi,{center:[0,-1.8499999999999999,2.25],children:zA(Qe,{size:[2.4*2,1.1,4.5+.2]})})]})}),zA(Zi,{center:c,children:zA(Qe,{size:a})}),qe(Sc,{children:[zA(Zi,{center:I,children:zA(Qe,{size:g})}),zA(Zi,{center:l,children:zA(Qe,{size:g})})]}),zA(Zi,{center:B,children:zA(Qe,{size:[.43,.4,12.2]})}),zA(Zi,{center:[1.3,0,C],children:zA(Qe,{size:[.43,.4,15]})}),zA(Zi,{center:[-1.3,0,C],children:zA(Qe,{size:[.43,.4,15]})})]})},nNe=()=>qe(Jn,{children:[zA(no,{rotation:Math.PI,position:{x:2/2+.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(no,{rotation:Math.PI,position:{x:2/2+.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(no,{rotation:Math.PI,position:{x:2/2+.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(no,{position:{x:-2/2-.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(no,{position:{x:-2/2-.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(no,{position:{x:-2/2-.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(pB,{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})]}),oNe=nNe,sNe=()=>qe(Jn,{children:[zA(pB,{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 zA(Qe,{center:[-1/2+.3/2,a,.05/2],size:[.3,.2,.05]})}),[0,1,2].map(r=>{const a=-.5+r*.5;return zA(Qe,{center:[1/2-.3/2,a,.05/2],size:[.3,.2,.05]})})]}),rNe=()=>qe(Jn,{children:[zA(no,{position:{x:-2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),zA(no,{rotation:Math.PI,position:{x:2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),zA(mo,{color:"#222",children:zA(pB,{center:{x:0,y:0,z:0},width:1.7,length:1.25,height:.95,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})}),zA(Qe,{color:"#777",size:[1.7/3,1.25-.075,.02],center:[-.85*2/3+.035,0,.95+.05]})]}),aNe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.4,.325,.175],center:[-1.05,0,.175/2]}),zA(Qe,{color:"#ccc",size:[.4,.325,.175],center:[1.05,0,.175/2]}),zA(mo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.175/2,children:zA(Qe,{size:[1.7,1.25,.175]})}),qe(Sc,{children:[zA(Zi,{z:.175,children:zA(Qe,{size:[1.7,1.25,.01]})}),zA(Zi,{z:.725,children:zA(Qe,{size:[1.7-.2,1.25-.2,.01]})})]})]})}),zA(Qe,{color:"#777",size:[1.7/3,1.25-.2,.02],center:[-1.05+1.7/4.4+.2,0,.725]})]}),gNe=()=>{const s=-1.0474999999999999,r=1.775/2+.4/2-.04;return qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.4,.325,.13],center:[s,0,.13/2]}),zA(Qe,{color:"#ccc",size:[.4,.325,.13],center:[r,0,.13/2]}),zA(mo,{color:"#222",children:zA(pB,{width:1.775,length:1.25,height:.725,center:{x:0,y:0,z:0},heightAboveSurface:0,straightHeightRatio:.7,taperRatio:.06,includeNotch:!1})}),zA(Qe,{color:"#777",size:[1.775/3,1.25-.05,.02],center:[s+1.775/4.4+.2,0,.725]})]})},cNe=({pitch:e=10})=>qe(Jn,{children:[zA(Kl,{height:4,radius:.5,center:[-e/2,0,.5]}),zA(QV,{radius:.5,center:[-e/2,0,2.5]}),zA(Zi,{x:-2.5,y:0,z:2.5,children:qe(rC,{rotation:[0,Math.PI/2,0],children:[zA(Kl,{height:e,radius:.5,center:[0,0,2.5]}),zA(mo,{color:"#d2b48c",children:zA(Kl,{height:5,radius:1.3,center:[0,0,2.5]})})]})}),zA(Kl,{height:4,radius:.5,center:[e/2,0,.5]}),zA(QV,{radius:.5,center:[e/2,0,2.5]})]}),INe=({bodyWidth:e=21,boardThickness:A=.5,leadWidth:t=1.6,leadLength:i=2.4,leadsPitch:n=2.54,leadsLeft:o,leadsRight:s,leadsTop:r,leadsBottom:a,innerHoles:g=!0,innerHoleEdgeDistance:c=1.61,innerHoleDiameter:I=1})=>{const l=e/2,B=A/2,C=A*1.05,Q=I/2,h=Math.max(o||0,s||0,r||0,a||0)*n||51,E=[],u=[];if(s){const w=-((s-1)/2)*n;for(let D=0;D<s;D++){const S=w+D*n;E.push({x:l-i/2,y:-S,pl:i,pw:t}),g&&u.push({x:l,y:-S},{x:l-c,y:-S})}}if(o){const w=-((o-1)/2)*n;for(let D=0;D<o;D++){const S=w+D*n;E.push({x:-l+i/2,y:-S,pl:i,pw:t}),g&&u.push({x:-l,y:-S},{x:-l+c,y:-S})}}if(r){const w=-((r-1)/2)*n;for(let D=0;D<r;D++){const S=w+D*n;E.push({x:-S,y:h/2-i/2,pl:t,pw:i}),g&&u.push({x:-S,y:h/2},{x:-S,y:h/2-c})}}if(a){const w=-((a-1)/2)*n;for(let D=0;D<a;D++){const S=w+D*n;E.push({x:-S,y:-h/2+i/2,pl:t,pw:i}),g&&u.push({x:-S,y:-h/2},{x:-S,y:-h/2+c})}}const d=zA(mo,{color:"#008080",children:qe(Im,{children:[zA(Qe,{center:[0,0,B],size:[e,h,A]}),E.map((w,D)=>zA(Qe,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]},D))]})}),f=g&&u.map((w,D)=>zA(Kl,{color:"black",center:[w.x,w.y,B],radius:Q,height:A*1.07})),m=E.map((w,D)=>zA(Qe,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]}));return qe(Jn,{children:[d,zA(mo,{color:"#FFD700",children:g?qe(Im,{children:[zA(zQ,{children:E.map((w,D)=>zA(Qe,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]},D))}),f]}):m})]})},lNe=({width:e=30,height:A=22,thickness:t=1,bezelInset:i=2,bezelDepth:n=1,screenColor:o="#001414",bezelColor:s="#0f1116",screenWidth:r,screenHeight:a,offset:g})=>{const c=e,I=A,l=Math.max(t,.4),B=Math.max(Math.min(n,l),.2),C=Math.max(l-B,0),Q=Math.max(i,0),h=Math.max(r??c-Q*2,2),E=Math.max(a??I-Q*2,2),u=Math.min(Math.max(B*.6,.2),B),d=g?.x??0,f=g?.y??0,m=g?.z??0;return qe(Zi,{offset:{x:d,y:f,z:m},children:[C>0&&zA(mo,{color:s,children:zA(Qe,{size:[c,I,C],offset:[0,0,C/2]})}),zA(mo,{color:s,children:qe(Im,{children:[zA(Qe,{size:[c,I,B],offset:[0,0,C+B/2]}),zA(Qe,{size:[h,E,B+.02],offset:[0,0,C+B/2]})]})}),zA(mo,{color:o,children:zA(Qe,{size:[h,E,u],offset:[0,0,C+u/2]})})]})},BNe=({numPins:e=5,rows:A=1,p:t=2.54,id:i=1,od:n=1.5,boardThickness:o=1.6,width:s,height:r,pinRowSide:a="left",holes:g=[],holeInset:c=1,pinRowHoleEdgeToEdgeDist:I=2,female:l,nopin:B,screen:C,screenWidth:Q,screenHeight:h,screenCenterOffsetX:E,screenCenterOffsetY:u})=>{const d=C??!1,f=o/2,m=Math.ceil(e/A);let w,D;a==="left"||a==="right"?(w=(A-1)*t+2*I,D=(m-1)*t+2*I):(D=(A-1)*t+2*I,w=(m-1)*t+2*I),e===0&&(w=10,D=10);const S=Number(s??w),_=Number(r??D),b=[];let R=0,F=0,H=0,Y=0,J=0,O=0;a==="left"||a==="right"?(R=a==="left"?-S/2+I:S/2-I,F=-((m-1)/2)*t,H=0,Y=t,J=a==="left"?t:-t,O=0):(R=-((m-1)/2)*t,F=a==="top"?_/2-I:-_/2+I,H=t,Y=0,J=0,O=a==="top"?-t:t);let W=0;for(let EA=0;EA<A&&W<e;EA++)for(let xA=0;xA<m&&W<e;xA++){const dA=R+xA*H+EA*J,OA=F+xA*Y+EA*O;b.push({x:dA,y:OA}),W++}const z=[];if(g)for(const EA of g){let xA=0,dA=0;EA==="topleft"?(xA=-S/2+c,dA=_/2-c):EA==="topright"?(xA=S/2-c,dA=_/2-c):EA==="bottomleft"?(xA=-S/2+c,dA=-_/2+c):EA==="bottomright"?(xA=S/2-c,dA=-_/2+c):EA==="center"&&(xA=0,dA=0),z.push({x:xA,y:dA})}const tA=.63,aA=2,eA=6,oA=3,rA=B||l?0:aA,BA=rA+o,pA=zA(mo,{color:"#008080",children:qe(Im,{children:[zA(Qe,{center:[0,0,f+rA],size:[S,_,o]}),z.map((EA,xA)=>zA(Kl,{center:[EA.x,EA.y,f+rA],radius:n/2,height:o},`hole-${xA}`)),b.map((EA,xA)=>zA(Kl,{center:[EA.x,EA.y,f+rA],radius:n/2,height:o},`pin-hole-${xA}`))]})}),_A=b.map((EA,xA)=>zA(mo,{color:"#FFD700",children:qe(Im,{children:[zA(Kl,{center:[EA.x,EA.y,o/2+rA],radius:n/2,height:o}),zA(Kl,{center:[EA.x,EA.y,o/2+rA],radius:i/2,height:o})]})})),FA=b.map((EA,xA)=>zA(Qet,{x:EA.x,y:EA.y,pinThickness:tA,shortSidePinLength:oA,longSidePinLength:eA,bodyHeight:aA,flipZ:dA=>dA})),PA=b.map((EA,xA)=>zA(yet,{x:EA.x,y:EA.y,flipZ:dA=>-dA}));return qe(Jn,{children:[pA,_A,!l&&!B&&FA,l&&PA,d&&zA(lNe,{width:Q??S*.8,height:h??_*.6,offset:{x:E??0,y:u??0,z:BA}})]})},CNe=({footprint:e})=>{const A=jGe.string(e).json();switch(A.fn){case"dip":return zA(tRe,{numPins:A.num_pins,pitch:A.p,bodyWidth:A.w});case"axial":return zA(cNe,{pitch:A.p});case"tssop":return zA(iRe,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"msop":return zA(nRe,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"vssop":return zA(_Re,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w,bodyLength:A.h});case"qfp":return zA(aRe,{pinCount:A.num_pins,pitch:A.p,leadWidth:A.pw,padContactLength:A.pl,bodyWidth:A.w});case"tqfp":return zA(PRe,{});case"lqfp":return zA(qRe,{pinCount:A.num_pins});case"qfn":{const n=typeof A.thermalpad?.x=="number"&&typeof A.thermalpad?.y=="number";return zA(hRe,{num_pins:A.num_pins,bodyWidth:A.w,bodyLength:A.h,pitch:A.p,padLength:A.pl,padWidth:A.pw,thermalPadSize:n?{width:A.thermalpad.x,length:A.thermalpad.y}:void 0})}case"dfn":{const n=typeof A.thermalpad?.x=="number"&&typeof A.thermalpad?.y=="number";return zA(WRe,{num_pins:A.num_pins,bodyWidth:A.w,bodyLength:A.h,pitch:A.p,padLength:A.pl,padWidth:A.pw,thermalPadSize:n?{width:A.thermalpad.x,length:A.thermalpad.y}:void 0})}case"pinrow":{const n=e.match(/_rows(\d+)/),o=n&&n[1]?parseInt(n[1],10):1;if(A.male)return zA(lRe,{numberOfPins:A.num_pins,pitch:A.p,invert:A.invert,faceup:A.faceup,rows:o,smd:A.smd||A.surface_mount,rightangle:A.rightangle});if(A.female)return zA(SRe,{numberOfPins:A.num_pins,pitch:A.p,rows:o})}case"cap":switch(A.imperial){case"0402":return zA(Iet,{color:"#856c4d"});case"0603":return zA(Bet,{color:"#856c4d"});case"0805":return zA(Cet,{color:"#856c4d"});case"0201":return zA(het,{color:"#856c4d"});case"01005":return zA(Eet,{color:"#856c4d"});case"1206":return zA(uet,{color:"#856c4d"});case"1210":return zA(det,{color:"#856c4d"});case"2010":return zA(pet,{color:"#856c4d"});case"2512":return zA(fet,{color:"#856c4d"})}case"sot235":return zA(uRe,{});case"sot457":return zA(tNe,{});case"sot223":return zA(JRe,{});case"sot23w":return zA(dRe,{});case"sot323":return zA(KRe,{});case"sod323f":return zA(aNe,{});case"sod323fl":return zA(gNe,{});case"sot363":return zA(oNe,{});case"sot886":return zA(sNe,{});case"sot963":return zA(eNe,{});case"pushbutton":return zA(bRe,{width:A.w,length:A.h,innerDiameter:A.id});case"soic":return zA(xRe,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"sod523":return zA(kRe,{});case"sod882":return zA(vRe,{});case"sma":return zA(FRe,{});case"smb":return zA(MRe,{});case"smc":return zA(GRe,{});case"smf":return zA(RRe,{});case"sod123f":return zA(NRe,{});case"sod123fl":return zA(LRe,{});case"sod123w":return zA(URe,{});case"sod128":return zA(HRe,{});case"sod323":return zA(rNe,{});case"sod923":return zA(YRe,{});case"hc49":return zA(ZRe,{});case"micromelf":return zA(VRe,{});case"minimelf":return zA(jRe,{});case"melf":return zA(zRe,{});case"ms012":return zA(XRe,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"ms013":return zA($Re,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"sot723":return zA(ORe,{});case"to220":return zA(ANe,{});case"to92":return zA(iNe,{});case"stampboard":case"stampreceiver":return zA(INe,{bodyWidth:A.w,leadsLeft:A.left,leadsRight:A.right,leadsTop:A.top,leadsBottom:A.bottom,leadsPitch:A.p,leadWidth:A.pw,leadLength:A.pl,innerHoles:A.innerhole,innerHoleEdgeDistance:A.innerholeedgedistance});case"mountedpcbmodule":{const n=A.rows??1,o=A.pinRowSide??"left",s=A.holeInset,r=A.width,a=A.height,g=A.pinrow,c=A.pinRowHoleEdgeToEdgeDist,I=Array.isArray(A.holes)?A.holes:[];return zA(BNe,{numPins:g,rows:n,p:A.p,id:A.id,od:A.od,width:r,height:a,pinRowSide:o,holes:I,holeInset:s,pinRowHoleEdgeToEdgeDist:c,nopin:A.nopin,female:A.female,screen:A.screen,screenWidth:A.screenwidth,screenHeight:A.screenheight,screenCenterOffsetX:A.screencenteroffsetx,screenCenterOffsetY:A.screencenteroffsety})}}const t=e.match(/_color\(([^)]+)\)/),i=t?t[1]:void 0;switch(A.imperial){case"0402":return zA(Iet,{color:i});case"0603":return zA(Bet,{color:i});case"0805":return zA(Cet,{color:i});case"0201":return zA(het,{color:i});case"01005":return zA(Eet,{color:i});case"1206":return zA(uet,{color:i});case"1210":return zA(det,{color:i});case"2010":return zA(pet,{color:i});case"2512":return zA(fet,{color:i})}return null},QNe=e=>e&&typeof e=="object"&&"type"in e,p2=e=>{if(typeof e=="number")return e;if(typeof e=="string"){const A=/^(-?\d+(?:\.\d+)?)\s*deg$/i.exec(e);if(A)return parseFloat(A[1])*Math.PI/180;const t=Number(e);if(!Number.isNaN(t))return t}return 0},hNe=e=>Array.isArray(e)?[Number(e[0])||0,Number(e[1])||0,Number(e[2])||0]:typeof e=="object"&&e?[Number(e.x)||0,Number(e.y)||0,Number(e.z)||0]:[0,0,0];function YD(e,A,t){const{jscad:{primitives:i,booleans:n,hulls:o,geometries:s,extrusions:r,transforms:a}}=t;if(e==null||e===!1)return[];if(Array.isArray(e))return e.flatMap(l=>YD(l,A,t));if(!QNe(e))return[];const{type:g,props:c,children:I}=e;if(g===aet)return(I??[]).flatMap(l=>YD(l,A,t));if(g===mo){const l=c?.color;return(I??[]).flatMap(B=>YD(B,l??A,t))}if(g===Zi){const l=hNe(c?.offset??c?.center??{x:c?.x,y:c?.y,z:c?.z});return(I??[]).flatMap(C=>YD(C,A,t)).map(({geom:C,color:Q})=>({geom:a.translate(l,C),color:Q??A}))}if(g===rC){const l=Array.isArray(c?.rotation)?[p2(c.rotation[0]),p2(c.rotation[1]),p2(c.rotation[2])]:[p2(c?.x??0),p2(c?.y??0),p2(c?.z??0)];return(I??[]).flatMap(C=>YD(C,A,t)).map(({geom:C,color:Q})=>({geom:a.rotateZ(l[2],a.rotateY(l[1],a.rotateX(l[0],C))),color:Q}))}if(g===zQ||g===Im||g===Sc){const l=(I??[]).flatMap(C=>YD(C,A,t)).map(C=>C.geom);if(l.length===0)return[];let B;return g===zQ?B=n.union(l):g===Im?B=n.subtract(l[0],l.slice(1)):B=o.hull(l),[{geom:B,color:A}]}if(g===KY){const l=c?.points??[];return[{geom:s.geom2.fromPoints(l),color:A??c?.color}]}if(g===qY){const l=(I??[]).flatMap(h=>YD(h,A,t)).map(h=>h.geom);if(l.length===0)return[];const B=l.length>1?n.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===Qe||g===get||g===Kl||g===QV||g===PY||g===_f){let l;if(g===Qe){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===get){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===Kl){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===QV){const B=c?.radius??1,C=c?.center??[0,0,0];l=i.sphere({radius:B,center:C})}else if(g===_f){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 YD(l,A,t)}return(I??[]).flatMap(l=>YD(l,A,t))}function ENe(e,A){return{geometries:YD(e,void 0,{jscad:A})}}function met(e){if(e.polygons){const A=[],t=[],i=[];let n=0;for(const s of e.polygons){for(const a of s.vertices)a.index=n,A.push(a[0],a[1],a[2]),e.color&&e.color.length>=3?i.push(e.color[0],e.color[1],e.color[2]):i.push(1,1,1),n++;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;t.push(r,g,c)}}const o=new kg;if(o.setAttribute("position",new mc(new Float32Array(A),3)),o.setIndex(t),i.length>0&&o.setAttribute("color",new mc(new Float32Array(i),3)),e.transforms){const s=new Qs;s.fromArray(e.transforms),o.applyMatrix4(s)}return o.computeVertexNormals(),o}if(e.sides){const A=[],t=[];for(const n of e.sides)A.push(n[0][0],n[0][1],0),e.color&&e.color.length>=3?t.push(e.color[0],e.color[1],e.color[2]):t.push(1,1,1);const i=new kg;if(i.setAttribute("position",new mc(new Float32Array(A),3)),t.length>0&&i.setAttribute("color",new mc(new Float32Array(t),3)),e.transforms){const n=new Qs;n.fromArray(e.transforms),i.applyMatrix4(n)}return i}return console.error("Invalid CSG object: neither polygons nor sides found"),new kg}function uNe(e,A){const t=$uA(CNe,{footprint:e});return ENe(t,A)}var dNe=Xa(sV()),wet=AA.createContext(null),pNe=()=>{const e=AA.useContext(wet);if(!e)throw new Error("useHover must be used within a HoverProvider");return e},fNe=({children:e})=>{const{camera:A,renderer:t}=nd(),[i,n]=AA.useState([]),o=AA.useMemo(()=>new dLt,[]),s=AA.useMemo(()=>new Sn,[]),r=AA.useRef(i);r.current=i;const a=AA.useRef(null),g=AA.useCallback(C=>{n(Q=>[...Q,C])},[]),c=AA.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)}n(Q=>Q.filter(h=>h.object!==C))},[]),I=AA.useCallback(C=>{let Q=C;for(;Q;){const h=r.current.find(E=>E.object===Q);if(h)return h;Q=Q.parent}},[]),l=AA.useCallback(C=>{if(!t.domElement)return;const Q=t.domElement.getBoundingClientRect();s.x=(C.clientX-Q.left)/Q.width*2-1,s.y=-((C.clientY-Q.top)/Q.height)*2+1,o.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=o.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,t,o,s,I]);AA.useEffect(()=>{const C=t.domElement;return C.addEventListener("mousemove",l),()=>{C.removeEventListener("mousemove",l)}},[t,l]);const B=AA.useMemo(()=>({addHoverable:g,removeHoverable:c}),[g,c]);return Z.jsx(wet.Provider,{value:B,children:e})},yNe=({children:e,object:A,onHover:t,onUnhover:i,isHovered:n})=>{const{addHoverable:o,removeHoverable:s}=pNe();return AA.useEffect(()=>A?(o({object:A,onHover:t,onUnhover:i}),()=>{s(A)}):void 0,[A,t,i,o,s]),Z.jsx(Z.Fragment,{children:e})},AJ=yNe,mNe=({positionOffset:e,footprint:A,rotationOffset:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=nd(),g=AA.useMemo(()=>{if(!A)return null;const{geometries:c}=uNe(A,dNe),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 An(l.color);C.convertLinearToSRGB();const Q={...B,color:[C.r,C.g,C.b]},h=met(Q),E=new TE({vertexColors:!0,side:YQ,transparent:r,opacity:r?.5:1,depthWrite:!r}),u=new Io(h,E);u.renderOrder=r?2:1,I.add(u)}return I},[A,r]);return AA.useEffect(()=>{if(!(!g||!a))return a.add(g),()=>{a.remove(g)}},[a,g]),AA.useEffect(()=>{g&&(e&&g.position.fromArray(e),t&&g.rotation.fromArray(t),s!==void 0&&g.scale.setScalar(s))},[g,e?.[0],e?.[1],e?.[2],t?.[0],t?.[1],t?.[2],s]),AA.useEffect(()=>{g&&g.traverse(c=>{c instanceof Io&&c.material instanceof TE&&(o?(c.material.emissive.setHex(255),c.material.emissiveIntensity=.2):c.material.emissiveIntensity=0)})},[o,g]),g?Z.jsx(AJ,{isHovered:o,onHover:i,onUnhover:n,object:g}):null},Det=new WeakMap,wNe=()=>{const e=new $c;return e.name="fallback-environment-map",e.mapping=Eq,e},DNe=e=>{if(!e)return null;const A=e,t=Det.get(A);if(t)return t;let i;if(e instanceof Vq){const n=new P$(e);i=n.fromScene(yHt(),.04).texture,n.dispose()}else i=wNe();return Det.set(A,i),i},bet=1.25;function xet({gltfUrl:e,position:A,rotation:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const{renderer:a,rootObject:g}=nd(),[c,I]=AA.useState(null),[l,B]=AA.useState(null);if(AA.useEffect(()=>{if(!e)return;const C=new wHt;let Q=!0;return C.load(e,h=>{if(!Q)return;const E=h.scene;E.traverse(u=>{if(u instanceof Io&&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),u.renderOrder=r?2:1}}),I(E)},void 0,h=>{if(!Q)return;console.error(`An error happened loading ${e}`,h);const E=h instanceof Error?h:new Error(`Failed to load glTF model from ${e}`);B(E)}),()=>{Q=!1}},[e,r]),AA.useEffect(()=>{c&&(A&&c.position.fromArray(A),t&&c.rotation.fromArray(t),s!==void 0&&c.scale.setScalar(s))},[c,A?.[0],A?.[1],A?.[2],t?.[0],t?.[1],t?.[2],s]),AA.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),AA.useEffect(()=>{if(!c||!a)return;const C=DNe(a);if(!C)return;const Q=[],h=E=>{E instanceof TE&&(Q.push({material:E,envMap:E.envMap??null,envMapIntensity:E.envMapIntensity??1}),E.envMap=C,(typeof E.envMapIntensity!="number"||E.envMapIntensity<bet)&&(E.envMapIntensity=bet),E.needsUpdate=!0)};return c.traverse(E=>{if(!(E instanceof Io))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]),AA.useEffect(()=>{c&&c.traverse(C=>{C instanceof Io&&C.material instanceof TE&&(o?(C.material.emissive.setHex(255),C.material.emissiveIntensity=.2):C.material.emissiveIntensity=0)})},[o,c]),l)throw l;return c?Z.jsx(AJ,{isHovered:o,onHover:i,onUnhover:n,object:c}):null}var SNe=Xa(ktt()),bNe=Xa(sV()),xNe=({jscadPlan:e,positionOffset:A,rotationOffset:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=nd(),{threeGeom:g,material:c}=AA.useMemo(()=>{const l=(0,SNe.executeJscadOperations)(bNe.default,e);if(!l||!l.polygons&&!l.sides)return{threeGeom:null,material:null};const B=met(l),C=new TE({vertexColors:!0,side:YQ,transparent:r,opacity:r?.5:1,depthWrite:!r});return{threeGeom:B,material:C}},[e,r]),I=AA.useMemo(()=>{if(!g)return null;const l=new Io(g,c);return l.renderOrder=r?2:1,l},[g,c,r]);return AA.useEffect(()=>{if(!(!I||!a))return a.add(I),()=>{a.remove(I)}},[a,I]),AA.useEffect(()=>{I&&(A&&I.position.fromArray(A),t&&I.rotation.fromArray(t),s!==void 0&&I.scale.setScalar(s))},[I,A?.[0],A?.[1],A?.[2],t?.[0],t?.[1],t?.[2],s]),AA.useMemo(()=>{if(c)if(o){const l=new An(c.color.getHex());c.emissive.copy(l),c.emissive.setRGB(0,0,1),c.emissiveIntensity=.2}else c.emissiveIntensity=0},[o,c]),g?Z.jsx(AJ,{isHovered:o,onHover:i,onUnhover:n,object:I}):null};function _Ne(e){return e.replace(/(DEF|USE)\s+([^\s]+)/g,(A,t,i)=>`${t} ${i.replace(/-/g,"_")}`)}async function kNe(e){const A=await fetch(e);if(!A.ok)throw new Error(`Failed to fetch "${e}": ${A.status} ${A.statusText}`);const t=await A.text();return new gYt().parse(_Ne(t),e)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function vNe(e){const[A,t]=AA.useState(null);return AA.useEffect(()=>{if(!e)return;const i=e.replace(/&cachebust_origin=$/,""),n=window.TSCIRCUIT_OBJ_LOADER_CACHE;let o=!1;async function s(){try{if(i.endsWith(".wrl"))return await kNe(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 uYt;if(c?.length){const l=c.join(`
|
|
5152
|
-
`).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new sYt;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(n.has(i)){const g=n.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||n.set(i,{...n.get(i),result:g}),g));return n.set(i,{promise:a,result:null}),a}return r().then(a=>{o||t(a)}).catch(a=>{console.error(a)}),()=>{o=!0}},[e]),A}function FNe({url:e,position:A,rotation:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const a=vNe(e),{rootObject:g}=nd(),c=AA.useMemo(()=>a&&!(a instanceof Error)?(a.traverse(I=>{if(I instanceof Io&&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),I.renderOrder=r?2:1}}),a):new Io(new nw(.5,.5,.5),new TE({transparent:!0,color:"red",opacity:.25})),[a,r]);if(AA.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),AA.useEffect(()=>{c&&(A&&(Array.isArray(A)?c.position.fromArray(A):c.position.copy(A)),t&&(Array.isArray(t)?c.rotation.fromArray(t):c.rotation.copy(t)),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(t)?t[0]:t?.x,Array.isArray(t)?t[1]:t?.y,Array.isArray(t)?t[2]:t?.z,s]),a instanceof Error)throw a;return Z.jsx(AJ,{isHovered:o,onHover:i,onUnhover:n,object:c})}var ddA,MNe="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function GNe(e){if(typeof e=="function")return e;if(e&&typeof e=="object"&&"default"in e&&typeof e.default=="function")return e.default;throw new Error("Unable to resolve occt-import-js factory export")}async function RNe(){if(!ddA){const e=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");ddA=GNe(e)({locateFile:t=>`${MNe}/${t}`})}return ddA}function NNe(e){const A=new hf;for(const t of e){const i=t.attributes.position?.array??[],n=t.index?.array??[];if(!i.length||!n.length)continue;const o=new kg;o.setAttribute("position",new $o(i,3));const s=t.attributes.normal?.array??[];s.length?o.setAttribute("normal",new $o(s,3)):o.computeVertexNormals(),o.setIndex(n);const r=new TE({color:t.color?new An(t.color[0],t.color[1],t.color[2]):new An(.82,.82,.82)}),a=new Io(o,r);a.name=t.name,A.add(a)}return A}async function LNe(e){const A=await fetch(e);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const t=await A.arrayBuffer(),n=(await RNe()).ReadStepFile(new Uint8Array(t),null);if(!n.success||!n.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=NNe(n.meshes),s=new EtA;return await new Promise((a,g)=>{s.parse(o,c=>{c instanceof ArrayBuffer?a(c):g(new Error("GLTFExporter did not return binary output"))},c=>{g(c)},{binary:!0})})}var _et="step-glb-cache:";function UNe(e){const A=new Uint8Array(e),t=32768;let i="";for(let n=0;n<A.length;n+=t){const o=A.subarray(n,n+t);i+=String.fromCharCode(...o)}return btoa(i)}function HNe(e){const A=atob(e),t=new Uint8Array(A.length);for(let i=0;i<A.length;i+=1)t[i]=A.charCodeAt(i);return t.buffer}function YNe(e){try{const A=localStorage.getItem(`${_et}${e}`);return A?HNe(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function ket(e,A){try{const t=UNe(A);localStorage.setItem(`${_et}${e}`,t)}catch(t){console.warn("Failed to write STEP GLB cache",t)}}function JNe(){const e=globalThis;return e.stepUrlToGltfModelConversions||(e.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),e.stepUrlToGltfModelConversions}var TNe=({stepUrl:e,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r})=>{const[a,g]=AA.useState(null);return AA.useEffect(()=>{let c=!0,I=null,l=!0;const B=JNe(),C=YNe(e);if(C){const E={arrayBuffer:C,blobUrl:URL.createObjectURL(new Blob([C],{type:"model/gltf-binary"}))};return B.completed.set(e,E),I=E.blobUrl,l=!1,g(E.blobUrl),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}}const Q=B.completed.get(e);if(Q)return I=Q.blobUrl,l=!1,g(Q.blobUrl),ket(e,Q.arrayBuffer),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)};let h=B.inProgress.get(e);return h||(h=LNe(e).then(E=>{const u={arrayBuffer:E,blobUrl:URL.createObjectURL(new Blob([E],{type:"model/gltf-binary"}))};return B.completed.set(e,u),B.inProgress.delete(e),u}).catch(E=>{throw B.inProgress.delete(e),E}),B.inProgress.set(e,h)),h.then(E=>{c&&(I=E.blobUrl,l=!1,g(E.blobUrl),ket(e,E.arrayBuffer))}).catch(E=>{console.error("Failed to convert STEP file to GLB",E),c&&g(null)}),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}},[e]),a?Z.jsx(xet,{gltfUrl:a,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r}):null},PNe=(e,A)=>{if(e)return A?A(e):e},vet=(...e)=>e,pdA=class extends Qn.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},KNe=({error:e,onError:A})=>(AA.useEffect(()=>{A(e)},[e,A]),null),Fet=({cad_component:e,circuitJson:A,resolveStaticAsset:t})=>{const i=Mtt(A),[n,o]=AA.useState(!1),{visibility:s}=OF(),[r,a]=AA.useState(null),g=AA.useCallback(R=>{R?.mousePosition?(o(!0),a(R.mousePosition)):(o(!1),a(null))},[]),c=AA.useCallback(()=>{o(!1),a(null)},[]),I=AA.useMemo(()=>yn(A).source_component.getUsing({source_component_id:e.source_component_id})?.name,[A,e.source_component_id]),l=AA.useMemo(()=>A.filter(F=>F.type==="pcb_plated_hole"&&F.pcb_component_id===e.pcb_component_id).length>0,[A,e.pcb_component_id]),B=AA.useCallback(R=>PNe(R,t),[t]),C=B(e.model_obj_url??e.model_wrl_url??e.model_stl_url),Q=B(e.model_glb_url??e.model_gltf_url),h=B(e.model_step_url),[E,u]=AA.useState(0),[d,f]=AA.useState(null);AA.useEffect(()=>{u(0),f(null)},[e.cad_component_id,C,Q,h]);const w=A.find(R=>R.type==="pcb_component"&&R.source_component_id===e.source_component_id)?.layer??"top",D=AA.useMemo(()=>e.rotation?vet(e.rotation.x*Math.PI/180,e.rotation.y*Math.PI/180,e.rotation.z*Math.PI/180):vet(0,0,0),[e.rotation,w]),S=AA.useMemo(()=>{if(!e.position)return;let R;return w==="top"?R=e.position.z:w==="bottom"?R=-(e.position.z+i):R=e.position.z,[e.position.x,e.position.y,R]},[e.position,w,i]),_=AA.useMemo(()=>{const R=[];return C&&R.push(Z.jsx(FNe,{url:C,position:S,rotation:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-mixed-${C}`)),Q&&R.push(Z.jsx(xet,{gltfUrl:Q,position:S,rotation:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-gltf-${Q}`)),h&&!e.model_jscad&&!e.footprinter_string&&R.push(Z.jsx(TNe,{stepUrl:h,position:S,rotation:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-step-${h}`)),R},[S,e.cad_component_id,e.footprinter_string,e.model_jscad,e.model_unit_to_mm_scale_factor,e.show_as_translucent_model,Q,g,c,n,D,h,C]);let b=null;if(_.length>0){if(E>=_.length){if(d)throw d;return null}b=Z.jsx(pdA,{fallback:({error:R})=>Z.jsx(KNe,{error:R,onError:F=>{f(F),u(H=>Math.max(H,E+1))}}),children:_[E]},`${e.cad_component_id}-fallback-${E}`)}else e.model_jscad?b=Z.jsx(xNe,{jscadPlan:e.model_jscad,positionOffset:S,rotationOffset:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},e.cad_component_id):e.footprinter_string&&(b=Z.jsx(mNe,{positionOffset:S,rotationOffset:D,footprint:e.footprinter_string,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model}));if(e.show_as_translucent_model){if(!s.translucentModels)return null}else if(l&&!s.throughHoleModels||!l&&!s.smtModels)return null;return Z.jsxs(Z.Fragment,{children:[b,n&&r?Z.jsx(Rtt,{position:r,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:I??"<unknown>"}):null]})},Met={version:"0.0.540"};function qNe(e){e.querySelectorAll("canvas").forEach(A=>A.remove())}var ONe=e=>{e.outputColorSpace=Vm,e.toneMapping=hFA,e.toneMappingExposure=1},Get="cadViewerCameraStateSession",Ret=(e,A)=>{try{const t={position:e.position.toArray(),quaternion:e.quaternion.toArray(),up:e.up.toArray(),fov:e.fov??50,target:A.target.toArray()};sessionStorage.setItem(Get,JSON.stringify(t))}catch(t){console.warn("Failed to save camera:",t)}},fdA=(e,A)=>{try{const t=sessionStorage.getItem(Get);if(!t)return!1;const i=JSON.parse(t);if(e.position.fromArray(i.position),e.quaternion.fromArray(i.quaternion),e.up.fromArray(i.up),"fov"in e){const n=e;n.fov=i.fov,n.updateProjectionMatrix?.()}return A.target.fromArray(i.target),A.update(),e.updateMatrixWorld(),!0}catch(t){return console.warn("Failed to restore camera:",t),!1}},Net=AA.createContext(void 0),WNe=({children:e,defaultTarget:A,initialCameraPosition:t})=>{const i=AA.useRef(null),n=AA.useRef(null),[o,s]=AA.useState(null),[r,a]=AA.useState("perspective"),[g,c]=AA.useState(t??null),[I,l]=AA.useState(new Cf(0,0,0)),B=AA.useMemo(()=>{const[E,u,d]=t??[5,-5,5],f=Math.hypot(E-A.x,u-A.y,d-A.z);return f>0?f:5},[t,A]),C=AA.useCallback(E=>{const u=[A.x,A.y,A.z],d=n.current,f=i.current;let m=B;switch(d&&f&&(m=d.position.distanceTo(f.target)),E){case"Top Center Angled":{const w=m/Math.sqrt(2);return{position:[A.x,A.y-w,A.z+w],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,n,i]),Q=AA.useCallback(E=>{i.current=E},[]),h=AA.useMemo(()=>({controlsRef:i,mainCameraRef:n,defaultTarget:A,baseDistance:B,controller:o,setController:s,getPresetConfig:C,handleControlsChange:Q,cameraType:r,setCameraType:a,cameraPosition:g,setCameraPosition:c,cameraRotation:I,setCameraRotation:l,saveCameraToSession:Ret,loadCameraFromSession:fdA}),[A,B,o,C,Q,r,g,I]);return Z.jsx(Net.Provider,{value:h,children:e})},ak=()=>{const e=AA.useContext(Net);if(!e)throw new Error("useCameraController must be used within a CameraControllerProvider");return e},ZNe=AA.forwardRef(({children:e,scene:A,camera:t,style:i,onCreated:n},o)=>{const{cameraType:s}=ak(),r=AA.useRef(null),[a,g]=AA.useState(null),c=AA.useRef([]),I=AA.useRef(void 0);I.current=n;const l=AA.useRef(null),B=AA.useCallback(E=>{c.current.push(E)},[]),C=AA.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=AA.useMemo(()=>new Pv,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=AA.useRef(new _g);return AA.useImperativeHandle(o,()=>h.current),AA.useEffect(()=>{if(!r.current)return;qNe(r.current);const E=new Vq({antialias:!0,alpha:!0});ONe(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 Yh(75,u,.1,1e3):new aU(-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)):(t?.up&&d.up.set(t.up[0],t.up[1],t.up[2]),t?.position&&d.position.set(t.position[0],t.position[1],t.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 gLt,w=()=>{const S=m.getElapsedTime(),_=m.getDelta();c.current.forEach(b=>b(S,_)),E.render(Q,d),f=requestAnimationFrame(w)};w();const D=()=>{if(r.current){const S=r.current.clientWidth/r.current.clientHeight;d instanceof Yh?d.aspect=S:d instanceof aU&&(d.left=-10*S,d.right=10*S,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),E.setSize(r.current.clientWidth,r.current.clientHeight)}};return window.addEventListener("resize",D),()=>{l.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",D),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]),Z.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&Z.jsx(Gtt.Provider,{value:a,children:Z.jsx(fNe,{children:e})})})}),VNe=({autoRotate:e,autoRotateSpeed:A,onStart:t,panSpeed:i,rotateSpeed:n,zoomSpeed:o,enableDamping:s,dampingFactor:r,target:a,onControlsChange:g})=>{const{camera:c,renderer:I}=nd(),l=AA.useMemo(()=>!c||!I?null:new pYt(c,I.domElement),[c,I]);return AA.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),AA.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),AA.useEffect(()=>{l&&(l.autoRotate=e||!1,l.autoRotateSpeed=A||1,i!==void 0&&(l.panSpeed=i),n!==void 0&&(l.rotateSpeed=n),o!==void 0&&(l.zoomSpeed=o),s!==void 0&&(l.enableDamping=s),r!==void 0&&(l.dampingFactor=r),l.zoomToCursor=!0,l.mouseButtons={LEFT:Kx.ROTATE,MIDDLE:Kx.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,e,A,i,n,o,s,r,a]),AA.useEffect(()=>{if(!(!l||!t))return l.addEventListener("start",t),()=>{l.removeEventListener("start",t)}},[l,t]),AA.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),HY(()=>{l?.update()},[l]),null},jNe=`
|
|
5152
|
+
`).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new sYt;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(n.has(i)){const g=n.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||n.set(i,{...n.get(i),result:g}),g));return n.set(i,{promise:a,result:null}),a}return r().then(a=>{o||t(a)}).catch(a=>{console.error(a)}),()=>{o=!0}},[e]),A}function FNe({url:e,position:A,rotation:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const a=vNe(e),{rootObject:g}=nd(),c=AA.useMemo(()=>a&&!(a instanceof Error)?(a.traverse(I=>{if(I instanceof Io&&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),I.renderOrder=r?2:1}}),a):new Io(new nw(.5,.5,.5),new TE({transparent:!0,color:"red",opacity:.25})),[a,r]);if(AA.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),AA.useEffect(()=>{c&&(A&&(Array.isArray(A)?c.position.fromArray(A):c.position.copy(A)),t&&(Array.isArray(t)?c.rotation.fromArray(t):c.rotation.copy(t)),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(t)?t[0]:t?.x,Array.isArray(t)?t[1]:t?.y,Array.isArray(t)?t[2]:t?.z,s]),a instanceof Error)throw a;return Z.jsx(AJ,{isHovered:o,onHover:i,onUnhover:n,object:c})}var ddA,MNe="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function GNe(e){if(typeof e=="function")return e;if(e&&typeof e=="object"&&"default"in e&&typeof e.default=="function")return e.default;throw new Error("Unable to resolve occt-import-js factory export")}async function RNe(){if(!ddA){const e=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");ddA=GNe(e)({locateFile:t=>`${MNe}/${t}`})}return ddA}function NNe(e){const A=new hf;for(const t of e){const i=t.attributes.position?.array??[],n=t.index?.array??[];if(!i.length||!n.length)continue;const o=new kg;o.setAttribute("position",new $o(i,3));const s=t.attributes.normal?.array??[];s.length?o.setAttribute("normal",new $o(s,3)):o.computeVertexNormals(),o.setIndex(n);const r=new TE({color:t.color?new An(t.color[0],t.color[1],t.color[2]):new An(.82,.82,.82)}),a=new Io(o,r);a.name=t.name,A.add(a)}return A}async function LNe(e){const A=await fetch(e);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const t=await A.arrayBuffer(),n=(await RNe()).ReadStepFile(new Uint8Array(t),null);if(!n.success||!n.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=NNe(n.meshes),s=new EtA;return await new Promise((a,g)=>{s.parse(o,c=>{c instanceof ArrayBuffer?a(c):g(new Error("GLTFExporter did not return binary output"))},c=>{g(c)},{binary:!0})})}var _et="step-glb-cache:";function UNe(e){const A=new Uint8Array(e),t=32768;let i="";for(let n=0;n<A.length;n+=t){const o=A.subarray(n,n+t);i+=String.fromCharCode(...o)}return btoa(i)}function HNe(e){const A=atob(e),t=new Uint8Array(A.length);for(let i=0;i<A.length;i+=1)t[i]=A.charCodeAt(i);return t.buffer}function YNe(e){try{const A=localStorage.getItem(`${_et}${e}`);return A?HNe(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function ket(e,A){try{const t=UNe(A);localStorage.setItem(`${_et}${e}`,t)}catch(t){console.warn("Failed to write STEP GLB cache",t)}}function JNe(){const e=globalThis;return e.stepUrlToGltfModelConversions||(e.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),e.stepUrlToGltfModelConversions}var TNe=({stepUrl:e,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r})=>{const[a,g]=AA.useState(null);return AA.useEffect(()=>{let c=!0,I=null,l=!0;const B=JNe(),C=YNe(e);if(C){const E={arrayBuffer:C,blobUrl:URL.createObjectURL(new Blob([C],{type:"model/gltf-binary"}))};return B.completed.set(e,E),I=E.blobUrl,l=!1,g(E.blobUrl),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}}const Q=B.completed.get(e);if(Q)return I=Q.blobUrl,l=!1,g(Q.blobUrl),ket(e,Q.arrayBuffer),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)};let h=B.inProgress.get(e);return h||(h=LNe(e).then(E=>{const u={arrayBuffer:E,blobUrl:URL.createObjectURL(new Blob([E],{type:"model/gltf-binary"}))};return B.completed.set(e,u),B.inProgress.delete(e),u}).catch(E=>{throw B.inProgress.delete(e),E}),B.inProgress.set(e,h)),h.then(E=>{c&&(I=E.blobUrl,l=!1,g(E.blobUrl),ket(e,E.arrayBuffer))}).catch(E=>{console.error("Failed to convert STEP file to GLB",E),c&&g(null)}),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}},[e]),a?Z.jsx(xet,{gltfUrl:a,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r}):null},PNe=(e,A)=>{if(e)return A?A(e):e},vet=(...e)=>e,pdA=class extends Qn.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},KNe=({error:e,onError:A})=>(AA.useEffect(()=>{A(e)},[e,A]),null),Fet=({cad_component:e,circuitJson:A,resolveStaticAsset:t})=>{const i=Mtt(A),[n,o]=AA.useState(!1),{visibility:s}=OF(),[r,a]=AA.useState(null),g=AA.useCallback(R=>{R?.mousePosition?(o(!0),a(R.mousePosition)):(o(!1),a(null))},[]),c=AA.useCallback(()=>{o(!1),a(null)},[]),I=AA.useMemo(()=>yn(A).source_component.getUsing({source_component_id:e.source_component_id})?.name,[A,e.source_component_id]),l=AA.useMemo(()=>A.filter(F=>F.type==="pcb_plated_hole"&&F.pcb_component_id===e.pcb_component_id).length>0,[A,e.pcb_component_id]),B=AA.useCallback(R=>PNe(R,t),[t]),C=B(e.model_obj_url??e.model_wrl_url??e.model_stl_url),Q=B(e.model_glb_url??e.model_gltf_url),h=B(e.model_step_url),[E,u]=AA.useState(0),[d,f]=AA.useState(null);AA.useEffect(()=>{u(0),f(null)},[e.cad_component_id,C,Q,h]);const w=A.find(R=>R.type==="pcb_component"&&R.source_component_id===e.source_component_id)?.layer??"top",D=AA.useMemo(()=>e.rotation?vet(e.rotation.x*Math.PI/180,e.rotation.y*Math.PI/180,e.rotation.z*Math.PI/180):vet(0,0,0),[e.rotation,w]),S=AA.useMemo(()=>{if(!e.position)return;let R;return w==="top"?R=e.position.z:w==="bottom"?R=-(e.position.z+i):R=e.position.z,[e.position.x,e.position.y,R]},[e.position,w,i]),_=AA.useMemo(()=>{const R=[];return C&&R.push(Z.jsx(FNe,{url:C,position:S,rotation:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-mixed-${C}`)),Q&&R.push(Z.jsx(xet,{gltfUrl:Q,position:S,rotation:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-gltf-${Q}`)),h&&!e.model_jscad&&!e.footprinter_string&&R.push(Z.jsx(TNe,{stepUrl:h,position:S,rotation:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-step-${h}`)),R},[S,e.cad_component_id,e.footprinter_string,e.model_jscad,e.model_unit_to_mm_scale_factor,e.show_as_translucent_model,Q,g,c,n,D,h,C]);let b=null;if(_.length>0){if(E>=_.length){if(d)throw d;return null}b=Z.jsx(pdA,{fallback:({error:R})=>Z.jsx(KNe,{error:R,onError:F=>{f(F),u(H=>Math.max(H,E+1))}}),children:_[E]},`${e.cad_component_id}-fallback-${E}`)}else e.model_jscad?b=Z.jsx(xNe,{jscadPlan:e.model_jscad,positionOffset:S,rotationOffset:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},e.cad_component_id):e.footprinter_string&&(b=Z.jsx(mNe,{positionOffset:S,rotationOffset:D,footprint:e.footprinter_string,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model}));if(e.show_as_translucent_model){if(!s.translucentModels)return null}else if(l&&!s.throughHoleModels||!l&&!s.smtModels)return null;return Z.jsxs(Z.Fragment,{children:[b,n&&r?Z.jsx(Rtt,{position:r,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:I??"<unknown>"}):null]})},Met={version:"0.0.541"};function qNe(e){e.querySelectorAll("canvas").forEach(A=>A.remove())}var ONe=e=>{e.outputColorSpace=Vm,e.toneMapping=hFA,e.toneMappingExposure=1},Get="cadViewerCameraStateSession",Ret=(e,A)=>{try{const t={position:e.position.toArray(),quaternion:e.quaternion.toArray(),up:e.up.toArray(),fov:e.fov??50,target:A.target.toArray()};sessionStorage.setItem(Get,JSON.stringify(t))}catch(t){console.warn("Failed to save camera:",t)}},fdA=(e,A)=>{try{const t=sessionStorage.getItem(Get);if(!t)return!1;const i=JSON.parse(t);if(e.position.fromArray(i.position),e.quaternion.fromArray(i.quaternion),e.up.fromArray(i.up),"fov"in e){const n=e;n.fov=i.fov,n.updateProjectionMatrix?.()}return A.target.fromArray(i.target),A.update(),e.updateMatrixWorld(),!0}catch(t){return console.warn("Failed to restore camera:",t),!1}},Net=AA.createContext(void 0),WNe=({children:e,defaultTarget:A,initialCameraPosition:t})=>{const i=AA.useRef(null),n=AA.useRef(null),[o,s]=AA.useState(null),[r,a]=AA.useState("perspective"),[g,c]=AA.useState(t??null),[I,l]=AA.useState(new Cf(0,0,0)),B=AA.useMemo(()=>{const[E,u,d]=t??[5,-5,5],f=Math.hypot(E-A.x,u-A.y,d-A.z);return f>0?f:5},[t,A]),C=AA.useCallback(E=>{const u=[A.x,A.y,A.z],d=n.current,f=i.current;let m=B;switch(d&&f&&(m=d.position.distanceTo(f.target)),E){case"Top Center Angled":{const w=m/Math.sqrt(2);return{position:[A.x,A.y-w,A.z+w],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,n,i]),Q=AA.useCallback(E=>{i.current=E},[]),h=AA.useMemo(()=>({controlsRef:i,mainCameraRef:n,defaultTarget:A,baseDistance:B,controller:o,setController:s,getPresetConfig:C,handleControlsChange:Q,cameraType:r,setCameraType:a,cameraPosition:g,setCameraPosition:c,cameraRotation:I,setCameraRotation:l,saveCameraToSession:Ret,loadCameraFromSession:fdA}),[A,B,o,C,Q,r,g,I]);return Z.jsx(Net.Provider,{value:h,children:e})},ak=()=>{const e=AA.useContext(Net);if(!e)throw new Error("useCameraController must be used within a CameraControllerProvider");return e},ZNe=AA.forwardRef(({children:e,scene:A,camera:t,style:i,onCreated:n},o)=>{const{cameraType:s}=ak(),r=AA.useRef(null),[a,g]=AA.useState(null),c=AA.useRef([]),I=AA.useRef(void 0);I.current=n;const l=AA.useRef(null),B=AA.useCallback(E=>{c.current.push(E)},[]),C=AA.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=AA.useMemo(()=>new Pv,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=AA.useRef(new _g);return AA.useImperativeHandle(o,()=>h.current),AA.useEffect(()=>{if(!r.current)return;qNe(r.current);const E=new Vq({antialias:!0,alpha:!0});ONe(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 Yh(75,u,.1,1e3):new aU(-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)):(t?.up&&d.up.set(t.up[0],t.up[1],t.up[2]),t?.position&&d.position.set(t.position[0],t.position[1],t.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 gLt,w=()=>{const S=m.getElapsedTime(),_=m.getDelta();c.current.forEach(b=>b(S,_)),E.render(Q,d),f=requestAnimationFrame(w)};w();const D=()=>{if(r.current){const S=r.current.clientWidth/r.current.clientHeight;d instanceof Yh?d.aspect=S:d instanceof aU&&(d.left=-10*S,d.right=10*S,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),E.setSize(r.current.clientWidth,r.current.clientHeight)}};return window.addEventListener("resize",D),()=>{l.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",D),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]),Z.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&Z.jsx(Gtt.Provider,{value:a,children:Z.jsx(fNe,{children:e})})})}),VNe=({autoRotate:e,autoRotateSpeed:A,onStart:t,panSpeed:i,rotateSpeed:n,zoomSpeed:o,enableDamping:s,dampingFactor:r,target:a,onControlsChange:g})=>{const{camera:c,renderer:I}=nd(),l=AA.useMemo(()=>!c||!I?null:new pYt(c,I.domElement),[c,I]);return AA.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),AA.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),AA.useEffect(()=>{l&&(l.autoRotate=e||!1,l.autoRotateSpeed=A||1,i!==void 0&&(l.panSpeed=i),n!==void 0&&(l.rotateSpeed=n),o!==void 0&&(l.zoomSpeed=o),s!==void 0&&(l.enableDamping=s),r!==void 0&&(l.dampingFactor=r),l.zoomToCursor=!0,l.mouseButtons={LEFT:Kx.ROTATE,MIDDLE:Kx.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,e,A,i,n,o,s,r,a]),AA.useEffect(()=>{if(!(!l||!t))return l.addEventListener("start",t),()=>{l.removeEventListener("start",t)}},[l,t]),AA.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),HY(()=>{l?.update()},[l]),null},jNe=`
|
|
5153
5153
|
varying vec3 worldPosition;
|
|
5154
5154
|
void main() {
|
|
5155
5155
|
worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
@@ -5183,7 +5183,7 @@ ${a.join(`
|
|
|
5183
5183
|
gl_FragColor = vec4(color, max(g1, g2) * a);
|
|
5184
5184
|
if (gl_FragColor.a <= 0.0) discard;
|
|
5185
5185
|
}
|
|
5186
|
-
`,XNe=({rotation:e,infiniteGrid:A,cellSize:t=1,sectionSize:i=10})=>{const{scene:n,camera:o}=nd(),s=1e3,r=AA.useMemo(()=>{const a=new ow(s,s);a.rotateX(-Math.PI/2);const g=new rD({vertexShader:jNe,fragmentShader:zNe,uniforms:{cellSize:{value:t},sectionSize:{value:i},gridColor:{value:new An(15658734)},sectionColor:{value:new An(13421823)},fadeDistance:{value:100},fadeStrength:{value:1.5}},transparent:!0,side:YQ}),c=new Io(a,g);return e&&c.rotation.fromArray(e),c},[s,t,i,e]);return HY(()=>{A&&r.position.set(o.position.x,o.position.y,0)}),AA.useEffect(()=>{if(!(!n||!r))return n.add(r),()=>{n.remove(r),r.geometry.dispose(),Array.isArray(r.material)?r.material.forEach(a=>a.dispose()):r.material.dispose()}},[n,r]),null},$Ne=()=>{const{scene:e}=nd(),A=AA.useMemo(()=>new HGA(16777215,Math.PI/2),[]),t=AA.useMemo(()=>{const i=new BAA(16777215,Math.PI/4);return i.position.set(-10,-10,10),i.decay=0,i},[]);return AA.useEffect(()=>{if(e)return e.add(A),e.add(t),()=>{e.remove(A),e.remove(t)}},[e,A,t]),null},A2e=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,t2e=()=>{const{controlsRef:e,mainCameraRef:A,defaultTarget:t,setController:i,getPresetConfig:n}=ak(),o=AA.useRef(null),s=AA.useRef(new Zd),r=AA.useRef(new Gt),a=AA.useRef(new Gt),g=AA.useRef(new Zd),c=AA.useRef(new Zd),I=AA.useRef(new _g),l=AA.useRef(new _g),B=AA.useCallback(({position:Q,target:h,up:E,durationMs:u=600})=>{if(!A.current)return;const d=e.current?.target??t,f=new Gt(Q[0],Q[1],Q[2]),m=h?new Gt(h[0],h[1],h[2]):t.clone(),w=new Gt(...E??[0,0,1]).normalize(),D=l.current;D.position.copy(f),D.up.copy(w),D.lookAt(m);const S=D.quaternion.clone(),_=A.current.quaternion.clone(),b=A.current.position.clone(),R=d.clone(),F=I.current;F.up.set(0,0,1),F.position.copy(b),F.lookAt(R);const H=F.quaternion.clone();F.up.set(0,0,1),F.position.copy(f),F.lookAt(m);const Y=F.quaternion.clone(),J=H.clone().invert().multiply(_).normalize(),O=Y.clone().invert().multiply(S).normalize();o.current={fromPosition:b,toPosition:f,fromTarget:R,toTarget:m,toQuaternion:S,rollFrom:J,rollTo:O,startTime:performance.now(),duration:u}},[A,e,t]),C=AA.useCallback(Q=>{if(Q==="Custom")return;const h=n(Q);h&&B(h)},[B,n]);return AA.useEffect(()=>A.current?(i({animateTo:B,animateToPreset:C}),()=>{i(null)}):void 0,[B,C,A,i]),HY(()=>{if(!A.current||!o.current)return;const{fromPosition:Q,toPosition:h,fromTarget:E,toTarget:u,toQuaternion:d,rollFrom:f,rollTo:m,startTime:w,duration:D}=o.current,S=performance.now()-w,_=D<=0?1:Math.min(S/D,1),b=A2e(_);A.current.position.lerpVectors(Q,h,b);const R=r.current;R.copy(E).lerp(u,b);const F=I.current;F.up.set(0,0,1),F.position.copy(A.current.position),F.lookAt(R);const H=s.current;H.copy(F.quaternion);const Y=g.current;Y.copy(f);const J=c.current;J.copy(m),f.dot(m)<0&&(J.x*=-1,J.y*=-1,J.z*=-1,J.w*=-1),J.normalize(),Y.slerp(J,b),A.current.quaternion.copy(H).multiply(Y).normalize();const O=a.current;O.set(0,1,0).applyQuaternion(A.current.quaternion).normalize(),A.current.up.copy(O),e.current?.target.copy(R),A.current.updateMatrixWorld(),e.current?.update(),_>=1&&(A.current.position.copy(h),A.current.quaternion.copy(d),A.current.up.set(0,0,1),A.current.updateMatrixWorld(),e.current?.target.copy(u),e.current?.update(),o.current=null)}),null},e2e=()=>{const{controlsRef:e}=ak(),A=AA.useRef(null),t=AA.useRef(!1),i=AA.useRef(null),n=AA.useCallback(s=>{A.current=s,!t.current&&e.current&&fdA(s,e.current)&&(t.current=!0)},[e]),o=AA.useCallback(()=>{if(!(!A.current||!e.current)){if(!t.current&&fdA(A.current,e.current)){t.current=!0;return}clearTimeout(i.current),i.current=setTimeout(()=>{A.current&&e.current&&Ret(A.current,e.current)},150)}},[e]);return{handleCameraCreated:n,handleControlsChange:o}};function i2e(e,A){const t=new Zd().setFromEuler(new Cf(e.x,e.y,e.z)),i=new Gt(0,0,1);return i.applyQuaternion(t),i.multiplyScalar(A)}var n2e=()=>{const{mainCameraRef:e}=ak(),A=AA.useRef(null),t=AA.useRef(null),i=AA.useRef(null),n=AA.useRef(null),o=AA.useRef(null),s=AA.useRef(null);return AA.useEffect(()=>{if(!A.current)return;const r=document.createElement("canvas");t.current=r,A.current.appendChild(r);const a=new Vq({canvas:r,antialias:!0,alpha:!0});a.setSize(120,120),a.setPixelRatio(window.devicePixelRatio),i.current=a;const g=new Pv;n.current=g;const c=new Yh(75,1,.1,1e3);c.up.set(0,0,1),o.current=c;const I=new HGA(16777215,Math.PI/2);g.add(I);const l=new hf;l.rotation.fromArray([Math.PI/2,0,0]);const B=1,C=new Io(new nw(B,B,B),new TE({color:"white"}));l.add(C);const Q=new BU(new S1t(new nw(B,B,B)),new Kv({color:0,linewidth:2}));l.add(Q),g.add(l);const h=.51,E=(_,b,R)=>{const F=new NtA;return F.text=_,F.position.fromArray(b),R&&F.rotation.fromArray(R),F.color="black",F.fontSize=.25,F.anchorX="center",F.anchorY="middle",F.depthOffset=0,F.font=null,F.sync(),F},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]),w=E("Top",[0,h,0],[-Math.PI/2,0,0]),D=E("Bottom",[0,-h,0],[Math.PI/2,0,0]);l.add(u),l.add(d),l.add(f),l.add(m),l.add(w),l.add(D);const S=()=>{if(e.current){const _=i2e(e.current.rotation??new Cf(0,0,0),2);_.equals(c.position)||(c.position.copy(_),c.lookAt(0,0,0))}a.render(g,c),s.current=requestAnimationFrame(S)};return S(),()=>{s.current&&cancelAnimationFrame(s.current),u.dispose(),d.dispose(),f.dispose(),m.dispose(),w.dispose(),D.dispose(),C.geometry.dispose(),C.material.dispose(),Q.geometry.dispose(),Q.material.dispose(),g.clear(),a.dispose(),a.forceContextLoss(),t.current&&A.current&&A.current.removeChild(t.current)}},[e]),Z.jsx("div",{ref:A,style:{position:"absolute",top:0,left:0,width:120,height:120,zIndex:YY.orientationCube}})},o2e=()=>{const{camera:e}=nd(),{setCameraRotation:A}=ak();return HY(()=>{e&&A(e.rotation)}),null},Let=AA.forwardRef(({children:e,initialCameraPosition:A=[5,-5,5],autoRotateDisabled:t,clickToInteractEnabled:i=!1,boardDimensions:n,boardCenter:o,onUserInteraction:s,onCameraControllerReady:r},a)=>{const[g,c]=AA.useState(!i),{mainCameraRef:I,handleControlsChange:l,controller:B}=ak(),{handleCameraCreated:C,handleControlsChange:Q}=e2e();AA.useEffect(()=>{r&&r(B)},[B,r]);const h=AA.useMemo(()=>{if(!n)return 10;const u=n.width??0,d=n.height??0,m=Math.max(u,d)*1.5;return m>10?m:10},[n]),E=AA.useMemo(()=>{if(o)return[o.x,o.y,0]},[o]);return Z.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[Z.jsx(n2e,{}),Z.jsxs(ZNe,{ref:a,scene:{up:new Gt(0,0,1)},camera:{up:[0,0,1],position:A},onCreated:({camera:u})=>{I.current=u,C(u)},children:[Z.jsx(t2e,{}),Z.jsx(o2e,{}),g&&Z.jsx(VNe,{autoRotate:!t,autoRotateSpeed:1,onStart:s,rotateSpeed:.5,panSpeed:.75,zoomSpeed:.5,enableDamping:!0,dampingFactor:.1,target:E,onControlsChange:u=>{l(u),Q()}}),Z.jsx($Ne,{}),Z.jsx(XNe,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:3,sectionSize:h,args:[h,h]}),e]}),Z.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:["@",Met.version]}),i&&!g&&Z.jsx("button",{type:"button",onClick:()=>c(!0),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&c(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:YY.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center"},children:Z.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"})})]})}),Uet=e=>AA.useMemo(()=>{if(!e)return[];const A=new _ue;return A.add(e),A.render(),A.getCircuitJson()},[e]),s2e=e=>{const[A,t]=AA.useState([]),[i,n]=AA.useState(!0);return AA.useEffect(()=>{if(!e)return;(async()=>{n(!0);const r=(Array.isArray(e)?e:[e]).map(async(a,g)=>{const c=vye.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);t(a)}catch(a){console.error("Error generating STLs:",a),t([])}finally{n(!1)}})()},[e]),{stls:A,loading:i}},r2e=Xa(KF()),a2e=Xa(XZ()),Tn=.01,_a={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]},mw=.001,XQ=32,ww=150,dV=.6,ydA={fr1:_a.fr1Tan,fr4:_a.fr4Tan},g2e={fr1:_a.fr1SolderMaskGreen,fr4:_a.fr4SolderMaskGreen},c2e=Xa(UY()),I2e=Xa(KF()),l2e=Xa(qF()),B2e=Xa(btt()),Het=e=>{let A=0;for(let i=0;i<e.length;i++){const n=(i+1)%e.length;A+=e[i][0]*e[n][1],A-=e[n][0]*e[i][1]}return A/2<=0},mdA=(e,A=1.2,t={})=>{const{xyOutset:i=0}=t,{outline:n}=e;let o=n.map(a=>[a.x,a.y]);Het(o)&&(o=o.reverse());let s=(0,I2e.polygon)({points:o});i!==0&&(s=(0,B2e.expand)({delta:i,corners:"edge"},s));let r=(0,c2e.extrudeLinear)({height:A},s);return r=(0,l2e.translate)([0,0,-A/2],r),r},C2e=e=>{const A=e.filter(a=>a.type==="pcb_panel"),t=yn(e).pcb_board.list();let i,n=1.2;if(A.length>0)i=A[0],n=t.find(g=>g.pcb_panel_id===i.pcb_panel_id)?.thickness??1.2;else{if(i=t.filter(g=>!g.pcb_panel_id)[0],!i)return console.warn("No pcb_board or pcb_panel found for simplified geometry"),[];n=i.thickness??1.2}let o;"outline"in i&&i.outline&&i.outline.length>0?o=mdA({outline:i.outline},n):o=(0,r2e.cuboid)({size:[i.width??10,i.height??10,n],center:[i.center.x,i.center.y,0]});const s="material"in i&&i.material?i.material:A.length>0?t.find(a=>a.pcb_panel_id===i.pcb_panel_id)?.material??"fr4":"fr4",r=ydA[s]??_a.fr4Tan;return[(0,a2e.colorize)(r,o)]},tJ=Xa(XZ()),Zh=Xa(LY()),wdA=Xa(UY()),kf=Xa(qF()),iI=Xa(KF()),gk=Xa(KF()),Q2e=Xa(UY()),pV=Xa(qF()),h2e=Xa(LY()),E2e=64,u2e=(e,A,t)=>{const i=(0,gk.ellipse)({center:[0,0],radius:[Math.max(e/2,Tn/2),Math.max(A/2,Tn/2)],segments:E2e}),n=(0,Q2e.extrudeLinear)({height:t},i);return(0,pV.translate)([0,0,-t/2],n)},d2e=(e,A,t)=>{const i=Math.max(e,Tn),n=Math.max(A,Tn);if(Math.abs(i-n)<1e-6)return(0,gk.cylinder)({center:[0,0,0],radius:i/2,height:t});const o=i>=n,s=o?i:n,r=o?n:i,a=Math.max(s-r,0),g=(0,gk.cuboid)({center:[0,0,0],size:o?[a,r,t]:[r,a,t]});if(a<=1e-6)return(0,gk.cylinder)({center:[0,0,0],radius:r/2,height:t});const c=a/2,I=(0,gk.cylinder)({center:o?[-c,0,0]:[0,-c,0],radius:r/2,height:t}),l=(0,gk.cylinder)({center:o?[c,0,0]:[0,c,0],radius:r/2,height:t});return(0,h2e.union)(g,I,l)},fV=(e,A,t={})=>{const i=e.hole_shape||"circle",n=t.sizeDelta??0,o=e.hole_offset_x||0,s=e.hole_offset_y||0,r=[e.x+o,e.y+s,0];if(i==="circle"){const B=Math.max((e.hole_diameter??0)+n,Tn),C=Math.max(B/2,Tn/2);return(0,gk.cylinder)({center:r,radius:C,height:A})}const a=e.hole_width??e.hole_diameter,g=e.hole_height??e.hole_diameter;if(!a||!g)return null;const c=Math.max(a+n,Tn),I=Math.max(g+n,Tn);if(i==="oval"){const B=u2e(c,I,A);return(0,pV.translate)([r[0],r[1],0],B)}if(i==="pill"||i==="rotated_pill"){let B=d2e(c,I,A);if(!B)return null;const C=e.ccw_rotation||0;return C&&(B=(0,pV.rotateZ)(C*Math.PI/180,B)),(0,pV.translate)(r,B)}const l=Math.max((e.hole_diameter??a??g??Tn)+n,Tn);return(0,gk.cylinder)({center:r,radius:l/2,height:A})},zr=Xa(KF()),JD=Xa(XZ()),nI=Xa(LY()),Yet=Xa(qF()),yV=Xa(UY()),vf=Xa(qF()),p2e=1e-5;function Jet(e,A,t){if(typeof t!="number"||!Number.isFinite(t)||t<=0)return 0;const i=e/2,n=A/2,o=Math.min(i,n)-2*p2e;return Math.max(0,Math.min(t,o))}function ck(e){if(!(!e||typeof e!="object"))return e.corner_radius??e.cornerRadius??e.rect_pad_border_radius??e.rectPadBorderRadius??e.rect_border_radius??e.rectBorderRadius??void 0}var f2e=.05,DdA=64,jF=(e,A)=>A?(0,nI.intersect)(A,e):e,eJ=(e,A,t={})=>{const{clipGeom:i}=t;e.shape||(e.shape="circle");const n=Math.max(A.pcbThickness*.002,Tn/5),o=Math.max(A.pcbThickness*3e-4,Tn/20),s=Math.max(A.pcbThickness*.0025,Tn/4),r=A.pcbThickness+2*f2e+4*Tn,a=Math.max(A.pcbThickness-2*(n+o+s),Tn),g=Math.max(a,Tn);if(e.shape==="circle"){const c=e.outer_diameter??Math.max(e.hole_diameter,0),I=a,l=(0,zr.cylinder)({center:[e.x,e.y,0],radius:c/2,height:I}),B=jF(l,i),C=(0,zr.cylinder)({center:[e.x,e.y,0],radius:Math.max(e.hole_diameter/2,.01),height:r});return(0,JD.colorize)(_a.copper,(0,nI.subtract)(B,C))}if(e.shape==="oval"){const c=e.outer_width||e.hole_width||0,I=e.outer_height||e.hole_height||0,l=e.hole_width||0,B=e.hole_height||0,C=(()=>{const E=(0,zr.cylinder)({center:[0,0,0],radius:1,height:a,segments:64}),u=(0,Yet.scale)([c/2,I/2,1],E);return(0,vf.translate)([e.x,e.y,0],u)})(),Q=jF(C,i),h=(()=>{const E=(0,zr.cylinder)({center:[0,0,0],radius:1,height:r,segments:64}),u=(0,Yet.scale)([Math.max(l/2,.01),Math.max(B/2,.01),1],E);return(0,vf.translate)([e.x,e.y,0],u)})();return(0,JD.colorize)(_a.copper,(0,nI.subtract)(Q,h))}if(e.shape==="circular_hole_with_rect_pad"){const c=e.hole_offset_x||0,I=e.hole_offset_y||0,l=e.rect_pad_width||e.hole_diameter,B=e.rect_pad_height||e.hole_diameter,C=ck(e),Q=jF((0,nI.union)((()=>{const u=(0,zr.roundedRectangle)({size:[l,B],roundRadius:C||0,segments:DdA}),d=(0,yV.extrudeLinear)({height:a},u);return(0,vf.translate)([e.x,e.y,-a/2],d)})(),(0,zr.cylinder)({center:[e.x+(c||0),e.y+(I||0),0],radius:e.hole_diameter/2,height:g})),i),h=(0,zr.cylinder)({center:[e.x+(c||0),e.y+(I||0),0],radius:Math.max(e.hole_diameter/2-Tn,.01),height:r}),E=(0,nI.subtract)(Q,h);return t.clipGeom?(0,JD.colorize)(_a.copper,(0,nI.intersect)(E,t.clipGeom)):(0,JD.colorize)(_a.copper,E)}if(e.shape==="pill"){const c=(e.ccw_rotation||0)*Math.PI/180,I=F=>{if(!c)return F;const H=(0,vf.translate)([-e.x,-e.y,0],F),Y=(0,vf.rotate)([0,0,c],H);return(0,vf.translate)([e.x,e.y,0],Y)},l=e.hole_height>e.hole_width,B=l?e.hole_height:e.hole_width,C=l?e.hole_width:e.hole_height,Q=l?e.outer_height||C+.2:e.outer_width||B+.2,h=l?e.outer_width||B+.2:e.outer_height||C+.2,E=C/2,u=Math.abs(B-C),m=((F,H,Y)=>{const J=H/2,O=Math.abs(F-H);if(O<=1e-6)return(0,zr.cylinder)({center:[e.x,e.y,0],radius:J,height:Y});const W=(0,zr.cuboid)({center:[e.x,e.y,0],size:l?[H,O,Y]:[O,H,Y]}),z=(0,zr.cylinder)({center:l?[e.x,e.y-O/2,0]:[e.x-O/2,e.y,0],radius:J,height:Y}),tA=(0,zr.cylinder)({center:l?[e.x,e.y+O/2,0]:[e.x+O/2,e.y,0],radius:J,height:Y});return(0,nI.union)(W,z,tA)})(Q,h,a),w=(0,zr.cuboid)({center:[e.x,e.y,0],size:l?[C-2*Tn,u,r]:[u,C-2*Tn,r]}),D=(0,zr.cylinder)({center:l?[e.x,e.y-u/2,0]:[e.x-u/2,e.y,0],radius:E-Tn,height:r}),S=(0,zr.cylinder)({center:l?[e.x,e.y+u/2,0]:[e.x+u/2,e.y,0],radius:E-Tn,height:r}),_=(0,nI.union)(w,D,S),b=jF(I(m),i),R=I(_);return(0,JD.colorize)(_a.copper,(0,nI.subtract)(b,R))}if(e.shape==="pill_hole_with_rect_pad"){if(e.hole_shape&&e.hole_shape!=="pill"||e.pad_shape&&e.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for pill_hole_with_rect_pad");const c=e.hole_offset_x||0,I=e.hole_offset_y||0,l=e.hole_height>e.hole_width,B=l?e.hole_height:e.hole_width,C=l?e.hole_width:e.hole_height,Q=C/2,h=Math.abs(B-C),E=e.rect_pad_width||B+.2,u=e.rect_pad_height||C+.2,d=ck(e),f=.03,m=(0,nI.union)((0,zr.cuboid)({center:[e.x+c,e.y+I,0],size:l?[C+2*f,h+2*f,g]:[h+2*f,C+2*f,g]}),(0,zr.cylinder)({center:l?[e.x+c,e.y+I-h/2,0]:[e.x+c-h/2,e.y+I,0],radius:Q+f,height:g}),(0,zr.cylinder)({center:l?[e.x+c,e.y+I+h/2,0]:[e.x+c+h/2,e.y+I,0],radius:Q+f,height:g})),w=(0,nI.union)((0,zr.cuboid)({center:[e.x+c,e.y+I,0],size:l?[C,h,r]:[h,C,r]}),(0,zr.cylinder)({center:l?[e.x+c,e.y+I-h/2,0]:[e.x+c-h/2,e.y+I,0],radius:Q,height:r}),(0,zr.cylinder)({center:l?[e.x+c,e.y+I+h/2,0]:[e.x+c+h/2,e.y+I,0],radius:Q,height:r})),D=(()=>{const F=(0,zr.roundedRectangle)({size:[E,u],roundRadius:d||0,segments:DdA}),H=(0,yV.extrudeLinear)({height:a},F);return(0,vf.translate)([e.x,e.y,-a/2],H)})(),S=(0,nI.subtract)(D,w),_=(0,nI.union)((0,zr.cuboid)({center:[e.x+c,e.y+I,0],size:l?[C-2*Tn,h-2*Tn,r]:[h-2*Tn,C-2*Tn,r]}),(0,zr.cylinder)({center:l?[e.x+c,e.y+I-h/2,0]:[e.x+c-h/2,e.y+I,0],radius:Q-Tn,height:r}),(0,zr.cylinder)({center:l?[e.x+c,e.y+I+h/2,0]:[e.x+c+h/2,e.y+I,0],radius:Q-Tn,height:r})),b=(0,nI.subtract)(m,_),R=jF((0,nI.union)(S,b),i);return(0,JD.colorize)(_a.copper,R)}else if(e.shape==="rotated_pill_hole_with_rect_pad"){if(e.hole_shape&&e.hole_shape!=="rotated_pill"||e.pad_shape&&e.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for rotated_pill_hole_with_rect_pad");const c=e.hole_offset_x||0,I=e.hole_offset_y||0,l=e.hole_width,B=e.hole_height,C=l>=B,Q=C?l:B,h=C?B:l,E=h/2,u=Math.abs(Q-h),d=e.rect_pad_width||l+.2,f=e.rect_pad_height||B+.2,m=ck(e),w=.03,D=(e.hole_ccw_rotation||0)*Math.PI/180,S=(e.rect_ccw_rotation||0)*Math.PI/180,_=z=>{const tA=c*Math.cos(D)-I*Math.sin(D),aA=c*Math.sin(D)+I*Math.cos(D),eA=(0,vf.rotate)([0,0,D],z);return(0,vf.translate)([e.x+tA,e.y+aA,0],eA)},b=z=>{if(!S)return z;const tA=(0,vf.translate)([-e.x,-e.y,0],z),aA=(0,vf.rotate)([0,0,S],tA);return(0,vf.translate)([e.x,e.y,0],aA)},R=_((0,nI.union)((0,zr.cuboid)({center:[0,0,0],size:C?[u+2*w,h+2*w,g]:[h+2*w,u+2*w,g]}),(0,zr.cylinder)({center:C?[-u/2,0,0]:[0,-u/2,0],radius:E+w,height:g}),(0,zr.cylinder)({center:C?[u/2,0,0]:[0,u/2,0],radius:E+w,height:g}))),F=_((0,nI.union)((0,zr.cuboid)({center:[0,0,0],size:C?[u,h,r]:[h,u,r]}),(0,zr.cylinder)({center:C?[-u/2,0,0]:[0,-u/2,0],radius:E,height:r}),(0,zr.cylinder)({center:C?[u/2,0,0]:[0,u/2,0],radius:E,height:r}))),H=b((()=>{const z=(0,zr.roundedRectangle)({size:[d,f],roundRadius:m||0,segments:DdA}),tA=(0,yV.extrudeLinear)({height:a},z);return(0,vf.translate)([e.x,e.y,-a/2],tA)})()),Y=(0,nI.subtract)(H,F),J=_((0,nI.union)((0,zr.cuboid)({center:[0,0,0],size:C?[u-2*Tn,h-2*Tn,r]:[h-2*Tn,u-2*Tn,r]}),(0,zr.cylinder)({center:C?[-u/2,0,0]:[0,-u/2,0],radius:E-Tn,height:r}),(0,zr.cylinder)({center:C?[u/2,0,0]:[0,u/2,0],radius:E-Tn,height:r}))),O=(0,nI.subtract)(R,J),W=jF((0,nI.union)(Y,O),i);return(0,JD.colorize)(_a.copper,W)}else if(e.shape==="hole_with_polygon_pad"){const c=e.pad_outline;if(!Array.isArray(c)||c.length<3)throw new Error(`Invalid pad_outline for plated hole at (${e.x}, ${e.y})`);const I=c.map(f=>[f.x,f.y]),l=(0,zr.polygon)({points:I}),Q=((f,m)=>{const w=Math.max(f,Tn),D=(0,yV.extrudeLinear)({height:w},l);return(0,vf.translate)([e.x,e.y,m-w/2],D)})(a,0),h=jF(Q,i),E=fV(e,g);if(!E)return(0,JD.colorize)(_a.copper,h);const u=fV(e,r,{sizeDelta:-2*Tn})||E;let d=(0,nI.union)((0,nI.subtract)(h,E),E);return t.clipGeom?(d=(0,nI.subtract)(d,u),d=(0,nI.intersect)(d,t.clipGeom),(0,JD.colorize)(_a.copper,d)):(0,JD.colorize)(_a.copper,(0,nI.subtract)(d,u))}else throw new Error(`Unsupported plated hole shape: ${e.shape}`)},y2e=Xa(LY()),m2e=Xa(qF()),SdA=Xa(KF());function w2e({x:e,y:A,outerDiameter:t,holeDiameter:i,thickness:n}){if(t<=i)throw new Error(`Invalid via geometry: outerDiameter (${t}) must be > holeDiameter (${i})`);const o=Tn,s=Math.min(t/2,i/2+o),a=(0,SdA.cylinder)({center:[0,0,0],radius:s,height:n,segments:XQ}),g=n+2*Tn,c=(0,SdA.cylinder)({center:[0,0,0],radius:i/2,height:g,segments:XQ}),I=(0,y2e.subtract)(a,c);return(0,m2e.translate)([e,A,0],I)}function D2e({x:e,y:A,holeDiameter:t,thickness:i}){const n=i*1.5,o=t/2+Tn;return(0,SdA.cylinder)({center:[e,A,0],radius:o,height:n,segments:XQ})}var S2e=64,b2e=1,bdA=.05,Tet=["initializing","processing_copper_pours","processing_plated_holes","processing_holes","processing_cutouts","processing_vias","finalizing","done"],x2e=class{circuitJson;board;plated_holes;holes;traces;pcb_vias;pcb_cutouts;boardGeom=null;platedHoleGeoms=[];viaGeoms=[];copperPourGeoms=[];boardClipGeom=null;state="initializing";currentIndex=0;ctx;onCompleteCallback;finalGeoms=[];getHoleToCut(e,A){const t=Tn/10;for(const i of this.pcb_vias)if(Math.abs(i.x-e)<t&&Math.abs(i.y-A)<t&&i.hole_diameter)return{diameter:i.hole_diameter};for(const i of this.plated_holes)if(i.shape==="circle"&&Math.abs(i.x-e)<t&&Math.abs(i.y-A)<t&&i.hole_diameter)return{diameter:i.hole_diameter};return null}constructor(e,A){this.circuitJson=e,this.onCompleteCallback=A;const t=e.filter(n=>n.type==="pcb_panel"),i=yn(e).pcb_board.list();if(t.length>0){const n=t[0],o=i.find(s=>s.pcb_panel_id===n.pcb_panel_id);this.board={type:"pcb_board",pcb_board_id:n.pcb_panel_id,center:n.center,width:n.width,height:n.height,thickness:o?.thickness??1.4,material:o?.material??"fr4",num_layers:o?.num_layers??2}}else{const n=i.filter(o=>!o.pcb_panel_id);this.board=n[0]}this.plated_holes=yn(e).pcb_plated_hole.list(),this.holes=yn(e).pcb_hole.list(),this.traces=yn(e).pcb_trace.list(),this.pcb_vias=yn(e).pcb_via.list(),this.pcb_cutouts=yn(e).pcb_cutout.list(),this.ctx={pcbThickness:this.board.thickness??1.2},this.initializeBoard()}initializeBoard(){const e=this.ctx.pcbThickness+2*b2e;this.board.outline&&this.board.outline.length>0?(this.boardGeom=mdA({outline:this.board.outline},this.ctx.pcbThickness),this.boardClipGeom=mdA({outline:this.board.outline},e,{xyOutset:bdA})):(this.boardGeom=(0,iI.cuboid)({size:[this.board.width,this.board.height,this.ctx.pcbThickness],center:[this.board.center.x,this.board.center.y,0]}),this.boardClipGeom=(0,iI.cuboid)({size:[this.board.width+2*bdA,this.board.height+2*bdA,e],center:[this.board.center.x,this.board.center.y,0]})),this.state="processing_copper_pours",this.currentIndex=0}goToNextState(){const e=Tet.indexOf(this.state);e!==-1&&(this.state=Tet[e+1],this.currentIndex=0)}step(e=1){if(this.state==="done"||!this.boardGeom)return!0;for(let A=0;A<e&&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_copper_pours":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(e){if(!this.boardGeom)return;let A=null;const t=this.ctx.pcbThickness*1.5;switch(e.shape){case"rect":{const i=Jet(e.width,e.height,ck(e));if(i>0){const n=(0,iI.roundedRectangle)({size:[e.width,e.height],roundRadius:i,segments:S2e});A=(0,wdA.extrudeLinear)({height:t},n),A=(0,kf.translate)([0,0,-t/2],A)}else A=(0,iI.cuboid)({center:[0,0,0],size:[e.width,e.height,t]});if(e.rotation){const n=e.rotation*Math.PI/180;A=(0,kf.rotateZ)(n,A)}A=(0,kf.translate)([e.center.x,e.center.y,0],A);break}case"circle":A=(0,iI.cylinder)({center:[e.center.x,e.center.y,0],radius:e.radius,height:t});break;case"polygon":{let i=e.points.map(o=>[o.x,o.y]);if(i.length<3){console.warn(`PCB Cutout [${e.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);break}Het(i)&&(i=i.reverse());const n=(0,iI.polygon)({points:i});A=(0,wdA.extrudeLinear)({height:t},n),A=(0,kf.translate)([0,0,-t/2],A);break}}A&&(this.boardGeom=(0,Zh.subtract)(this.boardGeom,A))}processPlatedHole(e,A={}){if(this.boardGeom){if(e.shape==="circle"||e.shape==="circular_hole_with_rect_pad"){let t=null;if(e.shape==="circular_hole_with_rect_pad"){if(e.hole_shape&&e.hole_shape!=="circle"||e.pad_shape&&e.pad_shape!=="rect")return;t=(0,iI.cylinder)({center:[e.x+(e.hole_offset_x||0),e.y+(e.hole_offset_y||0),0],radius:e.hole_diameter/2+Tn,height:this.ctx.pcbThickness*1.5})}else t=(0,iI.cylinder)({center:[e.x,e.y,0],radius:e.hole_diameter/2+Tn,height:this.ctx.pcbThickness*1.5});A.dontCutBoard||(this.boardGeom=(0,Zh.subtract)(this.boardGeom,t));const i=eJ(e,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(i)}else if(e.shape==="pill"||e.shape==="oval"){const t=e.hole_height>e.hole_width,i=t?e.hole_height:e.hole_width,n=t?e.hole_width:e.hole_height,o=n/2,s=Math.abs(i-n);let r;if(r=(0,Zh.union)((0,iI.cuboid)({center:[e.x,e.y,0],size:t?[n,s,this.ctx.pcbThickness*1.5]:[s,n,this.ctx.pcbThickness*1.5]}),(0,iI.cylinder)({center:t?[e.x,e.y-s/2,0]:[e.x-s/2,e.y,0],radius:o,height:this.ctx.pcbThickness*1.5}),(0,iI.cylinder)({center:t?[e.x,e.y+s/2,0]:[e.x+s/2,e.y,0],radius:o,height:this.ctx.pcbThickness*1.5})),e.ccw_rotation){const g=e.ccw_rotation*Math.PI/180;r=(0,kf.translate)([e.x,e.y,0],(0,kf.rotateZ)(g,(0,kf.translate)([-e.x,-e.y,0],r)))}A.dontCutBoard||(this.boardGeom=(0,Zh.subtract)(this.boardGeom,r));const a=eJ(e,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(e.shape==="pill_hole_with_rect_pad"){if(e.hole_shape&&e.hole_shape!=="pill"||e.pad_shape&&e.pad_shape!=="rect")return;const t=e.hole_height>e.hole_width,i=t?e.hole_height:e.hole_width,n=t?e.hole_width:e.hole_height,o=n/2,s=Math.abs(i-n);let r;r=(0,Zh.union)((0,iI.cuboid)({center:[e.x+(e.hole_offset_x||0),e.y+(e.hole_offset_y||0),0],size:t?[n,s,this.ctx.pcbThickness*1.5]:[s,n,this.ctx.pcbThickness*1.5]}),(0,iI.cylinder)({center:t?[e.x+(e.hole_offset_x||0),e.y+(e.hole_offset_y||0)-s/2,0]:[e.x+(e.hole_offset_x||0)-s/2,e.y+(e.hole_offset_y||0),0],radius:o,height:this.ctx.pcbThickness*1.5}),(0,iI.cylinder)({center:t?[e.x+(e.hole_offset_x||0),e.y+(e.hole_offset_y||0)+s/2,0]:[e.x+(e.hole_offset_x||0)+s/2,e.y+(e.hole_offset_y||0),0],radius:o,height:this.ctx.pcbThickness*1.5})),A.dontCutBoard||(this.boardGeom=(0,Zh.subtract)(this.boardGeom,r));const a=eJ(e,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(e.shape==="rotated_pill_hole_with_rect_pad"){if(e.hole_shape&&e.hole_shape!=="rotated_pill"||e.pad_shape&&e.pad_shape!=="rect")return;const t=e.hole_width,i=e.hole_height,n=t>=i,o=n?t:i,s=n?i:t,r=s/2,a=Math.abs(o-s),g=e.hole_offset_x||0,c=e.hole_offset_y||0;let I=(0,Zh.union)((0,iI.cuboid)({center:[0,0,0],size:n?[a,s,this.ctx.pcbThickness*1.5]:[s,a,this.ctx.pcbThickness*1.5]}),(0,iI.cylinder)({center:n?[-a/2,0,0]:[0,-a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}),(0,iI.cylinder)({center:n?[a/2,0,0]:[0,a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}));const l=(e.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,kf.rotateZ)(l,I);const Q=(0,kf.translate)([e.x+B,e.y+C,0],I);A.dontCutBoard||(this.boardGeom=(0,Zh.subtract)(this.boardGeom,Q));const h=eJ(e,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(h)}else if(e.shape==="hole_with_polygon_pad"){const t=e.pad_outline;if(!Array.isArray(t)||t.length<3)return;const i=this.ctx.pcbThickness*1.5,n=fV(e,i,{sizeDelta:2*Tn}),o=fV(e,i,{sizeDelta:-2*Tn});if(!n||!o)return;A.dontCutBoard||(this.boardGeom=(0,Zh.subtract)(this.boardGeom,n)),this.platedHoleGeoms=this.platedHoleGeoms.map(r=>(0,tJ.colorize)(_a.copper,(0,Zh.subtract)(r,o)));const s=eJ(e,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(s)}}}processHole(e){if(!this.boardGeom)return;const A=this.ctx.pcbThickness*1.5;if(e.hole_shape==="circle"){const t=(0,iI.cylinder)({center:[e.x,e.y,0],radius:e.hole_diameter/2+Tn,height:A});this.boardGeom=(0,Zh.subtract)(this.boardGeom,t);const i=(0,iI.cylinder)({center:[e.x,e.y,0],radius:e.hole_diameter/2+Tn/2,height:A});this.platedHoleGeoms=this.platedHoleGeoms.map(n=>(0,tJ.colorize)(_a.copper,(0,Zh.subtract)(n,i)))}else if(e.hole_shape==="pill"||e.hole_shape==="rotated_pill"||e.hole_shape==="oval"){const t=e.hole_width??e.hole_diameter,i=e.hole_height??e.hole_diameter,n=e.ccw_rotation??e.rotation??0,o=.02,s=(g,c,I,l)=>{if(g<=0||c<=0)return null;if(l)return(0,kf.translate)([0,0,-I/2],(0,wdA.extrudeLinear)({height:I},(0,iI.ellipse)({radius:[g/2,c/2]})));const B=Math.min(g,c)/2,C=Math.abs(g-c);return g>c?(0,Zh.union)((0,iI.cuboid)({center:[0,0,0],size:[C,c,I]}),(0,iI.cylinder)({center:[-C/2,0,0],radius:B,height:I}),(0,iI.cylinder)({center:[C/2,0,0],radius:B,height:I})):(0,Zh.union)((0,iI.cuboid)({center:[0,0,0],size:[g,C,I]}),(0,iI.cylinder)({center:[0,-C/2,0],radius:B,height:I}),(0,iI.cylinder)({center:[0,C/2,0],radius:B,height:I}))};let r=s(t,i,A,e.hole_shape==="oval"),a=s(t-2*o,i-2*o,A,e.hole_shape==="oval");if(r&&n!==0&&(r=(0,kf.rotateZ)(n*Math.PI/180,r)),a&&n!==0&&(a=(0,kf.rotateZ)(n*Math.PI/180,a)),r){const g=(0,kf.translate)([e.x,e.y,0],r);this.boardGeom=(0,Zh.subtract)(this.boardGeom,g)}if(a){const g=(0,kf.translate)([e.x,e.y,0],a);this.platedHoleGeoms=this.platedHoleGeoms.map(c=>(0,tJ.colorize)(_a.copper,(0,Zh.subtract)(c,g)))}}}processVia(e){if(this.boardGeom){if(typeof e.outer_diameter=="number"&&typeof e.hole_diameter=="number"){const A=w2e({x:e.x,y:e.y,outerDiameter:e.outer_diameter,holeDiameter:e.hole_diameter,thickness:this.ctx.pcbThickness});let t=A;this.boardClipGeom&&(t=(0,Zh.intersect)(this.boardClipGeom,A),t=(0,tJ.colorize)(_a.copper,t)),this.viaGeoms.push(t)}if(typeof e.hole_diameter=="number"){const A=D2e({x:e.x,y:e.y,holeDiameter:e.hole_diameter,thickness:this.ctx.pcbThickness});this.boardGeom=(0,Zh.subtract)(this.boardGeom,A)}}}finalize(){if(!this.boardGeom)return;const e=ydA[this.board.material]??_a.fr4Tan;this.boardGeom=(0,tJ.colorize)(e,this.boardGeom),this.finalGeoms=[this.boardGeom,...this.platedHoleGeoms,...this.viaGeoms,...this.copperPourGeoms],this.onCompleteCallback&&this.onCompleteCallback(this.finalGeoms)}getGeoms(){return this.finalGeoms}},_2e=e=>{const[A,t]=AA.useState(null),i=AA.useRef(!1);return AA.useEffect(()=>{let n=!1;if(!e){t(null);return}if(!e.some(g=>g.type==="pcb_board"||g.type==="pcb_panel")){t(null);return}const s=C2e(e);t(s);const r=new x2e(e,g=>{});return(async()=>{if(!i.current){i.current=!0;try{let g=!1;for(;!g&&!n;)g=r.step(1),g||await new Promise(c=>setTimeout(c,0));n||t(r.getGeoms())}catch(g){console.error("Error during board geometry building:",g)}finally{i.current=!1}}})(),()=>{n=!0}},[e]),A},k2e=({children:e,parent:A,position:t,rotation:i,scale:n,color:o,fontSize:s,anchorX:r,anchorY:a,depthOffset:g})=>{const{rootObject:c}=nd(),I=AA.useMemo(()=>{const l=new NtA;return l.text=e,t&&l.position.fromArray(t),i&&l.rotation.fromArray(i),n&&l.scale.fromArray(n),l.color=o||"white",l.fontSize=s||1,l.anchorX=r||"center",l.anchorY=a||"middle",l.depthOffset=g||0,l.font=null,l.sync(),l},[e,t,i,n,o,s,r,a,g]);return AA.useEffect(()=>{const l=A||c;if(!(!l||!I))return l.add(I),()=>{l.remove(I),I.dispose()}},[c,A,I]),null},Pet=({error:e,cad_component:A})=>{const{rootObject:t}=nd(),[i,n]=AA.useState(!1),[o,s]=AA.useState(null),r=AA.useCallback(I=>{I?.mousePosition?(n(!0),s(I.mousePosition)):(n(!1),s(null))},[]),a=AA.useCallback(()=>{n(!1),s(null)},[]),g=AA.useMemo(()=>A?.position?[A.position.x,A.position.y,A.position.z].map(l=>Number.isNaN(l)?0:l):[0,0,0],[A]),c=AA.useMemo(()=>{const I=new hf;return I.position.fromArray(g),I},[g]);return AA.useEffect(()=>{if(t)return t.add(c),()=>{t.remove(c)}},[t,c]),Z.jsxs(Z.Fragment,{children:[Z.jsxs(AJ,{isHovered:i,onHover:r,onUnhover:a,object:c,children:[Z.jsx(v2e,{parent:c}),Z.jsx(k2e,{parent:c,scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:`${e.toString().slice(0,50)}...`})]}),i&&o?Z.jsx(Rtt,{position:o,style:{fontFamily:"sans-serif",transform:"translate3d(-1rem, 0rem, 0)",backgroundColor:"white",padding:"6px",borderRadius:"4px",color:"red",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:e.toString()}):null]})},v2e=({parent:e})=>{const A=AA.useMemo(()=>{const t=new Io(new nw(.5,.5,.5),new TE({depthTest:!1,transparent:!0,color:"red",opacity:.5}));return t.renderOrder=999999,t.rotation.fromArray([Math.PI/4,Math.PI/4,0]),t},[]);return AA.useEffect(()=>(e.add(A),()=>{e.remove(A)}),[e,A]),null};function F2e({stlUrl:e,stlData:A,mtlUrl:t,color:i,opacity:n=1,layerType:o}){const{rootObject:s}=nd(),[r,a]=AA.useState(null);AA.useEffect(()=>{const c=new oYt;if(A){try{const I=c.parse(A);a(I)}catch(I){console.error("Failed to parse STL data",I),a(null)}return}e&&c.load(e,I=>{a(I)})},[e,A]);const g=AA.useMemo(()=>{if(!r)return null;const c=o==="board",I=new TE({color:Array.isArray(i)?new An(i[0],i[1],i[2]):i,transparent:n!==1,opacity:n,polygonOffset:c,polygonOffsetFactor:c?6:0,polygonOffsetUnits:c?6:0}),l=new Io(r,I);return l.renderOrder=c?-1:1,l},[r,i,n,o]);return AA.useEffect(()=>{if(!(!s||!g))return s.add(g),()=>{s.remove(g),g.geometry.dispose(),Array.isArray(g.material)?g.material.forEach(c=>c.dispose()):g.material.dispose()}},[s,g]),null}function M2e({stlData:e,color:A,opacity:t=1,layerType:i}){const{visibility:n}=OF();let o=!0;return i==="board"?o=n.boardBody:i==="top-copper"?o=n.topCopper:i==="bottom-copper"?o=n.bottomCopper:i==="top-silkscreen"?o=n.topSilkscreen:i==="bottom-silkscreen"&&(o=n.bottomSilkscreen),o?Z.jsx(F2e,{stlData:e,color:A,opacity:t,layerType:i}):null}var G2e=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].y,i=e[0].x,n=e[0].y;for(let o=1;o<e.length;o++){const s=e[o];s.x<A&&(A=s.x),s.y<t&&(t=s.y),s.x>i&&(i=s.x),s.y>n&&(n=s.y)}return{minX:A,minY:t,maxX:i,maxY:n}};function TD(e){if(e.outline&&e.outline.length>=3){const s=G2e(e.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=e.width??0,t=e.height??0,i=e.center?.x??0,n=e.center?.y??0;return{...{minX:i-A/2,maxX:i+A/2,minY:n-t/2,maxY:n+t/2},width:A,height:t,centerX:i,centerY:n}}function R2e({layer:e,circuitJson:A,boardData:t,copperColor:i,traceTextureResolution:n}){const s=yn(A).pcb_smtpad.list().filter(h=>h.layer===e);if(s.length===0)return null;const r=e==="top"?"top_copper":"bottom_copper",a=TD(t),g=document.createElement("canvas"),c=Math.floor(a.width*n),I=Math.floor(a.height*n);g.width=c,g.height=I;const l=g.getContext("2d");if(!l)return null;e==="bottom"&&(l.translate(0,I),l.scale(1,-1));const B="rgba(0,0,0,0)",C=new yw(l);C.configure({colorOverrides:{copper:{top:i,bottom:i,inner1:i,inner2:i,inner3:i,inner4:i,inner5:i,inner6:i},copperPour:{top:B,bottom:B},drill:B,boardOutline:B,substrate:B,keepout:B,fabricationNote:B,courtyard:{top:B,bottom:B},silkscreen:{top:B,bottom:B},soldermask:{top:B,bottom:B},soldermaskWithCopperUnderneath:{top:B,bottom:B},soldermaskOverCopper:{top:B,bottom:B}}}),C.setCameraBounds({minX:a.minX,maxX:a.maxX,minY:a.minY,maxY:a.maxY}),C.drawElements(s,{layers:[r],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});const Q=new sw(g);return Q.generateMipmaps=!0,Q.minFilter=KC,Q.magFilter=jg,Q.anisotropy=16,Q.needsUpdate=!0,Q}var N2e=e=>{const A=e.filter(t=>t.type==="pcb_panel");return A.length===0?null:A.length===1?A[0].pcb_panel_id:null};function L2e({layer:e,circuitJson:A,panelData:t,outlineColor:i="black",traceTextureResolution:n}){const o=N2e(A);if(!o)return null;const r=yn(A).pcb_board.list().filter(Q=>Q.pcb_panel_id===o||Q.position_mode==="relative_to_panel_anchor"&&!Q.pcb_panel_id);if(r.length===0)return null;const a=document.createElement("canvas"),g=Math.floor(t.width*n),c=Math.floor(t.height*n);a.width=g,a.height=c;const I=a.getContext("2d");if(!I)return null;e==="bottom"&&(I.translate(0,c),I.scale(1,-1)),I.strokeStyle=i,I.lineWidth=.05*n;const l=Q=>(Q-t.center.x+t.width/2)*n,B=Q=>(-(Q-t.center.y)+t.height/2)*n;r.forEach(Q=>{if(Q.outline&&Q.outline.length>=2)I.beginPath(),Q.outline.forEach((h,E)=>{const u=l(h.x),d=B(h.y);E===0?I.moveTo(u,d):I.lineTo(u,d)}),I.closePath(),I.stroke();else{const h=Q.width,E=Q.height,{x:u,y:d}=Q.center,f=l(u-h/2),m=B(d+E/2);I.strokeRect(f,m,h*n,E*n)}});const C=new sw(a);return C.generateMipmaps=!0,C.minFilter=KC,C.magFilter=jg,C.anisotropy=16,C.needsUpdate=!0,C}function U2e(e){return e&&e.route_type==="wire"&&typeof e.layer=="string"&&typeof e.width=="number"}function H2e(e,A){const t=[];let i=[];const n=()=>{if(i.length<2){i=[];return}t.push({...e,pcb_trace_id:`${e.pcb_trace_id}_${A}_${t.length}`,route:i}),i=[]};for(const o of e.route){if(!U2e(o)){n();continue}if(o.layer!==A){n();continue}i.push(o)}return n(),t}function Y2e({layer:e,circuitJson:A,boardData:t,traceColor:i,traceTextureResolution:n}){const o=yn(A).pcb_trace.list(),s=yn(A).pcb_via.list(),r=yn(A).pcb_plated_hole.list(),a=e==="top"?"top_copper":"bottom_copper",g=o.filter(f=>CtA(f).includes(a)).flatMap(f=>H2e(f,e));if(g.length===0)return null;const c=r.filter(f=>f.layers.includes(e)),I=[...g,...s,...c],l=TD(t),B=document.createElement("canvas"),C=Math.floor(l.width*n),Q=Math.floor(l.height*n);B.width=C,B.height=Q;const h=B.getContext("2d");if(!h)return null;e==="bottom"&&(h.translate(0,Q),h.scale(1,-1));const E="rgba(0,0,0,0)",u=new yw(h);u.configure({colorOverrides:{copper:{top:i,bottom:i,inner1:i,inner2:i,inner3:i,inner4:i,inner5:i,inner6:i},copperPour:{top:E,bottom:E},drill:E,boardOutline:E,substrate:E,keepout:E,fabricationNote:E,courtyard:{top:E,bottom:E},silkscreen:{top:E,bottom:E},soldermask:{top:E,bottom:E},soldermaskWithCopperUnderneath:{top:E,bottom:E},soldermaskOverCopper:{top:E,bottom:E}}}),u.setCameraBounds({minX:l.minX,maxX:l.maxX,minY:l.minY,maxY:l.maxY}),u.drawElements(I,{layers:[a],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});const d=new sw(B);return d.generateMipmaps=!0,d.minFilter=KC,d.magFilter=jg,d.anisotropy=16,d.needsUpdate=!0,d}var Ket=(e,A)=>{e.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},J2e=({ctx:e,layer:A,bounds:t,elements:i,copperColor:n})=>{const o=A==="top"?"top_copper":"bottom_copper",s=new yw(e);s.configure({colorOverrides:{copper:{top:n,bottom:n,inner1:n,inner2:n,inner3:n,inner4:n,inner5:n,inner6:n}}}),Ket(s,t),s.drawElements(i,{layers:[o]});const r=i.filter(I=>I.type==="pcb_copper_text"&&I.is_knockout===!0);if(r.length===0)return;const a=document.createElement("canvas");a.width=e.canvas.width,a.height=e.canvas.height;const g=a.getContext("2d");if(!g)return;const c=new yw(g);c.configure({colorOverrides:{copper:{top:"rgb(255,255,255)",bottom:"rgb(255,255,255)",inner1:"rgb(255,255,255)",inner2:"rgb(255,255,255)",inner3:"rgb(255,255,255)",inner4:"rgb(255,255,255)",inner5:"rgb(255,255,255)",inner6:"rgb(255,255,255)"}}}),Ket(c,t),c.drawElements(r.map(I=>({...I,is_knockout:!1})),{layers:[o]}),e.save(),e.globalCompositeOperation="destination-out",e.drawImage(a,0,0),e.restore()};function T2e({layer:e,circuitJson:A,boardData:t,copperColor:i="rgb(230, 153, 51)",traceTextureResolution:n=ww}){const o=A.filter(l=>l.type==="pcb_copper_text"&&"layer"in l&&l.layer===e);if(o.length===0)return null;const s=TD(t),r=Math.floor(s.width*n),a=Math.floor(s.height*n);if(r<=0||a<=0)return null;const g=document.createElement("canvas");g.width=r,g.height=a;const c=g.getContext("2d");if(!c)return null;e==="bottom"&&(c.translate(0,a),c.scale(1,-1)),J2e({ctx:c,layer:e,bounds:s,elements:o,copperColor:i});const I=new sw(g);return I.generateMipmaps=!0,I.minFilter=KC,I.magFilter=jg,I.anisotropy=16,I.needsUpdate=!0,I}var P2e=e=>{const[A=0,t=0,i=0]=e;return`rgb(${Math.round(A*255)}, ${Math.round(t*255)}, ${Math.round(i*255)})`},K2e=8;function q2e({layer:e,circuitJson:A,boardData:t,traceTextureResolution:i=ww,copperColor:n=P2e(_a.copper)}){const o=A.filter(f=>f.type==="pcb_copper_pour"),s=e==="top"?"top_copper":"bottom_copper",r=o.filter(f=>f.layer===e);if(r.length===0)return null;const a=TD(t),g=document.createElement("canvas"),c=Math.floor(a.width*i),I=Math.floor(a.height*i);g.width=c,g.height=I;const l=g.getContext("2d");if(!l)return null;e==="bottom"&&(l.translate(0,I),l.scale(1,-1));const B="rgba(0,0,0,0)",C=n,Q=n,h=(f,m)=>{if(f.length===0)return;const w=new yw(l);w.configure({colorOverrides:{copper:{top:m,bottom:m,inner1:m,inner2:m,inner3:m,inner4:m,inner5:m,inner6:m},copperPour:{top:B,bottom:B},drill:B,boardOutline:B,substrate:B,keepout:B,fabricationNote:B,courtyard:{top:B,bottom:B},silkscreen:{top:B,bottom:B},soldermask:{top:B,bottom:B},soldermaskWithCopperUnderneath:{top:B,bottom:B},soldermaskOverCopper:{top:B,bottom:B}}}),w.setCameraBounds({minX:a.minX,maxX:a.maxX,minY:a.minY,maxY:a.maxY}),w.drawElements(f,{layers:[s],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});for(let D=1;D<K2e;D+=1)w.drawElements(f,{layers:[s],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1})},E=r.filter(f=>f.covered_with_solder_mask!==!1),u=r.filter(f=>f.covered_with_solder_mask===!1);h(E,C),h(u,Q);const d=new sw(g);return d.generateMipmaps=!0,d.minFilter=KC,d.magFilter=jg,d.anisotropy=16,d.needsUpdate=!0,d}var qet=25.4,O2e=qet/1e3,W2e=/^\s*(-?\d*(?:\.\d+)?)(?:\s*(mm|mil|inch|in|"))?\s*$/i;function Z2e(e){if(!e)return;const A=e.trim().toLowerCase();return A==='"'||A==="inch"?"in":A}function mV(e){if(e==null)return;if(typeof e=="number")return Number.isFinite(e)?e:void 0;if(typeof e!="string")return;const A=e.trim();if(A.length===0)return;const t=A.match(W2e);if(!t){const r=Number.parseFloat(A);return Number.isFinite(r)?r:void 0}const[,i,n]=t,o=Number.parseFloat(i||"0");if(!Number.isFinite(o))return;switch(Z2e(n)){case"mil":return o*O2e;case"in":return o*qet;case"mm":case void 0:return o;default:return o}}function Bg(e,A){const t=mV(e);return t===void 0?A:t}var V2e="rgb(255,243,204)",ol="rgba(0,0,0,0)",j2e=(e,A)=>{e.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},z2e=e=>e.type==="pcb_fabrication_note_rect"?{...e,width:mV(e.width)??0,height:mV(e.height)??0,stroke_width:Bg(e.stroke_width,.1),corner_radius:mV(e.corner_radius)}:e.type==="pcb_fabrication_note_path"?{...e,stroke_width:Bg(e.stroke_width,.1)}:e.type==="pcb_fabrication_note_text"?{...e,font_size:Bg(e.font_size,1)}:e.type==="pcb_fabrication_note_dimension"?{...e,font_size:Bg(e.font_size,1),arrow_size:Bg(e.arrow_size,1),offset_distance:Bg(e.offset_distance,0)}:e,X2e=({ctx:e,layer:A,bounds:t,elements:i})=>{const n=`${A}_fabrication_note`,o=i.map(z2e),s=new yw(e);s.configure({colorOverrides:{copper:{top:ol,bottom:ol,inner1:ol,inner2:ol,inner3:ol,inner4:ol,inner5:ol,inner6:ol},copperPour:{top:ol,bottom:ol},drill:ol,boardOutline:ol,substrate:ol,keepout:ol,courtyard:{top:ol,bottom:ol},soldermask:{top:ol,bottom:ol},soldermaskWithCopperUnderneath:{top:ol,bottom:ol},soldermaskOverCopper:{top:ol,bottom:ol},silkscreen:{top:ol,bottom:ol},fabricationNote:V2e}}),j2e(s,t),s.drawElements(o,{layers:[n]})},$2e=e=>({minX:e.center.x-e.width/2,maxX:e.center.x+e.width/2,minY:e.center.y-e.height/2,maxY:e.center.y+e.height/2,width:e.width,height:e.height,centerX:e.center.x,centerY:e.center.y}),A1e=(e,A)=>{const t=Math.min(e.minX,A.minX),i=Math.max(e.maxX,A.maxX),n=Math.min(e.minY,A.minY),o=Math.max(e.maxY,A.maxY);return{minX:t,maxX:i,minY:n,maxY:o,width:i-t,height:o-n,centerX:(t+i)/2,centerY:(n+o)/2}},wV=(e,A)=>{const t=e.filter(s=>s.type==="pcb_panel"),i=e.filter(s=>s.type==="pcb_board"),n=t.find(s=>s.pcb_panel_id===A.pcb_board_id)??t[0];return n&&n.width>0&&n.height>0?$2e(n):(i.length>1?i:[A]).map(s=>TD(s)).reduce((s,r)=>A1e(s,r))},t1e=(e,A)=>!("layer"in e)||e.layer!==A?!1:e.type.startsWith("pcb_fabrication_note_");function e1e({layer:e,circuitJson:A,boardData:t,traceTextureResolution:i=ww}){const n=A.filter(I=>t1e(I,e));if(n.length===0)return null;const o=wV(A,t),s=Math.floor(o.width*i),r=Math.floor(o.height*i);if(s<=0||r<=0)return null;const a=document.createElement("canvas");a.width=s,a.height=r;const g=a.getContext("2d");if(!g)return null;e==="bottom"&&(g.translate(0,r),g.scale(1,-1)),X2e({ctx:g,layer:e,bounds:o,elements:n});const c=new sw(a);return c.generateMipmaps=!0,c.minFilter=KC,c.magFilter=jg,c.anisotropy=16,c.needsUpdate=!0,c}var NI="rgba(0,0,0,0)",i1e=(e,A)=>{e.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},n1e=e=>e.type==="pcb_note_line"?{...e,x1:Bg(e.x1,0),y1:Bg(e.y1,0),x2:Bg(e.x2,0),y2:Bg(e.y2,0),stroke_width:Bg(e.stroke_width,.1)}:e.type==="pcb_note_rect"?{...e,center:{x:Bg(e.center.x,0),y:Bg(e.center.y,0)},width:Bg(e.width,0),height:Bg(e.height,0),stroke_width:Bg(e.stroke_width,.1),corner_radius:Bg(e.corner_radius,0)}:e.type==="pcb_note_text"?{...e,anchor_position:{x:Bg(e.anchor_position.x,0),y:Bg(e.anchor_position.y,0)},font_size:Bg(e.font_size,1)}:e.type==="pcb_note_path"?{...e,route:e.route.map(A=>({...A,x:Bg(A.x,0),y:Bg(A.y,0)})),stroke_width:Bg(e.stroke_width,.1)}:e.type==="pcb_note_dimension"?{...e,from:{x:Bg(e.from.x,0),y:Bg(e.from.y,0)},to:{x:Bg(e.to.x,0),y:Bg(e.to.y,0)},font_size:Bg(e.font_size,1),arrow_size:Bg(e.arrow_size,1),offset_distance:Bg(e.offset_distance,0)}:e,o1e=({ctx:e,bounds:A,elements:t})=>{const i=t.map(n1e),n=new yw(e);n.configure({colorOverrides:{copper:{top:NI,bottom:NI,inner1:NI,inner2:NI,inner3:NI,inner4:NI,inner5:NI,inner6:NI},copperPour:{top:NI,bottom:NI},drill:NI,boardOutline:NI,substrate:NI,keepout:NI,courtyard:{top:NI,bottom:NI},soldermask:{top:NI,bottom:NI},soldermaskWithCopperUnderneath:{top:NI,bottom:NI},soldermaskOverCopper:{top:NI,bottom:NI},silkscreen:{top:NI,bottom:NI},fabricationNote:NI}}),i1e(n,A),n.drawElements(i)},s1e=(e,A)=>!("layer"in e)||e.layer!==A?!1:e.type.startsWith("pcb_note_");function r1e({layer:e,circuitJson:A,boardData:t,traceTextureResolution:i=ww}){const n=A.filter(I=>s1e(I,e));if(n.length===0)return null;const o=wV(A,t),s=Math.floor(o.width*i),r=Math.floor(o.height*i);if(s<=0||r<=0)return null;const a=document.createElement("canvas");a.width=s,a.height=r;const g=a.getContext("2d");if(!g)return null;e==="bottom"&&(g.translate(0,r),g.scale(1,-1)),o1e({ctx:g,bounds:o,elements:n});const c=new sw(a);return c.generateMipmaps=!0,c.minFilter=KC,c.magFilter=jg,c.anisotropy=16,c.needsUpdate=!0,c}var a1e="rgb(255,243,204)",fB="rgba(0,0,0,0)",g1e=(e,A)=>{e.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},c1e=({ctx:e,layer:A,bounds:t,elements:i,silkscreenColor:n})=>{const o=A==="top"?"top_silkscreen":"bottom_silkscreen",s=new yw(e);s.configure({colorOverrides:{copper:{top:fB,bottom:fB,inner1:fB,inner2:fB,inner3:fB,inner4:fB,inner5:fB,inner6:fB},copperPour:{top:fB,bottom:fB},drill:fB,boardOutline:fB,substrate:fB,keepout:fB,courtyard:{top:fB,bottom:fB},soldermask:{top:fB,bottom:fB},soldermaskWithCopperUnderneath:{top:fB,bottom:fB},soldermaskOverCopper:{top:fB,bottom:fB},silkscreen:{top:n,bottom:n},fabricationNote:a1e}}),g1e(s,t),s.drawElements(i,{layers:[o]})},I1e=(e,A)=>!("layer"in e)||e.layer!==A?!1:e.type.startsWith("pcb_silkscreen_");function l1e({layer:e,circuitJson:A,boardData:t,traceTextureResolution:i=ww,silkscreenColor:n="rgb(255,255,255)"}){const o=A.filter(l=>I1e(l,e));if(o.length===0)return null;const s=wV(A,t),r=Math.floor(s.width*i),a=Math.floor(s.height*i);if(r<=0||a<=0)return null;const g=document.createElement("canvas");g.width=r,g.height=a;const c=g.getContext("2d");if(!c)return null;e==="bottom"&&(c.translate(0,a),c.scale(1,-1)),c1e({ctx:c,layer:e,bounds:s,elements:o,silkscreenColor:n});const I=new sw(g);return I.generateMipmaps=!0,I.minFilter=KC,I.magFilter=jg,I.anisotropy=16,I.needsUpdate=!0,I}var DV=e=>{const[A=0,t=0,i=0]=e;return`rgb(${Math.round(A*255)}, ${Math.round(t*255)}, ${Math.round(i*255)})`},B1e=e=>{const A=DV(g2e[e]??_a.fr4SolderMaskGreen),t=DV(e==="fr1"?_a.fr1TracesWithMaskCopper:_a.fr4TracesWithMaskGreen);return{soldermask:A,soldermaskOverCopper:t,copper:DV(_a.copper),transparent:"rgba(0,0,0,0)"}},Oet=(e,A)=>{e.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},C1e=({ctx:e,layer:A,bounds:t,elements:i,boardMaterial:n})=>{const o=B1e(n),s=A==="top"?"top_copper":"bottom_copper",r=new yw(e);r.configure({colorOverrides:{copper:{top:o.transparent,bottom:o.transparent,inner1:o.transparent,inner2:o.transparent,inner3:o.transparent,inner4:o.transparent,inner5:o.transparent,inner6:o.transparent},drill:o.transparent,boardOutline:o.transparent,substrate:o.transparent,keepout:o.transparent,fabricationNote:o.transparent,silkscreen:{top:o.transparent,bottom:o.transparent},courtyard:{top:o.transparent,bottom:o.transparent},soldermask:{top:o.soldermask,bottom:o.soldermask},soldermaskWithCopperUnderneath:{top:o.soldermaskOverCopper,bottom:o.soldermaskOverCopper},soldermaskOverCopper:{top:o.soldermaskOverCopper,bottom:o.soldermaskOverCopper}}}),Oet(r,t),r.drawElements(i,{layers:[s],drawSoldermask:!0,drawSoldermaskTop:A==="top",drawSoldermaskBottom:A==="bottom"});const a=i.filter(g=>g.type==="pcb_copper_pour"&&g.layer===A&&g.covered_with_solder_mask===!1);if(a.length>0){e.save(),e.globalCompositeOperation="destination-out";const g=new yw(e);g.configure({colorOverrides:{copper:{top:o.copper,bottom:o.copper,inner1:o.copper,inner2:o.copper,inner3:o.copper,inner4:o.copper,inner5:o.copper,inner6:o.copper}}}),Oet(g,t),g.drawElements(a,{layers:[s]}),e.restore()}};function Q1e({layer:e,circuitJson:A,boardData:t,traceTextureResolution:i=ww}){const n=wV(A,t),o=Math.floor(n.width*i),s=Math.floor(n.height*i);if(o<=0||s<=0)return null;const r=document.createElement("canvas");r.width=o,r.height=s;const a=r.getContext("2d");if(!a)return null;e==="bottom"&&(a.translate(0,s),a.scale(1,-1));const g=A.some(I=>I.type==="pcb_board")?A:[t,...A];C1e({ctx:a,layer:e,bounds:n,elements:g,boardMaterial:t.material});const c=new sw(r);return c.generateMipmaps=!0,c.minFilter=KC,c.magFilter=jg,c.anisotropy=16,c.needsUpdate=!0,c}var h1e=(e,A)=>{e.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},E1e=({ctx:e,layer:A,bounds:t,elements:i,copperColor:n})=>{const o=A==="top"?"top_copper":"bottom_copper",s="rgba(0,0,0,0)",r=new yw(e);r.configure({colorOverrides:{copper:{top:n,bottom:n,inner1:n,inner2:n,inner3:n,inner4:n,inner5:n,inner6:n},drill:s,boardOutline:s,substrate:s,keepout:s,fabricationNote:s,silkscreen:{top:s,bottom:s},courtyard:{top:s,bottom:s},soldermask:{top:s,bottom:s},soldermaskWithCopperUnderneath:{top:s,bottom:s},soldermaskOverCopper:{top:s,bottom:s}}}),h1e(r,t),r.drawElements(i,{layers:[o]})};function u1e({layer:e,circuitJson:A,boardData:t,copperColor:i="rgb(230, 153, 51)",traceTextureResolution:n=ww}){const o=A.filter(l=>{if(l.type==="pcb_via")return!0;if(l.type!=="pcb_plated_hole")return!1;const B=l;return!Array.isArray(B.layers)||B.layers.includes(e)});if(o.length===0)return null;const s=TD(t),r=Math.floor(s.width*n),a=Math.floor(s.height*n);if(r<=0||a<=0)return null;const g=document.createElement("canvas");g.width=r,g.height=a;const c=g.getContext("2d");if(!c)return null;e==="bottom"&&(c.translate(0,a),c.scale(1,-1)),E1e({ctx:c,layer:e,bounds:s,elements:o,copperColor:i});const I=new sw(g);return I.generateMipmaps=!0,I.minFilter=KC,I.magFilter=jg,I.anisotropy=16,I.needsUpdate=!0,I}var Wet=e=>{const[A=0,t=0,i=0]=e;return`rgb(${Math.round(A*255)}, ${Math.round(t*255)}, ${Math.round(i*255)})`},d1e=({textures:e,boardData:A,traceTextureResolution:t})=>{if(!e.some(c=>c?.image))return null;const n=TD(A),o=Math.floor(n.width*t),s=Math.floor(n.height*t);if(o<=0||s<=0)return null;const r=document.createElement("canvas");r.width=o,r.height=s+1;const a=r.getContext("2d");if(!a)return null;e.forEach(c=>{if(!c?.image)return;const I=c.image;a.drawImage(I,0,0,o,s)});const g=new sw(r);return g.generateMipmaps=!1,g.minFilter=jg,g.magFilter=jg,g.premultiplyAlpha=!0,g.anisotropy=16,g.needsUpdate=!0,g};function Zet({circuitJson:e,boardData:A,traceTextureResolution:t,visibility:i}){const n=Wet(_a.copper),o="rgb(255,255,255)",s=Wet(_a.copper),r=i?.boardBody??!0,a=c=>{const I=(c==="top"?i?.topMask:i?.bottomMask)??!0,l=(c==="top"?i?.topCopper:i?.bottomCopper)??!0,B=(c==="top"?i?.topSilkscreen:i?.bottomSilkscreen)??!0,C=I?Q1e({layer:c,circuitJson:e,boardData:A,traceTextureResolution:t}):null,Q=l?Y2e({layer:c,circuitJson:e,boardData:A,traceColor:n,traceTextureResolution:t}):null,h=l?q2e({layer:c,circuitJson:e,boardData:A,traceTextureResolution:t,copperColor:s}):null,E=l?T2e({layer:c,circuitJson:e,boardData:A,copperColor:s,traceTextureResolution:t}):null,u=l?R2e({layer:c,circuitJson:e,boardData:A,copperColor:s,traceTextureResolution:t}):null,d=l?u1e({layer:c,circuitJson:e,boardData:A,copperColor:s,traceTextureResolution:t}):null,f=B?l1e({layer:c,circuitJson:e,boardData:A,silkscreenColor:o,traceTextureResolution:t}):null,m=B?e1e({layer:c,circuitJson:e,boardData:A,traceTextureResolution:t}):null,D=i?.pcbNotes??!1?r1e({layer:c,circuitJson:e,boardData:A,traceTextureResolution:t}):null,S=r?L2e({layer:c,circuitJson:e,panelData:A,traceTextureResolution:t}):null;return d1e({textures:[h,Q,u,d,C,E,f,m,D,S],boardData:A,traceTextureResolution:t})},g=A.num_layers??2;return{topBoard:a("top"),bottomBoard:g<2?null:a("bottom")}}function Vet(e,A){const{texture:t,yOffset:i,isBottomLayer:n,usePolygonOffset:o=!1,renderOrder:s=0,isFaux:r=!1}=e;if(!t)return null;const a=TD(A),g=new ow(a.width,a.height),c=new Vd({map:t,transparent:!0,alphaTest:.08,side:F0,depthWrite:!0,polygonOffset:o,polygonOffsetFactor:o?-4:0,polygonOffsetUnits:o?-4:0,opacity:r?dV:1}),I=new Io(g,c);return I.position.set(a.centerX,a.centerY,i),n&&I.rotation.set(Math.PI,0,0),I.name=`${n?"bottom":"top"}-board-texture-plane`,I.renderOrder=s,I}function p1e(e,A,t,i=!1){const n=[];if(!e||!A||t===null)return n;const o=.005,s=Vet({texture:e.topBoard,yOffset:t/2+o,isBottomLayer:!1,usePolygonOffset:!0,renderOrder:1,isFaux:i},A);s&&n.push(s);const r=Vet({texture:e.bottomBoard,yOffset:-t/2-o,isBottomLayer:!0,usePolygonOffset:!0,renderOrder:1,isFaux:i},A);return r&&n.push(r),n}var f1e=4e6,y1e=4096,m1e=1;function jet(e,A,t={}){const{maxTexturePixels:i=f1e,maxTextureDimension:n=y1e,minTextureResolution:o=m1e}=t,s=TD(e);if(!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<=0||s.height<=0)return A;const r=Math.max(s.width,s.height),a=n/r,g=Math.sqrt(i/(s.width*s.height)),c=Math.min(A,a,g);return Math.max(o,c)}function w1e({circuitJson:e,pcbThickness:A,isFaux:t=!1}){const{rootObject:i}=nd(),{visibility:n}=OF(),o=AA.useMemo(()=>{const a=e.filter(I=>I.type==="pcb_panel"),g=yn(e).pcb_board.list();if(a.length>0){const I=a[0],l=g.find(B=>B.pcb_panel_id===I.pcb_panel_id);return{type:"pcb_board",pcb_board_id:I.pcb_panel_id,center:I.center,width:I.width,height:I.height,thickness:l?.thickness??1.4,material:l?.material??"fr4",num_layers:l?.num_layers??2}}const c=g.filter(I=>!I.pcb_panel_id);return c.length>0?c[0]:null},[e]),s=AA.useMemo(()=>o?jet(o,ww):ww,[o]),r=AA.useMemo(()=>!o||!o.width||!o.height?null:Zet({circuitJson:e,boardData:o,traceTextureResolution:s,visibility:n}),[e,o,s,n]);return AA.useEffect(()=>{if(!i||!o||!r)return;const a=[],g=C=>{const Q=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],h=C;for(const E of Q){const u=h[E];u&&u instanceof $c&&(u.dispose(),h[E]=null)}C.dispose()},c=(C,Q,h,E,u=!1,d=!0,f=1)=>{if(!C)return null;const m=TD(o),w=new ow(m.width,m.height),D=new Vd({map:C,transparent:!0,alphaTest:.08,side:F0,depthWrite:d,polygonOffset:u,polygonOffsetFactor:u?-4:0,polygonOffsetUnits:u?-4:0,opacity:t?dV:1}),S=new Io(w,D);return S.position.set(m.centerX,m.centerY,Q),h&&S.rotation.set(Math.PI,0,0),S.name=E,S.renderOrder=f,S.frustumCulled=!1,S},I=.005,l=c(r.topBoard,A/2+I,!1,"jscad-top-board-texture",!0);l&&(a.push(l),i.add(l));const B=c(r.bottomBoard,-A/2-I,!0,"jscad-bottom-board-texture",!0);return B&&(a.push(B),i.add(B)),()=>{a.forEach(C=>{C.parent===i&&i.remove(C),C.geometry.dispose(),Array.isArray(C.material)?C.material.forEach(Q=>g(Q)):C.material instanceof Qf&&g(C.material)}),r.topBoard?.dispose(),r.bottomBoard?.dispose()}},[i,o,r,A]),null}function D1e(e){const A=yn(e).cad_component.list(),t=yn(e).pcb_smtpad.list(),i=yn(e).pcb_hole.list(),n=yn(e).pcb_plated_hole.list(),o=yn(e).pcb_via.list();if(A.length===0&&t.length===0&&i.length===0&&n.length===0&&o.length===0)return null;const s=[...i,...n,...o,...t],r=FR(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 zet(e){if(yn(e).pcb_board.list().length>0)return e;const t=D1e(e);if(!t)return e;const n=t.thickness/2;return[...e.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+n}}}}return s}),t]}var S1e=AA.forwardRef(({circuitJson:e,children:A,autoRotateDisabled:t,clickToInteractEnabled:i,onUserInteraction:n,onCameraControllerReady:o,resolveStaticAsset:s},r)=>{const a=Uet(A),g=AA.useMemo(()=>zet(e??a),[e,a]),c=_2e(g),I=AA.useMemo(()=>{if(!g)return[5,-5,5];try{const u=yn(g).pcb_board.list()[0];if(!u)return[5,-5,5];const{width:d,height:f}=u;if(!d&&!f)return[5,-5,5];const m=5,w=Math.max(d,m),D=Math.max(f,m),S=Math.max(w,D);return[S*.4,-S*.7,S*.9]}catch(u){return console.error(u),[5,-5,5]}},[g]),l=AA.useMemo(()=>{if(!g)return!1;try{const u=yn(g).pcb_board.list()[0];return!!u&&u.pcb_board_id==="faux-board"}catch{return!1}},[g]),B=AA.useMemo(()=>{if(g)try{const u=yn(g).pcb_board.list()[0];return u?{width:u.width??0,height:u.height??0}:void 0}catch(u){console.error(u);return}},[g]),C=AA.useMemo(()=>{if(g)try{const u=yn(g).pcb_board.list()[0];return!u||!u.center?void 0:{x:u.center.x,y:u.center.y}}catch(u){console.error(u);return}},[g]),Q=Mtt(g),{stls:h}=s2e(c),E=yn(g).cad_component.list();return Z.jsxs(Let,{ref:r,autoRotateDisabled:t,initialCameraPosition:I,clickToInteractEnabled:i,boardDimensions:B,boardCenter:C,onUserInteraction:n,onCameraControllerReady:o,children:[h.map(({stlData:u,color:d,layerType:f},m)=>Z.jsx(M2e,{stlData:u,color:d,opacity:m===0?l?.8:.95:1,layerType:f},`board-${m}`)),Z.jsx(w1e,{circuitJson:g,pcbThickness:Q,isFaux:l}),E.map(u=>Z.jsx(pdA,{fallback:({error:d})=>Z.jsx(Pet,{cad_component:u,error:d}),children:Z.jsx(Fet,{cad_component:u,circuitJson:g,resolveStaticAsset:s},u.cad_component_id)},u.cad_component_id))]})}),b1e=e=>{let A=0;for(let i=0;i<e.length;i++){const n=(i+1)%e.length;e[i]&&e[n]&&(A+=e[i][0]*e[n][1],A-=e[n][0]*e[i][1])}return A/2<=0};function x1e(e,A,t,i,n){let o,s=null;if(t.outline&&t.outline.length>=3){let r=t.outline.map(g=>[g.x,g.y]);b1e(r)&&(r=r.reverse());const a=A.ofPolygons([r]);n.push(a),s=a,o=e.extrude(a,i,void 0,void 0,void 0,!0),n.push(o)}else t.outline&&t.outline.length>0&&console.warn("Board outline has fewer than 3 points, falling back to rectangular board."),o=e.cube([t.width,t.height,i],!0),n.push(o),o=o.translate([t.center.x,t.center.y,0]),n.push(o);return{boardOp:o,outlineCrossSection:s}}var _1e=64;function zF({Manifold:e,width:A,height:t,thickness:i,borderRadius:n}){const o=Jet(A,t,n);if(o<=0)return e.cube([A,t,i],!0);const s=[],r=A-2*o,a=t-2*o;return r>0&&s.push(e.cube([r,t,i],!0)),a>0&&s.push(e.cube([A,a,i],!0)),[[A/2-o,t/2-o],[-A/2+o,t/2-o],[-A/2+o,-t/2+o],[A/2-o,-t/2+o]].forEach(([c,I])=>{s.push(e.cylinder(i,o,o,_1e,!0).translate([c,I,0]))}),e.union(s)}var k1e=e=>{let A=0;for(let i=0;i<e.length;i++){const n=(i+1)%e.length;e[i]&&e[n]&&(A+=e[i][0]*e[n][1],A-=e[n][0]*e[i][1])}return A/2<=0};function v1e(e,A,t,i,n){const o=[],s=yn(t).pcb_cutout.list();for(const r of s){let a;const g=i*1.5;switch(r.shape){case"rect":{const l=ck(r);if(typeof l=="number"&&l>0?a=zF({Manifold:e,width:r.width,height:r.height,thickness:g,borderRadius:l}):a=e.cube([r.width,r.height,g],!0),n.push(a),r.rotation){const B=a.rotate([0,0,r.rotation]);n.push(B),a=B}a=a.translate([r.center.x,r.center.y,0]),n.push(a);break}case"circle":a=e.cylinder(g,r.radius,-1,XQ,!0),n.push(a),a=a.translate([r.center.x,r.center.y,0]),n.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]);k1e(c)&&(c=c.reverse());const I=A.ofPolygons([c]);n.push(I),a=e.extrude(I,g,0,0,[1,1],!0),n.push(a);break;default:console.warn(`Unsupported cutout shape: ${r.shape} for cutout ${r.pcb_cutout_id}`);continue}a&&o.push(a)}return{cutoutOps:o}}function Xet({Manifold:e,x:A,y:t,diameter:i,thickness:n,segments:o=32}){return e.cylinder(n*1.2,i/2,i/2,o,!0).translate([A,t,0])}function $et({Manifold:e,x:A,y:t,holeDiameter:i,thickness:n,zOffset:o=.001,segments:s=32}){const r=i/2+o;return e.cylinder(n*1.2,r,r,s,!0).translate([A,t,0])}function F1e(e,A,t,i,n){const o=[],s=yn(t).pcb_hole.list(),r=(g,c,I)=>{const l=zF({Manifold:e,width:g,height:c,thickness:I,borderRadius:Math.min(g,c)/2});return n.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=Xet({Manifold:e,x:I,y:l,diameter:g.hole_diameter,thickness:i,segments:XQ}),o.push(E),n.push(E);return}if(c==="pill"||c==="rotated_pill")E=r(Q,h,B);else if(c==="oval"){let u=a(Q,h,XQ),d=0;for(let m=0;m<u.length;m++){const w=(m+1)%u.length;d+=u[m][0]*u[w][1],d-=u[w][0]*u[m][1]}d<=0&&(u=u.reverse());const f=A.ofPolygons([u]);n.push(f),E=e.extrude(f,B,0,0,[1,1],!0),n.push(E)}if(E){if(C!==0){const d=E.rotate([0,0,C]);n.push(d),E=d}const u=E.translate([I,l,0]);n.push(u),o.push(u)}}),{nonPlatedHoleBoardDrills:o}}function PD(e){const A=new kg;if(A.setAttribute("position",new $o(e.vertProperties,3)),A.setIndex(new M$(e.triVerts,1)),e.runIndex&&e.runIndex.length>1&&e.runOriginalID)for(let t=0;t<e.runIndex.length-1;t++){const i=e.runIndex[t],n=e.runIndex[t+1]-i;A.addGroup(i,n,0)}else A.addGroup(0,e.triVerts.length,0);return A}var iJ=e=>{let A=0;for(let i=0;i<e.length;i++){const n=(i+1)%e.length;e[i]&&e[n]&&(A+=e[i][0]*e[n][1],A-=e[n][0]*e[i][1])}return A/2<=0},SV=(e,A,t)=>{const i=[];for(let n=0;n<t;n++){const o=2*Math.PI*n/t;i.push([e/2*Math.cos(o),A/2*Math.sin(o)])}return i},XF=new An(..._a.copper),bV=.05,nJ=.003,oJ=5e-4,sJ=.004;function M1e(e,A,t,i,n,o){const s=[],r=yn(t).pcb_plated_hole.list(),a=[],g=[],c=(C,Q,h)=>{const E=zF({Manifold:e,width:C,height:Q,thickness:h,borderRadius:Math.min(C,Q)/2});return n.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]);iJ(h)&&(h=h.reverse());const E=A.ofPolygons([h]);n.push(E);const u=e.extrude(E,Q,0,0,[1,1],!0);return n.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 w=null;if(d==="circle"){const D=Math.max((C.hole_diameter??0)+h,Tn),S=Math.max(D/2,Tn/2);w=e.cylinder(Q,S,S,XQ,!0),n.push(w)}else{const D=C.hole_width??C.hole_diameter,S=C.hole_height??C.hole_diameter;if(!D||!S)return null;const _=Math.max(D+h,Tn),b=Math.max(S+h,Tn);if(d==="oval"){let R=SV(_,b,XQ);iJ(R)&&(R=R.reverse());const F=A.ofPolygons([R]);n.push(F),w=e.extrude(F,Q,0,0,[1,1],!0),n.push(w)}else(d==="pill"||d==="rotated_pill")&&(w=zF({Manifold:e,width:_,height:b,thickness:Q,borderRadius:Math.min(_,b)/2}),n.push(w))}if(!w)return null;if(f||m){const D=w.translate([f,m,0]);n.push(D),w=D}return w};r.forEach((C,Q)=>{const h=Math.max(i-2*(nJ+oJ+sJ),Tn);if(C.shape==="circle"){const E=$et({Manifold:e,x:C.x,y:C.y,holeDiameter:C.hole_diameter*1.02,thickness:i,zOffset:mw,segments:XQ});n.push(E),s.push(E);const u=h,d=e.cylinder(u,C.outer_diameter/2,C.outer_diameter/2,XQ,!0);n.push(d);const f=e.cylinder(u*1.05,C.hole_diameter/2,C.hole_diameter/2,XQ,!0);n.push(f);const m=d.subtract(f);n.push(m);const w=m.translate([C.x,C.y,0]);n.push(w);let D=w;if(o){const _=e.intersection([w,o]);n.push(_),D=_}g.push(D);const S=PD(D.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:S,color:XF})}else if(C.shape==="pill"){const E=C.hole_width,u=C.hole_height,d=.4,f=C.outer_width??E+d,m=C.outer_height??u+d,w=E+2*mw,D=u+2*mw,S=i*1.2;let _=c(w,D,S);if(C.ccw_rotation){const z=_.rotate([0,0,C.ccw_rotation]);n.push(z),_=z}const b=_.translate([C.x,C.y,0]);n.push(b),s.push(b);const R=h,F=c(f,m,R),H=c(E,u,R*1.05);let Y=F.subtract(H);if(n.push(Y),C.ccw_rotation){const z=Y.rotate([0,0,C.ccw_rotation]);n.push(z),Y=z}const J=Y.translate([C.x,C.y,0]);n.push(J);let O=J;if(o){const z=e.intersection([J,o]);n.push(z),O=z}g.push(O);const W=PD(O.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:W,color:XF})}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 E=C.hole_width,u=C.hole_height,d=C.hole_offset_x||0,f=C.hole_offset_y||0,m=C.rect_pad_width,w=C.rect_pad_height,D=ck(C),S=nJ,_=E+2*mw,b=u+2*mw,R=i*1.2,H=c(_,b,R).translate([d,f,0]).translate([C.x,C.y,0]);n.push(H),s.push(H);const Y=zF({Manifold:e,width:m,height:w,thickness:Math.max(i-2*(S+oJ+sJ),Tn),borderRadius:D});n.push(Y);const J=c(E,u,i*.8).translate([d,f,0]);n.push(J);const O=e.union([Y,J]);n.push(O);const W=c(Math.max(E-2*bV,.01),Math.max(u-2*bV,.01),i*1.2).translate([d,f,0]);n.push(W);const z=O.subtract(W);n.push(z);const tA=z.translate([C.x,C.y,0]);n.push(tA);let aA=tA;if(o){const oA=e.intersection([tA,o]);n.push(oA),aA=oA}g.push(aA);const eA=PD(aA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:eA,color:XF})}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 E=C.hole_width,u=C.hole_height,d=C.hole_offset_x||0,f=C.hole_offset_y||0,m=C.rect_pad_width,w=C.rect_pad_height,D=ck(C),S=nJ,_=E+2*mw,b=u+2*mw,R=i*1.2;let F=c(_,b,R).translate([d,f,0]);if(C.hole_ccw_rotation){const oA=F.rotate([0,0,C.hole_ccw_rotation]);n.push(oA),F=oA}const H=F.translate([C.x,C.y,0]);n.push(H),s.push(H);let Y=zF({Manifold:e,width:m,height:w,thickness:Math.max(i-2*(S+oJ+sJ),Tn),borderRadius:D});if(n.push(Y),C.rect_ccw_rotation){const oA=Y.rotate([0,0,C.rect_ccw_rotation]);n.push(oA),Y=oA}let J=c(E,u,i*.8).translate([d,f,0]);if(C.hole_ccw_rotation){const oA=J.rotate([0,0,C.hole_ccw_rotation]);n.push(oA),J=oA}n.push(J);const O=e.union([Y,J]);n.push(O);let W=c(Math.max(E-2*bV,.01),Math.max(u-2*bV,.01),i*1.2).translate([d,f,0]);if(C.hole_ccw_rotation){const oA=W.rotate([0,0,C.hole_ccw_rotation]);n.push(oA),W=oA}n.push(W);const z=O.subtract(W);n.push(z);const tA=z.translate([C.x,C.y,0]);n.push(tA);let aA=tA;if(o){const oA=e.intersection([tA,o]);n.push(oA),aA=oA}g.push(aA);const eA=PD(aA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:eA,color:XF})}else if(C.shape==="hole_with_polygon_pad"){const E=C.pad_outline;if(!Array.isArray(E)||E.length<3)return;const u=l({ph:C,depth:i*1.2,sizeDelta:2*Tn});if(!u)return;const d=u.translate([C.x,C.y,0]);n.push(d),s.push(d);const m=Math.max(i-2*(nJ+oJ+sJ),Tn),w=I({padOutline:E,thickness:m});if(!w)return;const D=l({ph:C,depth:i*1.02});if(!D)return;const S=l({ph:C,depth:i*.8,sizeDelta:-2*Tn})||D,_=e.union([w,D]);n.push(_);const b=_.subtract(S);n.push(b);const R=b.translate([C.x,C.y,0]);n.push(R);let F=R;if(o){const Y=e.intersection([R,o]);n.push(Y),F=Y}g.push(F);const H=PD(F.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:H,color:XF})}else if(C.shape==="oval"){const E=C.hole_width,u=C.hole_height,d=C.outer_width??E+.4,f=C.outer_height??u+.4,m=E+2*mw,w=u+2*mw,D=i*1.2;let S=SV(m,w,XQ);iJ(S)&&(S=S.reverse());const _=A.ofPolygons([S]);n.push(_);let b=e.extrude(_,D,0,0,[1,1],!0);if(n.push(b),C.ccw_rotation){const rA=b.rotate([0,0,C.ccw_rotation]);n.push(rA),b=rA}const R=b.translate([C.x,C.y,0]);n.push(R),s.push(R);const F=h;let H=SV(d,f,XQ);iJ(H)&&(H=H.reverse());const Y=A.ofPolygons([H]);n.push(Y);const J=e.extrude(Y,F,0,0,[1,1],!0);n.push(J);let O=SV(E,u,XQ);iJ(O)&&(O=O.reverse());const W=A.ofPolygons([O]);n.push(W);const z=e.extrude(W,F*1.05,0,0,[1,1],!0);n.push(z);let tA=J.subtract(z);if(n.push(tA),C.ccw_rotation){const rA=tA.rotate([0,0,C.ccw_rotation]);n.push(rA),tA=rA}const aA=tA.translate([C.x,C.y,0]);n.push(aA);let eA=aA;if(o){const rA=e.intersection([aA,o]);n.push(rA),eA=rA}g.push(eA);const oA=PD(eA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:oA,color:XF})}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 E=C.hole_offset_x||0,u=C.hole_offset_y||0,d=Xet({Manifold:e,x:C.x+E,y:C.y+u,diameter:C.hole_diameter,thickness:i,segments:XQ});n.push(d),s.push(d);const f=C.rect_pad_width??C.hole_diameter,m=C.rect_pad_height??C.hole_diameter,w=ck(C),D=nJ,S=C.hole_diameter/2,_=zF({Manifold:e,width:f,height:m,thickness:Math.max(i-2*(D+oJ+sJ),Tn),borderRadius:w});n.push(_);const b=e.cylinder(i*.8,S,S,XQ,!0).translate([E,u,0]);n.push(b);const R=e.union([_,b]);n.push(R);const F=e.cylinder(i*1.2,Math.max(S-Tn,.01),Math.max(S-Tn,.01),XQ,!0).translate([E,u,0]);n.push(F);const H=R.subtract(F);n.push(H);const Y=H.translate([C.x,C.y,0]);n.push(Y);let J=Y;if(o){const W=e.intersection([Y,o]);n.push(W),J=W}g.push(J);const O=PD(J.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:O,color:XF})}});let B;return g.length>0&&(B=e.union(g),n.push(B)),{platedHoleBoardDrills:s,platedHoleCopperGeoms:a,platedHoleSubtractOp:B}}function G1e({Manifold:e,x:A,y:t,outerDiameter:i,holeDiameter:n,thickness:o,zOffset:s=.001,segments:r=32}){const a=s;if(i<n)throw new Error(`Invalid via geometry: outerDiameter (${i}) must be >= holeDiameter (${n})`);const g=Math.min(i/2,n/2+a),I=e.cylinder(o,g,-1,r,!0),l=o+2*s,B=e.cylinder(l,n/2,-1,r,!0);return I.subtract(B).translate([A,t,0])}var R1e=new An(..._a.copper);function N1e(e,A,t,i,n){const o=[],s=yn(A).pcb_via.list(),r=[];return s.forEach((a,g)=>{if(typeof a.hole_diameter=="number"){const c=$et({Manifold:e,x:a.x,y:a.y,holeDiameter:a.hole_diameter,thickness:t,zOffset:mw,segments:XQ});i.push(c),o.push(c)}if(typeof a.outer_diameter=="number"&&typeof a.hole_diameter=="number"){const c=G1e({Manifold:e,x:a.x,y:a.y,outerDiameter:a.outer_diameter,holeDiameter:a.hole_diameter,thickness:t,zOffset:mw,segments:XQ});i.push(c);let I=c;if(n){const B=e.intersection([c,n]);i.push(B),I=B}const l=PD(I.getMesh());r.push({key:`via-${a.pcb_via_id||g}`,geometry:l,color:R1e})}}),{viaBoardDrills:o,viaCopperGeoms:r}}var L1e=(e,A,t)=>{const[i,n]=AA.useState(null),[o,s]=AA.useState(null),[r,a]=AA.useState(null),[g,c]=AA.useState(!0),I=AA.useRef([]),l=AA.useMemo(()=>{const h=A.filter(d=>d.type==="pcb_panel"),E=yn(A).pcb_board.list();if(h.length>0){const d=h[0],f=E.find(m=>m.pcb_panel_id===d.pcb_panel_id);return{type:"pcb_board",pcb_board_id:d.pcb_panel_id,center:d.center,width:d.width,height:d.height,thickness:f?.thickness??1.4,material:f?.material??"fr4",num_layers:f?.num_layers??2}}const u=E.filter(d=>!d.pcb_panel_id);return u.length>0?u[0]:null},[A]),B=AA.useMemo(()=>{const h=yn(A).pcb_board.list();return h.length>0&&h[0].pcb_board_id==="faux-board"},[A]),C=AA.useMemo(()=>l?jet(l,ww):ww,[l]);AA.useEffect(()=>{if(!e||!l){n(null),s(null),c(!1);return}if((l.width===0||!l.width)&&(l.height===0||!l.height)&&(!l.outline||l.outline.length<3)){n({platedHoles:[],vias:[]}),s(l.thickness??0),c(!1);return}c(!0),a(null);const h=e.Manifold,E=e.CrossSection,u=m=>{if(!(!m||typeof m.delete!="function"))try{m.delete()}catch(w){(!(w instanceof Error)||!w.message?.includes("Manifold instance already deleted"))&&console.warn("Failed to delete Manifold instance",w)}};I.current.forEach(u),I.current=[];let d=null;const f={};try{const m=l.thickness||1.4;s(m);const{boardOp:w,outlineCrossSection:D}=x1e(h,E,l,m,I.current);let S=w;const b=m+2*1;let R=null;const F=.01;if(D){let oA=D;if(F>0){const BA=D.offset(F);I.current.push(BA),oA=BA}const rA=h.extrude(oA,b,void 0,void 0,void 0,!0);I.current.push(rA),R=rA}else{const oA=(l.width||0)+2*F,rA=(l.height||0)+2*F,BA=h.cube([oA,rA,b],!0);I.current.push(BA);const pA=BA.translate([l.center.x,l.center.y,0]);I.current.push(pA),R=pA}const H=[];let Y=null;const{nonPlatedHoleBoardDrills:J}=F1e(h,E,A,m,I.current);H.push(...J);const{platedHoleBoardDrills:O,platedHoleCopperGeoms:W,platedHoleSubtractOp:z}=M1e(h,E,A,m,I.current,R);H.push(...O),f.platedHoles=W;const{viaBoardDrills:tA,viaCopperGeoms:aA}=N1e(h,A,m,I.current,R);if(H.push(...tA),f.vias=aA,H.length>0){Y=h.union(H),I.current.push(Y);const oA=z?h.union([Y,z]):Y;I.current.push(oA);const rA=S.subtract(oA);if(I.current.push(rA),S=rA,z){const BA=z.subtract(Y);I.current.push(BA);const pA=BA.getMesh(),_A=PD(pA);f.platedHoles=[{key:"plated-holes-union",geometry:_A,color:new An(_a.copper[0],_a.copper[1],_a.copper[2])}]}}const{cutoutOps:eA}=v1e(h,E,A,m,I.current);if(eA.length>0){const oA=h.union(eA);I.current.push(oA);const rA=S.subtract(oA);I.current.push(rA),S=rA}if(d=S,d){const oA=d.getMesh(),rA=PD(oA),BA=ydA[l.material]??_a.fr4Tan;f.board={geometry:rA,color:new An(BA[0],BA[1],BA[2]),material:l.material,isFaux:B}}n(f)}catch(m){console.error("Error processing geometry with Manifold in hook:",m),a(m.message||"An unknown error occurred while processing geometry in hook."),n(null)}finally{c(!1)}return()=>{I.current.forEach(u),I.current=[]}},[e,A,l]);const Q=AA.useMemo(()=>!l||!C?null:Zet({circuitJson:A,boardData:l,traceTextureResolution:C,visibility:t}),[A,l,C,t]);return{geoms:i,textures:Q,pcbThickness:o,error:r,isLoading:g,boardData:l,isFauxBoard:B}},U1e=YQ,H1e=({material:e,color:A,side:t=U1e,isFaux:i=!1})=>e==="fr4"?new rw({color:A,side:t,metalness:0,roughness:.8,specularIntensity:.2,ior:1.45,sheen:0,clearcoat:0,transparent:i,opacity:i?dV:1,flatShading:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}):new TE({color:A,side:t,flatShading:!0,metalness:.1,roughness:.8,transparent:!0,opacity:i?dV:.9,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});function Y1e(e){const A=[];if(!e)return A;if(e.board&&e.board.geometry){const i=new Io(e.board.geometry,H1e({material:e.board.material,color:e.board.color,side:YQ,isFaux:e.board.isFaux}));i.name="board-geom",A.push(i)}const t=i=>{i&&i.forEach(n=>{const o=new Io(n.geometry,new TE({color:n.color,side:YQ,flatShading:!0}));o.name=n.key,A.push(o)})};return t(e.platedHoles),t(e.vias),A}var J1e=({geometryMeshes:e,textureMeshes:A})=>{const{rootObject:t}=nd(),{visibility:i}=OF(),n=o=>{o.geometry.dispose();const s=Array.isArray(o.material)?o.material:[o.material];for(const r of s){if(!r)continue;const a=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],g=r;for(const c of a){const I=g[c];I&&I instanceof $c&&(I.dispose(),g[c]=null)}r.dispose()}};return AA.useEffect(()=>{if(t)return e.forEach(o=>{let s=!0;o.name==="board-geom"?s=i.boardBody:(o.name.includes("plated_hole")||o.name.includes("via"))&&(s=i.topCopper||i.bottomCopper),s&&t.add(o)}),()=>{e.forEach(o=>{o.parent===t&&t.remove(o),n(o)})}},[t,e,i]),AA.useEffect(()=>{if(t)return A.forEach(o=>{t.add(o)}),()=>{A.forEach(o=>{o.parent===t&&t.remove(o),n(o)})}},[t,A]),null},T1e="https://cdn.jsdelivr.net/npm/manifold-3d@3.2.1",P1e=({circuitJson:e,autoRotateDisabled:A,clickToInteractEnabled:t,onUserInteraction:i,children:n,onCameraControllerReady:o,resolveStaticAsset:s})=>{const r=Uet(n),a=AA.useMemo(()=>zet(e??r),[e,r]),[g,c]=AA.useState(null),[I,l]=AA.useState(null),{visibility:B}=OF();AA.useEffect(()=>{if(window.ManifoldModule&&typeof window.ManifoldModule=="object"&&window.ManifoldModule.setup){c(window.ManifoldModule);return}const R=async W=>{try{const z=await W();z.setup(),window.ManifoldModule=z,c(z)}catch(z){console.error("Failed to initialize Manifold:",z),l(`Failed to initialize Manifold: ${z instanceof Error?z.message:"Unknown error"}`)}},F=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(F){window.ManifoldModule=F,R(window.ManifoldModule);return}const H="manifoldLoaded",Y=()=>{const W=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(W)window.ManifoldModule=W,R(window.ManifoldModule);else{const z="ManifoldModule not found on window after script load.";console.error(z),l(z)}};window.addEventListener(H,Y,{once:!0});const J=document.createElement("script");J.type="module",J.innerHTML=`
|
|
5186
|
+
`,XNe=({rotation:e,infiniteGrid:A,cellSize:t=1,sectionSize:i=10})=>{const{scene:n,camera:o}=nd(),s=1e3,r=AA.useMemo(()=>{const a=new ow(s,s);a.rotateX(-Math.PI/2);const g=new rD({vertexShader:jNe,fragmentShader:zNe,uniforms:{cellSize:{value:t},sectionSize:{value:i},gridColor:{value:new An(15658734)},sectionColor:{value:new An(13421823)},fadeDistance:{value:100},fadeStrength:{value:1.5}},transparent:!0,side:YQ}),c=new Io(a,g);return e&&c.rotation.fromArray(e),c},[s,t,i,e]);return HY(()=>{A&&r.position.set(o.position.x,o.position.y,0)}),AA.useEffect(()=>{if(!(!n||!r))return n.add(r),()=>{n.remove(r),r.geometry.dispose(),Array.isArray(r.material)?r.material.forEach(a=>a.dispose()):r.material.dispose()}},[n,r]),null},$Ne=()=>{const{scene:e}=nd(),A=AA.useMemo(()=>new HGA(16777215,Math.PI/2),[]),t=AA.useMemo(()=>{const i=new BAA(16777215,Math.PI/4);return i.position.set(-10,-10,10),i.decay=0,i},[]);return AA.useEffect(()=>{if(e)return e.add(A),e.add(t),()=>{e.remove(A),e.remove(t)}},[e,A,t]),null},A2e=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,t2e=()=>{const{controlsRef:e,mainCameraRef:A,defaultTarget:t,setController:i,getPresetConfig:n}=ak(),o=AA.useRef(null),s=AA.useRef(new Zd),r=AA.useRef(new Gt),a=AA.useRef(new Gt),g=AA.useRef(new Zd),c=AA.useRef(new Zd),I=AA.useRef(new _g),l=AA.useRef(new _g),B=AA.useCallback(({position:Q,target:h,up:E,durationMs:u=600})=>{if(!A.current)return;const d=e.current?.target??t,f=new Gt(Q[0],Q[1],Q[2]),m=h?new Gt(h[0],h[1],h[2]):t.clone(),w=new Gt(...E??[0,0,1]).normalize(),D=l.current;D.position.copy(f),D.up.copy(w),D.lookAt(m);const S=D.quaternion.clone(),_=A.current.quaternion.clone(),b=A.current.position.clone(),R=d.clone(),F=I.current;F.up.set(0,0,1),F.position.copy(b),F.lookAt(R);const H=F.quaternion.clone();F.up.set(0,0,1),F.position.copy(f),F.lookAt(m);const Y=F.quaternion.clone(),J=H.clone().invert().multiply(_).normalize(),O=Y.clone().invert().multiply(S).normalize();o.current={fromPosition:b,toPosition:f,fromTarget:R,toTarget:m,toQuaternion:S,rollFrom:J,rollTo:O,startTime:performance.now(),duration:u}},[A,e,t]),C=AA.useCallback(Q=>{if(Q==="Custom")return;const h=n(Q);h&&B(h)},[B,n]);return AA.useEffect(()=>A.current?(i({animateTo:B,animateToPreset:C}),()=>{i(null)}):void 0,[B,C,A,i]),HY(()=>{if(!A.current||!o.current)return;const{fromPosition:Q,toPosition:h,fromTarget:E,toTarget:u,toQuaternion:d,rollFrom:f,rollTo:m,startTime:w,duration:D}=o.current,S=performance.now()-w,_=D<=0?1:Math.min(S/D,1),b=A2e(_);A.current.position.lerpVectors(Q,h,b);const R=r.current;R.copy(E).lerp(u,b);const F=I.current;F.up.set(0,0,1),F.position.copy(A.current.position),F.lookAt(R);const H=s.current;H.copy(F.quaternion);const Y=g.current;Y.copy(f);const J=c.current;J.copy(m),f.dot(m)<0&&(J.x*=-1,J.y*=-1,J.z*=-1,J.w*=-1),J.normalize(),Y.slerp(J,b),A.current.quaternion.copy(H).multiply(Y).normalize();const O=a.current;O.set(0,1,0).applyQuaternion(A.current.quaternion).normalize(),A.current.up.copy(O),e.current?.target.copy(R),A.current.updateMatrixWorld(),e.current?.update(),_>=1&&(A.current.position.copy(h),A.current.quaternion.copy(d),A.current.up.set(0,0,1),A.current.updateMatrixWorld(),e.current?.target.copy(u),e.current?.update(),o.current=null)}),null},e2e=()=>{const{controlsRef:e}=ak(),A=AA.useRef(null),t=AA.useRef(!1),i=AA.useRef(null),n=AA.useCallback(s=>{A.current=s,!t.current&&e.current&&fdA(s,e.current)&&(t.current=!0)},[e]),o=AA.useCallback(()=>{if(!(!A.current||!e.current)){if(!t.current&&fdA(A.current,e.current)){t.current=!0;return}clearTimeout(i.current),i.current=setTimeout(()=>{A.current&&e.current&&Ret(A.current,e.current)},150)}},[e]);return{handleCameraCreated:n,handleControlsChange:o}};function i2e(e,A){const t=new Zd().setFromEuler(new Cf(e.x,e.y,e.z)),i=new Gt(0,0,1);return i.applyQuaternion(t),i.multiplyScalar(A)}var n2e=()=>{const{mainCameraRef:e}=ak(),A=AA.useRef(null),t=AA.useRef(null),i=AA.useRef(null),n=AA.useRef(null),o=AA.useRef(null),s=AA.useRef(null);return AA.useEffect(()=>{if(!A.current)return;const r=document.createElement("canvas");t.current=r,A.current.appendChild(r);const a=new Vq({canvas:r,antialias:!0,alpha:!0});a.setSize(120,120),a.setPixelRatio(window.devicePixelRatio),i.current=a;const g=new Pv;n.current=g;const c=new Yh(75,1,.1,1e3);c.up.set(0,0,1),o.current=c;const I=new HGA(16777215,Math.PI/2);g.add(I);const l=new hf;l.rotation.fromArray([Math.PI/2,0,0]);const B=1,C=new Io(new nw(B,B,B),new TE({color:"white"}));l.add(C);const Q=new BU(new S1t(new nw(B,B,B)),new Kv({color:0,linewidth:2}));l.add(Q),g.add(l);const h=.51,E=(_,b,R)=>{const F=new NtA;return F.text=_,F.position.fromArray(b),R&&F.rotation.fromArray(R),F.color="black",F.fontSize=.25,F.anchorX="center",F.anchorY="middle",F.depthOffset=0,F.font=null,F.sync(),F},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]),w=E("Top",[0,h,0],[-Math.PI/2,0,0]),D=E("Bottom",[0,-h,0],[Math.PI/2,0,0]);l.add(u),l.add(d),l.add(f),l.add(m),l.add(w),l.add(D);const S=()=>{if(e.current){const _=i2e(e.current.rotation??new Cf(0,0,0),2);_.equals(c.position)||(c.position.copy(_),c.lookAt(0,0,0))}a.render(g,c),s.current=requestAnimationFrame(S)};return S(),()=>{s.current&&cancelAnimationFrame(s.current),u.dispose(),d.dispose(),f.dispose(),m.dispose(),w.dispose(),D.dispose(),C.geometry.dispose(),C.material.dispose(),Q.geometry.dispose(),Q.material.dispose(),g.clear(),a.dispose(),a.forceContextLoss(),t.current&&A.current&&A.current.removeChild(t.current)}},[e]),Z.jsx("div",{ref:A,style:{position:"absolute",top:0,left:0,width:120,height:120,zIndex:YY.orientationCube}})},o2e=()=>{const{camera:e}=nd(),{setCameraRotation:A}=ak();return HY(()=>{e&&A(e.rotation)}),null},Let=AA.forwardRef(({children:e,initialCameraPosition:A=[5,-5,5],autoRotateDisabled:t,clickToInteractEnabled:i=!1,boardDimensions:n,boardCenter:o,onUserInteraction:s,onCameraControllerReady:r},a)=>{const[g,c]=AA.useState(!i),{mainCameraRef:I,handleControlsChange:l,controller:B}=ak(),{handleCameraCreated:C,handleControlsChange:Q}=e2e();AA.useEffect(()=>{r&&r(B)},[B,r]);const h=AA.useMemo(()=>{if(!n)return 10;const u=n.width??0,d=n.height??0,m=Math.max(u,d)*1.5;return m>10?m:10},[n]),E=AA.useMemo(()=>{if(o)return[o.x,o.y,0]},[o]);return Z.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[Z.jsx(n2e,{}),Z.jsxs(ZNe,{ref:a,scene:{up:new Gt(0,0,1)},camera:{up:[0,0,1],position:A},onCreated:({camera:u})=>{I.current=u,C(u)},children:[Z.jsx(t2e,{}),Z.jsx(o2e,{}),g&&Z.jsx(VNe,{autoRotate:!t,autoRotateSpeed:1,onStart:s,rotateSpeed:.5,panSpeed:.75,zoomSpeed:.5,enableDamping:!0,dampingFactor:.1,target:E,onControlsChange:u=>{l(u),Q()}}),Z.jsx($Ne,{}),Z.jsx(XNe,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:3,sectionSize:h,args:[h,h]}),e]}),Z.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:["@",Met.version]}),i&&!g&&Z.jsx("button",{type:"button",onClick:()=>c(!0),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&c(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:YY.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center"},children:Z.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"})})]})}),Uet=e=>AA.useMemo(()=>{if(!e)return[];const A=new _ue;return A.add(e),A.render(),A.getCircuitJson()},[e]),s2e=e=>{const[A,t]=AA.useState([]),[i,n]=AA.useState(!0);return AA.useEffect(()=>{if(!e)return;(async()=>{n(!0);const r=(Array.isArray(e)?e:[e]).map(async(a,g)=>{const c=vye.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);t(a)}catch(a){console.error("Error generating STLs:",a),t([])}finally{n(!1)}})()},[e]),{stls:A,loading:i}},r2e=Xa(KF()),a2e=Xa(XZ()),Tn=.01,_a={copper:[.9,.6,.2],fr4Tan:[.6,.43,.28],fr4SolderMaskGreen:[.015,.059,.027],fr4TracesWithMaskGreen:[.063,.141,.023],fr4TracesWithoutMaskTan:[.6,.43,.28],fr1Tan:[.8,.4,.2],fr1TracesWithMaskCopper:[.9,.6,.2],fr1SolderMaskGreen:[.02,.1,.04]},mw=.001,XQ=32,ww=150,dV=.6,ydA={fr1:_a.fr1Tan,fr4:_a.fr4Tan},g2e={fr1:_a.fr1SolderMaskGreen,fr4:_a.fr4SolderMaskGreen},c2e=Xa(UY()),I2e=Xa(KF()),l2e=Xa(qF()),B2e=Xa(btt()),Het=e=>{let A=0;for(let i=0;i<e.length;i++){const n=(i+1)%e.length;A+=e[i][0]*e[n][1],A-=e[n][0]*e[i][1]}return A/2<=0},mdA=(e,A=1.2,t={})=>{const{xyOutset:i=0}=t,{outline:n}=e;let o=n.map(a=>[a.x,a.y]);Het(o)&&(o=o.reverse());let s=(0,I2e.polygon)({points:o});i!==0&&(s=(0,B2e.expand)({delta:i,corners:"edge"},s));let r=(0,c2e.extrudeLinear)({height:A},s);return r=(0,l2e.translate)([0,0,-A/2],r),r},C2e=e=>{const A=e.filter(a=>a.type==="pcb_panel"),t=yn(e).pcb_board.list();let i,n=1.2;if(A.length>0)i=A[0],n=t.find(g=>g.pcb_panel_id===i.pcb_panel_id)?.thickness??1.2;else{if(i=t.filter(g=>!g.pcb_panel_id)[0],!i)return console.warn("No pcb_board or pcb_panel found for simplified geometry"),[];n=i.thickness??1.2}let o;"outline"in i&&i.outline&&i.outline.length>0?o=mdA({outline:i.outline},n):o=(0,r2e.cuboid)({size:[i.width??10,i.height??10,n],center:[i.center.x,i.center.y,0]});const s="material"in i&&i.material?i.material:A.length>0?t.find(a=>a.pcb_panel_id===i.pcb_panel_id)?.material??"fr4":"fr4",r=ydA[s]??_a.fr4Tan;return[(0,a2e.colorize)(r,o)]},tJ=Xa(XZ()),Zh=Xa(LY()),wdA=Xa(UY()),kf=Xa(qF()),iI=Xa(KF()),gk=Xa(KF()),Q2e=Xa(UY()),pV=Xa(qF()),h2e=Xa(LY()),E2e=64,u2e=(e,A,t)=>{const i=(0,gk.ellipse)({center:[0,0],radius:[Math.max(e/2,Tn/2),Math.max(A/2,Tn/2)],segments:E2e}),n=(0,Q2e.extrudeLinear)({height:t},i);return(0,pV.translate)([0,0,-t/2],n)},d2e=(e,A,t)=>{const i=Math.max(e,Tn),n=Math.max(A,Tn);if(Math.abs(i-n)<1e-6)return(0,gk.cylinder)({center:[0,0,0],radius:i/2,height:t});const o=i>=n,s=o?i:n,r=o?n:i,a=Math.max(s-r,0),g=(0,gk.cuboid)({center:[0,0,0],size:o?[a,r,t]:[r,a,t]});if(a<=1e-6)return(0,gk.cylinder)({center:[0,0,0],radius:r/2,height:t});const c=a/2,I=(0,gk.cylinder)({center:o?[-c,0,0]:[0,-c,0],radius:r/2,height:t}),l=(0,gk.cylinder)({center:o?[c,0,0]:[0,c,0],radius:r/2,height:t});return(0,h2e.union)(g,I,l)},fV=(e,A,t={})=>{const i=e.hole_shape||"circle",n=t.sizeDelta??0,o=e.hole_offset_x||0,s=e.hole_offset_y||0,r=[e.x+o,e.y+s,0];if(i==="circle"){const B=Math.max((e.hole_diameter??0)+n,Tn),C=Math.max(B/2,Tn/2);return(0,gk.cylinder)({center:r,radius:C,height:A})}const a=e.hole_width??e.hole_diameter,g=e.hole_height??e.hole_diameter;if(!a||!g)return null;const c=Math.max(a+n,Tn),I=Math.max(g+n,Tn);if(i==="oval"){const B=u2e(c,I,A);return(0,pV.translate)([r[0],r[1],0],B)}if(i==="pill"||i==="rotated_pill"){let B=d2e(c,I,A);if(!B)return null;const C=e.ccw_rotation||0;return C&&(B=(0,pV.rotateZ)(C*Math.PI/180,B)),(0,pV.translate)(r,B)}const l=Math.max((e.hole_diameter??a??g??Tn)+n,Tn);return(0,gk.cylinder)({center:r,radius:l/2,height:A})},zr=Xa(KF()),JD=Xa(XZ()),nI=Xa(LY()),Yet=Xa(qF()),yV=Xa(UY()),vf=Xa(qF()),p2e=1e-5;function Jet(e,A,t){if(typeof t!="number"||!Number.isFinite(t)||t<=0)return 0;const i=e/2,n=A/2,o=Math.min(i,n)-2*p2e;return Math.max(0,Math.min(t,o))}function ck(e){if(!(!e||typeof e!="object"))return e.corner_radius??e.cornerRadius??e.rect_pad_border_radius??e.rectPadBorderRadius??e.rect_border_radius??e.rectBorderRadius??void 0}var f2e=.05,DdA=64,jF=(e,A)=>A?(0,nI.intersect)(A,e):e,eJ=(e,A,t={})=>{const{clipGeom:i}=t;e.shape||(e.shape="circle");const n=Math.max(A.pcbThickness*.002,Tn/5),o=Math.max(A.pcbThickness*3e-4,Tn/20),s=Math.max(A.pcbThickness*.0025,Tn/4),r=A.pcbThickness+2*f2e+4*Tn,a=Math.max(A.pcbThickness-2*(n+o+s),Tn),g=Math.max(a,Tn);if(e.shape==="circle"){const c=e.outer_diameter??Math.max(e.hole_diameter,0),I=a,l=(0,zr.cylinder)({center:[e.x,e.y,0],radius:c/2,height:I}),B=jF(l,i),C=(0,zr.cylinder)({center:[e.x,e.y,0],radius:Math.max(e.hole_diameter/2,.01),height:r});return(0,JD.colorize)(_a.copper,(0,nI.subtract)(B,C))}if(e.shape==="oval"){const c=e.outer_width||e.hole_width||0,I=e.outer_height||e.hole_height||0,l=e.hole_width||0,B=e.hole_height||0,C=(()=>{const E=(0,zr.cylinder)({center:[0,0,0],radius:1,height:a,segments:64}),u=(0,Yet.scale)([c/2,I/2,1],E);return(0,vf.translate)([e.x,e.y,0],u)})(),Q=jF(C,i),h=(()=>{const E=(0,zr.cylinder)({center:[0,0,0],radius:1,height:r,segments:64}),u=(0,Yet.scale)([Math.max(l/2,.01),Math.max(B/2,.01),1],E);return(0,vf.translate)([e.x,e.y,0],u)})();return(0,JD.colorize)(_a.copper,(0,nI.subtract)(Q,h))}if(e.shape==="circular_hole_with_rect_pad"){const c=e.hole_offset_x||0,I=e.hole_offset_y||0,l=e.rect_pad_width||e.hole_diameter,B=e.rect_pad_height||e.hole_diameter,C=ck(e),Q=jF((0,nI.union)((()=>{const u=(0,zr.roundedRectangle)({size:[l,B],roundRadius:C||0,segments:DdA}),d=(0,yV.extrudeLinear)({height:a},u);return(0,vf.translate)([e.x,e.y,-a/2],d)})(),(0,zr.cylinder)({center:[e.x+(c||0),e.y+(I||0),0],radius:e.hole_diameter/2,height:g})),i),h=(0,zr.cylinder)({center:[e.x+(c||0),e.y+(I||0),0],radius:Math.max(e.hole_diameter/2-Tn,.01),height:r}),E=(0,nI.subtract)(Q,h);return t.clipGeom?(0,JD.colorize)(_a.copper,(0,nI.intersect)(E,t.clipGeom)):(0,JD.colorize)(_a.copper,E)}if(e.shape==="pill"){const c=(e.ccw_rotation||0)*Math.PI/180,I=F=>{if(!c)return F;const H=(0,vf.translate)([-e.x,-e.y,0],F),Y=(0,vf.rotate)([0,0,c],H);return(0,vf.translate)([e.x,e.y,0],Y)},l=e.hole_height>e.hole_width,B=l?e.hole_height:e.hole_width,C=l?e.hole_width:e.hole_height,Q=l?e.outer_height||C+.2:e.outer_width||B+.2,h=l?e.outer_width||B+.2:e.outer_height||C+.2,E=C/2,u=Math.abs(B-C),m=((F,H,Y)=>{const J=H/2,O=Math.abs(F-H);if(O<=1e-6)return(0,zr.cylinder)({center:[e.x,e.y,0],radius:J,height:Y});const W=(0,zr.cuboid)({center:[e.x,e.y,0],size:l?[H,O,Y]:[O,H,Y]}),z=(0,zr.cylinder)({center:l?[e.x,e.y-O/2,0]:[e.x-O/2,e.y,0],radius:J,height:Y}),tA=(0,zr.cylinder)({center:l?[e.x,e.y+O/2,0]:[e.x+O/2,e.y,0],radius:J,height:Y});return(0,nI.union)(W,z,tA)})(Q,h,a),w=(0,zr.cuboid)({center:[e.x,e.y,0],size:l?[C-2*Tn,u,r]:[u,C-2*Tn,r]}),D=(0,zr.cylinder)({center:l?[e.x,e.y-u/2,0]:[e.x-u/2,e.y,0],radius:E-Tn,height:r}),S=(0,zr.cylinder)({center:l?[e.x,e.y+u/2,0]:[e.x+u/2,e.y,0],radius:E-Tn,height:r}),_=(0,nI.union)(w,D,S),b=jF(I(m),i),R=I(_);return(0,JD.colorize)(_a.copper,(0,nI.subtract)(b,R))}if(e.shape==="pill_hole_with_rect_pad"){if(e.hole_shape&&e.hole_shape!=="pill"||e.pad_shape&&e.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for pill_hole_with_rect_pad");const c=e.hole_offset_x||0,I=e.hole_offset_y||0,l=e.hole_height>e.hole_width,B=l?e.hole_height:e.hole_width,C=l?e.hole_width:e.hole_height,Q=C/2,h=Math.abs(B-C),E=e.rect_pad_width||B+.2,u=e.rect_pad_height||C+.2,d=ck(e),f=.03,m=(0,nI.union)((0,zr.cuboid)({center:[e.x+c,e.y+I,0],size:l?[C+2*f,h+2*f,g]:[h+2*f,C+2*f,g]}),(0,zr.cylinder)({center:l?[e.x+c,e.y+I-h/2,0]:[e.x+c-h/2,e.y+I,0],radius:Q+f,height:g}),(0,zr.cylinder)({center:l?[e.x+c,e.y+I+h/2,0]:[e.x+c+h/2,e.y+I,0],radius:Q+f,height:g})),w=(0,nI.union)((0,zr.cuboid)({center:[e.x+c,e.y+I,0],size:l?[C,h,r]:[h,C,r]}),(0,zr.cylinder)({center:l?[e.x+c,e.y+I-h/2,0]:[e.x+c-h/2,e.y+I,0],radius:Q,height:r}),(0,zr.cylinder)({center:l?[e.x+c,e.y+I+h/2,0]:[e.x+c+h/2,e.y+I,0],radius:Q,height:r})),D=(()=>{const F=(0,zr.roundedRectangle)({size:[E,u],roundRadius:d||0,segments:DdA}),H=(0,yV.extrudeLinear)({height:a},F);return(0,vf.translate)([e.x,e.y,-a/2],H)})(),S=(0,nI.subtract)(D,w),_=(0,nI.union)((0,zr.cuboid)({center:[e.x+c,e.y+I,0],size:l?[C-2*Tn,h-2*Tn,r]:[h-2*Tn,C-2*Tn,r]}),(0,zr.cylinder)({center:l?[e.x+c,e.y+I-h/2,0]:[e.x+c-h/2,e.y+I,0],radius:Q-Tn,height:r}),(0,zr.cylinder)({center:l?[e.x+c,e.y+I+h/2,0]:[e.x+c+h/2,e.y+I,0],radius:Q-Tn,height:r})),b=(0,nI.subtract)(m,_),R=jF((0,nI.union)(S,b),i);return(0,JD.colorize)(_a.copper,R)}else if(e.shape==="rotated_pill_hole_with_rect_pad"){if(e.hole_shape&&e.hole_shape!=="rotated_pill"||e.pad_shape&&e.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for rotated_pill_hole_with_rect_pad");const c=e.hole_offset_x||0,I=e.hole_offset_y||0,l=e.hole_width,B=e.hole_height,C=l>=B,Q=C?l:B,h=C?B:l,E=h/2,u=Math.abs(Q-h),d=e.rect_pad_width||l+.2,f=e.rect_pad_height||B+.2,m=ck(e),w=.03,D=(e.hole_ccw_rotation||0)*Math.PI/180,S=(e.rect_ccw_rotation||0)*Math.PI/180,_=z=>{const tA=c*Math.cos(D)-I*Math.sin(D),aA=c*Math.sin(D)+I*Math.cos(D),eA=(0,vf.rotate)([0,0,D],z);return(0,vf.translate)([e.x+tA,e.y+aA,0],eA)},b=z=>{if(!S)return z;const tA=(0,vf.translate)([-e.x,-e.y,0],z),aA=(0,vf.rotate)([0,0,S],tA);return(0,vf.translate)([e.x,e.y,0],aA)},R=_((0,nI.union)((0,zr.cuboid)({center:[0,0,0],size:C?[u+2*w,h+2*w,g]:[h+2*w,u+2*w,g]}),(0,zr.cylinder)({center:C?[-u/2,0,0]:[0,-u/2,0],radius:E+w,height:g}),(0,zr.cylinder)({center:C?[u/2,0,0]:[0,u/2,0],radius:E+w,height:g}))),F=_((0,nI.union)((0,zr.cuboid)({center:[0,0,0],size:C?[u,h,r]:[h,u,r]}),(0,zr.cylinder)({center:C?[-u/2,0,0]:[0,-u/2,0],radius:E,height:r}),(0,zr.cylinder)({center:C?[u/2,0,0]:[0,u/2,0],radius:E,height:r}))),H=b((()=>{const z=(0,zr.roundedRectangle)({size:[d,f],roundRadius:m||0,segments:DdA}),tA=(0,yV.extrudeLinear)({height:a},z);return(0,vf.translate)([e.x,e.y,-a/2],tA)})()),Y=(0,nI.subtract)(H,F),J=_((0,nI.union)((0,zr.cuboid)({center:[0,0,0],size:C?[u-2*Tn,h-2*Tn,r]:[h-2*Tn,u-2*Tn,r]}),(0,zr.cylinder)({center:C?[-u/2,0,0]:[0,-u/2,0],radius:E-Tn,height:r}),(0,zr.cylinder)({center:C?[u/2,0,0]:[0,u/2,0],radius:E-Tn,height:r}))),O=(0,nI.subtract)(R,J),W=jF((0,nI.union)(Y,O),i);return(0,JD.colorize)(_a.copper,W)}else if(e.shape==="hole_with_polygon_pad"){const c=e.pad_outline;if(!Array.isArray(c)||c.length<3)throw new Error(`Invalid pad_outline for plated hole at (${e.x}, ${e.y})`);const I=c.map(f=>[f.x,f.y]),l=(0,zr.polygon)({points:I}),Q=((f,m)=>{const w=Math.max(f,Tn),D=(0,yV.extrudeLinear)({height:w},l);return(0,vf.translate)([e.x,e.y,m-w/2],D)})(a,0),h=jF(Q,i),E=fV(e,g);if(!E)return(0,JD.colorize)(_a.copper,h);const u=fV(e,r,{sizeDelta:-2*Tn})||E;let d=(0,nI.union)((0,nI.subtract)(h,E),E);return t.clipGeom?(d=(0,nI.subtract)(d,u),d=(0,nI.intersect)(d,t.clipGeom),(0,JD.colorize)(_a.copper,d)):(0,JD.colorize)(_a.copper,(0,nI.subtract)(d,u))}else throw new Error(`Unsupported plated hole shape: ${e.shape}`)},y2e=Xa(LY()),m2e=Xa(qF()),SdA=Xa(KF());function w2e({x:e,y:A,outerDiameter:t,holeDiameter:i,thickness:n}){if(t<=i)throw new Error(`Invalid via geometry: outerDiameter (${t}) must be > holeDiameter (${i})`);const o=Tn,s=Math.min(t/2,i/2+o),a=(0,SdA.cylinder)({center:[0,0,0],radius:s,height:n,segments:XQ}),g=n+2*Tn,c=(0,SdA.cylinder)({center:[0,0,0],radius:i/2,height:g,segments:XQ}),I=(0,y2e.subtract)(a,c);return(0,m2e.translate)([e,A,0],I)}function D2e({x:e,y:A,holeDiameter:t,thickness:i}){const n=i*1.5,o=t/2+Tn;return(0,SdA.cylinder)({center:[e,A,0],radius:o,height:n,segments:XQ})}var S2e=64,b2e=1,bdA=.05,Tet=["initializing","processing_copper_pours","processing_plated_holes","processing_holes","processing_cutouts","processing_vias","finalizing","done"],x2e=class{circuitJson;board;plated_holes;holes;traces;pcb_vias;pcb_cutouts;boardGeom=null;platedHoleGeoms=[];viaGeoms=[];copperPourGeoms=[];boardClipGeom=null;state="initializing";currentIndex=0;ctx;onCompleteCallback;finalGeoms=[];getHoleToCut(e,A){const t=Tn/10;for(const i of this.pcb_vias)if(Math.abs(i.x-e)<t&&Math.abs(i.y-A)<t&&i.hole_diameter)return{diameter:i.hole_diameter};for(const i of this.plated_holes)if(i.shape==="circle"&&Math.abs(i.x-e)<t&&Math.abs(i.y-A)<t&&i.hole_diameter)return{diameter:i.hole_diameter};return null}constructor(e,A){this.circuitJson=e,this.onCompleteCallback=A;const t=e.filter(n=>n.type==="pcb_panel"),i=yn(e).pcb_board.list();if(t.length>0){const n=t[0],o=i.find(s=>s.pcb_panel_id===n.pcb_panel_id);this.board={type:"pcb_board",pcb_board_id:n.pcb_panel_id,center:n.center,width:n.width,height:n.height,thickness:o?.thickness??1.4,material:o?.material??"fr4",num_layers:o?.num_layers??2}}else{const n=i.filter(o=>!o.pcb_panel_id);this.board=n[0]}this.plated_holes=yn(e).pcb_plated_hole.list(),this.holes=yn(e).pcb_hole.list(),this.traces=yn(e).pcb_trace.list(),this.pcb_vias=yn(e).pcb_via.list(),this.pcb_cutouts=yn(e).pcb_cutout.list(),this.ctx={pcbThickness:this.board.thickness??1.2},this.initializeBoard()}initializeBoard(){const e=this.ctx.pcbThickness+2*b2e;this.board.outline&&this.board.outline.length>0?(this.boardGeom=mdA({outline:this.board.outline},this.ctx.pcbThickness),this.boardClipGeom=mdA({outline:this.board.outline},e,{xyOutset:bdA})):(this.boardGeom=(0,iI.cuboid)({size:[this.board.width,this.board.height,this.ctx.pcbThickness],center:[this.board.center.x,this.board.center.y,0]}),this.boardClipGeom=(0,iI.cuboid)({size:[this.board.width+2*bdA,this.board.height+2*bdA,e],center:[this.board.center.x,this.board.center.y,0]})),this.state="processing_copper_pours",this.currentIndex=0}goToNextState(){const e=Tet.indexOf(this.state);e!==-1&&(this.state=Tet[e+1],this.currentIndex=0)}step(e=1){if(this.state==="done"||!this.boardGeom)return!0;for(let A=0;A<e&&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_copper_pours":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(e){if(!this.boardGeom)return;let A=null;const t=this.ctx.pcbThickness*1.5;switch(e.shape){case"rect":{const i=Jet(e.width,e.height,ck(e));if(i>0){const n=(0,iI.roundedRectangle)({size:[e.width,e.height],roundRadius:i,segments:S2e});A=(0,wdA.extrudeLinear)({height:t},n),A=(0,kf.translate)([0,0,-t/2],A)}else A=(0,iI.cuboid)({center:[0,0,0],size:[e.width,e.height,t]});if(e.rotation){const n=e.rotation*Math.PI/180;A=(0,kf.rotateZ)(n,A)}A=(0,kf.translate)([e.center.x,e.center.y,0],A);break}case"circle":A=(0,iI.cylinder)({center:[e.center.x,e.center.y,0],radius:e.radius,height:t});break;case"polygon":{let i=e.points.map(o=>[o.x,o.y]);if(i.length<3){console.warn(`PCB Cutout [${e.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);break}Het(i)&&(i=i.reverse());const n=(0,iI.polygon)({points:i});A=(0,wdA.extrudeLinear)({height:t},n),A=(0,kf.translate)([0,0,-t/2],A);break}}A&&(this.boardGeom=(0,Zh.subtract)(this.boardGeom,A))}processPlatedHole(e,A={}){if(this.boardGeom){if(e.shape==="circle"||e.shape==="circular_hole_with_rect_pad"){let t=null;if(e.shape==="circular_hole_with_rect_pad"){if(e.hole_shape&&e.hole_shape!=="circle"||e.pad_shape&&e.pad_shape!=="rect")return;t=(0,iI.cylinder)({center:[e.x+(e.hole_offset_x||0),e.y+(e.hole_offset_y||0),0],radius:e.hole_diameter/2+Tn,height:this.ctx.pcbThickness*1.5})}else t=(0,iI.cylinder)({center:[e.x,e.y,0],radius:e.hole_diameter/2+Tn,height:this.ctx.pcbThickness*1.5});A.dontCutBoard||(this.boardGeom=(0,Zh.subtract)(this.boardGeom,t));const i=eJ(e,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(i)}else if(e.shape==="pill"||e.shape==="oval"){const t=e.hole_height>e.hole_width,i=t?e.hole_height:e.hole_width,n=t?e.hole_width:e.hole_height,o=n/2,s=Math.abs(i-n);let r;if(r=(0,Zh.union)((0,iI.cuboid)({center:[e.x,e.y,0],size:t?[n,s,this.ctx.pcbThickness*1.5]:[s,n,this.ctx.pcbThickness*1.5]}),(0,iI.cylinder)({center:t?[e.x,e.y-s/2,0]:[e.x-s/2,e.y,0],radius:o,height:this.ctx.pcbThickness*1.5}),(0,iI.cylinder)({center:t?[e.x,e.y+s/2,0]:[e.x+s/2,e.y,0],radius:o,height:this.ctx.pcbThickness*1.5})),e.ccw_rotation){const g=e.ccw_rotation*Math.PI/180;r=(0,kf.translate)([e.x,e.y,0],(0,kf.rotateZ)(g,(0,kf.translate)([-e.x,-e.y,0],r)))}A.dontCutBoard||(this.boardGeom=(0,Zh.subtract)(this.boardGeom,r));const a=eJ(e,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(e.shape==="pill_hole_with_rect_pad"){if(e.hole_shape&&e.hole_shape!=="pill"||e.pad_shape&&e.pad_shape!=="rect")return;const t=e.hole_height>e.hole_width,i=t?e.hole_height:e.hole_width,n=t?e.hole_width:e.hole_height,o=n/2,s=Math.abs(i-n);let r;r=(0,Zh.union)((0,iI.cuboid)({center:[e.x+(e.hole_offset_x||0),e.y+(e.hole_offset_y||0),0],size:t?[n,s,this.ctx.pcbThickness*1.5]:[s,n,this.ctx.pcbThickness*1.5]}),(0,iI.cylinder)({center:t?[e.x+(e.hole_offset_x||0),e.y+(e.hole_offset_y||0)-s/2,0]:[e.x+(e.hole_offset_x||0)-s/2,e.y+(e.hole_offset_y||0),0],radius:o,height:this.ctx.pcbThickness*1.5}),(0,iI.cylinder)({center:t?[e.x+(e.hole_offset_x||0),e.y+(e.hole_offset_y||0)+s/2,0]:[e.x+(e.hole_offset_x||0)+s/2,e.y+(e.hole_offset_y||0),0],radius:o,height:this.ctx.pcbThickness*1.5})),A.dontCutBoard||(this.boardGeom=(0,Zh.subtract)(this.boardGeom,r));const a=eJ(e,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(e.shape==="rotated_pill_hole_with_rect_pad"){if(e.hole_shape&&e.hole_shape!=="rotated_pill"||e.pad_shape&&e.pad_shape!=="rect")return;const t=e.hole_width,i=e.hole_height,n=t>=i,o=n?t:i,s=n?i:t,r=s/2,a=Math.abs(o-s),g=e.hole_offset_x||0,c=e.hole_offset_y||0;let I=(0,Zh.union)((0,iI.cuboid)({center:[0,0,0],size:n?[a,s,this.ctx.pcbThickness*1.5]:[s,a,this.ctx.pcbThickness*1.5]}),(0,iI.cylinder)({center:n?[-a/2,0,0]:[0,-a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}),(0,iI.cylinder)({center:n?[a/2,0,0]:[0,a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}));const l=(e.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,kf.rotateZ)(l,I);const Q=(0,kf.translate)([e.x+B,e.y+C,0],I);A.dontCutBoard||(this.boardGeom=(0,Zh.subtract)(this.boardGeom,Q));const h=eJ(e,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(h)}else if(e.shape==="hole_with_polygon_pad"){const t=e.pad_outline;if(!Array.isArray(t)||t.length<3)return;const i=this.ctx.pcbThickness*1.5,n=fV(e,i,{sizeDelta:2*Tn}),o=fV(e,i,{sizeDelta:-2*Tn});if(!n||!o)return;A.dontCutBoard||(this.boardGeom=(0,Zh.subtract)(this.boardGeom,n)),this.platedHoleGeoms=this.platedHoleGeoms.map(r=>(0,tJ.colorize)(_a.copper,(0,Zh.subtract)(r,o)));const s=eJ(e,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(s)}}}processHole(e){if(!this.boardGeom)return;const A=this.ctx.pcbThickness*1.5;if(e.hole_shape==="circle"){const t=(0,iI.cylinder)({center:[e.x,e.y,0],radius:e.hole_diameter/2+Tn,height:A});this.boardGeom=(0,Zh.subtract)(this.boardGeom,t);const i=(0,iI.cylinder)({center:[e.x,e.y,0],radius:e.hole_diameter/2+Tn/2,height:A});this.platedHoleGeoms=this.platedHoleGeoms.map(n=>(0,tJ.colorize)(_a.copper,(0,Zh.subtract)(n,i)))}else if(e.hole_shape==="pill"||e.hole_shape==="rotated_pill"||e.hole_shape==="oval"){const t=e.hole_width??e.hole_diameter,i=e.hole_height??e.hole_diameter,n=e.ccw_rotation??e.rotation??0,o=.02,s=(g,c,I,l)=>{if(g<=0||c<=0)return null;if(l)return(0,kf.translate)([0,0,-I/2],(0,wdA.extrudeLinear)({height:I},(0,iI.ellipse)({radius:[g/2,c/2]})));const B=Math.min(g,c)/2,C=Math.abs(g-c);return g>c?(0,Zh.union)((0,iI.cuboid)({center:[0,0,0],size:[C,c,I]}),(0,iI.cylinder)({center:[-C/2,0,0],radius:B,height:I}),(0,iI.cylinder)({center:[C/2,0,0],radius:B,height:I})):(0,Zh.union)((0,iI.cuboid)({center:[0,0,0],size:[g,C,I]}),(0,iI.cylinder)({center:[0,-C/2,0],radius:B,height:I}),(0,iI.cylinder)({center:[0,C/2,0],radius:B,height:I}))};let r=s(t,i,A,e.hole_shape==="oval"),a=s(t-2*o,i-2*o,A,e.hole_shape==="oval");if(r&&n!==0&&(r=(0,kf.rotateZ)(n*Math.PI/180,r)),a&&n!==0&&(a=(0,kf.rotateZ)(n*Math.PI/180,a)),r){const g=(0,kf.translate)([e.x,e.y,0],r);this.boardGeom=(0,Zh.subtract)(this.boardGeom,g)}if(a){const g=(0,kf.translate)([e.x,e.y,0],a);this.platedHoleGeoms=this.platedHoleGeoms.map(c=>(0,tJ.colorize)(_a.copper,(0,Zh.subtract)(c,g)))}}}processVia(e){if(this.boardGeom){if(typeof e.outer_diameter=="number"&&typeof e.hole_diameter=="number"){const A=w2e({x:e.x,y:e.y,outerDiameter:e.outer_diameter,holeDiameter:e.hole_diameter,thickness:this.ctx.pcbThickness});let t=A;this.boardClipGeom&&(t=(0,Zh.intersect)(this.boardClipGeom,A),t=(0,tJ.colorize)(_a.copper,t)),this.viaGeoms.push(t)}if(typeof e.hole_diameter=="number"){const A=D2e({x:e.x,y:e.y,holeDiameter:e.hole_diameter,thickness:this.ctx.pcbThickness});this.boardGeom=(0,Zh.subtract)(this.boardGeom,A)}}}finalize(){if(!this.boardGeom)return;const e=ydA[this.board.material]??_a.fr4Tan;this.boardGeom=(0,tJ.colorize)(e,this.boardGeom),this.finalGeoms=[this.boardGeom,...this.platedHoleGeoms,...this.viaGeoms,...this.copperPourGeoms],this.onCompleteCallback&&this.onCompleteCallback(this.finalGeoms)}getGeoms(){return this.finalGeoms}},_2e=e=>{const[A,t]=AA.useState(null),i=AA.useRef(!1);return AA.useEffect(()=>{let n=!1;if(!e){t(null);return}if(!e.some(g=>g.type==="pcb_board"||g.type==="pcb_panel")){t(null);return}const s=C2e(e);t(s);const r=new x2e(e,g=>{});return(async()=>{if(!i.current){i.current=!0;try{let g=!1;for(;!g&&!n;)g=r.step(1),g||await new Promise(c=>setTimeout(c,0));n||t(r.getGeoms())}catch(g){console.error("Error during board geometry building:",g)}finally{i.current=!1}}})(),()=>{n=!0}},[e]),A},k2e=({children:e,parent:A,position:t,rotation:i,scale:n,color:o,fontSize:s,anchorX:r,anchorY:a,depthOffset:g})=>{const{rootObject:c}=nd(),I=AA.useMemo(()=>{const l=new NtA;return l.text=e,t&&l.position.fromArray(t),i&&l.rotation.fromArray(i),n&&l.scale.fromArray(n),l.color=o||"white",l.fontSize=s||1,l.anchorX=r||"center",l.anchorY=a||"middle",l.depthOffset=g||0,l.font=null,l.sync(),l},[e,t,i,n,o,s,r,a,g]);return AA.useEffect(()=>{const l=A||c;if(!(!l||!I))return l.add(I),()=>{l.remove(I),I.dispose()}},[c,A,I]),null},Pet=({error:e,cad_component:A})=>{const{rootObject:t}=nd(),[i,n]=AA.useState(!1),[o,s]=AA.useState(null),r=AA.useCallback(I=>{I?.mousePosition?(n(!0),s(I.mousePosition)):(n(!1),s(null))},[]),a=AA.useCallback(()=>{n(!1),s(null)},[]),g=AA.useMemo(()=>A?.position?[A.position.x,A.position.y,A.position.z].map(l=>Number.isNaN(l)?0:l):[0,0,0],[A]),c=AA.useMemo(()=>{const I=new hf;return I.position.fromArray(g),I},[g]);return AA.useEffect(()=>{if(t)return t.add(c),()=>{t.remove(c)}},[t,c]),Z.jsxs(Z.Fragment,{children:[Z.jsxs(AJ,{isHovered:i,onHover:r,onUnhover:a,object:c,children:[Z.jsx(v2e,{parent:c}),Z.jsx(k2e,{parent:c,scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:`${e.toString().slice(0,50)}...`})]}),i&&o?Z.jsx(Rtt,{position:o,style:{fontFamily:"sans-serif",transform:"translate3d(-1rem, 0rem, 0)",backgroundColor:"white",padding:"6px",borderRadius:"4px",color:"red",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:e.toString()}):null]})},v2e=({parent:e})=>{const A=AA.useMemo(()=>{const t=new Io(new nw(.5,.5,.5),new TE({depthTest:!1,transparent:!0,color:"red",opacity:.5}));return t.renderOrder=999999,t.rotation.fromArray([Math.PI/4,Math.PI/4,0]),t},[]);return AA.useEffect(()=>(e.add(A),()=>{e.remove(A)}),[e,A]),null};function F2e({stlUrl:e,stlData:A,mtlUrl:t,color:i,opacity:n=1,layerType:o}){const{rootObject:s}=nd(),[r,a]=AA.useState(null);AA.useEffect(()=>{const c=new oYt;if(A){try{const I=c.parse(A);a(I)}catch(I){console.error("Failed to parse STL data",I),a(null)}return}e&&c.load(e,I=>{a(I)})},[e,A]);const g=AA.useMemo(()=>{if(!r)return null;const c=o==="board",I=new TE({color:Array.isArray(i)?new An(i[0],i[1],i[2]):i,transparent:n!==1,opacity:n,polygonOffset:c,polygonOffsetFactor:c?6:0,polygonOffsetUnits:c?6:0}),l=new Io(r,I);return l.renderOrder=c?-1:1,l},[r,i,n,o]);return AA.useEffect(()=>{if(!(!s||!g))return s.add(g),()=>{s.remove(g),g.geometry.dispose(),Array.isArray(g.material)?g.material.forEach(c=>c.dispose()):g.material.dispose()}},[s,g]),null}function M2e({stlData:e,color:A,opacity:t=1,layerType:i}){const{visibility:n}=OF();let o=!0;return i==="board"?o=n.boardBody:i==="top-copper"?o=n.topCopper:i==="bottom-copper"?o=n.bottomCopper:i==="top-silkscreen"?o=n.topSilkscreen:i==="bottom-silkscreen"&&(o=n.bottomSilkscreen),o?Z.jsx(F2e,{stlData:e,color:A,opacity:t,layerType:i}):null}var G2e=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].y,i=e[0].x,n=e[0].y;for(let o=1;o<e.length;o++){const s=e[o];s.x<A&&(A=s.x),s.y<t&&(t=s.y),s.x>i&&(i=s.x),s.y>n&&(n=s.y)}return{minX:A,minY:t,maxX:i,maxY:n}};function TD(e){if(e.outline&&e.outline.length>=3){const s=G2e(e.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=e.width??0,t=e.height??0,i=e.center?.x??0,n=e.center?.y??0;return{...{minX:i-A/2,maxX:i+A/2,minY:n-t/2,maxY:n+t/2},width:A,height:t,centerX:i,centerY:n}}function R2e({layer:e,circuitJson:A,boardData:t,copperColor:i,traceTextureResolution:n}){const s=yn(A).pcb_smtpad.list().filter(h=>h.layer===e);if(s.length===0)return null;const r=e==="top"?"top_copper":"bottom_copper",a=TD(t),g=document.createElement("canvas"),c=Math.floor(a.width*n),I=Math.floor(a.height*n);g.width=c,g.height=I;const l=g.getContext("2d");if(!l)return null;e==="bottom"&&(l.translate(0,I),l.scale(1,-1));const B="rgba(0,0,0,0)",C=new yw(l);C.configure({colorOverrides:{copper:{top:i,bottom:i,inner1:i,inner2:i,inner3:i,inner4:i,inner5:i,inner6:i},copperPour:{top:B,bottom:B},drill:B,boardOutline:B,substrate:B,keepout:B,fabricationNote:B,courtyard:{top:B,bottom:B},silkscreen:{top:B,bottom:B},soldermask:{top:B,bottom:B},soldermaskWithCopperUnderneath:{top:B,bottom:B},soldermaskOverCopper:{top:B,bottom:B}}}),C.setCameraBounds({minX:a.minX,maxX:a.maxX,minY:a.minY,maxY:a.maxY}),C.drawElements(s,{layers:[r],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});const Q=new sw(g);return Q.generateMipmaps=!0,Q.minFilter=KC,Q.magFilter=jg,Q.anisotropy=16,Q.needsUpdate=!0,Q}var N2e=e=>{const A=e.filter(t=>t.type==="pcb_panel");return A.length===0?null:A.length===1?A[0].pcb_panel_id:null};function L2e({layer:e,circuitJson:A,panelData:t,outlineColor:i="black",traceTextureResolution:n}){const o=N2e(A);if(!o)return null;const r=yn(A).pcb_board.list().filter(Q=>Q.pcb_panel_id===o||Q.position_mode==="relative_to_panel_anchor"&&!Q.pcb_panel_id);if(r.length===0)return null;const a=document.createElement("canvas"),g=Math.floor(t.width*n),c=Math.floor(t.height*n);a.width=g,a.height=c;const I=a.getContext("2d");if(!I)return null;e==="bottom"&&(I.translate(0,c),I.scale(1,-1)),I.strokeStyle=i,I.lineWidth=.05*n;const l=Q=>(Q-t.center.x+t.width/2)*n,B=Q=>(-(Q-t.center.y)+t.height/2)*n;r.forEach(Q=>{if(Q.outline&&Q.outline.length>=2)I.beginPath(),Q.outline.forEach((h,E)=>{const u=l(h.x),d=B(h.y);E===0?I.moveTo(u,d):I.lineTo(u,d)}),I.closePath(),I.stroke();else{const h=Q.width,E=Q.height,{x:u,y:d}=Q.center,f=l(u-h/2),m=B(d+E/2);I.strokeRect(f,m,h*n,E*n)}});const C=new sw(a);return C.generateMipmaps=!0,C.minFilter=KC,C.magFilter=jg,C.anisotropy=16,C.needsUpdate=!0,C}function U2e(e){return e&&e.route_type==="wire"&&typeof e.layer=="string"&&typeof e.width=="number"}function H2e(e,A){const t=[];let i=[];const n=()=>{if(i.length<2){i=[];return}t.push({...e,pcb_trace_id:`${e.pcb_trace_id}_${A}_${t.length}`,route:i}),i=[]};for(const o of e.route){if(!U2e(o)){n();continue}if(o.layer!==A){n();continue}i.push(o)}return n(),t}function Y2e({layer:e,circuitJson:A,boardData:t,traceColor:i,traceTextureResolution:n}){const o=yn(A).pcb_trace.list(),s=yn(A).pcb_via.list(),r=yn(A).pcb_plated_hole.list(),a=e==="top"?"top_copper":"bottom_copper",g=o.filter(f=>CtA(f).includes(a)).flatMap(f=>H2e(f,e));if(g.length===0)return null;const c=r.filter(f=>f.layers.includes(e)),I=[...g,...s,...c],l=TD(t),B=document.createElement("canvas"),C=Math.floor(l.width*n),Q=Math.floor(l.height*n);B.width=C,B.height=Q;const h=B.getContext("2d");if(!h)return null;e==="bottom"&&(h.translate(0,Q),h.scale(1,-1));const E="rgba(0,0,0,0)",u=new yw(h);u.configure({colorOverrides:{copper:{top:i,bottom:i,inner1:i,inner2:i,inner3:i,inner4:i,inner5:i,inner6:i},copperPour:{top:E,bottom:E},drill:E,boardOutline:E,substrate:E,keepout:E,fabricationNote:E,courtyard:{top:E,bottom:E},silkscreen:{top:E,bottom:E},soldermask:{top:E,bottom:E},soldermaskWithCopperUnderneath:{top:E,bottom:E},soldermaskOverCopper:{top:E,bottom:E}}}),u.setCameraBounds({minX:l.minX,maxX:l.maxX,minY:l.minY,maxY:l.maxY}),u.drawElements(I,{layers:[a],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});const d=new sw(B);return d.generateMipmaps=!0,d.minFilter=KC,d.magFilter=jg,d.anisotropy=16,d.needsUpdate=!0,d}var Ket=(e,A)=>{e.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},J2e=({ctx:e,layer:A,bounds:t,elements:i,copperColor:n})=>{const o=A==="top"?"top_copper":"bottom_copper",s=new yw(e);s.configure({colorOverrides:{copper:{top:n,bottom:n,inner1:n,inner2:n,inner3:n,inner4:n,inner5:n,inner6:n}}}),Ket(s,t),s.drawElements(i,{layers:[o]});const r=i.filter(I=>I.type==="pcb_copper_text"&&I.is_knockout===!0);if(r.length===0)return;const a=document.createElement("canvas");a.width=e.canvas.width,a.height=e.canvas.height;const g=a.getContext("2d");if(!g)return;const c=new yw(g);c.configure({colorOverrides:{copper:{top:"rgb(255,255,255)",bottom:"rgb(255,255,255)",inner1:"rgb(255,255,255)",inner2:"rgb(255,255,255)",inner3:"rgb(255,255,255)",inner4:"rgb(255,255,255)",inner5:"rgb(255,255,255)",inner6:"rgb(255,255,255)"}}}),Ket(c,t),c.drawElements(r.map(I=>({...I,is_knockout:!1})),{layers:[o]}),e.save(),e.globalCompositeOperation="destination-out",e.drawImage(a,0,0),e.restore()};function T2e({layer:e,circuitJson:A,boardData:t,copperColor:i="rgb(230, 153, 51)",traceTextureResolution:n=ww}){const o=A.filter(l=>l.type==="pcb_copper_text"&&"layer"in l&&l.layer===e);if(o.length===0)return null;const s=TD(t),r=Math.floor(s.width*n),a=Math.floor(s.height*n);if(r<=0||a<=0)return null;const g=document.createElement("canvas");g.width=r,g.height=a;const c=g.getContext("2d");if(!c)return null;e==="bottom"&&(c.translate(0,a),c.scale(1,-1)),J2e({ctx:c,layer:e,bounds:s,elements:o,copperColor:i});const I=new sw(g);return I.generateMipmaps=!0,I.minFilter=KC,I.magFilter=jg,I.anisotropy=16,I.needsUpdate=!0,I}var P2e=e=>{const[A=0,t=0,i=0]=e;return`rgb(${Math.round(A*255)}, ${Math.round(t*255)}, ${Math.round(i*255)})`},K2e=8;function q2e({layer:e,circuitJson:A,boardData:t,traceTextureResolution:i=ww,copperColor:n=P2e(_a.copper)}){const o=A.filter(f=>f.type==="pcb_copper_pour"),s=e==="top"?"top_copper":"bottom_copper",r=o.filter(f=>f.layer===e);if(r.length===0)return null;const a=TD(t),g=document.createElement("canvas"),c=Math.floor(a.width*i),I=Math.floor(a.height*i);g.width=c,g.height=I;const l=g.getContext("2d");if(!l)return null;e==="bottom"&&(l.translate(0,I),l.scale(1,-1));const B="rgba(0,0,0,0)",C=n,Q=n,h=(f,m)=>{if(f.length===0)return;const w=new yw(l);w.configure({colorOverrides:{copper:{top:m,bottom:m,inner1:m,inner2:m,inner3:m,inner4:m,inner5:m,inner6:m},copperPour:{top:B,bottom:B},drill:B,boardOutline:B,substrate:B,keepout:B,fabricationNote:B,courtyard:{top:B,bottom:B},silkscreen:{top:B,bottom:B},soldermask:{top:B,bottom:B},soldermaskWithCopperUnderneath:{top:B,bottom:B},soldermaskOverCopper:{top:B,bottom:B}}}),w.setCameraBounds({minX:a.minX,maxX:a.maxX,minY:a.minY,maxY:a.maxY}),w.drawElements(f,{layers:[s],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});for(let D=1;D<K2e;D+=1)w.drawElements(f,{layers:[s],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1})},E=r.filter(f=>f.covered_with_solder_mask!==!1),u=r.filter(f=>f.covered_with_solder_mask===!1);h(E,C),h(u,Q);const d=new sw(g);return d.generateMipmaps=!0,d.minFilter=KC,d.magFilter=jg,d.anisotropy=16,d.needsUpdate=!0,d}var qet=25.4,O2e=qet/1e3,W2e=/^\s*(-?\d*(?:\.\d+)?)(?:\s*(mm|mil|inch|in|"))?\s*$/i;function Z2e(e){if(!e)return;const A=e.trim().toLowerCase();return A==='"'||A==="inch"?"in":A}function mV(e){if(e==null)return;if(typeof e=="number")return Number.isFinite(e)?e:void 0;if(typeof e!="string")return;const A=e.trim();if(A.length===0)return;const t=A.match(W2e);if(!t){const r=Number.parseFloat(A);return Number.isFinite(r)?r:void 0}const[,i,n]=t,o=Number.parseFloat(i||"0");if(!Number.isFinite(o))return;switch(Z2e(n)){case"mil":return o*O2e;case"in":return o*qet;case"mm":case void 0:return o;default:return o}}function Bg(e,A){const t=mV(e);return t===void 0?A:t}var V2e="rgb(255,243,204)",ol="rgba(0,0,0,0)",j2e=(e,A)=>{e.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},z2e=e=>e.type==="pcb_fabrication_note_rect"?{...e,width:mV(e.width)??0,height:mV(e.height)??0,stroke_width:Bg(e.stroke_width,.1),corner_radius:mV(e.corner_radius)}:e.type==="pcb_fabrication_note_path"?{...e,stroke_width:Bg(e.stroke_width,.1)}:e.type==="pcb_fabrication_note_text"?{...e,font_size:Bg(e.font_size,1)}:e.type==="pcb_fabrication_note_dimension"?{...e,font_size:Bg(e.font_size,1),arrow_size:Bg(e.arrow_size,1),offset_distance:Bg(e.offset_distance,0)}:e,X2e=({ctx:e,layer:A,bounds:t,elements:i})=>{const n=`${A}_fabrication_note`,o=i.map(z2e),s=new yw(e);s.configure({colorOverrides:{copper:{top:ol,bottom:ol,inner1:ol,inner2:ol,inner3:ol,inner4:ol,inner5:ol,inner6:ol},copperPour:{top:ol,bottom:ol},drill:ol,boardOutline:ol,substrate:ol,keepout:ol,courtyard:{top:ol,bottom:ol},soldermask:{top:ol,bottom:ol},soldermaskWithCopperUnderneath:{top:ol,bottom:ol},soldermaskOverCopper:{top:ol,bottom:ol},silkscreen:{top:ol,bottom:ol},fabricationNote:V2e}}),j2e(s,t),s.drawElements(o,{layers:[n]})},$2e=e=>({minX:e.center.x-e.width/2,maxX:e.center.x+e.width/2,minY:e.center.y-e.height/2,maxY:e.center.y+e.height/2,width:e.width,height:e.height,centerX:e.center.x,centerY:e.center.y}),A1e=(e,A)=>{const t=Math.min(e.minX,A.minX),i=Math.max(e.maxX,A.maxX),n=Math.min(e.minY,A.minY),o=Math.max(e.maxY,A.maxY);return{minX:t,maxX:i,minY:n,maxY:o,width:i-t,height:o-n,centerX:(t+i)/2,centerY:(n+o)/2}},wV=(e,A)=>{const t=e.filter(s=>s.type==="pcb_panel"),i=e.filter(s=>s.type==="pcb_board"),n=t.find(s=>s.pcb_panel_id===A.pcb_board_id)??t[0];return n&&n.width>0&&n.height>0?$2e(n):(i.length>1?i:[A]).map(s=>TD(s)).reduce((s,r)=>A1e(s,r))},t1e=(e,A)=>!("layer"in e)||e.layer!==A?!1:e.type.startsWith("pcb_fabrication_note_");function e1e({layer:e,circuitJson:A,boardData:t,traceTextureResolution:i=ww}){const n=A.filter(I=>t1e(I,e));if(n.length===0)return null;const o=wV(A,t),s=Math.floor(o.width*i),r=Math.floor(o.height*i);if(s<=0||r<=0)return null;const a=document.createElement("canvas");a.width=s,a.height=r;const g=a.getContext("2d");if(!g)return null;e==="bottom"&&(g.translate(0,r),g.scale(1,-1)),X2e({ctx:g,layer:e,bounds:o,elements:n});const c=new sw(a);return c.generateMipmaps=!0,c.minFilter=KC,c.magFilter=jg,c.anisotropy=16,c.needsUpdate=!0,c}var NI="rgba(0,0,0,0)",i1e=(e,A)=>{e.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},n1e=e=>e.type==="pcb_note_line"?{...e,x1:Bg(e.x1,0),y1:Bg(e.y1,0),x2:Bg(e.x2,0),y2:Bg(e.y2,0),stroke_width:Bg(e.stroke_width,.1)}:e.type==="pcb_note_rect"?{...e,center:{x:Bg(e.center.x,0),y:Bg(e.center.y,0)},width:Bg(e.width,0),height:Bg(e.height,0),stroke_width:Bg(e.stroke_width,.1),corner_radius:Bg(e.corner_radius,0)}:e.type==="pcb_note_text"?{...e,anchor_position:{x:Bg(e.anchor_position.x,0),y:Bg(e.anchor_position.y,0)},font_size:Bg(e.font_size,1)}:e.type==="pcb_note_path"?{...e,route:e.route.map(A=>({...A,x:Bg(A.x,0),y:Bg(A.y,0)})),stroke_width:Bg(e.stroke_width,.1)}:e.type==="pcb_note_dimension"?{...e,from:{x:Bg(e.from.x,0),y:Bg(e.from.y,0)},to:{x:Bg(e.to.x,0),y:Bg(e.to.y,0)},font_size:Bg(e.font_size,1),arrow_size:Bg(e.arrow_size,1),offset_distance:Bg(e.offset_distance,0)}:e,o1e=({ctx:e,bounds:A,elements:t})=>{const i=t.map(n1e),n=new yw(e);n.configure({colorOverrides:{copper:{top:NI,bottom:NI,inner1:NI,inner2:NI,inner3:NI,inner4:NI,inner5:NI,inner6:NI},copperPour:{top:NI,bottom:NI},drill:NI,boardOutline:NI,substrate:NI,keepout:NI,courtyard:{top:NI,bottom:NI},soldermask:{top:NI,bottom:NI},soldermaskWithCopperUnderneath:{top:NI,bottom:NI},soldermaskOverCopper:{top:NI,bottom:NI},silkscreen:{top:NI,bottom:NI},fabricationNote:NI}}),i1e(n,A),n.drawElements(i)},s1e=(e,A)=>!("layer"in e)||e.layer!==A?!1:e.type.startsWith("pcb_note_");function r1e({layer:e,circuitJson:A,boardData:t,traceTextureResolution:i=ww}){const n=A.filter(I=>s1e(I,e));if(n.length===0)return null;const o=wV(A,t),s=Math.floor(o.width*i),r=Math.floor(o.height*i);if(s<=0||r<=0)return null;const a=document.createElement("canvas");a.width=s,a.height=r;const g=a.getContext("2d");if(!g)return null;e==="bottom"&&(g.translate(0,r),g.scale(1,-1)),o1e({ctx:g,bounds:o,elements:n});const c=new sw(a);return c.generateMipmaps=!0,c.minFilter=KC,c.magFilter=jg,c.anisotropy=16,c.needsUpdate=!0,c}var a1e="rgb(255,243,204)",fB="rgba(0,0,0,0)",g1e=(e,A)=>{e.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},c1e=({ctx:e,layer:A,bounds:t,elements:i,silkscreenColor:n})=>{const o=A==="top"?"top_silkscreen":"bottom_silkscreen",s=new yw(e);s.configure({colorOverrides:{copper:{top:fB,bottom:fB,inner1:fB,inner2:fB,inner3:fB,inner4:fB,inner5:fB,inner6:fB},copperPour:{top:fB,bottom:fB},drill:fB,boardOutline:fB,substrate:fB,keepout:fB,courtyard:{top:fB,bottom:fB},soldermask:{top:fB,bottom:fB},soldermaskWithCopperUnderneath:{top:fB,bottom:fB},soldermaskOverCopper:{top:fB,bottom:fB},silkscreen:{top:n,bottom:n},fabricationNote:a1e}}),g1e(s,t),s.drawElements(i,{layers:[o]})},I1e=(e,A)=>!("layer"in e)||e.layer!==A?!1:e.type.startsWith("pcb_silkscreen_");function l1e({layer:e,circuitJson:A,boardData:t,traceTextureResolution:i=ww,silkscreenColor:n="rgb(255,255,255)"}){const o=A.filter(l=>I1e(l,e));if(o.length===0)return null;const s=wV(A,t),r=Math.floor(s.width*i),a=Math.floor(s.height*i);if(r<=0||a<=0)return null;const g=document.createElement("canvas");g.width=r,g.height=a;const c=g.getContext("2d");if(!c)return null;e==="bottom"&&(c.translate(0,a),c.scale(1,-1)),c1e({ctx:c,layer:e,bounds:s,elements:o,silkscreenColor:n});const I=new sw(g);return I.generateMipmaps=!0,I.minFilter=KC,I.magFilter=jg,I.anisotropy=16,I.needsUpdate=!0,I}var DV=e=>{const[A=0,t=0,i=0]=e;return`rgb(${Math.round(A*255)}, ${Math.round(t*255)}, ${Math.round(i*255)})`},B1e=e=>{const A=DV(g2e[e]??_a.fr4SolderMaskGreen),t=DV(e==="fr1"?_a.fr1TracesWithMaskCopper:_a.fr4TracesWithMaskGreen);return{soldermask:A,soldermaskOverCopper:t,copper:DV(_a.copper),transparent:"rgba(0,0,0,0)"}},Oet=(e,A)=>{e.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},C1e=({ctx:e,layer:A,bounds:t,elements:i,boardMaterial:n})=>{const o=B1e(n),s=A==="top"?"top_copper":"bottom_copper",r=new yw(e);r.configure({colorOverrides:{copper:{top:o.transparent,bottom:o.transparent,inner1:o.transparent,inner2:o.transparent,inner3:o.transparent,inner4:o.transparent,inner5:o.transparent,inner6:o.transparent},drill:o.transparent,boardOutline:o.transparent,substrate:o.transparent,keepout:o.transparent,fabricationNote:o.transparent,silkscreen:{top:o.transparent,bottom:o.transparent},courtyard:{top:o.transparent,bottom:o.transparent},soldermask:{top:o.soldermask,bottom:o.soldermask},soldermaskWithCopperUnderneath:{top:o.soldermaskOverCopper,bottom:o.soldermaskOverCopper},soldermaskOverCopper:{top:o.soldermaskOverCopper,bottom:o.soldermaskOverCopper}}}),Oet(r,t),r.drawElements(i,{layers:[s],drawSoldermask:!0,drawSoldermaskTop:A==="top",drawSoldermaskBottom:A==="bottom"});const a=i.filter(g=>g.type==="pcb_copper_pour"&&g.layer===A&&g.covered_with_solder_mask===!1);if(a.length>0){e.save(),e.globalCompositeOperation="destination-out";const g=new yw(e);g.configure({colorOverrides:{copper:{top:o.copper,bottom:o.copper,inner1:o.copper,inner2:o.copper,inner3:o.copper,inner4:o.copper,inner5:o.copper,inner6:o.copper}}}),Oet(g,t),g.drawElements(a,{layers:[s]}),e.restore()}};function Q1e({layer:e,circuitJson:A,boardData:t,traceTextureResolution:i=ww}){const n=wV(A,t),o=Math.floor(n.width*i),s=Math.floor(n.height*i);if(o<=0||s<=0)return null;const r=document.createElement("canvas");r.width=o,r.height=s;const a=r.getContext("2d");if(!a)return null;e==="bottom"&&(a.translate(0,s),a.scale(1,-1));const g=A.some(I=>I.type==="pcb_board")?A:[t,...A];C1e({ctx:a,layer:e,bounds:n,elements:g,boardMaterial:t.material});const c=new sw(r);return c.generateMipmaps=!0,c.minFilter=KC,c.magFilter=jg,c.anisotropy=16,c.needsUpdate=!0,c}var h1e=(e,A)=>{e.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},E1e=({ctx:e,layer:A,bounds:t,elements:i,copperColor:n})=>{const o=A==="top"?"top_copper":"bottom_copper",s="rgba(0,0,0,0)",r=new yw(e);r.configure({colorOverrides:{copper:{top:n,bottom:n,inner1:n,inner2:n,inner3:n,inner4:n,inner5:n,inner6:n},drill:s,boardOutline:s,substrate:s,keepout:s,fabricationNote:s,silkscreen:{top:s,bottom:s},courtyard:{top:s,bottom:s},soldermask:{top:s,bottom:s},soldermaskWithCopperUnderneath:{top:s,bottom:s},soldermaskOverCopper:{top:s,bottom:s}}}),h1e(r,t),r.drawElements(i,{layers:[o]})};function u1e({layer:e,circuitJson:A,boardData:t,copperColor:i="rgb(230, 153, 51)",traceTextureResolution:n=ww}){const o=A.filter(l=>{if(l.type==="pcb_via")return!0;if(l.type!=="pcb_plated_hole")return!1;const B=l;return!Array.isArray(B.layers)||B.layers.includes(e)});if(o.length===0)return null;const s=TD(t),r=Math.floor(s.width*n),a=Math.floor(s.height*n);if(r<=0||a<=0)return null;const g=document.createElement("canvas");g.width=r,g.height=a;const c=g.getContext("2d");if(!c)return null;e==="bottom"&&(c.translate(0,a),c.scale(1,-1)),E1e({ctx:c,layer:e,bounds:s,elements:o,copperColor:i});const I=new sw(g);return I.generateMipmaps=!0,I.minFilter=KC,I.magFilter=jg,I.anisotropy=16,I.needsUpdate=!0,I}var Wet=e=>{const[A=0,t=0,i=0]=e;return`rgb(${Math.round(A*255)}, ${Math.round(t*255)}, ${Math.round(i*255)})`},d1e=({textures:e,boardData:A,traceTextureResolution:t})=>{if(!e.some(c=>c?.image))return null;const n=TD(A),o=Math.floor(n.width*t),s=Math.floor(n.height*t);if(o<=0||s<=0)return null;const r=document.createElement("canvas");r.width=o,r.height=s+1;const a=r.getContext("2d");if(!a)return null;e.forEach(c=>{if(!c?.image)return;const I=c.image;a.drawImage(I,0,0,o,s)});const g=new sw(r);return g.generateMipmaps=!1,g.minFilter=jg,g.magFilter=jg,g.premultiplyAlpha=!0,g.anisotropy=16,g.needsUpdate=!0,g};function Zet({circuitJson:e,boardData:A,traceTextureResolution:t,visibility:i}){const n=Wet(_a.copper),o="rgb(255,255,255)",s=Wet(_a.copper),r=i?.boardBody??!0,a=c=>{const I=(c==="top"?i?.topMask:i?.bottomMask)??!0,l=(c==="top"?i?.topCopper:i?.bottomCopper)??!0,B=(c==="top"?i?.topSilkscreen:i?.bottomSilkscreen)??!0,C=I?Q1e({layer:c,circuitJson:e,boardData:A,traceTextureResolution:t}):null,Q=l?Y2e({layer:c,circuitJson:e,boardData:A,traceColor:n,traceTextureResolution:t}):null,h=l?q2e({layer:c,circuitJson:e,boardData:A,traceTextureResolution:t,copperColor:s}):null,E=l?T2e({layer:c,circuitJson:e,boardData:A,copperColor:s,traceTextureResolution:t}):null,u=l?R2e({layer:c,circuitJson:e,boardData:A,copperColor:s,traceTextureResolution:t}):null,d=l?u1e({layer:c,circuitJson:e,boardData:A,copperColor:s,traceTextureResolution:t}):null,f=B?l1e({layer:c,circuitJson:e,boardData:A,silkscreenColor:o,traceTextureResolution:t}):null,m=B?e1e({layer:c,circuitJson:e,boardData:A,traceTextureResolution:t}):null,D=i?.pcbNotes??!1?r1e({layer:c,circuitJson:e,boardData:A,traceTextureResolution:t}):null,S=r?L2e({layer:c,circuitJson:e,panelData:A,traceTextureResolution:t}):null;return d1e({textures:[h,Q,u,d,C,E,f,m,D,S],boardData:A,traceTextureResolution:t})},g=A.num_layers??2;return{topBoard:a("top"),bottomBoard:g<2?null:a("bottom")}}function Vet(e,A){const{texture:t,yOffset:i,isBottomLayer:n,usePolygonOffset:o=!1,renderOrder:s=0,isFaux:r=!1}=e;if(!t)return null;const a=TD(A),g=new ow(a.width,a.height),c=new Vd({map:t,transparent:!0,alphaTest:.08,side:F0,depthWrite:!0,polygonOffset:o,polygonOffsetFactor:o?-4:0,polygonOffsetUnits:o?-4:0,opacity:r?dV:1}),I=new Io(g,c);return I.position.set(a.centerX,a.centerY,i),n&&I.rotation.set(Math.PI,0,0),I.name=`${n?"bottom":"top"}-board-texture-plane`,I.renderOrder=s,I}function p1e(e,A,t,i=!1){const n=[];if(!e||!A||t===null)return n;const o=.005,s=Vet({texture:e.topBoard,yOffset:t/2+o,isBottomLayer:!1,usePolygonOffset:!0,renderOrder:1,isFaux:i},A);s&&n.push(s);const r=Vet({texture:e.bottomBoard,yOffset:-t/2-o,isBottomLayer:!0,usePolygonOffset:!0,renderOrder:1,isFaux:i},A);return r&&n.push(r),n}var f1e=4e6,y1e=4096,m1e=1;function jet(e,A,t={}){const{maxTexturePixels:i=f1e,maxTextureDimension:n=y1e,minTextureResolution:o=m1e}=t,s=TD(e);if(!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<=0||s.height<=0)return A;const r=Math.max(s.width,s.height),a=n/r,g=Math.sqrt(i/(s.width*s.height)),c=Math.min(A,a,g);return Math.max(o,c)}function w1e({circuitJson:e,pcbThickness:A,isFaux:t=!1}){const{rootObject:i}=nd(),{visibility:n}=OF(),o=AA.useMemo(()=>{const a=e.filter(I=>I.type==="pcb_panel"),g=yn(e).pcb_board.list();if(a.length>0){const I=a[0],l=g.find(B=>B.pcb_panel_id===I.pcb_panel_id);return{type:"pcb_board",pcb_board_id:I.pcb_panel_id,center:I.center,width:I.width,height:I.height,thickness:l?.thickness??1.4,material:l?.material??"fr4",num_layers:l?.num_layers??2}}const c=g.filter(I=>!I.pcb_panel_id);return c.length>0?c[0]:null},[e]),s=AA.useMemo(()=>o?jet(o,ww):ww,[o]),r=AA.useMemo(()=>!o||!o.width||!o.height?null:Zet({circuitJson:e,boardData:o,traceTextureResolution:s,visibility:n}),[e,o,s,n]);return AA.useEffect(()=>{if(!i||!o||!r)return;const a=[],g=C=>{const Q=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],h=C;for(const E of Q){const u=h[E];u&&u instanceof $c&&(u.dispose(),h[E]=null)}C.dispose()},c=(C,Q,h,E,u=!1,d=!0,f=1)=>{if(!C)return null;const m=TD(o),w=new ow(m.width,m.height),D=new Vd({map:C,transparent:!0,alphaTest:.08,side:F0,depthWrite:d,polygonOffset:u,polygonOffsetFactor:u?-4:0,polygonOffsetUnits:u?-4:0,opacity:t?dV:1}),S=new Io(w,D);return S.position.set(m.centerX,m.centerY,Q),h&&S.rotation.set(Math.PI,0,0),S.name=E,S.renderOrder=f,S.frustumCulled=!1,S},I=.005,l=c(r.topBoard,A/2+I,!1,"jscad-top-board-texture",!0);l&&(a.push(l),i.add(l));const B=c(r.bottomBoard,-A/2-I,!0,"jscad-bottom-board-texture",!0);return B&&(a.push(B),i.add(B)),()=>{a.forEach(C=>{C.parent===i&&i.remove(C),C.geometry.dispose(),Array.isArray(C.material)?C.material.forEach(Q=>g(Q)):C.material instanceof Qf&&g(C.material)}),r.topBoard?.dispose(),r.bottomBoard?.dispose()}},[i,o,r,A]),null}function D1e(e){const A=yn(e).cad_component.list(),t=yn(e).pcb_smtpad.list(),i=yn(e).pcb_hole.list(),n=yn(e).pcb_plated_hole.list(),o=yn(e).pcb_via.list();if(A.length===0&&t.length===0&&i.length===0&&n.length===0&&o.length===0)return null;const s=[...i,...n,...o,...t],r=FR(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 zet(e){if(yn(e).pcb_board.list().length>0)return e;const t=D1e(e);if(!t)return e;const n=t.thickness/2;return[...e.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+n}}}}return s}),t]}var S1e=AA.forwardRef(({circuitJson:e,children:A,autoRotateDisabled:t,clickToInteractEnabled:i,onUserInteraction:n,onCameraControllerReady:o,resolveStaticAsset:s},r)=>{const a=Uet(A),g=AA.useMemo(()=>zet(e??a),[e,a]),c=_2e(g),I=AA.useMemo(()=>{if(!g)return[5,-5,5];try{const u=yn(g).pcb_board.list()[0];if(!u)return[5,-5,5];const{width:d,height:f}=u;if(!d&&!f)return[5,-5,5];const m=5,w=Math.max(d,m),D=Math.max(f,m),S=Math.max(w,D);return[S*.4,-S*.7,S*.9]}catch(u){return console.error(u),[5,-5,5]}},[g]),l=AA.useMemo(()=>{if(!g)return!1;try{const u=yn(g).pcb_board.list()[0];return!!u&&u.pcb_board_id==="faux-board"}catch{return!1}},[g]),B=AA.useMemo(()=>{if(g)try{const u=yn(g).pcb_board.list()[0];return u?{width:u.width??0,height:u.height??0}:void 0}catch(u){console.error(u);return}},[g]),C=AA.useMemo(()=>{if(g)try{const u=yn(g).pcb_board.list()[0];return!u||!u.center?void 0:{x:u.center.x,y:u.center.y}}catch(u){console.error(u);return}},[g]),Q=Mtt(g),{stls:h}=s2e(c),E=yn(g).cad_component.list();return Z.jsxs(Let,{ref:r,autoRotateDisabled:t,initialCameraPosition:I,clickToInteractEnabled:i,boardDimensions:B,boardCenter:C,onUserInteraction:n,onCameraControllerReady:o,children:[h.map(({stlData:u,color:d,layerType:f},m)=>Z.jsx(M2e,{stlData:u,color:d,opacity:m===0?l?.8:.95:1,layerType:f},`board-${m}`)),Z.jsx(w1e,{circuitJson:g,pcbThickness:Q,isFaux:l}),E.map(u=>Z.jsx(pdA,{fallback:({error:d})=>Z.jsx(Pet,{cad_component:u,error:d}),children:Z.jsx(Fet,{cad_component:u,circuitJson:g,resolveStaticAsset:s},u.cad_component_id)},u.cad_component_id))]})}),b1e=e=>{let A=0;for(let i=0;i<e.length;i++){const n=(i+1)%e.length;e[i]&&e[n]&&(A+=e[i][0]*e[n][1],A-=e[n][0]*e[i][1])}return A/2<=0};function x1e(e,A,t,i,n){let o,s=null;if(t.outline&&t.outline.length>=3){let r=t.outline.map(g=>[g.x,g.y]);b1e(r)&&(r=r.reverse());const a=A.ofPolygons([r]);n.push(a),s=a,o=e.extrude(a,i,void 0,void 0,void 0,!0),n.push(o)}else t.outline&&t.outline.length>0&&console.warn("Board outline has fewer than 3 points, falling back to rectangular board."),o=e.cube([t.width,t.height,i],!0),n.push(o),o=o.translate([t.center.x,t.center.y,0]),n.push(o);return{boardOp:o,outlineCrossSection:s}}var _1e=64;function zF({Manifold:e,width:A,height:t,thickness:i,borderRadius:n}){const o=Jet(A,t,n);if(o<=0)return e.cube([A,t,i],!0);const s=[],r=A-2*o,a=t-2*o;return r>0&&s.push(e.cube([r,t,i],!0)),a>0&&s.push(e.cube([A,a,i],!0)),[[A/2-o,t/2-o],[-A/2+o,t/2-o],[-A/2+o,-t/2+o],[A/2-o,-t/2+o]].forEach(([c,I])=>{s.push(e.cylinder(i,o,o,_1e,!0).translate([c,I,0]))}),e.union(s)}var k1e=e=>{let A=0;for(let i=0;i<e.length;i++){const n=(i+1)%e.length;e[i]&&e[n]&&(A+=e[i][0]*e[n][1],A-=e[n][0]*e[i][1])}return A/2<=0};function v1e(e,A,t,i,n){const o=[],s=yn(t).pcb_cutout.list();for(const r of s){let a;const g=i*1.5;switch(r.shape){case"rect":{const l=ck(r);if(typeof l=="number"&&l>0?a=zF({Manifold:e,width:r.width,height:r.height,thickness:g,borderRadius:l}):a=e.cube([r.width,r.height,g],!0),n.push(a),r.rotation){const B=a.rotate([0,0,r.rotation]);n.push(B),a=B}a=a.translate([r.center.x,r.center.y,0]),n.push(a);break}case"circle":a=e.cylinder(g,r.radius,-1,XQ,!0),n.push(a),a=a.translate([r.center.x,r.center.y,0]),n.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]);k1e(c)&&(c=c.reverse());const I=A.ofPolygons([c]);n.push(I),a=e.extrude(I,g,0,0,[1,1],!0),n.push(a);break;default:console.warn(`Unsupported cutout shape: ${r.shape} for cutout ${r.pcb_cutout_id}`);continue}a&&o.push(a)}return{cutoutOps:o}}function Xet({Manifold:e,x:A,y:t,diameter:i,thickness:n,segments:o=32}){return e.cylinder(n*1.2,i/2,i/2,o,!0).translate([A,t,0])}function $et({Manifold:e,x:A,y:t,holeDiameter:i,thickness:n,zOffset:o=.001,segments:s=32}){const r=i/2+o;return e.cylinder(n*1.2,r,r,s,!0).translate([A,t,0])}function F1e(e,A,t,i,n){const o=[],s=yn(t).pcb_hole.list(),r=(g,c,I)=>{const l=zF({Manifold:e,width:g,height:c,thickness:I,borderRadius:Math.min(g,c)/2});return n.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=Xet({Manifold:e,x:I,y:l,diameter:g.hole_diameter,thickness:i,segments:XQ}),o.push(E),n.push(E);return}if(c==="pill"||c==="rotated_pill")E=r(Q,h,B);else if(c==="oval"){let u=a(Q,h,XQ),d=0;for(let m=0;m<u.length;m++){const w=(m+1)%u.length;d+=u[m][0]*u[w][1],d-=u[w][0]*u[m][1]}d<=0&&(u=u.reverse());const f=A.ofPolygons([u]);n.push(f),E=e.extrude(f,B,0,0,[1,1],!0),n.push(E)}if(E){if(C!==0){const d=E.rotate([0,0,C]);n.push(d),E=d}const u=E.translate([I,l,0]);n.push(u),o.push(u)}}),{nonPlatedHoleBoardDrills:o}}function PD(e){const A=new kg;if(A.setAttribute("position",new $o(e.vertProperties,3)),A.setIndex(new M$(e.triVerts,1)),e.runIndex&&e.runIndex.length>1&&e.runOriginalID)for(let t=0;t<e.runIndex.length-1;t++){const i=e.runIndex[t],n=e.runIndex[t+1]-i;A.addGroup(i,n,0)}else A.addGroup(0,e.triVerts.length,0);return A}var iJ=e=>{let A=0;for(let i=0;i<e.length;i++){const n=(i+1)%e.length;e[i]&&e[n]&&(A+=e[i][0]*e[n][1],A-=e[n][0]*e[i][1])}return A/2<=0},SV=(e,A,t)=>{const i=[];for(let n=0;n<t;n++){const o=2*Math.PI*n/t;i.push([e/2*Math.cos(o),A/2*Math.sin(o)])}return i},XF=new An(..._a.copper),bV=.05,nJ=.003,oJ=5e-4,sJ=.004;function M1e(e,A,t,i,n,o){const s=[],r=yn(t).pcb_plated_hole.list(),a=[],g=[],c=(C,Q,h)=>{const E=zF({Manifold:e,width:C,height:Q,thickness:h,borderRadius:Math.min(C,Q)/2});return n.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]);iJ(h)&&(h=h.reverse());const E=A.ofPolygons([h]);n.push(E);const u=e.extrude(E,Q,0,0,[1,1],!0);return n.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 w=null;if(d==="circle"){const D=Math.max((C.hole_diameter??0)+h,Tn),S=Math.max(D/2,Tn/2);w=e.cylinder(Q,S,S,XQ,!0),n.push(w)}else{const D=C.hole_width??C.hole_diameter,S=C.hole_height??C.hole_diameter;if(!D||!S)return null;const _=Math.max(D+h,Tn),b=Math.max(S+h,Tn);if(d==="oval"){let R=SV(_,b,XQ);iJ(R)&&(R=R.reverse());const F=A.ofPolygons([R]);n.push(F),w=e.extrude(F,Q,0,0,[1,1],!0),n.push(w)}else(d==="pill"||d==="rotated_pill")&&(w=zF({Manifold:e,width:_,height:b,thickness:Q,borderRadius:Math.min(_,b)/2}),n.push(w))}if(!w)return null;if(f||m){const D=w.translate([f,m,0]);n.push(D),w=D}return w};r.forEach((C,Q)=>{const h=Math.max(i-2*(nJ+oJ+sJ),Tn);if(C.shape==="circle"){const E=$et({Manifold:e,x:C.x,y:C.y,holeDiameter:C.hole_diameter*1.02,thickness:i,zOffset:mw,segments:XQ});n.push(E),s.push(E);const u=h,d=e.cylinder(u,C.outer_diameter/2,C.outer_diameter/2,XQ,!0);n.push(d);const f=e.cylinder(u*1.05,C.hole_diameter/2,C.hole_diameter/2,XQ,!0);n.push(f);const m=d.subtract(f);n.push(m);const w=m.translate([C.x,C.y,0]);n.push(w);let D=w;if(o){const _=e.intersection([w,o]);n.push(_),D=_}g.push(D);const S=PD(D.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:S,color:XF})}else if(C.shape==="pill"){const E=C.hole_width,u=C.hole_height,d=.4,f=C.outer_width??E+d,m=C.outer_height??u+d,w=E+2*mw,D=u+2*mw,S=i*1.2;let _=c(w,D,S);if(C.ccw_rotation){const z=_.rotate([0,0,C.ccw_rotation]);n.push(z),_=z}const b=_.translate([C.x,C.y,0]);n.push(b),s.push(b);const R=h,F=c(f,m,R),H=c(E,u,R*1.05);let Y=F.subtract(H);if(n.push(Y),C.ccw_rotation){const z=Y.rotate([0,0,C.ccw_rotation]);n.push(z),Y=z}const J=Y.translate([C.x,C.y,0]);n.push(J);let O=J;if(o){const z=e.intersection([J,o]);n.push(z),O=z}g.push(O);const W=PD(O.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:W,color:XF})}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 E=C.hole_width,u=C.hole_height,d=C.hole_offset_x||0,f=C.hole_offset_y||0,m=C.rect_pad_width,w=C.rect_pad_height,D=ck(C),S=nJ,_=E+2*mw,b=u+2*mw,R=i*1.2,H=c(_,b,R).translate([d,f,0]).translate([C.x,C.y,0]);n.push(H),s.push(H);const Y=zF({Manifold:e,width:m,height:w,thickness:Math.max(i-2*(S+oJ+sJ),Tn),borderRadius:D});n.push(Y);const J=c(E,u,i*.8).translate([d,f,0]);n.push(J);const O=e.union([Y,J]);n.push(O);const W=c(Math.max(E-2*bV,.01),Math.max(u-2*bV,.01),i*1.2).translate([d,f,0]);n.push(W);const z=O.subtract(W);n.push(z);const tA=z.translate([C.x,C.y,0]);n.push(tA);let aA=tA;if(o){const oA=e.intersection([tA,o]);n.push(oA),aA=oA}g.push(aA);const eA=PD(aA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:eA,color:XF})}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 E=C.hole_width,u=C.hole_height,d=C.hole_offset_x||0,f=C.hole_offset_y||0,m=C.rect_pad_width,w=C.rect_pad_height,D=ck(C),S=nJ,_=E+2*mw,b=u+2*mw,R=i*1.2;let F=c(_,b,R).translate([d,f,0]);if(C.hole_ccw_rotation){const oA=F.rotate([0,0,C.hole_ccw_rotation]);n.push(oA),F=oA}const H=F.translate([C.x,C.y,0]);n.push(H),s.push(H);let Y=zF({Manifold:e,width:m,height:w,thickness:Math.max(i-2*(S+oJ+sJ),Tn),borderRadius:D});if(n.push(Y),C.rect_ccw_rotation){const oA=Y.rotate([0,0,C.rect_ccw_rotation]);n.push(oA),Y=oA}let J=c(E,u,i*.8).translate([d,f,0]);if(C.hole_ccw_rotation){const oA=J.rotate([0,0,C.hole_ccw_rotation]);n.push(oA),J=oA}n.push(J);const O=e.union([Y,J]);n.push(O);let W=c(Math.max(E-2*bV,.01),Math.max(u-2*bV,.01),i*1.2).translate([d,f,0]);if(C.hole_ccw_rotation){const oA=W.rotate([0,0,C.hole_ccw_rotation]);n.push(oA),W=oA}n.push(W);const z=O.subtract(W);n.push(z);const tA=z.translate([C.x,C.y,0]);n.push(tA);let aA=tA;if(o){const oA=e.intersection([tA,o]);n.push(oA),aA=oA}g.push(aA);const eA=PD(aA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:eA,color:XF})}else if(C.shape==="hole_with_polygon_pad"){const E=C.pad_outline;if(!Array.isArray(E)||E.length<3)return;const u=l({ph:C,depth:i*1.2,sizeDelta:2*Tn});if(!u)return;const d=u.translate([C.x,C.y,0]);n.push(d),s.push(d);const m=Math.max(i-2*(nJ+oJ+sJ),Tn),w=I({padOutline:E,thickness:m});if(!w)return;const D=l({ph:C,depth:i*1.02});if(!D)return;const S=l({ph:C,depth:i*.8,sizeDelta:-2*Tn})||D,_=e.union([w,D]);n.push(_);const b=_.subtract(S);n.push(b);const R=b.translate([C.x,C.y,0]);n.push(R);let F=R;if(o){const Y=e.intersection([R,o]);n.push(Y),F=Y}g.push(F);const H=PD(F.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:H,color:XF})}else if(C.shape==="oval"){const E=C.hole_width,u=C.hole_height,d=C.outer_width??E+.4,f=C.outer_height??u+.4,m=E+2*mw,w=u+2*mw,D=i*1.2;let S=SV(m,w,XQ);iJ(S)&&(S=S.reverse());const _=A.ofPolygons([S]);n.push(_);let b=e.extrude(_,D,0,0,[1,1],!0);if(n.push(b),C.ccw_rotation){const rA=b.rotate([0,0,C.ccw_rotation]);n.push(rA),b=rA}const R=b.translate([C.x,C.y,0]);n.push(R),s.push(R);const F=h;let H=SV(d,f,XQ);iJ(H)&&(H=H.reverse());const Y=A.ofPolygons([H]);n.push(Y);const J=e.extrude(Y,F,0,0,[1,1],!0);n.push(J);let O=SV(E,u,XQ);iJ(O)&&(O=O.reverse());const W=A.ofPolygons([O]);n.push(W);const z=e.extrude(W,F*1.05,0,0,[1,1],!0);n.push(z);let tA=J.subtract(z);if(n.push(tA),C.ccw_rotation){const rA=tA.rotate([0,0,C.ccw_rotation]);n.push(rA),tA=rA}const aA=tA.translate([C.x,C.y,0]);n.push(aA);let eA=aA;if(o){const rA=e.intersection([aA,o]);n.push(rA),eA=rA}g.push(eA);const oA=PD(eA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:oA,color:XF})}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 E=C.hole_offset_x||0,u=C.hole_offset_y||0,d=Xet({Manifold:e,x:C.x+E,y:C.y+u,diameter:C.hole_diameter,thickness:i,segments:XQ});n.push(d),s.push(d);const f=C.rect_pad_width??C.hole_diameter,m=C.rect_pad_height??C.hole_diameter,w=ck(C),D=nJ,S=C.hole_diameter/2,_=zF({Manifold:e,width:f,height:m,thickness:Math.max(i-2*(D+oJ+sJ),Tn),borderRadius:w});n.push(_);const b=e.cylinder(i*.8,S,S,XQ,!0).translate([E,u,0]);n.push(b);const R=e.union([_,b]);n.push(R);const F=e.cylinder(i*1.2,Math.max(S-Tn,.01),Math.max(S-Tn,.01),XQ,!0).translate([E,u,0]);n.push(F);const H=R.subtract(F);n.push(H);const Y=H.translate([C.x,C.y,0]);n.push(Y);let J=Y;if(o){const W=e.intersection([Y,o]);n.push(W),J=W}g.push(J);const O=PD(J.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:O,color:XF})}});let B;return g.length>0&&(B=e.union(g),n.push(B)),{platedHoleBoardDrills:s,platedHoleCopperGeoms:a,platedHoleSubtractOp:B}}function G1e({Manifold:e,x:A,y:t,outerDiameter:i,holeDiameter:n,thickness:o,zOffset:s=.001,segments:r=32}){const a=s;if(i<n)throw new Error(`Invalid via geometry: outerDiameter (${i}) must be >= holeDiameter (${n})`);const g=Math.min(i/2,n/2+a),I=e.cylinder(o,g,-1,r,!0),l=o+2*s,B=e.cylinder(l,n/2,-1,r,!0);return I.subtract(B).translate([A,t,0])}var R1e=new An(..._a.copper);function N1e(e,A,t,i,n){const o=[],s=yn(A).pcb_via.list(),r=[];return s.forEach((a,g)=>{if(typeof a.hole_diameter=="number"){const c=$et({Manifold:e,x:a.x,y:a.y,holeDiameter:a.hole_diameter,thickness:t,zOffset:mw,segments:XQ});i.push(c),o.push(c)}if(typeof a.outer_diameter=="number"&&typeof a.hole_diameter=="number"){const c=G1e({Manifold:e,x:a.x,y:a.y,outerDiameter:a.outer_diameter,holeDiameter:a.hole_diameter,thickness:t,zOffset:mw,segments:XQ});i.push(c);let I=c;if(n){const B=e.intersection([c,n]);i.push(B),I=B}const l=PD(I.getMesh());r.push({key:`via-${a.pcb_via_id||g}`,geometry:l,color:R1e})}}),{viaBoardDrills:o,viaCopperGeoms:r}}var L1e=(e,A,t)=>{const[i,n]=AA.useState(null),[o,s]=AA.useState(null),[r,a]=AA.useState(null),[g,c]=AA.useState(!0),I=AA.useRef([]),l=AA.useMemo(()=>{const h=A.filter(d=>d.type==="pcb_panel"),E=yn(A).pcb_board.list();if(h.length>0){const d=h[0],f=E.find(m=>m.pcb_panel_id===d.pcb_panel_id);return{type:"pcb_board",pcb_board_id:d.pcb_panel_id,center:d.center,width:d.width,height:d.height,thickness:f?.thickness??1.4,material:f?.material??"fr4",num_layers:f?.num_layers??2}}const u=E.filter(d=>!d.pcb_panel_id);return u.length>0?u[0]:null},[A]),B=AA.useMemo(()=>{const h=yn(A).pcb_board.list();return h.length>0&&h[0].pcb_board_id==="faux-board"},[A]),C=AA.useMemo(()=>l?jet(l,ww):ww,[l]);AA.useEffect(()=>{if(!e||!l){n(null),s(null),c(!1);return}if((l.width===0||!l.width)&&(l.height===0||!l.height)&&(!l.outline||l.outline.length<3)){n({platedHoles:[],vias:[]}),s(l.thickness??0),c(!1);return}c(!0),a(null);const h=e.Manifold,E=e.CrossSection,u=m=>{if(!(!m||typeof m.delete!="function"))try{m.delete()}catch(w){(!(w instanceof Error)||!w.message?.includes("Manifold instance already deleted"))&&console.warn("Failed to delete Manifold instance",w)}};I.current.forEach(u),I.current=[];let d=null;const f={};try{const m=l.thickness||1.4;s(m);const{boardOp:w,outlineCrossSection:D}=x1e(h,E,l,m,I.current);let S=w;const b=m+2*1;let R=null;const F=.01;if(D){let oA=D;if(F>0){const BA=D.offset(F);I.current.push(BA),oA=BA}const rA=h.extrude(oA,b,void 0,void 0,void 0,!0);I.current.push(rA),R=rA}else{const oA=(l.width||0)+2*F,rA=(l.height||0)+2*F,BA=h.cube([oA,rA,b],!0);I.current.push(BA);const pA=BA.translate([l.center.x,l.center.y,0]);I.current.push(pA),R=pA}const H=[];let Y=null;const{nonPlatedHoleBoardDrills:J}=F1e(h,E,A,m,I.current);H.push(...J);const{platedHoleBoardDrills:O,platedHoleCopperGeoms:W,platedHoleSubtractOp:z}=M1e(h,E,A,m,I.current,R);H.push(...O),f.platedHoles=W;const{viaBoardDrills:tA,viaCopperGeoms:aA}=N1e(h,A,m,I.current,R);if(H.push(...tA),f.vias=aA,H.length>0){Y=h.union(H),I.current.push(Y);const oA=z?h.union([Y,z]):Y;I.current.push(oA);const rA=S.subtract(oA);if(I.current.push(rA),S=rA,z){const BA=z.subtract(Y);I.current.push(BA);const pA=BA.getMesh(),_A=PD(pA);f.platedHoles=[{key:"plated-holes-union",geometry:_A,color:new An(_a.copper[0],_a.copper[1],_a.copper[2])}]}}const{cutoutOps:eA}=v1e(h,E,A,m,I.current);if(eA.length>0){const oA=h.union(eA);I.current.push(oA);const rA=S.subtract(oA);I.current.push(rA),S=rA}if(d=S,d){const oA=d.getMesh(),rA=PD(oA),BA=ydA[l.material]??_a.fr4Tan;f.board={geometry:rA,color:new An(BA[0],BA[1],BA[2]),material:l.material,isFaux:B}}n(f)}catch(m){console.error("Error processing geometry with Manifold in hook:",m),a(m.message||"An unknown error occurred while processing geometry in hook."),n(null)}finally{c(!1)}return()=>{I.current.forEach(u),I.current=[]}},[e,A,l]);const Q=AA.useMemo(()=>!l||!C?null:Zet({circuitJson:A,boardData:l,traceTextureResolution:C,visibility:t}),[A,l,C,t]);return{geoms:i,textures:Q,pcbThickness:o,error:r,isLoading:g,boardData:l,isFauxBoard:B}},U1e=YQ,H1e=({material:e,color:A,side:t=U1e,isFaux:i=!1})=>e==="fr4"?new rw({color:A,side:t,metalness:0,roughness:.8,specularIntensity:.2,ior:1.45,sheen:0,clearcoat:0,transparent:i,opacity:i?dV:1,flatShading:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}):new TE({color:A,side:t,flatShading:!0,metalness:.1,roughness:.8,transparent:!0,opacity:i?dV:.9,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});function Y1e(e){const A=[];if(!e)return A;if(e.board&&e.board.geometry){const i=new Io(e.board.geometry,H1e({material:e.board.material,color:e.board.color,side:YQ,isFaux:e.board.isFaux}));i.name="board-geom",A.push(i)}const t=i=>{i&&i.forEach(n=>{const o=new Io(n.geometry,new TE({color:n.color,side:YQ,flatShading:!0}));o.name=n.key,A.push(o)})};return t(e.platedHoles),t(e.vias),A}var J1e=({geometryMeshes:e,textureMeshes:A})=>{const{rootObject:t}=nd(),{visibility:i}=OF(),n=o=>{o.geometry.dispose();const s=Array.isArray(o.material)?o.material:[o.material];for(const r of s){if(!r)continue;const a=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],g=r;for(const c of a){const I=g[c];I&&I instanceof $c&&(I.dispose(),g[c]=null)}r.dispose()}};return AA.useEffect(()=>{if(t)return e.forEach(o=>{let s=!0;o.name==="board-geom"?s=i.boardBody:(o.name.includes("plated_hole")||o.name.includes("via"))&&(s=i.topCopper||i.bottomCopper),s&&t.add(o)}),()=>{e.forEach(o=>{o.parent===t&&t.remove(o),n(o)})}},[t,e,i]),AA.useEffect(()=>{if(t)return A.forEach(o=>{t.add(o)}),()=>{A.forEach(o=>{o.parent===t&&t.remove(o),n(o)})}},[t,A]),null},T1e="https://cdn.jsdelivr.net/npm/manifold-3d@3.2.1",P1e=({circuitJson:e,autoRotateDisabled:A,clickToInteractEnabled:t,onUserInteraction:i,children:n,onCameraControllerReady:o,resolveStaticAsset:s})=>{const r=Uet(n),a=AA.useMemo(()=>zet(e??r),[e,r]),[g,c]=AA.useState(null),[I,l]=AA.useState(null),{visibility:B}=OF();AA.useEffect(()=>{if(window.ManifoldModule&&typeof window.ManifoldModule=="object"&&window.ManifoldModule.setup){c(window.ManifoldModule);return}const R=async W=>{try{const z=await W();z.setup(),window.ManifoldModule=z,c(z)}catch(z){console.error("Failed to initialize Manifold:",z),l(`Failed to initialize Manifold: ${z instanceof Error?z.message:"Unknown error"}`)}},F=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(F){window.ManifoldModule=F,R(window.ManifoldModule);return}const H="manifoldLoaded",Y=()=>{const W=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(W)window.ManifoldModule=W,R(window.ManifoldModule);else{const z="ManifoldModule not found on window after script load.";console.error(z),l(z)}};window.addEventListener(H,Y,{once:!0});const J=document.createElement("script");J.type="module",J.innerHTML=`
|
|
5187
5187
|
try {
|
|
5188
5188
|
const { default: ManifoldModule } = await import('${T1e}/manifold.js');
|
|
5189
5189
|
window.ManifoldModule = ManifoldModule;
|
|
@@ -5685,7 +5685,7 @@ test("${g} should solve problem correctly", () => {
|
|
|
5685
5685
|
// Add more specific assertions based on expected output
|
|
5686
5686
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5687
5687
|
})
|
|
5688
|
-
`,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 ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:n,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.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:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},zQt=e=>e.activeSubSolver?[e,...zQt(e.activeSubSolver)]:[e],Qti=({solver:e})=>{const A=zQt(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx(Cti,{solver:t})]},t.constructor.name))})},hti=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(Q=>!Q,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),n&&n(e))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&e.solved&&n(e);return}e.step(),A()},t))},I=()=>{const Q=e;if(Q.getCurrentPhase&&!e.solved&&!e.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const Q=window.prompt("Step until which iteration?",`${e.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(;e.iterations<h&&!e.solved&&!e.failed;)e.step();A(),e.solved&&n&&n(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,o]);const B=e.getCurrentPhase!==void 0,C=B?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(Qti,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Z.jsx("button",{onClick:c,disabled:e.solved||e.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),Z.jsx("button",{onClick:l,disabled:e.solved||e.failed||o,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&&Z.jsx("button",{onClick:I,disabled:e.solved||e.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},Eti=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},uti=(e,A)=>{const i=e.pipelineDef[A].solverName,n=Eti(e,A),o=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(n==="Completed"){const l=e.pipelineDef[A+1],B=l?e.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},dti=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},pti=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},fti=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),yti=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=fti(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>Z.jsxs("div",{children:[i,": ",String(n)]},i))})]})},DyA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(DyA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=DyA(i));return A},mti=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=DyA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},wti=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>uti(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):mti(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.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"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(dti,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(pti,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(yti,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.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"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},Dti=class extends Qn.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function Sti({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],n=e.circles??[],o=e.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 t){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 n){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 o)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 Z.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)=>Z.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}`)),t.map((h,E)=>Z.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}`)),n.map((h,E)=>Z.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)=>Z.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>Z.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var bti=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=AA.useReducer(c=>c+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.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=e.pipelineDef!==void 0,g=c=>{const I=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)e.step();o()}};return Z.jsxs("div",{children:[Z.jsx(hti,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(Dti,{fallback:Z.jsx(Sti,{graphics:s}),children:Z.jsx(Bti,{graphics:s})}),a&&Z.jsx(wti,{solver:e,onStepUntilPhase:g})]})};const xti=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},_ti=e=>e.toLowerCase().includes("pack")?nTe:e.toLowerCase().includes("rout")?cTe:VJe,kti=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);xti();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=AA.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=AA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=ZgA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(ZgA).join(", ")}`,classFound:!1};try{const a=o.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}}},[o]);return e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.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."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.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:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return Z.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:()=>t(r),children:(()=>{const c=_ti(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?Z.jsx(jD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:Z.jsx(bti,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&Z.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:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},XQt=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{lq.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{lq.captureException(n,{error_type:i.type})}catch{}}},[t])},$Qt="0.0.1737",vti={version:$Qt},SyA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},byA=new Map,$j=e=>{const A=byA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},Fti=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=byA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return byA.set(t.name,n),{type:"tracked",store:e,...n}},Aht=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(SyA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(SyA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:c,...I}=Fti(r,g,a);let l=!0;n.setState=(Q,h,E)=>{const u=t(Q,h);if(!l)return u;const d=E===void 0?{type:s||"anonymous"}:typeof E=="string"?{type:E}:E;return r===void 0?(c?.send(d,i()),u):(c?.send({...d,type:`${r}/${d.type}`},{...$j(a.name),[r]:n.getState()}),u)};const B=(...Q)=>{const h=l;l=!1,t(...Q),l=h},C=e(n.setState,i,n);if(I.type==="untracked"?c?.init(C):(I.stores[I.store]=n,c?.init(Object.fromEntries(Object.entries(I.stores).map(([Q,h])=>[Q,Q===I.store?C:h.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let Q=!1;const h=n.dispatch;n.dispatch=(...E)=>{(SyA?"production":void 0)!=="production"&&E[0].type==="__setState"&&!Q&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),Q=!0),h(...E)}}return c.subscribe(Q=>{var h;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return xyA(Q.payload,E=>{if(E.type==="__setState"){if(r===void 0){B(E.state);return}Object.keys(E.state).length!==1&&console.error(`
|
|
5688
|
+
`,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 ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:n,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.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:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},zQt=e=>e.activeSubSolver?[e,...zQt(e.activeSubSolver)]:[e],Qti=({solver:e})=>{const A=zQt(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx(Cti,{solver:t})]},t.constructor.name))})},hti=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(Q=>!Q,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),n&&n(e))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&e.solved&&n(e);return}e.step(),A()},t))},I=()=>{const Q=e;if(Q.getCurrentPhase&&!e.solved&&!e.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const Q=window.prompt("Step until which iteration?",`${e.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(;e.iterations<h&&!e.solved&&!e.failed;)e.step();A(),e.solved&&n&&n(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,o]);const B=e.getCurrentPhase!==void 0,C=B?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(Qti,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Z.jsx("button",{onClick:c,disabled:e.solved||e.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),Z.jsx("button",{onClick:l,disabled:e.solved||e.failed||o,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&&Z.jsx("button",{onClick:I,disabled:e.solved||e.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},Eti=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},uti=(e,A)=>{const i=e.pipelineDef[A].solverName,n=Eti(e,A),o=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(n==="Completed"){const l=e.pipelineDef[A+1],B=l?e.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},dti=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},pti=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},fti=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),yti=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=fti(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>Z.jsxs("div",{children:[i,": ",String(n)]},i))})]})},DyA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(DyA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=DyA(i));return A},mti=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=DyA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},wti=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>uti(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):mti(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.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"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(dti,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(pti,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(yti,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.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"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},Dti=class extends Qn.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function Sti({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],n=e.circles??[],o=e.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 t){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 n){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 o)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 Z.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)=>Z.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}`)),t.map((h,E)=>Z.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}`)),n.map((h,E)=>Z.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)=>Z.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>Z.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var bti=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=AA.useReducer(c=>c+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.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=e.pipelineDef!==void 0,g=c=>{const I=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)e.step();o()}};return Z.jsxs("div",{children:[Z.jsx(hti,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(Dti,{fallback:Z.jsx(Sti,{graphics:s}),children:Z.jsx(Bti,{graphics:s})}),a&&Z.jsx(wti,{solver:e,onStepUntilPhase:g})]})};const xti=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},_ti=e=>e.toLowerCase().includes("pack")?nTe:e.toLowerCase().includes("rout")?cTe:VJe,kti=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);xti();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=AA.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=AA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=ZgA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(ZgA).join(", ")}`,classFound:!1};try{const a=o.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}}},[o]);return e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.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."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.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:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return Z.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:()=>t(r),children:(()=>{const c=_ti(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?Z.jsx(jD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:Z.jsx(bti,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&Z.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:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},XQt=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{lq.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{lq.captureException(n,{error_type:i.type})}catch{}}},[t])},$Qt="0.0.1738",vti={version:$Qt},SyA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},byA=new Map,$j=e=>{const A=byA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},Fti=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=byA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return byA.set(t.name,n),{type:"tracked",store:e,...n}},Aht=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(SyA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(SyA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:c,...I}=Fti(r,g,a);let l=!0;n.setState=(Q,h,E)=>{const u=t(Q,h);if(!l)return u;const d=E===void 0?{type:s||"anonymous"}:typeof E=="string"?{type:E}:E;return r===void 0?(c?.send(d,i()),u):(c?.send({...d,type:`${r}/${d.type}`},{...$j(a.name),[r]:n.getState()}),u)};const B=(...Q)=>{const h=l;l=!1,t(...Q),l=h},C=e(n.setState,i,n);if(I.type==="untracked"?c?.init(C):(I.stores[I.store]=n,c?.init(Object.fromEntries(Object.entries(I.stores).map(([Q,h])=>[Q,Q===I.store?C:h.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let Q=!1;const h=n.dispatch;n.dispatch=(...E)=>{(SyA?"production":void 0)!=="production"&&E[0].type==="__setState"&&!Q&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),Q=!0),h(...E)}}return c.subscribe(Q=>{var h;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return xyA(Q.payload,E=>{if(E.type==="__setState"){if(r===void 0){B(E.state);return}Object.keys(E.state).length!==1&&console.error(`
|
|
5689
5689
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
5690
5690
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
5691
5691
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|