@tscircuit/runframe 0.0.1571 → 0.0.1572

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.
@@ -5135,7 +5135,7 @@ ${a.join(`
5135
5135
  ${Q}polygon: ${C.polygon.vertices}
5136
5136
  `:a+=`
5137
5137
  `,C.children.length>0&&c.push(C.children)}return a}};A.exports=s}}),Npt=se({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(t,A){var e=Fpt(),i=Mpt(),n=class{constructor(o){this.polygonTree=new i,this.rootnode=new e(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}}),zhA=se({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(t,A){A.exports={Tree:Npt()}}}),vpt=se({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(t,A){var e=jo(),i=jhA(),{Tree:n}=zhA(),o=(s,r)=>{if(!i(s,r))return e.create();const a=new n(e.toPolygons(s)),g=new n(e.toPolygons(r));a.invert(),g.clipTo(a),g.invert(),a.clipTo(g),g.clipTo(a),a.addPolygons(g.allPolygons()),a.invert();const c=a.allPolygons();return e.create(c)};A.exports=o}}),vXA=se({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(t,A){var e=vo(),i=hH(),n=vpt(),o=(...s)=>{s=e(s);let r=s.shift();return s.forEach(a=>{r=n(r,a)}),r=i(r),r};A.exports=o}}),Lpt=se({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(t,A){var e=vo(),i=jo(),n=C_(),o=ZhA(),s=VhA(),r=vXA(),a=(...g)=>{g=e(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}}),Upt=se({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(t,A){var e=vo(),i=QH(),n=Vo(),o=jo(),s=Lpt(),r=vXA(),a=(...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only intersect of the types are supported");const c=g[0];return n.isA(c)?s(g):o.isA(c)?r(g):c};A.exports=a}}),Hpt=se({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(t,A){var e=mn(),i=C_(),n=jo(),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=e.create();I.forEach((d,p)=>{d.vertices.forEach(m=>{s(B,e.snap(C,m,c),p)})});const Q=I.map(d=>{let p=[];return d.vertices.forEach(m=>{p=p.concat(r(B,e.snap(C,m,c)))}),{e:1,d:o(p)}});B.clear();let h=0;const E=Q.length;for(let d=0;d<E;d++){const p=Q[d];if(p.e>0){const m=new Array(l);m[d]=!0;do h=0,m.forEach((D,w)=>{const S=Q[w];if(S.e>0){S.e=-1;for(let k=0;k<S.d.length;k++)m[S.d[k]]=!0;h++}});while(h>0);p.indexes=m}}const u=[];for(let d=0;d<E;d++)if(Q[d].indexes){const p=[];Q[d].indexes.forEach((m,D)=>p.push(I[D])),u.push(n.create(p))}return u};A.exports=a}}),Ypt=se({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(t,A){var e=vo(),i=jo(),n=Hpt(),o=(...s)=>{if(s=e(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}}),Jpt=se({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(t,A){var e=jo(),i=jhA(),{Tree:n}=zhA(),o=(s,r)=>{if(!i(s,r))return e.clone(s);const a=new n(e.toPolygons(s)),g=new n(e.toPolygons(r));a.invert(),a.clipTo(g),g.clipTo(a,!0),a.addPolygons(g.allPolygons()),a.invert();const c=a.allPolygons();return e.create(c)};A.exports=o}}),LXA=se({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(t,A){var e=vo(),i=hH(),n=Jpt(),o=(...s)=>{s=e(s);let r=s.shift();return s.forEach(a=>{r=n(r,a)}),r=i(r),r};A.exports=o}}),Tpt=se({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(t,A){var e=vo(),i=jo(),n=C_(),o=ZhA(),s=VhA(),r=LXA(),a=(...g)=>{g=e(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}}),Kpt=se({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(t,A){var e=vo(),i=QH(),n=Vo(),o=jo(),s=Tpt(),r=LXA(),a=(...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only subtract of the types are supported");const c=g[0];return n.isA(c)?s(g):o.isA(c)?r(g):c};A.exports=a}}),UXA=se({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(t,A){var e=jo(),i=jhA(),{Tree:n}=zhA(),o=(r,a)=>{if(!i(r,a))return s(r,a);const g=new n(e.toPolygons(r)),c=new n(e.toPolygons(a));g.clipTo(c,!1),c.clipTo(g),c.invert(),c.clipTo(g),c.invert();const I=g.allPolygons().concat(c.allPolygons());return e.create(I)},s=(r,a)=>{let g=e.toPolygons(r);return g=g.concat(e.toPolygons(a)),e.create(g)};A.exports=o}}),HXA=se({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(t,A){var e=vo(),i=hH(),n=UXA(),o=(...s)=>{s=e(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}}),YXA=se({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(t,A){var e=vo(),i=jo(),n=C_(),o=ZhA(),s=VhA(),r=HXA(),a=(...g)=>{g=e(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}}),XhA=se({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(t,A){var e=vo(),i=QH(),n=Vo(),o=jo(),s=YXA(),r=HXA(),a=(...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only unions of the same type are supported");const c=g[0];return n.isA(c)?s(g):o.isA(c)?r(g):c};A.exports=a}}),XN=se({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(t,A){A.exports={intersect:Upt(),scission:Ypt(),subtract:Kpt(),union:XhA()}}}),_W=se({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(t,A){var{EPS:e,TAU:i}=pr(),n=QXA(),o=ThA(),s=ps(),r=SW(),a=(g,c)=>{const I={delta:1,corners:"edge",closed:!1,segments:16};let{delta:l,corners:B,closed:C,segments:Q}=Object.assign({},I,g);if(Math.abs(l)<e)return c;let h=g.closed?r(c):1;h===0&&(h=1);const E=h>0&&l>=0||h<0&&l<0;l=Math.abs(l);let u=null,d=[];const p=[],m=s.create(),D=c.length;for(let w=0;w<D;w++){const S=(w+1)%D,k=c[w],x=c[S];E?s.subtract(m,k,x):s.subtract(m,x,k),s.normal(m,m),s.normalize(m,m),s.scale(m,m,l);const N=s.add(s.create(),k,m),M=s.add(s.create(),x,m),L=[N,M];if(u!=null&&(C||!C&&S!==0)){const Y=n(u[0],u[1],L[0],L[1]);Y?(d.pop(),L[0]=Y):p.push({c:k,s0:u,s1:L})}u=[N,M],!(S===0&&!C)&&(d.push(L[0]),d.push(L[1]))}if(C&&u!=null){const w=d[0],S=d[1],k=n(u[0],u[1],w,S);if(k)d[0]=k,d.pop();else{const x=c[0],N=[w,S];p.push({c:x,s0:u,s1:N})}}if(B==="edge"){const w=new Map;d.forEach((x,N)=>w.set(x,N));const S=o.create(),k=o.create();p.forEach(x=>{o.fromPoints(S,x.s0[0],x.s0[1]),o.fromPoints(k,x.s1[0],x.s1[1]);const N=o.intersectPointOfLines(S,k);if(Number.isFinite(N[0])&&Number.isFinite(N[1])){const M=x.s0[1],L=w.get(M);d[L]=N,d[(L+1)%d.length]=void 0}else{const M=x.s1[0],L=w.get(M);d[L]=void 0}}),d=d.filter(x=>x!==void 0)}if(B==="round"){let w=Math.floor(Q/4);const S=s.create();p.forEach(k=>{let x=s.angle(s.subtract(S,k.s1[0],k.c));if(x-=s.angle(s.subtract(S,k.s0[1],k.c)),E&&x<0&&(x=x+Math.PI,x<0&&(x=x+Math.PI)),!E&&x>0&&(x=x-Math.PI,x>0&&(x=x-Math.PI)),x!==0){w=Math.floor(Q*(Math.abs(x)/i));const N=x/w,M=s.angle(s.subtract(S,k.s0[1],k.c)),L=[];for(let Y=1;Y<w;Y++){const H=M+N*Y,O=s.fromAngleRadians(s.create(),H);s.scale(O,O,l),s.add(O,O,k.c),L.push(O)}if(L.length>0){const Y=k.s0[1];let H=d.findIndex(O=>s.equals(Y,O));H=(H+1)%d.length,d.splice(H,0,...L)}}else{const N=k.s1[0],M=d.findIndex(L=>s.equals(N,L));d.splice(M,1)}})}return d};A.exports=a}}),Ppt=se({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(t,A){var e=Vo(),i=_W(),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=e.toOutlines(s).map(C=>(o={delta:a,corners:g,closed:!0,segments:c},i(o,C))).reduce((C,Q)=>C.concat(e.toSides(e.fromPoints(Q))),[]);return e.create(B)};A.exports=n}}),qpt=se({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(t,A){var e=Wg(),i=mn(),n=jo(),o=nr(),s=(r,a)=>{i.dot(o.plane(a),r)>0&&(a=o.invert(a));const c=[a],I=o.transform(e.fromTranslation(e.create(),r),a),l=a.vertices.length;for(let B=0;B<l;B++){const C=B<l-1?B+1:0,Q=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}}),Opt=se({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(t,A){var{EPS:e,TAU:i}=pr(),n=Wg(),o=mn(),s=MXA(),r=jo(),a=nr(),g=bXA(),c=hH(),I=UXA(),l=qpt(),B=(E,u,d)=>{const p=u.toString();if(E.has(p))E.get(p)[1].push(d);else{const m=[u,[d]];E.set(p,m)}},C=(E,u,d)=>{const p=u[0].toString(),m=u[1].toString(),D=p<m?`${p},${m}`:`${m},${p}`;if(E.has(D))E.get(D)[1].push(d);else{const w=[u,[d]];E.set(D,w)}},Q=(E,u)=>{E.findIndex(p=>p===u)<0&&E.push(u)},h=(E,u)=>{const d={delta:1,segments:12},{delta:p,segments:m}=Object.assign({},d,E);let D=r.create();const w=new Map,S=new Map,k=o.create(),x=o.create();return r.toPolygons(u).forEach((M,L)=>{const Y=o.scale(o.create(),a.plane(M),2*p),H=a.transform(n.fromTranslation(n.create(),o.scale(o.create(),Y,-.5)),M),O=l(Y,H);D=I(D,O);const Z=M.vertices;for(let $=0;$<Z.length;$++){B(w,Z[$],a.plane(M));const tA=($+1)%Z.length,aA=[Z[$],Z[tA]];C(S,aA,a.plane(M))}}),S.forEach(M=>{const L=M[0],Y=M[1],H=L[0],O=L[1],Z=o.subtract(o.create(),O,H);o.normalize(Z,Z);const $=Y[0],tA=o.cross(o.create(),$,Z);let aA=[];for(let YA=0;YA<m;YA++)Q(aA,YA*i/m);for(let YA=0,QA=Y.length;YA<QA;YA++){const _A=Y[YA],dA=o.dot(tA,_A),KA=o.dot($,_A);let JA=Math.atan2(dA,KA);JA<0&&(JA+=i),Q(aA,JA),JA=Math.atan2(-dA,-KA),JA<0&&(JA+=i),Q(aA,JA)}aA=aA.sort(s);const eA=aA.length;let nA,rA;const lA=[],fA=[],xA=[];for(let YA=-1;YA<eA;YA++){const QA=aA[YA<0?YA+eA:YA],_A=Math.sin(QA),dA=Math.cos(QA);o.scale(k,$,dA*p),o.scale(x,tA,_A*p),o.add(k,k,x);const KA=o.add(o.create(),H,k),JA=o.add(o.create(),O,k);let ie=!1;if(YA>=0&&o.distance(KA,nA)<e&&(ie=!0),!ie){if(YA>=0){lA.push(KA),fA.push(JA);const pA=[rA,JA,KA,nA],Ae=a.create(pA);xA.push(Ae)}nA=KA,rA=JA}}fA.reverse(),xA.push(a.create(lA)),xA.push(a.create(fA));const RA=r.create(xA);D=I(D,RA)}),w.forEach(M=>{const L=M[0],Y=M[1],H=Y[0];let O=null,Z=0;for(let eA=1;eA<Y.length;eA++){const nA=Y[eA],rA=o.cross(k,H,nA),lA=o.length(rA);lA>.05&&lA>Z&&(Z=lA,O=nA)}O||(O=o.orthogonal(k,H));const $=o.cross(k,H,O);o.normalize($,$);const tA=o.cross(x,$,H),aA=g({center:[L[0],L[1],L[2]],radius:p,segments:m,axes:[H,$,tA]});D=I(D,aA)}),c(D)};A.exports=h}}),Wpt=se({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(t,A){var e=jo(),i=XhA(),n=Opt(),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(e.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}}),Zpt=se({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(t,A){var e=SW(),i=ps(),n=Vo(),o=bg(),s=_W(),r=c=>{let{external:I,internal:l}=c;e(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,D=C[C.length-1],w=i.angle(i.subtract(i.create(),Q[Q.length-1],D)),S=C[0],k=i.angle(i.subtract(i.create(),h[0],S));for(let x=1;x<E;x++){let N=w+m*x,M=i.fromAngleRadians(i.create(),N);i.scale(M,M,B),i.add(M,M,D),u.push(M),N=k+m*x,M=i.fromAngleRadians(i.create(),N),i.scale(M,M,B),i.add(M,M,S),d.push(M)}}const p=[];return p.push(...Q,...u,...h.reverse(),...d),n.fromPoints(p)},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}}),$hA=se({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(t,A){var e=vo(),i=Vo(),n=jo(),o=bg(),s=Ppt(),r=Wpt(),a=Zpt(),g=(c,...I)=>{if(I=e(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}}),Vpt=se({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(t,A){var e=Vo(),i=LhA(),n=_W(),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=e.toOutlines(r),C=l.map(Q=>(s={delta:l.reduce((u,d)=>u+i.arePointsInside(Q,i.create(d)),0)%2===0?g:-g,corners:c,closed:!0,segments:I},n(s,Q))).reduce((Q,h)=>Q.concat(e.toSides(e.fromPoints(h))),[]);return e.create(C)};A.exports=o}}),jpt=se({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(t,A){var e=bg(),i=_W(),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,e.toPoints(s));return e.fromPoints({closed:c},l)};A.exports=n}}),zpt=se({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(t,A){var e=vo(),i=Vo(),n=bg(),o=Vpt(),s=jpt(),r=(a,...g)=>{if(g=e(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}}),JXA=se({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(t,A){A.exports={expand:$hA(),offset:zpt()}}}),kW=se({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(t,A){var e=Wg(),i=mn(),n=Vo(),o=zN(),s=xW(),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=e.create(),d=(p,m,D)=>{const w=m/B*l,S=i.scale(i.create(),Q,m/B);return e.multiply(u,e.fromZRotation(u,w),e.fromTranslation(e.create(),S)),o.transform(u,D)};return a={numberOfSlices:B+1,capStart:!0,capEnd:!0,repair:C,callback:d},s(a,E)};A.exports=r}}),Xpt=se({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(t,A){var e=Vo(),i=bg(),n=kW(),o=(s,r)=>{if(!r.isClosed)throw new Error("extruded path must be closed");const a=i.toPoints(r),g=e.fromPoints(a);return n(s,g)};A.exports=o}}),$pt=se({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(t,A){var e=vo(),i=Vo(),n=bg(),o=kW(),s=Xpt(),r=(a,...g)=>{const c={height:1,twistAngle:0,twistSteps:1,repair:!0},{height:I,twistAngle:l,twistSteps:B,repair:C}=Object.assign({},c,a);if(g=e(g),g.length===0)throw new Error("wrong number of arguments");a={offset:[0,0,I],twistAngle:l,twistSteps:B,repair:C};const Q=g.map(h=>n.isA(h)?s(a,h):i.isA(h)?o(a,h):h);return Q.length===1?Q[0]:Q};A.exports=r}}),Aft=se({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(t,A){var e=bg(),i=$hA(),n=kW(),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],e.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}}),eft=se({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(t,A){var{area:e}=IH(),i=Vo(),n=bg(),o=$hA(),s=kW(),r=(a,g)=>{const c={size:1,height:1},{size:I,height:l}=Object.assign({},c,a);a.delta=I,a.offset=[0,0,l];const B=i.toOutlines(g);if(B.length===0)throw new Error("the given geometry cannot be empty");const Q=B.map(E=>(e(E)<0&&E.reverse(),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}}),tft=se({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(t,A){var e=vo(),i=Vo(),n=bg(),o=Aft(),s=eft(),r=(a,...g)=>{const c={size:1,height:1},{size:I,height:l}=Object.assign({},c,a);if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(I<=0)throw new Error("size must be positive");if(l<=0)throw new Error("height must be positive");const B=g.map(C=>n.isA(C)?o(a,C):i.isA(C)?s(a,C):C);return B.length===1?B[0]:B};A.exports=r}}),ift=se({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(t,A){var{TAU:e}=pr(),i=Wg(),n=Vo(),o=xW(),s=zN(),r=(a,g)=>{const c={angle:e,startAngle:0,pitch:10,height:0,endOffset:0,segmentsPerRotation:32};let{angle:I,startAngle:l,pitch:B,height:C,endOffset:Q,segmentsPerRotation:h}=Object.assign({},c,a);if(C!=0&&(B=C/(I/e)),h<3)throw new Error("The number of segments per rotation needs to be at least 3.");const u=n.toSides(g);if(u.length===0)throw new Error("The given geometry cannot be empty");const d=u.filter(x=>x[0][0]>=0);let p=s.fromSides(u);d.length===0&&(p=s.reverse(p));const m=Math.round(h/e*Math.abs(I)),D=m>=2?m:2,w=i.create(),S=i.create(),k=(x,N,M)=>{const L=l+I/D*N,Y=Q/D*N,H=(L-l)/e*B;return i.multiply(w,i.fromTranslation(i.create(),[Y,0,H*Math.sign(I)]),i.fromXRotation(i.create(),-e/4*Math.sign(I))),i.multiply(S,i.fromZRotation(i.create(),L),w),s.transform(S,M)};return o({numberOfSlices:D+1,callback:k},p)};A.exports=r}}),nft=se({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(t,A){var e=vo(),i=JhA(),n=ID(),o=Wg(),s=Vo(),r=jo(),a=nr(),g=C_(),c=YXA(),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 D=u[m].vertices.map(k=>n.projectionOfPoint(Q,k)),w=a.create(D),S=a.plane(w);i(Q,S)&&(a.measureArea(w)<E||d.push(w))}if(!i(Q,[0,0,1])){const m=o.fromVectorRotation(o.create(),Q,[0,0,1]);d=d.map(D=>a.transform(m,D))}d=d.sort((m,D)=>a.measureArea(D)-a.measureArea(m));const p=d.map(m=>s.fromPoints(m.vertices));return c(p)},l=(B,...C)=>{const Q={axis:[0,0,1],origin:[0,0,0]},{axis:h,origin:E}=Object.assign({},Q,B);if(C=e(C),C.length===0)throw new Error("wrong number of arguments");B={axis:h,origin:E};const u=C.map(d=>r.isA(d)?I(B,d):d);return u.length===1?u[0]:u};A.exports=l}}),EH=se({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(t,A){A.exports={extrudeFromSlices:xW(),extrudeLinear:$pt(),extrudeRectangular:tft(),extrudeRotate:FXA(),extrudeHelical:ift(),project:nft(),slice:zN()}}}),AEA=se({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(t,A){var e=ps(),i=s=>{let r=e.fromValues(1/0,1/0);s.forEach(c=>{(c[1]<r[1]||c[1]===r[1]&&c[0]<r[0])&&(r=c)});const a=[];s.forEach(c=>{const I=o(c[1]-r[1],c[0]-r[0]),l=e.squaredDistance(c,r);a.push({point:c,angle:I,distSq:l})}),a.sort((c,I)=>c.angle!==I.angle?c.angle-I.angle:c.distSq-I.distSq);const g=[];return a.forEach(c=>{let I=g.length;for(;I>1&&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}}),eEA=se({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(t,A){var e=Vo(),i=jo(),n=bg(),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=>{e.isA(c)?e.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}}),oft=se({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(t,A){var e=vo(),i=bg(),n=AEA(),o=eEA(),s=(...r)=>{r=e(r);const a=o(r),g=n(a);return i.fromPoints({closed:!0},g)};A.exports=s}}),sft=se({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(t,A){var e=vo(),i=Vo(),n=AEA(),o=eEA(),s=(...r)=>{r=e(r);const a=o(r),g=n(a);return g.length<3?i.create():i.fromPoints(g)};A.exports=s}}),TXA=se({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(t,A){var e=nr(),i=YzA(),n=o=>i(o,{skipTriangulation:!0}).map(a=>{const g=a.map(c=>o[c]);return e.create(g)});A.exports=n}}),rft=se({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(t,A){var e=vo(),i=jo(),n=eEA(),o=TXA(),s=(...r)=>{r=e(r);const a=n(r);return a.length===0?i.create():i.create(o(a))};A.exports=s}}),KXA=se({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(t,A){var e=vo(),i=QH(),n=Vo(),o=jo(),s=bg(),r=oft(),a=sft(),g=rft(),c=(...I)=>{if(I=e(I),I.length===0)throw new Error("wrong number of arguments");if(!i(I))throw new Error("only hulls of the same type are supported");const l=I[0];return s.isA(l)?r(I):n.isA(l)?a(I):o.isA(l)?g(I):l};A.exports=c}}),aft=se({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(t,A){var e=vo(),i=XhA(),n=KXA(),o=(...s)=>{if(s=e(s),s.length<2)throw new Error("wrong number of arguments");const r=[];for(let a=1;a<s.length;a++)r.push(n(s[a-1],s[a]));return i(r)};A.exports=o}}),gft=se({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(t,A){A.exports={hull:KXA(),hullChain:aft(),hullPoints2:AEA(),hullPoints3:TXA()}}}),PXA=se({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(t,A){var e=mn(),i=nr(),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=>e.snap(e.create(),C,s)),l=[];for(let C=0;C<I.length;C++){const Q=(C+1)%I.length;e.equals(I[C],I[Q])||l.push(I[C])}const B=i.create(l);return c.color&&(B.color=c.color),B});const g=s*s*Math.sqrt(3)/4;return a=a.filter(c=>n(g,c)),a};A.exports=o}}),cft=se({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(t,A){var e=JhA(),i=mn(),n=nr(),o=E=>{const u=n.toPoints(E),d=[];for(let p=0;p<u.length;p++){const m=(p+1)%u.length,D={v1:u[p],v2:u[m]};d.push(D)}for(let p=0;p<d.length;p++){const m=(p+1)%u.length;d[p].next=d[m],d[m].prev=d[p]}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 p=E.prev.v1,m=E.prev.v2,D=u.next.v2;const w=l(p,m,D,d);p=u.prev.v1,m=u.prev.v2,D=E.next.v2;const S=l(p,m,D,d);return[w,S]},c=i.create(),I=i.create(),l=(E,u,d,p)=>{const m=i.subtract(c,u,E),D=i.subtract(I,d,u);return i.cross(m,m,D),i.dot(m,p)},B=E=>{let u;const d=[];for(;E.next;){const p=E.next;d.push(E.v1),E.v1=null,E.v2=null,E.next=null,E.prev=null,E=p}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(),p=new Map;for(;d.length>0;){const D=d.shift(),w=o(D);for(let S=0;S<w.length;S++){const k=w[S],x=a(p,k);if(x){const N=g(k,x,u);if(N[0]>=0&&N[1]>=0){const M=x.next,L=k.next;k.prev.next=x.next,k.next.prev=x.prev,x.prev.next=k.next,x.next.prev=k.prev,k.v1=null,k.v2=null,k.next=null,k.prev=null,r(p,x),x.v1=null,x.v2=null,x.next=null,x.prev=null;const Y=(H,O,Z)=>{const $={v1:Z.v1,v2:O.v2,next:O.next,prev:Z.prev};Z.prev.next=$,O.next.prev=$,r(H,O),O.v1=null,O.v2=null,O.next=null,O.prev=null,r(H,Z),Z.v1=null,Z.v2=null,Z.next=null,Z.prev=null};N[0]===0&&Y(p,M,M.prev),N[1]===0&&Y(p,L,L.prev)}}else k.next&&s(p,k)}}const m=[];return p.forEach(D=>{const w=B(D);w&&m.push(w)}),p.clear(),m},Q=(E,u)=>Math.abs(E[3]-u[3])<15e-8?e(E,u):!1,h=(E,u)=>{const d=[];u.forEach(m=>{const D=d.find(w=>Q(w[0],n.plane(m)));D?D[1].push(m):d.push([n.plane(m),[m]])});let p=[];return d.forEach(m=>{const D=m[1],w=C(D);p=p.concat(w)}),p};A.exports=h}}),Ift=se({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(t,A){var e=pr(),i=mn(),n=nr(),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 p=0;p<d.length;p++){const m=d[p];let D=o(m.vertex0);if(D===Q&&(D=o(m.vertex1),D===h&&!(C!==null&&m.polygonindex!==C))){u=p;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),p=`${Q}/${d}`,m=`${d}/${Q}`;if(c.has(m)){const D=c.get(m);D.splice(-1,1),D.length===0&&c.delete(m)}else{const D={vertex0:C,vertex1:u,polygonindex:I};c.has(p)?c.get(p).push(D):c.set(p,[D])}C=u,Q=d}}else console.warn("warning: invalid polygon found during insertTjunctions")}if(c.size>0){const I=new Map,l=new Map,B=new Map;for(const[Q,h]of c)B.set(Q,!0),h.forEach(E=>{const u=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 p=c.get(E)[0];for(let m=0;m<2;m++){const D=m===0?p.vertex0:p.vertex1,w=m===0?p.vertex1:p.vertex0,S=o(D),k=o(w);let x=[];m===0?l.has(S)&&(x=l.get(S)):I.has(S)&&(x=I.get(S));for(let N=0;N<x.length;N++){const M=x[N],L=c.get(M)[0],Y=m===0?L.vertex0:L.vertex1;if(m===0?L.vertex1:L.vertex0,o(Y)===k){r(c,I,l,D,w,null),r(c,I,l,w,D,null),u=!1,m=2,Q=!0;break}else{const O=D,Z=w,$=Y,tA=i.subtract(i.create(),$,O),aA=i.dot(i.subtract(i.create(),Z,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,Z)<e.EPS*e.EPS){const rA=L.polygonindex,lA=C[rA],fA=o(L.vertex1);let xA=-1;for(let dA=0;dA<lA.vertices.length;dA++)if(o(lA.vertices[dA])===fA){xA=dA;break}const RA=lA.vertices.slice(0);RA.splice(xA,0,w);const YA=n.create(RA);C[rA]=YA,r(c,I,l,L.vertex0,L.vertex1,rA);const QA=s(c,I,l,L.vertex0,w,rA),_A=s(c,I,l,w,L.vertex1,rA);QA!==null&&B.set(QA,!0),_A!==null&&B.set(_A,!0),u=!1,m=2,Q=!0;break}}}}}}u&&B.delete(E)}if(!Q)break}g=C}return c.clear(),g};A.exports=a}}),lft=se({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(t,A){var e=mn(),i=nr(),n=(s,r,a)=>{const g=r.vertices.length;if(g>3){if(g>4){const l=[0,0,0];r.vertices.forEach(B=>e.add(l,l,B)),e.snap(l,e.divide(l,l,[g,g,g]),s);for(let B=0;B<g;B++){const C=i.create([l,r.vertices[B],r.vertices[(B+1)%g]]);r.color&&(C.color=r.color),a.push(C)}return}const c=i.create([r.vertices[0],r.vertices[1],r.vertices[2]]),I=i.create([r.vertices[0],r.vertices[2],r.vertices[3]]);r.color&&(c.color=r.color,I.color=r.color),a.push(c,I);return}a.push(r)},o=(s,r)=>{const a=[];return r.forEach(g=>{n(s,g,a)}),a};A.exports=o}}),Bft=se({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(t,A){var e=vo(),i=C_(),n=Vo(),o=jo(),s=bg(),r=PXA(),a=cft(),g=Ift(),c=lft(),I=(Q,h)=>h,l=(Q,h)=>h,B=(Q,h)=>{const E={snap:!1,simplify:!1,triangulate:!1},{snap:u,simplify:d,triangulate:p}=Object.assign({},E,Q),m=i(h);let D=o.toPolygons(h);u&&(D=r(m,D)),d&&(D=a(m,D)),p&&(D=g(D),D=c(m,D));const w=Object.assign({},h);return w.polygons=D,w},C=(Q,...h)=>{if(h=e(h),h.length===0)throw new Error("wrong number of arguments");const E=h.map(u=>{if(s.isA(u))return I(Q,u);if(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}}),Cft=se({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(t,A){var e=vo(),i=ps(),n=Vo(),o=jo(),s=bg(),r=C_(),a=PXA(),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=e(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}}),Qft=se({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(t,A){A.exports={generalize:Bft(),snap:Cft(),retessellate:hH()}}}),hft=se({"node_modules/@jscad/modeling/src/utils/padArrayToLength.js"(t,A){var e=(i,n,o)=>{for(i=i.slice();i.length<o;)i.push(n);return i};A.exports=e}}),Eft=se({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(t,A){var e=vo(),i=hft(),n=KhA(),{translate:o}=XF(),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=e(I),I.length===0)throw new Error("align(): No geometries were provided to act upon");if(C.filter(h=>h==null).length){const h=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}}),FW=se({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(t,A){var e=vo(),i=Vo(),n=jo(),o=bg(),s=jF(),{translate:r}=XF(),a=(B,C)=>{const Q={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:h,relativeTo:E}=Object.assign({},Q,B),u=s(C),d=[0,0,0];return h[0]&&(d[0]=E[0]-(u[0][0]+(u[1][0]-u[0][0])/2)),h[1]&&(d[1]=E[1]-(u[0][1]+(u[1][1]-u[0][1])/2)),h[2]&&(d[2]=E[2]-(u[0][2]+(u[1][2]-u[0][2])/2)),r(d,C)},g=(B,...C)=>{const Q={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:h,relativeTo:E}=Object.assign({},Q,B);if(C=e(C),C.length===0)throw new Error("wrong number of arguments");if(E.length!==3)throw new Error("relativeTo must be an array of length 3");B={axes:h,relativeTo:E};const u=C.map(d=>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}}}),GW=se({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(t,A){var e=vo(),i=Wg(),n=Vo(),o=jo(),s=bg(),r=(I,...l)=>{if(!Array.isArray(I))throw new Error("factors must be an array");if(l=e(l),l.length===0)throw new Error("wrong number of arguments");for(I=I.slice();I.length<3;)I.push(1);if(I[0]<=0||I[1]<=0||I[2]<=0)throw new Error("factors must be positive");const B=i.fromScaling(i.create(),I),C=l.map(Q=>s.isA(Q)?s.transform(B,Q):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}}}),uft=se({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(t,A){var e=vo(),i=Vo(),n=jo(),o=bg(),s=(r,...a)=>{if(a=e(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}}),$F=se({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(t,A){A.exports={align:Eft(),center:FW().center,centerX:FW().centerX,centerY:FW().centerY,centerZ:FW().centerZ,mirror:BH().mirror,mirrorX:BH().mirrorX,mirrorY:BH().mirrorY,mirrorZ:BH().mirrorZ,rotate:CH().rotate,rotateX:CH().rotateX,rotateY:CH().rotateY,rotateZ:CH().rotateZ,scale:GW().scale,scaleX:GW().scaleX,scaleY:GW().scaleY,scaleZ:GW().scaleZ,transform:uft(),translate:XF().translate,translateX:XF().translateX,translateY:XF().translateY,translateZ:XF().translateZ}}}),RW=se({"node_modules/@jscad/modeling/src/index.js"(t,A){A.exports={colors:DW(),curves:Cdt(),geometries:UhA(),maths:Hdt(),measurements:Wdt(),primitives:Q_(),text:WhA(),utils:NXA(),booleans:XN(),expansions:JXA(),extrusions:EH(),hulls:gft(),modifiers:Qft(),transforms:$F()}}}),qXA=se({"node_modules/jscad-planner/dist/index.cjs"(t,A){var e=Object.defineProperty,i=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,s=(l,B)=>{for(var C in B)e(l,C,{get:B[C],enumerable:!0})},r=(l,B,C,Q)=>{if(B&&typeof B=="object"||typeof B=="function")for(let h of n(B))!o.call(l,h)&&h!==C&&e(l,h,{get:()=>B[h],enumerable:!(Q=i(B,h))||Q.enumerable});return l},a=l=>r(e({},"__esModule",{value:!0}),l),g={};s(g,{executeJscadOperations:()=>I,jscadPlanner:()=>c}),A.exports=a(g);var c={booleans:{intersect:(...l)=>({type:"intersect",shapes:l}),subtract:(...l)=>({type:"subtract",shapes:l}),union:(...l)=>({type:"union",shapes:l})},hulls:{hull:(...l)=>({type:"hull",shapes:l.flat()}),hullChain:(...l)=>({type:"hullChain",shapes:l.flat()})},colors:{colorize:(l,B)=>({type:"colorize",color:l,shape:B})},primitives:{cube:l=>({type:"cube",...l}),sphere:l=>({type:"sphere",...l}),cylinder:l=>({type:"cylinder",...l}),polygon:l=>({type:"polygon",...l}),cuboid:l=>({type:"cuboid",...l}),roundedCuboid:l=>({type:"roundedCuboid",...l})},transforms:{rotate:(l,B)=>({type:"rotate",angles:l,shape:B}),scale:(l,B)=>({type:"scale",factors:l,shape:B}),translate:(l,B)=>({type:"translate",vector:l,shape:B})},extrusions:{extrudeLinear:(l,B)=>({type:"extrudeLinear",options:l,shape:B}),extrudeRotate:(l,B)=>({type:"extrudeRotate",options:l,shape:B})},maths:{vec2:{create:(l,B)=>[l,B],fromValues:(l,B)=>[l,B]},vec3:{create:(l,B,C)=>[l,B,C],fromValues:(l,B,C)=>[l,B,C]}},geometries:{geom2:{create:l=>({type:"createGeom2",points:l})},geom3:{create:l=>({type:"createGeom3",polygons:l})},path2:{create:l=>({type:"createPath2",points:l})}},measurements:{measureBoundingBox:l=>({type:"measureBoundingBox",shape:l}),measureArea:l=>({type:"measureArea",shape:l}),measureVolume:l=>({type:"measureVolume",shape:l})},utils:{degToRad:l=>l*Math.PI/180,radToDeg:l=>l*180/Math.PI}},I=(l,B)=>{if(Array.isArray(B)&&B.length===1)return I(l,B[0]);if(Array.isArray(B))throw new Error("executeJscadOperations currently doesn't support Array<JscadOperation>, try adding a root union or or executing each element individually");const C=E=>I(l,E),{type:Q,...h}=B;switch(Q){case"intersect":return l.booleans.intersect(...B.shapes.map(C));case"subtract":return l.booleans.subtract(...B.shapes.map(C));case"union":return l.booleans.union(...B.shapes.map(C));case"hull":return l.hulls.hull(...B.shapes.map(C));case"hullChain":return l.hulls.hullChain(...B.shapes.map(C));case"colorize":return l.colors.colorize(B.color,C(B.shape));case"cube":return l.primitives.cube(h);case"sphere":return l.primitives.sphere(h);case"cylinder":return l.primitives.cylinder(h);case"polygon":return l.primitives.polygon(h);case"cuboid":return l.primitives.cuboid(h);case"roundedCuboid":return l.primitives.roundedCuboid(h);case"rotate":return l.transforms.rotate(B.angles,C(B.shape));case"scale":return l.transforms.scale(B.factors,C(B.shape));case"translate":return l.transforms.translate(B.vector,C(B.shape));case"extrudeLinear":return l.extrusions.extrudeLinear(B.options,C(B.shape));case"extrudeRotate":return l.extrusions.extrudeRotate(B.options,C(B.shape));case"createGeom2":return l.geometries.geom2.create(B.points);case"createGeom3":return l.geometries.geom3.create(B.polygons);case"createPath2":return l.geometries.path2.create(B.points);case"measureBoundingBox":return l.measurements.measureBoundingBox(C(B.shape));case"measureArea":return l.measurements.measureArea(C(B.shape));case"measureVolume":return l.measurements.measureVolume(C(B.shape));case"degToRad":return l.utils.degToRad(B.degrees);case"radToDeg":return l.utils.radToDeg(B.radians);default:throw B.type===void 0?new Error(`Operation type is undefined. This usually means the operation object is malformed or not properly initialized. Operation: ${JSON.stringify(B,null,2).slice(0,200)}...`):new Error(`Unsupported operation type: ${B.type}. Operation: ${JSON.stringify(B,null,2)}`)}}}}),dft=se({"node_modules/ms/index.js"(t,A){var e=1e3,i=e*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*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return C;default:return}}}}function g(l){var B=Math.abs(l);return B>=o?Math.round(l/o)+"d":B>=n?Math.round(l/n)+"h":B>=i?Math.round(l/i)+"m":B>=e?Math.round(l/e)+"s":l+"ms"}function c(l){var B=Math.abs(l);return B>=o?I(l,B,o,"day"):B>=n?I(l,B,n,"hour"):B>=i?I(l,B,i,"minute"):B>=e?I(l,B,e,"second"):l+" ms"}function I(l,B,C,Q){var h=B>=C*1.5;return Math.round(l/C)+" "+Q+(h?"s":"")}}}),pft=se({"node_modules/debug/src/common.js"(t,A){function e(i){o.debug=o,o.default=o,o.coerce=I,o.disable=g,o.enable=r,o.enabled=c,o.humanize=dft(),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 p=u,m=Number(new Date),D=m-(C||m);p.diff=D,p.prev=C,p.curr=m,C=m,d[0]=o.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let w=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(k,x)=>{if(k==="%%")return"%";w++;const N=o.formatters[x];if(typeof N=="function"){const M=d[w];k=N.call(p,M),d.splice(w,1),w--}return k}),o.formatArgs.call(p,d),(p.log||o.log).apply(p,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=e}}),fft=se({"node_modules/debug/src/browser.js"(t,A){t.formatArgs=i,t.save=n,t.load=o,t.useColors=e,t.storage=s(),t.destroy=(()=>{let a=!1;return()=>{a||(a=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function e(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let a;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(a=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(a[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function i(a){if(a[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+a[0]+(this.useColors?"%c ":" ")+"+"+A.exports.humanize(this.diff),!this.useColors)return;const g="color: "+this.color;a.splice(1,0,g,"color: inherit");let c=0,I=0;a[0].replace(/%[a-zA-Z%]/g,l=>{l!=="%%"&&(c++,l==="%c"&&(I=c))}),a.splice(I,0,g)}t.log=console.debug||console.log||(()=>{});function n(a){try{a?t.storage.setItem("debug",a):t.storage.removeItem("debug")}catch{}}function o(){let a;try{a=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch{}return!a&&typeof _hA<"u"&&"env"in _hA&&(a=_hA.env.DEBUG),a}function s(){try{return localStorage}catch{}}A.exports=pft()(t);var{formatters:r}=A.exports;r.j=function(a){try{return JSON.stringify(a)}catch(g){return"[UnexpectedJSONParseError]: "+g.message}}}}),OXA={boardBody:!0,topCopper:!0,bottomCopper:!0,adhesive:!1,solderPaste:!1,topSilkscreen:!0,bottomSilkscreen:!0,topMask:!0,bottomMask:!0,throughHoleModels:!0,smtModels:!0,translucentModels:!0,modelsNotInPosFile:!1,modelsMarkedDNP:!1,modelBoundingBoxes:!1,threedAxis:!1,backgroundStart:!0,backgroundEnd:!0},WXA=V.createContext(void 0),yft=({children:t})=>{const[A,e]=V.useState(OXA),i=V.useCallback((s,r)=>{e(a=>({...a,[s]:r}))},[]),n=V.useCallback(()=>{e(OXA)},[]),o=V.useMemo(()=>({visibility:A,setLayerVisibility:i,resetToDefaults:n}),[A,i,n]);return W.jsx(WXA.Provider,{value:o,children:t})},$N=()=>{const t=V.useContext(WXA);if(!t)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return t},tEA=1.2;function ZXA(t){return V.useMemo(()=>{if(!t)return tEA;try{return Di(t).pcb_board.list()[0]?.thickness??tEA}catch{return tEA}},[t])}var VXA=V.createContext(null),Ju=()=>{const t=V.useContext(VXA);if(!t)throw new Error("useThree must be used within a ThreeProvider");return t},uH=(t,A=[])=>{const{addFrameListener:e,removeFrameListener:i}=Ju();tn.useEffect(()=>(e(t),()=>i(t)),[e,i,...A])},dH={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:90,appearanceMenu:91},jXA=({children:t,position:A,style:e})=>{const{camera:i,renderer:n}=Ju(),o=V.useRef(document.createElement("div")),[s,r]=V.useState(null);return V.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(g5.createPortal(t,o.current)),()=>{a.contains(o.current)&&a.removeChild(o.current)}},[n,t]),uH(()=>{if(!i||!o.current||!n)return;const a=new Re(...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=dH.htmlElements.toString(),e&&Object.assign(o.current.style,e)},[i,n,A,e]),s},zXA={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},kr=t=>{let A=typeof t=="number"?"mm":t.replace(/^[^a-zA-Z]+/g,"").toLowerCase();A||(A="mm");const e=typeof t=="number"?t:Number.parseFloat(t.split(A)[0]);if(A in zXA)return e*zXA[A];throw new Error(`Unsupported unit: ${A}`)},xl=kr,mft=Object.defineProperty,wft=(t,A)=>{for(var e in A)mft(t,e,{get:A[e],enumerable:!0})},ib={};wft(ib,{axial:()=>W0t,bga:()=>t0t,breakoutheaders:()=>syt,cap:()=>Fft,dfn:()=>x0t,diode:()=>kft,dip:()=>bft,electrolytic:()=>Kwt,hc49:()=>ayt,jst:()=>Iwt,led:()=>Gft,lqfp:()=>nyt,m2host:()=>cDt,melf:()=>pmt,micromelf:()=>wmt,minimelf:()=>lmt,mlp:()=>I0t,ms012:()=>N0t,ms013:()=>L0t,msop:()=>fwt,pad:()=>gyt,pinrow:()=>F0t,platedhole:()=>eDt,potentiometer:()=>Ywt,pushbutton:()=>X0t,qfn:()=>a0t,qfp:()=>c0t,quad:()=>ev,radial:()=>j0t,res:()=>$ft,sma:()=>xmt,smb:()=>vmt,smbf:()=>qwt,smc:()=>Ymt,smf:()=>Gmt,smtpad:()=>$wt,sod110:()=>Bwt,sod123:()=>K0t,sod123f:()=>Pyt,sod123fl:()=>Zyt,sod123w:()=>wyt,sod128:()=>tmt,sod323:()=>xyt,sod323f:()=>Yyt,sod323fl:()=>bwt,sod323w:()=>mwt,sod523:()=>Cyt,sod723:()=>Xyt,sod80:()=>pyt,sod882:()=>vyt,sod882d:()=>hmt,sod923:()=>Gyt,soic:()=>n0t,solderjumper:()=>Gwt,son:()=>Fwt,sop8:()=>uyt,sot:()=>iDt,sot223:()=>Pmt,sot23:()=>f0t,sot23w:()=>$mt,sot25:()=>D0t,sot323:()=>Vwt,sot343:()=>sDt,sot363:()=>E0t,sot457:()=>Nwt,sot563:()=>R0t,sot723:()=>H0t,sot886:()=>d0t,sot89:()=>amt,sot963:()=>Lwt,ssop:()=>B0t,stampboard:()=>Ayt,stampreceiver:()=>iyt,to220:()=>cmt,to92:()=>lyt,to92l:()=>lDt,to92s:()=>owt,tqfp:()=>g0t,tssop:()=>Q0t,vssop:()=>uwt});var Oi=(t,A,e)=>({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:e,pcb_component_id:"pcb_component_1",text:"{REF}",layer:"top",anchor_position:{x:t,y:A},anchor_alignment:"center"}),Wi=VA({norefdes:ge().optional().describe("disable reference designator label"),invert:ge().optional().describe("hint to invert the orientation of the 3D model"),faceup:ge().optional().describe("The male pin header should face upwards, out of the top layer"),nosilkscreen:ge().optional().describe("omit all silkscreen elements from the footprint")}),zo=(t,A,e,i,n)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circle",x:A,y:e,hole_diameter:kr(i),outer_diameter:kr(n),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()]}),nb=(t,A,e,i,n,o,s,r)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circular_hole_with_rect_pad",x:A,y:e,hole_diameter:kr(i),hole_shape:"circle",pad_shape:"rect",rect_pad_width:kr(n),rect_pad_height:kr(o),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()],hole_offset_x:s,hole_offset_y:r}),XXA=Array.from({length:9},(t,A)=>Math.cos(A/8*Math.PI-Math.PI)).map(t=>({x:t,y:-Math.sqrt(1-t**2)}));function h_(t){return typeof t=="string"?t.trim().toLowerCase().endsWith("mil")?parseFloat(t)*.0254:parseFloat(t):Number(t)}var MW=Wt([J(),WA()]).transform(t=>h_(t)),Dft=t=>Wi.extend({fn:J(),num_pins:WA().optional().default(6),wide:ge().optional(),narrow:ge().optional(),w:MW.optional(),p:MW.default(t.p??"2.54mm"),id:MW.optional(),od:MW.optional(),nosquareplating:ge().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=h_("0.55mm"),A.od=h_("0.95mm")):(A.id=h_("0.8mm"),A.od=h_("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=h_("600mil"):A.narrow?A.w=h_("300mil"):A.w=h_(t.w??"300mil")),A)),Sft=Dft({}),$XA=(t,A,e,i,n)=>{const o=t/2,s=A<=o,r=o-1,a=i,g=a*r;return s?{x:-e/2,y:g/2-(A-1)*a}:{x:e/2,y:-g/2+(A-o-1)*a}},bft=t=>{const A=Sft.parse(t),e=[];for(let g=0;g<A.num_pins;g++){const{x:c,y:I}=$XA(A.num_pins,g+1,A.w,A.p??2.54,A.nosquareplating);if(g===0&&!A.nosquareplating){e.push(nb(g+1,c,I,A.id??"0.8mm",A.od??"1mm",A.od??"1mm"));continue}e.push(zo(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},...XXA.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}=$XA(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=Oi(0,o/2+.5,.4);return{circuitJson:[...e,s,a,...r],parameters:A}},di=(t,A,e,i,n)=>({type:"pcb_smtpad",x:A,y:e,width:i,height:n,layer:"top",shape:"rect",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(o=>o.toString()):[t.toString()]}),A6A=[{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}],xft=Object.fromEntries(A6A.map(t=>[t.metric,t])),_ft=Object.fromEntries(A6A.map(t=>[t.imperial,t]));Wi.extend({tht:ge(),p:hA.optional(),pw:hA.optional(),ph:hA.optional(),metric:ae.optional(),imperial:ae.optional(),w:hA.optional(),h:hA.optional(),textbottom:ge().optional()});var NW=t=>{let{tht:A,p:e,pw:i,ph:n,metric:o,imperial:s,w:r,h:a,textbottom:g}=t;if(typeof r=="string"&&(r=xl(r)),typeof a=="string"&&(a=xl(a)),typeof e=="string"&&(e=xl(e)),typeof i=="string"&&(i=xl(i)),typeof n=="string"&&(n=xl(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=xft[o]),s&&(c=_ft[s]),c&&(r=c.w_mm_min,a=c.h_mm_min,e=c.p_mm_min,i=c.pw_mm_min,n=c.ph_mm_min),e===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:e/2,y:n/2+.4},{x:-e/2-i/2-.2,y:n/2+.4},{x:-e/2-i/2-.2,y:-n/2-.4},{x:e/2,y:-n/2-.4}],stroke_width:.1,pcb_silkscreen_path_id:""},l=g?-n/2-.9:n/2+.9,B=Oi(0,l,.2);return A?[zo(1,-e/2,0,i,i*1/.8),zo(2,e/2,0,i,i*1/.8),I,B]:[di(["1","left"],-e/2,0,i,n),di(["2","right"],e/2,0,i,n),I,B]},kft=t=>({circuitJson:NW(t),parameters:t}),Fft=t=>({circuitJson:NW(t),parameters:t}),Gft=t=>({circuitJson:NW(t),parameters:t}),Av=t=>{const{padSpacing:A,padWidth:e,padHeight:i,padPitch:n,numRows:o,textbottom:s}=t,r=[],a=(o-1)*(n/2);for(let S=0;S<o;S++)r.push(a-S*n);const g=[];r.forEach((S,k)=>{g.push(di(k+1,-A/2,S,e,i))}),r.slice().reverse().forEach((S,k)=>{g.push(di(k+o+1,A/2,S,e,i))});const c=Math.max(...r)+i/2+.4,I=Math.min(...r)-i/2-.4,l=-A/2-e/2-.4,B=A/2+e/2+.4,C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B*.5,y:c},{x:l*.5,y:c}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_top"},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B*.5,y:I},{x:l*.5,y:I}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_bottom"},h=-A/2,E=Math.max(...r),u=.2,d=h-e/2-.1,p=E+i/2+.1,m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:[{x:d,y:p},{x:d-u,y:p},{x:d,y:p+u},{x:d,y:p}],stroke_width:.1},D=s?I-.9:c+.9,w=Oi(0,D,.2);return[...g,C,Q,m,w]},Rft=Wi.extend({pw:J().default("0.5mm"),ph:J().default("0.4mm"),p:J().default("0.7mm"),textbottom:ge().optional()}),Mft=1,Nft=t=>{const A=Rft.parse(t),e=xl(A.pw),i=xl(A.ph),n=xl(A.p);return Av({padSpacing:Mft,padWidth:e,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom})},vft=Wi.extend({pw:J().default("0.5mm"),ph:J().default("0.32mm"),p:J().default("0.5mm"),textbottom:ge().optional()}),Lft=1,Uft=t=>{const A=vft.parse(t),e=xl(A.pw),i=xl(A.ph),n=xl(A.p);return Av({padSpacing:Lft,padWidth:e,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom})},Hft=Wi.extend({pw:J().default("0.9mm"),ph:J().default("0.4mm"),p:J().default("0.8mm"),textbottom:ge().optional()}),Yft=1.7,Jft=t=>{const A=Hft.parse(t),e=xl(A.pw),i=xl(A.ph),n=xl(A.p);return Av({padSpacing:Yft,padWidth:e,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom})},Tft=Wi.extend({pw:J().default("0.9mm"),ph:J().default("0.4mm"),p:J().default("0.8mm"),textbottom:ge().optional()}),Kft=1.7,Pft=t=>{const A=Tft.parse(t),e=xl(A.pw),i=xl(A.ph),n=xl(A.p);return Av({padSpacing:Kft,padWidth:e,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom})},qft=Wi.extend({pw:J().default("0.7mm"),ph:J().default("0.64mm"),p:J().default("0.94mm"),textbottom:ge().optional()}),Oft=1.4,Wft=t=>{const A=qft.parse(t),e=xl(A.pw),i=xl(A.ph),n=xl(A.p);return Av({padSpacing:Oft,padWidth:e,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom})},Zft=Wi.extend({pw:J().default("0.9mm"),ph:J().default("0.9mm"),p:J().default("1.34mm"),textbottom:ge().optional()}),Vft=3,jft=t=>{const A=Zft.parse(t),e=xl(A.pw),i=xl(A.ph),n=xl(A.p);return Av({padSpacing:Vft,padWidth:e,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom})},zft=t=>{const A=t.array??t.x;if(typeof A=="number")return Number.isNaN(A)?void 0:A;if(typeof A=="string"){const e=Number.parseInt(A,10);return Number.isNaN(e)?void 0:e}if(typeof t.imperial=="string"){const i=t.imperial.match(/(?:array|x)(2|4)$/)?.[1];if(i)return Number.parseInt(i,10)}},Xft=t=>t?(typeof t=="number"?`${t}`:t).split("_")[0]:void 0,$ft=t=>{const A=zft(t),e=Xft(t.imperial);return A===2&&e==="0402"?{circuitJson:Nft(t),parameters:t}:A===4&&e==="0402"?{circuitJson:Uft(t),parameters:t}:A===2&&e==="0603"?{circuitJson:Jft(t),parameters:t}:A===4&&e==="0603"?{circuitJson:Pft(t),parameters:t}:A===2&&e==="0606"?{circuitJson:Wft(t),parameters:t}:A===4&&e==="1206"?{circuitJson:jft(t),parameters:t}:{circuitJson:NW(t),parameters:t}},e6A=(t,{x:A,y:e,radius:i})=>({type:"pcb_smtpad",x:A,y:e,radius:i,layer:"top",shape:"circle",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(n=>n.toString()):[t.toString()]}),t6A="ABCDEFGHIJKLMNOPQRSTUVWXYZ",i6A=J().transform(t=>{const[A,e]=t.split(/[x ]/);return{x:parseFloat(A),y:parseFloat(e)}}).pipe(VA({x:WA(),y:WA()})),A0t=J().or(Se(Jc())).transform(t=>Array.isArray(t)?t:(t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,-1)),t.split(",").map(A=>{const e=Number(A);return isNaN(e)?A:e}))).pipe(Se(J().or(WA()))),e0t=Wi.extend({fn:J(),num_pins:WA().optional().default(64),grid:i6A.optional(),p:ae.default("0.8mm"),w:hA.optional(),h:hA.optional(),ball:hA.optional().describe("ball diameter"),pad:hA.optional().describe("pad width/height"),circularpads:ge().optional().describe("use circular pads"),tlorigin:ge().optional(),blorigin:ge().optional(),trorigin:ge().optional(),brorigin:ge().optional(),missing:A0t.default([])}).transform(t=>{let A="tl";if(t.blorigin&&(A="bl"),t.trorigin&&(A="tr"),t.brorigin&&(A="br"),!t.grid){const i=Math.ceil(Math.sqrt(t.num_pins));t.grid={x:i,y:i}}return t.missing&&(t.missing=t.missing.map(i=>{if(typeof i=="number")return i;if(i==="center")return"center";if(i==="topleft")return"topleft";const n=i.match(/([A-Z]+)(\d+)/);if(!n)return i;const o=t6A.indexOf(n[1]),s=Number.parseInt(n[2])-1;return o*t.grid.x+s+1})),{...t,origin:A}}),t0t=t=>{const A=e0t.parse(t);let{num_pins:e,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-e;if(g.length===0&&l>0&&(Math.sqrt(l)%1===0?g.push("center"):l===1&&g.push("topleft")),g?.includes("center")){const m=Math.floor(Math.sqrt(l)),D=Math.floor((i.x-m)/2),w=Math.floor((i.y-m)/2);for(let S=w;S<w+m;S++)for(let k=D;k<D+m;k++)I.push(S*i.x+k+1)}g?.includes("topleft")&&I.push(1);const B=new Set(I);let C=0;for(let m=0;m<i.y;m++)for(let D=0;D<i.x;D++){const w=(D-(i.x-1)/2)*n,S=(m-(i.y-1)/2)*n;let k=D,x=m;switch(A.origin){case"bl":k=D,x=i.y-1-m;break;case"br":k=i.x-1-D,x=i.y-1-m;break;case"tr":k=i.x-1-D,x=m;break}let N=x*i.x+k+1;if(B.has(N)){C++;continue}N-=C;const M=[N,`${t6A[x]}${k+1}`];c.push(A.circularpads?e6A(M,{x:w,y:S,radius:a/2}):di(M,w,S,a,a))}const Q=Oi(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 p={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:E,stroke_width:.05};return{circuitJson:[...c,Q,p],parameters:A}},vW=(t,A,e,i,n)=>({type:"pcb_smtpad",x:A,y:e,width:i,height:n,radius:n/2,layer:"top",shape:"pill",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(o=>o.toString()):[t.toString()]}),lD=t=>Wi.extend({fn:J(),num_pins:WA().optional().default(8),w:hA.default(hA.parse(t.w??"5.3mm")),p:hA.default(hA.parse(t.p??"1.27mm")),pw:hA.default(hA.parse(t.pw??"0.6mm")),pl:hA.default(hA.parse(t.pl??"1.0mm")),legsoutside:ge().optional().default(t.legsoutside??!1),pillpads:ge().optional().default(t.pillpads??!1),silkscreen_stroke_width:WA().optional().default(.1)}).transform(A=>(!A.pw&&!A.pl?(A.pw=hA.parse("0.6mm"),A.pl=hA.parse("1.0mm")):A.pw?A.pl||(A.pl=A.pw*(1/.6)):A.pw=A.pl*(.6/1),A)),i0t=lD({}),iEA=t=>{t.widthincludeslegs!==void 0&&(t.legsoutside=!t.widthincludeslegs);const{num_pins:A,pn:e,w:i,p:n,pl:o,legsoutside:s}=t,r=A/2,a=e<=r,g=r-1,c=n,I=c*g,l=s?o/2:-o/2;return a?{x:-i/2-l,y:I/2-(e-1)*c}:{x:i/2+l,y:-I/2+(e-r-1)*c}},n0t=t=>{const A=i0t.parse(t);return{circuitJson:E_(A),parameters:A}},E_=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=iEA({num_pins:t.num_pins,pn:r+1,w:t.w,p:t.p,pl:t.pl,legsoutside:t.legsoutside});t.pillpads?A.push(vW(r+1,a,g,t.pl,t.pw)):A.push(di(r+1,a,g,t.pl,t.pw))}const e=Math.min(1,t.p/2),i=t.w-(t.legsoutside?0:t.pl*2)-.2,n=(t.num_pins/2-1)*t.p+t.pw+e,o=Oi(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:t.silkscreen_stroke_width??.1,route:[{x:-i/2,y:-n/2},{x:-i/2,y:n/2},...XXA.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]},n6A=at(["leftside","topside","rightside","bottomside","toppin","bottompin","leftpin","rightpin"]),o0t=({num_pins:t,cw:A,ccw:e,startingpin:i})=>{const n=[],o=t/4;let s=1;const r={};for(const a of i??[])r[a]=!0;!r.leftside&&!r.topside&&!r.rightside&&!r.bottomside&&(r.leftside=!0),!r.bottompin&&!r.leftpin&&!r.rightpin&&!r.toppin&&(r.leftside?r.toppin=!0:r.topside?r.rightpin=!0:r.rightside?r.bottompin=!0:r.bottomside&&(r.leftpin=!0)),r.leftside&&r.toppin?s=1:r.leftside&&r.bottompin?s=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<t;a++)n[s]=a+1,e||!A?(s++,s>t&&(s=1)):(s--,s<1&&(s=t));return n},nEA=Wi.extend({fn:J(),cc:ge().default(!0).optional(),ccw:ge().default(!0).optional(),startingpin:J().or(Se(n6A)).transform(t=>typeof t=="string"?t.slice(1,-1).split(","):t).pipe(Se(n6A)).optional(),num_pins:WA().optional().default(64),w:hA.optional(),h:hA.optional(),p:hA.default(hA.parse("0.5mm")),pw:hA.optional(),pl:hA.optional(),thermalpad:Wt([FA(!0),i6A]).optional(),legsoutside:ge().default(!1)}),oEA=t=>{t.w&&!t.h?t.h=t.w:!t.w&&t.h&&(t.w=t.h);const A=t.num_pins/4;if(!t.p&&!t.pw&&!t.pl&&t.w){const e=A+4;t.p=t.w/e}return!t.p&&t.w&&t.h&&t.pw&&t.pl&&(t.p=(t.w-t.pl*2)/(A-1)),!t.w&&!t.h&&t.p&&(t.w=t.p*(A+4),t.h=t.w),t.p&&!t.pw&&!t.pl?(t.pw=t.p/2,t.pl=t.p/2):t.pw?t.pl||(t.pl=t.pw*(1/.6)):t.pw=t.pl*(.6/1),t},o6A=nEA.transform(oEA),s0t=["left","bottom","right","top"],r0t=t=>{const{pin_count:A,pn:e,w:i,h:n,p:o,pl:s,legsoutside:r}=t,a=A/4,g=s0t[Math.floor((e-1)/a)],c=(e-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")}},ev=t=>{const A=o6A.parse(t),e=[],i=o0t(A),n=A.num_pins/4;for(let r=0;r<A.num_pins;r++){const{x:a,y:g,o:c}=r0t({pin_count:A.num_pins,pn:r+1,w:A.w,h:A.h,p:A.p??.5,pl:A.pl,legsoutside:A.legsoutside});let I=A.pw,l=A.pl;c==="vert"&&([I,l]=[l,I]);const B=i[r+1];e.push(di(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;e.push(di(["thermalpad"],0,0,r,a))}else e.push(di(["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=Oi(0,A.h/2+(A.legsoutside?A.pl*1.2:.5),.3);return{circuitJson:[...e,...o,s],parameters:A}};nEA.extend({}).transform(oEA);var a0t=t=>(t.legsoutside=!1,t.pl||(t.pl=.875),t.pw||(t.pw=.25),ev(t)),g0t=t=>{if(t.legsoutside=!0,!t.p)switch(t.num_pins){case 32:t.p=.8;break;case 44:case 48:t.p=.5;break;case 64:case 80:case 100:t.p=.5;break;case 144:t.p=.5;break}if(!t.pl)switch(t.num_pins){case 32:case 44:case 48:case 64:case 80:case 100:t.pl=1.475;break;case 144:t.pl=1.6;break}if(!t.pw)switch(t.num_pins){case 32:t.pw=.55;break;case 44:case 48:case 64:case 80:case 100:t.pw=.3;break;case 144:t.pw=.25;break}return ev(t)},c0t=t=>{t.legsoutside=!0;const A=o6A.parse(t);if(!t.p)switch(t.num_pins){case 44:case 64:t.p=.8;break;case 52:t.w===14?t.p=1:t.p=.65;break;case 208:t.p=.5;break}if(!t.pl)switch(t.num_pins){case 44:case 52:case 64:t.pl=2.25;break;case 208:t.pl=1.65;break;default:t.pl=A.pl*4;break}if(!t.pw)switch(t.num_pins){case 44:case 64:t.pw=.5;break;case 52:t.w===14?t.pw=.45:t.pw=.55;break;case 208:t.pw=.3;break;default:t.pw=A.pw;break}return ev(t)};nEA.extend({}).transform(oEA);var I0t=t=>(t.legsoutside=!1,t.thermalpad===void 0&&(t.thermalpad=!0),ev(t)),l0t=lD({w:"3.9mm",p:"1.27mm"}),B0t=t=>{const A=l0t.parse(t);return{circuitJson:E_(A),parameters:A}},C0t=lD({w:"7.1mm",p:"0.65mm",pl:"1.35mm",pw:"0.40mm",legsoutside:!0}),Q0t=t=>{const A=C0t.parse(t);return{circuitJson:E_(A),parameters:A}},h0t=lD({}),E0t=t=>{const A=h0t.parse({fn:"sot363",num_pins:6,w:2.56,p:.65,pw:.4,pl:.65,legoutside:!0});return{circuitJson:E_(A),parameters:A}},u0t=Wi.extend({fn:J(),num_pins:FA(6).default(6),w:J().default("1.01mm"),h:J().default("1.45mm"),p:J().default("0.5mm"),pl:J().default("0.33mm"),pw:J().default("0.27mm"),string:J().optional()}),d0t=t=>{const A=u0t.parse({fn:"sot886",...t}),e=hA.parse(A.w),i=hA.parse(A.h),n=hA.parse(A.p),o=hA.parse(A.pl),s=hA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=s6A(B+1,e,n,o);r.push(di(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:i/2},{x:e/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:-i/2},{x:e/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=s6A(1,e,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=Oi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},s6A=(t,A,e,i)=>{const n=A/2-i/2;return t<=3?{x:-n,y:e-(t-1)*e}:{x:n,y:-e+(t-4)*e}},r6A=Wi.extend({fn:J(),num_pins:WA().default(3),w:J().default("1.92mm"),h:J().default("2.74mm"),pl:J().default("1.32mm"),pw:J().default("0.6mm"),p:J().default("0.95mm"),string:J().optional()}),p0t=lD({p:"0.95mm",w:"1.6mm",legsoutside:!0}),f0t=t=>{const A=t.string?.match(/^sot23_(\d+)/),e=A?Number.parseInt(A[1],10):3;if(e===6||e===8){const n=p0t.parse({...t,num_pins:e});return{circuitJson:E_(n),parameters:n}}const i=r6A.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:m0t(i),parameters:i};if(i.num_pins===5)return{circuitJson:g6A(i),parameters:i};throw new Error("Invalid number of pins")},y0t=t=>{const{pn:A,p:e}=t;return A===1?{x:-1.155,y:e}:A===2?{x:-1.155,y:-e}:{x:1.15,y:0}},m0t=t=>{const A=[];for(let i=0;i<t.num_pins;i++){const{x:n,y:o}=y0t({num_pins:t.num_pins,pn:i+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(di(i+1,n,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=Oi(0,Number.parseInt(t.h),.3);return[...A,e]},a6A=t=>{const{p:A,h:e,pn:i}=t;if(i===1)return{x:-e/2-.5,y:A};if(i===2)return{x:-e/2-.5,y:0};if(i===3)return{x:-e/2-.5,y:-A};if(i===4)return{x:e/2+.5,y:-A};if(i===5)return{x:e/2+.5,y:A};throw new Error("Invalid pin number")},g6A=t=>{const A=[];for(let I=1;I<=t.num_pins;I++){const{x:l,y:B}=a6A({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:I});A.push(di(I,l,B,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=(t.num_pins+1)/2*Number.parseFloat(t.p),i=Number.parseFloat(t.h),n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e/3,y:i/2+Number.parseFloat(t.p)/1.3},{x:e/3,y:i/2+Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e/3,y:-i/2-Number.parseFloat(t.p)/1.3},{x:e/3,y:-i/2-Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Oi(0,i+.3,.3),r=a6A({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});r.x=r.x-Number.parseFloat(t.pw)*1.5;const a=.3,g=.4,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:r.x+a/2,y:r.y},{x:r.x-a/2,y:r.y+g/2},{x:r.x-a/2,y:r.y-g/2},{x:r.x+a/2,y:r.y}],stroke_width:.05};return[...A,s,n,o,c]},w0t=r6A.extend({}),D0t=t=>{const A=w0t.parse({...t,num_pins:5});return{circuitJson:g6A(A),parameters:A}},S0t=[{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}],b0t=lD({}),x0t=t=>{const A=b0t.parse(t),e=[];for(let I=0;I<A.num_pins;I++){const{x:l,y:B}=iEA({num_pins:A.num_pins,pn:I+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});e.push(di(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 S0t){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=Oi(0,o/2+.4,o/12);return{circuitJson:[...e,c,...s],parameters:A}},sEA=({fs:t,pn:A,anchor_x:e,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:t,pcb_component_id:"pcb_component_1",text:`{PIN${A}}`,layer:r,anchor_position:{x:e,y:i},anchor_alignment:g,ccw_rotation:a}};function _0t({pinlabeltextalignleft:t,pinlabeltextalignright:A,pinlabelorthogonal:e}){let i="top";return e?i="left":i="top",t&&(e?i="bottom":i="right"),A&&(e?i="top":i="left"),i}var k0t=Wi.extend({fn:J(),num_pins:WA().optional().default(6),rows:Wt([J(),WA()]).transform(t=>Number(t)).optional().default(1).describe("number of rows"),p:hA.default("0.1in").describe("pitch"),id:hA.default("1.0mm").describe("inner diameter"),od:hA.default("1.5mm").describe("outer diameter"),male:ge().optional().describe("for male pin headers"),female:ge().optional().describe("for female pin headers"),smd:ge().optional().describe("surface mount device"),surfacemount:ge().optional().describe("surface mount device (verbose)"),rightangle:ge().optional().describe("right angle"),pw:hA.optional().default("1.0mm").describe("pad width for SMD"),pl:hA.optional().default("2.0mm").describe("pad length for SMD"),pinlabeltextalignleft:ge().optional().default(!1),pinlabeltextaligncenter:ge().optional().default(!1),pinlabeltextalignright:ge().optional().default(!1),pinlabelverticallyinverted:ge().optional().default(!1),pinlabelorthogonal:ge().optional().default(!1),nosquareplating:ge().optional().default(!1).describe("do not use rectangular pad for pin 1"),nopinlabels:ge().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:ge().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:ge().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top")}).transform(t=>{const A=_0t(t);return{...t,pinlabelAnchorSide:A,male:t.male??!t.female,female:t.female??!1,smd:t.smd??t.surfacemount??!1,rightangle:t.rightangle??!1}}).superRefine((t,A)=>{t.male&&t.female&&A.addIssue({code:Ot.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),F0t=t=>{const A=k0t.parse(t),{p:e,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=-e,d=({xoff:S,yoff:k,od:x,anchorSide:N,smd:M,pw:L,pl:Y})=>{let H=0,O=0;if(M){const Z=x/5;switch(N){case"right":H=L/2+Z;break;case"top":O=Y/2+Z;break;case"bottom":O=-(Y/2+Z);break;case"left":H=-(L/2+Z);break}}else{const Z=x*.75;switch(N){case"right":H=Z;break;case"top":O=Z;break;case"bottom":O=-Z;break;case"left":H=-Z;break}}return{anchor_x:S+H,anchor_y:k+O}},p=(S,k,x)=>{A.smd?h.push(di(S,k,x,A.pw,A.pl)):S===1&&!A.nosquareplating?h.push(nb(S,k,x,i,n,n,0,0)):h.push(zo(S,k,x,i,n));const{anchor_x:N,anchor_y:M}=d({xoff:k,yoff:x,od:n,anchorSide:r,smd:A.smd,pw:A.pw,pl:A.pl});l||(C?h.push(sEA({fs:n/5,pn:S,anchor_x:N,anchor_y:M,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})):h.push(sEA({fs:n/5,pn:S,anchor_x:N,anchor_y:M,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"top"})),B&&h.push(sEA({fs:n/5,pn:S,anchor_x:N,anchor_y:M,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})))},m=new Set,D=o>2&&E>2;if(o===1){const S=-((s-1)/2)*e;for(let k=0;k<s;k++){const x=k+1,N=S+k*e,M=`${N},0`;if(m.has(M))throw new Error(`Overlap at ${M}`);m.add(M),p(x,N,0)}}else if(D){const S=-((E-1)/2)*e;let k=1;for(let x=0;x<o&&k<=s;x++)for(let N=0;N<E&&k<=s;N++){const M=S+N*e,L=x*u,Y=`${M},${L}`;if(m.has(Y))throw new Error(`Overlap at ${Y}`);m.add(Y),p(k++,M,L)}}else{const S=-((E-1)/2)*e;let k=1,x=0,N=o-1,M=0,L=E-1;for(;k<=s&&x<=N&&M<=L;){for(let Y=x;Y<=N&&k<=s;Y++){const H=S+M*e,O=Y*u,Z=`${H},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),p(k++,H,O)}M++;for(let Y=M;Y<=L&&k<=s;Y++){const H=S+Y*e,O=N*u,Z=`${H},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),p(k++,H,O)}if(N--,M<=L){for(let Y=N;Y>=x&&k<=s;Y--){const H=S+L*e,O=Y*u,Z=`${H},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),p(k++,H,O)}L--}if(x<=N){for(let Y=L;Y>=M&&k<=s;Y--){const H=S+Y*e,O=x*u,Z=`${H},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),p(k++,H,O)}x++}}if(k-1<s)throw new Error(`Missing pins: assigned ${k-1}, expected ${s}`)}const w=Oi(0,e,.5);return{circuitJson:[...h,w],parameters:A}},G0t=Wi.extend({fn:J(),num_pins:FA(6).default(6),w:J().default("2.1mm"),h:J().default("2.45mm"),p:J().default("0.5mm"),pl:J().default("0.675mm"),pw:J().default("0.35mm"),string:J().optional()}),R0t=t=>{const A=G0t.parse({...t,fn:"sot563"}),e=hA.parse(A.w),i=hA.parse(A.h),n=hA.parse(A.p),o=hA.parse(A.pl),s=hA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=c6A(B+1,e,n,o);r.push(di(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:i/2},{x:e/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:-i/2},{x:e/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=c6A(1,e,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=Oi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},c6A=(t,A,e,i)=>{const n=A/2-i/2;return t<=3?{x:-n,y:e-(t-1)*e}:{x:n,y:-e+(t-4)*e}},M0t=lD({p:"1.27mm",w:"3.9mm",legsoutside:!0}),N0t=t=>{const A=M0t.parse({...t,num_pins:8});return{circuitJson:E_(A),parameters:A}},v0t=lD({p:"1.27mm",w:"7.5mm",legsoutside:!0}),L0t=t=>{const A=v0t.parse({...t,num_pins:16});return{circuitJson:E_(A),parameters:A}},U0t=Wi.extend({fn:J(),num_pins:FA(3).default(3),w:J().default("1.2mm"),h:J().default("1.2mm"),pw:J().default("0.40mm"),pl:J().default("0.45mm"),p:J().default("0.575mm")}),H0t=t=>{const A=U0t.parse(t),e=J0t(A),i=Oi(0,hA.parse(A.h),.2);return{circuitJson:[...e,i],parameters:A}},Y0t=t=>{const{pn:A,p:e}=t;return A===1?{x:e,y:0}:A===2?{x:-e,y:-.4}:{x:-e,y:.4}},J0t=t=>{const A=[];for(let e=0;e<3;e++){const{x:i,y:n}=Y0t({num_pins:t.num_pins,pn:e+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(di(e+1,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},T0t=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("2.36mm"),h:J().default("1.22mm"),pl:J().default("0.9mm"),pw:J().default("1.2mm"),p:J().default("3.30mm")}),K0t=t=>{const A=T0t.parse(t),e=Oi(0,hA.parse(A.h)/4+.4,.3);return{circuitJson:q0t(A).concat(e),parameters:A}},P0t=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},q0t=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=P0t({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},O0t=Wi.extend({fn:J(),p:hA.optional().default("2.54mm"),id:hA.optional().default("0.7mm"),od:hA.optional().default("1.4mm")}),W0t=t=>{const A=O0t.parse(t),{p:e,id:i,od:n}=A,o=[zo(1,-e/2,0,i,n),zo(2,e/2,0,i,n)],s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2+n+i/2,y:0},{x:e/2-n-i/2,y:0}],stroke_width:.1,pcb_silkscreen_path_id:""},r=Oi(0,1.5,.5);return{circuitJson:[...o,s,r],parameters:A}},Z0t=(t,A,e,i,n,o=.1)=>{const s=[],r=[],a=Math.max(1,Math.ceil(Math.PI*e/o)),g=Math.PI/a;for(let c=0;c<=a;c++){const I=c*g,l=t+Math.cos(I)*e,B=A+Math.sin(I)*e;l<t-i&&B>=A-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=t+Math.cos(I)*e,B=A+Math.sin(I)*e;l<t-i&&B>=A-n/2&&B<=A+n/2||r.push({x:l,y:B})}return{topArc:s,bottomArc:r}},V0t=Wi.extend({fn:J(),p:hA.optional().default("5mm"),id:hA.optional().default("0.8mm"),od:hA.optional().default("1.6mm"),ceramic:ge().optional(),electrolytic:ge().optional(),polarized:ge().optional()}),j0t=t=>{const A=V0t.parse(t),{p:e,id:i,od:n}=A;i===.8&&n===1.6&&(A.id=e===5?.8:e*.25,A.od=e===5?1.6:e*.5);const o=[zo(1,-e/2,0,A.id,A.od),zo(2,e/2,0,A.id,A.od)],s=e+.1,{topArc:r,bottomArc:a}=Z0t(0,0,s,A.od/2,A.od),g=.02*e,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:r,stroke_width:g,pcb_silkscreen_path_id:""},I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:g,pcb_silkscreen_path_id:""},l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:s},{x:0,y:-s}],stroke_width:g,pcb_silkscreen_path_id:""},B=.1*e,C=-(e+B+.04*e),Q=s-B-.08*e,h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:C-B,y:Q},{x:C+B,y:Q}],stroke_width:g,pcb_silkscreen_path_id:""},E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:C,y:Q-B},{x:C,y:Q+B}],stroke_width:g,pcb_silkscreen_path_id:""},u=Oi(0,s+.12*e,.1*e),d=[...o,c,I,l,u];return(A.electrolytic===!0||A.polarized===!0)&&d.push(h,E),{circuitJson:d,parameters:A}},LW=(t,A={})=>({type:"pcb_silkscreen_path",layer:A.layer||"top",pcb_component_id:A.pcb_component_id||"",pcb_silkscreen_path_id:A.pcb_silkscreen_path_id||"",route:t,stroke_width:A.stroke_width||.1}),z0t=Wi.extend({fn:FA("pushbutton"),w:hA.default(4.5),h:hA.default(6.5),id:hA.default(1),od:hA.default(1.2)}),X0t=t=>{const A=z0t.parse(t),e=A.w,i=A.h,n=A.id,o=[zo(1,-e/2,i/2,n,n*1.5),zo(2,-e/2,-i/2,n,n*1.5),zo(3,e/2,-i/2,n,n*1.5),zo(4,e/2,i/2,n,n*1.5)],s=[LW([{x:-e/2,y:-i/2},{x:-e/2,y:i/2}]),LW([{x:e/2,y:-i/2},{x:e/2,y:i/2}]),LW([{x:-e/2,y:0},{x:-e/5,y:0},{x:e/5*1/Math.sqrt(2),y:i/8}]),LW([{x:e/2,y:0},{x:e/5,y:0}])],r=Oi(0,i/2+.4,.5);return{circuitJson:[...o,...s,r],parameters:A}},I6A=Wi.extend({fn:J(),w:hA.default("22.58mm"),h:hA.optional(),left:hA.optional().default(20),right:hA.optional().default(20),top:hA.optional().default(2),bottom:hA.optional().default(2),p:hA.default(hA.parse("2.54mm")),pw:hA.default(hA.parse("1.6mm")),pl:hA.default(hA.parse("2.4mm")),innerhole:ge().default(!1),innerholeedgedistance:hA.default(hA.parse("1.61mm")),silkscreenlabels:ge().default(!1),silkscreenlabelmargin:hA.default(hA.parse("0.1mm"))}),$0t=t=>{const A=I6A.parse(t);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},UW=(t,A,e)=>{let i=[];return e==="right"&&(i=[{x:t+1/2,y:A},{x:t-1/2,y:A+.6/2},{x:t-1/2,y:A-.6/2},{x:t+1/2,y:A}]),e==="left"&&(i=[{x:t-1/2,y:A},{x:t+1/2,y:A+.6/2},{x:t+1/2,y:A-.6/2},{x:t-1/2,y:A}]),e==="top"&&(i=[{x:t,y:A+1/2},{x:t-.6/2,y:A-1/2},{x:t+.6/2,y:A-1/2},{x:t,y:A+1/2}]),e==="bottom"&&(i=[{x:t,y:A-1/2},{x:t-.6/2,y:A+1/2},{x:t+.6/2,y:A+1/2},{x:t,y:A-1/2}]),i},Ayt=t=>{const A=I6A.parse(t),e=A.h??$0t(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=UW(A.w/2-A.pl*1.4,Q+h*A.p,"right")),i.push(di(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(zo(h+1+A.left+(A.bottom??0)+g,A.w/2,Q+h*A.p,r,a)),n.push(zo(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=UW(-A.w/2+A.pl*1.4,Q-h*A.p,"left")),i.push(di(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(zo(h+1+g,-A.w/2,Q-h*A.p,r,a)),n.push(zo(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=UW(Q-h*A.p,e/2-A.pl*1.4,"top")),i.push(di(h+1+A.left+A.right+(A.bottom??0),Q-h*A.p,e/2-A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const E=h+1+A.left+A.right+(A.bottom??0),u=`pin${E}`;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:e/2-A.pl-(I+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:270})}A.innerhole&&(n.push(zo(h+1+A.left+A.right+(A.bottom??0)+g,Q-h*A.p,e/2,r,a)),n.push(zo(h+1+A.left+A.right+(A.bottom??0)+g*2,Q-h*A.p,e/2-A.innerholeedgedistance,r,a)))}}if(A.bottom){const Q=-((A.bottom-1)/2)*A.p;for(let h=0;h<A.bottom;h++){if(h===0&&!A.left&&!A.silkscreenlabels&&(s=UW(Q+h*A.p,-e/2+A.pl*1.4,"bottom")),i.push(di(h+1+A.left,Q+h*A.p,-e/2+A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const E=h+1+A.left,u=`pin${E}`;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:-e/2+A.pl+(I+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:90})}A.innerhole&&(n.push(zo(h+1+A.left+g,Q+h*A.p,-e/2,r,a)),n.push(zo(h+1+A.left+g*2,Q+h*A.p,-e/2+A.innerholeedgedistance,r,a)))}}const l={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_triangle_1",pcb_component_id:"2",route:s,stroke_width:.1,layer:"top"},B={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2,y:e/2},{x:A.w/2,y:e/2},{x:A.w/2,y:-e/2},{x:-A.w/2,y:-e/2},{x:-A.w/2,y:e/2}],stroke_width:.1,layer:"top"},C=Oi(0,e/1.8,e/25);return{circuitJson:[...i,...n,...o,B,...A.silkscreenlabels?[]:[l],C],parameters:A}},l6A=Wi.extend({fn:J(),w:hA.default("22.58mm"),h:hA.optional(),left:hA.optional().default(20),right:hA.optional().default(20),top:hA.optional().default(2),bottom:hA.optional().default(2),p:hA.default(hA.parse("2.54mm")),pw:hA.default(hA.parse("1.6mm")),pl:hA.default(hA.parse("3.2mm")),innerhole:ge().default(!1),innerholeedgedistance:hA.default(hA.parse("1.61mm"))}),eyt=t=>{const A=l6A.parse(t);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},tyt=(t,A,e,i=1,n=.6)=>{const o=i/2,s=n/2;return{left:[{x:t+o,y:A},{x:t-o,y:A+s},{x:t-o,y:A-s},{x:t+o,y:A}],right:[{x:t-o,y:A},{x:t+o,y:A+s},{x:t+o,y:A-s},{x:t-o,y:A}],top:[{x:t,y:A-o},{x:t-s,y:A+o},{x:t+s,y:A+o},{x:t,y:A-o}],bottom:[{x:t,y:A+o},{x:t-s,y:A-o},{x:t+s,y:A-o},{x:t,y:A+o}]}[e]},iyt=t=>{const A=l6A.parse(t),e=A.h??eyt(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=tyt(-A.w/2-A.pl/2,C-Q*A.p,"left")),i.push(di(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(zo(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(di(c,C-Q*A.p,-e/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:-e/2+A.pl/2-3.2},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(zo(c+a,C-Q*A.p,-e/2+A.innerholeedgedistance,s,r))}if(A.right){const C=-((A.right-1)/2)*A.p;for(let Q=0;Q<A.right;Q++)i.push(di(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(zo(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(di(c,C+Q*A.p,e/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:e/2-A.pl/2+3.2},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(zo(c+a,C+Q*A.p,e/2-A.innerholeedgedistance,s,r))}const I={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"1",pcb_component_id:"1",layer:"top",route:g,stroke_width:.1},l={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2-A.pl/3,y:e/2+A.pl/3},{x:A.w/2+A.pl/3,y:e/2+A.pl/3},{x:A.w/2+A.pl/3,y:-e/2-A.pl/3},{x:-A.w/2-A.pl/3,y:-e/2-A.pl/3},{x:-A.w/2-A.pl/3,y:e/2+A.pl/3}],stroke_width:.1,layer:"top"},B=Oi(0,e/1.8,e/25);return{circuitJson:[...o,...i,...n,l,I,B],parameters:A}},nyt=t=>(t.legsoutside=!0,t.pl||(t.pl=1.5),t.pw||(t.pw=.3),ev(t)),B6A=Wi.extend({fn:J(),w:hA.default("10mm"),h:hA.optional(),left:hA.optional().default(20),right:hA.optional().default(20),top:hA.optional().default(0),bottom:hA.optional().default(0),p:hA.default(hA.parse("2.54mm")),id:hA.optional().default(hA.parse("1mm")),od:hA.optional().default(hA.parse("1.5mm"))}),oyt=t=>{const A=B6A.parse(t);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},HW=(t,A,e,i=1,n=.6)=>{const o=i/2,s=n/2;return{left:[{x:t+o,y:A},{x:t-o,y:A+s},{x:t-o,y:A-s},{x:t+o,y:A}],right:[{x:t-o,y:A},{x:t+o,y:A+s},{x:t+o,y:A-s},{x:t-o,y:A}],top:[{x:t,y:A-o},{x:t-s,y:A+o},{x:t+s,y:A+o},{x:t,y:A-o}],bottom:[{x:t,y:A+o},{x:t-s,y:A-o},{x:t+s,y:A-o},{x:t,y:A+o}]}[e]},syt=t=>{const A=B6A.parse(t),e=A.h??oyt(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=HW(A.w/2+o*1.4,c+I*A.p,"right")),i.push(zo(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=HW(-A.w/2-o*1.4,c+I*A.p,"left")),i.push(zo(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=HW(c+I*A.p,e/2+o*1.4,"top")),i.push(zo(I+1+A.right+(A.bottom??0)+A.left,c+I*A.p,e/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=HW(c+I*A.p,-e/2-o*1.4,"bottom")),i.push(zo(I+1+A.left,c+I*A.p,-e/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:e/2+o},{x:A.w/2+o,y:e/2+o},{x:A.w/2+o,y:-e/2-o},{x:-A.w/2-o,y:-e/2-o},{x:-A.w/2-o,y:e/2+o}],stroke_width:.1,layer:"top"},g=Oi(0,e/1.7,e/25);return{circuitJson:[...i,a,g,r],parameters:A}},C6A=(t,A,e,i)=>Array.from({length:25},(n,o)=>{const s=o/24*Math.PI-Math.PI/2;return{x:t+(i==="right"?1:-1)*Math.cos(s)*e,y:A+Math.sin(s)*e}}),ryt=Wi.extend({fn:J(),p:hA.optional().default("4.88mm"),id:hA.optional().default("0.8mm"),od:hA.optional().default("1.5mm"),w:hA.optional().default("5.6mm"),h:hA.optional().default("3.5mm")}),ayt=t=>{const A=ryt.parse(t),{p:e,id:i,od:n,w:o,h:s}=A,r=s/2,a=[zo(1,-e/2,0,i,n),zo(2,e/2,0,i,n)],g=C6A(-o/2,0,r,"left"),c=C6A(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=Oi(0,e/4,.5);return{circuitJson:[...a,I,l],parameters:A}};Wi.extend({w:hA,h:hA});var gyt=t=>{const{w:A,h:e}=t,i=kr(A),n=kr(e);return{circuitJson:[di(1,0,0,i,n),Oi(0,n/2+.5,.2)],parameters:t}},pH=(t,A,e,i,n,o)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"pill",x:A,y:e,outer_width:kr(n),outer_height:kr(o),hole_width:kr(i),hole_height:kr(i),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()],ccw_rotation:0}),cyt=Wi.extend({fn:J(),num_pins:Wt([FA(3),FA(2)]).default(3),p:J().default("1.27mm"),id:J().default("0.72mm"),od:J().default("0.95mm"),w:J().default("4.5mm"),h:J().default("4.5mm"),inline:ge().default(!1),string:J().optional()}),Iyt=(t,A,e)=>Array.from({length:25},(i,n)=>{const o=n/24*Math.PI;return{x:t+Math.cos(o)*e,y:A+Math.sin(o)*e}}),lyt=t=>{const A=t.string?.match(/^to92_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=cyt.parse({...t,num_pins:e}),{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=[nb(1,-I,c-I,l,B,Q,0,0),pH(2,0,c-I,l,C,Q),pH(3,I,c-I,l,C,Q)]:h=[nb(1,-I,c-I,l,B,B,0,0),zo(2,0,c,l,B),zo(3,I,c-I,l,B)];else if(i.num_pins===2)h=[nb(1,-I,c-I,l,C,Q,0,0),pH(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=Iyt(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:""},p=Oi(0,c+1,.5);return{circuitJson:[...h,d,p],parameters:i}},Byt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("2.15mm"),h:J().default("1.20mm"),pl:J().default("0.5mm"),pw:J().default("0.6mm"),p:J().default("1.4mm")}),Cyt=t=>{const A=Byt.parse(t),e=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:hyt(A).concat(i,e),parameters:A}},Qyt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},hyt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=Qyt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Eyt=lD({}),uyt=t=>{const A=Eyt.parse(t),e=[];for(let s=0;s<A.num_pins;s++){const{x:r,y:a}=iEA({num_pins:A.num_pins,pn:s+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});e.push(di(s+1,r,a,A.pl??"1.5mm",A.pw??"0.6mm"))}const i=(A.num_pins/2-1)*A.p+A.pw,n=Oi(0,i/2-.5,i/12),o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-A.w/3,y:i/2+.2},{x:A.w/3,y:i/2+.2}],stroke_width:.1};return{circuitJson:[...e,n,o],parameters:A}},dyt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("5.0mm"),h:J().default("2.30mm"),pl:J().default("1.25mm"),pw:J().default("2mm"),p:J().default("3.75mm")}),pyt=t=>{const A=dyt.parse(t),e=Oi(0,hA.parse(A.h)/2+1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2+.5,y:hA.parse(A.h)/2+.5},{x:-hA.parse(A.w)/2-.5,y:hA.parse(A.h)/2+.5},{x:-hA.parse(A.w)/2-.5,y:-hA.parse(A.h)/2-.5},{x:hA.parse(A.p)/2+.5,y:-hA.parse(A.h)/2-.5}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:yyt(A).concat(i,e),parameters:A}},fyt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},yyt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=fyt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},myt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("4.4mm"),h:J().default("2.1mm"),pl:J().default("1.2mm"),pw:J().default("1.2mm"),p:J().default("2.9mm")}),wyt=t=>{const A=myt.parse(t),e=Oi(0,hA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Syt(A).concat(i,e),parameters:A}},Dyt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Syt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=Dyt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},byt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("3.30mm"),h:J().default("1.80mm"),pl:J().default("0.60mm"),pw:J().default("0.45mm"),p:J().default("2.1mm")}),xyt=t=>{const A=byt.parse(t),e=Oi(0,hA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:kyt(A).concat(i,e),parameters:A}},_yt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},kyt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=_yt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Fyt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("1.4mm"),h:J().default("0.9mm"),pl:J().default("0.36mm"),pw:J().default("0.25mm"),p:J().default("0.85mm")}),Gyt=t=>{const A=Fyt.parse(t),e=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2+.15,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.15,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.15,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2+.15,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Myt(A).concat(i,e),parameters:A}},Ryt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Myt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=Ryt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Nyt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("1.3mm"),h:J().default("0.9mm"),pl:J().default("0.4mm"),pw:J().default("0.7mm"),p:J().default("0.7mm")}),vyt=t=>{const A=Nyt.parse(t),e=Oi(0,hA.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2+.2,y:hA.parse(A.h)/2+.2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2+.2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2-.2},{x:hA.parse(A.p)/2+.2,y:-hA.parse(A.h)/2-.2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Uyt(A).concat(i,e),parameters:A}},Lyt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Uyt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=Lyt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Hyt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("3,05mm"),h:J().default("1.65mm"),pl:J().default("0.6mm"),pw:J().default("0.6mm"),pad_spacing:J().default("2.2mm")}),Yyt=t=>{const A=Hyt.parse(t),e=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.pad_spacing)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.pad_spacing)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Tyt(A).concat(i,e),parameters:A}},Jyt=t=>{const{pn:A,pad_spacing:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Tyt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=Jyt({pn:e,pad_spacing:Number.parseFloat(t.pad_spacing)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Kyt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("4.4mm"),h:J().default("2.1mm"),pl:J().default("1.2mm"),pw:J().default("1.2mm"),p:J().default("2.9mm")}),Pyt=t=>{const A=Kyt.parse(t),e=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Oyt(A).concat(i,e),parameters:A}},qyt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Oyt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=qyt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Wyt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("4.4mm"),h:J().default("2.1mm"),pl:J().default("0.91mm"),pw:J().default("1.22mm"),p:J().default("3.146mm")}),Zyt=t=>{const A=Wyt.parse(t),e=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:jyt(A).concat(i,e),parameters:A}},Vyt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},jyt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=Vyt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},zyt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("1.80mm"),h:J().default("1.00mm"),pl:J().default("0.66mm"),pw:J().default("0.5mm"),p:J().default("0.8mm")}),Xyt=t=>{const A=zyt.parse(t),e=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Amt(A).concat(i,e),parameters:A}},$yt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Amt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=$yt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},emt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("6.2mm"),h:J().default("3.4mm"),pl:J().default("1.4mm"),pw:J().default("2.1mm"),p:J().default("4.4mm")}),tmt=t=>{const A=emt.parse(t),e=Oi(0,hA.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:nmt(A).concat(i,e),parameters:A}},imt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},nmt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=imt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},omt=Wi.extend({fn:J(),num_pins:Wt([FA(3),FA(5)]).default(3),w:J().default("4.20mm"),h:J().default("4.80mm"),pl:J().default("1.3mm"),pw:J().default("0.9mm"),p:J().default("1.5mm"),string:J().optional()}),smt=t=>{const A=[],e=Number.parseFloat(t.p),i=Number.parseFloat(t.pw),n=Number.parseFloat(t.w),o=Number.parseFloat(t.pl),s=.175,r=(o-(o+s))/2;A.push(di(1,-n/2+r,e,o,i),di(2,-n/2,0,o+s,i),di(3,-n/2+r,-e,o,i));const a=Oi(0,0,.3),g=Number.parseFloat(t.w)/2-1,c=Number.parseFloat(t.h)/2,I={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-g,y:c},{x:g,y:c},{x:g,y:c/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},l={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-g,y:-c},{x:g,y:-c},{x:g,y:-c/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,I,l,a]},rmt=t=>{const A=[];Number.parseFloat(t.p),Number.parseFloat(t.pw),Number.parseFloat(t.w),A.push(di(1,-1.85,-1.5,1.5,.7),di(2,-1.85,1.5,1.5,.7),di(3,0,0,.8,2),di(4,1.85,-1.5,1.5,.7),di(5,1.85,1.5,1.5,.7));const e=Oi(0,Number.parseFloat(t.h)/2+.5,.3),i=Number.parseFloat(t.w)/2-1,n=Number.parseFloat(t.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,e]},amt=t=>{const A=t.string?.match(/^sot89_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=omt.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:smt(i),parameters:i};if(i.num_pins===5)return{circuitJson:rmt(i),parameters:i};throw new Error("Invalid number of pins for SOT89")},gmt=Wi.extend({fn:J(),p:hA.optional().default("5.0mm"),id:hA.optional().default("1.0mm"),od:hA.optional().default("1.9mm"),w:hA.optional().default("13mm"),h:hA.optional().default("7mm"),num_pins:WA().optional(),string:J().optional()}),cmt=t=>{const A=gmt.parse(t),{fn:e,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,D)=>{const w=a%2===0?(D-a/2+.5)*C:(D-Math.floor(a/2))*C;return zo(D+1,w,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:""}],p=Oi(0,s/2+.6,.5);return{circuitJson:[...Q,h,u,...d,p],parameters:{...A,p:C}}},Imt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("5.40mm"),h:J().default("2.30mm"),pl:J().default("1.30mm"),pw:J().default("1.70mm"),p:J().default("3.5mm")}),lmt=t=>{const A=Imt.parse(t),e=Oi(0,hA.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Cmt(A).concat(i,e),parameters:A}},Bmt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Cmt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=Bmt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Qmt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("1.90mm"),h:J().default("1.33mm"),pl:J().default("0.5mm"),pw:J().default("0.7mm"),p:J().default("0.8mm")}),hmt=t=>{const A=Qmt.parse(t),e=Oi(0,hA.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2+.1,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2+.1,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:umt(A).concat(i,e),parameters:A}},Emt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},umt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=Emt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},dmt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("7.0mm"),h:J().default("3.35mm"),pl:J().default("1.50mm"),pw:J().default("2.70mm"),p:J().default("4.8mm")}),pmt=t=>{const A=dmt.parse(t),e=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:ymt(A).concat(i,e),parameters:A}},fmt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},ymt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=fmt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},mmt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("3.0mm"),h:J().default("1.80mm"),pl:J().default("0.80mm"),pw:J().default("1.20mm"),p:J().default("1.6mm")}),wmt=t=>{const A=mmt.parse(t),e=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Smt(A).concat(i,e),parameters:A}},Dmt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Smt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=Dmt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},bmt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("7.10mm"),h:J().default("3.40mm"),pl:J().default("2.45mm"),pw:J().default("1.80mm"),p:J().default("4.05mm")}),xmt=t=>{const A=bmt.parse(t),e=Oi(0,hA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.5,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.5,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:kmt(A).concat(i,e),parameters:A}},_mt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},kmt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=_mt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Fmt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("4.80mm"),h:J().default("2.10mm"),pl:J().default("1.30mm"),pw:J().default("1.40mm"),p:J().default("2.9mm")}),Gmt=t=>{const A=Fmt.parse(t),e=Oi(0,hA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Mmt(A).concat(i,e),parameters:A}},Rmt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Mmt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=Rmt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Nmt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("7.30mm"),h:J().default("4.40mm"),pl:J().default("2.50mm"),pw:J().default("2.30mm"),p:J().default("4.30mm")}),vmt=t=>{const A=Nmt.parse(t),e=Oi(0,hA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Umt(A).concat(i,e),parameters:A}},Lmt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Umt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=Lmt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Hmt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("10.70mm"),h:J().default("6.60mm"),pl:J().default("3.30mm"),pw:J().default("2.50mm"),p:J().default("6.80mm")}),Ymt=t=>{const A=Hmt.parse(t),e=Oi(0,3,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2-.8},{x:-hA.parse(A.w)/2-.8,y:hA.parse(A.h)/2-.8},{x:-hA.parse(A.w)/2-.8,y:-hA.parse(A.h)/2+.8},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2+.8}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Tmt(A).concat(i,e),parameters:A}},Jmt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Tmt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=Jmt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Kmt=Wi.extend({fn:J(),num_pins:WA().default(4),w:J().default("8.50mm"),h:J().default("6.90mm"),pl:J().default("2mm"),pw:J().default("1.5mm"),p:J().default("2.30mm"),string:J().optional()}),Pmt=t=>{const A=t.string?.match(/^sot223_(\d+)/),e=A?Number.parseInt(A[1],10):4;if(e===8){const n=Wmt.parse({...t,num_pins:e});return{circuitJson:E_(n),parameters:n}}const i=Kmt.parse({...t,num_pins:e});if(i.num_pins===4)return{circuitJson:Omt(i),parameters:i};if(i.num_pins===5)return{circuitJson:Vmt(i),parameters:i};if(i.num_pins===6)return{circuitJson:zmt(i),parameters:i};throw new Error("Invalid number of pins")},qmt=t=>{const{pn:A,w:e,p:i}=t;return A===1?{x:-e/2+1.1,y:i}:A===2?{x:-e/2+1.1,y:0}:A===3?{x:-e/2+1.1,y:-i}:{x:e/2-1.1,y:0}},Omt=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=qmt({num_pins:t.num_pins,pn:r+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)}),c=r===3?3.8:Number.parseFloat(t.pw);A.push(di(r+1,a,g,Number.parseFloat(t.pl),c))}const e=Oi(0,0,.3),i=Number.parseFloat(t.w)/2-2.4,n=Number.parseFloat(t.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,e]},Wmt=lD({p:"0.90mm",w:"2.8mm",legsoutside:!0}),Zmt=t=>{const{p:A,pn:e,w:i}=t;if(e===1)return{x:-i/2+1.2,y:A/2+A};if(e===2)return{x:-i/2+1.2,y:A/2};if(e===3)return{x:-i/2+1.2,y:-A/2};if(e===4)return{x:-i/2+1.2,y:-A/2-A};if(e===5)return{x:i/2-1,y:0};throw new Error("Invalid pin number")},Vmt=t=>{const A=[];for(let r=1;r<=t.num_pins;r++){const{x:a,y:g}=Zmt({h:Number.parseFloat(t.h),p:1.5,pn:r,w:Number.parseFloat(t.w)});let c=Number.parseFloat(t.pw),I=Number.parseFloat(t.pl);r===5?(c=3.4,I=1.8):(c=1,I=2.2),A.push(di(r,a,g,I,c))}const e=Number.parseFloat(t.w)/2-2.4,i=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e,y:i},{x:e,y:i},{x:e,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e,y:-i},{x:e,y:-i},{x:e,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Oi(0,0,.3);return[...A,n,o,s]},jmt=t=>{const{p:A,pn:e,w:i}=t;if(e===1)return{x:-i/2+1.2,y:2*A};if(e===2)return{x:-i/2+1.2,y:A};if(e===3)return{x:-i/2+1.2,y:0};if(e===4)return{x:-i/2+1.2,y:-A};if(e===5)return{x:-i/2+1.2,y:-2*A};if(e===6)return{x:i/2-1.175,y:0};throw new Error("Invalid pin number")},zmt=t=>{const A=[];for(let r=1;r<=t.num_pins;r++){const{x:a,y:g}=jmt({h:Number.parseFloat(t.h),p:1.3,pn:r,w:8.7});let c=Number.parseFloat(t.pw),I=Number.parseFloat(t.pl);r===6?(c=3.4,I=2.15):(c=.6,I=2.2),A.push(di(r,a,g,I,c))}const e=Number.parseFloat(t.w)/2-2.4,i=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e,y:i},{x:e,y:i},{x:e,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e,y:-i},{x:e,y:-i},{x:e,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Oi(0,0,.3);return[...A,n,o,s]},Xmt=Wi.extend({fn:J(),num_pins:WA().default(3),w:J().default("3.40mm"),h:J().default("3.30mm"),pl:J().default("1mm"),pw:J().default("0.7mm"),p:J().default("1.2mm"),string:J().optional()}),$mt=t=>{const A=t.string?.match(/^sot23w_(\d+)/),e=A?Number.parseInt(A[1],3):3,i=Xmt.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:ewt(i),parameters:i};throw new Error("Invalid number of pins")},Awt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e,y:.95}:A===2?{x:-e,y:-.95}:{x:e,y:0}},ewt=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=Awt({num_pins:t.num_pins,pn:r+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(di(r+1,a,g,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=Oi(0,Number.parseInt(t.h)/2+1,.3),i=Number.parseFloat(t.w)/2-1,n=Number.parseFloat(t.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,e]},twt=Wi.extend({fn:J(),num_pins:Wt([FA(3),FA(2)]).default(3),p:J().default("1.27mm"),id:J().default("0.72mm"),od:J().default("0.95mm"),w:J().default("2.5mm"),h:J().default("4.2mm"),string:J().optional()}),iwt=t=>{const{p:A,id:e,od:i,w:n,h:o}=t,s=Number.parseFloat(o)/2,r=Number.parseFloat(A);return[zo(1,-r,s-r,e,i),zo(2,0,s-r,e,i),zo(3,r,s-r,e,i)]},nwt=t=>{const{p:A,id:e,od:i,h:n}=t,o=Number.parseFloat(n)/2,s=Number.parseFloat(A);return[zo(1,-s,o-s,e,i),zo(2,s,o-s,e,i)]},owt=t=>{const A=t.string?.match(/^to92s_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=twt.parse({...t,num_pins:e});let n=[];if(i.num_pins===3)n=iwt(i);else if(i.num_pins===2)n=nwt(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=Oi(0,o+1,.5);return{circuitJson:[...n,r,a],parameters:i}},swt=Wi.extend({fn:J(),p:hA.optional(),id:hA.optional(),pw:hA.optional(),pl:hA.optional(),w:hA.optional(),h:hA.optional(),sh:Wt([ge(),J(),WA()]).optional().transform(t=>{if(typeof t=="string"){const A=Number(t);return Number.isNaN(A)?!0:A}return t}).describe('JST SH (Surface-mount) connector family. SH stands for "Super High-density".'),ph:ge().optional().describe('JST PH (Through-hole) connector family. PH stands for "Pin Header".'),string:J().optional()}),rwt={ph:{p:hA.parse("2.2mm"),id:hA.parse("0.70mm"),pw:hA.parse("1.20mm"),pl:hA.parse("1.20mm"),w:hA.parse("6mm"),h:hA.parse("5mm")},sh:{p:hA.parse("1mm"),pw:hA.parse("0.6mm"),pl:hA.parse("1.55mm"),w:hA.parse("5.8mm"),h:hA.parse("7.8mm")}};function awt(t){return t.sh?"sh":(t.ph,"ph")}function gwt(t,A,e,i,n,o){const s=[];if(t==="ph"){const r=e/2;s.push(nb(1,-r,2,i,n,o)),s.push(nb(2,r,2,i,n,o))}else{const r=-((A-1)/2)*e;for(let g=0;g<A;g++){const c=r+g*e;console.log("x si",c),s.push(di(g+1,c,-1.325,n,o))}const a=(A-1)/2*e+1.3;console.log("offset",a),s.push(di(A+1,-a,1.22,1.2,1.8)),s.push(di(A+2,a,1.22,1.2,1.8))}return s}function cwt(t,A,e){return t==="ph"?{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-3,y:3},{x:3,y:3},{x:3,y:-2},{x:-3,y:-2},{x:-3,y:3}],stroke_width:.1,pcb_silkscreen_path_id:""}:{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[],stroke_width:.1,pcb_silkscreen_path_id:""}}var Iwt=t=>{const A=swt.parse(t),e=awt(A),i=rwt[e],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=e==="sh"?4:2;if(e==="sh"){const Q=(typeof t.string=="string"?t.string:"").match(/sh(\d+)/);if(Q&&Q[1]){const h=parseInt(Q[1],10);Number.isNaN(h)||(c=h)}else typeof A.sh=="number"&&(c=A.sh)}const I=gwt(e,c,n,o,s,r),l=cwt(e),B=Oi(0,g/2+1,.5);return{circuitJson:[...I,l,B],parameters:{...A,p:n,id:o,pw:s,pl:r,w:a,h:g,num_pins:c,sh:e==="sh",ph:e==="ph"}}},lwt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("3.30mm"),h:J().default("1.70mm"),pl:J().default("0.80mm"),pw:J().default("1mm"),p:J().default("1.90mm")}),Bwt=t=>{const A=lwt.parse(t),e=Oi(0,hA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Qwt(A).concat(i,e),parameters:A}},Cwt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Qwt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=Cwt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},hwt=t=>{switch(t){case 8:return{w:"3.06mm",h:"3.14mm",p:"0.65mm",pl:"1.6mm",pw:"0.5mm"};case 10:return{w:"3.10mm",h:"3.33mm",p:"0.5mm",pl:"1.45mm",pw:"0.3mm"};default:return{w:"3.06mm",h:"3.14mm",p:"0.65mm",pl:"1.6mm",pw:"0.5mm"}}},Ewt=Wi.extend({fn:J(),num_pins:Wt([FA(8),FA(10)]).default(8),w:J().optional(),h:J().optional(),p:J().optional(),pl:J().optional(),pw:J().optional(),string:J().optional()}),uwt=t=>{const A=Ewt.parse(t),e=hwt(A.num_pins),i=hA.parse(A.w||e.w),n=hA.parse(A.h||e.h),o=hA.parse(A.p||e.p),s=hA.parse(A.pl||e.pl),r=hA.parse(A.pw||e.pw),a=[],g=A.num_pins/2;for(let u=0;u<A.num_pins;u++){const{x:d,y:p}=Q6A(A.num_pins,u+1,i,o),m=u<g?u+1:A.num_pins-(u-g);a.push(di(m,d,p,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=Q6A(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=Oi(0,I/2+.5,.3);return{circuitJson:[...a,l,B,E,h],parameters:A}},Q6A=(t,A,e,i)=>{const n=t/2,o=(A-1)%n,s=A<=n?-1:1,r=(n-1)/2-o;return{x:s*hA.parse(t===8?"1.8mm":"2.2mm"),y:r*i}},dwt=t=>{switch(t){case 10:return{w:"3.10mm",h:"3.32mm",p:"0.5mm",pl:"1.63mm",pw:"0.33mm"};case 12:return{w:"3mm",h:"4mm",p:"0.65mm",pl:"0.88mm",pw:"0.4mm"};case 16:return{w:"3.10mm",h:"4mm",p:"0.5mm",pl:"0.88mm",pw:"0.3mm"};default:return{w:"3.10mm",h:"3.32mm",p:"0.65mm",pl:"1.63mm",pw:"0.4mm"}}},pwt=Wi.extend({fn:J(),num_pins:Wt([FA(8),FA(10),FA(12),FA(16)]).default(8),w:J().optional(),h:J().optional(),p:J().optional(),pl:J().optional(),pw:J().optional(),string:J().optional()}),h6A=(t,A,e,i)=>{const n=t/2,o=(A-1)%n,s=A<=n?-1:1,r=(n-1)/2-o;return{x:s*hA.parse("2mm"),y:r*i}},fwt=t=>{const A=pwt.parse(t),e=dwt(A.num_pins),i=hA.parse(A.w||e.w),n=hA.parse(A.h||e.h),o=hA.parse(A.p||e.p),s=hA.parse(A.pl||e.pl),r=hA.parse(A.pw||e.pw),a=[];for(let E=0;E<A.num_pins;E++){const{x:u,y:d}=h6A(A.num_pins,E+1,i,o);a.push(di(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=h6A(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=Oi(0,c/2+.5,.3);return{circuitJson:[...a,I,l,h,Q],parameters:A}},ywt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("3.8mm"),h:J().default("1.65mm"),pl:J().default("1.2mm"),pw:J().default("1.2mm"),pad_spacing:J().default("2.6mm")}),mwt=t=>{const A=ywt.parse(t),e=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.pad_spacing)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.pad_spacing)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Dwt(A).concat(i,e),parameters:A}},wwt=t=>{const{pn:A,pad_spacing:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Dwt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=wwt({pn:e,pad_spacing:Number.parseFloat(t.pad_spacing)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Swt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("3.20mm"),h:J().default("1.65mm"),pl:J().default("0.8mm"),pw:J().default("0.9mm"),pad_spacing:J().default("2.1mm")}),bwt=t=>{const A=Swt.parse(t),e=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.pad_spacing)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.pad_spacing)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:_wt(A).concat(i,e),parameters:A}},xwt=t=>{const{pn:A,pad_spacing:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},_wt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=xwt({pn:e,pad_spacing:Number.parseFloat(t.pad_spacing)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},kwt=Wi.extend({fn:J(),num_pins:Wt([FA(6),FA(8)]).default(8),w:J().default("3mm"),h:J().default("3mm"),p:J().default("0.5mm"),pl:J().default("0.52mm"),pw:J().default("0.35mm"),epw:J().default("1.40mm"),eph:J().default("1.60mm"),string:J().optional(),ep:ge().default(!1)}),Fwt=t=>{t.string&&t.string.includes("_ep")&&(t.ep=!0);const A=t.string?.match(/^son_(\d+)/),e=A?Number.parseInt(A[1],10):t.num_pins||8,i=kwt.parse({...t,num_pins:e}),n=hA.parse(i.w),o=hA.parse(i.h),s=hA.parse(i.p),r=hA.parse(i.pl),a=hA.parse(i.pw),g=hA.parse(i.epw),c=hA.parse(i.eph),I=[];for(let p=0;p<i.num_pins;p++){const{x:m,y:D}=E6A(i.num_pins,p+1,n,s);I.push(di(p+1,m,D,r,a))}i.ep&&I.push(di(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=E6A(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=Oi(0,B/2+.5,.3);return{circuitJson:[...I,C,Q,d,u],parameters:i}},E6A=(t,A,e,i)=>{const n=t/2,o=(A-1)%n,s=A<=n?-1:1,r=(n-1)/2-o;return{x:s*hA.parse("1.4mm"),y:r*i}},Gwt=t=>{const{num_pins:A,bridged:e,p:i=2.54,pw:n=1.5,ph:o=1.5}=t,s=hA.parse(i),r=hA.parse(n),a=hA.parse(o),g=Math.min(a/4,.5),c=[];for(let p=0;p<A;p++)c.push(di(p+1,p*s,0,r,a));let I=[];if(e){const p=e.split("").map(Number);if(p.length>1)for(let m=0;m<p.length-1;m++){const D=p[m],w=p[m+1];if(typeof D=="number"&&typeof w=="number"&&!isNaN(D)&&!isNaN(w)){const S=(D-1)*s,k=(w-1)*s,x=Math.sign(k-S),N=S+x*(r/2),M=k-x*(r/2);I.push({type:"pcb_trace",pcb_trace_id:"",route:[{start_pcb_port_id:`{PIN${D}}`,x:N,y:0,width:g,layer:"top",route_type:"wire"},{end_pcb_port_id:`{PIN${w}}`,x:M,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=Oi(C,u,.4);return{circuitJson:[...c,...I,h,d],parameters:t}},u6A={fn:FA("sot457"),num_pins:FA(6).default(6),pillh:J().default("0.45mm"),pillw:J().default("1.45mm"),pl:J(),pw:J(),p:J(),wave:ge().optional(),reflow:ge().optional()},Rwt=Wi.extend({...u6A,h:J().default("2.5mm"),w:J().default("2.7mm"),pl:J().default("0.8mm"),pw:J().default("0.55mm"),p:J().default("0.95mm")}),Mwt=Wi.extend({...u6A,h:J().default("3mm"),w:J().default("4mm"),pillr:J().default("0.225mm"),pl:J().default("1.45mm"),pw:J().default("1.5mm"),p:J().default("1.475mm")}).transform(t=>({...t,wave:t.wave??(t.reflow===void 0?!0:!t.reflow),reflow:t.reflow??(t.wave===void 0?!1:!t.wave)})),ob=t=>Number.parseFloat(t.replace("mm","")),d6A=({pitch:t,width:A,pinNumber:e})=>{const o={1:{x:-A/2-.1,y:t},2:{x:-A/2-.1,y:0},3:{x:-A/2-.1,y:-t},4:{x:A/2+.1,y:-t},5:{x:A/2+.1,y:0},6:{x:A/2+.1,y:t}}[e];if(!o)throw new Error(`Invalid pin number: ${e}`);return o},p6A=t=>{const A=[],e=ob(t.p),i=ob(t.pl),n=ob(t.pw),o=ob(t.w),s=ob(t.h);if(t.wave){const C={1:({padWidth:Q,padHeight:h})=>di(1,-e,e,h,Q),2:({padWidth:Q,padHeight:h})=>di(2,-e,-e,h,Q),3:({padWidth:Q,padHeight:h})=>vW(3,-e,0,ob(t.pillw),ob(t.pillh)),4:({padWidth:Q,padHeight:h})=>vW(4,e,0,ob(t.pillw),ob(t.pillh)),5:({padWidth:Q,padHeight:h})=>di(5,e,e,h,Q),6:({padWidth:Q,padHeight:h})=>di(6,e,-e,h,Q)};for(let Q=1;Q<=t.num_pins;Q++){const h=C[Q];h&&A.push(h({padWidth:i,padHeight:n}))}}else for(let C=1;C<=t.num_pins;C++){const{x:Q,y:h}=d6A({pitch:e,width:o,pinNumber:C});A.push(di(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+e/1.3},{x:o/3,y:s/2+e/1.3}],stroke_width:.05},a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-o/3,y:-s/2-e/1.3},{x:o/3,y:-s/2-e/1.3}],stroke_width:.05},g=Oi(0,s+.5,.3),c=d6A({pitch:e,width:o,pinNumber:1}),I=t.wave?1:.5,l=t.wave?.7:.3;c.x-=t.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]},Nwt=t=>{if(t.wave){const e=Mwt.parse({...t,fn:"sot457"});return{circuitJson:p6A(e),parameters:e}}const A=Rwt.parse(t);return{circuitJson:p6A(A),parameters:A}},vwt=Wi.extend({fn:J(),num_pins:FA(6).default(6),w:J().default("1.1mm"),h:J().default("1.45mm"),p:J().default("0.35mm"),pl:J().default("0.2mm"),pw:J().default("0.2mm"),string:J().optional()}),Lwt=t=>{const A=vwt.parse({...t,fn:"sot963"}),e=hA.parse(A.w),i=hA.parse(A.h),n=hA.parse(A.p),o=hA.parse(A.pl),s=hA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=f6A(B+1,e,n,o);r.push(di(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:i/2},{x:e/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:-i/2},{x:e/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=f6A(1,e,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=Oi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},f6A=(t,A,e,i)=>{const n=A/2-i/2;return t<=3?{x:-n,y:e-(t-1)*e}:{x:n,y:-e+(t-4)*e}},Uwt=Wi.extend({fn:J(),num_pins:Wt([FA(3),FA(2)]).default(3),p:J().default("3.8mm"),id:J().default("1.25mm"),od:J().default("2.35mm"),ca:J().default("14mm").describe("Caliper axis (width or diameter of the potentiometer body or adjustment knob)"),w:J().default("5.35mm"),h:J().default("4mm"),string:J().optional()}),Hwt=t=>{const{p:A,id:e,od:i,h:n,ca:o}=t,s=Number.parseFloat(n),r=Number.parseFloat(o);return[zo(1,0,r/4+.3,e,i),zo(2,s,0,e,i),zo(3,0,-r/4-.3,e,i)]},Ywt=t=>{const A=t.string?.match(/^potentiometer_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=Uwt.parse({...t,num_pins:e});let n=[];i.num_pins===3&&(n=Hwt(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=Oi(c,o+1,.5);return{circuitJson:[...n,a,g,I],parameters:i}},Jwt=Wi.extend({fn:J(),p:hA.optional().default("7.5mm"),id:hA.optional().default("1mm"),od:hA.optional().default("2mm"),d:hA.optional().default("10.5mm")}),Twt=(t,A,e,i,n)=>{const o=[],s=[];for(let r=0;r<=50;r++){const a=r/50*Math.PI,g=t+Math.cos(a)*e,c=A+Math.sin(a)*e;g<t-i&&c>=A-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=t+Math.cos(a)*e,c=A+Math.sin(a)*e;g<t-i&&c>=A-n/2&&c<=A+n/2||s.push({x:g,y:c})}return{topArc:o,bottomArc:s}},Kwt=t=>{const A=Jwt.parse(t),{p:e,id:i,od:n,d:o}=A,s=[zo(1,-e/2,0,i,n),zo(2,e/2,0,i,n)],{topArc:r,bottomArc:a}=Twt(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=Oi(0,o/2+1,.5);return{circuitJson:[...s,g,c,I,Q,h,E],parameters:A}},Pwt=Wi.extend({fn:J(),num_pins:FA(2).default(2),w:J().default("6.5mm"),h:J().default("3mm"),pl:J().default("1.75mm"),pw:J().default("2.40mm"),p:J().default("4.75mm")}),qwt=t=>{const A=Pwt.parse(t),e=Oi(0,hA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.3,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.3,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Wwt(A).concat(i,e),parameters:A}},Owt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Wwt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=Owt({pn:e,p:Number.parseFloat(t.p)});A.push(di(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Zwt=Wi.extend({fn:J(),num_pins:WA().default(3),w:J().default("2.45mm"),h:J().default("2.40mm"),pl:J().default("1.225mm"),pw:J().default("0.5mm"),p:J().default("0.95mm"),string:J().optional()}),Vwt=t=>{const A=t.string?.match(/^sot323_(\d+)/),e=A?Number.parseInt(A[1],3):3,i=Zwt.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:zwt(i),parameters:i};throw new Error("Invalid number of pins")},jwt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e,y:.65}:A===2?{x:-e,y:-.65}:{x:e,y:0}},zwt=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=jwt({num_pins:t.num_pins,pn:r+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(di(r+1,a,g,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=Oi(0,Number.parseInt(t.h)/2+1,.3),i=Number.parseFloat(t.w)/2-Number.parseFloat(t.pl),n=Number.parseFloat(t.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,e]},Xwt=Wi.extend({fn:J(),circle:ge().optional(),rect:ge().optional(),square:ge().optional(),pill:ge().optional(),d:hA.optional(),pd:hA.optional(),diameter:hA.optional(),r:hA.optional(),pr:hA.optional(),radius:hA.optional(),w:hA.optional(),pw:hA.optional(),width:hA.optional(),h:hA.optional(),ph:hA.optional(),height:hA.optional(),s:hA.optional(),size:hA.optional(),string:J().optional()}).transform(t=>{let A="rect";t.circle&&(A="circle"),t.square&&(A="square"),t.rect&&(A="rect"),t.pill&&(A="pill");let e,i,n;return A==="circle"?t.r!==void 0?e=kr(t.r):t.pr!==void 0?e=kr(t.pr):t.radius!==void 0?e=kr(t.radius):t.d!==void 0?e=kr(t.d)/2:t.pd!==void 0?e=kr(t.pd)/2:t.diameter!==void 0?e=kr(t.diameter)/2:e=kr("1mm")/2:(t.w!==void 0?i=kr(t.w):t.pw!==void 0?i=kr(t.pw):t.width!==void 0?i=kr(t.width):t.s!==void 0?i=kr(t.s):t.size!==void 0?i=kr(t.size):i=kr("1mm"),t.h!==void 0?n=kr(t.h):t.ph!==void 0?n=kr(t.ph):t.height!==void 0?n=kr(t.height):A==="square"||A==="rect"?n=i:n=kr("1mm")),{fn:t.fn,shape:A,radius:e,width:i,height:n}}),$wt=t=>{const A=Xwt.parse(t),{shape:e,radius:i,width:n,height:o}=A;let s,r;return e==="circle"?(s=e6A(1,{x:0,y:0,radius:i}),r=i+.5):e==="pill"?(s=vW(1,0,0,n,o),r=Math.max(n,o)/2+.5):(s=di(1,0,0,n,o),r=o/2+.5),{circuitJson:[s,Oi(0,r,.2)],parameters:A}},ADt=Wi.extend({fn:J(),d:hA.optional(),hd:hA.optional(),r:hA.optional(),hr:hA.optional(),pd:hA.optional(),pr:hA.optional(),squarepad:ge().optional().default(!1)}).transform(t=>{let A;t.d!==void 0?A=kr(t.d):t.hd!==void 0?A=kr(t.hd):t.r!==void 0?A=kr(t.r)*2:t.hr!==void 0?A=kr(t.hr)*2:A=kr("1mm");let e;return t.pd!==void 0?e=kr(t.pd):t.pr!==void 0?e=kr(t.pr)*2:e=A*(1.5/1),{fn:t.fn,d:A,pd:e,squarepad:t.squarepad??!1}}),eDt=t=>{const A=ADt.parse(t),{d:e,pd:i,squarepad:n}=A;return{circuitJson:[n?nb(1,0,0,e,i,i):zo(1,0,0,e,i),Oi(0,i/2+.5,.2)],parameters:A}},tDt=Wi.extend({fn:J(),num_pins:FA(6).default(6),h:J().default("1.6mm"),pl:J().default("1mm"),pw:J().default("0.7mm"),p:J().default("0.95mm")}),iDt=t=>{const A=tDt.parse(t);return{circuitJson:nDt(A),parameters:A}},y6A=t=>{const{p:A,h:e,pn:i}=t;if(i===1)return{x:-e/2-.5,y:A};if(i===2)return{x:-e/2-.5,y:0};if(i===3)return{x:-e/2-.5,y:-A};if(i===4)return{x:e/2+.5,y:-A};if(i===5)return{x:e/2+.5,y:0};if(i===6)return{x:e/2+.5,y:A};throw new Error("Invalid pin number")},nDt=t=>{const A=[];for(let I=1;I<=t.num_pins;I++){const{x:l,y:B}=y6A({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:I});A.push(di(I,l,B,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=t.num_pins/2*Number.parseFloat(t.p),i=Number.parseFloat(t.h),n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e/3,y:i/2+Number.parseFloat(t.p)/1.3},{x:e/3,y:i/2+Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e/3,y:-i/2-Number.parseFloat(t.p)/1.3},{x:e/3,y:-i/2-Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Oi(0,i+.3,.3),r=y6A({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});r.x=r.x-Number.parseFloat(t.pw)*1.5;const a=.7,g=.3,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:r.x+a/2,y:r.y},{x:r.x-a/2,y:r.y+g/2},{x:r.x-a/2,y:r.y-g/2},{x:r.x+a/2,y:r.y}],stroke_width:.05};return[...A,s,n,o,c]},oDt=Wi.extend({fn:J(),num_pins:WA().default(4),w:J().default("3.2mm"),h:J().default("2.6mm"),pl:J().default("1.35mm"),pw:J().default("0.50mm"),p:J().default("0.6mm"),string:J().optional()}),sDt=t=>{const A=t.string?.match(/^sot343_(\d+)/),e=A?Number.parseInt(A[1],4):4,i=oDt.parse({...t,num_pins:e});if(i.num_pins===4)return{circuitJson:aDt(i),parameters:i};throw new Error("Invalid number of pins")},rDt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e*1.92,y:-.65}:A===2?{x:-e*1.92,y:.65}:A===3?{x:e,y:.65}:A===4?{x:e,y:-.65}:{x:0,y:0}},aDt=t=>{const A=[],e=Number.parseFloat(t.w),i=Number.parseFloat(t.h),n=Number.parseFloat(t.pl),o=Number.parseFloat(t.pw),s=Number.parseFloat(t.p);let r=1/0,a=-1/0,g=1/0,c=-1/0;for(let d=0;d<t.num_pins;d++){const{x:p,y:m}=rDt({num_pins:t.num_pins,pn:d+1,p:s});A.push(di(d+1,p,m,n,o)),p<r&&(r=p),p>a&&(a=p),m<g&&(g=m),m>c&&(c=m)}const I=(r+a)/2,l=c-g,B=i*.3,C=l/2+B;let Q=e*.8;i<=2.6&&(Q/=2);const h=Oi(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]},gDt=Wi.extend({fn:J()}),cDt=t=>{const A=gDt.parse(t),e=[],i=.5-.15,n=1.5,s=.5/2,r=75,a=-37/2;for(let w=0;w<r;w++){const S=w+1;if(S>=24&&S<=31)continue;const k=a-w*s,x=S%2===0,N=n+(x?.25:0),L=.5-N/2,Y=di(S,L,k,N,i);Y.layer=x?"bottom":"top",e.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=(w,S,k=0,x=0)=>{Q=Math.min(Q,w-k/2),h=Math.max(h,w+k/2),E=Math.min(E,S-x/2),u=Math.max(u,S+x/2)};for(const w of e)d(w.x,w.y,w.width,w.height);d(l.center.x,l.center.y,l.width,l.height);for(const w of C.route)d(w.x,w.y);const p=(Q+h)/2,m=(E+u)/2,D=w=>{typeof w.x=="number"&&(w.x-=p),typeof w.y=="number"&&(w.y-=m),w.center&&(w.center.x-=p,w.center.y-=m),Array.isArray(w.route)&&(w.route=w.route.map(S=>({x:S.x-p,y:S.y-m})))};for(const w of e)D(w);return D(l),D(C),{circuitJson:[...e,l,C],parameters:A}},IDt=Wi.extend({fn:J(),num_pins:WA().default(3),inline:ge().default(!1),p:J().default("1.27mm"),id:J().default("0.75mm"),od:J().default("1.3mm"),w:J().default("4.8mm"),h:J().default("4.0mm")}),lDt=t=>{const A=IDt.parse(t),e=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=[nb(1,0,0,A.id,o,s,0,0),A.inline?pH(2,e,0,A.id,o,s):zo(2,e,e,A.id,o),A.inline?pH(3,e*2,0,A.id,o,s):zo(3,e*2,0,A.id,o)],a=i/2,g=A.inline?e-.09:e,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=Oi(g,c+a+1,.5);return{circuitJson:[...r,B,C],parameters:A}};function BDt(t){return t!=null}var CDt=(t,A)=>{if(!A)return t;const e=t.filter(c=>c.type==="pcb_smtpad"||c.type==="pcb_plated_hole"||c.type==="pcb_thtpad");if(e.length===0)return t;let i=1/0,n=-1/0,o=1/0,s=-1/0;const r=(c,I,l=0,B=0)=>{const C=c-l/2,Q=c+l/2,h=I-B/2,E=I+B/2;i=Math.min(i,C),n=Math.max(n,Q),o=Math.min(o,h),s=Math.max(s,E)};for(const c of e)if(c.type==="pcb_smtpad"){const I=c.shape==="circle"?c.radius*2:c.width,l=c.shape==="circle"?c.radius*2:c.height;r(c.x,c.y,I,l)}else if(c.type==="pcb_plated_hole"){const I=c.outer_diameter??c.hole_diameter;r(c.x,c.y,I,I)}else if(c.type==="pcb_thtpad"){const I=c.diameter;r(c.x,c.y,I,I)}let a=0,g=0;switch(A){case"center":a=(i+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=e.find(I=>I.port_hints?.[0]==="1")||e[0];a=c.x,g=c.y;break}if(a===0&&g===0)return t;for(const c of t){if(typeof c.x=="number"&&(c.x-=a),typeof c.y=="number"&&(c.y-=g),c.center&&typeof c.center.x=="number"&&(c.center.x-=a,c.center.y-=g),c.type==="pcb_silkscreen_path")for(const I of c.route)I.x-=a,I.y-=g;c.type==="pcb_silkscreen_text"&&c.anchor_position&&(c.anchor_position.x-=a,c.anchor_position.y-=g)}return t},QDt=(t,A)=>{const e=t.filter(i=>i.type==="pcb_silkscreen_text");if(e.length===0)return t;for(const i of e)A.norefdes&&(i.text="");return t},hDt=(t,A)=>A.nosilkscreen?t.filter(e=>e.type!=="pcb_silkscreen_path"&&e.type!=="pcb_silkscreen_text"):t,EDt=t=>{let A=YW();const i=t.replace(/^((?:\d{4}|\d{5}))(?=$|_)/,"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(BDt);for(const{fn:n,v:o}of i)A=A[n](o);return A.setString(t),A},uDt=()=>Object.keys(ib),YW=()=>{const t=new Proxy({},{get:(A,e)=>{if(e==="soup"||e==="circuitJson"){if("fn"in A&&ib[A.fn])return()=>{const{circuitJson:i}=ib[A.fn](A),n=hDt(i,A),o=QDt(n,A);return CDt(o,A.origin)};if(!ib[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>{throw new Error(`No function found for footprinter, make sure to specify .dip, .lr, .p, etc. Got "${e}"`)}}if(e==="json"){if(!ib[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>ib[A.fn](A).parameters}return e==="getFootprintNames"?()=>Object.keys(ib):e==="params"?()=>A:e==="setString"?i=>(A.string=i,t):i=>(Object.keys(A).length===0?`${e}${i}`in ib?(A[`${e}${i}`]=!0,A.fn=`${e}${i}`):(A[e]=!0,A.fn=e,e==="res"||e==="cap"?i&&(typeof i=="string"&&i.includes("_metric")?A.metric=i.split("_metric")[0]:A.imperial=i):A.num_pins=Number.isNaN(Number.parseFloat(i))?void 0:Number.parseFloat(i)):!i&&["w","h","p"].includes(e)||(A[e]=i??!0),t)}});return t};YW.string=EDt,YW.getFootprintNames=uDt;var dDt=YW,m6A=Symbol("Fragment");function rEA(t,A,...e){const i=e.length?e: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:t,props:(A&&A.children!==void 0?{...A,children:void 0}:A)||{},children:n}}var Qt=Symbol("Cuboid"),w6A=Symbol("Cube"),_l=Symbol("Cylinder"),JW=Symbol("Sphere"),fH=Symbol("RoundedCuboid"),Pi=Symbol("Translate"),ZB=Symbol("Rotate"),_Q=Symbol("Union"),tw=Symbol("Subtract"),Ec=Symbol("Hull"),Ko=Symbol("Colorize"),yH=Symbol("Polygon"),mH=Symbol("ExtrudeLinear"),lf=Symbol("RoundedCylinder"),Mn=m6A,zA=(t,A,e)=>rEA(t,A),Jt=(t,A,e)=>rEA(t,A),sB=({center:t,width:A,length:e,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,e)*s,d=Math.max(A-u,A*r),p=Math.max(e-u,e*r),m=Math.min(A,e)*.12,D=c??m,w={x:0,y:e/2-D*.25,z:i},S=I??w,k=Jt(_Q,{children:[Jt(Ec,{children:[zA(Pi,{z:.005,children:zA(Qt,{size:[d,p,.01]})}),zA(Pi,{z:h,children:zA(Qt,{size:[A,e,.01]})})]}),Jt(Ec,{children:[zA(Pi,{z:h,children:zA(Qt,{size:[A,e,.01]})}),zA(Pi,{z:h+E,children:zA(Qt,{size:[d,p,.01]})})]})]}),x=(M,L)=>zA(Pi,{offset:{x:M,y:L,z:0},children:zA(ZB,{rotation:[0,0,Math.PI/4],children:zA(Qt,{size:[Q*Math.SQRT2,Q*Math.SQRT2,i*3]})})});let N=k;if(Q>0){const M=A/2,L=e/2;N=Jt(tw,{children:[k,x(M,L),x(-M,L),x(M,-L),x(-M,-L)]})}return zA(Ko,{color:o,children:zA(Pi,{offset:t,children:zA(Pi,{offset:{x:0,y:0,z:n},children:g?Jt(tw,{children:[N,zA(Pi,{offset:S,children:zA(ZB,{rotation:l,children:zA(_l,{radius:D,height:C})})})]}):N})})})},pDt=t=>Array.from({length:t},(A,e)=>e);function aEA(t,A){if(t.length<2)throw new Error("Stroke must have at least two points");const e=Array.isArray(t[0])?t.map(([c,I])=>({x:c,y:I})):t,i=A/2,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(e[0],e[1]);r(e[0],a,1),r(e[0],a,-1);for(let c=1;c<e.length-1;c++){const I=e[c-1],l=e[c],B=e[c+1],C=s(I,l),Q=s(l,B),h=C.x+Q.x,E=C.y+Q.y,u=Math.sqrt(h*h+E*E);if(u/2>2*i)r(l,C,1),r(l,Q,1),r(l,C,-1),r(l,Q,-1);else{const p=1/u;r(l,{x:h*p,y:E*p},1),r(l,{x:h*p,y:E*p},-1)}}const g=s(e[e.length-2],e[e.length-1]);return r(e[e.length-1],g,1),r(e[e.length-1],g,-1),[...n,...o]}var fDt=t=>{const A=Math.min(...t.map(r=>r.x)),e=Math.max(...t.map(r=>r.x)),i=Math.min(...t.map(r=>r.y)),s=5.47/(Math.max(...t.map(r=>r.y))-i);return t.map(r=>({x:(r.x-A-(e-A)/2)*s,y:(r.y-i)*s}))},yDt=fDt([{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}]),D6A=5.47,TW=.5,mDt=({x:t,y:A,z:e})=>{const i=t>0;return Jt(Mn,{children:[zA(Pi,{offset:{x:t+.25/2,y:A,z:e},children:zA(ZB,{rotation:["-90deg",0,"90deg"],children:zA(mH,{height:.25,children:zA(yH,{points:yDt.slice().reverse().map(n=>[n.x,n.y])})})})}),zA(Pi,{offset:{x:t,y:A+(i?1:-1),z:e},children:zA(ZB,{rotation:["-90deg","90deg",i?"180deg":"0deg"],children:zA(mH,{height:2,children:zA(yH,{points:aEA([[0,0],[-1,0],[-1,-1]],.25).map(n=>[n.x,n.y])})})})})]})},wDt=({numPins:t=8,pitch:A=2.54,bodyWidth:e=6.4,rowSpacing:i})=>{const n=Math.floor(t/2),o=i??(e>=7?e:e+1.22),s=e>=7?o-1.22:e;return Jt(Mn,{children:[pDt(t).map(r=>{const a=r%n,g=(Math.floor(r/n)-.5)*2;return zA(mDt,{x:g*o/2,y:a*A-(n-1)/2*A,z:D6A/2+TW})}),zA(sB,{width:s,length:n*A+.5,height:D6A-TW,heightAboveSurface:TW,center:{x:0,y:0,z:TW}})]})};function DDt(t,{height:A,padContactLength:e,curveLength:i,bodyDistance:n,steepness:o=10}){i||(i=n*.3);let s=n-e-i;s<0&&(i+=s,s=0);const r=e*.75,a=e+i+(n-e-i)*.25;if(t<=r)return 0;if(t>=a)return A;const g=(t-r)/(a-r);return A/(1+Math.exp(-o*(g-.5)))}var zn=t=>{const{thickness:A,width:e,padContactLength:i,bodyDistance:n,height:o,rotation:s}=t,r=15,a=Array.from({length:r}).map((c,I)=>I/(r-1)*n).map(c=>[c,DDt(c,t)]),g=aEA(a,A);return zA(Ko,{color:"#fff",children:zA(Pi,{offset:{z:0,y:0,x:0,...t.position},children:zA(ZB,{rotation:["90deg",0,s??0],children:zA(Pi,{offset:{x:0,y:0,z:-e/2},children:zA(mH,{height:e,children:zA(yH,{points:g.map(c=>[c.x,c.y])})})})})})})},SDt=({pinCount:t,leadLength:A,leadWidth:e,pitch:i,bodyWidth:n})=>{const o=Math.ceil(t/2),s=i*t/2+e/2,r=(o-1)*i/2,a=.25;return Jt(Mn,{children:[Array.from({length:o}).map((g,c)=>zA(zn,{position:{x:-n/2-A,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),Array.from({length:o}).map((g,c)=>zA(zn,{rotation:Math.PI,position:{x:n/2+A,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),zA(sB,{center:{x:0,y:0,z:a/2},width:n-e-1,length:s,height:1.5})]})},bDt=({pinCount:t,padContactLength:A=.4,leadWidth:e=.2,pitch:i=.65,bodyWidth:n=3})=>{const o=Math.ceil(t/2),s=(o-1)*i/2,r=.2;return Jt(Mn,{children:[Array.from({length:o}).map((a,g)=>zA(zn,{position:{x:-n/2-A-.3,y:g*i-s,z:r/2},width:e,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),Array.from({length:o}).map((a,g)=>zA(zn,{rotation:Math.PI,position:{x:n/2+A+.3,y:g*i-s,z:r/2},width:e,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),zA(sB,{center:{x:0,y:0,z:r/2},width:n,length:n,height:1.1,notchRadius:.35,heightAboveSurface:.1,taperRatio:.09})]})},gEA=1,cEA=.5,tv=.5,wH=.2,xDt=gEA-wH*2,S6A=({color:t="#333"})=>Jt(Mn,{children:[zA(Qt,{size:[xDt,cEA,tv],offset:[0,0,tv/2],color:t}),zA(Qt,{size:[wH,tv,cEA],offset:[gEA/2-wH/2,0,tv/2],color:"#ccc"}),zA(Qt,{size:[wH,tv,cEA],offset:[-gEA/2+wH/2,0,tv/2],color:"#ccc"})]}),IEA=1.6,_Dt=IEA-.3*2,KW=.3,lEA=.85,iv=.6,b6A=({color:t="#333"})=>Jt(Mn,{children:[zA(Qt,{size:[_Dt,lEA,iv],offset:[0,0,iv/2],color:t}),zA(Qt,{size:[KW,lEA,iv],offset:[IEA/2-KW/2,0,iv/2],color:"#ccc"}),zA(Qt,{size:[KW,lEA,iv],offset:[-IEA/2+KW/2,0,iv/2],color:"#ccc"})]}),BEA=2,CEA=1.25,nv=.55,DH=.5,kDt=BEA-DH*2,x6A=({color:t="#333"})=>Jt(Mn,{children:[zA(Qt,{size:[kDt,CEA,nv],offset:[0,0,nv/2],color:t}),zA(Qt,{size:[DH,CEA,nv],offset:[BEA/2-DH/2,0,nv/2],color:"#ccc"}),zA(Qt,{size:[DH,CEA,nv],offset:[-BEA/2+DH/2,0,nv/2],color:"#ccc"})]}),FDt=({pinCount:t,pitch:A,leadWidth:e,padContactLength:i,bodyWidth:n})=>{const o=t/4;A||(A=GDt(t,n)),i||(i=RDt(t)),e||(e=MDt(t,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 Jt(Mn,{children:[Array.from({length:o}).map((B,C)=>zA(zn,{position:{x:-g/2-.4,y:C*A-r,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(zn,{rotation:Math.PI,position:{x:g/2+.4,y:C*A-r,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(zn,{rotation:Math.PI/2,position:{x:C*A-r,y:-a/2-.4,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(zn,{rotation:-Math.PI/2,position:{x:C*A-r,y:a/2+.4,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),zA(sB,{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})]})},GDt=(t,A)=>{switch(t){case 44:case 64:return .8;case 52:return A===14?1:.65;case 208:return .5;default:return .5}},RDt=t=>{switch(t){case 32:return .6;case 40:return .6;case 52:case 64:return .65;case 208:return 1.65;default:return .6}},MDt=(t,A)=>{switch(t){case 44:case 64:return .5;case 52:return A===14?.45:.55;case 208:return .3;default:return .25}},_6A=({x:t,y:A,pinThickness:e,shortSidePinLength:i,longSidePinLength:n,bodyHeight:o,bodyLength:s=2.54,bodyWidth:r=2.54,flipZ:a,faceup:g,smd:c,rightangle:I})=>Jt(Mn,{children:[zA(Pi,{y:I?-3:0,children:zA(Qt,{color:"#222",size:[s,r,o],center:[t,A,a(o/2)]})}),!g&&zA(Ko,{color:"gold",children:c?zA(zn,{rotation:-Math.PI/2,position:{x:t,y:A+1,z:e/2},thickness:e,width:e,height:e,padContactLength:2,bodyDistance:3}):Jt(Ec,{children:[zA(Qt,{color:"gold",size:[e,e,i*.9],center:[t,A,a(o*.9+o/2)]}),zA(Qt,{color:"gold",size:[e/1.8,e/1.8,i],center:[t,A,a(o+o/2)]})]})}),zA(Ko,{color:"gold",children:zA(Pi,{y:I?-3.9:0,z:I?1:0,children:zA(ZB,{rotation:I?[-Math.PI/2,0,0]:[0,0,0],children:Jt(Ec,{children:[zA(Qt,{color:"gold",size:[e,e,n*.9],center:[t,A,a(-n/2*.9)]}),zA(Qt,{color:"gold",size:[e/1.8,e/1.8,n],center:[t,A,a(-n/2)]})]})})})})]}),NDt=({numberOfPins:t,pitch:A=2.54,longSidePinLength:e=6,invert:i,faceup:n,rows:o=1,smd:s,rightangle:r})=>{const c=Math.ceil(t/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(Mn,{children:Array.from({length:t},(h,E)=>{const u=Math.floor(E/c),d=E%c,p=B+d*A,m=-u*I;return zA(_6A,{x:p,y:m,pinThickness:.63,shortSidePinLength:l,longSidePinLength:e,bodyHeight:2,flipZ:Q,faceup:n,smd:s,rightangle:r},E)})})},vDt=t=>{const A=["left","bottom","right","top"],{pin_count:e,pn:i,w:n,h:o,p:s,pl:r}=t,a=e/4,g=A[Math.floor((i-1)/a)],c=(i-1)%a,I=s*(a-1),l=s*(a-1),B=-r/2;switch(g){case"left":return{x:-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")}},LDt=({num_pins:t,cw:A,ccw:e,startingpin:i})=>{const n=[],o=t/4;let s=1;const r={};for(const a of i??[])r[a]=!0;!r.leftside&&!r.topside&&!r.rightside&&!r.bottomside&&(r.leftside=!0),!r.bottompin&&!r.leftpin&&!r.rightpin&&!r.toppin&&(r.leftside?r.toppin=!0:r.topside?r.rightpin=!0:r.rightside?r.bottompin=!0:r.bottomside&&(r.leftpin=!0)),r.leftside&&r.toppin?s=1:r.leftside&&r.bottompin?s=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<t;a++)n[s]=a+1,s++,s>t&&(s=1);return n},UDt=({num_pins:t=16,bodyWidth:A=9,bodyLength:e=9,bodyThickness:i=.8,thermalPadSize:n,padWidth:o=.25,padLength:s=.25,pitch:r=.5,thermalPadThickness:a=.05})=>{const g=LDt({num_pins:t,cw:!0,ccw:!0}),c=[];for(let I=0;I<t;I++){const{x:l,y:B,o:C}=vDt({pin_count:t,pn:I+1,w:A,h:e,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 Jt(Mn,{children:[zA(Ko,{color:"grey",children:zA(Qt,{center:{x:0,y:0,z:i/2},size:[A,e,i]})}),c.map((I,l)=>zA(Qt,{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(Qt,{center:{x:0,y:0,z:a/2},size:[n.width,n.length,a]})]})},HDt=UDt,YDt=()=>{const a=1.1999999999999997;return Jt(Mn,{children:[zA(zn,{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(zn,{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(zn,{position:{x:-2.8/2-a/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(zn,{position:{x:-2.8/2-a/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(zn,{position:{x:-2.8/2-a/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(sB,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2})]})},JDt=YDt,TDt=({fullWidth:t=2.9,fullLength:A=2.8})=>{const c=(t-1.92)/2+.3;return Jt(Mn,{children:[zA(zn,{rotation:Math.PI,position:{x:t/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(zn,{position:{x:-t/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(zn,{position:{x:-t/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(sB,{center:{x:0,y:0,z:0},width:1.92,length:2.9,height:1.1,straightHeightRatio:.45,heightAboveSurface:.05})]})},QEA=.6,hEA=.3,ov=.33,SH=.1,KDt=QEA-SH*2,k6A=({color:t="#333"})=>Jt(Mn,{children:[zA(Qt,{size:[KDt,hEA,ov],offset:[0,0,ov/2],color:t}),zA(Qt,{size:[SH,hEA,ov],offset:[QEA/2-SH/2,0,ov/2],color:"#ccc"}),zA(Qt,{size:[SH,hEA,ov],offset:[-QEA/2+SH/2,0,ov/2],color:"#ccc"})]}),EEA=.4,uEA=.2,sv=.13,bH=.07,PDt=EEA-bH*2,F6A=({color:t="#333"})=>Jt(Mn,{children:[zA(Qt,{size:[PDt,uEA,sv],offset:[0,0,sv/2],color:t}),zA(Qt,{size:[bH,uEA,sv],offset:[EEA/2-bH/2,0,sv/2],color:"#ccc"}),zA(Qt,{size:[bH,uEA,sv],offset:[-EEA/2+bH/2,0,sv/2],color:"#ccc"})]}),dEA=3.2,pEA=1.6,rv=.9,xH=.5,qDt=dEA-xH*2,G6A=({color:t="#333"})=>Jt(Mn,{children:[zA(Qt,{size:[qDt,pEA,rv],offset:[0,0,rv/2],color:t}),zA(Qt,{size:[xH,pEA,rv],offset:[dEA/2-xH/2,0,rv/2],color:"#ccc"}),zA(Qt,{size:[xH,pEA,rv],offset:[-dEA/2+xH/2,0,rv/2],color:"#ccc"})]}),fEA=3.2,yEA=2.5,av=1,_H=.6,ODt=fEA-_H*2,R6A=({color:t="#333"})=>Jt(Mn,{children:[zA(Qt,{size:[ODt,yEA,av],offset:[0,0,av/2],color:t}),zA(Qt,{size:[_H,yEA,av],offset:[fEA/2-_H/2,0,av/2],color:"#ccc"}),zA(Qt,{size:[_H,yEA,av],offset:[-fEA/2+_H/2,0,av/2],color:"#ccc"})]}),mEA=5,wEA=2.5,gv=1.4,kH=.6,WDt=mEA-kH*2,M6A=({color:t="#333"})=>Jt(Mn,{children:[zA(Qt,{size:[WDt,wEA,gv],offset:[0,0,gv/2],color:t}),zA(Qt,{size:[kH,wEA,gv],offset:[mEA/2-kH/2,0,gv/2],color:"#ccc"}),zA(Qt,{size:[kH,wEA,gv],offset:[-mEA/2+kH/2,0,gv/2],color:"#ccc"})]}),DEA=6.3,SEA=3.2,cv=1.8,FH=.8,ZDt=DEA-FH*2,N6A=({color:t="#333"})=>Jt(Mn,{children:[zA(Qt,{size:[ZDt,SEA,cv],offset:[0,0,cv/2],color:t}),zA(Qt,{size:[FH,SEA,cv],offset:[DEA/2-FH/2,0,cv/2],color:"#ccc"}),zA(Qt,{size:[FH,SEA,cv],offset:[-DEA/2+FH/2,0,cv/2],color:"#ccc"})]}),VDt=({x:t,y:A,pitch:e=2.54,legsLength:i=3,innerDiameter:n=.945,bodyHeight:o=5,bodyLength:s=e,bodyWidth:r=e,flipZ:a})=>{const g=n/1.5,c=g*1.6;return Jt(Mn,{children:[zA(Ko,{color:"#1a1a1a",children:Jt(tw,{children:[zA(Qt,{color:"#000",size:[s,r,o],center:[t,A,a(o/2)]}),n?zA(_l,{height:o+.1,radius:n/2,center:[t,A,a(o/2)],color:"#222"}):zA(Qt,{size:[c,c,o],center:[t,A,a(o/2)]})]})}),Jt(Ko,{color:"silver",children:[Jt(Ec,{children:[zA(Qt,{color:"silver",size:[g,g,i*.9],center:[t,A,a(-i/2*.9)]}),zA(Qt,{color:"silver",size:[g/1.8,g/1.8,i],center:[t,A,a(-i/2)]})]}),zA(Qt,{color:"silver",size:[c,c,c*.5],center:[t,A,a(c/2*.5)]})]})]})},jDt=({numberOfPins:t,pitch:A=2.54,legsLength:e=3,innerDiameter:i=.945,rows:n=1,invert:o})=>{const r=Math.ceil(t/n),a=2.54,g=-((r-1)/2)*A,c=I=>o?-I+5:I;return zA(Mn,{children:Array.from({length:t},(I,l)=>{const B=Math.floor(l/r),C=l%r,Q=g+C*A,h=-B*a;return zA(VDt,{x:Q,y:h,pitch:A,legsLength:e,innerDiameter:i,flipZ:c},l)})})},zDt=({width:t,length:A,innerDiameter:e=1})=>{const i=t,n=A,o=t*.7,s=e/2.5;return Jt(Mn,{children:[zA(fH,{color:"#1a1a1f",center:[0,0,o/2],size:[n,n,o],roundRadius:.3}),zA(fH,{color:"#f2f2f2",center:[0,0,o+o*.1/2.5],size:[n,n,o*.1],roundRadius:.14}),zA(_l,{color:"#1a1a1f",height:o*.8,radius:i/3,center:[0,0,o+o*.8/2]}),zA(_l,{color:"#1a1a1f",height:o*.2,radius:e/2,center:[n/3,n/3,o+o*.1/2]}),zA(_l,{color:"#1a1a1f",height:o*.2,radius:e/2,center:[-n/3,-n/3,o+o*.1/2]}),zA(_l,{color:"#1a1a1f",height:o*.2,radius:e/2,center:[-n/3,n/3,o+o*.1/2]}),zA(_l,{color:"#1a1a1f",height:o*.2,radius:e/2,center:[n/3,-n/3,o+o*.1/2]}),zA(PW,{thickness:e/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:-i/2,y:-n/2,z:-o*1.2}}),zA(PW,{thickness:e/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:-i/2,y:n/2,z:-o*1.2},rotation:Math.PI}),zA(PW,{thickness:e/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:i/2,y:n/2,z:-o*1.2},rotation:Math.PI}),zA(PW,{thickness:e/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:i/2+e/3.6,y:-n/2,z:-o*1.2}})]})},PW=t=>{const{thickness:A,width:e,horizontalLength:i,verticalLength:n,rotation:o=0,position:s}=t,r=[[0,i],[-n/3,i/3],[-n/5,i/4],[0,0]],a=aEA(r,A);return zA(Ko,{color:"#f2f2f2",children:zA(Pi,{offset:{x:s?.x||0,y:s?.y||0,z:s?.z||0},children:zA(ZB,{rotation:[0,55,o],children:zA(mH,{height:e,children:zA(yH,{points:a.map(g=>[g.y,g.x])})})})})})},XDt=({pinCount:t,leadLength:A,leadWidth:e,pitch:i,bodyWidth:n})=>{const o=Math.ceil(t/2),s=(o-1)*i/2,r=.25,a=1,g=.8,c=A*0,I=i*(o-1)+e+.2,l=n*.55;return Jt(Mn,{children:[Array.from({length:o}).map((B,C)=>zA(zn,{position:{x:-n/2-c,y:C*i-s,z:r/2},width:e,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),Array.from({length:o}).map((B,C)=>zA(zn,{rotation:Math.PI,position:{x:n/2+c,y:C*i-s,z:r/2},width:e,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),zA(sB,{center:{x:0,y:0,z:r/2},width:l,length:I,height:a})]})},$Dt=({pinCount:t,pitch:A,leadWidth:e,leadLength:i,bodyWidth:n,bodyLength:o})=>{const s=t===8?{pitch:.65,leadWidth:.3}:{pitch:.5,leadWidth:.225},r=isNaN(parseFloat(A))?s.pitch:parseFloat(A),a=isNaN(parseFloat(e))?s.leadWidth:parseFloat(e)*.8,g=isNaN(parseFloat(n))?2.6:parseFloat(n)*.8,c=isNaN(parseFloat(o))?2+Number(r)*1.4:parseFloat(o),I=t/2,l=(I-1)*r/2,B=.15,C=.8,Q=4.5,h=(Q-g)/2,E=h*.5;return Jt(Mn,{children:[Array.from({length:I}).map((u,d)=>zA(zn,{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(zn,{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(sB,{center:{x:0,y:0,z:B/2},width:g,length:c,height:1})]})},ASt=()=>Jt(Mn,{children:[zA(Qt,{color:"#ccc",size:[.5,.6,.12],center:[-.725,0,.12/2]}),zA(Qt,{color:"#ccc",size:[.5,.6,.12],center:[.725,0,.12/2]}),zA(Ko,{color:"#222",children:Jt(_Q,{children:[zA(Pi,{z:.3/2,children:zA(Qt,{size:[1.65,.8,.3]})}),Jt(Ec,{children:[zA(Pi,{z:.3,children:zA(Qt,{size:[1.65,.8,.01]})}),zA(Pi,{z:.6,children:zA(Qt,{size:[1.65-.2,.8-.2,.01]})})]})]})})]}),eSt=()=>Jt(Mn,{children:[zA(Qt,{color:"#ccc",size:[.26,.51,.12],center:[-.325,0,.12/2]}),zA(Qt,{color:"#ccc",size:[.26,.51,.12],center:[.325,0,.12/2]}),zA(Ko,{color:"#222",children:zA(Pi,{z:.47/2+.02,children:zA(Qt,{size:[.98,.58,.47]})})}),zA(Qt,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,.26/2,.47/4]}),zA(Qt,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,-.26/2,.47/4]}),zA(Qt,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[.65/2,0,.47/4]}),zA(Qt,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[-.65/2,0,.47/4]})]}),tSt=()=>{const g=zA(Ko,{color:"#1a1a1a",children:Jt(_Q,{children:[Jt(Ec,{children:[zA(Pi,{z:.13,children:zA(Qt,{size:[4,3,.03]})}),zA(Pi,{z:1.15,children:zA(Qt,{size:[4.4,3.4,.01]})})]}),Jt(Ec,{children:[zA(Pi,{z:1.15,children:zA(Qt,{size:[4.4,3.4,.01]})}),zA(Pi,{z:2.3,children:zA(Qt,{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(Ko,{color:"#c0c0c0",children:Jt(_Q,{children:[zA(Qt,{size:[2.3*.8,1.45,.2],center:[C,0,.2/2]}),zA(Qt,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),zA(Qt,{size:[E,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return Jt(Mn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},iSt=()=>{const g=zA(Ko,{color:"#1a1a1a",children:Jt(_Q,{children:[Jt(Ec,{children:[zA(Pi,{z:.13,children:zA(Qt,{size:[4,3,.03]})}),zA(Pi,{z:1.15,children:zA(Qt,{size:[4.4,3.4,.01]})})]}),Jt(Ec,{children:[zA(Pi,{z:1.15,children:zA(Qt,{size:[4.4,3.4,.01]})}),zA(Pi,{z:2.3,children:zA(Qt,{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(Ko,{color:"#c0c0c0",children:Jt(_Q,{children:[zA(Qt,{size:[2.3*.8,1.45,.2],center:[C,0,.2/2]}),zA(Qt,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),zA(Qt,{size:[E,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return Jt(Mn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},nSt=()=>{const g=zA(Ko,{color:"#1a1a1a",children:Jt(_Q,{children:[Jt(Ec,{children:[zA(Pi,{z:.21000000000000002,children:zA(Qt,{size:[6.3999999999999995,5.6,.03]})}),zA(Pi,{z:1.15,children:zA(Qt,{size:[6.8,6,.01]})})]}),Jt(Ec,{children:[zA(Pi,{z:1.15,children:zA(Qt,{size:[6.8,6,.01]})}),zA(Pi,{z:2.3,children:zA(Qt,{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(Ko,{color:"#c0c0c0",children:Jt(_Q,{children:[zA(Qt,{size:[2.3*.8,2.95,.2],center:[C,0,.2/2]}),zA(Qt,{size:[.2,2.95,1.14],center:[Q,0,1.14/2+.2]}),zA(Qt,{size:[E,2.95,.2],center:[u,0,.2/2+1.14]})]})})};return Jt(Mn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},oSt=()=>{const I=zA(Ko,{color:"#222",children:Jt(_Q,{children:[zA(Pi,{z:.27,children:zA(Qt,{size:[2.9,1.9,.54]})}),Jt(Ec,{children:[zA(Pi,{z:.54,children:zA(Qt,{size:[2.9,1.9,.01]})}),zA(Pi,{z:1.08,children:zA(Qt,{size:[2.6999999999999997,1.7,.01]})})]})]})});return Jt(Mn,{children:[zA(Qt,{color:"#ccc",size:[1,1.2,.25],center:[-1.3,0,.25/2]}),zA(Qt,{color:"#ccc",size:[1,1.2,.25],center:[1.3,0,.25/2]}),I]})},sSt=()=>Jt(Mn,{children:[zA(Qt,{color:"#ccc",size:[1,.6,.12],center:[-1.3,0,.12/2]}),zA(Qt,{color:"#ccc",size:[1,.6,.12],center:[1.3,0,.12/2]}),zA(Ko,{color:"#222",children:Jt(_Q,{children:[zA(Pi,{z:.55/2,children:zA(Qt,{size:[2.7,1.6,.55]})}),Jt(Ec,{children:[zA(Pi,{z:.55,children:zA(Qt,{size:[2.7,1.6,.01]})}),zA(Pi,{z:1.1,children:zA(Qt,{size:[2.7-.2,1.6-.2,.01]})})]})]})})]}),rSt=()=>Jt(Mn,{children:[zA(Qt,{color:"#ccc",size:[1,.9,.2],center:[-1.3,0,.2/2]}),zA(Qt,{color:"#ccc",size:[1,.9,.2],center:[1.3,0,.2/2]}),zA(Ko,{color:"#222",children:Jt(_Q,{children:[zA(Pi,{z:.2/2,children:zA(Qt,{size:[2.75,1.8,.2]})}),Jt(Ec,{children:[zA(Pi,{z:.2,children:zA(Qt,{size:[2.75,1.8,.01]})}),zA(Pi,{z:1,children:zA(Qt,{size:[2.75-.4,1.8-.4,.01]})})]})]})}),zA(Qt,{color:"#777",size:[.2,1.8-.4,.01],center:[-1.3+.4,0,1]})]}),aSt=()=>Jt(Mn,{children:[zA(Qt,{color:"#ccc",size:[.9,.9,.2],center:[-1.225,0,.2/2]}),zA(Qt,{color:"#ccc",size:[.9,.9,.2],center:[1.225,0,.2/2]}),zA(Ko,{color:"#222",children:Jt(_Q,{children:[Jt(Ec,{children:[zA(Pi,{z:.2,children:zA(Qt,{size:[2.6-.1/2,1.7-.1/2,.01]})}),zA(Pi,{z:.01,children:zA(Qt,{size:[2.6-.1,1.7-.1,.01]})})]}),Jt(Ec,{children:[zA(Pi,{z:.2,children:zA(Qt,{size:[2.6,1.7,.01]})}),zA(Pi,{z:1,children:zA(Qt,{size:[2.6-.4,1.7-.4,.01]})})]})]})}),zA(Qt,{color:"#777",size:[.2*2.7,1.7-.4,.02],center:[-1.225+.4,0,1]})]}),gSt=()=>Jt(Mn,{children:[zA(Qt,{color:"#ccc",size:[.9,1.75,.2],center:[-1.825,0,.2/2]}),zA(Qt,{color:"#ccc",size:[.9,1.75,.2],center:[1.825,0,.2/2]}),zA(Ko,{color:"#222",children:Jt(_Q,{children:[Jt(Ec,{children:[zA(Pi,{z:.2,children:zA(Qt,{size:[3.8-.05/2,2.5-.05/2,.01]})}),zA(Pi,{z:.01,children:zA(Qt,{size:[3.8-.05,2.5-.05,.01]})})]}),Jt(Ec,{children:[zA(Pi,{z:.2,children:zA(Qt,{size:[3.8,2.5,.01]})}),zA(Pi,{z:1,children:zA(Qt,{size:[3.8-.4,2.5-.4,.01]})})]})]})}),zA(Qt,{color:"#777",size:[.2*2.7,2.5-.4,.02],center:[-1.825+.4,0,1]})]}),cSt=()=>Jt(Mn,{children:[zA(Qt,{color:"#ccc",size:[.4,.25,.14],center:[-.4,0,.14/2]}),zA(Qt,{color:"#ccc",size:[.4,.25,.14],center:[.4,0,.14/2]}),zA(Ko,{color:"#222",children:Jt(_Q,{children:[zA(Pi,{z:.14/2,children:zA(Qt,{size:[.8,.6,.14]})}),Jt(Ec,{children:[zA(Pi,{z:.14,children:zA(Qt,{size:[.8,.6,.01]})}),zA(Pi,{z:.37,children:zA(Qt,{size:[.8-.1,.6-.1,.01]})})]})]})})]}),ISt=()=>{const c=3.0999999999999996;return Jt(Mn,{children:[zA(zn,{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(zn,{position:{x:-6.6/2-c/4,y:0,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(zn,{position:{x:-6.6/2-c/4,y:-2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(zn,{position:{x:-6.6/2-c/4,y:2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(sB,{center:{x:0,y:0,z:0},width:3.5,length:6.5,height:1.7,includeNotch:!1,taperRatio:.06,straightHeightRatio:.45})]})},lSt=()=>Jt(Mn,{children:[Array.from({length:16}).map((B,C)=>zA(zn,{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(zn,{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(zn,{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(zn,{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(sB,{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})]}),BSt=lSt,CSt=()=>{const g=.7999999999999998;return Jt(Mn,{children:[zA(zn,{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(zn,{position:{x:-2.05/2-g/4,y:-.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),zA(zn,{position:{x:-2.05/2-g/4,y:.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),zA(sB,{center:{x:0,y:0,z:0},width:1.25,length:2,height:.9,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})]})},QSt=({pinCount:t,pitch:A,leadWidth:e,padContactLength:i,bodyWidth:n})=>{const o=t/4;if(o!==Math.floor(o))throw new Error(`LQFP pinCount must be divisible by 4, got ${t}`);A||(A=.5),i||(i=.6),e||(e=.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 Jt(Mn,{children:[Array.from({length:o}).map((B,C)=>zA(zn,{position:{x:-g/2-.36,y:C*A-r,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(zn,{rotation:Math.PI,position:{x:g/2+.36,y:C*A-r,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(zn,{rotation:Math.PI/2,position:{x:C*A-r,y:-a/2-.36,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(zn,{rotation:-Math.PI/2,position:{x:C*A-r,y:a/2+.36,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),zA(sB,{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})]})},hSt=()=>{const i=.20900000000000002,n=.1,o=.3,s=.1,r=.2;return Jt(Mn,{children:[zA(Ko,{color:"#222",children:Jt(_Q,{children:[zA(Qt,{size:[.85,1.2,i],center:[0,0,i/2]}),Jt(Ec,{children:[zA(Pi,{z:i,children:zA(Qt,{size:[.85,1.2,.01]})}),zA(Pi,{z:.38,children:zA(Qt,{size:[.85-n,1.2-n,.01]})})]})]})}),zA(Qt,{color:"#ccc",size:[o,.25,s],center:[.55,0,s/2]}),zA(Qt,{color:"#ccc",size:[o,r,s],center:[-.55,.4,s/2]}),zA(Qt,{color:"#ccc",size:[o,r,s],center:[-.55,-.4,s/2]})]})},ESt=({num_pins:t,bodyWidth:A=5.3,bodyLength:e=5.3,bodyThickness:i=1,thermalPadSize:n,padWidth:o=e/5.3*.6,padLength:s=e/5.3*1,pitch:r=.5,thermalPadThickness:a=.2})=>{const g=[],c=Math.floor(t/2),I=r*(c-1);for(let l=0;l<t;l++){const B=l<c?"left":"right",C=l%c,Q=I/2-C*r,h=s,E=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 Jt(Mn,{children:[zA(sB,{center:{x:0,y:0,z:0},width:A,length:e,height:i,heightAboveSurface:0,color:"grey",chamferSize:.2,taperRatio:0,notchPosition:{x:-(A/2-s),y:e/2-s,z:i}}),g.map((l,B)=>zA(Qt,{center:[l.x,l.y,a/2],size:[l.padSizeX,l.padSizeY,a]})),n?.length!==void 0&&n?.width!==void 0&&zA(Qt,{center:[0,0,a/2],size:[n.width,n.length,a]})]})},uSt=({bodyLength:t=10.2,bodyWidth:A=4.65,bodyHeight:e=13.46,leadSpacing:i=5,leadDiameter:n=.8,leadLength:o=12.7,color:s="#ddd",leadColor:r="#b87333"})=>{const a=t/2,g=A/2,c=a-g,I=i/2,l=.85;return Jt(Mn,{children:[Jt(Ko,{color:s,children:[Jt(Ec,{children:[zA(lf,{height:e,roundRadius:.5,radius:g,center:[-c,0,e]}),zA(lf,{height:e,roundRadius:.5,radius:g,center:[c,0,e]})]}),Jt(Ec,{children:[zA(lf,{height:l,roundRadius:.1,radius:g+.85,center:[-c,0,e/2+l/2]}),zA(lf,{height:l,roundRadius:.1,radius:g+.85,center:[c,0,e/2+l/2]})]})]}),Jt(Ko,{color:r,children:[zA(_l,{height:o+e/2,radius:n/2,center:[-I+.06,0,-(o/2)+e/2]}),zA(_l,{height:o+e/2,radius:n/2,center:[I-.06,0,-(o/2)+e/2]})]})]})},dSt=({bodyLength:t=1.4,bodyDiameter:A=1.1,color:e="#3a3a3aff",contactColor:i="#c6c6c6",cathodeIdentification:n="#111"})=>Jt(Mn,{children:[zA(Ko,{color:e,children:Jt(ZB,{rotation:[0,"90deg",0],children:[zA(fH,{size:[A,A,t-.2],roundRadius:.2,center:[-A/2,0,.05]}),zA(_l,{height:.2/2,radius:A/2-.2,center:[-A/2,0,-t/2+.2/2]})]})}),zA(Ko,{color:n,children:zA(ZB,{rotation:[0,"90deg",0],children:zA(fH,{size:[A*1.01,A*1.01,t/3],roundRadius:.2,center:[-A/2,0,-t/4+.1]})})}),zA(Ko,{color:i,children:zA(ZB,{rotation:[0,"90deg",0],children:zA(lf,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,-t/2]})})}),zA(Ko,{color:i,children:zA(ZB,{rotation:[0,"90deg",0],children:zA(lf,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,t/2]})})})]}),pSt=({bodyLength:t=3.5,bodyDiameter:A=1.5,color:e="#3a3a3aff",contactColor:i="#c6c6c6"})=>Jt(Mn,{children:[zA(Ko,{color:e,children:zA(ZB,{rotation:[0,"90deg",0],children:zA(lf,{height:t,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),zA(Ko,{color:i,children:zA(ZB,{rotation:[0,"90deg",0],children:zA(lf,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,-t/2]})})}),zA(Ko,{color:i,children:zA(ZB,{rotation:[0,"90deg",0],children:zA(lf,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,t/2]})})})]}),fSt=({bodyLength:t=3.9,bodyDiameter:A=2.5,color:e="#3a3a3aff",contactColor:i="#c6c6c6"})=>Jt(Mn,{children:[zA(Ko,{color:e,children:zA(ZB,{rotation:[0,"90deg",0],children:zA(lf,{height:t,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),zA(Ko,{color:i,children:zA(ZB,{rotation:[0,"90deg",0],children:zA(lf,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,-t/2]})})}),zA(Ko,{color:i,children:zA(ZB,{rotation:[0,"90deg",0],children:zA(lf,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,t/2]})})})]}),ySt=({pinCount:t,padContactLength:A=.6,leadWidth:e=.41,pitch:i=1.27})=>{if(t%2!==0)throw new Error("MS012 pinCount must be even");const n=t/2,o=4.9,s=3.9,r=(n-1)*i/2,a=.2;return Jt(Mn,{children:[Array.from({length:n}).map((g,c)=>zA(zn,{position:{x:-s/2-A-.3,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:n}).map((g,c)=>zA(zn,{rotation:Math.PI,position:{x:s/2+A+.3,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),zA(sB,{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})]})},mSt=({pinCount:t=16,padContactLength:A=.6,leadWidth:e=.41,pitch:i=1.27})=>{if(t!==16)throw new Error("MS013 only supports 16 pins");const n=t/2,o=7.5,s=10.3,r=(n-1)*i/2,a=.2;return Jt(Mn,{children:[Array.from({length:n}).map((g,c)=>zA(zn,{position:{x:-o/2-A-.3,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:n}).map((g,c)=>zA(zn,{rotation:Math.PI,position:{x:o/2+A+.3,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),zA(sB,{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})]})},wSt=()=>{const Q=7.050000000000001,h=24.95+6.5/2;return zA(Pi,{center:[0,0,1],children:Jt(Mn,{children:[Jt(ZB,{rotation:[0,55,-55],children:[Jt(tw,{children:[zA(Qt,{color:"#ccc",size:[6.5+.1,9.9,1.3],center:[h,0,1.3-2]}),zA(_l,{color:"black",center:[h,0,1.3-2],radius:3/2,height:1.3*1.2})]}),zA(Ko,{color:"#222",children:zA(sB,{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(ZB,{rotation:[0,55,55],children:Array.from({length:3}).map((E,u)=>{const d=Q,p=(u-1)*2.7,m=-.5-.6;return Jt(Ko,{color:"gold",children:[Jt(Ec,{children:[zA(Pi,{center:[15.05-4.5/2+.1,p,m],children:zA(Qt,{size:[4.5,.81+1,.5]})}),zA(Pi,{center:[15.05-4.5/2-1+.1,p,m],children:zA(Qt,{size:[4.5,.81,.5]})})]}),zA(Pi,{center:[d,p,m],children:zA(Qt,{size:[16+.1,.81,.5]})})]},`prong-${u}`)})})]})})},DSt=()=>{const g=1.1999999999999997;return Jt(Mn,{children:[zA(zn,{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(zn,{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(zn,{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(zn,{position:{x:-2.8/2-g/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(zn,{position:{x:-2.8/2-g/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(zn,{position:{x:-2.8/2-g/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(sB,{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})]})},SSt=()=>Jt(Mn,{children:[zA(sB,{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(Qt,{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(Qt,{center:[.8/2-.19/2+.1,c,.12/2],size:[.19,.15,.12]})})]}),bSt=()=>{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 Jt(Pi,{center:[0,1,10.5],children:[zA(Ko,{color:s,children:Jt(tw,{children:[zA(Pi,{center:[0,0,2.25],children:zA(_l,{radius:2.4,height:4.5})}),zA(Pi,{center:[0,-1.8499999999999999,2.25],children:zA(Qt,{size:[2.4*2,1.1,4.5+.2]})})]})}),zA(Pi,{center:c,children:zA(Qt,{size:a})}),Jt(Ec,{children:[zA(Pi,{center:I,children:zA(Qt,{size:g})}),zA(Pi,{center:l,children:zA(Qt,{size:g})})]}),zA(Pi,{center:B,children:zA(Qt,{size:[.43,.4,12.2]})}),zA(Pi,{center:[1.3,0,C],children:zA(Qt,{size:[.43,.4,15]})}),zA(Pi,{center:[-1.3,0,C],children:zA(Qt,{size:[.43,.4,15]})})]})},xSt=()=>Jt(Mn,{children:[zA(zn,{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(zn,{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(zn,{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(zn,{position:{x:-2/2-.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(zn,{position:{x:-2/2-.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(zn,{position:{x:-2/2-.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(sB,{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})]}),_St=xSt,kSt=()=>Jt(Mn,{children:[zA(sB,{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(Qt,{center:[-1/2+.3/2,a,.05/2],size:[.3,.2,.05]})}),[0,1,2].map(r=>{const a=-.5+r*.5;return zA(Qt,{center:[1/2-.3/2,a,.05/2],size:[.3,.2,.05]})})]}),FSt=()=>Jt(Mn,{children:[zA(zn,{position:{x:-2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),zA(zn,{rotation:Math.PI,position:{x:2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),zA(Ko,{color:"#222",children:zA(sB,{center:{x:0,y:0,z:0},width:1.7,length:1.25,height:.95,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})}),zA(Qt,{color:"#777",size:[1.7/3,1.25-.075,.02],center:[-.85*2/3+.035,0,.95+.05]})]}),GSt=()=>Jt(Mn,{children:[zA(Qt,{color:"#ccc",size:[.4,.325,.175],center:[-1.05,0,.175/2]}),zA(Qt,{color:"#ccc",size:[.4,.325,.175],center:[1.05,0,.175/2]}),zA(Ko,{color:"#222",children:Jt(_Q,{children:[zA(Pi,{z:.175/2,children:zA(Qt,{size:[1.7,1.25,.175]})}),Jt(Ec,{children:[zA(Pi,{z:.175,children:zA(Qt,{size:[1.7,1.25,.01]})}),zA(Pi,{z:.725,children:zA(Qt,{size:[1.7-.2,1.25-.2,.01]})})]})]})}),zA(Qt,{color:"#777",size:[1.7/3,1.25-.2,.02],center:[-1.05+1.7/4.4+.2,0,.725]})]}),RSt=()=>{const s=-1.0474999999999999,r=1.775/2+.4/2-.04;return Jt(Mn,{children:[zA(Qt,{color:"#ccc",size:[.4,.325,.13],center:[s,0,.13/2]}),zA(Qt,{color:"#ccc",size:[.4,.325,.13],center:[r,0,.13/2]}),zA(Ko,{color:"#222",children:zA(sB,{width:1.775,length:1.25,height:.725,center:{x:0,y:0,z:0},heightAboveSurface:0,straightHeightRatio:.7,taperRatio:.06,includeNotch:!1})}),zA(Qt,{color:"#777",size:[1.775/3,1.25-.05,.02],center:[s+1.775/4.4+.2,0,.725]})]})},MSt=({pitch:t=10})=>Jt(Mn,{children:[zA(_l,{height:4,radius:.5,center:[-t/2,0,.5]}),zA(JW,{radius:.5,center:[-t/2,0,2.5]}),zA(Pi,{x:-2.5,y:0,z:2.5,children:Jt(ZB,{rotation:[0,Math.PI/2,0],children:[zA(_l,{height:t,radius:.5,center:[0,0,2.5]}),zA(Ko,{color:"#d2b48c",children:zA(_l,{height:5,radius:1.3,center:[0,0,2.5]})})]})}),zA(_l,{height:4,radius:.5,center:[t/2,0,.5]}),zA(JW,{radius:.5,center:[t/2,0,2.5]})]}),NSt=({bodyWidth:t=21,boardThickness:A=.5,leadWidth:e=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=t/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 D=-((s-1)/2)*n;for(let w=0;w<s;w++){const S=D+w*n;E.push({x:-l+i/2,y:-S,pl:i,pw:e}),g&&u.push({x:-l,y:-S},{x:-l+c,y:-S})}}if(o){const D=-((o-1)/2)*n;for(let w=0;w<o;w++){const S=D+w*n;E.push({x:l-i/2,y:-S,pl:i,pw:e}),g&&u.push({x:l,y:-S},{x:l-c,y:-S})}}if(r){const D=-((r-1)/2)*n;for(let w=0;w<r;w++){const S=D+w*n;E.push({x:-S,y:-h/2+i/2,pl:e,pw:i}),g&&u.push({x:-S,y:-h/2},{x:-S,y:-h/2+c})}}if(a){const D=-((a-1)/2)*n;for(let w=0;w<a;w++){const S=D+w*n;E.push({x:-S,y:h/2-i/2,pl:e,pw:i}),g&&u.push({x:-S,y:h/2},{x:-S,y:h/2-c})}}const d=zA(Ko,{color:"#008080",children:Jt(tw,{children:[zA(Qt,{center:[0,0,B],size:[t,h,A]}),E.map((D,w)=>zA(Qt,{center:[D.x,D.y,B],size:[D.pl+.01,D.pw+.01,C]},w))]})}),p=g&&u.map((D,w)=>zA(_l,{color:"black",center:[D.x,D.y,B],radius:Q,height:A*1.07})),m=E.map((D,w)=>zA(Qt,{center:[D.x,D.y,B],size:[D.pl+.01,D.pw+.01,C]}));return Jt(Mn,{children:[d,zA(Ko,{color:"#FFD700",children:g?Jt(tw,{children:[zA(_Q,{children:E.map((D,w)=>zA(Qt,{center:[D.x,D.y,B],size:[D.pl+.01,D.pw+.01,C]},w))}),p]}):m})]})},vSt=({numPins:t=5,rows:A=1,p:e=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,nopin:l})=>{const B=o/2,C=Math.ceil(t/A);let Q,h;a==="left"||a==="right"?(Q=(A-1)*e+2*I,h=(C-1)*e+2*I):(h=(A-1)*e+2*I,Q=(C-1)*e+2*I),t===0&&(Q=10,h=10);const E=Number(s??Q),u=Number(r??h),d=[];let p=0,m=0,D=0,w=0,S=0,k=0;a==="left"||a==="right"?(p=a==="left"?-E/2+I:E/2-I,m=-((C-1)/2)*e,D=0,w=e,S=a==="left"?e:-e,k=0):(p=-((C-1)/2)*e,m=a==="top"?u/2-I:-u/2+I,D=e,w=0,S=0,k=a==="top"?-e:e);let x=0;for(let aA=0;aA<A&&x<t;aA++)for(let eA=0;eA<C&&x<t;eA++){const nA=p+eA*D+aA*S,rA=m+eA*w+aA*k;d.push({x:nA,y:rA}),x++}const N=[];if(g)for(const aA of g){let eA=0,nA=0;aA==="topleft"?(eA=-E/2+c,nA=u/2-c):aA==="topright"?(eA=E/2-c,nA=u/2-c):aA==="bottomleft"?(eA=-E/2+c,nA=-u/2+c):aA==="bottomright"?(eA=E/2-c,nA=-u/2+c):aA==="center"&&(eA=0,nA=0),N.push({x:eA,y:nA})}const M=.63,L=2,Y=6,H=3,O=l?0:L,Z=zA(Ko,{color:"#008080",children:Jt(tw,{children:[zA(Qt,{center:[0,0,B+O],size:[E,u,o]}),N.map((aA,eA)=>zA(_l,{center:[aA.x,aA.y,B+O],radius:n/2,height:o},`hole-${eA}`)),d.map((aA,eA)=>zA(_l,{center:[aA.x,aA.y,B+O],radius:n/2,height:o},`pin-hole-${eA}`))]})}),$=d.map((aA,eA)=>zA(Ko,{color:"#FFD700",children:Jt(tw,{children:[zA(_l,{center:[aA.x,aA.y,o/2+O],radius:n/2,height:o}),zA(_l,{center:[aA.x,aA.y,o/2+O],radius:i/2,height:o})]})})),tA=d.map((aA,eA)=>zA(_6A,{x:aA.x,y:aA.y,pinThickness:M,shortSidePinLength:H,longSidePinLength:Y,bodyHeight:L,flipZ:nA=>nA}));return Jt(Mn,{children:[Z,$,!l&&tA]})},LSt=({footprint:t})=>{const A=dDt.string(t).json();switch(A.fn){case"dip":return zA(wDt,{numPins:A.num_pins,pitch:A.p,bodyWidth:A.w});case"axial":return zA(MSt,{pitch:A.p});case"tssop":return zA(SDt,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"msop":return zA(bDt,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"vssop":return zA($Dt,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w,bodyLength:A.h});case"qfp":return zA(FDt,{pinCount:A.num_pins,pitch:A.p,leadWidth:A.pw,padContactLength:A.pl,bodyWidth:A.w});case"tqfp":return zA(BSt,{});case"lqfp":return zA(QSt,{pinCount:A.num_pins});case"qfn":{const n=typeof A.thermalpad?.x=="number"&&typeof A.thermalpad?.y=="number";return zA(HDt,{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(ESt,{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=t.match(/_rows(\d+)/),o=n&&n[1]?parseInt(n[1],10):1;if(A.male)return zA(NDt,{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(jDt,{numberOfPins:A.num_pins,pitch:A.p,rows:o})}case"cap":switch(A.imperial){case"0402":return zA(S6A,{color:"#856c4d"});case"0603":return zA(b6A,{color:"#856c4d"});case"0805":return zA(x6A,{color:"#856c4d"});case"0201":return zA(k6A,{color:"#856c4d"});case"01005":return zA(F6A,{color:"#856c4d"});case"1206":return zA(G6A,{color:"#856c4d"});case"1210":return zA(R6A,{color:"#856c4d"});case"2010":return zA(M6A,{color:"#856c4d"});case"2512":return zA(N6A,{color:"#856c4d"})}case"sot235":return zA(JDt,{});case"sot457":return zA(DSt,{});case"sot223":return zA(ISt,{});case"sot23w":return zA(TDt,{});case"sot323":return zA(CSt,{});case"sod323f":return zA(GSt,{});case"sod323fl":return zA(RSt,{});case"sot363":return zA(_St,{});case"sot886":return zA(kSt,{});case"sot963":return zA(SSt,{});case"pushbutton":return zA(zDt,{width:A.w,length:A.h,innerDiameter:A.id});case"soic":return zA(XDt,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"sod523":return zA(ASt,{});case"sod882":return zA(eSt,{});case"sma":return zA(tSt,{});case"smb":return zA(iSt,{});case"smc":return zA(nSt,{});case"smf":return zA(oSt,{});case"sod123f":return zA(sSt,{});case"sod123fl":return zA(rSt,{});case"sod123w":return zA(aSt,{});case"sod128":return zA(gSt,{});case"sod323":return zA(FSt,{});case"sod923":return zA(cSt,{});case"hc49":return zA(uSt,{});case"micromelf":return zA(dSt,{});case"minimelf":return zA(pSt,{});case"melf":return zA(fSt,{});case"ms012":return zA(ySt,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"ms013":return zA(mSt,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"sot723":return zA(hSt,{});case"to220":return zA(wSt,{});case"to92":return zA(bSt,{});case"stampboard":case"stampreceiver":return zA(NSt,{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(vSt,{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})}}const e=t.match(/_color\(([^)]+)\)/),i=e?e[1]:void 0;switch(A.imperial){case"0402":return zA(S6A,{color:i});case"0603":return zA(b6A,{color:i});case"0805":return zA(x6A,{color:i});case"0201":return zA(k6A,{color:i});case"01005":return zA(F6A,{color:i});case"1206":return zA(G6A,{color:i});case"1210":return zA(R6A,{color:i});case"2010":return zA(M6A,{color:i});case"2512":return zA(N6A,{color:i})}return null},USt=t=>t&&typeof t=="object"&&"type"in t,Iv=t=>{if(typeof t=="number")return t;if(typeof t=="string"){const A=/^(-?\d+(?:\.\d+)?)\s*deg$/i.exec(t);if(A)return parseFloat(A[1])*Math.PI/180;const e=Number(t);if(!Number.isNaN(e))return e}return 0},HSt=t=>Array.isArray(t)?[Number(t[0])||0,Number(t[1])||0,Number(t[2])||0]:typeof t=="object"&&t?[Number(t.x)||0,Number(t.y)||0,Number(t.z)||0]:[0,0,0];function BD(t,A,e){const{jscad:{primitives:i,booleans:n,hulls:o,geometries:s,extrusions:r,transforms:a}}=e;if(t==null||t===!1)return[];if(Array.isArray(t))return t.flatMap(l=>BD(l,A,e));if(!USt(t))return[];const{type:g,props:c,children:I}=t;if(g===m6A)return(I??[]).flatMap(l=>BD(l,A,e));if(g===Ko){const l=c?.color;return(I??[]).flatMap(B=>BD(B,l??A,e))}if(g===Pi){const l=HSt(c?.offset??c?.center??{x:c?.x,y:c?.y,z:c?.z});return(I??[]).flatMap(C=>BD(C,A,e)).map(({geom:C,color:Q})=>({geom:a.translate(l,C),color:Q??A}))}if(g===ZB){const l=Array.isArray(c?.rotation)?[Iv(c.rotation[0]),Iv(c.rotation[1]),Iv(c.rotation[2])]:[Iv(c?.x??0),Iv(c?.y??0),Iv(c?.z??0)];return(I??[]).flatMap(C=>BD(C,A,e)).map(({geom:C,color:Q})=>({geom:a.rotateZ(l[2],a.rotateY(l[1],a.rotateX(l[0],C))),color:Q}))}if(g===_Q||g===tw||g===Ec){const l=(I??[]).flatMap(C=>BD(C,A,e)).map(C=>C.geom);if(l.length===0)return[];let B;return g===_Q?B=n.union(l):g===tw?B=n.subtract(l[0],l.slice(1)):B=o.hull(l),[{geom:B,color:A}]}if(g===yH){const l=c?.points??[];return[{geom:s.geom2.fromPoints(l),color:A??c?.color}]}if(g===mH){const l=(I??[]).flatMap(h=>BD(h,A,e)).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===Qt||g===w6A||g===_l||g===JW||g===fH||g===lf){let l;if(g===Qt){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===w6A){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===_l){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===JW){const B=c?.radius??1,C=c?.center??[0,0,0];l=i.sphere({radius:B,center:C})}else if(g===lf){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 BD(l,A,e)}return(I??[]).flatMap(l=>BD(l,A,e))}function YSt(t,A){return{geometries:BD(t,void 0,{jscad:A})}}function v6A(t){if(t.polygons){const A=[],e=[],i=[];let n=0;for(const s of t.polygons){for(const a of s.vertices)a.index=n,A.push(a[0],a[1],a[2]),t.color&&t.color.length>=3?i.push(t.color[0],t.color[1],t.color[2]):i.push(1,1,1),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;e.push(r,g,c)}}const o=new Dg;if(o.setAttribute("position",new Qc(new Float32Array(A),3)),o.setIndex(e),i.length>0&&o.setAttribute("color",new Qc(new Float32Array(i),3)),t.transforms){const s=new rs;s.fromArray(t.transforms),o.applyMatrix4(s)}return o.computeVertexNormals(),o}if(t.sides){const A=[],e=[];for(const n of t.sides)A.push(n[0][0],n[0][1],0),t.color&&t.color.length>=3?e.push(t.color[0],t.color[1],t.color[2]):e.push(1,1,1);const i=new Dg;if(i.setAttribute("position",new Qc(new Float32Array(A),3)),e.length>0&&i.setAttribute("color",new Qc(new Float32Array(e),3)),t.transforms){const n=new rs;n.fromArray(t.transforms),i.applyMatrix4(n)}return i}return console.error("Invalid CSG object: neither polygons nor sides found"),new Dg}function JSt(t,A){const e=rEA(LSt,{footprint:t});return YSt(e,A)}var TSt=Jr(RW()),L6A=V.createContext(null),KSt=()=>{const t=V.useContext(L6A);if(!t)throw new Error("useHover must be used within a HoverProvider");return t},PSt=({children:t})=>{const{camera:A,renderer:e}=Ju(),[i,n]=V.useState([]),o=V.useMemo(()=>new yrt,[]),s=V.useMemo(()=>new In,[]),r=V.useRef(i);r.current=i;const a=V.useRef(null),g=V.useCallback(C=>{n(Q=>[...Q,C])},[]),c=V.useCallback(C=>{if(a.current){let Q=!1,h=a.current.object;for(;h;){if(h===C){Q=!0;break}h=h.parent}Q&&(a.current.onUnhover(),a.current=null)}n(Q=>Q.filter(h=>h.object!==C))},[]),I=V.useCallback(C=>{let Q=C;for(;Q;){const h=r.current.find(E=>E.object===Q);if(h)return h;Q=Q.parent}},[]),l=V.useCallback(C=>{if(!e.domElement)return;const Q=e.domElement.getBoundingClientRect();s.x=(C.clientX-Q.left)/Q.width*2-1,s.y=-((C.clientY-Q.top)/Q.height)*2+1,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 p={mousePosition:[u.point.x,u.point.y,u.point.z]};a.current!==d?(a.current?.onUnhover(),d.onHover(p),a.current=d):d.onHover(p)}else a.current&&(a.current.onUnhover(),a.current=null)}else a.current&&(a.current.onUnhover(),a.current=null)},[A,e,o,s,I]);V.useEffect(()=>{const C=e.domElement;return C.addEventListener("mousemove",l),()=>{C.removeEventListener("mousemove",l)}},[e,l]);const B=V.useMemo(()=>({addHoverable:g,removeHoverable:c}),[g,c]);return W.jsx(L6A.Provider,{value:B,children:t})},qSt=({children:t,object:A,onHover:e,onUnhover:i,isHovered:n})=>{const{addHoverable:o,removeHoverable:s}=KSt();return V.useEffect(()=>A?(o({object:A,onHover:e,onUnhover:i}),()=>{s(A)}):void 0,[A,e,i,o,s]),W.jsx(W.Fragment,{children:t})},GH=qSt,OSt=({positionOffset:t,footprint:A,rotationOffset:e,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=Ju(),g=V.useMemo(()=>{if(!A)return null;const{geometries:c}=JSt(A,TSt),I=new If;for(const l of c.flat(1/0)){const B=l.geom;if(!B||!B.polygons&&!B.sides)continue;const C=new Ki(l.color);C.convertLinearToSRGB();const Q={...B,color:[C.r,C.g,C.b]},h=v6A(Q),E=new bE({vertexColors:!0,side:OB,transparent:r,opacity:r?.5:1,depthWrite:!r}),u=new io(h,E);I.add(u)}return I},[A,r]);return V.useEffect(()=>{if(!(!g||!a))return a.add(g),()=>{a.remove(g)}},[a,g]),V.useEffect(()=>{g&&(t&&g.position.fromArray(t),e&&g.rotation.fromArray(e),s!==void 0&&g.scale.setScalar(s))},[g,t?.[0],t?.[1],t?.[2],e?.[0],e?.[1],e?.[2],s]),V.useEffect(()=>{g&&g.traverse(c=>{c instanceof io&&c.material instanceof bE&&(o?(c.material.emissive.setHex(255),c.material.emissiveIntensity=.2):c.material.emissiveIntensity=0)})},[o,g]),g?W.jsx(GH,{isHovered:o,onHover:i,onUnhover:n,object:g}):null},U6A=new WeakMap,WSt=()=>{const t=new qI;return t.name="fallback-environment-map",t.mapping=K5,t},ZSt=t=>{if(!t)return null;const A=t,e=U6A.get(A);if(e)return e;let i;if(t instanceof f8){const n=new CrA(t);i=n.fromScene(Ort(),.04).texture,n.dispose()}else i=WSt();return U6A.set(A,i),i},H6A=1.25;function Y6A({gltfUrl:t,position:A,rotation:e,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const{renderer:a,rootObject:g}=Ju(),[c,I]=V.useState(null),[l,B]=V.useState(null);if(V.useEffect(()=>{if(!t)return;const C=new Zrt;let Q=!0;return C.load(t,h=>{if(!Q)return;const E=h.scene;E.traverse(u=>{if(u instanceof io&&u.material){const d=p=>{p.transparent=r,p.opacity=r?.5:1,p.depthWrite=!r,p.needsUpdate=!0};Array.isArray(u.material)?u.material.forEach(d):d(u.material)}}),I(E)},void 0,h=>{if(!Q)return;console.error(`An error happened loading ${t}`,h);const E=h instanceof Error?h:new Error(`Failed to load glTF model from ${t}`);B(E)}),()=>{Q=!1}},[t,r]),V.useEffect(()=>{c&&(A&&c.position.fromArray(A),e&&c.rotation.fromArray(e),s!==void 0&&c.scale.setScalar(s))},[c,A?.[0],A?.[1],A?.[2],e?.[0],e?.[1],e?.[2],s]),V.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),V.useEffect(()=>{if(!c||!a)return;const C=ZSt(a);if(!C)return;const Q=[],h=E=>{E instanceof bE&&(Q.push({material:E,envMap:E.envMap??null,envMapIntensity:E.envMapIntensity??1}),E.envMap=C,(typeof E.envMapIntensity!="number"||E.envMapIntensity<H6A)&&(E.envMapIntensity=H6A),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]),V.useEffect(()=>{c&&c.traverse(C=>{C instanceof io&&C.material instanceof bE&&(o?(C.material.emissive.setHex(255),C.material.emissiveIntensity=.2):C.material.emissiveIntensity=0)})},[o,c]),l)throw l;return c?W.jsx(GH,{isHovered:o,onHover:i,onUnhover:n,object:c}):null}var VSt=Jr(qXA()),jSt=Jr(RW()),zSt=({jscadPlan:t,positionOffset:A,rotationOffset:e,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=Ju(),{threeGeom:g,material:c}=V.useMemo(()=>{const l=(0,VSt.executeJscadOperations)(jSt.default,t);if(!l||!l.polygons&&!l.sides)return{threeGeom:null,material:null};const B=v6A(l),C=new bE({vertexColors:!0,side:OB,transparent:r,opacity:r?.5:1,depthWrite:!r});return{threeGeom:B,material:C}},[t,r]),I=V.useMemo(()=>g?new io(g,c):null,[g,c]);return V.useEffect(()=>{if(!(!I||!a))return a.add(I),()=>{a.remove(I)}},[a,I]),V.useEffect(()=>{I&&(A&&I.position.fromArray(A),e&&I.rotation.fromArray(e),s!==void 0&&I.scale.setScalar(s))},[I,A?.[0],A?.[1],A?.[2],e?.[0],e?.[1],e?.[2],s]),V.useMemo(()=>{if(c)if(o){const l=new Ki(c.color.getHex());c.emissive.copy(l),c.emissive.setRGB(0,0,1),c.emissiveIntensity=.2}else c.emissiveIntensity=0},[o,c]),g?W.jsx(GH,{isHovered:o,onHover:i,onUnhover:n,object:I}):null};function XSt(t){return t.replace(/(DEF|USE)\s+([^\s]+)/g,(A,e,i)=>`${e} ${i.replace(/-/g,"_")}`)}async function $St(t){const A=await fetch(t);if(!A.ok)throw new Error(`Failed to fetch "${t}": ${A.status} ${A.statusText}`);const e=await A.text();return new Rat().parse(XSt(e),t)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function Abt(t){const[A,e]=V.useState(null);return V.useEffect(()=>{if(!t)return;const i=t.replace(/&cachebust_origin=$/,""),n=window.TSCIRCUIT_OBJ_LOADER_CACHE;let o=!1;async function s(){try{if(i.endsWith(".wrl"))return await $St(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 Tat;if(c?.length){const l=c.join(`
5138
- `).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new kat;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||e(a)}).catch(a=>{console.error(a)}),()=>{o=!0}},[t]),A}function ebt({url:t,position:A,rotation:e,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const a=Abt(t),{rootObject:g}=Ju(),c=V.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)}}),a):new io(new Xm(.5,.5,.5),new bE({transparent:!0,color:"red",opacity:.25})),[a,r]);if(V.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),V.useEffect(()=>{c&&(A&&(Array.isArray(A)?c.position.fromArray(A):c.position.copy(A)),e&&(Array.isArray(e)?c.rotation.fromArray(e):c.rotation.copy(e)),s!==void 0&&c.scale.setScalar(s))},[c,Array.isArray(A)?A[0]:A?.x,Array.isArray(A)?A[1]:A?.y,Array.isArray(A)?A[2]:A?.z,Array.isArray(e)?e[0]:e?.x,Array.isArray(e)?e[1]:e?.y,Array.isArray(e)?e[2]:e?.z,s]),a instanceof Error)throw a;return W.jsx(GH,{isHovered:o,onHover:i,onUnhover:n,object:c})}var bEA,tbt="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function ibt(t){if(typeof t=="function")return t;if(t&&typeof t=="object"&&"default"in t&&typeof t.default=="function")return t.default;throw new Error("Unable to resolve occt-import-js factory export")}async function nbt(){if(!bEA){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");bEA=ibt(t)({locateFile:e=>`${tbt}/${e}`})}return bEA}function obt(t){const A=new If;for(const e of t){const i=e.attributes.position?.array??[],n=e.index?.array??[];if(!i.length||!n.length)continue;const o=new Dg;o.setAttribute("position",new To(i,3));const s=e.attributes.normal?.array??[];s.length?o.setAttribute("normal",new To(s,3)):o.computeVertexNormals(),o.setIndex(n);const r=new bE({color:e.color?new Ki(e.color[0],e.color[1],e.color[2]):new Ki(.82,.82,.82)}),a=new io(o,r);a.name=e.name,A.add(a)}return A}async function sbt(t){const A=await fetch(t);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const e=await A.arrayBuffer(),n=(await nbt()).ReadStepFile(new Uint8Array(e),null);if(!n.success||!n.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=obt(n.meshes),s=new qrA,r=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})});return URL.createObjectURL(new Blob([r],{type:"model/gltf-binary"}))}var J6A="step-glb-cache:";function rbt(t){const A=new Uint8Array(t),e=32768;let i="";for(let n=0;n<A.length;n+=e){const o=A.subarray(n,n+e);i+=String.fromCharCode(...o)}return btoa(i)}function abt(t){const A=atob(t),e=new Uint8Array(A.length);for(let i=0;i<A.length;i+=1)e[i]=A.charCodeAt(i);return e.buffer}function gbt(t){try{const A=localStorage.getItem(`${J6A}${t}`);return A?abt(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function cbt(t,A){try{const e=rbt(A);localStorage.setItem(`${J6A}${t}`,e)}catch(e){console.warn("Failed to write STEP GLB cache",e)}}var Ibt=({stepUrl:t,position:A,rotation:e,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r})=>{const[a,g]=V.useState(null);return V.useEffect(()=>{let c=!0,I=null;const l=gbt(t);return l?(I=URL.createObjectURL(new Blob([l],{type:"model/gltf-binary"})),g(I),()=>{c=!1,I&&URL.revokeObjectURL(I)}):(sbt(t).then(B=>{if(!c){URL.revokeObjectURL(B);return}I=B,g(B),fetch(B).then(C=>C.arrayBuffer()).then(C=>{cbt(t,C)}).catch(C=>{console.warn("Failed to cache STEP GLB",C)})}).catch(B=>{console.error("Failed to convert STEP file to GLB",B),c&&g(null)}),()=>{c=!1,I&&URL.revokeObjectURL(I)})},[t]),a?W.jsx(Y6A,{gltfUrl:a,position:A,rotation:e,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r}):null},T6A=(...t)=>t,K6A=({cad_component:t,circuitJson:A})=>{const e=ZXA(A),[i,n]=V.useState(!1),{visibility:o}=$N(),[s,r]=V.useState(null),a=V.useCallback(p=>{p?.mousePosition?(n(!0),r(p.mousePosition)):(n(!1),r(null))},[]),g=V.useCallback(()=>{n(!1),r(null)},[]),c=V.useMemo(()=>Di(A).source_component.getUsing({source_component_id:t.source_component_id})?.name,[A,t.source_component_id]),I=V.useMemo(()=>A.filter(m=>m.type==="pcb_plated_hole"&&m.pcb_component_id===t.pcb_component_id).length>0,[A,t.pcb_component_id]),l=t.model_obj_url??t.model_wrl_url??t.model_stl_url,B=t.model_glb_url??t.model_gltf_url,C=t.model_step_url,h=A.find(p=>p.type==="pcb_component"&&p.source_component_id===t.source_component_id)?.layer??"top",E=V.useMemo(()=>t.rotation?T6A(t.rotation.x*Math.PI/180,t.rotation.y*Math.PI/180,t.rotation.z*Math.PI/180):T6A(0,0,0),[t.rotation,h]),u=V.useMemo(()=>{if(!t.position)return;const p=.55;let m;return h==="top"?m=e/2:h==="bottom"?m=-(e/2)-p:m=t.position.z,[t.position.x,t.position.y,m]},[t.position,h,e]);let d=null;if(l?d=W.jsx(ebt,{url:l,position:u,rotation:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):B?d=W.jsx(Y6A,{gltfUrl:B,position:u,rotation:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):C&&!t.model_jscad&&!t.footprinter_string?d=W.jsx(Ibt,{stepUrl:C,position:u,rotation:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model}):t.model_jscad?d=W.jsx(zSt,{jscadPlan:t.model_jscad,positionOffset:u,rotationOffset:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):t.footprinter_string&&(d=W.jsx(OSt,{positionOffset:u,rotationOffset:E,footprint:t.footprinter_string,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model})),t.show_as_translucent_model){if(!o.translucentModels)return null}else if(I&&!o.throughHoleModels||!I&&!o.smtModels)return null;return W.jsxs(W.Fragment,{children:[d,i&&s?W.jsx(jXA,{position:s,style:{fontFamily:"sans-serif",transform:"translate3d(1rem, 1rem, 0)",backgroundColor:"white",padding:"5px",borderRadius:"3px",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:c??"<unknown>"}):null]})},P6A={version:"0.0.505"};function lbt(t){t.querySelectorAll("canvas").forEach(A=>A.remove())}var Bbt=t=>{t.outputColorSpace=Km,t.toneMapping=GKA,t.toneMappingExposure=1},q6A="cadViewerCameraStateSession",O6A=(t,A)=>{try{const e={position:t.position.toArray(),quaternion:t.quaternion.toArray(),up:t.up.toArray(),fov:t.fov??50,target:A.target.toArray()};sessionStorage.setItem(q6A,JSON.stringify(e))}catch(e){console.warn("Failed to save camera:",e)}},xEA=(t,A)=>{try{const e=sessionStorage.getItem(q6A);if(!e)return!1;const i=JSON.parse(e);if(t.position.fromArray(i.position),t.quaternion.fromArray(i.quaternion),t.up.fromArray(i.up),"fov"in t){const n=t;n.fov=i.fov,n.updateProjectionMatrix?.()}return A.target.fromArray(i.target),A.update(),t.updateMatrixWorld(),!0}catch(e){return console.warn("Failed to restore camera:",e),!1}},W6A=V.createContext(void 0),Cbt=({children:t,defaultTarget:A,initialCameraPosition:e})=>{const i=V.useRef(null),n=V.useRef(null),[o,s]=V.useState(null),[r,a]=V.useState("perspective"),[g,c]=V.useState(e??null),[I,l]=V.useState(new gf(0,0,0)),B=V.useMemo(()=>{const[E,u,d]=e??[5,-5,5],p=Math.hypot(E-A.x,u-A.y,d-A.z);return p>0?p:5},[e,A]),C=V.useCallback(E=>{const u=[A.x,A.y,A.z],d=n.current,p=i.current;let m=B;switch(d&&p&&(m=d.position.distanceTo(p.target)),E){case"Top Center Angled":{const D=m/Math.sqrt(2);return{position:[A.x,A.y-D,A.z+D],target:u,up:[0,0,1]}}case"Top Down":return{position:[A.x,A.y,A.z+m],target:u,up:[0,0,1]};case"Top Left Corner":return{position:[A.x-m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Top Right Corner":return{position:[A.x+m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Left Sideview":return{position:[A.x-m,A.y,A.z],target:u,up:[0,0,1]};case"Right Sideview":return{position:[A.x+m,A.y,A.z],target:u,up:[0,0,1]};case"Front":return{position:[A.x,A.y-m,A.z],target:u,up:[0,0,1]};default:return null}},[B,A,n,i]),Q=V.useCallback(E=>{i.current=E},[]),h=V.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:O6A,loadCameraFromSession:xEA}),[A,B,o,C,Q,r,g,I]);return W.jsx(W6A.Provider,{value:h,children:t})},u_=()=>{const t=V.useContext(W6A);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},Qbt=V.forwardRef(({children:t,scene:A,camera:e,style:i,onCreated:n},o)=>{const{cameraType:s}=u_(),r=V.useRef(null),[a,g]=V.useState(null),c=V.useRef([]),I=V.useRef(void 0);I.current=n;const l=V.useRef(null),B=V.useCallback(E=>{c.current.push(E)},[]),C=V.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=V.useMemo(()=>new LF,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=V.useRef(new wg);return V.useImperativeHandle(o,()=>h.current),V.useEffect(()=>{if(!r.current)return;lbt(r.current);const E=new f8({antialias:!0,alpha:!0});Bbt(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 wh(75,u,.1,1e3):new _U(-10*u,10*u,10,-10,-1e3,1e3);l.current?(d.position.copy(l.current.position),d.quaternion.copy(l.current.quaternion),d.up.copy(l.current.up)):(e?.up&&d.up.set(e.up[0],e.up[1],e.up[2]),e?.position&&d.position.set(e.position[0],e.position[1],e.position[2]),d.lookAt(0,0,0)),Q.add(h.current),window.__TSCIRCUIT_THREE_OBJECT=h.current,g({scene:Q,camera:d,renderer:E,rootObject:h.current,addFrameListener:B,removeFrameListener:C}),I.current?.({camera:d,renderer:E});let p;const m=new lrt,D=()=>{const S=m.getElapsedTime(),k=m.getDelta();c.current.forEach(x=>x(S,k)),E.render(Q,d),p=requestAnimationFrame(D)};D();const w=()=>{if(r.current){const S=r.current.clientWidth/r.current.clientHeight;d instanceof wh?d.aspect=S:d instanceof _U&&(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",w),()=>{l.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",w),cancelAnimationFrame(p),r.current&&E.domElement&&r.current.removeChild(E.domElement),E.dispose(),Q.remove(h.current),window.__TSCIRCUIT_THREE_OBJECT===h.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[Q,B,C,s]),W.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&W.jsx(VXA.Provider,{value:a,children:W.jsx(PSt,{children:t})})})}),hbt=({autoRotate:t,autoRotateSpeed:A,onStart:e,panSpeed:i,rotateSpeed:n,zoomSpeed:o,enableDamping:s,dampingFactor:r,target:a,onControlsChange:g})=>{const{camera:c,renderer:I}=Ju(),l=V.useMemo(()=>!c||!I?null:new Pat(c,I.domElement),[c,I]);return V.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),V.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),V.useEffect(()=>{l&&(l.autoRotate=t||!1,l.autoRotateSpeed=A||1,i!==void 0&&(l.panSpeed=i),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:Zx.ROTATE,MIDDLE:Zx.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,t,A,i,n,o,s,r,a]),V.useEffect(()=>{if(!(!l||!e))return l.addEventListener("start",e),()=>{l.removeEventListener("start",e)}},[l,e]),V.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),uH(()=>{l?.update()},[l]),null},Ebt=`
5138
+ `).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new kat;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||e(a)}).catch(a=>{console.error(a)}),()=>{o=!0}},[t]),A}function ebt({url:t,position:A,rotation:e,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const a=Abt(t),{rootObject:g}=Ju(),c=V.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)}}),a):new io(new Xm(.5,.5,.5),new bE({transparent:!0,color:"red",opacity:.25})),[a,r]);if(V.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),V.useEffect(()=>{c&&(A&&(Array.isArray(A)?c.position.fromArray(A):c.position.copy(A)),e&&(Array.isArray(e)?c.rotation.fromArray(e):c.rotation.copy(e)),s!==void 0&&c.scale.setScalar(s))},[c,Array.isArray(A)?A[0]:A?.x,Array.isArray(A)?A[1]:A?.y,Array.isArray(A)?A[2]:A?.z,Array.isArray(e)?e[0]:e?.x,Array.isArray(e)?e[1]:e?.y,Array.isArray(e)?e[2]:e?.z,s]),a instanceof Error)throw a;return W.jsx(GH,{isHovered:o,onHover:i,onUnhover:n,object:c})}var bEA,tbt="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function ibt(t){if(typeof t=="function")return t;if(t&&typeof t=="object"&&"default"in t&&typeof t.default=="function")return t.default;throw new Error("Unable to resolve occt-import-js factory export")}async function nbt(){if(!bEA){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");bEA=ibt(t)({locateFile:e=>`${tbt}/${e}`})}return bEA}function obt(t){const A=new If;for(const e of t){const i=e.attributes.position?.array??[],n=e.index?.array??[];if(!i.length||!n.length)continue;const o=new Dg;o.setAttribute("position",new To(i,3));const s=e.attributes.normal?.array??[];s.length?o.setAttribute("normal",new To(s,3)):o.computeVertexNormals(),o.setIndex(n);const r=new bE({color:e.color?new Ki(e.color[0],e.color[1],e.color[2]):new Ki(.82,.82,.82)}),a=new io(o,r);a.name=e.name,A.add(a)}return A}async function sbt(t){const A=await fetch(t);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const e=await A.arrayBuffer(),n=(await nbt()).ReadStepFile(new Uint8Array(e),null);if(!n.success||!n.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=obt(n.meshes),s=new qrA,r=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})});return URL.createObjectURL(new Blob([r],{type:"model/gltf-binary"}))}var J6A="step-glb-cache:";function rbt(t){const A=new Uint8Array(t),e=32768;let i="";for(let n=0;n<A.length;n+=e){const o=A.subarray(n,n+e);i+=String.fromCharCode(...o)}return btoa(i)}function abt(t){const A=atob(t),e=new Uint8Array(A.length);for(let i=0;i<A.length;i+=1)e[i]=A.charCodeAt(i);return e.buffer}function gbt(t){try{const A=localStorage.getItem(`${J6A}${t}`);return A?abt(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function cbt(t,A){try{const e=rbt(A);localStorage.setItem(`${J6A}${t}`,e)}catch(e){console.warn("Failed to write STEP GLB cache",e)}}var Ibt=({stepUrl:t,position:A,rotation:e,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r})=>{const[a,g]=V.useState(null);return V.useEffect(()=>{let c=!0,I=null;const l=gbt(t);return l?(I=URL.createObjectURL(new Blob([l],{type:"model/gltf-binary"})),g(I),()=>{c=!1,I&&URL.revokeObjectURL(I)}):(sbt(t).then(B=>{if(!c){URL.revokeObjectURL(B);return}I=B,g(B),fetch(B).then(C=>C.arrayBuffer()).then(C=>{cbt(t,C)}).catch(C=>{console.warn("Failed to cache STEP GLB",C)})}).catch(B=>{console.error("Failed to convert STEP file to GLB",B),c&&g(null)}),()=>{c=!1,I&&URL.revokeObjectURL(I)})},[t]),a?W.jsx(Y6A,{gltfUrl:a,position:A,rotation:e,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r}):null},T6A=(...t)=>t,K6A=({cad_component:t,circuitJson:A})=>{const e=ZXA(A),[i,n]=V.useState(!1),{visibility:o}=$N(),[s,r]=V.useState(null),a=V.useCallback(p=>{p?.mousePosition?(n(!0),r(p.mousePosition)):(n(!1),r(null))},[]),g=V.useCallback(()=>{n(!1),r(null)},[]),c=V.useMemo(()=>Di(A).source_component.getUsing({source_component_id:t.source_component_id})?.name,[A,t.source_component_id]),I=V.useMemo(()=>A.filter(m=>m.type==="pcb_plated_hole"&&m.pcb_component_id===t.pcb_component_id).length>0,[A,t.pcb_component_id]),l=t.model_obj_url??t.model_wrl_url??t.model_stl_url,B=t.model_glb_url??t.model_gltf_url,C=t.model_step_url,h=A.find(p=>p.type==="pcb_component"&&p.source_component_id===t.source_component_id)?.layer??"top",E=V.useMemo(()=>t.rotation?T6A(t.rotation.x*Math.PI/180,t.rotation.y*Math.PI/180,t.rotation.z*Math.PI/180):T6A(0,0,0),[t.rotation,h]),u=V.useMemo(()=>{if(!t.position)return;const p=.55;let m;return h==="top"?m=e/2:h==="bottom"?m=-(e/2)-p:m=t.position.z,[t.position.x,t.position.y,m]},[t.position,h,e]);let d=null;if(l?d=W.jsx(ebt,{url:l,position:u,rotation:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):B?d=W.jsx(Y6A,{gltfUrl:B,position:u,rotation:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):C&&!t.model_jscad&&!t.footprinter_string?d=W.jsx(Ibt,{stepUrl:C,position:u,rotation:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model}):t.model_jscad?d=W.jsx(zSt,{jscadPlan:t.model_jscad,positionOffset:u,rotationOffset:E,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):t.footprinter_string&&(d=W.jsx(OSt,{positionOffset:u,rotationOffset:E,footprint:t.footprinter_string,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model})),t.show_as_translucent_model){if(!o.translucentModels)return null}else if(I&&!o.throughHoleModels||!I&&!o.smtModels)return null;return W.jsxs(W.Fragment,{children:[d,i&&s?W.jsx(jXA,{position:s,style:{fontFamily:"sans-serif",transform:"translate3d(1rem, 1rem, 0)",backgroundColor:"white",padding:"5px",borderRadius:"3px",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:c??"<unknown>"}):null]})},P6A={version:"0.0.506"};function lbt(t){t.querySelectorAll("canvas").forEach(A=>A.remove())}var Bbt=t=>{t.outputColorSpace=Km,t.toneMapping=GKA,t.toneMappingExposure=1},q6A="cadViewerCameraStateSession",O6A=(t,A)=>{try{const e={position:t.position.toArray(),quaternion:t.quaternion.toArray(),up:t.up.toArray(),fov:t.fov??50,target:A.target.toArray()};sessionStorage.setItem(q6A,JSON.stringify(e))}catch(e){console.warn("Failed to save camera:",e)}},xEA=(t,A)=>{try{const e=sessionStorage.getItem(q6A);if(!e)return!1;const i=JSON.parse(e);if(t.position.fromArray(i.position),t.quaternion.fromArray(i.quaternion),t.up.fromArray(i.up),"fov"in t){const n=t;n.fov=i.fov,n.updateProjectionMatrix?.()}return A.target.fromArray(i.target),A.update(),t.updateMatrixWorld(),!0}catch(e){return console.warn("Failed to restore camera:",e),!1}},W6A=V.createContext(void 0),Cbt=({children:t,defaultTarget:A,initialCameraPosition:e})=>{const i=V.useRef(null),n=V.useRef(null),[o,s]=V.useState(null),[r,a]=V.useState("perspective"),[g,c]=V.useState(e??null),[I,l]=V.useState(new gf(0,0,0)),B=V.useMemo(()=>{const[E,u,d]=e??[5,-5,5],p=Math.hypot(E-A.x,u-A.y,d-A.z);return p>0?p:5},[e,A]),C=V.useCallback(E=>{const u=[A.x,A.y,A.z],d=n.current,p=i.current;let m=B;switch(d&&p&&(m=d.position.distanceTo(p.target)),E){case"Top Center Angled":{const D=m/Math.sqrt(2);return{position:[A.x,A.y-D,A.z+D],target:u,up:[0,0,1]}}case"Top Down":return{position:[A.x,A.y,A.z+m],target:u,up:[0,0,1]};case"Top Left Corner":return{position:[A.x-m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Top Right Corner":return{position:[A.x+m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Left Sideview":return{position:[A.x-m,A.y,A.z],target:u,up:[0,0,1]};case"Right Sideview":return{position:[A.x+m,A.y,A.z],target:u,up:[0,0,1]};case"Front":return{position:[A.x,A.y-m,A.z],target:u,up:[0,0,1]};default:return null}},[B,A,n,i]),Q=V.useCallback(E=>{i.current=E},[]),h=V.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:O6A,loadCameraFromSession:xEA}),[A,B,o,C,Q,r,g,I]);return W.jsx(W6A.Provider,{value:h,children:t})},u_=()=>{const t=V.useContext(W6A);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},Qbt=V.forwardRef(({children:t,scene:A,camera:e,style:i,onCreated:n},o)=>{const{cameraType:s}=u_(),r=V.useRef(null),[a,g]=V.useState(null),c=V.useRef([]),I=V.useRef(void 0);I.current=n;const l=V.useRef(null),B=V.useCallback(E=>{c.current.push(E)},[]),C=V.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=V.useMemo(()=>new LF,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=V.useRef(new wg);return V.useImperativeHandle(o,()=>h.current),V.useEffect(()=>{if(!r.current)return;lbt(r.current);const E=new f8({antialias:!0,alpha:!0});Bbt(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 wh(75,u,.1,1e3):new _U(-10*u,10*u,10,-10,-1e3,1e3);l.current?(d.position.copy(l.current.position),d.quaternion.copy(l.current.quaternion),d.up.copy(l.current.up)):(e?.up&&d.up.set(e.up[0],e.up[1],e.up[2]),e?.position&&d.position.set(e.position[0],e.position[1],e.position[2]),d.lookAt(0,0,0)),Q.add(h.current),window.__TSCIRCUIT_THREE_OBJECT=h.current,g({scene:Q,camera:d,renderer:E,rootObject:h.current,addFrameListener:B,removeFrameListener:C}),I.current?.({camera:d,renderer:E});let p;const m=new lrt,D=()=>{const S=m.getElapsedTime(),k=m.getDelta();c.current.forEach(x=>x(S,k)),E.render(Q,d),p=requestAnimationFrame(D)};D();const w=()=>{if(r.current){const S=r.current.clientWidth/r.current.clientHeight;d instanceof wh?d.aspect=S:d instanceof _U&&(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",w),()=>{l.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",w),cancelAnimationFrame(p),r.current&&E.domElement&&r.current.removeChild(E.domElement),E.dispose(),Q.remove(h.current),window.__TSCIRCUIT_THREE_OBJECT===h.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[Q,B,C,s]),W.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&W.jsx(VXA.Provider,{value:a,children:W.jsx(PSt,{children:t})})})}),hbt=({autoRotate:t,autoRotateSpeed:A,onStart:e,panSpeed:i,rotateSpeed:n,zoomSpeed:o,enableDamping:s,dampingFactor:r,target:a,onControlsChange:g})=>{const{camera:c,renderer:I}=Ju(),l=V.useMemo(()=>!c||!I?null:new Pat(c,I.domElement),[c,I]);return V.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),V.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),V.useEffect(()=>{l&&(l.autoRotate=t||!1,l.autoRotateSpeed=A||1,i!==void 0&&(l.panSpeed=i),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:Zx.ROTATE,MIDDLE:Zx.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,t,A,i,n,o,s,r,a]),V.useEffect(()=>{if(!(!l||!e))return l.addEventListener("start",e),()=>{l.removeEventListener("start",e)}},[l,e]),V.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),uH(()=>{l?.update()},[l]),null},Ebt=`
5139
5139
  varying vec3 worldPosition;
5140
5140
  void main() {
5141
5141
  worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
@@ -5169,7 +5169,7 @@ ${a.join(`
5169
5169
  gl_FragColor = vec4(color, max(g1, g2) * a);
5170
5170
  if (gl_FragColor.a <= 0.0) discard;
5171
5171
  }
5172
- `,dbt=({rotation:t,infiniteGrid:A,cellSize:e=1,sectionSize:i=10})=>{const{scene:n,camera:o}=Ju(),s=1e3,r=V.useMemo(()=>{const a=new $m(s,s);a.rotateX(-Math.PI/2);const g=new nD({vertexShader:Ebt,fragmentShader:ubt,uniforms:{cellSize:{value:e},sectionSize:{value:i},gridColor:{value:new Ki(15658734)},sectionColor:{value:new Ki(13421823)},fadeDistance:{value:100},fadeStrength:{value:1.5}},transparent:!0,side:OB}),c=new io(a,g);return t&&c.rotation.fromArray(t),c},[s,e,i,t]);return uH(()=>{A&&r.position.set(o.position.x,o.position.y,0)}),V.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},pbt=()=>{const{scene:t}=Ju(),A=V.useMemo(()=>new e4A(16777215,Math.PI/2),[]),e=V.useMemo(()=>{const i=new UrA(16777215,Math.PI/4);return i.position.set(-10,-10,10),i.decay=0,i},[]);return V.useEffect(()=>{if(t)return t.add(A),t.add(e),()=>{t.remove(A),t.remove(e)}},[t,A,e]),null},fbt=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,ybt=()=>{const{controlsRef:t,mainCameraRef:A,defaultTarget:e,setController:i,getPresetConfig:n}=u_(),o=V.useRef(null),s=V.useRef(new Nd),r=V.useRef(new Re),a=V.useRef(new Re),g=V.useRef(new Nd),c=V.useRef(new Nd),I=V.useRef(new wg),l=V.useRef(new wg),B=V.useCallback(({position:Q,target:h,up:E,durationMs:u=600})=>{if(!A.current)return;const d=t.current?.target??e,p=new Re(Q[0],Q[1],Q[2]),m=h?new Re(h[0],h[1],h[2]):e.clone(),D=new Re(...E??[0,0,1]).normalize(),w=l.current;w.position.copy(p),w.up.copy(D),w.lookAt(m);const S=w.quaternion.clone(),k=A.current.quaternion.clone(),x=A.current.position.clone(),N=d.clone(),M=I.current;M.up.set(0,0,1),M.position.copy(x),M.lookAt(N);const L=M.quaternion.clone();M.up.set(0,0,1),M.position.copy(p),M.lookAt(m);const Y=M.quaternion.clone(),H=L.clone().invert().multiply(k).normalize(),O=Y.clone().invert().multiply(S).normalize();o.current={fromPosition:x,toPosition:p,fromTarget:N,toTarget:m,toQuaternion:S,rollFrom:H,rollTo:O,startTime:performance.now(),duration:u}},[A,t,e]),C=V.useCallback(Q=>{if(Q==="Custom")return;const h=n(Q);h&&B(h)},[B,n]);return V.useEffect(()=>A.current?(i({animateTo:B,animateToPreset:C}),()=>{i(null)}):void 0,[B,C,A,i]),uH(()=>{if(!A.current||!o.current)return;const{fromPosition:Q,toPosition:h,fromTarget:E,toTarget:u,toQuaternion:d,rollFrom:p,rollTo:m,startTime:D,duration:w}=o.current,S=performance.now()-D,k=w<=0?1:Math.min(S/w,1),x=fbt(k);A.current.position.lerpVectors(Q,h,x);const N=r.current;N.copy(E).lerp(u,x);const M=I.current;M.up.set(0,0,1),M.position.copy(A.current.position),M.lookAt(N);const L=s.current;L.copy(M.quaternion);const Y=g.current;Y.copy(p);const H=c.current;H.copy(m),p.dot(m)<0&&(H.x*=-1,H.y*=-1,H.z*=-1,H.w*=-1),H.normalize(),Y.slerp(H,x),A.current.quaternion.copy(L).multiply(Y).normalize();const O=a.current;O.set(0,1,0).applyQuaternion(A.current.quaternion).normalize(),A.current.up.copy(O),t.current?.target.copy(N),A.current.updateMatrixWorld(),t.current?.update(),k>=1&&(A.current.position.copy(h),A.current.quaternion.copy(d),A.current.up.set(0,0,1),A.current.updateMatrixWorld(),t.current?.target.copy(u),t.current?.update(),o.current=null)}),null},mbt=()=>{const{controlsRef:t}=u_(),A=V.useRef(null),e=V.useRef(!1),i=V.useRef(null),n=V.useCallback(s=>{A.current=s,!e.current&&t.current&&xEA(s,t.current)&&(e.current=!0)},[t]),o=V.useCallback(()=>{if(!(!A.current||!t.current)){if(!e.current&&xEA(A.current,t.current)){e.current=!0;return}clearTimeout(i.current),i.current=setTimeout(()=>{A.current&&t.current&&O6A(A.current,t.current)},150)}},[t]);return{handleCameraCreated:n,handleControlsChange:o}};function wbt(t,A){const e=new Nd().setFromEuler(new gf(t.x,t.y,t.z)),i=new Re(0,0,1);return i.applyQuaternion(e),i.multiplyScalar(A)}var Dbt=()=>{const{mainCameraRef:t}=u_(),A=V.useRef(null),e=V.useRef(null),i=V.useRef(null),n=V.useRef(null),o=V.useRef(null),s=V.useRef(null);return V.useEffect(()=>{if(!A.current)return;const r=document.createElement("canvas");e.current=r,A.current.appendChild(r);const a=new f8({canvas:r,antialias:!0,alpha:!0});a.setSize(120,120),a.setPixelRatio(window.devicePixelRatio),i.current=a;const g=new LF;n.current=g;const c=new wh(75,1,.1,1e3);c.up.set(0,0,1),o.current=c;const I=new e4A(16777215,Math.PI/2);g.add(I);const l=new If;l.rotation.fromArray([Math.PI/2,0,0]);const B=1,C=new io(new Xm(B,B,B),new bE({color:"white"}));l.add(C);const Q=new MU(new _st(new Xm(B,B,B)),new UF({color:0,linewidth:2}));l.add(Q),g.add(l);const h=.51,E=(k,x,N)=>{const M=new caA;return M.text=k,M.position.fromArray(x),N&&M.rotation.fromArray(N),M.color="black",M.fontSize=.25,M.anchorX="center",M.anchorY="middle",M.depthOffset=0,M.font=null,M.sync(),M},u=E("Front",[0,0,h]),d=E("Back",[0,0,-h],[0,Math.PI,0]),p=E("Right",[h,0,0],[0,Math.PI/2,0]),m=E("Left",[-h,0,0],[0,-Math.PI/2,0]),D=E("Top",[0,h,0],[-Math.PI/2,0,0]),w=E("Bottom",[0,-h,0],[Math.PI/2,0,0]);l.add(u),l.add(d),l.add(p),l.add(m),l.add(D),l.add(w);const S=()=>{if(t.current){const k=wbt(t.current.rotation??new gf(0,0,0),2);k.equals(c.position)||(c.position.copy(k),c.lookAt(0,0,0))}a.render(g,c),s.current=requestAnimationFrame(S)};return S(),()=>{s.current&&cancelAnimationFrame(s.current),u.dispose(),d.dispose(),p.dispose(),m.dispose(),D.dispose(),w.dispose(),C.geometry.dispose(),C.material.dispose(),Q.geometry.dispose(),Q.material.dispose(),g.clear(),a.dispose(),e.current&&A.current&&A.current.removeChild(e.current)}},[t]),W.jsx("div",{ref:A,style:{position:"absolute",top:0,left:0,width:120,height:120,zIndex:dH.orientationCube}})},Sbt=()=>{const{camera:t}=Ju(),{setCameraRotation:A}=u_();return uH(()=>{t&&A(t.rotation)}),null},Z6A=V.forwardRef(({children:t,initialCameraPosition:A=[5,-5,5],autoRotateDisabled:e,clickToInteractEnabled:i=!1,boardDimensions:n,boardCenter:o,onUserInteraction:s,onCameraControllerReady:r},a)=>{const[g,c]=V.useState(!i),{mainCameraRef:I,handleControlsChange:l,controller:B}=u_(),{handleCameraCreated:C,handleControlsChange:Q}=mbt();V.useEffect(()=>{r&&r(B)},[B,r]);const h=V.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=V.useMemo(()=>{if(o)return[o.x,o.y,0]},[o]);return W.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[W.jsx(Dbt,{}),W.jsxs(Qbt,{ref:a,scene:{up:new Re(0,0,1)},camera:{up:[0,0,1],position:A},onCreated:({camera:u})=>{I.current=u,C(u)},children:[W.jsx(ybt,{}),W.jsx(Sbt,{}),g&&W.jsx(hbt,{autoRotate:!e,autoRotateSpeed:1,onStart:s,rotateSpeed:.5,panSpeed:.75,zoomSpeed:.5,enableDamping:!0,dampingFactor:.1,target:E,onControlsChange:u=>{l(u),Q()}}),W.jsx(pbt,{}),W.jsx(dbt,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:3,sectionSize:h,args:[h,h]}),t]}),W.jsxs("div",{style:{position:"absolute",right:24,bottom:24,fontFamily:"sans-serif",color:"white",WebkitTextStroke:"0.5px rgba(0, 0, 0, 0.5)",fontSize:11},children:["@",P6A.version]}),i&&!g&&W.jsx("button",{type:"button",onClick:()=>c(!0),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&c(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:dH.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center"},children:W.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",fontFamily:"sans-serif",pointerEvents:"none"},children:"Click to Interact"})})]})}),V6A=t=>V.useMemo(()=>{if(!t)return[];const A=new pXe;return A.add(t),A.render(),A.getCircuitJson()},[t]),bbt=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(!0);return V.useEffect(()=>{if(!t)return;(async()=>{n(!0);const r=(Array.isArray(t)?t:[t]).map(async(a,g)=>{const c=YCt.serialize({binary:!0},[a]),l=await new Blob(c).arrayBuffer(),C=a.layerType||(g===0?"board":void 0);return{stlData:l,color:a.color,layerType:C}});try{const a=await Promise.all(r);e(a)}catch(a){console.error("Error generating STLs:",a),e([])}finally{n(!1)}})()},[t]),{stls:A,loading:i}},xbt=Jr(Q_()),_bt=Jr(DW()),Jn=.01,Wa={traces:.001,copper:.002},Xn={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]},Bf=.001,VB=32,RH=.035,MH=150,qW=.6,_EA={fr1:Xn.fr1Tan,fr4:Xn.fr4Tan},j6A={fr1:Xn.fr1SolderMaskGreen,fr4:Xn.fr4SolderMaskGreen},kbt=Jr(EH()),Fbt=Jr(Q_()),Gbt=Jr($F()),Rbt=Jr(JXA()),z6A=t=>{let A=0;for(let i=0;i<t.length;i++){const n=(i+1)%t.length;A+=t[i][0]*t[n][1],A-=t[n][0]*t[i][1]}return A/2<=0},kEA=(t,A=1.2,e={})=>{const{xyOutset:i=0}=e,{outline:n}=t;let o=n.map(a=>[a.x,a.y]);z6A(o)&&(o=o.reverse());let s=(0,Fbt.polygon)({points:o});i!==0&&(s=(0,Rbt.expand)({delta:i,corners:"edge"},s));let r=(0,kbt.extrudeLinear)({height:A},s);return r=(0,Gbt.translate)([0,0,-A/2],r),r},Mbt=t=>{const A=t.filter(a=>a.type==="pcb_panel"),e=Di(t).pcb_board.list();let i,n=1.2;if(A.length>0)i=A[0],n=e.find(g=>g.pcb_panel_id===i.pcb_panel_id)?.thickness??1.2;else{if(i=e.filter(g=>!g.pcb_panel_id)[0],!i)return console.warn("No pcb_board or pcb_panel found for simplified geometry"),[];n=i.thickness??1.2}let o;"outline"in i&&i.outline&&i.outline.length>0?o=kEA({outline:i.outline},n):o=(0,xbt.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?e.find(a=>a.pcb_panel_id===i.pcb_panel_id)?.material??"fr4":"fr4",r=_EA[s]??Xn.fr4Tan;return[(0,_bt.colorize)(r,o)]},Dh=Jr($F()),xg=Jr(Q_()),Tu=Jr(DW()),_g=Jr(XN()),or=Jr(Q_()),CD=Jr(DW()),ia=Jr(XN()),X6A=Jr($F()),NH=Jr(EH()),Hd=Jr($F()),Nbt=1e-5;function w0(t,A,e){if(typeof e!="number"||!Number.isFinite(e)||e<=0)return 0;const i=t/2,n=A/2,o=Math.min(i,n)-2*Nbt;return Math.max(0,Math.min(e,o))}function NC(t){if(!(!t||typeof t!="object"))return t.corner_radius??t.cornerRadius??t.rect_pad_border_radius??t.rectPadBorderRadius??t.rect_border_radius??t.rectBorderRadius??void 0}var d_=Jr(Q_()),vbt=Jr(EH()),OW=Jr($F()),Lbt=Jr(XN()),Ubt=64,Hbt=(t,A,e)=>{const i=(0,d_.ellipse)({center:[0,0],radius:[Math.max(t/2,Jn/2),Math.max(A/2,Jn/2)],segments:Ubt}),n=(0,vbt.extrudeLinear)({height:e},i);return(0,OW.translate)([0,0,-e/2],n)},Ybt=(t,A,e)=>{const i=Math.max(t,Jn),n=Math.max(A,Jn);if(Math.abs(i-n)<1e-6)return(0,d_.cylinder)({center:[0,0,0],radius:i/2,height:e});const o=i>=n,s=o?i:n,r=o?n:i,a=Math.max(s-r,0),g=(0,d_.cuboid)({center:[0,0,0],size:o?[a,r,e]:[r,a,e]});if(a<=1e-6)return(0,d_.cylinder)({center:[0,0,0],radius:r/2,height:e});const c=a/2,I=(0,d_.cylinder)({center:o?[-c,0,0]:[0,-c,0],radius:r/2,height:e}),l=(0,d_.cylinder)({center:o?[c,0,0]:[0,c,0],radius:r/2,height:e});return(0,Lbt.union)(g,I,l)},WW=(t,A,e={})=>{const i=t.hole_shape||"circle",n=e.sizeDelta??0,o=t.hole_offset_x||0,s=t.hole_offset_y||0,r=[t.x+o,t.y+s,0];if(i==="circle"){const B=Math.max((t.hole_diameter??0)+n,Jn),C=Math.max(B/2,Jn/2);return(0,d_.cylinder)({center:r,radius:C,height:A})}const a=t.hole_width??t.hole_diameter,g=t.hole_height??t.hole_diameter;if(!a||!g)return null;const c=Math.max(a+n,Jn),I=Math.max(g+n,Jn);if(i==="oval"){const B=Hbt(c,I,A);return(0,OW.translate)([r[0],r[1],0],B)}if(i==="pill"||i==="rotated_pill"){let B=Ybt(c,I,A);if(!B)return null;const C=t.ccw_rotation||0;return C&&(B=(0,OW.rotateZ)(C*Math.PI/180,B)),(0,OW.translate)(r,B)}const l=Math.max((t.hole_diameter??a??g??Jn)+n,Jn);return(0,d_.cylinder)({center:r,radius:l/2,height:A})},D0=.02,ZW=64,AG=(t,A)=>A?(0,ia.intersect)(A,t):t,lv=({width:t,height:A,thickness:e,center:i,borderRadius:n})=>{const o=w0(t,A,n);if(o<=0)return(0,or.cuboid)({center:i,size:[t,A,e]});const s=(0,or.roundedRectangle)({size:[t,A],roundRadius:o,segments:ZW}),r=(0,NH.extrudeLinear)({height:e},s),a=i[2]-e/2;return(0,Hd.translate)([i[0],i[1],a],r)},vH=(t,A,e={})=>{const{clipGeom:i}=e;t.shape||(t.shape="circle");const n=A.pcbThickness+2*D0+4*Jn,o=A.pcbThickness/2+Wa.copper,s=-A.pcbThickness/2-Wa.copper,r=o-s;if(t.shape==="circle"){const a=t.outer_diameter??Math.max(t.hole_diameter,0),g=r+.01,c=(0,or.cylinder)({center:[t.x,t.y,0],radius:a/2,height:g}),I=AG(c,i),l=(0,or.cylinder)({center:[t.x,t.y,0],radius:Math.max(t.hole_diameter/2,.01),height:n});return(0,CD.colorize)(Xn.copper,(0,ia.subtract)(I,l))}if(t.shape==="oval"){const a=t.outer_width||t.hole_width||0,g=t.outer_height||t.hole_height||0,c=t.hole_width||0,I=t.hole_height||0,l=(()=>{const Q=(0,or.cylinder)({center:[0,0,0],radius:1,height:r+.01,segments:64}),h=(0,X6A.scale)([a/2,g/2,1],Q);return(0,Hd.translate)([t.x,t.y,0],h)})(),B=AG(l,i),C=(()=>{const Q=(0,or.cylinder)({center:[0,0,0],radius:1,height:n,segments:64}),h=(0,X6A.scale)([Math.max(c/2,.01),Math.max(I/2,.01),1],Q);return(0,Hd.translate)([t.x,t.y,0],h)})();return(0,CD.colorize)(Xn.copper,(0,ia.subtract)(B,C))}if(t.shape==="circular_hole_with_rect_pad"){const a=t.hole_offset_x||0,g=t.hole_offset_y||0,c=t.rect_pad_width||t.hole_diameter,I=t.rect_pad_height||t.hole_diameter,l=NC(t),B=AG((0,ia.union)(lv({width:c,height:I,thickness:D0,center:[t.x,t.y,o],borderRadius:l}),lv({width:c,height:I,thickness:D0,center:[t.x,t.y,s],borderRadius:l}),(()=>{const E=Math.max(r-D0*2,Jn),p=(o+s)/2,m=(0,or.roundedRectangle)({size:[c,I],roundRadius:l||0,segments:ZW}),D=(0,NH.extrudeLinear)({height:E},m);return(0,Hd.translate)([t.x,t.y,p-E/2],D)})(),(0,or.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:t.hole_diameter/2,height:r})),i),C=(0,or.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:Math.max(t.hole_diameter/2-Jn,.01),height:n}),Q=(0,or.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:t.hole_diameter/2,height:r});let h=(0,ia.union)((0,ia.subtract)(B,Q),Q);return e.clipGeom?(h=(0,ia.subtract)(h,C),h=(0,ia.intersect)(h,e.clipGeom),(0,CD.colorize)(Xn.copper,h)):(0,CD.colorize)(Xn.copper,(0,ia.subtract)(h,C))}if(t.shape==="pill"){const a=(t.ccw_rotation||0)*Math.PI/180,g=x=>{if(!a)return x;const N=(0,Hd.translate)([-t.x,-t.y,0],x),M=(0,Hd.rotate)([0,0,a],N);return(0,Hd.translate)([t.x,t.y,0],M)},c=t.hole_height>t.hole_width,I=c?t.hole_height:t.hole_width,l=c?t.hole_width:t.hole_height,B=c?t.outer_height||l+.2:t.outer_width||I+.2,C=c?t.outer_width||I+.2:t.outer_height||l+.2,Q=l/2,h=Math.abs(I-l),E=r+.01,d=((x,N,M)=>{const L=N/2,Y=Math.abs(x-N);if(Y<=1e-6)return(0,or.cylinder)({center:[t.x,t.y,0],radius:L,height:M});const H=(0,or.cuboid)({center:[t.x,t.y,0],size:c?[N,Y,M]:[Y,N,M]}),O=(0,or.cylinder)({center:c?[t.x,t.y-Y/2,0]:[t.x-Y/2,t.y,0],radius:L,height:M}),Z=(0,or.cylinder)({center:c?[t.x,t.y+Y/2,0]:[t.x+Y/2,t.y,0],radius:L,height:M});return(0,ia.union)(H,O,Z)})(B,C,E),p=(0,or.cuboid)({center:[t.x,t.y,0],size:c?[l-2*Jn,h,n]:[h,l-2*Jn,n]}),m=(0,or.cylinder)({center:c?[t.x,t.y-h/2,0]:[t.x-h/2,t.y,0],radius:Q-Jn,height:n}),D=(0,or.cylinder)({center:c?[t.x,t.y+h/2,0]:[t.x+h/2,t.y,0],radius:Q-Jn,height:n}),w=(0,ia.union)(p,m,D),S=AG(g(d),i),k=g(w);return(0,CD.colorize)(Xn.copper,(0,ia.subtract)(S,k))}if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for pill_hole_with_rect_pad");const a=t.hole_offset_x||0,g=t.hole_offset_y||0,c=t.hole_height>t.hole_width,I=c?t.hole_height:t.hole_width,l=c?t.hole_width:t.hole_height,B=l/2,C=Math.abs(I-l),Q=t.rect_pad_width||I+.2,h=t.rect_pad_height||l+.2,E=NC(t),u=.03,d=(0,ia.union)((0,or.cuboid)({center:[t.x+a,t.y+g,0],size:c?[l+2*u,C+2*u,r]:[C+2*u,l+2*u,r]}),(0,or.cylinder)({center:c?[t.x+a,t.y+g-C/2,0]:[t.x+a-C/2,t.y+g,0],radius:B+u,height:r}),(0,or.cylinder)({center:c?[t.x+a,t.y+g+C/2,0]:[t.x+a+C/2,t.y+g,0],radius:B+u,height:r})),p=(0,ia.union)((0,or.cuboid)({center:[t.x+a,t.y+g,0],size:c?[l,C,n*1.1]:[C,l,n*1.1]}),(0,or.cylinder)({center:c?[t.x+a,t.y+g-C/2,0]:[t.x+a-C/2,t.y+g,0],radius:B,height:n*1.1}),(0,or.cylinder)({center:c?[t.x+a,t.y+g+C/2,0]:[t.x+a+C/2,t.y+g,0],radius:B,height:n*1.1})),m=lv({width:Q,height:h,thickness:D0,center:[t.x,t.y,o],borderRadius:E}),D=lv({width:Q,height:h,thickness:D0,center:[t.x,t.y,s],borderRadius:E}),w=(()=>{const Y=Math.max(r-D0*2,Jn),Z=(o+s)/2,$=(0,or.roundedRectangle)({size:[Q,h],roundRadius:E||0,segments:ZW}),tA=(0,NH.extrudeLinear)({height:Y},$);return(0,Hd.translate)([t.x,t.y,Z-Y/2],tA)})(),S=(0,ia.subtract)(m,p),k=(0,ia.subtract)(D,p),x=(0,ia.subtract)(w,p),N=(0,ia.union)((0,or.cuboid)({center:[t.x+a,t.y+g,0],size:c?[l-2*Jn,C-2*Jn,n*1.1]:[C-2*Jn,l-2*Jn,n*1.1]}),(0,or.cylinder)({center:c?[t.x+a,t.y+g-C/2,0]:[t.x+a-C/2,t.y+g,0],radius:B-Jn,height:n*1.1}),(0,or.cylinder)({center:c?[t.x+a,t.y+g+C/2,0]:[t.x+a+C/2,t.y+g,0],radius:B-Jn,height:n*1.1})),M=(0,ia.subtract)(d,N),L=AG((0,ia.union)(S,k,x,M),i);return(0,CD.colorize)(Xn.copper,L)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for rotated_pill_hole_with_rect_pad");const a=t.hole_offset_x||0,g=t.hole_offset_y||0,c=t.hole_width,I=t.hole_height,l=c>=I,B=l?c:I,C=l?I:c,Q=C/2,h=Math.abs(B-C),E=t.rect_pad_width||c+.2,u=t.rect_pad_height||I+.2,d=NC(t),p=.03,m=(t.hole_ccw_rotation||0)*Math.PI/180,D=(t.rect_ccw_rotation||0)*Math.PI/180,w=aA=>{const eA=a*Math.cos(m)-g*Math.sin(m),nA=a*Math.sin(m)+g*Math.cos(m),rA=(0,Hd.rotate)([0,0,m],aA);return(0,Hd.translate)([t.x+eA,t.y+nA,0],rA)},S=aA=>{if(!D)return aA;const eA=(0,Hd.translate)([-t.x,-t.y,0],aA),nA=(0,Hd.rotate)([0,0,D],eA);return(0,Hd.translate)([t.x,t.y,0],nA)},k=w((0,ia.union)((0,or.cuboid)({center:[0,0,0],size:l?[h+2*p,C+2*p,r]:[C+2*p,h+2*p,r]}),(0,or.cylinder)({center:l?[-h/2,0,0]:[0,-h/2,0],radius:Q+p,height:r}),(0,or.cylinder)({center:l?[h/2,0,0]:[0,h/2,0],radius:Q+p,height:r}))),x=w((0,ia.union)((0,or.cuboid)({center:[0,0,0],size:l?[h,C,n*1.1]:[C,h,n*1.1]}),(0,or.cylinder)({center:l?[-h/2,0,0]:[0,-h/2,0],radius:Q,height:n*1.1}),(0,or.cylinder)({center:l?[h/2,0,0]:[0,h/2,0],radius:Q,height:n*1.1}))),N=S(lv({width:E,height:u,thickness:D0,center:[t.x,t.y,o],borderRadius:d})),M=S(lv({width:E,height:u,thickness:D0,center:[t.x,t.y,s],borderRadius:d})),L=S((()=>{const aA=Math.max(r-D0*2,Jn),rA=(o+s)/2,lA=(0,or.roundedRectangle)({size:[E,u],roundRadius:d||0,segments:ZW}),fA=(0,NH.extrudeLinear)({height:aA},lA);return(0,Hd.translate)([t.x,t.y,rA-aA/2],fA)})()),Y=(0,ia.subtract)(N,x),H=(0,ia.subtract)(M,x),O=(0,ia.subtract)(L,x),Z=w((0,ia.union)((0,or.cuboid)({center:[0,0,0],size:l?[h-2*Jn,C-2*Jn,n*1.1]:[C-2*Jn,h-2*Jn,n*1.1]}),(0,or.cylinder)({center:l?[-h/2,0,0]:[0,-h/2,0],radius:Q-Jn,height:n*1.1}),(0,or.cylinder)({center:l?[h/2,0,0]:[0,h/2,0],radius:Q-Jn,height:n*1.1}))),$=(0,ia.subtract)(k,Z),tA=AG((0,ia.union)(Y,H,O,$),i);return(0,CD.colorize)(Xn.copper,tA)}else if(t.shape==="hole_with_polygon_pad"){const a=t.pad_outline;if(!Array.isArray(a)||a.length<3)throw new Error(`Invalid pad_outline for plated hole at (${t.x}, ${t.y})`);const g=a.map(p=>[p.x,p.y]),c=(0,or.polygon)({points:g}),I=(o+s)/2,l=(p,m)=>{const D=Math.max(p,Jn),w=(0,NH.extrudeLinear)({height:D},c);return(0,Hd.translate)([t.x,t.y,m-D/2],w)},B=l(Math.max(r-D0*2,Jn),I),C=l(D0,o),Q=l(D0,s),h=AG((0,ia.union)(B,C,Q),i),E=WW(t,r);if(!E)return(0,CD.colorize)(Xn.copper,h);const u=WW(t,n,{sizeDelta:-2*Jn})||E;let d=(0,ia.union)((0,ia.subtract)(h,E),E);return e.clipGeom?(d=(0,ia.subtract)(d,u),d=(0,ia.intersect)(d,e.clipGeom),(0,CD.colorize)(Xn.copper,d)):(0,CD.colorize)(Xn.copper,(0,ia.subtract)(d,u))}else throw new Error(`Unsupported plated hole shape: ${t.shape}`)},VW=Jr(EH()),$6A=Jr(XN()),Jbt=Jr($F()),LH=Jr(Q_());function Tbt({x:t,y:A,outerDiameter:e,holeDiameter:i,thickness:n}){if(e<=i)throw new Error(`Invalid via geometry: outerDiameter (${e}) must be > holeDiameter (${i})`);const o=Jn,s=Jn,r=Math.min(e/2,i/2+s),a=(0,LH.cylinder)({center:[0,0,0],radius:r,height:n,segments:VB}),g=(0,LH.cylinder)({center:[0,0,n/2],radius:e/2,height:o,segments:VB}),c=(0,LH.cylinder)({center:[0,0,-n/2],radius:e/2,height:o,segments:VB}),I=(0,$6A.union)([a,g,c]),l=n+o*2,B=(0,LH.cylinder)({center:[0,0,0],radius:i/2,height:l,segments:VB}),C=(0,$6A.subtract)(I,B);return(0,Jbt.translate)([t,A,0],C)}function Kbt({x:t,y:A,holeDiameter:e,thickness:i}){const n=i*1.5,o=e/2+Jn;return(0,LH.cylinder)({center:[t,A,0],radius:o,height:n,segments:VB})}var A7A=64,Pbt=1,FEA=.05,e7A=(t,A,e,i)=>{const n=w0(t,A,i);if(n<=0)return(0,xg.cuboid)({center:[0,0,0],size:[t,A,e]});const o=(0,xg.roundedRectangle)({size:[t,A],roundRadius:n,segments:A7A}),s=(0,VW.extrudeLinear)({height:e},o);return(0,Dh.translate)([0,0,-e/2],s)},t7A=["initializing","processing_pads","processing_copper_pours","processing_plated_holes","processing_holes","processing_cutouts","processing_vias","finalizing","done"],qbt=class{circuitJson;board;plated_holes;holes;pads;traces;pcb_vias;pcb_cutouts;boardGeom=null;platedHoleGeoms=[];padGeoms=[];viaGeoms=[];copperPourGeoms=[];boardClipGeom=null;state="initializing";currentIndex=0;ctx;onCompleteCallback;finalGeoms=[];getHoleToCut(t,A){const e=Jn/10;for(const i of this.pcb_vias)if(Math.abs(i.x-t)<e&&Math.abs(i.y-A)<e&&i.hole_diameter)return{diameter:i.hole_diameter};for(const i of this.plated_holes)if(i.shape==="circle"&&Math.abs(i.x-t)<e&&Math.abs(i.y-A)<e&&i.hole_diameter)return{diameter:i.hole_diameter};return null}constructor(t,A){this.circuitJson=t,this.onCompleteCallback=A;const e=t.filter(n=>n.type==="pcb_panel"),i=Di(t).pcb_board.list();if(e.length>0){const n=e[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=Di(t).pcb_plated_hole.list(),this.holes=Di(t).pcb_hole.list(),this.pads=Di(t).pcb_smtpad.list(),this.traces=Di(t).pcb_trace.list(),this.pcb_vias=Di(t).pcb_via.list(),this.pcb_cutouts=Di(t).pcb_cutout.list(),this.ctx={pcbThickness:this.board.thickness??1.2},this.initializeBoard()}initializeBoard(){const t=this.ctx.pcbThickness+2*Pbt;this.board.outline&&this.board.outline.length>0?(this.boardGeom=kEA({outline:this.board.outline},this.ctx.pcbThickness),this.boardClipGeom=kEA({outline:this.board.outline},t,{xyOutset:FEA})):(this.boardGeom=(0,xg.cuboid)({size:[this.board.width,this.board.height,this.ctx.pcbThickness],center:[this.board.center.x,this.board.center.y,0]}),this.boardClipGeom=(0,xg.cuboid)({size:[this.board.width+2*FEA,this.board.height+2*FEA,t],center:[this.board.center.x,this.board.center.y,0]})),this.state="processing_pads",this.currentIndex=0}goToNextState(){const t=t7A.indexOf(this.state);t!==-1&&(this.state=t7A[t+1],this.currentIndex=0)}step(t=1){if(this.state==="done"||!this.boardGeom)return!0;for(let A=0;A<t&&this.state!=="done";A++)switch(this.state){case"processing_plated_holes":this.currentIndex<this.plated_holes.length?(this.processPlatedHole(this.plated_holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_holes":this.currentIndex<this.holes.length?(this.processHole(this.holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_pads":this.currentIndex<this.pads.length?(this.processPad(this.pads[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_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(t){if(!this.boardGeom)return;let A=null;const e=this.ctx.pcbThickness*1.5;switch(t.shape){case"rect":{const i=w0(t.width,t.height,NC(t));if(i>0){const n=(0,xg.roundedRectangle)({size:[t.width,t.height],roundRadius:i,segments:A7A});A=(0,VW.extrudeLinear)({height:e},n),A=(0,Dh.translate)([0,0,-e/2],A)}else A=(0,xg.cuboid)({center:[0,0,0],size:[t.width,t.height,e]});if(t.rotation){const n=t.rotation*Math.PI/180;A=(0,Dh.rotateZ)(n,A)}A=(0,Dh.translate)([t.center.x,t.center.y,0],A);break}case"circle":A=(0,xg.cylinder)({center:[t.center.x,t.center.y,0],radius:t.radius,height:e});break;case"polygon":{let i=t.points.map(o=>[o.x,o.y]);if(i.length<3){console.warn(`PCB Cutout [${t.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);break}z6A(i)&&(i=i.reverse());const n=(0,xg.polygon)({points:i});A=(0,VW.extrudeLinear)({height:e},n),A=(0,Dh.translate)([0,0,-e/2],A);break}}A&&(this.boardGeom=(0,_g.subtract)(this.boardGeom,A))}processPlatedHole(t,A={}){if(this.boardGeom){if(t.shape==="circle"||t.shape==="circular_hole_with_rect_pad"){let e=null;if(t.shape==="circular_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="circle"||t.pad_shape&&t.pad_shape!=="rect")return;e=(0,xg.cylinder)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],radius:t.hole_diameter/2+Jn,height:this.ctx.pcbThickness*1.5})}else e=(0,xg.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+Jn,height:this.ctx.pcbThickness*1.5});A.dontCutBoard||(this.boardGeom=(0,_g.subtract)(this.boardGeom,e)),this.padGeoms=this.padGeoms.map(n=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(n,e)));const i=vH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(i)}else if(t.shape==="pill"||t.shape==="oval"){const e=t.hole_height>t.hole_width,i=e?t.hole_height:t.hole_width,n=e?t.hole_width:t.hole_height,o=n/2,s=Math.abs(i-n);let r;if(r=(0,_g.union)((0,xg.cuboid)({center:[t.x,t.y,0],size:e?[n,s,this.ctx.pcbThickness*1.5]:[s,n,this.ctx.pcbThickness*1.5]}),(0,xg.cylinder)({center:e?[t.x,t.y-s/2,0]:[t.x-s/2,t.y,0],radius:o,height:this.ctx.pcbThickness*1.5}),(0,xg.cylinder)({center:e?[t.x,t.y+s/2,0]:[t.x+s/2,t.y,0],radius:o,height:this.ctx.pcbThickness*1.5})),t.ccw_rotation){const g=t.ccw_rotation*Math.PI/180;r=(0,Dh.translate)([t.x,t.y,0],(0,Dh.rotateZ)(g,(0,Dh.translate)([-t.x,-t.y,0],r)))}A.dontCutBoard||(this.boardGeom=(0,_g.subtract)(this.boardGeom,r)),this.padGeoms=this.padGeoms.map(g=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(g,r)));const a=vH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")return;const e=t.hole_height>t.hole_width,i=e?t.hole_height:t.hole_width,n=e?t.hole_width:t.hole_height,o=n/2,s=Math.abs(i-n);let r;r=(0,_g.union)((0,xg.cuboid)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],size:e?[n,s,this.ctx.pcbThickness*1.5]:[s,n,this.ctx.pcbThickness*1.5]}),(0,xg.cylinder)({center:e?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)-s/2,0]:[t.x+(t.hole_offset_x||0)-s/2,t.y+(t.hole_offset_y||0),0],radius:o,height:this.ctx.pcbThickness*1.5}),(0,xg.cylinder)({center:e?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)+s/2,0]:[t.x+(t.hole_offset_x||0)+s/2,t.y+(t.hole_offset_y||0),0],radius:o,height:this.ctx.pcbThickness*1.5})),A.dontCutBoard||(this.boardGeom=(0,_g.subtract)(this.boardGeom,r)),this.padGeoms=this.padGeoms.map(g=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(g,r)));const a=vH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")return;const e=t.hole_width,i=t.hole_height,n=e>=i,o=n?e:i,s=n?i:e,r=s/2,a=Math.abs(o-s),g=t.hole_offset_x||0,c=t.hole_offset_y||0;let I=(0,_g.union)((0,xg.cuboid)({center:[0,0,0],size:n?[a,s,this.ctx.pcbThickness*1.5]:[s,a,this.ctx.pcbThickness*1.5]}),(0,xg.cylinder)({center:n?[-a/2,0,0]:[0,-a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}),(0,xg.cylinder)({center:n?[a/2,0,0]:[0,a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}));const l=(t.hole_ccw_rotation||0)*Math.PI/180,B=g*Math.cos(l)-c*Math.sin(l),C=g*Math.sin(l)+c*Math.cos(l);I=(0,Dh.rotateZ)(l,I);const Q=(0,Dh.translate)([t.x+B,t.y+C,0],I);A.dontCutBoard||(this.boardGeom=(0,_g.subtract)(this.boardGeom,Q)),this.padGeoms=this.padGeoms.map(E=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(E,Q)));const h=vH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(h)}else if(t.shape==="hole_with_polygon_pad"){const e=t.pad_outline;if(!Array.isArray(e)||e.length<3)return;const i=this.ctx.pcbThickness*1.5,n=WW(t,i,{sizeDelta:2*Jn}),o=WW(t,i,{sizeDelta:-2*Jn});if(!n||!o)return;A.dontCutBoard||(this.boardGeom=(0,_g.subtract)(this.boardGeom,n)),this.padGeoms=this.padGeoms.map(r=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(r,n))),this.platedHoleGeoms=this.platedHoleGeoms.map(r=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(r,o)));const s=vH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(s)}}}processHole(t){if(!this.boardGeom)return;const A=this.ctx.pcbThickness*1.5;if(t.hole_shape==="circle"){const e=(0,xg.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+Jn,height:A});this.boardGeom=(0,_g.subtract)(this.boardGeom,e),this.padGeoms=this.padGeoms.map(n=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(n,e)));const i=(0,xg.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+Jn/2,height:A});this.platedHoleGeoms=this.platedHoleGeoms.map(n=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(n,i)))}else if(t.hole_shape==="pill"||t.hole_shape==="rotated_pill"||t.hole_shape==="oval"){const e=t.hole_width??t.hole_diameter,i=t.hole_height??t.hole_diameter,n=t.ccw_rotation??t.rotation??0,o=.02,s=(g,c,I,l)=>{if(g<=0||c<=0)return null;if(l)return(0,Dh.translate)([0,0,-I/2],(0,VW.extrudeLinear)({height:I},(0,xg.ellipse)({radius:[g/2,c/2]})));const B=Math.min(g,c)/2,C=Math.abs(g-c);return g>c?(0,_g.union)((0,xg.cuboid)({center:[0,0,0],size:[C,c,I]}),(0,xg.cylinder)({center:[-C/2,0,0],radius:B,height:I}),(0,xg.cylinder)({center:[C/2,0,0],radius:B,height:I})):(0,_g.union)((0,xg.cuboid)({center:[0,0,0],size:[g,C,I]}),(0,xg.cylinder)({center:[0,-C/2,0],radius:B,height:I}),(0,xg.cylinder)({center:[0,C/2,0],radius:B,height:I}))};let r=s(e,i,A,t.hole_shape==="oval"),a=s(e-2*o,i-2*o,A,t.hole_shape==="oval");if(r&&n!==0&&(r=(0,Dh.rotateZ)(n*Math.PI/180,r)),a&&n!==0&&(a=(0,Dh.rotateZ)(n*Math.PI/180,a)),r){const g=(0,Dh.translate)([t.x,t.y,0],r);this.boardGeom=(0,_g.subtract)(this.boardGeom,g),this.padGeoms=this.padGeoms.map(c=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(c,g)))}if(a){const g=(0,Dh.translate)([t.x,t.y,0],a);this.platedHoleGeoms=this.platedHoleGeoms.map(c=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(c,g)))}}}processPad(t){const A=t.layer==="bottom"?-1:1,e=A*this.ctx.pcbThickness/2+A*Wa.copper,i=NC(t);if(t.shape==="rect"){const n=e7A(t.width,t.height,Jn,i);let s=(0,Dh.translate)([t.x,t.y,e],n);this.boardClipGeom&&(s=(0,_g.intersect)(this.boardClipGeom,s)),s=(0,Tu.colorize)(Xn.copper,s),this.padGeoms.push(s)}else if(t.shape==="rotated_rect"){let n=e7A(t.width,t.height,Jn,i);const o=t.ccw_rotation*Math.PI/180;n=(0,Dh.rotateZ)(o,n);let r=(0,Dh.translate)([t.x,t.y,e],n);this.boardClipGeom&&(r=(0,_g.intersect)(this.boardClipGeom,r)),r=(0,Tu.colorize)(Xn.copper,r),this.padGeoms.push(r)}else if(t.shape==="circle"){let n=(0,xg.cylinder)({center:[t.x,t.y,e],radius:t.radius,height:Jn});this.boardClipGeom&&(n=(0,_g.intersect)(this.boardClipGeom,n)),n=(0,Tu.colorize)(Xn.copper,n),this.padGeoms.push(n)}}processVia(t){if(this.boardGeom){if(typeof t.outer_diameter=="number"&&typeof t.hole_diameter=="number"){const A=Tbt({x:t.x,y:t.y,outerDiameter:t.outer_diameter,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});let e=A;this.boardClipGeom&&(e=(0,_g.intersect)(this.boardClipGeom,A),e=(0,Tu.colorize)(Xn.copper,e)),this.viaGeoms.push(e)}if(typeof t.hole_diameter=="number"){const A=Kbt({x:t.x,y:t.y,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});this.boardGeom=(0,_g.subtract)(this.boardGeom,A),this.padGeoms=this.padGeoms.map(e=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(e,A)))}}}finalize(){if(!this.boardGeom)return;const t=_EA[this.board.material]??Xn.fr4Tan;this.boardGeom=(0,Tu.colorize)(t,this.boardGeom),this.finalGeoms=[this.boardGeom,...this.platedHoleGeoms,...this.padGeoms,...this.viaGeoms,...this.copperPourGeoms],this.onCompleteCallback&&this.onCompleteCallback(this.finalGeoms)}getGeoms(){return this.finalGeoms}},Obt=t=>{const[A,e]=V.useState(null),i=V.useRef(!1);return V.useEffect(()=>{let n=!1;if(!t){e(null);return}if(!t.some(g=>g.type==="pcb_board"||g.type==="pcb_panel")){e(null);return}const s=Mbt(t);e(s);const r=new qbt(t,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||e(r.getGeoms())}catch(g){console.error("Error during board geometry building:",g)}finally{i.current=!1}}})(),()=>{n=!0}},[t]),A},Wbt=({children:t,parent:A,position:e,rotation:i,scale:n,color:o,fontSize:s,anchorX:r,anchorY:a,depthOffset:g})=>{const{rootObject:c}=Ju(),I=V.useMemo(()=>{const l=new caA;return l.text=t,e&&l.position.fromArray(e),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},[t,e,i,n,o,s,r,a,g]);return V.useEffect(()=>{const l=A||c;if(!(!l||!I))return l.add(I),()=>{l.remove(I),I.dispose()}},[c,A,I]),null},i7A=({error:t,cad_component:A})=>{const{rootObject:e}=Ju(),[i,n]=V.useState(!1),[o,s]=V.useState(null),r=V.useCallback(I=>{I?.mousePosition?(n(!0),s(I.mousePosition)):(n(!1),s(null))},[]),a=V.useCallback(()=>{n(!1),s(null)},[]),g=V.useMemo(()=>A?.position?[A.position.x,A.position.y,A.position.z].map(l=>Number.isNaN(l)?0:l):[0,0,0],[A]),c=V.useMemo(()=>{const I=new If;return I.position.fromArray(g),I},[g]);return V.useEffect(()=>{if(e)return e.add(c),()=>{e.remove(c)}},[e,c]),W.jsxs(W.Fragment,{children:[W.jsxs(GH,{isHovered:i,onHover:r,onUnhover:a,object:c,children:[W.jsx(Zbt,{parent:c}),W.jsx(Wbt,{parent:c,scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:`${t.toString().slice(0,50)}...`})]}),i&&o?W.jsx(jXA,{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:t.toString()}):null]})},Zbt=({parent:t})=>{const A=V.useMemo(()=>{const e=new io(new Xm(.5,.5,.5),new bE({depthTest:!1,transparent:!0,color:"red",opacity:.5}));return e.renderOrder=999999,e.rotation.fromArray([Math.PI/4,Math.PI/4,0]),e},[]);return V.useEffect(()=>(t.add(A),()=>{t.remove(A)}),[t,A]),null};function Vbt({stlUrl:t,stlData:A,mtlUrl:e,color:i,opacity:n=1}){const{rootObject:o}=Ju(),[s,r]=V.useState(null);V.useEffect(()=>{const g=new _at;if(A){try{const c=g.parse(A);r(c)}catch(c){console.error("Failed to parse STL data",c),r(null)}return}t&&g.load(t,c=>{r(c)})},[t,A]);const a=V.useMemo(()=>{if(!s)return null;const g=new bE({color:Array.isArray(i)?new Ki(i[0],i[1],i[2]):i,transparent:n!==1,opacity:n});return new io(s,g)},[s,i,n]);return V.useEffect(()=>{if(!(!o||!a))return o.add(a),()=>{o.remove(a),a.geometry.dispose(),Array.isArray(a.material)?a.material.forEach(g=>g.dispose()):a.material.dispose()}},[o,a]),null}function jbt({stlData:t,color:A,opacity:e=1,layerType:i}){const{visibility:n}=$N();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?W.jsx(Vbt,{stlData:t,color:A,opacity:e}):null}var n7A=class extends tn.Component{constructor(t){super(t),this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},zbt=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,n=t[0].y;for(let o=1;o<t.length;o++){const s=t[o];s.x<A&&(A=s.x),s.y<e&&(e=s.y),s.x>i&&(i=s.x),s.y>n&&(n=s.y)}return{minX:A,minY:e,maxX:i,maxY:n}};function p_(t){if(t.outline&&t.outline.length>=3){const s=zbt(t.outline);return{...s,width:s.maxX-s.minX,height:s.maxY-s.minY,centerX:(s.minX+s.maxX)/2,centerY:(s.minY+s.maxY)/2}}const A=t.width??0,e=t.height??0,i=t.center?.x??0,n=t.center?.y??0;return{...{minX:i-A/2,maxX:i+A/2,minY:n-e/2,maxY:n+e/2},width:A,height:e,centerX:i,centerY:n}}Jr(Q_()),Jr(XN());function Xbt(t,A,e,i){if(!e||Math.abs(e)<1e-9)return[];const n=4*Math.atan(e),o=A[0]-t[0],s=A[1]-t[1],r=Math.sqrt(o*o+s*s);if(r<1e-9)return[];const a=Math.abs(r/(2*Math.sin(n/2))),g=Math.sqrt(Math.max(0,a*a-r/2*(r/2))),c=[(t[0]+A[0])/2,(t[1]+A[1])/2],I=o/r,B=-(s/r),C=I,Q=c[0]+B*g*Math.sign(e),h=c[1]+C*g*Math.sign(e),E=Math.atan2(t[1]-h,t[0]-Q),u=[],d=Math.max(2,Math.ceil(i*Math.abs(n)/(Math.PI*2)*4)),p=n/d;for(let m=1;m<d;m++){const D=E+p*m;u.push([Q+a*Math.cos(D),h+a*Math.sin(D)])}return u}function o7A(t,A){const e=[],i=t.vertices;for(let n=0;n<i.length;n++){const o=i[n],s=i[(n+1)%i.length];if(e.push([o.x,o.y]),o.bulge){const r=Xbt([o.x,o.y],[s.x,s.y],o.bulge,A);e.push(...r)}}return e}function s7A({ctx:t,points:A,canvasXFromPcb:e,canvasYFromPcb:i}){A.length<3||(t.beginPath(),A.forEach((n,o)=>{const s=e(n[0]),r=i(n[1]);o===0?t.moveTo(s,r):t.lineTo(s,r)}),t.closePath(),t.fill())}function $bt({ctx:t,pour:A,canvasXFromPcb:e,canvasYFromPcb:i}){const n=A.brep_shape;if(!n||!n.outer_ring)return;const o=o7A(n.outer_ring,32);if(o.length>=3&&s7A({ctx:t,points:o,canvasXFromPcb:e,canvasYFromPcb:i}),n.inner_rings&&n.inner_rings.length>0){t.globalCompositeOperation="destination-out";for(const s of n.inner_rings){const r=o7A(s,32);r.length>=3&&s7A({ctx:t,points:r,canvasXFromPcb:e,canvasYFromPcb:i})}t.globalCompositeOperation="source-over"}}function jW({layer:t,circuitJson:A,boardData:e,traceTextureResolution:i=MH}){const n=A.filter(E=>E.type==="pcb_copper_pour"),o=t==="top"?"top_copper":"bottom_copper",s=n.filter(E=>E.layer===t);if(s.length===0)return null;const r=p_(e),a=document.createElement("canvas"),g=Math.floor(r.width*i),c=Math.floor(r.height*i);a.width=g,a.height=c;const I=a.getContext("2d");if(!I)return null;t==="bottom"&&(I.translate(0,c),I.scale(1,-1));const l=E=>(E-r.minX)*i,B=E=>(r.maxY-E)*i,C=s.filter(E=>E.shape==="rect"||E.shape==="polygon"),Q=s.filter(E=>E.shape==="brep");if(C.length>0){const E=new PQt(I);E.setCameraBounds({minX:r.minX,maxX:r.maxX,minY:r.minY,maxY:r.maxY});const u=C.filter(D=>D.covered_with_solder_mask!==!1),d=C.filter(D=>D.covered_with_solder_mask===!1),p=`rgb(${Xn.fr4TracesWithMaskGreen.map(D=>D*255).join(",")})`,m=`rgb(${Xn.copper.map(D=>D*255).join(",")})`;u.length>0&&(E.configure({colorOverrides:{copper:{top:p,bottom:p,inner1:p,inner2:p,inner3:p,inner4:p,inner5:p,inner6:p}}}),E.drawElements(u,{layers:[o]})),d.length>0&&(E.configure({colorOverrides:{copper:{top:m,bottom:m,inner1:m,inner2:m,inner3:m,inner4:m,inner5:m,inner6:m}}}),E.drawElements(d,{layers:[o]}))}for(const E of Q){const d=E.covered_with_solder_mask!==!1?Xn.fr4TracesWithMaskGreen:Xn.copper,p=`rgb(${d[0]*255}, ${d[1]*255}, ${d[2]*255})`;I.fillStyle=p,$bt({ctx:I,pour:E,canvasXFromPcb:l,canvasYFromPcb:B})}const h=new MN(a);return h.generateMipmaps=!0,h.minFilter=Lu,h.magFilter=oB,h.anisotropy=16,h.needsUpdate=!0,h}function Cf(t,A){const{texture:e,yOffset:i,isBottomLayer:n,textureType:o,usePolygonOffset:s=!1,renderOrder:r=0,isFaux:a=!1}=t;if(!e)return null;const g=p_(A),c=new $m(g.width,g.height),I=new vd({map:e,transparent:!0,side:OB,depthWrite:o==="panel-outlines",polygonOffset:s,polygonOffsetFactor:s?-4:0,polygonOffsetUnits:s?-4:0,opacity:a?qW:1}),l=new io(c,I);return l.position.set(g.centerX,g.centerY,i),n&&l.rotation.set(Math.PI,0,0),l.name=`${n?"bottom":"top"}-${o}-texture-plane`,l.renderOrder=r,l}function Axt(t,A,e,i=!1){const n=[];if(!t||!A||e===null)return n;const o=Cf({texture:t.topTrace,yOffset:e/2+Wa.traces,isBottomLayer:!1,textureType:"trace",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);o&&n.push(o);const s=Cf({texture:t.topTraceWithMask,yOffset:e/2+Wa.traces,isBottomLayer:!1,textureType:"trace-with-mask",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);s&&n.push(s);const r=Cf({texture:t.topSilkscreen,yOffset:e/2+.003,isBottomLayer:!1,textureType:"silkscreen",usePolygonOffset:!1,renderOrder:3,isFaux:i},A);r&&n.push(r);const a=Cf({texture:t.bottomTrace,yOffset:-e/2-Wa.traces,isBottomLayer:!0,textureType:"trace",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);a&&n.push(a);const g=Cf({texture:t.bottomTraceWithMask,yOffset:-e/2-Wa.traces,isBottomLayer:!0,textureType:"trace-with-mask",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);g&&n.push(g);const c=Cf({texture:t.bottomSilkscreen,yOffset:-e/2-.003,isBottomLayer:!0,textureType:"silkscreen",usePolygonOffset:!1,renderOrder:3,isFaux:i},A);c&&n.push(c);const I=Cf({texture:t.topSoldermask,yOffset:e/2+.001,isBottomLayer:!1,textureType:"soldermask",usePolygonOffset:!0,renderOrder:1,isFaux:i},A);I&&n.push(I);const l=Cf({texture:t.bottomSoldermask,yOffset:-e/2-.001,isBottomLayer:!0,textureType:"soldermask",usePolygonOffset:!0,renderOrder:1,isFaux:i},A);l&&n.push(l);const B=Cf({texture:t.topCopperText,yOffset:e/2+Wa.copper,isBottomLayer:!1,textureType:"copper-text",usePolygonOffset:!0,renderOrder:2,isFaux:i},A);B&&n.push(B);const C=Cf({texture:t.bottomCopperText,yOffset:-e/2-Wa.copper,isBottomLayer:!0,textureType:"copper-text",usePolygonOffset:!0,renderOrder:2,isFaux:i},A);C&&n.push(C);const Q=Cf({texture:t.topCopper,yOffset:e/2+Wa.copper,isBottomLayer:!1,textureType:"copper",usePolygonOffset:!0,renderOrder:2,isFaux:i},A);Q&&n.push(Q);const h=Cf({texture:t.bottomCopper,yOffset:-e/2-Wa.copper,isBottomLayer:!0,textureType:"copper",usePolygonOffset:!0,renderOrder:2,isFaux:i},A);h&&n.push(h);const E=Cf({texture:t.topPanelOutlines,yOffset:e/2+.004,isBottomLayer:!1,textureType:"panel-outlines",usePolygonOffset:!1,renderOrder:4,isFaux:i},A);E&&n.push(E);const u=Cf({texture:t.bottomPanelOutlines,yOffset:-e/2-.004,isBottomLayer:!0,textureType:"panel-outlines",usePolygonOffset:!1,renderOrder:4,isFaux:i},A);return u&&n.push(u),n}var ext=Jr(WhA());function r7A(t,A){return Array.isArray(A)?[t.a*A[0]+t.c*A[1]+t.e,t.b*A[0]+t.d*A[1]+t.f]:{x:t.a*A.x+t.c*A.y+t.e,y:t.b*A.x+t.d*A.y+t.f}}function f_(t,A=0){return{a:1,c:0,e:t,b:0,d:1,f:A}}function a7A(...t){t=Array.isArray(t[0])?t[0]:t;const A=(e,i)=>({a:e.a*i.a+e.c*i.b,c:e.a*i.c+e.c*i.d,e:e.a*i.e+e.c*i.f+e.e,b:e.b*i.a+e.d*i.b,d:e.b*i.c+e.d*i.d,f:e.b*i.e+e.d*i.f+e.f});switch(t.length){case 0:throw new Error("no matrices provided");case 1:return t[0];case 2:return A(t[0],t[1]);default:{const[e,i,...n]=t,o=A(e,i);return a7A(o,...n)}}}function g7A(...t){return a7A(...t)}var{cos:txt,sin:ixt}=Math;function c7A(t,A,e){const i=txt(t),n=ixt(t);return{a:i,c:-n,e:0,b:n,d:i,f:0}}function nxt(t,A){function e(){this.constructor=t}e.prototype=A.prototype,t.prototype=new e}function zW(t,A,e,i){var n=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(n,zW.prototype),n.expected=A,n.found=e,n.location=i,n.name="SyntaxError",n}nxt(zW,Error);function GEA(t,A,e){return e=e||" ",t.length>A?t:(A-=t.length,e+=e.repeat(A),t+e.slice(0,A))}zW.prototype.format=function(t){var A="Error: "+this.message;if(this.location){var e=null,i;for(i=0;i<t.length;i++)if(t[i].source===this.location.source){e=t[i].text.split(/\r\n|\n|\r/g);break}var n=this.location.start,o=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(n):n,s=this.location.source+":"+o.line+":"+o.column;if(e){var r=this.location.end,a=GEA("",o.line.toString().length," "),g=e[n.line-1],c=n.line===r.line?r.column:g.length+1,I=c-n.column||1;A+=`
5172
+ `,dbt=({rotation:t,infiniteGrid:A,cellSize:e=1,sectionSize:i=10})=>{const{scene:n,camera:o}=Ju(),s=1e3,r=V.useMemo(()=>{const a=new $m(s,s);a.rotateX(-Math.PI/2);const g=new nD({vertexShader:Ebt,fragmentShader:ubt,uniforms:{cellSize:{value:e},sectionSize:{value:i},gridColor:{value:new Ki(15658734)},sectionColor:{value:new Ki(13421823)},fadeDistance:{value:100},fadeStrength:{value:1.5}},transparent:!0,side:OB}),c=new io(a,g);return t&&c.rotation.fromArray(t),c},[s,e,i,t]);return uH(()=>{A&&r.position.set(o.position.x,o.position.y,0)}),V.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},pbt=()=>{const{scene:t}=Ju(),A=V.useMemo(()=>new e4A(16777215,Math.PI/2),[]),e=V.useMemo(()=>{const i=new UrA(16777215,Math.PI/4);return i.position.set(-10,-10,10),i.decay=0,i},[]);return V.useEffect(()=>{if(t)return t.add(A),t.add(e),()=>{t.remove(A),t.remove(e)}},[t,A,e]),null},fbt=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,ybt=()=>{const{controlsRef:t,mainCameraRef:A,defaultTarget:e,setController:i,getPresetConfig:n}=u_(),o=V.useRef(null),s=V.useRef(new Nd),r=V.useRef(new Re),a=V.useRef(new Re),g=V.useRef(new Nd),c=V.useRef(new Nd),I=V.useRef(new wg),l=V.useRef(new wg),B=V.useCallback(({position:Q,target:h,up:E,durationMs:u=600})=>{if(!A.current)return;const d=t.current?.target??e,p=new Re(Q[0],Q[1],Q[2]),m=h?new Re(h[0],h[1],h[2]):e.clone(),D=new Re(...E??[0,0,1]).normalize(),w=l.current;w.position.copy(p),w.up.copy(D),w.lookAt(m);const S=w.quaternion.clone(),k=A.current.quaternion.clone(),x=A.current.position.clone(),N=d.clone(),M=I.current;M.up.set(0,0,1),M.position.copy(x),M.lookAt(N);const L=M.quaternion.clone();M.up.set(0,0,1),M.position.copy(p),M.lookAt(m);const Y=M.quaternion.clone(),H=L.clone().invert().multiply(k).normalize(),O=Y.clone().invert().multiply(S).normalize();o.current={fromPosition:x,toPosition:p,fromTarget:N,toTarget:m,toQuaternion:S,rollFrom:H,rollTo:O,startTime:performance.now(),duration:u}},[A,t,e]),C=V.useCallback(Q=>{if(Q==="Custom")return;const h=n(Q);h&&B(h)},[B,n]);return V.useEffect(()=>A.current?(i({animateTo:B,animateToPreset:C}),()=>{i(null)}):void 0,[B,C,A,i]),uH(()=>{if(!A.current||!o.current)return;const{fromPosition:Q,toPosition:h,fromTarget:E,toTarget:u,toQuaternion:d,rollFrom:p,rollTo:m,startTime:D,duration:w}=o.current,S=performance.now()-D,k=w<=0?1:Math.min(S/w,1),x=fbt(k);A.current.position.lerpVectors(Q,h,x);const N=r.current;N.copy(E).lerp(u,x);const M=I.current;M.up.set(0,0,1),M.position.copy(A.current.position),M.lookAt(N);const L=s.current;L.copy(M.quaternion);const Y=g.current;Y.copy(p);const H=c.current;H.copy(m),p.dot(m)<0&&(H.x*=-1,H.y*=-1,H.z*=-1,H.w*=-1),H.normalize(),Y.slerp(H,x),A.current.quaternion.copy(L).multiply(Y).normalize();const O=a.current;O.set(0,1,0).applyQuaternion(A.current.quaternion).normalize(),A.current.up.copy(O),t.current?.target.copy(N),A.current.updateMatrixWorld(),t.current?.update(),k>=1&&(A.current.position.copy(h),A.current.quaternion.copy(d),A.current.up.set(0,0,1),A.current.updateMatrixWorld(),t.current?.target.copy(u),t.current?.update(),o.current=null)}),null},mbt=()=>{const{controlsRef:t}=u_(),A=V.useRef(null),e=V.useRef(!1),i=V.useRef(null),n=V.useCallback(s=>{A.current=s,!e.current&&t.current&&xEA(s,t.current)&&(e.current=!0)},[t]),o=V.useCallback(()=>{if(!(!A.current||!t.current)){if(!e.current&&xEA(A.current,t.current)){e.current=!0;return}clearTimeout(i.current),i.current=setTimeout(()=>{A.current&&t.current&&O6A(A.current,t.current)},150)}},[t]);return{handleCameraCreated:n,handleControlsChange:o}};function wbt(t,A){const e=new Nd().setFromEuler(new gf(t.x,t.y,t.z)),i=new Re(0,0,1);return i.applyQuaternion(e),i.multiplyScalar(A)}var Dbt=()=>{const{mainCameraRef:t}=u_(),A=V.useRef(null),e=V.useRef(null),i=V.useRef(null),n=V.useRef(null),o=V.useRef(null),s=V.useRef(null);return V.useEffect(()=>{if(!A.current)return;const r=document.createElement("canvas");e.current=r,A.current.appendChild(r);const a=new f8({canvas:r,antialias:!0,alpha:!0});a.setSize(120,120),a.setPixelRatio(window.devicePixelRatio),i.current=a;const g=new LF;n.current=g;const c=new wh(75,1,.1,1e3);c.up.set(0,0,1),o.current=c;const I=new e4A(16777215,Math.PI/2);g.add(I);const l=new If;l.rotation.fromArray([Math.PI/2,0,0]);const B=1,C=new io(new Xm(B,B,B),new bE({color:"white"}));l.add(C);const Q=new MU(new _st(new Xm(B,B,B)),new UF({color:0,linewidth:2}));l.add(Q),g.add(l);const h=.51,E=(k,x,N)=>{const M=new caA;return M.text=k,M.position.fromArray(x),N&&M.rotation.fromArray(N),M.color="black",M.fontSize=.25,M.anchorX="center",M.anchorY="middle",M.depthOffset=0,M.font=null,M.sync(),M},u=E("Front",[0,0,h]),d=E("Back",[0,0,-h],[0,Math.PI,0]),p=E("Right",[h,0,0],[0,Math.PI/2,0]),m=E("Left",[-h,0,0],[0,-Math.PI/2,0]),D=E("Top",[0,h,0],[-Math.PI/2,0,0]),w=E("Bottom",[0,-h,0],[Math.PI/2,0,0]);l.add(u),l.add(d),l.add(p),l.add(m),l.add(D),l.add(w);const S=()=>{if(t.current){const k=wbt(t.current.rotation??new gf(0,0,0),2);k.equals(c.position)||(c.position.copy(k),c.lookAt(0,0,0))}a.render(g,c),s.current=requestAnimationFrame(S)};return S(),()=>{s.current&&cancelAnimationFrame(s.current),u.dispose(),d.dispose(),p.dispose(),m.dispose(),D.dispose(),w.dispose(),C.geometry.dispose(),C.material.dispose(),Q.geometry.dispose(),Q.material.dispose(),g.clear(),a.dispose(),a.forceContextLoss(),e.current&&A.current&&A.current.removeChild(e.current)}},[t]),W.jsx("div",{ref:A,style:{position:"absolute",top:0,left:0,width:120,height:120,zIndex:dH.orientationCube}})},Sbt=()=>{const{camera:t}=Ju(),{setCameraRotation:A}=u_();return uH(()=>{t&&A(t.rotation)}),null},Z6A=V.forwardRef(({children:t,initialCameraPosition:A=[5,-5,5],autoRotateDisabled:e,clickToInteractEnabled:i=!1,boardDimensions:n,boardCenter:o,onUserInteraction:s,onCameraControllerReady:r},a)=>{const[g,c]=V.useState(!i),{mainCameraRef:I,handleControlsChange:l,controller:B}=u_(),{handleCameraCreated:C,handleControlsChange:Q}=mbt();V.useEffect(()=>{r&&r(B)},[B,r]);const h=V.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=V.useMemo(()=>{if(o)return[o.x,o.y,0]},[o]);return W.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[W.jsx(Dbt,{}),W.jsxs(Qbt,{ref:a,scene:{up:new Re(0,0,1)},camera:{up:[0,0,1],position:A},onCreated:({camera:u})=>{I.current=u,C(u)},children:[W.jsx(ybt,{}),W.jsx(Sbt,{}),g&&W.jsx(hbt,{autoRotate:!e,autoRotateSpeed:1,onStart:s,rotateSpeed:.5,panSpeed:.75,zoomSpeed:.5,enableDamping:!0,dampingFactor:.1,target:E,onControlsChange:u=>{l(u),Q()}}),W.jsx(pbt,{}),W.jsx(dbt,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:3,sectionSize:h,args:[h,h]}),t]}),W.jsxs("div",{style:{position:"absolute",right:24,bottom:24,fontFamily:"sans-serif",color:"white",WebkitTextStroke:"0.5px rgba(0, 0, 0, 0.5)",fontSize:11},children:["@",P6A.version]}),i&&!g&&W.jsx("button",{type:"button",onClick:()=>c(!0),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&c(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:dH.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center"},children:W.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",fontFamily:"sans-serif",pointerEvents:"none"},children:"Click to Interact"})})]})}),V6A=t=>V.useMemo(()=>{if(!t)return[];const A=new pXe;return A.add(t),A.render(),A.getCircuitJson()},[t]),bbt=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(!0);return V.useEffect(()=>{if(!t)return;(async()=>{n(!0);const r=(Array.isArray(t)?t:[t]).map(async(a,g)=>{const c=YCt.serialize({binary:!0},[a]),l=await new Blob(c).arrayBuffer(),C=a.layerType||(g===0?"board":void 0);return{stlData:l,color:a.color,layerType:C}});try{const a=await Promise.all(r);e(a)}catch(a){console.error("Error generating STLs:",a),e([])}finally{n(!1)}})()},[t]),{stls:A,loading:i}},xbt=Jr(Q_()),_bt=Jr(DW()),Jn=.01,Wa={traces:.001,copper:.002},Xn={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]},Bf=.001,VB=32,RH=.035,MH=150,qW=.6,_EA={fr1:Xn.fr1Tan,fr4:Xn.fr4Tan},j6A={fr1:Xn.fr1SolderMaskGreen,fr4:Xn.fr4SolderMaskGreen},kbt=Jr(EH()),Fbt=Jr(Q_()),Gbt=Jr($F()),Rbt=Jr(JXA()),z6A=t=>{let A=0;for(let i=0;i<t.length;i++){const n=(i+1)%t.length;A+=t[i][0]*t[n][1],A-=t[n][0]*t[i][1]}return A/2<=0},kEA=(t,A=1.2,e={})=>{const{xyOutset:i=0}=e,{outline:n}=t;let o=n.map(a=>[a.x,a.y]);z6A(o)&&(o=o.reverse());let s=(0,Fbt.polygon)({points:o});i!==0&&(s=(0,Rbt.expand)({delta:i,corners:"edge"},s));let r=(0,kbt.extrudeLinear)({height:A},s);return r=(0,Gbt.translate)([0,0,-A/2],r),r},Mbt=t=>{const A=t.filter(a=>a.type==="pcb_panel"),e=Di(t).pcb_board.list();let i,n=1.2;if(A.length>0)i=A[0],n=e.find(g=>g.pcb_panel_id===i.pcb_panel_id)?.thickness??1.2;else{if(i=e.filter(g=>!g.pcb_panel_id)[0],!i)return console.warn("No pcb_board or pcb_panel found for simplified geometry"),[];n=i.thickness??1.2}let o;"outline"in i&&i.outline&&i.outline.length>0?o=kEA({outline:i.outline},n):o=(0,xbt.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?e.find(a=>a.pcb_panel_id===i.pcb_panel_id)?.material??"fr4":"fr4",r=_EA[s]??Xn.fr4Tan;return[(0,_bt.colorize)(r,o)]},Dh=Jr($F()),xg=Jr(Q_()),Tu=Jr(DW()),_g=Jr(XN()),or=Jr(Q_()),CD=Jr(DW()),ia=Jr(XN()),X6A=Jr($F()),NH=Jr(EH()),Hd=Jr($F()),Nbt=1e-5;function w0(t,A,e){if(typeof e!="number"||!Number.isFinite(e)||e<=0)return 0;const i=t/2,n=A/2,o=Math.min(i,n)-2*Nbt;return Math.max(0,Math.min(e,o))}function NC(t){if(!(!t||typeof t!="object"))return t.corner_radius??t.cornerRadius??t.rect_pad_border_radius??t.rectPadBorderRadius??t.rect_border_radius??t.rectBorderRadius??void 0}var d_=Jr(Q_()),vbt=Jr(EH()),OW=Jr($F()),Lbt=Jr(XN()),Ubt=64,Hbt=(t,A,e)=>{const i=(0,d_.ellipse)({center:[0,0],radius:[Math.max(t/2,Jn/2),Math.max(A/2,Jn/2)],segments:Ubt}),n=(0,vbt.extrudeLinear)({height:e},i);return(0,OW.translate)([0,0,-e/2],n)},Ybt=(t,A,e)=>{const i=Math.max(t,Jn),n=Math.max(A,Jn);if(Math.abs(i-n)<1e-6)return(0,d_.cylinder)({center:[0,0,0],radius:i/2,height:e});const o=i>=n,s=o?i:n,r=o?n:i,a=Math.max(s-r,0),g=(0,d_.cuboid)({center:[0,0,0],size:o?[a,r,e]:[r,a,e]});if(a<=1e-6)return(0,d_.cylinder)({center:[0,0,0],radius:r/2,height:e});const c=a/2,I=(0,d_.cylinder)({center:o?[-c,0,0]:[0,-c,0],radius:r/2,height:e}),l=(0,d_.cylinder)({center:o?[c,0,0]:[0,c,0],radius:r/2,height:e});return(0,Lbt.union)(g,I,l)},WW=(t,A,e={})=>{const i=t.hole_shape||"circle",n=e.sizeDelta??0,o=t.hole_offset_x||0,s=t.hole_offset_y||0,r=[t.x+o,t.y+s,0];if(i==="circle"){const B=Math.max((t.hole_diameter??0)+n,Jn),C=Math.max(B/2,Jn/2);return(0,d_.cylinder)({center:r,radius:C,height:A})}const a=t.hole_width??t.hole_diameter,g=t.hole_height??t.hole_diameter;if(!a||!g)return null;const c=Math.max(a+n,Jn),I=Math.max(g+n,Jn);if(i==="oval"){const B=Hbt(c,I,A);return(0,OW.translate)([r[0],r[1],0],B)}if(i==="pill"||i==="rotated_pill"){let B=Ybt(c,I,A);if(!B)return null;const C=t.ccw_rotation||0;return C&&(B=(0,OW.rotateZ)(C*Math.PI/180,B)),(0,OW.translate)(r,B)}const l=Math.max((t.hole_diameter??a??g??Jn)+n,Jn);return(0,d_.cylinder)({center:r,radius:l/2,height:A})},D0=.02,ZW=64,AG=(t,A)=>A?(0,ia.intersect)(A,t):t,lv=({width:t,height:A,thickness:e,center:i,borderRadius:n})=>{const o=w0(t,A,n);if(o<=0)return(0,or.cuboid)({center:i,size:[t,A,e]});const s=(0,or.roundedRectangle)({size:[t,A],roundRadius:o,segments:ZW}),r=(0,NH.extrudeLinear)({height:e},s),a=i[2]-e/2;return(0,Hd.translate)([i[0],i[1],a],r)},vH=(t,A,e={})=>{const{clipGeom:i}=e;t.shape||(t.shape="circle");const n=A.pcbThickness+2*D0+4*Jn,o=A.pcbThickness/2+Wa.copper,s=-A.pcbThickness/2-Wa.copper,r=o-s;if(t.shape==="circle"){const a=t.outer_diameter??Math.max(t.hole_diameter,0),g=r+.01,c=(0,or.cylinder)({center:[t.x,t.y,0],radius:a/2,height:g}),I=AG(c,i),l=(0,or.cylinder)({center:[t.x,t.y,0],radius:Math.max(t.hole_diameter/2,.01),height:n});return(0,CD.colorize)(Xn.copper,(0,ia.subtract)(I,l))}if(t.shape==="oval"){const a=t.outer_width||t.hole_width||0,g=t.outer_height||t.hole_height||0,c=t.hole_width||0,I=t.hole_height||0,l=(()=>{const Q=(0,or.cylinder)({center:[0,0,0],radius:1,height:r+.01,segments:64}),h=(0,X6A.scale)([a/2,g/2,1],Q);return(0,Hd.translate)([t.x,t.y,0],h)})(),B=AG(l,i),C=(()=>{const Q=(0,or.cylinder)({center:[0,0,0],radius:1,height:n,segments:64}),h=(0,X6A.scale)([Math.max(c/2,.01),Math.max(I/2,.01),1],Q);return(0,Hd.translate)([t.x,t.y,0],h)})();return(0,CD.colorize)(Xn.copper,(0,ia.subtract)(B,C))}if(t.shape==="circular_hole_with_rect_pad"){const a=t.hole_offset_x||0,g=t.hole_offset_y||0,c=t.rect_pad_width||t.hole_diameter,I=t.rect_pad_height||t.hole_diameter,l=NC(t),B=AG((0,ia.union)(lv({width:c,height:I,thickness:D0,center:[t.x,t.y,o],borderRadius:l}),lv({width:c,height:I,thickness:D0,center:[t.x,t.y,s],borderRadius:l}),(()=>{const E=Math.max(r-D0*2,Jn),p=(o+s)/2,m=(0,or.roundedRectangle)({size:[c,I],roundRadius:l||0,segments:ZW}),D=(0,NH.extrudeLinear)({height:E},m);return(0,Hd.translate)([t.x,t.y,p-E/2],D)})(),(0,or.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:t.hole_diameter/2,height:r})),i),C=(0,or.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:Math.max(t.hole_diameter/2-Jn,.01),height:n}),Q=(0,or.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:t.hole_diameter/2,height:r});let h=(0,ia.union)((0,ia.subtract)(B,Q),Q);return e.clipGeom?(h=(0,ia.subtract)(h,C),h=(0,ia.intersect)(h,e.clipGeom),(0,CD.colorize)(Xn.copper,h)):(0,CD.colorize)(Xn.copper,(0,ia.subtract)(h,C))}if(t.shape==="pill"){const a=(t.ccw_rotation||0)*Math.PI/180,g=x=>{if(!a)return x;const N=(0,Hd.translate)([-t.x,-t.y,0],x),M=(0,Hd.rotate)([0,0,a],N);return(0,Hd.translate)([t.x,t.y,0],M)},c=t.hole_height>t.hole_width,I=c?t.hole_height:t.hole_width,l=c?t.hole_width:t.hole_height,B=c?t.outer_height||l+.2:t.outer_width||I+.2,C=c?t.outer_width||I+.2:t.outer_height||l+.2,Q=l/2,h=Math.abs(I-l),E=r+.01,d=((x,N,M)=>{const L=N/2,Y=Math.abs(x-N);if(Y<=1e-6)return(0,or.cylinder)({center:[t.x,t.y,0],radius:L,height:M});const H=(0,or.cuboid)({center:[t.x,t.y,0],size:c?[N,Y,M]:[Y,N,M]}),O=(0,or.cylinder)({center:c?[t.x,t.y-Y/2,0]:[t.x-Y/2,t.y,0],radius:L,height:M}),Z=(0,or.cylinder)({center:c?[t.x,t.y+Y/2,0]:[t.x+Y/2,t.y,0],radius:L,height:M});return(0,ia.union)(H,O,Z)})(B,C,E),p=(0,or.cuboid)({center:[t.x,t.y,0],size:c?[l-2*Jn,h,n]:[h,l-2*Jn,n]}),m=(0,or.cylinder)({center:c?[t.x,t.y-h/2,0]:[t.x-h/2,t.y,0],radius:Q-Jn,height:n}),D=(0,or.cylinder)({center:c?[t.x,t.y+h/2,0]:[t.x+h/2,t.y,0],radius:Q-Jn,height:n}),w=(0,ia.union)(p,m,D),S=AG(g(d),i),k=g(w);return(0,CD.colorize)(Xn.copper,(0,ia.subtract)(S,k))}if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for pill_hole_with_rect_pad");const a=t.hole_offset_x||0,g=t.hole_offset_y||0,c=t.hole_height>t.hole_width,I=c?t.hole_height:t.hole_width,l=c?t.hole_width:t.hole_height,B=l/2,C=Math.abs(I-l),Q=t.rect_pad_width||I+.2,h=t.rect_pad_height||l+.2,E=NC(t),u=.03,d=(0,ia.union)((0,or.cuboid)({center:[t.x+a,t.y+g,0],size:c?[l+2*u,C+2*u,r]:[C+2*u,l+2*u,r]}),(0,or.cylinder)({center:c?[t.x+a,t.y+g-C/2,0]:[t.x+a-C/2,t.y+g,0],radius:B+u,height:r}),(0,or.cylinder)({center:c?[t.x+a,t.y+g+C/2,0]:[t.x+a+C/2,t.y+g,0],radius:B+u,height:r})),p=(0,ia.union)((0,or.cuboid)({center:[t.x+a,t.y+g,0],size:c?[l,C,n*1.1]:[C,l,n*1.1]}),(0,or.cylinder)({center:c?[t.x+a,t.y+g-C/2,0]:[t.x+a-C/2,t.y+g,0],radius:B,height:n*1.1}),(0,or.cylinder)({center:c?[t.x+a,t.y+g+C/2,0]:[t.x+a+C/2,t.y+g,0],radius:B,height:n*1.1})),m=lv({width:Q,height:h,thickness:D0,center:[t.x,t.y,o],borderRadius:E}),D=lv({width:Q,height:h,thickness:D0,center:[t.x,t.y,s],borderRadius:E}),w=(()=>{const Y=Math.max(r-D0*2,Jn),Z=(o+s)/2,$=(0,or.roundedRectangle)({size:[Q,h],roundRadius:E||0,segments:ZW}),tA=(0,NH.extrudeLinear)({height:Y},$);return(0,Hd.translate)([t.x,t.y,Z-Y/2],tA)})(),S=(0,ia.subtract)(m,p),k=(0,ia.subtract)(D,p),x=(0,ia.subtract)(w,p),N=(0,ia.union)((0,or.cuboid)({center:[t.x+a,t.y+g,0],size:c?[l-2*Jn,C-2*Jn,n*1.1]:[C-2*Jn,l-2*Jn,n*1.1]}),(0,or.cylinder)({center:c?[t.x+a,t.y+g-C/2,0]:[t.x+a-C/2,t.y+g,0],radius:B-Jn,height:n*1.1}),(0,or.cylinder)({center:c?[t.x+a,t.y+g+C/2,0]:[t.x+a+C/2,t.y+g,0],radius:B-Jn,height:n*1.1})),M=(0,ia.subtract)(d,N),L=AG((0,ia.union)(S,k,x,M),i);return(0,CD.colorize)(Xn.copper,L)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for rotated_pill_hole_with_rect_pad");const a=t.hole_offset_x||0,g=t.hole_offset_y||0,c=t.hole_width,I=t.hole_height,l=c>=I,B=l?c:I,C=l?I:c,Q=C/2,h=Math.abs(B-C),E=t.rect_pad_width||c+.2,u=t.rect_pad_height||I+.2,d=NC(t),p=.03,m=(t.hole_ccw_rotation||0)*Math.PI/180,D=(t.rect_ccw_rotation||0)*Math.PI/180,w=aA=>{const eA=a*Math.cos(m)-g*Math.sin(m),nA=a*Math.sin(m)+g*Math.cos(m),rA=(0,Hd.rotate)([0,0,m],aA);return(0,Hd.translate)([t.x+eA,t.y+nA,0],rA)},S=aA=>{if(!D)return aA;const eA=(0,Hd.translate)([-t.x,-t.y,0],aA),nA=(0,Hd.rotate)([0,0,D],eA);return(0,Hd.translate)([t.x,t.y,0],nA)},k=w((0,ia.union)((0,or.cuboid)({center:[0,0,0],size:l?[h+2*p,C+2*p,r]:[C+2*p,h+2*p,r]}),(0,or.cylinder)({center:l?[-h/2,0,0]:[0,-h/2,0],radius:Q+p,height:r}),(0,or.cylinder)({center:l?[h/2,0,0]:[0,h/2,0],radius:Q+p,height:r}))),x=w((0,ia.union)((0,or.cuboid)({center:[0,0,0],size:l?[h,C,n*1.1]:[C,h,n*1.1]}),(0,or.cylinder)({center:l?[-h/2,0,0]:[0,-h/2,0],radius:Q,height:n*1.1}),(0,or.cylinder)({center:l?[h/2,0,0]:[0,h/2,0],radius:Q,height:n*1.1}))),N=S(lv({width:E,height:u,thickness:D0,center:[t.x,t.y,o],borderRadius:d})),M=S(lv({width:E,height:u,thickness:D0,center:[t.x,t.y,s],borderRadius:d})),L=S((()=>{const aA=Math.max(r-D0*2,Jn),rA=(o+s)/2,lA=(0,or.roundedRectangle)({size:[E,u],roundRadius:d||0,segments:ZW}),fA=(0,NH.extrudeLinear)({height:aA},lA);return(0,Hd.translate)([t.x,t.y,rA-aA/2],fA)})()),Y=(0,ia.subtract)(N,x),H=(0,ia.subtract)(M,x),O=(0,ia.subtract)(L,x),Z=w((0,ia.union)((0,or.cuboid)({center:[0,0,0],size:l?[h-2*Jn,C-2*Jn,n*1.1]:[C-2*Jn,h-2*Jn,n*1.1]}),(0,or.cylinder)({center:l?[-h/2,0,0]:[0,-h/2,0],radius:Q-Jn,height:n*1.1}),(0,or.cylinder)({center:l?[h/2,0,0]:[0,h/2,0],radius:Q-Jn,height:n*1.1}))),$=(0,ia.subtract)(k,Z),tA=AG((0,ia.union)(Y,H,O,$),i);return(0,CD.colorize)(Xn.copper,tA)}else if(t.shape==="hole_with_polygon_pad"){const a=t.pad_outline;if(!Array.isArray(a)||a.length<3)throw new Error(`Invalid pad_outline for plated hole at (${t.x}, ${t.y})`);const g=a.map(p=>[p.x,p.y]),c=(0,or.polygon)({points:g}),I=(o+s)/2,l=(p,m)=>{const D=Math.max(p,Jn),w=(0,NH.extrudeLinear)({height:D},c);return(0,Hd.translate)([t.x,t.y,m-D/2],w)},B=l(Math.max(r-D0*2,Jn),I),C=l(D0,o),Q=l(D0,s),h=AG((0,ia.union)(B,C,Q),i),E=WW(t,r);if(!E)return(0,CD.colorize)(Xn.copper,h);const u=WW(t,n,{sizeDelta:-2*Jn})||E;let d=(0,ia.union)((0,ia.subtract)(h,E),E);return e.clipGeom?(d=(0,ia.subtract)(d,u),d=(0,ia.intersect)(d,e.clipGeom),(0,CD.colorize)(Xn.copper,d)):(0,CD.colorize)(Xn.copper,(0,ia.subtract)(d,u))}else throw new Error(`Unsupported plated hole shape: ${t.shape}`)},VW=Jr(EH()),$6A=Jr(XN()),Jbt=Jr($F()),LH=Jr(Q_());function Tbt({x:t,y:A,outerDiameter:e,holeDiameter:i,thickness:n}){if(e<=i)throw new Error(`Invalid via geometry: outerDiameter (${e}) must be > holeDiameter (${i})`);const o=Jn,s=Jn,r=Math.min(e/2,i/2+s),a=(0,LH.cylinder)({center:[0,0,0],radius:r,height:n,segments:VB}),g=(0,LH.cylinder)({center:[0,0,n/2],radius:e/2,height:o,segments:VB}),c=(0,LH.cylinder)({center:[0,0,-n/2],radius:e/2,height:o,segments:VB}),I=(0,$6A.union)([a,g,c]),l=n+o*2,B=(0,LH.cylinder)({center:[0,0,0],radius:i/2,height:l,segments:VB}),C=(0,$6A.subtract)(I,B);return(0,Jbt.translate)([t,A,0],C)}function Kbt({x:t,y:A,holeDiameter:e,thickness:i}){const n=i*1.5,o=e/2+Jn;return(0,LH.cylinder)({center:[t,A,0],radius:o,height:n,segments:VB})}var A7A=64,Pbt=1,FEA=.05,e7A=(t,A,e,i)=>{const n=w0(t,A,i);if(n<=0)return(0,xg.cuboid)({center:[0,0,0],size:[t,A,e]});const o=(0,xg.roundedRectangle)({size:[t,A],roundRadius:n,segments:A7A}),s=(0,VW.extrudeLinear)({height:e},o);return(0,Dh.translate)([0,0,-e/2],s)},t7A=["initializing","processing_pads","processing_copper_pours","processing_plated_holes","processing_holes","processing_cutouts","processing_vias","finalizing","done"],qbt=class{circuitJson;board;plated_holes;holes;pads;traces;pcb_vias;pcb_cutouts;boardGeom=null;platedHoleGeoms=[];padGeoms=[];viaGeoms=[];copperPourGeoms=[];boardClipGeom=null;state="initializing";currentIndex=0;ctx;onCompleteCallback;finalGeoms=[];getHoleToCut(t,A){const e=Jn/10;for(const i of this.pcb_vias)if(Math.abs(i.x-t)<e&&Math.abs(i.y-A)<e&&i.hole_diameter)return{diameter:i.hole_diameter};for(const i of this.plated_holes)if(i.shape==="circle"&&Math.abs(i.x-t)<e&&Math.abs(i.y-A)<e&&i.hole_diameter)return{diameter:i.hole_diameter};return null}constructor(t,A){this.circuitJson=t,this.onCompleteCallback=A;const e=t.filter(n=>n.type==="pcb_panel"),i=Di(t).pcb_board.list();if(e.length>0){const n=e[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=Di(t).pcb_plated_hole.list(),this.holes=Di(t).pcb_hole.list(),this.pads=Di(t).pcb_smtpad.list(),this.traces=Di(t).pcb_trace.list(),this.pcb_vias=Di(t).pcb_via.list(),this.pcb_cutouts=Di(t).pcb_cutout.list(),this.ctx={pcbThickness:this.board.thickness??1.2},this.initializeBoard()}initializeBoard(){const t=this.ctx.pcbThickness+2*Pbt;this.board.outline&&this.board.outline.length>0?(this.boardGeom=kEA({outline:this.board.outline},this.ctx.pcbThickness),this.boardClipGeom=kEA({outline:this.board.outline},t,{xyOutset:FEA})):(this.boardGeom=(0,xg.cuboid)({size:[this.board.width,this.board.height,this.ctx.pcbThickness],center:[this.board.center.x,this.board.center.y,0]}),this.boardClipGeom=(0,xg.cuboid)({size:[this.board.width+2*FEA,this.board.height+2*FEA,t],center:[this.board.center.x,this.board.center.y,0]})),this.state="processing_pads",this.currentIndex=0}goToNextState(){const t=t7A.indexOf(this.state);t!==-1&&(this.state=t7A[t+1],this.currentIndex=0)}step(t=1){if(this.state==="done"||!this.boardGeom)return!0;for(let A=0;A<t&&this.state!=="done";A++)switch(this.state){case"processing_plated_holes":this.currentIndex<this.plated_holes.length?(this.processPlatedHole(this.plated_holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_holes":this.currentIndex<this.holes.length?(this.processHole(this.holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_pads":this.currentIndex<this.pads.length?(this.processPad(this.pads[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_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(t){if(!this.boardGeom)return;let A=null;const e=this.ctx.pcbThickness*1.5;switch(t.shape){case"rect":{const i=w0(t.width,t.height,NC(t));if(i>0){const n=(0,xg.roundedRectangle)({size:[t.width,t.height],roundRadius:i,segments:A7A});A=(0,VW.extrudeLinear)({height:e},n),A=(0,Dh.translate)([0,0,-e/2],A)}else A=(0,xg.cuboid)({center:[0,0,0],size:[t.width,t.height,e]});if(t.rotation){const n=t.rotation*Math.PI/180;A=(0,Dh.rotateZ)(n,A)}A=(0,Dh.translate)([t.center.x,t.center.y,0],A);break}case"circle":A=(0,xg.cylinder)({center:[t.center.x,t.center.y,0],radius:t.radius,height:e});break;case"polygon":{let i=t.points.map(o=>[o.x,o.y]);if(i.length<3){console.warn(`PCB Cutout [${t.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);break}z6A(i)&&(i=i.reverse());const n=(0,xg.polygon)({points:i});A=(0,VW.extrudeLinear)({height:e},n),A=(0,Dh.translate)([0,0,-e/2],A);break}}A&&(this.boardGeom=(0,_g.subtract)(this.boardGeom,A))}processPlatedHole(t,A={}){if(this.boardGeom){if(t.shape==="circle"||t.shape==="circular_hole_with_rect_pad"){let e=null;if(t.shape==="circular_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="circle"||t.pad_shape&&t.pad_shape!=="rect")return;e=(0,xg.cylinder)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],radius:t.hole_diameter/2+Jn,height:this.ctx.pcbThickness*1.5})}else e=(0,xg.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+Jn,height:this.ctx.pcbThickness*1.5});A.dontCutBoard||(this.boardGeom=(0,_g.subtract)(this.boardGeom,e)),this.padGeoms=this.padGeoms.map(n=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(n,e)));const i=vH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(i)}else if(t.shape==="pill"||t.shape==="oval"){const e=t.hole_height>t.hole_width,i=e?t.hole_height:t.hole_width,n=e?t.hole_width:t.hole_height,o=n/2,s=Math.abs(i-n);let r;if(r=(0,_g.union)((0,xg.cuboid)({center:[t.x,t.y,0],size:e?[n,s,this.ctx.pcbThickness*1.5]:[s,n,this.ctx.pcbThickness*1.5]}),(0,xg.cylinder)({center:e?[t.x,t.y-s/2,0]:[t.x-s/2,t.y,0],radius:o,height:this.ctx.pcbThickness*1.5}),(0,xg.cylinder)({center:e?[t.x,t.y+s/2,0]:[t.x+s/2,t.y,0],radius:o,height:this.ctx.pcbThickness*1.5})),t.ccw_rotation){const g=t.ccw_rotation*Math.PI/180;r=(0,Dh.translate)([t.x,t.y,0],(0,Dh.rotateZ)(g,(0,Dh.translate)([-t.x,-t.y,0],r)))}A.dontCutBoard||(this.boardGeom=(0,_g.subtract)(this.boardGeom,r)),this.padGeoms=this.padGeoms.map(g=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(g,r)));const a=vH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")return;const e=t.hole_height>t.hole_width,i=e?t.hole_height:t.hole_width,n=e?t.hole_width:t.hole_height,o=n/2,s=Math.abs(i-n);let r;r=(0,_g.union)((0,xg.cuboid)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],size:e?[n,s,this.ctx.pcbThickness*1.5]:[s,n,this.ctx.pcbThickness*1.5]}),(0,xg.cylinder)({center:e?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)-s/2,0]:[t.x+(t.hole_offset_x||0)-s/2,t.y+(t.hole_offset_y||0),0],radius:o,height:this.ctx.pcbThickness*1.5}),(0,xg.cylinder)({center:e?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)+s/2,0]:[t.x+(t.hole_offset_x||0)+s/2,t.y+(t.hole_offset_y||0),0],radius:o,height:this.ctx.pcbThickness*1.5})),A.dontCutBoard||(this.boardGeom=(0,_g.subtract)(this.boardGeom,r)),this.padGeoms=this.padGeoms.map(g=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(g,r)));const a=vH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")return;const e=t.hole_width,i=t.hole_height,n=e>=i,o=n?e:i,s=n?i:e,r=s/2,a=Math.abs(o-s),g=t.hole_offset_x||0,c=t.hole_offset_y||0;let I=(0,_g.union)((0,xg.cuboid)({center:[0,0,0],size:n?[a,s,this.ctx.pcbThickness*1.5]:[s,a,this.ctx.pcbThickness*1.5]}),(0,xg.cylinder)({center:n?[-a/2,0,0]:[0,-a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}),(0,xg.cylinder)({center:n?[a/2,0,0]:[0,a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}));const l=(t.hole_ccw_rotation||0)*Math.PI/180,B=g*Math.cos(l)-c*Math.sin(l),C=g*Math.sin(l)+c*Math.cos(l);I=(0,Dh.rotateZ)(l,I);const Q=(0,Dh.translate)([t.x+B,t.y+C,0],I);A.dontCutBoard||(this.boardGeom=(0,_g.subtract)(this.boardGeom,Q)),this.padGeoms=this.padGeoms.map(E=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(E,Q)));const h=vH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(h)}else if(t.shape==="hole_with_polygon_pad"){const e=t.pad_outline;if(!Array.isArray(e)||e.length<3)return;const i=this.ctx.pcbThickness*1.5,n=WW(t,i,{sizeDelta:2*Jn}),o=WW(t,i,{sizeDelta:-2*Jn});if(!n||!o)return;A.dontCutBoard||(this.boardGeom=(0,_g.subtract)(this.boardGeom,n)),this.padGeoms=this.padGeoms.map(r=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(r,n))),this.platedHoleGeoms=this.platedHoleGeoms.map(r=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(r,o)));const s=vH(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(s)}}}processHole(t){if(!this.boardGeom)return;const A=this.ctx.pcbThickness*1.5;if(t.hole_shape==="circle"){const e=(0,xg.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+Jn,height:A});this.boardGeom=(0,_g.subtract)(this.boardGeom,e),this.padGeoms=this.padGeoms.map(n=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(n,e)));const i=(0,xg.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+Jn/2,height:A});this.platedHoleGeoms=this.platedHoleGeoms.map(n=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(n,i)))}else if(t.hole_shape==="pill"||t.hole_shape==="rotated_pill"||t.hole_shape==="oval"){const e=t.hole_width??t.hole_diameter,i=t.hole_height??t.hole_diameter,n=t.ccw_rotation??t.rotation??0,o=.02,s=(g,c,I,l)=>{if(g<=0||c<=0)return null;if(l)return(0,Dh.translate)([0,0,-I/2],(0,VW.extrudeLinear)({height:I},(0,xg.ellipse)({radius:[g/2,c/2]})));const B=Math.min(g,c)/2,C=Math.abs(g-c);return g>c?(0,_g.union)((0,xg.cuboid)({center:[0,0,0],size:[C,c,I]}),(0,xg.cylinder)({center:[-C/2,0,0],radius:B,height:I}),(0,xg.cylinder)({center:[C/2,0,0],radius:B,height:I})):(0,_g.union)((0,xg.cuboid)({center:[0,0,0],size:[g,C,I]}),(0,xg.cylinder)({center:[0,-C/2,0],radius:B,height:I}),(0,xg.cylinder)({center:[0,C/2,0],radius:B,height:I}))};let r=s(e,i,A,t.hole_shape==="oval"),a=s(e-2*o,i-2*o,A,t.hole_shape==="oval");if(r&&n!==0&&(r=(0,Dh.rotateZ)(n*Math.PI/180,r)),a&&n!==0&&(a=(0,Dh.rotateZ)(n*Math.PI/180,a)),r){const g=(0,Dh.translate)([t.x,t.y,0],r);this.boardGeom=(0,_g.subtract)(this.boardGeom,g),this.padGeoms=this.padGeoms.map(c=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(c,g)))}if(a){const g=(0,Dh.translate)([t.x,t.y,0],a);this.platedHoleGeoms=this.platedHoleGeoms.map(c=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(c,g)))}}}processPad(t){const A=t.layer==="bottom"?-1:1,e=A*this.ctx.pcbThickness/2+A*Wa.copper,i=NC(t);if(t.shape==="rect"){const n=e7A(t.width,t.height,Jn,i);let s=(0,Dh.translate)([t.x,t.y,e],n);this.boardClipGeom&&(s=(0,_g.intersect)(this.boardClipGeom,s)),s=(0,Tu.colorize)(Xn.copper,s),this.padGeoms.push(s)}else if(t.shape==="rotated_rect"){let n=e7A(t.width,t.height,Jn,i);const o=t.ccw_rotation*Math.PI/180;n=(0,Dh.rotateZ)(o,n);let r=(0,Dh.translate)([t.x,t.y,e],n);this.boardClipGeom&&(r=(0,_g.intersect)(this.boardClipGeom,r)),r=(0,Tu.colorize)(Xn.copper,r),this.padGeoms.push(r)}else if(t.shape==="circle"){let n=(0,xg.cylinder)({center:[t.x,t.y,e],radius:t.radius,height:Jn});this.boardClipGeom&&(n=(0,_g.intersect)(this.boardClipGeom,n)),n=(0,Tu.colorize)(Xn.copper,n),this.padGeoms.push(n)}}processVia(t){if(this.boardGeom){if(typeof t.outer_diameter=="number"&&typeof t.hole_diameter=="number"){const A=Tbt({x:t.x,y:t.y,outerDiameter:t.outer_diameter,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});let e=A;this.boardClipGeom&&(e=(0,_g.intersect)(this.boardClipGeom,A),e=(0,Tu.colorize)(Xn.copper,e)),this.viaGeoms.push(e)}if(typeof t.hole_diameter=="number"){const A=Kbt({x:t.x,y:t.y,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});this.boardGeom=(0,_g.subtract)(this.boardGeom,A),this.padGeoms=this.padGeoms.map(e=>(0,Tu.colorize)(Xn.copper,(0,_g.subtract)(e,A)))}}}finalize(){if(!this.boardGeom)return;const t=_EA[this.board.material]??Xn.fr4Tan;this.boardGeom=(0,Tu.colorize)(t,this.boardGeom),this.finalGeoms=[this.boardGeom,...this.platedHoleGeoms,...this.padGeoms,...this.viaGeoms,...this.copperPourGeoms],this.onCompleteCallback&&this.onCompleteCallback(this.finalGeoms)}getGeoms(){return this.finalGeoms}},Obt=t=>{const[A,e]=V.useState(null),i=V.useRef(!1);return V.useEffect(()=>{let n=!1;if(!t){e(null);return}if(!t.some(g=>g.type==="pcb_board"||g.type==="pcb_panel")){e(null);return}const s=Mbt(t);e(s);const r=new qbt(t,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||e(r.getGeoms())}catch(g){console.error("Error during board geometry building:",g)}finally{i.current=!1}}})(),()=>{n=!0}},[t]),A},Wbt=({children:t,parent:A,position:e,rotation:i,scale:n,color:o,fontSize:s,anchorX:r,anchorY:a,depthOffset:g})=>{const{rootObject:c}=Ju(),I=V.useMemo(()=>{const l=new caA;return l.text=t,e&&l.position.fromArray(e),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},[t,e,i,n,o,s,r,a,g]);return V.useEffect(()=>{const l=A||c;if(!(!l||!I))return l.add(I),()=>{l.remove(I),I.dispose()}},[c,A,I]),null},i7A=({error:t,cad_component:A})=>{const{rootObject:e}=Ju(),[i,n]=V.useState(!1),[o,s]=V.useState(null),r=V.useCallback(I=>{I?.mousePosition?(n(!0),s(I.mousePosition)):(n(!1),s(null))},[]),a=V.useCallback(()=>{n(!1),s(null)},[]),g=V.useMemo(()=>A?.position?[A.position.x,A.position.y,A.position.z].map(l=>Number.isNaN(l)?0:l):[0,0,0],[A]),c=V.useMemo(()=>{const I=new If;return I.position.fromArray(g),I},[g]);return V.useEffect(()=>{if(e)return e.add(c),()=>{e.remove(c)}},[e,c]),W.jsxs(W.Fragment,{children:[W.jsxs(GH,{isHovered:i,onHover:r,onUnhover:a,object:c,children:[W.jsx(Zbt,{parent:c}),W.jsx(Wbt,{parent:c,scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:`${t.toString().slice(0,50)}...`})]}),i&&o?W.jsx(jXA,{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:t.toString()}):null]})},Zbt=({parent:t})=>{const A=V.useMemo(()=>{const e=new io(new Xm(.5,.5,.5),new bE({depthTest:!1,transparent:!0,color:"red",opacity:.5}));return e.renderOrder=999999,e.rotation.fromArray([Math.PI/4,Math.PI/4,0]),e},[]);return V.useEffect(()=>(t.add(A),()=>{t.remove(A)}),[t,A]),null};function Vbt({stlUrl:t,stlData:A,mtlUrl:e,color:i,opacity:n=1}){const{rootObject:o}=Ju(),[s,r]=V.useState(null);V.useEffect(()=>{const g=new _at;if(A){try{const c=g.parse(A);r(c)}catch(c){console.error("Failed to parse STL data",c),r(null)}return}t&&g.load(t,c=>{r(c)})},[t,A]);const a=V.useMemo(()=>{if(!s)return null;const g=new bE({color:Array.isArray(i)?new Ki(i[0],i[1],i[2]):i,transparent:n!==1,opacity:n});return new io(s,g)},[s,i,n]);return V.useEffect(()=>{if(!(!o||!a))return o.add(a),()=>{o.remove(a),a.geometry.dispose(),Array.isArray(a.material)?a.material.forEach(g=>g.dispose()):a.material.dispose()}},[o,a]),null}function jbt({stlData:t,color:A,opacity:e=1,layerType:i}){const{visibility:n}=$N();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?W.jsx(Vbt,{stlData:t,color:A,opacity:e}):null}var n7A=class extends tn.Component{constructor(t){super(t),this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},zbt=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,n=t[0].y;for(let o=1;o<t.length;o++){const s=t[o];s.x<A&&(A=s.x),s.y<e&&(e=s.y),s.x>i&&(i=s.x),s.y>n&&(n=s.y)}return{minX:A,minY:e,maxX:i,maxY:n}};function p_(t){if(t.outline&&t.outline.length>=3){const s=zbt(t.outline);return{...s,width:s.maxX-s.minX,height:s.maxY-s.minY,centerX:(s.minX+s.maxX)/2,centerY:(s.minY+s.maxY)/2}}const A=t.width??0,e=t.height??0,i=t.center?.x??0,n=t.center?.y??0;return{...{minX:i-A/2,maxX:i+A/2,minY:n-e/2,maxY:n+e/2},width:A,height:e,centerX:i,centerY:n}}Jr(Q_()),Jr(XN());function Xbt(t,A,e,i){if(!e||Math.abs(e)<1e-9)return[];const n=4*Math.atan(e),o=A[0]-t[0],s=A[1]-t[1],r=Math.sqrt(o*o+s*s);if(r<1e-9)return[];const a=Math.abs(r/(2*Math.sin(n/2))),g=Math.sqrt(Math.max(0,a*a-r/2*(r/2))),c=[(t[0]+A[0])/2,(t[1]+A[1])/2],I=o/r,B=-(s/r),C=I,Q=c[0]+B*g*Math.sign(e),h=c[1]+C*g*Math.sign(e),E=Math.atan2(t[1]-h,t[0]-Q),u=[],d=Math.max(2,Math.ceil(i*Math.abs(n)/(Math.PI*2)*4)),p=n/d;for(let m=1;m<d;m++){const D=E+p*m;u.push([Q+a*Math.cos(D),h+a*Math.sin(D)])}return u}function o7A(t,A){const e=[],i=t.vertices;for(let n=0;n<i.length;n++){const o=i[n],s=i[(n+1)%i.length];if(e.push([o.x,o.y]),o.bulge){const r=Xbt([o.x,o.y],[s.x,s.y],o.bulge,A);e.push(...r)}}return e}function s7A({ctx:t,points:A,canvasXFromPcb:e,canvasYFromPcb:i}){A.length<3||(t.beginPath(),A.forEach((n,o)=>{const s=e(n[0]),r=i(n[1]);o===0?t.moveTo(s,r):t.lineTo(s,r)}),t.closePath(),t.fill())}function $bt({ctx:t,pour:A,canvasXFromPcb:e,canvasYFromPcb:i}){const n=A.brep_shape;if(!n||!n.outer_ring)return;const o=o7A(n.outer_ring,32);if(o.length>=3&&s7A({ctx:t,points:o,canvasXFromPcb:e,canvasYFromPcb:i}),n.inner_rings&&n.inner_rings.length>0){t.globalCompositeOperation="destination-out";for(const s of n.inner_rings){const r=o7A(s,32);r.length>=3&&s7A({ctx:t,points:r,canvasXFromPcb:e,canvasYFromPcb:i})}t.globalCompositeOperation="source-over"}}function jW({layer:t,circuitJson:A,boardData:e,traceTextureResolution:i=MH}){const n=A.filter(E=>E.type==="pcb_copper_pour"),o=t==="top"?"top_copper":"bottom_copper",s=n.filter(E=>E.layer===t);if(s.length===0)return null;const r=p_(e),a=document.createElement("canvas"),g=Math.floor(r.width*i),c=Math.floor(r.height*i);a.width=g,a.height=c;const I=a.getContext("2d");if(!I)return null;t==="bottom"&&(I.translate(0,c),I.scale(1,-1));const l=E=>(E-r.minX)*i,B=E=>(r.maxY-E)*i,C=s.filter(E=>E.shape==="rect"||E.shape==="polygon"),Q=s.filter(E=>E.shape==="brep");if(C.length>0){const E=new PQt(I);E.setCameraBounds({minX:r.minX,maxX:r.maxX,minY:r.minY,maxY:r.maxY});const u=C.filter(D=>D.covered_with_solder_mask!==!1),d=C.filter(D=>D.covered_with_solder_mask===!1),p=`rgb(${Xn.fr4TracesWithMaskGreen.map(D=>D*255).join(",")})`,m=`rgb(${Xn.copper.map(D=>D*255).join(",")})`;u.length>0&&(E.configure({colorOverrides:{copper:{top:p,bottom:p,inner1:p,inner2:p,inner3:p,inner4:p,inner5:p,inner6:p}}}),E.drawElements(u,{layers:[o]})),d.length>0&&(E.configure({colorOverrides:{copper:{top:m,bottom:m,inner1:m,inner2:m,inner3:m,inner4:m,inner5:m,inner6:m}}}),E.drawElements(d,{layers:[o]}))}for(const E of Q){const d=E.covered_with_solder_mask!==!1?Xn.fr4TracesWithMaskGreen:Xn.copper,p=`rgb(${d[0]*255}, ${d[1]*255}, ${d[2]*255})`;I.fillStyle=p,$bt({ctx:I,pour:E,canvasXFromPcb:l,canvasYFromPcb:B})}const h=new MN(a);return h.generateMipmaps=!0,h.minFilter=Lu,h.magFilter=oB,h.anisotropy=16,h.needsUpdate=!0,h}function Cf(t,A){const{texture:e,yOffset:i,isBottomLayer:n,textureType:o,usePolygonOffset:s=!1,renderOrder:r=0,isFaux:a=!1}=t;if(!e)return null;const g=p_(A),c=new $m(g.width,g.height),I=new vd({map:e,transparent:!0,side:OB,depthWrite:o==="panel-outlines",polygonOffset:s,polygonOffsetFactor:s?-4:0,polygonOffsetUnits:s?-4:0,opacity:a?qW:1}),l=new io(c,I);return l.position.set(g.centerX,g.centerY,i),n&&l.rotation.set(Math.PI,0,0),l.name=`${n?"bottom":"top"}-${o}-texture-plane`,l.renderOrder=r,l}function Axt(t,A,e,i=!1){const n=[];if(!t||!A||e===null)return n;const o=Cf({texture:t.topTrace,yOffset:e/2+Wa.traces,isBottomLayer:!1,textureType:"trace",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);o&&n.push(o);const s=Cf({texture:t.topTraceWithMask,yOffset:e/2+Wa.traces,isBottomLayer:!1,textureType:"trace-with-mask",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);s&&n.push(s);const r=Cf({texture:t.topSilkscreen,yOffset:e/2+.003,isBottomLayer:!1,textureType:"silkscreen",usePolygonOffset:!1,renderOrder:3,isFaux:i},A);r&&n.push(r);const a=Cf({texture:t.bottomTrace,yOffset:-e/2-Wa.traces,isBottomLayer:!0,textureType:"trace",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);a&&n.push(a);const g=Cf({texture:t.bottomTraceWithMask,yOffset:-e/2-Wa.traces,isBottomLayer:!0,textureType:"trace-with-mask",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);g&&n.push(g);const c=Cf({texture:t.bottomSilkscreen,yOffset:-e/2-.003,isBottomLayer:!0,textureType:"silkscreen",usePolygonOffset:!1,renderOrder:3,isFaux:i},A);c&&n.push(c);const I=Cf({texture:t.topSoldermask,yOffset:e/2+.001,isBottomLayer:!1,textureType:"soldermask",usePolygonOffset:!0,renderOrder:1,isFaux:i},A);I&&n.push(I);const l=Cf({texture:t.bottomSoldermask,yOffset:-e/2-.001,isBottomLayer:!0,textureType:"soldermask",usePolygonOffset:!0,renderOrder:1,isFaux:i},A);l&&n.push(l);const B=Cf({texture:t.topCopperText,yOffset:e/2+Wa.copper,isBottomLayer:!1,textureType:"copper-text",usePolygonOffset:!0,renderOrder:2,isFaux:i},A);B&&n.push(B);const C=Cf({texture:t.bottomCopperText,yOffset:-e/2-Wa.copper,isBottomLayer:!0,textureType:"copper-text",usePolygonOffset:!0,renderOrder:2,isFaux:i},A);C&&n.push(C);const Q=Cf({texture:t.topCopper,yOffset:e/2+Wa.copper,isBottomLayer:!1,textureType:"copper",usePolygonOffset:!0,renderOrder:2,isFaux:i},A);Q&&n.push(Q);const h=Cf({texture:t.bottomCopper,yOffset:-e/2-Wa.copper,isBottomLayer:!0,textureType:"copper",usePolygonOffset:!0,renderOrder:2,isFaux:i},A);h&&n.push(h);const E=Cf({texture:t.topPanelOutlines,yOffset:e/2+.004,isBottomLayer:!1,textureType:"panel-outlines",usePolygonOffset:!1,renderOrder:4,isFaux:i},A);E&&n.push(E);const u=Cf({texture:t.bottomPanelOutlines,yOffset:-e/2-.004,isBottomLayer:!0,textureType:"panel-outlines",usePolygonOffset:!1,renderOrder:4,isFaux:i},A);return u&&n.push(u),n}var ext=Jr(WhA());function r7A(t,A){return Array.isArray(A)?[t.a*A[0]+t.c*A[1]+t.e,t.b*A[0]+t.d*A[1]+t.f]:{x:t.a*A.x+t.c*A.y+t.e,y:t.b*A.x+t.d*A.y+t.f}}function f_(t,A=0){return{a:1,c:0,e:t,b:0,d:1,f:A}}function a7A(...t){t=Array.isArray(t[0])?t[0]:t;const A=(e,i)=>({a:e.a*i.a+e.c*i.b,c:e.a*i.c+e.c*i.d,e:e.a*i.e+e.c*i.f+e.e,b:e.b*i.a+e.d*i.b,d:e.b*i.c+e.d*i.d,f:e.b*i.e+e.d*i.f+e.f});switch(t.length){case 0:throw new Error("no matrices provided");case 1:return t[0];case 2:return A(t[0],t[1]);default:{const[e,i,...n]=t,o=A(e,i);return a7A(o,...n)}}}function g7A(...t){return a7A(...t)}var{cos:txt,sin:ixt}=Math;function c7A(t,A,e){const i=txt(t),n=ixt(t);return{a:i,c:-n,e:0,b:n,d:i,f:0}}function nxt(t,A){function e(){this.constructor=t}e.prototype=A.prototype,t.prototype=new e}function zW(t,A,e,i){var n=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(n,zW.prototype),n.expected=A,n.found=e,n.location=i,n.name="SyntaxError",n}nxt(zW,Error);function GEA(t,A,e){return e=e||" ",t.length>A?t:(A-=t.length,e+=e.repeat(A),t+e.slice(0,A))}zW.prototype.format=function(t){var A="Error: "+this.message;if(this.location){var e=null,i;for(i=0;i<t.length;i++)if(t[i].source===this.location.source){e=t[i].text.split(/\r\n|\n|\r/g);break}var n=this.location.start,o=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(n):n,s=this.location.source+":"+o.line+":"+o.column;if(e){var r=this.location.end,a=GEA("",o.line.toString().length," "),g=e[n.line-1],c=n.line===r.line?r.column:g.length+1,I=c-n.column||1;A+=`
5173
5173
  --> `+s+`
5174
5174
  `+a+` |
5175
5175
  `+o.line+" | "+g+`
@@ -5686,7 +5686,7 @@ test("${g} should solve problem correctly", () => {
5686
5686
  // Add more specific assertions based on expected output
5687
5687
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5688
5688
  })
5689
- `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Zce=t=>t.activeSubSolver?[t,...Zce(t.activeSubSolver)]:[t],TVt=({solver:t})=>{const A=Zce(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(JVt,{solver:e})]},e.constructor.name))})},KVt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),n&&n(t))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&t.solved&&n(t);return}t.step(),A()},e))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(TVt,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.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"}),W.jsx("button",{onClick:g,disabled:t.solved||t.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"}),W.jsx("button",{onClick:c,disabled:t.solved||t.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"}),W.jsx("button",{onClick:l,disabled:t.solved||t.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&&W.jsx("button",{onClick:I,disabled:t.solved||t.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"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},PVt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},qVt=(t,A)=>{const i=t.pipelineDef[A].solverName,n=PVt(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const l=t.pipelineDef[A+1],B=l?t.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=t.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}},OVt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},WVt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},ZVt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),VVt=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=ZVt(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},TfA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(TfA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=TfA(i));return A},jVt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=TfA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,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(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},zVt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>qVt(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):jVt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(OVt,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(WVt,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(VVt,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.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:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},XVt=class extends tn.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function $Vt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],n=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of e){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,p=h.height??0;c(E,u),c(E+d,u+p)}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 W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),e.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var A9t=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();o()}};return W.jsxs("div",{children:[W.jsx(KVt,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(XVt,{fallback:W.jsx($Vt,{graphics:s}),children:W.jsx(YVt,{graphics:s})}),a&&W.jsx(zVt,{solver:t,onStepUntilPhase:g})]})};const e9t=()=>{V.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},t9t=t=>t.toLowerCase().includes("pack")?QMt:t.toLowerCase().includes("rout")?pMt:AMt,i9t=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);e9t();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=OnA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(OnA).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 t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const c=t9t(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(Hy,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(A9t,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Vce=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{U5.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{U5.captureException(n,{error_type:i.type})}catch{}}},[e])},jce="0.0.1570",n9t={version:jce},V9=yYA()(mYA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),o9t=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=e1("eval-version-selection",null),g=V9(B=>B.setLastRunEvalVersion),c=V9(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},s9t=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},r9t=t=>{const A=V.useRef(null),e=PI(i=>i.recentEvents);V.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function a9t(t){const A=g9t(t),e=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(I9t);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function g9t(t){const A=V.forwardRef((e,i)=>{const{children:n,...o}=e;if(V.isValidElement(n)){const s=B9t(n),r=l9t(o,n.props);return n.type!==V.Fragment&&(r.ref=i?of(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var c9t=Symbol("radix.slottable");function I9t(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===c9t}function l9t(t,A){const e={...A};for(const i in A){const n=t[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?e[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(e[i]=n):i==="style"?e[i]={...n,...o}:i==="className"&&(e[i]=[n,o].filter(Boolean).join(" "))}return{...t,...e}}function B9t(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var j9="Dialog",[zce,Xce]=Hm(j9),[C9t,Bw]=zce(j9),$ce=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=Lx({prop:i,defaultProp:n??!1,onChange:o,caller:j9});return W.jsx(C9t,{scope:A,triggerRef:r,contentRef:a,contentId:yE(),titleId:yE(),descriptionId:yE(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};$ce.displayName=j9;var AIe="DialogTrigger",eIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Bw(AIe,e),o=hI(A,n.triggerRef);return W.jsx(qa.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":qfA(n.open),...i,ref:o,onClick:Hn(t.onClick,n.onOpenToggle)})});eIe.displayName=AIe;var KfA="DialogPortal",[Q9t,tIe]=zce(KfA,{forceMount:void 0}),iIe=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=Bw(KfA,A);return W.jsx(Q9t,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(h0,{present:e||o.open,children:W.jsx(OZ,{asChild:!0,container:n,children:s})}))})};iIe.displayName=KfA;var z9="DialogOverlay",nIe=V.forwardRef((t,A)=>{const e=tIe(z9,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Bw(z9,t.__scopeDialog);return o.modal?W.jsx(h0,{present:i||o.open,children:W.jsx(E9t,{...n,ref:A})}):null});nIe.displayName=z9;var h9t=a9t("DialogOverlay.RemoveScroll"),E9t=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Bw(z9,e);return W.jsx(AV,{as:h9t,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(qa.div,{"data-state":qfA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),GG="DialogContent",oIe=V.forwardRef((t,A)=>{const e=tIe(GG,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Bw(GG,t.__scopeDialog);return W.jsx(h0,{present:i||o.open,children:o.modal?W.jsx(u9t,{...n,ref:A}):W.jsx(d9t,{...n,ref:A})})});oIe.displayName=GG;var u9t=V.forwardRef((t,A)=>{const e=Bw(GG,t.__scopeDialog),i=V.useRef(null),n=hI(A,e.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return KuA(o)},[]),W.jsx(sIe,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Hn(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:Hn(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Hn(t.onFocusOutside,o=>o.preventDefault())})}),d9t=V.forwardRef((t,A)=>{const e=Bw(GG,t.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(sIe,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{t.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||e.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{t.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;e.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),sIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=Bw(GG,e),a=V.useRef(null),g=hI(A,a);return wuA(),W.jsxs(W.Fragment,{children:[W.jsx(RZ,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx($H,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":qfA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(f9t,{titleId:r.titleId}),W.jsx(m9t,{contentRef:a,descriptionId:r.descriptionId})]})]})}),PfA="DialogTitle",rIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Bw(PfA,e);return W.jsx(qa.h2,{id:n.titleId,...i,ref:A})});rIe.displayName=PfA;var aIe="DialogDescription",gIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Bw(aIe,e);return W.jsx(qa.p,{id:n.descriptionId,...i,ref:A})});gIe.displayName=aIe;var cIe="DialogClose",IIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Bw(cIe,e);return W.jsx(qa.button,{type:"button",...i,ref:A,onClick:Hn(t.onClick,()=>n.onOpenChange(!1))})});IIe.displayName=cIe;function qfA(t){return t?"open":"closed"}var lIe="DialogTitleWarning",[p9t,BIe]=YXe(lIe,{contentName:GG,titleName:PfA,docsSlug:"dialog"}),f9t=({titleId:t})=>{const A=BIe(lIe),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
5689
+ `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Zce=t=>t.activeSubSolver?[t,...Zce(t.activeSubSolver)]:[t],TVt=({solver:t})=>{const A=Zce(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(JVt,{solver:e})]},e.constructor.name))})},KVt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),n&&n(t))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&t.solved&&n(t);return}t.step(),A()},e))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(TVt,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.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"}),W.jsx("button",{onClick:g,disabled:t.solved||t.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"}),W.jsx("button",{onClick:c,disabled:t.solved||t.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"}),W.jsx("button",{onClick:l,disabled:t.solved||t.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&&W.jsx("button",{onClick:I,disabled:t.solved||t.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"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},PVt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},qVt=(t,A)=>{const i=t.pipelineDef[A].solverName,n=PVt(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const l=t.pipelineDef[A+1],B=l?t.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=t.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}},OVt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},WVt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},ZVt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),VVt=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=ZVt(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},TfA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(TfA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=TfA(i));return A},jVt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=TfA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,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(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},zVt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>qVt(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):jVt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(OVt,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(WVt,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(VVt,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.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:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},XVt=class extends tn.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function $Vt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],n=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of e){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,p=h.height??0;c(E,u),c(E+d,u+p)}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 W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),e.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var A9t=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();o()}};return W.jsxs("div",{children:[W.jsx(KVt,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(XVt,{fallback:W.jsx($Vt,{graphics:s}),children:W.jsx(YVt,{graphics:s})}),a&&W.jsx(zVt,{solver:t,onStepUntilPhase:g})]})};const e9t=()=>{V.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},t9t=t=>t.toLowerCase().includes("pack")?QMt:t.toLowerCase().includes("rout")?pMt:AMt,i9t=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);e9t();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=OnA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(OnA).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 t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const c=t9t(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(Hy,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(A9t,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Vce=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{U5.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{U5.captureException(n,{error_type:i.type})}catch{}}},[e])},jce="0.0.1571",n9t={version:jce},V9=yYA()(mYA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),o9t=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=e1("eval-version-selection",null),g=V9(B=>B.setLastRunEvalVersion),c=V9(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},s9t=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},r9t=t=>{const A=V.useRef(null),e=PI(i=>i.recentEvents);V.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function a9t(t){const A=g9t(t),e=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(I9t);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function g9t(t){const A=V.forwardRef((e,i)=>{const{children:n,...o}=e;if(V.isValidElement(n)){const s=B9t(n),r=l9t(o,n.props);return n.type!==V.Fragment&&(r.ref=i?of(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var c9t=Symbol("radix.slottable");function I9t(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===c9t}function l9t(t,A){const e={...A};for(const i in A){const n=t[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?e[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(e[i]=n):i==="style"?e[i]={...n,...o}:i==="className"&&(e[i]=[n,o].filter(Boolean).join(" "))}return{...t,...e}}function B9t(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var j9="Dialog",[zce,Xce]=Hm(j9),[C9t,Bw]=zce(j9),$ce=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=Lx({prop:i,defaultProp:n??!1,onChange:o,caller:j9});return W.jsx(C9t,{scope:A,triggerRef:r,contentRef:a,contentId:yE(),titleId:yE(),descriptionId:yE(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};$ce.displayName=j9;var AIe="DialogTrigger",eIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Bw(AIe,e),o=hI(A,n.triggerRef);return W.jsx(qa.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":qfA(n.open),...i,ref:o,onClick:Hn(t.onClick,n.onOpenToggle)})});eIe.displayName=AIe;var KfA="DialogPortal",[Q9t,tIe]=zce(KfA,{forceMount:void 0}),iIe=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=Bw(KfA,A);return W.jsx(Q9t,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(h0,{present:e||o.open,children:W.jsx(OZ,{asChild:!0,container:n,children:s})}))})};iIe.displayName=KfA;var z9="DialogOverlay",nIe=V.forwardRef((t,A)=>{const e=tIe(z9,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Bw(z9,t.__scopeDialog);return o.modal?W.jsx(h0,{present:i||o.open,children:W.jsx(E9t,{...n,ref:A})}):null});nIe.displayName=z9;var h9t=a9t("DialogOverlay.RemoveScroll"),E9t=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Bw(z9,e);return W.jsx(AV,{as:h9t,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(qa.div,{"data-state":qfA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),GG="DialogContent",oIe=V.forwardRef((t,A)=>{const e=tIe(GG,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Bw(GG,t.__scopeDialog);return W.jsx(h0,{present:i||o.open,children:o.modal?W.jsx(u9t,{...n,ref:A}):W.jsx(d9t,{...n,ref:A})})});oIe.displayName=GG;var u9t=V.forwardRef((t,A)=>{const e=Bw(GG,t.__scopeDialog),i=V.useRef(null),n=hI(A,e.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return KuA(o)},[]),W.jsx(sIe,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Hn(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:Hn(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Hn(t.onFocusOutside,o=>o.preventDefault())})}),d9t=V.forwardRef((t,A)=>{const e=Bw(GG,t.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(sIe,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{t.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||e.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{t.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;e.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),sIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=Bw(GG,e),a=V.useRef(null),g=hI(A,a);return wuA(),W.jsxs(W.Fragment,{children:[W.jsx(RZ,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx($H,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":qfA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(f9t,{titleId:r.titleId}),W.jsx(m9t,{contentRef:a,descriptionId:r.descriptionId})]})]})}),PfA="DialogTitle",rIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Bw(PfA,e);return W.jsx(qa.h2,{id:n.titleId,...i,ref:A})});rIe.displayName=PfA;var aIe="DialogDescription",gIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Bw(aIe,e);return W.jsx(qa.p,{id:n.descriptionId,...i,ref:A})});gIe.displayName=aIe;var cIe="DialogClose",IIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Bw(cIe,e);return W.jsx(qa.button,{type:"button",...i,ref:A,onClick:Hn(t.onClick,()=>n.onOpenChange(!1))})});IIe.displayName=cIe;function qfA(t){return t?"open":"closed"}var lIe="DialogTitleWarning",[p9t,BIe]=YXe(lIe,{contentName:GG,titleName:PfA,docsSlug:"dialog"}),f9t=({titleId:t})=>{const A=BIe(lIe),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
5690
5690
 
5691
5691
  If you want to hide the \`${A.titleName}\`, you can wrap it with our VisuallyHidden component.
5692
5692